diff --git a/-lstdc++ b/-lstdc++ new file mode 100644 index 0000000..cacdd7d Binary files /dev/null and b/-lstdc++ differ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5090605 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "structures.h": "c" + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a50f7d7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ + YOLO LICENSE + Version 2, July 29 2016 + +THIS SOFTWARE LICENSE IS PROVIDED "ALL CAPS" SO THAT YOU KNOW IT IS SUPER +SERIOUS AND YOU DON'T MESS AROUND WITH COPYRIGHT LAW BECAUSE YOU WILL GET IN +TROUBLE HERE ARE SOME OTHER BUZZWORDS COMMONLY IN THESE THINGS WARRANTIES +LIABILITY CONTRACT TORT LIABLE CLAIMS RESTRICTION MERCHANTABILITY. NOW HERE'S +THE REAL LICENSE: + +0. Darknet is public domain. +1. Do whatever you want with it. +2. Stop emailing me about it! diff --git a/LICENSE.fuck b/LICENSE.fuck new file mode 100644 index 0000000..8b1a9d8 --- /dev/null +++ b/LICENSE.fuck @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/LICENSE.gen b/LICENSE.gen new file mode 100644 index 0000000..c541132 --- /dev/null +++ b/LICENSE.gen @@ -0,0 +1,91 @@ +RNN LICENSE Version 3, June 21 2017 + +Copyright (c) 1990, 1989, 1999 Free87337 May 48 THIRD PARTIES OR ANY OTHER THE +COMPLAIN OR CONSEQUENTIAL DAMAGES AND REGARDLESS OF WHETHER IN CONTRACT, TO THE +EXTENT REPAIR OR AGENTS (NOT THE IN ANY EVENT). THE SOFTWARE WILL BE +UNINTERRUPTED OR ERROR-FREE OR ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF ALL THE WORK (GOVERNED CODE) HIM RESPONSES, OR OF FINES, +SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR ANY OTHER OR OTHER HARL UNDER NO +CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), +PATENT PERMITTED BY THE INSTAGRAM PARENT STATE OR TORT (INCLUDING NEGLIGENCE), +PRODUCT LIABILITY OR OTHERWISE, ARISING OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR ANYTHING PROVIDED IN THIS PRODUCT, COMMIS AND SERVICES +ARE LICENSED SOFTWARE AND ANY RESULE OR ANY OTHER THE COPYRIGHT HOLDERS BE +LIABLE FOR ANY SPECIAL, INCIDENTAL, CASE, SUCH WARRANTIES, EXPRESS OR IMPLIED, +INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COPYRIGHT HOLDERS AND/OR ANY +PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY +EXPRESS OR DISTRIBUTE THAT ALL CLAIMS ARE SHALL CREATE DERAVE BE LIABLE TO YOU +WILL HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +6\. TERMINATION. TO THE EXTENT PERMITTED BY LAW, NO USE OF THE COVERED CODE IS +WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE +INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +SERVICING, REPAIR OR COULT OR IN ANY WAY OUT OF THE USE OF THE WEBSITES OR +SERVICE WILL BE CONSEQUENTIAL DAMAGES OF ANY KIND HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + +This paragraph Agreement constitutes the entire agreement between the parties +with respect to the Work licensed here. However, if you place the name of the +fact that the arbitration was the consultation of the parties as a "patent is". +Subject to the terms and conditions of this License, Contributor has knowledge +that a license under a third party may also be used to endorse or promote +products derived from the Work, and there is no warranty on the Software and +Science Fees. For the purposes of this Agreement, attach the following +disclaimers (without liabilities of written notice to the Subject Software) in a +manner that a product is under common control with you. The Free Software +Foundation may publish revised and/or new versions of the License for the +Modifications made by the applicable terms. The Recipient shall promptly retain +the covered works for any reason be entered in any federal or state or login +Restricted Laws appearing in the United States or any of its own information +that is not disabled from a derivative work except as expressly permitted in +this License, to the extent that they are in receiving the Software and Source +Code or any exercise of the rights granted to You by this License or a +Contributor made by the Licensor or are authorized to make a reasonable +retirement by the courts of the courts located in Santa Clara County, California +printed and related to the Work or “Company” and Apache Software Foundation. If +the Licensor shall be entitled to reflect your rights to use the Software and +the Software to exercise the rights granted to the recipient without a +requirement to exercise the rights granted by the Agreement to the provision +will begin will appear in such cases, you will use such information without such +corporation shall be an officer with respect to any part of the Software or any +portion thereof. Capitalized terms are included in the Initial Contributor and +under no circumstances will license the Service at any time and for any direct, +indirect, special, incidental, or consequential damages of or assist in +connection with any Services or the registration purposes only to the extent +that it includes any or all means including the processing of which you download +any derivative work. Any of the purchases’ transmission purposes are made +available, if any, in other circumstances, we may review the copyright notice. +In the event that this Agreement is required to give us strict content. The +inclusion of the other party hereunder may also notify you Intellectual Property +Rights to any third party. This means that the Source Code exists of the Work +will not charge a program available to you at any time. You must include a +prominent statement that the Software is governed under a particular version of +this Agreement. You must include a provision to the extent that there is no +warranty for the content of others. You agree that the Recipient was appointed +as a Contributor, (c) are effective until terminated by hereunder, then the +registration are not disabled and not limited to, submit any Customer Data +without the updated use of the Software and that no fee is released. You grant +to Use Other Arbitration Rules for Diagnostic or Services may use or modify the +Apple Software and Consolidated Apple Software or Services. The Company may have +full risk as a product of the Compatible Source. A Contribution by the Licensor +or by the updated Software under the following conditions we can redistribute +any General Provision of this Agreement. If the Program is used in accordance +with the terms of this Agreement, Customer may provide advertisements from your +devices that clause you can your employer or a transaction or country that has +been controlled by the arbitrator, that they will be useful of this Agreement. +The term "Open Source Software is available in connection with the program, and +you may not protect the combination of the Covered Code. You should like to +select a user's rights to charge a copy of this License. I are Contributor's +confidentiality of the exercise of the rights granted herein. Such a covered +work is released as a consequence, the Licensor shall be eligible for a purpose +or subcontractor of the person or entity to the user of the user, then the word +"Application" means having the original fee for any reason; and that no patent +license to more than fifty stated close of the license term. The terms of this +License will the license terms and conditions set forth in Section 2.2 (OPEC) +and You will not use the Software or any set of responsibility for any resulting +information that the Original Code warrants that you have the right to disclose +these information (or in the notification; or (iii) late use of the software or +any third party to the three (50) days before such belief to the extent that it +includes a court court obtains the rights granted by this License. diff --git a/LICENSE.gpl b/LICENSE.gpl new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/LICENSE.gpl @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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 . + +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: + + {project} Copyright (C) {year} {fullname} + 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 +. + + 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 +. diff --git a/LICENSE.meta b/LICENSE.meta new file mode 100644 index 0000000..6728bd2 --- /dev/null +++ b/LICENSE.meta @@ -0,0 +1,8 @@ + META-LICENSE + Version 1, June 21 2017 + +Any and all licenses may be applied to the software either individually +or in concert. Any issues, ambiguities, paradoxes, or metaphysical quandries +arising from this combination should be discussed with a local faith leader, +hermit, or guru. The Oxford comma shall be used. + diff --git a/LICENSE.mit b/LICENSE.mit new file mode 100644 index 0000000..5bd806c --- /dev/null +++ b/LICENSE.mit @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2017 Joseph Redmon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/LICENSE.v1 b/LICENSE.v1 new file mode 100644 index 0000000..5b8709a --- /dev/null +++ b/LICENSE.v1 @@ -0,0 +1,13 @@ + YOLO LICENSE + Version 1, July 10 2015 + +THIS SOFTWARE LICENSE IS PROVIDED "ALL CAPS" SO THAT YOU KNOW IT IS SUPER +SERIOUS AND YOU DON'T MESS AROUND WITH COPYRIGHT LAW BECAUSE YOU WILL GET IN +TROUBLE HERE ARE SOME OTHER BUZZWORDS COMMONLY IN THESE THINGS WARRANTIES +LIABILITY CONTRACT TORT LIABLE CLAIMS RESTRICTION MERCHANTABILITY SUBJECT TO +THE FOLLOWING CONDITIONS: + +1. #yolo +2. #swag +3. #blazeit + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..52c48f1 --- /dev/null +++ b/Makefile @@ -0,0 +1,75 @@ + +GPU=0 +CUDNN=0 +OPENCV=0 +OPENMP=0 +DEBUG=0 + +OS := $(shell uname) + +#VPATH=./src/:./examples +VPATH=./src +#SLIB= libopencv_core.so libopencv_highgui.so +ALIB=libdarknet.a +EXEC=gynet +OBJDIR=./obj/ + +#-I/usr/local/opencv/include +#-L/usr/local/opencv/lib + +TOOLCHAIN_PATH ?= /usr/local/linaro-aarch64-2018.08-gcc8.2 +CROSS_COMPILE_TOOL_CHAIN_PATH := $(TOOLCHAIN_PATH) +CC = $(CROSS_COMPILE_TOOL_CHAIN_PATH)/bin/aarch64-linux-gnu-gcc +CPP = $(CROSS_COMPILE_TOOL_CHAIN_PATH)/bin/aarch64-linux-gnu-g++ + +#CC=gcc +#CPP=g++ +NVCC=nvcc +AR=ar +ARFLAGS=rcs +OPTS=-Ofast +LDFLAGS= -lm -pthread -L$(PWD) -Wl,--start-group libcurl.a libssl.a libcrypto.a libz.a -lpng16 -ldl -lpthread libjpeg.a libpng16.a libopencv_core.a libopencv_imgproc.a libopencv_imgcodecs.a libopencv_video.a libopencv_img_hash.a -Wl,--end-group +#COMMON= -Iinclude/ -Isrc/ +COMMON= -Iinclude/ -Isrc/ -Isrc/opencv/ -Isrc/opencv2/ -Iinclude/ambarella/ -Iinclude/ambarella/arch_v5/ +CFLAGS=-Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC + +CFLAGS+=$(OPTS) + +OBJ=gemm.o utility.o utils.o cJSON.o cryptionPlus.o nweb.o strptime_c.o gettest.o exif.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o detection_layer.o route_layer.o upsample_layer.o box.o normalization_layer.o avgpool_layer.o layer.o local_layer.o shortcut_layer.o logistic_layer.o activation_layer.o rnn_layer.o gru_layer.o crnn_layer.o demo.o batchnorm_layer.o region_layer.o reorg_layer.o tree.o lstm_layer.o l2norm_layer.o yolo_layer.o iseg_layer.o image_opencv.o art.o detector.o darknet.o test_nnctrl_live.o amba_bbox_utils.o amba_ssd_detection_out.o amba_yolov3_out.o lib_data_process.o signal_test.o iniReader.o alm_queue.o sqlite_db.o fflpr_plate_db.o cgicmd.o encrypt.o decrypt.o ColorDetector.o base64.o intLib.o sha1.o websocket.o ptz.o pns.o md5.o cold_zone.o pns.o net_curl.o ivs.o fork_pipe_lib.o cv_point_transform.o block_to_send.o md5_f.o url_encode.o send_osd_data.o ir_control.o dbscan.o levenshtein.o levenshtein_sqlite.o yuv_rgb.o test_yuv_rgb.o structures.o barcode.o onvif_data.o ivs_detection.o pythonR.o anpr_rule.o k_means.o parking_method.o + + +#osd_server_yolov3.o osd_server_utils.o lib_smartfb.o +#captcha.o yolo.o cifar.o classifier.o coco.o go.o instance-segmenter.o lsd.o nightmare.o regressor.o +#segmenter.o super.o +OBJS = $(addprefix $(OBJDIR), $(OBJ)) +DEPS = $(wildcard src/*.h) $(wildcard src/*.hpp) $(wildcard src/opencv/*.h) $(wildcard src/opencv/*.hpp) $(wildcard src/opencv2/*.h) $(wildcard src/opencv2/*.hpp) $(wildcard include/ambarella/freetype/*.h) $(wildcard include/ambarella/freetype/config/*.h) + +#all: obj backup results $(ALIB) $(EXEC) +all: obj results $(ALIB) $(EXEC) libnnctrl.so #lib_data_process.so + +$(EXEC): $(ALIB) + $(CC) -g $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS) libzlog.a -lstdc++ $(ALIB) \ + libnnctrl.so libcavalry_mem.so libvproc.so libfreetype.so libsqlite3.so libidn2.so.0.3.5 libnghttp2.so.14.13.3 libunistring.so.2.1.0 libzbar.so.0.2.0 + #lib_data_process.so + +$(ALIB): $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +$(OBJDIR)%.o: %.cpp $(DEPS) + $(CPP) $(COMMON) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)%.o: %.c $(DEPS) + $(CC) $(COMMON) $(CFLAGS) -c $< -o $@ + +obj: + mkdir -p obj +backup: + mkdir -p backup +results: + mkdir -p results + +.PHONY: clean + +clean: + rm -rf $(OBJS) $(SLIB) $(ALIB) $(EXEC) $(EXECOBJ) $(OBJDIR)/* + diff --git a/Original.jpg b/Original.jpg new file mode 100644 index 0000000..97af43a Binary files /dev/null and b/Original.jpg differ diff --git a/cacert.pem b/cacert.pem new file mode 100644 index 0000000..fdb454d --- /dev/null +++ b/cacert.pem @@ -0,0 +1,3174 @@ +## +## Bundle of CA Root Certificates +## +## Certificate data from Mozilla as of: Mon Jul 5 21:35:54 2021 GMT +## +## This is a bundle of X.509 certificates of public Certificate Authorities +## (CA). These were automatically extracted from Mozilla's root certificates +## file (certdata.txt). This file can be found in the mozilla source tree: +## https://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt +## +## It contains the certificates in PEM format and therefore +## can be directly used with curl / libcurl / php_curl, or with +## an Apache+mod_ssl webserver for SSL client authentication. +## Just configure this file as the SSLCACertificateFile. +## +## Conversion done with mk-ca-bundle.pl version 1.28. +## SHA256: c8f6733d1ff4e6a4769c182971a1234f95ae079247a9c439a13423fe8ba5c24f +## + + +GlobalSign Root CA +================== +-----BEGIN CERTIFICATE----- +MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkGA1UEBhMCQkUx +GTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jvb3QgQ0ExGzAZBgNVBAMTEkds +b2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAwMDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNV +BAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYD +VQQDExJHbG9iYWxTaWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDa +DuaZjc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavpxy0Sy6sc +THAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp1Wrjsok6Vjk4bwY8iGlb +Kk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdGsnUOhugZitVtbNV4FpWi6cgKOOvyJBNP +c1STE4U6G7weNLWLBYy5d4ux2x8gkasJU26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrX +gzT/LCrBbBlDSgeF59N89iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV +HRMBAf8EBTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0BAQUF +AAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOzyj1hTdNGCbM+w6Dj +Y1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE38NflNUVyRRBnMRddWQVDf9VMOyG +j/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymPAbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhH +hm4qxFYxldBniYUr+WymXUadDKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveC +X4XSQRjbgbMEHMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A== +-----END CERTIFICATE----- + +GlobalSign Root CA - R2 +======================= +-----BEGIN CERTIFICATE----- +MIIDujCCAqKgAwIBAgILBAAAAAABD4Ym5g0wDQYJKoZIhvcNAQEFBQAwTDEgMB4GA1UECxMXR2xv +YmFsU2lnbiBSb290IENBIC0gUjIxEzARBgNVBAoTCkdsb2JhbFNpZ24xEzARBgNVBAMTCkdsb2Jh +bFNpZ24wHhcNMDYxMjE1MDgwMDAwWhcNMjExMjE1MDgwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxT +aWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2ln +bjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKbPJA6+Lm8omUVCxKs+IVSbC9N/hHD6 +ErPLv4dfxn+G07IwXNb9rfF73OX4YJYJkhD10FPe+3t+c4isUoh7SqbKSaZeqKeMWhG8eoLrvozp +s6yWJQeXSpkqBy+0Hne/ig+1AnwblrjFuTosvNYSuetZfeLQBoZfXklqtTleiDTsvHgMCJiEbKjN +S7SgfQx5TfC4LcshytVsW33hoCmEofnTlEnLJGKRILzdC9XZzPnqJworc5HGnRusyMvo4KD0L5CL +TfuwNhv2GXqF4G3yYROIXJ/gkwpRl4pazq+r1feqCapgvdzZX99yqWATXgAByUr6P6TqBwMhAo6C +ygPCm48CAwEAAaOBnDCBmTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E +FgQUm+IHV2ccHsBqBt5ZtJot39wZhi4wNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL2NybC5nbG9i +YWxzaWduLm5ldC9yb290LXIyLmNybDAfBgNVHSMEGDAWgBSb4gdXZxwewGoG3lm0mi3f3BmGLjAN +BgkqhkiG9w0BAQUFAAOCAQEAmYFThxxol4aR7OBKuEQLq4GsJ0/WwbgcQ3izDJr86iw8bmEbTUsp +9Z8FHSbBuOmDAGJFtqkIk7mpM0sYmsL4h4hO291xNBrBVNpGP+DTKqttVCL1OmLNIG+6KYnX3ZHu +01yiPqFbQfXf5WRDLenVOavSot+3i9DAgBkcRcAtjOj4LaR0VknFBbVPFd5uRHg5h6h+u/N5GJG7 +9G+dwfCMNYxdAfvDbbnvRG15RjF+Cv6pgsH/76tuIMRQyV+dTZsXjAzlAcmgQWpzU/qlULRuJQ/7 +TBj0/VLZjmmx6BEP3ojY+x1J96relc8geMJgEtslQIxq/H5COEBkEveegeGTLg== +-----END CERTIFICATE----- + +Entrust.net Premium 2048 Secure Server CA +========================================= +-----BEGIN CERTIFICATE----- +MIIEKjCCAxKgAwIBAgIEOGPe+DANBgkqhkiG9w0BAQUFADCBtDEUMBIGA1UEChMLRW50cnVzdC5u +ZXQxQDA+BgNVBAsUN3d3dy5lbnRydXN0Lm5ldC9DUFNfMjA0OCBpbmNvcnAuIGJ5IHJlZi4gKGxp +bWl0cyBsaWFiLikxJTAjBgNVBAsTHChjKSAxOTk5IEVudHJ1c3QubmV0IExpbWl0ZWQxMzAxBgNV +BAMTKkVudHJ1c3QubmV0IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ICgyMDQ4KTAeFw05OTEyMjQx +NzUwNTFaFw0yOTA3MjQxNDE1MTJaMIG0MRQwEgYDVQQKEwtFbnRydXN0Lm5ldDFAMD4GA1UECxQ3 +d3d3LmVudHJ1c3QubmV0L0NQU18yMDQ4IGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTEl +MCMGA1UECxMcKGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDEzMDEGA1UEAxMqRW50cnVzdC5u +ZXQgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgKDIwNDgpMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A +MIIBCgKCAQEArU1LqRKGsuqjIAcVFmQqK0vRvwtKTY7tgHalZ7d4QMBzQshowNtTK91euHaYNZOL +Gp18EzoOH1u3Hs/lJBQesYGpjX24zGtLA/ECDNyrpUAkAH90lKGdCCmziAv1h3edVc3kw37XamSr +hRSGlVuXMlBvPci6Zgzj/L24ScF2iUkZ/cCovYmjZy/Gn7xxGWC4LeksyZB2ZnuU4q941mVTXTzW +nLLPKQP5L6RQstRIzgUyVYr9smRMDuSYB3Xbf9+5CFVghTAp+XtIpGmG4zU/HoZdenoVve8AjhUi +VBcAkCaTvA5JaJG/+EfTnZVCwQ5N328mz8MYIWJmQ3DW1cAH4QIDAQABo0IwQDAOBgNVHQ8BAf8E +BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUVeSB0RGAvtiJuQijMfmhJAkWuXAwDQYJ +KoZIhvcNAQEFBQADggEBADubj1abMOdTmXx6eadNl9cZlZD7Bh/KM3xGY4+WZiT6QBshJ8rmcnPy +T/4xmf3IDExoU8aAghOY+rat2l098c5u9hURlIIM7j+VrxGrD9cv3h8Dj1csHsm7mhpElesYT6Yf +zX1XEC+bBAlahLVu2B064dae0Wx5XnkcFMXj0EyTO2U87d89vqbllRrDtRnDvV5bu/8j72gZyxKT +J1wDLW8w0B62GqzeWvfRqqgnpv55gcR5mTNXuhKwqeBCbJPKVt7+bYQLCIt+jerXmCHG8+c8eS9e +nNFMFY3h7CI3zJpDC5fcgJCNs2ebb0gIFVbPv/ErfF6adulZkMV8gzURZVE= +-----END CERTIFICATE----- + +Baltimore CyberTrust Root +========================= +-----BEGIN CERTIFICATE----- +MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJRTESMBAGA1UE +ChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3li +ZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoXDTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMC +SUUxEjAQBgNVBAoTCUJhbHRpbW9yZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFs +dGltb3JlIEN5YmVyVHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKME +uyKrmD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjrIZ3AQSsB +UnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeKmpYcqWe4PwzV9/lSEy/C +G9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSuXmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9 +XbIGevOF6uvUA65ehD5f/xXtabz5OTZydc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjpr +l3RjM71oGDHweI12v/yejl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoI +VDaGezq1BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEB +BQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT929hkTI7gQCvlYpNRh +cL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3WgxjkzSswF07r51XgdIGn9w/xZchMB5 +hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsa +Y71k5h+3zvDyny67G7fyUIhzksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9H +RCwBXbsdtTLSR9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp +-----END CERTIFICATE----- + +Entrust Root Certification Authority +==================================== +-----BEGIN CERTIFICATE----- +MIIEkTCCA3mgAwIBAgIERWtQVDANBgkqhkiG9w0BAQUFADCBsDELMAkGA1UEBhMCVVMxFjAUBgNV +BAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0Lm5ldC9DUFMgaXMgaW5jb3Jw +b3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMWKGMpIDIwMDYgRW50cnVzdCwgSW5jLjEtMCsG +A1UEAxMkRW50cnVzdCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA2MTEyNzIwMjM0 +MloXDTI2MTEyNzIwNTM0MlowgbAxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMu +MTkwNwYDVQQLEzB3d3cuZW50cnVzdC5uZXQvQ1BTIGlzIGluY29ycG9yYXRlZCBieSByZWZlcmVu +Y2UxHzAdBgNVBAsTFihjKSAyMDA2IEVudHJ1c3QsIEluYy4xLTArBgNVBAMTJEVudHJ1c3QgUm9v +dCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +ALaVtkNC+sZtKm9I35RMOVcF7sN5EUFoNu3s/poBj6E4KPz3EEZmLk0eGrEaTsbRwJWIsMn/MYsz +A9u3g3s+IIRe7bJWKKf44LlAcTfFy0cOlypowCKVYhXbR9n10Cv/gkvJrT7eTNuQgFA/CYqEAOww +Cj0Yzfv9KlmaI5UXLEWeH25DeW0MXJj+SKfFI0dcXv1u5x609mhF0YaDW6KKjbHjKYD+JXGIrb68 +j6xSlkuqUY3kEzEZ6E5Nn9uss2rVvDlUccp6en+Q3X0dgNmBu1kmwhH+5pPi94DkZfs0Nw4pgHBN +rziGLp5/V6+eF67rHMsoIV+2HNjnogQi+dPa2MsCAwEAAaOBsDCBrTAOBgNVHQ8BAf8EBAMCAQYw +DwYDVR0TAQH/BAUwAwEB/zArBgNVHRAEJDAigA8yMDA2MTEyNzIwMjM0MlqBDzIwMjYxMTI3MjA1 +MzQyWjAfBgNVHSMEGDAWgBRokORnpKZTgMeGZqTx90tD+4S9bTAdBgNVHQ4EFgQUaJDkZ6SmU4DH +hmak8fdLQ/uEvW0wHQYJKoZIhvZ9B0EABBAwDhsIVjcuMTo0LjADAgSQMA0GCSqGSIb3DQEBBQUA +A4IBAQCT1DCw1wMgKtD5Y+iRDAUgqV8ZyntyTtSx29CW+1RaGSwMCPeyvIWonX9tO1KzKtvn1ISM +Y/YPyyYBkVBs9F8U4pN0wBOeMDpQ47RgxRzwIkSNcUesyBrJ6ZuaAGAT/3B+XxFNSRuzFVJ7yVTa +v52Vr2ua2J7p8eRDjeIRRDq/r72DQnNSi6q7pynP9WQcCk3RvKqsnyrQ/39/2n3qse0wJcGE2jTS +W3iDVuycNsMm4hH2Z0kdkquM++v/eu6FSqdQgPCnXEqULl8FmTxSQeDNtGPPAUO6nIPcj2A781q0 +tHuu2guQOHXvgR1m0vdXcDazv/wor3ElhVsT/h5/WrQ8 +-----END CERTIFICATE----- + +Comodo AAA Services root +======================== +-----BEGIN CERTIFICATE----- +MIIEMjCCAxqgAwIBAgIBATANBgkqhkiG9w0BAQUFADB7MQswCQYDVQQGEwJHQjEbMBkGA1UECAwS +R3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0Eg +TGltaXRlZDEhMB8GA1UEAwwYQUFBIENlcnRpZmljYXRlIFNlcnZpY2VzMB4XDTA0MDEwMTAwMDAw +MFoXDTI4MTIzMTIzNTk1OVowezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hl +c3RlcjEQMA4GA1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNV +BAMMGEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAL5AnfRu4ep2hxxNRUSOvkbIgwadwSr+GB+O5AL686tdUIoWMQuaBtDFcCLNSS1UY8y2bmhG +C1Pqy0wkwLxyTurxFa70VJoSCsN6sjNg4tqJVfMiWPPe3M/vg4aijJRPn2jymJBGhCfHdr/jzDUs +i14HZGWCwEiwqJH5YZ92IFCokcdmtet4YgNW8IoaE+oxox6gmf049vYnMlhvB/VruPsUK6+3qszW +Y19zjNoFmag4qMsXeDZRrOme9Hg6jc8P2ULimAyrL58OAd7vn5lJ8S3frHRNG5i1R8XlKdH5kBjH +Ypy+g8cmez6KJcfA3Z3mNWgQIJ2P2N7Sw4ScDV7oL8kCAwEAAaOBwDCBvTAdBgNVHQ4EFgQUoBEK +Iz6W8Qfs4q8p74Klf9AwpLQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wewYDVR0f +BHQwcjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20vQUFBQ2VydGlmaWNhdGVTZXJ2aWNl +cy5jcmwwNqA0oDKGMGh0dHA6Ly9jcmwuY29tb2RvLm5ldC9BQUFDZXJ0aWZpY2F0ZVNlcnZpY2Vz +LmNybDANBgkqhkiG9w0BAQUFAAOCAQEACFb8AvCb6P+k+tZ7xkSAzk/ExfYAWMymtrwUSWgEdujm +7l3sAg9g1o1QGE8mTgHj5rCl7r+8dFRBv/38ErjHT1r0iWAFf2C3BUrz9vHCv8S5dIa2LX1rzNLz +Rt0vxuBqw8M0Ayx9lt1awg6nCpnBBYurDC/zXDrPbDdVCYfeU0BsWO/8tqtlbgT2G9w84FoVxp7Z +8VlIMCFlA2zs6SFz7JsDoeA3raAVGI/6ugLOpyypEBMs1OUIJqsil2D4kF501KKaU73yqWjgom7C +12yxow+ev+to51byrvLjKzg6CYG1a4XXvi3tPxq3smPi9WIsgtRqAEFQ8TmDn5XpNpaYbg== +-----END CERTIFICATE----- + +QuoVadis Root CA 2 +================== +-----BEGIN CERTIFICATE----- +MIIFtzCCA5+gAwIBAgICBQkwDQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCQk0xGTAXBgNVBAoT +EFF1b1ZhZGlzIExpbWl0ZWQxGzAZBgNVBAMTElF1b1ZhZGlzIFJvb3QgQ0EgMjAeFw0wNjExMjQx +ODI3MDBaFw0zMTExMjQxODIzMzNaMEUxCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBM +aW1pdGVkMRswGQYDVQQDExJRdW9WYWRpcyBSb290IENBIDIwggIiMA0GCSqGSIb3DQEBAQUAA4IC +DwAwggIKAoICAQCaGMpLlA0ALa8DKYrwD4HIrkwZhR0In6spRIXzL4GtMh6QRr+jhiYaHv5+HBg6 +XJxgFyo6dIMzMH1hVBHL7avg5tKifvVrbxi3Cgst/ek+7wrGsxDp3MJGF/hd/aTa/55JWpzmM+Yk +lvc/ulsrHHo1wtZn/qtmUIttKGAr79dgw8eTvI02kfN/+NsRE8Scd3bBrrcCaoF6qUWD4gXmuVbB +lDePSHFjIuwXZQeVikvfj8ZaCuWw419eaxGrDPmF60Tp+ARz8un+XJiM9XOva7R+zdRcAitMOeGy +lZUtQofX1bOQQ7dsE/He3fbE+Ik/0XX1ksOR1YqI0JDs3G3eicJlcZaLDQP9nL9bFqyS2+r+eXyt +66/3FsvbzSUr5R/7mp/iUcw6UwxI5g69ybR2BlLmEROFcmMDBOAENisgGQLodKcftslWZvB1Jdxn +wQ5hYIizPtGo/KPaHbDRsSNU30R2be1B2MGyIrZTHN81Hdyhdyox5C315eXbyOD/5YDXC2Og/zOh +D7osFRXql7PSorW+8oyWHhqPHWykYTe5hnMz15eWniN9gqRMgeKh0bpnX5UHoycR7hYQe7xFSkyy +BNKr79X9DFHOUGoIMfmR2gyPZFwDwzqLID9ujWc9Otb+fVuIyV77zGHcizN300QyNQliBJIWENie +J0f7OyHj+OsdWwIDAQABo4GwMIGtMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgEGMB0GA1Ud +DgQWBBQahGK8SEwzJQTU7tD2A8QZRtGUazBuBgNVHSMEZzBlgBQahGK8SEwzJQTU7tD2A8QZRtGU +a6FJpEcwRTELMAkGA1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxGzAZBgNVBAMT +ElF1b1ZhZGlzIFJvb3QgQ0EgMoICBQkwDQYJKoZIhvcNAQEFBQADggIBAD4KFk2fBluornFdLwUv +Z+YTRYPENvbzwCYMDbVHZF34tHLJRqUDGCdViXh9duqWNIAXINzng/iN/Ae42l9NLmeyhP3ZRPx3 +UIHmfLTJDQtyU/h2BwdBR5YM++CCJpNVjP4iH2BlfF/nJrP3MpCYUNQ3cVX2kiF495V5+vgtJodm +VjB3pjd4M1IQWK4/YY7yarHvGH5KWWPKjaJW1acvvFYfzznB4vsKqBUsfU16Y8Zsl0Q80m/DShcK ++JDSV6IZUaUtl0HaB0+pUNqQjZRG4T7wlP0QADj1O+hA4bRuVhogzG9Yje0uRY/W6ZM/57Es3zrW +IozchLsib9D45MY56QSIPMO661V6bYCZJPVsAfv4l7CUW+v90m/xd2gNNWQjrLhVoQPRTUIZ3Ph1 +WVaj+ahJefivDrkRoHy3au000LYmYjgahwz46P0u05B/B5EqHdZ+XIWDmbA4CD/pXvk1B+TJYm5X +f6dQlfe6yJvmjqIBxdZmv3lh8zwc4bmCXF2gw+nYSL0ZohEUGW6yhhtoPkg3Goi3XZZenMfvJ2II +4pEZXNLxId26F0KCl3GBUzGpn/Z9Yr9y4aOTHcyKJloJONDO1w2AFrR4pTqHTI2KpdVGl/IsELm8 +VCLAAVBpQ570su9t+Oza8eOx79+Rj1QqCyXBJhnEUhAFZdWCEOrCMc0u +-----END CERTIFICATE----- + +QuoVadis Root CA 3 +================== +-----BEGIN CERTIFICATE----- +MIIGnTCCBIWgAwIBAgICBcYwDQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCQk0xGTAXBgNVBAoT +EFF1b1ZhZGlzIExpbWl0ZWQxGzAZBgNVBAMTElF1b1ZhZGlzIFJvb3QgQ0EgMzAeFw0wNjExMjQx +OTExMjNaFw0zMTExMjQxOTA2NDRaMEUxCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBM +aW1pdGVkMRswGQYDVQQDExJRdW9WYWRpcyBSb290IENBIDMwggIiMA0GCSqGSIb3DQEBAQUAA4IC +DwAwggIKAoICAQDMV0IWVJzmmNPTTe7+7cefQzlKZbPoFog02w1ZkXTPkrgEQK0CSzGrvI2RaNgg +DhoB4hp7Thdd4oq3P5kazethq8Jlph+3t723j/z9cI8LoGe+AaJZz3HmDyl2/7FWeUUrH556VOij +KTVopAFPD6QuN+8bv+OPEKhyq1hX51SGyMnzW9os2l2ObjyjPtr7guXd8lyyBTNvijbO0BNO/79K +DDRMpsMhvVAEVeuxu537RR5kFd5VAYwCdrXLoT9CabwvvWhDFlaJKjdhkf2mrk7AyxRllDdLkgbv +BNDInIjbC3uBr7E9KsRlOni27tyAsdLTmZw67mtaa7ONt9XOnMK+pUsvFrGeaDsGb659n/je7Mwp +p5ijJUMv7/FfJuGITfhebtfZFG4ZM2mnO4SJk8RTVROhUXhA+LjJou57ulJCg54U7QVSWllWp5f8 +nT8KKdjcT5EOE7zelaTfi5m+rJsziO+1ga8bxiJTyPbH7pcUsMV8eFLI8M5ud2CEpukqdiDtWAEX +MJPpGovgc2PZapKUSU60rUqFxKMiMPwJ7Wgic6aIDFUhWMXhOp8q3crhkODZc6tsgLjoC2SToJyM +Gf+z0gzskSaHirOi4XCPLArlzW1oUevaPwV/izLmE1xr/l9A4iLItLRkT9a6fUg+qGkM17uGcclz +uD87nSVL2v9A6wIDAQABo4IBlTCCAZEwDwYDVR0TAQH/BAUwAwEB/zCB4QYDVR0gBIHZMIHWMIHT +BgkrBgEEAb5YAAMwgcUwgZMGCCsGAQUFBwICMIGGGoGDQW55IHVzZSBvZiB0aGlzIENlcnRpZmlj +YXRlIGNvbnN0aXR1dGVzIGFjY2VwdGFuY2Ugb2YgdGhlIFF1b1ZhZGlzIFJvb3QgQ0EgMyBDZXJ0 +aWZpY2F0ZSBQb2xpY3kgLyBDZXJ0aWZpY2F0aW9uIFByYWN0aWNlIFN0YXRlbWVudC4wLQYIKwYB +BQUHAgEWIWh0dHA6Ly93d3cucXVvdmFkaXNnbG9iYWwuY29tL2NwczALBgNVHQ8EBAMCAQYwHQYD +VR0OBBYEFPLAE+CCQz777i9nMpY1XNu4ywLQMG4GA1UdIwRnMGWAFPLAE+CCQz777i9nMpY1XNu4 +ywLQoUmkRzBFMQswCQYDVQQGEwJCTTEZMBcGA1UEChMQUXVvVmFkaXMgTGltaXRlZDEbMBkGA1UE +AxMSUXVvVmFkaXMgUm9vdCBDQSAzggIFxjANBgkqhkiG9w0BAQUFAAOCAgEAT62gLEz6wPJv92ZV +qyM07ucp2sNbtrCD2dDQ4iH782CnO11gUyeim/YIIirnv6By5ZwkajGxkHon24QRiSemd1o417+s +hvzuXYO8BsbRd2sPbSQvS3pspweWyuOEn62Iix2rFo1bZhfZFvSLgNLd+LJ2w/w4E6oM3kJpK27z +POuAJ9v1pkQNn1pVWQvVDVJIxa6f8i+AxeoyUDUSly7B4f/xI4hROJ/yZlZ25w9Rl6VSDE1JUZU2 +Pb+iSwwQHYaZTKrzchGT5Or2m9qoXadNt54CrnMAyNojA+j56hl0YgCUyyIgvpSnWbWCar6ZeXqp +8kokUvd0/bpO5qgdAm6xDYBEwa7TIzdfu4V8K5Iu6H6li92Z4b8nby1dqnuH/grdS/yO9SbkbnBC +bjPsMZ57k8HkyWkaPcBrTiJt7qtYTcbQQcEr6k8Sh17rRdhs9ZgC06DYVYoGmRmioHfRMJ6szHXu +g/WwYjnPbFfiTNKRCw51KBuav/0aQ/HKd/s7j2G4aSgWQgRecCocIdiP4b0jWy10QJLZYxkNc91p +vGJHvOB0K7Lrfb5BG7XARsWhIstfTsEokt4YutUqKLsRixeTmJlglFwjz1onl14LBQaTNx47aTbr +qZ5hHY8y2o4M1nQ+ewkk2gF3R8Q7zTSMmfXK4SVhM7JZG+Ju1zdXtg2pEto= +-----END CERTIFICATE----- + +Security Communication Root CA +============================== +-----BEGIN CERTIFICATE----- +MIIDWjCCAkKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBQMQswCQYDVQQGEwJKUDEYMBYGA1UEChMP +U0VDT00gVHJ1c3QubmV0MScwJQYDVQQLEx5TZWN1cml0eSBDb21tdW5pY2F0aW9uIFJvb3RDQTEw +HhcNMDMwOTMwMDQyMDQ5WhcNMjMwOTMwMDQyMDQ5WjBQMQswCQYDVQQGEwJKUDEYMBYGA1UEChMP +U0VDT00gVHJ1c3QubmV0MScwJQYDVQQLEx5TZWN1cml0eSBDb21tdW5pY2F0aW9uIFJvb3RDQTEw +ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCzs/5/022x7xZ8V6UMbXaKL0u/ZPtM7orw +8yl89f/uKuDp6bpbZCKamm8sOiZpUQWZJtzVHGpxxpp9Hp3dfGzGjGdnSj74cbAZJ6kJDKaVv0uM +DPpVmDvY6CKhS3E4eayXkmmziX7qIWgGmBSWh9JhNrxtJ1aeV+7AwFb9Ms+k2Y7CI9eNqPPYJayX +5HA49LY6tJ07lyZDo6G8SVlyTCMwhwFY9k6+HGhWZq/NQV3Is00qVUarH9oe4kA92819uZKAnDfd +DJZkndwi92SL32HeFZRSFaB9UslLqCHJxrHty8OVYNEP8Ktw+N/LTX7s1vqr2b1/VPKl6Xn62dZ2 +JChzAgMBAAGjPzA9MB0GA1UdDgQWBBSgc0mZaNyFW2XjmygvV5+9M7wHSDALBgNVHQ8EBAMCAQYw +DwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAaECpqLvkT115swW1F7NgE+vGkl3g +0dNq/vu+m22/xwVtWSDEHPC32oRYAmP6SBbvT6UL90qY8j+eG61Ha2POCEfrUj94nK9NrvjVT8+a +mCoQQTlSxN3Zmw7vkwGusi7KaEIkQmywszo+zenaSMQVy+n5Bw+SUEmK3TGXX8npN6o7WWWXlDLJ +s58+OmJYxUmtYg5xpTKqL8aJdkNAExNnPaJUJRDL8Try2frbSVa7pv6nQTXD4IhhyYjH3zYQIphZ +6rBK+1YWc26sTfcioU+tHXotRSflMMFe8toTyyVCUZVHA4xsIcx0Qu1T/zOLjw9XARYvz6buyXAi +FL39vmwLAw== +-----END CERTIFICATE----- + +XRamp Global CA Root +==================== +-----BEGIN CERTIFICATE----- +MIIEMDCCAxigAwIBAgIQUJRs7Bjq1ZxN1ZfvdY+grTANBgkqhkiG9w0BAQUFADCBgjELMAkGA1UE +BhMCVVMxHjAcBgNVBAsTFXd3dy54cmFtcHNlY3VyaXR5LmNvbTEkMCIGA1UEChMbWFJhbXAgU2Vj +dXJpdHkgU2VydmljZXMgSW5jMS0wKwYDVQQDEyRYUmFtcCBHbG9iYWwgQ2VydGlmaWNhdGlvbiBB +dXRob3JpdHkwHhcNMDQxMTAxMTcxNDA0WhcNMzUwMTAxMDUzNzE5WjCBgjELMAkGA1UEBhMCVVMx +HjAcBgNVBAsTFXd3dy54cmFtcHNlY3VyaXR5LmNvbTEkMCIGA1UEChMbWFJhbXAgU2VjdXJpdHkg +U2VydmljZXMgSW5jMS0wKwYDVQQDEyRYUmFtcCBHbG9iYWwgQ2VydGlmaWNhdGlvbiBBdXRob3Jp +dHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCYJB69FbS638eMpSe2OAtp87ZOqCwu +IR1cRN8hXX4jdP5efrRKt6atH67gBhbim1vZZ3RrXYCPKZ2GG9mcDZhtdhAoWORlsH9KmHmf4MMx +foArtYzAQDsRhtDLooY2YKTVMIJt2W7QDxIEM5dfT2Fa8OT5kavnHTu86M/0ay00fOJIYRyO82FE +zG+gSqmUsE3a56k0enI4qEHMPJQRfevIpoy3hsvKMzvZPTeL+3o+hiznc9cKV6xkmxnr9A8ECIqs +AxcZZPRaJSKNNCyy9mgdEm3Tih4U2sSPpuIjhdV6Db1q4Ons7Be7QhtnqiXtRYMh/MHJfNViPvry +xS3T/dRlAgMBAAGjgZ8wgZwwEwYJKwYBBAGCNxQCBAYeBABDAEEwCwYDVR0PBAQDAgGGMA8GA1Ud +EwEB/wQFMAMBAf8wHQYDVR0OBBYEFMZPoj0GY4QJnM5i5ASsjVy16bYbMDYGA1UdHwQvMC0wK6Ap +oCeGJWh0dHA6Ly9jcmwueHJhbXBzZWN1cml0eS5jb20vWEdDQS5jcmwwEAYJKwYBBAGCNxUBBAMC +AQEwDQYJKoZIhvcNAQEFBQADggEBAJEVOQMBG2f7Shz5CmBbodpNl2L5JFMn14JkTpAuw0kbK5rc +/Kh4ZzXxHfARvbdI4xD2Dd8/0sm2qlWkSLoC295ZLhVbO50WfUfXN+pfTXYSNrsf16GBBEYgoyxt +qZ4Bfj8pzgCT3/3JknOJiWSe5yvkHJEs0rnOfc5vMZnT5r7SHpDwCRR5XCOrTdLaIR9NmXmd4c8n +nxCbHIgNsIpkQTG4DmyQJKSbXHGPurt+HBvbaoAPIbzp26a3QPSyi6mx5O+aGtA9aZnuqCij4Tyz +8LIRnM98QObd50N9otg6tamN8jSZxNQQ4Qb9CYQQO+7ETPTsJ3xCwnR8gooJybQDJbw= +-----END CERTIFICATE----- + +Go Daddy Class 2 CA +=================== +-----BEGIN CERTIFICATE----- +MIIEADCCAuigAwIBAgIBADANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEhMB8GA1UEChMY +VGhlIEdvIERhZGR5IEdyb3VwLCBJbmMuMTEwLwYDVQQLEyhHbyBEYWRkeSBDbGFzcyAyIENlcnRp +ZmljYXRpb24gQXV0aG9yaXR5MB4XDTA0MDYyOTE3MDYyMFoXDTM0MDYyOTE3MDYyMFowYzELMAkG +A1UEBhMCVVMxITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28g +RGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASAwDQYJKoZIhvcNAQEBBQAD +ggENADCCAQgCggEBAN6d1+pXGEmhW+vXX0iG6r7d/+TvZxz0ZWizV3GgXne77ZtJ6XCAPVYYYwhv +2vLM0D9/AlQiVBDYsoHUwHU9S3/Hd8M+eKsaA7Ugay9qK7HFiH7Eux6wwdhFJ2+qN1j3hybX2C32 +qRe3H3I2TqYXP2WYktsqbl2i/ojgC95/5Y0V4evLOtXiEqITLdiOr18SPaAIBQi2XKVlOARFmR6j +YGB0xUGlcmIbYsUfb18aQr4CUWWoriMYavx4A6lNf4DD+qta/KFApMoZFv6yyO9ecw3ud72a9nmY +vLEHZ6IVDd2gWMZEewo+YihfukEHU1jPEX44dMX4/7VpkI+EdOqXG68CAQOjgcAwgb0wHQYDVR0O +BBYEFNLEsNKR1EwRcbNhyz2h/t2oatTjMIGNBgNVHSMEgYUwgYKAFNLEsNKR1EwRcbNhyz2h/t2o +atTjoWekZTBjMQswCQYDVQQGEwJVUzEhMB8GA1UEChMYVGhlIEdvIERhZGR5IEdyb3VwLCBJbmMu +MTEwLwYDVQQLEyhHbyBEYWRkeSBDbGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwG +A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBADJL87LKPpH8EsahB4yOd6AzBhRckB4Y9wim +PQoZ+YeAEW5p5JYXMP80kWNyOO7MHAGjHZQopDH2esRU1/blMVgDoszOYtuURXO1v0XJJLXVggKt +I3lpjbi2Tc7PTMozI+gciKqdi0FuFskg5YmezTvacPd+mSYgFFQlq25zheabIZ0KbIIOqPjCDPoQ +HmyW74cNxA9hi63ugyuV+I6ShHI56yDqg+2DzZduCLzrTia2cyvk0/ZM/iZx4mERdEr/VxqHD3VI +Ls9RaRegAhJhldXRQLIQTO7ErBBDpqWeCtWVYpoNz4iCxTIM5CufReYNnyicsbkqWletNw+vHX/b +vZ8= +-----END CERTIFICATE----- + +Starfield Class 2 CA +==================== +-----BEGIN CERTIFICATE----- +MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzElMCMGA1UEChMc +U3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZpZWxkIENsYXNzIDIg +Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQwNjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBo +MQswCQYDVQQGEwJVUzElMCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAG +A1UECxMpU3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqG +SIb3DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf8MOh2tTY +bitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN+lq2cwQlZut3f+dZxkqZ +JRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVm +epsZGD3/cVE8MC5fvj13c7JdBmzDI1aaK4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSN +F4Azbl5KXZnJHoe0nRrA1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HF +MIHCMB0GA1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fRzt0f +hvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNo +bm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBDbGFzcyAyIENlcnRpZmljYXRpb24g +QXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGs +afPzWdqbAYcaT1epoXkJKtv3L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLM +PUxA2IGvd56Deruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl +xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynpVSJYACPq4xJD +KVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEYWQPJIrSPnNVeKtelttQKbfi3 +QBFGmh95DmK/D5fs4C8fF5Q= +-----END CERTIFICATE----- + +DigiCert Assured ID Root CA +=========================== +-----BEGIN CERTIFICATE----- +MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBlMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQw +IgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzEx +MTEwMDAwMDAwWjBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQL +ExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0Ew +ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7cJpSIqvTO +9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYPmDI2dsze3Tyoou9q+yHy +UmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW +/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpy +oeb6pNnVFzF1roV9Iq4/AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whf +GHdPAgMBAAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRF +66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYunpyGd823IDzANBgkq +hkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRCdWKuh+vy1dneVrOfzM4UKLkNl2Bc +EkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTffwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38Fn +SbNd67IJKusm7Xi+fT8r87cmNW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i +8b5QZ7dsvfPxH2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe ++o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g== +-----END CERTIFICATE----- + +DigiCert Global Root CA +======================= +-----BEGIN CERTIFICATE----- +MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSAw +HgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBDQTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAw +MDAwMDBaMGExCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3 +dy5kaWdpY2VydC5jb20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkq +hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsBCSDMAZOn +TjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97nh6Vfe63SKMI2tavegw5 +BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt43C/dxC//AH2hdmoRBBYMql1GNXRor5H +4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7PT19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y +7vrTC0LUq7dBMtoM1O/4gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQAB +o2MwYTAOBgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbRTLtm +8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUwDQYJKoZIhvcNAQEF +BQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/EsrhMAtudXH/vTBH1jLuG2cenTnmCmr +EbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIt +tep3Sp+dWOIrWcBAI+0tKIJFPnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886 +UAb3LujEV0lsYSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk +CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= +-----END CERTIFICATE----- + +DigiCert High Assurance EV Root CA +================================== +-----BEGIN CERTIFICATE----- +MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw +KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw +MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ +MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu +Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t +Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS +OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3 +MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ +NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe +h10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMB +Af8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSY +JhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQ +V8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFp +myPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkK +mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe +vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K +-----END CERTIFICATE----- + +DST Root CA X3 +============== +-----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/MSQwIgYDVQQK +ExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMTDkRTVCBSb290IENBIFgzMB4X +DTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVowPzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1 +cmUgVHJ1c3QgQ28uMRcwFQYDVQQDEw5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBAN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmT +rE4Orz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEqOLl5CjH9 +UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9bxiqKqy69cK3FCxolkHRy +xXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40d +utolucbY38EVAjqr2m7xPi71XAicPNaDaeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0T +AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQ +MA0GCSqGSIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69ikug +dB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXrAvHRAosZy5Q6XkjE +GB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZzR8srzJmwN0jP41ZL9c8PDHIyh8bw +RLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubS +fZGL+T0yjWW06XyxV3bqxbYoOb8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + +SwissSign Gold CA - G2 +====================== +-----BEGIN CERTIFICATE----- +MIIFujCCA6KgAwIBAgIJALtAHEP1Xk+wMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNVBAYTAkNIMRUw +EwYDVQQKEwxTd2lzc1NpZ24gQUcxHzAdBgNVBAMTFlN3aXNzU2lnbiBHb2xkIENBIC0gRzIwHhcN +MDYxMDI1MDgzMDM1WhcNMzYxMDI1MDgzMDM1WjBFMQswCQYDVQQGEwJDSDEVMBMGA1UEChMMU3dp +c3NTaWduIEFHMR8wHQYDVQQDExZTd2lzc1NpZ24gR29sZCBDQSAtIEcyMIICIjANBgkqhkiG9w0B +AQEFAAOCAg8AMIICCgKCAgEAr+TufoskDhJuqVAtFkQ7kpJcyrhdhJJCEyq8ZVeCQD5XJM1QiyUq +t2/876LQwB8CJEoTlo8jE+YoWACjR8cGp4QjK7u9lit/VcyLwVcfDmJlD909Vopz2q5+bbqBHH5C +jCA12UNNhPqE21Is8w4ndwtrvxEvcnifLtg+5hg3Wipy+dpikJKVyh+c6bM8K8vzARO/Ws/BtQpg +vd21mWRTuKCWs2/iJneRjOBiEAKfNA+k1ZIzUd6+jbqEemA8atufK+ze3gE/bk3lUIbLtK/tREDF +ylqM2tIrfKjuvqblCqoOpd8FUrdVxyJdMmqXl2MT28nbeTZ7hTpKxVKJ+STnnXepgv9VHKVxaSvR +AiTysybUa9oEVeXBCsdtMDeQKuSeFDNeFhdVxVu1yzSJkvGdJo+hB9TGsnhQ2wwMC3wLjEHXuend +jIj3o02yMszYF9rNt85mndT9Xv+9lz4pded+p2JYryU0pUHHPbwNUMoDAw8IWh+Vc3hiv69yFGkO +peUDDniOJihC8AcLYiAQZzlG+qkDzAQ4embvIIO1jEpWjpEA/I5cgt6IoMPiaG59je883WX0XaxR +7ySArqpWl2/5rX3aYT+YdzylkbYcjCbaZaIJbcHiVOO5ykxMgI93e2CaHt+28kgeDrpOVG2Y4OGi +GqJ3UM/EY5LsRxmd6+ZrzsECAwEAAaOBrDCBqTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUw +AwEB/zAdBgNVHQ4EFgQUWyV7lqRlUX64OfPAeGZe6Drn8O4wHwYDVR0jBBgwFoAUWyV7lqRlUX64 +OfPAeGZe6Drn8O4wRgYDVR0gBD8wPTA7BglghXQBWQECAQEwLjAsBggrBgEFBQcCARYgaHR0cDov +L3JlcG9zaXRvcnkuc3dpc3NzaWduLmNvbS8wDQYJKoZIhvcNAQEFBQADggIBACe645R88a7A3hfm +5djV9VSwg/S7zV4Fe0+fdWavPOhWfvxyeDgD2StiGwC5+OlgzczOUYrHUDFu4Up+GC9pWbY9ZIEr +44OE5iKHjn3g7gKZYbge9LgriBIWhMIxkziWMaa5O1M/wySTVltpkuzFwbs4AOPsF6m43Md8AYOf +Mke6UiI0HTJ6CVanfCU2qT1L2sCCbwq7EsiHSycR+R4tx5M/nttfJmtS2S6K8RTGRI0Vqbe/vd6m +Gu6uLftIdxf+u+yvGPUqUfA5hJeVbG4bwyvEdGB5JbAKJ9/fXtI5z0V9QkvfsywexcZdylU6oJxp +mo/a77KwPJ+HbBIrZXAVUjEaJM9vMSNQH4xPjyPDdEFjHFWoFN0+4FFQz/EbMFYOkrCChdiDyyJk +vC24JdVUorgG6q2SpCSgwYa1ShNqR88uC1aVVMvOmttqtKay20EIhid392qgQmwLOM7XdVAyksLf +KzAiSNDVQTglXaTpXZ/GlHXQRf0wl0OPkKsKx4ZzYEppLd6leNcG2mqeSz53OiATIgHQv2ieY2Br +NU0LbbqhPcCT4H8js1WtciVORvnSFu+wZMEBnunKoGqYDs/YYPIvSbjkQuE4NRb0yG5P94FW6Lqj +viOvrv1vA+ACOzB2+httQc8Bsem4yWb02ybzOqR08kkkW8mw0FfB+j564ZfJ +-----END CERTIFICATE----- + +SwissSign Silver CA - G2 +======================== +-----BEGIN CERTIFICATE----- +MIIFvTCCA6WgAwIBAgIITxvUL1S7L0swDQYJKoZIhvcNAQEFBQAwRzELMAkGA1UEBhMCQ0gxFTAT +BgNVBAoTDFN3aXNzU2lnbiBBRzEhMB8GA1UEAxMYU3dpc3NTaWduIFNpbHZlciBDQSAtIEcyMB4X +DTA2MTAyNTA4MzI0NloXDTM2MTAyNTA4MzI0NlowRzELMAkGA1UEBhMCQ0gxFTATBgNVBAoTDFN3 +aXNzU2lnbiBBRzEhMB8GA1UEAxMYU3dpc3NTaWduIFNpbHZlciBDQSAtIEcyMIICIjANBgkqhkiG +9w0BAQEFAAOCAg8AMIICCgKCAgEAxPGHf9N4Mfc4yfjDmUO8x/e8N+dOcbpLj6VzHVxumK4DV644 +N0MvFz0fyM5oEMF4rhkDKxD6LHmD9ui5aLlV8gREpzn5/ASLHvGiTSf5YXu6t+WiE7brYT7QbNHm ++/pe7R20nqA1W6GSy/BJkv6FCgU+5tkL4k+73JU3/JHpMjUi0R86TieFnbAVlDLaYQ1HTWBCrpJH +6INaUFjpiou5XaHc3ZlKHzZnu0jkg7Y360g6rw9njxcH6ATK72oxh9TAtvmUcXtnZLi2kUpCe2Uu +MGoM9ZDulebyzYLs2aFK7PayS+VFheZteJMELpyCbTapxDFkH4aDCyr0NQp4yVXPQbBH6TCfmb5h +qAaEuSh6XzjZG6k4sIN/c8HDO0gqgg8hm7jMqDXDhBuDsz6+pJVpATqJAHgE2cn0mRmrVn5bi4Y5 +FZGkECwJMoBgs5PAKrYYC51+jUnyEEp/+dVGLxmSo5mnJqy7jDzmDrxHB9xzUfFwZC8I+bRHHTBs +ROopN4WSaGa8gzj+ezku01DwH/teYLappvonQfGbGHLy9YR0SslnxFSuSGTfjNFusB3hB48IHpmc +celM2KX3RxIfdNFRnobzwqIjQAtz20um53MGjMGg6cFZrEb65i/4z3GcRm25xBWNOHkDRUjvxF3X +CO6HOSKGsg0PWEP3calILv3q1h8CAwEAAaOBrDCBqTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/ +BAUwAwEB/zAdBgNVHQ4EFgQUF6DNweRBtjpbO8tFnb0cwpj6hlgwHwYDVR0jBBgwFoAUF6DNweRB +tjpbO8tFnb0cwpj6hlgwRgYDVR0gBD8wPTA7BglghXQBWQEDAQEwLjAsBggrBgEFBQcCARYgaHR0 +cDovL3JlcG9zaXRvcnkuc3dpc3NzaWduLmNvbS8wDQYJKoZIhvcNAQEFBQADggIBAHPGgeAn0i0P +4JUw4ppBf1AsX19iYamGamkYDHRJ1l2E6kFSGG9YrVBWIGrGvShpWJHckRE1qTodvBqlYJ7YH39F +kWnZfrt4csEGDyrOj4VwYaygzQu4OSlWhDJOhrs9xCrZ1x9y7v5RoSJBsXECYxqCsGKrXlcSH9/L +3XWgwF15kIwb4FDm3jH+mHtwX6WQ2K34ArZv02DdQEsixT2tOnqfGhpHkXkzuoLcMmkDlm4fS/Bx +/uNncqCxv1yL5PqZIseEuRuNI5c/7SXgz2W79WEE790eslpBIlqhn10s6FvJbakMDHiqYMZWjwFa +DGi8aRl5xB9+lwW/xekkUV7U1UtT7dkjWjYDZaPBA61BMPNGG4WQr2W11bHkFlt4dR2Xem1ZqSqP +e97Dh4kQmUlzeMg9vVE1dCrV8X5pGyq7O70luJpaPXJhkGaH7gzWTdQRdAtq/gsD/KNVV4n+Ssuu +WxcFyPKNIzFTONItaj+CuY0IavdeQXRuwxF+B6wpYJE/OMpXEA29MC/HpeZBoNquBYeaoKRlbEwJ +DIm6uNO5wJOKMPqN5ZprFQFOZ6raYlY+hAhm0sQ2fac+EPyI4NSA5QC9qvNOBqN6avlicuMJT+ub +DgEj8Z+7fNzcbBGXJbLytGMU0gYqZ4yD9c7qB9iaah7s5Aq7KkzrCWA5zspi2C5u +-----END CERTIFICATE----- + +SecureTrust CA +============== +-----BEGIN CERTIFICATE----- +MIIDuDCCAqCgAwIBAgIQDPCOXAgWpa1Cf/DrJxhZ0DANBgkqhkiG9w0BAQUFADBIMQswCQYDVQQG +EwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24xFzAVBgNVBAMTDlNlY3VyZVRy +dXN0IENBMB4XDTA2MTEwNzE5MzExOFoXDTI5MTIzMTE5NDA1NVowSDELMAkGA1UEBhMCVVMxIDAe +BgNVBAoTF1NlY3VyZVRydXN0IENvcnBvcmF0aW9uMRcwFQYDVQQDEw5TZWN1cmVUcnVzdCBDQTCC +ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKukgeWVzfX2FI7CT8rU4niVWJxB4Q2ZQCQX +OZEzZum+4YOvYlyJ0fwkW2Gz4BERQRwdbvC4u/jep4G6pkjGnx29vo6pQT64lO0pGtSO0gMdA+9t +DWccV9cGrcrI9f4Or2YlSASWC12juhbDCE/RRvgUXPLIXgGZbf2IzIaowW8xQmxSPmjL8xk037uH +GFaAJsTQ3MBv396gwpEWoGQRS0S8Hvbn+mPeZqx2pHGj7DaUaHp3pLHnDi+BeuK1cobvomuL8A/b +01k/unK8RCSc43Oz969XL0Imnal0ugBS8kvNU3xHCzaFDmapCJcWNFfBZveA4+1wVMeT4C4oFVmH +ursCAwEAAaOBnTCBmjATBgkrBgEEAYI3FAIEBh4EAEMAQTALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/ +BAUwAwEB/zAdBgNVHQ4EFgQUQjK2FvoE/f5dS3rD/fdMQB1aQ68wNAYDVR0fBC0wKzApoCegJYYj +aHR0cDovL2NybC5zZWN1cmV0cnVzdC5jb20vU1RDQS5jcmwwEAYJKwYBBAGCNxUBBAMCAQAwDQYJ +KoZIhvcNAQEFBQADggEBADDtT0rhWDpSclu1pqNlGKa7UTt36Z3q059c4EVlew3KW+JwULKUBRSu +SceNQQcSc5R+DCMh/bwQf2AQWnL1mA6s7Ll/3XpvXdMc9P+IBWlCqQVxyLesJugutIxq/3HcuLHf +mbx8IVQr5Fiiu1cprp6poxkmD5kuCLDv/WnPmRoJjeOnnyvJNjR7JLN4TJUXpAYmHrZkUjZfYGfZ +nMUFdAvnZyPSCPyI6a6Lf+Ew9Dd+/cYy2i2eRDAwbO4H3tI0/NL/QPZL9GZGBlSm8jIKYyYwa5vR +3ItHuuG51WLQoqD0ZwV4KWMabwTW+MZMo5qxN7SN5ShLHZ4swrhovO0C7jE= +-----END CERTIFICATE----- + +Secure Global CA +================ +-----BEGIN CERTIFICATE----- +MIIDvDCCAqSgAwIBAgIQB1YipOjUiolN9BPI8PjqpTANBgkqhkiG9w0BAQUFADBKMQswCQYDVQQG +EwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24xGTAXBgNVBAMTEFNlY3VyZSBH +bG9iYWwgQ0EwHhcNMDYxMTA3MTk0MjI4WhcNMjkxMjMxMTk1MjA2WjBKMQswCQYDVQQGEwJVUzEg +MB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24xGTAXBgNVBAMTEFNlY3VyZSBHbG9iYWwg +Q0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvNS7YrGxVaQZx5RNoJLNP2MwhR/jx +YDiJiQPpvepeRlMJ3Fz1Wuj3RSoC6zFh1ykzTM7HfAo3fg+6MpjhHZevj8fcyTiW89sa/FHtaMbQ +bqR8JNGuQsiWUGMu4P51/pinX0kuleM5M2SOHqRfkNJnPLLZ/kG5VacJjnIFHovdRIWCQtBJwB1g +8NEXLJXr9qXBkqPFwqcIYA1gBBCWeZ4WNOaptvolRTnIHmX5k/Wq8VLcmZg9pYYaDDUz+kulBAYV +HDGA76oYa8J719rO+TMg1fW9ajMtgQT7sFzUnKPiXB3jqUJ1XnvUd+85VLrJChgbEplJL4hL/VBi +0XPnj3pDAgMBAAGjgZ0wgZowEwYJKwYBBAGCNxQCBAYeBABDAEEwCwYDVR0PBAQDAgGGMA8GA1Ud +EwEB/wQFMAMBAf8wHQYDVR0OBBYEFK9EBMJBfkiD2045AuzshHrmzsmkMDQGA1UdHwQtMCswKaAn +oCWGI2h0dHA6Ly9jcmwuc2VjdXJldHJ1c3QuY29tL1NHQ0EuY3JsMBAGCSsGAQQBgjcVAQQDAgEA +MA0GCSqGSIb3DQEBBQUAA4IBAQBjGghAfaReUw132HquHw0LURYD7xh8yOOvaliTFGCRsoTciE6+ +OYo68+aCiV0BN7OrJKQVDpI1WkpEXk5X+nXOH0jOZvQ8QCaSmGwb7iRGDBezUqXbpZGRzzfTb+cn +CDpOGR86p1hcF895P4vkp9MmI50mD1hp/Ed+stCNi5O/KU9DaXR2Z0vPB4zmAve14bRDtUstFJ/5 +3CYNv6ZHdAbYiNE6KTCEztI5gGIbqMdXSbxqVVFnFUq+NQfk1XWYN3kwFNspnWzFacxHVaIw98xc +f8LDmBxrThaA63p4ZUWiABqvDA1VZDRIuJK58bRQKfJPIx/abKwfROHdI3hRW8cW +-----END CERTIFICATE----- + +COMODO Certification Authority +============================== +-----BEGIN CERTIFICATE----- +MIIEHTCCAwWgAwIBAgIQToEtioJl4AsC7j41AkblPTANBgkqhkiG9w0BAQUFADCBgTELMAkGA1UE +BhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgG +A1UEChMRQ09NT0RPIENBIExpbWl0ZWQxJzAlBgNVBAMTHkNPTU9ETyBDZXJ0aWZpY2F0aW9uIEF1 +dGhvcml0eTAeFw0wNjEyMDEwMDAwMDBaFw0yOTEyMzEyMzU5NTlaMIGBMQswCQYDVQQGEwJHQjEb +MBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRowGAYDVQQKExFD +T01PRE8gQ0EgTGltaXRlZDEnMCUGA1UEAxMeQ09NT0RPIENlcnRpZmljYXRpb24gQXV0aG9yaXR5 +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0ECLi3LjkRv3UcEbVASY06m/weaKXTuH ++7uIzg3jLz8GlvCiKVCZrts7oVewdFFxze1CkU1B/qnI2GqGd0S7WWaXUF601CxwRM/aN5VCaTww +xHGzUvAhTaHYujl8HJ6jJJ3ygxaYqhZ8Q5sVW7euNJH+1GImGEaaP+vB+fGQV+useg2L23IwambV +4EajcNxo2f8ESIl33rXp+2dtQem8Ob0y2WIC8bGoPW43nOIv4tOiJovGuFVDiOEjPqXSJDlqR6sA +1KGzqSX+DT+nHbrTUcELpNqsOO9VUCQFZUaTNE8tja3G1CEZ0o7KBWFxB3NH5YoZEr0ETc5OnKVI +rLsm9wIDAQABo4GOMIGLMB0GA1UdDgQWBBQLWOWLxkwVN6RAqTCpIb5HNlpW/zAOBgNVHQ8BAf8E +BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zBJBgNVHR8EQjBAMD6gPKA6hjhodHRwOi8vY3JsLmNvbW9k +b2NhLmNvbS9DT01PRE9DZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDANBgkqhkiG9w0BAQUFAAOC +AQEAPpiem/Yb6dc5t3iuHXIYSdOH5EOC6z/JqvWote9VfCFSZfnVDeFs9D6Mk3ORLgLETgdxb8CP +OGEIqB6BCsAvIC9Bi5HcSEW88cbeunZrM8gALTFGTO3nnc+IlP8zwFboJIYmuNg4ON8qa90SzMc/ +RxdMosIGlgnW2/4/PEZB31jiVg88O8EckzXZOFKs7sjsLjBOlDW0JB9LeGna8gI4zJVSk/BwJVmc +IGfE7vmLV2H0knZ9P4SNVbfo5azV8fUZVqZa+5Acr5Pr5RzUZ5ddBA6+C4OmF4O5MBKgxTMVBbkN ++8cFduPYSo38NBejxiEovjBFMR7HeL5YYTisO+IBZQ== +-----END CERTIFICATE----- + +Network Solutions Certificate Authority +======================================= +-----BEGIN CERTIFICATE----- +MIID5jCCAs6gAwIBAgIQV8szb8JcFuZHFhfjkDFo4DANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQG +EwJVUzEhMB8GA1UEChMYTmV0d29yayBTb2x1dGlvbnMgTC5MLkMuMTAwLgYDVQQDEydOZXR3b3Jr +IFNvbHV0aW9ucyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDYxMjAxMDAwMDAwWhcNMjkxMjMx +MjM1OTU5WjBiMQswCQYDVQQGEwJVUzEhMB8GA1UEChMYTmV0d29yayBTb2x1dGlvbnMgTC5MLkMu +MTAwLgYDVQQDEydOZXR3b3JrIFNvbHV0aW9ucyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDkvH6SMG3G2I4rC7xGzuAnlt7e+foS0zwzc7MEL7xx +jOWftiJgPl9dzgn/ggwbmlFQGiaJ3dVhXRncEg8tCqJDXRfQNJIg6nPPOCwGJgl6cvf6UDL4wpPT +aaIjzkGxzOTVHzbRijr4jGPiFFlp7Q3Tf2vouAPlT2rlmGNpSAW+Lv8ztumXWWn4Zxmuk2GWRBXT +crA/vGp97Eh/jcOrqnErU2lBUzS1sLnFBgrEsEX1QV1uiUV7PTsmjHTC5dLRfbIR1PtYMiKagMnc +/Qzpf14Dl847ABSHJ3A4qY5usyd2mFHgBeMhqxrVhSI8KbWaFsWAqPS7azCPL0YCorEMIuDTAgMB +AAGjgZcwgZQwHQYDVR0OBBYEFCEwyfsA106Y2oeqKtCnLrFAMadMMA4GA1UdDwEB/wQEAwIBBjAP +BgNVHRMBAf8EBTADAQH/MFIGA1UdHwRLMEkwR6BFoEOGQWh0dHA6Ly9jcmwubmV0c29sc3NsLmNv +bS9OZXR3b3JrU29sdXRpb25zQ2VydGlmaWNhdGVBdXRob3JpdHkuY3JsMA0GCSqGSIb3DQEBBQUA +A4IBAQC7rkvnt1frf6ott3NHhWrB5KUd5Oc86fRZZXe1eltajSU24HqXLjjAV2CDmAaDn7l2em5Q +4LqILPxFzBiwmZVRDuwduIj/h1AcgsLj4DKAv6ALR8jDMe+ZZzKATxcheQxpXN5eNK4CtSbqUN9/ +GGUsyfJj4akH/nxxH2szJGoeBfcFaMBqEssuXmHLrijTfsK0ZpEmXzwuJF/LWA/rKOyvEZbz3Htv +wKeI8lN3s2Berq4o2jUsbzRF0ybh3uxbTydrFny9RAQYgrOJeRcQcT16ohZO9QHNpGxlaKFJdlxD +ydi8NmdspZS11My5vWo1ViHe2MPr+8ukYEywVaCge1ey +-----END CERTIFICATE----- + +COMODO ECC Certification Authority +================================== +-----BEGIN CERTIFICATE----- +MIICiTCCAg+gAwIBAgIQH0evqmIAcFBUTAGem2OZKjAKBggqhkjOPQQDAzCBhTELMAkGA1UEBhMC +R0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UE +ChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlvbiBB +dXRob3JpdHkwHhcNMDgwMzA2MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBhTELMAkGA1UEBhMCR0Ix +GzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMR +Q09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlvbiBBdXRo +b3JpdHkwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQDR3svdcmCFYX7deSRFtSrYpn1PlILBs5BAH+X +4QokPB0BBO490o0JlwzgdeT6+3eKKvUDYEs2ixYjFq0JcfRK9ChQtP6IHG4/bC8vCVlbpVsLM5ni +wz2J+Wos77LTBumjQjBAMB0GA1UdDgQWBBR1cacZSBm8nZ3qQUfflMRId5nTeTAOBgNVHQ8BAf8E +BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjEA7wNbeqy3eApyt4jf/7VG +FAkK+qDmfQjGGoe9GKhzvSbKYAydzpmfz1wPMOG+FDHqAjAU9JM8SaczepBGR7NjfRObTrdvGDeA +U/7dIOA1mjbRxwG55tzd8/8dLDoWV9mSOdY= +-----END CERTIFICATE----- + +Certigna +======== +-----BEGIN CERTIFICATE----- +MIIDqDCCApCgAwIBAgIJAP7c4wEPyUj/MA0GCSqGSIb3DQEBBQUAMDQxCzAJBgNVBAYTAkZSMRIw +EAYDVQQKDAlEaGlteW90aXMxETAPBgNVBAMMCENlcnRpZ25hMB4XDTA3MDYyOTE1MTMwNVoXDTI3 +MDYyOTE1MTMwNVowNDELMAkGA1UEBhMCRlIxEjAQBgNVBAoMCURoaW15b3RpczERMA8GA1UEAwwI +Q2VydGlnbmEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIaPHJ1tazNHUmgh7stL7q +XOEm7RFHYeGifBZ4QCHkYJ5ayGPhxLGWkv8YbWkj4Sti993iNi+RB7lIzw7sebYs5zRLcAglozyH +GxnygQcPOJAZ0xH+hrTy0V4eHpbNgGzOOzGTtvKg0KmVEn2lmsxryIRWijOp5yIVUxbwzBfsV1/p +ogqYCd7jX5xv3EjjhQsVWqa6n6xI4wmy9/Qy3l40vhx4XUJbzg4ij02Q130yGLMLLGq/jj8UEYkg +DncUtT2UCIf3JR7VsmAA7G8qKCVuKj4YYxclPz5EIBb2JsglrgVKtOdjLPOMFlN+XPsRGgjBRmKf +Irjxwo1p3Po6WAbfAgMBAAGjgbwwgbkwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUGu3+QTmQ +tCRZvgHyUtVF9lo53BEwZAYDVR0jBF0wW4AUGu3+QTmQtCRZvgHyUtVF9lo53BGhOKQ2MDQxCzAJ +BgNVBAYTAkZSMRIwEAYDVQQKDAlEaGlteW90aXMxETAPBgNVBAMMCENlcnRpZ25hggkA/tzjAQ/J +SP8wDgYDVR0PAQH/BAQDAgEGMBEGCWCGSAGG+EIBAQQEAwIABzANBgkqhkiG9w0BAQUFAAOCAQEA +hQMeknH2Qq/ho2Ge6/PAD/Kl1NqV5ta+aDY9fm4fTIrv0Q8hbV6lUmPOEvjvKtpv6zf+EwLHyzs+ +ImvaYS5/1HI93TDhHkxAGYwP15zRgzB7mFncfca5DClMoTOi62c6ZYTTluLtdkVwj7Ur3vkj1klu +PBS1xp81HlDQwY9qcEQCYsuuHWhBp6pX6FOqB9IG9tUUBguRA3UsbHK1YZWaDYu5Def131TN3ubY +1gkIl2PlwS6wt0QmwCbAr1UwnjvVNioZBPRcHv/PLLf/0P2HQBHVESO7SMAhqaQoLf0V+LBOK/Qw +WyH8EZE0vkHve52Xdf+XlcCWWC/qu0bXu+TZLg== +-----END CERTIFICATE----- + +Cybertrust Global Root +====================== +-----BEGIN CERTIFICATE----- +MIIDoTCCAomgAwIBAgILBAAAAAABD4WqLUgwDQYJKoZIhvcNAQEFBQAwOzEYMBYGA1UEChMPQ3li +ZXJ0cnVzdCwgSW5jMR8wHQYDVQQDExZDeWJlcnRydXN0IEdsb2JhbCBSb290MB4XDTA2MTIxNTA4 +MDAwMFoXDTIxMTIxNTA4MDAwMFowOzEYMBYGA1UEChMPQ3liZXJ0cnVzdCwgSW5jMR8wHQYDVQQD +ExZDeWJlcnRydXN0IEdsb2JhbCBSb290MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA ++Mi8vRRQZhP/8NN57CPytxrHjoXxEnOmGaoQ25yiZXRadz5RfVb23CO21O1fWLE3TdVJDm71aofW +0ozSJ8bi/zafmGWgE07GKmSb1ZASzxQG9Dvj1Ci+6A74q05IlG2OlTEQXO2iLb3VOm2yHLtgwEZL +AfVJrn5GitB0jaEMAs7u/OePuGtm839EAL9mJRQr3RAwHQeWP032a7iPt3sMpTjr3kfb1V05/Iin +89cqdPHoWqI7n1C6poxFNcJQZZXcY4Lv3b93TZxiyWNzFtApD0mpSPCzqrdsxacwOUBdrsTiXSZT +8M4cIwhhqJQZugRiQOwfOHB3EgZxpzAYXSUnpQIDAQABo4GlMIGiMA4GA1UdDwEB/wQEAwIBBjAP +BgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBS2CHsNesysIEyGVjJez6tuhS1wVzA/BgNVHR8EODA2 +MDSgMqAwhi5odHRwOi8vd3d3Mi5wdWJsaWMtdHJ1c3QuY29tL2NybC9jdC9jdHJvb3QuY3JsMB8G +A1UdIwQYMBaAFLYIew16zKwgTIZWMl7Pq26FLXBXMA0GCSqGSIb3DQEBBQUAA4IBAQBW7wojoFRO +lZfJ+InaRcHUowAl9B8Tq7ejhVhpwjCt2BWKLePJzYFa+HMjWqd8BfP9IjsO0QbE2zZMcwSO5bAi +5MXzLqXZI+O4Tkogp24CJJ8iYGd7ix1yCcUxXOl5n4BHPa2hCwcUPUf/A2kaDAtE52Mlp3+yybh2 +hO0j9n0Hq0V+09+zv+mKts2oomcrUtW3ZfA5TGOgkXmTUg9U3YO7n9GPp1Nzw8v/MOx8BLjYRB+T +X3EJIrduPuocA06dGiBh+4E37F78CkWr1+cXVdCg6mCbpvbjjFspwgZgFJ0tl0ypkxWdYcQBX0jW +WL1WMRJOEcgh4LMRkWXbtKaIOM5V +-----END CERTIFICATE----- + +ePKI Root Certification Authority +================================= +-----BEGIN CERTIFICATE----- +MIIFsDCCA5igAwIBAgIQFci9ZUdcr7iXAF7kBtK8nTANBgkqhkiG9w0BAQUFADBeMQswCQYDVQQG +EwJUVzEjMCEGA1UECgwaQ2h1bmdod2EgVGVsZWNvbSBDby4sIEx0ZC4xKjAoBgNVBAsMIWVQS0kg +Um9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNDEyMjAwMjMxMjdaFw0zNDEyMjAwMjMx +MjdaMF4xCzAJBgNVBAYTAlRXMSMwIQYDVQQKDBpDaHVuZ2h3YSBUZWxlY29tIENvLiwgTHRkLjEq +MCgGA1UECwwhZVBLSSBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIICIjANBgkqhkiG9w0B +AQEFAAOCAg8AMIICCgKCAgEA4SUP7o3biDN1Z82tH306Tm2d0y8U82N0ywEhajfqhFAHSyZbCUNs +IZ5qyNUD9WBpj8zwIuQf5/dqIjG3LBXy4P4AakP/h2XGtRrBp0xtInAhijHyl3SJCRImHJ7K2RKi +lTza6We/CKBk49ZCt0Xvl/T29de1ShUCWH2YWEtgvM3XDZoTM1PRYfl61dd4s5oz9wCGzh1NlDiv +qOx4UXCKXBCDUSH3ET00hl7lSM2XgYI1TBnsZfZrxQWh7kcT1rMhJ5QQCtkkO7q+RBNGMD+XPNjX +12ruOzjjK9SXDrkb5wdJfzcq+Xd4z1TtW0ado4AOkUPB1ltfFLqfpo0kR0BZv3I4sjZsN/+Z0V0O +WQqraffAsgRFelQArr5T9rXn4fg8ozHSqf4hUmTFpmfwdQcGlBSBVcYn5AGPF8Fqcde+S/uUWH1+ +ETOxQvdibBjWzwloPn9s9h6PYq2lY9sJpx8iQkEeb5mKPtf5P0B6ebClAZLSnT0IFaUQAS2zMnao +lQ2zepr7BxB4EW/hj8e6DyUadCrlHJhBmd8hh+iVBmoKs2pHdmX2Os+PYhcZewoozRrSgx4hxyy/ +vv9haLdnG7t4TY3OZ+XkwY63I2binZB1NJipNiuKmpS5nezMirH4JYlcWrYvjB9teSSnUmjDhDXi +Zo1jDiVN1Rmy5nk3pyKdVDECAwEAAaNqMGgwHQYDVR0OBBYEFB4M97Zn8uGSJglFwFU5Lnc/Qkqi +MAwGA1UdEwQFMAMBAf8wOQYEZyoHAAQxMC8wLQIBADAJBgUrDgMCGgUAMAcGBWcqAwAABBRFsMLH +ClZ87lt4DJX5GFPBphzYEDANBgkqhkiG9w0BAQUFAAOCAgEACbODU1kBPpVJufGBuvl2ICO1J2B0 +1GqZNF5sAFPZn/KmsSQHRGoqxqWOeBLoR9lYGxMqXnmbnwoqZ6YlPwZpVnPDimZI+ymBV3QGypzq +KOg4ZyYr8dW1P2WT+DZdjo2NQCCHGervJ8A9tDkPJXtoUHRVnAxZfVo9QZQlUgjgRywVMRnVvwdV +xrsStZf0X4OFunHB2WyBEXYKCrC/gpf36j36+uwtqSiUO1bd0lEursC9CBWMd1I0ltabrNMdjmEP +NXubrjlpC2JgQCA2j6/7Nu4tCEoduL+bXPjqpRugc6bY+G7gMwRfaKonh+3ZwZCc7b3jajWvY9+r +GNm65ulK6lCKD2GTHuItGeIwlDWSXQ62B68ZgI9HkFFLLk3dheLSClIKF5r8GrBQAuUBo2M3IUxE +xJtRmREOc5wGj1QupyheRDmHVi03vYVElOEMSyycw5KFNGHLD7ibSkNS/jQ6fbjpKdx2qcgw+BRx +gMYeNkh0IkFch4LoGHGLQYlE535YW6i4jRPpp2zDR+2zGp1iro2C6pSe3VkQw63d4k3jMdXH7Ojy +sP6SHhYKGvzZ8/gntsm+HbRsZJB/9OTEW9c3rkIO3aQab3yIVMUWbuF6aC74Or8NpDyJO3inTmOD +BCEIZ43ygknQW/2xzQ+DhNQ+IIX3Sj0rnP0qCglN6oH4EZw= +-----END CERTIFICATE----- + +certSIGN ROOT CA +================ +-----BEGIN CERTIFICATE----- +MIIDODCCAiCgAwIBAgIGIAYFFnACMA0GCSqGSIb3DQEBBQUAMDsxCzAJBgNVBAYTAlJPMREwDwYD +VQQKEwhjZXJ0U0lHTjEZMBcGA1UECxMQY2VydFNJR04gUk9PVCBDQTAeFw0wNjA3MDQxNzIwMDRa +Fw0zMTA3MDQxNzIwMDRaMDsxCzAJBgNVBAYTAlJPMREwDwYDVQQKEwhjZXJ0U0lHTjEZMBcGA1UE +CxMQY2VydFNJR04gUk9PVCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALczuX7I +JUqOtdu0KBuqV5Do0SLTZLrTk+jUrIZhQGpgV2hUhE28alQCBf/fm5oqrl0Hj0rDKH/v+yv6efHH +rfAQUySQi2bJqIirr1qjAOm+ukbuW3N7LBeCgV5iLKECZbO9xSsAfsT8AzNXDe3i+s5dRdY4zTW2 +ssHQnIFKquSyAVwdj1+ZxLGt24gh65AIgoDzMKND5pCCrlUoSe1b16kQOA7+j0xbm0bqQfWwCHTD +0IgztnzXdN/chNFDDnU5oSVAKOp4yw4sLjmdjItuFhwvJoIQ4uNllAoEwF73XVv4EOLQunpL+943 +AAAaWyjj0pxzPjKHmKHJUS/X3qwzs08CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8B +Af8EBAMCAcYwHQYDVR0OBBYEFOCMm9slSbPxfIbWskKHC9BroNnkMA0GCSqGSIb3DQEBBQUAA4IB +AQA+0hyJLjX8+HXd5n9liPRyTMks1zJO890ZeUe9jjtbkw9QSSQTaxQGcu8J06Gh40CEyecYMnQ8 +SG4Pn0vU9x7Tk4ZkVJdjclDVVc/6IJMCopvDI5NOFlV2oHB5bc0hH88vLbwZ44gx+FkagQnIl6Z0 +x2DEW8xXjrJ1/RsCCdtZb3KTafcxQdaIOL+Hsr0Wefmq5L6IJd1hJyMctTEHBDa0GpC9oHRxUIlt +vBTjD4au8as+x6AJzKNI0eDbZOeStc+vckNwi/nDhDwTqn6Sm1dTk/pwwpEOMfmbZ13pljheX7Nz +TogVZ96edhBiIL5VaZVDADlN9u6wWk5JRFRYX0KD +-----END CERTIFICATE----- + +NetLock Arany (Class Gold) Főtanúsítvány +======================================== +-----BEGIN CERTIFICATE----- +MIIEFTCCAv2gAwIBAgIGSUEs5AAQMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYDVQQGEwJIVTERMA8G +A1UEBwwIQnVkYXBlc3QxFTATBgNVBAoMDE5ldExvY2sgS2Z0LjE3MDUGA1UECwwuVGFuw7pzw610 +dsOhbnlraWFkw7NrIChDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzKTE1MDMGA1UEAwwsTmV0TG9jayBB +cmFueSAoQ2xhc3MgR29sZCkgRsWRdGFuw7pzw610dsOhbnkwHhcNMDgxMjExMTUwODIxWhcNMjgx +MjA2MTUwODIxWjCBpzELMAkGA1UEBhMCSFUxETAPBgNVBAcMCEJ1ZGFwZXN0MRUwEwYDVQQKDAxO +ZXRMb2NrIEtmdC4xNzA1BgNVBAsMLlRhbsO6c8OtdHbDoW55a2lhZMOzayAoQ2VydGlmaWNhdGlv +biBTZXJ2aWNlcykxNTAzBgNVBAMMLE5ldExvY2sgQXJhbnkgKENsYXNzIEdvbGQpIEbFkXRhbsO6 +c8OtdHbDoW55MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxCRec75LbRTDofTjl5Bu +0jBFHjzuZ9lk4BqKf8owyoPjIMHj9DrTlF8afFttvzBPhCf2nx9JvMaZCpDyD/V/Q4Q3Y1GLeqVw +/HpYzY6b7cNGbIRwXdrzAZAj/E4wqX7hJ2Pn7WQ8oLjJM2P+FpD/sLj916jAwJRDC7bVWaaeVtAk +H3B5r9s5VA1lddkVQZQBr17s9o3x/61k/iCa11zr/qYfCGSji3ZVrR47KGAuhyXoqq8fxmRGILdw +fzzeSNuWU7c5d+Qa4scWhHaXWy+7GRWF+GmF9ZmnqfI0p6m2pgP8b4Y9VHx2BJtr+UBdADTHLpl1 +neWIA6pN+APSQnbAGwIDAKiLo0UwQzASBgNVHRMBAf8ECDAGAQH/AgEEMA4GA1UdDwEB/wQEAwIB +BjAdBgNVHQ4EFgQUzPpnk/C2uNClwB7zU/2MU9+D15YwDQYJKoZIhvcNAQELBQADggEBAKt/7hwW +qZw8UQCgwBEIBaeZ5m8BiFRhbvG5GK1Krf6BQCOUL/t1fC8oS2IkgYIL9WHxHG64YTjrgfpioTta +YtOUZcTh5m2C+C8lcLIhJsFyUR+MLMOEkMNaj7rP9KdlpeuY0fsFskZ1FSNqb4VjMIDw1Z4fKRzC +bLBQWV2QWzuoDTDPv31/zvGdg73JRm4gpvlhUbohL3u+pRVjodSVh/GeufOJ8z2FuLjbvrW5Kfna +NwUASZQDhETnv0Mxz3WLJdH0pmT1kvarBes96aULNmLazAZfNou2XjG4Kvte9nHfRCaexOYNkbQu +dZWAUWpLMKawYqGT8ZvYzsRjdT9ZR7E= +-----END CERTIFICATE----- + +Hongkong Post Root CA 1 +======================= +-----BEGIN CERTIFICATE----- +MIIDMDCCAhigAwIBAgICA+gwDQYJKoZIhvcNAQEFBQAwRzELMAkGA1UEBhMCSEsxFjAUBgNVBAoT +DUhvbmdrb25nIFBvc3QxIDAeBgNVBAMTF0hvbmdrb25nIFBvc3QgUm9vdCBDQSAxMB4XDTAzMDUx +NTA1MTMxNFoXDTIzMDUxNTA0NTIyOVowRzELMAkGA1UEBhMCSEsxFjAUBgNVBAoTDUhvbmdrb25n +IFBvc3QxIDAeBgNVBAMTF0hvbmdrb25nIFBvc3QgUm9vdCBDQSAxMIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEArP84tulmAknjorThkPlAj3n54r15/gK97iSSHSL22oVyaf7XPwnU3ZG1 +ApzQjVrhVcNQhrkpJsLj2aDxaQMoIIBFIi1WpztUlVYiWR8o3x8gPW2iNr4joLFutbEnPzlTCeqr +auh0ssJlXI6/fMN4hM2eFvz1Lk8gKgifd/PFHsSaUmYeSF7jEAaPIpjhZY4bXSNmO7ilMlHIhqqh +qZ5/dpTCpmy3QfDVyAY45tQM4vM7TG1QjMSDJ8EThFk9nnV0ttgCXjqQesBCNnLsak3c78QA3xMY +V18meMjWCnl3v/evt3a5pQuEF10Q6m/hq5URX208o1xNg1vysxmKgIsLhwIDAQABoyYwJDASBgNV +HRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIBxjANBgkqhkiG9w0BAQUFAAOCAQEADkbVPK7i +h9legYsCmEEIjEy82tvuJxuC52pF7BaLT4Wg87JwvVqWuspube5Gi27nKi6Wsxkz67SfqLI37pio +l7Yutmcn1KZJ/RyTZXaeQi/cImyaT/JaFTmxcdcrUehtHJjA2Sr0oYJ71clBoiMBdDhViw+5Lmei +IAQ32pwL0xch4I+XeTRvhEgCIDMb5jREn5Fw9IBehEPCKdJsEhTkYY2sEJCehFC78JZvRZ+K88ps +T/oROhUVRsPNH4NbLUES7VBnQRM9IauUiqpOfMGx+6fWtScvl6tu4B3i0RwsH0Ti/L6RoZz71ilT +c4afU9hDDl3WY4JxHYB0yvbiAmvZWg== +-----END CERTIFICATE----- + +SecureSign RootCA11 +=================== +-----BEGIN CERTIFICATE----- +MIIDbTCCAlWgAwIBAgIBATANBgkqhkiG9w0BAQUFADBYMQswCQYDVQQGEwJKUDErMCkGA1UEChMi +SmFwYW4gQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcywgSW5jLjEcMBoGA1UEAxMTU2VjdXJlU2lnbiBS +b290Q0ExMTAeFw0wOTA0MDgwNDU2NDdaFw0yOTA0MDgwNDU2NDdaMFgxCzAJBgNVBAYTAkpQMSsw +KQYDVQQKEyJKYXBhbiBDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzLCBJbmMuMRwwGgYDVQQDExNTZWN1 +cmVTaWduIFJvb3RDQTExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA/XeqpRyQBTvL +TJszi1oURaTnkBbR31fSIRCkF/3frNYfp+TbfPfs37gD2pRY/V1yfIw/XwFndBWW4wI8h9uuywGO +wvNmxoVF9ALGOrVisq/6nL+k5tSAMJjzDbaTj6nU2DbysPyKyiyhFTOVMdrAG/LuYpmGYz+/3ZMq +g6h2uRMft85OQoWPIucuGvKVCbIFtUROd6EgvanyTgp9UK31BQ1FT0Zx/Sg+U/sE2C3XZR1KG/rP +O7AxmjVuyIsG0wCR8pQIZUyxNAYAeoni8McDWc/V1uinMrPmmECGxc0nEovMe863ETxiYAcjPitA +bpSACW22s293bzUIUPsCh8U+iQIDAQABo0IwQDAdBgNVHQ4EFgQUW/hNT7KlhtQ60vFjmqC+CfZX +t94wDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAKCh +OBZmLqdWHyGcBvod7bkixTgm2E5P7KN/ed5GIaGHd48HCJqypMWvDzKYC3xmKbabfSVSSUOrTC4r +bnpwrxYO4wJs+0LmGJ1F2FXI6Dvd5+H0LgscNFxsWEr7jIhQX5Ucv+2rIrVls4W6ng+4reV6G4pQ +Oh29Dbx7VFALuUKvVaAYga1lme++5Jy/xIWrQbJUb9wlze144o4MjQlJ3WN7WmmWAiGovVJZ6X01 +y8hSyn+B/tlr0/cR7SXf+Of5pPpyl4RTDaXQMhhRdlkUbA/r7F+AjHVDg8OFmP9Mni0N5HeDk061 +lgeLKBObjBmNQSdJQO7e5iNEOdyhIta6A/I= +-----END CERTIFICATE----- + +Microsec e-Szigno Root CA 2009 +============================== +-----BEGIN CERTIFICATE----- +MIIECjCCAvKgAwIBAgIJAMJ+QwRORz8ZMA0GCSqGSIb3DQEBCwUAMIGCMQswCQYDVQQGEwJIVTER +MA8GA1UEBwwIQnVkYXBlc3QxFjAUBgNVBAoMDU1pY3Jvc2VjIEx0ZC4xJzAlBgNVBAMMHk1pY3Jv +c2VjIGUtU3ppZ25vIFJvb3QgQ0EgMjAwOTEfMB0GCSqGSIb3DQEJARYQaW5mb0BlLXN6aWduby5o +dTAeFw0wOTA2MTYxMTMwMThaFw0yOTEyMzAxMTMwMThaMIGCMQswCQYDVQQGEwJIVTERMA8GA1UE +BwwIQnVkYXBlc3QxFjAUBgNVBAoMDU1pY3Jvc2VjIEx0ZC4xJzAlBgNVBAMMHk1pY3Jvc2VjIGUt +U3ppZ25vIFJvb3QgQ0EgMjAwOTEfMB0GCSqGSIb3DQEJARYQaW5mb0BlLXN6aWduby5odTCCASIw +DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOn4j/NjrdqG2KfgQvvPkd6mJviZpWNwrZuuyjNA +fW2WbqEORO7hE52UQlKavXWFdCyoDh2Tthi3jCyoz/tccbna7P7ofo/kLx2yqHWH2Leh5TvPmUpG +0IMZfcChEhyVbUr02MelTTMuhTlAdX4UfIASmFDHQWe4oIBhVKZsTh/gnQ4H6cm6M+f+wFUoLAKA +pxn1ntxVUwOXewdI/5n7N4okxFnMUBBjjqqpGrCEGob5X7uxUG6k0QrM1XF+H6cbfPVTbiJfyyvm +1HxdrtbCxkzlBQHZ7Vf8wSN5/PrIJIOV87VqUQHQd9bpEqH5GoP7ghu5sJf0dgYzQ0mg/wu1+rUC +AwEAAaOBgDB+MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBTLD8bf +QkPMPcu1SCOhGnqmKrs0aDAfBgNVHSMEGDAWgBTLD8bfQkPMPcu1SCOhGnqmKrs0aDAbBgNVHREE +FDASgRBpbmZvQGUtc3ppZ25vLmh1MA0GCSqGSIb3DQEBCwUAA4IBAQDJ0Q5eLtXMs3w+y/w9/w0o +lZMEyL/azXm4Q5DwpL7v8u8hmLzU1F0G9u5C7DBsoKqpyvGvivo/C3NqPuouQH4frlRheesuCDfX +I/OMn74dseGkddug4lQUsbocKaQY9hK6ohQU4zE1yED/t+AFdlfBHFny+L/k7SViXITwfn4fs775 +tyERzAMBVnCnEJIeGzSBHq2cGsMEPO0CYdYeBvNfOofyK/FFh+U9rNHHV4S9a67c2Pm2G2JwCz02 +yULyMtd6YebS2z3PyKnJm9zbWETXbzivf3jTo60adbocwTZ8jx5tHMN1Rq41Bab2XD0h7lbwyYIi +LXpUq3DDfSJlgnCW +-----END CERTIFICATE----- + +GlobalSign Root CA - R3 +======================= +-----BEGIN CERTIFICATE----- +MIIDXzCCAkegAwIBAgILBAAAAAABIVhTCKIwDQYJKoZIhvcNAQELBQAwTDEgMB4GA1UECxMXR2xv +YmFsU2lnbiBSb290IENBIC0gUjMxEzARBgNVBAoTCkdsb2JhbFNpZ24xEzARBgNVBAMTCkdsb2Jh +bFNpZ24wHhcNMDkwMzE4MTAwMDAwWhcNMjkwMzE4MTAwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxT +aWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2ln +bjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMwldpB5BngiFvXAg7aEyiie/QV2EcWt +iHL8RgJDx7KKnQRfJMsuS+FggkbhUqsMgUdwbN1k0ev1LKMPgj0MK66X17YUhhB5uzsTgHeMCOFJ +0mpiLx9e+pZo34knlTifBtc+ycsmWQ1z3rDI6SYOgxXG71uL0gRgykmmKPZpO/bLyCiR5Z2KYVc3 +rHQU3HTgOu5yLy6c+9C7v/U9AOEGM+iCK65TpjoWc4zdQQ4gOsC0p6Hpsk+QLjJg6VfLuQSSaGjl +OCZgdbKfd/+RFO+uIEn8rUAVSNECMWEZXriX7613t2Saer9fwRPvm2L7DWzgVGkWqQPabumDk3F2 +xmmFghcCAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYE +FI/wS3+oLkUkrk1Q+mOai97i3Ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZURUm7 +lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMpjjM5RcOO5LlXbKr8 +EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK6fBdRoyV3XpYKBovHd7NADdBj+1E +bddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQXmcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18 +YIvDQVETI53O9zJrlAGomecsMx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7r +kpeDMdmztcpHWD9f +-----END CERTIFICATE----- + +Autoridad de Certificacion Firmaprofesional CIF A62634068 +========================================================= +-----BEGIN CERTIFICATE----- +MIIGFDCCA/ygAwIBAgIIU+w77vuySF8wDQYJKoZIhvcNAQEFBQAwUTELMAkGA1UEBhMCRVMxQjBA +BgNVBAMMOUF1dG9yaWRhZCBkZSBDZXJ0aWZpY2FjaW9uIEZpcm1hcHJvZmVzaW9uYWwgQ0lGIEE2 +MjYzNDA2ODAeFw0wOTA1MjAwODM4MTVaFw0zMDEyMzEwODM4MTVaMFExCzAJBgNVBAYTAkVTMUIw +QAYDVQQDDDlBdXRvcmlkYWQgZGUgQ2VydGlmaWNhY2lvbiBGaXJtYXByb2Zlc2lvbmFsIENJRiBB +NjI2MzQwNjgwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDKlmuO6vj78aI14H9M2uDD +Utd9thDIAl6zQyrET2qyyhxdKJp4ERppWVevtSBC5IsP5t9bpgOSL/UR5GLXMnE42QQMcas9UX4P +B99jBVzpv5RvwSmCwLTaUbDBPLutN0pcyvFLNg4kq7/DhHf9qFD0sefGL9ItWY16Ck6WaVICqjaY +7Pz6FIMMNx/Jkjd/14Et5cS54D40/mf0PmbR0/RAz15iNA9wBj4gGFrO93IbJWyTdBSTo3OxDqqH +ECNZXyAFGUftaI6SEspd/NYrspI8IM/hX68gvqB2f3bl7BqGYTM+53u0P6APjqK5am+5hyZvQWyI +plD9amML9ZMWGxmPsu2bm8mQ9QEM3xk9Dz44I8kvjwzRAv4bVdZO0I08r0+k8/6vKtMFnXkIoctX +MbScyJCyZ/QYFpM6/EfY0XiWMR+6KwxfXZmtY4laJCB22N/9q06mIqqdXuYnin1oKaPnirjaEbsX +LZmdEyRG98Xi2J+Of8ePdG1asuhy9azuJBCtLxTa/y2aRnFHvkLfuwHb9H/TKI8xWVvTyQKmtFLK +bpf7Q8UIJm+K9Lv9nyiqDdVF8xM6HdjAeI9BZzwelGSuewvF6NkBiDkal4ZkQdU7hwxu+g/GvUgU +vzlN1J5Bto+WHWOWk9mVBngxaJ43BjuAiUVhOSPHG0SjFeUc+JIwuwIDAQABo4HvMIHsMBIGA1Ud +EwEB/wQIMAYBAf8CAQEwDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBRlzeurNR4APn7VdMActHNH +DhpkLzCBpgYDVR0gBIGeMIGbMIGYBgRVHSAAMIGPMC8GCCsGAQUFBwIBFiNodHRwOi8vd3d3LmZp +cm1hcHJvZmVzaW9uYWwuY29tL2NwczBcBggrBgEFBQcCAjBQHk4AUABhAHMAZQBvACAAZABlACAA +bABhACAAQgBvAG4AYQBuAG8AdgBhACAANAA3ACAAQgBhAHIAYwBlAGwAbwBuAGEAIAAwADgAMAAx +ADcwDQYJKoZIhvcNAQEFBQADggIBABd9oPm03cXF661LJLWhAqvdpYhKsg9VSytXjDvlMd3+xDLx +51tkljYyGOylMnfX40S2wBEqgLk9am58m9Ot/MPWo+ZkKXzR4Tgegiv/J2Wv+xYVxC5xhOW1//qk +R71kMrv2JYSiJ0L1ILDCExARzRAVukKQKtJE4ZYm6zFIEv0q2skGz3QeqUvVhyj5eTSSPi5E6PaP +T481PyWzOdxjKpBrIF/EUhJOlywqrJ2X3kjyo2bbwtKDlaZmp54lD+kLM5FlClrD2VQS3a/DTg4f +Jl4N3LON7NWBcN7STyQF82xO9UxJZo3R/9ILJUFI/lGExkKvgATP0H5kSeTy36LssUzAKh3ntLFl +osS88Zj0qnAHY7S42jtM+kAiMFsRpvAFDsYCA0irhpuF3dvd6qJ2gHN99ZwExEWN57kci57q13XR +crHedUTnQn3iV2t93Jm8PYMo6oCTjcVMZcFwgbg4/EMxsvYDNEeyrPsiBsse3RdHHF9mudMaotoR +saS8I8nkvof/uZS2+F0gStRf571oe2XyFR7SOqkt6dhrJKyXWERHrVkY8SFlcN7ONGCoQPHzPKTD +KCOM/iczQ0CgFzzr6juwcqajuUpLXhZI9LK8yIySxZ2frHI2vDSANGupi5LAuBft7HZT9SQBjLMi +6Et8Vcad+qMUu2WFbm5PEn4KPJ2V +-----END CERTIFICATE----- + +Izenpe.com +========== +-----BEGIN CERTIFICATE----- +MIIF8TCCA9mgAwIBAgIQALC3WhZIX7/hy/WL1xnmfTANBgkqhkiG9w0BAQsFADA4MQswCQYDVQQG +EwJFUzEUMBIGA1UECgwLSVpFTlBFIFMuQS4xEzARBgNVBAMMCkl6ZW5wZS5jb20wHhcNMDcxMjEz +MTMwODI4WhcNMzcxMjEzMDgyNzI1WjA4MQswCQYDVQQGEwJFUzEUMBIGA1UECgwLSVpFTlBFIFMu +QS4xEzARBgNVBAMMCkl6ZW5wZS5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDJ +03rKDx6sp4boFmVqscIbRTJxldn+EFvMr+eleQGPicPK8lVx93e+d5TzcqQsRNiekpsUOqHnJJAK +ClaOxdgmlOHZSOEtPtoKct2jmRXagaKH9HtuJneJWK3W6wyyQXpzbm3benhB6QiIEn6HLmYRY2xU ++zydcsC8Lv/Ct90NduM61/e0aL6i9eOBbsFGb12N4E3GVFWJGjMxCrFXuaOKmMPsOzTFlUFpfnXC +PCDFYbpRR6AgkJOhkEvzTnyFRVSa0QUmQbC1TR0zvsQDyCV8wXDbO/QJLVQnSKwv4cSsPsjLkkxT +OTcj7NMB+eAJRE1NZMDhDVqHIrytG6P+JrUV86f8hBnp7KGItERphIPzidF0BqnMC9bC3ieFUCbK +F7jJeodWLBoBHmy+E60QrLUk9TiRodZL2vG70t5HtfG8gfZZa88ZU+mNFctKy6lvROUbQc/hhqfK +0GqfvEyNBjNaooXlkDWgYlwWTvDjovoDGrQscbNYLN57C9saD+veIR8GdwYDsMnvmfzAuU8Lhij+ +0rnq49qlw0dpEuDb8PYZi+17cNcC1u2HGCgsBCRMd+RIihrGO5rUD8r6ddIBQFqNeb+Lz0vPqhbB +leStTIo+F5HUsWLlguWABKQDfo2/2n+iD5dPDNMN+9fR5XJ+HMh3/1uaD7euBUbl8agW7EekFwID +AQABo4H2MIHzMIGwBgNVHREEgagwgaWBD2luZm9AaXplbnBlLmNvbaSBkTCBjjFHMEUGA1UECgw+ +SVpFTlBFIFMuQS4gLSBDSUYgQTAxMzM3MjYwLVJNZXJjLlZpdG9yaWEtR2FzdGVpeiBUMTA1NSBG +NjIgUzgxQzBBBgNVBAkMOkF2ZGEgZGVsIE1lZGl0ZXJyYW5lbyBFdG9yYmlkZWEgMTQgLSAwMTAx +MCBWaXRvcmlhLUdhc3RlaXowDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0O +BBYEFB0cZQ6o8iV7tJHP5LGx5r1VdGwFMA0GCSqGSIb3DQEBCwUAA4ICAQB4pgwWSp9MiDrAyw6l +Fn2fuUhfGI8NYjb2zRlrrKvV9pF9rnHzP7MOeIWblaQnIUdCSnxIOvVFfLMMjlF4rJUT3sb9fbga +kEyrkgPH7UIBzg/YsfqikuFgba56awmqxinuaElnMIAkejEWOVt+8Rwu3WwJrfIxwYJOubv5vr8q +hT/AQKM6WfxZSzwoJNu0FXWuDYi6LnPAvViH5ULy617uHjAimcs30cQhbIHsvm0m5hzkQiCeR7Cs +g1lwLDXWrzY0tM07+DKo7+N4ifuNRSzanLh+QBxh5z6ikixL8s36mLYp//Pye6kfLqCTVyvehQP5 +aTfLnnhqBbTFMXiJ7HqnheG5ezzevh55hM6fcA5ZwjUukCox2eRFekGkLhObNA5me0mrZJfQRsN5 +nXJQY6aYWwa9SG3YOYNw6DXwBdGqvOPbyALqfP2C2sJbUjWumDqtujWTI6cfSN01RpiyEGjkpTHC +ClguGYEQyVB1/OpaFs4R1+7vUIgtYf8/QnMFlEPVjjxOAToZpR9GTnfQXeWBIiGH/pR9hNiTrdZo +Q0iy2+tzJOeRf1SktoA+naM8THLCV8Sg1Mw4J87VBp6iSNnpn86CcDaTmjvfliHjWbcM2pE38P1Z +WrOZyGlsQyYBNWNgVYkDOnXYukrZVP/u3oDYLdE41V4tC5h9Pmzb/CaIxw== +-----END CERTIFICATE----- + +Go Daddy Root Certificate Authority - G2 +======================================== +-----BEGIN CERTIFICATE----- +MIIDxTCCAq2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMxEDAOBgNVBAgT +B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoTEUdvRGFkZHkuY29tLCBJbmMu +MTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5 +MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgYMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6 +b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjExMC8G +A1UEAxMoR28gRGFkZHkgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZI +hvcNAQEBBQADggEPADCCAQoCggEBAL9xYgjx+lk09xvJGKP3gElY6SKDE6bFIEMBO4Tx5oVJnyfq +9oQbTqC023CYxzIBsQU+B07u9PpPL1kwIuerGVZr4oAH/PMWdYA5UXvl+TW2dE6pjYIT5LY/qQOD ++qK+ihVqf94Lw7YZFAXK6sOoBJQ7RnwyDfMAZiLIjWltNowRGLfTshxgtDj6AozO091GB94KPutd +fMh8+7ArU6SSYmlRJQVhGkSBjCypQ5Yj36w6gZoOKcUcqeldHraenjAKOc7xiID7S13MMuyFYkMl +NAJWJwGRtDtwKj9useiciAF9n9T521NtYJ2/LOdYq7hfRvzOxBsDPAnrSTFcaUaz4EcCAwEAAaNC +MEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFDqahQcQZyi27/a9 +BUFuIMGU2g/eMA0GCSqGSIb3DQEBCwUAA4IBAQCZ21151fmXWWcDYfF+OwYxdS2hII5PZYe096ac +vNjpL9DbWu7PdIxztDhC2gV7+AJ1uP2lsdeu9tfeE8tTEH6KRtGX+rcuKxGrkLAngPnon1rpN5+r +5N9ss4UXnT3ZJE95kTXWXwTrgIOrmgIttRD02JDHBHNA7XIloKmf7J6raBKZV8aPEjoJpL1E/QYV +N8Gb5DKj7Tjo2GTzLH4U/ALqn83/B2gX2yKQOC16jdFU8WnjXzPKej17CuPKf1855eJ1usV2GDPO +LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI4uJEvlz36hz1 +-----END CERTIFICATE----- + +Starfield Root Certificate Authority - G2 +========================================= +-----BEGIN CERTIFICATE----- +MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMxEDAOBgNVBAgT +B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNobm9s +b2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVsZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0 +eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAw +DgYDVQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQg +VGVjaG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZpY2F0ZSBB +dXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL3twQP89o/8ArFv +W59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMgnLRJdzIpVv257IzdIvpy3Cdhl+72WoTs +bhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNk +N3mSwOxGXn/hbVNMYq/NHwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7Nf +ZTD4p7dNdloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0HZbU +JtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC +AQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0GCSqGSIb3DQEBCwUAA4IBAQARWfol +TwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjUsHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx +4mcujJUDJi5DnUox9g61DLu34jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUw +F5okxBDgBPfg8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K +pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1mMpYjn0q7pBZ +c2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0 +-----END CERTIFICATE----- + +Starfield Services Root Certificate Authority - G2 +================================================== +-----BEGIN CERTIFICATE----- +MIID7zCCAtegAwIBAgIBADANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UEBhMCVVMxEDAOBgNVBAgT +B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNobm9s +b2dpZXMsIEluYy4xOzA5BgNVBAMTMlN0YXJmaWVsZCBTZXJ2aWNlcyBSb290IENlcnRpZmljYXRl +IEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgZgxCzAJBgNV +BAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxT +dGFyZmllbGQgVGVjaG5vbG9naWVzLCBJbmMuMTswOQYDVQQDEzJTdGFyZmllbGQgU2VydmljZXMg +Um9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC +AQoCggEBANUMOsQq+U7i9b4Zl1+OiFOxHz/Lz58gE20pOsgPfTz3a3Y4Y9k2YKibXlwAgLIvWX/2 +h/klQ4bnaRtSmpDhcePYLQ1Ob/bISdm28xpWriu2dBTrz/sm4xq6HZYuajtYlIlHVv8loJNwU4Pa +hHQUw2eeBGg6345AWh1KTs9DkTvnVtYAcMtS7nt9rjrnvDH5RfbCYM8TWQIrgMw0R9+53pBlbQLP +LJGmpufehRhJfGZOozptqbXuNC66DQO4M99H67FrjSXZm86B0UVGMpZwh94CDklDhbZsc7tk6mFB +rMnUVN+HL8cisibMn1lUaJ/8viovxFUcdUBgF4UCVTmLfwUCAwEAAaNCMEAwDwYDVR0TAQH/BAUw +AwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJxfAN+qAdcwKziIorhtSpzyEZGDMA0GCSqG +SIb3DQEBCwUAA4IBAQBLNqaEd2ndOxmfZyMIbw5hyf2E3F/YNoHN2BtBLZ9g3ccaaNnRbobhiCPP +E95Dz+I0swSdHynVv/heyNXBve6SbzJ08pGCL72CQnqtKrcgfU28elUSwhXqvfdqlS5sdJ/PHLTy +xQGjhdByPq1zqwubdQxtRbeOlKyWN7Wg0I8VRw7j6IPdj/3vQQF3zCepYoUz8jcI73HPdwbeyBkd +iEDPfUYd/x7H4c7/I9vG+o1VTqkC50cRRj70/b17KSa7qWFiNyi2LSr2EIZkyXCn0q23KXB56jza +YyWf/Wi3MOxw+3WKt21gZ7IeyLnp2KhvAotnDU0mV3HaIPzBSlCNsSi6 +-----END CERTIFICATE----- + +AffirmTrust Commercial +====================== +-----BEGIN CERTIFICATE----- +MIIDTDCCAjSgAwIBAgIId3cGJyapsXwwDQYJKoZIhvcNAQELBQAwRDELMAkGA1UEBhMCVVMxFDAS +BgNVBAoMC0FmZmlybVRydXN0MR8wHQYDVQQDDBZBZmZpcm1UcnVzdCBDb21tZXJjaWFsMB4XDTEw +MDEyOTE0MDYwNloXDTMwMTIzMTE0MDYwNlowRDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC0FmZmly +bVRydXN0MR8wHQYDVQQDDBZBZmZpcm1UcnVzdCBDb21tZXJjaWFsMIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEA9htPZwcroRX1BiLLHwGy43NFBkRJLLtJJRTWzsO3qyxPxkEylFf6Eqdb +DuKPHx6GGaeqtS25Xw2Kwq+FNXkyLbscYjfysVtKPcrNcV/pQr6U6Mje+SJIZMblq8Yrba0F8PrV +C8+a5fBQpIs7R6UjW3p6+DM/uO+Zl+MgwdYoic+U+7lF7eNAFxHUdPALMeIrJmqbTFeurCA+ukV6 +BfO9m2kVrn1OIGPENXY6BwLJN/3HR+7o8XYdcxXyl6S1yHp52UKqK39c/s4mT6NmgTWvRLpUHhww +MmWd5jyTXlBOeuM61G7MGvv50jeuJCqrVwMiKA1JdX+3KNp1v47j3A55MQIDAQABo0IwQDAdBgNV +HQ4EFgQUnZPGU4teyq8/nx4P5ZmVvCT2lI8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC +AQYwDQYJKoZIhvcNAQELBQADggEBAFis9AQOzcAN/wr91LoWXym9e2iZWEnStB03TX8nfUYGXUPG +hi4+c7ImfU+TqbbEKpqrIZcUsd6M06uJFdhrJNTxFq7YpFzUf1GO7RgBsZNjvbz4YYCanrHOQnDi +qX0GJX0nof5v7LMeJNrjS1UaADs1tDvZ110w/YETifLCBivtZ8SOyUOyXGsViQK8YvxO8rUzqrJv +0wqiUOP2O+guRMLbZjipM1ZI8W0bM40NjD9gN53Tym1+NH4Nn3J2ixufcv1SNUFFApYvHLKac0kh +sUlHRUe072o0EclNmsxZt9YCnlpOZbWUrhvfKbAW8b8Angc6F2S1BLUjIZkKlTuXfO8= +-----END CERTIFICATE----- + +AffirmTrust Networking +====================== +-----BEGIN CERTIFICATE----- +MIIDTDCCAjSgAwIBAgIIfE8EORzUmS0wDQYJKoZIhvcNAQEFBQAwRDELMAkGA1UEBhMCVVMxFDAS +BgNVBAoMC0FmZmlybVRydXN0MR8wHQYDVQQDDBZBZmZpcm1UcnVzdCBOZXR3b3JraW5nMB4XDTEw +MDEyOTE0MDgyNFoXDTMwMTIzMTE0MDgyNFowRDELMAkGA1UEBhMCVVMxFDASBgNVBAoMC0FmZmly +bVRydXN0MR8wHQYDVQQDDBZBZmZpcm1UcnVzdCBOZXR3b3JraW5nMIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAtITMMxcua5Rsa2FSoOujz3mUTOWUgJnLVWREZY9nZOIG41w3SfYvm4SE +Hi3yYJ0wTsyEheIszx6e/jarM3c1RNg1lho9Nuh6DtjVR6FqaYvZ/Ls6rnla1fTWcbuakCNrmreI +dIcMHl+5ni36q1Mr3Lt2PpNMCAiMHqIjHNRqrSK6mQEubWXLviRmVSRLQESxG9fhwoXA3hA/Pe24 +/PHxI1Pcv2WXb9n5QHGNfb2V1M6+oF4nI979ptAmDgAp6zxG8D1gvz9Q0twmQVGeFDdCBKNwV6gb +h+0t+nvujArjqWaJGctB+d1ENmHP4ndGyH329JKBNv3bNPFyfvMMFr20FQIDAQABo0IwQDAdBgNV +HQ4EFgQUBx/S55zawm6iQLSwelAQUHTEyL0wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC +AQYwDQYJKoZIhvcNAQEFBQADggEBAIlXshZ6qML91tmbmzTCnLQyFE2npN/svqe++EPbkTfOtDIu +UFUaNU52Q3Eg75N3ThVwLofDwR1t3Mu1J9QsVtFSUzpE0nPIxBsFZVpikpzuQY0x2+c06lkh1QF6 +12S4ZDnNye2v7UsDSKegmQGA3GWjNq5lWUhPgkvIZfFXHeVZLgo/bNjR9eUJtGxUAArgFU2HdW23 +WJZa3W3SAKD0m0i+wzekujbgfIeFlxoVot4uolu9rxj5kFDNcFn4J2dHy8egBzp90SxdbBk6ZrV9 +/ZFvgrG+CJPbFEfxojfHRZ48x3evZKiT3/Zpg4Jg8klCNO1aAFSFHBY2kgxc+qatv9s= +-----END CERTIFICATE----- + +AffirmTrust Premium +=================== +-----BEGIN CERTIFICATE----- +MIIFRjCCAy6gAwIBAgIIbYwURrGmCu4wDQYJKoZIhvcNAQEMBQAwQTELMAkGA1UEBhMCVVMxFDAS +BgNVBAoMC0FmZmlybVRydXN0MRwwGgYDVQQDDBNBZmZpcm1UcnVzdCBQcmVtaXVtMB4XDTEwMDEy +OTE0MTAzNloXDTQwMTIzMTE0MTAzNlowQTELMAkGA1UEBhMCVVMxFDASBgNVBAoMC0FmZmlybVRy +dXN0MRwwGgYDVQQDDBNBZmZpcm1UcnVzdCBQcmVtaXVtMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A +MIICCgKCAgEAxBLfqV/+Qd3d9Z+K4/as4Tx4mrzY8H96oDMq3I0gW64tb+eT2TZwamjPjlGjhVtn +BKAQJG9dKILBl1fYSCkTtuG+kU3fhQxTGJoeJKJPj/CihQvL9Cl/0qRY7iZNyaqoe5rZ+jjeRFcV +5fiMyNlI4g0WJx0eyIOFJbe6qlVBzAMiSy2RjYvmia9mx+n/K+k8rNrSs8PhaJyJ+HoAVt70VZVs ++7pk3WKL3wt3MutizCaam7uqYoNMtAZ6MMgpv+0GTZe5HMQxK9VfvFMSF5yZVylmd2EhMQcuJUmd +GPLu8ytxjLW6OQdJd/zvLpKQBY0tL3d770O/Nbua2Plzpyzy0FfuKE4mX4+QaAkvuPjcBukumj5R +p9EixAqnOEhss/n/fauGV+O61oV4d7pD6kh/9ti+I20ev9E2bFhc8e6kGVQa9QPSdubhjL08s9NI +S+LI+H+SqHZGnEJlPqQewQcDWkYtuJfzt9WyVSHvutxMAJf7FJUnM7/oQ0dG0giZFmA7mn7S5u04 +6uwBHjxIVkkJx0w3AJ6IDsBz4W9m6XJHMD4Q5QsDyZpCAGzFlH5hxIrff4IaC1nEWTJ3s7xgaVY5 +/bQGeyzWZDbZvUjthB9+pSKPKrhC9IK31FOQeE4tGv2Bb0TXOwF0lkLgAOIua+rF7nKsu7/+6qqo ++Nz2snmKtmcCAwEAAaNCMEAwHQYDVR0OBBYEFJ3AZ6YMItkm9UWrpmVSESfYRaxjMA8GA1UdEwEB +/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBDAUAA4ICAQCzV00QYk465KzquByv +MiPIs0laUZx2KI15qldGF9X1Uva3ROgIRL8YhNILgM3FEv0AVQVhh0HctSSePMTYyPtwni94loMg +Nt58D2kTiKV1NpgIpsbfrM7jWNa3Pt668+s0QNiigfV4Py/VpfzZotReBA4Xrf5B8OWycvpEgjNC +6C1Y91aMYj+6QrCcDFx+LmUmXFNPALJ4fqENmS2NuB2OosSw/WDQMKSOyARiqcTtNd56l+0OOF6S +L5Nwpamcb6d9Ex1+xghIsV5n61EIJenmJWtSKZGc0jlzCFfemQa0W50QBuHCAKi4HEoCChTQwUHK ++4w1IX2COPKpVJEZNZOUbWo6xbLQu4mGk+ibyQ86p3q4ofB4Rvr8Ny/lioTz3/4E2aFooC8k4gmV +BtWVyuEklut89pMFu+1z6S3RdTnX5yTb2E5fQ4+e0BQ5v1VwSJlXMbSc7kqYA5YwH2AG7hsj/oFg +IxpHYoWlzBk0gG+zrBrjn/B7SK3VAdlntqlyk+otZrWyuOQ9PLLvTIzq6we/qzWaVYa8GKa1qF60 +g2xraUDTn9zxw2lrueFtCfTxqlB2Cnp9ehehVZZCmTEJ3WARjQUwfuaORtGdFNrHF+QFlozEJLUb +zxQHskD4o55BhrwE0GuWyCqANP2/7waj3VjFhT0+j/6eKeC2uAloGRwYQw== +-----END CERTIFICATE----- + +AffirmTrust Premium ECC +======================= +-----BEGIN CERTIFICATE----- +MIIB/jCCAYWgAwIBAgIIdJclisc/elQwCgYIKoZIzj0EAwMwRTELMAkGA1UEBhMCVVMxFDASBgNV +BAoMC0FmZmlybVRydXN0MSAwHgYDVQQDDBdBZmZpcm1UcnVzdCBQcmVtaXVtIEVDQzAeFw0xMDAx +MjkxNDIwMjRaFw00MDEyMzExNDIwMjRaMEUxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtBZmZpcm1U +cnVzdDEgMB4GA1UEAwwXQWZmaXJtVHJ1c3QgUHJlbWl1bSBFQ0MwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAAQNMF4bFZ0D0KF5Nbc6PJJ6yhUczWLznCZcBz3lVPqj1swS6vQUX+iOGasvLkjmrBhDeKzQ +N8O9ss0s5kfiGuZjuD0uL3jET9v0D6RoTFVya5UdThhClXjMNzyR4ptlKymjQjBAMB0GA1UdDgQW +BBSaryl6wBE1NSZRMADDav5A1a7WPDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAK +BggqhkjOPQQDAwNnADBkAjAXCfOHiFBar8jAQr9HX/VsaobgxCd05DhT1wV/GzTjxi+zygk8N53X +57hG8f2h4nECMEJZh0PUUd+60wkyWs6Iflc9nF9Ca/UHLbXwgpP5WW+uZPpY5Yse42O+tYHNbwKM +eQ== +-----END CERTIFICATE----- + +Certum Trusted Network CA +========================= +-----BEGIN CERTIFICATE----- +MIIDuzCCAqOgAwIBAgIDBETAMA0GCSqGSIb3DQEBBQUAMH4xCzAJBgNVBAYTAlBMMSIwIAYDVQQK +ExlVbml6ZXRvIFRlY2hub2xvZ2llcyBTLkEuMScwJQYDVQQLEx5DZXJ0dW0gQ2VydGlmaWNhdGlv +biBBdXRob3JpdHkxIjAgBgNVBAMTGUNlcnR1bSBUcnVzdGVkIE5ldHdvcmsgQ0EwHhcNMDgxMDIy +MTIwNzM3WhcNMjkxMjMxMTIwNzM3WjB+MQswCQYDVQQGEwJQTDEiMCAGA1UEChMZVW5pemV0byBU +ZWNobm9sb2dpZXMgUy5BLjEnMCUGA1UECxMeQ2VydHVtIENlcnRpZmljYXRpb24gQXV0aG9yaXR5 +MSIwIAYDVQQDExlDZXJ0dW0gVHJ1c3RlZCBOZXR3b3JrIENBMIIBIjANBgkqhkiG9w0BAQEFAAOC +AQ8AMIIBCgKCAQEA4/t9o3K6wvDJFIf1awFO4W5AB7ptJ11/91sts1rHUV+rpDKmYYe2bg+G0jAC +l/jXaVehGDldamR5xgFZrDwxSjh80gTSSyjoIF87B6LMTXPb865Px1bVWqeWifrzq2jUI4ZZJ88J +J7ysbnKDHDBy3+Ci6dLhdHUZvSqeexVUBBvXQzmtVSjF4hq79MDkrjhJM8x2hZ85RdKknvISjFH4 +fOQtf/WsX+sWn7Et0brMkUJ3TCXJkDhv2/DM+44el1k+1WBO5gUo7Ul5E0u6SNsv+XLTOcr+H9g0 +cvW0QM8xAcPs3hEtF10fuFDRXhmnad4HMyjKUJX5p1TLVIZQRan5SQIDAQABo0IwQDAPBgNVHRMB +Af8EBTADAQH/MB0GA1UdDgQWBBQIds3LB/8k9sXN7buQvOKEN0Z19zAOBgNVHQ8BAf8EBAMCAQYw +DQYJKoZIhvcNAQEFBQADggEBAKaorSLOAT2mo/9i0Eidi15ysHhE49wcrwn9I0j6vSrEuVUEtRCj +jSfeC4Jj0O7eDDd5QVsisrCaQVymcODU0HfLI9MA4GxWL+FpDQ3Zqr8hgVDZBqWo/5U30Kr+4rP1 +mS1FhIrlQgnXdAIv94nYmem8J9RHjboNRhx3zxSkHLmkMcScKHQDNP8zGSal6Q10tz6XxnboJ5aj +Zt3hrvJBW8qYVoNzcOSGGtIxQbovvi0TWnZvTuhOgQ4/WwMioBK+ZlgRSssDxLQqKi2WF+A5VLxI +03YnnZotBqbJ7DnSq9ufmgsnAjUpsUCV5/nonFWIGUbWtzT1fs45mtk48VH3Tyw= +-----END CERTIFICATE----- + +TWCA Root Certification Authority +================================= +-----BEGIN CERTIFICATE----- +MIIDezCCAmOgAwIBAgIBATANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJUVzESMBAGA1UECgwJ +VEFJV0FOLUNBMRAwDgYDVQQLDAdSb290IENBMSowKAYDVQQDDCFUV0NBIFJvb3QgQ2VydGlmaWNh +dGlvbiBBdXRob3JpdHkwHhcNMDgwODI4MDcyNDMzWhcNMzAxMjMxMTU1OTU5WjBfMQswCQYDVQQG +EwJUVzESMBAGA1UECgwJVEFJV0FOLUNBMRAwDgYDVQQLDAdSb290IENBMSowKAYDVQQDDCFUV0NB +IFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCwfnK4pAOU5qfeCTiRShFAh6d8WWQUe7UREN3+v9XAu1bihSX0NXIP+FPQQeFEAcK0HMMx +QhZHhTMidrIKbw/lJVBPhYa+v5guEGcevhEFhgWQxFnQfHgQsIBct+HHK3XLfJ+utdGdIzdjp9xC +oi2SBBtQwXu4PhvJVgSLL1KbralW6cH/ralYhzC2gfeXRfwZVzsrb+RH9JlF/h3x+JejiB03HFyP +4HYlmlD4oFT/RJB2I9IyxsOrBr/8+7/zrX2SYgJbKdM1o5OaQ2RgXbL6Mv87BK9NQGr5x+PvI/1r +y+UPizgN7gr8/g+YnzAx3WxSZfmLgb4i4RxYA7qRG4kHAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIB +BjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRqOFsmjd6LWvJPelSDGRjjCDWmujANBgkqhkiG +9w0BAQUFAAOCAQEAPNV3PdrfibqHDAhUaiBQkr6wQT25JmSDCi/oQMCXKCeCMErJk/9q56YAf4lC +mtYR5VPOL8zy2gXE/uJQxDqGfczafhAJO5I1KlOy/usrBdlsXebQ79NqZp4VKIV66IIArB6nCWlW +QtNoURi+VJq/REG6Sb4gumlc7rh3zc5sH62Dlhh9DrUUOYTxKOkto557HnpyWoOzeW/vtPzQCqVY +T0bf+215WfKEIlKuD8z7fDvnaspHYcN6+NOSBB+4IIThNlQWx0DeO4pz3N/GCUzf7Nr/1FNCocny +Yh0igzyXxfkZYiesZSLX0zzG5Y6yU8xJzrww/nsOM5D77dIUkR8Hrw== +-----END CERTIFICATE----- + +Security Communication RootCA2 +============================== +-----BEGIN CERTIFICATE----- +MIIDdzCCAl+gAwIBAgIBADANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJKUDElMCMGA1UEChMc +U0VDT00gVHJ1c3QgU3lzdGVtcyBDTy4sTFRELjEnMCUGA1UECxMeU2VjdXJpdHkgQ29tbXVuaWNh +dGlvbiBSb290Q0EyMB4XDTA5MDUyOTA1MDAzOVoXDTI5MDUyOTA1MDAzOVowXTELMAkGA1UEBhMC +SlAxJTAjBgNVBAoTHFNFQ09NIFRydXN0IFN5c3RlbXMgQ08uLExURC4xJzAlBgNVBAsTHlNlY3Vy +aXR5IENvbW11bmljYXRpb24gUm9vdENBMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +ANAVOVKxUrO6xVmCxF1SrjpDZYBLx/KWvNs2l9amZIyoXvDjChz335c9S672XewhtUGrzbl+dp++ ++T42NKA7wfYxEUV0kz1XgMX5iZnK5atq1LXaQZAQwdbWQonCv/Q4EpVMVAX3NuRFg3sUZdbcDE3R +3n4MqzvEFb46VqZab3ZpUql6ucjrappdUtAtCms1FgkQhNBqyjoGADdH5H5XTz+L62e4iKrFvlNV +spHEfbmwhRkGeC7bYRr6hfVKkaHnFtWOojnflLhwHyg/i/xAXmODPIMqGplrz95Zajv8bxbXH/1K +EOtOghY6rCcMU/Gt1SSwawNQwS08Ft1ENCcadfsCAwEAAaNCMEAwHQYDVR0OBBYEFAqFqXdlBZh8 +QIH4D5csOPEK7DzPMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEB +CwUAA4IBAQBMOqNErLlFsceTfsgLCkLfZOoc7llsCLqJX2rKSpWeeo8HxdpFcoJxDjrSzG+ntKEj +u/Ykn8sX/oymzsLS28yN/HH8AynBbF0zX2S2ZTuJbxh2ePXcokgfGT+Ok+vx+hfuzU7jBBJV1uXk +3fs+BXziHV7Gp7yXT2g69ekuCkO2r1dcYmh8t/2jioSgrGK+KwmHNPBqAbubKVY8/gA3zyNs8U6q +tnRGEmyR7jTV7JqR50S+kDFy1UkC9gLl9B/rfNmWVan/7Ir5mUf/NVoCqgTLiluHcSmRvaS0eg29 +mvVXIwAHIRc/SjnRBUkLp7Y3gaVdjKozXoEofKd9J+sAro03 +-----END CERTIFICATE----- + +EC-ACC +====== +-----BEGIN CERTIFICATE----- +MIIFVjCCBD6gAwIBAgIQ7is969Qh3hSoYqwE893EATANBgkqhkiG9w0BAQUFADCB8zELMAkGA1UE +BhMCRVMxOzA5BgNVBAoTMkFnZW5jaWEgQ2F0YWxhbmEgZGUgQ2VydGlmaWNhY2lvIChOSUYgUS0w +ODAxMTc2LUkpMSgwJgYDVQQLEx9TZXJ2ZWlzIFB1YmxpY3MgZGUgQ2VydGlmaWNhY2lvMTUwMwYD +VQQLEyxWZWdldSBodHRwczovL3d3dy5jYXRjZXJ0Lm5ldC92ZXJhcnJlbCAoYykwMzE1MDMGA1UE +CxMsSmVyYXJxdWlhIEVudGl0YXRzIGRlIENlcnRpZmljYWNpbyBDYXRhbGFuZXMxDzANBgNVBAMT +BkVDLUFDQzAeFw0wMzAxMDcyMzAwMDBaFw0zMTAxMDcyMjU5NTlaMIHzMQswCQYDVQQGEwJFUzE7 +MDkGA1UEChMyQWdlbmNpYSBDYXRhbGFuYSBkZSBDZXJ0aWZpY2FjaW8gKE5JRiBRLTA4MDExNzYt +SSkxKDAmBgNVBAsTH1NlcnZlaXMgUHVibGljcyBkZSBDZXJ0aWZpY2FjaW8xNTAzBgNVBAsTLFZl +Z2V1IGh0dHBzOi8vd3d3LmNhdGNlcnQubmV0L3ZlcmFycmVsIChjKTAzMTUwMwYDVQQLEyxKZXJh +cnF1aWEgRW50aXRhdHMgZGUgQ2VydGlmaWNhY2lvIENhdGFsYW5lczEPMA0GA1UEAxMGRUMtQUND +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsyLHT+KXQpWIR4NA9h0X84NzJB5R85iK +w5K4/0CQBXCHYMkAqbWUZRkiFRfCQ2xmRJoNBD45b6VLeqpjt4pEndljkYRm4CgPukLjbo73FCeT +ae6RDqNfDrHrZqJyTxIThmV6PttPB/SnCWDaOkKZx7J/sxaVHMf5NLWUhdWZXqBIoH7nF2W4onW4 +HvPlQn2v7fOKSGRdghST2MDk/7NQcvJ29rNdQlB50JQ+awwAvthrDk4q7D7SzIKiGGUzE3eeml0a +E9jD2z3Il3rucO2n5nzbcc8tlGLfbdb1OL4/pYUKGbio2Al1QnDE6u/LDsg0qBIimAy4E5S2S+zw +0JDnJwIDAQABo4HjMIHgMB0GA1UdEQQWMBSBEmVjX2FjY0BjYXRjZXJ0Lm5ldDAPBgNVHRMBAf8E +BTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUoMOLRKo3pUW/l4Ba0fF4opvpXY0wfwYD +VR0gBHgwdjB0BgsrBgEEAfV4AQMBCjBlMCwGCCsGAQUFBwIBFiBodHRwczovL3d3dy5jYXRjZXJ0 +Lm5ldC92ZXJhcnJlbDA1BggrBgEFBQcCAjApGidWZWdldSBodHRwczovL3d3dy5jYXRjZXJ0Lm5l +dC92ZXJhcnJlbCAwDQYJKoZIhvcNAQEFBQADggEBAKBIW4IB9k1IuDlVNZyAelOZ1Vr/sXE7zDkJ +lF7W2u++AVtd0x7Y/X1PzaBB4DSTv8vihpw3kpBWHNzrKQXlxJ7HNd+KDM3FIUPpqojlNcAZQmNa +Al6kSBg6hW/cnbw/nZzBh7h6YQjpdwt/cKt63dmXLGQehb+8dJahw3oS7AwaboMMPOhyRp/7SNVe +l+axofjk70YllJyJ22k4vuxcDlbHZVHlUIiIv0LVKz3l+bqeLrPK9HOSAgu+TGbrIP65y7WZf+a2 +E/rKS03Z7lNGBjvGTq2TWoF+bCpLagVFjPIhpDGQh2xlnJ2lYJU6Un/10asIbvPuW/mIPX64b24D +5EI= +-----END CERTIFICATE----- + +Hellenic Academic and Research Institutions RootCA 2011 +======================================================= +-----BEGIN CERTIFICATE----- +MIIEMTCCAxmgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBlTELMAkGA1UEBhMCR1IxRDBCBgNVBAoT +O0hlbGxlbmljIEFjYWRlbWljIGFuZCBSZXNlYXJjaCBJbnN0aXR1dGlvbnMgQ2VydC4gQXV0aG9y +aXR5MUAwPgYDVQQDEzdIZWxsZW5pYyBBY2FkZW1pYyBhbmQgUmVzZWFyY2ggSW5zdGl0dXRpb25z +IFJvb3RDQSAyMDExMB4XDTExMTIwNjEzNDk1MloXDTMxMTIwMTEzNDk1MlowgZUxCzAJBgNVBAYT +AkdSMUQwQgYDVQQKEztIZWxsZW5pYyBBY2FkZW1pYyBhbmQgUmVzZWFyY2ggSW5zdGl0dXRpb25z +IENlcnQuIEF1dGhvcml0eTFAMD4GA1UEAxM3SGVsbGVuaWMgQWNhZGVtaWMgYW5kIFJlc2VhcmNo +IEluc3RpdHV0aW9ucyBSb290Q0EgMjAxMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AKlTAOMupvaO+mDYLZU++CwqVE7NuYRhlFhPjz2L5EPzdYmNUeTDN9KKiE15HrcS3UN4SoqS5tdI +1Q+kOilENbgH9mgdVc04UfCMJDGFr4PJfel3r+0ae50X+bOdOFAPplp5kYCvN66m0zH7tSYJnTxa +71HFK9+WXesyHgLacEnsbgzImjeN9/E2YEsmLIKe0HjzDQ9jpFEw4fkrJxIH2Oq9GGKYsFk3fb7u +8yBRQlqD75O6aRXxYp2fmTmCobd0LovUxQt7L/DICto9eQqakxylKHJzkUOap9FNhYS5qXSPFEDH +3N6sQWRstBmbAmNtJGSPRLIl6s5ddAxjMlyNh+UCAwEAAaOBiTCBhjAPBgNVHRMBAf8EBTADAQH/ +MAsGA1UdDwQEAwIBBjAdBgNVHQ4EFgQUppFC/RNhSiOeCKQp5dgTBCPuQSUwRwYDVR0eBEAwPqA8 +MAWCAy5ncjAFggMuZXUwBoIELmVkdTAGggQub3JnMAWBAy5ncjAFgQMuZXUwBoEELmVkdTAGgQQu +b3JnMA0GCSqGSIb3DQEBBQUAA4IBAQAf73lB4XtuP7KMhjdCSk4cNx6NZrokgclPEg8hwAOXhiVt +XdMiKahsog2p6z0GW5k6x8zDmjR/qw7IThzh+uTczQ2+vyT+bOdrwg3IBp5OjWEopmr95fZi6hg8 +TqBTnbI6nOulnJEWtk2C4AwFSKls9cz4y51JtPACpf1wA+2KIaWuE4ZJwzNzvoc7dIsXRSZMFpGD +/md9zU1jZ/rzAxKWeAaNsWftjj++n08C9bMJL/NMh98qy5V8AcysNnq/onN694/BtZqhFLKPM58N +7yLcZnuEvUUXBj08yrl3NI/K6s8/MT7jiOOASSXIl7WdmplNsDz4SgCbZN2fOUvRJ9e4 +-----END CERTIFICATE----- + +Actalis Authentication Root CA +============================== +-----BEGIN CERTIFICATE----- +MIIFuzCCA6OgAwIBAgIIVwoRl0LE48wwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVQxDjAM +BgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3RhbGlzIFMucC5BLi8wMzM1ODUyMDk2NzEnMCUGA1UE +AwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBSb290IENBMB4XDTExMDkyMjExMjIwMloXDTMwMDky +MjExMjIwMlowazELMAkGA1UEBhMCSVQxDjAMBgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3RhbGlz +IFMucC5BLi8wMzM1ODUyMDk2NzEnMCUGA1UEAwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBSb290 +IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAp8bEpSmkLO/lGMWwUKNvUTufClrJ +wkg4CsIcoBh/kbWHuUA/3R1oHwiD1S0eiKD4j1aPbZkCkpAW1V8IbInX4ay8IMKx4INRimlNAJZa +by/ARH6jDuSRzVju3PvHHkVH3Se5CAGfpiEd9UEtL0z9KK3giq0itFZljoZUj5NDKd45RnijMCO6 +zfB9E1fAXdKDa0hMxKufgFpbOr3JpyI/gCczWw63igxdBzcIy2zSekciRDXFzMwujt0q7bd9Zg1f +YVEiVRvjRuPjPdA1YprbrxTIW6HMiRvhMCb8oJsfgadHHwTrozmSBp+Z07/T6k9QnBn+locePGX2 +oxgkg4YQ51Q+qDp2JE+BIcXjDwL4k5RHILv+1A7TaLndxHqEguNTVHnd25zS8gebLra8Pu2Fbe8l +EfKXGkJh90qX6IuxEAf6ZYGyojnP9zz/GPvG8VqLWeICrHuS0E4UT1lF9gxeKF+w6D9Fz8+vm2/7 +hNN3WpVvrJSEnu68wEqPSpP4RCHiMUVhUE4Q2OM1fEwZtN4Fv6MGn8i1zeQf1xcGDXqVdFUNaBr8 +EBtiZJ1t4JWgw5QHVw0U5r0F+7if5t+L4sbnfpb2U8WANFAoWPASUHEXMLrmeGO89LKtmyuy/uE5 +jF66CyCU3nuDuP/jVo23Eek7jPKxwV2dpAtMK9myGPW1n0sCAwEAAaNjMGEwHQYDVR0OBBYEFFLY +iDrIn3hm7YnzezhwlMkCAjbQMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUUtiIOsifeGbt +ifN7OHCUyQICNtAwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4ICAQALe3KHwGCmSUyI +WOYdiPcUZEim2FgKDk8TNd81HdTtBjHIgT5q1d07GjLukD0R0i70jsNjLiNmsGe+b7bAEzlgqqI0 +JZN1Ut6nna0Oh4lScWoWPBkdg/iaKWW+9D+a2fDzWochcYBNy+A4mz+7+uAwTc+G02UQGRjRlwKx +K3JCaKygvU5a2hi/a5iB0P2avl4VSM0RFbnAKVy06Ij3Pjaut2L9HmLecHgQHEhb2rykOLpn7VU+ +Xlff1ANATIGk0k9jpwlCCRT8AKnCgHNPLsBA2RF7SOp6AsDT6ygBJlh0wcBzIm2Tlf05fbsq4/aC +4yyXX04fkZT6/iyj2HYauE2yOE+b+h1IYHkm4vP9qdCa6HCPSXrW5b0KDtst842/6+OkfcvHlXHo +2qN8xcL4dJIEG4aspCJTQLas/kx2z/uUMsA1n3Y/buWQbqCmJqK4LL7RK4X9p2jIugErsWx0Hbhz +lefut8cl8ABMALJ+tguLHPPAUJ4lueAI3jZm/zel0btUZCzJJ7VLkn5l/9Mt4blOvH+kQSGQQXem +OR/qnuOf0GZvBeyqdn6/axag67XH/JJULysRJyU3eExRarDzzFhdFPFqSBX/wge2sY0PjlxQRrM9 +vwGYT7JZVEc+NHt4bVaTLnPqZih4zR0Uv6CPLy64Lo7yFIrM6bV8+2ydDKXhlg== +-----END CERTIFICATE----- + +Buypass Class 2 Root CA +======================= +-----BEGIN CERTIFICATE----- +MIIFWTCCA0GgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJOTzEdMBsGA1UECgwU +QnV5cGFzcyBBUy05ODMxNjMzMjcxIDAeBgNVBAMMF0J1eXBhc3MgQ2xhc3MgMiBSb290IENBMB4X +DTEwMTAyNjA4MzgwM1oXDTQwMTAyNjA4MzgwM1owTjELMAkGA1UEBhMCTk8xHTAbBgNVBAoMFEJ1 +eXBhc3MgQVMtOTgzMTYzMzI3MSAwHgYDVQQDDBdCdXlwYXNzIENsYXNzIDIgUm9vdCBDQTCCAiIw +DQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBANfHXvfBB9R3+0Mh9PT1aeTuMgHbo4Yf5FkNuud1 +g1Lr6hxhFUi7HQfKjK6w3Jad6sNgkoaCKHOcVgb/S2TwDCo3SbXlzwx87vFKu3MwZfPVL4O2fuPn +9Z6rYPnT8Z2SdIrkHJasW4DptfQxh6NR/Md+oW+OU3fUl8FVM5I+GC911K2GScuVr1QGbNgGE41b +/+EmGVnAJLqBcXmQRFBoJJRfuLMR8SlBYaNByyM21cHxMlAQTn/0hpPshNOOvEu/XAFOBz3cFIqU +CqTqc/sLUegTBxj6DvEr0VQVfTzh97QZQmdiXnfgolXsttlpF9U6r0TtSsWe5HonfOV116rLJeff +awrbD02TTqigzXsu8lkBarcNuAeBfos4GzjmCleZPe4h6KP1DBbdi+w0jpwqHAAVF41og9JwnxgI +zRFo1clrUs3ERo/ctfPYV3Me6ZQ5BL/T3jjetFPsaRyifsSP5BtwrfKi+fv3FmRmaZ9JUaLiFRhn +Bkp/1Wy1TbMz4GHrXb7pmA8y1x1LPC5aAVKRCfLf6o3YBkBjqhHk/sM3nhRSP/TizPJhk9H9Z2vX +Uq6/aKtAQ6BXNVN48FP4YUIHZMbXb5tMOA1jrGKvNouicwoN9SG9dKpN6nIDSdvHXx1iY8f93ZHs +M+71bbRuMGjeyNYmsHVee7QHIJihdjK4TWxPAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYD +VR0OBBYEFMmAd+BikoL1RpzzuvdMw964o605MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsF +AAOCAgEAU18h9bqwOlI5LJKwbADJ784g7wbylp7ppHR/ehb8t/W2+xUbP6umwHJdELFx7rxP462s +A20ucS6vxOOto70MEae0/0qyexAQH6dXQbLArvQsWdZHEIjzIVEpMMpghq9Gqx3tOluwlN5E40EI +osHsHdb9T7bWR9AUC8rmyrV7d35BH16Dx7aMOZawP5aBQW9gkOLo+fsicdl9sz1Gv7SEr5AcD48S +aq/v7h56rgJKihcrdv6sVIkkLE8/trKnToyokZf7KcZ7XC25y2a2t6hbElGFtQl+Ynhw/qlqYLYd +DnkM/crqJIByw5c/8nerQyIKx+u2DISCLIBrQYoIwOula9+ZEsuK1V6ADJHgJgg2SMX6OBE1/yWD +LfJ6v9r9jv6ly0UsH8SIU653DtmadsWOLB2jutXsMq7Aqqz30XpN69QH4kj3Io6wpJ9qzo6ysmD0 +oyLQI+uUWnpp3Q+/QFesa1lQ2aOZ4W7+jQF5JyMV3pKdewlNWudLSDBaGOYKbeaP4NK75t98biGC +wWg5TbSYWGZizEqQXsP6JwSxeRV0mcy+rSDeJmAc61ZRpqPq5KM/p/9h3PFaTWwyI0PurKju7koS +CTxdccK+efrCh2gdC/1cacwG0Jp9VJkqyTkaGa9LKkPzY11aWOIv4x3kqdbQCtCev9eBCfHJxyYN +rJgWVqA= +-----END CERTIFICATE----- + +Buypass Class 3 Root CA +======================= +-----BEGIN CERTIFICATE----- +MIIFWTCCA0GgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJOTzEdMBsGA1UECgwU +QnV5cGFzcyBBUy05ODMxNjMzMjcxIDAeBgNVBAMMF0J1eXBhc3MgQ2xhc3MgMyBSb290IENBMB4X +DTEwMTAyNjA4Mjg1OFoXDTQwMTAyNjA4Mjg1OFowTjELMAkGA1UEBhMCTk8xHTAbBgNVBAoMFEJ1 +eXBhc3MgQVMtOTgzMTYzMzI3MSAwHgYDVQQDDBdCdXlwYXNzIENsYXNzIDMgUm9vdCBDQTCCAiIw +DQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAKXaCpUWUOOV8l6ddjEGMnqb8RB2uACatVI2zSRH +sJ8YZLya9vrVediQYkwiL944PdbgqOkcLNt4EemOaFEVcsfzM4fkoF0LXOBXByow9c3EN3coTRiR +5r/VUv1xLXA+58bEiuPwKAv0dpihi4dVsjoT/Lc+JzeOIuOoTyrvYLs9tznDDgFHmV0ST9tD+leh +7fmdvhFHJlsTmKtdFoqwNxxXnUX/iJY2v7vKB3tvh2PX0DJq1l1sDPGzbjniazEuOQAnFN44wOwZ +ZoYS6J1yFhNkUsepNxz9gjDthBgd9K5c/3ATAOux9TN6S9ZV+AWNS2mw9bMoNlwUxFFzTWsL8TQH +2xc519woe2v1n/MuwU8XKhDzzMro6/1rqy6any2CbgTUUgGTLT2G/H783+9CHaZr77kgxve9oKeV +/afmiSTYzIw0bOIjL9kSGiG5VZFvC5F5GQytQIgLcOJ60g7YaEi7ghM5EFjp2CoHxhLbWNvSO1UQ +RwUVZ2J+GGOmRj8JDlQyXr8NYnon74Do29lLBlo3WiXQCBJ31G8JUJc9yB3D34xFMFbG02SrZvPA +Xpacw8Tvw3xrizp5f7NJzz3iiZ+gMEuFuZyUJHmPfWupRWgPK9Dx2hzLabjKSWJtyNBjYt1gD1iq +j6G8BaVmos8bdrKEZLFMOVLAMLrwjEsCsLa3AgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYD +VR0OBBYEFEe4zf/lb+74suwvTg75JbCOPGvDMA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsF +AAOCAgEAACAjQTUEkMJAYmDv4jVM1z+s4jSQuKFvdvoWFqRINyzpkMLyPPgKn9iB5btb2iUspKdV +cSQy9sgL8rxq+JOssgfCX5/bzMiKqr5qb+FJEMwx14C7u8jYog5kV+qi9cKpMRXSIGrs/CIBKM+G +uIAeqcwRpTzyFrNHnfzSgCHEy9BHcEGhyoMZCCxt8l13nIoUE9Q2HJLw5QY33KbmkJs4j1xrG0aG +Q0JfPgEHU1RdZX33inOhmlRaHylDFCfChQ+1iHsaO5S3HWCntZznKWlXWpuTekMwGwPXYshApqr8 +ZORK15FTAaggiG6cX0S5y2CBNOxv033aSF/rtJC8LakcC6wc1aJoIIAE1vyxjy+7SjENSoYc6+I2 +KSb12tjE8nVhz36udmNKekBlk4f4HoCMhuWG1o8O/FMsYOgWYRqiPkN7zTlgVGr18okmAWiDSKIz +6MkEkbIRNBE+6tBDGR8Dk5AM/1E9V/RBbuHLoL7ryWPNbczk+DaqaJ3tvV2XcEQNtg413OEMXbug +UZTLfhbrES+jkkXITHHZvMmZUldGL1DPvTVp9D0VzgalLA8+9oG6lLvDu79leNKGef9JOxqDDPDe +eOzI8k1MGt6CKfjBWtrt7uYnXuhF0J0cUahoq0Tj0Itq4/g7u9xN12TyUb7mqqta6THuBrxzvxNi +Cp/HuZc= +-----END CERTIFICATE----- + +T-TeleSec GlobalRoot Class 3 +============================ +-----BEGIN CERTIFICATE----- +MIIDwzCCAqugAwIBAgIBATANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UEBhMCREUxKzApBgNVBAoM +IlQtU3lzdGVtcyBFbnRlcnByaXNlIFNlcnZpY2VzIEdtYkgxHzAdBgNVBAsMFlQtU3lzdGVtcyBU +cnVzdCBDZW50ZXIxJTAjBgNVBAMMHFQtVGVsZVNlYyBHbG9iYWxSb290IENsYXNzIDMwHhcNMDgx +MDAxMTAyOTU2WhcNMzMxMDAxMjM1OTU5WjCBgjELMAkGA1UEBhMCREUxKzApBgNVBAoMIlQtU3lz +dGVtcyBFbnRlcnByaXNlIFNlcnZpY2VzIEdtYkgxHzAdBgNVBAsMFlQtU3lzdGVtcyBUcnVzdCBD +ZW50ZXIxJTAjBgNVBAMMHFQtVGVsZVNlYyBHbG9iYWxSb290IENsYXNzIDMwggEiMA0GCSqGSIb3 +DQEBAQUAA4IBDwAwggEKAoIBAQC9dZPwYiJvJK7genasfb3ZJNW4t/zN8ELg63iIVl6bmlQdTQyK +9tPPcPRStdiTBONGhnFBSivwKixVA9ZIw+A5OO3yXDw/RLyTPWGrTs0NvvAgJ1gORH8EGoel15YU +NpDQSXuhdfsaa3Ox+M6pCSzyU9XDFES4hqX2iys52qMzVNn6chr3IhUciJFrf2blw2qAsCTz34ZF +iP0Zf3WHHx+xGwpzJFu5ZeAsVMhg02YXP+HMVDNzkQI6pn97djmiH5a2OK61yJN0HZ65tOVgnS9W +0eDrXltMEnAMbEQgqxHY9Bn20pxSN+f6tsIxO0rUFJmtxxr1XV/6B7h8DR/Wgx6zAgMBAAGjQjBA +MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBS1A/d2O2GCahKqGFPr +AyGUv/7OyjANBgkqhkiG9w0BAQsFAAOCAQEAVj3vlNW92nOyWL6ukK2YJ5f+AbGwUgC4TeQbIXQb +fsDuXmkqJa9c1h3a0nnJ85cp4IaH3gRZD/FZ1GSFS5mvJQQeyUapl96Cshtwn5z2r3Ex3XsFpSzT +ucpH9sry9uetuUg/vBa3wW306gmv7PO15wWeph6KU1HWk4HMdJP2udqmJQV0eVp+QD6CSyYRMG7h +P0HHRwA11fXT91Q+gT3aSWqas+8QPebrb9HIIkfLzM8BMZLZGOMivgkeGj5asuRrDFR6fUNOuIml +e9eiPZaGzPImNC1qkp2aGtAw4l1OBLBfiyB+d8E9lYLRRpo7PHi4b6HQDWSieB4pTpPDpFQUWw== +-----END CERTIFICATE----- + +D-TRUST Root Class 3 CA 2 2009 +============================== +-----BEGIN CERTIFICATE----- +MIIEMzCCAxugAwIBAgIDCYPzMA0GCSqGSIb3DQEBCwUAME0xCzAJBgNVBAYTAkRFMRUwEwYDVQQK +DAxELVRydXN0IEdtYkgxJzAlBgNVBAMMHkQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgMjAwOTAe +Fw0wOTExMDUwODM1NThaFw0yOTExMDUwODM1NThaME0xCzAJBgNVBAYTAkRFMRUwEwYDVQQKDAxE +LVRydXN0IEdtYkgxJzAlBgNVBAMMHkQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgMjAwOTCCASIw +DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANOySs96R+91myP6Oi/WUEWJNTrGa9v+2wBoqOAD +ER03UAifTUpolDWzU9GUY6cgVq/eUXjsKj3zSEhQPgrfRlWLJ23DEE0NkVJD2IfgXU42tSHKXzlA +BF9bfsyjxiupQB7ZNoTWSPOSHjRGICTBpFGOShrvUD9pXRl/RcPHAY9RySPocq60vFYJfxLLHLGv +KZAKyVXMD9O0Gu1HNVpK7ZxzBCHQqr0ME7UAyiZsxGsMlFqVlNpQmvH/pStmMaTJOKDfHR+4CS7z +p+hnUquVH+BGPtikw8paxTGA6Eian5Rp/hnd2HN8gcqW3o7tszIFZYQ05ub9VxC1X3a/L7AQDcUC +AwEAAaOCARowggEWMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFP3aFMSfMN4hvR5COfyrYyNJ +4PGEMA4GA1UdDwEB/wQEAwIBBjCB0wYDVR0fBIHLMIHIMIGAoH6gfIZ6bGRhcDovL2RpcmVjdG9y +eS5kLXRydXN0Lm5ldC9DTj1ELVRSVVNUJTIwUm9vdCUyMENsYXNzJTIwMyUyMENBJTIwMiUyMDIw +MDksTz1ELVRydXN0JTIwR21iSCxDPURFP2NlcnRpZmljYXRlcmV2b2NhdGlvbmxpc3QwQ6BBoD+G +PWh0dHA6Ly93d3cuZC10cnVzdC5uZXQvY3JsL2QtdHJ1c3Rfcm9vdF9jbGFzc18zX2NhXzJfMjAw +OS5jcmwwDQYJKoZIhvcNAQELBQADggEBAH+X2zDI36ScfSF6gHDOFBJpiBSVYEQBrLLpME+bUMJm +2H6NMLVwMeniacfzcNsgFYbQDfC+rAF1hM5+n02/t2A7nPPKHeJeaNijnZflQGDSNiH+0LS4F9p0 +o3/U37CYAqxva2ssJSRyoWXuJVrl5jLn8t+rSfrzkGkj2wTZ51xY/GXUl77M/C4KzCUqNQT4YJEV +dT1B/yMfGchs64JTBKbkTCJNjYy6zltz7GRUUG3RnFX7acM2w4y8PIWmawomDeCTmGCufsYkl4ph +X5GOZpIJhzbNi5stPvZR1FDUWSi9g/LMKHtThm3YJohw1+qRzT65ysCQblrGXnRl11z+o+I= +-----END CERTIFICATE----- + +D-TRUST Root Class 3 CA 2 EV 2009 +================================= +-----BEGIN CERTIFICATE----- +MIIEQzCCAyugAwIBAgIDCYP0MA0GCSqGSIb3DQEBCwUAMFAxCzAJBgNVBAYTAkRFMRUwEwYDVQQK +DAxELVRydXN0IEdtYkgxKjAoBgNVBAMMIUQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgRVYgMjAw +OTAeFw0wOTExMDUwODUwNDZaFw0yOTExMDUwODUwNDZaMFAxCzAJBgNVBAYTAkRFMRUwEwYDVQQK +DAxELVRydXN0IEdtYkgxKjAoBgNVBAMMIUQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgRVYgMjAw +OTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJnxhDRwui+3MKCOvXwEz75ivJn9gpfS +egpnljgJ9hBOlSJzmY3aFS3nBfwZcyK3jpgAvDw9rKFs+9Z5JUut8Mxk2og+KbgPCdM03TP1YtHh +zRnp7hhPTFiu4h7WDFsVWtg6uMQYZB7jM7K1iXdODL/ZlGsTl28So/6ZqQTMFexgaDbtCHu39b+T +7WYxg4zGcTSHThfqr4uRjRxWQa4iN1438h3Z0S0NL2lRp75mpoo6Kr3HGrHhFPC+Oh25z1uxav60 +sUYgovseO3Dvk5h9jHOW8sXvhXCtKSb8HgQ+HKDYD8tSg2J87otTlZCpV6LqYQXY+U3EJ/pure35 +11H3a6UCAwEAAaOCASQwggEgMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFNOUikxiEyoZLsyv +cop9NteaHNxnMA4GA1UdDwEB/wQEAwIBBjCB3QYDVR0fBIHVMIHSMIGHoIGEoIGBhn9sZGFwOi8v +ZGlyZWN0b3J5LmQtdHJ1c3QubmV0L0NOPUQtVFJVU1QlMjBSb290JTIwQ2xhc3MlMjAzJTIwQ0El +MjAyJTIwRVYlMjAyMDA5LE89RC1UcnVzdCUyMEdtYkgsQz1ERT9jZXJ0aWZpY2F0ZXJldm9jYXRp +b25saXN0MEagRKBChkBodHRwOi8vd3d3LmQtdHJ1c3QubmV0L2NybC9kLXRydXN0X3Jvb3RfY2xh +c3NfM19jYV8yX2V2XzIwMDkuY3JsMA0GCSqGSIb3DQEBCwUAA4IBAQA07XtaPKSUiO8aEXUHL7P+ +PPoeUSbrh/Yp3uDx1MYkCenBz1UbtDDZzhr+BlGmFaQt77JLvyAoJUnRpjZ3NOhk31KxEcdzes05 +nsKtjHEh8lprr988TlWvsoRlFIm5d8sqMb7Po23Pb0iUMkZv53GMoKaEGTcH8gNFCSuGdXzfX2lX +ANtu2KZyIktQ1HWYVt+3GP9DQ1CuekR78HlR10M9p9OB0/DJT7naxpeG0ILD5EJt/rDiZE4OJudA +NCa1CInXCGNjOCd1HjPqbqjdn5lPdE2BiYBL3ZqXKVwvvoFBuYz/6n1gBp7N1z3TLqMVvKjmJuVv +w9y4AyHqnxbxLFS1 +-----END CERTIFICATE----- + +CA Disig Root R2 +================ +-----BEGIN CERTIFICATE----- +MIIFaTCCA1GgAwIBAgIJAJK4iNuwisFjMA0GCSqGSIb3DQEBCwUAMFIxCzAJBgNVBAYTAlNLMRMw +EQYDVQQHEwpCcmF0aXNsYXZhMRMwEQYDVQQKEwpEaXNpZyBhLnMuMRkwFwYDVQQDExBDQSBEaXNp +ZyBSb290IFIyMB4XDTEyMDcxOTA5MTUzMFoXDTQyMDcxOTA5MTUzMFowUjELMAkGA1UEBhMCU0sx +EzARBgNVBAcTCkJyYXRpc2xhdmExEzARBgNVBAoTCkRpc2lnIGEucy4xGTAXBgNVBAMTEENBIERp +c2lnIFJvb3QgUjIwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCio8QACdaFXS1tFPbC +w3OeNcJxVX6B+6tGUODBfEl45qt5WDza/3wcn9iXAng+a0EE6UG9vgMsRfYvZNSrXaNHPWSb6Wia +xswbP7q+sos0Ai6YVRn8jG+qX9pMzk0DIaPY0jSTVpbLTAwAFjxfGs3Ix2ymrdMxp7zo5eFm1tL7 +A7RBZckQrg4FY8aAamkw/dLukO8NJ9+flXP04SXabBbeQTg06ov80egEFGEtQX6sx3dOy1FU+16S +GBsEWmjGycT6txOgmLcRK7fWV8x8nhfRyyX+hk4kLlYMeE2eARKmK6cBZW58Yh2EhN/qwGu1pSqV +g8NTEQxzHQuyRpDRQjrOQG6Vrf/GlK1ul4SOfW+eioANSW1z4nuSHsPzwfPrLgVv2RvPN3YEyLRa +5Beny912H9AZdugsBbPWnDTYltxhh5EF5EQIM8HauQhl1K6yNg3ruji6DOWbnuuNZt2Zz9aJQfYE +koopKW1rOhzndX0CcQ7zwOe9yxndnWCywmZgtrEE7snmhrmaZkCo5xHtgUUDi/ZnWejBBhG93c+A +Ak9lQHhcR1DIm+YfgXvkRKhbhZri3lrVx/k6RGZL5DJUfORsnLMOPReisjQS1n6yqEm70XooQL6i +Fh/f5DcfEXP7kAplQ6INfPgGAVUzfbANuPT1rqVCV3w2EYx7XsQDnYx5nQIDAQABo0IwQDAPBgNV +HRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUtZn4r7CU9eMg1gqtzk5WpC5u +Qu0wDQYJKoZIhvcNAQELBQADggIBACYGXnDnZTPIgm7ZnBc6G3pmsgH2eDtpXi/q/075KMOYKmFM +tCQSin1tERT3nLXK5ryeJ45MGcipvXrA1zYObYVybqjGom32+nNjf7xueQgcnYqfGopTpti72TVV +sRHFqQOzVju5hJMiXn7B9hJSi+osZ7z+Nkz1uM/Rs0mSO9MpDpkblvdhuDvEK7Z4bLQjb/D907Je +dR+Zlais9trhxTF7+9FGs9K8Z7RiVLoJ92Owk6Ka+elSLotgEqv89WBW7xBci8QaQtyDW2QOy7W8 +1k/BfDxujRNt+3vrMNDcTa/F1balTFtxyegxvug4BkihGuLq0t4SOVga/4AOgnXmt8kHbA7v/zjx +mHHEt38OFdAlab0inSvtBfZGR6ztwPDUO+Ls7pZbkBNOHlY667DvlruWIxG68kOGdGSVyCh13x01 +utI3gzhTODY7z2zp+WsO0PsE6E9312UBeIYMej4hYvF/Y3EMyZ9E26gnonW+boE+18DrG5gPcFw0 +sorMwIUY6256s/daoQe/qUKS82Ail+QUoQebTnbAjn39pCXHR+3/H3OszMOl6W8KjptlwlCFtaOg +UxLMVYdh84GuEEZhvUQhuMI9dM9+JDX6HAcOmz0iyu8xL4ysEr3vQCj8KWefshNPZiTEUxnpHikV +7+ZtsH8tZ/3zbBt1RqPlShfppNcL +-----END CERTIFICATE----- + +ACCVRAIZ1 +========= +-----BEGIN CERTIFICATE----- +MIIH0zCCBbugAwIBAgIIXsO3pkN/pOAwDQYJKoZIhvcNAQEFBQAwQjESMBAGA1UEAwwJQUNDVlJB +SVoxMRAwDgYDVQQLDAdQS0lBQ0NWMQ0wCwYDVQQKDARBQ0NWMQswCQYDVQQGEwJFUzAeFw0xMTA1 +MDUwOTM3MzdaFw0zMDEyMzEwOTM3MzdaMEIxEjAQBgNVBAMMCUFDQ1ZSQUlaMTEQMA4GA1UECwwH +UEtJQUNDVjENMAsGA1UECgwEQUNDVjELMAkGA1UEBhMCRVMwggIiMA0GCSqGSIb3DQEBAQUAA4IC +DwAwggIKAoICAQCbqau/YUqXry+XZpp0X9DZlv3P4uRm7x8fRzPCRKPfmt4ftVTdFXxpNRFvu8gM +jmoYHtiP2Ra8EEg2XPBjs5BaXCQ316PWywlxufEBcoSwfdtNgM3802/J+Nq2DoLSRYWoG2ioPej0 +RGy9ocLLA76MPhMAhN9KSMDjIgro6TenGEyxCQ0jVn8ETdkXhBilyNpAlHPrzg5XPAOBOp0KoVdD +aaxXbXmQeOW1tDvYvEyNKKGno6e6Ak4l0Squ7a4DIrhrIA8wKFSVf+DuzgpmndFALW4ir50awQUZ +0m/A8p/4e7MCQvtQqR0tkw8jq8bBD5L/0KIV9VMJcRz/RROE5iZe+OCIHAr8Fraocwa48GOEAqDG +WuzndN9wrqODJerWx5eHk6fGioozl2A3ED6XPm4pFdahD9GILBKfb6qkxkLrQaLjlUPTAYVtjrs7 +8yM2x/474KElB0iryYl0/wiPgL/AlmXz7uxLaL2diMMxs0Dx6M/2OLuc5NF/1OVYm3z61PMOm3WR +5LpSLhl+0fXNWhn8ugb2+1KoS5kE3fj5tItQo05iifCHJPqDQsGH+tUtKSpacXpkatcnYGMN285J +9Y0fkIkyF/hzQ7jSWpOGYdbhdQrqeWZ2iE9x6wQl1gpaepPluUsXQA+xtrn13k/c4LOsOxFwYIRK +Q26ZIMApcQrAZQIDAQABo4ICyzCCAscwfQYIKwYBBQUHAQEEcTBvMEwGCCsGAQUFBzAChkBodHRw +Oi8vd3d3LmFjY3YuZXMvZmlsZWFkbWluL0FyY2hpdm9zL2NlcnRpZmljYWRvcy9yYWl6YWNjdjEu +Y3J0MB8GCCsGAQUFBzABhhNodHRwOi8vb2NzcC5hY2N2LmVzMB0GA1UdDgQWBBTSh7Tj3zcnk1X2 +VuqB5TbMjB4/vTAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFNKHtOPfNyeTVfZW6oHlNsyM +Hj+9MIIBcwYDVR0gBIIBajCCAWYwggFiBgRVHSAAMIIBWDCCASIGCCsGAQUFBwICMIIBFB6CARAA +QQB1AHQAbwByAGkAZABhAGQAIABkAGUAIABDAGUAcgB0AGkAZgBpAGMAYQBjAGkA8wBuACAAUgBh +AO0AegAgAGQAZQAgAGwAYQAgAEEAQwBDAFYAIAAoAEEAZwBlAG4AYwBpAGEAIABkAGUAIABUAGUA +YwBuAG8AbABvAGcA7QBhACAAeQAgAEMAZQByAHQAaQBmAGkAYwBhAGMAaQDzAG4AIABFAGwAZQBj +AHQAcgDzAG4AaQBjAGEALAAgAEMASQBGACAAUQA0ADYAMAAxADEANQA2AEUAKQAuACAAQwBQAFMA +IABlAG4AIABoAHQAdABwADoALwAvAHcAdwB3AC4AYQBjAGMAdgAuAGUAczAwBggrBgEFBQcCARYk +aHR0cDovL3d3dy5hY2N2LmVzL2xlZ2lzbGFjaW9uX2MuaHRtMFUGA1UdHwROMEwwSqBIoEaGRGh0 +dHA6Ly93d3cuYWNjdi5lcy9maWxlYWRtaW4vQXJjaGl2b3MvY2VydGlmaWNhZG9zL3JhaXphY2N2 +MV9kZXIuY3JsMA4GA1UdDwEB/wQEAwIBBjAXBgNVHREEEDAOgQxhY2N2QGFjY3YuZXMwDQYJKoZI +hvcNAQEFBQADggIBAJcxAp/n/UNnSEQU5CmH7UwoZtCPNdpNYbdKl02125DgBS4OxnnQ8pdpD70E +R9m+27Up2pvZrqmZ1dM8MJP1jaGo/AaNRPTKFpV8M9xii6g3+CfYCS0b78gUJyCpZET/LtZ1qmxN +YEAZSUNUY9rizLpm5U9EelvZaoErQNV/+QEnWCzI7UiRfD+mAM/EKXMRNt6GGT6d7hmKG9Ww7Y49 +nCrADdg9ZuM8Db3VlFzi4qc1GwQA9j9ajepDvV+JHanBsMyZ4k0ACtrJJ1vnE5Bc5PUzolVt3OAJ +TS+xJlsndQAJxGJ3KQhfnlmstn6tn1QwIgPBHnFk/vk4CpYY3QIUrCPLBhwepH2NDd4nQeit2hW3 +sCPdK6jT2iWH7ehVRE2I9DZ+hJp4rPcOVkkO1jMl1oRQQmwgEh0q1b688nCBpHBgvgW1m54ERL5h +I6zppSSMEYCUWqKiuUnSwdzRp+0xESyeGabu4VXhwOrPDYTkF7eifKXeVSUG7szAh1xA2syVP1Xg +Nce4hL60Xc16gwFy7ofmXx2utYXGJt/mwZrpHgJHnyqobalbz+xFd3+YJ5oyXSrjhO7FmGYvliAd +3djDJ9ew+f7Zfc3Qn48LFFhRny+Lwzgt3uiP1o2HpPVWQxaZLPSkVrQ0uGE3ycJYgBugl6H8WY3p +EfbRD0tVNEYqi4Y7 +-----END CERTIFICATE----- + +TWCA Global Root CA +=================== +-----BEGIN CERTIFICATE----- +MIIFQTCCAymgAwIBAgICDL4wDQYJKoZIhvcNAQELBQAwUTELMAkGA1UEBhMCVFcxEjAQBgNVBAoT +CVRBSVdBTi1DQTEQMA4GA1UECxMHUm9vdCBDQTEcMBoGA1UEAxMTVFdDQSBHbG9iYWwgUm9vdCBD +QTAeFw0xMjA2MjcwNjI4MzNaFw0zMDEyMzExNTU5NTlaMFExCzAJBgNVBAYTAlRXMRIwEAYDVQQK +EwlUQUlXQU4tQ0ExEDAOBgNVBAsTB1Jvb3QgQ0ExHDAaBgNVBAMTE1RXQ0EgR2xvYmFsIFJvb3Qg +Q0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCwBdvI64zEbooh745NnHEKH1Jw7W2C +nJfF10xORUnLQEK1EjRsGcJ0pDFfhQKX7EMzClPSnIyOt7h52yvVavKOZsTuKwEHktSz0ALfUPZV +r2YOy+BHYC8rMjk1Ujoog/h7FsYYuGLWRyWRzvAZEk2tY/XTP3VfKfChMBwqoJimFb3u/Rk28OKR +Q4/6ytYQJ0lM793B8YVwm8rqqFpD/G2Gb3PpN0Wp8DbHzIh1HrtsBv+baz4X7GGqcXzGHaL3SekV +tTzWoWH1EfcFbx39Eb7QMAfCKbAJTibc46KokWofwpFFiFzlmLhxpRUZyXx1EcxwdE8tmx2RRP1W +KKD+u4ZqyPpcC1jcxkt2yKsi2XMPpfRaAok/T54igu6idFMqPVMnaR1sjjIsZAAmY2E2TqNGtz99 +sy2sbZCilaLOz9qC5wc0GZbpuCGqKX6mOL6OKUohZnkfs8O1CWfe1tQHRvMq2uYiN2DLgbYPoA/p +yJV/v1WRBXrPPRXAb94JlAGD1zQbzECl8LibZ9WYkTunhHiVJqRaCPgrdLQABDzfuBSO6N+pjWxn +kjMdwLfS7JLIvgm/LCkFbwJrnu+8vyq8W8BQj0FwcYeyTbcEqYSjMq+u7msXi7Kx/mzhkIyIqJdI +zshNy/MGz19qCkKxHh53L46g5pIOBvwFItIm4TFRfTLcDwIDAQABoyMwITAOBgNVHQ8BAf8EBAMC +AQYwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAXzSBdu+WHdXltdkCY4QWwa6g +cFGn90xHNcgL1yg9iXHZqjNB6hQbbCEAwGxCGX6faVsgQt+i0trEfJdLjbDorMjupWkEmQqSpqsn +LhpNgb+E1HAerUf+/UqdM+DyucRFCCEK2mlpc3INvjT+lIutwx4116KD7+U4x6WFH6vPNOw/KP4M +8VeGTslV9xzU2KV9Bnpv1d8Q34FOIWWxtuEXeZVFBs5fzNxGiWNoRI2T9GRwoD2dKAXDOXC4Ynsg +/eTb6QihuJ49CcdP+yz4k3ZB3lLg4VfSnQO8d57+nile98FRYB/e2guyLXW3Q0iT5/Z5xoRdgFlg +lPx4mI88k1HtQJAH32RjJMtOcQWh15QaiDLxInQirqWm2BJpTGCjAu4r7NRjkgtevi92a6O2JryP +A9gK8kxkRr05YuWW6zRjESjMlfGt7+/cgFhI6Uu46mWs6fyAtbXIRfmswZ/ZuepiiI7E8UuDEq3m +i4TWnsLrgxifarsbJGAzcMzs9zLzXNl5fe+epP7JI8Mk7hWSsT2RTyaGvWZzJBPqpK5jwa19hAM8 +EHiGG3njxPPyBJUgriOCxLM6AGK/5jYk4Ve6xx6QddVfP5VhK8E7zeWzaGHQRiapIVJpLesux+t3 +zqY6tQMzT3bR51xUAV3LePTJDL/PEo4XLSNolOer/qmyKwbQBM0= +-----END CERTIFICATE----- + +TeliaSonera Root CA v1 +====================== +-----BEGIN CERTIFICATE----- +MIIFODCCAyCgAwIBAgIRAJW+FqD3LkbxezmCcvqLzZYwDQYJKoZIhvcNAQEFBQAwNzEUMBIGA1UE +CgwLVGVsaWFTb25lcmExHzAdBgNVBAMMFlRlbGlhU29uZXJhIFJvb3QgQ0EgdjEwHhcNMDcxMDE4 +MTIwMDUwWhcNMzIxMDE4MTIwMDUwWjA3MRQwEgYDVQQKDAtUZWxpYVNvbmVyYTEfMB0GA1UEAwwW +VGVsaWFTb25lcmEgUm9vdCBDQSB2MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMK+ +6yfwIaPzaSZVfp3FVRaRXP3vIb9TgHot0pGMYzHw7CTww6XScnwQbfQ3t+XmfHnqjLWCi65ItqwA +3GV17CpNX8GH9SBlK4GoRz6JI5UwFpB/6FcHSOcZrr9FZ7E3GwYq/t75rH2D+1665I+XZ75Ljo1k +B1c4VWk0Nj0TSO9P4tNmHqTPGrdeNjPUtAa9GAH9d4RQAEX1jF3oI7x+/jXh7VB7qTCNGdMJjmhn +Xb88lxhTuylixcpecsHHltTbLaC0H2kD7OriUPEMPPCs81Mt8Bz17Ww5OXOAFshSsCPN4D7c3TxH +oLs1iuKYaIu+5b9y7tL6pe0S7fyYGKkmdtwoSxAgHNN/Fnct7W+A90m7UwW7XWjH1Mh1Fj+JWov3 +F0fUTPHSiXk+TT2YqGHeOh7S+F4D4MHJHIzTjU3TlTazN19jY5szFPAtJmtTfImMMsJu7D0hADnJ +oWjiUIMusDor8zagrC/kb2HCUQk5PotTubtn2txTuXZZNp1D5SDgPTJghSJRt8czu90VL6R4pgd7 +gUY2BIbdeTXHlSw7sKMXNeVzH7RcWe/a6hBle3rQf5+ztCo3O3CLm1u5K7fsslESl1MpWtTwEhDc +TwK7EpIvYtQ/aUN8Ddb8WHUBiJ1YFkveupD/RwGJBmr2X7KQarMCpgKIv7NHfirZ1fpoeDVNAgMB +AAGjPzA9MA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgEGMB0GA1UdDgQWBBTwj1k4ALP1j5qW +DNXr+nuqF+gTEjANBgkqhkiG9w0BAQUFAAOCAgEAvuRcYk4k9AwI//DTDGjkk0kiP0Qnb7tt3oNm +zqjMDfz1mgbldxSR651Be5kqhOX//CHBXfDkH1e3damhXwIm/9fH907eT/j3HEbAek9ALCI18Bmx +0GtnLLCo4MBANzX2hFxc469CeP6nyQ1Q6g2EdvZR74NTxnr/DlZJLo961gzmJ1TjTQpgcmLNkQfW +pb/ImWvtxBnmq0wROMVvMeJuScg/doAmAyYp4Db29iBT4xdwNBedY2gea+zDTYa4EzAvXUYNR0PV +G6pZDrlcjQZIrXSHX8f8MVRBE+LHIQ6e4B4N4cB7Q4WQxYpYxmUKeFfyxiMPAdkgS94P+5KFdSpc +c41teyWRyu5FrgZLAMzTsVlQ2jqIOylDRl6XK1TOU2+NSueW+r9xDkKLfP0ooNBIytrEgUy7onOT +JsjrDNYmiLbAJM+7vVvrdX3pCI6GMyx5dwlppYn8s3CQh3aP0yK7Qs69cwsgJirQmz1wHiRszYd2 +qReWt88NkvuOGKmYSdGe/mBEciG5Ge3C9THxOUiIkCR1VBatzvT4aRRkOfujuLpwQMcnHL/EVlP6 +Y2XQ8xwOFvVrhlhNGNTkDY6lnVuR3HYkUD/GKvvZt5y11ubQ2egZixVxSK236thZiNSQvxaz2ems +WWFUyBy6ysHK4bkgTI86k4mloMy/0/Z1pHWWbVY= +-----END CERTIFICATE----- + +E-Tugra Certification Authority +=============================== +-----BEGIN CERTIFICATE----- +MIIGSzCCBDOgAwIBAgIIamg+nFGby1MwDQYJKoZIhvcNAQELBQAwgbIxCzAJBgNVBAYTAlRSMQ8w +DQYDVQQHDAZBbmthcmExQDA+BgNVBAoMN0UtVHXEn3JhIEVCRyBCaWxpxZ9pbSBUZWtub2xvamls +ZXJpIHZlIEhpem1ldGxlcmkgQS7Fni4xJjAkBgNVBAsMHUUtVHVncmEgU2VydGlmaWthc3lvbiBN +ZXJrZXppMSgwJgYDVQQDDB9FLVR1Z3JhIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTEzMDMw +NTEyMDk0OFoXDTIzMDMwMzEyMDk0OFowgbIxCzAJBgNVBAYTAlRSMQ8wDQYDVQQHDAZBbmthcmEx +QDA+BgNVBAoMN0UtVHXEn3JhIEVCRyBCaWxpxZ9pbSBUZWtub2xvamlsZXJpIHZlIEhpem1ldGxl +cmkgQS7Fni4xJjAkBgNVBAsMHUUtVHVncmEgU2VydGlmaWthc3lvbiBNZXJrZXppMSgwJgYDVQQD +DB9FLVR1Z3JhIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIICIjANBgkqhkiG9w0BAQEFAAOCAg8A +MIICCgKCAgEA4vU/kwVRHoViVF56C/UYB4Oufq9899SKa6VjQzm5S/fDxmSJPZQuVIBSOTkHS0vd +hQd2h8y/L5VMzH2nPbxHD5hw+IyFHnSOkm0bQNGZDbt1bsipa5rAhDGvykPL6ys06I+XawGb1Q5K +CKpbknSFQ9OArqGIW66z6l7LFpp3RMih9lRozt6Plyu6W0ACDGQXwLWTzeHxE2bODHnv0ZEoq1+g +ElIwcxmOj+GMB6LDu0rw6h8VqO4lzKRG+Bsi77MOQ7osJLjFLFzUHPhdZL3Dk14opz8n8Y4e0ypQ +BaNV2cvnOVPAmJ6MVGKLJrD3fY185MaeZkJVgkfnsliNZvcHfC425lAcP9tDJMW/hkd5s3kc91r0 +E+xs+D/iWR+V7kI+ua2oMoVJl0b+SzGPWsutdEcf6ZG33ygEIqDUD13ieU/qbIWGvaimzuT6w+Gz +rt48Ue7LE3wBf4QOXVGUnhMMti6lTPk5cDZvlsouDERVxcr6XQKj39ZkjFqzAQqptQpHF//vkUAq +jqFGOjGY5RH8zLtJVor8udBhmm9lbObDyz51Sf6Pp+KJxWfXnUYTTjF2OySznhFlhqt/7x3U+Lzn +rFpct1pHXFXOVbQicVtbC/DP3KBhZOqp12gKY6fgDT+gr9Oq0n7vUaDmUStVkhUXU8u3Zg5mTPj5 +dUyQ5xJwx0UCAwEAAaNjMGEwHQYDVR0OBBYEFC7j27JJ0JxUeVz6Jyr+zE7S6E5UMA8GA1UdEwEB +/wQFMAMBAf8wHwYDVR0jBBgwFoAULuPbsknQnFR5XPonKv7MTtLoTlQwDgYDVR0PAQH/BAQDAgEG +MA0GCSqGSIb3DQEBCwUAA4ICAQAFNzr0TbdF4kV1JI+2d1LoHNgQk2Xz8lkGpD4eKexd0dCrfOAK +kEh47U6YA5n+KGCRHTAduGN8qOY1tfrTYXbm1gdLymmasoR6d5NFFxWfJNCYExL/u6Au/U5Mh/jO +XKqYGwXgAEZKgoClM4so3O0409/lPun++1ndYYRP0lSWE2ETPo+Aab6TR7U1Q9Jauz1c77NCR807 +VRMGsAnb/WP2OogKmW9+4c4bU2pEZiNRCHu8W1Ki/QY3OEBhj0qWuJA3+GbHeJAAFS6LrVE1Uweo +a2iu+U48BybNCAVwzDk/dr2l02cmAYamU9JgO3xDf1WKvJUawSg5TB9D0pH0clmKuVb8P7Sd2nCc +dlqMQ1DujjByTd//SffGqWfZbawCEeI6FiWnWAjLb1NBnEg4R2gz0dfHj9R0IdTDBZB6/86WiLEV +KV0jq9BgoRJP3vQXzTLlyb/IQ639Lo7xr+L0mPoSHyDYwKcMhcWQ9DstliaxLL5Mq+ux0orJ23gT +Dx4JnW2PAJ8C2sH6H3p6CcRK5ogql5+Ji/03X186zjhZhkuvcQu02PJwT58yE+Owp1fl2tpDy4Q0 +8ijE6m30Ku/Ba3ba+367hTzSU8JNvnHhRdH9I2cNE3X7z2VnIp2usAnRCf8dNL/+I5c30jn6PQ0G +C7TbO6Orb1wdtn7os4I07QZcJA== +-----END CERTIFICATE----- + +T-TeleSec GlobalRoot Class 2 +============================ +-----BEGIN CERTIFICATE----- +MIIDwzCCAqugAwIBAgIBATANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UEBhMCREUxKzApBgNVBAoM +IlQtU3lzdGVtcyBFbnRlcnByaXNlIFNlcnZpY2VzIEdtYkgxHzAdBgNVBAsMFlQtU3lzdGVtcyBU +cnVzdCBDZW50ZXIxJTAjBgNVBAMMHFQtVGVsZVNlYyBHbG9iYWxSb290IENsYXNzIDIwHhcNMDgx +MDAxMTA0MDE0WhcNMzMxMDAxMjM1OTU5WjCBgjELMAkGA1UEBhMCREUxKzApBgNVBAoMIlQtU3lz +dGVtcyBFbnRlcnByaXNlIFNlcnZpY2VzIEdtYkgxHzAdBgNVBAsMFlQtU3lzdGVtcyBUcnVzdCBD +ZW50ZXIxJTAjBgNVBAMMHFQtVGVsZVNlYyBHbG9iYWxSb290IENsYXNzIDIwggEiMA0GCSqGSIb3 +DQEBAQUAA4IBDwAwggEKAoIBAQCqX9obX+hzkeXaXPSi5kfl82hVYAUdAqSzm1nzHoqvNK38DcLZ +SBnuaY/JIPwhqgcZ7bBcrGXHX+0CfHt8LRvWurmAwhiCFoT6ZrAIxlQjgeTNuUk/9k9uN0goOA/F +vudocP05l03Sx5iRUKrERLMjfTlH6VJi1hKTXrcxlkIF+3anHqP1wvzpesVsqXFP6st4vGCvx970 +2cu+fjOlbpSD8DT6IavqjnKgP6TeMFvvhk1qlVtDRKgQFRzlAVfFmPHmBiiRqiDFt1MmUUOyCxGV +WOHAD3bZwI18gfNycJ5v/hqO2V81xrJvNHy+SE/iWjnX2J14np+GPgNeGYtEotXHAgMBAAGjQjBA +MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBS/WSA2AHmgoCJrjNXy +YdK4LMuCSjANBgkqhkiG9w0BAQsFAAOCAQEAMQOiYQsfdOhyNsZt+U2e+iKo4YFWz827n+qrkRk4 +r6p8FU3ztqONpfSO9kSpp+ghla0+AGIWiPACuvxhI+YzmzB6azZie60EI4RYZeLbK4rnJVM3YlNf +vNoBYimipidx5joifsFvHZVwIEoHNN/q/xWA5brXethbdXwFeilHfkCoMRN3zUA7tFFHei4R40cR +3p1m0IvVVGb6g1XqfMIpiRvpb7PO4gWEyS8+eIVibslfwXhjdFjASBgMmTnrpMwatXlajRWc2BQN +9noHV8cigwUtPJslJj0Ys6lDfMjIq2SPDqO/nBudMNva0Bkuqjzx+zOAduTNrRlPBSeOE6Fuwg== +-----END CERTIFICATE----- + +Atos TrustedRoot 2011 +===================== +-----BEGIN CERTIFICATE----- +MIIDdzCCAl+gAwIBAgIIXDPLYixfszIwDQYJKoZIhvcNAQELBQAwPDEeMBwGA1UEAwwVQXRvcyBU +cnVzdGVkUm9vdCAyMDExMQ0wCwYDVQQKDARBdG9zMQswCQYDVQQGEwJERTAeFw0xMTA3MDcxNDU4 +MzBaFw0zMDEyMzEyMzU5NTlaMDwxHjAcBgNVBAMMFUF0b3MgVHJ1c3RlZFJvb3QgMjAxMTENMAsG +A1UECgwEQXRvczELMAkGA1UEBhMCREUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCV +hTuXbyo7LjvPpvMpNb7PGKw+qtn4TaA+Gke5vJrf8v7MPkfoepbCJI419KkM/IL9bcFyYie96mvr +54rMVD6QUM+A1JX76LWC1BTFtqlVJVfbsVD2sGBkWXppzwO3bw2+yj5vdHLqqjAqc2K+SZFhyBH+ +DgMq92og3AIVDV4VavzjgsG1xZ1kCWyjWZgHJ8cblithdHFsQ/H3NYkQ4J7sVaE3IqKHBAUsR320 +HLliKWYoyrfhk/WklAOZuXCFteZI6o1Q/NnezG8HDt0Lcp2AMBYHlT8oDv3FdU9T1nSatCQujgKR +z3bFmx5VdJx4IbHwLfELn8LVlhgf8FQieowHAgMBAAGjfTB7MB0GA1UdDgQWBBSnpQaxLKYJYO7R +l+lwrrw7GWzbITAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKelBrEspglg7tGX6XCuvDsZ +bNshMBgGA1UdIAQRMA8wDQYLKwYBBAGwLQMEAQEwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEB +CwUAA4IBAQAmdzTblEiGKkGdLD4GkGDEjKwLVLgfuXvTBznk+j57sj1O7Z8jvZfza1zv7v1Apt+h +k6EKhqzvINB5Ab149xnYJDE0BAGmuhWawyfc2E8PzBhj/5kPDpFrdRbhIfzYJsdHt6bPWHJxfrrh +TZVHO8mvbaG0weyJ9rQPOLXiZNwlz6bb65pcmaHFCN795trV1lpFDMS3wrUU77QR/w4VtfX128a9 +61qn8FYiqTxlVMYVqL2Gns2Dlmh6cYGJ4Qvh6hEbaAjMaZ7snkGeRDImeuKHCnE96+RapNLbxc3G +3mB/ufNPRJLvKrcYPqcZ2Qt9sTdBQrC6YB3y/gkRsPCHe6ed +-----END CERTIFICATE----- + +QuoVadis Root CA 1 G3 +===================== +-----BEGIN CERTIFICATE----- +MIIFYDCCA0igAwIBAgIUeFhfLq0sGUvjNwc1NBMotZbUZZMwDQYJKoZIhvcNAQELBQAwSDELMAkG +A1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxHjAcBgNVBAMTFVF1b1ZhZGlzIFJv +b3QgQ0EgMSBHMzAeFw0xMjAxMTIxNzI3NDRaFw00MjAxMTIxNzI3NDRaMEgxCzAJBgNVBAYTAkJN +MRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMR4wHAYDVQQDExVRdW9WYWRpcyBSb290IENBIDEg +RzMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCgvlAQjunybEC0BJyFuTHK3C3kEakE +PBtVwedYMB0ktMPvhd6MLOHBPd+C5k+tR4ds7FtJwUrVu4/sh6x/gpqG7D0DmVIB0jWerNrwU8lm +PNSsAgHaJNM7qAJGr6Qc4/hzWHa39g6QDbXwz8z6+cZM5cOGMAqNF34168Xfuw6cwI2H44g4hWf6 +Pser4BOcBRiYz5P1sZK0/CPTz9XEJ0ngnjybCKOLXSoh4Pw5qlPafX7PGglTvF0FBM+hSo+LdoIN +ofjSxxR3W5A2B4GbPgb6Ul5jxaYA/qXpUhtStZI5cgMJYr2wYBZupt0lwgNm3fME0UDiTouG9G/l +g6AnhF4EwfWQvTA9xO+oabw4m6SkltFi2mnAAZauy8RRNOoMqv8hjlmPSlzkYZqn0ukqeI1RPToV +7qJZjqlc3sX5kCLliEVx3ZGZbHqfPT2YfF72vhZooF6uCyP8Wg+qInYtyaEQHeTTRCOQiJ/GKubX +9ZqzWB4vMIkIG1SitZgj7Ah3HJVdYdHLiZxfokqRmu8hqkkWCKi9YSgxyXSthfbZxbGL0eUQMk1f +iyA6PEkfM4VZDdvLCXVDaXP7a3F98N/ETH3Goy7IlXnLc6KOTk0k+17kBL5yG6YnLUlamXrXXAkg +t3+UuU/xDRxeiEIbEbfnkduebPRq34wGmAOtzCjvpUfzUwIDAQABo0IwQDAPBgNVHRMBAf8EBTAD +AQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUo5fW816iEOGrRZ88F2Q87gFwnMwwDQYJKoZI +hvcNAQELBQADggIBABj6W3X8PnrHX3fHyt/PX8MSxEBd1DKquGrX1RUVRpgjpeaQWxiZTOOtQqOC +MTaIzen7xASWSIsBx40Bz1szBpZGZnQdT+3Btrm0DWHMY37XLneMlhwqI2hrhVd2cDMT/uFPpiN3 +GPoajOi9ZcnPP/TJF9zrx7zABC4tRi9pZsMbj/7sPtPKlL92CiUNqXsCHKnQO18LwIE6PWThv6ct +Tr1NxNgpxiIY0MWscgKCP6o6ojoilzHdCGPDdRS5YCgtW2jgFqlmgiNR9etT2DGbe+m3nUvriBbP ++V04ikkwj+3x6xn0dxoxGE1nVGwvb2X52z3sIexe9PSLymBlVNFxZPT5pqOBMzYzcfCkeF9OrYMh +3jRJjehZrJ3ydlo28hP0r+AJx2EqbPfgna67hkooby7utHnNkDPDs3b69fBsnQGQ+p6Q9pxyz0fa +wx/kNSBT8lTR32GDpgLiJTjehTItXnOQUl1CxM49S+H5GYQd1aJQzEH7QRTDvdbJWqNjZgKAvQU6 +O0ec7AAmTPWIUb+oI38YB7AL7YsmoWTTYUrrXJ/es69nA7Mf3W1daWhpq1467HxpvMc7hU6eFbm0 +FU/DlXpY18ls6Wy58yljXrQs8C097Vpl4KlbQMJImYFtnh8GKjwStIsPm6Ik8KaN1nrgS7ZklmOV +hMJKzRwuJIczYOXD +-----END CERTIFICATE----- + +QuoVadis Root CA 2 G3 +===================== +-----BEGIN CERTIFICATE----- +MIIFYDCCA0igAwIBAgIURFc0JFuBiZs18s64KztbpybwdSgwDQYJKoZIhvcNAQELBQAwSDELMAkG +A1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxHjAcBgNVBAMTFVF1b1ZhZGlzIFJv +b3QgQ0EgMiBHMzAeFw0xMjAxMTIxODU5MzJaFw00MjAxMTIxODU5MzJaMEgxCzAJBgNVBAYTAkJN +MRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMR4wHAYDVQQDExVRdW9WYWRpcyBSb290IENBIDIg +RzMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQChriWyARjcV4g/Ruv5r+LrI3HimtFh +ZiFfqq8nUeVuGxbULX1QsFN3vXg6YOJkApt8hpvWGo6t/x8Vf9WVHhLL5hSEBMHfNrMWn4rjyduY +NM7YMxcoRvynyfDStNVNCXJJ+fKH46nafaF9a7I6JaltUkSs+L5u+9ymc5GQYaYDFCDy54ejiK2t +oIz/pgslUiXnFgHVy7g1gQyjO/Dh4fxaXc6AcW34Sas+O7q414AB+6XrW7PFXmAqMaCvN+ggOp+o +MiwMzAkd056OXbxMmO7FGmh77FOm6RQ1o9/NgJ8MSPsc9PG/Srj61YxxSscfrf5BmrODXfKEVu+l +V0POKa2Mq1W/xPtbAd0jIaFYAI7D0GoT7RPjEiuA3GfmlbLNHiJuKvhB1PLKFAeNilUSxmn1uIZo +L1NesNKqIcGY5jDjZ1XHm26sGahVpkUG0CM62+tlXSoREfA7T8pt9DTEceT/AFr2XK4jYIVz8eQQ +sSWu1ZK7E8EM4DnatDlXtas1qnIhO4M15zHfeiFuuDIIfR0ykRVKYnLP43ehvNURG3YBZwjgQQvD +6xVu+KQZ2aKrr+InUlYrAoosFCT5v0ICvybIxo/gbjh9Uy3l7ZizlWNof/k19N+IxWA1ksB8aRxh +lRbQ694Lrz4EEEVlWFA4r0jyWbYW8jwNkALGcC4BrTwV1wIDAQABo0IwQDAPBgNVHRMBAf8EBTAD +AQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQU7edvdlq/YOxJW8ald7tyFnGbxD0wDQYJKoZI +hvcNAQELBQADggIBAJHfgD9DCX5xwvfrs4iP4VGyvD11+ShdyLyZm3tdquXK4Qr36LLTn91nMX66 +AarHakE7kNQIXLJgapDwyM4DYvmL7ftuKtwGTTwpD4kWilhMSA/ohGHqPHKmd+RCroijQ1h5fq7K +pVMNqT1wvSAZYaRsOPxDMuHBR//47PERIjKWnML2W2mWeyAMQ0GaW/ZZGYjeVYg3UQt4XAoeo0L9 +x52ID8DyeAIkVJOviYeIyUqAHerQbj5hLja7NQ4nlv1mNDthcnPxFlxHBlRJAHpYErAK74X9sbgz +dWqTHBLmYF5vHX/JHyPLhGGfHoJE+V+tYlUkmlKY7VHnoX6XOuYvHxHaU4AshZ6rNRDbIl9qxV6X +U/IyAgkwo1jwDQHVcsaxfGl7w/U2Rcxhbl5MlMVerugOXou/983g7aEOGzPuVBj+D77vfoRrQ+Nw +mNtddbINWQeFFSM51vHfqSYP1kjHs6Yi9TM3WpVHn3u6GBVv/9YUZINJ0gpnIdsPNWNgKCLjsZWD +zYWm3S8P52dSbrsvhXz1SnPnxT7AvSESBT/8twNJAlvIJebiVDj1eYeMHVOyToV7BjjHLPj4sHKN +JeV3UvQDHEimUF+IIDBu8oJDqz2XhOdT+yHBTw8imoa4WSr2Rz0ZiC3oheGe7IUIarFsNMkd7Egr +O3jtZsSOeWmD3n+M +-----END CERTIFICATE----- + +QuoVadis Root CA 3 G3 +===================== +-----BEGIN CERTIFICATE----- +MIIFYDCCA0igAwIBAgIULvWbAiin23r/1aOp7r0DoM8Sah0wDQYJKoZIhvcNAQELBQAwSDELMAkG +A1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxHjAcBgNVBAMTFVF1b1ZhZGlzIFJv +b3QgQ0EgMyBHMzAeFw0xMjAxMTIyMDI2MzJaFw00MjAxMTIyMDI2MzJaMEgxCzAJBgNVBAYTAkJN +MRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMR4wHAYDVQQDExVRdW9WYWRpcyBSb290IENBIDMg +RzMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCzyw4QZ47qFJenMioKVjZ/aEzHs286 +IxSR/xl/pcqs7rN2nXrpixurazHb+gtTTK/FpRp5PIpM/6zfJd5O2YIyC0TeytuMrKNuFoM7pmRL +Mon7FhY4futD4tN0SsJiCnMK3UmzV9KwCoWdcTzeo8vAMvMBOSBDGzXRU7Ox7sWTaYI+FrUoRqHe +6okJ7UO4BUaKhvVZR74bbwEhELn9qdIoyhA5CcoTNs+cra1AdHkrAj80//ogaX3T7mH1urPnMNA3 +I4ZyYUUpSFlob3emLoG+B01vr87ERRORFHAGjx+f+IdpsQ7vw4kZ6+ocYfx6bIrc1gMLnia6Et3U +VDmrJqMz6nWB2i3ND0/kA9HvFZcba5DFApCTZgIhsUfei5pKgLlVj7WiL8DWM2fafsSntARE60f7 +5li59wzweyuxwHApw0BiLTtIadwjPEjrewl5qW3aqDCYz4ByA4imW0aucnl8CAMhZa634RylsSqi +Md5mBPfAdOhx3v89WcyWJhKLhZVXGqtrdQtEPREoPHtht+KPZ0/l7DxMYIBpVzgeAVuNVejH38DM +dyM0SXV89pgR6y3e7UEuFAUCf+D+IOs15xGsIs5XPd7JMG0QA4XN8f+MFrXBsj6IbGB/kE+V9/Yt +rQE5BwT6dYB9v0lQ7e/JxHwc64B+27bQ3RP+ydOc17KXqQIDAQABo0IwQDAPBgNVHRMBAf8EBTAD +AQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUxhfQvKjqAkPyGwaZXSuQILnXnOQwDQYJKoZI +hvcNAQELBQADggIBADRh2Va1EodVTd2jNTFGu6QHcrxfYWLopfsLN7E8trP6KZ1/AvWkyaiTt3px +KGmPc+FSkNrVvjrlt3ZqVoAh313m6Tqe5T72omnHKgqwGEfcIHB9UqM+WXzBusnIFUBhynLWcKzS +t/Ac5IYp8M7vaGPQtSCKFWGafoaYtMnCdvvMujAWzKNhxnQT5WvvoxXqA/4Ti2Tk08HS6IT7SdEQ +TXlm66r99I0xHnAUrdzeZxNMgRVhvLfZkXdxGYFgu/BYpbWcC/ePIlUnwEsBbTuZDdQdm2NnL9Du +DcpmvJRPpq3t/O5jrFc/ZSXPsoaP0Aj/uHYUbt7lJ+yreLVTubY/6CD50qi+YUbKh4yE8/nxoGib +Ih6BJpsQBJFxwAYf3KDTuVan45gtf4Od34wrnDKOMpTwATwiKp9Dwi7DmDkHOHv8XgBCH/MyJnmD +hPbl8MFREsALHgQjDFSlTC9JxUrRtm5gDWv8a4uFJGS3iQ6rJUdbPM9+Sb3H6QrG2vd+DhcI00iX +0HGS8A85PjRqHH3Y8iKuu2n0M7SmSFXRDw4m6Oy2Cy2nhTXN/VnIn9HNPlopNLk9hM6xZdRZkZFW +dSHBd575euFgndOtBBj0fOtek49TSiIp+EgrPk2GrFt/ywaZWWDYWGWVjUTR939+J399roD1B0y2 +PpxxVJkES/1Y+Zj0 +-----END CERTIFICATE----- + +DigiCert Assured ID Root G2 +=========================== +-----BEGIN CERTIFICATE----- +MIIDljCCAn6gAwIBAgIQC5McOtY5Z+pnI7/Dr5r0SzANBgkqhkiG9w0BAQsFADBlMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQw +IgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgRzIwHhcNMTMwODAxMTIwMDAwWhcNMzgw +MTE1MTIwMDAwWjBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQL +ExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgRzIw +ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDZ5ygvUj82ckmIkzTz+GoeMVSAn61UQbVH +35ao1K+ALbkKz3X9iaV9JPrjIgwrvJUXCzO/GU1BBpAAvQxNEP4HteccbiJVMWWXvdMX0h5i89vq +bFCMP4QMls+3ywPgym2hFEwbid3tALBSfK+RbLE4E9HpEgjAALAcKxHad3A2m67OeYfcgnDmCXRw +VWmvo2ifv922ebPynXApVfSr/5Vh88lAbx3RvpO704gqu52/clpWcTs/1PPRCv4o76Pu2ZmvA9OP +YLfykqGxvYmJHzDNw6YuYjOuFgJ3RFrngQo8p0Quebg/BLxcoIfhG69Rjs3sLPr4/m3wOnyqi+Rn +lTGNAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBTO +w0q5mVXyuNtgv6l+vVa1lzan1jANBgkqhkiG9w0BAQsFAAOCAQEAyqVVjOPIQW5pJ6d1Ee88hjZv +0p3GeDgdaZaikmkuOGybfQTUiaWxMTeKySHMq2zNixya1r9I0jJmwYrA8y8678Dj1JGG0VDjA9tz +d29KOVPt3ibHtX2vK0LRdWLjSisCx1BL4GnilmwORGYQRI+tBev4eaymG+g3NJ1TyWGqolKvSnAW +hsI6yLETcDbYz+70CjTVW0z9B5yiutkBclzzTcHdDrEcDcRjvq30FPuJ7KJBDkzMyFdA0G4Dqs0M +jomZmWzwPDCvON9vvKO+KSAnq3T/EyJ43pdSVR6DtVQgA+6uwE9W3jfMw3+qBCe703e4YtsXfJwo +IhNzbM8m9Yop5w== +-----END CERTIFICATE----- + +DigiCert Assured ID Root G3 +=========================== +-----BEGIN CERTIFICATE----- +MIICRjCCAc2gAwIBAgIQC6Fa+h3foLVJRK/NJKBs7DAKBggqhkjOPQQDAzBlMQswCQYDVQQGEwJV +UzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYD +VQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgRzMwHhcNMTMwODAxMTIwMDAwWhcNMzgwMTE1 +MTIwMDAwWjBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgRzMwdjAQ +BgcqhkjOPQIBBgUrgQQAIgNiAAQZ57ysRGXtzbg/WPuNsVepRC0FFfLvC/8QdJ+1YlJfZn4f5dwb +RXkLzMZTCp2NXQLZqVneAlr2lSoOjThKiknGvMYDOAdfVdp+CW7if17QRSAPWXYQ1qAk8C3eNvJs +KTmjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBTL0L2p4ZgF +UaFNN6KDec6NHSrkhDAKBggqhkjOPQQDAwNnADBkAjAlpIFFAmsSS3V0T8gj43DydXLefInwz5Fy +YZ5eEJJZVrmDxxDnOOlYJjZ91eQ0hjkCMHw2U/Aw5WJjOpnitqM7mzT6HtoQknFekROn3aRukswy +1vUhZscv6pZjamVFkpUBtA== +-----END CERTIFICATE----- + +DigiCert Global Root G2 +======================= +-----BEGIN CERTIFICATE----- +MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSAw +HgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBHMjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUx +MjAwMDBaMGExCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3 +dy5kaWdpY2VydC5jb20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkq +hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI2/Ou8jqJ +kTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx1x7e/dfgy5SDN67sH0NO +3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQq2EGnI/yuum06ZIya7XzV+hdG82MHauV +BJVJ8zUtluNJbd134/tJS7SsVQepj5WztCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyM +UNGPHgm+F6HmIcr9g+UQvIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQAB +o0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV5uNu +5g/6+rkS7QYXjzkwDQYJKoZIhvcNAQELBQADggEBAGBnKJRvDkhj6zHd6mcY1Yl9PMWLSn/pvtsr +F9+wX3N3KjITOYFnQoQj8kVnNeyIv/iPsGEMNKSuIEyExtv4NeF22d+mQrvHRAiGfzZ0JFrabA0U +WTW98kndth/Jsw1HKj2ZL7tcu7XUIOGZX1NGFdtom/DzMNU+MeKNhJ7jitralj41E6Vf8PlwUHBH +QRFXGU7Aj64GxJUTFy8bJZ918rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/ +iyK5S9kJRaTepLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl +MrY= +-----END CERTIFICATE----- + +DigiCert Global Root G3 +======================= +-----BEGIN CERTIFICATE----- +MIICPzCCAcWgAwIBAgIQBVVWvPJepDU1w6QP1atFcjAKBggqhkjOPQQDAzBhMQswCQYDVQQGEwJV +UzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSAwHgYD +VQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBHMzAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAw +MDBaMGExCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5k +aWdpY2VydC5jb20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEczMHYwEAYHKoZIzj0C +AQYFK4EEACIDYgAE3afZu4q4C/sLfyHS8L6+c/MzXRq8NOrexpu80JX28MzQC7phW1FGfp4tn+6O +YwwX7Adw9c+ELkCDnOg/QW07rdOkFFk2eJ0DQ+4QE2xy3q6Ip6FrtUPOZ9wj/wMco+I+o0IwQDAP +BgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUs9tIpPmhxdiuNkHMEWNp +Yim8S8YwCgYIKoZIzj0EAwMDaAAwZQIxAK288mw/EkrRLTnDCgmXc/SINoyIJ7vmiI1Qhadj+Z4y +3maTD/HMsQmP3Wyr+mt/oAIwOWZbwmSNuJ5Q3KjVSaLtx9zRSX8XAbjIho9OjIgrqJqpisXRAL34 +VOKa5Vt8sycX +-----END CERTIFICATE----- + +DigiCert Trusted Root G4 +======================== +-----BEGIN CERTIFICATE----- +MIIFkDCCA3igAwIBAgIQBZsbV56OITLiOQe9p3d1XDANBgkqhkiG9w0BAQwFADBiMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSEw +HwYDVQQDExhEaWdpQ2VydCBUcnVzdGVkIFJvb3QgRzQwHhcNMTMwODAxMTIwMDAwWhcNMzgwMTE1 +MTIwMDAwWjBiMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSEwHwYDVQQDExhEaWdpQ2VydCBUcnVzdGVkIFJvb3QgRzQwggIiMA0G +CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC/5pBzaN675F1KPDAiMGkz7MKnJS7JIT3yithZwuEp +pz1Yq3aaza57G4QNxDAf8xukOBbrVsaXbR2rsnnyyhHS5F/WBTxSD1Ifxp4VpX6+n6lXFllVcq9o +k3DCsrp1mWpzMpTREEQQLt+C8weE5nQ7bXHiLQwb7iDVySAdYyktzuxeTsiT+CFhmzTrBcZe7Fsa +vOvJz82sNEBfsXpm7nfISKhmV1efVFiODCu3T6cw2Vbuyntd463JT17lNecxy9qTXtyOj4DatpGY +QJB5w3jHtrHEtWoYOAMQjdjUN6QuBX2I9YI+EJFwq1WCQTLX2wRzKm6RAXwhTNS8rhsDdV14Ztk6 +MUSaM0C/CNdaSaTC5qmgZ92kJ7yhTzm1EVgX9yRcRo9k98FpiHaYdj1ZXUJ2h4mXaXpI8OCiEhtm +mnTK3kse5w5jrubU75KSOp493ADkRSWJtppEGSt+wJS00mFt6zPZxd9LBADMfRyVw4/3IbKyEbe7 +f/LVjHAsQWCqsWMYRJUadmJ+9oCw++hkpjPRiQfhvbfmQ6QYuKZ3AeEPlAwhHbJUKSWJbOUOUlFH +dL4mrLZBdd56rF+NP8m800ERElvlEFDrMcXKchYiCd98THU/Y+whX8QgUWtvsauGi0/C1kVfnSD8 +oR7FwI+isX4KJpn15GkvmB0t9dmpsh3lGwIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1Ud +DwEB/wQEAwIBhjAdBgNVHQ4EFgQU7NfjgtJxXWRM3y5nP+e6mK4cD08wDQYJKoZIhvcNAQEMBQAD +ggIBALth2X2pbL4XxJEbw6GiAI3jZGgPVs93rnD5/ZpKmbnJeFwMDF/k5hQpVgs2SV1EY+CtnJYY +ZhsjDT156W1r1lT40jzBQ0CuHVD1UvyQO7uYmWlrx8GnqGikJ9yd+SeuMIW59mdNOj6PWTkiU0Tr +yF0Dyu1Qen1iIQqAyHNm0aAFYF/opbSnr6j3bTWcfFqK1qI4mfN4i/RN0iAL3gTujJtHgXINwBQy +7zBZLq7gcfJW5GqXb5JQbZaNaHqasjYUegbyJLkJEVDXCLG4iXqEI2FCKeWjzaIgQdfRnGTZ6iah +ixTXTBmyUEFxPT9NcCOGDErcgdLMMpSEDQgJlxxPwO5rIHQw0uA5NBCFIRUBCOhVMt5xSdkoF1BN +5r5N0XWs0Mr7QbhDparTwwVETyw2m+L64kW4I1NsBm9nVX9GtUw/bihaeSbSpKhil9Ie4u1Ki7wb +/UdKDd9nZn6yW0HQO+T0O/QEY+nvwlQAUaCKKsnOeMzV6ocEGLPOr0mIr/OSmbaz5mEP0oUA51Aa +5BuVnRmhuZyxm7EAHu/QD09CbMkKvO5D+jpxpchNJqU1/YldvIViHTLSoCtU7ZpXwdv6EM8Zt4tK +G48BtieVU+i2iW1bvGjUI+iLUaJW+fCmgKDWHrO8Dw9TdSmq6hN35N6MgSGtBxBHEa2HPQfRdbzP +82Z+ +-----END CERTIFICATE----- + +COMODO RSA Certification Authority +================================== +-----BEGIN CERTIFICATE----- +MIIF2DCCA8CgAwIBAgIQTKr5yttjb+Af907YWwOGnTANBgkqhkiG9w0BAQwFADCBhTELMAkGA1UE +BhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgG +A1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNhdGlv +biBBdXRob3JpdHkwHhcNMTAwMTE5MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBhTELMAkGA1UEBhMC +R0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UE +ChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNhdGlvbiBB +dXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCR6FSS0gpWsawNJN3Fz0Rn +dJkrN6N9I3AAcbxT38T6KhKPS38QVr2fcHK3YX/JSw8Xpz3jsARh7v8Rl8f0hj4K+j5c+ZPmNHrZ +FGvnnLOFoIJ6dq9xkNfs/Q36nGz637CC9BR++b7Epi9Pf5l/tfxnQ3K9DADWietrLNPtj5gcFKt+ +5eNu/Nio5JIk2kNrYrhV/erBvGy2i/MOjZrkm2xpmfh4SDBF1a3hDTxFYPwyllEnvGfDyi62a+pG +x8cgoLEfZd5ICLqkTqnyg0Y3hOvozIFIQ2dOciqbXL1MGyiKXCJ7tKuY2e7gUYPDCUZObT6Z+pUX +2nwzV0E8jVHtC7ZcryxjGt9XyD+86V3Em69FmeKjWiS0uqlWPc9vqv9JWL7wqP/0uK3pN/u6uPQL +OvnoQ0IeidiEyxPx2bvhiWC4jChWrBQdnArncevPDt09qZahSL0896+1DSJMwBGB7FY79tOi4lu3 +sgQiUpWAk2nojkxl8ZEDLXB0AuqLZxUpaVICu9ffUGpVRr+goyhhf3DQw6KqLCGqR84onAZFdr+C +GCe01a60y1Dma/RMhnEw6abfFobg2P9A3fvQQoh/ozM6LlweQRGBY84YcWsr7KaKtzFcOmpH4MN5 +WdYgGq/yapiqcrxXStJLnbsQ/LBMQeXtHT1eKJ2czL+zUdqnR+WEUwIDAQABo0IwQDAdBgNVHQ4E +FgQUu69+Aj36pvE8hI6t7jiY7NkyMtQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8w +DQYJKoZIhvcNAQEMBQADggIBAArx1UaEt65Ru2yyTUEUAJNMnMvlwFTPoCWOAvn9sKIN9SCYPBMt +rFaisNZ+EZLpLrqeLppysb0ZRGxhNaKatBYSaVqM4dc+pBroLwP0rmEdEBsqpIt6xf4FpuHA1sj+ +nq6PK7o9mfjYcwlYRm6mnPTXJ9OV2jeDchzTc+CiR5kDOF3VSXkAKRzH7JsgHAckaVd4sjn8OoSg +tZx8jb8uk2IntznaFxiuvTwJaP+EmzzV1gsD41eeFPfR60/IvYcjt7ZJQ3mFXLrrkguhxuhoqEwW +sRqZCuhTLJK7oQkYdQxlqHvLI7cawiiFwxv/0Cti76R7CZGYZ4wUAc1oBmpjIXUDgIiKboHGhfKp +pC3n9KUkEEeDys30jXlYsQab5xoq2Z0B15R97QNKyvDb6KkBPvVWmckejkk9u+UJueBPSZI9FoJA +zMxZxuY67RIuaTxslbH9qh17f4a+Hg4yRvv7E491f0yLS0Zj/gA0QHDBw7mh3aZw4gSzQbzpgJHq +ZJx64SIDqZxubw5lT2yHh17zbqD5daWbQOhTsiedSrnAdyGN/4fy3ryM7xfft0kL0fJuMAsaDk52 +7RH89elWsn2/x20Kk4yl0MC2Hb46TpSi125sC8KKfPog88Tk5c0NqMuRkrF8hey1FGlmDoLnzc7I +LaZRfyHBNVOFBkpdn627G190 +-----END CERTIFICATE----- + +USERTrust RSA Certification Authority +===================================== +-----BEGIN CERTIFICATE----- +MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCBiDELMAkGA1UE +BhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQK +ExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNh +dGlvbiBBdXRob3JpdHkwHhcNMTAwMjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UE +BhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQK +ExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNh +dGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCAEmUXNg7D2wiz +0KxXDXbtzSfTTK1Qg2HiqiBNCS1kCdzOiZ/MPans9s/B3PHTsdZ7NygRK0faOca8Ohm0X6a9fZ2j +Y0K2dvKpOyuR+OJv0OwWIJAJPuLodMkYtJHUYmTbf6MG8YgYapAiPLz+E/CHFHv25B+O1ORRxhFn +RghRy4YUVD+8M/5+bJz/Fp0YvVGONaanZshyZ9shZrHUm3gDwFA66Mzw3LyeTP6vBZY1H1dat//O ++T23LLb2VN3I5xI6Ta5MirdcmrS3ID3KfyI0rn47aGYBROcBTkZTmzNg95S+UzeQc0PzMsNT79uq +/nROacdrjGCT3sTHDN/hMq7MkztReJVni+49Vv4M0GkPGw/zJSZrM233bkf6c0Plfg6lZrEpfDKE +Y1WJxA3Bk1QwGROs0303p+tdOmw1XNtB1xLaqUkL39iAigmTYo61Zs8liM2EuLE/pDkP2QKe6xJM +lXzzawWpXhaDzLhn4ugTncxbgtNMs+1b/97lc6wjOy0AvzVVdAlJ2ElYGn+SNuZRkg7zJn0cTRe8 +yexDJtC/QV9AqURE9JnnV4eeUB9XVKg+/XRjL7FQZQnmWEIuQxpMtPAlR1n6BB6T1CZGSlCBst6+ +eLf8ZxXhyVeEHg9j1uliutZfVS7qXMYoCAQlObgOK6nyTJccBz8NUvXt7y+CDwIDAQABo0IwQDAd +BgNVHQ4EFgQUU3m/WqorSs9UgOHYm8Cd8rIDZsswDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQF +MAMBAf8wDQYJKoZIhvcNAQEMBQADggIBAFzUfA3P9wF9QZllDHPFUp/L+M+ZBn8b2kMVn54CVVeW +FPFSPCeHlCjtHzoBN6J2/FNQwISbxmtOuowhT6KOVWKR82kV2LyI48SqC/3vqOlLVSoGIG1VeCkZ +7l8wXEskEVX/JJpuXior7gtNn3/3ATiUFJVDBwn7YKnuHKsSjKCaXqeYalltiz8I+8jRRa8YFWSQ +Eg9zKC7F4iRO/Fjs8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM +8WcRiQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYzeSf7dNXGi +FSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZXHlKYC6SQK5MNyosycdi +yA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9c +J2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRBVXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGw +sAvgnEzDHNb842m1R0aBL6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gx +Q+6IHdfGjjxDah2nGN59PRbxYvnKkKj9 +-----END CERTIFICATE----- + +USERTrust ECC Certification Authority +===================================== +-----BEGIN CERTIFICATE----- +MIICjzCCAhWgAwIBAgIQXIuZxVqUxdJxVt7NiYDMJjAKBggqhkjOPQQDAzCBiDELMAkGA1UEBhMC +VVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQKExVU +aGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBFQ0MgQ2VydGlmaWNhdGlv +biBBdXRob3JpdHkwHhcNMTAwMjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UEBhMC +VVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQKExVU +aGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBFQ0MgQ2VydGlmaWNhdGlv +biBBdXRob3JpdHkwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQarFRaqfloI+d61SRvU8Za2EurxtW2 +0eZzca7dnNYMYf3boIkDuAUU7FfO7l0/4iGzzvfUinngo4N+LZfQYcTxmdwlkWOrfzCjtHDix6Ez +nPO/LlxTsV+zfTJ/ijTjeXmjQjBAMB0GA1UdDgQWBBQ64QmG1M8ZwpZ2dEl23OA1xmNjmjAOBgNV +HQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjA2Z6EWCNzklwBB +HU6+4WMBzzuqQhFkoJ2UOQIReVx7Hfpkue4WQrO/isIJxOzksU0CMQDpKmFHjFJKS04YcPbWRNZu +9YO6bVi9JNlWSOrvxKJGgYhqOkbRqZtNyWHa0V1Xahg= +-----END CERTIFICATE----- + +GlobalSign ECC Root CA - R4 +=========================== +-----BEGIN CERTIFICATE----- +MIIB4TCCAYegAwIBAgIRKjikHJYKBN5CsiilC+g0mAIwCgYIKoZIzj0EAwIwUDEkMCIGA1UECxMb +R2xvYmFsU2lnbiBFQ0MgUm9vdCBDQSAtIFI0MRMwEQYDVQQKEwpHbG9iYWxTaWduMRMwEQYDVQQD +EwpHbG9iYWxTaWduMB4XDTEyMTExMzAwMDAwMFoXDTM4MDExOTAzMTQwN1owUDEkMCIGA1UECxMb +R2xvYmFsU2lnbiBFQ0MgUm9vdCBDQSAtIFI0MRMwEQYDVQQKEwpHbG9iYWxTaWduMRMwEQYDVQQD +EwpHbG9iYWxTaWduMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEuMZ5049sJQ6fLjkZHAOkrprl +OQcJFspjsbmG+IpXwVfOQvpzofdlQv8ewQCybnMO/8ch5RikqtlxP6jUuc6MHaNCMEAwDgYDVR0P +AQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFFSwe61FuOJAf/sKbvu+M8k8o4TV +MAoGCCqGSM49BAMCA0gAMEUCIQDckqGgE6bPA7DmxCGXkPoUVy0D7O48027KqGx2vKLeuwIgJ6iF +JzWbVsaj8kfSt24bAgAXqmemFZHe+pTsewv4n4Q= +-----END CERTIFICATE----- + +GlobalSign ECC Root CA - R5 +=========================== +-----BEGIN CERTIFICATE----- +MIICHjCCAaSgAwIBAgIRYFlJ4CYuu1X5CneKcflK2GwwCgYIKoZIzj0EAwMwUDEkMCIGA1UECxMb +R2xvYmFsU2lnbiBFQ0MgUm9vdCBDQSAtIFI1MRMwEQYDVQQKEwpHbG9iYWxTaWduMRMwEQYDVQQD +EwpHbG9iYWxTaWduMB4XDTEyMTExMzAwMDAwMFoXDTM4MDExOTAzMTQwN1owUDEkMCIGA1UECxMb +R2xvYmFsU2lnbiBFQ0MgUm9vdCBDQSAtIFI1MRMwEQYDVQQKEwpHbG9iYWxTaWduMRMwEQYDVQQD +EwpHbG9iYWxTaWduMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAER0UOlvt9Xb/pOdEh+J8LttV7HpI6 +SFkc8GIxLcB6KP4ap1yztsyX50XUWPrRd21DosCHZTQKH3rd6zwzocWdTaRvQZU4f8kehOvRnkmS +h5SHDDqFSmafnVmTTZdhBoZKo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAd +BgNVHQ4EFgQUPeYpSJvqB8ohREom3m7e0oPQn1kwCgYIKoZIzj0EAwMDaAAwZQIxAOVpEslu28Yx +uglB4Zf4+/2a4n0Sye18ZNPLBSWLVtmg515dTguDnFt2KaAJJiFqYgIwcdK1j1zqO+F4CYWodZI7 +yFz9SO8NdCKoCOJuxUnOxwy8p2Fp8fc74SrL+SvzZpA3 +-----END CERTIFICATE----- + +Staat der Nederlanden EV Root CA +================================ +-----BEGIN CERTIFICATE----- +MIIFcDCCA1igAwIBAgIEAJiWjTANBgkqhkiG9w0BAQsFADBYMQswCQYDVQQGEwJOTDEeMBwGA1UE +CgwVU3RhYXQgZGVyIE5lZGVybGFuZGVuMSkwJwYDVQQDDCBTdGFhdCBkZXIgTmVkZXJsYW5kZW4g +RVYgUm9vdCBDQTAeFw0xMDEyMDgxMTE5MjlaFw0yMjEyMDgxMTEwMjhaMFgxCzAJBgNVBAYTAk5M +MR4wHAYDVQQKDBVTdGFhdCBkZXIgTmVkZXJsYW5kZW4xKTAnBgNVBAMMIFN0YWF0IGRlciBOZWRl +cmxhbmRlbiBFViBSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA48d+ifkk +SzrSM4M1LGns3Amk41GoJSt5uAg94JG6hIXGhaTK5skuU6TJJB79VWZxXSzFYGgEt9nCUiY4iKTW +O0Cmws0/zZiTs1QUWJZV1VD+hq2kY39ch/aO5ieSZxeSAgMs3NZmdO3dZ//BYY1jTw+bbRcwJu+r +0h8QoPnFfxZpgQNH7R5ojXKhTbImxrpsX23Wr9GxE46prfNeaXUmGD5BKyF/7otdBwadQ8QpCiv8 +Kj6GyzyDOvnJDdrFmeK8eEEzduG/L13lpJhQDBXd4Pqcfzho0LKmeqfRMb1+ilgnQ7O6M5HTp5gV +XJrm0w912fxBmJc+qiXbj5IusHsMX/FjqTf5m3VpTCgmJdrV8hJwRVXj33NeN/UhbJCONVrJ0yPr +08C+eKxCKFhmpUZtcALXEPlLVPxdhkqHz3/KRawRWrUgUY0viEeXOcDPusBCAUCZSCELa6fS/ZbV +0b5GnUngC6agIk440ME8MLxwjyx1zNDFjFE7PZQIZCZhfbnDZY8UnCHQqv0XcgOPvZuM5l5Tnrmd +74K74bzickFbIZTTRTeU0d8JOV3nI6qaHcptqAqGhYqCvkIH1vI4gnPah1vlPNOePqc7nvQDs/nx +fRN0Av+7oeX6AHkcpmZBiFxgV6YuCcS6/ZrPpx9Aw7vMWgpVSzs4dlG4Y4uElBbmVvMCAwEAAaNC +MEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFP6rAJCYniT8qcwa +ivsnuL8wbqg7MA0GCSqGSIb3DQEBCwUAA4ICAQDPdyxuVr5Os7aEAJSrR8kN0nbHhp8dB9O2tLsI +eK9p0gtJ3jPFrK3CiAJ9Brc1AsFgyb/E6JTe1NOpEyVa/m6irn0F3H3zbPB+po3u2dfOWBfoqSmu +c0iH55vKbimhZF8ZE/euBhD/UcabTVUlT5OZEAFTdfETzsemQUHSv4ilf0X8rLiltTMMgsT7B/Zq +5SWEXwbKwYY5EdtYzXc7LMJMD16a4/CrPmEbUCTCwPTxGfARKbalGAKb12NMcIxHowNDXLldRqAN +b/9Zjr7dn3LDWyvfjFvO5QxGbJKyCqNMVEIYFRIYvdr8unRu/8G2oGTYqV9Vrp9canaW2HNnh/tN +f1zuacpzEPuKqf2evTY4SUmH9A4U8OmHuD+nT3pajnnUk+S7aFKErGzp85hwVXIy+TSrK0m1zSBi +5Dp6Z2Orltxtrpfs/J92VoguZs9btsmksNcFuuEnL5O7Jiqik7Ab846+HUCjuTaPPoIaGl6I6lD4 +WeKDRikL40Rc4ZW2aZCaFG+XroHPaO+Zmr615+F/+PoTRxZMzG0IQOeLeG9QgkRQP2YGiqtDhFZK +DyAthg710tvSeopLzaXoTvFeJiUBWSOgftL2fiFX1ye8FVdMpEbB4IMeDExNH08GGeL5qPQ6gqGy +eUN51q1veieQA6TqJIc/2b3Z6fJfUEkc7uzXLg== +-----END CERTIFICATE----- + +IdenTrust Commercial Root CA 1 +============================== +-----BEGIN CERTIFICATE----- +MIIFYDCCA0igAwIBAgIQCgFCgAAAAUUjyES1AAAAAjANBgkqhkiG9w0BAQsFADBKMQswCQYDVQQG +EwJVUzESMBAGA1UEChMJSWRlblRydXN0MScwJQYDVQQDEx5JZGVuVHJ1c3QgQ29tbWVyY2lhbCBS +b290IENBIDEwHhcNMTQwMTE2MTgxMjIzWhcNMzQwMTE2MTgxMjIzWjBKMQswCQYDVQQGEwJVUzES +MBAGA1UEChMJSWRlblRydXN0MScwJQYDVQQDEx5JZGVuVHJ1c3QgQ29tbWVyY2lhbCBSb290IENB +IDEwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCnUBneP5k91DNG8W9RYYKyqU+PZ4ld +hNlT3Qwo2dfw/66VQ3KZ+bVdfIrBQuExUHTRgQ18zZshq0PirK1ehm7zCYofWjK9ouuU+ehcCuz/ +mNKvcbO0U59Oh++SvL3sTzIwiEsXXlfEU8L2ApeN2WIrvyQfYo3fw7gpS0l4PJNgiCL8mdo2yMKi +1CxUAGc1bnO/AljwpN3lsKImesrgNqUZFvX9t++uP0D1bVoE/c40yiTcdCMbXTMTEl3EASX2MN0C +XZ/g1Ue9tOsbobtJSdifWwLziuQkkORiT0/Br4sOdBeo0XKIanoBScy0RnnGF7HamB4HWfp1IYVl +3ZBWzvurpWCdxJ35UrCLvYf5jysjCiN2O/cz4ckA82n5S6LgTrx+kzmEB/dEcH7+B1rlsazRGMzy +NeVJSQjKVsk9+w8YfYs7wRPCTY/JTw436R+hDmrfYi7LNQZReSzIJTj0+kuniVyc0uMNOYZKdHzV +WYfCP04MXFL0PfdSgvHqo6z9STQaKPNBiDoT7uje/5kdX7rL6B7yuVBgwDHTc+XvvqDtMwt0viAg +xGds8AgDelWAf0ZOlqf0Hj7h9tgJ4TNkK2PXMl6f+cB7D3hvl7yTmvmcEpB4eoCHFddydJxVdHix +uuFucAS6T6C6aMN7/zHwcz09lCqxC0EOoP5NiGVreTO01wIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC +AQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU7UQZwNPwBovupHu+QucmVMiONnYwDQYJKoZI +hvcNAQELBQADggIBAA2ukDL2pkt8RHYZYR4nKM1eVO8lvOMIkPkp165oCOGUAFjvLi5+U1KMtlwH +6oi6mYtQlNeCgN9hCQCTrQ0U5s7B8jeUeLBfnLOic7iPBZM4zY0+sLj7wM+x8uwtLRvM7Kqas6pg +ghstO8OEPVeKlh6cdbjTMM1gCIOQ045U8U1mwF10A0Cj7oV+wh93nAbowacYXVKV7cndJZ5t+qnt +ozo00Fl72u1Q8zW/7esUTTHHYPTa8Yec4kjixsU3+wYQ+nVZZjFHKdp2mhzpgq7vmrlR94gjmmmV +YjzlVYA211QC//G5Xc7UI2/YRYRKW2XviQzdFKcgyxilJbQN+QHwotL0AMh0jqEqSI5l2xPE4iUX +feu+h1sXIFRRk0pTAwvsXcoz7WL9RccvW9xYoIA55vrX/hMUpu09lEpCdNTDd1lzzY9GvlU47/ro +kTLql1gEIt44w8y8bckzOmoKaT+gyOpyj4xjhiO9bTyWnpXgSUyqorkqG5w2gXjtw+hG4iZZRHUe +2XWJUc0QhJ1hYMtd+ZciTY6Y5uN/9lu7rs3KSoFrXgvzUeF0K+l+J6fZmUlO+KWA2yUPHGNiiskz +Z2s8EIPGrd6ozRaOjfAHN3Gf8qv8QfXBi+wAN10J5U6A7/qxXDgGpRtK4dw4LTzcqx+QGtVKnO7R +cGzM7vRX+Bi6hG6H +-----END CERTIFICATE----- + +IdenTrust Public Sector Root CA 1 +================================= +-----BEGIN CERTIFICATE----- +MIIFZjCCA06gAwIBAgIQCgFCgAAAAUUjz0Z8AAAAAjANBgkqhkiG9w0BAQsFADBNMQswCQYDVQQG +EwJVUzESMBAGA1UEChMJSWRlblRydXN0MSowKAYDVQQDEyFJZGVuVHJ1c3QgUHVibGljIFNlY3Rv +ciBSb290IENBIDEwHhcNMTQwMTE2MTc1MzMyWhcNMzQwMTE2MTc1MzMyWjBNMQswCQYDVQQGEwJV +UzESMBAGA1UEChMJSWRlblRydXN0MSowKAYDVQQDEyFJZGVuVHJ1c3QgUHVibGljIFNlY3RvciBS +b290IENBIDEwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC2IpT8pEiv6EdrCvsnduTy +P4o7ekosMSqMjbCpwzFrqHd2hCa2rIFCDQjrVVi7evi8ZX3yoG2LqEfpYnYeEe4IFNGyRBb06tD6 +Hi9e28tzQa68ALBKK0CyrOE7S8ItneShm+waOh7wCLPQ5CQ1B5+ctMlSbdsHyo+1W/CD80/HLaXI +rcuVIKQxKFdYWuSNG5qrng0M8gozOSI5Cpcu81N3uURF/YTLNiCBWS2ab21ISGHKTN9T0a9SvESf +qy9rg3LvdYDaBjMbXcjaY8ZNzaxmMc3R3j6HEDbhuaR672BQssvKplbgN6+rNBM5Jeg5ZuSYeqoS +mJxZZoY+rfGwyj4GD3vwEUs3oERte8uojHH01bWRNszwFcYr3lEXsZdMUD2xlVl8BX0tIdUAvwFn +ol57plzy9yLxkA2T26pEUWbMfXYD62qoKjgZl3YNa4ph+bz27nb9cCvdKTz4Ch5bQhyLVi9VGxyh +LrXHFub4qjySjmm2AcG1hp2JDws4lFTo6tyePSW8Uybt1as5qsVATFSrsrTZ2fjXctscvG29ZV/v +iDUqZi/u9rNl8DONfJhBaUYPQxxp+pu10GFqzcpL2UyQRqsVWaFHVCkugyhfHMKiq3IXAAaOReyL +4jM9f9oZRORicsPfIsbyVtTdX5Vy7W1f90gDW/3FKqD2cyOEEBsB5wIDAQABo0IwQDAOBgNVHQ8B +Af8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU43HgntinQtnbcZFrlJPrw6PRFKMw +DQYJKoZIhvcNAQELBQADggIBAEf63QqwEZE4rU1d9+UOl1QZgkiHVIyqZJnYWv6IAcVYpZmxI1Qj +t2odIFflAWJBF9MJ23XLblSQdf4an4EKwt3X9wnQW3IV5B4Jaj0z8yGa5hV+rVHVDRDtfULAj+7A +mgjVQdZcDiFpboBhDhXAuM/FSRJSzL46zNQuOAXeNf0fb7iAaJg9TaDKQGXSc3z1i9kKlT/YPyNt +GtEqJBnZhbMX73huqVjRI9PHE+1yJX9dsXNw0H8GlwmEKYBhHfpe/3OsoOOJuBxxFcbeMX8S3OFt +m6/n6J91eEyrRjuazr8FGF1NFTwWmhlQBJqymm9li1JfPFgEKCXAZmExfrngdbkaqIHWchezxQMx +NRF4eKLg6TCMf4DfWN88uieW4oA0beOY02QnrEh+KHdcxiVhJfiFDGX6xDIvpZgF5PgLZxYWxoK4 +Mhn5+bl53B/N66+rDt0b20XkeucC4pVd/GnwU2lhlXV5C15V5jgclKlZM57IcXR5f1GJtshquDDI +ajjDbp7hNxbqBWJMWxJH7ae0s1hWx0nzfxJoCTFx8G34Tkf71oXuxVhAGaQdp/lLQzfcaFpPz+vC +ZHTetBXZ9FRUGi8c15dxVJCO2SCdUyt/q4/i6jC8UDfv8Ue1fXwsBOxonbRJRBD0ckscZOf85muQ +3Wl9af0AVqW3rLatt8o+Ae+c +-----END CERTIFICATE----- + +Entrust Root Certification Authority - G2 +========================================= +-----BEGIN CERTIFICATE----- +MIIEPjCCAyagAwIBAgIESlOMKDANBgkqhkiG9w0BAQsFADCBvjELMAkGA1UEBhMCVVMxFjAUBgNV +BAoTDUVudHJ1c3QsIEluYy4xKDAmBgNVBAsTH1NlZSB3d3cuZW50cnVzdC5uZXQvbGVnYWwtdGVy +bXMxOTA3BgNVBAsTMChjKSAyMDA5IEVudHJ1c3QsIEluYy4gLSBmb3IgYXV0aG9yaXplZCB1c2Ug +b25seTEyMDAGA1UEAxMpRW50cnVzdCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0gRzIw +HhcNMDkwNzA3MTcyNTU0WhcNMzAxMjA3MTc1NTU0WjCBvjELMAkGA1UEBhMCVVMxFjAUBgNVBAoT +DUVudHJ1c3QsIEluYy4xKDAmBgNVBAsTH1NlZSB3d3cuZW50cnVzdC5uZXQvbGVnYWwtdGVybXMx +OTA3BgNVBAsTMChjKSAyMDA5IEVudHJ1c3QsIEluYy4gLSBmb3IgYXV0aG9yaXplZCB1c2Ugb25s +eTEyMDAGA1UEAxMpRW50cnVzdCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0gRzIwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6hLZy254Ma+KZ6TABp3bqMriVQRrJ2mFOWHLP +/vaCeb9zYQYKpSfYs1/TRU4cctZOMvJyig/3gxnQaoCAAEUesMfnmr8SVycco2gvCoe9amsOXmXz +HHfV1IWNcCG0szLni6LVhjkCsbjSR87kyUnEO6fe+1R9V77w6G7CebI6C1XiUJgWMhNcL3hWwcKU +s/Ja5CeanyTXxuzQmyWC48zCxEXFjJd6BmsqEZ+pCm5IO2/b1BEZQvePB7/1U1+cPvQXLOZprE4y +TGJ36rfo5bs0vBmLrpxR57d+tVOxMyLlbc9wPBr64ptntoP0jaWvYkxN4FisZDQSA/i2jZRjJKRx +AgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRqciZ6 +0B7vfec7aVHUbI2fkBJmqzANBgkqhkiG9w0BAQsFAAOCAQEAeZ8dlsa2eT8ijYfThwMEYGprmi5Z +iXMRrEPR9RP/jTkrwPK9T3CMqS/qF8QLVJ7UG5aYMzyorWKiAHarWWluBh1+xLlEjZivEtRh2woZ +Rkfz6/djwUAFQKXSt/S1mja/qYh2iARVBCuch38aNzx+LaUa2NSJXsq9rD1s2G2v1fN2D807iDgi +nWyTmsQ9v4IbZT+mD12q/OWyFcq1rca8PdCE6OoGcrBNOTJ4vz4RnAuknZoh8/CbCzB428Hch0P+ +vGOaysXCHMnHjf87ElgI5rY97HosTvuDls4MPGmHVHOkc8KT/1EQrBVUAdj8BbGJoX90g5pJ19xO +e4pIb4tF9g== +-----END CERTIFICATE----- + +Entrust Root Certification Authority - EC1 +========================================== +-----BEGIN CERTIFICATE----- +MIIC+TCCAoCgAwIBAgINAKaLeSkAAAAAUNCR+TAKBggqhkjOPQQDAzCBvzELMAkGA1UEBhMCVVMx +FjAUBgNVBAoTDUVudHJ1c3QsIEluYy4xKDAmBgNVBAsTH1NlZSB3d3cuZW50cnVzdC5uZXQvbGVn +YWwtdGVybXMxOTA3BgNVBAsTMChjKSAyMDEyIEVudHJ1c3QsIEluYy4gLSBmb3IgYXV0aG9yaXpl +ZCB1c2Ugb25seTEzMDEGA1UEAxMqRW50cnVzdCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5 +IC0gRUMxMB4XDTEyMTIxODE1MjUzNloXDTM3MTIxODE1NTUzNlowgb8xCzAJBgNVBAYTAlVTMRYw +FAYDVQQKEw1FbnRydXN0LCBJbmMuMSgwJgYDVQQLEx9TZWUgd3d3LmVudHJ1c3QubmV0L2xlZ2Fs +LXRlcm1zMTkwNwYDVQQLEzAoYykgMjAxMiBFbnRydXN0LCBJbmMuIC0gZm9yIGF1dGhvcml6ZWQg +dXNlIG9ubHkxMzAxBgNVBAMTKkVudHJ1c3QgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAt +IEVDMTB2MBAGByqGSM49AgEGBSuBBAAiA2IABIQTydC6bUF74mzQ61VfZgIaJPRbiWlH47jCffHy +AsWfoPZb1YsGGYZPUxBtByQnoaD41UcZYUx9ypMn6nQM72+WCf5j7HBdNq1nd67JnXxVRDqiY1Ef +9eNi1KlHBz7MIKNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYE +FLdj5xrdjekIplWDpOBqUEFlEUJJMAoGCCqGSM49BAMDA2cAMGQCMGF52OVCR98crlOZF7ZvHH3h +vxGU0QOIdeSNiaSKd0bebWHvAvX7td/M/k7//qnmpwIwW5nXhTcGtXsI/esni0qU+eH6p44mCOh8 +kmhtc9hvJqwhAriZtyZBWyVgrtBIGu4G +-----END CERTIFICATE----- + +CFCA EV ROOT +============ +-----BEGIN CERTIFICATE----- +MIIFjTCCA3WgAwIBAgIEGErM1jANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJDTjEwMC4GA1UE +CgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRUwEwYDVQQDDAxDRkNB +IEVWIFJPT1QwHhcNMTIwODA4MDMwNzAxWhcNMjkxMjMxMDMwNzAxWjBWMQswCQYDVQQGEwJDTjEw +MC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRUwEwYDVQQD +DAxDRkNBIEVWIFJPT1QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDXXWvNED8fBVnV +BU03sQ7smCuOFR36k0sXgiFxEFLXUWRwFsJVaU2OFW2fvwwbwuCjZ9YMrM8irq93VCpLTIpTUnrD +7i7es3ElweldPe6hL6P3KjzJIx1qqx2hp/Hz7KDVRM8Vz3IvHWOX6Jn5/ZOkVIBMUtRSqy5J35DN +uF++P96hyk0g1CXohClTt7GIH//62pCfCqktQT+x8Rgp7hZZLDRJGqgG16iI0gNyejLi6mhNbiyW +ZXvKWfry4t3uMCz7zEasxGPrb382KzRzEpR/38wmnvFyXVBlWY9ps4deMm/DGIq1lY+wejfeWkU7 +xzbh72fROdOXW3NiGUgthxwG+3SYIElz8AXSG7Ggo7cbcNOIabla1jj0Ytwli3i/+Oh+uFzJlU9f +py25IGvPa931DfSCt/SyZi4QKPaXWnuWFo8BGS1sbn85WAZkgwGDg8NNkt0yxoekN+kWzqotaK8K +gWU6cMGbrU1tVMoqLUuFG7OA5nBFDWteNfB/O7ic5ARwiRIlk9oKmSJgamNgTnYGmE69g60dWIol +hdLHZR4tjsbftsbhf4oEIRUpdPA+nJCdDC7xij5aqgwJHsfVPKPtl8MeNPo4+QgO48BdK4PRVmrJ +tqhUUy54Mmc9gn900PvhtgVguXDbjgv5E1hvcWAQUhC5wUEJ73IfZzF4/5YFjQIDAQABo2MwYTAf +BgNVHSMEGDAWgBTj/i39KNALtbq2osS/BqoFjJP7LzAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB +/wQEAwIBBjAdBgNVHQ4EFgQU4/4t/SjQC7W6tqLEvwaqBYyT+y8wDQYJKoZIhvcNAQELBQADggIB +ACXGumvrh8vegjmWPfBEp2uEcwPenStPuiB/vHiyz5ewG5zz13ku9Ui20vsXiObTej/tUxPQ4i9q +ecsAIyjmHjdXNYmEwnZPNDatZ8POQQaIxffu2Bq41gt/UP+TqhdLjOztUmCypAbqTuv0axn96/Ua +4CUqmtzHQTb3yHQFhDmVOdYLO6Qn+gjYXB74BGBSESgoA//vU2YApUo0FmZ8/Qmkrp5nGm9BC2sG +E5uPhnEFtC+NiWYzKXZUmhH4J/qyP5Hgzg0b8zAarb8iXRvTvyUFTeGSGn+ZnzxEk8rUQElsgIfX +BDrDMlI1Dlb4pd19xIsNER9Tyx6yF7Zod1rg1MvIB671Oi6ON7fQAUtDKXeMOZePglr4UeWJoBjn +aH9dCi77o0cOPaYjesYBx4/IXr9tgFa+iiS6M+qf4TIRnvHST4D2G0CvOJ4RUHlzEhLN5mydLIhy +PDCBBpEi6lmt2hkuIsKNuYyH4Ga8cyNfIWRjgEj1oDwYPZTISEEdQLpe/v5WOaHIz16eGWRGENoX +kbcFgKyLmZJ956LYBws2J+dIeWCKw9cTXPhyQN9Ky8+ZAAoACxGV2lZFA4gKn2fQ1XmxqI1AbQ3C +ekD6819kR5LLU7m7Wc5P/dAVUwHY3+vZ5nbv0CO7O6l5s9UCKc2Jo5YPSjXnTkLAdc0Hz+Ys63su +-----END CERTIFICATE----- + +OISTE WISeKey Global Root GB CA +=============================== +-----BEGIN CERTIFICATE----- +MIIDtTCCAp2gAwIBAgIQdrEgUnTwhYdGs/gjGvbCwDANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQG +EwJDSDEQMA4GA1UEChMHV0lTZUtleTEiMCAGA1UECxMZT0lTVEUgRm91bmRhdGlvbiBFbmRvcnNl +ZDEoMCYGA1UEAxMfT0lTVEUgV0lTZUtleSBHbG9iYWwgUm9vdCBHQiBDQTAeFw0xNDEyMDExNTAw +MzJaFw0zOTEyMDExNTEwMzFaMG0xCzAJBgNVBAYTAkNIMRAwDgYDVQQKEwdXSVNlS2V5MSIwIAYD +VQQLExlPSVNURSBGb3VuZGF0aW9uIEVuZG9yc2VkMSgwJgYDVQQDEx9PSVNURSBXSVNlS2V5IEds +b2JhbCBSb290IEdCIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2Be3HEokKtaX +scriHvt9OO+Y9bI5mE4nuBFde9IllIiCFSZqGzG7qFshISvYD06fWvGxWuR51jIjK+FTzJlFXHtP +rby/h0oLS5daqPZI7H17Dc0hBt+eFf1Biki3IPShehtX1F1Q/7pn2COZH8g/497/b1t3sWtuuMlk +9+HKQUYOKXHQuSP8yYFfTvdv37+ErXNku7dCjmn21HYdfp2nuFeKUWdy19SouJVUQHMD9ur06/4o +Qnc/nSMbsrY9gBQHTC5P99UKFg29ZkM3fiNDecNAhvVMKdqOmq0NpQSHiB6F4+lT1ZvIiwNjeOvg +GUpuuy9rM2RYk61pv48b74JIxwIDAQABo1EwTzALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB +/zAdBgNVHQ4EFgQUNQ/INmNe4qPs+TtmFc5RUuORmj0wEAYJKwYBBAGCNxUBBAMCAQAwDQYJKoZI +hvcNAQELBQADggEBAEBM+4eymYGQfp3FsLAmzYh7KzKNbrghcViXfa43FK8+5/ea4n32cZiZBKpD +dHij40lhPnOMTZTg+XHEthYOU3gf1qKHLwI5gSk8rxWYITD+KJAAjNHhy/peyP34EEY7onhCkRd0 +VQreUGdNZtGn//3ZwLWoo4rOZvUPQ82nK1d7Y0Zqqi5S2PTt4W2tKZB4SLrhI6qjiey1q5bAtEui +HZeeevJuQHHfaPFlTc58Bd9TZaml8LGXBHAVRgOY1NK/VLSgWH1Sb9pWJmLU2NuJMW8c8CLC02Ic +Nc1MaRVUGpCY3useX8p3x8uOPUNpnJpY0CQ73xtAln41rYHHTnG6iBM= +-----END CERTIFICATE----- + +SZAFIR ROOT CA2 +=============== +-----BEGIN CERTIFICATE----- +MIIDcjCCAlqgAwIBAgIUPopdB+xV0jLVt+O2XwHrLdzk1uQwDQYJKoZIhvcNAQELBQAwUTELMAkG +A1UEBhMCUEwxKDAmBgNVBAoMH0tyYWpvd2EgSXpiYSBSb3psaWN6ZW5pb3dhIFMuQS4xGDAWBgNV +BAMMD1NaQUZJUiBST09UIENBMjAeFw0xNTEwMTkwNzQzMzBaFw0zNTEwMTkwNzQzMzBaMFExCzAJ +BgNVBAYTAlBMMSgwJgYDVQQKDB9LcmFqb3dhIEl6YmEgUm96bGljemVuaW93YSBTLkEuMRgwFgYD +VQQDDA9TWkFGSVIgUk9PVCBDQTIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3vD5Q +qEvNQLXOYeeWyrSh2gwisPq1e3YAd4wLz32ohswmUeQgPYUM1ljj5/QqGJ3a0a4m7utT3PSQ1hNK +DJA8w/Ta0o4NkjrcsbH/ON7Dui1fgLkCvUqdGw+0w8LBZwPd3BucPbOw3gAeqDRHu5rr/gsUvTaE +2g0gv/pby6kWIK05YO4vdbbnl5z5Pv1+TW9NL++IDWr63fE9biCloBK0TXC5ztdyO4mTp4CEHCdJ +ckm1/zuVnsHMyAHs6A6KCpbns6aH5db5BSsNl0BwPLqsdVqc1U2dAgrSS5tmS0YHF2Wtn2yIANwi +ieDhZNRnvDF5YTy7ykHNXGoAyDw4jlivAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0P +AQH/BAQDAgEGMB0GA1UdDgQWBBQuFqlKGLXLzPVvUPMjX/hd56zwyDANBgkqhkiG9w0BAQsFAAOC +AQEAtXP4A9xZWx126aMqe5Aosk3AM0+qmrHUuOQn/6mWmc5G4G18TKI4pAZw8PRBEew/R40/cof5 +O/2kbytTAOD/OblqBw7rHRz2onKQy4I9EYKL0rufKq8h5mOGnXkZ7/e7DDWQw4rtTw/1zBLZpD67 +oPwglV9PJi8RI4NOdQcPv5vRtB3pEAT+ymCPoky4rc/hkA/NrgrHXXu3UNLUYfrVFdvXn4dRVOul +4+vJhaAlIDf7js4MNIThPIGyd05DpYhfhmehPea0XGG2Ptv+tyjFogeutcrKjSoS75ftwjCkySp6 ++/NNIxuZMzSgLvWpCz/UXeHPhJ/iGcJfitYgHuNztw== +-----END CERTIFICATE----- + +Certum Trusted Network CA 2 +=========================== +-----BEGIN CERTIFICATE----- +MIIF0jCCA7qgAwIBAgIQIdbQSk8lD8kyN/yqXhKN6TANBgkqhkiG9w0BAQ0FADCBgDELMAkGA1UE +BhMCUEwxIjAgBgNVBAoTGVVuaXpldG8gVGVjaG5vbG9naWVzIFMuQS4xJzAlBgNVBAsTHkNlcnR1 +bSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEkMCIGA1UEAxMbQ2VydHVtIFRydXN0ZWQgTmV0d29y +ayBDQSAyMCIYDzIwMTExMDA2MDgzOTU2WhgPMjA0NjEwMDYwODM5NTZaMIGAMQswCQYDVQQGEwJQ +TDEiMCAGA1UEChMZVW5pemV0byBUZWNobm9sb2dpZXMgUy5BLjEnMCUGA1UECxMeQ2VydHVtIENl +cnRpZmljYXRpb24gQXV0aG9yaXR5MSQwIgYDVQQDExtDZXJ0dW0gVHJ1c3RlZCBOZXR3b3JrIENB +IDIwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC9+Xj45tWADGSdhhuWZGc/IjoedQF9 +7/tcZ4zJzFxrqZHmuULlIEub2pt7uZld2ZuAS9eEQCsn0+i6MLs+CRqnSZXvK0AkwpfHp+6bJe+o +CgCXhVqqndwpyeI1B+twTUrWwbNWuKFBOJvR+zF/j+Bf4bE/D44WSWDXBo0Y+aomEKsq09DRZ40b +Rr5HMNUuctHFY9rnY3lEfktjJImGLjQ/KUxSiyqnwOKRKIm5wFv5HdnnJ63/mgKXwcZQkpsCLL2p +uTRZCr+ESv/f/rOf69me4Jgj7KZrdxYq28ytOxykh9xGc14ZYmhFV+SQgkK7QtbwYeDBoz1mo130 +GO6IyY0XRSmZMnUCMe4pJshrAua1YkV/NxVaI2iJ1D7eTiew8EAMvE0Xy02isx7QBlrd9pPPV3WZ +9fqGGmd4s7+W/jTcvedSVuWz5XV710GRBdxdaeOVDUO5/IOWOZV7bIBaTxNyxtd9KXpEulKkKtVB +Rgkg/iKgtlswjbyJDNXXcPiHUv3a76xRLgezTv7QCdpw75j6VuZt27VXS9zlLCUVyJ4ueE742pye +hizKV/Ma5ciSixqClnrDvFASadgOWkaLOusm+iPJtrCBvkIApPjW/jAux9JG9uWOdf3yzLnQh1vM +BhBgu4M1t15n3kfsmUjxpKEV/q2MYo45VU85FrmxY53/twIDAQABo0IwQDAPBgNVHRMBAf8EBTAD +AQH/MB0GA1UdDgQWBBS2oVQ5AsOgP46KvPrU+Bym0ToO/TAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZI +hvcNAQENBQADggIBAHGlDs7k6b8/ONWJWsQCYftMxRQXLYtPU2sQF/xlhMcQSZDe28cmk4gmb3DW +Al45oPePq5a1pRNcgRRtDoGCERuKTsZPpd1iHkTfCVn0W3cLN+mLIMb4Ck4uWBzrM9DPhmDJ2vuA +L55MYIR4PSFk1vtBHxgP58l1cb29XN40hz5BsA72udY/CROWFC/emh1auVbONTqwX3BNXuMp8SMo +clm2q8KMZiYcdywmdjWLKKdpoPk79SPdhRB0yZADVpHnr7pH1BKXESLjokmUbOe3lEu6LaTaM4tM +pkT/WjzGHWTYtTHkpjx6qFcL2+1hGsvxznN3Y6SHb0xRONbkX8eftoEq5IVIeVheO/jbAoJnwTnb +w3RLPTYe+SmTiGhbqEQZIfCn6IENLOiTNrQ3ssqwGyZ6miUfmpqAnksqP/ujmv5zMnHCnsZy4Ypo +J/HkD7TETKVhk/iXEAcqMCWpuchxuO9ozC1+9eB+D4Kob7a6bINDd82Kkhehnlt4Fj1F4jNy3eFm +ypnTycUm/Q1oBEauttmbjL4ZvrHG8hnjXALKLNhvSgfZyTXaQHXyxKcZb55CEJh15pWLYLztxRLX +is7VmFxWlgPF7ncGNf/P5O4/E2Hu29othfDNrp2yGAlFw5Khchf8R7agCyzxxN5DaAhqXzvwdmP7 +zAYspsbiDrW5viSP +-----END CERTIFICATE----- + +Hellenic Academic and Research Institutions RootCA 2015 +======================================================= +-----BEGIN CERTIFICATE----- +MIIGCzCCA/OgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBpjELMAkGA1UEBhMCR1IxDzANBgNVBAcT +BkF0aGVuczFEMEIGA1UEChM7SGVsbGVuaWMgQWNhZGVtaWMgYW5kIFJlc2VhcmNoIEluc3RpdHV0 +aW9ucyBDZXJ0LiBBdXRob3JpdHkxQDA+BgNVBAMTN0hlbGxlbmljIEFjYWRlbWljIGFuZCBSZXNl +YXJjaCBJbnN0aXR1dGlvbnMgUm9vdENBIDIwMTUwHhcNMTUwNzA3MTAxMTIxWhcNNDAwNjMwMTAx +MTIxWjCBpjELMAkGA1UEBhMCR1IxDzANBgNVBAcTBkF0aGVuczFEMEIGA1UEChM7SGVsbGVuaWMg +QWNhZGVtaWMgYW5kIFJlc2VhcmNoIEluc3RpdHV0aW9ucyBDZXJ0LiBBdXRob3JpdHkxQDA+BgNV +BAMTN0hlbGxlbmljIEFjYWRlbWljIGFuZCBSZXNlYXJjaCBJbnN0aXR1dGlvbnMgUm9vdENBIDIw +MTUwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDC+Kk/G4n8PDwEXT2QNrCROnk8Zlrv +bTkBSRq0t89/TSNTt5AA4xMqKKYx8ZEA4yjsriFBzh/a/X0SWwGDD7mwX5nh8hKDgE0GPt+sr+eh +iGsxr/CL0BgzuNtFajT0AoAkKAoCFZVedioNmToUW/bLy1O8E00BiDeUJRtCvCLYjqOWXjrZMts+ +6PAQZe104S+nfK8nNLspfZu2zwnI5dMK/IhlZXQK3HMcXM1AsRzUtoSMTFDPaI6oWa7CJ06CojXd +FPQf/7J31Ycvqm59JCfnxssm5uX+Zwdj2EUN3TpZZTlYepKZcj2chF6IIbjV9Cz82XBST3i4vTwr +i5WY9bPRaM8gFH5MXF/ni+X1NYEZN9cRCLdmvtNKzoNXADrDgfgXy5I2XdGj2HUb4Ysn6npIQf1F +GQatJ5lOwXBH3bWfgVMS5bGMSF0xQxfjjMZ6Y5ZLKTBOhE5iGV48zpeQpX8B653g+IuJ3SWYPZK2 +fu/Z8VFRfS0myGlZYeCsargqNhEEelC9MoS+L9xy1dcdFkfkR2YgP/SWxa+OAXqlD3pk9Q0Yh9mu +iNX6hME6wGkoLfINaFGq46V3xqSQDqE3izEjR8EJCOtu93ib14L8hCCZSRm2Ekax+0VVFqmjZayc +Bw/qa9wfLgZy7IaIEuQt218FL+TwA9MmM+eAws1CoRc0CwIDAQABo0IwQDAPBgNVHRMBAf8EBTAD +AQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUcRVnyMjJvXVdctA4GGqd83EkVAswDQYJKoZI +hvcNAQELBQADggIBAHW7bVRLqhBYRjTyYtcWNl0IXtVsyIe9tC5G8jH4fOpCtZMWVdyhDBKg2mF+ +D1hYc2Ryx+hFjtyp8iY/xnmMsVMIM4GwVhO+5lFc2JsKT0ucVlMC6U/2DWDqTUJV6HwbISHTGzrM +d/K4kPFox/la/vot9L/J9UUbzjgQKjeKeaO04wlshYaT/4mWJ3iBj2fjRnRUjtkNaeJK9E10A/+y +d+2VZ5fkscWrv2oj6NSU4kQoYsRL4vDY4ilrGnB+JGGTe08DMiUNRSQrlrRGar9KC/eaj8GsGsVn +82800vpzY4zvFrCopEYq+OsS7HK07/grfoxSwIuEVPkvPuNVqNxmsdnhX9izjFk0WaSrT2y7Hxjb +davYy5LNlDhhDgcGH0tGEPEVvo2FXDtKK4F5D7Rpn0lQl033DlZdwJVqwjbDG2jJ9SrcR5q+ss7F +Jej6A7na+RZukYT1HCjI/CbM1xyQVqdfbzoEvM14iQuODy+jqk+iGxI9FghAD/FGTNeqewjBCvVt +J94Cj8rDtSvK6evIIVM4pcw72Hc3MKJP2W/R8kCtQXoXxdZKNYm3QdV8hn9VTYNKpXMgwDqvkPGa +JI7ZjnHKe7iG2rKPmT4dEw0SEe7Uq/DpFXYC5ODfqiAeW2GFZECpkJcNrVPSWh2HagCXZWK0vm9q +p/UsQu0yrbYhnr68 +-----END CERTIFICATE----- + +Hellenic Academic and Research Institutions ECC RootCA 2015 +=========================================================== +-----BEGIN CERTIFICATE----- +MIICwzCCAkqgAwIBAgIBADAKBggqhkjOPQQDAjCBqjELMAkGA1UEBhMCR1IxDzANBgNVBAcTBkF0 +aGVuczFEMEIGA1UEChM7SGVsbGVuaWMgQWNhZGVtaWMgYW5kIFJlc2VhcmNoIEluc3RpdHV0aW9u +cyBDZXJ0LiBBdXRob3JpdHkxRDBCBgNVBAMTO0hlbGxlbmljIEFjYWRlbWljIGFuZCBSZXNlYXJj +aCBJbnN0aXR1dGlvbnMgRUNDIFJvb3RDQSAyMDE1MB4XDTE1MDcwNzEwMzcxMloXDTQwMDYzMDEw +MzcxMlowgaoxCzAJBgNVBAYTAkdSMQ8wDQYDVQQHEwZBdGhlbnMxRDBCBgNVBAoTO0hlbGxlbmlj +IEFjYWRlbWljIGFuZCBSZXNlYXJjaCBJbnN0aXR1dGlvbnMgQ2VydC4gQXV0aG9yaXR5MUQwQgYD +VQQDEztIZWxsZW5pYyBBY2FkZW1pYyBhbmQgUmVzZWFyY2ggSW5zdGl0dXRpb25zIEVDQyBSb290 +Q0EgMjAxNTB2MBAGByqGSM49AgEGBSuBBAAiA2IABJKgQehLgoRc4vgxEZmGZE4JJS+dQS8KrjVP +dJWyUWRrjWvmP3CV8AVER6ZyOFB2lQJajq4onvktTpnvLEhvTCUp6NFxW98dwXU3tNf6e3pCnGoK +Vlp8aQuqgAkkbH7BRqNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0O +BBYEFLQiC4KZJAEOnLvkDv2/+5cgk5kqMAoGCCqGSM49BAMCA2cAMGQCMGfOFmI4oqxiRaeplSTA +GiecMjvAwNW6qef4BENThe5SId6d9SWDPp5YSy/XZxMOIQIwBeF1Ad5o7SofTUwJCA3sS61kFyjn +dc5FZXIhF8siQQ6ME5g4mlRtm8rifOoCWCKR +-----END CERTIFICATE----- + +ISRG Root X1 +============ +-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UE +BhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQD +EwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQG +EwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMT +DElTUkcgUm9vdCBYMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54r +Vygch77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+0TM8ukj1 +3Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6UA5/TR5d8mUgjU+g4rk8K +b4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sWT8KOEUt+zwvo/7V3LvSye0rgTBIlDHCN +Aymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyHB5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ +4Q7e2RCOFvu396j3x+UCB5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf +1b0SHzUvKBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWnOlFu +hjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTnjh8BCNAw1FtxNrQH +usEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbwqHyGO0aoSCqI3Haadr8faqU9GY/r +OPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CIrU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4G +A1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY +9umbbjANBgkqhkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL +ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ3BebYhtF8GaV +0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KKNFtY2PwByVS5uCbMiogziUwt +hDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJw +TdwJx4nLCgdNbOhdjsnvzqvHu7UrTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nx +e5AW0wdeRlN8NwdCjNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZA +JzVcoyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq4RgqsahD +YVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPAmRGunUHBcnWEvgJBQl9n +JEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57demyPxgcYxn/eR44/KJ4EBs+lVDR3veyJ +m+kXQ99b21/+jh5Xos1AnX5iItreGCc= +-----END CERTIFICATE----- + +AC RAIZ FNMT-RCM +================ +-----BEGIN CERTIFICATE----- +MIIFgzCCA2ugAwIBAgIPXZONMGc2yAYdGsdUhGkHMA0GCSqGSIb3DQEBCwUAMDsxCzAJBgNVBAYT +AkVTMREwDwYDVQQKDAhGTk1ULVJDTTEZMBcGA1UECwwQQUMgUkFJWiBGTk1ULVJDTTAeFw0wODEw +MjkxNTU5NTZaFw0zMDAxMDEwMDAwMDBaMDsxCzAJBgNVBAYTAkVTMREwDwYDVQQKDAhGTk1ULVJD +TTEZMBcGA1UECwwQQUMgUkFJWiBGTk1ULVJDTTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC +ggIBALpxgHpMhm5/yBNtwMZ9HACXjywMI7sQmkCpGreHiPibVmr75nuOi5KOpyVdWRHbNi63URcf +qQgfBBckWKo3Shjf5TnUV/3XwSyRAZHiItQDwFj8d0fsjz50Q7qsNI1NOHZnjrDIbzAzWHFctPVr +btQBULgTfmxKo0nRIBnuvMApGGWn3v7v3QqQIecaZ5JCEJhfTzC8PhxFtBDXaEAUwED653cXeuYL +j2VbPNmaUtu1vZ5Gzz3rkQUCwJaydkxNEJY7kvqcfw+Z374jNUUeAlz+taibmSXaXvMiwzn15Cou +08YfxGyqxRxqAQVKL9LFwag0Jl1mpdICIfkYtwb1TplvqKtMUejPUBjFd8g5CSxJkjKZqLsXF3mw +WsXmo8RZZUc1g16p6DULmbvkzSDGm0oGObVo/CK67lWMK07q87Hj/LaZmtVC+nFNCM+HHmpxffnT +tOmlcYF7wk5HlqX2doWjKI/pgG6BU6VtX7hI+cL5NqYuSf+4lsKMB7ObiFj86xsc3i1w4peSMKGJ +47xVqCfWS+2QrYv6YyVZLag13cqXM7zlzced0ezvXg5KkAYmY6252TUtB7p2ZSysV4999AeU14EC +ll2jB0nVetBX+RvnU0Z1qrB5QstocQjpYL05ac70r8NWQMetUqIJ5G+GR4of6ygnXYMgrwTJbFaa +i0b1AgMBAAGjgYMwgYAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYE +FPd9xf3E6Jobd2Sn9R2gzL+HYJptMD4GA1UdIAQ3MDUwMwYEVR0gADArMCkGCCsGAQUFBwIBFh1o +dHRwOi8vd3d3LmNlcnQuZm5tdC5lcy9kcGNzLzANBgkqhkiG9w0BAQsFAAOCAgEAB5BK3/MjTvDD +nFFlm5wioooMhfNzKWtN/gHiqQxjAb8EZ6WdmF/9ARP67Jpi6Yb+tmLSbkyU+8B1RXxlDPiyN8+s +D8+Nb/kZ94/sHvJwnvDKuO+3/3Y3dlv2bojzr2IyIpMNOmqOFGYMLVN0V2Ue1bLdI4E7pWYjJ2cJ +j+F3qkPNZVEI7VFY/uY5+ctHhKQV8Xa7pO6kO8Rf77IzlhEYt8llvhjho6Tc+hj507wTmzl6NLrT +Qfv6MooqtyuGC2mDOL7Nii4LcK2NJpLuHvUBKwrZ1pebbuCoGRw6IYsMHkCtA+fdZn71uSANA+iW ++YJF1DngoABd15jmfZ5nc8OaKveri6E6FO80vFIOiZiaBECEHX5FaZNXzuvO+FB8TxxuBEOb+dY7 +Ixjp6o7RTUaN8Tvkasq6+yO3m/qZASlaWFot4/nUbQ4mrcFuNLwy+AwF+mWj2zs3gyLp1txyM/1d +8iC9djwj2ij3+RvrWWTV3F9yfiD8zYm1kGdNYno/Tq0dwzn+evQoFt9B9kiABdcPUXmsEKvU7ANm +5mqwujGSQkBqvjrTcuFqN1W8rB2Vt2lh8kORdOag0wokRqEIr9baRRmW1FMdW4R58MD3R++Lj8UG +rp1MYp3/RgT408m2ECVAdf4WqslKYIYvuu8wd+RU4riEmViAqhOLUTpPSPaLtrM= +-----END CERTIFICATE----- + +Amazon Root CA 1 +================ +-----BEGIN CERTIFICATE----- +MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsFADA5MQswCQYD +VQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSAxMB4XDTE1 +MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpv +bjEZMBcGA1UEAxMQQW1hem9uIFJvb3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBALJ4gHHKeNXjca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgH +FzZM9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qwIFAGbHrQ +gLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6VOujw5H5SNz/0egwLX0t +dHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L93FcXmn/6pUCyziKrlA4b9v7LWIbxcce +VOF34GfID5yHI9Y/QCB/IIDEgEw+OyQmjgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB +/zAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3 +DQEBCwUAA4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDIU5PM +CCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUsN+gDS63pYaACbvXy +8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vvo/ufQJVtMVT8QtPHRh8jrdkPSHCa +2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2 +xJNDd2ZhwLnoQdeXeGADbkpyrqXRfboQnoZsG4q5WTP468SQvvG5 +-----END CERTIFICATE----- + +Amazon Root CA 2 +================ +-----BEGIN CERTIFICATE----- +MIIFQTCCAymgAwIBAgITBmyf0pY1hp8KD+WGePhbJruKNzANBgkqhkiG9w0BAQwFADA5MQswCQYD +VQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSAyMB4XDTE1 +MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpv +bjEZMBcGA1UEAxMQQW1hem9uIFJvb3QgQ0EgMjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC +ggIBAK2Wny2cSkxKgXlRmeyKy2tgURO8TW0G/LAIjd0ZEGrHJgw12MBvIITplLGbhQPDW9tK6Mj4 +kHbZW0/jTOgGNk3Mmqw9DJArktQGGWCsN0R5hYGCrVo34A3MnaZMUnbqQ523BNFQ9lXg1dKmSYXp +N+nKfq5clU1Imj+uIFptiJXZNLhSGkOQsL9sBbm2eLfq0OQ6PBJTYv9K8nu+NQWpEjTj82R0Yiw9 +AElaKP4yRLuH3WUnAnE72kr3H9rN9yFVkE8P7K6C4Z9r2UXTu/Bfh+08LDmG2j/e7HJV63mjrdvd +fLC6HM783k81ds8P+HgfajZRRidhW+mez/CiVX18JYpvL7TFz4QuK/0NURBs+18bvBt+xa47mAEx +kv8LV/SasrlX6avvDXbR8O70zoan4G7ptGmh32n2M8ZpLpcTnqWHsFcQgTfJU7O7f/aS0ZzQGPSS +btqDT6ZjmUyl+17vIWR6IF9sZIUVyzfpYgwLKhbcAS4y2j5L9Z469hdAlO+ekQiG+r5jqFoz7Mt0 +Q5X5bGlSNscpb/xVA1wf+5+9R+vnSUeVC06JIglJ4PVhHvG/LopyboBZ/1c6+XUyo05f7O0oYtlN +c/LMgRdg7c3r3NunysV+Ar3yVAhU/bQtCSwXVEqY0VThUWcI0u1ufm8/0i2BWSlmy5A5lREedCf+ +3euvAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSw +DPBMMPQFWAJI/TPlUq9LhONmUjANBgkqhkiG9w0BAQwFAAOCAgEAqqiAjw54o+Ci1M3m9Zh6O+oA +A7CXDpO8Wqj2LIxyh6mx/H9z/WNxeKWHWc8w4Q0QshNabYL1auaAn6AFC2jkR2vHat+2/XcycuUY ++gn0oJMsXdKMdYV2ZZAMA3m3MSNjrXiDCYZohMr/+c8mmpJ5581LxedhpxfL86kSk5Nrp+gvU5LE +YFiwzAJRGFuFjWJZY7attN6a+yb3ACfAXVU3dJnJUH/jWS5E4ywl7uxMMne0nxrpS10gxdr9HIcW +xkPo1LsmmkVwXqkLN1PiRnsn/eBG8om3zEK2yygmbtmlyTrIQRNg91CMFa6ybRoVGld45pIq2WWQ +gj9sAq+uEjonljYE1x2igGOpm/HlurR8FLBOybEfdF849lHqm/osohHUqS0nGkWxr7JOcQ3AWEbW +aQbLU8uz/mtBzUF+fUwPfHJ5elnNXkoOrJupmHN5fLT0zLm4BwyydFy4x2+IoZCn9Kr5v2c69BoV +Yh63n749sSmvZ6ES8lgQGVMDMBu4Gon2nL2XA46jCfMdiyHxtN/kHNGfZQIG6lzWE7OE76KlXIx3 +KadowGuuQNKotOrN8I1LOJwZmhsoVLiJkO/KdYE+HvJkJMcYr07/R54H9jVlpNMKVv/1F2Rs76gi +JUmTtt8AF9pYfl3uxRuw0dFfIRDH+fO6AgonB8Xx1sfT4PsJYGw= +-----END CERTIFICATE----- + +Amazon Root CA 3 +================ +-----BEGIN CERTIFICATE----- +MIIBtjCCAVugAwIBAgITBmyf1XSXNmY/Owua2eiedgPySjAKBggqhkjOPQQDAjA5MQswCQYDVQQG +EwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSAzMB4XDTE1MDUy +NjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZ +MBcGA1UEAxMQQW1hem9uIFJvb3QgQ0EgMzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCmXp8ZB +f8ANm+gBG1bG8lKlui2yEujSLtf6ycXYqm0fc4E7O5hrOXwzpcVOho6AF2hiRVd9RFgdszflZwjr +Zt6jQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSrttvXBp43 +rDCGB5Fwx5zEGbF4wDAKBggqhkjOPQQDAgNJADBGAiEA4IWSoxe3jfkrBqWTrBqYaGFy+uGh0Psc +eGCmQ5nFuMQCIQCcAu/xlJyzlvnrxir4tiz+OpAUFteMYyRIHN8wfdVoOw== +-----END CERTIFICATE----- + +Amazon Root CA 4 +================ +-----BEGIN CERTIFICATE----- +MIIB8jCCAXigAwIBAgITBmyf18G7EEwpQ+Vxe3ssyBrBDjAKBggqhkjOPQQDAzA5MQswCQYDVQQG +EwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSA0MB4XDTE1MDUy +NjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZ +MBcGA1UEAxMQQW1hem9uIFJvb3QgQ0EgNDB2MBAGByqGSM49AgEGBSuBBAAiA2IABNKrijdPo1MN +/sGKe0uoe0ZLY7Bi9i0b2whxIdIA6GO9mif78DluXeo9pcmBqqNbIJhFXRbb/egQbeOc4OO9X4Ri +83BkM6DLJC9wuoihKqB1+IGuYgbEgds5bimwHvouXKNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAYYwHQYDVR0OBBYEFNPsxzplbszh2naaVvuc84ZtV+WBMAoGCCqGSM49BAMDA2gA +MGUCMDqLIfG9fhGt0O9Yli/W651+kI0rz2ZVwyzjKKlwCkcO8DdZEv8tmZQoTipPNU0zWgIxAOp1 +AE47xDqUEpHJWEadIRNyp4iciuRMStuW1KyLa2tJElMzrdfkviT8tQp21KW8EA== +-----END CERTIFICATE----- + +TUBITAK Kamu SM SSL Kok Sertifikasi - Surum 1 +============================================= +-----BEGIN CERTIFICATE----- +MIIEYzCCA0ugAwIBAgIBATANBgkqhkiG9w0BAQsFADCB0jELMAkGA1UEBhMCVFIxGDAWBgNVBAcT +D0dlYnplIC0gS29jYWVsaTFCMEAGA1UEChM5VHVya2l5ZSBCaWxpbXNlbCB2ZSBUZWtub2xvamlr +IEFyYXN0aXJtYSBLdXJ1bXUgLSBUVUJJVEFLMS0wKwYDVQQLEyRLYW11IFNlcnRpZmlrYXN5b24g +TWVya2V6aSAtIEthbXUgU00xNjA0BgNVBAMTLVRVQklUQUsgS2FtdSBTTSBTU0wgS29rIFNlcnRp +ZmlrYXNpIC0gU3VydW0gMTAeFw0xMzExMjUwODI1NTVaFw00MzEwMjUwODI1NTVaMIHSMQswCQYD +VQQGEwJUUjEYMBYGA1UEBxMPR2ViemUgLSBLb2NhZWxpMUIwQAYDVQQKEzlUdXJraXllIEJpbGlt +c2VsIHZlIFRla25vbG9qaWsgQXJhc3Rpcm1hIEt1cnVtdSAtIFRVQklUQUsxLTArBgNVBAsTJEth +bXUgU2VydGlmaWthc3lvbiBNZXJrZXppIC0gS2FtdSBTTTE2MDQGA1UEAxMtVFVCSVRBSyBLYW11 +IFNNIFNTTCBLb2sgU2VydGlmaWthc2kgLSBTdXJ1bSAxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A +MIIBCgKCAQEAr3UwM6q7a9OZLBI3hNmNe5eA027n/5tQlT6QlVZC1xl8JoSNkvoBHToP4mQ4t4y8 +6Ij5iySrLqP1N+RAjhgleYN1Hzv/bKjFxlb4tO2KRKOrbEz8HdDc72i9z+SqzvBV96I01INrN3wc +wv61A+xXzry0tcXtAA9TNypN9E8Mg/uGz8v+jE69h/mniyFXnHrfA2eJLJ2XYacQuFWQfw4tJzh0 +3+f92k4S400VIgLI4OD8D62K18lUUMw7D8oWgITQUVbDjlZ/iSIzL+aFCr2lqBs23tPcLG07xxO9 +WSMs5uWk99gL7eqQQESolbuT1dCANLZGeA4fAJNG4e7p+exPFwIDAQABo0IwQDAdBgNVHQ4EFgQU +ZT/HiobGPN08VFw1+DrtUgxHV8gwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJ +KoZIhvcNAQELBQADggEBACo/4fEyjq7hmFxLXs9rHmoJ0iKpEsdeV31zVmSAhHqT5Am5EM2fKifh +AHe+SMg1qIGf5LgsyX8OsNJLN13qudULXjS99HMpw+0mFZx+CFOKWI3QSyjfwbPfIPP54+M638yc +lNhOT8NrF7f3cuitZjO1JVOr4PhMqZ398g26rrnZqsZr+ZO7rqu4lzwDGrpDxpa5RXI4s6ehlj2R +e37AIVNMh+3yC1SVUZPVIqUNivGTDj5UDrDYyU7c8jEyVupk+eq1nRZmQnLzf9OxMUP8pI4X8W0j +q5Rm+K37DwhuJi1/FwcJsoz7UMCflo3Ptv0AnVoUmr8CRPXBwp8iXqIPoeM= +-----END CERTIFICATE----- + +GDCA TrustAUTH R5 ROOT +====================== +-----BEGIN CERTIFICATE----- +MIIFiDCCA3CgAwIBAgIIfQmX/vBH6nowDQYJKoZIhvcNAQELBQAwYjELMAkGA1UEBhMCQ04xMjAw +BgNVBAoMKUdVQU5HIERPTkcgQ0VSVElGSUNBVEUgQVVUSE9SSVRZIENPLixMVEQuMR8wHQYDVQQD +DBZHRENBIFRydXN0QVVUSCBSNSBST09UMB4XDTE0MTEyNjA1MTMxNVoXDTQwMTIzMTE1NTk1OVow +YjELMAkGA1UEBhMCQ04xMjAwBgNVBAoMKUdVQU5HIERPTkcgQ0VSVElGSUNBVEUgQVVUSE9SSVRZ +IENPLixMVEQuMR8wHQYDVQQDDBZHRENBIFRydXN0QVVUSCBSNSBST09UMIICIjANBgkqhkiG9w0B +AQEFAAOCAg8AMIICCgKCAgEA2aMW8Mh0dHeb7zMNOwZ+Vfy1YI92hhJCfVZmPoiC7XJjDp6L3TQs +AlFRwxn9WVSEyfFrs0yw6ehGXTjGoqcuEVe6ghWinI9tsJlKCvLriXBjTnnEt1u9ol2x8kECK62p +OqPseQrsXzrj/e+APK00mxqriCZ7VqKChh/rNYmDf1+uKU49tm7srsHwJ5uu4/Ts765/94Y9cnrr +pftZTqfrlYwiOXnhLQiPzLyRuEH3FMEjqcOtmkVEs7LXLM3GKeJQEK5cy4KOFxg2fZfmiJqwTTQJ +9Cy5WmYqsBebnh52nUpmMUHfP/vFBu8btn4aRjb3ZGM74zkYI+dndRTVdVeSN72+ahsmUPI2JgaQ +xXABZG12ZuGR224HwGGALrIuL4xwp9E7PLOR5G62xDtw8mySlwnNR30YwPO7ng/Wi64HtloPzgsM +R6flPri9fcebNaBhlzpBdRfMK5Z3KpIhHtmVdiBnaM8Nvd/WHwlqmuLMc3GkL30SgLdTMEZeS1SZ +D2fJpcjyIMGC7J0R38IC+xo70e0gmu9lZJIQDSri3nDxGGeCjGHeuLzRL5z7D9Ar7Rt2ueQ5Vfj4 +oR24qoAATILnsn8JuLwwoC8N9VKejveSswoAHQBUlwbgsQfZxw9cZX08bVlX5O2ljelAU58VS6Bx +9hoh49pwBiFYFIeFd3mqgnkCAwEAAaNCMEAwHQYDVR0OBBYEFOLJQJ9NzuiaoXzPDj9lxSmIahlR +MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4ICAQDRSVfg +p8xoWLoBDysZzY2wYUWsEe1jUGn4H3++Fo/9nesLqjJHdtJnJO29fDMylyrHBYZmDRd9FBUb1Ov9 +H5r2XpdptxolpAqzkT9fNqyL7FeoPueBihhXOYV0GkLH6VsTX4/5COmSdI31R9KrO9b7eGZONn35 +6ZLpBN79SWP8bfsUcZNnL0dKt7n/HipzcEYwv1ryL3ml4Y0M2fmyYzeMN2WFcGpcWwlyua1jPLHd ++PwyvzeG5LuOmCd+uh8W4XAR8gPfJWIyJyYYMoSf/wA6E7qaTfRPuBRwIrHKK5DOKcFw9C+df/KQ +HtZa37dG/OaG+svgIHZ6uqbL9XzeYqWxi+7egmaKTjowHz+Ay60nugxe19CxVsp3cbK1daFQqUBD +F8Io2c9Si1vIY9RCPqAzekYu9wogRlR+ak8x8YF+QnQ4ZXMn7sZ8uI7XpTrXmKGcjBBV09tL7ECQ +8s1uV9JiDnxXk7Gnbc2dg7sq5+W2O3FYrf3RRbxake5TFW/TRQl1brqQXR4EzzffHqhmsYzmIGrv +/EhOdJhCrylvLmrH+33RZjEizIYAfmaDDEL0vTSSwxrqT8p+ck0LcIymSLumoRT2+1hEmRSuqguT +aaApJUqlyyvdimYHFngVV3Eb7PVHhPOeMTd61X8kreS8/f3MboPoDKi3QWwH3b08hpcv0g== +-----END CERTIFICATE----- + +TrustCor RootCert CA-1 +====================== +-----BEGIN CERTIFICATE----- +MIIEMDCCAxigAwIBAgIJANqb7HHzA7AZMA0GCSqGSIb3DQEBCwUAMIGkMQswCQYDVQQGEwJQQTEP +MA0GA1UECAwGUGFuYW1hMRQwEgYDVQQHDAtQYW5hbWEgQ2l0eTEkMCIGA1UECgwbVHJ1c3RDb3Ig +U3lzdGVtcyBTLiBkZSBSLkwuMScwJQYDVQQLDB5UcnVzdENvciBDZXJ0aWZpY2F0ZSBBdXRob3Jp +dHkxHzAdBgNVBAMMFlRydXN0Q29yIFJvb3RDZXJ0IENBLTEwHhcNMTYwMjA0MTIzMjE2WhcNMjkx +MjMxMTcyMzE2WjCBpDELMAkGA1UEBhMCUEExDzANBgNVBAgMBlBhbmFtYTEUMBIGA1UEBwwLUGFu +YW1hIENpdHkxJDAiBgNVBAoMG1RydXN0Q29yIFN5c3RlbXMgUy4gZGUgUi5MLjEnMCUGA1UECwwe +VHJ1c3RDb3IgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MR8wHQYDVQQDDBZUcnVzdENvciBSb290Q2Vy +dCBDQS0xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv463leLCJhJrMxnHQFgKq1mq +jQCj/IDHUHuO1CAmujIS2CNUSSUQIpidRtLByZ5OGy4sDjjzGiVoHKZaBeYei0i/mJZ0PmnK6bV4 +pQa81QBeCQryJ3pS/C3Vseq0iWEk8xoT26nPUu0MJLq5nux+AHT6k61sKZKuUbS701e/s/OojZz0 +JEsq1pme9J7+wH5COucLlVPat2gOkEz7cD+PSiyU8ybdY2mplNgQTsVHCJCZGxdNuWxu72CVEY4h +gLW9oHPY0LJ3xEXqWib7ZnZ2+AYfYW0PVcWDtxBWcgYHpfOxGgMFZA6dWorWhnAbJN7+KIor0Gqw +/Hqi3LJ5DotlDwIDAQABo2MwYTAdBgNVHQ4EFgQU7mtJPHo/DeOxCbeKyKsZn3MzUOcwHwYDVR0j +BBgwFoAU7mtJPHo/DeOxCbeKyKsZn3MzUOcwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC +AYYwDQYJKoZIhvcNAQELBQADggEBACUY1JGPE+6PHh0RU9otRCkZoB5rMZ5NDp6tPVxBb5UrJKF5 +mDo4Nvu7Zp5I/5CQ7z3UuJu0h3U/IJvOcs+hVcFNZKIZBqEHMwwLKeXx6quj7LUKdJDHfXLy11yf +ke+Ri7fc7Waiz45mO7yfOgLgJ90WmMCV1Aqk5IGadZQ1nJBfiDcGrVmVCrDRZ9MZyonnMlo2HD6C +qFqTvsbQZJG2z9m2GM/bftJlo6bEjhcxwft+dtvTheNYsnd6djtsL1Ac59v2Z3kf9YKVmgenFK+P +3CghZwnS1k1aHBkcjndcw5QkPTJrS37UeJSDvjdNzl/HHk484IkzlQsPpTLWPFp5LBk= +-----END CERTIFICATE----- + +TrustCor RootCert CA-2 +====================== +-----BEGIN CERTIFICATE----- +MIIGLzCCBBegAwIBAgIIJaHfyjPLWQIwDQYJKoZIhvcNAQELBQAwgaQxCzAJBgNVBAYTAlBBMQ8w +DQYDVQQIDAZQYW5hbWExFDASBgNVBAcMC1BhbmFtYSBDaXR5MSQwIgYDVQQKDBtUcnVzdENvciBT +eXN0ZW1zIFMuIGRlIFIuTC4xJzAlBgNVBAsMHlRydXN0Q29yIENlcnRpZmljYXRlIEF1dGhvcml0 +eTEfMB0GA1UEAwwWVHJ1c3RDb3IgUm9vdENlcnQgQ0EtMjAeFw0xNjAyMDQxMjMyMjNaFw0zNDEy +MzExNzI2MzlaMIGkMQswCQYDVQQGEwJQQTEPMA0GA1UECAwGUGFuYW1hMRQwEgYDVQQHDAtQYW5h +bWEgQ2l0eTEkMCIGA1UECgwbVHJ1c3RDb3IgU3lzdGVtcyBTLiBkZSBSLkwuMScwJQYDVQQLDB5U +cnVzdENvciBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxHzAdBgNVBAMMFlRydXN0Q29yIFJvb3RDZXJ0 +IENBLTIwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCnIG7CKqJiJJWQdsg4foDSq8Gb +ZQWU9MEKENUCrO2fk8eHyLAnK0IMPQo+QVqedd2NyuCb7GgypGmSaIwLgQ5WoD4a3SwlFIIvl9Nk +RvRUqdw6VC0xK5mC8tkq1+9xALgxpL56JAfDQiDyitSSBBtlVkxs1Pu2YVpHI7TYabS3OtB0PAx1 +oYxOdqHp2yqlO/rOsP9+aij9JxzIsekp8VduZLTQwRVtDr4uDkbIXvRR/u8OYzo7cbrPb1nKDOOb +XUm4TOJXsZiKQlecdu/vvdFoqNL0Cbt3Nb4lggjEFixEIFapRBF37120Hapeaz6LMvYHL1cEksr1 +/p3C6eizjkxLAjHZ5DxIgif3GIJ2SDpxsROhOdUuxTTCHWKF3wP+TfSvPd9cW436cOGlfifHhi5q +jxLGhF5DUVCcGZt45vz27Ud+ez1m7xMTiF88oWP7+ayHNZ/zgp6kPwqcMWmLmaSISo5uZk3vFsQP +eSghYA2FFn3XVDjxklb9tTNMg9zXEJ9L/cb4Qr26fHMC4P99zVvh1Kxhe1fVSntb1IVYJ12/+Ctg +rKAmrhQhJ8Z3mjOAPF5GP/fDsaOGM8boXg25NSyqRsGFAnWAoOsk+xWq5Gd/bnc/9ASKL3x74xdh +8N0JqSDIvgmk0H5Ew7IwSjiqqewYmgeCK9u4nBit2uBGF6zPXQIDAQABo2MwYTAdBgNVHQ4EFgQU +2f4hQG6UnrybPZx9mCAZ5YwwYrIwHwYDVR0jBBgwFoAU2f4hQG6UnrybPZx9mCAZ5YwwYrIwDwYD +VR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAYYwDQYJKoZIhvcNAQELBQADggIBAJ5Fngw7tu/h +Osh80QA9z+LqBrWyOrsGS2h60COXdKcs8AjYeVrXWoSK2BKaG9l9XE1wxaX5q+WjiYndAfrs3fnp +kpfbsEZC89NiqpX+MWcUaViQCqoL7jcjx1BRtPV+nuN79+TMQjItSQzL/0kMmx40/W5ulop5A7Zv +2wnL/V9lFDfhOPXzYRZY5LVtDQsEGz9QLX+zx3oaFoBg+Iof6Rsqxvm6ARppv9JYx1RXCI/hOWB3 +S6xZhBqI8d3LT3jX5+EzLfzuQfogsL7L9ziUwOHQhQ+77Sxzq+3+knYaZH9bDTMJBzN7Bj8RpFxw +PIXAz+OQqIN3+tvmxYxoZxBnpVIt8MSZj3+/0WvitUfW2dCFmU2Umw9Lje4AWkcdEQOsQRivh7dv +DDqPys/cA8GiCcjl/YBeyGBCARsaU1q7N6a3vLqE6R5sGtRk2tRD/pOLS/IseRYQ1JMLiI+h2IYU +RpFHmygk71dSTlxCnKr3Sewn6EAes6aJInKc9Q0ztFijMDvd1GpUk74aTfOTlPf8hAs/hCBcNANE +xdqtvArBAs8e5ZTZ845b2EzwnexhF7sUMlQMAimTHpKG9n/v55IFDlndmQguLvqcAFLTxWYp5KeX +RKQOKIETNcX2b2TmQcTVL8w0RSXPQQCWPUouwpaYT05KnJe32x+SMsj/D1Fu1uwJ +-----END CERTIFICATE----- + +TrustCor ECA-1 +============== +-----BEGIN CERTIFICATE----- +MIIEIDCCAwigAwIBAgIJAISCLF8cYtBAMA0GCSqGSIb3DQEBCwUAMIGcMQswCQYDVQQGEwJQQTEP +MA0GA1UECAwGUGFuYW1hMRQwEgYDVQQHDAtQYW5hbWEgQ2l0eTEkMCIGA1UECgwbVHJ1c3RDb3Ig +U3lzdGVtcyBTLiBkZSBSLkwuMScwJQYDVQQLDB5UcnVzdENvciBDZXJ0aWZpY2F0ZSBBdXRob3Jp +dHkxFzAVBgNVBAMMDlRydXN0Q29yIEVDQS0xMB4XDTE2MDIwNDEyMzIzM1oXDTI5MTIzMTE3Mjgw +N1owgZwxCzAJBgNVBAYTAlBBMQ8wDQYDVQQIDAZQYW5hbWExFDASBgNVBAcMC1BhbmFtYSBDaXR5 +MSQwIgYDVQQKDBtUcnVzdENvciBTeXN0ZW1zIFMuIGRlIFIuTC4xJzAlBgNVBAsMHlRydXN0Q29y +IENlcnRpZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAwwOVHJ1c3RDb3IgRUNBLTEwggEiMA0GCSqG +SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPj+ARtZ+odnbb3w9U73NjKYKtR8aja+3+XzP4Q1HpGjOR +MRegdMTUpwHmspI+ap3tDvl0mEDTPwOABoJA6LHip1GnHYMma6ve+heRK9jGrB6xnhkB1Zem6g23 +xFUfJ3zSCNV2HykVh0A53ThFEXXQmqc04L/NyFIduUd+Dbi7xgz2c1cWWn5DkR9VOsZtRASqnKmc +p0yJF4OuowReUoCLHhIlERnXDH19MURB6tuvsBzvgdAsxZohmz3tQjtQJvLsznFhBmIhVE5/wZ0+ +fyCMgMsq2JdiyIMzkX2woloPV+g7zPIlstR8L+xNxqE6FXrntl019fZISjZFZtS6mFjBAgMBAAGj +YzBhMB0GA1UdDgQWBBREnkj1zG1I1KBLf/5ZJC+Dl5mahjAfBgNVHSMEGDAWgBREnkj1zG1I1KBL +f/5ZJC+Dl5mahjAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsF +AAOCAQEABT41XBVwm8nHc2FvcivUwo/yQ10CzsSUuZQRg2dd4mdsdXa/uwyqNsatR5Nj3B5+1t4u +/ukZMjgDfxT2AHMsWbEhBuH7rBiVDKP/mZb3Kyeb1STMHd3BOuCYRLDE5D53sXOpZCz2HAF8P11F +hcCF5yWPldwX8zyfGm6wyuMdKulMY/okYWLW2n62HGz1Ah3UKt1VkOsqEUc8Ll50soIipX1TH0Xs +J5F95yIW6MBoNtjG8U+ARDL54dHRHareqKucBK+tIA5kmE2la8BIWJZpTdwHjFGTot+fDz2LYLSC +jaoITmJF4PkL0uDgPFveXHEnJcLmA4GLEFPjx1WitJ/X5g== +-----END CERTIFICATE----- + +SSL.com Root Certification Authority RSA +======================================== +-----BEGIN CERTIFICATE----- +MIIF3TCCA8WgAwIBAgIIeyyb0xaAMpkwDQYJKoZIhvcNAQELBQAwfDELMAkGA1UEBhMCVVMxDjAM +BgNVBAgMBVRleGFzMRAwDgYDVQQHDAdIb3VzdG9uMRgwFgYDVQQKDA9TU0wgQ29ycG9yYXRpb24x +MTAvBgNVBAMMKFNTTC5jb20gUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSBSU0EwHhcNMTYw +MjEyMTczOTM5WhcNNDEwMjEyMTczOTM5WjB8MQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMx +EDAOBgNVBAcMB0hvdXN0b24xGDAWBgNVBAoMD1NTTCBDb3Jwb3JhdGlvbjExMC8GA1UEAwwoU1NM +LmNvbSBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IFJTQTCCAiIwDQYJKoZIhvcNAQEBBQAD +ggIPADCCAgoCggIBAPkP3aMrfcvQKv7sZ4Wm5y4bunfh4/WvpOz6Sl2RxFdHaxh3a3by/ZPkPQ/C +Fp4LZsNWlJ4Xg4XOVu/yFv0AYvUiCVToZRdOQbngT0aXqhvIuG5iXmmxX9sqAn78bMrzQdjt0Oj8 +P2FI7bADFB0QDksZ4LtO7IZl/zbzXmcCC52GVWH9ejjt/uIZALdvoVBidXQ8oPrIJZK0bnoix/ge +oeOy3ZExqysdBP+lSgQ36YWkMyv94tZVNHwZpEpox7Ko07fKoZOI68GXvIz5HdkihCR0xwQ9aqkp +k8zruFvh/l8lqjRYyMEjVJ0bmBHDOJx+PYZspQ9AhnwC9FwCTyjLrnGfDzrIM/4RJTXq/LrFYD3Z +fBjVsqnTdXgDciLKOsMf7yzlLqn6niy2UUb9rwPW6mBo6oUWNmuF6R7As93EJNyAKoFBbZQ+yODJ +gUEAnl6/f8UImKIYLEJAs/lvOCdLToD0PYFH4Ih86hzOtXVcUS4cK38acijnALXRdMbX5J+tB5O2 +UzU1/Dfkw/ZdFr4hc96SCvigY2q8lpJqPvi8ZVWb3vUNiSYE/CUapiVpy8JtynziWV+XrOvvLsi8 +1xtZPCvM8hnIk2snYxnP/Okm+Mpxm3+T/jRnhE6Z6/yzeAkzcLpmpnbtG3PrGqUNxCITIJRWCk4s +bE6x/c+cCbqiM+2HAgMBAAGjYzBhMB0GA1UdDgQWBBTdBAkHovV6fVJTEpKV7jiAJQ2mWTAPBgNV +HRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFN0ECQei9Xp9UlMSkpXuOIAlDaZZMA4GA1UdDwEB/wQE +AwIBhjANBgkqhkiG9w0BAQsFAAOCAgEAIBgRlCn7Jp0cHh5wYfGVcpNxJK1ok1iOMq8bs3AD/CUr +dIWQPXhq9LmLpZc7tRiRux6n+UBbkflVma8eEdBcHadm47GUBwwyOabqG7B52B2ccETjit3E+ZUf +ijhDPwGFpUenPUayvOUiaPd7nNgsPgohyC0zrL/FgZkxdMF1ccW+sfAjRfSda/wZY52jvATGGAsl +u1OJD7OAUN5F7kR/q5R4ZJjT9ijdh9hwZXT7DrkT66cPYakylszeu+1jTBi7qUD3oFRuIIhxdRjq +erQ0cuAjJ3dctpDqhiVAq+8zD8ufgr6iIPv2tS0a5sKFsXQP+8hlAqRSAUfdSSLBv9jra6x+3uxj +MxW3IwiPxg+NQVrdjsW5j+VFP3jbutIbQLH+cU0/4IGiul607BXgk90IH37hVZkLId6Tngr75qNJ +vTYw/ud3sqB1l7UtgYgXZSD32pAAn8lSzDLKNXz1PQ/YK9f1JmzJBjSWFupwWRoyeXkLtoh/D1JI +Pb9s2KJELtFOt3JY04kTlf5Eq/jXixtunLwsoFvVagCvXzfh1foQC5ichucmj87w7G6KVwuA406y +wKBjYZC6VWg3dGq2ktufoYYitmUnDuy2n0Jg5GfCtdpBC8TTi2EbvPofkSvXRAdeuims2cXp71NI +WuuA8ShYIc2wBlX7Jz9TkHCpBB5XJ7k= +-----END CERTIFICATE----- + +SSL.com Root Certification Authority ECC +======================================== +-----BEGIN CERTIFICATE----- +MIICjTCCAhSgAwIBAgIIdebfy8FoW6gwCgYIKoZIzj0EAwIwfDELMAkGA1UEBhMCVVMxDjAMBgNV +BAgMBVRleGFzMRAwDgYDVQQHDAdIb3VzdG9uMRgwFgYDVQQKDA9TU0wgQ29ycG9yYXRpb24xMTAv +BgNVBAMMKFNTTC5jb20gUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSBFQ0MwHhcNMTYwMjEy +MTgxNDAzWhcNNDEwMjEyMTgxNDAzWjB8MQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMxEDAO +BgNVBAcMB0hvdXN0b24xGDAWBgNVBAoMD1NTTCBDb3Jwb3JhdGlvbjExMC8GA1UEAwwoU1NMLmNv +bSBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IEVDQzB2MBAGByqGSM49AgEGBSuBBAAiA2IA +BEVuqVDEpiM2nl8ojRfLliJkP9x6jh3MCLOicSS6jkm5BBtHllirLZXI7Z4INcgn64mMU1jrYor+ +8FsPazFSY0E7ic3s7LaNGdM0B9y7xgZ/wkWV7Mt/qCPgCemB+vNH06NjMGEwHQYDVR0OBBYEFILR +hXMw5zUE044CkvvlpNHEIejNMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUgtGFczDnNQTT +jgKS++Wk0cQh6M0wDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA2cAMGQCMG/n61kRpGDPYbCW +e+0F+S8Tkdzt5fxQaxFGRrMcIQBiu77D5+jNB5n5DQtdcj7EqgIwH7y6C+IwJPt8bYBVCpk+gA0z +5Wajs6O7pdWLjwkspl1+4vAHCGht0nxpbl/f5Wpl +-----END CERTIFICATE----- + +SSL.com EV Root Certification Authority RSA R2 +============================================== +-----BEGIN CERTIFICATE----- +MIIF6zCCA9OgAwIBAgIIVrYpzTS8ePYwDQYJKoZIhvcNAQELBQAwgYIxCzAJBgNVBAYTAlVTMQ4w +DAYDVQQIDAVUZXhhczEQMA4GA1UEBwwHSG91c3RvbjEYMBYGA1UECgwPU1NMIENvcnBvcmF0aW9u +MTcwNQYDVQQDDC5TU0wuY29tIEVWIFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgUlNBIFIy +MB4XDTE3MDUzMTE4MTQzN1oXDTQyMDUzMDE4MTQzN1owgYIxCzAJBgNVBAYTAlVTMQ4wDAYDVQQI +DAVUZXhhczEQMA4GA1UEBwwHSG91c3RvbjEYMBYGA1UECgwPU1NMIENvcnBvcmF0aW9uMTcwNQYD +VQQDDC5TU0wuY29tIEVWIFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgUlNBIFIyMIICIjAN +BgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAjzZlQOHWTcDXtOlG2mvqM0fNTPl9fb69LT3w23jh +hqXZuglXaO1XPqDQCEGD5yhBJB/jchXQARr7XnAjssufOePPxU7Gkm0mxnu7s9onnQqG6YE3Bf7w +cXHswxzpY6IXFJ3vG2fThVUCAtZJycxa4bH3bzKfydQ7iEGonL3Lq9ttewkfokxykNorCPzPPFTO +Zw+oz12WGQvE43LrrdF9HSfvkusQv1vrO6/PgN3B0pYEW3p+pKk8OHakYo6gOV7qd89dAFmPZiw+ +B6KjBSYRaZfqhbcPlgtLyEDhULouisv3D5oi53+aNxPN8k0TayHRwMwi8qFG9kRpnMphNQcAb9Zh +CBHqurj26bNg5U257J8UZslXWNvNh2n4ioYSA0e/ZhN2rHd9NCSFg83XqpyQGp8hLH94t2S42Oim +9HizVcuE0jLEeK6jj2HdzghTreyI/BXkmg3mnxp3zkyPuBQVPWKchjgGAGYS5Fl2WlPAApiiECto +RHuOec4zSnaqW4EWG7WK2NAAe15itAnWhmMOpgWVSbooi4iTsjQc2KRVbrcc0N6ZVTsj9CLg+Slm +JuwgUHfbSguPvuUCYHBBXtSuUDkiFCbLsjtzdFVHB3mBOagwE0TlBIqulhMlQg+5U8Sb/M3kHN48 ++qvWBkofZ6aYMBzdLNvcGJVXZsb/XItW9XcCAwEAAaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAfBgNV +HSMEGDAWgBT5YLvU49U09rj1BoAlp3PbRmmonjAdBgNVHQ4EFgQU+WC71OPVNPa49QaAJadz20Zp +qJ4wDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4ICAQBWs47LCp1Jjr+kxJG7ZhcFUZh1 +++VQLHqe8RT6q9OKPv+RKY9ji9i0qVQBDb6Thi/5Sm3HXvVX+cpVHBK+Rw82xd9qt9t1wkclf7nx +Y/hoLVUE0fKNsKTPvDxeH3jnpaAgcLAExbf3cqfeIg29MyVGjGSSJuM+LmOW2puMPfgYCdcDzH2G +guDKBAdRUNf/ktUM79qGn5nX67evaOI5JpS6aLe/g9Pqemc9YmeuJeVy6OLk7K4S9ksrPJ/psEDz +OFSz/bdoyNrGj1E8svuR3Bznm53htw1yj+KkxKl4+esUrMZDBcJlOSgYAsOCsp0FvmXtll9ldDz7 +CTUue5wT/RsPXcdtgTpWD8w74a8CLyKsRspGPKAcTNZEtF4uXBVmCeEmKf7GUmG6sXP/wwyc5Wxq +lD8UykAWlYTzWamsX0xhk23RO8yilQwipmdnRC652dKKQbNmC1r7fSOl8hqw/96bg5Qu0T/fkreR +rwU7ZcegbLHNYhLDkBvjJc40vG93drEQw/cFGsDWr3RiSBd3kmmQYRzelYB0VI8YHMPzA9C/pEN1 +hlMYegouCRw2n5H9gooiS9EOUCXdywMMF8mDAAhONU2Ki+3wApRmLER/y5UnlhetCTCstnEXbosX +9hwJ1C07mKVx01QT2WDz9UtmT/rx7iASjbSsV7FFY6GsdqnC+w== +-----END CERTIFICATE----- + +SSL.com EV Root Certification Authority ECC +=========================================== +-----BEGIN CERTIFICATE----- +MIIClDCCAhqgAwIBAgIILCmcWxbtBZUwCgYIKoZIzj0EAwIwfzELMAkGA1UEBhMCVVMxDjAMBgNV +BAgMBVRleGFzMRAwDgYDVQQHDAdIb3VzdG9uMRgwFgYDVQQKDA9TU0wgQ29ycG9yYXRpb24xNDAy +BgNVBAMMK1NTTC5jb20gRVYgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSBFQ0MwHhcNMTYw +MjEyMTgxNTIzWhcNNDEwMjEyMTgxNTIzWjB/MQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMx +EDAOBgNVBAcMB0hvdXN0b24xGDAWBgNVBAoMD1NTTCBDb3Jwb3JhdGlvbjE0MDIGA1UEAwwrU1NM +LmNvbSBFViBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IEVDQzB2MBAGByqGSM49AgEGBSuB +BAAiA2IABKoSR5CYG/vvw0AHgyBO8TCCogbR8pKGYfL2IWjKAMTH6kMAVIbc/R/fALhBYlzccBYy +3h+Z1MzFB8gIH2EWB1E9fVwHU+M1OIzfzZ/ZLg1KthkuWnBaBu2+8KGwytAJKaNjMGEwHQYDVR0O +BBYEFFvKXuXe0oGqzagtZFG22XKbl+ZPMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUW8pe +5d7SgarNqC1kUbbZcpuX5k8wDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA2gAMGUCMQCK5kCJ +N+vp1RPZytRrJPOwPYdGWBrssd9v+1a6cGvHOMzosYxPD/fxZ3YOg9AeUY8CMD32IygmTMZgh5Mm +m7I1HrrW9zzRHM76JTymGoEVW/MSD2zuZYrJh6j5B+BimoxcSg== +-----END CERTIFICATE----- + +GlobalSign Root CA - R6 +======================= +-----BEGIN CERTIFICATE----- +MIIFgzCCA2ugAwIBAgIORea7A4Mzw4VlSOb/RVEwDQYJKoZIhvcNAQEMBQAwTDEgMB4GA1UECxMX +R2xvYmFsU2lnbiBSb290IENBIC0gUjYxEzARBgNVBAoTCkdsb2JhbFNpZ24xEzARBgNVBAMTCkds +b2JhbFNpZ24wHhcNMTQxMjEwMDAwMDAwWhcNMzQxMjEwMDAwMDAwWjBMMSAwHgYDVQQLExdHbG9i +YWxTaWduIFJvb3QgQ0EgLSBSNjETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFs +U2lnbjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAJUH6HPKZvnsFMp7PPcNCPG0RQss +grRIxutbPK6DuEGSMxSkb3/pKszGsIhrxbaJ0cay/xTOURQh7ErdG1rG1ofuTToVBu1kZguSgMpE +3nOUTvOniX9PeGMIyBJQbUJmL025eShNUhqKGoC3GYEOfsSKvGRMIRxDaNc9PIrFsmbVkJq3MQbF +vuJtMgamHvm566qjuL++gmNQ0PAYid/kD3n16qIfKtJwLnvnvJO7bVPiSHyMEAc4/2ayd2F+4OqM +PKq0pPbzlUoSB239jLKJz9CgYXfIWHSw1CM69106yqLbnQneXUQtkPGBzVeS+n68UARjNN9rkxi+ +azayOeSsJDa38O+2HBNXk7besvjihbdzorg1qkXy4J02oW9UivFyVm4uiMVRQkQVlO6jxTiWm05O +WgtH8wY2SXcwvHE35absIQh1/OZhFj931dmRl4QKbNQCTXTAFO39OfuD8l4UoQSwC+n+7o/hbguy +CLNhZglqsQY6ZZZZwPA1/cnaKI0aEYdwgQqomnUdnjqGBQCe24DWJfncBZ4nWUx2OVvq+aWh2IMP +0f/fMBH5hc8zSPXKbWQULHpYT9NLCEnFlWQaYw55PfWzjMpYrZxCRXluDocZXFSxZba/jJvcE+kN +b7gu3GduyYsRtYQUigAZcIN5kZeR1BonvzceMgfYFGM8KEyvAgMBAAGjYzBhMA4GA1UdDwEB/wQE +AwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBSubAWjkxPioufi1xzWx/B/yGdToDAfBgNV +HSMEGDAWgBSubAWjkxPioufi1xzWx/B/yGdToDANBgkqhkiG9w0BAQwFAAOCAgEAgyXt6NH9lVLN +nsAEoJFp5lzQhN7craJP6Ed41mWYqVuoPId8AorRbrcWc+ZfwFSY1XS+wc3iEZGtIxg93eFyRJa0 +lV7Ae46ZeBZDE1ZXs6KzO7V33EByrKPrmzU+sQghoefEQzd5Mr6155wsTLxDKZmOMNOsIeDjHfrY +BzN2VAAiKrlNIC5waNrlU/yDXNOd8v9EDERm8tLjvUYAGm0CuiVdjaExUd1URhxN25mW7xocBFym +Fe944Hn+Xds+qkxV/ZoVqW/hpvvfcDDpw+5CRu3CkwWJ+n1jez/QcYF8AOiYrg54NMMl+68KnyBr +3TsTjxKM4kEaSHpzoHdpx7Zcf4LIHv5YGygrqGytXm3ABdJ7t+uA/iU3/gKbaKxCXcPu9czc8FB1 +0jZpnOZ7BN9uBmm23goJSFmH63sUYHpkqmlD75HHTOwY3WzvUy2MmeFe8nI+z1TIvWfspA9MRf/T +uTAjB0yPEL+GltmZWrSZVxykzLsViVO6LAUP5MSeGbEYNNVMnbrt9x+vJJUEeKgDu+6B5dpffItK +oZB0JaezPkvILFa9x8jvOOJckvB595yEunQtYQEgfn7R8k8HWV+LLUNS60YMlOH1Zkd5d9VUWx+t +JDfLRVpOoERIyNiwmcUVhAn21klJwGW45hpxbqCo8YLoRT5s1gLXCmeDBVrJpBA= +-----END CERTIFICATE----- + +OISTE WISeKey Global Root GC CA +=============================== +-----BEGIN CERTIFICATE----- +MIICaTCCAe+gAwIBAgIQISpWDK7aDKtARb8roi066jAKBggqhkjOPQQDAzBtMQswCQYDVQQGEwJD +SDEQMA4GA1UEChMHV0lTZUtleTEiMCAGA1UECxMZT0lTVEUgRm91bmRhdGlvbiBFbmRvcnNlZDEo +MCYGA1UEAxMfT0lTVEUgV0lTZUtleSBHbG9iYWwgUm9vdCBHQyBDQTAeFw0xNzA1MDkwOTQ4MzRa +Fw00MjA1MDkwOTU4MzNaMG0xCzAJBgNVBAYTAkNIMRAwDgYDVQQKEwdXSVNlS2V5MSIwIAYDVQQL +ExlPSVNURSBGb3VuZGF0aW9uIEVuZG9yc2VkMSgwJgYDVQQDEx9PSVNURSBXSVNlS2V5IEdsb2Jh +bCBSb290IEdDIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETOlQwMYPchi82PG6s4nieUqjFqdr +VCTbUf/q9Akkwwsin8tqJ4KBDdLArzHkdIJuyiXZjHWd8dvQmqJLIX4Wp2OQ0jnUsYd4XxiWD1Ab +NTcPasbc2RNNpI6QN+a9WzGRo1QwUjAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAd +BgNVHQ4EFgQUSIcUrOPDnpBgOtfKie7TrYy0UGYwEAYJKwYBBAGCNxUBBAMCAQAwCgYIKoZIzj0E +AwMDaAAwZQIwJsdpW9zV57LnyAyMjMPdeYwbY9XJUpROTYJKcx6ygISpJcBMWm1JKWB4E+J+SOtk +AjEA2zQgMgj/mkkCtojeFK9dbJlxjRo/i9fgojaGHAeCOnZT/cKi7e97sIBPWA9LUzm9 +-----END CERTIFICATE----- + +GTS Root R1 +=========== +-----BEGIN CERTIFICATE----- +MIIFWjCCA0KgAwIBAgIQbkepxUtHDA3sM9CJuRz04TANBgkqhkiG9w0BAQwFADBHMQswCQYDVQQG +EwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJv +b3QgUjEwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAwMDAwWjBHMQswCQYDVQQGEwJVUzEiMCAG +A1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwggIi +MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC2EQKLHuOhd5s73L+UPreVp0A8of2C+X0yBoJx +9vaMf/vo27xqLpeXo4xL+Sv2sfnOhB2x+cWX3u+58qPpvBKJXqeqUqv4IyfLpLGcY9vXmX7wCl7r +aKb0xlpHDU0QM+NOsROjyBhsS+z8CZDfnWQpJSMHobTSPS5g4M/SCYe7zUjwTcLCeoiKu7rPWRnW +r4+wB7CeMfGCwcDfLqZtbBkOtdh+JhpFAz2weaSUKK0PfyblqAj+lug8aJRT7oM6iCsVlgmy4HqM +LnXWnOunVmSPlk9orj2XwoSPwLxAwAtcvfaHszVsrBhQf4TgTM2S0yDpM7xSma8ytSmzJSq0SPly +4cpk9+aCEI3oncKKiPo4Zor8Y/kB+Xj9e1x3+naH+uzfsQ55lVe0vSbv1gHR6xYKu44LtcXFilWr +06zqkUspzBmkMiVOKvFlRNACzqrOSbTqn3yDsEB750Orp2yjj32JgfpMpf/VjsPOS+C12LOORc92 +wO1AK/1TD7Cn1TsNsYqiA94xrcx36m97PtbfkSIS5r762DL8EGMUUXLeXdYWk70paDPvOmbsB4om +3xPXV2V4J95eSRQAogB/mqghtqmxlbCluQ0WEdrHbEg8QOB+DVrNVjzRlwW5y0vtOUucxD/SVRNu +JLDWcfr0wbrM7Rv1/oFB2ACYPTrIrnqYNxgFlQIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYD +VR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU5K8rJnEaK0gnhS9SZizv8IkTcT4wDQYJKoZIhvcNAQEM +BQADggIBADiWCu49tJYeX++dnAsznyvgyv3SjgofQXSlfKqE1OXyHuY3UjKcC9FhHb8owbZEKTV1 +d5iyfNm9dKyKaOOpMQkpAWBz40d8U6iQSifvS9efk+eCNs6aaAyC58/UEBZvXw6ZXPYfcX3v73sv +fuo21pdwCxXu11xWajOl40k4DLh9+42FpLFZXvRq4d2h9mREruZRgyFmxhE+885H7pwoHyXa/6xm +ld01D1zvICxi/ZG6qcz8WpyTgYMpl0p8WnK0OdC3d8t5/Wk6kjftbjhlRn7pYL15iJdfOBL07q9b +gsiG1eGZbYwE8na6SfZu6W0eX6DvJ4J2QPim01hcDyxC2kLGe4g0x8HYRZvBPsVhHdljUEn2NIVq +4BjFbkerQUIpm/ZgDdIx02OYI5NaAIFItO/Nis3Jz5nu2Z6qNuFoS3FJFDYoOj0dzpqPJeaAcWEr +tXvM+SUWgeExX6GjfhaknBZqlxi9dnKlC54dNuYvoS++cJEPqOba+MSSQGwlfnuzCdyyF62ARPBo +pY+Udf90WuioAnwMCeKpSwughQtiue+hMZL77/ZRBIls6Kl0obsXs7X9SQ98POyDGCBDTtWTurQ0 +sR8WNh8M5mQ5Fkzc4P4dyKliPUDqysU0ArSuiYgzNdwsE3PYJ/HQcu51OyLemGhmW/HGY0dVHLql +CFF1pkgl +-----END CERTIFICATE----- + +GTS Root R2 +=========== +-----BEGIN CERTIFICATE----- +MIIFWjCCA0KgAwIBAgIQbkepxlqz5yDFMJo/aFLybzANBgkqhkiG9w0BAQwFADBHMQswCQYDVQQG +EwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJv +b3QgUjIwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAwMDAwWjBHMQswCQYDVQQGEwJVUzEiMCAG +A1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjIwggIi +MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDO3v2m++zsFDQ8BwZabFn3GTXd98GdVarTzTuk +k3LvCvptnfbwhYBboUhSnznFt+4orO/LdmgUud+tAWyZH8QiHZ/+cnfgLFuv5AS/T3KgGjSY6Dlo +7JUle3ah5mm5hRm9iYz+re026nO8/4Piy33B0s5Ks40FnotJk9/BW9BuXvAuMC6C/Pq8tBcKSOWI +m8Wba96wyrQD8Nr0kLhlZPdcTK3ofmZemde4wj7I0BOdre7kRXuJVfeKH2JShBKzwkCX44ofR5Gm +dFrS+LFjKBC4swm4VndAoiaYecb+3yXuPuWgf9RhD1FLPD+M2uFwdNjCaKH5wQzpoeJ/u1U8dgbu +ak7MkogwTZq9TwtImoS1mKPV+3PBV2HdKFZ1E66HjucMUQkQdYhMvI35ezzUIkgfKtzra7tEscsz +cTJGr61K8YzodDqs5xoic4DSMPclQsciOzsSrZYuxsN2B6ogtzVJV+mSSeh2FnIxZyuWfoqjx5RW +Ir9qS34BIbIjMt/kmkRtWVtd9QCgHJvGeJeNkP+byKq0rxFROV7Z+2et1VsRnTKaG73Vululycsl +aVNVJ1zgyjbLiGH7HrfQy+4W+9OmTN6SpdTi3/UGVN4unUu0kzCqgc7dGtxRcw1PcOnlthYhGXmy +5okLdWTK1au8CcEYof/UVKGFPP0UJAOyh9OktwIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYD +VR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUu//KjiOfT5nK2+JopqUVJxce2Q4wDQYJKoZIhvcNAQEM +BQADggIBALZp8KZ3/p7uC4Gt4cCpx/k1HUCCq+YEtN/L9x0Pg/B+E02NjO7jMyLDOfxA325BS0JT +vhaI8dI4XsRomRyYUpOM52jtG2pzegVATX9lO9ZY8c6DR2Dj/5epnGB3GFW1fgiTz9D2PGcDFWEJ ++YF59exTpJ/JjwGLc8R3dtyDovUMSRqodt6Sm2T4syzFJ9MHwAiApJiS4wGWAqoC7o87xdFtCjMw +c3i5T1QWvwsHoaRc5svJXISPD+AVdyx+Jn7axEvbpxZ3B7DNdehyQtaVhJ2Gg/LkkM0JR9SLA3Da +WsYDQvTtN6LwG1BUSw7YhN4ZKJmBR64JGz9I0cNv4rBgF/XuIwKl2gBbbZCr7qLpGzvpx0QnRY5r +n/WkhLx3+WuXrD5RRaIRpsyF7gpo8j5QOHokYh4XIDdtak23CZvJ/KRY9bb7nE4Yu5UC56Gtmwfu +Nmsk0jmGwZODUNKBRqhfYlcsu2xkiAhu7xNUX90txGdj08+JN7+dIPT7eoOboB6BAFDC5AwiWVIQ +7UNWhwD4FFKnHYuTjKJNRn8nxnGbJN7k2oaLDX5rIMHAnuFl2GqjpuiFizoHCBy69Y9Vmhh1fuXs +gWbRIXOhNUQLgD1bnF5vKheW0YMjiGZt5obicDIvUiLnyOd/xCxgXS/Dr55FBcOEArf9LAhST4Ld +o/DUhgkC +-----END CERTIFICATE----- + +GTS Root R3 +=========== +-----BEGIN CERTIFICATE----- +MIICDDCCAZGgAwIBAgIQbkepx2ypcyRAiQ8DVd2NHTAKBggqhkjOPQQDAzBHMQswCQYDVQQGEwJV +UzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3Qg +UjMwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAwMDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UE +ChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjMwdjAQBgcq +hkjOPQIBBgUrgQQAIgNiAAQfTzOHMymKoYTey8chWEGJ6ladK0uFxh1MJ7x/JlFyb+Kf1qPKzEUU +Rout736GjOyxfi//qXGdGIRFBEFVbivqJn+7kAHjSxm65FSWRQmx1WyRRK2EE46ajA2ADDL24Cej +QjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTB8Sa6oC2uhYHP +0/EqEr24Cmf9vDAKBggqhkjOPQQDAwNpADBmAjEAgFukfCPAlaUs3L6JbyO5o91lAFJekazInXJ0 +glMLfalAvWhgxeG4VDvBNhcl2MG9AjEAnjWSdIUlUfUk7GRSJFClH9voy8l27OyCbvWFGFPouOOa +KaqW04MjyaR7YbPMAuhd +-----END CERTIFICATE----- + +GTS Root R4 +=========== +-----BEGIN CERTIFICATE----- +MIICCjCCAZGgAwIBAgIQbkepyIuUtui7OyrYorLBmTAKBggqhkjOPQQDAzBHMQswCQYDVQQGEwJV +UzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3Qg +UjQwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAwMDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UE +ChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjQwdjAQBgcq +hkjOPQIBBgUrgQQAIgNiAATzdHOnaItgrkO4NcWBMHtLSZ37wWHO5t5GvWvVYRg1rkDdc/eJkTBa +6zzuhXyiQHY7qca4R9gq55KRanPpsXI5nymfopjTX15YhmUPoYRlBtHci8nHc8iMai/lxKvRHYqj +QjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBSATNbrdP9JNqPV +2Py1PsVq8JQdjDAKBggqhkjOPQQDAwNnADBkAjBqUFJ0CMRw3J5QdCHojXohw0+WbhXRIjVhLfoI +N+4Zba3bssx9BzT1YBkstTTZbyACMANxsbqjYAuG7ZoIapVon+Kz4ZNkfF6Tpt95LY2F45TPI11x +zPKwTdb+mciUqXWi4w== +-----END CERTIFICATE----- + +UCA Global G2 Root +================== +-----BEGIN CERTIFICATE----- +MIIFRjCCAy6gAwIBAgIQXd+x2lqj7V2+WmUgZQOQ7zANBgkqhkiG9w0BAQsFADA9MQswCQYDVQQG +EwJDTjERMA8GA1UECgwIVW5pVHJ1c3QxGzAZBgNVBAMMElVDQSBHbG9iYWwgRzIgUm9vdDAeFw0x +NjAzMTEwMDAwMDBaFw00MDEyMzEwMDAwMDBaMD0xCzAJBgNVBAYTAkNOMREwDwYDVQQKDAhVbmlU +cnVzdDEbMBkGA1UEAwwSVUNBIEdsb2JhbCBHMiBSb290MIICIjANBgkqhkiG9w0BAQEFAAOCAg8A +MIICCgKCAgEAxeYrb3zvJgUno4Ek2m/LAfmZmqkywiKHYUGRO8vDaBsGxUypK8FnFyIdK+35KYmT +oni9kmugow2ifsqTs6bRjDXVdfkX9s9FxeV67HeToI8jrg4aA3++1NDtLnurRiNb/yzmVHqUwCoV +8MmNsHo7JOHXaOIxPAYzRrZUEaalLyJUKlgNAQLx+hVRZ2zA+te2G3/RVogvGjqNO7uCEeBHANBS +h6v7hn4PJGtAnTRnvI3HLYZveT6OqTwXS3+wmeOwcWDcC/Vkw85DvG1xudLeJ1uK6NjGruFZfc8o +LTW4lVYa8bJYS7cSN8h8s+1LgOGN+jIjtm+3SJUIsUROhYw6AlQgL9+/V087OpAh18EmNVQg7Mc/ +R+zvWr9LesGtOxdQXGLYD0tK3Cv6brxzks3sx1DoQZbXqX5t2Okdj4q1uViSukqSKwxW/YDrCPBe +KW4bHAyvj5OJrdu9o54hyokZ7N+1wxrrFv54NkzWbtA+FxyQF2smuvt6L78RHBgOLXMDj6DlNaBa +4kx1HXHhOThTeEDMg5PXCp6dW4+K5OXgSORIskfNTip1KnvyIvbJvgmRlld6iIis7nCs+dwp4wwc +OxJORNanTrAmyPPZGpeRaOrvjUYG0lZFWJo8DA+DuAUlwznPO6Q0ibd5Ei9Hxeepl2n8pndntd97 +8XplFeRhVmUCAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0O +BBYEFIHEjMz15DD/pQwIX4wVZyF0Ad/fMA0GCSqGSIb3DQEBCwUAA4ICAQATZSL1jiutROTL/7lo +5sOASD0Ee/ojL3rtNtqyzm325p7lX1iPyzcyochltq44PTUbPrw7tgTQvPlJ9Zv3hcU2tsu8+Mg5 +1eRfB70VVJd0ysrtT7q6ZHafgbiERUlMjW+i67HM0cOU2kTC5uLqGOiiHycFutfl1qnN3e92mI0A +Ds0b+gO3joBYDic/UvuUospeZcnWhNq5NXHzJsBPd+aBJ9J3O5oUb3n09tDh05S60FdRvScFDcH9 +yBIw7m+NESsIndTUv4BFFJqIRNow6rSn4+7vW4LVPtateJLbXDzz2K36uGt/xDYotgIVilQsnLAX +c47QN6MUPJiVAAwpBVueSUmxX8fjy88nZY41F7dXyDDZQVu5FLbowg+UMaeUmMxq67XhJ/UQqAHo +jhJi6IjMtX9Gl8CbEGY4GjZGXyJoPd/JxhMnq1MGrKI8hgZlb7F+sSlEmqO6SWkoaY/X5V+tBIZk +bxqgDMUIYs6Ao9Dz7GjevjPHF1t/gMRMTLGmhIrDO7gJzRSBuhjjVFc2/tsvfEehOjPI+Vg7RE+x +ygKJBJYoaMVLuCaJu9YzL1DV/pqJuhgyklTGW+Cd+V7lDSKb9triyCGyYiGqhkCyLmTTX8jjfhFn +RR8F/uOi77Oos/N9j/gMHyIfLXC0uAE0djAA5SN4p1bXUB+K+wb1whnw0A== +-----END CERTIFICATE----- + +UCA Extended Validation Root +============================ +-----BEGIN CERTIFICATE----- +MIIFWjCCA0KgAwIBAgIQT9Irj/VkyDOeTzRYZiNwYDANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQG +EwJDTjERMA8GA1UECgwIVW5pVHJ1c3QxJTAjBgNVBAMMHFVDQSBFeHRlbmRlZCBWYWxpZGF0aW9u +IFJvb3QwHhcNMTUwMzEzMDAwMDAwWhcNMzgxMjMxMDAwMDAwWjBHMQswCQYDVQQGEwJDTjERMA8G +A1UECgwIVW5pVHJ1c3QxJTAjBgNVBAMMHFVDQSBFeHRlbmRlZCBWYWxpZGF0aW9uIFJvb3QwggIi +MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCpCQcoEwKwmeBkqh5DFnpzsZGgdT6o+uM4AHrs +iWogD4vFsJszA1qGxliG1cGFu0/GnEBNyr7uaZa4rYEwmnySBesFK5pI0Lh2PpbIILvSsPGP2KxF +Rv+qZ2C0d35qHzwaUnoEPQc8hQ2E0B92CvdqFN9y4zR8V05WAT558aopO2z6+I9tTcg1367r3CTu +eUWnhbYFiN6IXSV8l2RnCdm/WhUFhvMJHuxYMjMR83dksHYf5BA1FxvyDrFspCqjc/wJHx4yGVMR +59mzLC52LqGj3n5qiAno8geK+LLNEOfic0CTuwjRP+H8C5SzJe98ptfRr5//lpr1kXuYC3fUfugH +0mK1lTnj8/FtDw5lhIpjVMWAtuCeS31HJqcBCF3RiJ7XwzJE+oJKCmhUfzhTA8ykADNkUVkLo4KR +el7sFsLzKuZi2irbWWIQJUoqgQtHB0MGcIfS+pMRKXpITeuUx3BNr2fVUbGAIAEBtHoIppB/TuDv +B0GHr2qlXov7z1CymlSvw4m6WC31MJixNnI5fkkE/SmnTHnkBVfblLkWU41Gsx2VYVdWf6/wFlth +WG82UBEL2KwrlRYaDh8IzTY0ZRBiZtWAXxQgXy0MoHgKaNYs1+lvK9JKBZP8nm9rZ/+I8U6laUpS +NwXqxhaN0sSZ0YIrO7o1dfdRUVjzyAfd5LQDfwIDAQABo0IwQDAdBgNVHQ4EFgQU2XQ65DA9DfcS +3H5aBZ8eNJr34RQwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAYYwDQYJKoZIhvcNAQEL +BQADggIBADaNl8xCFWQpN5smLNb7rhVpLGsaGvdftvkHTFnq88nIua7Mui563MD1sC3AO6+fcAUR +ap8lTwEpcOPlDOHqWnzcSbvBHiqB9RZLcpHIojG5qtr8nR/zXUACE/xOHAbKsxSQVBcZEhrxH9cM +aVr2cXj0lH2RC47skFSOvG+hTKv8dGT9cZr4QQehzZHkPJrgmzI5c6sq1WnIeJEmMX3ixzDx/BR4 +dxIOE/TdFpS/S2d7cFOFyrC78zhNLJA5wA3CXWvp4uXViI3WLL+rG761KIcSF3Ru/H38j9CHJrAb ++7lsq+KePRXBOy5nAliRn+/4Qh8st2j1da3Ptfb/EX3C8CSlrdP6oDyp+l3cpaDvRKS+1ujl5BOW +F3sGPjLtx7dCvHaj2GU4Kzg1USEODm8uNBNA4StnDG1KQTAYI1oyVZnJF+A83vbsea0rWBmirSwi +GpWOvpaQXUJXxPkUAzUrHC1RVwinOt4/5Mi0A3PCwSaAuwtCH60NryZy2sy+s6ODWA2CxR9GUeOc +GMyNm43sSet1UNWMKFnKdDTajAshqx7qG+XH/RU+wBeq+yNuJkbL+vmxcmtpzyKEC2IPrNkZAJSi +djzULZrtBJ4tBmIQN1IchXIbJ+XMxjHsN+xjWZsLHXbMfjKaiJUINlK73nZfdklJrX+9ZSCyycEr +dhh2n1ax +-----END CERTIFICATE----- + +Certigna Root CA +================ +-----BEGIN CERTIFICATE----- +MIIGWzCCBEOgAwIBAgIRAMrpG4nxVQMNo+ZBbcTjpuEwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE +BhMCRlIxEjAQBgNVBAoMCURoaW15b3RpczEcMBoGA1UECwwTMDAwMiA0ODE0NjMwODEwMDAzNjEZ +MBcGA1UEAwwQQ2VydGlnbmEgUm9vdCBDQTAeFw0xMzEwMDEwODMyMjdaFw0zMzEwMDEwODMyMjda +MFoxCzAJBgNVBAYTAkZSMRIwEAYDVQQKDAlEaGlteW90aXMxHDAaBgNVBAsMEzAwMDIgNDgxNDYz +MDgxMDAwMzYxGTAXBgNVBAMMEENlcnRpZ25hIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4IC +DwAwggIKAoICAQDNGDllGlmx6mQWDoyUJJV8g9PFOSbcDO8WV43X2KyjQn+Cyu3NW9sOty3tRQgX +stmzy9YXUnIo245Onoq2C/mehJpNdt4iKVzSs9IGPjA5qXSjklYcoW9MCiBtnyN6tMbaLOQdLNyz +KNAT8kxOAkmhVECe5uUFoC2EyP+YbNDrihqECB63aCPuI9Vwzm1RaRDuoXrC0SIxwoKF0vJVdlB8 +JXrJhFwLrN1CTivngqIkicuQstDuI7pmTLtipPlTWmR7fJj6o0ieD5Wupxj0auwuA0Wv8HT4Ks16 +XdG+RCYyKfHx9WzMfgIhC59vpD++nVPiz32pLHxYGpfhPTc3GGYo0kDFUYqMwy3OU4gkWGQwFsWq +4NYKpkDfePb1BHxpE4S80dGnBs8B92jAqFe7OmGtBIyT46388NtEbVncSVmurJqZNjBBe3YzIoej +wpKGbvlw7q6Hh5UbxHq9MfPU0uWZ/75I7HX1eBYdpnDBfzwboZL7z8g81sWTCo/1VTp2lc5ZmIoJ +lXcymoO6LAQ6l73UL77XbJuiyn1tJslV1c/DeVIICZkHJC1kJWumIWmbat10TWuXekG9qxf5kBdI +jzb5LdXF2+6qhUVB+s06RbFo5jZMm5BX7CO5hwjCxAnxl4YqKE3idMDaxIzb3+KhF1nOJFl0Mdp/ +/TBt2dzhauH8XwIDAQABo4IBGjCCARYwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYw +HQYDVR0OBBYEFBiHVuBud+4kNTxOc5of1uHieX4rMB8GA1UdIwQYMBaAFBiHVuBud+4kNTxOc5of +1uHieX4rMEQGA1UdIAQ9MDswOQYEVR0gADAxMC8GCCsGAQUFBwIBFiNodHRwczovL3d3d3cuY2Vy +dGlnbmEuZnIvYXV0b3JpdGVzLzBtBgNVHR8EZjBkMC+gLaArhilodHRwOi8vY3JsLmNlcnRpZ25h +LmZyL2NlcnRpZ25hcm9vdGNhLmNybDAxoC+gLYYraHR0cDovL2NybC5kaGlteW90aXMuY29tL2Nl +cnRpZ25hcm9vdGNhLmNybDANBgkqhkiG9w0BAQsFAAOCAgEAlLieT/DjlQgi581oQfccVdV8AOIt +OoldaDgvUSILSo3L6btdPrtcPbEo/uRTVRPPoZAbAh1fZkYJMyjhDSSXcNMQH+pkV5a7XdrnxIxP +TGRGHVyH41neQtGbqH6mid2PHMkwgu07nM3A6RngatgCdTer9zQoKJHyBApPNeNgJgH60BGM+RFq +7q89w1DTj18zeTyGqHNFkIwgtnJzFyO+B2XleJINugHA64wcZr+shncBlA2c5uk5jR+mUYyZDDl3 +4bSb+hxnV29qao6pK0xXeXpXIs/NX2NGjVxZOob4Mkdio2cNGJHc+6Zr9UhhcyNZjgKnvETq9Emd +8VRY+WCv2hikLyhF3HqgiIZd8zvn/yk1gPxkQ5Tm4xxvvq0OKmOZK8l+hfZx6AYDlf7ej0gcWtSS +6Cvu5zHbugRqh5jnxV/vfaci9wHYTfmJ0A6aBVmknpjZbyvKcL5kwlWj9Omvw5Ip3IgWJJk8jSaY +tlu3zM63Nwf9JtmYhST/WSMDmu2dnajkXjjO11INb9I/bbEFa0nOipFGc/T2L/Coc3cOZayhjWZS +aX5LaAzHHjcng6WMxwLkFM1JAbBzs/3GkDpv0mztO+7skb6iQ12LAEpmJURw3kAP+HwV96LOPNde +E4yBFxgX0b3xdxA61GU5wSesVywlVP+i2k+KYTlerj1KjL0= +-----END CERTIFICATE----- + +emSign Root CA - G1 +=================== +-----BEGIN CERTIFICATE----- +MIIDlDCCAnygAwIBAgIKMfXkYgxsWO3W2DANBgkqhkiG9w0BAQsFADBnMQswCQYDVQQGEwJJTjET +MBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl +ZDEcMBoGA1UEAxMTZW1TaWduIFJvb3QgQ0EgLSBHMTAeFw0xODAyMTgxODMwMDBaFw00MzAyMTgx +ODMwMDBaMGcxCzAJBgNVBAYTAklOMRMwEQYDVQQLEwplbVNpZ24gUEtJMSUwIwYDVQQKExxlTXVk +aHJhIFRlY2hub2xvZ2llcyBMaW1pdGVkMRwwGgYDVQQDExNlbVNpZ24gUm9vdCBDQSAtIEcxMIIB +IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk0u76WaK7p1b1TST0Bsew+eeuGQzf2N4aLTN +LnF115sgxk0pvLZoYIr3IZpWNVrzdr3YzZr/k1ZLpVkGoZM0Kd0WNHVO8oG0x5ZOrRkVUkr+PHB1 +cM2vK6sVmjM8qrOLqs1D/fXqcP/tzxE7lM5OMhbTI0Aqd7OvPAEsbO2ZLIvZTmmYsvePQbAyeGHW +DV/D+qJAkh1cF+ZwPjXnorfCYuKrpDhMtTk1b+oDafo6VGiFbdbyL0NVHpENDtjVaqSW0RM8LHhQ +6DqS0hdW5TUaQBw+jSztOd9C4INBdN+jzcKGYEho42kLVACL5HZpIQ15TjQIXhTCzLG3rdd8cIrH +hQIDAQABo0IwQDAdBgNVHQ4EFgQU++8Nhp6w492pufEhF38+/PB3KxowDgYDVR0PAQH/BAQDAgEG +MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAFn/8oz1h31xPaOfG1vR2vjTnGs2 +vZupYeveFix0PZ7mddrXuqe8QhfnPZHr5X3dPpzxz5KsbEjMwiI/aTvFthUvozXGaCocV685743Q +NcMYDHsAVhzNixl03r4PEuDQqqE/AjSxcM6dGNYIAwlG7mDgfrbESQRRfXBgvKqy/3lyeqYdPV8q ++Mri/Tm3R7nrft8EI6/6nAYH6ftjk4BAtcZsCjEozgyfz7MjNYBBjWzEN3uBL4ChQEKF6dk4jeih +U80Bv2noWgbyRQuQ+q7hv53yrlc8pa6yVvSLZUDp/TGBLPQ5Cdjua6e0ph0VpZj3AYHYhX3zUVxx +iN66zB+Afko= +-----END CERTIFICATE----- + +emSign ECC Root CA - G3 +======================= +-----BEGIN CERTIFICATE----- +MIICTjCCAdOgAwIBAgIKPPYHqWhwDtqLhDAKBggqhkjOPQQDAzBrMQswCQYDVQQGEwJJTjETMBEG +A1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg +MB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0gRzMwHhcNMTgwMjE4MTgzMDAwWhcNNDMwMjE4 +MTgzMDAwWjBrMQswCQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11 +ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0g +RzMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQjpQy4LRL1KPOxst3iAhKAnjlfSU2fySU0WXTsuwYc +58Byr+iuL+FBVIcUqEqy6HyC5ltqtdyzdc6LBtCGI79G1Y4PPwT01xySfvalY8L1X44uT6EYGQIr +MgqCZH0Wk9GjQjBAMB0GA1UdDgQWBBR8XQKEE9TMipuBzhccLikenEhjQjAOBgNVHQ8BAf8EBAMC +AQYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAwNpADBmAjEAvvNhzwIQHWSVB7gYboiFBS+D +CBeQyh+KTOgNG3qxrdWBCUfvO6wIBHxcmbHtRwfSAjEAnbpV/KlK6O3t5nYBQnvI+GDZjVGLVTv7 +jHvrZQnD+JbNR6iC8hZVdyR+EhCVBCyj +-----END CERTIFICATE----- + +emSign Root CA - C1 +=================== +-----BEGIN CERTIFICATE----- +MIIDczCCAlugAwIBAgILAK7PALrEzzL4Q7IwDQYJKoZIhvcNAQELBQAwVjELMAkGA1UEBhMCVVMx +EzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMRwwGgYDVQQDExNlbVNp +Z24gUm9vdCBDQSAtIEMxMB4XDTE4MDIxODE4MzAwMFoXDTQzMDIxODE4MzAwMFowVjELMAkGA1UE +BhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMRwwGgYDVQQD +ExNlbVNpZ24gUm9vdCBDQSAtIEMxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+up +ufGZBczYKCFK83M0UYRWEPWgTywS4/oTmifQz/l5GnRfHXk5/Fv4cI7gklL35CX5VIPZHdPIWoU/ +Xse2B+4+wM6ar6xWQio5JXDWv7V7Nq2s9nPczdcdioOl+yuQFTdrHCZH3DspVpNqs8FqOp099cGX +OFgFixwR4+S0uF2FHYP+eF8LRWgYSKVGczQ7/g/IdrvHGPMF0Ybzhe3nudkyrVWIzqa2kbBPrH4V +I5b2P/AgNBbeCsbEBEV5f6f9vtKppa+cxSMq9zwhbL2vj07FOrLzNBL834AaSaTUqZX3noleooms +lMuoaJuvimUnzYnu3Yy1aylwQ6BpC+S5DwIDAQABo0IwQDAdBgNVHQ4EFgQU/qHgcB4qAzlSWkK+ +XJGFehiqTbUwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD +ggEBAMJKVvoVIXsoounlHfv4LcQ5lkFMOycsxGwYFYDGrK9HWS8mC+M2sO87/kOXSTKZEhVb3xEp +/6tT+LvBeA+snFOvV71ojD1pM/CjoCNjO2RnIkSt1XHLVip4kqNPEjE2NuLe/gDEo2APJ62gsIq1 +NnpSob0n9CAnYuhNlCQT5AoE6TyrLshDCUrGYQTlSTR+08TI9Q/Aqum6VF7zYytPT1DU/rl7mYw9 +wC68AivTxEDkigcxHpvOJpkT+xHqmiIMERnHXhuBUDDIlhJu58tBf5E7oke3VIAb3ADMmpDqw8NQ +BmIMMMAVSKeoWXzhriKi4gp6D/piq1JM4fHfyr6DDUI= +-----END CERTIFICATE----- + +emSign ECC Root CA - C3 +======================= +-----BEGIN CERTIFICATE----- +MIICKzCCAbGgAwIBAgIKe3G2gla4EnycqDAKBggqhkjOPQQDAzBaMQswCQYDVQQGEwJVUzETMBEG +A1UECxMKZW1TaWduIFBLSTEUMBIGA1UEChMLZU11ZGhyYSBJbmMxIDAeBgNVBAMTF2VtU2lnbiBF +Q0MgUm9vdCBDQSAtIEMzMB4XDTE4MDIxODE4MzAwMFoXDTQzMDIxODE4MzAwMFowWjELMAkGA1UE +BhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMSAwHgYDVQQD +ExdlbVNpZ24gRUNDIFJvb3QgQ0EgLSBDMzB2MBAGByqGSM49AgEGBSuBBAAiA2IABP2lYa57JhAd +6bciMK4G9IGzsUJxlTm801Ljr6/58pc1kjZGDoeVjbk5Wum739D+yAdBPLtVb4OjavtisIGJAnB9 +SMVK4+kiVCJNk7tCDK93nCOmfddhEc5lx/h//vXyqaNCMEAwHQYDVR0OBBYEFPtaSNCAIEDyqOkA +B2kZd6fmw/TPMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMDA2gA +MGUCMQC02C8Cif22TGK6Q04ThHK1rt0c3ta13FaPWEBaLd4gTCKDypOofu4SQMfWh0/434UCMBwU +ZOR8loMRnLDRWmFLpg9J0wD8ofzkpf9/rdcw0Md3f76BB1UwUCAU9Vc4CqgxUQ== +-----END CERTIFICATE----- + +Hongkong Post Root CA 3 +======================= +-----BEGIN CERTIFICATE----- +MIIFzzCCA7egAwIBAgIUCBZfikyl7ADJk0DfxMauI7gcWqQwDQYJKoZIhvcNAQELBQAwbzELMAkG +A1UEBhMCSEsxEjAQBgNVBAgTCUhvbmcgS29uZzESMBAGA1UEBxMJSG9uZyBLb25nMRYwFAYDVQQK +Ew1Ib25na29uZyBQb3N0MSAwHgYDVQQDExdIb25na29uZyBQb3N0IFJvb3QgQ0EgMzAeFw0xNzA2 +MDMwMjI5NDZaFw00MjA2MDMwMjI5NDZaMG8xCzAJBgNVBAYTAkhLMRIwEAYDVQQIEwlIb25nIEtv +bmcxEjAQBgNVBAcTCUhvbmcgS29uZzEWMBQGA1UEChMNSG9uZ2tvbmcgUG9zdDEgMB4GA1UEAxMX +SG9uZ2tvbmcgUG9zdCBSb290IENBIDMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCz +iNfqzg8gTr7m1gNt7ln8wlffKWihgw4+aMdoWJwcYEuJQwy51BWy7sFOdem1p+/l6TWZ5Mwc50tf +jTMwIDNT2aa71T4Tjukfh0mtUC1Qyhi+AViiE3CWu4mIVoBc+L0sPOFMV4i707mV78vH9toxdCim +5lSJ9UExyuUmGs2C4HDaOym71QP1mbpV9WTRYA6ziUm4ii8F0oRFKHyPaFASePwLtVPLwpgchKOe +sL4jpNrcyCse2m5FHomY2vkALgbpDDtw1VAliJnLzXNg99X/NWfFobxeq81KuEXryGgeDQ0URhLj +0mRiikKYvLTGCAj4/ahMZJx2Ab0vqWwzD9g/KLg8aQFChn5pwckGyuV6RmXpwtZQQS4/t+TtbNe/ +JgERohYpSms0BpDsE9K2+2p20jzt8NYt3eEV7KObLyzJPivkaTv/ciWxNoZbx39ri1UbSsUgYT2u +y1DhCDq+sI9jQVMwCFk8mB13umOResoQUGC/8Ne8lYePl8X+l2oBlKN8W4UdKjk60FSh0Tlxnf0h ++bV78OLgAo9uliQlLKAeLKjEiafv7ZkGL7YKTE/bosw3Gq9HhS2KX8Q0NEwA/RiTZxPRN+ZItIsG +xVd7GYYKecsAyVKvQv83j+GjHno9UKtjBucVtT+2RTeUN7F+8kjDf8V1/peNRY8apxpyKBpADwID +AQABo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAfBgNVHSMEGDAWgBQXnc0e +i9Y5K3DTXNSguB+wAPzFYTAdBgNVHQ4EFgQUF53NHovWOStw01zUoLgfsAD8xWEwDQYJKoZIhvcN +AQELBQADggIBAFbVe27mIgHSQpsY1Q7XZiNc4/6gx5LS6ZStS6LG7BJ8dNVI0lkUmcDrudHr9Egw +W62nV3OZqdPlt9EuWSRY3GguLmLYauRwCy0gUCCkMpXRAJi70/33MvJJrsZ64Ee+bs7Lo3I6LWld +y8joRTnU+kLBEUx3XZL7av9YROXrgZ6voJmtvqkBZss4HTzfQx/0TW60uhdG/H39h4F5ag0zD/ov ++BS5gLNdTaqX4fnkGMX41TiMJjz98iji7lpJiCzfeT2OnpA8vUFKOt1b9pq0zj8lMH8yfaIDlNDc +eqFS3m6TjRgm/VWsvY+b0s+v54Ysyx8Jb6NvqYTUc79NoXQbTiNg8swOqn+knEwlqLJmOzj/2ZQw +9nKEvmhVEA/GcywWaZMH/rFF7buiVWqw2rVKAiUnhde3t4ZEFolsgCs+l6mc1X5VTMbeRRAc6uk7 +nwNT7u56AQIWeNTowr5GdogTPyK7SBIdUgC0An4hGh6cJfTzPV4e0hz5sy229zdcxsshTrD3mUcY +hcErulWuBurQB7Lcq9CClnXO0lD+mefPL5/ndtFhKvshuzHQqp9HpLIiyhY6UFfEW0NnxWViA0kB +60PZ2Pierc+xYw5F9KBaLJstxabArahH9CdMOA0uG0k7UvToiIMrVCjU8jVStDKDYmlkDJGcn5fq +dBb9HxEGmpv0 +-----END CERTIFICATE----- + +Entrust Root Certification Authority - G4 +========================================= +-----BEGIN CERTIFICATE----- +MIIGSzCCBDOgAwIBAgIRANm1Q3+vqTkPAAAAAFVlrVgwDQYJKoZIhvcNAQELBQAwgb4xCzAJBgNV +BAYTAlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMuMSgwJgYDVQQLEx9TZWUgd3d3LmVudHJ1c3Qu +bmV0L2xlZ2FsLXRlcm1zMTkwNwYDVQQLEzAoYykgMjAxNSBFbnRydXN0LCBJbmMuIC0gZm9yIGF1 +dGhvcml6ZWQgdXNlIG9ubHkxMjAwBgNVBAMTKUVudHJ1c3QgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1 +dGhvcml0eSAtIEc0MB4XDTE1MDUyNzExMTExNloXDTM3MTIyNzExNDExNlowgb4xCzAJBgNVBAYT +AlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMuMSgwJgYDVQQLEx9TZWUgd3d3LmVudHJ1c3QubmV0 +L2xlZ2FsLXRlcm1zMTkwNwYDVQQLEzAoYykgMjAxNSBFbnRydXN0LCBJbmMuIC0gZm9yIGF1dGhv +cml6ZWQgdXNlIG9ubHkxMjAwBgNVBAMTKUVudHJ1c3QgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhv +cml0eSAtIEc0MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsewsQu7i0TD/pZJH4i3D +umSXbcr3DbVZwbPLqGgZ2K+EbTBwXX7zLtJTmeH+H17ZSK9dE43b/2MzTdMAArzE+NEGCJR5WIoV +3imz/f3ET+iq4qA7ec2/a0My3dl0ELn39GjUu9CH1apLiipvKgS1sqbHoHrmSKvS0VnM1n4j5pds +8ELl3FFLFUHtSUrJ3hCX1nbB76W1NhSXNdh4IjVS70O92yfbYVaCNNzLiGAMC1rlLAHGVK/XqsEQ +e9IFWrhAnoanw5CGAlZSCXqc0ieCU0plUmr1POeo8pyvi73TDtTUXm6Hnmo9RR3RXRv06QqsYJn7 +ibT/mCzPfB3pAqoEmh643IhuJbNsZvc8kPNXwbMv9W3y+8qh+CmdRouzavbmZwe+LGcKKh9asj5X +xNMhIWNlUpEbsZmOeX7m640A2Vqq6nPopIICR5b+W45UYaPrL0swsIsjdXJ8ITzI9vF01Bx7owVV +7rtNOzK+mndmnqxpkCIHH2E6lr7lmk/MBTwoWdPBDFSoWWG9yHJM6Nyfh3+9nEg2XpWjDrk4JFX8 +dWbrAuMINClKxuMrLzOg2qOGpRKX/YAr2hRC45K9PvJdXmd0LhyIRyk0X+IyqJwlN4y6mACXi0mW +Hv0liqzc2thddG5msP9E36EYxr5ILzeUePiVSj9/E15dWf10hkNjc0kCAwEAAaNCMEAwDwYDVR0T +AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJ84xFYjwznooHFs6FRM5Og6sb9n +MA0GCSqGSIb3DQEBCwUAA4ICAQAS5UKme4sPDORGpbZgQIeMJX6tuGguW8ZAdjwD+MlZ9POrYs4Q +jbRaZIxowLByQzTSGwv2LFPSypBLhmb8qoMi9IsabyZIrHZ3CL/FmFz0Jomee8O5ZDIBf9PD3Vht +7LGrhFV0d4QEJ1JrhkzO3bll/9bGXp+aEJlLdWr+aumXIOTkdnrG0CSqkM0gkLpHZPt/B7NTeLUK +YvJzQ85BK4FqLoUWlFPUa19yIqtRLULVAJyZv967lDtX/Zr1hstWO1uIAeV8KEsD+UmDfLJ/fOPt +jqF/YFOOVZ1QNBIPt5d7bIdKROf1beyAN/BYGW5KaHbwH5Lk6rWS02FREAutp9lfx1/cH6NcjKF+ +m7ee01ZvZl4HliDtC3T7Zk6LERXpgUl+b7DUUH8i119lAg2m9IUe2K4GS0qn0jFmwvjO5QimpAKW +RGhXxNUzzxkvFMSUHHuk2fCfDrGA4tGeEWSpiBE6doLlYsKA2KSD7ZPvfC+QsDJMlhVoSFLUmQjA +JOgc47OlIQ6SwJAfzyBfyjs4x7dtOvPmRLgOMWuIjnDrnBdSqEGULoe256YSxXXfW8AKbnuk5F6G ++TaU33fD6Q3AOfF5u0aOq0NZJ7cguyPpVkAh7DE9ZapD8j3fcEThuk0mEDuYn/PIjhs4ViFqUZPT +kcpG2om3PVODLAgfi49T3f+sHw== +-----END CERTIFICATE----- + +Microsoft ECC Root Certificate Authority 2017 +============================================= +-----BEGIN CERTIFICATE----- +MIICWTCCAd+gAwIBAgIQZvI9r4fei7FK6gxXMQHC7DAKBggqhkjOPQQDAzBlMQswCQYDVQQGEwJV +UzEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMTYwNAYDVQQDEy1NaWNyb3NvZnQgRUND +IFJvb3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IDIwMTcwHhcNMTkxMjE4MjMwNjQ1WhcNNDIwNzE4 +MjMxNjA0WjBlMQswCQYDVQQGEwJVUzEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMTYw +NAYDVQQDEy1NaWNyb3NvZnQgRUNDIFJvb3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IDIwMTcwdjAQ +BgcqhkjOPQIBBgUrgQQAIgNiAATUvD0CQnVBEyPNgASGAlEvaqiBYgtlzPbKnR5vSmZRogPZnZH6 +thaxjG7efM3beaYvzrvOcS/lpaso7GMEZpn4+vKTEAXhgShC48Zo9OYbhGBKia/teQ87zvH2RPUB +eMCjVDBSMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTIy5lycFIM ++Oa+sgRXKSrPQhDtNTAQBgkrBgEEAYI3FQEEAwIBADAKBggqhkjOPQQDAwNoADBlAjBY8k3qDPlf +Xu5gKcs68tvWMoQZP3zVL8KxzJOuULsJMsbG7X7JNpQS5GiFBqIb0C8CMQCZ6Ra0DvpWSNSkMBaR +eNtUjGUBiudQZsIxtzm6uBoiB078a1QWIP8rtedMDE2mT3M= +-----END CERTIFICATE----- + +Microsoft RSA Root Certificate Authority 2017 +============================================= +-----BEGIN CERTIFICATE----- +MIIFqDCCA5CgAwIBAgIQHtOXCV/YtLNHcB6qvn9FszANBgkqhkiG9w0BAQwFADBlMQswCQYDVQQG +EwJVUzEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMTYwNAYDVQQDEy1NaWNyb3NvZnQg +UlNBIFJvb3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IDIwMTcwHhcNMTkxMjE4MjI1MTIyWhcNNDIw +NzE4MjMwMDIzWjBlMQswCQYDVQQGEwJVUzEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9u +MTYwNAYDVQQDEy1NaWNyb3NvZnQgUlNBIFJvb3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IDIwMTcw +ggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDKW76UM4wplZEWCpW9R2LBifOZNt9GkMml +7Xhqb0eRaPgnZ1AzHaGm++DlQ6OEAlcBXZxIQIJTELy/xztokLaCLeX0ZdDMbRnMlfl7rEqUrQ7e +S0MdhweSE5CAg2Q1OQT85elss7YfUJQ4ZVBcF0a5toW1HLUX6NZFndiyJrDKxHBKrmCk3bPZ7Pw7 +1VdyvD/IybLeS2v4I2wDwAW9lcfNcztmgGTjGqwu+UcF8ga2m3P1eDNbx6H7JyqhtJqRjJHTOoI+ +dkC0zVJhUXAoP8XFWvLJjEm7FFtNyP9nTUwSlq31/niol4fX/V4ggNyhSyL71Imtus5Hl0dVe49F +yGcohJUcaDDv70ngNXtk55iwlNpNhTs+VcQor1fznhPbRiefHqJeRIOkpcrVE7NLP8TjwuaGYaRS +MLl6IE9vDzhTyzMMEyuP1pq9KsgtsRx9S1HKR9FIJ3Jdh+vVReZIZZ2vUpC6W6IYZVcSn2i51BVr +lMRpIpj0M+Dt+VGOQVDJNE92kKz8OMHY4Xu54+OU4UZpyw4KUGsTuqwPN1q3ErWQgR5WrlcihtnJ +0tHXUeOrO8ZV/R4O03QK0dqq6mm4lyiPSMQH+FJDOvTKVTUssKZqwJz58oHhEmrARdlns87/I6KJ +ClTUFLkqqNfs+avNJVgyeY+QW5g5xAgGwax/Dj0ApQIDAQABo1QwUjAOBgNVHQ8BAf8EBAMCAYYw +DwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUCctZf4aycI8awznjwNnpv7tNsiMwEAYJKwYBBAGC +NxUBBAMCAQAwDQYJKoZIhvcNAQEMBQADggIBAKyvPl3CEZaJjqPnktaXFbgToqZCLgLNFgVZJ8og +6Lq46BrsTaiXVq5lQ7GPAJtSzVXNUzltYkyLDVt8LkS/gxCP81OCgMNPOsduET/m4xaRhPtthH80 +dK2Jp86519efhGSSvpWhrQlTM93uCupKUY5vVau6tZRGrox/2KJQJWVggEbbMwSubLWYdFQl3JPk ++ONVFT24bcMKpBLBaYVu32TxU5nhSnUgnZUP5NbcA/FZGOhHibJXWpS2qdgXKxdJ5XbLwVaZOjex +/2kskZGT4d9Mozd2TaGf+G0eHdP67Pv0RR0Tbc/3WeUiJ3IrhvNXuzDtJE3cfVa7o7P4NHmJweDy +AmH3pvwPuxwXC65B2Xy9J6P9LjrRk5Sxcx0ki69bIImtt2dmefU6xqaWM/5TkshGsRGRxpl/j8nW +ZjEgQRCHLQzWwa80mMpkg/sTV9HB8Dx6jKXB/ZUhoHHBk2dxEuqPiAppGWSZI1b7rCoucL5mxAyE +7+WL85MB+GqQk2dLsmijtWKP6T+MejteD+eMuMZ87zf9dOLITzNy4ZQ5bb0Sr74MTnB8G2+NszKT +c0QWbej09+CVgI+WXTik9KveCjCHk9hNAHFiRSdLOkKEW39lt2c0Ui2cFmuqqNh7o0JMcccMyj6D +5KbvtwEwXlGjefVwaaZBRA+GsCyRxj3qrg+E +-----END CERTIFICATE----- + +e-Szigno Root CA 2017 +===================== +-----BEGIN CERTIFICATE----- +MIICQDCCAeWgAwIBAgIMAVRI7yH9l1kN9QQKMAoGCCqGSM49BAMCMHExCzAJBgNVBAYTAkhVMREw +DwYDVQQHDAhCdWRhcGVzdDEWMBQGA1UECgwNTWljcm9zZWMgTHRkLjEXMBUGA1UEYQwOVkFUSFUt +MjM1ODQ0OTcxHjAcBgNVBAMMFWUtU3ppZ25vIFJvb3QgQ0EgMjAxNzAeFw0xNzA4MjIxMjA3MDZa +Fw00MjA4MjIxMjA3MDZaMHExCzAJBgNVBAYTAkhVMREwDwYDVQQHDAhCdWRhcGVzdDEWMBQGA1UE +CgwNTWljcm9zZWMgTHRkLjEXMBUGA1UEYQwOVkFUSFUtMjM1ODQ0OTcxHjAcBgNVBAMMFWUtU3pp +Z25vIFJvb3QgQ0EgMjAxNzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJbcPYrYsHtvxie+RJCx +s1YVe45DJH0ahFnuY2iyxl6H0BVIHqiQrb1TotreOpCmYF9oMrWGQd+HWyx7xf58etqjYzBhMA8G +A1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBSHERUI0arBeAyxr87GyZDv +vzAEwDAfBgNVHSMEGDAWgBSHERUI0arBeAyxr87GyZDvvzAEwDAKBggqhkjOPQQDAgNJADBGAiEA +tVfd14pVCzbhhkT61NlojbjcI4qKDdQvfepz7L9NbKgCIQDLpbQS+ue16M9+k/zzNY9vTlp8tLxO +svxyqltZ+efcMQ== +-----END CERTIFICATE----- + +certSIGN Root CA G2 +=================== +-----BEGIN CERTIFICATE----- +MIIFRzCCAy+gAwIBAgIJEQA0tk7GNi02MA0GCSqGSIb3DQEBCwUAMEExCzAJBgNVBAYTAlJPMRQw +EgYDVQQKEwtDRVJUU0lHTiBTQTEcMBoGA1UECxMTY2VydFNJR04gUk9PVCBDQSBHMjAeFw0xNzAy +MDYwOTI3MzVaFw00MjAyMDYwOTI3MzVaMEExCzAJBgNVBAYTAlJPMRQwEgYDVQQKEwtDRVJUU0lH +TiBTQTEcMBoGA1UECxMTY2VydFNJR04gUk9PVCBDQSBHMjCCAiIwDQYJKoZIhvcNAQEBBQADggIP +ADCCAgoCggIBAMDFdRmRfUR0dIf+DjuW3NgBFszuY5HnC2/OOwppGnzC46+CjobXXo9X69MhWf05 +N0IwvlDqtg+piNguLWkh59E3GE59kdUWX2tbAMI5Qw02hVK5U2UPHULlj88F0+7cDBrZuIt4Imfk +abBoxTzkbFpG583H+u/E7Eu9aqSs/cwoUe+StCmrqzWaTOTECMYmzPhpn+Sc8CnTXPnGFiWeI8Mg +wT0PPzhAsP6CRDiqWhqKa2NYOLQV07YRaXseVO6MGiKscpc/I1mbySKEwQdPzH/iV8oScLumZfNp +dWO9lfsbl83kqK/20U6o2YpxJM02PbyWxPFsqa7lzw1uKA2wDrXKUXt4FMMgL3/7FFXhEZn91Qqh +ngLjYl/rNUssuHLoPj1PrCy7Lobio3aP5ZMqz6WryFyNSwb/EkaseMsUBzXgqd+L6a8VTxaJW732 +jcZZroiFDsGJ6x9nxUWO/203Nit4ZoORUSs9/1F3dmKh7Gc+PoGD4FapUB8fepmrY7+EF3fxDTvf +95xhszWYijqy7DwaNz9+j5LP2RIUZNoQAhVB/0/E6xyjyfqZ90bp4RjZsbgyLcsUDFDYg2WD7rlc +z8sFWkz6GZdr1l0T08JcVLwyc6B49fFtHsufpaafItzRUZ6CeWRgKRM+o/1Pcmqr4tTluCRVLERL +iohEnMqE0yo7AgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1Ud +DgQWBBSCIS1mxteg4BXrzkwJd8RgnlRuAzANBgkqhkiG9w0BAQsFAAOCAgEAYN4auOfyYILVAzOB +ywaK8SJJ6ejqkX/GM15oGQOGO0MBzwdw5AgeZYWR5hEit/UCI46uuR59H35s5r0l1ZUa8gWmr4UC +b6741jH/JclKyMeKqdmfS0mbEVeZkkMR3rYzpMzXjWR91M08KCy0mpbqTfXERMQlqiCA2ClV9+BB +/AYm/7k29UMUA2Z44RGx2iBfRgB4ACGlHgAoYXhvqAEBj500mv/0OJD7uNGzcgbJceaBxXntC6Z5 +8hMLnPddDnskk7RI24Zf3lCGeOdA5jGokHZwYa+cNywRtYK3qq4kNFtyDGkNzVmf9nGvnAvRCjj5 +BiKDUyUM/FHE5r7iOZULJK2v0ZXkltd0ZGtxTgI8qoXzIKNDOXZbbFD+mpwUHmUUihW9o4JFWklW +atKcsWMy5WHgUyIOpwpJ6st+H6jiYoD2EEVSmAYY3qXNL3+q1Ok+CHLsIwMCPKaq2LxndD0UF/tU +Sxfj03k9bWtJySgOLnRQvwzZRjoQhsmnP+mg7H/rpXdYaXHmgwo38oZJar55CJD2AhZkPuXaTH4M +NMn5X7azKFGnpyuqSfqNZSlO42sTp5SjLVFteAxEy9/eCG/Oo2Sr05WE1LlSVHJ7liXMvGnjSG4N +0MedJ5qq+BOS3R7fY581qRY27Iy4g/Q9iY/NtBde17MXQRBdJ3NghVdJIgc= +-----END CERTIFICATE----- + +Trustwave Global Certification Authority +======================================== +-----BEGIN CERTIFICATE----- +MIIF2jCCA8KgAwIBAgIMBfcOhtpJ80Y1LrqyMA0GCSqGSIb3DQEBCwUAMIGIMQswCQYDVQQGEwJV +UzERMA8GA1UECAwISWxsaW5vaXMxEDAOBgNVBAcMB0NoaWNhZ28xITAfBgNVBAoMGFRydXN0d2F2 +ZSBIb2xkaW5ncywgSW5jLjExMC8GA1UEAwwoVHJ1c3R3YXZlIEdsb2JhbCBDZXJ0aWZpY2F0aW9u +IEF1dGhvcml0eTAeFw0xNzA4MjMxOTM0MTJaFw00MjA4MjMxOTM0MTJaMIGIMQswCQYDVQQGEwJV +UzERMA8GA1UECAwISWxsaW5vaXMxEDAOBgNVBAcMB0NoaWNhZ28xITAfBgNVBAoMGFRydXN0d2F2 +ZSBIb2xkaW5ncywgSW5jLjExMC8GA1UEAwwoVHJ1c3R3YXZlIEdsb2JhbCBDZXJ0aWZpY2F0aW9u +IEF1dGhvcml0eTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBALldUShLPDeS0YLOvR29 +zd24q88KPuFd5dyqCblXAj7mY2Hf8g+CY66j96xz0XznswuvCAAJWX/NKSqIk4cXGIDtiLK0thAf +LdZfVaITXdHG6wZWiYj+rDKd/VzDBcdu7oaJuogDnXIhhpCujwOl3J+IKMujkkkP7NAP4m1ET4Bq +stTnoApTAbqOl5F2brz81Ws25kCI1nsvXwXoLG0R8+eyvpJETNKXpP7ScoFDB5zpET71ixpZfR9o +WN0EACyW80OzfpgZdNmcc9kYvkHHNHnZ9GLCQ7mzJ7Aiy/k9UscwR7PJPrhq4ufogXBeQotPJqX+ +OsIgbrv4Fo7NDKm0G2x2EOFYeUY+VM6AqFcJNykbmROPDMjWLBz7BegIlT1lRtzuzWniTY+HKE40 +Cz7PFNm73bZQmq131BnW2hqIyE4bJ3XYsgjxroMwuREOzYfwhI0Vcnyh78zyiGG69Gm7DIwLdVcE +uE4qFC49DxweMqZiNu5m4iK4BUBjECLzMx10coos9TkpoNPnG4CELcU9402x/RpvumUHO1jsQkUm ++9jaJXLE9gCxInm943xZYkqcBW89zubWR2OZxiRvchLIrH+QtAuRcOi35hYQcRfO3gZPSEF9NUqj +ifLJS3tBEW1ntwiYTOURGa5CgNz7kAXU+FDKvuStx8KU1xad5hePrzb7AgMBAAGjQjBAMA8GA1Ud +EwEB/wQFMAMBAf8wHQYDVR0OBBYEFJngGWcNYtt2s9o9uFvo/ULSMQ6HMA4GA1UdDwEB/wQEAwIB +BjANBgkqhkiG9w0BAQsFAAOCAgEAmHNw4rDT7TnsTGDZqRKGFx6W0OhUKDtkLSGm+J1WE2pIPU/H +PinbbViDVD2HfSMF1OQc3Og4ZYbFdada2zUFvXfeuyk3QAUHw5RSn8pk3fEbK9xGChACMf1KaA0H +ZJDmHvUqoai7PF35owgLEQzxPy0QlG/+4jSHg9bP5Rs1bdID4bANqKCqRieCNqcVtgimQlRXtpla +4gt5kNdXElE1GYhBaCXUNxeEFfsBctyV3lImIJgm4nb1J2/6ADtKYdkNy1GTKv0WBpanI5ojSP5R +vbbEsLFUzt5sQa0WZ37b/TjNuThOssFgy50X31ieemKyJo90lZvkWx3SD92YHJtZuSPTMaCm/zjd +zyBP6VhWOmfD0faZmZ26NraAL4hHT4a/RDqA5Dccprrql5gR0IRiR2Qequ5AvzSxnI9O4fKSTx+O +856X3vOmeWqJcU9LJxdI/uz0UA9PSX3MReO9ekDFQdxhVicGaeVyQYHTtgGJoC86cnn+OjC/QezH +Yj6RS8fZMXZC+fc8Y+wmjHMMfRod6qh8h6jCJ3zhM0EPz8/8AKAigJ5Kp28AsEFFtyLKaEjFQqKu +3R3y4G5OBVixwJAWKqQ9EEC+j2Jjg6mcgn0tAumDMHzLJ8n9HmYAsC7TIS+OMxZsmO0QqAfWzJPP +29FpHOTKyeC2nOnOcXHebD8WpHk= +-----END CERTIFICATE----- + +Trustwave Global ECC P256 Certification Authority +================================================= +-----BEGIN CERTIFICATE----- +MIICYDCCAgegAwIBAgIMDWpfCD8oXD5Rld9dMAoGCCqGSM49BAMCMIGRMQswCQYDVQQGEwJVUzER +MA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAfBgNVBAoTGFRydXN0d2F2ZSBI +b2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3YXZlIEdsb2JhbCBFQ0MgUDI1NiBDZXJ0aWZp +Y2F0aW9uIEF1dGhvcml0eTAeFw0xNzA4MjMxOTM1MTBaFw00MjA4MjMxOTM1MTBaMIGRMQswCQYD +VQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAfBgNVBAoTGFRy +dXN0d2F2ZSBIb2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3YXZlIEdsb2JhbCBFQ0MgUDI1 +NiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABH77bOYj +43MyCMpg5lOcunSNGLB4kFKA3TjASh3RqMyTpJcGOMoNFWLGjgEqZZ2q3zSRLoHB5DOSMcT9CTqm +P62jQzBBMA8GA1UdEwEB/wQFMAMBAf8wDwYDVR0PAQH/BAUDAwcGADAdBgNVHQ4EFgQUo0EGrJBt +0UrrdaVKEJmzsaGLSvcwCgYIKoZIzj0EAwIDRwAwRAIgB+ZU2g6gWrKuEZ+Hxbb/ad4lvvigtwjz +RM4q3wghDDcCIC0mA6AFvWvR9lz4ZcyGbbOcNEhjhAnFjXca4syc4XR7 +-----END CERTIFICATE----- + +Trustwave Global ECC P384 Certification Authority +================================================= +-----BEGIN CERTIFICATE----- +MIICnTCCAiSgAwIBAgIMCL2Fl2yZJ6SAaEc7MAoGCCqGSM49BAMDMIGRMQswCQYDVQQGEwJVUzER +MA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAfBgNVBAoTGFRydXN0d2F2ZSBI +b2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3YXZlIEdsb2JhbCBFQ0MgUDM4NCBDZXJ0aWZp +Y2F0aW9uIEF1dGhvcml0eTAeFw0xNzA4MjMxOTM2NDNaFw00MjA4MjMxOTM2NDNaMIGRMQswCQYD +VQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAfBgNVBAoTGFRy +dXN0d2F2ZSBIb2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3YXZlIEdsb2JhbCBFQ0MgUDM4 +NCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGvaDXU1CDFH +Ba5FmVXxERMuSvgQMSOjfoPTfygIOiYaOs+Xgh+AtycJj9GOMMQKmw6sWASr9zZ9lCOkmwqKi6vr +/TklZvFe/oyujUF5nQlgziip04pt89ZF1PKYhDhloKNDMEEwDwYDVR0TAQH/BAUwAwEB/zAPBgNV +HQ8BAf8EBQMDBwYAMB0GA1UdDgQWBBRVqYSJ0sEyvRjLbKYHTsjnnb6CkDAKBggqhkjOPQQDAwNn +ADBkAjA3AZKXRRJ+oPM+rRk6ct30UJMDEr5E0k9BpIycnR+j9sKS50gU/k6bpZFXrsY3crsCMGcl +CrEMXu6pY5Jv5ZAL/mYiykf9ijH3g/56vxC+GCsej/YpHpRZ744hN8tRmKVuSw== +-----END CERTIFICATE----- + +NAVER Global Root Certification Authority +========================================= +-----BEGIN CERTIFICATE----- +MIIFojCCA4qgAwIBAgIUAZQwHqIL3fXFMyqxQ0Rx+NZQTQ0wDQYJKoZIhvcNAQEMBQAwaTELMAkG +A1UEBhMCS1IxJjAkBgNVBAoMHU5BVkVSIEJVU0lORVNTIFBMQVRGT1JNIENvcnAuMTIwMAYDVQQD +DClOQVZFUiBHbG9iYWwgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0xNzA4MTgwODU4 +NDJaFw0zNzA4MTgyMzU5NTlaMGkxCzAJBgNVBAYTAktSMSYwJAYDVQQKDB1OQVZFUiBCVVNJTkVT +UyBQTEFURk9STSBDb3JwLjEyMDAGA1UEAwwpTkFWRVIgR2xvYmFsIFJvb3QgQ2VydGlmaWNhdGlv +biBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC21PGTXLVAiQqrDZBb +UGOukJR0F0Vy1ntlWilLp1agS7gvQnXp2XskWjFlqxcX0TM62RHcQDaH38dq6SZeWYp34+hInDEW ++j6RscrJo+KfziFTowI2MMtSAuXaMl3Dxeb57hHHi8lEHoSTGEq0n+USZGnQJoViAbbJAh2+g1G7 +XNr4rRVqmfeSVPc0W+m/6imBEtRTkZazkVrd/pBzKPswRrXKCAfHcXLJZtM0l/aM9BhK4dA9WkW2 +aacp+yPOiNgSnABIqKYPszuSjXEOdMWLyEz59JuOuDxp7W87UC9Y7cSw0BwbagzivESq2M0UXZR4 +Yb8ObtoqvC8MC3GmsxY/nOb5zJ9TNeIDoKAYv7vxvvTWjIcNQvcGufFt7QSUqP620wbGQGHfnZ3z +VHbOUzoBppJB7ASjjw2i1QnK1sua8e9DXcCrpUHPXFNwcMmIpi3Ua2FzUCaGYQ5fG8Ir4ozVu53B +A0K6lNpfqbDKzE0K70dpAy8i+/Eozr9dUGWokG2zdLAIx6yo0es+nPxdGoMuK8u180SdOqcXYZai +cdNwlhVNt0xz7hlcxVs+Qf6sdWA7G2POAN3aCJBitOUt7kinaxeZVL6HSuOpXgRM6xBtVNbv8ejy +YhbLgGvtPe31HzClrkvJE+2KAQHJuFFYwGY6sWZLxNUxAmLpdIQM201GLQIDAQABo0IwQDAdBgNV +HQ4EFgQU0p+I36HNLL3s9TsBAZMzJ7LrYEswDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMB +Af8wDQYJKoZIhvcNAQEMBQADggIBADLKgLOdPVQG3dLSLvCkASELZ0jKbY7gyKoNqo0hV4/GPnrK +21HUUrPUloSlWGB/5QuOH/XcChWB5Tu2tyIvCZwTFrFsDDUIbatjcu3cvuzHV+YwIHHW1xDBE1UB +jCpD5EHxzzp6U5LOogMFDTjfArsQLtk70pt6wKGm+LUx5vR1yblTmXVHIloUFcd4G7ad6Qz4G3bx +hYTeodoS76TiEJd6eN4MUZeoIUCLhr0N8F5OSza7OyAfikJW4Qsav3vQIkMsRIz75Sq0bBwcupTg +E34h5prCy8VCZLQelHsIJchxzIdFV4XTnyliIoNRlwAYl3dqmJLJfGBs32x9SuRwTMKeuB330DTH +D8z7p/8Dvq1wkNoL3chtl1+afwkyQf3NosxabUzyqkn+Zvjp2DXrDige7kgvOtB5CTh8piKCk5XQ +A76+AqAF3SAi428diDRgxuYKuQl1C/AH6GmWNcf7I4GOODm4RStDeKLRLBT/DShycpWbXgnbiUSY +qqFJu3FS8r/2/yehNq+4tneI3TqkbZs0kNwUXTC/t+sX5Ie3cdCh13cV1ELX8vMxmV2b3RZtP+oG +I/hGoiLtk/bdmuYqh7GYVPEi92tF4+KOdh2ajcQGjTa3FPOdVGm3jjzVpG2Tgbet9r1ke8LJaDmg +kpzNNIaRkPpkUZ3+/uul9XXeifdy +-----END CERTIFICATE----- + +AC RAIZ FNMT-RCM SERVIDORES SEGUROS +=================================== +-----BEGIN CERTIFICATE----- +MIICbjCCAfOgAwIBAgIQYvYybOXE42hcG2LdnC6dlTAKBggqhkjOPQQDAzB4MQswCQYDVQQGEwJF +UzERMA8GA1UECgwIRk5NVC1SQ00xDjAMBgNVBAsMBUNlcmVzMRgwFgYDVQRhDA9WQVRFUy1RMjgy +NjAwNEoxLDAqBgNVBAMMI0FDIFJBSVogRk5NVC1SQ00gU0VSVklET1JFUyBTRUdVUk9TMB4XDTE4 +MTIyMDA5MzczM1oXDTQzMTIyMDA5MzczM1oweDELMAkGA1UEBhMCRVMxETAPBgNVBAoMCEZOTVQt +UkNNMQ4wDAYDVQQLDAVDZXJlczEYMBYGA1UEYQwPVkFURVMtUTI4MjYwMDRKMSwwKgYDVQQDDCNB +QyBSQUlaIEZOTVQtUkNNIFNFUlZJRE9SRVMgU0VHVVJPUzB2MBAGByqGSM49AgEGBSuBBAAiA2IA +BPa6V1PIyqvfNkpSIeSX0oNnnvBlUdBeh8dHsVnyV0ebAAKTRBdp20LHsbI6GA60XYyzZl2hNPk2 +LEnb80b8s0RpRBNm/dfF/a82Tc4DTQdxz69qBdKiQ1oKUm8BA06Oi6NCMEAwDwYDVR0TAQH/BAUw +AwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFAG5L++/EYZg8k/QQW6rcx/n0m5JMAoGCCqG +SM49BAMDA2kAMGYCMQCuSuMrQMN0EfKVrRYj3k4MGuZdpSRea0R7/DjiT8ucRRcRTBQnJlU5dUoD +zBOQn5ICMQD6SmxgiHPz7riYYqnOK8LZiqZwMR2vsJRM60/G49HzYqc8/5MuB1xJAWdpEgJyv+c= +-----END CERTIFICATE----- + +GlobalSign Root R46 +=================== +-----BEGIN CERTIFICATE----- +MIIFWjCCA0KgAwIBAgISEdK7udcjGJ5AXwqdLdDfJWfRMA0GCSqGSIb3DQEBDAUAMEYxCzAJBgNV +BAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMRwwGgYDVQQDExNHbG9iYWxTaWduIFJv +b3QgUjQ2MB4XDTE5MDMyMDAwMDAwMFoXDTQ2MDMyMDAwMDAwMFowRjELMAkGA1UEBhMCQkUxGTAX +BgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExHDAaBgNVBAMTE0dsb2JhbFNpZ24gUm9vdCBSNDYwggIi +MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCsrHQy6LNl5brtQyYdpokNRbopiLKkHWPd08Es +CVeJOaFV6Wc0dwxu5FUdUiXSE2te4R2pt32JMl8Nnp8semNgQB+msLZ4j5lUlghYruQGvGIFAha/ +r6gjA7aUD7xubMLL1aa7DOn2wQL7Id5m3RerdELv8HQvJfTqa1VbkNud316HCkD7rRlr+/fKYIje +2sGP1q7Vf9Q8g+7XFkyDRTNrJ9CG0Bwta/OrffGFqfUo0q3v84RLHIf8E6M6cqJaESvWJ3En7YEt +bWaBkoe0G1h6zD8K+kZPTXhc+CtI4wSEy132tGqzZfxCnlEmIyDLPRT5ge1lFgBPGmSXZgjPjHvj +K8Cd+RTyG/FWaha/LIWFzXg4mutCagI0GIMXTpRW+LaCtfOW3T3zvn8gdz57GSNrLNRyc0NXfeD4 +12lPFzYE+cCQYDdF3uYM2HSNrpyibXRdQr4G9dlkbgIQrImwTDsHTUB+JMWKmIJ5jqSngiCNI/on +ccnfxkF0oE32kRbcRoxfKWMxWXEM2G/CtjJ9++ZdU6Z+Ffy7dXxd7Pj2Fxzsx2sZy/N78CsHpdls +eVR2bJ0cpm4O6XkMqCNqo98bMDGfsVR7/mrLZqrcZdCinkqaByFrgY/bxFn63iLABJzjqls2k+g9 +vXqhnQt2sQvHnf3PmKgGwvgqo6GDoLclcqUC4wIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAYYwDwYD +VR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA1yrc4GHqMywptWU4jaWSf8FmSwwDQYJKoZIhvcNAQEM +BQADggIBAHx47PYCLLtbfpIrXTncvtgdokIzTfnvpCo7RGkerNlFo048p9gkUbJUHJNOxO97k4Vg +JuoJSOD1u8fpaNK7ajFxzHmuEajwmf3lH7wvqMxX63bEIaZHU1VNaL8FpO7XJqti2kM3S+LGteWy +gxk6x9PbTZ4IevPuzz5i+6zoYMzRx6Fcg0XERczzF2sUyQQCPtIkpnnpHs6i58FZFZ8d4kuaPp92 +CC1r2LpXFNqD6v6MVenQTqnMdzGxRBF6XLE+0xRFFRhiJBPSy03OXIPBNvIQtQ6IbbjhVp+J3pZm +OUdkLG5NrmJ7v2B0GbhWrJKsFjLtrWhV/pi60zTe9Mlhww6G9kuEYO4Ne7UyWHmRVSyBQ7N0H3qq +JZ4d16GLuc1CLgSkZoNNiTW2bKg2SnkheCLQQrzRQDGQob4Ez8pn7fXwgNNgyYMqIgXQBztSvwye +qiv5u+YfjyW6hY0XHgL+XVAEV8/+LbzvXMAaq7afJMbfc2hIkCwU9D9SGuTSyxTDYWnP4vkYxboz +nxSjBF25cfe1lNj2M8FawTSLfJvdkzrnE6JwYZ+vj+vYxXX4M2bUdGc6N3ec592kD3ZDZopD8p/7 +DEJ4Y9HiD2971KE9dJeFt0g5QdYg/NA6s/rob8SKunE3vouXsXgxT7PntgMTzlSdriVZzH81Xwj3 +QEUxeCp6 +-----END CERTIFICATE----- + +GlobalSign Root E46 +=================== +-----BEGIN CERTIFICATE----- +MIICCzCCAZGgAwIBAgISEdK7ujNu1LzmJGjFDYQdmOhDMAoGCCqGSM49BAMDMEYxCzAJBgNVBAYT +AkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMRwwGgYDVQQDExNHbG9iYWxTaWduIFJvb3Qg +RTQ2MB4XDTE5MDMyMDAwMDAwMFoXDTQ2MDMyMDAwMDAwMFowRjELMAkGA1UEBhMCQkUxGTAXBgNV +BAoTEEdsb2JhbFNpZ24gbnYtc2ExHDAaBgNVBAMTE0dsb2JhbFNpZ24gUm9vdCBFNDYwdjAQBgcq +hkjOPQIBBgUrgQQAIgNiAAScDrHPt+ieUnd1NPqlRqetMhkytAepJ8qUuwzSChDH2omwlwxwEwkB +jtjqR+q+soArzfwoDdusvKSGN+1wCAB16pMLey5SnCNoIwZD7JIvU4Tb+0cUB+hflGddyXqBPCCj +QjBAMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQxCpCPtsad0kRL +gLWi5h+xEk8blTAKBggqhkjOPQQDAwNoADBlAjEA31SQ7Zvvi5QCkxeCmb6zniz2C5GMn0oUsfZk +vLtoURMMA/cVi4RguYv/Uo7njLwcAjA8+RHUjE7AwWHCFUyqqx0LMV87HOIAl0Qx5v5zli/altP+ +CAezNIm8BZ/3Hobui3A= +-----END CERTIFICATE----- + +GLOBALTRUST 2020 +================ +-----BEGIN CERTIFICATE----- +MIIFgjCCA2qgAwIBAgILWku9WvtPilv6ZeUwDQYJKoZIhvcNAQELBQAwTTELMAkGA1UEBhMCQVQx +IzAhBgNVBAoTGmUtY29tbWVyY2UgbW9uaXRvcmluZyBHbWJIMRkwFwYDVQQDExBHTE9CQUxUUlVT +VCAyMDIwMB4XDTIwMDIxMDAwMDAwMFoXDTQwMDYxMDAwMDAwMFowTTELMAkGA1UEBhMCQVQxIzAh +BgNVBAoTGmUtY29tbWVyY2UgbW9uaXRvcmluZyBHbWJIMRkwFwYDVQQDExBHTE9CQUxUUlVTVCAy +MDIwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAri5WrRsc7/aVj6B3GyvTY4+ETUWi +D59bRatZe1E0+eyLinjF3WuvvcTfk0Uev5E4C64OFudBc/jbu9G4UeDLgztzOG53ig9ZYybNpyrO +VPu44sB8R85gfD+yc/LAGbaKkoc1DZAoouQVBGM+uq/ufF7MpotQsjj3QWPKzv9pj2gOlTblzLmM +CcpL3TGQlsjMH/1WljTbjhzqLL6FLmPdqqmV0/0plRPwyJiT2S0WR5ARg6I6IqIoV6Lr/sCMKKCm +fecqQjuCgGOlYx8ZzHyyZqjC0203b+J+BlHZRYQfEs4kUmSFC0iAToexIiIwquuuvuAC4EDosEKA +A1GqtH6qRNdDYfOiaxaJSaSjpCuKAsR49GiKweR6NrFvG5Ybd0mN1MkGco/PU+PcF4UgStyYJ9OR +JitHHmkHr96i5OTUawuzXnzUJIBHKWk7buis/UDr2O1xcSvy6Fgd60GXIsUf1DnQJ4+H4xj04KlG +DfV0OoIu0G4skaMxXDtG6nsEEFZegB31pWXogvziB4xiRfUg3kZwhqG8k9MedKZssCz3AwyIDMvU +clOGvGBG85hqwvG/Q/lwIHfKN0F5VVJjjVsSn8VoxIidrPIwq7ejMZdnrY8XD2zHc+0klGvIg5rQ +mjdJBKuxFshsSUktq6HQjJLyQUp5ISXbY9e2nKd+Qmn7OmMCAwEAAaNjMGEwDwYDVR0TAQH/BAUw +AwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFNwuH9FhN3nkq9XVsxJxaD1qaJwiMB8GA1Ud +IwQYMBaAFNwuH9FhN3nkq9XVsxJxaD1qaJwiMA0GCSqGSIb3DQEBCwUAA4ICAQCR8EICaEDuw2jA +VC/f7GLDw56KoDEoqoOOpFaWEhCGVrqXctJUMHytGdUdaG/7FELYjQ7ztdGl4wJCXtzoRlgHNQIw +4Lx0SsFDKv/bGtCwr2zD/cuz9X9tAy5ZVp0tLTWMstZDFyySCstd6IwPS3BD0IL/qMy/pJTAvoe9 +iuOTe8aPmxadJ2W8esVCgmxcB9CpwYhgROmYhRZf+I/KARDOJcP5YBugxZfD0yyIMaK9MOzQ0MAS +8cE54+X1+NZK3TTN+2/BT+MAi1bikvcoskJ3ciNnxz8RFbLEAwW+uxF7Cr+obuf/WEPPm2eggAe2 +HcqtbepBEX4tdJP7wry+UUTF72glJ4DjyKDUEuzZpTcdN3y0kcra1LGWge9oXHYQSa9+pTeAsRxS +vTOBTI/53WXZFM2KJVj04sWDpQmQ1GwUY7VA3+vA/MRYfg0UFodUJ25W5HCEuGwyEn6CMUO+1918 +oa2u1qsgEu8KwxCMSZY13At1XrFP1U80DhEgB3VDRemjEdqso5nCtnkn4rnvyOL2NSl6dPrFf4IF +YqYK6miyeUcGbvJXqBUzxvd4Sj1Ce2t+/vdG6tHrju+IaFvowdlxfv1k7/9nR4hYJS8+hge9+6jl +gqispdNpQ80xiEmEU5LAsTkbOYMBMMTyqfrQA71yN2BWHzZ8vTmR9W0Nv3vXkg== +-----END CERTIFICATE----- + +ANF Secure Server Root CA +========================= +-----BEGIN CERTIFICATE----- +MIIF7zCCA9egAwIBAgIIDdPjvGz5a7EwDQYJKoZIhvcNAQELBQAwgYQxEjAQBgNVBAUTCUc2MzI4 +NzUxMDELMAkGA1UEBhMCRVMxJzAlBgNVBAoTHkFORiBBdXRvcmlkYWQgZGUgQ2VydGlmaWNhY2lv +bjEUMBIGA1UECxMLQU5GIENBIFJhaXoxIjAgBgNVBAMTGUFORiBTZWN1cmUgU2VydmVyIFJvb3Qg +Q0EwHhcNMTkwOTA0MTAwMDM4WhcNMzkwODMwMTAwMDM4WjCBhDESMBAGA1UEBRMJRzYzMjg3NTEw +MQswCQYDVQQGEwJFUzEnMCUGA1UEChMeQU5GIEF1dG9yaWRhZCBkZSBDZXJ0aWZpY2FjaW9uMRQw +EgYDVQQLEwtBTkYgQ0EgUmFpejEiMCAGA1UEAxMZQU5GIFNlY3VyZSBTZXJ2ZXIgUm9vdCBDQTCC +AiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBANvrayvmZFSVgpCjcqQZAZ2cC4Ffc0m6p6zz +BE57lgvsEeBbphzOG9INgxwruJ4dfkUyYA8H6XdYfp9qyGFOtibBTI3/TO80sh9l2Ll49a2pcbnv +T1gdpd50IJeh7WhM3pIXS7yr/2WanvtH2Vdy8wmhrnZEE26cLUQ5vPnHO6RYPUG9tMJJo8gN0pcv +B2VSAKduyK9o7PQUlrZXH1bDOZ8rbeTzPvY1ZNoMHKGESy9LS+IsJJ1tk0DrtSOOMspvRdOoiXse +zx76W0OLzc2oD2rKDF65nkeP8Nm2CgtYZRczuSPkdxl9y0oukntPLxB3sY0vaJxizOBQ+OyRp1RM +VwnVdmPF6GUe7m1qzwmd+nxPrWAI/VaZDxUse6mAq4xhj0oHdkLePfTdsiQzW7i1o0TJrH93PB0j +7IKppuLIBkwC/qxcmZkLLxCKpvR/1Yd0DVlJRfbwcVw5Kda/SiOL9V8BY9KHcyi1Swr1+KuCLH5z +JTIdC2MKF4EA/7Z2Xue0sUDKIbvVgFHlSFJnLNJhiQcND85Cd8BEc5xEUKDbEAotlRyBr+Qc5RQe +8TZBAQIvfXOn3kLMTOmJDVb3n5HUA8ZsyY/b2BzgQJhdZpmYgG4t/wHFzstGH6wCxkPmrqKEPMVO +Hj1tyRRM4y5Bu8o5vzY8KhmqQYdOpc5LMnndkEl/AgMBAAGjYzBhMB8GA1UdIwQYMBaAFJxf0Gxj +o1+TypOYCK2Mh6UsXME3MB0GA1UdDgQWBBScX9BsY6Nfk8qTmAitjIelLFzBNzAOBgNVHQ8BAf8E +BAMCAYYwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEATh65isagmD9uw2nAalxJ +UqzLK114OMHVVISfk/CHGT0sZonrDUL8zPB1hT+L9IBdeeUXZ701guLyPI59WzbLWoAAKfLOKyzx +j6ptBZNscsdW699QIyjlRRA96Gejrw5VD5AJYu9LWaL2U/HANeQvwSS9eS9OICI7/RogsKQOLHDt +dD+4E5UGUcjohybKpFtqFiGS3XNgnhAY3jyB6ugYw3yJ8otQPr0R4hUDqDZ9MwFsSBXXiJCZBMXM +5gf0vPSQ7RPi6ovDj6MzD8EpTBNO2hVWcXNyglD2mjN8orGoGjR0ZVzO0eurU+AagNjqOknkJjCb +5RyKqKkVMoaZkgoQI1YS4PbOTOK7vtuNknMBZi9iPrJyJ0U27U1W45eZ/zo1PqVUSlJZS2Db7v54 +EX9K3BR5YLZrZAPbFYPhor72I5dQ8AkzNqdxliXzuUJ92zg/LFis6ELhDtjTO0wugumDLmsx2d1H +hk9tl5EuT+IocTUW0fJz/iUrB0ckYyfI+PbZa/wSMVYIwFNCr5zQM378BvAxRAMU8Vjq8moNqRGy +g77FGr8H6lnco4g175x2MjxNBiLOFeXdntiP2t7SxDnlF4HPOEfrf4htWRvfn0IUrn7PqLBmZdo3 +r5+qPeoott7VMVgWglvquxl1AnMaykgaIZOQCo6ThKd9OyMYkomgjaw= +-----END CERTIFICATE----- + +Certum EC-384 CA +================ +-----BEGIN CERTIFICATE----- +MIICZTCCAeugAwIBAgIQeI8nXIESUiClBNAt3bpz9DAKBggqhkjOPQQDAzB0MQswCQYDVQQGEwJQ +TDEhMB8GA1UEChMYQXNzZWNvIERhdGEgU3lzdGVtcyBTLkEuMScwJQYDVQQLEx5DZXJ0dW0gQ2Vy +dGlmaWNhdGlvbiBBdXRob3JpdHkxGTAXBgNVBAMTEENlcnR1bSBFQy0zODQgQ0EwHhcNMTgwMzI2 +MDcyNDU0WhcNNDMwMzI2MDcyNDU0WjB0MQswCQYDVQQGEwJQTDEhMB8GA1UEChMYQXNzZWNvIERh +dGEgU3lzdGVtcyBTLkEuMScwJQYDVQQLEx5DZXJ0dW0gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkx +GTAXBgNVBAMTEENlcnR1bSBFQy0zODQgQ0EwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAATEKI6rGFtq +vm5kN2PkzeyrOvfMobgOgknXhimfoZTy42B4mIF4Bk3y7JoOV2CDn7TmFy8as10CW4kjPMIRBSqn +iBMY81CE1700LCeJVf/OTOffph8oxPBUw7l8t1Ot68KjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYD +VR0OBBYEFI0GZnQkdjrzife81r1HfS+8EF9LMA4GA1UdDwEB/wQEAwIBBjAKBggqhkjOPQQDAwNo +ADBlAjADVS2m5hjEfO/JUG7BJw+ch69u1RsIGL2SKcHvlJF40jocVYli5RsJHrpka/F2tNQCMQC0 +QoSZ/6vnnvuRlydd3LBbMHHOXjgaatkl5+r3YZJW+OraNsKHZZYuciUvf9/DE8k= +-----END CERTIFICATE----- + +Certum Trusted Root CA +====================== +-----BEGIN CERTIFICATE----- +MIIFwDCCA6igAwIBAgIQHr9ZULjJgDdMBvfrVU+17TANBgkqhkiG9w0BAQ0FADB6MQswCQYDVQQG +EwJQTDEhMB8GA1UEChMYQXNzZWNvIERhdGEgU3lzdGVtcyBTLkEuMScwJQYDVQQLEx5DZXJ0dW0g +Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkxHzAdBgNVBAMTFkNlcnR1bSBUcnVzdGVkIFJvb3QgQ0Ew +HhcNMTgwMzE2MTIxMDEzWhcNNDMwMzE2MTIxMDEzWjB6MQswCQYDVQQGEwJQTDEhMB8GA1UEChMY +QXNzZWNvIERhdGEgU3lzdGVtcyBTLkEuMScwJQYDVQQLEx5DZXJ0dW0gQ2VydGlmaWNhdGlvbiBB +dXRob3JpdHkxHzAdBgNVBAMTFkNlcnR1bSBUcnVzdGVkIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQDRLY67tzbqbTeRn06TpwXkKQMlzhyC93yZn0EGze2jusDbCSzBfN8p +fktlL5On1AFrAygYo9idBcEq2EXxkd7fO9CAAozPOA/qp1x4EaTByIVcJdPTsuclzxFUl6s1wB52 +HO8AU5853BSlLCIls3Jy/I2z5T4IHhQqNwuIPMqw9MjCoa68wb4pZ1Xi/K1ZXP69VyywkI3C7Te2 +fJmItdUDmj0VDT06qKhF8JVOJVkdzZhpu9PMMsmN74H+rX2Ju7pgE8pllWeg8xn2A1bUatMn4qGt +g/BKEiJ3HAVz4hlxQsDsdUaakFjgao4rpUYwBI4Zshfjvqm6f1bxJAPXsiEodg42MEx51UGamqi4 +NboMOvJEGyCI98Ul1z3G4z5D3Yf+xOr1Uz5MZf87Sst4WmsXXw3Hw09Omiqi7VdNIuJGmj8PkTQk +fVXjjJU30xrwCSss0smNtA0Aq2cpKNgB9RkEth2+dv5yXMSFytKAQd8FqKPVhJBPC/PgP5sZ0jeJ +P/J7UhyM9uH3PAeXjA6iWYEMspA90+NZRu0PqafegGtaqge2Gcu8V/OXIXoMsSt0Puvap2ctTMSY +njYJdmZm/Bo/6khUHL4wvYBQv3y1zgD2DGHZ5yQD4OMBgQ692IU0iL2yNqh7XAjlRICMb/gv1SHK +HRzQ+8S1h9E6Tsd2tTVItQIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBSM+xx1 +vALTn04uSNn5YFSqxLNP+jAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQENBQADggIBAEii1QAL +LtA/vBzVtVRJHlpr9OTy4EA34MwUe7nJ+jW1dReTagVphZzNTxl4WxmB82M+w85bj/UvXgF2Ez8s +ALnNllI5SW0ETsXpD4YN4fqzX4IS8TrOZgYkNCvozMrnadyHncI013nR03e4qllY/p0m+jiGPp2K +h2RX5Rc64vmNueMzeMGQ2Ljdt4NR5MTMI9UGfOZR0800McD2RrsLrfw9EAUqO0qRJe6M1ISHgCq8 +CYyqOhNf6DR5UMEQGfnTKB7U0VEwKbOukGfWHwpjscWpxkIxYxeU72nLL/qMFH3EQxiJ2fAyQOaA +4kZf5ePBAFmo+eggvIksDkc0C+pXwlM2/KfUrzHN/gLldfq5Jwn58/U7yn2fqSLLiMmq0Uc9Nneo +WWRrJ8/vJ8HjJLWG965+Mk2weWjROeiQWMODvA8s1pfrzgzhIMfatz7DP78v3DSk+yshzWePS/Tj +6tQ/50+6uaWTRRxmHyH6ZF5v4HaUMst19W7l9o/HuKTMqJZ9ZPskWkoDbGs4xugDQ5r3V7mzKWmT +OPQD8rv7gmsHINFSH5pkAnuYZttcTVoP0ISVoDwUQwbKytu4QTbaakRnh6+v40URFWkIsr4WOZck +bxJF0WddCajJFdr60qZfE2Efv4WstK2tBZQIgx51F9NxO5NQI1mg7TyRVJ12AMXDuDjb +-----END CERTIFICATE----- diff --git a/cfg/alexnet.cfg b/cfg/alexnet.cfg new file mode 100644 index 0000000..e2ed4bb --- /dev/null +++ b/cfg/alexnet.cfg @@ -0,0 +1,96 @@ +[net] +# Training +# batch=128 +# subdivisions=1 +# Testing +batch=1 +subdivisions=1 +height=227 +width=227 +channels=3 +momentum=0.9 +decay=0.0005 +max_crop=256 + +learning_rate=0.01 +policy=poly +power=4 +max_batches=800000 + +angle=7 +hue = .1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +filters=96 +size=11 +stride=4 +pad=0 +activation=relu + +[maxpool] +size=3 +stride=2 +padding=0 + +[convolutional] +filters=256 +size=5 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=3 +stride=2 +padding=0 + +[convolutional] +filters=384 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=384 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=3 +stride=2 +padding=0 + +[connected] +output=4096 +activation=relu + +[dropout] +probability=.5 + +[connected] +output=4096 +activation=relu + +[dropout] +probability=.5 + +[connected] +output=1000 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/cifar.cfg b/cfg/cifar.cfg new file mode 100644 index 0000000..b2f69f5 --- /dev/null +++ b/cfg/cifar.cfg @@ -0,0 +1,121 @@ +[net] +batch=128 +subdivisions=1 +height=28 +width=28 +channels=3 +max_crop=32 +min_crop=32 + +hue=.1 +saturation=.75 +exposure=.75 + +learning_rate=0.4 +policy=poly +power=4 +max_batches = 5000 +momentum=0.9 +decay=0.0005 + + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[dropout] +probability=.5 + +[convolutional] +filters=10 +size=1 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[softmax] +groups=1 diff --git a/cfg/cifar.test.cfg b/cfg/cifar.test.cfg new file mode 100644 index 0000000..18b6c54 --- /dev/null +++ b/cfg/cifar.test.cfg @@ -0,0 +1,117 @@ +[net] +batch=128 +subdivisions=1 +height=32 +width=32 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.4 +policy=poly +power=4 +max_batches = 50000 + + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[dropout] +probability=.5 + +[convolutional] +filters=10 +size=1 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[softmax] +groups=1 +temperature=3 + diff --git a/cfg/coco.data b/cfg/coco.data new file mode 100644 index 0000000..3003841 --- /dev/null +++ b/cfg/coco.data @@ -0,0 +1,8 @@ +classes= 80 +train = /home/pjreddie/data/coco/trainvalno5k.txt +valid = coco_testdev +#valid = data/coco_val_5k.list +names = data/coco.names +backup = /home/pjreddie/backup/ +eval=coco + diff --git a/cfg/combine9k.data b/cfg/combine9k.data new file mode 100644 index 0000000..06a3e76 --- /dev/null +++ b/cfg/combine9k.data @@ -0,0 +1,10 @@ +classes= 9418 +#train = /home/pjreddie/data/coco/trainvalno5k.txt +train = data/combine9k.train.list +valid = /home/pjreddie/data/imagenet/det.val.files +labels = data/9k.labels +names = data/9k.names +backup = backup/ +map = data/inet9k.map +eval = imagenet +results = results diff --git a/cfg/darknet.cfg b/cfg/darknet.cfg new file mode 100644 index 0000000..375107f --- /dev/null +++ b/cfg/darknet.cfg @@ -0,0 +1,120 @@ +[net] +# Training +# batch=128 +# subdivisions=1 +# Testing +batch=1 +subdivisions=1 +height=256 +width=256 +min_crop=128 +max_crop=448 +channels=3 +momentum=0.9 +decay=0.0005 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + +[convolutional] +batch_normalize=1 +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/darknet19.cfg b/cfg/darknet19.cfg new file mode 100644 index 0000000..28ac966 --- /dev/null +++ b/cfg/darknet19.cfg @@ -0,0 +1,205 @@ +[net] +# Training +#batch=128 +#subdivisions=2 + +# Testing + batch=1 + subdivisions=1 + +height=256 +width=256 +min_crop=128 +max_crop=448 +channels=3 +momentum=0.9 +decay=0.0005 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 + diff --git a/cfg/darknet19_448.cfg b/cfg/darknet19_448.cfg new file mode 100644 index 0000000..c6df730 --- /dev/null +++ b/cfg/darknet19_448.cfg @@ -0,0 +1,197 @@ +[net] +batch=128 +subdivisions=4 +height=448 +width=448 +max_crop=512 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.001 +policy=poly +power=4 +max_batches=100000 + +angle=7 +hue = .1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 + diff --git a/cfg/darknet53.cfg b/cfg/darknet53.cfg new file mode 100644 index 0000000..7b6d576 --- /dev/null +++ b/cfg/darknet53.cfg @@ -0,0 +1,566 @@ +[net] +# Training +# batch=128 +# subdivisions=4 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/darknet53_448.cfg b/cfg/darknet53_448.cfg new file mode 100644 index 0000000..dedab1b --- /dev/null +++ b/cfg/darknet53_448.cfg @@ -0,0 +1,559 @@ +[net] +# Training - start training with darknet53.weights +# batch=128 +# subdivisions=8 + +# Testing +batch=1 +subdivisions=1 + +height=448 +width=448 +channels=3 +min_crop=448 +max_crop=512 + +learning_rate=0.001 +policy=poly +power=4 +max_batches=100000 +momentum=0.9 +decay=0.0005 + + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/darknet9000.cfg b/cfg/darknet9000.cfg new file mode 100644 index 0000000..9dd2dfb --- /dev/null +++ b/cfg/darknet9000.cfg @@ -0,0 +1,205 @@ +[net] +# Training +# batch=128 +# subdivisions=4 +# Testing +batch = 1 +subdivisions = 1 +height=448 +width=448 +max_crop=512 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.001 +policy=poly +power=4 +max_batches=100000 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=9418 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 +tree=data/9k.tree + +[cost] +type=masked + diff --git a/cfg/densenet201.cfg b/cfg/densenet201.cfg new file mode 100644 index 0000000..65b4aec --- /dev/null +++ b/cfg/densenet201.cfg @@ -0,0 +1,1951 @@ +[net] +# Training +# batch=128 +# subdivisions=4 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +max_crop=448 +channels=3 +momentum=0.9 +decay=0.0005 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=1600000 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1,-3 + + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 + diff --git a/cfg/extraction.cfg b/cfg/extraction.cfg new file mode 100644 index 0000000..66cb15f --- /dev/null +++ b/cfg/extraction.cfg @@ -0,0 +1,209 @@ +[net] +# Training +# batch=128 +# subdivisions=4 + +# Testing +batch=1 +subdivisions=1 + +height=224 +width=224 +max_crop=320 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.1 +policy=poly +power=4 +max_batches=1600000 + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[softmax] +groups=1 + diff --git a/cfg/extraction.conv.cfg b/cfg/extraction.conv.cfg new file mode 100644 index 0000000..2a7d09e --- /dev/null +++ b/cfg/extraction.conv.cfg @@ -0,0 +1,179 @@ +[net] +batch=1 +subdivisions=1 +height=256 +width=256 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.5 +policy=poly +power=6 +max_batches=500000 + +[convolutional] +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=192 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[connected] +output=1000 +activation=leaky + +[softmax] +groups=1 + diff --git a/cfg/extraction22k.cfg b/cfg/extraction22k.cfg new file mode 100644 index 0000000..b5f5409 --- /dev/null +++ b/cfg/extraction22k.cfg @@ -0,0 +1,206 @@ +[net] +batch=128 +subdivisions=1 +height=224 +width=224 +max_crop=320 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.01 +max_batches = 0 +policy=steps +steps=444000,590000,970000 +scales=.5,.2,.1 + +#policy=sigmoid +#gamma=.00008 +#step=100000 +#max_batches=200000 + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=3 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[connected] +output=21842 +activation=leaky + +[softmax] +groups=1 + diff --git a/cfg/go.cfg b/cfg/go.cfg new file mode 100644 index 0000000..c730092 --- /dev/null +++ b/cfg/go.cfg @@ -0,0 +1,132 @@ +[net] +batch=512 +subdivisions=1 +height=19 +width=19 +channels=1 +momentum=0.9 +decay=0.0005 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=10000000 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=1 +size=1 +stride=1 +pad=1 +activation=linear + +[reorg] +extra=1 +stride=1 + +[softmax] + diff --git a/cfg/go.test.cfg b/cfg/go.test.cfg new file mode 100644 index 0000000..1e4e438 --- /dev/null +++ b/cfg/go.test.cfg @@ -0,0 +1,132 @@ +[net] +batch=1 +subdivisions=1 +height=19 +width=19 +channels=1 +momentum=0.9 +decay=0.0005 + +learning_rate=0.01 +policy=poly +power=4 +max_batches=100000 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu +batch_normalize=1 + +[convolutional] +filters=1 +size=1 +stride=1 +pad=1 +activation=linear + +[reorg] +extra=1 +stride=1 + +[softmax] + + diff --git a/cfg/gru.cfg b/cfg/gru.cfg new file mode 100644 index 0000000..6064221 --- /dev/null +++ b/cfg/gru.cfg @@ -0,0 +1,29 @@ +[net] +inputs=256 +momentum=0.9 +decay=0.0 +subdivisions=1 +batch = 1 +time_steps=1 +learning_rate=.002 +adam=1 + +policy=constant +power=4 +max_batches=1000000 + +[gru] +output = 256 + +[gru] +output = 256 + +[gru] +output = 256 + +[connected] +output=256 +activation=linear + +[softmax] + diff --git a/cfg/imagenet1k.data b/cfg/imagenet1k.data new file mode 100644 index 0000000..6634a27 --- /dev/null +++ b/cfg/imagenet1k.data @@ -0,0 +1,8 @@ +classes=1000 +train = /data/imagenet/imagenet1k.train.list +valid = /data/imagenet/imagenet1k.valid.list +backup = /home/pjreddie/backup/ +labels = data/imagenet.labels.list +names = data/imagenet.shortnames.list +top=5 + diff --git a/cfg/imagenet22k.dataset b/cfg/imagenet22k.dataset new file mode 100644 index 0000000..e25ef00 --- /dev/null +++ b/cfg/imagenet22k.dataset @@ -0,0 +1,9 @@ +classes=21842 +train = /data/imagenet/imagenet22k.train.list +valid = /data/imagenet/imagenet22k.valid.list +#valid = /data/imagenet/imagenet1k.valid.list +backup = /home/pjreddie/backup/ +labels = data/imagenet.labels.list +names = data/imagenet.shortnames.list +top = 5 + diff --git a/cfg/imagenet9k.hierarchy.dataset b/cfg/imagenet9k.hierarchy.dataset new file mode 100644 index 0000000..41fb71b --- /dev/null +++ b/cfg/imagenet9k.hierarchy.dataset @@ -0,0 +1,9 @@ +classes=9418 +train = data/9k.train.list +valid = /data/imagenet/imagenet1k.valid.list +leaves = data/imagenet1k.labels +backup = /home/pjreddie/backup/ +labels = data/9k.labels +names = data/9k.names +top=5 + diff --git a/cfg/jnet-conv.cfg b/cfg/jnet-conv.cfg new file mode 100644 index 0000000..056f82a --- /dev/null +++ b/cfg/jnet-conv.cfg @@ -0,0 +1,118 @@ +[net] +batch=1 +subdivisions=1 +height=10 +width=10 +channels=3 +learning_rate=0.01 +momentum=0.9 +decay=0.0005 + +[convolutional] +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +stride=2 +size=2 + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +stride=2 +size=2 + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +stride=2 +size=2 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +stride=2 +size=2 + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +stride=2 +size=2 + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + diff --git a/cfg/openimages.data b/cfg/openimages.data new file mode 100644 index 0000000..fa80e5a --- /dev/null +++ b/cfg/openimages.data @@ -0,0 +1,8 @@ +classes= 601 +train = /home/pjreddie/data/openimsv4/openimages.train.list +#valid = coco_testdev +valid = data/coco_val_5k.list +names = data/openimages.names +backup = /home/pjreddie/backup/ +eval=coco + diff --git a/cfg/resnet101.cfg b/cfg/resnet101.cfg new file mode 100644 index 0000000..de45882 --- /dev/null +++ b/cfg/resnet101.cfg @@ -0,0 +1,990 @@ +[net] +# Training +# batch=128 +# subdivisions=2 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +# Conv 4 +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +#Conv 5 +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + + + + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 + +[cost] +type=sse + diff --git a/cfg/resnet152.cfg b/cfg/resnet152.cfg new file mode 100644 index 0000000..e8e3297 --- /dev/null +++ b/cfg/resnet152.cfg @@ -0,0 +1,1460 @@ +[net] +# Training +# batch=128 +# subdivisions=8 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +max_crop=448 +channels=3 +momentum=0.9 +decay=0.0005 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=1600000 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +# Conv 4 +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +#Conv 5 +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + + + + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 + diff --git a/cfg/resnet18.cfg b/cfg/resnet18.cfg new file mode 100644 index 0000000..275f4bd --- /dev/null +++ b/cfg/resnet18.cfg @@ -0,0 +1,228 @@ +[net] +# Training +# batch=128 +# subdivisions=1 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + + +# Residual Block +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Strided Residual Block +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + + +# Strided Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + + +# Strided Residual Block +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + + + + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/resnet34.cfg b/cfg/resnet34.cfg new file mode 100644 index 0000000..9f68f09 --- /dev/null +++ b/cfg/resnet34.cfg @@ -0,0 +1,392 @@ +[net] +# Training +# batch=128 +# subdivisions=2 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Strided Residual Block +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Strided Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + +# Residual Block +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=linear + +[shortcut] +activation=leaky +from=-3 + + + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/resnet50.cfg b/cfg/resnet50.cfg new file mode 100644 index 0000000..d0d7c51 --- /dev/null +++ b/cfg/resnet50.cfg @@ -0,0 +1,510 @@ +[net] +# Training +# batch=128 +# subdivisions=4 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +# Conv 4 +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +#Conv 5 +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + + + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + + diff --git a/cfg/resnext101-32x4d.cfg b/cfg/resnext101-32x4d.cfg new file mode 100644 index 0000000..8538ccc --- /dev/null +++ b/cfg/resnext101-32x4d.cfg @@ -0,0 +1,1053 @@ +[net] +# Training +# batch=128 +# subdivisions=8 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=4096 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=4096 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=4096 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/resnext152-32x4d.cfg b/cfg/resnext152-32x4d.cfg new file mode 100644 index 0000000..48279fd --- /dev/null +++ b/cfg/resnext152-32x4d.cfg @@ -0,0 +1,1562 @@ +[net] +# Training +# batch=128 +# subdivisions=16 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=4096 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=4096 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +groups = 32 +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=4096 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + + + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + diff --git a/cfg/resnext50.cfg b/cfg/resnext50.cfg new file mode 100644 index 0000000..12aebdf --- /dev/null +++ b/cfg/resnext50.cfg @@ -0,0 +1,523 @@ +[net] +# Training +# batch=128 +# subdivisions=4 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +min_crop=128 +max_crop=448 + +burn_in=1000 +learning_rate=0.1 +policy=poly +power=4 +max_batches=800000 +momentum=0.9 +decay=0.0005 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + + + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +groups=32 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + + +# Conv 4 +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +groups=32 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +#Conv 5 +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +groups=32 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +groups=32 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=2048 +size=1 +stride=1 +pad=1 +activation=linear + +[shortcut] +from=-4 +activation=leaky + +[avgpool] + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[softmax] +groups=1 + + diff --git a/cfg/rnn.cfg b/cfg/rnn.cfg new file mode 100644 index 0000000..61b202f --- /dev/null +++ b/cfg/rnn.cfg @@ -0,0 +1,38 @@ +[net] +subdivisions=1 +inputs=256 +batch = 1 +momentum=0.9 +decay=0.001 +max_batches = 2000 +time_steps=1 +learning_rate=0.1 +policy=steps +steps=1000,1500 +scales=.1,.1 + +[rnn] +batch_normalize=1 +output = 1024 +hidden=1024 +activation=leaky + +[rnn] +batch_normalize=1 +output = 1024 +hidden=1024 +activation=leaky + +[rnn] +batch_normalize=1 +output = 1024 +hidden=1024 +activation=leaky + +[connected] +output=256 +activation=leaky + +[softmax] + + diff --git a/cfg/rnn.train.cfg b/cfg/rnn.train.cfg new file mode 100644 index 0000000..b974899 --- /dev/null +++ b/cfg/rnn.train.cfg @@ -0,0 +1,38 @@ +[net] +subdivisions=1 +inputs=256 +batch = 128 +momentum=0.9 +decay=0.001 +max_batches = 2000 +time_steps=576 +learning_rate=0.1 +policy=steps +steps=1000,1500 +scales=.1,.1 + +[rnn] +batch_normalize=1 +output = 1024 +hidden=1024 +activation=leaky + +[rnn] +batch_normalize=1 +output = 1024 +hidden=1024 +activation=leaky + +[rnn] +batch_normalize=1 +output = 1024 +hidden=1024 +activation=leaky + +[connected] +output=256 +activation=leaky + +[softmax] + + diff --git a/cfg/strided.cfg b/cfg/strided.cfg new file mode 100644 index 0000000..2f74508 --- /dev/null +++ b/cfg/strided.cfg @@ -0,0 +1,182 @@ +[net] +batch=128 +subdivisions=4 +height=256 +width=256 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.01 +policy=steps +scales=.1,.1,.1 +steps=200000,300000,400000 +max_batches=800000 + + +[crop] +crop_height=224 +crop_width=224 +flip=1 +angle=0 +saturation=1 +exposure=1 +shift=.2 + +[convolutional] +filters=64 +size=7 +stride=2 +pad=1 +activation=ramp + +[convolutional] +filters=192 +size=3 +stride=2 +pad=1 +activation=ramp + +[convolutional] +filters=128 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=3 +stride=2 +pad=1 +activation=ramp + +[convolutional] +filters=128 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=128 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=512 +size=3 +stride=2 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=256 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=1024 +size=3 +stride=2 +pad=1 +activation=ramp + +[convolutional] +filters=512 +size=1 +stride=1 +pad=1 +activation=ramp + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=ramp + +[maxpool] +size=3 +stride=2 + +[connected] +output=4096 +activation=ramp + +[dropout] +probability=0.5 + +[connected] +output=1000 +activation=ramp + +[softmax] + diff --git a/cfg/t1.test.cfg b/cfg/t1.test.cfg new file mode 100644 index 0000000..b362811 --- /dev/null +++ b/cfg/t1.test.cfg @@ -0,0 +1,117 @@ +[net] +batch=1 +subdivisions=1 +height=224 +width=224 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.0005 +policy=steps +steps=200,400,600,20000,30000 +scales=2.5,2,2,.1,.1 +max_batches = 40000 + +[convolutional] +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[connected] +output= 1470 +activation=linear + +[detection] +classes=20 +coords=4 +rescore=1 +side=7 +num=2 +softmax=0 +sqrt=1 +jitter=.2 + +object_scale=1 +noobject_scale=.5 +class_scale=1 +coord_scale=5 + diff --git a/cfg/tiny.cfg b/cfg/tiny.cfg new file mode 100644 index 0000000..f97327c --- /dev/null +++ b/cfg/tiny.cfg @@ -0,0 +1,174 @@ +[net] +# Train +batch=128 +subdivisions=1 +# Test +# batch=1 +# subdivisions=1 +height=224 +width=224 +channels=3 +momentum=0.9 +decay=0.0005 +max_crop=320 + +learning_rate=0.1 +policy=poly +power=4 +max_batches=1600000 + +angle=7 +hue=.1 +saturation=.75 +exposure=.75 +aspect=.75 + +[convolutional] +batch_normalize=1 +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=16 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=16 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1000 +size=1 +stride=1 +pad=1 +activation=linear + +[avgpool] + +[softmax] +groups=1 + + diff --git a/cfg/vgg-16.cfg b/cfg/vgg-16.cfg new file mode 100644 index 0000000..c73b17b --- /dev/null +++ b/cfg/vgg-16.cfg @@ -0,0 +1,157 @@ +[net] +# Training +# batch=128 +# subdivisions=4 + +# Testing +batch=1 +subdivisions=1 + +height=256 +width=256 +channels=3 +learning_rate=0.00001 +momentum=0.9 +decay=0.0005 + +[crop] +crop_height=224 +crop_width=224 +flip=1 +exposure=1 +saturation=1 +angle=0 + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[connected] +output=4096 +activation=relu + +[dropout] +probability=.5 + +[connected] +output=4096 +activation=relu + +[dropout] +probability=.5 + +[connected] +output=1000 +activation=linear + +[softmax] +groups=1 + + diff --git a/cfg/vgg-conv.cfg b/cfg/vgg-conv.cfg new file mode 100644 index 0000000..21e1d72 --- /dev/null +++ b/cfg/vgg-conv.cfg @@ -0,0 +1,121 @@ +[net] +batch=1 +subdivisions=1 +width=224 +height=224 +channels=3 +learning_rate=0.00001 +momentum=0.9 +decay=0.0005 + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=64 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=128 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=256 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[convolutional] +filters=512 +size=3 +stride=1 +pad=1 +activation=relu + +[maxpool] +size=2 +stride=2 + diff --git a/cfg/voc.data b/cfg/voc.data new file mode 100644 index 0000000..7807b5d --- /dev/null +++ b/cfg/voc.data @@ -0,0 +1,6 @@ +classes= 20 +train = /home/pjreddie/data/voc/train.txt +valid = /home/pjreddie/data/voc/2007_test.txt +names = data/voc.names +backup = backup + diff --git a/cfg/writing.cfg b/cfg/writing.cfg new file mode 100644 index 0000000..1ed899b --- /dev/null +++ b/cfg/writing.cfg @@ -0,0 +1,41 @@ +[net] +batch=128 +subdivisions=2 +height=256 +width=256 +channels=3 +learning_rate=0.00000001 +momentum=0.9 +decay=0.0005 +seen=0 + +[convolutional] +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=1 +size=3 +stride=1 +pad=1 +activation=logistic + +[cost] + diff --git a/cfg/yolo9000.cfg b/cfg/yolo9000.cfg new file mode 100644 index 0000000..e745f78 --- /dev/null +++ b/cfg/yolo9000.cfg @@ -0,0 +1,218 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=8 +batch=1 +subdivisions=1 +height=544 +width=544 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +hue=.1 +saturation=.75 +exposure=.75 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +filters=28269 +size=1 +stride=1 +pad=1 +activation=linear + +[region] +anchors = 0.77871, 1.14074, 3.00525, 4.31277, 9.22725, 9.61974 +bias_match=1 +classes=9418 +coords=4 +num=3 +softmax=1 +jitter=.2 +rescore=1 + +object_scale=5 +noobject_scale=1 +class_scale=1 +coord_scale=1 + +thresh = .6 +absolute=1 +random=1 + +tree=data/9k.tree +map = data/coco9k.map diff --git a/cfg/yolov1-tiny.cfg b/cfg/yolov1-tiny.cfg new file mode 100644 index 0000000..a5e7b49 --- /dev/null +++ b/cfg/yolov1-tiny.cfg @@ -0,0 +1,130 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=8 +height=448 +width=448 +channels=3 +momentum=0.9 +decay=0.0005 + +saturation=.75 +exposure=.75 +hue = .1 + +learning_rate=0.0005 +policy=steps +steps=200,400,600,800,20000,30000 +scales=2.5,2,2,2,.1,.1 +max_batches = 40000 + +[convolutional] +batch_normalize=1 +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[connected] +output= 1470 +activation=linear + +[detection] +classes=20 +coords=4 +rescore=1 +side=7 +num=2 +softmax=0 +sqrt=1 +jitter=.2 + +object_scale=1 +noobject_scale=.5 +class_scale=1 +coord_scale=5 + diff --git a/cfg/yolov1.cfg b/cfg/yolov1.cfg new file mode 100644 index 0000000..06cf6e6 --- /dev/null +++ b/cfg/yolov1.cfg @@ -0,0 +1,261 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=8 +height=448 +width=448 +channels=3 +momentum=0.9 +decay=0.0005 +saturation=1.5 +exposure=1.5 +hue=.1 + +learning_rate=0.0005 +policy=steps +steps=200,400,600,20000,30000 +scales=2.5,2,2,.1,.1 +max_batches = 40000 + +[convolutional] +batch_normalize=1 +filters=64 +size=7 +stride=2 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +####### + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[local] +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[dropout] +probability=.5 + +[connected] +output= 1715 +activation=linear + +[detection] +classes=20 +coords=4 +rescore=1 +side=7 +num=3 +softmax=0 +sqrt=1 +jitter=.2 + +object_scale=1 +noobject_scale=.5 +class_scale=1 +coord_scale=5 + diff --git a/cfg/yolov2-tiny-voc.cfg b/cfg/yolov2-tiny-voc.cfg new file mode 100644 index 0000000..c4c127c --- /dev/null +++ b/cfg/yolov2-tiny-voc.cfg @@ -0,0 +1,138 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=2 +width=416 +height=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +max_batches = 40200 +policy=steps +steps=-1,100,20000,30000 +scales=.1,10,.1,.1 + +[convolutional] +batch_normalize=1 +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=1 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +########### + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=125 +activation=linear + +[region] +anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 +bias_match=1 +classes=20 +coords=4 +num=5 +softmax=1 +jitter=.2 +rescore=1 + +object_scale=5 +noobject_scale=1 +class_scale=1 +coord_scale=1 + +absolute=1 +thresh = .6 +random=1 diff --git a/cfg/yolov2-tiny.cfg b/cfg/yolov2-tiny.cfg new file mode 100644 index 0000000..81d0ac4 --- /dev/null +++ b/cfg/yolov2-tiny.cfg @@ -0,0 +1,139 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=2 +width=416 +height=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=1 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +########### + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=425 +activation=linear + +[region] +anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 +bias_match=1 +classes=80 +coords=4 +num=5 +softmax=1 +jitter=.2 +rescore=0 + +object_scale=5 +noobject_scale=1 +class_scale=1 +coord_scale=1 + +absolute=1 +thresh = .6 +random=1 diff --git a/cfg/yolov2-voc.cfg b/cfg/yolov2-voc.cfg new file mode 100644 index 0000000..dbf2de2 --- /dev/null +++ b/cfg/yolov2-voc.cfg @@ -0,0 +1,258 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=8 +height=416 +width=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 80200 +policy=steps +steps=40000,60000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + + +####### + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[route] +layers=-9 + +[convolutional] +batch_normalize=1 +size=1 +stride=1 +pad=1 +filters=64 +activation=leaky + +[reorg] +stride=2 + +[route] +layers=-1,-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=125 +activation=linear + + +[region] +anchors = 1.3221, 1.73145, 3.19275, 4.00944, 5.05587, 8.09892, 9.47112, 4.84053, 11.2364, 10.0071 +bias_match=1 +classes=20 +coords=4 +num=5 +softmax=1 +jitter=.3 +rescore=1 + +object_scale=5 +noobject_scale=1 +class_scale=1 +coord_scale=1 + +absolute=1 +thresh = .6 +random=1 diff --git a/cfg/yolov2.cfg b/cfg/yolov2.cfg new file mode 100644 index 0000000..088edf8 --- /dev/null +++ b/cfg/yolov2.cfg @@ -0,0 +1,258 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=8 +width=608 +height=608 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + + +####### + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[route] +layers=-9 + +[convolutional] +batch_normalize=1 +size=1 +stride=1 +pad=1 +filters=64 +activation=leaky + +[reorg] +stride=2 + +[route] +layers=-1,-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=425 +activation=linear + + +[region] +anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 +bias_match=1 +classes=80 +coords=4 +num=5 +softmax=1 +jitter=.3 +rescore=1 + +object_scale=5 +noobject_scale=1 +class_scale=1 +coord_scale=1 + +absolute=1 +thresh = .6 +random=1 diff --git a/cfg/yolov3-openimages.cfg b/cfg/yolov3-openimages.cfg new file mode 100644 index 0000000..65d241a --- /dev/null +++ b/cfg/yolov3-openimages.cfg @@ -0,0 +1,789 @@ +[net] +# Testing + batch=1 + subdivisions=1 +# Training +batch=64 +subdivisions=16 +width=608 +height=608 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=5000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +###################### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=1818 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=601 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 61 + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=1818 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=601 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 36 + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=1818 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=601 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + diff --git a/cfg/yolov3-spp.cfg b/cfg/yolov3-spp.cfg new file mode 100644 index 0000000..4ad2a05 --- /dev/null +++ b/cfg/yolov3-spp.cfg @@ -0,0 +1,822 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=16 +width=608 +height=608 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +###################### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 + +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 61 + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 36 + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + diff --git a/cfg/yolov3-tiny.cfg b/cfg/yolov3-tiny.cfg new file mode 100644 index 0000000..cfca3cf --- /dev/null +++ b/cfg/yolov3-tiny.cfg @@ -0,0 +1,182 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +# batch=64 +# subdivisions=2 +width=416 +height=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=16 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=1 + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +########### + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + + +[yolo] +mask = 3,4,5 +anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 +classes=80 +num=6 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 8 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 0,1,2 +anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 +classes=80 +num=6 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 diff --git a/cfg/yolov3-voc.cfg b/cfg/yolov3-voc.cfg new file mode 100644 index 0000000..3f3e8df --- /dev/null +++ b/cfg/yolov3-voc.cfg @@ -0,0 +1,785 @@ +[net] +# Testing + batch=1 + subdivisions=1 +# Training +# batch=64 +# subdivisions=16 +width=416 +height=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 50200 +policy=steps +steps=40000,45000 +scales=.1,.1 + + + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +###################### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=75 +activation=linear + +[yolo] +mask = 6,7,8 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=20 +num=9 +jitter=.3 +ignore_thresh = .5 +truth_thresh = 1 +random=1 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 61 + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=75 +activation=linear + +[yolo] +mask = 3,4,5 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=20 +num=9 +jitter=.3 +ignore_thresh = .5 +truth_thresh = 1 +random=1 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 36 + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=75 +activation=linear + +[yolo] +mask = 0,1,2 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=20 +num=9 +jitter=.3 +ignore_thresh = .5 +truth_thresh = 1 +random=1 + diff --git a/cfg/yolov3.cfg b/cfg/yolov3.cfg new file mode 100644 index 0000000..938ffff --- /dev/null +++ b/cfg/yolov3.cfg @@ -0,0 +1,789 @@ +[net] +# Testing +# batch=1 +# subdivisions=1 +# Training +batch=64 +subdivisions=16 +width=608 +height=608 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=1 +pad=1 +activation=leaky + +[shortcut] +from=-3 +activation=linear + +###################### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 61 + + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 36 + + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 + diff --git a/data/9k.labels b/data/9k.labels new file mode 100644 index 0000000..e2bd308 --- /dev/null +++ b/data/9k.labels @@ -0,0 +1,9418 @@ +n00002452 +n00020827 +n00002684 +n11425580 +n05220461 +n09225146 +n05538625 +n01900150 +n05225602 +n05418717 +n05302499 +n05578095 +n09475179 +n09376198 +n14877585 +n15046900 +n00019613 +n00021265 +n15067877 +n09436708 +n14915184 +n07555863 +n07850329 +n07849336 +n07705711 +n07622061 +n07594066 +n07854982 +n07852833 +n07852614 +n07854184 +n07852229 +n07851443 +n07705931 +n07707451 +n07752966 +n07760859 +n07747055 +n07754684 +n07768694 +n07764847 +n07768858 +n07739125 +n07746551 +n07753113 +n07763987 +n07748574 +n07751451 +n07762244 +n07750872 +n07742704 +n07765208 +n07763792 +n07767847 +n07766173 +n07751004 +n07760153 +n07758680 +n07753592 +n07751280 +n07769731 +n07763629 +n07755411 +n07754451 +n07753275 +n07764155 +n07765073 +n07762114 +n07762913 +n07753743 +n07765999 +n07765361 +n07752377 +n07757132 +n07769584 +n07751148 +n07761141 +n07761309 +n07749731 +n07747951 +n07749446 +n07747607 +n07749582 +n07750449 +n07749969 +n07750146 +n07748157 +n07748416 +n07748276 +n07748912 +n07748753 +n07749192 +n07749312 +n07739344 +n07739506 +n07742313 +n07740220 +n07740954 +n07740461 +n07740342 +n07745940 +n07767171 +n07744246 +n07744057 +n07744811 +n07744682 +n07745466 +n07743902 +n07746334 +n07746186 +n07743544 +n07743224 +n07755707 +n07756951 +n07755929 +n07757990 +n07757312 +n07757511 +n07734744 +n07719213 +n07768423 +n07735510 +n07718472 +n07710283 +n07713395 +n07708398 +n07710007 +n07718747 +n07708798 +n07723039 +n07715561 +n07709333 +n07730406 +n07730033 +n07733394 +n07713267 +n07722217 +n07817871 +n07736813 +n07719839 +n07712267 +n07730207 +n07710616 +n07710952 +n07711569 +n07711080 +n07713763 +n07713895 +n07733567 +n07715103 +n07715221 +n07715407 +n07714990 +n07735687 +n07735803 +n07714188 +n07714448 +n07714895 +n07714571 +n07714078 +n07720442 +n07734017 +n07713074 +n07734555 +n07720615 +n07721325 +n07720875 +n07721195 +n07721018 +n07721456 +n07722052 +n07721942 +n07721678 +n07734292 +n07734183 +n07724943 +n07725376 +n07726095 +n07725255 +n07729485 +n07726796 +n07727458 +n07727048 +n07727578 +n07727868 +n07728804 +n07728053 +n07728585 +n07728181 +n07729384 +n07729828 +n07725531 +n07725789 +n07725888 +n07715721 +n07717070 +n07716906 +n07716358 +n07716034 +n07717556 +n07717410 +n07720277 +n07736256 +n07723330 +n07719616 +n07736692 +n07733712 +n07732747 +n07730855 +n07731587 +n07731006 +n07723559 +n07724654 +n07724269 +n07724492 +n07722485 +n07723177 +n07722888 +n07639069 +n07679356 +n07682197 +n07680517 +n07695878 +n07685730 +n07682316 +n07684517 +n07680761 +n07681691 +n07684600 +n07684164 +n07686720 +n07680932 +n07687211 +n07681450 +n07683786 +n07695742 +n07682477 +n07686873 +n07684289 +n07683490 +n07682808 +n07690585 +n07684938 +n07690892 +n07685399 +n07693972 +n07690273 +n07691091 +n07687789 +n07685218 +n07694516 +n07694839 +n07694659 +n07690511 +n07690739 +n07690431 +n07688624 +n07688898 +n07689003 +n07690152 +n07693725 +n07690019 +n07692614 +n07691758 +n07691539 +n07691650 +n07693223 +n07693048 +n07691237 +n07687626 +n07687381 +n07687469 +n07871810 +n07684084 +n14580897 +n15062057 +n14698884 +n14696793 +n14765422 +n14844693 +n15019030 +n12167075 +n14974264 +n14858292 +n15075141 +n04033425 +n07556637 +n07566340 +n07560652 +n07881800 +n07938313 +n07800091 +n07570720 +n01464844 +n07556406 +n07840804 +n07802417 +n07925608 +n07844867 +n07569644 +n07568502 +n07809096 +n07843775 +n07755089 +n07882497 +n07573347 +n07923748 +n07572957 +n07731952 +n07804323 +n07804771 +n07803093 +n07803545 +n07732168 +n07732636 +n07804657 +n07804900 +n07809368 +n07841345 +n07827284 +n07827130 +n07822518 +n07827410 +n07816052 +n07812184 +n07810907 +n07858595 +n07811416 +n07824702 +n07818277 +n07819769 +n07920989 +n07822323 +n07815424 +n07814390 +n07826930 +n07814487 +n07814203 +n07583066 +n07822845 +n07767344 +n07823105 +n07828987 +n07582609 +n07825972 +n07823460 +n07823698 +n07822197 +n07856270 +n07767709 +n07829412 +n07829331 +n07829248 +n07857731 +n07857170 +n07838233 +n07836838 +n07826091 +n07830593 +n07840027 +n07832416 +n07832902 +n07835921 +n07835457 +n07831146 +n07831267 +n07834618 +n07834507 +n07595914 +n07858978 +n07859583 +n07860103 +n07860331 +n07860447 +n07816164 +n07818689 +n07821260 +n07820683 +n07816575 +n07817160 +n07817315 +n07819166 +n07817024 +n07818995 +n07816398 +n07820497 +n07932841 +n07820145 +n07819896 +n07816296 +n07821758 +n07933154 +n07935379 +n07935043 +n07847198 +n07844042 +n07848196 +n07847453 +n07847917 +n07847827 +n07678729 +n07860805 +n07860988 +n07883031 +n07623136 +n07861158 +n07627931 +n07628068 +n07565161 +n07565083 +n07561590 +n07561112 +n07560903 +n07562495 +n07564971 +n07938149 +n07938007 +n07884567 +n07924033 +n07919310 +n07891189 +n07922764 +n07929519 +n07921455 +n07933274 +n07927197 +n07925966 +n07891309 +n07936263 +n07883251 +n07914271 +n07911371 +n07901587 +n07891433 +n07891726 +n07886176 +n07886057 +n07907943 +n07921615 +n07886572 +n07902121 +n07886463 +n07912211 +n07911677 +n07914777 +n07930554 +n07930433 +n07930315 +n07915491 +n07915094 +n07913393 +n07916041 +n07914995 +n07916183 +n07914413 +n07917392 +n07917133 +n07915918 +n07930864 +n07931870 +n07932039 +n07930062 +n07906111 +n07907037 +n07902799 +n07904865 +n07905474 +n07902937 +n07904395 +n07905038 +n07902336 +n07905979 +n07903101 +n07904760 +n07903208 +n07904934 +n07906284 +n07902443 +n07903841 +n07903962 +n07903731 +n07903643 +n07907161 +n07906718 +n07907831 +n07907548 +n07907429 +n07906877 +n07906572 +n07893253 +n07892418 +n07893642 +n07899003 +n07896287 +n07896661 +n07893528 +n07896165 +n07900225 +n07893891 +n07900406 +n07895237 +n07898745 +n07896060 +n07899108 +n07892512 +n07897750 +n07892813 +n07894703 +n07894102 +n07894551 +n07900616 +n07900958 +n07900734 +n07900825 +n07901457 +n07898117 +n07895435 +n07899434 +n07899292 +n07894298 +n07895595 +n07894965 +n07897865 +n07895839 +n07895710 +n07898333 +n07897438 +n07895962 +n07896893 +n07899899 +n07895100 +n07898443 +n07899533 +n07894799 +n07897975 +n07899660 +n07894451 +n07910656 +n07909593 +n07911249 +n07910048 +n07908411 +n07910379 +n07908647 +n07886849 +n07887634 +n07887099 +n07889510 +n07887192 +n07887304 +n07888229 +n07887967 +n07889274 +n07887461 +n07888465 +n07890226 +n07890352 +n07889814 +n07890068 +n07890540 +n07888816 +n07924834 +n07924443 +n07924276 +n07920540 +n07920222 +n07920052 +n07920349 +n07919441 +n07731284 +n07919572 +n07920872 +n07921239 +n07934282 +n07933799 +n07929172 +n07927931 +n07928488 +n07928367 +n07927512 +n07928887 +n07928696 +n07928790 +n07936745 +n07935737 +n07936548 +n07801508 +n07805594 +n07800740 +n07801091 +n07802026 +n07801779 +n07801892 +n07557165 +n07560193 +n07651025 +n07560331 +n07557434 +n07556970 +n05399243 +n15089258 +n07560542 +n07573696 +n07613815 +n07643981 +n07596684 +n07600696 +n07597145 +n07597365 +n07599998 +n07596967 +n07620689 +n07642471 +n07643200 +n07642742 +n07643026 +n07642933 +n07643306 +n07606538 +n07599911 +n07607138 +n07608429 +n07598256 +n07606669 +n07607605 +n07601572 +n07609632 +n07605597 +n07607967 +n07609215 +n07841907 +n07606764 +n07605944 +n07601686 +n07605380 +n07605040 +n07601809 +n07605474 +n07842130 +n07842044 +n07600285 +n07600177 +n07842202 +n07579688 +n07580053 +n07588947 +n07842753 +n07583197 +n07879350 +n07880751 +n07868200 +n07863802 +n07875152 +n07824191 +n07878785 +n07865484 +n07866015 +n07868955 +n07861557 +n07580253 +n07877187 +n07866868 +n07880458 +n07648913 +n07580470 +n07866277 +n07591961 +n07868508 +n07871436 +n07864934 +n07874780 +n07879659 +n07878926 +n07937461 +n07842433 +n07862611 +n07863374 +n07866723 +n07867021 +n07867164 +n07726525 +n07624466 +n07842308 +n07877299 +n07880080 +n07862348 +n07873464 +n07869775 +n07879953 +n07625061 +n07843636 +n07696403 +n07580592 +n07655263 +n07868340 +n07619004 +n07879174 +n07867324 +n07843464 +n07877961 +n07873807 +n07867421 +n07654298 +n07878647 +n07611839 +n07842605 +n07871720 +n07869611 +n07876651 +n07880968 +n07875436 +n07806221 +n07841495 +n07823951 +n07712382 +n07591586 +n07590320 +n07587111 +n07592481 +n07590611 +n07591473 +n07590502 +n07591049 +n07592768 +n07585758 +n07588193 +n07586894 +n07588299 +n07584110 +n07587441 +n07587023 +n07586099 +n07588574 +n07584332 +n07586604 +n07586718 +n07585107 +n07585557 +n07585208 +n07584593 +n07585906 +n07584423 +n07587618 +n07587700 +n07588111 +n07704054 +n07704205 +n07871234 +n07870167 +n07863547 +n07700003 +n07619208 +n07619409 +n07874159 +n07874343 +n07874259 +n07874441 +n07874063 +n07867751 +n07867616 +n07808587 +n07807834 +n07806633 +n07807171 +n07807710 +n07807922 +n07808904 +n07806774 +n07807472 +n07841639 +n07841800 +n07695965 +n07712748 +n07712559 +n07697825 +n07697313 +n07696728 +n07696625 +n07698543 +n07698401 +n07865105 +n07696977 +n07698250 +n07698782 +n07697100 +n07696839 +n07697537 +n07712856 +n07712959 +n07579575 +n07579787 +n07609840 +n07581346 +n07611991 +n07613266 +n07611358 +n07612632 +n07612996 +n07613480 +n07611267 +n07612367 +n07611148 +n07611046 +n07617611 +n07612137 +n07616386 +n07631926 +n07615774 +n07616487 +n07614730 +n07614500 +n07614198 +n07616748 +n07616046 +n07617051 +n07615671 +n07615190 +n07614825 +n07615460 +n07617708 +n07618432 +n07582152 +n07734879 +n07581775 +n07582277 +n07730320 +n07581249 +n15089645 +n15089472 +n15093137 +n15093298 +n15090742 +n15091473 +n14919819 +n15091669 +n14810561 +n14973585 +n15091304 +n15091846 +n15092227 +n15090065 +n07576438 +n07577374 +n07575984 +n07574602 +n07574426 +n07593199 +n07576182 +n07574923 +n07574780 +n07575726 +n07575076 +n07578093 +n07576577 +n07577144 +n07576781 +n07574504 +n07577538 +n09335240 +n00027167 +n09334396 +n09283193 +n03892891 +n09287968 +n03059685 +n00003553 +n09300905 +n09452395 +n09260907 +n08630039 +n08630985 +n09386842 +n08593262 +n08620061 +n09379111 +n08649711 +n08658309 +n08568978 +n08512259 +n03823111 +n04170933 +n09433839 +n08578517 +n08640739 +n08574314 +n08552138 +n08645104 +n08505018 +n08659861 +n08659446 +n08673395 +n08583455 +n08598301 +n08651247 +n03120491 +n02802544 +n08614632 +n08674739 +n08569998 +n08494231 +n08677424 +n08616050 +n08518171 +n08573842 +n08521623 +n03368352 +n03417345 +n04454908 +n03902482 +n04610879 +n08579352 +n03963645 +n03417749 +n08524735 +n08537837 +n08551296 +n08628141 +n08633683 +n08539072 +n09249034 +n09263912 +n08583292 +n09443281 +n08547544 +n08664443 +n04602044 +n08580944 +n03581125 +n08517676 +n08598568 +n08584914 +n03899933 +n02776631 +n03322099 +n03935234 +n04052442 +n03159535 +n15102894 +n09242389 +n09382099 +n09282208 +n09392402 +n09393605 +n09445289 +n03030880 +n03946162 +n03485997 +n03882960 +n04322026 +n03474896 +n02764398 +n02907082 +n03948830 +n09205509 +n09472413 +n09443453 +n09309292 +n09366017 +n09366317 +n09376786 +n09348460 +n09246464 +n09433442 +n09454153 +n09409752 +n09403734 +n09331251 +n09437454 +n09238926 +n09283866 +n09217230 +n09305898 +n09288635 +n09308743 +n09308572 +n09194227 +n09289331 +n09468604 +n09344324 +n09335809 +n09435739 +n09215437 +n09259219 +n09217638 +n09304750 +n09206896 +n09405787 +n09233446 +n09290444 +n09457979 +n09245515 +n09376526 +n09415671 +n09448690 +n09230041 +n09398076 +n09453008 +n09303008 +n09359803 +n09302616 +n09409512 +n09399592 +n09199101 +n09230202 +n09283405 +n09326662 +n09193705 +n09218641 +n09472597 +n09421951 +n09270735 +n09406793 +n09213434 +n09256479 +n09210862 +n09421799 +n09224725 +n09396465 +n09362945 +n09259025 +n09398677 +n09428293 +n09447666 +n09332890 +n08596076 +n09428628 +n09361517 +n09265620 +n09303528 +n09436444 +n09274152 +n09213565 +n09269472 +n09206985 +n09228055 +n09466678 +n09415584 +n09475925 +n09257843 +n09239302 +n09294877 +n00021939 +n00004258 +n00019128 +n02749953 +n02852523 +n03767112 +n14977504 +n03129123 +n03848729 +n03964744 +n04362025 +n04469003 +n04341686 +n03575240 +n03873064 +n03122748 +n03309808 +n02871147 +n03364340 +n14786479 +n03169390 +n04564698 +n04339291 +n00022903 +n03315023 +n03302121 +n03076708 +n04188643 +n03354613 +n14976871 +n03670849 +n02917521 +n04414909 +n04435180 +n02725872 +n04076846 +n02743547 +n03816849 +n04007894 +n03934656 +n03720163 +n04227144 +n04260364 +n03925226 +n04564581 +n02744844 +n04042358 +n03927091 +n03927539 +n03876519 +n04485423 +n03835197 +n03342127 +n04246271 +n04321238 +n04180314 +n03625783 +n03684611 +n03514693 +n03421485 +n04026180 +n02870526 +n04599396 +n06415688 +n03822171 +n04582205 +n03727605 +n03849679 +n04598792 +n03631922 +n02933649 +n03600722 +n03169176 +n03418618 +n02727016 +n03526198 +n03794798 +n03859608 +n03968581 +n03717447 +n03614782 +n03915900 +n04431025 +n03974070 +n02779435 +n03941231 +n04399382 +n03603442 +n09229709 +n03548402 +n03944138 +n04238128 +n04284869 +n03061211 +n03219135 +n09282724 +n09191635 +n09443641 +n04186268 +n03447358 +n03607029 +n03536348 +n02857023 +n04381860 +n04213626 +n03961939 +n04394630 +n03365592 +n04501550 +n04296562 +n03159640 +n04354182 +n03549732 +n03360300 +n03892178 +n02768973 +n03906224 +n03313333 +n02990373 +n02861886 +n03365991 +n02898711 +n03109693 +n13898207 +n04358874 +n02687821 +n03135532 +n03545756 +n03548626 +n03469175 +n03688943 +n02914991 +n04191595 +n09218315 +n03074380 +n02699494 +n02733524 +n04460130 +n04471148 +n03792048 +n03388043 +n03837869 +n03321954 +n02733213 +n03687137 +n03065424 +n02839110 +n03894379 +n03725717 +n04226464 +n03071160 +n03839993 +n02913152 +n04128413 +n04008947 +n03917198 +n03222318 +n04295881 +n03241335 +n02735688 +n02777734 +n03984381 +n03216828 +n03517899 +n03546340 +n04361095 +n13897996 +n03171356 +n03290195 +n03743902 +n03297735 +n04217882 +n02863426 +n03408054 +n03463381 +n03758089 +n03686130 +n02800497 +n03379828 +n03233744 +n02953197 +n04108822 +n03865557 +n04492749 +n04532670 +n04311004 +n03122073 +n03415486 +n04366367 +n04479939 +n03956922 +n03069752 +n04592465 +n03316406 +n03212811 +n03844673 +n04068441 +n04103094 +n03387653 +n04311595 +n03697007 +n04300358 +n04032603 +n02810782 +n03492250 +n03826186 +n03547054 +n04411264 +n03550153 +n03560430 +n03254189 +n03792972 +n04025508 +n03900979 +n02769963 +n03374473 +n02954163 +n03334291 +n04549028 +n03035252 +n03448956 +n04113765 +n03975035 +n04486054 +n02905152 +n03784896 +n04104384 +n02946127 +n04501947 +n03047052 +n04206790 +n03029197 +n03767745 +n04028581 +n04220250 +n04556948 +n04479823 +n04028764 +n04312432 +n03347617 +n03519387 +n04361260 +n03098959 +n02826886 +n02814860 +n02922292 +n04251701 +n04051825 +n03390786 +n02811936 +n02699770 +n04546855 +n03409393 +n04544325 +n02755823 +n03904657 +n02825961 +n02898369 +n04326799 +n02796623 +n03839795 +n03967942 +n03659686 +n03454707 +n04127395 +n03795580 +n02788148 +n02894605 +n03459775 +n04571566 +n04047401 +n03549589 +n04304680 +n03327234 +n03160309 +n03427296 +n03221720 +n03698815 +n03985881 +n04501370 +n03395514 +n02963821 +n04153025 +n03394649 +n03226880 +n03579538 +n04239074 +n04086446 +n02793842 +n03498662 +n04329834 +n04547592 +n04082710 +n04046974 +n03000134 +n03252637 +n03511175 +n04604644 +n03930313 +n04326547 +n04560882 +n02920369 +n03262072 +n03108853 +n04390977 +n03999160 +n03542333 +n04409384 +n02666943 +n02726681 +n02763604 +n03478756 +n03545150 +n04104500 +n04081699 +n03859280 +n03402941 +n03739518 +n03542605 +n03661043 +n02977936 +n03322570 +n03953416 +n04081281 +n03770316 +n04112654 +n03839671 +n03842012 +n04407686 +n04217546 +n03449564 +n03457902 +n04093625 +n03956157 +n04018399 +n02882190 +n03544360 +n04118635 +n02734725 +n04233124 +n03430418 +n04146050 +n03007444 +n04417809 +n03479397 +n03092166 +n02993546 +n04080705 +n08640531 +n03788498 +n08560295 +n04095109 +n04229737 +n03541696 +n03790755 +n03036022 +n03466839 +n03698723 +n03333610 +n03837698 +n03121298 +n04187547 +n03416489 +n02968074 +n03860404 +n03055857 +n02859443 +n04598318 +n02727426 +n03730334 +n03210552 +n04294879 +n03016389 +n03123809 +n02793495 +n03884778 +n03028079 +n04407435 +n04210390 +n04346328 +n03724756 +n04374735 +n03788195 +n03007130 +n03618982 +n02667576 +n02984061 +n02984203 +n03772077 +n02935658 +n04111414 +n02760099 +n02892499 +n02935891 +n03199647 +n02956699 +n03282295 +n04461437 +n03005033 +n03152303 +n04305210 +n03121431 +n03558176 +n03557360 +n02696165 +n03393017 +n04258438 +n02919792 +n04115256 +n02932400 +n03257210 +n03719053 +n03685820 +n03428090 +n03686924 +n04131368 +n03118969 +n03219483 +n04052658 +n02857477 +n03180865 +n04535524 +n03002816 +n04079244 +n03322836 +n04413969 +n02907873 +n03878066 +n04305323 +n03718458 +n04354026 +n03158186 +n04535370 +n03010915 +n03718935 +n04073948 +n03439348 +n03892557 +n03877845 +n03781244 +n02667379 +n02667478 +n03165616 +n03092314 +n03801671 +n03849814 +n03801533 +n03032252 +n03678729 +n03529860 +n03097362 +n04177931 +n02940385 +n03111041 +n03064935 +n03626115 +n02838728 +n03356858 +n02902079 +n04439585 +n03263076 +n04453037 +n03942920 +n03379204 +n03522003 +n03220692 +n02782778 +n02918112 +n02704949 +n03899768 +n03109881 +n02775178 +n03517647 +n03024064 +n02894158 +n04030518 +n03004824 +n02758134 +n03120198 +n03200231 +n04105893 +n02750070 +n03285912 +n03813078 +n02694045 +n04328946 +n03443005 +n03378005 +n02754656 +n03047941 +n03382292 +n04446276 +n04356925 +n03288500 +n04363991 +n04112579 +n03038685 +n03412058 +n03718581 +n02991302 +n03691817 +n04139395 +n03238131 +n02839592 +n02824319 +n03619890 +n03660909 +n04329477 +n04602762 +n04180229 +n02710324 +n03200701 +n04065464 +n03541091 +n04058096 +n02873839 +n03089879 +n02821627 +n03040376 +n03679712 +n03222176 +n03478907 +n04061793 +n02857644 +n04345028 +n03683708 +n03062122 +n04406239 +n03079741 +n03120778 +n03982331 +n02807731 +n03098688 +n02715513 +n04558478 +n03746486 +n04555291 +n04018667 +n03529175 +n03653740 +n04345201 +n03885535 +n04324387 +n04523831 +n04067818 +n03200539 +n02952585 +n03319745 +n04119478 +n03283221 +n04064862 +n03850245 +n04401680 +n04541987 +n03090172 +n04209613 +n03727465 +n03788601 +n03465718 +n03542860 +n03225108 +n03836062 +n03165466 +n03457008 +n03086580 +n03878211 +n03303831 +n03891538 +n03235042 +n04000592 +n03075946 +n02932019 +n03939677 +n02931148 +n03696065 +n02933462 +n03061505 +n04305572 +n02960352 +n02934451 +n04299370 +n03235180 +n04414199 +n02936714 +n03964495 +n03907227 +n04539203 +n03993703 +n03683079 +n03016737 +n03003730 +n04061969 +n02843276 +n04037220 +n03550289 +n03124590 +n04100519 +n03376159 +n04262161 +n02921884 +n03348868 +n04080454 +n03404449 +n02868638 +n03555006 +n04076713 +n03732114 +n03617095 +n02849885 +n03837606 +n03425325 +n03566193 +n03762434 +n03073694 +n03343560 +n03346455 +n02731398 +n02991847 +n03148324 +n04295571 +n03411544 +n02705201 +n03854722 +n04327204 +n04355267 +n03399677 +n04527648 +n03168107 +n02770211 +n03986704 +n03721590 +n03251533 +n02853016 +n03259505 +n04409625 +n03679384 +n03776460 +n03088389 +n02726305 +n04549919 +n02992032 +n03088580 +n04613696 +n03685307 +n04517408 +n03507241 +n03354207 +n03042490 +n03529629 +n04172107 +n04584373 +n04412416 +n02672371 +n03349892 +n02932693 +n02822064 +n03361297 +n03010473 +n04360501 +n03391770 +n03903868 +n02929289 +n03373943 +n02669295 +n04087826 +n02926591 +n04589593 +n03390983 +n03416094 +n03530642 +n04492375 +n03646916 +n03111296 +n03931765 +n04587648 +n03042697 +n04478512 +n02689144 +n03454536 +n03453443 +n04545305 +n02977619 +n04387261 +n02732827 +n04038727 +n03793186 +n04136510 +n02976350 +n03855333 +n02813399 +n04297750 +n04232800 +n03211789 +n04110178 +n03986562 +n04473108 +n03041810 +n03224603 +n03224753 +n03637898 +n03320959 +n03961711 +n02790669 +n02835829 +n03696301 +n03207630 +n04459773 +n03896526 +n03900393 +n03792526 +n04340935 +n03386011 +n03385557 +n02806088 +n03610098 +n03628511 +n02676938 +n02695627 +n03723781 +n03334382 +n02805983 +n03296328 +n03878963 +n02980441 +n02993194 +n03743016 +n04178329 +n02892201 +n03810952 +n03884926 +n03220237 +n03745571 +n03953020 +n03574555 +n04511002 +n03748162 +n03841666 +n02931417 +n03506370 +n03965456 +n03119203 +n03176763 +n04202417 +n03722288 +n02879309 +n04131208 +n04200800 +n02871525 +n03871371 +n04428634 +n03606251 +n04462240 +n03039827 +n02813544 +n03436417 +n03367410 +n03249342 +n03416640 +n03173387 +n04245508 +n02791270 +n04299215 +n04443257 +n03822656 +n02927161 +n03952576 +n03089624 +n03099274 +n02813645 +n08492461 +n03461385 +n03847823 +n04358707 +n03555426 +n03457686 +n04261281 +n03322704 +n08571898 +n03822504 +n02885882 +n03504723 +n03111690 +n03856012 +n03592245 +n03911513 +n04005630 +n04447443 +n04566257 +n03294048 +n03091374 +n03563967 +n03405265 +n03183080 +n02997391 +n04377057 +n03094503 +n03100490 +n06254669 +n03176594 +n02807523 +n03128519 +n03690938 +n04186051 +n03476991 +n03794136 +n03916031 +n03475823 +n02723165 +n03994008 +n03113152 +n02808185 +n03484487 +n03067339 +n04357314 +n03640850 +n02862916 +n04450640 +n03487444 +n02683791 +n03992325 +n03898271 +n03916470 +n03071021 +n04448070 +n03980026 +n02901793 +n04447276 +n04386792 +n03177165 +n03519081 +n03714235 +n03314780 +n03676087 +n03309687 +n03724066 +n03676483 +n04112752 +n03309110 +n03308481 +n02738031 +n03171228 +n02866578 +n02703275 +n03812924 +n02813752 +n02746365 +n03647520 +n02950256 +n03332393 +n03786715 +n02801450 +n03553248 +n02753044 +n04113641 +n04206570 +n04063373 +n04285146 +n03926148 +n03811847 +n03889726 +n03430959 +n04137444 +n03414162 +n03888257 +n03278248 +n02727825 +n02761206 +n03729951 +n02774921 +n04393095 +n02979290 +n03192543 +n04533802 +n02799897 +n03135030 +n03039259 +n04225729 +n04607035 +n03132261 +n02802721 +n03594148 +n04212282 +n03446832 +n04275661 +n04318131 +n02885338 +n02885462 +n03472232 +n04571292 +n02800213 +n02811059 +n02811204 +n02797881 +n02811350 +n02799175 +n03528901 +n03349771 +n04425804 +n04164406 +n04102037 +n04102162 +n04102618 +n03558404 +n03523987 +n04273972 +n03336282 +n03132076 +n04582869 +n03445924 +n03447075 +n04399537 +n03446070 +n04597066 +n03585073 +n03244047 +n04284341 +n04569822 +n03762332 +n04028074 +n03823216 +n03950537 +n04135024 +n03524150 +n03978686 +n03535780 +n03538037 +n04509260 +n03888605 +n04469514 +n02777292 +n04524142 +n03980478 +n03255030 +n02790996 +n03289660 +n02942699 +n03037404 +n03338821 +n03667664 +n02884994 +n03358726 +n03976467 +n03974915 +n04569063 +n03789171 +n03196062 +n03987266 +n04069434 +n04609531 +n04067658 +n03817191 +n04071263 +n03619396 +n04091097 +n03351434 +n04295081 +n04091693 +n03138669 +n03139464 +n04179824 +n03349469 +n02966687 +n03650551 +n03241093 +n03240683 +n03494706 +n04247876 +n03503718 +n04124202 +n03480719 +n02900160 +n04290615 +n04266162 +n02768226 +n02778669 +n04028315 +n03982430 +n02882647 +n03716327 +n03020416 +n04113406 +n03442756 +n04540255 +n03941417 +n04254680 +n03982232 +n02882301 +n04256891 +n03333252 +n04023962 +n02839351 +n03134739 +n03131967 +n04409515 +n03445777 +n04118538 +n03145719 +n03742019 +n02802426 +n03267113 +n03942813 +n03482877 +n02799071 +n04039742 +n02861147 +n04540053 +n03598930 +n06785654 +n03014440 +n04579986 +n03901750 +n02802215 +n03820318 +n03278914 +n03782006 +n03781787 +n04405762 +n04401088 +n03857828 +n03916720 +n02872529 +n02979186 +n02988304 +n04060647 +n02757462 +n03656957 +n03963294 +n04405540 +n03034405 +n02979074 +n02995345 +n03775388 +n04142731 +n04392985 +n03181293 +n03777754 +n03293741 +n04392526 +n02705944 +n02992529 +n04270371 +n03179910 +n03902125 +n03488438 +n03187595 +n04044498 +n04405907 +n04043733 +n04137773 +n03516996 +n03046921 +n04077430 +n03517760 +n04315948 +n03584254 +n04546340 +n03584400 +n03436182 +n02942349 +n04404997 +n03909160 +n04026053 +n04173511 +n04070003 +n03257586 +n03509608 +n04171208 +n04450243 +n04506506 +n03434188 +n03567066 +n02923129 +n03386544 +n03046802 +n03757604 +n03927299 +n03924679 +n04608923 +n03316105 +n03767459 +n03987990 +n03084834 +n03422072 +n02855390 +n02921029 +n03425769 +n03871524 +n02852360 +n04105704 +n04408871 +n04241573 +n04402057 +n03664943 +n03605915 +n03543012 +n03196990 +n03639497 +n02840134 +n04594218 +n02999410 +n03086868 +n02790823 +n03886641 +n02709637 +n03374838 +n02835412 +n04440963 +n03011018 +n03600977 +n03093792 +n03228967 +n04573281 +n03521076 +n04144241 +n04571958 +n04160372 +n03787523 +n02928299 +n04333869 +n03213826 +n04476972 +n04593866 +n02788689 +n04451818 +n04516672 +n04116512 +n03816136 +n03294833 +n04317420 +n02908217 +n03532342 +n04185071 +n04285622 +n03653220 +n04369282 +n03346135 +n03837422 +n04317833 +n03039947 +n04100174 +n04608567 +n04208427 +n04282872 +n03396074 +n02865931 +n04112147 +n04459909 +n03659292 +n04463679 +n03487090 +n03138344 +n04317976 +n03613592 +n04393808 +n03903424 +n04099003 +n03470629 +n04264628 +n02771004 +n04193377 +n04400737 +n02670683 +n04367011 +n03489162 +n03588951 +n03919430 +n03418242 +n03967562 +n03075097 +n03239726 +n03154446 +n04387706 +n03417970 +n04050066 +n04299963 +n03684224 +n03919289 +n03970156 +n03941684 +n03966976 +n04258859 +n04266486 +n03481172 +n03946076 +n04606574 +n04154565 +n04489817 +n04140064 +n03848348 +n04150980 +n04208210 +n02898269 +n04269944 +n02966545 +n03430313 +n03715386 +n03731695 +n04457910 +n03947466 +n02680754 +n03848168 +n02697675 +n02886434 +n03474779 +n03376938 +n03488188 +n04016240 +n04016576 +n03109150 +n02877962 +n02951585 +n03511333 +n03649909 +n03995856 +n04089976 +n03995372 +n03240140 +n03154073 +n04503593 +n02844307 +n02848216 +n03624400 +n02866386 +n03030557 +n03265032 +n04148054 +n03623556 +n02764044 +n04057047 +n04594828 +n03020692 +n03954731 +n04186848 +n04250473 +n04016684 +n04163530 +n02973904 +n02880842 +n03973628 +n03041632 +n03549473 +n02976123 +n03890093 +n03658185 +n04373089 +n03911658 +n02811468 +n03498962 +n04185804 +n04332074 +n04127521 +n03067212 +n04597400 +n03601638 +n04247630 +n04283585 +n03621049 +n02997607 +n03403643 +n04103206 +n04059516 +n03724417 +n03621377 +n04293119 +n03775199 +n03101517 +n03101986 +n03454885 +n03767966 +n03266371 +n04578934 +n02850732 +n03880531 +n03133878 +n02999138 +n04270147 +n03459328 +n03284981 +n04309548 +n03101796 +n03101156 +n04500060 +n03846677 +n04317325 +n03400231 +n04097760 +n04596742 +n04138977 +n03453231 +n03047799 +n03984234 +n03262519 +n04326676 +n03992703 +n04282992 +n03018209 +n02869155 +n03713436 +n03317788 +n03625646 +n03133050 +n04546194 +n03729826 +n03053474 +n03332271 +n04277352 +n04321453 +n04296261 +n03250847 +n03715669 +n02949202 +n04374315 +n02806379 +n04381724 +n04491388 +n02698634 +n03355925 +n03141823 +n03274265 +n04453156 +n04122349 +n04156140 +n03475581 +n02902687 +n04185946 +n03908714 +n04310904 +n03145522 +n04039381 +n04292414 +n04409806 +n02772700 +n04426316 +n04333129 +n03012013 +n04072551 +n03831382 +n03651843 +n04156946 +n03873416 +n02831894 +n04150153 +n03258905 +n04292921 +n02906734 +n04367480 +n04111190 +n04549629 +n04182322 +n03949317 +n03616428 +n02764779 +n03976657 +n03351979 +n03091044 +n04434531 +n03244231 +n03127408 +n04472563 +n04277493 +n02946824 +n02871824 +n04319937 +n04230603 +n03051396 +n02931836 +n04267577 +n03726993 +n03726760 +n02883004 +n04610676 +n03775847 +n04115996 +n03711999 +n03382856 +n03374372 +n04279353 +n03908204 +n03906997 +n03518943 +n03003091 +n03128248 +n03652100 +n02783161 +n04185529 +n04033901 +n03388183 +n03326948 +n03405725 +n03842156 +n03200906 +n04550184 +n02821943 +n04379243 +n04379964 +n04549122 +n03636649 +n03201035 +n04555400 +n02912065 +n02933112 +n02766320 +n02822579 +n03649797 +n03129753 +n02870880 +n03290653 +n03298716 +n04161981 +n04165409 +n03015254 +n03337140 +n04104147 +n02963302 +n04529681 +n03050546 +n02739550 +n02818832 +n02831724 +n03962852 +n03540914 +n02920083 +n04491638 +n03388549 +n03115762 +n02920259 +n04503413 +n04236809 +n04222210 +n03482252 +n03799876 +n03225988 +n03414676 +n03465426 +n04381587 +n03116530 +n02699629 +n02894337 +n04301000 +n03090000 +n03904060 +n03620967 +n03850492 +n04398951 +n03653583 +n04603729 +n03428226 +n03238586 +n03179701 +n03246933 +n03063968 +n04480033 +n03092883 +n03011741 +n02789487 +n03735963 +n04061681 +n04130143 +n04247736 +n03231368 +n03630262 +n04608329 +n04164868 +n03164722 +n03201208 +n03202354 +n04067921 +n03367059 +n04380533 +n04057981 +n03237340 +n03018349 +n03742115 +n02804414 +n03131574 +n02970534 +n03125729 +n03001627 +n04447861 +n04326896 +n04256520 +n03858418 +n02828884 +n03649674 +n03002711 +n04099969 +n04373704 +n04429376 +n04331277 +n03632729 +n03518445 +n02738535 +n04590933 +n03376595 +n04576002 +n03790953 +n02791124 +n03262932 +n04062428 +n03786621 +n04593077 +n03168217 +n02946270 +n03801880 +n04382438 +n03380724 +n04177755 +n03165096 +n03100346 +n03693474 +n03015149 +n04344873 +n03891251 +n03360622 +n03920867 +n04177820 +n04590021 +n03016953 +n03518305 +n02843553 +n03508101 +n03666591 +n06791372 +n03099945 +n03141702 +n03243218 +n03626760 +n03904909 +n03800933 +n04200537 +n04198797 +n03699975 +n03088707 +n02776205 +n04294212 +n03339643 +n03738472 +n02676261 +n04474466 +n03008976 +n02688443 +n04114844 +n03929660 +n03287351 +n03320046 +n03553019 +n03175604 +n02678897 +n04461879 +n04359589 +n03851341 +n04331639 +n04450749 +n03923918 +n03574816 +n03074855 +n04074963 +n03302790 +n03075768 +n04554406 +n04210120 +n04562262 +n02855089 +n04526964 +n02895606 +n02730265 +n04226826 +n03467796 +n04081844 +n03614007 +n03269401 +n02729965 +n03345837 +n03111899 +n04069276 +n02694426 +n03277771 +n04252331 +n03525827 +n03744840 +n03613294 +n03827536 +n04263760 +n03568117 +n03180969 +n02895438 +n03565288 +n02683558 +n03537241 +n03267972 +n04228054 +n03664675 +n04258333 +n03272239 +n04041069 +n03423479 +n03099147 +n04265275 +n04330267 +n03031422 +n03728437 +n07273802 +n06793231 +n06794110 +n06874185 +n03269203 +n02981321 +n03582959 +n04375405 +n03307792 +n02988963 +n03580518 +n04338517 +n03279153 +n03614532 +n04586932 +n02803349 +n03915437 +n03254862 +n03025886 +n02787622 +n04615226 +n04132603 +n03467517 +n02880546 +n04224842 +n03698360 +n03716887 +n03716966 +n03495258 +n02676566 +n03499907 +n04506289 +n03272010 +n04536153 +n04536866 +n02992211 +n04536335 +n04536595 +n04330998 +n04419642 +n03273551 +n04376400 +n03928116 +n03039015 +n03854065 +n02672831 +n03452741 +n04515003 +n04278353 +n03738066 +n02766792 +n03086457 +n03496296 +n04278247 +n03840681 +n04598582 +n02891788 +n03854815 +n03393324 +n04579667 +n03945615 +n03609397 +n03372029 +n02817799 +n03228016 +n04222847 +n02804610 +n03838899 +n03037709 +n04141076 +n02793089 +n02912894 +n03369276 +n03394916 +n04487394 +n03110669 +n03494537 +n03494278 +n03086670 +n03006626 +n03884397 +n02775483 +n03343354 +n03912218 +n03245724 +n02803934 +n02804252 +n02804123 +n03301568 +n03483230 +n02869249 +n03447721 +n04532831 +n04311174 +n03721384 +n03440682 +n03017168 +n03612965 +n03720891 +n03249569 +n03157348 +n02869737 +n02803666 +n04387400 +n04249415 +n04410086 +n04243941 +n03996416 +n03999992 +n02769290 +n04004475 +n03702248 +n03789946 +n04252653 +n02977058 +n03322940 +n03082979 +n04613939 +n03765561 +n04303357 +n03997484 +n03087069 +n04303497 +n04237423 +n04417180 +n04064401 +n02938886 +n04525305 +n04243546 +n02760199 +n03418915 +n02829596 +n03551395 +n04024274 +n03007591 +n03563200 +n04004767 +n03250405 +n03672827 +n03643737 +n03675235 +n04419868 +n03985069 +n04505036 +n02794664 +n04595285 +n03225777 +n02909285 +n03571942 +n04184435 +n03240892 +n03460040 +n03646296 +n03766044 +n03287733 +n03273061 +n03507963 +n03596285 +n02761557 +n02687423 +n03433877 +n04309049 +n03579982 +n04591517 +n03424630 +n03193107 +n03859000 +n04040373 +n04099175 +n03321103 +n02872333 +n04265904 +n02700064 +n04587404 +n04304375 +n03616763 +n03146846 +n03500699 +n03075634 +n04428191 +n03496892 +n03210245 +n03496612 +n04238763 +n06359193 +n03528523 +n04175147 +n03196324 +n04358117 +n04603399 +n03918480 +n03985232 +n03180011 +n03832673 +n03956785 +n03642806 +n03485407 +n03914337 +n04561422 +n03736064 +n03063485 +n04477219 +n04587559 +n03272125 +n03996145 +n02911332 +n03034663 +n03000684 +n04380916 +n04121728 +n02786837 +n04279462 +n03689157 +n03604156 +n03452267 +n02666196 +n02679257 +n03483823 +n04171831 +n04594489 +n03106898 +n03510244 +n02934168 +n03760310 +n04471632 +n03666362 +n03020034 +n03336575 +n03604843 +n04402984 +n03898129 +n04401828 +n03995265 +n03307037 +n03300443 +n03268918 +n04004990 +n03995535 +n03350602 +n03373237 +n03251932 +n04573937 +n04334365 +n03861271 +n04520784 +n04332243 +n02688273 +n03843555 +n04216634 +n04398834 +n03066849 +n03407865 +n02710201 +n04040759 +n03736970 +n04110955 +n04112430 +n02969010 +n03096960 +n03996849 +n02761392 +n02677718 +n03102859 +n03431243 +n04392764 +n03339529 +n04289027 +n04011827 +n02709367 +n03446268 +n04568069 +n03700963 +n04167346 +n04021798 +n03432129 +n04088797 +n02918595 +n03532672 +n04228215 +n03119510 +n04063154 +n04371774 +n04590746 +n04586581 +n04586421 +n03189083 +n04211528 +n03296081 +n02903204 +n03150232 +n04282494 +n03082807 +n02686227 +n02962200 +n03198500 +n02973017 +n04475411 +n03431745 +n04306592 +n02692086 +n04154152 +n04020298 +n04574999 +n03559999 +n03659809 +n03566329 +n03767203 +n04563204 +n04101701 +n02836035 +n02980036 +n03460147 +n04115144 +n03334912 +n04543772 +n04563413 +n02974003 +n04289690 +n03944341 +n03992509 +n03430551 +n03244919 +n03874293 +n04113194 +n04290507 +n02833793 +n03943115 +n04051549 +n02764505 +n04154340 +n03456299 +n03425413 +n02835724 +n04354487 +n03487886 +n02995871 +n03329302 +n04102406 +n02966193 +n04510706 +n03054901 +n03393761 +n03209359 +n02860415 +n04067472 +n04211857 +n02848523 +n03473227 +n03032811 +n04111668 +n03873699 +n03563460 +n03320421 +n03208556 +n04019541 +n02890188 +n04448361 +n03397947 +n03954393 +n04385799 +n03712111 +n04519153 +n04313503 +n03450018 +n03602883 +n04072193 +n04372370 +n02783459 +n02927887 +n04438507 +n03374649 +n03325088 +n04422875 +n02727141 +n03775636 +n04327682 +n04445952 +n04027023 +n03186818 +n03537412 +n03793850 +n03222516 +n02826589 +n03363549 +n03795758 +n03469493 +n03103396 +n03301833 +n02686379 +n03432061 +n03389611 +n04579432 +n04218564 +n03743279 +n03506560 +n02824448 +n03123917 +n03028596 +n03201529 +n04275548 +n03794056 +n03680858 +n04568557 +n03819994 +n03639077 +n03352628 +n04529962 +n04283255 +n04283096 +n04112252 +n03357716 +n04117464 +n03536122 +n04592741 +n03303217 +n03271574 +n02887079 +n03176386 +n02768114 +n04320973 +n03933933 +n03934042 +n02767433 +n04190052 +n03638883 +n02783994 +n04283378 +n02797692 +n04314914 +n02887209 +n03938401 +n02817031 +n04098513 +n03057920 +n03495570 +n04081044 +n02888569 +n04386051 +n02871005 +n04341414 +n03506184 +n04161358 +n04430475 +n03490884 +n04038440 +n03495039 +n02953455 +n03632577 +n02871439 +n03719343 +n03814639 +n03622839 +n02713003 +n02768655 +n02737660 +n03505133 +n03019685 +n02741475 +n04148579 +n03105467 +n04190376 +n04220036 +n04094720 +n04515129 +n02886599 +n04476831 +n02815950 +n04590263 +n03223686 +n04318787 +n03592773 +n03073977 +n03988170 +n04360798 +n02974348 +n03443149 +n03821518 +n02864593 +n03637181 +n04402449 +n03733131 +n04436329 +n04119751 +n04433585 +n04045644 +n03437941 +n04436185 +n03366974 +n03601840 +n02970685 +n03937931 +n03955489 +n04123740 +n03002096 +n02835915 +n02910145 +n02770830 +n04325041 +n03288886 +n04485082 +n04275175 +n03704549 +n03801760 +n02943871 +n03262809 +n02759257 +n04009801 +n03340723 +n03643253 +n03656484 +n03838298 +n03087366 +n02943241 +n02709101 +n03094159 +n04355933 +n03309465 +n03333711 +n03395859 +n03987376 +n03049782 +n04403413 +n04583212 +n03967396 +n04147495 +n03733925 +n04565375 +n03467068 +n03231160 +n02708711 +n03813176 +n03852280 +n03739693 +n03575958 +n02981911 +n03308152 +n04419073 +n04089836 +n04383015 +n03070193 +n03760944 +n02670382 +n04340521 +n03709206 +n03092656 +n04403638 +n03760671 +n02751295 +n03293863 +n03852688 +n04044716 +n04070207 +n03333129 +n04068601 +n02978478 +n03822767 +n04145863 +n03715114 +n03279508 +n03332989 +n03667829 +n02841506 +n03484931 +n03850053 +n03082280 +n03692522 +n03868643 +n03247083 +n04070415 +n04053508 +n02794156 +n03904782 +n04421872 +n02751215 +n03735637 +n03429288 +n04437953 +n02710600 +n02939866 +n03991837 +n04382880 +n04141975 +n04392113 +n03753077 +n03554460 +n04180888 +n04118776 +n02699915 +n04029734 +n03736470 +n04559730 +n04518343 +n02710429 +n03424862 +n04001499 +n03718335 +n04274985 +n02753394 +n03046257 +n04555897 +n04355338 +n04438304 +n03544143 +n03452594 +n03196217 +n02694662 +n04548280 +n02708093 +n03909406 +n03145147 +n03197337 +n02708433 +n03973839 +n04607869 +n04328186 +n03891332 +n03026907 +n04528968 +n03759661 +n02777100 +n02708555 +n03277459 +n03272810 +n03841143 +n02702989 +n04273796 +n03842986 +n04561287 +n04541320 +n03708843 +n04449966 +n03467984 +n02879718 +n02880393 +n02892948 +n03624134 +n04373894 +n04346157 +n04008634 +n02715712 +n03343853 +n04177041 +n02689274 +n03423306 +n03875955 +n02950826 +n02759963 +n03948459 +n04502851 +n03732020 +n03803116 +n04090263 +n04076284 +n04171459 +n02760429 +n03416775 +n03695857 +n04171629 +n02760855 +n02749479 +n02760658 +n03701391 +n04347519 +n02923682 +n04517211 +n03607659 +n04450133 +n03073296 +n03178674 +n04086273 +n03427202 +n03363749 +n03802007 +n04250224 +n04585980 +n02961451 +n03136369 +n03687928 +n03615790 +n02812949 +n03699591 +n03158885 +n04054361 +n03327691 +n02904640 +n02987492 +n04121511 +n03292475 +n03375575 +n02916350 +n02950943 +n03080633 +n04015908 +n02745611 +n03178000 +n03706229 +n03080497 +n02841315 +n04272054 +n04009552 +n04403925 +n03443912 +n04356056 +n04238617 +n03399761 +n03795976 +n03864692 +n03555662 +n02963503 +n04376876 +n04317175 +n03643149 +n03858183 +n04364545 +n04083800 +n03514451 +n03938037 +n04056180 +n03302671 +n04477387 +n04080833 +n04251144 +n03868863 +n02731629 +n03876231 +n04287747 +n02889646 +n03484576 +n03323703 +n04162706 +n03652932 +n04125853 +n02891188 +n03803284 +n02999936 +n02865665 +n02910353 +n03627232 +n03041114 +n03051249 +n02982599 +n03940256 +n03229244 +n04153751 +n04238321 +n02928608 +n04159354 +n03887185 +n03682487 +n04431745 +n03683606 +n03038281 +n03043958 +n02960690 +n03804744 +n04445327 +n03836451 +n02881906 +n02880189 +n03644858 +n03497352 +n04095342 +n03476313 +n04227900 +n03499354 +n02903126 +n02860640 +n02796318 +n04127249 +n04197781 +n03057541 +n04554871 +n03423719 +n03503477 +n03855604 +n03874599 +n04136800 +n03645011 +n03075370 +n03223162 +n03886762 +n02915904 +n03476684 +n03551084 +n03208938 +n03250089 +n04505470 +n04036303 +n03085013 +n03928814 +n03033362 +n04168199 +n03589513 +n03098140 +n04401949 +n03034244 +n03968293 +n03275681 +n03163222 +n04470953 +n04257986 +n02715229 +n02955247 +n04269270 +n04072960 +n04364160 +n04257790 +n02810471 +n04414675 +n03048883 +n04595855 +n03084420 +n03577090 +n03778817 +n04004210 +n03578656 +n03125057 +n03033986 +n03788047 +n03274561 +n03261776 +n03759954 +n03691459 +n04402580 +n03505667 +n03087816 +n02963692 +n04502670 +n02917377 +n04390873 +n04599124 +n04349401 +n03846772 +n03204955 +n04041747 +n04404817 +n03207305 +n04142999 +n04610274 +n04540547 +n03359285 +n03651388 +n03870980 +n04013729 +n04258138 +n03773035 +n03485198 +n02965783 +n04059947 +n03861842 +n02921756 +n02761834 +n04201064 +n03343737 +n04058594 +n04143140 +n04494204 +n03211117 +n03918737 +n03221351 +n04464615 +n03793489 +n02714751 +n03506727 +n02823124 +n04484432 +n03913343 +n03085219 +n03782190 +n04152593 +n03196598 +n03676759 +n03361380 +n04588739 +n03187268 +n02940570 +n03085602 +n02769075 +n02988066 +n03027250 +n03070059 +n03525454 +n04538552 +n02948557 +n03031152 +n02947818 +n03746005 +n03746155 +n02935017 +n03851787 +n03706653 +n03744276 +n03708036 +n04063868 +n02763306 +n03079230 +n04533946 +n02988679 +n02988486 +n02757061 +n03492542 +n03209910 +n03359436 +n04052757 +n04534359 +n02979399 +n04391838 +n03924069 +n03694639 +n04178190 +n03636248 +n03665366 +n03358172 +n03640988 +n02948072 +n03818343 +n04534895 +n04384910 +n03423877 +n03844045 +n03549897 +n03370387 +n04335886 +n04286575 +n03272383 +n03590841 +n03018712 +n03359137 +n03665924 +n03911767 +n03503997 +n04107743 +n04339879 +n03318294 +n04148703 +n04160847 +n03824713 +n02852173 +n04456115 +n03365374 +n03401129 +n03442597 +n03187037 +n04529108 +n03975232 +n03668279 +n03482523 +n04371050 +n03772584 +n04164757 +n03544238 +n04288272 +n04116098 +n03066359 +n02886321 +n03525074 +n04585745 +n03281145 +n03126707 +n04575824 +n03178430 +n03733281 +n03078287 +n03820728 +n03440216 +n04080138 +n03302938 +n03738241 +n03085915 +n04141712 +n04082886 +n04545858 +n04041544 +n04400289 +n04402746 +n03578055 +n03580845 +n04404412 +n04137897 +n04365328 +n03072201 +n03681477 +n04358491 +n03300216 +n04595028 +n04008385 +n03674440 +n04366116 +n03401279 +n03957315 +n04488202 +n04555700 +n03206908 +n02893692 +n03210683 +n03991062 +n02920658 +n04074185 +n03147509 +n02774152 +n02978881 +n03256032 +n02773037 +n03733805 +n03438257 +n03875806 +n03733644 +n03291819 +n04183329 +n03935335 +n02801938 +n04179712 +n04139859 +n03994614 +n02946921 +n04576211 +n04600312 +n02839910 +n02949542 +n03779370 +n02964843 +n04533700 +n02975212 +n02974697 +n04531098 +n03233905 +n04060904 +n03871083 +n04560292 +n02883344 +n03062336 +n03920288 +n03456024 +n04176190 +n04499062 +n04350581 +n02880940 +n02978753 +n04050933 +n02927764 +n04130257 +n03775546 +n03984759 +n02997910 +n04263257 +n04023695 +n04103769 +n02682922 +n04254120 +n02754103 +n03571280 +n03174731 +n02815749 +n03629520 +n03063073 +n03002948 +n04397452 +n03216710 +n03301940 +n04207343 +n03055418 +n04083309 +n02769748 +n04122685 +n02816656 +n04134008 +n02970408 +n03883524 +n03253886 +n02870676 +n04452528 +n03709823 +n04026417 +n03235796 +n03291963 +n04124098 +n04122825 +n03993180 +n04204081 +n04446844 +n03414029 +n03619793 +n03958227 +n03445617 +n04235860 +n03469903 +n03461288 +n04284572 +n03972524 +n04544450 +n03321563 +n03521899 +n03898395 +n03372549 +n04496872 +n04559910 +n02918831 +n03676623 +n04249882 +n04206225 +n02823750 +n04119360 +n03443371 +n04592099 +n03062245 +n04131690 +n03914438 +n03883385 +n03050864 +n03482405 +n02893608 +n04204238 +n04582349 +n03764736 +n02823510 +n04255586 +n03904433 +n02946509 +n04103364 +n03791053 +n04170037 +n04509417 +n04543158 +n02804515 +n03484083 +n02766534 +n02834778 +n03538634 +n04467099 +n02959942 +n04482393 +n02740533 +n04065272 +n04464852 +n04252077 +n02916179 +n03684823 +n04335435 +n03791235 +n04465501 +n03384352 +n02740300 +n02739889 +n03256788 +n02946348 +n04520382 +n04211219 +n03193597 +n03272562 +n04389854 +n04465358 +n04310018 +n03193260 +n03193423 +n03506880 +n04490091 +n02704792 +n03389761 +n03790512 +n03444034 +n02958343 +n04252225 +n03345487 +n04520170 +n04467665 +n04474035 +n03417042 +n03632852 +n04461696 +n03256166 +n04465666 +n03930630 +n03173929 +n03796401 +n03896419 +n03977966 +n02871314 +n04466871 +n03785016 +n02814533 +n03680512 +n03777568 +n03268790 +n03770679 +n03100240 +n03079136 +n02930766 +n04201733 +n04037443 +n03498781 +n04097373 +n02831335 +n04285965 +n04166281 +n03594945 +n03670208 +n03141065 +n02701002 +n04516354 +n04322801 +n04347119 +n03870105 +n03543394 +n04285008 +n03119396 +n03122295 +n02970849 +n03538406 +n03255899 +n03599486 +n03981924 +n03868242 +n04397027 +n03648431 +n04176068 +n02797295 +n04204347 +n03490119 +n02835271 +n04126066 +n04026813 +n03792782 +n02968473 +n03435991 +n02912557 +n04297098 +n03389889 +n02775039 +n03393912 +n03895866 +n02932523 +n02885108 +n04389521 +n03828020 +n04020912 +n03200357 +n04246855 +n04065789 +n02747177 +n03678558 +n04134523 +n03935116 +n02900705 +n03078995 +n03210372 +n03619650 +n04548362 +n02962843 +n03986355 +n03214582 +n03031012 +n04200000 +n03468821 +n02755140 +n03683995 +n04608435 +n04556533 +n02774630 +n03438863 +n03487533 +n04137217 +n02773838 +n04491769 +n03498441 +n03420345 +n04570815 +n02967294 +n03986949 +n03865371 +n04518764 +n02863750 +n03355768 +n02881193 +n03633091 +n02876657 +n02877266 +n03990474 +n03950228 +n02808440 +n03786901 +n02909870 +n03241496 +n03129001 +n04591887 +n04001265 +n04493381 +n03572321 +n04438897 +n02801525 +n03784270 +n02758960 +n03029445 +n02795169 +n04388743 +n03593526 +n02993368 +n04447028 +n03350204 +n04149083 +n04263336 +n04246060 +n03983396 +n04557648 +n03603722 +n02985963 +n03449451 +n03937543 +n02962061 +n03359566 +n02823428 +n03571625 +n03174450 +n04579056 +n03140431 +n04591713 +n02960903 +n03923379 +n04579145 +n04560804 +n03521675 +n03295246 +n04422727 +n02952374 +n04518132 +n03709363 +n03595409 +n04139140 +n04398044 +n03259401 +n04516214 +n04324297 +n03612814 +n02939185 +n03915118 +n04397768 +n03063689 +n03064250 +n04132985 +n04399158 +n04225031 +n03543603 +n03379343 +n03797390 +n03693707 +n04389430 +n03063599 +n04443766 +n02824058 +n02836174 +n02843158 +n04553703 +n02788572 +n02823335 +n04592005 +n03610418 +n03426134 +n04560113 +n04173046 +n02732072 +n04078574 +n04562935 +n04049303 +n02951703 +n02705429 +n03101664 +n02815834 +n04516116 +n03725600 +n04522168 +n03133415 +n03593122 +n03960374 +n04476259 +n02982515 +n03259009 +n03004275 +n04131929 +n03416900 +n03565830 +n03543735 +n03858085 +n04255163 +n02747802 +n03871628 +n02919414 +n03167978 +n02778456 +n03500389 +n03870672 +n02782681 +n02971356 +n03064758 +n04200258 +n04253057 +n03908618 +n03127925 +n02786331 +n04589325 +n03014705 +n04340750 +n02998003 +n03710193 +n02978055 +n02836392 +n03871724 +n04452615 +n04462011 +n03064350 +n03535024 +n04477548 +n02989099 +n02977438 +n04125257 +n02976939 +n04125021 +n04469813 +n03002341 +n04214282 +n04019101 +n04172342 +n03538179 +n04524313 +n04231693 +n04103918 +n04467307 +n04196502 +n03678362 +n03306385 +n04212165 +n04468005 +n02924116 +n03680942 +n03394272 +n03896233 +n04349306 +n03711044 +n03394480 +n03078802 +n02917067 +n04487081 +n03769881 +n04146614 +n04310157 +n02918964 +n04099429 +n03764276 +n03773504 +n03125870 +n04235291 +n03478589 +n04389033 +n03886053 +n03919096 +n03549199 +n02686568 +n04530566 +n04264914 +n03547229 +n03510583 +n04308084 +n03666917 +n03491032 +n03439814 +n03512147 +n04552348 +n02691156 +n02759387 +n02867715 +n02704645 +n04012084 +n02690373 +n02842573 +n03365231 +n03595860 +n03335030 +n04308273 +n04160586 +n02686121 +n04583620 +n03604311 +n03596543 +n04308397 +n03577672 +n02692877 +n02850950 +n02782093 +n03541923 +n02858304 +n04476116 +n04610013 +n04194289 +n04128837 +n02792409 +n03662601 +n03977592 +n03447447 +n04158807 +n02792552 +n04095210 +n04495843 +n04024983 +n03939178 +n04244997 +n03329663 +n04409128 +n02947660 +n03344393 +n03790230 +n03236423 +n03981566 +n03545470 +n04229480 +n02951358 +n03199901 +n04037964 +n03105306 +n04612504 +n03436891 +n03602081 +n04115456 +n03609235 +n03861430 +n03254374 +n04038231 +n04038338 +n04273569 +n03859170 +n02932891 +n03552749 +n04197110 +n04606251 +n03896103 +n03947888 +n03668488 +n03541269 +n04309348 +n02965300 +n04224543 +n04552696 +n03673027 +n03698604 +n02965216 +n03141327 +n03874138 +n04317063 +n02878222 +n03095699 +n02784124 +n03845190 +n04347754 +n03466493 +n03397266 +n02812201 +n03466600 +n02687172 +n03718212 +n03180504 +n02755529 +n03811295 +n04612373 +n03045228 +n03327133 +n04242408 +n03612010 +n03186285 +n04128499 +n02793199 +n04147183 +n04587327 +n04483307 +n02981792 +n02982416 +n04266014 +n04264765 +n03218198 +n02860847 +n02861022 +n04336792 +n03122202 +n06271778 +n06255081 +n06263609 +n06276697 +n06272290 +n06276501 +n06277280 +n06281040 +n06277135 +n06278338 +n06278475 +n06274760 +n06272803 +n06272612 +n06263369 +n06266417 +n06595351 +n06267145 +n06596607 +n06596727 +n06596364 +n06596474 +n06267893 +n06267564 +n06267655 +n06266633 +n06267991 +n03938244 +n03872495 +n04135315 +n02823964 +n03408444 +n02967626 +n04053677 +n04151940 +n04453910 +n03380867 +n04014297 +n03045698 +n04605726 +n04513827 +n03050026 +n03724870 +n03341153 +n03366823 +n03058107 +n02952237 +n03357376 +n03221059 +n03376279 +n03956623 +n03261603 +n02944459 +n04201297 +n02954938 +n03717622 +n03661340 +n04041243 +n02877765 +n03825788 +n03047690 +n04199027 +n02735538 +n02872752 +n03361550 +n04241394 +n03865949 +n04122578 +n04239786 +n03027625 +n04124370 +n04272389 +n02904927 +n04593524 +n04545748 +n02855701 +n02713364 +n03041449 +n03411079 +n03680355 +n04120489 +n03868406 +n02882894 +n03967270 +n04022332 +n04133789 +n03025250 +n04027706 +n04386664 +n03364008 +n03297103 +n03600475 +n02925666 +n04228581 +n03521544 +n04089666 +n04116294 +n03516844 +n04542715 +n03124043 +n03798061 +n02873733 +n03067518 +n03046133 +n04554211 +n04444749 +n03797896 +n04192858 +n02888270 +n04151581 +n04187233 +n02826068 +n04181718 +n04191943 +n04281375 +n04416005 +n04105068 +n03314608 +n03530910 +n04187061 +n02955065 +n03725035 +n03315644 +n03142679 +n02937958 +n02739668 +n02840245 +n02840619 +n03546766 +n02851099 +n03673767 +n03959701 +n03539433 +n02740764 +n02895154 +n03513376 +n02950632 +n03623338 +n03929855 +n04130907 +n04589890 +n03347037 +n04590553 +n03788365 +n03637318 +n03889871 +n03652729 +n02825657 +n04172776 +n02843684 +n02951843 +n03610524 +n02763901 +n04507155 +n03415252 +n03409591 +n04357121 +n03718789 +n03220513 +n03522100 +n04435653 +n03546235 +n04523525 +n04234887 +n03413684 +n04417672 +n03148727 +n03435593 +n03847471 +n02796207 +n04087709 +n03527444 +n04141327 +n04207763 +n03548086 +n04423845 +n03213538 +n03657121 +n03424325 +n03314378 +n04229816 +n02983189 +n02862048 +n04192698 +n03000247 +n02916936 +n03112719 +n03146219 +n02933340 +n04045255 +n02873520 +n04589190 +n03592669 +n03151077 +n04211356 +n04525584 +n04590129 +n04102285 +n04418357 +n04209239 +n02925107 +n02890513 +n03436549 +n03291741 +n02992368 +n07248320 +n03590306 +n03958752 +n04207151 +n03885293 +n03654576 +n02767665 +n03114379 +n02785648 +n02876084 +n04240752 +n02820210 +n04236377 +n02851939 +n03309356 +n04231272 +n04162433 +n02786058 +n04369025 +n02979836 +n03267821 +n04033995 +n02683323 +n02849154 +n02822220 +n03731483 +n03898633 +n03266749 +n03128427 +n03123553 +n04034262 +n04046400 +n03688405 +n04118021 +n03223299 +n03727837 +n04144539 +n04183217 +n03998194 +n02904233 +n04297847 +n04066270 +n02908773 +n03353951 +n03445326 +n04528079 +n03875218 +n03805725 +n03437430 +n03115897 +n03284743 +n04525417 +n03342015 +n03284886 +n03285578 +n03844233 +n04557308 +n03646020 +n04581102 +n03261019 +n03973402 +n03642444 +n04450994 +n04084889 +n04412097 +n03337383 +n03729308 +n03970546 +n03802393 +n04395024 +n04525038 +n02809105 +n03615406 +n02828427 +n04123567 +n03188725 +n04539794 +n03253796 +n03013850 +n03115400 +n04459610 +n03132666 +n03885194 +n03019938 +n03326795 +n03115180 +n04525191 +n04138261 +n03625355 +n04137355 +n04003856 +n03356982 +n04568841 +n03409297 +n02944579 +n04605163 +n02977330 +n04395106 +n03779128 +n02904803 +n04524941 +n04198453 +n02878425 +n03703862 +n03819595 +n03877351 +n04613015 +n03914831 +n03932670 +n03785237 +n04414476 +n04056932 +n02675219 +n03106722 +n03917814 +n03016868 +n02922798 +n04432662 +n02802990 +n03631177 +n04189282 +n03435743 +n03983612 +n03175189 +n03357267 +n04184316 +n02942460 +n03836906 +n03233123 +n03430091 +n03855214 +n03386726 +n03437741 +n04599235 +n04350458 +n04383839 +n03653110 +n04502502 +n03854421 +n02952109 +n03298858 +n03160740 +n03843438 +n04393549 +n02903852 +n03947798 +n03529444 +n04482297 +n03227317 +n03595523 +n03429914 +n04496614 +n03016609 +n03485794 +n03463666 +n03258330 +n03207743 +n04459362 +n02786198 +n03471190 +n02834397 +n04127904 +n03897943 +n03490006 +n03887697 +n03207835 +n03381776 +n03383099 +n04278447 +n03505383 +n04455652 +n03712337 +n02782602 +n03598151 +n03775747 +n03410571 +n03696568 +n04307767 +n03645577 +n03358380 +n04208065 +n03809603 +n02820556 +n03703730 +n03938522 +n04045397 +n03663531 +n03662719 +n03703945 +n03662887 +n04326084 +n02897820 +n14943580 +n14785065 +n15074568 +n14820180 +n04035912 +n03766935 +n04313628 +n03530511 +n03460297 +n03149686 +n03455488 +n03344642 +n03796522 +n03043693 +n02681392 +n04339638 +n15102455 +n04234455 +n03341297 +n04453390 +n14908027 +n14976759 +n03111177 +n03282401 +n03451798 +n03292603 +n03815149 +n03723267 +n02892304 +n07621618 +n02732572 +n03178782 +n02681518 +n03397087 +n03635108 +n04395651 +n03762602 +n03282591 +n06883725 +n03516367 +n04682462 +n03354903 +n02788021 +n04458633 +n03140292 +n03362890 +n05244934 +n11487732 +n03597469 +n03397532 +n03649161 +n03914106 +n02787435 +n03030262 +n02685082 +n02887970 +n02852043 +n03909020 +n03814906 +n03436075 +n03899328 +n04096066 +n03895293 +n04215402 +n04461570 +n03904183 +n03519981 +n02969323 +n04426618 +n04466613 +n03215508 +n03306610 +n02744323 +n02762508 +n02758863 +n04335209 +n04334599 +n03948242 +n03539678 +n02680512 +n03089014 +n03895585 +n04493505 +n04244379 +n04250850 +n04562496 +n02984469 +n02795528 +n03944672 +n03533014 +n04385536 +n03231912 +n03147280 +n04257684 +n04497962 +n04298661 +n03415749 +n02981024 +n04048441 +n04391569 +n02784218 +n03572107 +n02680337 +n03957420 +n02992795 +n03506028 +n03438071 +n04440749 +n02739427 +n04040247 +n02971167 +n04381994 +n04087432 +n03153375 +n03438661 +n03527149 +n03963198 +n04284002 +n04380346 +n03383948 +n04284438 +n04263502 +n04398688 +n04350769 +n04597913 +n03557270 +n04381073 +n03180384 +n02976249 +n02928049 +n04307986 +n04380255 +n02973805 +n02687992 +n04406817 +n02693246 +n02692232 +n03745146 +n04329190 +n04306080 +n04551055 +n03452449 +n03131669 +n03768916 +n03214253 +n03587205 +n03406966 +n03093574 +n03672352 +n03051540 +n02729837 +n03655720 +n03456186 +n02855925 +n03825080 +n04015204 +n03859495 +n03815482 +n03625943 +n03692379 +n02728440 +n03068998 +n03763968 +n03502509 +n03877472 +n03419014 +n02742322 +n04596852 +n03863108 +n03441112 +n02671780 +n02846141 +n03381126 +n02756098 +n04059157 +n02814774 +n03746330 +n04335693 +n04241249 +n04194127 +n03863262 +n04001845 +n02738859 +n03386870 +n03216402 +n02730930 +n04207903 +n03121897 +n03015478 +n03268645 +n04266375 +n03623198 +n03450516 +n04532106 +n03010795 +n02669723 +n02811719 +n03324928 +n03239259 +n03615563 +n03513137 +n03531281 +n04498389 +n03497657 +n02954340 +n03124474 +n04432203 +n03379051 +n03492922 +n03127747 +n04356595 +n03404360 +n03124170 +n02817516 +n02859184 +n04248507 +n03325941 +n02987379 +n04259630 +n04482177 +n02818135 +n03984643 +n02869837 +n03950899 +n02881757 +n03766322 +n03046029 +n03937835 +n02799323 +n03103563 +n04209133 +n03610682 +n02776825 +n03331077 +n04387095 +n02831237 +n04232153 +n03049924 +n04228693 +n04556408 +n02807133 +n03787032 +n04612026 +n02816768 +n03502331 +n04143897 +n04104770 +n03188531 +n04605572 +n04097866 +n04574067 +n03655072 +n04230808 +n04508163 +n04172904 +n04531873 +n04197391 +n03863923 +n03540090 +n02922578 +n04488530 +n04489008 +n04332580 +n03404149 +n03816005 +n04370774 +n03657511 +n04371563 +n03487642 +n04046277 +n04350905 +n04370048 +n03450734 +n03314884 +n03826039 +n02998841 +n03719743 +n03797182 +n03505504 +n04495698 +n03325584 +n04325704 +n03520493 +n03615655 +n03237992 +n03617480 +n02667093 +n02807616 +n03410938 +n04269822 +n03866082 +n03454442 +n03770439 +n03617312 +n03732458 +n02780815 +n03205669 +n04136333 +n03534580 +n03920737 +n02892767 +n03387323 +n04223299 +n03421324 +n03132776 +n04508949 +n02863014 +n02944146 +n04514241 +n03013580 +n04508489 +n03112869 +n03885788 +n04103665 +n03673450 +n03688192 +n02930214 +n04509171 +n03824381 +n02854739 +n04426427 +n02837887 +n02901114 +n03885028 +n03234164 +n04602956 +n03629231 +n03595614 +n03163381 +n03978966 +n03057021 +n03045337 +n04252560 +n04363777 +n03254046 +n04187970 +n03398228 +n03630383 +n03456665 +n03589791 +n04049405 +n02957008 +n04123448 +n03404251 +n03751269 +n04222307 +n02867966 +n03902756 +n04368496 +n03228254 +n02864504 +n03891051 +n03844815 +n04479046 +n03770954 +n04122492 +n03980874 +n04445154 +n04445040 +n03607923 +n04173907 +n04497570 +n04186455 +n02936402 +n04205318 +n03877674 +n04370288 +n04132158 +n02896442 +n03019434 +n04233715 +n03600285 +n03903733 +n03688605 +n03594734 +n03107488 +n03660124 +n04337287 +n02825442 +n02910864 +n03543112 +n02831595 +n03653833 +n03815615 +n03128085 +n02865351 +n04591157 +n02883205 +n02847631 +n03710721 +n04371430 +n02837789 +n03226538 +n03943920 +n04222470 +n03885669 +n02925519 +n04427715 +n04504141 +n04502197 +n02963159 +n04370456 +n04021028 +n04453666 +n03464053 +n02944075 +n03236735 +n02861387 +n02854926 +n03480579 +n03062015 +n04136161 +n02936570 +n04355511 +n03013438 +n04334105 +n03450230 +n03604400 +n03205574 +n02898585 +n04397645 +n02781121 +n03429682 +n03775071 +n03616979 +n02827606 +n03405595 +n03781683 +n03527565 +n02972397 +n03540267 +n04434932 +n04254777 +n04323819 +n03885904 +n03710637 +n02752496 +n04378956 +n03622931 +n02736798 +n03836976 +n03026506 +n03384891 +n03289985 +n03859958 +n02726017 +n03113657 +n03320519 +n03113835 +n03398153 +n04285803 +n02669534 +n03206718 +n03476083 +n03201776 +n02780704 +n03201638 +n03239054 +n02683454 +n04459018 +n04584207 +n03237416 +n02887489 +n02752615 +n03528263 +n03251766 +n04517823 +n03584829 +n04488857 +n03150511 +n04580493 +n04179913 +n04174101 +n03620052 +n03534776 +n04475631 +n04309833 +n03207941 +n04070727 +n04554684 +n03102654 +n03273913 +n03557590 +n03170635 +n04442312 +n03761084 +n04442441 +n03063338 +n03543254 +n04542943 +n03212114 +n03297495 +n04330340 +n03862676 +n03378174 +n03557692 +n03102371 +n03273740 +n03425595 +n04003241 +n02905036 +n04111531 +n03259280 +n03425241 +n03483316 +n03050655 +n04277826 +n04496726 +n04607242 +n02808304 +n03219010 +n04499446 +n02821030 +n03938725 +n04188179 +n04439712 +n03971218 +n03223553 +n02856463 +n03250279 +n03882058 +n03635668 +n02846511 +n04251791 +n04189816 +n02731900 +n04225987 +n04214046 +n04149813 +n04543996 +n03502200 +n03005285 +n03969259 +n04254009 +n04446521 +n04208936 +n04559451 +n03371875 +n03993053 +n04108268 +n03106110 +n03644378 +n02919890 +n04290079 +n03107046 +n04426788 +n02874537 +n04581829 +n03641569 +n03367545 +n04598965 +n04605321 +n00004475 +n00006484 +n12739332 +n00017222 +n00015388 +n01326291 +n11537327 +n00007846 +n12992868 +n00005787 +n12172906 +n13083586 +n13123431 +n11536673 +n11552806 +n13083023 +n13100156 +n12476510 +n11545524 +n11552386 +n13121544 +n12205694 +n13100677 +n13103136 +n13085113 +n13084834 +n13134302 +n13084184 +n12477163 +n12477583 +n12477747 +n12480895 +n12479537 +n12481458 +n11547562 +n11545714 +n13221529 +n13220122 +n13223265 +n13223588 +n13223710 +n12953206 +n13194572 +n13205058 +n12961879 +n12953484 +n13186654 +n13197274 +n13173882 +n13229543 +n13192625 +n13185269 +n13193642 +n13207335 +n13183056 +n13200651 +n13195341 +n13206817 +n13199970 +n12957924 +n13198914 +n13199717 +n13215586 +n13190747 +n13193856 +n13194036 +n11665372 +n11596108 +n12694486 +n11666854 +n11669921 +n11672400 +n12606438 +n12799776 +n11736694 +n12008487 +n11955896 +n12879527 +n12884260 +n12034141 +n12290748 +n12026476 +n12833149 +n11892817 +n12914923 +n11969607 +n11794024 +n12026018 +n11672269 +n12830222 +n11811473 +n12022054 +n11971406 +n11826198 +n12950314 +n11857875 +n11988596 +n11939699 +n11915214 +n11821184 +n12293723 +n11814584 +n11725015 +n12890265 +n11733312 +n11859472 +n11971248 +n11888800 +n11971927 +n12898774 +n11810358 +n11904109 +n11943407 +n11978233 +n12683407 +n12950126 +n11726707 +n11813077 +n11889619 +n11905749 +n11812910 +n11900569 +n12020184 +n11960245 +n11859737 +n12909421 +n12041446 +n12909917 +n11992806 +n11807979 +n11925303 +n11971783 +n11939491 +n11918473 +n11989869 +n11727091 +n11793779 +n11891175 +n11792341 +n11839568 +n11943660 +n11947802 +n12475242 +n11815491 +n12480456 +n11839823 +n11732567 +n12475035 +n12360108 +n12833985 +n11941924 +n11883328 +n11719286 +n11736851 +n11887119 +n12001707 +n11950345 +n11892637 +n11805956 +n11892029 +n11806219 +n12008252 +n11918286 +n11962272 +n12093600 +n12836862 +n12093329 +n11733054 +n12020507 +n11931918 +n11958080 +n12877838 +n11812094 +n11811706 +n11923174 +n12023726 +n12023407 +n11923637 +n11990313 +n11915899 +n12030908 +n12015221 +n11990167 +n11981192 +n11980318 +n11972759 +n11921395 +n12294124 +n12295796 +n12294723 +n12294331 +n12294871 +n12296432 +n12295033 +n11726269 +n11725821 +n11725973 +n12891305 +n12891643 +n11978713 +n11979527 +n11978961 +n11979715 +n12683571 +n12683791 +n11901759 +n11908549 +n11901294 +n11903671 +n11901977 +n11902389 +n11908846 +n11901597 +n11905392 +n11902200 +n11906917 +n12044467 +n12052787 +n12056217 +n12075830 +n12055516 +n12083113 +n12047884 +n12048056 +n12080820 +n12070381 +n12061380 +n12080395 +n12061614 +n12074408 +n12070583 +n12071744 +n12049282 +n12047345 +n12064389 +n12075010 +n12052447 +n12053405 +n12050533 +n12077944 +n12086539 +n12064591 +n12058822 +n12046028 +n12083591 +n12073991 +n12043444 +n12086012 +n12073554 +n12046815 +n12063639 +n12058630 +n12084890 +n12070016 +n12076223 +n12069679 +n12048399 +n12049562 +n12076577 +n12086192 +n12074867 +n12075299 +n12072722 +n12066018 +n12084555 +n12070712 +n12079963 +n12065316 +n12059314 +n12085664 +n12050959 +n12062468 +n12085267 +n12078172 +n12057211 +n12057447 +n12056758 +n12056601 +n12043836 +n12043673 +n12067193 +n12066630 +n12062781 +n12062626 +n11808299 +n11808721 +n11808932 +n11808468 +n11809594 +n11809094 +n11727358 +n11727738 +n11727540 +n11816649 +n11816336 +n11816829 +n11816121 +n11815918 +n11815721 +n12362274 +n12362668 +n12361946 +n11950877 +n11950686 +n11961100 +n12020736 +n12020941 +n11934616 +n11933546 +n11934807 +n12879963 +n12015959 +n11836722 +n11860555 +n12258885 +n11980682 +n12016567 +n11737534 +n11965627 +n11991263 +n11989393 +n12006766 +n12887293 +n12937130 +n12291959 +n11972291 +n11927215 +n12012111 +n11970586 +n11963932 +n11966215 +n11966083 +n12006930 +n12007196 +n11600372 +n11599324 +n11603246 +n11602873 +n11603835 +n11601333 +n12484784 +n12610328 +n11791569 +n11714853 +n13122364 +n11715430 +n11715678 +n12801781 +n11728099 +n11786131 +n12150028 +n12801520 +n11789066 +n11792742 +n12152532 +n12151615 +n12152722 +n11733548 +n11720353 +n12810595 +n12342299 +n13238375 +n12867826 +n12665048 +n11973341 +n12312728 +n11818069 +n12848499 +n11779300 +n12822955 +n12816508 +n12719684 +n12350758 +n12095020 +n11861641 +n11962667 +n12870891 +n12939282 +n12812478 +n12031927 +n12023108 +n12858150 +n12861892 +n12841007 +n12212361 +n12869061 +n12906214 +n12910285 +n12486574 +n12090890 +n12702948 +n12437513 +n11968931 +n11817914 +n11772408 +n12932173 +n12817694 +n11910460 +n12603449 +n12939874 +n12002428 +n12015525 +n11807108 +n12835331 +n12168565 +n12840362 +n12352287 +n11969166 +n11968704 +n12821895 +n12344283 +n11866248 +n11995092 +n12622875 +n11735053 +n12548280 +n13150894 +n12685431 +n12387633 +n12171966 +n12796022 +n12934036 +n12443323 +n12870535 +n12682668 +n12778605 +n12623077 +n12836212 +n11982115 +n12003696 +n12005656 +n12098403 +n12606545 +n11902709 +n12882945 +n12785889 +n11986511 +n12682411 +n12469517 +n12029635 +n12860365 +n12552309 +n11977303 +n11825351 +n12836337 +n12844939 +n12925179 +n11926833 +n12604228 +n11752578 +n12855042 +n11956850 +n12092262 +n12506991 +n12882779 +n11747468 +n12385429 +n12822115 +n12821505 +n12607456 +n12819728 +n12817464 +n12811027 +n12024445 +n12573474 +n12864545 +n11949402 +n11868814 +n11953038 +n12599435 +n12840749 +n13233727 +n12342498 +n12795555 +n11984542 +n12847008 +n12719944 +n11855274 +n12095647 +n12441183 +n12942572 +n12602980 +n12684379 +n12441390 +n12785724 +n11916696 +n12574320 +n12092417 +n12036939 +n11700058 +n12845413 +n11824146 +n11910271 +n11916467 +n11807525 +n12101870 +n11939180 +n12353754 +n12104501 +n12794985 +n12355760 +n12793015 +n12932966 +n12931542 +n12889713 +n12849061 +n11722466 +n11720643 +n12665857 +n12665271 +n11785668 +n11780148 +n11784497 +n11782036 +n11786539 +n11782761 +n12858871 +n12858397 +n11959632 +n11959862 +n12911673 +n12911440 +n12091213 +n12091550 +n12091377 +n12091953 +n12703557 +n12703190 +n12703383 +n12437930 +n12437769 +n12352639 +n12352844 +n12352990 +n12344700 +n12344483 +n12687957 +n12685831 +n12687698 +n12687462 +n12686274 +n12686077 +n12687044 +n12686676 +n12388989 +n12388143 +n12387839 +n12388858 +n12390099 +n12389501 +n12390314 +n12782915 +n12779603 +n12781940 +n12782530 +n11753700 +n11753355 +n11753143 +n12856680 +n12855494 +n12540250 +n12515711 +n12575322 +n12575812 +n12556307 +n12539306 +n12557681 +n12558425 +n12866162 +n12865824 +n12865037 +n12866635 +n12865562 +n12866002 +n11879054 +n11878283 +n11875691 +n11876634 +n11877193 +n11876803 +n11876432 +n11870418 +n11875938 +n11894327 +n11881742 +n11870747 +n11896722 +n11879722 +n11895092 +n11894770 +n11882074 +n11882426 +n13235503 +n13234678 +n12039317 +n12037691 +n12038406 +n12038585 +n12148757 +n12102133 +n12121610 +n12139575 +n12113195 +n12112918 +n12116429 +n12141495 +n12133462 +n12108871 +n12104238 +n12141167 +n12115180 +n12112008 +n12128071 +n12146311 +n12124627 +n12110778 +n12129134 +n12134025 +n12145477 +n12142085 +n12135898 +n12137120 +n12127030 +n12127768 +n12127460 +n12356023 +n12357485 +n12793494 +n12794135 +n12849279 +n12849416 +n12847374 +n12517642 +n11731659 +n12813189 +n11838916 +n12517445 +n12513172 +n12823859 +n12566954 +n13148208 +n12158798 +n12485981 +n13237188 +n12826516 +n13120211 +n12580654 +n11769621 +n12824053 +n11769803 +n12383402 +n12823717 +n12157769 +n13144794 +n12371439 +n12159055 +n12160490 +n12158443 +n12160303 +n12159388 +n12160857 +n12161969 +n12827270 +n12828791 +n12827537 +n11788727 +n11789589 +n12571781 +n11792029 +n12384839 +n12384227 +n12384037 +n12164363 +n12166128 +n12165170 +n12164881 +n12164656 +n13146583 +n13145040 +n12509476 +n13112664 +n13104059 +n12655869 +n12546183 +n12671651 +n12215579 +n12901724 +n12938193 +n12680864 +n12329260 +n12924623 +n12659356 +n12788201 +n12343480 +n13142504 +n11830906 +n12504783 +n12659539 +n12214789 +n11699442 +n12217453 +n12574866 +n12374418 +n12249542 +n13118707 +n12215022 +n12342852 +n12762896 +n12306717 +n11769176 +n12805146 +n12519089 +n11754893 +n12772908 +n12624381 +n12482031 +n12243109 +n12223764 +n12170585 +n12230794 +n12791329 +n12674120 +n12917901 +n12237486 +n12185859 +n12681893 +n12905412 +n12899537 +n12899752 +n12806015 +n12011620 +n12922763 +n12651229 +n12303083 +n11928352 +n11926365 +n12223569 +n12791064 +n12311579 +n11834654 +n11760785 +n12749679 +n12489815 +n12666965 +n12929403 +n12902662 +n12620196 +n12237641 +n12625383 +n12244153 +n11774513 +n12520864 +n12516828 +n12849717 +n12485653 +n12790430 +n12788854 +n11924445 +n12632335 +n11947251 +n12099342 +n11931540 +n12545635 +n11778257 +n11924849 +n12367611 +n12602262 +n12328567 +n12328398 +n12629305 +n11907689 +n11940006 +n12546962 +n11925898 +n11947629 +n11948864 +n11948264 +n12368451 +n12369309 +n12368028 +n12307240 +n12307076 +n12483427 +n12483625 +n12482893 +n12483841 +n12173664 +n12173912 +n12171316 +n12174521 +n12171098 +n12177844 +n12174311 +n12178896 +n12179122 +n12676534 +n12676703 +n12675876 +n12920204 +n12921868 +n12621410 +n12622297 +n12245319 +n12244650 +n12244819 +n12521394 +n12530818 +n12849952 +n12850336 +n12850168 +n12495146 +n12570972 +n12196129 +n13107694 +n12202936 +n13111881 +n13103877 +n12409231 +n12765115 +n12265600 +n12409470 +n12713866 +n12281241 +n11709205 +n12189429 +n12562785 +n12284821 +n12401335 +n12570394 +n11759224 +n12286988 +n12491826 +n12527738 +n12696492 +n12325234 +n12198286 +n12330891 +n11650558 +n12405714 +n12284262 +n12714755 +n13109733 +n12262553 +n12506341 +n12303462 +n12260799 +n12302071 +n12492106 +n11762433 +n12582231 +n12774299 +n13108481 +n12267411 +n11756092 +n12662772 +n13108662 +n12528549 +n12690653 +n12180885 +n13108545 +n13108323 +n12334293 +n12670758 +n12286826 +n12724942 +n12155009 +n12570703 +n12523475 +n12154773 +n12915811 +n12268246 +n13108131 +n12806732 +n12524188 +n11758799 +n12496427 +n12568186 +n12495895 +n12196527 +n12196336 +n12196694 +n12203529 +n12204175 +n12282933 +n12282527 +n12283542 +n12282737 +n12282235 +n12402051 +n12402840 +n12401684 +n12402348 +n12402596 +n11759853 +n11759404 +n12406715 +n12406488 +n12407890 +n12406902 +n12330469 +n12345899 +n11709674 +n12329473 +n12200143 +n11712282 +n12752205 +n13110915 +n12513933 +n12189987 +n12731401 +n12717224 +n12717072 +n12946849 +n12756457 +n12201580 +n11703669 +n12491017 +n12190410 +n12242409 +n07754894 +n12818346 +n12658308 +n12658118 +n12494794 +n12317296 +n12651821 +n11711764 +n11710136 +n11711537 +n11710393 +n12755225 +n12753573 +n12754648 +n12754781 +n12755727 +n12754981 +n12755387 +n12753007 +n12753245 +n12754003 +n12759273 +n12318378 +n12288823 +n12319204 +n12319414 +n12732491 +n12733647 +n12732756 +n12732009 +n12733870 +n12732966 +n12733218 +n12948495 +n12948251 +n12948053 +n12947313 +n12757303 +n12757458 +n11704093 +n11705171 +n12707781 +n12399132 +n12400720 +n12345280 +n11695599 +n12771192 +n12704343 +n12638218 +n12644902 +n12190869 +n12373100 +n12300840 +n12743352 +n12651611 +n12629666 +n12636224 +n12648045 +n12399384 +n12301180 +n12744387 +n12640839 +n12745386 +n12633638 +n12771390 +n12761284 +n12400489 +n12333530 +n12333771 +n12333053 +n12641413 +n12332030 +n12711984 +n12709901 +n12708293 +n12713063 +n12711596 +n12709103 +n12709688 +n12710415 +n12710295 +n12710693 +n12708654 +n12708941 +n12643313 +n12638753 +n12646740 +n12645174 +n12650379 +n12634429 +n12633994 +n12634211 +n12635532 +n12635955 +n12635744 +n12643473 +n12649065 +n12641931 +n12642200 +n12650556 +n12649539 +n12649317 +n12646605 +n12647560 +n12648888 +n12263987 +n12263038 +n12306089 +n12305986 +n12305293 +n12304703 +n12305475 +n12262018 +n12261808 +n12261571 +n12595699 +n12587132 +n12583126 +n12596709 +n12591351 +n12596849 +n12582665 +n12596148 +n12595964 +n12582846 +n12587803 +n12591017 +n12588320 +n12588780 +n12585629 +n12597134 +n12598027 +n12597466 +n12583401 +n12593994 +n12590232 +n11757653 +n11756669 +n11757851 +n11664418 +n13108841 +n11647703 +n11628793 +n11658331 +n11623105 +n11630017 +n11628456 +n11658544 +n11643835 +n11624531 +n11661372 +n11645914 +n11630489 +n11640132 +n11608250 +n11620673 +n11618861 +n11627168 +n11623815 +n11624192 +n11623967 +n11635152 +n11634736 +n11635433 +n11636204 +n11644462 +n11644226 +n11644046 +n11626585 +n11625632 +n11625003 +n11626826 +n11625804 +n11626152 +n11626409 +n11646694 +n11646167 +n11632167 +n11631854 +n11632619 +n11616662 +n11611561 +n11611356 +n11617631 +n11612575 +n11611758 +n11614713 +n11615387 +n11612018 +n11611087 +n11612923 +n11616486 +n11618290 +n11612349 +n11611233 +n11617090 +n11614250 +n11618525 +n11615026 +n11617272 +n11614039 +n11613459 +n11615967 +n11614420 +n11621029 +n11622184 +n11622591 +n11621281 +n11622368 +n11621950 +n11621547 +n11621727 +n11619455 +n11619227 +n11627512 +n11628087 +n11627908 +n12691661 +n12691428 +n12316572 +n12334891 +n12340755 +n12316444 +n12336727 +n12338796 +n12338454 +n12336973 +n12336092 +n12336224 +n12337617 +n12725521 +n12727101 +n12729521 +n12726670 +n12729315 +n12729729 +n12731029 +n12270741 +n12271643 +n12278650 +n12279458 +n12269241 +n12275489 +n12273114 +n12276872 +n12278371 +n12272883 +n12269652 +n12273768 +n12277800 +n12271933 +n12279772 +n12270946 +n12269406 +n12275675 +n12276628 +n12275131 +n12274358 +n12272239 +n12277578 +n12501202 +n12814643 +n12493208 +n12807773 +n12807409 +n12807251 +n11758122 +n12915568 +n12656369 +n12656685 +n12547215 +n12547503 +n11944196 +n11984144 +n11805544 +n11874081 +n11965218 +n12392549 +n11956348 +n11945514 +n11944954 +n11998888 +n11953884 +n11954345 +n11955153 +n11954161 +n12421137 +n12421467 +n12411461 +n12451915 +n12425281 +n12459629 +n12421683 +n12422129 +n12421917 +n12411922 +n12418221 +n12416073 +n12413165 +n12414932 +n12412606 +n12412355 +n12414035 +n12413880 +n12453186 +n12452836 +n12450344 +n12426248 +n12429352 +n12460697 +n12449526 +n12473840 +n12458550 +n12449296 +n12472024 +n12457091 +n12465557 +n12461466 +n12454159 +n12431434 +n12451240 +n12451399 +n12450840 +n12428076 +n12428747 +n12427566 +n12427184 +n12426623 +n12427757 +n12461109 +n12460957 +n12454705 +n12454949 +n12435777 +n12435649 +n11819509 +n11819912 +n11842204 +n11852028 +n11851258 +n11847169 +n11853813 +n11848479 +n11844892 +n11851839 +n11845557 +n11849871 +n11849983 +n11851578 +n11854479 +n11844371 +n11853356 +n11845793 +n11845913 +n11784126 +n11783920 +n12832315 +n11723770 +n11724109 +n12766869 +n12455950 +n11723227 +n12757816 +n11773987 +n12766595 +n01324610 +n02153109 +n01323599 +n01314781 +n01321579 +n01317541 +n01318894 +n01314663 +n02311060 +n01317916 +n01321230 +n01314388 +n02075612 +n02152740 +n01466257 +n01316949 +n01905661 +n01320872 +n01319467 +n01316422 +n02157206 +n10300303 +n02152881 +n01324431 +n01321854 +n01321770 +n01956344 +n01613615 +n01318279 +n02376542 +n02122948 +n01888045 +n01322343 +n01887896 +n02412440 +n01322221 +n01322604 +n01323261 +n01322685 +n02395694 +n01504344 +n01504179 +n01318381 +n02122580 +n01317813 +n02469472 +n02309337 +n02311617 +n02264232 +n02299157 +n02310585 +n02299505 +n02302620 +n02295390 +n02310717 +n02288268 +n02297442 +n02300797 +n02285801 +n02307325 +n02376791 +n02377063 +n01323355 +n01469103 +n01468712 +n01471682 +n01473806 +n01627424 +n01861778 +n09828216 +n01459791 +n02156871 +n01661091 +n01503061 +n02512053 +n01477525 +n02528163 +n02512938 +n01482071 +n02638596 +n01457852 +n01455778 +n01456756 +n02552171 +n01428580 +n02549989 +n02640857 +n02641379 +n02639087 +n02639605 +n02640242 +n02554730 +n02618827 +n02549248 +n02603317 +n01451426 +n02548247 +n02642107 +n02657368 +n02603540 +n02652668 +n02560110 +n02556846 +n02555863 +n02581957 +n02564270 +n02623445 +n02565573 +n02610664 +n02590702 +n02588286 +n02620167 +n02573704 +n02576223 +n02606384 +n02605316 +n02619550 +n02561108 +n02619165 +n02610066 +n02562315 +n02586543 +n02593019 +n02594250 +n02616851 +n02585872 +n02607862 +n02557182 +n02557318 +n02557749 +n02624167 +n02628062 +n02631475 +n02630281 +n02631041 +n02629230 +n02626762 +n02625258 +n02625612 +n02624807 +n02626265 +n02625851 +n02627292 +n02627532 +n02576575 +n02579928 +n02580336 +n02576906 +n02579303 +n02578771 +n02578928 +n02580679 +n02580830 +n02607201 +n02607470 +n02607072 +n02605703 +n02606052 +n02605936 +n02561381 +n02561661 +n02561514 +n02564720 +n02563648 +n02563182 +n02563792 +n02562796 +n02565072 +n02565324 +n02599052 +n02596381 +n02597608 +n02596067 +n02595702 +n02598573 +n02598878 +n02642644 +n02649546 +n02643112 +n02643566 +n02643836 +n02644113 +n02658531 +n02657694 +n02660208 +n02654745 +n02654425 +n02656670 +n02655020 +n02655523 +n02653145 +n02656032 +n02655848 +n02541687 +n02542432 +n02524202 +n02533834 +n02543565 +n02517442 +n01438208 +n02526121 +n02529772 +n02518324 +n02520147 +n02519686 +n02519862 +n02583567 +n01444339 +n01446589 +n01438581 +n01439121 +n01448951 +n02584449 +n02584145 +n02583890 +n01446760 +n01447331 +n01448594 +n01448291 +n01439514 +n01442972 +n01440764 +n01443831 +n01443537 +n01443243 +n01449712 +n01449374 +n02527622 +n02527057 +n02527271 +n02532602 +n02533209 +n02566834 +n02537085 +n02534734 +n02514041 +n02568959 +n02568087 +n02570164 +n02569484 +n02537716 +n02538216 +n02537525 +n02537319 +n02538010 +n02536456 +n02535537 +n02535258 +n02536864 +n02535759 +n01482330 +n01495701 +n01487506 +n01495493 +n01486838 +n01488918 +n01492357 +n01494475 +n01483522 +n01488038 +n01489501 +n01491006 +n01489709 +n01489920 +n01490112 +n01491361 +n01490670 +n01493146 +n01492569 +n01484850 +n01484097 +n01483830 +n01498041 +n01496331 +n01499396 +n01500476 +n01500091 +n01501160 +n01498989 +n01629276 +n01639765 +n01629962 +n01630284 +n01629819 +n01637615 +n01632047 +n01631663 +n01630670 +n01630901 +n01632458 +n01632777 +n01632601 +n01645776 +n01640846 +n01644900 +n01643896 +n01650167 +n01644373 +n01646648 +n01646902 +n01646292 +n01646802 +n01646388 +n01647640 +n01646555 +n01642539 +n01641206 +n01641577 +n01641391 +n01642257 +n01641739 +n01650690 +n01652026 +n01886756 +n01871265 +n01871875 +n01874434 +n01862399 +n02082791 +n01887474 +n01889074 +n02372584 +n01888411 +n02453611 +n02430559 +n01887623 +n02469914 +n02075296 +n02139199 +n02062017 +n02323449 +n02372952 +n01888181 +n02329401 +n01887787 +n02453108 +n01888264 +n02461830 +n02370806 +n01891633 +n01893825 +n02454794 +n02456962 +n02454379 +n02460009 +n02458135 +n02457945 +n02457408 +n02460451 +n02461128 +n02470238 +n02501583 +n02472293 +n02470325 +n02496913 +n02484322 +n02475669 +n02474777 +n02475078 +n02470899 +n02483092 +n02480153 +n02483708 +n02483362 +n02481823 +n02480495 +n02480855 +n02482650 +n02482474 +n02481103 +n02481366 +n02481500 +n02500267 +n02497673 +n02499316 +n02499808 +n02499022 +n02484473 +n02489589 +n02486410 +n02485536 +n02489166 +n02488702 +n02486261 +n02487347 +n02484975 +n02488291 +n02486657 +n02486908 +n02487847 +n02487547 +n02493793 +n02490219 +n02494079 +n02493509 +n02492035 +n02492660 +n02491107 +n02490811 +n02507649 +n02120997 +n02134971 +n02083346 +n02441326 +n02131653 +n02509515 +n02508213 +n02509815 +n02508021 +n02509197 +n02510455 +n02127808 +n02121620 +n02128925 +n02129604 +n02128385 +n02130308 +n02129165 +n02128757 +n02129923 +n02129837 +n01323068 +n02129463 +n01322898 +n02121808 +n02124623 +n02122878 +n02123159 +n02123045 +n02123242 +n02124484 +n02124075 +n02124313 +n02122298 +n02123478 +n02123394 +n02123917 +n02123597 +n02122510 +n02122725 +n02122430 +n02126640 +n02125494 +n02127052 +n02125311 +n02125081 +n02126139 +n02126787 +n02125010 +n02127292 +n02127482 +n02127678 +n02127381 +n02138441 +n02137015 +n02137549 +n02138647 +n02138777 +n02084071 +n02115335 +n02114100 +n02083672 +n02115096 +n02118333 +n02117135 +n02110958 +n02112826 +n02111500 +n02112706 +n02113335 +n02084861 +n02111129 +n02112497 +n02110341 +n02084732 +n02111626 +n02085374 +n02087122 +n02103406 +n02110806 +n02113978 +n02111277 +n02085272 +n02113186 +n02113023 +n02113799 +n02113624 +n02113712 +n02112018 +n02112350 +n02112137 +n02111889 +n02086346 +n02086240 +n02087046 +n02085936 +n02085782 +n02085620 +n02086079 +n02086753 +n02086646 +n02086910 +n02092468 +n02087394 +n02089468 +n02098550 +n02087551 +n02089232 +n02096437 +n02096756 +n02095412 +n02096051 +n02098286 +n02093859 +n02094114 +n02093754 +n02094433 +n02095314 +n02093647 +n02097474 +n02097658 +n02098413 +n02097298 +n02096177 +n02096585 +n02095050 +n02096294 +n02093056 +n02094258 +n02093991 +n02094562 +n02098105 +n02097209 +n02097130 +n02097047 +n02095570 +n02095727 +n02095889 +n02093256 +n02093428 +n02094721 +n02094931 +n02098906 +n02099997 +n02098806 +n02100399 +n02101108 +n02099029 +n02100583 +n02100236 +n02101006 +n02100735 +n02100877 +n02102318 +n02102605 +n02101861 +n02101388 +n02101556 +n02102480 +n02102973 +n02102040 +n02102177 +n02099267 +n02099601 +n02099429 +n02099849 +n02099712 +n02091635 +n02088466 +n02090475 +n02088238 +n02091244 +n02091467 +n02088839 +n02091831 +n02088094 +n02089078 +n02088632 +n02092002 +n02090379 +n02089555 +n02088364 +n02092339 +n02090827 +n02090622 +n02090721 +n02089973 +n02089867 +n02091134 +n02091032 +n02109047 +n02103841 +n02109961 +n02108551 +n02109811 +n02109525 +n02108915 +n02106854 +n02108672 +n02107420 +n02108422 +n02104523 +n02108089 +n02108254 +n02104029 +n02104280 +n02106966 +n02104365 +n02107142 +n02107312 +n02110627 +n02110185 +n02110063 +n02107574 +n02108000 +n02107683 +n02107908 +n02104882 +n02105412 +n02105855 +n02105505 +n02106166 +n02106030 +n02106550 +n02105641 +n02106662 +n02105251 +n02106382 +n02105056 +n02105162 +n02116738 +n02115641 +n02115913 +n02114855 +n01322508 +n02114712 +n02114548 +n02114367 +n02119022 +n02119477 +n02119789 +n02120079 +n02120505 +n02119634 +n02117900 +n02117512 +n02442845 +n02443484 +n02446206 +n02450295 +n02445394 +n02444819 +n02441942 +n02443114 +n02449350 +n02445715 +n02447366 +n02443346 +n02445004 +n02445171 +n02134084 +n02133161 +n01322983 +n02133704 +n02132136 +n02134418 +n02132580 +n02132788 +n02141306 +n02140049 +n02139671 +n02146371 +n02145424 +n02147591 +n02147947 +n02062430 +n02073250 +n02075927 +n02062744 +n02066707 +n02063224 +n02068974 +n02068541 +n02070430 +n02069412 +n02069701 +n02071636 +n02071294 +n02072798 +n02070174 +n02069974 +n02066245 +n02064338 +n02064816 +n02065407 +n02065026 +n02073831 +n02074367 +n02081571 +n02076196 +n02079389 +n02076779 +n02080415 +n02079851 +n02080146 +n02077658 +n02077152 +n02077923 +n02078574 +n02078738 +n02079005 +n02328429 +n02323902 +n02324045 +n02326432 +n02325722 +n02325366 +n02324587 +n02324850 +n02324514 +n02328150 +n02324431 +n02327842 +n02326862 +n02327028 +n02367492 +n02331046 +n02365480 +n02343320 +n02341974 +n02346627 +n02366959 +n02339376 +n02363005 +n02342885 +n02359324 +n02355227 +n02361337 +n02359556 +n02364520 +n02343772 +n02330245 +n02338145 +n02353861 +n02333546 +n02333909 +n02360282 +n02358091 +n02359915 +n02355477 +n02358890 +n02358390 +n02356381 +n02357111 +n02356977 +n02357401 +n02356798 +n02361706 +n02361587 +n02364840 +n02364673 +n02332755 +n02332156 +n02503517 +n02504458 +n02504013 +n02394477 +n02373336 +n02399000 +n02437136 +n02395003 +n02437616 +n02438580 +n02397744 +n02398521 +n02397529 +n02429456 +n02430045 +n02401031 +n02439033 +n02439398 +n02434190 +n02433925 +n02433318 +n02432983 +n02431337 +n02432511 +n02430830 +n02431122 +n02434954 +n02432291 +n02431785 +n02431976 +n02433546 +n02432704 +n02414578 +n02410509 +n02411206 +n02407959 +n02402010 +n02419796 +n02411705 +n02418064 +n02416519 +n02416104 +n02415435 +n02415253 +n02415577 +n02415829 +n02410702 +n02410900 +n02408817 +n02408429 +n02409508 +n02404573 +n02402175 +n02404906 +n02402425 +n02405302 +n02410011 +n02404186 +n02403003 +n02403325 +n02403231 +n02403740 +n02403454 +n02406174 +n02404432 +n02406647 +n02407625 +n02407071 +n02405929 +n02407276 +n02407390 +n02406533 +n02424305 +n02421136 +n02420509 +n02427724 +n02426813 +n02426481 +n02421792 +n02421449 +n02424695 +n02420828 +n02422391 +n02422699 +n02424486 +n02425887 +n02422106 +n02424085 +n02428508 +n02428349 +n02423022 +n02424909 +n02425228 +n02423218 +n02423589 +n02413131 +n02413050 +n02411999 +n02412210 +n02412080 +n02418465 +n02419336 +n02419634 +n02416964 +n02416820 +n02417914 +n02417387 +n02417070 +n02416880 +n02417534 +n02437482 +n02437312 +n02396427 +n02397096 +n02396014 +n02395406 +n02438173 +n02438272 +n02391994 +n02393580 +n02374149 +n02393940 +n02392434 +n02393161 +n02392824 +n02374451 +n02391049 +n02389346 +n02388917 +n02377603 +n02382948 +n02389128 +n02381460 +n02389261 +n02382204 +n02375302 +n02376918 +n02387722 +n02388832 +n02381609 +n02377703 +n02388735 +n02386014 +n02380464 +n02386310 +n02377480 +n02380335 +n02382437 +n02389026 +n02385214 +n02383231 +n02388276 +n02377291 +n02377181 +n02377388 +n02379430 +n02378969 +n02378541 +n02381364 +n02379329 +n02381004 +n02381261 +n02379908 +n02379183 +n02386141 +n02386224 +n02382338 +n02387254 +n02386496 +n02386853 +n02387093 +n02386968 +n02387346 +n02382039 +n02380745 +n02380583 +n02382750 +n02382635 +n02382850 +n02391234 +n02391373 +n02391508 +n02390015 +n02389779 +n02389559 +n01872401 +n01873310 +n01872772 +n01877134 +n01882714 +n01883070 +n01875313 +n01874928 +n01883513 +n01881171 +n01877606 +n01877812 +n01878929 +n01879509 +n01884834 +n01885498 +n01662622 +n01661818 +n01662784 +n01669372 +n01669191 +n01666228 +n01667778 +n01672032 +n01669654 +n01663401 +n01665932 +n01668665 +n01670092 +n01667114 +n01668892 +n01664990 +n01664065 +n01663782 +n01665541 +n01664369 +n01664674 +n01664492 +n01670802 +n01671125 +n01670535 +n01671479 +n01696633 +n01726692 +n01673282 +n01674464 +n01699831 +n01698434 +n01697178 +n01698640 +n01699040 +n01697611 +n01697457 +n01740551 +n01752165 +n01751748 +n01745125 +n01741562 +n01727646 +n01753488 +n01752736 +n01752585 +n01753032 +n01753959 +n01754533 +n01754370 +n01754876 +n01757901 +n01757677 +n01755581 +n01757115 +n01755740 +n01756089 +n01756508 +n01756291 +n01756733 +n01757343 +n01747885 +n01749939 +n01751472 +n01747589 +n01749582 +n01746359 +n01745484 +n01748264 +n01748906 +n01741943 +n01743605 +n01742821 +n01742172 +n01743086 +n01744100 +n01743936 +n01744401 +n01730960 +n01735189 +n01733757 +n01729322 +n01732244 +n01731545 +n01737021 +n01729977 +n01730812 +n01730563 +n01728572 +n01728920 +n01739381 +n01734418 +n01740131 +n01735577 +n01735439 +n01734104 +n01733957 +n01732614 +n01732789 +n01737875 +n01737472 +n01737728 +n01730185 +n01730307 +n01734808 +n01734637 +n01675722 +n01693783 +n01694709 +n01684133 +n01692333 +n01695060 +n01685808 +n01676755 +n01687665 +n01674990 +n01694178 +n01692864 +n01689411 +n01681940 +n01681653 +n01678343 +n01682714 +n01682435 +n01681328 +n01680264 +n01679626 +n01677366 +n01677747 +n01679962 +n01680655 +n01680478 +n01687978 +n01689081 +n01688243 +n01693334 +n01693175 +n01690149 +n01689811 +n01700470 +n01713764 +n01701859 +n01704323 +n01515303 +n01844917 +n01524359 +n01514668 +n01833805 +n01838038 +n01825930 +n01844551 +n01604330 +n01834918 +n01822602 +n01514752 +n01517565 +n01789386 +n01844231 +n01816887 +n01517966 +n01503976 +n01514859 +n02000954 +n01858441 +n02016358 +n02021795 +n01845132 +n02008041 +n02014237 +n02021050 +n02018795 +n02005790 +n02002075 +n02013177 +n02012849 +n02013706 +n02014524 +n02007558 +n02014941 +n02006656 +n02005399 +n02022684 +n02008497 +n02010453 +n02009229 +n02011281 +n02008643 +n02008796 +n02011460 +n02010728 +n02011016 +n02009750 +n02009508 +n02009380 +n02009912 +n02010272 +n02012185 +n02011805 +n02006063 +n02006364 +n02003204 +n02002724 +n02002556 +n02004131 +n02003839 +n02004492 +n02004855 +n02017725 +n02015357 +n02016066 +n02015554 +n02018027 +n02018368 +n02018207 +n02006985 +n02007284 +n02023341 +n02034129 +n02034295 +n02036053 +n02040266 +n02037110 +n02034661 +n02031585 +n02031934 +n02030996 +n02036711 +n02026059 +n02033779 +n02038993 +n02033561 +n02037464 +n02024479 +n02025239 +n02023992 +n02024763 +n02025043 +n02023855 +n02034971 +n02035210 +n02032222 +n02032355 +n02032480 +n02033041 +n02030287 +n02027897 +n02030837 +n02029087 +n02029378 +n02028035 +n02027075 +n02028900 +n02027492 +n02029706 +n02027357 +n02028727 +n02030035 +n02026948 +n02028175 +n02028342 +n02028451 +n02037869 +n02038466 +n01858845 +n01858906 +n01860002 +n01858281 +n01859190 +n01858780 +n01859325 +n01860187 +n01859496 +n01859689 +n01859852 +n02016956 +n02017213 +n02016816 +n02040505 +n02057731 +n02050004 +n02045369 +n02049088 +n02051474 +n02055658 +n02047614 +n02041085 +n02044178 +n02043808 +n02043333 +n02041246 +n02043063 +n02042472 +n02041678 +n02042180 +n02041875 +n02042759 +n02042046 +n02044778 +n02044517 +n02059162 +n02058221 +n02058594 +n02060411 +n02060889 +n02060133 +n02050442 +n02050313 +n02051059 +n02050586 +n02050809 +n02045864 +n02046759 +n02045596 +n02047260 +n02046939 +n02047411 +n02047045 +n02052775 +n02054036 +n02054502 +n02051845 +n02053083 +n02054711 +n02055107 +n02052204 +n02052365 +n02053425 +n02053584 +n02055803 +n02056728 +n02057035 +n02056570 +n02057330 +n02056228 +n02048115 +n02048353 +n02047975 +n01845477 +n01855672 +n01846331 +n01856890 +n01857851 +n01857079 +n01856380 +n01857512 +n01857325 +n01856072 +n01856553 +n01856155 +n01857632 +n01847253 +n01851375 +n01849676 +n01852329 +n01850192 +n01847978 +n01852400 +n01848840 +n01849157 +n01847806 +n01849466 +n01848123 +n01850553 +n01847089 +n01851895 +n01849863 +n01852142 +n01847000 +n01852671 +n01848976 +n01847407 +n01848648 +n01852861 +n01851207 +n01851038 +n01850373 +n01850873 +n01847170 +n01851573 +n01851731 +n01848555 +n01848323 +n01848453 +n01853195 +n01853870 +n01854415 +n01853498 +n01853666 +n01854838 +n01855032 +n01855476 +n01855188 +n01854700 +n01584225 +n01546506 +n01546921 +n01525720 +n01546039 +n01539573 +n01585121 +n01585715 +n01584695 +n01586374 +n01584853 +n01586020 +n01552813 +n01551711 +n01555004 +n01554448 +n01547832 +n01548301 +n01549886 +n01549430 +n01550172 +n01549641 +n01555305 +n01549053 +n01548865 +n01548492 +n01563128 +n01589718 +n01578575 +n01576695 +n01528654 +n01591697 +n01594004 +n01557185 +n01527347 +n01597022 +n01598588 +n01527617 +n01576076 +n01555809 +n01587834 +n01602630 +n01597336 +n01538955 +n01529672 +n01600657 +n01601694 +n01527194 +n01586941 +n01588002 +n01527917 +n01587526 +n01601068 +n01603600 +n01602832 +n01571904 +n01575745 +n01566645 +n01594372 +n01589286 +n01526521 +n01582856 +n01528396 +n01528845 +n01556182 +n01542786 +n01590583 +n01564914 +n01567133 +n01563746 +n01564394 +n01563449 +n01565078 +n01570676 +n01570839 +n01570267 +n01567678 +n01569060 +n01568892 +n01568294 +n01569971 +n01569262 +n01567879 +n01568720 +n01569423 +n01563945 +n01564217 +n01566207 +n01565599 +n01565930 +n01564773 +n01579410 +n01581984 +n01579578 +n01582398 +n01580077 +n01579260 +n01579028 +n01582220 +n01579149 +n01580870 +n01581166 +n01577035 +n01578180 +n01577659 +n01593028 +n01592084 +n01592694 +n01592387 +n01592540 +n01592257 +n01562265 +n01558993 +n01559477 +n01558461 +n01558307 +n01558149 +n01560105 +n01558594 +n01557962 +n01558765 +n01561732 +n01562014 +n01560280 +n01562451 +n01561452 +n01560419 +n01560636 +n01559804 +n01560793 +n01560935 +n01598988 +n01599556 +n01600085 +n01599269 +n01599159 +n01597906 +n01598074 +n01597737 +n01533651 +n01534155 +n01540233 +n01531178 +n01534762 +n01533893 +n01537134 +n01531344 +n01541386 +n01531512 +n01533481 +n01541922 +n01533000 +n01544704 +n01530575 +n01532325 +n01532511 +n01531811 +n01534582 +n01532829 +n01530439 +n01533339 +n01531971 +n01534433 +n01541102 +n01540566 +n01540832 +n01536644 +n01535469 +n01536334 +n01536186 +n01535690 +n01536780 +n01536035 +n01537544 +n01538059 +n01538630 +n01537895 +n01538200 +n01603812 +n01603953 +n01573898 +n01573074 +n01572328 +n01572782 +n01574045 +n01573240 +n01573360 +n01572654 +n01572489 +n01574560 +n01575117 +n01574390 +n01575401 +n01595450 +n01595168 +n01595624 +n01594787 +n01594968 +n01595974 +n01596273 +n01583209 +n01583495 +n01543632 +n01544389 +n01591123 +n01591005 +n01591301 +n01539925 +n01540090 +n01834540 +n01834177 +n01843065 +n01838598 +n01842235 +n01843719 +n01843383 +n01839598 +n01839330 +n01839086 +n01841102 +n01841679 +n01840775 +n01839750 +n01841441 +n01841288 +n01827403 +n01826364 +n01830915 +n01830042 +n01829413 +n01826680 +n01829869 +n01828970 +n01828556 +n01827793 +n01828096 +n01616318 +n01605630 +n01618503 +n01613294 +n01621127 +n01616764 +n01618922 +n01617766 +n01617443 +n01618082 +n01617095 +n01620414 +n01619310 +n01620735 +n01619536 +n01619835 +n01620135 +n01609751 +n01606522 +n01607812 +n01608265 +n01610955 +n01610552 +n01606809 +n01616086 +n01608432 +n01607600 +n01607962 +n01606672 +n01609956 +n01610226 +n01613177 +n01611800 +n01611472 +n01612628 +n01612476 +n01612275 +n01611969 +n01612122 +n01609391 +n01609062 +n01608814 +n01613807 +n01614343 +n01615121 +n01614925 +n01614038 +n01614556 +n01615703 +n01615458 +n01622959 +n01621635 +n01623880 +n01623425 +n01622352 +n01623615 +n01622120 +n01625562 +n01623706 +n01624115 +n01624537 +n01622483 +n01623110 +n01624833 +n01622779 +n01837072 +n01835276 +n01825278 +n01823013 +n01824575 +n01824035 +n01521399 +n01521756 +n01518878 +n01519873 +n01519563 +n01789740 +n01810700 +n01801876 +n01791463 +n01791107 +n02153203 +n01794344 +n01791954 +n01794158 +n01809106 +n01791625 +n01792429 +n01792158 +n01793435 +n01792042 +n01793715 +n01792640 +n01793249 +n01792955 +n01815601 +n01811909 +n01814370 +n01812337 +n01813088 +n01812662 +n01814921 +n01814755 +n01813532 +n01813385 +n01813948 +n01814217 +n01802721 +n01810268 +n01795088 +n01803078 +n01806567 +n01807496 +n01807105 +n01803362 +n01804163 +n01805801 +n01806297 +n01806364 +n01806143 +n01806467 +n01804478 +n01806847 +n01804653 +n01808140 +n01807828 +n01797307 +n01798484 +n01797020 +n01797886 +n01797601 +n01796729 +n01795545 +n01796340 +n01819734 +n01821203 +n01819115 +n01817346 +n01818832 +n01817953 +n01818515 +n01818299 +n01820052 +n01820348 +n01817263 +n01821869 +n01822300 +n01819313 +n01819465 +n01821076 +n01820546 +n01317089 +n01317294 +n01918744 +n01922303 +n01940736 +n02316707 +n01909422 +n01767661 +n01906749 +n01930112 +n01934440 +n01924916 +n01938454 +n01935395 +n01955084 +n01955933 +n01968315 +n01942177 +n01960459 +n01963317 +n01956481 +n01963571 +n01959985 +n01965889 +n01961985 +n01957335 +n01958038 +n01959492 +n01964441 +n01964271 +n01965529 +n01969726 +n01968897 +n01972541 +n01970164 +n01970667 +n01951274 +n01953361 +n01943899 +n01945845 +n01943087 +n01953762 +n01950731 +n01945685 +n01944390 +n01949085 +n01947396 +n01946630 +n01944812 +n01945143 +n01944955 +n02317335 +n02321170 +n02319555 +n02319095 +n02321529 +n02317781 +n01909906 +n01914163 +n01913166 +n01910747 +n01915700 +n01914609 +n01915811 +n01916925 +n01916187 +n01916481 +n01917882 +n01917289 +n01784675 +n01974773 +n01768244 +n01786646 +n01769347 +n01787835 +n02309242 +n02159955 +n01785667 +n01994910 +n01976868 +n01990007 +n01975687 +n01976146 +n01990800 +n01992773 +n01991520 +n01991028 +n01982650 +n01986806 +n01986214 +n01987545 +n01976957 +n01985128 +n01984245 +n01984695 +n01983481 +n01981276 +n01979874 +n01978455 +n01978287 +n01980166 +n01982068 +n01770393 +n01770081 +n01776192 +n01772222 +n01776313 +n01779629 +n01779148 +n01772664 +n01775370 +n01774750 +n01775062 +n01773797 +n01774384 +n01773157 +n01773549 +n02226183 +n02236896 +n02263378 +n02232951 +n02163297 +n02262449 +n02246011 +n02188699 +n02272871 +n02273392 +n02231052 +n02161457 +n02236355 +n02312427 +n02231487 +n02162561 +n02164464 +n02241569 +n02262803 +n02206270 +n02274024 +n02312640 +n02268148 +n02270623 +n02207805 +n02226429 +n02229544 +n02228341 +n02226970 +n02241426 +n02240517 +n02266050 +n02264885 +n02264363 +n02236044 +n02236241 +n02233338 +n02234355 +n02234848 +n02233943 +n02251775 +n02256656 +n02258198 +n02257284 +n02250822 +n02259212 +n02252226 +n02200198 +n02205219 +n02203152 +n02196344 +n02190166 +n02198859 +n02196119 +n02201000 +n02202006 +n02195819 +n02195526 +n02192513 +n02191773 +n02190790 +n02192252 +n02191979 +n02169974 +n02168245 +n02167151 +n02169023 +n02165456 +n02171453 +n02180875 +n02183096 +n02169497 +n02176261 +n02176439 +n02165105 +n02177972 +n02168699 +n02166567 +n02166826 +n02171869 +n02175916 +n02175569 +n02172870 +n02173373 +n02174001 +n02172182 +n02172518 +n02174659 +n02243562 +n02244797 +n02212062 +n02218371 +n02219486 +n02206856 +n02216211 +n02215770 +n02212602 +n02213107 +n02212958 +n02213543 +n02213239 +n02213788 +n02220804 +n02221083 +n02221414 +n02209354 +n02208280 +n02211627 +n02210427 +n02211444 +n02209624 +n02208498 +n02208848 +n02274259 +n02283201 +n02281787 +n02274822 +n02281406 +n02277742 +n02279972 +n02280649 +n02282257 +n02282903 +n02282385 +n02275773 +n02278210 +n02276258 +n02276902 +n02279257 +n02277094 +n02276078 +n02275560 +n02277268 +n02276355 +n02276749 +n02278024 +n02281015 +n02281136 +n02305929 +n02301452 +n02295064 +n02298541 +n02284611 +n02287004 +n02291572 +n02305085 +n02301935 +n02304432 +n02303284 +n02302969 +n02292692 +n02291748 +n02268443 +n02268853 +n01321123 +n02376679 +n01323493 +n01338685 +n01387065 +n01339083 +n01339336 +n01339801 +n01339471 +n01397114 +n01389507 +n01397871 +n01410457 +n01407798 +n01424420 +n01392380 +n01395254 +n01396048 +n11542137 +n11544015 +n11542640 +n09626238 +n09856671 +n09605289 +n09622049 +n09971273 +n09882716 +n09621232 +n09902954 +n09620794 +n09727440 +n09624168 +n09752519 +n10378026 +n10500217 +n10514429 +n09610405 +n09617867 +n10355449 +n09618957 +n10002760 +n10384496 +n09637339 +n09613191 +n09836160 +n10274815 +n09890749 +n10112591 +n10260706 +n09606527 +n09767197 +n10709529 +n09976429 +n09918554 +n10588074 +n10565667 +n09990415 +n10120330 +n09616922 +n09622302 +n09630641 +n09796809 +n09614684 +n10635788 +n09645091 +n10405694 +n09676884 +n09638875 +n09874428 +n09627906 +n09628382 +n10522759 +n10247880 +n09624980 +n10529231 +n10024362 +n09614315 +n09612848 +n09632518 +n10147935 +n09871867 +n09620078 +n09634494 +n10077593 +n10040945 +n09623038 +n10560106 +n10289039 +n10422405 +n09774783 +n10042845 +n09831962 +n10726031 +n09923673 +n09610660 +n09626031 +n10401331 +n09621545 +n10362319 +n10665698 +n09906449 +n09939313 +n10439373 +n09607630 +n09631463 +n10451450 +n10541229 +n09793141 +n10633450 +n10530959 +n09629752 +n10560637 +n10431625 +n09619168 +n09763784 +n09636339 +n10235549 +n09845401 +n10513823 +n10610465 +n09951274 +n09816771 +n10401829 +n10307234 +n10505613 +n10148035 +n09874725 +n09944022 +n10015485 +n10728624 +n10308168 +n10200781 +n10480253 +n10376523 +n09903153 +n10748620 +n10581890 +n10045713 +n10165109 +n10694258 +n10509063 +n10559996 +n10366966 +n10305802 +n10421470 +n10164492 +n10477713 +n10020890 +n10679174 +n10632576 +n10189278 +n09894445 +n10504206 +n10559288 +n09917593 +n09833441 +n10384392 +n10060352 +n09840217 +n09777012 +n10309896 +n09905185 +n10686885 +n10209731 +n10093818 +n10754189 +n10411551 +n10577284 +n10285313 +n10333439 +n10624074 +n10287213 +n09871229 +n10078719 +n09843443 +n10173771 +n10192839 +n10419785 +n10406266 +n10288964 +n10804287 +n10665587 +n10153414 +n10406765 +n10611613 +n09805324 +n09824361 +n10316360 +n10707233 +n10696508 +n09858165 +n10175248 +n09979321 +n10692482 +n10396106 +n10427764 +n10385566 +n10439851 +n09820263 +n10533013 +n09854421 +n10304914 +n10575463 +n09915651 +n10453184 +n10101634 +n10701180 +n09835230 +n10746931 +n10542888 +n10604491 +n09764381 +n09929298 +n10019406 +n09785659 +n10618342 +n10782471 +n10701644 +n10105733 +n10638922 +n09842047 +n10315561 +n09835506 +n10153594 +n09830194 +n10263411 +n10157128 +n10498816 +n10689306 +n10604380 +n10634849 +n09923561 +n09764598 +n10086568 +n10007684 +n09841696 +n10321340 +n10092488 +n10386984 +n10387196 +n10205457 +n10578021 +n10098710 +n09836519 +n09836786 +n09836343 +n09877951 +n10300154 +n10095769 +n10435988 +n09930257 +n10387324 +n10098862 +n10642596 +n10331167 +n09946814 +n10299250 +n09896170 +n10415638 +n10091450 +n10069296 +n09989502 +n10226413 +n10493685 +n09765278 +n09930876 +n10340312 +n09990777 +n09834699 +n10737103 +n10649197 +n10701962 +n10415037 +n10151760 +n10229883 +n10732010 +n10603851 +n10599806 +n10369317 +n09903501 +n10755080 +n10098245 +n10382825 +n10536416 +n10036929 +n10624310 +n09842528 +n10085869 +n09991867 +n10078131 +n10627252 +n10682953 +n10237196 +n09789566 +n10182190 +n09899671 +n10150071 +n10091651 +n10806113 +n10249459 +n10317500 +n09822830 +n10448983 +n09862621 +n10540114 +n10009276 +n10333838 +n10730728 +n10721321 +n09659188 +n09650729 +n09652149 +n09659039 +n09729530 +n09641002 +n09725653 +n09846469 +n09750770 +n10486166 +n10169147 +n09684901 +n09683757 +n09682291 +n10364198 +n10518602 +n10341573 +n10672371 +n10332861 +n10112129 +n10602470 +n10727256 +n10508141 +n10652605 +n09881265 +n09933098 +n09812338 +n09920283 +n10078806 +n10339966 +n10667477 +n10566072 +n10469874 +n10624540 +n09809925 +n09846755 +n09873899 +n09779790 +n10034614 +n10449664 +n10034201 +n09951616 +n10037385 +n09846894 +n10282672 +n10053808 +n09815790 +n10137825 +n10605985 +n10604979 +n09861946 +n10763383 +n09841188 +n10644598 +n10548681 +n10791221 +n10583790 +n09873473 +n10763620 +n10548537 +n10120671 +n10241300 +n10318293 +n10176679 +n09932508 +n10186216 +n10134178 +n10079399 +n09821831 +n09934337 +n10324560 +n10063461 +n09886403 +n09760609 +n10260800 +n10655594 +n09938449 +n10183931 +n09972458 +n09813219 +n10049363 +n10372373 +n10076604 +n09835348 +n09974648 +n10433164 +n09859152 +n10727171 +n10308732 +n09833536 +n10582746 +n10393909 +n10013927 +n10225219 +n10202624 +n09800964 +n10465831 +n09787534 +n10174445 +n10441962 +n10132035 +n09896685 +n09934774 +n10279018 +n10793570 +n10155849 +n10087434 +n09964202 +n09811852 +n10348526 +n10317007 +n10058777 +n10360747 +n09941964 +n10347446 +n09770359 +n09941787 +n09942970 +n09809749 +n09770179 +n10208950 +n10580772 +n10093475 +n10645017 +n09943239 +n09943541 +n10263790 +n10283170 +n10259348 +n10092978 +n10296176 +n09893191 +n10123844 +n10259780 +n10259997 +n10510245 +n10622053 +n10058585 +n10690648 +n10523341 +n10739391 +n10476467 +n10512372 +n10802507 +n10753442 +n09733793 +n09738708 +n09641757 +n09738400 +n09727826 +n09686536 +n09724533 +n09744834 +n09743792 +n09744161 +n09742101 +n09689435 +n09734450 +n09644152 +n09750282 +n09673495 +n09718811 +n09718217 +n09712696 +n09718936 +n10711766 +n09694771 +n09719794 +n09714694 +n09675922 +n09676247 +n10774440 +n09720256 +n09725229 +n09731571 +n09691729 +n09693982 +n09712448 +n09697401 +n09696585 +n09722658 +n09724656 +n09723067 +n09694664 +n09712324 +n09689958 +n09695979 +n10327987 +n09688804 +n09730204 +n09711435 +n09713108 +n09731343 +n09717233 +n09695620 +n09728285 +n09707289 +n09701833 +n09700964 +n09750891 +n09715427 +n09708750 +n09705784 +n09734185 +n09752023 +n09635534 +n09696456 +n09732170 +n09730824 +n09719309 +n09734535 +n09736945 +n09720842 +n09692915 +n09751895 +n09724785 +n09747495 +n09734639 +n09749386 +n09705124 +n09731436 +n10303814 +n10450303 +n10722575 +n10054657 +n10631309 +n10249270 +n09913455 +n10162991 +n09807754 +n09505153 +n10209082 +n10323634 +n10104064 +n10001481 +n10242328 +n10159045 +n09932098 +n10253995 +n10005934 +n10578471 +n09770949 +n10004718 +n10570019 +n10289462 +n10069645 +n10187990 +n09916348 +n10727458 +n10320863 +n10572706 +n10572889 +n10038409 +n10756148 +n09927451 +n10243664 +n10502329 +n09988493 +n10373390 +n10470779 +n09928136 +n10750031 +n10081204 +n09857200 +n10013811 +n09894143 +n10313239 +n10082997 +n10677713 +n09787765 +n10485883 +n10275395 +n09913593 +n09772930 +n09633969 +n10195593 +n09756049 +n10607478 +n09855433 +n10017272 +n10630188 +n10522035 +n10521662 +n10380672 +n10210911 +n10382710 +n10164747 +n09782397 +n10524076 +n10467395 +n10467179 +n10698368 +n09792969 +n10525617 +n10675010 +n09889941 +n10557854 +n09618760 +n09899929 +n10116702 +n10258786 +n10508710 +n09873348 +n09870208 +n10793168 +n10098517 +n10314517 +n10629939 +n10477077 +n10261624 +n10082687 +n10262445 +n10167152 +n10098624 +n10674713 +n09838621 +n10047459 +n10091564 +n10740868 +n09872066 +n10070711 +n10628644 +n10421016 +n09915434 +n10588357 +n10529965 +n10334009 +n10339717 +n09818022 +n10412055 +n10335931 +n09945745 +n10432441 +n10607291 +n10583387 +n10718131 +n10542761 +n10147121 +n10738111 +n10159533 +n10223177 +n10185793 +n10553235 +n10293332 +n10178216 +n10563403 +n10488656 +n10619642 +n10276477 +n10620758 +n10450161 +n10043643 +n10043491 +n10313724 +n10084295 +n10787470 +n10333601 +n10131151 +n09871681 +n09981939 +n10055410 +n10243137 +n10377021 +n10368528 +n10025635 +n09874862 +n10613996 +n10472129 +n10598181 +n10129825 +n09847543 +n10173410 +n10780284 +n09889065 +n09832456 +n10780632 +n10117851 +n09827363 +n10247358 +n10282482 +n10092794 +n10375314 +n09981278 +n10082043 +n09972010 +n10237069 +n09792555 +n10236946 +n10568358 +n10207169 +n10236304 +n10734394 +n10373998 +n10595164 +n10357613 +n09823502 +n10146104 +n10602985 +n10145239 +n10267865 +n09854218 +n10399491 +n10102800 +n10102369 +n10406391 +n10300500 +n10080869 +n10332385 +n09988063 +n10375402 +n10145774 +n10143172 +n10145590 +n10345015 +n10142747 +n10142391 +n10146002 +n10267311 +n10141590 +n10092643 +n09918248 +n10671613 +n10141732 +n10145340 +n10145902 +n10145480 +n09827683 +n10135129 +n10465451 +n10353016 +n13001930 +n13040629 +n12969131 +n12985420 +n13052670 +n13037406 +n13077295 +n12987056 +n12979829 +n12975804 +n12974987 +n12985773 +n13044778 +n12985857 +n13035241 +n13043926 +n12982468 +n13035707 +n13044375 +n12969425 +n13060190 +n13054073 +n13040303 +n13028611 +n12997654 +n12983048 +n13062421 +n13054560 +n12963628 +n12980840 +n12991184 +n12989938 +n12992177 +n12988158 +n13029326 +n13029760 +n13011595 +n13049953 +n12998815 +n12997919 +n13052931 +n13050397 +n13012253 +n13001041 +n13005984 +n13000891 +n13007417 +n13019835 +n13013764 +n13006894 +n13002750 +n13017102 +n13232779 +n13009429 +n13013534 +n13003522 +n13001366 +n13009085 +n13022210 +n13002925 +n13006171 +n13003712 +n13001206 +n13004423 +n13001529 +n13003254 +n13003061 +n13032115 +n13032381 +n13033577 +n13055577 +n13055949 +n13055423 +n05430628 +n05450617 +n05449959 +n05451384 +n05453657 +n09369169 +n09454412 +n09403211 +n13086908 +n09416076 +n09251407 +n05218119 +n09444100 +n09438940 +n09257949 +n09189157 +n09475044 +n11691857 +n13102775 +n13087625 +n13022709 +n11675842 +n13152742 +n13125117 +n13129165 +n11690254 +n11669335 +n13134947 +n11676500 +n11675025 +n11674332 +n11669786 +n13131028 +n13132338 +n13132656 +n12301445 +n13133613 +n13141415 +n13137409 +n12642090 +n12267677 +n12658481 +n12144313 +n12158031 +n13135832 +n12620546 +n11636835 +n13139055 +n12144580 +n07929351 +n13136556 +n12768682 +n11689483 +n13136316 +n07770571 +n07737081 +n07774842 +n07774596 +n07775050 +n07772788 +n07771212 +n07772147 +n07772274 +n07774719 +n07737745 +n07772935 +n15086247 +n11879895 +n12576323 +n12532564 +n07814634 +n07775197 +n07770763 +n11748002 +n12172364 +n12515925 +n12560282 +n12578916 +n12560621 +n12544539 +n12024690 +n13154494 +n11690455 +n12927013 +n11953610 +n13128365 +n13133932 +n13163991 +n13134059 +n13131618 +n13130726 +n11678010 +n12136392 +n11979964 +n12088223 +n12462805 +n12433081 +n09218494 +n09381242 +n09460046 +n09451237 +n09450163 +n01904182 +n13155095 +n09432283 +n11705387 +n09438844 +n11692265 +n05237755 +n09416890 +n01956764 +n01904806 +n01904886 +n05586759 +n05581932 +n01904029 +n05238282 +n05254795 +n02469248 +n05256862 +n05258051 +n01899894 +n05261404 +n05259914 +n05261310 +n05260240 +n05262185 +n05261566 +n05262534 +n05262422 +n05263183 +n05263448 +n11524662 +n11448153 +n09247410 +n11508382 +n11524451 diff --git a/data/9k.names b/data/9k.names new file mode 100644 index 0000000..e81c80e --- /dev/null +++ b/data/9k.names @@ -0,0 +1,9418 @@ +thing +matter +object +atmospheric phenomenon +body part +body of water +head +hair +structure +vein +mouth +heel +watercourse +ocean +gas +solid +substance +food +tear gas +sky +ice +food +cheese +yogurt +produce +baked goods +cake mix +Emmenthal +Camembert +Brie +mozzarella +Stilton +double cream +edible fruit +vegetable +currant +custard apple +citrus +jackfruit +pomegranate +avocado +prickly pear +apple +carambola +fig +mangosteen +tangelo +plum +papaya +apricot +berry +elderberry +loquat +pear +litchi +peach +muscat +grape +banana +pitahaya +rambutan +kiwi +melon +breadfruit +pineapple +mango +date +papaw +durian +passion fruit +jujube +guava +dried fruit +cherry +quince +nectarine +cherimoya +soursop +lime +mandarin +kumquat +orange +lemon +citron +grapefruit +pomelo +clementine +tangerine +satsuma +sweet orange +bitter orange +navel orange +Valencia orange +crab apple +eating apple +Granny Smith +Delicious +McIntosh +Red Delicious +Golden Delicious +strawberry +mulberry +currant +lingonberry +blackberry +red currant +raspberry +cranberry +acerola +persimmon +blueberry +bilberry +muskmelon +watermelon +cantaloup +sour cherry +sweet cherry +bing cherry +mushroom +asparagus +plantain +pumpkin +cucumber +root vegetable +cruciferous vegetable +raw vegetable +solanaceous vegetable +artichoke +legume +leek +squash +greens +celery +cardoon +gumbo +pieplant +onion +fennel +taro +beet +yam +carrot +potato +baked potato +mashed potato +french fries +mustard +cabbage +kohlrabi +cauliflower +brussels sprouts +broccoli rabe +broccoli +radish +turnip +collards +bok choy +savoy cabbage +head cabbage +kale +pepper +tomato +eggplant +tomatillo +sweet pepper +hot pepper +bell pepper +pimento +green pepper +chili +tabasco +cayenne +jalapeno +cherry tomato +beefsteak tomato +bean +pea +chickpea +lentil +soy +common bean +black bean +kidney bean +fresh bean +green bean +shell bean +snap bean +haricot vert +string bean +fava bean +green soybean +green pea +snow pea +sugar snap pea +summer squash +winter squash +spaghetti squash +zucchini +yellow squash +butternut squash +acorn squash +chard +turnip greens +salad green +bean sprout +spinach +lamb's-quarter +cress +chicory +chicory escarole +radicchio +lettuce +leaf lettuce +crisphead lettuce +cos +green onion +shallot +purple onion +doughnut +bread +crouton +breadstick +soft pretzel +rye bread +dark bread +raisin bread +brown bread +cinnamon bread +quick bread +matzo +sour bread +bun +white bread +challah +loaf of bread +pretzel +English muffin +toast +nan +chapatti +garlic bread +Yorkshire pudding +banana bread +scone +Irish soda bread +biscuit +muffin +drop scone +cornbread +nut bread +buttermilk biscuit +hardtack +shortcake +corn muffin +popover +bran muffin +cornpone +hush puppy +johnnycake +hamburger bun +bagel +frankfurter bun +sweet roll +hard roll +brioche +crescent roll +honey bun +cinnamon roll +cross bun +Italian bread +baguet +French bread +meat loaf +French loaf +material +stucco +gravel +rock +leopard +soil +sand +loofa +paper +litter +toilet tissue +queen +comestible +foodstuff +fare +beverage +soul food +feed +nutriment +yolk +comfort food +egg +grain +carrot juice +soya milk +whole wheat flour +oatmeal +ingredient +dairy product +cocoa +concoction +Spam +juice +canned food +corn +rice +wild rice +barley +wheat +sweet corn +popcorn +white rice +paddy +flavorer +egg yolk +saffron +juniper berries +cayenne +sesame seed +sassafras +spice +condiment +sweetening +herb +paprika +garlic +nasturtium +mocha +cardamom +nutmeg +stick cinnamon +Chinese anise +clove +cinnamon +guacamole +chili sauce +olive +chutney +vinegar +dip +soy sauce +salsa +cranberry sauce +catsup +spread +green olive +sauce +wine vinegar +cider vinegar +hummus +miso +spaghetti sauce +chocolate sauce +Tabasco +hot sauce +veloute +pesto +dressing +bourguignon +hollandaise +carbonara +tomato sauce +green mayonnaise +mayonnaise +powdered sugar +honey +syrup +sorghum +grenadine +maple syrup +basil +lemon balm +sweet woodruff +clary sage +hyssop +comfrey +coriander +mint +chives +marjoram +borage +sage +tea +rosemary +parsley +bay leaf +thyme +tea bag +oolong +souchong +cream +milk +whipping cream +clotted cream +light cream +heavy cream +stuffing +batter +dough +filling +pastry +bread dough +puff paste +phyllo +chow +menu +dietary +diet +diet +dietary supplement +vegetarianism +vitamin pill +multivitamin +alcohol +fruit juice +fizz +near beer +cocoa +coffee +cider +tea +soft drink +fruit drink +ginger beer +drinking water +potion +smoothie +mixed drink +liquor +sake +wine +hooch +home brew +liqueur +hard cider +brew +neutral spirits +aperitif +highball +cocktail +spritzer +punch +pina colada +mimosa +julep +gin and tonic +Bloody Mary +martini +gimlet +gin and it +daiquiri +sidecar +Sazerac +margarita +cup +May wine +eggnog +fruit punch +vodka +firewater +aquavit +grog +schnapps +arrack +gin +rum +aqua vitae +tequila +bitters +geneva +brandy +ouzo +whiskey +eau de vie +Cognac +grappa +Armagnac +Calvados +Irish +bourbon +sour mash +Scotch +rye +corn whiskey +blended whiskey +blush wine +vintage +champagne +vin ordinaire +dessert wine +macon +sparkling wine +Cotes de Provence +varietal +Burgundy +fortified wine +Bordeaux +table wine +California wine +vermouth +red wine +Rhone wine +white wine +Montrachet +Beaujolais +Chablis +Madeira +sherry +malmsey +port +muscat +Saint Emilion +claret +dry vermouth +sweet vermouth +Medoc +Chianti +Pinot noir +Rioja +Merlot +Cabernet +zinfandel +Riesling +Sauvignon blanc +Muscadet +Yquem +Pinot blanc +Sauterne +Chenin blanc +Chardonnay +sack +Verdicchio +Canary wine +Pernod +Drambuie +sambuca +triple sec +absinth +maraschino +anisette +beer +lager +draft beer +ale +suds +Munich beer +Pilsner +light beer +malt +bock +Weissbier +porter +stout +bitter +pale ale +Guinness +Weizenbock +orange juice +cranberry juice +nectar +iced coffee +caffe latte +espresso +cappuccino +Irish coffee +chicory +cafe au lait +mocha +Turkish coffee +ice tea +cuppa +tonic +cola +orange soda +ginger ale +pop +root beer +Coca Cola +Pepsi +mineral water +bottled water +soda water +oil cake +bird feed +fodder +eatage +hay +alfalfa +broad bean +dainty +fast food +puree +finger food +dish +course +mother's milk +vitamin +kosher +meal +jello +gelatin +sweet +candied apple +confiture +candy +chewing gum +confectionery +maraschino +conserve +strawberry jam +apple butter +lemon curd +jam +jelly +peppermint +peanut brittle +chocolate kiss +nougat bar +candy bar +jelly bean +lollipop +candy cane +truffle +chocolate fudge +cough drop +sugar candy +Easter egg +kiss +gumdrop +candy corn +fondant +cotton candy +caramel +fudge +candy egg +chocolate egg +bubble gum +gum ball +poached egg +piece de resistance +side dish +stew +omelet +soup +sashimi +taco +French toast +cheese souffle +potpie +lamb curry +stuffed tomato +chow mein +croquette +gefilte fish +coq au vin +special +spaghetti and meatballs +eggs Benedict +schnitzel +buffalo wing +chicken casserole +rissole +paella +frittata +meatball +chili +porridge +tamale +stuffed tomato +couscous +deviled egg +beef Wellington +pasta +egg roll +enchilada +falafel +mushy peas +turnover +scrambled eggs +Spanish rice +teriyaki +barbecued spareribs +pilaf +kabob +tempura +samosa +fried egg +sandwich plate +chicken cacciatore +saute +fried rice +custard +sukiyaki +fish and chips +souffle +steak au poivre +pizza +fondue +biryani +stuffed peppers +mousse +shirred egg +Swedish meatball +jambalaya +Scotch egg +burrito +risotto +salad +boiled egg +curry +snack food +bouillabaisse +goulash +pottage +beef stew +hot pot +fish stew +hotchpotch +Irish stew +ratatouille +gazpacho +won ton +petite marmite +split-pea soup +consomme +chowder +potage +marmite +lentil soup +bisque +pea soup +pepper pot +chicken broth +chicken soup +broth +broth +gumbo +borsch +corn chowder +clam chowder +fish chowder +gruel +congee +macaroni and cheese +lasagna +cannelloni +spaghetti +creme caramel +creme brulee +pepperoni pizza +anchovy pizza +cheese pizza +Sicilian pizza +sausage pizza +chocolate fondue +cheese fondue +coleslaw +macaroni salad +tossed salad +salad nicoise +pasta salad +fruit salad +tabbouleh +green salad +chef's salad +hard-boiled egg +Easter egg +sandwich +corn chip +chip +bomber +cheeseburger +chicken sandwich +ham sandwich +Reuben +bacon-lettuce-tomato sandwich +chili dog +open-face sandwich +gyro +wrap +hamburger +club sandwich +hotdog +tortilla chip +nacho +entree +plate +dessert +appetizer +mousse +tiramisu +frozen dessert +pudding +pudding +trifle +flan +whip +dumpling +compote +chocolate mousse +pavlova +parfait +ice-cream cake +ice lolly +ice-cream sundae +ice-cream cone +ice cream +ice +banana split +frozen yogurt +frozen custard +vanilla ice cream +peach ice cream +chocolate ice cream +strawberry ice cream +plum pudding +chocolate pudding +shrimp cocktail +stuffed mushroom +cocktail +hors d'oeuvre +carrot stick +antipasto +water-soluble vitamin +fat-soluble vitamin +vitamin P +vitamin C +B-complex vitamin +vitamin B2 +inositol +vitamin B6 +choline +pantothenic acid +vitamin B12 +vitamin Bc +vitamin D +vitamin A1 +picnic +bite +supper +breakfast +refection +smorgasbord +buffet +brunch +continental breakfast +dinner +lunch +banquet +cookout +fish fry +barbecue +refreshment +nosh +land +location +land +fomite +part +geological formation +cobweb +whole +hail +swamp +cultivated land +region +region +pass +line +point +opening +bedside +soil horizon +extremity +boundary +nib +selvage +shoreline +benthos +resort area +geographical area +district +scrubland +bush +oilfield +field +tract +heronry +grassland +site +court +basketball court +fairground +plot +field +amusement park +veld +pasture +campsite +garbage heap +cemetery +flowerbed +garden +topiary +peach orchard +yard +grainfield +playground +garden +city +city district +eparchy +kasbah +waterfront +business district +col +defile +hemline +spoor +crest +topographic point +workplace +half-mast +intersection +bus stop +mecca +hole-in-the-wall +patisserie +bakery +farm +piggery +ranch +dairy +knothole +chasm +oxbow +floor +pinetum +plain +steppe +cigarette butt +pipefitting +handle +panhandle +stock +haft +ax handle +broomstick +pistol grip +arete +volcanic crater +spring +ice mass +natural depression +natural elevation +oceanfront +massif +cliff +shore +talus +ridge +range +lakefront +slope +cave +foreshore +beach +hot spring +geyser +icecap +iceberg +Alpine glacier +glacier +valley +lunar crater +landfill +sinkhole +basin +crater +bed +hole +arroyo +ravine +canyon +gorge +tidal basin +cirque +ocean floor +riverbed +streambed +burrow +pothole +tableland +hill +mountain +highland +ridge +promontory +anthill +butte +foothill +knoll +alp +ben +volcano +sandbar +dune +reef +bank +coral reef +atoll +sandbank +bluff +point +mull +crag +precipice +seashore +strand +lakeside +littoral +seaside +mountainside +descent +hillside +ski slope +escarpment +bank +downhill +ascent +brae +uphill +riverbank +waterside +cove +cavern +grotto +artifact +living thing +natural object +assembly +block +millstone +paving +creation +opening +plaything +surface +tramline +structure +instrumentality +padding +covering +fabric +bookmark +float +building material +decoration +way +strip +article +facility +excavation +commodity +sheet +fixture +blacktop +line +bullion +tessera +tile +anvil +representation +art +needlework +product +pieta +map +sketch +sonogram +photograph +waxwork +arthrogram +radiogram +photomicrograph +photostat +painting +triptych +nude +finger-painting +smocking +stitch +sewing stitch +knitting stitch +lockstitch +hemstitch +garter stitch +purl +book +work +jotter +newspaper +wicker +masterpiece +openwork +woodwork +lacquerware +cabinetwork +joinery +decolletage +gargoyle +aperture +hole +mouthpiece +outfall +plughole +manhole +keyhole +perforation +thumbhole +pogo stick +ball +pinata +teddy +jungle gym +bubble +hula-hoop +pinwheel +slide +sport kite +cockhorse +doll +foam +air bubble +spume +shaving foam +golliwog +kachina +horizontal surface +board +tabletop +side +platform +tarmacadam +floor +turntable +stage +dais +sumo ring +hurricane deck +flatbed +parquet +backgammon board +pegboard +facade +ceiling +body +floor +bridge +corner +conformation +superstructure +airdock +cross +house of cards +hull +gun enclosure +lookout +building complex +shelter +honeycomb +column +altar +arch +tower +transept +mound +fountain +obelisk +fan vaulting +arcade +loggia +coil +billboard +partition +masonry +skein +colonnade +obstruction +building +sail +projection +peristyle +door +stadium +drinking fountain +area +balcony +porch +dock +high altar +housing +supporting structure +balance +defensive structure +entablature +memorial +establishment +signboard +bodywork +fuselage +ground floor +mezzanine +loft +basement +footbridge +drawbridge +cantilever bridge +rope bridge +overpass +truss bridge +viaduct +steel arch bridge +covered bridge +gangplank +suspension bridge +trestle bridge +plant +college +winery +factory +distillery +oil refinery +refinery +rolling mill +foundry +steel mill +lumbermill +stamp mill +quartz battery +battery +harbor +Nissen hut +hovel +tent +hut +igloo +dugout +mountain tent +pup tent +pavilion +backpacking tent +fly tent +canvas tent +field tent +wall tent +circus tent +Gothic arch +round arch +pointed arch +triumphal arch +broken arch +Moorish arch +Roman arch +campanile +turret +clock tower +shot tower +church tower +minaret +pylon +silo +watchtower +trestle +pylon +steeple +fire tower +high-rise +supporting tower +control tower +bell tower +beacon +burial mound +snowbank +rampart +fraise +battlement +altarpiece +wall +gable +wainscoting +attic +pediment +bell gable +brickwork +stonework +barrier +obstacle +plug +lever +grate +safety rail +movable barrier +bannister +breakwater +grille +weir +railing +hurdle +starting gate +fence +dam +gate +door +lychgate +portcullis +turnstile +French window +car door +screen door +French door +double door +interior door +sliding door +revolving door +barn door +hatchback +storm door +wall +retaining wall +rail fence +chainlink fence +dry wall +hedge +worm fence +picket fence +stone wall +water jump +bunker +earplug +cork +tap +presbytery +hotel +tenement +abattoir +apartment building +aviary +hall +house +Roman building +rest house +outbuilding +funeral home +medical building +hotel-casino +library +casino +farm building +place of worship +restaurant +ministry +rotunda +observatory +office building +temple +signal box +government building +greenhouse +rink +planetarium +public house +bowling alley +house +ruin +architecture +skyscraper +gazebo +school +chapterhouse +theater +hall of residence +conservatory +center +resort hotel +resort +motel +dude ranch +Ritz +ski lodge +hostel +motor hotel +city hall +guildhall +lyceum +field house +oast house +courthouse +shed +garage +carport +outhouse +coach house +boathouse +woodshed +apiary +maternity hospital +dispensary +stable +chicken coop +cowbarn +barn +pantheon +church +temple +shrine +stupa +masjid +synagogue +mosque +chapel +kirk +abbey +cathedral +cathedral +minster +cafe +rotisserie +automat +brasserie +cafeteria +diner +capitol +embassy +town hall +chancellery +customhouse +Statehouse +courthouse +ice rink +ice hockey rink +alehouse +free house +solar house +bungalow +row house +cabin +duplex house +mansion +lodging house +gatehouse +log cabin +saltbox +country house +dollhouse +ranch house +boarding house +detached house +villa +chalet +residence +farmhouse +terraced house +brownstone +palace +stately home +manor +summer house +dacha +villa +chateau +manse +religious residence +glebe house +parsonage +palace +monastery +abbey +abbey +day school +conservatory +music school +opera +music hall +cinema +little theater +home theater +control center +settlement house +call center +cornice +cog +knob +bill +flange +brim +tine +eaves +tooth +pinhead +football stadium +hippodrome +dome +ballpark +bullring +amphitheater +patio +corner +baggage claim +hideaway +choir +breakfast area +quad +chancel +auditorium +court +dining area +room +assembly hall +enclosure +nave +aisle +storage space +goalmouth +food court +atrium +cloister +forecourt +toilet +sun parlor +engineering +surgery +rotunda +classroom +gallery +manor hall +cell +lounge +sauna +dressing room +billiard room +belfry +kitchen +library +storeroom +workroom +sewing room +anechoic chamber +dining room +recreation room +hospital room +reading room +booth +conference room +bedroom +clean room +living room +door +hall +reception room +boardroom +study +locker room +cocktail lounge +television room +compartment +court +poolroom +bathroom +control room +anteroom +water closet +men's room +washroom +public toilet +home room +lecture room +study hall +pantry +stockroom +vault +refectory +dining-hall +canteen +family room +rumpus room +emergency room +recovery room +operating room +telephone booth +voting booth +confessional +shower stall +master bedroom +motel room +guestroom +hotel room +dormitory +nursery +day nursery +great hall +concert hall +palace +exhibition hall +parlor +drawing room +press box +command module +cabin +pilothouse +cab +luggage compartment +cabinet +cockpit +stateroom +car +cable car +stall +drawing room +terrarium +cage +playpen +pen +vivarium +pound +lock +chicken yard +chamber +recess +birdcage +rabbit hutch +hutch +cow pen +rodeo +fold +sounding board +burial chamber +firing chamber +resonator +furnace +bomb shelter +hyperbaric chamber +repository +mausoleum +kiln +blast furnace +oast +gas oven +incinerator +mihrab +columbarium +fire +fireplace +apse +cellar +cupboard +stacks +gallery +amphitheater +organ loft +stoop +sun deck +front porch +veranda +deck +back porch +portico +marina +dry dock +block +dwelling +tennis camp +living quarters +mobile home +condominium +apartment +ward +cellblock +condominium +yurt +lodge +vacation home +hearth +fixer-upper +cliff dwelling +homestead +semi-detached house +wigwam +tepee +accommodation +first class +cabin class +bedsitting room +flatlet +chassis +support +framework +pedestal +buttress +flying buttress +abutment +ribbing +bustle +window frame +frame +gantry +honeycomb +truss +lattice +cornice +picture frame +window +climbing frame +trellis +airframe +grate +grape arbor +walker +casing +tambour +arbor +rack +mounting +sash +casement +oriel +bay window +stained-glass window +skylight +display window +rose window +porthole +transom +clerestory +dormer +dormer window +lancet window +fanlight +plate rack +barbecue +bicycle rack +luggage rack +dish rack +towel rack +passe-partout +pave +mount +stronghold +fortress +fortification +bastion +keep +kremlin +acropolis +alcazar +martello tower +fieldwork +bastion +escarpment +palisade +castle +cenotaph +megalith +Seven Wonders of the Ancient World +brass +national monument +pantheon +dolmen +menhir +place of business +institution +university +mercantile establishment +office +cabaret +health spa +plaza +country store +department store +shop +marketplace +boutique +salon +shoe shop +bookshop +package store +thriftshop +junk shop +toyshop +cleaners +bazaar +gift shop +florist +drugstore +garage +delicatessen +small stores +barbershop +stall +tobacco shop +newsstand +butcher shop +pizzeria +confectionery +convenience store +bazaar +agora +grocery store +open-air market +supermarket +hypermarket +greengrocery +souk +farmer's market +flea market +newsroom +box office +headquarters +correctional institution +orphanage +jail +penitentiary +prison +toiletry +weaponry +equipment +connection +implement +furnishing +device +ceramic +system +container +conveyance +medium +deodorant +bath oil +cream +lotion +shaving cream +hair spray +mousse +perfume +hairdressing +antiperspirant +powder +cosmetic +bath salts +hand cream +cold cream +sunscreen +lanolin +body lotion +toner +hand lotion +after-shave +potpourri +patchouli +perfumery +cologne +toilet water +pomade +brilliantine +toilet powder +talcum +depilatory +highlighter +makeup +face powder +lip-gloss +eyeshadow +mascara +lipstick +rouge +eyeliner +eyebrow pencil +armament +defense system +bomb +ammunition +naval weaponry +bazooka +artillery +launcher +cannon +field artillery +mortar +basilisk +hydrogen bomb +atom bomb +round +shotgun shell +recorder +sports equipment +photographic equipment +naval equipment +parasail +gear +satellite +game equipment +parachute +electronic equipment +apparatus +automation +material +baggage +tape recorder +cassette recorder +Dictaphone +videocassette recorder +baseball equipment +croquet mallet +clay pigeon +skate +wrestling mat +cricket equipment +basketball equipment +javelin +shuttlecock +golf equipment +spike +stick +boxing equipment +boxing glove +gymnastic apparatus +weight +baseball glove +batting cage +batting glove +base +batting helmet +baseball bat +home plate +first base +third base +second base +in-line skate +Rollerblade +roller skate +ice skate +hockey skate +speed skate +figure skate +cricket bat +wicket +golfcart +golf glove +tee +golf club +wood +iron +driver +spoon +wedge +midiron +putter +niblick +pitching wedge +sand wedge +hockey stick +polo mallet +horizontal bar +horse +uneven parallel bars +parallel bars +trampoline +balance beam +vaulting horse +pommel horse +dumbbell +barbell +enlarger +camera +clapperboard +film +light meter +box camera +flash camera +Polaroid camera +point-and-shoot camera +webcam +motion-picture camera +digital camera +portrait camera +reflex camera +X-ray film +reel +negative +regalia +kit +rig +fishing gear +stable gear +rigging +crown +crown jewels +sewing kit +first-aid kit +carpenter's kit +layette +drill rig +drilling platform +harness +snaffle +headgear +saddle blanket +halter +bridle +sputnik +space station +backboard +ball +puzzle +pool table +bowling pin +man +chip +roulette wheel +goal +volleyball net +pinball machine +soccer ball +pool ball +bowling ball +softball +field hockey ball +punching bag +billiard ball +croquet ball +cricket ball +tennis ball +golf ball +rugby ball +cue ball +medicine ball +basketball +eight ball +ping-pong ball +handball +baseball +racquetball +bocce ball +volleyball +jigsaw puzzle +crossword puzzle +chessman +white +pawn +basket +net +electronic fetal monitor +monitor +monitor +television monitor +telephone +oscilloscope +peripheral +booster +cassette player +CD player +receiver +audio system +lens +playback +television equipment +circuitry +cassette deck +central processing unit +mixer +scanner +tape player +detector +modem +equalizer +tape deck +amplifier +cellular telephone +speakerphone +desk phone +pay-phone +handset +dial telephone +radiotelephone +television receiver +radio receiver +satellite receiver +heterodyne receiver +clock radio +reproducer +hi-fi +stereo +iPod +Walkman +video iPod +ghetto blaster +camcorder +television camera +pendulum +purifier +sequencer +reformer +duplicator +heat pump +semaphore +tomograph +ultracentrifuge +generator +incubator +burner +Foucault pendulum +clock pendulum +metronome +Photostat +photocopier +Xerox +facsimile +mimeograph +positron emission tomography scanner +computerized axial tomography scanner +gas burner +blowtorch +bunsen burner +gas ring +packaging +blister pack +roofing +temporary hookup +slip ring +telephone line +ligament +junction +hot line +digital subscriber line +land line +binder +wire +chain +concertina +barbed wire +paper chain +anchor chain +fob +bicycle chain +tire chain +chatelaine +joint +contact +dovetail +welt +hinge +scarf joint +weld +seam +mortise joint +butt hinge +strap hinge +distributor point +tread +wiper +bar +tool +utensil +rubber eraser +needle +eraser +stick +brush +hook +sharpener +sports implement +leather strip +swatter +fire iron +oar +stick +cleaning implement +rod +writing implement +shovel +split rail +fret +bolt +rotor +towel rail +lever +track +handlebar +crowbar +stick +key +tappet +pedal +rocker arm +gun trigger +space bar +backspace key +shift key +telegraph key +accelerator +sustaining pedal +hand tool +jack +pestle +garden tool +plow +comb +drill +cutting implement +tamp +garden rake +rake +stamp +locking pliers +pestle +plunger +pincer +pliers +soldering iron +spade +hammer +pipe cutter +wrench +screwdriver +trowel +saw +opener +scraper +shovel +brick trowel +spatula +carpenter's hammer +gavel +mallet +maul +torque wrench +pipe wrench +adjustable wrench +open-end wrench +Allen wrench +box wrench +hacksaw +folding saw +handsaw +pruner +pruning saw +corkscrew +bottle opener +can opener +hedge trimmer +lawn mower +power mower +riding mower +power drill +electric drill +cutter +twist bit +bit +blade +knife blade +bolt cutter +cigar cutter +edge tool +scissors +knife +ax +razor +wire cutter +chisel +plane +shears +snips +pruning shears +secateurs +carving knife +Bowie knife +pocketknife +cleaver +hunting knife +case knife +parer +letter opener +switchblade +penknife +battle-ax +hatchet +shaver +straight razor +safety razor +cold chisel +wood chisel +jointer +smooth plane +spokeshave +kitchen utensil +ceramic ware +funnel +rolling pin +reamer +masher +kitchenware +squeezer +mixer +cookie cutter +cooking utensil +grater +mincer +eggbeater +whisk +blender +pan +Crock Pot +chafing dish +spatula +griddle +enamelware +steamer +cookie sheet +cooker +turner +omelet pan +stewing pan +frying pan +roaster +wok +saucepan +graniteware +cloisonne +porcelain +earthenware +stoneware +pottery +Spode +china +bone china +majolica +faience +knitting needle +crochet needle +walking stick +matchstick +club +fiddlestick +spindle +stob +staff +drumstick +mallet +cane +sword cane +bat +table-tennis racquet +truncheon +alpenstock +flagpole +crutch +electric toothbrush +toothbrush +sable +scrub brush +hairbrush +bristle brush +shaving brush +pencil sharpener +steel +cue +racket +squash racket +tennis racket +badminton racket +thong +strap +cheekpiece +rein +noseband +leading rein +scull +paddle +besom +scouring pad +dustmop +squeegee +broom +swab +rotating shaft +wand +shaft +piston rod +kickstand +axle +pole +fishing rod +connecting rod +tie rod +driveshaft +crankshaft +transmission shaft +spindle +camshaft +boom +stilt +ski pole +clothes tree +caber +spar +mast +mast +bowsprit +yard +mizzenmast +royal mast +mainmast +foremast +fly rod +spinning rod +pencil +pen +highlighter +chalk +crayon +lead pencil +ballpoint +Sharpie +quill +fountain pen +felt-tip pen +furniture +office furniture +dining-room furniture +wardrobe +bedroom furniture +table +table +wall unit +lamp +dining-room table +washstand +buffet +cabinet +baby bed +bedstead +lawn furniture +credenza +bookcase +entertainment center +etagere +seat +sectional +chest of drawers +file +Rolodex +card index +vertical file +clothes closet +armoire +bed +berth +platform bed +hospital bed +bunk +trundle bed +four-poster +couch +bunk bed +twin bed +sleigh bed +single bed +hammock +Murphy bed +double bed +gaming table +gueridon +table-tennis table +counter +altar +breakfast table +stand +conference table +pedestal table +kitchen table +operating table +tea table +lectern +worktable +gateleg table +dressing table +desk +drop-leaf table +coffee table +trestle table +console table +checkout +bar +meat counter +reception desk +salad bar +snack bar +drafting table +lab bench +writing desk +secretary +davenport +dining table +dinner table +refectory table +floor lamp +table lamp +reading lamp +dresser +china cabinet +medicine chest +bassinet +crib +carrycot +cradle +chair +toilet seat +stool +sofa +ottoman +bench +lawn chair +chaise longue +rocking chair +swivel chair +throne +straight chair +ladder-back +highchair +armchair +Windsor chair +folding chair +wheelchair +motorized wheelchair +barber chair +easy chair +recliner +Morris chair +wing chair +deck chair +camp chair +music stool +taboret +footstool +settee +daybed +convertible +love seat +chesterfield +studio couch +park bench +flat bench +pew +settle +window seat +chiffonier +highboy +bird feeder +heater +lighter +signal +converter +crusher +drive +knocker +peeler +musical instrument +shoehorn +shock absorber +machine +conductor +bait +stabilizer +filter +mechanism +acoustic device +trap +charger +airfoil +router +pick +energizer +fan +hydrofoil +dental appliance +adapter +toy +support +optical device +straightener +tongs +phonograph needle +instrument +comb +remote control +exercise device +comforter +washboard +shredder +water ski +blower +ventilator +breathing device +applicator +skeleton key +guitar pick +restraint +keyboard +electrical device +appliance +fire extinguisher +corrective +reflector +alarm +electronic device +snowshoe +holding device +memory device +key +noisemaker +source of illumination +indicator +detector +breathalyzer +imprint +afterburner +horn +elastic device +ski +lifting device +solar heater +electric heater +radiator +gas heater +convector +space heater +stove +cigar lighter +match +cairn +sign +street sign +traffic light +electrical converter +catalytic converter +inverter +synchronous converter +external drive +CD-ROM drive +internal drive +stringed instrument +electronic instrument +keyboard instrument +wind instrument +bass +percussion instrument +dulcimer +chordophone +banjo +zither +samisen +guitar +bowed stringed instrument +sitar +lute +mandola +mandolin +harp +acoustic guitar +Hawaiian guitar +uke +electric guitar +viol +violin +cello +viola +viola da gamba +Stradavarius +theremin +electric organ +synthesizer +piano +clavier +organ +accordion +grand piano +upright +spinet +mechanical piano +baby grand +concert grand +harpsichord +spinet +ocarina +woodwind +brass +organ pipe +free-reed instrument +whistle +pipe +kazoo +flute +beating-reed instrument +double-reed instrument +single-reed instrument +bassoon +oboe +clarinet +sax +baritone +bugle +flugelhorn +French horn +trombone +cornet +harmonium +harmonica +concertina +chanter +panpipe +bagpipe +fipple flute +pennywhistle +drone +bass fiddle +bass horn +bass guitar +euphonium +handbell +bones +gong +vibraphone +steel drum +marimba +glockenspiel +chime +kettle +maraca +drum +cymbal +bongo +bass drum +tambourine +snare drum +tenor drum +slot machine +power shovel +press +backhoe +printer +machine tool +motor +snow thrower +cash machine +farm machine +computer +Zamboni +mill +staple gun +power tool +concrete mixer +stapler +slicer +textile machine +record player +calculator +vending machine +slot +automat +garlic press +bench press +hydraulic press +punch press +character printer +impact printer +printer +drum printer +line printer +laser printer +Linotype +thermal printer +portable +typewriter +bar printer +wire matrix printer +dot matrix printer +bubble jet printer +ink-jet printer +shaper +drill press +grinder +lathe +miller +engine +electric motor +heat engine +jet engine +automobile engine +aircraft engine +generator +steam engine +internal-combustion engine +wind turbine +gasoline engine +diesel +outboard motor +radial engine +rocket +fanjet +booster +space rocket +alternator +windmill +starter +kick starter +cultivator +haymaker +combine +thresher +harvester +disk harrow +harrow +slide rule +web site +home computer +server +digital computer +supercomputer +workstation +personal computer +portable computer +desktop computer +notebook +planner +laptop +hand-held computer +pepper mill +water mill +meat grinder +coffee mill +treadmill +windmill +electric hammer +power saw +buffer +circular saw +chain saw +table saw +saber saw +bandsaw +spinning wheel +loom +jukebox +gramophone +abacus +adding machine +hand calculator +semiconductor device +wire +cord +heat sink +cable +microprocessor +transistor +light-emitting diode +chip +filament +jumper cable +telephone wire +patchcord +telephone cord +power cord +extension cord +ethernet cable +electrical cable +printer cable +power line +fisherman's lure +fly +dry fly +wet fly +streamer fly +outrigger +vane +strainer +air filter +oil filter +sieve +tea-strainer +colander +fusee drive +android +radiator +mechanical device +rotating mechanism +rotor head +carriage +control +power steering +automaton +action +cooling system +gear +tape drive +film advance +sprinkler +propeller +anchor +golf-club head +weathervane +machine +seeder +pump +gearshift +ride +bumper +hook +ski binding +coupling +record changer +swing +windshield wiper +winder +winder +diaphragm +shutter +escapement +broadcaster +curler +splint +compressor +air compressor +carburetor +dildo +cartridge holder +trapeze +gearing +stator +airplane propeller +screw +pulley +wheel +idle pulley +lever +inclined plane +millwheel +waterwheel +roller +bicycle wheel +caster +grinding wheel +rowel +fifth wheel +wagon wheel +waterwheel +car wheel +sprocket +pinwheel +potter's wheel +gear +driving wheel +paddlewheel +roulette +spur gear +bevel gear +pinion +ramp +ax head +screw +grease-gun +gas pump +bicycle pump +sump pump +hand pump +centrifugal pump +Ferris wheel +roller coaster +carousel +universal joint +clutch +freewheel +disk clutch +bobbin +reel +shuttle +blade +gyroscope +circle +rotor +paddle +impeller +fan blade +disk +puck +brake disk +token +Frisbee +planchet +tail rotor +main rotor +valve +steering wheel +governor +joystick +regulator +switch +ball valve +butterfly valve +timer +flywheel +faucet +thermostat +aperture +mixing faucet +stopcock +toggle switch +push button +dial +horn button +mouse button +doorbell +bell push +flintlock +movement +gunlock +cooling tower +evaporative cooler +air conditioner +gearset +four-wheel drive +whistle +silencer +megaphone +hearing aid +bell +cowbell +church bell +dinner bell +spider web +mousetrap +lobster pot +web +net +landing net +fishnet +vertical stabilizer +spoiler +spoiler +rotor blade +flap +rudder +horizontal stabilizer +wing +exhaust fan +electric fan +brace +denture +backboard +stirrup +pier +pier +back +shelf +landing gear +baluster +spoke +base +step +brace +pillow block +bearing +rocker +coat hanger +harp +rest +bracket +tailstock +bookend +structural member +headstock +seat +thrust bearing +hanger +rack +harness +cantle +ladder-back +bookshelf +mantel +neck brace +knee brace +ankle brace +back brace +arm +headrest +chin rest +armrest +sconce +corbel +shelf bracket +sill +riser +upright +brace +tread +beam +windowsill +doorsill +stile +jamb +column +post +support column +caryatid +goalpost +newel post +bollard +lamppost +telephone pole +maypole +timber +rundle +tie +rafter +girder +timber +floor joist +joist +car seat +pillion +plane seat +saddle +chair +bicycle seat +bucket seat +backseat +stock saddle +English saddle +tripod +spice rack +magazine rack +music stand +camera tripod +easel +autofocus +projector +finder +laser +lens +objective +condenser +camera lens +anastigmat +contact +sunglass +eyepiece +field lens +Fresnel lens +portrait lens +closeup lens +telephoto lens +wide-angle lens +plotter +scientific instrument +measuring instrument +weapon +guillotine +drafting instrument +analyzer +navigational instrument +optical instrument +medical instrument +instrument of punishment +catapult +extractor +theodolite +riding crop +tachymeter +collider +microtome +accelerator +stroboscope +magnifier +console +telescope +microscope +astronomical telescope +equatorial +optical telescope +radio telescope +refracting telescope +field glass +reflecting telescope +Cassegrainian telescope +Newtonian telescope +Schmidt telescope +Maksutov telescope +electron microscope +field-emission microscope +light microscope +binocular microscope +hand glass +operating microscope +compound microscope +loupe +oximeter +dropper +refractometer +rangefinder +barometer +pedometer +thermometer +astrolabe +measuring stick +gauge +timepiece +aneroid barometer +caliper +potentiometer +tachometer +scale +tape +meter +hygrometer +sextant +rule +altazimuth +pyrometer +meat thermometer +water gauge +vacuum gauge +anemometer +gasoline gauge +pressure gauge +manometer +sphygmomanometer +atomic clock +clock +watch +sundial +timer +hourglass +grandfather clock +digital clock +alarm clock +wall clock +analog clock +pendulum clock +cuckoo clock +digital watch +analog watch +pocket watch +wristwatch +stopwatch +parking meter +chronograph +vernier caliper +micrometer +balance +analytical balance +electronic balance +electric meter +odometer +ammeter +speedometer +ohmmeter +water meter +voltmeter +magnetometer +tomahawk +gun +bow +bow and arrow +brass knucks +knife +sword +stun gun +projectile +antiaircraft +firearm +set gun +air gun +gas gun +paintball gun +cannon +autoloader +pistol +twenty-two +Mauser +muzzle loader +rifle +repeating firearm +semiautomatic firearm +automatic firearm +Garand rifle +Luger +semiautomatic pistol +automatic rifle +assault rifle +automatic pistol +machine gun +submachine gun +burp gun +Uzi +Kalashnikov +Tommy gun +Colt +derringer +revolver +gat +flintlock +musket +sniper rifle +Winchester +carbine +crossbow +longbow +khukuri +bayonet +machete +dagger +rapier +fencing sword +broadsword +cavalry sword +saber +epee +foil +bullet +cannonball +compass +protractor +artificial horizon +depth finder +magnetic compass +compass +binoculars +spectacles +projector +telescopic sight +goggles +sunglasses +slide projector +front projector +movie projector +overhead projector +hypodermic syringe +cardiograph +syringe +stethoscope +laryngoscope +otoscope +surgical instrument +retractor +hemostat +pillory +rattan +exercise bike +treadmill +respirator +snorkel +oxygen mask +aqualung +paintbrush +spray gun +brake +handcuff +fastener +seat belt +leash +safety belt +brake system +muzzle +chain +bolt +buckle +knot +cleat +clothespin +catch +pin +dowel +screw +slide fastener +button +seal +paper fastener +lock +thumbtack +locker +clasp +clip +carabiner +nail +toggle +nut and bolt +bowline +bow +latch +hasp +rivet +hairpin +skewer +hatpin +brochette +bobby pin +barrette +safety pin +shirt button +coat button +washer +gasket +head gasket +O ring +padlock +sash fastener +latch +combination lock +doorlock +paper clip +bulldog clip +hair slide +hydraulic brake +disk brake +drum brake +typewriter keyboard +QWERTY keyboard +computer keyboard +piano keyboard +circuit +Segway +jack +control panel +telephone jack +circuit breaker +plug +electrolytic +dashboard +transducer +solar cell +antenna +capacitor +spark plug +relay +surge suppressor +solar array +battery +Tesla coil +closed circuit +wiring +computer circuit +integrated circuit +module +printed circuit +interface +CPU board +circuit board +mosaic +electro-acoustic transducer +earphone +microphone +loudspeaker +telephone receiver +headset +condenser microphone +cardioid microphone +tweeter +bullhorn +tannoy +woofer +subwoofer +omnidirectional antenna +directional antenna +radio antenna +television antenna +dish +scanner +yagi +voltaic battery +flashlight battery +lead-acid battery +pack +prosthesis +solar dish +mirror +hand glass +car mirror +rearview mirror +outside mirror +burglar alarm +automobile horn +shofar +fire alarm +readout +scanner +tube +display +personal digital assistant +dongle +trackball +mouse +answering machine +hearing aid +beeper +triode +pentode +computer monitor +monitor +screen +digital display +liquid crystal display +flat panel display +window +dialog box +caller ID +computer screen +background +C-clamp +chuck +collet +holder +vise +candlestick +cigarette holder +candelabrum +menorah +Menorah +cache +optical disk +magnetic disk +memory +magnetic tape +recording +auxiliary storage +compact disk +videodisk +CD-ROM +CD-R +audio CD +hard disc +diskette +flash memory +random-access memory +videotape +cassette tape +tape +phonograph record +LP +seventy-eight +lamp +light +flash +lantern +candle +neon lamp +vigil light +taillight +gas lamp +oil lamp +hurricane lamp +fluorescent lamp +streetlight +spotlight +electric lamp +jack-o'-lantern +Chinese lantern +flashlight +light bulb +penlight +headlight +room light +strip lighting +fairy light +sconce +searchlight +night-light +blinker +torch +flood +fuel gauge +gnomon +dial +vernier scale +pointer +light pen +hand +sweep hand +minute hand +second hand +hour hand +spring +rubber band +coil spring +box spring +hoist +winch +elevator +crane +wheel and axle +derrick +maze +communication system +network +Global Positioning System +resonator +exhaust +mechanical system +computer system +scaffolding +reticle +walkie-talkie +radio +telecommunication system +telephone system +intercommunication system +interphone +television +satellite television +surveillance system +color television +local area network +superhighway +ethernet +wireless local area network +production line +linkage +suspension +fuel injection +planter +trophy case +wastepaper basket +dish +bread-bin +dispenser +pot +bunker +reliquary +cup +bag +cassette +Dumpster +bag +measuring cup +glass +paintball +measure +envelope +shaker +piggy bank +basket +sewing basket +savings bank +powder horn +can +wheeled vehicle +workbasket +bin +canister +mold +cargo container +videocassette +case +case +vessel +drawer +receptacle +package +watering can +box +cocotte +Petri dish +gravy boat +serving dish +tureen +sugar bowl +bowl +casserole +ramekin +butter dish +salad bowl +mixing bowl +porringer +cereal bowl +soup bowl +punch bowl +roll-on +aerosol +soap dispenser +atomizer +inhaler +demitasse +beaker +kylix +coffee cup +chalice +teacup +Dixie cup +evening bag +shoulder bag +clutch bag +reticule +backpack +sachet +beanbag +sandbag +carryall +pannier +duffel bag +book bag +tool bag +mailbag +purse +drawstring bag +envelope +saddlebag +sack +pouch +shopping bag +toilet bag +gamebag +kitbag +plastic bag +golf bag +sleeping bag +gunnysack +grocery bag +sporran +pocket +waist pack +fanny pack +hip pocket +patch pocket +flute +tumbler +water glass +bumper +liqueur glass +snifter +shot glass +beer glass +rummer +goblet +wineglass +cocktail shaker +saltshaker +pepper shaker +pannier +clothes hamper +hamper +breadbasket +shopping basket +wicker basket +milk can +beer can +soda can +pedicab +camper trailer +rolling stock +motor scooter +self-propelled vehicle +unicycle +wagon +bassinet +handcart +baby buggy +bicycle +horse-drawn vehicle +trailer +car +tricycle +armored vehicle +recreational vehicle +tracked vehicle +snowmobile +bulldozer +locomotive +streetcar +motor vehicle +tractor +forklift +armored personnel carrier +armored car +dune buggy +camper +van +shunter +diesel locomotive +electric locomotive +tank engine +traction engine +steam locomotive +diesel-electric locomotive +diesel-hydraulic locomotive +hearse +truck +amphibian +four-wheel drive +motorcycle +go-kart +car +snowplow +fire engine +van +trailer truck +transporter +garbage truck +ladder truck +tow truck +dump truck +tractor +pickup +delivery truck +moving van +passenger van +police van +bookmobile +trail bike +moped +beach wagon +loaner +Model T +electric +minivan +convertible +compact +cab +shooting brake +racer +hatchback +roadster +berlin +sport utility +sedan +jeep +limousine +cruiser +ambulance +used-car +stock car +subcompact +pace car +hot rod +sports car +coupe +covered wagon +cart +horse cart +dumpcart +jinrikisha +pony cart +oxcart +tea cart +laundry cart +serving cart +barrow +shopping cart +hand truck +bicycle-built-for-two +safety bicycle +push-bike +mountain bike +carriage +gharry +buggy +stagecoach +four-wheeler +baggage car +freight car +passenger car +cabin car +boxcar +tank car +nonsmoker +Pullman +dining car +smoker +recycling bin +ashcan +litterbin +sandbox +pig bed +briefcase +compact +dispatch case +kit +wallet +cardcase +portfolio +ditty bag +cigarette case +shoe +gun case +attache case +locket +writing desk +watch case +baggage +glasses case +hand luggage +satchel +bag +trunk +hatbox +garment bag +weekender +carpetbag +portmanteau +overnighter +valise +boiler +flagon +bowl +ladle +bottle +bottle +pot +pitcher +bathtub +mortar +bucket +drinking vessel +cream pitcher +wine bucket +pressure cooker +tub +inkwell +tin +basin +monstrance +autoclave +churn +barrel +tank +jar +censer +toilet bowl +fishbowl +scoop +soup ladle +smelling bottle +pop bottle +water bottle +jug +catsup bottle +gourd +pill bottle +carboy +flask +beer bottle +ink bottle +demijohn +whiskey bottle +cruet +wine bottle +carafe +phial +whiskey jug +water jug +hipflask +Erlenmeyer flask +thermos +canteen +vacuum flask +magnum +jeroboam +saucepot +teapot +Dutch oven +urn +stockpot +kettle +caldron +percolator +teakettle +coffeepot +coffee urn +samovar +tea urn +sitz bath +hot tub +footbath +mug +loving cup +tankard +coffee mug +toby +beer mug +bidet +birdbath +washbasin +baptismal font +beer barrel +wine cask +keg +gas tank +water heater +septic tank +aquarium +reservoir +water tower +rain barrel +canopic jar +amphora +cookie jar +beaker +urn +Mason jar +vase +crock +jampot +plate +tray +cat box +dustpan +chamberpot +salver +garbage +in-basket +hot-water bottle +ossuary +socket +ashtray +packet +bundle +deck +bale +hay bale +pack +ballot box +carton +coffin +shoebox +snuffbox +pencil box +crate +bandbox +window box +chest +strongbox +cereal box +mailbox +casket +bier +packing box +toolbox +toy box +coffer +hope chest +treasure chest +cedar chest +cash register +safe-deposit +cashbox +safe +tramway +chairlift +sidecar +public transport +semitrailer +horsebox +vehicle +ski tow +roll-on roll-off +trailer +shipping +litter +express +shuttle bus +train +bus +local +freight liner +passenger train +subway train +mail train +freight train +commuter +bullet train +trolleybus +minibus +school bus +steamroller +bumper car +rocket +military vehicle +missile +craft +sled +half track +tank +panzer +personnel carrier +Humvee +aircraft +vessel +spacecraft +hovercraft +heavier-than-air craft +stealth aircraft +lighter-than-air craft +hang glider +glider +helicopter +warplane +airplane +autogiro +bomber +amphibian +propeller plane +airliner +biplane +floatplane +jet +fighter +stealth bomber +seaplane +airbus +widebody aircraft +jumbojet +jetliner +stealth fighter +interceptor +airship +blimp +balloon +hot-air balloon +boat +trawler +yacht +ship +sailing vessel +bareboat +lifeboat +police boat +gondola +sea boat +barge +river boat +tugboat +punt +pilot boat +small boat +ferry +tender +canal boat +fireboat +motorboat +dredger +pontoon +houseboat +skiff +canoe +dinghy +racing boat +coracle +yawl +gig +jolly boat +rowing boat +kayak +outrigger canoe +dugout canoe +racing gig +racing skiff +speedboat +outboard motorboat +cabin cruiser +hydrofoil +shipwreck +wreck +passenger ship +pirate +lightship +hospital ship +steamer +cargo ship +sister ship +warship +liner +luxury liner +cargo liner +cruise ship +paddle steamer +sternwheeler +bottom +container ship +banana boat +oil tanker +submarine +guided missile cruiser +frigate +battleship +guided missile frigate +aircraft carrier +man-of-war +destroyer +attack submarine +nautilus +yawl +clipper +felucca +sloop +ketch +dhow +sailboat +bark +schooner +windjammer +trimaran +catamaran +catboat +space shuttle +space capsule +dogsled +bobsled +bobsled +stretcher +covered couch +telecommunication +vehicle +print media +broadcasting +telephone +radiotelephone +television +reception +radio +cable television +high-definition television +three-way calling +call +voice mail +press +journalism +magazine +newspaper +pulp +slick +comic book +news magazine +tabloid +daily +gazette +Fleet Street +yellow journalism +pillow +pad +sanitary napkin +beer mat +futon +carpet pad +range hood +screen +top +footwear +protective covering +cloak +wrapping +upholstery +cloth covering +mask +finger +floor cover +coating +canopy +flap +domino +folder +planking +earmuff +camouflage +shoji +cap +manhole cover +lid +radiator cap +bottlecap +nipple +clog +shoe +arctic +boot +flats +slipper +overshoe +sabot +slingback +chukka +saddle oxford +spectator pump +brogan +wing tip +walker +blucher +anklet +cleats +gaiter +Loafer +running shoe +oxford +bowling shoe +plimsoll +pump +sandal +chopine +pusher +talaria +flip-flop +espadrille +jodhpur +buskin +ski boot +hip boot +riding boot +rubber boot +Hessian boot +waders +cowboy boot +mule +bootee +cold frame +cloche +washboard +toecap +mulch +shield +bracer +screen +sheathing +bell jar +shade +shelter +splashboard +testudo +roof +faceplate +hood +sheath +cap +mask +facing +crystal +calash +armor +binder +binding +housing +blind +lining +plate +horseshoe +armor plate +breastplate +helmet +cannon +knee piece +pickelhaube +sallet +window screen +fire screen +windshield +mosquito net +lampshade +parasol +lean-to +bell cote +sentry box +birdhouse +canopy +kennel +awning +umbrella +gamp +gable roof +sunroof +mansard +dome +hip roof +tile roof +housetop +vault +slate roof +gambrel +thatch +cupola +geodesic dome +onion dome +barrel vault +ribbed vault +holster +scabbard +shoulder holster +hubcap +thimble +distributor cap +lens cap +gasmask +face mask +ski mask +catcher's mask +body armor +shield +chain mail +bulletproof vest +corselet +cuirass +cabinet +radome +boot +window blind +jalousie +curtain +shutter +Venetian blind +window shade +roller blind +theater curtain +shower curtain +bushing +brake lining +gift wrapping +envelope +cellophane +book jacket +jacket +plastic wrap +shoulder +pant leg +leg +back +cosy +bandage +bosom +slipcover +bedclothes +sleeve +blindfold +eyepatch +skirt +seat +Band Aid +swathe +cast +elastic bandage +quilt +afghan +blanket +bedspread +mattress cover +patchwork +eiderdown +crazy quilt +coverlet +quilted bedspread +raglan sleeve +long sleeve +rug +doormat +mat +scatter rug +shag rug +prayer rug +broadloom +stair-carpet +red carpet +Brussels carpet +fixative +gold plate +verdigris +paint +nail polish +gilt +couch +enamel +veneer +finger paint +enamel +encaustic +oil paint +water-base paint +latex paint +whitewash +earflap +pocket flap +lapel +tongue +revers +tent-fly +file folder +matchbook +plush +muslin +tarpaulin +velvet +batik +khaki +belting +sacking +diaper +voile +duffel +chenille +cotton flannel +toweling +crinoline +panting +chintz +felt +cotton +velveteen +satin +knit +sateen +print +flannel +webbing +gabardine +camouflage +worsted +cashmere +tartan +mohair +brocade +velour +shirttail +boucle +madras +net +paisley +yoke +percale +piece of cloth +moquette +terry +rayon +acetate rayon +cord +permanent press +chiffon +burlap +ticking +basket weave +lace +sheeting +georgette +poplin +denim +flannelette +shantung +camel's hair +nylon +drapery +gauze +organza +foulard +gingham +wool +suede cloth +taffeta +leatherette +tweed +organdy +canopy +etamine +damask +oilcloth +tapestry +broadcloth +pique +homespun +tricot +double knit +jersey +gauze +tulle +chicken wire +handkerchief +groundsheet +dustcloth +dishrag +towel +bandanna +gusset +bib +sail +patch +hand towel +paper towel +dishtowel +fore-and-aft sail +foresail +spinnaker +headsail +topsail +mainsail +balloon sail +jib +mizzen +gaff topsail +lugsail +staysail +lateen +flash +shoulder patch +narrow wale +Bedford cord +macrame +pillow lace +raft +life preserver +life buoy +Mae West +life jacket +stone +brick +lumber +bricks and mortar +tile +concrete +quoin +millstone +stele +hone +grindstone +curbstone +gravestone +firebrick +mud brick +clinker +adobe +strip +chipboard +slat +fingerboard +toothpick +hip tile +pantile +cornice +embellishment +graffito +epergne +necklet +marquetry +brass +garnish +arabesque +design +adornment +frieze +lambrequin +tattoo +mihrab +emblem +swastika +herringbone +spot +flag +banner +totem pole +crucifix +fleur-de-lis +macule +parhelion +jewelry +frill +lavaliere +peplum +bangle +cigar band +aigrette +bracelet +bling +pendant earring +necklace +ghat +path +road +passage +sidewalk +towpath +pedestrian crossing +highway +carriageway +thoroughfare +trail +divided highway +expressway +arterial road +autostrada +autobahn +street +street +piste +horse-trail +adit +conduit +passageway +tube +sluice +snorkel +waterspout +catheter +barrel +pipe +hookah +tailpipe +drain +culvert +soil pipe +tunnel +stairwell +gangway +catacomb +railroad tunnel +tape +band +inkle +adhesive tape +plaster +cellulose tape +headstall +girdle +tire +armlet +radial +car tire +tableware +riband +cutlery +glass +hollowware +platter +spoon +table knife +fork +Spork +soupspoon +teaspoon +sugar spoon +wooden spoon +iced-tea spoon +tablespoon +dessert spoon +case knife +butter knife +steak knife +tablefork +carving fork +airfield +telpherage +air terminal +airport +menagerie +storehouse +station +warehouse +granary +crib +mineshaft +ditch +irrigation ditch +furrow +consumer goods +linen +clothing +appliance +leisure wear +grey +blue +nightwear +protective garment +outerwear +neckpiece +knitwear +loungewear +apparel +collar +military uniform +headdress +pajama +garment +array +woman's clothing +overall +glove +accessory +black +footwear +attire +ready-to-wear +beachwear +man's clothing +street clothes +slip-on +shin guard +overall +pressure suit +arm guard +foul-weather gear +diving suit +apron +shoulder pad +coverall +chest protector +elbow pad +spacesuit +knee pad +gown +vestment +chasuble +academic gown +battle dress +fatigues +dress uniform +khakis +helmet +hood +turban +hat +cap +cowl +tiara +football helmet +hard hat +crash helmet +sunhat +fur hat +cowboy hat +bearskin +boater +snap-brim hat +fedora +cavalier hat +sombrero +tricorn +beaver +porkpie +bonnet +pith hat +bowler hat +millinery +cloche +pillbox +baseball cap +coonskin cap +shower cap +kepi +balaclava +fez +tam +beret +skullcap +cloth cap +ski cap +watch cap +bathing cap +mortarboard +yarmulke +beanie +head covering +scarf +romper +diaper +wraparound +robe +wet suit +legging +skirt +undergarment +separate +vest +shirt +overgarment +hose +burqa +trouser +trouser +straitjacket +fur +neckwear +sweat suit +leotard +swimsuit +hand-me-down +raglan +suit +sweater +gown +face veil +niqab +chador +mantilla +muffler +headscarf +tudung +feather boa +stole +hijab +khimar +dressing gown +kimono +abaya +bathrobe +gaiter +spat +overskirt +grass skirt +miniskirt +kilt +maxi +ballet skirt +dirndl +sarong +hoopskirt +petticoat +brassiere +foundation garment +singlet +garter belt +crinoline +underwear +body stocking +camisole +uplift +chemise +underpants +corset +panty girdle +roll-on +lingerie +long johns +BVD +undies +nightgown +bloomers +thong +bikini pants +briefs +pantie +drawers +work-shirt +kurta +jersey +dashiki +polo shirt +coat +cloak +snowsuit +surcoat +duffel coat +sheepskin coat +frock coat +lab coat +greatcoat +jacket +raincoat +capote +sack coat +fur coat +mess jacket +single-breasted jacket +bomber jacket +pea jacket +swallow-tailed coat +doublet +bolero +parka +oilskin +trench coat +mink +sable coat +poncho +toga virilis +toga +kameez +serape +tunic +shawl +caftan +short pants +pajama +sweat pants +salwar +breeches +chino +slacks +jodhpurs +pedal pusher +long trousers +jean +cords +Levi's +stretch pants +bellbottom trousers +buckskins +hot pants +Bermuda shorts +lederhosen +necktie +cravat +bolo tie +Windsor tie +bow tie +black tie +maillot +swimming trunks +bikini +double-breasted suit +pinstripe +single-breasted suit +pants suit +business suit +three-piece suit +two-piece +turtleneck +cardigan +sweatshirt +pullover +top +G-string +camisole +dress +bodice +blouse +halter +cocktail dress +sari +caftan +sundress +chemise +strapless +gown +jumper +dirndl +bridal gown +tea gown +ball gown +gauntlet +mitten +kid glove +belt +furnishing +money belt +holster +cartridge belt +hosiery +tights +sock +stocking +pantyhose +maillot +athletic sock +tabi +knee-high +argyle +nylons +Christmas stocking +formalwear +ensemble +outfit +ao dai +costume +fancy dress +costume +frock +sportswear +academic costume +disguise +hairpiece +dinner jacket +balldress +dinner dress +dress suit +Afro-wig +toupee +wig +dress hat +brace +athletic supporter +home appliance +dryer +vacuum +iron +trouser press +curling iron +white goods +sewing machine +serger +kitchen appliance +Hoover +travel iron +steam iron +dishwasher +refrigerator +washer +cooler +electric refrigerator +ice machine +deep-freeze +toaster +microwave +toaster oven +coffee maker +hot plate +waffle iron +disposal +espresso maker +stove +oven +food processor +ice maker +cookstove +electric range +gas range +Primus stove +broiler +rotisserie +Dutch oven +gas oven +hand blower +clothes dryer +spin dryer +tumble-dryer +wringer +bath towel +doily +Turkish towel +bed linen +pillow sham +sheet +tinfoil +plywood +doorplate +board +drumhead +panel +laminate +blackboard +snowboard +Sheetrock +surfboard +skateboard +sideboard +scoreboard +wainscot +headboard +chandelier +plumbing fixture +soap dish +toilet +shower +water faucet +flush toilet +potty seat +rope +cord +lasso +bungee +spun yarn +cordage +thread +bootlace +wick +lanyard +floss +woof +worsted +organism +cell +mistletoe +plant +animal +microorganism +bryophyte +person +fungus +benthos +flowering maple +vascular plant +strangler +aquatic +annual +houseplant +poisonous plant +agave +pteridophyte +spermatophyte +aquatic plant +herb +vine +woody plant +weed +cultivar +bulbous plant +succulent +American agave +maguey +maguey +sansevieria +dracaena +mother-in-law's tongue +fern ally +fern +club moss +scouring rush +ground pine +ground cedar +ground fir +flowering fern +lady fern +Boston fern +flowering fern +royal fern +tree fern +oak fern +common polypody +mountain fern +shield fern +deer fern +wood fern +American maidenhair fern +hart's-tongue +soft shield fern +holly fern +maidenhair +holly fern +water clover +sensitive fern +Christmas fern +angiopteris +soft tree fern +male fern +marginal wood fern +angiosperm +gymnosperm +barbados cherry +dicot +flower +wildflower +commelina +woodland star +nigella +black-eyed Susan +mistflower +calceolaria +toadflax +zinnia +centaury +Easter daisy +African violet +brompton stock +verbena +blue daisy +pink calla +Mexican sunflower +bloomer +achimenes +lychnis +painted daisy +treasure flower +globe amaranth +common valerian +rose moss +tidytips +common daisy +composite +ice plant +gentian +soapwort +anemone +veronica +larkspur +spring beauty +gazania +damask violet +Barberton daisy +bush violet +baby's breath +corydalis +calendula +sunflower +scabious +valerian +rue anemone +sandwort +candytuft +horn poppy +sandwort +poppy +stokes' aster +dahlia +Virginia spring beauty +petunia +orchid +hybrid petunia +African daisy +pink +African daisy +African daisy +daisy +common ageratum +oxeye daisy +columbine +calla lily +sweet alyssum +spathiphyllum +four o'clock +common marigold +cornflower +strawflower +silene +tuberose +common four-o'clock +rocket larkspur +bellwort +begonia +streptocarpus +Swan River daisy +wallflower +peony +love-in-a-mist +wallflower +cineraria +chrysanthemum +stock +sandwort +Malcolm stock +mountain sandwort +coneflower +ageratum +coneflower +sowbread +scorpionweed +cyclamen +delphinium +marigold +aster +cosmos +Mediterranean snapdragon +mullein pink +ragged robin +mayweed +tansy +dusty miller +corn chamomile +shasta daisy +everlasting +wingstem +rosinweed +oxeye daisy +strawflower +strawflower +cudweed +pearly everlasting +gentianella +agueweed +closed gentian +closed gentian +great yellow gentian +fringed gentian +marsh gentian +snowdrop anemone +wood anemone +wood anemone +germander speedwell +common speedwell +common sunflower +prairie sunflower +giant sunflower +Jerusalem artichoke +sweet scabious +field scabious +Iceland poppy +wind poppy +Iceland poppy +celandine +oriental poppy +opium poppy +celandine poppy +prickly poppy +California poppy +corn poppy +blue poppy +aerides +coelogyne +lady's slipper +Venus' slipper +cymbid +sobralia +spider orchid +spider orchid +Psychopsis papilio +liparis +butterfly orchid +butterfly orchid +butterfly orchid +oncidium +twayblade +twayblade +grass pink +brassavola +fragrant orchid +fly orchid +frog orchid +coral root +cattleya +lesser butterfly orchid +vanilla +short-spurred fragrant orchid +common spotted orchid +bog rose +ladies' tresses +odontoglossum +orchis +vanda +pansy orchid +Bletilla striata +rattlesnake plantain +marsh orchid +stanhopea +laelia +phaius +lizard orchid +caladenia +calypso +moth orchid +blue orchid +bee orchid +early spider orchid +masdevallia +bog rein orchid +European ladies' tresses +fen orchid +pogonia +fringed orchis +dendrobium +fly orchid +helleborine +helleborine +stelis +greater butterfly orchid +yellow lady's slipper +large yellow lady's slipper +common lady's-slipper +moccasin flower +butterfly orchid +male orchis +ragged orchid +purple-fringed orchid +stream orchid +Epipactis helleborine +sweet William +china pink +Japanese pink +carnation +cottage pink +maiden pink +meeting house +granny's bonnets +blue columbine +fire pink +white campion +bladder campion +red campion +wild pink +moss campion +wax begonia +hybrid tuberous begonia +rex begonia +crown daisy +corn marigold +florist's chrysanthemum +African marigold +French marigold +New England aster +bushy aster +Michaelmas daisy +Indian paintbrush +goldenrod +sand verbena +bitterroot +Indian pipe +heliopsis +meadow goldenrod +pasqueflower +fleabane +blazing star +edelweiss +coneflower +balloon flower +wild carrot +prairie gentian +desert sunflower +Arnica montana +butterweed +gaillardia +brittlebush +orange daisy +daisy fleabane +Mexican hat +long-head coneflower +cycad +welwitschia +encephalartos +dioon +macrozamia +false sago +water shamrock +water hyacinth +pistia +water lily +marsh plant +water nymph +European white lily +bog star +marsh marigold +wild calla +sedge +parnassia +skunk cabbage +skunk cabbage +cotton grass +nutgrass +common cotton grass +winter aconite +buttercup +phlox +willowherb +stapelia +skullcap +bedstraw +gumweed +kangaroo paw +common chickweed +hyssop +arum +common comfrey +borage +nasturtium +canna +loosestrife +toad lily +globe thistle +wild thyme +common fennel +bear's breech +ironweed +feverfew +monarda +physostegia +creeping bugle +vegetable +hedge nettle +plum tomato +ground cherry +flax +primrose +oxalis +kniphofia +boneset +chickweed +periwinkle +garden angelica +bugloss +Dutchman's breeches +pie plant +cow parsnip +butterbur +milk thistle +mouse-ear chickweed +yellow bells +lobelia +anise hyssop +banana +Joe-Pye weed +Joe-Pye weed +garden forget-me-not +evening primrose +spiderflower +sweet false chamomile +agrimonia +hepatica +medic +peperomia +geranium +viola +okra +bergenia +astrantia +aspidistra +thyme +common teasel +carnivorous plant +harvest-lice +nemophila +hawkweed +hawkweed +fleabane +plumbago +spiderwort +prickly poppy +common foxglove +stonecrop +garden lettuce +teasel +herb Paris +coltsfoot +basil +sainfoin +sneezeweed +cockscomb +baby blue-eyes +coleus +spurge nettle +arnica +sour dock +clover +mint +coreopsis +pimpernel +kidney vetch +foxglove +legume +reseda +forget-me-not +Virginia bluebell +pineapple +blueweed +anchusa +moss pink +common dandelion +false lupine +sage +chamomile +crucifer +chicory +broad-leaved plantain +bugle +milkweed +fireweed +spirea +inula +hemp nettle +garden nasturtium +pokeweed +moneywort +asparagus +Italian parsley +rhubarb +jewelweed +asparagus fern +sedum +yarrow +bird's foot trefoil +scarlet pimpernel +campanula +mayapple +painted nettle +pigweed +bleeding heart +achillea +snow-in-summer +gramineous plant +balsamroot +Abyssinian banana +herbage +astilbe +ginger +saxifrage +cow parsley +dill +common mullein +dead nettle +creeping buttercup +meadow buttercup +yellow bedstraw +sweet woodruff +caladium +cuckoopint +jack-in-the-pulpit +alocasia +taro +amorphophallus +bee balm +bee balm +artichoke +cardoon +tomatillo +tomatillo +English primrose +oxlip +cowslip +polyanthus +creeping oxalis +common wood sorrel +Bermuda buttercup +red-hot poker +poker plant +dwarf banana +Japanese banana +plantain +sundrops +common evening primrose +ivy geranium +cranesbill +fish geranium +rose geranium +meadow cranesbill +wild geranium +dove's foot geranium +herb robert +horned violet +field pansy +violet +dog violet +pale violet +bird's-foot violet +hedge violet +Venus's flytrap +pitcher plant +tropical pitcher plant +sundew +white clover +red clover +crimson clover +pennyroyal +water-mint +beach pea +chickpea +vetch +tufted vetch +bean +wild pea +scarlet runner +sieva bean +clary +common sage +clary sage +wild sage +purple sage +meadow clary +bok choy +mustard +cabbage +cauliflower +collard +broccoli +brussels sprout +garlic mustard +head cabbage +radish plant +bittercress +alyssum +field mustard +rape +radish +radish +lady's smock +crinkleroot +butterfly weed +swamp milkweed +tussock bellflower +Canterbury bell +clustered bellflower +peach bells +giant bamboo +grass +fescue +cordgrass +feather reed grass +reed grass +orchard grass +cereal +broom beard grass +tall oat grass +tallgrass +St. Augustine grass +pampas grass +grama +dallisgrass +zoysia +rye grass +brome +fountain grass +rye +popcorn +wheat +millet +sorghum +panic grass +goose grass +switch grass +common ginger +shellflower +meadow saxifrage +purple saxifrage +white dead nettle +henbit +ground ivy +blue pea +purple clematis +black-eyed Susan +bougainvillea +butterfly pea +butterfly pea +bindweed +kudzu +Boston ivy +squash +yellow jasmine +wax plant +morning glory +liana +Japanese wistaria +allamanda +field bindweed +common allamanda +passionflower +convolvulus +gourd +grape +Chinese gooseberry +summer squash +winter squash +pumpkin +spaghetti squash +yellow squash +acorn squash +winter crookneck +cypress vine +Japanese morning glory +moonflower +golden pothos +ceriman +jade vine +pothos +love-in-a-mist +maypop +granadilla +sweet melon +bottle gourd +net melon +winter melon +cantaloupe +Sauvignon grape +fox grape +wild indigo +shrub +tree +raspberry +lupine +abelia +banksia +bird pepper +sea holly +guelder rose +crape myrtle +castor-oil plant +spirea +hydrangea +fuchsia +redberry +saltbush +false indigo +bridal wreath +protea +Oregon grape +grevillea +gorse +rockrose +cowberry +subshrub +honeypot +California fuchsia +sumac +jasmine +impala lily +currant +axseed +mimosa +southern buckthorn +flowering quince +yucca +purple heather +waratah +mallow +strawberry tree +mock orange +honeysuckle +spurge +kalmia +bush hibiscus +weigela +Christmasberry +angel's trumpet +angel's trumpet +gooseberry +dusty miller +croton +Pyracantha +forsythia +artemisia +silversword +waratah +philadelphus +common lilac +saltwort +calliandra +wahoo +bird of paradise +cape jasmine +camellia +night jasmine +rose +mountain laurel +cotoneaster +rhododendron +frangipani +broom +desert pea +lavender +butterfly bush +deutzia +hortensia +burdock +prairie smoke +centaury +sea lavender +common mugwort +bird's foot trefoil +large periwinkle +great burdock +St John's wort +eriogonum +purple loosestrife +loosestrife +mountain avens +matilija poppy +bur marigold +wild lupine +marguerite +dusty miller +great knapweed +knapweed +creeping St John's wort +klammath weed +common St John's wort +common jasmine +winter jasmine +Adam's needle +bear grass +Joshua tree +Spanish dagger +hollyhock +rose mallow +common mallow +marsh mallow +musk mallow +hibiscus +althea +rose mallow +cotton rose +woodbine +trumpet honeysuckle +Japanese honeysuckle +poinsettia +crown of thorns +damask rose +musk rose +azalea +rosebay +swamp azalea +common broom +woodwaxen +English lavender +spike lavender +French lavender +locust tree +kowhai +bottle-tree +timber tree +linden +bonsai +snag +hackberry +pepper tree +Japanese oak +European hackberry +cork tree +birch +star anise +red silk-cotton tree +roble +common alder +fig tree +Japanese pagoda tree +albizzia +European hornbeam +cassia +coral tree +neem +white mangrove +Chinese parasol tree +bayberry +yellowwood +elm +alder +prickly ash +angiospermous tree +chestnut +cabbage bark +ash +beech +fringe tree +golden shower tree +lead tree +palm +balata +sapling +black beech +acacia +coffee +gymnospermous tree +ceibo +incense tree +lacebark +shade tree +pollard +gum tree +wild medlar +hornbeam +willow +textile screw pine +mescal bean +Brazilian rosewood +pandanus +white mangrove +oak +bean tree +plane tree +blackwood +coralwood +Kentucky coffee tree +black locust +honey locust +flame tree +flame tree +kurrajong +American basswood +silver lime +black birch +silver birch +swamp birch +downy birch +grey birch +golden fig +India-rubber tree +fig +banyan +pipal +rain tree +silk tree +smooth-leaved elm +American elm +English elm +cedar elm +myrtle +mangrove +magnolia +Queen's crape myrtle +looking-glass plant +tulip tree +maple +nut tree +redbud +baobab +poplar +tree of heaven +ailanthus +dogwood +holly +cacao +laurel +mountain ebony +kapok +sorrel tree +cacao bean +Spanish elm +rowan +mountain ash +royal poinciana +iron tree +fruit tree +sweet bay +southern magnolia +star magnolia +umbrella tree +box elder +red maple +hedge maple +Norway maple +Japanese maple +sycamore +California box elder +silver maple +sugar maple +Oregon maple +cashew +walnut +hazelnut +black walnut +English walnut +black poplar +aspen +cottonwood +white poplar +quaking aspen +Eastern cottonwood +black cottonwood +cornelian cherry +bunchberry +common European dogwood +common white dogwood +bearberry +inkberry +true laurel +cassia +citrus +mulberry +jackfruit +pomegranate +pawpaw +persimmon +carambola +plum +almond tree +durian +papaya +olive tree +longan +pear +loquat +medlar +peach +white mulberry +olive +litchi +Japanese apricot +rambutan +apple tree +Japanese persimmon +mango +breadfruit +guava +guava +jaboticaba +cherry +Surinam cherry +lime +mandarin +orange +kumquat +lemon +pomelo +grapefruit +clementine +tangerine +sweet orange +sour orange +bergamot +cherry plum +Allegheny plum +flowering almond +almond +flowering almond +crab apple +apple +wild apple +Southern crab apple +Bechtel crab +Iowa crab +sour cherry +flowering cherry +wild cherry +sweet cherry +chokecherry +Japanese flowering cherry +oriental cherry +fuji +hagberry tree +black cherry +Ozark chinkapin +American chestnut +pumpkin ash +mountain ash +manna ash +European ash +red ash +weeping beech +American beech +copper beech +bamboo palm +wine palm +fan palm +royal palm +cabbage palm +cabbage palm +sago palm +miniature fan palm +lady palm +feather palm +coconut +cabbage palm +carnauba +caranday +palmyra +cabbage palmetto +key palm +saw palmetto +palmetto +date palm +oil palm +silver wattle +wattle +huisache +ginkgo +conifer +kauri +green douglas fir +miro +cedar +cedar +douglas fir +matai +arborvitae +spruce +yew +araucaria +cypress +metasequoia +pine +fir +larch +hemlock +cedar of Lebanon +Atlas cedar +deodar +southern white cedar +incense cedar +Oregon cedar +Japanese cedar +Oriental arborvitae +American arborvitae +western red cedar +Colorado spruce +white spruce +Norway spruce +red spruce +black spruce +Sitka spruce +oriental spruce +bunya bunya +monkey puzzle +Monterey cypress +Arizona cypress +Italian cypress +Scotch pine +pond pine +pitch pine +table-mountain pine +ancient pine +stone pine +Jeffrey pine +loblolly pine +Swiss pine +spruce pine +white pine +red pine +Japanese black pine +Swiss mountain pine +black pine +Monterey pine +yellow pine +Torrey pine +shore pine +bristlecone pine +whitebark pine +western white pine +longleaf pine +ponderosa +silver fir +Fraser fir +Alpine fir +amabilis fir +lowland fir +balsam fir +European silver fir +white fir +western larch +American larch +eastern hemlock +western hemlock +mountain hemlock +gumbo-limbo +elephant tree +sweet gum +eucalyptus +sour gum +liquidambar +snow gum +mountain ash +black mallee +alpine ash +red gum +red gum +blue gum +osier +pussy willow +bay willow +weeping willow +swamp willow +purple willow +common osier +European turkey oak +red oak +cork oak +black oak +live oak +chestnut oak +bluejack oak +pin oak +post oak +shingle oak +white oak +laurel oak +northern red oak +southern red oak +southern live oak +canyon oak +coast live oak +chinquapin oak +basket oak +swamp chestnut oak +bur oak +Oregon white oak +common oak +tamarind +catalpa +carob +California sycamore +American sycamore +London plane +lightwood +black mangrove +wild raspberry +black raspberry +bluebonnet +Texas bluebonnet +thistle +cat's-ear +corn cockle +yellow rocket +fireweed +stinging nettle +horseweed +stemless carline thistle +musk thistle +cotton thistle +plume thistle +field thistle +bull thistle +Canada thistle +hippeastrum +narcissus +iridaceous plant +fritillary +liliaceous plant +star-of-Bethlehem +daffodil +jonquil +jonquil +iris +blue-eyed grass +blackberry-lily +dwarf iris +dwarf iris +beardless iris +bearded iris +Japanese iris +German iris +snake's head fritillary +crown imperial +dogtooth violet +lily +African lily +grape hyacinth +common camas +false lily of the valley +common hyacinth +camas +clintonia +lemon lily +squaw grass +scilla +tulip +alliaceous plant +fawn lily +glacier lily +yellow adder's tongue +Turk's-cap +Turk's-cap +tiger lily +tiger lily +mountain lily +Easter lily +tassel hyacinth +common grape hyacinth +Tulipa gesneriana +Darwin tulip +garlic chive +wild garlic +Hottentot fig +livingstone daisy +cactus +nopal +nopal +barrel cactus +night-blooming cereus +night-blooming cereus +night-blooming cereus +cholla +echinocactus +mammillaria +feather ball +prickly pear +crab cactus +saguaro +Christmas cactus +hedgehog cactus +golden barrel cactus +flamingo flower +anthurium +gloxinia +baneberry +red baneberry +poison ivy +gloriosa +monkshood +American holly +oleander +poison ash +herbivore +big game +thoroughbred +creepy-crawly +young +domestic animal +pet +critter +larva +feeder +male +pest +omnivore +predator +chordate +work animal +invertebrate +female +marine animal +scavenger +hexapod +mate +prey +carnivore +young mammal +orphan +spat +young bird +hatchling +foal +kitten +calf +pup +calf +lamb +baby +puppy +suckling +cub +piglet +nestling +fledgling +head +stray +feeder +tadpole +caterpillar +nymph +doodlebug +tobacco hornworm +cabbageworm +tomato hornworm +silkworm +cutworm +woolly bear +measuring worm +armyworm +silkworm +tussock caterpillar +tent caterpillar +colt +ridgeling +sire +sea squirt +ascidian +vertebrate +aquatic vertebrate +amphibian +mammal +baby +fetus +quadruped +reptile +bird +fish +lamprey +teleost fish +food fish +elasmobranch +ganoid +trumpetfish +pipefish +seahorse +spiny-finned fish +soft-finned fish +needlefish +beluga +gar +bowfin +paddlefish +sturgeon +percoid fish +dragonet +frogfish +barracuda +soldierfish +goosefish +scorpaenoid +flatfish +great barracuda +plectognath +snook +perch +perch +dolphinfish +freshwater bass +scombroid +bass +parrotfish +sea bream +grunt +flathead +bluefish +carangid fish +damselfish +butterfly fish +mudskipper +pike +goby +tautog +sunfish +snapper +snapper +sciaenid fish +wolffish +cichlid +wrasse +yellow perch +European perch +walleye +mackerel +skipjack +black marlin +sailfish +marlin +bonito +tuna +wahoo +Spanish mackerel +Spanish mackerel +cero +king mackerel +bluefin +yellowfin +jack +permit +scad +crevalle jack +kingfish +amberjack +yellowtail +horse mackerel +horse mackerel +clown anemone fish +sergeant major +anemone fish +chaetodon +rock beauty +angelfish +northern pike +pickerel +muskellunge +black bass +pumpkinseed +freshwater bream +bluegill +crappie +smallmouth +largemouth +sea trout +croaker +kingfish +mulloway +red drum +white croaker +white croaker +scorpaenid +flathead +scorpionfish +lionfish +stonefish +rockfish +plaice +flounder +halibut +cowfish +boxfish +ocean sunfish +puffer +spiny puffer +triggerfish +balloonfish +porcupinefish +tarpon +bonefish +pollack +anchovy +lizardfish +catfish +cypriniform fish +eel +clupeid fish +European catfish +flathead catfish +channel catfish +blue catfish +characin +electric eel +cyprinodont +loach +cyprinid +topminnow +piranha +cardinal tetra +tetra +killifish +striped killifish +guppy +swordtail +carp +minnow +tench +crucian carp +goldfish +gudgeon +platy +mosquitofish +conger +tuna +moray +sardine +pilchard +sea bass +trout +salmon +barracouta +grouper +striped bass +jewfish +hind +sea trout +brook trout +rainbow trout +brown trout +lake trout +chinook +Atlantic salmon +redfish +coho +landlocked salmon +shark +ray +sand tiger +angel shark +nurse shark +requiem shark +smooth dogfish +hammerhead +mackerel shark +whale shark +bull shark +blue shark +sandbar shark +blacktip shark +whitetip shark +tiger shark +lemon shark +whitetip shark +smoothhound +great white shark +mako +porbeagle +stingray +electric ray +spotted eagle ray +Atlantic manta +manta +skate +eagle ray +salamander +frog +spotted salamander +newt +European fire salamander +slender salamander +ambystomid +eft +common newt +red eft +spotted salamander +axolotl +tiger salamander +true toad +true frog +tailed frog +crapaud +tree toad +tree frog +natterjack +Eurasian green toad +bufo +American toad +agua +western toad +European toad +grass frog +wood-frog +bullfrog +leopard frog +pickerel frog +green frog +spring peeper +chorus frog +placental +tusker +monotreme +marsupial +female mammal +aardvark +livestock +insectivore +hyrax +doe +edentate +stag +bull +primate +carnivore +bat +aquatic mammal +lagomorph +rock hyrax +yearling +rodent +cow +pachyderm +buck +pangolin +ungulate +shrew +hedgehog +peba +sloth +armadillo +anteater +two-toed sloth +two-toed sloth +three-toed sloth +ant bear +tamandua +simian +tarsier +homo +ape +lemur +monkey +Homo sapiens sapiens +Homo sapiens +Neandertal man +anthropoid ape +lesser ape +great ape +siamang +gibbon +chimpanzee +orangutan +gorilla +pygmy chimpanzee +central chimpanzee +western lowland gorilla +mountain gorilla +silverback +indri +Madagascar cat +potto +galago +slow loris +Old World monkey +New World monkey +baboon +vervet +proboscis monkey +colobus +patas +macaque +guenon +langur +chacma +mandrill +Barbary ape +rhesus +spider monkey +marmoset +squirrel monkey +titi +capuchin +howler monkey +tamarin +pygmy marmoset +procyonid +feline +viverrine +canine +musteline mammal +bear +coati +common raccoon +lesser panda +raccoon +kinkajou +giant panda +big cat +cat +jaguar +tiger +leopard +cheetah +lion +snow leopard +tigress +Bengal tiger +tiger cub +lioness +lion cub +domestic cat +wildcat +tabby +tiger cat +tabby +tortoiseshell +Manx +Egyptian cat +Abyssinian +kitty +Angora +Persian cat +Burmese cat +Siamese cat +alley cat +tom +mouser +margay +ocelot +lynx +cougar +European wildcat +serval +manul +sand cat +common lynx +bobcat +caracal +Canada lynx +meerkat +genet +mongoose +slender-tailed meerkat +suricate +dog +wild dog +wolf +bitch +jackal +fox +hyena +pug +corgi +Great Pyrenees +Brabancon griffon +poodle +cur +Leonberg +griffon +dalmatian +pooch +spitz +toy dog +hunting dog +working dog +basenji +Mexican hairless +Newfoundland +lapdog +Cardigan +Pembroke +standard poodle +toy poodle +miniature poodle +Pomeranian +keeshond +chow +Samoyed +toy spaniel +Shih-Tzu +toy terrier +Maltese dog +Japanese spaniel +Chihuahua +Pekinese +King Charles spaniel +Blenheim spaniel +papillon +terrier +Rhodesian ridgeback +sausage dog +sporting dog +hound +dachshund +Dandie Dinmont +schnauzer +wirehair +Airedale +West Highland white terrier +Kerry blue terrier +Norfolk terrier +Border terrier +Yorkshire terrier +wire-haired fox terrier +Bedlington terrier +Tibetan terrier +silky terrier +Lhasa +Scotch terrier +cairn +Boston bull +fox terrier +Australian terrier +bullterrier +Norwich terrier +Irish terrier +rat terrier +soft-coated wheaten terrier +standard schnauzer +giant schnauzer +miniature schnauzer +Lakeland terrier +Welsh terrier +Sealyham terrier +Staffordshire bullterrier +American Staffordshire terrier +Manchester terrier +toy Manchester +water dog +pointer +bird dog +setter +spaniel +retriever +vizsla +German short-haired pointer +Gordon setter +English setter +Irish setter +cocker spaniel +water spaniel +springer spaniel +Brittany spaniel +clumber +Sussex spaniel +Irish water spaniel +English springer +Welsh springer spaniel +flat-coated retriever +golden retriever +curly-coated retriever +Chesapeake Bay retriever +Labrador retriever +otterhound +bloodhound +wolfhound +basset +Ibizan hound +Norwegian elkhound +coonhound +Saluki +Afghan hound +black-and-tan coonhound +bluetick +Scottish deerhound +redbone +foxhound +beagle +Weimaraner +greyhound +borzoi +Irish wolfhound +English foxhound +Walker hound +whippet +Italian greyhound +Great Dane +watchdog +Eskimo dog +Tibetan mastiff +sled dog +Saint Bernard +French bulldog +police dog +bulldog +Sennenhunde +bull mastiff +shepherd dog +boxer +mastiff +kuvasz +housedog +pinscher +schipperke +Doberman +miniature pinscher +affenpinscher +Siberian husky +malamute +Greater Swiss Mountain dog +EntleBucher +Bernese mountain dog +Appenzeller +Belgian sheepdog +kelpie +Shetland sheepdog +komondor +Border collie +collie +Rottweiler +Old English sheepdog +German shepherd +briard +Bouvier des Flandres +groenendael +malinois +African hunting dog +dingo +dhole +coyote +wolf pup +red wolf +white wolf +timber wolf +red fox +red fox +kit fox +Arctic fox +grey fox +kit fox +spotted hyena +striped hyena +mink +black-footed ferret +striped skunk +pine marten +sea otter +otter +weasel +polecat +glutton +skunk +badger +ferret +river otter +Eurasian otter +ice bear +American black bear +bear cub +Asiatic black bear +brown bear +sloth bear +grizzly +Alaskan brown bear +carnivorous bat +flying fox +fruit bat +brown bat +vespertilian bat +pallid bat +pipistrelle +cetacean +sea cow +pinniped mammal +whale +toothed whale +baleen whale +dolphin +bottle-nosed whale +porpoise +common dolphin +bottlenose dolphin +pilot whale +killer whale +white whale +Pacific bottlenose dolphin +Atlantic bottlenose dolphin +grey whale +rorqual +blue whale +lesser rorqual +finback +manatee +dugong +walrus +seal +earless seal +eared seal +elephant seal +harbor seal +harp seal +fur seal +fur seal +sea lion +California sea lion +Australian sea lion +Steller sea lion +pika +leporid +rabbit +hare +eastern cottontail +wood rabbit +bunny +European rabbit +lapin +Angora +rabbit ears +snowshoe hare +European hare +jackrabbit +chinchilla +rat +capybara +golden hamster +water vole +porcupine +coypu +vole +beaver +hamster +prairie dog +squirrel +marmot +blacktail prairie dog +cavy +gerbil +mouse +muskrat +gopher +brown rat +black rat +chipmunk +ground squirrel +eastern chipmunk +tree squirrel +rock squirrel +mantled ground squirrel +eastern grey squirrel +red squirrel +black squirrel +American red squirrel +fox squirrel +hoary marmot +groundhog +aperea +guinea pig +field mouse +house mouse +elephant +African elephant +Indian elephant +even-toed ungulate +odd-toed ungulate +ruminant +camel +swine +llama +vicuna +collared peccary +hippopotamus +peccary +pronghorn +deer +bovid +giraffe +okapi +woodland caribou +caribou +fallow deer +elk +hart +mule deer +fawn +red deer +muntjac +Virginia deer +wapiti +Japanese deer +roe deer +black-tailed deer +wild sheep +bison +musk ox +Old World buffalo +bovine +antelope +sheep +goat antelope +goat +aoudad +mountain sheep +Dall sheep +bighorn +mouflon +American bison +wisent +carabao +water buffalo +Cape buffalo +Brahman +ox +zebu +cattle +yak +gaur +beef +ox +bull +bullock +heifer +cow +dairy cattle +longhorn +Charolais +Hereford +Durham +Aberdeen Angus +Galloway +Friesian +Brown Swiss +kudu +addax +blackbuck +waterbuck +eland +steenbok +dik-dik +gnu +harnessed antelope +gerenuk +sassaby +impala +greater kudu +sable antelope +hartebeest +bongo +gemsbok +oryx +gazelle +nyala +bushbuck +Thomson's gazelle +springbok antelope +domestic sheep +black sheep +ewe +wether +ram +mountain goat +chamois +takin +nanny +kid +ibex +Angora +domestic goat +billy +wild goat +Bactrian camel +Arabian camel +wild boar +warthog +boar +hog +guanaco +alpaca +rhinoceros +tapir +equine +Malayan tapir +Indian rhinoceros +black rhinoceros +white rhinoceros +horse +zebra +ass +bay +broodmare +racehorse +palomino +wild horse +pinto +hack +roan +male horse +post horse +liver chestnut +tarpan +saddle horse +chestnut +harness horse +polo pony +workhorse +mare +pony +pony +sorrel +yearling +thoroughbred +trotting horse +stud +stallion +gelding +Tennessee walker +hack +cavalry horse +grey +Morgan +buckskin +dun +Arabian +quarter horse +cob +hackney +plow horse +farm horse +draft horse +carthorse +Percheron +Clydesdale +shire +cayuse +bronco +mustang +Welsh pony +Shetland pony +Exmoor +common zebra +mountain zebra +grevy's zebra +jennet +burro +domestic ass +echidna +platypus +echidna +kangaroo +koala +wombat +common opossum +opossum +dasyurid marsupial +phalanger +giant kangaroo +wallaby +rock wallaby +tree wallaby +Tasmanian devil +numbat +chelonian +diapsid +turtle +Western box turtle +box turtle +common snapping turtle +terrapin +soft-shelled turtle +painted turtle +sea turtle +snapping turtle +slider +tortoise +mud turtle +cooter +hawksbill turtle +loggerhead +green turtle +leatherback turtle +ridley +Pacific ridley +Atlantic ridley +giant tortoise +gopher tortoise +European tortoise +desert tortoise +crocodilian reptile +snake +tuatara +lizard +dinosaur +alligator +crocodile +American alligator +caiman +Asian crocodile +African crocodile +blind snake +viper +sea snake +elapid +constrictor +colubrid snake +horned viper +asp +adder +puff adder +pit viper +water moccasin +copperhead +rattlesnake +ground rattler +massasauga +diamondback +Mojave rattlesnake +timber rattlesnake +prairie rattlesnake +Western diamondback +sidewinder +rock rattlesnake +speckled rattlesnake +cobra +green mamba +taipan +copperhead +mamba +coral snake +coral snake +Indian cobra +hamadryad +boa +python +rosy boa +boa constrictor +anaconda +reticulated python +carpet snake +rock python +blacksnake +garter snake +bull snake +hognose snake +rat snake +whip-snake +water snake +green snake +racer +green snake +thunder snake +ringneck snake +vine snake +king snake +night snake +ribbon snake +common garter snake +pine snake +gopher snake +corn snake +black rat snake +grass snake +common water snake +water moccasin +smooth green snake +rough green snake +milk snake +common kingsnake +banded gecko +chameleon +monitor +skink +Gila monster +Komodo dragon +whiptail +iguanid +agamid +gecko +African chameleon +lacertid lizard +anguid lizard +horned lizard +tree lizard +chuckwalla +American chameleon +basilisk +side-blotched lizard +spiny lizard +collared lizard +common iguana +marine iguana +leopard lizard +western fence lizard +fence lizard +agama +mountain devil +frilled lizard +green lizard +sand lizard +blindworm +alligator lizard +ornithischian +tyrannosaur +stegosaur +triceratops +bird of passage +aquatic bird +passerine +cock +hummingbird +piciform bird +coraciiform bird +quetzal +bird of prey +caprimulgiform bird +cuculiform bird +gamecock +ratite +gallinaceous bird +trogon +parrot +carinate +dickeybird +hen +wading bird +swan +gallinule +seabird +waterfowl +heron +crested cariama +trumpeter +bustard +ibis +stork +whooping crane +crane +limpkin +chunga +flamingo +rail +spoonbill +shoebill +shorebird +great blue heron +night heron +little blue heron +boatbill +great white heron +egret +bittern +black-crowned night heron +yellow-crowned night heron +great white heron +little egret +snowy egret +American egret +cattle egret +least bittern +American bittern +wood ibis +sacred ibis +marabou +black stork +white stork +saddlebill +jabiru +policeman bird +wood ibis +notornis +weka +spotted crake +crake +coot +Old World coot +American coot +common spoonbill +roseate spoonbill +plover +godwit +Hudsonian godwit +stilt +stone curlew +oystercatcher +stilt +American woodcock +snipe +woodcock +avocet +sandpiper +European curlew +pratincole +curlew +phalarope +golden plover +ruddy turnstone +killdeer +lapwing +turnstone +piping plover +black-necked stilt +black-winged stilt +whole snipe +Wilson's snipe +great snipe +dowitcher +tattler +greenshank +willet +curlew sandpiper +sanderling +redshank +spotted sandpiper +knot +red-backed sandpiper +upland sandpiper +least sandpiper +pectoral sandpiper +ruff +European sandpiper +yellowlegs +greater yellowlegs +lesser yellowlegs +red phalarope +Wilson's phalarope +pen +cygnet +trumpeter +coscoroba +mute swan +cob +whooper +black swan +tundra swan +whistling swan +Bewick's swan +purple gallinule +European gallinule +moorhen +coastal diving bird +pelagic bird +grebe +auk +loon +pelecaniform seabird +sphenisciform seabird +puffin +larid +jaeger +skimmer +sea swallow +gull +tern +ivory gull +mew +laughing gull +black-backed gull +kittiwake +herring gull +skua +parasitic jaeger +petrel +albatross +wandering albatross +shearwater +storm petrel +fulmar +red-necked grebe +great crested grebe +pied-billed grebe +black-necked grebe +dabchick +razorbill +guillemot +auklet +murre +black guillemot +common murre +pigeon guillemot +frigate bird +cormorant +snakebird +pelican +gannet +water turkey +tropic bird +white pelican +Old world white pelican +solan +booby +penguin +emperor penguin +jackass penguin +king penguin +rock hopper +Adelie +horned puffin +tufted puffin +Atlantic puffin +anseriform bird +goose +duck +blue goose +barnacle goose +snow goose +Chinese goose +common brant goose +brant +gosling +greylag +gander +honker +diving duck +scaup +shelduck +wood drake +bufflehead +black duck +mandarin duck +American widgeon +pintail +mallard +sheldrake +teal +Barrow's goldeneye +quack-quack +wild duck +ruddy duck +wood duck +drake +muscovy duck +shoveler +dabbling duck +widgeon +sea duck +redhead +pochard +goldeneye +canvasback +duckling +greater scaup +lesser scaup +garganey +greenwing +bluewing +eider +old squaw +merganser +scoter +common scoter +American merganser +red-breasted merganser +hooded merganser +smew +goosander +wren +broadbill +tyrannid +oscine +scrubbird +sparrow +marsh wren +rock wren +winter wren +cactus wren +house wren +Carolina wren +ovenbird +manakin +pitta +woodhewer +New World flycatcher +kingbird +phoebe +pewee +vermillion flycatcher +western wood pewee +scissortail +grey kingbird +eastern kingbird +Arkansas kingbird +warbler +brown creeper +corvine bird +starling +pipit +titmouse +fairy bluebird +thrush +hedge sparrow +wood swallow +shrike +lark +golden oriole +Old World flycatcher +thrasher +vireo +tanager +honeycreeper +finch +bowerbird +water ouzel +accentor +mockingbird +brown thrasher +skylark +catbird +satin bowerbird +waxwing +red-eyed vireo +New World oriole +Old World oriole +babbler +swallow +creeper +songbird +Australian magpie +wagtail +meadow pipit +spotted flycatcher +weaver +nuthatch +greater whitethroat +New World warbler +kinglet +Old World warbler +gnatcatcher +lesser whitethroat +yellowthroat +common yellowthroat +ovenbird +parula warbler +Blackburn +yellow warbler +American redstart +yellow-breasted chat +Audubon's warbler +Wilson's warbler +Cape May warbler +myrtle warbler +goldcrest +ruby-crowned kinglet +tailorbird +sedge warbler +wren warbler +blackcap +rook +Clark's nutcracker +jackdaw +European magpie +jay +raven +crow +magpie +American crow +blue jay +Canada jay +common starling +hill myna +myna +bushtit +chickadee +blue tit +tufted titmouse +Carolina chickadee +black-capped chickadee +robin +robin +hermit thrush +redwing +fieldfare +song thrush +nightingale +blackbird +missel thrush +ring ouzel +wheatear +bluebird +thrush nightingale +bluethroat +redstart +bulbul +Old World chat +wood thrush +stonechat +whinchat +butcherbird +loggerhead shrike +bush shrike +northern shrike +European shrike +western tanager +summer tanager +scarlet tanager +serin +bullfinch +grosbeak +goldfinch +New World sparrow +crossbill +bunting +linnet +cardinal +siskin +common canary +towhee +purple finch +honeycreeper +brambling +New World goldfinch +pine siskin +redpoll +dark-eyed junco +house finch +chaffinch +canary +redpoll +junco +pine grosbeak +evening grosbeak +hawfinch +song sparrow +white-throated sparrow +tree sparrow +field sparrow +white-crowned sparrow +swamp sparrow +chipping sparrow +indigo bunting +reed bunting +snow bunting +ortolan +yellowhammer +cedar waxwing +Bohemian waxwing +bobolink +meadowlark +northern oriole +orchard oriole +New World blackbird +eastern meadowlark +western meadowlark +Bullock's oriole +Baltimore oriole +purple grackle +cowbird +grackle +red-winged blackbird +white-bellied swallow +tree swallow +martin +barn swallow +cliff swallow +house martin +bank martin +butcherbird +currawong +Java sparrow +zebra finch +red-breasted nuthatch +European nuthatch +white-breasted nuthatch +English sparrow +tree sparrow +thornbill +Archilochus colubris +jacamar +woodpecker +barbet +toucanet +toucan +flicker +downy woodpecker +green woodpecker +sapsucker +wryneck +redheaded woodpecker +yellow-shafted flicker +red-breasted sapsucker +yellow-bellied sapsucker +kingfisher +roller +motmot +Euopean hoopoe +hornbill +European roller +hoopoe +bee eater +kookaburra +Eurasian kingfisher +belted kingfisher +vulture +hawk +secretary bird +eagle +owl +Old World vulture +New World vulture +Egyptian vulture +bearded vulture +black vulture +griffon vulture +black vulture +buzzard +king vulture +condor +Andean condor +California condor +harrier +goshawk +red-shouldered hawk +honey buzzard +falcon +harrier eagle +Cooper's hawk +osprey +kite +rough-legged hawk +buzzard +sparrow hawk +marsh harrier +marsh hawk +carancha +gyrfalcon +peregrine +caracara +hobby +pigeon hawk +kestrel +sparrow hawk +white-tailed kite +swallow-tailed kite +black kite +eaglet +golden eagle +sea eagle +bald eagle +harpy +tawny eagle +fishing eagle +ern +tawny owl +owlet +spotted owl +screech owl +horned owl +screech owl +little owl +barn owl +scops owl +Old World scops owl +hawk owl +great horned owl +barred owl +long-eared owl +great grey owl +frogmouth +goatsucker +touraco +cuckoo +coucal +roadrunner +rhea +rhea +ostrich +emu +cassowary +domestic fowl +columbiform bird +brush turkey +red jungle fowl +jungle fowl +game bird +turkey cock +bantam +turkey +guinea fowl +chicken +cockerel +cock +Rhode Island red +chick +Orpington +hen +pullet +brood hen +sandgrouse +pigeon +domestic pigeon +dove +wood pigeon +rock dove +homing pigeon +roller +Streptopelia turtur +turtledove +Australian turtledove +mourning dove +phasianid +tinamou +grouse +pheasant +quail +partridge +tragopan +ring-necked pheasant +golden pheasant +peafowl +peahen +blue peafowl +peacock +green peafowl +bobwhite +California quail +northern bobwhite +red-legged partridge +Hungarian partridge +spruce grouse +prairie chicken +capercaillie +ruffed grouse +sage grouse +moorhen +black grouse +ptarmigan +cockateel +parakeet +cockatoo +poll +kea +African grey +macaw +amazon +lovebird +lory +popinjay +budgerigar +ring-necked parakeet +sulphur-crested cockatoo +pink cockatoo +rainbow lorikeet +lorikeet +beast of burden +draft animal +ctenophore +worm +mollusk +echinoderm +coelenterate +arthropod +sponge +nematode +annelid +flatworm +medicinal leech +earthworm +chiton +bivalve +cephalopod +gastropod +oyster +ark shell +clam +mussel +cockle +scallop +pearl oyster +soft-shell clam +quahog +giant clam +freshwater mussel +edible mussel +zebra mussel +octopod +chambered nautilus +cuttlefish +octopus +paper nautilus +sea hare +cowrie +conch +seasnail +ormer +tiger cowrie +sea slug +slug +snail +common limpet +whelk +nerita +edible snail +brown snail +garden snail +starfish +feather star +sand dollar +sea urchin +sea cucumber +brittle star +polyp +anthozoan +Portuguese man-of-war +jellyfish +sea pen +sea anemone +coral +stony coral +gorgonian +sea fan +mushroom coral +brain coral +centipede +crustacean +trilobite +millipede +arachnid +horseshoe crab +instar +insect +house centipede +daphnia +brachyuran +mantis shrimp +malacostracan crustacean +decapod crustacean +isopod +amphipod +pill bug +woodlouse +lobster +shrimp +hermit crab +prawn +crab +crayfish +Norway lobster +spiny lobster +American lobster +king crab +blue crab +rock crab +Dungeness crab +fiddler crab +European spider crab +scorpion +harvestman +acarine +spider +tick +mite +wood tick +orb-weaving spider +European wolf spider +tarantula +wolf spider +garden spider +black widow +black and gold garden spider +barn spider +orthopterous insect +hemipterous insect +neuropteron +dictyopterous insect +collembolan +mayfly +homopterous insect +dipterous insect +earwig +common European earwig +phasmid +pollinator +bug +pupa +walking stick +scorpion fly +beetle +heteropterous insect +stonefly +hymenopterous insect +lepidopterous insect +chrysalis +odonate +silverfish +worker bee +grasshopper +cricket +katydid +locust +true bug +bedbug +dobson +green lacewing +lacewing +mantis +praying mantis +cockroach +American cockroach +German cockroach +oriental cockroach +plant louse +cicada +meadow spittlebug +seventeen-year locust +mealybug +leafhopper +aphid +mosquito +crane fly +midge +fruit fly +fly +horse tick +robber fly +Asian tiger mosquito +common mosquito +bee fly +horsefly +flesh fly +blowfly +housefly +greenbottle +bluebottle +Colorado potato beetle +firefly +ground beetle +sawyer +ladybug +lamellicorn beetle +rove beetle +Asian longhorned beetle +leaf beetle +elaterid beetle +click beetle +tiger beetle +weevil +long-horned beetle +Hippodamia convergens +vedalia +scarabaeid beetle +stag beetle +rose chafer +June beetle +Japanese beetle +rhinoceros beetle +dung beetle +scarab +cockchafer +water strider +wheel bug +wasp +ichneumon fly +ant +bee +cicada killer +digger wasp +vespid +hornet +paper wasp +common wasp +giant hornet +yellow jacket +carpenter ant +fire ant +wood ant +carpenter bee +honeybee +mason bee +andrena +leaf-cutting bee +bumblebee +Africanized bee +black bee +butterfly +moth +lycaenid +nymphalid +sulphur butterfly +ringlet +monarch +cabbage butterfly +blue +hairstreak +copper +tortoiseshell +fritillary +admiral +banded purple +peacock +red-spotted purple +painted beauty +mourning cloak +viceroy +red admiral +white admiral +comma +small white +large white +cinnabar +saturniid +noctuid moth +hawkmoth +tea tortrix +geometrid +tineid +atlas moth +emperor +polyphemus moth +cecropia +luna moth +carpet moth +clothes moth +dragonfly +damselfly +hen +filly +dam +herpes +protoctist +herpes simplex +herpes zoster +cytomegalovirus +herpes varicella zoster +alga +protozoan +seagrass +pond scum +green algae +plasmodium +ameba +ciliate +paramecium +sphagnum +hepatica +liverwort +peer +birth +adult +juvenile +countrywoman +businessperson +native +celebrant +native +Filipino +male +Gemini +onlooker +queen +referee +commoner +expert +newcomer +face +demonstrator +orphan +Black woman +contestant +bullfighter +lowerclassman +candidate +friend +life +anomaly +actor +thrower +creature +child +sheep +scuba diver +dancer +garbage man +entertainer +lover +unfortunate +anti +defender +sphinx +Indian +patient +Slav +White +brick +recipient +religious person +rescuer +Latin +money handler +rich person +domestic partner +creator +consumer +worker +groom +boy scout +inhabitant +African +fan +eager beaver +leader +schoolmate +man +philatelist +advocate +eccentric +bad person +transvestite +citizen +communicator +nonworker +parrot +intellectual +nonsmoker +student +chameleon +combatant +platinum blond +appointee +unpleasant person +politician +ruler +ancient +spectator +right-hander +traveler +scientist +picker +female +acquaintance +Black +relative +beard +redhead +sleeper +computer user +associate +participant +member +raiser +groom +bride +commissioner +director +tribesman +board member +important person +professional +oldster +celebrity +very important person +serjeant-at-law +educator +health professional +teacher +reading teacher +schoolmaster +nurse +medical practitioner +pharmacist +head nurse +probationer +doctor +surgeon +specialist +house physician +cardiologist +radiologist +schoolchild +child +bairn +orphan +entrepreneur +baron +agent +merchant +certified public accountant +syndic +insurance broker +fishmonger +vintner +peddler +seller +male child +mother's boy +son +man +cub +farm boy +bat boy +Herr +hunk +Peter Pan +patriarch +adonis +young buck +stud +guy +patriarch +sleuth +archer +authority +military attache +therapist +technician +black belt +high priest +critic +taster +panelist +physical therapist +osteopath +player +athlete +rival +billiard player +medalist +seeded player +chess master +pool player +football player +tennis player +ball hawk +vaulter +runner +skater +acrobat +climber +diver +alpinist +soccer player +winger +tennis pro +forward +sport +basketball player +miler +ballplayer +gymnast +back +lineman +halfback +quarterback +tailback +skateboarder +speedskater +circus acrobat +aerialist +fielder +designated hitter +base runner +minor leaguer +first baseman +outfielder +right fielder +infielder +semifinalist +foe +matador +picador +banderillero +buddy +mate +flatmate +pitcher +closer +right-handed pitcher +folk dancer +square dancer +morris dancer +compere +master of ceremonies +caricaturist +performer +fire-eater +executant +dancer +juggler +puppeteer +actor +clown +musician +dancing-master +ballet dancer +understudy +starlet +tenor saxophonist +percussionist +guitarist +keyboardist +trumpeter +sitar player +singer +oboist +cellist +violist +flutist +organist +rock star +drummer +songster +bass +fiance +darling +fancier +soul mate +sweetheart +kisser +amputee +homeless +casualty +guard +fireman +zoo keeper +lawman +military policeman +attorney general +policeman +bobby +Mountie +detective +motorcycle cop +trooper +traffic cop +Kiliwa +Biloxi +Chickasaw +Kickapoo +Arab +white man +Omani +Bedouin +Yemeni +protegee +heiress +swami +Buddhist +Muslim +novitiate +religious +Muslimah +Sufi +mother +monk +Sister +treasurer +ratepayer +state treasurer +bursar +cobbler +artist +choreographer +farmer +musician +stylist +sculptor +press photographer +songwriter +arranger +beekeeper +breeder +agriculturist +drinker +policyholder +drinker +concert-goer +drunkard +beer drinker +maid +employee +assistant +gondolier +skilled worker +skidder +boatman +waiter +bartender +staff member +salesperson +workman +settler +breadwinner +waitress +salesman +gardener +laborer +mill-hand +hired hand +coal miner +horse wrangler +goat herder +farmhand +attendant +cog +model +escort +caddie +companion +lifeguard +steward +color guard +honor guard +cover girl +artist's model +electrician +official +falconer +balloonist +craftsman +pilot +blacksmith +trawler +mender +baker +serviceman +painter +diplomat +judge +incumbent +appointee +presbyter +ambassador +high commissioner +plenipotentiary +glassblower +carpenter +coiffeur +machinist +wright +hairdresser +fighter pilot +copilot +artilleryman +Navy SEAL +military officer +enlisted person +noncommissioned officer +commanding officer +naval commander +adjutant general +commander in chief +commissioned officer +army officer +adjutant +inspector general +sergeant +first sergeant +staff sergeant +commissioned military officer +commissioned naval officer +line officer +major +lieutenant +first lieutenant +marshal +captain +general +lieutenant colonel +lieutenant commander +rear admiral +soldier +enlisted man +tanker +reservist +Unknown Soldier +private +recruit +yard bird +villager +Tahitian +American +Asian +American +Polynesian +European +New Zealander +North Carolinian +Minnesotan +Nebraskan +Floridian +Afghan +Tibetan +Mongol +Papuan +Indian +Jordanian +Japanese +Malay +Korean +Timorese +Bornean +Lao +Iraqi +Gujarati +Punjabi +West Indian +Latin American +North American +South American +Bahamian +Barbadian +Haitian +Central American +Canadian +Mexican +Nicaraguan +Mexican-American +Bolivian +Guyanese +Albanian +Byelorussian +Monegasque +Frank +Scandinavian +Laconian +Netherlander +Slovene +Sabine +Bulgarian +Romanian +Lithuanian +Englishwoman +Britisher +Yugoslav +Dubliner +Parisian +Eritrean +Tanzanian +Zulu +Black African +Cameroonian +Sudanese +Senegalese +Kenyan +Togolese +Ugandan +Liberian +Herero +Zimbabwean +Nigerian +Gambian +Tuareg +Guinean +Ethiopian +South African +mayor +politician +trainer +employer +Speaker +lawgiver +cheerleader +head +aristocrat +spiritual leader +instigator +mistress +boss +demagogue +Labourite +animal trainer +pitching coach +legislator +deputy +senator +administrator +department head +secretary +manageress +executive +hotelier +chief executive officer +Treasury +minister +Secretary of State +Secretary of the Interior +duchess +viscount +clergyman +lama +rabbi +Dalai Lama +officiant +priest +cleric +vicar +Father +bishop +diocesan +cardinal +metropolitan +federalist +supporter +ambassador +protectionist +loyalist +cheerleader +adulteress +wrongdoer +hypocrite +abettor +skinhead +biographer +disk jockey +speaker +representative +reporter +orator +interlocutor +organ-grinder +head of state +alderman +resident commissioner +President of the United States +president +television reporter +anchor +retiree +sunbather +camper +scholar +exponent +casuist +futurist +licentiate +reader +brawler +boxer +wrestler +flyweight +middleweight +sparring partner +prizefighter +light heavyweight +featherweight +lightweight +heavyweight +flyweight +sumo wrestler +bantamweight +egotist +fire-eater +upstart +bragger +exhibitionist +sovereign +Pharaoh +Cheops +sheik +rider +motorcyclist +musher +astronaut +pedestrian +mover +commuter +pilgrim +skin-diver +settler +tourist +runner +gringo +unicyclist +hang glider +jockey +horseman +saunterer +marcher +hitter +scrambler +psycholinguist +social scientist +lumper +sociologist +political scientist +economist +econometrician +microeconomist +female child +woman +mother's daughter +girl wonder +Boy Scout +Cub Scout +enchantress +lady +old woman +nymph +donna +bridesmaid +smasher +primigravida +signorina +girl +beldam +heroine +widow +call girl +baggage +wife +gal +baby +lass +maid +first lady +old lady +crown princess +father-in-law +cousin +kinswoman +ancestor +kinsman +second cousin +in-law +kin +twin +offspring +sibling +niece +aunt +great-niece +sister +great-aunt +little sister +big sister +parent +forefather +forebear +patriarch +mater +father +mother +dad +old man +great grandparent +grandparent +great grandmother +nan +grandma +grandfather +great-nephew +little brother +grandchild +firstborn +child +successor +granddaughter +great grandchild +great grandson +great granddaughter +baby +godson +premature baby +neonate +shiitake +common stinkhorn +earthball +truffle +hen-of-the-woods +gyromitra +mildew +lichen +white fungus +true slime mold +slime mold +club fungus +earthstar +coral fungus +false morel +puffball +pythium +helvella +giant puffball +Scleroderma citrinum +jelly fungus +agaric +stinkhorn +discomycete +basidiomycete +Phytophthora infestans +Jew's-ear +bolete +powdery mildew +downy mildew +reindeer moss +beard lichen +Iceland moss +lecanora +Sarcoscypha coccinea +Aleuria aurantia +gill fungus +polypore +agaric +mushroom +Polyporus squamosus +bracket fungus +Entoloma lividum +mushroom +inky cap +mushroom +oyster mushroom +deer mushroom +parasol mushroom +fairy-ring mushroom +royal agaric +blewits +honey mushroom +Pholiota squarrosa +lepiota +blushing mushroom +horse mushroom +nameko +winter mushroom +false deathcap +shaggymane +destroying angel +toadstool +chanterelle +meadow mushroom +death cap +fly agaric +morel +common morel +black morel +Boletus edulis +Boletus luridus +Boletus chrysenteron +somatic cell +histiocyte +leukocyte +lymphocyte +neutrophil +nest +tangle +radiator +plant part +rock +comet +cadaver +star +snowdrift +covering +aerie +wasp's nest +lip +tendril +plant organ +mycelium +reproductive structure +leaf +root +stalk +hypanthium +flower +fruit +pistil +rosebud +inflorescence +floret +umbel +flower cluster +panicle +olive +ear +buckthorn berry +berry +wild cherry +acorn +rowanberry +mealie +gourd +seed +hip +juniper berry +pod +corn +coffee bean +nut +buckeye +oilseed +bean +edible seed +edible nut +pine nut +macadamia nut +pistachio +hazelnut +walnut +cashew +chestnut +pecan +peanut +coconut +linseed +rapeseed +broad bean +soy +cumin +sunflower seed +pumpkin seed +legume +okra +chickpea +pea +cowpea +garden pea +lentil +dandelion green +frond +petal +cassava +chicory +tuber +spadix +branchlet +bulb +petiole +scape +cornstalk +rattan +Jerusalem artichoke +yam +squill +onion +belay +outcrop +tor +supernova +sun +shell +bracteole +shell +cassia bark +snowcap +perianth +body covering +roof +seashell +scallop shell +oyster shell +exoskeleton +cuticle +plastron +skin +hair +scapular +hairdo +forelock +encolure +facial hair +pigtail +thatch +pompadour +mustache +beard +mustachio +soup-strainer +stubble +soul patch +weather +dust storm +cloud +snow +wave diff --git a/data/9k.tree b/data/9k.tree new file mode 100644 index 0000000..deb61e2 --- /dev/null +++ b/data/9k.tree @@ -0,0 +1,9418 @@ +n00002452 -1 +n00020827 -1 +n00002684 -1 +n11425580 -1 +n05220461 0 +n09225146 0 +n05538625 4 +n01900150 4 +n05225602 4 +n05418717 8 +n05302499 8 +n05578095 8 +n09475179 5 +n09376198 5 +n14877585 1 +n15046900 1 +n00019613 1 +n00021265 1 +n15067877 14 +n09436708 14 +n14915184 15 +n07555863 15 +n07850329 21 +n07849336 21 +n07705711 21 +n07622061 21 +n07594066 21 +n07854982 22 +n07852833 22 +n07852614 22 +n07854184 22 +n07852229 22 +n07851443 22 +n07705931 24 +n07707451 24 +n07752966 33 +n07760859 33 +n07747055 33 +n07754684 33 +n07768694 33 +n07764847 33 +n07768858 33 +n07739125 33 +n07746551 33 +n07753113 33 +n07763987 33 +n07748574 33 +n07751451 33 +n07762244 33 +n07750872 33 +n07742704 33 +n07765208 33 +n07763792 33 +n07767847 33 +n07766173 33 +n07751004 33 +n07760153 33 +n07758680 33 +n07753592 33 +n07751280 33 +n07769731 33 +n07763629 33 +n07755411 33 +n07754451 33 +n07753275 33 +n07764155 33 +n07765073 33 +n07762114 33 +n07762913 33 +n07753743 33 +n07765999 33 +n07765361 33 +n07752377 33 +n07757132 33 +n07769584 33 +n07751148 33 +n07761141 36 +n07761309 36 +n07749731 37 +n07747951 37 +n07749446 37 +n07747607 37 +n07749582 37 +n07750449 37 +n07749969 37 +n07750146 37 +n07748157 79 +n07748416 79 +n07748276 79 +n07748912 81 +n07748753 81 +n07749192 89 +n07749312 89 +n07739344 42 +n07739506 42 +n07742313 94 +n07740220 94 +n07740954 94 +n07740461 96 +n07740342 96 +n07745940 50 +n07767171 50 +n07744246 50 +n07744057 50 +n07744811 50 +n07744682 50 +n07745466 50 +n07743902 50 +n07746334 50 +n07746186 50 +n07743544 50 +n07743224 50 +n07755707 62 +n07756951 62 +n07755929 62 +n07757990 73 +n07757312 73 +n07757511 73 +n07734744 34 +n07719213 34 +n07768423 34 +n07735510 34 +n07718472 34 +n07710283 34 +n07713395 34 +n07708398 34 +n07710007 34 +n07718747 34 +n07708798 34 +n07723039 34 +n07715561 34 +n07709333 34 +n07730406 34 +n07730033 34 +n07733394 34 +n07713267 34 +n07722217 34 +n07817871 34 +n07736813 123 +n07719839 123 +n07712267 123 +n07730207 123 +n07710616 123 +n07710952 142 +n07711569 142 +n07711080 142 +n07713763 124 +n07713895 124 +n07733567 124 +n07715103 124 +n07715221 124 +n07715407 124 +n07714990 124 +n07735687 124 +n07735803 124 +n07714188 147 +n07714448 147 +n07714895 147 +n07714571 147 +n07714078 147 +n07720442 126 +n07734017 126 +n07713074 126 +n07734555 126 +n07720615 160 +n07721325 160 +n07720875 164 +n07721195 164 +n07721018 164 +n07721456 165 +n07722052 165 +n07721942 169 +n07721678 169 +n07734292 161 +n07734183 161 +n07724943 128 +n07725376 128 +n07726095 128 +n07725255 128 +n07729485 175 +n07726796 175 +n07727458 180 +n07727048 180 +n07727578 180 +n07727868 183 +n07728804 183 +n07728053 184 +n07728585 184 +n07728181 184 +n07729384 185 +n07729828 185 +n07725531 176 +n07725789 191 +n07725888 191 +n07715721 130 +n07717070 130 +n07716906 194 +n07716358 194 +n07716034 194 +n07717556 195 +n07717410 195 +n07720277 131 +n07736256 131 +n07723330 131 +n07719616 131 +n07736692 131 +n07733712 131 +n07732747 203 +n07730855 203 +n07731587 203 +n07731006 203 +n07723559 203 +n07724654 211 +n07724269 211 +n07724492 211 +n07722485 136 +n07723177 136 +n07722888 136 +n07639069 25 +n07679356 25 +n07682197 219 +n07680517 219 +n07695878 219 +n07685730 219 +n07682316 219 +n07684517 219 +n07680761 219 +n07681691 219 +n07684600 219 +n07684164 219 +n07686720 219 +n07680932 219 +n07687211 219 +n07681450 219 +n07683786 219 +n07695742 219 +n07682477 219 +n07686873 219 +n07684289 219 +n07683490 219 +n07682808 219 +n07690585 228 +n07684938 228 +n07690892 228 +n07685399 228 +n07693972 228 +n07690273 228 +n07691091 228 +n07687789 228 +n07685218 228 +n07694516 245 +n07694839 245 +n07694659 245 +n07690511 246 +n07690739 246 +n07690431 246 +n07688624 248 +n07688898 248 +n07689003 248 +n07690152 231 +n07693725 231 +n07690019 231 +n07692614 231 +n07691758 231 +n07691539 231 +n07691650 231 +n07693223 262 +n07693048 262 +n07691237 262 +n07687626 232 +n07687381 232 +n07687469 232 +n07871810 234 +n07684084 234 +n14580897 16 +n15062057 16 +n14698884 274 +n14696793 274 +n14765422 274 +n14844693 274 +n15019030 274 +n12167075 274 +n14974264 274 +n14858292 274 +n15075141 282 +n04033425 282 +n07556637 17 +n07566340 17 +n07560652 17 +n07881800 17 +n07938313 17 +n07800091 17 +n07570720 17 +n01464844 17 +n07556406 17 +n07840804 287 +n07802417 287 +n07925608 287 +n07844867 287 +n07569644 287 +n07568502 287 +n07809096 287 +n07843775 287 +n07755089 287 +n07882497 287 +n07573347 287 +n07923748 287 +n07572957 287 +n07731952 296 +n07804323 296 +n07804771 296 +n07803093 296 +n07803545 296 +n07732168 308 +n07732636 308 +n07804657 309 +n07804900 309 +n07809368 301 +n07841345 301 +n07827284 317 +n07827130 317 +n07822518 317 +n07827410 317 +n07816052 317 +n07812184 317 +n07810907 317 +n07858595 317 +n07811416 317 +n07824702 317 +n07818277 317 +n07819769 317 +n07920989 317 +n07822323 317 +n07815424 324 +n07814390 324 +n07826930 324 +n07814487 324 +n07814203 324 +n07583066 325 +n07822845 325 +n07767344 325 +n07823105 325 +n07828987 325 +n07582609 325 +n07825972 325 +n07823460 325 +n07823698 325 +n07822197 325 +n07856270 325 +n07767709 325 +n07829412 325 +n07829331 342 +n07829248 342 +n07857731 348 +n07857170 348 +n07838233 350 +n07836838 350 +n07826091 350 +n07830593 350 +n07840027 350 +n07832416 350 +n07832902 350 +n07835921 350 +n07835457 350 +n07831146 355 +n07831267 355 +n07834618 361 +n07834507 361 +n07595914 326 +n07858978 326 +n07859583 326 +n07860103 370 +n07860331 370 +n07860447 370 +n07816164 327 +n07818689 327 +n07821260 327 +n07820683 327 +n07816575 327 +n07817160 327 +n07817315 327 +n07819166 327 +n07817024 327 +n07818995 327 +n07816398 327 +n07820497 327 +n07932841 327 +n07820145 327 +n07819896 327 +n07816296 327 +n07821758 327 +n07933154 386 +n07935379 386 +n07935043 386 +n07847198 302 +n07844042 302 +n07848196 394 +n07847453 394 +n07847917 394 +n07847827 394 +n07678729 304 +n07860805 304 +n07860988 304 +n07883031 304 +n07623136 402 +n07861158 402 +n07627931 404 +n07628068 404 +n07565161 288 +n07565083 288 +n07561590 288 +n07561112 288 +n07560903 288 +n07562495 411 +n07564971 411 +n07938149 413 +n07938007 413 +n07884567 289 +n07924033 289 +n07919310 289 +n07891189 289 +n07922764 289 +n07929519 289 +n07921455 289 +n07933274 289 +n07927197 289 +n07925966 289 +n07891309 289 +n07936263 289 +n07883251 289 +n07914271 289 +n07911371 417 +n07901587 417 +n07891433 417 +n07891726 417 +n07886176 417 +n07886057 417 +n07907943 417 +n07921615 417 +n07886572 417 +n07902121 417 +n07886463 417 +n07912211 431 +n07911677 431 +n07914777 431 +n07930554 431 +n07930433 431 +n07930315 431 +n07915491 442 +n07915094 442 +n07913393 443 +n07916041 443 +n07914995 443 +n07916183 443 +n07914413 443 +n07917392 443 +n07917133 443 +n07915918 443 +n07930864 445 +n07931870 445 +n07932039 445 +n07930062 445 +n07906111 432 +n07907037 432 +n07902799 432 +n07904865 432 +n07905474 432 +n07902937 432 +n07904395 432 +n07905038 432 +n07902336 432 +n07905979 432 +n07903101 432 +n07904760 432 +n07903208 432 +n07904934 432 +n07906284 432 +n07902443 474 +n07903841 474 +n07903962 474 +n07903731 474 +n07903643 474 +n07907161 476 +n07906718 476 +n07907831 476 +n07907548 476 +n07907429 476 +n07906877 476 +n07906572 476 +n07893253 434 +n07892418 434 +n07893642 434 +n07899003 434 +n07896287 434 +n07896661 434 +n07893528 434 +n07896165 434 +n07900225 434 +n07893891 434 +n07900406 434 +n07895237 434 +n07898745 434 +n07896060 434 +n07899108 434 +n07892512 434 +n07897750 434 +n07892813 434 +n07894703 498 +n07894102 498 +n07894551 498 +n07900616 499 +n07900958 499 +n07900734 499 +n07900825 499 +n07901457 499 +n07898117 500 +n07895435 500 +n07899434 503 +n07899292 503 +n07894298 504 +n07895595 504 +n07894965 504 +n07897865 504 +n07895839 504 +n07895710 504 +n07898333 504 +n07897438 506 +n07895962 506 +n07896893 506 +n07899899 506 +n07895100 506 +n07898443 506 +n07899533 506 +n07894799 506 +n07897975 506 +n07899660 506 +n07894451 506 +n07910656 437 +n07909593 437 +n07911249 437 +n07910048 437 +n07908411 437 +n07910379 437 +n07908647 437 +n07886849 439 +n07887634 544 +n07887099 544 +n07889510 544 +n07887192 544 +n07887304 545 +n07888229 545 +n07887967 545 +n07889274 545 +n07887461 545 +n07888465 547 +n07890226 547 +n07890352 547 +n07889814 547 +n07890068 547 +n07890540 547 +n07888816 547 +n07924834 418 +n07924443 418 +n07924276 418 +n07920540 422 +n07920222 422 +n07920052 422 +n07920349 422 +n07919441 422 +n07731284 422 +n07919572 422 +n07920872 422 +n07921239 422 +n07934282 424 +n07933799 424 +n07929172 425 +n07927931 425 +n07928488 425 +n07928367 425 +n07927512 425 +n07928887 425 +n07928696 576 +n07928790 576 +n07936745 428 +n07935737 428 +n07936548 428 +n07801508 291 +n07805594 291 +n07800740 291 +n07801091 588 +n07802026 588 +n07801779 588 +n07801892 588 +n07557165 292 +n07560193 292 +n07651025 292 +n07560331 292 +n07557434 292 +n07556970 292 +n05399243 292 +n15089258 292 +n07560542 292 +n07573696 292 +n07613815 593 +n07643981 593 +n07596684 593 +n07600696 605 +n07597145 605 +n07597365 605 +n07599998 605 +n07596967 605 +n07620689 605 +n07642471 607 +n07643200 612 +n07642742 612 +n07643026 612 +n07642933 612 +n07643306 612 +n07606538 608 +n07599911 608 +n07607138 608 +n07608429 608 +n07598256 608 +n07606669 608 +n07607605 608 +n07601572 608 +n07609632 608 +n07605597 608 +n07607967 608 +n07609215 608 +n07841907 608 +n07606764 608 +n07605944 608 +n07601686 608 +n07605380 608 +n07605040 608 +n07601809 608 +n07605474 608 +n07842130 630 +n07842044 630 +n07600285 609 +n07600177 609 +n07842202 597 +n07579688 597 +n07580053 597 +n07588947 597 +n07842753 597 +n07583197 597 +n07879350 597 +n07880751 597 +n07868200 597 +n07863802 597 +n07875152 597 +n07824191 597 +n07878785 597 +n07865484 597 +n07866015 597 +n07868955 597 +n07861557 597 +n07580253 597 +n07877187 597 +n07866868 597 +n07880458 597 +n07648913 597 +n07580470 597 +n07866277 597 +n07591961 597 +n07868508 597 +n07871436 597 +n07864934 597 +n07874780 597 +n07879659 597 +n07878926 597 +n07937461 597 +n07842433 597 +n07862611 597 +n07863374 597 +n07866723 597 +n07867021 597 +n07867164 597 +n07726525 597 +n07624466 597 +n07842308 597 +n07877299 597 +n07880080 597 +n07862348 597 +n07873464 597 +n07869775 597 +n07879953 597 +n07625061 597 +n07843636 597 +n07696403 597 +n07580592 597 +n07655263 597 +n07868340 597 +n07619004 597 +n07879174 597 +n07867324 597 +n07843464 597 +n07877961 597 +n07873807 597 +n07867421 597 +n07654298 597 +n07878647 597 +n07611839 597 +n07842605 597 +n07871720 597 +n07869611 597 +n07876651 597 +n07880968 597 +n07875436 597 +n07806221 597 +n07841495 597 +n07823951 597 +n07712382 597 +n07591586 645 +n07590320 645 +n07587111 645 +n07592481 645 +n07590611 645 +n07591473 645 +n07590502 645 +n07591049 645 +n07592768 645 +n07585758 647 +n07588193 647 +n07586894 647 +n07588299 647 +n07584110 647 +n07587441 647 +n07587023 647 +n07586099 647 +n07588574 647 +n07584332 647 +n07586604 647 +n07586718 647 +n07585107 647 +n07585557 647 +n07585208 647 +n07584593 647 +n07585906 647 +n07584423 647 +n07587618 729 +n07587700 729 +n07588111 729 +n07704054 670 +n07704205 670 +n07871234 676 +n07870167 676 +n07863547 676 +n07700003 676 +n07619208 695 +n07619409 695 +n07874159 700 +n07874343 700 +n07874259 700 +n07874441 700 +n07874063 700 +n07867751 701 +n07867616 701 +n07808587 711 +n07807834 711 +n07806633 711 +n07807171 711 +n07807710 711 +n07807922 711 +n07808904 711 +n07806774 762 +n07807472 762 +n07841639 712 +n07841800 712 +n07695965 714 +n07712748 714 +n07712559 714 +n07697825 771 +n07697313 771 +n07696728 771 +n07696625 771 +n07698543 771 +n07698401 771 +n07865105 771 +n07696977 771 +n07698250 771 +n07698782 771 +n07697100 771 +n07696839 771 +n07697537 771 +n07712856 772 +n07712959 772 +n07579575 598 +n07579787 598 +n07609840 598 +n07581346 598 +n07611991 791 +n07613266 791 +n07611358 791 +n07612632 791 +n07612996 791 +n07613480 791 +n07611267 791 +n07612367 791 +n07611148 791 +n07611046 791 +n07617611 791 +n07612137 791 +n07616386 795 +n07631926 795 +n07615774 795 +n07616487 795 +n07614730 795 +n07614500 795 +n07614198 795 +n07616748 795 +n07616046 795 +n07617051 795 +n07615671 810 +n07615190 810 +n07614825 810 +n07615460 810 +n07617708 796 +n07618432 796 +n07582152 792 +n07734879 792 +n07581775 792 +n07582277 792 +n07730320 792 +n07581249 792 +n15089645 600 +n15089472 600 +n15093137 827 +n15093298 827 +n15090742 827 +n15091473 831 +n14919819 831 +n15091669 831 +n14810561 831 +n14973585 831 +n15091304 831 +n15091846 831 +n15092227 828 +n15090065 828 +n07576438 602 +n07577374 602 +n07575984 602 +n07574602 602 +n07574426 602 +n07593199 602 +n07576182 602 +n07574923 602 +n07574780 602 +n07575726 602 +n07575076 602 +n07578093 602 +n07576577 841 +n07577144 853 +n07576781 853 +n07574504 842 +n07577538 842 +n09335240 2 +n00027167 2 +n09334396 2 +n09283193 2 +n03892891 2 +n09287968 2 +n03059685 2 +n00003553 2 +n09300905 2 +n09452395 858 +n09260907 858 +n08630039 859 +n08630985 859 +n09386842 859 +n08593262 859 +n08620061 859 +n09379111 859 +n08649711 869 +n08658309 869 +n08568978 869 +n08512259 877 +n03823111 877 +n04170933 878 +n09433839 878 +n08578517 870 +n08640739 870 +n08574314 870 +n08552138 870 +n08645104 884 +n08505018 884 +n08659861 884 +n08659446 884 +n08673395 884 +n08583455 890 +n08598301 890 +n08651247 890 +n03120491 890 +n02802544 890 +n08614632 890 +n08674739 890 +n08569998 890 +n08494231 890 +n08677424 892 +n08616050 892 +n08518171 893 +n08573842 893 +n08521623 893 +n03368352 897 +n03417345 897 +n04454908 906 +n03902482 906 +n04610879 898 +n08579352 898 +n03963645 909 +n03417749 909 +n08524735 885 +n08537837 885 +n08551296 885 +n08628141 914 +n08633683 914 +n08539072 914 +n09249034 871 +n09263912 871 +n08583292 872 +n09443281 872 +n08547544 872 +n08664443 873 +n04602044 873 +n08580944 873 +n03581125 924 +n08517676 924 +n08598568 924 +n08584914 924 +n03899933 925 +n02776631 925 +n03322099 925 +n03935234 933 +n04052442 933 +n03159535 933 +n15102894 874 +n09242389 874 +n09382099 860 +n09282208 860 +n09392402 860 +n09393605 860 +n09445289 860 +n03030880 862 +n03946162 862 +n03485997 862 +n03882960 946 +n04322026 946 +n03474896 946 +n02764398 946 +n02907082 946 +n03948830 946 +n09205509 863 +n09472413 863 +n09443453 863 +n09309292 863 +n09366017 863 +n09366317 863 +n09376786 863 +n09348460 863 +n09246464 863 +n09433442 863 +n09454153 863 +n09409752 863 +n09403734 863 +n09331251 863 +n09437454 863 +n09238926 863 +n09283866 863 +n09217230 863 +n09305898 955 +n09288635 955 +n09308743 956 +n09308572 956 +n09194227 956 +n09289331 956 +n09468604 957 +n09344324 957 +n09335809 957 +n09435739 957 +n09215437 957 +n09259219 957 +n09217638 957 +n09304750 957 +n09206896 977 +n09405787 977 +n09233446 986 +n09290444 986 +n09457979 981 +n09245515 981 +n09376526 983 +n09415671 983 +n09448690 983 +n09230041 984 +n09398076 984 +n09453008 958 +n09303008 958 +n09359803 958 +n09302616 958 +n09409512 958 +n09399592 958 +n09199101 997 +n09230202 997 +n09283405 997 +n09326662 997 +n09193705 998 +n09218641 998 +n09472597 998 +n09421951 1000 +n09270735 1000 +n09406793 1000 +n09213434 1000 +n09256479 1011 +n09210862 1011 +n09421799 1012 +n09224725 1012 +n09396465 1001 +n09362945 1001 +n09259025 961 +n09398677 961 +n09428293 962 +n09447666 962 +n09332890 962 +n08596076 1021 +n09428628 1021 +n09361517 967 +n09265620 967 +n09303528 967 +n09436444 967 +n09274152 967 +n09213565 967 +n09269472 967 +n09206985 967 +n09228055 967 +n09466678 967 +n09415584 1031 +n09475925 1031 +n09257843 968 +n09239302 968 +n09294877 968 +n00021939 865 +n00004258 865 +n00019128 865 +n02749953 865 +n02852523 1041 +n03767112 1041 +n14977504 1041 +n03129123 1041 +n03848729 1041 +n03964744 1041 +n04362025 1041 +n04469003 1041 +n04341686 1041 +n03575240 1041 +n03873064 1041 +n03122748 1041 +n03309808 1041 +n02871147 1041 +n03364340 1041 +n14786479 1041 +n03169390 1041 +n04564698 1041 +n04339291 1041 +n00022903 1041 +n03315023 1041 +n03302121 1041 +n03076708 1041 +n04188643 1041 +n03354613 1041 +n14976871 1041 +n03670849 1041 +n02917521 1045 +n04414909 1045 +n04435180 1045 +n02725872 1045 +n04076846 1048 +n02743547 1048 +n03816849 1048 +n04007894 1048 +n03934656 1076 +n03720163 1076 +n04227144 1076 +n04260364 1076 +n03925226 1076 +n04564581 1076 +n02744844 1084 +n04042358 1084 +n03927091 1084 +n03927539 1084 +n03876519 1077 +n04485423 1077 +n03835197 1090 +n03342127 1090 +n04246271 1078 +n04321238 1078 +n04180314 1095 +n03625783 1095 +n03684611 1096 +n03514693 1096 +n03421485 1097 +n04026180 1097 +n02870526 1079 +n04599396 1079 +n06415688 1079 +n03822171 1079 +n04582205 1103 +n03727605 1103 +n03849679 1103 +n04598792 1103 +n03631922 1103 +n02933649 1109 +n03600722 1109 +n03169176 1049 +n03418618 1049 +n02727016 1049 +n03526198 1049 +n03794798 1049 +n03859608 1049 +n03968581 1116 +n03717447 1116 +n03614782 1116 +n03915900 1116 +n04431025 1116 +n03974070 1050 +n02779435 1050 +n03941231 1050 +n04399382 1050 +n03603442 1050 +n09229709 1050 +n03548402 1050 +n03944138 1050 +n04238128 1050 +n04284869 1050 +n03061211 1050 +n03219135 1050 +n09282724 1129 +n09191635 1129 +n09443641 1136 +n04186268 1136 +n03447358 1135 +n03607029 1135 +n03536348 1051 +n02857023 1051 +n04381860 1051 +n04213626 1051 +n03961939 1142 +n04394630 1142 +n03365592 1142 +n04501550 1146 +n04296562 1146 +n03159640 1146 +n04354182 1146 +n03549732 1146 +n03360300 1148 +n03892178 1148 +n02768973 1143 +n03906224 1143 +n03313333 1145 +n02990373 1145 +n02861886 1053 +n03365991 1053 +n02898711 1053 +n03109693 1053 +n13898207 1053 +n04358874 1053 +n02687821 1053 +n03135532 1053 +n03545756 1053 +n03548626 1053 +n03469175 1053 +n03688943 1053 +n02914991 1053 +n04191595 1053 +n09218315 1053 +n03074380 1053 +n02699494 1053 +n02733524 1053 +n04460130 1053 +n04471148 1053 +n03792048 1053 +n03388043 1053 +n03837869 1053 +n03321954 1053 +n02733213 1053 +n03687137 1053 +n03065424 1053 +n02839110 1053 +n03894379 1053 +n03725717 1053 +n04226464 1053 +n03071160 1053 +n03839993 1053 +n02913152 1053 +n04128413 1053 +n04008947 1053 +n03917198 1053 +n03222318 1053 +n04295881 1053 +n03241335 1053 +n02735688 1053 +n02777734 1053 +n03984381 1053 +n03216828 1053 +n03517899 1053 +n03546340 1053 +n04361095 1053 +n13897996 1053 +n03171356 1053 +n03290195 1053 +n03743902 1053 +n03297735 1053 +n04217882 1053 +n02863426 1160 +n03408054 1160 +n03463381 1161 +n03758089 1161 +n03686130 1161 +n02800497 1161 +n03379828 1162 +n03233744 1162 +n02953197 1162 +n04108822 1162 +n03865557 1162 +n04492749 1162 +n04532670 1162 +n04311004 1162 +n03122073 1162 +n03415486 1162 +n04366367 1162 +n04479939 1162 +n03956922 1172 +n03069752 1172 +n04592465 1231 +n03316406 1231 +n03212811 1231 +n03844673 1231 +n04068441 1231 +n04103094 1234 +n03387653 1234 +n04311595 1234 +n03697007 1234 +n04300358 1234 +n04032603 1242 +n02810782 1242 +n03492250 1173 +n03826186 1173 +n03547054 1173 +n04411264 1173 +n03550153 1173 +n03560430 1173 +n03254189 1173 +n03792972 1248 +n04025508 1248 +n03900979 1248 +n02769963 1248 +n03374473 1248 +n02954163 1248 +n03334291 1257 +n04549028 1257 +n03035252 1257 +n03448956 1177 +n04113765 1177 +n03975035 1177 +n04486054 1177 +n02905152 1177 +n03784896 1262 +n04104384 1262 +n02946127 1178 +n04501947 1178 +n03047052 1178 +n04206790 1178 +n03029197 1178 +n03767745 1178 +n04028581 1178 +n04220250 1178 +n04556948 1178 +n04479823 1178 +n04028764 1178 +n04312432 1178 +n03347617 1178 +n03519387 1178 +n04361260 1178 +n03098959 1178 +n02826886 1178 +n02814860 1178 +n02922292 1180 +n04251701 1180 +n04051825 1180 +n03390786 1288 +n02811936 1288 +n02699770 1188 +n04546855 1188 +n03409393 1292 +n04544325 1292 +n02755823 1292 +n03904657 1293 +n02825961 1293 +n02898369 1189 +n04326799 1189 +n02796623 1192 +n03839795 1192 +n03967942 1192 +n03659686 1192 +n03454707 1300 +n04127395 1300 +n03795580 1300 +n02788148 1300 +n02894605 1300 +n03459775 1300 +n04571566 1300 +n04047401 1300 +n03549589 1300 +n04304680 1300 +n03327234 1300 +n03160309 1300 +n03427296 1306 +n03221720 1306 +n03698815 1316 +n03985881 1316 +n04501370 1316 +n03395514 1317 +n02963821 1317 +n04153025 1317 +n03394649 1317 +n03226880 1317 +n03579538 1317 +n04239074 1317 +n04086446 1317 +n02793842 1317 +n03498662 1317 +n04329834 1317 +n04547592 1314 +n04082710 1314 +n04046974 1314 +n03000134 1314 +n03252637 1314 +n03511175 1314 +n04604644 1314 +n03930313 1314 +n04326547 1314 +n04560882 1301 +n02920369 1301 +n03262072 1302 +n03108853 1302 +n04390977 1302 +n03999160 1193 +n03542333 1193 +n04409384 1193 +n02666943 1193 +n02726681 1193 +n02763604 1193 +n03478756 1193 +n03545150 1193 +n04104500 1193 +n04081699 1193 +n03859280 1193 +n03402941 1193 +n03739518 1193 +n03542605 1193 +n03661043 1193 +n02977936 1193 +n03322570 1193 +n03953416 1193 +n04081281 1193 +n03770316 1193 +n04112654 1193 +n03839671 1193 +n03842012 1193 +n04407686 1193 +n04217546 1193 +n03449564 1193 +n03457902 1193 +n04093625 1193 +n03956157 1193 +n04018399 1193 +n02882190 1193 +n03544360 1193 +n04118635 1193 +n02734725 1193 +n04233124 1193 +n03430418 1193 +n04146050 1193 +n03007444 1193 +n04417809 1193 +n03479397 1193 +n03092166 1193 +n02993546 1193 +n04080705 1347 +n08640531 1347 +n03788498 1347 +n08560295 1347 +n04095109 1347 +n04229737 1347 +n03541696 1347 +n03790755 1347 +n03036022 1352 +n03466839 1352 +n03698723 1352 +n03333610 1353 +n03837698 1353 +n03121298 1353 +n04187547 1356 +n03416489 1356 +n02968074 1356 +n03860404 1356 +n03055857 1356 +n02859443 1402 +n04598318 1402 +n02727426 1402 +n03730334 1358 +n03210552 1358 +n04294879 1362 +n03016389 1362 +n03123809 1362 +n02793495 1362 +n03884778 1363 +n03028079 1363 +n04407435 1363 +n04210390 1363 +n04346328 1363 +n03724756 1363 +n04374735 1363 +n03788195 1363 +n03007130 1363 +n03618982 1417 +n02667576 1417 +n02984061 1417 +n02984203 1417 +n03772077 1417 +n02935658 1364 +n04111414 1364 +n02760099 1364 +n02892499 1364 +n02935891 1364 +n03199647 1364 +n02956699 1371 +n03282295 1371 +n04461437 1371 +n03005033 1371 +n03152303 1371 +n04305210 1371 +n03121431 1371 +n03558176 1373 +n03557360 1373 +n02696165 1375 +n03393017 1375 +n04258438 1377 +n02919792 1377 +n04115256 1377 +n02932400 1377 +n03257210 1377 +n03719053 1377 +n03685820 1377 +n03428090 1377 +n03686924 1377 +n04131368 1377 +n03118969 1377 +n03219483 1377 +n04052658 1377 +n02857477 1377 +n03180865 1377 +n04535524 1377 +n03002816 1377 +n04079244 1377 +n03322836 1377 +n04413969 1449 +n02907873 1449 +n03878066 1452 +n04305323 1452 +n03718458 1452 +n04354026 1457 +n03158186 1457 +n04535370 1457 +n03010915 1457 +n03718935 1464 +n04073948 1464 +n03439348 1464 +n03892557 1464 +n03877845 1464 +n03781244 1476 +n02667379 1476 +n02667478 1476 +n03165616 1382 +n03092314 1382 +n03801671 1382 +n03849814 1384 +n03801533 1384 +n03032252 1384 +n03678729 1384 +n03529860 1384 +n03097362 1387 +n04177931 1387 +n02940385 1387 +n03111041 1195 +n03064935 1195 +n03626115 1195 +n02838728 1195 +n03356858 1195 +n02902079 1195 +n04439585 1195 +n03263076 1195 +n04453037 1195 +n03942920 1195 +n03379204 1198 +n03522003 1198 +n03220692 1198 +n02782778 1198 +n02918112 1198 +n02704949 1198 +n03899768 1200 +n03109881 1200 +n02775178 1200 +n03517647 1200 +n03024064 1200 +n02894158 1200 +n04030518 1200 +n03004824 1200 +n02758134 1200 +n03120198 1200 +n03200231 1200 +n04105893 1200 +n02750070 1200 +n03285912 1200 +n03813078 1200 +n02694045 1200 +n04328946 1200 +n03443005 1200 +n03378005 1519 +n02754656 1519 +n03047941 1519 +n03382292 1519 +n04446276 1521 +n04356925 1521 +n03288500 1521 +n04363991 1521 +n04112579 1521 +n03038685 1521 +n03412058 1521 +n03718581 1521 +n02991302 1521 +n03691817 1521 +n04139395 1521 +n03238131 1521 +n02839592 1521 +n02824319 1521 +n03619890 1521 +n03660909 1521 +n04329477 1521 +n04602762 1521 +n04180229 1521 +n02710324 1521 +n03200701 1521 +n04065464 1521 +n03541091 1521 +n04058096 1521 +n02873839 1521 +n03089879 1521 +n02821627 1521 +n03040376 1521 +n03679712 1521 +n03222176 1521 +n03478907 1521 +n04061793 1521 +n02857644 1521 +n04345028 1521 +n03683708 1521 +n03062122 1521 +n04406239 1521 +n03079741 1521 +n03120778 1521 +n03982331 1521 +n02807731 1521 +n03098688 1521 +n02715513 1521 +n04558478 1532 +n03746486 1532 +n04555291 1532 +n04018667 1532 +n03529175 1537 +n03653740 1537 +n04345201 1537 +n03885535 1548 +n04324387 1548 +n04523831 1548 +n04067818 1552 +n03200539 1552 +n02952585 1553 +n03319745 1553 +n04119478 1553 +n03283221 1554 +n04064862 1554 +n03850245 1554 +n04401680 1556 +n04541987 1556 +n03090172 1556 +n04209613 1556 +n03727465 1558 +n03788601 1558 +n03465718 1558 +n03542860 1558 +n03225108 1558 +n03836062 1558 +n03165466 1558 +n03457008 1562 +n03086580 1562 +n03878211 1562 +n03303831 1562 +n03891538 1563 +n03235042 1563 +n04000592 1569 +n03075946 1569 +n02932019 1569 +n03939677 1569 +n02931148 1569 +n03696065 1569 +n02933462 1569 +n03061505 1569 +n04305572 1569 +n02960352 1569 +n02934451 1569 +n04299370 1569 +n03235180 1569 +n04414199 1523 +n02936714 1523 +n03964495 1523 +n03907227 1523 +n04539203 1523 +n03993703 1523 +n03683079 1523 +n03016737 1523 +n03003730 1523 +n04061969 1523 +n02843276 1624 +n04037220 1624 +n03550289 1624 +n03124590 1626 +n04100519 1626 +n03376159 1626 +n04262161 1631 +n02921884 1631 +n03348868 1631 +n04080454 1631 +n03404449 1631 +n02868638 1631 +n03555006 1631 +n04076713 1640 +n03732114 1640 +n03617095 1643 +n02849885 1643 +n03837606 1643 +n03425325 1643 +n03566193 1643 +n03762434 1632 +n03073694 1632 +n03343560 1632 +n03346455 1632 +n02731398 1632 +n02991847 1526 +n03148324 1526 +n04295571 1526 +n03411544 1201 +n02705201 1661 +n03854722 1661 +n04327204 1202 +n04355267 1202 +n03399677 1202 +n04527648 1202 +n03168107 1202 +n02770211 1202 +n03986704 1202 +n03721590 1203 +n03251533 1203 +n02853016 1205 +n03259505 1205 +n04409625 1205 +n03679384 1205 +n03776460 1205 +n03088389 1205 +n02726305 1205 +n04549919 1673 +n02992032 1673 +n03088580 1674 +n04613696 1674 +n03685307 1674 +n04517408 1674 +n03507241 1674 +n03354207 1674 +n03042490 1674 +n03529629 1674 +n04172107 1674 +n04584373 1684 +n04412416 1684 +n02672371 1676 +n03349892 1693 +n02932693 1693 +n02822064 1679 +n03361297 1679 +n03010473 1206 +n04360501 1206 +n03391770 1206 +n03903868 1699 +n02929289 1699 +n03373943 1699 +n02669295 1699 +n04087826 1700 +n02926591 1700 +n04589593 1700 +n03390983 1700 +n03416094 1700 +n03530642 1700 +n04492375 1700 +n03646916 1700 +n03111296 1700 +n03931765 1700 +n04587648 1700 +n03042697 1700 +n04478512 1700 +n02689144 1700 +n03454536 1700 +n03453443 1700 +n04545305 1700 +n02977619 1700 +n04387261 1700 +n02732827 1700 +n04038727 1700 +n03793186 1700 +n04136510 1700 +n02976350 1700 +n03855333 1715 +n02813399 1715 +n04297750 1715 +n04232800 1715 +n03211789 1715 +n04110178 1715 +n03986562 1715 +n04473108 1715 +n03041810 1715 +n03224603 1715 +n03224753 1715 +n03637898 1715 +n03320959 1715 +n03961711 1725 +n02790669 1725 +n02835829 1725 +n03696301 1725 +n03207630 1725 +n04459773 1725 +n03896526 1726 +n03900393 1726 +n03792526 1726 +n04340935 1208 +n03386011 1208 +n03385557 1208 +n02806088 1751 +n03610098 1751 +n03628511 1754 +n02676938 1754 +n02695627 1752 +n03723781 1752 +n03334382 1753 +n02805983 1753 +n03296328 1753 +n03878963 1753 +n02980441 1753 +n02993194 1210 +n03743016 1210 +n04178329 1210 +n02892201 1210 +n03810952 1210 +n03884926 1210 +n03220237 1766 +n03745571 1766 +n03953020 1211 +n03574555 1211 +n04511002 1211 +n03748162 1773 +n03841666 1773 +n02931417 1773 +n03506370 1773 +n03965456 1776 +n03119203 1776 +n03176763 1776 +n04202417 1776 +n03722288 1776 +n02879309 1783 +n04131208 1783 +n04200800 1783 +n02871525 1783 +n03871371 1783 +n04428634 1783 +n03606251 1783 +n04462240 1783 +n03039827 1783 +n02813544 1783 +n03436417 1783 +n03367410 1783 +n03249342 1783 +n03416640 1783 +n03173387 1783 +n04245508 1783 +n02791270 1783 +n04299215 1783 +n04443257 1783 +n03822656 1783 +n02927161 1783 +n03952576 1783 +n03089624 1783 +n03099274 1783 +n02813645 1784 +n08492461 1784 +n03461385 1784 +n03847823 1784 +n04358707 1811 +n03555426 1811 +n03457686 1811 +n04261281 1812 +n03322704 1812 +n08571898 1812 +n03822504 1777 +n02885882 1777 +n03504723 1777 +n03111690 1774 +n03856012 1774 +n03592245 1822 +n03911513 1822 +n04005630 1822 +n04447443 1054 +n04566257 1054 +n03294048 1054 +n03091374 1054 +n03563967 1054 +n03405265 1054 +n03183080 1054 +n02997391 1054 +n04377057 1054 +n03094503 1054 +n03100490 1054 +n06254669 1054 +n03176594 1827 +n02807523 1827 +n03128519 1827 +n03690938 1827 +n04186051 1827 +n03476991 1827 +n03794136 1827 +n03916031 1827 +n03475823 1827 +n02723165 1827 +n03994008 1827 +n03113152 1827 +n02808185 1827 +n03484487 1841 +n03067339 1841 +n04357314 1841 +n03640850 1841 +n02862916 1842 +n04450640 1842 +n03487444 1842 +n02683791 1842 +n03992325 1846 +n03898271 1846 +n03916470 1846 +n03071021 1846 +n04448070 1846 +n03980026 1847 +n02901793 1847 +n04447276 1849 +n04386792 1849 +n03177165 1850 +n03519081 1850 +n03714235 1850 +n03314780 1871 +n03676087 1871 +n03309687 1871 +n03724066 1871 +n03676483 1871 +n04112752 1871 +n03309110 1871 +n03308481 1871 +n02738031 1828 +n03171228 1828 +n02866578 1828 +n02703275 1828 +n03812924 1828 +n02813752 1880 +n02746365 1880 +n03647520 1880 +n02950256 1886 +n03332393 1886 +n03786715 1888 +n02801450 1888 +n03553248 1882 +n02753044 1882 +n04113641 1883 +n04206570 1883 +n04063373 1829 +n04285146 1829 +n03926148 1829 +n03811847 1829 +n03889726 1829 +n03430959 1829 +n04137444 1829 +n03414162 1829 +n03888257 1829 +n03278248 1829 +n02727825 1829 +n02761206 1829 +n03729951 1829 +n02774921 1829 +n04393095 1896 +n02979290 1896 +n03192543 1910 +n04533802 1910 +n02799897 1897 +n03135030 1897 +n03039259 1897 +n04225729 1897 +n04607035 1897 +n03132261 1897 +n02802721 1897 +n03594148 1897 +n04212282 1897 +n03446832 1897 +n04275661 1897 +n04318131 1897 +n02885338 1897 +n02885462 1897 +n03472232 1897 +n04571292 1897 +n02800213 1914 +n02811059 1914 +n02811204 1914 +n02797881 1914 +n02811350 1914 +n02799175 1914 +n03528901 1933 +n03349771 1933 +n04425804 1933 +n04164406 1933 +n04102037 1917 +n04102162 1917 +n04102618 1917 +n03558404 1917 +n03523987 1943 +n04273972 1943 +n03336282 1943 +n03132076 1919 +n04582869 1919 +n03445924 1923 +n03447075 1923 +n04399537 1923 +n03446070 1923 +n04597066 1952 +n03585073 1952 +n03244047 1953 +n04284341 1953 +n04569822 1954 +n03762332 1954 +n04028074 1954 +n03823216 1954 +n03950537 1957 +n04135024 1957 +n03524150 1925 +n03978686 1925 +n03535780 1928 +n03538037 1928 +n04509260 1928 +n03888605 1928 +n04469514 1928 +n02777292 1928 +n04524142 1966 +n03980478 1966 +n03255030 1929 +n02790996 1929 +n03289660 1898 +n02942699 1898 +n03037404 1898 +n03338821 1898 +n03667664 1898 +n02884994 1976 +n03358726 1976 +n03976467 1976 +n03974915 1976 +n04569063 1976 +n03789171 1976 +n03196062 1976 +n03987266 1976 +n04069434 1976 +n04609531 1978 +n04067658 1978 +n03817191 1978 +n04071263 1901 +n03619396 1901 +n04091097 1901 +n03351434 1901 +n04295081 1901 +n04091693 1901 +n03138669 1992 +n03139464 1992 +n04179824 1993 +n03349469 1993 +n02966687 1993 +n03650551 1993 +n03241093 1994 +n03240683 1994 +n03494706 1996 +n04247876 1996 +n03503718 1996 +n04124202 1996 +n03480719 2008 +n02900160 2008 +n04290615 1902 +n04266162 1902 +n02768226 1903 +n02778669 1903 +n04028315 1903 +n03982430 1903 +n02882647 1903 +n03716327 1903 +n03020416 1903 +n04113406 1903 +n03442756 1903 +n04540255 1903 +n03941417 1903 +n04254680 2015 +n03982232 2015 +n02882301 2015 +n04256891 2015 +n03333252 2015 +n04023962 2015 +n02839351 2015 +n03134739 2015 +n03131967 2015 +n04409515 2015 +n03445777 2015 +n04118538 2015 +n03145719 2015 +n03742019 2015 +n02802426 2015 +n03267113 2015 +n03942813 2015 +n03482877 2015 +n02799071 2015 +n04039742 2015 +n02861147 2015 +n04540053 2015 +n03598930 2016 +n06785654 2016 +n03014440 2019 +n04579986 2019 +n03901750 2019 +n02802215 2022 +n03820318 2022 +n03278914 1905 +n03782006 1905 +n03781787 1905 +n04405762 1905 +n04401088 1905 +n03857828 1905 +n03916720 1905 +n02872529 1905 +n02979186 1905 +n02988304 1905 +n04060647 1905 +n02757462 1905 +n03656957 1905 +n03963294 1905 +n04405540 1905 +n03034405 1905 +n02979074 1905 +n02995345 1905 +n03775388 1905 +n04142731 1905 +n04392985 1905 +n03181293 1905 +n03777754 1905 +n03293741 1905 +n04392526 1905 +n02705944 1905 +n02992529 2058 +n04270371 2058 +n03179910 2058 +n03902125 2058 +n03488438 2058 +n03187595 2058 +n04044498 2058 +n04405907 2064 +n04043733 2064 +n04137773 2064 +n03516996 2088 +n03046921 2088 +n04077430 2065 +n03517760 2092 +n04315948 2092 +n03584254 2094 +n04546340 2094 +n03584400 2094 +n03436182 2094 +n02942349 2068 +n04404997 2068 +n03909160 1906 +n04026053 1906 +n04173511 1906 +n04070003 1906 +n03257586 1906 +n03509608 1906 +n04171208 1906 +n04450243 1906 +n04506506 1906 +n03434188 1906 +n03567066 1906 +n02923129 1906 +n03386544 2101 +n03046802 2101 +n03757604 2101 +n03927299 2105 +n03924679 2105 +n04608923 2105 +n03316105 2105 +n03767459 2105 +n03987990 2108 +n03084834 2108 +n03422072 2112 +n02855390 2112 +n02921029 2123 +n03425769 2123 +n03871524 1908 +n02852360 1908 +n04105704 1908 +n04408871 1830 +n04241573 1830 +n04402057 1830 +n03664943 1830 +n03605915 1830 +n03543012 2132 +n03196990 2132 +n03639497 2132 +n02840134 2133 +n04594218 2133 +n02999410 2133 +n03086868 2139 +n02790823 2139 +n03886641 2140 +n02709637 2140 +n03374838 2140 +n02835412 2140 +n04440963 2140 +n03011018 2140 +n03600977 2134 +n03093792 2134 +n03228967 2149 +n04573281 2149 +n03521076 2149 +n04144241 2149 +n04571958 2149 +n04160372 2149 +n03787523 2149 +n02928299 2153 +n04333869 2153 +n03213826 2150 +n04476972 2150 +n04593866 2150 +n02788689 1831 +n04451818 1831 +n04516672 1831 +n04116512 1831 +n03816136 1831 +n03294833 1831 +n04317420 1831 +n02908217 1831 +n03532342 1831 +n04185071 1831 +n04285622 1831 +n03653220 1831 +n04369282 1831 +n03346135 1831 +n03837422 1831 +n04317833 1831 +n03039947 1831 +n04100174 1831 +n04608567 1831 +n04208427 1831 +n04282872 2163 +n03396074 2163 +n02865931 2163 +n04112147 2163 +n04459909 2163 +n03659292 2163 +n04463679 2163 +n03487090 2163 +n03138344 2188 +n04317976 2188 +n03613592 2188 +n04393808 2188 +n03903424 2188 +n04099003 2188 +n03470629 2188 +n04264628 2193 +n02771004 2193 +n04193377 2193 +n04400737 2193 +n02670683 2195 +n04367011 2195 +n03489162 2164 +n03588951 2164 +n03919430 2164 +n03418242 2164 +n03967562 2164 +n03075097 2164 +n03239726 2164 +n03154446 2164 +n04387706 2164 +n03417970 2164 +n04050066 2164 +n04299963 2164 +n03684224 2204 +n03919289 2204 +n03970156 2204 +n03941684 2204 +n03966976 2204 +n04258859 2204 +n04266486 2204 +n03481172 2204 +n03946076 2204 +n04606574 2204 +n04154565 2204 +n04489817 2204 +n04140064 2204 +n03848348 2204 +n04150980 2204 +n04208210 2204 +n02898269 2204 +n04269944 2204 +n02966545 2223 +n03430313 2223 +n03715386 2223 +n03731695 2223 +n04457910 2225 +n03947466 2225 +n02680754 2225 +n03848168 2225 +n02697675 2225 +n02886434 2225 +n03474779 2228 +n03376938 2228 +n03488188 2228 +n04016240 2246 +n04016576 2246 +n03109150 2229 +n02877962 2229 +n02951585 2229 +n03511333 2207 +n03649909 2207 +n03995856 2253 +n04089976 2253 +n03995372 2210 +n03240140 2210 +n03154073 2211 +n04503593 2211 +n02844307 2211 +n02848216 2211 +n03624400 2211 +n02866386 2258 +n03030557 2258 +n03265032 2258 +n04148054 2265 +n03623556 2265 +n02764044 2265 +n04057047 2265 +n04594828 2265 +n03020692 2265 +n03954731 2265 +n04186848 2266 +n04250473 2273 +n04016684 2273 +n04163530 2273 +n02973904 2267 +n02880842 2267 +n03973628 2267 +n03041632 2267 +n03549473 2267 +n02976123 2267 +n03890093 2267 +n03658185 2267 +n04373089 2279 +n03911658 2279 +n02811468 2268 +n03498962 2268 +n04185804 2269 +n04332074 2269 +n04127521 2269 +n03067212 2271 +n04597400 2271 +n03601638 2272 +n04247630 2272 +n04283585 2272 +n03621049 2165 +n02997607 2165 +n03403643 2165 +n04103206 2297 +n04059516 2297 +n03724417 2297 +n03621377 2297 +n04293119 2297 +n03775199 2297 +n03101517 2297 +n03101986 2297 +n03454885 2297 +n03767966 2297 +n03266371 2305 +n04578934 2305 +n02850732 2305 +n03880531 2307 +n03133878 2307 +n02999138 2307 +n04270147 2307 +n03459328 2307 +n03284981 2307 +n04309548 2307 +n03101796 2307 +n03101156 2307 +n04500060 2307 +n03846677 2313 +n04317325 2313 +n03400231 2313 +n04097760 2313 +n04596742 2313 +n04138977 2313 +n03453231 2318 +n03047799 2318 +n03984234 2298 +n03262519 2298 +n04326676 2298 +n03992703 2298 +n04282992 2331 +n03018209 2331 +n02869155 2331 +n03713436 2332 +n03317788 2332 +n03625646 2167 +n03133050 2167 +n04546194 2169 +n03729826 2169 +n03053474 2169 +n03332271 2169 +n04277352 2169 +n04321453 2169 +n04296261 2169 +n03250847 2169 +n03715669 2169 +n02949202 2342 +n04374315 2342 +n02806379 2344 +n04381724 2344 +n04491388 2344 +n02698634 2348 +n03355925 2348 +n03141823 2348 +n03274265 2170 +n04453156 2170 +n04122349 2170 +n04156140 2170 +n03475581 2170 +n02902687 2170 +n04185946 2170 +n03908714 2172 +n04310904 2172 +n03145522 2173 +n04039381 2173 +n04292414 2369 +n04409806 2369 +n02772700 2369 +n04426316 2174 +n04333129 2174 +n03012013 2374 +n04072551 2374 +n03831382 2374 +n03651843 2374 +n04156946 2177 +n03873416 2177 +n02831894 2179 +n04150153 2179 +n03258905 2179 +n04292921 2179 +n02906734 2179 +n04367480 2179 +n04111190 2180 +n04549629 2180 +n04182322 2180 +n03949317 2180 +n03616428 2180 +n02764779 2180 +n03976657 2180 +n03351979 2180 +n03091044 2180 +n04434531 2180 +n03244231 2387 +n03127408 2387 +n04472563 2387 +n04277493 2387 +n02946824 2387 +n02871824 2393 +n04319937 2393 +n04230603 2393 +n03051396 2393 +n02931836 2393 +n04267577 2393 +n03726993 2393 +n03726760 2407 +n02883004 2407 +n04610676 2407 +n03775847 2409 +n04115996 2409 +n03711999 2409 +n03382856 2409 +n03374372 2394 +n04279353 2394 +n03908204 2181 +n03906997 2181 +n03518943 2181 +n03003091 2181 +n03128248 2181 +n03652100 2181 +n02783161 2419 +n04185529 2419 +n04033901 2419 +n03388183 2419 +n03326948 2419 +n03405725 1832 +n03842156 2429 +n03200906 2429 +n04550184 2429 +n02821943 2429 +n04379243 2429 +n04379964 2429 +n04549122 2429 +n03636649 2429 +n03201035 2429 +n04555400 2429 +n02912065 2429 +n02933112 2429 +n02766320 2429 +n02822579 2429 +n03649797 2429 +n03129753 2429 +n02870880 2429 +n03290653 2429 +n03298716 2429 +n04161981 2429 +n04165409 2429 +n03015254 2429 +n03337140 2430 +n04104147 2452 +n02963302 2452 +n04529681 2452 +n03050546 2432 +n02739550 2432 +n02818832 2433 +n02831724 2458 +n03962852 2458 +n03540914 2458 +n02920083 2458 +n04491638 2458 +n03388549 2458 +n03115762 2458 +n02920259 2458 +n04503413 2458 +n04236809 2458 +n04222210 2458 +n03482252 2458 +n03799876 2458 +n03225988 2458 +n03414676 2434 +n03465426 2434 +n04381587 2434 +n03116530 2434 +n02699629 2434 +n02894337 2434 +n04301000 2434 +n03090000 2434 +n03904060 2434 +n03620967 2434 +n03850492 2434 +n04398951 2434 +n03653583 2434 +n04603729 2434 +n03428226 2434 +n03238586 2434 +n03179701 2434 +n03246933 2434 +n03063968 2434 +n04480033 2434 +n03092883 2434 +n03011741 2476 +n02789487 2476 +n03735963 2476 +n04061681 2476 +n04130143 2495 +n04247736 2495 +n03231368 2486 +n03630262 2486 +n04608329 2489 +n04164868 2489 +n03164722 2489 +n03201208 2435 +n03202354 2505 +n04067921 2505 +n03367059 2437 +n04380533 2437 +n04057981 2437 +n03237340 2441 +n03018349 2441 +n03742115 2441 +n02804414 2442 +n03131574 2442 +n02970534 2442 +n03125729 2442 +n03001627 2449 +n04447861 2449 +n04326896 2449 +n04256520 2449 +n03858418 2449 +n02828884 2449 +n03649674 2518 +n03002711 2518 +n04099969 2518 +n04373704 2518 +n04429376 2518 +n04331277 2518 +n03632729 2518 +n03518445 2518 +n02738535 2518 +n04590933 2518 +n03376595 2518 +n04576002 2518 +n03790953 2518 +n02791124 2518 +n03262932 2532 +n04062428 2532 +n03786621 2532 +n04593077 2532 +n03168217 2534 +n02946270 2534 +n03801880 2520 +n04382438 2520 +n03380724 2520 +n04177755 2521 +n03165096 2521 +n03100346 2521 +n03693474 2521 +n03015149 2549 +n04344873 2549 +n03891251 2523 +n03360622 2523 +n03920867 2523 +n04177820 2523 +n04590021 2523 +n03016953 2451 +n03518305 2451 +n02843553 1833 +n03508101 1833 +n03666591 1833 +n06791372 1833 +n03099945 1833 +n03141702 1833 +n03243218 1833 +n03626760 1833 +n03904909 1833 +n03800933 1833 +n04200537 1833 +n04198797 1833 +n03699975 1833 +n03088707 1833 +n02776205 1833 +n04294212 1833 +n03339643 1833 +n03738472 1833 +n02676261 1833 +n04474466 1833 +n03008976 1833 +n02688443 1833 +n04114844 1833 +n03929660 1833 +n03287351 1833 +n03320046 1833 +n03553019 1833 +n03175604 1833 +n02678897 1833 +n04461879 1833 +n04359589 1833 +n03851341 1833 +n04331639 1833 +n04450749 1833 +n03923918 1833 +n03574816 1833 +n03074855 1833 +n04074963 1833 +n03302790 1833 +n03075768 1833 +n04554406 1833 +n04210120 1833 +n04562262 1833 +n02855089 1833 +n04526964 1833 +n02895606 1833 +n02730265 1833 +n04226826 1833 +n03467796 1833 +n04081844 1833 +n03614007 1833 +n03269401 1833 +n02729965 1833 +n03345837 1833 +n03111899 1833 +n04069276 1833 +n02694426 1833 +n03277771 1833 +n04252331 1833 +n03525827 1833 +n03744840 1833 +n03613294 1833 +n03827536 1833 +n04263760 1833 +n03568117 1833 +n03180969 1833 +n02895438 1833 +n03565288 1833 +n02683558 1833 +n03537241 1833 +n03267972 1833 +n04228054 1833 +n03664675 1833 +n04258333 2561 +n03272239 2561 +n04041069 2561 +n03423479 2561 +n03099147 2561 +n04265275 2561 +n04330267 2561 +n03031422 2562 +n03728437 2562 +n07273802 2563 +n06793231 2563 +n06794110 2563 +n06874185 2563 +n03269203 2564 +n02981321 2564 +n03582959 2646 +n04375405 2646 +n03307792 2566 +n02988963 2566 +n03580518 2566 +n04338517 2569 +n03279153 2569 +n03614532 2569 +n04586932 2569 +n02803349 2569 +n03915437 2569 +n03254862 2653 +n03025886 2653 +n02787622 2653 +n04615226 2653 +n04132603 2653 +n03467517 2653 +n02880546 2653 +n04224842 2653 +n03698360 2660 +n03716887 2660 +n03716966 2660 +n03495258 2660 +n02676566 2664 +n03499907 2664 +n04506289 2664 +n03272010 2664 +n04536153 2665 +n04536866 2665 +n02992211 2665 +n04536335 2665 +n04536595 2665 +n04330998 2665 +n04419642 2654 +n03273551 2654 +n04376400 2654 +n03928116 2655 +n03039015 2655 +n03854065 2655 +n02672831 2655 +n03452741 2684 +n04515003 2684 +n04278353 2684 +n03738066 2684 +n02766792 2688 +n03086457 2688 +n03496296 2685 +n04278247 2685 +n03840681 2656 +n04598582 2656 +n02891788 2656 +n03854815 2656 +n03393324 2656 +n04579667 2656 +n03945615 2656 +n03609397 2656 +n03372029 2697 +n02817799 2697 +n03228016 2705 +n04222847 2705 +n02804610 2706 +n03838899 2706 +n03037709 2707 +n04141076 2707 +n02793089 2698 +n02912894 2698 +n03369276 2698 +n03394916 2698 +n04487394 2698 +n03110669 2698 +n03494537 2700 +n03494278 2700 +n03086670 2700 +n03006626 2702 +n03884397 2702 +n02775483 2702 +n03343354 2702 +n03912218 2702 +n03245724 2702 +n02803934 2657 +n02804252 2657 +n02804123 2657 +n03301568 2657 +n03483230 2658 +n02869249 2658 +n03447721 2658 +n04532831 2658 +n04311174 2658 +n03721384 2658 +n03440682 2658 +n03017168 2658 +n03612965 2658 +n03720891 2658 +n03249569 2658 +n03157348 2658 +n02869737 2741 +n02803666 2741 +n04387400 2741 +n04249415 2741 +n04410086 2741 +n04243941 2572 +n03996416 2572 +n03999992 2572 +n02769290 2572 +n04004475 2572 +n03702248 2572 +n03789946 2572 +n04252653 2572 +n02977058 2572 +n03322940 2572 +n03082979 2572 +n04613939 2572 +n03765561 2572 +n04303357 2572 +n03997484 2572 +n03087069 2572 +n04303497 2572 +n04237423 2572 +n04417180 2572 +n04064401 2572 +n02938886 2572 +n04525305 2748 +n04243546 2748 +n02760199 2748 +n03418915 2750 +n02829596 2750 +n03551395 2750 +n04024274 2750 +n03007591 2752 +n03563200 2752 +n04004767 2752 +n03250405 2752 +n03672827 2752 +n03643737 2752 +n03675235 2752 +n04419868 2752 +n03985069 2776 +n04505036 2776 +n02794664 2777 +n04595285 2777 +n03225777 2778 +n02909285 2788 +n03571942 2788 +n04184435 2753 +n03240892 2753 +n03460040 2753 +n03646296 2791 +n03766044 2791 +n03287733 2754 +n03273061 2754 +n03507963 2796 +n03596285 2796 +n02761557 2796 +n02687423 2796 +n03433877 2796 +n04309049 2798 +n03579982 2798 +n04591517 2804 +n03424630 2804 +n03193107 2804 +n03859000 2804 +n04040373 2804 +n04099175 2799 +n03321103 2799 +n02872333 2810 +n04265904 2810 +n02700064 2802 +n04587404 2802 +n04304375 2797 +n03616763 2797 +n03146846 2757 +n03500699 2757 +n03075634 2757 +n04428191 2757 +n03496892 2757 +n03210245 2818 +n03496612 2818 +n04238763 2758 +n06359193 2758 +n03528523 2758 +n04175147 2758 +n03196324 2758 +n04358117 2829 +n04603399 2829 +n03918480 2829 +n03985232 2832 +n03180011 2832 +n03832673 2833 +n03956785 2833 +n03642806 2833 +n03485407 2833 +n03914337 2760 +n04561422 2760 +n03736064 2760 +n03063485 2760 +n04477219 2760 +n04587559 2760 +n03272125 2762 +n03996145 2762 +n02911332 2762 +n03034663 2846 +n03000684 2846 +n04380916 2846 +n04121728 2846 +n02786837 2846 +n04279462 2766 +n03689157 2766 +n03604156 2767 +n03452267 2767 +n02666196 2768 +n02679257 2768 +n03483823 2768 +n04171831 2573 +n04594489 2573 +n03106898 2573 +n03510244 2573 +n02934168 2573 +n03760310 2860 +n04471632 2860 +n03666362 2860 +n03020034 2860 +n03336575 2861 +n03604843 2861 +n04402984 2861 +n03898129 2861 +n04401828 2861 +n03995265 2862 +n03307037 2862 +n03300443 2864 +n03268918 2864 +n04004990 2864 +n03995535 2864 +n03350602 2574 +n03373237 2880 +n03251932 2881 +n04573937 2881 +n04334365 2881 +n03861271 2575 +n04520784 2575 +n04332243 2576 +n02688273 2576 +n03843555 2576 +n04216634 2887 +n04398834 2887 +n03066849 2887 +n03407865 2577 +n02710201 2577 +n04040759 2577 +n03736970 2577 +n04110955 2577 +n04112430 2577 +n02969010 2577 +n03096960 2577 +n03996849 2577 +n02761392 2577 +n02677718 2577 +n03102859 2577 +n03431243 2577 +n04392764 2577 +n03339529 2577 +n04289027 2896 +n04011827 2896 +n02709367 2896 +n03446268 2896 +n04568069 2896 +n03700963 2896 +n04167346 2896 +n04021798 2896 +n03432129 2896 +n04088797 2896 +n02918595 2896 +n03532672 2896 +n04228215 2896 +n03119510 2896 +n04063154 2896 +n04371774 2896 +n04590746 2896 +n04586581 2896 +n04586421 2896 +n03189083 2896 +n04211528 2896 +n03296081 2896 +n02903204 2896 +n03150232 2896 +n04282494 2896 +n03082807 2896 +n02686227 2896 +n02962200 2896 +n03198500 2896 +n02973017 2896 +n04475411 2896 +n03431745 2896 +n04306592 2896 +n02692086 2909 +n04154152 2909 +n04020298 2913 +n04574999 2913 +n03559999 2913 +n03659809 2913 +n03566329 2913 +n03767203 2944 +n04563204 2944 +n04101701 2944 +n02836035 2944 +n02980036 2944 +n03460147 2944 +n04115144 2944 +n03334912 2944 +n04543772 2944 +n04563413 2944 +n02974003 2944 +n04289690 2944 +n03944341 2944 +n03992509 2944 +n03430551 2944 +n03244919 2944 +n03874293 2944 +n04113194 2944 +n04290507 2962 +n02833793 2962 +n03943115 2962 +n04051549 2947 +n02764505 2947 +n04154340 2947 +n03456299 2915 +n03425413 2915 +n02835724 2915 +n04354487 2915 +n03487886 2915 +n02995871 2915 +n03329302 2917 +n04102406 2917 +n02966193 2917 +n04510706 2921 +n03054901 2921 +n03393761 2982 +n03209359 2982 +n02860415 2926 +n04067472 2926 +n04211857 2926 +n02848523 2897 +n03473227 2897 +n03032811 2897 +n04111668 2897 +n03873699 2988 +n03563460 2988 +n03320421 2988 +n03208556 2990 +n04019541 2995 +n02890188 2995 +n04448361 2995 +n03397947 2995 +n03954393 2995 +n04385799 2991 +n03712111 2991 +n04519153 2900 +n04313503 2900 +n03450018 2900 +n03602883 2900 +n04072193 2900 +n04372370 2900 +n02783459 3003 +n02927887 3003 +n04438507 3005 +n03374649 3005 +n03325088 3007 +n04422875 3007 +n02727141 3007 +n03775636 3013 +n04327682 3013 +n04445952 3008 +n04027023 3008 +n03186818 3008 +n03537412 3019 +n03793850 3019 +n03222516 3019 +n02826589 3019 +n03363549 2903 +n03795758 2903 +n03469493 2903 +n03103396 2904 +n03301833 2904 +n02686379 2904 +n03432061 2905 +n03389611 2905 +n04579432 2578 +n04218564 2578 +n03743279 2578 +n03506560 2578 +n02824448 2578 +n03123917 3037 +n03028596 3037 +n03201529 3037 +n04275548 2579 +n03794056 2579 +n03680858 2579 +n04568557 2579 +n03819994 2579 +n03639077 3045 +n03352628 3045 +n04529962 2581 +n04283255 2581 +n04283096 2581 +n04112252 2581 +n03357716 2581 +n04117464 2581 +n03536122 2581 +n04592741 2581 +n03303217 2585 +n03271574 2585 +n02887079 2587 +n03176386 2587 +n02768114 2590 +n04320973 2590 +n03933933 2590 +n03934042 2590 +n02767433 2590 +n04190052 2590 +n03638883 2590 +n02783994 2590 +n04283378 2590 +n02797692 2590 +n04314914 2590 +n02887209 2590 +n03938401 2590 +n02817031 2590 +n04098513 2590 +n03057920 2590 +n03495570 2590 +n04081044 2590 +n02888569 2590 +n04386051 2590 +n02871005 2590 +n04341414 2590 +n03506184 2590 +n04161358 2590 +n04430475 2590 +n03490884 2590 +n04038440 2590 +n03495039 2590 +n02953455 3064 +n03632577 3064 +n02871439 3065 +n03719343 3065 +n03814639 3071 +n03622839 3071 +n02713003 3071 +n02768655 3071 +n02737660 3077 +n03505133 3077 +n03019685 3077 +n02741475 3077 +n04148579 3078 +n03105467 3078 +n04190376 3078 +n04220036 3081 +n04094720 3081 +n04515129 3081 +n02886599 3081 +n04476831 3081 +n02815950 3081 +n04590263 3103 +n03223686 3103 +n04318787 3105 +n03592773 3105 +n03073977 3105 +n03988170 3105 +n04360798 3113 +n02974348 3113 +n03443149 3114 +n03821518 3114 +n02864593 3114 +n03637181 3114 +n04402449 3114 +n03733131 3114 +n04436329 3114 +n04119751 3106 +n04433585 3106 +n04045644 3108 +n03437941 3108 +n04436185 3108 +n03366974 3108 +n03601840 3108 +n02970685 3083 +n03937931 3083 +n03955489 3083 +n04123740 3083 +n03002096 3083 +n02835915 3083 +n02910145 3083 +n02770830 3083 +n04325041 3134 +n03288886 3134 +n04485082 3086 +n04275175 3086 +n03704549 3086 +n03801760 3086 +n02943871 3141 +n03262809 3141 +n02759257 2591 +n04009801 2591 +n03340723 2591 +n03643253 2591 +n03656484 2591 +n03838298 3151 +n03087366 3151 +n02943241 3151 +n02709101 3151 +n03094159 3151 +n04355933 3151 +n03309465 3151 +n03333711 3151 +n03395859 3151 +n03987376 3154 +n03049782 3154 +n04403413 3154 +n04583212 3154 +n03967396 2595 +n04147495 2595 +n03733925 2595 +n04565375 2595 +n03467068 2595 +n03231160 2595 +n02708711 2595 +n03813176 2595 +n03852280 2595 +n03739693 2595 +n03575958 2595 +n02981911 2595 +n03308152 2595 +n04419073 2595 +n04089836 2595 +n04383015 2595 +n03070193 3166 +n03760944 3166 +n02670382 3166 +n04340521 3166 +n03709206 3166 +n03092656 3166 +n04403638 3185 +n03760671 3185 +n02751295 3187 +n03293863 3187 +n03852688 3189 +n04044716 3189 +n04070207 3191 +n03333129 3191 +n04068601 3191 +n02978478 3195 +n03822767 3195 +n04145863 3195 +n03715114 3195 +n03279508 3188 +n03332989 3188 +n03667829 3188 +n02841506 3202 +n03484931 3202 +n03850053 3202 +n03082280 3202 +n03692522 3202 +n03868643 3167 +n03247083 3167 +n04070415 3167 +n04053508 3167 +n02794156 3167 +n03904782 3167 +n04421872 3167 +n02751215 3167 +n03735637 3167 +n03429288 3167 +n04437953 3167 +n02710600 3167 +n02939866 3167 +n03991837 3167 +n04382880 3167 +n04141975 3167 +n04392113 3167 +n03753077 3167 +n03554460 3167 +n04180888 3167 +n04118776 3167 +n02699915 3167 +n04029734 3214 +n03736470 3214 +n04559730 3217 +n04518343 3217 +n02710429 3217 +n03424862 3217 +n04001499 3217 +n03718335 3236 +n04274985 3236 +n02753394 3218 +n03046257 3218 +n04555897 3218 +n04355338 3218 +n04438304 3218 +n03544143 3218 +n03452594 3240 +n03196217 3240 +n02694662 3240 +n04548280 3240 +n02708093 3240 +n03909406 3240 +n03145147 3240 +n03197337 3241 +n02708433 3241 +n03973839 3241 +n04607869 3241 +n04328186 3243 +n03891332 3243 +n03026907 3243 +n04528968 3220 +n03759661 3220 +n02777100 3223 +n02708555 3261 +n03277459 3261 +n03272810 3225 +n03841143 3225 +n02702989 3225 +n04273796 3225 +n03842986 3225 +n04561287 3225 +n04541320 3225 +n03708843 3225 +n04449966 3168 +n03467984 3168 +n02879718 3168 +n02880393 3168 +n02892948 3168 +n03624134 3168 +n04373894 3168 +n04346157 3168 +n04008634 3168 +n02715712 3273 +n03343853 3273 +n04177041 3273 +n02689274 3273 +n03423306 3273 +n03875955 3273 +n02950826 3273 +n02759963 3282 +n03948459 3282 +n04502851 3282 +n03732020 3282 +n03803116 3282 +n04090263 3282 +n04076284 3282 +n04171459 3288 +n02760429 3288 +n03416775 3295 +n03695857 3295 +n04171629 3295 +n02760855 3296 +n02749479 3296 +n02760658 3296 +n03701391 3296 +n04347519 3303 +n02923682 3304 +n04517211 3304 +n03607659 3304 +n04450133 3304 +n03073296 3289 +n03178674 3289 +n04086273 3289 +n03427202 3289 +n03363749 3292 +n03802007 3292 +n04250224 3293 +n04585980 3293 +n02961451 3293 +n03136369 3274 +n03687928 3274 +n03615790 3277 +n02812949 3277 +n03699591 3277 +n03158885 3277 +n04054361 3278 +n03327691 3278 +n02904640 3278 +n02987492 3278 +n04121511 3325 +n03292475 3325 +n03375575 3325 +n02916350 3280 +n02950943 3280 +n03080633 3170 +n04015908 3170 +n02745611 3172 +n03178000 3172 +n03706229 3172 +n03080497 3172 +n02841315 3173 +n04272054 3173 +n04009552 3173 +n04403925 3173 +n03443912 3340 +n04356056 3340 +n04238617 3341 +n03399761 3341 +n03795976 3341 +n03864692 3341 +n03555662 3174 +n02963503 3174 +n04376876 3174 +n04317175 3174 +n03643149 3174 +n03858183 3174 +n04364545 3174 +n04083800 3355 +n03514451 3355 +n03938037 3175 +n04056180 3175 +n03302671 2598 +n04477387 2598 +n04080833 2605 +n04251144 2605 +n03868863 2605 +n02731629 2605 +n03876231 2606 +n04287747 2606 +n02889646 2609 +n03484576 2609 +n03323703 2609 +n04162706 2609 +n03652932 2609 +n04125853 2609 +n02891188 2609 +n03803284 2609 +n02999936 2609 +n02865665 3370 +n02910353 3370 +n03627232 3370 +n03041114 3370 +n03051249 3370 +n02982599 3370 +n03940256 3370 +n03229244 3370 +n04153751 3370 +n04238321 3370 +n02928608 3370 +n04159354 3370 +n03887185 3370 +n03682487 3370 +n04431745 3370 +n03683606 3370 +n03038281 3370 +n03043958 3370 +n02960690 3370 +n03804744 3370 +n04445327 3370 +n03836451 3370 +n02881906 3379 +n02880189 3379 +n03644858 3382 +n03497352 3382 +n04095342 3383 +n03476313 3383 +n04227900 3383 +n03499354 3383 +n02903126 3383 +n02860640 3383 +n02796318 3383 +n04127249 3383 +n04197781 3387 +n03057541 3387 +n04554871 3388 +n03423719 3388 +n03503477 3414 +n03855604 3414 +n03874599 3390 +n04136800 3390 +n03645011 3390 +n03075370 3390 +n03223162 3390 +n03886762 3394 +n02915904 3394 +n03476684 3394 +n03551084 3374 +n03208938 3425 +n03250089 3425 +n04505470 2610 +n04036303 2610 +n03085013 2610 +n03928814 2610 +n03033362 2611 +n04168199 2611 +n03589513 2611 +n03098140 2611 +n04401949 2611 +n03034244 2611 +n03968293 2611 +n03275681 2611 +n03163222 2611 +n04470953 2611 +n04257986 2611 +n02715229 2611 +n02955247 2611 +n04269270 2611 +n04072960 2611 +n04364160 2611 +n04257790 2611 +n02810471 2611 +n04414675 2611 +n03048883 3432 +n04595855 3432 +n03084420 3432 +n03577090 3453 +n03778817 3453 +n04004210 3453 +n03578656 3453 +n03125057 3456 +n03033986 3456 +n03788047 3441 +n03274561 3441 +n03261776 3461 +n03759954 3461 +n03691459 3461 +n04402580 3462 +n03505667 3462 +n03087816 3463 +n02963692 3463 +n04502670 3464 +n02917377 3464 +n04390873 3464 +n04599124 3464 +n04349401 3464 +n03846772 3443 +n03204955 3443 +n04041747 3474 +n04404817 3474 +n03207305 3475 +n04142999 3475 +n04610274 3475 +n04540547 3449 +n03359285 3481 +n03651388 3481 +n03870980 2614 +n04013729 2614 +n04258138 2615 +n03773035 2615 +n03485198 3487 +n02965783 3487 +n04059947 3489 +n03861842 3489 +n02921756 2616 +n02761834 2616 +n04201064 2616 +n03343737 2616 +n04058594 2617 +n04143140 2617 +n04494204 2617 +n03211117 2617 +n03918737 2617 +n03221351 2617 +n04464615 2617 +n03793489 2617 +n02714751 2617 +n03506727 2617 +n02823124 2617 +n04484432 3498 +n03913343 3498 +n03085219 3499 +n03782190 3499 +n04152593 3499 +n03196598 3499 +n03676759 3499 +n03361380 3499 +n04588739 3499 +n03187268 3499 +n02940570 3499 +n03085602 3511 +n02769075 3511 +n02988066 2619 +n03027250 2619 +n03070059 2619 +n03525454 2619 +n04538552 2619 +n02948557 3523 +n03031152 3523 +n02947818 3525 +n03746005 3527 +n03746155 3527 +n02935017 2620 +n03851787 2620 +n03706653 2620 +n03744276 2620 +n03708036 2620 +n04063868 2620 +n02763306 2620 +n03079230 3531 +n04533946 3531 +n02988679 3537 +n02988486 3537 +n02757061 3537 +n03492542 3532 +n03209910 3532 +n03359436 3533 +n04052757 3533 +n04534359 3534 +n02979399 3534 +n04391838 3535 +n03924069 3535 +n03694639 3549 +n04178190 3549 +n03636248 2623 +n03665366 2623 +n03358172 3552 +n03640988 3552 +n02948072 3552 +n03818343 3552 +n04534895 3552 +n04384910 3552 +n03423877 3552 +n03844045 3552 +n03549897 3552 +n03370387 3552 +n04335886 3552 +n04286575 3552 +n03272383 3552 +n03590841 3555 +n03018712 3555 +n03359137 3566 +n03665924 3566 +n03911767 3566 +n03503997 3553 +n04107743 3553 +n04339879 3553 +n03318294 3553 +n04148703 3553 +n04160847 3553 +n03824713 3553 +n02852173 3553 +n04456115 3553 +n03365374 3553 +n03401129 2624 +n03442597 2624 +n03187037 2624 +n04529108 2624 +n03975232 2624 +n03668279 3586 +n03482523 3586 +n04371050 3588 +n03772584 3588 +n04164757 3588 +n03544238 3588 +n04288272 2630 +n04116098 2630 +n03066359 3593 +n02886321 3593 +n03525074 2632 +n04585745 2632 +n03281145 2632 +n03126707 2632 +n04575824 2632 +n03178430 2632 +n03733281 1835 +n03078287 1835 +n03820728 1835 +n03440216 1835 +n04080138 1835 +n03302938 1835 +n03738241 1835 +n03085915 1835 +n04141712 1835 +n04082886 1835 +n04545858 3604 +n04041544 3604 +n04400289 3604 +n04402746 3604 +n03578055 3604 +n03580845 3604 +n04404412 3615 +n04137897 3619 +n04365328 3619 +n03072201 3619 +n03681477 3605 +n04358491 3605 +n03300216 3623 +n04595028 3623 +n04008385 3609 +n03674440 3609 +n04366116 3609 +n03401279 3609 +n03957315 1836 +n04488202 1836 +n04555700 1836 +n03206908 1836 +n02893692 1836 +n03210683 1836 +n03991062 1836 +n02920658 1836 +n04074185 1836 +n03147509 1836 +n02774152 1836 +n02978881 1836 +n03256032 1836 +n02773037 1836 +n03733805 1836 +n03438257 1836 +n03875806 1836 +n03733644 1836 +n03291819 1836 +n04183329 1836 +n03935335 1836 +n02801938 1836 +n04179712 1836 +n04139859 1836 +n03994614 1836 +n02946921 1836 +n04576211 1836 +n04600312 1836 +n02839910 1836 +n02949542 1836 +n03779370 1836 +n02964843 1836 +n04533700 1836 +n02975212 1836 +n02974697 1836 +n04531098 1836 +n03233905 1836 +n04060904 1836 +n03871083 1836 +n04560292 1836 +n02883344 1836 +n03062336 3634 +n03920288 3634 +n03456024 3634 +n04176190 3634 +n04499062 3634 +n04350581 3634 +n02880940 3634 +n02978753 3634 +n04050933 3634 +n02927764 3634 +n04130257 3678 +n03775546 3678 +n03984759 3678 +n02997910 3678 +n04263257 3678 +n04023695 3678 +n04103769 3636 +n02682922 3636 +n04254120 3636 +n02754103 3636 +n03571280 3636 +n03174731 3640 +n02815749 3640 +n03629520 3640 +n03063073 3640 +n03002948 3640 +n04397452 3640 +n03216710 3640 +n03301940 3641 +n04207343 3641 +n03055418 3641 +n04083309 3641 +n02769748 3644 +n04122685 3644 +n02816656 3644 +n04134008 3644 +n02970408 3644 +n03883524 3644 +n03253886 3644 +n02870676 3644 +n04452528 3644 +n03709823 3644 +n04026417 3644 +n03235796 3644 +n03291963 3644 +n04124098 3644 +n04122825 3644 +n03993180 3644 +n04204081 3644 +n04446844 3644 +n03414029 3644 +n03619793 3644 +n03958227 3644 +n03445617 3644 +n04235860 3644 +n03469903 3644 +n03461288 3644 +n04284572 3719 +n03972524 3719 +n04544450 3719 +n03321563 3719 +n03521899 3730 +n03898395 3730 +n03372549 3646 +n04496872 3646 +n04559910 3646 +n02918831 3646 +n03676623 3646 +n04249882 3646 +n04206225 3646 +n02823750 3646 +n04119360 3646 +n03443371 3646 +n04592099 3646 +n03062245 3650 +n04131690 3650 +n03914438 3650 +n03883385 3652 +n03050864 3652 +n03482405 3652 +n02893608 3652 +n04204238 3652 +n04582349 3652 +n03764736 3656 +n02823510 3656 +n04255586 3656 +n03904433 3657 +n02946509 3657 +n04103364 3657 +n03791053 3657 +n04170037 3657 +n04509417 3657 +n04543158 3657 +n02804515 3657 +n03484083 3657 +n02766534 3657 +n02834778 3657 +n03538634 3657 +n04467099 3657 +n02959942 3657 +n04482393 3657 +n02740533 3762 +n04065272 3762 +n04464852 3762 +n04252077 3762 +n02916179 3762 +n03684823 3762 +n04335435 3762 +n03791235 3762 +n04465501 3762 +n03384352 3762 +n02740300 3773 +n02739889 3773 +n03256788 3774 +n02946348 3774 +n04520382 3774 +n04211219 3778 +n03193597 3778 +n03272562 3778 +n04389854 3778 +n04465358 3778 +n04310018 3778 +n03193260 3789 +n03193423 3789 +n03506880 3780 +n04490091 3780 +n02704792 3780 +n03389761 3780 +n03790512 3780 +n03444034 3780 +n02958343 3780 +n04252225 3780 +n03345487 3797 +n04520170 3797 +n04467665 3797 +n04474035 3797 +n03417042 3797 +n03632852 3797 +n04461696 3797 +n03256166 3797 +n04465666 3797 +n03930630 3797 +n03173929 3805 +n03796401 3805 +n03896419 3805 +n03977966 3805 +n02871314 3805 +n04466871 3800 +n03785016 3800 +n02814533 3802 +n03680512 3802 +n03777568 3802 +n03268790 3802 +n03770679 3802 +n03100240 3802 +n03079136 3802 +n02930766 3802 +n04201733 3802 +n04037443 3802 +n03498781 3802 +n04097373 3802 +n02831335 3802 +n04285965 3802 +n04166281 3802 +n03594945 3802 +n03670208 3802 +n03141065 3802 +n02701002 3802 +n04516354 3802 +n04322801 3802 +n04347119 3802 +n03870105 3802 +n03543394 3802 +n04285008 3802 +n03119396 3802 +n03122295 3764 +n02970849 3764 +n03538406 3848 +n03255899 3848 +n03599486 3848 +n03981924 3848 +n03868242 3848 +n04397027 3766 +n03648431 3766 +n04176068 3766 +n02797295 3766 +n04204347 3766 +n03490119 3766 +n02835271 3768 +n04126066 3768 +n04026813 3768 +n03792782 3768 +n02968473 3769 +n03435991 3864 +n02912557 3864 +n04297098 3864 +n03389889 3864 +n02775039 3771 +n03393912 3771 +n03895866 3771 +n02932523 3771 +n02885108 3870 +n04389521 3870 +n03828020 3871 +n04020912 3871 +n03200357 3871 +n04246855 3871 +n04065789 3659 +n02747177 3659 +n03678558 3659 +n04134523 3661 +n03935116 3661 +n02900705 3665 +n03078995 3665 +n03210372 3665 +n03619650 3665 +n04548362 3665 +n02962843 3665 +n03986355 3665 +n03214582 3665 +n03031012 3665 +n04200000 3665 +n03468821 3665 +n02755140 3665 +n03683995 3665 +n04608435 3665 +n04556533 3665 +n02774630 3665 +n03438863 3665 +n03487533 3899 +n04137217 3899 +n02773838 3899 +n04491769 3899 +n03498441 3899 +n03420345 3903 +n04570815 3903 +n02967294 3903 +n03986949 3903 +n03865371 3903 +n04518764 3903 +n02863750 3666 +n03355768 3666 +n02881193 3666 +n03633091 3666 +n02876657 3666 +n02877266 3666 +n03990474 3666 +n03950228 3666 +n02808440 3666 +n03786901 3666 +n02909870 3666 +n03241496 3666 +n03129001 3666 +n04591887 3666 +n04001265 3666 +n04493381 3666 +n03572321 3666 +n04438897 3666 +n02801525 3666 +n03784270 3666 +n02758960 3666 +n03029445 3666 +n02795169 3666 +n04388743 3666 +n03593526 3666 +n02993368 3666 +n04447028 3914 +n03350204 3914 +n04149083 3915 +n04263336 3915 +n04246060 3916 +n03983396 3916 +n04557648 3916 +n03603722 3916 +n02985963 3916 +n03449451 3916 +n03937543 3916 +n02962061 3916 +n03359566 3916 +n02823428 3916 +n03571625 3916 +n03174450 3916 +n04579056 3916 +n03140431 3916 +n04591713 3916 +n02960903 3916 +n03923379 3916 +n04579145 3945 +n04560804 3945 +n03521675 3950 +n03295246 3950 +n04422727 3950 +n02952374 3950 +n04518132 3950 +n03709363 3956 +n03595409 3956 +n04139140 3918 +n04398044 3918 +n03259401 3918 +n04516214 3918 +n04324297 3918 +n03612814 3918 +n02939185 3918 +n03915118 3918 +n04397768 3918 +n03063689 3918 +n03064250 3971 +n04132985 3971 +n04399158 3971 +n04225031 3920 +n03543603 3920 +n03379343 3920 +n03797390 3923 +n03693707 3923 +n04389430 3923 +n03063599 3984 +n04443766 3984 +n02824058 3984 +n02836174 3930 +n02843158 3930 +n04553703 3930 +n02788572 3930 +n02823335 3934 +n04592005 3934 +n03610418 3934 +n03426134 3935 +n04560113 3935 +n04173046 3935 +n02732072 3935 +n04078574 3935 +n04562935 4001 +n04049303 4001 +n02951703 3936 +n02705429 3936 +n03101664 3936 +n02815834 3936 +n04516116 3936 +n03725600 3936 +n04522168 3936 +n03133415 3936 +n03593122 3936 +n03960374 3668 +n04476259 3668 +n02982515 3668 +n03259009 3668 +n03004275 3668 +n04131929 3668 +n03416900 3668 +n03565830 3668 +n03543735 3668 +n03858085 3668 +n04255163 3668 +n02747802 3668 +n03871628 3669 +n02919414 3669 +n03167978 3669 +n02778456 4026 +n03500389 4026 +n03870672 4026 +n02782681 3671 +n02971356 3671 +n03064758 3671 +n04200258 3671 +n04253057 3671 +n03908618 3671 +n03127925 3671 +n02786331 3671 +n04589325 3671 +n03014705 3671 +n04340750 3671 +n02998003 3671 +n03710193 3671 +n02978055 3671 +n02836392 3671 +n03871724 3671 +n04452615 4040 +n04462011 4040 +n03064350 4040 +n03535024 4040 +n04477548 4040 +n02989099 4040 +n02977438 4041 +n04125257 4041 +n02976939 4041 +n04125021 4041 +n04469813 1837 +n03002341 1837 +n04214282 1837 +n04019101 1837 +n04172342 1837 +n03538179 1837 +n04524313 1837 +n04231693 1837 +n04103918 1837 +n04467307 1837 +n04196502 1837 +n03678362 1837 +n03306385 4060 +n04212165 4060 +n04468005 4060 +n02924116 4060 +n03680942 4060 +n03394272 4071 +n03896233 4071 +n04349306 4071 +n03711044 4071 +n03394480 4071 +n03078802 4075 +n02917067 4075 +n04487081 4072 +n03769881 4072 +n04146614 4072 +n04310157 4063 +n02918964 4063 +n04099429 4063 +n03764276 4063 +n03773504 4063 +n03125870 4063 +n04235291 4063 +n03478589 4087 +n04389033 4087 +n03886053 4087 +n03919096 4087 +n03549199 4087 +n02686568 4089 +n04530566 4089 +n04264914 4089 +n03547229 4089 +n03510583 4096 +n04308084 4096 +n03666917 4096 +n03491032 4100 +n03439814 4100 +n03512147 4100 +n04552348 4100 +n02691156 4100 +n02759387 4100 +n02867715 4107 +n02704645 4107 +n04012084 4107 +n02690373 4107 +n02842573 4107 +n03365231 4107 +n03595860 4107 +n03335030 4107 +n04308273 4107 +n04160586 4107 +n02686121 4112 +n04583620 4112 +n03604311 4115 +n03596543 4115 +n04308397 4116 +n03577672 4116 +n02692877 4102 +n02850950 4102 +n02782093 4102 +n03541923 4102 +n02858304 4097 +n04476116 4097 +n04610013 4097 +n04194289 4097 +n04128837 4097 +n02792409 4097 +n03662601 4129 +n03977592 4129 +n03447447 4129 +n04158807 4129 +n02792552 4129 +n04095210 4129 +n04495843 4129 +n04024983 4129 +n03939178 4129 +n04244997 4129 +n03329663 4129 +n04409128 4129 +n02947660 4129 +n03344393 4129 +n03790230 4129 +n03236423 4139 +n03981566 4139 +n03545470 4139 +n04229480 4144 +n02951358 4144 +n03199901 4144 +n04037964 4144 +n03105306 4144 +n04612504 4144 +n03436891 4144 +n03602081 4144 +n04115456 4144 +n03609235 4154 +n03861430 4154 +n03254374 4154 +n04038231 4156 +n04038338 4156 +n04273569 4149 +n03859170 4149 +n02932891 4149 +n03552749 4149 +n04197110 4132 +n04606251 4132 +n03896103 4132 +n03947888 4132 +n03668488 4132 +n03541269 4132 +n04309348 4132 +n02965300 4132 +n04224543 4132 +n04552696 4132 +n03673027 4173 +n03698604 4181 +n02965216 4181 +n03141327 4181 +n03874138 4177 +n04317063 4177 +n02878222 4178 +n03095699 4178 +n02784124 4178 +n03845190 4178 +n04347754 4180 +n03466493 4180 +n03397266 4180 +n02812201 4180 +n03466600 4180 +n02687172 4180 +n03718212 4180 +n03180504 4180 +n02755529 4191 +n03811295 4191 +n04612373 4133 +n03045228 4133 +n03327133 4133 +n04242408 4133 +n03612010 4133 +n03186285 4133 +n04128499 4133 +n02793199 4133 +n04147183 4133 +n04587327 4133 +n04483307 4207 +n02981792 4207 +n02982416 4207 +n04266014 4098 +n04264765 4098 +n03218198 4090 +n02860847 4090 +n02861022 4090 +n04336792 4068 +n03122202 4068 +n06271778 1838 +n06255081 1838 +n06263609 1838 +n06276697 4221 +n06272290 4221 +n06276501 4221 +n06277280 4224 +n06281040 4224 +n06277135 4224 +n06278338 4227 +n06278475 4227 +n06274760 4225 +n06272803 4225 +n06272612 4225 +n06263369 4223 +n06266417 4223 +n06595351 4235 +n06267145 4235 +n06596607 4237 +n06596727 4237 +n06596364 4237 +n06596474 4237 +n06267893 4238 +n06267564 4238 +n06267655 4238 +n06266633 4236 +n06267991 4236 +n03938244 1055 +n03872495 1055 +n04135315 4249 +n02823964 4249 +n03408444 4249 +n02967626 4249 +n04053677 1056 +n04151940 1056 +n04453910 1056 +n03380867 1056 +n04014297 1056 +n03045698 1056 +n04605726 1056 +n04513827 1056 +n03050026 1056 +n03724870 1056 +n03341153 1056 +n03366823 1056 +n03058107 1056 +n02952237 1056 +n03357376 1056 +n03221059 1056 +n03376279 1056 +n03956623 1056 +n03261603 1056 +n02944459 4255 +n04201297 4255 +n02954938 4256 +n03717622 4256 +n03661340 4256 +n04041243 4275 +n02877765 4275 +n03825788 4275 +n03047690 4257 +n04199027 4257 +n02735538 4257 +n02872752 4257 +n03361550 4257 +n04241394 4257 +n03865949 4257 +n04122578 4282 +n04239786 4282 +n03027625 4282 +n04124370 4282 +n04272389 4282 +n02904927 4282 +n04593524 4282 +n04545748 4282 +n02855701 4282 +n02713364 4282 +n03041449 4282 +n03411079 4282 +n03680355 4282 +n04120489 4282 +n03868406 4282 +n02882894 4282 +n03967270 4282 +n04022332 4282 +n04133789 4282 +n03025250 4282 +n04027706 4306 +n04386664 4306 +n03364008 4306 +n03297103 4306 +n03600475 4284 +n02925666 4284 +n04228581 4284 +n03521544 4284 +n04089666 4284 +n04116294 4284 +n03516844 4284 +n04542715 4284 +n03124043 4284 +n03798061 4286 +n02873733 4286 +n03067518 4258 +n03046133 4258 +n04554211 4258 +n04444749 4258 +n03797896 4258 +n04192858 4258 +n02888270 4258 +n04151581 4258 +n04187233 4258 +n02826068 4258 +n04181718 4258 +n04191943 4258 +n04281375 4258 +n04416005 4258 +n04105068 4258 +n03314608 4258 +n03530910 4258 +n04187061 4258 +n02955065 4258 +n03725035 4258 +n03315644 4258 +n03142679 4258 +n02937958 4258 +n02739668 4258 +n02840245 4258 +n02840619 4258 +n03546766 4258 +n02851099 4258 +n03673767 4258 +n03959701 4328 +n03539433 4352 +n02740764 4352 +n02895154 4354 +n03513376 4354 +n02950632 4354 +n03623338 4354 +n03929855 4356 +n04130907 4356 +n04589890 4330 +n03347037 4330 +n04590553 4330 +n03788365 4330 +n03637318 4333 +n03889871 4333 +n03652729 4334 +n02825657 4334 +n04172776 4334 +n02843684 4334 +n02951843 4334 +n03610524 4334 +n02763901 4371 +n04507155 4371 +n03415252 4371 +n03409591 4337 +n04357121 4337 +n03718789 4337 +n03220513 4337 +n03522100 4337 +n04435653 4337 +n03546235 4337 +n04523525 4337 +n04234887 4337 +n03413684 4337 +n04417672 4337 +n03148727 4379 +n03435593 4379 +n03847471 4379 +n02796207 4383 +n04087709 4383 +n03527444 4340 +n04141327 4340 +n04207763 4340 +n03548086 4341 +n04423845 4341 +n03213538 4341 +n03657121 4341 +n03424325 4342 +n03314378 4342 +n04229816 4400 +n02983189 4400 +n02862048 4346 +n04192698 4346 +n03000247 4403 +n02916936 4403 +n03112719 4403 +n03146219 4403 +n02933340 4349 +n04045255 4349 +n02873520 4349 +n04589190 4350 +n03592669 4350 +n03151077 4350 +n04211356 4350 +n04525584 4412 +n04590129 4412 +n04102285 4412 +n04418357 4414 +n04209239 4414 +n02925107 4351 +n02890513 4351 +n03436549 4260 +n03291741 4260 +n02992368 4260 +n07248320 4260 +n03590306 4260 +n03958752 4260 +n04207151 4262 +n03885293 4262 +n03654576 4262 +n02767665 4262 +n03114379 4262 +n02785648 4262 +n02876084 4262 +n04240752 4262 +n02820210 4262 +n04236377 4262 +n02851939 4262 +n03309356 4262 +n04231272 4262 +n04162433 4262 +n02786058 4434 +n04369025 4434 +n02979836 4434 +n03267821 4434 +n04033995 4437 +n02683323 4437 +n02849154 4437 +n02822220 4437 +n03731483 4437 +n03898633 4447 +n03266749 4447 +n03128427 4447 +n03123553 4450 +n04034262 4450 +n04046400 4438 +n03688405 4438 +n04118021 4265 +n03223299 4265 +n03727837 4265 +n04144539 4459 +n04183217 4459 +n03998194 4459 +n02904233 4459 +n04297847 4459 +n04066270 4459 +n02908773 4459 +n03353951 4266 +n03445326 4266 +n04528079 4266 +n03875218 4266 +n03805725 4266 +n03437430 4266 +n03115897 4266 +n03284743 4266 +n04525417 4266 +n03342015 4472 +n03284886 4472 +n03285578 4472 +n03844233 4472 +n04557308 4472 +n03646020 4482 +n04581102 4482 +n03261019 4268 +n03973402 4268 +n03642444 4268 +n04450994 4268 +n04084889 4268 +n04412097 4268 +n03337383 4270 +n03729308 4270 +n03970546 1057 +n03802393 1057 +n04395024 1057 +n04525038 1057 +n02809105 1057 +n03615406 1057 +n02828427 1057 +n04123567 1057 +n03188725 1057 +n04539794 1057 +n03253796 1057 +n03013850 1057 +n03115400 1057 +n04459610 1057 +n03132666 1057 +n03885194 1057 +n03019938 1057 +n03326795 1057 +n03115180 1057 +n04525191 1057 +n04138261 1057 +n03625355 1057 +n04137355 1057 +n04003856 1057 +n03356982 1057 +n04568841 1057 +n03409297 1057 +n02944579 1057 +n04605163 1057 +n02977330 1057 +n04395106 1057 +n03779128 1057 +n02904803 1057 +n04524941 1057 +n04198453 1057 +n02878425 1057 +n03703862 1057 +n03819595 1057 +n03877351 1057 +n04613015 1057 +n03914831 1057 +n03932670 1057 +n03785237 1057 +n04414476 1057 +n04056932 1057 +n02675219 1057 +n03106722 1057 +n03917814 1057 +n03016868 1057 +n02922798 1057 +n04432662 1057 +n02802990 1057 +n03631177 1057 +n04189282 1057 +n03435743 1057 +n03983612 1057 +n03175189 1057 +n03357267 1057 +n04184316 1057 +n02942460 1057 +n03836906 1057 +n03233123 1057 +n03430091 1057 +n03855214 1057 +n03386726 1057 +n03437741 1057 +n04599235 1057 +n04350458 1057 +n04383839 1057 +n03653110 1057 +n04502502 1057 +n03854421 1057 +n02952109 1057 +n03298858 1057 +n03160740 1057 +n03843438 1057 +n04393549 1057 +n02903852 1057 +n03947798 1057 +n03529444 1057 +n04482297 4514 +n03227317 4514 +n03595523 4514 +n03429914 4530 +n04496614 4530 +n03016609 4530 +n03485794 4534 +n03463666 4534 +n03258330 4534 +n03207743 4534 +n04459362 4534 +n02786198 4534 +n03471190 4534 +n02834397 4534 +n04127904 4534 +n03897943 4534 +n03490006 4583 +n03887697 4583 +n03207835 4583 +n03381776 4587 +n03383099 4587 +n04278447 4587 +n03505383 4587 +n04455652 4587 +n03712337 4587 +n02782602 4587 +n03598151 4592 +n03775747 4592 +n03410571 4592 +n03696568 4592 +n04307767 4592 +n03645577 4592 +n03358380 4588 +n04208065 4588 +n03809603 4539 +n02820556 4539 +n03703730 4545 +n03938522 4545 +n04045397 1059 +n03663531 1059 +n03662719 4612 +n03703945 4612 +n03662887 4612 +n04326084 1060 +n02897820 1060 +n14943580 1060 +n14785065 1060 +n15074568 1060 +n14820180 1060 +n04035912 1060 +n03766935 4616 +n04313628 4616 +n03530511 4616 +n03460297 4616 +n03149686 4616 +n03455488 4616 +n03344642 4617 +n03796522 4617 +n03043693 4617 +n02681392 4617 +n04339638 4618 +n15102455 4618 +n04234455 4633 +n03341297 4633 +n04453390 4633 +n14908027 4620 +n14976759 4620 +n03111177 1061 +n03282401 1061 +n03451798 1061 +n03292603 1061 +n03815149 1061 +n03723267 1061 +n02892304 1061 +n07621618 1061 +n02732572 1061 +n03178782 1061 +n02681518 1061 +n03397087 1061 +n03635108 1061 +n04395651 4649 +n03762602 4649 +n03282591 4649 +n06883725 4649 +n03516367 4649 +n04682462 4649 +n03354903 4655 +n02788021 4655 +n04458633 4655 +n03140292 4655 +n03362890 4655 +n05244934 4658 +n11487732 4658 +n03597469 4650 +n03397532 4650 +n03649161 4650 +n03914106 4650 +n02787435 4650 +n03030262 4650 +n02685082 4650 +n02887970 4666 +n02852043 4666 +n03909020 4666 +n03814906 4666 +n03436075 1062 +n03899328 1062 +n04096066 1062 +n03895293 1062 +n04215402 4678 +n04461570 4678 +n03904183 4678 +n03519981 4679 +n02969323 4679 +n04426618 4679 +n04466613 4679 +n03215508 4684 +n03306610 4684 +n02744323 4684 +n02762508 4689 +n02758863 4689 +n04335209 4686 +n04334599 4686 +n03948242 4687 +n03539678 4687 +n02680512 4680 +n03089014 4680 +n03895585 4680 +n04493505 4698 +n04244379 4698 +n04250850 4698 +n04562496 4698 +n02984469 4700 +n02795528 4700 +n03944672 4700 +n03533014 4700 +n04385536 4706 +n03231912 4706 +n03147280 4709 +n04257684 4709 +n04497962 4699 +n04298661 4699 +n03415749 4699 +n02981024 4712 +n04048441 4712 +n04391569 1063 +n02784218 1063 +n03572107 4717 +n02680337 4717 +n03957420 4720 +n02992795 4720 +n03506028 4718 +n03438071 4718 +n04440749 4718 +n02739427 4718 +n04040247 4725 +n02971167 4725 +n04381994 1064 +n04087432 1064 +n03153375 4729 +n03438661 4729 +n03527149 4729 +n03963198 4729 +n04284002 4731 +n04380346 4731 +n03383948 4731 +n04284438 4731 +n04263502 4735 +n04398688 4735 +n04350769 4735 +n04597913 4735 +n03557270 4735 +n04381073 4735 +n03180384 4735 +n02976249 4736 +n02928049 4736 +n04307986 4736 +n04380255 4737 +n02973805 4737 +n02687992 1065 +n04406817 1065 +n02693246 1065 +n02692232 1065 +n03745146 1065 +n04329190 1065 +n04306080 1065 +n04551055 4756 +n03452449 4756 +n03131669 4756 +n03768916 1066 +n03214253 1066 +n03587205 4762 +n03406966 4762 +n03093574 1067 +n03672352 1067 +n03051540 4765 +n02729837 4765 +n03655720 4767 +n03456186 4767 +n02855925 4767 +n03825080 4767 +n04015204 4767 +n03859495 4767 +n03815482 4767 +n03625943 4767 +n03692379 4767 +n02728440 4767 +n03068998 4767 +n03763968 4767 +n03502509 4767 +n03877472 4767 +n03419014 4767 +n02742322 4767 +n04596852 4767 +n03863108 4767 +n03441112 4767 +n02671780 4767 +n02846141 4767 +n03381126 4767 +n02756098 4767 +n04059157 4767 +n02814774 4767 +n03746330 4767 +n04335693 4767 +n04241249 4767 +n04194127 4773 +n03863262 4773 +n04001845 4773 +n02738859 4773 +n03386870 4773 +n03216402 4773 +n02730930 4773 +n04207903 4773 +n03121897 4773 +n03015478 4773 +n03268645 4773 +n04266375 4773 +n03623198 4773 +n03450516 4774 +n04532106 4810 +n03010795 4810 +n02669723 4810 +n02811719 4780 +n03324928 4780 +n03239259 4780 +n03615563 4780 +n03513137 4781 +n03531281 4781 +n04498389 4781 +n03497657 4781 +n02954340 4781 +n03124474 4781 +n04432203 4781 +n03379051 4818 +n03492922 4818 +n03127747 4818 +n04356595 4821 +n03404360 4821 +n03124170 4821 +n02817516 4821 +n02859184 4821 +n04248507 4821 +n03325941 4821 +n02987379 4821 +n04259630 4821 +n04482177 4821 +n02818135 4821 +n03984643 4821 +n02869837 4821 +n03950899 4821 +n02881757 4821 +n03766322 4821 +n03046029 4843 +n03937835 4843 +n02799323 4822 +n03103563 4822 +n04209133 4822 +n03610682 4822 +n02776825 4822 +n03331077 4822 +n04387095 4822 +n02831237 4822 +n04232153 4822 +n03049924 4822 +n04228693 4822 +n04556408 4822 +n02807133 4822 +n03787032 4822 +n04612026 4854 +n02816768 4854 +n03502331 4783 +n04143897 4783 +n04104770 4783 +n03188531 4783 +n04605572 4783 +n04097866 4783 +n04574067 4783 +n03655072 4783 +n04230808 4783 +n04508163 4783 +n04172904 4783 +n04531873 4783 +n04197391 4783 +n03863923 4783 +n03540090 4783 +n02922578 4783 +n04488530 4783 +n04489008 4783 +n04332580 4783 +n03404149 4783 +n03816005 4783 +n04370774 4783 +n03657511 4783 +n04371563 4783 +n03487642 4783 +n04046277 4783 +n04350905 4783 +n04370048 4783 +n03450734 4783 +n03314884 4862 +n03826039 4862 +n02998841 4862 +n03719743 4863 +n03797182 4863 +n03505504 4863 +n04495698 4863 +n03325584 4863 +n04325704 4863 +n03520493 4896 +n03615655 4896 +n03237992 4867 +n03617480 4867 +n02667093 4867 +n02807616 4867 +n03410938 4869 +n04269822 4869 +n03866082 4870 +n03454442 4870 +n03770439 4870 +n03617312 4870 +n03732458 4870 +n02780815 4870 +n03205669 4870 +n04136333 4870 +n03534580 4870 +n03920737 4871 +n02892767 4871 +n03387323 4871 +n04223299 4871 +n03421324 4871 +n03132776 4871 +n04508949 4871 +n02863014 4871 +n02944146 4871 +n04514241 4871 +n03013580 4871 +n04508489 4871 +n03112869 4919 +n03885788 4919 +n04103665 4919 +n03673450 4923 +n03688192 4923 +n02930214 4923 +n04509171 4932 +n03824381 4932 +n02854739 4928 +n04426427 4928 +n02837887 4928 +n02901114 4928 +n03885028 4928 +n03234164 4928 +n04602956 4874 +n03629231 4874 +n03595614 4874 +n03163381 4874 +n03978966 4874 +n03057021 4875 +n03045337 4875 +n04252560 4875 +n04363777 4948 +n03254046 4948 +n04187970 4948 +n03398228 4948 +n03630383 4948 +n03456665 4948 +n03589791 4948 +n04049405 4948 +n02957008 4948 +n04123448 4948 +n03404251 4948 +n03751269 4957 +n04222307 4957 +n02867966 4957 +n03902756 4957 +n04368496 4957 +n03228254 4957 +n02864504 4957 +n03891051 4957 +n03844815 4958 +n04479046 4958 +n03770954 4961 +n04122492 4961 +n03980874 4949 +n04445154 4949 +n04445040 4949 +n03607923 4949 +n04173907 4949 +n04497570 4949 +n04186455 4949 +n02936402 4949 +n04205318 4879 +n03877674 4879 +n04370288 4879 +n04132158 4879 +n02896442 4879 +n03019434 4879 +n04233715 4879 +n03600285 4879 +n03903733 4879 +n03688605 4879 +n03594734 4879 +n03107488 4879 +n03660124 4879 +n04337287 4879 +n02825442 4879 +n02910864 4879 +n03543112 4982 +n02831595 4982 +n03653833 4982 +n03815615 4882 +n03128085 4882 +n02865351 5001 +n04591157 5001 +n02883205 5001 +n02847631 5001 +n03710721 4885 +n04371430 4885 +n02837789 4885 +n03226538 4888 +n03943920 4888 +n04222470 4888 +n03885669 4888 +n02925519 4888 +n04427715 5014 +n04504141 5014 +n04502197 4889 +n02963159 4889 +n04370456 4889 +n04021028 4889 +n04453666 4785 +n03464053 4785 +n02944075 4785 +n03236735 4785 +n02861387 5021 +n02854926 5021 +n03480579 5021 +n03062015 5024 +n04136161 5024 +n02936570 5024 +n04355511 5024 +n03013438 5024 +n04334105 5024 +n03450230 5024 +n03604400 5024 +n03205574 5024 +n02898585 5034 +n04397645 5034 +n02781121 5034 +n03429682 4787 +n03775071 4787 +n03616979 4787 +n02827606 4788 +n03405595 4788 +n03781683 5043 +n03527565 5043 +n02972397 5043 +n03540267 4790 +n04434932 5048 +n04254777 5048 +n04323819 5048 +n03885904 5049 +n03710637 5049 +n02752496 5050 +n04378956 5050 +n03622931 5050 +n02736798 5050 +n03836976 5051 +n03026506 5051 +n03384891 4791 +n03289985 4791 +n03859958 4791 +n02726017 4791 +n03113657 4791 +n03320519 4791 +n03113835 4791 +n03398153 4791 +n04285803 4791 +n02669534 4791 +n03206718 4791 +n03476083 4791 +n03201776 5060 +n02780704 5060 +n03201638 5060 +n03239054 5060 +n02683454 5071 +n04459018 5071 +n04584207 5071 +n03237416 4794 +n02887489 4794 +n02752615 4794 +n03528263 4768 +n03251766 4768 +n04517823 5082 +n03584829 5082 +n04488857 5082 +n03150511 5082 +n04580493 5082 +n04179913 5082 +n04174101 5082 +n03620052 5082 +n03534776 5082 +n04475631 5085 +n04309833 5085 +n03207941 5088 +n04070727 5088 +n04554684 5088 +n03102654 5096 +n03273913 5096 +n03557590 5099 +n03170635 5099 +n04442312 5091 +n03761084 5091 +n04442441 5091 +n03063338 5091 +n03543254 5091 +n04542943 5091 +n03212114 5091 +n03297495 5091 +n04330340 5091 +n03862676 5091 +n03378174 5091 +n03557692 5091 +n03102371 5110 +n03273740 5110 +n03425595 5110 +n04003241 5110 +n02905036 5111 +n04111531 5111 +n03259280 5111 +n03425241 5111 +n03483316 5083 +n03050655 5083 +n04277826 5123 +n04496726 5123 +n04607242 5123 +n02808304 4766 +n03219010 4766 +n04499446 4766 +n02821030 4766 +n03938725 5130 +n04188179 5130 +n04439712 1068 +n03971218 1068 +n03223553 1068 +n02856463 1068 +n03250279 1068 +n03882058 1068 +n03635668 1068 +n02846511 1068 +n04251791 5136 +n04189816 5136 +n02731900 5136 +n04225987 5136 +n04214046 5136 +n04149813 5136 +n04543996 5138 +n03502200 5138 +n03005285 1069 +n03969259 1069 +n04254009 1069 +n04446521 5150 +n04208936 5150 +n04559451 5150 +n03371875 5152 +n03993053 5152 +n04108268 1071 +n03106110 1071 +n03644378 5157 +n02919890 5157 +n04290079 5157 +n03107046 5157 +n04426788 5158 +n02874537 5158 +n04581829 5158 +n03641569 5158 +n03367545 5163 +n04598965 5163 +n04605321 5163 +n00004475 1042 +n00006484 1042 +n12739332 5170 +n00017222 5170 +n00015388 5170 +n01326291 5170 +n11537327 5170 +n00007846 5170 +n12992868 5170 +n00005787 5170 +n12172906 5173 +n13083586 5173 +n13123431 5173 +n11536673 5173 +n11552806 5173 +n13083023 5173 +n13100156 5173 +n12476510 5181 +n11545524 5181 +n11552386 5181 +n13121544 5181 +n12205694 5181 +n13100677 5181 +n13103136 5181 +n13085113 5181 +n13084834 5181 +n13134302 5181 +n13084184 5181 +n12477163 5187 +n12477583 5187 +n12477747 5187 +n12480895 5187 +n12479537 5187 +n12481458 5187 +n11547562 5188 +n11545714 5188 +n13221529 5204 +n13220122 5204 +n13223265 5206 +n13223588 5208 +n13223710 5208 +n12953206 5205 +n13194572 5205 +n13205058 5205 +n12961879 5205 +n12953484 5205 +n13186654 5205 +n13197274 5205 +n13173882 5205 +n13229543 5205 +n13192625 5205 +n13185269 5205 +n13193642 5205 +n13207335 5205 +n13183056 5205 +n13200651 5205 +n13195341 5205 +n13206817 5205 +n13199970 5205 +n12957924 5205 +n13198914 5205 +n13199717 5205 +n13215586 5216 +n13190747 5216 +n13193856 5222 +n13194036 5222 +n11665372 5189 +n11596108 5189 +n12694486 5236 +n11666854 5236 +n11669921 5236 +n11672400 5236 +n12606438 5240 +n12799776 5240 +n11736694 5240 +n12008487 5240 +n11955896 5240 +n12879527 5240 +n12884260 5240 +n12034141 5240 +n12290748 5240 +n12026476 5240 +n12833149 5240 +n11892817 5240 +n12914923 5240 +n11969607 5240 +n11794024 5240 +n12026018 5240 +n11672269 5240 +n12830222 5240 +n11811473 5240 +n12022054 5240 +n11971406 5240 +n11826198 5240 +n12950314 5240 +n11857875 5240 +n11988596 5240 +n11939699 5240 +n11915214 5240 +n11821184 5240 +n12293723 5240 +n11814584 5240 +n11725015 5240 +n12890265 5240 +n11733312 5240 +n11859472 5240 +n11971248 5240 +n11888800 5240 +n11971927 5240 +n12898774 5240 +n11810358 5240 +n11904109 5240 +n11943407 5240 +n11978233 5240 +n12683407 5240 +n12950126 5240 +n11726707 5240 +n11813077 5240 +n11889619 5240 +n11905749 5240 +n11812910 5240 +n11900569 5240 +n12020184 5240 +n11960245 5240 +n11859737 5240 +n12909421 5240 +n12041446 5240 +n12909917 5240 +n11992806 5240 +n11807979 5240 +n11925303 5240 +n11971783 5240 +n11939491 5240 +n11918473 5240 +n11989869 5240 +n11727091 5240 +n11793779 5240 +n11891175 5240 +n11792341 5240 +n11839568 5240 +n11943660 5240 +n11947802 5240 +n12475242 5240 +n11815491 5240 +n12480456 5240 +n11839823 5240 +n11732567 5240 +n12475035 5240 +n12360108 5240 +n12833985 5240 +n11941924 5240 +n11883328 5240 +n11719286 5240 +n11736851 5240 +n11887119 5240 +n12001707 5240 +n11950345 5240 +n11892637 5240 +n11805956 5240 +n11892029 5240 +n11806219 5240 +n12008252 5240 +n11918286 5240 +n11962272 5240 +n12093600 5240 +n12836862 5240 +n12093329 5240 +n11733054 5240 +n12020507 5240 +n11931918 5240 +n11958080 5240 +n12877838 5240 +n11812094 5260 +n11811706 5260 +n11923174 5268 +n12023726 5268 +n12023407 5268 +n11923637 5268 +n11990313 5268 +n11915899 5268 +n12030908 5268 +n12015221 5268 +n11990167 5268 +n11981192 5349 +n11980318 5349 +n11972759 5349 +n11921395 5349 +n12294124 5270 +n12295796 5270 +n12294723 5270 +n12294331 5270 +n12294871 5270 +n12296432 5270 +n12295033 5270 +n11726269 5272 +n11725821 5272 +n11725973 5272 +n12891305 5273 +n12891643 5273 +n11978713 5283 +n11979527 5283 +n11978961 5283 +n11979715 5283 +n12683571 5284 +n12683791 5284 +n11901759 5291 +n11908549 5291 +n11901294 5291 +n11903671 5291 +n11901977 5291 +n11902389 5291 +n11908846 5291 +n11901597 5291 +n11905392 5291 +n11902200 5291 +n11906917 5291 +n12044467 5296 +n12052787 5296 +n12056217 5296 +n12075830 5296 +n12055516 5296 +n12083113 5296 +n12047884 5296 +n12048056 5296 +n12080820 5296 +n12070381 5296 +n12061380 5296 +n12080395 5296 +n12061614 5296 +n12074408 5296 +n12070583 5296 +n12071744 5296 +n12049282 5296 +n12047345 5296 +n12064389 5296 +n12075010 5296 +n12052447 5296 +n12053405 5296 +n12050533 5296 +n12077944 5296 +n12086539 5296 +n12064591 5296 +n12058822 5296 +n12046028 5296 +n12083591 5296 +n12073991 5296 +n12043444 5296 +n12086012 5296 +n12073554 5296 +n12046815 5296 +n12063639 5296 +n12058630 5296 +n12084890 5296 +n12070016 5296 +n12076223 5296 +n12069679 5296 +n12048399 5296 +n12049562 5296 +n12076577 5296 +n12086192 5296 +n12074867 5296 +n12075299 5296 +n12072722 5296 +n12066018 5296 +n12084555 5296 +n12070712 5296 +n12079963 5296 +n12065316 5296 +n12059314 5296 +n12085664 5296 +n12050959 5296 +n12062468 5296 +n12085267 5296 +n12078172 5296 +n12057211 5388 +n12057447 5388 +n12056758 5388 +n12056601 5388 +n12043836 5416 +n12043673 5416 +n12067193 5437 +n12066630 5437 +n12062781 5441 +n12062626 5441 +n11808299 5299 +n11808721 5299 +n11808932 5299 +n11808468 5299 +n11809594 5299 +n11809094 5299 +n11727358 5305 +n11727738 5305 +n11727540 5305 +n11816649 5313 +n11816336 5313 +n11816829 5313 +n11816121 5313 +n11815918 5313 +n11815721 5313 +n12362274 5318 +n12362668 5318 +n12361946 5318 +n11950877 5326 +n11950686 5326 +n11961100 5326 +n12020736 5338 +n12020941 5338 +n11934616 5339 +n11933546 5339 +n11934807 5339 +n12879963 5241 +n12015959 5241 +n11836722 5241 +n11860555 5241 +n12258885 5241 +n11980682 5241 +n12016567 5241 +n11737534 5241 +n11965627 5241 +n11991263 5241 +n11989393 5241 +n12006766 5241 +n12887293 5241 +n12937130 5241 +n12291959 5241 +n11972291 5241 +n11927215 5241 +n12012111 5241 +n11970586 5241 +n11963932 5241 +n11966215 5488 +n11966083 5488 +n12006930 5491 +n12007196 5491 +n11600372 5237 +n11599324 5237 +n11603246 5504 +n11602873 5504 +n11603835 5504 +n11601333 5504 +n12484784 5190 +n12610328 5190 +n11791569 5190 +n11714853 5190 +n13122364 5190 +n11715430 5513 +n11715678 5513 +n12801781 5514 +n11728099 5514 +n11786131 5514 +n12150028 5514 +n12801520 5514 +n11789066 5514 +n11792742 5514 +n12152532 5520 +n12151615 5520 +n12152722 5520 +n11733548 5191 +n11720353 5191 +n12810595 5191 +n12342299 5191 +n13238375 5191 +n12867826 5191 +n12665048 5191 +n11973341 5191 +n12312728 5191 +n11818069 5191 +n12848499 5191 +n11779300 5191 +n12822955 5191 +n12816508 5191 +n12719684 5191 +n12350758 5191 +n12095020 5191 +n11861641 5191 +n11962667 5191 +n12870891 5191 +n12939282 5191 +n12812478 5191 +n12031927 5191 +n12023108 5191 +n12858150 5191 +n12861892 5191 +n12841007 5191 +n12212361 5191 +n12869061 5191 +n12906214 5191 +n12910285 5191 +n12486574 5191 +n12090890 5191 +n12702948 5191 +n12437513 5191 +n11968931 5191 +n11817914 5191 +n11772408 5191 +n12932173 5191 +n12817694 5191 +n11910460 5191 +n12603449 5191 +n12939874 5191 +n12002428 5191 +n12015525 5191 +n11807108 5191 +n12835331 5191 +n12168565 5191 +n12840362 5191 +n12352287 5191 +n11969166 5191 +n11968704 5191 +n12821895 5191 +n12344283 5191 +n11866248 5191 +n11995092 5191 +n12622875 5191 +n11735053 5191 +n12548280 5191 +n13150894 5191 +n12685431 5191 +n12387633 5191 +n12171966 5191 +n12796022 5191 +n12934036 5191 +n12443323 5191 +n12870535 5191 +n12682668 5191 +n12778605 5191 +n12623077 5191 +n12836212 5191 +n11982115 5191 +n12003696 5191 +n12005656 5191 +n12098403 5191 +n12606545 5191 +n11902709 5191 +n12882945 5191 +n12785889 5191 +n11986511 5191 +n12682411 5191 +n12469517 5191 +n12029635 5191 +n12860365 5191 +n12552309 5191 +n11977303 5191 +n11825351 5191 +n12836337 5191 +n12844939 5191 +n12925179 5191 +n11926833 5191 +n12604228 5191 +n11752578 5191 +n12855042 5191 +n11956850 5191 +n12092262 5191 +n12506991 5191 +n12882779 5191 +n11747468 5191 +n12385429 5191 +n12822115 5191 +n12821505 5191 +n12607456 5191 +n12819728 5191 +n12817464 5191 +n12811027 5191 +n12024445 5191 +n12573474 5191 +n12864545 5191 +n11949402 5191 +n11868814 5191 +n11953038 5191 +n12599435 5191 +n12840749 5191 +n13233727 5191 +n12342498 5191 +n12795555 5191 +n11984542 5191 +n12847008 5191 +n12719944 5191 +n11855274 5191 +n12095647 5191 +n12441183 5191 +n12942572 5191 +n12602980 5191 +n12684379 5191 +n12441390 5191 +n12785724 5191 +n11916696 5191 +n12574320 5191 +n12092417 5191 +n12036939 5191 +n11700058 5191 +n12845413 5191 +n11824146 5191 +n11910271 5191 +n11916467 5191 +n11807525 5191 +n12101870 5191 +n11939180 5191 +n12353754 5191 +n12104501 5191 +n12794985 5191 +n12355760 5191 +n12793015 5191 +n12932966 5191 +n12931542 5191 +n12889713 5191 +n12849061 5191 +n11722466 5528 +n11720643 5528 +n12665857 5533 +n12665271 5533 +n11785668 5538 +n11780148 5538 +n11784497 5538 +n11782036 5538 +n11786539 5538 +n11782761 5538 +n12858871 5551 +n12858397 5551 +n11959632 5554 +n11959862 5554 +n12911673 5557 +n12911440 5557 +n12091213 5559 +n12091550 5559 +n12091377 5559 +n12091953 5559 +n12703557 5560 +n12703190 5560 +n12703383 5560 +n12437930 5561 +n12437769 5561 +n12352639 5576 +n12352844 5576 +n12352990 5576 +n12344700 5580 +n12344483 5580 +n12687957 5587 +n12685831 5587 +n12687698 5587 +n12687462 5587 +n12686274 5707 +n12686077 5707 +n12687044 5707 +n12686676 5707 +n12388989 5588 +n12388143 5588 +n12387839 5588 +n12388858 5716 +n12390099 5716 +n12389501 5716 +n12390314 5716 +n12782915 5595 +n12779603 5595 +n12781940 5595 +n12782530 5595 +n11753700 5619 +n11753355 5619 +n11753143 5619 +n12856680 5620 +n12855494 5620 +n12540250 5625 +n12515711 5625 +n12575322 5625 +n12575812 5625 +n12556307 5625 +n12539306 5625 +n12557681 5734 +n12558425 5734 +n12866162 5635 +n12865824 5635 +n12865037 5635 +n12866635 5635 +n12865562 5635 +n12866002 5635 +n11879054 5637 +n11878283 5637 +n11875691 5637 +n11876634 5637 +n11877193 5637 +n11876803 5637 +n11876432 5637 +n11870418 5637 +n11875938 5637 +n11894327 5637 +n11881742 5637 +n11870747 5637 +n11896722 5745 +n11879722 5745 +n11895092 5753 +n11894770 5753 +n11882074 5754 +n11882426 5754 +n13235503 5641 +n13234678 5641 +n12039317 5658 +n12037691 5658 +n12038406 5658 +n12038585 5658 +n12148757 5665 +n12102133 5665 +n12121610 5769 +n12139575 5769 +n12113195 5769 +n12112918 5769 +n12116429 5769 +n12141495 5769 +n12133462 5769 +n12108871 5769 +n12104238 5769 +n12141167 5769 +n12115180 5769 +n12112008 5769 +n12128071 5769 +n12146311 5769 +n12124627 5769 +n12110778 5769 +n12129134 5769 +n12134025 5775 +n12145477 5775 +n12142085 5775 +n12135898 5775 +n12137120 5790 +n12127030 5790 +n12127768 5792 +n12127460 5792 +n12356023 5670 +n12357485 5670 +n12793494 5671 +n12794135 5671 +n12849279 5675 +n12849416 5675 +n12847374 5192 +n12517642 5192 +n11731659 5192 +n12813189 5192 +n11838916 5192 +n12517445 5192 +n12513172 5192 +n12823859 5192 +n12566954 5192 +n13148208 5192 +n12158798 5192 +n12485981 5192 +n13237188 5192 +n12826516 5192 +n13120211 5192 +n12580654 5192 +n11769621 5192 +n12824053 5192 +n11769803 5192 +n12383402 5192 +n12823717 5192 +n12157769 5192 +n13144794 5192 +n12371439 5192 +n12159055 5811 +n12160490 5811 +n12158443 5811 +n12160303 5825 +n12159388 5825 +n12160857 5826 +n12161969 5826 +n12827270 5814 +n12828791 5814 +n12827537 5814 +n11788727 5815 +n11789589 5815 +n12571781 5815 +n11792029 5815 +n12384839 5820 +n12384227 5820 +n12384037 5820 +n12164363 5822 +n12166128 5822 +n12165170 5842 +n12164881 5842 +n12164656 5842 +n13146583 5823 +n13145040 5823 +n12509476 5193 +n13112664 5193 +n13104059 5193 +n12655869 5193 +n12546183 5193 +n12671651 5850 +n12215579 5850 +n12901724 5850 +n12938193 5850 +n12680864 5850 +n12329260 5850 +n12924623 5850 +n12659356 5850 +n12788201 5850 +n12343480 5850 +n13142504 5850 +n11830906 5850 +n12504783 5850 +n12659539 5850 +n12214789 5850 +n11699442 5850 +n12217453 5850 +n12574866 5850 +n12374418 5850 +n12249542 5850 +n13118707 5850 +n12215022 5850 +n12342852 5850 +n12762896 5850 +n12306717 5850 +n11769176 5850 +n12805146 5850 +n12519089 5850 +n11754893 5850 +n12772908 5850 +n12624381 5850 +n12482031 5850 +n12243109 5850 +n12223764 5850 +n12170585 5850 +n12230794 5850 +n12791329 5850 +n12674120 5850 +n12917901 5850 +n12237486 5850 +n12185859 5850 +n12681893 5850 +n12905412 5850 +n12899537 5850 +n12899752 5850 +n12806015 5850 +n12011620 5850 +n12922763 5850 +n12651229 5850 +n12303083 5850 +n11928352 5850 +n11926365 5850 +n12223569 5850 +n12791064 5850 +n12311579 5850 +n11834654 5850 +n11760785 5850 +n12749679 5850 +n12489815 5850 +n12666965 5850 +n12929403 5850 +n12902662 5850 +n12620196 5850 +n12237641 5850 +n12625383 5850 +n12244153 5850 +n11774513 5850 +n12520864 5850 +n12516828 5850 +n12849717 5850 +n12485653 5850 +n12790430 5862 +n12788854 5862 +n11924445 5874 +n12632335 5874 +n11947251 5874 +n12099342 5874 +n11931540 5874 +n12545635 5874 +n11778257 5874 +n11924849 5874 +n12367611 5874 +n12602262 5874 +n12328567 5874 +n12328398 5874 +n12629305 5874 +n11907689 5874 +n11940006 5874 +n12546962 5874 +n11925898 5874 +n11947629 5929 +n11948864 5929 +n11948264 5929 +n12368451 5935 +n12369309 5935 +n12368028 5935 +n12307240 5878 +n12307076 5878 +n12483427 5885 +n12483625 5885 +n12482893 5885 +n12483841 5885 +n12173664 5888 +n12173912 5888 +n12171316 5888 +n12174521 5888 +n12171098 5888 +n12177844 5888 +n12174311 5888 +n12178896 5961 +n12179122 5961 +n12676534 5891 +n12676703 5891 +n12675876 5891 +n12920204 5892 +n12921868 5892 +n12621410 5916 +n12622297 5916 +n12245319 5919 +n12244650 5919 +n12244819 5919 +n12521394 5921 +n12530818 5921 +n12849952 5923 +n12850336 5923 +n12850168 5923 +n12495146 5851 +n12570972 5851 +n12196129 5851 +n13107694 5851 +n12202936 5851 +n13111881 5851 +n13103877 5851 +n12409231 5851 +n12765115 5851 +n12265600 5851 +n12409470 5851 +n12713866 5851 +n12281241 5851 +n11709205 5851 +n12189429 5851 +n12562785 5851 +n12284821 5851 +n12401335 5851 +n12570394 5851 +n11759224 5851 +n12286988 5851 +n12491826 5851 +n12527738 5851 +n12696492 5851 +n12325234 5851 +n12198286 5851 +n12330891 5851 +n11650558 5851 +n12405714 5851 +n12284262 5851 +n12714755 5851 +n13109733 5851 +n12262553 5851 +n12506341 5851 +n12303462 5851 +n12260799 5851 +n12302071 5851 +n12492106 5851 +n11762433 5851 +n12582231 5851 +n12774299 5851 +n13108481 5851 +n12267411 5851 +n11756092 5851 +n12662772 5851 +n13108662 5851 +n12528549 5851 +n12690653 5851 +n12180885 5851 +n13108545 5851 +n13108323 5851 +n12334293 5851 +n12670758 5851 +n12286826 5851 +n12724942 5851 +n12155009 5851 +n12570703 5851 +n12523475 5851 +n12154773 5851 +n12915811 5851 +n12268246 5851 +n13108131 5851 +n12806732 5851 +n12524188 5851 +n11758799 5851 +n12496427 5851 +n12568186 5980 +n12495895 5980 +n12196527 5982 +n12196336 5982 +n12196694 5982 +n12203529 5984 +n12204175 5984 +n12282933 5992 +n12282527 5992 +n12283542 5992 +n12282737 5992 +n12282235 5992 +n12402051 5997 +n12402840 5997 +n12401684 5997 +n12402348 5997 +n12402596 5997 +n11759853 5999 +n11759404 5999 +n12406715 6008 +n12406488 6008 +n12407890 6008 +n12406902 6008 +n12330469 6011 +n12345899 6011 +n11709674 6011 +n12329473 6011 +n12200143 6011 +n11712282 6011 +n12752205 6011 +n13110915 6011 +n12513933 6011 +n12189987 6011 +n12731401 6011 +n12717224 6011 +n12717072 6011 +n12946849 6011 +n12756457 6011 +n12201580 6011 +n11703669 6011 +n12491017 6011 +n12190410 6011 +n12242409 6011 +n07754894 6011 +n12818346 6011 +n12658308 6011 +n12658118 6011 +n12494794 6011 +n12317296 6011 +n12651821 6011 +n11711764 6071 +n11710136 6071 +n11711537 6071 +n11710393 6071 +n12755225 6075 +n12753573 6075 +n12754648 6075 +n12754781 6075 +n12755727 6075 +n12754981 6075 +n12755387 6075 +n12753007 6075 +n12753245 6075 +n12754003 6075 +n12759273 6076 +n12318378 6076 +n12288823 6076 +n12319204 6111 +n12319414 6111 +n12732491 6079 +n12733647 6079 +n12732756 6079 +n12732009 6079 +n12733870 6079 +n12732966 6117 +n12733218 6117 +n12948495 6082 +n12948251 6082 +n12948053 6082 +n12947313 6082 +n12757303 6083 +n12757458 6083 +n11704093 6085 +n11705171 6085 +n12707781 6095 +n12399132 6095 +n12400720 6095 +n12345280 6095 +n11695599 6095 +n12771192 6095 +n12704343 6095 +n12638218 6095 +n12644902 6095 +n12190869 6095 +n12373100 6095 +n12300840 6095 +n12743352 6095 +n12651611 6095 +n12629666 6095 +n12636224 6095 +n12648045 6095 +n12399384 6095 +n12301180 6095 +n12744387 6095 +n12640839 6095 +n12745386 6095 +n12633638 6095 +n12771390 6095 +n12761284 6095 +n12400489 6095 +n12333530 6095 +n12333771 6095 +n12333053 6095 +n12641413 6095 +n12332030 6095 +n12711984 6130 +n12709901 6130 +n12708293 6130 +n12713063 6130 +n12711596 6130 +n12709103 6130 +n12709688 6130 +n12710415 6162 +n12710295 6162 +n12710693 6163 +n12708654 6163 +n12708941 6163 +n12643313 6137 +n12638753 6137 +n12646740 6138 +n12645174 6138 +n12650379 6138 +n12634429 6152 +n12633994 6152 +n12634211 6152 +n12635532 6152 +n12635955 6180 +n12635744 6180 +n12643473 6159 +n12649065 6159 +n12641931 6159 +n12642200 6159 +n12650556 6159 +n12649539 6185 +n12649317 6185 +n12646605 6185 +n12647560 6186 +n12648888 6186 +n12263987 6012 +n12263038 6012 +n12306089 6014 +n12305986 6014 +n12305293 6014 +n12304703 6014 +n12305475 6014 +n12262018 6015 +n12261808 6015 +n12261571 6015 +n12595699 6019 +n12587132 6019 +n12583126 6019 +n12596709 6019 +n12591351 6019 +n12596849 6019 +n12582665 6019 +n12596148 6019 +n12595964 6019 +n12582846 6019 +n12587803 6019 +n12591017 6019 +n12588320 6206 +n12588780 6206 +n12585629 6206 +n12597134 6206 +n12598027 6206 +n12597466 6206 +n12583401 6206 +n12593994 6213 +n12590232 6213 +n11757653 6023 +n11756669 6023 +n11757851 6023 +n11664418 6025 +n13108841 6025 +n11647703 6229 +n11628793 6229 +n11658331 6229 +n11623105 6229 +n11630017 6229 +n11628456 6229 +n11658544 6229 +n11643835 6229 +n11624531 6229 +n11661372 6229 +n11645914 6229 +n11630489 6229 +n11640132 6229 +n11608250 6229 +n11620673 6229 +n11618861 6229 +n11627168 6229 +n11623815 6233 +n11624192 6233 +n11623967 6233 +n11635152 6234 +n11634736 6234 +n11635433 6234 +n11636204 6234 +n11644462 6237 +n11644226 6237 +n11644046 6237 +n11626585 6238 +n11625632 6238 +n11625003 6238 +n11626826 6238 +n11625804 6238 +n11626152 6238 +n11626409 6238 +n11646694 6240 +n11646167 6240 +n11632167 6241 +n11631854 6241 +n11632619 6241 +n11616662 6243 +n11611561 6243 +n11611356 6243 +n11617631 6243 +n11612575 6243 +n11611758 6243 +n11614713 6243 +n11615387 6243 +n11612018 6243 +n11611087 6243 +n11612923 6243 +n11616486 6243 +n11618290 6243 +n11612349 6243 +n11611233 6243 +n11617090 6243 +n11614250 6243 +n11618525 6243 +n11615026 6243 +n11617272 6243 +n11614039 6279 +n11613459 6279 +n11615967 6285 +n11614420 6285 +n11621029 6244 +n11622184 6293 +n11622591 6293 +n11621281 6293 +n11622368 6293 +n11621950 6293 +n11621547 6293 +n11621727 6293 +n11619455 6245 +n11619227 6245 +n11627512 6246 +n11628087 6246 +n11627908 6246 +n12691661 6027 +n12691428 6027 +n12316572 6031 +n12334891 6031 +n12340755 6031 +n12316444 6031 +n12336727 6309 +n12338796 6309 +n12338454 6309 +n12336973 6309 +n12336092 6309 +n12336224 6309 +n12337617 6309 +n12725521 6034 +n12727101 6034 +n12729521 6034 +n12726670 6034 +n12729315 6034 +n12729729 6319 +n12731029 6319 +n12270741 6040 +n12271643 6040 +n12278650 6040 +n12279458 6040 +n12269241 6040 +n12275489 6040 +n12273114 6040 +n12276872 6040 +n12278371 6040 +n12272883 6040 +n12269652 6040 +n12273768 6040 +n12277800 6327 +n12271933 6327 +n12279772 6330 +n12270946 6330 +n12269406 6330 +n12275675 6331 +n12276628 6331 +n12275131 6331 +n12274358 6336 +n12272239 6336 +n12277578 6336 +n12501202 6041 +n12814643 6041 +n12493208 6041 +n12807773 6042 +n12807409 6042 +n12807251 6042 +n11758122 6043 +n12915568 6043 +n12656369 5852 +n12656685 5852 +n12547215 5853 +n12547503 5853 +n11944196 5194 +n11984144 5194 +n11805544 5194 +n11874081 5194 +n11965218 5194 +n12392549 5194 +n11956348 5194 +n11945514 6361 +n11944954 6361 +n11998888 6361 +n11953884 6361 +n11954345 6361 +n11955153 6371 +n11954161 6371 +n12421137 5196 +n12421467 5196 +n12411461 5196 +n12451915 5196 +n12425281 5196 +n12459629 5196 +n12421683 6376 +n12422129 6376 +n12421917 6376 +n12411922 6377 +n12418221 6377 +n12416073 6377 +n12413165 6384 +n12414932 6384 +n12412606 6384 +n12412355 6384 +n12414035 6384 +n12413880 6384 +n12453186 6378 +n12452836 6378 +n12450344 6379 +n12426248 6379 +n12429352 6379 +n12460697 6379 +n12449526 6379 +n12473840 6379 +n12458550 6379 +n12449296 6379 +n12472024 6379 +n12457091 6379 +n12465557 6379 +n12461466 6379 +n12454159 6379 +n12431434 6379 +n12451240 6395 +n12451399 6395 +n12450840 6395 +n12428076 6396 +n12428747 6396 +n12427566 6396 +n12427184 6396 +n12426623 6396 +n12427757 6396 +n12461109 6398 +n12460957 6398 +n12454705 6407 +n12454949 6407 +n12435777 6408 +n12435649 6408 +n11819509 5197 +n11819912 5197 +n11842204 5197 +n11852028 6426 +n11851258 6426 +n11847169 6426 +n11853813 6426 +n11848479 6426 +n11844892 6426 +n11851839 6426 +n11845557 6426 +n11849871 6426 +n11849983 6426 +n11851578 6426 +n11854479 6426 +n11844371 6426 +n11853356 6426 +n11845793 6434 +n11845913 6434 +n11784126 5185 +n11783920 5185 +n12832315 5185 +n11723770 5186 +n11724109 5186 +n12766869 5186 +n12455950 5186 +n11723227 5186 +n12757816 5186 +n11773987 5186 +n12766595 5186 +n01324610 5174 +n02153109 5174 +n01323599 5174 +n01314781 5174 +n01321579 5174 +n01317541 5174 +n01318894 5174 +n01314663 5174 +n02311060 5174 +n01317916 5174 +n01321230 5174 +n01314388 5174 +n02075612 5174 +n02152740 5174 +n01466257 5174 +n01316949 5174 +n01905661 5174 +n01320872 5174 +n01319467 5174 +n01316422 5174 +n02157206 5174 +n10300303 5174 +n02152881 5174 +n01324431 5174 +n01321854 6458 +n01321770 6458 +n01956344 6458 +n01613615 6458 +n01318279 6458 +n02376542 6478 +n02122948 6478 +n01888045 6478 +n01322343 6478 +n01887896 6478 +n02412440 6478 +n01322221 6478 +n01322604 6478 +n01323261 6478 +n01322685 6478 +n02395694 6478 +n01504344 6481 +n01504179 6481 +n01318381 6459 +n02122580 6459 +n01317813 6459 +n02469472 6462 +n02309337 6462 +n02311617 6462 +n02264232 6462 +n02299157 6500 +n02310585 6500 +n02299505 6500 +n02302620 6500 +n02295390 6500 +n02310717 6500 +n02288268 6500 +n02297442 6500 +n02300797 6500 +n02285801 6500 +n02307325 6500 +n02376791 6464 +n02377063 6464 +n01323355 6464 +n01469103 6468 +n01468712 6468 +n01471682 6468 +n01473806 6519 +n01627424 6519 +n01861778 6519 +n09828216 6519 +n01459791 6519 +n02156871 6519 +n01661091 6519 +n01503061 6519 +n02512053 6520 +n01477525 6520 +n02528163 6528 +n02512938 6528 +n01482071 6528 +n02638596 6530 +n01457852 6530 +n01455778 6530 +n01456756 6530 +n02552171 6530 +n01428580 6530 +n02549989 6530 +n02640857 6533 +n02641379 6533 +n02639087 6533 +n02639605 6533 +n02640242 6533 +n02554730 6537 +n02618827 6537 +n02549248 6537 +n02603317 6537 +n01451426 6537 +n02548247 6537 +n02642107 6537 +n02657368 6537 +n02603540 6537 +n02652668 6537 +n02560110 6545 +n02556846 6545 +n02555863 6545 +n02581957 6545 +n02564270 6545 +n02623445 6545 +n02565573 6545 +n02610664 6545 +n02590702 6545 +n02588286 6545 +n02620167 6545 +n02573704 6545 +n02576223 6545 +n02606384 6545 +n02605316 6545 +n02619550 6545 +n02561108 6545 +n02619165 6545 +n02610066 6545 +n02562315 6545 +n02586543 6545 +n02593019 6545 +n02594250 6545 +n02616851 6545 +n02585872 6545 +n02607862 6545 +n02557182 6556 +n02557318 6556 +n02557749 6556 +n02624167 6560 +n02628062 6560 +n02631475 6560 +n02630281 6560 +n02631041 6560 +n02629230 6560 +n02626762 6560 +n02625258 6584 +n02625612 6584 +n02624807 6584 +n02626265 6592 +n02625851 6592 +n02627292 6590 +n02627532 6590 +n02576575 6567 +n02579928 6567 +n02580336 6567 +n02576906 6598 +n02579303 6598 +n02578771 6598 +n02578928 6598 +n02580679 6600 +n02580830 6600 +n02607201 6568 +n02607470 6568 +n02607072 6568 +n02605703 6569 +n02606052 6569 +n02605936 6569 +n02561381 6571 +n02561661 6571 +n02561514 6571 +n02564720 6574 +n02563648 6574 +n02563182 6574 +n02563792 6574 +n02562796 6574 +n02565072 6616 +n02565324 6616 +n02599052 6577 +n02596381 6577 +n02597608 6577 +n02596067 6577 +n02595702 6577 +n02598573 6624 +n02598878 6624 +n02642644 6551 +n02649546 6551 +n02643112 6630 +n02643566 6630 +n02643836 6630 +n02644113 6630 +n02658531 6552 +n02657694 6552 +n02660208 6552 +n02654745 6554 +n02654425 6554 +n02656670 6554 +n02655020 6554 +n02655523 6554 +n02653145 6554 +n02656032 6643 +n02655848 6643 +n02541687 6538 +n02542432 6538 +n02524202 6538 +n02533834 6538 +n02543565 6538 +n02517442 6538 +n01438208 6538 +n02526121 6538 +n02529772 6538 +n02518324 6652 +n02520147 6652 +n02519686 6652 +n02519862 6652 +n02583567 6653 +n01444339 6653 +n01446589 6653 +n01438581 6653 +n01439121 6653 +n01448951 6653 +n02584449 6660 +n02584145 6660 +n02583890 6660 +n01446760 6662 +n01447331 6662 +n01448594 6662 +n01448291 6662 +n01439514 6664 +n01442972 6664 +n01440764 6664 +n01443831 6664 +n01443537 6664 +n01443243 6664 +n01449712 6665 +n01449374 6665 +n02527622 6654 +n02527057 6654 +n02527271 6654 +n02532602 6655 +n02533209 6655 +n02566834 6531 +n02537085 6531 +n02534734 6531 +n02514041 6531 +n02568959 6686 +n02568087 6686 +n02570164 6690 +n02569484 6690 +n02537716 6687 +n02538216 6687 +n02537525 6687 +n02537319 6687 +n02538010 6687 +n02536456 6688 +n02535537 6688 +n02535258 6688 +n02536864 6688 +n02535759 6688 +n01482330 6532 +n01495701 6532 +n01487506 6704 +n01495493 6704 +n01486838 6704 +n01488918 6704 +n01492357 6704 +n01494475 6704 +n01483522 6704 +n01488038 6704 +n01489501 6709 +n01491006 6709 +n01489709 6709 +n01489920 6709 +n01490112 6709 +n01491361 6709 +n01490670 6709 +n01493146 6710 +n01492569 6710 +n01484850 6712 +n01484097 6712 +n01483830 6712 +n01498041 6705 +n01496331 6705 +n01499396 6705 +n01500476 6705 +n01500091 6705 +n01501160 6705 +n01498989 6705 +n01629276 6521 +n01639765 6521 +n01629962 6733 +n01630284 6733 +n01629819 6733 +n01637615 6733 +n01632047 6733 +n01631663 6736 +n01630670 6736 +n01630901 6736 +n01632458 6739 +n01632777 6739 +n01632601 6739 +n01645776 6734 +n01640846 6734 +n01644900 6734 +n01643896 6734 +n01650167 6734 +n01644373 6734 +n01646648 6746 +n01646902 6746 +n01646292 6746 +n01646802 6746 +n01646388 6746 +n01647640 6746 +n01646555 6746 +n01642539 6747 +n01641206 6747 +n01641577 6747 +n01641391 6747 +n01642257 6747 +n01641739 6747 +n01650690 6750 +n01652026 6750 +n01886756 6522 +n01871265 6522 +n01871875 6522 +n01874434 6522 +n01862399 6522 +n02082791 6767 +n01887474 6767 +n01889074 6767 +n02372584 6767 +n01888411 6767 +n02453611 6767 +n02430559 6767 +n01887623 6767 +n02469914 6767 +n02075296 6767 +n02139199 6767 +n02062017 6767 +n02323449 6767 +n02372952 6767 +n01888181 6767 +n02329401 6767 +n01887787 6767 +n02453108 6767 +n01888264 6767 +n02461830 6767 +n02370806 6767 +n01891633 6774 +n01893825 6774 +n02454794 6777 +n02456962 6777 +n02454379 6777 +n02460009 6777 +n02458135 6796 +n02457945 6796 +n02457408 6796 +n02460451 6798 +n02461128 6798 +n02470238 6780 +n02501583 6780 +n02472293 6780 +n02470325 6780 +n02496913 6780 +n02484322 6780 +n02475669 6806 +n02474777 6806 +n02475078 6806 +n02470899 6807 +n02483092 6813 +n02480153 6813 +n02483708 6814 +n02483362 6814 +n02481823 6815 +n02480495 6815 +n02480855 6815 +n02482650 6818 +n02482474 6818 +n02481103 6820 +n02481366 6820 +n02481500 6820 +n02500267 6808 +n02497673 6808 +n02499316 6808 +n02499808 6808 +n02499022 6808 +n02484473 6809 +n02489589 6809 +n02486410 6831 +n02485536 6831 +n02489166 6831 +n02488702 6831 +n02486261 6831 +n02487347 6831 +n02484975 6831 +n02488291 6831 +n02486657 6833 +n02486908 6833 +n02487847 6838 +n02487547 6838 +n02493793 6832 +n02490219 6832 +n02494079 6832 +n02493509 6832 +n02492035 6832 +n02492660 6832 +n02491107 6846 +n02490811 6846 +n02507649 6781 +n02120997 6781 +n02134971 6781 +n02083346 6781 +n02441326 6781 +n02131653 6781 +n02509515 6853 +n02508213 6853 +n02509815 6853 +n02508021 6853 +n02509197 6853 +n02510455 6853 +n02127808 6854 +n02121620 6854 +n02128925 6865 +n02129604 6865 +n02128385 6865 +n02130308 6865 +n02129165 6865 +n02128757 6865 +n02129923 6868 +n02129837 6868 +n01323068 6868 +n02129463 6871 +n01322898 6871 +n02121808 6866 +n02124623 6866 +n02122878 6878 +n02123159 6878 +n02123045 6878 +n02123242 6878 +n02124484 6878 +n02124075 6878 +n02124313 6878 +n02122298 6878 +n02123478 6878 +n02123394 6878 +n02123917 6878 +n02123597 6878 +n02122510 6878 +n02122725 6878 +n02122430 6878 +n02126640 6879 +n02125494 6879 +n02127052 6879 +n02125311 6879 +n02125081 6879 +n02126139 6879 +n02126787 6879 +n02125010 6879 +n02127292 6897 +n02127482 6897 +n02127678 6897 +n02127381 6897 +n02138441 6855 +n02137015 6855 +n02137549 6855 +n02138647 6907 +n02138777 6907 +n02084071 6856 +n02115335 6856 +n02114100 6856 +n02083672 6856 +n02115096 6856 +n02118333 6856 +n02117135 6856 +n02110958 6912 +n02112826 6912 +n02111500 6912 +n02112706 6912 +n02113335 6912 +n02084861 6912 +n02111129 6912 +n02112497 6912 +n02110341 6912 +n02084732 6912 +n02111626 6912 +n02085374 6912 +n02087122 6912 +n02103406 6912 +n02110806 6912 +n02113978 6912 +n02111277 6912 +n02085272 6912 +n02113186 6920 +n02113023 6920 +n02113799 6923 +n02113624 6923 +n02113712 6923 +n02112018 6929 +n02112350 6929 +n02112137 6929 +n02111889 6929 +n02086346 6930 +n02086240 6930 +n02087046 6930 +n02085936 6930 +n02085782 6930 +n02085620 6930 +n02086079 6930 +n02086753 6946 +n02086646 6946 +n02086910 6946 +n02092468 6931 +n02087394 6931 +n02089468 6931 +n02098550 6931 +n02087551 6931 +n02089232 6931 +n02096437 6956 +n02096756 6956 +n02095412 6956 +n02096051 6956 +n02098286 6956 +n02093859 6956 +n02094114 6956 +n02093754 6956 +n02094433 6956 +n02095314 6956 +n02093647 6956 +n02097474 6956 +n02097658 6956 +n02098413 6956 +n02097298 6956 +n02096177 6956 +n02096585 6956 +n02095050 6956 +n02096294 6956 +n02093056 6956 +n02094258 6956 +n02093991 6956 +n02094562 6956 +n02098105 6956 +n02097209 6963 +n02097130 6963 +n02097047 6963 +n02095570 6964 +n02095727 6964 +n02095889 6964 +n02093256 6981 +n02093428 6981 +n02094721 6984 +n02094931 6984 +n02098906 6959 +n02099997 6959 +n02098806 6959 +n02100399 6959 +n02101108 6959 +n02099029 6959 +n02100583 6997 +n02100236 6997 +n02101006 6999 +n02100735 6999 +n02100877 6999 +n02102318 7000 +n02102605 7000 +n02101861 7000 +n02101388 7000 +n02101556 7000 +n02102480 7000 +n02102973 7000 +n02102040 7009 +n02102177 7009 +n02099267 7001 +n02099601 7001 +n02099429 7001 +n02099849 7001 +n02099712 7001 +n02091635 6960 +n02088466 6960 +n02090475 6960 +n02088238 6960 +n02091244 6960 +n02091467 6960 +n02088839 6960 +n02091831 6960 +n02088094 6960 +n02089078 6960 +n02088632 6960 +n02092002 6960 +n02090379 6960 +n02089555 6960 +n02088364 6960 +n02092339 6960 +n02090827 6960 +n02090622 7023 +n02090721 7023 +n02089973 7034 +n02089867 7034 +n02091134 7037 +n02091032 7037 +n02109047 6932 +n02103841 6932 +n02109961 6932 +n02108551 6932 +n02109811 6932 +n02109525 6932 +n02108915 6932 +n02106854 6932 +n02108672 6932 +n02107420 6932 +n02108422 6932 +n02104523 6932 +n02108089 6932 +n02108254 6932 +n02104029 7045 +n02104280 7045 +n02106966 7045 +n02104365 7045 +n02107142 7060 +n02107312 7060 +n02110627 7060 +n02110185 7048 +n02110063 7048 +n02107574 7053 +n02108000 7053 +n02107683 7053 +n02107908 7053 +n02104882 7055 +n02105412 7055 +n02105855 7055 +n02105505 7055 +n02106166 7055 +n02106030 7055 +n02106550 7055 +n02105641 7055 +n02106662 7055 +n02105251 7055 +n02106382 7055 +n02105056 7071 +n02105162 7071 +n02116738 6913 +n02115641 6913 +n02115913 6913 +n02114855 6914 +n01322508 6914 +n02114712 6914 +n02114548 6914 +n02114367 6914 +n02119022 6917 +n02119477 6917 +n02119789 6917 +n02120079 6917 +n02120505 6917 +n02119634 6917 +n02117900 6918 +n02117512 6918 +n02442845 6857 +n02443484 6857 +n02446206 6857 +n02450295 6857 +n02445394 6857 +n02444819 6857 +n02441942 6857 +n02443114 6857 +n02449350 6857 +n02445715 6857 +n02447366 6857 +n02443346 6857 +n02445004 7105 +n02445171 7105 +n02134084 6858 +n02133161 6858 +n01322983 6858 +n02133704 6858 +n02132136 6858 +n02134418 6858 +n02132580 7118 +n02132788 7118 +n02141306 6782 +n02140049 6782 +n02139671 6782 +n02146371 7122 +n02145424 7122 +n02147591 7126 +n02147947 7126 +n02062430 6783 +n02073250 6783 +n02075927 6783 +n02062744 7129 +n02066707 7132 +n02063224 7132 +n02068974 7133 +n02068541 7133 +n02070430 7135 +n02069412 7135 +n02069701 7135 +n02071636 7135 +n02071294 7135 +n02072798 7135 +n02070174 7139 +n02069974 7139 +n02066245 7134 +n02064338 7134 +n02064816 7134 +n02065407 7146 +n02065026 7146 +n02073831 7130 +n02074367 7130 +n02081571 7131 +n02076196 7131 +n02079389 7153 +n02076779 7153 +n02080415 7154 +n02079851 7154 +n02080146 7154 +n02077658 7155 +n02077152 7155 +n02077923 7155 +n02078574 7161 +n02078738 7161 +n02079005 7161 +n02328429 6784 +n02323902 6784 +n02324045 7166 +n02326432 7166 +n02325722 7167 +n02325366 7167 +n02324587 7167 +n02324850 7167 +n02324514 7167 +n02328150 7167 +n02324431 7167 +n02327842 7168 +n02326862 7168 +n02327028 7168 +n02367492 6787 +n02331046 6787 +n02365480 6787 +n02343320 6787 +n02341974 6787 +n02346627 6787 +n02366959 6787 +n02339376 6787 +n02363005 6787 +n02342885 6787 +n02359324 6787 +n02355227 6787 +n02361337 6787 +n02359556 6787 +n02364520 6787 +n02343772 6787 +n02330245 6787 +n02338145 6787 +n02353861 7180 +n02333546 7180 +n02333909 7180 +n02360282 7190 +n02358091 7190 +n02359915 7190 +n02355477 7190 +n02358890 7201 +n02358390 7201 +n02356381 7203 +n02357111 7203 +n02356977 7203 +n02357401 7203 +n02356798 7203 +n02361706 7191 +n02361587 7191 +n02364840 7193 +n02364673 7193 +n02332755 7195 +n02332156 7195 +n02503517 6789 +n02504458 7217 +n02504013 7217 +n02394477 6792 +n02373336 6792 +n02399000 7220 +n02437136 7220 +n02395003 7220 +n02437616 7220 +n02438580 7220 +n02397744 7220 +n02398521 7220 +n02397529 7220 +n02429456 7222 +n02430045 7222 +n02401031 7222 +n02439033 7222 +n02439398 7222 +n02434190 7231 +n02433925 7231 +n02433318 7231 +n02432983 7231 +n02431337 7231 +n02432511 7231 +n02430830 7231 +n02431122 7231 +n02434954 7231 +n02432291 7231 +n02431785 7231 +n02431976 7231 +n02433546 7231 +n02432704 7231 +n02414578 7232 +n02410509 7232 +n02411206 7232 +n02407959 7232 +n02402010 7232 +n02419796 7232 +n02411705 7232 +n02418064 7232 +n02416519 7232 +n02416104 7249 +n02415435 7249 +n02415253 7249 +n02415577 7259 +n02415829 7259 +n02410702 7250 +n02410900 7250 +n02408817 7252 +n02408429 7252 +n02409508 7252 +n02404573 7253 +n02402175 7253 +n02404906 7253 +n02402425 7253 +n02405302 7269 +n02410011 7269 +n02404186 7271 +n02403003 7271 +n02403325 7271 +n02403231 7271 +n02403740 7271 +n02403454 7271 +n02406174 7271 +n02404432 7274 +n02406647 7274 +n02407625 7274 +n02407071 7274 +n02405929 7274 +n02407276 7274 +n02407390 7280 +n02406533 7280 +n02424305 7254 +n02421136 7254 +n02420509 7254 +n02427724 7254 +n02426813 7254 +n02426481 7254 +n02421792 7254 +n02421449 7254 +n02424695 7254 +n02420828 7254 +n02422391 7254 +n02422699 7254 +n02424486 7254 +n02425887 7254 +n02422106 7254 +n02424085 7254 +n02428508 7254 +n02428349 7254 +n02423022 7254 +n02424909 7297 +n02425228 7297 +n02423218 7307 +n02423589 7307 +n02413131 7255 +n02413050 7255 +n02411999 7255 +n02412210 7255 +n02412080 7255 +n02418465 7256 +n02419336 7256 +n02419634 7256 +n02416964 7257 +n02416820 7257 +n02417914 7257 +n02417387 7257 +n02417070 7257 +n02416880 7257 +n02417534 7257 +n02437482 7223 +n02437312 7223 +n02396427 7224 +n02397096 7224 +n02396014 7224 +n02395406 7224 +n02438173 7225 +n02438272 7225 +n02391994 7221 +n02393580 7221 +n02374149 7221 +n02393940 7221 +n02392434 7335 +n02393161 7335 +n02392824 7335 +n02374451 7337 +n02391049 7337 +n02389346 7337 +n02388917 7342 +n02377603 7342 +n02382948 7342 +n02389128 7342 +n02381460 7342 +n02389261 7342 +n02382204 7342 +n02375302 7342 +n02376918 7342 +n02387722 7342 +n02388832 7342 +n02381609 7342 +n02377703 7342 +n02388735 7342 +n02386014 7342 +n02380464 7342 +n02386310 7342 +n02377480 7342 +n02380335 7342 +n02382437 7342 +n02389026 7342 +n02385214 7347 +n02383231 7347 +n02388276 7347 +n02377291 7353 +n02377181 7353 +n02377388 7353 +n02379430 7357 +n02378969 7357 +n02378541 7357 +n02381364 7357 +n02379329 7357 +n02381004 7357 +n02381261 7357 +n02379908 7357 +n02379183 7357 +n02386141 7359 +n02386224 7359 +n02382338 7361 +n02387254 7361 +n02386496 7361 +n02386853 7385 +n02387093 7385 +n02386968 7385 +n02387346 7385 +n02382039 7363 +n02380745 7363 +n02380583 7363 +n02382750 7364 +n02382635 7364 +n02382850 7364 +n02391234 7343 +n02391373 7343 +n02391508 7343 +n02390015 7344 +n02389779 7344 +n02389559 7344 +n01872401 6769 +n01873310 6769 +n01872772 6769 +n01877134 6770 +n01882714 6770 +n01883070 6770 +n01875313 6770 +n01874928 6770 +n01883513 6770 +n01881171 6770 +n01877606 7405 +n01877812 7405 +n01878929 7413 +n01879509 7413 +n01884834 7410 +n01885498 7410 +n01662622 6526 +n01661818 6526 +n01662784 7418 +n01669372 7420 +n01669191 7420 +n01666228 7420 +n01667778 7420 +n01672032 7420 +n01669654 7420 +n01663401 7420 +n01665932 7420 +n01668665 7420 +n01670092 7420 +n01667114 7420 +n01668892 7420 +n01664990 7427 +n01664065 7427 +n01663782 7427 +n01665541 7427 +n01664369 7427 +n01664674 7437 +n01664492 7437 +n01670802 7430 +n01671125 7430 +n01670535 7430 +n01671479 7430 +n01696633 7419 +n01726692 7419 +n01673282 7419 +n01674464 7419 +n01699831 7419 +n01698434 7444 +n01697178 7444 +n01698640 7444 +n01699040 7444 +n01697611 7450 +n01697457 7450 +n01740551 7445 +n01752165 7445 +n01751748 7445 +n01745125 7445 +n01741562 7445 +n01727646 7445 +n01753488 7456 +n01752736 7456 +n01752585 7456 +n01753032 7456 +n01753959 7456 +n01754533 7465 +n01754370 7465 +n01754876 7465 +n01757901 7468 +n01757677 7468 +n01755581 7468 +n01757115 7468 +n01755740 7468 +n01756089 7468 +n01756508 7468 +n01756291 7468 +n01756733 7468 +n01757343 7468 +n01747885 7458 +n01749939 7458 +n01751472 7458 +n01747589 7458 +n01749582 7458 +n01746359 7458 +n01745484 7458 +n01748264 7479 +n01748906 7479 +n01741943 7459 +n01743605 7488 +n01742821 7488 +n01742172 7488 +n01743086 7488 +n01744100 7489 +n01743936 7489 +n01744401 7489 +n01730960 7460 +n01735189 7460 +n01733757 7460 +n01729322 7460 +n01732244 7460 +n01731545 7460 +n01737021 7460 +n01729977 7460 +n01730812 7460 +n01730563 7460 +n01728572 7460 +n01728920 7460 +n01739381 7460 +n01734418 7460 +n01740131 7460 +n01735577 7497 +n01735439 7497 +n01734104 7498 +n01733957 7498 +n01732614 7500 +n01732789 7500 +n01737875 7502 +n01737472 7502 +n01737728 7502 +n01730185 7503 +n01730307 7503 +n01734808 7509 +n01734637 7509 +n01675722 7447 +n01693783 7447 +n01694709 7447 +n01684133 7447 +n01692333 7447 +n01695060 7447 +n01685808 7447 +n01676755 7447 +n01687665 7447 +n01674990 7447 +n01694178 7447 +n01692864 7447 +n01689411 7447 +n01681940 7531 +n01681653 7531 +n01678343 7531 +n01682714 7531 +n01682435 7531 +n01681328 7531 +n01680264 7531 +n01679626 7531 +n01677366 7531 +n01677747 7531 +n01679962 7531 +n01680655 7543 +n01680478 7543 +n01687978 7532 +n01689081 7532 +n01688243 7532 +n01693334 7535 +n01693175 7535 +n01690149 7536 +n01689811 7536 +n01700470 7448 +n01713764 7448 +n01701859 7557 +n01704323 7557 +n01515303 6527 +n01844917 6527 +n01524359 6527 +n01514668 6527 +n01833805 6527 +n01838038 6527 +n01825930 6527 +n01844551 6527 +n01604330 6527 +n01834918 6527 +n01822602 6527 +n01514752 6527 +n01517565 6527 +n01789386 6527 +n01844231 6527 +n01816887 6527 +n01517966 6527 +n01503976 6527 +n01514859 6527 +n02000954 7562 +n01858441 7562 +n02016358 7562 +n02021795 7562 +n01845132 7562 +n02008041 7580 +n02014237 7580 +n02021050 7580 +n02018795 7580 +n02005790 7580 +n02002075 7580 +n02013177 7580 +n02012849 7580 +n02013706 7580 +n02014524 7580 +n02007558 7580 +n02014941 7580 +n02006656 7580 +n02005399 7580 +n02022684 7580 +n02008497 7585 +n02010453 7585 +n02009229 7585 +n02011281 7585 +n02008643 7585 +n02008796 7585 +n02011460 7585 +n02010728 7601 +n02011016 7601 +n02009750 7605 +n02009508 7605 +n02009380 7605 +n02009912 7605 +n02010272 7605 +n02012185 7606 +n02011805 7606 +n02006063 7589 +n02006364 7589 +n02003204 7590 +n02002724 7590 +n02002556 7590 +n02004131 7590 +n02003839 7590 +n02004492 7590 +n02004855 7590 +n02017725 7596 +n02015357 7596 +n02016066 7596 +n02015554 7596 +n02018027 7596 +n02018368 7629 +n02018207 7629 +n02006985 7597 +n02007284 7597 +n02023341 7599 +n02034129 7599 +n02034295 7599 +n02036053 7599 +n02040266 7599 +n02037110 7599 +n02034661 7599 +n02031585 7599 +n02031934 7599 +n02030996 7599 +n02036711 7599 +n02026059 7599 +n02033779 7599 +n02038993 7599 +n02033561 7599 +n02037464 7599 +n02024479 7634 +n02025239 7634 +n02023992 7634 +n02024763 7634 +n02025043 7634 +n02023855 7634 +n02034971 7640 +n02035210 7640 +n02032222 7642 +n02032355 7642 +n02032480 7642 +n02033041 7642 +n02030287 7645 +n02027897 7645 +n02030837 7645 +n02029087 7645 +n02029378 7645 +n02028035 7645 +n02027075 7645 +n02028900 7645 +n02027492 7645 +n02029706 7645 +n02027357 7645 +n02028727 7645 +n02030035 7645 +n02026948 7645 +n02028175 7645 +n02028342 7676 +n02028451 7676 +n02037869 7649 +n02038466 7649 +n01858845 7581 +n01858906 7581 +n01860002 7581 +n01858281 7581 +n01859190 7581 +n01858780 7581 +n01859325 7581 +n01860187 7581 +n01859496 7581 +n01859689 7689 +n01859852 7689 +n02016956 7582 +n02017213 7582 +n02016816 7582 +n02040505 7583 +n02057731 7583 +n02050004 7583 +n02045369 7583 +n02049088 7583 +n02051474 7583 +n02055658 7583 +n02047614 7583 +n02041085 7695 +n02044178 7695 +n02043808 7695 +n02043333 7703 +n02041246 7703 +n02043063 7703 +n02042472 7707 +n02041678 7707 +n02042180 7707 +n02041875 7707 +n02042759 7707 +n02042046 7707 +n02044778 7704 +n02044517 7704 +n02059162 7696 +n02058221 7696 +n02058594 7696 +n02060411 7717 +n02060889 7717 +n02060133 7717 +n02050442 7697 +n02050313 7697 +n02051059 7697 +n02050586 7697 +n02050809 7697 +n02045864 7698 +n02046759 7698 +n02045596 7698 +n02047260 7729 +n02046939 7729 +n02047411 7729 +n02047045 7729 +n02052775 7700 +n02054036 7700 +n02054502 7700 +n02051845 7700 +n02053083 7700 +n02054711 7700 +n02055107 7700 +n02052204 7738 +n02052365 7738 +n02053425 7739 +n02053584 7739 +n02055803 7701 +n02056728 7746 +n02057035 7746 +n02056570 7746 +n02057330 7746 +n02056228 7746 +n02048115 7702 +n02048353 7702 +n02047975 7702 +n01845477 7584 +n01855672 7755 +n01846331 7755 +n01856890 7756 +n01857851 7756 +n01857079 7756 +n01856380 7756 +n01857512 7756 +n01857325 7756 +n01856072 7756 +n01856553 7756 +n01856155 7756 +n01857632 7756 +n01847253 7757 +n01851375 7757 +n01849676 7757 +n01852329 7757 +n01850192 7757 +n01847978 7757 +n01852400 7757 +n01848840 7757 +n01849157 7757 +n01847806 7757 +n01849466 7757 +n01848123 7757 +n01850553 7757 +n01847089 7757 +n01851895 7757 +n01849863 7757 +n01852142 7757 +n01847000 7757 +n01852671 7757 +n01848976 7757 +n01847407 7757 +n01848648 7757 +n01852861 7757 +n01851207 7757 +n01851038 7757 +n01850373 7757 +n01850873 7757 +n01847170 7757 +n01851573 7769 +n01851731 7769 +n01848555 7779 +n01848323 7779 +n01848453 7779 +n01853195 7790 +n01853870 7790 +n01854415 7790 +n01853498 7790 +n01853666 7790 +n01854838 7803 +n01855032 7803 +n01855476 7803 +n01855188 7803 +n01854700 7803 +n01584225 7563 +n01546506 7563 +n01546921 7563 +n01525720 7563 +n01546039 7563 +n01539573 7563 +n01585121 7811 +n01585715 7811 +n01584695 7811 +n01586374 7811 +n01584853 7811 +n01586020 7811 +n01552813 7813 +n01551711 7813 +n01555004 7813 +n01554448 7813 +n01547832 7813 +n01548301 7827 +n01549886 7827 +n01549430 7827 +n01550172 7827 +n01549641 7827 +n01555305 7827 +n01549053 7828 +n01548865 7828 +n01548492 7828 +n01563128 7814 +n01589718 7814 +n01578575 7814 +n01576695 7814 +n01528654 7814 +n01591697 7814 +n01594004 7814 +n01557185 7814 +n01527347 7814 +n01597022 7814 +n01598588 7814 +n01527617 7814 +n01576076 7814 +n01555809 7814 +n01587834 7814 +n01602630 7814 +n01597336 7814 +n01538955 7814 +n01529672 7814 +n01600657 7814 +n01601694 7814 +n01527194 7814 +n01586941 7814 +n01588002 7814 +n01527917 7814 +n01587526 7814 +n01601068 7814 +n01603600 7814 +n01602832 7814 +n01571904 7814 +n01575745 7814 +n01566645 7814 +n01594372 7814 +n01589286 7814 +n01526521 7814 +n01582856 7814 +n01528396 7814 +n01528845 7814 +n01556182 7814 +n01542786 7814 +n01590583 7814 +n01564914 7837 +n01567133 7837 +n01563746 7837 +n01564394 7837 +n01563449 7837 +n01565078 7837 +n01570676 7879 +n01570839 7879 +n01570267 7879 +n01567678 7879 +n01569060 7879 +n01568892 7879 +n01568294 7879 +n01569971 7879 +n01569262 7879 +n01567879 7879 +n01568720 7879 +n01569423 7879 +n01563945 7880 +n01564217 7880 +n01566207 7881 +n01565599 7881 +n01565930 7881 +n01564773 7881 +n01579410 7839 +n01581984 7839 +n01579578 7839 +n01582398 7839 +n01580077 7839 +n01579260 7839 +n01579028 7839 +n01582220 7839 +n01579149 7839 +n01580870 7906 +n01581166 7906 +n01577035 7840 +n01578180 7840 +n01577659 7840 +n01593028 7842 +n01592084 7842 +n01592694 7842 +n01592387 7842 +n01592540 7917 +n01592257 7917 +n01562265 7844 +n01558993 7844 +n01559477 7844 +n01558461 7844 +n01558307 7844 +n01558149 7844 +n01560105 7844 +n01558594 7844 +n01557962 7844 +n01558765 7844 +n01561732 7844 +n01562014 7844 +n01560280 7844 +n01562451 7844 +n01561452 7844 +n01560419 7844 +n01560636 7844 +n01559804 7844 +n01560793 7938 +n01560935 7938 +n01598988 7847 +n01599556 7847 +n01600085 7847 +n01599269 7942 +n01599159 7942 +n01597906 7853 +n01598074 7853 +n01597737 7853 +n01533651 7855 +n01534155 7855 +n01540233 7855 +n01531178 7855 +n01534762 7855 +n01533893 7855 +n01537134 7855 +n01531344 7855 +n01541386 7855 +n01531512 7855 +n01533481 7855 +n01541922 7855 +n01533000 7855 +n01544704 7855 +n01530575 7855 +n01532325 7855 +n01532511 7855 +n01531811 7855 +n01534582 7855 +n01532829 7855 +n01530439 7855 +n01533339 7855 +n01531971 7855 +n01534433 7855 +n01541102 7952 +n01540566 7952 +n01540832 7952 +n01536644 7954 +n01535469 7954 +n01536334 7954 +n01536186 7954 +n01535690 7954 +n01536780 7954 +n01536035 7954 +n01537544 7956 +n01538059 7956 +n01538630 7956 +n01537895 7956 +n01538200 7956 +n01603812 7864 +n01603953 7864 +n01573898 7866 +n01573074 7866 +n01572328 7866 +n01572782 7866 +n01574045 7866 +n01573240 7992 +n01573360 7992 +n01572654 7993 +n01572489 7993 +n01574560 7995 +n01575117 7995 +n01574390 7995 +n01575401 7995 +n01595450 7869 +n01595168 7869 +n01595624 7869 +n01594787 7869 +n01594968 7869 +n01595974 8006 +n01596273 8006 +n01583209 7872 +n01583495 7872 +n01543632 7876 +n01544389 7876 +n01591123 7877 +n01591005 7877 +n01591301 7877 +n01539925 7816 +n01540090 7816 +n01834540 7565 +n01834177 7565 +n01843065 7566 +n01838598 7566 +n01842235 7566 +n01843719 7566 +n01843383 7566 +n01839598 8023 +n01839330 8023 +n01839086 8023 +n01841102 8023 +n01841679 8023 +n01840775 8023 +n01839750 8023 +n01841441 8030 +n01841288 8030 +n01827403 7567 +n01826364 7567 +n01830915 7567 +n01830042 7567 +n01829413 7567 +n01826680 7567 +n01829869 7567 +n01828970 7567 +n01828556 8036 +n01827793 8036 +n01828096 8036 +n01616318 7569 +n01605630 7569 +n01618503 7569 +n01613294 7569 +n01621127 7569 +n01616764 8047 +n01618922 8047 +n01617766 8052 +n01617443 8052 +n01618082 8052 +n01617095 8052 +n01620414 8053 +n01619310 8053 +n01620735 8053 +n01619536 8053 +n01619835 8061 +n01620135 8061 +n01609751 8048 +n01606522 8048 +n01607812 8048 +n01608265 8048 +n01610955 8048 +n01610552 8048 +n01606809 8048 +n01616086 8048 +n01608432 8048 +n01607600 8048 +n01607962 8048 +n01606672 8048 +n01609956 8064 +n01610226 8064 +n01613177 8068 +n01611800 8068 +n01611472 8068 +n01612628 8068 +n01612476 8068 +n01612275 8068 +n01611969 8068 +n01612122 8068 +n01609391 8072 +n01609062 8072 +n01608814 8072 +n01613807 8050 +n01614343 8050 +n01615121 8050 +n01614925 8050 +n01614038 8050 +n01614556 8050 +n01615703 8091 +n01615458 8091 +n01622959 8051 +n01621635 8051 +n01623880 8051 +n01623425 8051 +n01622352 8051 +n01623615 8051 +n01622120 8051 +n01625562 8051 +n01623706 8051 +n01624115 8051 +n01624537 8051 +n01622483 8051 +n01623110 8051 +n01624833 8051 +n01622779 8051 +n01837072 7570 +n01835276 7570 +n01825278 7571 +n01823013 7571 +n01824575 8115 +n01824035 8115 +n01521399 7573 +n01521756 7573 +n01518878 7573 +n01519873 7573 +n01519563 7573 +n01789740 7574 +n01810700 7574 +n01801876 7574 +n01791463 7574 +n01791107 7574 +n02153203 7574 +n01794344 8123 +n01791954 8123 +n01794158 8123 +n01809106 8123 +n01791625 8123 +n01792429 8133 +n01792158 8133 +n01793435 8133 +n01792042 8133 +n01793715 8133 +n01792640 8133 +n01793249 8139 +n01792955 8139 +n01815601 8124 +n01811909 8124 +n01814370 8143 +n01812337 8143 +n01813088 8143 +n01812662 8143 +n01814921 8144 +n01814755 8144 +n01813532 8145 +n01813385 8145 +n01813948 8145 +n01814217 8145 +n01802721 8128 +n01810268 8128 +n01795088 8128 +n01803078 8154 +n01806567 8154 +n01807496 8154 +n01807105 8157 +n01803362 8157 +n01804163 8157 +n01805801 8157 +n01806297 8163 +n01806364 8163 +n01806143 8163 +n01806467 8163 +n01804478 8158 +n01806847 8158 +n01804653 8158 +n01808140 8159 +n01807828 8159 +n01797307 8156 +n01798484 8156 +n01797020 8156 +n01797886 8156 +n01797601 8156 +n01796729 8156 +n01795545 8156 +n01796340 8156 +n01819734 7576 +n01821203 7576 +n01819115 7576 +n01817346 7576 +n01818832 7576 +n01817953 7576 +n01818515 7576 +n01818299 7576 +n01820052 7576 +n01820348 7576 +n01817263 7576 +n01821869 8182 +n01822300 8182 +n01819313 8183 +n01819465 8183 +n01821076 8190 +n01820546 8190 +n01317089 6469 +n01317294 6469 +n01918744 6470 +n01922303 6470 +n01940736 6470 +n02316707 6470 +n01909422 6470 +n01767661 6470 +n01906749 6470 +n01930112 8201 +n01934440 8201 +n01924916 8201 +n01938454 8208 +n01935395 8208 +n01955084 8202 +n01955933 8202 +n01968315 8202 +n01942177 8202 +n01960459 8213 +n01963317 8213 +n01956481 8213 +n01963571 8213 +n01959985 8213 +n01965889 8213 +n01961985 8213 +n01957335 8218 +n01958038 8218 +n01959492 8218 +n01964441 8219 +n01964271 8219 +n01965529 8219 +n01969726 8214 +n01968897 8214 +n01972541 8214 +n01970164 8229 +n01970667 8229 +n01951274 8215 +n01953361 8215 +n01943899 8215 +n01945845 8215 +n01943087 8215 +n01953762 8215 +n01950731 8215 +n01945685 8215 +n01944390 8215 +n01949085 8237 +n01947396 8237 +n01946630 8237 +n01944812 8242 +n01945143 8242 +n01944955 8242 +n02317335 8203 +n02321170 8203 +n02319555 8203 +n02319095 8203 +n02321529 8203 +n02317781 8203 +n01909906 8204 +n01914163 8204 +n01913166 8204 +n01910747 8204 +n01915700 8256 +n01914609 8256 +n01915811 8256 +n01916925 8261 +n01916187 8261 +n01916481 8261 +n01917882 8262 +n01917289 8262 +n01784675 8205 +n01974773 8205 +n01768244 8205 +n01786646 8205 +n01769347 8205 +n01787835 8205 +n02309242 8205 +n02159955 8205 +n01785667 8205 +n01994910 8268 +n01976868 8268 +n01990007 8268 +n01975687 8268 +n01976146 8268 +n01990800 8279 +n01992773 8279 +n01991520 8281 +n01991028 8281 +n01982650 8280 +n01986806 8280 +n01986214 8280 +n01987545 8280 +n01976957 8280 +n01985128 8280 +n01984245 8285 +n01984695 8285 +n01983481 8285 +n01981276 8289 +n01979874 8289 +n01978455 8289 +n01978287 8289 +n01980166 8289 +n01982068 8289 +n01770393 8271 +n01770081 8271 +n01776192 8271 +n01772222 8271 +n01776313 8302 +n01779629 8302 +n01779148 8302 +n01772664 8303 +n01775370 8303 +n01774750 8303 +n01775062 8303 +n01773797 8303 +n01774384 8303 +n01773157 8303 +n01773549 8303 +n02226183 8274 +n02236896 8274 +n02263378 8274 +n02232951 8274 +n02163297 8274 +n02262449 8274 +n02246011 8274 +n02188699 8274 +n02272871 8274 +n02273392 8274 +n02231052 8274 +n02161457 8274 +n02236355 8274 +n02312427 8274 +n02231487 8274 +n02162561 8274 +n02164464 8274 +n02241569 8274 +n02262803 8274 +n02206270 8274 +n02274024 8274 +n02312640 8274 +n02268148 8274 +n02270623 8274 +n02207805 8274 +n02226429 8315 +n02229544 8315 +n02228341 8340 +n02226970 8340 +n02241426 8316 +n02240517 8316 +n02266050 8317 +n02264885 8317 +n02264363 8317 +n02236044 8318 +n02236241 8318 +n02233338 8318 +n02234355 8351 +n02234848 8351 +n02233943 8351 +n02251775 8321 +n02256656 8321 +n02258198 8321 +n02257284 8321 +n02250822 8321 +n02259212 8321 +n02252226 8321 +n02200198 8322 +n02205219 8322 +n02203152 8322 +n02196344 8322 +n02190166 8322 +n02198859 8322 +n02196119 8322 +n02201000 8362 +n02202006 8362 +n02195819 8366 +n02195526 8366 +n02192513 8366 +n02191773 8366 +n02190790 8366 +n02192252 8374 +n02191979 8374 +n02169974 8331 +n02168245 8331 +n02167151 8331 +n02169023 8331 +n02165456 8331 +n02171453 8331 +n02180875 8331 +n02183096 8331 +n02169497 8331 +n02176261 8331 +n02176439 8331 +n02165105 8331 +n02177972 8331 +n02168699 8331 +n02166567 8382 +n02166826 8382 +n02171869 8383 +n02175916 8383 +n02175569 8394 +n02172870 8394 +n02173373 8394 +n02174001 8394 +n02172182 8394 +n02172518 8394 +n02174659 8394 +n02243562 8332 +n02244797 8332 +n02212062 8334 +n02218371 8334 +n02219486 8334 +n02206856 8334 +n02216211 8405 +n02215770 8405 +n02212602 8405 +n02213107 8411 +n02212958 8411 +n02213543 8411 +n02213239 8412 +n02213788 8412 +n02220804 8407 +n02221083 8407 +n02221414 8407 +n02209354 8408 +n02208280 8408 +n02211627 8408 +n02210427 8408 +n02211444 8408 +n02209624 8408 +n02208498 8421 +n02208848 8421 +n02274259 8335 +n02283201 8335 +n02281787 8428 +n02274822 8428 +n02281406 8428 +n02277742 8428 +n02279972 8428 +n02280649 8428 +n02282257 8430 +n02282903 8430 +n02282385 8430 +n02275773 8431 +n02278210 8431 +n02276258 8431 +n02276902 8431 +n02279257 8431 +n02277094 8431 +n02276078 8431 +n02275560 8431 +n02277268 8431 +n02276355 8431 +n02276749 8431 +n02278024 8431 +n02281015 8435 +n02281136 8435 +n02305929 8429 +n02301452 8429 +n02295064 8429 +n02298541 8429 +n02284611 8429 +n02287004 8429 +n02291572 8429 +n02305085 8454 +n02301935 8454 +n02304432 8454 +n02303284 8454 +n02302969 8454 +n02292692 8459 +n02291748 8459 +n02268443 8337 +n02268853 8337 +n01321123 6471 +n02376679 6471 +n01323493 6471 +n01338685 5175 +n01387065 5175 +n01339083 8472 +n01339336 8472 +n01339801 8472 +n01339471 8472 +n01397114 8473 +n01389507 8473 +n01397871 8478 +n01410457 8478 +n01407798 8478 +n01424420 8479 +n01392380 8479 +n01395254 8479 +n01396048 8479 +n11542137 5176 +n11544015 5176 +n11542640 5176 +n09626238 5177 +n09856671 5177 +n09605289 5177 +n09622049 5177 +n09971273 5177 +n09882716 5177 +n09621232 5177 +n09902954 5177 +n09620794 5177 +n09727440 5177 +n09624168 5177 +n09752519 5177 +n10378026 5177 +n10500217 5177 +n10514429 5177 +n09610405 5177 +n09617867 5177 +n10355449 5177 +n09618957 5177 +n10002760 5177 +n10384496 5177 +n09637339 5177 +n09613191 5177 +n09836160 5177 +n10274815 5177 +n09890749 5177 +n10112591 5177 +n10260706 5177 +n09606527 5177 +n09767197 5177 +n10709529 5177 +n09976429 5177 +n09918554 5177 +n10588074 5177 +n10565667 5177 +n09990415 5177 +n10120330 5177 +n09616922 5177 +n09622302 5177 +n09630641 5177 +n09796809 5177 +n09614684 5177 +n10635788 5177 +n09645091 5177 +n10405694 5177 +n09676884 5177 +n09638875 5177 +n09874428 5177 +n09627906 5177 +n09628382 5177 +n10522759 5177 +n10247880 5177 +n09624980 5177 +n10529231 5177 +n10024362 5177 +n09614315 5177 +n09612848 5177 +n09632518 5177 +n10147935 5177 +n09871867 5177 +n09620078 5177 +n09634494 5177 +n10077593 5177 +n10040945 5177 +n09623038 5177 +n10560106 5177 +n10289039 5177 +n10422405 5177 +n09774783 5177 +n10042845 5177 +n09831962 5177 +n10726031 5177 +n09923673 5177 +n09610660 5177 +n09626031 5177 +n10401331 5177 +n09621545 5177 +n10362319 5177 +n10665698 5177 +n09906449 5177 +n09939313 5177 +n10439373 5177 +n09607630 5177 +n09631463 5177 +n10451450 5177 +n10541229 5177 +n09793141 5177 +n10633450 5177 +n10530959 5177 +n09629752 5177 +n10560637 5177 +n10431625 5177 +n09619168 5177 +n09763784 5177 +n09636339 5177 +n10235549 5177 +n09845401 5177 +n10513823 5177 +n10610465 5177 +n09951274 5177 +n09816771 8490 +n10401829 8590 +n10307234 8590 +n10505613 8590 +n10148035 8591 +n09874725 8591 +n09944022 8592 +n10015485 8592 +n10728624 8592 +n10308168 8592 +n10200781 8492 +n10480253 8492 +n10376523 8492 +n09903153 8600 +n10748620 8600 +n10581890 8601 +n10045713 8601 +n10165109 8601 +n10694258 8606 +n10509063 8606 +n10559996 8606 +n10366966 8607 +n10305802 8607 +n10421470 8607 +n10164492 8611 +n10477713 8611 +n10020890 8612 +n10679174 8616 +n10632576 8616 +n10189278 8616 +n09894445 8618 +n10504206 8618 +n10559288 8493 +n09917593 8493 +n09833441 8623 +n10384392 8623 +n10060352 8495 +n09840217 8495 +n09777012 8495 +n10309896 8495 +n09905185 8495 +n10686885 8628 +n10209731 8628 +n10093818 8629 +n10754189 8629 +n10411551 8629 +n10577284 8629 +n10285313 8500 +n10333439 8500 +n10624074 8500 +n10287213 8500 +n09871229 8637 +n10078719 8637 +n09843443 8637 +n10173771 8640 +n10192839 8640 +n10419785 8640 +n10406266 8640 +n10288964 8640 +n10804287 8640 +n10665587 8640 +n10153414 8640 +n10406765 8640 +n10611613 8506 +n09805324 8506 +n09824361 8506 +n10316360 8506 +n10707233 8506 +n10696508 8506 +n09858165 8506 +n10175248 8655 +n09979321 8655 +n10692482 8661 +n10396106 8661 +n10427764 8657 +n10385566 8657 +n10439851 8512 +n09820263 8512 +n10533013 8512 +n09854421 8666 +n10304914 8666 +n10575463 8666 +n09915651 8666 +n10453184 8666 +n10101634 8667 +n10701180 8667 +n09835230 8667 +n10746931 8667 +n10542888 8667 +n10604491 8667 +n09764381 8667 +n09929298 8667 +n10019406 8667 +n09785659 8667 +n10618342 8667 +n10782471 8667 +n10701644 8667 +n10105733 8667 +n10638922 8667 +n09842047 8667 +n10315561 8667 +n09835506 8667 +n10153594 8667 +n09830194 8674 +n10263411 8674 +n10157128 8693 +n10498816 8693 +n10689306 8693 +n10604380 8679 +n10634849 8679 +n09923561 8680 +n09764598 8680 +n10086568 8691 +n10007684 8691 +n09841696 8691 +n10321340 8691 +n10092488 8702 +n10386984 8702 +n10387196 8702 +n10205457 8702 +n10578021 8668 +n10098710 8668 +n09836519 8513 +n09836786 8513 +n09836343 8513 +n09877951 8516 +n10300154 8516 +n10095769 8516 +n10435988 8520 +n09930257 8718 +n10387324 8718 +n10098862 8525 +n10642596 8721 +n10331167 8721 +n09946814 8527 +n10299250 8527 +n09896170 8527 +n10415638 8527 +n10091450 8727 +n10069296 8727 +n09989502 8727 +n10226413 8727 +n10493685 8727 +n09765278 8727 +n09930876 8727 +n10340312 8727 +n09990777 8730 +n09834699 8730 +n10737103 8733 +n10649197 8733 +n10701962 8735 +n10415037 8735 +n10151760 8735 +n10229883 8735 +n10732010 8735 +n10603851 8735 +n10599806 8735 +n10369317 8735 +n09903501 8735 +n10755080 8735 +n10098245 8735 +n10382825 8735 +n10536416 8735 +n10036929 8735 +n10624310 8746 +n09842528 8746 +n10085869 8528 +n09991867 8528 +n10078131 8528 +n10627252 8528 +n10682953 8528 +n10237196 8528 +n09789566 8529 +n10182190 8529 +n09899671 8529 +n10150071 8531 +n10091651 8531 +n10806113 8531 +n10249459 8531 +n10317500 8768 +n09822830 8768 +n10448983 8768 +n09862621 8771 +n10540114 8771 +n10009276 8771 +n10333838 8771 +n10730728 8771 +n10721321 8771 +n09659188 8533 +n09650729 8533 +n09652149 8533 +n09659039 8533 +n09729530 8536 +n09641002 8536 +n09725653 8782 +n09846469 8782 +n09750770 8782 +n10486166 8538 +n10169147 8538 +n09684901 8539 +n09683757 8539 +n09682291 8539 +n10364198 8539 +n10518602 8539 +n10341573 8791 +n10672371 8791 +n10332861 8793 +n10112129 8793 +n10602470 8793 +n10727256 8542 +n10508141 8542 +n10652605 8799 +n09881265 8799 +n09933098 8545 +n09812338 8545 +n09920283 8545 +n10078806 8545 +n10339966 8804 +n10667477 8804 +n10566072 8804 +n10469874 8804 +n10624540 8807 +n09809925 8807 +n09846755 8806 +n09873899 8806 +n09779790 8806 +n10034614 8546 +n10449664 8546 +n10034201 8546 +n09951616 8546 +n10037385 8818 +n09846894 8818 +n10282672 8547 +n10053808 8547 +n09815790 8547 +n10137825 8547 +n10605985 8547 +n10604979 8547 +n09861946 8547 +n10763383 8823 +n09841188 8823 +n10644598 8823 +n10548681 8823 +n10791221 8823 +n10583790 8823 +n09873473 8823 +n10763620 8823 +n10548537 8823 +n10120671 8823 +n10241300 8833 +n10318293 8833 +n10176679 8839 +n09932508 8839 +n10186216 8841 +n10134178 8841 +n10079399 8841 +n09821831 8824 +n09934337 8824 +n10324560 8824 +n10063461 8846 +n09886403 8846 +n09760609 8846 +n10260800 8846 +n10655594 8846 +n09938449 8849 +n10183931 8849 +n09972458 8848 +n09813219 8848 +n10049363 8826 +n10372373 8826 +n10076604 8826 +n09835348 8826 +n09974648 8826 +n10433164 8826 +n09859152 8826 +n10727171 8826 +n10308732 8826 +n09833536 8826 +n10582746 8826 +n10393909 8826 +n10013927 8859 +n10225219 8859 +n10202624 8859 +n09800964 8859 +n10465831 8859 +n09787534 8870 +n10174445 8870 +n10441962 8870 +n10132035 8862 +n09896685 8862 +n09934774 8862 +n10279018 8862 +n10793570 8862 +n10155849 8862 +n10087434 8863 +n09964202 8863 +n09811852 8868 +n10348526 8868 +n10317007 8868 +n10058777 8868 +n10360747 8888 +n09941964 8888 +n10347446 8888 +n09770359 8888 +n09941787 8888 +n09942970 8888 +n09809749 8888 +n09770179 8888 +n10208950 8888 +n10580772 8890 +n10093475 8899 +n10645017 8899 +n09943239 8895 +n09943541 8895 +n10263790 8895 +n10283170 8902 +n10259348 8902 +n10092978 8902 +n10296176 8902 +n09893191 8902 +n10123844 8902 +n10259780 8902 +n10259997 8903 +n10510245 8903 +n10622053 8889 +n10058585 8889 +n10690648 8914 +n10523341 8914 +n10739391 8914 +n10476467 8915 +n10512372 8915 +n10802507 8915 +n10753442 8550 +n09733793 8550 +n09738708 8550 +n09641757 8550 +n09738400 8550 +n09727826 8550 +n09686536 8550 +n09724533 8550 +n09744834 8924 +n09743792 8924 +n09744161 8924 +n09742101 8924 +n09689435 8925 +n09734450 8925 +n09644152 8925 +n09750282 8925 +n09673495 8925 +n09718811 8925 +n09718217 8925 +n09712696 8925 +n09718936 8925 +n10711766 8925 +n09694771 8925 +n09719794 8925 +n09714694 8925 +n09675922 8938 +n09676247 8938 +n10774440 8926 +n09720256 8926 +n09725229 8926 +n09731571 8926 +n09691729 8949 +n09693982 8949 +n09712448 8949 +n09697401 8951 +n09696585 8951 +n09722658 8956 +n09724656 8956 +n09723067 8956 +n09694664 8952 +n09712324 8952 +n09689958 8928 +n09695979 8928 +n10327987 8928 +n09688804 8928 +n09730204 8928 +n09711435 8928 +n09713108 8928 +n09731343 8928 +n09717233 8928 +n09695620 8928 +n09728285 8928 +n09707289 8928 +n09701833 8928 +n09700964 8928 +n09750891 8928 +n09715427 8928 +n09708750 8928 +n09705784 8551 +n09734185 8551 +n09752023 8551 +n09635534 8551 +n09696456 8551 +n09732170 8551 +n09730824 8551 +n09719309 8551 +n09734535 8551 +n09736945 8551 +n09720842 8551 +n09692915 8551 +n09751895 8551 +n09724785 8551 +n09747495 8551 +n09734639 8551 +n09749386 8551 +n09705124 8551 +n09731436 8551 +n10303814 8554 +n10450303 8554 +n10722575 8554 +n10054657 8554 +n10631309 8554 +n10249270 8554 +n09913455 8554 +n10162991 8554 +n09807754 8554 +n09505153 8554 +n10209082 8554 +n10323634 8554 +n10104064 8554 +n10001481 9000 +n10242328 9000 +n10159045 9001 +n09932098 9001 +n10253995 9004 +n10005934 9016 +n10578471 9016 +n09770949 9006 +n10004718 9006 +n10570019 9006 +n10289462 9019 +n10069645 9019 +n10187990 9019 +n09916348 9023 +n10727458 9023 +n10320863 9023 +n10572706 9021 +n10572889 9021 +n10038409 9007 +n10756148 9007 +n09927451 9008 +n10243664 9008 +n10502329 9008 +n09988493 9008 +n10373390 9032 +n10470779 9032 +n09928136 9032 +n10750031 9037 +n10081204 9037 +n09857200 9037 +n10013811 9041 +n09894143 9041 +n10313239 9041 +n10082997 8558 +n10677713 8558 +n09787765 8558 +n10485883 8558 +n10275395 9046 +n09913593 9046 +n09772930 8560 +n09633969 8560 +n10195593 9052 +n09756049 9052 +n10607478 9052 +n09855433 8563 +n10017272 8563 +n10630188 8563 +n10522035 8563 +n10521662 8563 +n10380672 9058 +n10210911 9058 +n10382710 9059 +n10164747 9059 +n09782397 9059 +n10524076 9059 +n10467395 9064 +n10467179 9064 +n10698368 9060 +n09792969 9060 +n10525617 8564 +n10675010 8564 +n09889941 8564 +n10557854 8566 +n09618760 8566 +n09899929 8566 +n10116702 9074 +n10258786 9074 +n10508710 9074 +n09873348 8570 +n09870208 8570 +n10793168 8570 +n10098517 9081 +n10314517 9081 +n10629939 9081 +n10477077 9081 +n10261624 9086 +n10082687 9086 +n10262445 9086 +n10167152 9082 +n10098624 9082 +n10674713 9082 +n09838621 9082 +n10047459 8573 +n10091564 8573 +n10740868 8573 +n09872066 9094 +n10070711 9094 +n10628644 8575 +n10421016 8575 +n09915434 8575 +n10588357 8575 +n10529965 8579 +n10334009 8579 +n10339717 8579 +n09818022 8579 +n10412055 8579 +n10335931 8579 +n09945745 8579 +n10432441 8579 +n10607291 8579 +n10583387 8579 +n10718131 8579 +n10542761 8579 +n10147121 8579 +n10738111 9103 +n10159533 9103 +n10223177 9103 +n10185793 9103 +n10553235 9107 +n10293332 9107 +n10178216 9108 +n10563403 9108 +n10488656 8580 +n10619642 8580 +n10276477 8580 +n10620758 9125 +n10450161 9125 +n10043643 9125 +n10043491 9129 +n10313724 9129 +n10084295 8582 +n10787470 8582 +n10333601 8582 +n10131151 8582 +n09871681 9132 +n09981939 9132 +n10055410 9133 +n10243137 9133 +n10377021 9133 +n10368528 9133 +n10025635 9133 +n09874862 9133 +n10613996 9133 +n10472129 9133 +n10598181 9133 +n10129825 9133 +n09847543 9133 +n10173410 9133 +n10780284 9133 +n09889065 9133 +n09832456 9133 +n10780632 9133 +n10117851 9147 +n09827363 9147 +n10247358 9147 +n10282482 9147 +n10092794 9153 +n10375314 9153 +n09981278 9153 +n10082043 8585 +n09972010 8585 +n10237069 8585 +n09792555 8585 +n10236946 8585 +n10568358 8585 +n10207169 8585 +n10236304 8585 +n10734394 8585 +n10373998 8585 +n10595164 8585 +n10357613 9163 +n09823502 9163 +n10146104 9163 +n10602985 9163 +n10145239 9163 +n10267865 9175 +n09854218 9175 +n10399491 9164 +n10102800 9164 +n10102369 9164 +n10406391 9164 +n10300500 9179 +n10080869 9179 +n10332385 9179 +n09988063 9184 +n10375402 9184 +n10145774 9181 +n10143172 9181 +n10145590 9181 +n10345015 9189 +n10142747 9189 +n10142391 9189 +n10146002 9165 +n10267311 9165 +n10141590 9170 +n10092643 9170 +n09918248 9170 +n10671613 9170 +n10141732 9196 +n10145340 9196 +n10145902 9201 +n10145480 9201 +n09827683 9198 +n10135129 9204 +n10465451 9204 +n10353016 9204 +n13001930 5178 +n13040629 5178 +n12969131 5178 +n12985420 5178 +n13052670 5178 +n13037406 5178 +n13077295 5178 +n12987056 5178 +n12979829 5178 +n12975804 5178 +n12974987 5178 +n12985773 5178 +n13044778 5178 +n12985857 5178 +n13035241 5178 +n13043926 5178 +n12982468 5178 +n13035707 5178 +n13044375 5178 +n12969425 5178 +n13060190 5178 +n13054073 5178 +n13040303 5178 +n13028611 5178 +n12997654 5178 +n12983048 5178 +n13062421 5178 +n13054560 5178 +n12963628 9214 +n12980840 9214 +n12991184 9215 +n12989938 9215 +n12992177 9215 +n12988158 9215 +n13029326 9231 +n13029760 9231 +n13011595 9232 +n13049953 9232 +n12998815 9232 +n12997919 9232 +n13052931 9245 +n13050397 9245 +n13012253 9246 +n13001041 9246 +n13005984 9246 +n13000891 9246 +n13007417 9246 +n13019835 9246 +n13013764 9246 +n13006894 9246 +n13002750 9246 +n13017102 9246 +n13232779 9246 +n13009429 9246 +n13013534 9246 +n13003522 9246 +n13001366 9246 +n13009085 9246 +n13022210 9246 +n13002925 9246 +n13006171 9246 +n13003712 9246 +n13001206 9246 +n13004423 9246 +n13001529 9246 +n13003254 9246 +n13003061 9246 +n13032115 9247 +n13032381 9275 +n13033577 9275 +n13055577 9235 +n13055949 9235 +n13055423 9235 +n05430628 5171 +n05450617 9281 +n05449959 9281 +n05451384 9283 +n05453657 9283 +n09369169 1043 +n09454412 1043 +n09403211 1043 +n13086908 1043 +n09416076 1043 +n09251407 1043 +n05218119 1043 +n09444100 1043 +n09438940 1043 +n09257949 1043 +n09189157 9286 +n09475044 9286 +n11691857 9289 +n13102775 9289 +n13087625 9289 +n13022709 9289 +n11675842 9300 +n13152742 9300 +n13125117 9300 +n13129165 9300 +n11690254 9300 +n11669335 9302 +n13134947 9302 +n11676500 9302 +n11675025 9307 +n11674332 9307 +n11669786 9307 +n13131028 9311 +n13132338 9311 +n13132656 9311 +n12301445 9308 +n13133613 9308 +n13141415 9308 +n13137409 9308 +n12642090 9308 +n12267677 9308 +n12658481 9308 +n12144313 9308 +n12158031 9308 +n13135832 9308 +n12620546 9308 +n11636835 9308 +n13139055 9308 +n12144580 9325 +n07929351 9325 +n13136556 9325 +n12768682 9325 +n11689483 9325 +n13136316 9325 +n07770571 9325 +n07737081 9331 +n07774842 9336 +n07774596 9336 +n07775050 9336 +n07772788 9336 +n07771212 9336 +n07772147 9336 +n07772274 9336 +n07774719 9336 +n07737745 9336 +n07772935 9336 +n15086247 9333 +n11879895 9333 +n12576323 9334 +n12532564 9334 +n07814634 9335 +n07775197 9335 +n07770763 9335 +n11748002 9328 +n12172364 9328 +n12515925 9354 +n12560282 9354 +n12578916 9354 +n12560621 9354 +n12544539 9354 +n12024690 9303 +n13154494 9303 +n11690455 9303 +n12927013 9304 +n11953610 9304 +n13128365 9305 +n13133932 9305 +n13163991 9305 +n13134059 9305 +n13131618 9305 +n13130726 9305 +n11678010 9305 +n12136392 9305 +n11979964 9366 +n12088223 9366 +n12462805 9369 +n12433081 9369 +n09218494 9290 +n09381242 9290 +n09460046 9290 +n09451237 9293 +n09450163 9293 +n01904182 9295 +n13155095 9295 +n09432283 9295 +n11705387 9295 +n09438844 9295 +n11692265 9295 +n05237755 9295 +n09416890 9295 +n01956764 9383 +n01904806 9383 +n01904886 9383 +n05586759 9389 +n05581932 9389 +n01904029 9389 +n05238282 9389 +n05254795 9389 +n02469248 9389 +n05256862 9398 +n05258051 9398 +n01899894 9398 +n05261404 9398 +n05259914 9400 +n05261310 9400 +n05260240 9400 +n05262185 9403 +n05261566 9403 +n05262534 9407 +n05262422 9407 +n05263183 9408 +n05263448 9408 +n11524662 3 +n11448153 3 +n09247410 3 +n11508382 9413 +n11524451 9413 diff --git a/data/coco.names b/data/coco.names new file mode 100644 index 0000000..ca76c80 --- /dev/null +++ b/data/coco.names @@ -0,0 +1,80 @@ +person +bicycle +car +motorbike +aeroplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +sofa +pottedplant +bed +diningtable +toilet +tvmonitor +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/data/coco9k.map b/data/coco9k.map new file mode 100644 index 0000000..5155b65 --- /dev/null +++ b/data/coco9k.map @@ -0,0 +1,80 @@ +5177 +3768 +3802 +3800 +4107 +4072 +4071 +3797 +4097 +2645 +5150 +2644 +3257 +2523 +6527 +6866 +6912 +7342 +7255 +7271 +7217 +6858 +7343 +7233 +3704 +4374 +3641 +5001 +3899 +2999 +2631 +5141 +2015 +1133 +1935 +1930 +5144 +5143 +2371 +3916 +3745 +3640 +4749 +4736 +4735 +3678 +58 +42 +771 +81 +152 +141 +786 +700 +218 +791 +2518 +2521 +3637 +2458 +2505 +2519 +3499 +2837 +3503 +2597 +3430 +2080 +5103 +5111 +5102 +3013 +5096 +1102 +3218 +4010 +2266 +1127 +5122 +2360 diff --git a/data/dog.jpg b/data/dog.jpg new file mode 100644 index 0000000..77b0381 Binary files /dev/null and b/data/dog.jpg differ diff --git a/data/eagle.jpg b/data/eagle.jpg new file mode 100644 index 0000000..8b75095 Binary files /dev/null and b/data/eagle.jpg differ diff --git a/data/giraffe.jpg b/data/giraffe.jpg new file mode 100644 index 0000000..a93e8b8 Binary files /dev/null and b/data/giraffe.jpg differ diff --git a/data/goal.txt b/data/goal.txt new file mode 100644 index 0000000..c63d157 --- /dev/null +++ b/data/goal.txt @@ -0,0 +1,3 @@ ++++++ +val_eq (Val.add (Val.add (r3 PC) Vone) Vone) (Val.add (x2 PC) Vone) +***** diff --git a/data/horses.jpg b/data/horses.jpg new file mode 100644 index 0000000..3a761f4 Binary files /dev/null and b/data/horses.jpg differ diff --git a/data/imagenet.labels.list b/data/imagenet.labels.list new file mode 100644 index 0000000..2326872 --- /dev/null +++ b/data/imagenet.labels.list @@ -0,0 +1,21842 @@ +n02119789 +n02100735 +n02110185 +n02096294 +n02102040 +n02066245 +n02509815 +n02124075 +n02417914 +n02123394 +n02125311 +n02423022 +n02346627 +n02077923 +n02110063 +n02447366 +n02109047 +n02089867 +n02102177 +n02091134 +n02092002 +n02071294 +n02442845 +n02504458 +n02092339 +n02098105 +n02096437 +n02114712 +n02105641 +n02128925 +n02091635 +n02088466 +n02096051 +n02117135 +n02138441 +n02097130 +n02493509 +n02457408 +n02389026 +n02443484 +n02110341 +n02089078 +n02086910 +n02445715 +n02093256 +n02113978 +n02106382 +n02441942 +n02113712 +n02113186 +n02105162 +n02415577 +n02356798 +n02488702 +n02123159 +n02098413 +n02422699 +n02114855 +n02094433 +n02111277 +n02132136 +n02119022 +n02091467 +n02106550 +n02422106 +n02091831 +n02120505 +n02104365 +n02086079 +n02112706 +n02098286 +n02095889 +n02484975 +n02137549 +n02500267 +n02129604 +n02090721 +n02396427 +n02108000 +n02391049 +n02412080 +n02108915 +n02480495 +n02110806 +n02128385 +n02107683 +n02085936 +n02094114 +n02087046 +n02100583 +n02096177 +n02494079 +n02105056 +n02101556 +n02123597 +n02481823 +n02105505 +n02088094 +n02085782 +n02489166 +n02364673 +n02114548 +n02134084 +n02480855 +n02090622 +n02113624 +n02093859 +n02403003 +n02097298 +n02108551 +n02493793 +n02107142 +n02096585 +n02107574 +n02107908 +n02086240 +n02102973 +n02112018 +n02093647 +n02397096 +n02437312 +n02483708 +n02097047 +n02106030 +n02099601 +n02093991 +n02110627 +n02106166 +n02326432 +n02108089 +n02097658 +n02088364 +n02111129 +n02100236 +n02486261 +n02115913 +n02486410 +n02487347 +n02099849 +n02108422 +n02104029 +n02492035 +n02110958 +n02099429 +n02094258 +n02099267 +n02395406 +n02112350 +n02109961 +n02101388 +n02113799 +n02095570 +n02128757 +n02101006 +n02115641 +n02097209 +n02342885 +n02097474 +n02120079 +n02095314 +n02088238 +n02408429 +n02133161 +n02328150 +n02410509 +n02492660 +n02398521 +n02112137 +n02510455 +n02093428 +n02105855 +n02111500 +n02085620 +n02123045 +n02490219 +n02099712 +n02109525 +n02454379 +n02111889 +n02088632 +n02090379 +n02443114 +n02361337 +n02105412 +n02483362 +n02437616 +n02107312 +n02325366 +n02091032 +n02129165 +n02102318 +n02100877 +n02074367 +n02504013 +n02363005 +n02102480 +n02113023 +n02086646 +n02497673 +n02087394 +n02127052 +n02116738 +n02488291 +n02091244 +n02114367 +n02130308 +n02089973 +n02105251 +n02134418 +n02093754 +n02106662 +n02444819 +n01882714 +n01871265 +n01872401 +n01877812 +n01873310 +n01883070 +n04086273 +n04507155 +n04147183 +n04254680 +n02672831 +n02219486 +n02317335 +n01968897 +n03452741 +n03642806 +n07745940 +n02690373 +n04552348 +n02692877 +n02782093 +n04266014 +n03344393 +n03447447 +n04273569 +n03662601 +n02951358 +n04612504 +n02981792 +n04483307 +n03095699 +n03673027 +n03947888 +n02687172 +n04347754 +n04606251 +n03478589 +n04389033 +n03773504 +n02860847 +n03218198 +n02835271 +n03792782 +n03393912 +n03895866 +n02797295 +n04204347 +n03791053 +n03384352 +n03272562 +n04310018 +n02704792 +n02701002 +n02814533 +n02930766 +n03100240 +n03594945 +n03670208 +n03770679 +n03777568 +n04037443 +n04285008 +n03444034 +n03445924 +n03785016 +n04252225 +n03345487 +n03417042 +n03930630 +n04461696 +n04467665 +n03796401 +n03977966 +n04065272 +n04335435 +n04252077 +n04465501 +n03776460 +n04482393 +n04509417 +n03538406 +n03599486 +n03868242 +n02804414 +n03125729 +n03131574 +n03388549 +n02870880 +n03018349 +n03742115 +n03016953 +n04380533 +n03337140 +n03891251 +n02791124 +n04429376 +n03376595 +n04099969 +n04344873 +n04447861 +n03179701 +n03982430 +n03201208 +n03290653 +n04550184 +n07742313 +n07747607 +n07749582 +n07753113 +n07753275 +n07753592 +n07754684 +n07760859 +n07768694 +n12267677 +n12620546 +n13133613 +n11879895 +n12144580 +n12768682 +n03854065 +n04515003 +n03017168 +n03249569 +n03447721 +n03720891 +n03721384 +n04311174 +n02787622 +n02992211 +n04536866 +n03495258 +n02676566 +n03272010 +n03110669 +n03394916 +n04487394 +n03494278 +n03840681 +n03884397 +n02804610 +n03838899 +n04141076 +n03372029 +n11939491 +n12057211 +n09246464 +n09468604 +n09193705 +n09472597 +n09399592 +n09421951 +n09256479 +n09332890 +n09428293 +n09288635 +n03498962 +n03041632 +n03658185 +n03954731 +n03995372 +n03649909 +n03481172 +n03109150 +n02951585 +n03970156 +n04154565 +n04208210 +n03967562 +n03000684 +n01514668 +n01514859 +n01518878 +n01530575 +n01531178 +n01532829 +n01534433 +n01537544 +n01558993 +n01560419 +n01580077 +n01582220 +n01592084 +n01601694 +n01608432 +n01614925 +n01616318 +n01622779 +n01795545 +n01796340 +n01797886 +n01798484 +n01806143 +n01806567 +n01807496 +n01817953 +n01818515 +n01819313 +n01820546 +n01824575 +n01828970 +n01829413 +n01833805 +n01843065 +n01843383 +n01847000 +n01855032 +n01855672 +n01860187 +n02002556 +n02002724 +n02006656 +n02007558 +n02009912 +n02009229 +n02011460 +n02012849 +n02013706 +n02018207 +n02018795 +n02025239 +n02027492 +n02028035 +n02033041 +n02037110 +n02017213 +n02051845 +n02056570 +n02058221 +n01484850 +n01491361 +n01494475 +n01496331 +n01498041 +n02514041 +n02536864 +n01440764 +n01443537 +n02526121 +n02606052 +n02607072 +n02643566 +n02655020 +n02640242 +n02641379 +n01664065 +n01665541 +n01667114 +n01667778 +n01669191 +n01675722 +n01677366 +n01682714 +n01685808 +n01687978 +n01688243 +n01689811 +n01692333 +n01693334 +n01694178 +n01695060 +n01704323 +n01697457 +n01698640 +n01728572 +n01728920 +n01729322 +n01729977 +n01734418 +n01735189 +n01737021 +n01739381 +n01740131 +n01742172 +n01744401 +n01748264 +n01749939 +n01751748 +n01753488 +n01755581 +n01756291 +n01629819 +n01630670 +n01631663 +n01632458 +n01632777 +n01641577 +n01644373 +n01644900 +n04579432 +n04592741 +n03876231 +n03483316 +n03868863 +n04251144 +n03691459 +n03759954 +n04152593 +n03793489 +n03271574 +n03843555 +n04332243 +n04265275 +n04330267 +n03467068 +n02794156 +n04118776 +n03841143 +n04141975 +n02708093 +n03196217 +n04548280 +n03544143 +n04355338 +n03891332 +n04328186 +n03197337 +n04317175 +n04376876 +n03706229 +n02841315 +n04009552 +n04356056 +n03692522 +n04044716 +n02879718 +n02950826 +n02749479 +n04090263 +n04008634 +n03085013 +n04505470 +n03126707 +n03666591 +n02666196 +n02977058 +n04238763 +n03180011 +n03485407 +n03832673 +n06359193 +n03496892 +n04428191 +n04004767 +n04243546 +n04525305 +n04179913 +n03602883 +n04372370 +n03532672 +n02974003 +n03874293 +n03944341 +n03992509 +n03425413 +n02966193 +n04371774 +n04067472 +n04040759 +n04019541 +n03492542 +n04355933 +n03929660 +n02965783 +n04258138 +n04074963 +n03208938 +n02910353 +n03476684 +n03627232 +n03075370 +n03874599 +n03804744 +n04127249 +n04153751 +n03803284 +n04162706 +n04228054 +n02948072 +n03590841 +n04286575 +n04456115 +n03814639 +n03933933 +n04485082 +n03733131 +n03794056 +n04275548 +n01768244 +n01770081 +n01770393 +n01773157 +n01773549 +n01773797 +n01774384 +n01774750 +n01775062 +n01776313 +n01784675 +n01990800 +n01978287 +n01978455 +n01980166 +n01981276 +n01983481 +n01984695 +n01985128 +n01986214 +n02165105 +n02165456 +n02167151 +n02168699 +n02169497 +n02172182 +n02174001 +n02177972 +n02190166 +n02206856 +n02226429 +n02229544 +n02231487 +n02233338 +n02236044 +n02256656 +n02259212 +n02264363 +n02268443 +n02268853 +n02276258 +n02277742 +n02279972 +n02280649 +n02281406 +n02281787 +n01910747 +n01914609 +n01917289 +n01924916 +n01930112 +n01943899 +n01944390 +n01945685 +n01950731 +n01955084 +n02319095 +n02321529 +n03584829 +n03297495 +n03761084 +n03259280 +n04111531 +n04442312 +n04542943 +n04517823 +n03207941 +n04070727 +n04554684 +n03133878 +n03400231 +n04596742 +n02939185 +n03063689 +n04398044 +n04270147 +n02699494 +n04486054 +n03899768 +n04311004 +n04366367 +n04532670 +n02793495 +n03457902 +n03877845 +n03781244 +n03661043 +n02727426 +n02859443 +n03028079 +n03788195 +n04346328 +n03956157 +n04081281 +n03032252 +n03529860 +n03697007 +n03065424 +n03837869 +n04458633 +n02980441 +n04005630 +n03461385 +n02776631 +n02791270 +n02871525 +n02927161 +n03089624 +n04200800 +n04443257 +n04462240 +n03388043 +n03042490 +n04613696 +n03216828 +n02892201 +n03743016 +n02788148 +n02894605 +n03160309 +n03000134 +n03930313 +n04604644 +n04326547 +n03459775 +n04239074 +n04501370 +n03792972 +n04149813 +n03530642 +n03961711 +n03903868 +n02814860 +n07711569 +n07720875 +n07714571 +n07714990 +n07715103 +n07716358 +n07716906 +n07717410 +n07717556 +n07718472 +n07718747 +n07730033 +n07734744 +n04209239 +n03594734 +n02971356 +n03485794 +n04133789 +n02747177 +n04125021 +n07579787 +n03814906 +n03134739 +n03404251 +n04423845 +n03877472 +n04120489 +n03062245 +n03014705 +n03717622 +n03777754 +n04493381 +n04476259 +n02777292 +n07693725 +n03998194 +n03617480 +n07590611 +n04579145 +n03623198 +n07248320 +n04277352 +n04229816 +n02823428 +n03127747 +n02877765 +n04435653 +n03724870 +n03710637 +n03920288 +n03379051 +n02807133 +n04399382 +n03527444 +n03983396 +n03924679 +n04532106 +n06785654 +n03445777 +n07613480 +n04350905 +n04562935 +n03325584 +n03045698 +n07892512 +n03250847 +n04192698 +n03026506 +n03534580 +n07565083 +n04296562 +n02869837 +n07871810 +n02799071 +n03314780 +n04141327 +n04357314 +n02823750 +n13052670 +n07583066 +n03637318 +n04599235 +n07802026 +n02883205 +n03709823 +n04560804 +n02909870 +n03207743 +n04263257 +n07932039 +n03786901 +n04479046 +n03873416 +n02999410 +n04367480 +n03775546 +n07875152 +n04591713 +n04201297 +n02916936 +n03240683 +n02840245 +n02963159 +n04370456 +n03991062 +n02843684 +n03482405 +n03942813 +n03908618 +n03902125 +n07584110 +n02730930 +n04023962 +n02769748 +n10148035 +n02817516 +n03908714 +n02906734 +n03788365 +n02667093 +n03787032 +n03980874 +n03141823 +n03976467 +n04264628 +n07930864 +n04039381 +n06874185 +n04033901 +n04041544 +n07860988 +n03146219 +n03763968 +n03676483 +n04209133 +n03782006 +n03857828 +n03775071 +n02892767 +n07684084 +n04522168 +n03764736 +n04118538 +n03887697 +n13044778 +n03291819 +n03770439 +n03124170 +n04487081 +n03916031 +n02808440 +n07697537 +n12985857 +n02917067 +n03938244 +n15075141 +n02978881 +n02966687 +n03633091 +n13040303 +n03690938 +n03476991 +n02669723 +n03220513 +n03127925 +n04584207 +n07880968 +n03937543 +n03000247 +n04418357 +n04590129 +n02795169 +n04553703 +n02783161 +n02802426 +n02808304 +n03124043 +n03450230 +n04589890 +n12998815 +n02992529 +n03825788 +n02790996 +n03710193 +n03630383 +n03347037 +n03769881 +n03871628 +n03733281 +n03976657 +n03535780 +n04259630 +n03929855 +n04049303 +n04548362 +n02979186 +n06596364 +n03935335 +n06794110 +n02825657 +n03388183 +n04591157 +n04540053 +n03866082 +n04136333 +n04026417 +n02865351 +n02834397 +n03888257 +n04235860 +n04404412 +n04371430 +n03733805 +n07920052 +n07873807 +n02895154 +n04204238 +n04597913 +n04131690 +n07836838 +n09835506 +n03443371 +n13037406 +n04336792 +n04557648 +n03187595 +n04254120 +n03595614 +n04146614 +n03598930 +n03958227 +n04069434 +n03188531 +n02786058 +n07615774 +n04525038 +n04409515 +n03424325 +n03223299 +n03680355 +n07614500 +n07695742 +n04033995 +n03710721 +n04392985 +n03047690 +n03584254 +n13054560 +n10565667 +n03950228 +n03729826 +n02837789 +n04254777 +n02988304 +n03657121 +n04417672 +n04523525 +n02815834 +n09229709 +n07697313 +n03888605 +n03355925 +n03063599 +n04116512 +n04325704 +n07831146 +n03255030 +n00483313 +n02432291 +n02356381 +n02377388 +n04028764 +n04381587 +n02279257 +n04168199 +n00445055 +n02461128 +n03626760 +n04313503 +n00451635 +n02509515 +n04224842 +n09403734 +n02769290 +n13054073 +n03163222 +n00464478 +n03087069 +n04477219 +n03445617 +n00449054 +n00483705 +n04395106 +n03389611 +n04285965 +n04166281 +n04003856 +n03696301 +n00475787 +n04587404 +n09218641 +n02276355 +n03592669 +n04459909 +n04492375 +n09447666 +n00463543 +n04148703 +n04591517 +n03970546 +n04297750 +n02782778 +n02383231 +n03693474 +n02277094 +n03766044 +n02056228 +n03394272 +n03047052 +n00434075 +n04185946 +n02411999 +n03858418 +n12833149 +n02836035 +n03108853 +n04587559 +n04138261 +n02278024 +n03063485 +n02774921 +n09475044 +n02811204 +n03329302 +n04026813 +n03986562 +n03379204 +n03426134 +n02790669 +n03487090 +n03548402 +n08614632 +n04054361 +n03421485 +n03302671 +n03098959 +n02970408 +n03772584 +n03064935 +n09415584 +n11715430 +n12024445 +n02710201 +n03475581 +n13142504 +n03396074 +n03211789 +n03914337 +n03678558 +n03233123 +n00453396 +n00454395 +n00440382 +n04289027 +n00445226 +n11953610 +n04128413 +n00480211 +n00470966 +n12547503 +n03085219 +n02275773 +n02692086 +n04257790 +n00448748 +n02686379 +n12328567 +n03432129 +n03859000 +n12091377 +n02124313 +n00442847 +n04603399 +n03114379 +n02920369 +n03818343 +n02946127 +n02978055 +n12914923 +n02705429 +n00448232 +n12882945 +n04289690 +n07606669 +n02056728 +n11848479 +n03046921 +n12282933 +n02867966 +n12821505 +n02812949 +n04545305 +n02699770 +n04395651 +n02900160 +n04099003 +n02054711 +n12606545 +n03356858 +n01859190 +n03643737 +n02962200 +n03123553 +n09361517 +n02793089 +n00449517 +n02783994 +n10117851 +n12038585 +n04383839 +n10142391 +n07719213 +n03536122 +n02472987 +n03454536 +n11728099 +n02392824 +n03795758 +n04282872 +n00448872 +n02404432 +n03797182 +n03029197 +n03665924 +n12477163 +n02769963 +n03863262 +n01532325 +n04165409 +n04593077 +n04473108 +n03577090 +n09988063 +n00446804 +n03931765 +n00475014 +n02700064 +n03240892 +n12475242 +n11735053 +n04053508 +n02852173 +n02382750 +n03823111 +n04543772 +n04112147 +n04433585 +n03175189 +n03596543 +n00445685 +n03307792 +n04589593 +n01814217 +n02993368 +n04303497 +n02811350 +n03355768 +n03699591 +n04590553 +n01893825 +n12726670 +n09916348 +n11544015 +n01318894 +n02133704 +n02367492 +n04506289 +n02069974 +n01900150 +n03207835 +n03363549 +n02831595 +n04970470 +n04160847 +n03767203 +n03928814 +n02302969 +n02918595 +n10401331 +n04231272 +n03717447 +n03063968 +n03380724 +n00825773 +n09988493 +n02740300 +n04539794 +n04121511 +n01323599 +n12937130 +n02428508 +n02980036 +n12061380 +n01887787 +n04214046 +n01787835 +n00466630 +n02979290 +n03927091 +n03231368 +n03904657 +n04469003 +n04196502 +n02122948 +n04544325 +n07868340 +n13876561 +n11925898 +n12158443 +n01595450 +n12454705 +n02069412 +n09618957 +n02357111 +n00451563 +n04197110 +n02276902 +n03111296 +n03909020 +n12303083 +n02082791 +n01956764 +n04269822 +n04207343 +n02433318 +n01888181 +n12682668 +n01592387 +n09793141 +n00466273 +n04026180 +n06255081 +n12172364 +n10145590 +n12311579 +n12173912 +n03822171 +n03140292 +n03027625 +n02739427 +n02060133 +n02431785 +n03219010 +n00447957 +n11910271 +n03620967 +n12547215 +n02409508 +n04290079 +n12329260 +n13901858 +n02008497 +n10304914 +n04524142 +n04279462 +n04233124 +n09733793 +n12822115 +n09475179 +n10151760 +n03418618 +n12858397 +n07735510 +n03549473 +n10098245 +n03653583 +n10604380 +n03375575 +n03885293 +n01527347 +n03237340 +n02760658 +n11953038 +n03187268 +n03004275 +n02393161 +n11965218 +n08580944 +n03938725 +n03900979 +n04144241 +n03760310 +n02376679 +n03237992 +n09432283 +n02379908 +n09918554 +n04041747 +n12012111 +n10331167 +n01612122 +n10147935 +n07691539 +n11669786 +n09403427 +n01935395 +n09903501 +n04439585 +n04459018 +n02780704 +n03720163 +n12899752 +n04118635 +n03404149 +n02429456 +n00449168 +n04516354 +n04317833 +n12075299 +n07878647 +n09438940 +n03361550 +n02027357 +n04317976 +n03092883 +n04526964 +n03985069 +n03610682 +n04028581 +n02277268 +n09433839 +n03846431 +n03919289 +n10146104 +n10260706 +n02686227 +n03321103 +n00444846 +n01558307 +n01595168 +n03919096 +n11844892 +n04260364 +n02750070 +n03034244 +n03002096 +n04273972 +n11814584 +n04605321 +n07745466 +n02922798 +n03361380 +n12651229 +n08521623 +n04498389 +n00453313 +n04967882 +n12024690 +n03934656 +n02685082 +n04501550 +n09972458 +n03055418 +n07763629 +n03902756 +n09938449 +n09712696 +n02387346 +n03133415 +n07711080 +n03129753 +n03524150 +n02275560 +n03993053 +n03438661 +n11939180 +n00466524 +n11753355 +n03456024 +n03421324 +n07890540 +n11720643 +n02057035 +n00453126 +n04453037 +n01540832 +n03546235 +n03370387 +n02041875 +n02871439 +n03262072 +n01786646 +n02430830 +n02799175 +n05262422 +n03854722 +n12817694 +n04449966 +n01564773 +n02034971 +n03490119 +n02822579 +n07879953 +n04110178 +n04963588 +n04252653 +n01565078 +n02389128 +n02779435 +n10645017 +n04582205 +n08573842 +n10146002 +n03892178 +n03119396 +n03813078 +n07866868 +n03160740 +n03371875 +n02417387 +n03904782 +n03098688 +n02902687 +n01828556 +n04401680 +n04590933 +n01575401 +n07693048 +n02901114 +n03047941 +n04355511 +n11849871 +n10738111 +n03122073 +n12052787 +n01594004 +n01549886 +n02824058 +n03506184 +n11487732 +n12574866 +n12948053 +n10091450 +n00470554 +n00326094 +n12093329 +n04438897 +n07818995 +n12828791 +n13901321 +n10613996 +n10159533 +n02669295 +n02843158 +n06415688 +n14858292 +n09813219 +n12485653 +n03200231 +n02089468 +n03935234 +n01539925 +n12428076 +n10439373 +n01536644 +n02694662 +n02123242 +n03002711 +n03363749 +n02669534 +n03451798 +n11927215 +n02679257 +n09475925 +n10015485 +n12422129 +n03946162 +n02377291 +n07871720 +n12622297 +n12782915 +n01579260 +n11838916 +n10267311 +n12824053 +n03340723 +n02276749 +n04439712 +n02126139 +n04188179 +n02386853 +n07942152 +n02499316 +n04324387 +n10635788 +n04234887 +n12237641 +n03713436 +n04960582 +n04076713 +n01646292 +n03947798 +n02840134 +n04476972 +n09822830 +n03551395 +n04533802 +n02918964 +n00474657 +n12932966 +n01615458 +n01806364 +n12458550 +n11784497 +n03557360 +n10638922 +n09889941 +n10689306 +n03358172 +n04295571 +n06596607 +n11853356 +n00482122 +n11760785 +n03150232 +n11778257 +n03059685 +n10105733 +n04104384 +n07691237 +n04326676 +n07684938 +n12666965 +n04177820 +n13918387 +n03398153 +n03914438 +n09932098 +n02988486 +n02977619 +n03317788 +n03484487 +n02988679 +n04062428 +n02568087 +n12866162 +n04227144 +n07875436 +n04082886 +n11753700 +n00470682 +n02122298 +n10145239 +n12755727 +n04214282 +n01852671 +n02378969 +n04108822 +n10382825 +n12392549 +n03973839 +n12258885 +n11782761 +n12389501 +n02940570 +n03405595 +n02969323 +n03207630 +n10169147 +n03805725 +n09847543 +n02415253 +n07880080 +n04305572 +n02042180 +n07565161 +n02871147 +n04438507 +n04445154 +n07842433 +n12029635 +n09750282 +n09621232 +n01858906 +n02761206 +n03986355 +n12591351 +n13916721 +n02905036 +n11894770 +n02377603 +n12924623 +n03950899 +n09454153 +n10247358 +n05261310 +n11943660 +n10804287 +n03560430 +n01756089 +n10618342 +n04283378 +n13926786 +n04238321 +n04393549 +n04461879 +n03502200 +n00440941 +n03494706 +n04148579 +n13902336 +n02780815 +n10726031 +n04124098 +n12344483 +n04384910 +n07681450 +n02030837 +n04059157 +n09247410 +n02714751 +n08633683 +n04520784 +n10141732 +n12371439 +n04499062 +n02931148 +n07609632 +n04536335 +n02874537 +n03013438 +n11786539 +n11690455 +n07600696 +n00478262 +n00466712 +n03399677 +n12441183 +n07895962 +n11966083 +n02990373 +n04241249 +n02068541 +n12513933 +n02356977 +n04252560 +n04087826 +n03455488 +n07619409 +n09787534 +n03680942 +n00446980 +n12384839 +n03416900 +n07821758 +n11853813 +n01606522 +n11780148 +n04969242 +n12413880 +n04130257 +n01322604 +n03061211 +n01959492 +n02842573 +n04313628 +n03815149 +n02445394 +n08547544 +n03222176 +n04070003 +n03075768 +n09695979 +n02877266 +n08583292 +n02870676 +n03657511 +n01621635 +n04284341 +n04136161 +n02836174 +n10247880 +n01744100 +n02882894 +n03408444 +n03411079 +n02366959 +n04399158 +n04542715 +n02787435 +n04251701 +n13863020 +n07890226 +n12245319 +n12849952 +n11626826 +n00887544 +n03140431 +n03519387 +n03855604 +n07906111 +n02054036 +n11954161 +n03038281 +n00450998 +n12136392 +n02119477 +n04356925 +n02406647 +n04450133 +n12545635 +n01565599 +n02028900 +n07817024 +n02971167 +n04309049 +n02678897 +n12795555 +n11769803 +n01904886 +n02079851 +n12189987 +n04581829 +n12098403 +n01839330 +n12587803 +n03652932 +n08628141 +n03544238 +n04513827 +n01847806 +n03132076 +n10243137 +n03621377 +n10530959 +n14765422 +n04968139 +n12950314 +n02064816 +n02846511 +n10513823 +n11772408 +n03341297 +n03492922 +n03683606 +n02894337 +n02365480 +n09846755 +n03495039 +n01317813 +n12610328 +n02157206 +n01588002 +n03914831 +n03659686 +n10406765 +n09205509 +n02870526 +n07954211 +n10578471 +n11646694 +n03115762 +n07762913 +n12056758 +n12305986 +n11845913 +n02835915 +n02831237 +n07927512 +n12171098 +n02073831 +n07605040 +n02885462 +n02768114 +n04450994 +n11844371 +n03963645 +n02956699 +n02029378 +n01528396 +n10005934 +n04465666 +n04390977 +n11882074 +n03831382 +n04605163 +n06276501 +n02944075 +n05258051 +n07901457 +n12683571 +n02205219 +n13235503 +n02388735 +n03941231 +n14919819 +n12816508 +n11536673 +n13895262 +n02903204 +n10137825 +n07841345 +n07893253 +n01850192 +n07769731 +n11773987 +n03539678 +n12938193 +n10802507 +n03089879 +n00477392 +n01828096 +n09263912 +n13653902 +n04579667 +n01322983 +n08579352 +n07587023 +n07756951 +n07870167 +n10588357 +n01606809 +n13864035 +n02802544 +n07591961 +n02979399 +n04144539 +n02416820 +n11769176 +n09743792 +n09732170 +n04972451 +n13918274 +n01847089 +n01859689 +n04208065 +n07617051 +n10674713 +n07914271 +n07887461 +n03736064 +n03644858 +n03878963 +n04040247 +n07891433 +n01611969 +n07587618 +n02689144 +n10049363 +n04059516 +n10313239 +n03115400 +n01519563 +n01533893 +n03850245 +n11733548 +n03372549 +n01884834 +n02839110 +n07887192 +n03617312 +n07886463 +n03103396 +n07764847 +n01855476 +n07808587 +n12858871 +n03632729 +n10209731 +n04141712 +n03978686 +n03225988 +n00475273 +n09224725 +n04966543 +n01322221 +n03649674 +n13154494 +n03948830 +n03320519 +n03723267 +n07869611 +n12342498 +n01827793 +n03145719 +n11821184 +n11956348 +n11857875 +n10339717 +n09450163 +n10756148 +n01591301 +n07915094 +n04422727 +n09719309 +n03349469 +n03389889 +n10718131 +n04298661 +n09747495 +n03676623 +n03547229 +n03062015 +n10734394 +n07817315 +n02852360 +n01850553 +n02952585 +n03587205 +n02009750 +n01540090 +n02947660 +n03656957 +n03378174 +n02508213 +n01572489 +n12008487 +n12185859 +n11691046 +n01323355 +n05262534 +n00448126 +n02432983 +n12038406 +n03883385 +n02411206 +n01643896 +n10159045 +n11675025 +n01803362 +n02009508 +n07920349 +n04098513 +n11617272 +n09913455 +n12390314 +n04171208 +n02995345 +n10634849 +n03173929 +n02749953 +n11845793 +n12796022 +n11955153 +n11816829 +n03032453 +n11984542 +n02992795 +n03712111 +n02873733 +n02759387 +n14915184 +n02381364 +n12686274 +n07857731 +n04518764 +n03010473 +n02418465 +n02359556 +n07894799 +n04104770 +n04335209 +n01848976 +n02006063 +n04454908 +n03002948 +n04220250 +n09923561 +n04102162 +n11958080 +n04598965 +n10173410 +n03067339 +n02003204 +n12686676 +n11986511 +n02311617 +n03367059 +n02761557 +n05578095 +n04041069 +n10575463 +n03325941 +n10082043 +n01806297 +n09691729 +n04593866 +n01813088 +n01625562 +n03906224 +n01652026 +n10236304 +n04102618 +n04321453 +n07820145 +n01575117 +n12788854 +n07823698 +n04206225 +n03216710 +n02421449 +n03343737 +n07560903 +n02872529 +n11989869 +n12071744 +n06278475 +n04492749 +n02920259 +n03798061 +n02420509 +n03316105 +n12052447 +n03974915 +n02904803 +n03430418 +n12291959 +n06892775 +n03875806 +n07903841 +n10282482 +n02683323 +n07862348 +n01849157 +n04469813 +n09944022 +n03342127 +n07592481 +n02936402 +n02405929 +n10002760 +n02537716 +n05259914 +n01560280 +n12694486 +n07879350 +n02377063 +n03637181 +n03409297 +n01607812 +n02808185 +n09239302 +n12055516 +n09712448 +n02859184 +n12772908 +n02735538 +n10333838 +n12336092 +n02386968 +n04613939 +n00452864 +n04535524 +n03174731 +n04189816 +n07607605 +n12909917 +n02387722 +n02960690 +n07715221 +n02407071 +n10667477 +n09398076 +n04236809 +n01904806 +n01610552 +n12373100 +n12771390 +n04122685 +n07804771 +n15102455 +n03469175 +n03746005 +n02536456 +n03505667 +n11816336 +n09376198 +n10572706 +n03464053 +n02869155 +n07816164 +n04969798 +n02942349 +n14820180 +n01623615 +n12676703 +n03369276 +n03650551 +n02010272 +n02976123 +n01852400 +n02196119 +n04132158 +n03238586 +n07639069 +n03313333 +n10542761 +n12215022 +n00455173 +n10019406 +n12899537 +n04277826 +n09906449 +n04549629 +n11508382 +n15090065 +n10289462 +n04540255 +n02723165 +n04335693 +n01536334 +n03107488 +n12782530 +n14785065 +n02974348 +n09874862 +n04479939 +n03309465 +n09902954 +n12092417 +n03425595 +n12433081 +n07806774 +n12462805 +n01314781 +n10192839 +n01622120 +n07807171 +n03261019 +n02843553 +n04287747 +n02324587 +n09915434 +n01818299 +n01592694 +n03826186 +n03607659 +n01527917 +n03628511 +n02005399 +n04204081 +n02052775 +n04403413 +n03914106 +n12811027 +n01872772 +n04555700 +n02004855 +n04602762 +n02713003 +n04406817 +n11934807 +n03336282 +n09684901 +n03836976 +n11959862 +n03062336 +n03506028 +n04503413 +n07819896 +n03205669 +n11902200 +n07685218 +n03046133 +n10261624 +n10303814 +n03676087 +n04023695 +n07587111 +n07764155 +n01504179 +n03794136 +n03389761 +n13901211 +n02784124 +n04488530 +n02807731 +n07898443 +n04981658 +n04177755 +n03649161 +n04125257 +n10135129 +n03653110 +n10560106 +n07735687 +n03511333 +n11960245 +n03301568 +n03878066 +n10746931 +n04223299 +n04237423 +n07888229 +n01819734 +n12312728 +n09981939 +n03727465 +n13882276 +n02993194 +n11971927 +n09713108 +n03581125 +n09718936 +n14698884 +n03005285 +n03540914 +n03359436 +n03934042 +n07569644 +n04964878 +n07890068 +n07580253 +n01538630 +n03132666 +n03259009 +n02796318 +n12703190 +n01464844 +n11792029 +n04270371 +n13102775 +n02933649 +n02387254 +n02890188 +n04335886 +n04358491 +n02786837 +n03885194 +n04001265 +n03438071 +n10375402 +n02997910 +n03326795 +n00470830 +n02734725 +n03494537 +n08376250 +n07743544 +n02991847 +n04246271 +n04156140 +n04381073 +n07732168 +n04951071 +n07977870 +n04334599 +n02838728 +n03326948 +n11723227 +n08182379 +n03686924 +n03821518 +n02382204 +n02080415 +n11788727 +n07732636 +n03860404 +n03898395 +n07867324 +n04392113 +n13237188 +n03263076 +n07843636 +n04968056 +n04397027 +n03320421 +n06267564 +n02880842 +n04115456 +n13862407 +n10289039 +n03128248 +n01457852 +n01536035 +n04579056 +n03937931 +n03036022 +n01804163 +n09913593 +n12841007 +n03115897 +n03256032 +n02475669 +n07924443 +n03061505 +n10001481 +n03600722 +n07842308 +n10696508 +n04215402 +n10588074 +n03614782 +n03995535 +n12091953 +n04113194 +n10092978 +n03011741 +n04381860 +n07819769 +n07905474 +n03288500 +n04225987 +n13223710 +n02879087 +n02920083 +n08640739 +n03362890 +n03996849 +n03849814 +n09694664 +n02407390 +n02910864 +n02388917 +n01668665 +n07616046 +n02932891 +n10553235 +n03652729 +n01615703 +n12801781 +n12164656 +n05302499 +n03801760 +n03332271 +n02901793 +n03941417 +n09833441 +n01623110 +n02807523 +n10598181 +n03725600 +n10368528 +n04116098 +n12719944 +n02045864 +n02173373 +n02811059 +n04479823 +n07816398 +n10572889 +n04142731 +n07687381 +n02799323 +n07865484 +n01858845 +n12684379 +n01842235 +n09242389 +n02028727 +n03527565 +n03438863 +n15019030 +n13907272 +n09659039 +n04251791 +n03683995 +n04137217 +n04389430 +n09785659 +n02016816 +n03124590 +n01859325 +n03138669 +n02999936 +n11926365 +n12686077 +n03517760 +n09734450 +n04563413 +n12074867 +n01564217 +n12521394 +n06267893 +n03594148 +n04139395 +n12369309 +n01544389 +n12048056 +n04524941 +n03016868 +n03653740 +n02795528 +n03687137 +n03766935 +n03361297 +n04263502 +n10043491 +n03446268 +n01994910 +n03891538 +n10091564 +n10226413 +n02755140 +n03500389 +n10237196 +n03625646 +n06596474 +n03360300 +n09730824 +n10732010 +n04469514 +n02904927 +n04961331 +n02936570 +n03680858 +n07585758 +n09199101 +n04050933 +n03712337 +n03911513 +n01556182 +n03102371 +n07928887 +n12133462 +n03974070 +n03971218 +n03292475 +n03425241 +n03440216 +n11995092 +n02894158 +n02918112 +n10568358 +n11524451 +n03169176 +n04100519 +n07588193 +n06883725 +n02860640 +n07762114 +n04082710 +n07896893 +n10167152 +n03287351 +n02788021 +n08494231 +n01560935 +n03249342 +n04564581 +n09349648 +n07704205 +n03510244 +n12127460 +n09945745 +n11719286 +n11613459 +n12656369 +n03824381 +n07655263 +n09894143 +n04964001 +n02161457 +n07654298 +n07930433 +n02979074 +n02026948 +n13914608 +n07611267 +n02843276 +n09827363 +n10259780 +n04432662 +n11715678 +n12388858 +n03057920 +n10465451 +n03855214 +n07728181 +n09835348 +n03549732 +n04589325 +n03491032 +n00452034 +n03948242 +n01456756 +n07921615 +n02809105 +n12889713 +n07586894 +n07734879 +n07905979 +n12847374 +n12129134 +n02122580 +n04028074 +n02911332 +n09251407 +n07697825 +n04597309 +n02800213 +n03480579 +n07621618 +n04170933 +n03743279 +n01916481 +n04037220 +n10748620 +n02708433 +n12007196 +n02561381 +n04103769 +n03030880 +n04413969 +n03911658 +n04590746 +n00476389 +n04331639 +n07725789 +n01792429 +n02949542 +n07686720 +n04064862 +n04447028 +n01713764 +n09854218 +n04032603 +n04405907 +n15093298 +n04385536 +n11954345 +n01560793 +n09249034 +n03784270 +n03436549 +n01324610 +n02379183 +n07616487 +n04119478 +n03309356 +n12865037 +n12850168 +n04250850 +n03024064 +n04412097 +n02982515 +n00450070 +n10175248 +n11847169 +n12276872 +n12870891 +n10229883 +n10505613 +n03482252 +n09300905 +n02919890 +n07617611 +n10283170 +n01607962 +n01671125 +n07894551 +n04561287 +n00005787 +n10025635 +n02850732 +n03732020 +n02036711 +n07907429 +n03797896 +n03004824 +n12011620 +n10300303 +n03105467 +n03767745 +n07868508 +n07868200 +n03788047 +n07886057 +n04559451 +n09845401 +n04373704 +n02676938 +n02565324 +n02667478 +n02122878 +n03244047 +n01747589 +n04320973 +n13205058 +n02379430 +n11959632 +n10183931 +n07683490 +n10055410 +n04370288 +n03273551 +n13900422 +n07899434 +n04053677 +n07740461 +n11879722 +n04282494 +n02981911 +n03449451 +n07581249 +n03965456 +n11808468 +n13881644 +n11725973 +n12091213 +n13193856 +n02873520 +n02754656 +n02431976 +n01324431 +n02385214 +n01888411 +n12680864 +n07731284 +n04337287 +n07631926 +n02549248 +n04395024 +n07585557 +n02776825 +n09460046 +n12023108 +n00475403 +n10098517 +n07902336 +n03683708 +n02412210 +n04397452 +n04583212 +n13869547 +n03632577 +n01616086 +n02763901 +n08256735 +n03015478 +n02084732 +n12178896 +n11966215 +n07605380 +n13869788 +n01847170 +n07744811 +n01854700 +n00444937 +n10422405 +n07801892 +n09688804 +n11879054 +n02802215 +n07908411 +n07822518 +n01558594 +n07935737 +n10730728 +n04436329 +n04294879 +n04972350 +n12911440 +n13886260 +n07578093 +n02537525 +n03703730 +n09607630 +n13865904 +n02360282 +n11731659 +n04126066 +n04212165 +n11618290 +n07588574 +n09269472 +n11896722 +n02892304 +n03487642 +n02028342 +n03321563 +n03135030 +n03522100 +n03253886 +n04095109 +n06470073 +n12603449 +n10644598 +n10260800 +n01535469 +n09696456 +n03553019 +n03963198 +n11918473 +n10314517 +n03002341 +n07574923 +n10421470 +n05716342 +n03244231 +n01730563 +n11691857 +n12807251 +n12345899 +n03142679 +n01531512 +n12307240 +n07835457 +n04535370 +n00451186 +n12481458 +n03434188 +n09734185 +n04578934 +n04167346 +n02747802 +n03459328 +n03301940 +n01562014 +n07690431 +n10642596 +n03696065 +n12781940 +n02759257 +n04392764 +n04218564 +n03499907 +n01536780 +n09751895 +n03235042 +n04570815 +n12070381 +n09448690 +n07625061 +n10178216 +n04560113 +n09457979 +n03858085 +n02421792 +n02944579 +n10085869 +n09718811 +n04103206 +n04239786 +n04501947 +n01321123 +n02390015 +n03964495 +n01554448 +n02925107 +n03028596 +n12483625 +n03227317 +n10701644 +n11968704 +n03900393 +n01851038 +n02276078 +n03132776 +n07585906 +n04480033 +n07880458 +n12887293 +n07921239 +n03307037 +n04595028 +n04244379 +n13131028 +n10313724 +n09436708 +n02694045 +n09941787 +n00449796 +n01817346 +n07928696 +n03401279 +n12901724 +n11646167 +n07682477 +n09415671 +n07900225 +n03607029 +n02692232 +n11834654 +n07935379 +n12437930 +n03762434 +n07922764 +n03595523 +n04546340 +n10686885 +n03516844 +n03767112 +n09896685 +n03859608 +n03149686 +n07920872 +n12388143 +n10406391 +n04233715 +n04373089 +n02023992 +n01947396 +n12115180 +n00479616 +n03962852 +n02392434 +n12414035 +n14976871 +n03201776 +n10665587 +n03600285 +n04402449 +n08539072 +n03629231 +n12860365 +n03488438 +n03337383 +n12455950 +n10384392 +n02953455 +n03101796 +n07919572 +n03233744 +n01578180 +n01756508 +n04556533 +n02962843 +n02882190 +n03731483 +n01850873 +n05260240 +n03111177 +n09836519 +n03030557 +n11789066 +n02788572 +n07903101 +n04067818 +n07840804 +n01567678 +n12427184 +n03333610 +n02416964 +n10607291 +n07936548 +n05451384 +n02968074 +n07605597 +n02704949 +n07609215 +n01951274 +n07696977 +n03180384 +n04303357 +n03291741 +n02207805 +n10123844 +n03420345 +n12384227 +n02758863 +n02047975 +n03978966 +n03549199 +n04275175 +n09294877 +n09836343 +n11970586 +n02010728 +n10369317 +n12681893 +n03192543 +n12413165 +n12174521 +n11916696 +n10042845 +n07822197 +n04968749 +n10323634 +n12849416 +n02814774 +n05538625 +n03078802 +n12230794 +n07726095 +n03051249 +n12005656 +n11876432 +n12164881 +n09711435 +n01622483 +n09896170 +n07684289 +n03368352 +n07910048 +n03159535 +n00466377 +n01541386 +n11647703 +n09752023 +n07903731 +n12249542 +n03794798 +n11786131 +n02852043 +n10493685 +n09846894 +n01752585 +n01536186 +n07618432 +n09859152 +n02065026 +n02382635 +n07867616 +n03885788 +n04255586 +n03275681 +n11961100 +n12485981 +n04495698 +n03293741 +n13902048 +n03254862 +n07903962 +n01594787 +n11962272 +n03284886 +n07842202 +n10157128 +n02405302 +n04443766 +n06266633 +n02519862 +n01487506 +n03373943 +n04247876 +n04327204 +n03349771 +n09260907 +n10092794 +n12223764 +n03504723 +n11926833 +n01820052 +n13032381 +n03889871 +n03209359 +n04608923 +n15093137 +n15091304 +n03688405 +n09905185 +n03543112 +n11611356 +n03885028 +n03234164 +n07594066 +n02396014 +n03456186 +n09874725 +n11601333 +n02917521 +n03055857 +n02804123 +n12352844 +n12866002 +n09858165 +n12037691 +n02565072 +n04477387 +n02008643 +n07867021 +n04119360 +n09893191 +n02944146 +n12435649 +n13197274 +n04974859 +n07751004 +n12003696 +n02762508 +n02680512 +n01743086 +n06998748 +n10607478 +n07613815 +n01559477 +n01859852 +n03239054 +n04466871 +n05263183 +n13173882 +n07897438 +n12427757 +n04400737 +n03291963 +n07682808 +n11692265 +n04130143 +n09445289 +n07696839 +n03835197 +n12821895 +n09734639 +n03365374 +n04305210 +n04962240 +n09871867 +n07897750 +n07616386 +n09443281 +n03641569 +n13882563 +n07680761 +n10498816 +n04034262 +n03533014 +n07928790 +n07690152 +n10060352 +n04124370 +n12453186 +n04509171 +n03013580 +n10604979 +n12515711 +n04971211 +n07693223 +n03786715 +n07894703 +n02761834 +n04232800 +n03437741 +n04045644 +n14976759 +n03042697 +n12557681 +n06275095 +n11678010 +n01586941 +n07684517 +n07822845 +n03483823 +n09951616 +n03180865 +n07861557 +n03644378 +n12848499 +n11962667 +n03886762 +n04238128 +n11979964 +n13915113 +n12791329 +n12457091 +n03341153 +n10267865 +n03484576 +n10186216 +n07612137 +n03843438 +n11807525 +n11931540 +n02027897 +n07614730 +n04116294 +n03469903 +n10017272 +n03688605 +n07860103 +n03981566 +n01888045 +n03345837 +n11998888 +n02071636 +n02726017 +n04310157 +n04607869 +n01622959 +n08524735 +n03119203 +n12031927 +n03610524 +n02807616 +n04056180 +n03233905 +n03374473 +n14810561 +n11944954 +n03121431 +n09750891 +n08505018 +n10727171 +n12357485 +n12571781 +n12067193 +n07586604 +n02086753 +n03548086 +n02560110 +n07804900 +n02880393 +n04208427 +n12931542 +n01594968 +n05218119 +n03520493 +n03727605 +n12687698 +n03612965 +n04135315 +n07730320 +n10540114 +n07599911 +n01323493 +n02115096 +n04590263 +n12043836 +n02861387 +n09836786 +n04966941 +n02816768 +n13131618 +n10701962 +n02919792 +n03442597 +n04325041 +n03333129 +n04091693 +n04950952 +n10631309 +n04177931 +n13234678 +n01970667 +n07748416 +n07893642 +n07691650 +n03660909 +n04145863 +n11945514 +n10334009 +n12336973 +n03954393 +n04558478 +n09899929 +n03487533 +n07816575 +n07877187 +n07863547 +n01603812 +n02098906 +n04973585 +n03674440 +n04371050 +n12243109 +n07871234 +n02928049 +n07574504 +n07889274 +n12141167 +n04543996 +n03080633 +n03423479 +n07879659 +n04380916 +n10514429 +n07584423 +n04009801 +n12479537 +n07606538 +n07698543 +n12353754 +n10132035 +n03367545 +n04245508 +n09811852 +n02024763 +n04052442 +n10120330 +n12352639 +n12606438 +n07752966 +n09772930 +n02535759 +n11737534 +n10345015 +n12427566 +n09705784 +n04112654 +n02985963 +n03758089 +n12953484 +n07906572 +n02881757 +n12739332 +n03718458 +n03407865 +n07775050 +n03210552 +n09452395 +n09789566 +n10566072 +n10559996 +n07826930 +n12414932 +n01887474 +n03026907 +n07751148 +n10223177 +n03957420 +n03788601 +n12244819 +n12421137 +n04266162 +n10038409 +n02981024 +n03228967 +n11825351 +n12058822 +n11963932 +n03041449 +n03046029 +n07590502 +n02932523 +n02152881 +n04970398 +n07887967 +n12812478 +n12421917 +n02708711 +n11870747 +n04290507 +n07934282 +n01608265 +n12070583 +n03205574 +n02305085 +n07866015 +n02960903 +n10098624 +n00481803 +n07938007 +n02693246 +n03923379 +n04103665 +n11792742 +n12489815 +n04971313 +n01668892 +n01055165 +n03215508 +n12104501 +n07899292 +n12822955 +n07713074 +n03842012 +n02449350 +n07868955 +n02835829 +n12283542 +n04525584 +n07910656 +n11625003 +n03987266 +n02805983 +n15091846 +n09736945 +n04973816 +n02439398 +n01519873 +n07899003 +n03019938 +n07582152 +n01885498 +n12108871 +n02934451 +n04327682 +n07696625 +n09750770 +n12084890 +n03960374 +n07585107 +n01570839 +n11905392 +n06277135 +n07842044 +n03751269 +n04398951 +n12861892 +n12649539 +n07596967 +n07580592 +n12845413 +n07690739 +n07804657 +n04334105 +n03779128 +n03268918 +n03066359 +n02744323 +n12596148 +n04272389 +n07832416 +n10210911 +n01548865 +n03221351 +n15091669 +n07878926 +n07607967 +n12171966 +n02846141 +n07576781 +n02922292 +n10092643 +n01732614 +n02578771 +n02864593 +n03537241 +n09635534 +n03268645 +n07852833 +n13873917 +n12640839 +n03506727 +n10536416 +n09976429 +n10692482 +n07600285 +n04156946 +n07818689 +n02605703 +n02710429 +n02890351 +n03408054 +n03121298 +n02731629 +n12450840 +n04061681 +n10153414 +n07648913 +n07891309 +n01562265 +n14973585 +n01610226 +n06267991 +n03302938 +n07822323 +n07826091 +n02764398 +n10406266 +n09282208 +n01734104 +n04283096 +n03530910 +n11542137 +n02610664 +n03856012 +n01531811 +n07862611 +n11625632 +n12643313 +n02469248 +n03333711 +n02907082 +n02122430 +n01559804 +n09744161 +n10187990 +n12015525 +n07844867 +n07887304 +n02878425 +n02009380 +n11448153 +n10655594 +n12566954 +n11901977 +n03999160 +n02389779 +n07928488 +n12785889 +n04281375 +n03745146 +n03224603 +n04594828 +n12835331 +n09715427 +n11615026 +n09972010 +n04038231 +n02379329 +n03445326 +n10753442 +n04249882 +n11727738 +n07866723 +n04282992 +n11621281 +n01566645 +n03919430 +n11980682 +n03480719 +n11625804 +n10467395 +n09436444 +n07867751 +n03684611 +n03788498 +n12062626 +n07808904 +n07690585 +n03865557 +n10711766 +n10465831 +n04380255 +n12166128 +n04432203 +n07892418 +n10432441 +n12991184 +n04209613 +n04459773 +n09666883 +n07807472 +n09873899 +n12939874 +n04545748 +n09637339 +n07919441 +n03987376 +n03645577 +n03437430 +n10671613 +n02964843 +n09707289 +n11700058 +n03877351 +n03518445 +n07643200 +n02140049 +n12683791 +n12418221 +n04154152 +n03397947 +n03238131 +n11851839 +n04545858 +n07744682 +n02995871 +n07593199 +n03543394 +n10293332 +n12658481 +n11599324 +n02705201 +n03920867 +n08249459 +n02876084 +n03937835 +n01397871 +n03849679 +n12016567 +n04208936 +n07696728 +n13148208 +n01904029 +n08659861 +n07878785 +n07827130 +n03390983 +n02624807 +n03319745 +n03994614 +n00446493 +n12477583 +n02920658 +n04602956 +n02688273 +n07577538 +n04350581 +n09283405 +n04074185 +n04495843 +n03538179 +n03454885 +n03878211 +n10308168 +n08518171 +n02660208 +n07904760 +n07928367 +n10174445 +n02137015 +n02863426 +n07700003 +n04015908 +n03946076 +n11725821 +n01794344 +n04364160 +n01663782 +n04283255 +n02822064 +n04406239 +n02782681 +n11990313 +n03563460 +n02957008 +n07889814 +n07896060 +n03683079 +n04278447 +n13011595 +n11810358 +n03836451 +n12827537 +n03545470 +n03213538 +n07929351 +n03471190 +n02882301 +n03625943 +n03397087 +n11955896 +n04097373 +n03145522 +n03034405 +n02889646 +n02928299 +n09652149 +n01641391 +n04593524 +n07651025 +n03719343 +n03884778 +n03452594 +n02174659 +n12345280 +n03039827 +n03309687 +n11635433 +n02057330 +n01664990 +n09779790 +n02011016 +n09689958 +n07770763 +n03010915 +n03443912 +n02946509 +n13050397 +n03031012 +n04217546 +n04124202 +n12766869 +n04177041 +n12050533 +n03251932 +n03086580 +n03918737 +n04386792 +n03176594 +n01577035 +n01669654 +n01818832 +n10441962 +n03885904 +n03724756 +n02925666 +n03549589 +n03062122 +n02828427 +n12604228 +n03624400 +n07725888 +n03873699 +n01503976 +n02887079 +n03610098 +n02940385 +n04610013 +n03652100 +n04496872 +n04008385 +n02583890 +n10476467 +n03395514 +n03306385 +n04228581 +n02389261 +n12576323 +n01579149 +n01623425 +n02593019 +n03995265 +n02124484 +n12745386 +n04355267 +n02643836 +n01614343 +n03810952 +n04058594 +n12278650 +n03474779 +n02823510 +n00442437 +n12039317 +n04574067 +n03762602 +n02153109 +n03518943 +n04289827 +n02288268 +n07749969 +n04132985 +n03213826 +n04307986 +n03567066 +n02049088 +n04408871 +n03522003 +n09305898 +n04266375 +n08571898 +n03039259 +n01587526 +n03261603 +n00464277 +n02627532 +n02992368 +n03640850 +n03037404 +n04525191 +n02106854 +n07772147 +n04173511 +n12761284 +n03257210 +n02813544 +n07740342 +n04066270 +n03070059 +n03616428 +n02904233 +n03209910 +n04389854 +n03078995 +n03193260 +n01488038 +n01754533 +n12629305 +n02055107 +n11664418 +n04228693 +n03353951 +n03440682 +n03025250 +n03300216 +n02042046 +n04226826 +n03342015 +n03090000 +n02050313 +n03492250 +n01535690 +n01572654 +n03465718 +n02879309 +n06278338 +n04113406 +n03695857 +n09720256 +n01860002 +n02851939 +n09828216 +n02564270 +n03528901 +n02542432 +n11978961 +n01670802 +n03956623 +n01612275 +n09376786 +n03222318 +n02813645 +n02213543 +n13898207 +n03616763 +n03616979 +n11904109 +n04212282 +n04608435 +n02042472 +n04198453 +n03216402 +n02015357 +n12282737 +n02699629 +n12866635 +n02048353 +n02933340 +n01793715 +n12001707 +n02878222 +n03187037 +n03105306 +n04080705 +n04254009 +n01623880 +n02839592 +n03436182 +n01591123 +n01318279 +n03002816 +n13155095 +n03141702 +n03775388 +n12165170 +n03322836 +n03259401 +n04471148 +n03911767 +n12585629 +n04317325 +n04257986 +n03133050 +n02035210 +n12891305 +n11882426 +n04491388 +n12948251 +n03498781 +n04262161 +n03775636 +n09915651 +n07584332 +n07852614 +n11626152 +n03901750 +n09723067 +n04265904 +n09920283 +n02397744 +n03253796 +n07712959 +n03898129 +n01743936 +n02075612 +n04560292 +n03479397 +n04334365 +n04357121 +n10145902 +n03844673 +n09854421 +n12687957 +n12598027 +n03944138 +n01839750 +n07722888 +n04258859 +n03088389 +n03351434 +n03509608 +n01677747 +n03145147 +n12046815 +n03505133 +n01629962 +n03333252 +n03993703 +n02962061 +n04529962 +n03463666 +n07681691 +n12160857 +n04187233 +n09331251 +n11614713 +n04376400 +n12301445 +n12633994 +n03883524 +n11614420 +n13062421 +n03645011 +n03293863 +n11640132 +n02579928 +n02854739 +n04461437 +n07729384 +n02977936 +n02836392 +n03593122 +n01666228 +n07820683 +n07568502 +n11910460 +n09348460 +n09712324 +n02403740 +n03482877 +n04370774 +n07750146 +n12992177 +n03152303 +n04134008 +n09805324 +n01611800 +n04374315 +n07586099 +n02032222 +n01979874 +n04350769 +n02907873 +n03016609 +n02543565 +n03256166 +n03016737 +n02419336 +n03268790 +n03559999 +n07765999 +n04607035 +n02416104 +n02123917 +n12484784 +n03225108 +n10739391 +n03506880 +n02918831 +n03045228 +n12516828 +n01314663 +n04172342 +n02768226 +n12368028 +n01500476 +n01558149 +n03604156 +n04035912 +n02359915 +n12261571 +n03875955 +n01887623 +n03871371 +n03390786 +n12494794 +n03826039 +n04465358 +n03838298 +n03165466 +n04229737 +n01321770 +n04354026 +n02998003 +n04114844 +n10611613 +n03600475 +n01909906 +n00466880 +n04284869 +n07722485 +n04496614 +n03298716 +n02285801 +n04081699 +n07765208 +n12659539 +n11618525 +n11757653 +n07727048 +n03913343 +n12070016 +n02697675 +n04284572 +n02595702 +n04482297 +n03516996 +n03704549 +n02040266 +n04476116 +n01323261 +n03823216 +n07696403 +n03226880 +n09734535 +n03950537 +n01671479 +n03049924 +n12593994 +n04568841 +n03604400 +n01837072 +n01754370 +n03122202 +n12338454 +n04094720 +n04150980 +n03429682 +n03884926 +n03378005 +n02434954 +n03461288 +n02893692 +n04472563 +n10472129 +n04590021 +n07739344 +n04162433 +n03395859 +n12059314 +n03498662 +n03678729 +n02927764 +n02770211 +n11710393 +n07730207 +n04178190 +n07772935 +n03801880 +n04414675 +n12729521 +n12203529 +n04122578 +n04575824 +n06267655 +n03698360 +n02804515 +n02431337 +n08598568 +n02893608 +n02270623 +n00479440 +n11616662 +n02884994 +n04305323 +n02407625 +n04476831 +n04222307 +n03179910 +n11623967 +n00446311 +n00454983 +n02886434 +n12279458 +n03723781 +n11816121 +n02403231 +n11808299 +n07816296 +n03219483 +n02657694 +n00453478 +n02816656 +n02625851 +n04112752 +n03339529 +n12171316 +n02044517 +n04137773 +n01486838 +n03015149 +n12911673 +n03967270 +n03498441 +n11672269 +n03386870 +n11615967 +n02580679 +n01681653 +n02793199 +n02824319 +n10727458 +n02555863 +n01533000 +n02175916 +n12064389 +n04383015 +n02469472 +n03101664 +n03623338 +n12295796 +n02869249 +n01792042 +n03447075 +n04453390 +n04382438 +n04112252 +n03332393 +n12729729 +n01851207 +n04269270 +n12333771 +n06272612 +n03135532 +n02927887 +n11711537 +n12301180 +n04107743 +n01813948 +n03282295 +n09714694 +n00483409 +n01504344 +n04279353 +n04040373 +n12658308 +n04134523 +n10104064 +n12056601 +n04525417 +n07819166 +n12263038 +n02072798 +n03125057 +n03367410 +n04000592 +n03549897 +n01877606 +n01564914 +n12307076 +n02855925 +n03176763 +n12271933 +n04121728 +n07690511 +n02825442 +n04442441 +n01630901 +n03088580 +n02499808 +n10675010 +n01531971 +n02273392 +n01526521 +n01531344 +n03667664 +n02888270 +n04412416 +n07733394 +n04559910 +n04105704 +n11792341 +n04201064 +n01693175 +n04555291 +n02908773 +n01976868 +n03529175 +n03365231 +n03622839 +n04258333 +n03327133 +n03425769 +n12477747 +n03718935 +n11727540 +n07933799 +n03030262 +n12043673 +n02619550 +n07937461 +n12198286 +n08560295 +n12402348 +n01733957 +n12344700 +n02763604 +n11925303 +n01557962 +n03927299 +n11611758 +n03035252 +n09454412 +n04004990 +n03456299 +n02175569 +n03668279 +n12352990 +n03507241 +n01534155 +n12278371 +n02499022 +n03822767 +n01318381 +n04024983 +n04277493 +n11934616 +n02027075 +n11611561 +n03454442 +n02236355 +n01732789 +n07722052 +n01489501 +n04409625 +n10563403 +n01817263 +n07757511 +n03770316 +n02977438 +n01840775 +n03607923 +n03322704 +n02375302 +n01614038 +n01646555 +n03952576 +n02946824 +n12847008 +n03016389 +n11809594 +n03165096 +n03839671 +n02687821 +n01689081 +n03822656 +n02597608 +n12336727 +n01579578 +n03631922 +n03904909 +n11658331 +n04224543 +n12621410 +n03870672 +n04252331 +n09720842 +n01396048 +n11988596 +n00483205 +n02871005 +n01597022 +n02382039 +n07743902 +n02358890 +n07877961 +n05263448 +n01862399 +n04136800 +n10624540 +n11990167 +n02731398 +n03366974 +n03490006 +n01561732 +n02626265 +n10627252 +n12402051 +n08517676 +n10488656 +n03099274 +n03718581 +n11806219 +n01830042 +n07728585 +n03732114 +n10755080 +n03359285 +n07720277 +n03354207 +n01596273 +n04416005 +n01847253 +n07733567 +n09725653 +n04274985 +n00449977 +n07772274 +n12063639 +n01530439 +n01322508 +n04397768 +n07273802 +n04261281 +n10524076 +n01678343 +n03410938 +n01797020 +n02388832 +n07719616 +n03639497 +n09787765 +n07721018 +n11818069 +n04185529 +n11644462 +n12074408 +n00483848 +n01583495 +n11891175 +n03347617 +n03308481 +n02535258 +n07750872 +n07748157 +n02855701 +n04584373 +n02461830 +n02912557 +n12277578 +n03604311 +n03643253 +n03031152 +n04039742 +n03435743 +n13908201 +n04150153 +n03250405 +n01410457 +n02357401 +n12588780 +n12729315 +n01690149 +n02538216 +n03171228 +n02424909 +n06274760 +n03775747 +n04211857 +n12429352 +n12272239 +n11759853 +n03401129 +n12649317 +n02625258 +n12651611 +n03603442 +n02803934 +n03861271 +n02605936 +n02018368 +n12711984 +n02811936 +n04612026 +n01339471 +n02923682 +n09194227 +n04346157 +n03939178 +n12635532 +n01593028 +n01793249 +n02380464 +n12400720 +n07708398 +n12020941 +n12492106 +n12850336 +n12749679 +n02892948 +n12591017 +n03193423 +n01791463 +n11979527 +n12134025 +n12167075 +n09308743 +n13108545 +n01618503 +n07827284 +n07724492 +n02338145 +n04533946 +n01586020 +n07598256 +n01603953 +n12646740 +n03067518 +n04046277 +n01532511 +n07769584 +n11644046 +n12753573 +n02681392 +n08492461 +n07749446 +n04409384 +n01791954 +n12330891 +n04560882 +n10145480 +n04250473 +n02655848 +n02903126 +n11736851 +n11901294 +n12865824 +n03870105 +n00449892 +n04240752 +n11851258 +n04200537 +n12049562 +n01521399 +n03565830 +n07860447 +n03067212 +n01664674 +n07561590 +n02727141 +n02324514 +n02372952 +n01584853 +n07766173 +n11811706 +n03097362 +n04200258 +n02732572 +n01853195 +n12282527 +n09838621 +n02764505 +n04256891 +n12337617 +n12635955 +n07831267 +n11628793 +n12316572 +n07807834 +n02037869 +n01821869 +n02820556 +n04517211 +n01839086 +n03842986 +n07698401 +n02386224 +n07841800 +n01830915 +n11616486 +n11902389 +n03427202 +n12727101 +n01851573 +n02125494 +n07746186 +n11628087 +n07746551 +n03943115 +n11892029 +n02861022 +n11733312 +n01852329 +n09392402 +n12336224 +n07887099 +n03403643 +n04414199 +n07895100 +n02264232 +n02317781 +n07823460 +n07755929 +n02524202 +n04324297 +n11627512 +n01585715 +n02922578 +n00479887 +n02687423 +n02416880 +n11784126 +n12073991 +n01853870 +n01561452 +n04187970 +n10300154 +n02520147 +n12294124 +n07743224 +n12066018 +n11634736 +n02041678 +n11626585 +n02386141 +n03986949 +n07860331 +n12356023 +n12072722 +n03082280 +n12083113 +n12979829 +n01448594 +n03007444 +n07858978 +n01641739 +n02043333 +n12020736 +n02751215 +n04528079 +n01538200 +n07925608 +n12091550 +n03742019 +n03518305 +n01642539 +n03414029 +n04363991 +n03767966 +n02596067 +n01586374 +n02885882 +n04080138 +n11617631 +n02033779 +n09451237 +n02310585 +n12648045 +n03955489 +n01752736 +n07899899 +n02299505 +n01579410 +n02156871 +n02998841 +n03759661 +n02050809 +n02683454 +n11621950 +n02910145 +n04967801 +n07896661 +n11906917 +n12275675 +n11611233 +n07736692 +n02312640 +n12588320 +n04399537 +n12757303 +n04197781 +n12717224 +n11635152 +n03122295 +n01792955 +n13133932 +n02518324 +n01584695 +n02915904 +n02967294 +n04345201 +n03019434 +n02470238 +n03049782 +n03101517 +n12709688 +n03716887 +n02422391 +n12638753 +n00288384 +n02162561 +n02053584 +n01317294 +n03334291 +n07814634 +n12273768 +n12406715 +n11644226 +n01646802 +n03460147 +n12338796 +n01972541 +n02147947 +n03890093 +n04127395 +n01581984 +n01681328 +n02213239 +n04582869 +n03254189 +n03274265 +n03186285 +n11839823 +n01624833 +n09792969 +n07891189 +n12023726 +n07619208 +n03466600 +n01849676 +n12190869 +n03079136 +n12317296 +n13001930 +n00477639 +n02944459 +n03903733 +n04131208 +n12710295 +n12180885 +n11612349 +n03443149 +n03982331 +n04264765 +n12642090 +n03237416 +n13868944 +n04046400 +n11705171 +n11979715 +n12597134 +n01609956 +n01568294 +n01469103 +n00443692 +n01606672 +n04556408 +n07690019 +n03977592 +n03358726 +n12696492 +n01573240 +n11632619 +n01772664 +n03453231 +n04179712 +n03646020 +n01812662 +n04306592 +n07724654 +n13908580 +n02903852 +n04284438 +n13132656 +n04317063 +n07829248 +n01589718 +n02654745 +n12294331 +n12515925 +n07900825 +n07721195 +n04189282 +n11907689 +n01624537 +n12333530 +n07762244 +n11757851 +n01599159 +n04038338 +n01568892 +n12691661 +n09744834 +n04307767 +n03120778 +n07920540 +n03781683 +n04185804 +n12080820 +n04354182 +n07574426 +n02579303 +n03046802 +n12078172 +n03210245 +n01614556 +n02304432 +n07713267 +n09724656 +n02861147 +n12755387 +n01483830 +n12921868 +n12026018 +n07817871 +n12062781 +n04241573 +n11621727 +n03376159 +n11815721 +n13007034 +n03540090 +n00450866 +n11619455 +n01528845 +n01568720 +n12743352 +n02871314 +n03606251 +n01490670 +n04246060 +n02053425 +n10780284 +n01915700 +n04510706 +n00456465 +n01563945 +n11809094 +n09855433 +n04112579 +n03855333 +n09809925 +n03413684 +n02123478 +n12070712 +n03651843 +n02032355 +n01591005 +n01646648 +n02752615 +n02415829 +n03283221 +n04368496 +n01573360 +n02321170 +n10348526 +n04446844 +n07763792 +n12077944 +n04431025 +n02895438 +n10082687 +n07714188 +n02262449 +n03090172 +n12491017 +n01558461 +n12754781 +n04070415 +n04297098 +n03424862 +n01970164 +n09833536 +n01793435 +n01670535 +n09894445 +n09676247 +n01548492 +n12501202 +n03250089 +n03358380 +n02578928 +n12020184 +n02301935 +n03393017 +n12340755 +n01849863 +n01748906 +n03075946 +n01810268 +n01984245 +n04555400 +n12286988 +n04097760 +n02050586 +n12104238 +n01679962 +n02709101 +n01569060 +n12790430 +n01757901 +n13199717 +n11815918 +n07827410 +n02970534 +n12942572 +n07924276 +n04103918 +n11704093 +n07908647 +n07601686 +n12172906 +n04084889 +n02381261 +n02299157 +n11978713 +n12460957 +n02963503 +n03272810 +n12469517 +n03443005 +n01797307 +n02952237 +n11908549 +n13912540 +n03428226 +n10276477 +n01757343 +n01443243 +n01607600 +n03580518 +n12709103 +n07579688 +n04329834 +n12710415 +n11808932 +n10583790 +n02213788 +n11622184 +n12596709 +n02216211 +n07721942 +n07765361 +n01848453 +n11724109 +n02028451 +n02935017 +n12046028 +n10629939 +n00441073 +n07900958 +n12451399 +n02823964 +n04210120 +n01848840 +n10485883 +n07767709 +n02432704 +n11622591 +n03210372 +n07848196 +n11992806 +n02953197 +n07620689 +n01521756 +n03571625 +n03158186 +n12647560 +n02065407 +n01572782 +n09890749 +n05581932 +n07754451 +n03350204 +n13044375 +n12294723 +n12482893 +n04434531 +n12989938 +n12196336 +n01701859 +n07746334 +n11941924 +n02047411 +n12650379 +n10486166 +n01599556 +n01567879 +n12675876 +n01682435 +n02043808 +n12362668 +n12306089 +n02999138 +n01679626 +n03557270 +n01546039 +n11901759 +n01549053 +n11883328 +n06596727 +n03193107 +n11612018 +n03300443 +n03612010 +n03668488 +n12648888 +n01448291 +n11632167 +n10262445 +n09742101 +n09717233 +n04299370 +n03094159 +n04536595 +n03514693 +n02029706 +n02886321 +n07816052 +n04045255 +n01851731 +n02627292 +n01841288 +n02739889 +n02932693 +n03784896 +n04569063 +n07902799 +n03863108 +n02607470 +n13200651 +n07916183 +n01573898 +n04347119 +n10076604 +n13033577 +n01824035 +n03630262 +n04426316 +n03064250 +n12262018 +n12048399 +n12279772 +n04143140 +n07829331 +n12891643 +n01826680 +n12646605 +n13103877 +n02023855 +n03086868 +n04163530 +n03736470 +n04358117 +n13872822 +n03159640 +n01680655 +n11611087 +n03980478 +n02978478 +n01555004 +n12402840 +n07763987 +n04387706 +n04979002 +n03258330 +n09856671 +n11624192 +n01538059 +n02003839 +n12552309 +n10469874 +n01576076 +n03643149 +n04419868 +n04586581 +n00483508 +n03131967 +n01847407 +n07929172 +n09683757 +n03786621 +n04369282 +n12733870 +n11612575 +n11619227 +n03301833 +n02176439 +n01569971 +n07935043 +n02563792 +n02051059 +n04482177 +n11859472 +n11710136 +n04115144 +n07864934 +n07691758 +n02620167 +n07748276 +n03415486 +n07835921 +n00452152 +n01848323 +n12906214 +n12075010 +n01563449 +n01499396 +n01570267 +n12047345 +n07920989 +n07601572 +n02683558 +n04428634 +n04345028 +n12161969 +n03460040 +n02561514 +n02006364 +n03582959 +n11812910 +n13185269 +n04297847 +n07896165 +n01552813 +n12361946 +n02031585 +n12766595 +n11622368 +n11695599 +n11615387 +n02509197 +n12409470 +n01314388 +n11758799 +n09846469 +n02675219 +n04253057 +n04041243 +n12276628 +n04381724 +n01855188 +n02203152 +n04403925 +n11895092 +n11924849 +n04172904 +n11888800 +n01546506 +n07906718 +n01489920 +n03436417 +n03615655 +n07765073 +n02434190 +n02004492 +n12282235 +n12406488 +n11981192 +n10373390 +n13183056 +n04332074 +n12818346 +n07731006 +n02598573 +n02438580 +n01957335 +n03356982 +n10288964 +n02629230 +n02042759 +n12319414 +n01451426 +n03521675 +n02016066 +n01813532 +n13207335 +n11805544 +n04401828 +n02952109 +n03963294 +n10013811 +n12058630 +n01551711 +n01574560 +n01858780 +n10093818 +n03858183 +n01550172 +n03571280 +n02309242 +n10258786 +n01569423 +n10134178 +n08578517 +n04445327 +n03250279 +n02584449 +n03223553 +n04523831 +n04485423 +n02050442 +n04474035 +n04528968 +n02649546 +n01913166 +n09971273 +n04517408 +n02437482 +n03824713 +n03778817 +n07643026 +n01613177 +n12022054 +n07714448 +n07592768 +n00454493 +n03296328 +n02305929 +n03084834 +n03698815 +n12093600 +n08649711 +n03466493 +n04067658 +n03041114 +n03514451 +n01491006 +n04178329 +n03790953 +n03938401 +n02048115 +n07768858 +n03273740 +n10333601 +n05418717 +n12754003 +n02098806 +n03314608 +n01565930 +n12113195 +n12284821 +n12483427 +n04332580 +n10382710 +n03416094 +n02837887 +n03917198 +n14131950 +n04414476 +n11861641 +n11903671 +n01841441 +n09872066 +n01806467 +n04964799 +n00467320 +n01595974 +n03220692 +n01339083 +n01825278 +n11727358 +n04518343 +n11984144 +n07724269 +n02292692 +n02324850 +n01753032 +n01624115 +n11816649 +n07930062 +n02460451 +n12319204 +n04340521 +n12325234 +n01541102 +n02979836 +n00141669 +n01822300 +n11658544 +n12272883 +n03334382 +n11726707 +n03639077 +n07904934 +n03516367 +n03698723 +n03553248 +n11812094 +n03724417 +n01540566 +n02341974 +n11819912 +n07734555 +n02987379 +n03580845 +n12546962 +n02548247 +n12753245 +n07768423 +n12849279 +n11617090 +n02912894 +n07840027 +n12295033 +n12703383 +n02696165 +n10419785 +n04426427 +n03694639 +n11712282 +n04142999 +n01597737 +n03801533 +n01495493 +n07774719 +n03267113 +n01742821 +n03859170 +n03416640 +n03320959 +n12733218 +n02017725 +n13229543 +n09344324 +n04965451 +n01490112 +n10069296 +n12084555 +n04554406 +n04086446 +n02976249 +n02656032 +n02424486 +n02381609 +n09934337 +n04573937 +n07685399 +n02800497 +n02905152 +n02951703 +n07760153 +n03609397 +n00447463 +n03680512 +n02046939 +n03288886 +n11870418 +n03386544 +n07767171 +n07847453 +n12687044 +n01664492 +n03099147 +n03463381 +n02125081 +n12920204 +n03517647 +n02603540 +n12267411 +n11933546 +n11947802 +n04387095 +n12975804 +n02973904 +n13195341 +n04048441 +n11753143 +n03212114 +n03298858 +n04366116 +n01424420 +n10450161 +n01442972 +n07877299 +n04503593 +n04349306 +n12969425 +n12597466 +n03092656 +n07914995 +n03487886 +n12223569 +n01756733 +n13919919 +n04175147 +n02029087 +n03530511 +n02425887 +n03572107 +n03927539 +n03383099 +n04130907 +n01632601 +n07823105 +n10378026 +n02382850 +n07613266 +n03235180 +n02810782 +n12708654 +n11636835 +n02823124 +n03402941 +n12121610 +n03715114 +n04052658 +n00480366 +n12493208 +n04255163 +n12145477 +n01489709 +n12402596 +n01598074 +n03837606 +n02628062 +n04103364 +n03247083 +n02032480 +n07736256 +n12578916 +n09218315 +n02218371 +n03730334 +n02080146 +n03836906 +n02868638 +n02198859 +n12744387 +n02942460 +n11754893 +n12274358 +n02725872 +n09218494 +n03942920 +n07574780 +n02921756 +n01757115 +n02763306 +n11758122 +n10508141 +n02303284 +n04083800 +n13879049 +n12765115 +n12075830 +n02666943 +n11980318 +n07907037 +n12794135 +n02333909 +n03870980 +n07586718 +n11923174 +n10782471 +n01493146 +n12294871 +n11726269 +n12932173 +n07825972 +n12732009 +n03572321 +n07682197 +n03423306 +n12495895 +n03545756 +n03557692 +n03785237 +n07902937 +n09899671 +n12061614 +n07902443 +n01449374 +n12632335 +n03474896 +n03539433 +n04310904 +n03902482 +n12006930 +n03285578 +n04200000 +n03912218 +n07821260 +n03548626 +n03223686 +n11826198 +n03165616 +n02104280 +n09981278 +n09382099 +n03732458 +n03987990 +n09946814 +n12270741 +n07737745 +n04172776 +n10189278 +n03543012 +n12629666 +n02180875 +n04087432 +n12961879 +n03321954 +n12528549 +n02424085 +n09843443 +n03846677 +n12304703 +n09873473 +n03410571 +n03041810 +n02425228 +n01562451 +n03615790 +n10081204 +n03985881 +n07842130 +n02890513 +n03649797 +n02381004 +n12560621 +n12523475 +n07687626 +n11905749 +n11759404 +n12905412 +n03542605 +n03983612 +n12573474 +n11972291 +n03767459 +n02698634 +n12713866 +n13084834 +n02202006 +n13108323 +n02631475 +n10737103 +n03637898 +n03069752 +n12400489 +n09692915 +n10242328 +n02794664 +n12465557 +n12085267 +n03348868 +n12754981 +n02745611 +n10504206 +n12073554 +n02835724 +n04605572 +n02825961 +n03528523 +n12116429 +n02973805 +n12708941 +n01544704 +n04180229 +n09403211 +n08242223 +n02146371 +n12127768 +n09770359 +n03295246 +n01757677 +n04385799 +n02584145 +n07909593 +n12587132 +n13029326 +n04184316 +n07903643 +n01848555 +n10750031 +n02332156 +n12703557 +n03196990 +n12406902 +n02768973 +n12416073 +n02147591 +n09724533 +n09693982 +n12687462 +n01982068 +n03435991 +n03272125 +n07713763 +n03018712 +n03648431 +n03336575 +n07854184 +n12806015 +n07879174 +n03984643 +n03147280 +n02699915 +n07617708 +n01533651 +n12483841 +n01697611 +n02576906 +n03724066 +n03935116 +n09782397 +n01599269 +n10672371 +n12066630 +n03178674 +n15086247 +n03523987 +n02826068 +n12580654 +n02358390 +n01647640 +n10259997 +n03738066 +n13915023 +n02639605 +n03174450 +n12269406 +n09874428 +n03432061 +n04386051 +n03923918 +n04592465 +n12480456 +n10333439 +n04206790 +n01443831 +n02967626 +n07733712 +n03746155 +n12947313 +n11690254 +n12244650 +n12670758 +n08658309 +n12710693 +n11860555 +n03485198 +n03047799 +n04461570 +n07600177 +n02126640 +n12704343 +n02866386 +n03008976 +n04532831 +n03465426 +n12691428 +n01641206 +n04962062 +n03254046 +n04425804 +n02014524 +n03439348 +n02538010 +n11603246 +n12265600 +n12277800 +n04016240 +n12086192 +n09650729 +n01549641 +n03112719 +n04961062 +n02710324 +n12049282 +n12362274 +n11969607 +n12856680 +n02201000 +n07863802 +n03360622 +n07601809 +n04354487 +n12898774 +n12939282 +n03109693 +n12867826 +n12441390 +n12915811 +n12879527 +n04137355 +n04131368 +n03527149 +n10164492 +n09932508 +n12426623 +n12575812 +n02557318 +n10263790 +n04309548 +n00476235 +n04194127 +n11876634 +n10327987 +n03499354 +n02616851 +n04464615 +n03615406 +n02744844 +n11732567 +n10347446 +n09752519 +n04228215 +n10004718 +n07899533 +n12030908 +n15102894 +n12044467 +n11711764 +n02610066 +n03415749 +n04562496 +n02034295 +n02297442 +n03566193 +n12506991 +n07774842 +n12827270 +n14908027 +n12242409 +n04072960 +n02829596 +n12496427 +n02266050 +n13108481 +n12473840 +n08677424 +n12076223 +n15091473 +n02815749 +n04549028 +n12558425 +n12023407 +n04179824 +n02378541 +n03188725 +n12517445 +n07573347 +n02004131 +n11921395 +n12570972 +n10602470 +n12095647 +n03854421 +n02450295 +n02792409 +n03543735 +n12836337 +n12204175 +n12152722 +n07900734 +n12517642 +n02775039 +n12607456 +n03376938 +n12179122 +n09873348 +n01847978 +n07888816 +n10453184 +n09675922 +n01851895 +n12865562 +n01797601 +n03711044 +n02738859 +n12064591 +n04033425 +n08551296 +n01650690 +n01537895 +n04207151 +n10087434 +n12261808 +n09438844 +n10364198 +n01814755 +n01583209 +n12270946 +n11892817 +n03344642 +n04117464 +n07847917 +n04003241 +n10362319 +n10477713 +n03495570 +n07560542 +n04363777 +n04534359 +n02404906 +n03349892 +n07712267 +n02960352 +n07866277 +n07857170 +n00324978 +n02755823 +n03150511 +n04211528 +n01899894 +n07588299 +n11874081 +n03425325 +n04506506 +n11949402 +n02952374 +n03309110 +n12159388 +n07591049 +n03068998 +n03228254 +n10279018 +n04173046 +n07728053 +n13052931 +n01597906 +n12368451 +n02767665 +n09435739 +n03915900 +n09728285 +n03292603 +n03331077 +n07817160 +n07917392 +n12540250 +n04153025 +n10209082 +n03968581 +n12676534 +n11824146 +n03521899 +n01853666 +n04292921 +n12332030 +n03984759 +n02863014 +n07801091 +n07723177 +n03289660 +n01533481 +n04488202 +n03468821 +n02382338 +n03543254 +n01961985 +n07915918 +n03703862 +n02771004 +n02047045 +n03877674 +n13141415 +n03529629 +n02240517 +n03675235 +n04491638 +n12384037 +n04419642 +n03019685 +n07591586 +n04496726 +n12985420 +n12927013 +n12196694 +n03473227 +n11621547 +n02988066 +n10451450 +n07729828 +n09618760 +n12196527 +n01555305 +n12830222 +n11950877 +n13190747 +n12160303 +n12390099 +n02818135 +n03163381 +n04554211 +n03244919 +n07897975 +n03386726 +n04290615 +n02011281 +n12407890 +n04123448 +n07904865 +n03447358 +n02393940 +n07931870 +n02937958 +n04318787 +n04587327 +n12807409 +n04112430 +n07560193 +n12774299 +n02618827 +n07854982 +n03757604 +n03817191 +n12793494 +n02324431 +n03013850 +n04113641 +n01612476 +n03127408 +n02038466 +n03799876 +n04257684 +n03382292 +n10449664 +n04394630 +n10275395 +n07698250 +n12329473 +n07694659 +n07642742 +n02563648 +n08583455 +n02557182 +n02775178 +n09274152 +n03189083 +n12570703 +n04211219 +n12486574 +n03073694 +n11969166 +n02475078 +n02976350 +n08584914 +n07899660 +n10116702 +n01613807 +n12461109 +n04025508 +n12451240 +n12596849 +n12079963 +n03541269 +n04561422 +n11699442 +n07725255 +n03460297 +n07616748 +n12757458 +n03103563 +n02813752 +n07698782 +n12840362 +n01543632 +n01602832 +n01875313 +n12472024 +n02926591 +n02872333 +n10728624 +n12532564 +n03882960 +n12333053 +n03684224 +n13146583 +n03436075 +n04154340 +n03868643 +n02598878 +n04139140 +n03266371 +n04083309 +n12506341 +n12200143 +n03503477 +n12807773 +n03123917 +n13029760 +n10173771 +n03659809 +n12047884 +n12759273 +n04193377 +n04258438 +n04597400 +n04579986 +n03719743 +n04299963 +n02864504 +n10510245 +n03417970 +n09719794 +n03138344 +n02085272 +n07694516 +n12665857 +n01642257 +n03229244 +n10581890 +n10318293 +n03635108 +n10652605 +n12189429 +n09934774 +n11709205 +n04207903 +n10296176 +n10603851 +n03450734 +n13223588 +n12754648 +n09886403 +n07751280 +n11950686 +n07814390 +n12799776 +n01646902 +n09796809 +n12819728 +n01938454 +n02410011 +n07607138 +n02119634 +n10332861 +n09230202 +n02757061 +n02849885 +n15092227 +n12151615 +n03111041 +n02413050 +n03506560 +n07744057 +n04030518 +n12544539 +n04089836 +n02038993 +n13882201 +n12099342 +n01946630 +n10095769 +n02982416 +n12957924 +n13215586 +n07726525 +n12452836 +n03801671 +n04598318 +n01449712 +n12428747 +n04119751 +n10509063 +n07694839 +n02782602 +n11626409 +n02573704 +n12399384 +n12388989 +n01601068 +n11971406 +n04367011 +n07930315 +n12925179 +n04967674 +n03497352 +n03653833 +n01819465 +n03688192 +n02802990 +n03393761 +n04430475 +n13107694 +n10384496 +n07867164 +n12449526 +n01515303 +n12574320 +n01444339 +n07919310 +n03453443 +n04173907 +n02887489 +n07772788 +n03629520 +n02580830 +n11705387 +n12069679 +n01956344 +n02406533 +n03973402 +n03938037 +n04969952 +n04103094 +n04393808 +n07715407 +n04172107 +n01917882 +n12085664 +n07608429 +n09835230 +n04135024 +n07842605 +n12568186 +n04339879 +n07691091 +n01801876 +n00474568 +n01807105 +n12128071 +n01673282 +n11948864 +n03991837 +n09659188 +n02070174 +n02670683 +n12454949 +n10385566 +n11631854 +n12305293 +n12002428 +n12948495 +n12757816 +n11852028 +n10690648 +n09283866 +n03214582 +n03423877 +n04127521 +n03006626 +n09283193 +n07712559 +n01447331 +n02981321 +n02658531 +n11947629 +n02419634 +n02420828 +n11923637 +n12570394 +n11968931 +n12731029 +n09749386 +n07736813 +n03967396 +n11908846 +n03029445 +n02426481 +n01964271 +n13198914 +n04484432 +n12656685 +n10806113 +n11849983 +n03236423 +n10649197 +n07688624 +n03057541 +n12015221 +n02094931 +n02014237 +n07560331 +n02801450 +n04206570 +n07556406 +n11627908 +n11889619 +n07852229 +n04063154 +n02713364 +n02783459 +n12877838 +n02930214 +n02125010 +n02407276 +n07815424 +n12855494 +n12530818 +n07750449 +n01963317 +n10082997 +n03245724 +n03012013 +n03555006 +n02421136 +n03332989 +n04375405 +n03746486 +n12636224 +n03278914 +n07917133 +n12504783 +n09416890 +n03896526 +n02258198 +n12983048 +n03837698 +n12869061 +n04541987 +n01637615 +n04401949 +n02241426 +n13220122 +n07876651 +n03729308 +n02364840 +n01339801 +n03418915 +n09257843 +n11614039 +n09731343 +n03809603 +n05399243 +n01569262 +n11901597 +n03124474 +n01566207 +n03796522 +n12595699 +n04573281 +n09689435 +n11859737 +n03201529 +n12902662 +n03374372 +n03760944 +n09189157 +n01517966 +n10431625 +n02898269 +n03693707 +n04369025 +n07834618 +n04095342 +n02786331 +n03822504 +n02284611 +n09862621 +n03436891 +n07688898 +n12435777 +n03949317 +n12443323 +n12273114 +n12623077 +n04333869 +n07907831 +n07774596 +n05450617 +n03320262 +n04190376 +n12671651 +n11819509 +n07588111 +n09756049 +n07611046 +n04973291 +n11602873 +n00120010 +n03500699 +n03844815 +n03708843 +n04452528 +n04387261 +n09889065 +n10147121 +n03318294 +n12599435 +n04164406 +n01965529 +n11636204 +n11791569 +n12275131 +n02977330 +n07851443 +n04132603 +n07824191 +n09760609 +n12190410 +n07915491 +n12665271 +n10120671 +n02570164 +n10208950 +n02163297 +n02244797 +n09842528 +n08645104 +n01841679 +n11603835 +n04488857 +n07814487 +n01953762 +n04612373 +n11877193 +n03198500 +n03981924 +n01943087 +n11552806 +n04414909 +n03005033 +n02457945 +n10500217 +n10375314 +n04607242 +n07914777 +n09832456 +n12915568 +n12813189 +n10578021 +n03519081 +n07801779 +n12026476 +n03296081 +n03850492 +n07902121 +n09881265 +n12562785 +n03290195 +n10131151 +n10078719 +n01558765 +n03917814 +n02045596 +n07734183 +n03414676 +n07933154 +n02126787 +n12148757 +n12263987 +n07684164 +n03406966 +n01492569 +n02988963 +n12963628 +n09964202 +n03417749 +n01854838 +n02921029 +n02183096 +n11762433 +n11722466 +n02387093 +n02768655 +n12519089 +n09871229 +n07938313 +n10502329 +n11989393 +n03768916 +n13145040 +n11813077 +n04457910 +n03655720 +n03703945 +n11876803 +n01438581 +n07910379 +n07847827 +n02300797 +n09245515 +n10754189 +n04581102 +n12513172 +n02458135 +n03762332 +n11789589 +n09695620 +n03850053 +n07911249 +n12342852 +n12753007 +n07748574 +n07727458 +n03696568 +n04304680 +n07723039 +n07775197 +n07577144 +n03043693 +n04374735 +n01858281 +n09228055 +n09466678 +n01949085 +n02024479 +n11623815 +n02704645 +n07894451 +n01751472 +n01646388 +n01317916 +n13880994 +n10300500 +n11794024 +n03735963 +n04610274 +n11854479 +n07754894 +n02639087 +n02122510 +n02262803 +n12732966 +n04529108 +n13194036 +n09990777 +n10009276 +n12088223 +n12155009 +n07886176 +n04278247 +n04222723 +n11707229 +n01999186 +n07851641 +n12741792 +n01315213 +n10033412 +n04249582 +n03586631 +n03237839 +n12037499 +n12014085 +n07756325 +n01636352 +n03905947 +n08611339 +n07693590 +n03724538 +n09791816 +n01666585 +n10588965 +n11613219 +n10542608 +n12913791 +n10528023 +n03171635 +n11923397 +n12854600 +n10410246 +n12698598 +n04135118 +n09844457 +n04441790 +n03882611 +n02337001 +n07907342 +n12561169 +n12027658 +n10719132 +n09851165 +n02801823 +n12330587 +n01683558 +n12162181 +n04387932 +n11704620 +n09679170 +n07601290 +n04028221 +n10277027 +n09877750 +n11758483 +n10027246 +n03819336 +n10205231 +n12478768 +n03451711 +n12973443 +n01923025 +n03262717 +n07807594 +n00475535 +n07744430 +n02341475 +n04614655 +n07924747 +n03388323 +n12680402 +n03202940 +n04534520 +n09661873 +n15092059 +n11832480 +n04198355 +n12529220 +n12389130 +n12304115 +n03234952 +n07610620 +n02868975 +n04442741 +n05282652 +n02820675 +n12795352 +n12675299 +n08547468 +n04189651 +n04141198 +n04513998 +n12273939 +n12482668 +n12858618 +n01958346 +n03172038 +n10280674 +n04301760 +n02631330 +n12433178 +n07763107 +n03068181 +n07565259 +n03605598 +n13177884 +n04005197 +n09751496 +n12737383 +n07648997 +n09839702 +n09442595 +n07925229 +n12150722 +n11898775 +n09904208 +n02207345 +n07642361 +n07685918 +n03205458 +n10574538 +n09742315 +n02599557 +n03585682 +n04273659 +n02200850 +n03410740 +n03391301 +n07726672 +n09782167 +n13155305 +n02067240 +n07561848 +n07728708 +n12463134 +n12228229 +n09743487 +n12225563 +n03421669 +n03226375 +n03973945 +n12498055 +n04483925 +n04564278 +n11890150 +n12519563 +n12754468 +n04353573 +n11615607 +n04430896 +n04585128 +n10395828 +n10773665 +n02772435 +n09881895 +n12663023 +n01615303 +n12803754 +n09445008 +n03955296 +n05245192 +n05486510 +n07899769 +n07575510 +n02307681 +n03814817 +n02670186 +n03598515 +n12797860 +n03518135 +n07587962 +n12630763 +n06273743 +n09843824 +n03226254 +n12407222 +n02961544 +n12951835 +n06417096 +n02016659 +n01441117 +n07735404 +n09411189 +n13896217 +n03262248 +n03451120 +n02525382 +n03375329 +n04155068 +n12916179 +n10297234 +n11907100 +n03423568 +n04360914 +n12027222 +n12199790 +n01744270 +n09896401 +n07925116 +n03693860 +n04414319 +n07767549 +n03555564 +n04043411 +n07872593 +n03774461 +n03129471 +n04497801 +n11756870 +n09776346 +n04530283 +n01520576 +n12828220 +n01583828 +n04120842 +n09676021 +n04344734 +n01916388 +n12513613 +n09861863 +n02310334 +n03318983 +n04533499 +n02427576 +n12727518 +n04502059 +n11725480 +n11987126 +n11876204 +n03504205 +n09720595 +n12315999 +n12935609 +n04452757 +n12201331 +n01603152 +n10772092 +n03156279 +n12723610 +n02003037 +n03244775 +n07802963 +n11954642 +n07770034 +n09931165 +n10559508 +n01745902 +n07654148 +n10070108 +n01585287 +n13196003 +n04389718 +n10253122 +n03730893 +n02983357 +n02783900 +n01680813 +n03072440 +n03109253 +n03274435 +n11655974 +n10048612 +n07849733 +n07896994 +n03792334 +n03035832 +n03819448 +n03105088 +n11943992 +n01485479 +n01699675 +n11795049 +n12086778 +n01840120 +n07753980 +n10685398 +n04346428 +n04532398 +n07709172 +n02146700 +n09461069 +n03853924 +n01321456 +n12068432 +n09757449 +n03206282 +n03751757 +n13053608 +n11695974 +n12123741 +n03500209 +n04367371 +n02890940 +n01917611 +n07835331 +n02907656 +n04136045 +n12059625 +n03862862 +n12864160 +n00440039 +n03448590 +n12628986 +n04115802 +n03949145 +n12916511 +n12647893 +n09706255 +n13181811 +n07752109 +n04375615 +n01648620 +n04403524 +n09967967 +n12911079 +n03857687 +n02803539 +n01551080 +n10734891 +n13235159 +n04127633 +n07935878 +n12853482 +n10191001 +n03126385 +n10076224 +n01812866 +n12919403 +n03769610 +n09283767 +n03462110 +n11770256 +n12038898 +n09889170 +n11894558 +n10298647 +n02592055 +n02795670 +n11701066 +n12762049 +n02890662 +n07918193 +n02976455 +n03100897 +n13127843 +n12184912 +n00468299 +n12407079 +n12496949 +n03541537 +n05260127 +n01535140 +n01541760 +n11945783 +n07687053 +n07745046 +n12083847 +n02382132 +n12270027 +n10140597 +n03788914 +n01790711 +n02197689 +n03173270 +n10368624 +n04449290 +n01579729 +n07834872 +n07734417 +n02379630 +n01636829 +n12549192 +n12951146 +n13579829 +n03268142 +n11761202 +n02769669 +n09452760 +n04095577 +n12031139 +n02003577 +n12891469 +n03931885 +n01577941 +n04176295 +n12046428 +n03418402 +n13145250 +n11865874 +n12473608 +n11797321 +n01798168 +n09923186 +n02786736 +n01698782 +n09976283 +n03975788 +n14685296 +n01682172 +n07838441 +n02771286 +n03429137 +n03948950 +n02512830 +n02298218 +n10141364 +n02823848 +n02077384 +n12584715 +n11748811 +n02214773 +n03667552 +n04121426 +n04135710 +n07579917 +n12275888 +n07826453 +n12167436 +n04586072 +n09877288 +n04248396 +n02761696 +n03038870 +n01490360 +n12353203 +n09785891 +n12057660 +n04146343 +n12557556 +n02081798 +n02917964 +n07898617 +n12597798 +n07574176 +n07764630 +n03008177 +n04255899 +n04434207 +n07897600 +n09929577 +n11811921 +n12415595 +n02893941 +n12276110 +n02821202 +n09690621 +n02508742 +n02077787 +n02390640 +n03764822 +n02257985 +n13033134 +n04559166 +n07865196 +n10506915 +n12051103 +n10473917 +n12775919 +n02971579 +n12880462 +n11837970 +n02063662 +n09840520 +n12019827 +n09208496 +n12836508 +n02982232 +n04219185 +n03332005 +n07914128 +n07862461 +n04250692 +n09267854 +n04561734 +n02076402 +n12344837 +n02919148 +n06592281 +n03668803 +n03062985 +n04246731 +n12112609 +n04012482 +n03558633 +n03982642 +n01998741 +n07665438 +n04209509 +n07913882 +n01749244 +n07801342 +n02611561 +n04488742 +n01897536 +n10624437 +n13128976 +n07931612 +n04300643 +n03727067 +n03360431 +n07593471 +n10253296 +n03297226 +n03854506 +n07879450 +n10562283 +n12557438 +n13154388 +n12862512 +n02126028 +n07752514 +n02387887 +n12066261 +n07666176 +n02806530 +n09988703 +n03721252 +n03221540 +n12195533 +n02682569 +n03622058 +n03943266 +n04207596 +n11721337 +n02427032 +n07910152 +n01551300 +n12861345 +n11660300 +n03786313 +n12966945 +n02046171 +n02797535 +n03546112 +n07711232 +n02044908 +n02998563 +n02652132 +n12634986 +n12187247 +n11645590 +n07582892 +n03065243 +n09911226 +n04396902 +n10763075 +n02359047 +n10400108 +n04294614 +n03991646 +n11728945 +n07766891 +n12277150 +n13141564 +n10563314 +n12426749 +n07827750 +n12403994 +n12627119 +n03420801 +n10203949 +n12830568 +n12280060 +n13180875 +n12659064 +n04239436 +n03823312 +n04367746 +n12448700 +n01896844 +n07581931 +n09384106 +n11625223 +n04198722 +n01477875 +n09932336 +n03477512 +n12281974 +n10117739 +n07759194 +n12281788 +n01405007 +n03077616 +n02304036 +n12947544 +n03140126 +n12356960 +n07807002 +n07877849 +n02956795 +n04373795 +n07925500 +n10359546 +n09730077 +n01694955 +n10611267 +n04316498 +n07849912 +n12841354 +n07903543 +n10026976 +n04050313 +n03939844 +n03260849 +n07917507 +n12228387 +n03199775 +n01569566 +n02403920 +n04261638 +n02986160 +n03724623 +n01960177 +n03783430 +n07877675 +n10401639 +n04215153 +n03077741 +n02589623 +n12934985 +n03233624 +n04506688 +n12194147 +n09975425 +n07818825 +n12641007 +n10036692 +n02771750 +n12285900 +n01472303 +n10033663 +n10707134 +n03219966 +n11772879 +n10146416 +n10435169 +n10304086 +n12385566 +n03126580 +n12904314 +n03619196 +n02299846 +n03574243 +n12368257 +n03690473 +n01748686 +n09834378 +n07750736 +n02930645 +n01679307 +n03721047 +n02710044 +n07563207 +n02930080 +n09309168 +n03127203 +n02863536 +n02536165 +n01559639 +n09654518 +n02961035 +n12007406 +n12773651 +n04351699 +n03114504 +n06273414 +n02017475 +n01733466 +n02175014 +n07920663 +n03953901 +n09670521 +n09400987 +n11791341 +n02284884 +n12919646 +n07880325 +n03801353 +n01982347 +n07828642 +n01570421 +n03998333 +n03449309 +n10482220 +n12850906 +n12805561 +n12926689 +n03232543 +n04248851 +n03195959 +n04082562 +n03846100 +n07682952 +n07695652 +n11809271 +n09895561 +n04287898 +n09740724 +n02859955 +n09830400 +n03674731 +n02825153 +n04571686 +n13107891 +n10318607 +n07848093 +n13226871 +n08555710 +n03137473 +n02776978 +n03141455 +n12514138 +n01809371 +n09405078 +n01753180 +n02184473 +n11610215 +n03539546 +n12731835 +n04485884 +n03590588 +n10221312 +n04049753 +n03441345 +n02302244 +n12262185 +n15092650 +n11877646 +n10377185 +n01684578 +n03796605 +n07897116 +n03164344 +n12135049 +n10757050 +n01692523 +n04566756 +n07697699 +n07575392 +n10262655 +n04064747 +n07914006 +n12433769 +n07873348 +n04457767 +n10019072 +n02921195 +n03856465 +n04041408 +n12639584 +n12920955 +n11781176 +n07864756 +n03941013 +n03646148 +n04401578 +n11692792 +n02757714 +n02286089 +n04253168 +n03890514 +n07855510 +n03507458 +n04123026 +n11661909 +n12435152 +n04330746 +n09481120 +n03731019 +n03717285 +n03271030 +n02772101 +n07740597 +n02847852 +n12825497 +n12263738 +n03342262 +n03603594 +n07804543 +n12932365 +n12695975 +n10297531 +n04054670 +n03175081 +n12703856 +n03832144 +n03966206 +n02414290 +n03619275 +n09738121 +n03290096 +n10585077 +n07731767 +n12409840 +n12026981 +n02278980 +n02752810 +n01654637 +n02654112 +n10314836 +n13023134 +n01823414 +n07461050 +n11902982 +n04543636 +n02204907 +n04049585 +n12304899 +n03073545 +n04272928 +n10315456 +n03975657 +n09899782 +n12288005 +n07005523 +n03795269 +n09823832 +n02242137 +n02907391 +n03643491 +n03245889 +n12285369 +n03061345 +n03797264 +n07838073 +n09219233 +n02859343 +n07608098 +n03920641 +n12578626 +n10688356 +n04542858 +n07834065 +n00443803 +n04181561 +n04570214 +n02047517 +n03295012 +n01633781 +n10610850 +n04035836 +n03001115 +n04593376 +n02393807 +n13061348 +n10123122 +n11800236 +n13207094 +n10140929 +n12167602 +n01809752 +n10421956 +n02764935 +n03424489 +n12889219 +n04046091 +n07714287 +n07708685 +n07736087 +n04142434 +n11961446 +n04521863 +n02414763 +n02901377 +n00467536 +n13085747 +n03855756 +n11846765 +n02530999 +n03063199 +n04258618 +n12204032 +n04424692 +n11758276 +n02653497 +n03766508 +n02026629 +n02572484 +n12339831 +n01635027 +n01668436 +n07821919 +n01543175 +n02689748 +n12528974 +n04024862 +n04184880 +n11720891 +n13869896 +n01678043 +n01647303 +n11532682 +n03236217 +n04963307 +n03012897 +n11682659 +n03191286 +n07643891 +n12737898 +n10680609 +n07924955 +n03879705 +n10461060 +n02523427 +n02013567 +n09893344 +n04124488 +n09863031 +n12454436 +n12305089 +n07709046 +n03805180 +n11940599 +n01691217 +n04198562 +n03978421 +n02357585 +n07818572 +n12870682 +n03798442 +n04154938 +n10550369 +n11957678 +n01958531 +n09936825 +n02334201 +n07910538 +n11978551 +n10562135 +n12700088 +n12784889 +n04480853 +n03281673 +n07588419 +n02968333 +n11935469 +n13046669 +n11730602 +n09643799 +n11849467 +n01758757 +n09638454 +n03267468 +n07914586 +n12104734 +n02961225 +n09827246 +n09917214 +n13079073 +n12634734 +n04089376 +n13034062 +n11714382 +n12753762 +n07683039 +n11840067 +n07689842 +n12173069 +n12172481 +n04182152 +n07869522 +n10356877 +n02771166 +n03154895 +n07615289 +n12986227 +n12361135 +n03456447 +n12706410 +n12895811 +n02988156 +n03130761 +n10639359 +n03628215 +n02738741 +n01643507 +n07730708 +n03232309 +n02846733 +n04969540 +n03051041 +n12890928 +n03235327 +n04289576 +n07588817 +n10325774 +n03973285 +n09703485 +n02358584 +n03061674 +n03195332 +n02901259 +n07849619 +n04486934 +n07908812 +n01588725 +n03682877 +n11949015 +n04146504 +n04146862 +n07898247 +n03318865 +n04367950 +n07880213 +n04247011 +n01447658 +n12711817 +n03146687 +n02926426 +n12856091 +n11966896 +n02413593 +n09764900 +n03009794 +n03314227 +n10499232 +n10075693 +n04451318 +n12320806 +n11933728 +n07764315 +n12133682 +n09904837 +n12832538 +n03816530 +n07802863 +n04391445 +n09728137 +n03887330 +n04436012 +n03957991 +n07771731 +n06266973 +n10407310 +n10290919 +n07862244 +n01842504 +n10262561 +n12726159 +n07691954 +n07618119 +n03437829 +n11966617 +n03629100 +n04231905 +n04208760 +n03344305 +n03684143 +n12934174 +n08645212 +n03556679 +n12109365 +n03751458 +n02380875 +n02025389 +n02770721 +n09830629 +n02800675 +n04951186 +n04483073 +n12710577 +n12789054 +n12058192 +n11777080 +n07716203 +n09618880 +n04525821 +n04016846 +n02918330 +n10375052 +n13158512 +n13090871 +n02929582 +n02308735 +n10487182 +n02213663 +n07608339 +n04384593 +n12890490 +n03992436 +n02994573 +n13231078 +n12880244 +n01651059 +n02925009 +n09686401 +n13219976 +n09981540 +n04582771 +n06267758 +n09893502 +n13214340 +n03272940 +n12554911 +n02214341 +n04137089 +n03874487 +n04573513 +n12003167 +n12004547 +n13065089 +n01903346 +n04373428 +n02216365 +n02024185 +n12577895 +n11698042 +n07586318 +n11705776 +n03030353 +n04486213 +n07885705 +n07928163 +n02356612 +n02767038 +n02897097 +n11662371 +n04128710 +n09842395 +n07683360 +n11533212 +n08495908 +n12841193 +n03669886 +n07768068 +n02381831 +n12081215 +n02757337 +n02811618 +n10144338 +n01379389 +n09698644 +n12779851 +n10400618 +n11801891 +n12322099 +n12408077 +n02767956 +n08640962 +n07816839 +n03021228 +n10346015 +n07868830 +n07917272 +n10076957 +n12865708 +n04290259 +n03595264 +n03986224 +n07825194 +n01610100 +n04417086 +n12995601 +n12734070 +n15091129 +n12428412 +n07587331 +n02405101 +n03108455 +n03594523 +n04489695 +n03892425 +n13032618 +n04409011 +n07590752 +n15092942 +n03914583 +n13066448 +n03532919 +n10639637 +n04566561 +n13223843 +n07904637 +n12347158 +n02720048 +n03901229 +n03936466 +n10574840 +n03782794 +n12397431 +n07908567 +n12580896 +n02697221 +n09791419 +n02577403 +n07870069 +n02136103 +n04318892 +n01462544 +n09747191 +n12287836 +n03067093 +n03934565 +n03543945 +n13126856 +n02240068 +n01585422 +n12413301 +n03246454 +n01876034 +n03635330 +n11680596 +n03228365 +n03082656 +n11609862 +n12859986 +n03934229 +n10233248 +n03166514 +n12166793 +n10115430 +n03327553 +n03373611 +n02967782 +n12338258 +n01604968 +n01323155 +n02590094 +n03044934 +n07866409 +n12291143 +n14900342 +n12094612 +n07845702 +n07926250 +n10750640 +n04359500 +n09797873 +n09953350 +n03561047 +n12122725 +n12725738 +n01453087 +n04977412 +n04575723 +n13219833 +n12161056 +n04273285 +n12482437 +n12863624 +n04953296 +n03390075 +n10188957 +n02874442 +n04236935 +n09990690 +n12866459 +n04075715 +n09725000 +n12794367 +n12461673 +n03050453 +n03677115 +n12427391 +n07736371 +n02973236 +n02406749 +n12322699 +n12815198 +n10680796 +n03268311 +n02405799 +n12302248 +n09791014 +n01545574 +n07740033 +n07862095 +n09901337 +n04390577 +n03597916 +n12110085 +n11802586 +n04205505 +n07696527 +n12076852 +n04344003 +n03326660 +n02823586 +n03042139 +n01565345 +n07905296 +n01454545 +n07650903 +n07905386 +n12530629 +n02841187 +n02943964 +n03329536 +n09681234 +n03479121 +n03770085 +n04147793 +n11552133 +n03774327 +n13197507 +n07901355 +n10400437 +n07837912 +n02310941 +n07845087 +n02239774 +n04976319 +n03960490 +n05239437 +n06275471 +n01633406 +n04257223 +n12009420 +n10483138 +n02775897 +n07866151 +n07922512 +n02666624 +n03944024 +n03842377 +n01832493 +n07855907 +n03968728 +n04492060 +n07879072 +n11635830 +n11802800 +n02357911 +n02431628 +n03730494 +n13099999 +n07768230 +n13147270 +n12331655 +n10237676 +n11855553 +n09759501 +n10620586 +n13181055 +n12309277 +n13183489 +n04382695 +n07679034 +n10495756 +n02173113 +n12764202 +n03683457 +n10298912 +n07680313 +n10160280 +n02205673 +n12053690 +n11653904 +n02931294 +n04093775 +n12856479 +n02427470 +n07608866 +n09954639 +n11639445 +n03364599 +n09924106 +n09683924 +n10419472 +n03089753 +n12620969 +n07604956 +n12940609 +n12564083 +n03514894 +n10343355 +n13068255 +n03805280 +n12793284 +n03140652 +n02666501 +n11717577 +n04267435 +n04593185 +n12820853 +n03934311 +n02630615 +n07767002 +n07723968 +n01631354 +n07931452 +n12414818 +n03097673 +n09944430 +n04457474 +n11850521 +n12227658 +n10131815 +n12408717 +n03566730 +n12777680 +n06273555 +n04357531 +n03759243 +n09861599 +n03015851 +n04175039 +n03392741 +n07859796 +n07741138 +n04474187 +n02266864 +n04553561 +n02667244 +n12720200 +n12432356 +n07806120 +n10362557 +n11929743 +n07765862 +n02963987 +n02762371 +n02747672 +n04289195 +n04056413 +n03039493 +n03894677 +n12338655 +n04422409 +n12079120 +n10252222 +n10168837 +n12919847 +n10297841 +n01340014 +n11710827 +n10167838 +n12278107 +n01384164 +n10498986 +n02742468 +n02899439 +n11752937 +n12107710 +n12315598 +n03985441 +n07605804 +n07686202 +n12884100 +n13121349 +n11725311 +n10420507 +n11706761 +n01381044 +n03331599 +n12336333 +n10185483 +n07880880 +n01782516 +n12615232 +n03175457 +n12657082 +n01750437 +n07918879 +n13213066 +n12927494 +n02910542 +n06273986 +n02161338 +n10235024 +n12180168 +n03659950 +n02160947 +n11861853 +n09866817 +n09279986 +n12393269 +n01552034 +n05526957 +n02956883 +n12818966 +n09753792 +n03114236 +n12273344 +n12546617 +n13177048 +n02129991 +n01731941 +n01628770 +n12774641 +n07685546 +n03253279 +n10678937 +n12579038 +n08673039 +n01392275 +n02379081 +n10530150 +n12851469 +n12414449 +n11694664 +n11877283 +n09708889 +n03585438 +n00483605 +n12332555 +n03323096 +n07851767 +n02417663 +n10667863 +n02856237 +n09269341 +n01596608 +n09720033 +n13160604 +n04443164 +n02814428 +n11622771 +n10328123 +n04338963 +n01794651 +n12069217 +n07762740 +n02935387 +n11897116 +n10569179 +n12749852 +n10745006 +n07823280 +n12162425 +n09801533 +n03772269 +n04518643 +n07916319 +n12771597 +n02147173 +n10342992 +n03795123 +n11646344 +n12847927 +n07686021 +n12383894 +n04465050 +n14564779 +n04212467 +n12274863 +n02380052 +n04329958 +n12034384 +n04213353 +n04366033 +n04955160 +n02778294 +n12890685 +n03028785 +n03097535 +n04533594 +n01750167 +n01415626 +n12276477 +n07729926 +n07711371 +n12843970 +n10500419 +n12891093 +n03840823 +n12509665 +n11878101 +n04315342 +n07685031 +n12305819 +n10039271 +n12264512 +n03911866 +n13919547 +n12413419 +n03785721 +n02599347 +n03786194 +n04018155 +n12856287 +n09607903 +n02396088 +n10212501 +n10313000 +n07683617 +n03586219 +n03890233 +n03156767 +n12033709 +n01648139 +n04399846 +n10671736 +n07698672 +n10791115 +n07708124 +n02709908 +n04266968 +n01758141 +n10058962 +n09444783 +n03668067 +n02838345 +n02388143 +n12893993 +n12590499 +n01462042 +n02689434 +n13209808 +n04075291 +n02412629 +n01953594 +n03906463 +n03043423 +n02200509 +n10152763 +n12504570 +n04396808 +n03382413 +n03618101 +n02767147 +n02390101 +n03450974 +n12778398 +n03625539 +n02574271 +n04113316 +n07572616 +n11809437 +n04119230 +n03829954 +n10500603 +n04258732 +n02731900 +n10174330 +n01574801 +n08663703 +n12558230 +n03981760 +n07732904 +n11875523 +n11823436 +n03238286 +n03079494 +n04281260 +n07873057 +n11686912 +n10568608 +n07593004 +n04271531 +n10037922 +n07838551 +n03615300 +n12624568 +n12940226 +n05242928 +n03680734 +n01589893 +n11652376 +n11893640 +n04119091 +n09696763 +n07851554 +n02660640 +n12124818 +n10370955 +n02663211 +n02414209 +n13187367 +n03258577 +n04375241 +n07617932 +n12240477 +n03417202 +n07595649 +n03839424 +n03087245 +n02431441 +n04396335 +n03484809 +n03426285 +n03592931 +n02912319 +n03488887 +n12187891 +n07592400 +n12918609 +n07858114 +n07567980 +n01548694 +n02726210 +n02406859 +n10147262 +n05458576 +n02848921 +n03503233 +n02587618 +n03465151 +n03582508 +n11654293 +n03695452 +n02197185 +n04223170 +n10243273 +n03149135 +n02842809 +n03669534 +n03857291 +n02147328 +n12278865 +n12733428 +n03264906 +n09924195 +n10432189 +n12203896 +n03892728 +n12360958 +n10418735 +n01650901 +n12420722 +n03341606 +n02557909 +n07751858 +n03483971 +n12019035 +n03991202 +n02072040 +n03129848 +n04505345 +n02405440 +n03901974 +n11656123 +n11552976 +n10291822 +n10108018 +n09902731 +n03325691 +n12646072 +n04134170 +n12097396 +n07564008 +n01624305 +n03421117 +n02776007 +n10792856 +n07818133 +n03227184 +n10198437 +n04157099 +n12743009 +n07820960 +n12749456 +n13035925 +n05262698 +n03422771 +n02878628 +n12140903 +n07820297 +n03524745 +n09901921 +n03170872 +n10039946 +n12638964 +n11989087 +n03461988 +n04287451 +n04298053 +n07882420 +n04002262 +n02734835 +n11707827 +n07756641 +n12808007 +n10069981 +n12637123 +n12947895 +n04363082 +n04292080 +n11858077 +n04535252 +n12646397 +n12283147 +n12321077 +n02746595 +n02895328 +n07624924 +n12537253 +n11952541 +n02181477 +n01440160 +n03878828 +n12861541 +n02869563 +n04242084 +n03197201 +n09396608 +n04291992 +n07845863 +n04314522 +n12843557 +n04029647 +n12146654 +n13147386 +n12954799 +n11920133 +n03038480 +n03213715 +n02971473 +n04149374 +n04230387 +n00444340 +n11859275 +n07564796 +n02948403 +n10186068 +n04315713 +n02366002 +n02670935 +n13208302 +n10225931 +n07826340 +n04102872 +n02259708 +n11855842 +n09941089 +n08896327 +n10237464 +n12084158 +n03764995 +n03627954 +n12384375 +n10341343 +n07876189 +n04573379 +n07904293 +n07840520 +n12038038 +n03005147 +n10483799 +n02978367 +n01484285 +n13094273 +n04539053 +n01748389 +n10146816 +n07815839 +n12991837 +n03294604 +n03588841 +n04055180 +n03209477 +n09917345 +n04393913 +n12337391 +n12126084 +n01882125 +n07688130 +n02814116 +n09640715 +n12679593 +n12596345 +n03029925 +n11761650 +n04457157 +n12683096 +n07709881 +n03841290 +n13157684 +n07927836 +n03523134 +n03690279 +n10187491 +n12451070 +n02682311 +n03978815 +n11806679 +n07808022 +n01386354 +n03622526 +n02369293 +n11885856 +n02289610 +n12663359 +n02624987 +n13173488 +n03027001 +n07896765 +n11935330 +n07814790 +n04242704 +n09959142 +n07589543 +n03551582 +n07843117 +n03556992 +n02060569 +n04000998 +n03825271 +n11946918 +n02874750 +n03479502 +n09919451 +n02176747 +n02080713 +n03400972 +n10222170 +n07926785 +n07852302 +n03012373 +n10438842 +n12868019 +n03634034 +n04210591 +n07853560 +n12374862 +n09248399 +n04355115 +n12908093 +n12906498 +n12875269 +n02791665 +n03146777 +n02854378 +n12414159 +n07821610 +n07595180 +n12238913 +n12141385 +n10761190 +n12165758 +n01653223 +n12956367 +n03695753 +n12416703 +n12346813 +n03405111 +n04304215 +n01624212 +n12674895 +n09850760 +n12407715 +n04156040 +n11610437 +n03395256 +n09970822 +n04229959 +n02530831 +n07870894 +n12098524 +n12828379 +n04057215 +n10751152 +n10053439 +n03674270 +n07869291 +n12256920 +n02535163 +n04282231 +n02136452 +n02365108 +n10328328 +n02315487 +n03325403 +n09231117 +n03342657 +n09980985 +n10702167 +n11961871 +n02065263 +n12857779 +n03219612 +n07805966 +n10699981 +n07691863 +n12831932 +n04179126 +n10208189 +n09765118 +n07922147 +n01631512 +n01947997 +n01405616 +n01892030 +n07827896 +n12964920 +n07749870 +n03276696 +n10020670 +n11828577 +n07624666 +n10590146 +n02407521 +n10253703 +n03270854 +n11610047 +n12981443 +n12413642 +n12302565 +n03177059 +n04594114 +n10227985 +n07728391 +n10395073 +n02810270 +n03569293 +n07812046 +n03843316 +n12477401 +n03802643 +n07618029 +n10755648 +n12837803 +n12454556 +n01636127 +n02809241 +n03270165 +n12035631 +n02962414 +n09750641 +n01793085 +n04346003 +n07922041 +n04164002 +n12499979 +n03301291 +n07921834 +n09656077 +n07599161 +n13155611 +n10194231 +n10063635 +n03601442 +n10366276 +n00475661 +n03943714 +n10377291 +n02624551 +n02568447 +n07589458 +n09691858 +n02685995 +n11919975 +n01690466 +n13211020 +n04114069 +n10530383 +n04200908 +n12631932 +n07916437 +n03219859 +n07918309 +n10368291 +n10253479 +n03317889 +n13206178 +n02821415 +n10592811 +n12557064 +n12872458 +n10212231 +n07926346 +n09695514 +n09741816 +n03964611 +n07812913 +n09703708 +n02587479 +n10593521 +n03485309 +n03776877 +n12289433 +n07716504 +n10580030 +n03061893 +n03206158 +n09710041 +n04266849 +n07864065 +n12767648 +n02333190 +n12295429 +n02406432 +n01799679 +n07861983 +n02201626 +n03441582 +n03653975 +n02834506 +n12263204 +n10672662 +n03072682 +n03410423 +n11620389 +n04542095 +n07910970 +n03697913 +n02706806 +n09736798 +n12318965 +n07938594 +n12032429 +n03191776 +n04210288 +n01422335 +n03236093 +n11881189 +n02247216 +n12338146 +n03104512 +n00474881 +n04172230 +n01461315 +n04400109 +n10646140 +n02215621 +n10096126 +n03019806 +n11809754 +n02492948 +n10741367 +n10308504 +n07875560 +n02523110 +n07738224 +n02015797 +n10499631 +n03025165 +n03284308 +n03508881 +n10441037 +n10757492 +n07608721 +n09755241 +n04264361 +n04394421 +n03776997 +n03175843 +n04476526 +n02523877 +n13196369 +n10190122 +n03172738 +n02709763 +n02070624 +n04563560 +n04017807 +n03824589 +n07817758 +n03222722 +n01542433 +n13173259 +n04458201 +n12869668 +n12580786 +n02407763 +n09760913 +n10530571 +n11752798 +n09612700 +n07601175 +n11632376 +n10641223 +n03158668 +n03411208 +n01413457 +n03684740 +n10248008 +n12656528 +n11849271 +n07771891 +n12067433 +n12389727 +n11734698 +n04042204 +n07825399 +n12621945 +n07624757 +n03180732 +n09741331 +n10246317 +n04030414 +n07821107 +n04524716 +n03789603 +n12867449 +n10249869 +n02434415 +n07614103 +n03333349 +n04602840 +n09923996 +n02658811 +n13033879 +n03663433 +n02873623 +n07837545 +n12436907 +n02675077 +n01500854 +n04435552 +n01790304 +n11687789 +n03443543 +n09733459 +n01606177 +n12245885 +n11721642 +n02201497 +n12010815 +n04594742 +n02755984 +n07927716 +n04245218 +n03134118 +n13214485 +n12294542 +n12713521 +n03556173 +n12650038 +n07719058 +n04319774 +n10443830 +n10019187 +n09720702 +n07926442 +n10402709 +n03989777 +n11699751 +n09613118 +n02965122 +n04221076 +n01861330 +n12837052 +n02975589 +n09668437 +n03012499 +n01418498 +n12451566 +n03585778 +n07692517 +n09672590 +n09741999 +n09748648 +n07621264 +n03482001 +n10185148 +n01542168 +n12536291 +n07846557 +n11840476 +n03130866 +n02631775 +n11730015 +n03715275 +n07680168 +n12175370 +n05427346 +n03665232 +n08611421 +n11730458 +n02413484 +n09783884 +n07888378 +n04611351 +n02247655 +n02136794 +n11649359 +n01382033 +n07889193 +n10405540 +n03510384 +n04420720 +n03585875 +n03812789 +n01835769 +n12139921 +n09762011 +n10103228 +n03477410 +n11930788 +n10064831 +n12311045 +n07681805 +n03136504 +n12887713 +n03886940 +n03130233 +n10197392 +n12333961 +n07672914 +n12723062 +n12599661 +n04268799 +n03696909 +n12809868 +n12452256 +n10710778 +n02571652 +n12117326 +n02450677 +n03041265 +n12544240 +n01966377 +n10252354 +n02378625 +n09814488 +n10569011 +n13067330 +n07928998 +n07890970 +n02187279 +n02592371 +n07846802 +n03475961 +n05448704 +n10410996 +n02851795 +n10093167 +n12468719 +n09876701 +n03057724 +n03469031 +n02344270 +n04248209 +n02687682 +n04467899 +n12897788 +n03436656 +n12539832 +n09906704 +n03190458 +n11843441 +n12130549 +n11823756 +n03153246 +n03684489 +n04160036 +n02908951 +n12855365 +n03518230 +n12225222 +n12933274 +n10432957 +n02921406 +n10156831 +n12239647 +n02826812 +n03411927 +n11602091 +n13200986 +n04244847 +n01330126 +n14938389 +n03001540 +n04387531 +n03423099 +n07608533 +n11723986 +n07600394 +n12529500 +n02403820 +n02587300 +n10333317 +n07935288 +n12680652 +n01449980 +n12153914 +n07803310 +n11741797 +n01881857 +n13081999 +n08644045 +n02061217 +n02173784 +n02660519 +n03104019 +n13137951 +n04538403 +n02621258 +n04515729 +n04165945 +n11919761 +n13078021 +n07861247 +n11959259 +n11801665 +n04070545 +n13210597 +n10218043 +n10717337 +n01365885 +n10718952 +n11979187 +n03880032 +n03798610 +n03477303 +n01876667 +n11860208 +n03401721 +n03360133 +n13230843 +n13194758 +n13190060 +n02564935 +n13894154 +n12754311 +n07697408 +n13171210 +n02035402 +n03736147 +n10396337 +n04554998 +n02793930 +n04126852 +n03654826 +n09411295 +n06255613 +n01680983 +n10261862 +n01581874 +n10378780 +n10646641 +n03539103 +n03351151 +n04349913 +n03906106 +n02370525 +n03319576 +n04113968 +n09693244 +n02945964 +n03344509 +n04117216 +n03889626 +n03557840 +n09800469 +n04280487 +n07890890 +n12147835 +n12295237 +n03883664 +n04436992 +n02922877 +n10099002 +n01988203 +n10056719 +n11646517 +n03672521 +n04568713 +n10111358 +n03606347 +n04047733 +n12320627 +n10251612 +n10460033 +n01742447 +n11917835 +n10443032 +n13079567 +n04363671 +n10788852 +n10482587 +n03308614 +n12741586 +n12938667 +n04539407 +n01630148 +n02303777 +n13050940 +n04552551 +n02341288 +n04098169 +n04110439 +n11625391 +n12259316 +n02822762 +n10631131 +n04089152 +n03571439 +n04558199 +n12656909 +n03170292 +n02877642 +n12771890 +n03033267 +n12658603 +n13354021 +n12855886 +n11840246 +n03619050 +n07727252 +n12932706 +n13874073 +n01315805 +n02948942 +n12048928 +n03146449 +n10656969 +n09872557 +n03906590 +n04454792 +n12500309 +n04239333 +n01815036 +n09644657 +n10497645 +n02918455 +n07812662 +n04240434 +n10804636 +n11967878 +n04184095 +n11834272 +n05244755 +n02299039 +n12665659 +n12144987 +n07607492 +n11887750 +n13083461 +n04577139 +n09670909 +n07876893 +n02875948 +n04069582 +n10458111 +n10361194 +n09389867 +n01651778 +n11933387 +n13193143 +n12834190 +n03516266 +n02184589 +n10041373 +n02809605 +n04064213 +n04957589 +n12643113 +n02582721 +n07911061 +n07921360 +n10369417 +n10527147 +n04104925 +n03707372 +n01386182 +n10374849 +n09902851 +n08559155 +n02332447 +n11649150 +n11722036 +n01823740 +n04592356 +n10002257 +n10661732 +n07562379 +n07597263 +n04036776 +n13112201 +n09842288 +n07738105 +n04545984 +n09635973 +n02885233 +n02756854 +n07808479 +n03029296 +n01543383 +n02884450 +n09843716 +n04224395 +n10576676 +n10140051 +n07919894 +n07806879 +n10212780 +n09478210 +n12017127 +n03770224 +n07606191 +n03555217 +n09715165 +n12270460 +n12129738 +n11739365 +n02303585 +n07818029 +n05314075 +n03019304 +n09859975 +n09454744 +n13151082 +n12586989 +n00455076 +n07741357 +n04957356 +n08659242 +n04577293 +n04126244 +n03131193 +n12428242 +n03569494 +n03781594 +n07743384 +n02892392 +n12576695 +n12199982 +n07693439 +n07719756 +n11884384 +n03043798 +n12351091 +n03690168 +n02214499 +n01839949 +n01831360 +n12642964 +n02957862 +n03125588 +n12883628 +n04002371 +n10747965 +n09744462 +n02853745 +n13030337 +n12156679 +n02761034 +n12587487 +n03374570 +n12728322 +n01731764 +n07918706 +n03696445 +n03185868 +n02805283 +n03868763 +n02202124 +n12369665 +n12449934 +n12650229 +n02656301 +n07743723 +n11702713 +n02927053 +n03916385 +n01486010 +n03986071 +n04188064 +n13897528 +n12414329 +n07718068 +n07837755 +n11735570 +n10464542 +n04091466 +n01315581 +n10374943 +n03989898 +n13220525 +n04076052 +n04062179 +n02414442 +n04414101 +n04446162 +n00480885 +n03536568 +n03773835 +n10728998 +n12643877 +n02255391 +n03799610 +n07847585 +n00446411 +n11910666 +n03139998 +n02296276 +n02889996 +n02786611 +n10363445 +n07854348 +n08583682 +n09912681 +n07896422 +n02368821 +n11935953 +n12185254 +n11738547 +n03809211 +n02448318 +n13066979 +n01987076 +n12009047 +n12839574 +n13174823 +n07902520 +n03369866 +n13209129 +n02593191 +n03853291 +n02620578 +n10071332 +n01813658 +n09895480 +n10134760 +n01316734 +n07845166 +n03175983 +n13132156 +n12814960 +n12883265 +n03637787 +n04310507 +n04133114 +n03900194 +n04129688 +n04449550 +n01805321 +n01717467 +n01573627 +n12271451 +n11722621 +n09976917 +n12232280 +n12905135 +n03451253 +n01655344 +n12346986 +n11987511 +n10517283 +n02941845 +n12730370 +n03121190 +n07917874 +n10023656 +n10151133 +n07695187 +n03258456 +n10639238 +n10682713 +n02085019 +n12343753 +n10749928 +n04595611 +n04410565 +n08500819 +n07719980 +n04016479 +n03232417 +n03469832 +n09834885 +n07925327 +n10094782 +n03632100 +n12734215 +n09845849 +n04047139 +n10743124 +n02604954 +n12270278 +n03036244 +n11991777 +n10168012 +n02561803 +n10531109 +n10344319 +n03804211 +n10513938 +n10732967 +n09917481 +n02950482 +n03148808 +n07910245 +n07925423 +n07889990 +n04302988 +n07745357 +n04346511 +n07573563 +n02564403 +n12084400 +n10030277 +n09815455 +n04388473 +n12404729 +n10576316 +n12072210 +n11811059 +n01824344 +n03556811 +n03175301 +n07586485 +n13137010 +n11986729 +n04967561 +n03881404 +n07692114 +n07874995 +n02770585 +n07853345 +n02775689 +n04328580 +n01323781 +n07773428 +n02414043 +n02794474 +n02352932 +n07569873 +n12374705 +n03606106 +n04267246 +n04369485 +n11934239 +n12705698 +n11841247 +n07868045 +n03525693 +n12358293 +n02937010 +n09658398 +n12711182 +n03516647 +n04591631 +n10228712 +n11930353 +n03471779 +n12594324 +n02251593 +n04455579 +n02542017 +n03381450 +n03320845 +n12364940 +n09657748 +n12412987 +n01840412 +n10570704 +n10117267 +n03251280 +n10195261 +n12178129 +n12285049 +n02177775 +n10117415 +n03707766 +n04475309 +n05604434 +n03999064 +n12127575 +n01972131 +n09793946 +n01635176 +n02791532 +n07564101 +n07876460 +n02813981 +n10764719 +n03638743 +n12761702 +n02125689 +n11657585 +n09923003 +n13069773 +n02683183 +n04324515 +n11936946 +n12862828 +n02659808 +n02619861 +n13175682 +n11648039 +n07768139 +n12512674 +n12108613 +n02947977 +n12899971 +n03845107 +n07689490 +n02081927 +n07619508 +n10248377 +n10300041 +n10761326 +n09655213 +n02675522 +n04963111 +n01995686 +n03256631 +n10684630 +n04471912 +n12728864 +n03870546 +n02829246 +n09725546 +n03409920 +n13194918 +n10055297 +n02513248 +n01462803 +n11782266 +n13094145 +n07839478 +n13916363 +n07932454 +n09722817 +n07774479 +n10386874 +n12832822 +n01599388 +n02964295 +n04349189 +n07689313 +n11653126 +n02309841 +n02064000 +n04410663 +n04562122 +n02358712 +n09901786 +n10441124 +n12882158 +n12815668 +n10159289 +n01641930 +n03315990 +n12271187 +n10277638 +n07815163 +n12903014 +n07915366 +n04412300 +n01324799 +n03408264 +n09452291 +n03019198 +n11890884 +n10355806 +n03186199 +n04013600 +n12541157 +n06259898 +n06273294 +n11946051 +n01671705 +n04415257 +n01905321 +n04050600 +n12604460 +n04051439 +n02929184 +n11765568 +n10025060 +n02396796 +n04033287 +n13027557 +n03127531 +n10308066 +n09729062 +n01593553 +n02476567 +n07609728 +n12970293 +n01419888 +n03215749 +n01684741 +n13067672 +n03870290 +n07846359 +n12961536 +n03356559 +n07727140 +n09843602 +n02378755 +n12044041 +n01977485 +n07718920 +n12060546 +n04265428 +n12237855 +n04006067 +n10227266 +n04361937 +n12134486 +n10097842 +n02264591 +n03912821 +n07594155 +n03116163 +n11771924 +n04155457 +n12394118 +n10507380 +n01844746 +n11901452 +n03024233 +n03383562 +n11806814 +n10062716 +n04204755 +n08613733 +n12907671 +n03533654 +n09826605 +n03109033 +n07606419 +n03537085 +n11615812 +n07695504 +n11694300 +n04520962 +n09971839 +n02664285 +n03402511 +n02061560 +n13133140 +n03548195 +n12877493 +n02425086 +n12845187 +n12488454 +n02975994 +n02071028 +n01457407 +n03685486 +n07605282 +n07771405 +n07827554 +n10538733 +n03438780 +n04379096 +n12686496 +n10001764 +n11848867 +n12125001 +n09886540 +n03275566 +n01442710 +n12789554 +n07858197 +n12722071 +n12868880 +n10441694 +n12409651 +n07727741 +n12289585 +n04069166 +n12686877 +n03723439 +n07815956 +n12543455 +n10778044 +n02200630 +n10074841 +n12640284 +n12589841 +n07592317 +n07866571 +n12712626 +n04228422 +n11711289 +n03590475 +n13081229 +n03045800 +n03639230 +n02874214 +n07615954 +n03204134 +n12053962 +n12769219 +n15006012 +n09873769 +n11818636 +n01959029 +n03349599 +n12227909 +n07576969 +n03638180 +n07742224 +n03390673 +n02344175 +n03770520 +n00447361 +n13235319 +n01983674 +n10061882 +n04267165 +n12493868 +n12713358 +n02930339 +n10493419 +n12918810 +n02582220 +n12248359 +n02644501 +n04596492 +n04538249 +n07905618 +n13230190 +n07808268 +n15005577 +n09351905 +n12730544 +n11937023 +n04024137 +n02238358 +n11646955 +n11618079 +n09849990 +n04060448 +n04220805 +n12725940 +n12004120 +n01484562 +n02669442 +n12132956 +n01756916 +n03980986 +n02256172 +n07716750 +n12119390 +n04047834 +n11934041 +n12828977 +n03648219 +n11873612 +n12909614 +n04397860 +n03908111 +n03261395 +n03695616 +n11668117 +n12014355 +n02896074 +n03988758 +n04426184 +n10328696 +n02477028 +n04507326 +n04320871 +n03256472 +n01919385 +n03988926 +n13182164 +n07826250 +n03207548 +n01396617 +n04369618 +n07913774 +n13229951 +n03410022 +n12728508 +n01997119 +n03598783 +n01341090 +n03879456 +n01736796 +n02864122 +n13879816 +n02684962 +n12246037 +n02433729 +n04364397 +n09881358 +n02950120 +n03326371 +n02243878 +n01790812 +n12990597 +n03330947 +n07764486 +n03332173 +n10006177 +n03347472 +n07619301 +n10106509 +n12365285 +n01732989 +n07678586 +n04098795 +n07733847 +n03994297 +n12872914 +n02762909 +n07766530 +n13198482 +n02395855 +n12273515 +n04487894 +n07847047 +n12488709 +n02859557 +n04255768 +n02360933 +n03267696 +n03152951 +n10188715 +n10520544 +n13065514 +n02900594 +n03699754 +n01319187 +n01949499 +n10417424 +n01603000 +n12062105 +n09683180 +n09863339 +n01880716 +n10702615 +n03893935 +n10495555 +n04131499 +n02957252 +n02113892 +n07724078 +n12246941 +n04303095 +n01751215 +n04213530 +n12117695 +n12418507 +n01922948 +n12131405 +n13188767 +n01481498 +n03174079 +n02407172 +n11613867 +n10152616 +n10119609 +n04158250 +n11695085 +n07855105 +n02854630 +n03768683 +n12739966 +n12266984 +n12819141 +n12732605 +n13205249 +n11917407 +n01607429 +n02694279 +n07815294 +n06614901 +n07846471 +n12119717 +n02595339 +n12366186 +n10693235 +n12263410 +n12484244 +n10337488 +n04146976 +n01469723 +n07872748 +n03238879 +n12000191 +n07846938 +n03116008 +n12139196 +n04013176 +n10317963 +n12140511 +n02065726 +n01649556 +n10316862 +n01755952 +n04385079 +n12770529 +n02814338 +n01675352 +n11874423 +n01369484 +n10537708 +n07618281 +n07821404 +n02297819 +n03238762 +n03357081 +n02628600 +n07830986 +n12507823 +n04431925 +n11955532 +n03429771 +n10281896 +n12383737 +n12760875 +n09673091 +n12892013 +n06625062 +n04503269 +n03674842 +n12338979 +n04268275 +n12033139 +n11767877 +n07812790 +n12676134 +n04037873 +n10097477 +n12310638 +n12258101 +n09391386 +n13196738 +n13866626 +n12720354 +n10106995 +n07843220 +n03878294 +n04101375 +n07733217 +n10220080 +n04601938 +n10778148 +n12973937 +n10556825 +n12256708 +n12583855 +n04259202 +n07628181 +n04226962 +n02777402 +n09674412 +n12188635 +n03776167 +n04504038 +n04156591 +n02270945 +n02264021 +n07826653 +n02980203 +n02059852 +n02102806 +n12921660 +n04477725 +n10107173 +n12837466 +n02697022 +n04350688 +n12110236 +n02177196 +n07899976 +n12639910 +n02368399 +n10009162 +n03950647 +n09248153 +n02425532 +n04044955 +n11933257 +n03460899 +n10147710 +n02379743 +n02413917 +n02890804 +n12915140 +n02146879 +n07915800 +n01787006 +n03646809 +n11677902 +n04065909 +n02088992 +n02887832 +n10115946 +n02306825 +n03719560 +n10456696 +n03758220 +n12625003 +n04021503 +n07563366 +n02531625 +n10304650 +n12855710 +n09735654 +n07853762 +n03512030 +n12898342 +n02297938 +n12618727 +n04082344 +n12953712 +n12617559 +n03035715 +n02532451 +n05399356 +n03602686 +n10082423 +n04607759 +n07581607 +n07594737 +n04030965 +n03464628 +n12103894 +n03039353 +n03522990 +n02964934 +n03169063 +n10153865 +n09653144 +n09941571 +n12907057 +n07768318 +n02600798 +n02187150 +n01811243 +n12252383 +n04495555 +n07678953 +n13181244 +n13069224 +n13184394 +n12765402 +n03471347 +n10208847 +n03697366 +n09840435 +n02506947 +n09709673 +n07928578 +n11935715 +n07848936 +n02757927 +n01999767 +n02245443 +n10260473 +n13898645 +n02701260 +n07840219 +n11785875 +n12385830 +n12017664 +n12145148 +n04530456 +n01929186 +n02384741 +n04113038 +n03296217 +n09723819 +n03766697 +n12143215 +n09929202 +n02684248 +n12119539 +n03566555 +n12941220 +n04124573 +n10750188 +n07733005 +n04230707 +n03829857 +n07756838 +n12244458 +n12543826 +n03514129 +n02762169 +n04435870 +n03342863 +n09745324 +n12369476 +n11652039 +n03915320 +n07746749 +n07608641 +n12642600 +n02389943 +n12137791 +n04111962 +n12493426 +n12454793 +n01455317 +n10728117 +n03281524 +n12195734 +n12353431 +n02477329 +n02678010 +n04557522 +n10162354 +n14942411 +n07806043 +n12274151 +n09835153 +n03983499 +n04086663 +n07851926 +n07868684 +n11926976 +n03972146 +n04310604 +n09675799 +n13880704 +n13173132 +n07577918 +n10720964 +n11937102 +n03349020 +n12340581 +n03725506 +n03477143 +n10578162 +n01731137 +n03382104 +n11616852 +n01493829 +n09327077 +n03856335 +n03321843 +n02375757 +n02118643 +n08500989 +n03496486 +n04140777 +n12858987 +n02845293 +n04093157 +n07819682 +n10394786 +n12289310 +n02901620 +n01559160 +n07919165 +n12648196 +n11774972 +n11995396 +n10543937 +n10154013 +n03977158 +n01884476 +n12266528 +n11906127 +n12661538 +n04396650 +n12761905 +n04175574 +n10181878 +n12017326 +n12876899 +n09744346 +n07741706 +n04451636 +n07735981 +n03751590 +n03140546 +n03070396 +n03091223 +n12071477 +n07562017 +n09981092 +n09847344 +n12552893 +n12371202 +n02245111 +n01598271 +n04400499 +n02298095 +n15048888 +n02967170 +n04030161 +n10676434 +n01556514 +n13235766 +n02538562 +n12603672 +n03941586 +n02449183 +n07567611 +n12923257 +n02296021 +n11730933 +n12497669 +n02917742 +n07875926 +n02714535 +n13142182 +n02878107 +n07861334 +n02682811 +n03730655 +n03681813 +n12970733 +n02132320 +n12436090 +n07931280 +n04295353 +n12982590 +n01783017 +n13164501 +n02424589 +n01499732 +n12650805 +n04543509 +n10369699 +n03439631 +n13160116 +n07831663 +n05449196 +n13025854 +n10169241 +n02847461 +n10734963 +n13213397 +n03343234 +n12275317 +n02793414 +n04300509 +n01803893 +n11617878 +n02179192 +n03637480 +n04514648 +n03087521 +n10478827 +n11757190 +n12919195 +n04532504 +n01736375 +n04015786 +n04545471 +n12668131 +n04472961 +n14786943 +n07584938 +n02498743 +n07744559 +n10010062 +n10101308 +n07832099 +n02601767 +n10473453 +n02451575 +n02496052 +n03696746 +n12669803 +n07904072 +n04290762 +n11737125 +n07760755 +n12553742 +n12068138 +n12630999 +n02390938 +n02202678 +n02216740 +n02679961 +n13173697 +n11828973 +n02287987 +n04585318 +n10360366 +n07745661 +n03474352 +n07934800 +n12677612 +n03692272 +n13092240 +n04230487 +n11846312 +n12433952 +n11793403 +n03056873 +n05454833 +n12517077 +n12682882 +n02649218 +n09425344 +n07878283 +n02795978 +n10064977 +n12754174 +n02945813 +n01750743 +n03150661 +n13880415 +n12337800 +n04017571 +n09754907 +n04456734 +n02967540 +n10621400 +n11744471 +n01971620 +n04148285 +n10781817 +n11991549 +n12305654 +n03943833 +n10330931 +n12918991 +n01783706 +n11933099 +n12931231 +n07589967 +n09666349 +n07853445 +n12714949 +n03548533 +n04158672 +n03809802 +n03080309 +n12800049 +n02578454 +n02834027 +n10067600 +n03044671 +n04198233 +n07930205 +n04357930 +n12221522 +n11957317 +n03085781 +n03723885 +n03614383 +n02661618 +n04292221 +n03426574 +n03838024 +n10442093 +n12399534 +n01450950 +n07876550 +n11937446 +n09870096 +n02631628 +n05460759 +n01710177 +n03660562 +n04283784 +n01497738 +n02232223 +n04209811 +n12837259 +n02864987 +n04499810 +n12654857 +n03493792 +n09688233 +n02312912 +n10057271 +n07606058 +n03258192 +n10507565 +n11930038 +n08679269 +n03812263 +n11662128 +n04085574 +n07643577 +n03981094 +n02796412 +n02513939 +n07686634 +n07936979 +n03168774 +n03816394 +n07625324 +n04138131 +n10383094 +n10222716 +n10381981 +n12254168 +n13223090 +n03056583 +n09910556 +n03277004 +n12649866 +n02089725 +n03688707 +n09665367 +n07849506 +n02843909 +n13141797 +n02477516 +n09710886 +n03835941 +n11734493 +n10778711 +n10007809 +n02038141 +n12766043 +n02353172 +n02030224 +n10762212 +n06274921 +n13033396 +n03560860 +n01961234 +n13868515 +n03216199 +n01553527 +n04429038 +n10211036 +n02150885 +n02435517 +n02755675 +n09699020 +n12566331 +n03909516 +n02903727 +n02594942 +n04173172 +n04125692 +n12251001 +n02412787 +n01649412 +n01411450 +n01774097 +n09912907 +n03162556 +n07566231 +n12267534 +n03928589 +n04142327 +n11771147 +n07832592 +n04155177 +n07937621 +n07839864 +n03201895 +n13095013 +n10298271 +n03059103 +n03784793 +n11925450 +n03288742 +n02809364 +n04108999 +n04449449 +n03726233 +n07854455 +n03692136 +n12018447 +n03374282 +n06008896 +n07598928 +n03577312 +n04604806 +n09892513 +n04370600 +n08238463 +n01793159 +n07822687 +n03242390 +n07685303 +n03822361 +n01996280 +n10505942 +n06596845 +n04219580 +n12056990 +n10579062 +n10240082 +n10298202 +n07711907 +n03905730 +n12222900 +n07598622 +n04415815 +n12389932 +n12154114 +n04210012 +n12500751 +n03729402 +n12122918 +n04572121 +n12804352 +n02415130 +n12780325 +n11639084 +n12768933 +n02253494 +n13217005 +n03567788 +n12304286 +n10703480 +n07766723 +n05455113 +n07741804 +n12186839 +n01687128 +n01350701 +n03260206 +n07876026 +n12528382 +n04125541 +n10457444 +n01606097 +n11717399 +n04598416 +n12899166 +n09748101 +n12160125 +n07608980 +n07843348 +n02409038 +n02571167 +n09980805 +n09706029 +n02495242 +n12765846 +n10373525 +n12321873 +n03047171 +n12365462 +n03752398 +n02662993 +n10316527 +n10728233 +n06273207 +n01733214 +n12297846 +n12755876 +n02428842 +n02289307 +n04536465 +n03253187 +n02297294 +n05584746 +n03117642 +n12189779 +n10338231 +n07599649 +n04559994 +n12710917 +n09966470 +n12470907 +n04499300 +n12403075 +n11837743 +n02269657 +n12599185 +n07618587 +n03996004 +n12851094 +n03392648 +n01319001 +n12826143 +n12369845 +n01814549 +n10056103 +n12854193 +n02267483 +n04019881 +n03490649 +n04268142 +n10801802 +n12315060 +n10149436 +n04563790 +n09865068 +n03000530 +n10657556 +n07840672 +n12118414 +n02856013 +n02900459 +n04094859 +n12079523 +n11827541 +n12236160 +n02904505 +n02846619 +n09842823 +n12926039 +n02146201 +n03195799 +n12815838 +n09899289 +n01483021 +n02519340 +n05453815 +n10329035 +n02494383 +n09742927 +n13220355 +n03212406 +n11759609 +n10061431 +n12095281 +n04262530 +n03799240 +n02426176 +n04608809 +n12230540 +n13880551 +n11741175 +n11858814 +n11723452 +n07590841 +n12604845 +n10342543 +n12760539 +n09270657 +n02563079 +n10643937 +n12843316 +n01651641 +n07838811 +n04359034 +n07758260 +n02762725 +n11726433 +n03114743 +n01952029 +n12321395 +n11930571 +n12337922 +n12427946 +n12001294 +n12551457 +n13235011 +n02290340 +n06419354 +n12408873 +n01741442 +n12308447 +n10243872 +n03658635 +n03694761 +n02570484 +n12912801 +n04158002 +n02417785 +n01332181 +n03703075 +n10283366 +n03142431 +n02779609 +n02300554 +n09868782 +n10323752 +n03166809 +n03394149 +n02827148 +n02186717 +n01350226 +n03344784 +n03555996 +n04498873 +n13157481 +n04519887 +n12028424 +n12349711 +n10471640 +n07741235 +n04032936 +n12357968 +n10228592 +n13178284 +n04168840 +n13239177 +n03561573 +n02566489 +n11807696 +n07681264 +n02566665 +n10456070 +n10063919 +n10492727 +n01788579 +n11977660 +n02036228 +n02738978 +n03989349 +n10332953 +n12949361 +n09901502 +n07839730 +n13146928 +n10152306 +n04170515 +n11602478 +n02522722 +n01333610 +n13030852 +n02143891 +n12807624 +n04542329 +n12243693 +n12036226 +n13917690 +n02553028 +n02752199 +n10594857 +n11627714 +n04348070 +n13171797 +n04612257 +n07934373 +n04536765 +n02244515 +n04526800 +n04546595 +n02551668 +n12143405 +n07871588 +n07858484 +n03628728 +n13179804 +n03242264 +n12089846 +n07588688 +n07620047 +n01647466 +n09685233 +n03467254 +n12666369 +n05449661 +n10694939 +n12886600 +n12256522 +n04006330 +n03317673 +n04316815 +n12222090 +n04022866 +n04088441 +n07617526 +n10782362 +n04355821 +n13901490 +n12508618 +n03849943 +n04503499 +n13193466 +n09754633 +n07583978 +n13911045 +n07643679 +n12054195 +n10692090 +n04032509 +n10146927 +n02031298 +n04002629 +n04035748 +n10712229 +n02866106 +n07909504 +n04540397 +n06266878 +n10219879 +n12567950 +n07853648 +n03191561 +n07856045 +n12646197 +n03317510 +n10515863 +n13198054 +n02808829 +n12889579 +n02698473 +n09924437 +n03595055 +n12306270 +n07857356 +n09715303 +n03024518 +n04323519 +n09629065 +n04178668 +n12748248 +n02308618 +n07873198 +n10564098 +n03007297 +n04036155 +n02143439 +n10507482 +n12267931 +n03956331 +n12888234 +n04066476 +n07813107 +n02736396 +n10306496 +n12324388 +n01744555 +n01649726 +n06596179 +n03616091 +n07754279 +n02072493 +n12408280 +n04314632 +n02412700 +n04030846 +n09833997 +n03599964 +n05258627 +n12572759 +n12136581 +n02419056 +n12453714 +n11652217 +n03878511 +n03907908 +n12223160 +n10514121 +n04153330 +n12163279 +n12623818 +n03495671 +n13222985 +n10354754 +n04365112 +n12384680 +n12538209 +n03105214 +n12534862 +n13869045 +n03945928 +n11613692 +n11892181 +n13002209 +n02685253 +n07598529 +n02629716 +n13202355 +n07927070 +n02176916 +n04370955 +n11988132 +n03246197 +n01440467 +n07620145 +n03940894 +n01897667 +n03408340 +n12602612 +n02539424 +n03863657 +n04559620 +n02604480 +n11822300 +n03518829 +n11619845 +n10504090 +n03341035 +n02908123 +n04281998 +n03277602 +n03865288 +n10074578 +n13902793 +n03054605 +n04404200 +n12786836 +n12235051 +n04035231 +n12009792 +n12705458 +n04378489 +n02476870 +n11954798 +n03573848 +n02087314 +n03162460 +n04363412 +n02261063 +n09953615 +n01947139 +n03044801 +n04287351 +n04479287 +n03861596 +n12510343 +n07854066 +n03027505 +n12161577 +n04197878 +n01812187 +n10015792 +n08685188 +n11737009 +n10333044 +n02730568 +n10290813 +n13096779 +n05257476 +n07917951 +n12121187 +n03517509 +n07932762 +n02336275 +n12159942 +n12105981 +n02562971 +n13882961 +n12016777 +n02793684 +n12717644 +n01380754 +n07724173 +n04055861 +n11831297 +n03059934 +n03370646 +n10065758 +n09459979 +n07913644 +n04322531 +n03457451 +n02567633 +n04240867 +n10693334 +n10556704 +n04614844 +n07909362 +n12082131 +n09268007 +n04359217 +n09883807 +n02292085 +n04052346 +n03431570 +n02843465 +n04584056 +n04432043 +n09846142 +n07864317 +n04475749 +n04227050 +n04280845 +n03535284 +n07890617 +n03217889 +n02806762 +n11967315 +n11762927 +n02501923 +n03442487 +n09690083 +n02964634 +n02920164 +n07855317 +n10196725 +n03042829 +n11662937 +n12183816 +n12311224 +n13884261 +n02243209 +n03140771 +n02385002 +n03071288 +n12936826 +n04583022 +n07859142 +n04578112 +n04467506 +n12938081 +n09982152 +n12555255 +n03335333 +n10104888 +n12151170 +n12709349 +n10456138 +n02237868 +n07620327 +n12561309 +n12341931 +n12350032 +n01775730 +n12950796 +n01440242 +n04261767 +n10568915 +n12285195 +n07589872 +n13112035 +n07840395 +n11750508 +n12286197 +n03336168 +n03325288 +n02551134 +n04293258 +n13130014 +n07733124 +n04451139 +n11985903 +n03602365 +n11722342 +n11944751 +n12897999 +n02277422 +n03101302 +n07608245 +n03531982 +n01997825 +n11713370 +n04442582 +n02833403 +n04427857 +n01648356 +n10645223 +n10414865 +n10696101 +n12885045 +n10037080 +n12218274 +n07570530 +n04493259 +n10659042 +n10577710 +n03141612 +n10582604 +n00446632 +n02834642 +n07568389 +n04583888 +n04096848 +n12879068 +n04495051 +n09837459 +n12216215 +n03702440 +n10174695 +n10559009 +n10577182 +n07686299 +n04269668 +n02404028 +n03720665 +n09885866 +n03082450 +n12492682 +n12780563 +n03703463 +n02644360 +n02307910 +n01374703 +n04402342 +n04264134 +n03158414 +n04443433 +n12522894 +n10803978 +n11706942 +n10751026 +n13143758 +n02972934 +n04174234 +n12718995 +n11994150 +n11545350 +n12526754 +n07753448 +n02870772 +n11942659 +n11744108 +n12735160 +n12229887 +n04970312 +n02874336 +n10721819 +n13193269 +n03330665 +n09865162 +n10306595 +n12161744 +n03303669 +n07846688 +n02168427 +n01961600 +n03559531 +n09826821 +n03413124 +n09695019 +n03783873 +n11863877 +n13874558 +n02283617 +n11895472 +n13182799 +n07854614 +n03283827 +n01397690 +n02650413 +n09809279 +n10290541 +n10383505 +n11724660 +n07689757 +n10181547 +n07620597 +n11979354 +n02771547 +n13061471 +n12631637 +n11966385 +n03969510 +n11735977 +n07621497 +n12956588 +n03217653 +n04546081 +n11696450 +n10300654 +n02032769 +n01654863 +n09779280 +n02390258 +n03887512 +n10489426 +n10745770 +n10713843 +n03602194 +n10710913 +n07864475 +n04486322 +n07915213 +n08663051 +n10236842 +n02390738 +n02388453 +n03598385 +n12228689 +n11771746 +n12803226 +n11242849 +n02378149 +n10427223 +n05448827 +n11870044 +n12477983 +n12311413 +n03500090 +n10280034 +n02685365 +n03652389 +n12728656 +n07695284 +n09961198 +n03780799 +n03935883 +n01612955 +n12475774 +n02701730 +n07833535 +n12584365 +n03902220 +n12727960 +n10619492 +n04450465 +n10646780 +n10110731 +n04142175 +n12296735 +n09337048 +n12681579 +n12819354 +n12541403 +n04305016 +n12798910 +n10321126 +n08618831 +n09721244 +n02225798 +n01637338 +n12218868 +n05545879 +n12022382 +n03972372 +n02505063 +n01694311 +n10695450 +n10081842 +n12297507 +n07592922 +n12118661 +n01952712 +n10517137 +n01340522 +n07719330 +n03729482 +n04168541 +n03090710 +n07873679 +n07828378 +n07728284 +n10343088 +n07869937 +n14585392 +n01453475 +n12095412 +n04973020 +n12810007 +n07564515 +n01599741 +n11629047 +n09937802 +n12450607 +n12460146 +n02292401 +n03632963 +n09617696 +n12545232 +n02874642 +n09934488 +n10091349 +n01447946 +n05469861 +n11830400 +n03382533 +n02608547 +n12697152 +n03542727 +n10716576 +n03664159 +n07568625 +n02976815 +n13147532 +n02336826 +n12432574 +n07686461 +n04107598 +n02505998 +n09849167 +n03688066 +n02836513 +n01576358 +n01893021 +n12017511 +n12065649 +n01714231 +n11662585 +n12827907 +n12954353 +n11936199 +n01368672 +n03843883 +n12184095 +n10058411 +n11684654 +n08506347 +n10579549 +n01423302 +n11604046 +n07613158 +n03605504 +n02090129 +n02284224 +n01958435 +n12664469 +n04459122 +n09617161 +n09780828 +n11830252 +n12870048 +n04247544 +n09871095 +n02962938 +n09933020 +n13064457 +n10341243 +n07694169 +n13200193 +n07765728 +n01524761 +n07730562 +n07751737 +n07740855 +n04192521 +n12593122 +n07841037 +n02809736 +n10604275 +n12512095 +n01907287 +n04592596 +n09823153 +n03181667 +n12449784 +n07908923 +n12365900 +n03053976 +n15060688 +n04165675 +n02530637 +n09816654 +n12540966 +n07934152 +n09290350 +n03455802 +n10111779 +n01351315 +n10281770 +n13862552 +n12435486 +n12370174 +n12296045 +n03493219 +n12363301 +n11973749 +n03939565 +n02938321 +n13209270 +n12604639 +n12657755 +n03604536 +n10328941 +n04278932 +n10376890 +n01884203 +n02061853 +n04256318 +n07831821 +n10585217 +n07591813 +n10210648 +n07739035 +n01632308 +n10319313 +n02861777 +n03821145 +n13029610 +n04239900 +n10313441 +n04951716 +n10628097 +n02368116 +n08571275 +n04433377 +n10458596 +n12435965 +n12448136 +n12129986 +n04295777 +n07898895 +n07854266 +n12327846 +n12318782 +n07825850 +n10414239 +n11731157 +n04409911 +n10655442 +n11829205 +n01738306 +n02840515 +n04150371 +n03369512 +n02645538 +n12773917 +n07818422 +n03227010 +n10303037 +n12942025 +n12406304 +n06616216 +n02435216 +n12981954 +n03683341 +n09703809 +n07722666 +n11817160 +n10110893 +n10228468 +n03572631 +n01378545 +n02130086 +n04388574 +n11960673 +n12956922 +n11924014 +n09895902 +n03426462 +n07759576 +n02563949 +n03466947 +n02522637 +n09480959 +n02033882 +n02451415 +n12677120 +n10580437 +n04425977 +n03057841 +n12285512 +n07614348 +n03144873 +n03391613 +n12366870 +n02304657 +n07863935 +n07909714 +n02413717 +n12591702 +n07838659 +n02967407 +n12016914 +n02735268 +n09470027 +n10222259 +n03899100 +n10513509 +n11620016 +n12600267 +n04368840 +n03016209 +n04085017 +n03215076 +n10238272 +n09782855 +n07586179 +n12434483 +n12452480 +n01990516 +n12030092 +n11739978 +n12714254 +n13036804 +n07727377 +n07879560 +n03710421 +n12128490 +n11968519 +n03250588 +n10173579 +n03114041 +n02942015 +n12729164 +n07871065 +n02591330 +n09353815 +n10138472 +n02712545 +n12866333 +n07835823 +n03508485 +n01758895 +n02925385 +n03321419 +n09931418 +n02846874 +n12500518 +n07587819 +n03160186 +n04974340 +n13067532 +n11940349 +n13027879 +n02878534 +n10055566 +n07925708 +n12628356 +n11958499 +n03472672 +n04233295 +n04563020 +n03426871 +n04330109 +n03677682 +n04129766 +n02884859 +n12692521 +n10188856 +n03500971 +n10355306 +n12407545 +n11955040 +n10028541 +n10345659 +n14720833 +n09641578 +n12613706 +n11718296 +n03380301 +n01334217 +n03890358 +n03583419 +n12447121 +n09660010 +n11826569 +n11837351 +n12096089 +n03871860 +n01821554 +n12834938 +n02738449 +n02644665 +n03316873 +n12548564 +n03605417 +n12094401 +n13152339 +n03004531 +n03080904 +n03535647 +n12349315 +n04213264 +n07860208 +n01526766 +n03710937 +n11806521 +n10618234 +n12306938 +n10473562 +n10050880 +n04596116 +n02577164 +n04479694 +n07936093 +n07834286 +n12175181 +n03986857 +n02919648 +n12055073 +n04567593 +n07585015 +n12771085 +n10551576 +n09778783 +n01593282 +n02406952 +n12331263 +n10629329 +n12287195 +n07729225 +n07828041 +n01880473 +n12257725 +n02696246 +n07853232 +n11936864 +n09745229 +n03364156 +n04503155 +n03194297 +n04003359 +n07607361 +n10106387 +n10306890 +n10455619 +n01647180 +n07740115 +n12106323 +n03626272 +n11685621 +n11866706 +n04321121 +n01606978 +n12621619 +n11615259 +n07840304 +n02841847 +n05459769 +n03432360 +n04604276 +n12356395 +n12468545 +n03645168 +n00477827 +n03459591 +n04202142 +n12959074 +n07881625 +n12382233 +n02405692 +n12299640 +n12247202 +n12628705 +n12534625 +n09264803 +n12176953 +n09835017 +n10390807 +n04975739 +n12474418 +n11931135 +n07917791 +n10636488 +n09690496 +n11993675 +n03703203 +n11794139 +n13015688 +n04168084 +n01948446 +n10169419 +n04455048 +n04973669 +n12840502 +n12120578 +n10448455 +n01386007 +n02288122 +n01441910 +n02278463 +n03108759 +n02753710 +n03143400 +n13080866 +n13917785 +n13124358 +n13220663 +n02475358 +n01925916 +n02684649 +n10451590 +n03869976 +n03881305 +n07928264 +n01422185 +n04035634 +n11996677 +n04261369 +n12925583 +n12764008 +n09972587 +n03708962 +n01791388 +n02892626 +n04098399 +n07823369 +n07752874 +n13225244 +n03376771 +n01771766 +n13146403 +n12157179 +n13897198 +n07770869 +n13240362 +n07610502 +n03688504 +n02896856 +n12543186 +n09967063 +n05453412 +n12590600 +n02378870 +n07568241 +n01687290 +n00474769 +n11694866 +n02338722 +n02637977 +n04567746 +n10586444 +n11907405 +n03421960 +n07605693 +n10384214 +n12877637 +n12018363 +n10056611 +n13882487 +n12140759 +n04114301 +n11762018 +n12678794 +n11817501 +n02116450 +n12018530 +n03324629 +n12726528 +n03155502 +n10493199 +n04181083 +n10609198 +n04328703 +n03045074 +n07769886 +n01892385 +n12828520 +n03165211 +n11800565 +n07567139 +n13877547 +n12829582 +n02949084 +n07589724 +n01746191 +n12395463 +n05459457 +n10565502 +n11981475 +n09310616 +n12327022 +n02313709 +n12957803 +n11865276 +n12955414 +n12939479 +n13225365 +n07936459 +n03139089 +n07577772 +n12057895 +n03620353 +n12152031 +n01885158 +n04096733 +n12626674 +n10464711 +n10675609 +n07752782 +n03709960 +n02540983 +n02285179 +n01903234 +n07835701 +n04421083 +n02352290 +n09421031 +n03349367 +n02539894 +n04052235 +n07922955 +n03941887 +n04234260 +n04423552 +n11975254 +n08501887 +n12489676 +n04574348 +n10602119 +n02163008 +n02748491 +n10024937 +n10033888 +n12605683 +n01790398 +n10128519 +n14977188 +n10293590 +n12077244 +n09741074 +n11694469 +n12692714 +n12159804 +n12533437 +n03831203 +n03692004 +n09462600 +n04537436 +n06618653 +n07913537 +n12783316 +n10038119 +n10236521 +n01486540 +n07875267 +n04345787 +n07681355 +n13028937 +n03607186 +n07863107 +n12387103 +n09830926 +n03574416 +n04478383 +n11685091 +n03197446 +n03225458 +n09741722 +n07736527 +n02857907 +n10177150 +n12711398 +n10308275 +n02418770 +n02577662 +n09935107 +n03362639 +n12446908 +n04329681 +n04114428 +n09624899 +n12913144 +n12338034 +n02341616 +n12360817 +n12907857 +n02414904 +n05482922 +n11974888 +n04127117 +n12581110 +n04368365 +n01699254 +n12525753 +n04254450 +n11951052 +n12458874 +n12721477 +n07562651 +n02239192 +n10533874 +n12006306 +n09537660 +n10008123 +n02788386 +n03248835 +n04491312 +n11795580 +n04025633 +n10166189 +n07703889 +n11824747 +n07605198 +n12134836 +n03591116 +n02946753 +n13212025 +n11742310 +n02328820 +n02985606 +n09955944 +n12679432 +n10020366 +n12013035 +n02942147 +n04172512 +n11802410 +n10789709 +n03385295 +n02039497 +n01416213 +n11940750 +n12178780 +n01967963 +n12662379 +n12217851 +n02812631 +n12432069 +n09991740 +n03089477 +n12458713 +n03876111 +n10311661 +n12286068 +n02838958 +n11936369 +n03716228 +n13228017 +n06276902 +n12677331 +n04330189 +n10488016 +n12011370 +n04343740 +n07893792 +n02171164 +n03963483 +n12080588 +n07577657 +n12936155 +n03809686 +n04223066 +n04086066 +n12776558 +n07813579 +n01841943 +n12285705 +n02581482 +n11653570 +n10010632 +n04305947 +n12228886 +n12797368 +n01404495 +n09697986 +n11882237 +n10077879 +n07607832 +n09779461 +n13212379 +n10769188 +n10715789 +n01480106 +n02145910 +n04275093 +n01983829 +n01978010 +n09937903 +n11976314 +n11785276 +n12386945 +n04445782 +n10712374 +n10706812 +n10194775 +n12655062 +n10739135 +n02597972 +n02307176 +n04121342 +n02350670 +n12698027 +n02805845 +n02895008 +n13149970 +n03451365 +n04542595 +n07803895 +n07864198 +n09690864 +n03844550 +n12378249 +n10345422 +n13163553 +n10457903 +n10783539 +n10539015 +n11757017 +n10274173 +n08652376 +n10283546 +n04541777 +n02824152 +n12945177 +n02082056 +n03695957 +n07936015 +n07591162 +n03628071 +n02990758 +n07685118 +n04023422 +n04951875 +n03541393 +n10289176 +n04039209 +n07913180 +n07910799 +n12017853 +n03732543 +n10656120 +n10512859 +n04556664 +n12464649 +n12927758 +n12078451 +n07878145 +n10561320 +n12467592 +n07689217 +n07619881 +n11935187 +n09837720 +n03642144 +n12220019 +n02983507 +n03271260 +n02778588 +n10193650 +n01654083 +n02746978 +n10202763 +n02953552 +n07924366 +n08583554 +n02905886 +n07855603 +n09745834 +n12366053 +n04140539 +n03383211 +n11648268 +n03352961 +n12116734 +n07771539 +n07836077 +n03842754 +n11683838 +n03004409 +n11730750 +n13098962 +n12292463 +n02867592 +n01653026 +n07583865 +n12548804 +n12702124 +n03917048 +n12677841 +n12511488 +n04217387 +n12495670 +n03554375 +n12403513 +n08558770 +n02781764 +n12339526 +n12742290 +n01404365 +n03591798 +n12446737 +n10494195 +n12110352 +n01672611 +n10493922 +n03638623 +n09910840 +n02238594 +n02575325 +n13186546 +n11873182 +n10344774 +n04094060 +n10417682 +n02749169 +n02428089 +n04549721 +n03824284 +n12107002 +n12784371 +n09986904 +n01634227 +n07826544 +n12253487 +n01679005 +n12516165 +n09339810 +n03126090 +n07803408 +n11883945 +n03842276 +n03397412 +n03280216 +n12264786 +n02545841 +n11877860 +n01830479 +n13207923 +n12490490 +n02542958 +n04114719 +n12590715 +n13226320 +n11644872 +n04119630 +n10176913 +n04213105 +n11652966 +n12546420 +n12625823 +n11897466 +n02092173 +n10567613 +n04953678 +n10059067 +n12408466 +n03056288 +n13036116 +n04169597 +n12467197 +n02569905 +n02758490 +n12623211 +n04077889 +n04959061 +n04183957 +n11689815 +n03777126 +n03306869 +n07720084 +n02659478 +n12947756 +n04341288 +n04448185 +n04037076 +n09828988 +n03346289 +n04174705 +n13126050 +n04255346 +n09764732 +n11773628 +n14891255 +n04314107 +n02184720 +n02646892 +n04320598 +n01979526 +n03191451 +n03662452 +n10290422 +n01739094 +n02305636 +n04202282 +n05459101 +n02766168 +n09994808 +n03528100 +n10475940 +n03005619 +n12639168 +n02144936 +n13202125 +n10703221 +n03770834 +n12324056 +n03474167 +n02609302 +n12166929 +n12852570 +n12920719 +n12508762 +n11983375 +n01422450 +n12616630 +n09681107 +n10486561 +n13038577 +n12266644 +n02478875 +n02547014 +n02249809 +n03336742 +n12038760 +n01672432 +n09861287 +n03678879 +n01949973 +n09928845 +n02310149 +n12648693 +n10533983 +n12812801 +n04550676 +n01800633 +n12128306 +n12744142 +n13140367 +n07803213 +n07688265 +n13068434 +n02030568 +n12955840 +n01625121 +n13215258 +n04270576 +n02680638 +n02817251 +n01539272 +n04066023 +n12969927 +n10280598 +n04001661 +n09774167 +n10358575 +n01836673 +n02290664 +n09940725 +n12447581 +n07803779 +n04561965 +n10151261 +n01538362 +n10170060 +n13160365 +n09823287 +n12554729 +n10620212 +n11935027 +n03465605 +n03227856 +n08519299 +n07785487 +n03522863 +n02861286 +n12200905 +n04269502 +n02104184 +n07612273 +n01390763 +n11872658 +n12981086 +n10244359 +n01738731 +n12117235 +n12846690 +n02861658 +n08782627 +n09832633 +n02531114 +n01394492 +n03269073 +n03077442 +n09794668 +n13884384 +n08659331 +n02556373 +n02587877 +n03523506 +n03723153 +n12024805 +n13061172 +n03978575 +n07914686 +n13134844 +n12183026 +n03573574 +n03765128 +n03319167 +n01920438 +n07852452 +n07680655 +n03017698 +n12959538 +n04261506 +n01793340 +n03292362 +n12817855 +n03593222 +n01962506 +n12453018 +n04027367 +n12518481 +n09223487 +n07871335 +n03779246 +n09668562 +n01889849 +n02492356 +n07830841 +n03277149 +n09968652 +n03092476 +n10400205 +n06263202 +n07595368 +n12767208 +n02196896 +n12580012 +n10265801 +n02103181 +n02922461 +n01731277 +n12422559 +n04278605 +n02250280 +n03283413 +n11829922 +n10191613 +n02493224 +n04427559 +n12181352 +n12742878 +n10683675 +n04503705 +n03785142 +n12816942 +n10723230 +n11936707 +n12360534 +n12909759 +n03766218 +n02696843 +n11935877 +n07828156 +n10617397 +n12921499 +n13158714 +n10166394 +n12370549 +n03505015 +n12769065 +n02636550 +n10781236 +n09869317 +n10275249 +n04234763 +n10735173 +n13137225 +n02070776 +n04232312 +n07575226 +n03471030 +n07909954 +n02633677 +n01662060 +n07563642 +n04263950 +n11824344 +n13178707 +n02972714 +n10417288 +n12092930 +n11993203 +n10170681 +n03726116 +n03215337 +n12564613 +n14975598 +n07758125 +n03123666 +n07717714 +n01421333 +n02359667 +n09403086 +n03857026 +n12759668 +n02628259 +n02307515 +n12146488 +n09777870 +n07819303 +n12105353 +n10784113 +n11802995 +n12561594 +n02845130 +n12100187 +n03507658 +n02141611 +n01800195 +n03470005 +n12444898 +n02203592 +n09707061 +n00475142 +n12216628 +n01732093 +n02581642 +n03803780 +n12114590 +n04541662 +n12267133 +n11652753 +n07859951 +n04524594 +n12843144 +n04040540 +n10604880 +n12559044 +n03063834 +n12394328 +n12704513 +n10230216 +n10756641 +n02101670 +n12309630 +n03070587 +n11626010 +n04239639 +n01638329 +n01928517 +n13144084 +n10420649 +n03102516 +n12395289 +n09833111 +n01651285 +n11688069 +n12881913 +n12783730 +n07716649 +n03618678 +n10344203 +n03626502 +n10718665 +n03577474 +n01683201 +n03246653 +n12153224 +n02519472 +n02470709 +n15090238 +n03129636 +n07774295 +n04577567 +n09995829 +n09662038 +n10297367 +n03555862 +n12531727 +n09947127 +n12533190 +n04062807 +n00479734 +n12860978 +n01884104 +n09866559 +n12069009 +n04595501 +n12088495 +n02909053 +n12283790 +n02180427 +n10697282 +n07562881 +n13092078 +n11706325 +n01746952 +n01978136 +n07731436 +n02386746 +n12648424 +n12726357 +n10314182 +n07839172 +n11753562 +n12903503 +n12589687 +n02375438 +n03604763 +n11549895 +n13202602 +n12304420 +n10738215 +n12220829 +n10095420 +n12177455 +n11887476 +n04006411 +n09838370 +n02853218 +n12688372 +n03335461 +n02800940 +n03036701 +n09885059 +n10206629 +n11922926 +n01678657 +n12192132 +n12248141 +n03108624 +n01936671 +n02417242 +n03222857 +n03768823 +n04343511 +n03538817 +n12655726 +n12521186 +n01330497 +n12767423 +n12965951 +n09695132 +n04410886 +n12599874 +n07865700 +n07596160 +n10227698 +n03224490 +n11598886 +n02948293 +n09906293 +n12247963 +n03301175 +n03895170 +n04259468 +n07808806 +n13147689 +n09856827 +n13882639 +n02241008 +n03842585 +n02883101 +n12182276 +n13918717 +n12728164 +n10634464 +n02477187 +n03107716 +n02342250 +n01479213 +n12793695 +n09808080 +n10707707 +n04161010 +n02836607 +n10076483 +n07726386 +n03872273 +n10250712 +n07688412 +n13884930 +n12301766 +n10196404 +n07591330 +n03814727 +n09610255 +n12757115 +n09814381 +n02397987 +n07886317 +n03959123 +n02185167 +n03533845 +n11838413 +n10227393 +n07704305 +n03580615 +n02663485 +n10101981 +n04346855 +n10067011 +n04464125 +n02829510 +n10007995 +n07845775 +n03004713 +n02450561 +n09905530 +n10361060 +n12394638 +n12095934 +n10479135 +n03145277 +n12246773 +n13194212 +n04475900 +n03252787 +n14867545 +n10485298 +n09961739 +n02149653 +n01553762 +n03931980 +n02344408 +n11676850 +n04034367 +n04235646 +n12867184 +n12625670 +n12763529 +n07593107 +n04351550 +n02571810 +n13899735 +n03652826 +n09495962 +n03421768 +n04205062 +n11918808 +n07745197 +n07752264 +n01892744 +n04609811 +n10278456 +n11790936 +n09754152 +n13234519 +n09820044 +n00440643 +n02350357 +n03779884 +n07803992 +n03305953 +n01836087 +n10068234 +n10690421 +n03134394 +n12380761 +n12801966 +n03134232 +n02596720 +n07591236 +n11882821 +n02312175 +n02387983 +n01912152 +n10805501 +n12718074 +n03188290 +n02776505 +n10528148 +n09971385 +n10524223 +n09958292 +n02721813 +n10300829 +n12007766 +n12107191 +n04449700 +n02987950 +n11878633 +n12328801 +n04551833 +n10567722 +n11654984 +n02808968 +n12066451 +n02964075 +n11633284 +n02434712 +n03070854 +n07926540 +n01543936 +n10091861 +n09938080 +n11976511 +n03342432 +n12886831 +n12509993 +n12958261 +n12730776 +n10066206 +n07846014 +n13176714 +n03332591 +n04607640 +n02513727 +n12138248 +n11964848 +n01318053 +n10553140 +n07839055 +n02632039 +n11865429 +n02286654 +n02367812 +n12093885 +n10774329 +n02296912 +n01729672 +n10353928 +n12033504 +n11936113 +n03263338 +n07822053 +n09737050 +n13875884 +n13212559 +n11690088 +n05468739 +n09344724 +n02507148 +n01377694 +n04172607 +n10464870 +n07804152 +n02825872 +n03139640 +n11858703 +n10227490 +n12334153 +n03616225 +n12018188 +n12399656 +n10235269 +n11840764 +n01995514 +n03326475 +n12704041 +n10684827 +n03006788 +n13906484 +n02868240 +n03614887 +n03491724 +n12124172 +n03675907 +n13170840 +n03983712 +n03254737 +n07836269 +n01784293 +n02095212 +n12470512 +n12219668 +n12920521 +n04492157 +n02950018 +n01922717 +n11797981 +n12601805 +n02744961 +n07814925 +n09798096 +n03939062 +n13891547 +n07564292 +n01590220 +n09295210 +n03997875 +n03479266 +n01491661 +n03781055 +n12528768 +n10657306 +n12014923 +n10094320 +n02532272 +n02224023 +n04541136 +n12067672 +n02661473 +n04233027 +n12399899 +n12889412 +n01736032 +n12551173 +n01337734 +n10104487 +n02921592 +n02148512 +n10216403 +n03276839 +n01781570 +n03999621 +n02505238 +n12537569 +n10433452 +n02351343 +n12365158 +n08539276 +n01897257 +n12221801 +n10557246 +n10437698 +n01803641 +n11836327 +n07813833 +n03468570 +n06277025 +n10040240 +n03692842 +n03017835 +n01881564 +n10487363 +n07937069 +n10597505 +n01638722 +n10160412 +n09825096 +n12611640 +n03098515 +n10654211 +n13196234 +n03436990 +n04058486 +n09814567 +n10758337 +n03515934 +n07688757 +n10269199 +n12627347 +n04521571 +n01636510 +n03220095 +n09982525 +n12768809 +n02340930 +n02473857 +n12336586 +n12125584 +n02833040 +n02498153 +n01467804 +n12120347 +n11650430 +n11953339 +n12592058 +n05102764 +n10575594 +n09722064 +n01966586 +n10619888 +n07852376 +n12650915 +n10321882 +n11974557 +n09847267 +n13201423 +n12337131 +n13185658 +n02150134 +n10538853 +n10471732 +n07836600 +n03526062 +n02512752 +n04232437 +n03367321 +n04308915 +n07600895 +n11539289 +n03539293 +n12699922 +n07817599 +n02781213 +n03594010 +n12035907 +n04075813 +n05233741 +n07863229 +n10735984 +n12095543 +n12272735 +n04229620 +n12240965 +n07768590 +n04420024 +n12111627 +n02861509 +n02595056 +n12183452 +n04607982 +n13213577 +n07741888 +n03750614 +n10043024 +n03372933 +n10051861 +n10199251 +n03249956 +n03984125 +n02956393 +n11619687 +n03356279 +n07833951 +n10715030 +n02340358 +n10768272 +n01494041 +n02592734 +n03323319 +n02136285 +n03995661 +n09945223 +n03547397 +n10044682 +n12878784 +n02803809 +n13160254 +n12726902 +n12196954 +n03161016 +n03105645 +n04218921 +n09493983 +n10719036 +n12263588 +n12565102 +n10684146 +n03148518 +n04287986 +n02340640 +n04331443 +n10727016 +n03369407 +n07824863 +n07844786 +n12467433 +n07582811 +n02964196 +n02197877 +n10758445 +n03271376 +n13212175 +n03260504 +n12777778 +n11973634 +n05467054 +n11946313 +n02462213 +n13906669 +n10520286 +n02074726 +n01771100 +n13880199 +n09811568 +n13883763 +n02334728 +n11831100 +n12025220 +n12751172 +n03858837 +n10127186 +n12831535 +n07823591 +n02513805 +n03662301 +n09913329 +n02749670 +n10655986 +n01787191 +n03199488 +n12732252 +n12253664 +n07735294 +n03440876 +n09650839 +n03844965 +n10341446 +n12688187 +n12961242 +n03423224 +n13157346 +n09802951 +n11948044 +n03489048 +n12279060 +n03664840 +n03731882 +n07742605 +n07870734 +n03949761 +n10759331 +n07739923 +n02737351 +n01788291 +n11780424 +n03722646 +n12297110 +n12363768 +n04495310 +n10008254 +n03934890 +n01318478 +n03609959 +n10070377 +n04123228 +n13068735 +n02909706 +n10671042 +n10491998 +n07650792 +n12664710 +n10213034 +n03455642 +n10411867 +n09903936 +n10121800 +n02622955 +n03647423 +n07596566 +n09654898 +n12248780 +n02684515 +n04255670 +n06273890 +n03495941 +n12960552 +n09724234 +n03861048 +n03293095 +n11835251 +n12852428 +n04084517 +n01814620 +n13159890 +n03147156 +n02311748 +n10237799 +n07584859 +n01946827 +n09651968 +n12241192 +n03669245 +n07858336 +n11932927 +n04444218 +n10526534 +n03642573 +n09470222 +n10731732 +n12001924 +n03786096 +n01359762 +n03824999 +n13877667 +n10591811 +n10574311 +n03275125 +n11631985 +n10539160 +n10502950 +n12499757 +n12432707 +n12068615 +n07689624 +n02610373 +n03204436 +n13051346 +n13134531 +n07610890 +n04021164 +n03502897 +n02299378 +n10417843 +n10050043 +n07929940 +n02593453 +n10577820 +n12870225 +n03333851 +n09463226 +n11741575 +n09193551 +n12012510 +n11987349 +n09215023 +n07924655 +n10060075 +n11999278 +n03933391 +n02602059 +n11993444 +n02337902 +n10149867 +n04441093 +n02868429 +n10629647 +n04192361 +n12029039 +n02768433 +n12078747 +n12730143 +n03255167 +n12492900 +n01709876 +n09672725 +n07870620 +n02315821 +n12277334 +n12204730 +n07852712 +n01319685 +n07802246 +n13031193 +n00812526 +n09658815 +n11982939 +n04264485 +n07893425 +n04094438 +n03285730 +n13182338 +n10724570 +n07832741 +n13210350 +n10654015 +n04058721 +n07875086 +n03462747 +n03994417 +n02889856 +n11957514 +n10109443 +n10478462 +n03064562 +n02477782 +n11920998 +n02138169 +n04227787 +n11797508 +n10753339 +n12928307 +n11921792 +n12643688 +n01833112 +n03919808 +n09817386 +n01903498 +n03848033 +n12031547 +n01035504 +n12324906 +n01911063 +n02588794 +n03749634 +n03539754 +n02242455 +n03079616 +n03246312 +n09705671 +n07860629 +n10458356 +n10051761 +n09709531 +n02867401 +n12522678 +n13150378 +n04462576 +n03462315 +n03712981 +n07607027 +n10581648 +n02957427 +n04271793 +n02253913 +n12824735 +n11697802 +n02161588 +n12463975 +n02361090 +n09784564 +n09680908 +n03512452 +n13214217 +n10712690 +n04023119 +n07814007 +n09833751 +n12885265 +n02259987 +n11933903 +n03628831 +n11967142 +n02533545 +n03900301 +n07919787 +n12793886 +n10768148 +n03071552 +n02780315 +n12193665 +n03378442 +n04486616 +n07832307 +n03164192 +n12786273 +n04261868 +n12655351 +n12320414 +n04371979 +n10630093 +n13052014 +n01357328 +n07879821 +n09753348 +n03796974 +n11701302 +n11678299 +n04022434 +n11610823 +n07726009 +n04117639 +n10474343 +n11888061 +n01842788 +n10435251 +n03343047 +n03383378 +n12750767 +n09662661 +n05241485 +n10000459 +n12220496 +n02246941 +n12676370 +n02253264 +n07766409 +n02940289 +n12089320 +n10363573 +n12922119 +n09783537 +n11695285 +n12331066 +n12573647 +n10218164 +n12509821 +n07862946 +n12818601 +n02589316 +n13191620 +n03758992 +n12112337 +n10733820 +n02898093 +n02645953 +n10150794 +n04595762 +n02344918 +n13132756 +n12859153 +n12138444 +n04211001 +n12935166 +n07830493 +n10142166 +n11951820 +n03018848 +n01453742 +n11985321 +n10000294 +n01362336 +n02328009 +n12639376 +n03090437 +n02204249 +n04312916 +n13127666 +n09684082 +n03432509 +n10274318 +n09704057 +n07593972 +n10074249 +n13157971 +n01638194 +n04036963 +n11708857 +n03418749 +n12589458 +n11899762 +n07683138 +n01601410 +n07854707 +n04279063 +n03239607 +n10302700 +n12520406 +n12576451 +n03881534 +n07565608 +n02349390 +n12569851 +n12249294 +n04059399 +n03530189 +n09357346 +n04325208 +n13159691 +n04045941 +n13898315 +n11992479 +n02353411 +n07825496 +n12922458 +n03115014 +n11761836 +n03323211 +n02793296 +n03492087 +n05241662 +n05491154 +n10419630 +n04506895 +n10546428 +n02907296 +n10769459 +n11647868 +n13188462 +n03825442 +n13209460 +n10742005 +n07599242 +n12361754 +n04570532 +n04131811 +n07756499 +n02598134 +n01910252 +n02910701 +n10129338 +n13871717 +n12673588 +n12565912 +n07562172 +n02711237 +n10775003 +n07695410 +n02637179 +n12930951 +n10261211 +n02906963 +n01366700 +n10642705 +n09846586 +n02779719 +n04978561 +n01369358 +n12114010 +n03521771 +n10667709 +n02296612 +n10722029 +n03500557 +n01365474 +n10472447 +n07585644 +n07609316 +n04013060 +n04505888 +n09726811 +n12692160 +n12378963 +n03585551 +n13139837 +n10167565 +n03799375 +n11990920 +n09640327 +n04502989 +n10108832 +n10561736 +n01897426 +n11766189 +n12462582 +n12913524 +n02684356 +n13200542 +n10466198 +n04331892 +n01478969 +n07837234 +n07692248 +n04552097 +n12382875 +n01484447 +n04120695 +n12681376 +n10293861 +n11965962 +n11788039 +n03959227 +n01832813 +n09918867 +n09942697 +n07587206 +n10459882 +n01347583 +n02267208 +n03951453 +n03006903 +n12126736 +n10286749 +n03395401 +n04605057 +n03467887 +n12755559 +n04020744 +n11629354 +n01647033 +n02780445 +n10205714 +n09439032 +n03138128 +n02763083 +n07835547 +n12251278 +n11949857 +n01635480 +n10675142 +n07845335 +n07751977 +n10332110 +n11871496 +n11764814 +n12229651 +n07760297 +n09865672 +n02919308 +n12218490 +n03782929 +n12231709 +n11909864 +n03144982 +n11799331 +n10433610 +n10483395 +n03206023 +n05442594 +n03626418 +n07870478 +n10171456 +n11964446 +n12796849 +n02126317 +n03797062 +n01412694 +n07610746 +n03581897 +n04479526 +n12447891 +n11906514 +n09699642 +n12873984 +n10586903 +n13234114 +n02436353 +n11889205 +n01460303 +n04400899 +n11884967 +n02140491 +n12215824 +n03586911 +n01394040 +n10691937 +n12371704 +n09668988 +n04362624 +n01740885 +n01337191 +n09714120 +n02185481 +n08555333 +n10704238 +n12430471 +n12034594 +n10012484 +n12088909 +n03205903 +n04129490 +n13090018 +n10712474 +n12234669 +n13016076 +n00454855 +n13882713 +n02644817 +n03192907 +n03519226 +n01561181 +n04583967 +n11732052 +n10732854 +n04480303 +n07934908 +n03825673 +n10621294 +n04354387 +n03374102 +n02922159 +n13158815 +n04000716 +n09685806 +n04427216 +n12051514 +n09712967 +n12081649 +n09748889 +n03252231 +n10704886 +n12897118 +n12525168 +n11728769 +n02731251 +n02548884 +n12403276 +n09627807 +n08679167 +n09663999 +n04247440 +n07711683 +n09909929 +n03415868 +n05244421 +n07680416 +n12757668 +n11935794 +n03483086 +n01860864 +n10755164 +n03675076 +n12004987 +n07566092 +n04078955 +n03379719 +n01916588 +n10138369 +n09755893 +n03649003 +n03977430 +n02309120 +n10616578 +n12242850 +n12388293 +n03292085 +n09919061 +n10302576 +n01497413 +n01936858 +n01377278 +n04358256 +n02667693 +n12125183 +n07758582 +n07813324 +n09737453 +n12745564 +n03855464 +n03166685 +n01446152 +n09801102 +n10561222 +n10576818 +n13915209 +n10474446 +n03845990 +n04237174 +n12531328 +n07855812 +n10763245 +n04614505 +n07905770 +n12051792 +n12653633 +n03593862 +n10359659 +n10436334 +n07853125 +n12911264 +n12265083 +n03638014 +n04444121 +n02706221 +n10563711 +n07808166 +n11799732 +n04093915 +n10451858 +n04410760 +n10075299 +n12740967 +n12635359 +n09611722 +n12902466 +n13915305 +n05542893 +n04440597 +n03675445 +n12315245 +n10646032 +n10047199 +n12775717 +n10365514 +n10590452 +n11616260 +n02812342 +n07856756 +n04570416 +n03565991 +n12215210 +n04330896 +n02388588 +n02266269 +n10760199 +n14714645 +n02742070 +n03565710 +n12609379 +n03420935 +n03441465 +n00453631 +n01963479 +n04362972 +n09863936 +n03961394 +n03009269 +n12297280 +n04561010 +n12192877 +n02981565 +n12134695 +n07855413 +n03232815 +n10180791 +n09932788 +n10571907 +n02109256 +n02660091 +n07865788 +n13228536 +n10306279 +n02635580 +n03634899 +n10262343 +n12296929 +n04393301 +n06281175 +n04485586 +n13103660 +n10510974 +n04166436 +n01634522 +n07596362 +n12700357 +n08597579 +n11744011 +n12238756 +n01790171 +n04571800 +n11867311 +n03464467 +n12241880 +n09961605 +n12592544 +n03170459 +n09938991 +n02692680 +n10295371 +n04331765 +n02612167 +n02520810 +n11977887 +n04094608 +n07722390 +n07832202 +n12448361 +n04612159 +n12186352 +n13161151 +n12654227 +n09868899 +n10104756 +n09920106 +n12981301 +n02610980 +n12545865 +n10673296 +n04110841 +n01704626 +n04055700 +n12117912 +n10519126 +n12443736 +n01697978 +n02148088 +n03012644 +n12091697 +n10395390 +n10509810 +n10462751 +n02896949 +n03836602 +n03928994 +n07718195 +n02473983 +n08571642 +n02648916 +n11970298 +n06274292 +n04613158 +n09856401 +n12811713 +n13111340 +n12122442 +n10095265 +n04445610 +n11631619 +n07863644 +n12022821 +n10315217 +n12549799 +n03386343 +n03121040 +n03558007 +n12272432 +n11798496 +n02522866 +n02952935 +n10741493 +n12143065 +n07883156 +n09616573 +n02289988 +n13161904 +n02588945 +n00451768 +n12375769 +n10777299 +n04495183 +n11930994 +n09970088 +n02254246 +n12276314 +n07857598 +n04428382 +n03789794 +n03383821 +n12980080 +n01447139 +n12880799 +n03501520 +n10764465 +n13143285 +n12727729 +n12444095 +n02354621 +n13174354 +n01691652 +n07732525 +n10437014 +n04368235 +n10371052 +n02611898 +n03597147 +n09912431 +n03135788 +n07888058 +n02409202 +n14582716 +n11934463 +n04395332 +n12558680 +n05257967 +n11798978 +n10617024 +n04102760 +n12132092 +n12988572 +n10390698 +n11887310 +n12063211 +n12952717 +n13141972 +n12176453 +n10245863 +n10509161 +n10389976 +n10333165 +n01474864 +n09274305 +n11888424 +n10368711 +n13222877 +n10469611 +n07582970 +n09700125 +n12805762 +n07865575 +n07853852 +n03628421 +n04482975 +n03099622 +n01349735 +n11943133 +n12736603 +n12197601 +n10597745 +n04418644 +n12689305 +n07755262 +n10598459 +n04312020 +n03195485 +n09776642 +n10596517 +n10223606 +n01923890 +n12703716 +n03465040 +n12372233 +n12528109 +n03571853 +n10802621 +n10204177 +n02320465 +n03976105 +n02214096 +n02148991 +n10377542 +n10697135 +n03538542 +n07582027 +n04517999 +n12180456 +n02838014 +n03977266 +n03818001 +n12191240 +n11648776 +n10773800 +n04475496 +n03945817 +n04682018 +n02994743 +n02787269 +n11650160 +n03834472 +n03389983 +n09797742 +n06209940 +n12525513 +n12672289 +n01893164 +n10710259 +n01892145 +n11773408 +n10554024 +n09864968 +n10699752 +n11631405 +n10414768 +n04430605 +n10742546 +n10738871 +n12857204 +n09309046 +n01724840 +n04123317 +n07881525 +n03868044 +n02140268 +n10708292 +n09838295 +n09797998 +n10710171 +n11814996 +n11938556 +n03543511 +n02151230 +n01515217 +n03533392 +n02039780 +n12810151 +n02335231 +n12152251 +n13225617 +n09801275 +n01978587 +n14821852 +n11742878 +n12679023 +n03521431 +n09679028 +n02021281 +n10784544 +n04421258 +n12492460 +n03720005 +n02541257 +n03889397 +n02888898 +n10659762 +n12045157 +n12712320 +n10369095 +n09721444 +n12769318 +n01703161 +n12697514 +n07836456 +n03905361 +n10660883 +n07769306 +n11893916 +n07846274 +n04110281 +n03655470 +n07740744 +n01363719 +n12540647 +n09896311 +n12842642 +n07755619 +n07754155 +n11548870 +n02868546 +n04215588 +n04288165 +n13201566 +n07721118 +n12018271 +n11903333 +n02909165 +n02662559 +n11658709 +n13063514 +n07725663 +n10179069 +n10776887 +n12637485 +n03814528 +n12542043 +n07833333 +n07820036 +n02746683 +n07925808 +n10349750 +n03154316 +n04155625 +n03232923 +n02116185 +n09998788 +n02821543 +n03410303 +n10656223 +n07916582 +n12880638 +n10408809 +n04612840 +n11805255 +n12044784 +n10497534 +n03458422 +n12873341 +n07808675 +n09476123 +n07611733 +n10598013 +n02214660 +n05469664 +n03952150 +n11855435 +n04375926 +n08523340 +n01642391 +n04007415 +n09756961 +n12891824 +n02894847 +n11698245 +n12906771 +n02894024 +n04131015 +n11882636 +n04386456 +n03291551 +n07837110 +n12462221 +n08540532 +n10299875 +n12705978 +n10448322 +n10487592 +n12175598 +n02272552 +n03833907 +n10383237 +n12758176 +n12729950 +n10061195 +n07816726 +n03241903 +n12239880 +n10380499 +n07855188 +n10207077 +n02770078 +n12961393 +n03778459 +n10734741 +n03485575 +n09958447 +n12337246 +n11830045 +n09866354 +n03209666 +n01470145 +n10395209 +n03872016 +n04267091 +n12888457 +n12104104 +n04088229 +n01964957 +n12002651 +n02503756 +n00481938 +n01908042 +n03378765 +n04193883 +n09862183 +n11861487 +n02520525 +n02081060 +n10386754 +n12693865 +n04514095 +n01325060 +n02460817 +n07568095 +n03651605 +n02561937 +n12844409 +n12888016 +n02974565 +n12439154 +n13018906 +n12071259 +n03897634 +n02863176 +n10603528 +n03493911 +n12887532 +n12944095 +n12794568 +n09980458 +n03503567 +n11783162 +n13123309 +n11729860 +n03702582 +n04280373 +n10086744 +n01790557 +n12627526 +n10552393 +n12092629 +n03888998 +n12751675 +n01442450 +n02479332 +n07726230 +n03642341 +n03142325 +n06263895 +n12088327 +n09703344 +n10528493 +n02820085 +n07737594 +n04090781 +n09901642 +n02328942 +n02724722 +n09866115 +n12658715 +n10481167 +n13135692 +n11850918 +n10205344 +n12361560 +n03698123 +n03284482 +n12106134 +n04441528 +n02591613 +n02581108 +n07856186 +n12197359 +n12900783 +n01725713 +n12012253 +n03907475 +n02170738 +n03694949 +n13238654 +n04611795 +n02782432 +n13191148 +n02741367 +n04170694 +n12770892 +n01973148 +n10080508 +n10161622 +n09808591 +n07912093 +n02059541 +n02779971 +n03857156 +n12945366 +n03055159 +n12758325 +n10067305 +n02597818 +n07808352 +n13147153 +n10679723 +n02271222 +n04012665 +n12942729 +n10349243 +n01377510 +n07800636 +n10654321 +n10219453 +n09961469 +n10732521 +n04479405 +n11632929 +n03856728 +n08658918 +n10327143 +n10754281 +n02085118 +n09691604 +n09952163 +n10082299 +n03872167 +n03733465 +n04138869 +n01425223 +n12066821 +n02177506 +n09892262 +n02896694 +n12983654 +n13224922 +n09658921 +n12744850 +n03639880 +n02943686 +n10660621 +n11936539 +n03698226 +n04519536 +n12392765 +n09319604 +n07567039 +n04160261 +n01802159 +n02838178 +n07746910 +n02266421 +n10240417 +n12542240 +n12550408 +n01445857 +n04132465 +n03569014 +n12666050 +n12362514 +n10676569 +n09702673 +n12885510 +n04447156 +n04396226 +n12240150 +n11639306 +n02249134 +n01340785 +n02833140 +n10027590 +n02142407 +n11996251 +n07874531 +n04340019 +n03166120 +n10420277 +n04465203 +n12738259 +n12831141 +n03998673 +n01385017 +n12842519 +n02587051 +n10753061 +n12505253 +n13906936 +n01989516 +n12640435 +n07852532 +n04243142 +n10261511 +n12853287 +n12239240 +n03973003 +n09983889 +n10345302 +n14804958 +n02354162 +n03049326 +n10443659 +n01318660 +n12787364 +n04253304 +n11941094 +n09283514 +n09393524 +n11865574 +n01531639 +n04409279 +n02859729 +n10712835 +n03694196 +n04343630 +n10331098 +n12929600 +n02826259 +n10171219 +n07735179 +n07594840 +n03709644 +n09950728 +n09859285 +n07718329 +n01418620 +n09858299 +n12395068 +n10011360 +n07763290 +n02643316 +n03596099 +n04422566 +n11958888 +n09650989 +n10318686 +n01333082 +n12886402 +n03781467 +n12667582 +n02923535 +n09988311 +n08663860 +n02508346 +n13885011 +n03939281 +n10772937 +n04485750 +n09871952 +n10291942 +n07759324 +n10174971 +n03666238 +n01937579 +n02308033 +n07847706 +n10371330 +n04124887 +n11853079 +n11941478 +n12647231 +n04601041 +n12718483 +n02902816 +n01941340 +n04066767 +n07617839 +n02254901 +n03488784 +n07834774 +n02524659 +n03367969 +n10783734 +n03422484 +n09776807 +n03970363 +n10131590 +n03433247 +n02622712 +n10206506 +n12061104 +n11936287 +n07874674 +n10061043 +n07828275 +n03764606 +n12236768 +n01826844 +n09741904 +n05454978 +n03591592 +n01441272 +n03736372 +n07585474 +n12762405 +n12943912 +n01894522 +n03218446 +n11846425 +n11689678 +n04147916 +n02375862 +n10409459 +n09287415 +n10113583 +n03261263 +n02817386 +n09869578 +n10550252 +n02532786 +n12031388 +n07937344 +n11612235 +n01571410 +n09402944 +n04234670 +n02603862 +n04196925 +n09999135 +n10468750 +n15093049 +n03003633 +n11650307 +n12312110 +n02525703 +n10501635 +n09751622 +n10114550 +n10103155 +n12829975 +n04004099 +n12419878 +n02082190 +n03328201 +n03093427 +n07845571 +n12655498 +n02558206 +n12563045 +n07573453 +n12324558 +n13016289 +n10601234 +n10310783 +n03531691 +n02135610 +n03168543 +n09985978 +n10615334 +n07839312 +n09985809 +n10142537 +n10417969 +n07869111 +n12514992 +n04327544 +n10326776 +n12583681 +n01476418 +n12840168 +n03852544 +n11713763 +n07824502 +n07858841 +n12256325 +n03036149 +n07883661 +n04500390 +n10170866 +n01835918 +n10760951 +n10720197 +n12330239 +n02135844 +n10210512 +n03217739 +n10802953 +n03136254 +n02161225 +n03961630 +n12927194 +n02251233 +n13891937 +n09945603 +n02695762 +n12181612 +n13234857 +n10175725 +n11346873 +n07934678 +n02318687 +n10251329 +n04112921 +n04001132 +n03042984 +n11704791 +n04246459 +n12193334 +n10718509 +n10371221 +n05278922 +n03265754 +n12186554 +n12481289 +n10521853 +n10748506 +n11729142 +n10143595 +n09422631 +n07562984 +n07850219 +n04193742 +n11997160 +n12002826 +n12820113 +n04132829 +n10272913 +n03358841 +n12610740 +n12384569 +n10725280 +n02746008 +n13148384 +n12635151 +n02337171 +n10350774 +n12308907 +n04542474 +n04339062 +n03549350 +n10240235 +n10556033 +n10214390 +n01791314 +n02801047 +n07817465 +n11610602 +n10315730 +n14592309 +n10249191 +n12453857 +n12579822 +n09833275 +n04051269 +n11552594 +n04088343 +n04565039 +n03930431 +n10679503 +n11899921 +n10295479 +n01357507 +n13036312 +n03404900 +n12523141 +n01816017 +n02020578 +n12661045 +n06262943 +n02775813 +n12921315 +n09751076 +n09834258 +n10585628 +n12885754 +n04411019 +n10342367 +n10368798 +n09672840 +n12729023 +n04578329 +n10325549 +n03680248 +n11920663 +n10416567 +n10011486 +n01643255 +n03193754 +n07823814 +n04055447 +n10660128 +n07765612 +n07612530 +n04205613 +n09677427 +n03989199 +n11100798 +n12721122 +n10000787 +n10382157 +n07724819 +n12928819 +n11631159 +n02608996 +n10516527 +n09703101 +n12290975 +n03470222 +n03810412 +n03729131 +n03356038 +n12692024 +n12614625 +n10789415 +n02333819 +n01722670 +n03885410 +n12038208 +n02294097 +n02608860 +n02500596 +n07909231 +n03254625 +n09681973 +n12221368 +n01893399 +n10025295 +n03194812 +n13181406 +n12249122 +n03447894 +n09795010 +n02187900 +n10139651 +n10631654 +n01792530 +n02569631 +n07853946 +n09907804 +n03263758 +n04214649 +n02450829 +n02431542 +n11998492 +n02651060 +n04101860 +n01806061 +n13901423 +n12903964 +n03968479 +n04268565 +n12601494 +n02083780 +n04570118 +n12247407 +n03337822 +n09878921 +n02369935 +n10022908 +n09667358 +n13160938 +n11937360 +n07741623 +n03705808 +n12241426 +n10478118 +n03805933 +n10343869 +n09391774 +n03482128 +n10357737 +n10334461 +n09675045 +n09662951 +n10174253 +n01815270 +n13873361 +n04432785 +n09778927 +n10671898 +n05571341 +n10033572 +n09864632 +n10618465 +n03437184 +n12786464 +n01723579 +n11798270 +n07742415 +n02143142 +n10548419 +n03695122 +n02518622 +n04605446 +n10218292 +n11832671 +n12646950 +n03382708 +n09844898 +n09674786 +n01472502 +n07616906 +n09763272 +n03982767 +n10005006 +n03059236 +n01816474 +n03725869 +n01979269 +n04226322 +n13236100 +n03920384 +n11852148 +n04373563 +n04324120 +n11686652 +n03036341 +n02142898 +n09783776 +n13147918 +n03465320 +n07855721 +n10336411 +n10438619 +n07750299 +n12237152 +n03559373 +n10077106 +n10169796 +n09828403 +n09959658 +n12464128 +n12934685 +n04221673 +n02617537 +n11689367 +n10180580 +n07813717 +n12529905 +n02340186 +n01400247 +n11749112 +n04404072 +n03135656 +n12098827 +n12481150 +n10023506 +n03500838 +n01564101 +n04009923 +n10023264 +n03908456 +n03206405 +n07590068 +n09958133 +n10755394 +n01423617 +n11511327 +n10536274 +n01965252 +n11549245 +n11935627 +n09635635 +n03752071 +n07585997 +n03147084 +n12666159 +n09748408 +n03796848 +n01501948 +n02345078 +n12430675 +n03103128 +n11710987 +n03393199 +n09233603 +n10465002 +n04298765 +n01351170 +n02720576 +n03966582 +n10643837 +n12420124 +n10793799 +n01652297 +n09281252 +n11983606 +n10222497 +n11832899 +n02391617 +n12434106 +n03987674 +n02140179 +n07896560 +n04325804 +n10647745 +n01924800 +n10156629 +n03545961 +n03906789 +n01890564 +n10699558 +n12332218 +n03247495 +n11839460 +n03527675 +n12586725 +n13208965 +n02714315 +n02750320 +n04615149 +n12679876 +n12863234 +n03304323 +n12139793 +n11922755 +n12321669 +n04979307 +n01921059 +n09657206 +n13042134 +n04045787 +n11700279 +n02337598 +n01415920 +n01400391 +n13207572 +n10785480 +n02515713 +n12018100 +n02634545 +n03292736 +n02881546 +n12655605 +n03105810 +n10545792 +n03894933 +n09796974 +n10320484 +n12308112 +n11549009 +n13047862 +n14941787 +n12379531 +n10540252 +n11696935 +n12184468 +n12851860 +n12908854 +n10586265 +n12369066 +n10426630 +n12523850 +n03916289 +n04538878 +n09908769 +n02828115 +n07560422 +n10266016 +n03569174 +n06423496 +n10495167 +n03617834 +n09327538 +n10195056 +n10508379 +n13031323 +n11659248 +n04242315 +n10742111 +n10700963 +n12032686 +n09877587 +n07825597 +n07568991 +n11736362 +n12169099 +n13103750 +n03263640 +n12248941 +n10665302 +n01920051 +n09704283 +n11533999 +n04503073 +n11645163 +n10639817 +n09920901 +n06340977 +n03251100 +n10378113 +n03226090 +n10131268 +n02877513 +n13191884 +n02787120 +n11709045 +n02740061 +n12323665 +n02831998 +n10342180 +n12716594 +n04498275 +n09905050 +n03745487 +n07642833 +n10294020 +n10211666 +n12205460 +n02981198 +n01642943 +n07679140 +n04390483 +n10432875 +n09214269 +n10792506 +n10243483 +n13099833 +n10221520 +n13177768 +n04091584 +n10672540 +n10200246 +n13889331 +n02345340 +n10237556 +n01833415 +n01335218 +n09804230 +n09957523 +n05235879 +n10070449 +n10308653 +n10721708 +n04312654 +n10394434 +n12201938 +n12434775 +n07601025 +n02672152 +n10157271 +n02635154 +n12572858 +n13182937 +n10160188 +n03396997 +n10344656 +n02968210 +n10190516 +n07684422 +n03706939 +n07618871 +n02290870 +n03817331 +n03275311 +n12698774 +n04375080 +n07837630 +n04314216 +n11833373 +n07618684 +n03742238 +n12532886 +n03712444 +n11750989 +n10038620 +n09617577 +n03807334 +n10108089 +n01816140 +n10715347 +n02648035 +n13127303 +n02809491 +n02430748 +n12235479 +n01451863 +n01514926 +n10010864 +n01913440 +n09660240 +n11806369 +n01470479 +n12655245 +n07655067 +n03436772 +n11778092 +n03951800 +n10277815 +n07931733 +n01479820 +n03576955 +n07609549 +n12568649 +n05263316 +n02636405 +n01384084 +n03298352 +n07617344 +n09987045 +n10573957 +n07801709 +n02589062 +n02534165 +n02748359 +n09607782 +n07590974 +n02199170 +n02696569 +n09678747 +n12795209 +n13176363 +n10663315 +n10588724 +n09772330 +n10174589 +n12366313 +n11883628 +n07617447 +n01334690 +n03168663 +n11764478 +n08599174 +n03942028 +n12153033 +n03448696 +n12096674 +n10037588 +n03548320 +n09760290 +n10374541 +n09653438 +n10294139 +n10276942 +n12279293 +n12764507 +n12803958 +n10764622 +n02140858 +n07599068 +n10245507 +n12351790 +n12818004 +n10118301 +n03945459 +n09912995 +n12176709 +n03873996 +n10339179 +n10614507 +n10114662 +n10784922 +n03821424 +n04959230 +n13015509 +n12573911 +n11948469 +n09775907 +n12758014 +n01780142 +n09956578 +n12165384 +n10088200 +n10382480 +n04131113 +n09930628 +n09784160 +n11750173 +n13064111 +n03817522 +n12662074 +n03176238 +n12310021 +n11679378 +n09961331 +n02385580 +n11904274 +n03113505 +n10244913 +n02836900 +n09986700 +n11963572 +n13158605 +n10321632 +n02179891 +n02189670 +n10097995 +n10774756 +n10783240 +n10605737 +n02530052 +n10386196 +n10184505 +n09788237 +n03589672 +n12509109 +n10658304 +n12966804 +n12559518 +n03189311 +n01451295 +n12179632 +n12301613 +n10496489 +n03402785 +n10244108 +n02385676 +n03552001 +n03092053 +n02313360 +n02547733 +n02109391 +n01327909 +n04574606 +n03060728 +n07840124 +n10567848 +n10062176 +n02703124 +n10804732 +n12699301 +n04515890 +n07919665 +n10457214 +n09663248 +n03165955 +n12988341 +n03987865 +n03031756 +n10277912 +n10172080 +n09325824 +n03198223 +n09605110 +n10113869 +n11603462 +n03352366 +n11930203 +n09769929 +n12979316 +n02579762 +n09953052 +n03105974 +n00476140 +n11598287 +n02830157 +n10512201 +n09746936 +n10668666 +n02919976 +n09993651 +n02149861 +n09705003 +n10389865 +n11655152 +n10010767 +n10070563 +n03688832 +n10590239 +n11936027 +n02939763 +n03163488 +n03171910 +n09955406 +n03266195 +n10217208 +n09338013 +n07594250 +n03215930 +n09725935 +n10592049 +n03732658 +n12498457 +n09966554 +n10668450 +n10361525 +n04060198 +n11936624 +n02602760 +n03942600 +n03708425 +n10020533 +n12067817 +n07590177 +n01891274 +n11837204 +n01419332 +n03860234 +n12616248 +n07834160 +n09867154 +n09788073 +n12222493 +n03388990 +n04245412 +n10182402 +n11675404 +n10450038 +n13045594 +n13158167 +n13082568 +n12052267 +n12707199 +n07810531 +n07914887 +n13127001 +n02573249 +n08619112 +n10471859 +n09919899 +n03635516 +n12067029 +n03352232 +n07765517 +n10519984 +n02742194 +n03062798 +n13124654 +n09958569 +n02370137 +n10121714 +n04019335 +n07732433 +n02559383 +n12585137 +n09729156 +n10744078 +n09954355 +n03078506 +n10062042 +n10688811 +n02668613 +n03142205 +n10347204 +n10518349 +n09898020 +n12563702 +n05468098 +n10116370 +n07838905 +n03127024 +n03545585 +n12801072 +n09940818 +n04480995 +n10466564 +n02606751 +n10032987 +n10771066 +n01587278 +n11852531 +n01455461 +n10397392 +n02349205 +n10180923 +n09778266 +n04366832 +n10051975 +n10538629 +n09865744 +n12554029 +n13118330 +n12952590 +n04187751 +n09924313 +n10062594 +n01980655 +n10028402 +n02567334 +n10590903 +n10265891 +n10739297 +n01457082 +n03437581 +n03713151 +n03475674 +n05464534 +n11863467 +n06592421 +n12491435 +n14914945 +n10279778 +n03388711 +n10483890 +n10612373 +n03332784 +n02332954 +n02952798 +n13041943 +n01607309 +n04356772 +n07711799 +n12670962 +n12229111 +n07878479 +n12401893 +n07772413 +n12138110 +n09781504 +n07902698 +n02750652 +n13042316 +n12400924 +n02304797 +n03066464 +n12852234 +n10155222 +n05541509 +n10711483 +n04210858 +n02835551 +n12859679 +n02935490 +n03540476 +n05279953 +n09807075 +n09617435 +n03566860 +n10549510 +n10025391 +n10754449 +n11927740 +n03554645 +n01837526 +n02656969 +n08648917 +n07860548 +n01452345 +n04021704 +n07783827 +n10080117 +n02187554 +n03214966 +n10036444 +n04291069 +n12407396 +n02170599 +n09896826 +n12417836 +n07845495 +n02749292 +n03061819 +n03682380 +n10756261 +n10369955 +n09692125 +n09978442 +n04277669 +n10539278 +n09703932 +n01879837 +n02746225 +n13159357 +n11763874 +n10540656 +n07933530 +n12987535 +n02371344 +n10654827 +n09723944 +n12775393 +n11856573 +n12626878 +n12716400 +n09903639 +n09784043 +n03906894 +n10775128 +n03124313 +n10396727 +n02841641 +n10211830 +n12283395 +n03490784 +n14175579 +n04027935 +n12396091 +n02609823 +n01414216 +n09880741 +n11976933 +n03073384 +n09270160 +n11768816 +n12073217 +n11597657 +n09994878 +n11756329 +n12579404 +n03161893 +n01451115 +n07736971 +n02949356 +n03878418 +n12653436 +n10626630 +n12777892 +n13061704 +n10498699 +n03609786 +n03199358 +n10776339 +n10762480 +n13179056 +n10113249 +n04029913 +n12640081 +n10493835 +n11683216 +n03524287 +n04585626 +n02969527 +n12976554 +n08569482 +n10204833 +n12442548 +n02577952 +n09357447 +n10202225 +n02198129 +n11882972 +n10404426 +n01600341 +n12016434 +n09867069 +n10576223 +n09893600 +n01702479 +n04274686 +n04406552 +n02848118 +n02258629 +n03260733 +n03685640 +n11751974 +n09967555 +n06274546 +n09649067 +n10681557 +n07606933 +n03110202 +n11982545 +n10803031 +n02679142 +n04086937 +n10514255 +n04506402 +n03884554 +n09970192 +n10117017 +n12642435 +n10186686 +n02097967 +n03956531 +n11834890 +n02677436 +n10040698 +n11796188 +n03348142 +n04168472 +n02294407 +n12483282 +n09429630 +n04423687 +n09819477 +n09755555 +n10157016 +n03344935 +n07762373 +n12871859 +n09853541 +n09875979 +n13050705 +n02251067 +n10637483 +n03823673 +n10357012 +n03424204 +n04431648 +n01475940 +n02339282 +n10248198 +n07683265 +n13150592 +n10359117 +n10096508 +n03473078 +n13052248 +n10743356 +n03710079 +n10634990 +n04507689 +n07921090 +n02352002 +n03924407 +n03609147 +n02837567 +n03406759 +n03909658 +n10286282 +n12135576 +n01912809 +n10801561 +n10717055 +n03473465 +n03761588 +n03144156 +n09474412 +n10253611 +n12549420 +n02499568 +n09910222 +n10431122 +n12699031 +n01697749 +n11786843 +n03888808 +n12089496 +n10066314 +n10302905 +n12696830 +n09965787 +n11969806 +n04066388 +n13080306 +n03913930 +n09968259 +n10490421 +n10714195 +n07570021 +n10343449 +n10401204 +n03472796 +n10779897 +n11787190 +n03503097 +n10439523 +n12123648 +n04279858 +n10511771 +n09755788 +n08253141 +n02616397 +n12248574 +n01645466 +n04334504 +n07729142 +n05451099 +n10503818 +n10354265 +n09707735 +n02633422 +n11999656 +n01324916 +n02088745 +n09354511 +n10705448 +n09756195 +n10136615 +n10427359 +n09702134 +n12600095 +n04122262 +n10791820 +n03330002 +n02713496 +n11710658 +n09664908 +n02550203 +n02349847 +n12835766 +n04098260 +n11536567 +n11686780 +n12875861 +n12758471 +n09806944 +n11810030 +n10400003 +n10098388 +n11663263 +n10559683 +n07833672 +n10753989 +n10643095 +n01988869 +n03112240 +n12911914 +n09979913 +n09785236 +n09790047 +n02676097 +n01653509 +n04601159 +n01938735 +n10748142 +n12978076 +n11990627 +n10437262 +n12972136 +n04077594 +n10148825 +n02269340 +n12886185 +n03608504 +n11677485 +n10612518 +n12267265 +n10649308 +n05458173 +n10650162 +n03213361 +n02747063 +n01611674 +n02322992 +n01554017 +n03512624 +n12773142 +n12747120 +n09902128 +n03162714 +n03924532 +n10299125 +n12378753 +n02778131 +n09976024 +n13093629 +n10778999 +n07721833 +n12232851 +n07876775 +n10097590 +n03194170 +n13029122 +n04573832 +n12859272 +n09639382 +n07688021 +n02878796 +n10751710 +n03633632 +n07762534 +n10779995 +n13914265 +n13093275 +n10729330 +n10433077 +n03663910 +n10499110 +n02272286 +n10371450 +n01967308 +n12633061 +n11659627 +n12982915 +n10344121 +n10268629 +n02697876 +n09879552 +n10167361 +n10719807 +n04042076 +n01632952 +n03243625 +n02125872 +n10105906 +n12194613 +n03149810 +n10721124 +n03947343 +n02020219 +n10122531 +n01315330 +n08647264 +n00452734 +n03607527 +n10010243 +n09863749 +n04473275 +n11782878 +n03585337 +n09655466 +n12989007 +n11711971 +n10716864 +n10475835 +n10704712 +n01894956 +n10568443 +n12881105 +n10387836 +n10403633 +n08645318 +n03500457 +n10377633 +n10108464 +n09933972 +n02618094 +n11798688 +n04155735 +n09780395 +n12822466 +n04302200 +n11899223 +n10633298 +n02760298 +n12142450 +n10803282 +n10769321 +n10514051 +n10597889 +n11837562 +n02261757 +n01458746 +n09830759 +n10003476 +n09817174 +n10738670 +n10118743 +n12096563 +n03054491 +n12155773 +n10439727 +n04170384 +n03223923 +n12632733 +n07845421 +n10062905 +n11831521 +n04267985 +n12796385 +n04154854 +n00444142 +n09778537 +n03115663 +n04385157 +n10109826 +n02337332 +n09996304 +n09880189 +n12871696 +n11823305 +n02516776 +n12377494 +n08511017 +n04421417 +n10765305 +n09675673 +n03488111 +n03076623 +n11829672 +n10292316 +n10758949 +n13031474 +n02829353 +n10090745 +n09186592 +n12736999 +n12715195 +n11684499 +n03168933 +n09890192 +n10596899 +n12527081 +n10496393 +n10497135 +n02137302 +n03266620 +n12958615 +n12664187 +n02633977 +n04262869 +n04215800 +n13133233 +n02392555 +n09858733 +n10186350 +n01715888 +n03142099 +n08573674 +n11687071 +n02690715 +n03146342 +n12331788 +n08079613 +n10609092 +n12943049 +n12234318 +n02312325 +n12618146 +n10135197 +n11705573 +n02794368 +n02850358 +n09464486 +n01993525 +n03187153 +n10097262 +n02976641 +n12198793 +n12941717 +n10219240 +n12434634 +n03827420 +n10437137 +n10342893 +n04174026 +n10265281 +n07757874 +n10765885 +n01470895 +n02349557 +n11716698 +n03765467 +n10227793 +n07824268 +n12994892 +n10486236 +n02974454 +n10718349 +n11726145 +n09909660 +n03378593 +n07805006 +n09875025 +n02645691 +n10223069 +n03722944 +n04389999 +n02544274 +n10239928 +n04456011 +n10382302 +n01552333 +n10082562 +n12952469 +n09883047 +n10442573 +n01891013 +n10690268 +n13111504 +n02287352 +n03567635 +n10331347 +n09762385 +n09933842 +n02369555 +n12291459 +n09919200 +n01492860 +n02067768 +n10713254 +n10550468 +n12846335 +n03835729 +n12467018 +n11676743 +n03629643 +n12987423 +n10655730 +n08678783 +n10349836 +n10087736 +n10246703 +n10338391 +n04585456 +n04158138 +n10500942 +n09850974 +n10791890 +n10020807 +n03315805 +n02752917 +n04033801 +n10492086 +n04427473 +n02940706 +n12110475 +n09832978 +n12515393 +n07800487 +n09848110 +n02659176 +n09967406 +n10536134 +n10760622 +n09736485 +n07830690 +n07835173 +n09814252 +n10311506 +n10341955 +n03869838 +n07760673 +n09970402 +n12526178 +n11687964 +n09968741 +n10719267 +n07851054 +n10116478 +n10599215 +n09951524 +n03855908 +n03997274 +n02986348 +n08599292 +n02474282 +n04155889 +n09983314 +n01987727 +n10280130 +n10404998 +n02294577 +n02998696 +n08586978 +n11652578 +n13867005 +n12663254 +n10524869 +n02287622 +n10220924 +n03279918 +n02626089 +n10291110 +n12820669 +n07861681 +n08643267 +n07720185 +n12555859 +n03225616 +n09769525 +n03295140 +n12489046 +n10615179 +n12150969 +n02888429 +n10753182 +n10267166 +n03675558 +n12693352 +n02378299 +n02788462 +n03622401 +n12236977 +n10730542 +n12758099 +n10502046 +n11937195 +n10366145 +n10307114 +n12984595 +n10128748 +n09362316 +n09789898 +n09654079 +n04260192 +n10114476 +n08623676 +n10331841 +n05265736 +n10269289 +n03090856 +n12764978 +n02825240 +n10358032 +n09825750 +n03062651 +n11196627 +n11825749 +n04148464 +n04439505 +n07572858 +n04561857 +n12904562 +n03643907 +n10723597 +n01492708 +n10071557 +n10140683 +n01739871 +n12984267 +n03072056 +n10772580 +n10462588 +n11936448 +n10494373 +n12845908 +n09793352 +n10717196 +n12577362 +n09779124 +n10663549 +n02286425 +n10380126 +n01890144 +n02751490 +n03361109 +n01781875 +n13128278 +n09994400 +n09883452 +n13881512 +n02833275 +n10362003 +n01376543 +n12366675 +n09984960 +n10173665 +n10673776 +n02057898 +n01934844 +n04057673 +n10018747 +n02916065 +n13024653 +n05539947 +n09648911 +n04150273 +n01393486 +n10411356 +n12232114 +n02436224 +n12757930 +n03095965 +n10555059 +n01577458 +n09666476 +n10598904 +n11656549 +n02591911 +n13092385 +n10506336 +n13103023 +n09658254 +n04095938 +n11936782 +n07824383 +n09781650 +n10240821 +n01780426 +n02850060 +n02863340 +n13914141 +n12138578 +n13034555 +n12291671 +n12133151 +n04515444 +n04591359 +n02589196 +n02689819 +n11740414 +n07610295 +n10246395 +n09921034 +n12447346 +n12641180 +n01419573 +n04242587 +n07760395 +n03399579 +n09866661 +n02549376 +n11861238 +n01588996 +n04319545 +n09789150 +n03288643 +n10312491 +n03353281 +n02345997 +n09711132 +n03043173 +n02558860 +n03703590 +n03188871 +n12589142 +n12113323 +n09987161 +n05242239 +n09686262 +n09780984 +n09668199 +n09716933 +n11675738 +n04459243 +n11833749 +n10646942 +n07760070 +n10286539 +n04469684 +n13030616 +n03939440 +n01725086 +n09967816 +n10500824 +n13026015 +n03983928 +n02936921 +n04115542 +n10245029 +n12105828 +n12452673 +n10498046 +n10737264 +n11766046 +n04079603 +n10072054 +n12569037 +n10153155 +n09867311 +n02806992 +n10258602 +n10164025 +n10520964 +n02258508 +n12199399 +n05266096 +n08496334 +n10351064 +n12441552 +n12878325 +n13102648 +n02980625 +n03462972 +n12395906 +n13022903 +n11895714 +n03324814 +n11318824 +n01728266 +n07883510 +n10731013 +n10181799 +n12142357 +n09671089 +n11531334 +n01718414 +n04573625 +n10390600 +n11553522 +n01314910 +n04227519 +n10514784 +n02944256 +n12103680 +n03081859 +n11655592 +n12569616 +n10700105 +n09755086 +n03865820 +n01456137 +n10442232 +n02900987 +n04491934 +n07849026 +n04519728 +n09986450 +n03305300 +n10186143 +n02879422 +n03018614 +n10747548 +n10562509 +n10068425 +n12593341 +n11937692 +n08679562 +n09613690 +n10646433 +n12251740 +n10994097 +n13048447 +n03848537 +n12153741 +n12614096 +n11654438 +n09985470 +n10562968 +n02923915 +n10740594 +n07802767 +n12514592 +n10335801 +n03878674 +n12586499 +n10255459 +n02413824 +n10312600 +n02616128 +n12644283 +n04238953 +n04526520 +n01898593 +n09737161 +n03372822 +n09781398 +n10339251 +n02502807 +n10198832 +n10679610 +n13136781 +n11974373 +n11680457 +n10083677 +n04037298 +n09945021 +n09987239 +n02708885 +n13107807 +n10130877 +n12507379 +n08651104 +n12116058 +n10135297 +n04269086 +n03858533 +n10477955 +n04394031 +n10442417 +n10074735 +n03618797 +n03460455 +n04374521 +n10756061 +n08517010 +n12923108 +n02362194 +n01704103 +n10062492 +n01394771 +n10473789 +n10330593 +n02748183 +n12562141 +n09745933 +n02505485 +n11922661 +n12018014 +n09866922 +n04067143 +n13161254 +n07813495 +n01374846 +n10213429 +n03253071 +n02546028 +n01642097 +n01475232 +n03212247 +n10155600 +n11689957 +n11738997 +n10525878 +n03301389 +n10589666 +n01908958 +n10289766 +n03900028 +n03437295 +n02987823 +n02739123 +n10505347 +n02546627 +n10381804 +n10132502 +n10336904 +n10189597 +n09786115 +n12875697 +n10761519 +n01470733 +n02875626 +n12111238 +n07862770 +n07856895 +n09996039 +n03368048 +n07913300 +n10062996 +n10555430 +n04302863 +n12758555 +n10740732 +n02385898 +n02385098 +n12162758 +n03887899 +n03976268 +n04234160 +n03641947 +n07857076 +n10578656 +n12135729 +n12675515 +n09032191 +n12969670 +n02600503 +n12518013 +n10227166 +n10121026 +n01801672 +n10661216 +n03244388 +n04147291 +n09664556 +n02539573 +n04480141 +n10601362 +n02613572 +n10537906 +n02613820 +n11656771 +n03841011 +n02845985 +n12534208 +n10241024 +n03645290 +n12743976 +n11922839 +n07709701 +n03066232 +n03467380 +n09266604 +n09663786 +n12775070 +n02427183 +n04083113 +n12896615 +n10501453 +n02345774 +n09965515 +n09704157 +n10666752 +n03846970 +n04167661 +n03991321 +n09556121 +n10686517 +n02586238 +n03594277 +n03591313 +n10391416 +n10756837 +n13163649 +n03971960 +n10245341 +n02577041 +n04481642 +n12373739 +n10214062 +n10091997 +n10275848 +n02090253 +n03514340 +n04593629 +n11795216 +n03126927 +n11871748 +n10272782 +n12056099 +n04484024 +n03101375 +n12255225 +n10724372 +n10531838 +n02354781 +n02389865 +n02853336 +n01477080 +n01779939 +n10776052 +n10724132 +n10284871 +n10554141 +n03898787 +n02366301 +n10721612 +n04421740 +n04256758 +n01445593 +n10103921 +n02729222 +n02530188 +n02387452 +n02601921 +n01711160 +n02474110 +n09869447 +n12789977 +n10158506 +n10396908 +n07839593 +n02662825 +n02473720 +n13034788 +n07752602 +n03762238 +n10262880 +n07770180 +n04030054 +n10151367 +n03525252 +n10252075 +n10747424 +n10191388 +n04130566 +n03951068 +n13239921 +n03733547 +n10358124 +n11549779 +n09203827 +n04043168 +n10359422 +n04286960 +n04237287 +n10130686 +n02338449 +n12912274 +n10586998 +n02812785 +n10364502 +n03955941 +n12324222 +n09743601 +n03766600 +n01427399 +n12968309 +n11776234 +n01501777 +n10051026 +n10397001 +n01516212 +n02596252 +n02225081 +n10479328 +n02109687 +n10181445 +n02248062 +n03802973 +n01639187 +n02142734 +n02342534 +n02410141 +n02743426 +n03950359 +n12253835 +n07805478 +n03706415 +n03578981 +n04560619 +n09761753 +n03524425 +n01962788 +n04350235 +n10686694 +n13139321 +n10195155 +n12335937 +n12758399 +n03805374 +n12895298 +n03800371 +n11972959 +n11530008 +n03178538 +n02217839 +n10591072 +n04033557 +n01880813 +n12292877 +n02430643 +n07599383 +n01954516 +n09894909 +n02474605 +n03576443 +n07595051 +n03367875 +n12945549 +n02360480 +n14583400 +n04208582 +n02405577 +n02550655 +n02513355 +n04381450 +n00444490 +n03567912 +n09937688 +n07932323 +n04029416 +n01913346 +n13237508 +n04437276 +n12938445 +n03042384 +n12543639 +n03194992 +n04094250 +n12045514 +n03825913 +n03504293 +n12758250 +n03547861 +n03649288 +n04572235 +n07569423 +n03534695 +n03253714 +n01501641 +n13906767 +n12578255 +n11749603 +n07742513 +n07609083 +n04214413 +n07595751 +n12013701 +n12592839 +n12949160 +n04093223 +n02983072 +n03510072 +n02966068 +n03867854 +n01747285 +n10691318 +n13091982 +n12574470 +n02255023 +n03449217 +n03153585 +n04006227 +n13140049 +n02965024 +n03805503 +n03911406 +n13120958 +n12203699 +n01456454 +n10397142 +n12920043 +n02412977 +n08674344 +n07801007 +n03037590 +n10361296 +n13133316 +n03483637 +n04435759 +n12983873 +n02627037 +n03783304 +n07725158 +n02921292 +n01788864 +n01705010 +n12616996 +n03903290 +n08662427 +n03667060 +n07856992 +n03252422 +n02449699 +n12137954 +n10024025 +n07891095 +n04337157 +n04368109 +n03015631 +n02363996 +n12824289 +n03206602 +n12799269 +n02333733 +n01793565 +n01721898 +n03178173 +n02844056 +n11688378 +n13889066 +n02637475 +n03750437 +n01403457 +n01717229 +n02677136 +n12512294 +n03736269 +n02838577 +n08661878 +n01993830 +n02777638 +n02900857 +n04023021 +n03843092 +n07770439 +n12928491 +n03697812 +n02639922 +n13139482 +n07771082 +n12487058 +n07774182 +n02122810 +n02856362 +n11686195 +n11687432 +n02853870 +n04239218 +n02665250 +n02938218 +n11746600 +n10183347 +n10681194 +n04164199 +n04407257 +n12549005 +n02331842 +n03862379 +n02863638 +n11962994 +n03091907 +n04177654 +n02252972 +n02403153 +n01376437 +n02848806 +n08579266 +n07616265 +n10331258 +n10765587 +n09433312 +n03412387 +n10178077 +n13123841 +n02532918 +n04144651 +n03296963 +n03450881 +n04348988 +n10425946 +n03257065 +n02354320 +n11689197 +n04084682 +n10140783 +n03637027 +n02346170 +n02559144 +n01705591 +n09400584 +n03840327 +n03918074 +n04053767 +n02406046 +n00288190 +n03160001 +n03366464 +n09249155 +n01324305 +n07556872 +n03381565 +n12705220 +n11874878 +n02632494 +n02502006 +n03146560 +n02179340 +n04312756 +n10162016 +n03800563 +n04140853 +n07933652 +n03075248 +n04421582 +n10652703 +n02218134 +n12233249 +n04578559 +n01781071 +n02615298 +n04436832 +n04054566 +n02608284 +n11674019 +n03505764 +n02662397 +n09422190 +n04382537 +n04355684 +n04383923 +n09888635 +n03783575 +n03228796 +n07772026 +n02381119 +n15060326 +n10586166 +n12647787 +n02458517 +n10281546 +n03498866 +n02485988 +n10121246 +n09391644 +n03103904 +n08676253 +n02203978 +n04092168 +n03213014 +n03138217 +n04135933 +n12612811 +n04478066 +n02157285 +n02543255 +n03863783 +n01502101 +n03930229 +n12439830 +n09425019 +n02618513 +n02910241 +n12261359 +n03648667 +n04365229 +n03461651 +n04388040 +n03295928 +n03581531 +n04203356 +n02622249 +n13142907 +n04497249 +n11678377 +n02366579 +n02931013 +n02837134 +n03132438 +n13092987 +n04196803 +n03056215 +n03255322 +n02130925 +n10291469 +n02971940 +n01718096 +n12510774 +n11766432 +n04271891 +n03366721 +n03154616 +n03694356 +n10478293 +n11763142 +n07763483 +n03037228 +n09201998 +n01517389 +n00443517 +n12693244 +n03580990 +n03519848 +n10238375 +n10783646 +n03564849 +n03975926 +n02473554 +n02450426 +n03464952 +n04411835 +n04573045 +n10505732 +n04337650 +n10621514 +n10334782 +n12434985 +n07769102 +n10594523 +n05475397 +n01875610 +n03299406 +n10507692 +n02593679 +n03317233 +n13239736 +n03550420 +n03247351 +n03819047 +n03633341 +n03154745 +n04073425 +n04532022 +n02910964 +n04301242 +n04378651 +n13098515 +n11775626 +n14603798 +n10263146 +n01886045 +n03761731 +n02224713 +n04591249 +n02144251 +n03849412 +n11548728 +n04051705 +n12298165 +n03150795 +n03989447 +n02826459 +n07602650 +n03155915 +n09891730 +n02067603 +n01523105 +n03618339 +n03897130 +n02711780 +n05285623 +n03533486 +n04085873 +n01923404 +n10139077 +n01709484 +n02183507 +n03216562 +n01971850 +n03136051 +n02948834 +n03589313 +n03665851 +n02937336 +n02035656 +n07769465 +n07849186 +n12585373 +n12280364 +n02846260 +n02511730 +n02614653 +n04193179 +n11718681 +n09467696 +n01522450 +n03040836 +n03162297 +n11896141 +n04000480 +n10350220 +n07746038 +n02124157 +n10655169 +n03476542 +n03895038 +n00443917 +n07757753 +n01726203 +n02987706 +n12750076 +n03012734 +n02941228 +n04194009 +n04501127 +n09794550 +n03510487 +n08589670 +n03166951 +n03673270 +n09792125 +n08492354 +n02396157 +n01628331 +n03993878 +n07833816 +n04958865 +n13650447 +n04339191 +n02826683 +n02893269 +n02810139 +n02626471 +n02589796 +n08677801 +n04325968 +n03275864 +n02622547 +n04406687 +n04097085 +n02998107 +n07831450 +n03658102 +n02575590 +n03523398 +n02412909 +n02953850 +n04337503 +n03510987 +n12664005 +n03710294 +n13138155 +n10110093 +n07831955 +n03932080 +n12971804 +n03943623 +n03726371 +n10531445 +n12984489 +n07835051 +n12097556 +n02685701 +n03038041 +n02451125 +n04594919 +n02372140 +n02665985 +n03496183 +n03961828 +n03802800 +n01713170 +n03602790 +n04974145 +n02780588 +n04031884 +n03588216 +n02614140 +n04578708 +n04501281 +n03166600 +n03992975 +n04206070 +n03227721 +n02582349 +n02664642 +n07805389 +n09226869 +n02459190 +n12216968 +n03628984 +n02524928 +n09209025 +n04078002 +n03167153 +n03562565 +n07599554 +n10252547 +n03279804 +n07692887 +n14909584 +n02529293 +n04444953 +n04156814 +n07616174 +n03415626 +n03331244 +n03868324 +n03644073 +n02818687 +n10085101 +n02953056 +n03202481 +n02118707 +n03591901 +n12602434 +n02943465 +n02818254 +n07922607 +n02597004 +n04212810 +n04056073 +n12327528 +n02207647 +n01792808 +n03002555 +n03951213 +n12242123 +n10062275 +n12325787 +n10048117 +n11937278 +n03624767 +n04039041 +n04059298 +n03707171 +n07758407 +n01333483 +n02219015 +n02436645 +n02478239 +n04457638 +n01781698 +n09474765 +n03686363 +n10769084 +n09456207 +n02385776 +n13555775 +n03962685 +n13129078 +n03463185 +n01429172 +n04243251 +n12177129 +n03143754 +n03958338 +n02791795 +n04560502 +n12776774 +n02745816 +n03009111 +n02976552 +n03008817 +n03211413 +n03537550 +n12200504 +n01909788 +n11790089 +n03480973 +n10507070 +n01707294 +n04374907 +n04281571 +n00006024 +n03823906 +n12603273 +n03503358 +n04027820 +n12645530 +n02535080 +n04143365 +n08385989 +n12661227 +n12814857 +n11871059 +n04268418 +n13128582 +n01928865 +n04359124 +n12670334 +n03610836 +n04543924 +n02252799 +n15102359 +n04437380 +n04316924 +n11872324 +n09330378 +n10122300 +n03784139 +n00443375 +n14993378 +n01721174 +n00004475 +n00006484 +n00007846 +n00015388 +n00017222 +n00021265 +n00021939 +n00288000 +n00433458 +n00433661 +n00433802 +n00439826 +n00440218 +n00440509 +n00440747 +n00441824 +n00442115 +n00442981 +n00443231 +n00444651 +n00445351 +n00445802 +n00447073 +n00447221 +n00447540 +n00448466 +n00448640 +n00448958 +n00449295 +n00449695 +n00450335 +n00450700 +n00451370 +n00451866 +n00452293 +n00453935 +n00454237 +n00454624 +n00463246 +n00464651 +n00464894 +n00467719 +n00467995 +n00468480 +n00469651 +n00471437 +n00471613 +n00479076 +n00480508 +n00480993 +n00482298 +n00523513 +n01035667 +n01316422 +n01316579 +n01316949 +n01317089 +n01317391 +n01317541 +n01319467 +n01320872 +n01321230 +n01321579 +n01321854 +n01322343 +n01322685 +n01322898 +n01323068 +n01326291 +n01329186 +n01338685 +n01339336 +n01340935 +n01342269 +n01358572 +n01367772 +n01375204 +n01376237 +n01380610 +n01384687 +n01385330 +n01387065 +n01389507 +n01390123 +n01392380 +n01395254 +n01397114 +n01402600 +n01407798 +n01421807 +n01438208 +n01439121 +n01439514 +n01439808 +n01441425 +n01444783 +n01445429 +n01446589 +n01446760 +n01448951 +n01450661 +n01454856 +n01455778 +n01458842 +n01459791 +n01461646 +n01466257 +n01467336 +n01468238 +n01468712 +n01471682 +n01473806 +n01474283 +n01477525 +n01478511 +n01480516 +n01480880 +n01481331 +n01482071 +n01482330 +n01483522 +n01484097 +n01488918 +n01491874 +n01492357 +n01493541 +n01494757 +n01494882 +n01495006 +n01495701 +n01497118 +n01498406 +n01498699 +n01498989 +n01500091 +n01501160 +n01503061 +n01514752 +n01515078 +n01517565 +n01524359 +n01525720 +n01527194 +n01527617 +n01528654 +n01529672 +n01533339 +n01534582 +n01534762 +n01537134 +n01538955 +n01539573 +n01540233 +n01541922 +n01542786 +n01544208 +n01546921 +n01547832 +n01548301 +n01549430 +n01550761 +n01553142 +n01555809 +n01557185 +n01560105 +n01560636 +n01563128 +n01563746 +n01564394 +n01567133 +n01568132 +n01569836 +n01570676 +n01571904 +n01572328 +n01573074 +n01574045 +n01574390 +n01575745 +n01576695 +n01577659 +n01578575 +n01579028 +n01580379 +n01580490 +n01580772 +n01580870 +n01581166 +n01581434 +n01581730 +n01582398 +n01582498 +n01582856 +n01584225 +n01585121 +n01587834 +n01588431 +n01589286 +n01591697 +n01592257 +n01592540 +n01594372 +n01595624 +n01597336 +n01598588 +n01598988 +n01600085 +n01600657 +n01602080 +n01602209 +n01602630 +n01603600 +n01604330 +n01605630 +n01608814 +n01609062 +n01609391 +n01609751 +n01610955 +n01611472 +n01612628 +n01613294 +n01613615 +n01615121 +n01616551 +n01616764 +n01617095 +n01617443 +n01617766 +n01618082 +n01618922 +n01619310 +n01619536 +n01619835 +n01620135 +n01620414 +n01620735 +n01621127 +n01622352 +n01623706 +n01627424 +n01629276 +n01630284 +n01631175 +n01632047 +n01637112 +n01637932 +n01639765 +n01640846 +n01645776 +n01649170 +n01650167 +n01651487 +n01653773 +n01661091 +n01661592 +n01661818 +n01662622 +n01662784 +n01663401 +n01664369 +n01665932 +n01667432 +n01668091 +n01669372 +n01670092 +n01672032 +n01674216 +n01674464 +n01674990 +n01676755 +n01680264 +n01680478 +n01681940 +n01684133 +n01685439 +n01686044 +n01686220 +n01686403 +n01686609 +n01686808 +n01687665 +n01688961 +n01689411 +n01691951 +n01692864 +n01693783 +n01694709 +n01696633 +n01697178 +n01698434 +n01699040 +n01701551 +n01702256 +n01703011 +n01703569 +n01705934 +n01708106 +n01708998 +n01712008 +n01712752 +n01717016 +n01719403 +n01722998 +n01724231 +n01726692 +n01727646 +n01730185 +n01730307 +n01730812 +n01730960 +n01731545 +n01732244 +n01733757 +n01734637 +n01734808 +n01735439 +n01735577 +n01735728 +n01737472 +n01737728 +n01737875 +n01738065 +n01738601 +n01739647 +n01740551 +n01741232 +n01741562 +n01741943 +n01743605 +n01745125 +n01745484 +n01746359 +n01747885 +n01749582 +n01749742 +n01751036 +n01752165 +n01753959 +n01754876 +n01755740 +n01767661 +n01769347 +n01770795 +n01771417 +n01772222 +n01775370 +n01776192 +n01776705 +n01777304 +n01777467 +n01777649 +n01777909 +n01778217 +n01778487 +n01778621 +n01778801 +n01779148 +n01779463 +n01779629 +n01780696 +n01782209 +n01785667 +n01789386 +n01789740 +n01791107 +n01791625 +n01792158 +n01792640 +n01794158 +n01795088 +n01795735 +n01795900 +n01796019 +n01796105 +n01796519 +n01796729 +n01798706 +n01798839 +n01798979 +n01799302 +n01800424 +n01801088 +n01801479 +n01802721 +n01803078 +n01804478 +n01804653 +n01804921 +n01805070 +n01805801 +n01806847 +n01807828 +n01808140 +n01808291 +n01808596 +n01809106 +n01810700 +n01811909 +n01812337 +n01813385 +n01814370 +n01814921 +n01815601 +n01816887 +n01819115 +n01820348 +n01820801 +n01821076 +n01821203 +n01822602 +n01823013 +n01824749 +n01825930 +n01826364 +n01827403 +n01829869 +n01831712 +n01832167 +n01834177 +n01834540 +n01835276 +n01838038 +n01838598 +n01839598 +n01841102 +n01843719 +n01844231 +n01844551 +n01844917 +n01845132 +n01845477 +n01846331 +n01848123 +n01848648 +n01849466 +n01850373 +n01851375 +n01852142 +n01852861 +n01853498 +n01854415 +n01856072 +n01856155 +n01856380 +n01856553 +n01856890 +n01857079 +n01857325 +n01857512 +n01857632 +n01857851 +n01858441 +n01859496 +n01860497 +n01861148 +n01861778 +n01871543 +n01871875 +n01874434 +n01874928 +n01876326 +n01877134 +n01878061 +n01878335 +n01878639 +n01878929 +n01879217 +n01879509 +n01880152 +n01881171 +n01883513 +n01883920 +n01886756 +n01887896 +n01888264 +n01889074 +n01889520 +n01890860 +n01891633 +n01892551 +n01894207 +n01905661 +n01906749 +n01907738 +n01909422 +n01911403 +n01911839 +n01912454 +n01914163 +n01914830 +n01915811 +n01916187 +n01916925 +n01918744 +n01922303 +n01925270 +n01925695 +n01926379 +n01926689 +n01927159 +n01927456 +n01927928 +n01928215 +n01930852 +n01931140 +n01931520 +n01931714 +n01932151 +n01932936 +n01933151 +n01933478 +n01933988 +n01934440 +n01935176 +n01936391 +n01937909 +n01940736 +n01941223 +n01942177 +n01942869 +n01943541 +n01944118 +n01944812 +n01944955 +n01945143 +n01945340 +n01945845 +n01946277 +n01948573 +n01951613 +n01953361 +n01955933 +n01956481 +n01958038 +n01959985 +n01960459 +n01963571 +n01964049 +n01964441 +n01965889 +n01967094 +n01968315 +n01969726 +n01971094 +n01971280 +n01974773 +n01975687 +n01976146 +n01976957 +n01978930 +n01981702 +n01982650 +n01983048 +n01985493 +n01985797 +n01986806 +n01987545 +n01988701 +n01989869 +n01990007 +n01991028 +n01991520 +n01992262 +n01992423 +n01992773 +n01996585 +n01998183 +n02000954 +n02002075 +n02005790 +n02006985 +n02007284 +n02008041 +n02008796 +n02010453 +n02011805 +n02011943 +n02012185 +n02013177 +n02014941 +n02015554 +n02016358 +n02016956 +n02018027 +n02019190 +n02019438 +n02019929 +n02021050 +n02021795 +n02022684 +n02023341 +n02025043 +n02026059 +n02028175 +n02030035 +n02030287 +n02030996 +n02031934 +n02033208 +n02033324 +n02033561 +n02034129 +n02034661 +n02036053 +n02037464 +n02039171 +n02040505 +n02041085 +n02041246 +n02043063 +n02044178 +n02044778 +n02045369 +n02046759 +n02047260 +n02047614 +n02048698 +n02049532 +n02050004 +n02051474 +n02052204 +n02052365 +n02053083 +n02054502 +n02055658 +n02055803 +n02057731 +n02058594 +n02058747 +n02059162 +n02060411 +n02060889 +n02062017 +n02062430 +n02062744 +n02063224 +n02064338 +n02066707 +n02068206 +n02068974 +n02069701 +n02070430 +n02073250 +n02075296 +n02075927 +n02076196 +n02076779 +n02077152 +n02077658 +n02078292 +n02078574 +n02078738 +n02079005 +n02079389 +n02081571 +n02083346 +n02083672 +n02084071 +n02084861 +n02085374 +n02086346 +n02086478 +n02087122 +n02087551 +n02088839 +n02089232 +n02089555 +n02090475 +n02090827 +n02092468 +n02093056 +n02094562 +n02094721 +n02095050 +n02095412 +n02095727 +n02096756 +n02097786 +n02098550 +n02099029 +n02099997 +n02100399 +n02101108 +n02101861 +n02102605 +n02103406 +n02103841 +n02104523 +n02104882 +n02106966 +n02107420 +n02108254 +n02108672 +n02109150 +n02109811 +n02110532 +n02111626 +n02112497 +n02112826 +n02113335 +n02114100 +n02115012 +n02115335 +n02117512 +n02117646 +n02117900 +n02118176 +n02118333 +n02119247 +n02119359 +n02120278 +n02120997 +n02121620 +n02121808 +n02122725 +n02123785 +n02124623 +n02127292 +n02127381 +n02127482 +n02127586 +n02127678 +n02127808 +n02128598 +n02128669 +n02129463 +n02129530 +n02129837 +n02129923 +n02130545 +n02131653 +n02132466 +n02132580 +n02132788 +n02133400 +n02134971 +n02135220 +n02137722 +n02137888 +n02138647 +n02138777 +n02139199 +n02139671 +n02141306 +n02141713 +n02144593 +n02145424 +n02148835 +n02149420 +n02150482 +n02152740 +n02152991 +n02153203 +n02153809 +n02156732 +n02159955 +n02164464 +n02165877 +n02166229 +n02166567 +n02166826 +n02167505 +n02167820 +n02167944 +n02168245 +n02169023 +n02169218 +n02169705 +n02169974 +n02170400 +n02170993 +n02171453 +n02171869 +n02172518 +n02172678 +n02172761 +n02172870 +n02174355 +n02176261 +n02178411 +n02178717 +n02179012 +n02180233 +n02181235 +n02181724 +n02182045 +n02182355 +n02182642 +n02182930 +n02183857 +n02186153 +n02188699 +n02189363 +n02190790 +n02191273 +n02191773 +n02191979 +n02192252 +n02192513 +n02192814 +n02193009 +n02193163 +n02194249 +n02194750 +n02195091 +n02195526 +n02195819 +n02196344 +n02198532 +n02199502 +n02200198 +n02202287 +n02204722 +n02206270 +n02207179 +n02207449 +n02208280 +n02208498 +n02208848 +n02208979 +n02209111 +n02209354 +n02209624 +n02209964 +n02210427 +n02210921 +n02211444 +n02211627 +n02211896 +n02212062 +n02212602 +n02212958 +n02213107 +n02215161 +n02215770 +n02217563 +n02218713 +n02220055 +n02220225 +n02220518 +n02220804 +n02221083 +n02221414 +n02221571 +n02221715 +n02221820 +n02222035 +n02222321 +n02222582 +n02223266 +n02223520 +n02226183 +n02226821 +n02226970 +n02227247 +n02227604 +n02227966 +n02228341 +n02228697 +n02229156 +n02229765 +n02230023 +n02230187 +n02230480 +n02230634 +n02231052 +n02231803 +n02233943 +n02234355 +n02234570 +n02234848 +n02235205 +n02236241 +n02236896 +n02237424 +n02237581 +n02238235 +n02238887 +n02239528 +n02241569 +n02241799 +n02243562 +n02244173 +n02246011 +n02246628 +n02247511 +n02248368 +n02248510 +n02248887 +n02249515 +n02250822 +n02251775 +n02252226 +n02253127 +n02253715 +n02254697 +n02257003 +n02257284 +n02257715 +n02259377 +n02260421 +n02260863 +n02261419 +n02262178 +n02263378 +n02264885 +n02265330 +n02268148 +n02269196 +n02269522 +n02270011 +n02270200 +n02271570 +n02271897 +n02272871 +n02274024 +n02274259 +n02274822 +n02278210 +n02278839 +n02279637 +n02280458 +n02281015 +n02281136 +n02281267 +n02282257 +n02282385 +n02282553 +n02282903 +n02283077 +n02283201 +n02283951 +n02285548 +n02287004 +n02287799 +n02288789 +n02291220 +n02291572 +n02291748 +n02293352 +n02293868 +n02295064 +n02295390 +n02295870 +n02298541 +n02300173 +n02301452 +n02302459 +n02302620 +n02305407 +n02306433 +n02307325 +n02308139 +n02308471 +n02309337 +n02310000 +n02310717 +n02311060 +n02312006 +n02312427 +n02313008 +n02316707 +n02318167 +n02319308 +n02319555 +n02319829 +n02320127 +n02322047 +n02323449 +n02323902 +n02324045 +n02325722 +n02325884 +n02326074 +n02326763 +n02326862 +n02327028 +n02327175 +n02327435 +n02327656 +n02327842 +n02328429 +n02329401 +n02330245 +n02331046 +n02331309 +n02332755 +n02333546 +n02334460 +n02335127 +n02336011 +n02336641 +n02338901 +n02339376 +n02339922 +n02343058 +n02343320 +n02343772 +n02344528 +n02345600 +n02346998 +n02347274 +n02347573 +n02347744 +n02348173 +n02348788 +n02350105 +n02350989 +n02351870 +n02352591 +n02353861 +n02355227 +n02355477 +n02358091 +n02359324 +n02360781 +n02361587 +n02361706 +n02361850 +n02363245 +n02363351 +n02364520 +n02369680 +n02370806 +n02372584 +n02373336 +n02374149 +n02374451 +n02376542 +n02376791 +n02376918 +n02377181 +n02377480 +n02377703 +n02378415 +n02380335 +n02380583 +n02380745 +n02381460 +n02382437 +n02382948 +n02384858 +n02386014 +n02386310 +n02386496 +n02388276 +n02389346 +n02389559 +n02390454 +n02390834 +n02391234 +n02391373 +n02391508 +n02391994 +n02393580 +n02394477 +n02395003 +n02395694 +n02395931 +n02397529 +n02399000 +n02401031 +n02402010 +n02402175 +n02402425 +n02403325 +n02403454 +n02404186 +n02404573 +n02406174 +n02407959 +n02408660 +n02408817 +n02409870 +n02410702 +n02410900 +n02411705 +n02412440 +n02413131 +n02414578 +n02415435 +n02416519 +n02417070 +n02417534 +n02418064 +n02419796 +n02423218 +n02423362 +n02423589 +n02424305 +n02424695 +n02426813 +n02427724 +n02428349 +n02430045 +n02430559 +n02431122 +n02432511 +n02433546 +n02433925 +n02435853 +n02437136 +n02437971 +n02438173 +n02438272 +n02439033 +n02441326 +n02442172 +n02442336 +n02442446 +n02442572 +n02442668 +n02443015 +n02443346 +n02443808 +n02443959 +n02444251 +n02445004 +n02445171 +n02446206 +n02446352 +n02446645 +n02447021 +n02447762 +n02448060 +n02448633 +n02448885 +n02450034 +n02453108 +n02453611 +n02454794 +n02455135 +n02455428 +n02455720 +n02456008 +n02456275 +n02456962 +n02460009 +n02469914 +n02470325 +n02470899 +n02471300 +n02471762 +n02472293 +n02473307 +n02474777 +n02476219 +n02480153 +n02481103 +n02481235 +n02481366 +n02481500 +n02482060 +n02482286 +n02482474 +n02482650 +n02483092 +n02484322 +n02484473 +n02485225 +n02485371 +n02485536 +n02485688 +n02486657 +n02486908 +n02487079 +n02487547 +n02487675 +n02487847 +n02488003 +n02488415 +n02488894 +n02489589 +n02490597 +n02490811 +n02491107 +n02491329 +n02491474 +n02496913 +n02501583 +n02502514 +n02503127 +n02503517 +n02504770 +n02507649 +n02508021 +n02512053 +n02512938 +n02513560 +n02515214 +n02516188 +n02517442 +n02517938 +n02519148 +n02519686 +n02521646 +n02522399 +n02524524 +n02526425 +n02526818 +n02527057 +n02527271 +n02527622 +n02528163 +n02529772 +n02530421 +n02532028 +n02532602 +n02533209 +n02533834 +n02534559 +n02534734 +n02535537 +n02537085 +n02537319 +n02538406 +n02538985 +n02540412 +n02541687 +n02546331 +n02548689 +n02549989 +n02550460 +n02552171 +n02554730 +n02556846 +n02557591 +n02557749 +n02559862 +n02561108 +n02561661 +n02562315 +n02562796 +n02563182 +n02564720 +n02565573 +n02566109 +n02568959 +n02569484 +n02570838 +n02572196 +n02574910 +n02576223 +n02576575 +n02578233 +n02579557 +n02580336 +n02581957 +n02583567 +n02585872 +n02586543 +n02588286 +n02590495 +n02590702 +n02590987 +n02594250 +n02596381 +n02597367 +n02599052 +n02599958 +n02600298 +n02601344 +n02602405 +n02603317 +n02604157 +n02605316 +n02606384 +n02607201 +n02607862 +n02613181 +n02614482 +n02614978 +n02619165 +n02621908 +n02623445 +n02624167 +n02625612 +n02626762 +n02627835 +n02630281 +n02630739 +n02631041 +n02636170 +n02636854 +n02638596 +n02640626 +n02640857 +n02642107 +n02642644 +n02643112 +n02644113 +n02646667 +n02648625 +n02650050 +n02650541 +n02652668 +n02653145 +n02653786 +n02654425 +n02655523 +n02656670 +n02657368 +n02658079 +n02661017 +n02662239 +n02663849 +n02667379 +n02667576 +n02668393 +n02670382 +n02671780 +n02672371 +n02676261 +n02676670 +n02677028 +n02677718 +n02678384 +n02680110 +n02680754 +n02682407 +n02682922 +n02683791 +n02686121 +n02686568 +n02687992 +n02688443 +n02689274 +n02691156 +n02692513 +n02693413 +n02693540 +n02694426 +n02694966 +n02695627 +n02697576 +n02698244 +n02700258 +n02700895 +n02702989 +n02703275 +n02705944 +n02708224 +n02708555 +n02709367 +n02709637 +n02710600 +n02712643 +n02713218 +n02715229 +n02715513 +n02715712 +n02716626 +n02726305 +n02726681 +n02727016 +n02727825 +n02728440 +n02729837 +n02729965 +n02730265 +n02732072 +n02732827 +n02733213 +n02733524 +n02735361 +n02735688 +n02736798 +n02737660 +n02738031 +n02738271 +n02738535 +n02739550 +n02739668 +n02740533 +n02740764 +n02741475 +n02742322 +n02742753 +n02745492 +n02746365 +n02749790 +n02750169 +n02751067 +n02751295 +n02752496 +n02753044 +n02753394 +n02754103 +n02755352 +n02755529 +n02756098 +n02756977 +n02757462 +n02757810 +n02758134 +n02758960 +n02759700 +n02759963 +n02760099 +n02760199 +n02760429 +n02760855 +n02761392 +n02763198 +n02763714 +n02764044 +n02764614 +n02764779 +n02765028 +n02766320 +n02766534 +n02766792 +n02767433 +n02769075 +n02770830 +n02772554 +n02772700 +n02773037 +n02773838 +n02774152 +n02774630 +n02775483 +n02776205 +n02777100 +n02777734 +n02777927 +n02778456 +n02778669 +n02781121 +n02781338 +n02781517 +n02783035 +n02783324 +n02784998 +n02785648 +n02786198 +n02786463 +n02788689 +n02789487 +n02790823 +n02792552 +n02792948 +n02793842 +n02794008 +n02794779 +n02794972 +n02795783 +n02796207 +n02796623 +n02796995 +n02797692 +n02797881 +n02799897 +n02801184 +n02801525 +n02801938 +n02802721 +n02803349 +n02803666 +n02804252 +n02806088 +n02806379 +n02806875 +n02810471 +n02811468 +n02811719 +n02812201 +n02813252 +n02813399 +n02815478 +n02815950 +n02816494 +n02817031 +n02817650 +n02817799 +n02818832 +n02819697 +n02820210 +n02821627 +n02821943 +n02822220 +n02822399 +n02822865 +n02823335 +n02824448 +n02826589 +n02826886 +n02827606 +n02828299 +n02828884 +n02831335 +n02831724 +n02831894 +n02833793 +n02834778 +n02835412 +n02836268 +n02839351 +n02839910 +n02840619 +n02841063 +n02841506 +n02842133 +n02843029 +n02843777 +n02844214 +n02844307 +n02844714 +n02847631 +n02848216 +n02848523 +n02849154 +n02850950 +n02851099 +n02853016 +n02854532 +n02854926 +n02855089 +n02855390 +n02855793 +n02857365 +n02857477 +n02857644 +n02858304 +n02860415 +n02861886 +n02862048 +n02862916 +n02863750 +n02865665 +n02865931 +n02866578 +n02867715 +n02869737 +n02871631 +n02871824 +n02871963 +n02872752 +n02873839 +n02874086 +n02875436 +n02876326 +n02876457 +n02876657 +n02877962 +n02879517 +n02880189 +n02880546 +n02880940 +n02881193 +n02881906 +n02882483 +n02882647 +n02883004 +n02883344 +n02884225 +n02885108 +n02885338 +n02886599 +n02887209 +n02887970 +n02888569 +n02889425 +n02891188 +n02891788 +n02892499 +n02893418 +n02896294 +n02896442 +n02897389 +n02897820 +n02898173 +n02898369 +n02898585 +n02898711 +n02900705 +n02901481 +n02901901 +n02902079 +n02902916 +n02903006 +n02904109 +n02904640 +n02908217 +n02909285 +n02911485 +n02912065 +n02913152 +n02914991 +n02916179 +n02916350 +n02917377 +n02917607 +n02919414 +n02920503 +n02921884 +n02923129 +n02924116 +n02925519 +n02928413 +n02928608 +n02929289 +n02929462 +n02929923 +n02931417 +n02931836 +n02932019 +n02932400 +n02933112 +n02933462 +n02933750 +n02933990 +n02934168 +n02935658 +n02935891 +n02936176 +n02936281 +n02936714 +n02938886 +n02939866 +n02941095 +n02942699 +n02943241 +n02943871 +n02944826 +n02945161 +n02946270 +n02946348 +n02946921 +n02947212 +n02947818 +n02948557 +n02949202 +n02950186 +n02950256 +n02950632 +n02950943 +n02951843 +n02952485 +n02952674 +n02953673 +n02954163 +n02954340 +n02954938 +n02955065 +n02955247 +n02955540 +n02955767 +n02957135 +n02957755 +n02958343 +n02959942 +n02961451 +n02961947 +n02963302 +n02963692 +n02963821 +n02965216 +n02965300 +n02965529 +n02966545 +n02966786 +n02966942 +n02967081 +n02967991 +n02968473 +n02969010 +n02969163 +n02969634 +n02969886 +n02970685 +n02970849 +n02971691 +n02972397 +n02973017 +n02974697 +n02975212 +n02976939 +n02978205 +n02978753 +n02979516 +n02982599 +n02983189 +n02983904 +n02984061 +n02984203 +n02984469 +n02984699 +n02985137 +n02985828 +n02986066 +n02987047 +n02987492 +n02989099 +n02991048 +n02991302 +n02992032 +n02993546 +n02995998 +n02997391 +n02997607 +n03001282 +n03001627 +n03002210 +n03003091 +n03004620 +n03005515 +n03007130 +n03007591 +n03010656 +n03010795 +n03011018 +n03011355 +n03012159 +n03013006 +n03014440 +n03015254 +n03017070 +n03018209 +n03020034 +n03020416 +n03020692 +n03024333 +n03025070 +n03025886 +n03027108 +n03027250 +n03029066 +n03031422 +n03032811 +n03033362 +n03033986 +n03034516 +n03034663 +n03035510 +n03036469 +n03036866 +n03037108 +n03037709 +n03038685 +n03039015 +n03039947 +n03040229 +n03040376 +n03043274 +n03043958 +n03045337 +n03046257 +n03048883 +n03049066 +n03049457 +n03050026 +n03050546 +n03050655 +n03050864 +n03051396 +n03051540 +n03052464 +n03052917 +n03053047 +n03054901 +n03055670 +n03056097 +n03056493 +n03057021 +n03057636 +n03058107 +n03058603 +n03058949 +n03059366 +n03061050 +n03063073 +n03063338 +n03064350 +n03064758 +n03065708 +n03066849 +n03070193 +n03071021 +n03071160 +n03072201 +n03073296 +n03073977 +n03074380 +n03074855 +n03075097 +n03075500 +n03075634 +n03076411 +n03076708 +n03078287 +n03078670 +n03079230 +n03079741 +n03080497 +n03080731 +n03081986 +n03082127 +n03082807 +n03082979 +n03084420 +n03085333 +n03085602 +n03085915 +n03086183 +n03086457 +n03086670 +n03087366 +n03087643 +n03087816 +n03088707 +n03091044 +n03091374 +n03092166 +n03092314 +n03093792 +n03094503 +n03096439 +n03096960 +n03098140 +n03098806 +n03099454 +n03099771 +n03099945 +n03100346 +n03100490 +n03101156 +n03101986 +n03102654 +n03102859 +n03106722 +n03106898 +n03107046 +n03109881 +n03111690 +n03112869 +n03113152 +n03113657 +n03113835 +n03114839 +n03115180 +n03116530 +n03116767 +n03117199 +n03118346 +n03118969 +n03119510 +n03120198 +n03120491 +n03121897 +n03122748 +n03123809 +n03125870 +n03128085 +n03128427 +n03128519 +n03129001 +n03130066 +n03130563 +n03131669 +n03132261 +n03134853 +n03135917 +n03136369 +n03137579 +n03139464 +n03140900 +n03141065 +n03141327 +n03143572 +n03145384 +n03145843 +n03146846 +n03147509 +n03148324 +n03148727 +n03149401 +n03151077 +n03153948 +n03154073 +n03154446 +n03155178 +n03156071 +n03156405 +n03157348 +n03158796 +n03158885 +n03161450 +n03162818 +n03163798 +n03163973 +n03164605 +n03164722 +n03164929 +n03165823 +n03167978 +n03168107 +n03168217 +n03170635 +n03171356 +n03172965 +n03173387 +n03175604 +n03176386 +n03177165 +n03177708 +n03178000 +n03178430 +n03180504 +n03180969 +n03181293 +n03182140 +n03182232 +n03182912 +n03183080 +n03186818 +n03187751 +n03189818 +n03193597 +n03196062 +n03196324 +n03196598 +n03199647 +n03199901 +n03200357 +n03200539 +n03200701 +n03200906 +n03201035 +n03201638 +n03201996 +n03202354 +n03202760 +n03203089 +n03203806 +n03204306 +n03204558 +n03204955 +n03205143 +n03205304 +n03206718 +n03206908 +n03207305 +n03208556 +n03210683 +n03211117 +n03211616 +n03212811 +n03214253 +n03214450 +n03215191 +n03219135 +n03220237 +n03221059 +n03221720 +n03222516 +n03223162 +n03223441 +n03224753 +n03224893 +n03225777 +n03226538 +n03228016 +n03228533 +n03228692 +n03229115 +n03229526 +n03231160 +n03231819 +n03235796 +n03235979 +n03236580 +n03236735 +n03237212 +n03237639 +n03239259 +n03239726 +n03240140 +n03241093 +n03241335 +n03241496 +n03242120 +n03242506 +n03242995 +n03243218 +n03245271 +n03245421 +n03246933 +n03250952 +n03251533 +n03251766 +n03252324 +n03252637 +n03254374 +n03255488 +n03255899 +n03256788 +n03256928 +n03257586 +n03258905 +n03259505 +n03261776 +n03262519 +n03262809 +n03262932 +n03265032 +n03266749 +n03267821 +n03269203 +n03269401 +n03270695 +n03271765 +n03271865 +n03272239 +n03272383 +n03273061 +n03273913 +n03274561 +n03274796 +n03276179 +n03277459 +n03277771 +n03278248 +n03279153 +n03279364 +n03279508 +n03280394 +n03280644 +n03281145 +n03282060 +n03282401 +n03284743 +n03284981 +n03285912 +n03286572 +n03287733 +n03288003 +n03289985 +n03291413 +n03292960 +n03294048 +n03294833 +n03296478 +n03297103 +n03297644 +n03297735 +n03298089 +n03302790 +n03303217 +n03303831 +n03304197 +n03304465 +n03305522 +n03307573 +n03308152 +n03309808 +n03314378 +n03314884 +n03315644 +n03316406 +n03318136 +n03319457 +n03320046 +n03322570 +n03322940 +n03323703 +n03324928 +n03325088 +n03326073 +n03327234 +n03327691 +n03327841 +n03329663 +n03330792 +n03334017 +n03334492 +n03334912 +n03335030 +n03335846 +n03336839 +n03337494 +n03338287 +n03338821 +n03339296 +n03339643 +n03340009 +n03340923 +n03342961 +n03343354 +n03343560 +n03343853 +n03346135 +n03346455 +n03349296 +n03350352 +n03350456 +n03350602 +n03351262 +n03351979 +n03352628 +n03354903 +n03355468 +n03356446 +n03357267 +n03357716 +n03359137 +n03359566 +n03360731 +n03361683 +n03362771 +n03363363 +n03364008 +n03364937 +n03365592 +n03365991 +n03366823 +n03373237 +n03374649 +n03374838 +n03375171 +n03376279 +n03378342 +n03379343 +n03379828 +n03379989 +n03380647 +n03380867 +n03381126 +n03381231 +n03381776 +n03382856 +n03382969 +n03383468 +n03384167 +n03384891 +n03385557 +n03386011 +n03387323 +n03387653 +n03390327 +n03391770 +n03393324 +n03394480 +n03394649 +n03396580 +n03396654 +n03397266 +n03397532 +n03398228 +n03399761 +n03399971 +n03402188 +n03402369 +n03404012 +n03404360 +n03404449 +n03405265 +n03405725 +n03407369 +n03409393 +n03409591 +n03410147 +n03411339 +n03412058 +n03412220 +n03412511 +n03412906 +n03413264 +n03413428 +n03413828 +n03414162 +n03415252 +n03416489 +n03416775 +n03417345 +n03418158 +n03418242 +n03419014 +n03422072 +n03422589 +n03423719 +n03424630 +n03427296 +n03428090 +n03428349 +n03429003 +n03429288 +n03429914 +n03430091 +n03430313 +n03430551 +n03430959 +n03431243 +n03431745 +n03433637 +n03433877 +n03434285 +n03434830 +n03435593 +n03437941 +n03438257 +n03439814 +n03441112 +n03442288 +n03442756 +n03446070 +n03446832 +n03448031 +n03448956 +n03449564 +n03449858 +n03450516 +n03452267 +n03452449 +n03453320 +n03454110 +n03454211 +n03454707 +n03455355 +n03456548 +n03456665 +n03457008 +n03457686 +n03458271 +n03459914 +n03461882 +n03465500 +n03465818 +n03466162 +n03466839 +n03467517 +n03467796 +n03467984 +n03468696 +n03469493 +n03470387 +n03470629 +n03470948 +n03472232 +n03472535 +n03472937 +n03473817 +n03473966 +n03475823 +n03476083 +n03476313 +n03477773 +n03477902 +n03478756 +n03478907 +n03481521 +n03482523 +n03483230 +n03483531 +n03484083 +n03484931 +n03487331 +n03487444 +n03487774 +n03488188 +n03488603 +n03489162 +n03490324 +n03490449 +n03490884 +n03491988 +n03496296 +n03496612 +n03497100 +n03497657 +n03498536 +n03499468 +n03500295 +n03501152 +n03501288 +n03501614 +n03502331 +n03502509 +n03502777 +n03503718 +n03503997 +n03505383 +n03505504 +n03506370 +n03507963 +n03508101 +n03509394 +n03509843 +n03510583 +n03510866 +n03511175 +n03512147 +n03512911 +n03513137 +n03513376 +n03515338 +n03517899 +n03517982 +n03518631 +n03519674 +n03521076 +n03521544 +n03522634 +n03524574 +n03524976 +n03525074 +n03525454 +n03525827 +n03528263 +n03529444 +n03531281 +n03531447 +n03531546 +n03532342 +n03534776 +n03535024 +n03536761 +n03537412 +n03538037 +n03538300 +n03538634 +n03538957 +n03540267 +n03540595 +n03541091 +n03541696 +n03541923 +n03542333 +n03542860 +n03543603 +n03544360 +n03545150 +n03546340 +n03547054 +n03547530 +n03548930 +n03550153 +n03550289 +n03551084 +n03551790 +n03552449 +n03552749 +n03553486 +n03554460 +n03555426 +n03555662 +n03557590 +n03558176 +n03558404 +n03558739 +n03561169 +n03563200 +n03563710 +n03563967 +n03565288 +n03565565 +n03566329 +n03568117 +n03568818 +n03571942 +n03572205 +n03574555 +n03574816 +n03575958 +n03576215 +n03577672 +n03577818 +n03578055 +n03578251 +n03578656 +n03579538 +n03579982 +n03583621 +n03584400 +n03585073 +n03588951 +n03589513 +n03589791 +n03590306 +n03590932 +n03592245 +n03592773 +n03593526 +n03595409 +n03595860 +n03596285 +n03597317 +n03598151 +n03598299 +n03598646 +n03600977 +n03601638 +n03601840 +n03602081 +n03603722 +n03604629 +n03604843 +n03605722 +n03605915 +n03606465 +n03609235 +n03609542 +n03610418 +n03610992 +n03612814 +n03613294 +n03613592 +n03614007 +n03614532 +n03615563 +n03617095 +n03617594 +n03618546 +n03618982 +n03619396 +n03619650 +n03619793 +n03619890 +n03620052 +n03621049 +n03621694 +n03622931 +n03623556 +n03624134 +n03625355 +n03626115 +n03631177 +n03631811 +n03632852 +n03633886 +n03635032 +n03635668 +n03635932 +n03636248 +n03636649 +n03638883 +n03639675 +n03640988 +n03642444 +n03646296 +n03646916 +n03647520 +n03651388 +n03653220 +n03653454 +n03654576 +n03655072 +n03656484 +n03657239 +n03658858 +n03659292 +n03660124 +n03661340 +n03662719 +n03662887 +n03663531 +n03664675 +n03664943 +n03665366 +n03666362 +n03666917 +n03667235 +n03667829 +n03671914 +n03672827 +n03673450 +n03673767 +n03676759 +n03677766 +n03679384 +n03679712 +n03681477 +n03682487 +n03684823 +n03685307 +n03685820 +n03686130 +n03686470 +n03687928 +n03688943 +n03689157 +n03689570 +n03690851 +n03691817 +n03692379 +n03693293 +n03697552 +n03698604 +n03699280 +n03699975 +n03700963 +n03701191 +n03701391 +n03701640 +n03701790 +n03702248 +n03704834 +n03705379 +n03706653 +n03707597 +n03708036 +n03709206 +n03709363 +n03709545 +n03710528 +n03711711 +n03711999 +n03712887 +n03713069 +n03714235 +n03715386 +n03715669 +n03715892 +n03716966 +n03717131 +n03718212 +n03718335 +n03718699 +n03718789 +n03719053 +n03721590 +n03722007 +n03722288 +n03724176 +n03725035 +n03725717 +n03726516 +n03726760 +n03726993 +n03727837 +n03727946 +n03728437 +n03728982 +n03729647 +n03729951 +n03730153 +n03730788 +n03731695 +n03733644 +n03733925 +n03735637 +n03736970 +n03738241 +n03738472 +n03739518 +n03739693 +n03743902 +n03744276 +n03744684 +n03744840 +n03745571 +n03746330 +n03748162 +n03749504 +n03749807 +n03750206 +n03751065 +n03752185 +n03752922 +n03753077 +n03753514 +n03758894 +n03759432 +n03760671 +n03762982 +n03763727 +n03764276 +n03765561 +n03765934 +n03766322 +n03768132 +n03769722 +n03770954 +n03772077 +n03772674 +n03773035 +n03775199 +n03775847 +n03779000 +n03779370 +n03780047 +n03781787 +n03782190 +n03785499 +n03787523 +n03789171 +n03789400 +n03789946 +n03790230 +n03790512 +n03790755 +n03791235 +n03792048 +n03792526 +n03793850 +n03795976 +n03796181 +n03797390 +n03798982 +n03799113 +n03800485 +n03800772 +n03800933 +n03802007 +n03802228 +n03802393 +n03803116 +n03809312 +n03811295 +n03811444 +n03811847 +n03811965 +n03812382 +n03812924 +n03813176 +n03813946 +n03815278 +n03815482 +n03815615 +n03816005 +n03816136 +n03816849 +n03817647 +n03819595 +n03819994 +n03820154 +n03820318 +n03820728 +n03820950 +n03824197 +n03825080 +n03827536 +n03828020 +n03829340 +n03831757 +n03834040 +n03834604 +n03836062 +n03837422 +n03838748 +n03839172 +n03839276 +n03839795 +n03841666 +n03842156 +n03844045 +n03844233 +n03845190 +n03846234 +n03846772 +n03847471 +n03847823 +n03848168 +n03848348 +n03849275 +n03850613 +n03851341 +n03851787 +n03852280 +n03852688 +n03854815 +n03859280 +n03859495 +n03859958 +n03861430 +n03861842 +n03862676 +n03863923 +n03864139 +n03864356 +n03864692 +n03865371 +n03865949 +n03868406 +n03871083 +n03871524 +n03871724 +n03873848 +n03874138 +n03874823 +n03875218 +n03880129 +n03880323 +n03880531 +n03883054 +n03883773 +n03883944 +n03884639 +n03885535 +n03885669 +n03886053 +n03886641 +n03887185 +n03888022 +n03889503 +n03889726 +n03891051 +n03892557 +n03894051 +n03894379 +n03896103 +n03896233 +n03896419 +n03896628 +n03896984 +n03897943 +n03898271 +n03898633 +n03899612 +n03899933 +n03901338 +n03903133 +n03903424 +n03904060 +n03904183 +n03904433 +n03905540 +n03906997 +n03907654 +n03908204 +n03909160 +n03909406 +n03915118 +n03915437 +n03916470 +n03916720 +n03917327 +n03918480 +n03920737 +n03923564 +n03923692 +n03924069 +n03926148 +n03926412 +n03926876 +n03927792 +n03928116 +n03929091 +n03929202 +n03929443 +n03930515 +n03932670 +n03936269 +n03938522 +n03939677 +n03940256 +n03941684 +n03943920 +n03945615 +n03947111 +n03947466 +n03948459 +n03951971 +n03953020 +n03953416 +n03955809 +n03956785 +n03956922 +n03957315 +n03957762 +n03958630 +n03958752 +n03959014 +n03959701 +n03961939 +n03962525 +n03962932 +n03963028 +n03965907 +n03966325 +n03966751 +n03966976 +n03967942 +n03968293 +n03971321 +n03972524 +n03973520 +n03973628 +n03975035 +n03979377 +n03979492 +n03980026 +n03981340 +n03982232 +n03982895 +n03984234 +n03984381 +n03985232 +n03986704 +n03988170 +n03989665 +n03990474 +n03991443 +n03992325 +n03992703 +n03993180 +n03993403 +n03994008 +n03994757 +n03995018 +n03995856 +n03996145 +n03996416 +n03997484 +n03999992 +n04000311 +n04001397 +n04001499 +n04001845 +n04004210 +n04004475 +n04005912 +n04007664 +n04010057 +n04010779 +n04010927 +n04011827 +n04012084 +n04013729 +n04014297 +n04015204 +n04016576 +n04016684 +n04018399 +n04018667 +n04019101 +n04019696 +n04020087 +n04020298 +n04020912 +n04021028 +n04021362 +n04021798 +n04022332 +n04022708 +n04023249 +n04024274 +n04026053 +n04026918 +n04027023 +n04027706 +n04028315 +n04029734 +n04030274 +n04036303 +n04037964 +n04038440 +n04038727 +n04039848 +n04042358 +n04042632 +n04042795 +n04042985 +n04043733 +n04044307 +n04044498 +n04045085 +n04045397 +n04046590 +n04046974 +n04047401 +n04049405 +n04050066 +n04051549 +n04051825 +n04052757 +n04056932 +n04057047 +n04057435 +n04057846 +n04057981 +n04058096 +n04058239 +n04059947 +n04060647 +n04060904 +n04061793 +n04061969 +n04062644 +n04063373 +n04063868 +n04064401 +n04065464 +n04065789 +n04067231 +n04067353 +n04067921 +n04068441 +n04068601 +n04069276 +n04069777 +n04070207 +n04070964 +n04071102 +n04071263 +n04071393 +n04072193 +n04072551 +n04073948 +n04075468 +n04075916 +n04076284 +n04077430 +n04077734 +n04078574 +n04079106 +n04079244 +n04079933 +n04080454 +n04080833 +n04081844 +n04083649 +n04086794 +n04087126 +n04087709 +n04088696 +n04088797 +n04089666 +n04089976 +n04090548 +n04091097 +n04093625 +n04095210 +n04096066 +n04097622 +n04097866 +n04099175 +n04099429 +n04100174 +n04101497 +n04101701 +n04102037 +n04102285 +n04102406 +n04102962 +n04104147 +n04104500 +n04105068 +n04105438 +n04105893 +n04107984 +n04108268 +n04110068 +n04110654 +n04110955 +n04111190 +n04111414 +n04111668 +n04113765 +n04114996 +n04115256 +n04115996 +n04116389 +n04118021 +n04121228 +n04122349 +n04122492 +n04122825 +n04123123 +n04123567 +n04123740 +n04125116 +n04125853 +n04126541 +n04126659 +n04126980 +n04127904 +n04128499 +n04128837 +n04131929 +n04134632 +n04136510 +n04137444 +n04137897 +n04138977 +n04139859 +n04140064 +n04140631 +n04141838 +n04143897 +n04146050 +n04147495 +n04148054 +n04149083 +n04151108 +n04151581 +n04151940 +n04152387 +n04154753 +n04156297 +n04156411 +n04157320 +n04158807 +n04158956 +n04160372 +n04160586 +n04161358 +n04161981 +n04164757 +n04164868 +n04166111 +n04167489 +n04169437 +n04170037 +n04171459 +n04171629 +n04171831 +n04174101 +n04174500 +n04176068 +n04176190 +n04176528 +n04177329 +n04177545 +n04180063 +n04180888 +n04181228 +n04181718 +n04182322 +n04183217 +n04183329 +n04184435 +n04184600 +n04185071 +n04186051 +n04186268 +n04186455 +n04186624 +n04186848 +n04187061 +n04187547 +n04187885 +n04189092 +n04190052 +n04190464 +n04190747 +n04190997 +n04191150 +n04191595 +n04191943 +n04192238 +n04192858 +n04194289 +n04196080 +n04197391 +n04198015 +n04198797 +n04199027 +n04201733 +n04202417 +n04205318 +n04206356 +n04207763 +n04210390 +n04211356 +n04211970 +n04215910 +n04216634 +n04216860 +n04216963 +n04217718 +n04217882 +n04219424 +n04221823 +n04222210 +n04222470 +n04222847 +n04225031 +n04225222 +n04225729 +n04226464 +n04226537 +n04227900 +n04229007 +n04229107 +n04229480 +n04230603 +n04230808 +n04231693 +n04232153 +n04233832 +n04234455 +n04235291 +n04235771 +n04236001 +n04236377 +n04236702 +n04238617 +n04241042 +n04241394 +n04242408 +n04243003 +n04243941 +n04244997 +n04245847 +n04246855 +n04247630 +n04247736 +n04248507 +n04249415 +n04250224 +n04250599 +n04253931 +n04255499 +n04256520 +n04260589 +n04261116 +n04262678 +n04263336 +n04263760 +n04264233 +n04264914 +n04266486 +n04267577 +n04269944 +n04270891 +n04271148 +n04272054 +n04272782 +n04273064 +n04273796 +n04275283 +n04275661 +n04275904 +n04278353 +n04279172 +n04279987 +n04280259 +n04280970 +n04283585 +n04283905 +n04284002 +n04285146 +n04285622 +n04285803 +n04286128 +n04288272 +n04288533 +n04288673 +n04289449 +n04291242 +n04291759 +n04292414 +n04292572 +n04293119 +n04293744 +n04294212 +n04294426 +n04295081 +n04295881 +n04299215 +n04300358 +n04301000 +n04301474 +n04303258 +n04304375 +n04305471 +n04306080 +n04306847 +n04307419 +n04307878 +n04308084 +n04308273 +n04308397 +n04308583 +n04308807 +n04309348 +n04309833 +n04310721 +n04311595 +n04312154 +n04312432 +n04313220 +n04314914 +n04315828 +n04315948 +n04317420 +n04318131 +n04318982 +n04319937 +n04320405 +n04322026 +n04322692 +n04322801 +n04323819 +n04326799 +n04326896 +n04328054 +n04328329 +n04328946 +n04329477 +n04330340 +n04330669 +n04330998 +n04331277 +n04332987 +n04333129 +n04338517 +n04339638 +n04340750 +n04340935 +n04341133 +n04341414 +n04341686 +n04346679 +n04347519 +n04348184 +n04348359 +n04349401 +n04350104 +n04350458 +n04354589 +n04356595 +n04358707 +n04358874 +n04359335 +n04359589 +n04360501 +n04360798 +n04361095 +n04361260 +n04362821 +n04363210 +n04363874 +n04364545 +n04364827 +n04364994 +n04365328 +n04365484 +n04365751 +n04368695 +n04370048 +n04371563 +n04373894 +n04375775 +n04377057 +n04378956 +n04379243 +n04379964 +n04380346 +n04381994 +n04382334 +n04382880 +n04383130 +n04383301 +n04386664 +n04387201 +n04387400 +n04388162 +n04388743 +n04389521 +n04390873 +n04391838 +n04392526 +n04393095 +n04394261 +n04395875 +n04397168 +n04397261 +n04397645 +n04398497 +n04398688 +n04398834 +n04399046 +n04400289 +n04401088 +n04402057 +n04402580 +n04402746 +n04402984 +n04403638 +n04404817 +n04404997 +n04405540 +n04405762 +n04407435 +n04407686 +n04409128 +n04409806 +n04410086 +n04410365 +n04410485 +n04411264 +n04411966 +n04413151 +n04413419 +n04415663 +n04416901 +n04417180 +n04417361 +n04417809 +n04419073 +n04421872 +n04422875 +n04427715 +n04428008 +n04431436 +n04431745 +n04434932 +n04435180 +n04436185 +n04436401 +n04436542 +n04437670 +n04437953 +n04438304 +n04438643 +n04440963 +n04441662 +n04444749 +n04445040 +n04445952 +n04446276 +n04447276 +n04447443 +n04448070 +n04448361 +n04450243 +n04450640 +n04450749 +n04451818 +n04452615 +n04452848 +n04453156 +n04453666 +n04453910 +n04454654 +n04455250 +n04455652 +n04456472 +n04457326 +n04458843 +n04459362 +n04459610 +n04460130 +n04462011 +n04463679 +n04464852 +n04467099 +n04467307 +n04468005 +n04469251 +n04470741 +n04471315 +n04471632 +n04472243 +n04472726 +n04473884 +n04474466 +n04475411 +n04475631 +n04477548 +n04478512 +n04478657 +n04480527 +n04481524 +n04487724 +n04488427 +n04489008 +n04489817 +n04490091 +n04491769 +n04493109 +n04494204 +n04495450 +n04497442 +n04497570 +n04498523 +n04499446 +n04499554 +n04500060 +n04501837 +n04502197 +n04502502 +n04502670 +n04502851 +n04504141 +n04504770 +n04505036 +n04506994 +n04507453 +n04508163 +n04508489 +n04508949 +n04509260 +n04509592 +n04511002 +n04514241 +n04516116 +n04516214 +n04516672 +n04518132 +n04519153 +n04520170 +n04520382 +n04521987 +n04524313 +n04527648 +n04529681 +n04530566 +n04531098 +n04531873 +n04533042 +n04533199 +n04533700 +n04534127 +n04534895 +n04536153 +n04538552 +n04539203 +n04540761 +n04541320 +n04543158 +n04544450 +n04546194 +n04546855 +n04547592 +n04549122 +n04549919 +n04551055 +n04552696 +n04553389 +n04554871 +n04555600 +n04555897 +n04556948 +n04557308 +n04557751 +n04558059 +n04558804 +n04559023 +n04559730 +n04562262 +n04563204 +n04565375 +n04566257 +n04567098 +n04568069 +n04568557 +n04569520 +n04569822 +n04570958 +n04571292 +n04571566 +n04571958 +n04572935 +n04574471 +n04574999 +n04576002 +n04576211 +n04576971 +n04577426 +n04577769 +n04578801 +n04579230 +n04580493 +n04581595 +n04582349 +n04583620 +n04585745 +n04585980 +n04586932 +n04587648 +n04588739 +n04589190 +n04589434 +n04591056 +n04591887 +n04592005 +n04592099 +n04594218 +n04594489 +n04595285 +n04595855 +n04596852 +n04597066 +n04597804 +n04598136 +n04598582 +n04599124 +n04600312 +n04600486 +n04600912 +n04603729 +n04603872 +n04605726 +n04606574 +n04608329 +n04608567 +n04609531 +n04609651 +n04610176 +n04610503 +n04610676 +n04611916 +n04613015 +n04615226 +n04615644 +n04950713 +n04951373 +n04958634 +n04959672 +n04960277 +n04961691 +n04963740 +n04965179 +n04965661 +n04967191 +n04968895 +n04970059 +n04970631 +n04970916 +n04972801 +n04973386 +n04976952 +n05238282 +n05241218 +n05242070 +n05244934 +n05266879 +n05399034 +n05447757 +n05449959 +n05453657 +n05467758 +n05586759 +n06254669 +n06262567 +n06263369 +n06263609 +n06263762 +n06266417 +n06266710 +n06267145 +n06271778 +n06272290 +n06272803 +n06274092 +n06275353 +n06276697 +n06277280 +n06281040 +n06359467 +n06359657 +n06418693 +n06591815 +n06592078 +n06595351 +n06613686 +n06793231 +n07556637 +n07556970 +n07557165 +n07557434 +n07560652 +n07561112 +n07562495 +n07563800 +n07564629 +n07564971 +n07565725 +n07565945 +n07566340 +n07566863 +n07567390 +n07567707 +n07568818 +n07569106 +n07569543 +n07570720 +n07572353 +n07572957 +n07573103 +n07573696 +n07574602 +n07575076 +n07575726 +n07575984 +n07576182 +n07576438 +n07576577 +n07577374 +n07579575 +n07580053 +n07580359 +n07580470 +n07581346 +n07581775 +n07582277 +n07582441 +n07582609 +n07583197 +n07584228 +n07584593 +n07585208 +n07587441 +n07587700 +n07588947 +n07590320 +n07591473 +n07592094 +n07592656 +n07593774 +n07595914 +n07596046 +n07596452 +n07596684 +n07597145 +n07597365 +n07598734 +n07599468 +n07599783 +n07599998 +n07600506 +n07601407 +n07605474 +n07605944 +n07606278 +n07606764 +n07607707 +n07609407 +n07609840 +n07611148 +n07611358 +n07611839 +n07611991 +n07612367 +n07612632 +n07612996 +n07613671 +n07614198 +n07614825 +n07615052 +n07615190 +n07615460 +n07615569 +n07615671 +n07616590 +n07617188 +n07619004 +n07623136 +n07624466 +n07627931 +n07628068 +n07641928 +n07642471 +n07642933 +n07643306 +n07643474 +n07643764 +n07643981 +n07644244 +n07663899 +n07678729 +n07679356 +n07680517 +n07680932 +n07681926 +n07682316 +n07682624 +n07683786 +n07684600 +n07685730 +n07686873 +n07687211 +n07687469 +n07687789 +n07689003 +n07690273 +n07690892 +n07692405 +n07692614 +n07693889 +n07693972 +n07694403 +n07695878 +n07695965 +n07697100 +n07704054 +n07705931 +n07707451 +n07708512 +n07708798 +n07709333 +n07710007 +n07710283 +n07710616 +n07710952 +n07712063 +n07712382 +n07712748 +n07712856 +n07713395 +n07713895 +n07714078 +n07714802 +n07714895 +n07715561 +n07715721 +n07716034 +n07717070 +n07717858 +n07718671 +n07719437 +n07719839 +n07720442 +n07720615 +n07721325 +n07721456 +n07721678 +n07722217 +n07722763 +n07723330 +n07723559 +n07723753 +n07724943 +n07725376 +n07725531 +n07726796 +n07727578 +n07727868 +n07728804 +n07729000 +n07729485 +n07730406 +n07730855 +n07731122 +n07731587 +n07731952 +n07732302 +n07732747 +n07734017 +n07734292 +n07735052 +n07735803 +n07737081 +n07739125 +n07739506 +n07740220 +n07740954 +n07741461 +n07742012 +n07742704 +n07744246 +n07747055 +n07747811 +n07747951 +n07748753 +n07748912 +n07749095 +n07749192 +n07749312 +n07749731 +n07750586 +n07751451 +n07752377 +n07752664 +n07753743 +n07755089 +n07755411 +n07755707 +n07756096 +n07757132 +n07757312 +n07757602 +n07757990 +n07758680 +n07758950 +n07759424 +n07759691 +n07759816 +n07760501 +n07761141 +n07761309 +n07761611 +n07761777 +n07761954 +n07767344 +n07767847 +n07770571 +n07771212 +n07800091 +n07800740 +n07801508 +n07802152 +n07802417 +n07803093 +n07803545 +n07804323 +n07805254 +n07805594 +n07805731 +n07806221 +n07806633 +n07807317 +n07807710 +n07807922 +n07809096 +n07809368 +n07810907 +n07811416 +n07812184 +n07814203 +n07815588 +n07818277 +n07819480 +n07820497 +n07820814 +n07823951 +n07824702 +n07824988 +n07825717 +n07828987 +n07829412 +n07830593 +n07832902 +n07834507 +n07836731 +n07837002 +n07837362 +n07838233 +n07841495 +n07841639 +n07841907 +n07842753 +n07842972 +n07843464 +n07843775 +n07844042 +n07844604 +n07846143 +n07847198 +n07848338 +n07848771 +n07849336 +n07850083 +n07850329 +n07851298 +n07852045 +n07852919 +n07854813 +n07856270 +n07857959 +n07858595 +n07859284 +n07859583 +n07860805 +n07861158 +n07861813 +n07863374 +n07864638 +n07865105 +n07867421 +n07867883 +n07869391 +n07869775 +n07870313 +n07871436 +n07873464 +n07874063 +n07874159 +n07874259 +n07874343 +n07874441 +n07874780 +n07875693 +n07875835 +n07876281 +n07880751 +n07881117 +n07881205 +n07881404 +n07881800 +n07882497 +n07882886 +n07883031 +n07883251 +n07883384 +n07884567 +n07886572 +n07886849 +n07887634 +n07888465 +n07888909 +n07889510 +n07890352 +n07890750 +n07891726 +n07892813 +n07893528 +n07893891 +n07894102 +n07894298 +n07894965 +n07895237 +n07895435 +n07895595 +n07895710 +n07895839 +n07896287 +n07897200 +n07897865 +n07898117 +n07898333 +n07898745 +n07899108 +n07900406 +n07900616 +n07901587 +n07903208 +n07904395 +n07905038 +n07906284 +n07906877 +n07907161 +n07907548 +n07907943 +n07909129 +n07909811 +n07911371 +n07911677 +n07912211 +n07913393 +n07914413 +n07915618 +n07916041 +n07917618 +n07918028 +n07920222 +n07921455 +n07921948 +n07923748 +n07924033 +n07924560 +n07924834 +n07925966 +n07926920 +n07927197 +n07927931 +n07929519 +n07930554 +n07931001 +n07931096 +n07932614 +n07932841 +n07933274 +n07933891 +n07934032 +n07934530 +n07935152 +n07935504 +n07936263 +n07936745 +n07938149 +n07951464 +n08554440 +n08558963 +n08596076 +n08598301 +n08616050 +n08640531 +n08659446 +n09191635 +n09206896 +n09206985 +n09210862 +n09213434 +n09213565 +n09214060 +n09214916 +n09215437 +n09217230 +n09230041 +n09233446 +n09238926 +n09255070 +n09259025 +n09259219 +n09262690 +n09265620 +n09269882 +n09270735 +n09287968 +n09289331 +n09289596 +n09290444 +n09295946 +n09300306 +n09302616 +n09303008 +n09303528 +n09304750 +n09305031 +n09308572 +n09309292 +n09315159 +n09326662 +n09335693 +n09335809 +n09336555 +n09337253 +n09344198 +n09352849 +n09359803 +n09362945 +n09366017 +n09366317 +n09375606 +n09376526 +n09381242 +n09393605 +n09396465 +n09398677 +n09405787 +n09406793 +n09409512 +n09409752 +n09410224 +n09416076 +n09421799 +n09428628 +n09432990 +n09433442 +n09437454 +n09439213 +n09443641 +n09453008 +n09458269 +n09472413 +n09474010 +n09505153 +n09606009 +n09606527 +n09608709 +n09610405 +n09613191 +n09615336 +n09616922 +n09619168 +n09619452 +n09620078 +n09620794 +n09622049 +n09622302 +n09624168 +n09624559 +n09625401 +n09626238 +n09627906 +n09629246 +n09629752 +n09631129 +n09632274 +n09632518 +n09633969 +n09636339 +n09638875 +n09639919 +n09641002 +n09644152 +n09648743 +n09651123 +n09665545 +n09669631 +n09670280 +n09676884 +n09679925 +n09690208 +n09694771 +n09696585 +n09697401 +n09700964 +n09701148 +n09701833 +n09705124 +n09708750 +n09710164 +n09716047 +n09718217 +n09722658 +n09724785 +n09725229 +n09725772 +n09726621 +n09727440 +n09727826 +n09730204 +n09731436 +n09731571 +n09735258 +n09738400 +n09744679 +n09754217 +n09758173 +n09758885 +n09761068 +n09763784 +n09764201 +n09764598 +n09765278 +n09767197 +n09769076 +n09770179 +n09771435 +n09772746 +n09773962 +n09774783 +n09790482 +n09792555 +n09795124 +n09795334 +n09800964 +n09802445 +n09802641 +n09805151 +n09805475 +n09809538 +n09809749 +n09810166 +n09811712 +n09814660 +n09815790 +n09816771 +n09818022 +n09820263 +n09821831 +n09823502 +n09824135 +n09824609 +n09826204 +n09830194 +n09831962 +n09834699 +n09836160 +n09840217 +n09841188 +n09841515 +n09841696 +n09842047 +n09848489 +n09851575 +n09853645 +n09853881 +n09854915 +n09857007 +n09861946 +n09865398 +n09868270 +n09871681 +n09877951 +n09889691 +n09892693 +n09894654 +n09895222 +n09895701 +n09902353 +n09903153 +n09910374 +n09917593 +n09918248 +n09923418 +n09923673 +n09924996 +n09927089 +n09927451 +n09928136 +n09928451 +n09929298 +n09930257 +n09930876 +n09931640 +n09933098 +n09935434 +n09936892 +n09937056 +n09941964 +n09942970 +n09943239 +n09943811 +n09944160 +n09945319 +n09950457 +n09951070 +n09951274 +n09960688 +n09962966 +n09964411 +n09968845 +n09974648 +n09976728 +n09979321 +n09983572 +n09989502 +n09990415 +n09991867 +n09992538 +n09992837 +n09993252 +n09994673 +n09996481 +n09997622 +n10001217 +n10006748 +n10007684 +n10009484 +n10009671 +n10015215 +n10015897 +n10017422 +n10018861 +n10020890 +n10024362 +n10029068 +n10034201 +n10034614 +n10035952 +n10036266 +n10036929 +n10037385 +n10040945 +n10041887 +n10042690 +n10043643 +n10044879 +n10047459 +n10048367 +n10048836 +n10052694 +n10053808 +n10054657 +n10055730 +n10055847 +n10060175 +n10067968 +n10070711 +n10077593 +n10078131 +n10078806 +n10079399 +n10079893 +n10080869 +n10083823 +n10084043 +n10084295 +n10086383 +n10091651 +n10092488 +n10093475 +n10094584 +n10095869 +n10098710 +n10098862 +n10099375 +n10101634 +n10102800 +n10105085 +n10107303 +n10109662 +n10111903 +n10112129 +n10118844 +n10126177 +n10126424 +n10126708 +n10127689 +n10129825 +n10134396 +n10134982 +n10136959 +n10142747 +n10142946 +n10143172 +n10143725 +n10145340 +n10145774 +n10148305 +n10150071 +n10150940 +n10151570 +n10153594 +n10154186 +n10154601 +n10155849 +n10162194 +n10164233 +n10165448 +n10168183 +n10168584 +n10171567 +n10182190 +n10185793 +n10186774 +n10187130 +n10195593 +n10200781 +n10202624 +n10205457 +n10206173 +n10207169 +n10210137 +n10215623 +n10216106 +n10224578 +n10225219 +n10228278 +n10235385 +n10237069 +n10241300 +n10243664 +n10245639 +n10249270 +n10249459 +n10249950 +n10257221 +n10259348 +n10263411 +n10266328 +n10266848 +n10271677 +n10273064 +n10274815 +n10276045 +n10282672 +n10284064 +n10284965 +n10296444 +n10299250 +n10299700 +n10305635 +n10305802 +n10306004 +n10308732 +n10312287 +n10314054 +n10315561 +n10316360 +n10317007 +n10317500 +n10320863 +n10321340 +n10322238 +n10323999 +n10324560 +n10328437 +n10332385 +n10335246 +n10335931 +n10340312 +n10341573 +n10343554 +n10345100 +n10353016 +n10353355 +n10355142 +n10355449 +n10355688 +n10356450 +n10357613 +n10360747 +n10366966 +n10369528 +n10370381 +n10376523 +n10377021 +n10379376 +n10380672 +n10383816 +n10386984 +n10387196 +n10387324 +n10393909 +n10396106 +n10399130 +n10400998 +n10402824 +n10403876 +n10405694 +n10407954 +n10409752 +n10411551 +n10415037 +n10417551 +n10418101 +n10419047 +n10420031 +n10421016 +n10426454 +n10427764 +n10428004 +n10433737 +n10435716 +n10435988 +n10438172 +n10439851 +n10444194 +n10450303 +n10462860 +n10464052 +n10466918 +n10467179 +n10470779 +n10474064 +n10474645 +n10478960 +n10481268 +n10482054 +n10482921 +n10484858 +n10488309 +n10495421 +n10499355 +n10499857 +n10506544 +n10508710 +n10512372 +n10512708 +n10519494 +n10521100 +n10521662 +n10522035 +n10522324 +n10522759 +n10523341 +n10525134 +n10525436 +n10525617 +n10527334 +n10529231 +n10541833 +n10542888 +n10543161 +n10544232 +n10544748 +n10546633 +n10548537 +n10548681 +n10554846 +n10556518 +n10557854 +n10559288 +n10560637 +n10568200 +n10570019 +n10575787 +n10576962 +n10577284 +n10580535 +n10582746 +n10583387 +n10594147 +n10595164 +n10595647 +n10599806 +n10602985 +n10604634 +n10605253 +n10610465 +n10612210 +n10614629 +n10617193 +n10618685 +n10618848 +n10619642 +n10620758 +n10622053 +n10624074 +n10624310 +n10625860 +n10628644 +n10630188 +n10632576 +n10633450 +n10648237 +n10648696 +n10654932 +n10657835 +n10661002 +n10661563 +n10665698 +n10669991 +n10674130 +n10676018 +n10679174 +n10682953 +n10686073 +n10692883 +n10693824 +n10694258 +n10698368 +n10700201 +n10700640 +n10701180 +n10703336 +n10703692 +n10705615 +n10707233 +n10708454 +n10709529 +n10713686 +n10720453 +n10721321 +n10722575 +n10722965 +n10726786 +n10735298 +n10740868 +n10741152 +n10742997 +n10744164 +n10747119 +n10751265 +n10752480 +n10759151 +n10759982 +n10763383 +n10763620 +n10765679 +n10766260 +n10768903 +n10779610 +n10780632 +n10782791 +n10782940 +n10787470 +n10791221 +n10792335 +n10793570 +n10794014 +n11531193 +n11537327 +n11542640 +n11545524 +n11545714 +n11547562 +n11547855 +n11552386 +n11553240 +n11596108 +n11598686 +n11600372 +n11601177 +n11601918 +n11608250 +n11609475 +n11609684 +n11612923 +n11614250 +n11618861 +n11620673 +n11621029 +n11623105 +n11624531 +n11627168 +n11628456 +n11630017 +n11630489 +n11643835 +n11645914 +n11647306 +n11649878 +n11650558 +n11650759 +n11661372 +n11665372 +n11666854 +n11669921 +n11672400 +n11674332 +n11676500 +n11684264 +n11689483 +n11693981 +n11697560 +n11700864 +n11703669 +n11708658 +n11709674 +n11713164 +n11720353 +n11722982 +n11723770 +n11725015 +n11725623 +n11727091 +n11729478 +n11733054 +n11736694 +n11741350 +n11745817 +n11747468 +n11748002 +n11751765 +n11752578 +n11756092 +n11756669 +n11759224 +n11763625 +n11767354 +n11769621 +n11771539 +n11774513 +n11775340 +n11779300 +n11782036 +n11783920 +n11785668 +n11789438 +n11789962 +n11790788 +n11793779 +n11794519 +n11796005 +n11801392 +n11805956 +n11807108 +n11807979 +n11808721 +n11811473 +n11815491 +n11817914 +n11820965 +n11823043 +n11830714 +n11830906 +n11832214 +n11836722 +n11839568 +n11845557 +n11851578 +n11855274 +n11857696 +n11862835 +n11865071 +n11866248 +n11868814 +n11869351 +n11869689 +n11872146 +n11875691 +n11875938 +n11877473 +n11878283 +n11887119 +n11890022 +n11892637 +n11894327 +n11898639 +n11900569 +n11902709 +n11915214 +n11915658 +n11915899 +n11916467 +n11918286 +n11919447 +n11920498 +n11924445 +n11928352 +n11928858 +n11931918 +n11932745 +n11939699 +n11940006 +n11943407 +n11944196 +n11945367 +n11946727 +n11947251 +n11948264 +n11950345 +n11951511 +n11952346 +n11953884 +n11954484 +n11956850 +n11965627 +n11967744 +n11970101 +n11971248 +n11971783 +n11972759 +n11973341 +n11976170 +n11977303 +n11978233 +n11982115 +n11985053 +n11985739 +n11988893 +n11991263 +n11997032 +n11997969 +n12006766 +n12008252 +n12008749 +n12010628 +n12013511 +n12015959 +n12018760 +n12020507 +n12024176 +n12030654 +n12034141 +n12036067 +n12036939 +n12041446 +n12043444 +n12045860 +n12050959 +n12053405 +n12056217 +n12057447 +n12062468 +n12065316 +n12065777 +n12075151 +n12076577 +n12080395 +n12083591 +n12086012 +n12086539 +n12087961 +n12090890 +n12092262 +n12094244 +n12095020 +n12096395 +n12101870 +n12102133 +n12105125 +n12107970 +n12108432 +n12109827 +n12110778 +n12112008 +n12112918 +n12113657 +n12117017 +n12119099 +n12119238 +n12121033 +n12124627 +n12126360 +n12131550 +n12135898 +n12136720 +n12137120 +n12137569 +n12139575 +n12141495 +n12142085 +n12143676 +n12144313 +n12146311 +n12147226 +n12152532 +n12153580 +n12154773 +n12155583 +n12156819 +n12157056 +n12157769 +n12158031 +n12158798 +n12159055 +n12159555 +n12160490 +n12161285 +n12163035 +n12164363 +n12166424 +n12168565 +n12170585 +n12173664 +n12174311 +n12174926 +n12182049 +n12187663 +n12188289 +n12195391 +n12196129 +n12199266 +n12201580 +n12202936 +n12205694 +n12214789 +n12215579 +n12217453 +n12221191 +n12224978 +n12225349 +n12226932 +n12231192 +n12236546 +n12237486 +n12244153 +n12245695 +n12246232 +n12252168 +n12252866 +n12253229 +n12256112 +n12257570 +n12260799 +n12262553 +n12265394 +n12266217 +n12266796 +n12268246 +n12269241 +n12269652 +n12271643 +n12274630 +n12275489 +n12281241 +n12284262 +n12286826 +n12287642 +n12288823 +n12290748 +n12293723 +n12296432 +n12300840 +n12302071 +n12303462 +n12305475 +n12306717 +n12307756 +n12310349 +n12316444 +n12318378 +n12320010 +n12322501 +n12328398 +n12330469 +n12334293 +n12334891 +n12335483 +n12335664 +n12335800 +n12340383 +n12341542 +n12342299 +n12343480 +n12344283 +n12346578 +n12350758 +n12352287 +n12355760 +n12360108 +n12360684 +n12364604 +n12367611 +n12374418 +n12377198 +n12381511 +n12385429 +n12387633 +n12387839 +n12392070 +n12396924 +n12399132 +n12401335 +n12401684 +n12405714 +n12409231 +n12411461 +n12412355 +n12412606 +n12416423 +n12419037 +n12420535 +n12421467 +n12421683 +n12425281 +n12430198 +n12431434 +n12437513 +n12437769 +n12441958 +n12446200 +n12446519 +n12449296 +n12450344 +n12451915 +n12454159 +n12459629 +n12460697 +n12461466 +n12462032 +n12463743 +n12464476 +n12466727 +n12470092 +n12474167 +n12475035 +n12476510 +n12480895 +n12491826 +n12495146 +n12499163 +n12506181 +n12508309 +n12509476 +n12511856 +n12516584 +n12522188 +n12524188 +n12526516 +n12527738 +n12539074 +n12539306 +n12546183 +n12548280 +n12550210 +n12554526 +n12556656 +n12560282 +n12560775 +n12562577 +n12572546 +n12573256 +n12575322 +n12582231 +n12582665 +n12582846 +n12583126 +n12583401 +n12584191 +n12586298 +n12590232 +n12594989 +n12595964 +n12602262 +n12602980 +n12612170 +n12614477 +n12615710 +n12620196 +n12622875 +n12624381 +n12625383 +n12631331 +n12633638 +n12634211 +n12634429 +n12635744 +n12636885 +n12638218 +n12638556 +n12639736 +n12640607 +n12641413 +n12641931 +n12642200 +n12643473 +n12644902 +n12645174 +n12647376 +n12649065 +n12650556 +n12651821 +n12653218 +n12655869 +n12658118 +n12658846 +n12659356 +n12660601 +n12662772 +n12663804 +n12665048 +n12667406 +n12667964 +n12674120 +n12674685 +n12682411 +n12683407 +n12685431 +n12685831 +n12688716 +n12690653 +n12695144 +n12698435 +n12705013 +n12707781 +n12708293 +n12709901 +n12711596 +n12713063 +n12714755 +n12715914 +n12717072 +n12719684 +n12724942 +n12725521 +n12727301 +n12731401 +n12732491 +n12732756 +n12733647 +n12741222 +n12742741 +n12743823 +n12746884 +n12749049 +n12752205 +n12755225 +n12756457 +n12762896 +n12768369 +n12771192 +n12772753 +n12777436 +n12778605 +n12779603 +n12785724 +n12791064 +n12793015 +n12794985 +n12798284 +n12800586 +n12801520 +n12805146 +n12806732 +n12810595 +n12812235 +n12814643 +n12817464 +n12822769 +n12823717 +n12823859 +n12832315 +n12833985 +n12834798 +n12836212 +n12836862 +n12839979 +n12840749 +n12842302 +n12842887 +n12844939 +n12849061 +n12853080 +n12854048 +n12858150 +n12866968 +n12869478 +n12870535 +n12871272 +n12877244 +n12878169 +n12879963 +n12882779 +n12884260 +n12890265 +n12893463 +n12903367 +n12904938 +n12908645 +n12909421 +n12912670 +n12917901 +n12922763 +n12926480 +n12928071 +n12929403 +n12930778 +n12931906 +n12934036 +n12934479 +n12939104 +n12941536 +n12942395 +n12943443 +n12946849 +n12950126 +n12952165 +n12953206 +n12956170 +n12957608 +n12960378 +n12960863 +n12965626 +n12968136 +n12969131 +n12970193 +n12971400 +n12973791 +n12974987 +n12976198 +n12980840 +n12982468 +n12983961 +n12985773 +n12987056 +n12988158 +n12992868 +n12997654 +n12997919 +n13000891 +n13001041 +n13001206 +n13001366 +n13001529 +n13002750 +n13002925 +n13003061 +n13003254 +n13003522 +n13003712 +n13004423 +n13004640 +n13004826 +n13004992 +n13005329 +n13005984 +n13006171 +n13006631 +n13006894 +n13007417 +n13007629 +n13008157 +n13008315 +n13008485 +n13008689 +n13008839 +n13009085 +n13009244 +n13009429 +n13009656 +n13010694 +n13010951 +n13011221 +n13012253 +n13012469 +n13012973 +n13013534 +n13013764 +n13013965 +n13014097 +n13014265 +n13014409 +n13014581 +n13014741 +n13014879 +n13017102 +n13017240 +n13017439 +n13017610 +n13017789 +n13017979 +n13018088 +n13018232 +n13018407 +n13019496 +n13019643 +n13019835 +n13020191 +n13020481 +n13020964 +n13021166 +n13021332 +n13021543 +n13021689 +n13021867 +n13022210 +n13022709 +n13024012 +n13024500 +n13025647 +n13028611 +n13032115 +n13032923 +n13035241 +n13035389 +n13035707 +n13037585 +n13037805 +n13038068 +n13038376 +n13038744 +n13039349 +n13040629 +n13040796 +n13041312 +n13042982 +n13043926 +n13045210 +n13045975 +n13046130 +n13049953 +n13055423 +n13055577 +n13055792 +n13055949 +n13056135 +n13056349 +n13056607 +n13056799 +n13057054 +n13057242 +n13057422 +n13057639 +n13058037 +n13058272 +n13058608 +n13059298 +n13059657 +n13060017 +n13060190 +n13063269 +n13066129 +n13067191 +n13068917 +n13070308 +n13070875 +n13071371 +n13071553 +n13071815 +n13072031 +n13072209 +n13072350 +n13072528 +n13072706 +n13072863 +n13073055 +n13073703 +n13074619 +n13074814 +n13075020 +n13075272 +n13075441 +n13075684 +n13075847 +n13076041 +n13076405 +n13076643 +n13076831 +n13077033 +n13077295 +n13079419 +n13083023 +n13084184 +n13085113 +n13091620 +n13091774 +n13100156 +n13100677 +n13104059 +n13108131 +n13108662 +n13108841 +n13109733 +n13110915 +n13111174 +n13111881 +n13118707 +n13119870 +n13120211 +n13121104 +n13122364 +n13123431 +n13125117 +n13130161 +n13130726 +n13132034 +n13132338 +n13132486 +n13132940 +n13134302 +n13134947 +n13135832 +n13136316 +n13136556 +n13137409 +n13137672 +n13138308 +n13138658 +n13138842 +n13139055 +n13139647 +n13141141 +n13145444 +n13149296 +n13150894 +n13154841 +n13156986 +n13157137 +n13160831 +n13163991 +n13172923 +n13174670 +n13177529 +n13180534 +n13186388 +n13188096 +n13188268 +n13192625 +n13193642 +n13194572 +n13195761 +n13199970 +n13201969 +n13206817 +n13207736 +n13208705 +n13211790 +n13219422 +n13221529 +n13224673 +n13230662 +n13231678 +n13231919 +n13232106 +n13232363 +n13232779 +n13233727 +n13238375 +n13238988 +n13252672 +n13862780 +n13863186 +n13863473 +n13863771 +n13864153 +n13864965 +n13865298 +n13865483 +n13866144 +n13866827 +n13867492 +n13868248 +n13868371 +n13872592 +n13873502 +n13875392 +n13875571 +n13878306 +n13879320 +n13883603 +n13888491 +n13893786 +n13894434 +n13896100 +n13897996 +n13900287 +n13903079 +n13905121 +n13905275 +n13905792 +n13912260 +n13915999 +n14633206 +n14696793 +n14844693 +n14853210 +n14899328 +n14900184 +n14974264 +n14977504 +n14992287 +n15062057 +n15067877 +n15089258 +n15089472 +n15089645 +n15089803 +n15090742 +n15092409 +n15092751 diff --git a/data/imagenet.shortnames.list b/data/imagenet.shortnames.list new file mode 100644 index 0000000..e9600eb --- /dev/null +++ b/data/imagenet.shortnames.list @@ -0,0 +1,21842 @@ +kit fox +English setter +Siberian husky +Australian terrier +English springer +grey whale +lesser panda +Egyptian cat +ibex +Persian cat +cougar +gazelle +porcupine +sea lion +malamute +badger +Great Dane +Walker hound +Welsh springer spaniel +whippet +Scottish deerhound +killer whale +mink +African elephant +Weimaraner +soft-coated wheaten terrier +Dandie Dinmont +red wolf +Old English sheepdog +jaguar +otterhound +bloodhound +Airedale +hyena +meerkat +giant schnauzer +titi +three-toed sloth +sorrel +black-footed ferret +dalmatian +black-and-tan coonhound +papillon +skunk +Staffordshire bullterrier +Mexican hairless +Bouvier des Flandres +weasel +miniature poodle +Cardigan +malinois +bighorn +fox squirrel +colobus +tiger cat +Lhasa +impala +coyote +Yorkshire terrier +Newfoundland +brown bear +red fox +Norwegian elkhound +Rottweiler +hartebeest +Saluki +grey fox +schipperke +Pekinese +Brabancon griffon +West Highland white terrier +Sealyham terrier +guenon +mongoose +indri +tiger +Irish wolfhound +wild boar +EntleBucher +zebra +ram +French bulldog +orangutan +basenji +leopard +Bernese mountain dog +Maltese dog +Norfolk terrier +toy terrier +vizsla +cairn +squirrel monkey +groenendael +clumber +Siamese cat +chimpanzee +komondor +Afghan hound +Japanese spaniel +proboscis monkey +guinea pig +white wolf +ice bear +gorilla +borzoi +toy poodle +Kerry blue terrier +ox +Scotch terrier +Tibetan mastiff +spider monkey +Doberman +Boston bull +Greater Swiss Mountain dog +Appenzeller +Shih-Tzu +Irish water spaniel +Pomeranian +Bedlington terrier +warthog +Arabian camel +siamang +miniature schnauzer +collie +golden retriever +Irish terrier +affenpinscher +Border collie +hare +boxer +silky terrier +beagle +Leonberg +German short-haired pointer +patas +dhole +baboon +macaque +Chesapeake Bay retriever +bull mastiff +kuvasz +capuchin +pug +curly-coated retriever +Norwich terrier +flat-coated retriever +hog +keeshond +Eskimo dog +Brittany spaniel +standard poodle +Lakeland terrier +snow leopard +Gordon setter +dingo +standard schnauzer +hamster +Tibetan terrier +Arctic fox +wire-haired fox terrier +basset +water buffalo +American black bear +Angora +bison +howler monkey +hippopotamus +chow +giant panda +American Staffordshire terrier +Shetland sheepdog +Great Pyrenees +Chihuahua +tabby +marmoset +Labrador retriever +Saint Bernard +armadillo +Samoyed +bluetick +redbone +polecat +marmot +kelpie +gibbon +llama +miniature pinscher +wood rabbit +Italian greyhound +lion +cocker spaniel +Irish setter +dugong +Indian elephant +beaver +Sussex spaniel +Pembroke +Blenheim spaniel +Madagascar cat +Rhodesian ridgeback +lynx +African hunting dog +langur +Ibizan hound +timber wolf +cheetah +English foxhound +briard +sloth bear +Border terrier +German shepherd +otter +koala +tusker +echidna +wallaby +platypus +wombat +revolver +umbrella +schooner +soccer ball +accordion +ant +starfish +chambered nautilus +grand piano +laptop +strawberry +airliner +warplane +airship +balloon +space shuttle +fireboat +gondola +speedboat +lifeboat +canoe +yawl +catamaran +trimaran +container ship +liner +pirate +aircraft carrier +submarine +wreck +half track +tank +missile +bobsled +dogsled +bicycle-built-for-two +mountain bike +freight car +passenger car +barrow +shopping cart +motor scooter +forklift +electric locomotive +steam locomotive +amphibian +ambulance +beach wagon +cab +convertible +jeep +limousine +minivan +Model T +racer +sports car +go-kart +golfcart +moped +snowplow +fire engine +garbage truck +pickup +tow truck +trailer truck +moving van +police van +recreational vehicle +streetcar +snowmobile +tractor +mobile home +tricycle +unicycle +horse cart +jinrikisha +oxcart +bassinet +cradle +crib +four-poster +bookcase +china cabinet +medicine chest +chiffonier +table lamp +file +park bench +barber chair +throne +folding chair +rocking chair +studio couch +toilet seat +desk +pool table +dining table +entertainment center +wardrobe +Granny Smith +orange +lemon +fig +pineapple +banana +jackfruit +custard apple +pomegranate +acorn +hip +ear +rapeseed +corn +buckeye +organ +upright +chime +drum +gong +maraca +marimba +steel drum +banjo +cello +violin +harp +acoustic guitar +electric guitar +cornet +French horn +trombone +harmonica +ocarina +panpipe +bassoon +oboe +sax +flute +daisy +yellow lady's slipper +cliff +valley +alp +volcano +promontory +sandbar +coral reef +lakeside +seashore +geyser +hatchet +cleaver +letter opener +plane +power drill +lawn mower +hammer +corkscrew +can opener +plunger +screwdriver +shovel +plow +chain saw +cock +hen +ostrich +brambling +goldfinch +house finch +junco +indigo bunting +robin +bulbul +jay +magpie +chickadee +water ouzel +kite +bald eagle +vulture +great grey owl +black grouse +ptarmigan +ruffed grouse +prairie chicken +peacock +quail +partridge +African grey +macaw +sulphur-crested cockatoo +lorikeet +coucal +bee eater +hornbill +hummingbird +jacamar +toucan +drake +red-breasted merganser +goose +black swan +white stork +black stork +spoonbill +flamingo +American egret +little blue heron +bittern +crane +limpkin +American coot +bustard +ruddy turnstone +red-backed sandpiper +redshank +dowitcher +oystercatcher +European gallinule +pelican +king penguin +albatross +great white shark +tiger shark +hammerhead +electric ray +stingray +barracouta +coho +tench +goldfish +eel +rock beauty +anemone fish +lionfish +puffer +sturgeon +gar +loggerhead +leatherback turtle +mud turtle +terrapin +box turtle +banded gecko +common iguana +American chameleon +whiptail +agama +frilled lizard +alligator lizard +Gila monster +green lizard +African chameleon +Komodo dragon +triceratops +African crocodile +American alligator +thunder snake +ringneck snake +hognose snake +green snake +king snake +garter snake +water snake +vine snake +night snake +boa constrictor +rock python +Indian cobra +green mamba +sea snake +horned viper +diamondback +sidewinder +European fire salamander +common newt +eft +spotted salamander +axolotl +bullfrog +tree frog +tailed frog +whistle +wing +paintbrush +hand blower +oxygen mask +snorkel +loudspeaker +microphone +screen +mouse +electric fan +oil filter +strainer +space heater +stove +guillotine +barometer +rule +odometer +scale +analog clock +digital clock +wall clock +hourglass +sundial +parking meter +stopwatch +digital watch +stethoscope +syringe +magnetic compass +binoculars +projector +sunglasses +loupe +radio telescope +bow +cannon +assault rifle +rifle +projectile +computer keyboard +typewriter keyboard +crane +lighter +abacus +cash machine +slide rule +desktop computer +hand-held computer +notebook +web site +harvester +thresher +printer +slot +vending machine +sewing machine +joystick +switch +hook +car wheel +paddlewheel +pinwheel +potter's wheel +gas pump +carousel +swing +reel +radiator +puck +hard disc +sunglass +pick +car mirror +solar dish +remote control +disk brake +buckle +hair slide +knot +combination lock +padlock +nail +safety pin +screw +muzzle +seat belt +ski +candle +jack-o'-lantern +spotlight +torch +neck brace +pier +tripod +maypole +mousetrap +spider web +trilobite +harvestman +scorpion +black and gold garden spider +barn spider +garden spider +black widow +tarantula +wolf spider +tick +centipede +isopod +Dungeness crab +rock crab +fiddler crab +king crab +American lobster +spiny lobster +crayfish +hermit crab +tiger beetle +ladybug +ground beetle +long-horned beetle +leaf beetle +dung beetle +rhinoceros beetle +weevil +fly +bee +grasshopper +cricket +walking stick +cockroach +mantis +cicada +leafhopper +lacewing +dragonfly +damselfly +admiral +ringlet +monarch +cabbage butterfly +sulphur butterfly +lycaenid +jellyfish +sea anemone +brain coral +flatworm +nematode +conch +snail +slug +sea slug +chiton +sea urchin +sea cucumber +iron +espresso maker +microwave +Dutch oven +rotisserie +toaster +waffle iron +vacuum +dishwasher +refrigerator +washer +Crock Pot +frying pan +wok +caldron +coffeepot +teapot +spatula +altar +triumphal arch +patio +steel arch bridge +suspension bridge +viaduct +barn +greenhouse +palace +monastery +library +apiary +boathouse +church +mosque +stupa +planetarium +restaurant +cinema +home theater +lumbermill +coil +obelisk +totem pole +castle +prison +grocery store +bakery +barbershop +bookshop +butcher shop +confectionery +shoe shop +tobacco shop +toyshop +fountain +cliff dwelling +yurt +dock +brass +megalith +bannister +breakwater +dam +chainlink fence +picket fence +worm fence +stone wall +grille +sliding door +turnstile +mountain tent +scoreboard +honeycomb +plate rack +pedestal +beacon +mashed potato +bell pepper +head cabbage +broccoli +cauliflower +zucchini +spaghetti squash +acorn squash +butternut squash +cucumber +artichoke +cardoon +mushroom +shower curtain +jean +carton +handkerchief +sandal +ashcan +safe +plate +necklace +croquet ball +fur coat +thimble +pajama +running shoe +cocktail shaker +chest +manhole cover +modem +tub +tray +balance beam +bagel +prayer rug +kimono +hot pot +whiskey jug +knee pad +book jacket +spindle +ski mask +beer bottle +crash helmet +bottlecap +tile roof +mask +maillot +Petri dish +football helmet +bathing cap +teddy +holster +pop bottle +photocopier +vestment +crossword puzzle +golf ball +trifle +suit +water tower +feather boa +cloak +red wine +drumstick +shield +Christmas stocking +hoopskirt +menu +stage +bonnet +meat loaf +baseball +face powder +scabbard +sunscreen +beer glass +hen-of-the-woods +guacamole +lampshade +wool +hay +bow tie +mailbag +water jug +bucket +dishrag +soup bowl +eggnog +mortar +trench coat +paddle +chain +swab +mixing bowl +potpie +wine bottle +shoji +bulletproof vest +drilling platform +binder +cardigan +sweatshirt +pot +birdhouse +hamper +ping-pong ball +pencil box +pay-phone +consomme +apron +punching bag +backpack +groom +bearskin +pencil sharpener +broom +mosquito net +abaya +mortarboard +poncho +crutch +Polaroid camera +space bar +cup +racket +traffic light +quill +radio +dough +cuirass +military uniform +lipstick +shower cap +monitor +oscilloscope +mitten +brassiere +French loaf +vase +milk can +rugby ball +paper towel +earthstar +envelope +miniskirt +cowboy hat +trolleybus +perfume +bathtub +hotdog +coral fungus +bullet train +pillow +toilet tissue +cassette +carpenter's kit +ladle +stinkhorn +lotion +hair spray +academic gown +dome +crate +wig +burrito +pill bottle +chain mail +theater curtain +window shade +barrel +washbasin +ballpoint +basketball +bath towel +cowboy boot +gown +window screen +agaric +cellular telephone +nipple +barbell +mailbox +lab coat +fire screen +minibus +packet +maze +pole +horizontal bar +sombrero +pickelhaube +rain barrel +wallet +cassette player +comic book +piggy bank +street sign +bell cote +fountain pen +Windsor tie +volleyball +overskirt +sarong +purse +bolo tie +bib +parachute +sleeping bag +television +swimming trunks +measuring cup +espresso +pizza +breastplate +shopping basket +wooden spoon +saltshaker +chocolate sauce +ballplayer +goblet +gyromitra +stretcher +water bottle +dial telephone +soap dispenser +jersey +school bus +jigsaw puzzle +plastic bag +reflex camera +diaper +Band Aid +ice lolly +velvet +tennis ball +gasmask +doormat +Loafer +ice cream +pretzel +quilt +maillot +tape player +clog +iPod +bolete +scuba diver +pitcher +matchstick +bikini +sock +CD player +lens cap +thatch +vault +beaker +bubble +cheeseburger +parallel bars +flagpole +coffee mug +rubber eraser +stole +carbonara +dumbbell +singles +Virginia deer +eastern grey squirrel +gelding +pylon +table-tennis table +peacock +Segway +surfing +tamandua +knocker +steering wheel +motorcycling +coati +sitar +range +backhoe +agaric +dashboard +water polo +concrete mixer +treadmill +golf bag +skateboarding +royal tennis +tartan +four-wheel drive +sport utility +sedan +print +luggage rack +softball +windmill +ben +red admiral +jalousie +towel rail +truss +strand +ice hockey +sconce +wind turbine +plush +stained-glass window +ballpark +thoroughbred +love seat +red-spotted purple +miller +Adelie +freight liner +clock tower +acrobatics +shaving brush +ewe +ottoman +African violet +bicycle wheel +cork +windmill +satin +comma +coffee mill +baggage +wasp's nest +batting glove +Ferris wheel +push-bike +porthole +football stadium +gas tank +barbecue +handlebar +hula-hoop +fairground +rapier +garter stitch +exercise bike +control tower +carryall +minute hand +cog +riverbank +water nymph +common dandelion +android +hairbrush +redberry +fret +display window +pepper mill +litterbin +drapery +ducking +fly-fishing +broad jump +sprinkler +water-skiing +chicory +sail +volleyball +rugby +Texas bluebonnet +computer monitor +tortoiseshell +airplane propeller +solar array +figure skating +air conditioner +purple loosestrife +gearshift +outboard motor +cowslip +Abyssinian +dip +workstation +cosy +bunker +neon lamp +campanile +casket +verbena +amphora +sumo +common foxglove +sprocket +jelly bean +emperor penguin +night-blooming cereus +clock radio +black birch +bomber jacket +Virginia bluebell +bayonet +walker +altarpiece +tattoo +bridle +rocker arm +water turkey +spiderwort +flange +mute swan +laser printer +carburetor +coverlet +mountainside +baritone +auto racing +baluster +gal +peach bells +taffeta +grandfather +asparagus +horizontal stabilizer +world +grate +marsh marigold +white rhinoceros +movement +split rail +rollerblading +longhorn +muffler +church tower +light bulb +American agave +backpacking tent +overall +New World goldfinch +sectional +wing chair +transom +integrated circuit +dad +spar +picture frame +no-hit game +alternator +drill press +strawflower +hepatica +rangefinder +blinker +Welsh pony +nib +wagon wheel +rotor +tie +denim +jetliner +sculling +external drive +window frame +mourning dove +censer +stapler +batting helmet +flagon +machete +windshield +hedgehog +weeping willow +chief executive officer +hepatica +pet +Asiatic black bear +chinchilla +uke +Atlantic bottlenose dolphin +hair +dishtowel +flintlock +Bermuda shorts +lavender +searchlight +millwheel +piano keyboard +luna moth +bumper +parrot +skirt +manhole +coffee table +footstool +judo +Dalai Lama +armored personnel carrier +voile +saber +thoroughbred +wild carrot +gemsbok +caster +butterfly orchid +cow +sideboard +horseshoe crab +match play +cassette recorder +photomicrograph +drafting table +pediment +tramline +shipping +kitten +wainscoting +fried rice +helix +marguerite +pumpkin +white-bellied swallow +Tulipa gesneriana +common dolphin +face +red squirrel +bicycling +shipwreck +banded purple +cornice +pendant earring +forsythia +aardvark +seashell +spat +shoulder bag +fallow deer +yearling +common teasel +tufted titmouse +ancient +professional golf +purl +vehicle +okra +great grandmother +common lilac +rose mallow +newspaper +crucifix +chukka +armlet +fulmar +wapiti +doily +Greco-Roman wrestling +bleeding heart +kitchen table +bluebonnet +Cape buffalo +spun yarn +crape myrtle +dewdrop +great blue heron +medalist +vaulting horse +spinning wheel +skyscraper +Tahitian +forget-me-not +watercourse +guitarist +gargoyle +bee balm +pumpkin +hunting knife +flutist +lectern +skateboarder +foil +pant leg +hedge sparrow +dresser +automatic pistol +chicory +dialog box +chamberpot +black rhinoceros +fireweed +half-mast +pillow sham +pavilion +scarf joint +microprocessor +filly +dressing gown +shell +Arabian +child +radio antenna +butterweed +morris dancer +sparrow hawk +groom +brioche +floret +rainbow +earthworm +cellist +tine +toupee +balldress +map +angel's trumpet +ruin +fur +pronghorn +speed skating +used-car +stick +early spider orchid +stuffed peppers +snowdrift +flats +least sandpiper +stick +console table +ventilator +portable +kepi +pylon +viceroy +shoreline +Olympian Zeus +pestle +great-niece +life +air compressor +fanjet +scuba diving +fieldfare +tree swallow +personnel carrier +night-blooming cereus +sonogram +assembly hall +circuit breaker +chair +speed skate +soapwort +worsted +raspberry +burlap +flat panel display +Pyracantha +cemetery +turban +deer hunting +bottle green +dandelion green +pieta +aigrette +turntable +cover girl +clutch bag +kiwi +pea jacket +color guard +Malay +shire +crock +french fries +credenza +hockey stick +mourning cloak +potty seat +glass +balsamroot +medal play +red clover +gravy boat +garter belt +Guinness +meadow buttercup +jackass penguin +coursing +tooth +hawfinch +housetop +fluorescent lamp +black-backed gull +bookshelf +earplug +millipede +fawn +baseball bat +soup-strainer +organ loft +bugloss +tomahawk +blackcap +black-necked stilt +hand truck +bedstead +tempura +rose window +crimson +snow thrower +lesser whitethroat +palomino +ball +staff sergeant +wicker +garbage heap +great-nephew +parquet +coupe +nave +eggs Benedict +damask +flush toilet +Angora +pedometer +control room +bristle brush +kookaburra +telephone booth +Windsor chair +red-winged blackbird +cinnamon roll +briefs +cloister +sundress +mammillaria +unicyclist +covered bridge +coelogyne +fairy bluebird +phoebe +beer mug +headstock +parhelion +gorse +common European dogwood +fire-eater +professional football +rock climbing +cyclamen +tin +marjoram +Japanese morning glory +pipe +smasher +hang glider +abutment +birdbath +jotter +litter +artist's model +butterfly bush +dining area +sausage dog +piggery +English sparrow +Turk's-cap +platinum blond +song sparrow +alarm clock +tortoiseshell +chaise longue +flintlock +academic costume +graffito +Arnica montana +adding machine +waterside +director +jonquil +pipefitting +stud +Swedish meatball +musk rose +Venus's flytrap +raven +bougainvillea +little brother +field bindweed +finder +white admiral +tinfoil +serval +sheet +carthorse +people +potto +stockroom +sphinx +slate roof +mountain laurel +majolica +coal black +repository +bufo +pique +binder +tread +attorney general +hydraulic press +videocassette recorder +bumper car +professional baseball +cow parsley +ern +blue peafowl +common hyacinth +jack-in-the-pulpit +ice hockey rink +sport +camper +tailback +flash +stacks +pulp +Christmas cactus +netball +calliandra +curler +large periwinkle +cobweb +forward +Roman arch +cross bun +stoneware +banana bread +cape jasmine +settle +tongue +frock +pepper shaker +pitching coach +CD-R +casing +faience +hand cream +CD-ROM +recliner +striped bass +clary +sketch +risotto +reticle +white clover +touch football +kitty +great-aunt +Japanese maple +sidecar +muscovy duck +hack +rope bridge +organist +stinging nettle +pocket watch +Indian pipe +amorphophallus +bird's-foot violet +caller ID +furnishing +carriageway +dish rack +heiress +nail polish +beldam +Dall sheep +teriyaki +stateroom +laughing gull +chow +bookmark +timer +toga virilis +deviled egg +coltsfoot +Papuan +native +cygnet +automation +portfolio +cabbage palm +cube +broiler +radish +broodmare +castor-oil plant +pith hat +talus +lass +thatch +common marigold +young buck +igloo +prairie rattlesnake +soccer player +spoke +place +slide fastener +tapestry +toy +headboard +cross-country skiing +harness +sconce +rim +ballet skirt +transvestite +saddlebag +common evening primrose +taillight +challah +willet +ready-to-wear +cloud +answering machine +waterfront +vane +granddaughter +Chinese gooseberry +tureen +cab +truffle +viola +bootlace +chemise +taro +petal +candied apple +soccer +miniature golf +front porch +asparagus +Sauvignon blanc +daisy fleabane +ceiling +slip-on +bottle-nosed whale +redbud +black squirrel +snowsuit +ribbing +gravestone +creme brulee +ambassador +local +archery +love-in-a-mist +garbage +thyme +night-blooming cereus +goshawk +cuckoopint +azure +German iris +salad bowl +puppy +cockhorse +giant clam +biplane +stele +necklet +sea otter +crest +door +reformer +comforter +Byelorussian +bottle +hemline +book bag +leotard +owlet +spoon +sari +bidet +Latin +reticulated python +bowling shoe +futon +gaiter +coypu +tea urn +waders +bangle +snowbank +pencil +porter +azalea +English lavender +red spruce +team sport +cruet +high-rise +O ring +vodka +cormorant +Canada thistle +clasp +showjumping +rattan +red fox +sun parlor +Charolais +Tommy gun +bird's foot trefoil +sedge warbler +knot +chives +car tire +steam engine +adapter +spirea +common allamanda +oyster shell +harbor seal +baobab +wick +plumbago +downy woodpecker +coconut +leash +kasbah +hour hand +upholstery +mallard +cricket bat +lady +kitchenware +right-hander +leopard +olive green +common valerian +blue whale +blackboard +redhead +periwinkle +fingerboard +hard hat +locker +breakfast table +capybara +beekeeper +harness +feeder +water hyacinth +hexapod +brown thrasher +percale +lever +patriarch +arete +book +book +senator +bunya bunya +couch +durian +common lady's-slipper +mountain ash +golden barrel cactus +bicycle seat +beret +pop +musk mallow +manatee +cotton candy +boxing glove +backboard +tongue +saguaro +playground +capitol +sanderling +wagtail +deputy +tractor +tap +lady's smock +noseband +worsted +radiotelephone +camisole +forelock +muscat +sweet scabious +crane fly +butterfly weed +chestnut +pinata +inositol +borage +aquatic +belly +broadcaster +gondolier +egg yolk +blush wine +bufflehead +rambutan +oleander +horse-trail +sea holly +yard bird +conference room +lacrosse +belted kingfisher +defile +extremum +whistle +bear cub +grainfield +potage +watermelon +lasagna +sheik +Cooper's hawk +bulb +basketball court +paella +cassette tape +scatter rug +kid +impala lily +Minnesotan +Sudanese +chocolate +tail +quack-quack +whistling swan +shoulder patch +frozen custard +sumo wrestler +smoothie +bock +meat grinder +latch +palisade +radial +sake +kestrel +corn chowder +airframe +electrician +reamer +metropolitan +cotton flannel +cassowary +crossbill +operating room +winter aconite +flute +Tasmanian devil +billboard +suds +kilt +aperitif +cooling tower +avocado +hooded merganser +coleslaw +bee balm +ladder-back +insurance broker +scaffolding +polo mallet +double bed +two-hitter +bluff +gamboge +baby +lawn chair +frond +pistol grip +fancy dress +marquetry +jambalaya +fireweed +Eurasian kingfisher +cue ball +ice plant +horseweed +rose moss +musher +sun +viscount +white-breasted nuthatch +gin and tonic +thermos +Kenyan +first-aid kit +four-wheeler +tourist +stairwell +Gambian +liqueur glass +hovercraft +cocktail dress +twin +coriander +blister pack +Barrow's goldeneye +canteen +irrigation ditch +great white heron +tree sparrow +canal boat +lens +food processor +common raccoon +Baltimore oriole +black-eyed Susan +bush hibiscus +corolla +sire +mustachio +professional wrestling +elk +clustered bellflower +pannier +musk ox +crapaud +animal trainer +rosebud +ring-necked pheasant +little egret +cappuccino +rocker +bristlecone pine +cheerleader +hedge violet +semaphore +central processing unit +speedskater +delivery truck +assembly +hedgehog cactus +bergenia +bull thistle +bladder campion +cinquefoil +inula +cellulose tape +main rotor +bootee +autogiro +ice +grey +meadow cranesbill +hummus +valise +chassis +mountain goat +blacktail prairie dog +Chardonnay +romper +street +shoveler +wood ibis +topiary +chalice +silo +circus acrobat +Rollerblade +cosmos +woof +heroine +cold cream +marabou +herb robert +garden lettuce +nymph +floor lamp +automobile engine +heel +radiator +seeded player +fedora +father-in-law +peahen +Bahamian +wiper +wood pigeon +barn owl +pegboard +chorus frog +kin +roller skate +stob +rosemary +cowbird +hortensia +cranberry sauce +shot glass +Dixie cup +gnu +fire alarm +diet +booster +oxeye daisy +twayblade +high-definition television +truss bridge +bunk bed +mule +blackbuck +facsimile +frog orchid +point-and-shoot camera +brocade +gazebo +prairie gentian +concert +paintball +Cognac +maid +afghan +barbecued spareribs +pintail +tramway +commissioner +finger-painting +beef stew +caftan +Aberdeen Angus +demonstrator +sea trout +pigtail +thrush nightingale +barbados cherry +sashimi +ridgeling +lamppost +gabardine +red-shouldered hawk +bath salts +cavern +cymbid +Haitian +boater +southern buckthorn +arctic +motorcycle cop +red gum +Clydesdale +Zamboni +beagling +villa +demitasse +Sheetrock +lollipop +hybrid petunia +post horse +carabiner +brussels sprouts +Durham +stylist +pothole +sleigh bed +scallop shell +harrier eagle +papaya +Japanese persimmon +sachet +wild rice +chipboard +gun enclosure +menorah +chinook +headset +white campion +ocean +Secretary of State +G-string +bone china +basil +greenish blue +camcorder +concrete +screech owl +trumpet honeysuckle +flugelhorn +layette +cattle egret +case knife +mandarin duck +robber fly +salwar +dressing table +doughnut +facade +runner +honeypot +surf casting +diver +angel's trumpet +spin dryer +chameleon +wand +snow +vitamin A1 +manageress +volleyball net +antiperspirant +street clothes +tree sparrow +cords +sundew +bricks and mortar +caryatid +bridesmaid +trestle bridge +eyepiece +celebrant +scarlet pimpernel +gas range +onion +green salad +squill +creepy-crawly +hunk +little owl +salad nicoise +earflap +bird feeder +spray gun +bunny +Cheops +amazon +blue tit +Nissen hut +Kalashnikov +skylark +kremlin +shoebill +shopping bag +frigate bird +telephoto lens +peplum +moss pink +echidna +wastepaper basket +wood ibis +workroom +ankle brace +telpherage +Michaelmas daisy +figure skate +swami +nylons +cardoon +cocotte +headstall +twin bed +parsley +dirndl +corn poppy +nut bread +cloche +light heavyweight +mayor +lip-gloss +punch bowl +pottage +mango +fledgling +mousse +four-wheel drive +barrel +banana boat +trouser +bathroom +Sauterne +ring +settee +lavaliere +safe-deposit +godson +leatherette +schoolmate +radish +hedge trimmer +dahlia +euphonium +palace +vaulter +singlet +slicer +Pilsner +cockateel +kangaroo paw +Cub Scout +master bedroom +hexagon +cenotaph +Barberton daisy +Netherlander +intersection +Korean +gravel +chandelier +hospital bed +flash memory +pier +whole wheat flour +maroon +pale ale +special +snow bunting +crinoline +dustpan +barrette +common wood sorrel +yolk +pothos +speakerphone +tendril +cabinetwork +farm horse +brake disk +streetlight +superhighway +bandsaw +panting +pressure cooker +girdle +old man +cereal bowl +felt +hurling +architecture +harmonium +chain +blueberry +cellar +smocking +scrub brush +tablespoon +sweet corn +graining +library +street +bill +felt-tip pen +monkshood +crowd +log cabin +newel post +hack +elephant seal +golden pothos +popcorn +outhouse +patch pocket +fish and chips +tape +wax plant +eaves +fried egg +emerald +tea cart +fan blade +daily +Bowie knife +rowing boat +leaf shape +man +crayon +trumpetfish +chipping sparrow +whiskey bottle +pillion +city hall +golden pheasant +cheerleader +creeping bugle +couch +Dumpster +Homo sapiens sapiens +cranberry juice +cockpit +demagogue +joinery +scrambled eggs +technician +sidewalk +sheep +keyhole +power line +polyanthus +roulette +first lieutenant +checkout +tabletop +nasturtium +schnapps +engineering +skateboard +ground fir +bouquet +bunk +resort area +fleur-de-lis +power steering +opera +Bolivian +Friesian +buckskins +bay +slider +frozen yogurt +cabin cruiser +saunterer +lean-to +fishing eagle +bog star +cantaloupe +mouth +music stand +fiddlestick +brilliantine +pinball machine +bairn +barred owl +bath oil +signorina +Mason jar +nymph +rubber band +garden nasturtium +razorbill +Japanese beetle +batting cage +trestle +borage +Secretary of the Interior +scanner +baguet +baseball cap +chow mein +pen +jewelweed +barbet +chasm +pectoral sandpiper +holster +glasses case +sand +crevice +Kickapoo +snowboard +locket +satchel +tankard +alpinist +moorhen +cow pen +whooper +crown +chain +silversword +wild geranium +hi-fi +Tibetan +waterwheel +bee orchid +ruby-crowned kinglet +common broom +tabloid +javelin +sauna +klammath weed +zebra finch +spider orchid +velour +chiffon +lecture room +barrel +loggia +millstone +flatlet +soupspoon +econometrician +golf-club head +daphnia +parlor +fire-eater +juggler +attache case +hay bale +kisser +knitting needle +news magazine +flatbed +Senegalese +trumpeter +trampoline +brogan +bone +caftan +lobster pot +gazpacho +anthill +ramekin +mainsail +penitentiary +spotted flycatcher +cookstove +root beer +broom beard grass +pogo stick +plywood +epee +gas oven +Global Positioning System +sweet false chamomile +breakfast area +bullring +second cousin +wave +decolletage +rodeo +won ton +swastika +bobby pin +papaw +retaining wall +Muscadet +heavyweight +energizer +banner +amusement park +whinchat +drugstore +waxwork +meander +congee +heat sink +switch grass +commuter +peony +western white pine +wild raspberry +nightgown +saute +cardinal +claret +pollinator +biryani +pina colada +cassette deck +European sandpiper +block +flan +birdcage +baby +lieutenant colonel +ticking +European white lily +dog violet +coat hanger +premature baby +organza +string bean +balloonist +hurricane deck +window box +hang glider +bullfighting +piste +seahorse +hard cider +batik +common mullein +petite marmite +stuffed mushroom +tequila +ground ivy +fountain grass +stray +putter +buffer +comet +bomber +woodcarving +baseball glove +halter +garnish +selvage +megaphone +sea fan +rabbit hutch +very important person +analog watch +long-head coneflower +northern pike +roll-on +cigarette butt +terraced house +penknife +windshield wiper +cricket +straightener +snow pea +cockerel +canister +sour bread +recovery room +toilet bowl +tyrannosaur +big sister +quartz battery +television receiver +vitamin C +tailpipe +field thistle +stonechat +col +monstrance +gift wrapping +herbivore +quarter horse +ice-cream sundae +rumpus room +eyepatch +clary sage +French lavender +snorkel +choir +tent-fly +cat box +horse racing +high priest +barrel cactus +pin oak +wild thyme +keyboardist +raiser +hammock +hail +bungee +chocolate mousse +major +buzzard +gopher tortoise +Chablis +water meter +benthos +donna +blender +Mauser +avocet +rye +mulch +chancel +dusty miller +mate +corbel +minaret +frittata +French toast +mosaic +home brew +water faucet +beard +swivel chair +acropolis +largemouth +abbey +tabby +driver +copperhead +stirrup +Boston fern +Tennessee walker +artichoke +honor guard +chapatti +enchantress +sweat pants +electric organ +column +dry vermouth +range hood +Red Delicious +rape +splint +catapult +gourd +antipasto +plaza +carnation +star +wood anemone +English primrose +male fern +boot +atrium +Japanese deer +carnivore +yearling +doe +guelder rose +chicory +stretch pants +ice-cream cake +frogfish +tarpaulin +chicken soup +balaclava +tor +feverfew +three-hitter +flyweight +aqua vitae +locker room +wether +teacup +wide-angle lens +hook +ladder-back +osprey +awning +wedding +chest protector +pooch +rose mallow +orange daisy +fondant +envelope +duckling +blackberry +goosander +snorkeling +philatelist +broad bean +Frank +bok choy +basket +absinth +cayenne +blackbird +bottled water +trooper +timber +stable +chestnut +tomatillo +bell +banquet +rainbow trout +macrame +appointee +heart +chipmunk +purple clematis +safety bicycle +shuttle bus +Japanese black pine +lentil soup +downhill +field mustard +brass +hand-me-down +greater yellowlegs +fanny pack +croquet mallet +hip roof +duffel bag +Ritz +document +pie plant +staff member +lifeguard +white-throated sparrow +Cameroonian +hydrofoil +platter +common ageratum +middleweight +chairlift +brunch +pharmacist +lemon +driveshaft +green snake +lip +London plane +mangrove +crystal +siskin +common jasmine +hollandaise +villa +cross-country riding +mother-in-law's tongue +generator +Tanzanian +whisk +seeder +ashtray +griddle +evening bag +bluebird +bran muffin +square dancer +luggage compartment +tropical pitcher plant +autofocus +tape drive +silencer +Hawaiian guitar +swamp sparrow +Zimbabwean +drawing room +weekender +liparis +streambed +samosa +hitter +water heater +tidal basin +ossuary +dik-dik +camouflage +fiance +Jordanian +rolling pin +slingback +turret +hen +jennet +playpen +woodhewer +bushing +church bell +bear grass +double knit +tennis pro +Joe-Pye weed +pave +pochard +painted beauty +crinoline +gumbo +trestle table +schnitzel +balloon flower +Turkish coffee +extension cord +wireless local area network +sluice +umbel +microeconomist +sky +aisle +commander in chief +hydroplane racing +poll +Coca Cola +fuel injection +bird pepper +monkey puzzle +English muffin +riverbed +varietal +kachina +airport +saltwort +oolong +red-hot poker +mihrab +cocoa +jersey +Walkman +syndic +Hessian boot +millstone +carpenter +outfall +curbstone +mocha +field pansy +patriarch +slacks +switchblade +killdeer +whelk +pampas grass +racquetball +platform bed +Indian rhinoceros +Japanese iris +blacktop +dinner jacket +stud +jodhpurs +telephone pole +business district +kurta +basil +handset +file folder +gloriosa +orphan +cantle +cookie sheet +cafe au lait +drawbridge +hill myna +Western diamondback +watch case +cardcase +bowling alley +mattress cover +canvasback +pompadour +cornice +matador +cigar cutter +skunk cabbage +baptismal font +bitters +refectory +egg +parula warbler +tiger lily +field house +nanny +skin-diver +soda water +lymphocyte +carport +chocolate fudge +amphitheater +sugar candy +sea hare +open-face sandwich +dessert spoon +staple gun +envelope +worker bee +general +garment bag +maypop +autobahn +Atlantic puffin +polo shirt +Humvee +spice rack +grotto +banderillero +gaillardia +black-crowned night heron +oboist +weigela +Dictaphone +dwarf iris +marsh mallow +yarrow +eccentric +catsup +jade green +mistress +henbit +beachwear +head +commuter +strawberry tree +chickpea +clothespin +fleabane +brussels sprout +winter melon +Laconian +great horned owl +caricaturist +nan +flowerbed +triple sec +dairy +round of golf +cardinal +kauri +Zulu +Armagnac +cowberry +mouthpiece +wild calla +bling +puppeteer +beer drinker +adder +field sparrow +chocolate pudding +blacksmith +finback +Shetland pony +cheese fondue +panty girdle +soda can +electrolytic +florist's chrysanthemum +yellow jasmine +tudung +equalizer +ridge +dulcimer +grappa +barn swallow +coneflower +enamel +poached egg +halfback +yak +toby +Fleet Street +blue catfish +sand tiger +flying buttress +snaffle +stoop +first base +cultivated land +first lady +waratah +headquarters +arnica +lovebird +common morel +parasol +disk clutch +Xerox +vitamin P +vitamin B12 +long sleeve +certified public accountant +hot pants +pitch pine +pantie +drawers +cake mix +boar +grey +bride +false sago +bullion +coach house +bass guitar +Japanese banana +meadow clary +black belt +Canterbury bell +smallmouth +treadmill +great white heron +enchilada +rummer +captain +camisole +wild garlic +oak fern +ultramarine +peach +hawkweed +autostrada +adit +anaconda +artwork +skinhead +jello +hermit thrush +Bewick's swan +dress suit +trail bike +stubble +common polypody +Riesling +Easter lily +telegraph key +envelope +garlic bread +perianth +salad bar +steppe +club sandwich +nude +garden forget-me-not +Tuareg +flood +Statehouse +charcoal +boy scout +Rhone wine +parfait +spoor +lanyard +octagon +brown bread +quarterback +quilted bedspread +hookah +Pepsi +hamburger bun +entrepreneur +saddle oxford +snake's head fritillary +undies +chemise +skidder +chickpea +carnation +honey bun +mortar +Montrachet +automobile horn +skylight +gingham +rafter +pantile +climbing frame +scarlet runner +cable +cornstalk +mockingbird +raisin bread +chili sauce +hand calculator +concert-goer +detached house +coq au vin +lasso +hyssop +globe thistle +paper clip +slide +Jerusalem artichoke +tetrahedron +mock orange +lemon lily +finger +little sister +handcuff +horse wrangler +pavlova +oilcloth +snow-in-summer +common mugwort +greenshank +ice-cream cone +rubber boot +gunnysack +disk jockey +long trousers +sorghum +pontoon +calf +fire extinguisher +cotton thistle +pilot whale +ao dai +steamroller +wristwatch +tawny owl +city +country store +ironweed +kennel +bathrobe +rattan +drawer +fly tent +choline +musk thistle +courthouse +Yugoslav +bush +trawler +shellflower +jade vine +ragged orchid +pea soup +King Charles spaniel +hubcap +snook +paddy +bow and arrow +shovel +dill +cliff swallow +cadaver +hijab +masterpiece +fish geranium +kettle +sanitary napkin +carrot stick +Mountie +peanut brittle +dam +jackal +windowsill +butterfly orchid +bodice +picador +pale yellow +beanie +petiole +tenor saxophonist +bungalow +gnomon +stock saddle +field glass +rigging +wood grain +Speaker +settlement house +swamp milkweed +paper nautilus +tangerine +champagne +crescent roll +library +Schmidt telescope +stemless carline thistle +motorcyclist +alpine ash +planchet +water closet +casuist +hand luggage +hyssop +spaghetti and meatballs +cannelloni +cedar waxwing +water dog +brick red +linkage +sweep hand +purple heather +macaroni and cheese +butter knife +refreshment +malt +St. Augustine grass +wainscot +compass +gas heater +tamale +table saw +referee +borsch +projector +dracaena +peppermint +Reuben +Abyssinian banana +glassblower +floss +small stores +artilleryman +lapwing +ranch +garbage man +dwarf banana +commelina +currant +adulteress +landlocked salmon +pasqueflower +nan +tiger lily +Eritrean +rotunda +catsup bottle +mezzanine +royal fern +blended whiskey +bowler hat +mistletoe +manor +fusee drive +pistachio +dispensary +swamp +amputee +sculptor +schoolmaster +Chinese anise +dwarf iris +livestock +chronograph +nectarine +jockey +plaster +motel room +swamp azalea +hippeastrum +space station +duchess +catacomb +dovetail +cockscomb +common spotted orchid +brittlebush +cleats +cloche +hotchpotch +cabin car +prey +indigo +light beer +bear's breech +jonquil +analyzer +alyssum +spur gear +ice tea +honey buzzard +twayblade +dirndl +atlas moth +croquette +carafe +flyweight +professional basketball +multivitamin +air terminal +phial +roll-on +skunk cabbage +bird of paradise +rose +cooter +camping +divided highway +herbage +sweet vermouth +common comfrey +eggplant +office building +glutton +gefilte fish +bicycle rack +swamp birch +Venetian blind +Pernod +Norway spruce +portrait camera +bastion +vitamin Bc +Ugandan +Indian red +okapi +emu +vin ordinaire +chintz +shrimp cocktail +numbat +tall oat grass +cable car +stopcock +ham sandwich +Yemeni +stanhopea +plate +chicken broth +common yellowthroat +California poppy +radio +chocolate egg +mess jacket +tea table +physostegia +Japanese flowering cherry +confectionery +chicken cacciatore +painted nettle +popover +white rice +strapless +mohair +electrical cable +coil spring +arterial road +miniature fan palm +spectator pump +pesto +interlocutor +eastern kingbird +dongle +vitamin B6 +stuffed tomato +cough drop +okra +black +barbecue +burial mound +firstborn +corn snake +amberjack +bollard +horn +Black African +elbow pad +Camembert +circle +Japanese apricot +hearing aid +rock star +creature +taster +bubble gum +scull +lemon balm +chaetodon +anemometer +brake drum +fuselage +courthouse +aqualung +yellow adder's tongue +reception desk +guy +buffalo wing +ginger beer +robin +pantothenic acid +marsh hawk +yellow journalism +exhaust +cardamom +Tabasco +ax handle +patriarch +floor +pine snake +spoiler +hood +sphagnum +parrotfish +orphanage +redpoll +beef Wellington +white spruce +cherry plum +scapular +field lens +broomstick +mouser +wood thrush +Nebraskan +hotelier +milk thistle +soya milk +Munich beer +boucle +snowy egret +dust storm +steward +kudzu +oriental poppy +presbytery +burro +orange soda +stonecrop +splashboard +menagerie +dormer +wire cutter +yellow bells +Dubliner +shore pine +cousin +racing gig +Morgan +gold plate +villager +snifter +granny's bonnets +egg roll +Spode +amabilis fir +babbler +pestle +heliopsis +halter +black spruce +President of the United States +ski slope +chocolate fondue +lockstitch +motel +Epipactis helleborine +tabbouleh +Yorkshire pudding +overpass +Timorese +presbyter +tablefork +bottle gourd +tiara +vintage +pilgrim +reindeer moss +shower stall +towel rack +kachina +chef's salad +breeder +cow parsnip +walker +Black woman +Irish coffee +portrait lens +lateen +gilt +successor +cargo container +Lithuanian +mayapple +paisley +highchair +strawberry jam +flying fox +field scabious +blue-eyed grass +screw +Frisbee +dressing room +cholla +walkie-talkie +red currant +centrifugal pump +smorgasbord +hot rod +marcher +rowanberry +welwitschia +amphitheater +pew +concert band +bosom +pillbox +seagrass +openwork +meadow goldenrod +shower +chicken sandwich +Boston ivy +plastron +oilfield +stuffed tomato +juniper berries +frame +Spanish mackerel +family room +powder horn +fight +maguey +bunker +work-shirt +air filter +nosh +sugar bowl +foothill +reliquary +tugboat +horsebox +grater +palace +board member +campsite +halibut +geneva +ginger ale +high commissioner +genet +bodywork +spaghetti +protractor +pipe cutter +wood anemone +turkey cock +surge suppressor +green turtle +spoiler +bedsitting room +television room +ballot box +shasta daisy +impeller +capote +bitter +California wine +lock +spinnaker +gill fungus +baby's breath +nut and bolt +moonflower +houseboat +distributor cap +coffee bean +gusset +bowling ball +knitwear +frieze +mistflower +roadster +cue +circuitry +brake +butt hinge +Chickasaw +leopard frog +wing tip +puree +mantel +pantheon +grandfather clock +cockchafer +pomegranate +cleaners +eyeshadow +Oregon cedar +rock hopper +hawksbill turtle +agriculturist +yellow-crowned night heron +Albanian +pumpkin seed +chateau +goggles +camper trailer +bracket fungus +cigarette case +signal box +saddle blanket +poison ivy +set gun +cattleya +dry fly +concert hall +personal digital assistant +talcum +deodorant +common starling +painted turtle +kea +plenipotentiary +pantyhose +masjid +buskin +hurdle +cocktail lounge +belting +sour dock +knife blade +sugar snap pea +paddle +dickeybird +brace +keep +call center +yacht +lead pencil +tumbler +production line +tetra +private +French window +express +ski boot +pinto +broad bean +American crow +screech owl +snapper +power cord +Manx +rambutan +sun deck +stonefish +golden eagle +national monument +readout +cork oak +hacksaw +beer can +bathe +tussock bellflower +wet suit +mihrab +big game +highlighter +sprocket +measuring worm +grapefruit +samovar +distributor point +steak knife +incubator +loon +temporary hookup +hippodrome +hot spring +spacesuit +flea market +clay pigeon +catbird +earmuff +tetherball +yellowfin +cellophane +lanolin +clapperboard +velveteen +police dog +cashew +sequencer +mango +duplex house +bazaar +Golden Delicious +red carpet +collet +kickstand +broadloom +diskette +tank engine +compact +diesel-electric locomotive +whale shark +water moccasin +mountain avens +tropic bird +ginkgo +ski cap +fixative +glockenspiel +chopine +ethernet +herring gull +skeleton key +finger paint +conference table +great crested grebe +harbor +white-crowned sparrow +Bullock's oriole +guestroom +boutique +cable television +roulette wheel +Luger +Latin American +trumpeter +blindfold +baby +freshwater bass +home plate +bonefish +giant sunflower +giant tortoise +planking +pigeon hawk +oceanfront +door +bazaar +common wasp +conformation +kick starter +kid glove +corydalis +shuttlecock +writing desk +ivory gull +shirttail +diving suit +weka +downy birch +altar +wild sage +tufted puffin +cabinet +Orpington +cineraria +bottom +dial +coracle +resort hotel +soap dish +spotted owl +billiard room +ghetto blaster +red-breasted nuthatch +hatchling +chalet +bracteole +crusher +mixer +net melon +farmhouse +Dutch oven +transept +penlight +palmyra +stewing pan +solar cell +crochet needle +black-winged stilt +germander speedwell +crinkleroot +truncheon +bunchberry +hatchback +sounding board +mixing faucet +chess master +bisque +Brie +Sitka spruce +pawn +Mexican-American +space rocket +choreographer +collared peccary +duffel +nacho +patchcord +carpet snake +omnivore +watering can +hall of residence +streamer fly +sunroof +great grandson +oil refinery +billiard player +ivy geranium +key palm +pinwheel +yellow-shafted flicker +purple onion +soldering iron +condominium +fishing gear +heat pump +marine iguana +cuckoo clock +Bletilla striata +headrest +spotted salamander +field hockey ball +pound +carboy +vertical stabilizer +groundsheet +cinnamon bread +acorn squash +sheathing +lakefront +Jeffrey pine +synthesizer +olive +apple +pannier +ponderosa +Jew's-ear +latch +equatorial +metasequoia +permit +bloomers +town hall +fava bean +casino +bier +jampot +common snapping turtle +clary sage +oatmeal +Dutchman's breeches +massif +Guyanese +heifer +handball +sweat suit +pomelo +Iceland moss +customhouse +sandbag +archer +gyrfalcon +sword cane +marmite +whole snipe +blue crab +sugar spoon +brownstone +chicken wire +lizardfish +dump truck +chicken yard +chamois +electric +idle pulley +jujube +wrestling mat +aoudad +Burmese cat +water shamrock +dormitory +Unknown Soldier +hearse +bumper +clipper +desert pea +critter +semitrailer +backboard +common St John's wort +Atlantic manta +song thrush +jukebox +quoin +eastern chipmunk +copper beech +paintball gun +bull +package store +fraise +royal poinciana +niqab +traction engine +objective +day nursery +ski lodge +orphan +summer house +cereal box +router +sleuth +jodhpur +polyp +croquet +sport kite +green onion +tulle +etagere +tussock caterpillar +rest house +elderberry +bridal wreath +Torrey pine +silver wattle +kidney bean +pentode +laelia +Allen wrench +sporran +red drum +tricot +heterodyne receiver +magazine rack +stone curlew +trawler +suckling +niblick +sandwich plate +double door +Togolese +pitching wedge +desert tortoise +cloth cap +date palm +webbing +jumper +frogmouth +copperhead +covered couch +black mallee +riser +scraper +gauntlet +pantheon +food court +muntjac +grocery bag +bread-bin +transmission shaft +primigravida +window seat +crab apple +seat +Fresnel lens +dendrobium +hatchback +little theater +butter dish +back porch +umbrella tree +carrot +seventy-eight +coconut +music stool +Tesla coil +bay willow +American basswood +sabot +wheel and axle +gazette +lute +bassinet +hart +mecca +breadbasket +silverfish +handball +Scotch pine +box camera +stately home +Hereford +tread +single-breasted jacket +desk phone +deodar +professional boxing +fly casting +box wrench +black oak +martello tower +red campion +bullock +sweet William +bay leaf +dollhouse +flounder +fox hunting +beanbag +king mackerel +rouge +film advance +common mallow +parasitic jaeger +satellite receiver +nurse shark +chesterfield +tomatillo +plimsoll +hatbox +bloomer +foul-weather gear +longleaf pine +horse mackerel +tree lizard +bark +belfry +Treasury +perch +purple finch +stag beetle +fragrant orchid +tachymeter +tadpole +cookie jar +knee piece +agueweed +bones +chick +golf glove +toothpick +taboret +rotor blade +field artillery +purple willow +redhead +spark plug +guava +voice mail +cross +butterfly valve +star magnolia +olive +room light +Australian turtledove +embassy +Iraqi +singles +nestling +spinning rod +radial engine +rowan +sandbox +boss +moccasin flower +veneer +mint +American chestnut +white whale +CPU board +florist +press box +hurricane lamp +giant kangaroo +greater whitethroat +winter jasmine +blue +department store +southern red oak +saber saw +corn muffin +bellbottom trousers +toaster oven +red eft +condominium +galago +sunbather +redpoll +common European earwig +songbird +linnet +light meter +bracer +tepee +gumbo +water glass +roofing +spathiphyllum +shofar +sand lizard +washroom +Brussels carpet +brachyuran +home room +floatplane +knee brace +solar heater +felucca +gas ring +maguey +manse +blue columbine +cuppa +cigar band +male orchis +mudskipper +couscous +Chinese parasol tree +dude ranch +banyan +gopher snake +sundrops +aviary +African daisy +missel thrush +Photostat +stone pine +circus tent +tangle +printer cable +grease-gun +rose chafer +light pen +plantain +hearth +bullfinch +post oak +slow loris +Newtonian telescope +head +punt +spindle +New England aster +spotted sandpiper +pond pine +grass skirt +bug +black rat snake +tabasco +bull shark +tennis camp +scrambler +popinjay +bing cherry +ministry +cash register +redheaded woodpecker +kameez +farmer's market +roan +harpy +European toad +pizzeria +camshaft +hemp nettle +chicken coop +cottage pink +daybed +observatory +airdock +mountain devil +newsstand +kingfish +snow gum +jackdaw +lacquerware +peeler +miro +sister ship +damask rose +pack +snowshoe +Liberian +paramecium +tidytips +professional tennis +bookend +wood swallow +cayuse +cranberry +rock squirrel +steak au poivre +soul patch +female mammal +sash fastener +songwriter +oxeye daisy +apse +floor joist +hand towel +wheatear +cero +soul mate +golden fig +bus stop +psycholinguist +convenience store +manor hall +mountain sandwort +Euopean hoopoe +haricot vert +mausoleum +violist +flashlight battery +chard +fixer-upper +bank martin +testudo +diving duck +kohlrabi +Omani +sphygmomanometer +greyhound racing +chestnut +rattlesnake plantain +chaffinch +wolf pup +teakettle +cairn +souk +resident commissioner +chuckwalla +gaiter +capercaillie +liver chestnut +bean sprout +land line +ambassador +green pepper +common chickweed +Sharpie +Oriental arborvitae +oncidium +pallone +currawong +sweet alyssum +fire tower +eyebrow pencil +redfish +apricot +clementine +blucher +wigwam +pangolin +buggy +common oak +jumbojet +laser +cigarette holder +racquetball +georgette +cleft +scouring pad +drum printer +pond scum +American red squirrel +caranday +swamp willow +blindworm +brook trout +defense system +nyala +three-way calling +mizzen +shuttle +African lily +Oregon white oak +rain tree +fuel gauge +oriental cherry +wahoo +pear +jungle gym +bass fiddle +outrigger +angelfish +Old World coot +lime +battlement +yarmulke +herpes varicella zoster +burp gun +Alpine glacier +stun gun +pilot boat +Southern crab apple +bushtit +pullet +polo pony +jackfruit +raw vegetable +French marigold +golden shower tree +spike lavender +wahoo +brass knucks +cabbage palm +diesel-hydraulic locomotive +red jungle fowl +prairie sunflower +rye +loofa +icecap +shade tree +secretary bird +saffron +cos +muskrat +videodisk +Carolina wren +candy bar +Bohemian waxwing +flowering almond +cold frame +raglan +pine siskin +quince +western red cedar +red maple +adobe +agora +kumquat +tenement +bantam +bayberry +water jump +great granddaughter +snips +porcupinefish +brochette +love-in-a-mist +Iceland poppy +common sage +pace car +camel racing +slipcover +nopal +shoehorn +calypso +rhea +in-basket +maple syrup +cold chisel +Pacific ridley +dietary +aperture +lapin +rock hyrax +house wren +litchi +ragged robin +control center +shoebox +arabesque +eider +silver birch +bantamweight +ax head +softball +blue gum +Bechtel crab +tomato sauce +green douglas fir +sweet gum +macaroni salad +red phalarope +budgerigar +Bedford cord +Uzi +green woodpecker +ohmmeter +bacon-lettuce-tomato sandwich +hackney +Easter egg +motmot +red pine +opium poppy +gat +pussy willow +greater scaup +ocelot +persimmon +western hemlock +carambola +pinion +Malcolm stock +bobsled +larkspur +wood drake +pinetum +red gum +draft beer +funnel +terrarium +Pinot blanc +doodlebug +brittle star +salsa +cantaloup +pollack +stockpot +eastern hemlock +rock wren +burqa +squash +aircraft engine +billy +flamingo flower +odontoglossum +old squaw +redstart +sheepskin coat +mate +flathead catfish +gentianella +bilberry +bog rein orchid +incense cedar +mew +Colorado spruce +cob +portmanteau +grenadine +common ginger +masdevallia +compound microscope +sobralia +white fungus +guppy +chapterhouse +honey +green frog +sea swallow +African marigold +astrolabe +verdigris +yellowhammer +carrot juice +oxlip +medicine ball +highboy +grass frog +gamebag +surgery +mincer +mulloway +cactus wren +box office +resonator +table-mountain pine +European curlew +supernova +cabbageworm +peach +plane seat +asp +Yquem +tomato hornworm +rook +quadruped +chador +micrometer +dabchick +Afro-wig +balsam fir +bucket seat +sage green +macon +blue poppy +chinquapin oak +black pine +spinach +chrysalis +carnauba +tee +bearberry +shirt button +tree of heaven +southern white cedar +covered wagon +brood hen +spadix +European catfish +winter wren +bulldog clip +carpetbag +study hall +chino +simian +closeup lens +cookie cutter +grapefruit +mandola +sassaby +Allegheny plum +piaffe +scorpion fly +booby +draft animal +field tent +cumin +laurel oak +smooth-leaved elm +American arborvitae +American toad +grinding wheel +mountain ash +cuttlefish +pipistrelle +parer +safety rail +Clark's nutcracker +side-blotched lizard +giant hornet +wicket +dugout +electric toothbrush +dhow +common four-o'clock +long-eared owl +anchor +near beer +tansy +creme caramel +guided missile frigate +shelduck +durian +compact +iron tree +shiitake +polo +camouflage +pedal pusher +salon +tangerine +lacebark +Swiss mountain pine +goalpost +poolroom +space capsule +wild cherry +dress hat +wave +raglan sleeve +cassia +Jerusalem artichoke +cabbage palmetto +marsh harrier +American redstart +sea squirt +cliff diving +sparrow hawk +watch cap +frankfurter bun +police boat +flash camera +neem +eastern meadowlark +Italian cypress +orb-weaving spider +graniteware +sewing basket +latex paint +rock dove +stator +leaf lettuce +roulette +broadcloth +Spork +panicle +sternwheeler +cider vinegar +brown creeper +cowfish +closed gentian +chickpea +port +pimento +sheeting +matilija poppy +hawk owl +guava +papaya +huisache +European shrike +racing skiff +yellow warbler +gumbo-limbo +North Carolinian +staysail +court +iced coffee +money belt +shaver +Psychopsis papilio +sumo ring +refection +kingfish +clock pendulum +greater butterfly orchid +disk harrow +tawny eagle +polyphemus moth +pieplant +Nicaraguan +bocce ball +California box elder +porbeagle +crown of thorns +Mexican sunflower +fennel +stream orchid +slip ring +white fir +fold +moss campion +fairy ring +hose +pony-trekking +western larch +meadow pipit +Cape May warbler +longan +bookmobile +junk shop +lemon shark +smelling bottle +solan +widow +sea pen +universal joint +day game +goldcrest +maiden pink +biographer +rotunda +oriel +arranger +gambrel +Angora +fen orchid +leading rein +Wilson's snipe +European nuthatch +natterjack +athletic supporter +mouflon +emergency room +swallow-tailed coat +western meadowlark +feather star +Navy SEAL +toilet bag +loquat +lesser butterfly orchid +thumbhole +breathalyzer +featherweight +collards +mayfly +confessional +mountain ebony +redwing +Norway maple +refractometer +stagecoach +gasoline gauge +octopus +baker +Rhode Island red +European tortoise +cardiologist +Punjabi +Arkansas kingbird +tamarind +drum brake +flash +yellowtail +stokes' aster +emperor +free house +sour gum +ruddy duck +hamadryad +command module +tinamou +Norway lobster +washstand +European hornbeam +roaster +black-necked grebe +tallgrass +leopard lizard +anastigmat +Blackburn +deutzia +ground rattler +Christmas fern +wild pink +sesame seed +carrycot +Italian parsley +nectar +roll-on roll-off +true laurel +anisette +candy corn +flowering maple +revers +dun +tobacco hornworm +common sunflower +common grape hyacinth +cardiograph +electric meter +herb Paris +goalmouth +spruce grouse +canopy +wind poppy +stemma +gateleg table +lumper +speckled rattlesnake +gudgeon +rough-legged hawk +internal drive +pomelo +piece de resistance +storm door +clementine +Japanese pink +settler +yellow jacket +Fraser fir +royal palm +cicada killer +cayenne +guava +bluewing +red baneberry +lesser yellowlegs +cache +bog rose +sparring partner +ski jumping +sherry +glacier lily +beer mat +shredder +American widgeon +protectionist +green olive +black-tailed deer +Alpine fir +dispatch case +whipping cream +African daisy +cantilever bridge +maraschino +rhea +ink bottle +dacha +hagberry tree +lesser rorqual +orchard oriole +candidate +cuticle +breadfruit +fishbowl +giant puffball +closed gentian +Joshua tree +tie rod +beard lichen +flame tree +stegosaur +acerola +Swan River daisy +common murre +flowering almond +protegee +loggerhead shrike +Wilson's warbler +Japanese honeysuckle +basilisk +skimmer +hybrid tuberous begonia +pumpkin ash +chafing dish +collared lizard +iced-tea spoon +scrubbird +Iceland poppy +grey kingbird +wallflower +slick +diesel +Swiss pine +ethernet cable +ketch +lightship +black cherry +swordtail +Monterey cypress +lightweight +Floridian +Sabine +stall +contact +viola da gamba +hemstitch +upland sandpiper +box spring +sassafras +radome +lesser scaup +bluefin +yellow-bellied sapsucker +armored car +cabin class +Moorish arch +webcam +aquavit +overall +sergeant major +soft shield fern +gin and it +bobolink +subcompact +falconer +black morel +roadrunner +lab bench +thong +coffee urn +weeping beech +caladenia +southern live oak +scanner +wine vinegar +common speedwell +European roller +fuji +snag +piping plover +concertina +secateurs +meat thermometer +supercomputer +funnel +dais +western fence lizard +spruce pine +pommel horse +Cassegrainian telescope +pitta +India-rubber tree +mangosteen +tamp +aposematic coloration +dustcloth +birth +Atlas cedar +reed bunting +jabiru +sainfoin +press photographer +golden oriole +laryngoscope +thermal printer +winder +doubles +cricket ball +dabbling duck +tonic +Buddhist +Morris chair +swatter +quaking aspen +ancient pine +American larch +evaporative cooler +click beetle +yellow-breasted chat +souchong +bluegill +pied-billed grebe +tricorn +spring beauty +southern magnolia +rowel +chili +hard roll +flathead +satsuma +gangplank +bourguignon +cockfighting +greenwing +plum tomato +fly orchid +gnatcatcher +spotted eagle ray +ovenbird +brassavola +mocha +candy cane +afterburner +thriftshop +study +winter crookneck +grinder +muskellunge +sacred ibis +inverter +sandwort +deer fern +stair-carpet +Cotes de Provence +ovenbird +rex begonia +American woodcock +poison ash +lowland fir +pawpaw +loblolly pine +kinkajou +European hackberry +pest +coralwood +Bedouin +acetate rayon +snuffbox +radiator cap +basket oak +table-tennis racquet +smew +midge +telescopic sight +radish +great burdock +separate +damask violet +broadbill +bourbon +blacktip shark +gift shop +khimar +date +woodland caribou +policeman bird +grey birch +American elm +strawflower +officiant +hart's-tongue +straight razor +Spanish elm +radicchio +white croaker +vicuna +soft-shell clam +flannel +adonis +bonito +kittiwake +English walnut +soldierfish +hipflask +spotted crake +Streptopelia turtur +American maidenhair fern +corn cockle +telephone cord +canopy +playback +diocesan +marsh orchid +manakin +purple grackle +cob +fishmonger +otoscope +vermillion flycatcher +inhaler +instar +licentiate +myrtle warbler +goat herder +benthos +toggle +drumhead +piranha +doorplate +vault +triptych +red-necked grebe +transporter +vernier caliper +flathead +Portuguese man-of-war +countrywoman +vacation home +Bactrian camel +night-light +module +lemon curd +carancha +painted daisy +bok choy +ratatouille +troll +escarpment +cinnabar +computerized axial tomography scanner +lychgate +sowbread +bedside +guided missile cruiser +reel +cleat +hemostat +blue shark +Seven Wonders of the Ancient World +motorized wheelchair +pillow block +horned puffin +prickly pear +electric range +mother's daughter +vein +Oregon maple +bird dog +faceplate +wren warbler +feather reed grass +common alder +Adam's needle +straitjacket +organ-grinder +gantry +bikini pants +peristyle +herpes +terry +toad lily +celandine +red-breasted sapsucker +bragger +green peafowl +fuschia +quoits +house martin +dome +herpes simplex 1 +touraco +meeting house +vacuum gauge +cat's-ear +crisphead lettuce +carpet moth +European rabbit +puff adder +Old World scops owl +fire pink +fruit punch +ant bear +black walnut +stroboscope +white mangrove +pine grosbeak +cast +check-in +ring-necked parakeet +matai +shingle oak +fieldwork +rue anemone +landing net +ouzo +herringbone +lyceum +hydrogen bomb +mullein pink +masher +evening grosbeak +water vole +livingstone daisy +tomatillo +cavalier hat +interphone +wild lupine +goosefish +sugar maple +plantain +white dead nettle +Monterey pine +bugle +veloute +marsh gentian +Bermuda buttercup +alehouse +Peter Pan +thong +LP +tulip tree +scanner +scarlet tanager +music hall +angel shark +pecan +eight ball +rosy boa +outboard motorboat +garage +fanlight +black cottonwood +notornis +mountain fern +lunar crater +reddish orange +whitetip shark +executant +European ladies' tresses +washboard +revolving door +case knife +balloonfish +greater kudu +tarpan +cog +wet fly +Irish soda bread +basement +broken arch +canopic jar +muscat +kazoo +bobsledding +loaner +black guillemot +English saddle +garlic mustard +Foucault pendulum +mulberry +clotted cream +dove's foot geranium +Atlantic ridley +convector +ground floor +European wildcat +poinsettia +hideaway +great barracuda +black beech +bushy aster +cornflower +tam +true slime mold +carving knife +holly fern +railroad tunnel +crimson clover +disposal +etamine +suspension +plasmodium +political scientist +minnow +Spanish rice +twist bit +subway train +Scleroderma citrinum +saw palmetto +console +gimlet +hand pump +waratah +rock rattlesnake +keel +server +curlew sandpiper +hone +sable antelope +inkle +photostat +foresail +sallet +tiger salamander +chutney +onlooker +Exmoor +tiramisu +drawing room +battery +sour orange +juniper berry +beeper +funeral home +fescue +Maksutov telescope +ranch house +jai alai +carob +socket +popcorn +sandbar shark +pipal +summer tanager +oast +skipjack +rolling stock +dropper +great snipe +turnip greens +cowpea +honeycomb +ichneumon fly +maternity hospital +harp seal +nylon +bomb shelter +horse tick +litchi +camel's hair +mimosa +bur oak +anvil +belay +pinhead +continental breakfast +burglar alarm +Mojave rattlesnake +auxiliary storage +lightwood +ratepayer +cecropia +retractor +quadrate +pepper tree +Venus' slipper +abattoir +strawflower +firewater +purple saxifrage +black rat +pack +pepper pot +mayweed +winger +whitetip shark +great yellow gentian +snowdrop anemone +garden angelica +soy sauce +white poplar +inkwell +crouton +gas gun +honey locust +house of cards +ice maker +moquette +arrack +casualty +butterfly orchid +eau de vie +mosquitofish +prairie smoke +haft +horseshoe +steel +peach orchard +Mexican hat +encaustic +shoe +pennywhistle +sweet woodruff +hull +doorsill +globe amaranth +day school +housedog +crown princess +oxbow +maxi +positron emission tomography scanner +compere +European turkey oak +peanut +sentry box +house physician +hot line +loquat +rove beetle +riband +flowering fern +fan vaulting +ceibo +bongo +bat boy +omelet pan +European ash +breadwinner +gaff topsail +clerestory +bushbuck +bluethroat +khukuri +Father +portcullis +candy egg +brake lining +lawn furniture +buckskin +garden pea +Brazilian rosewood +Italian bread +horn poppy +silk tree +Christmasberry +hotel-casino +poplin +false lupine +desert sunflower +mimeograph +alpenstock +cork tree +cultivar +common mosquito +pollard +black marlin +understudy +lancet window +college +breadfruit +Herero +Labourite +bar printer +squaw grass +stelis +firing chamber +sycamore +artificial horizon +radiologist +pansy orchid +bicycle pump +wraparound +bell gable +home computer +orchard grass +carving fork +bergamot +honeycreeper +sewing room +radiator +core +brown bat +goose grass +adjutant general +Erlenmeyer flask +massasauga +tail rotor +cardinal tetra +Drambuie +wine palm +Sarcoscypha coccinea +shantung +Calvados +garganey +vicar +house mouse +creeping oxalis +digital subscriber line +cedar elm +backgammon board +blackberry-lily +pallid bat +New Zealander +Barbadian +rose geranium +European spider crab +gharry +electric hammer +mustard +Chinese lantern +laundry cart +filament +mozzarella +gooseberry +sukiyaki +porkpie +culvert +altazimuth +plum pudding +serin +Spanish dagger +Asian crocodile +crevalle jack +mascara +pig bed +alderman +northern shrike +Sufi +purple-fringed orchid +derringer +linseed +hockey skate +bell jar +Japanese wistaria +mantled ground squirrel +western toad +lieutenant commander +mechanical piano +ovoid +paddlefish +demijohn +coast live oak +brick +gearset +tailstock +phonograph needle +winery +tuberose +mother's boy +shot tower +crucian carp +carpet pad +lamb's-quarter +Menorah +common white dogwood +hypanthium +rosebay +wild medlar +soil horizon +sweet orange +bitterroot +hand glass +cloisonne +towpath +gum ball +margay +carambola +bolt cutter +charger +vibraphone +gueridon +elephant tree +wood-frog +ash grey +duffel coat +third base +chunga +glebe house +lake trout +encephalartos +Japanese oak +northern red oak +pruner +blue orchid +Biloxi +western wood pewee +corselet +alabaster +anechoic chamber +grass pink +wax begonia +blue daisy +pennyroyal +Asian tiger mosquito +cheese souffle +flat bench +caramel +sump pump +bush violet +common fennel +corner +skullcap +asparagus fern +white mangrove +calceolaria +sateen +saltbox +hollowware +head nurse +coal miner +mountain lily +tufted vetch +European perch +line officer +steamer +stickball +shin guard +cauliflower +Monegasque +hatpin +wolffish +trackball +khaki +arthrogram +rocket larkspur +naval commander +Gemini +ski binding +department head +Chenin blanc +wingstem +knothole +aerides +sweet bay +tautog +gangway +waterspout +Hudsonian godwit +armyworm +incinerator +kidney vetch +pine nut +cypress vine +hip tile +sorrel tree +relay +bench press +Kentucky coffee tree +dobson +sapling +false lily of the valley +veld +phaius +vitamin B2 +beaker +wall tent +sieva bean +dusty miller +sewing kit +cavalry horse +diaper +butterfly pea +Spam +saddlebill +pearly everlasting +kowhai +Sister +moneywort +organdy +pine marten +bareboat +hot-water bottle +baby blue-eyes +silver lime +common cotton grass +malmsey +blue pea +baggage car +pineapple +folding saw +cotton rose +brawler +black duck +Weizenbock +pool player +Gujarati +wild duck +purple sage +sage grouse +mail train +arm guard +short-spurred fragrant orchid +queen +eparchy +spring peeper +ortolan +shoulder +fighter pilot +American beech +snowcap +novitiate +roller +butcherbird +canyon oak +brompton stock +firebrick +rudder +light cream +Primus stove +nonsmoker +probationer +harp +kosher +surcoat +videotape +zebu +first class +yam +car +rissole +miso +funambulism +attic +curling iron +shutter +encolure +split-pea soup +yellow rocket +gas oven +ultracentrifuge +chamomile +canteen +eyeliner +yellow squash +Irish stew +collar +doublet +machinist +septic tank +snap bean +Polyporus squamosus +western tanager +creeping St John's wort +back +sinkhole +perforation +Romanian +epergne +fez +comfrey +sidecar +beach pea +screen door +instigator +plughole +woodbine +pigweed +hip pocket +common scoter +squeegee +Surinam cherry +porringer +body stocking +eatage +shallot +enlarger +common canary +trophy case +gun case +plow horse +hot plate +pearl oyster +margarita +madras +backspace key +pigeon guillemot +pajama +buckthorn berry +homestead +bedbug +Linotype +trundle bed +granadilla +theremin +chin rest +bouillabaisse +tumble-dryer +truffle +cassava +kurrajong +gyroscope +European silver fir +C-clamp +politician +green soybean +exponent +flame tree +scissortail +achimenes +crown daisy +soft tree fern +spaghetti squash +pale violet +beaver +dashiki +washboard +driving wheel +sack +foulard +sputnik +boatbill +English elm +sack coat +grog +golliwog +Malayan tapir +May wine +calash +stile +windjammer +American sycamore +rotor head +fast food +balata +dragonet +Emmenthal +metronome +negative +meadow saxifrage +rabbit ears +chenille +round +hobby +crankshaft +Wilson's phalarope +Murphy bed +soil pipe +forecourt +policyholder +tarmacadam +loyalist +gyro +Queen's crape myrtle +shortcake +apple butter +pumpkinseed +heronry +yellow perch +baggage claim +escarpment +diaphragm +mescal bean +shunter +flax +columbarium +Joe-Pye weed +Neandertal man +casement +hole-in-the-wall +Verdicchio +futurist +eaglet +tassel hyacinth +pup tent +fawn lily +cabbage palm +pogonia +hospital ship +water mill +Oregon grape +lentil +grindstone +banana split +inkberry +coonskin cap +bazooka +wrap +anise hyssop +Java sparrow +red-eyed vireo +common opossum +clintonia +bustle +booster +tribesman +soy +panhandle +jaboticaba +locking pliers +Sauvignon grape +ghat +screw +oximeter +white croaker +saucepot +eggbeater +reticule +cabbage bark +looking-glass plant +head gasket +California sycamore +cowbell +Aleuria aurantia +Herr +lever +spider orchid +cashew +shift key +solar house +wood chisel +white +mantilla +stamp +bolero +rear admiral +garden rake +Lao +crowbar +lapdog +buttermilk biscuit +yellow bedstraw +pickerel frog +dowel +serjeant-at-law +mill-hand +lambrequin +state treasurer +red silk-cotton tree +coiffeur +star anise +shoulder pad +marshal +sitar player +gown +ground cedar +hedge maple +caddie +pitahaya +corn marigold +stick cinnamon +woodland star +Eurasian green toad +anti +blueweed +medicinal leech +gaur +chocolate kiss +kit fox +mother +butte +audio CD +blast furnace +vitamin D +nutgrass +cornice +black sheep +hearing aid +lingonberry +quad +lentil +riding crop +pratincole +pentagon +sea lavender +nerita +flatmate +catboat +water clover +angiopteris +mushy peas +crown imperial +music school +woodshed +platy +Turk's-cap +rundle +reading teacher +hardtack +balloon sail +oriental spruce +bluefish +white mulberry +horned violet +satin bowerbird +treasure flower +sustaining pedal +mimosa +spurge nettle +sea green +hasp +lederhosen +pink cockatoo +long johns +basket weave +freewheel +thrust bearing +timber tree +orphan +falafel +common camas +bird of passage +bird's foot trefoil +electric eel +fizz +grape arbor +serape +brace +hazelnut +kylix +horse mackerel +cassia bark +lizard orchid +spat +Brown Swiss +pocket flap +pillory +purplish blue +rolling mill +tappet +broccoli rabe +semi-detached house +mushroom coral +fly orchid +nougat bar +ball hawk +sand wedge +shirred egg +black locust +strip lighting +drop scone +brush turkey +ball +tragopan +dallisgrass +tuatara +great knapweed +potentiometer +Kiliwa +Pacific bottlenose dolphin +accelerator +Darwin tulip +osteopath +Arizona cypress +manna ash +butterbur +cornelian cherry +American holly +nopal +tanker +foreshore +ditty bag +gas lamp +safety razor +chanter +fomite +chip +striped killifish +catalytic converter +plaice +dusty miller +takin +gerenuk +corn chamomile +Japanese pagoda tree +boneset +common osier +Guinean +taro +plotter +celandine poppy +churn +steenbok +edible mussel +sensitive fern +triode +black raspberry +zoo keeper +feather ball +dredger +starlet +cornpone +coat button +rosinweed +toy Manchester +crested cariama +finger food +basilisk +shotgun shell +comfort food +mountain hemlock +candytuft +Stilton +record changer +anklet +ball valve +Mediterranean snapdragon +BVD +sand cat +Galloway +nutmeg +water-mint +woodwaxen +citron +ark shell +federalist +drone +cheekpiece +hyperbaric chamber +addax +field-emission microscope +synchronous converter +men's room +medlar +electronic fetal monitor +Sazerac +false indigo +roof +passe-partout +meadow spittlebug +Phytophthora infestans +oast house +hedge nettle +voting booth +slender salamander +telephone jack +true bug +scouring rush +Scotch egg +matchbook +aperea +cytomegalovirus +garlic press +cove +whitebark pine +Slovene +narrow wale +mother's milk +Audubon's warbler +prickly poppy +cowl +tailorbird +mud brick +bamboo palm +welt +Afghan +Virginia spring beauty +dinner bell +night jasmine +fly rod +microtome +aerie +carinate +picker +brick trowel +loving cup +swathe +green mayonnaise +rivet +bandbox +newsroom +tea tortrix +bobby +gig +hush puppy +garlic chive +piston rod +aspidistra +bluejack oak +harvest-lice +strap hinge +sour mash +macadamia nut +histiocyte +fan belt +shelf bracket +abelia +Hottentot fig +fish chowder +abettor +compote +beige +dioon +hop +haymaker +oilskin +magnetometer +tool bag +tambour +call girl +gringo +fairy light +broad-leaved plantain +second base +zebra mussel +Japanese cedar +pistia +swamp chestnut oak +cashmere +double cream +samisen +lamb curry +companion +kapok +julep +sweet woodruff +gardener +jewfish +inspector general +collembolan +wheel bug +bass +scrubland +wryneck +macrozamia +trouser press +clove +tiger cowrie +yawl +collard +dildo +pony cart +ormer +annual +tessera +chancellery +two-toed sloth +queen +old lady +wringer +spritzer +baggage +black mangrove +black-eyed Susan +semifinalist +highlighter +alfalfa +Easter daisy +escapement +operating table +neutral spirits +bursar +roble +entablature +girl wonder +farm boy +ring ouzel +permanent press +auklet +beefsteak tomato +gaming table +tea bag +manul +giant bamboo +Ozark chinkapin +matzo +furrow +smoothhound +CD-ROM drive +powdery mildew +copilot +garden +American merganser +bunsen burner +Asian longhorned beetle +lead tree +creeping buttercup +Percheron +back brace +axseed +cub +soul food +rabbi +edelweiss +mineshaft +fox grape +sandwort +torque wrench +leisure wear +Mae West +broccoli +loach +maraschino +heavy cream +silkworm +cirque +vintner +whitewash +butterfly pea +two-toed sloth +midiron +ceriman +Bulgarian +operating microscope +sambuca +California fuchsia +silver maple +tangelo +black bean +lugsail +starting gate +leek +sunflower seed +fish fry +clinker +synagogue +coscoroba +brae +uphill +common limpet +golden plover +cedar of Lebanon +amphibian +Canary wine +taipan +agua +feeder +parallel +mater +pink calla +meat counter +yagi +crab cactus +cacao bean +bowfin +alley cat +stonefly +Eastern cottonwood +vernier scale +marginal wood fern +dancing-master +detective +yam +textile screw pine +hooch +spinet +single prop +sassafras +goose barnacle +triple cream +China tree +peeper +dressmaker +snatch block +ironmongery +dressing case +creeping bellflower +silver sage +honeydew +eastern red-backed salamander +peg +nombril +danish +mashie +anarchist +alligator snapping turtle +shepherd +American white pine +runner +chalice vine +rheumatologist +defibrillator +yellow chamomile +lemon balm +peacekeeper +native beech +sandwich board +Bavarian +titrator +paneling +deer mouse +poteen +sugar snap pea +meadow salsify +town crier +best +basinet +common myrtle +night lizard +cushaw +Tampax +camphor tree +gentile +orange peel +putty knife +pyromaniac +Brummie +fever tree +double +nest +inferior +cabbage tree +graduated cylinder +mucor +woodborer +earthwork +potato salad +four-hitter +gooseberry +water vole +ziggurat +grapefruit juice +four-in-hand +cranberry bush +diode +videotape +Mohican +niacin +beetroot +shirtsleeve +cork tree +two-eyed violet +white ash +drawing chalk +baked Alaska +bone-ash cup +toastrack +diastema +bed jacket +dwarf astilbe +yellow honeysuckle +cow pasture +sheet pile +saxhorn +upholstery material +California white oak +Spanish bayonet +horsemint +littleneck +deflector +magician +standard transmission +blue marlin +shallot +feijoa +collar +board +jump suit +common staghorn fern +priory +Xhosa +Loranthaceae +barbecued wing +barmaid +spit +lemon juice +umbrella plant +field pennycress +centenarian +queen bee +fish stick +black bread +dirk +secularist +German American +spotted weakfish +iron foundry +speed bump +yellow-fever mosquito +gag +frame +black-eyed pea +alcoholic +involucre +sperm whale +balanced diet +wax bean +butcher's broom +winter heath +Mainer +Australian pine +gas guzzler +double-breasted jacket +pod +palo verde +trimmer +wattmeter +dyer's woad +crotalaria +vine maple +sulky +jack pine +thumb +Wilton +Panchen Lama +welder +badminton court +business editor +Arabian coffee +Kamchatkan sea eagle +foamflower +steep +plane +freckle +cerebral cortex +Vouvray +tea +forest tent caterpillar +neckerchief +accelerator +jig +bridal wreath +highball glass +New England clam chowder +beach strawberry +call waiting +baton twirler +double boiler +Dutch elm +car bomb +filmy fern +breviary +Florida gallinule +dace +parsnip +riparian forest +crescent +earplug +grab bar +cusk +foglamp +screwtop +black mangrove +mascot +Welsh poppy +gas holder +support hose +salsify +red beech +Indian python +caroler +pineapple juice +lowboy +terra sigillata +black olive +hypodermic needle +radio-phonograph +moussaka +miter joint +creche +tuning fork +black wattle +affiliate +vertical tail +kiwi +red morning-glory +piping crow +runway +Kashmiri +studio apartment +sea feather +Judas tree +boatbuilder +corn earworm +fallboard +Victrola +lechwe +goat willow +turret clock +Canada anemone +leaf lettuce +savoy cabbage +headpiece +Lebanese +fothergilla +hemlock +toolshed +silver tree +blue-headed vireo +weatherman +cylinder +caltrop +adjutant bird +driving iron +millet +European woolly thistle +rose apple +clown +schoolfriend +eastern coral snake +barbecue +executive vice president +long-billed marsh wren +brittle bladder fern +tank destroyer +left-hander +matting +catchment +balsa raft +eastern fence lizard +color tube +corncrib +electric typewriter +westland pine +elder statesman +whey +plonk +mound +cittern +nest egg +copyholder +China aster +basking shark +gavial +common duckweed +vanilla orchid +red-shafted flicker +granadilla +sylph +sty +vest pocket +potherb +little brown bat +Trapezium +ordinary +adult +purple-fringed orchid +abseiler +disco +metal detector +beefsteak fungus +ilang-ilang +barley grass +hawser +suture +brake shoe +staghorn coral +barbecue sauce +Browning machine gun +sarcophagus +disa +oven thermometer +rosemary +track +gorget +quince +royal +piston ring +teak +pin cherry +Komi +walking fern +sloe +synchronous motor +fire-bellied toad +Teleprompter +co-star +cape gooseberry +oscillograph +bass clarinet +cock of the rock +Tyke +showy milkweed +safety valve +branch water +sweet marjoram +hugger +crampon +fairy godmother +band-tailed pigeon +snow-on-the-mountain +minibar +foreland +grosgrain +dita +rampion +calligrapher +jointed charlock +master +sheepshead +barrelhouse +Carolina allspice +mastic +brake pad +whiskey sour +casement window +conveyer belt +stolon +pavonia +shinny +witch elm +logwood +hostel +pageboy +vesper sparrow +pyrrhuloxia +common carline thistle +wafer +boysenberry +screw augur +hack +American white oak +governor general +Mother Hubbard +game fowl +drosophila +delft +nymphet +tollbooth +chough +Russian dressing +plum tomato +American saddle horse +dusky salamander +black medick +red valerian +cordage +Elastoplast +conacaste +backlighting +swell +riveting machine +cowpen daisy +openbill +water speedwell +picture hat +crested myna +servo +bletia +garden trowel +muscadine +common caper +false lily of the valley +aralia +sharp-tailed grouse +cigar smoker +bandoneon +Chinese alligator +crazy +point lace +charcoal +Texas horned lizard +marinara +backstay +Gatling gun +piston +game fish +fall armyworm +grammarian +beer hall +guadalupe fur seal +sugar palm +peanut +velvet ant +light machine gun +rya +cling film +adobo +myrtle oak +angelica +balsam apple +windbreak +brother-in-law +snap brim +automobile factory +clavichord +dusky shark +edible banana +altar boy +California lady's slipper +schoolbag +wax bean +Atlantic walrus +bullpen +straw wine +thatch palm +potluck +tamarind +charcuterie +sod house +tie rack +liebfraumilch +clinician +scarlet lychnis +Spanish iris +bread knife +water oak +bedpan +Angolan +bassarisk +Alaska fur seal +African wild ass +milk float +froghopper +Verpa bohemica +water cooler +chop suey +ranker +red helleborine +Prince of Wales +marmalade tree +car train +giant red paintbrush +desert sand verbena +right whale +baron +stevia +asterism +five-spot +catapult +Silex +fiberscope +refresher +beef Bourguignonne +snood +divot +waterproof +crabeater seal +Missouri primrose +bumper guard +rock opera +Lilo +coffee can +smokehouse +buffalo grass +propjet +ice tongs +poop deck +acorn barnacle +veal parmesan +shower room +collins +ringhals +silage +jawfish +trouser cuff +contour feather +songstress +rachis +White Russian +stanchion +mastaba +flatbed press +viand +legal representative +espalier +organic light-emitting diode +sushi +scorer +haricot +pinna +plectranthus +jungle cat +dried apricot +coach horse +white fringed orchis +veal cordon bleu +bath +dallier +marching order +donkey jacket +Panama tree +aerator +klaxon +pinnacle +shouldered arch +lesser celandine +common eland +Grand Marnier +cock of the rock +phlomis +Japanese umbrella pine +morning room +dead-man's-fingers +little auk +bascule +house paint +home fries +great skua +cesspool +flying gurnard +wild crab +checkerbloom +Wollemi pine +cheese dip +coif +charwoman +tea ball +waif +Arctic ground squirrel +parishioner +stabilizer bar +potentiometer +black cohosh +medlar +willow oak +cascara buckthorn +scoutmaster +Canada lily +poppy seed +paper mulberry +blackthorn +garrison cap +inductee +aeschynanthus +interior live oak +black spleenwort +wild service tree +sling +nicad +swab +sego lily +eiderdown +fruit cocktail +pallasite +weeping spruce +shiv +sea lamprey +coachman +half binding +American white birch +gainer +Concord grape +yellow birch +fucus +common room +io moth +red osier +crucible +galangal +salmagundi +pepper steak +cap opener +swizzle stick +tomato juice +Nobelist +Sarawakian +African monitor +sleeping beauty +stereoscope +curd +pyramid bugle +applejack +dosser +rake handle +pilot light +Eames chair +Scotch and soda +bell heather +dinette +blackpoll +dogie +sound camera +cattle guard +mashie niblick +edible cockle +monocle +steak tartare +partaker +sidesaddle +communications satellite +porkfish +water hemlock +drawbar +ultramicroscope +Jamaican cherry +craftsman +lovage +common apricot +drum majorette +backsword +smooth alder +Amniota +dribbler +theosophist +dolman +ivory tree +Green Beret +pipe smoker +mayoress +mignonette +crampon +henbane +kirtle +death's-head moth +instep +great St John's wort +lorry +black-necked cobra +ball carrier +Jordan almond +byway +earless lizard +marble +andiron +high-protein diet +buzzer +ice floe +crankcase +Bofors gun +sockeye +veery +Delaware +caravansary +prairie coneflower +star apple +suiting +cot +call forwarding +American gallinule +glossy snake +rose chafer +instant coffee +placket +Tarahumara +pulsar +philodendron +orange tortrix +cypress spurge +Welsh rarebit +music box +giant crab +vanilla bean +water thrush +prayer shawl +gouge +promoter +dagga +black currant +bitter cassava +drain basket +snare +digital audiotape +retainer +olive drab +gluten bread +graham cracker +cheddar pink +caregiver +spray paint +Anglo-American +boatyard +backbencher +Link trainer +bell arch +weir +arbor +millionairess +sour cream +earthtongue +crawlspace +crossjack +balalaika +crupper +western redbud +guinea hen +rangeland +gaboon viper +common louse +single-leaf +horseshoe +balsam poplar +triskelion +jack-in-the-box +jester +rain stick +glove compartment +imperial moth +Japanese beech +biotin +turnip +oligarch +western skink +mudguard +retsina +data system +green bristlegrass +visiting professor +beaded lizard +weathercock +Sloppy Joe +high tea +lightweight +record sleeve +cooler +nodding onion +pigs in blankets +torque converter +district attorney +bunting +orrery +radiator hose +common plum +wood spurge +calamus +chicken Kiev +pin +lath +telephone bell +thistledown +audiotape +gypsy moth +snuffer +pari-mutuel machine +peanut butter +hearthrug +sack +Old World yew +chives +stovepipe +xenolith +mattock +mangle +electric chair +backup system +Empire +blackwash +dodder +Allegheny chinkapin +finger plate +junk +brown rice +wild angelica +chinaberry +mason +rasp +den +violet wood sorrel +nosewheel +plenum +merino +kirtle +Igbo +ensign +sex symbol +Belgian endive +sugarberry +yellow salsify +purple emperor +atlas +African clawed frog +leatherjacket +midwife +sac fungus +European cuckoo +three-day event +Mexican poppy +wagon tire +armyworm +rain gauge +Oregon ash +columbarium +spectrophotometer +Milanese +pointing trowel +casualty +Eastern hop hornbeam +lobe +mouthpiece +au pair girl +giant water bug +Browning automatic rifle +laser-guided bomb +drone +white alder +cockleshell +mufti +gravy +berm +boat hook +marshmallow +pet shop +cowpea +tactician +wading pool +anchovy dressing +flip +shackle +Wedgwood +thick-billed murre +erecting prism +giant salamander +sleeper +quiver +chain store +wing tip +New World tapir +witches' butter +gendarme +ginseng +common maidenhair +graduate nurse +balsam pear +hoatzin +philanthropist +axle bar +gas meter +moth mullein +ragbag +Chinese cabbage +celery stick +rutabaga +scalpel +cape marigold +variometer +argali +brig +shuffleboard +wort +Orlon +epiphyllum +allice shad +coffee filter +solar telescope +Japanese linden +thinning shears +golden wattle +queen triggerfish +millinery +surfbird +flame fish +clove +dicamptodon +red-bellied terrapin +turmeric +baya +air horn +Indian coral tree +punnet +sharkskin +water crowfoot +bight +desert iguana +Texas toad +volva +dredge +Turkey red +chemical plant +gemma +dice cup +orange marmalade +mistletoe +surveyor +frozen orange juice +pallette +poultryman +burbot +courlan +captain +saddlery +bodyguard +dwarf tulip +black ash +pulse +nailbrush +tickseed sunflower +legless lizard +shirtwaist +polling booth +chickeree +garlic chive +common thyme +multichannel recorder +screw thread +sangoma +calliopsis +geoduck +colleen +bandicoot rat +pastis +swamp sunflower +scorekeeper +Honduras mahogany +Australian pitcher plant +triangle +elevator shaft +green pea soup +carrel +prairie aster +bird's-nest fungus +scarlet clematis +gook +mescal button +carcase +mulatto +ejection seat +strawberry daiquiri +goat grass +car battery +babu +chief of staff +monilia +Siberian crab +ridge rope +Morchella semilibera +nutmeg +moosewood +graham bread +California four o'clock +zwieback +velvetleaf +abelmosk +shadow box +corned beef hash +newsreader +backstairs +cutwork +sherbert +tooth fungus +angel-wing begonia +greasepaint +common milkwort +potato vine +CD drive +crepe de Chine +sporting man +koto +armet +barking frog +celeriac +drainage ditch +black box +steel blue +clotheshorse +corn speedwell +drawknife +spritsail +vichyssoise +modeler +pocketcomb +limey +suslik +cockpit +digester +brig +raita +troll +benedictine +rock wren +lock +Barnaby's thistle +school bell +school ship +Soave +falchion +swaddling clothes +terrine +smoke screen +rivulus +sweet lemon +cullis +bustier +peppermint +Philadelphia fleabane +Hampshire +active +charnel house +face guard +Quebecois +facilitator +tongue depressor +bitternut +heath aster +sapodilla +bluestem +centrist +Canterbury bell +needlenose pliers +groats +tapa +Qatari +paper feed +tilt-top table +plastering trowel +brazil nut +rotogravure +patriot +manicurist +bacon and eggs +puffbird +lightweight +golden willow +kaiser roll +duff +girandole +seaside daisy +Kurdistan +Skivvies +showboat +fire bell +lock-gate +greater masterwort +weald +ice ax +toetoe +mess kit +bucking bronco +black turnstone +backscratcher +backpacker +basement +marbleization +trigger +satsuma +fall-blooming hydrangea +mountain lady's slipper +yellow oleander +crookneck +ex-president +Venn diagram +psaltery +bulwark +old boy +linear leaf +aril +butt weld +fall webworm +pruner +bald-faced hornet +nougat +tailgate +field speedwell +potsherd +center punch +long beech fern +desert paintbrush +canyon treefrog +bushel basket +Eurasian +swamp horsetail +cryptanalyst +wicket +school newspaper +captive +spider brake +electric mixer +tumbleweed +mason wasp +sash window +paddock +wet bar +oxtongue +stevia +wheat rust +scute +switch engine +mud dauber +dotterel +snailflower +common barberry +mulligatawny +cinnamon bark +cigar box +trivet +proof spirit +cream soda +western grey squirrel +baby powder +Bren +Japanese yew +sailcloth +Basket Maker +bannock +basidiocarp +aphelion +erect bugle +limiter +bosc +Przewalski's horse +helmet orchid +audiometer +battle cruiser +grass widower +staphylococcus +Congolese +common pitcher plant +parliamentary agent +Virginia snakeroot +mockernut +Siberian elm +backbench +rough +chervil +chlamys +nationalist +galantine +screwdriver +falsifier +cancerweed +spur +jerkin +porte-cochere +dill pickle +Montagu's harrier +tetrode +true fungus +American quaking aspen +vitamin B1 +leopard lily +eggdrop soup +aurochs +core bit +Jaws of Life +trousseau +parquetry +Disciotis venosa +tender +beef goulash +vitamin K1 +pepper spray +covered smut +hook +sports announcer +weapons carrier +foxtail grass +sloe gin +mezereon +antifouling paint +pavior +pile driver +security consultant +monkey-wrench +Indian hemp +amaretto +American wistaria +A-line +market strategist +rainbow runner +souvlaki +binturong +stiletto +gastrula +Vietnamese +Old World hop hornbeam +cold cathode +pier table +houndstooth check +prop root +leaf-footed bug +sedge wren +Dutch iris +drop curtain +opossum rat +lame +pollen tube +doubletree +compression bandage +pinon pine +catmint +pier arch +kingmaker +deanery +loofah +fullback +fencing mask +flying boat +carpet sweeper +lemon-scented gum +Accipitriformes +kit +pigfish +clipper +dolmas +lesser centaury +blood agar +water violet +raw milk +lemonade +vicar-general +supply closet +Anzac +confectioner +ignition key +velvet grass +white willow +John Dory +ruddiness +wheel +common horsetail +hubbard squash +speculum +Spanish bayonet +mountain mint +glint +foxhole +housemate +bootjack +sleigh bell +clog dancer +Mexican mint +rendering +Hausa +star saxifrage +spring squill +clothesbrush +liquid metal reactor +Columbia tiger lily +sorrel +cartwheel +Jersey +Caucasian walnut +desert willow +surveyor +elbow +Santa Gertrudis +fringe bush +industry analyst +lyrebird +Cortland +arroz con pollo +catechist +tank top +jew's harp +cereal oat +heartleaf +short sleeve +butty +butterfly plant +stud finder +felloe +beer garden +clevis +wood warbler +demerara +cornetfish +mince +Jamaica rum +Spanish broom +binnacle +camise +ferrule +Copt +hall +minicar +scimitar +cryptogam +miter box +limestone fern +Marsala +Parliamentarian +gravy +woolly bear moth +formula +squash bug +pigmentation +plate +skin graft +radiotelegraph +hellbender +soft pedal +lavender cotton +propagator +Bailey bridge +cottage pie +rotgut +A battery +pintle +off-line equipment +European swift +shrimp butter +plumb bob +trunk lid +succotash +yellow cypress +heartleaf +antelope squirrel +sambar +maternity ward +deciduous plant +bartlett +Riesling +sour cherry +Klansman +poke +academician +sociolinguist +bird's nest fern +common privet +scale fern +tachograph +oyster stuffing +pusher +green June beetle +staghorn sumac +lockage +master +bap +harlequin +blackfly +spotted coral root +kahikatea +cabana +riot gun +apple mint +kob +praline +confidant +pahautea +float +city father +Zen Buddhist +pessimist +conference center +banksia rose +comfit +sweet cicely +winged bean +henroost +myope +bunt +nailfile +yellow mountain saxifrage +cruise control +abandoned ship +water chinquapin +spanker +wing nut +puccoon +pier glass +Atlantic sailfish +medlar +buttercrunch +rough-skinned newt +planter's punch +Dutch iris +control key +committeewoman +torpedo-boat destroyer +garambulla +tree heath +gladiator +September elm +inclinometer +snowbell +call-in +sunsuit +microfiche +bluestocking +cheval glass +server +franking machine +sugar syrup +Macoun +transport ship +alderfly +wash-and-wear +Abbe condenser +bush nasturtium +wild leek +canary seed +Northern Baptist +sweet wormwood +jaboticaba +cardroom +autoradiograph +ash-pan +sprinkler system +rattrap +claymore +parts bin +forest red gum +thermonuclear reactor +Indian crocus +lector +heir apparent +leafy spurge +masquerader +varicella zoster virus +cucumber tree +hedger +Shumard oak +zooplankton +quartermaster +arrester +bridge +hop clover +meadow foxtail +winter hazel +portable circular saw +penuche +limpa +blue toadflax +mesophyte +Alpine anemone +pet sitter +avocado +streptococcus +fiber optic cable +river red gum +hornist +chicken taco +red spider +tape grass +densitometer +salmonberry +tiger snake +hot toddy +silver fern +candlenut +buckram +local call +defoliator +king +mahoe +lever lock +social insect +winter purslane +bootblack +fireball +ramie +bellbird +prepuce +capote +Chinese forget-me-not +Pisces +costume +California black oak +tree lupine +golden polypody +liger +California whipsnake +urodele +sapodilla +skillet bread +duckpin +supremo +asparagus bean +kampong +endameba +cow pony +rider +motherwort +Persian iris +soursop +kohlrabi +Parisienne +irons +doubles +feijoa +farmplace +cottage cheese +bezoar goat +subcontractor +blunderbuss +down +purple martin +Lapp +crenate leaf +tobacco pouch +beach towel +Santa Lucia fir +monetarist +stringer +ocellated turkey +Texas purple spike +ackee +caddy +hedge mustard +second-rater +strawberry bush +valedictorian +steak sauce +prairie gourd +aspirant +mint +Valenciennes +vodka martini +American persimmon +big brown bat +Mycenaen +mouthpiece +norfolk island pine +pennyroyal +Jewish rye bread +granadilla +tract house +wall +shuttle helicopter +blackjack oak +Lippizan +storm window +white zinnia +sickle +sushi bar +polish +baldric +brooklime +church hat +control circuit +vicuna +death adder +eukaryote +durmast +field soybean +jacket potato +wild basil +queen consort +brooklime +octant +blue false indigo +broccoli raab +step-down transformer +date bread +blue ash +duffer +oak chestnut +pennant +wedge +Florentine iris +morion +weakfish +morning dress +public address system +spearmint +Ashkenazi +sow +interpreter +Metis +pita +iron lung +parfait glass +cylinder lock +immortelle +obstetrical toad +tee hinge +successor +western +working girl +julienne +AND circuit +spaghetti junction +fer-de-lance +enlisted woman +star +lightning rod +bilge pump +pacer +horse nettle +African oil palm +blastocyst +air hammer +bamboo fern +remote terminal +lambkin +money cowrie +Pelham +clinical thermometer +wiggler +guru +false indigo +tea bag +foredeck +king +baby shoe +mule +grab bag +silver-bell tree +knitting machine +cobia +roulette ball +larder +button pink +rumble seat +noria +queen mother +solar thermal system +aquaplane +highbrow +rusty blackbird +desktop +lima bean +pontoon bridge +watercress +wild cabbage +tumbleweed +dressing sack +compact-disk burner +spittoon +marrow +sporophyte +second fiddle +pot-au-feu +specialty store +dry +mole +khadi +japonica +lovage +squamous cell +lobe +European creeper +brown pine +bladderpod +rumble +French Canadian +mascarpone +Pacific halibut +perennial ryegrass +wine lover +turbot +longwool +silver tree fern +dust cover +synchromesh +corn pudding +alpine azalea +garboard +cane sugar +observation dome +condensation pump +hind +taximeter +hand drill +gas thermometer +jammer +buffing wheel +handstamp +prairie mallow +turkey stew +sun spurge +duck pate +kibble +Cassin's kingbird +apadana +Devon +grinner +oocyte +blank +header +schoolmaster +guard ship +intravenous pyelogram +rimu +luff +Mediterranean fruit fly +singlestick +lady-in-waiting +curb +birch +limekiln +orthoscope +serotine +Spanish oak +swamp cottonwood +edger +city man +picnicker +white basswood +Parsons table +Christmas begonia +perspirer +Pacific tree toad +Cape tulip +finger bowl +blue pike +greengage +handcar +milkweed +potbelly +river dolphin +creel +typewriter carriage +banteng +pawnbroker's shop +huon pine +biennial +man of action +foundress +caveman +featheredge +jordan almond +sandblaster +coralberry +low-calorie diet +hoot owl +garter +bain-marie +wrecker +fenugreek +double-hung window +idol +scullery +balloon vine +summer savory +winged spindle tree +Helvella crispa +walrus mustache +gas engine +boulle +rush grass +rue +hoe handle +cat fancier +deerstalker +dunker +American red plum +fall dandelion +groover +sprag +stair-rod +wish-wash +pricket +architrave +California laurel +net melon +Arizona sycamore +executive secretary +silverweed +silky cornel +surface ship +square sail +common purslane +villa +holly-leaved cherry +sweet birch +pecan +artillery shell +breast pocket +pirogi +scarlet runner +rabbit brush +mealworm +leather carp +palette knife +Jerusalem sage +boneshaker +slit lamp +digital voltmeter +polar glacier +square-rigger +homogenized milk +Sten gun +lesser calamint +pyrograph +Korean lawn grass +Zinfandel +crepe fern +western ragweed +clasp knife +distributor housing +cartouche +scooter +ski parka +jackknife +Carolina spring beauty +soft diet +candlesnuffer +horse trader +step stool +agouti +accelerometer +annual fern +judge advocate +angelica +roll film +treehopper +ombu +comer +sultanate +kitchen help +hooded ladies' tresses +milking machine +knuckle joint +Jamaica honeysuckle +music teacher +sauerkraut +Weston cell +slivovitz +Worcester sauce +tall bellflower +chancery +prophetess +casquet +shortfin mako +sorus +visual display unit +asp +grenadier +black pepper +crottle +erasable programmable read-only memory +jabot +ratchet +disk controller +chief petty officer +tap wrench +white mountain ash +cultivated rice +flying phalanger +skillet corn bread +BB gun +Elamite +European red elder +reed rhapis +ciderpress +inga +torpedo +wild teasel +bean curd +oeil de boeuf +acuminate leaf +bitter lemon +hitchrack +Lorraine cross +hostess +European dogtooth +adz +polonaise +rock sandwort +Waldorf salad +myrmecophile +klystron +mole rat +draba +corn borer +robusta coffee +chub mackerel +leatherleaf +chronometer +Moselle +sea aster +fennel +slop basin +constable +Brunswick stew +hydraulic pump +French omelet +icebreaker +Manx shearwater +press of sail +ninepin +blue succory +bootstrap +hallstand +chit +firefly +bearded seal +fuel filter +jezebel +mate +Roquefort +cheesecloth +plasterer +blue pimpernel +lake dwelling +shrink-wrap +goat cheese +common gum cistus +coastland +Sunday best +wild tobacco +mandrake +common unicorn plant +barbican +culotte +blockhouse +German iris +tarragon +caramel +wild rosemary +grain +voyager +squirting cucumber +eastern narrow-mouthed toad +creeping fern +luge +saffron +garland flower +furnace room +starship +Oriental scops owl +Italian honeysuckle +berserker +Chinese elm +scrubber +bishop pine +French polish +compromiser +skimmer +river shad +lobster thermidor +leadwort +man-of-the-earth +razorblade +vicegerent +empress +link +ham and eggs +wild lily of the valley +blackfish +splicer +fossa +mara +moneygrubber +brachiopod +fauteuil +caldera +finish coat +croupier +termer +leopard's-bane +sei whale +molucca balm +dolly +dog food +term infant +soft roll +episcia +sewer +inquiry agent +active citizen +perry +California newt +moon shell +bladderwrack +common shrew +dill +Dutch elm fungus +key lime +electrometer +divorce lawyer +lamb's-quarters +apple turnover +shipmate +Guernsey +legionnaire +electric blanket +Rocky mountain pinon +tobacco mildew +stinking iris +forestiera +departure lounge +wiper motor +jurist +scarlet runner +pallbearer +batter's box +inertial guidance system +fines herbes +oilcan +sisal +mustache cup +steamed pudding +Visayan +fiesta flower +lady tulip +lungless salamander +batiste +electrical system +blazing star +car carrier +Walloon +mother hen +stump +mulled cider +secondary coil +Alexandria senna +etui +scrumpy +Havasupai +jawbreaker +glume +ex-husband +Eskimo +Joint Direct Attack Munition +number theorist +five-hitter +pinstripe +Olympian +common mackerel +stone bass +bigos +Bahraini +airbrush +great ragweed +glass lizard +hand fern +roundel +riding master +shoetree +yellow avens +old fashioned +dolman +stinger +nursling +legate +faille +golden fern +bedpost +shop steward +kidney bean +bladderwort +internist +limeade +Bruneian +Coloradan +playsuit +wintergreen oil +Cantabrigian +mutton snapper +shot putter +hand grenade +moccasin +cobnut +marrow +separatist +cockscomb +discharge pipe +Gabonese +spade bit +chicken cordon bleu +varnish tree +European wood mouse +striped gentian +Ayrshire +curassow +moo goo gai pan +malarial mosquito +glow tube +ledger board +bib-and-tucker +European chestnut +suffragette +color wash +gaffsail +golden larch +voting machine +Kahlua +lungi +amusement arcade +Uzbek +butternut +mold +mule's ears +dickey +shrimper +trophozoite +dreadnought +shepherd's purse +greenhouse whitefly +spotted gum +copperware +perfect game +semigloss +spawn +telecom hotel +stakeholder +mason wasp +flibbertigibbet +chin strap +fringed pink +saki +urchin +memorizer +roulade +whiting +cling +corncrake +Queen of England +choo-choo +empty +heating pad +playmate +visualizer +popcorn ball +absconder +sou'wester +target acquisition system +mock-up +dental floss +tray cloth +haddock +bulblet fern +housing commissioner +delayed action +anchor light +harbor porpoise +water wings +PT boat +night latch +fennel +doorframe +green-tailed towhee +grey polypody +torture chamber +American germander +Chinese wistaria +cattalo +accompanist +rifleman +alpine clover +contrarian +lemon peel +Mexican cypress +sprog +dado +Galilean telescope +desmid +lockup +Latin +American raspberry +mescal +butternut +prairie orchid +downy yellow violet +green hellebore +radio compass +bread and butter pickle +Cherokee rose +knish +destroyer escort +Arkansan +langlaufer +pyxis +winter savory +velocipede +motley +winter savory +law student +barren ground caribou +apple dumpling +field hospital +works +city editor +European flatfish +Morchella crassipes +life office +boot camp +cream sauce +cape aloe +acetate disk +devil ray +tile cutter +Plymouth Rock +microspore +godown +Syrian +tiercel +American cranberry +lesser spearwort +anopheline +Spanish oyster plant +wire cloth +attic fan +birch beer +small computer system interface +crook +ribbon fern +explorer's gentian +nagami +I-beam +rosebud cherry +Jerusalem artichoke +Stillson wrench +pluralist +district manager +Levantine +orangeade +part-timer +post horn +Oregon grape +contadino +cargo helicopter +silverpoint +chaja +California bluebell +case +Shasta +cheese cutter +Leishmania +avalanche lily +iron horse +bialy +Yana +Delawarean +Prussian +nonpareil +hammer +hoper +chewink +anil +skim milk +desert four o'clock +crescent wrench +white marlin +blue jasmine +malacca +anadama bread +purple poppy mallow +ganglion cell +ligature +no-parking zone +golden clematis +Cotswold +aliterate +shebeen +yardarm +superbug +fanaloka +stinking cedar +spirochete +wort +pater +heaume +thermocouple +ironing +naval tactical data system +European goatsucker +prairie cordgrass +accused +foreign agent +halberd +western mugwort +esthetician +Persian lilac +cracked-wheat bread +crosscut saw +rock penstemon +paper cutter +crematory +ideologist +cattley guava +margarine +creosote bush +hoary plantain +spark gap +lumberjack +Greek valerian +mission bells +tight end +bigeye +large crabgrass +stone marten +cleat +lentil +bay scallop +lector +charger +assemblywoman +second lieutenant +boil smut +sarsaparilla +hydromel +cat flea +pinfish +whole milk +hairnet +myeloblast +peasant +blind curve +first offender +dwarf-white trillium +Brother +coatdress +gun emplacement +tamarisk gerbil +snap +air cushion +trailing edge +potato vine +gig +everlasting pea +champion +dibble +rattail cactus +timothy +prince's-feather +cutlas +lockring +sealing wax +Brussels lace +corn mint +highboard +she-oak +wild celery +pillar +Burberry +Hakka +leucothoe +bell tent +gallery +coontie +leather fern +smack +adenovirus +linoleum +chain wrench +tammy +gas fixture +nut bar +baneberry +butterscotch +goat's rue +bullock +grey snapper +mother-in-law +hyson +wayfaring tree +mollie +needle spike rush +buckwheat +bayberry +brush-tailed phalanger +dry rot +harborage +stormy petrel +Oriental beetle +Atlantic halibut +coping saw +simple fruit +viscose rayon +surgeonfish +upstairs +security system +common ragweed +verticillium +pancake batter +hawk's-beard +Dutchman's-pipe +refrigeration system +European parsley fern +Ivy Leaguer +totalitarian +gonococcus +towhead +showy sunflower +pallium +multiengine airplane +hair trigger +rabbit-eared bandicoot +siskiyou lewisia +fuel system +flat arch +broad beech fern +Alpine lady fern +bracken +Kentucky black bass +rut +mountain maple +tunaburger +umbrella fern +white-headed stilt +meat hook +panhandler +washhouse +barnyard +safety lamp +leg +ripple mark +paper +sagebrush lizard +light heavyweight +common nutcracker +operator +stalking-horse +horseless carriage +fishhook +suction cup +peg +Ungulata +false teeth +round-bottom flask +Luba +campaign hat +firebox +rudder +parapet +ice pack +appellant +spirit stove +metheglin +common bamboo +soapwort gentian +pannikin +time capsule +burn bag +folk poet +tropical prawn +end man +new caledonian pine +linen +web +free trader +jury box +railing +pignut +leaker +potboy +rubber boa +white snakeroot +plumber +Candida albicans +surfboat +woman +promulgator +eyecup +wild China tree +rattlesnake master +Viyella +alpine salamander +ailanthus silkworm +Albatrellus ovinus +war room +meadow vole +robotics equipment +rotary actuator +Engelmann spruce +pinesap +beefcake +native speaker +ridge +injector +water chute +salmonberry +decoupage +bottlebrush +date plum +circlet +American mountain ash +pocketbook +horsemint +sweet four o'clock +kirpan +pinto bean +chervil +equator +range animal +candy thermometer +calanthe +cul +stipendiary +brahman +pelican crossing +topgallant +wild senna +sliding window +carrier pigeon +Tatar +quadruplet +bumboat +spearmint oil +slip clutch +young Turk +golden yarrow +shank +glasswort +dental plaque +Manduca sexta +Northern bedstraw +dent corn +Life Saver +western wall flower +bedder +wherry +Tuscarora +scrapple +borstal +reflux condenser +problem solver +nondriver +perforation +eastern cricket frog +white wood aster +broad buckler-fern +Cape primrose +herringbone +head louse +earl +baton +recording system +primary color for light +cherry laurel +pomfret +ratafia +chocolate milk +obscurantist +revisionist +rood screen +magnetic needle +commensal +oil tycoon +celebrant +domicile +harvest mouse +California nutmeg +greater spearwort +black-billed cuckoo +winepress +demographer +straw boss +diabetic diet +sweetmeat +rabbet +ming tree +basketweaver +freestone +walk-in +Aryan +box coat +audio amplifier +chicken salad +churidars +whydah +box +batman +siren +selectman +gouger +drip coffee +Caesar salad +interpreter +whinstone +grey goldenrod +minicomputer +honey crisp +hypercoaster +Irishman +swamp white oak +reed canary grass +globeflower +cynthia moth +fennel seed +canthus +chino +blind date +tar pit +watermelon begonia +fishtail palm +overcast +Pearmain +primary color for pigments +coal seam +wherry +safety bolt +cretonne +Michigan lily +inflater +moneybag +huckleberry +brassard +bush vetch +looking glass tree +pinwheel roll +alfalfa sprout +sea kale +clinometer +achira +lorgnette +potter wasp +gilded flicker +tody +capulin +captain's chair +crackle +gerardia +prie-dieu +venture capitalist +New Jerseyan +block and tackle +elf cup +bur reed +automatic transmission +wax palm +flytrap +crack willow +coachwhip +swizzle +lugger +Dewar flask +baster +oxyacetylene torch +Culex quinquefasciatus +St Peter's wort +wild hyacinth +Russian almond +burrfish +wintergreen +katsura tree +butcher knife +perfumery +thresher +porte-cochere +sheepwalk +hypotenuse +Dalmatian iris +buttercup squash +demiglace +goldenseal +preceptor +rigger +poikilotherm +old-age pensioner +posthouse +wood horsetail +repeater +reciprocating engine +Rambouillet +terra cotta +togs +battledore +horizontal tail +missile defense system +trier +morello +woolly adelgid +munition +double creme +in-fighting +squirrel corn +crow's nest +antler moth +brake cylinder +bandoleer +noticer +Parmesan +hipline +cheapskate +Dubonnet +mole rat +bog aster +ribbon tree +meadow rue +nard +ratel +loose smut +snapping shrimp +golden glow +basil thyme +Florida strap fern +moonshine +flume +lace fern +black bream +orchestra pit +archerfish +exile +ringdove +career man +godfather +bottom-feeder +pasteurized milk +dental implant +pedicel +Catalpa speciosa +yellow foxglove +lancet arch +steam shovel +sampan +patrol boat +sailor cap +tollgate +monal +velociraptor +cacique +jack oak +cursed crowfoot +creep +Parry manzanita +common matrimony vine +grace cup +caecilian +spurge laurel +prickly lettuce +Regius professor +camail +Sitka willow +Courtelle +gin sling +dogmatist +guest +saltine +dust cover +sport +sweeper +feist +lady's-eardrop +vibist +wire stripper +tenpin +interplanetary space +beet green +pruning knife +drainage system +gunnery +ballet master +lime juice +flak catcher +lacrosse ball +Canadian aspen +beatnik +railhead +utilizer +spadefish +Arizona white oak +city university +dense blazing star +hedger +chain pickerel +right-hand man +namby-pamby +nacelle +redneck +tumbler +Chief Secretary +cannon +cupola +kummel +papaya juice +Burton +Stanley Steamer +loganberry +stylus +square meal +rock bass +western ladies' tresses +dramatist +assignee +tandoor +trumpetwood +segregator +green adder's mouth +coral necklace +ani +iceboat +densimeter +oxtail soup +kernel +cos lettuce +greenishness +panchromatic film +Parker House roll +oatmeal +backsaw +double Gloucester +bailey +storage cell +giant +coconut milk +broadtail +barouche +loir +soybean meal +white-leaved rockrose +junction barrier +spandrel +sweat bag +goldilocks +flowering wintergreen +cockspur +beef fondue +holding cell +cardamom +cagoule +Kamia +tangelo +Herschelian telescope +wine bar +kachina +sand sage +guy +ivory palm +citrus mealybug +topper +ladyfish +force pump +fanion +calaba +Iowa +orrisroot +ivorybill +Secretary of Agriculture +gagman +dry cell +hypnotist +kenaf +grey alder +deathwatch beetle +gagman +magnetic stripe +trap door +abdominal wall +prefab +broomcorn millet +architeuthis +angler +Pacific giant salamander +barbette carriage +low-fat diet +veal scallopini +B battery +wallah +landing flap +pistachio +jaguarundi +nagi +cicerone +felt fungus +Aertex +stocks +smooth aster +patchouli +lemon sole +sleeper +basket fern +dundathu pine +anjou +Moreton Bay chestnut +broom sedge +candid camera +red angel's trumpet +oilstone +cinnamon toast +Pacific walrus +fruit custard +Jehovah's Witness +mate +voyeur +Esselen +achromatic lens +sanguine +brine shrimp +dunce cap +swot +transit instrument +grey willow +pack +bench clamp +Nova Scotian +gadgetry +silvery spleenwort +enchantress +rough fish +morula +giant taro +sorus +roux +polyhedral angle +spruce beer +Chicano +cola extract +outfielder +kohleria +white-rumped shrike +car-ferry +subway token +spoon bread +totara +corn borer +bowhead +tensimeter +water scooter +flickertail +Catholicos +pleaser +blue-eyed Mary +calabash +handyman +cascades frog +facing +scarlet oak +lutist +ginger +tree tomato +Harvey Wallbanger +tent peg +insectivore +fusil +swale +chinning bar +bladderpod +New Dealer +dhoti +proscenium arch +common vetchling +channel +collect call +safflower +Texas tortoise +test equipment +theca +RAM disk +sheep sorrel +rammer +buttonhook +honey mesquite +dominus +babirusa +queen +Aspergillus fumigatus +crash barrier +nonmember +Muscovite +verdin +Australopithecus afarensis +Turkish Delight +stalked puffball +giardia +divider +mountain skink +head smut +pacemaker +evaporated milk +rattlesnake fern +flamethrower +navy bean +bather +steed +showy orchis +stone crab +artichoke heart +phantom orchid +space helmet +swamp laurel +privateer +junior +surcoat +bristlegrass +flower girl +aphid lion +penthouse +lemonade mix +coude telescope +natal plum +scriber +wood nettle +rape suspect +resplendent quetzel +western poppy +choir loft +fore-topsail +thyme-leaved sandwort +erotic +short circuit +outdoors +flowering tobacco +hookup +aviatrix +corker +horehound +horn +swamp pine +water biscuit +cherimoya +vaporizer +courtier +European sole +full skirt +Mother Carey's chicken +cymule +huck +white snapdragon +mountain nyala +country borage +bonduc +casein paint +grampus +shrimpfish +lodge +dragee +black walnut +caraway seed +roper +glass cutter +tab key +Richardson's geranium +demigod +chichipe +Italian ryegrass +cadet +electrograph +rudd +carpenteria +foie gras +lignum vitae +hedge nettle +pledger +American hackberry +flageolet +beaked hazelnut +reflectometer +sticky geranium +marriage bed +white pepper +japanese clover +whiteface +gnat +extrovert +Canada plum +talipot +chicken stew +egg foo yong +fraxinella +skibob +saucer magnolia +jacket +green smut fungus +cloakroom +landing skid +booth +ice milk +dipole +striped coral root +red buckeye +roughcast +breaststroker +cowherb +razor clam +first-aid station +briarroot +clambake +lander +Bramley's Seedling +frail +jird +minisub +luging +poison milkweed +European lobster +epidemiologist +spandex +paloverde +marumi +bypass condenser +punter +petty spurge +Coryphaena hippurus +bilberry +vermillion rockfish +witness box +viscometer +pulque +Massachusetts fern +herring salad +ridge tile +mesa +dwarf grey willow +southern aster +punch pliers +tarnished plant bug +hoop pine +Japanese red pine +benedick +rebozo +silver plate +silver willow +mouse-ear hawkweed +bonito shark +abutment arch +noble cane +tiger rattlesnake +pongee +jumping plant louse +pattypan squash +giant ryegrass +railroad bed +stiff aster +imperial Japanese morning glory +laundry +winter cress +large white petunia +tea maker +pen-and-ink +early warning system +lug +monocot +sea wormwood +breechblock +postage meter +third rail +Mongoloid +Australopithecus boisei +umbrella tent +stirrer +Dumpy level +beroe +post and lintel +green spleenwort +tomato paste +dishpan +stentor +sweatband +cobbler +New York fern +gaff +prairie willow +cyclops +jigsaw +rotavirus +pallet +eastern ground snake +boiling water reactor +acute triangle +agora +European cranberry +roebuck +surgical dressing +busboy +cannikin +feedlot +common pond-skater +cochin +horsehair lichen +fetter +sapote +fichu +dermatologist +fire tongs +creme anglais +foster-mother +laurelwood +chicken snake +mincemeat +rocker +wild spinach +powder and shot +butterwort +auxiliary engine +mamey +hart's-tongue +sucking pig +American turkey oak +troopship +buttermilk +divi-divi +boatswain's chair +soda fountain +southern flying squirrel +elastic +cutaway +housekeeper +renegade +apple rust +bridoon +machicolation +stunt +keyhole limpet +personality +solitary vireo +epidendron +Jihadist +boffin +bettong +terror +partial denture +pusher +saltcellar +capstan +large poodle +Bibb lettuce +low-bush blueberry +staple +banded krait +sickroom +barnyard grass +wandflower +woodworm +bluegrass +squirrel's-foot fern +rabbitfish +delta wing +milking shorthorn +limber pine +guru +gamine +scythe +sweetsop +Gruyere +bloodmobile +mine detector +American mistletoe +silver beech +hound's-tongue +Lombardy poplar +basket fern +pink-and-white everlasting +redtail +Aladdin's lamp +mace +outtake +condensed milk +Canada wild rye +silver perch +waxflower +taxer +Chinese chestnut +Our Lord's candle +mugwump +school system +salp +osso buco +dress shirt +butterweed +low-fat milk +couchette +broomcorn +proscenium +mill agent +smut grass +humpback +southern spadefoot +military leader +canebrake rattlesnake +tailor-made +ebony +beach house +flying gecko +hoary alison +typhoid bacillus +Romanov +vanilla pudding +sweet cicely +Spodoptera exigua +dress rack +flannel +skipjack +bolognese pasta sauce +rooibos +thunderer +blessed thistle +gauntlet +mahatma +granadilla +laurel sumac +Yuma +thyme-leaved speedwell +encyclical +twill +linocut +manna gum +spark arrester +cocklebur +Indian hemp +lemon oil +Hall's honeysuckle +raceway +flop +Himalayan lilac +one-flowered wintergreen +photosphere +silvery spleenwort +convex polygon +canarybird flower +foster-sister +fluffy omelet +palanquin +roll +dandelion green +Javanese +workpiece +Carmelite +bread mold +schlemiel +wild lily of the valley +grugru +solenoid +puff batter +skep +balance wheel +Gadaba +portia tree +mobcap +two-man tent +scuffle +firebrat +ant lion +anise +caster +giant petrel +American water spaniel +naboom +treasure ship +foster-son +fiddleneck +alidade +sugar refinery +wild oat +water beetle +generic +damson plum +abrocome +detainee +pitch pipe +coast +nilgai +radiotherapy equipment +heart-leaved aster +gristmill +grocer +Appaloosa +Cheviot +brake pedal +lantana +cave myotis +Rob Roy +sea spider +latrine +carpophore +recycling plant +coondog +brace and bit +funambulist +eggar +mantelet +postdoc +mezzanine +coco plum +pulse generator +high-vitamin diet +menhaden +mechanical engineer +bergamot mint +Chuvash +grated cheese +helicon +belladonna +beet armyworm +eelgrass +resuscitator +interrupted fern +arrow grass +cistern +Pacific herring +colostrum +journal bearing +Fauve +wrist pin +canape +choice morsel +quadraphony +guard boat +shortgrass +claymore mine +hitching post +cargo door +decoder +gym rat +Cocopa +commander +apple of Peru +seckel +yellow goatfish +dog flea +dodo +oconee bells +Tudor arch +turkey stuffing +ebony spleenwort +wheat flag smut +scolopendrium +Brazilian pepper tree +gusset +inspector +lunar excursion module +baron +plantigrade mammal +Creole +phosphate +aromatic aster +ghee +audiovisual +onychophoran +cotton stainer +lieutenant junior grade +spheroid +amen corner +caper sauce +Caladium bicolor +dyer's rocket +seaside goldenrod +flint corn +Very pistol +rotifer +steeplechaser +rouleau +escape wheel +Namibian +millivoltmeter +emmer +climatologist +agateware +sea lyme grass +inclinometer +water fennel +saddle seat +vicar +garden cress +ski rack +Norfolk jacket +casaba +coast rhododendron +sericea lespedeza +hematocrit +autopilot +tilter +finish coat +Pennsylvanian +shrubby St John's wort +podocarp +percussion cap +ceriman +peanut bar +gean +jack +durra +rotor +carob +cottage tulip +three-spined stickleback +trencher +elevator +kalumpang +abaca +Australopithecus robustus +active matrix screen +water bed +hatmaker +lodestone +cat food +overcup oak +balletomane +popgun +rheometer +process cheese +frog legs +heartleaf arnica +p-n-p transistor +steam turbine +Tulu +scalene triangle +licorice fern +coffee break +trade unionist +starved aster +firing pin +water gum +Masonite +hairspring +seminarian +blue racer +forecastle +scrub pine +Atlantic spiny dogfish +kopje +orphrey +fan tracery +gee-gee +vixen +interstellar space +Harris Tweed +sawmill +lemon mint +bitewing +ringlet +Chinese mustard +paleontologist +American hazel +brigantine +clay-colored robin +zombie +nectarine +West Indian jasmine +pineapple weed +rusher +gynecologist +pole +thylacine +myrtle beech +golden cup +woodruff +T-bar lift +terebinth +service club +homegirl +Blue Mountain tea +figwort +New Hampshirite +Stayman +tonometer +white turnip +messuage +cruet-stand +colliery +connecting room +lesser twayblade +bland diet +crown prince +beggarwoman +restharrow +bower actinidia +firebug +hepatic tanager +telegraph +Spodoptera frugiperda +spackle +carpenter's square +pyx +supermom +thickhead +whorled milkweed +Arctic char +Chinese rhubarb +pince-nez +wolverine +tomato concentrate +cascarilla bark +red underwing +leather flower +Jerusalem thorn +bullpen +Salisbury steak +anode +coffeeberry +bottling plant +fritter batter +aerial torpedo +matrix +local oscillator +stalked puffball +bruin +three-cornered leek +wassail +stabling +damping off fungus +myriapod +osier +lesser kudu +cownose ray +chokecherry +wagon +obstetrician +Glengarry +even-pinnate leaf +wine sauce +osteocyte +baker's yeast +heir presumptive +blackjack +tympanist +golden fern +fipple +Japanese oak +bar mask +stamping machine +argus +knobcone pine +oil beetle +lanai +upper berth +condenser +proctologist +catechu +wild spurge +vestry +ground snake +proton accelerator +walker +scarlet bush +transom +lagging +bouillon +slender loris +black currant +developer +football hero +plum sauce +striped mullet +prince charming +fictional animal +prosimian +lug wrench +lemonwood +kirsch +spy satellite +black caraway +Thompson Seedless +bead tree +purple fringeless orchid +Virginia strawberry +chigetai +punkie +gall wasp +addressing machine +rock polypody +good-king-henry +spring cankerworm +wimple +noncandidate +saskatoon +hacienda +Darjeeling +snowberry +lounging pajama +ascospore +ski-plane +hedgehog cereus +Welsh onion +yautia +coaster brake +sickle cell +parrot's beak +fuller's teasel +painted greenling +scablands +stuffed cabbage +barrel organ +etcher +dwarf maple +camp +Australian blacksnake +currycomb +obtuse triangle +rose gum +psychrometer +abridger +torpedo +carpet loom +sodalist +slender rush +loligo +sclerometer +wimp +dotted gayfeather +green ash +pinstripe +moralist +medusa's head +garden centipede +heath aster +fool's parsley +olla podrida +Potawatomi +Edam +toothache tree +hulk +seabag +narthex +compartment +prairie star +lookdown +B-flat clarinet +event planner +clip lead +shirting +milk punch +supercharger +macadamia nut +giant coreopsis +computer store +martingale +keyboard buffer +summer flounder +squash ball +gas turbine +object ball +plier +black mulberry +reef squirrelfish +scampi +willow aster +bowler +striped marlin +smooth muscle cell +diplodocus +Liberty ship +sponge cloth +guitarfish +walking leaf +showroom +California bluebell +bolo +turnbuckle +boysenberry +hardware +Gael +imago +endorser +jujube +dust bag +rapporteur +field wormwood +low-water mark +naval missile +Pacific yew +reversible +crabapple jelly +poniard +barricade +spawner +simnel +seltzer +deckle edge +needle +timbale +satellite transmitter +organization man +job candidate +orderly +native cranberry +fir clubmoss +coaming +chartered accountant +electron accelerator +Sierra plum +American foxhound +long underwear +Penobscot +blueberry yogurt +biretta +cascara +Paranthropus +Dorian +nun's habit +lenten rose +Augustinian +designer +northern phalarope +mombin +hazel mouse +reeve +waffler +telegraphy +Verpa conica +ignition coil +Japanese oyster +S-shape +divining rod +ant thrush +throat protector +interlocutor +Desmodus rotundus +pere david's deer +attenuator +Cypriot +red sandalwood +pendulum watch +broadcloth +striped drum +sequence +safety arch +diapensia +hog +western spadefoot +chlorella +comb-footed spider +Chechen +darning needle +C-ration +hard beech +piano action +scaling ladder +Nepal trumpet flower +ravigote +screw wrench +ramekin +Lyonnaise sauce +dinner napkin +partial veil +masseuse +coatrack +mooring tower +blue-eyed African daisy +English horn +baton +rope tow +toll bridge +massage parlor +quark cheese +lounging jacket +tall goldenrod +flying jib +coordinate axis +barley-sugar +integrator +worm gear +captain +sweatshop +class +layer +chili powder +dripping pan +oatcake +newsroom +tadpole shrimp +rake +trade magazine +silks +ram's-head +senior +knower +masseur +yam +peg +wheel tree +hardbake +test room +long-spurred violet +creeping spike rush +shrapnel +coffee senna +matchbox +creeping soft grass +welder's mask +pickaback plant +urial +hooded pitcher plant +incense cedar +Ohio buckeye +ant cow +skeleton fork fern +Indiaman +swamp ash +testatrix +marang +spherocyte +Winesap +Indian mallow +teju +Yersinia pestis +dye-works +sauerbraten +coral bean tree +safe house +postulator +eyas +lotus +wood vise +lady-of-the-night +East German +cymling +rock candy +western omelet +anoa +rainbow seaperch +crossover voter +Finn +tree shrew +hog plum +Federal +shagbark +clockwork +Alexandrian laurel +metal wood +brill +military chaplain +trend-setter +call-back +Indian rat snake +spurred gentian +Japanese maple +forest goat +bee moth +viola da braccio +duckboard +armyworm +hangnail +counterbore +cream-of-tartar tree +Mullah +bonbon +water hazard +temple orange +corporatist +rough bindweed +Turkish bath +mistletoe fig +beach sand verbena +caddisworm +English plantain +brown Betty +power pack +lion's-ear +Francis turbine +stayer +dichondra +marsh St-John's wort +squab +energizer +common horehound +mantispid +pullback +handwheel +spark arrester +yakuza +Virginian witch hazel +grunter +waterworks +bondwoman +chain printer +stockjobber +coconut milk +yardgrass +blue chip +bridle path +riser +pleurothallis +saltwort +salal +broadside +blackboard eraser +bastard +Para rubber tree +red bat +digital-analog converter +calabash +cashier +cow shark +horned pout +microphage +monologist +woolly monkey +Illinoisan +marsh horsetail +distaff +siris +eparch +gooseneck loosestrife +sounding rocket +multiprocessor +saiga +xerographic printer +madrona +right triangle +sweet gale +red maids +wolfsbane +pork-and-veal goulash +French sorrel +mutterer +Venetian sumac +drumlin +white crappie +squire +large-flowered calamint +northern cricket frog +mushroom sauce +supertanker +morello +auxiliary boiler +Virginia thimbleweed +cottage tent +bubble shell +big shellbark +wormwood sage +cider gum +coast lily +American feverfew +Peruvian balsam +purple silkweed +tobacco moth +desk dictionary +rock elm +eastern indigo snake +Japanese privet +lamb +levee +L-plate +soapfish +painted tongue +scuttle +markhor +Marburg virus +mackinaw +major +crypt +ball and chain +domestic silkworm moth +bottom feeder +mistress +death house +freight elevator +bellyband +Pulex irritans +Bacillus anthracis +fire control radar +hysterosalpingogram +turbogenerator +decompound leaf +vambrace +scentless camomile +Medinilla magnifica +prima ballerina +Northern Spy +quartz lamp +grains of paradise +justiciar +felt fern +seismograph +Madagascar jasmine +imaret +white perch +Alpine mouse-ear +tea bread +yellow bass +poseuse +espionage agent +punching bag +eurypterid +orange sneezeweed +banded stilt +armhole +postern +mother +kapuka +catechumen +Soubise +Sauvignon blanc +gunnery sergeant +self-starter +ceratozamia +Atlantic cod +Reoviridae +blood cup +horseshoe bat +oriental plane +voussoir +fetterbush +samara +truncated pyramid +lingcod +athenaeum +shyster +Carolina hemlock +submarine torpedo +floating fern +yataghan +sun tea +viola d'amore +conenose +ventilation shaft +walk-up apartment +saury +wild wheat +porcupine ball +tahini +kris +grass fern +drip pan +black bryony +Scotch broth +tapioca pudding +southwestern toad +Hare Krishna +guimpe +wild madder +megalocyte +teaching fellow +shrubby penstemon +lesser wintergreen +privet hedge +Fahrenheit thermometer +stern chaser +prickly ash +pump room +ricer +chicken mousse +wing commander +sun gear +bolus +alpine milk vetch +opera cloak +twinjet +Goldie's fern +abnegator +alphabet soup +node +grape jelly +early coral root +Tarzan +quarterstaff +greeter +Eurasian woodcock +primary coil +quirt +tinkerer +bolt +creme de fraise +voltage regulator +news photography +Jat +bristly locust +Gouda +dickey +lobster butter +dwarf flowering almond +fagot stitch +Reform Jew +ostrich fern +bathyscaphe +purple mullein +alpaca +civic leader +jellaba +Arizona ash +wasabi +Irishwoman +choke +stockinet +religionist +sewage disposal plant +bittersweet +Hyphantria cunea +pheasant under glass +screen actor +chapterhouse +quoit +horseshoe bat +rapper +cupule +planetary gear +cascade penstemon +redoubt +salt +areaway +megalomaniac +bush willow +amethystine python +plains spadefoot +colour supplement +kick pleat +bell apple +narwhal +slippery elm +stenograph +baa-lamb +quadrant +balker +jobcentre +spit curl +bastard indigo +malacca +serow +adobe lily +yacca +palestra +penalty box +scrub beefwood +reenactor +screening +white bryony +alderleaf Juneberry +harpoon +alpine clubmoss +neurosurgeon +surrey +sweet calabash +Scotch laburnum +coquille +French honeysuckle +extrados +pipe cleaner +southwestern white pine +Virginian stock +scaly lentinus +aileron +carob bar +swordfish +Alpine woodsia +negus +wireworm +sweep +goldfields +drop arch +European bream +roly-poly +pin +bastard wing +fustian +wild buckwheat +lake whitefish +overcoat +water filter +Bermuda chub +New Zealand spinach +high-hat cymbal +European larch +radiologic technologist +fine-tooth comb +brunch coat +splice +electronic converter +overmantel +extern +taper +cluster bomb +teletypewriter +pinwheel +trailing arbutus +quipu +creeping zinnia +orange milkwort +tabard +Australopithecus africanus +melancholy thistle +insole +courser +darkroom +surface-to-air missile system +bark-louse +Confederate +neritina +clip-on +spouter +trench knife +outside caliper +dhak +Limburger +chuck wagon +buttercup squash +shirtdress +pouter pigeon +dirty old man +zodiac +fennel flower +mother figure +appointment +Manichaean +lignum +bouffant +rum sling +Ravenna grass +hibachi +gin rickey +American harvest mouse +cocozelle +western wheatgrass +black crappie +rhombus +Missouri goldenrod +barndoor +wild mango +pneumococcus +Boston lettuce +ratline +desert holly +cobweb +fluoroscope +ethnologist +tor +bullshot +stockade +greave +rock sea bass +slip-joint pliers +taxi dancer +schizophrenic +zill +creme de menthe +orange-blossom orchid +divot +supplejack +busybody +casemaking clothes moth +ramrod +gearbox +birdcall +Wiffle +thwart +beauty consultant +chicken paprika +trawl +skep +spirometer +hopper +kvass +doggie bag +bath chair +showy daisy +wild tamarind +Tarsius syrichta +glyptics +Algerian +cargo area +bunk +Velveeta +iconoclast +clinch +New Caledonian yew +false mallow +Japanese tree lilac +convex polyhedron +water boatman +cruise missile +finisher +colonoscope +cumin +wickiup +saccharin +whipcord +trailer camp +eryngo +cuckold +yam bean +fighting chair +forewoman +galingale +citron +positivist +four-lined plant bug +suet pudding +field pea +Circaea lutetiana +deer grass +trap-door spider +common corn salad +mirror carp +sounder +second-in-command +seaside alder +burgoo +ming tree +curry sauce +courbaril +green alder +figure loom +fauld +halfbeak +squelch circuit +cladode +winter cress +tongue and groove joint +dwarf dandelion +joss house +western buttercup +welted thistle +potato tree +anglewing +cookfire +marzipan +hood latch +seed shrimp +common moonseed +toasting fork +bevel +three-quarter binding +midwife toad +stage director +Pentecostal +technical sergeant +golden-beard penstemon +drunk +silky oak +corn gluten feed +T-square +stoker +selling agent +cruse +server +rope-a-dope +bicorn +matzo meal +wide wale +roadblock +false foxglove +tuck box +bandsman +smoke bush +machinist's vise +Highlander +scholiast +self-starter +Swedish rye bread +spark transmitter +maverick +maquiladora +cabinetmaker +compress +rainbow shower +huntsman's horn +mackinaw +copper rockfish +lappet +nitrate bacterium +telephone plug +soutache +Dacron +toboggan +sissoo +yogi +laurel-tree +vice chancellor +Christ's-thorn +cartridge fuse +serial port +quassia +tarweed +pecopteris +beggarweed +anchovy pear +bookbindery +woodland oxeye +toad rush +sandalwood tree +marsh andromeda +Tyrian purple +boothose +tragedienne +fragrant cliff fern +festoon +bondwoman +melancholic +butternut squash +exhaust valve +semi-skimmed milk +glowworm +Virginia oyster +Identikit +ayah +gallows tree +Carioca +monoplane +jewels-of-opar +scallop +moth miller +marsh cress +lobed spleenwort +ricotta +emitter +arame +tub gurnard +army attache +maniac +organizer +pheasant's-eye +Melba toast +homeboy +Bavarian cream +Maximilian's sunflower +backstop +Tremella foliacea +yellow avens +spreading fleabane +plumb level +false rue anemone +zabaglione +climbing maidenhair +doeskin +walking shoe +lancewood +material +jacksnipe +South American poison toad +agonist +hinny +paper mill +psychophysicist +valley girl +toast mistress +jorum +tiler +chicken Tetrazzini +trivet +grasshopper +three-mile limit +kink +kiang +pole horse +jig +Cornish heath +hedge thorn +false alumroot +Popper +remount +photojournalist +sideroblast +stonecress +Agave tequilana +Japanese lilac +hawse +maenad +air bag +leaf spring +dwarf willow +soda cracker +contralto +moleskin +pilaster +Audubon's caracara +pia +American organ +bleu cheese dressing +betel palm +PC board +almond willow +socializer +tone arm +stammerer +free-liver +scaler +Gentianopsis crinita +leak +black haw +hound's-tongue +grass pea +Stassano furnace +coralbells +ministrant +perihelion +Luxemburger +powder-post termite +arboreal salamander +cushion flower +foramen magnum +pyrethrum +poacher +woolly mammoth +horned chameleon +tearaway +father-figure +tufted gentian +salmi +finger millet +physa +registrar +polyoma +bamboo shoot +matchlock +seine +congress boot +bulgur pilaf +monosodium glutamate +Kentucky wonder +mycologist +kedgeree +ragweed pollen +boarfish +yellow pimpernel +tan +northern Jacob's ladder +macrobiotic diet +migrant shrike +big-cone spruce +colonialist +white dogtooth violet +bath asparagus +webbing clothes moth +ladies' room +experimenter +prairie bird's-foot trefoil +bootleg +cognitive neuroscientist +fire chief +flagfish +dendrite +stinking goosefoot +fore edge +hogfish +Spanish cedar +hotel-casino +Tory +life-support system +pea flour +cash bar +Chenin blanc +white-footed mouse +Canada garlic +salt-rising bread +roomette +mastodon +bell founder +long iron +bi-fold door +fig-bird +European water shrew +dyer's weed +frog orchid +allosaur +Florida yew +wild potato vine +crape fern +flat-topped white aster +klebsiella +oil heater +waxmallow +enjoyer +mesocarp +semidesert +senior vice president +coccidium +burrawong +syllabub +jump suit +harrier +leaf roller +cherrystone +cinchona tree +touring car +eulogist +air force officer +red goosefoot +cat thyme +smoothbore +slugger +cardiac monitor +cobber +blister rust +musicologist +rolled biscuit +Braun's holly fern +hog plum +nonpasserine bird +pascal celery +damson +Jonathan +Sheraton +cohune palm +egg white +baton +sixth-former +Siberian pea tree +choanocyte +wineskin +auditor +detention home +Leichtlin's camas +Chartreuse +clusia +club car +wattle and daub +security blanket +common American shad +assistant professor +marsh pea +camomile tea +gopher hole +gravure +Freudian +spirillum +maharani +equilateral +crow garlic +mammee apple +felwort +hardtop +dillenia +curlycup gumweed +pilot engine +calcimine +wooly lip fern +bitter dock +wineberry +jumper +monolingual +spinning frame +old-timer +native cat +diving petrel +sodium-vapor lamp +marchand de vin +sexton +matelote +interior designer +windfall +mole salamander +minder +bodkin +neutron bomb +Caloscypha fulgens +slinger ring +mezzo-soprano +aura +Southern Baptist +viscacha +midfield +tie +prosthetist +round-headed leek +yellow mariposa tulip +canary grass +staddle +Tokay +Muenster +brazil nut +California black walnut +applesauce +penologist +virgin's bower +tenon +steward +Jerusalem oak +red-bellied snake +bindery +scow +fluid flywheel +bullhead +satinleaf +clove +double glazing +matron +wild parsnip +winged elm +shoot-'em-up +musk deer +white rust +lock +Cornishman +Vidalia onion +corn spurry +freeloader +justice of the peace +inlay +myxobacteria +tiglon +tangram +German ivy +scented fern +woolly daisy +caretaker +gastroscope +scuppernong +spotted sunfish +guilloche +codling +wormcast +Eskimo curlew +tayra +European fly honeysuckle +septuagenarian +third gear +coatee +red alder +water ice +cubitiere +frame buffer +gamboge tree +pernyi moth +chicken Marengo +Galliano +Lincoln +true sago palm +hunter's sauce +carpet beater +alpine goldenrod +arch support +vehicle-borne transmission +jilt +paternoster +redcap +Siberian larch +hoary plantain +swan's down +chicane +reverse +divan +kneeler +alexic +mock turtle soup +daffodil garlic +mission bells +squilla +ursinia +winter's bark +trifoliate orange +discina +frijole +Swiss steak +maildrop +knotgrass +dog fennel +drum sander +heroin addict +costume +camber arch +shining willow +lutefisk +red porgy +microfossil +good old boy +angle bracket +pitcher sage +bordelaise +heat exchanger +carrion +bush jacket +fanjet +coach +blackface +sicklepod +Manhattan clam chowder +daisywheel printer +olive +Sphacelotheca +Spanish needles +brown root rot fungus +boudoir +encyclopedist +V-8 juice +red haw +brass buttons +gym suit +skywalk +water wagon +gas-turbine ship +stoup +lisle +sailor suit +box beam +balm of gilead +housemaster +hayrack +neutralist +water elm +brook thistle +doyenne +nark +alpha-tocopheral +WASP +hydrilla +water-shield +footlocker +variola major +pargeting +ion engine +yellow globe lily +Malecite +bloodleaf +yellow sand verbena +whorled loosestrife +packinghouse +Carolina parakeet +Virginia waterleaf +armband +red rockfish +factory ship +moon trefoil +jump seat +water gillyflower +yerba mansa +chamfer bit +compass saw +hopsacking +Indian rhododendron +sickbed +treacle +honey eater +mailsorter +seabeach sandwort +sob sister +primrose jasmine +prince consort +elocutionist +wishing cap +runner +trestle +sugar water +half-and-half dressing +fringed poppy mallow +portiere +bung +swan orchid +weather satellite +beef broth +marblewood +sapper +agitator +wren-tit +grade +allspice tree +spacewalker +American hornbeam +sieva bean +dill seed +potoroo +love-in-winter +alembic +Cheshire cheese +small white aster +Oregonian +flipper +twill +differential gear +Prince Albert +licorice +foster-father +Melkite +portraitist +Yosemite toad +Cox's Orange Pippin +slender wheatgrass +knob +silique +Rocky Mountain bee plant +stirrup pump +chicken hawk +sweetbrier +Sierra lodgepole pine +poulette +biohazard suit +striated muscle cell +Geiger counter +World Wide Web +turmeric +prairie wake-robin +latchet +pushball +grill +shooting lodge +floating-moss +refried beans +boojum tree +red poll +toothbrush tree +rabbiteye blueberry +red haw +sweet vetch +delta +upland cotton +ballet mistress +padrone +complementary color +great Solomon's-seal +bud brush +brandy sling +spinster +Andorran +Mojave aster +mackinaw +golden calla +bottom rot fungus +segmental arch +periwinkle +hellion +topknot +copper +Mexican hyssop +weeping love grass +point woman +pathogen +fall cankerworm +common shiner +silverspot +corer +atomic pile +crystal detector +yellow spot fungus +truncated cone +saprobe +variegated horsetail +Cro-magnon +cercaria +aglet +pollster +oyster bed +pancake turner +egg cream +sporozoite +quirk molding +mutisia +sound bow +physic nut +sugar-bush +cow +magnetron +jungle hen +brassie +rock bit +taco sauce +seeded raisin +desert selaginella +folding door +vinegarroon +Pinot blanc +rye +ellipsoid +betel nut +tree of knowledge +ambrosia +long tom +breechloader +bicolor lespediza +cosmetician +monoblast +American oil palm +prancer +farina +caiman lizard +hardball +bullock's heart +cotton rat +whiting +weather ship +sharecropper +creamcups +gas bracket +divinity +ornithologist +yellow twining snapdragon +showy goldenrod +end man +heptagon +sand dropseed +round file +guama +blue elder +sand spurry +raccoon dog +zigzag goldenrod +fast reactor +arctic willow +cyclopean masonry +punter +sgraffito +slattern +storage ring +clipper +pulasan +short-tailed shrew +scammony +daybook +umbrella tree +coloring +element of a cone +gesneriad +cane +burgoo +western coral snake +friendship plant +Leydig cell +scrutineer +hairy golden aster +inclined fault +water milfoil +bryozoan +nardoo +native pomegranate +curly grass +Florence fennel +resurrection plant +ice water +crown +ploughman's lunch +clustered lady's slipper +kitchenette +sand sedge +pouched mouse +roadbed +parsley haw +predecessor +super heavyweight +seedless raisin +mailbag +sparling +codling moth +squama +Bercy +thermoelectric thermometer +Jaculus jaculus +saltpan +firmer chisel +round whitefish +ramrod +criollo +pinch bar +slash pocket +thigh pad +velvet plant +intergalactic space +brazilian ironwood +whaleboat +sirrah +hanging fly +aspirator +Dominican +dribbler +yellow-eyed grass +Cornish +geophysicist +tarmacadam +marchioness +rattlesnake orchid +Alaska Native +ilama +myrrh tree +zucchini +licorice root +nosebag +lounger +troposphere +virginal +spaghetti Western +Virgin Mary +waterwheel plant +dry nurse +enate +carpet shark +rijsttaffel +stuffing nut +caraway seed bread +Leotia lubrica +kaffiyeh +Boston baked beans +halophyte +backscratcher +instillator +trefoil arch +pip +digitizer +dosemeter +Carolinian +French sorrel +boards +historian +rangpur +clansman +goral +leatherjacket +coiner +fleece +white globe lily +storm cellar +roundhouse +mediatrix +butterfly flower +swamp gum +prairie vole +rhizomatous begonia +common tobacco +Marco Polo sheep +subarachnoid space +broomweed +safety net +silky wisteria +swagger stick +spectacled caiman +derris root +soap pad +chop-suey greens +summer hyacinth +palo santo +carbohydrate loading +chinch bug +roadman +sheep plant +messiah +desk officer +banquette +drugget +trumpet arch +great duckweed +purdah +heartbreaker +hasty pudding +alligator weed +dragee +yellow bristlegrass +Jacob's ladder +campstool +coffee fern +sweet fern +little chief hare +cat-o'-nine-tails +rep +American red elder +divorcee +black salsify +cambric +sennit +Canada ginger +wonderer +Formica +cream-colored courser +zooid +European beggar-ticks +sorrel tree +piddock +blolly +red-flowered silky oak +bay +Hooker's onion +dark horse +cone clutch +Roman hyacinth +paintbox +mestiza +green alder +bill +panicled aster +mammogram +snuffbox fern +Rediffusion +swamp fly honeysuckle +stoup +psychiatrist +nodding groundsel +student union +cold duck +bee beetle +playbox +Psychopsis krameriana +nosh-up +earthnut +narthex +single-rotor helicopter +revetment +sweetleaf +seasoned salt +piculet +speckled alder +mackerel scad +common yellowwood +devisee +static tube +Spanish heath +umbrella plant +fucoid +Chilean +coral-root bittercress +fanatic +cachou +agony aunt +bird's-foot fern +washwoman +torchbearer +placoderm +frosted bat +spicemill +Cape lobster +hard-shell crab +colonizer +camphor daisy +friar's-cowl +false tamarisk +toggle joint +tinsmith +theorist +hydrologist +loganberry +universal donor +northern whiting +tent-caterpillar moth +russet +kangaroo mouse +African scented mahogany +bastinado +breast implant +betel +grade separation +vox humana +stodge +Maryland chicken +Anguillan +oil pump +governor's plum +narcissist +deadwood +private citizen +winker +ropewalker +gidgee +Lothario +ski resort +major-domo +von Neumann machine +belaying pin +water parsnip +Fissipedia +luggage carrier +spring water +oyster stew +kohl +celesta +date-nut bread +punchboard +sunniness +hospital train +man +rack and pinion +mixer +pousse-cafe +narrow goldenrod +Maxim gun +stiff +recruiting-sergeant +watch glass +white hellebore +tung tree +prairie white-fringed orchid +beef Stroganoff +scoffer +grassy death camas +Shawnee cake +tapioca +Short's aster +banker +laparoscope +honeyflower +Caterpillar +electric clock +baling wire +huntress +Surinam toad +art school +incurable +Canton crepe +apple juice +hipline +bronchoscope +marshmallow fluff +Texan +wild fig +sawed-off shotgun +forestay +red kauri +fish slice +Egyptian grass +English walnut +brown sauce +ogee arch +nectary +chambray +leather flower +phloem +Persian violet +bomb calorimeter +western narrow-mouthed toad +soup du jour +sickle alfalfa +caracolito +periscope +coralberry +sword bean +sigmoidoscope +water locust +hygrodeik +sycamore +sheikdom +ballistocardiograph +clove +akee +fucoid +jacquard +cat's-ear +puritan +slender wild oat +smooth softshell +purchasing agent +landing craft +chartist +lace bug +sharksucker +Virginia chain fern +horseradish +namer +ripcord +personage +aspirin powder +puku +Wankel engine +nightcap +velvet bent +roridula +cytogeneticist +olm +almond extract +common heath +fringe-toed lizard +Kentucky yellowwood +lithosphere +cramp +bulgur +scurvy grass +officer's mess +frigate +electroscope +giant chinkapin +opah +rutabaga +wood hoopoe +Farley maidenhair +shingle tree +argentine +router +palm nut +quillwort +hiba arborvitae +runcible spoon +hireling +sickbay +alpine totara +white lupine +Cotoneaster horizontalis +desert plume +staghound +Sea Scout +opalescence +enophile +Jersey elm +coal house +Helvella acetabulum +selenium cell +white camas +creole-fish +auger +fragrant agrimony +research center +achromia +shank +cottonseed +mod con +extension +sugar beet +winter flounder +silky dogwood +strop +tokamak +rabbit ears +baby farmer +fireman's ax +serration +taproot +socket wrench +action officer +Chilean jasmine +Greek fire +stem-winder +body louse +lumpsucker +stink bomb +American lady crab +dicer +lie detector +maneuverer +black-headed snake +tiger moth +shooting stick +spermatid +babushka +deaconess +home +prior +chanfron +chickasaw plum +big-eared bat +rusty woodsia +tertigravida +miniver +combretum +habit +bluehead +angled loofah +gipsywort +fire-on-the-mountain +purple milk vetch +alpine gold +merozoite +loddon pondweed +Uniat +provost marshal +Gyromitra fastigiata +Coigue +proconsul +oarfish +San Jose scale +filature +chimney plant +spiny softshell +bluecoat +live axle +river limpet +clever Dick +pink bollworm +Japanese plum +roarer +caricature plant +wardroom +Texas chachalaca +Bahia grass +Moreton Bay tulipwood +accessory fruit +pearl barley +ashcake +bunt +Polynesian tattler +pine fern +laughing owl +potato fern +speaking trumpet +adjoining room +bearing rein +banana quit +redbrick university +Scleroderma bovista +magdalen +pressurized water reactor +advisee +NIMBY +poorwill +almond moth +comedian +star tulip +cracked wheat +water pump +guest of honor +yellow-breasted bunting +hire +pedate leaf +augur +purple locoweed +Socinian +upland white aster +guesthouse +double reed +detention basin +rollmops +hitch +bodega +mayeng +sparkplug wrench +attack dog +peach melba +heliozoan +tower mustard +blue mold fungus +lamplighter +banded sand snake +smooth crabgrass +elsholtzia +bodkin +Aegean island +bag lady +alewife +arcella +electrical contact +common ax +animist +concave polyhedron +coalface +climbing perch +yellowtail +hobble skirt +marquee +Russian dandelion +snow mushroom +polo ball +NADA daiquiri +cormous plant +chaparral mallow +inside caliper +milking stool +fallout shelter +sea gooseberry +Danish blue +grissino +chimney breast +mosquito fern +soundbox +spring chicken +epauliere +cape forget-me-not +japan +saddle oyster +white fritillary +push-button radio +bladder senna +bladder stone +macedoine +moire +Shawnee +starnose mole +douroucouli +horseradish sauce +electron gun +cotter +console +park commissioner +free press +lump sugar +western poison oak +apple maggot +keurboom +lisper +griffon +burin +horseshoe whipsnake +Jacobean lily +spinner +cochineal insect +emesis basin +sowbane +humanitarian +uakari +three-dimensional radar +wild hollyhock +heartseed +swinger +two-by-four +mop handle +common amsinckia +traitress +rush aster +fibrous-rooted begonia +violet-flowered petunia +milliammeter +alidade +azure aster +celery seed +snorer +scarlet plume +obtuse leaf +heathen +rose chestnut +headrace +dwarf buckeye +Pacific tripletail +wiggler +bounty hunter +Lowlander +slate pencil +typist +syconium +vaquita +skybox +business lunch +gusher +curacao +palometa +Diapsida +light diet +sourdine +thorny amaranth +potato fern +cartridge extractor +peshmerga +chaffweed +tahoka daisy +hematologist +massage parlor +diverging lens +breadroot +papyrus +amarelle +cover plate +hubbard squash +cryptomonad +whitetail prairie dog +rabbit burrow +orthochromatic film +goncalo alves +Chile bonito +tent-caterpillar moth +Manila grass +buck sergeant +mustard seed +crested wheatgrass +wise guy +asarabacca +field pea +bite plate +barbasco +heart-lung machine +mouse-eared bat +piping guan +gun pendulum +climbing onion +fungus gnat +Livonian +one-hitter +Chilean firebush +Sonoran whipsnake +round scad +myelogram +Rhodes grass +vomitory +roble beech +South-African yellowwood +molasses +Velcro +common calamint +radiation pyrometer +sketcher +chaparral pea +coffee stall +Australian nettle +bilimbi +Khedive +visionary +field spaniel +devilwood +collimator +Siberian spruce +sling +limestone salamander +ribbon worm +hazel +petter +coolant system +artillery plant +bailiff +chameleon tree frog +microsporophyll +maiden blue-eyed Mary +Drosophyllum lusitanicum +cocozelle +king post +nailer +knobkerrie +tovarich +Intelnet +worm lizard +drop forge +wool grass +brown bullhead +anthropoid +vitamin A2 +creche +hickory nut +whiffletree +deipnosophist +Muskhogean +masochist +hypsometer +gliricidia +complexifier +wild licorice +reconnaissance vehicle +fives +beefsteak plant +eastern dasyure +bookworm +crested coral root +wire recorder +cinnamon vine +bubble +Newfoundland dwarf birch +spruce bark beetle +teetotaler +fad diet +ascus +spicebush +African coral snake +soft-shell crab +Postum +packhorse +sand cherry +cricket-bat willow +middlebrow +Hungarian sauce +buffalo clover +jimsonweed +latanier +stablemate +jumper +zoospore +smooth woodsia +flowering ash +unilateralist +lomatia +flapper +wild cotton +Siberian wall flower +probe +bankrupt +blockade +lemon geranium +fig leaf +basic point defense missile system +clack valve +buttinsky +ingenue +mountain everlasting +zebra-tailed lizard +shaving-brush tree +evergreen huckleberry +core drill +lugworm +Cashmere goat +doorjamb +minelayer +student center +horsehair +European dewberry +white broom +arenavirus +eastern poison oak +rye ergot +Tupi +tensiometer +fleawort +coquille +icing sugar +junior lightweight +Doppler radar +mahuang +candlepin +chambermaid +evergreen blueberry +Eton jacket +parvis +solleret +molded salad +malvasia +birth-control campaigner +nonagon +backswimmer +ogee +bowstring +salt marsh mallow +trapezohedron +hoary willow +speech therapist +Zinjanthropus +core +red-backed mouse +eptatretus +mossy saxifrage +Aristotelian +Thessalonian +searing iron +bifocals +falangist +field pea +packsaddle +lay reader +hoecake +cuboid +white maire +iceman +lobscouse +neckcloth +color-blind person +Chinese holly +assemblyman +white-lipped peccary +kava +plastron +crab louse +hook wrench +trailing four o'clock +junior +skilly +internet +tonguefish +footman +sub-assembly +evangelist +track +bench lathe +desk clerk +scalded milk +chamois cloth +American marten +chachka +nondescript +pellitory-of-the-wall +swamp candles +procurator +cuddy +farkleberry +mountain male fern +trawl +dual scan display +fish meal +prospector +convener +guano bat +ant shrike +picture rail +sand rat +gynophore +quilting +sleeper +summer savory +Cotoneaster dammeri +smooth sumac +slumgullion +suite +catalufa +spherule +lean-to tent +gryphon +gas shell +short iron +sweet sultan +dewberry +Victoria plum +American water shrew +X-ray tube +macebearer +green arrow arum +abbe +poke milkweed +atheist +Fosbury flop +Ord kangaroo rat +moldboard +wheat germ +explosive trace detection +whippoorwill +examiner +tallyman +Crookes tube +wild peach +fringed grass of Parnassus +Crookes radiometer +Atlantic croaker +lobster stew +spring cress +maggot +pacer +hydra +Zionist +pepper tree +diamante +baize +Rhodesian man +county agent +respecter +Anglican +antimacassar +materialist +Swan River everlasting +cloud grass +toll line +C battery +chinese mustard +grass poly +warming pan +seasonal worker +common sickle pine +bathysphere +elegant Habenaria +card table +Chilean cedar +brocket +collimator +malted milk +avadavat +fire marshall +coloratura +yellow spiny daisy +fingerstall +narrow-leaf penstemon +indigo broom +pillwort +bearberry willow +Etonian +certified milk +climbing bird's nest fern +field coil +wrist pad +parr +kaoliang +engelmannia +stocker +satrap +Nantua +spearfish +caper tree +gold-tail moth +mountain chinchilla +sea milkwort +westerner +army cutworm +leaf-nosed snake +neurobiologist +xeranthemum +Eastern silvery aster +ecclesiastical attire +caper +Ukranian +bight +button fern +peach pit +oligodendrocyte +maar +digitigrade mammal +streptobacillus +sensitometer +preemptor +oat +bell foundry +crown lens +rock purslane +Junior +Brazilian guava +kicksorter +Ohio goldenrod +red mulberry +King's Counsel +mountain four o'clock +fairy shrimp +fell +oca +sycophant +chantry +dermatoglyphic +bomblet +keyhole saw +hangman's rope +little barley +lion-jaw forceps +giant scrambling fern +popper +dulcimer +Espagnole +tardigrade +smooth-haired fox terrier +bullbrier +rewa-rewa +Japanese poinsettia +trunk line +cannery +helminth +American spikenard +prince's-feather +arthroscope +ginger +aphakic +pilot bit +angle of refraction +low-sodium diet +wall creeper +growler +praetorium +Hall of Fame +soupfin shark +Molotov cocktail +kaffir boom +stitcher +sawwort +flagellant +Atlantic herring +Reticulitermes lucifugus +voltaic pile +snowy orchid +southern flounder +skysail +osage orange +white mullein +lined snake +tolu tree +poliovirus +foreman +burette +jackass bat +invigilator +electromyograph +acarus +presence chamber +columbian mammoth +hyacinth bean +pilot +meadow jumping mouse +Maria +outskirts +aftershaft +Queensland nut +schlockmeister +plainsman +afropavo +scarlet musk flower +five spice powder +gunboat +multiplex +Dutch uncle +louvered window +chimney corner +cuscus +psalmist +Vichy water +signer +amphiuma +harmonizer +authorizer +naiad +control rod +stentor +mountain bladder fern +gig +read-only memory chip +assenter +vixen +hermitage +corn dab +locksmith +cockspur thorn +variable-pitch propeller +western red-backed salamander +dolman sleeve +cultist +sweet buckeye +pine vole +Peking man +mountain swamp gum +nimblewill +bethel +aye-aye +lancelet +teff +Alpine celery pine +endive +nipa palm +center of curvature +seeder +Sabahan +sea scallop +social secretary +gorgonzola +western chokecherry +misanthrope +rabbitweed +beggarman +button fern +white mallee +doodia +mastiff bat +roper +prima donna +blanc +holding pen +fingerling +skyhook +flophouse +steam chest +crystallized ginger +acrocarp +horse pistol +true mahogany +costmary +ballistic galvanometer +jaunting car +bartonia +rep +mandibular notch +bubble and squeak +umpire +fringed loosestrife +bear oak +ski jump +staggerbush +plumcot +thermal reactor +field brome +bodkin +jackknife-fish +malope +writing arm +gold fern +Stayman Winesap +merlon +eclectic +fluxmeter +emeritus +imam +drum +pop tent +capital ship +subalpine larch +flail +Lorenzo dressing +tomboy +eastern woodrat +warrantee +Pacific spiny dogfish +sheepshead porgy +farthingale +Cryptoprocta +power loom +communicant +howdah +ectomorph +false foxglove +basset horn +odd-pinnate leaf +Wisconsin weeping willow +Queensland bottletree +dampener +corbel arch +silent butler +Circe +town clerk +Japanese chestnut +bloodwood tree +switcher +cup hook +spreader +rice rat +straightedge +traverser +fluid drive +Spanish paprika +sour milk +poison camas +bean dip +card table +vinegar fly +vizier +electric-discharge lamp +purple rock brake +dynamo +Japanese snowbell +Grindelia robusta +neuroglia +safflower seed +coronet +frown line +Renaissance man +Steller's sea cow +book scorpion +isosceles triangle +arthritic +spherical triangle +kangaroo mouse +garden orache +stemless hymenoxys +titi +out-basket +gent +columnea +mint sauce +mouthbreeder +Liebig condenser +cheerer +assegai +stickler +Merostomata +dimmer +grey poplar +common heath +scorzonera +glory hole +Blackfoot +oil slick +musketeer +apple geranium +daisyleaf grape fern +gas furnace +bijugate leaf +Arabist +star-thistle +hand throttle +huckleberry oak +lift pump +maulstick +Rome Beauty +Newburg sauce +pit +volunteer +Baldwin +ark +Asian horseshoe crab +black calla +marlinespike +Gentianopsid procera +guinea gold vine +tucker-bag +desk sergeant +piezometer +migrator +keelson +executrix +sackcloth +onion smut +buckboard +substitute +pudge +mess +cinchona +intervenor +gravimeter +pederast +censor +gastroenterologist +cutlassfish +launch +demerara +Diegueno +bog bilberry +aglet +soda fountain +crank call +harpoon gun +ribbon fern +Gurkha +output device +epilating wax +greasewood +water horehound +return key +fairy swallow +spatulate leaf +culverin +leptocephalus +kleptomaniac +barley water +bleeding tooth +Cheyenne +maleberry +limber +tapenade +whorled aster +toe +revenant +lap joint +vein +truant +florest's cineraria +morning dress +trichodesmium +nightshirt +element of a cylinder +shopaholic +section hand +electrodynamometer +Guadalupe cypress +rosebud +racist +avaram +keeled garlic +Alaska rein orchid +orange toast +cunner +dipstick +Neolentinus ponderosus +bulbil +charlotte +pull-through +header +Manduca quinquemaculata +persona grata +elegist +cafe royale +scup +semanticist +wood sage +field magnet +tundra +bay myrtle +alluvial flat +arrowleaf groundsel +celtuce +baryon +must +entrant +othonna +pied-a-terre +liza +sticky aster +grasshopper mouse +prison guard +tire iron +bomb rack +Spanish American +sheltered workshop +turfing daisy +backbone +tangle orchid +creeping willow +dumb bomb +horse cassia +barosaur +Yavapai +shrimp Newburg +peanut worm +dwarf chinkapin oak +corchorus +brick cheese +by-catch +stover +Urnula craterium +clasp +Kekchi +alpine coltsfoot +soybean future +altar wine +ripping chisel +encephalogram +mountain spleenwort +transferee +remoulade sauce +American rock brake +stenographer +read/write head +loblolly +ground +powdered mustard +brake band +sea dahlia +freak +proconsul +Coffey still +Sivapithecus +pellitory +palm cat +skew arch +American angelica tree +vigilante +candelilla +andryala +amarelle +swiftlet +petcock +associate professor +sclerite +open circuit +Virginia crownbeard +Last Supper +button tree +scyphozoan +margate +mercury cell +horsewhip +water scorpion +companionway +drop cloth +Amhara +miraculous food +pro-lifer +embryologist +Creole +bombazine +Indian blackwood +cubeb +trace detector +gros point +main-topsail +meringue kiss +spree killer +capstone +specimen bottle +woolly apple aphid +silverweed +American barberry +gallfly +European bog asphodel +northern flying squirrel +alliterator +Old Catholic +heliograph +Pteris cretica +tippler +pump well +allspice +balancer +scarlet bugler +lantern fly +white prairie aster +krummhorn +robin's plantain +Pacific sardine +patty-pan +decaffeinated coffee +western saxifrage +warrantee +colorimeter +ball bearing +makomako +foot +troika +apricot sauce +data multiplexer +rose-root +sound film +Northern dewberry +water hickory +swing door +spastic +Oligoporus leucospongia +botulinus +tamale pie +Sagittarius +muff +spicebush +petiolule +pump action +Parry's pinyon +split-pea +rudder blade +princess royal +wormseed mustard +honey guide +pip-squeak +fin keel +foretop +cyrilla +Navaho +melanocyte +deist +silver tree +citrus whitefly +Morrow's honeysuckle +green peach aphid +longanberry +call-board +wild yam +novelist +toothed spurge +alienee +pond apple +allspice +Carolina lupine +Jack of all trades +white false indigo +boiled dinner +princewood +sailor's-choice +false bracken +microbrewery +black grama +tutee +brickkiln +sea raven +guesser +wirework +European lemming +thyrse +plains lemon monarda +milo +shunt +spotted cowbane +anchovy sauce +grande dame +Maryland golden aster +Chinese puzzle +boarfish +burweed marsh elder +defense contractor +nitric bacteria +Belgian hare +beach plum +conformal projection +sand fly +steering linkage +quickset +Mahayanist +Geiger tube +loudmouth +Lancastrian +brownie mix +ex-spouse +deltoid leaf +Shasta salamander +rabbet joint +purple anise +garibaldi +gebang palm +bladderpod +Host +great bowerbird +string cheese +spinning jenny +drift net +matriarch +guar +bitter betch +panda car +mess +plains pocket mouse +scarlet wisteria tree +deerberry +reamer +homing torpedo +molehill +stockyard +reniform leaf +rag +symmetry +Texas star +lerot +pickle relish +three-seeded mercury +cotter pin +ice-cream bean +farmyard +bar magnet +hansom +prickle cell +renal cortex +pest +Ultrasuede +sailing master +brougham +wastrel +amboina pine +Canary Island hare's foot fern +ninepin ball +southwestern lip fern +usherette +lemon drop +star begonia +weeds +saltworks +Persian melon +corbina +medusa +bucksaw +Gibson girl +diameter +American twinflower +kino +clear liquid diet +angiocardiogram +wetter +oyster cracker +yellowfin mojarra +wild parsley +life tenant +broom closet +Corynebacterium diphtheriae +square shooter +bedwetter +ball-and-socket joint +nonsolid color +Salmonella typhimurium +buffel grass +hip pad +subaltern +heliothis moth +trail boss +hayloft +Francisella +primordial dwarf +cock-a-leekie +sugarplum +propulsion system +tyrolean +Carib +salai +ketembilla +ironclad +cornhusk +heckler +multistage rocket +north island edelweiss +Chaldean +twenty-two pistol +Francophobe +scofflaw +sickle feather +screw bean +sea squill +Scopolia carniolica +agglomerator +western holly fern +presenter +straight pin +Myxine glutinosa +Colbert +clover-leaf roll +war paint +bird's-eye bush +longfin mako +running suit +arrow wood +margrave +blue fleabane +dracontium +plastron +chimney swift +child prodigy +commissar +turtle soup +postulant +archaebacteria +snakefly +Pitot tube +chap +smilo +Malthusian +French roof +worm wheel +gulag +pointed-leaf maple +pull-off +Cathaya +American green toad +ball cartridge +infiltrator +snowfield +crotchet +auxiliary pump +bearnaise +galax +chaenactis +olympic salamander +sundowner +cows' milk +beach plum +moss-trooper +Arabidopsis thaliana +cat's-claw +bog rosemary +ribier +book agent +bumper jack +beefwood +monk's cloth +alpine bearberry +climbing fumitory +cucking stool +puka +Piltdown man +property man +discharge lamp +X chromosome +knobble +lobster Newburg +herbalist +sunray +golden saxifrage +leopard cat +muffle +stonewort +blancmange +intraocular lens +trepan +desert mariposa tulip +plume poppy +Dane +martynia +shaver +white milkweed +napu +tansy-leaved rocket +abortus +telemeter +tansy mustard +harpy +honeysuckle +ironworks +testacean +Tartuffe +silvervine +Sihasapa +surface gauge +western blind snake +paramyxovirus +Icelander +bird louse +stockbroker belt +test-tube baby +ague root +little golden zinnia +dietician +elephant's-foot +dirty bomb +sailing warship +brier +tinter +Connemara heath +potato fungus +bait casting +decagon +rosefish +die +high-pass filter +solitaire +widow's walk +goldthread +Tudor +trews +orange pekoe +ninon +soda jerk +sump +flying carpet +burial garment +oblanceolate leaf +press gallery +Shintoist +three-centered arch +spreading pogonia +Moro +foxtail orchid +Ghanian +dry kiln +thane +naranjilla +bitter pea +American bugbane +apron string +oyster fish +Port Jackson fig +prize winner +high-water mark +Oneida +smoking room +potato skin +charge d'affaires +gantlet +amyloid plaque +barmbrack +mate +arrow leaved aster +handbarrow +horned screamer +virago +linoleum knife +rattlesnake root +K ration +reset +foot brake +red coral +good guy +aberrant +lavalava +poleax +garden webworm +sneezer +mountain heath +American dog violet +eolith +chimneysweeper +matriarch +smalltooth sawfish +sea mouse +tubercle bacillus +superconducting supercollider +Abney level +darnel +gherkin +celery salt +Tungus +pulasan +oriflamme +death camp +redhorse +apprehender +scion +selectwoman +pentahedron +principal +old school tie +slice bar +chanar +pimento butter +wailer +zero +mescal +rosebud orchid +stone bramble +Jarvik heart +NOC +pitchman +rat cheese +strawberry tomato +dwarf golden chinkapin +landau +tocsin +ampulla +scratcher +crab Louis +ginseng +ripcord +polluter +tensiometer +eyewitness +aalii +Oregon crab apple +conservator +day jessamine +hexahedron +suture +tippet +linsey-woolsey +vernal witch hazel +stainer +egocentric +canistel +nudger +shipping agent +shortleaf pine +battle sight +cheese spread +weeder +incendiary bomb +honeyflower +stovepipe iron +stepper +hellgrammiate +votary +aflatoxin +arquebus +impulse turbine +pipewort +garrote +glow lamp +pigsticking +blood clam +surface search radar +Bolshevik +platen +chariot +Gentianopsis thermalis +water level +quandong +catalytic cracker +giant foxtail +nut butter +drainplug +holdover +coastguardsman +Secretary of Health and Human Services +Seeing Eye dog +American plaice +coquilles Saint-Jacques +christella +medium +clingfish +lally +light-o'-love +Gentianopsis detonsa +taper file +signal detection +trip wire +lignosae +receiver +sedan +mud puppy +corn sugar +Philippine mahogany +magnetic pole +jointed rush +trapper's tea +Dorking +welcome wagon +clammyweed +guard +false azalea +convalescent +babassu +dedicated file server +colossus +air search radar +marquess +straight flute +sand stargazer +sea catfish +rosilla +ripsaw +Bermuda onion +peach sauce +sagebrush mariposa tulip +yashmak +Virginia mallow +erose leaf +sand blackberry +boulevardier +forester +choragus +onion mildew +threadfin +winged pea +sugar daddy +rotary press +styracosaur +rathskeller +Japanese millet +anchorite +coral drops +false gavial +eastern pipistrel +cheese press +Chinese primrose +pamperer +real estate broker +power worker +breeder reactor +nutcracker +piano wire +cushaw +Sinanthropus +firebreak +kelp greenling +herba impia +toll call +yoke +bird fancier +evening-snow +fever tree +reed meadow grass +flanker back +toggle bolt +Santa Cruz cypress +carbonnade flamande +northern dune tansy +mikado +millettia +forty-five +court +icepick +holm oak +Japanese angelica tree +Pacific cod +cant hook +urologist +spelt +lekvar +enologist +Mediterranean flour moth +prickly-edged leaf +Spanish grunt +dune cycling +frostweed +whisperer +tucker +Roman wormwood +counterterrorist +woolly alder aphid +Nuttall oak +snail butter +threshing floor +motley +forge +water mold +mummichog +sulfur paintbrush +head +walking delegate +jujube +peachleaf willow +Christmas bells +valley pocket gopher +bear's-paw fern +Lanthanotus borneensis +pearl hominy +placeman +swage block +offerer +stargazer +jeweler's glass +male chauvinist +crossbar +Oktoberfest +tamarau +micronutrient +large-leaved aster +tasset +tepary bean +sausage curl +ivy +snob +roller towel +wood meadowgrass +archil +padrone +prairie rocket +tongueflower +kidney fern +Carolina buckthorn +sea island cotton +landscape architect +realist +oyabun +mother hen +ostracoderm +esker +heliophila +nympholept +shining clubmoss +press agent +clam dip +Djiboutian +white currant +codfish ball +hand cheese +kraal +trident +conventicle +bacteroid +Indian plantain +quandong +kola nut +signor +theater light +musk clover +canistel +silent partner +steel-wool pad +diggings +affluent +sightreader +John Doe +arrowworm +goatsfoot +guardroom +wild cinnamon +kaffir boom +ink eraser +yardie +industrialist +sea lily +polarimeter +Polistes annularis +western big-eared bat +omnivore +Ted +horsecloth +crab cocktail +vacuum chamber +flower-of-an-hour +bilge +poleax +neolith +Montezuma +plum-yew +welfare case +trave +pipe bomb +shading +Centigrade thermometer +bangalore torpedo +celery top pine +nuclear rocket +fowling piece +anti-Semite +landscape +derris +bush honeysuckle +Mediterranean water shrew +ticket collector +masked shrew +white dipladenia +Savoyard +bondman +tempter +pygmy cypress +pentathlete +thruster +usurper +Arminian +yerba buena +ice field +ichthyosaurus +sackcloth +bean tostada +Oxbridge +Pteropus hypomelanus +thinker +bank robber +ape-man +thurifer +knawel +mule fat +hot spot +hairy-legged vampire bat +night raven +hook and eye +crocodile bird +skunkweed +beaver rat +cypress sedge +florida selaginella +April fool +Jonah crab +glass wool +corkwood +dwarf elder +hinging post +gentile +Brazilian trumpeter +witch doctor +thermograph +pink shower +Mao jacket +capelin +parang +bradawl +stooper +jewel orchid +citrange +oarswoman +Macedonian +particolored buckeye +pachycephalosaur +satinwood +Chinese brown sauce +peep sight +straight man +quandong +chamois cress +nonfat dry milk +rosin bag +Leiden jar +Grimes' golden +spirillum +grass vetch +carillonneur +downy wood mint +melon ball +sweet calabash +chlamydospore +bombshell +sidewall +sprig +Indian button fern +globe pepper +rough-stemmed goldenrod +bocconia +bubble chamber +sand dab +plum-fruited yew +aecium +marrowfat pea +hobbyist +whipper-in +salad burnet +neckband +Tangier pea +sauce Louis +salad burnet +artist's loft +koumiss +Nazarene +cutter +scrim +drape +crab-eating dog +deckhand +bedroll +gaff +stifler +pink lady +great plains paintbrush +patternmaker +yoke +caryophyllaceous plant +angrecum +quadriplegic +grid +genlisea +aspic +water table +junket +signore +Mutillidae +proprioceptor +pivoting window +Indian poke +synchroscope +trichion +tarahumara frog +proctoscope +abomination +purslane speedwell +breast drill +Japanese barberry +mandrake root +breakable +salon +American watercress +take-up +entrenchment +cocktail sauce +Scotch asphodel +borough +matchmaker +Seneca snakeroot +pointsman +psephologist +clustered poppy mallow +onion thrips +nuclear-powered ship +organizer +deciduous holly +balsam willow +enzymologist +caraway +drip loop +dog laurel +Orangeman +sapsago +polymath +backplate +leathery grape fern +modillion +two-timer +handhold +consignee +white stringybark +nettle-leaved goosefoot +bookmaker +disk drive +doliolum +palmist +packinghouse +Spandau +Whipple's penstemon +sword grass +ribbon development +pearly-shelled mussel +winter heliotrope +rogue elephant +deck tennis +Venus's flower basket +football +shim +boatswain +blinks +armored catfish +hooded seal +outdoorswoman +water starwort +upholstery needle +pleurodont +silky anteater +cornmeal +lead-in +redfin pickerel +horse balm +Rydberg's penstemon +cascade transformer +fly poison +Volvaria bombycina +broad-leaved twayblade +pastry cart +body plethysmograph +waverer +hardware store +Parry's penstemon +European sanicle +strawberry geranium +cross-examiner +head gate +devil's tongue +hemiepiphyte +pine hyacinth +machmeter +spirit lamp +field judge +Rock Cornish +mayhaw +Sassenach +bog pimpernel +parallel interface +crowberry +roach +Aegyptopithecus +cajan pea +lapboard +cryostat +magnetic storage medium +white yam +Lombard +rhymer +bed and breakfast +bunya bunya +rifle grenade +caterer +collared pika +anti-submarine rocket +bookkeeper +Western mountain ash +profit taker +fruitlet +Knowlton's cactus +infernal +beefsteak begonia +lunula +emulsion +intermediate wheatgrass +titfer +European sea bream +bigeye scad +yak butter +kola +cone pepper +plesiosaur +ragwort +penal colony +black carpet beetle +lubber's hole +Stapelias asterias +yard marker +balloon bomb +Scythian lamb +armory +selsyn +marblewood +spirula +fatalist +hash head +armiger +Dom Pedro +white-chinned petrel +ballast +orthopter +greater water parsnip +clutch +largeleaf holly +Evangelist +king whiting +tuna fish salad +Muscadet +surpriser +jumping bristletail +proportional counter tube +Hamburg parsley +obstructionist +pus-forming bacteria +creep feed +stepbrother +janissary +control freak +trusty +trepan +King William pine +orthicon +geological horizon +molecular biologist +violator +pariah dog +Austrian +conciliator +Fauntleroy +packing needle +mazer +Saturday night special +leucocytozoan +coastal rein orchid +whirligig beetle +capitalist +breeches buoy +clubroot fungus +meadow spikemoss +Kichai +Spanish lime +land office +camera obscura +strafer +purple-stemmed aster +lusterware +valve +Roman nettle +isthmus +breadstuff +sealskin +maleo +bilge keel +carissa plum +fish fly +kolkhoznik +heath pea +cowage +hog sucker +Sam Browne belt +inductor +wild licorice +Socotra begonia +supernumerary +Angle +red shrubby penstemon +toilet kit +tawse +sweet bells +kawaka +brown soft scale +lyssavirus +betting shop +double-crosser +macrotus +climbing hempweed +poi +strip mall +deadhead +petit juror +tract housing +American mistletoe +lace-flower vine +precipitator +endoparasite +hairy wood mint +red snapper +Victorian +hog peanut +line of heart +opossum shrimp +plumcot +Bavarian blue +slops +light flyweight +oregano +sand myrtle +pocket battleship +curator +narc +hydraulic cement +plains pocket gopher +closed loop +pluralist +molter +Christmas bush +snuffers +slender knapweed +footwall +plage +caper tree +red siskin +tender +boat train +tipster +low-pass filter +student lamp +morosoph +japonica +bellows +herald +oyster plant +savory +mail +computational linguist +blade +winter crookneck squash +zoomastigote +blackmailer +richweed +dialectician +genip +plumed scorpionfish +jet bridge +thermopile +billy buttons +Brule +millwright +Arenaviridae +Jones' penstemon +monastic habit +genipap fruit +burnous +dairyman +top +crab-eating raccoon +quadrangular prism +pilot burner +weeder +trireme +boy wonder +man of letters +Catawba +high-muck-a-muck +light circuit +bloodworm +lappet caterpillar +half-and-half +office boy +saddle stitch +mistletoe cactus +false chamomile +Catalina cherry +workhouse +Jamaica quassia +britches +tooth shell +reduction gear +carrot pudding +balsam woolly aphid +handspike +aioli +silver hake +flour bin +wireman +gas-cooled reactor +aficionado +plus fours +gitano +gene chip +oilfish +ingenue +tulip orchid +late purple aster +pork and beans +envoy +lemon extract +milk bar +black huckleberry +ground roller +Connecticuter +siderocyte +Jacquard loom +chub +meat safe +stock cube +Australian sumac +purple sanicle +tailless tenrec +dog wrench +rainbow cactus +castor bean +scintillation counter +eohippus +pawnbroker +gauge boson +front man +early warning radar +bearing wall +Bourbon +sandwichman +sild +gravelweed +perishable +cembra nut +riflebird +quicksand +slate +sweeper +ship-towed long-range acoustic detection system +defamer +president +vitamin K3 +challis +tanekaha +bloodwort +grenadier +quietist +Zairese +fucker +foremother +gesneria +print buffer +salsilla +fissiped mammal +fender +consulate +acidophilus milk +Southern dewberry +snail darter +Panama redwood tree +dehydrated food +bush willow +coffee fungus +Sinologist +Mesoamerican +hood +large civet +deck-house +cyborg +smuggler +pepper sauce +cyberpunk +Grand Inquisitor +persona non grata +haggis +weeping tree broom +stop bath +modifier +coyol +conodont +yellow giant hyssop +optical pyrometer +Carolina moonseed +marinade +aspartame +false wintergreen +cityscape +philter +turnery +hemiplegic +chuck-will's-widow +vower +track star +myrtaceous tree +small civet +intelligence analyst +dogcart +yardman +cross bit +holometabola +platen +sweet cassava +Comstock mealybug +acute angle +Communist +alcohol thermometer +mountain hollyhock +Mead's milkweed +highjacker +Townes +congou +Astrophyton muricatum +lazybones +roughcast +pressure cabin +clinch +cinnamon +smoke bomb +quandong +tout +office-bearer +punctum +efficiency apartment +Queensland hemp +Ceylon bowstring hemp +newswoman +vermin +fetid bugbane +grantee +sanitary landfill +gluten-free diet +clabber +shillelagh +white lettuce +sweet coltsfoot +beggar's lice +samite +loser +flasher +water star grass +banana passion fruit +translator +artificial kidney +Virginia creeper +American crab apple +cactus mouse +nebbish +Ligustrum obtusifolium +vox angelica +stringer +hunter +know-it-all +scene painter +invalidator +jungle cock +basilica +coriander +California single-leaf pinyon +miles gloriosus +pina cloth +law agent +scarlet fritillary +keurboom +bailor +ramjet +seedling +rib joint pliers +ways +picket ship +Surgeon General +wasabi +marquis +clostridium perfringens +Helvella sulcata +furnace lining +kingwood +painted sandgrouse +plain wanderer +Indian madder +silver screen +bailey +dwarf spurge +Serbian +ball-buster +shaheed +Platte River penstemon +tensiometer +mute +nymphomaniac +Yokuts +arroyo willow +whipping post +class act +load +winged everlasting +periodontist +diarist +robber frog +diestock +curry powder +ratchet wheel +store detective +hog plum +prune whip +shortwave diathermy machine +Anabaptist +post chaise +Kennan +bean caper +delegate +orderly sergeant +celtuce +jumping bean +gowen cypress +puddingwife +registered nurse +West Saxon +rosita +gun room +nasotracheal tube +matchboard +flagship +Boswellia carteri +Canadian pondweed +wonder boy +sewer rat +dimetrodon +pantograph +marsh bellflower +angoumois moth +slippery dick +woolly indris +creme de cacao +dulciana +Jewess +Macadamia integrifolia +least shrew +don +diffuser +black-stem spleenwort +grouseberry +goniometer +annotator +sticktight +gossip columnist +speechwriter +capon +rock hind +Liederkranz +chandler +echocardiograph +sidelight +fisher +brocket +New Zealand daisybush +northern sea robin +roller bandage +peachick +pellet +pichi +plug fuse +spark coil +buckwheat +brood bitch +wedgie +dwarf bilberry +filigree +bull +queen +dodo +Salish +denticulate leaf +Western silvery aster +Prima +magnetic bottle +fetterbush +process-server +nainsook +mythologist +Piedmont glacier +hammerhead +niggard +Mound Builder +Kui +Nootka +highbinder +passenger pigeon +oblong +tickler coil +agnostic +succorer +esophagogastric junction +dressmaker's model +bombshell +social anthropologist +gildhall +orpine +pterodactyl +bristly sarsaparilla +Lane's Prince Albert +hognose bat +salesgirl +lubricating system +electric catfish +wrap +Jacksonian +chard +cherry laurel +foreground +beadsman +Kolam +amniote +frozen pudding +acid head +poor box +depositor +coattail +pallas's sandgrouse +mason's level +English lady crab +skeg +cruel plant +petrolatum gauze +tuna +swivel +stock-in-trade +perisperm +civies +Phyllostomus hastatus +alienor +Verdicchio +guard's van +onion butter +moviegoer +planter +citrange +box huckleberry +iconoscope +familiar +helmsman +baby boomer +constructivist +American bog asphodel +whorled caraway +simple pendulum +viviparous eelpout +Job's tears +holdout +sour salt +poison bush +dusky-footed woodrat +golden algae +granadilla tree +telethermometer +crossbar +thrift +African bowstring hemp +dog in the manger +hayrack +gold-crowned kinglet +prolonge +doge +pencil +discount house +mulligan stew +Nonconformist +virologist +gregarine +facula +rocket scientist +thin-shelled mussel +oospore +annual salt-marsh aster +Afrikaner +metallic +julienne +culverin +cleavers +Berliner +mudhif +thorny skate +brown lemming +yellow colicroot +cooling system +large-leaved magnolia +free-reed +canyonside +preemptor +stake +Brucella +anti-G suit +pleximeter +squire +salsilla +write-in candidate +lowland burrowing treefrog +flare star +dwarf hulsea +jobber +mangel-wurzel +quagga +red-skinned onion +positive pole +Pteropus capestratus +jug wine +stomacher +standee +bladder worm +hakim +house of correction +pelisse +golden mole +temporizer +rose apple +drove +umbrellawort +holy of holies +lawyer cane +smooth lip fern +anode +astatic coils +zip gun +feverroot +self-heal +expansion bit +salt reed grass +field pussytoes +nutmeg hickory +cryptic coloration +Venus's girdle +Hunkpapa +Calostoma cinnabarina +raft foundation +May apple +pygmy mouse +prokaryote +yellow-green algae +Bermuda maidenhair +withdrawer +coelacanth +Elliott's goldenrod +driftfish +epicyclic train +bowl +swamp dewberry +corbel step +sadist +party line +anti-American +mining engineer +Amur privet +conidium +Gastrocybe lateritia +lithia water +chaulmoogra +Rough Rider +Guinea pepper +glade mallow +pitcher sage +whitecup +shanghaier +low St Andrew's cross +phonologist +cocobolo +perfumery +visor +prison chaplain +belt +ingesta +literary critic +industrial watercourse +reckoner +pursuer +Kinetoscope +Kuiper belt +hyperope +raw recruit +Galiella rufa +Prince Albert yew +slit trench +usher +tenderfoot +white-rayed mule's ears +browser +piccalilli +bran +giant buttercup +water lobelia +arborescent plant +echinus +dryland blueberry +struggler +platyctenean +Geordie +domatium +twenty-two rifle +keteleeria +sports editor +chorus girl +Hakham +dry-bulb thermometer +onomancer +double-bitted ax +Girondist +bottle bank +thyrsopteris +bandwagon +star anise +armored car +dhawa +Bessemer converter +mutineer +paradise tree +tupik +centurion +mending +chowchow +margrave +International Grandmaster +African hemp +catafalque +leptodactylid frog +forcemeat +tank shell +pill +barbecue pit +worthy +lady's maid +evergreen +Jesuit +South American staghorn +rigger +suffragan +imperialist +spherical angle +grey lemming +kitchen police +tree swift +coliphage +archaist +Conservative +rib +exegete +Mendelian +tragedian +steerage +Paleo-American +obeche +garlic +grapefruit peel +accommodating lens implant +half blood +barrelfish +catgut +lanceolate spleenwort +hardliner +frieze +name dropper +carrack +huckster +onion bread +magnetic head +pease pudding +raisin moth +negative magnetic pole +electroencephalograph +bunji-bunji +synchroflash +Mornay sauce +stencil +winged pigweed +Nesselrode +MEDLINE +licorice +mainspring +melilotus +duke +experimenter +Napier's bones +four-minute man +pin-tailed sandgrouse +toolmaker +pogge +rootstock +baton +pricket +creeping snowberry +anomalops +nester +devourer +apolemia +Maricopa +pine-barren sandwort +larvacean +American dewberry +escalope de veau Orloff +gig +myrtle +pitsaw +Lutheran +fish house punch +gnathostome +intake valve +molasses taffy +clammy locust +vandyke beard +Atlantic tripletail +planktonic algae +estradiol patch +flummery +cytologist +sectarian +oil meal +tomtate +mediterranean anchovy +aspersorium +argonaut +porkholt +sheep ked +algometer +Adventist +false goatsbeard +snake polypody +streetwalker +shelver +adoptee +highflier +pitch apple +prairie rocket +fish mousse +viroid +deckle +manila tamarind +observer's meridian +pincurl clip +hardstem bulrush +gossamer +brookweed +Druze +hug-me-tight +accessory before the fact +oilman +Comanche +Marine +bedlamite +Chinese cork oak +squawbush +false miterwort +walk-on +Cynopterus sphinx +brandyball +landlubber +arrowroot +cape forget-me-not +galoot +tabor pipe +checker +Levant cotton +paddle box +murderess +smirker +fuddy-duddy +withdrawer +newel +shade +pink disease fungus +tipu +sweet sultan +aeronautical engineer +tall gallberry holly +acarid +conqueror +cucumber +film director +ordinary +salon +closet queen +allegorizer +tonka bean +flax rust +negative pole +dagame +dentist's drill +mock privet +micropyle +contributor +dark horse +climbing corydalis +cosmotron +land agent +Big Blue +Cynic +tassel flower +lyrate leaf +Minuteman +Dutch-elm beetle +Hessian fly +flower girl +West-sider +window dresser +skinny-dipper +whitebait +out-and-outer +hooker +amicus curiae +jack +camwood +stockist +black root rot fungus +Jamaica dogwood +diaphragm +Holocentrus ascensionis +roselle +black maire +Pygmy +fumigator +lame duck +mudder +hydraulic transmission +conning tower +phoronid +batfish +hearing dog +monohybrid +whaling gun +Cockcroft and Walton accelerator +allemande +seasoner +epileptic +ammonia clock +Young Turk +lanseh tree +urceole +cafe noir +poster girl +Oglala +deadeye +manna lichen +positive pole +cinch +lyricist +hermaphrodite +kidney stone +dilator +number one +frotteur +kaffir bread +fish knife +tarragon +adjuster +potato wart fungus +Florida pompano +conductor +corbie gable +rounders +Catha edulis +bender +recruit +Uruguayan +subject +bunghole +day boarder +pocketed bat +Oxonian +owner-occupier +yellow-leaf sickle pine +devisor +exhibitor +looking glass +shipowner +crooked-stemmed aster +calico +dash-pot +defilade +Confucian +egg-and-dart +irreligionist +lepton +self-rising flour +diving bell +Brahui +shop girl +maximum and minimum thermometer +Dalmatian laburnum +correspondent +subduer +nonperson +Reaumur thermometer +rough-leaved aster +jacksmelt +pinfold +magneto +ex-wife +round-leaved rein orchid +purloo +American shrew mole +sweet sand verbena +polymastigote +outfitter +curled leaf pondweed +Italian dressing +borderer +ambusher +geebung +four-stroke engine +small ship +homeopath +gynostegium +political prisoner +Radiigera fuscogleba +ensiform leaf +rhizoctinia +satyr orchid +rue +bouillon cube +flip +prophyll +tilefish +periselene +prima donna +choker +laminar flow clean room +Hooker's orchid +fish joint +mombin +remover +array +coelostat +autophyte +consigner +Damaraland mole rat +gasman +public works +lye hominy +pearlfish +piassava palm +Georgian +uxoricide +confessor +community center +epigone +tagger +abrading stone +cryoscope +nautch girl +reliever +Cartesian +Indian beech +protoplasmic astrocyte +fundamentalist +mustard sauce +crank +houselights +five-point bishop's cap +comedienne +triangle +presentist +beaugregory +dreamer +Wave +blue mockingbird +Barbados gooseberry +ten-spined stickleback +papoose +silky pocket mouse +holdup man +agent-in-place +suspensory +emigrant +ropemaker +bookbinder +jumby bead +undershrub +Killarney fern +sheep bell +city slicker +equerry +pea crab +down-and-out +blackmouth bass +shirtmaker +lister +UNIX guru +snipefish +gimbal +maisonette +haircloth +Ranvier's nodes +pigmy talinum +tribute album +msasa +hydroxide ion +madame +four-pounder +prophet +sloganeer +field-effect transistor +nude mouse +canteen +Calostoma lutescens +buteonine +sunlamp +Uruguay potato +Spanish tamarind +Prince-of-Wales'-heath +kishke +caprifig +chincapin +hegari +alarmist +bathtub gin +astatic galvanometer +Calostoma ravenelii +marang +tussah +coin box +bugleweed +hacker +frontal eminence +timekeeper +shunt +bicycle clip +mustang mint +caesium clock +hospice +glenoid fossa +archpriest +ex-gambler +incrustation +salvager +Donatist +violator +lamb succory +hygroscope +oilbird +sharptail mola +showplace +corn syrup +flashlight fish +pulse timing circuit +anchovy paste +fascista +chigoe +divan +Druid +squad room +Huntingdon elm +buffalo carpet beetle +carper +corn lily +goats' milk +assault gun +cockpit +Lochaber ax +Visigoth +occupier +Basotho +criminologist +spindle +Rosicrucian +Cornishwoman +musk kangaroo +artificial skin +pandurate leaf +Parkia javanica +roundhead +tea-like drink +basidiolichen +unguiculate +stepmother +Nauruan +gutta-percha tree +bloodberry +scarlet haw +marupa +censor +algebraist +pelvimeter +whaler +cowhide +paparazzo +biochip +internationalist +Yukon white birch +hangar queen +chlamydia +puttee +Pipturus albidus +pearly razorfish +sea moss +burglar +hoary golden bush +colter +drey +bushman's poison +maxillaria +gnetum +deadeye +shittah +swamp oak +damper block +deepwater squirrelfish +truffle +cangue +paleolith +lawyerbush +sorehead +Texas snowbell +Tremella reticulata +quarter +keelboat +dimity +whiner +Wagnerian +myrmecophyte +frontierswoman +pyrometric cone +big-tree plum +puppy +galbulus +hod +winceyette +carriage wrench +dictostylium +farmland +infanticide +Jacob's rod +threadfish +monocline +inamorato +leaf miner +purple cress +passer +black-fronted bush shrike +silverrod +bootmaker +segregate +captive +Edmontonia +spherometer +television transmitter +bladder +Saratoga spittlebug +dynamometer +lodge +smooth darling pea +Cossack +wake-up call +Olmec +sutler +molasses kiss +corner post +rattlesnake weed +yardmaster +adder +rhinoscope +referral +ulster +pantaloon +counterspy +gadgeteer +heart cherry +hospital chaplain +Clydesdale terrier +plank-bed +Russian thistle +actinometer +dyspeptic +common wolffia +firewall +seidel +potato moth +soapweed +seif dune +thill +cosmographer +absolver +halberdier +fire control system +kai apple +bastard pennyroyal +Big Brother +broadcast journalist +Albatrellus dispansus +citrophilous mealybug +split end +nickel-iron battery +Newtonian +gas maser +thumbstall +anaspid +dusky-footed wood rat +latitudinarian +flatbrod +schizocarp +niqaabi +flight surgeon +gyrocompass +Polyporus tenuiculus +Utopian +mailboat +spellbinder +undercoat +cassareep +typical jerboa +photocathode +katharometer +bight +fur-piece +penetration bomb +malik +Siberian millet +nanomia +Wykehamist +tosser +gyrostabilizer +microwave diathermy machine +crystal set +wall +legatee +alfalfa +angwantibo +charioteer +piano maker +African mahogany +Morlett's crocodile +taro +parallel circuit +cush-cush +etymologist +matriculate +neem seed +cornerback +kingfisher daisy +redoubt +blastomycete +peplos +costumier +publican +tobogganist +semolina +myrmidon +parricide +gymslip +whoremaster +cryptocoryne +header +platitudinarian +barleycorn +spiral bandage +reciter +abecedarian +dance +wrymouth +bilberry +Liopelma hamiltoni +streamliner +Fordhooks +fixed phagocyte +radiobiologist +neurologist +Selkup +dollarfish +cascade everlasting +acrodont +boarhound +midstream +theatrical producer +abhorrer +goldsmith +photometrist +Anglo-Saxon +rugel's plantain +sable +workmate +ferule +ankus +earleaved umbrella tree +Passamaquody +timucu +Mexican pocket mouse +yerba santa +Rochon prism +apomict +monocarp +sweet unicorn plant +common winterberry holly +archivist +drypis +paretic +fly-by-night +white-berry yew +Schoolman +blue cheese dressing +vintager +squatter +Euphausia pacifica +corrugated fastener +yellow henbane +Croesus +almoner +analphabet +acoustic delay line +sheep frog +workhouse +horseleech +venturer +pond-scum parasite +Pyrenees daisy +plagiarist +Truncocolumella citrina +rerebrace +group captain +caddis fly +hot-rock penstemon +kanzu +stylopodium +slopseller +rauli beech +starter +ootid +statesman +distributor cam +ascot +falcon-gentle +Duplicidentata +spotted antbird +heliometer +false buckthorn +Allegheny spurge +Cavalier +dart +photocoagulator +master-at-arms +kei apple +baldachin +crapshooter +gametangium +white hope +chipotle +spike heath +Scotch woodcock +Florentine +differential analyzer +Mitrula elegans +wet cell +basil balm +Circassian +corn cake +bouncing betty +vice-regent +lagerphone +ketembilla +whoremaster +fork +tetrasporangium +trifler +pill head +life-support system +quartermaster general +tobacco thrips +officeholder +teredo +toyon +Sundacarpus amara +Phytophthora citrophthora +naif +lobbyist +alligator wrench +bully +heavy +toxicologist +radio chassis +waterdog +drive line +kaffir cat +foster-brother +breakax +curette +traditionalist +pipe vise +striped button quail +gawker +homeotherm +schoolyard +battue +kalansuwa +deviationist +Bolshevik +transponder +pungapung +iron +Eyeish +roccella +manglietia +Tory +print seller +Texas Ranger +otter shrew +seconder +shellflower +outlier +party man +wold +hayfork +oncologist +framer +co-beneficiary +ocean pout +Chinese angelica +scrimshaw +air attache +false gromwell +standing press +fringepod +specifier +automatic choke +durum +yenta +wassailer +reeler +signora +beach pancake +common booklouse +pellicle +backroom boy +den mother +associate +Unitarian +gambist +brookweed +clubroom +cat's-tail +playboy +self-registering thermometer +doorstop +bennet +yak's milk +escapee +quail bush +sparge pipe +coast boykinia +screw key +half gainer +aggravator +cotton mill +tailor's chalk +free agent +cotton mouse +deadhead +bunny +turpentine camphor weed +amaranth +ceratodus +red lauan +beam-ends +thermograph +wally +Toda +handrest +commissary +oak-leaved goosefoot +manufacturer +voicer +Jafnea semitosta +bench hook +finder +abyssal zone +rabbitwood +Hercules'-club +epicarp +declinometer +camp follower +signaler +Australian pea +putz +qadi +banded palm civet +egg timer +regnellidium +calisaya +harvestfish +sound spectrograph +side-wheeler +glomerule +woolly rhinoceros +Black Muslim +horticulturist +ornithomimid +cryometer +battlefront +gametophyte +airmailer +cuisse +nakedwood +baseball club +slasher +anise +leatherleaf +leatherjacket +horned pondweed +gofer +Saigon cinnamon +barong +blazer +twinkler +skeleton shrimp +dial +floorwalker +case shot +flannelbush +cultivated parsnip +Jane Doe +few-flowered leek +nogging +placer miner +muzzler +serge +lion-hunter +capulin +Wandering Jew +ascidian tadpole +hispid pocket mouse +southern spatterdock +milk wagon +junior middleweight +duck sauce +promycelium +protozoologist +cascade liquefier +tout +longheaded thimbleweed +charcoal burner +footage +slop +bridge agent +miller's-thumb +Job's comforter +marocain +tanker plane +lancetfish +knocker +toque +ordinand +umbrella bird +favorite son +hare's-foot bristle fern +business traveler +plotter +Asiatic shrew mole +tallyman +stump +Paleacrita vernata +index register +mortgagee +accuser +codger +sand rat +seaside centaury +chiropractor +Florida smoothhound +dwarf sperm whale +T-man +sannup +dragonhead +numdah +alkali grass +gynobase +kymograph +ascolichen +steward +waterline +Nazarene +filer +lapidary +muncher +wincey +scyphus +question master +besieger +worldling +docent +facing +atmometer +quern +puerpera +three-decker +calliope +wild red oat +bailee +flame pea +cattle cake +theist +yellowtail flounder +cosmopolitan +rocket engineer +vouchee +Turkoman +hard sauce +Thousand Island dressing +assayer +messmate +mutilator +oyster bar +flame tokay +countess +prairie mimosa +microsporangium +cotter +townsman +paring +fundraiser +simperer +Comrade +orlop deck +power takeoff +cattleship +prime meridian +Javanthropus +scriptorium +curandera +long-clawed prawn +maestro +paster +potato tuberworm +chachka +junkyard +cape yellowwood +reentrant polygon +Liberian coffee +restaurateur +Alsophila pometaria +Jekyll and Hyde +electrophorus +Scomberomorus maculatus +manipulator +gromwell +chicken provencale +ashram +mangel-wurzel +shamrock pea +dossal +adducer +erection +Mysore thorn +smoothie +chufa +brace wrench +victualer +litterer +linstock +Protium guianense +palfrey +banyan +klieg light +dangleberry +trooper +yaupon holly +quitter +tradescant's aster +nullipara +melter +devil's urn +ghostwriter +mouth +analogist +Creek +sonic depth finder +fucker +locus of infection +mortician +esophageal smear +locum tenens +conic projection +aroeira blanca +bellarmine +night porter +automobile mechanic +codpiece +Munro +cottonweed +scoinson arch +tinderbox +frozen food +waterproofing +Egyptian henbane +lash +transactor +American smooth dogfish +existentialist +grabber +Sonoran lyre snake +Rufous rubber cup +colors +weekend warrior +power user +perennial salt marsh aster +Puritan +Apalachicola rosemary +anecdotist +tosser +moth bean +agnostic +stretcher-bearer +browntail +optimist +brewer's mole +astronomy satellite +flat file +rust mite +tuberous plant +day laborer +buster +trapezoid +bevatron +nonresident +Streptomyces griseus +mangosteen +customer agent +hero worshiper +suicide bomber +procellariiform seabird +archiannelid +reaction turbine +distortionist +bulldog wrench +grainy club +scalp +Aztec +scow +globigerina +pedant +heartleaf manzanita +kanchil +low gallberry holly +containment +scandalmonger +rose-colored starling +Powhatan +addle-head +Chilean rimu +Atlantic sea bream +arthrospore +ramrod +root climber +Kalapooia +roach clip +Schreiber's aster +horseradish +albino +Kshatriya +trombidiid +blasting cap +body pad +brachium +shallu +Wynnea americana +slender centaury +munj +upset +wind tunnel +cottonwick +airing cupboard +pepper shrub +ambrosia +languisher +chosen +rose globe lily +purple apricot +costia +sloop of war +sultana +frontlet +booster +sargassum fish +broad-leaved montia +rifleman bird +stillroom +amoralist +enginery +meter maid +fitment +southern bog lemming +Athenian +clincher +cusk-eel +mackintosh +diaphone +corozo +Australian reed grass +czar +spongioblast +Eurafrican +airhead +Shahaptian +Roman +pollinium +tourist class +halogeton +stamper +emperor +malingerer +tramp steamer +Peziza domicilina +pilot cloth +stenopterygius +cost accountant +Queen's Counsel +wine-maker's yeast +poppet +cage +rowlock arch +landgrave +bearded wheatgrass +stink bell +quaker +undesirable +algarroba +resistance pyrometer +exorcist +carib wood +guvnor +border patrolman +bathhouse +licenser +headman +rentier +pine spittlebug +nut-leaved screw tree +paraduodenal smear +apron +necker +smilax +Alpine besseya +creeper +castle +ground bait +Queensland grass-cloth plant +sclerotium +great yellowcress +fat farm +Stoker +hoop snake +elixir of life +Trotskyite +home buyer +wheat berry +Tutelo +semi-climber +utahraptor +wet-bulb thermometer +packrat +hygrophyte +darter +sketcher +refiner +camlet +midgrass +compound +tarwood +Colorado River hemp +toiler +abstractor +override +dwarf pipefish +plodder +briefcase computer +trunk hose +brown butter +valve-in-head engine +cymbalist +explosive detection system +horsewoman +boutonniere +chinchilla +venerator +scourer +exarch +cohune nut +ayapana +continental divide +cosigner +stalker +pyxie +Genet +Macowanites americanus +open-hearth furnace +water chestnut +American frogbit +tarwood +cutter +scout +burr +upsetter +grist +tagasaste +mouthpiece +palette +rattan +letterman +Exmoor +Methodist +eelblenny +marasca +slide valve +ventilation +saddle hackle +Yakut +flux applicator +air traveler +murder suspect +Cynocephalus variegatus +idolizer +Surgeon General +nutlet +little-head snakeweed +germ tube +fellow traveler +raceabout +commodore +czar +anamorphosis +treelet +girlfriend +groundnut +sideline +giant star grass +goffer +spark lever +oubliette +processor +tare +plodder +extremist +Kipp's apparatus +gripsack +S wrench +viscountess +bridgehead +cascarilla +Asiatic flying squirrel +protoceratops +equerry +difflugia +princeling +moonlighter +aspergill +common flat pea +Utahan +imperial mammoth +plantain-leaved pussytoes +Boott's goldenrod +bootlegger +reed pipe +runcinate leaf +onion salt +nitrite bacterium +introvert +duck +New World opah +goliath frog +heterostracan +disrupting explosive +haggler +candlenut +false bugbane +returning officer +eudiometer +ship-breaker +metazoan +mandarin +patka +gill net +cavity wall +armilla +rainmaker +dealfish +orderly +gleaner +muffin man +house sitter +alto +sand devil's claw +vulcanizer +appendicularia +boron chamber +chess +bitok +anchovy butter +dropout +flour mill +bishop +escapist +scapegrace +stanhope +smooth winterberry holly +upstager +stalking-horse +pony +prairie gourd +parabolic mirror +Polaroid +slasher +lap +garlic butter +sendee +German millet +hairy honeysuckle +Swiss canton +Scleroderma flavidium +red goatfish +telegraph plant +Jungian +garment cutter +mallee hen +stranger +driveway +schooner +Paiute +cisco +trestlework +sipper +shanny +romanticist +Molly Miller +mountain rimu +odd-leg caliper +bitumastic +Western Australia coral pea +labor coach +latchkey +harpulla +solitary pussytoes +chop-suey greens +coil +guimpe +diapir +Osage +gutta-percha tree +giant eland +reticulation +garden huckleberry +quick study +Hudson bay collared lemming +coreligionist +Lancastrian +stumblebum +omnirange +seersucker +Potemkin village +Rhea Silvia +symphonist +bolti +jaw +jaconet +page +visiting fireman +haulm +p-n junction +landlubber +yellow jack +triclinium +souari +invader +fire walker +Luddite +Plott hound +hemming-stitch +winker +star-duckweed +craniometer +Arabidopsis lyrata +loser +cypripedia +trimmer arch +cookhouse +pink fivecorner +transfer +ringleader +northern pocket gopher +moke +blockade-runner +cyclostome +web-spinning mite +Whig +transcriber +malahini +sawyer +patent log +paca +tragedian +thermojunction +soffit +black buffalo +foreigner +applecart +brit +pole horse +white mullet +argentinosaur +Homo soloensis +bounty hunter +decumary +hand +paperboy +Smitane +windowpane +Java man +Wynnea sparassoides +prune +middy +lilliputian +sorb +pyrostat +guest worker +hold +leaseholder +vegan +humanist +salinometer +piton +zygospore +means +night rider +tetraspore +archipelago +radiomicrometer +nitpicker +spot weld +slicer +girlfriend +round-tailed muskrat +cock's eggs +Shavian +bay +nuclear chemist +planetarium +hiccup nut +Marylander +milling +microsporidian +brown cup +Strophanthus kombe +little skate +emancipator +paperhanger +archaeopteryx +maigre +Mastotermes electrodominicus +procurer +seizure-alert dog +homeboy +cotton strain +mute +siren +spearnose bat +phenacomys +gayal +arsenal +pitchfork +Port Jackson heath +cud +magnetic core memory +interferometer +water jacket +account executive +hodoscope +window oyster +sudatorium +syncopator +loment +hypertensive +smoothbark +Geogia holly +nailhead +African holly +musette +chafeweed +microflora +derrick +strawworm +shogun +queen post +jerboa kangaroo +columbo +royal +sourball +solenogaster +cardsharp +Homo habilis +intaglio +calf's-foot jelly +flotsam +skirret +baronduki +chyme +shovel hat +Welsh +monoplane flying fish +groundfish +tablet-armed chair +swan dive +Indian club +colonial +cassiri +pyramidal tent +praya +silk vine +time clock +button snakeroot +clews +Korean lespedeza +diffuser +ripping bar +puttyroot +nipple shield +headpin +juneberry holly +hub-and-spoke +laver +weldment +plain flour +hoosegow +dudeen +grey skate +line of life +mung +arariba +Newtown Wonder +rock candy +side chapel +castor sugar +narrow-leaved white-topped aster +babassu nut +puka +rings +catchall +heat shield +caroche +oxbow +Australian coral snake +tapper +sporangiophore +fenugreek +spruce gall aphid +gouache +cutoff +private line +pod +cargo hatch +nailhead +penile implant +geophyte +small-leaved linden +deepwater pipefish +paperhanger +hairy spurge +Persian lamb +subtropics +feed grain +clarence +nonparticipant +scorpioid cyme +hand brake +tiller +Geglossaceae +albacore +monochrome +goa bean +bur +tongue worm +psittacosaur +frog's lettuce +pectoral +terreplein +light filter +fishpaste +dry point +grison +feterita +dolichocephalic +oenomel +stretcher +swag +cheval-de-frise +mountain beaver +scammony +discus +leatherleaf saxifrage +wharf rat +Dominique +pelycosaur +depth gauge +bishop +archespore +true anomaly +silver jenny +mercy seat +kelp +oviraptorid +acrylic +Chinese pea tree +meat house +bilge well +Temperate Zone +whale louse +balbriggan +briefcase bomb +pump-type pliers +oil +sour gourd +Jewbush +lunette +Chinese paddlefish +pyxidium +beechnut +calabar bean +grugru nut +gib +blunt file +cataphyll +megasporangium +blockbuster +sliding seat +hogchoker +calceus +Connarus guianensis +honest woman +survivor +second balcony +tempera +Calvary clover +murine +outwork +bogy +elephant's-foot +conning tower +set square +blackfly +stirk +Streptomyces erythreus +blade +goldfield +snowball +mortal enemy +waltzer +shoal +galley +hitchhiker +lithophyte +brisling +scauper +esophagoscope +grab +subtracter +philosopher +duplex apartment +southeastern pocket gopher +bonduc nut +reverberatory furnace +grader +lamp house +northern bog lemming +brotula +ornithopod +ptyalith +obturator +perpetual motion machine +range pole +Africander +curvet +daisy print wheel +floor +collector +mutant +tuck +fore-and-after +senega +buckler mustard +louvar +Tarsius glis +culdoscope +Spanish fly +steering gear +hatchet man +museum +saw set +cambric tea +comber +thermohydrometer +stationer +chalcis fly +bryanthus +whipstitch +harvest mite +rock gunnel +time bomb +rariora +pigfish +apetalous flower +head shop +horned whiff +sandpit +tachistoscope +sundries +taffrail +caller +monofocal lens implant +Dover's powder +souari nut +crowbait +render +Shakespearian +hagberry +megatherian +magus +hatchel +mangabey +garroter +piedmont +cope +barrio +psychodid +rigout +distributor +croupier's rake +sarcenet +narrow-leaved water plantain +treenail +biped +lanternfish +overdrive +barndoor skate +picket boat +amber lily +sawpit +sand lance +bucket shop +common beech +laundry truck +surtout +grogram +tampion +escape hatch +interstice +shop bell +snake mackerel +nakedwood +tumbrel +mericarp +mountain paca +cab +big board +cringle +eusporangium +shipping room +coal chute +dumbwaiter +Smiledon californicus +man-at-arms +cartridge +deinonychus +pigeon pea +screw bean +spectacle +floorboard +cutting room +low-warp-loom +proconsul +sabicu +genipap +clapper +aquifer +archaeornis +belly flop +Protium heptaphyllum +interrupter +high-warp loom +knight +wiper +impression +poker +Pithecanthropus +sable +guardroom +tenter +wellhead +raja +strickle +sodomite +mountebank +sand leek +Barbados gooseberry +shuffler +sensory fiber +crab-eating opossum +etching +rare bird +scup +fagot +negro vine +hutment +droshky +nephoscope +lady chapel +cutty stool +release +vestiture +buff +standard +Tabernacle +vascular ray +snakewood +chlorobenzylidenemalononitrile +limnologist +pouched mole +microwave linear accelerator +Mastotermes darwiniensis +wind tee +orange bat +open sight +carpospore +rampant arch +sabbatia +cursor +post exchange +bellpull +center +cyclostyle +canonist +pygmy sperm whale +moa +king +pass-through +angioscope +marrow +hookup +revetment +acanthocephalan +good Samaritan +apatosaur +web spinner +dixie +ommastrephes +crossbench +candlewick +jack +light arm +caisson +kaki +quandong nut +Meuniere butter +coquilla nut +mast +black +twitterer +bluethroat pikeblenny +shielding +water-shield +urolith +elephant bird +clearway +dark lantern +schizopetalon +press +Nazi +sugarberry +Maltese +stevedore +hair shirt +party wall +gainer +blackheart +nothosaur +cavetto +evergreen bittersweet +chemical bomb +calpac +shingle +turnpike +animator +heaver +isoclinic line +death knell +liner +anathema +aerie +razorback +Ichyostega +pound net +French dressing +mottle +yard +string tie +bell seat +brattice +battering ram +sierra +pompon +vertex +stomach pump +electrolytic cell +escolar +telpher +roadhouse +cerecloth +tartare sauce +letter case +whale sucker +hob +teg +canvas +strickle +hectograph +Cartagena bark +mail car +acinus +freedom rider +bread sauce +picture window +Rhizopogon idahoensis +pinprick +mass spectrograph +ringer +devil's cigar +salad cream +marlberry +airbrake +Clark cell +yellow-throated marten +wire gauge +dinoceras +aba +harpoon log +plate rail +mustard plaster +coelophysis +journal box +puce +ballcock +quartering +izar +clinid +whirler +turnspit +deathbed +pottle +shot +doubler +Coryphaena equisetis +English sole +chicken feed +borrow pit +mylodontid +Chilean nut +Kundt's tube +ling +asthenosphere +reseau +death seat +immovable bandage +peppermint patty +lecturer +electron multiplier +bear claw +hyacinth +beaked salmon +toehold +scull +snowball +gangsaw +fiber +oxeye +lashing +Beckman thermometer +fence +cantilever +dinner theater +Reynard +jag +umbrella plant +camera lucida +beaver +slug +yellowfin croaker +Sibley tent +rat-tail file +anchovy pear +soldier +cackler +chaise +Pitot-static tube +minniebush +Episcopalian +oleaster +ejaculator +wavy-leaved aster +knight +rack +real storage +magnetic mine +cocoa plum +vesiculovirus +birch leaf miner +water chevrotain +rudapithecus +torpedo tube +itch mite +warren +loft +washerman +terrace +nonstarter +shit +platform +caudex +ground control +Ostariophysi +slopshop +Peruvian cotton +crystal oscillator +plastic bomb +bar bit +watering cart +Asiatic sweetleaf +artificial joint +chariot +casern +charge-exchange accelerator +display adapter +hornpipe +honey bell +planula +Nephthytis afzelii +hame +ranter +trachodon +synchrocyclotron +splasher +heterotroph +Nicol prism +Himalayan rhubarb +headfast +put-put +bitter almond +parr +scantling +power breakfast +madder +Catalpa bignioides +rose of Jericho +spark chamber +rhizome +beard worm +supper club +negro peach +keratoscope +wain +apple aphid +planking +time-delay measuring instrument +sternpost +sicklepod +lake bed +gatherer +monotype +dead-man's float +poison gas +dicynodont +organism +cell +person +animal +plant +food +artifact +dressage +contact sport +outdoor sport +gymnastics +track and field +jumping +high jump +skiing +water sport +swimming +dive +floating +skin diving +rowing +boxing +sledding +tobogganing +wrestling +skating +ice skating +roller skating +racing +boat racing +riding +equestrian sport +cycling +blood sport +hunt +fishing +angling +casting +athletic game +outdoor game +golf +field game +field hockey +football +American football +ball game +baseball +court game +badminton +basketball +tennis +sport +Seder +scavenger +bottom-feeder +work animal +beast of burden +pack animal +domestic animal +marine animal +female +male +young +young mammal +pup +cub +lion cub +tiger cub +microorganism +arbovirus +herpes +herpes zoster +reovirus +moneran +cyanobacteria +enteric bacteria +actinomycete +streptomyces +diplococcus +parasite +ectoparasite +protoctist +protozoan +sarcodinian +ameba +ciliate +alga +brown algae +green algae +sporozoan +cypriniform fish +cyprinid +carp +domestic carp +shiner +catostomid +buffalo fish +cyprinodont +killifish +topminnow +squirrelfish +stickleback +pipefish +embryo +fetus +blastula +chordate +cephalochordate +tunicate +ascidian +vertebrate +aquatic vertebrate +jawless vertebrate +lamprey +hagfish +cartilaginous fish +holocephalan +chimaera +elasmobranch +shark +mackerel shark +mako +requiem shark +dogfish +smooth dogfish +spiny dogfish +smooth hammerhead +smalleye hammerhead +shovelhead +ray +sawfish +roughtail stingray +butterfly ray +eagle ray +manta +skate +bird +gamecock +night bird +ratite +passerine +oscine +accentor +lark +pipit +finch +canary +dark-eyed junco +New World sparrow +bunting +honeycreeper +sparrow +grosbeak +towhee +weaver +grassfinch +tyrannid +New World flycatcher +kingbird +pewee +cotinga +antbird +Old World flycatcher +thrush +nightingale +Old World chat +warbler +kinglet +Old World warbler +New World warbler +flycatching warbler +New World chat +yellowthroat +New World oriole +northern oriole +meadowlark +New World blackbird +grackle +Old World oriole +starling +myna +corvine bird +crow +Old World jay +common European jay +New World jay +blue jay +Canada jay +Rocky Mountain jay +nutcracker +European magpie +American magpie +Australian magpie +wren +marsh wren +thrasher +New Zealand wren +creeper +titmouse +black-capped chickadee +Carolina chickadee +swallow +martin +tanager +shrike +butcherbird +bush shrike +bowerbird +European water ouzel +American water ouzel +vireo +waxwing +bird of prey +hawk +black kite +swallow-tailed kite +white-tailed kite +harrier +falcon +peregrine +caracara +eagle +young bird +sea eagle +Aegypiidae +Old World vulture +griffon vulture +bearded vulture +Egyptian vulture +black vulture +New World vulture +buzzard +condor +Andean condor +California condor +black vulture +king vulture +owl +horned owl +scops owl +amphibian +salamander +newt +Pacific newt +ambystomid +climbing salamander +web-toed salamander +frog +true frog +true toad +spadefoot +tree toad +cricket frog +tongueless frog +reptile +anapsid +diapsid +chelonian +turtle +sea turtle +ridley +snapping turtle +musk turtle +diamondback terrapin +Western box turtle +tortoise +soft-shelled turtle +saurian +lizard +gecko +iguanid +spiny lizard +fence lizard +horned lizard +skink +teiid lizard +racerunner +plateau striped whiptail +Chihuahuan spotted whiptail +western whiptail +checkered whiptail +agamid +moloch +anguid lizard +venomous lizard +lacertid lizard +chameleon +monitor +crocodilian reptile +crocodile +alligator +caiman +armored dinosaur +ankylosaur +bone-headed dinosaur +ceratopsian +hadrosaur +saurischian +sauropod +theropod +ceratosaur +maniraptor +synapsid +pterosaur +ichthyosaur +snake +colubrid snake +smooth green snake +rough green snake +racer +blacksnake +whip-snake +rat snake +bull snake +common kingsnake +milk snake +common garter snake +ribbon snake +Western ribbon snake +common water snake +water moccasin +grass snake +viperine grass snake +sand snake +lyre snake +blind snake +indigo snake +constrictor +boa +python +elapid +coral snake +coral snake +cobra +mamba +black mamba +krait +viper +pit viper +rattlesnake +timber rattlesnake +arthropod +arachnid +false scorpion +whip-scorpion +spider +European wolf spider +acarine +hard tick +Ixodes dammini +Ixodes neotomae +Ixodes pacificus +Ixodes scapularis +sheep-tick +Ixodes persulcatus +Ixodes dentatus +Ixodes spinipalpis +wood tick +soft tick +mite +trombiculid +spider mite +house centipede +gallinaceous bird +domestic fowl +jungle fowl +chicken +cock +hen +turkey +grouse +European black grouse +Asian black grouse +blackcock +greyhen +red grouse +moorhen +greater prairie chicken +lesser prairie chicken +heath hen +guan +chachalaca +megapode +mallee fowl +phasianid +pheasant +bobwhite +northern bobwhite +Old World quail +migratory quail +peafowl +California quail +Hungarian partridge +red-legged partridge +Greek partridge +mountain quail +guinea fowl +columbiform bird +pigeon +dove +turtledove +domestic pigeon +homing pigeon +sandgrouse +parrot +cockatoo +lory +varied Lorikeet +rainbow lorikeet +parakeet +cuculiform bird +cuckoo +crow pheasant +coraciiform bird +roller +kingfisher +hoopoe +apodiform bird +swift +Archilochus colubris +thornbill +goatsucker +piciform bird +woodpecker +flicker +sapsucker +toucanet +trogon +quetzal +aquatic bird +waterfowl +anseriform bird +duck +teal +widgeon +sheldrake +goldeneye +scaup +wood duck +sea duck +scoter +merganser +gosling +gander +Chinese goose +greylag +blue goose +snow goose +brant +common brant goose +honker +barnacle goose +swan +tundra swan +screamer +crested screamer +mammal +prototherian +monotreme +marsupial +opossum +bandicoot +kangaroo +common wallaby +hare wallaby +nail-tailed wallaby +rock wallaby +pademelon +tree wallaby +rat kangaroo +phalanger +dasyurid marsupial +dasyure +placental +calf +buck +insectivore +mole +shrew mole +shrew +water shrew +tenrec +invertebrate +sponge +glass sponge +coelenterate +Chrysaora quinquecirrha +hydrozoan +siphonophore +anthozoan +actinia +coral +gorgonian +stony coral +ctenophore +worm +planarian +fluke +liver fluke +Fasciolopsis buski +schistosome +tapeworm +echinococcus +taenia +common roundworm +chicken roundworm +pinworm +eelworm +vinegar eel +trichina +hookworm +filaria +Guinea worm +annelid +oligochaete +polychaete +leech +mollusk +scaphopod +gastropod +abalone +scorpion shell +giant conch +edible snail +garden snail +brown snail +Helix hortensis +seasnail +neritid +limpet +Hermissenda crassicornis +cowrie +bivalve +clam +quahog +cockle +oyster +mussel +marine mussel +freshwater mussel +scallop +shipworm +cephalopod +octopod +decapod +squid +crustacean +malacostracan crustacean +decapod crustacean +crab +swimming crab +spider crab +lobster +true lobster +Old World crayfish +American crayfish +shrimp +prawn +krill +stomatopod +mantis shrimp +woodlouse +pill bug +sow bug +sea louse +amphipod +copepod +barnacle +wading bird +stork +ibis +common spoonbill +roseate spoonbill +heron +egret +night heron +American bittern +European bittern +least bittern +whooping crane +rail +crake +gallinule +purple gallinule +coot +great bustard +plain turkey +button quail +trumpeter +seabird +shorebird +plover +turnstone +sandpiper +yellowlegs +ruff +tattler +woodcock +snipe +greyback +red-breasted snipe +curlew +godwit +stilt +stilt +phalarope +courser +coastal diving bird +larid +gull +tern +jaeger +skua +auk +guillemot +murre +puffin +gaviiform seabird +podicipitiform seabird +grebe +pelecaniform seabird +white pelican +Old world white pelican +gannet +snakebird +sphenisciform seabird +penguin +pelagic bird +wandering albatross +black-footed albatross +petrel +shearwater +storm petrel +aquatic mammal +cetacean +whale +baleen whale +rorqual +toothed whale +beaked whale +dolphin +bottlenose dolphin +porpoise +sea cow +carnivore +pinniped mammal +seal +eared seal +fur seal +fur seal +South American sea lion +California sea lion +Australian sea lion +Steller sea lion +earless seal +walrus +canine +bitch +dog +cur +toy dog +toy spaniel +English toy spaniel +hunting dog +hound +coonhound +dachshund +foxhound +wolfhound +greyhound +terrier +bullterrier +rat terrier +Manchester terrier +fox terrier +wirehair +Welsh terrier +schnauzer +Skye terrier +sporting dog +retriever +pointer +setter +spaniel +springer spaniel +water spaniel +working dog +watchdog +shepherd dog +Belgian sheepdog +pinscher +Sennenhunde +mastiff +bulldog +guide dog +sled dog +liver-spotted dalmatian +spitz +griffon +corgi +poodle +wolf +coydog +wild dog +striped hyena +brown hyena +spotted hyena +aardwolf +fox +black fox +silver fox +blue fox +feline +cat +domestic cat +tom +blue point Siamese +wildcat +common lynx +Canada lynx +bobcat +spotted lynx +caracal +big cat +leopardess +panther +lioness +lionet +Bengal tiger +tigress +saber-toothed tiger +bear +Syrian bear +grizzly +Alaskan brown bear +cinnamon bear +viverrine +civet +Indian mongoose +ichneumon +slender-tailed meerkat +suricate +bat +fruit bat +carnivorous bat +leafnose bat +false vampire +vespertilian bat +long-eared bat +freetail +vampire bat +predator +game +game bird +fossorial mammal +tetrapod +insect +beetle +two-spotted ladybug +Mexican bean beetle +Hippodamia convergens +vedalia +bombardier beetle +calosoma +searcher +firefly +sawyer +pine sawyer +flea beetle +Colorado potato beetle +carpet beetle +clerid beetle +lamellicorn beetle +scarabaeid beetle +scarab +tumblebug +dorbeetle +June beetle +melolonthid beetle +elaterid beetle +snout beetle +boll weevil +blister beetle +bark beetle +darkling beetle +flour beetle +seed beetle +pea weevil +bean weevil +rice weevil +louse +flea +dipterous insect +gall midge +housefly +tsetse fly +blowfly +bluebottle +greenbottle +flesh fly +tachina fly +gadfly +botfly +human botfly +sheep botfly +warble fly +horsefly +bee fly +fruit fly +louse fly +horn fly +mosquito +gnat +fungus gnat +hymenopterous insect +drone +worker +honeybee +Africanized bee +black bee +Carniolan bee +Italian bee +carpenter bee +bumblebee +cuckoo-bumblebee +andrena +Nomia melanderi +leaf-cutting bee +mason bee +potter bee +wasp +vespid +paper wasp +hornet +sphecoid wasp +digger wasp +chalcid fly +sawfly +pharaoh ant +little black ant +army ant +carpenter ant +fire ant +wood ant +slave ant +Formica fusca +slave-making ant +sanguinary ant +bulldog ant +Amazon ant +termite +dry-wood termite +orthopterous insect +short-horned grasshopper +locust +migratory locust +migratory grasshopper +long-horned grasshopper +katydid +mormon cricket +sand cricket +mole cricket +European house cricket +field cricket +tree cricket +snowy tree cricket +phasmid +diapheromera +oriental cockroach +American cockroach +Australian cockroach +German cockroach +giant cockroach +praying mantis +hemipterous insect +leaf bug +mirid bug +lygus bug +lygaeid +coreid bug +heteropterous insect +water bug +water strider +assassin bug +homopterous insect +whitefly +sweet-potato whitefly +coccid insect +scale insect +soft scale +armored scale +mealybug +plant louse +aphid +greenfly +woolly aphid +adelgid +dog-day cicada +seventeen-year locust +spittle insect +plant hopper +psocopterous insect +psocid +booklouse +ephemerid +neuropteron +green lacewing +brown lacewing +odonate +trichopterous insect +caseworm +thysanuran insect +bristletail +thysanopter +thrips +earwig +lepidopterous insect +butterfly +nymphalid +fritillary +emperor butterfly +danaid +pierid +small white +large white +southern cabbage butterfly +blue +copper +American copper +hairstreak +Strymon melinus +moth +tortricid +lymantriid +geometrid +cankerworm +pyralid +tineoid +tineid +clothes moth +gelechiid +grain moth +noctuid moth +cutworm +underwing +hawkmoth +bombycid +saturniid +giant silkworm moth +silkworm +arctiid +lasiocampid +tent caterpillar +webworm +webworm moth +caterpillar +bollworm +woolly bear +larva +grub +pupa +queen +echinoderm +basket star +edible sea urchin +sand dollar +heart urchin +crinoid +trepang +lagomorph +leporid +rabbit +eastern cottontail +swamp rabbit +marsh hare +leveret +European hare +jackrabbit +white-tailed jackrabbit +blacktail jackrabbit +polar hare +snowshoe hare +pika +rodent +mouse +rat +pocket rat +field mouse +brown rat +jerboa rat +water rat +New World mouse +wood mouse +wood rat +vole +packrat +Eurasian hamster +golden hamster +gerbil +lemming +pied lemming +Old World porcupine +brush-tailed porcupine +long-tailed porcupine +New World porcupine +Canada porcupine +pocket mouse +kangaroo rat +jumping mouse +jerboa +dormouse +gopher +squirrel +tree squirrel +ground squirrel +prairie dog +American flying squirrel +groundhog +hoary marmot +yellowbelly marmot +Old World beaver +New World beaver +cavy +naked mole rat +ungulate +hyrax +odd-toed ungulate +equine +horse +foal +colt +male horse +stallion +mare +saddle horse +warhorse +pony +mustang +bronco +wild horse +pony +racehorse +racer +harness horse +workhorse +draft horse +trotting horse +ass +domestic ass +wild ass +onager +common zebra +mountain zebra +grevy's zebra +rhinoceros +tapir +even-toed ungulate +swine +piglet +porker +peccary +ruminant +bovid +bovine +ox +cattle +bull +cow +beef +Brahman +dairy cattle +Old World buffalo +Indian buffalo +carabao +Asian wild ox +American bison +wisent +sheep +lamb +domestic sheep +wild sheep +mountain sheep +goat +domestic goat +wild goat +goat antelope +antelope +Thomson's gazelle +Gazella subgutturosa +springbok +kudu +harnessed antelope +eland +waterbuck +oryx +deer +stag +red deer +mule deer +roe deer +caribou +chevrotain +camel +domestic llama +guanaco +alpaca +giraffe +musteline mammal +ermine +stoat +New World least weasel +Old World least weasel +longtail weasel +American mink +ferret +muishond +snake muishond +striped muishond +river otter +Eurasian otter +striped skunk +hooded skunk +hog-nosed skunk +spotted skunk +American badger +Eurasian badger +ferret badger +hog badger +marten +pachyderm +edentate +peba +apar +tatouay +peludo +giant armadillo +pichiciago +sloth +anteater +primate +ape +anthropoid ape +hominoid +hominid +homo +Homo erectus +Homo sapiens +australopithecine +great ape +western lowland gorilla +eastern lowland gorilla +mountain gorilla +silverback +western chimpanzee +eastern chimpanzee +central chimpanzee +pygmy chimpanzee +lesser ape +monkey +Old World monkey +talapoin +grivet +vervet +green monkey +chacma +mandrill +drill +rhesus +bonnet macaque +Barbary ape +crab-eating macaque +entellus +guereza +New World monkey +true marmoset +pygmy marmoset +tamarin +silky tamarin +pinche +lemur +tarsier +flying lemur +proboscidean +elephant +mammoth +procyonid +raccoon +fish +food fish +young fish +crossopterygian +lungfish +catfish +silurid +bullhead +channel catfish +gadoid +cod +hake +elver +common eel +tuna +moray +conger +teleost fish +clupeid fish +shad +herring +sardine +pilchard +anchovy +salmonid +salmon +Atlantic salmon +trout +brown trout +char +whitefish +smelt +tarpon +ribbonfish +toadfish +needlefish +flying fish +spiny-finned fish +percoid fish +perch +pike-perch +walleye +robalo +pike +pickerel +sunfish +crappie +freshwater bream +black bass +bass +serranid fish +grouper +hind +surfperch +cardinalfish +remora +carangid fish +jack +moonfish +pompano +scad +dolphinfish +characin +cichlid +snapper +grunt +sparid +sea bream +porgy +sciaenid fish +croaker +whiting +sea trout +mullet +goatfish +mullet +silversides +barracuda +sea chub +butterfly fish +damselfish +clown anemone fish +wrasse +blenny +pikeblenny +gunnel +goby +gempylid +scombroid +mackerel +Spanish mackerel +tuna +bonito +sailfish +billfish +marlin +tripletail +mojarra +ganoid +Pacific sturgeon +beluga +scorpaenoid +scorpaenid +scorpionfish +rockfish +lumpfish +greenling +gurnard +sea robin +plectognath +triggerfish +filefish +boxfish +spiny puffer +ocean sunfish +flatfish +righteye flounder +lefteye flounder +whiff +sole +abbey +abbey +abrader +accelerator +accessory +accommodation +acoustic device +acoustic modem +acrylic +action +actuator +adhesive bandage +adjustable wrench +aeolian harp +aerosol +after-shave +airbus +aircraft +airfield +airfoil +air gun +airplane +air pump +air-to-air missile +air-to-ground missile +alarm +alb +alcazar +Allen screw +alms dish +altimeter +Amati +ammeter +ammunition +amplifier +analog computer +analytical balance +anchor +anchor chain +aneroid barometer +angledozer +anklet +antenna +anteroom +antiaircraft +antiballistic missile +apartment +apartment building +aperture +apparatus +apparel +appliance +appliance +applicator +aquarium +arbor +arcade +arch +arc lamp +area +argyle +arm +armament +armature +armchair +armoire +armor +armored vehicle +armor plate +armrest +array +arrow +artificial heart +artillery +assembly +assembly plant +astrodome +astronomical telescope +athletic sock +atom bomb +atomic clock +atomizer +attachment +attack submarine +attire +audiocassette +audio system +audiotape +auditorium +autoclave +autoinjector +autoloader +automat +automat +automatic firearm +automatic rifle +automaton +auxiliary research submarine +awl +ax +axis +axle +axletree +baby bed +baby buggy +baby grand +back +background +backseat +badminton equipment +badminton racket +bag +bag +bag +baggage +bagpipe +bait +balance +balcony +balcony +bale +ball +ball gown +ballistic missile +ballistic pendulum +ball-peen hammer +ballroom +band +bandage +bandanna +banderilla +bar +bar +barbed wire +barge +barge pole +barn door +barograph +barrack +barrage balloon +barrel knot +barrel vault +barrier +barroom +base +base +baseball equipment +basilica +basin +basket +basketball equipment +bass +bass drum +bass horn +bastion +bat +bathhouse +battery +battle-ax +battle dress +battleship +bay rum +bay window +beading plane +beam +beam balance +bearing +beater +beating-reed instrument +bed +bed +bedclothes +bedroom +bedroom furniture +bedspread +bedspring +beehive +beer barrel +bell +bell push +bell tower +belt +belt buckle +bench +berlin +berth +besom +bevel gear +bicycle +bicycle chain +bier +billiard ball +bin +binding +bin liner +binocular microscope +bioscope +birchbark canoe +bird shot +bistro +bit +bit +black tie +blade +blade +blanket +blimp +blind +block +block plane +blouse +blower +blowtorch +bludgeon +boarding +boarding house +boardroom +boat +bobbin +body +body armor +body lotion +boiler +bolt +bolt +bomb +bomber +bongo +boom +boom +boomerang +boot +booth +booth +bore bit +Boston rocker +bota +bottle +bottle opener +bow +bow +bowed stringed instrument +bowl +bowl +bowline +bowling equipment +bowling pin +bowsprit +box +box +boxcar +boxing equipment +brace +brace +bracelet +bracket +brake +brake system +brass +brasserie +brazier +breechcloth +breeches +brewpub +brick +bricklayer's hammer +brickwork +bridal gown +bridge +briefcase +brigandine +brilliant pebble +brim +broad arrow +broadax +broad hatchet +broadsword +brush +bubble jet printer +buffer +buffet +building +building complex +bulldozer +bullet +bullhorn +bullnose +bundle +bunker +burial chamber +burner +bus +business suit +butt joint +button +buttress +butt shaft +buzz bomb +cabaret +caber +cabin +cabin +cabinet +cabinet +cabin liner +cable +cable +cafe +cafeteria +cafeteria tray +caff +cage +calculator +caliper +calorimeter +camera +camera lens +camera tripod +camp +camp +camp chair +camper +can +canal +candelabrum +candlestick +cane +cannikin +cannon +cannon +cannonball +canopy +canteen +canteen +canvas +canvas tent +cap +cap +cap +capacitor +caparison +cape +cap screw +capsule +car +car +carbine +carbon arc lamp +card index +cardioid microphone +car door +cargo liner +cargo ship +carillon +carpenter's hammer +carpenter's level +carpenter's mallet +carpenter's rule +carpet tack +carriage +carriage +carriage bolt +carrick bend +carrier +car seat +cart +cartridge +cartridge belt +cartridge holder +case +case +cashbox +casque +casserole +cassock +catch +catcher's mask +cathedra +cathedral +cathedral +catheter +cathode +cathode-ray tube +cat's-paw +cattle car +cautery +cavalry sword +cedar chest +cell +cell +cellblock +center +centrifuge +ceramic +ceramic ware +chain tongs +chair +chair of state +chalk +chamfer plane +chandlery +chapel +character printer +chassis +chasuble +chatelaine +checker +cheeseboard +chemical reactor +chessman +chest of drawers +child's room +china +chip +chip +chisel +choke +chokey +chordophone +chronoscope +chuck +church key +cigar lighter +circle +circuit +circuit board +circular plane +circular saw +cistern +civilian clothing +clamp +clamshell +clarinet +classroom +clavier +cleaning implement +cleaning pad +clean room +clinic +clip +cloak +clock +closed circuit +closed-circuit television +closet +cloth covering +clothes closet +clothes dryer +clothes hamper +clothes tree +clothing +clothing store +clout nail +clove hitch +clutch +coach +coal car +coal shovel +coat +coat closet +coating +coating +coat of paint +coaxial cable +cocked hat +coffee cup +coffee maker +coffer +coffin +coil +colander +collider +cologne +colonnade +color television +Colt +column +column +comb +comb +combination plane +combine +commissary +commodity +communication system +commutator +compact disk +compartment +compass +compass card +compound lens +compound lever +compressor +computer +computer circuit +computer network +computer screen +computer system +concentration camp +concert grand +concertina +condenser +condenser +condenser microphone +conductor +connecting rod +connection +conservatory +conservatory +contact +container +contrabassoon +control +control panel +control system +convent +converging lens +converter +convertible +conveyance +cooker +cooking utensil +cooler +cooling system +cord +cord +cordage +corner +correctional institution +corset +cosmetic +costume +costume +cotter +cotton +counter +counter +counter +counter tube +country house +coupling +court +court +coverall +covering +cowbarn +craft +cravat +crazy quilt +cream +cream pitcher +crematory +crepe +crib +cricket equipment +croquet equipment +crossbar +crossbow +crosspiece +crown jewels +cruiser +cruiser +cruise ship +crystal microphone +cudgel +cuff +cultivator +cup +cupboard +cupola +curb roof +curtain +cutout +cutter +cutting implement +cybercafe +cyclotron +cylinder +cymbal +dado plane +dagger +damper +dart +data converter +data input device +davenport +davenport +davit +dead axle +deck +deck +deck chair +deep-freeze +defensive structure +delay line +delicatessen +dental appliance +denture +depilatory +depressor +depth finder +derrick +destroyer +detector +detector +detonating fuse +detonator +developer +device +dial +dialyzer +diathermy machine +diesel locomotive +digital camera +digital computer +digital display +diner +dinghy +dining car +dining-hall +dining room +dining-room furniture +dining-room table +dinner dress +dinner pail +dinner table +diode +dip +diplomatic building +dipper +DIP switch +directional antenna +directional microphone +direction finder +disguise +dish +dish +disk +dispenser +display +display panel +distillery +ditch +ditch spade +dive bomber +doll +dolmen +domino +door +doorbell +doorlock +doornail +dormer window +dormitory +dot matrix printer +double-breasted suit +double-reed instrument +douche +dovecote +dovetail plane +downstage +drafting instrument +Dragunov +drawstring bag +dray +dredging bucket +dress +dress blues +dressing +dress uniform +drill +electric drill +drill rig +drinking fountain +drinking vessel +drip mat +drip pot +drive +drive +drogue +drogue parachute +drop-leaf table +dry battery +dry dock +dryer +dry masonry +dry wall +dugout canoe +dumdum +dumpcart +dune buggy +dungeon +duplicator +dustmop +dwelling +earphone +earthenware +easel +easy chair +edge tool +eiderdown +elastic bandage +electrical converter +electrical device +electric bell +electric frying pan +electric furnace +electric heater +electric lamp +electric motor +electric refrigerator +electro-acoustic transducer +electrode +electromagnet +electronic balance +electronic device +electronic equipment +electronic instrument +electronic voltmeter +electron microscope +electrostatic generator +electrostatic printer +elevator +embankment +embellishment +enamel +enamelware +enclosure +endoscope +engine +engine +ensemble +entrenching tool +epidiascope +equipment +eraser +escutcheon +espadrille +espresso shop +establishment +estaminet +exercise device +exhaust fan +exhibition hall +Exocet +expansion bolt +explosive device +external-combustion engine +extractor +fabric +face mask +face veil +facing +factory +fairlead +false face +fan +farm building +farm machine +fastener +fatigues +faucet +feedback circuit +fence +fencing sword +fender +ferry +fetoscope +field-sequential color television +fife +fifth wheel +fighter +figure eight +file +file server +filling +film +film +filter +filter +finery +finisher +fipple flute +fire +firearm +fire iron +fireplace +firkin +fisherman's bend +fisherman's knot +fisherman's lure +fishing boat +fishing rod +fishnet +flag +flageolet +flambeau +flannelette +flap +flashlight +flask +flatcar +flat tip screwdriver +fleet ballistic missile submarine +flight simulator +flip-flop +floating dock +floor +floor +floor cover +fly +flywheel +fob +foghorn +folder +food hamper +footbath +footbridge +foothold +foot rule +footwear +footwear +forceps +fore-and-aft sail +foremast +fore plane +fore-topmast +fork +formalwear +fortification +fortress +foundation garment +foundry +fragmentation bomb +framework +free-reed instrument +freight train +French door +friary +friction clutch +frigate +frill +frock coat +front projector +fruit machine +full-dress uniform +full metal jacket +funny wagon +fur hat +furnace +furnishing +furniture +fuse +gable +gable roof +gaff +galleon +gallery +galley +galley +gallows +galvanometer +gambling house +game +game equipment +gamp +garage +Garand rifle +garden +garden spade +garden tool +garment +gas burner +gas-discharge tube +gasket +gasoline engine +gate +gatehouse +gatepost +gathered skirt +gauge +gauze +gauze +gavel +gear +gear +gear +gearing +general-purpose bomb +generator +generator +Geneva gown +geodesic dome +girder +glass +glider +glove +glyptic art +goal +golf club +golf equipment +Gordian knot +Gothic arch +government building +government office +gown +gramophone +granary +granny knot +grapnel +grapnel +grate +graver +greasy spoon +greatcoat +great hall +greengrocery +grenade +grillroom +groined vault +Guarnerius +guidance system +guided missile +guildhall +guitar +guitar pick +gun +gun carriage +gunlock +gunsight +gun trigger +gurney +gymnastic apparatus +gym shoe +gypsy cab +habergeon +habit +hairdressing +hairpiece +hairpin +half hatchet +half hitch +hall +hall +hammer +hand +handbell +handbow +handcart +hand glass +handloom +hand lotion +hand mower +handsaw +hand shovel +hand tool +handwear +handwheel +hanger +hank +harpsichord +harrow +hash house +hat +hatch +hauberk +hawser bend +hazard +head +head +head covering +headdress +header +headgear +headlight +headsail +headscarf +health spa +heat engine +heater +heat lamp +heat-seeking missile +heavier-than-air craft +heckelphone +hedge +helicopter +helm +helmet +helmet +heraldry +high altar +high-angle gun +high gear +high table +hinge +hip boot +hitch +hoe +hogshead +hoist +holder +holding device +home appliance +homespun +hood +hood +hood +hook +Hoover +hope chest +horn +horn button +horse +horsecar +horse-drawn vehicle +horsehair wig +hosiery +hospital +hospital room +hostel +hot-air balloon +hotel +hotel room +hot tub +house +house +housing +hovel +huarache +humeral veil +hut +hutch +hydraulic brake +hydraulic system +hydroelectric turbine +hydrofoil +hydrometer +hygrometer +hypermarket +hypodermic syringe +ice machine +ice rink +ice skate +icetray +ignition switch +impact printer +implant +implement +imprint +improvised explosive device +inclined plane +indicator +induction coil +ink-jet printer +inkstand +institution +instrument +instrument of punishment +instrument of torture +interceptor +interchange +intercommunication system +intercontinental ballistic missile +interface +interior door +internal-combustion engine +ionization chamber +video iPod +iron +jack +jack +jacket +jacket +jack plane +jail +jamb +jar +jeroboam +jet +jet engine +jewelled headdress +jib +jibboom +jiggermast +joint +jointer +joist +jolly boat +jug +jumper +jumper cable +junction +junction +jury mast +kayak +keel +keg +kerchief +kettle +key +key +keyboard +keyboard instrument +khakis +kiln +kinescope +kingbolt +kirk +kit +kit +kitbag +kitchen +kitchen appliance +kitchen utensil +kite balloon +knee-high +knife +knife +knit +knob +lace +lacquer +ladder truck +lag screw +lamasery +laminate +lamination +lamp +lamp +landing gear +land mine +lantern +lapel +lathe +lattice +launcher +lead-acid battery +leather strip +Leclanche cell +leg +legging +lens +lens implant +level +lever +Levi's +lid +life buoy +life jacket +life preserver +lifting device +ligament +light +light-emitting diode +lighter-than-air craft +lighting +light microscope +linear accelerator +line printer +lingerie +lining +liquid crystal display +lister +living quarters +living room +local area network +lock +locomotive +lodge +lodging house +loft +loft +longbow +lookout +loom +loop knot +lota +lounge +loungewear +love knot +lunchroom +luxury liner +lyre +machine +machine +machine bolt +machine gun +machinery +machine screw +machine tool +magic lantern +magnet +magnetic disk +magnetic recorder +magnetic tape +magnifier +magnum +magnus hitch +mailer +mainframe +mainmast +main-topmast +main yard +makeup +mallet +mallet +mallet +mandolin +manger +man-of-war +manometer +MANPAD +mansard +mansion +marina +marker +marketplace +maser +mask +masonry +mass spectrometer +mast +mast +mat +mat +match +match +match plane +material +materiel +Matthew Walker +maul +measure +measuring instrument +measuring stick +mechanical device +mechanical system +mechanism +medical building +medical instrument +memorial +memory +memory chip +memory device +menhir +man's clothing +mercantile establishment +mercury barometer +mercury thermometer +mercury-vapor lamp +mess +metal screw +meteorological balloon +meter +meterstick +microbalance +microfilm +microscope +military hospital +military quarters +military vehicle +mill +milldam +millinery +mine +minibike +mink +minster +Minuteman +mirror +mixer +mizzenmast +module +mold +moldboard plow +monitor +monitor +morgue +mortise joint +motion-picture camera +motion-picture film +motor +motorboat +motorcycle +motor hotel +motor vehicle +mound +mount +mouse button +movie projector +moving-coil galvanometer +mug +multiplex +multiplexer +musette pipe +mushroom anchor +musical instrument +musket +musket ball +muslin +muzzle loader +narrowbody aircraft +nautilus +navigational system +naval equipment +naval gun +naval radar +naval weaponry +navigational instrument +nebuchadnezzar +neckline +neckpiece +necktie +neckwear +needle +needlework +negligee +net +net +net +net +network +network +night bell +nightwear +noisemaker +nonsmoker +non-volatile storage +nose flute +nuclear reactor +nuclear weapon +nursery +oar +oblique bandage +oboe da caccia +oboe d'amore +obstacle +office +office furniture +oil lamp +oil paint +oil tanker +olive drab +omnidirectional antenna +onion dome +open-air market +open-end wrench +opener +openside plane +ophthalmoscope +optical device +optical disk +optical instrument +optical telescope +organ pipe +outbuilding +outerwear +outfit +outrigger canoe +outside mirror +oven +overgarment +overhand knot +overhang +overhead projector +overnighter +overshoe +oxford +package +packaging +packing box +paddle +paddle steamer +page printer +paint +pallium +pan +pan +panic button +panopticon +panopticon +pantechnicon +pantry +pants suit +panzer +paper chain +paper fastener +parabolic reflector +parapet +parasail +parka +parsonage +particle detector +partition +passenger ship +passenger train +passenger van +passive matrix display +passkey +patch +patchouli +patchwork +patina +patisserie +pavis +peavey +pedal +pedestal table +pedestrian crossing +pedicab +peg +pen +penal institution +pencil +pendulum +pendulum clock +percolator +percussion instrument +perfumery +peripheral +periwig +personal computer +petticoat +Phillips screw +Phillips screwdriver +phonograph record +photographic equipment +photographic paper +photometer +physical pendulum +piano +piccolo +pick +pick +pickle barrel +piece of cloth +pile +pillow lace +pilothouse +pin +pincer +pinstripe +pipe +pipet +pipe wrench +pistol +pivot +place of business +place of worship +planetarium +planner +plant +planter +plasterboard +plastic laminate +plastic wrap +plastron +plate +platform +platform +platform rocker +plating +pleat +plethysmograph +plexor +pliers +plug +plug +pneumatic drill +pocket +pocket-handkerchief +pocketknife +pointed arch +polyester +polygraph +pomade +pontifical +pool ball +poorhouse +porcelain +porch +portable computer +portico +post +posthole digger +pot +potential divider +potpourri +pottery +pouch +poultice +powder +powder keg +power brake +power mower +power saw +power shovel +power tool +press +press +pressure dome +pressure gauge +pressure suit +printed circuit +printer +prison camp +prod +prolonge knot +prompter +prong +propeller +propeller plane +prosthesis +protective covering +protective garment +pruning saw +pruning shears +public house +public toilet +public transport +pull +pull chain +pulley +Pullman +pullover +pulse counter +pump +pump +pump house +punch +punch press +purifier +push broom +push button +pusher +puzzle +pyrometer +pyx +QWERTY keyboard +racing boat +rack +rack +radar +radiogram +radio interferometer +radio link +radiometer +radio receiver +radiotelegraph +radiotelephone +radio transmitter +raft +rail +rail fence +railing +raincoat +rake +ramp +rampart +random-access memory +rayon +razor +reaction-propulsion engine +reactor +reading lamp +reading room +read-only memory +rearview mirror +receiver +receptacle +reception room +recess +reconnaissance plane +recorder +recording +record player +recreation room +recycling bin +reed stop +reef knot +refectory table +refinery +reflecting telescope +reflector +reformatory +refracting telescope +refrigerator car +refuge +regalia +regimentals +regulator +rein +religious residence +removable disk +repair shop +repeating firearm +reproducer +rescue equipment +reservoir +reset button +residence +resistor +resonator +respirator +restraint +retort +rheostat +rib +ribbed vault +riddle +ride +riding boot +riding mower +rifle ball +rig +rink +river boat +road +roadway +robe +rocket +rocket +rod +roller +roller +in-line skate +roller blind +roller coaster +rolling hitch +Rolodex +Roman building +roof +roof +room +roost +rope +rose water +rotary engine +rotating mechanism +rotating shaft +rotisserie +rotor +round arch +router plane +row house +royal mast +rubber bullet +rug +rushlight +sable +sable coat +sack +sackbut +sacking +saddle +safe +safety belt +safety curtain +safety fuse +safety match +sail +sailboat +sailing vessel +salver +sandglass +sash +satellite +satellite television +saucepan +savings bank +saw +sawhorse +scale +scarf +school +scientific instrument +scissors +scoop +scratcher +screen +screen +screen +screw eye +scrub plane +scuffer +sculpture +sea boat +sea chest +seam +seaplane +seat +seat +second hand +secretary +security system +seeker +selector +self-propelled vehicle +semiautomatic firearm +semiautomatic pistol +semiconductor device +serger +serpent +serving cart +serving dish +set +setscrew +setscrew +sewing needle +sextant +shackle +shade +shaft +shag rug +shaker +shaper +shaping tool +sharpener +shaving cream +shaving foam +shawl +shawm +shears +sheath +shed +sheepshank +sheet bend +shelf +shell +shell +shell +shellac +shelter +shelter +shelter +shield +ship +shipboard system +shirt +shirtfront +shock absorber +shoe +shooting brake +shop +short pants +shotgun +shoulder holster +shrine +shutter +shuttle +sidewinder +sieve +sifter +sights +signaling device +signboard +silk +simulator +single bed +single-breasted suit +single-reed instrument +sitz bath +six-pack +skate +skein +skeleton +skewer +skidder +skid lid +skiff +ski pole +skirt +ski tow +skullcap +slack suit +slat +sled +sleeper +sleeping car +sleeve +sleeve +slide projector +slipknot +slipper +sloop +slop pail +slot machine +small boat +smart bomb +smoker +smooth plane +snack bar +snap-brim hat +snare drum +sniper rifle +Sno-cat +soapbox +socle +sofa +sonograph +sorter +sound recording +soup ladle +source of illumination +soutane +spacecraft +spade +spar +spatula +spear +spear +spectacles +spectrograph +spectroscope +speedometer +spider +spike +spike +spinet +spinning machine +spiral ratchet screwdriver +spiral spring +spit +spokeshave +sponge mop +spoon +sports equipment +sports implement +sportswear +spot +spring +spring balance +springboard +sprit +square +square knot +squash racket +squawk box +squeezer +squinch +stabilizer +stabilizer +stable gear +stadium +stall +stamp mill +stand +standard cell +staple +starter +state prison +station +statue +stay +steakhouse +stealth aircraft +stealth bomber +stealth fighter +steam bath +steamboat +steamer +steam iron +steam whistle +steel mill +steelyard +steeple +steering system +step +step-up transformer +stereo +stick +stick +still +stilt +Stinger +stock +stockcar +stock car +stocking +stonework +stool +stopper knot +storage battery +storage space +storeroom +stove +stove bolt +Stradavarius +straight chair +strap +strap +stringed instrument +strip +strongbox +stronghold +strongroom +structural member +structure +stylus +submachine gun +submersible +submersible +subwoofer +suction pump +suede cloth +sunbonnet +sunhat +supermarket +superstructure +supply chamber +support +support +support column +supporting structure +supporting tower +surface lift +surface-to-air missile +surgeon's knot +surgical instrument +surgical knife +surplice +surveillance system +surveying instrument +surveyor's level +swamp buggy +sweater +swimsuit +sword +synchrotron +system +tabi +table +table +table knife +tableware +tabor +tachometer +tack +tack hammer +talaria +tambour +tambourine +tampon +tank +tank car +tannoy +tape +tape deck +tape recorder +target +tavern +tea chest +teaching aid +tea gown +teashop +teaspoon +tea-strainer +tea tray +telecommunication system +telephone +telephone line +telephone receiver +telephone system +telephone wire +telescope +television antenna +television camera +television equipment +television monitor +temple +temple +tender +tennis racket +tenor drum +tenoroon +tenpenny nail +tent +tenterhook +terminal +terminal +test rocket +tetraskelion +textile machine +textile mill +theater +theodolite +thermometer +thermostat +three-piece suit +three-way switch +thumbscrew +thumbtack +tights +tile +timber +timber hitch +timbrel +time-fuse +timepiece +timer +time-switch +tire chain +tithe barn +toecap +toga +toggle switch +toilet +toilet powder +toiletry +toilet water +token +tomograph +toner +tongs +tool +toolbox +tooth +toothbrush +top +top +topgallant +topmast +topsail +torpedo +torpedo boat +touch screen +towel +toweling +tower +toy box +track +tracked vehicle +trailer +trailer +train +trammel +transdermal patch +transformer +transistor +transmission +transmitter +transporter +trap +trapeze +travel iron +treasure chest +trellis +trench +trial balloon +triclinium +troop carrier +trough +trouser +trowel +truck +trunk +try square +tube +tuck shop +tun +tunic +turbine +Turkish towel +Turk's head +turner +turntable +turtleneck +tweed +tweeter +twenty-two +two-piece +typesetting machine +typewriter +ultraviolet lamp +undercarriage +undergarment +underpants +underwear +uneven parallel bars +uniform +university +uplift +urn +urn +utensil +vacuum flask +valve +van +van +varnish +vehicle +veranda +vertical file +vessel +vessel +vest +vibrator +vibrator +videocassette +video recording +vigil light +viol +vise +vivarium +voltaic cell +voltmeter +wagon +waist pack +walking stick +wall +wall +wall unit +ward +warehouse +warship +wash +washer +washtub +watch +watchtower +water-base paint +water butt +water cart +watercolor +water-cooled reactor +water gauge +water ski +waterwheel +weapon +weaponry +weatherglass +weathervane +web +wedge +wedge +weighbridge +weight +weir +weld +well +whaler +wheel +wheelchair +wheeled vehicle +wheelwork +whetstone +whip +whisk +whispering gallery +white goods +whorehouse +wicker basket +widebody aircraft +winch +Winchester +wind instrument +window +window +window blind +window envelope +Windsor knot +wine bucket +wine cask +wineglass +wire +wire +wire matrix printer +wiring +woman's clothing +wood +woodenware +woodscrew +woodwind +woofer +workbasket +workbench +work-clothing +worktable +workwear +wrapping +wrench +writing desk +writing implement +X-ray film +X-ray machine +yacht chair +yard +yard +yardstick +yoke +zither +zoot suit +grain +light +colorlessness +chromatic color +black +gray +dark red +orange +yellow +green +blue +purple +reddish purple +pink +light brown +reddish brown +complexion +skin +epidermal cell +columnar cell +macule +specimen +milk +embryonic cell +leukocyte +neutrophil +astrocyte +exoskeleton +medium +film +press +print media +storage medium +journalism +photojournalism +newspaper +telecommunication +telephone +call +long distance +wireless +broadcasting +television +reception +chat room +portal site +wordbook +album +concept album +magazine +movie +sign +comestible +course +dainty +dish +fare +diet +dietary supplement +liquid diet +reducing diet +vegetarianism +ration +field ration +foodstuff +starches +concentrate +meal +roughage +flour +wheat flour +nutriment +commissariat +canned food +canned meat +meal +breakfast +lunch +dinner +supper +buffet +picnic +cookout +bite +entree +side dish +casserole +chicken casserole +appetizer +cocktail +hors d'oeuvre +relish +dip +soup +madrilene +broth +broth +chowder +clam chowder +stew +goulash +fish stew +fricassee +ragout +ready-mix +powdered sugar +granulated sugar +brown sugar +sweet +confiture +candy +hard candy +patty +brittle +chewing gum +candied fruit +candied citrus peel +fudge +gumdrop +mint +kiss +lozenge +taffy +dessert +dumpling +frozen dessert +mousse +mousse +whip +pudding +pudding +tipsy cake +ice +chocolate ice cream +Neapolitan ice cream +peach ice cream +strawberry ice cream +tutti-frutti +vanilla ice cream +split +pudding +custard +pastry +turnover +puff paste +phyllo +fish cake +conserve +jam +jelly +apple jelly +marmalade +gelatin +gelatin dessert +patty +stuffing +bread +breadstick +bun +cracker +dark bread +flatbread +loaf of bread +quick bread +rye bread +toast +white bread +French bread +cornbread +johnnycake +muffin +scone +onion roll +sweet roll +onion bagel +biscuit +baking-powder biscuit +soft pretzel +sandwich +hamburger +gruel +edible fruit +vegetable +crudites +legume +greens +solanaceous vegetable +root vegetable +potato +baked potato +sweet potato +snack food +corn chip +tortilla chip +cruciferous vegetable +cabbage +kale +red cabbage +savoy cabbage +squash +summer squash +yellow squash +winter squash +turban squash +gherkin +sprout +beet +pepper +sweet pepper +hot pepper +chili +jalapeno +onion +Spanish onion +salad green +lettuce +butterhead lettuce +bean +pea +green pea +common bean +fresh bean +green bean +shell bean +lima bean +soy +celery +chicory +coffee substitute +chicory escarole +corn +hominy +cress +tomato +cherry tomato +salsify +turnip +edible nut +apple +eating apple +Delicious +McIntosh +Pippin +cooking apple +berry +currant +citrus +temple orange +mandarin +bitter orange +sweet orange +Jaffa orange +navel orange +Valencia orange +lime +almond +plum +dried fruit +raisin +passion fruit +cocoa +melon +muskmelon +winter melon +cherry +sweet cherry +heart cherry +sour cherry +grape +fox grape +muscadine +slipskin grape +vinifera grape +Tokay +cherimoya +soursop +sweetsop +ilama +pond apple +olive +pear +edible seed +walnut +feed +fodder +oil cake +timothy +grain +barley +wheat +rice +mash +bird feed +petfood +salad +tossed salad +combination salad +pasta salad +fruit salad +ingredient +flavorer +condiment +herb +spice +cinnamon +pepper +garlic +mustard +sage +savory +curry +paprika +pickle +sweet pickle +vinegar +sauce +hot sauce +dressing +mayonnaise +cheese sauce +hot-fudge sauce +white sauce +spaghetti sauce +boiled egg +hard-boiled egg +Easter egg +omelet +firm omelet +souffle +dairy product +milk +milk +powdered milk +cream +butter +clarified butter +yogurt +curd +cheese +cream cheese +bleu +cheddar +Swiss cheese +spread +pate +sweetening +sugar +syrup +batter +bread dough +chicken and rice +pasta +Tetrazzini +chili dog +fondue +fondue +hash +kabob +seafood Newburg +meatball +pilaf +sausage pizza +pepperoni pizza +cheese pizza +anchovy pizza +Sicilian pizza +porridge +fish loaf +salmon loaf +scallopine +taco +beef burrito +quesadilla +tostada +beverage +concoction +mix +filling +potion +elixir +alcohol +brew +beer +lager +Weissbier +malt +ale +stout +mead +wine +white wine +sparkling wine +Burgundy +Beaujolais +Medoc +Pinot noir +Bordeaux +claret +Chianti +Cabernet +Merlot +dessert wine +Rhine wine +Rioja +Saint Emilion +zinfandel +table wine +vermouth +fortified wine +Madeira +liquor +brandy +gin +rum +whiskey +corn whiskey +Irish +Scotch +liqueur +coffee liqueur +orange liqueur +mixed drink +cocktail +highball +Bloody Mary +daiquiri +manhattan +martini +sling +sour +caffe latte +cider +sweet cider +juice +fruit juice +grape juice +orange juice +fruit drink +mulled wine +soft drink +cola +coffee +punch +champagne cup +claret cup +rickey +tea +tea +herb tea +tisane +black tea +green tea +water +drinking water +mineral water +vitamin pill +collection +suburb +residence +littoral +grassland +pasture +resort +field +air bubble +arroyo +ascent +atoll +bank +bank +bar +barrier reef +basin +beach +burrow +canyon +cave +continental glacier +crag +crater +dale +descent +draw +dune +geological formation +glacier +glen +gorge +gulch +gully +highland +hill +hillside +hole +hollow +iceberg +ice mass +ion +knoll +landfall +landfill +lather +ledge +lowland +meteorite +mountain +mull +natural depression +natural elevation +nullah +ocean floor +outcrop +plain +point +precipice +ravine +reef +ridge +ridge +rift valley +rock +sandbank +seaside +shiner +shore +slope +soapsuds +spume +tableland +tideland +volcanic crater +wadi +spiritual leader +adventurer +anomaly +benefactor +commoner +contestant +discussant +entertainer +female +finisher +inhabitant +native +juvenile +lover +male +mediator +national +peer +recipient +sensualist +traveler +unwelcome person +unskilled person +worker +wrongdoer +Black +White +Semite +white man +Mongol +Nahuatl +Caddo +Penutian +Teton +Taracahitian +Slav +Catholic +Altaic +Bornean +Canadian +Central American +Britisher +English person +Englishwoman +Ethiopian +Parisian +Greek +Italian +Japanese +Mexican +Nigerian +North American +Pakistani +South American Indian +Filipino +Polynesian +Scandinavian +South African +South American +Turki +American +New Yorker +abbess +abstainer +academic administrator +accomplice +acquaintance +acquirer +aerialist +actor +actor +addict +adjutant +admirer +adulterer +advertiser +advocate +analyst +ancestor +announcer +announcer +appointee +appreciator +appropriator +archbishop +architect +army engineer +army officer +arrival +articulator +asserter +assistant +associate +astronaut +athlete +attendant +aunt +authoritarian +authority +aviator +back +bad person +ballet dancer +bullfighter +baron +bartender +baseball coach +base runner +basketball player +believer +betrothed +bigot +big shot +biochemist +bisexual +boatman +bond servant +botanist +Boy Scout +buddy +campaigner +captain +card player +careerist +caretaker +cavalryman +celebrity +charmer +child +child +cipher +citizen +civil rights leader +cleaner +clergyman +cleric +clerk +climber +closer +clown +coach +cobbler +collaborator +college student +collegian +commanding officer +commissioned officer +commissioned military officer +commissioner +committee member +communist +compulsive +computer scientist +computer user +contractor +convict +copycat +counselor +craftsman +creditor +critic +curate +dancer +dancer +darling +date +daughter +dawdler +deacon +deaf person +debtor +deliveryman +descender +designated hitter +detective +detractor +director +disbeliever +dispatcher +distributor +doctor +domestic partner +draftsman +drinker +drinker +drug addict +drug user +drummer +drunkard +eager beaver +earner +eavesdropper +economist +editor +egotist +elder +elected official +emissary +employee +employer +endomorph +enemy +entrant +examiner +exhibitionist +fan +fancier +farmer +farmhand +fascist +father +female aristocrat +female offspring +female child +fielder +fireman +first baseman +first sergeant +flag officer +flatterer +foe +folk dancer +follower +football player +forefather +forger +founder +free agent +friar +monk +gambler +generator +geneticist +genitor +geologist +girl +godchild +godparent +golfer +grandma +grandmaster +grandparent +granter +great grandchild +great grandparent +grouch +guard +guest +guide +gymnast +Gypsy +hack +hairdresser +hater +headmaster +hearer +hedonist +heir +herder +homeless +horseman +host +host +hypocrite +important person +incumbent +infielder +informer +in-law +insurgent +investigator +investor +journalist +judge +juror +Counsel to the Crown +kinswoman +laborer +lama +landowner +lawgiver +lawman +lawyer +liberator +lieutenant +lineman +literate +litigant +Lord +failure +lowerclassman +lumberman +maid +maker +malcontent +martinet +master of ceremonies +masturbator +medical officer +medical practitioner +medical scientist +mender +meteorologist +middle-aged man +miler +military attache +military officer +military policeman +minister +minor leaguer +misfit +mixed-blood +model +moneymaker +mother +mourner +mover +musician +Muslimah +mystic +nanny +neonate +nephew +neutral +newcomer +newcomer +newspaper editor +niece +noncommissioned officer +nurse +observer +occultist +oldster +old woman +opportunist +orator +originator +outfielder +right fielder +right-handed pitcher +painter +panelist +pardoner +parodist +party +passenger +patient +patron +payer +peddler +percussionist +personal representative +personification +pervert +petitioner +Pharaoh +phonetician +physical therapist +physicist +pimp +pisser +pitcher +planner +player +poet +politician +practitioner +prayer +preserver +president +priest +princess +principal +proctor +programmer +promiser +propagandist +prosecutor +psychic +pusher +queen +queen +ranch hand +reader +recruit +recruiter +religious leader +repairman +reporter +representative +reprobate +rescuer +reservist +restrainer +retailer +retiree +revolutionist +rich person +civil authority +runner +running back +rustic +saboteur +sailor +salesman +salesperson +scalper +schemer +scholar +schoolchild +scientist +second baseman +secretary +seeker +selfish person +seller +serf +serviceman +settler +shrew +sibling +sick person +singer +sister +skeptic +skier +sleeper +slob +smith +snoop +social climber +socialist +social scientist +sociologist +soldier +son +songster +sorcerer +sovereign +speaker +specialist +spectator +stand-in +star +stepparent +stock trader +stranger +strategist +student +subordinate +suitor +superior +surgeon +sweetheart +sympathizer +tax assessor +taxonomist +teacher +television reporter +tenant +tenant +tennis player +testator +testee +theologian +therapist +thinker +thrower +toastmaster +trader +traffic cop +trainer +traitor +traveling salesman +tyrant +upstart +upstart +utility man +vacationer +vegetarian +vice president +victim +volunteer +votary +waiter +waitress +wanderer +wanton +washer +white supremacist +wife +winner +winner +woman +workman +worshiper +wright +writer +wilding +bryophyte +liverwort +pteridophyte +fern +fern ally +spore +spermatophyte +perennial +gymnosperm +ephedra +cycad +sago palm +zamia +pine +pinon +nut pine +white pine +yellow pine +larch +fir +silver fir +cedar +spruce +hemlock +douglas fir +cedar +cypress +arborvitae +araucaria +kauri pine +celery pine +yellowwood +gymnospermous yellowwood +yew +angiosperm +dicot +flower +wildflower +inflorescence +pistil +pericarp +oilseed +custard apple +barberry +allspice +laurel +anise tree +magnolia +moonseed +buttercup +aconite +baneberry +anemone +thimbleweed +columbine +clematis +delphinium +nigella +wax myrtle +zebrawood +legume +legume +darling pea +clover +acacia +wattle +albizzia +nitta tree +dogbane +allamanda +carissa +frangipani +rauwolfia +arum +alocasia +anthurium +caladium +monstera +nephthytis +arrow arum +calla lily +duckweed +watermeal +birthwort +sandwort +mouse-ear chickweed +pink +china pink +lychnis +silene +chickweed +fig marigold +amaranth +orach +saltbush +beet +sand verbena +four o'clock +echinocactus +prickly pear +pokeweed +portulaca +flame flower +caper +spiderflower +crucifer +cress +watercress +rock cress +cabbage +head cabbage +turnip plant +mustard +wallflower +woad +stock +radish plant +pennycress +poppy +prickly poppy +composite +compass plant +everlasting +achillea +ageratum +ragweed +ammobium +burdock +artemisia +mugwort +aster +wood aster +common daisy +bur marigold +calendula +thistle +carline thistle +catananche +centaury +knapweed +chrysanthemum +golden aster +goldenbush +plume thistle +woolly thistle +coreopsis +fleabane +woolly sunflower +cotton rose +gazania +African daisy +cudweed +gumweed +goldenbush +sneezeweed +sunflower +hawkweed +marsh elder +krigia +hawkbit +blazing star +rattlesnake root +daisybush +coneflower +coneflower +cutleaved coneflower +golden thistle +white-topped aster +goldenrod +sow thistle +marigold +dandelion +crownbeard +zinnia +achene +campanula +orchid +orchis +arethusa +helleborine +coral root +lady's slipper +large yellow lady's slipper +helleborine +fringed orchis +rein orchid +spider orchid +moth orchid +butterfly orchid +ladies' tresses +vanda +vanilla +yam +primrose +pimpernel +featherfoil +loosestrife +water pimpernel +gramineous plant +grass +wheatgrass +foxtail +broom grass +oat +brome +grama +reed grass +burgrass +crabgrass +lyme grass +wild rye +plume grass +rye grass +ricegrass +meadowgrass +millet +reed +sorghum +grain sorghum +cordgrass +cereal +wheat +corn +mealie +zoysia +bamboo +cotton grass +spike rush +pandanus +cattail +grain +kernel +gourd +gourd +squash +summer squash +marrow +winter squash +turban squash +bryony +sweet melon +luffa +lobelia +mallow +hollyhock +althea +poppy mallow +seashore mallow +globe mallow +tulipwood tree +sterculia +bottle-tree +screw tree +cacao +linden +herb +protea +banksia +grevillea +macadamia +casuarina +beefwood +heath +bearberry +huckleberry +kalmia +rhododendron +cranberry +blueberry +shortia +Australian heath +epacris +wintergreen +pipsissewa +beech +chestnut +tanbark oak +southern beech +New Zealand beech +oak +live oak +white oak +red oak +scrub oak +chestnut oak +birch +alder +hornbeam +hop hornbeam +hazelnut +centaury +gentian +fringed gentian +olive tree +fringe tree +ash +red ash +jasmine +privet +lilac +liquidambar +walnut +hickory +wing nut +loosestrife +myrtle +gum tree +eucalyptus +flooded gum +mallee +stringybark +tupelo +enchanter's nightshade +willowherb +fuchsia +evening primrose +daphne +canna +banana +ginger +begonia +tuberous begonia +poon +St John's wort +rockrose +dipterocarp +candlewood +reseda +viola +violet +nettle +cannabis +mulberry +fig tree +fig +elm +hackberry +iridaceous plant +bearded iris +beardless iris +crocus +amaryllis +blood lily +narcissus +daffodil +liliaceous plant +colicroot +alliaceous plant +kniphofia +poker plant +asphodel +mariposa +globe lily +camas +dogtooth violet +fritillary +tulip +star-of-Bethlehem +grape hyacinth +scilla +false asphodel +bog asphodel +hellebore +death camas +sarsaparilla +Solomon's-seal +bellwort +agave +sansevieria +cassia +locust tree +senna +angelim +milk vetch +wild indigo +pea tree +glory pea +rosewood +blackwood +tick trefoil +coral tree +vetchling +wild pea +lupine +medic +mucuna +locoweed +pole bean +pea +edible-pod pea +quira +hoary pea +bush pea +vetch +palm +sago palm +feather palm +fan palm +palmetto +areca +calamus +oil palm +raffia palm +lady palm +eriogonum +rhubarb +water plantain +waterweed +pondweed +rose +agrimonia +flowering quince +cotoneaster +avens +apple tree +wild apple +crab apple +Iowa crab +cinquefoil +plum +wild plum +bullace +apricot +cherry +wild cherry +sweet cherry +sour cherry +almond tree +almond +bird cherry +flowering cherry +chokecherry +fruit tree +bramble bush +raspberry +mountain ash +service tree +spirea +madderwort +coffee +cinchona +bedstraw +genipa +hamelia +honeysuckle +American fly honeysuckle +teasel +scabious +geranium +cranesbill +storksbill +incense tree +mahogany +silver ash +milkwort +citrus +orange +mandarin +lemon +kumquat +prickly ash +bitterwood tree +ailanthus +nasturtium +willow +osier +sallow +poplar +black poplar +cottonwood +aspen +soapberry +soapberry vine +harpullia +pachysandra +spindle tree +maple +box elder +holly +sumac +horse chestnut +persimmon +buckthorn +styrax +carnivorous plant +pitcher plant +sedum +philadelphus +saxifrage +astilbe +alumroot +miterwort +parnassia +currant +plane tree +phlox +acanthus +catalpa +anchusa +comfrey +convolvulus +bindweed +gloxinia +streptocarpus +waterleaf +nemophila +scorpionweed +giant hyssop +bugle +wood mint +calamint +coleus +dead nettle +origanum +horehound +monarda +savory +germander +thyme +blue curls +snapdragon +kitten-tails +Indian paintbrush +foxglove +toadflax +veronica +nightshade +thorn apple +matrimony vine +cupflower +petunia +salpiglossis +spurge +croton +cassava +slipper spurge +camellia +umbellifer +angelica +astrantia +caraway +fennel +parsnip +parsley +sanicle +dogwood +valerian +bristle fern +flowering fern +climbing fern +clover fern +adder's tongue +grape fern +ergot +sclerotinia +earthball +Podaxaceae +false truffle +rhizopus +slime mold +cellular slime mold +downy mildew +pythium +Sarcosomataceae +club fungus +lichen +lecanora +fungus +basidiomycete +mushroom +mushroom +mushroom +toadstool +horse mushroom +meadow mushroom +royal agaric +false deathcap +fly agaric +death cap +blushing mushroom +destroying angel +chanterelle +floccose chanterelle +pig's ears +cinnabar chanterelle +jack-o-lantern fungus +inky cap +shaggymane +milkcap +fairy-ring mushroom +oyster mushroom +olive-tree agaric +Pholiota astragalina +Pholiota aurea +Pholiota destruens +Pholiota flammans +Pholiota flavida +nameko +Pholiota squarrosa-adiposa +Pholiota squarrosa +Pholiota squarrosoides +Stropharia ambigua +Stropharia hornemannii +Stropharia rugoso-annulata +Entoloma lividum +Entoloma aprile +Chlorophyllum molybdites +lepiota +parasol mushroom +poisonous parasol +Lepiota naucina +Lepiota rhacodes +American parasol +Lepiota rubrotincta +Lepiota clypeolaria +onion stem +blewits +sandy mushroom +Tricholoma pessundatum +Tricholoma sejunctum +man-on-a-horse +Tricholoma venenata +Tricholoma pardinum +Tricholoma vaccinum +Tricholoma aurantium +Pluteus aurantiorugosus +Pluteus magnus +deer mushroom +straw mushroom +Volvariella bombycina +Clitocybe clavipes +Clitocybe dealbata +Clitocybe inornata +Clitocybe robusta +Clitocybe irina +Clitocybe subconnexa +winter mushroom +mycelium +ascomycete +Clavicipitaceae +yeast +discomycete +morel +Verpa +false morel +lorchel +helvella +Gyromitra californica +Gyromitra sphaerospora +Gyromitra esculenta +Gyromitra infula +Gyromitra gigas +gasteromycete +common stinkhorn +Phallus ravenelii +dog stinkhorn +stinky squid +puffball +Geastrum coronatum +Astreus pteridis +Astreus hygrometricus +polypore +Boletus chrysenteron +Boletus edulis +Frost's bolete +Boletus luridus +Boletus mirabilis +Boletus pallidus +Boletus pulcherrimus +Boletus pulverulentus +Boletus roxanae +Boletus subvelutipes +Boletus variipes +Boletus zelleri +Fuscoboletinus paluster +Fuscoboletinus serotinus +Leccinum fibrillosum +Suillus albivelatus +old-man-of-the-woods +Boletellus russellii +jelly fungus +rust +smut +cornsmut +flag smut fungus +waxycap +Hygrocybe acutoconica +Hygrophorus borealis +Hygrophorus caeruleus +Hygrophorus inocybiformis +Hygrophorus kauffmanii +Hygrophorus marzuolus +Hygrophorus purpurascens +Hygrophorus russula +Hygrophorus sordidus +Hygrophorus tennesseensis +Hygrophorus turundus +Neohygrophorus angelesianus +Cortinarius armillatus +Cortinarius atkinsonianus +Cortinarius corrugatus +Cortinarius gentilis +Cortinarius mutabilis +Cortinarius semisanguineus +Cortinarius subfoetidus +Cortinarius violaceus +Gymnopilus spectabilis +Gymnopilus validipes +Gymnopilus ventricosus +mold +mildew +candida +houseplant +succulent +weed +sporophyll +sporangium +poisonous plant +vine +tree +bean tree +gymnospermous tree +conifer +angiospermous tree +nut tree +spice tree +bonsai +subshrub +bramble +liana +desert plant +marsh plant +strangler +root +receptacle +scape +peduncle +flower cluster +raceme +cyme +bulbous plant +fruit +seed +bean +nut +berry +aggregate fruit +drupe +drupelet +pome +pod +husk +buckthorn +vinifera +true pepper +peperomia +bract +palmate leaf +pinnate leaf +dentate leaf +branchlet +polypody +strap fern +staghorn fern +spleenwort +chain fern +davallia +hare's-foot fern +shield fern +wood fern +lady fern +bladder fern +holly fern +woodsia +maidenhair +brittle maidenhair +lip fern +cliff brake +horsetail +club moss +spikemoss +beech fern +shoestring fungus +Armillaria caligata +Armillaria ponderosa +Armillaria zelleri +honey mushroom +milkweed +stapelia +stephanotis +orangery +figure +plane figure +solid figure +line +convex shape +concave shape +cylinder +round shape +polygon +concave polygon +amorphous shape +closed curve +simple closed curve +cone +circle +ring +loop +ellipse +triangle +spherical polygon +angular distance +groove +bulge +bow +balance +toroid +boundary +incisure +notch +wrinkle +tree +regular polyhedron +carbon +rock +soil +high explosive +culture medium +agar +paper +paving +plaster +stucco +tear gas +vitamin +fat-soluble vitamin +water-soluble vitamin +vitamin A +B-complex vitamin +vitamin E +vitamin K diff --git a/data/inet9k.map b/data/inet9k.map new file mode 100644 index 0000000..c91b3c1 --- /dev/null +++ b/data/inet9k.map @@ -0,0 +1,200 @@ +2687 +4107 +8407 +7254 +42 +6797 +127 +2268 +2442 +3704 +260 +1970 +58 +4443 +2661 +2043 +2039 +4858 +4007 +6858 +8408 +166 +2523 +3768 +4347 +6527 +2446 +5005 +3274 +3678 +4918 +709 +4072 +8428 +7223 +2251 +3802 +3848 +7271 +2677 +8267 +2849 +2518 +2738 +3746 +5105 +3430 +3503 +2249 +1841 +2032 +2358 +122 +3984 +4865 +3246 +5095 +6912 +6878 +8467 +2741 +1973 +3057 +7217 +1872 +44 +2452 +3637 +2704 +6917 +2715 +6734 +2325 +6864 +6677 +2035 +1949 +338 +2664 +5122 +1844 +784 +2223 +7188 +2719 +2670 +4830 +158 +4818 +7228 +1965 +7342 +786 +2095 +8281 +8258 +7406 +3915 +8382 +2437 +2837 +82 +6871 +1876 +7447 +8285 +5007 +2740 +3463 +5103 +3755 +4910 +6809 +3800 +118 +3396 +3092 +2709 +81 +7105 +4036 +2366 +1846 +5177 +2684 +64 +2041 +3919 +700 +3724 +1742 +39 +807 +7184 +2256 +235 +2778 +2996 +2030 +3714 +7167 +2369 +6705 +6861 +5096 +2597 +2166 +2036 +3228 +3747 +2711 +8300 +2226 +7153 +7255 +2631 +7109 +8242 +7445 +3776 +3803 +3690 +2025 +2521 +2316 +7190 +8249 +3352 +2639 +2887 +100 +4219 +3344 +5008 +7224 +3351 +2434 +2074 +2034 +8304 +5004 +6868 +5102 +2645 +4071 +2716 +2717 +7420 +3499 +3763 +5084 +2676 +2046 +5107 +5097 +3944 +4097 +7132 +3956 +7343 diff --git a/data/kite.jpg b/data/kite.jpg new file mode 100644 index 0000000..9eb325a Binary files /dev/null and b/data/kite.jpg differ diff --git a/data/labels/100_0.png b/data/labels/100_0.png new file mode 100644 index 0000000..77878ec Binary files /dev/null and b/data/labels/100_0.png differ diff --git a/data/labels/100_1.png b/data/labels/100_1.png new file mode 100644 index 0000000..86181c0 Binary files /dev/null and b/data/labels/100_1.png differ diff --git a/data/labels/100_2.png b/data/labels/100_2.png new file mode 100644 index 0000000..5d43046 Binary files /dev/null and b/data/labels/100_2.png differ diff --git a/data/labels/100_3.png b/data/labels/100_3.png new file mode 100644 index 0000000..353401f Binary files /dev/null and b/data/labels/100_3.png differ diff --git a/data/labels/100_4.png b/data/labels/100_4.png new file mode 100644 index 0000000..d22f891 Binary files /dev/null and b/data/labels/100_4.png differ diff --git a/data/labels/100_5.png b/data/labels/100_5.png new file mode 100644 index 0000000..7f65183 Binary files /dev/null and b/data/labels/100_5.png differ diff --git a/data/labels/100_6.png b/data/labels/100_6.png new file mode 100644 index 0000000..18eb173 Binary files /dev/null and b/data/labels/100_6.png differ diff --git a/data/labels/100_7.png b/data/labels/100_7.png new file mode 100644 index 0000000..b45964b Binary files /dev/null and b/data/labels/100_7.png differ diff --git a/data/labels/101_0.png b/data/labels/101_0.png new file mode 100644 index 0000000..8739bc7 Binary files /dev/null and b/data/labels/101_0.png differ diff --git a/data/labels/101_1.png b/data/labels/101_1.png new file mode 100644 index 0000000..5a39331 Binary files /dev/null and b/data/labels/101_1.png differ diff --git a/data/labels/101_2.png b/data/labels/101_2.png new file mode 100644 index 0000000..c223477 Binary files /dev/null and b/data/labels/101_2.png differ diff --git a/data/labels/101_3.png b/data/labels/101_3.png new file mode 100644 index 0000000..09f50e3 Binary files /dev/null and b/data/labels/101_3.png differ diff --git a/data/labels/101_4.png b/data/labels/101_4.png new file mode 100644 index 0000000..7d7960b Binary files /dev/null and b/data/labels/101_4.png differ diff --git a/data/labels/101_5.png b/data/labels/101_5.png new file mode 100644 index 0000000..08d8003 Binary files /dev/null and b/data/labels/101_5.png differ diff --git a/data/labels/101_6.png b/data/labels/101_6.png new file mode 100644 index 0000000..9d554db Binary files /dev/null and b/data/labels/101_6.png differ diff --git a/data/labels/101_7.png b/data/labels/101_7.png new file mode 100644 index 0000000..37855f0 Binary files /dev/null and b/data/labels/101_7.png differ diff --git a/data/labels/102_0.png b/data/labels/102_0.png new file mode 100644 index 0000000..7b8b0fb Binary files /dev/null and b/data/labels/102_0.png differ diff --git a/data/labels/102_1.png b/data/labels/102_1.png new file mode 100644 index 0000000..ade5aa5 Binary files /dev/null and b/data/labels/102_1.png differ diff --git a/data/labels/102_2.png b/data/labels/102_2.png new file mode 100644 index 0000000..2068f0b Binary files /dev/null and b/data/labels/102_2.png differ diff --git a/data/labels/102_3.png b/data/labels/102_3.png new file mode 100644 index 0000000..00e494e Binary files /dev/null and b/data/labels/102_3.png differ diff --git a/data/labels/102_4.png b/data/labels/102_4.png new file mode 100644 index 0000000..37637d3 Binary files /dev/null and b/data/labels/102_4.png differ diff --git a/data/labels/102_5.png b/data/labels/102_5.png new file mode 100644 index 0000000..a86b69b Binary files /dev/null and b/data/labels/102_5.png differ diff --git a/data/labels/102_6.png b/data/labels/102_6.png new file mode 100644 index 0000000..7d6889e Binary files /dev/null and b/data/labels/102_6.png differ diff --git a/data/labels/102_7.png b/data/labels/102_7.png new file mode 100644 index 0000000..a9a7381 Binary files /dev/null and b/data/labels/102_7.png differ diff --git a/data/labels/103_0.png b/data/labels/103_0.png new file mode 100644 index 0000000..17cc959 Binary files /dev/null and b/data/labels/103_0.png differ diff --git a/data/labels/103_1.png b/data/labels/103_1.png new file mode 100644 index 0000000..175794c Binary files /dev/null and b/data/labels/103_1.png differ diff --git a/data/labels/103_2.png b/data/labels/103_2.png new file mode 100644 index 0000000..415038d Binary files /dev/null and b/data/labels/103_2.png differ diff --git a/data/labels/103_3.png b/data/labels/103_3.png new file mode 100644 index 0000000..1101880 Binary files /dev/null and b/data/labels/103_3.png differ diff --git a/data/labels/103_4.png b/data/labels/103_4.png new file mode 100644 index 0000000..b8bf32e Binary files /dev/null and b/data/labels/103_4.png differ diff --git a/data/labels/103_5.png b/data/labels/103_5.png new file mode 100644 index 0000000..6c81a57 Binary files /dev/null and b/data/labels/103_5.png differ diff --git a/data/labels/103_6.png b/data/labels/103_6.png new file mode 100644 index 0000000..ce580c0 Binary files /dev/null and b/data/labels/103_6.png differ diff --git a/data/labels/103_7.png b/data/labels/103_7.png new file mode 100644 index 0000000..1919f01 Binary files /dev/null and b/data/labels/103_7.png differ diff --git a/data/labels/104_0.png b/data/labels/104_0.png new file mode 100644 index 0000000..4ce801b Binary files /dev/null and b/data/labels/104_0.png differ diff --git a/data/labels/104_1.png b/data/labels/104_1.png new file mode 100644 index 0000000..cdc2ba6 Binary files /dev/null and b/data/labels/104_1.png differ diff --git a/data/labels/104_2.png b/data/labels/104_2.png new file mode 100644 index 0000000..aa88c84 Binary files /dev/null and b/data/labels/104_2.png differ diff --git a/data/labels/104_3.png b/data/labels/104_3.png new file mode 100644 index 0000000..d574267 Binary files /dev/null and b/data/labels/104_3.png differ diff --git a/data/labels/104_4.png b/data/labels/104_4.png new file mode 100644 index 0000000..71f9662 Binary files /dev/null and b/data/labels/104_4.png differ diff --git a/data/labels/104_5.png b/data/labels/104_5.png new file mode 100644 index 0000000..3159b0e Binary files /dev/null and b/data/labels/104_5.png differ diff --git a/data/labels/104_6.png b/data/labels/104_6.png new file mode 100644 index 0000000..018e0e1 Binary files /dev/null and b/data/labels/104_6.png differ diff --git a/data/labels/104_7.png b/data/labels/104_7.png new file mode 100644 index 0000000..39fbe16 Binary files /dev/null and b/data/labels/104_7.png differ diff --git a/data/labels/105_0.png b/data/labels/105_0.png new file mode 100644 index 0000000..388be1a Binary files /dev/null and b/data/labels/105_0.png differ diff --git a/data/labels/105_1.png b/data/labels/105_1.png new file mode 100644 index 0000000..284a130 Binary files /dev/null and b/data/labels/105_1.png differ diff --git a/data/labels/105_2.png b/data/labels/105_2.png new file mode 100644 index 0000000..d378969 Binary files /dev/null and b/data/labels/105_2.png differ diff --git a/data/labels/105_3.png b/data/labels/105_3.png new file mode 100644 index 0000000..f9ebb66 Binary files /dev/null and b/data/labels/105_3.png differ diff --git a/data/labels/105_4.png b/data/labels/105_4.png new file mode 100644 index 0000000..afb260b Binary files /dev/null and b/data/labels/105_4.png differ diff --git a/data/labels/105_5.png b/data/labels/105_5.png new file mode 100644 index 0000000..53274dd Binary files /dev/null and b/data/labels/105_5.png differ diff --git a/data/labels/105_6.png b/data/labels/105_6.png new file mode 100644 index 0000000..6b952ea Binary files /dev/null and b/data/labels/105_6.png differ diff --git a/data/labels/105_7.png b/data/labels/105_7.png new file mode 100644 index 0000000..02b1b7d Binary files /dev/null and b/data/labels/105_7.png differ diff --git a/data/labels/106_0.png b/data/labels/106_0.png new file mode 100644 index 0000000..7075259 Binary files /dev/null and b/data/labels/106_0.png differ diff --git a/data/labels/106_1.png b/data/labels/106_1.png new file mode 100644 index 0000000..66e73ab Binary files /dev/null and b/data/labels/106_1.png differ diff --git a/data/labels/106_2.png b/data/labels/106_2.png new file mode 100644 index 0000000..aaf88c6 Binary files /dev/null and b/data/labels/106_2.png differ diff --git a/data/labels/106_3.png b/data/labels/106_3.png new file mode 100644 index 0000000..bc6b981 Binary files /dev/null and b/data/labels/106_3.png differ diff --git a/data/labels/106_4.png b/data/labels/106_4.png new file mode 100644 index 0000000..b662b7e Binary files /dev/null and b/data/labels/106_4.png differ diff --git a/data/labels/106_5.png b/data/labels/106_5.png new file mode 100644 index 0000000..43b4561 Binary files /dev/null and b/data/labels/106_5.png differ diff --git a/data/labels/106_6.png b/data/labels/106_6.png new file mode 100644 index 0000000..e667664 Binary files /dev/null and b/data/labels/106_6.png differ diff --git a/data/labels/106_7.png b/data/labels/106_7.png new file mode 100644 index 0000000..727f3f6 Binary files /dev/null and b/data/labels/106_7.png differ diff --git a/data/labels/107_0.png b/data/labels/107_0.png new file mode 100644 index 0000000..9c8d836 Binary files /dev/null and b/data/labels/107_0.png differ diff --git a/data/labels/107_1.png b/data/labels/107_1.png new file mode 100644 index 0000000..7dc3d2b Binary files /dev/null and b/data/labels/107_1.png differ diff --git a/data/labels/107_2.png b/data/labels/107_2.png new file mode 100644 index 0000000..d27cf78 Binary files /dev/null and b/data/labels/107_2.png differ diff --git a/data/labels/107_3.png b/data/labels/107_3.png new file mode 100644 index 0000000..04b6c22 Binary files /dev/null and b/data/labels/107_3.png differ diff --git a/data/labels/107_4.png b/data/labels/107_4.png new file mode 100644 index 0000000..cbc4515 Binary files /dev/null and b/data/labels/107_4.png differ diff --git a/data/labels/107_5.png b/data/labels/107_5.png new file mode 100644 index 0000000..bc9730c Binary files /dev/null and b/data/labels/107_5.png differ diff --git a/data/labels/107_6.png b/data/labels/107_6.png new file mode 100644 index 0000000..ffbe415 Binary files /dev/null and b/data/labels/107_6.png differ diff --git a/data/labels/107_7.png b/data/labels/107_7.png new file mode 100644 index 0000000..95f81a5 Binary files /dev/null and b/data/labels/107_7.png differ diff --git a/data/labels/108_0.png b/data/labels/108_0.png new file mode 100644 index 0000000..ce05b22 Binary files /dev/null and b/data/labels/108_0.png differ diff --git a/data/labels/108_1.png b/data/labels/108_1.png new file mode 100644 index 0000000..70d3895 Binary files /dev/null and b/data/labels/108_1.png differ diff --git a/data/labels/108_2.png b/data/labels/108_2.png new file mode 100644 index 0000000..7a95038 Binary files /dev/null and b/data/labels/108_2.png differ diff --git a/data/labels/108_3.png b/data/labels/108_3.png new file mode 100644 index 0000000..81637b3 Binary files /dev/null and b/data/labels/108_3.png differ diff --git a/data/labels/108_4.png b/data/labels/108_4.png new file mode 100644 index 0000000..0ea83f2 Binary files /dev/null and b/data/labels/108_4.png differ diff --git a/data/labels/108_5.png b/data/labels/108_5.png new file mode 100644 index 0000000..98d79d8 Binary files /dev/null and b/data/labels/108_5.png differ diff --git a/data/labels/108_6.png b/data/labels/108_6.png new file mode 100644 index 0000000..25303aa Binary files /dev/null and b/data/labels/108_6.png differ diff --git a/data/labels/108_7.png b/data/labels/108_7.png new file mode 100644 index 0000000..6fb03a5 Binary files /dev/null and b/data/labels/108_7.png differ diff --git a/data/labels/109_0.png b/data/labels/109_0.png new file mode 100644 index 0000000..8169faf Binary files /dev/null and b/data/labels/109_0.png differ diff --git a/data/labels/109_1.png b/data/labels/109_1.png new file mode 100644 index 0000000..16bc989 Binary files /dev/null and b/data/labels/109_1.png differ diff --git a/data/labels/109_2.png b/data/labels/109_2.png new file mode 100644 index 0000000..cf8cf63 Binary files /dev/null and b/data/labels/109_2.png differ diff --git a/data/labels/109_3.png b/data/labels/109_3.png new file mode 100644 index 0000000..5f6757b Binary files /dev/null and b/data/labels/109_3.png differ diff --git a/data/labels/109_4.png b/data/labels/109_4.png new file mode 100644 index 0000000..5d9fdab Binary files /dev/null and b/data/labels/109_4.png differ diff --git a/data/labels/109_5.png b/data/labels/109_5.png new file mode 100644 index 0000000..be6b733 Binary files /dev/null and b/data/labels/109_5.png differ diff --git a/data/labels/109_6.png b/data/labels/109_6.png new file mode 100644 index 0000000..a02a117 Binary files /dev/null and b/data/labels/109_6.png differ diff --git a/data/labels/109_7.png b/data/labels/109_7.png new file mode 100644 index 0000000..1349d93 Binary files /dev/null and b/data/labels/109_7.png differ diff --git a/data/labels/110_0.png b/data/labels/110_0.png new file mode 100644 index 0000000..49a2582 Binary files /dev/null and b/data/labels/110_0.png differ diff --git a/data/labels/110_1.png b/data/labels/110_1.png new file mode 100644 index 0000000..10630cc Binary files /dev/null and b/data/labels/110_1.png differ diff --git a/data/labels/110_2.png b/data/labels/110_2.png new file mode 100644 index 0000000..f9004da Binary files /dev/null and b/data/labels/110_2.png differ diff --git a/data/labels/110_3.png b/data/labels/110_3.png new file mode 100644 index 0000000..b0d6ae1 Binary files /dev/null and b/data/labels/110_3.png differ diff --git a/data/labels/110_4.png b/data/labels/110_4.png new file mode 100644 index 0000000..8f57528 Binary files /dev/null and b/data/labels/110_4.png differ diff --git a/data/labels/110_5.png b/data/labels/110_5.png new file mode 100644 index 0000000..b335e49 Binary files /dev/null and b/data/labels/110_5.png differ diff --git a/data/labels/110_6.png b/data/labels/110_6.png new file mode 100644 index 0000000..450fbb6 Binary files /dev/null and b/data/labels/110_6.png differ diff --git a/data/labels/110_7.png b/data/labels/110_7.png new file mode 100644 index 0000000..c7b4754 Binary files /dev/null and b/data/labels/110_7.png differ diff --git a/data/labels/111_0.png b/data/labels/111_0.png new file mode 100644 index 0000000..a0e5883 Binary files /dev/null and b/data/labels/111_0.png differ diff --git a/data/labels/111_1.png b/data/labels/111_1.png new file mode 100644 index 0000000..9c17d57 Binary files /dev/null and b/data/labels/111_1.png differ diff --git a/data/labels/111_2.png b/data/labels/111_2.png new file mode 100644 index 0000000..4771086 Binary files /dev/null and b/data/labels/111_2.png differ diff --git a/data/labels/111_3.png b/data/labels/111_3.png new file mode 100644 index 0000000..bfba021 Binary files /dev/null and b/data/labels/111_3.png differ diff --git a/data/labels/111_4.png b/data/labels/111_4.png new file mode 100644 index 0000000..7a4aeda Binary files /dev/null and b/data/labels/111_4.png differ diff --git a/data/labels/111_5.png b/data/labels/111_5.png new file mode 100644 index 0000000..180a9c5 Binary files /dev/null and b/data/labels/111_5.png differ diff --git a/data/labels/111_6.png b/data/labels/111_6.png new file mode 100644 index 0000000..e1482cd Binary files /dev/null and b/data/labels/111_6.png differ diff --git a/data/labels/111_7.png b/data/labels/111_7.png new file mode 100644 index 0000000..c9355d0 Binary files /dev/null and b/data/labels/111_7.png differ diff --git a/data/labels/112_0.png b/data/labels/112_0.png new file mode 100644 index 0000000..d732efe Binary files /dev/null and b/data/labels/112_0.png differ diff --git a/data/labels/112_1.png b/data/labels/112_1.png new file mode 100644 index 0000000..11243af Binary files /dev/null and b/data/labels/112_1.png differ diff --git a/data/labels/112_2.png b/data/labels/112_2.png new file mode 100644 index 0000000..c3c4220 Binary files /dev/null and b/data/labels/112_2.png differ diff --git a/data/labels/112_3.png b/data/labels/112_3.png new file mode 100644 index 0000000..f830185 Binary files /dev/null and b/data/labels/112_3.png differ diff --git a/data/labels/112_4.png b/data/labels/112_4.png new file mode 100644 index 0000000..a4b184a Binary files /dev/null and b/data/labels/112_4.png differ diff --git a/data/labels/112_5.png b/data/labels/112_5.png new file mode 100644 index 0000000..02f97a2 Binary files /dev/null and b/data/labels/112_5.png differ diff --git a/data/labels/112_6.png b/data/labels/112_6.png new file mode 100644 index 0000000..2001b39 Binary files /dev/null and b/data/labels/112_6.png differ diff --git a/data/labels/112_7.png b/data/labels/112_7.png new file mode 100644 index 0000000..9a14a71 Binary files /dev/null and b/data/labels/112_7.png differ diff --git a/data/labels/113_0.png b/data/labels/113_0.png new file mode 100644 index 0000000..e36c84e Binary files /dev/null and b/data/labels/113_0.png differ diff --git a/data/labels/113_1.png b/data/labels/113_1.png new file mode 100644 index 0000000..4c81c21 Binary files /dev/null and b/data/labels/113_1.png differ diff --git a/data/labels/113_2.png b/data/labels/113_2.png new file mode 100644 index 0000000..b29b8d0 Binary files /dev/null and b/data/labels/113_2.png differ diff --git a/data/labels/113_3.png b/data/labels/113_3.png new file mode 100644 index 0000000..6233584 Binary files /dev/null and b/data/labels/113_3.png differ diff --git a/data/labels/113_4.png b/data/labels/113_4.png new file mode 100644 index 0000000..d1373f9 Binary files /dev/null and b/data/labels/113_4.png differ diff --git a/data/labels/113_5.png b/data/labels/113_5.png new file mode 100644 index 0000000..ecfa110 Binary files /dev/null and b/data/labels/113_5.png differ diff --git a/data/labels/113_6.png b/data/labels/113_6.png new file mode 100644 index 0000000..c4e0d98 Binary files /dev/null and b/data/labels/113_6.png differ diff --git a/data/labels/113_7.png b/data/labels/113_7.png new file mode 100644 index 0000000..55ac8cf Binary files /dev/null and b/data/labels/113_7.png differ diff --git a/data/labels/114_0.png b/data/labels/114_0.png new file mode 100644 index 0000000..9d42671 Binary files /dev/null and b/data/labels/114_0.png differ diff --git a/data/labels/114_1.png b/data/labels/114_1.png new file mode 100644 index 0000000..277eed4 Binary files /dev/null and b/data/labels/114_1.png differ diff --git a/data/labels/114_2.png b/data/labels/114_2.png new file mode 100644 index 0000000..9c18af3 Binary files /dev/null and b/data/labels/114_2.png differ diff --git a/data/labels/114_3.png b/data/labels/114_3.png new file mode 100644 index 0000000..412f320 Binary files /dev/null and b/data/labels/114_3.png differ diff --git a/data/labels/114_4.png b/data/labels/114_4.png new file mode 100644 index 0000000..65912f0 Binary files /dev/null and b/data/labels/114_4.png differ diff --git a/data/labels/114_5.png b/data/labels/114_5.png new file mode 100644 index 0000000..fdf7bd2 Binary files /dev/null and b/data/labels/114_5.png differ diff --git a/data/labels/114_6.png b/data/labels/114_6.png new file mode 100644 index 0000000..8f6b639 Binary files /dev/null and b/data/labels/114_6.png differ diff --git a/data/labels/114_7.png b/data/labels/114_7.png new file mode 100644 index 0000000..acf9180 Binary files /dev/null and b/data/labels/114_7.png differ diff --git a/data/labels/115_0.png b/data/labels/115_0.png new file mode 100644 index 0000000..4767c45 Binary files /dev/null and b/data/labels/115_0.png differ diff --git a/data/labels/115_1.png b/data/labels/115_1.png new file mode 100644 index 0000000..79f5d39 Binary files /dev/null and b/data/labels/115_1.png differ diff --git a/data/labels/115_2.png b/data/labels/115_2.png new file mode 100644 index 0000000..963c068 Binary files /dev/null and b/data/labels/115_2.png differ diff --git a/data/labels/115_3.png b/data/labels/115_3.png new file mode 100644 index 0000000..bc0d24f Binary files /dev/null and b/data/labels/115_3.png differ diff --git a/data/labels/115_4.png b/data/labels/115_4.png new file mode 100644 index 0000000..a39b0f0 Binary files /dev/null and b/data/labels/115_4.png differ diff --git a/data/labels/115_5.png b/data/labels/115_5.png new file mode 100644 index 0000000..63e0078 Binary files /dev/null and b/data/labels/115_5.png differ diff --git a/data/labels/115_6.png b/data/labels/115_6.png new file mode 100644 index 0000000..344ef84 Binary files /dev/null and b/data/labels/115_6.png differ diff --git a/data/labels/115_7.png b/data/labels/115_7.png new file mode 100644 index 0000000..c6e743c Binary files /dev/null and b/data/labels/115_7.png differ diff --git a/data/labels/116_0.png b/data/labels/116_0.png new file mode 100644 index 0000000..bf9b263 Binary files /dev/null and b/data/labels/116_0.png differ diff --git a/data/labels/116_1.png b/data/labels/116_1.png new file mode 100644 index 0000000..2fb12a9 Binary files /dev/null and b/data/labels/116_1.png differ diff --git a/data/labels/116_2.png b/data/labels/116_2.png new file mode 100644 index 0000000..dd04491 Binary files /dev/null and b/data/labels/116_2.png differ diff --git a/data/labels/116_3.png b/data/labels/116_3.png new file mode 100644 index 0000000..0314e85 Binary files /dev/null and b/data/labels/116_3.png differ diff --git a/data/labels/116_4.png b/data/labels/116_4.png new file mode 100644 index 0000000..cf919a6 Binary files /dev/null and b/data/labels/116_4.png differ diff --git a/data/labels/116_5.png b/data/labels/116_5.png new file mode 100644 index 0000000..c9e04ed Binary files /dev/null and b/data/labels/116_5.png differ diff --git a/data/labels/116_6.png b/data/labels/116_6.png new file mode 100644 index 0000000..1d0ab79 Binary files /dev/null and b/data/labels/116_6.png differ diff --git a/data/labels/116_7.png b/data/labels/116_7.png new file mode 100644 index 0000000..1fcdaa6 Binary files /dev/null and b/data/labels/116_7.png differ diff --git a/data/labels/117_0.png b/data/labels/117_0.png new file mode 100644 index 0000000..917b4a2 Binary files /dev/null and b/data/labels/117_0.png differ diff --git a/data/labels/117_1.png b/data/labels/117_1.png new file mode 100644 index 0000000..59cae8a Binary files /dev/null and b/data/labels/117_1.png differ diff --git a/data/labels/117_2.png b/data/labels/117_2.png new file mode 100644 index 0000000..d7c7f33 Binary files /dev/null and b/data/labels/117_2.png differ diff --git a/data/labels/117_3.png b/data/labels/117_3.png new file mode 100644 index 0000000..18679c3 Binary files /dev/null and b/data/labels/117_3.png differ diff --git a/data/labels/117_4.png b/data/labels/117_4.png new file mode 100644 index 0000000..bceedf9 Binary files /dev/null and b/data/labels/117_4.png differ diff --git a/data/labels/117_5.png b/data/labels/117_5.png new file mode 100644 index 0000000..c0bddab Binary files /dev/null and b/data/labels/117_5.png differ diff --git a/data/labels/117_6.png b/data/labels/117_6.png new file mode 100644 index 0000000..731fd14 Binary files /dev/null and b/data/labels/117_6.png differ diff --git a/data/labels/117_7.png b/data/labels/117_7.png new file mode 100644 index 0000000..c04ed0b Binary files /dev/null and b/data/labels/117_7.png differ diff --git a/data/labels/118_0.png b/data/labels/118_0.png new file mode 100644 index 0000000..4b8dfc6 Binary files /dev/null and b/data/labels/118_0.png differ diff --git a/data/labels/118_1.png b/data/labels/118_1.png new file mode 100644 index 0000000..fa886ac Binary files /dev/null and b/data/labels/118_1.png differ diff --git a/data/labels/118_2.png b/data/labels/118_2.png new file mode 100644 index 0000000..958ff5e Binary files /dev/null and b/data/labels/118_2.png differ diff --git a/data/labels/118_3.png b/data/labels/118_3.png new file mode 100644 index 0000000..241b788 Binary files /dev/null and b/data/labels/118_3.png differ diff --git a/data/labels/118_4.png b/data/labels/118_4.png new file mode 100644 index 0000000..9399152 Binary files /dev/null and b/data/labels/118_4.png differ diff --git a/data/labels/118_5.png b/data/labels/118_5.png new file mode 100644 index 0000000..279c954 Binary files /dev/null and b/data/labels/118_5.png differ diff --git a/data/labels/118_6.png b/data/labels/118_6.png new file mode 100644 index 0000000..9379cb9 Binary files /dev/null and b/data/labels/118_6.png differ diff --git a/data/labels/118_7.png b/data/labels/118_7.png new file mode 100644 index 0000000..b34ca8a Binary files /dev/null and b/data/labels/118_7.png differ diff --git a/data/labels/119_0.png b/data/labels/119_0.png new file mode 100644 index 0000000..ae03b91 Binary files /dev/null and b/data/labels/119_0.png differ diff --git a/data/labels/119_1.png b/data/labels/119_1.png new file mode 100644 index 0000000..7794fb6 Binary files /dev/null and b/data/labels/119_1.png differ diff --git a/data/labels/119_2.png b/data/labels/119_2.png new file mode 100644 index 0000000..976c49b Binary files /dev/null and b/data/labels/119_2.png differ diff --git a/data/labels/119_3.png b/data/labels/119_3.png new file mode 100644 index 0000000..2e0160e Binary files /dev/null and b/data/labels/119_3.png differ diff --git a/data/labels/119_4.png b/data/labels/119_4.png new file mode 100644 index 0000000..0540927 Binary files /dev/null and b/data/labels/119_4.png differ diff --git a/data/labels/119_5.png b/data/labels/119_5.png new file mode 100644 index 0000000..4649a59 Binary files /dev/null and b/data/labels/119_5.png differ diff --git a/data/labels/119_6.png b/data/labels/119_6.png new file mode 100644 index 0000000..eb5e0fb Binary files /dev/null and b/data/labels/119_6.png differ diff --git a/data/labels/119_7.png b/data/labels/119_7.png new file mode 100644 index 0000000..5615e77 Binary files /dev/null and b/data/labels/119_7.png differ diff --git a/data/labels/120_0.png b/data/labels/120_0.png new file mode 100644 index 0000000..64fd621 Binary files /dev/null and b/data/labels/120_0.png differ diff --git a/data/labels/120_1.png b/data/labels/120_1.png new file mode 100644 index 0000000..e13ecef Binary files /dev/null and b/data/labels/120_1.png differ diff --git a/data/labels/120_2.png b/data/labels/120_2.png new file mode 100644 index 0000000..b6ae604 Binary files /dev/null and b/data/labels/120_2.png differ diff --git a/data/labels/120_3.png b/data/labels/120_3.png new file mode 100644 index 0000000..13a4c3c Binary files /dev/null and b/data/labels/120_3.png differ diff --git a/data/labels/120_4.png b/data/labels/120_4.png new file mode 100644 index 0000000..af550a8 Binary files /dev/null and b/data/labels/120_4.png differ diff --git a/data/labels/120_5.png b/data/labels/120_5.png new file mode 100644 index 0000000..38474e4 Binary files /dev/null and b/data/labels/120_5.png differ diff --git a/data/labels/120_6.png b/data/labels/120_6.png new file mode 100644 index 0000000..e356cde Binary files /dev/null and b/data/labels/120_6.png differ diff --git a/data/labels/120_7.png b/data/labels/120_7.png new file mode 100644 index 0000000..5a585b4 Binary files /dev/null and b/data/labels/120_7.png differ diff --git a/data/labels/121_0.png b/data/labels/121_0.png new file mode 100644 index 0000000..2c20381 Binary files /dev/null and b/data/labels/121_0.png differ diff --git a/data/labels/121_1.png b/data/labels/121_1.png new file mode 100644 index 0000000..820c17d Binary files /dev/null and b/data/labels/121_1.png differ diff --git a/data/labels/121_2.png b/data/labels/121_2.png new file mode 100644 index 0000000..fabda00 Binary files /dev/null and b/data/labels/121_2.png differ diff --git a/data/labels/121_3.png b/data/labels/121_3.png new file mode 100644 index 0000000..79ac0b1 Binary files /dev/null and b/data/labels/121_3.png differ diff --git a/data/labels/121_4.png b/data/labels/121_4.png new file mode 100644 index 0000000..7ded729 Binary files /dev/null and b/data/labels/121_4.png differ diff --git a/data/labels/121_5.png b/data/labels/121_5.png new file mode 100644 index 0000000..5d59b5a Binary files /dev/null and b/data/labels/121_5.png differ diff --git a/data/labels/121_6.png b/data/labels/121_6.png new file mode 100644 index 0000000..49a63f3 Binary files /dev/null and b/data/labels/121_6.png differ diff --git a/data/labels/121_7.png b/data/labels/121_7.png new file mode 100644 index 0000000..fea7b9e Binary files /dev/null and b/data/labels/121_7.png differ diff --git a/data/labels/122_0.png b/data/labels/122_0.png new file mode 100644 index 0000000..76ed270 Binary files /dev/null and b/data/labels/122_0.png differ diff --git a/data/labels/122_1.png b/data/labels/122_1.png new file mode 100644 index 0000000..57f2857 Binary files /dev/null and b/data/labels/122_1.png differ diff --git a/data/labels/122_2.png b/data/labels/122_2.png new file mode 100644 index 0000000..d9f27cd Binary files /dev/null and b/data/labels/122_2.png differ diff --git a/data/labels/122_3.png b/data/labels/122_3.png new file mode 100644 index 0000000..c065790 Binary files /dev/null and b/data/labels/122_3.png differ diff --git a/data/labels/122_4.png b/data/labels/122_4.png new file mode 100644 index 0000000..62b891e Binary files /dev/null and b/data/labels/122_4.png differ diff --git a/data/labels/122_5.png b/data/labels/122_5.png new file mode 100644 index 0000000..276222e Binary files /dev/null and b/data/labels/122_5.png differ diff --git a/data/labels/122_6.png b/data/labels/122_6.png new file mode 100644 index 0000000..0b2924e Binary files /dev/null and b/data/labels/122_6.png differ diff --git a/data/labels/122_7.png b/data/labels/122_7.png new file mode 100644 index 0000000..8708778 Binary files /dev/null and b/data/labels/122_7.png differ diff --git a/data/labels/123_0.png b/data/labels/123_0.png new file mode 100644 index 0000000..95f92aa Binary files /dev/null and b/data/labels/123_0.png differ diff --git a/data/labels/123_1.png b/data/labels/123_1.png new file mode 100644 index 0000000..e0e4fdd Binary files /dev/null and b/data/labels/123_1.png differ diff --git a/data/labels/123_2.png b/data/labels/123_2.png new file mode 100644 index 0000000..6a9c0b0 Binary files /dev/null and b/data/labels/123_2.png differ diff --git a/data/labels/123_3.png b/data/labels/123_3.png new file mode 100644 index 0000000..8783377 Binary files /dev/null and b/data/labels/123_3.png differ diff --git a/data/labels/123_4.png b/data/labels/123_4.png new file mode 100644 index 0000000..c9de4f7 Binary files /dev/null and b/data/labels/123_4.png differ diff --git a/data/labels/123_5.png b/data/labels/123_5.png new file mode 100644 index 0000000..8deaa3c Binary files /dev/null and b/data/labels/123_5.png differ diff --git a/data/labels/123_6.png b/data/labels/123_6.png new file mode 100644 index 0000000..47ca880 Binary files /dev/null and b/data/labels/123_6.png differ diff --git a/data/labels/123_7.png b/data/labels/123_7.png new file mode 100644 index 0000000..bf3a5d7 Binary files /dev/null and b/data/labels/123_7.png differ diff --git a/data/labels/124_0.png b/data/labels/124_0.png new file mode 100644 index 0000000..a54db7c Binary files /dev/null and b/data/labels/124_0.png differ diff --git a/data/labels/124_1.png b/data/labels/124_1.png new file mode 100644 index 0000000..c545361 Binary files /dev/null and b/data/labels/124_1.png differ diff --git a/data/labels/124_2.png b/data/labels/124_2.png new file mode 100644 index 0000000..c5a6a76 Binary files /dev/null and b/data/labels/124_2.png differ diff --git a/data/labels/124_3.png b/data/labels/124_3.png new file mode 100644 index 0000000..37b9e82 Binary files /dev/null and b/data/labels/124_3.png differ diff --git a/data/labels/124_4.png b/data/labels/124_4.png new file mode 100644 index 0000000..0521fe2 Binary files /dev/null and b/data/labels/124_4.png differ diff --git a/data/labels/124_5.png b/data/labels/124_5.png new file mode 100644 index 0000000..a5ad765 Binary files /dev/null and b/data/labels/124_5.png differ diff --git a/data/labels/124_6.png b/data/labels/124_6.png new file mode 100644 index 0000000..2dbf0f1 Binary files /dev/null and b/data/labels/124_6.png differ diff --git a/data/labels/124_7.png b/data/labels/124_7.png new file mode 100644 index 0000000..0730ca0 Binary files /dev/null and b/data/labels/124_7.png differ diff --git a/data/labels/125_0.png b/data/labels/125_0.png new file mode 100644 index 0000000..67e37b2 Binary files /dev/null and b/data/labels/125_0.png differ diff --git a/data/labels/125_1.png b/data/labels/125_1.png new file mode 100644 index 0000000..4dc1ea5 Binary files /dev/null and b/data/labels/125_1.png differ diff --git a/data/labels/125_2.png b/data/labels/125_2.png new file mode 100644 index 0000000..6f3babe Binary files /dev/null and b/data/labels/125_2.png differ diff --git a/data/labels/125_3.png b/data/labels/125_3.png new file mode 100644 index 0000000..4c7a26c Binary files /dev/null and b/data/labels/125_3.png differ diff --git a/data/labels/125_4.png b/data/labels/125_4.png new file mode 100644 index 0000000..149eaa9 Binary files /dev/null and b/data/labels/125_4.png differ diff --git a/data/labels/125_5.png b/data/labels/125_5.png new file mode 100644 index 0000000..8ae40f7 Binary files /dev/null and b/data/labels/125_5.png differ diff --git a/data/labels/125_6.png b/data/labels/125_6.png new file mode 100644 index 0000000..5893043 Binary files /dev/null and b/data/labels/125_6.png differ diff --git a/data/labels/125_7.png b/data/labels/125_7.png new file mode 100644 index 0000000..47bd85b Binary files /dev/null and b/data/labels/125_7.png differ diff --git a/data/labels/126_0.png b/data/labels/126_0.png new file mode 100644 index 0000000..f602708 Binary files /dev/null and b/data/labels/126_0.png differ diff --git a/data/labels/126_1.png b/data/labels/126_1.png new file mode 100644 index 0000000..cb8b76e Binary files /dev/null and b/data/labels/126_1.png differ diff --git a/data/labels/126_2.png b/data/labels/126_2.png new file mode 100644 index 0000000..ccef7a2 Binary files /dev/null and b/data/labels/126_2.png differ diff --git a/data/labels/126_3.png b/data/labels/126_3.png new file mode 100644 index 0000000..9fcf7ab Binary files /dev/null and b/data/labels/126_3.png differ diff --git a/data/labels/126_4.png b/data/labels/126_4.png new file mode 100644 index 0000000..d3f01bf Binary files /dev/null and b/data/labels/126_4.png differ diff --git a/data/labels/126_5.png b/data/labels/126_5.png new file mode 100644 index 0000000..00c57f1 Binary files /dev/null and b/data/labels/126_5.png differ diff --git a/data/labels/126_6.png b/data/labels/126_6.png new file mode 100644 index 0000000..2c2dbb1 Binary files /dev/null and b/data/labels/126_6.png differ diff --git a/data/labels/126_7.png b/data/labels/126_7.png new file mode 100644 index 0000000..55ee5a7 Binary files /dev/null and b/data/labels/126_7.png differ diff --git a/data/labels/32_0.png b/data/labels/32_0.png new file mode 100644 index 0000000..22be2de Binary files /dev/null and b/data/labels/32_0.png differ diff --git a/data/labels/32_1.png b/data/labels/32_1.png new file mode 100644 index 0000000..21abfa4 Binary files /dev/null and b/data/labels/32_1.png differ diff --git a/data/labels/32_2.png b/data/labels/32_2.png new file mode 100644 index 0000000..eae41b9 Binary files /dev/null and b/data/labels/32_2.png differ diff --git a/data/labels/32_3.png b/data/labels/32_3.png new file mode 100644 index 0000000..fcc007e Binary files /dev/null and b/data/labels/32_3.png differ diff --git a/data/labels/32_4.png b/data/labels/32_4.png new file mode 100644 index 0000000..f4c498c Binary files /dev/null and b/data/labels/32_4.png differ diff --git a/data/labels/32_5.png b/data/labels/32_5.png new file mode 100644 index 0000000..16248c9 Binary files /dev/null and b/data/labels/32_5.png differ diff --git a/data/labels/32_6.png b/data/labels/32_6.png new file mode 100644 index 0000000..1e50183 Binary files /dev/null and b/data/labels/32_6.png differ diff --git a/data/labels/32_7.png b/data/labels/32_7.png new file mode 100644 index 0000000..81bd1d5 Binary files /dev/null and b/data/labels/32_7.png differ diff --git a/data/labels/33_0.png b/data/labels/33_0.png new file mode 100644 index 0000000..d1a1141 Binary files /dev/null and b/data/labels/33_0.png differ diff --git a/data/labels/33_1.png b/data/labels/33_1.png new file mode 100644 index 0000000..a13dd33 Binary files /dev/null and b/data/labels/33_1.png differ diff --git a/data/labels/33_2.png b/data/labels/33_2.png new file mode 100644 index 0000000..57201b2 Binary files /dev/null and b/data/labels/33_2.png differ diff --git a/data/labels/33_3.png b/data/labels/33_3.png new file mode 100644 index 0000000..0210160 Binary files /dev/null and b/data/labels/33_3.png differ diff --git a/data/labels/33_4.png b/data/labels/33_4.png new file mode 100644 index 0000000..fd181d1 Binary files /dev/null and b/data/labels/33_4.png differ diff --git a/data/labels/33_5.png b/data/labels/33_5.png new file mode 100644 index 0000000..ed4387a Binary files /dev/null and b/data/labels/33_5.png differ diff --git a/data/labels/33_6.png b/data/labels/33_6.png new file mode 100644 index 0000000..1126292 Binary files /dev/null and b/data/labels/33_6.png differ diff --git a/data/labels/33_7.png b/data/labels/33_7.png new file mode 100644 index 0000000..1d67d55 Binary files /dev/null and b/data/labels/33_7.png differ diff --git a/data/labels/34_0.png b/data/labels/34_0.png new file mode 100644 index 0000000..7b24cfa Binary files /dev/null and b/data/labels/34_0.png differ diff --git a/data/labels/34_1.png b/data/labels/34_1.png new file mode 100644 index 0000000..39f7edc Binary files /dev/null and b/data/labels/34_1.png differ diff --git a/data/labels/34_2.png b/data/labels/34_2.png new file mode 100644 index 0000000..00c4e87 Binary files /dev/null and b/data/labels/34_2.png differ diff --git a/data/labels/34_3.png b/data/labels/34_3.png new file mode 100644 index 0000000..79d5176 Binary files /dev/null and b/data/labels/34_3.png differ diff --git a/data/labels/34_4.png b/data/labels/34_4.png new file mode 100644 index 0000000..d524830 Binary files /dev/null and b/data/labels/34_4.png differ diff --git a/data/labels/34_5.png b/data/labels/34_5.png new file mode 100644 index 0000000..25a7e43 Binary files /dev/null and b/data/labels/34_5.png differ diff --git a/data/labels/34_6.png b/data/labels/34_6.png new file mode 100644 index 0000000..bf3b613 Binary files /dev/null and b/data/labels/34_6.png differ diff --git a/data/labels/34_7.png b/data/labels/34_7.png new file mode 100644 index 0000000..1148f2d Binary files /dev/null and b/data/labels/34_7.png differ diff --git a/data/labels/35_0.png b/data/labels/35_0.png new file mode 100644 index 0000000..ff572a8 Binary files /dev/null and b/data/labels/35_0.png differ diff --git a/data/labels/35_1.png b/data/labels/35_1.png new file mode 100644 index 0000000..1bba494 Binary files /dev/null and b/data/labels/35_1.png differ diff --git a/data/labels/35_2.png b/data/labels/35_2.png new file mode 100644 index 0000000..b7d708e Binary files /dev/null and b/data/labels/35_2.png differ diff --git a/data/labels/35_3.png b/data/labels/35_3.png new file mode 100644 index 0000000..302cc73 Binary files /dev/null and b/data/labels/35_3.png differ diff --git a/data/labels/35_4.png b/data/labels/35_4.png new file mode 100644 index 0000000..9e11a20 Binary files /dev/null and b/data/labels/35_4.png differ diff --git a/data/labels/35_5.png b/data/labels/35_5.png new file mode 100644 index 0000000..9ab56b3 Binary files /dev/null and b/data/labels/35_5.png differ diff --git a/data/labels/35_6.png b/data/labels/35_6.png new file mode 100644 index 0000000..d75876c Binary files /dev/null and b/data/labels/35_6.png differ diff --git a/data/labels/35_7.png b/data/labels/35_7.png new file mode 100644 index 0000000..1bbdc9f Binary files /dev/null and b/data/labels/35_7.png differ diff --git a/data/labels/36_0.png b/data/labels/36_0.png new file mode 100644 index 0000000..929660a Binary files /dev/null and b/data/labels/36_0.png differ diff --git a/data/labels/36_1.png b/data/labels/36_1.png new file mode 100644 index 0000000..646e770 Binary files /dev/null and b/data/labels/36_1.png differ diff --git a/data/labels/36_2.png b/data/labels/36_2.png new file mode 100644 index 0000000..ba6603c Binary files /dev/null and b/data/labels/36_2.png differ diff --git a/data/labels/36_3.png b/data/labels/36_3.png new file mode 100644 index 0000000..56e5ba3 Binary files /dev/null and b/data/labels/36_3.png differ diff --git a/data/labels/36_4.png b/data/labels/36_4.png new file mode 100644 index 0000000..e87046c Binary files /dev/null and b/data/labels/36_4.png differ diff --git a/data/labels/36_5.png b/data/labels/36_5.png new file mode 100644 index 0000000..5a7672d Binary files /dev/null and b/data/labels/36_5.png differ diff --git a/data/labels/36_6.png b/data/labels/36_6.png new file mode 100644 index 0000000..b16b2a2 Binary files /dev/null and b/data/labels/36_6.png differ diff --git a/data/labels/36_7.png b/data/labels/36_7.png new file mode 100644 index 0000000..1f94312 Binary files /dev/null and b/data/labels/36_7.png differ diff --git a/data/labels/37_0.png b/data/labels/37_0.png new file mode 100644 index 0000000..44b7f4e Binary files /dev/null and b/data/labels/37_0.png differ diff --git a/data/labels/37_1.png b/data/labels/37_1.png new file mode 100644 index 0000000..36712dc Binary files /dev/null and b/data/labels/37_1.png differ diff --git a/data/labels/37_2.png b/data/labels/37_2.png new file mode 100644 index 0000000..759aed9 Binary files /dev/null and b/data/labels/37_2.png differ diff --git a/data/labels/37_3.png b/data/labels/37_3.png new file mode 100644 index 0000000..03253dd Binary files /dev/null and b/data/labels/37_3.png differ diff --git a/data/labels/37_4.png b/data/labels/37_4.png new file mode 100644 index 0000000..ed5e4bd Binary files /dev/null and b/data/labels/37_4.png differ diff --git a/data/labels/37_5.png b/data/labels/37_5.png new file mode 100644 index 0000000..fe20590 Binary files /dev/null and b/data/labels/37_5.png differ diff --git a/data/labels/37_6.png b/data/labels/37_6.png new file mode 100644 index 0000000..11f34eb Binary files /dev/null and b/data/labels/37_6.png differ diff --git a/data/labels/37_7.png b/data/labels/37_7.png new file mode 100644 index 0000000..dee9ba3 Binary files /dev/null and b/data/labels/37_7.png differ diff --git a/data/labels/38_0.png b/data/labels/38_0.png new file mode 100644 index 0000000..47c51e1 Binary files /dev/null and b/data/labels/38_0.png differ diff --git a/data/labels/38_1.png b/data/labels/38_1.png new file mode 100644 index 0000000..3abcc8b Binary files /dev/null and b/data/labels/38_1.png differ diff --git a/data/labels/38_2.png b/data/labels/38_2.png new file mode 100644 index 0000000..47a85e9 Binary files /dev/null and b/data/labels/38_2.png differ diff --git a/data/labels/38_3.png b/data/labels/38_3.png new file mode 100644 index 0000000..1af926e Binary files /dev/null and b/data/labels/38_3.png differ diff --git a/data/labels/38_4.png b/data/labels/38_4.png new file mode 100644 index 0000000..783342a Binary files /dev/null and b/data/labels/38_4.png differ diff --git a/data/labels/38_5.png b/data/labels/38_5.png new file mode 100644 index 0000000..20b9222 Binary files /dev/null and b/data/labels/38_5.png differ diff --git a/data/labels/38_6.png b/data/labels/38_6.png new file mode 100644 index 0000000..f68e4d9 Binary files /dev/null and b/data/labels/38_6.png differ diff --git a/data/labels/38_7.png b/data/labels/38_7.png new file mode 100644 index 0000000..c6ffc54 Binary files /dev/null and b/data/labels/38_7.png differ diff --git a/data/labels/39_0.png b/data/labels/39_0.png new file mode 100644 index 0000000..860f831 Binary files /dev/null and b/data/labels/39_0.png differ diff --git a/data/labels/39_1.png b/data/labels/39_1.png new file mode 100644 index 0000000..021b232 Binary files /dev/null and b/data/labels/39_1.png differ diff --git a/data/labels/39_2.png b/data/labels/39_2.png new file mode 100644 index 0000000..7ac7b15 Binary files /dev/null and b/data/labels/39_2.png differ diff --git a/data/labels/39_3.png b/data/labels/39_3.png new file mode 100644 index 0000000..82baf94 Binary files /dev/null and b/data/labels/39_3.png differ diff --git a/data/labels/39_4.png b/data/labels/39_4.png new file mode 100644 index 0000000..4fb4186 Binary files /dev/null and b/data/labels/39_4.png differ diff --git a/data/labels/39_5.png b/data/labels/39_5.png new file mode 100644 index 0000000..1c613c5 Binary files /dev/null and b/data/labels/39_5.png differ diff --git a/data/labels/39_6.png b/data/labels/39_6.png new file mode 100644 index 0000000..e570bcd Binary files /dev/null and b/data/labels/39_6.png differ diff --git a/data/labels/39_7.png b/data/labels/39_7.png new file mode 100644 index 0000000..5cb309f Binary files /dev/null and b/data/labels/39_7.png differ diff --git a/data/labels/40_0.png b/data/labels/40_0.png new file mode 100644 index 0000000..346c633 Binary files /dev/null and b/data/labels/40_0.png differ diff --git a/data/labels/40_1.png b/data/labels/40_1.png new file mode 100644 index 0000000..7dfa7b5 Binary files /dev/null and b/data/labels/40_1.png differ diff --git a/data/labels/40_2.png b/data/labels/40_2.png new file mode 100644 index 0000000..a2b0e0f Binary files /dev/null and b/data/labels/40_2.png differ diff --git a/data/labels/40_3.png b/data/labels/40_3.png new file mode 100644 index 0000000..f727425 Binary files /dev/null and b/data/labels/40_3.png differ diff --git a/data/labels/40_4.png b/data/labels/40_4.png new file mode 100644 index 0000000..4c89b55 Binary files /dev/null and b/data/labels/40_4.png differ diff --git a/data/labels/40_5.png b/data/labels/40_5.png new file mode 100644 index 0000000..35b4fcd Binary files /dev/null and b/data/labels/40_5.png differ diff --git a/data/labels/40_6.png b/data/labels/40_6.png new file mode 100644 index 0000000..215972b Binary files /dev/null and b/data/labels/40_6.png differ diff --git a/data/labels/40_7.png b/data/labels/40_7.png new file mode 100644 index 0000000..0d8eb55 Binary files /dev/null and b/data/labels/40_7.png differ diff --git a/data/labels/41_0.png b/data/labels/41_0.png new file mode 100644 index 0000000..42dd387 Binary files /dev/null and b/data/labels/41_0.png differ diff --git a/data/labels/41_1.png b/data/labels/41_1.png new file mode 100644 index 0000000..0e1da96 Binary files /dev/null and b/data/labels/41_1.png differ diff --git a/data/labels/41_2.png b/data/labels/41_2.png new file mode 100644 index 0000000..31cf47d Binary files /dev/null and b/data/labels/41_2.png differ diff --git a/data/labels/41_3.png b/data/labels/41_3.png new file mode 100644 index 0000000..e512186 Binary files /dev/null and b/data/labels/41_3.png differ diff --git a/data/labels/41_4.png b/data/labels/41_4.png new file mode 100644 index 0000000..150cb57 Binary files /dev/null and b/data/labels/41_4.png differ diff --git a/data/labels/41_5.png b/data/labels/41_5.png new file mode 100644 index 0000000..7ac1a18 Binary files /dev/null and b/data/labels/41_5.png differ diff --git a/data/labels/41_6.png b/data/labels/41_6.png new file mode 100644 index 0000000..4bdd2f0 Binary files /dev/null and b/data/labels/41_6.png differ diff --git a/data/labels/41_7.png b/data/labels/41_7.png new file mode 100644 index 0000000..50568ba Binary files /dev/null and b/data/labels/41_7.png differ diff --git a/data/labels/42_0.png b/data/labels/42_0.png new file mode 100644 index 0000000..f41cd84 Binary files /dev/null and b/data/labels/42_0.png differ diff --git a/data/labels/42_1.png b/data/labels/42_1.png new file mode 100644 index 0000000..4aee8e6 Binary files /dev/null and b/data/labels/42_1.png differ diff --git a/data/labels/42_2.png b/data/labels/42_2.png new file mode 100644 index 0000000..e045f1d Binary files /dev/null and b/data/labels/42_2.png differ diff --git a/data/labels/42_3.png b/data/labels/42_3.png new file mode 100644 index 0000000..edc194b Binary files /dev/null and b/data/labels/42_3.png differ diff --git a/data/labels/42_4.png b/data/labels/42_4.png new file mode 100644 index 0000000..e417c3e Binary files /dev/null and b/data/labels/42_4.png differ diff --git a/data/labels/42_5.png b/data/labels/42_5.png new file mode 100644 index 0000000..d6593c6 Binary files /dev/null and b/data/labels/42_5.png differ diff --git a/data/labels/42_6.png b/data/labels/42_6.png new file mode 100644 index 0000000..ffcaaed Binary files /dev/null and b/data/labels/42_6.png differ diff --git a/data/labels/42_7.png b/data/labels/42_7.png new file mode 100644 index 0000000..4895af7 Binary files /dev/null and b/data/labels/42_7.png differ diff --git a/data/labels/43_0.png b/data/labels/43_0.png new file mode 100644 index 0000000..af5295e Binary files /dev/null and b/data/labels/43_0.png differ diff --git a/data/labels/43_1.png b/data/labels/43_1.png new file mode 100644 index 0000000..0e20f34 Binary files /dev/null and b/data/labels/43_1.png differ diff --git a/data/labels/43_2.png b/data/labels/43_2.png new file mode 100644 index 0000000..be2fbb3 Binary files /dev/null and b/data/labels/43_2.png differ diff --git a/data/labels/43_3.png b/data/labels/43_3.png new file mode 100644 index 0000000..5183eb1 Binary files /dev/null and b/data/labels/43_3.png differ diff --git a/data/labels/43_4.png b/data/labels/43_4.png new file mode 100644 index 0000000..526b500 Binary files /dev/null and b/data/labels/43_4.png differ diff --git a/data/labels/43_5.png b/data/labels/43_5.png new file mode 100644 index 0000000..03d62ff Binary files /dev/null and b/data/labels/43_5.png differ diff --git a/data/labels/43_6.png b/data/labels/43_6.png new file mode 100644 index 0000000..b245a4c Binary files /dev/null and b/data/labels/43_6.png differ diff --git a/data/labels/43_7.png b/data/labels/43_7.png new file mode 100644 index 0000000..e21688a Binary files /dev/null and b/data/labels/43_7.png differ diff --git a/data/labels/44_0.png b/data/labels/44_0.png new file mode 100644 index 0000000..63e66ff Binary files /dev/null and b/data/labels/44_0.png differ diff --git a/data/labels/44_1.png b/data/labels/44_1.png new file mode 100644 index 0000000..49f2fe2 Binary files /dev/null and b/data/labels/44_1.png differ diff --git a/data/labels/44_2.png b/data/labels/44_2.png new file mode 100644 index 0000000..32fd2de Binary files /dev/null and b/data/labels/44_2.png differ diff --git a/data/labels/44_3.png b/data/labels/44_3.png new file mode 100644 index 0000000..bb1118f Binary files /dev/null and b/data/labels/44_3.png differ diff --git a/data/labels/44_4.png b/data/labels/44_4.png new file mode 100644 index 0000000..cd80bbd Binary files /dev/null and b/data/labels/44_4.png differ diff --git a/data/labels/44_5.png b/data/labels/44_5.png new file mode 100644 index 0000000..f83e115 Binary files /dev/null and b/data/labels/44_5.png differ diff --git a/data/labels/44_6.png b/data/labels/44_6.png new file mode 100644 index 0000000..1f8ad89 Binary files /dev/null and b/data/labels/44_6.png differ diff --git a/data/labels/44_7.png b/data/labels/44_7.png new file mode 100644 index 0000000..8c5d632 Binary files /dev/null and b/data/labels/44_7.png differ diff --git a/data/labels/45_0.png b/data/labels/45_0.png new file mode 100644 index 0000000..701bdc8 Binary files /dev/null and b/data/labels/45_0.png differ diff --git a/data/labels/45_1.png b/data/labels/45_1.png new file mode 100644 index 0000000..976103f Binary files /dev/null and b/data/labels/45_1.png differ diff --git a/data/labels/45_2.png b/data/labels/45_2.png new file mode 100644 index 0000000..4bc50cf Binary files /dev/null and b/data/labels/45_2.png differ diff --git a/data/labels/45_3.png b/data/labels/45_3.png new file mode 100644 index 0000000..335c2c7 Binary files /dev/null and b/data/labels/45_3.png differ diff --git a/data/labels/45_4.png b/data/labels/45_4.png new file mode 100644 index 0000000..8fc2738 Binary files /dev/null and b/data/labels/45_4.png differ diff --git a/data/labels/45_5.png b/data/labels/45_5.png new file mode 100644 index 0000000..acc4c09 Binary files /dev/null and b/data/labels/45_5.png differ diff --git a/data/labels/45_6.png b/data/labels/45_6.png new file mode 100644 index 0000000..0077104 Binary files /dev/null and b/data/labels/45_6.png differ diff --git a/data/labels/45_7.png b/data/labels/45_7.png new file mode 100644 index 0000000..d486ccd Binary files /dev/null and b/data/labels/45_7.png differ diff --git a/data/labels/46_0.png b/data/labels/46_0.png new file mode 100644 index 0000000..44fa798 Binary files /dev/null and b/data/labels/46_0.png differ diff --git a/data/labels/46_1.png b/data/labels/46_1.png new file mode 100644 index 0000000..0f35bbb Binary files /dev/null and b/data/labels/46_1.png differ diff --git a/data/labels/46_2.png b/data/labels/46_2.png new file mode 100644 index 0000000..e3355f5 Binary files /dev/null and b/data/labels/46_2.png differ diff --git a/data/labels/46_3.png b/data/labels/46_3.png new file mode 100644 index 0000000..9226458 Binary files /dev/null and b/data/labels/46_3.png differ diff --git a/data/labels/46_4.png b/data/labels/46_4.png new file mode 100644 index 0000000..77a841c Binary files /dev/null and b/data/labels/46_4.png differ diff --git a/data/labels/46_5.png b/data/labels/46_5.png new file mode 100644 index 0000000..e86cbaf Binary files /dev/null and b/data/labels/46_5.png differ diff --git a/data/labels/46_6.png b/data/labels/46_6.png new file mode 100644 index 0000000..5011ded Binary files /dev/null and b/data/labels/46_6.png differ diff --git a/data/labels/46_7.png b/data/labels/46_7.png new file mode 100644 index 0000000..53c8871 Binary files /dev/null and b/data/labels/46_7.png differ diff --git a/data/labels/47_0.png b/data/labels/47_0.png new file mode 100644 index 0000000..9b7c050 Binary files /dev/null and b/data/labels/47_0.png differ diff --git a/data/labels/47_1.png b/data/labels/47_1.png new file mode 100644 index 0000000..75ba112 Binary files /dev/null and b/data/labels/47_1.png differ diff --git a/data/labels/47_2.png b/data/labels/47_2.png new file mode 100644 index 0000000..2f07656 Binary files /dev/null and b/data/labels/47_2.png differ diff --git a/data/labels/47_3.png b/data/labels/47_3.png new file mode 100644 index 0000000..3fd0728 Binary files /dev/null and b/data/labels/47_3.png differ diff --git a/data/labels/47_4.png b/data/labels/47_4.png new file mode 100644 index 0000000..9e503eb Binary files /dev/null and b/data/labels/47_4.png differ diff --git a/data/labels/47_5.png b/data/labels/47_5.png new file mode 100644 index 0000000..fddef15 Binary files /dev/null and b/data/labels/47_5.png differ diff --git a/data/labels/47_6.png b/data/labels/47_6.png new file mode 100644 index 0000000..0117b55 Binary files /dev/null and b/data/labels/47_6.png differ diff --git a/data/labels/47_7.png b/data/labels/47_7.png new file mode 100644 index 0000000..fff1323 Binary files /dev/null and b/data/labels/47_7.png differ diff --git a/data/labels/48_0.png b/data/labels/48_0.png new file mode 100644 index 0000000..4775310 Binary files /dev/null and b/data/labels/48_0.png differ diff --git a/data/labels/48_1.png b/data/labels/48_1.png new file mode 100644 index 0000000..231cd3f Binary files /dev/null and b/data/labels/48_1.png differ diff --git a/data/labels/48_2.png b/data/labels/48_2.png new file mode 100644 index 0000000..b653e9c Binary files /dev/null and b/data/labels/48_2.png differ diff --git a/data/labels/48_3.png b/data/labels/48_3.png new file mode 100644 index 0000000..d148a75 Binary files /dev/null and b/data/labels/48_3.png differ diff --git a/data/labels/48_4.png b/data/labels/48_4.png new file mode 100644 index 0000000..9e1b0d5 Binary files /dev/null and b/data/labels/48_4.png differ diff --git a/data/labels/48_5.png b/data/labels/48_5.png new file mode 100644 index 0000000..f554133 Binary files /dev/null and b/data/labels/48_5.png differ diff --git a/data/labels/48_6.png b/data/labels/48_6.png new file mode 100644 index 0000000..d841928 Binary files /dev/null and b/data/labels/48_6.png differ diff --git a/data/labels/48_7.png b/data/labels/48_7.png new file mode 100644 index 0000000..145ed36 Binary files /dev/null and b/data/labels/48_7.png differ diff --git a/data/labels/49_0.png b/data/labels/49_0.png new file mode 100644 index 0000000..f979710 Binary files /dev/null and b/data/labels/49_0.png differ diff --git a/data/labels/49_1.png b/data/labels/49_1.png new file mode 100644 index 0000000..0cb26d4 Binary files /dev/null and b/data/labels/49_1.png differ diff --git a/data/labels/49_2.png b/data/labels/49_2.png new file mode 100644 index 0000000..0684a71 Binary files /dev/null and b/data/labels/49_2.png differ diff --git a/data/labels/49_3.png b/data/labels/49_3.png new file mode 100644 index 0000000..ce89eb7 Binary files /dev/null and b/data/labels/49_3.png differ diff --git a/data/labels/49_4.png b/data/labels/49_4.png new file mode 100644 index 0000000..a8f6b14 Binary files /dev/null and b/data/labels/49_4.png differ diff --git a/data/labels/49_5.png b/data/labels/49_5.png new file mode 100644 index 0000000..c7e8033 Binary files /dev/null and b/data/labels/49_5.png differ diff --git a/data/labels/49_6.png b/data/labels/49_6.png new file mode 100644 index 0000000..a091704 Binary files /dev/null and b/data/labels/49_6.png differ diff --git a/data/labels/49_7.png b/data/labels/49_7.png new file mode 100644 index 0000000..f385b75 Binary files /dev/null and b/data/labels/49_7.png differ diff --git a/data/labels/50_0.png b/data/labels/50_0.png new file mode 100644 index 0000000..6af169d Binary files /dev/null and b/data/labels/50_0.png differ diff --git a/data/labels/50_1.png b/data/labels/50_1.png new file mode 100644 index 0000000..a3c0300 Binary files /dev/null and b/data/labels/50_1.png differ diff --git a/data/labels/50_2.png b/data/labels/50_2.png new file mode 100644 index 0000000..1ea6ff6 Binary files /dev/null and b/data/labels/50_2.png differ diff --git a/data/labels/50_3.png b/data/labels/50_3.png new file mode 100644 index 0000000..3c0bf1d Binary files /dev/null and b/data/labels/50_3.png differ diff --git a/data/labels/50_4.png b/data/labels/50_4.png new file mode 100644 index 0000000..eb6a9d9 Binary files /dev/null and b/data/labels/50_4.png differ diff --git a/data/labels/50_5.png b/data/labels/50_5.png new file mode 100644 index 0000000..acdb5ed Binary files /dev/null and b/data/labels/50_5.png differ diff --git a/data/labels/50_6.png b/data/labels/50_6.png new file mode 100644 index 0000000..c74ac5a Binary files /dev/null and b/data/labels/50_6.png differ diff --git a/data/labels/50_7.png b/data/labels/50_7.png new file mode 100644 index 0000000..6d3f530 Binary files /dev/null and b/data/labels/50_7.png differ diff --git a/data/labels/51_0.png b/data/labels/51_0.png new file mode 100644 index 0000000..48bad97 Binary files /dev/null and b/data/labels/51_0.png differ diff --git a/data/labels/51_1.png b/data/labels/51_1.png new file mode 100644 index 0000000..7703a74 Binary files /dev/null and b/data/labels/51_1.png differ diff --git a/data/labels/51_2.png b/data/labels/51_2.png new file mode 100644 index 0000000..804e21b Binary files /dev/null and b/data/labels/51_2.png differ diff --git a/data/labels/51_3.png b/data/labels/51_3.png new file mode 100644 index 0000000..5b08757 Binary files /dev/null and b/data/labels/51_3.png differ diff --git a/data/labels/51_4.png b/data/labels/51_4.png new file mode 100644 index 0000000..30727fb Binary files /dev/null and b/data/labels/51_4.png differ diff --git a/data/labels/51_5.png b/data/labels/51_5.png new file mode 100644 index 0000000..de240ea Binary files /dev/null and b/data/labels/51_5.png differ diff --git a/data/labels/51_6.png b/data/labels/51_6.png new file mode 100644 index 0000000..c252b01 Binary files /dev/null and b/data/labels/51_6.png differ diff --git a/data/labels/51_7.png b/data/labels/51_7.png new file mode 100644 index 0000000..806f99b Binary files /dev/null and b/data/labels/51_7.png differ diff --git a/data/labels/52_0.png b/data/labels/52_0.png new file mode 100644 index 0000000..a554b31 Binary files /dev/null and b/data/labels/52_0.png differ diff --git a/data/labels/52_1.png b/data/labels/52_1.png new file mode 100644 index 0000000..936c84f Binary files /dev/null and b/data/labels/52_1.png differ diff --git a/data/labels/52_2.png b/data/labels/52_2.png new file mode 100644 index 0000000..57e3f05 Binary files /dev/null and b/data/labels/52_2.png differ diff --git a/data/labels/52_3.png b/data/labels/52_3.png new file mode 100644 index 0000000..6a8f99e Binary files /dev/null and b/data/labels/52_3.png differ diff --git a/data/labels/52_4.png b/data/labels/52_4.png new file mode 100644 index 0000000..91f97f0 Binary files /dev/null and b/data/labels/52_4.png differ diff --git a/data/labels/52_5.png b/data/labels/52_5.png new file mode 100644 index 0000000..a78504f Binary files /dev/null and b/data/labels/52_5.png differ diff --git a/data/labels/52_6.png b/data/labels/52_6.png new file mode 100644 index 0000000..f52bd2c Binary files /dev/null and b/data/labels/52_6.png differ diff --git a/data/labels/52_7.png b/data/labels/52_7.png new file mode 100644 index 0000000..621b8e0 Binary files /dev/null and b/data/labels/52_7.png differ diff --git a/data/labels/53_0.png b/data/labels/53_0.png new file mode 100644 index 0000000..a750615 Binary files /dev/null and b/data/labels/53_0.png differ diff --git a/data/labels/53_1.png b/data/labels/53_1.png new file mode 100644 index 0000000..1c4e097 Binary files /dev/null and b/data/labels/53_1.png differ diff --git a/data/labels/53_2.png b/data/labels/53_2.png new file mode 100644 index 0000000..f523856 Binary files /dev/null and b/data/labels/53_2.png differ diff --git a/data/labels/53_3.png b/data/labels/53_3.png new file mode 100644 index 0000000..85505f8 Binary files /dev/null and b/data/labels/53_3.png differ diff --git a/data/labels/53_4.png b/data/labels/53_4.png new file mode 100644 index 0000000..14e8da1 Binary files /dev/null and b/data/labels/53_4.png differ diff --git a/data/labels/53_5.png b/data/labels/53_5.png new file mode 100644 index 0000000..79781fc Binary files /dev/null and b/data/labels/53_5.png differ diff --git a/data/labels/53_6.png b/data/labels/53_6.png new file mode 100644 index 0000000..a6e1863 Binary files /dev/null and b/data/labels/53_6.png differ diff --git a/data/labels/53_7.png b/data/labels/53_7.png new file mode 100644 index 0000000..bff5eb6 Binary files /dev/null and b/data/labels/53_7.png differ diff --git a/data/labels/54_0.png b/data/labels/54_0.png new file mode 100644 index 0000000..98ce423 Binary files /dev/null and b/data/labels/54_0.png differ diff --git a/data/labels/54_1.png b/data/labels/54_1.png new file mode 100644 index 0000000..643ef36 Binary files /dev/null and b/data/labels/54_1.png differ diff --git a/data/labels/54_2.png b/data/labels/54_2.png new file mode 100644 index 0000000..2c3894e Binary files /dev/null and b/data/labels/54_2.png differ diff --git a/data/labels/54_3.png b/data/labels/54_3.png new file mode 100644 index 0000000..6190fdc Binary files /dev/null and b/data/labels/54_3.png differ diff --git a/data/labels/54_4.png b/data/labels/54_4.png new file mode 100644 index 0000000..92afc20 Binary files /dev/null and b/data/labels/54_4.png differ diff --git a/data/labels/54_5.png b/data/labels/54_5.png new file mode 100644 index 0000000..feab352 Binary files /dev/null and b/data/labels/54_5.png differ diff --git a/data/labels/54_6.png b/data/labels/54_6.png new file mode 100644 index 0000000..c46698f Binary files /dev/null and b/data/labels/54_6.png differ diff --git a/data/labels/54_7.png b/data/labels/54_7.png new file mode 100644 index 0000000..175dbeb Binary files /dev/null and b/data/labels/54_7.png differ diff --git a/data/labels/55_0.png b/data/labels/55_0.png new file mode 100644 index 0000000..644838b Binary files /dev/null and b/data/labels/55_0.png differ diff --git a/data/labels/55_1.png b/data/labels/55_1.png new file mode 100644 index 0000000..b84e0eb Binary files /dev/null and b/data/labels/55_1.png differ diff --git a/data/labels/55_2.png b/data/labels/55_2.png new file mode 100644 index 0000000..3896d08 Binary files /dev/null and b/data/labels/55_2.png differ diff --git a/data/labels/55_3.png b/data/labels/55_3.png new file mode 100644 index 0000000..21e9266 Binary files /dev/null and b/data/labels/55_3.png differ diff --git a/data/labels/55_4.png b/data/labels/55_4.png new file mode 100644 index 0000000..d6aed1b Binary files /dev/null and b/data/labels/55_4.png differ diff --git a/data/labels/55_5.png b/data/labels/55_5.png new file mode 100644 index 0000000..1f60c36 Binary files /dev/null and b/data/labels/55_5.png differ diff --git a/data/labels/55_6.png b/data/labels/55_6.png new file mode 100644 index 0000000..2a7f1fb Binary files /dev/null and b/data/labels/55_6.png differ diff --git a/data/labels/55_7.png b/data/labels/55_7.png new file mode 100644 index 0000000..80c527b Binary files /dev/null and b/data/labels/55_7.png differ diff --git a/data/labels/56_0.png b/data/labels/56_0.png new file mode 100644 index 0000000..8a1e0c7 Binary files /dev/null and b/data/labels/56_0.png differ diff --git a/data/labels/56_1.png b/data/labels/56_1.png new file mode 100644 index 0000000..a0a81a0 Binary files /dev/null and b/data/labels/56_1.png differ diff --git a/data/labels/56_2.png b/data/labels/56_2.png new file mode 100644 index 0000000..367f20e Binary files /dev/null and b/data/labels/56_2.png differ diff --git a/data/labels/56_3.png b/data/labels/56_3.png new file mode 100644 index 0000000..cf56f8f Binary files /dev/null and b/data/labels/56_3.png differ diff --git a/data/labels/56_4.png b/data/labels/56_4.png new file mode 100644 index 0000000..e57cce7 Binary files /dev/null and b/data/labels/56_4.png differ diff --git a/data/labels/56_5.png b/data/labels/56_5.png new file mode 100644 index 0000000..c206547 Binary files /dev/null and b/data/labels/56_5.png differ diff --git a/data/labels/56_6.png b/data/labels/56_6.png new file mode 100644 index 0000000..040692a Binary files /dev/null and b/data/labels/56_6.png differ diff --git a/data/labels/56_7.png b/data/labels/56_7.png new file mode 100644 index 0000000..4c27c10 Binary files /dev/null and b/data/labels/56_7.png differ diff --git a/data/labels/57_0.png b/data/labels/57_0.png new file mode 100644 index 0000000..e20a46f Binary files /dev/null and b/data/labels/57_0.png differ diff --git a/data/labels/57_1.png b/data/labels/57_1.png new file mode 100644 index 0000000..17cd262 Binary files /dev/null and b/data/labels/57_1.png differ diff --git a/data/labels/57_2.png b/data/labels/57_2.png new file mode 100644 index 0000000..98fad29 Binary files /dev/null and b/data/labels/57_2.png differ diff --git a/data/labels/57_3.png b/data/labels/57_3.png new file mode 100644 index 0000000..ba80aa0 Binary files /dev/null and b/data/labels/57_3.png differ diff --git a/data/labels/57_4.png b/data/labels/57_4.png new file mode 100644 index 0000000..e982243 Binary files /dev/null and b/data/labels/57_4.png differ diff --git a/data/labels/57_5.png b/data/labels/57_5.png new file mode 100644 index 0000000..e947ff8 Binary files /dev/null and b/data/labels/57_5.png differ diff --git a/data/labels/57_6.png b/data/labels/57_6.png new file mode 100644 index 0000000..c4ae076 Binary files /dev/null and b/data/labels/57_6.png differ diff --git a/data/labels/57_7.png b/data/labels/57_7.png new file mode 100644 index 0000000..bd4ca16 Binary files /dev/null and b/data/labels/57_7.png differ diff --git a/data/labels/58_0.png b/data/labels/58_0.png new file mode 100644 index 0000000..d9e35f7 Binary files /dev/null and b/data/labels/58_0.png differ diff --git a/data/labels/58_1.png b/data/labels/58_1.png new file mode 100644 index 0000000..0dd6dd0 Binary files /dev/null and b/data/labels/58_1.png differ diff --git a/data/labels/58_2.png b/data/labels/58_2.png new file mode 100644 index 0000000..b9f1319 Binary files /dev/null and b/data/labels/58_2.png differ diff --git a/data/labels/58_3.png b/data/labels/58_3.png new file mode 100644 index 0000000..0604337 Binary files /dev/null and b/data/labels/58_3.png differ diff --git a/data/labels/58_4.png b/data/labels/58_4.png new file mode 100644 index 0000000..7283e03 Binary files /dev/null and b/data/labels/58_4.png differ diff --git a/data/labels/58_5.png b/data/labels/58_5.png new file mode 100644 index 0000000..2df3db9 Binary files /dev/null and b/data/labels/58_5.png differ diff --git a/data/labels/58_6.png b/data/labels/58_6.png new file mode 100644 index 0000000..e120909 Binary files /dev/null and b/data/labels/58_6.png differ diff --git a/data/labels/58_7.png b/data/labels/58_7.png new file mode 100644 index 0000000..e85fc0a Binary files /dev/null and b/data/labels/58_7.png differ diff --git a/data/labels/59_0.png b/data/labels/59_0.png new file mode 100644 index 0000000..09b2120 Binary files /dev/null and b/data/labels/59_0.png differ diff --git a/data/labels/59_1.png b/data/labels/59_1.png new file mode 100644 index 0000000..4b91814 Binary files /dev/null and b/data/labels/59_1.png differ diff --git a/data/labels/59_2.png b/data/labels/59_2.png new file mode 100644 index 0000000..cc302c2 Binary files /dev/null and b/data/labels/59_2.png differ diff --git a/data/labels/59_3.png b/data/labels/59_3.png new file mode 100644 index 0000000..6921796 Binary files /dev/null and b/data/labels/59_3.png differ diff --git a/data/labels/59_4.png b/data/labels/59_4.png new file mode 100644 index 0000000..4b77147 Binary files /dev/null and b/data/labels/59_4.png differ diff --git a/data/labels/59_5.png b/data/labels/59_5.png new file mode 100644 index 0000000..4325e62 Binary files /dev/null and b/data/labels/59_5.png differ diff --git a/data/labels/59_6.png b/data/labels/59_6.png new file mode 100644 index 0000000..135da33 Binary files /dev/null and b/data/labels/59_6.png differ diff --git a/data/labels/59_7.png b/data/labels/59_7.png new file mode 100644 index 0000000..353ae33 Binary files /dev/null and b/data/labels/59_7.png differ diff --git a/data/labels/60_0.png b/data/labels/60_0.png new file mode 100644 index 0000000..210e77d Binary files /dev/null and b/data/labels/60_0.png differ diff --git a/data/labels/60_1.png b/data/labels/60_1.png new file mode 100644 index 0000000..507c736 Binary files /dev/null and b/data/labels/60_1.png differ diff --git a/data/labels/60_2.png b/data/labels/60_2.png new file mode 100644 index 0000000..4227322 Binary files /dev/null and b/data/labels/60_2.png differ diff --git a/data/labels/60_3.png b/data/labels/60_3.png new file mode 100644 index 0000000..ac4d026 Binary files /dev/null and b/data/labels/60_3.png differ diff --git a/data/labels/60_4.png b/data/labels/60_4.png new file mode 100644 index 0000000..5cf89ed Binary files /dev/null and b/data/labels/60_4.png differ diff --git a/data/labels/60_5.png b/data/labels/60_5.png new file mode 100644 index 0000000..5ceb7fe Binary files /dev/null and b/data/labels/60_5.png differ diff --git a/data/labels/60_6.png b/data/labels/60_6.png new file mode 100644 index 0000000..45121a7 Binary files /dev/null and b/data/labels/60_6.png differ diff --git a/data/labels/60_7.png b/data/labels/60_7.png new file mode 100644 index 0000000..33eb9e3 Binary files /dev/null and b/data/labels/60_7.png differ diff --git a/data/labels/61_0.png b/data/labels/61_0.png new file mode 100644 index 0000000..72bc6bf Binary files /dev/null and b/data/labels/61_0.png differ diff --git a/data/labels/61_1.png b/data/labels/61_1.png new file mode 100644 index 0000000..50def57 Binary files /dev/null and b/data/labels/61_1.png differ diff --git a/data/labels/61_2.png b/data/labels/61_2.png new file mode 100644 index 0000000..a0e9a67 Binary files /dev/null and b/data/labels/61_2.png differ diff --git a/data/labels/61_3.png b/data/labels/61_3.png new file mode 100644 index 0000000..0b7d149 Binary files /dev/null and b/data/labels/61_3.png differ diff --git a/data/labels/61_4.png b/data/labels/61_4.png new file mode 100644 index 0000000..c0b71d8 Binary files /dev/null and b/data/labels/61_4.png differ diff --git a/data/labels/61_5.png b/data/labels/61_5.png new file mode 100644 index 0000000..cf39e63 Binary files /dev/null and b/data/labels/61_5.png differ diff --git a/data/labels/61_6.png b/data/labels/61_6.png new file mode 100644 index 0000000..95282d4 Binary files /dev/null and b/data/labels/61_6.png differ diff --git a/data/labels/61_7.png b/data/labels/61_7.png new file mode 100644 index 0000000..6da5c02 Binary files /dev/null and b/data/labels/61_7.png differ diff --git a/data/labels/62_0.png b/data/labels/62_0.png new file mode 100644 index 0000000..bb12109 Binary files /dev/null and b/data/labels/62_0.png differ diff --git a/data/labels/62_1.png b/data/labels/62_1.png new file mode 100644 index 0000000..5b82445 Binary files /dev/null and b/data/labels/62_1.png differ diff --git a/data/labels/62_2.png b/data/labels/62_2.png new file mode 100644 index 0000000..d4ca5a6 Binary files /dev/null and b/data/labels/62_2.png differ diff --git a/data/labels/62_3.png b/data/labels/62_3.png new file mode 100644 index 0000000..24ddea8 Binary files /dev/null and b/data/labels/62_3.png differ diff --git a/data/labels/62_4.png b/data/labels/62_4.png new file mode 100644 index 0000000..34130a2 Binary files /dev/null and b/data/labels/62_4.png differ diff --git a/data/labels/62_5.png b/data/labels/62_5.png new file mode 100644 index 0000000..823d996 Binary files /dev/null and b/data/labels/62_5.png differ diff --git a/data/labels/62_6.png b/data/labels/62_6.png new file mode 100644 index 0000000..63dd85d Binary files /dev/null and b/data/labels/62_6.png differ diff --git a/data/labels/62_7.png b/data/labels/62_7.png new file mode 100644 index 0000000..7c6158f Binary files /dev/null and b/data/labels/62_7.png differ diff --git a/data/labels/63_0.png b/data/labels/63_0.png new file mode 100644 index 0000000..2d9571e Binary files /dev/null and b/data/labels/63_0.png differ diff --git a/data/labels/63_1.png b/data/labels/63_1.png new file mode 100644 index 0000000..5376e07 Binary files /dev/null and b/data/labels/63_1.png differ diff --git a/data/labels/63_2.png b/data/labels/63_2.png new file mode 100644 index 0000000..746ffa0 Binary files /dev/null and b/data/labels/63_2.png differ diff --git a/data/labels/63_3.png b/data/labels/63_3.png new file mode 100644 index 0000000..58bb35a Binary files /dev/null and b/data/labels/63_3.png differ diff --git a/data/labels/63_4.png b/data/labels/63_4.png new file mode 100644 index 0000000..ff1dc1a Binary files /dev/null and b/data/labels/63_4.png differ diff --git a/data/labels/63_5.png b/data/labels/63_5.png new file mode 100644 index 0000000..13e34ce Binary files /dev/null and b/data/labels/63_5.png differ diff --git a/data/labels/63_6.png b/data/labels/63_6.png new file mode 100644 index 0000000..9407c83 Binary files /dev/null and b/data/labels/63_6.png differ diff --git a/data/labels/63_7.png b/data/labels/63_7.png new file mode 100644 index 0000000..e9c3edf Binary files /dev/null and b/data/labels/63_7.png differ diff --git a/data/labels/64_0.png b/data/labels/64_0.png new file mode 100644 index 0000000..0a3a101 Binary files /dev/null and b/data/labels/64_0.png differ diff --git a/data/labels/64_1.png b/data/labels/64_1.png new file mode 100644 index 0000000..6313960 Binary files /dev/null and b/data/labels/64_1.png differ diff --git a/data/labels/64_2.png b/data/labels/64_2.png new file mode 100644 index 0000000..c49565c Binary files /dev/null and b/data/labels/64_2.png differ diff --git a/data/labels/64_3.png b/data/labels/64_3.png new file mode 100644 index 0000000..c697f9b Binary files /dev/null and b/data/labels/64_3.png differ diff --git a/data/labels/64_4.png b/data/labels/64_4.png new file mode 100644 index 0000000..de194c7 Binary files /dev/null and b/data/labels/64_4.png differ diff --git a/data/labels/64_5.png b/data/labels/64_5.png new file mode 100644 index 0000000..9905004 Binary files /dev/null and b/data/labels/64_5.png differ diff --git a/data/labels/64_6.png b/data/labels/64_6.png new file mode 100644 index 0000000..7b91569 Binary files /dev/null and b/data/labels/64_6.png differ diff --git a/data/labels/64_7.png b/data/labels/64_7.png new file mode 100644 index 0000000..b9ebcee Binary files /dev/null and b/data/labels/64_7.png differ diff --git a/data/labels/65_0.png b/data/labels/65_0.png new file mode 100644 index 0000000..c388066 Binary files /dev/null and b/data/labels/65_0.png differ diff --git a/data/labels/65_1.png b/data/labels/65_1.png new file mode 100644 index 0000000..9f7d7f7 Binary files /dev/null and b/data/labels/65_1.png differ diff --git a/data/labels/65_2.png b/data/labels/65_2.png new file mode 100644 index 0000000..6f76694 Binary files /dev/null and b/data/labels/65_2.png differ diff --git a/data/labels/65_3.png b/data/labels/65_3.png new file mode 100644 index 0000000..3593128 Binary files /dev/null and b/data/labels/65_3.png differ diff --git a/data/labels/65_4.png b/data/labels/65_4.png new file mode 100644 index 0000000..23f4814 Binary files /dev/null and b/data/labels/65_4.png differ diff --git a/data/labels/65_5.png b/data/labels/65_5.png new file mode 100644 index 0000000..8eae6d7 Binary files /dev/null and b/data/labels/65_5.png differ diff --git a/data/labels/65_6.png b/data/labels/65_6.png new file mode 100644 index 0000000..02fec76 Binary files /dev/null and b/data/labels/65_6.png differ diff --git a/data/labels/65_7.png b/data/labels/65_7.png new file mode 100644 index 0000000..c80822e Binary files /dev/null and b/data/labels/65_7.png differ diff --git a/data/labels/66_0.png b/data/labels/66_0.png new file mode 100644 index 0000000..278a401 Binary files /dev/null and b/data/labels/66_0.png differ diff --git a/data/labels/66_1.png b/data/labels/66_1.png new file mode 100644 index 0000000..47c3735 Binary files /dev/null and b/data/labels/66_1.png differ diff --git a/data/labels/66_2.png b/data/labels/66_2.png new file mode 100644 index 0000000..dfcf8c4 Binary files /dev/null and b/data/labels/66_2.png differ diff --git a/data/labels/66_3.png b/data/labels/66_3.png new file mode 100644 index 0000000..d8d69a7 Binary files /dev/null and b/data/labels/66_3.png differ diff --git a/data/labels/66_4.png b/data/labels/66_4.png new file mode 100644 index 0000000..842976a Binary files /dev/null and b/data/labels/66_4.png differ diff --git a/data/labels/66_5.png b/data/labels/66_5.png new file mode 100644 index 0000000..991caf8 Binary files /dev/null and b/data/labels/66_5.png differ diff --git a/data/labels/66_6.png b/data/labels/66_6.png new file mode 100644 index 0000000..32c5284 Binary files /dev/null and b/data/labels/66_6.png differ diff --git a/data/labels/66_7.png b/data/labels/66_7.png new file mode 100644 index 0000000..14e8609 Binary files /dev/null and b/data/labels/66_7.png differ diff --git a/data/labels/67_0.png b/data/labels/67_0.png new file mode 100644 index 0000000..7f2786a Binary files /dev/null and b/data/labels/67_0.png differ diff --git a/data/labels/67_1.png b/data/labels/67_1.png new file mode 100644 index 0000000..798b421 Binary files /dev/null and b/data/labels/67_1.png differ diff --git a/data/labels/67_2.png b/data/labels/67_2.png new file mode 100644 index 0000000..802aaab Binary files /dev/null and b/data/labels/67_2.png differ diff --git a/data/labels/67_3.png b/data/labels/67_3.png new file mode 100644 index 0000000..9d975ca Binary files /dev/null and b/data/labels/67_3.png differ diff --git a/data/labels/67_4.png b/data/labels/67_4.png new file mode 100644 index 0000000..94ee577 Binary files /dev/null and b/data/labels/67_4.png differ diff --git a/data/labels/67_5.png b/data/labels/67_5.png new file mode 100644 index 0000000..021a877 Binary files /dev/null and b/data/labels/67_5.png differ diff --git a/data/labels/67_6.png b/data/labels/67_6.png new file mode 100644 index 0000000..c358732 Binary files /dev/null and b/data/labels/67_6.png differ diff --git a/data/labels/67_7.png b/data/labels/67_7.png new file mode 100644 index 0000000..46acdf2 Binary files /dev/null and b/data/labels/67_7.png differ diff --git a/data/labels/68_0.png b/data/labels/68_0.png new file mode 100644 index 0000000..9e86a2f Binary files /dev/null and b/data/labels/68_0.png differ diff --git a/data/labels/68_1.png b/data/labels/68_1.png new file mode 100644 index 0000000..d7d3ac3 Binary files /dev/null and b/data/labels/68_1.png differ diff --git a/data/labels/68_2.png b/data/labels/68_2.png new file mode 100644 index 0000000..3a48f05 Binary files /dev/null and b/data/labels/68_2.png differ diff --git a/data/labels/68_3.png b/data/labels/68_3.png new file mode 100644 index 0000000..808603a Binary files /dev/null and b/data/labels/68_3.png differ diff --git a/data/labels/68_4.png b/data/labels/68_4.png new file mode 100644 index 0000000..d4f9bd4 Binary files /dev/null and b/data/labels/68_4.png differ diff --git a/data/labels/68_5.png b/data/labels/68_5.png new file mode 100644 index 0000000..25d8a96 Binary files /dev/null and b/data/labels/68_5.png differ diff --git a/data/labels/68_6.png b/data/labels/68_6.png new file mode 100644 index 0000000..0059c7f Binary files /dev/null and b/data/labels/68_6.png differ diff --git a/data/labels/68_7.png b/data/labels/68_7.png new file mode 100644 index 0000000..c2aa922 Binary files /dev/null and b/data/labels/68_7.png differ diff --git a/data/labels/69_0.png b/data/labels/69_0.png new file mode 100644 index 0000000..51140e0 Binary files /dev/null and b/data/labels/69_0.png differ diff --git a/data/labels/69_1.png b/data/labels/69_1.png new file mode 100644 index 0000000..bcf7311 Binary files /dev/null and b/data/labels/69_1.png differ diff --git a/data/labels/69_2.png b/data/labels/69_2.png new file mode 100644 index 0000000..582b289 Binary files /dev/null and b/data/labels/69_2.png differ diff --git a/data/labels/69_3.png b/data/labels/69_3.png new file mode 100644 index 0000000..e331123 Binary files /dev/null and b/data/labels/69_3.png differ diff --git a/data/labels/69_4.png b/data/labels/69_4.png new file mode 100644 index 0000000..a310f84 Binary files /dev/null and b/data/labels/69_4.png differ diff --git a/data/labels/69_5.png b/data/labels/69_5.png new file mode 100644 index 0000000..ad69668 Binary files /dev/null and b/data/labels/69_5.png differ diff --git a/data/labels/69_6.png b/data/labels/69_6.png new file mode 100644 index 0000000..a7b8f45 Binary files /dev/null and b/data/labels/69_6.png differ diff --git a/data/labels/69_7.png b/data/labels/69_7.png new file mode 100644 index 0000000..7f3200c Binary files /dev/null and b/data/labels/69_7.png differ diff --git a/data/labels/70_0.png b/data/labels/70_0.png new file mode 100644 index 0000000..e0fb76c Binary files /dev/null and b/data/labels/70_0.png differ diff --git a/data/labels/70_1.png b/data/labels/70_1.png new file mode 100644 index 0000000..40c8217 Binary files /dev/null and b/data/labels/70_1.png differ diff --git a/data/labels/70_2.png b/data/labels/70_2.png new file mode 100644 index 0000000..63c811b Binary files /dev/null and b/data/labels/70_2.png differ diff --git a/data/labels/70_3.png b/data/labels/70_3.png new file mode 100644 index 0000000..7c93cf7 Binary files /dev/null and b/data/labels/70_3.png differ diff --git a/data/labels/70_4.png b/data/labels/70_4.png new file mode 100644 index 0000000..6033fb1 Binary files /dev/null and b/data/labels/70_4.png differ diff --git a/data/labels/70_5.png b/data/labels/70_5.png new file mode 100644 index 0000000..bfcf028 Binary files /dev/null and b/data/labels/70_5.png differ diff --git a/data/labels/70_6.png b/data/labels/70_6.png new file mode 100644 index 0000000..5fe9cdb Binary files /dev/null and b/data/labels/70_6.png differ diff --git a/data/labels/70_7.png b/data/labels/70_7.png new file mode 100644 index 0000000..027af86 Binary files /dev/null and b/data/labels/70_7.png differ diff --git a/data/labels/71_0.png b/data/labels/71_0.png new file mode 100644 index 0000000..679b5e9 Binary files /dev/null and b/data/labels/71_0.png differ diff --git a/data/labels/71_1.png b/data/labels/71_1.png new file mode 100644 index 0000000..6f5271b Binary files /dev/null and b/data/labels/71_1.png differ diff --git a/data/labels/71_2.png b/data/labels/71_2.png new file mode 100644 index 0000000..93dc749 Binary files /dev/null and b/data/labels/71_2.png differ diff --git a/data/labels/71_3.png b/data/labels/71_3.png new file mode 100644 index 0000000..03a4bc6 Binary files /dev/null and b/data/labels/71_3.png differ diff --git a/data/labels/71_4.png b/data/labels/71_4.png new file mode 100644 index 0000000..3976418 Binary files /dev/null and b/data/labels/71_4.png differ diff --git a/data/labels/71_5.png b/data/labels/71_5.png new file mode 100644 index 0000000..b0c4295 Binary files /dev/null and b/data/labels/71_5.png differ diff --git a/data/labels/71_6.png b/data/labels/71_6.png new file mode 100644 index 0000000..bb8710d Binary files /dev/null and b/data/labels/71_6.png differ diff --git a/data/labels/71_7.png b/data/labels/71_7.png new file mode 100644 index 0000000..68148a9 Binary files /dev/null and b/data/labels/71_7.png differ diff --git a/data/labels/72_0.png b/data/labels/72_0.png new file mode 100644 index 0000000..a2edd04 Binary files /dev/null and b/data/labels/72_0.png differ diff --git a/data/labels/72_1.png b/data/labels/72_1.png new file mode 100644 index 0000000..f1e8bcd Binary files /dev/null and b/data/labels/72_1.png differ diff --git a/data/labels/72_2.png b/data/labels/72_2.png new file mode 100644 index 0000000..a9516f1 Binary files /dev/null and b/data/labels/72_2.png differ diff --git a/data/labels/72_3.png b/data/labels/72_3.png new file mode 100644 index 0000000..5b94490 Binary files /dev/null and b/data/labels/72_3.png differ diff --git a/data/labels/72_4.png b/data/labels/72_4.png new file mode 100644 index 0000000..83f7dbf Binary files /dev/null and b/data/labels/72_4.png differ diff --git a/data/labels/72_5.png b/data/labels/72_5.png new file mode 100644 index 0000000..5a40ad3 Binary files /dev/null and b/data/labels/72_5.png differ diff --git a/data/labels/72_6.png b/data/labels/72_6.png new file mode 100644 index 0000000..b889837 Binary files /dev/null and b/data/labels/72_6.png differ diff --git a/data/labels/72_7.png b/data/labels/72_7.png new file mode 100644 index 0000000..4ec34df Binary files /dev/null and b/data/labels/72_7.png differ diff --git a/data/labels/73_0.png b/data/labels/73_0.png new file mode 100644 index 0000000..e554432 Binary files /dev/null and b/data/labels/73_0.png differ diff --git a/data/labels/73_1.png b/data/labels/73_1.png new file mode 100644 index 0000000..08d1924 Binary files /dev/null and b/data/labels/73_1.png differ diff --git a/data/labels/73_2.png b/data/labels/73_2.png new file mode 100644 index 0000000..3c87085 Binary files /dev/null and b/data/labels/73_2.png differ diff --git a/data/labels/73_3.png b/data/labels/73_3.png new file mode 100644 index 0000000..11d0f76 Binary files /dev/null and b/data/labels/73_3.png differ diff --git a/data/labels/73_4.png b/data/labels/73_4.png new file mode 100644 index 0000000..ebacf1f Binary files /dev/null and b/data/labels/73_4.png differ diff --git a/data/labels/73_5.png b/data/labels/73_5.png new file mode 100644 index 0000000..d58377d Binary files /dev/null and b/data/labels/73_5.png differ diff --git a/data/labels/73_6.png b/data/labels/73_6.png new file mode 100644 index 0000000..293b96b Binary files /dev/null and b/data/labels/73_6.png differ diff --git a/data/labels/73_7.png b/data/labels/73_7.png new file mode 100644 index 0000000..80f409d Binary files /dev/null and b/data/labels/73_7.png differ diff --git a/data/labels/74_0.png b/data/labels/74_0.png new file mode 100644 index 0000000..cc1d9f3 Binary files /dev/null and b/data/labels/74_0.png differ diff --git a/data/labels/74_1.png b/data/labels/74_1.png new file mode 100644 index 0000000..9171332 Binary files /dev/null and b/data/labels/74_1.png differ diff --git a/data/labels/74_2.png b/data/labels/74_2.png new file mode 100644 index 0000000..c08cea8 Binary files /dev/null and b/data/labels/74_2.png differ diff --git a/data/labels/74_3.png b/data/labels/74_3.png new file mode 100644 index 0000000..ce8e8c8 Binary files /dev/null and b/data/labels/74_3.png differ diff --git a/data/labels/74_4.png b/data/labels/74_4.png new file mode 100644 index 0000000..b112fa6 Binary files /dev/null and b/data/labels/74_4.png differ diff --git a/data/labels/74_5.png b/data/labels/74_5.png new file mode 100644 index 0000000..c9a7bbb Binary files /dev/null and b/data/labels/74_5.png differ diff --git a/data/labels/74_6.png b/data/labels/74_6.png new file mode 100644 index 0000000..8f72aac Binary files /dev/null and b/data/labels/74_6.png differ diff --git a/data/labels/74_7.png b/data/labels/74_7.png new file mode 100644 index 0000000..f85a9f9 Binary files /dev/null and b/data/labels/74_7.png differ diff --git a/data/labels/75_0.png b/data/labels/75_0.png new file mode 100644 index 0000000..b1f3ac4 Binary files /dev/null and b/data/labels/75_0.png differ diff --git a/data/labels/75_1.png b/data/labels/75_1.png new file mode 100644 index 0000000..9f06109 Binary files /dev/null and b/data/labels/75_1.png differ diff --git a/data/labels/75_2.png b/data/labels/75_2.png new file mode 100644 index 0000000..9224666 Binary files /dev/null and b/data/labels/75_2.png differ diff --git a/data/labels/75_3.png b/data/labels/75_3.png new file mode 100644 index 0000000..eb76489 Binary files /dev/null and b/data/labels/75_3.png differ diff --git a/data/labels/75_4.png b/data/labels/75_4.png new file mode 100644 index 0000000..7dfee15 Binary files /dev/null and b/data/labels/75_4.png differ diff --git a/data/labels/75_5.png b/data/labels/75_5.png new file mode 100644 index 0000000..8b081f6 Binary files /dev/null and b/data/labels/75_5.png differ diff --git a/data/labels/75_6.png b/data/labels/75_6.png new file mode 100644 index 0000000..95631cf Binary files /dev/null and b/data/labels/75_6.png differ diff --git a/data/labels/75_7.png b/data/labels/75_7.png new file mode 100644 index 0000000..db915ea Binary files /dev/null and b/data/labels/75_7.png differ diff --git a/data/labels/76_0.png b/data/labels/76_0.png new file mode 100644 index 0000000..5ceef1d Binary files /dev/null and b/data/labels/76_0.png differ diff --git a/data/labels/76_1.png b/data/labels/76_1.png new file mode 100644 index 0000000..5386831 Binary files /dev/null and b/data/labels/76_1.png differ diff --git a/data/labels/76_2.png b/data/labels/76_2.png new file mode 100644 index 0000000..6c8393a Binary files /dev/null and b/data/labels/76_2.png differ diff --git a/data/labels/76_3.png b/data/labels/76_3.png new file mode 100644 index 0000000..fbe5712 Binary files /dev/null and b/data/labels/76_3.png differ diff --git a/data/labels/76_4.png b/data/labels/76_4.png new file mode 100644 index 0000000..e47a6eb Binary files /dev/null and b/data/labels/76_4.png differ diff --git a/data/labels/76_5.png b/data/labels/76_5.png new file mode 100644 index 0000000..f349490 Binary files /dev/null and b/data/labels/76_5.png differ diff --git a/data/labels/76_6.png b/data/labels/76_6.png new file mode 100644 index 0000000..e661143 Binary files /dev/null and b/data/labels/76_6.png differ diff --git a/data/labels/76_7.png b/data/labels/76_7.png new file mode 100644 index 0000000..64d0834 Binary files /dev/null and b/data/labels/76_7.png differ diff --git a/data/labels/77_0.png b/data/labels/77_0.png new file mode 100644 index 0000000..05aab7d Binary files /dev/null and b/data/labels/77_0.png differ diff --git a/data/labels/77_1.png b/data/labels/77_1.png new file mode 100644 index 0000000..64cb608 Binary files /dev/null and b/data/labels/77_1.png differ diff --git a/data/labels/77_2.png b/data/labels/77_2.png new file mode 100644 index 0000000..2da938c Binary files /dev/null and b/data/labels/77_2.png differ diff --git a/data/labels/77_3.png b/data/labels/77_3.png new file mode 100644 index 0000000..14179d9 Binary files /dev/null and b/data/labels/77_3.png differ diff --git a/data/labels/77_4.png b/data/labels/77_4.png new file mode 100644 index 0000000..894b470 Binary files /dev/null and b/data/labels/77_4.png differ diff --git a/data/labels/77_5.png b/data/labels/77_5.png new file mode 100644 index 0000000..a55e5b6 Binary files /dev/null and b/data/labels/77_5.png differ diff --git a/data/labels/77_6.png b/data/labels/77_6.png new file mode 100644 index 0000000..4f0e714 Binary files /dev/null and b/data/labels/77_6.png differ diff --git a/data/labels/77_7.png b/data/labels/77_7.png new file mode 100644 index 0000000..804e8c2 Binary files /dev/null and b/data/labels/77_7.png differ diff --git a/data/labels/78_0.png b/data/labels/78_0.png new file mode 100644 index 0000000..e1fede7 Binary files /dev/null and b/data/labels/78_0.png differ diff --git a/data/labels/78_1.png b/data/labels/78_1.png new file mode 100644 index 0000000..23b2a74 Binary files /dev/null and b/data/labels/78_1.png differ diff --git a/data/labels/78_2.png b/data/labels/78_2.png new file mode 100644 index 0000000..5471820 Binary files /dev/null and b/data/labels/78_2.png differ diff --git a/data/labels/78_3.png b/data/labels/78_3.png new file mode 100644 index 0000000..bc9659a Binary files /dev/null and b/data/labels/78_3.png differ diff --git a/data/labels/78_4.png b/data/labels/78_4.png new file mode 100644 index 0000000..54b95f9 Binary files /dev/null and b/data/labels/78_4.png differ diff --git a/data/labels/78_5.png b/data/labels/78_5.png new file mode 100644 index 0000000..2c67a51 Binary files /dev/null and b/data/labels/78_5.png differ diff --git a/data/labels/78_6.png b/data/labels/78_6.png new file mode 100644 index 0000000..44326f5 Binary files /dev/null and b/data/labels/78_6.png differ diff --git a/data/labels/78_7.png b/data/labels/78_7.png new file mode 100644 index 0000000..4d5d8dc Binary files /dev/null and b/data/labels/78_7.png differ diff --git a/data/labels/79_0.png b/data/labels/79_0.png new file mode 100644 index 0000000..f3f4c1e Binary files /dev/null and b/data/labels/79_0.png differ diff --git a/data/labels/79_1.png b/data/labels/79_1.png new file mode 100644 index 0000000..23d960e Binary files /dev/null and b/data/labels/79_1.png differ diff --git a/data/labels/79_2.png b/data/labels/79_2.png new file mode 100644 index 0000000..ce5c52b Binary files /dev/null and b/data/labels/79_2.png differ diff --git a/data/labels/79_3.png b/data/labels/79_3.png new file mode 100644 index 0000000..b80a4f2 Binary files /dev/null and b/data/labels/79_3.png differ diff --git a/data/labels/79_4.png b/data/labels/79_4.png new file mode 100644 index 0000000..7fa16f8 Binary files /dev/null and b/data/labels/79_4.png differ diff --git a/data/labels/79_5.png b/data/labels/79_5.png new file mode 100644 index 0000000..c67c5bb Binary files /dev/null and b/data/labels/79_5.png differ diff --git a/data/labels/79_6.png b/data/labels/79_6.png new file mode 100644 index 0000000..e89ecd2 Binary files /dev/null and b/data/labels/79_6.png differ diff --git a/data/labels/79_7.png b/data/labels/79_7.png new file mode 100644 index 0000000..d964ae4 Binary files /dev/null and b/data/labels/79_7.png differ diff --git a/data/labels/80_0.png b/data/labels/80_0.png new file mode 100644 index 0000000..61403c9 Binary files /dev/null and b/data/labels/80_0.png differ diff --git a/data/labels/80_1.png b/data/labels/80_1.png new file mode 100644 index 0000000..992338d Binary files /dev/null and b/data/labels/80_1.png differ diff --git a/data/labels/80_2.png b/data/labels/80_2.png new file mode 100644 index 0000000..cfbd431 Binary files /dev/null and b/data/labels/80_2.png differ diff --git a/data/labels/80_3.png b/data/labels/80_3.png new file mode 100644 index 0000000..5de9472 Binary files /dev/null and b/data/labels/80_3.png differ diff --git a/data/labels/80_4.png b/data/labels/80_4.png new file mode 100644 index 0000000..0fecaf1 Binary files /dev/null and b/data/labels/80_4.png differ diff --git a/data/labels/80_5.png b/data/labels/80_5.png new file mode 100644 index 0000000..cbf65bd Binary files /dev/null and b/data/labels/80_5.png differ diff --git a/data/labels/80_6.png b/data/labels/80_6.png new file mode 100644 index 0000000..ff54a38 Binary files /dev/null and b/data/labels/80_6.png differ diff --git a/data/labels/80_7.png b/data/labels/80_7.png new file mode 100644 index 0000000..3d6f415 Binary files /dev/null and b/data/labels/80_7.png differ diff --git a/data/labels/81_0.png b/data/labels/81_0.png new file mode 100644 index 0000000..5a2025f Binary files /dev/null and b/data/labels/81_0.png differ diff --git a/data/labels/81_1.png b/data/labels/81_1.png new file mode 100644 index 0000000..511aec0 Binary files /dev/null and b/data/labels/81_1.png differ diff --git a/data/labels/81_2.png b/data/labels/81_2.png new file mode 100644 index 0000000..8e2f7e9 Binary files /dev/null and b/data/labels/81_2.png differ diff --git a/data/labels/81_3.png b/data/labels/81_3.png new file mode 100644 index 0000000..52edfd4 Binary files /dev/null and b/data/labels/81_3.png differ diff --git a/data/labels/81_4.png b/data/labels/81_4.png new file mode 100644 index 0000000..e60c7a9 Binary files /dev/null and b/data/labels/81_4.png differ diff --git a/data/labels/81_5.png b/data/labels/81_5.png new file mode 100644 index 0000000..d58df4f Binary files /dev/null and b/data/labels/81_5.png differ diff --git a/data/labels/81_6.png b/data/labels/81_6.png new file mode 100644 index 0000000..d31ba09 Binary files /dev/null and b/data/labels/81_6.png differ diff --git a/data/labels/81_7.png b/data/labels/81_7.png new file mode 100644 index 0000000..0770576 Binary files /dev/null and b/data/labels/81_7.png differ diff --git a/data/labels/82_0.png b/data/labels/82_0.png new file mode 100644 index 0000000..1bc3a98 Binary files /dev/null and b/data/labels/82_0.png differ diff --git a/data/labels/82_1.png b/data/labels/82_1.png new file mode 100644 index 0000000..e5931dc Binary files /dev/null and b/data/labels/82_1.png differ diff --git a/data/labels/82_2.png b/data/labels/82_2.png new file mode 100644 index 0000000..a5f8bb7 Binary files /dev/null and b/data/labels/82_2.png differ diff --git a/data/labels/82_3.png b/data/labels/82_3.png new file mode 100644 index 0000000..8b138a9 Binary files /dev/null and b/data/labels/82_3.png differ diff --git a/data/labels/82_4.png b/data/labels/82_4.png new file mode 100644 index 0000000..8a57060 Binary files /dev/null and b/data/labels/82_4.png differ diff --git a/data/labels/82_5.png b/data/labels/82_5.png new file mode 100644 index 0000000..f4dc04e Binary files /dev/null and b/data/labels/82_5.png differ diff --git a/data/labels/82_6.png b/data/labels/82_6.png new file mode 100644 index 0000000..2c7073a Binary files /dev/null and b/data/labels/82_6.png differ diff --git a/data/labels/82_7.png b/data/labels/82_7.png new file mode 100644 index 0000000..f4d966d Binary files /dev/null and b/data/labels/82_7.png differ diff --git a/data/labels/83_0.png b/data/labels/83_0.png new file mode 100644 index 0000000..c048782 Binary files /dev/null and b/data/labels/83_0.png differ diff --git a/data/labels/83_1.png b/data/labels/83_1.png new file mode 100644 index 0000000..3515f98 Binary files /dev/null and b/data/labels/83_1.png differ diff --git a/data/labels/83_2.png b/data/labels/83_2.png new file mode 100644 index 0000000..4a13b8d Binary files /dev/null and b/data/labels/83_2.png differ diff --git a/data/labels/83_3.png b/data/labels/83_3.png new file mode 100644 index 0000000..0944ac8 Binary files /dev/null and b/data/labels/83_3.png differ diff --git a/data/labels/83_4.png b/data/labels/83_4.png new file mode 100644 index 0000000..8b9f82f Binary files /dev/null and b/data/labels/83_4.png differ diff --git a/data/labels/83_5.png b/data/labels/83_5.png new file mode 100644 index 0000000..67f70ad Binary files /dev/null and b/data/labels/83_5.png differ diff --git a/data/labels/83_6.png b/data/labels/83_6.png new file mode 100644 index 0000000..0d3c0e1 Binary files /dev/null and b/data/labels/83_6.png differ diff --git a/data/labels/83_7.png b/data/labels/83_7.png new file mode 100644 index 0000000..0daab32 Binary files /dev/null and b/data/labels/83_7.png differ diff --git a/data/labels/84_0.png b/data/labels/84_0.png new file mode 100644 index 0000000..ffc3eb4 Binary files /dev/null and b/data/labels/84_0.png differ diff --git a/data/labels/84_1.png b/data/labels/84_1.png new file mode 100644 index 0000000..956e5eb Binary files /dev/null and b/data/labels/84_1.png differ diff --git a/data/labels/84_2.png b/data/labels/84_2.png new file mode 100644 index 0000000..a1e94fa Binary files /dev/null and b/data/labels/84_2.png differ diff --git a/data/labels/84_3.png b/data/labels/84_3.png new file mode 100644 index 0000000..2369b0c Binary files /dev/null and b/data/labels/84_3.png differ diff --git a/data/labels/84_4.png b/data/labels/84_4.png new file mode 100644 index 0000000..6d82ee8 Binary files /dev/null and b/data/labels/84_4.png differ diff --git a/data/labels/84_5.png b/data/labels/84_5.png new file mode 100644 index 0000000..6e95b70 Binary files /dev/null and b/data/labels/84_5.png differ diff --git a/data/labels/84_6.png b/data/labels/84_6.png new file mode 100644 index 0000000..9d62561 Binary files /dev/null and b/data/labels/84_6.png differ diff --git a/data/labels/84_7.png b/data/labels/84_7.png new file mode 100644 index 0000000..accde30 Binary files /dev/null and b/data/labels/84_7.png differ diff --git a/data/labels/85_0.png b/data/labels/85_0.png new file mode 100644 index 0000000..48e9906 Binary files /dev/null and b/data/labels/85_0.png differ diff --git a/data/labels/85_1.png b/data/labels/85_1.png new file mode 100644 index 0000000..3080720 Binary files /dev/null and b/data/labels/85_1.png differ diff --git a/data/labels/85_2.png b/data/labels/85_2.png new file mode 100644 index 0000000..e5a9369 Binary files /dev/null and b/data/labels/85_2.png differ diff --git a/data/labels/85_3.png b/data/labels/85_3.png new file mode 100644 index 0000000..5816c66 Binary files /dev/null and b/data/labels/85_3.png differ diff --git a/data/labels/85_4.png b/data/labels/85_4.png new file mode 100644 index 0000000..7d18ec0 Binary files /dev/null and b/data/labels/85_4.png differ diff --git a/data/labels/85_5.png b/data/labels/85_5.png new file mode 100644 index 0000000..f7b5550 Binary files /dev/null and b/data/labels/85_5.png differ diff --git a/data/labels/85_6.png b/data/labels/85_6.png new file mode 100644 index 0000000..7106103 Binary files /dev/null and b/data/labels/85_6.png differ diff --git a/data/labels/85_7.png b/data/labels/85_7.png new file mode 100644 index 0000000..7179daf Binary files /dev/null and b/data/labels/85_7.png differ diff --git a/data/labels/86_0.png b/data/labels/86_0.png new file mode 100644 index 0000000..2412ea1 Binary files /dev/null and b/data/labels/86_0.png differ diff --git a/data/labels/86_1.png b/data/labels/86_1.png new file mode 100644 index 0000000..7de1777 Binary files /dev/null and b/data/labels/86_1.png differ diff --git a/data/labels/86_2.png b/data/labels/86_2.png new file mode 100644 index 0000000..aae67da Binary files /dev/null and b/data/labels/86_2.png differ diff --git a/data/labels/86_3.png b/data/labels/86_3.png new file mode 100644 index 0000000..e932d2e Binary files /dev/null and b/data/labels/86_3.png differ diff --git a/data/labels/86_4.png b/data/labels/86_4.png new file mode 100644 index 0000000..9a580c8 Binary files /dev/null and b/data/labels/86_4.png differ diff --git a/data/labels/86_5.png b/data/labels/86_5.png new file mode 100644 index 0000000..6766a5d Binary files /dev/null and b/data/labels/86_5.png differ diff --git a/data/labels/86_6.png b/data/labels/86_6.png new file mode 100644 index 0000000..462e729 Binary files /dev/null and b/data/labels/86_6.png differ diff --git a/data/labels/86_7.png b/data/labels/86_7.png new file mode 100644 index 0000000..7843c12 Binary files /dev/null and b/data/labels/86_7.png differ diff --git a/data/labels/87_0.png b/data/labels/87_0.png new file mode 100644 index 0000000..e7c1285 Binary files /dev/null and b/data/labels/87_0.png differ diff --git a/data/labels/87_1.png b/data/labels/87_1.png new file mode 100644 index 0000000..e0af6e0 Binary files /dev/null and b/data/labels/87_1.png differ diff --git a/data/labels/87_2.png b/data/labels/87_2.png new file mode 100644 index 0000000..4bdce94 Binary files /dev/null and b/data/labels/87_2.png differ diff --git a/data/labels/87_3.png b/data/labels/87_3.png new file mode 100644 index 0000000..2d446b9 Binary files /dev/null and b/data/labels/87_3.png differ diff --git a/data/labels/87_4.png b/data/labels/87_4.png new file mode 100644 index 0000000..2719131 Binary files /dev/null and b/data/labels/87_4.png differ diff --git a/data/labels/87_5.png b/data/labels/87_5.png new file mode 100644 index 0000000..f635def Binary files /dev/null and b/data/labels/87_5.png differ diff --git a/data/labels/87_6.png b/data/labels/87_6.png new file mode 100644 index 0000000..25ddeb7 Binary files /dev/null and b/data/labels/87_6.png differ diff --git a/data/labels/87_7.png b/data/labels/87_7.png new file mode 100644 index 0000000..b26e702 Binary files /dev/null and b/data/labels/87_7.png differ diff --git a/data/labels/88_0.png b/data/labels/88_0.png new file mode 100644 index 0000000..43b1427 Binary files /dev/null and b/data/labels/88_0.png differ diff --git a/data/labels/88_1.png b/data/labels/88_1.png new file mode 100644 index 0000000..5703b63 Binary files /dev/null and b/data/labels/88_1.png differ diff --git a/data/labels/88_2.png b/data/labels/88_2.png new file mode 100644 index 0000000..b3b565a Binary files /dev/null and b/data/labels/88_2.png differ diff --git a/data/labels/88_3.png b/data/labels/88_3.png new file mode 100644 index 0000000..4afd6dd Binary files /dev/null and b/data/labels/88_3.png differ diff --git a/data/labels/88_4.png b/data/labels/88_4.png new file mode 100644 index 0000000..198f7b0 Binary files /dev/null and b/data/labels/88_4.png differ diff --git a/data/labels/88_5.png b/data/labels/88_5.png new file mode 100644 index 0000000..e46b641 Binary files /dev/null and b/data/labels/88_5.png differ diff --git a/data/labels/88_6.png b/data/labels/88_6.png new file mode 100644 index 0000000..81830a0 Binary files /dev/null and b/data/labels/88_6.png differ diff --git a/data/labels/88_7.png b/data/labels/88_7.png new file mode 100644 index 0000000..a916e4e Binary files /dev/null and b/data/labels/88_7.png differ diff --git a/data/labels/89_0.png b/data/labels/89_0.png new file mode 100644 index 0000000..b6f9c4b Binary files /dev/null and b/data/labels/89_0.png differ diff --git a/data/labels/89_1.png b/data/labels/89_1.png new file mode 100644 index 0000000..e5e7a1e Binary files /dev/null and b/data/labels/89_1.png differ diff --git a/data/labels/89_2.png b/data/labels/89_2.png new file mode 100644 index 0000000..9f9d361 Binary files /dev/null and b/data/labels/89_2.png differ diff --git a/data/labels/89_3.png b/data/labels/89_3.png new file mode 100644 index 0000000..4404891 Binary files /dev/null and b/data/labels/89_3.png differ diff --git a/data/labels/89_4.png b/data/labels/89_4.png new file mode 100644 index 0000000..802bfe4 Binary files /dev/null and b/data/labels/89_4.png differ diff --git a/data/labels/89_5.png b/data/labels/89_5.png new file mode 100644 index 0000000..d77e019 Binary files /dev/null and b/data/labels/89_5.png differ diff --git a/data/labels/89_6.png b/data/labels/89_6.png new file mode 100644 index 0000000..4a4fa6b Binary files /dev/null and b/data/labels/89_6.png differ diff --git a/data/labels/89_7.png b/data/labels/89_7.png new file mode 100644 index 0000000..b3dd798 Binary files /dev/null and b/data/labels/89_7.png differ diff --git a/data/labels/90_0.png b/data/labels/90_0.png new file mode 100644 index 0000000..3e10db1 Binary files /dev/null and b/data/labels/90_0.png differ diff --git a/data/labels/90_1.png b/data/labels/90_1.png new file mode 100644 index 0000000..9c4e67e Binary files /dev/null and b/data/labels/90_1.png differ diff --git a/data/labels/90_2.png b/data/labels/90_2.png new file mode 100644 index 0000000..92d0167 Binary files /dev/null and b/data/labels/90_2.png differ diff --git a/data/labels/90_3.png b/data/labels/90_3.png new file mode 100644 index 0000000..9d346a2 Binary files /dev/null and b/data/labels/90_3.png differ diff --git a/data/labels/90_4.png b/data/labels/90_4.png new file mode 100644 index 0000000..ba6012b Binary files /dev/null and b/data/labels/90_4.png differ diff --git a/data/labels/90_5.png b/data/labels/90_5.png new file mode 100644 index 0000000..b664cd2 Binary files /dev/null and b/data/labels/90_5.png differ diff --git a/data/labels/90_6.png b/data/labels/90_6.png new file mode 100644 index 0000000..500c099 Binary files /dev/null and b/data/labels/90_6.png differ diff --git a/data/labels/90_7.png b/data/labels/90_7.png new file mode 100644 index 0000000..3e899a8 Binary files /dev/null and b/data/labels/90_7.png differ diff --git a/data/labels/91_0.png b/data/labels/91_0.png new file mode 100644 index 0000000..0ad0d55 Binary files /dev/null and b/data/labels/91_0.png differ diff --git a/data/labels/91_1.png b/data/labels/91_1.png new file mode 100644 index 0000000..afbe0f0 Binary files /dev/null and b/data/labels/91_1.png differ diff --git a/data/labels/91_2.png b/data/labels/91_2.png new file mode 100644 index 0000000..d2c8899 Binary files /dev/null and b/data/labels/91_2.png differ diff --git a/data/labels/91_3.png b/data/labels/91_3.png new file mode 100644 index 0000000..002032d Binary files /dev/null and b/data/labels/91_3.png differ diff --git a/data/labels/91_4.png b/data/labels/91_4.png new file mode 100644 index 0000000..795ce7d Binary files /dev/null and b/data/labels/91_4.png differ diff --git a/data/labels/91_5.png b/data/labels/91_5.png new file mode 100644 index 0000000..1d1eb22 Binary files /dev/null and b/data/labels/91_5.png differ diff --git a/data/labels/91_6.png b/data/labels/91_6.png new file mode 100644 index 0000000..bb31267 Binary files /dev/null and b/data/labels/91_6.png differ diff --git a/data/labels/91_7.png b/data/labels/91_7.png new file mode 100644 index 0000000..70c2cf3 Binary files /dev/null and b/data/labels/91_7.png differ diff --git a/data/labels/92_0.png b/data/labels/92_0.png new file mode 100644 index 0000000..e730aed Binary files /dev/null and b/data/labels/92_0.png differ diff --git a/data/labels/92_1.png b/data/labels/92_1.png new file mode 100644 index 0000000..7f9b51d Binary files /dev/null and b/data/labels/92_1.png differ diff --git a/data/labels/92_2.png b/data/labels/92_2.png new file mode 100644 index 0000000..f01916f Binary files /dev/null and b/data/labels/92_2.png differ diff --git a/data/labels/92_3.png b/data/labels/92_3.png new file mode 100644 index 0000000..b850533 Binary files /dev/null and b/data/labels/92_3.png differ diff --git a/data/labels/92_4.png b/data/labels/92_4.png new file mode 100644 index 0000000..ece1682 Binary files /dev/null and b/data/labels/92_4.png differ diff --git a/data/labels/92_5.png b/data/labels/92_5.png new file mode 100644 index 0000000..8216690 Binary files /dev/null and b/data/labels/92_5.png differ diff --git a/data/labels/92_6.png b/data/labels/92_6.png new file mode 100644 index 0000000..9b581fa Binary files /dev/null and b/data/labels/92_6.png differ diff --git a/data/labels/92_7.png b/data/labels/92_7.png new file mode 100644 index 0000000..e57b2e8 Binary files /dev/null and b/data/labels/92_7.png differ diff --git a/data/labels/93_0.png b/data/labels/93_0.png new file mode 100644 index 0000000..c21f522 Binary files /dev/null and b/data/labels/93_0.png differ diff --git a/data/labels/93_1.png b/data/labels/93_1.png new file mode 100644 index 0000000..64cbba6 Binary files /dev/null and b/data/labels/93_1.png differ diff --git a/data/labels/93_2.png b/data/labels/93_2.png new file mode 100644 index 0000000..a81e1cd Binary files /dev/null and b/data/labels/93_2.png differ diff --git a/data/labels/93_3.png b/data/labels/93_3.png new file mode 100644 index 0000000..273f35c Binary files /dev/null and b/data/labels/93_3.png differ diff --git a/data/labels/93_4.png b/data/labels/93_4.png new file mode 100644 index 0000000..b44e4c6 Binary files /dev/null and b/data/labels/93_4.png differ diff --git a/data/labels/93_5.png b/data/labels/93_5.png new file mode 100644 index 0000000..1e96e9b Binary files /dev/null and b/data/labels/93_5.png differ diff --git a/data/labels/93_6.png b/data/labels/93_6.png new file mode 100644 index 0000000..3407e55 Binary files /dev/null and b/data/labels/93_6.png differ diff --git a/data/labels/93_7.png b/data/labels/93_7.png new file mode 100644 index 0000000..428e072 Binary files /dev/null and b/data/labels/93_7.png differ diff --git a/data/labels/94_0.png b/data/labels/94_0.png new file mode 100644 index 0000000..baa512b Binary files /dev/null and b/data/labels/94_0.png differ diff --git a/data/labels/94_1.png b/data/labels/94_1.png new file mode 100644 index 0000000..5f1b116 Binary files /dev/null and b/data/labels/94_1.png differ diff --git a/data/labels/94_2.png b/data/labels/94_2.png new file mode 100644 index 0000000..1cd051e Binary files /dev/null and b/data/labels/94_2.png differ diff --git a/data/labels/94_3.png b/data/labels/94_3.png new file mode 100644 index 0000000..a0a7264 Binary files /dev/null and b/data/labels/94_3.png differ diff --git a/data/labels/94_4.png b/data/labels/94_4.png new file mode 100644 index 0000000..26e82bc Binary files /dev/null and b/data/labels/94_4.png differ diff --git a/data/labels/94_5.png b/data/labels/94_5.png new file mode 100644 index 0000000..19c32ec Binary files /dev/null and b/data/labels/94_5.png differ diff --git a/data/labels/94_6.png b/data/labels/94_6.png new file mode 100644 index 0000000..e753cad Binary files /dev/null and b/data/labels/94_6.png differ diff --git a/data/labels/94_7.png b/data/labels/94_7.png new file mode 100644 index 0000000..7d4dfb7 Binary files /dev/null and b/data/labels/94_7.png differ diff --git a/data/labels/95_0.png b/data/labels/95_0.png new file mode 100644 index 0000000..2b25519 Binary files /dev/null and b/data/labels/95_0.png differ diff --git a/data/labels/95_1.png b/data/labels/95_1.png new file mode 100644 index 0000000..6fea8c2 Binary files /dev/null and b/data/labels/95_1.png differ diff --git a/data/labels/95_2.png b/data/labels/95_2.png new file mode 100644 index 0000000..d170be1 Binary files /dev/null and b/data/labels/95_2.png differ diff --git a/data/labels/95_3.png b/data/labels/95_3.png new file mode 100644 index 0000000..fe5501e Binary files /dev/null and b/data/labels/95_3.png differ diff --git a/data/labels/95_4.png b/data/labels/95_4.png new file mode 100644 index 0000000..ec87fee Binary files /dev/null and b/data/labels/95_4.png differ diff --git a/data/labels/95_5.png b/data/labels/95_5.png new file mode 100644 index 0000000..efa9f0b Binary files /dev/null and b/data/labels/95_5.png differ diff --git a/data/labels/95_6.png b/data/labels/95_6.png new file mode 100644 index 0000000..6840b82 Binary files /dev/null and b/data/labels/95_6.png differ diff --git a/data/labels/95_7.png b/data/labels/95_7.png new file mode 100644 index 0000000..85f887d Binary files /dev/null and b/data/labels/95_7.png differ diff --git a/data/labels/96_0.png b/data/labels/96_0.png new file mode 100644 index 0000000..2033d9b Binary files /dev/null and b/data/labels/96_0.png differ diff --git a/data/labels/96_1.png b/data/labels/96_1.png new file mode 100644 index 0000000..c60d36a Binary files /dev/null and b/data/labels/96_1.png differ diff --git a/data/labels/96_2.png b/data/labels/96_2.png new file mode 100644 index 0000000..878dd1b Binary files /dev/null and b/data/labels/96_2.png differ diff --git a/data/labels/96_3.png b/data/labels/96_3.png new file mode 100644 index 0000000..f7429a2 Binary files /dev/null and b/data/labels/96_3.png differ diff --git a/data/labels/96_4.png b/data/labels/96_4.png new file mode 100644 index 0000000..6dff9da Binary files /dev/null and b/data/labels/96_4.png differ diff --git a/data/labels/96_5.png b/data/labels/96_5.png new file mode 100644 index 0000000..4869f9d Binary files /dev/null and b/data/labels/96_5.png differ diff --git a/data/labels/96_6.png b/data/labels/96_6.png new file mode 100644 index 0000000..f6a8a69 Binary files /dev/null and b/data/labels/96_6.png differ diff --git a/data/labels/96_7.png b/data/labels/96_7.png new file mode 100644 index 0000000..89b19d4 Binary files /dev/null and b/data/labels/96_7.png differ diff --git a/data/labels/97_0.png b/data/labels/97_0.png new file mode 100644 index 0000000..6426224 Binary files /dev/null and b/data/labels/97_0.png differ diff --git a/data/labels/97_1.png b/data/labels/97_1.png new file mode 100644 index 0000000..f9a61f4 Binary files /dev/null and b/data/labels/97_1.png differ diff --git a/data/labels/97_2.png b/data/labels/97_2.png new file mode 100644 index 0000000..d1d02ac Binary files /dev/null and b/data/labels/97_2.png differ diff --git a/data/labels/97_3.png b/data/labels/97_3.png new file mode 100644 index 0000000..7e9e936 Binary files /dev/null and b/data/labels/97_3.png differ diff --git a/data/labels/97_4.png b/data/labels/97_4.png new file mode 100644 index 0000000..21dd17e Binary files /dev/null and b/data/labels/97_4.png differ diff --git a/data/labels/97_5.png b/data/labels/97_5.png new file mode 100644 index 0000000..5e59fa2 Binary files /dev/null and b/data/labels/97_5.png differ diff --git a/data/labels/97_6.png b/data/labels/97_6.png new file mode 100644 index 0000000..6f279a4 Binary files /dev/null and b/data/labels/97_6.png differ diff --git a/data/labels/97_7.png b/data/labels/97_7.png new file mode 100644 index 0000000..6447e6d Binary files /dev/null and b/data/labels/97_7.png differ diff --git a/data/labels/98_0.png b/data/labels/98_0.png new file mode 100644 index 0000000..3d25931 Binary files /dev/null and b/data/labels/98_0.png differ diff --git a/data/labels/98_1.png b/data/labels/98_1.png new file mode 100644 index 0000000..c76706a Binary files /dev/null and b/data/labels/98_1.png differ diff --git a/data/labels/98_2.png b/data/labels/98_2.png new file mode 100644 index 0000000..6dceadb Binary files /dev/null and b/data/labels/98_2.png differ diff --git a/data/labels/98_3.png b/data/labels/98_3.png new file mode 100644 index 0000000..d3cf1bc Binary files /dev/null and b/data/labels/98_3.png differ diff --git a/data/labels/98_4.png b/data/labels/98_4.png new file mode 100644 index 0000000..5d5addc Binary files /dev/null and b/data/labels/98_4.png differ diff --git a/data/labels/98_5.png b/data/labels/98_5.png new file mode 100644 index 0000000..55479d9 Binary files /dev/null and b/data/labels/98_5.png differ diff --git a/data/labels/98_6.png b/data/labels/98_6.png new file mode 100644 index 0000000..4d8f3d9 Binary files /dev/null and b/data/labels/98_6.png differ diff --git a/data/labels/98_7.png b/data/labels/98_7.png new file mode 100644 index 0000000..cec6017 Binary files /dev/null and b/data/labels/98_7.png differ diff --git a/data/labels/99_0.png b/data/labels/99_0.png new file mode 100644 index 0000000..f5975c9 Binary files /dev/null and b/data/labels/99_0.png differ diff --git a/data/labels/99_1.png b/data/labels/99_1.png new file mode 100644 index 0000000..3cdfdec Binary files /dev/null and b/data/labels/99_1.png differ diff --git a/data/labels/99_2.png b/data/labels/99_2.png new file mode 100644 index 0000000..a0dc573 Binary files /dev/null and b/data/labels/99_2.png differ diff --git a/data/labels/99_3.png b/data/labels/99_3.png new file mode 100644 index 0000000..e183f6a Binary files /dev/null and b/data/labels/99_3.png differ diff --git a/data/labels/99_4.png b/data/labels/99_4.png new file mode 100644 index 0000000..bc1a490 Binary files /dev/null and b/data/labels/99_4.png differ diff --git a/data/labels/99_5.png b/data/labels/99_5.png new file mode 100644 index 0000000..c568d5e Binary files /dev/null and b/data/labels/99_5.png differ diff --git a/data/labels/99_6.png b/data/labels/99_6.png new file mode 100644 index 0000000..e274446 Binary files /dev/null and b/data/labels/99_6.png differ diff --git a/data/labels/99_7.png b/data/labels/99_7.png new file mode 100644 index 0000000..f7b9e09 Binary files /dev/null and b/data/labels/99_7.png differ diff --git a/data/labels/make_labels.py b/data/labels/make_labels.py new file mode 100644 index 0000000..c8146f6 --- /dev/null +++ b/data/labels/make_labels.py @@ -0,0 +1,23 @@ +import os +import string +import pipes + +font = 'futura-normal' + +def make_labels(s): + l = string.printable + for word in l: + if word == ' ': + os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\ " 32_%d.png'%(font,s,s/12-1)) + if word == '@': + os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\@" 64_%d.png'%(font,s,s/12-1)) + elif word == '\\': + os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\\\\\\\\" 92_%d.png'%(font,s,s/12-1)) + elif ord(word) in [9,10,11,12,13,14]: + pass + else: + os.system("convert -fill black -background white -bordercolor white -font %s -pointsize %d label:%s \"%d_%d.png\""%(font,s,pipes.quote(word), ord(word),s/12-1)) + +for i in [12,24,36,48,60,72,84,96]: + make_labels(i) + diff --git a/data/openimages.names b/data/openimages.names new file mode 100644 index 0000000..ddfd8f2 --- /dev/null +++ b/data/openimages.names @@ -0,0 +1,601 @@ +Tortoise +Container +Magpie +Sea turtle +Football +Ambulance +Ladder +Toothbrush +Syringe +Sink +Toy +Organ +Cassette deck +Apple +Human eye +Cosmetics +Paddle +Snowman +Beer +Chopsticks +Human beard +Bird +Parking meter +Traffic light +Croissant +Cucumber +Radish +Towel +Doll +Skull +Washing machine +Glove +Tick +Belt +Sunglasses +Banjo +Cart +Ball +Backpack +Bicycle +Home appliance +Centipede +Boat +Surfboard +Boot +Headphones +Hot dog +Shorts +Fast food +Bus +Boy +Screwdriver +Bicycle wheel +Barge +Laptop +Miniskirt +Drill +Dress +Bear +Waffle +Pancake +Brown bear +Woodpecker +Blue jay +Pretzel +Bagel +Tower +Teapot +Person +Bow and arrow +Swimwear +Beehive +Brassiere +Bee +Bat +Starfish +Popcorn +Burrito +Chainsaw +Balloon +Wrench +Tent +Vehicle registration plate +Lantern +Toaster +Flashlight +Billboard +Tiara +Limousine +Necklace +Carnivore +Scissors +Stairs +Computer keyboard +Printer +Traffic sign +Chair +Shirt +Poster +Cheese +Sock +Fire hydrant +Land vehicle +Earrings +Tie +Watercraft +Cabinetry +Suitcase +Muffin +Bidet +Snack +Snowmobile +Clock +Medical equipment +Cattle +Cello +Jet ski +Camel +Coat +Suit +Desk +Cat +Bronze sculpture +Juice +Gondola +Beetle +Cannon +Computer mouse +Cookie +Office building +Fountain +Coin +Calculator +Cocktail +Computer monitor +Box +Stapler +Christmas tree +Cowboy hat +Hiking equipment +Studio couch +Drum +Dessert +Wine rack +Drink +Zucchini +Ladle +Human mouth +Dairy +Dice +Oven +Dinosaur +Ratchet +Couch +Cricket ball +Winter melon +Spatula +Whiteboard +Pencil sharpener +Door +Hat +Shower +Eraser +Fedora +Guacamole +Dagger +Scarf +Dolphin +Sombrero +Tin can +Mug +Tap +Harbor seal +Stretcher +Can opener +Goggles +Human body +Roller skates +Coffee cup +Cutting board +Blender +Plumbing fixture +Stop sign +Office supplies +Volleyball +Vase +Slow cooker +Wardrobe +Coffee +Whisk +Paper towel +Personal care +Food +Sun hat +Tree house +Flying disc +Skirt +Gas stove +Salt and pepper shakers +Mechanical fan +Face powder +Fax +Fruit +French fries +Nightstand +Barrel +Kite +Tart +Treadmill +Fox +Flag +Horn +Window blind +Human foot +Golf cart +Jacket +Egg +Street light +Guitar +Pillow +Human leg +Isopod +Grape +Human ear +Power plugs and sockets +Panda +Giraffe +Woman +Door handle +Rhinoceros +Bathtub +Goldfish +Houseplant +Goat +Baseball bat +Baseball glove +Mixing bowl +Marine invertebrates +Kitchen utensil +Light switch +House +Horse +Stationary bicycle +Hammer +Ceiling fan +Sofa bed +Adhesive tape +Harp +Sandal +Bicycle helmet +Saucer +Harpsichord +Human hair +Heater +Harmonica +Hamster +Curtain +Bed +Kettle +Fireplace +Scale +Drinking straw +Insect +Hair dryer +Kitchenware +Indoor rower +Invertebrate +Food processor +Bookcase +Refrigerator +Wood-burning stove +Punching bag +Common fig +Cocktail shaker +Jaguar +Golf ball +Fashion accessory +Alarm clock +Filing cabinet +Artichoke +Table +Tableware +Kangaroo +Koala +Knife +Bottle +Bottle opener +Lynx +Lavender +Lighthouse +Dumbbell +Human head +Bowl +Humidifier +Porch +Lizard +Billiard table +Mammal +Mouse +Motorcycle +Musical instrument +Swim cap +Frying pan +Snowplow +Bathroom cabinet +Missile +Bust +Man +Waffle iron +Milk +Ring binder +Plate +Mobile phone +Baked goods +Mushroom +Crutch +Pitcher +Mirror +Lifejacket +Table tennis racket +Pencil case +Musical keyboard +Scoreboard +Briefcase +Kitchen knife +Nail +Tennis ball +Plastic bag +Oboe +Chest of drawers +Ostrich +Piano +Girl +Plant +Potato +Hair spray +Sports equipment +Pasta +Penguin +Pumpkin +Pear +Infant bed +Polar bear +Mixer +Cupboard +Jacuzzi +Pizza +Digital clock +Pig +Reptile +Rifle +Lipstick +Skateboard +Raven +High heels +Red panda +Rose +Rabbit +Sculpture +Saxophone +Shotgun +Seafood +Submarine sandwich +Snowboard +Sword +Picture frame +Sushi +Loveseat +Ski +Squirrel +Tripod +Stethoscope +Submarine +Scorpion +Segway +Training bench +Snake +Coffee table +Skyscraper +Sheep +Television +Trombone +Tea +Tank +Taco +Telephone +Torch +Tiger +Strawberry +Trumpet +Tree +Tomato +Train +Tool +Picnic basket +Cooking spray +Trousers +Bowling equipment +Football helmet +Truck +Measuring cup +Coffeemaker +Violin +Vehicle +Handbag +Paper cutter +Wine +Weapon +Wheel +Worm +Wok +Whale +Zebra +Auto part +Jug +Pizza cutter +Cream +Monkey +Lion +Bread +Platter +Chicken +Eagle +Helicopter +Owl +Duck +Turtle +Hippopotamus +Crocodile +Toilet +Toilet paper +Squid +Clothing +Footwear +Lemon +Spider +Deer +Frog +Banana +Rocket +Wine glass +Countertop +Tablet computer +Waste container +Swimming pool +Dog +Book +Elephant +Shark +Candle +Leopard +Axe +Hand dryer +Soap dispenser +Porcupine +Flower +Canary +Cheetah +Palm tree +Hamburger +Maple +Building +Fish +Lobster +Asparagus +Furniture +Hedgehog +Airplane +Spoon +Otter +Bull +Oyster +Horizontal bar +Convenience store +Bomb +Bench +Ice cream +Caterpillar +Butterfly +Parachute +Orange +Antelope +Beaker +Moths and butterflies +Window +Closet +Castle +Jellyfish +Goose +Mule +Swan +Peach +Coconut +Seat belt +Raccoon +Chisel +Fork +Lamp +Camera +Squash +Racket +Human face +Human arm +Vegetable +Diaper +Unicycle +Falcon +Chime +Snail +Shellfish +Cabbage +Carrot +Mango +Jeans +Flowerpot +Pineapple +Drawer +Stool +Envelope +Cake +Dragonfly +Sunflower +Microwave oven +Honeycomb +Marine mammal +Sea lion +Ladybug +Shelf +Watch +Candy +Salad +Parrot +Handgun +Sparrow +Van +Grinder +Spice rack +Light bulb +Corded phone +Sports uniform +Tennis racket +Wall clock +Serving tray +Kitchen & dining room table +Dog bed +Cake stand +Cat furniture +Bathroom accessory +Facial tissue holder +Pressure cooker +Kitchen appliance +Tire +Ruler +Luggage and bags +Microphone +Broccoli +Umbrella +Pastry +Grapefruit +Band-aid +Animal +Bell pepper +Turkey +Lily +Pomegranate +Doughnut +Glasses +Human nose +Pen +Ant +Car +Aircraft +Human hand +Skunk +Teddy bear +Watermelon +Cantaloupe +Dishwasher +Flute +Balance beam +Sandwich +Shrimp +Sewing machine +Binoculars +Rays and skates +Ipod +Accordion +Willow +Crab +Crown +Seahorse +Perfume +Alpaca +Taxi +Canoe +Remote control +Wheelchair +Rugby ball +Armadillo +Maracas +Helmet diff --git a/data/person.jpg b/data/person.jpg new file mode 100644 index 0000000..61d377f Binary files /dev/null and b/data/person.jpg differ diff --git a/data/scream.jpg b/data/scream.jpg new file mode 100644 index 0000000..43f2c36 Binary files /dev/null and b/data/scream.jpg differ diff --git a/data/voc.names b/data/voc.names new file mode 100644 index 0000000..8420ab3 --- /dev/null +++ b/data/voc.names @@ -0,0 +1,20 @@ +aeroplane +bicycle +bird +boat +bottle +bus +car +cat +chair +cow +diningtable +dog +horse +motorbike +person +pottedplant +sheep +sofa +train +tvmonitor diff --git a/freetype/include/freetype2/freetype/config/ftconfig.h b/freetype/include/freetype2/freetype/config/ftconfig.h new file mode 100644 index 0000000..fd0f0ba --- /dev/null +++ b/freetype/include/freetype2/freetype/config/ftconfig.h @@ -0,0 +1,603 @@ +/* ftconfig.h. Generated from ftconfig.in by configure. */ +/***************************************************************************/ +/* */ +/* ftconfig.in */ +/* */ +/* UNIX-specific configuration file (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This header file contains a number of macro definitions that are used */ + /* by the rest of the engine. Most of the macros here are automatically */ + /* determined at compile time, and you should not need to change it to */ + /* port FreeType, except to compile the library with a non-ANSI */ + /* compiler. */ + /* */ + /* Note however that if some specific modifications are needed, we */ + /* advise you to place a modified copy in your build directory. */ + /* */ + /* The build directory is usually `builds/', and contains */ + /* system-specific files that are always included first when building */ + /* the library. */ + /* */ + /*************************************************************************/ + + +#ifndef FTCONFIG_H_ +#define FTCONFIG_H_ + +#include +#include FT_CONFIG_OPTIONS_H +#include FT_CONFIG_STANDARD_LIBRARY_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* PLATFORM-SPECIFIC CONFIGURATION MACROS */ + /* */ + /* These macros can be toggled to suit a specific system. The current */ + /* ones are defaults used to compile FreeType in an ANSI C environment */ + /* (16bit compilers are also supported). Copy this file to your own */ + /* `builds/' directory, and edit it to port the engine. */ + /* */ + /*************************************************************************/ + + +#define HAVE_UNISTD_H 1 +#define HAVE_FCNTL_H 1 +#define HAVE_STDINT_H 1 + + + /* There are systems (like the Texas Instruments 'C54x) where a `char' */ + /* has 16 bits. ANSI C says that sizeof(char) is always 1. Since an */ + /* `int' has 16 bits also for this system, sizeof(int) gives 1 which */ + /* is probably unexpected. */ + /* */ + /* `CHAR_BIT' (defined in limits.h) gives the number of bits in a */ + /* `char' type. */ + +#ifndef FT_CHAR_BIT +#define FT_CHAR_BIT CHAR_BIT +#endif + + +/* #undef FT_USE_AUTOCONF_SIZEOF_TYPES */ +#ifdef FT_USE_AUTOCONF_SIZEOF_TYPES + +#define SIZEOF_INT 4 +#define SIZEOF_LONG 8 +#define FT_SIZEOF_INT SIZEOF_INT +#define FT_SIZEOF_LONG SIZEOF_LONG + +#else /* !FT_USE_AUTOCONF_SIZEOF_TYPES */ + + /* Following cpp computation of the bit length of int and long */ + /* is copied from default include/freetype/config/ftconfig.h. */ + /* If any improvement is required for this file, it should be */ + /* applied to the original header file for the builders that */ + /* do not use configure script. */ + + /* The size of an `int' type. */ +#if FT_UINT_MAX == 0xFFFFUL +#define FT_SIZEOF_INT (16 / FT_CHAR_BIT) +#elif FT_UINT_MAX == 0xFFFFFFFFUL +#define FT_SIZEOF_INT (32 / FT_CHAR_BIT) +#elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL +#define FT_SIZEOF_INT (64 / FT_CHAR_BIT) +#else +#error "Unsupported size of `int' type!" +#endif + + /* The size of a `long' type. A five-byte `long' (as used e.g. on the */ + /* DM642) is recognized but avoided. */ +#if FT_ULONG_MAX == 0xFFFFFFFFUL +#define FT_SIZEOF_LONG (32 / FT_CHAR_BIT) +#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL +#define FT_SIZEOF_LONG (32 / FT_CHAR_BIT) +#elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL +#define FT_SIZEOF_LONG (64 / FT_CHAR_BIT) +#else +#error "Unsupported size of `long' type!" +#endif + +#endif /* !FT_USE_AUTOCONF_SIZEOF_TYPES */ + + + /* FT_UNUSED is a macro used to indicate that a given parameter is not */ + /* used -- this is only used to get rid of unpleasant compiler warnings */ +#ifndef FT_UNUSED +#define FT_UNUSED( arg ) ( (arg) = (arg) ) +#endif + + + /*************************************************************************/ + /* */ + /* AUTOMATIC CONFIGURATION MACROS */ + /* */ + /* These macros are computed from the ones defined above. Don't touch */ + /* their definition, unless you know precisely what you are doing. No */ + /* porter should need to mess with them. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Mac support */ + /* */ + /* This is the only necessary change, so it is defined here instead */ + /* providing a new configuration file. */ + /* */ +#if defined( __APPLE__ ) || ( defined( __MWERKS__ ) && defined( macintosh ) ) + /* no Carbon frameworks for 64bit 10.4.x */ + /* AvailabilityMacros.h is available since Mac OS X 10.2, */ + /* so guess the system version by maximum errno before inclusion */ +#include +#ifdef ECANCELED /* defined since 10.2 */ +#include "AvailabilityMacros.h" +#endif +#if defined( __LP64__ ) && \ + ( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 ) +#undef FT_MACINTOSH +#endif + +#elif defined( __SC__ ) || defined( __MRC__ ) + /* Classic MacOS compilers */ +#include "ConditionalMacros.h" +#if TARGET_OS_MAC +#define FT_MACINTOSH 1 +#endif + +#endif + + + /* Fix compiler warning with sgi compiler */ +#if defined( __sgi ) && !defined( __GNUC__ ) +#if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 ) +#pragma set woff 3505 +#endif +#endif + + + /*************************************************************************/ + /* */ + /*
*/ + /* basic_types */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Int16 */ + /* */ + /* */ + /* A typedef for a 16bit signed integer type. */ + /* */ + typedef signed short FT_Int16; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_UInt16 */ + /* */ + /* */ + /* A typedef for a 16bit unsigned integer type. */ + /* */ + typedef unsigned short FT_UInt16; + + /* */ + + + /* this #if 0 ... #endif clause is for documentation purposes */ +#if 0 + + /*************************************************************************/ + /* */ + /* */ + /* FT_Int32 */ + /* */ + /* */ + /* A typedef for a 32bit signed integer type. The size depends on */ + /* the configuration. */ + /* */ + typedef signed XXX FT_Int32; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_UInt32 */ + /* */ + /* A typedef for a 32bit unsigned integer type. The size depends on */ + /* the configuration. */ + /* */ + typedef unsigned XXX FT_UInt32; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_Int64 */ + /* */ + /* A typedef for a 64bit signed integer type. The size depends on */ + /* the configuration. Only defined if there is real 64bit support; */ + /* otherwise, it gets emulated with a structure (if necessary). */ + /* */ + typedef signed XXX FT_Int64; + + + /*************************************************************************/ + /* */ + /* */ + /* FT_UInt64 */ + /* */ + /* A typedef for a 64bit unsigned integer type. The size depends on */ + /* the configuration. Only defined if there is real 64bit support; */ + /* otherwise, it gets emulated with a structure (if necessary). */ + /* */ + typedef unsigned XXX FT_UInt64; + + /* */ + +#endif + +#if FT_SIZEOF_INT == 4 + + typedef signed int FT_Int32; + typedef unsigned int FT_UInt32; + +#elif FT_SIZEOF_LONG == 4 + + typedef signed long FT_Int32; + typedef unsigned long FT_UInt32; + +#else +#error "no 32bit type found -- please check your configuration files" +#endif + + + /* look up an integer type that is at least 32 bits */ +#if FT_SIZEOF_INT >= 4 + + typedef int FT_Fast; + typedef unsigned int FT_UFast; + +#elif FT_SIZEOF_LONG >= 4 + + typedef long FT_Fast; + typedef unsigned long FT_UFast; + +#endif + + + /* determine whether we have a 64-bit int type */ + /* (mostly for environments without `autoconf') */ +#if FT_SIZEOF_LONG == 8 + + /* FT_LONG64 must be defined if a 64-bit type is available */ +#define FT_LONG64 +#define FT_INT64 long +#define FT_UINT64 unsigned long + + /* we handle the LLP64 scheme separately for GCC and clang, */ + /* suppressing the `long long' warning */ +#elif ( FT_SIZEOF_LONG == 4 ) && \ + defined( HAVE_LONG_LONG_INT ) && \ + defined( __GNUC__ ) +#pragma GCC diagnostic ignored "-Wlong-long" +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + + /*************************************************************************/ + /* */ + /* A 64-bit data type may create compilation problems if you compile */ + /* in strict ANSI mode. To avoid them, we disable other 64-bit data */ + /* types if __STDC__ is defined. You can however ignore this rule */ + /* by defining the FT_CONFIG_OPTION_FORCE_INT64 configuration macro. */ + /* */ +#elif !defined( __STDC__ ) || defined( FT_CONFIG_OPTION_FORCE_INT64 ) + +#if defined( __STDC_VERSION__ ) && __STDC_VERSION__ >= 199901L + +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + +#elif defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */ + + /* this compiler provides the __int64 type */ +#define FT_LONG64 +#define FT_INT64 __int64 +#define FT_UINT64 unsigned __int64 + +#elif defined( __BORLANDC__ ) /* Borland C++ */ + + /* XXXX: We should probably check the value of __BORLANDC__ in order */ + /* to test the compiler version. */ + + /* this compiler provides the __int64 type */ +#define FT_LONG64 +#define FT_INT64 __int64 +#define FT_UINT64 unsigned __int64 + +#elif defined( __WATCOMC__ ) /* Watcom C++ */ + + /* Watcom doesn't provide 64-bit data types */ + +#elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */ + +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + +#elif defined( __GNUC__ ) + + /* GCC provides the `long long' type */ +#define FT_LONG64 +#define FT_INT64 long long int +#define FT_UINT64 unsigned long long int + +#endif /* __STDC_VERSION__ >= 199901L */ + +#endif /* FT_SIZEOF_LONG == 8 */ + +#ifdef FT_LONG64 + typedef FT_INT64 FT_Int64; + typedef FT_UINT64 FT_UInt64; +#endif + + +#ifdef _WIN64 + /* only 64bit Windows uses the LLP64 data model, i.e., */ + /* 32bit integers, 64bit pointers */ +#define FT_UINT_TO_POINTER( x ) (void*)(unsigned __int64)(x) +#else +#define FT_UINT_TO_POINTER( x ) (void*)(unsigned long)(x) +#endif + + + /*************************************************************************/ + /* */ + /* miscellaneous */ + /* */ + /*************************************************************************/ + + +#define FT_BEGIN_STMNT do { +#define FT_END_STMNT } while ( 0 ) +#define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT + + + /* typeof condition taken from gnulib's `intprops.h' header file */ +#if ( ( defined( __GNUC__ ) && __GNUC__ >= 2 ) || \ + ( defined( __IBMC__ ) && __IBMC__ >= 1210 && \ + defined( __IBM__TYPEOF__ ) ) || \ + ( defined( __SUNPRO_C ) && __SUNPRO_C >= 0x5110 && !__STDC__ ) ) +#define FT_TYPEOF( type ) ( __typeof__ ( type ) ) +#else +#define FT_TYPEOF( type ) /* empty */ +#endif + + + /* Use FT_LOCAL and FT_LOCAL_DEF to declare and define, respectively, */ + /* a function that gets used only within the scope of a module. */ + /* Normally, both the header and source code files for such a */ + /* function are within a single module directory. */ + /* */ + /* Intra-module arrays should be tagged with FT_LOCAL_ARRAY and */ + /* FT_LOCAL_ARRAY_DEF. */ + /* */ +#ifdef FT_MAKE_OPTION_SINGLE_OBJECT + +#define FT_LOCAL( x ) static x +#define FT_LOCAL_DEF( x ) static x + +#else + +#ifdef __cplusplus +#define FT_LOCAL( x ) extern "C" x +#define FT_LOCAL_DEF( x ) extern "C" x +#else +#define FT_LOCAL( x ) extern x +#define FT_LOCAL_DEF( x ) x +#endif + +#endif /* FT_MAKE_OPTION_SINGLE_OBJECT */ + +#define FT_LOCAL_ARRAY( x ) extern const x +#define FT_LOCAL_ARRAY_DEF( x ) const x + + + /* Use FT_BASE and FT_BASE_DEF to declare and define, respectively, */ + /* functions that are used in more than a single module. In the */ + /* current setup this implies that the declaration is in a header */ + /* file in the `include/freetype/internal' directory, and the */ + /* function body is in a file in `src/base'. */ + /* */ +#ifndef FT_BASE + +#ifdef __cplusplus +#define FT_BASE( x ) extern "C" x +#else +#define FT_BASE( x ) extern x +#endif + +#endif /* !FT_BASE */ + + +#ifndef FT_BASE_DEF + +#ifdef __cplusplus +#define FT_BASE_DEF( x ) x +#else +#define FT_BASE_DEF( x ) x +#endif + +#endif /* !FT_BASE_DEF */ + + + /* When compiling FreeType as a DLL or DSO with hidden visibility */ + /* some systems/compilers need a special attribute in front OR after */ + /* the return type of function declarations. */ + /* */ + /* Two macros are used within the FreeType source code to define */ + /* exported library functions: FT_EXPORT and FT_EXPORT_DEF. */ + /* */ + /* FT_EXPORT( return_type ) */ + /* */ + /* is used in a function declaration, as in */ + /* */ + /* FT_EXPORT( FT_Error ) */ + /* FT_Init_FreeType( FT_Library* alibrary ); */ + /* */ + /* */ + /* FT_EXPORT_DEF( return_type ) */ + /* */ + /* is used in a function definition, as in */ + /* */ + /* FT_EXPORT_DEF( FT_Error ) */ + /* FT_Init_FreeType( FT_Library* alibrary ) */ + /* { */ + /* ... some code ... */ + /* return FT_Err_Ok; */ + /* } */ + /* */ + /* You can provide your own implementation of FT_EXPORT and */ + /* FT_EXPORT_DEF here if you want. */ + /* */ + /* To export a variable, use FT_EXPORT_VAR. */ + /* */ +#ifndef FT_EXPORT + +#ifdef FT2_BUILD_LIBRARY + +#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) ) +#define FT_EXPORT( x ) __declspec( dllexport ) x +#elif defined( __GNUC__ ) && __GNUC__ >= 4 +#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x +#elif defined( __cplusplus ) +#define FT_EXPORT( x ) extern "C" x +#else +#define FT_EXPORT( x ) extern x +#endif + +#else + +#if defined( FT2_DLLIMPORT ) +#define FT_EXPORT( x ) __declspec( dllimport ) x +#elif defined( __cplusplus ) +#define FT_EXPORT( x ) extern "C" x +#else +#define FT_EXPORT( x ) extern x +#endif + +#endif + +#endif /* !FT_EXPORT */ + + +#ifndef FT_EXPORT_DEF + +#ifdef __cplusplus +#define FT_EXPORT_DEF( x ) extern "C" x +#else +#define FT_EXPORT_DEF( x ) extern x +#endif + +#endif /* !FT_EXPORT_DEF */ + + +#ifndef FT_EXPORT_VAR + +#ifdef __cplusplus +#define FT_EXPORT_VAR( x ) extern "C" x +#else +#define FT_EXPORT_VAR( x ) extern x +#endif + +#endif /* !FT_EXPORT_VAR */ + + /* The following macros are needed to compile the library with a */ + /* C++ compiler and with 16bit compilers. */ + /* */ + + /* This is special. Within C++, you must specify `extern "C"' for */ + /* functions which are used via function pointers, and you also */ + /* must do that for structures which contain function pointers to */ + /* assure C linkage -- it's not possible to have (local) anonymous */ + /* functions which are accessed by (global) function pointers. */ + /* */ + /* */ + /* FT_CALLBACK_DEF is used to _define_ a callback function, */ + /* located in the same source code file as the structure that uses */ + /* it. */ + /* */ + /* FT_BASE_CALLBACK and FT_BASE_CALLBACK_DEF are used to declare */ + /* and define a callback function, respectively, in a similar way */ + /* as FT_BASE and FT_BASE_DEF work. */ + /* */ + /* FT_CALLBACK_TABLE is used to _declare_ a constant variable that */ + /* contains pointers to callback functions. */ + /* */ + /* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable */ + /* that contains pointers to callback functions. */ + /* */ + /* */ + /* Some 16bit compilers have to redefine these macros to insert */ + /* the infamous `_cdecl' or `__fastcall' declarations. */ + /* */ +#ifndef FT_CALLBACK_DEF +#ifdef __cplusplus +#define FT_CALLBACK_DEF( x ) extern "C" x +#else +#define FT_CALLBACK_DEF( x ) static x +#endif +#endif /* FT_CALLBACK_DEF */ + +#ifndef FT_BASE_CALLBACK +#ifdef __cplusplus +#define FT_BASE_CALLBACK( x ) extern "C" x +#define FT_BASE_CALLBACK_DEF( x ) extern "C" x +#else +#define FT_BASE_CALLBACK( x ) extern x +#define FT_BASE_CALLBACK_DEF( x ) x +#endif +#endif /* FT_BASE_CALLBACK */ + +#ifndef FT_CALLBACK_TABLE +#ifdef __cplusplus +#define FT_CALLBACK_TABLE extern "C" +#define FT_CALLBACK_TABLE_DEF extern "C" +#else +#define FT_CALLBACK_TABLE extern +#define FT_CALLBACK_TABLE_DEF /* nothing */ +#endif +#endif /* FT_CALLBACK_TABLE */ + + +FT_END_HEADER + + +#endif /* FTCONFIG_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/config/ftheader.h b/freetype/include/freetype2/freetype/config/ftheader.h new file mode 100644 index 0000000..702f77c --- /dev/null +++ b/freetype/include/freetype2/freetype/config/ftheader.h @@ -0,0 +1,804 @@ +/***************************************************************************/ +/* */ +/* ftheader.h */ +/* */ +/* Build macros of the FreeType 2 library. */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +#ifndef FTHEADER_H_ +#define FTHEADER_H_ + + + /*@***********************************************************************/ + /* */ + /* */ + /* FT_BEGIN_HEADER */ + /* */ + /* */ + /* This macro is used in association with @FT_END_HEADER in header */ + /* files to ensure that the declarations within are properly */ + /* encapsulated in an `extern "C" { .. }' block when included from a */ + /* C++ compiler. */ + /* */ +#ifdef __cplusplus +#define FT_BEGIN_HEADER extern "C" { +#else +#define FT_BEGIN_HEADER /* nothing */ +#endif + + + /*@***********************************************************************/ + /* */ + /* */ + /* FT_END_HEADER */ + /* */ + /* */ + /* This macro is used in association with @FT_BEGIN_HEADER in header */ + /* files to ensure that the declarations within are properly */ + /* encapsulated in an `extern "C" { .. }' block when included from a */ + /* C++ compiler. */ + /* */ +#ifdef __cplusplus +#define FT_END_HEADER } +#else +#define FT_END_HEADER /* nothing */ +#endif + + + /*************************************************************************/ + /* */ + /* Aliases for the FreeType 2 public and configuration files. */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /*
*/ + /* header_file_macros */ + /* */ + /* */ + /* Header File Macros */ + /* */ + /* <Abstract> */ + /* Macro definitions used to #include specific header files. */ + /* */ + /* <Description> */ + /* The following macros are defined to the name of specific */ + /* FreeType~2 header files. They can be used directly in #include */ + /* statements as in: */ + /* */ + /* { */ + /* #include FT_FREETYPE_H */ + /* #include FT_MULTIPLE_MASTERS_H */ + /* #include FT_GLYPH_H */ + /* } */ + /* */ + /* There are several reasons why we are now using macros to name */ + /* public header files. The first one is that such macros are not */ + /* limited to the infamous 8.3~naming rule required by DOS (and */ + /* `FT_MULTIPLE_MASTERS_H' is a lot more meaningful than `ftmm.h'). */ + /* */ + /* The second reason is that it allows for more flexibility in the */ + /* way FreeType~2 is installed on a given system. */ + /* */ + /*************************************************************************/ + + + /* configuration files */ + + /************************************************************************* + * + * @macro: + * FT_CONFIG_CONFIG_H + * + * @description: + * A macro used in #include statements to name the file containing + * FreeType~2 configuration data. + * + */ +#ifndef FT_CONFIG_CONFIG_H +#define FT_CONFIG_CONFIG_H <freetype/config/ftconfig.h> +#endif + + + /************************************************************************* + * + * @macro: + * FT_CONFIG_STANDARD_LIBRARY_H + * + * @description: + * A macro used in #include statements to name the file containing + * FreeType~2 interface to the standard C library functions. + * + */ +#ifndef FT_CONFIG_STANDARD_LIBRARY_H +#define FT_CONFIG_STANDARD_LIBRARY_H <freetype/config/ftstdlib.h> +#endif + + + /************************************************************************* + * + * @macro: + * FT_CONFIG_OPTIONS_H + * + * @description: + * A macro used in #include statements to name the file containing + * FreeType~2 project-specific configuration options. + * + */ +#ifndef FT_CONFIG_OPTIONS_H +#define FT_CONFIG_OPTIONS_H <freetype/config/ftoption.h> +#endif + + + /************************************************************************* + * + * @macro: + * FT_CONFIG_MODULES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list of FreeType~2 modules that are statically linked to new library + * instances in @FT_Init_FreeType. + * + */ +#ifndef FT_CONFIG_MODULES_H +#define FT_CONFIG_MODULES_H <freetype/config/ftmodule.h> +#endif + + /* */ + + /* public headers */ + + /************************************************************************* + * + * @macro: + * FT_FREETYPE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * base FreeType~2 API. + * + */ +#define FT_FREETYPE_H <freetype/freetype.h> + + + /************************************************************************* + * + * @macro: + * FT_ERRORS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list of FreeType~2 error codes (and messages). + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_ERRORS_H <freetype/fterrors.h> + + + /************************************************************************* + * + * @macro: + * FT_MODULE_ERRORS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list of FreeType~2 module error offsets (and messages). + * + */ +#define FT_MODULE_ERRORS_H <freetype/ftmoderr.h> + + + /************************************************************************* + * + * @macro: + * FT_SYSTEM_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 interface to low-level operations (i.e., memory management + * and stream i/o). + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_SYSTEM_H <freetype/ftsystem.h> + + + /************************************************************************* + * + * @macro: + * FT_IMAGE_H + * + * @description: + * A macro used in #include statements to name the file containing type + * definitions related to glyph images (i.e., bitmaps, outlines, + * scan-converter parameters). + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_IMAGE_H <freetype/ftimage.h> + + + /************************************************************************* + * + * @macro: + * FT_TYPES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * basic data types defined by FreeType~2. + * + * It is included by @FT_FREETYPE_H. + * + */ +#define FT_TYPES_H <freetype/fttypes.h> + + + /************************************************************************* + * + * @macro: + * FT_LIST_H + * + * @description: + * A macro used in #include statements to name the file containing the + * list management API of FreeType~2. + * + * (Most applications will never need to include this file.) + * + */ +#define FT_LIST_H <freetype/ftlist.h> + + + /************************************************************************* + * + * @macro: + * FT_OUTLINE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * scalable outline management API of FreeType~2. + * + */ +#define FT_OUTLINE_H <freetype/ftoutln.h> + + + /************************************************************************* + * + * @macro: + * FT_SIZES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API which manages multiple @FT_Size objects per face. + * + */ +#define FT_SIZES_H <freetype/ftsizes.h> + + + /************************************************************************* + * + * @macro: + * FT_MODULE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * module management API of FreeType~2. + * + */ +#define FT_MODULE_H <freetype/ftmodapi.h> + + + /************************************************************************* + * + * @macro: + * FT_RENDER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * renderer module management API of FreeType~2. + * + */ +#define FT_RENDER_H <freetype/ftrender.h> + + + /************************************************************************* + * + * @macro: + * FT_DRIVER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the driver modules. + * + */ +#define FT_DRIVER_H <freetype/ftdriver.h> + + + /************************************************************************* + * + * @macro: + * FT_AUTOHINTER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the auto-hinting module. + * + * Deprecated since version 2.9; use @FT_DRIVER_H instead. + * + */ +#define FT_AUTOHINTER_H FT_DRIVER_H + + + /************************************************************************* + * + * @macro: + * FT_CFF_DRIVER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the CFF driver module. + * + * Deprecated since version 2.9; use @FT_DRIVER_H instead. + * + */ +#define FT_CFF_DRIVER_H FT_DRIVER_H + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_DRIVER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the TrueType driver module. + * + * Deprecated since version 2.9; use @FT_DRIVER_H instead. + * + */ +#define FT_TRUETYPE_DRIVER_H FT_DRIVER_H + + + /************************************************************************* + * + * @macro: + * FT_PCF_DRIVER_H + * + * @description: + * A macro used in #include statements to name the file containing + * structures and macros related to the PCF driver module. + * + * Deprecated since version 2.9; use @FT_DRIVER_H instead. + * + */ +#define FT_PCF_DRIVER_H FT_DRIVER_H + + + /************************************************************************* + * + * @macro: + * FT_TYPE1_TABLES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * types and API specific to the Type~1 format. + * + */ +#define FT_TYPE1_TABLES_H <freetype/t1tables.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_IDS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * enumeration values which identify name strings, languages, encodings, + * etc. This file really contains a _large_ set of constant macro + * definitions, taken from the TrueType and OpenType specifications. + * + */ +#define FT_TRUETYPE_IDS_H <freetype/ttnameid.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_TABLES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * types and API specific to the TrueType (as well as OpenType) format. + * + */ +#define FT_TRUETYPE_TABLES_H <freetype/tttables.h> + + + /************************************************************************* + * + * @macro: + * FT_TRUETYPE_TAGS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of TrueType four-byte `tags' which identify blocks in + * SFNT-based font formats (i.e., TrueType and OpenType). + * + */ +#define FT_TRUETYPE_TAGS_H <freetype/tttags.h> + + + /************************************************************************* + * + * @macro: + * FT_BDF_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which accesses BDF-specific strings from a + * face. + * + */ +#define FT_BDF_H <freetype/ftbdf.h> + + + /************************************************************************* + * + * @macro: + * FT_CID_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which access CID font information from a + * face. + * + */ +#define FT_CID_H <freetype/ftcid.h> + + + /************************************************************************* + * + * @macro: + * FT_GZIP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports gzip-compressed files. + * + */ +#define FT_GZIP_H <freetype/ftgzip.h> + + + /************************************************************************* + * + * @macro: + * FT_LZW_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports LZW-compressed files. + * + */ +#define FT_LZW_H <freetype/ftlzw.h> + + + /************************************************************************* + * + * @macro: + * FT_BZIP2_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports bzip2-compressed files. + * + */ +#define FT_BZIP2_H <freetype/ftbzip2.h> + + + /************************************************************************* + * + * @macro: + * FT_WINFONTS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * definitions of an API which supports Windows FNT files. + * + */ +#define FT_WINFONTS_H <freetype/ftwinfnt.h> + + + /************************************************************************* + * + * @macro: + * FT_GLYPH_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional glyph management component. + * + */ +#define FT_GLYPH_H <freetype/ftglyph.h> + + + /************************************************************************* + * + * @macro: + * FT_BITMAP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional bitmap conversion component. + * + */ +#define FT_BITMAP_H <freetype/ftbitmap.h> + + + /************************************************************************* + * + * @macro: + * FT_BBOX_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional exact bounding box computation routines. + * + */ +#define FT_BBOX_H <freetype/ftbbox.h> + + + /************************************************************************* + * + * @macro: + * FT_CACHE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * API of the optional FreeType~2 cache sub-system. + * + */ +#define FT_CACHE_H <freetype/ftcache.h> + + + /************************************************************************* + * + * @macro: + * FT_MAC_H + * + * @description: + * A macro used in #include statements to name the file containing the + * Macintosh-specific FreeType~2 API. The latter is used to access + * fonts embedded in resource forks. + * + * This header file must be explicitly included by client applications + * compiled on the Mac (note that the base API still works though). + * + */ +#define FT_MAC_H <freetype/ftmac.h> + + + /************************************************************************* + * + * @macro: + * FT_MULTIPLE_MASTERS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional multiple-masters management API of FreeType~2. + * + */ +#define FT_MULTIPLE_MASTERS_H <freetype/ftmm.h> + + + /************************************************************************* + * + * @macro: + * FT_SFNT_NAMES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional FreeType~2 API which accesses embedded `name' strings in + * SFNT-based font formats (i.e., TrueType and OpenType). + * + */ +#define FT_SFNT_NAMES_H <freetype/ftsnames.h> + + + /************************************************************************* + * + * @macro: + * FT_OPENTYPE_VALIDATE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional FreeType~2 API which validates OpenType tables (BASE, GDEF, + * GPOS, GSUB, JSTF). + * + */ +#define FT_OPENTYPE_VALIDATE_H <freetype/ftotval.h> + + + /************************************************************************* + * + * @macro: + * FT_GX_VALIDATE_H + * + * @description: + * A macro used in #include statements to name the file containing the + * optional FreeType~2 API which validates TrueTypeGX/AAT tables (feat, + * mort, morx, bsln, just, kern, opbd, trak, prop). + * + */ +#define FT_GX_VALIDATE_H <freetype/ftgxval.h> + + + /************************************************************************* + * + * @macro: + * FT_PFR_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which accesses PFR-specific data. + * + */ +#define FT_PFR_H <freetype/ftpfr.h> + + + /************************************************************************* + * + * @macro: + * FT_STROKER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which provides functions to stroke outline paths. + */ +#define FT_STROKER_H <freetype/ftstroke.h> + + + /************************************************************************* + * + * @macro: + * FT_SYNTHESIS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs artificial obliquing and emboldening. + */ +#define FT_SYNTHESIS_H <freetype/ftsynth.h> + + + /************************************************************************* + * + * @macro: + * FT_FONT_FORMATS_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which provides functions specific to font formats. + */ +#define FT_FONT_FORMATS_H <freetype/ftfntfmt.h> + + /* deprecated */ +#define FT_XFREE86_H FT_FONT_FORMATS_H + + + /************************************************************************* + * + * @macro: + * FT_TRIGONOMETRY_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs trigonometric computations (e.g., + * cosines and arc tangents). + */ +#define FT_TRIGONOMETRY_H <freetype/fttrigon.h> + + + /************************************************************************* + * + * @macro: + * FT_LCD_FILTER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs color filtering for subpixel rendering. + */ +#define FT_LCD_FILTER_H <freetype/ftlcdfil.h> + + + /************************************************************************* + * + * @macro: + * FT_INCREMENTAL_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which performs incremental glyph loading. + */ +#define FT_INCREMENTAL_H <freetype/ftincrem.h> + + + /************************************************************************* + * + * @macro: + * FT_GASP_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which returns entries from the TrueType GASP table. + */ +#define FT_GASP_H <freetype/ftgasp.h> + + + /************************************************************************* + * + * @macro: + * FT_ADVANCES_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which returns individual and ranged glyph advances. + */ +#define FT_ADVANCES_H <freetype/ftadvanc.h> + + + /* */ + + /* These header files don't need to be included by the user. */ +#define FT_ERROR_DEFINITIONS_H <freetype/fterrdef.h> +#define FT_PARAMETER_TAGS_H <freetype/ftparams.h> + + /* Deprecated macros. */ +#define FT_UNPATENTED_HINTING_H <freetype/ftparams.h> +#define FT_TRUETYPE_UNPATENTED_H <freetype/ftparams.h> + + /* FT_CACHE_H is the only header file needed for the cache subsystem. */ +#define FT_CACHE_IMAGE_H FT_CACHE_H +#define FT_CACHE_SMALL_BITMAPS_H FT_CACHE_H +#define FT_CACHE_CHARMAP_H FT_CACHE_H + + /* The internals of the cache sub-system are no longer exposed. We */ + /* default to FT_CACHE_H at the moment just in case, but we know of */ + /* no rogue client that uses them. */ + /* */ +#define FT_CACHE_MANAGER_H FT_CACHE_H +#define FT_CACHE_INTERNAL_MRU_H FT_CACHE_H +#define FT_CACHE_INTERNAL_MANAGER_H FT_CACHE_H +#define FT_CACHE_INTERNAL_CACHE_H FT_CACHE_H +#define FT_CACHE_INTERNAL_GLYPH_H FT_CACHE_H +#define FT_CACHE_INTERNAL_IMAGE_H FT_CACHE_H +#define FT_CACHE_INTERNAL_SBITS_H FT_CACHE_H + + + /* + * Include internal headers definitions from <internal/...> + * only when building the library. + */ +#ifdef FT2_BUILD_LIBRARY +#define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h> +#include FT_INTERNAL_INTERNAL_H +#endif /* FT2_BUILD_LIBRARY */ + + +#endif /* FTHEADER_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/config/ftmodule.h b/freetype/include/freetype2/freetype/config/ftmodule.h new file mode 100644 index 0000000..d1b938b --- /dev/null +++ b/freetype/include/freetype2/freetype/config/ftmodule.h @@ -0,0 +1,22 @@ +/* This is a generated file. */ +FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) +FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) +FT_USE_MODULE( FT_Module_Class, autofit_module_class ) +FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) +FT_USE_MODULE( FT_Module_Class, gxv_module_class ) +FT_USE_MODULE( FT_Module_Class, otv_module_class ) +FT_USE_MODULE( FT_Module_Class, psaux_module_class ) +FT_USE_MODULE( FT_Module_Class, psnames_module_class ) +/* EOF */ diff --git a/freetype/include/freetype2/freetype/config/ftoption.h b/freetype/include/freetype2/freetype/config/ftoption.h new file mode 100644 index 0000000..6142b8d --- /dev/null +++ b/freetype/include/freetype2/freetype/config/ftoption.h @@ -0,0 +1,977 @@ +/***************************************************************************/ +/* */ +/* ftoption.h */ +/* */ +/* User-selectable configuration macros (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTOPTION_H_ +#define FTOPTION_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* USER-SELECTABLE CONFIGURATION MACROS */ + /* */ + /* This file contains the default configuration macro definitions for */ + /* a standard build of the FreeType library. There are three ways to */ + /* use this file to build project-specific versions of the library: */ + /* */ + /* - You can modify this file by hand, but this is not recommended in */ + /* cases where you would like to build several versions of the */ + /* library from a single source directory. */ + /* */ + /* - You can put a copy of this file in your build directory, more */ + /* precisely in `$BUILD/freetype/config/ftoption.h', where `$BUILD' */ + /* is the name of a directory that is included _before_ the FreeType */ + /* include path during compilation. */ + /* */ + /* The default FreeType Makefiles and Jamfiles use the build */ + /* directory `builds/<system>' by default, but you can easily change */ + /* that for your own projects. */ + /* */ + /* - Copy the file <ft2build.h> to `$BUILD/ft2build.h' and modify it */ + /* slightly to pre-define the macro FT_CONFIG_OPTIONS_H used to */ + /* locate this file during the build. For example, */ + /* */ + /* #define FT_CONFIG_OPTIONS_H <myftoptions.h> */ + /* #include <freetype/config/ftheader.h> */ + /* */ + /* will use `$BUILD/myftoptions.h' instead of this file for macro */ + /* definitions. */ + /* */ + /* Note also that you can similarly pre-define the macro */ + /* FT_CONFIG_MODULES_H used to locate the file listing of the modules */ + /* that are statically linked to the library at compile time. By */ + /* default, this file is <freetype/config/ftmodule.h>. */ + /* */ + /* We highly recommend using the third method whenever possible. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** G E N E R A L F R E E T Y P E 2 C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*#***********************************************************************/ + /* */ + /* If you enable this configuration option, FreeType recognizes an */ + /* environment variable called `FREETYPE_PROPERTIES', which can be used */ + /* to control the various font drivers and modules. The controllable */ + /* properties are listed in the section @properties. */ + /* */ + /* You have to undefine this configuration option on platforms that lack */ + /* the concept of environment variables (and thus don't have the */ + /* `getenv' function), for example Windows CE. */ + /* */ + /* `FREETYPE_PROPERTIES' has the following syntax form (broken here into */ + /* multiple lines for better readability). */ + /* */ + /* { */ + /* <optional whitespace> */ + /* <module-name1> ':' */ + /* <property-name1> '=' <property-value1> */ + /* <whitespace> */ + /* <module-name2> ':' */ + /* <property-name2> '=' <property-value2> */ + /* ... */ + /* } */ + /* */ + /* Example: */ + /* */ + /* FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ */ + /* cff:no-stem-darkening=1 \ */ + /* autofitter:warping=1 */ + /* */ +#define FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES + + + /*************************************************************************/ + /* */ + /* Uncomment the line below if you want to activate LCD rendering */ + /* technology similar to ClearType in this build of the library. This */ + /* technology triples the resolution in the direction color subpixels. */ + /* To mitigate color fringes inherent to this technology, you also need */ + /* to explicitly set up LCD filtering. */ + /* */ + /* Note that this feature is covered by several Microsoft patents */ + /* and should not be activated in any default build of the library. */ + /* When this macro is not defined, FreeType offers alternative LCD */ + /* rendering technology that produces excellent output without LCD */ + /* filtering. */ + /* */ +#define FT_CONFIG_OPTION_SUBPIXEL_RENDERING + + + /*************************************************************************/ + /* */ + /* Many compilers provide a non-ANSI 64-bit data type that can be used */ + /* by FreeType to speed up some computations. However, this will create */ + /* some problems when compiling the library in strict ANSI mode. */ + /* */ + /* For this reason, the use of 64-bit integers is normally disabled when */ + /* the __STDC__ macro is defined. You can however disable this by */ + /* defining the macro FT_CONFIG_OPTION_FORCE_INT64 here. */ + /* */ + /* For most compilers, this will only create compilation warnings when */ + /* building the library. */ + /* */ + /* ObNote: The compiler-specific 64-bit integers are detected in the */ + /* file `ftconfig.h' either statically or through the */ + /* `configure' script on supported platforms. */ + /* */ +#undef FT_CONFIG_OPTION_FORCE_INT64 + + + /*************************************************************************/ + /* */ + /* If this macro is defined, do not try to use an assembler version of */ + /* performance-critical functions (e.g. FT_MulFix). You should only do */ + /* that to verify that the assembler function works properly, or to */ + /* execute benchmark tests of the various implementations. */ +/* #define FT_CONFIG_OPTION_NO_ASSEMBLER */ + + + /*************************************************************************/ + /* */ + /* If this macro is defined, try to use an inlined assembler version of */ + /* the `FT_MulFix' function, which is a `hotspot' when loading and */ + /* hinting glyphs, and which should be executed as fast as possible. */ + /* */ + /* Note that if your compiler or CPU is not supported, this will default */ + /* to the standard and portable implementation found in `ftcalc.c'. */ + /* */ +#define FT_CONFIG_OPTION_INLINE_MULFIX + + + /*************************************************************************/ + /* */ + /* LZW-compressed file support. */ + /* */ + /* FreeType now handles font files that have been compressed with the */ + /* `compress' program. This is mostly used to parse many of the PCF */ + /* files that come with various X11 distributions. The implementation */ + /* uses NetBSD's `zopen' to partially uncompress the file on the fly */ + /* (see src/lzw/ftgzip.c). */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ +#define FT_CONFIG_OPTION_USE_LZW + + + /*************************************************************************/ + /* */ + /* Gzip-compressed file support. */ + /* */ + /* FreeType now handles font files that have been compressed with the */ + /* `gzip' program. This is mostly used to parse many of the PCF files */ + /* that come with XFree86. The implementation uses `zlib' to */ + /* partially uncompress the file on the fly (see src/gzip/ftgzip.c). */ + /* */ + /* Define this macro if you want to enable this `feature'. See also */ + /* the macro FT_CONFIG_OPTION_SYSTEM_ZLIB below. */ + /* */ +#define FT_CONFIG_OPTION_USE_ZLIB + + + /*************************************************************************/ + /* */ + /* ZLib library selection */ + /* */ + /* This macro is only used when FT_CONFIG_OPTION_USE_ZLIB is defined. */ + /* It allows FreeType's `ftgzip' component to link to the system's */ + /* installation of the ZLib library. This is useful on systems like */ + /* Unix or VMS where it generally is already available. */ + /* */ + /* If you let it undefined, the component will use its own copy */ + /* of the zlib sources instead. These have been modified to be */ + /* included directly within the component and *not* export external */ + /* function names. This allows you to link any program with FreeType */ + /* _and_ ZLib without linking conflicts. */ + /* */ + /* Do not #undef this macro here since the build system might define */ + /* it for certain configurations only. */ + /* */ + /* If you use a build system like cmake or the `configure' script, */ + /* options set by those programs have precendence, overwriting the */ + /* value here with the configured one. */ + /* */ +/* #undef FT_CONFIG_OPTION_SYSTEM_ZLIB */ + + + /*************************************************************************/ + /* */ + /* Bzip2-compressed file support. */ + /* */ + /* FreeType now handles font files that have been compressed with the */ + /* `bzip2' program. This is mostly used to parse many of the PCF */ + /* files that come with XFree86. The implementation uses `libbz2' to */ + /* partially uncompress the file on the fly (see src/bzip2/ftbzip2.c). */ + /* Contrary to gzip, bzip2 currently is not included and need to use */ + /* the system available bzip2 implementation. */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ + /* If you use a build system like cmake or the `configure' script, */ + /* options set by those programs have precendence, overwriting the */ + /* value here with the configured one. */ + /* */ +/* #undef FT_CONFIG_OPTION_USE_BZIP2 */ + + + /*************************************************************************/ + /* */ + /* Define to disable the use of file stream functions and types, FILE, */ + /* fopen() etc. Enables the use of smaller system libraries on embedded */ + /* systems that have multiple system libraries, some with or without */ + /* file stream support, in the cases where file stream support is not */ + /* necessary such as memory loading of font files. */ + /* */ +/* #define FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT */ + + + /*************************************************************************/ + /* */ + /* PNG bitmap support. */ + /* */ + /* FreeType now handles loading color bitmap glyphs in the PNG format. */ + /* This requires help from the external libpng library. Uncompressed */ + /* color bitmaps do not need any external libraries and will be */ + /* supported regardless of this configuration. */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ + /* If you use a build system like cmake or the `configure' script, */ + /* options set by those programs have precendence, overwriting the */ + /* value here with the configured one. */ + /* */ +/* #undef FT_CONFIG_OPTION_USE_PNG */ + + + /*************************************************************************/ + /* */ + /* HarfBuzz support. */ + /* */ + /* FreeType uses the HarfBuzz library to improve auto-hinting of */ + /* OpenType fonts. If available, many glyphs not directly addressable */ + /* by a font's character map will be hinted also. */ + /* */ + /* Define this macro if you want to enable this `feature'. */ + /* */ + /* If you use a build system like cmake or the `configure' script, */ + /* options set by those programs have precendence, overwriting the */ + /* value here with the configured one. */ + /* */ +/* #undef FT_CONFIG_OPTION_USE_HARFBUZZ */ + + + /*************************************************************************/ + /* */ + /* Glyph Postscript Names handling */ + /* */ + /* By default, FreeType 2 is compiled with the `psnames' module. This */ + /* module is in charge of converting a glyph name string into a */ + /* Unicode value, or return a Macintosh standard glyph name for the */ + /* use with the TrueType `post' table. */ + /* */ + /* Undefine this macro if you do not want `psnames' compiled in your */ + /* build of FreeType. This has the following effects: */ + /* */ + /* - The TrueType driver will provide its own set of glyph names, */ + /* if you build it to support postscript names in the TrueType */ + /* `post' table, but will not synthesize a missing Unicode charmap. */ + /* */ + /* - The Type 1 driver will not be able to synthesize a Unicode */ + /* charmap out of the glyphs found in the fonts. */ + /* */ + /* You would normally undefine this configuration macro when building */ + /* a version of FreeType that doesn't contain a Type 1 or CFF driver. */ + /* */ +#define FT_CONFIG_OPTION_POSTSCRIPT_NAMES + + + /*************************************************************************/ + /* */ + /* Postscript Names to Unicode Values support */ + /* */ + /* By default, FreeType 2 is built with the `PSNames' module compiled */ + /* in. Among other things, the module is used to convert a glyph name */ + /* into a Unicode value. This is especially useful in order to */ + /* synthesize on the fly a Unicode charmap from the CFF/Type 1 driver */ + /* through a big table named the `Adobe Glyph List' (AGL). */ + /* */ + /* Undefine this macro if you do not want the Adobe Glyph List */ + /* compiled in your `PSNames' module. The Type 1 driver will not be */ + /* able to synthesize a Unicode charmap out of the glyphs found in the */ + /* fonts. */ + /* */ +#define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST + + + /*************************************************************************/ + /* */ + /* Support for Mac fonts */ + /* */ + /* Define this macro if you want support for outline fonts in Mac */ + /* format (mac dfont, mac resource, macbinary containing a mac */ + /* resource) on non-Mac platforms. */ + /* */ + /* Note that the `FOND' resource isn't checked. */ + /* */ +#define FT_CONFIG_OPTION_MAC_FONTS + + + /*************************************************************************/ + /* */ + /* Guessing methods to access embedded resource forks */ + /* */ + /* Enable extra Mac fonts support on non-Mac platforms (e.g. */ + /* GNU/Linux). */ + /* */ + /* Resource forks which include fonts data are stored sometimes in */ + /* locations which users or developers don't expected. In some cases, */ + /* resource forks start with some offset from the head of a file. In */ + /* other cases, the actual resource fork is stored in file different */ + /* from what the user specifies. If this option is activated, */ + /* FreeType tries to guess whether such offsets or different file */ + /* names must be used. */ + /* */ + /* Note that normal, direct access of resource forks is controlled via */ + /* the FT_CONFIG_OPTION_MAC_FONTS option. */ + /* */ +#ifdef FT_CONFIG_OPTION_MAC_FONTS +#define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK +#endif + + + /*************************************************************************/ + /* */ + /* Allow the use of FT_Incremental_Interface to load typefaces that */ + /* contain no glyph data, but supply it via a callback function. */ + /* This is required by clients supporting document formats which */ + /* supply font data incrementally as the document is parsed, such */ + /* as the Ghostscript interpreter for the PostScript language. */ + /* */ +#define FT_CONFIG_OPTION_INCREMENTAL + + + /*************************************************************************/ + /* */ + /* The size in bytes of the render pool used by the scan-line converter */ + /* to do all of its work. */ + /* */ +#define FT_RENDER_POOL_SIZE 16384L + + + /*************************************************************************/ + /* */ + /* FT_MAX_MODULES */ + /* */ + /* The maximum number of modules that can be registered in a single */ + /* FreeType library object. 32 is the default. */ + /* */ +#define FT_MAX_MODULES 32 + + + /*************************************************************************/ + /* */ + /* Debug level */ + /* */ + /* FreeType can be compiled in debug or trace mode. In debug mode, */ + /* errors are reported through the `ftdebug' component. In trace */ + /* mode, additional messages are sent to the standard output during */ + /* execution. */ + /* */ + /* Define FT_DEBUG_LEVEL_ERROR to build the library in debug mode. */ + /* Define FT_DEBUG_LEVEL_TRACE to build it in trace mode. */ + /* */ + /* Don't define any of these macros to compile in `release' mode! */ + /* */ + /* Do not #undef these macros here since the build system might define */ + /* them for certain configurations only. */ + /* */ +/* #define FT_DEBUG_LEVEL_ERROR */ +/* #define FT_DEBUG_LEVEL_TRACE */ + + + /*************************************************************************/ + /* */ + /* Autofitter debugging */ + /* */ + /* If FT_DEBUG_AUTOFIT is defined, FreeType provides some means to */ + /* control the autofitter behaviour for debugging purposes with global */ + /* boolean variables (consequently, you should *never* enable this */ + /* while compiling in `release' mode): */ + /* */ + /* _af_debug_disable_horz_hints */ + /* _af_debug_disable_vert_hints */ + /* _af_debug_disable_blue_hints */ + /* */ + /* Additionally, the following functions provide dumps of various */ + /* internal autofit structures to stdout (using `printf'): */ + /* */ + /* af_glyph_hints_dump_points */ + /* af_glyph_hints_dump_segments */ + /* af_glyph_hints_dump_edges */ + /* af_glyph_hints_get_num_segments */ + /* af_glyph_hints_get_segment_offset */ + /* */ + /* As an argument, they use another global variable: */ + /* */ + /* _af_debug_hints */ + /* */ + /* Please have a look at the `ftgrid' demo program to see how those */ + /* variables and macros should be used. */ + /* */ + /* Do not #undef these macros here since the build system might define */ + /* them for certain configurations only. */ + /* */ +/* #define FT_DEBUG_AUTOFIT */ + + + /*************************************************************************/ + /* */ + /* Memory Debugging */ + /* */ + /* FreeType now comes with an integrated memory debugger that is */ + /* capable of detecting simple errors like memory leaks or double */ + /* deletes. To compile it within your build of the library, you */ + /* should define FT_DEBUG_MEMORY here. */ + /* */ + /* Note that the memory debugger is only activated at runtime when */ + /* when the _environment_ variable `FT2_DEBUG_MEMORY' is defined also! */ + /* */ + /* Do not #undef this macro here since the build system might define */ + /* it for certain configurations only. */ + /* */ +/* #define FT_DEBUG_MEMORY */ + + + /*************************************************************************/ + /* */ + /* Module errors */ + /* */ + /* If this macro is set (which is _not_ the default), the higher byte */ + /* of an error code gives the module in which the error has occurred, */ + /* while the lower byte is the real error code. */ + /* */ + /* Setting this macro makes sense for debugging purposes only, since */ + /* it would break source compatibility of certain programs that use */ + /* FreeType 2. */ + /* */ + /* More details can be found in the files ftmoderr.h and fterrors.h. */ + /* */ +#undef FT_CONFIG_OPTION_USE_MODULE_ERRORS + + + /*************************************************************************/ + /* */ + /* Position Independent Code */ + /* */ + /* If this macro is set (which is _not_ the default), FreeType2 will */ + /* avoid creating constants that require address fixups. Instead the */ + /* constants will be moved into a struct and additional intialization */ + /* code will be used. */ + /* */ + /* Setting this macro is needed for systems that prohibit address */ + /* fixups, such as BREW. [Note that standard compilers like gcc or */ + /* clang handle PIC generation automatically; you don't have to set */ + /* FT_CONFIG_OPTION_PIC, which is only necessary for very special */ + /* compilers.] */ + /* */ + /* Note that FT_CONFIG_OPTION_PIC support is not available for all */ + /* modules (see `modules.cfg' for a complete list). For building with */ + /* FT_CONFIG_OPTION_PIC support, do the following. */ + /* */ + /* 0. Clone the repository. */ + /* 1. Define FT_CONFIG_OPTION_PIC. */ + /* 2. Remove all subdirectories in `src' that don't have */ + /* FT_CONFIG_OPTION_PIC support. */ + /* 3. Comment out the corresponding modules in `modules.cfg'. */ + /* 4. Compile. */ + /* */ +/* #define FT_CONFIG_OPTION_PIC */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** S F N T D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_EMBEDDED_BITMAPS if you want to support */ + /* embedded bitmaps in all formats using the SFNT module (namely */ + /* TrueType & OpenType). */ + /* */ +#define TT_CONFIG_OPTION_EMBEDDED_BITMAPS + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_POSTSCRIPT_NAMES if you want to be able to */ + /* load and enumerate the glyph Postscript names in a TrueType or */ + /* OpenType file. */ + /* */ + /* Note that when you do not compile the `PSNames' module by undefining */ + /* the above FT_CONFIG_OPTION_POSTSCRIPT_NAMES, the `sfnt' module will */ + /* contain additional code used to read the PS Names table from a font. */ + /* */ + /* (By default, the module uses `PSNames' to extract glyph names.) */ + /* */ +#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_SFNT_NAMES if your applications need to */ + /* access the internal name table in a SFNT-based format like TrueType */ + /* or OpenType. The name table contains various strings used to */ + /* describe the font, like family name, copyright, version, etc. It */ + /* does not contain any glyph name though. */ + /* */ + /* Accessing SFNT names is done through the functions declared in */ + /* `ftsnames.h'. */ + /* */ +#define TT_CONFIG_OPTION_SFNT_NAMES + + + /*************************************************************************/ + /* */ + /* TrueType CMap support */ + /* */ + /* Here you can fine-tune which TrueType CMap table format shall be */ + /* supported. */ +#define TT_CONFIG_CMAP_FORMAT_0 +#define TT_CONFIG_CMAP_FORMAT_2 +#define TT_CONFIG_CMAP_FORMAT_4 +#define TT_CONFIG_CMAP_FORMAT_6 +#define TT_CONFIG_CMAP_FORMAT_8 +#define TT_CONFIG_CMAP_FORMAT_10 +#define TT_CONFIG_CMAP_FORMAT_12 +#define TT_CONFIG_CMAP_FORMAT_13 +#define TT_CONFIG_CMAP_FORMAT_14 + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_BYTECODE_INTERPRETER if you want to compile */ + /* a bytecode interpreter in the TrueType driver. */ + /* */ + /* By undefining this, you will only compile the code necessary to load */ + /* TrueType glyphs without hinting. */ + /* */ + /* Do not #undef this macro here, since the build system might */ + /* define it for certain configurations only. */ + /* */ +#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_SUBPIXEL_HINTING if you want to compile */ + /* subpixel hinting support into the TrueType driver. This modifies the */ + /* TrueType hinting mechanism when anything but FT_RENDER_MODE_MONO is */ + /* requested. */ + /* */ + /* In particular, it modifies the bytecode interpreter to interpret (or */ + /* not) instructions in a certain way so that all TrueType fonts look */ + /* like they do in a Windows ClearType (DirectWrite) environment. See */ + /* [1] for a technical overview on what this means. See `ttinterp.h' */ + /* for more details on the LEAN option. */ + /* */ + /* There are three possible values. */ + /* */ + /* Value 1: */ + /* This value is associated with the `Infinality' moniker, */ + /* contributed by an individual nicknamed Infinality with the goal of */ + /* making TrueType fonts render better than on Windows. A high */ + /* amount of configurability and flexibility, down to rules for */ + /* single glyphs in fonts, but also very slow. Its experimental and */ + /* slow nature and the original developer losing interest meant that */ + /* this option was never enabled in default builds. */ + /* */ + /* The corresponding interpreter version is v38. */ + /* */ + /* Value 2: */ + /* The new default mode for the TrueType driver. The Infinality code */ + /* base was stripped to the bare minimum and all configurability */ + /* removed in the name of speed and simplicity. The configurability */ + /* was mainly aimed at legacy fonts like Arial, Times New Roman, or */ + /* Courier. Legacy fonts are fonts that modify vertical stems to */ + /* achieve clean black-and-white bitmaps. The new mode focuses on */ + /* applying a minimal set of rules to all fonts indiscriminately so */ + /* that modern and web fonts render well while legacy fonts render */ + /* okay. */ + /* */ + /* The corresponding interpreter version is v40. */ + /* */ + /* Value 3: */ + /* Compile both, making both v38 and v40 available (the latter is the */ + /* default). */ + /* */ + /* By undefining these, you get rendering behavior like on Windows */ + /* without ClearType, i.e., Windows XP without ClearType enabled and */ + /* Win9x (interpreter version v35). Or not, depending on how much */ + /* hinting blood and testing tears the font designer put into a given */ + /* font. If you define one or both subpixel hinting options, you can */ + /* switch between between v35 and the ones you define (using */ + /* `FT_Property_Set'). */ + /* */ + /* This option requires TT_CONFIG_OPTION_BYTECODE_INTERPRETER to be */ + /* defined. */ + /* */ + /* [1] https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx */ + /* */ +/* #define TT_CONFIG_OPTION_SUBPIXEL_HINTING 1 */ +#define TT_CONFIG_OPTION_SUBPIXEL_HINTING 2 +/* #define TT_CONFIG_OPTION_SUBPIXEL_HINTING ( 1 | 2 ) */ + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED to compile the */ + /* TrueType glyph loader to use Apple's definition of how to handle */ + /* component offsets in composite glyphs. */ + /* */ + /* Apple and MS disagree on the default behavior of component offsets */ + /* in composites. Apple says that they should be scaled by the scaling */ + /* factors in the transformation matrix (roughly, it's more complex) */ + /* while MS says they should not. OpenType defines two bits in the */ + /* composite flags array which can be used to disambiguate, but old */ + /* fonts will not have them. */ + /* */ + /* https://www.microsoft.com/typography/otspec/glyf.htm */ + /* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html */ + /* */ +#undef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_GX_VAR_SUPPORT if you want to include */ + /* support for Apple's distortable font technology (fvar, gvar, cvar, */ + /* and avar tables). This has many similarities to Type 1 Multiple */ + /* Masters support. */ + /* */ +#define TT_CONFIG_OPTION_GX_VAR_SUPPORT + + + /*************************************************************************/ + /* */ + /* Define TT_CONFIG_OPTION_BDF if you want to include support for */ + /* an embedded `BDF ' table within SFNT-based bitmap formats. */ + /* */ +#define TT_CONFIG_OPTION_BDF + + + /*************************************************************************/ + /* */ + /* Option TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES controls the maximum */ + /* number of bytecode instructions executed for a single run of the */ + /* bytecode interpreter, needed to prevent infinite loops. You don't */ + /* want to change this except for very special situations (e.g., making */ + /* a library fuzzer spend less time to handle broken fonts). */ + /* */ + /* It is not expected that this value is ever modified by a configuring */ + /* script; instead, it gets surrounded with #ifndef ... #endif so that */ + /* the value can be set as a preprocessor option on the compiler's */ + /* command line. */ + /* */ +#ifndef TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES +#define TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES 1000000L +#endif + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* T1_MAX_DICT_DEPTH is the maximum depth of nest dictionaries and */ + /* arrays in the Type 1 stream (see t1load.c). A minimum of 4 is */ + /* required. */ + /* */ +#define T1_MAX_DICT_DEPTH 5 + + + /*************************************************************************/ + /* */ + /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */ + /* calls during glyph loading. */ + /* */ +#define T1_MAX_SUBRS_CALLS 16 + + + /*************************************************************************/ + /* */ + /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */ + /* minimum of 16 is required. */ + /* */ + /* The Chinese font MingTiEG-Medium (CNS 11643 character set) needs 256. */ + /* */ +#define T1_MAX_CHARSTRINGS_OPERANDS 256 + + + /*************************************************************************/ + /* */ + /* Define this configuration macro if you want to prevent the */ + /* compilation of `t1afm', which is in charge of reading Type 1 AFM */ + /* files into an existing face. Note that if set, the T1 driver will be */ + /* unable to produce kerning distances. */ + /* */ +#undef T1_CONFIG_OPTION_NO_AFM + + + /*************************************************************************/ + /* */ + /* Define this configuration macro if you want to prevent the */ + /* compilation of the Multiple Masters font support in the Type 1 */ + /* driver. */ + /* */ +#undef T1_CONFIG_OPTION_NO_MM_SUPPORT + + + /*************************************************************************/ + /* */ + /* T1_CONFIG_OPTION_OLD_ENGINE controls whether the pre-Adobe Type 1 */ + /* engine gets compiled into FreeType. If defined, it is possible to */ + /* switch between the two engines using the `hinting-engine' property of */ + /* the type1 driver module. */ + /* */ +/* #define T1_CONFIG_OPTION_OLD_ENGINE */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** C F F D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Using CFF_CONFIG_OPTION_DARKENING_PARAMETER_{X,Y}{1,2,3,4} it is */ + /* possible to set up the default values of the four control points that */ + /* define the stem darkening behaviour of the (new) CFF engine. For */ + /* more details please read the documentation of the */ + /* `darkening-parameters' property (file `ftdriver.h'), which allows the */ + /* control at run-time. */ + /* */ + /* Do *not* undefine these macros! */ + /* */ +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 500 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 400 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 1000 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 275 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 1667 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 275 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 2333 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 0 + + + /*************************************************************************/ + /* */ + /* CFF_CONFIG_OPTION_OLD_ENGINE controls whether the pre-Adobe CFF */ + /* engine gets compiled into FreeType. If defined, it is possible to */ + /* switch between the two engines using the `hinting-engine' property of */ + /* the cff driver module. */ + /* */ +/* #define CFF_CONFIG_OPTION_OLD_ENGINE */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** P C F D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* There are many PCF fonts just called `Fixed' which look completely */ + /* different, and which have nothing to do with each other. When */ + /* selecting `Fixed' in KDE or Gnome one gets results that appear rather */ + /* random, the style changes often if one changes the size and one */ + /* cannot select some fonts at all. This option makes the PCF module */ + /* prepend the foundry name (plus a space) to the family name. */ + /* */ + /* We also check whether we have `wide' characters; all put together, we */ + /* get family names like `Sony Fixed' or `Misc Fixed Wide'. */ + /* */ + /* If this option is activated, it can be controlled with the */ + /* `no-long-family-names' property of the pcf driver module. */ + /* */ +/* #define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** A U T O F I T M O D U L E C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Compile autofit module with CJK (Chinese, Japanese, Korean) script */ + /* support. */ + /* */ +#define AF_CONFIG_OPTION_CJK + + /*************************************************************************/ + /* */ + /* Compile autofit module with fallback Indic script support, covering */ + /* some scripts that the `latin' submodule of the autofit module doesn't */ + /* (yet) handle. */ + /* */ +#define AF_CONFIG_OPTION_INDIC + + /*************************************************************************/ + /* */ + /* Compile autofit module with warp hinting. The idea of the warping */ + /* code is to slightly scale and shift a glyph within a single dimension */ + /* so that as much of its segments are aligned (more or less) on the */ + /* grid. To find out the optimal scaling and shifting value, various */ + /* parameter combinations are tried and scored. */ + /* */ + /* This experimental option is active only if the rendering mode is */ + /* FT_RENDER_MODE_LIGHT; you can switch warping on and off with the */ + /* `warping' property of the auto-hinter (see file `ftdriver.h' for more */ + /* information; by default it is switched off). */ + /* */ +#define AF_CONFIG_OPTION_USE_WARPER + + /*************************************************************************/ + /* */ + /* Use TrueType-like size metrics for `light' auto-hinting. */ + /* */ + /* It is strongly recommended to avoid this option, which exists only to */ + /* help some legacy applications retain its appearance and behaviour */ + /* with respect to auto-hinted TrueType fonts. */ + /* */ + /* The very reason this option exists at all are GNU/Linux distributions */ + /* like Fedora that did not un-patch the following change (which was */ + /* present in FreeType between versions 2.4.6 and 2.7.1, inclusive). */ + /* */ + /* 2011-07-16 Steven Chu <steven.f.chu@gmail.com> */ + /* */ + /* [truetype] Fix metrics on size request for scalable fonts. */ + /* */ + /* This problematic commit is now reverted (more or less). */ + /* */ +/* #define AF_CONFIG_OPTION_TT_SIZE_METRICS */ + + /* */ + + + /* + * This macro is obsolete. Support has been removed in FreeType + * version 2.5. + */ +/* #define FT_CONFIG_OPTION_OLD_INTERNALS */ + + + /* + * This macro is defined if native TrueType hinting is requested by the + * definitions above. + */ +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +#define TT_USE_BYTECODE_INTERPRETER + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING +#if TT_CONFIG_OPTION_SUBPIXEL_HINTING & 1 +#define TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY +#endif + +#if TT_CONFIG_OPTION_SUBPIXEL_HINTING & 2 +#define TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL +#endif +#endif +#endif + + + /* + * Check CFF darkening parameters. The checks are the same as in function + * `cff_property_set' in file `cffdrivr.c'. + */ +#if CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 < 0 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 < 0 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 > 500 +#error "Invalid CFF darkening parameters!" +#endif + +FT_END_HEADER + + +#endif /* FTOPTION_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/config/ftstdlib.h b/freetype/include/freetype2/freetype/config/ftstdlib.h new file mode 100644 index 0000000..42f9a06 --- /dev/null +++ b/freetype/include/freetype2/freetype/config/ftstdlib.h @@ -0,0 +1,175 @@ +/***************************************************************************/ +/* */ +/* ftstdlib.h */ +/* */ +/* ANSI-specific library and header configuration file (specification */ +/* only). */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file is used to group all #includes to the ANSI C library that */ + /* FreeType normally requires. It also defines macros to rename the */ + /* standard functions within the FreeType source code. */ + /* */ + /* Load a file which defines FTSTDLIB_H_ before this one to override it. */ + /* */ + /*************************************************************************/ + + +#ifndef FTSTDLIB_H_ +#define FTSTDLIB_H_ + + +#include <stddef.h> + +#define ft_ptrdiff_t ptrdiff_t + + + /**********************************************************************/ + /* */ + /* integer limits */ + /* */ + /* UINT_MAX and ULONG_MAX are used to automatically compute the size */ + /* of `int' and `long' in bytes at compile-time. So far, this works */ + /* for all platforms the library has been tested on. */ + /* */ + /* Note that on the extremely rare platforms that do not provide */ + /* integer types that are _exactly_ 16 and 32 bits wide (e.g. some */ + /* old Crays where `int' is 36 bits), we do not make any guarantee */ + /* about the correct behaviour of FT2 with all fonts. */ + /* */ + /* In these case, `ftconfig.h' will refuse to compile anyway with a */ + /* message like `couldn't find 32-bit type' or something similar. */ + /* */ + /**********************************************************************/ + + +#include <limits.h> + +#define FT_CHAR_BIT CHAR_BIT +#define FT_USHORT_MAX USHRT_MAX +#define FT_INT_MAX INT_MAX +#define FT_INT_MIN INT_MIN +#define FT_UINT_MAX UINT_MAX +#define FT_LONG_MIN LONG_MIN +#define FT_LONG_MAX LONG_MAX +#define FT_ULONG_MAX ULONG_MAX + + + /**********************************************************************/ + /* */ + /* character and string processing */ + /* */ + /**********************************************************************/ + + +#include <string.h> + +#define ft_memchr memchr +#define ft_memcmp memcmp +#define ft_memcpy memcpy +#define ft_memmove memmove +#define ft_memset memset +#define ft_strcat strcat +#define ft_strcmp strcmp +#define ft_strcpy strcpy +#define ft_strlen strlen +#define ft_strncmp strncmp +#define ft_strncpy strncpy +#define ft_strrchr strrchr +#define ft_strstr strstr + + + /**********************************************************************/ + /* */ + /* file handling */ + /* */ + /**********************************************************************/ + + +#include <stdio.h> + +#define FT_FILE FILE +#define ft_fclose fclose +#define ft_fopen fopen +#define ft_fread fread +#define ft_fseek fseek +#define ft_ftell ftell +#define ft_sprintf sprintf + + + /**********************************************************************/ + /* */ + /* sorting */ + /* */ + /**********************************************************************/ + + +#include <stdlib.h> + +#define ft_qsort qsort + + + /**********************************************************************/ + /* */ + /* memory allocation */ + /* */ + /**********************************************************************/ + + +#define ft_scalloc calloc +#define ft_sfree free +#define ft_smalloc malloc +#define ft_srealloc realloc + + + /**********************************************************************/ + /* */ + /* miscellaneous */ + /* */ + /**********************************************************************/ + + +#define ft_strtol strtol +#define ft_getenv getenv + + + /**********************************************************************/ + /* */ + /* execution control */ + /* */ + /**********************************************************************/ + + +#include <setjmp.h> + +#define ft_jmp_buf jmp_buf /* note: this cannot be a typedef since */ + /* jmp_buf is defined as a macro */ + /* on certain platforms */ + +#define ft_longjmp longjmp +#define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */ + + + /* the following is only used for debugging purposes, i.e., if */ + /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */ + +#include <stdarg.h> + + +#endif /* FTSTDLIB_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/freetype.h b/freetype/include/freetype2/freetype/freetype.h new file mode 100644 index 0000000..9664404 --- /dev/null +++ b/freetype/include/freetype2/freetype/freetype.h @@ -0,0 +1,4657 @@ +/***************************************************************************/ +/* */ +/* freetype.h */ +/* */ +/* FreeType high-level API and common types (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FREETYPE_H_ +#define FREETYPE_H_ + + +#ifndef FT_FREETYPE_H +#error "`ft2build.h' hasn't been included yet!" +#error "Please always use macros to include FreeType header files." +#error "Example:" +#error " #include <ft2build.h>" +#error " #include FT_FREETYPE_H" +#endif + + +#include <ft2build.h> +#include FT_CONFIG_CONFIG_H +#include FT_TYPES_H +#include FT_ERRORS_H + + +FT_BEGIN_HEADER + + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* header_inclusion */ + /* */ + /* <Title> */ + /* FreeType's header inclusion scheme */ + /* */ + /* <Abstract> */ + /* How client applications should include FreeType header files. */ + /* */ + /* <Description> */ + /* To be as flexible as possible (and for historical reasons), */ + /* FreeType uses a very special inclusion scheme to load header */ + /* files, for example */ + /* */ + /* { */ + /* #include <ft2build.h> */ + /* */ + /* #include FT_FREETYPE_H */ + /* #include FT_OUTLINE_H */ + /* } */ + /* */ + /* A compiler and its preprocessor only needs an include path to find */ + /* the file `ft2build.h'; the exact locations and names of the other */ + /* FreeType header files are hidden by preprocessor macro names, */ + /* loaded by `ft2build.h'. The API documentation always gives the */ + /* header macro name needed for a particular function. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* user_allocation */ + /* */ + /* <Title> */ + /* User allocation */ + /* */ + /* <Abstract> */ + /* How client applications should allocate FreeType data structures. */ + /* */ + /* <Description> */ + /* FreeType assumes that structures allocated by the user and passed */ + /* as arguments are zeroed out except for the actual data. In other */ + /* words, it is recommended to use `calloc' (or variants of it) */ + /* instead of `malloc' for allocation. */ + /* */ + /*************************************************************************/ + + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* B A S I C T Y P E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* base_interface */ + /* */ + /* <Title> */ + /* Base Interface */ + /* */ + /* <Abstract> */ + /* The FreeType~2 base font interface. */ + /* */ + /* <Description> */ + /* This section describes the most important public high-level API */ + /* functions of FreeType~2. */ + /* */ + /* <Order> */ + /* FT_Library */ + /* FT_Face */ + /* FT_Size */ + /* FT_GlyphSlot */ + /* FT_CharMap */ + /* FT_Encoding */ + /* FT_ENC_TAG */ + /* */ + /* FT_FaceRec */ + /* */ + /* FT_FACE_FLAG_SCALABLE */ + /* FT_FACE_FLAG_FIXED_SIZES */ + /* FT_FACE_FLAG_FIXED_WIDTH */ + /* FT_FACE_FLAG_HORIZONTAL */ + /* FT_FACE_FLAG_VERTICAL */ + /* FT_FACE_FLAG_COLOR */ + /* FT_FACE_FLAG_SFNT */ + /* FT_FACE_FLAG_CID_KEYED */ + /* FT_FACE_FLAG_TRICKY */ + /* FT_FACE_FLAG_KERNING */ + /* FT_FACE_FLAG_MULTIPLE_MASTERS */ + /* FT_FACE_FLAG_VARIATION */ + /* FT_FACE_FLAG_GLYPH_NAMES */ + /* FT_FACE_FLAG_EXTERNAL_STREAM */ + /* FT_FACE_FLAG_HINTER */ + /* */ + /* FT_HAS_HORIZONTAL */ + /* FT_HAS_VERTICAL */ + /* FT_HAS_KERNING */ + /* FT_HAS_FIXED_SIZES */ + /* FT_HAS_GLYPH_NAMES */ + /* FT_HAS_COLOR */ + /* FT_HAS_MULTIPLE_MASTERS */ + /* */ + /* FT_IS_SFNT */ + /* FT_IS_SCALABLE */ + /* FT_IS_FIXED_WIDTH */ + /* FT_IS_CID_KEYED */ + /* FT_IS_TRICKY */ + /* FT_IS_NAMED_INSTANCE */ + /* FT_IS_VARIATION */ + /* */ + /* FT_STYLE_FLAG_BOLD */ + /* FT_STYLE_FLAG_ITALIC */ + /* */ + /* FT_SizeRec */ + /* FT_Size_Metrics */ + /* */ + /* FT_GlyphSlotRec */ + /* FT_Glyph_Metrics */ + /* FT_SubGlyph */ + /* */ + /* FT_Bitmap_Size */ + /* */ + /* FT_Init_FreeType */ + /* FT_Done_FreeType */ + /* */ + /* FT_New_Face */ + /* FT_Done_Face */ + /* FT_Reference_Face */ + /* FT_New_Memory_Face */ + /* FT_Face_Properties */ + /* FT_Open_Face */ + /* FT_Open_Args */ + /* FT_Parameter */ + /* FT_Attach_File */ + /* FT_Attach_Stream */ + /* */ + /* FT_Set_Char_Size */ + /* FT_Set_Pixel_Sizes */ + /* FT_Request_Size */ + /* FT_Select_Size */ + /* FT_Size_Request_Type */ + /* FT_Size_RequestRec */ + /* FT_Size_Request */ + /* FT_Set_Transform */ + /* FT_Load_Glyph */ + /* FT_Get_Char_Index */ + /* FT_Get_First_Char */ + /* FT_Get_Next_Char */ + /* FT_Get_Name_Index */ + /* FT_Load_Char */ + /* */ + /* FT_OPEN_MEMORY */ + /* FT_OPEN_STREAM */ + /* FT_OPEN_PATHNAME */ + /* FT_OPEN_DRIVER */ + /* FT_OPEN_PARAMS */ + /* */ + /* FT_LOAD_DEFAULT */ + /* FT_LOAD_RENDER */ + /* FT_LOAD_MONOCHROME */ + /* FT_LOAD_LINEAR_DESIGN */ + /* FT_LOAD_NO_SCALE */ + /* FT_LOAD_NO_HINTING */ + /* FT_LOAD_NO_BITMAP */ + /* FT_LOAD_NO_AUTOHINT */ + /* FT_LOAD_COLOR */ + /* */ + /* FT_LOAD_VERTICAL_LAYOUT */ + /* FT_LOAD_IGNORE_TRANSFORM */ + /* FT_LOAD_FORCE_AUTOHINT */ + /* FT_LOAD_NO_RECURSE */ + /* FT_LOAD_PEDANTIC */ + /* */ + /* FT_LOAD_TARGET_NORMAL */ + /* FT_LOAD_TARGET_LIGHT */ + /* FT_LOAD_TARGET_MONO */ + /* FT_LOAD_TARGET_LCD */ + /* FT_LOAD_TARGET_LCD_V */ + /* */ + /* FT_LOAD_TARGET_MODE */ + /* */ + /* FT_Render_Glyph */ + /* FT_Render_Mode */ + /* FT_Get_Kerning */ + /* FT_Kerning_Mode */ + /* FT_Get_Track_Kerning */ + /* FT_Get_Glyph_Name */ + /* FT_Get_Postscript_Name */ + /* */ + /* FT_CharMapRec */ + /* FT_Select_Charmap */ + /* FT_Set_Charmap */ + /* FT_Get_Charmap_Index */ + /* */ + /* FT_Get_FSType_Flags */ + /* FT_Get_SubGlyph_Info */ + /* */ + /* FT_Face_Internal */ + /* FT_Size_Internal */ + /* FT_Slot_Internal */ + /* */ + /* FT_FACE_FLAG_XXX */ + /* FT_STYLE_FLAG_XXX */ + /* FT_OPEN_XXX */ + /* FT_LOAD_XXX */ + /* FT_LOAD_TARGET_XXX */ + /* FT_SUBGLYPH_FLAG_XXX */ + /* FT_FSTYPE_XXX */ + /* */ + /* FT_HAS_FAST_GLYPHS */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Glyph_Metrics */ + /* */ + /* <Description> */ + /* A structure to model the metrics of a single glyph. The values */ + /* are expressed in 26.6 fractional pixel format; if the flag */ + /* @FT_LOAD_NO_SCALE has been used while loading the glyph, values */ + /* are expressed in font units instead. */ + /* */ + /* <Fields> */ + /* width :: */ + /* The glyph's width. */ + /* */ + /* height :: */ + /* The glyph's height. */ + /* */ + /* horiBearingX :: */ + /* Left side bearing for horizontal layout. */ + /* */ + /* horiBearingY :: */ + /* Top side bearing for horizontal layout. */ + /* */ + /* horiAdvance :: */ + /* Advance width for horizontal layout. */ + /* */ + /* vertBearingX :: */ + /* Left side bearing for vertical layout. */ + /* */ + /* vertBearingY :: */ + /* Top side bearing for vertical layout. Larger positive values */ + /* mean further below the vertical glyph origin. */ + /* */ + /* vertAdvance :: */ + /* Advance height for vertical layout. Positive values mean the */ + /* glyph has a positive advance downward. */ + /* */ + /* <Note> */ + /* If not disabled with @FT_LOAD_NO_HINTING, the values represent */ + /* dimensions of the hinted glyph (in case hinting is applicable). */ + /* */ + /* Stroking a glyph with an outside border does not increase */ + /* `horiAdvance' or `vertAdvance'; you have to manually adjust these */ + /* values to account for the added width and height. */ + /* */ + /* FreeType doesn't use the `VORG' table data for CFF fonts because */ + /* it doesn't have an interface to quickly retrieve the glyph height. */ + /* The y~coordinate of the vertical origin can be simply computed as */ + /* `vertBearingY + height' after loading a glyph. */ + /* */ + typedef struct FT_Glyph_Metrics_ + { + FT_Pos width; + FT_Pos height; + + FT_Pos horiBearingX; + FT_Pos horiBearingY; + FT_Pos horiAdvance; + + FT_Pos vertBearingX; + FT_Pos vertBearingY; + FT_Pos vertAdvance; + + } FT_Glyph_Metrics; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Bitmap_Size */ + /* */ + /* <Description> */ + /* This structure models the metrics of a bitmap strike (i.e., a set */ + /* of glyphs for a given point size and resolution) in a bitmap font. */ + /* It is used for the `available_sizes' field of @FT_Face. */ + /* */ + /* <Fields> */ + /* height :: The vertical distance, in pixels, between two */ + /* consecutive baselines. It is always positive. */ + /* */ + /* width :: The average width, in pixels, of all glyphs in the */ + /* strike. */ + /* */ + /* size :: The nominal size of the strike in 26.6 fractional */ + /* points. This field is not very useful. */ + /* */ + /* x_ppem :: The horizontal ppem (nominal width) in 26.6 fractional */ + /* pixels. */ + /* */ + /* y_ppem :: The vertical ppem (nominal height) in 26.6 fractional */ + /* pixels. */ + /* */ + /* <Note> */ + /* Windows FNT: */ + /* The nominal size given in a FNT font is not reliable. If the */ + /* driver finds it incorrect, it sets `size' to some calculated */ + /* values, and `x_ppem' and `y_ppem' to the pixel width and height */ + /* given in the font, respectively. */ + /* */ + /* TrueType embedded bitmaps: */ + /* `size', `width', and `height' values are not contained in the */ + /* bitmap strike itself. They are computed from the global font */ + /* parameters. */ + /* */ + typedef struct FT_Bitmap_Size_ + { + FT_Short height; + FT_Short width; + + FT_Pos size; + + FT_Pos x_ppem; + FT_Pos y_ppem; + + } FT_Bitmap_Size; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* O B J E C T C L A S S E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Library */ + /* */ + /* <Description> */ + /* A handle to a FreeType library instance. Each `library' is */ + /* completely independent from the others; it is the `root' of a set */ + /* of objects like fonts, faces, sizes, etc. */ + /* */ + /* It also embeds a memory manager (see @FT_Memory), as well as a */ + /* scan-line converter object (see @FT_Raster). */ + /* */ + /* In multi-threaded applications it is easiest to use one */ + /* `FT_Library' object per thread. In case this is too cumbersome, */ + /* a single `FT_Library' object across threads is possible also */ + /* (since FreeType version 2.5.6), as long as a mutex lock is used */ + /* around @FT_New_Face and @FT_Done_Face. */ + /* */ + /* <Note> */ + /* Library objects are normally created by @FT_Init_FreeType, and */ + /* destroyed with @FT_Done_FreeType. If you need reference-counting */ + /* (cf. @FT_Reference_Library), use @FT_New_Library and */ + /* @FT_Done_Library. */ + /* */ + typedef struct FT_LibraryRec_ *FT_Library; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Module */ + /* */ + /* <Description> */ + /* A handle to a given FreeType module object. A module can be a */ + /* font driver, a renderer, or anything else that provides services */ + /* to the former. */ + /* */ + typedef struct FT_ModuleRec_* FT_Module; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Driver */ + /* */ + /* <Description> */ + /* A handle to a given FreeType font driver object. A font driver */ + /* is a module capable of creating faces from font files. */ + /* */ + typedef struct FT_DriverRec_* FT_Driver; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Renderer */ + /* */ + /* <Description> */ + /* A handle to a given FreeType renderer. A renderer is a module in */ + /* charge of converting a glyph's outline image to a bitmap. It */ + /* supports a single glyph image format, and one or more target */ + /* surface depths. */ + /* */ + typedef struct FT_RendererRec_* FT_Renderer; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* base_interface */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Face */ + /* */ + /* <Description> */ + /* A handle to a typographic face object. A face object models a */ + /* given typeface, in a given style. */ + /* */ + /* <Note> */ + /* A face object also owns a single @FT_GlyphSlot object, as well */ + /* as one or more @FT_Size objects. */ + /* */ + /* Use @FT_New_Face or @FT_Open_Face to create a new face object from */ + /* a given filepath or a custom input stream. */ + /* */ + /* Use @FT_Done_Face to destroy it (along with its slot and sizes). */ + /* */ + /* An `FT_Face' object can only be safely used from one thread at a */ + /* time. Similarly, creation and destruction of `FT_Face' with the */ + /* same @FT_Library object can only be done from one thread at a */ + /* time. On the other hand, functions like @FT_Load_Glyph and its */ + /* siblings are thread-safe and do not need the lock to be held as */ + /* long as the same `FT_Face' object is not used from multiple */ + /* threads at the same time. */ + /* */ + /* <Also> */ + /* See @FT_FaceRec for the publicly accessible fields of a given face */ + /* object. */ + /* */ + typedef struct FT_FaceRec_* FT_Face; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Size */ + /* */ + /* <Description> */ + /* A handle to an object that models a face scaled to a given */ + /* character size. */ + /* */ + /* <Note> */ + /* An @FT_Face has one _active_ @FT_Size object that is used by */ + /* functions like @FT_Load_Glyph to determine the scaling */ + /* transformation that in turn is used to load and hint glyphs and */ + /* metrics. */ + /* */ + /* You can use @FT_Set_Char_Size, @FT_Set_Pixel_Sizes, */ + /* @FT_Request_Size or even @FT_Select_Size to change the content */ + /* (i.e., the scaling values) of the active @FT_Size. */ + /* */ + /* You can use @FT_New_Size to create additional size objects for a */ + /* given @FT_Face, but they won't be used by other functions until */ + /* you activate it through @FT_Activate_Size. Only one size can be */ + /* activated at any given time per face. */ + /* */ + /* <Also> */ + /* See @FT_SizeRec for the publicly accessible fields of a given size */ + /* object. */ + /* */ + typedef struct FT_SizeRec_* FT_Size; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_GlyphSlot */ + /* */ + /* <Description> */ + /* A handle to a given `glyph slot'. A slot is a container that can */ + /* hold any of the glyphs contained in its parent face. */ + /* */ + /* In other words, each time you call @FT_Load_Glyph or */ + /* @FT_Load_Char, the slot's content is erased by the new glyph data, */ + /* i.e., the glyph's metrics, its image (bitmap or outline), and */ + /* other control information. */ + /* */ + /* <Also> */ + /* See @FT_GlyphSlotRec for the publicly accessible glyph fields. */ + /* */ + typedef struct FT_GlyphSlotRec_* FT_GlyphSlot; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_CharMap */ + /* */ + /* <Description> */ + /* A handle to a character map (usually abbreviated to `charmap'). A */ + /* charmap is used to translate character codes in a given encoding */ + /* into glyph indexes for its parent's face. Some font formats may */ + /* provide several charmaps per font. */ + /* */ + /* Each face object owns zero or more charmaps, but only one of them */ + /* can be `active', providing the data used by @FT_Get_Char_Index or */ + /* @FT_Load_Char. */ + /* */ + /* The list of available charmaps in a face is available through the */ + /* `face->num_charmaps' and `face->charmaps' fields of @FT_FaceRec. */ + /* */ + /* The currently active charmap is available as `face->charmap'. */ + /* You should call @FT_Set_Charmap to change it. */ + /* */ + /* <Note> */ + /* When a new face is created (either through @FT_New_Face or */ + /* @FT_Open_Face), the library looks for a Unicode charmap within */ + /* the list and automatically activates it. If there is no Unicode */ + /* charmap, FreeType doesn't set an `active' charmap. */ + /* */ + /* <Also> */ + /* See @FT_CharMapRec for the publicly accessible fields of a given */ + /* character map. */ + /* */ + typedef struct FT_CharMapRec_* FT_CharMap; + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_ENC_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags into an unsigned long. It is */ + /* used to define `encoding' identifiers (see @FT_Encoding). */ + /* */ + /* <Note> */ + /* Since many 16-bit compilers don't like 32-bit enumerations, you */ + /* should redefine this macro in case of problems to something like */ + /* this: */ + /* */ + /* { */ + /* #define FT_ENC_TAG( value, a, b, c, d ) value */ + /* } */ + /* */ + /* to get a simple enumeration without assigning special numbers. */ + /* */ + +#ifndef FT_ENC_TAG +#define FT_ENC_TAG( value, a, b, c, d ) \ + value = ( ( (FT_UInt32)(a) << 24 ) | \ + ( (FT_UInt32)(b) << 16 ) | \ + ( (FT_UInt32)(c) << 8 ) | \ + (FT_UInt32)(d) ) + +#endif /* FT_ENC_TAG */ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Encoding */ + /* */ + /* <Description> */ + /* An enumeration to specify character sets supported by charmaps. */ + /* Used in the @FT_Select_Charmap API function. */ + /* */ + /* <Note> */ + /* Despite the name, this enumeration lists specific character */ + /* repertories (i.e., charsets), and not text encoding methods (e.g., */ + /* UTF-8, UTF-16, etc.). */ + /* */ + /* Other encodings might be defined in the future. */ + /* */ + /* <Values> */ + /* FT_ENCODING_NONE :: */ + /* The encoding value~0 is reserved. */ + /* */ + /* FT_ENCODING_UNICODE :: */ + /* The Unicode character set. This value covers all versions of */ + /* the Unicode repertoire, including ASCII and Latin-1. Most fonts */ + /* include a Unicode charmap, but not all of them. */ + /* */ + /* For example, if you want to access Unicode value U+1F028 (and */ + /* the font contains it), use value 0x1F028 as the input value for */ + /* @FT_Get_Char_Index. */ + /* */ + /* FT_ENCODING_MS_SYMBOL :: */ + /* Microsoft Symbol encoding, used to encode mathematical symbols */ + /* and wingdings. For more information, see */ + /* `https://www.microsoft.com/typography/otspec/recom.htm', */ + /* `http://www.kostis.net/charsets/symbol.htm', and */ + /* `http://www.kostis.net/charsets/wingding.htm'. */ + /* */ + /* This encoding uses character codes from the PUA (Private Unicode */ + /* Area) in the range U+F020-U+F0FF. */ + /* */ + /* FT_ENCODING_SJIS :: */ + /* Shift JIS encoding for Japanese. More info at */ + /* `https://en.wikipedia.org/wiki/Shift_JIS'. See note on */ + /* multi-byte encodings below. */ + /* */ + /* FT_ENCODING_PRC :: */ + /* Corresponds to encoding systems mainly for Simplified Chinese as */ + /* used in People's Republic of China (PRC). The encoding layout */ + /* is based on GB~2312 and its supersets GBK and GB~18030. */ + /* */ + /* FT_ENCODING_BIG5 :: */ + /* Corresponds to an encoding system for Traditional Chinese as */ + /* used in Taiwan and Hong Kong. */ + /* */ + /* FT_ENCODING_WANSUNG :: */ + /* Corresponds to the Korean encoding system known as Extended */ + /* Wansung (MS Windows code page 949). */ + /* For more information see */ + /* `https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit949.txt'. */ + /* */ + /* FT_ENCODING_JOHAB :: */ + /* The Korean standard character set (KS~C 5601-1992), which */ + /* corresponds to MS Windows code page 1361. This character set */ + /* includes all possible Hangul character combinations. */ + /* */ + /* FT_ENCODING_ADOBE_LATIN_1 :: */ + /* Corresponds to a Latin-1 encoding as defined in a Type~1 */ + /* PostScript font. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_STANDARD :: */ + /* Adobe Standard encoding, as found in Type~1, CFF, and */ + /* OpenType/CFF fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_EXPERT :: */ + /* Adobe Expert encoding, as found in Type~1, CFF, and OpenType/CFF */ + /* fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_CUSTOM :: */ + /* Corresponds to a custom encoding, as found in Type~1, CFF, and */ + /* OpenType/CFF fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_APPLE_ROMAN :: */ + /* Apple roman encoding. Many TrueType and OpenType fonts contain */ + /* a charmap for this 8-bit encoding, since older versions of Mac */ + /* OS are able to use it. */ + /* */ + /* FT_ENCODING_OLD_LATIN_2 :: */ + /* This value is deprecated and was neither used nor reported by */ + /* FreeType. Don't use or test for it. */ + /* */ + /* FT_ENCODING_MS_SJIS :: */ + /* Same as FT_ENCODING_SJIS. Deprecated. */ + /* */ + /* FT_ENCODING_MS_GB2312 :: */ + /* Same as FT_ENCODING_PRC. Deprecated. */ + /* */ + /* FT_ENCODING_MS_BIG5 :: */ + /* Same as FT_ENCODING_BIG5. Deprecated. */ + /* */ + /* FT_ENCODING_MS_WANSUNG :: */ + /* Same as FT_ENCODING_WANSUNG. Deprecated. */ + /* */ + /* FT_ENCODING_MS_JOHAB :: */ + /* Same as FT_ENCODING_JOHAB. Deprecated. */ + /* */ + /* <Note> */ + /* By default, FreeType enables a Unicode charmap and tags it with */ + /* FT_ENCODING_UNICODE when it is either provided or can be generated */ + /* from PostScript glyph name dictionaries in the font file. */ + /* All other encodings are considered legacy and tagged only if */ + /* explicitly defined in the font file. Otherwise, FT_ENCODING_NONE */ + /* is used. */ + /* */ + /* FT_ENCODING_NONE is set by the BDF and PCF drivers if the charmap */ + /* is neither Unicode nor ISO-8859-1 (otherwise it is set to */ + /* FT_ENCODING_UNICODE). Use @FT_Get_BDF_Charset_ID to find out */ + /* which encoding is really present. If, for example, the */ + /* `cs_registry' field is `KOI8' and the `cs_encoding' field is `R', */ + /* the font is encoded in KOI8-R. */ + /* */ + /* FT_ENCODING_NONE is always set (with a single exception) by the */ + /* winfonts driver. Use @FT_Get_WinFNT_Header and examine the */ + /* `charset' field of the @FT_WinFNT_HeaderRec structure to find out */ + /* which encoding is really present. For example, */ + /* @FT_WinFNT_ID_CP1251 (204) means Windows code page 1251 (for */ + /* Russian). */ + /* */ + /* FT_ENCODING_NONE is set if `platform_id' is @TT_PLATFORM_MACINTOSH */ + /* and `encoding_id' is not `TT_MAC_ID_ROMAN' (otherwise it is set to */ + /* FT_ENCODING_APPLE_ROMAN). */ + /* */ + /* If `platform_id' is @TT_PLATFORM_MACINTOSH, use the function */ + /* @FT_Get_CMap_Language_ID to query the Mac language ID that may */ + /* be needed to be able to distinguish Apple encoding variants. See */ + /* */ + /* https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt */ + /* */ + /* to get an idea how to do that. Basically, if the language ID */ + /* is~0, don't use it, otherwise subtract 1 from the language ID. */ + /* Then examine `encoding_id'. If, for example, `encoding_id' is */ + /* `TT_MAC_ID_ROMAN' and the language ID (minus~1) is */ + /* `TT_MAC_LANGID_GREEK', it is the Greek encoding, not Roman. */ + /* `TT_MAC_ID_ARABIC' with `TT_MAC_LANGID_FARSI' means the Farsi */ + /* variant the Arabic encoding. */ + /* */ + typedef enum FT_Encoding_ + { + FT_ENC_TAG( FT_ENCODING_NONE, 0, 0, 0, 0 ), + + FT_ENC_TAG( FT_ENCODING_MS_SYMBOL, 's', 'y', 'm', 'b' ), + FT_ENC_TAG( FT_ENCODING_UNICODE, 'u', 'n', 'i', 'c' ), + + FT_ENC_TAG( FT_ENCODING_SJIS, 's', 'j', 'i', 's' ), + FT_ENC_TAG( FT_ENCODING_PRC, 'g', 'b', ' ', ' ' ), + FT_ENC_TAG( FT_ENCODING_BIG5, 'b', 'i', 'g', '5' ), + FT_ENC_TAG( FT_ENCODING_WANSUNG, 'w', 'a', 'n', 's' ), + FT_ENC_TAG( FT_ENCODING_JOHAB, 'j', 'o', 'h', 'a' ), + + /* for backward compatibility */ + FT_ENCODING_GB2312 = FT_ENCODING_PRC, + FT_ENCODING_MS_SJIS = FT_ENCODING_SJIS, + FT_ENCODING_MS_GB2312 = FT_ENCODING_PRC, + FT_ENCODING_MS_BIG5 = FT_ENCODING_BIG5, + FT_ENCODING_MS_WANSUNG = FT_ENCODING_WANSUNG, + FT_ENCODING_MS_JOHAB = FT_ENCODING_JOHAB, + + FT_ENC_TAG( FT_ENCODING_ADOBE_STANDARD, 'A', 'D', 'O', 'B' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_EXPERT, 'A', 'D', 'B', 'E' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_CUSTOM, 'A', 'D', 'B', 'C' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_LATIN_1, 'l', 'a', 't', '1' ), + + FT_ENC_TAG( FT_ENCODING_OLD_LATIN_2, 'l', 'a', 't', '2' ), + + FT_ENC_TAG( FT_ENCODING_APPLE_ROMAN, 'a', 'r', 'm', 'n' ) + + } FT_Encoding; + + + /* these constants are deprecated; use the corresponding `FT_Encoding' */ + /* values instead */ +#define ft_encoding_none FT_ENCODING_NONE +#define ft_encoding_unicode FT_ENCODING_UNICODE +#define ft_encoding_symbol FT_ENCODING_MS_SYMBOL +#define ft_encoding_latin_1 FT_ENCODING_ADOBE_LATIN_1 +#define ft_encoding_latin_2 FT_ENCODING_OLD_LATIN_2 +#define ft_encoding_sjis FT_ENCODING_SJIS +#define ft_encoding_gb2312 FT_ENCODING_PRC +#define ft_encoding_big5 FT_ENCODING_BIG5 +#define ft_encoding_wansung FT_ENCODING_WANSUNG +#define ft_encoding_johab FT_ENCODING_JOHAB + +#define ft_encoding_adobe_standard FT_ENCODING_ADOBE_STANDARD +#define ft_encoding_adobe_expert FT_ENCODING_ADOBE_EXPERT +#define ft_encoding_adobe_custom FT_ENCODING_ADOBE_CUSTOM +#define ft_encoding_apple_roman FT_ENCODING_APPLE_ROMAN + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_CharMapRec */ + /* */ + /* <Description> */ + /* The base charmap structure. */ + /* */ + /* <Fields> */ + /* face :: A handle to the parent face object. */ + /* */ + /* encoding :: An @FT_Encoding tag identifying the charmap. Use */ + /* this with @FT_Select_Charmap. */ + /* */ + /* platform_id :: An ID number describing the platform for the */ + /* following encoding ID. This comes directly from */ + /* the TrueType specification and gets emulated for */ + /* other formats. */ + /* */ + /* encoding_id :: A platform specific encoding number. This also */ + /* comes from the TrueType specification and gets */ + /* emulated similarly. */ + /* */ + typedef struct FT_CharMapRec_ + { + FT_Face face; + FT_Encoding encoding; + FT_UShort platform_id; + FT_UShort encoding_id; + + } FT_CharMapRec; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* B A S E O B J E C T C L A S S E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Face_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Face_InternalRec' structure that models */ + /* the private data of a given @FT_Face object. */ + /* */ + /* This structure might change between releases of FreeType~2 and is */ + /* not generally available to client applications. */ + /* */ + typedef struct FT_Face_InternalRec_* FT_Face_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_FaceRec */ + /* */ + /* <Description> */ + /* FreeType root face class structure. A face object models a */ + /* typeface in a font file. */ + /* */ + /* <Fields> */ + /* num_faces :: The number of faces in the font file. Some */ + /* font formats can have multiple faces in */ + /* a single font file. */ + /* */ + /* face_index :: This field holds two different values. */ + /* Bits 0-15 are the index of the face in the */ + /* font file (starting with value~0). They */ + /* are set to~0 if there is only one face in */ + /* the font file. */ + /* */ + /* [Since 2.6.1] Bits 16-30 are relevant to GX */ + /* and OpenType variation fonts only, holding */ + /* the named instance index for the current */ + /* face index (starting with value~1; value~0 */ + /* indicates font access without a named */ + /* instance). For non-variation fonts, bits */ + /* 16-30 are ignored. If we have the third */ + /* named instance of face~4, say, `face_index' */ + /* is set to 0x00030004. */ + /* */ + /* Bit 31 is always zero (this is, */ + /* `face_index' is always a positive value). */ + /* */ + /* [Since 2.9] Changing the design coordinates */ + /* with @FT_Set_Var_Design_Coordinates or */ + /* @FT_Set_Var_Blend_Coordinates does not */ + /* influence the named instance index value */ + /* (only @FT_Set_Named_Instance does that). */ + /* */ + /* face_flags :: A set of bit flags that give important */ + /* information about the face; see */ + /* @FT_FACE_FLAG_XXX for the details. */ + /* */ + /* style_flags :: The lower 16~bits contain a set of bit */ + /* flags indicating the style of the face; see */ + /* @FT_STYLE_FLAG_XXX for the details. */ + /* */ + /* [Since 2.6.1] Bits 16-30 hold the number */ + /* of named instances available for the */ + /* current face if we have a GX or OpenType */ + /* variation (sub)font. Bit 31 is always zero */ + /* (this is, `style_flags' is always a */ + /* positive value). Note that a variation */ + /* font has always at least one named */ + /* instance, namely the default instance. */ + /* */ + /* num_glyphs :: The number of glyphs in the face. If the */ + /* face is scalable and has sbits (see */ + /* `num_fixed_sizes'), it is set to the number */ + /* of outline glyphs. */ + /* */ + /* For CID-keyed fonts (not in an SFNT */ + /* wrapper) this value gives the highest CID */ + /* used in the font. */ + /* */ + /* family_name :: The face's family name. This is an ASCII */ + /* string, usually in English, that describes */ + /* the typeface's family (like `Times New */ + /* Roman', `Bodoni', `Garamond', etc). This */ + /* is a least common denominator used to list */ + /* fonts. Some formats (TrueType & OpenType) */ + /* provide localized and Unicode versions of */ + /* this string. Applications should use the */ + /* format specific interface to access them. */ + /* Can be NULL (e.g., in fonts embedded in a */ + /* PDF file). */ + /* */ + /* In case the font doesn't provide a specific */ + /* family name entry, FreeType tries to */ + /* synthesize one, deriving it from other name */ + /* entries. */ + /* */ + /* style_name :: The face's style name. This is an ASCII */ + /* string, usually in English, that describes */ + /* the typeface's style (like `Italic', */ + /* `Bold', `Condensed', etc). Not all font */ + /* formats provide a style name, so this field */ + /* is optional, and can be set to NULL. As */ + /* for `family_name', some formats provide */ + /* localized and Unicode versions of this */ + /* string. Applications should use the format */ + /* specific interface to access them. */ + /* */ + /* num_fixed_sizes :: The number of bitmap strikes in the face. */ + /* Even if the face is scalable, there might */ + /* still be bitmap strikes, which are called */ + /* `sbits' in that case. */ + /* */ + /* available_sizes :: An array of @FT_Bitmap_Size for all bitmap */ + /* strikes in the face. It is set to NULL if */ + /* there is no bitmap strike. */ + /* */ + /* Note that FreeType tries to sanitize the */ + /* strike data since they are sometimes sloppy */ + /* or incorrect, but this can easily fail. */ + /* */ + /* num_charmaps :: The number of charmaps in the face. */ + /* */ + /* charmaps :: An array of the charmaps of the face. */ + /* */ + /* generic :: A field reserved for client uses. See the */ + /* @FT_Generic type description. */ + /* */ + /* bbox :: The font bounding box. Coordinates are */ + /* expressed in font units (see */ + /* `units_per_EM'). The box is large enough */ + /* to contain any glyph from the font. Thus, */ + /* `bbox.yMax' can be seen as the `maximum */ + /* ascender', and `bbox.yMin' as the `minimum */ + /* descender'. Only relevant for scalable */ + /* formats. */ + /* */ + /* Note that the bounding box might be off by */ + /* (at least) one pixel for hinted fonts. See */ + /* @FT_Size_Metrics for further discussion. */ + /* */ + /* units_per_EM :: The number of font units per EM square for */ + /* this face. This is typically 2048 for */ + /* TrueType fonts, and 1000 for Type~1 fonts. */ + /* Only relevant for scalable formats. */ + /* */ + /* ascender :: The typographic ascender of the face, */ + /* expressed in font units. For font formats */ + /* not having this information, it is set to */ + /* `bbox.yMax'. Only relevant for scalable */ + /* formats. */ + /* */ + /* descender :: The typographic descender of the face, */ + /* expressed in font units. For font formats */ + /* not having this information, it is set to */ + /* `bbox.yMin'. Note that this field is */ + /* negative for values below the baseline. */ + /* Only relevant for scalable formats. */ + /* */ + /* height :: This value is the vertical distance */ + /* between two consecutive baselines, */ + /* expressed in font units. It is always */ + /* positive. Only relevant for scalable */ + /* formats. */ + /* */ + /* If you want the global glyph height, use */ + /* `ascender - descender'. */ + /* */ + /* max_advance_width :: The maximum advance width, in font units, */ + /* for all glyphs in this face. This can be */ + /* used to make word wrapping computations */ + /* faster. Only relevant for scalable */ + /* formats. */ + /* */ + /* max_advance_height :: The maximum advance height, in font units, */ + /* for all glyphs in this face. This is only */ + /* relevant for vertical layouts, and is set */ + /* to `height' for fonts that do not provide */ + /* vertical metrics. Only relevant for */ + /* scalable formats. */ + /* */ + /* underline_position :: The position, in font units, of the */ + /* underline line for this face. It is the */ + /* center of the underlining stem. Only */ + /* relevant for scalable formats. */ + /* */ + /* underline_thickness :: The thickness, in font units, of the */ + /* underline for this face. Only relevant for */ + /* scalable formats. */ + /* */ + /* glyph :: The face's associated glyph slot(s). */ + /* */ + /* size :: The current active size for this face. */ + /* */ + /* charmap :: The current active charmap for this face. */ + /* */ + /* <Note> */ + /* Fields may be changed after a call to @FT_Attach_File or */ + /* @FT_Attach_Stream. */ + /* */ + /* For an OpenType variation font, the values of the following fields */ + /* can change after a call to @FT_Set_Var_Design_Coordinates (and */ + /* friends) if the font contains an `MVAR' table: `ascender', */ + /* `descender', `height', `underline_position', and */ + /* `underline_thickness'. */ + /* */ + /* Especially for TrueType fonts see also the documentation for */ + /* @FT_Size_Metrics. */ + /* */ + typedef struct FT_FaceRec_ + { + FT_Long num_faces; + FT_Long face_index; + + FT_Long face_flags; + FT_Long style_flags; + + FT_Long num_glyphs; + + FT_String* family_name; + FT_String* style_name; + + FT_Int num_fixed_sizes; + FT_Bitmap_Size* available_sizes; + + FT_Int num_charmaps; + FT_CharMap* charmaps; + + FT_Generic generic; + + /*# The following member variables (down to `underline_thickness') */ + /*# are only relevant to scalable outlines; cf. @FT_Bitmap_Size */ + /*# for bitmap fonts. */ + FT_BBox bbox; + + FT_UShort units_per_EM; + FT_Short ascender; + FT_Short descender; + FT_Short height; + + FT_Short max_advance_width; + FT_Short max_advance_height; + + FT_Short underline_position; + FT_Short underline_thickness; + + FT_GlyphSlot glyph; + FT_Size size; + FT_CharMap charmap; + + /*@private begin */ + + FT_Driver driver; + FT_Memory memory; + FT_Stream stream; + + FT_ListRec sizes_list; + + FT_Generic autohint; /* face-specific auto-hinter data */ + void* extensions; /* unused */ + + FT_Face_Internal internal; + + /*@private end */ + + } FT_FaceRec; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_FACE_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the `face_flags' field of the */ + /* @FT_FaceRec structure. They inform client applications of */ + /* properties of the corresponding face. */ + /* */ + /* <Values> */ + /* FT_FACE_FLAG_SCALABLE :: */ + /* The face contains outline glyphs. Note that a face can contain */ + /* bitmap strikes also, i.e., a face can have both this flag and */ + /* @FT_FACE_FLAG_FIXED_SIZES set. */ + /* */ + /* FT_FACE_FLAG_FIXED_SIZES :: */ + /* The face contains bitmap strikes. See also the */ + /* `num_fixed_sizes' and `available_sizes' fields of @FT_FaceRec. */ + /* */ + /* FT_FACE_FLAG_FIXED_WIDTH :: */ + /* The face contains fixed-width characters (like Courier, Lucida, */ + /* MonoType, etc.). */ + /* */ + /* FT_FACE_FLAG_SFNT :: */ + /* The face uses the SFNT storage scheme. For now, this means */ + /* TrueType and OpenType. */ + /* */ + /* FT_FACE_FLAG_HORIZONTAL :: */ + /* The face contains horizontal glyph metrics. This should be set */ + /* for all common formats. */ + /* */ + /* FT_FACE_FLAG_VERTICAL :: */ + /* The face contains vertical glyph metrics. This is only */ + /* available in some formats, not all of them. */ + /* */ + /* FT_FACE_FLAG_KERNING :: */ + /* The face contains kerning information. If set, the kerning */ + /* distance can be retrieved using the function @FT_Get_Kerning. */ + /* Otherwise the function always return the vector (0,0). Note */ + /* that FreeType doesn't handle kerning data from the SFNT `GPOS' */ + /* table (as present in many OpenType fonts). */ + /* */ + /* FT_FACE_FLAG_FAST_GLYPHS :: */ + /* THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT. */ + /* */ + /* FT_FACE_FLAG_MULTIPLE_MASTERS :: */ + /* The face contains multiple masters and is capable of */ + /* interpolating between them. Supported formats are Adobe MM, */ + /* TrueType GX, and OpenType variation fonts. */ + /* */ + /* See section @multiple_masters for API details. */ + /* */ + /* FT_FACE_FLAG_GLYPH_NAMES :: */ + /* The face contains glyph names, which can be retrieved using */ + /* @FT_Get_Glyph_Name. Note that some TrueType fonts contain */ + /* broken glyph name tables. Use the function */ + /* @FT_Has_PS_Glyph_Names when needed. */ + /* */ + /* FT_FACE_FLAG_EXTERNAL_STREAM :: */ + /* Used internally by FreeType to indicate that a face's stream was */ + /* provided by the client application and should not be destroyed */ + /* when @FT_Done_Face is called. Don't read or test this flag. */ + /* */ + /* FT_FACE_FLAG_HINTER :: */ + /* The font driver has a hinting machine of its own. For example, */ + /* with TrueType fonts, it makes sense to use data from the SFNT */ + /* `gasp' table only if the native TrueType hinting engine (with */ + /* the bytecode interpreter) is available and active. */ + /* */ + /* FT_FACE_FLAG_CID_KEYED :: */ + /* The face is CID-keyed. In that case, the face is not accessed */ + /* by glyph indices but by CID values. For subsetted CID-keyed */ + /* fonts this has the consequence that not all index values are a */ + /* valid argument to @FT_Load_Glyph. Only the CID values for which */ + /* corresponding glyphs in the subsetted font exist make */ + /* `FT_Load_Glyph' return successfully; in all other cases you get */ + /* an `FT_Err_Invalid_Argument' error. */ + /* */ + /* Note that CID-keyed fonts that are in an SFNT wrapper (this is, */ + /* all OpenType/CFF fonts) don't have this flag set since the */ + /* glyphs are accessed in the normal way (using contiguous */ + /* indices); the `CID-ness' isn't visible to the application. */ + /* */ + /* FT_FACE_FLAG_TRICKY :: */ + /* The face is `tricky', this is, it always needs the font format's */ + /* native hinting engine to get a reasonable result. A typical */ + /* example is the old Chinese font `mingli.ttf' (but not */ + /* `mingliu.ttc') that uses TrueType bytecode instructions to move */ + /* and scale all of its subglyphs. */ + /* */ + /* It is not possible to auto-hint such fonts using */ + /* @FT_LOAD_FORCE_AUTOHINT; it will also ignore */ + /* @FT_LOAD_NO_HINTING. You have to set both @FT_LOAD_NO_HINTING */ + /* and @FT_LOAD_NO_AUTOHINT to really disable hinting; however, you */ + /* probably never want this except for demonstration purposes. */ + /* */ + /* Currently, there are about a dozen TrueType fonts in the list of */ + /* tricky fonts; they are hard-coded in file `ttobjs.c'. */ + /* */ + /* FT_FACE_FLAG_COLOR :: */ + /* [Since 2.5.1] The face has color glyph tables. To access color */ + /* glyphs use @FT_LOAD_COLOR. */ + /* */ + /* FT_FACE_FLAG_VARIATION :: */ + /* [Since 2.9] Set if the current face (or named instance) has been */ + /* altered with @FT_Set_MM_Design_Coordinates, */ + /* @FT_Set_Var_Design_Coordinates, or */ + /* @FT_Set_Var_Blend_Coordinates. This flag is unset by a call to */ + /* @FT_Set_Named_Instance. */ + /* */ +#define FT_FACE_FLAG_SCALABLE ( 1L << 0 ) +#define FT_FACE_FLAG_FIXED_SIZES ( 1L << 1 ) +#define FT_FACE_FLAG_FIXED_WIDTH ( 1L << 2 ) +#define FT_FACE_FLAG_SFNT ( 1L << 3 ) +#define FT_FACE_FLAG_HORIZONTAL ( 1L << 4 ) +#define FT_FACE_FLAG_VERTICAL ( 1L << 5 ) +#define FT_FACE_FLAG_KERNING ( 1L << 6 ) +#define FT_FACE_FLAG_FAST_GLYPHS ( 1L << 7 ) +#define FT_FACE_FLAG_MULTIPLE_MASTERS ( 1L << 8 ) +#define FT_FACE_FLAG_GLYPH_NAMES ( 1L << 9 ) +#define FT_FACE_FLAG_EXTERNAL_STREAM ( 1L << 10 ) +#define FT_FACE_FLAG_HINTER ( 1L << 11 ) +#define FT_FACE_FLAG_CID_KEYED ( 1L << 12 ) +#define FT_FACE_FLAG_TRICKY ( 1L << 13 ) +#define FT_FACE_FLAG_COLOR ( 1L << 14 ) +#define FT_FACE_FLAG_VARIATION ( 1L << 15 ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_HORIZONTAL( face ) + * + * @description: + * A macro that returns true whenever a face object contains + * horizontal metrics (this is true for all font formats though). + * + * @also: + * @FT_HAS_VERTICAL can be used to check for vertical metrics. + * + */ +#define FT_HAS_HORIZONTAL( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_HORIZONTAL ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_VERTICAL( face ) + * + * @description: + * A macro that returns true whenever a face object contains real + * vertical metrics (and not only synthesized ones). + * + */ +#define FT_HAS_VERTICAL( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_VERTICAL ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_KERNING( face ) + * + * @description: + * A macro that returns true whenever a face object contains kerning + * data that can be accessed with @FT_Get_Kerning. + * + */ +#define FT_HAS_KERNING( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_KERNING ) + + + /************************************************************************* + * + * @macro: + * FT_IS_SCALABLE( face ) + * + * @description: + * A macro that returns true whenever a face object contains a scalable + * font face (true for TrueType, Type~1, Type~42, CID, OpenType/CFF, + * and PFR font formats). + * + */ +#define FT_IS_SCALABLE( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_SCALABLE ) + + + /************************************************************************* + * + * @macro: + * FT_IS_SFNT( face ) + * + * @description: + * A macro that returns true whenever a face object contains a font + * whose format is based on the SFNT storage scheme. This usually + * means: TrueType fonts, OpenType fonts, as well as SFNT-based embedded + * bitmap fonts. + * + * If this macro is true, all functions defined in @FT_SFNT_NAMES_H and + * @FT_TRUETYPE_TABLES_H are available. + * + */ +#define FT_IS_SFNT( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_SFNT ) + + + /************************************************************************* + * + * @macro: + * FT_IS_FIXED_WIDTH( face ) + * + * @description: + * A macro that returns true whenever a face object contains a font face + * that contains fixed-width (or `monospace', `fixed-pitch', etc.) + * glyphs. + * + */ +#define FT_IS_FIXED_WIDTH( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_FIXED_SIZES( face ) + * + * @description: + * A macro that returns true whenever a face object contains some + * embedded bitmaps. See the `available_sizes' field of the + * @FT_FaceRec structure. + * + */ +#define FT_HAS_FIXED_SIZES( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_FIXED_SIZES ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_FAST_GLYPHS( face ) + * + * @description: + * Deprecated. + * + */ +#define FT_HAS_FAST_GLYPHS( face ) 0 + + + /************************************************************************* + * + * @macro: + * FT_HAS_GLYPH_NAMES( face ) + * + * @description: + * A macro that returns true whenever a face object contains some glyph + * names that can be accessed through @FT_Get_Glyph_Name. + * + */ +#define FT_HAS_GLYPH_NAMES( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_MULTIPLE_MASTERS( face ) + * + * @description: + * A macro that returns true whenever a face object contains some + * multiple masters. The functions provided by @FT_MULTIPLE_MASTERS_H + * are then available to choose the exact design you want. + * + */ +#define FT_HAS_MULTIPLE_MASTERS( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS ) + + + /************************************************************************* + * + * @macro: + * FT_IS_NAMED_INSTANCE( face ) + * + * @description: + * A macro that returns true whenever a face object is a named instance + * of a GX or OpenType variation font. + * + * [Since 2.9] Changing the design coordinates with + * @FT_Set_Var_Design_Coordinates or @FT_Set_Var_Blend_Coordinates does + * not influence the return value of this macro (only + * @FT_Set_Named_Instance does that). + * + * @since: + * 2.7 + * + */ +#define FT_IS_NAMED_INSTANCE( face ) \ + ( (face)->face_index & 0x7FFF0000L ) + + + /************************************************************************* + * + * @macro: + * FT_IS_VARIATION( face ) + * + * @description: + * A macro that returns true whenever a face object has been altered + * by @FT_Set_MM_Design_Coordinates, @FT_Set_Var_Design_Coordinates, or + * @FT_Set_Var_Blend_Coordinates. + * + * @since: + * 2.9 + * + */ +#define FT_IS_VARIATION( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_VARIATION ) + + + /************************************************************************* + * + * @macro: + * FT_IS_CID_KEYED( face ) + * + * @description: + * A macro that returns true whenever a face object contains a CID-keyed + * font. See the discussion of @FT_FACE_FLAG_CID_KEYED for more + * details. + * + * If this macro is true, all functions defined in @FT_CID_H are + * available. + * + */ +#define FT_IS_CID_KEYED( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_CID_KEYED ) + + + /************************************************************************* + * + * @macro: + * FT_IS_TRICKY( face ) + * + * @description: + * A macro that returns true whenever a face represents a `tricky' font. + * See the discussion of @FT_FACE_FLAG_TRICKY for more details. + * + */ +#define FT_IS_TRICKY( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_TRICKY ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_COLOR( face ) + * + * @description: + * A macro that returns true whenever a face object contains + * tables for color glyphs. + * + * @since: + * 2.5.1 + * + */ +#define FT_HAS_COLOR( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_COLOR ) + + + /*************************************************************************/ + /* */ + /* <Const> */ + /* FT_STYLE_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags to indicate the style of a given face. These */ + /* are used in the `style_flags' field of @FT_FaceRec. */ + /* */ + /* <Values> */ + /* FT_STYLE_FLAG_ITALIC :: */ + /* The face style is italic or oblique. */ + /* */ + /* FT_STYLE_FLAG_BOLD :: */ + /* The face is bold. */ + /* */ + /* <Note> */ + /* The style information as provided by FreeType is very basic. More */ + /* details are beyond the scope and should be done on a higher level */ + /* (for example, by analyzing various fields of the `OS/2' table in */ + /* SFNT based fonts). */ + /* */ +#define FT_STYLE_FLAG_ITALIC ( 1 << 0 ) +#define FT_STYLE_FLAG_BOLD ( 1 << 1 ) + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Size_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Size_InternalRec' structure, used to */ + /* model private data of a given @FT_Size object. */ + /* */ + typedef struct FT_Size_InternalRec_* FT_Size_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_Metrics */ + /* */ + /* <Description> */ + /* The size metrics structure gives the metrics of a size object. */ + /* */ + /* <Fields> */ + /* x_ppem :: The width of the scaled EM square in pixels, hence */ + /* the term `ppem' (pixels per EM). It is also */ + /* referred to as `nominal width'. */ + /* */ + /* y_ppem :: The height of the scaled EM square in pixels, */ + /* hence the term `ppem' (pixels per EM). It is also */ + /* referred to as `nominal height'. */ + /* */ + /* x_scale :: A 16.16 fractional scaling value to convert */ + /* horizontal metrics from font units to 26.6 */ + /* fractional pixels. Only relevant for scalable */ + /* font formats. */ + /* */ + /* y_scale :: A 16.16 fractional scaling value to convert */ + /* vertical metrics from font units to 26.6 */ + /* fractional pixels. Only relevant for scalable */ + /* font formats. */ + /* */ + /* ascender :: The ascender in 26.6 fractional pixels, rounded up */ + /* to an integer value. See @FT_FaceRec for the */ + /* details. */ + /* */ + /* descender :: The descender in 26.6 fractional pixels, rounded */ + /* down to an integer value. See @FT_FaceRec for the */ + /* details. */ + /* */ + /* height :: The height in 26.6 fractional pixels, rounded to */ + /* an integer value. See @FT_FaceRec for the */ + /* details. */ + /* */ + /* max_advance :: The maximum advance width in 26.6 fractional */ + /* pixels, rounded to an integer value. See */ + /* @FT_FaceRec for the details. */ + /* */ + /* <Note> */ + /* The scaling values, if relevant, are determined first during a */ + /* size changing operation. The remaining fields are then set by the */ + /* driver. For scalable formats, they are usually set to scaled */ + /* values of the corresponding fields in @FT_FaceRec. Some values */ + /* like ascender or descender are rounded for historical reasons; */ + /* more precise values (for outline fonts) can be derived by scaling */ + /* the corresponding @FT_FaceRec values manually, with code similar */ + /* to the following. */ + /* */ + /* { */ + /* scaled_ascender = FT_MulFix( face->ascender, */ + /* size_metrics->y_scale ); */ + /* } */ + /* */ + /* Note that due to glyph hinting and the selected rendering mode */ + /* these values are usually not exact; consequently, they must be */ + /* treated as unreliable with an error margin of at least one pixel! */ + /* */ + /* Indeed, the only way to get the exact metrics is to render _all_ */ + /* glyphs. As this would be a definite performance hit, it is up to */ + /* client applications to perform such computations. */ + /* */ + /* The `FT_Size_Metrics' structure is valid for bitmap fonts also. */ + /* */ + /* */ + /* *TrueType* *fonts* *with* *native* *bytecode* *hinting* */ + /* */ + /* All applications that handle TrueType fonts with native hinting */ + /* must be aware that TTFs expect different rounding of vertical font */ + /* dimensions. The application has to cater for this, especially if */ + /* it wants to rely on a TTF's vertical data (for example, to */ + /* properly align box characters vertically). */ + /* */ + /* Only the application knows _in_ _advance_ that it is going to use */ + /* native hinting for TTFs! FreeType, on the other hand, selects the */ + /* hinting mode not at the time of creating an @FT_Size object but */ + /* much later, namely while calling @FT_Load_Glyph. */ + /* */ + /* Here is some pseudo code that illustrates a possible solution. */ + /* */ + /* { */ + /* font_format = FT_Get_Font_Format( face ); */ + /* */ + /* if ( !strcmp( font_format, "TrueType" ) && */ + /* do_native_bytecode_hinting ) */ + /* { */ + /* ascender = ROUND( FT_MulFix( face->ascender, */ + /* size_metrics->y_scale ) ); */ + /* descender = ROUND( FT_MulFix( face->descender, */ + /* size_metrics->y_scale ) ); */ + /* } */ + /* else */ + /* { */ + /* ascender = size_metrics->ascender; */ + /* descender = size_metrics->descender; */ + /* } */ + /* */ + /* height = size_metrics->height; */ + /* max_advance = size_metrics->max_advance; */ + /* } */ + /* */ + typedef struct FT_Size_Metrics_ + { + FT_UShort x_ppem; /* horizontal pixels per EM */ + FT_UShort y_ppem; /* vertical pixels per EM */ + + FT_Fixed x_scale; /* scaling values used to convert font */ + FT_Fixed y_scale; /* units to 26.6 fractional pixels */ + + FT_Pos ascender; /* ascender in 26.6 frac. pixels */ + FT_Pos descender; /* descender in 26.6 frac. pixels */ + FT_Pos height; /* text height in 26.6 frac. pixels */ + FT_Pos max_advance; /* max horizontal advance, in 26.6 pixels */ + + } FT_Size_Metrics; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SizeRec */ + /* */ + /* <Description> */ + /* FreeType root size class structure. A size object models a face */ + /* object at a given size. */ + /* */ + /* <Fields> */ + /* face :: Handle to the parent face object. */ + /* */ + /* generic :: A typeless pointer, unused by the FreeType library or */ + /* any of its drivers. It can be used by client */ + /* applications to link their own data to each size */ + /* object. */ + /* */ + /* metrics :: Metrics for this size object. This field is read-only. */ + /* */ + typedef struct FT_SizeRec_ + { + FT_Face face; /* parent face object */ + FT_Generic generic; /* generic pointer for client uses */ + FT_Size_Metrics metrics; /* size metrics */ + FT_Size_Internal internal; + + } FT_SizeRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SubGlyph */ + /* */ + /* <Description> */ + /* The subglyph structure is an internal object used to describe */ + /* subglyphs (for example, in the case of composites). */ + /* */ + /* <Note> */ + /* The subglyph implementation is not part of the high-level API, */ + /* hence the forward structure declaration. */ + /* */ + /* You can however retrieve subglyph information with */ + /* @FT_Get_SubGlyph_Info. */ + /* */ + typedef struct FT_SubGlyphRec_* FT_SubGlyph; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Slot_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Slot_InternalRec' structure, used to */ + /* model private data of a given @FT_GlyphSlot object. */ + /* */ + typedef struct FT_Slot_InternalRec_* FT_Slot_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_GlyphSlotRec */ + /* */ + /* <Description> */ + /* FreeType root glyph slot class structure. A glyph slot is a */ + /* container where individual glyphs can be loaded, be they in */ + /* outline or bitmap format. */ + /* */ + /* <Fields> */ + /* library :: A handle to the FreeType library instance */ + /* this slot belongs to. */ + /* */ + /* face :: A handle to the parent face object. */ + /* */ + /* next :: In some cases (like some font tools), several */ + /* glyph slots per face object can be a good */ + /* thing. As this is rare, the glyph slots are */ + /* listed through a direct, single-linked list */ + /* using its `next' field. */ + /* */ + /* generic :: A typeless pointer unused by the FreeType */ + /* library or any of its drivers. It can be */ + /* used by client applications to link their own */ + /* data to each glyph slot object. */ + /* */ + /* metrics :: The metrics of the last loaded glyph in the */ + /* slot. The returned values depend on the last */ + /* load flags (see the @FT_Load_Glyph API */ + /* function) and can be expressed either in 26.6 */ + /* fractional pixels or font units. */ + /* */ + /* Note that even when the glyph image is */ + /* transformed, the metrics are not. */ + /* */ + /* linearHoriAdvance :: The advance width of the unhinted glyph. */ + /* Its value is expressed in 16.16 fractional */ + /* pixels, unless @FT_LOAD_LINEAR_DESIGN is set */ + /* when loading the glyph. This field can be */ + /* important to perform correct WYSIWYG layout. */ + /* Only relevant for outline glyphs. */ + /* */ + /* linearVertAdvance :: The advance height of the unhinted glyph. */ + /* Its value is expressed in 16.16 fractional */ + /* pixels, unless @FT_LOAD_LINEAR_DESIGN is set */ + /* when loading the glyph. This field can be */ + /* important to perform correct WYSIWYG layout. */ + /* Only relevant for outline glyphs. */ + /* */ + /* advance :: This shorthand is, depending on */ + /* @FT_LOAD_IGNORE_TRANSFORM, the transformed */ + /* (hinted) advance width for the glyph, in 26.6 */ + /* fractional pixel format. As specified with */ + /* @FT_LOAD_VERTICAL_LAYOUT, it uses either the */ + /* `horiAdvance' or the `vertAdvance' value of */ + /* `metrics' field. */ + /* */ + /* format :: This field indicates the format of the image */ + /* contained in the glyph slot. Typically */ + /* @FT_GLYPH_FORMAT_BITMAP, */ + /* @FT_GLYPH_FORMAT_OUTLINE, or */ + /* @FT_GLYPH_FORMAT_COMPOSITE, but other values */ + /* are possible. */ + /* */ + /* bitmap :: This field is used as a bitmap descriptor. */ + /* Note that the address and content of the */ + /* bitmap buffer can change between calls of */ + /* @FT_Load_Glyph and a few other functions. */ + /* */ + /* bitmap_left :: The bitmap's left bearing expressed in */ + /* integer pixels. */ + /* */ + /* bitmap_top :: The bitmap's top bearing expressed in integer */ + /* pixels. This is the distance from the */ + /* baseline to the top-most glyph scanline, */ + /* upwards y~coordinates being *positive*. */ + /* */ + /* outline :: The outline descriptor for the current glyph */ + /* image if its format is */ + /* @FT_GLYPH_FORMAT_OUTLINE. Once a glyph is */ + /* loaded, `outline' can be transformed, */ + /* distorted, emboldened, etc. However, it must */ + /* not be freed. */ + /* */ + /* num_subglyphs :: The number of subglyphs in a composite glyph. */ + /* This field is only valid for the composite */ + /* glyph format that should normally only be */ + /* loaded with the @FT_LOAD_NO_RECURSE flag. */ + /* */ + /* subglyphs :: An array of subglyph descriptors for */ + /* composite glyphs. There are `num_subglyphs' */ + /* elements in there. Currently internal to */ + /* FreeType. */ + /* */ + /* control_data :: Certain font drivers can also return the */ + /* control data for a given glyph image (e.g. */ + /* TrueType bytecode, Type~1 charstrings, etc.). */ + /* This field is a pointer to such data; it is */ + /* currently internal to FreeType. */ + /* */ + /* control_len :: This is the length in bytes of the control */ + /* data. Currently internal to FreeType. */ + /* */ + /* other :: Reserved. */ + /* */ + /* lsb_delta :: The difference between hinted and unhinted */ + /* left side bearing while auto-hinting is */ + /* active. Zero otherwise. */ + /* */ + /* rsb_delta :: The difference between hinted and unhinted */ + /* right side bearing while auto-hinting is */ + /* active. Zero otherwise. */ + /* */ + /* <Note> */ + /* If @FT_Load_Glyph is called with default flags (see */ + /* @FT_LOAD_DEFAULT) the glyph image is loaded in the glyph slot in */ + /* its native format (e.g., an outline glyph for TrueType and Type~1 */ + /* formats). [Since 2.9] The prospective bitmap metrics are */ + /* calculated according to @FT_LOAD_TARGET_XXX and other flags even */ + /* for the outline glyph, even if @FT_LOAD_RENDER is not set. */ + /* */ + /* This image can later be converted into a bitmap by calling */ + /* @FT_Render_Glyph. This function searches the current renderer for */ + /* the native image's format, then invokes it. */ + /* */ + /* The renderer is in charge of transforming the native image through */ + /* the slot's face transformation fields, then converting it into a */ + /* bitmap that is returned in `slot->bitmap'. */ + /* */ + /* Note that `slot->bitmap_left' and `slot->bitmap_top' are also used */ + /* to specify the position of the bitmap relative to the current pen */ + /* position (e.g., coordinates (0,0) on the baseline). Of course, */ + /* `slot->format' is also changed to @FT_GLYPH_FORMAT_BITMAP. */ + /* */ + /* Here is a small pseudo code fragment that shows how to use */ + /* `lsb_delta' and `rsb_delta' to do fractional positioning of */ + /* glyphs: */ + /* */ + /* { */ + /* FT_GlyphSlot slot = face->glyph; */ + /* FT_Pos origin_x = 0; */ + /* */ + /* */ + /* for all glyphs do */ + /* <load glyph with `FT_Load_Glyph'> */ + /* */ + /* FT_Outline_Translate( slot->outline, origin_x & 63, 0 ); */ + /* */ + /* <save glyph image, or render glyph, or ...> */ + /* */ + /* <compute kern between current and next glyph */ + /* and add it to `origin_x'> */ + /* */ + /* origin_x += slot->advance.x; */ + /* origin_x += slot->rsb_delta - slot->lsb_delta; */ + /* endfor */ + /* } */ + /* */ + /* Here is another small pseudo code fragment that shows how to use */ + /* `lsb_delta' and `rsb_delta' to improve integer positioning of */ + /* glyphs: */ + /* */ + /* { */ + /* FT_GlyphSlot slot = face->glyph; */ + /* FT_Pos origin_x = 0; */ + /* FT_Pos prev_rsb_delta = 0; */ + /* */ + /* */ + /* for all glyphs do */ + /* <compute kern between current and previous glyph */ + /* and add it to `origin_x'> */ + /* */ + /* <load glyph with `FT_Load_Glyph'> */ + /* */ + /* if ( prev_rsb_delta - slot->lsb_delta > 32 ) */ + /* origin_x -= 64; */ + /* else if ( prev_rsb_delta - slot->lsb_delta < -31 ) */ + /* origin_x += 64; */ + /* */ + /* prev_rsb_delta = slot->rsb_delta; */ + /* */ + /* <save glyph image, or render glyph, or ...> */ + /* */ + /* origin_x += slot->advance.x; */ + /* endfor */ + /* } */ + /* */ + /* If you use strong auto-hinting, you *must* apply these delta */ + /* values! Otherwise you will experience far too large inter-glyph */ + /* spacing at small rendering sizes in most cases. Note that it */ + /* doesn't harm to use the above code for other hinting modes also, */ + /* since the delta values are zero then. */ + /* */ + typedef struct FT_GlyphSlotRec_ + { + FT_Library library; + FT_Face face; + FT_GlyphSlot next; + FT_UInt reserved; /* retained for binary compatibility */ + FT_Generic generic; + + FT_Glyph_Metrics metrics; + FT_Fixed linearHoriAdvance; + FT_Fixed linearVertAdvance; + FT_Vector advance; + + FT_Glyph_Format format; + + FT_Bitmap bitmap; + FT_Int bitmap_left; + FT_Int bitmap_top; + + FT_Outline outline; + + FT_UInt num_subglyphs; + FT_SubGlyph subglyphs; + + void* control_data; + long control_len; + + FT_Pos lsb_delta; + FT_Pos rsb_delta; + + void* other; + + FT_Slot_Internal internal; + + } FT_GlyphSlotRec; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* F U N C T I O N S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Init_FreeType */ + /* */ + /* <Description> */ + /* Initialize a new FreeType library object. The set of modules */ + /* that are registered by this function is determined at build time. */ + /* */ + /* <Output> */ + /* alibrary :: A handle to a new library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* In case you want to provide your own memory allocating routines, */ + /* use @FT_New_Library instead, followed by a call to */ + /* @FT_Add_Default_Modules (or a series of calls to @FT_Add_Module) */ + /* and @FT_Set_Default_Properties. */ + /* */ + /* See the documentation of @FT_Library and @FT_Face for */ + /* multi-threading issues. */ + /* */ + /* If you need reference-counting (cf. @FT_Reference_Library), use */ + /* @FT_New_Library and @FT_Done_Library. */ + /* */ + /* If compilation option FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES is */ + /* set, this function reads the `FREETYPE_PROPERTIES' environment */ + /* variable to control driver properties. See section @properties */ + /* for more. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Init_FreeType( FT_Library *alibrary ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_FreeType */ + /* */ + /* <Description> */ + /* Destroy a given FreeType library object and all of its children, */ + /* including resources, drivers, faces, sizes, etc. */ + /* */ + /* <Input> */ + /* library :: A handle to the target library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_FreeType( FT_Library library ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_OPEN_XXX */ + /* */ + /* <Description> */ + /* A list of bit field constants used within the `flags' field of the */ + /* @FT_Open_Args structure. */ + /* */ + /* <Values> */ + /* FT_OPEN_MEMORY :: This is a memory-based stream. */ + /* */ + /* FT_OPEN_STREAM :: Copy the stream from the `stream' field. */ + /* */ + /* FT_OPEN_PATHNAME :: Create a new input stream from a C~path */ + /* name. */ + /* */ + /* FT_OPEN_DRIVER :: Use the `driver' field. */ + /* */ + /* FT_OPEN_PARAMS :: Use the `num_params' and `params' fields. */ + /* */ + /* <Note> */ + /* The `FT_OPEN_MEMORY', `FT_OPEN_STREAM', and `FT_OPEN_PATHNAME' */ + /* flags are mutually exclusive. */ + /* */ +#define FT_OPEN_MEMORY 0x1 +#define FT_OPEN_STREAM 0x2 +#define FT_OPEN_PATHNAME 0x4 +#define FT_OPEN_DRIVER 0x8 +#define FT_OPEN_PARAMS 0x10 + + + /* these constants are deprecated; use the corresponding `FT_OPEN_XXX' */ + /* values instead */ +#define ft_open_memory FT_OPEN_MEMORY +#define ft_open_stream FT_OPEN_STREAM +#define ft_open_pathname FT_OPEN_PATHNAME +#define ft_open_driver FT_OPEN_DRIVER +#define ft_open_params FT_OPEN_PARAMS + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Parameter */ + /* */ + /* <Description> */ + /* A simple structure to pass more or less generic parameters to */ + /* @FT_Open_Face and @FT_Face_Properties. */ + /* */ + /* <Fields> */ + /* tag :: A four-byte identification tag. */ + /* */ + /* data :: A pointer to the parameter data. */ + /* */ + /* <Note> */ + /* The ID and function of parameters are driver-specific. See */ + /* section @parameter_tags for more information. */ + /* */ + typedef struct FT_Parameter_ + { + FT_ULong tag; + FT_Pointer data; + + } FT_Parameter; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Open_Args */ + /* */ + /* <Description> */ + /* A structure to indicate how to open a new font file or stream. A */ + /* pointer to such a structure can be used as a parameter for the */ + /* functions @FT_Open_Face and @FT_Attach_Stream. */ + /* */ + /* <Fields> */ + /* flags :: A set of bit flags indicating how to use the */ + /* structure. */ + /* */ + /* memory_base :: The first byte of the file in memory. */ + /* */ + /* memory_size :: The size in bytes of the file in memory. */ + /* */ + /* pathname :: A pointer to an 8-bit file pathname. */ + /* */ + /* stream :: A handle to a source stream object. */ + /* */ + /* driver :: This field is exclusively used by @FT_Open_Face; */ + /* it simply specifies the font driver to use for */ + /* opening the face. If set to NULL, FreeType tries */ + /* to load the face with each one of the drivers in */ + /* its list. */ + /* */ + /* num_params :: The number of extra parameters. */ + /* */ + /* params :: Extra parameters passed to the font driver when */ + /* opening a new face. */ + /* */ + /* <Note> */ + /* The stream type is determined by the contents of `flags' that */ + /* are tested in the following order by @FT_Open_Face: */ + /* */ + /* If the @FT_OPEN_MEMORY bit is set, assume that this is a */ + /* memory file of `memory_size' bytes, located at `memory_address'. */ + /* The data are not copied, and the client is responsible for */ + /* releasing and destroying them _after_ the corresponding call to */ + /* @FT_Done_Face. */ + /* */ + /* Otherwise, if the @FT_OPEN_STREAM bit is set, assume that a */ + /* custom input stream `stream' is used. */ + /* */ + /* Otherwise, if the @FT_OPEN_PATHNAME bit is set, assume that this */ + /* is a normal file and use `pathname' to open it. */ + /* */ + /* If the @FT_OPEN_DRIVER bit is set, @FT_Open_Face only tries to */ + /* open the file with the driver whose handler is in `driver'. */ + /* */ + /* If the @FT_OPEN_PARAMS bit is set, the parameters given by */ + /* `num_params' and `params' is used. They are ignored otherwise. */ + /* */ + /* Ideally, both the `pathname' and `params' fields should be tagged */ + /* as `const'; this is missing for API backward compatibility. In */ + /* other words, applications should treat them as read-only. */ + /* */ + typedef struct FT_Open_Args_ + { + FT_UInt flags; + const FT_Byte* memory_base; + FT_Long memory_size; + FT_String* pathname; + FT_Stream stream; + FT_Module driver; + FT_Int num_params; + FT_Parameter* params; + + } FT_Open_Args; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face */ + /* */ + /* <Description> */ + /* Call @FT_Open_Face to open a font by its pathname. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* pathname :: A path to the font file. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Use @FT_Done_Face to destroy the created @FT_Face object (along */ + /* with its slot and sizes). */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face( FT_Library library, + const char* filepathname, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Memory_Face */ + /* */ + /* <Description> */ + /* Call @FT_Open_Face to open a font that has been loaded into */ + /* memory. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* file_base :: A pointer to the beginning of the font data. */ + /* */ + /* file_size :: The size of the memory chunk used by the font data. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You must not deallocate the memory before calling @FT_Done_Face. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Memory_Face( FT_Library library, + const FT_Byte* file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Open_Face */ + /* */ + /* <Description> */ + /* Create a face object from a given resource described by */ + /* @FT_Open_Args. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* args :: A pointer to an `FT_Open_Args' structure that must */ + /* be filled by the caller. */ + /* */ + /* face_index :: This field holds two different values. Bits 0-15 */ + /* are the index of the face in the font file (starting */ + /* with value~0). Set it to~0 if there is only one */ + /* face in the font file. */ + /* */ + /* [Since 2.6.1] Bits 16-30 are relevant to GX and */ + /* OpenType variation fonts only, specifying the named */ + /* instance index for the current face index (starting */ + /* with value~1; value~0 makes FreeType ignore named */ + /* instances). For non-variation fonts, bits 16-30 are */ + /* ignored. Assuming that you want to access the third */ + /* named instance in face~4, `face_index' should be set */ + /* to 0x00030004. If you want to access face~4 without */ + /* variation handling, simply set `face_index' to */ + /* value~4. */ + /* */ + /* `FT_Open_Face' and its siblings can be used to */ + /* quickly check whether the font format of a given */ + /* font resource is supported by FreeType. In general, */ + /* if the `face_index' argument is negative, the */ + /* function's return value is~0 if the font format is */ + /* recognized, or non-zero otherwise. The function */ + /* allocates a more or less empty face handle in */ + /* `*aface' (if `aface' isn't NULL); the only two */ + /* useful fields in this special case are */ + /* `face->num_faces' and `face->style_flags'. For any */ + /* negative value of `face_index', `face->num_faces' */ + /* gives the number of faces within the font file. For */ + /* the negative value `-(N+1)' (with `N' a non-negative */ + /* 16-bit value), bits 16-30 in `face->style_flags' */ + /* give the number of named instances in face `N' if we */ + /* have a variation font (or zero otherwise). After */ + /* examination, the returned @FT_Face structure should */ + /* be deallocated with a call to @FT_Done_Face. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Unlike FreeType 1.x, this function automatically creates a glyph */ + /* slot for the face object that can be accessed directly through */ + /* `face->glyph'. */ + /* */ + /* Each new face object created with this function also owns a */ + /* default @FT_Size object, accessible as `face->size'. */ + /* */ + /* One @FT_Library instance can have multiple face objects, this is, */ + /* @FT_Open_Face and its siblings can be called multiple times using */ + /* the same `library' argument. */ + /* */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Face. */ + /* */ + /* To loop over all faces, use code similar to the following snippet */ + /* (omitting the error handling). */ + /* */ + /* { */ + /* ... */ + /* FT_Face face; */ + /* FT_Long i, num_faces; */ + /* */ + /* */ + /* error = FT_Open_Face( library, args, -1, &face ); */ + /* if ( error ) { ... } */ + /* */ + /* num_faces = face->num_faces; */ + /* FT_Done_Face( face ); */ + /* */ + /* for ( i = 0; i < num_faces; i++ ) */ + /* { */ + /* ... */ + /* error = FT_Open_Face( library, args, i, &face ); */ + /* ... */ + /* FT_Done_Face( face ); */ + /* ... */ + /* } */ + /* } */ + /* */ + /* To loop over all valid values for `face_index', use something */ + /* similar to the following snippet, again without error handling. */ + /* The code accesses all faces immediately (thus only a single call */ + /* of `FT_Open_Face' within the do-loop), with and without named */ + /* instances. */ + /* */ + /* { */ + /* ... */ + /* FT_Face face; */ + /* */ + /* FT_Long num_faces = 0; */ + /* FT_Long num_instances = 0; */ + /* */ + /* FT_Long face_idx = 0; */ + /* FT_Long instance_idx = 0; */ + /* */ + /* */ + /* do */ + /* { */ + /* FT_Long id = ( instance_idx << 16 ) + face_idx; */ + /* */ + /* */ + /* error = FT_Open_Face( library, args, id, &face ); */ + /* if ( error ) { ... } */ + /* */ + /* num_faces = face->num_faces; */ + /* num_instances = face->style_flags >> 16; */ + /* */ + /* ... */ + /* */ + /* FT_Done_Face( face ); */ + /* */ + /* if ( instance_idx < num_instances ) */ + /* instance_idx++; */ + /* else */ + /* { */ + /* face_idx++; */ + /* instance_idx = 0; */ + /* } */ + /* */ + /* } while ( face_idx < num_faces ) */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_Open_Face( FT_Library library, + const FT_Open_Args* args, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Attach_File */ + /* */ + /* <Description> */ + /* Call @FT_Attach_Stream to attach a file. */ + /* */ + /* <InOut> */ + /* face :: The target face object. */ + /* */ + /* <Input> */ + /* filepathname :: The pathname. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Attach_File( FT_Face face, + const char* filepathname ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Attach_Stream */ + /* */ + /* <Description> */ + /* `Attach' data to a face object. Normally, this is used to read */ + /* additional information for the face object. For example, you can */ + /* attach an AFM file that comes with a Type~1 font to get the */ + /* kerning values and other metrics. */ + /* */ + /* <InOut> */ + /* face :: The target face object. */ + /* */ + /* <Input> */ + /* parameters :: A pointer to @FT_Open_Args that must be filled by */ + /* the caller. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The meaning of the `attach' (i.e., what really happens when the */ + /* new file is read) is not fixed by FreeType itself. It really */ + /* depends on the font format (and thus the font driver). */ + /* */ + /* Client applications are expected to know what they are doing */ + /* when invoking this function. Most drivers simply do not implement */ + /* file or stream attachments. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Attach_Stream( FT_Face face, + FT_Open_Args* parameters ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Reference_Face */ + /* */ + /* <Description> */ + /* A counter gets initialized to~1 at the time an @FT_Face structure */ + /* is created. This function increments the counter. @FT_Done_Face */ + /* then only destroys a face if the counter is~1, otherwise it simply */ + /* decrements the counter. */ + /* */ + /* This function helps in managing life-cycles of structures that */ + /* reference @FT_Face objects. */ + /* */ + /* <Input> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.4.2 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Reference_Face( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Face */ + /* */ + /* <Description> */ + /* Discard a given face object, as well as all of its child slots and */ + /* sizes. */ + /* */ + /* <Input> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Face. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Face( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Select_Size */ + /* */ + /* <Description> */ + /* Select a bitmap strike. To be more precise, this function sets */ + /* the scaling factors of the active @FT_Size object in a face so */ + /* that bitmaps from this particular strike are taken by */ + /* @FT_Load_Glyph and friends. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* strike_index :: The index of the bitmap strike in the */ + /* `available_sizes' field of @FT_FaceRec structure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* For bitmaps embedded in outline fonts it is common that only a */ + /* subset of the available glyphs at a given ppem value is available. */ + /* FreeType silently uses outlines if there is no bitmap for a given */ + /* glyph index. */ + /* */ + /* For GX and OpenType variation fonts, a bitmap strike makes sense */ + /* only if the default instance is active (this is, no glyph */ + /* variation takes place); otherwise, FreeType simply ignores bitmap */ + /* strikes. The same is true for all named instances that are */ + /* different from the default instance. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Select_Size( FT_Face face, + FT_Int strike_index ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Size_Request_Type */ + /* */ + /* <Description> */ + /* An enumeration type that lists the supported size request types, */ + /* i.e., what input size (in font units) maps to the requested output */ + /* size (in pixels, as computed from the arguments of */ + /* @FT_Size_Request). */ + /* */ + /* <Values> */ + /* FT_SIZE_REQUEST_TYPE_NOMINAL :: */ + /* The nominal size. The `units_per_EM' field of @FT_FaceRec is */ + /* used to determine both scaling values. */ + /* */ + /* This is the standard scaling found in most applications. In */ + /* particular, use this size request type for TrueType fonts if */ + /* they provide optical scaling or something similar. Note, */ + /* however, that `units_per_EM' is a rather abstract value which */ + /* bears no relation to the actual size of the glyphs in a font. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_REAL_DIM :: */ + /* The real dimension. The sum of the `ascender' and (minus of) */ + /* the `descender' fields of @FT_FaceRec is used to determine both */ + /* scaling values. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_BBOX :: */ + /* The font bounding box. The width and height of the `bbox' field */ + /* of @FT_FaceRec are used to determine the horizontal and vertical */ + /* scaling value, respectively. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_CELL :: */ + /* The `max_advance_width' field of @FT_FaceRec is used to */ + /* determine the horizontal scaling value; the vertical scaling */ + /* value is determined the same way as */ + /* @FT_SIZE_REQUEST_TYPE_REAL_DIM does. Finally, both scaling */ + /* values are set to the smaller one. This type is useful if you */ + /* want to specify the font size for, say, a window of a given */ + /* dimension and 80x24 cells. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_SCALES :: */ + /* Specify the scaling values directly. */ + /* */ + /* <Note> */ + /* The above descriptions only apply to scalable formats. For bitmap */ + /* formats, the behaviour is up to the driver. */ + /* */ + /* See the note section of @FT_Size_Metrics if you wonder how size */ + /* requesting relates to scaling values. */ + /* */ + typedef enum FT_Size_Request_Type_ + { + FT_SIZE_REQUEST_TYPE_NOMINAL, + FT_SIZE_REQUEST_TYPE_REAL_DIM, + FT_SIZE_REQUEST_TYPE_BBOX, + FT_SIZE_REQUEST_TYPE_CELL, + FT_SIZE_REQUEST_TYPE_SCALES, + + FT_SIZE_REQUEST_TYPE_MAX + + } FT_Size_Request_Type; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_RequestRec */ + /* */ + /* <Description> */ + /* A structure to model a size request. */ + /* */ + /* <Fields> */ + /* type :: See @FT_Size_Request_Type. */ + /* */ + /* width :: The desired width, given as a 26.6 fractional */ + /* point value (with 72pt = 1in). */ + /* */ + /* height :: The desired height, given as a 26.6 fractional */ + /* point value (with 72pt = 1in). */ + /* */ + /* horiResolution :: The horizontal resolution (dpi, i.e., pixels per */ + /* inch). If set to zero, `width' is treated as a */ + /* 26.6 fractional *pixel* value, which gets */ + /* internally rounded to an integer. */ + /* */ + /* vertResolution :: The vertical resolution (dpi, i.e., pixels per */ + /* inch). If set to zero, `height' is treated as a */ + /* 26.6 fractional *pixel* value, which gets */ + /* internally rounded to an integer. */ + /* */ + /* <Note> */ + /* If `width' is zero, the horizontal scaling value is set equal */ + /* to the vertical scaling value, and vice versa. */ + /* */ + /* If `type' is FT_SIZE_REQUEST_TYPE_SCALES, `width' and `height' are */ + /* interpreted directly as 16.16 fractional scaling values, without */ + /* any further modification, and both `horiResolution' and */ + /* `vertResolution' are ignored. */ + /* */ + typedef struct FT_Size_RequestRec_ + { + FT_Size_Request_Type type; + FT_Long width; + FT_Long height; + FT_UInt horiResolution; + FT_UInt vertResolution; + + } FT_Size_RequestRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_Request */ + /* */ + /* <Description> */ + /* A handle to a size request structure. */ + /* */ + typedef struct FT_Size_RequestRec_ *FT_Size_Request; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Request_Size */ + /* */ + /* <Description> */ + /* Resize the scale of the active @FT_Size object in a face. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* req :: A pointer to a @FT_Size_RequestRec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Although drivers may select the bitmap strike matching the */ + /* request, you should not rely on this if you intend to select a */ + /* particular bitmap strike. Use @FT_Select_Size instead in that */ + /* case. */ + /* */ + /* The relation between the requested size and the resulting glyph */ + /* size is dependent entirely on how the size is defined in the */ + /* source face. The font designer chooses the final size of each */ + /* glyph relative to this size. For more information refer to */ + /* `https://www.freetype.org/freetype2/docs/glyphs/glyphs-2.html'. */ + /* */ + /* Contrary to @FT_Set_Char_Size, this function doesn't have special */ + /* code to normalize zero-valued widths, heights, or resolutions */ + /* (which lead to errors in most cases). */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Request_Size( FT_Face face, + FT_Size_Request req ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Char_Size */ + /* */ + /* <Description> */ + /* Call @FT_Request_Size to request the nominal size (in points). */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* char_width :: The nominal width, in 26.6 fractional points. */ + /* */ + /* char_height :: The nominal height, in 26.6 fractional points. */ + /* */ + /* horz_resolution :: The horizontal resolution in dpi. */ + /* */ + /* vert_resolution :: The vertical resolution in dpi. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* While this function allows fractional points as input values, the */ + /* resulting ppem value for the given resolution is always rounded to */ + /* the nearest integer. */ + /* */ + /* If either the character width or height is zero, it is set equal */ + /* to the other value. */ + /* */ + /* If either the horizontal or vertical resolution is zero, it is set */ + /* equal to the other value. */ + /* */ + /* A character width or height smaller than 1pt is set to 1pt; if */ + /* both resolution values are zero, they are set to 72dpi. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Char_Size( FT_Face face, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Pixel_Sizes */ + /* */ + /* <Description> */ + /* Call @FT_Request_Size to request the nominal size (in pixels). */ + /* */ + /* <InOut> */ + /* face :: A handle to the target face object. */ + /* */ + /* <Input> */ + /* pixel_width :: The nominal width, in pixels. */ + /* */ + /* pixel_height :: The nominal height, in pixels. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You should not rely on the resulting glyphs matching or being */ + /* constrained to this pixel size. Refer to @FT_Request_Size to */ + /* understand how requested sizes relate to actual sizes. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Pixel_Sizes( FT_Face face, + FT_UInt pixel_width, + FT_UInt pixel_height ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Load_Glyph */ + /* */ + /* <Description> */ + /* Load a glyph into the glyph slot of a face object. */ + /* */ + /* <InOut> */ + /* face :: A handle to the target face object where the glyph */ + /* is loaded. */ + /* */ + /* <Input> */ + /* glyph_index :: The index of the glyph in the font file. For */ + /* CID-keyed fonts (either in PS or in CFF format) */ + /* this argument specifies the CID value. */ + /* */ + /* load_flags :: A flag indicating what to load for this glyph. The */ + /* @FT_LOAD_XXX constants can be used to control the */ + /* glyph loading process (e.g., whether the outline */ + /* should be scaled, whether to load bitmaps or not, */ + /* whether to hint the outline, etc). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The loaded glyph may be transformed. See @FT_Set_Transform for */ + /* the details. */ + /* */ + /* For subsetted CID-keyed fonts, `FT_Err_Invalid_Argument' is */ + /* returned for invalid CID values (this is, for CID values that */ + /* don't have a corresponding glyph in the font). See the discussion */ + /* of the @FT_FACE_FLAG_CID_KEYED flag for more details. */ + /* */ + /* If you receive `FT_Err_Glyph_Too_Big', try getting the glyph */ + /* outline at EM size, then scale it manually and fill it as a */ + /* graphics operation. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Load_Glyph( FT_Face face, + FT_UInt glyph_index, + FT_Int32 load_flags ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Load_Char */ + /* */ + /* <Description> */ + /* Load a glyph into the glyph slot of a face object, accessed by its */ + /* character code. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object where the glyph */ + /* is loaded. */ + /* */ + /* <Input> */ + /* char_code :: The glyph's character code, according to the */ + /* current charmap used in the face. */ + /* */ + /* load_flags :: A flag indicating what to load for this glyph. The */ + /* @FT_LOAD_XXX constants can be used to control the */ + /* glyph loading process (e.g., whether the outline */ + /* should be scaled, whether to load bitmaps or not, */ + /* whether to hint the outline, etc). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function simply calls @FT_Get_Char_Index and @FT_Load_Glyph. */ + /* */ + /* Many fonts contain glyphs that can't be loaded by this function */ + /* since its glyph indices are not listed in any of the font's */ + /* charmaps. */ + /* */ + /* If no active cmap is set up (i.e., `face->charmap' is zero), the */ + /* call to @FT_Get_Char_Index is omitted, and the function behaves */ + /* identically to @FT_Load_Glyph. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Load_Char( FT_Face face, + FT_ULong char_code, + FT_Int32 load_flags ); + + + /************************************************************************* + * + * @enum: + * FT_LOAD_XXX + * + * @description: + * A list of bit field constants for @FT_Load_Glyph to indicate what + * kind of operations to perform during glyph loading. + * + * @values: + * FT_LOAD_DEFAULT :: + * Corresponding to~0, this value is used as the default glyph load + * operation. In this case, the following happens: + * + * 1. FreeType looks for a bitmap for the glyph corresponding to the + * face's current size. If one is found, the function returns. + * The bitmap data can be accessed from the glyph slot (see note + * below). + * + * 2. If no embedded bitmap is searched for or found, FreeType looks + * for a scalable outline. If one is found, it is loaded from + * the font file, scaled to device pixels, then `hinted' to the + * pixel grid in order to optimize it. The outline data can be + * accessed from the glyph slot (see note below). + * + * Note that by default the glyph loader doesn't render outlines into + * bitmaps. The following flags are used to modify this default + * behaviour to more specific and useful cases. + * + * FT_LOAD_NO_SCALE :: + * Don't scale the loaded outline glyph but keep it in font units. + * + * This flag implies @FT_LOAD_NO_HINTING and @FT_LOAD_NO_BITMAP, and + * unsets @FT_LOAD_RENDER. + * + * If the font is `tricky' (see @FT_FACE_FLAG_TRICKY for more), using + * FT_LOAD_NO_SCALE usually yields meaningless outlines because the + * subglyphs must be scaled and positioned with hinting instructions. + * This can be solved by loading the font without FT_LOAD_NO_SCALE and + * setting the character size to `font->units_per_EM'. + * + * FT_LOAD_NO_HINTING :: + * Disable hinting. This generally generates `blurrier' bitmap glyphs + * when the glyph are rendered in any of the anti-aliased modes. See + * also the note below. + * + * This flag is implied by @FT_LOAD_NO_SCALE. + * + * FT_LOAD_RENDER :: + * Call @FT_Render_Glyph after the glyph is loaded. By default, the + * glyph is rendered in @FT_RENDER_MODE_NORMAL mode. This can be + * overridden by @FT_LOAD_TARGET_XXX or @FT_LOAD_MONOCHROME. + * + * This flag is unset by @FT_LOAD_NO_SCALE. + * + * FT_LOAD_NO_BITMAP :: + * Ignore bitmap strikes when loading. Bitmap-only fonts ignore this + * flag. + * + * @FT_LOAD_NO_SCALE always sets this flag. + * + * FT_LOAD_VERTICAL_LAYOUT :: + * Load the glyph for vertical text layout. In particular, the + * `advance' value in the @FT_GlyphSlotRec structure is set to the + * `vertAdvance' value of the `metrics' field. + * + * In case @FT_HAS_VERTICAL doesn't return true, you shouldn't use + * this flag currently. Reason is that in this case vertical metrics + * get synthesized, and those values are not always consistent across + * various font formats. + * + * FT_LOAD_FORCE_AUTOHINT :: + * Prefer the auto-hinter over the font's native hinter. See also + * the note below. + * + * FT_LOAD_PEDANTIC :: + * Make the font driver perform pedantic verifications during glyph + * loading. This is mostly used to detect broken glyphs in fonts. + * By default, FreeType tries to handle broken fonts also. + * + * In particular, errors from the TrueType bytecode engine are not + * passed to the application if this flag is not set; this might + * result in partially hinted or distorted glyphs in case a glyph's + * bytecode is buggy. + * + * FT_LOAD_NO_RECURSE :: + * Don't load composite glyphs recursively. Instead, the font + * driver should set the `num_subglyph' and `subglyphs' values of + * the glyph slot accordingly, and set `glyph->format' to + * @FT_GLYPH_FORMAT_COMPOSITE. The description of subglyphs can + * then be accessed with @FT_Get_SubGlyph_Info. + * + * This flag implies @FT_LOAD_NO_SCALE and @FT_LOAD_IGNORE_TRANSFORM. + * + * FT_LOAD_IGNORE_TRANSFORM :: + * Ignore the transform matrix set by @FT_Set_Transform. + * + * FT_LOAD_MONOCHROME :: + * This flag is used with @FT_LOAD_RENDER to indicate that you want to + * render an outline glyph to a 1-bit monochrome bitmap glyph, with + * 8~pixels packed into each byte of the bitmap data. + * + * Note that this has no effect on the hinting algorithm used. You + * should rather use @FT_LOAD_TARGET_MONO so that the + * monochrome-optimized hinting algorithm is used. + * + * FT_LOAD_LINEAR_DESIGN :: + * Keep `linearHoriAdvance' and `linearVertAdvance' fields of + * @FT_GlyphSlotRec in font units. See @FT_GlyphSlotRec for + * details. + * + * FT_LOAD_NO_AUTOHINT :: + * Disable the auto-hinter. See also the note below. + * + * FT_LOAD_COLOR :: + * [Since 2.5] Load embedded color bitmap images. The resulting color + * bitmaps, if available, will have the @FT_PIXEL_MODE_BGRA format. + * If the flag is not set and color bitmaps are found, they are + * converted to 256-level gray bitmaps transparently, using the + * @FT_PIXEL_MODE_GRAY format. + * + * FT_LOAD_COMPUTE_METRICS :: + * [Since 2.6.1] Compute glyph metrics from the glyph data, without + * the use of bundled metrics tables (for example, the `hdmx' table in + * TrueType fonts). This flag is mainly used by font validating or + * font editing applications, which need to ignore, verify, or edit + * those tables. + * + * Currently, this flag is only implemented for TrueType fonts. + * + * FT_LOAD_BITMAP_METRICS_ONLY :: + * [Since 2.7.1] Request loading of the metrics and bitmap image + * information of a (possibly embedded) bitmap glyph without + * allocating or copying the bitmap image data itself. No effect if + * the target glyph is not a bitmap image. + * + * This flag unsets @FT_LOAD_RENDER. + * + * FT_LOAD_CROP_BITMAP :: + * Ignored. Deprecated. + * + * FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH :: + * Ignored. Deprecated. + * + * @note: + * By default, hinting is enabled and the font's native hinter (see + * @FT_FACE_FLAG_HINTER) is preferred over the auto-hinter. You can + * disable hinting by setting @FT_LOAD_NO_HINTING or change the + * precedence by setting @FT_LOAD_FORCE_AUTOHINT. You can also set + * @FT_LOAD_NO_AUTOHINT in case you don't want the auto-hinter to be + * used at all. + * + * See the description of @FT_FACE_FLAG_TRICKY for a special exception + * (affecting only a handful of Asian fonts). + * + * Besides deciding which hinter to use, you can also decide which + * hinting algorithm to use. See @FT_LOAD_TARGET_XXX for details. + * + * Note that the auto-hinter needs a valid Unicode cmap (either a native + * one or synthesized by FreeType) for producing correct results. If a + * font provides an incorrect mapping (for example, assigning the + * character code U+005A, LATIN CAPITAL LETTER Z, to a glyph depicting a + * mathematical integral sign), the auto-hinter might produce useless + * results. + * + */ +#define FT_LOAD_DEFAULT 0x0 +#define FT_LOAD_NO_SCALE ( 1L << 0 ) +#define FT_LOAD_NO_HINTING ( 1L << 1 ) +#define FT_LOAD_RENDER ( 1L << 2 ) +#define FT_LOAD_NO_BITMAP ( 1L << 3 ) +#define FT_LOAD_VERTICAL_LAYOUT ( 1L << 4 ) +#define FT_LOAD_FORCE_AUTOHINT ( 1L << 5 ) +#define FT_LOAD_CROP_BITMAP ( 1L << 6 ) +#define FT_LOAD_PEDANTIC ( 1L << 7 ) +#define FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ( 1L << 9 ) +#define FT_LOAD_NO_RECURSE ( 1L << 10 ) +#define FT_LOAD_IGNORE_TRANSFORM ( 1L << 11 ) +#define FT_LOAD_MONOCHROME ( 1L << 12 ) +#define FT_LOAD_LINEAR_DESIGN ( 1L << 13 ) +#define FT_LOAD_NO_AUTOHINT ( 1L << 15 ) + /* Bits 16-19 are used by `FT_LOAD_TARGET_' */ +#define FT_LOAD_COLOR ( 1L << 20 ) +#define FT_LOAD_COMPUTE_METRICS ( 1L << 21 ) +#define FT_LOAD_BITMAP_METRICS_ONLY ( 1L << 22 ) + + /* */ + + /* used internally only by certain font drivers */ +#define FT_LOAD_ADVANCE_ONLY ( 1L << 8 ) +#define FT_LOAD_SBITS_ONLY ( 1L << 14 ) + + + /************************************************************************** + * + * @enum: + * FT_LOAD_TARGET_XXX + * + * @description: + * A list of values to select a specific hinting algorithm for the + * hinter. You should OR one of these values to your `load_flags' + * when calling @FT_Load_Glyph. + * + * Note that a font's native hinters may ignore the hinting algorithm + * you have specified (e.g., the TrueType bytecode interpreter). You + * can set @FT_LOAD_FORCE_AUTOHINT to ensure that the auto-hinter is + * used. + * + * @values: + * FT_LOAD_TARGET_NORMAL :: + * The default hinting algorithm, optimized for standard gray-level + * rendering. For monochrome output, use @FT_LOAD_TARGET_MONO + * instead. + * + * FT_LOAD_TARGET_LIGHT :: + * A lighter hinting algorithm for gray-level modes. Many generated + * glyphs are fuzzier but better resemble their original shape. This + * is achieved by snapping glyphs to the pixel grid only vertically + * (Y-axis), as is done by FreeType's new CFF engine or Microsoft's + * ClearType font renderer. This preserves inter-glyph spacing in + * horizontal text. The snapping is done either by the native font + * driver, if the driver itself and the font support it, or by the + * auto-hinter. + * + * Advance widths are rounded to integer values; however, using the + * `lsb_delta' and `rsb_delta' fields of @FT_GlyphSlotRec, it is + * possible to get fractional advance widths for subpixel positioning + * (which is recommended to use). + * + * If configuration option AF_CONFIG_OPTION_TT_SIZE_METRICS is active, + * TrueType-like metrics are used to make this mode behave similarly + * as in unpatched FreeType versions between 2.4.6 and 2.7.1 + * (inclusive). + * + * FT_LOAD_TARGET_MONO :: + * Strong hinting algorithm that should only be used for monochrome + * output. The result is probably unpleasant if the glyph is rendered + * in non-monochrome modes. + * + * FT_LOAD_TARGET_LCD :: + * A variant of @FT_LOAD_TARGET_LIGHT optimized for horizontally + * decimated LCD displays. + * + * FT_LOAD_TARGET_LCD_V :: + * A variant of @FT_LOAD_TARGET_NORMAL optimized for vertically + * decimated LCD displays. + * + * @note: + * You should use only _one_ of the FT_LOAD_TARGET_XXX values in your + * `load_flags'. They can't be ORed. + * + * If @FT_LOAD_RENDER is also set, the glyph is rendered in the + * corresponding mode (i.e., the mode that matches the used algorithm + * best). An exception is FT_LOAD_TARGET_MONO since it implies + * @FT_LOAD_MONOCHROME. + * + * You can use a hinting algorithm that doesn't correspond to the same + * rendering mode. As an example, it is possible to use the `light' + * hinting algorithm and have the results rendered in horizontal LCD + * pixel mode, with code like + * + * { + * FT_Load_Glyph( face, glyph_index, + * load_flags | FT_LOAD_TARGET_LIGHT ); + * + * FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD ); + * } + * + * In general, you should stick with one rendering mode. For example, + * switching between @FT_LOAD_TARGET_NORMAL and @FT_LOAD_TARGET_MONO + * enforces a lot of recomputation for TrueType fonts, which is slow. + * Another reason is caching: Selecting a different mode usually causes + * changes in both the outlines and the rasterized bitmaps; it is thus + * necessary to empty the cache after a mode switch to avoid false hits. + * + */ +#define FT_LOAD_TARGET_( x ) ( (FT_Int32)( (x) & 15 ) << 16 ) + +#define FT_LOAD_TARGET_NORMAL FT_LOAD_TARGET_( FT_RENDER_MODE_NORMAL ) +#define FT_LOAD_TARGET_LIGHT FT_LOAD_TARGET_( FT_RENDER_MODE_LIGHT ) +#define FT_LOAD_TARGET_MONO FT_LOAD_TARGET_( FT_RENDER_MODE_MONO ) +#define FT_LOAD_TARGET_LCD FT_LOAD_TARGET_( FT_RENDER_MODE_LCD ) +#define FT_LOAD_TARGET_LCD_V FT_LOAD_TARGET_( FT_RENDER_MODE_LCD_V ) + + + /************************************************************************** + * + * @macro: + * FT_LOAD_TARGET_MODE + * + * @description: + * Return the @FT_Render_Mode corresponding to a given + * @FT_LOAD_TARGET_XXX value. + * + */ +#define FT_LOAD_TARGET_MODE( x ) ( (FT_Render_Mode)( ( (x) >> 16 ) & 15 ) ) + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Transform */ + /* */ + /* <Description> */ + /* Set the transformation that is applied to glyph images when they */ + /* are loaded into a glyph slot through @FT_Load_Glyph. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the transformation's 2x2 matrix. Use NULL */ + /* for the identity matrix. */ + /* delta :: A pointer to the translation vector. Use NULL for the */ + /* null vector. */ + /* */ + /* <Note> */ + /* The transformation is only applied to scalable image formats after */ + /* the glyph has been loaded. It means that hinting is unaltered by */ + /* the transformation and is performed on the character size given in */ + /* the last call to @FT_Set_Char_Size or @FT_Set_Pixel_Sizes. */ + /* */ + /* Note that this also transforms the `face.glyph.advance' field, but */ + /* *not* the values in `face.glyph.metrics'. */ + /* */ + FT_EXPORT( void ) + FT_Set_Transform( FT_Face face, + FT_Matrix* matrix, + FT_Vector* delta ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Render_Mode */ + /* */ + /* <Description> */ + /* Render modes supported by FreeType~2. Each mode corresponds to a */ + /* specific type of scanline conversion performed on the outline. */ + /* */ + /* For bitmap fonts and embedded bitmaps the `bitmap->pixel_mode' */ + /* field in the @FT_GlyphSlotRec structure gives the format of the */ + /* returned bitmap. */ + /* */ + /* All modes except @FT_RENDER_MODE_MONO use 256 levels of opacity, */ + /* indicating pixel coverage. Use linear alpha blending and gamma */ + /* correction to correctly render non-monochrome glyph bitmaps onto a */ + /* surface; see @FT_Render_Glyph. */ + /* */ + /* <Values> */ + /* FT_RENDER_MODE_NORMAL :: */ + /* Default render mode; it corresponds to 8-bit anti-aliased */ + /* bitmaps. */ + /* */ + /* FT_RENDER_MODE_LIGHT :: */ + /* This is equivalent to @FT_RENDER_MODE_NORMAL. It is only */ + /* defined as a separate value because render modes are also used */ + /* indirectly to define hinting algorithm selectors. See */ + /* @FT_LOAD_TARGET_XXX for details. */ + /* */ + /* FT_RENDER_MODE_MONO :: */ + /* This mode corresponds to 1-bit bitmaps (with 2~levels of */ + /* opacity). */ + /* */ + /* FT_RENDER_MODE_LCD :: */ + /* This mode corresponds to horizontal RGB and BGR subpixel */ + /* displays like LCD screens. It produces 8-bit bitmaps that are */ + /* 3~times the width of the original glyph outline in pixels, and */ + /* which use the @FT_PIXEL_MODE_LCD mode. */ + /* */ + /* FT_RENDER_MODE_LCD_V :: */ + /* This mode corresponds to vertical RGB and BGR subpixel displays */ + /* (like PDA screens, rotated LCD displays, etc.). It produces */ + /* 8-bit bitmaps that are 3~times the height of the original */ + /* glyph outline in pixels and use the @FT_PIXEL_MODE_LCD_V mode. */ + /* */ + /* <Note> */ + /* Should you define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your */ + /* `ftoption.h', which enables patented ClearType-style rendering, */ + /* the LCD-optimized glyph bitmaps should be filtered to reduce color */ + /* fringes inherent to this technology. You can either set up LCD */ + /* filtering with @FT_Library_SetLcdFilter or @FT_Face_Properties, */ + /* or do the filtering yourself. The default FreeType LCD rendering */ + /* technology does not require filtering. */ + /* */ + /* The selected render mode only affects vector glyphs of a font. */ + /* Embedded bitmaps often have a different pixel mode like */ + /* @FT_PIXEL_MODE_MONO. You can use @FT_Bitmap_Convert to transform */ + /* them into 8-bit pixmaps. */ + /* */ + typedef enum FT_Render_Mode_ + { + FT_RENDER_MODE_NORMAL = 0, + FT_RENDER_MODE_LIGHT, + FT_RENDER_MODE_MONO, + FT_RENDER_MODE_LCD, + FT_RENDER_MODE_LCD_V, + + FT_RENDER_MODE_MAX + + } FT_Render_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Render_Mode' values instead */ +#define ft_render_mode_normal FT_RENDER_MODE_NORMAL +#define ft_render_mode_mono FT_RENDER_MODE_MONO + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Render_Glyph */ + /* */ + /* <Description> */ + /* Convert a given glyph image to a bitmap. It does so by inspecting */ + /* the glyph image format, finding the relevant renderer, and */ + /* invoking it. */ + /* */ + /* <InOut> */ + /* slot :: A handle to the glyph slot containing the image to */ + /* convert. */ + /* */ + /* <Input> */ + /* render_mode :: The render mode used to render the glyph image into */ + /* a bitmap. See @FT_Render_Mode for a list of */ + /* possible values. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* To get meaningful results, font scaling values must be set with */ + /* functions like @FT_Set_Char_Size before calling `FT_Render_Glyph'. */ + /* */ + /* When FreeType outputs a bitmap of a glyph, it really outputs an */ + /* alpha coverage map. If a pixel is completely covered by a */ + /* filled-in outline, the bitmap contains 0xFF at that pixel, meaning */ + /* that 0xFF/0xFF fraction of that pixel is covered, meaning the */ + /* pixel is 100% black (or 0% bright). If a pixel is only 50% */ + /* covered (value 0x80), the pixel is made 50% black (50% bright or a */ + /* middle shade of grey). 0% covered means 0% black (100% bright or */ + /* white). */ + /* */ + /* On high-DPI screens like on smartphones and tablets, the pixels */ + /* are so small that their chance of being completely covered and */ + /* therefore completely black are fairly good. On the low-DPI */ + /* screens, however, the situation is different. The pixels are too */ + /* large for most of the details of a glyph and shades of gray are */ + /* the norm rather than the exception. */ + /* */ + /* This is relevant because all our screens have a second problem: */ + /* they are not linear. 1~+~1 is not~2. Twice the value does not */ + /* result in twice the brightness. When a pixel is only 50% covered, */ + /* the coverage map says 50% black, and this translates to a pixel */ + /* value of 128 when you use 8~bits per channel (0-255). However, */ + /* this does not translate to 50% brightness for that pixel on our */ + /* sRGB and gamma~2.2 screens. Due to their non-linearity, they */ + /* dwell longer in the darks and only a pixel value of about 186 */ + /* results in 50% brightness -- 128 ends up too dark on both bright */ + /* and dark backgrounds. The net result is that dark text looks */ + /* burnt-out, pixely and blotchy on bright background, bright text */ + /* too frail on dark backgrounds, and colored text on colored */ + /* background (for example, red on green) seems to have dark halos or */ + /* `dirt' around it. The situation is especially ugly for diagonal */ + /* stems like in `w' glyph shapes where the quality of FreeType's */ + /* anti-aliasing depends on the correct display of grays. On */ + /* high-DPI screens where smaller, fully black pixels reign supreme, */ + /* this doesn't matter, but on our low-DPI screens with all the gray */ + /* shades, it does. 0% and 100% brightness are the same things in */ + /* linear and non-linear space, just all the shades in-between */ + /* aren't. */ + /* */ + /* The blending function for placing text over a background is */ + /* */ + /* { */ + /* dst = alpha * src + (1 - alpha) * dst , */ + /* } */ + /* */ + /* which is known as the OVER operator. */ + /* */ + /* To correctly composite an antialiased pixel of a glyph onto a */ + /* surface, */ + /* */ + /* 1. take the foreground and background colors (e.g., in sRGB space) */ + /* and apply gamma to get them in a linear space, */ + /* */ + /* 2. use OVER to blend the two linear colors using the glyph pixel */ + /* as the alpha value (remember, the glyph bitmap is an alpha */ + /* coverage bitmap), and */ + /* */ + /* 3. apply inverse gamma to the blended pixel and write it back to */ + /* the image. */ + /* */ + /* Internal testing at Adobe found that a target inverse gamma of~1.8 */ + /* for step~3 gives good results across a wide range of displays with */ + /* an sRGB gamma curve or a similar one. */ + /* */ + /* This process can cost performance. There is an approximation that */ + /* does not need to know about the background color; see */ + /* https://bel.fi/alankila/lcd/ and */ + /* https://bel.fi/alankila/lcd/alpcor.html for details. */ + /* */ + /* *ATTENTION*: Linear blending is even more important when dealing */ + /* with subpixel-rendered glyphs to prevent color-fringing! A */ + /* subpixel-rendered glyph must first be filtered with a filter that */ + /* gives equal weight to the three color primaries and does not */ + /* exceed a sum of 0x100, see section @lcd_filtering. Then the */ + /* only difference to gray linear blending is that subpixel-rendered */ + /* linear blending is done 3~times per pixel: red foreground subpixel */ + /* to red background subpixel and so on for green and blue. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Render_Glyph( FT_GlyphSlot slot, + FT_Render_Mode render_mode ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Kerning_Mode */ + /* */ + /* <Description> */ + /* An enumeration to specify the format of kerning values returned by */ + /* @FT_Get_Kerning. */ + /* */ + /* <Values> */ + /* FT_KERNING_DEFAULT :: Return grid-fitted kerning distances in */ + /* 26.6 fractional pixels. */ + /* */ + /* FT_KERNING_UNFITTED :: Return un-grid-fitted kerning distances in */ + /* 26.6 fractional pixels. */ + /* */ + /* FT_KERNING_UNSCALED :: Return the kerning vector in original font */ + /* units. */ + /* */ + /* <Note> */ + /* FT_KERNING_DEFAULT returns full pixel values; it also makes */ + /* FreeType heuristically scale down kerning distances at small ppem */ + /* values so that they don't become too big. */ + /* */ + /* Both FT_KERNING_DEFAULT and FT_KERNING_UNFITTED use the current */ + /* horizontal scaling factor (as set e.g. with @FT_Set_Char_Size) to */ + /* convert font units to pixels. */ + /* */ + typedef enum FT_Kerning_Mode_ + { + FT_KERNING_DEFAULT = 0, + FT_KERNING_UNFITTED, + FT_KERNING_UNSCALED + + } FT_Kerning_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Kerning_Mode' values instead */ +#define ft_kerning_default FT_KERNING_DEFAULT +#define ft_kerning_unfitted FT_KERNING_UNFITTED +#define ft_kerning_unscaled FT_KERNING_UNSCALED + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Kerning */ + /* */ + /* <Description> */ + /* Return the kerning vector between two glyphs of the same face. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* left_glyph :: The index of the left glyph in the kern pair. */ + /* */ + /* right_glyph :: The index of the right glyph in the kern pair. */ + /* */ + /* kern_mode :: See @FT_Kerning_Mode for more information. */ + /* Determines the scale and dimension of the returned */ + /* kerning vector. */ + /* */ + /* <Output> */ + /* akerning :: The kerning vector. This is either in font units, */ + /* fractional pixels (26.6 format), or pixels for */ + /* scalable formats, and in pixels for fixed-sizes */ + /* formats. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Only horizontal layouts (left-to-right & right-to-left) are */ + /* supported by this method. Other layouts, or more sophisticated */ + /* kernings, are out of the scope of this API function -- they can be */ + /* implemented through format-specific interfaces. */ + /* */ + /* Kerning for OpenType fonts implemented in a `GPOS' table is not */ + /* supported; use @FT_HAS_KERNING to find out whether a font has data */ + /* that can be extracted with `FT_Get_Kerning'. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Kerning( FT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_UInt kern_mode, + FT_Vector *akerning ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Track_Kerning */ + /* */ + /* <Description> */ + /* Return the track kerning for a given face object at a given size. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* point_size :: The point size in 16.16 fractional points. */ + /* */ + /* degree :: The degree of tightness. Increasingly negative */ + /* values represent tighter track kerning, while */ + /* increasingly positive values represent looser track */ + /* kerning. Value zero means no track kerning. */ + /* */ + /* <Output> */ + /* akerning :: The kerning in 16.16 fractional points, to be */ + /* uniformly applied between all glyphs. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Currently, only the Type~1 font driver supports track kerning, */ + /* using data from AFM files (if attached with @FT_Attach_File or */ + /* @FT_Attach_Stream). */ + /* */ + /* Only very few AFM files come with track kerning data; please refer */ + /* to Adobe's AFM specification for more details. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Track_Kerning( FT_Face face, + FT_Fixed point_size, + FT_Int degree, + FT_Fixed* akerning ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Glyph_Name */ + /* */ + /* <Description> */ + /* Retrieve the ASCII name of a given glyph in a face. This only */ + /* works for those faces where @FT_HAS_GLYPH_NAMES(face) returns~1. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* glyph_index :: The glyph index. */ + /* */ + /* buffer_max :: The maximum number of bytes available in the */ + /* buffer. */ + /* */ + /* <Output> */ + /* buffer :: A pointer to a target buffer where the name is */ + /* copied to. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* An error is returned if the face doesn't provide glyph names or if */ + /* the glyph index is invalid. In all cases of failure, the first */ + /* byte of `buffer' is set to~0 to indicate an empty name. */ + /* */ + /* The glyph name is truncated to fit within the buffer if it is too */ + /* long. The returned string is always zero-terminated. */ + /* */ + /* Be aware that FreeType reorders glyph indices internally so that */ + /* glyph index~0 always corresponds to the `missing glyph' (called */ + /* `.notdef'). */ + /* */ + /* This function always returns an error if the config macro */ + /* `FT_CONFIG_OPTION_NO_GLYPH_NAMES' is not defined in `ftoption.h'. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Glyph_Name( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Postscript_Name */ + /* */ + /* <Description> */ + /* Retrieve the ASCII PostScript name of a given face, if available. */ + /* This only works with PostScript, TrueType, and OpenType fonts. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Return> */ + /* A pointer to the face's PostScript name. NULL if unavailable. */ + /* */ + /* <Note> */ + /* The returned pointer is owned by the face and is destroyed with */ + /* it. */ + /* */ + /* For variation fonts, this string changes if you select a different */ + /* instance, and you have to call `FT_Get_PostScript_Name' again to */ + /* retrieve it. FreeType follows Adobe TechNote #5902, `Generating */ + /* PostScript Names for Fonts Using OpenType Font Variations'. */ + /* */ + /* https://download.macromedia.com/pub/developer/opentype/tech-notes/5902.AdobePSNameGeneration.html */ + /* */ + /* [Since 2.9] Special PostScript names for named instances are only */ + /* returned if the named instance is set with @FT_Set_Named_Instance */ + /* (and the font has corresponding entries in its `fvar' table). If */ + /* @FT_IS_VARIATION returns true, the algorithmically derived */ + /* PostScript name is provided, not looking up special entries for */ + /* named instances. */ + /* */ + FT_EXPORT( const char* ) + FT_Get_Postscript_Name( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Select_Charmap */ + /* */ + /* <Description> */ + /* Select a given charmap by its encoding tag (as listed in */ + /* `freetype.h'). */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* encoding :: A handle to the selected encoding. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function returns an error if no charmap in the face */ + /* corresponds to the encoding queried here. */ + /* */ + /* Because many fonts contain more than a single cmap for Unicode */ + /* encoding, this function has some special code to select the one */ + /* that covers Unicode best (`best' in the sense that a UCS-4 cmap is */ + /* preferred to a UCS-2 cmap). It is thus preferable to */ + /* @FT_Set_Charmap in this case. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Select_Charmap( FT_Face face, + FT_Encoding encoding ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Charmap */ + /* */ + /* <Description> */ + /* Select a given charmap for character code to glyph index mapping. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* charmap :: A handle to the selected charmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function returns an error if the charmap is not part of */ + /* the face (i.e., if it is not listed in the `face->charmaps' */ + /* table). */ + /* */ + /* It also fails if an OpenType type~14 charmap is selected (which */ + /* doesn't map character codes to glyph indices at all). */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Charmap( FT_Face face, + FT_CharMap charmap ); + + + /************************************************************************* + * + * @function: + * FT_Get_Charmap_Index + * + * @description: + * Retrieve index of a given charmap. + * + * @input: + * charmap :: + * A handle to a charmap. + * + * @return: + * The index into the array of character maps within the face to which + * `charmap' belongs. If an error occurs, -1 is returned. + * + */ + FT_EXPORT( FT_Int ) + FT_Get_Charmap_Index( FT_CharMap charmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Char_Index */ + /* */ + /* <Description> */ + /* Return the glyph index of a given character code. This function */ + /* uses the currently selected charmap to do the mapping. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* charcode :: The character code. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means `undefined character code'. */ + /* */ + /* <Note> */ + /* If you use FreeType to manipulate the contents of font files */ + /* directly, be aware that the glyph index returned by this function */ + /* doesn't always correspond to the internal indices used within the */ + /* file. This is done to ensure that value~0 always corresponds to */ + /* the `missing glyph'. If the first glyph is not named `.notdef', */ + /* then for Type~1 and Type~42 fonts, `.notdef' will be moved into */ + /* the glyph ID~0 position, and whatever was there will be moved to */ + /* the position `.notdef' had. For Type~1 fonts, if there is no */ + /* `.notdef' glyph at all, then one will be created at index~0 and */ + /* whatever was there will be moved to the last index -- Type~42 */ + /* fonts are considered invalid under this condition. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Char_Index( FT_Face face, + FT_ULong charcode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_First_Char */ + /* */ + /* <Description> */ + /* Return the first character code in the current charmap of a given */ + /* face, together with its corresponding glyph index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Output> */ + /* agindex :: Glyph index of first character code. 0~if charmap is */ + /* empty. */ + /* */ + /* <Return> */ + /* The charmap's first character code. */ + /* */ + /* <Note> */ + /* You should use this function together with @FT_Get_Next_Char to */ + /* parse all character codes available in a given charmap. The code */ + /* should look like this: */ + /* */ + /* { */ + /* FT_ULong charcode; */ + /* FT_UInt gindex; */ + /* */ + /* */ + /* charcode = FT_Get_First_Char( face, &gindex ); */ + /* while ( gindex != 0 ) */ + /* { */ + /* ... do something with (charcode,gindex) pair ... */ + /* */ + /* charcode = FT_Get_Next_Char( face, charcode, &gindex ); */ + /* } */ + /* } */ + /* */ + /* Be aware that character codes can have values up to 0xFFFFFFFF; */ + /* this might happen for non-Unicode or malformed cmaps. However, */ + /* even with regular Unicode encoding, so-called `last resort fonts' */ + /* (using SFNT cmap format 13, see function @FT_Get_CMap_Format) */ + /* normally have entries for all Unicode characters up to 0x1FFFFF, */ + /* which can cause *a lot* of iterations. */ + /* */ + /* Note that `*agindex' is set to~0 if the charmap is empty. The */ + /* result itself can be~0 in two cases: if the charmap is empty or */ + /* if the value~0 is the first valid character code. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_First_Char( FT_Face face, + FT_UInt *agindex ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Next_Char */ + /* */ + /* <Description> */ + /* Return the next character code in the current charmap of a given */ + /* face following the value `char_code', as well as the corresponding */ + /* glyph index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* char_code :: The starting character code. */ + /* */ + /* <Output> */ + /* agindex :: Glyph index of next character code. 0~if charmap */ + /* is empty. */ + /* */ + /* <Return> */ + /* The charmap's next character code. */ + /* */ + /* <Note> */ + /* You should use this function with @FT_Get_First_Char to walk */ + /* over all character codes available in a given charmap. See the */ + /* note for that function for a simple code example. */ + /* */ + /* Note that `*agindex' is set to~0 when there are no more codes in */ + /* the charmap. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_Next_Char( FT_Face face, + FT_ULong char_code, + FT_UInt *agindex ); + + + /************************************************************************* + * + * @function: + * FT_Face_Properties + * + * @description: + * Set or override certain (library or module-wide) properties on a + * face-by-face basis. Useful for finer-grained control and avoiding + * locks on shared structures (threads can modify their own faces as + * they see fit). + * + * Contrary to @FT_Property_Set, this function uses @FT_Parameter so + * that you can pass multiple properties to the target face in one call. + * Note that only a subset of the available properties can be + * controlled. + * + * * @FT_PARAM_TAG_STEM_DARKENING (stem darkening, corresponding to the + * property `no-stem-darkening' provided by the `autofit', `cff', + * `type1', and `t1cid' modules; see @no-stem-darkening). + * + * * @FT_PARAM_TAG_LCD_FILTER_WEIGHTS (LCD filter weights, corresponding + * to function @FT_Library_SetLcdFilterWeights). + * + * * @FT_PARAM_TAG_RANDOM_SEED (seed value for the CFF, Type~1, and CID + * `random' operator, corresponding to the `random-seed' property + * provided by the `cff', `type1', and `t1cid' modules; see + * @random-seed). + * + * Pass NULL as `data' in @FT_Parameter for a given tag to reset the + * option and use the library or module default again. + * + * @input: + * face :: + * A handle to the source face object. + * + * num_properties :: + * The number of properties that follow. + * + * properties :: + * A handle to an @FT_Parameter array with `num_properties' elements. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Here an example that sets three properties. You must define + * FT_CONFIG_OPTION_SUBPIXEL_RENDERING to make the LCD filter examples + * work. + * + * { + * FT_Parameter property1; + * FT_Bool darken_stems = 1; + * + * FT_Parameter property2; + * FT_LcdFiveTapFilter custom_weight = + * { 0x11, 0x44, 0x56, 0x44, 0x11 }; + * + * FT_Parameter property3; + * FT_Int32 random_seed = 314159265; + * + * FT_Parameter properties[3] = { property1, + * property2, + * property3 }; + * + * + * property1.tag = FT_PARAM_TAG_STEM_DARKENING; + * property1.data = &darken_stems; + * + * property2.tag = FT_PARAM_TAG_LCD_FILTER_WEIGHTS; + * property2.data = custom_weight; + * + * property3.tag = FT_PARAM_TAG_RANDOM_SEED; + * property3.data = &random_seed; + * + * FT_Face_Properties( face, 3, properties ); + * } + * + * The next example resets a single property to its default value. + * + * { + * FT_Parameter property; + * + * + * property.tag = FT_PARAM_TAG_LCD_FILTER_WEIGHTS; + * property.data = NULL; + * + * FT_Face_Properties( face, 1, &property ); + * } + * + * @since: + * 2.8 + * + */ + FT_EXPORT( FT_Error ) + FT_Face_Properties( FT_Face face, + FT_UInt num_properties, + FT_Parameter* properties ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Name_Index */ + /* */ + /* <Description> */ + /* Return the glyph index of a given glyph name. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* glyph_name :: The glyph name. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means `undefined character code'. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Name_Index( FT_Face face, + FT_String* glyph_name ); + + + /************************************************************************* + * + * @macro: + * FT_SUBGLYPH_FLAG_XXX + * + * @description: + * A list of constants describing subglyphs. Please refer to the + * `glyf' table description in the OpenType specification for the + * meaning of the various flags (which get synthesized for + * non-OpenType subglyphs). + * + * @values: + * FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS :: + * FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES :: + * FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID :: + * FT_SUBGLYPH_FLAG_SCALE :: + * FT_SUBGLYPH_FLAG_XY_SCALE :: + * FT_SUBGLYPH_FLAG_2X2 :: + * FT_SUBGLYPH_FLAG_USE_MY_METRICS :: + * + */ +#define FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS 1 +#define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES 2 +#define FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID 4 +#define FT_SUBGLYPH_FLAG_SCALE 8 +#define FT_SUBGLYPH_FLAG_XY_SCALE 0x40 +#define FT_SUBGLYPH_FLAG_2X2 0x80 +#define FT_SUBGLYPH_FLAG_USE_MY_METRICS 0x200 + + + /************************************************************************* + * + * @func: + * FT_Get_SubGlyph_Info + * + * @description: + * Retrieve a description of a given subglyph. Only use it if + * `glyph->format' is @FT_GLYPH_FORMAT_COMPOSITE; an error is + * returned otherwise. + * + * @input: + * glyph :: + * The source glyph slot. + * + * sub_index :: + * The index of the subglyph. Must be less than + * `glyph->num_subglyphs'. + * + * @output: + * p_index :: + * The glyph index of the subglyph. + * + * p_flags :: + * The subglyph flags, see @FT_SUBGLYPH_FLAG_XXX. + * + * p_arg1 :: + * The subglyph's first argument (if any). + * + * p_arg2 :: + * The subglyph's second argument (if any). + * + * p_transform :: + * The subglyph transformation (if any). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The values of `*p_arg1', `*p_arg2', and `*p_transform' must be + * interpreted depending on the flags returned in `*p_flags'. See the + * OpenType specification for details. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_SubGlyph_Info( FT_GlyphSlot glyph, + FT_UInt sub_index, + FT_Int *p_index, + FT_UInt *p_flags, + FT_Int *p_arg1, + FT_Int *p_arg2, + FT_Matrix *p_transform ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_FSTYPE_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the `fsType' field of the OS/2 table */ + /* in a TrueType or OpenType font and the `FSType' entry in a */ + /* PostScript font. These bit flags are returned by */ + /* @FT_Get_FSType_Flags; they inform client applications of embedding */ + /* and subsetting restrictions associated with a font. */ + /* */ + /* See */ + /* https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/FontPolicies.pdf */ + /* for more details. */ + /* */ + /* <Values> */ + /* FT_FSTYPE_INSTALLABLE_EMBEDDING :: */ + /* Fonts with no fsType bit set may be embedded and permanently */ + /* installed on the remote system by an application. */ + /* */ + /* FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING :: */ + /* Fonts that have only this bit set must not be modified, embedded */ + /* or exchanged in any manner without first obtaining permission of */ + /* the font software copyright owner. */ + /* */ + /* FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING :: */ + /* The font may be embedded and temporarily loaded on the remote */ + /* system. Documents containing Preview & Print fonts must be */ + /* opened `read-only'; no edits can be applied to the document. */ + /* */ + /* FT_FSTYPE_EDITABLE_EMBEDDING :: */ + /* The font may be embedded but must only be installed temporarily */ + /* on other systems. In contrast to Preview & Print fonts, */ + /* documents containing editable fonts may be opened for reading, */ + /* editing is permitted, and changes may be saved. */ + /* */ + /* FT_FSTYPE_NO_SUBSETTING :: */ + /* The font may not be subsetted prior to embedding. */ + /* */ + /* FT_FSTYPE_BITMAP_EMBEDDING_ONLY :: */ + /* Only bitmaps contained in the font may be embedded; no outline */ + /* data may be embedded. If there are no bitmaps available in the */ + /* font, then the font is unembeddable. */ + /* */ + /* <Note> */ + /* The flags are ORed together, thus more than a single value can be */ + /* returned. */ + /* */ + /* While the `fsType' flags can indicate that a font may be embedded, */ + /* a license with the font vendor may be separately required to use */ + /* the font in this way. */ + /* */ +#define FT_FSTYPE_INSTALLABLE_EMBEDDING 0x0000 +#define FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING 0x0002 +#define FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING 0x0004 +#define FT_FSTYPE_EDITABLE_EMBEDDING 0x0008 +#define FT_FSTYPE_NO_SUBSETTING 0x0100 +#define FT_FSTYPE_BITMAP_EMBEDDING_ONLY 0x0200 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_FSType_Flags */ + /* */ + /* <Description> */ + /* Return the `fsType' flags for a font. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Return> */ + /* The `fsType' flags, see @FT_FSTYPE_XXX. */ + /* */ + /* <Note> */ + /* Use this function rather than directly reading the `fs_type' field */ + /* in the @PS_FontInfoRec structure, which is only guaranteed to */ + /* return the correct results for Type~1 fonts. */ + /* */ + /* <Since> */ + /* 2.3.8 */ + /* */ + FT_EXPORT( FT_UShort ) + FT_Get_FSType_Flags( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* glyph_variants */ + /* */ + /* <Title> */ + /* Unicode Variation Sequences */ + /* */ + /* <Abstract> */ + /* The FreeType~2 interface to Unicode Variation Sequences (UVS), */ + /* using the SFNT cmap format~14. */ + /* */ + /* <Description> */ + /* Many characters, especially for CJK scripts, have variant forms. */ + /* They are a sort of grey area somewhere between being totally */ + /* irrelevant and semantically distinct; for this reason, the Unicode */ + /* consortium decided to introduce Variation Sequences (VS), */ + /* consisting of a Unicode base character and a variation selector */ + /* instead of further extending the already huge number of */ + /* characters. */ + /* */ + /* Unicode maintains two different sets, namely `Standardized */ + /* Variation Sequences' and registered `Ideographic Variation */ + /* Sequences' (IVS), collected in the `Ideographic Variation */ + /* Database' (IVD). */ + /* */ + /* https://unicode.org/Public/UCD/latest/ucd/StandardizedVariants.txt */ + /* https://unicode.org/reports/tr37/ */ + /* https://unicode.org/ivd/ */ + /* */ + /* To date (January 2017), the character with the most ideographic */ + /* variations is U+9089, having 32 such IVS. */ + /* */ + /* Three Mongolian Variation Selectors have the values U+180B-U+180D; */ + /* 256 generic Variation Selectors are encoded in the ranges */ + /* U+FE00-U+FE0F and U+E0100-U+E01EF. IVS currently use Variation */ + /* Selectors from the range U+E0100-U+E01EF only. */ + /* */ + /* A VS consists of the base character value followed by a single */ + /* Variation Selector. For example, to get the first variation of */ + /* U+9089, you have to write the character sequence `U+9089 U+E0100'. */ + /* */ + /* Adobe and MS decided to support both standardized and ideographic */ + /* VS with a new cmap subtable (format~14). It is an odd subtable */ + /* because it is not a mapping of input code points to glyphs, but */ + /* contains lists of all variations supported by the font. */ + /* */ + /* A variation may be either `default' or `non-default' for a given */ + /* font. A default variation is the one you will get for that code */ + /* point if you look it up in the standard Unicode cmap. A */ + /* non-default variation is a different glyph. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharVariantIndex */ + /* */ + /* <Description> */ + /* Return the glyph index of a given character code as modified by */ + /* the variation selector. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character code point in Unicode. */ + /* */ + /* variantSelector :: */ + /* The Unicode code point of the variation selector. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means either `undefined character code', or */ + /* `undefined selector code', or `no variation selector cmap */ + /* subtable', or `current CharMap is not Unicode'. */ + /* */ + /* <Note> */ + /* If you use FreeType to manipulate the contents of font files */ + /* directly, be aware that the glyph index returned by this function */ + /* doesn't always correspond to the internal indices used within */ + /* the file. This is done to ensure that value~0 always corresponds */ + /* to the `missing glyph'. */ + /* */ + /* This function is only meaningful if */ + /* a) the font has a variation selector cmap sub table, */ + /* and */ + /* b) the current charmap has a Unicode encoding. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Face_GetCharVariantIndex( FT_Face face, + FT_ULong charcode, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharVariantIsDefault */ + /* */ + /* <Description> */ + /* Check whether this variation of this Unicode character is the one */ + /* to be found in the `cmap'. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character codepoint in Unicode. */ + /* */ + /* variantSelector :: */ + /* The Unicode codepoint of the variation selector. */ + /* */ + /* <Return> */ + /* 1~if found in the standard (Unicode) cmap, 0~if found in the */ + /* variation selector cmap, or -1 if it is not a variation. */ + /* */ + /* <Note> */ + /* This function is only meaningful if the font has a variation */ + /* selector cmap subtable. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_Int ) + FT_Face_GetCharVariantIsDefault( FT_Face face, + FT_ULong charcode, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetVariantSelectors */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode variation selectors found */ + /* in the font. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* <Return> */ + /* A pointer to an array of selector code points, or NULL if there is */ + /* no valid variation selector cmap subtable. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetVariantSelectors( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetVariantsOfChar */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode variation selectors found */ + /* for the specified character code. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character codepoint in Unicode. */ + /* */ + /* <Return> */ + /* A pointer to an array of variation selector code points that are */ + /* active for the given character, or NULL if the corresponding list */ + /* is empty. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetVariantsOfChar( FT_Face face, + FT_ULong charcode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharsOfVariant */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode character codes found for */ + /* the specified variation selector. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* variantSelector :: */ + /* The variation selector code point in Unicode. */ + /* */ + /* <Return> */ + /* A list of all the code points that are specified by this selector */ + /* (both default and non-default codes are returned) or NULL if there */ + /* is no valid cmap or the variation selector is invalid. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetCharsOfVariant( FT_Face face, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /* <Title> */ + /* Computations */ + /* */ + /* <Abstract> */ + /* Crunching fixed numbers and vectors. */ + /* */ + /* <Description> */ + /* This section contains various functions used to perform */ + /* computations on 16.16 fixed-float numbers or 2d vectors. */ + /* */ + /* <Order> */ + /* FT_MulDiv */ + /* FT_MulFix */ + /* FT_DivFix */ + /* FT_RoundFix */ + /* FT_CeilFix */ + /* FT_FloorFix */ + /* FT_Vector_Transform */ + /* FT_Matrix_Multiply */ + /* FT_Matrix_Invert */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_MulDiv */ + /* */ + /* <Description> */ + /* Compute `(a*b)/c' with maximum accuracy, using a 64-bit */ + /* intermediate integer whenever necessary. */ + /* */ + /* This function isn't necessarily as fast as some processor specific */ + /* operations, but is at least completely portable. */ + /* */ + /* <Input> */ + /* a :: The first multiplier. */ + /* */ + /* b :: The second multiplier. */ + /* */ + /* c :: The divisor. */ + /* */ + /* <Return> */ + /* The result of `(a*b)/c'. This function never traps when trying to */ + /* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ + /* on the signs of `a' and `b'. */ + /* */ + FT_EXPORT( FT_Long ) + FT_MulDiv( FT_Long a, + FT_Long b, + FT_Long c ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_MulFix */ + /* */ + /* <Description> */ + /* Compute `(a*b)/0x10000' with maximum accuracy. Its main use is to */ + /* multiply a given value by a 16.16 fixed-point factor. */ + /* */ + /* <Input> */ + /* a :: The first multiplier. */ + /* */ + /* b :: The second multiplier. Use a 16.16 factor here whenever */ + /* possible (see note below). */ + /* */ + /* <Return> */ + /* The result of `(a*b)/0x10000'. */ + /* */ + /* <Note> */ + /* This function has been optimized for the case where the absolute */ + /* value of `a' is less than 2048, and `b' is a 16.16 scaling factor. */ + /* As this happens mainly when scaling from notional units to */ + /* fractional pixels in FreeType, it resulted in noticeable speed */ + /* improvements between versions 2.x and 1.x. */ + /* */ + /* As a conclusion, always try to place a 16.16 factor as the */ + /* _second_ argument of this function; this can make a great */ + /* difference. */ + /* */ + FT_EXPORT( FT_Long ) + FT_MulFix( FT_Long a, + FT_Long b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_DivFix */ + /* */ + /* <Description> */ + /* Compute `(a*0x10000)/b' with maximum accuracy. Its main use is to */ + /* divide a given value by a 16.16 fixed-point factor. */ + /* */ + /* <Input> */ + /* a :: The numerator. */ + /* */ + /* b :: The denominator. Use a 16.16 factor here. */ + /* */ + /* <Return> */ + /* The result of `(a*0x10000)/b'. */ + /* */ + FT_EXPORT( FT_Long ) + FT_DivFix( FT_Long a, + FT_Long b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_RoundFix */ + /* */ + /* <Description> */ + /* Round a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number to be rounded. */ + /* */ + /* <Return> */ + /* `a' rounded to the nearest 16.16 fixed integer, halfway cases away */ + /* from zero. */ + /* */ + /* <Note> */ + /* The function uses wrap-around arithmetic. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_RoundFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_CeilFix */ + /* */ + /* <Description> */ + /* Compute the smallest following integer of a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number for which the ceiling function is to be computed. */ + /* */ + /* <Return> */ + /* `a' rounded towards plus infinity. */ + /* */ + /* <Note> */ + /* The function uses wrap-around arithmetic. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_CeilFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_FloorFix */ + /* */ + /* <Description> */ + /* Compute the largest previous integer of a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number for which the floor function is to be computed. */ + /* */ + /* <Return> */ + /* `a' rounded towards minus infinity. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_FloorFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Vector_Transform */ + /* */ + /* <Description> */ + /* Transform a single vector through a 2x2 matrix. */ + /* */ + /* <InOut> */ + /* vector :: The target vector to transform. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the source 2x2 matrix. */ + /* */ + /* <Note> */ + /* The result is undefined if either `vector' or `matrix' is invalid. */ + /* */ + FT_EXPORT( void ) + FT_Vector_Transform( FT_Vector* vec, + const FT_Matrix* matrix ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* version */ + /* */ + /* <Title> */ + /* FreeType Version */ + /* */ + /* <Abstract> */ + /* Functions and macros related to FreeType versions. */ + /* */ + /* <Description> */ + /* Note that those functions and macros are of limited use because */ + /* even a new release of FreeType with only documentation changes */ + /* increases the version number. */ + /* */ + /* <Order> */ + /* FT_Library_Version */ + /* */ + /* FREETYPE_MAJOR */ + /* FREETYPE_MINOR */ + /* FREETYPE_PATCH */ + /* */ + /* FT_Face_CheckTrueTypePatents */ + /* FT_Face_SetUnpatentedHinting */ + /* */ + /* FREETYPE_XXX */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @enum: + * FREETYPE_XXX + * + * @description: + * These three macros identify the FreeType source code version. + * Use @FT_Library_Version to access them at runtime. + * + * @values: + * FREETYPE_MAJOR :: The major version number. + * FREETYPE_MINOR :: The minor version number. + * FREETYPE_PATCH :: The patch level. + * + * @note: + * The version number of FreeType if built as a dynamic link library + * with the `libtool' package is _not_ controlled by these three + * macros. + * + */ +#define FREETYPE_MAJOR 2 +#define FREETYPE_MINOR 9 +#define FREETYPE_PATCH 1 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Library_Version */ + /* */ + /* <Description> */ + /* Return the version of the FreeType library being used. This is */ + /* useful when dynamically linking to the library, since one cannot */ + /* use the macros @FREETYPE_MAJOR, @FREETYPE_MINOR, and */ + /* @FREETYPE_PATCH. */ + /* */ + /* <Input> */ + /* library :: A source library handle. */ + /* */ + /* <Output> */ + /* amajor :: The major version number. */ + /* */ + /* aminor :: The minor version number. */ + /* */ + /* apatch :: The patch version number. */ + /* */ + /* <Note> */ + /* The reason why this function takes a `library' argument is because */ + /* certain programs implement library initialization in a custom way */ + /* that doesn't use @FT_Init_FreeType. */ + /* */ + /* In such cases, the library version might not be available before */ + /* the library object has been created. */ + /* */ + FT_EXPORT( void ) + FT_Library_Version( FT_Library library, + FT_Int *amajor, + FT_Int *aminor, + FT_Int *apatch ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_CheckTrueTypePatents */ + /* */ + /* <Description> */ + /* Deprecated, does nothing. */ + /* */ + /* <Input> */ + /* face :: A face handle. */ + /* */ + /* <Return> */ + /* Always returns false. */ + /* */ + /* <Note> */ + /* Since May 2010, TrueType hinting is no longer patented. */ + /* */ + /* <Since> */ + /* 2.3.5 */ + /* */ + FT_EXPORT( FT_Bool ) + FT_Face_CheckTrueTypePatents( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_SetUnpatentedHinting */ + /* */ + /* <Description> */ + /* Deprecated, does nothing. */ + /* */ + /* <Input> */ + /* face :: A face handle. */ + /* */ + /* value :: New boolean setting. */ + /* */ + /* <Return> */ + /* Always returns false. */ + /* */ + /* <Note> */ + /* Since May 2010, TrueType hinting is no longer patented. */ + /* */ + /* <Since> */ + /* 2.3.5 */ + /* */ + FT_EXPORT( FT_Bool ) + FT_Face_SetUnpatentedHinting( FT_Face face, + FT_Bool value ); + + /* */ + + +FT_END_HEADER + +#endif /* FREETYPE_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftadvanc.h b/freetype/include/freetype2/freetype/ftadvanc.h new file mode 100644 index 0000000..f78e8b1 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftadvanc.h @@ -0,0 +1,187 @@ +/***************************************************************************/ +/* */ +/* ftadvanc.h */ +/* */ +/* Quick computation of advance widths (specification only). */ +/* */ +/* Copyright 2008-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTADVANC_H_ +#define FTADVANC_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * quick_advance + * + * @title: + * Quick retrieval of advance values + * + * @abstract: + * Retrieve horizontal and vertical advance values without processing + * glyph outlines, if possible. + * + * @description: + * This section contains functions to quickly extract advance values + * without handling glyph outlines, if possible. + * + * @order: + * FT_Get_Advance + * FT_Get_Advances + * + */ + + + /*************************************************************************/ + /* */ + /* <Const> */ + /* FT_ADVANCE_FLAG_FAST_ONLY */ + /* */ + /* <Description> */ + /* A bit-flag to be OR-ed with the `flags' parameter of the */ + /* @FT_Get_Advance and @FT_Get_Advances functions. */ + /* */ + /* If set, it indicates that you want these functions to fail if the */ + /* corresponding hinting mode or font driver doesn't allow for very */ + /* quick advance computation. */ + /* */ + /* Typically, glyphs that are either unscaled, unhinted, bitmapped, */ + /* or light-hinted can have their advance width computed very */ + /* quickly. */ + /* */ + /* Normal and bytecode hinted modes that require loading, scaling, */ + /* and hinting of the glyph outline, are extremely slow by */ + /* comparison. */ + /* */ +#define FT_ADVANCE_FLAG_FAST_ONLY 0x20000000L + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Advance */ + /* */ + /* <Description> */ + /* Retrieve the advance value of a given glyph outline in an */ + /* @FT_Face. */ + /* */ + /* <Input> */ + /* face :: The source @FT_Face handle. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* load_flags :: A set of bit flags similar to those used when */ + /* calling @FT_Load_Glyph, used to determine what kind */ + /* of advances you need. */ + /* <Output> */ + /* padvance :: The advance value. If scaling is performed (based on */ + /* the value of `load_flags'), the advance value is in */ + /* 16.16 format. Otherwise, it is in font units. */ + /* */ + /* If @FT_LOAD_VERTICAL_LAYOUT is set, this is the */ + /* vertical advance corresponding to a vertical layout. */ + /* Otherwise, it is the horizontal advance in a */ + /* horizontal layout. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY and */ + /* if the corresponding font backend doesn't have a quick way to */ + /* retrieve the advances. */ + /* */ + /* A scaled advance is returned in 16.16 format but isn't transformed */ + /* by the affine transformation specified by @FT_Set_Transform. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Advance( FT_Face face, + FT_UInt gindex, + FT_Int32 load_flags, + FT_Fixed *padvance ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Advances */ + /* */ + /* <Description> */ + /* Retrieve the advance values of several glyph outlines in an */ + /* @FT_Face. */ + /* */ + /* <Input> */ + /* face :: The source @FT_Face handle. */ + /* */ + /* start :: The first glyph index. */ + /* */ + /* count :: The number of advance values you want to retrieve. */ + /* */ + /* load_flags :: A set of bit flags similar to those used when */ + /* calling @FT_Load_Glyph. */ + /* */ + /* <Output> */ + /* padvance :: The advance values. This array, to be provided by the */ + /* caller, must contain at least `count' elements. */ + /* */ + /* If scaling is performed (based on the value of */ + /* `load_flags'), the advance values are in 16.16 format. */ + /* Otherwise, they are in font units. */ + /* */ + /* If @FT_LOAD_VERTICAL_LAYOUT is set, these are the */ + /* vertical advances corresponding to a vertical layout. */ + /* Otherwise, they are the horizontal advances in a */ + /* horizontal layout. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY and */ + /* if the corresponding font backend doesn't have a quick way to */ + /* retrieve the advances. */ + /* */ + /* Scaled advances are returned in 16.16 format but aren't */ + /* transformed by the affine transformation specified by */ + /* @FT_Set_Transform. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Advances( FT_Face face, + FT_UInt start, + FT_UInt count, + FT_Int32 load_flags, + FT_Fixed *padvances ); + + /* */ + + +FT_END_HEADER + +#endif /* FTADVANC_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftbbox.h b/freetype/include/freetype2/freetype/ftbbox.h new file mode 100644 index 0000000..f9eb70b --- /dev/null +++ b/freetype/include/freetype2/freetype/ftbbox.h @@ -0,0 +1,101 @@ +/***************************************************************************/ +/* */ +/* ftbbox.h */ +/* */ +/* FreeType exact bbox computation (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This component has a _single_ role: to compute exact outline bounding */ + /* boxes. */ + /* */ + /* It is separated from the rest of the engine for various technical */ + /* reasons. It may well be integrated in `ftoutln' later. */ + /* */ + /*************************************************************************/ + + +#ifndef FTBBOX_H_ +#define FTBBOX_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* outline_processing */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Get_BBox */ + /* */ + /* <Description> */ + /* Compute the exact bounding box of an outline. This is slower */ + /* than computing the control box. However, it uses an advanced */ + /* algorithm that returns _very_ quickly when the two boxes */ + /* coincide. Otherwise, the outline Bezier arcs are traversed to */ + /* extract their extrema. */ + /* */ + /* <Input> */ + /* outline :: A pointer to the source outline. */ + /* */ + /* <Output> */ + /* abbox :: The outline's exact bounding box. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If the font is tricky and the glyph has been loaded with */ + /* @FT_LOAD_NO_SCALE, the resulting BBox is meaningless. To get */ + /* reasonable values for the BBox it is necessary to load the glyph */ + /* at a large ppem value (so that the hinting instructions can */ + /* properly shift and scale the subglyphs), then extracting the BBox, */ + /* which can be eventually converted back to font units. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Get_BBox( FT_Outline* outline, + FT_BBox *abbox ); + + /* */ + + +FT_END_HEADER + +#endif /* FTBBOX_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/freetype/include/freetype2/freetype/ftbdf.h b/freetype/include/freetype2/freetype/ftbdf.h new file mode 100644 index 0000000..1b6dea6 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftbdf.h @@ -0,0 +1,210 @@ +/***************************************************************************/ +/* */ +/* ftbdf.h */ +/* */ +/* FreeType API for accessing BDF-specific strings (specification). */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTBDF_H_ +#define FTBDF_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* bdf_fonts */ + /* */ + /* <Title> */ + /* BDF and PCF Files */ + /* */ + /* <Abstract> */ + /* BDF and PCF specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions specific to BDF */ + /* and PCF fonts. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @enum: + * BDF_PropertyType + * + * @description: + * A list of BDF property types. + * + * @values: + * BDF_PROPERTY_TYPE_NONE :: + * Value~0 is used to indicate a missing property. + * + * BDF_PROPERTY_TYPE_ATOM :: + * Property is a string atom. + * + * BDF_PROPERTY_TYPE_INTEGER :: + * Property is a 32-bit signed integer. + * + * BDF_PROPERTY_TYPE_CARDINAL :: + * Property is a 32-bit unsigned integer. + */ + typedef enum BDF_PropertyType_ + { + BDF_PROPERTY_TYPE_NONE = 0, + BDF_PROPERTY_TYPE_ATOM = 1, + BDF_PROPERTY_TYPE_INTEGER = 2, + BDF_PROPERTY_TYPE_CARDINAL = 3 + + } BDF_PropertyType; + + + /********************************************************************** + * + * @type: + * BDF_Property + * + * @description: + * A handle to a @BDF_PropertyRec structure to model a given + * BDF/PCF property. + */ + typedef struct BDF_PropertyRec_* BDF_Property; + + + /********************************************************************** + * + * @struct: + * BDF_PropertyRec + * + * @description: + * This structure models a given BDF/PCF property. + * + * @fields: + * type :: + * The property type. + * + * u.atom :: + * The atom string, if type is @BDF_PROPERTY_TYPE_ATOM. May be + * NULL, indicating an empty string. + * + * u.integer :: + * A signed integer, if type is @BDF_PROPERTY_TYPE_INTEGER. + * + * u.cardinal :: + * An unsigned integer, if type is @BDF_PROPERTY_TYPE_CARDINAL. + */ + typedef struct BDF_PropertyRec_ + { + BDF_PropertyType type; + union { + const char* atom; + FT_Int32 integer; + FT_UInt32 cardinal; + + } u; + + } BDF_PropertyRec; + + + /********************************************************************** + * + * @function: + * FT_Get_BDF_Charset_ID + * + * @description: + * Retrieve a BDF font character set identity, according to + * the BDF specification. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * acharset_encoding :: + * Charset encoding, as a C~string, owned by the face. + * + * acharset_registry :: + * Charset registry, as a C~string, owned by the face. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with BDF faces, returning an error otherwise. + */ + FT_EXPORT( FT_Error ) + FT_Get_BDF_Charset_ID( FT_Face face, + const char* *acharset_encoding, + const char* *acharset_registry ); + + + /********************************************************************** + * + * @function: + * FT_Get_BDF_Property + * + * @description: + * Retrieve a BDF property from a BDF or PCF font file. + * + * @input: + * face :: A handle to the input face. + * + * name :: The property name. + * + * @output: + * aproperty :: The property. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function works with BDF _and_ PCF fonts. It returns an error + * otherwise. It also returns an error if the property is not in the + * font. + * + * A `property' is a either key-value pair within the STARTPROPERTIES + * ... ENDPROPERTIES block of a BDF font or a key-value pair from the + * `info->props' array within a `FontRec' structure of a PCF font. + * + * Integer properties are always stored as `signed' within PCF fonts; + * consequently, @BDF_PROPERTY_TYPE_CARDINAL is a possible return value + * for BDF fonts only. + * + * In case of error, `aproperty->type' is always set to + * @BDF_PROPERTY_TYPE_NONE. + */ + FT_EXPORT( FT_Error ) + FT_Get_BDF_Property( FT_Face face, + const char* prop_name, + BDF_PropertyRec *aproperty ); + + /* */ + +FT_END_HEADER + +#endif /* FTBDF_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftbitmap.h b/freetype/include/freetype2/freetype/ftbitmap.h new file mode 100644 index 0000000..a43187c --- /dev/null +++ b/freetype/include/freetype2/freetype/ftbitmap.h @@ -0,0 +1,240 @@ +/***************************************************************************/ +/* */ +/* ftbitmap.h */ +/* */ +/* FreeType utility functions for bitmaps (specification). */ +/* */ +/* Copyright 2004-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTBITMAP_H_ +#define FTBITMAP_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* bitmap_handling */ + /* */ + /* <Title> */ + /* Bitmap Handling */ + /* */ + /* <Abstract> */ + /* Handling FT_Bitmap objects. */ + /* */ + /* <Description> */ + /* This section contains functions for handling @FT_Bitmap objects. */ + /* Note that none of the functions changes the bitmap's `flow' (as */ + /* indicated by the sign of the `pitch' field in `FT_Bitmap'). */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Init */ + /* */ + /* <Description> */ + /* Initialize a pointer to an @FT_Bitmap structure. */ + /* */ + /* <InOut> */ + /* abitmap :: A pointer to the bitmap structure. */ + /* */ + /* <Note> */ + /* A deprecated name for the same function is `FT_Bitmap_New'. */ + /* */ + FT_EXPORT( void ) + FT_Bitmap_Init( FT_Bitmap *abitmap ); + + + /* deprecated */ + FT_EXPORT( void ) + FT_Bitmap_New( FT_Bitmap *abitmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Copy */ + /* */ + /* <Description> */ + /* Copy a bitmap into another one. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* source :: A handle to the source bitmap. */ + /* */ + /* <Output> */ + /* target :: A handle to the target bitmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Copy( FT_Library library, + const FT_Bitmap *source, + FT_Bitmap *target ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Embolden */ + /* */ + /* <Description> */ + /* Embolden a bitmap. The new bitmap will be about `xStrength' */ + /* pixels wider and `yStrength' pixels higher. The left and bottom */ + /* borders are kept unchanged. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* xStrength :: How strong the glyph is emboldened horizontally. */ + /* Expressed in 26.6 pixel format. */ + /* */ + /* yStrength :: How strong the glyph is emboldened vertically. */ + /* Expressed in 26.6 pixel format. */ + /* */ + /* <InOut> */ + /* bitmap :: A handle to the target bitmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The current implementation restricts `xStrength' to be less than */ + /* or equal to~8 if bitmap is of pixel_mode @FT_PIXEL_MODE_MONO. */ + /* */ + /* If you want to embolden the bitmap owned by a @FT_GlyphSlotRec, */ + /* you should call @FT_GlyphSlot_Own_Bitmap on the slot first. */ + /* */ + /* Bitmaps in @FT_PIXEL_MODE_GRAY2 and @FT_PIXEL_MODE_GRAY@ format */ + /* are converted to @FT_PIXEL_MODE_GRAY format (i.e., 8bpp). */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Embolden( FT_Library library, + FT_Bitmap* bitmap, + FT_Pos xStrength, + FT_Pos yStrength ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Convert */ + /* */ + /* <Description> */ + /* Convert a bitmap object with depth 1bpp, 2bpp, 4bpp, 8bpp or 32bpp */ + /* to a bitmap object with depth 8bpp, making the number of used */ + /* bytes line (a.k.a. the `pitch') a multiple of `alignment'. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* source :: The source bitmap. */ + /* */ + /* alignment :: The pitch of the bitmap is a multiple of this */ + /* parameter. Common values are 1, 2, or 4. */ + /* */ + /* <Output> */ + /* target :: The target bitmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* It is possible to call @FT_Bitmap_Convert multiple times without */ + /* calling @FT_Bitmap_Done (the memory is simply reallocated). */ + /* */ + /* Use @FT_Bitmap_Done to finally remove the bitmap object. */ + /* */ + /* The `library' argument is taken to have access to FreeType's */ + /* memory handling functions. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Convert( FT_Library library, + const FT_Bitmap *source, + FT_Bitmap *target, + FT_Int alignment ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GlyphSlot_Own_Bitmap */ + /* */ + /* <Description> */ + /* Make sure that a glyph slot owns `slot->bitmap'. */ + /* */ + /* <Input> */ + /* slot :: The glyph slot. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function is to be used in combination with */ + /* @FT_Bitmap_Embolden. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Bitmap_Done */ + /* */ + /* <Description> */ + /* Destroy a bitmap object initialized with @FT_Bitmap_Init. */ + /* */ + /* <Input> */ + /* library :: A handle to a library object. */ + /* */ + /* bitmap :: The bitmap object to be freed. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `library' argument is taken to have access to FreeType's */ + /* memory handling functions. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Bitmap_Done( FT_Library library, + FT_Bitmap *bitmap ); + + + /* */ + + +FT_END_HEADER + +#endif /* FTBITMAP_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftbzip2.h b/freetype/include/freetype2/freetype/ftbzip2.h new file mode 100644 index 0000000..6edfa03 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftbzip2.h @@ -0,0 +1,102 @@ +/***************************************************************************/ +/* */ +/* ftbzip2.h */ +/* */ +/* Bzip2-compressed stream support. */ +/* */ +/* Copyright 2010-2018 by */ +/* Joel Klinghed. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTBZIP2_H_ +#define FTBZIP2_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* bzip2 */ + /* */ + /* <Title> */ + /* BZIP2 Streams */ + /* */ + /* <Abstract> */ + /* Using bzip2-compressed font files. */ + /* */ + /* <Description> */ + /* This section contains the declaration of Bzip2-specific functions. */ + /* */ + /*************************************************************************/ + + + /************************************************************************ + * + * @function: + * FT_Stream_OpenBzip2 + * + * @description: + * Open a new stream to parse bzip2-compressed font files. This is + * mainly used to support the compressed `*.pcf.bz2' fonts that come + * with XFree86. + * + * @input: + * stream :: + * The target embedding stream. + * + * source :: + * The source stream. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source stream must be opened _before_ calling this function. + * + * Calling the internal function `FT_Stream_Close' on the new stream will + * *not* call `FT_Stream_Close' on the source stream. None of the stream + * objects will be released to the heap. + * + * The stream implementation is very basic and resets the decompression + * process each time seeking backwards is needed within the stream. + * + * In certain builds of the library, bzip2 compression recognition is + * automatically handled when calling @FT_New_Face or @FT_Open_Face. + * This means that if no font driver is capable of handling the raw + * compressed file, the library will try to open a bzip2 compressed stream + * from it and re-open the face with it. + * + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with bzip2 support. + */ + FT_EXPORT( FT_Error ) + FT_Stream_OpenBzip2( FT_Stream stream, + FT_Stream source ); + + /* */ + + +FT_END_HEADER + +#endif /* FTBZIP2_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftcache.h b/freetype/include/freetype2/freetype/ftcache.h new file mode 100644 index 0000000..52d5f00 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftcache.h @@ -0,0 +1,1042 @@ +/***************************************************************************/ +/* */ +/* ftcache.h */ +/* */ +/* FreeType Cache subsystem (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTCACHE_H_ +#define FTCACHE_H_ + + +#include <ft2build.h> +#include FT_GLYPH_H + + +FT_BEGIN_HEADER + + + /************************************************************************* + * + * <Section> + * cache_subsystem + * + * <Title> + * Cache Sub-System + * + * <Abstract> + * How to cache face, size, and glyph data with FreeType~2. + * + * <Description> + * This section describes the FreeType~2 cache sub-system, which is used + * to limit the number of concurrently opened @FT_Face and @FT_Size + * objects, as well as caching information like character maps and glyph + * images while limiting their maximum memory usage. + * + * Note that all types and functions begin with the `FTC_' prefix. + * + * The cache is highly portable and thus doesn't know anything about the + * fonts installed on your system, or how to access them. This implies + * the following scheme: + * + * First, available or installed font faces are uniquely identified by + * @FTC_FaceID values, provided to the cache by the client. Note that + * the cache only stores and compares these values, and doesn't try to + * interpret them in any way. + * + * Second, the cache calls, only when needed, a client-provided function + * to convert an @FTC_FaceID into a new @FT_Face object. The latter is + * then completely managed by the cache, including its termination + * through @FT_Done_Face. To monitor termination of face objects, the + * finalizer callback in the `generic' field of the @FT_Face object can + * be used, which might also be used to store the @FTC_FaceID of the + * face. + * + * Clients are free to map face IDs to anything else. The most simple + * usage is to associate them to a (pathname,face_index) pair that is + * used to call @FT_New_Face. However, more complex schemes are also + * possible. + * + * Note that for the cache to work correctly, the face ID values must be + * *persistent*, which means that the contents they point to should not + * change at runtime, or that their value should not become invalid. + * + * If this is unavoidable (e.g., when a font is uninstalled at runtime), + * you should call @FTC_Manager_RemoveFaceID as soon as possible, to let + * the cache get rid of any references to the old @FTC_FaceID it may + * keep internally. Failure to do so will lead to incorrect behaviour + * or even crashes. + * + * To use the cache, start with calling @FTC_Manager_New to create a new + * @FTC_Manager object, which models a single cache instance. You can + * then look up @FT_Face and @FT_Size objects with + * @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively. + * + * If you want to use the charmap caching, call @FTC_CMapCache_New, then + * later use @FTC_CMapCache_Lookup to perform the equivalent of + * @FT_Get_Char_Index, only much faster. + * + * If you want to use the @FT_Glyph caching, call @FTC_ImageCache, then + * later use @FTC_ImageCache_Lookup to retrieve the corresponding + * @FT_Glyph objects from the cache. + * + * If you need lots of small bitmaps, it is much more memory efficient + * to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup. This + * returns @FTC_SBitRec structures, which are used to store small + * bitmaps directly. (A small bitmap is one whose metrics and + * dimensions all fit into 8-bit integers). + * + * We hope to also provide a kerning cache in the near future. + * + * + * <Order> + * FTC_Manager + * FTC_FaceID + * FTC_Face_Requester + * + * FTC_Manager_New + * FTC_Manager_Reset + * FTC_Manager_Done + * FTC_Manager_LookupFace + * FTC_Manager_LookupSize + * FTC_Manager_RemoveFaceID + * + * FTC_Node + * FTC_Node_Unref + * + * FTC_ImageCache + * FTC_ImageCache_New + * FTC_ImageCache_Lookup + * + * FTC_SBit + * FTC_SBitCache + * FTC_SBitCache_New + * FTC_SBitCache_Lookup + * + * FTC_CMapCache + * FTC_CMapCache_New + * FTC_CMapCache_Lookup + * + *************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** BASIC TYPE DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: FTC_FaceID + * + * @description: + * An opaque pointer type that is used to identity face objects. The + * contents of such objects is application-dependent. + * + * These pointers are typically used to point to a user-defined + * structure containing a font file path, and face index. + * + * @note: + * Never use NULL as a valid @FTC_FaceID. + * + * Face IDs are passed by the client to the cache manager that calls, + * when needed, the @FTC_Face_Requester to translate them into new + * @FT_Face objects. + * + * If the content of a given face ID changes at runtime, or if the value + * becomes invalid (e.g., when uninstalling a font), you should + * immediately call @FTC_Manager_RemoveFaceID before any other cache + * function. + * + * Failure to do so will result in incorrect behaviour or even + * memory leaks and crashes. + */ + typedef FT_Pointer FTC_FaceID; + + + /************************************************************************ + * + * @functype: + * FTC_Face_Requester + * + * @description: + * A callback function provided by client applications. It is used by + * the cache manager to translate a given @FTC_FaceID into a new valid + * @FT_Face object, on demand. + * + * <Input> + * face_id :: + * The face ID to resolve. + * + * library :: + * A handle to a FreeType library object. + * + * req_data :: + * Application-provided request data (see note below). + * + * <Output> + * aface :: + * A new @FT_Face handle. + * + * <Return> + * FreeType error code. 0~means success. + * + * <Note> + * The third parameter `req_data' is the same as the one passed by the + * client when @FTC_Manager_New is called. + * + * The face requester should not perform funny things on the returned + * face object, like creating a new @FT_Size for it, or setting a + * transformation through @FT_Set_Transform! + */ + typedef FT_Error + (*FTC_Face_Requester)( FTC_FaceID face_id, + FT_Library library, + FT_Pointer req_data, + FT_Face* aface ); + + /* */ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE MANAGER OBJECT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_Manager */ + /* */ + /* <Description> */ + /* This object corresponds to one instance of the cache-subsystem. */ + /* It is used to cache one or more @FT_Face objects, along with */ + /* corresponding @FT_Size objects. */ + /* */ + /* The manager intentionally limits the total number of opened */ + /* @FT_Face and @FT_Size objects to control memory usage. See the */ + /* `max_faces' and `max_sizes' parameters of @FTC_Manager_New. */ + /* */ + /* The manager is also used to cache `nodes' of various types while */ + /* limiting their total memory usage. */ + /* */ + /* All limitations are enforced by keeping lists of managed objects */ + /* in most-recently-used order, and flushing old nodes to make room */ + /* for new ones. */ + /* */ + typedef struct FTC_ManagerRec_* FTC_Manager; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_Node */ + /* */ + /* <Description> */ + /* An opaque handle to a cache node object. Each cache node is */ + /* reference-counted. A node with a count of~0 might be flushed */ + /* out of a full cache whenever a lookup request is performed. */ + /* */ + /* If you look up nodes, you have the ability to `acquire' them, */ + /* i.e., to increment their reference count. This will prevent the */ + /* node from being flushed out of the cache until you explicitly */ + /* `release' it (see @FTC_Node_Unref). */ + /* */ + /* See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup. */ + /* */ + typedef struct FTC_NodeRec_* FTC_Node; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_New */ + /* */ + /* <Description> */ + /* Create a new cache manager. */ + /* */ + /* <Input> */ + /* library :: The parent FreeType library handle to use. */ + /* */ + /* max_faces :: Maximum number of opened @FT_Face objects managed by */ + /* this cache instance. Use~0 for defaults. */ + /* */ + /* max_sizes :: Maximum number of opened @FT_Size objects managed by */ + /* this cache instance. Use~0 for defaults. */ + /* */ + /* max_bytes :: Maximum number of bytes to use for cached data nodes. */ + /* Use~0 for defaults. Note that this value does not */ + /* account for managed @FT_Face and @FT_Size objects. */ + /* */ + /* requester :: An application-provided callback used to translate */ + /* face IDs into real @FT_Face objects. */ + /* */ + /* req_data :: A generic pointer that is passed to the requester */ + /* each time it is called (see @FTC_Face_Requester). */ + /* */ + /* <Output> */ + /* amanager :: A handle to a new manager object. 0~in case of */ + /* failure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Manager_New( FT_Library library, + FT_UInt max_faces, + FT_UInt max_sizes, + FT_ULong max_bytes, + FTC_Face_Requester requester, + FT_Pointer req_data, + FTC_Manager *amanager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_Reset */ + /* */ + /* <Description> */ + /* Empty a given cache manager. This simply gets rid of all the */ + /* currently cached @FT_Face and @FT_Size objects within the manager. */ + /* */ + /* <InOut> */ + /* manager :: A handle to the manager. */ + /* */ + FT_EXPORT( void ) + FTC_Manager_Reset( FTC_Manager manager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_Done */ + /* */ + /* <Description> */ + /* Destroy a given manager after emptying it. */ + /* */ + /* <Input> */ + /* manager :: A handle to the target cache manager object. */ + /* */ + FT_EXPORT( void ) + FTC_Manager_Done( FTC_Manager manager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_LookupFace */ + /* */ + /* <Description> */ + /* Retrieve the @FT_Face object that corresponds to a given face ID */ + /* through a cache manager. */ + /* */ + /* <Input> */ + /* manager :: A handle to the cache manager. */ + /* */ + /* face_id :: The ID of the face object. */ + /* */ + /* <Output> */ + /* aface :: A handle to the face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned @FT_Face object is always owned by the manager. You */ + /* should never try to discard it yourself. */ + /* */ + /* The @FT_Face object doesn't necessarily have a current size object */ + /* (i.e., face->size can be~0). If you need a specific `font size', */ + /* use @FTC_Manager_LookupSize instead. */ + /* */ + /* Never change the face's transformation matrix (i.e., never call */ + /* the @FT_Set_Transform function) on a returned face! If you need */ + /* to transform glyphs, do it yourself after glyph loading. */ + /* */ + /* When you perform a lookup, out-of-memory errors are detected */ + /* _within_ the lookup and force incremental flushes of the cache */ + /* until enough memory is released for the lookup to succeed. */ + /* */ + /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */ + /* already been completely flushed, and still no memory was available */ + /* for the operation. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Manager_LookupFace( FTC_Manager manager, + FTC_FaceID face_id, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_ScalerRec */ + /* */ + /* <Description> */ + /* A structure used to describe a given character size in either */ + /* pixels or points to the cache manager. See */ + /* @FTC_Manager_LookupSize. */ + /* */ + /* <Fields> */ + /* face_id :: The source face ID. */ + /* */ + /* width :: The character width. */ + /* */ + /* height :: The character height. */ + /* */ + /* pixel :: A Boolean. If 1, the `width' and `height' fields are */ + /* interpreted as integer pixel character sizes. */ + /* Otherwise, they are expressed as 1/64th of points. */ + /* */ + /* x_res :: Only used when `pixel' is value~0 to indicate the */ + /* horizontal resolution in dpi. */ + /* */ + /* y_res :: Only used when `pixel' is value~0 to indicate the */ + /* vertical resolution in dpi. */ + /* */ + /* <Note> */ + /* This type is mainly used to retrieve @FT_Size objects through the */ + /* cache manager. */ + /* */ + typedef struct FTC_ScalerRec_ + { + FTC_FaceID face_id; + FT_UInt width; + FT_UInt height; + FT_Int pixel; + FT_UInt x_res; + FT_UInt y_res; + + } FTC_ScalerRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_Scaler */ + /* */ + /* <Description> */ + /* A handle to an @FTC_ScalerRec structure. */ + /* */ + typedef struct FTC_ScalerRec_* FTC_Scaler; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_LookupSize */ + /* */ + /* <Description> */ + /* Retrieve the @FT_Size object that corresponds to a given */ + /* @FTC_ScalerRec pointer through a cache manager. */ + /* */ + /* <Input> */ + /* manager :: A handle to the cache manager. */ + /* */ + /* scaler :: A scaler handle. */ + /* */ + /* <Output> */ + /* asize :: A handle to the size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned @FT_Size object is always owned by the manager. You */ + /* should never try to discard it by yourself. */ + /* */ + /* You can access the parent @FT_Face object simply as `size->face' */ + /* if you need it. Note that this object is also owned by the */ + /* manager. */ + /* */ + /* <Note> */ + /* When you perform a lookup, out-of-memory errors are detected */ + /* _within_ the lookup and force incremental flushes of the cache */ + /* until enough memory is released for the lookup to succeed. */ + /* */ + /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */ + /* already been completely flushed, and still no memory is available */ + /* for the operation. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Manager_LookupSize( FTC_Manager manager, + FTC_Scaler scaler, + FT_Size *asize ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Node_Unref */ + /* */ + /* <Description> */ + /* Decrement a cache node's internal reference count. When the count */ + /* reaches 0, it is not destroyed but becomes eligible for subsequent */ + /* cache flushes. */ + /* */ + /* <Input> */ + /* node :: The cache node handle. */ + /* */ + /* manager :: The cache manager handle. */ + /* */ + FT_EXPORT( void ) + FTC_Node_Unref( FTC_Node node, + FTC_Manager manager ); + + + /************************************************************************* + * + * @function: + * FTC_Manager_RemoveFaceID + * + * @description: + * A special function used to indicate to the cache manager that + * a given @FTC_FaceID is no longer valid, either because its + * content changed, or because it was deallocated or uninstalled. + * + * @input: + * manager :: + * The cache manager handle. + * + * face_id :: + * The @FTC_FaceID to be removed. + * + * @note: + * This function flushes all nodes from the cache corresponding to this + * `face_id', with the exception of nodes with a non-null reference + * count. + * + * Such nodes are however modified internally so as to never appear + * in later lookups with the same `face_id' value, and to be immediately + * destroyed when released by all their users. + * + */ + FT_EXPORT( void ) + FTC_Manager_RemoveFaceID( FTC_Manager manager, + FTC_FaceID face_id ); + + + /************************************************************************* + * + * @type: + * FTC_CMapCache + * + * @description: + * An opaque handle used to model a charmap cache. This cache is to + * hold character codes -> glyph indices mappings. + * + */ + typedef struct FTC_CMapCacheRec_* FTC_CMapCache; + + + /************************************************************************* + * + * @function: + * FTC_CMapCache_New + * + * @description: + * Create a new charmap cache. + * + * @input: + * manager :: + * A handle to the cache manager. + * + * @output: + * acache :: + * A new cache handle. NULL in case of error. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Like all other caches, this one will be destroyed with the cache + * manager. + * + */ + FT_EXPORT( FT_Error ) + FTC_CMapCache_New( FTC_Manager manager, + FTC_CMapCache *acache ); + + + /************************************************************************ + * + * @function: + * FTC_CMapCache_Lookup + * + * @description: + * Translate a character code into a glyph index, using the charmap + * cache. + * + * @input: + * cache :: + * A charmap cache handle. + * + * face_id :: + * The source face ID. + * + * cmap_index :: + * The index of the charmap in the source face. Any negative value + * means to use the cache @FT_Face's default charmap. + * + * char_code :: + * The character code (in the corresponding charmap). + * + * @return: + * Glyph index. 0~means `no glyph'. + * + */ + FT_EXPORT( FT_UInt ) + FTC_CMapCache_Lookup( FTC_CMapCache cache, + FTC_FaceID face_id, + FT_Int cmap_index, + FT_UInt32 char_code ); + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** IMAGE CACHE OBJECT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************* + * + * @struct: + * FTC_ImageTypeRec + * + * @description: + * A structure used to model the type of images in a glyph cache. + * + * @fields: + * face_id :: + * The face ID. + * + * width :: + * The width in pixels. + * + * height :: + * The height in pixels. + * + * flags :: + * The load flags, as in @FT_Load_Glyph. + * + */ + typedef struct FTC_ImageTypeRec_ + { + FTC_FaceID face_id; + FT_UInt width; + FT_UInt height; + FT_Int32 flags; + + } FTC_ImageTypeRec; + + + /************************************************************************* + * + * @type: + * FTC_ImageType + * + * @description: + * A handle to an @FTC_ImageTypeRec structure. + * + */ + typedef struct FTC_ImageTypeRec_* FTC_ImageType; + + + /* */ + + +#define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \ + ( (d1)->face_id == (d2)->face_id && \ + (d1)->width == (d2)->width && \ + (d1)->flags == (d2)->flags ) + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_ImageCache */ + /* */ + /* <Description> */ + /* A handle to a glyph image cache object. They are designed to */ + /* hold many distinct glyph images while not exceeding a certain */ + /* memory threshold. */ + /* */ + typedef struct FTC_ImageCacheRec_* FTC_ImageCache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_New */ + /* */ + /* <Description> */ + /* Create a new glyph image cache. */ + /* */ + /* <Input> */ + /* manager :: The parent manager for the image cache. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new glyph image cache object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_New( FTC_Manager manager, + FTC_ImageCache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_Lookup */ + /* */ + /* <Description> */ + /* Retrieve a given glyph image from a glyph image cache. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* type :: A pointer to a glyph image type descriptor. */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* <Output> */ + /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */ + /* failure. */ + /* */ + /* anode :: Used to return the address of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the glyph image, after increasing its reference */ + /* count. This ensures that the node (as well as the @FT_Glyph) will */ + /* always be kept in the cache until you call @FTC_Node_Unref to */ + /* `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the @FT_Glyph could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_Lookup( FTC_ImageCache cache, + FTC_ImageType type, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_LookupScaler */ + /* */ + /* <Description> */ + /* A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec */ + /* to specify the face ID and its size. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* scaler :: A pointer to a scaler descriptor. */ + /* */ + /* load_flags :: The corresponding load flags. */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* <Output> */ + /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */ + /* failure. */ + /* */ + /* anode :: Used to return the address of the corresponding */ + /* cache node after incrementing its reference count */ + /* (see note below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the glyph image, after increasing its reference */ + /* count. This ensures that the node (as well as the @FT_Glyph) will */ + /* always be kept in the cache until you call @FTC_Node_Unref to */ + /* `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the @FT_Glyph could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + /* Calls to @FT_Set_Char_Size and friends have no effect on cached */ + /* glyphs; you should always use the FreeType cache API instead. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_LookupScaler( FTC_ImageCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ); + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBit */ + /* */ + /* <Description> */ + /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */ + /* structure for details. */ + /* */ + typedef struct FTC_SBitRec_* FTC_SBit; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_SBitRec */ + /* */ + /* <Description> */ + /* A very compact structure used to describe a small glyph bitmap. */ + /* */ + /* <Fields> */ + /* width :: The bitmap width in pixels. */ + /* */ + /* height :: The bitmap height in pixels. */ + /* */ + /* left :: The horizontal distance from the pen position to the */ + /* left bitmap border (a.k.a. `left side bearing', or */ + /* `lsb'). */ + /* */ + /* top :: The vertical distance from the pen position (on the */ + /* baseline) to the upper bitmap border (a.k.a. `top */ + /* side bearing'). The distance is positive for upwards */ + /* y~coordinates. */ + /* */ + /* format :: The format of the glyph bitmap (monochrome or gray). */ + /* */ + /* max_grays :: Maximum gray level value (in the range 1 to~255). */ + /* */ + /* pitch :: The number of bytes per bitmap line. May be positive */ + /* or negative. */ + /* */ + /* xadvance :: The horizontal advance width in pixels. */ + /* */ + /* yadvance :: The vertical advance height in pixels. */ + /* */ + /* buffer :: A pointer to the bitmap pixels. */ + /* */ + typedef struct FTC_SBitRec_ + { + FT_Byte width; + FT_Byte height; + FT_Char left; + FT_Char top; + + FT_Byte format; + FT_Byte max_grays; + FT_Short pitch; + FT_Char xadvance; + FT_Char yadvance; + + FT_Byte* buffer; + + } FTC_SBitRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBitCache */ + /* */ + /* <Description> */ + /* A handle to a small bitmap cache. These are special cache objects */ + /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */ + /* much more efficient way than the traditional glyph image cache */ + /* implemented by @FTC_ImageCache. */ + /* */ + typedef struct FTC_SBitCacheRec_* FTC_SBitCache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_New */ + /* */ + /* <Description> */ + /* Create a new cache to store small glyph bitmaps. */ + /* */ + /* <Input> */ + /* manager :: A handle to the source cache manager. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new sbit cache. NULL in case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_New( FTC_Manager manager, + FTC_SBitCache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_Lookup */ + /* */ + /* <Description> */ + /* Look up a given small glyph bitmap in a given sbit cache and */ + /* `lock' it to prevent its flushing from the cache until needed. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* type :: A pointer to the glyph image type descriptor. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* <Output> */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* anode :: Used to return the address of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to~0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the bitmap, after increasing its reference count. */ + /* This ensures that the node (as well as the image) will always be */ + /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the bitmap could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_Lookup( FTC_SBitCache cache, + FTC_ImageType type, + FT_UInt gindex, + FTC_SBit *sbit, + FTC_Node *anode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_LookupScaler */ + /* */ + /* <Description> */ + /* A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec */ + /* to specify the face ID and its size. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* scaler :: A pointer to the scaler descriptor. */ + /* */ + /* load_flags :: The corresponding load flags. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* <Output> */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* anode :: Used to return the address of the corresponding */ + /* cache node after incrementing its reference count */ + /* (see note below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to~0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the bitmap, after increasing its reference count. */ + /* This ensures that the node (as well as the image) will always be */ + /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the bitmap could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_LookupScaler( FTC_SBitCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FTC_SBit *sbit, + FTC_Node *anode ); + + /* */ + + +FT_END_HEADER + +#endif /* FTCACHE_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftchapters.h b/freetype/include/freetype2/freetype/ftchapters.h new file mode 100644 index 0000000..51257bb --- /dev/null +++ b/freetype/include/freetype2/freetype/ftchapters.h @@ -0,0 +1,139 @@ +/***************************************************************************/ +/* */ +/* This file defines the structure of the FreeType reference. */ +/* It is used by the python script that generates the HTML files. */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* general_remarks */ +/* */ +/* <Title> */ +/* General Remarks */ +/* */ +/* <Sections> */ +/* header_inclusion */ +/* user_allocation */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* core_api */ +/* */ +/* <Title> */ +/* Core API */ +/* */ +/* <Sections> */ +/* version */ +/* basic_types */ +/* base_interface */ +/* glyph_variants */ +/* glyph_management */ +/* mac_specific */ +/* sizes_management */ +/* header_file_macros */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* format_specific */ +/* */ +/* <Title> */ +/* Format-Specific API */ +/* */ +/* <Sections> */ +/* multiple_masters */ +/* truetype_tables */ +/* type1_tables */ +/* sfnt_names */ +/* bdf_fonts */ +/* cid_fonts */ +/* pfr_fonts */ +/* winfnt_fonts */ +/* font_formats */ +/* gasp_table */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* module_specific */ +/* */ +/* <Title> */ +/* Controlling FreeType Modules */ +/* */ +/* <Sections> */ +/* auto_hinter */ +/* cff_driver */ +/* t1_cid_driver */ +/* tt_driver */ +/* pcf_driver */ +/* properties */ +/* parameter_tags */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* cache_subsystem */ +/* */ +/* <Title> */ +/* Cache Sub-System */ +/* */ +/* <Sections> */ +/* cache_subsystem */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* support_api */ +/* */ +/* <Title> */ +/* Support API */ +/* */ +/* <Sections> */ +/* computations */ +/* list_processing */ +/* outline_processing */ +/* quick_advance */ +/* bitmap_handling */ +/* raster */ +/* glyph_stroker */ +/* system_interface */ +/* module_management */ +/* gzip */ +/* lzw */ +/* bzip2 */ +/* lcd_filtering */ +/* */ +/***************************************************************************/ + +/***************************************************************************/ +/* */ +/* <Chapter> */ +/* error_codes */ +/* */ +/* <Title> */ +/* Error Codes */ +/* */ +/* <Sections> */ +/* error_enumerations */ +/* error_code_values */ +/* */ +/***************************************************************************/ diff --git a/freetype/include/freetype2/freetype/ftcid.h b/freetype/include/freetype2/freetype/ftcid.h new file mode 100644 index 0000000..5e9100a --- /dev/null +++ b/freetype/include/freetype2/freetype/ftcid.h @@ -0,0 +1,168 @@ +/***************************************************************************/ +/* */ +/* ftcid.h */ +/* */ +/* FreeType API for accessing CID font information (specification). */ +/* */ +/* Copyright 2007-2018 by */ +/* Dereg Clegg and Michael Toftdal. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTCID_H_ +#define FTCID_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cid_fonts */ + /* */ + /* <Title> */ + /* CID Fonts */ + /* */ + /* <Abstract> */ + /* CID-keyed font specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of CID-keyed font specific */ + /* functions. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @function: + * FT_Get_CID_Registry_Ordering_Supplement + * + * @description: + * Retrieve the Registry/Ordering/Supplement triple (also known as the + * "R/O/S") from a CID-keyed font. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * registry :: + * The registry, as a C~string, owned by the face. + * + * ordering :: + * The ordering, as a C~string, owned by the face. + * + * supplement :: + * The supplement. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces, returning an error + * otherwise. + * + * @since: + * 2.3.6 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_Registry_Ordering_Supplement( FT_Face face, + const char* *registry, + const char* *ordering, + FT_Int *supplement ); + + + /********************************************************************** + * + * @function: + * FT_Get_CID_Is_Internally_CID_Keyed + * + * @description: + * Retrieve the type of the input face, CID keyed or not. In + * contrast to the @FT_IS_CID_KEYED macro this function returns + * successfully also for CID-keyed fonts in an SFNT wrapper. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * is_cid :: + * The type of the face as an @FT_Bool. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces and OpenType fonts, + * returning an error otherwise. + * + * @since: + * 2.3.9 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face, + FT_Bool *is_cid ); + + + /********************************************************************** + * + * @function: + * FT_Get_CID_From_Glyph_Index + * + * @description: + * Retrieve the CID of the input glyph index. + * + * @input: + * face :: + * A handle to the input face. + * + * glyph_index :: + * The input glyph index. + * + * @output: + * cid :: + * The CID as an @FT_UInt. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with CID faces and OpenType fonts, + * returning an error otherwise. + * + * @since: + * 2.3.9 + */ + FT_EXPORT( FT_Error ) + FT_Get_CID_From_Glyph_Index( FT_Face face, + FT_UInt glyph_index, + FT_UInt *cid ); + + /* */ + + +FT_END_HEADER + +#endif /* FTCID_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftdriver.h b/freetype/include/freetype2/freetype/ftdriver.h new file mode 100644 index 0000000..e90475b --- /dev/null +++ b/freetype/include/freetype2/freetype/ftdriver.h @@ -0,0 +1,1225 @@ +/***************************************************************************/ +/* */ +/* ftdriver.h */ +/* */ +/* FreeType API for controlling driver modules (specification only). */ +/* */ +/* Copyright 2017-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTDRIVER_H_ +#define FTDRIVER_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H +#include FT_PARAMETER_TAGS_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * auto_hinter + * + * @title: + * The auto-hinter + * + * @abstract: + * Controlling the auto-hinting module. + * + * @description: + * While FreeType's auto-hinter doesn't expose API functions by itself, + * it is possible to control its behaviour with @FT_Property_Set and + * @FT_Property_Get. The following lists the available properties + * together with the necessary macros and structures. + * + * Note that the auto-hinter's module name is `autofitter' for + * historical reasons. + * + * Available properties are @increase-x-height, @no-stem-darkening + * (experimental), @darkening-parameters (experimental), @warping + * (experimental), @glyph-to-script-map (experimental), @fallback-script + * (experimental), and @default-script (experimental), as documented in + * the @properties section. + * + */ + + + /************************************************************************** + * + * @section: + * cff_driver + * + * @title: + * The CFF driver + * + * @abstract: + * Controlling the CFF driver module. + * + * @description: + * While FreeType's CFF driver doesn't expose API functions by itself, + * it is possible to control its behaviour with @FT_Property_Set and + * @FT_Property_Get. + * + * The CFF driver's module name is `cff'. + * + * Available properties are @hinting-engine, @no-stem-darkening, + * @darkening-parameters, and @random-seed, as documented in the + * @properties section. + * + * + * *Hinting* *and* *antialiasing* *principles* *of* *the* *new* *engine* + * + * The rasterizer is positioning horizontal features (e.g., ascender + * height & x-height, or crossbars) on the pixel grid and minimizing the + * amount of antialiasing applied to them, while placing vertical + * features (vertical stems) on the pixel grid without hinting, thus + * representing the stem position and weight accurately. Sometimes the + * vertical stems may be only partially black. In this context, + * `antialiasing' means that stems are not positioned exactly on pixel + * borders, causing a fuzzy appearance. + * + * There are two principles behind this approach. + * + * 1) No hinting in the horizontal direction: Unlike `superhinted' + * TrueType, which changes glyph widths to accommodate regular + * inter-glyph spacing, Adobe's approach is `faithful to the design' in + * representing both the glyph width and the inter-glyph spacing + * designed for the font. This makes the screen display as close as it + * can be to the result one would get with infinite resolution, while + * preserving what is considered the key characteristics of each glyph. + * Note that the distances between unhinted and grid-fitted positions at + * small sizes are comparable to kerning values and thus would be + * noticeable (and distracting) while reading if hinting were applied. + * + * One of the reasons to not hint horizontally is antialiasing for LCD + * screens: The pixel geometry of modern displays supplies three + * vertical subpixels as the eye moves horizontally across each visible + * pixel. On devices where we can be certain this characteristic is + * present a rasterizer can take advantage of the subpixels to add + * increments of weight. In Western writing systems this turns out to + * be the more critical direction anyway; the weights and spacing of + * vertical stems (see above) are central to Armenian, Cyrillic, Greek, + * and Latin type designs. Even when the rasterizer uses greyscale + * antialiasing instead of color (a necessary compromise when one + * doesn't know the screen characteristics), the unhinted vertical + * features preserve the design's weight and spacing much better than + * aliased type would. + * + * 2) Alignment in the vertical direction: Weights and spacing along the + * y~axis are less critical; what is much more important is the visual + * alignment of related features (like cap-height and x-height). The + * sense of alignment for these is enhanced by the sharpness of grid-fit + * edges, while the cruder vertical resolution (full pixels instead of + * 1/3 pixels) is less of a problem. + * + * On the technical side, horizontal alignment zones for ascender, + * x-height, and other important height values (traditionally called + * `blue zones') as defined in the font are positioned independently, + * each being rounded to the nearest pixel edge, taking care of + * overshoot suppression at small sizes, stem darkening, and scaling. + * + * Hstems (this is, hint values defined in the font to help align + * horizontal features) that fall within a blue zone are said to be + * `captured' and are aligned to that zone. Uncaptured stems are moved + * in one of four ways, top edge up or down, bottom edge up or down. + * Unless there are conflicting hstems, the smallest movement is taken + * to minimize distortion. + * + */ + + + /************************************************************************** + * + * @section: + * pcf_driver + * + * @title: + * The PCF driver + * + * @abstract: + * Controlling the PCF driver module. + * + * @description: + * While FreeType's PCF driver doesn't expose API functions by itself, + * it is possible to control its behaviour with @FT_Property_Set and + * @FT_Property_Get. Right now, there is a single property + * @no-long-family-names available if FreeType is compiled with + * PCF_CONFIG_OPTION_LONG_FAMILY_NAMES. + * + * The PCF driver's module name is `pcf'. + * + */ + + + /************************************************************************** + * + * @section: + * t1_cid_driver + * + * @title: + * The Type 1 and CID drivers + * + * @abstract: + * Controlling the Type~1 and CID driver modules. + * + * @description: + * It is possible to control the behaviour of FreeType's Type~1 and + * Type~1 CID drivers with @FT_Property_Set and @FT_Property_Get. + * + * Behind the scenes, both drivers use the Adobe CFF engine for hinting; + * however, the used properties must be specified separately. + * + * The Type~1 driver's module name is `type1'; the CID driver's module + * name is `t1cid'. + * + * Available properties are @hinting-engine, @no-stem-darkening, + * @darkening-parameters, and @random-seed, as documented in the + * @properties section. + * + * Please see the @cff_driver section for more details on the new + * hinting engine. + * + */ + + + /************************************************************************** + * + * @section: + * tt_driver + * + * @title: + * The TrueType driver + * + * @abstract: + * Controlling the TrueType driver module. + * + * @description: + * While FreeType's TrueType driver doesn't expose API functions by + * itself, it is possible to control its behaviour with @FT_Property_Set + * and @FT_Property_Get. The following lists the available properties + * together with the necessary macros and structures. + * + * The TrueType driver's module name is `truetype'. + * + * A single property @interpreter-version is available, as documented in + * the @properties section. + * + * We start with a list of definitions, kindly provided by Greg + * Hitchcock. + * + * _Bi-Level_ _Rendering_ + * + * Monochromatic rendering, exclusively used in the early days of + * TrueType by both Apple and Microsoft. Microsoft's GDI interface + * supported hinting of the right-side bearing point, such that the + * advance width could be non-linear. Most often this was done to + * achieve some level of glyph symmetry. To enable reasonable + * performance (e.g., not having to run hinting on all glyphs just to + * get the widths) there was a bit in the head table indicating if the + * side bearing was hinted, and additional tables, `hdmx' and `LTSH', to + * cache hinting widths across multiple sizes and device aspect ratios. + * + * _Font_ _Smoothing_ + * + * Microsoft's GDI implementation of anti-aliasing. Not traditional + * anti-aliasing as the outlines were hinted before the sampling. The + * widths matched the bi-level rendering. + * + * _ClearType_ _Rendering_ + * + * Technique that uses physical subpixels to improve rendering on LCD + * (and other) displays. Because of the higher resolution, many methods + * of improving symmetry in glyphs through hinting the right-side + * bearing were no longer necessary. This lead to what GDI calls + * `natural widths' ClearType, see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec21. Since hinting + * has extra resolution, most non-linearity went away, but it is still + * possible for hints to change the advance widths in this mode. + * + * _ClearType_ _Compatible_ _Widths_ + * + * One of the earliest challenges with ClearType was allowing the + * implementation in GDI to be selected without requiring all UI and + * documents to reflow. To address this, a compatible method of + * rendering ClearType was added where the font hints are executed once + * to determine the width in bi-level rendering, and then re-run in + * ClearType, with the difference in widths being absorbed in the font + * hints for ClearType (mostly in the white space of hints); see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec20. Somewhat by + * definition, compatible width ClearType allows for non-linear widths, + * but only when the bi-level version has non-linear widths. + * + * _ClearType_ _Subpixel_ _Positioning_ + * + * One of the nice benefits of ClearType is the ability to more crisply + * display fractional widths; unfortunately, the GDI model of integer + * bitmaps did not support this. However, the WPF and Direct Write + * frameworks do support fractional widths. DWrite calls this `natural + * mode', not to be confused with GDI's `natural widths'. Subpixel + * positioning, in the current implementation of Direct Write, + * unfortunately does not support hinted advance widths, see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec22. Note that the + * TrueType interpreter fully allows the advance width to be adjusted in + * this mode, just the DWrite client will ignore those changes. + * + * _ClearType_ _Backward_ _Compatibility_ + * + * This is a set of exceptions made in the TrueType interpreter to + * minimize hinting techniques that were problematic with the extra + * resolution of ClearType; see + * http://www.beatstamm.com/typography/RTRCh4.htm#Sec1 and + * https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx. + * This technique is not to be confused with ClearType compatible + * widths. ClearType backward compatibility has no direct impact on + * changing advance widths, but there might be an indirect impact on + * disabling some deltas. This could be worked around in backward + * compatibility mode. + * + * _Native_ _ClearType_ _Mode_ + * + * (Not to be confused with `natural widths'.) This mode removes all + * the exceptions in the TrueType interpreter when running with + * ClearType. Any issues on widths would still apply, though. + * + */ + + + /************************************************************************** + * + * @section: + * properties + * + * @title: + * Driver properties + * + * @abstract: + * Controlling driver modules. + * + * @description: + * Driver modules can be controlled by setting and unsetting properties, + * using the functions @FT_Property_Set and @FT_Property_Get. This + * section documents the available properties, together with auxiliary + * macros and structures. + * + */ + + + /************************************************************************** + * + * @enum: + * FT_HINTING_XXX + * + * @description: + * A list of constants used for the @hinting-engine property to + * select the hinting engine for CFF, Type~1, and CID fonts. + * + * @values: + * FT_HINTING_FREETYPE :: + * Use the old FreeType hinting engine. + * + * FT_HINTING_ADOBE :: + * Use the hinting engine contributed by Adobe. + * + * @since: + * 2.9 + * + */ +#define FT_HINTING_FREETYPE 0 +#define FT_HINTING_ADOBE 1 + + /* these constants (introduced in 2.4.12) are deprecated */ +#define FT_CFF_HINTING_FREETYPE FT_HINTING_FREETYPE +#define FT_CFF_HINTING_ADOBE FT_HINTING_ADOBE + + + /************************************************************************** + * + * @property: + * hinting-engine + * + * @description: + * Thanks to Adobe, which contributed a new hinting (and parsing) + * engine, an application can select between `freetype' and `adobe' if + * compiled with CFF_CONFIG_OPTION_OLD_ENGINE. If this configuration + * macro isn't defined, `hinting-engine' does nothing. + * + * The same holds for the Type~1 and CID modules if compiled with + * T1_CONFIG_OPTION_OLD_ENGINE. + * + * For the `cff' module, the default engine is `freetype' if + * CFF_CONFIG_OPTION_OLD_ENGINE is defined, and `adobe' otherwise. + * + * For both the `type1' and `t1cid' modules, the default engine is + * `freetype' if T1_CONFIG_OPTION_OLD_ENGINE is defined, and `adobe' + * otherwise. + * + * The following example code demonstrates how to select Adobe's hinting + * engine for the `cff' module (omitting the error handling). + * + * { + * FT_Library library; + * FT_UInt hinting_engine = FT_CFF_HINTING_ADOBE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "cff", + * "hinting-engine", &hinting_engine ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable (using values `adobe' or `freetype'). + * + * @since: + * 2.4.12 (for `cff' module) + * + * 2.9 (for `type1' and `t1cid' modules) + * + */ + + + /************************************************************************** + * + * @property: + * no-stem-darkening + * + * @description: + * All glyphs that pass through the auto-hinter will be emboldened + * unless this property is set to TRUE. The same is true for the CFF, + * Type~1, and CID font modules if the `Adobe' engine is selected (which + * is the default). + * + * Stem darkening emboldens glyphs at smaller sizes to make them more + * readable on common low-DPI screens when using linear alpha blending + * and gamma correction, see @FT_Render_Glyph. When not using linear + * alpha blending and gamma correction, glyphs will appear heavy and + * fuzzy! + * + * Gamma correction essentially lightens fonts since shades of grey are + * shifted to higher pixel values (=~higher brightness) to match the + * original intention to the reality of our screens. The side-effect is + * that glyphs `thin out'. Mac OS~X and Adobe's proprietary font + * rendering library implement a counter-measure: stem darkening at + * smaller sizes where shades of gray dominate. By emboldening a glyph + * slightly in relation to its pixel size, individual pixels get higher + * coverage of filled-in outlines and are therefore `blacker'. This + * counteracts the `thinning out' of glyphs, making text remain readable + * at smaller sizes. + * + * By default, the Adobe engines for CFF, Type~1, and CID fonts darken + * stems at smaller sizes, regardless of hinting, to enhance contrast. + * Setting this property, stem darkening gets switched off. + * + * For the auto-hinter, stem-darkening is experimental currently and + * thus switched off by default (this is, `no-stem-darkening' is set to + * TRUE by default). Total consistency with the CFF driver is not + * achieved right now because the emboldening method differs and glyphs + * must be scaled down on the Y-axis to keep outline points inside their + * precomputed blue zones. The smaller the size (especially 9ppem and + * down), the higher the loss of emboldening versus the CFF driver. + * + * Note that stem darkening is never applied if @FT_LOAD_NO_SCALE is + * set. + * + * { + * FT_Library library; + * FT_Bool no_stem_darkening = TRUE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "cff", + * "no-stem-darkening", &no_stem_darkening ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable (using values 1 and 0 for `on' and `off', respectively). + * It can also be set per face using @FT_Face_Properties with + * @FT_PARAM_TAG_STEM_DARKENING. + * + * @since: + * 2.4.12 (for `cff' module) + * + * 2.6.2 (for `autofitter' module) + * + * 2.9 (for `type1' and `t1cid' modules) + * + */ + + + /************************************************************************** + * + * @property: + * darkening-parameters + * + * @description: + * By default, the Adobe hinting engine, as used by the CFF, Type~1, and + * CID font drivers, darkens stems as follows (if the + * `no-stem-darkening' property isn't set): + * + * { + * stem width <= 0.5px: darkening amount = 0.4px + * stem width = 1px: darkening amount = 0.275px + * stem width = 1.667px: darkening amount = 0.275px + * stem width >= 2.333px: darkening amount = 0px + * } + * + * and piecewise linear in-between. At configuration time, these four + * control points can be set with the macro + * `CFF_CONFIG_OPTION_DARKENING_PARAMETERS'; the CFF, Type~1, and CID + * drivers share these values. At runtime, the control points can be + * changed using the `darkening-parameters' property, as the following + * example demonstrates for the Type~1 driver. + * + * { + * FT_Library library; + * FT_Int darken_params[8] = { 500, 300, // x1, y1 + * 1000, 200, // x2, y2 + * 1500, 100, // x3, y3 + * 2000, 0 }; // x4, y4 + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "type1", + * "darkening-parameters", darken_params ); + * } + * + * The x~values give the stem width, and the y~values the darkening + * amount. The unit is 1000th of pixels. All coordinate values must be + * positive; the x~values must be monotonically increasing; the + * y~values must be monotonically decreasing and smaller than or + * equal to 500 (corresponding to half a pixel); the slope of each + * linear piece must be shallower than -1 (e.g., -.4). + * + * The auto-hinter provides this property, too, as an experimental + * feature. See @no-stem-darkening for more. + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable, using eight comma-separated integers without spaces. Here + * the above example, using `\' to break the line for readability. + * + * { + * FREETYPE_PROPERTIES=\ + * type1:darkening-parameters=500,300,1000,200,1500,100,2000,0 + * } + * + * @since: + * 2.5.1 (for `cff' module) + * + * 2.6.2 (for `autofitter' module) + * + * 2.9 (for `type1' and `t1cid' modules) + * + */ + + + /************************************************************************** + * + * @property: + * random-seed + * + * @description: + * By default, the seed value for the CFF `random' operator and the + * similar `0 28 callothersubr pop' command for the Type~1 and CID + * drivers is set to a random value. However, mainly for debugging + * purposes, it is often necessary to use a known value as a seed so + * that the pseudo-random number sequences generated by `random' are + * repeatable. + * + * The `random-seed' property does that. Its argument is a signed 32bit + * integer; if the value is zero or negative, the seed given by the + * `intitialRandomSeed' private DICT operator in a CFF file gets used + * (or a default value if there is no such operator). If the value is + * positive, use it instead of `initialRandomSeed', which is + * consequently ignored. + * + * @note: + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable. It can also be set per face using @FT_Face_Properties with + * @FT_PARAM_TAG_RANDOM_SEED. + * + * @since: + * 2.8 (for `cff' module) + * + * 2.9 (for `type1' and `t1cid' modules) + * + */ + + + /************************************************************************** + * + * @property: + * no-long-family-names + * + * @description: + * If PCF_CONFIG_OPTION_LONG_FAMILY_NAMES is active while compiling + * FreeType, the PCF driver constructs long family names. + * + * There are many PCF fonts just called `Fixed' which look completely + * different, and which have nothing to do with each other. When + * selecting `Fixed' in KDE or Gnome one gets results that appear rather + * random, the style changes often if one changes the size and one + * cannot select some fonts at all. The improve this situation, the PCF + * module prepends the foundry name (plus a space) to the family name. + * It also checks whether there are `wide' characters; all put together, + * family names like `Sony Fixed' or `Misc Fixed Wide' are constructed. + * + * If `no-long-family-names' is set, this feature gets switched off. + * + * { + * FT_Library library; + * FT_Bool no_long_family_names = TRUE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "pcf", + * "no-long-family-names", + * &no_long_family_names ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable (using values 1 and 0 for `on' and `off', respectively). + * + * @since: + * 2.8 + */ + + + /************************************************************************** + * + * @enum: + * TT_INTERPRETER_VERSION_XXX + * + * @description: + * A list of constants used for the @interpreter-version property to + * select the hinting engine for Truetype fonts. + * + * The numeric value in the constant names represents the version + * number as returned by the `GETINFO' bytecode instruction. + * + * @values: + * TT_INTERPRETER_VERSION_35 :: + * Version~35 corresponds to MS rasterizer v.1.7 as used e.g. in + * Windows~98; only grayscale and B/W rasterizing is supported. + * + * TT_INTERPRETER_VERSION_38 :: + * Version~38 corresponds to MS rasterizer v.1.9; it is roughly + * equivalent to the hinting provided by DirectWrite ClearType (as can + * be found, for example, in the Internet Explorer~9 running on + * Windows~7). It is used in FreeType to select the `Infinality' + * subpixel hinting code. The code may be removed in a future + * version. + * + * TT_INTERPRETER_VERSION_40 :: + * Version~40 corresponds to MS rasterizer v.2.1; it is roughly + * equivalent to the hinting provided by DirectWrite ClearType (as can + * be found, for example, in Microsoft's Edge Browser on Windows~10). + * It is used in FreeType to select the `minimal' subpixel hinting + * code, a stripped-down and higher performance version of the + * `Infinality' code. + * + * @note: + * This property controls the behaviour of the bytecode interpreter + * and thus how outlines get hinted. It does *not* control how glyph + * get rasterized! In particular, it does not control subpixel color + * filtering. + * + * If FreeType has not been compiled with the configuration option + * TT_CONFIG_OPTION_SUBPIXEL_HINTING, selecting version~38 or~40 causes + * an `FT_Err_Unimplemented_Feature' error. + * + * Depending on the graphics framework, Microsoft uses different + * bytecode and rendering engines. As a consequence, the version + * numbers returned by a call to the `GETINFO' bytecode instruction are + * more convoluted than desired. + * + * Here are two tables that try to shed some light on the possible + * values for the MS rasterizer engine, together with the additional + * features introduced by it. + * + * { + * GETINFO framework version feature + * ------------------------------------------------------------------- + * 3 GDI (Win 3.1), v1.0 16-bit, first version + * TrueImage + * 33 GDI (Win NT 3.1), v1.5 32-bit + * HP Laserjet + * 34 GDI (Win 95) v1.6 font smoothing, + * new SCANTYPE opcode + * 35 GDI (Win 98/2000) v1.7 (UN)SCALED_COMPONENT_OFFSET + * bits in composite glyphs + * 36 MGDI (Win CE 2) v1.6+ classic ClearType + * 37 GDI (XP and later), v1.8 ClearType + * GDI+ old (before Vista) + * 38 GDI+ old (Vista, Win 7), v1.9 subpixel ClearType, + * WPF Y-direction ClearType, + * additional error checking + * 39 DWrite (before Win 8) v2.0 subpixel ClearType flags + * in GETINFO opcode, + * bug fixes + * 40 GDI+ (after Win 7), v2.1 Y-direction ClearType flag + * DWrite (Win 8) in GETINFO opcode, + * Gray ClearType + * } + * + * The `version' field gives a rough orientation only, since some + * applications provided certain features much earlier (as an example, + * Microsoft Reader used subpixel and Y-direction ClearType already in + * Windows 2000). Similarly, updates to a given framework might include + * improved hinting support. + * + * { + * version sampling rendering comment + * x y x y + * -------------------------------------------------------------- + * v1.0 normal normal B/W B/W bi-level + * v1.6 high high gray gray grayscale + * v1.8 high normal color-filter B/W (GDI) ClearType + * v1.9 high high color-filter gray Color ClearType + * v2.1 high normal gray B/W Gray ClearType + * v2.1 high high gray gray Gray ClearType + * } + * + * Color and Gray ClearType are the two available variants of + * `Y-direction ClearType', meaning grayscale rasterization along the + * Y-direction; the name used in the TrueType specification for this + * feature is `symmetric smoothing'. `Classic ClearType' is the + * original algorithm used before introducing a modified version in + * Win~XP. Another name for v1.6's grayscale rendering is `font + * smoothing', and `Color ClearType' is sometimes also called `DWrite + * ClearType'. To differentiate between today's Color ClearType and the + * earlier ClearType variant with B/W rendering along the vertical axis, + * the latter is sometimes called `GDI ClearType'. + * + * `Normal' and `high' sampling describe the (virtual) resolution to + * access the rasterized outline after the hinting process. `Normal' + * means 1 sample per grid line (i.e., B/W). In the current Microsoft + * implementation, `high' means an extra virtual resolution of 16x16 (or + * 16x1) grid lines per pixel for bytecode instructions like `MIRP'. + * After hinting, these 16 grid lines are mapped to 6x5 (or 6x1) grid + * lines for color filtering if Color ClearType is activated. + * + * Note that `Gray ClearType' is essentially the same as v1.6's + * grayscale rendering. However, the GETINFO instruction handles it + * differently: v1.6 returns bit~12 (hinting for grayscale), while v2.1 + * returns bits~13 (hinting for ClearType), 18 (symmetrical smoothing), + * and~19 (Gray ClearType). Also, this mode respects bits 2 and~3 for + * the version~1 gasp table exclusively (like Color ClearType), while + * v1.6 only respects the values of version~0 (bits 0 and~1). + * + * Keep in mind that the features of the above interpreter versions + * might not map exactly to FreeType features or behavior because it is + * a fundamentally different library with different internals. + * + */ +#define TT_INTERPRETER_VERSION_35 35 +#define TT_INTERPRETER_VERSION_38 38 +#define TT_INTERPRETER_VERSION_40 40 + + + /************************************************************************** + * + * @property: + * interpreter-version + * + * @description: + * Currently, three versions are available, two representing the + * bytecode interpreter with subpixel hinting support (old `Infinality' + * code and new stripped-down and higher performance `minimal' code) and + * one without, respectively. The default is subpixel support if + * TT_CONFIG_OPTION_SUBPIXEL_HINTING is defined, and no subpixel support + * otherwise (since it isn't available then). + * + * If subpixel hinting is on, many TrueType bytecode instructions behave + * differently compared to B/W or grayscale rendering (except if `native + * ClearType' is selected by the font). Microsoft's main idea is to + * render at a much increased horizontal resolution, then sampling down + * the created output to subpixel precision. However, many older fonts + * are not suited to this and must be specially taken care of by + * applying (hardcoded) tweaks in Microsoft's interpreter. + * + * Details on subpixel hinting and some of the necessary tweaks can be + * found in Greg Hitchcock's whitepaper at + * `https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx'. + * Note that FreeType currently doesn't really `subpixel hint' (6x1, 6x2, + * or 6x5 supersampling) like discussed in the paper. Depending on the + * chosen interpreter, it simply ignores instructions on vertical stems + * to arrive at very similar results. + * + * The following example code demonstrates how to deactivate subpixel + * hinting (omitting the error handling). + * + * { + * FT_Library library; + * FT_Face face; + * FT_UInt interpreter_version = TT_INTERPRETER_VERSION_35; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "truetype", + * "interpreter-version", + * &interpreter_version ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable (using values `35', `38', or `40'). + * + * @since: + * 2.5 + */ + + + /************************************************************************** + * + * @property: + * glyph-to-script-map + * + * @description: + * *Experimental* *only* + * + * The auto-hinter provides various script modules to hint glyphs. + * Examples of supported scripts are Latin or CJK. Before a glyph is + * auto-hinted, the Unicode character map of the font gets examined, and + * the script is then determined based on Unicode character ranges, see + * below. + * + * OpenType fonts, however, often provide much more glyphs than + * character codes (small caps, superscripts, ligatures, swashes, etc.), + * to be controlled by so-called `features'. Handling OpenType features + * can be quite complicated and thus needs a separate library on top of + * FreeType. + * + * The mapping between glyph indices and scripts (in the auto-hinter + * sense, see the @FT_AUTOHINTER_SCRIPT_XXX values) is stored as an + * array with `num_glyphs' elements, as found in the font's @FT_Face + * structure. The `glyph-to-script-map' property returns a pointer to + * this array, which can be modified as needed. Note that the + * modification should happen before the first glyph gets processed by + * the auto-hinter so that the global analysis of the font shapes + * actually uses the modified mapping. + * + * The following example code demonstrates how to access it (omitting + * the error handling). + * + * { + * FT_Library library; + * FT_Face face; + * FT_Prop_GlyphToScriptMap prop; + * + * + * FT_Init_FreeType( &library ); + * FT_New_Face( library, "foo.ttf", 0, &face ); + * + * prop.face = face; + * + * FT_Property_Get( library, "autofitter", + * "glyph-to-script-map", &prop ); + * + * // adjust `prop.map' as needed right here + * + * FT_Load_Glyph( face, ..., FT_LOAD_FORCE_AUTOHINT ); + * } + * + * @since: + * 2.4.11 + * + */ + + + /************************************************************************** + * + * @enum: + * FT_AUTOHINTER_SCRIPT_XXX + * + * @description: + * *Experimental* *only* + * + * A list of constants used for the @glyph-to-script-map property to + * specify the script submodule the auto-hinter should use for hinting a + * particular glyph. + * + * @values: + * FT_AUTOHINTER_SCRIPT_NONE :: + * Don't auto-hint this glyph. + * + * FT_AUTOHINTER_SCRIPT_LATIN :: + * Apply the latin auto-hinter. For the auto-hinter, `latin' is a + * very broad term, including Cyrillic and Greek also since characters + * from those scripts share the same design constraints. + * + * By default, characters from the following Unicode ranges are + * assigned to this submodule. + * + * { + * U+0020 - U+007F // Basic Latin (no control characters) + * U+00A0 - U+00FF // Latin-1 Supplement (no control characters) + * U+0100 - U+017F // Latin Extended-A + * U+0180 - U+024F // Latin Extended-B + * U+0250 - U+02AF // IPA Extensions + * U+02B0 - U+02FF // Spacing Modifier Letters + * U+0300 - U+036F // Combining Diacritical Marks + * U+0370 - U+03FF // Greek and Coptic + * U+0400 - U+04FF // Cyrillic + * U+0500 - U+052F // Cyrillic Supplement + * U+1D00 - U+1D7F // Phonetic Extensions + * U+1D80 - U+1DBF // Phonetic Extensions Supplement + * U+1DC0 - U+1DFF // Combining Diacritical Marks Supplement + * U+1E00 - U+1EFF // Latin Extended Additional + * U+1F00 - U+1FFF // Greek Extended + * U+2000 - U+206F // General Punctuation + * U+2070 - U+209F // Superscripts and Subscripts + * U+20A0 - U+20CF // Currency Symbols + * U+2150 - U+218F // Number Forms + * U+2460 - U+24FF // Enclosed Alphanumerics + * U+2C60 - U+2C7F // Latin Extended-C + * U+2DE0 - U+2DFF // Cyrillic Extended-A + * U+2E00 - U+2E7F // Supplemental Punctuation + * U+A640 - U+A69F // Cyrillic Extended-B + * U+A720 - U+A7FF // Latin Extended-D + * U+FB00 - U+FB06 // Alphab. Present. Forms (Latin Ligatures) + * U+1D400 - U+1D7FF // Mathematical Alphanumeric Symbols + * U+1F100 - U+1F1FF // Enclosed Alphanumeric Supplement + * } + * + * FT_AUTOHINTER_SCRIPT_CJK :: + * Apply the CJK auto-hinter, covering Chinese, Japanese, Korean, old + * Vietnamese, and some other scripts. + * + * By default, characters from the following Unicode ranges are + * assigned to this submodule. + * + * { + * U+1100 - U+11FF // Hangul Jamo + * U+2E80 - U+2EFF // CJK Radicals Supplement + * U+2F00 - U+2FDF // Kangxi Radicals + * U+2FF0 - U+2FFF // Ideographic Description Characters + * U+3000 - U+303F // CJK Symbols and Punctuation + * U+3040 - U+309F // Hiragana + * U+30A0 - U+30FF // Katakana + * U+3100 - U+312F // Bopomofo + * U+3130 - U+318F // Hangul Compatibility Jamo + * U+3190 - U+319F // Kanbun + * U+31A0 - U+31BF // Bopomofo Extended + * U+31C0 - U+31EF // CJK Strokes + * U+31F0 - U+31FF // Katakana Phonetic Extensions + * U+3200 - U+32FF // Enclosed CJK Letters and Months + * U+3300 - U+33FF // CJK Compatibility + * U+3400 - U+4DBF // CJK Unified Ideographs Extension A + * U+4DC0 - U+4DFF // Yijing Hexagram Symbols + * U+4E00 - U+9FFF // CJK Unified Ideographs + * U+A960 - U+A97F // Hangul Jamo Extended-A + * U+AC00 - U+D7AF // Hangul Syllables + * U+D7B0 - U+D7FF // Hangul Jamo Extended-B + * U+F900 - U+FAFF // CJK Compatibility Ideographs + * U+FE10 - U+FE1F // Vertical forms + * U+FE30 - U+FE4F // CJK Compatibility Forms + * U+FF00 - U+FFEF // Halfwidth and Fullwidth Forms + * U+1B000 - U+1B0FF // Kana Supplement + * U+1D300 - U+1D35F // Tai Xuan Hing Symbols + * U+1F200 - U+1F2FF // Enclosed Ideographic Supplement + * U+20000 - U+2A6DF // CJK Unified Ideographs Extension B + * U+2A700 - U+2B73F // CJK Unified Ideographs Extension C + * U+2B740 - U+2B81F // CJK Unified Ideographs Extension D + * U+2F800 - U+2FA1F // CJK Compatibility Ideographs Supplement + * } + * + * FT_AUTOHINTER_SCRIPT_INDIC :: + * Apply the indic auto-hinter, covering all major scripts from the + * Indian sub-continent and some other related scripts like Thai, Lao, + * or Tibetan. + * + * By default, characters from the following Unicode ranges are + * assigned to this submodule. + * + * { + * U+0900 - U+0DFF // Indic Range + * U+0F00 - U+0FFF // Tibetan + * U+1900 - U+194F // Limbu + * U+1B80 - U+1BBF // Sundanese + * U+A800 - U+A82F // Syloti Nagri + * U+ABC0 - U+ABFF // Meetei Mayek + * U+11800 - U+118DF // Sharada + * } + * + * Note that currently Indic support is rudimentary only, missing blue + * zone support. + * + * @since: + * 2.4.11 + * + */ +#define FT_AUTOHINTER_SCRIPT_NONE 0 +#define FT_AUTOHINTER_SCRIPT_LATIN 1 +#define FT_AUTOHINTER_SCRIPT_CJK 2 +#define FT_AUTOHINTER_SCRIPT_INDIC 3 + + + /************************************************************************** + * + * @struct: + * FT_Prop_GlyphToScriptMap + * + * @description: + * *Experimental* *only* + * + * The data exchange structure for the @glyph-to-script-map property. + * + * @since: + * 2.4.11 + * + */ + typedef struct FT_Prop_GlyphToScriptMap_ + { + FT_Face face; + FT_UShort* map; + + } FT_Prop_GlyphToScriptMap; + + + /************************************************************************** + * + * @property: + * fallback-script + * + * @description: + * *Experimental* *only* + * + * If no auto-hinter script module can be assigned to a glyph, a + * fallback script gets assigned to it (see also the + * @glyph-to-script-map property). By default, this is + * @FT_AUTOHINTER_SCRIPT_CJK. Using the `fallback-script' property, + * this fallback value can be changed. + * + * { + * FT_Library library; + * FT_UInt fallback_script = FT_AUTOHINTER_SCRIPT_NONE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "autofitter", + * "fallback-script", &fallback_script ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * It's important to use the right timing for changing this value: The + * creation of the glyph-to-script map that eventually uses the + * fallback script value gets triggered either by setting or reading a + * face-specific property like @glyph-to-script-map, or by auto-hinting + * any glyph from that face. In particular, if you have already created + * an @FT_Face structure but not loaded any glyph (using the + * auto-hinter), a change of the fallback script will affect this face. + * + * @since: + * 2.4.11 + * + */ + + + /************************************************************************** + * + * @property: + * default-script + * + * @description: + * *Experimental* *only* + * + * If FreeType gets compiled with FT_CONFIG_OPTION_USE_HARFBUZZ to make + * the HarfBuzz library access OpenType features for getting better + * glyph coverages, this property sets the (auto-fitter) script to be + * used for the default (OpenType) script data of a font's GSUB table. + * Features for the default script are intended for all scripts not + * explicitly handled in GSUB; an example is a `dlig' feature, + * containing the combination of the characters `T', `E', and `L' to + * form a `TEL' ligature. + * + * By default, this is @FT_AUTOHINTER_SCRIPT_LATIN. Using the + * `default-script' property, this default value can be changed. + * + * { + * FT_Library library; + * FT_UInt default_script = FT_AUTOHINTER_SCRIPT_NONE; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "autofitter", + * "default-script", &default_script ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * It's important to use the right timing for changing this value: The + * creation of the glyph-to-script map that eventually uses the + * default script value gets triggered either by setting or reading a + * face-specific property like @glyph-to-script-map, or by auto-hinting + * any glyph from that face. In particular, if you have already created + * an @FT_Face structure but not loaded any glyph (using the + * auto-hinter), a change of the default script will affect this face. + * + * @since: + * 2.5.3 + * + */ + + + /************************************************************************** + * + * @property: + * increase-x-height + * + * @description: + * For ppem values in the range 6~<= ppem <= `increase-x-height', round + * up the font's x~height much more often than normally. If the value + * is set to~0, which is the default, this feature is switched off. Use + * this property to improve the legibility of small font sizes if + * necessary. + * + * { + * FT_Library library; + * FT_Face face; + * FT_Prop_IncreaseXHeight prop; + * + * + * FT_Init_FreeType( &library ); + * FT_New_Face( library, "foo.ttf", 0, &face ); + * FT_Set_Char_Size( face, 10 * 64, 0, 72, 0 ); + * + * prop.face = face; + * prop.limit = 14; + * + * FT_Property_Set( library, "autofitter", + * "increase-x-height", &prop ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * Set this value right after calling @FT_Set_Char_Size, but before + * loading any glyph (using the auto-hinter). + * + * @since: + * 2.4.11 + * + */ + + + /************************************************************************** + * + * @struct: + * FT_Prop_IncreaseXHeight + * + * @description: + * The data exchange structure for the @increase-x-height property. + * + */ + typedef struct FT_Prop_IncreaseXHeight_ + { + FT_Face face; + FT_UInt limit; + + } FT_Prop_IncreaseXHeight; + + + /************************************************************************** + * + * @property: + * warping + * + * @description: + * *Experimental* *only* + * + * If FreeType gets compiled with option AF_CONFIG_OPTION_USE_WARPER to + * activate the warp hinting code in the auto-hinter, this property + * switches warping on and off. + * + * Warping only works in `normal' auto-hinting mode replacing it. + * The idea of the code is to slightly scale and shift a glyph along + * the non-hinted dimension (which is usually the horizontal axis) so + * that as much of its segments are aligned (more or less) to the grid. + * To find out a glyph's optimal scaling and shifting value, various + * parameter combinations are tried and scored. + * + * By default, warping is off. The example below shows how to switch on + * warping (omitting the error handling). + * + * { + * FT_Library library; + * FT_Bool warping = 1; + * + * + * FT_Init_FreeType( &library ); + * + * FT_Property_Set( library, "autofitter", + * "warping", &warping ); + * } + * + * @note: + * This property can be used with @FT_Property_Get also. + * + * This property can be set via the `FREETYPE_PROPERTIES' environment + * variable (using values 1 and 0 for `on' and `off', respectively). + * + * The warping code can also change advance widths. Have a look at the + * `lsb_delta' and `rsb_delta' fields in the @FT_GlyphSlotRec structure + * for details on improving inter-glyph distances while rendering. + * + * Since warping is a global property of the auto-hinter it is best to + * change its value before rendering any face. Otherwise, you should + * reload all faces that get auto-hinted in `normal' hinting mode. + * + * @since: + * 2.6 + * + */ + + + /* */ + + +FT_END_HEADER + + +#endif /* FTDRIVER_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/fterrdef.h b/freetype/include/freetype2/freetype/fterrdef.h new file mode 100644 index 0000000..8ffd346 --- /dev/null +++ b/freetype/include/freetype2/freetype/fterrdef.h @@ -0,0 +1,280 @@ +/***************************************************************************/ +/* */ +/* fterrdef.h */ +/* */ +/* FreeType error codes (specification). */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* error_code_values */ + /* */ + /* <Title> */ + /* Error Code Values */ + /* */ + /* <Abstract> */ + /* All possible error codes returned by FreeType functions. */ + /* */ + /* <Description> */ + /* The list below is taken verbatim from the file `fterrdef.h' */ + /* (loaded automatically by including `FT_FREETYPE_H'). The first */ + /* argument of the `FT_ERROR_DEF_' macro is the error label; by */ + /* default, the prefix `FT_Err_' gets added so that you get error */ + /* names like `FT_Err_Cannot_Open_Resource'. The second argument is */ + /* the error code, and the last argument an error string, which is not */ + /* used by FreeType. */ + /* */ + /* Within your application you should *only* use error names and */ + /* *never* its numeric values! The latter might (and actually do) */ + /* change in forthcoming FreeType versions. */ + /* */ + /* Macro `FT_NOERRORDEF_' defines `FT_Err_Ok', which is always zero. */ + /* See the `Error Enumerations' subsection how to automatically */ + /* generate a list of error strings. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Err_XXX */ + /* */ + /*************************************************************************/ + + /* generic errors */ + + FT_NOERRORDEF_( Ok, 0x00, + "no error" ) + + FT_ERRORDEF_( Cannot_Open_Resource, 0x01, + "cannot open resource" ) + FT_ERRORDEF_( Unknown_File_Format, 0x02, + "unknown file format" ) + FT_ERRORDEF_( Invalid_File_Format, 0x03, + "broken file" ) + FT_ERRORDEF_( Invalid_Version, 0x04, + "invalid FreeType version" ) + FT_ERRORDEF_( Lower_Module_Version, 0x05, + "module version is too low" ) + FT_ERRORDEF_( Invalid_Argument, 0x06, + "invalid argument" ) + FT_ERRORDEF_( Unimplemented_Feature, 0x07, + "unimplemented feature" ) + FT_ERRORDEF_( Invalid_Table, 0x08, + "broken table" ) + FT_ERRORDEF_( Invalid_Offset, 0x09, + "broken offset within table" ) + FT_ERRORDEF_( Array_Too_Large, 0x0A, + "array allocation size too large" ) + FT_ERRORDEF_( Missing_Module, 0x0B, + "missing module" ) + FT_ERRORDEF_( Missing_Property, 0x0C, + "missing property" ) + + /* glyph/character errors */ + + FT_ERRORDEF_( Invalid_Glyph_Index, 0x10, + "invalid glyph index" ) + FT_ERRORDEF_( Invalid_Character_Code, 0x11, + "invalid character code" ) + FT_ERRORDEF_( Invalid_Glyph_Format, 0x12, + "unsupported glyph image format" ) + FT_ERRORDEF_( Cannot_Render_Glyph, 0x13, + "cannot render this glyph format" ) + FT_ERRORDEF_( Invalid_Outline, 0x14, + "invalid outline" ) + FT_ERRORDEF_( Invalid_Composite, 0x15, + "invalid composite glyph" ) + FT_ERRORDEF_( Too_Many_Hints, 0x16, + "too many hints" ) + FT_ERRORDEF_( Invalid_Pixel_Size, 0x17, + "invalid pixel size" ) + + /* handle errors */ + + FT_ERRORDEF_( Invalid_Handle, 0x20, + "invalid object handle" ) + FT_ERRORDEF_( Invalid_Library_Handle, 0x21, + "invalid library handle" ) + FT_ERRORDEF_( Invalid_Driver_Handle, 0x22, + "invalid module handle" ) + FT_ERRORDEF_( Invalid_Face_Handle, 0x23, + "invalid face handle" ) + FT_ERRORDEF_( Invalid_Size_Handle, 0x24, + "invalid size handle" ) + FT_ERRORDEF_( Invalid_Slot_Handle, 0x25, + "invalid glyph slot handle" ) + FT_ERRORDEF_( Invalid_CharMap_Handle, 0x26, + "invalid charmap handle" ) + FT_ERRORDEF_( Invalid_Cache_Handle, 0x27, + "invalid cache manager handle" ) + FT_ERRORDEF_( Invalid_Stream_Handle, 0x28, + "invalid stream handle" ) + + /* driver errors */ + + FT_ERRORDEF_( Too_Many_Drivers, 0x30, + "too many modules" ) + FT_ERRORDEF_( Too_Many_Extensions, 0x31, + "too many extensions" ) + + /* memory errors */ + + FT_ERRORDEF_( Out_Of_Memory, 0x40, + "out of memory" ) + FT_ERRORDEF_( Unlisted_Object, 0x41, + "unlisted object" ) + + /* stream errors */ + + FT_ERRORDEF_( Cannot_Open_Stream, 0x51, + "cannot open stream" ) + FT_ERRORDEF_( Invalid_Stream_Seek, 0x52, + "invalid stream seek" ) + FT_ERRORDEF_( Invalid_Stream_Skip, 0x53, + "invalid stream skip" ) + FT_ERRORDEF_( Invalid_Stream_Read, 0x54, + "invalid stream read" ) + FT_ERRORDEF_( Invalid_Stream_Operation, 0x55, + "invalid stream operation" ) + FT_ERRORDEF_( Invalid_Frame_Operation, 0x56, + "invalid frame operation" ) + FT_ERRORDEF_( Nested_Frame_Access, 0x57, + "nested frame access" ) + FT_ERRORDEF_( Invalid_Frame_Read, 0x58, + "invalid frame read" ) + + /* raster errors */ + + FT_ERRORDEF_( Raster_Uninitialized, 0x60, + "raster uninitialized" ) + FT_ERRORDEF_( Raster_Corrupted, 0x61, + "raster corrupted" ) + FT_ERRORDEF_( Raster_Overflow, 0x62, + "raster overflow" ) + FT_ERRORDEF_( Raster_Negative_Height, 0x63, + "negative height while rastering" ) + + /* cache errors */ + + FT_ERRORDEF_( Too_Many_Caches, 0x70, + "too many registered caches" ) + + /* TrueType and SFNT errors */ + + FT_ERRORDEF_( Invalid_Opcode, 0x80, + "invalid opcode" ) + FT_ERRORDEF_( Too_Few_Arguments, 0x81, + "too few arguments" ) + FT_ERRORDEF_( Stack_Overflow, 0x82, + "stack overflow" ) + FT_ERRORDEF_( Code_Overflow, 0x83, + "code overflow" ) + FT_ERRORDEF_( Bad_Argument, 0x84, + "bad argument" ) + FT_ERRORDEF_( Divide_By_Zero, 0x85, + "division by zero" ) + FT_ERRORDEF_( Invalid_Reference, 0x86, + "invalid reference" ) + FT_ERRORDEF_( Debug_OpCode, 0x87, + "found debug opcode" ) + FT_ERRORDEF_( ENDF_In_Exec_Stream, 0x88, + "found ENDF opcode in execution stream" ) + FT_ERRORDEF_( Nested_DEFS, 0x89, + "nested DEFS" ) + FT_ERRORDEF_( Invalid_CodeRange, 0x8A, + "invalid code range" ) + FT_ERRORDEF_( Execution_Too_Long, 0x8B, + "execution context too long" ) + FT_ERRORDEF_( Too_Many_Function_Defs, 0x8C, + "too many function definitions" ) + FT_ERRORDEF_( Too_Many_Instruction_Defs, 0x8D, + "too many instruction definitions" ) + FT_ERRORDEF_( Table_Missing, 0x8E, + "SFNT font table missing" ) + FT_ERRORDEF_( Horiz_Header_Missing, 0x8F, + "horizontal header (hhea) table missing" ) + FT_ERRORDEF_( Locations_Missing, 0x90, + "locations (loca) table missing" ) + FT_ERRORDEF_( Name_Table_Missing, 0x91, + "name table missing" ) + FT_ERRORDEF_( CMap_Table_Missing, 0x92, + "character map (cmap) table missing" ) + FT_ERRORDEF_( Hmtx_Table_Missing, 0x93, + "horizontal metrics (hmtx) table missing" ) + FT_ERRORDEF_( Post_Table_Missing, 0x94, + "PostScript (post) table missing" ) + FT_ERRORDEF_( Invalid_Horiz_Metrics, 0x95, + "invalid horizontal metrics" ) + FT_ERRORDEF_( Invalid_CharMap_Format, 0x96, + "invalid character map (cmap) format" ) + FT_ERRORDEF_( Invalid_PPem, 0x97, + "invalid ppem value" ) + FT_ERRORDEF_( Invalid_Vert_Metrics, 0x98, + "invalid vertical metrics" ) + FT_ERRORDEF_( Could_Not_Find_Context, 0x99, + "could not find context" ) + FT_ERRORDEF_( Invalid_Post_Table_Format, 0x9A, + "invalid PostScript (post) table format" ) + FT_ERRORDEF_( Invalid_Post_Table, 0x9B, + "invalid PostScript (post) table" ) + FT_ERRORDEF_( DEF_In_Glyf_Bytecode, 0x9C, + "found FDEF or IDEF opcode in glyf bytecode" ) + FT_ERRORDEF_( Missing_Bitmap, 0x9D, + "missing bitmap in strike" ) + + /* CFF, CID, and Type 1 errors */ + + FT_ERRORDEF_( Syntax_Error, 0xA0, + "opcode syntax error" ) + FT_ERRORDEF_( Stack_Underflow, 0xA1, + "argument stack underflow" ) + FT_ERRORDEF_( Ignore, 0xA2, + "ignore" ) + FT_ERRORDEF_( No_Unicode_Glyph_Name, 0xA3, + "no Unicode glyph name found" ) + FT_ERRORDEF_( Glyph_Too_Big, 0xA4, + "glyph too big for hinting" ) + + /* BDF errors */ + + FT_ERRORDEF_( Missing_Startfont_Field, 0xB0, + "`STARTFONT' field missing" ) + FT_ERRORDEF_( Missing_Font_Field, 0xB1, + "`FONT' field missing" ) + FT_ERRORDEF_( Missing_Size_Field, 0xB2, + "`SIZE' field missing" ) + FT_ERRORDEF_( Missing_Fontboundingbox_Field, 0xB3, + "`FONTBOUNDINGBOX' field missing" ) + FT_ERRORDEF_( Missing_Chars_Field, 0xB4, + "`CHARS' field missing" ) + FT_ERRORDEF_( Missing_Startchar_Field, 0xB5, + "`STARTCHAR' field missing" ) + FT_ERRORDEF_( Missing_Encoding_Field, 0xB6, + "`ENCODING' field missing" ) + FT_ERRORDEF_( Missing_Bbx_Field, 0xB7, + "`BBX' field missing" ) + FT_ERRORDEF_( Bbx_Too_Big, 0xB8, + "`BBX' too big" ) + FT_ERRORDEF_( Corrupted_Font_Header, 0xB9, + "Font header corrupted or missing fields" ) + FT_ERRORDEF_( Corrupted_Font_Glyphs, 0xBA, + "Font glyphs corrupted or missing fields" ) + + /* */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/fterrors.h b/freetype/include/freetype2/freetype/fterrors.h new file mode 100644 index 0000000..f6ee5c2 --- /dev/null +++ b/freetype/include/freetype2/freetype/fterrors.h @@ -0,0 +1,226 @@ +/***************************************************************************/ +/* */ +/* fterrors.h */ +/* */ +/* FreeType error code handling (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* error_enumerations */ + /* */ + /* <Title> */ + /* Error Enumerations */ + /* */ + /* <Abstract> */ + /* How to handle errors and error strings. */ + /* */ + /* <Description> */ + /* The header file `fterrors.h' (which is automatically included by */ + /* `freetype.h' defines the handling of FreeType's enumeration */ + /* constants. It can also be used to generate error message strings */ + /* with a small macro trick explained below. */ + /* */ + /* *Error* *Formats* */ + /* */ + /* The configuration macro FT_CONFIG_OPTION_USE_MODULE_ERRORS can be */ + /* defined in `ftoption.h' in order to make the higher byte indicate */ + /* the module where the error has happened (this is not compatible */ + /* with standard builds of FreeType~2, however). See the file */ + /* `ftmoderr.h' for more details. */ + /* */ + /* *Error* *Message* *Strings* */ + /* */ + /* Error definitions are set up with special macros that allow client */ + /* applications to build a table of error message strings. The */ + /* strings are not included in a normal build of FreeType~2 to save */ + /* space (most client applications do not use them). */ + /* */ + /* To do so, you have to define the following macros before including */ + /* this file. */ + /* */ + /* { */ + /* FT_ERROR_START_LIST */ + /* } */ + /* */ + /* This macro is called before anything else to define the start of */ + /* the error list. It is followed by several FT_ERROR_DEF calls. */ + /* */ + /* { */ + /* FT_ERROR_DEF( e, v, s ) */ + /* } */ + /* */ + /* This macro is called to define one single error. `e' is the error */ + /* code identifier (e.g., `Invalid_Argument'), `v' is the error's */ + /* numerical value, and `s' is the corresponding error string. */ + /* */ + /* { */ + /* FT_ERROR_END_LIST */ + /* } */ + /* */ + /* This macro ends the list. */ + /* */ + /* Additionally, you have to undefine `FTERRORS_H_' before #including */ + /* this file. */ + /* */ + /* Here is a simple example. */ + /* */ + /* { */ + /* #undef FTERRORS_H_ */ + /* #define FT_ERRORDEF( e, v, s ) { e, s }, */ + /* #define FT_ERROR_START_LIST { */ + /* #define FT_ERROR_END_LIST { 0, NULL } }; */ + /* */ + /* const struct */ + /* { */ + /* int err_code; */ + /* const char* err_msg; */ + /* } ft_errors[] = */ + /* */ + /* #include FT_ERRORS_H */ + /* } */ + /* */ + /* Note that `FT_Err_Ok' is _not_ defined with `FT_ERRORDEF' but with */ + /* `FT_NOERRORDEF'; it is always zero. */ + /* */ + /*************************************************************************/ + + /* */ + + /* In previous FreeType versions we used `__FTERRORS_H__'. However, */ + /* using two successive underscores in a non-system symbol name */ + /* violates the C (and C++) standard, so it was changed to the */ + /* current form. In spite of this, we have to make */ + /* */ + /* #undefine __FTERRORS_H__ */ + /* */ + /* work for backward compatibility. */ + /* */ +#if !( defined( FTERRORS_H_ ) && defined ( __FTERRORS_H__ ) ) +#define FTERRORS_H_ +#define __FTERRORS_H__ + + + /* include module base error codes */ +#include FT_MODULE_ERRORS_H + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** SETUP MACROS *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#undef FT_NEED_EXTERN_C + + + /* FT_ERR_PREFIX is used as a prefix for error identifiers. */ + /* By default, we use `FT_Err_'. */ + /* */ +#ifndef FT_ERR_PREFIX +#define FT_ERR_PREFIX FT_Err_ +#endif + + + /* FT_ERR_BASE is used as the base for module-specific errors. */ + /* */ +#ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS + +#ifndef FT_ERR_BASE +#define FT_ERR_BASE FT_Mod_Err_Base +#endif + +#else + +#undef FT_ERR_BASE +#define FT_ERR_BASE 0 + +#endif /* FT_CONFIG_OPTION_USE_MODULE_ERRORS */ + + + /* If FT_ERRORDEF is not defined, we need to define a simple */ + /* enumeration type. */ + /* */ +#ifndef FT_ERRORDEF + +#define FT_ERRORDEF( e, v, s ) e = v, +#define FT_ERROR_START_LIST enum { +#define FT_ERROR_END_LIST FT_ERR_CAT( FT_ERR_PREFIX, Max ) }; + +#ifdef __cplusplus +#define FT_NEED_EXTERN_C + extern "C" { +#endif + +#endif /* !FT_ERRORDEF */ + + + /* this macro is used to define an error */ +#define FT_ERRORDEF_( e, v, s ) \ + FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v + FT_ERR_BASE, s ) + + /* this is only used for <module>_Err_Ok, which must be 0! */ +#define FT_NOERRORDEF_( e, v, s ) \ + FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v, s ) + + +#ifdef FT_ERROR_START_LIST + FT_ERROR_START_LIST +#endif + + + /* now include the error codes */ +#include FT_ERROR_DEFINITIONS_H + + +#ifdef FT_ERROR_END_LIST + FT_ERROR_END_LIST +#endif + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** SIMPLE CLEANUP *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + +#ifdef FT_NEED_EXTERN_C + } +#endif + +#undef FT_ERROR_START_LIST +#undef FT_ERROR_END_LIST + +#undef FT_ERRORDEF +#undef FT_ERRORDEF_ +#undef FT_NOERRORDEF_ + +#undef FT_NEED_EXTERN_C +#undef FT_ERR_BASE + + /* FT_ERR_PREFIX is needed internally */ +#ifndef FT2_BUILD_LIBRARY +#undef FT_ERR_PREFIX +#endif + +#endif /* !(FTERRORS_H_ && __FTERRORS_H__) */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftfntfmt.h b/freetype/include/freetype2/freetype/ftfntfmt.h new file mode 100644 index 0000000..cc86efa --- /dev/null +++ b/freetype/include/freetype2/freetype/ftfntfmt.h @@ -0,0 +1,95 @@ +/***************************************************************************/ +/* */ +/* ftfntfmt.h */ +/* */ +/* Support functions for font formats. */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTFNTFMT_H_ +#define FTFNTFMT_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* font_formats */ + /* */ + /* <Title> */ + /* Font Formats */ + /* */ + /* <Abstract> */ + /* Getting the font format. */ + /* */ + /* <Description> */ + /* The single function in this section can be used to get the font */ + /* format. Note that this information is not needed normally; */ + /* however, there are special cases (like in PDF devices) where it is */ + /* important to differentiate, in spite of FreeType's uniform API. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Font_Format */ + /* */ + /* <Description> */ + /* Return a string describing the format of a given face. Possible */ + /* values are `TrueType', `Type~1', `BDF', `PCF', `Type~42', */ + /* `CID~Type~1', `CFF', `PFR', and `Windows~FNT'. */ + /* */ + /* The return value is suitable to be used as an X11 FONT_PROPERTY. */ + /* */ + /* <Input> */ + /* face :: */ + /* Input face handle. */ + /* */ + /* <Return> */ + /* Font format string. NULL in case of error. */ + /* */ + /* <Note> */ + /* A deprecated name for the same function is */ + /* `FT_Get_X11_Font_Format'. */ + /* */ + FT_EXPORT( const char* ) + FT_Get_Font_Format( FT_Face face ); + + + /* deprecated */ + FT_EXPORT( const char* ) + FT_Get_X11_Font_Format( FT_Face face ); + + + /* */ + + +FT_END_HEADER + +#endif /* FTFNTFMT_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftgasp.h b/freetype/include/freetype2/freetype/ftgasp.h new file mode 100644 index 0000000..fc1248f --- /dev/null +++ b/freetype/include/freetype2/freetype/ftgasp.h @@ -0,0 +1,142 @@ +/***************************************************************************/ +/* */ +/* ftgasp.h */ +/* */ +/* Access of TrueType's `gasp' table (specification). */ +/* */ +/* Copyright 2007-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTGASP_H_ +#define FTGASP_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************** + * + * @section: + * gasp_table + * + * @title: + * Gasp Table + * + * @abstract: + * Retrieving TrueType `gasp' table entries. + * + * @description: + * The function @FT_Get_Gasp can be used to query a TrueType or OpenType + * font for specific entries in its `gasp' table, if any. This is + * mainly useful when implementing native TrueType hinting with the + * bytecode interpreter to duplicate the Windows text rendering results. + */ + + /************************************************************************* + * + * @enum: + * FT_GASP_XXX + * + * @description: + * A list of values and/or bit-flags returned by the @FT_Get_Gasp + * function. + * + * @values: + * FT_GASP_NO_TABLE :: + * This special value means that there is no GASP table in this face. + * It is up to the client to decide what to do. + * + * FT_GASP_DO_GRIDFIT :: + * Grid-fitting and hinting should be performed at the specified ppem. + * This *really* means TrueType bytecode interpretation. If this bit + * is not set, no hinting gets applied. + * + * FT_GASP_DO_GRAY :: + * Anti-aliased rendering should be performed at the specified ppem. + * If not set, do monochrome rendering. + * + * FT_GASP_SYMMETRIC_SMOOTHING :: + * If set, smoothing along multiple axes must be used with ClearType. + * + * FT_GASP_SYMMETRIC_GRIDFIT :: + * Grid-fitting must be used with ClearType's symmetric smoothing. + * + * @note: + * The bit-flags `FT_GASP_DO_GRIDFIT' and `FT_GASP_DO_GRAY' are to be + * used for standard font rasterization only. Independently of that, + * `FT_GASP_SYMMETRIC_SMOOTHING' and `FT_GASP_SYMMETRIC_GRIDFIT' are to + * be used if ClearType is enabled (and `FT_GASP_DO_GRIDFIT' and + * `FT_GASP_DO_GRAY' are consequently ignored). + * + * `ClearType' is Microsoft's implementation of LCD rendering, partly + * protected by patents. + * + * @since: + * 2.3.0 + */ +#define FT_GASP_NO_TABLE -1 +#define FT_GASP_DO_GRIDFIT 0x01 +#define FT_GASP_DO_GRAY 0x02 +#define FT_GASP_SYMMETRIC_GRIDFIT 0x04 +#define FT_GASP_SYMMETRIC_SMOOTHING 0x08 + + + /************************************************************************* + * + * @func: + * FT_Get_Gasp + * + * @description: + * For a TrueType or OpenType font file, return the rasterizer behaviour + * flags from the font's `gasp' table corresponding to a given + * character pixel size. + * + * @input: + * face :: The source face handle. + * + * ppem :: The vertical character pixel size. + * + * @return: + * Bit flags (see @FT_GASP_XXX), or @FT_GASP_NO_TABLE if there is no + * `gasp' table in the face. + * + * @note: + * If you want to use the MM functionality of OpenType variation fonts + * (i.e., using @FT_Set_Var_Design_Coordinates and friends), call this + * function *after* setting an instance since the return values can + * change. + * + * @since: + * 2.3.0 + */ + FT_EXPORT( FT_Int ) + FT_Get_Gasp( FT_Face face, + FT_UInt ppem ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGASP_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftglyph.h b/freetype/include/freetype2/freetype/ftglyph.h new file mode 100644 index 0000000..5f3fc00 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftglyph.h @@ -0,0 +1,614 @@ +/***************************************************************************/ +/* */ +/* ftglyph.h */ +/* */ +/* FreeType convenience functions to handle glyphs (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file contains the definition of several convenience functions */ + /* that can be used by client applications to easily retrieve glyph */ + /* bitmaps and outlines from a given face. */ + /* */ + /* These functions should be optional if you are writing a font server */ + /* or text layout engine on top of FreeType. However, they are pretty */ + /* handy for many other simple uses of the library. */ + /* */ + /*************************************************************************/ + + +#ifndef FTGLYPH_H_ +#define FTGLYPH_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* glyph_management */ + /* */ + /* <Title> */ + /* Glyph Management */ + /* */ + /* <Abstract> */ + /* Generic interface to manage individual glyph data. */ + /* */ + /* <Description> */ + /* This section contains definitions used to manage glyph data */ + /* through generic FT_Glyph objects. Each of them can contain a */ + /* bitmap, a vector outline, or even images in other formats. */ + /* */ + /*************************************************************************/ + + + /* forward declaration to a private type */ + typedef struct FT_Glyph_Class_ FT_Glyph_Class; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Glyph */ + /* */ + /* <Description> */ + /* Handle to an object used to model generic glyph images. It is a */ + /* pointer to the @FT_GlyphRec structure and can contain a glyph */ + /* bitmap or pointer. */ + /* */ + /* <Note> */ + /* Glyph objects are not owned by the library. You must thus release */ + /* them manually (through @FT_Done_Glyph) _before_ calling */ + /* @FT_Done_FreeType. */ + /* */ + typedef struct FT_GlyphRec_* FT_Glyph; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_GlyphRec */ + /* */ + /* <Description> */ + /* The root glyph structure contains a given glyph image plus its */ + /* advance width in 16.16 fixed-point format. */ + /* */ + /* <Fields> */ + /* library :: A handle to the FreeType library object. */ + /* */ + /* clazz :: A pointer to the glyph's class. Private. */ + /* */ + /* format :: The format of the glyph's image. */ + /* */ + /* advance :: A 16.16 vector that gives the glyph's advance width. */ + /* */ + typedef struct FT_GlyphRec_ + { + FT_Library library; + const FT_Glyph_Class* clazz; + FT_Glyph_Format format; + FT_Vector advance; + + } FT_GlyphRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_BitmapGlyph */ + /* */ + /* <Description> */ + /* A handle to an object used to model a bitmap glyph image. This is */ + /* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. */ + /* */ + typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_BitmapGlyphRec */ + /* */ + /* <Description> */ + /* A structure used for bitmap glyph images. This really is a */ + /* `sub-class' of @FT_GlyphRec. */ + /* */ + /* <Fields> */ + /* root :: The root @FT_Glyph fields. */ + /* */ + /* left :: The left-side bearing, i.e., the horizontal distance */ + /* from the current pen position to the left border of the */ + /* glyph bitmap. */ + /* */ + /* top :: The top-side bearing, i.e., the vertical distance from */ + /* the current pen position to the top border of the glyph */ + /* bitmap. This distance is positive for upwards~y! */ + /* */ + /* bitmap :: A descriptor for the bitmap. */ + /* */ + /* <Note> */ + /* You can typecast an @FT_Glyph to @FT_BitmapGlyph if you have */ + /* `glyph->format == FT_GLYPH_FORMAT_BITMAP'. This lets you access */ + /* the bitmap's contents easily. */ + /* */ + /* The corresponding pixel buffer is always owned by @FT_BitmapGlyph */ + /* and is thus created and destroyed with it. */ + /* */ + typedef struct FT_BitmapGlyphRec_ + { + FT_GlyphRec root; + FT_Int left; + FT_Int top; + FT_Bitmap bitmap; + + } FT_BitmapGlyphRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_OutlineGlyph */ + /* */ + /* <Description> */ + /* A handle to an object used to model an outline glyph image. This */ + /* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. */ + /* */ + typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_OutlineGlyphRec */ + /* */ + /* <Description> */ + /* A structure used for outline (vectorial) glyph images. This */ + /* really is a `sub-class' of @FT_GlyphRec. */ + /* */ + /* <Fields> */ + /* root :: The root @FT_Glyph fields. */ + /* */ + /* outline :: A descriptor for the outline. */ + /* */ + /* <Note> */ + /* You can typecast an @FT_Glyph to @FT_OutlineGlyph if you have */ + /* `glyph->format == FT_GLYPH_FORMAT_OUTLINE'. This lets you access */ + /* the outline's content easily. */ + /* */ + /* As the outline is extracted from a glyph slot, its coordinates are */ + /* expressed normally in 26.6 pixels, unless the flag */ + /* @FT_LOAD_NO_SCALE was used in @FT_Load_Glyph() or @FT_Load_Char(). */ + /* */ + /* The outline's tables are always owned by the object and are */ + /* destroyed with it. */ + /* */ + typedef struct FT_OutlineGlyphRec_ + { + FT_GlyphRec root; + FT_Outline outline; + + } FT_OutlineGlyphRec; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Glyph */ + /* */ + /* <Description> */ + /* A function used to extract a glyph image from a slot. Note that */ + /* the created @FT_Glyph object must be released with @FT_Done_Glyph. */ + /* */ + /* <Input> */ + /* slot :: A handle to the source glyph slot. */ + /* */ + /* <Output> */ + /* aglyph :: A handle to the glyph object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Because `*aglyph->advance.x' and '*aglyph->advance.y' are 16.16 */ + /* fixed-point numbers, `slot->advance.x' and `slot->advance.y' */ + /* (which are in 26.6 fixed-point format) must be in the range */ + /* ]-32768;32768[. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Glyph( FT_GlyphSlot slot, + FT_Glyph *aglyph ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_Copy */ + /* */ + /* <Description> */ + /* A function used to copy a glyph image. Note that the created */ + /* @FT_Glyph object must be released with @FT_Done_Glyph. */ + /* */ + /* <Input> */ + /* source :: A handle to the source glyph object. */ + /* */ + /* <Output> */ + /* target :: A handle to the target glyph object. 0~in case of */ + /* error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Glyph_Copy( FT_Glyph source, + FT_Glyph *target ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_Transform */ + /* */ + /* <Description> */ + /* Transform a glyph image if its format is scalable. */ + /* */ + /* <InOut> */ + /* glyph :: A handle to the target glyph object. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to a 2x2 matrix to apply. */ + /* */ + /* delta :: A pointer to a 2d vector to apply. Coordinates are */ + /* expressed in 1/64th of a pixel. */ + /* */ + /* <Return> */ + /* FreeType error code (if not 0, the glyph format is not scalable). */ + /* */ + /* <Note> */ + /* The 2x2 transformation matrix is also applied to the glyph's */ + /* advance vector. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Glyph_Transform( FT_Glyph glyph, + FT_Matrix* matrix, + FT_Vector* delta ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Glyph_BBox_Mode */ + /* */ + /* <Description> */ + /* The mode how the values of @FT_Glyph_Get_CBox are returned. */ + /* */ + /* <Values> */ + /* FT_GLYPH_BBOX_UNSCALED :: */ + /* Return unscaled font units. */ + /* */ + /* FT_GLYPH_BBOX_SUBPIXELS :: */ + /* Return unfitted 26.6 coordinates. */ + /* */ + /* FT_GLYPH_BBOX_GRIDFIT :: */ + /* Return grid-fitted 26.6 coordinates. */ + /* */ + /* FT_GLYPH_BBOX_TRUNCATE :: */ + /* Return coordinates in integer pixels. */ + /* */ + /* FT_GLYPH_BBOX_PIXELS :: */ + /* Return grid-fitted pixel coordinates. */ + /* */ + typedef enum FT_Glyph_BBox_Mode_ + { + FT_GLYPH_BBOX_UNSCALED = 0, + FT_GLYPH_BBOX_SUBPIXELS = 0, + FT_GLYPH_BBOX_GRIDFIT = 1, + FT_GLYPH_BBOX_TRUNCATE = 2, + FT_GLYPH_BBOX_PIXELS = 3 + + } FT_Glyph_BBox_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Glyph_BBox_Mode' values instead */ +#define ft_glyph_bbox_unscaled FT_GLYPH_BBOX_UNSCALED +#define ft_glyph_bbox_subpixels FT_GLYPH_BBOX_SUBPIXELS +#define ft_glyph_bbox_gridfit FT_GLYPH_BBOX_GRIDFIT +#define ft_glyph_bbox_truncate FT_GLYPH_BBOX_TRUNCATE +#define ft_glyph_bbox_pixels FT_GLYPH_BBOX_PIXELS + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_Get_CBox */ + /* */ + /* <Description> */ + /* Return a glyph's `control box'. The control box encloses all the */ + /* outline's points, including Bezier control points. Though it */ + /* coincides with the exact bounding box for most glyphs, it can be */ + /* slightly larger in some situations (like when rotating an outline */ + /* that contains Bezier outside arcs). */ + /* */ + /* Computing the control box is very fast, while getting the bounding */ + /* box can take much more time as it needs to walk over all segments */ + /* and arcs in the outline. To get the latter, you can use the */ + /* `ftbbox' component, which is dedicated to this single task. */ + /* */ + /* <Input> */ + /* glyph :: A handle to the source glyph object. */ + /* */ + /* mode :: The mode that indicates how to interpret the returned */ + /* bounding box values. */ + /* */ + /* <Output> */ + /* acbox :: The glyph coordinate bounding box. Coordinates are */ + /* expressed in 1/64th of pixels if it is grid-fitted. */ + /* */ + /* <Note> */ + /* Coordinates are relative to the glyph origin, using the y~upwards */ + /* convention. */ + /* */ + /* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode' */ + /* must be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font */ + /* units in 26.6 pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS */ + /* is another name for this constant. */ + /* */ + /* If the font is tricky and the glyph has been loaded with */ + /* @FT_LOAD_NO_SCALE, the resulting CBox is meaningless. To get */ + /* reasonable values for the CBox it is necessary to load the glyph */ + /* at a large ppem value (so that the hinting instructions can */ + /* properly shift and scale the subglyphs), then extracting the CBox, */ + /* which can be eventually converted back to font units. */ + /* */ + /* Note that the maximum coordinates are exclusive, which means that */ + /* one can compute the width and height of the glyph image (be it in */ + /* integer or 26.6 pixels) as: */ + /* */ + /* { */ + /* width = bbox.xMax - bbox.xMin; */ + /* height = bbox.yMax - bbox.yMin; */ + /* } */ + /* */ + /* Note also that for 26.6 coordinates, if `bbox_mode' is set to */ + /* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, */ + /* which corresponds to: */ + /* */ + /* { */ + /* bbox.xMin = FLOOR(bbox.xMin); */ + /* bbox.yMin = FLOOR(bbox.yMin); */ + /* bbox.xMax = CEILING(bbox.xMax); */ + /* bbox.yMax = CEILING(bbox.yMax); */ + /* } */ + /* */ + /* To get the bbox in pixel coordinates, set `bbox_mode' to */ + /* @FT_GLYPH_BBOX_TRUNCATE. */ + /* */ + /* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' */ + /* to @FT_GLYPH_BBOX_PIXELS. */ + /* */ + FT_EXPORT( void ) + FT_Glyph_Get_CBox( FT_Glyph glyph, + FT_UInt bbox_mode, + FT_BBox *acbox ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Glyph_To_Bitmap */ + /* */ + /* <Description> */ + /* Convert a given glyph object to a bitmap glyph object. */ + /* */ + /* <InOut> */ + /* the_glyph :: A pointer to a handle to the target glyph. */ + /* */ + /* <Input> */ + /* render_mode :: An enumeration that describes how the data is */ + /* rendered. */ + /* */ + /* origin :: A pointer to a vector used to translate the glyph */ + /* image before rendering. Can be~0 (if no */ + /* translation). The origin is expressed in */ + /* 26.6 pixels. */ + /* */ + /* destroy :: A boolean that indicates that the original glyph */ + /* image should be destroyed by this function. It is */ + /* never destroyed in case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function does nothing if the glyph format isn't scalable. */ + /* */ + /* The glyph image is translated with the `origin' vector before */ + /* rendering. */ + /* */ + /* The first parameter is a pointer to an @FT_Glyph handle, that will */ + /* be _replaced_ by this function (with newly allocated data). */ + /* Typically, you would use (omitting error handling): */ + /* */ + /* */ + /* { */ + /* FT_Glyph glyph; */ + /* FT_BitmapGlyph glyph_bitmap; */ + /* */ + /* */ + /* // load glyph */ + /* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAULT ); */ + /* */ + /* // extract glyph image */ + /* error = FT_Get_Glyph( face->glyph, &glyph ); */ + /* */ + /* // convert to a bitmap (default render mode + destroying old) */ + /* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) */ + /* { */ + /* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, */ + /* 0, 1 ); */ + /* if ( error ) // `glyph' unchanged */ + /* ... */ + /* } */ + /* */ + /* // access bitmap content by typecasting */ + /* glyph_bitmap = (FT_BitmapGlyph)glyph; */ + /* */ + /* // do funny stuff with it, like blitting/drawing */ + /* ... */ + /* */ + /* // discard glyph image (bitmap or not) */ + /* FT_Done_Glyph( glyph ); */ + /* } */ + /* */ + /* */ + /* Here another example, again without error handling: */ + /* */ + /* */ + /* { */ + /* FT_Glyph glyphs[MAX_GLYPHS] */ + /* */ + /* */ + /* ... */ + /* */ + /* for ( idx = 0; i < MAX_GLYPHS; i++ ) */ + /* error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT ) || */ + /* FT_Get_Glyph ( face->glyph, &glyph[idx] ); */ + /* */ + /* ... */ + /* */ + /* for ( idx = 0; i < MAX_GLYPHS; i++ ) */ + /* { */ + /* FT_Glyph bitmap = glyphs[idx]; */ + /* */ + /* */ + /* ... */ + /* */ + /* // after this call, `bitmap' no longer points into */ + /* // the `glyphs' array (and the old value isn't destroyed) */ + /* FT_Glyph_To_Bitmap( &bitmap, FT_RENDER_MODE_MONO, 0, 0 ); */ + /* */ + /* ... */ + /* */ + /* FT_Done_Glyph( bitmap ); */ + /* } */ + /* */ + /* ... */ + /* */ + /* for ( idx = 0; i < MAX_GLYPHS; i++ ) */ + /* FT_Done_Glyph( glyphs[idx] ); */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_Glyph_To_Bitmap( FT_Glyph* the_glyph, + FT_Render_Mode render_mode, + FT_Vector* origin, + FT_Bool destroy ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Glyph */ + /* */ + /* <Description> */ + /* Destroy a given glyph. */ + /* */ + /* <Input> */ + /* glyph :: A handle to the target glyph object. */ + /* */ + FT_EXPORT( void ) + FT_Done_Glyph( FT_Glyph glyph ); + + /* */ + + + /* other helpful functions */ + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Matrix_Multiply */ + /* */ + /* <Description> */ + /* Perform the matrix operation `b = a*b'. */ + /* */ + /* <Input> */ + /* a :: A pointer to matrix `a'. */ + /* */ + /* <InOut> */ + /* b :: A pointer to matrix `b'. */ + /* */ + /* <Note> */ + /* The result is undefined if either `a' or `b' is zero. */ + /* */ + /* Since the function uses wrap-around arithmetic, results become */ + /* meaningless if the arguments are very large. */ + /* */ + FT_EXPORT( void ) + FT_Matrix_Multiply( const FT_Matrix* a, + FT_Matrix* b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Matrix_Invert */ + /* */ + /* <Description> */ + /* Invert a 2x2 matrix. Return an error if it can't be inverted. */ + /* */ + /* <InOut> */ + /* matrix :: A pointer to the target matrix. Remains untouched in */ + /* case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Matrix_Invert( FT_Matrix* matrix ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGLYPH_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/freetype/include/freetype2/freetype/ftgxval.h b/freetype/include/freetype2/freetype/ftgxval.h new file mode 100644 index 0000000..8382d59 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftgxval.h @@ -0,0 +1,357 @@ +/***************************************************************************/ +/* */ +/* ftgxval.h */ +/* */ +/* FreeType API for validating TrueTypeGX/AAT tables (specification). */ +/* */ +/* Copyright 2004-2018 by */ +/* Masatake YAMATO, Redhat K.K, */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/***************************************************************************/ +/* */ +/* gxvalid is derived from both gxlayout module and otvalid module. */ +/* Development of gxlayout is supported by the Information-technology */ +/* Promotion Agency(IPA), Japan. */ +/* */ +/***************************************************************************/ + + +#ifndef FTGXVAL_H_ +#define FTGXVAL_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* gx_validation */ + /* */ + /* <Title> */ + /* TrueTypeGX/AAT Validation */ + /* */ + /* <Abstract> */ + /* An API to validate TrueTypeGX/AAT tables. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions to validate */ + /* some TrueTypeGX tables (feat, mort, morx, bsln, just, kern, opbd, */ + /* trak, prop, lcar). */ + /* */ + /* <Order> */ + /* FT_TrueTypeGX_Validate */ + /* FT_TrueTypeGX_Free */ + /* */ + /* FT_ClassicKern_Validate */ + /* FT_ClassicKern_Free */ + /* */ + /* FT_VALIDATE_GX_LENGTH */ + /* FT_VALIDATE_GXXXX */ + /* FT_VALIDATE_CKERNXXX */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* */ + /* Warning: Use FT_VALIDATE_XXX to validate a table. */ + /* Following definitions are for gxvalid developers. */ + /* */ + /* */ + /*************************************************************************/ + +#define FT_VALIDATE_feat_INDEX 0 +#define FT_VALIDATE_mort_INDEX 1 +#define FT_VALIDATE_morx_INDEX 2 +#define FT_VALIDATE_bsln_INDEX 3 +#define FT_VALIDATE_just_INDEX 4 +#define FT_VALIDATE_kern_INDEX 5 +#define FT_VALIDATE_opbd_INDEX 6 +#define FT_VALIDATE_trak_INDEX 7 +#define FT_VALIDATE_prop_INDEX 8 +#define FT_VALIDATE_lcar_INDEX 9 +#define FT_VALIDATE_GX_LAST_INDEX FT_VALIDATE_lcar_INDEX + + + /************************************************************************* + * + * @macro: + * FT_VALIDATE_GX_LENGTH + * + * @description: + * The number of tables checked in this module. Use it as a parameter + * for the `table-length' argument of function @FT_TrueTypeGX_Validate. + */ +#define FT_VALIDATE_GX_LENGTH ( FT_VALIDATE_GX_LAST_INDEX + 1 ) + + /* */ + + /* Up to 0x1000 is used by otvalid. + Ox2xxx is reserved for feature OT extension. */ +#define FT_VALIDATE_GX_START 0x4000 +#define FT_VALIDATE_GX_BITFIELD( tag ) \ + ( FT_VALIDATE_GX_START << FT_VALIDATE_##tag##_INDEX ) + + + /********************************************************************** + * + * @enum: + * FT_VALIDATE_GXXXX + * + * @description: + * A list of bit-field constants used with @FT_TrueTypeGX_Validate to + * indicate which TrueTypeGX/AAT Type tables should be validated. + * + * @values: + * FT_VALIDATE_feat :: + * Validate `feat' table. + * + * FT_VALIDATE_mort :: + * Validate `mort' table. + * + * FT_VALIDATE_morx :: + * Validate `morx' table. + * + * FT_VALIDATE_bsln :: + * Validate `bsln' table. + * + * FT_VALIDATE_just :: + * Validate `just' table. + * + * FT_VALIDATE_kern :: + * Validate `kern' table. + * + * FT_VALIDATE_opbd :: + * Validate `opbd' table. + * + * FT_VALIDATE_trak :: + * Validate `trak' table. + * + * FT_VALIDATE_prop :: + * Validate `prop' table. + * + * FT_VALIDATE_lcar :: + * Validate `lcar' table. + * + * FT_VALIDATE_GX :: + * Validate all TrueTypeGX tables (feat, mort, morx, bsln, just, kern, + * opbd, trak, prop and lcar). + * + */ + +#define FT_VALIDATE_feat FT_VALIDATE_GX_BITFIELD( feat ) +#define FT_VALIDATE_mort FT_VALIDATE_GX_BITFIELD( mort ) +#define FT_VALIDATE_morx FT_VALIDATE_GX_BITFIELD( morx ) +#define FT_VALIDATE_bsln FT_VALIDATE_GX_BITFIELD( bsln ) +#define FT_VALIDATE_just FT_VALIDATE_GX_BITFIELD( just ) +#define FT_VALIDATE_kern FT_VALIDATE_GX_BITFIELD( kern ) +#define FT_VALIDATE_opbd FT_VALIDATE_GX_BITFIELD( opbd ) +#define FT_VALIDATE_trak FT_VALIDATE_GX_BITFIELD( trak ) +#define FT_VALIDATE_prop FT_VALIDATE_GX_BITFIELD( prop ) +#define FT_VALIDATE_lcar FT_VALIDATE_GX_BITFIELD( lcar ) + +#define FT_VALIDATE_GX ( FT_VALIDATE_feat | \ + FT_VALIDATE_mort | \ + FT_VALIDATE_morx | \ + FT_VALIDATE_bsln | \ + FT_VALIDATE_just | \ + FT_VALIDATE_kern | \ + FT_VALIDATE_opbd | \ + FT_VALIDATE_trak | \ + FT_VALIDATE_prop | \ + FT_VALIDATE_lcar ) + + + /********************************************************************** + * + * @function: + * FT_TrueTypeGX_Validate + * + * @description: + * Validate various TrueTypeGX tables to assure that all offsets and + * indices are valid. The idea is that a higher-level library that + * actually does the text layout can access those tables without + * error checking (which can be quite time consuming). + * + * @input: + * face :: + * A handle to the input face. + * + * validation_flags :: + * A bit field that specifies the tables to be validated. See + * @FT_VALIDATE_GXXXX for possible values. + * + * table_length :: + * The size of the `tables' array. Normally, @FT_VALIDATE_GX_LENGTH + * should be passed. + * + * @output: + * tables :: + * The array where all validated sfnt tables are stored. + * The array itself must be allocated by a client. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with TrueTypeGX fonts, returning an error + * otherwise. + * + * After use, the application should deallocate the buffers pointed to by + * each `tables' element, by calling @FT_TrueTypeGX_Free. A NULL value + * indicates that the table either doesn't exist in the font, the + * application hasn't asked for validation, or the validator doesn't have + * the ability to validate the sfnt table. + */ + FT_EXPORT( FT_Error ) + FT_TrueTypeGX_Validate( FT_Face face, + FT_UInt validation_flags, + FT_Bytes tables[FT_VALIDATE_GX_LENGTH], + FT_UInt table_length ); + + + /********************************************************************** + * + * @function: + * FT_TrueTypeGX_Free + * + * @description: + * Free the buffer allocated by TrueTypeGX validator. + * + * @input: + * face :: + * A handle to the input face. + * + * table :: + * The pointer to the buffer allocated by + * @FT_TrueTypeGX_Validate. + * + * @note: + * This function must be used to free the buffer allocated by + * @FT_TrueTypeGX_Validate only. + */ + FT_EXPORT( void ) + FT_TrueTypeGX_Free( FT_Face face, + FT_Bytes table ); + + + /********************************************************************** + * + * @enum: + * FT_VALIDATE_CKERNXXX + * + * @description: + * A list of bit-field constants used with @FT_ClassicKern_Validate + * to indicate the classic kern dialect or dialects. If the selected + * type doesn't fit, @FT_ClassicKern_Validate regards the table as + * invalid. + * + * @values: + * FT_VALIDATE_MS :: + * Handle the `kern' table as a classic Microsoft kern table. + * + * FT_VALIDATE_APPLE :: + * Handle the `kern' table as a classic Apple kern table. + * + * FT_VALIDATE_CKERN :: + * Handle the `kern' as either classic Apple or Microsoft kern table. + */ +#define FT_VALIDATE_MS ( FT_VALIDATE_GX_START << 0 ) +#define FT_VALIDATE_APPLE ( FT_VALIDATE_GX_START << 1 ) + +#define FT_VALIDATE_CKERN ( FT_VALIDATE_MS | FT_VALIDATE_APPLE ) + + + /********************************************************************** + * + * @function: + * FT_ClassicKern_Validate + * + * @description: + * Validate classic (16-bit format) kern table to assure that the offsets + * and indices are valid. The idea is that a higher-level library that + * actually does the text layout can access those tables without error + * checking (which can be quite time consuming). + * + * The `kern' table validator in @FT_TrueTypeGX_Validate deals with both + * the new 32-bit format and the classic 16-bit format, while + * FT_ClassicKern_Validate only supports the classic 16-bit format. + * + * @input: + * face :: + * A handle to the input face. + * + * validation_flags :: + * A bit field that specifies the dialect to be validated. See + * @FT_VALIDATE_CKERNXXX for possible values. + * + * @output: + * ckern_table :: + * A pointer to the kern table. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * After use, the application should deallocate the buffers pointed to by + * `ckern_table', by calling @FT_ClassicKern_Free. A NULL value + * indicates that the table doesn't exist in the font. + */ + FT_EXPORT( FT_Error ) + FT_ClassicKern_Validate( FT_Face face, + FT_UInt validation_flags, + FT_Bytes *ckern_table ); + + + /********************************************************************** + * + * @function: + * FT_ClassicKern_Free + * + * @description: + * Free the buffer allocated by classic Kern validator. + * + * @input: + * face :: + * A handle to the input face. + * + * table :: + * The pointer to the buffer that is allocated by + * @FT_ClassicKern_Validate. + * + * @note: + * This function must be used to free the buffer allocated by + * @FT_ClassicKern_Validate only. + */ + FT_EXPORT( void ) + FT_ClassicKern_Free( FT_Face face, + FT_Bytes table ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGXVAL_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftgzip.h b/freetype/include/freetype2/freetype/ftgzip.h new file mode 100644 index 0000000..db033da --- /dev/null +++ b/freetype/include/freetype2/freetype/ftgzip.h @@ -0,0 +1,151 @@ +/***************************************************************************/ +/* */ +/* ftgzip.h */ +/* */ +/* Gzip-compressed stream support. */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTGZIP_H_ +#define FTGZIP_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* gzip */ + /* */ + /* <Title> */ + /* GZIP Streams */ + /* */ + /* <Abstract> */ + /* Using gzip-compressed font files. */ + /* */ + /* <Description> */ + /* This section contains the declaration of Gzip-specific functions. */ + /* */ + /*************************************************************************/ + + + /************************************************************************ + * + * @function: + * FT_Stream_OpenGzip + * + * @description: + * Open a new stream to parse gzip-compressed font files. This is + * mainly used to support the compressed `*.pcf.gz' fonts that come + * with XFree86. + * + * @input: + * stream :: + * The target embedding stream. + * + * source :: + * The source stream. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source stream must be opened _before_ calling this function. + * + * Calling the internal function `FT_Stream_Close' on the new stream will + * *not* call `FT_Stream_Close' on the source stream. None of the stream + * objects will be released to the heap. + * + * The stream implementation is very basic and resets the decompression + * process each time seeking backwards is needed within the stream. + * + * In certain builds of the library, gzip compression recognition is + * automatically handled when calling @FT_New_Face or @FT_Open_Face. + * This means that if no font driver is capable of handling the raw + * compressed file, the library will try to open a gzipped stream from + * it and re-open the face with it. + * + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with zlib support. + */ + FT_EXPORT( FT_Error ) + FT_Stream_OpenGzip( FT_Stream stream, + FT_Stream source ); + + + /************************************************************************ + * + * @function: + * FT_Gzip_Uncompress + * + * @description: + * Decompress a zipped input buffer into an output buffer. This function + * is modeled after zlib's `uncompress' function. + * + * @input: + * memory :: + * A FreeType memory handle. + * + * input :: + * The input buffer. + * + * input_len :: + * The length of the input buffer. + * + * @output: + * output:: + * The output buffer. + * + * @inout: + * output_len :: + * Before calling the function, this is the total size of the output + * buffer, which must be large enough to hold the entire uncompressed + * data (so the size of the uncompressed data must be known in + * advance). After calling the function, `output_len' is the size of + * the used data in `output'. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with zlib support. + * + * @since: + * 2.5.1 + */ + FT_EXPORT( FT_Error ) + FT_Gzip_Uncompress( FT_Memory memory, + FT_Byte* output, + FT_ULong* output_len, + const FT_Byte* input, + FT_ULong input_len ); + + /* */ + + +FT_END_HEADER + +#endif /* FTGZIP_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftimage.h b/freetype/include/freetype2/freetype/ftimage.h new file mode 100644 index 0000000..79ede19 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftimage.h @@ -0,0 +1,1205 @@ +/***************************************************************************/ +/* */ +/* ftimage.h */ +/* */ +/* FreeType glyph image formats and default raster interface */ +/* (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + /*************************************************************************/ + /* */ + /* Note: A `raster' is simply a scan-line converter, used to render */ + /* FT_Outlines into FT_Bitmaps. */ + /* */ + /*************************************************************************/ + + +#ifndef FTIMAGE_H_ +#define FTIMAGE_H_ + + + /* STANDALONE_ is from ftgrays.c */ +#ifndef STANDALONE_ +#include <ft2build.h> +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* basic_types */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Pos */ + /* */ + /* <Description> */ + /* The type FT_Pos is used to store vectorial coordinates. Depending */ + /* on the context, these can represent distances in integer font */ + /* units, or 16.16, or 26.6 fixed-point pixel coordinates. */ + /* */ + typedef signed long FT_Pos; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Vector */ + /* */ + /* <Description> */ + /* A simple structure used to store a 2D vector; coordinates are of */ + /* the FT_Pos type. */ + /* */ + /* <Fields> */ + /* x :: The horizontal coordinate. */ + /* y :: The vertical coordinate. */ + /* */ + typedef struct FT_Vector_ + { + FT_Pos x; + FT_Pos y; + + } FT_Vector; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_BBox */ + /* */ + /* <Description> */ + /* A structure used to hold an outline's bounding box, i.e., the */ + /* coordinates of its extrema in the horizontal and vertical */ + /* directions. */ + /* */ + /* <Fields> */ + /* xMin :: The horizontal minimum (left-most). */ + /* */ + /* yMin :: The vertical minimum (bottom-most). */ + /* */ + /* xMax :: The horizontal maximum (right-most). */ + /* */ + /* yMax :: The vertical maximum (top-most). */ + /* */ + /* <Note> */ + /* The bounding box is specified with the coordinates of the lower */ + /* left and the upper right corner. In PostScript, those values are */ + /* often called (llx,lly) and (urx,ury), respectively. */ + /* */ + /* If `yMin' is negative, this value gives the glyph's descender. */ + /* Otherwise, the glyph doesn't descend below the baseline. */ + /* Similarly, if `ymax' is positive, this value gives the glyph's */ + /* ascender. */ + /* */ + /* `xMin' gives the horizontal distance from the glyph's origin to */ + /* the left edge of the glyph's bounding box. If `xMin' is negative, */ + /* the glyph extends to the left of the origin. */ + /* */ + typedef struct FT_BBox_ + { + FT_Pos xMin, yMin; + FT_Pos xMax, yMax; + + } FT_BBox; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Pixel_Mode */ + /* */ + /* <Description> */ + /* An enumeration type used to describe the format of pixels in a */ + /* given bitmap. Note that additional formats may be added in the */ + /* future. */ + /* */ + /* <Values> */ + /* FT_PIXEL_MODE_NONE :: */ + /* Value~0 is reserved. */ + /* */ + /* FT_PIXEL_MODE_MONO :: */ + /* A monochrome bitmap, using 1~bit per pixel. Note that pixels */ + /* are stored in most-significant order (MSB), which means that */ + /* the left-most pixel in a byte has value 128. */ + /* */ + /* FT_PIXEL_MODE_GRAY :: */ + /* An 8-bit bitmap, generally used to represent anti-aliased glyph */ + /* images. Each pixel is stored in one byte. Note that the number */ + /* of `gray' levels is stored in the `num_grays' field of the */ + /* @FT_Bitmap structure (it generally is 256). */ + /* */ + /* FT_PIXEL_MODE_GRAY2 :: */ + /* A 2-bit per pixel bitmap, used to represent embedded */ + /* anti-aliased bitmaps in font files according to the OpenType */ + /* specification. We haven't found a single font using this */ + /* format, however. */ + /* */ + /* FT_PIXEL_MODE_GRAY4 :: */ + /* A 4-bit per pixel bitmap, representing embedded anti-aliased */ + /* bitmaps in font files according to the OpenType specification. */ + /* We haven't found a single font using this format, however. */ + /* */ + /* FT_PIXEL_MODE_LCD :: */ + /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */ + /* used for display on LCD displays; the bitmap is three times */ + /* wider than the original glyph image. See also */ + /* @FT_RENDER_MODE_LCD. */ + /* */ + /* FT_PIXEL_MODE_LCD_V :: */ + /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */ + /* used for display on rotated LCD displays; the bitmap is three */ + /* times taller than the original glyph image. See also */ + /* @FT_RENDER_MODE_LCD_V. */ + /* */ + /* FT_PIXEL_MODE_BGRA :: */ + /* [Since 2.5] An image with four 8-bit channels per pixel, */ + /* representing a color image (such as emoticons) with alpha */ + /* channel. For each pixel, the format is BGRA, which means, the */ + /* blue channel comes first in memory. The color channels are */ + /* pre-multiplied and in the sRGB colorspace. For example, full */ + /* red at half-translucent opacity will be represented as */ + /* `00,00,80,80', not `00,00,FF,80'. See also @FT_LOAD_COLOR. */ + /* */ + typedef enum FT_Pixel_Mode_ + { + FT_PIXEL_MODE_NONE = 0, + FT_PIXEL_MODE_MONO, + FT_PIXEL_MODE_GRAY, + FT_PIXEL_MODE_GRAY2, + FT_PIXEL_MODE_GRAY4, + FT_PIXEL_MODE_LCD, + FT_PIXEL_MODE_LCD_V, + FT_PIXEL_MODE_BGRA, + + FT_PIXEL_MODE_MAX /* do not remove */ + + } FT_Pixel_Mode; + + + /* these constants are deprecated; use the corresponding `FT_Pixel_Mode' */ + /* values instead. */ +#define ft_pixel_mode_none FT_PIXEL_MODE_NONE +#define ft_pixel_mode_mono FT_PIXEL_MODE_MONO +#define ft_pixel_mode_grays FT_PIXEL_MODE_GRAY +#define ft_pixel_mode_pal2 FT_PIXEL_MODE_GRAY2 +#define ft_pixel_mode_pal4 FT_PIXEL_MODE_GRAY4 + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Bitmap */ + /* */ + /* <Description> */ + /* A structure used to describe a bitmap or pixmap to the raster. */ + /* Note that we now manage pixmaps of various depths through the */ + /* `pixel_mode' field. */ + /* */ + /* <Fields> */ + /* rows :: The number of bitmap rows. */ + /* */ + /* width :: The number of pixels in bitmap row. */ + /* */ + /* pitch :: The pitch's absolute value is the number of bytes */ + /* taken by one bitmap row, including padding. */ + /* However, the pitch is positive when the bitmap has */ + /* a `down' flow, and negative when it has an `up' */ + /* flow. In all cases, the pitch is an offset to add */ + /* to a bitmap pointer in order to go down one row. */ + /* */ + /* Note that `padding' means the alignment of a */ + /* bitmap to a byte border, and FreeType functions */ + /* normally align to the smallest possible integer */ + /* value. */ + /* */ + /* For the B/W rasterizer, `pitch' is always an even */ + /* number. */ + /* */ + /* To change the pitch of a bitmap (say, to make it a */ + /* multiple of 4), use @FT_Bitmap_Convert. */ + /* Alternatively, you might use callback functions to */ + /* directly render to the application's surface; see */ + /* the file `example2.cpp' in the tutorial for a */ + /* demonstration. */ + /* */ + /* buffer :: A typeless pointer to the bitmap buffer. This */ + /* value should be aligned on 32-bit boundaries in */ + /* most cases. */ + /* */ + /* num_grays :: This field is only used with */ + /* @FT_PIXEL_MODE_GRAY; it gives the number of gray */ + /* levels used in the bitmap. */ + /* */ + /* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. */ + /* See @FT_Pixel_Mode for possible values. */ + /* */ + /* palette_mode :: This field is intended for paletted pixel modes; */ + /* it indicates how the palette is stored. Not */ + /* used currently. */ + /* */ + /* palette :: A typeless pointer to the bitmap palette; this */ + /* field is intended for paletted pixel modes. Not */ + /* used currently. */ + /* */ + typedef struct FT_Bitmap_ + { + unsigned int rows; + unsigned int width; + int pitch; + unsigned char* buffer; + unsigned short num_grays; + unsigned char pixel_mode; + unsigned char palette_mode; + void* palette; + + } FT_Bitmap; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* outline_processing */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Outline */ + /* */ + /* <Description> */ + /* This structure is used to describe an outline to the scan-line */ + /* converter. */ + /* */ + /* <Fields> */ + /* n_contours :: The number of contours in the outline. */ + /* */ + /* n_points :: The number of points in the outline. */ + /* */ + /* points :: A pointer to an array of `n_points' @FT_Vector */ + /* elements, giving the outline's point coordinates. */ + /* */ + /* tags :: A pointer to an array of `n_points' chars, giving */ + /* each outline point's type. */ + /* */ + /* If bit~0 is unset, the point is `off' the curve, */ + /* i.e., a Bezier control point, while it is `on' if */ + /* set. */ + /* */ + /* Bit~1 is meaningful for `off' points only. If set, */ + /* it indicates a third-order Bezier arc control point; */ + /* and a second-order control point if unset. */ + /* */ + /* If bit~2 is set, bits 5-7 contain the drop-out mode */ + /* (as defined in the OpenType specification; the value */ + /* is the same as the argument to the SCANMODE */ + /* instruction). */ + /* */ + /* Bits 3 and~4 are reserved for internal purposes. */ + /* */ + /* contours :: An array of `n_contours' shorts, giving the end */ + /* point of each contour within the outline. For */ + /* example, the first contour is defined by the points */ + /* `0' to `contours[0]', the second one is defined by */ + /* the points `contours[0]+1' to `contours[1]', etc. */ + /* */ + /* flags :: A set of bit flags used to characterize the outline */ + /* and give hints to the scan-converter and hinter on */ + /* how to convert/grid-fit it. See @FT_OUTLINE_XXX. */ + /* */ + /* <Note> */ + /* The B/W rasterizer only checks bit~2 in the `tags' array for the */ + /* first point of each contour. The drop-out mode as given with */ + /* @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and */ + /* @FT_OUTLINE_INCLUDE_STUBS in `flags' is then overridden. */ + /* */ + typedef struct FT_Outline_ + { + short n_contours; /* number of contours in glyph */ + short n_points; /* number of points in the glyph */ + + FT_Vector* points; /* the outline's points */ + char* tags; /* the points flags */ + short* contours; /* the contour end points */ + + int flags; /* outline masks */ + + } FT_Outline; + + /* */ + + /* Following limits must be consistent with */ + /* FT_Outline.{n_contours,n_points} */ +#define FT_OUTLINE_CONTOURS_MAX SHRT_MAX +#define FT_OUTLINE_POINTS_MAX SHRT_MAX + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_OUTLINE_XXX */ + /* */ + /* <Description> */ + /* A list of bit-field constants use for the flags in an outline's */ + /* `flags' field. */ + /* */ + /* <Values> */ + /* FT_OUTLINE_NONE :: */ + /* Value~0 is reserved. */ + /* */ + /* FT_OUTLINE_OWNER :: */ + /* If set, this flag indicates that the outline's field arrays */ + /* (i.e., `points', `flags', and `contours') are `owned' by the */ + /* outline object, and should thus be freed when it is destroyed. */ + /* */ + /* FT_OUTLINE_EVEN_ODD_FILL :: */ + /* By default, outlines are filled using the non-zero winding rule. */ + /* If set to 1, the outline will be filled using the even-odd fill */ + /* rule (only works with the smooth rasterizer). */ + /* */ + /* FT_OUTLINE_REVERSE_FILL :: */ + /* By default, outside contours of an outline are oriented in */ + /* clock-wise direction, as defined in the TrueType specification. */ + /* This flag is set if the outline uses the opposite direction */ + /* (typically for Type~1 fonts). This flag is ignored by the scan */ + /* converter. */ + /* */ + /* FT_OUTLINE_IGNORE_DROPOUTS :: */ + /* By default, the scan converter will try to detect drop-outs in */ + /* an outline and correct the glyph bitmap to ensure consistent */ + /* shape continuity. If set, this flag hints the scan-line */ + /* converter to ignore such cases. See below for more information. */ + /* */ + /* FT_OUTLINE_SMART_DROPOUTS :: */ + /* Select smart dropout control. If unset, use simple dropout */ + /* control. Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See */ + /* below for more information. */ + /* */ + /* FT_OUTLINE_INCLUDE_STUBS :: */ + /* If set, turn pixels on for `stubs', otherwise exclude them. */ + /* Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for */ + /* more information. */ + /* */ + /* FT_OUTLINE_HIGH_PRECISION :: */ + /* This flag indicates that the scan-line converter should try to */ + /* convert this outline to bitmaps with the highest possible */ + /* quality. It is typically set for small character sizes. Note */ + /* that this is only a hint that might be completely ignored by a */ + /* given scan-converter. */ + /* */ + /* FT_OUTLINE_SINGLE_PASS :: */ + /* This flag is set to force a given scan-converter to only use a */ + /* single pass over the outline to render a bitmap glyph image. */ + /* Normally, it is set for very large character sizes. It is only */ + /* a hint that might be completely ignored by a given */ + /* scan-converter. */ + /* */ + /* <Note> */ + /* The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, */ + /* and @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth */ + /* rasterizer. */ + /* */ + /* There exists a second mechanism to pass the drop-out mode to the */ + /* B/W rasterizer; see the `tags' field in @FT_Outline. */ + /* */ + /* Please refer to the description of the `SCANTYPE' instruction in */ + /* the OpenType specification (in file `ttinst1.doc') how simple */ + /* drop-outs, smart drop-outs, and stubs are defined. */ + /* */ +#define FT_OUTLINE_NONE 0x0 +#define FT_OUTLINE_OWNER 0x1 +#define FT_OUTLINE_EVEN_ODD_FILL 0x2 +#define FT_OUTLINE_REVERSE_FILL 0x4 +#define FT_OUTLINE_IGNORE_DROPOUTS 0x8 +#define FT_OUTLINE_SMART_DROPOUTS 0x10 +#define FT_OUTLINE_INCLUDE_STUBS 0x20 + +#define FT_OUTLINE_HIGH_PRECISION 0x100 +#define FT_OUTLINE_SINGLE_PASS 0x200 + + + /* these constants are deprecated; use the corresponding */ + /* `FT_OUTLINE_XXX' values instead */ +#define ft_outline_none FT_OUTLINE_NONE +#define ft_outline_owner FT_OUTLINE_OWNER +#define ft_outline_even_odd_fill FT_OUTLINE_EVEN_ODD_FILL +#define ft_outline_reverse_fill FT_OUTLINE_REVERSE_FILL +#define ft_outline_ignore_dropouts FT_OUTLINE_IGNORE_DROPOUTS +#define ft_outline_high_precision FT_OUTLINE_HIGH_PRECISION +#define ft_outline_single_pass FT_OUTLINE_SINGLE_PASS + + /* */ + +#define FT_CURVE_TAG( flag ) ( flag & 3 ) + +#define FT_CURVE_TAG_ON 1 +#define FT_CURVE_TAG_CONIC 0 +#define FT_CURVE_TAG_CUBIC 2 + +#define FT_CURVE_TAG_HAS_SCANMODE 4 + +#define FT_CURVE_TAG_TOUCH_X 8 /* reserved for the TrueType hinter */ +#define FT_CURVE_TAG_TOUCH_Y 16 /* reserved for the TrueType hinter */ + +#define FT_CURVE_TAG_TOUCH_BOTH ( FT_CURVE_TAG_TOUCH_X | \ + FT_CURVE_TAG_TOUCH_Y ) + +#define FT_Curve_Tag_On FT_CURVE_TAG_ON +#define FT_Curve_Tag_Conic FT_CURVE_TAG_CONIC +#define FT_Curve_Tag_Cubic FT_CURVE_TAG_CUBIC +#define FT_Curve_Tag_Touch_X FT_CURVE_TAG_TOUCH_X +#define FT_Curve_Tag_Touch_Y FT_CURVE_TAG_TOUCH_Y + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_MoveToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `move */ + /* to' function during outline walking/decomposition. */ + /* */ + /* A `move to' is emitted to start a new contour in an outline. */ + /* */ + /* <Input> */ + /* to :: A pointer to the target point of the `move to'. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of the */ + /* decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_MoveToFunc)( const FT_Vector* to, + void* user ); + +#define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_LineToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `line */ + /* to' function during outline walking/decomposition. */ + /* */ + /* A `line to' is emitted to indicate a segment in the outline. */ + /* */ + /* <Input> */ + /* to :: A pointer to the target point of the `line to'. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of the */ + /* decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_LineToFunc)( const FT_Vector* to, + void* user ); + +#define FT_Outline_LineTo_Func FT_Outline_LineToFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_ConicToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `conic */ + /* to' function during outline walking or decomposition. */ + /* */ + /* A `conic to' is emitted to indicate a second-order Bezier arc in */ + /* the outline. */ + /* */ + /* <Input> */ + /* control :: An intermediate control point between the last position */ + /* and the new target in `to'. */ + /* */ + /* to :: A pointer to the target end point of the conic arc. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of */ + /* the decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_ConicToFunc)( const FT_Vector* control, + const FT_Vector* to, + void* user ); + +#define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Outline_CubicToFunc */ + /* */ + /* <Description> */ + /* A function pointer type used to describe the signature of a `cubic */ + /* to' function during outline walking or decomposition. */ + /* */ + /* A `cubic to' is emitted to indicate a third-order Bezier arc. */ + /* */ + /* <Input> */ + /* control1 :: A pointer to the first Bezier control point. */ + /* */ + /* control2 :: A pointer to the second Bezier control point. */ + /* */ + /* to :: A pointer to the target end point. */ + /* */ + /* user :: A typeless pointer, which is passed from the caller of */ + /* the decomposition function. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + typedef int + (*FT_Outline_CubicToFunc)( const FT_Vector* control1, + const FT_Vector* control2, + const FT_Vector* to, + void* user ); + +#define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Outline_Funcs */ + /* */ + /* <Description> */ + /* A structure to hold various function pointers used during outline */ + /* decomposition in order to emit segments, conic, and cubic Beziers. */ + /* */ + /* <Fields> */ + /* move_to :: The `move to' emitter. */ + /* */ + /* line_to :: The segment emitter. */ + /* */ + /* conic_to :: The second-order Bezier arc emitter. */ + /* */ + /* cubic_to :: The third-order Bezier arc emitter. */ + /* */ + /* shift :: The shift that is applied to coordinates before they */ + /* are sent to the emitter. */ + /* */ + /* delta :: The delta that is applied to coordinates before they */ + /* are sent to the emitter, but after the shift. */ + /* */ + /* <Note> */ + /* The point coordinates sent to the emitters are the transformed */ + /* version of the original coordinates (this is important for high */ + /* accuracy during scan-conversion). The transformation is simple: */ + /* */ + /* { */ + /* x' = (x << shift) - delta */ + /* y' = (y << shift) - delta */ + /* } */ + /* */ + /* Set the values of `shift' and `delta' to~0 to get the original */ + /* point coordinates. */ + /* */ + typedef struct FT_Outline_Funcs_ + { + FT_Outline_MoveToFunc move_to; + FT_Outline_LineToFunc line_to; + FT_Outline_ConicToFunc conic_to; + FT_Outline_CubicToFunc cubic_to; + + int shift; + FT_Pos delta; + + } FT_Outline_Funcs; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* basic_types */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_IMAGE_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags to an unsigned long type. */ + /* */ + /* <Note> */ + /* Since many 16-bit compilers don't like 32-bit enumerations, you */ + /* should redefine this macro in case of problems to something like */ + /* this: */ + /* */ + /* { */ + /* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value */ + /* } */ + /* */ + /* to get a simple enumeration without assigning special numbers. */ + /* */ +#ifndef FT_IMAGE_TAG +#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ + value = ( ( (unsigned long)_x1 << 24 ) | \ + ( (unsigned long)_x2 << 16 ) | \ + ( (unsigned long)_x3 << 8 ) | \ + (unsigned long)_x4 ) +#endif /* FT_IMAGE_TAG */ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Glyph_Format */ + /* */ + /* <Description> */ + /* An enumeration type used to describe the format of a given glyph */ + /* image. Note that this version of FreeType only supports two image */ + /* formats, even though future font drivers will be able to register */ + /* their own format. */ + /* */ + /* <Values> */ + /* FT_GLYPH_FORMAT_NONE :: */ + /* The value~0 is reserved. */ + /* */ + /* FT_GLYPH_FORMAT_COMPOSITE :: */ + /* The glyph image is a composite of several other images. This */ + /* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to */ + /* report compound glyphs (like accented characters). */ + /* */ + /* FT_GLYPH_FORMAT_BITMAP :: */ + /* The glyph image is a bitmap, and can be described as an */ + /* @FT_Bitmap. You generally need to access the `bitmap' field of */ + /* the @FT_GlyphSlotRec structure to read it. */ + /* */ + /* FT_GLYPH_FORMAT_OUTLINE :: */ + /* The glyph image is a vectorial outline made of line segments */ + /* and Bezier arcs; it can be described as an @FT_Outline; you */ + /* generally want to access the `outline' field of the */ + /* @FT_GlyphSlotRec structure to read it. */ + /* */ + /* FT_GLYPH_FORMAT_PLOTTER :: */ + /* The glyph image is a vectorial path with no inside and outside */ + /* contours. Some Type~1 fonts, like those in the Hershey family, */ + /* contain glyphs in this format. These are described as */ + /* @FT_Outline, but FreeType isn't currently capable of rendering */ + /* them correctly. */ + /* */ + typedef enum FT_Glyph_Format_ + { + FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ), + + FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ), + FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ), + FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ), + FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' ) + + } FT_Glyph_Format; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Glyph_Format' values instead. */ +#define ft_glyph_format_none FT_GLYPH_FORMAT_NONE +#define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE +#define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP +#define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE +#define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** R A S T E R D E F I N I T I O N S *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* A raster is a scan converter, in charge of rendering an outline into */ + /* a bitmap. This section contains the public API for rasters. */ + /* */ + /* Note that in FreeType 2, all rasters are now encapsulated within */ + /* specific modules called `renderers'. See `ftrender.h' for more */ + /* details on renderers. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* raster */ + /* */ + /* <Title> */ + /* Scanline Converter */ + /* */ + /* <Abstract> */ + /* How vectorial outlines are converted into bitmaps and pixmaps. */ + /* */ + /* <Description> */ + /* This section contains technical definitions. */ + /* */ + /* <Order> */ + /* FT_Raster */ + /* FT_Span */ + /* FT_SpanFunc */ + /* */ + /* FT_Raster_Params */ + /* FT_RASTER_FLAG_XXX */ + /* */ + /* FT_Raster_NewFunc */ + /* FT_Raster_DoneFunc */ + /* FT_Raster_ResetFunc */ + /* FT_Raster_SetModeFunc */ + /* FT_Raster_RenderFunc */ + /* FT_Raster_Funcs */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Raster */ + /* */ + /* <Description> */ + /* An opaque handle (pointer) to a raster object. Each object can be */ + /* used independently to convert an outline into a bitmap or pixmap. */ + /* */ + typedef struct FT_RasterRec_* FT_Raster; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Span */ + /* */ + /* <Description> */ + /* A structure used to model a single span of gray pixels when */ + /* rendering an anti-aliased bitmap. */ + /* */ + /* <Fields> */ + /* x :: The span's horizontal start position. */ + /* */ + /* len :: The span's length in pixels. */ + /* */ + /* coverage :: The span color/coverage, ranging from 0 (background) */ + /* to 255 (foreground). */ + /* */ + /* <Note> */ + /* This structure is used by the span drawing callback type named */ + /* @FT_SpanFunc that takes the y~coordinate of the span as a */ + /* parameter. */ + /* */ + /* The coverage value is always between 0 and 255. If you want less */ + /* gray values, the callback function has to reduce them. */ + /* */ + typedef struct FT_Span_ + { + short x; + unsigned short len; + unsigned char coverage; + + } FT_Span; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_SpanFunc */ + /* */ + /* <Description> */ + /* A function used as a call-back by the anti-aliased renderer in */ + /* order to let client applications draw themselves the gray pixel */ + /* spans on each scan line. */ + /* */ + /* <Input> */ + /* y :: The scanline's y~coordinate. */ + /* */ + /* count :: The number of spans to draw on this scanline. */ + /* */ + /* spans :: A table of `count' spans to draw on the scanline. */ + /* */ + /* user :: User-supplied data that is passed to the callback. */ + /* */ + /* <Note> */ + /* This callback allows client applications to directly render the */ + /* gray spans of the anti-aliased bitmap to any kind of surfaces. */ + /* */ + /* This can be used to write anti-aliased outlines directly to a */ + /* given background bitmap, and even perform translucency. */ + /* */ + typedef void + (*FT_SpanFunc)( int y, + int count, + const FT_Span* spans, + void* user ); + +#define FT_Raster_Span_Func FT_SpanFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_BitTest_Func */ + /* */ + /* <Description> */ + /* Deprecated, unimplemented. */ + /* */ + typedef int + (*FT_Raster_BitTest_Func)( int y, + int x, + void* user ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_BitSet_Func */ + /* */ + /* <Description> */ + /* Deprecated, unimplemented. */ + /* */ + typedef void + (*FT_Raster_BitSet_Func)( int y, + int x, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_RASTER_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flag constants as used in the `flags' field of a */ + /* @FT_Raster_Params structure. */ + /* */ + /* <Values> */ + /* FT_RASTER_FLAG_DEFAULT :: This value is 0. */ + /* */ + /* FT_RASTER_FLAG_AA :: This flag is set to indicate that an */ + /* anti-aliased glyph image should be */ + /* generated. Otherwise, it will be */ + /* monochrome (1-bit). */ + /* */ + /* FT_RASTER_FLAG_DIRECT :: This flag is set to indicate direct */ + /* rendering. In this mode, client */ + /* applications must provide their own span */ + /* callback. This lets them directly */ + /* draw or compose over an existing bitmap. */ + /* If this bit is not set, the target */ + /* pixmap's buffer _must_ be zeroed before */ + /* rendering. */ + /* */ + /* Direct rendering is only possible with */ + /* anti-aliased glyphs. */ + /* */ + /* FT_RASTER_FLAG_CLIP :: This flag is only used in direct */ + /* rendering mode. If set, the output will */ + /* be clipped to a box specified in the */ + /* `clip_box' field of the */ + /* @FT_Raster_Params structure. */ + /* */ + /* Note that by default, the glyph bitmap */ + /* is clipped to the target pixmap, except */ + /* in direct rendering mode where all spans */ + /* are generated if no clipping box is set. */ + /* */ +#define FT_RASTER_FLAG_DEFAULT 0x0 +#define FT_RASTER_FLAG_AA 0x1 +#define FT_RASTER_FLAG_DIRECT 0x2 +#define FT_RASTER_FLAG_CLIP 0x4 + + /* these constants are deprecated; use the corresponding */ + /* `FT_RASTER_FLAG_XXX' values instead */ +#define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT +#define ft_raster_flag_aa FT_RASTER_FLAG_AA +#define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT +#define ft_raster_flag_clip FT_RASTER_FLAG_CLIP + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Raster_Params */ + /* */ + /* <Description> */ + /* A structure to hold the arguments used by a raster's render */ + /* function. */ + /* */ + /* <Fields> */ + /* target :: The target bitmap. */ + /* */ + /* source :: A pointer to the source glyph image (e.g., an */ + /* @FT_Outline). */ + /* */ + /* flags :: The rendering flags. */ + /* */ + /* gray_spans :: The gray span drawing callback. */ + /* */ + /* black_spans :: Unused. */ + /* */ + /* bit_test :: Unused. */ + /* */ + /* bit_set :: Unused. */ + /* */ + /* user :: User-supplied data that is passed to each drawing */ + /* callback. */ + /* */ + /* clip_box :: An optional clipping box. It is only used in */ + /* direct rendering mode. Note that coordinates here */ + /* should be expressed in _integer_ pixels (and not in */ + /* 26.6 fixed-point units). */ + /* */ + /* <Note> */ + /* An anti-aliased glyph bitmap is drawn if the @FT_RASTER_FLAG_AA */ + /* bit flag is set in the `flags' field, otherwise a monochrome */ + /* bitmap is generated. */ + /* */ + /* If the @FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the */ + /* raster will call the `gray_spans' callback to draw gray pixel */ + /* spans. This allows direct composition over a pre-existing bitmap */ + /* through user-provided callbacks to perform the span drawing and */ + /* composition. Not supported by the monochrome rasterizer. */ + /* */ + typedef struct FT_Raster_Params_ + { + const FT_Bitmap* target; + const void* source; + int flags; + FT_SpanFunc gray_spans; + FT_SpanFunc black_spans; /* unused */ + FT_Raster_BitTest_Func bit_test; /* unused */ + FT_Raster_BitSet_Func bit_set; /* unused */ + void* user; + FT_BBox clip_box; + + } FT_Raster_Params; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_NewFunc */ + /* */ + /* <Description> */ + /* A function used to create a new raster object. */ + /* */ + /* <Input> */ + /* memory :: A handle to the memory allocator. */ + /* */ + /* <Output> */ + /* raster :: A handle to the new raster object. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `memory' parameter is a typeless pointer in order to avoid */ + /* un-wanted dependencies on the rest of the FreeType code. In */ + /* practice, it is an @FT_Memory object, i.e., a handle to the */ + /* standard FreeType memory allocator. However, this field can be */ + /* completely ignored by a given raster implementation. */ + /* */ + typedef int + (*FT_Raster_NewFunc)( void* memory, + FT_Raster* raster ); + +#define FT_Raster_New_Func FT_Raster_NewFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_DoneFunc */ + /* */ + /* <Description> */ + /* A function used to destroy a given raster object. */ + /* */ + /* <Input> */ + /* raster :: A handle to the raster object. */ + /* */ + typedef void + (*FT_Raster_DoneFunc)( FT_Raster raster ); + +#define FT_Raster_Done_Func FT_Raster_DoneFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_ResetFunc */ + /* */ + /* <Description> */ + /* FreeType used to provide an area of memory called the `render */ + /* pool' available to all registered rasterizers. This was not */ + /* thread safe, however, and now FreeType never allocates this pool. */ + /* */ + /* This function is called after a new raster object is created. */ + /* */ + /* <Input> */ + /* raster :: A handle to the new raster object. */ + /* */ + /* pool_base :: Previously, the address in memory of the render pool. */ + /* Set this to NULL. */ + /* */ + /* pool_size :: Previously, the size in bytes of the render pool. */ + /* Set this to 0. */ + /* */ + /* <Note> */ + /* Rasterizers should rely on dynamic or stack allocation if they */ + /* want to (a handle to the memory allocator is passed to the */ + /* rasterizer constructor). */ + /* */ + typedef void + (*FT_Raster_ResetFunc)( FT_Raster raster, + unsigned char* pool_base, + unsigned long pool_size ); + +#define FT_Raster_Reset_Func FT_Raster_ResetFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_SetModeFunc */ + /* */ + /* <Description> */ + /* This function is a generic facility to change modes or attributes */ + /* in a given raster. This can be used for debugging purposes, or */ + /* simply to allow implementation-specific `features' in a given */ + /* raster module. */ + /* */ + /* <Input> */ + /* raster :: A handle to the new raster object. */ + /* */ + /* mode :: A 4-byte tag used to name the mode or property. */ + /* */ + /* args :: A pointer to the new mode/property to use. */ + /* */ + typedef int + (*FT_Raster_SetModeFunc)( FT_Raster raster, + unsigned long mode, + void* args ); + +#define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Raster_RenderFunc */ + /* */ + /* <Description> */ + /* Invoke a given raster to scan-convert a given glyph image into a */ + /* target bitmap. */ + /* */ + /* <Input> */ + /* raster :: A handle to the raster object. */ + /* */ + /* params :: A pointer to an @FT_Raster_Params structure used to */ + /* store the rendering parameters. */ + /* */ + /* <Return> */ + /* Error code. 0~means success. */ + /* */ + /* <Note> */ + /* The exact format of the source image depends on the raster's glyph */ + /* format defined in its @FT_Raster_Funcs structure. It can be an */ + /* @FT_Outline or anything else in order to support a large array of */ + /* glyph formats. */ + /* */ + /* Note also that the render function can fail and return a */ + /* `FT_Err_Unimplemented_Feature' error code if the raster used does */ + /* not support direct composition. */ + /* */ + /* XXX: For now, the standard raster doesn't support direct */ + /* composition but this should change for the final release (see */ + /* the files `demos/src/ftgrays.c' and `demos/src/ftgrays2.c' */ + /* for examples of distinct implementations that support direct */ + /* composition). */ + /* */ + typedef int + (*FT_Raster_RenderFunc)( FT_Raster raster, + const FT_Raster_Params* params ); + +#define FT_Raster_Render_Func FT_Raster_RenderFunc + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Raster_Funcs */ + /* */ + /* <Description> */ + /* A structure used to describe a given raster class to the library. */ + /* */ + /* <Fields> */ + /* glyph_format :: The supported glyph format for this raster. */ + /* */ + /* raster_new :: The raster constructor. */ + /* */ + /* raster_reset :: Used to reset the render pool within the raster. */ + /* */ + /* raster_render :: A function to render a glyph into a given bitmap. */ + /* */ + /* raster_done :: The raster destructor. */ + /* */ + typedef struct FT_Raster_Funcs_ + { + FT_Glyph_Format glyph_format; + + FT_Raster_NewFunc raster_new; + FT_Raster_ResetFunc raster_reset; + FT_Raster_SetModeFunc raster_set_mode; + FT_Raster_RenderFunc raster_render; + FT_Raster_DoneFunc raster_done; + + } FT_Raster_Funcs; + + /* */ + + +FT_END_HEADER + +#endif /* FTIMAGE_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/freetype/include/freetype2/freetype/ftincrem.h b/freetype/include/freetype2/freetype/ftincrem.h new file mode 100644 index 0000000..44619f9 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftincrem.h @@ -0,0 +1,343 @@ +/***************************************************************************/ +/* */ +/* ftincrem.h */ +/* */ +/* FreeType incremental loading (specification). */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTINCREM_H_ +#define FTINCREM_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H +#include FT_PARAMETER_TAGS_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************** + * + * @section: + * incremental + * + * @title: + * Incremental Loading + * + * @abstract: + * Custom Glyph Loading. + * + * @description: + * This section contains various functions used to perform so-called + * `incremental' glyph loading. This is a mode where all glyphs loaded + * from a given @FT_Face are provided by the client application. + * + * Apart from that, all other tables are loaded normally from the font + * file. This mode is useful when FreeType is used within another + * engine, e.g., a PostScript Imaging Processor. + * + * To enable this mode, you must use @FT_Open_Face, passing an + * @FT_Parameter with the @FT_PARAM_TAG_INCREMENTAL tag and an + * @FT_Incremental_Interface value. See the comments for + * @FT_Incremental_InterfaceRec for an example. + * + */ + + + /*************************************************************************** + * + * @type: + * FT_Incremental + * + * @description: + * An opaque type describing a user-provided object used to implement + * `incremental' glyph loading within FreeType. This is used to support + * embedded fonts in certain environments (e.g., PostScript interpreters), + * where the glyph data isn't in the font file, or must be overridden by + * different values. + * + * @note: + * It is up to client applications to create and implement @FT_Incremental + * objects, as long as they provide implementations for the methods + * @FT_Incremental_GetGlyphDataFunc, @FT_Incremental_FreeGlyphDataFunc + * and @FT_Incremental_GetGlyphMetricsFunc. + * + * See the description of @FT_Incremental_InterfaceRec to understand how + * to use incremental objects with FreeType. + * + */ + typedef struct FT_IncrementalRec_* FT_Incremental; + + + /*************************************************************************** + * + * @struct: + * FT_Incremental_MetricsRec + * + * @description: + * A small structure used to contain the basic glyph metrics returned + * by the @FT_Incremental_GetGlyphMetricsFunc method. + * + * @fields: + * bearing_x :: + * Left bearing, in font units. + * + * bearing_y :: + * Top bearing, in font units. + * + * advance :: + * Horizontal component of glyph advance, in font units. + * + * advance_v :: + * Vertical component of glyph advance, in font units. + * + * @note: + * These correspond to horizontal or vertical metrics depending on the + * value of the `vertical' argument to the function + * @FT_Incremental_GetGlyphMetricsFunc. + * + */ + typedef struct FT_Incremental_MetricsRec_ + { + FT_Long bearing_x; + FT_Long bearing_y; + FT_Long advance; + FT_Long advance_v; /* since 2.3.12 */ + + } FT_Incremental_MetricsRec; + + + /*************************************************************************** + * + * @struct: + * FT_Incremental_Metrics + * + * @description: + * A handle to an @FT_Incremental_MetricsRec structure. + * + */ + typedef struct FT_Incremental_MetricsRec_* FT_Incremental_Metrics; + + + /*************************************************************************** + * + * @type: + * FT_Incremental_GetGlyphDataFunc + * + * @description: + * A function called by FreeType to access a given glyph's data bytes + * during @FT_Load_Glyph or @FT_Load_Char if incremental loading is + * enabled. + * + * Note that the format of the glyph's data bytes depends on the font + * file format. For TrueType, it must correspond to the raw bytes within + * the `glyf' table. For PostScript formats, it must correspond to the + * *unencrypted* charstring bytes, without any `lenIV' header. It is + * undefined for any other format. + * + * @input: + * incremental :: + * Handle to an opaque @FT_Incremental handle provided by the client + * application. + * + * glyph_index :: + * Index of relevant glyph. + * + * @output: + * adata :: + * A structure describing the returned glyph data bytes (which will be + * accessed as a read-only byte block). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If this function returns successfully the method + * @FT_Incremental_FreeGlyphDataFunc will be called later to release + * the data bytes. + * + * Nested calls to @FT_Incremental_GetGlyphDataFunc can happen for + * compound glyphs. + * + */ + typedef FT_Error + (*FT_Incremental_GetGlyphDataFunc)( FT_Incremental incremental, + FT_UInt glyph_index, + FT_Data* adata ); + + + /*************************************************************************** + * + * @type: + * FT_Incremental_FreeGlyphDataFunc + * + * @description: + * A function used to release the glyph data bytes returned by a + * successful call to @FT_Incremental_GetGlyphDataFunc. + * + * @input: + * incremental :: + * A handle to an opaque @FT_Incremental handle provided by the client + * application. + * + * data :: + * A structure describing the glyph data bytes (which will be accessed + * as a read-only byte block). + * + */ + typedef void + (*FT_Incremental_FreeGlyphDataFunc)( FT_Incremental incremental, + FT_Data* data ); + + + /*************************************************************************** + * + * @type: + * FT_Incremental_GetGlyphMetricsFunc + * + * @description: + * A function used to retrieve the basic metrics of a given glyph index + * before accessing its data. This is necessary because, in certain + * formats like TrueType, the metrics are stored in a different place from + * the glyph images proper. + * + * @input: + * incremental :: + * A handle to an opaque @FT_Incremental handle provided by the client + * application. + * + * glyph_index :: + * Index of relevant glyph. + * + * vertical :: + * If true, return vertical metrics. + * + * ametrics :: + * This parameter is used for both input and output. + * The original glyph metrics, if any, in font units. If metrics are + * not available all the values must be set to zero. + * + * @output: + * ametrics :: + * The replacement glyph metrics in font units. + * + */ + typedef FT_Error + (*FT_Incremental_GetGlyphMetricsFunc) + ( FT_Incremental incremental, + FT_UInt glyph_index, + FT_Bool vertical, + FT_Incremental_MetricsRec *ametrics ); + + + /************************************************************************** + * + * @struct: + * FT_Incremental_FuncsRec + * + * @description: + * A table of functions for accessing fonts that load data + * incrementally. Used in @FT_Incremental_InterfaceRec. + * + * @fields: + * get_glyph_data :: + * The function to get glyph data. Must not be null. + * + * free_glyph_data :: + * The function to release glyph data. Must not be null. + * + * get_glyph_metrics :: + * The function to get glyph metrics. May be null if the font does + * not provide overriding glyph metrics. + * + */ + typedef struct FT_Incremental_FuncsRec_ + { + FT_Incremental_GetGlyphDataFunc get_glyph_data; + FT_Incremental_FreeGlyphDataFunc free_glyph_data; + FT_Incremental_GetGlyphMetricsFunc get_glyph_metrics; + + } FT_Incremental_FuncsRec; + + + /*************************************************************************** + * + * @struct: + * FT_Incremental_InterfaceRec + * + * @description: + * A structure to be used with @FT_Open_Face to indicate that the user + * wants to support incremental glyph loading. You should use it with + * @FT_PARAM_TAG_INCREMENTAL as in the following example: + * + * { + * FT_Incremental_InterfaceRec inc_int; + * FT_Parameter parameter; + * FT_Open_Args open_args; + * + * + * // set up incremental descriptor + * inc_int.funcs = my_funcs; + * inc_int.object = my_object; + * + * // set up optional parameter + * parameter.tag = FT_PARAM_TAG_INCREMENTAL; + * parameter.data = &inc_int; + * + * // set up FT_Open_Args structure + * open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS; + * open_args.pathname = my_font_pathname; + * open_args.num_params = 1; + * open_args.params = ¶meter; // we use one optional argument + * + * // open the font + * error = FT_Open_Face( library, &open_args, index, &face ); + * ... + * } + * + */ + typedef struct FT_Incremental_InterfaceRec_ + { + const FT_Incremental_FuncsRec* funcs; + FT_Incremental object; + + } FT_Incremental_InterfaceRec; + + + /*************************************************************************** + * + * @type: + * FT_Incremental_Interface + * + * @description: + * A pointer to an @FT_Incremental_InterfaceRec structure. + * + */ + typedef FT_Incremental_InterfaceRec* FT_Incremental_Interface; + + + /* */ + + +FT_END_HEADER + +#endif /* FTINCREM_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftlcdfil.h b/freetype/include/freetype2/freetype/ftlcdfil.h new file mode 100644 index 0000000..2a27196 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftlcdfil.h @@ -0,0 +1,309 @@ +/***************************************************************************/ +/* */ +/* ftlcdfil.h */ +/* */ +/* FreeType API for color filtering of subpixel bitmap glyphs */ +/* (specification). */ +/* */ +/* Copyright 2006-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTLCDFIL_H_ +#define FTLCDFIL_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H +#include FT_PARAMETER_TAGS_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************** + * + * @section: + * lcd_filtering + * + * @title: + * LCD Filtering + * + * @abstract: + * Reduce color fringes of subpixel-rendered bitmaps. + * + * @description: + * Should you #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your + * `ftoption.h', which enables patented ClearType-style rendering, + * the LCD-optimized glyph bitmaps should be filtered to reduce color + * fringes inherent to this technology. The default FreeType LCD + * rendering uses different technology, and API described below, + * although available, does nothing. + * + * ClearType-style LCD rendering exploits the color-striped structure of + * LCD pixels, increasing the available resolution in the direction of + * the stripe (usually horizontal RGB) by a factor of~3. Since these + * subpixels are color pixels, using them unfiltered creates severe + * color fringes. Use the @FT_Library_SetLcdFilter API to specify a + * low-pass filter, which is then applied to subpixel-rendered bitmaps + * generated through @FT_Render_Glyph. The filter sacrifices some of + * the higher resolution to reduce color fringes, making the glyph image + * slightly blurrier. Positional improvements will remain. + * + * A filter should have two properties: + * + * 1) It should be normalized, meaning the sum of the 5~components + * should be 256 (0x100). It is possible to go above or under this + * target sum, however: going under means tossing out contrast, going + * over means invoking clamping and thereby non-linearities that + * increase contrast somewhat at the expense of greater distortion + * and color-fringing. Contrast is better enhanced through stem + * darkening. + * + * 2) It should be color-balanced, meaning a filter `{~a, b, c, b, a~}' + * where a~+ b~=~c. It distributes the computed coverage for one + * subpixel to all subpixels equally, sacrificing some won resolution + * but drastically reducing color-fringing. Positioning improvements + * remain! Note that color-fringing can only really be minimized + * when using a color-balanced filter and alpha-blending the glyph + * onto a surface in linear space; see @FT_Render_Glyph. + * + * Regarding the form, a filter can be a `boxy' filter or a `beveled' + * filter. Boxy filters are sharper but are less forgiving of non-ideal + * gamma curves of a screen (viewing angles!), beveled filters are + * fuzzier but more tolerant. + * + * Examples: + * + * - [0x10 0x40 0x70 0x40 0x10] is beveled and neither balanced nor + * normalized. + * + * - [0x1A 0x33 0x4D 0x33 0x1A] is beveled and balanced but not + * normalized. + * + * - [0x19 0x33 0x66 0x4c 0x19] is beveled and normalized but not + * balanced. + * + * - [0x00 0x4c 0x66 0x4c 0x00] is boxily beveled and normalized but not + * balanced. + * + * - [0x00 0x55 0x56 0x55 0x00] is boxy, normalized, and almost + * balanced. + * + * - [0x08 0x4D 0x56 0x4D 0x08] is beveled, normalized and, almost + * balanced. + * + * The filter affects glyph bitmaps rendered through @FT_Render_Glyph, + * @FT_Load_Glyph, and @FT_Load_Char. It does _not_ affect the output + * of @FT_Outline_Render and @FT_Outline_Get_Bitmap. + * + * If this feature is activated, the dimensions of LCD glyph bitmaps are + * either wider or taller than the dimensions of the corresponding + * outline with regard to the pixel grid. For example, for + * @FT_RENDER_MODE_LCD, the filter adds 3~subpixels to the left, and + * 3~subpixels to the right. The bitmap offset values are adjusted + * accordingly, so clients shouldn't need to modify their layout and + * glyph positioning code when enabling the filter. + * + * It is important to understand that linear alpha blending and gamma + * correction is critical for correctly rendering glyphs onto surfaces + * without artifacts and even more critical when subpixel rendering is + * involved. + * + * Each of the 3~alpha values (subpixels) is independently used to blend + * one color channel. That is, red alpha blends the red channel of the + * text color with the red channel of the background pixel. The + * distribution of density values by the color-balanced filter assumes + * alpha blending is done in linear space; only then color artifacts + * cancel out. + */ + + + /**************************************************************************** + * + * @enum: + * FT_LcdFilter + * + * @description: + * A list of values to identify various types of LCD filters. + * + * @values: + * FT_LCD_FILTER_NONE :: + * Do not perform filtering. When used with subpixel rendering, this + * results in sometimes severe color fringes. + * + * FT_LCD_FILTER_DEFAULT :: + * The default filter reduces color fringes considerably, at the cost + * of a slight blurriness in the output. + * + * It is a beveled, normalized, and color-balanced five-tap filter + * that is more forgiving to screens with non-ideal gamma curves and + * viewing angles. Note that while color-fringing is reduced, it can + * only be minimized by using linear alpha blending and gamma + * correction to render glyphs onto surfaces. The default filter + * weights are [0x08 0x4D 0x56 0x4D 0x08]. + * + * FT_LCD_FILTER_LIGHT :: + * The light filter is a variant that is sharper at the cost of + * slightly more color fringes than the default one. + * + * It is a boxy, normalized, and color-balanced three-tap filter that + * is less forgiving to screens with non-ideal gamma curves and + * viewing angles. This filter works best when the rendering system + * uses linear alpha blending and gamma correction to render glyphs + * onto surfaces. The light filter weights are + * [0x00 0x55 0x56 0x55 0x00]. + * + * FT_LCD_FILTER_LEGACY :: + * This filter corresponds to the original libXft color filter. It + * provides high contrast output but can exhibit really bad color + * fringes if glyphs are not extremely well hinted to the pixel grid. + * In other words, it only works well if the TrueType bytecode + * interpreter is enabled *and* high-quality hinted fonts are used. + * + * This filter is only provided for comparison purposes, and might be + * disabled or stay unsupported in the future. + * + * FT_LCD_FILTER_LEGACY1 :: + * For historical reasons, the FontConfig library returns a different + * enumeration value for legacy LCD filtering. To make code work that + * (incorrectly) forwards FontConfig's enumeration value to + * @FT_Library_SetLcdFilter without proper mapping, it is thus easiest + * to have another enumeration value, which is completely equal to + * `FT_LCD_FILTER_LEGACY'. + * + * @since: + * 2.3.0 (`FT_LCD_FILTER_LEGACY1' since 2.6.2) + */ + typedef enum FT_LcdFilter_ + { + FT_LCD_FILTER_NONE = 0, + FT_LCD_FILTER_DEFAULT = 1, + FT_LCD_FILTER_LIGHT = 2, + FT_LCD_FILTER_LEGACY1 = 3, + FT_LCD_FILTER_LEGACY = 16, + + FT_LCD_FILTER_MAX /* do not remove */ + + } FT_LcdFilter; + + + /************************************************************************** + * + * @func: + * FT_Library_SetLcdFilter + * + * @description: + * This function is used to apply color filtering to LCD decimated + * bitmaps, like the ones used when calling @FT_Render_Glyph with + * @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V. + * + * @input: + * library :: + * A handle to the target library instance. + * + * filter :: + * The filter type. + * + * You can use @FT_LCD_FILTER_NONE here to disable this feature, or + * @FT_LCD_FILTER_DEFAULT to use a default filter that should work + * well on most LCD screens. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This feature is always disabled by default. Clients must make an + * explicit call to this function with a `filter' value other than + * @FT_LCD_FILTER_NONE in order to enable it. + * + * Due to *PATENTS* covering subpixel rendering, this function doesn't + * do anything except returning `FT_Err_Unimplemented_Feature' if the + * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not + * defined in your build of the library, which should correspond to all + * default builds of FreeType. + * + * @since: + * 2.3.0 + */ + FT_EXPORT( FT_Error ) + FT_Library_SetLcdFilter( FT_Library library, + FT_LcdFilter filter ); + + + /************************************************************************** + * + * @func: + * FT_Library_SetLcdFilterWeights + * + * @description: + * This function can be used to enable LCD filter with custom weights, + * instead of using presets in @FT_Library_SetLcdFilter. + * + * @input: + * library :: + * A handle to the target library instance. + * + * weights :: + * A pointer to an array; the function copies the first five bytes and + * uses them to specify the filter weights. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Due to *PATENTS* covering subpixel rendering, this function doesn't + * do anything except returning `FT_Err_Unimplemented_Feature' if the + * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not + * defined in your build of the library, which should correspond to all + * default builds of FreeType. + * + * LCD filter weights can also be set per face using @FT_Face_Properties + * with @FT_PARAM_TAG_LCD_FILTER_WEIGHTS. + * + * @since: + * 2.4.0 + */ + FT_EXPORT( FT_Error ) + FT_Library_SetLcdFilterWeights( FT_Library library, + unsigned char *weights ); + + + /* + * @type: + * FT_LcdFiveTapFilter + * + * @description: + * A typedef for passing the five LCD filter weights to + * @FT_Face_Properties within an @FT_Parameter structure. + * + * @since: + * 2.8 + * + */ +#define FT_LCD_FILTER_FIVE_TAPS 5 + + typedef FT_Byte FT_LcdFiveTapFilter[FT_LCD_FILTER_FIVE_TAPS]; + + + /* */ + + +FT_END_HEADER + +#endif /* FTLCDFIL_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftlist.h b/freetype/include/freetype2/freetype/ftlist.h new file mode 100644 index 0000000..117473b --- /dev/null +++ b/freetype/include/freetype2/freetype/ftlist.h @@ -0,0 +1,276 @@ +/***************************************************************************/ +/* */ +/* ftlist.h */ +/* */ +/* Generic list support for FreeType (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file implements functions relative to list processing. Its */ + /* data structures are defined in `freetype.h'. */ + /* */ + /*************************************************************************/ + + +#ifndef FTLIST_H_ +#define FTLIST_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* list_processing */ + /* */ + /* <Title> */ + /* List Processing */ + /* */ + /* <Abstract> */ + /* Simple management of lists. */ + /* */ + /* <Description> */ + /* This section contains various definitions related to list */ + /* processing using doubly-linked nodes. */ + /* */ + /* <Order> */ + /* FT_List */ + /* FT_ListNode */ + /* FT_ListRec */ + /* FT_ListNodeRec */ + /* */ + /* FT_List_Add */ + /* FT_List_Insert */ + /* FT_List_Find */ + /* FT_List_Remove */ + /* FT_List_Up */ + /* FT_List_Iterate */ + /* FT_List_Iterator */ + /* FT_List_Finalize */ + /* FT_List_Destructor */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Find */ + /* */ + /* <Description> */ + /* Find the list node for a given listed object. */ + /* */ + /* <Input> */ + /* list :: A pointer to the parent list. */ + /* data :: The address of the listed object. */ + /* */ + /* <Return> */ + /* List node. NULL if it wasn't found. */ + /* */ + FT_EXPORT( FT_ListNode ) + FT_List_Find( FT_List list, + void* data ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Add */ + /* */ + /* <Description> */ + /* Append an element to the end of a list. */ + /* */ + /* <InOut> */ + /* list :: A pointer to the parent list. */ + /* node :: The node to append. */ + /* */ + FT_EXPORT( void ) + FT_List_Add( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Insert */ + /* */ + /* <Description> */ + /* Insert an element at the head of a list. */ + /* */ + /* <InOut> */ + /* list :: A pointer to parent list. */ + /* node :: The node to insert. */ + /* */ + FT_EXPORT( void ) + FT_List_Insert( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Remove */ + /* */ + /* <Description> */ + /* Remove a node from a list. This function doesn't check whether */ + /* the node is in the list! */ + /* */ + /* <Input> */ + /* node :: The node to remove. */ + /* */ + /* <InOut> */ + /* list :: A pointer to the parent list. */ + /* */ + FT_EXPORT( void ) + FT_List_Remove( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Up */ + /* */ + /* <Description> */ + /* Move a node to the head/top of a list. Used to maintain LRU */ + /* lists. */ + /* */ + /* <InOut> */ + /* list :: A pointer to the parent list. */ + /* node :: The node to move. */ + /* */ + FT_EXPORT( void ) + FT_List_Up( FT_List list, + FT_ListNode node ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_List_Iterator */ + /* */ + /* <Description> */ + /* An FT_List iterator function that is called during a list parse */ + /* by @FT_List_Iterate. */ + /* */ + /* <Input> */ + /* node :: The current iteration list node. */ + /* */ + /* user :: A typeless pointer passed to @FT_List_Iterate. */ + /* Can be used to point to the iteration's state. */ + /* */ + typedef FT_Error + (*FT_List_Iterator)( FT_ListNode node, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Iterate */ + /* */ + /* <Description> */ + /* Parse a list and calls a given iterator function on each element. */ + /* Note that parsing is stopped as soon as one of the iterator calls */ + /* returns a non-zero value. */ + /* */ + /* <Input> */ + /* list :: A handle to the list. */ + /* iterator :: An iterator function, called on each node of the list. */ + /* user :: A user-supplied field that is passed as the second */ + /* argument to the iterator. */ + /* */ + /* <Return> */ + /* The result (a FreeType error code) of the last iterator call. */ + /* */ + FT_EXPORT( FT_Error ) + FT_List_Iterate( FT_List list, + FT_List_Iterator iterator, + void* user ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_List_Destructor */ + /* */ + /* <Description> */ + /* An @FT_List iterator function that is called during a list */ + /* finalization by @FT_List_Finalize to destroy all elements in a */ + /* given list. */ + /* */ + /* <Input> */ + /* system :: The current system object. */ + /* */ + /* data :: The current object to destroy. */ + /* */ + /* user :: A typeless pointer passed to @FT_List_Iterate. It can */ + /* be used to point to the iteration's state. */ + /* */ + typedef void + (*FT_List_Destructor)( FT_Memory memory, + void* data, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_List_Finalize */ + /* */ + /* <Description> */ + /* Destroy all elements in the list as well as the list itself. */ + /* */ + /* <Input> */ + /* list :: A handle to the list. */ + /* */ + /* destroy :: A list destructor that will be applied to each element */ + /* of the list. Set this to NULL if not needed. */ + /* */ + /* memory :: The current memory object that handles deallocation. */ + /* */ + /* user :: A user-supplied field that is passed as the last */ + /* argument to the destructor. */ + /* */ + /* <Note> */ + /* This function expects that all nodes added by @FT_List_Add or */ + /* @FT_List_Insert have been dynamically allocated. */ + /* */ + FT_EXPORT( void ) + FT_List_Finalize( FT_List list, + FT_List_Destructor destroy, + FT_Memory memory, + void* user ); + + /* */ + + +FT_END_HEADER + +#endif /* FTLIST_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftlzw.h b/freetype/include/freetype2/freetype/ftlzw.h new file mode 100644 index 0000000..1615912 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftlzw.h @@ -0,0 +1,99 @@ +/***************************************************************************/ +/* */ +/* ftlzw.h */ +/* */ +/* LZW-compressed stream support. */ +/* */ +/* Copyright 2004-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTLZW_H_ +#define FTLZW_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* lzw */ + /* */ + /* <Title> */ + /* LZW Streams */ + /* */ + /* <Abstract> */ + /* Using LZW-compressed font files. */ + /* */ + /* <Description> */ + /* This section contains the declaration of LZW-specific functions. */ + /* */ + /*************************************************************************/ + + /************************************************************************ + * + * @function: + * FT_Stream_OpenLZW + * + * @description: + * Open a new stream to parse LZW-compressed font files. This is + * mainly used to support the compressed `*.pcf.Z' fonts that come + * with XFree86. + * + * @input: + * stream :: The target embedding stream. + * + * source :: The source stream. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source stream must be opened _before_ calling this function. + * + * Calling the internal function `FT_Stream_Close' on the new stream will + * *not* call `FT_Stream_Close' on the source stream. None of the stream + * objects will be released to the heap. + * + * The stream implementation is very basic and resets the decompression + * process each time seeking backwards is needed within the stream + * + * In certain builds of the library, LZW compression recognition is + * automatically handled when calling @FT_New_Face or @FT_Open_Face. + * This means that if no font driver is capable of handling the raw + * compressed file, the library will try to open a LZW stream from it + * and re-open the face with it. + * + * This function may return `FT_Err_Unimplemented_Feature' if your build + * of FreeType was not compiled with LZW support. + */ + FT_EXPORT( FT_Error ) + FT_Stream_OpenLZW( FT_Stream stream, + FT_Stream source ); + + /* */ + + +FT_END_HEADER + +#endif /* FTLZW_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftmac.h b/freetype/include/freetype2/freetype/ftmac.h new file mode 100644 index 0000000..c1e497c --- /dev/null +++ b/freetype/include/freetype2/freetype/ftmac.h @@ -0,0 +1,275 @@ +/***************************************************************************/ +/* */ +/* ftmac.h */ +/* */ +/* Additional Mac-specific API. */ +/* */ +/* Copyright 1996-2018 by */ +/* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* NOTE: Include this file after FT_FREETYPE_H and after any */ +/* Mac-specific headers (because this header uses Mac types such as */ +/* Handle, FSSpec, FSRef, etc.) */ +/* */ +/***************************************************************************/ + + +#ifndef FTMAC_H_ +#define FTMAC_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + + /* gcc-3.1 and later can warn about functions tagged as deprecated */ +#ifndef FT_DEPRECATED_ATTRIBUTE +#if defined( __GNUC__ ) && \ + ( ( __GNUC__ >= 4 ) || \ + ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 1 ) ) ) +#define FT_DEPRECATED_ATTRIBUTE __attribute__(( deprecated )) +#else +#define FT_DEPRECATED_ATTRIBUTE +#endif +#endif + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* mac_specific */ + /* */ + /* <Title> */ + /* Mac Specific Interface */ + /* */ + /* <Abstract> */ + /* Only available on the Macintosh. */ + /* */ + /* <Description> */ + /* The following definitions are only available if FreeType is */ + /* compiled on a Macintosh. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face_From_FOND */ + /* */ + /* <Description> */ + /* Create a new face object from a FOND resource. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* fond :: A FOND resource. */ + /* */ + /* face_index :: Only supported for the -1 `sanity check' special */ + /* case. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Notes> */ + /* This function can be used to create @FT_Face objects from fonts */ + /* that are installed in the system as follows. */ + /* */ + /* { */ + /* fond = GetResource( 'FOND', fontName ); */ + /* error = FT_New_Face_From_FOND( library, fond, 0, &face ); */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face_From_FOND( FT_Library library, + Handle fond, + FT_Long face_index, + FT_Face *aface ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GetFile_From_Mac_Name */ + /* */ + /* <Description> */ + /* Return an FSSpec for the disk file containing the named font. */ + /* */ + /* <Input> */ + /* fontName :: Mac OS name of the font (e.g., Times New Roman */ + /* Bold). */ + /* */ + /* <Output> */ + /* pathSpec :: FSSpec to the file. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* face_index :: Index of the face. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFile_From_Mac_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GetFile_From_Mac_ATS_Name */ + /* */ + /* <Description> */ + /* Return an FSSpec for the disk file containing the named font. */ + /* */ + /* <Input> */ + /* fontName :: Mac OS name of the font in ATS framework. */ + /* */ + /* <Output> */ + /* pathSpec :: FSSpec to the file. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* face_index :: Index of the face. For passing to */ + /* @FT_New_Face_From_FSSpec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFile_From_Mac_ATS_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_GetFilePath_From_Mac_ATS_Name */ + /* */ + /* <Description> */ + /* Return a pathname of the disk file and face index for given font */ + /* name that is handled by ATS framework. */ + /* */ + /* <Input> */ + /* fontName :: Mac OS name of the font in ATS framework. */ + /* */ + /* <Output> */ + /* path :: Buffer to store pathname of the file. For passing */ + /* to @FT_New_Face. The client must allocate this */ + /* buffer before calling this function. */ + /* */ + /* maxPathSize :: Lengths of the buffer `path' that client allocated. */ + /* */ + /* face_index :: Index of the face. For passing to @FT_New_Face. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, + UInt8* path, + UInt32 maxPathSize, + FT_Long* face_index ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face_From_FSSpec */ + /* */ + /* <Description> */ + /* Create a new face object from a given resource and typeface index */ + /* using an FSSpec to the font file. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* spec :: FSSpec to the font file. */ + /* */ + /* face_index :: The index of the face within the resource. The */ + /* first face has index~0. */ + /* <Output> */ + /* aface :: A handle to a new face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* @FT_New_Face_From_FSSpec is identical to @FT_New_Face except */ + /* it accepts an FSSpec instead of a path. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face_From_FSSpec( FT_Library library, + const FSSpec *spec, + FT_Long face_index, + FT_Face *aface ) + FT_DEPRECATED_ATTRIBUTE; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face_From_FSRef */ + /* */ + /* <Description> */ + /* Create a new face object from a given resource and typeface index */ + /* using an FSRef to the font file. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* spec :: FSRef to the font file. */ + /* */ + /* face_index :: The index of the face within the resource. The */ + /* first face has index~0. */ + /* <Output> */ + /* aface :: A handle to a new face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* @FT_New_Face_From_FSRef is identical to @FT_New_Face except */ + /* it accepts an FSRef instead of a path. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face_From_FSRef( FT_Library library, + const FSRef *ref, + FT_Long face_index, + FT_Face *aface ) + FT_DEPRECATED_ATTRIBUTE; + + /* */ + + +FT_END_HEADER + + +#endif /* FTMAC_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftmm.h b/freetype/include/freetype2/freetype/ftmm.h new file mode 100644 index 0000000..9948102 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftmm.h @@ -0,0 +1,638 @@ +/***************************************************************************/ +/* */ +/* ftmm.h */ +/* */ +/* FreeType Multiple Master font interface (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMM_H_ +#define FTMM_H_ + + +#include <ft2build.h> +#include FT_TYPE1_TABLES_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* multiple_masters */ + /* */ + /* <Title> */ + /* Multiple Masters */ + /* */ + /* <Abstract> */ + /* How to manage Multiple Masters fonts. */ + /* */ + /* <Description> */ + /* The following types and functions are used to manage Multiple */ + /* Master fonts, i.e., the selection of specific design instances by */ + /* setting design axis coordinates. */ + /* */ + /* Besides Adobe MM fonts, the interface supports Apple's TrueType GX */ + /* and OpenType variation fonts. Some of the routines only work with */ + /* Adobe MM fonts, others will work with all three types. They are */ + /* similar enough that a consistent interface makes sense. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_MM_Axis */ + /* */ + /* <Description> */ + /* A structure to model a given axis in design space for Multiple */ + /* Masters fonts. */ + /* */ + /* This structure can't be used for TrueType GX or OpenType variation */ + /* fonts. */ + /* */ + /* <Fields> */ + /* name :: The axis's name. */ + /* */ + /* minimum :: The axis's minimum design coordinate. */ + /* */ + /* maximum :: The axis's maximum design coordinate. */ + /* */ + typedef struct FT_MM_Axis_ + { + FT_String* name; + FT_Long minimum; + FT_Long maximum; + + } FT_MM_Axis; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Multi_Master */ + /* */ + /* <Description> */ + /* A structure to model the axes and space of a Multiple Masters */ + /* font. */ + /* */ + /* This structure can't be used for TrueType GX or OpenType variation */ + /* fonts. */ + /* */ + /* <Fields> */ + /* num_axis :: Number of axes. Cannot exceed~4. */ + /* */ + /* num_designs :: Number of designs; should be normally 2^num_axis */ + /* even though the Type~1 specification strangely */ + /* allows for intermediate designs to be present. */ + /* This number cannot exceed~16. */ + /* */ + /* axis :: A table of axis descriptors. */ + /* */ + typedef struct FT_Multi_Master_ + { + FT_UInt num_axis; + FT_UInt num_designs; + FT_MM_Axis axis[T1_MAX_MM_AXIS]; + + } FT_Multi_Master; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Var_Axis */ + /* */ + /* <Description> */ + /* A structure to model a given axis in design space for Multiple */ + /* Masters, TrueType GX, and OpenType variation fonts. */ + /* */ + /* <Fields> */ + /* name :: The axis's name. */ + /* Not always meaningful for TrueType GX or OpenType */ + /* variation fonts. */ + /* */ + /* minimum :: The axis's minimum design coordinate. */ + /* */ + /* def :: The axis's default design coordinate. */ + /* FreeType computes meaningful default values for Adobe */ + /* MM fonts. */ + /* */ + /* maximum :: The axis's maximum design coordinate. */ + /* */ + /* tag :: The axis's tag (the equivalent to `name' for TrueType */ + /* GX and OpenType variation fonts). FreeType provides */ + /* default values for Adobe MM fonts if possible. */ + /* */ + /* strid :: The axis name entry in the font's `name' table. This */ + /* is another (and often better) version of the `name' */ + /* field for TrueType GX or OpenType variation fonts. Not */ + /* meaningful for Adobe MM fonts. */ + /* */ + /* <Note> */ + /* The fields `minimum', `def', and `maximum' are 16.16 fractional */ + /* values for TrueType GX and OpenType variation fonts. For Adobe MM */ + /* fonts, the values are integers. */ + /* */ + typedef struct FT_Var_Axis_ + { + FT_String* name; + + FT_Fixed minimum; + FT_Fixed def; + FT_Fixed maximum; + + FT_ULong tag; + FT_UInt strid; + + } FT_Var_Axis; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Var_Named_Style */ + /* */ + /* <Description> */ + /* A structure to model a named instance in a TrueType GX or OpenType */ + /* variation font. */ + /* */ + /* This structure can't be used for Adobe MM fonts. */ + /* */ + /* <Fields> */ + /* coords :: The design coordinates for this instance. */ + /* This is an array with one entry for each axis. */ + /* */ + /* strid :: The entry in `name' table identifying this instance. */ + /* */ + /* psid :: The entry in `name' table identifying a PostScript name */ + /* for this instance. Value 0xFFFF indicates a missing */ + /* entry. */ + /* */ + typedef struct FT_Var_Named_Style_ + { + FT_Fixed* coords; + FT_UInt strid; + FT_UInt psid; /* since 2.7.1 */ + + } FT_Var_Named_Style; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_MM_Var */ + /* */ + /* <Description> */ + /* A structure to model the axes and space of an Adobe MM, TrueType */ + /* GX, or OpenType variation font. */ + /* */ + /* Some fields are specific to one format and not to the others. */ + /* */ + /* <Fields> */ + /* num_axis :: The number of axes. The maximum value is~4 for */ + /* Adobe MM fonts; no limit in TrueType GX or */ + /* OpenType variation fonts. */ + /* */ + /* num_designs :: The number of designs; should be normally */ + /* 2^num_axis for Adobe MM fonts. Not meaningful */ + /* for TrueType GX or OpenType variation fonts */ + /* (where every glyph could have a different */ + /* number of designs). */ + /* */ + /* num_namedstyles :: The number of named styles; a `named style' is */ + /* a tuple of design coordinates that has a string */ + /* ID (in the `name' table) associated with it. */ + /* The font can tell the user that, for example, */ + /* [Weight=1.5,Width=1.1] is `Bold'. Another name */ + /* for `named style' is `named instance'. */ + /* */ + /* For Adobe Multiple Masters fonts, this value is */ + /* always zero because the format does not support */ + /* named styles. */ + /* */ + /* axis :: An axis descriptor table. */ + /* TrueType GX and OpenType variation fonts */ + /* contain slightly more data than Adobe MM fonts. */ + /* Memory management of this pointer is done */ + /* internally by FreeType. */ + /* */ + /* namedstyle :: A named style (instance) table. */ + /* Only meaningful for TrueType GX and OpenType */ + /* variation fonts. Memory management of this */ + /* pointer is done internally by FreeType. */ + /* */ + typedef struct FT_MM_Var_ + { + FT_UInt num_axis; + FT_UInt num_designs; + FT_UInt num_namedstyles; + FT_Var_Axis* axis; + FT_Var_Named_Style* namedstyle; + + } FT_MM_Var; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Multi_Master */ + /* */ + /* <Description> */ + /* Retrieve a variation descriptor of a given Adobe MM font. */ + /* */ + /* This function can't be used with TrueType GX or OpenType variation */ + /* fonts. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* <Output> */ + /* amaster :: The Multiple Masters descriptor. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Multi_Master( FT_Face face, + FT_Multi_Master *amaster ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_MM_Var */ + /* */ + /* <Description> */ + /* Retrieve a variation descriptor for a given font. */ + /* */ + /* This function works with all supported variation formats. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* <Output> */ + /* amaster :: The variation descriptor. */ + /* Allocates a data structure, which the user must */ + /* deallocate with a call to @FT_Done_MM_Var after use. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_MM_Var( FT_Face face, + FT_MM_Var* *amaster ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_MM_Var */ + /* */ + /* <Description> */ + /* Free the memory allocated by @FT_Get_MM_Var. */ + /* */ + /* <Input> */ + /* library :: A handle of the face's parent library object that was */ + /* used in the call to @FT_Get_MM_Var to create `amaster'. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_MM_Var( FT_Library library, + FT_MM_Var *amaster ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_MM_Design_Coordinates */ + /* */ + /* <Description> */ + /* For Adobe MM fonts, choose an interpolated font design through */ + /* design coordinates. */ + /* */ + /* This function can't be used with TrueType GX or OpenType variation */ + /* fonts. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face. */ + /* */ + /* <Input> */ + /* num_coords :: The number of available design coordinates. If it */ + /* is larger than the number of axes, ignore the excess */ + /* values. If it is smaller than the number of axes, */ + /* use default values for the remaining axes. */ + /* */ + /* coords :: An array of design coordinates. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* [Since 2.8.1] To reset all axes to the default values, call the */ + /* function with `num_coords' set to zero and `coords' set to NULL. */ + /* */ + /* [Since 2.9] If `num_coords' is larger than zero, this function */ + /* sets the @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags' */ + /* field (i.e., @FT_IS_VARIATION will return true). If `num_coords' */ + /* is zero, this bit flag gets unset. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_MM_Design_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Long* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Var_Design_Coordinates */ + /* */ + /* <Description> */ + /* Choose an interpolated font design through design coordinates. */ + /* */ + /* This function works with all supported variation formats. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face. */ + /* */ + /* <Input> */ + /* num_coords :: The number of available design coordinates. If it */ + /* is larger than the number of axes, ignore the excess */ + /* values. If it is smaller than the number of axes, */ + /* use default values for the remaining axes. */ + /* */ + /* coords :: An array of design coordinates. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* [Since 2.8.1] To reset all axes to the default values, call the */ + /* function with `num_coords' set to zero and `coords' set to NULL. */ + /* [Since 2.9] `Default values' means the currently selected named */ + /* instance (or the base font if no named instance is selected). */ + /* */ + /* [Since 2.9] If `num_coords' is larger than zero, this function */ + /* sets the @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags' */ + /* field (i.e., @FT_IS_VARIATION will return true). If `num_coords' */ + /* is zero, this bit flag gets unset. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Var_Design_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Var_Design_Coordinates */ + /* */ + /* <Description> */ + /* Get the design coordinates of the currently selected interpolated */ + /* font. */ + /* */ + /* This function works with all supported variation formats. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* num_coords :: The number of design coordinates to retrieve. If it */ + /* is larger than the number of axes, set the excess */ + /* values to~0. */ + /* */ + /* <Output> */ + /* coords :: The design coordinates array. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.7.1 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Var_Design_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_MM_Blend_Coordinates */ + /* */ + /* <Description> */ + /* Choose an interpolated font design through normalized blend */ + /* coordinates. */ + /* */ + /* This function works with all supported variation formats. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face. */ + /* */ + /* <Input> */ + /* num_coords :: The number of available design coordinates. If it */ + /* is larger than the number of axes, ignore the excess */ + /* values. If it is smaller than the number of axes, */ + /* use default values for the remaining axes. */ + /* */ + /* coords :: The design coordinates array (each element must be */ + /* between 0 and 1.0 for Adobe MM fonts, and between */ + /* -1.0 and 1.0 for TrueType GX and OpenType variation */ + /* fonts). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* [Since 2.8.1] To reset all axes to the default values, call the */ + /* function with `num_coords' set to zero and `coords' set to NULL. */ + /* [Since 2.9] `Default values' means the currently selected named */ + /* instance (or the base font if no named instance is selected). */ + /* */ + /* [Since 2.9] If `num_coords' is larger than zero, this function */ + /* sets the @FT_FACE_FLAG_VARIATION bit in @FT_Face's `face_flags' */ + /* field (i.e., @FT_IS_VARIATION will return true). If `num_coords' */ + /* is zero, this bit flag gets unset. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_MM_Blend_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_MM_Blend_Coordinates */ + /* */ + /* <Description> */ + /* Get the normalized blend coordinates of the currently selected */ + /* interpolated font. */ + /* */ + /* This function works with all supported variation formats. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* num_coords :: The number of normalized blend coordinates to */ + /* retrieve. If it is larger than the number of axes, */ + /* set the excess values to~0.5 for Adobe MM fonts, and */ + /* to~0 for TrueType GX and OpenType variation fonts. */ + /* */ + /* <Output> */ + /* coords :: The normalized blend coordinates array. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.7.1 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_MM_Blend_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Var_Blend_Coordinates */ + /* */ + /* <Description> */ + /* This is another name of @FT_Set_MM_Blend_Coordinates. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Var_Blend_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Var_Blend_Coordinates */ + /* */ + /* <Description> */ + /* This is another name of @FT_Get_MM_Blend_Coordinates. */ + /* */ + /* <Since> */ + /* 2.7.1 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Var_Blend_Coordinates( FT_Face face, + FT_UInt num_coords, + FT_Fixed* coords ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_VAR_AXIS_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the return value of */ + /* @FT_Get_Var_Axis_Flags. */ + /* */ + /* <Values> */ + /* FT_VAR_AXIS_FLAG_HIDDEN :: */ + /* The variation axis should not be exposed to user interfaces. */ + /* */ + /* <Since> */ + /* 2.8.1 */ + /* */ +#define FT_VAR_AXIS_FLAG_HIDDEN 1 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Var_Axis_Flags */ + /* */ + /* <Description> */ + /* Get the `flags' field of an OpenType Variation Axis Record. */ + /* */ + /* Not meaningful for Adobe MM fonts (`*flags' is always zero). */ + /* */ + /* <Input> */ + /* master :: The variation descriptor. */ + /* */ + /* axis_index :: The index of the requested variation axis. */ + /* */ + /* <Output> */ + /* flags :: The `flags' field. See @FT_VAR_AXIS_FLAG_XXX for */ + /* possible values. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.8.1 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Var_Axis_Flags( FT_MM_Var* master, + FT_UInt axis_index, + FT_UInt* flags ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Named_Instance */ + /* */ + /* <Description> */ + /* Set or change the current named instance. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* instance_index :: The index of the requested instance, starting */ + /* with value 1. If set to value 0, FreeType */ + /* switches to font access without a named */ + /* instance. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The function uses the value of `instance_index' to set bits 16-30 */ + /* of the face's `face_index' field. It also resets any variation */ + /* applied to the font, and the @FT_FACE_FLAG_VARIATION bit of the */ + /* face's `face_flags' field gets reset to zero (i.e., */ + /* @FT_IS_VARIATION will return false). */ + /* */ + /* For Adobe MM fonts (which don't have named instances) this */ + /* function simply resets the current face to the default instance. */ + /* */ + /* <Since> */ + /* 2.9 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Named_Instance( FT_Face face, + FT_UInt instance_index ); + + /* */ + + +FT_END_HEADER + +#endif /* FTMM_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftmodapi.h b/freetype/include/freetype2/freetype/ftmodapi.h new file mode 100644 index 0000000..a6eb876 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftmodapi.h @@ -0,0 +1,711 @@ +/***************************************************************************/ +/* */ +/* ftmodapi.h */ +/* */ +/* FreeType modules public interface (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMODAPI_H_ +#define FTMODAPI_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /* <Title> */ + /* Module Management */ + /* */ + /* <Abstract> */ + /* How to add, upgrade, remove, and control modules from FreeType. */ + /* */ + /* <Description> */ + /* The definitions below are used to manage modules within FreeType. */ + /* Modules can be added, upgraded, and removed at runtime. */ + /* Additionally, some module properties can be controlled also. */ + /* */ + /* Here is a list of possible values of the `module_name' field in */ + /* the @FT_Module_Class structure. */ + /* */ + /* { */ + /* autofitter */ + /* bdf */ + /* cff */ + /* gxvalid */ + /* otvalid */ + /* pcf */ + /* pfr */ + /* psaux */ + /* pshinter */ + /* psnames */ + /* raster1 */ + /* sfnt */ + /* smooth, smooth-lcd, smooth-lcdv */ + /* truetype */ + /* type1 */ + /* type42 */ + /* t1cid */ + /* winfonts */ + /* } */ + /* */ + /* Note that the FreeType Cache sub-system is not a FreeType module. */ + /* */ + /* <Order> */ + /* FT_Module */ + /* FT_Module_Constructor */ + /* FT_Module_Destructor */ + /* FT_Module_Requester */ + /* FT_Module_Class */ + /* */ + /* FT_Add_Module */ + /* FT_Get_Module */ + /* FT_Remove_Module */ + /* FT_Add_Default_Modules */ + /* */ + /* FT_Property_Set */ + /* FT_Property_Get */ + /* FT_Set_Default_Properties */ + /* */ + /* FT_New_Library */ + /* FT_Done_Library */ + /* FT_Reference_Library */ + /* */ + /* FT_Renderer */ + /* FT_Renderer_Class */ + /* */ + /* FT_Get_Renderer */ + /* FT_Set_Renderer */ + /* */ + /* FT_Set_Debug_Hook */ + /* */ + /*************************************************************************/ + + + /* module bit flags */ +#define FT_MODULE_FONT_DRIVER 1 /* this module is a font driver */ +#define FT_MODULE_RENDERER 2 /* this module is a renderer */ +#define FT_MODULE_HINTER 4 /* this module is a glyph hinter */ +#define FT_MODULE_STYLER 8 /* this module is a styler */ + +#define FT_MODULE_DRIVER_SCALABLE 0x100 /* the driver supports */ + /* scalable fonts */ +#define FT_MODULE_DRIVER_NO_OUTLINES 0x200 /* the driver does not */ + /* support vector outlines */ +#define FT_MODULE_DRIVER_HAS_HINTER 0x400 /* the driver provides its */ + /* own hinter */ +#define FT_MODULE_DRIVER_HINTS_LIGHTLY 0x800 /* the driver's hinter */ + /* produces LIGHT hints */ + + + /* deprecated values */ +#define ft_module_font_driver FT_MODULE_FONT_DRIVER +#define ft_module_renderer FT_MODULE_RENDERER +#define ft_module_hinter FT_MODULE_HINTER +#define ft_module_styler FT_MODULE_STYLER + +#define ft_module_driver_scalable FT_MODULE_DRIVER_SCALABLE +#define ft_module_driver_no_outlines FT_MODULE_DRIVER_NO_OUTLINES +#define ft_module_driver_has_hinter FT_MODULE_DRIVER_HAS_HINTER +#define ft_module_driver_hints_lightly FT_MODULE_DRIVER_HINTS_LIGHTLY + + + typedef FT_Pointer FT_Module_Interface; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Module_Constructor */ + /* */ + /* <Description> */ + /* A function used to initialize (not create) a new module object. */ + /* */ + /* <Input> */ + /* module :: The module to initialize. */ + /* */ + typedef FT_Error + (*FT_Module_Constructor)( FT_Module module ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Module_Destructor */ + /* */ + /* <Description> */ + /* A function used to finalize (not destroy) a given module object. */ + /* */ + /* <Input> */ + /* module :: The module to finalize. */ + /* */ + typedef void + (*FT_Module_Destructor)( FT_Module module ); + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Module_Requester */ + /* */ + /* <Description> */ + /* A function used to query a given module for a specific interface. */ + /* */ + /* <Input> */ + /* module :: The module to be searched. */ + /* */ + /* name :: The name of the interface in the module. */ + /* */ + typedef FT_Module_Interface + (*FT_Module_Requester)( FT_Module module, + const char* name ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Module_Class */ + /* */ + /* <Description> */ + /* The module class descriptor. */ + /* */ + /* <Fields> */ + /* module_flags :: Bit flags describing the module. */ + /* */ + /* module_size :: The size of one module object/instance in */ + /* bytes. */ + /* */ + /* module_name :: The name of the module. */ + /* */ + /* module_version :: The version, as a 16.16 fixed number */ + /* (major.minor). */ + /* */ + /* module_requires :: The version of FreeType this module requires, */ + /* as a 16.16 fixed number (major.minor). Starts */ + /* at version 2.0, i.e., 0x20000. */ + /* */ + /* module_init :: The initializing function. */ + /* */ + /* module_done :: The finalizing function. */ + /* */ + /* get_interface :: The interface requesting function. */ + /* */ + typedef struct FT_Module_Class_ + { + FT_ULong module_flags; + FT_Long module_size; + const FT_String* module_name; + FT_Fixed module_version; + FT_Fixed module_requires; + + const void* module_interface; + + FT_Module_Constructor module_init; + FT_Module_Destructor module_done; + FT_Module_Requester get_interface; + + } FT_Module_Class; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Add_Module */ + /* */ + /* <Description> */ + /* Add a new module to a given library instance. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library object. */ + /* */ + /* <Input> */ + /* clazz :: A pointer to class descriptor for the module. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* An error will be returned if a module already exists by that name, */ + /* or if the module requires a version of FreeType that is too great. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Add_Module( FT_Library library, + const FT_Module_Class* clazz ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Module */ + /* */ + /* <Description> */ + /* Find a module by its name. */ + /* */ + /* <Input> */ + /* library :: A handle to the library object. */ + /* */ + /* module_name :: The module's name (as an ASCII string). */ + /* */ + /* <Return> */ + /* A module handle. 0~if none was found. */ + /* */ + /* <Note> */ + /* FreeType's internal modules aren't documented very well, and you */ + /* should look up the source code for details. */ + /* */ + FT_EXPORT( FT_Module ) + FT_Get_Module( FT_Library library, + const char* module_name ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Remove_Module */ + /* */ + /* <Description> */ + /* Remove a given module from a library instance. */ + /* */ + /* <InOut> */ + /* library :: A handle to a library object. */ + /* */ + /* <Input> */ + /* module :: A handle to a module object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The module object is destroyed by the function in case of success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Remove_Module( FT_Library library, + FT_Module module ); + + + /********************************************************************** + * + * @function: + * FT_Property_Set + * + * @description: + * Set a property for a given module. + * + * @input: + * library :: + * A handle to the library the module is part of. + * + * module_name :: + * The module name. + * + * property_name :: + * The property name. Properties are described in section + * @properties. + * + * Note that only a few modules have properties. + * + * value :: + * A generic pointer to a variable or structure that gives the new + * value of the property. The exact definition of `value' is + * dependent on the property; see section @properties. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If `module_name' isn't a valid module name, or `property_name' + * doesn't specify a valid property, or if `value' doesn't represent a + * valid value for the given property, an error is returned. + * + * The following example sets property `bar' (a simple integer) in + * module `foo' to value~1. + * + * { + * FT_UInt bar; + * + * + * bar = 1; + * FT_Property_Set( library, "foo", "bar", &bar ); + * } + * + * Note that the FreeType Cache sub-system doesn't recognize module + * property changes. To avoid glyph lookup confusion within the cache + * you should call @FTC_Manager_Reset to completely flush the cache if + * a module property gets changed after @FTC_Manager_New has been + * called. + * + * It is not possible to set properties of the FreeType Cache + * sub-system itself with FT_Property_Set; use @FTC_Property_Set + * instead. + * + * @since: + * 2.4.11 + * + */ + FT_EXPORT( FT_Error ) + FT_Property_Set( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + const void* value ); + + + /********************************************************************** + * + * @function: + * FT_Property_Get + * + * @description: + * Get a module's property value. + * + * @input: + * library :: + * A handle to the library the module is part of. + * + * module_name :: + * The module name. + * + * property_name :: + * The property name. Properties are described in section + * @properties. + * + * @inout: + * value :: + * A generic pointer to a variable or structure that gives the + * value of the property. The exact definition of `value' is + * dependent on the property; see section @properties. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If `module_name' isn't a valid module name, or `property_name' + * doesn't specify a valid property, or if `value' doesn't represent a + * valid value for the given property, an error is returned. + * + * The following example gets property `baz' (a range) in module `foo'. + * + * { + * typedef range_ + * { + * FT_Int32 min; + * FT_Int32 max; + * + * } range; + * + * range baz; + * + * + * FT_Property_Get( library, "foo", "baz", &baz ); + * } + * + * It is not possible to retrieve properties of the FreeType Cache + * sub-system with FT_Property_Get; use @FTC_Property_Get instead. + * + * @since: + * 2.4.11 + * + */ + FT_EXPORT( FT_Error ) + FT_Property_Get( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + void* value ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Default_Properties */ + /* */ + /* <Description> */ + /* If compilation option FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES is */ + /* set, this function reads the `FREETYPE_PROPERTIES' environment */ + /* variable to control driver properties. See section @properties */ + /* for more. */ + /* */ + /* If the compilation option is not set, this function does nothing. */ + /* */ + /* `FREETYPE_PROPERTIES' has the following syntax form (broken here */ + /* into multiple lines for better readability). */ + /* */ + /* { */ + /* <optional whitespace> */ + /* <module-name1> ':' */ + /* <property-name1> '=' <property-value1> */ + /* <whitespace> */ + /* <module-name2> ':' */ + /* <property-name2> '=' <property-value2> */ + /* ... */ + /* } */ + /* */ + /* Example: */ + /* */ + /* { */ + /* FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ */ + /* cff:no-stem-darkening=1 \ */ + /* autofitter:warping=1 */ + /* } */ + /* */ + /* <InOut> */ + /* library :: A handle to a new library object. */ + /* */ + /* <Since> */ + /* 2.8 */ + /* */ + FT_EXPORT( void ) + FT_Set_Default_Properties( FT_Library library ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Reference_Library */ + /* */ + /* <Description> */ + /* A counter gets initialized to~1 at the time an @FT_Library */ + /* structure is created. This function increments the counter. */ + /* @FT_Done_Library then only destroys a library if the counter is~1, */ + /* otherwise it simply decrements the counter. */ + /* */ + /* This function helps in managing life-cycles of structures that */ + /* reference @FT_Library objects. */ + /* */ + /* <Input> */ + /* library :: A handle to a target library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.4.2 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Reference_Library( FT_Library library ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Library */ + /* */ + /* <Description> */ + /* This function is used to create a new FreeType library instance */ + /* from a given memory object. It is thus possible to use libraries */ + /* with distinct memory allocators within the same program. Note, */ + /* however, that the used @FT_Memory structure is expected to remain */ + /* valid for the life of the @FT_Library object. */ + /* */ + /* Normally, you would call this function (followed by a call to */ + /* @FT_Add_Default_Modules or a series of calls to @FT_Add_Module, */ + /* and a call to @FT_Set_Default_Properties) instead of */ + /* @FT_Init_FreeType to initialize the FreeType library. */ + /* */ + /* Don't use @FT_Done_FreeType but @FT_Done_Library to destroy a */ + /* library instance. */ + /* */ + /* <Input> */ + /* memory :: A handle to the original memory object. */ + /* */ + /* <Output> */ + /* alibrary :: A pointer to handle of a new library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Library. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Library( FT_Memory memory, + FT_Library *alibrary ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Library */ + /* */ + /* <Description> */ + /* Discard a given library object. This closes all drivers and */ + /* discards all resource objects. */ + /* */ + /* <Input> */ + /* library :: A handle to the target library. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Library. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Library( FT_Library library ); + + /* */ + + typedef void + (*FT_DebugHook_Func)( void* arg ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Debug_Hook */ + /* */ + /* <Description> */ + /* Set a debug hook function for debugging the interpreter of a font */ + /* format. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library object. */ + /* */ + /* <Input> */ + /* hook_index :: The index of the debug hook. You should use the */ + /* values defined in `ftobjs.h', e.g., */ + /* `FT_DEBUG_HOOK_TRUETYPE'. */ + /* */ + /* debug_hook :: The function used to debug the interpreter. */ + /* */ + /* <Note> */ + /* Currently, four debug hook slots are available, but only two (for */ + /* the TrueType and the Type~1 interpreter) are defined. */ + /* */ + /* Since the internal headers of FreeType are no longer installed, */ + /* the symbol `FT_DEBUG_HOOK_TRUETYPE' isn't available publicly. */ + /* This is a bug and will be fixed in a forthcoming release. */ + /* */ + FT_EXPORT( void ) + FT_Set_Debug_Hook( FT_Library library, + FT_UInt hook_index, + FT_DebugHook_Func debug_hook ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Add_Default_Modules */ + /* */ + /* <Description> */ + /* Add the set of default drivers to a given library object. */ + /* This is only useful when you create a library object with */ + /* @FT_New_Library (usually to plug a custom memory manager). */ + /* */ + /* <InOut> */ + /* library :: A handle to a new library object. */ + /* */ + FT_EXPORT( void ) + FT_Add_Default_Modules( FT_Library library ); + + + + /************************************************************************** + * + * @section: + * truetype_engine + * + * @title: + * The TrueType Engine + * + * @abstract: + * TrueType bytecode support. + * + * @description: + * This section contains a function used to query the level of TrueType + * bytecode support compiled in this version of the library. + * + */ + + + /************************************************************************** + * + * @enum: + * FT_TrueTypeEngineType + * + * @description: + * A list of values describing which kind of TrueType bytecode + * engine is implemented in a given FT_Library instance. It is used + * by the @FT_Get_TrueType_Engine_Type function. + * + * @values: + * FT_TRUETYPE_ENGINE_TYPE_NONE :: + * The library doesn't implement any kind of bytecode interpreter. + * + * FT_TRUETYPE_ENGINE_TYPE_UNPATENTED :: + * Deprecated and removed. + * + * FT_TRUETYPE_ENGINE_TYPE_PATENTED :: + * The library implements a bytecode interpreter that covers + * the full instruction set of the TrueType virtual machine (this + * was governed by patents until May 2010, hence the name). + * + * @since: + * 2.2 + * + */ + typedef enum FT_TrueTypeEngineType_ + { + FT_TRUETYPE_ENGINE_TYPE_NONE = 0, + FT_TRUETYPE_ENGINE_TYPE_UNPATENTED, + FT_TRUETYPE_ENGINE_TYPE_PATENTED + + } FT_TrueTypeEngineType; + + + /************************************************************************** + * + * @func: + * FT_Get_TrueType_Engine_Type + * + * @description: + * Return an @FT_TrueTypeEngineType value to indicate which level of + * the TrueType virtual machine a given library instance supports. + * + * @input: + * library :: + * A library instance. + * + * @return: + * A value indicating which level is supported. + * + * @since: + * 2.2 + * + */ + FT_EXPORT( FT_TrueTypeEngineType ) + FT_Get_TrueType_Engine_Type( FT_Library library ); + + /* */ + + +FT_END_HEADER + +#endif /* FTMODAPI_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftmoderr.h b/freetype/include/freetype2/freetype/ftmoderr.h new file mode 100644 index 0000000..e0fc131 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftmoderr.h @@ -0,0 +1,194 @@ +/***************************************************************************/ +/* */ +/* ftmoderr.h */ +/* */ +/* FreeType module error offsets (specification). */ +/* */ +/* Copyright 2001-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This file is used to define the FreeType module error codes. */ + /* */ + /* If the macro FT_CONFIG_OPTION_USE_MODULE_ERRORS in `ftoption.h' is */ + /* set, the lower byte of an error value identifies the error code as */ + /* usual. In addition, the higher byte identifies the module. For */ + /* example, the error `FT_Err_Invalid_File_Format' has value 0x0003, the */ + /* error `TT_Err_Invalid_File_Format' has value 0x1303, the error */ + /* `T1_Err_Invalid_File_Format' has value 0x1403, etc. */ + /* */ + /* Note that `FT_Err_Ok', `TT_Err_Ok', etc. are always equal to zero, */ + /* including the high byte. */ + /* */ + /* If FT_CONFIG_OPTION_USE_MODULE_ERRORS isn't set, the higher byte of */ + /* an error value is set to zero. */ + /* */ + /* To hide the various `XXX_Err_' prefixes in the source code, FreeType */ + /* provides some macros in `fttypes.h'. */ + /* */ + /* FT_ERR( err ) */ + /* Add current error module prefix (as defined with the */ + /* `FT_ERR_PREFIX' macro) to `err'. For example, in the BDF module */ + /* the line */ + /* */ + /* error = FT_ERR( Invalid_Outline ); */ + /* */ + /* expands to */ + /* */ + /* error = BDF_Err_Invalid_Outline; */ + /* */ + /* For simplicity, you can always use `FT_Err_Ok' directly instead */ + /* of `FT_ERR( Ok )'. */ + /* */ + /* FT_ERR_EQ( errcode, err ) */ + /* FT_ERR_NEQ( errcode, err ) */ + /* Compare error code `errcode' with the error `err' for equality */ + /* and inequality, respectively. Example: */ + /* */ + /* if ( FT_ERR_EQ( error, Invalid_Outline ) ) */ + /* ... */ + /* */ + /* Using this macro you don't have to think about error prefixes. */ + /* Of course, if module errors are not active, the above example is */ + /* the same as */ + /* */ + /* if ( error == FT_Err_Invalid_Outline ) */ + /* ... */ + /* */ + /* FT_ERROR_BASE( errcode ) */ + /* FT_ERROR_MODULE( errcode ) */ + /* Get base error and module error code, respectively. */ + /* */ + /* */ + /* It can also be used to create a module error message table easily */ + /* with something like */ + /* */ + /* { */ + /* #undef FTMODERR_H_ */ + /* #define FT_MODERRDEF( e, v, s ) { FT_Mod_Err_ ## e, s }, */ + /* #define FT_MODERR_START_LIST { */ + /* #define FT_MODERR_END_LIST { 0, 0 } }; */ + /* */ + /* const struct */ + /* { */ + /* int mod_err_offset; */ + /* const char* mod_err_msg */ + /* } ft_mod_errors[] = */ + /* */ + /* #include FT_MODULE_ERRORS_H */ + /* } */ + /* */ + /*************************************************************************/ + + +#ifndef FTMODERR_H_ +#define FTMODERR_H_ + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** SETUP MACROS *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#undef FT_NEED_EXTERN_C + +#ifndef FT_MODERRDEF + +#ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS +#define FT_MODERRDEF( e, v, s ) FT_Mod_Err_ ## e = v, +#else +#define FT_MODERRDEF( e, v, s ) FT_Mod_Err_ ## e = 0, +#endif + +#define FT_MODERR_START_LIST enum { +#define FT_MODERR_END_LIST FT_Mod_Err_Max }; + +#ifdef __cplusplus +#define FT_NEED_EXTERN_C + extern "C" { +#endif + +#endif /* !FT_MODERRDEF */ + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** LIST MODULE ERROR BASES *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#ifdef FT_MODERR_START_LIST + FT_MODERR_START_LIST +#endif + + + FT_MODERRDEF( Base, 0x000, "base module" ) + FT_MODERRDEF( Autofit, 0x100, "autofitter module" ) + FT_MODERRDEF( BDF, 0x200, "BDF module" ) + FT_MODERRDEF( Bzip2, 0x300, "Bzip2 module" ) + FT_MODERRDEF( Cache, 0x400, "cache module" ) + FT_MODERRDEF( CFF, 0x500, "CFF module" ) + FT_MODERRDEF( CID, 0x600, "CID module" ) + FT_MODERRDEF( Gzip, 0x700, "Gzip module" ) + FT_MODERRDEF( LZW, 0x800, "LZW module" ) + FT_MODERRDEF( OTvalid, 0x900, "OpenType validation module" ) + FT_MODERRDEF( PCF, 0xA00, "PCF module" ) + FT_MODERRDEF( PFR, 0xB00, "PFR module" ) + FT_MODERRDEF( PSaux, 0xC00, "PS auxiliary module" ) + FT_MODERRDEF( PShinter, 0xD00, "PS hinter module" ) + FT_MODERRDEF( PSnames, 0xE00, "PS names module" ) + FT_MODERRDEF( Raster, 0xF00, "raster module" ) + FT_MODERRDEF( SFNT, 0x1000, "SFNT module" ) + FT_MODERRDEF( Smooth, 0x1100, "smooth raster module" ) + FT_MODERRDEF( TrueType, 0x1200, "TrueType module" ) + FT_MODERRDEF( Type1, 0x1300, "Type 1 module" ) + FT_MODERRDEF( Type42, 0x1400, "Type 42 module" ) + FT_MODERRDEF( Winfonts, 0x1500, "Windows FON/FNT module" ) + FT_MODERRDEF( GXvalid, 0x1600, "GX validation module" ) + + +#ifdef FT_MODERR_END_LIST + FT_MODERR_END_LIST +#endif + + + /*******************************************************************/ + /*******************************************************************/ + /***** *****/ + /***** CLEANUP *****/ + /***** *****/ + /*******************************************************************/ + /*******************************************************************/ + + +#ifdef FT_NEED_EXTERN_C + } +#endif + +#undef FT_MODERR_START_LIST +#undef FT_MODERR_END_LIST +#undef FT_MODERRDEF +#undef FT_NEED_EXTERN_C + + +#endif /* FTMODERR_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftotval.h b/freetype/include/freetype2/freetype/ftotval.h new file mode 100644 index 0000000..26731c2 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftotval.h @@ -0,0 +1,204 @@ +/***************************************************************************/ +/* */ +/* ftotval.h */ +/* */ +/* FreeType API for validating OpenType tables (specification). */ +/* */ +/* Copyright 2004-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/***************************************************************************/ +/* */ +/* */ +/* Warning: This module might be moved to a different library in the */ +/* future to avoid a tight dependency between FreeType and the */ +/* OpenType specification. */ +/* */ +/* */ +/***************************************************************************/ + + +#ifndef FTOTVAL_H_ +#define FTOTVAL_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* ot_validation */ + /* */ + /* <Title> */ + /* OpenType Validation */ + /* */ + /* <Abstract> */ + /* An API to validate OpenType tables. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions to validate */ + /* some OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH). */ + /* */ + /* <Order> */ + /* FT_OpenType_Validate */ + /* FT_OpenType_Free */ + /* */ + /* FT_VALIDATE_OTXXX */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @enum: + * FT_VALIDATE_OTXXX + * + * @description: + * A list of bit-field constants used with @FT_OpenType_Validate to + * indicate which OpenType tables should be validated. + * + * @values: + * FT_VALIDATE_BASE :: + * Validate BASE table. + * + * FT_VALIDATE_GDEF :: + * Validate GDEF table. + * + * FT_VALIDATE_GPOS :: + * Validate GPOS table. + * + * FT_VALIDATE_GSUB :: + * Validate GSUB table. + * + * FT_VALIDATE_JSTF :: + * Validate JSTF table. + * + * FT_VALIDATE_MATH :: + * Validate MATH table. + * + * FT_VALIDATE_OT :: + * Validate all OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH). + * + */ +#define FT_VALIDATE_BASE 0x0100 +#define FT_VALIDATE_GDEF 0x0200 +#define FT_VALIDATE_GPOS 0x0400 +#define FT_VALIDATE_GSUB 0x0800 +#define FT_VALIDATE_JSTF 0x1000 +#define FT_VALIDATE_MATH 0x2000 + +#define FT_VALIDATE_OT ( FT_VALIDATE_BASE | \ + FT_VALIDATE_GDEF | \ + FT_VALIDATE_GPOS | \ + FT_VALIDATE_GSUB | \ + FT_VALIDATE_JSTF | \ + FT_VALIDATE_MATH ) + + /********************************************************************** + * + * @function: + * FT_OpenType_Validate + * + * @description: + * Validate various OpenType tables to assure that all offsets and + * indices are valid. The idea is that a higher-level library that + * actually does the text layout can access those tables without + * error checking (which can be quite time consuming). + * + * @input: + * face :: + * A handle to the input face. + * + * validation_flags :: + * A bit field that specifies the tables to be validated. See + * @FT_VALIDATE_OTXXX for possible values. + * + * @output: + * BASE_table :: + * A pointer to the BASE table. + * + * GDEF_table :: + * A pointer to the GDEF table. + * + * GPOS_table :: + * A pointer to the GPOS table. + * + * GSUB_table :: + * A pointer to the GSUB table. + * + * JSTF_table :: + * A pointer to the JSTF table. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with OpenType fonts, returning an error + * otherwise. + * + * After use, the application should deallocate the five tables with + * @FT_OpenType_Free. A NULL value indicates that the table either + * doesn't exist in the font, or the application hasn't asked for + * validation. + */ + FT_EXPORT( FT_Error ) + FT_OpenType_Validate( FT_Face face, + FT_UInt validation_flags, + FT_Bytes *BASE_table, + FT_Bytes *GDEF_table, + FT_Bytes *GPOS_table, + FT_Bytes *GSUB_table, + FT_Bytes *JSTF_table ); + + /********************************************************************** + * + * @function: + * FT_OpenType_Free + * + * @description: + * Free the buffer allocated by OpenType validator. + * + * @input: + * face :: + * A handle to the input face. + * + * table :: + * The pointer to the buffer that is allocated by + * @FT_OpenType_Validate. + * + * @note: + * This function must be used to free the buffer allocated by + * @FT_OpenType_Validate only. + */ + FT_EXPORT( void ) + FT_OpenType_Free( FT_Face face, + FT_Bytes table ); + + /* */ + + +FT_END_HEADER + +#endif /* FTOTVAL_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftoutln.h b/freetype/include/freetype2/freetype/ftoutln.h new file mode 100644 index 0000000..89389a4 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftoutln.h @@ -0,0 +1,582 @@ +/***************************************************************************/ +/* */ +/* ftoutln.h */ +/* */ +/* Support for the FT_Outline type used to store glyph shapes of */ +/* most scalable font formats (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTOUTLN_H_ +#define FTOUTLN_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* outline_processing */ + /* */ + /* <Title> */ + /* Outline Processing */ + /* */ + /* <Abstract> */ + /* Functions to create, transform, and render vectorial glyph images. */ + /* */ + /* <Description> */ + /* This section contains routines used to create and destroy scalable */ + /* glyph images known as `outlines'. These can also be measured, */ + /* transformed, and converted into bitmaps and pixmaps. */ + /* */ + /* <Order> */ + /* FT_Outline */ + /* FT_Outline_New */ + /* FT_Outline_Done */ + /* FT_Outline_Copy */ + /* FT_Outline_Translate */ + /* FT_Outline_Transform */ + /* FT_Outline_Embolden */ + /* FT_Outline_EmboldenXY */ + /* FT_Outline_Reverse */ + /* FT_Outline_Check */ + /* */ + /* FT_Outline_Get_CBox */ + /* FT_Outline_Get_BBox */ + /* */ + /* FT_Outline_Get_Bitmap */ + /* FT_Outline_Render */ + /* FT_Outline_Decompose */ + /* FT_Outline_Funcs */ + /* FT_Outline_MoveToFunc */ + /* FT_Outline_LineToFunc */ + /* FT_Outline_ConicToFunc */ + /* FT_Outline_CubicToFunc */ + /* */ + /* FT_Orientation */ + /* FT_Outline_Get_Orientation */ + /* */ + /* FT_OUTLINE_XXX */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Decompose */ + /* */ + /* <Description> */ + /* Walk over an outline's structure to decompose it into individual */ + /* segments and Bezier arcs. This function also emits `move to' */ + /* operations to indicate the start of new contours in the outline. */ + /* */ + /* <Input> */ + /* outline :: A pointer to the source target. */ + /* */ + /* func_interface :: A table of `emitters', i.e., function pointers */ + /* called during decomposition to indicate path */ + /* operations. */ + /* */ + /* <InOut> */ + /* user :: A typeless pointer that is passed to each */ + /* emitter during the decomposition. It can be */ + /* used to store the state during the */ + /* decomposition. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* A contour that contains a single point only is represented by a */ + /* `move to' operation followed by `line to' to the same point. In */ + /* most cases, it is best to filter this out before using the */ + /* outline for stroking purposes (otherwise it would result in a */ + /* visible dot when round caps are used). */ + /* */ + /* Similarly, the function returns success for an empty outline also */ + /* (doing nothing, this is, not calling any emitter); if necessary, */ + /* you should filter this out, too. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Decompose( FT_Outline* outline, + const FT_Outline_Funcs* func_interface, + void* user ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_New */ + /* */ + /* <Description> */ + /* Create a new outline of a given size. */ + /* */ + /* <Input> */ + /* library :: A handle to the library object from where the */ + /* outline is allocated. Note however that the new */ + /* outline will *not* necessarily be *freed*, when */ + /* destroying the library, by @FT_Done_FreeType. */ + /* */ + /* numPoints :: The maximum number of points within the outline. */ + /* Must be smaller than or equal to 0xFFFF (65535). */ + /* */ + /* numContours :: The maximum number of contours within the outline. */ + /* This value must be in the range 0 to `numPoints'. */ + /* */ + /* <Output> */ + /* anoutline :: A handle to the new outline. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The reason why this function takes a `library' parameter is simply */ + /* to use the library's memory allocator. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_New( FT_Library library, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline *anoutline ); + + + FT_EXPORT( FT_Error ) + FT_Outline_New_Internal( FT_Memory memory, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline *anoutline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Done */ + /* */ + /* <Description> */ + /* Destroy an outline created with @FT_Outline_New. */ + /* */ + /* <Input> */ + /* library :: A handle of the library object used to allocate the */ + /* outline. */ + /* */ + /* outline :: A pointer to the outline object to be discarded. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If the outline's `owner' field is not set, only the outline */ + /* descriptor will be released. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Done( FT_Library library, + FT_Outline* outline ); + + + FT_EXPORT( FT_Error ) + FT_Outline_Done_Internal( FT_Memory memory, + FT_Outline* outline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Check */ + /* */ + /* <Description> */ + /* Check the contents of an outline descriptor. */ + /* */ + /* <Input> */ + /* outline :: A handle to a source outline. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* An empty outline, or an outline with a single point only is also */ + /* valid. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Check( FT_Outline* outline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Get_CBox */ + /* */ + /* <Description> */ + /* Return an outline's `control box'. The control box encloses all */ + /* the outline's points, including Bezier control points. Though it */ + /* coincides with the exact bounding box for most glyphs, it can be */ + /* slightly larger in some situations (like when rotating an outline */ + /* that contains Bezier outside arcs). */ + /* */ + /* Computing the control box is very fast, while getting the bounding */ + /* box can take much more time as it needs to walk over all segments */ + /* and arcs in the outline. To get the latter, you can use the */ + /* `ftbbox' component, which is dedicated to this single task. */ + /* */ + /* <Input> */ + /* outline :: A pointer to the source outline descriptor. */ + /* */ + /* <Output> */ + /* acbox :: The outline's control box. */ + /* */ + /* <Note> */ + /* See @FT_Glyph_Get_CBox for a discussion of tricky fonts. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Get_CBox( const FT_Outline* outline, + FT_BBox *acbox ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Translate */ + /* */ + /* <Description> */ + /* Apply a simple translation to the points of an outline. */ + /* */ + /* <InOut> */ + /* outline :: A pointer to the target outline descriptor. */ + /* */ + /* <Input> */ + /* xOffset :: The horizontal offset. */ + /* */ + /* yOffset :: The vertical offset. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Translate( const FT_Outline* outline, + FT_Pos xOffset, + FT_Pos yOffset ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Copy */ + /* */ + /* <Description> */ + /* Copy an outline into another one. Both objects must have the */ + /* same sizes (number of points & number of contours) when this */ + /* function is called. */ + /* */ + /* <Input> */ + /* source :: A handle to the source outline. */ + /* */ + /* <Output> */ + /* target :: A handle to the target outline. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Copy( const FT_Outline* source, + FT_Outline *target ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Transform */ + /* */ + /* <Description> */ + /* Apply a simple 2x2 matrix to all of an outline's points. Useful */ + /* for applying rotations, slanting, flipping, etc. */ + /* */ + /* <InOut> */ + /* outline :: A pointer to the target outline descriptor. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the transformation matrix. */ + /* */ + /* <Note> */ + /* You can use @FT_Outline_Translate if you need to translate the */ + /* outline's points. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Transform( const FT_Outline* outline, + const FT_Matrix* matrix ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Embolden */ + /* */ + /* <Description> */ + /* Embolden an outline. The new outline will be at most 4~times */ + /* `strength' pixels wider and higher. You may think of the left and */ + /* bottom borders as unchanged. */ + /* */ + /* Negative `strength' values to reduce the outline thickness are */ + /* possible also. */ + /* */ + /* <InOut> */ + /* outline :: A handle to the target outline. */ + /* */ + /* <Input> */ + /* strength :: How strong the glyph is emboldened. Expressed in */ + /* 26.6 pixel format. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The used algorithm to increase or decrease the thickness of the */ + /* glyph doesn't change the number of points; this means that certain */ + /* situations like acute angles or intersections are sometimes */ + /* handled incorrectly. */ + /* */ + /* If you need `better' metrics values you should call */ + /* @FT_Outline_Get_CBox or @FT_Outline_Get_BBox. */ + /* */ + /* Example call: */ + /* */ + /* { */ + /* FT_Load_Glyph( face, index, FT_LOAD_DEFAULT ); */ + /* if ( face->glyph->format == FT_GLYPH_FORMAT_OUTLINE ) */ + /* FT_Outline_Embolden( &face->glyph->outline, strength ); */ + /* } */ + /* */ + /* To get meaningful results, font scaling values must be set with */ + /* functions like @FT_Set_Char_Size before calling FT_Render_Glyph. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Embolden( FT_Outline* outline, + FT_Pos strength ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_EmboldenXY */ + /* */ + /* <Description> */ + /* Embolden an outline. The new outline will be `xstrength' pixels */ + /* wider and `ystrength' pixels higher. Otherwise, it is similar to */ + /* @FT_Outline_Embolden, which uses the same strength in both */ + /* directions. */ + /* */ + /* <Since> */ + /* 2.4.10 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_EmboldenXY( FT_Outline* outline, + FT_Pos xstrength, + FT_Pos ystrength ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Reverse */ + /* */ + /* <Description> */ + /* Reverse the drawing direction of an outline. This is used to */ + /* ensure consistent fill conventions for mirrored glyphs. */ + /* */ + /* <InOut> */ + /* outline :: A pointer to the target outline descriptor. */ + /* */ + /* <Note> */ + /* This function toggles the bit flag @FT_OUTLINE_REVERSE_FILL in */ + /* the outline's `flags' field. */ + /* */ + /* It shouldn't be used by a normal client application, unless it */ + /* knows what it is doing. */ + /* */ + FT_EXPORT( void ) + FT_Outline_Reverse( FT_Outline* outline ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Get_Bitmap */ + /* */ + /* <Description> */ + /* Render an outline within a bitmap. The outline's image is simply */ + /* OR-ed to the target bitmap. */ + /* */ + /* <Input> */ + /* library :: A handle to a FreeType library object. */ + /* */ + /* outline :: A pointer to the source outline descriptor. */ + /* */ + /* <InOut> */ + /* abitmap :: A pointer to the target bitmap descriptor. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function does NOT CREATE the bitmap, it only renders an */ + /* outline image within the one you pass to it! Consequently, the */ + /* various fields in `abitmap' should be set accordingly. */ + /* */ + /* It will use the raster corresponding to the default glyph format. */ + /* */ + /* The value of the `num_grays' field in `abitmap' is ignored. If */ + /* you select the gray-level rasterizer, and you want less than 256 */ + /* gray levels, you have to use @FT_Outline_Render directly. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Get_Bitmap( FT_Library library, + FT_Outline* outline, + const FT_Bitmap *abitmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Outline_Render */ + /* */ + /* <Description> */ + /* Render an outline within a bitmap using the current scan-convert. */ + /* This function uses an @FT_Raster_Params structure as an argument, */ + /* allowing advanced features like direct composition, translucency, */ + /* etc. */ + /* */ + /* <Input> */ + /* library :: A handle to a FreeType library object. */ + /* */ + /* outline :: A pointer to the source outline descriptor. */ + /* */ + /* <InOut> */ + /* params :: A pointer to an @FT_Raster_Params structure used to */ + /* describe the rendering operation. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You should know what you are doing and how @FT_Raster_Params works */ + /* to use this function. */ + /* */ + /* The field `params.source' will be set to `outline' before the scan */ + /* converter is called, which means that the value you give to it is */ + /* actually ignored. */ + /* */ + /* The gray-level rasterizer always uses 256 gray levels. If you */ + /* want less gray levels, you have to provide your own span callback. */ + /* See the @FT_RASTER_FLAG_DIRECT value of the `flags' field in the */ + /* @FT_Raster_Params structure for more details. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Outline_Render( FT_Library library, + FT_Outline* outline, + FT_Raster_Params* params ); + + + /************************************************************************** + * + * @enum: + * FT_Orientation + * + * @description: + * A list of values used to describe an outline's contour orientation. + * + * The TrueType and PostScript specifications use different conventions + * to determine whether outline contours should be filled or unfilled. + * + * @values: + * FT_ORIENTATION_TRUETYPE :: + * According to the TrueType specification, clockwise contours must + * be filled, and counter-clockwise ones must be unfilled. + * + * FT_ORIENTATION_POSTSCRIPT :: + * According to the PostScript specification, counter-clockwise contours + * must be filled, and clockwise ones must be unfilled. + * + * FT_ORIENTATION_FILL_RIGHT :: + * This is identical to @FT_ORIENTATION_TRUETYPE, but is used to + * remember that in TrueType, everything that is to the right of + * the drawing direction of a contour must be filled. + * + * FT_ORIENTATION_FILL_LEFT :: + * This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to + * remember that in PostScript, everything that is to the left of + * the drawing direction of a contour must be filled. + * + * FT_ORIENTATION_NONE :: + * The orientation cannot be determined. That is, different parts of + * the glyph have different orientation. + * + */ + typedef enum FT_Orientation_ + { + FT_ORIENTATION_TRUETYPE = 0, + FT_ORIENTATION_POSTSCRIPT = 1, + FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE, + FT_ORIENTATION_FILL_LEFT = FT_ORIENTATION_POSTSCRIPT, + FT_ORIENTATION_NONE + + } FT_Orientation; + + + /************************************************************************** + * + * @function: + * FT_Outline_Get_Orientation + * + * @description: + * This function analyzes a glyph outline and tries to compute its + * fill orientation (see @FT_Orientation). This is done by integrating + * the total area covered by the outline. The positive integral + * corresponds to the clockwise orientation and @FT_ORIENTATION_POSTSCRIPT + * is returned. The negative integral corresponds to the counter-clockwise + * orientation and @FT_ORIENTATION_TRUETYPE is returned. + * + * Note that this will return @FT_ORIENTATION_TRUETYPE for empty + * outlines. + * + * @input: + * outline :: + * A handle to the source outline. + * + * @return: + * The orientation. + * + */ + FT_EXPORT( FT_Orientation ) + FT_Outline_Get_Orientation( FT_Outline* outline ); + + /* */ + + +FT_END_HEADER + +#endif /* FTOUTLN_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/freetype/include/freetype2/freetype/ftparams.h b/freetype/include/freetype2/freetype/ftparams.h new file mode 100644 index 0000000..5a9006c --- /dev/null +++ b/freetype/include/freetype2/freetype/ftparams.h @@ -0,0 +1,205 @@ +/***************************************************************************/ +/* */ +/* ftparams.h */ +/* */ +/* FreeType API for possible FT_Parameter tags (specification only). */ +/* */ +/* Copyright 2017-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTPARAMS_H_ +#define FTPARAMS_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /************************************************************************** + * + * @section: + * parameter_tags + * + * @title: + * Parameter Tags + * + * @abstract: + * Macros for driver property and font loading parameter tags. + * + * @description: + * This section contains macros for the @FT_Parameter structure that are + * used with various functions to activate some special functionality or + * different behaviour of various components of FreeType. + * + */ + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY + * + * @description: + * A tag for @FT_Parameter to make @FT_Open_Face ignore typographic + * family names in the `name' table (introduced in OpenType version + * 1.4). Use this for backward compatibility with legacy systems that + * have a four-faces-per-family restriction. + * + * @since: + * 2.8 + * + */ +#define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY \ + FT_MAKE_TAG( 'i', 'g', 'p', 'f' ) + + + /* this constant is deprecated */ +#define FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY \ + FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY + * + * @description: + * A tag for @FT_Parameter to make @FT_Open_Face ignore typographic + * subfamily names in the `name' table (introduced in OpenType version + * 1.4). Use this for backward compatibility with legacy systems that + * have a four-faces-per-family restriction. + * + * @since: + * 2.8 + * + */ +#define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY \ + FT_MAKE_TAG( 'i', 'g', 'p', 's' ) + + + /* this constant is deprecated */ +#define FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY \ + FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_INCREMENTAL + * + * @description: + * An @FT_Parameter tag to be used with @FT_Open_Face to indicate + * incremental glyph loading. + * + */ +#define FT_PARAM_TAG_INCREMENTAL \ + FT_MAKE_TAG( 'i', 'n', 'c', 'r' ) + + + /************************************************************************** + * + * @constant: + * FT_PARAM_TAG_LCD_FILTER_WEIGHTS + * + * @description: + * An @FT_Parameter tag to be used with @FT_Face_Properties. The + * corresponding argument specifies the five LCD filter weights for a + * given face (if using @FT_LOAD_TARGET_LCD, for example), overriding + * the global default values or the values set up with + * @FT_Library_SetLcdFilterWeights. + * + * @since: + * 2.8 + * + */ +#define FT_PARAM_TAG_LCD_FILTER_WEIGHTS \ + FT_MAKE_TAG( 'l', 'c', 'd', 'f' ) + + + /************************************************************************** + * + * @constant: + * FT_PARAM_TAG_RANDOM_SEED + * + * @description: + * An @FT_Parameter tag to be used with @FT_Face_Properties. The + * corresponding 32bit signed integer argument overrides the font + * driver's random seed value with a face-specific one; see + * @random-seed. + * + * @since: + * 2.8 + * + */ +#define FT_PARAM_TAG_RANDOM_SEED \ + FT_MAKE_TAG( 's', 'e', 'e', 'd' ) + + + /************************************************************************** + * + * @constant: + * FT_PARAM_TAG_STEM_DARKENING + * + * @description: + * An @FT_Parameter tag to be used with @FT_Face_Properties. The + * corresponding Boolean argument specifies whether to apply stem + * darkening, overriding the global default values or the values set up + * with @FT_Property_Set (see @no-stem-darkening). + * + * This is a passive setting that only takes effect if the font driver + * or autohinter honors it, which the CFF, Type~1, and CID drivers + * always do, but the autohinter only in `light' hinting mode (as of + * version 2.9). + * + * @since: + * 2.8 + * + */ +#define FT_PARAM_TAG_STEM_DARKENING \ + FT_MAKE_TAG( 'd', 'a', 'r', 'k' ) + + + /*************************************************************************** + * + * @constant: + * FT_PARAM_TAG_UNPATENTED_HINTING + * + * @description: + * Deprecated, no effect. + * + * Previously: A constant used as the tag of an @FT_Parameter structure to + * indicate that unpatented methods only should be used by the TrueType + * bytecode interpreter for a typeface opened by @FT_Open_Face. + * + */ +#define FT_PARAM_TAG_UNPATENTED_HINTING \ + FT_MAKE_TAG( 'u', 'n', 'p', 'a' ) + + + /* */ + + +FT_END_HEADER + + +#endif /* FTPARAMS_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftpfr.h b/freetype/include/freetype2/freetype/ftpfr.h new file mode 100644 index 0000000..a69cc48 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftpfr.h @@ -0,0 +1,172 @@ +/***************************************************************************/ +/* */ +/* ftpfr.h */ +/* */ +/* FreeType API for accessing PFR-specific data (specification only). */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTPFR_H_ +#define FTPFR_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* pfr_fonts */ + /* */ + /* <Title> */ + /* PFR Fonts */ + /* */ + /* <Abstract> */ + /* PFR/TrueDoc specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of PFR-specific functions. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @function: + * FT_Get_PFR_Metrics + * + * @description: + * Return the outline and metrics resolutions of a given PFR face. + * + * @input: + * face :: Handle to the input face. It can be a non-PFR face. + * + * @output: + * aoutline_resolution :: + * Outline resolution. This is equivalent to `face->units_per_EM' + * for non-PFR fonts. Optional (parameter can be NULL). + * + * ametrics_resolution :: + * Metrics resolution. This is equivalent to `outline_resolution' + * for non-PFR fonts. Optional (parameter can be NULL). + * + * ametrics_x_scale :: + * A 16.16 fixed-point number used to scale distance expressed + * in metrics units to device subpixels. This is equivalent to + * `face->size->x_scale', but for metrics only. Optional (parameter + * can be NULL). + * + * ametrics_y_scale :: + * Same as `ametrics_x_scale' but for the vertical direction. + * optional (parameter can be NULL). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If the input face is not a PFR, this function will return an error. + * However, in all cases, it will return valid values. + */ + FT_EXPORT( FT_Error ) + FT_Get_PFR_Metrics( FT_Face face, + FT_UInt *aoutline_resolution, + FT_UInt *ametrics_resolution, + FT_Fixed *ametrics_x_scale, + FT_Fixed *ametrics_y_scale ); + + + /********************************************************************** + * + * @function: + * FT_Get_PFR_Kerning + * + * @description: + * Return the kerning pair corresponding to two glyphs in a PFR face. + * The distance is expressed in metrics units, unlike the result of + * @FT_Get_Kerning. + * + * @input: + * face :: A handle to the input face. + * + * left :: Index of the left glyph. + * + * right :: Index of the right glyph. + * + * @output: + * avector :: A kerning vector. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function always return distances in original PFR metrics + * units. This is unlike @FT_Get_Kerning with the @FT_KERNING_UNSCALED + * mode, which always returns distances converted to outline units. + * + * You can use the value of the `x_scale' and `y_scale' parameters + * returned by @FT_Get_PFR_Metrics to scale these to device subpixels. + */ + FT_EXPORT( FT_Error ) + FT_Get_PFR_Kerning( FT_Face face, + FT_UInt left, + FT_UInt right, + FT_Vector *avector ); + + + /********************************************************************** + * + * @function: + * FT_Get_PFR_Advance + * + * @description: + * Return a given glyph advance, expressed in original metrics units, + * from a PFR font. + * + * @input: + * face :: A handle to the input face. + * + * gindex :: The glyph index. + * + * @output: + * aadvance :: The glyph advance in metrics units. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You can use the `x_scale' or `y_scale' results of @FT_Get_PFR_Metrics + * to convert the advance to device subpixels (i.e., 1/64th of pixels). + */ + FT_EXPORT( FT_Error ) + FT_Get_PFR_Advance( FT_Face face, + FT_UInt gindex, + FT_Pos *aadvance ); + + /* */ + + +FT_END_HEADER + +#endif /* FTPFR_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftrender.h b/freetype/include/freetype2/freetype/ftrender.h new file mode 100644 index 0000000..fa8ad22 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftrender.h @@ -0,0 +1,233 @@ +/***************************************************************************/ +/* */ +/* ftrender.h */ +/* */ +/* FreeType renderer modules public interface (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTRENDER_H_ +#define FTRENDER_H_ + + +#include <ft2build.h> +#include FT_MODULE_H +#include FT_GLYPH_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /*************************************************************************/ + + + /* create a new glyph object */ + typedef FT_Error + (*FT_Glyph_InitFunc)( FT_Glyph glyph, + FT_GlyphSlot slot ); + + /* destroys a given glyph object */ + typedef void + (*FT_Glyph_DoneFunc)( FT_Glyph glyph ); + + typedef void + (*FT_Glyph_TransformFunc)( FT_Glyph glyph, + const FT_Matrix* matrix, + const FT_Vector* delta ); + + typedef void + (*FT_Glyph_GetBBoxFunc)( FT_Glyph glyph, + FT_BBox* abbox ); + + typedef FT_Error + (*FT_Glyph_CopyFunc)( FT_Glyph source, + FT_Glyph target ); + + typedef FT_Error + (*FT_Glyph_PrepareFunc)( FT_Glyph glyph, + FT_GlyphSlot slot ); + +/* deprecated */ +#define FT_Glyph_Init_Func FT_Glyph_InitFunc +#define FT_Glyph_Done_Func FT_Glyph_DoneFunc +#define FT_Glyph_Transform_Func FT_Glyph_TransformFunc +#define FT_Glyph_BBox_Func FT_Glyph_GetBBoxFunc +#define FT_Glyph_Copy_Func FT_Glyph_CopyFunc +#define FT_Glyph_Prepare_Func FT_Glyph_PrepareFunc + + + struct FT_Glyph_Class_ + { + FT_Long glyph_size; + FT_Glyph_Format glyph_format; + + FT_Glyph_InitFunc glyph_init; + FT_Glyph_DoneFunc glyph_done; + FT_Glyph_CopyFunc glyph_copy; + FT_Glyph_TransformFunc glyph_transform; + FT_Glyph_GetBBoxFunc glyph_bbox; + FT_Glyph_PrepareFunc glyph_prepare; + }; + + + typedef FT_Error + (*FT_Renderer_RenderFunc)( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_Render_Mode mode, + const FT_Vector* origin ); + + typedef FT_Error + (*FT_Renderer_TransformFunc)( FT_Renderer renderer, + FT_GlyphSlot slot, + const FT_Matrix* matrix, + const FT_Vector* delta ); + + + typedef void + (*FT_Renderer_GetCBoxFunc)( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_BBox* cbox ); + + + typedef FT_Error + (*FT_Renderer_SetModeFunc)( FT_Renderer renderer, + FT_ULong mode_tag, + FT_Pointer mode_ptr ); + +/* deprecated identifiers */ +#define FTRenderer_render FT_Renderer_RenderFunc +#define FTRenderer_transform FT_Renderer_TransformFunc +#define FTRenderer_getCBox FT_Renderer_GetCBoxFunc +#define FTRenderer_setMode FT_Renderer_SetModeFunc + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Renderer_Class */ + /* */ + /* <Description> */ + /* The renderer module class descriptor. */ + /* */ + /* <Fields> */ + /* root :: The root @FT_Module_Class fields. */ + /* */ + /* glyph_format :: The glyph image format this renderer handles. */ + /* */ + /* render_glyph :: A method used to render the image that is in a */ + /* given glyph slot into a bitmap. */ + /* */ + /* transform_glyph :: A method used to transform the image that is in */ + /* a given glyph slot. */ + /* */ + /* get_glyph_cbox :: A method used to access the glyph's cbox. */ + /* */ + /* set_mode :: A method used to pass additional parameters. */ + /* */ + /* raster_class :: For @FT_GLYPH_FORMAT_OUTLINE renderers only. */ + /* This is a pointer to its raster's class. */ + /* */ + typedef struct FT_Renderer_Class_ + { + FT_Module_Class root; + + FT_Glyph_Format glyph_format; + + FT_Renderer_RenderFunc render_glyph; + FT_Renderer_TransformFunc transform_glyph; + FT_Renderer_GetCBoxFunc get_glyph_cbox; + FT_Renderer_SetModeFunc set_mode; + + FT_Raster_Funcs* raster_class; + + } FT_Renderer_Class; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Renderer */ + /* */ + /* <Description> */ + /* Retrieve the current renderer for a given glyph format. */ + /* */ + /* <Input> */ + /* library :: A handle to the library object. */ + /* */ + /* format :: The glyph format. */ + /* */ + /* <Return> */ + /* A renderer handle. 0~if none found. */ + /* */ + /* <Note> */ + /* An error will be returned if a module already exists by that name, */ + /* or if the module requires a version of FreeType that is too great. */ + /* */ + /* To add a new renderer, simply use @FT_Add_Module. To retrieve a */ + /* renderer by its name, use @FT_Get_Module. */ + /* */ + FT_EXPORT( FT_Renderer ) + FT_Get_Renderer( FT_Library library, + FT_Glyph_Format format ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Renderer */ + /* */ + /* <Description> */ + /* Set the current renderer to use, and set additional mode. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library object. */ + /* */ + /* <Input> */ + /* renderer :: A handle to the renderer object. */ + /* */ + /* num_params :: The number of additional parameters. */ + /* */ + /* parameters :: Additional parameters. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* In case of success, the renderer will be used to convert glyph */ + /* images in the renderer's known format into bitmaps. */ + /* */ + /* This doesn't change the current renderer for other formats. */ + /* */ + /* Currently, no FreeType renderer module uses `parameters'; you */ + /* should thus always pass NULL as the value. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Renderer( FT_Library library, + FT_Renderer renderer, + FT_UInt num_params, + FT_Parameter* parameters ); + + /* */ + + +FT_END_HEADER + +#endif /* FTRENDER_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftsizes.h b/freetype/include/freetype2/freetype/ftsizes.h new file mode 100644 index 0000000..72cb08b --- /dev/null +++ b/freetype/include/freetype2/freetype/ftsizes.h @@ -0,0 +1,159 @@ +/***************************************************************************/ +/* */ +/* ftsizes.h */ +/* */ +/* FreeType size objects management (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Typical application would normally not need to use these functions. */ + /* However, they have been placed in a public API for the rare cases */ + /* where they are needed. */ + /* */ + /*************************************************************************/ + + +#ifndef FTSIZES_H_ +#define FTSIZES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* sizes_management */ + /* */ + /* <Title> */ + /* Size Management */ + /* */ + /* <Abstract> */ + /* Managing multiple sizes per face. */ + /* */ + /* <Description> */ + /* When creating a new face object (e.g., with @FT_New_Face), an */ + /* @FT_Size object is automatically created and used to store all */ + /* pixel-size dependent information, available in the `face->size' */ + /* field. */ + /* */ + /* It is however possible to create more sizes for a given face, */ + /* mostly in order to manage several character pixel sizes of the */ + /* same font family and style. See @FT_New_Size and @FT_Done_Size. */ + /* */ + /* Note that @FT_Set_Pixel_Sizes and @FT_Set_Char_Size only */ + /* modify the contents of the current `active' size; you thus need */ + /* to use @FT_Activate_Size to change it. */ + /* */ + /* 99% of applications won't need the functions provided here, */ + /* especially if they use the caching sub-system, so be cautious */ + /* when using these. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Size */ + /* */ + /* <Description> */ + /* Create a new size object from a given face object. */ + /* */ + /* <Input> */ + /* face :: A handle to a parent face object. */ + /* */ + /* <Output> */ + /* asize :: A handle to a new size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You need to call @FT_Activate_Size in order to select the new size */ + /* for upcoming calls to @FT_Set_Pixel_Sizes, @FT_Set_Char_Size, */ + /* @FT_Load_Glyph, @FT_Load_Char, etc. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Size( FT_Face face, + FT_Size* size ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Size */ + /* */ + /* <Description> */ + /* Discard a given size object. Note that @FT_Done_Face */ + /* automatically discards all size objects allocated with */ + /* @FT_New_Size. */ + /* */ + /* <Input> */ + /* size :: A handle to a target size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Size( FT_Size size ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Activate_Size */ + /* */ + /* <Description> */ + /* Even though it is possible to create several size objects for a */ + /* given face (see @FT_New_Size for details), functions like */ + /* @FT_Load_Glyph or @FT_Load_Char only use the one that has been */ + /* activated last to determine the `current character pixel size'. */ + /* */ + /* This function can be used to `activate' a previously created size */ + /* object. */ + /* */ + /* <Input> */ + /* size :: A handle to a target size object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* If `face' is the size's parent face object, this function changes */ + /* the value of `face->size' to the input size handle. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Activate_Size( FT_Size size ); + + /* */ + + +FT_END_HEADER + +#endif /* FTSIZES_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftsnames.h b/freetype/include/freetype2/freetype/ftsnames.h new file mode 100644 index 0000000..8eb8d70 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftsnames.h @@ -0,0 +1,253 @@ +/***************************************************************************/ +/* */ +/* ftsnames.h */ +/* */ +/* Simple interface to access SFNT `name' tables (which are used */ +/* to hold font names, copyright info, notices, etc.) (specification). */ +/* */ +/* This is _not_ used to retrieve glyph names! */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSNAMES_H_ +#define FTSNAMES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H +#include FT_PARAMETER_TAGS_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* sfnt_names */ + /* */ + /* <Title> */ + /* SFNT Names */ + /* */ + /* <Abstract> */ + /* Access the names embedded in TrueType and OpenType files. */ + /* */ + /* <Description> */ + /* The TrueType and OpenType specifications allow the inclusion of */ + /* a special names table (`name') in font files. This table contains */ + /* textual (and internationalized) information regarding the font, */ + /* like family name, copyright, version, etc. */ + /* */ + /* The definitions below are used to access them if available. */ + /* */ + /* Note that this has nothing to do with glyph names! */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SfntName */ + /* */ + /* <Description> */ + /* A structure used to model an SFNT `name' table entry. */ + /* */ + /* <Fields> */ + /* platform_id :: The platform ID for `string'. */ + /* See @TT_PLATFORM_XXX for possible values. */ + /* */ + /* encoding_id :: The encoding ID for `string'. */ + /* See @TT_APPLE_ID_XXX, @TT_MAC_ID_XXX, */ + /* @TT_ISO_ID_XXX, @TT_MS_ID_XXX, and @TT_ADOBE_ID_XXX */ + /* for possible values. */ + /* */ + /* language_id :: The language ID for `string'. */ + /* See @TT_MAC_LANGID_XXX and @TT_MS_LANGID_XXX for */ + /* possible values. */ + /* */ + /* Registered OpenType values for `language_id' are */ + /* always smaller than 0x8000; values equal or larger */ + /* than 0x8000 usually indicate a language tag string */ + /* (introduced in OpenType version 1.6). Use function */ + /* @FT_Get_Sfnt_LangTag with `language_id' as its */ + /* argument to retrieve the associated language tag. */ + /* */ + /* name_id :: An identifier for `string'. */ + /* See @TT_NAME_ID_XXX for possible values. */ + /* */ + /* string :: The `name' string. Note that its format differs */ + /* depending on the (platform,encoding) pair, being */ + /* either a string of bytes (without a terminating */ + /* NULL byte) or containing UTF-16BE entities. */ + /* */ + /* string_len :: The length of `string' in bytes. */ + /* */ + /* <Note> */ + /* Please refer to the TrueType or OpenType specification for more */ + /* details. */ + /* */ + typedef struct FT_SfntName_ + { + FT_UShort platform_id; + FT_UShort encoding_id; + FT_UShort language_id; + FT_UShort name_id; + + FT_Byte* string; /* this string is *not* null-terminated! */ + FT_UInt string_len; /* in bytes */ + + } FT_SfntName; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_Name_Count */ + /* */ + /* <Description> */ + /* Retrieve the number of name strings in the SFNT `name' table. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* <Return> */ + /* The number of strings in the `name' table. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Sfnt_Name_Count( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_Name */ + /* */ + /* <Description> */ + /* Retrieve a string of the SFNT `name' table for a given index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* idx :: The index of the `name' string. */ + /* */ + /* <Output> */ + /* aname :: The indexed @FT_SfntName structure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `string' array returned in the `aname' structure is not */ + /* null-terminated. Note that you don't have to deallocate `string' */ + /* by yourself; FreeType takes care of it if you call @FT_Done_Face. */ + /* */ + /* Use @FT_Get_Sfnt_Name_Count to get the total number of available */ + /* `name' table entries, then do a loop until you get the right */ + /* platform, encoding, and name ID. */ + /* */ + /* `name' table format~1 entries can use language tags also, see */ + /* @FT_Get_Sfnt_LangTag. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Sfnt_Name( FT_Face face, + FT_UInt idx, + FT_SfntName *aname ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SfntLangTag */ + /* */ + /* <Description> */ + /* A structure to model a language tag entry from an SFNT `name' */ + /* table. */ + /* */ + /* <Fields> */ + /* string :: The language tag string, encoded in UTF-16BE */ + /* (without trailing NULL bytes). */ + /* */ + /* string_len :: The length of `string' in *bytes*. */ + /* */ + /* <Note> */ + /* Please refer to the TrueType or OpenType specification for more */ + /* details. */ + /* */ + /* <Since> */ + /* 2.8 */ + /* */ + typedef struct FT_SfntLangTag_ + { + FT_Byte* string; /* this string is *not* null-terminated! */ + FT_UInt string_len; /* in bytes */ + + } FT_SfntLangTag; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_LangTag */ + /* */ + /* <Description> */ + /* Retrieve the language tag associated with a language ID of an SFNT */ + /* `name' table entry. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face. */ + /* */ + /* langID :: The language ID, as returned by @FT_Get_Sfnt_Name. */ + /* This is always a value larger than 0x8000. */ + /* */ + /* <Output> */ + /* alangTag :: The language tag associated with the `name' table */ + /* entry's language ID. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The `string' array returned in the `alangTag' structure is not */ + /* null-terminated. Note that you don't have to deallocate `string' */ + /* by yourself; FreeType takes care of it if you call @FT_Done_Face. */ + /* */ + /* Only `name' table format~1 supports language tags. For format~0 */ + /* tables, this function always returns FT_Err_Invalid_Table. For */ + /* invalid format~1 language ID values, FT_Err_Invalid_Argument is */ + /* returned. */ + /* */ + /* <Since> */ + /* 2.8 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Sfnt_LangTag( FT_Face face, + FT_UInt langID, + FT_SfntLangTag *alangTag ); + + + /* */ + + +FT_END_HEADER + +#endif /* FTSNAMES_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftstroke.h b/freetype/include/freetype2/freetype/ftstroke.h new file mode 100644 index 0000000..44b6fbe --- /dev/null +++ b/freetype/include/freetype2/freetype/ftstroke.h @@ -0,0 +1,785 @@ +/***************************************************************************/ +/* */ +/* ftstroke.h */ +/* */ +/* FreeType path stroker (specification). */ +/* */ +/* Copyright 2002-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSTROKE_H_ +#define FTSTROKE_H_ + +#include <ft2build.h> +#include FT_OUTLINE_H +#include FT_GLYPH_H + + +FT_BEGIN_HEADER + + + /************************************************************************ + * + * @section: + * glyph_stroker + * + * @title: + * Glyph Stroker + * + * @abstract: + * Generating bordered and stroked glyphs. + * + * @description: + * This component generates stroked outlines of a given vectorial + * glyph. It also allows you to retrieve the `outside' and/or the + * `inside' borders of the stroke. + * + * This can be useful to generate `bordered' glyph, i.e., glyphs + * displayed with a coloured (and anti-aliased) border around their + * shape. + * + * @order: + * FT_Stroker + * + * FT_Stroker_LineJoin + * FT_Stroker_LineCap + * FT_StrokerBorder + * + * FT_Outline_GetInsideBorder + * FT_Outline_GetOutsideBorder + * + * FT_Glyph_Stroke + * FT_Glyph_StrokeBorder + * + * FT_Stroker_New + * FT_Stroker_Set + * FT_Stroker_Rewind + * FT_Stroker_ParseOutline + * FT_Stroker_Done + * + * FT_Stroker_BeginSubPath + * FT_Stroker_EndSubPath + * + * FT_Stroker_LineTo + * FT_Stroker_ConicTo + * FT_Stroker_CubicTo + * + * FT_Stroker_GetBorderCounts + * FT_Stroker_ExportBorder + * FT_Stroker_GetCounts + * FT_Stroker_Export + * + */ + + + /************************************************************** + * + * @type: + * FT_Stroker + * + * @description: + * Opaque handle to a path stroker object. + */ + typedef struct FT_StrokerRec_* FT_Stroker; + + + /************************************************************** + * + * @enum: + * FT_Stroker_LineJoin + * + * @description: + * These values determine how two joining lines are rendered + * in a stroker. + * + * @values: + * FT_STROKER_LINEJOIN_ROUND :: + * Used to render rounded line joins. Circular arcs are used + * to join two lines smoothly. + * + * FT_STROKER_LINEJOIN_BEVEL :: + * Used to render beveled line joins. The outer corner of + * the joined lines is filled by enclosing the triangular + * region of the corner with a straight line between the + * outer corners of each stroke. + * + * FT_STROKER_LINEJOIN_MITER_FIXED :: + * Used to render mitered line joins, with fixed bevels if the + * miter limit is exceeded. The outer edges of the strokes + * for the two segments are extended until they meet at an + * angle. If the segments meet at too sharp an angle (such + * that the miter would extend from the intersection of the + * segments a distance greater than the product of the miter + * limit value and the border radius), then a bevel join (see + * above) is used instead. This prevents long spikes being + * created. FT_STROKER_LINEJOIN_MITER_FIXED generates a miter + * line join as used in PostScript and PDF. + * + * FT_STROKER_LINEJOIN_MITER_VARIABLE :: + * FT_STROKER_LINEJOIN_MITER :: + * Used to render mitered line joins, with variable bevels if + * the miter limit is exceeded. The intersection of the + * strokes is clipped at a line perpendicular to the bisector + * of the angle between the strokes, at the distance from the + * intersection of the segments equal to the product of the + * miter limit value and the border radius. This prevents + * long spikes being created. + * FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line + * join as used in XPS. FT_STROKER_LINEJOIN_MITER is an alias + * for FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for + * backward compatibility. + */ + typedef enum FT_Stroker_LineJoin_ + { + FT_STROKER_LINEJOIN_ROUND = 0, + FT_STROKER_LINEJOIN_BEVEL = 1, + FT_STROKER_LINEJOIN_MITER_VARIABLE = 2, + FT_STROKER_LINEJOIN_MITER = FT_STROKER_LINEJOIN_MITER_VARIABLE, + FT_STROKER_LINEJOIN_MITER_FIXED = 3 + + } FT_Stroker_LineJoin; + + + /************************************************************** + * + * @enum: + * FT_Stroker_LineCap + * + * @description: + * These values determine how the end of opened sub-paths are + * rendered in a stroke. + * + * @values: + * FT_STROKER_LINECAP_BUTT :: + * The end of lines is rendered as a full stop on the last + * point itself. + * + * FT_STROKER_LINECAP_ROUND :: + * The end of lines is rendered as a half-circle around the + * last point. + * + * FT_STROKER_LINECAP_SQUARE :: + * The end of lines is rendered as a square around the + * last point. + */ + typedef enum FT_Stroker_LineCap_ + { + FT_STROKER_LINECAP_BUTT = 0, + FT_STROKER_LINECAP_ROUND, + FT_STROKER_LINECAP_SQUARE + + } FT_Stroker_LineCap; + + + /************************************************************** + * + * @enum: + * FT_StrokerBorder + * + * @description: + * These values are used to select a given stroke border + * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder. + * + * @values: + * FT_STROKER_BORDER_LEFT :: + * Select the left border, relative to the drawing direction. + * + * FT_STROKER_BORDER_RIGHT :: + * Select the right border, relative to the drawing direction. + * + * @note: + * Applications are generally interested in the `inside' and `outside' + * borders. However, there is no direct mapping between these and the + * `left' and `right' ones, since this really depends on the glyph's + * drawing orientation, which varies between font formats. + * + * You can however use @FT_Outline_GetInsideBorder and + * @FT_Outline_GetOutsideBorder to get these. + */ + typedef enum FT_StrokerBorder_ + { + FT_STROKER_BORDER_LEFT = 0, + FT_STROKER_BORDER_RIGHT + + } FT_StrokerBorder; + + + /************************************************************** + * + * @function: + * FT_Outline_GetInsideBorder + * + * @description: + * Retrieve the @FT_StrokerBorder value corresponding to the + * `inside' borders of a given outline. + * + * @input: + * outline :: + * The source outline handle. + * + * @return: + * The border index. @FT_STROKER_BORDER_RIGHT for empty or invalid + * outlines. + */ + FT_EXPORT( FT_StrokerBorder ) + FT_Outline_GetInsideBorder( FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Outline_GetOutsideBorder + * + * @description: + * Retrieve the @FT_StrokerBorder value corresponding to the + * `outside' borders of a given outline. + * + * @input: + * outline :: + * The source outline handle. + * + * @return: + * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid + * outlines. + */ + FT_EXPORT( FT_StrokerBorder ) + FT_Outline_GetOutsideBorder( FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Stroker_New + * + * @description: + * Create a new stroker object. + * + * @input: + * library :: + * FreeType library handle. + * + * @output: + * astroker :: + * A new stroker object handle. NULL in case of error. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_New( FT_Library library, + FT_Stroker *astroker ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Set + * + * @description: + * Reset a stroker object's attributes. + * + * @input: + * stroker :: + * The target stroker handle. + * + * radius :: + * The border radius. + * + * line_cap :: + * The line cap style. + * + * line_join :: + * The line join style. + * + * miter_limit :: + * The miter limit for the FT_STROKER_LINEJOIN_MITER_FIXED and + * FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles, + * expressed as 16.16 fixed-point value. + * + * @note: + * The radius is expressed in the same units as the outline + * coordinates. + * + * This function calls @FT_Stroker_Rewind automatically. + */ + FT_EXPORT( void ) + FT_Stroker_Set( FT_Stroker stroker, + FT_Fixed radius, + FT_Stroker_LineCap line_cap, + FT_Stroker_LineJoin line_join, + FT_Fixed miter_limit ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Rewind + * + * @description: + * Reset a stroker object without changing its attributes. + * You should call this function before beginning a new + * series of calls to @FT_Stroker_BeginSubPath or + * @FT_Stroker_EndSubPath. + * + * @input: + * stroker :: + * The target stroker handle. + */ + FT_EXPORT( void ) + FT_Stroker_Rewind( FT_Stroker stroker ); + + + /************************************************************** + * + * @function: + * FT_Stroker_ParseOutline + * + * @description: + * A convenience function used to parse a whole outline with + * the stroker. The resulting outline(s) can be retrieved + * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export. + * + * @input: + * stroker :: + * The target stroker handle. + * + * outline :: + * The source outline. + * + * opened :: + * A boolean. If~1, the outline is treated as an open path instead + * of a closed one. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If `opened' is~0 (the default), the outline is treated as a closed + * path, and the stroker generates two distinct `border' outlines. + * + * If `opened' is~1, the outline is processed as an open path, and the + * stroker generates a single `stroke' outline. + * + * This function calls @FT_Stroker_Rewind automatically. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_ParseOutline( FT_Stroker stroker, + FT_Outline* outline, + FT_Bool opened ); + + + /************************************************************** + * + * @function: + * FT_Stroker_BeginSubPath + * + * @description: + * Start a new sub-path in the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * to :: + * A pointer to the start vector. + * + * open :: + * A boolean. If~1, the sub-path is treated as an open one. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function is useful when you need to stroke a path that is + * not stored as an @FT_Outline object. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_BeginSubPath( FT_Stroker stroker, + FT_Vector* to, + FT_Bool open ); + + + /************************************************************** + * + * @function: + * FT_Stroker_EndSubPath + * + * @description: + * Close the current sub-path in the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function after @FT_Stroker_BeginSubPath. + * If the subpath was not `opened', this function `draws' a + * single line segment to the start position when needed. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_EndSubPath( FT_Stroker stroker ); + + + /************************************************************** + * + * @function: + * FT_Stroker_LineTo + * + * @description: + * `Draw' a single line segment in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_LineTo( FT_Stroker stroker, + FT_Vector* to ); + + + /************************************************************** + * + * @function: + * FT_Stroker_ConicTo + * + * @description: + * `Draw' a single quadratic Bezier in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * control :: + * A pointer to a Bezier control point. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_ConicTo( FT_Stroker stroker, + FT_Vector* control, + FT_Vector* to ); + + + /************************************************************** + * + * @function: + * FT_Stroker_CubicTo + * + * @description: + * `Draw' a single cubic Bezier in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * control1 :: + * A pointer to the first Bezier control point. + * + * control2 :: + * A pointer to second Bezier control point. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_CubicTo( FT_Stroker stroker, + FT_Vector* control1, + FT_Vector* control2, + FT_Vector* to ); + + + /************************************************************** + * + * @function: + * FT_Stroker_GetBorderCounts + * + * @description: + * Call this function once you have finished parsing your paths + * with the stroker. It returns the number of points and + * contours necessary to export one of the `border' or `stroke' + * outlines generated by the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * border :: + * The border index. + * + * @output: + * anum_points :: + * The number of points. + * + * anum_contours :: + * The number of contours. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * When an outline, or a sub-path, is `closed', the stroker generates + * two independent `border' outlines, named `left' and `right'. + * + * When the outline, or a sub-path, is `opened', the stroker merges + * the `border' outlines with caps. The `left' border receives all + * points, while the `right' border becomes empty. + * + * Use the function @FT_Stroker_GetCounts instead if you want to + * retrieve the counts associated to both borders. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_GetBorderCounts( FT_Stroker stroker, + FT_StrokerBorder border, + FT_UInt *anum_points, + FT_UInt *anum_contours ); + + + /************************************************************** + * + * @function: + * FT_Stroker_ExportBorder + * + * @description: + * Call this function after @FT_Stroker_GetBorderCounts to + * export the corresponding border to your own @FT_Outline + * structure. + * + * Note that this function appends the border points and + * contours to your outline, but does not try to resize its + * arrays. + * + * @input: + * stroker :: + * The target stroker handle. + * + * border :: + * The border index. + * + * outline :: + * The target outline handle. + * + * @note: + * Always call this function after @FT_Stroker_GetBorderCounts to + * get sure that there is enough room in your @FT_Outline object to + * receive all new data. + * + * When an outline, or a sub-path, is `closed', the stroker generates + * two independent `border' outlines, named `left' and `right'. + * + * When the outline, or a sub-path, is `opened', the stroker merges + * the `border' outlines with caps. The `left' border receives all + * points, while the `right' border becomes empty. + * + * Use the function @FT_Stroker_Export instead if you want to + * retrieve all borders at once. + */ + FT_EXPORT( void ) + FT_Stroker_ExportBorder( FT_Stroker stroker, + FT_StrokerBorder border, + FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Stroker_GetCounts + * + * @description: + * Call this function once you have finished parsing your paths + * with the stroker. It returns the number of points and + * contours necessary to export all points/borders from the stroked + * outline/path. + * + * @input: + * stroker :: + * The target stroker handle. + * + * @output: + * anum_points :: + * The number of points. + * + * anum_contours :: + * The number of contours. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Stroker_GetCounts( FT_Stroker stroker, + FT_UInt *anum_points, + FT_UInt *anum_contours ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Export + * + * @description: + * Call this function after @FT_Stroker_GetBorderCounts to + * export all borders to your own @FT_Outline structure. + * + * Note that this function appends the border points and + * contours to your outline, but does not try to resize its + * arrays. + * + * @input: + * stroker :: + * The target stroker handle. + * + * outline :: + * The target outline handle. + */ + FT_EXPORT( void ) + FT_Stroker_Export( FT_Stroker stroker, + FT_Outline* outline ); + + + /************************************************************** + * + * @function: + * FT_Stroker_Done + * + * @description: + * Destroy a stroker object. + * + * @input: + * stroker :: + * A stroker handle. Can be NULL. + */ + FT_EXPORT( void ) + FT_Stroker_Done( FT_Stroker stroker ); + + + /************************************************************** + * + * @function: + * FT_Glyph_Stroke + * + * @description: + * Stroke a given outline glyph object with a given stroker. + * + * @inout: + * pglyph :: + * Source glyph handle on input, new glyph handle on output. + * + * @input: + * stroker :: + * A stroker handle. + * + * destroy :: + * A Boolean. If~1, the source glyph object is destroyed + * on success. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source glyph is untouched in case of error. + * + * Adding stroke may yield a significantly wider and taller glyph + * depending on how large of a radius was used to stroke the glyph. You + * may need to manually adjust horizontal and vertical advance amounts + * to account for this added size. + */ + FT_EXPORT( FT_Error ) + FT_Glyph_Stroke( FT_Glyph *pglyph, + FT_Stroker stroker, + FT_Bool destroy ); + + + /************************************************************** + * + * @function: + * FT_Glyph_StrokeBorder + * + * @description: + * Stroke a given outline glyph object with a given stroker, but + * only return either its inside or outside border. + * + * @inout: + * pglyph :: + * Source glyph handle on input, new glyph handle on output. + * + * @input: + * stroker :: + * A stroker handle. + * + * inside :: + * A Boolean. If~1, return the inside border, otherwise + * the outside border. + * + * destroy :: + * A Boolean. If~1, the source glyph object is destroyed + * on success. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The source glyph is untouched in case of error. + * + * Adding stroke may yield a significantly wider and taller glyph + * depending on how large of a radius was used to stroke the glyph. You + * may need to manually adjust horizontal and vertical advance amounts + * to account for this added size. + */ + FT_EXPORT( FT_Error ) + FT_Glyph_StrokeBorder( FT_Glyph *pglyph, + FT_Stroker stroker, + FT_Bool inside, + FT_Bool destroy ); + + /* */ + +FT_END_HEADER + +#endif /* FTSTROKE_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/freetype/include/freetype2/freetype/ftsynth.h b/freetype/include/freetype2/freetype/ftsynth.h new file mode 100644 index 0000000..ff9fb43 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftsynth.h @@ -0,0 +1,84 @@ +/***************************************************************************/ +/* */ +/* ftsynth.h */ +/* */ +/* FreeType synthesizing code for emboldening and slanting */ +/* (specification). */ +/* */ +/* Copyright 2000-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS ALPHA CODE! THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /* Main reason for not lifting the functions in this module to a */ + /* `standard' API is that the used parameters for emboldening and */ + /* slanting are not configurable. Consider the functions as a */ + /* code resource that should be copied into the application and */ + /* adapted to the particular needs. */ + + +#ifndef FTSYNTH_H_ +#define FTSYNTH_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /* Embolden a glyph by a `reasonable' value (which is highly a matter of */ + /* taste). This function is actually a convenience function, providing */ + /* a wrapper for @FT_Outline_Embolden and @FT_Bitmap_Embolden. */ + /* */ + /* For emboldened outlines the height, width, and advance metrics are */ + /* increased by the strength of the emboldening -- this even affects */ + /* mono-width fonts! */ + /* */ + /* You can also call @FT_Outline_Get_CBox to get precise values. */ + FT_EXPORT( void ) + FT_GlyphSlot_Embolden( FT_GlyphSlot slot ); + + /* Slant an outline glyph to the right by about 12 degrees. */ + FT_EXPORT( void ) + FT_GlyphSlot_Oblique( FT_GlyphSlot slot ); + + /* */ + + +FT_END_HEADER + +#endif /* FTSYNTH_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftsystem.h b/freetype/include/freetype2/freetype/ftsystem.h new file mode 100644 index 0000000..f6b1629 --- /dev/null +++ b/freetype/include/freetype2/freetype/ftsystem.h @@ -0,0 +1,355 @@ +/***************************************************************************/ +/* */ +/* ftsystem.h */ +/* */ +/* FreeType low-level system interface definition (specification). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSYSTEM_H_ +#define FTSYSTEM_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* system_interface */ + /* */ + /* <Title> */ + /* System Interface */ + /* */ + /* <Abstract> */ + /* How FreeType manages memory and i/o. */ + /* */ + /* <Description> */ + /* This section contains various definitions related to memory */ + /* management and i/o access. You need to understand this */ + /* information if you want to use a custom memory manager or you own */ + /* i/o streams. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* M E M O R Y M A N A G E M E N T */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: + * FT_Memory + * + * @description: + * A handle to a given memory manager object, defined with an + * @FT_MemoryRec structure. + * + */ + typedef struct FT_MemoryRec_* FT_Memory; + + + /************************************************************************* + * + * @functype: + * FT_Alloc_Func + * + * @description: + * A function used to allocate `size' bytes from `memory'. + * + * @input: + * memory :: + * A handle to the source memory manager. + * + * size :: + * The size in bytes to allocate. + * + * @return: + * Address of new memory block. 0~in case of failure. + * + */ + typedef void* + (*FT_Alloc_Func)( FT_Memory memory, + long size ); + + + /************************************************************************* + * + * @functype: + * FT_Free_Func + * + * @description: + * A function used to release a given block of memory. + * + * @input: + * memory :: + * A handle to the source memory manager. + * + * block :: + * The address of the target memory block. + * + */ + typedef void + (*FT_Free_Func)( FT_Memory memory, + void* block ); + + + /************************************************************************* + * + * @functype: + * FT_Realloc_Func + * + * @description: + * A function used to re-allocate a given block of memory. + * + * @input: + * memory :: + * A handle to the source memory manager. + * + * cur_size :: + * The block's current size in bytes. + * + * new_size :: + * The block's requested new size. + * + * block :: + * The block's current address. + * + * @return: + * New block address. 0~in case of memory shortage. + * + * @note: + * In case of error, the old block must still be available. + * + */ + typedef void* + (*FT_Realloc_Func)( FT_Memory memory, + long cur_size, + long new_size, + void* block ); + + + /************************************************************************* + * + * @struct: + * FT_MemoryRec + * + * @description: + * A structure used to describe a given memory manager to FreeType~2. + * + * @fields: + * user :: + * A generic typeless pointer for user data. + * + * alloc :: + * A pointer type to an allocation function. + * + * free :: + * A pointer type to an memory freeing function. + * + * realloc :: + * A pointer type to a reallocation function. + * + */ + struct FT_MemoryRec_ + { + void* user; + FT_Alloc_Func alloc; + FT_Free_Func free; + FT_Realloc_Func realloc; + }; + + + /*************************************************************************/ + /* */ + /* I / O M A N A G E M E N T */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: + * FT_Stream + * + * @description: + * A handle to an input stream. + * + * @also: + * See @FT_StreamRec for the publicly accessible fields of a given + * stream object. + * + */ + typedef struct FT_StreamRec_* FT_Stream; + + + /************************************************************************* + * + * @struct: + * FT_StreamDesc + * + * @description: + * A union type used to store either a long or a pointer. This is used + * to store a file descriptor or a `FILE*' in an input stream. + * + */ + typedef union FT_StreamDesc_ + { + long value; + void* pointer; + + } FT_StreamDesc; + + + /************************************************************************* + * + * @functype: + * FT_Stream_IoFunc + * + * @description: + * A function used to seek and read data from a given input stream. + * + * @input: + * stream :: + * A handle to the source stream. + * + * offset :: + * The offset of read in stream (always from start). + * + * buffer :: + * The address of the read buffer. + * + * count :: + * The number of bytes to read from the stream. + * + * @return: + * The number of bytes effectively read by the stream. + * + * @note: + * This function might be called to perform a seek or skip operation + * with a `count' of~0. A non-zero return value then indicates an + * error. + * + */ + typedef unsigned long + (*FT_Stream_IoFunc)( FT_Stream stream, + unsigned long offset, + unsigned char* buffer, + unsigned long count ); + + + /************************************************************************* + * + * @functype: + * FT_Stream_CloseFunc + * + * @description: + * A function used to close a given input stream. + * + * @input: + * stream :: + * A handle to the target stream. + * + */ + typedef void + (*FT_Stream_CloseFunc)( FT_Stream stream ); + + + /************************************************************************* + * + * @struct: + * FT_StreamRec + * + * @description: + * A structure used to describe an input stream. + * + * @input: + * base :: + * For memory-based streams, this is the address of the first stream + * byte in memory. This field should always be set to NULL for + * disk-based streams. + * + * size :: + * The stream size in bytes. + * + * In case of compressed streams where the size is unknown before + * actually doing the decompression, the value is set to 0x7FFFFFFF. + * (Note that this size value can occur for normal streams also; it is + * thus just a hint.) + * + * pos :: + * The current position within the stream. + * + * descriptor :: + * This field is a union that can hold an integer or a pointer. It is + * used by stream implementations to store file descriptors or `FILE*' + * pointers. + * + * pathname :: + * This field is completely ignored by FreeType. However, it is often + * useful during debugging to use it to store the stream's filename + * (where available). + * + * read :: + * The stream's input function. + * + * close :: + * The stream's close function. + * + * memory :: + * The memory manager to use to preload frames. This is set + * internally by FreeType and shouldn't be touched by stream + * implementations. + * + * cursor :: + * This field is set and used internally by FreeType when parsing + * frames. + * + * limit :: + * This field is set and used internally by FreeType when parsing + * frames. + * + */ + typedef struct FT_StreamRec_ + { + unsigned char* base; + unsigned long size; + unsigned long pos; + + FT_StreamDesc descriptor; + FT_StreamDesc pathname; + FT_Stream_IoFunc read; + FT_Stream_CloseFunc close; + + FT_Memory memory; + unsigned char* cursor; + unsigned char* limit; + + } FT_StreamRec; + + /* */ + + +FT_END_HEADER + +#endif /* FTSYSTEM_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/fttrigon.h b/freetype/include/freetype2/freetype/fttrigon.h new file mode 100644 index 0000000..2e3f3f1 --- /dev/null +++ b/freetype/include/freetype2/freetype/fttrigon.h @@ -0,0 +1,350 @@ +/***************************************************************************/ +/* */ +/* fttrigon.h */ +/* */ +/* FreeType trigonometric functions (specification). */ +/* */ +/* Copyright 2001-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTTRIGON_H_ +#define FTTRIGON_H_ + +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @type: + * FT_Angle + * + * @description: + * This type is used to model angle values in FreeType. Note that the + * angle is a 16.16 fixed-point value expressed in degrees. + * + */ + typedef FT_Fixed FT_Angle; + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_PI + * + * @description: + * The angle pi expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_PI ( 180L << 16 ) + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_2PI + * + * @description: + * The angle 2*pi expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_2PI ( FT_ANGLE_PI * 2 ) + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_PI2 + * + * @description: + * The angle pi/2 expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_PI2 ( FT_ANGLE_PI / 2 ) + + + /************************************************************************* + * + * @macro: + * FT_ANGLE_PI4 + * + * @description: + * The angle pi/4 expressed in @FT_Angle units. + * + */ +#define FT_ANGLE_PI4 ( FT_ANGLE_PI / 4 ) + + + /************************************************************************* + * + * @function: + * FT_Sin + * + * @description: + * Return the sinus of a given angle in fixed-point format. + * + * @input: + * angle :: + * The input angle. + * + * @return: + * The sinus value. + * + * @note: + * If you need both the sinus and cosinus for a given angle, use the + * function @FT_Vector_Unit. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Sin( FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Cos + * + * @description: + * Return the cosinus of a given angle in fixed-point format. + * + * @input: + * angle :: + * The input angle. + * + * @return: + * The cosinus value. + * + * @note: + * If you need both the sinus and cosinus for a given angle, use the + * function @FT_Vector_Unit. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Cos( FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Tan + * + * @description: + * Return the tangent of a given angle in fixed-point format. + * + * @input: + * angle :: + * The input angle. + * + * @return: + * The tangent value. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Tan( FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Atan2 + * + * @description: + * Return the arc-tangent corresponding to a given vector (x,y) in + * the 2d plane. + * + * @input: + * x :: + * The horizontal vector coordinate. + * + * y :: + * The vertical vector coordinate. + * + * @return: + * The arc-tangent value (i.e. angle). + * + */ + FT_EXPORT( FT_Angle ) + FT_Atan2( FT_Fixed x, + FT_Fixed y ); + + + /************************************************************************* + * + * @function: + * FT_Angle_Diff + * + * @description: + * Return the difference between two angles. The result is always + * constrained to the ]-PI..PI] interval. + * + * @input: + * angle1 :: + * First angle. + * + * angle2 :: + * Second angle. + * + * @return: + * Constrained value of `value2-value1'. + * + */ + FT_EXPORT( FT_Angle ) + FT_Angle_Diff( FT_Angle angle1, + FT_Angle angle2 ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Unit + * + * @description: + * Return the unit vector corresponding to a given angle. After the + * call, the value of `vec.x' will be `cos(angle)', and the value of + * `vec.y' will be `sin(angle)'. + * + * This function is useful to retrieve both the sinus and cosinus of a + * given angle quickly. + * + * @output: + * vec :: + * The address of target vector. + * + * @input: + * angle :: + * The input angle. + * + */ + FT_EXPORT( void ) + FT_Vector_Unit( FT_Vector* vec, + FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Rotate + * + * @description: + * Rotate a vector by a given angle. + * + * @inout: + * vec :: + * The address of target vector. + * + * @input: + * angle :: + * The input angle. + * + */ + FT_EXPORT( void ) + FT_Vector_Rotate( FT_Vector* vec, + FT_Angle angle ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Length + * + * @description: + * Return the length of a given vector. + * + * @input: + * vec :: + * The address of target vector. + * + * @return: + * The vector length, expressed in the same units that the original + * vector coordinates. + * + */ + FT_EXPORT( FT_Fixed ) + FT_Vector_Length( FT_Vector* vec ); + + + /************************************************************************* + * + * @function: + * FT_Vector_Polarize + * + * @description: + * Compute both the length and angle of a given vector. + * + * @input: + * vec :: + * The address of source vector. + * + * @output: + * length :: + * The vector length. + * + * angle :: + * The vector angle. + * + */ + FT_EXPORT( void ) + FT_Vector_Polarize( FT_Vector* vec, + FT_Fixed *length, + FT_Angle *angle ); + + + /************************************************************************* + * + * @function: + * FT_Vector_From_Polar + * + * @description: + * Compute vector coordinates from a length and angle. + * + * @output: + * vec :: + * The address of source vector. + * + * @input: + * length :: + * The vector length. + * + * angle :: + * The vector angle. + * + */ + FT_EXPORT( void ) + FT_Vector_From_Polar( FT_Vector* vec, + FT_Fixed length, + FT_Angle angle ); + + /* */ + + +FT_END_HEADER + +#endif /* FTTRIGON_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/fttypes.h b/freetype/include/freetype2/freetype/fttypes.h new file mode 100644 index 0000000..f638c2e --- /dev/null +++ b/freetype/include/freetype2/freetype/fttypes.h @@ -0,0 +1,602 @@ +/***************************************************************************/ +/* */ +/* fttypes.h */ +/* */ +/* FreeType simple types definitions (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTTYPES_H_ +#define FTTYPES_H_ + + +#include <ft2build.h> +#include FT_CONFIG_CONFIG_H +#include FT_SYSTEM_H +#include FT_IMAGE_H + +#include <stddef.h> + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* basic_types */ + /* */ + /* <Title> */ + /* Basic Data Types */ + /* */ + /* <Abstract> */ + /* The basic data types defined by the library. */ + /* */ + /* <Description> */ + /* This section contains the basic data types defined by FreeType~2, */ + /* ranging from simple scalar types to bitmap descriptors. More */ + /* font-specific structures are defined in a different section. */ + /* */ + /* <Order> */ + /* FT_Byte */ + /* FT_Bytes */ + /* FT_Char */ + /* FT_Int */ + /* FT_UInt */ + /* FT_Int16 */ + /* FT_UInt16 */ + /* FT_Int32 */ + /* FT_UInt32 */ + /* FT_Int64 */ + /* FT_UInt64 */ + /* FT_Short */ + /* FT_UShort */ + /* FT_Long */ + /* FT_ULong */ + /* FT_Bool */ + /* FT_Offset */ + /* FT_PtrDist */ + /* FT_String */ + /* FT_Tag */ + /* FT_Error */ + /* FT_Fixed */ + /* FT_Pointer */ + /* FT_Pos */ + /* FT_Vector */ + /* FT_BBox */ + /* FT_Matrix */ + /* FT_FWord */ + /* FT_UFWord */ + /* FT_F2Dot14 */ + /* FT_UnitVector */ + /* FT_F26Dot6 */ + /* FT_Data */ + /* */ + /* FT_MAKE_TAG */ + /* */ + /* FT_Generic */ + /* FT_Generic_Finalizer */ + /* */ + /* FT_Bitmap */ + /* FT_Pixel_Mode */ + /* FT_Palette_Mode */ + /* FT_Glyph_Format */ + /* FT_IMAGE_TAG */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Bool */ + /* */ + /* <Description> */ + /* A typedef of unsigned char, used for simple booleans. As usual, */ + /* values 1 and~0 represent true and false, respectively. */ + /* */ + typedef unsigned char FT_Bool; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_FWord */ + /* */ + /* <Description> */ + /* A signed 16-bit integer used to store a distance in original font */ + /* units. */ + /* */ + typedef signed short FT_FWord; /* distance in FUnits */ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_UFWord */ + /* */ + /* <Description> */ + /* An unsigned 16-bit integer used to store a distance in original */ + /* font units. */ + /* */ + typedef unsigned short FT_UFWord; /* unsigned distance */ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Char */ + /* */ + /* <Description> */ + /* A simple typedef for the _signed_ char type. */ + /* */ + typedef signed char FT_Char; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Byte */ + /* */ + /* <Description> */ + /* A simple typedef for the _unsigned_ char type. */ + /* */ + typedef unsigned char FT_Byte; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Bytes */ + /* */ + /* <Description> */ + /* A typedef for constant memory areas. */ + /* */ + typedef const FT_Byte* FT_Bytes; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Tag */ + /* */ + /* <Description> */ + /* A typedef for 32-bit tags (as used in the SFNT format). */ + /* */ + typedef FT_UInt32 FT_Tag; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_String */ + /* */ + /* <Description> */ + /* A simple typedef for the char type, usually used for strings. */ + /* */ + typedef char FT_String; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Short */ + /* */ + /* <Description> */ + /* A typedef for signed short. */ + /* */ + typedef signed short FT_Short; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_UShort */ + /* */ + /* <Description> */ + /* A typedef for unsigned short. */ + /* */ + typedef unsigned short FT_UShort; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Int */ + /* */ + /* <Description> */ + /* A typedef for the int type. */ + /* */ + typedef signed int FT_Int; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_UInt */ + /* */ + /* <Description> */ + /* A typedef for the unsigned int type. */ + /* */ + typedef unsigned int FT_UInt; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Long */ + /* */ + /* <Description> */ + /* A typedef for signed long. */ + /* */ + typedef signed long FT_Long; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_ULong */ + /* */ + /* <Description> */ + /* A typedef for unsigned long. */ + /* */ + typedef unsigned long FT_ULong; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_F2Dot14 */ + /* */ + /* <Description> */ + /* A signed 2.14 fixed-point type used for unit vectors. */ + /* */ + typedef signed short FT_F2Dot14; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_F26Dot6 */ + /* */ + /* <Description> */ + /* A signed 26.6 fixed-point type used for vectorial pixel */ + /* coordinates. */ + /* */ + typedef signed long FT_F26Dot6; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Fixed */ + /* */ + /* <Description> */ + /* This type is used to store 16.16 fixed-point values, like scaling */ + /* values or matrix coefficients. */ + /* */ + typedef signed long FT_Fixed; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Error */ + /* */ + /* <Description> */ + /* The FreeType error code type. A value of~0 is always interpreted */ + /* as a successful operation. */ + /* */ + typedef int FT_Error; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Pointer */ + /* */ + /* <Description> */ + /* A simple typedef for a typeless pointer. */ + /* */ + typedef void* FT_Pointer; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Offset */ + /* */ + /* <Description> */ + /* This is equivalent to the ANSI~C `size_t' type, i.e., the largest */ + /* _unsigned_ integer type used to express a file size or position, */ + /* or a memory block size. */ + /* */ + typedef size_t FT_Offset; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_PtrDist */ + /* */ + /* <Description> */ + /* This is equivalent to the ANSI~C `ptrdiff_t' type, i.e., the */ + /* largest _signed_ integer type used to express the distance */ + /* between two pointers. */ + /* */ + typedef ft_ptrdiff_t FT_PtrDist; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_UnitVector */ + /* */ + /* <Description> */ + /* A simple structure used to store a 2D vector unit vector. Uses */ + /* FT_F2Dot14 types. */ + /* */ + /* <Fields> */ + /* x :: Horizontal coordinate. */ + /* */ + /* y :: Vertical coordinate. */ + /* */ + typedef struct FT_UnitVector_ + { + FT_F2Dot14 x; + FT_F2Dot14 y; + + } FT_UnitVector; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Matrix */ + /* */ + /* <Description> */ + /* A simple structure used to store a 2x2 matrix. Coefficients are */ + /* in 16.16 fixed-point format. The computation performed is: */ + /* */ + /* { */ + /* x' = x*xx + y*xy */ + /* y' = x*yx + y*yy */ + /* } */ + /* */ + /* <Fields> */ + /* xx :: Matrix coefficient. */ + /* */ + /* xy :: Matrix coefficient. */ + /* */ + /* yx :: Matrix coefficient. */ + /* */ + /* yy :: Matrix coefficient. */ + /* */ + typedef struct FT_Matrix_ + { + FT_Fixed xx, xy; + FT_Fixed yx, yy; + + } FT_Matrix; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Data */ + /* */ + /* <Description> */ + /* Read-only binary data represented as a pointer and a length. */ + /* */ + /* <Fields> */ + /* pointer :: The data. */ + /* */ + /* length :: The length of the data in bytes. */ + /* */ + typedef struct FT_Data_ + { + const FT_Byte* pointer; + FT_Int length; + + } FT_Data; + + + /*************************************************************************/ + /* */ + /* <FuncType> */ + /* FT_Generic_Finalizer */ + /* */ + /* <Description> */ + /* Describe a function used to destroy the `client' data of any */ + /* FreeType object. See the description of the @FT_Generic type for */ + /* details of usage. */ + /* */ + /* <Input> */ + /* The address of the FreeType object that is under finalization. */ + /* Its client data is accessed through its `generic' field. */ + /* */ + typedef void (*FT_Generic_Finalizer)( void* object ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Generic */ + /* */ + /* <Description> */ + /* Client applications often need to associate their own data to a */ + /* variety of FreeType core objects. For example, a text layout API */ + /* might want to associate a glyph cache to a given size object. */ + /* */ + /* Some FreeType object contains a `generic' field, of type */ + /* FT_Generic, which usage is left to client applications and font */ + /* servers. */ + /* */ + /* It can be used to store a pointer to client-specific data, as well */ + /* as the address of a `finalizer' function, which will be called by */ + /* FreeType when the object is destroyed (for example, the previous */ + /* client example would put the address of the glyph cache destructor */ + /* in the `finalizer' field). */ + /* */ + /* <Fields> */ + /* data :: A typeless pointer to any client-specified data. This */ + /* field is completely ignored by the FreeType library. */ + /* */ + /* finalizer :: A pointer to a `generic finalizer' function, which */ + /* will be called when the object is destroyed. If this */ + /* field is set to NULL, no code will be called. */ + /* */ + typedef struct FT_Generic_ + { + void* data; + FT_Generic_Finalizer finalizer; + + } FT_Generic; + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_MAKE_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags that are used to label */ + /* TrueType tables into an unsigned long, to be used within FreeType. */ + /* */ + /* <Note> */ + /* The produced values *must* be 32-bit integers. Don't redefine */ + /* this macro. */ + /* */ +#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \ + (FT_Tag) \ + ( ( (FT_ULong)_x1 << 24 ) | \ + ( (FT_ULong)_x2 << 16 ) | \ + ( (FT_ULong)_x3 << 8 ) | \ + (FT_ULong)_x4 ) + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* L I S T M A N A G E M E N T */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* list_processing */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_ListNode */ + /* */ + /* <Description> */ + /* Many elements and objects in FreeType are listed through an */ + /* @FT_List record (see @FT_ListRec). As its name suggests, an */ + /* FT_ListNode is a handle to a single list element. */ + /* */ + typedef struct FT_ListNodeRec_* FT_ListNode; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_List */ + /* */ + /* <Description> */ + /* A handle to a list record (see @FT_ListRec). */ + /* */ + typedef struct FT_ListRec_* FT_List; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_ListNodeRec */ + /* */ + /* <Description> */ + /* A structure used to hold a single list element. */ + /* */ + /* <Fields> */ + /* prev :: The previous element in the list. NULL if first. */ + /* */ + /* next :: The next element in the list. NULL if last. */ + /* */ + /* data :: A typeless pointer to the listed object. */ + /* */ + typedef struct FT_ListNodeRec_ + { + FT_ListNode prev; + FT_ListNode next; + void* data; + + } FT_ListNodeRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_ListRec */ + /* */ + /* <Description> */ + /* A structure used to hold a simple doubly-linked list. These are */ + /* used in many parts of FreeType. */ + /* */ + /* <Fields> */ + /* head :: The head (first element) of doubly-linked list. */ + /* */ + /* tail :: The tail (last element) of doubly-linked list. */ + /* */ + typedef struct FT_ListRec_ + { + FT_ListNode head; + FT_ListNode tail; + + } FT_ListRec; + + /* */ + + +#define FT_IS_EMPTY( list ) ( (list).head == 0 ) +#define FT_BOOL( x ) ( (FT_Bool)( x ) ) + + /* concatenate C tokens */ +#define FT_ERR_XCAT( x, y ) x ## y +#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y ) + + /* see `ftmoderr.h' for descriptions of the following macros */ + +#define FT_ERR( e ) FT_ERR_CAT( FT_ERR_PREFIX, e ) + +#define FT_ERROR_BASE( x ) ( (x) & 0xFF ) +#define FT_ERROR_MODULE( x ) ( (x) & 0xFF00U ) + +#define FT_ERR_EQ( x, e ) \ + ( FT_ERROR_BASE( x ) == FT_ERROR_BASE( FT_ERR( e ) ) ) +#define FT_ERR_NEQ( x, e ) \ + ( FT_ERROR_BASE( x ) != FT_ERROR_BASE( FT_ERR( e ) ) ) + + +FT_END_HEADER + +#endif /* FTTYPES_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ftwinfnt.h b/freetype/include/freetype2/freetype/ftwinfnt.h new file mode 100644 index 0000000..461c65b --- /dev/null +++ b/freetype/include/freetype2/freetype/ftwinfnt.h @@ -0,0 +1,275 @@ +/***************************************************************************/ +/* */ +/* ftwinfnt.h */ +/* */ +/* FreeType API for accessing Windows fnt-specific data. */ +/* */ +/* Copyright 2003-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTWINFNT_H_ +#define FTWINFNT_H_ + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* winfnt_fonts */ + /* */ + /* <Title> */ + /* Window FNT Files */ + /* */ + /* <Abstract> */ + /* Windows FNT specific API. */ + /* */ + /* <Description> */ + /* This section contains the declaration of Windows FNT specific */ + /* functions. */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @enum: + * FT_WinFNT_ID_XXX + * + * @description: + * A list of valid values for the `charset' byte in + * @FT_WinFNT_HeaderRec. Exact mapping tables for the various cpXXXX + * encodings (except for cp1361) can be found at + * ftp://ftp.unicode.org/Public in the MAPPINGS/VENDORS/MICSFT/WINDOWS + * subdirectory. cp1361 is roughly a superset of + * MAPPINGS/OBSOLETE/EASTASIA/KSC/JOHAB.TXT. + * + * @values: + * FT_WinFNT_ID_DEFAULT :: + * This is used for font enumeration and font creation as a + * `don't care' value. Valid font files don't contain this value. + * When querying for information about the character set of the font + * that is currently selected into a specified device context, this + * return value (of the related Windows API) simply denotes failure. + * + * FT_WinFNT_ID_SYMBOL :: + * There is no known mapping table available. + * + * FT_WinFNT_ID_MAC :: + * Mac Roman encoding. + * + * FT_WinFNT_ID_OEM :: + * From Michael Poettgen <michael@poettgen.de>: + * + * The `Windows Font Mapping' article says that FT_WinFNT_ID_OEM + * is used for the charset of vector fonts, like `modern.fon', + * `roman.fon', and `script.fon' on Windows. + * + * The `CreateFont' documentation says: The FT_WinFNT_ID_OEM value + * specifies a character set that is operating-system dependent. + * + * The `IFIMETRICS' documentation from the `Windows Driver + * Development Kit' says: This font supports an OEM-specific + * character set. The OEM character set is system dependent. + * + * In general OEM, as opposed to ANSI (i.e., cp1252), denotes the + * second default codepage that most international versions of + * Windows have. It is one of the OEM codepages from + * + * https://msdn.microsoft.com/en-us/goglobal/bb964655, + * + * and is used for the `DOS boxes', to support legacy applications. + * A German Windows version for example usually uses ANSI codepage + * 1252 and OEM codepage 850. + * + * FT_WinFNT_ID_CP874 :: + * A superset of Thai TIS 620 and ISO 8859-11. + * + * FT_WinFNT_ID_CP932 :: + * A superset of Japanese Shift-JIS (with minor deviations). + * + * FT_WinFNT_ID_CP936 :: + * A superset of simplified Chinese GB 2312-1980 (with different + * ordering and minor deviations). + * + * FT_WinFNT_ID_CP949 :: + * A superset of Korean Hangul KS~C 5601-1987 (with different + * ordering and minor deviations). + * + * FT_WinFNT_ID_CP950 :: + * A superset of traditional Chinese Big~5 ETen (with different + * ordering and minor deviations). + * + * FT_WinFNT_ID_CP1250 :: + * A superset of East European ISO 8859-2 (with slightly different + * ordering). + * + * FT_WinFNT_ID_CP1251 :: + * A superset of Russian ISO 8859-5 (with different ordering). + * + * FT_WinFNT_ID_CP1252 :: + * ANSI encoding. A superset of ISO 8859-1. + * + * FT_WinFNT_ID_CP1253 :: + * A superset of Greek ISO 8859-7 (with minor modifications). + * + * FT_WinFNT_ID_CP1254 :: + * A superset of Turkish ISO 8859-9. + * + * FT_WinFNT_ID_CP1255 :: + * A superset of Hebrew ISO 8859-8 (with some modifications). + * + * FT_WinFNT_ID_CP1256 :: + * A superset of Arabic ISO 8859-6 (with different ordering). + * + * FT_WinFNT_ID_CP1257 :: + * A superset of Baltic ISO 8859-13 (with some deviations). + * + * FT_WinFNT_ID_CP1258 :: + * For Vietnamese. This encoding doesn't cover all necessary + * characters. + * + * FT_WinFNT_ID_CP1361 :: + * Korean (Johab). + */ + +#define FT_WinFNT_ID_CP1252 0 +#define FT_WinFNT_ID_DEFAULT 1 +#define FT_WinFNT_ID_SYMBOL 2 +#define FT_WinFNT_ID_MAC 77 +#define FT_WinFNT_ID_CP932 128 +#define FT_WinFNT_ID_CP949 129 +#define FT_WinFNT_ID_CP1361 130 +#define FT_WinFNT_ID_CP936 134 +#define FT_WinFNT_ID_CP950 136 +#define FT_WinFNT_ID_CP1253 161 +#define FT_WinFNT_ID_CP1254 162 +#define FT_WinFNT_ID_CP1258 163 +#define FT_WinFNT_ID_CP1255 177 +#define FT_WinFNT_ID_CP1256 178 +#define FT_WinFNT_ID_CP1257 186 +#define FT_WinFNT_ID_CP1251 204 +#define FT_WinFNT_ID_CP874 222 +#define FT_WinFNT_ID_CP1250 238 +#define FT_WinFNT_ID_OEM 255 + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_WinFNT_HeaderRec */ + /* */ + /* <Description> */ + /* Windows FNT Header info. */ + /* */ + typedef struct FT_WinFNT_HeaderRec_ + { + FT_UShort version; + FT_ULong file_size; + FT_Byte copyright[60]; + FT_UShort file_type; + FT_UShort nominal_point_size; + FT_UShort vertical_resolution; + FT_UShort horizontal_resolution; + FT_UShort ascent; + FT_UShort internal_leading; + FT_UShort external_leading; + FT_Byte italic; + FT_Byte underline; + FT_Byte strike_out; + FT_UShort weight; + FT_Byte charset; + FT_UShort pixel_width; + FT_UShort pixel_height; + FT_Byte pitch_and_family; + FT_UShort avg_width; + FT_UShort max_width; + FT_Byte first_char; + FT_Byte last_char; + FT_Byte default_char; + FT_Byte break_char; + FT_UShort bytes_per_row; + FT_ULong device_offset; + FT_ULong face_name_offset; + FT_ULong bits_pointer; + FT_ULong bits_offset; + FT_Byte reserved; + FT_ULong flags; + FT_UShort A_space; + FT_UShort B_space; + FT_UShort C_space; + FT_UShort color_table_offset; + FT_ULong reserved1[4]; + + } FT_WinFNT_HeaderRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_WinFNT_Header */ + /* */ + /* <Description> */ + /* A handle to an @FT_WinFNT_HeaderRec structure. */ + /* */ + typedef struct FT_WinFNT_HeaderRec_* FT_WinFNT_Header; + + + /********************************************************************** + * + * @function: + * FT_Get_WinFNT_Header + * + * @description: + * Retrieve a Windows FNT font info header. + * + * @input: + * face :: A handle to the input face. + * + * @output: + * aheader :: The WinFNT header. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * This function only works with Windows FNT faces, returning an error + * otherwise. + */ + FT_EXPORT( FT_Error ) + FT_Get_WinFNT_Header( FT_Face face, + FT_WinFNT_HeaderRec *aheader ); + + /* */ + + +FT_END_HEADER + +#endif /* FTWINFNT_H_ */ + + +/* END */ + + +/* Local Variables: */ +/* coding: utf-8 */ +/* End: */ diff --git a/freetype/include/freetype2/freetype/t1tables.h b/freetype/include/freetype2/freetype/t1tables.h new file mode 100644 index 0000000..3503c26 --- /dev/null +++ b/freetype/include/freetype2/freetype/t1tables.h @@ -0,0 +1,770 @@ +/***************************************************************************/ +/* */ +/* t1tables.h */ +/* */ +/* Basic Type 1/Type 2 tables definitions and interface (specification */ +/* only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef T1TABLES_H_ +#define T1TABLES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* type1_tables */ + /* */ + /* <Title> */ + /* Type 1 Tables */ + /* */ + /* <Abstract> */ + /* Type~1 (PostScript) specific font tables. */ + /* */ + /* <Description> */ + /* This section contains the definition of Type 1-specific tables, */ + /* including structures related to other PostScript font formats. */ + /* */ + /* <Order> */ + /* PS_FontInfoRec */ + /* PS_FontInfo */ + /* PS_PrivateRec */ + /* PS_Private */ + /* */ + /* CID_FaceDictRec */ + /* CID_FaceDict */ + /* CID_FaceInfoRec */ + /* CID_FaceInfo */ + /* */ + /* FT_Has_PS_Glyph_Names */ + /* FT_Get_PS_Font_Info */ + /* FT_Get_PS_Font_Private */ + /* FT_Get_PS_Font_Value */ + /* */ + /* T1_Blend_Flags */ + /* T1_EncodingType */ + /* PS_Dict_Keys */ + /* */ + /*************************************************************************/ + + + /* Note that we separate font data in PS_FontInfoRec and PS_PrivateRec */ + /* structures in order to support Multiple Master fonts. */ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_FontInfoRec */ + /* */ + /* <Description> */ + /* A structure used to model a Type~1 or Type~2 FontInfo dictionary. */ + /* Note that for Multiple Master fonts, each instance has its own */ + /* FontInfo dictionary. */ + /* */ + typedef struct PS_FontInfoRec_ + { + FT_String* version; + FT_String* notice; + FT_String* full_name; + FT_String* family_name; + FT_String* weight; + FT_Long italic_angle; + FT_Bool is_fixed_pitch; + FT_Short underline_position; + FT_UShort underline_thickness; + + } PS_FontInfoRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_FontInfo */ + /* */ + /* <Description> */ + /* A handle to a @PS_FontInfoRec structure. */ + /* */ + typedef struct PS_FontInfoRec_* PS_FontInfo; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* T1_FontInfo */ + /* */ + /* <Description> */ + /* This type is equivalent to @PS_FontInfoRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef PS_FontInfoRec T1_FontInfo; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_PrivateRec */ + /* */ + /* <Description> */ + /* A structure used to model a Type~1 or Type~2 private dictionary. */ + /* Note that for Multiple Master fonts, each instance has its own */ + /* Private dictionary. */ + /* */ + typedef struct PS_PrivateRec_ + { + FT_Int unique_id; + FT_Int lenIV; + + FT_Byte num_blue_values; + FT_Byte num_other_blues; + FT_Byte num_family_blues; + FT_Byte num_family_other_blues; + + FT_Short blue_values[14]; + FT_Short other_blues[10]; + + FT_Short family_blues [14]; + FT_Short family_other_blues[10]; + + FT_Fixed blue_scale; + FT_Int blue_shift; + FT_Int blue_fuzz; + + FT_UShort standard_width[1]; + FT_UShort standard_height[1]; + + FT_Byte num_snap_widths; + FT_Byte num_snap_heights; + FT_Bool force_bold; + FT_Bool round_stem_up; + + FT_Short snap_widths [13]; /* including std width */ + FT_Short snap_heights[13]; /* including std height */ + + FT_Fixed expansion_factor; + + FT_Long language_group; + FT_Long password; + + FT_Short min_feature[2]; + + } PS_PrivateRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* PS_Private */ + /* */ + /* <Description> */ + /* A handle to a @PS_PrivateRec structure. */ + /* */ + typedef struct PS_PrivateRec_* PS_Private; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* T1_Private */ + /* */ + /* <Description> */ + /* This type is equivalent to @PS_PrivateRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef PS_PrivateRec T1_Private; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* T1_Blend_Flags */ + /* */ + /* <Description> */ + /* A set of flags used to indicate which fields are present in a */ + /* given blend dictionary (font info or private). Used to support */ + /* Multiple Masters fonts. */ + /* */ + /* <Values> */ + /* T1_BLEND_UNDERLINE_POSITION :: */ + /* T1_BLEND_UNDERLINE_THICKNESS :: */ + /* T1_BLEND_ITALIC_ANGLE :: */ + /* T1_BLEND_BLUE_VALUES :: */ + /* T1_BLEND_OTHER_BLUES :: */ + /* T1_BLEND_STANDARD_WIDTH :: */ + /* T1_BLEND_STANDARD_HEIGHT :: */ + /* T1_BLEND_STEM_SNAP_WIDTHS :: */ + /* T1_BLEND_STEM_SNAP_HEIGHTS :: */ + /* T1_BLEND_BLUE_SCALE :: */ + /* T1_BLEND_BLUE_SHIFT :: */ + /* T1_BLEND_FAMILY_BLUES :: */ + /* T1_BLEND_FAMILY_OTHER_BLUES :: */ + /* T1_BLEND_FORCE_BOLD :: */ + /* */ + typedef enum T1_Blend_Flags_ + { + /* required fields in a FontInfo blend dictionary */ + T1_BLEND_UNDERLINE_POSITION = 0, + T1_BLEND_UNDERLINE_THICKNESS, + T1_BLEND_ITALIC_ANGLE, + + /* required fields in a Private blend dictionary */ + T1_BLEND_BLUE_VALUES, + T1_BLEND_OTHER_BLUES, + T1_BLEND_STANDARD_WIDTH, + T1_BLEND_STANDARD_HEIGHT, + T1_BLEND_STEM_SNAP_WIDTHS, + T1_BLEND_STEM_SNAP_HEIGHTS, + T1_BLEND_BLUE_SCALE, + T1_BLEND_BLUE_SHIFT, + T1_BLEND_FAMILY_BLUES, + T1_BLEND_FAMILY_OTHER_BLUES, + T1_BLEND_FORCE_BOLD, + + T1_BLEND_MAX /* do not remove */ + + } T1_Blend_Flags; + + + /* these constants are deprecated; use the corresponding */ + /* `T1_Blend_Flags' values instead */ +#define t1_blend_underline_position T1_BLEND_UNDERLINE_POSITION +#define t1_blend_underline_thickness T1_BLEND_UNDERLINE_THICKNESS +#define t1_blend_italic_angle T1_BLEND_ITALIC_ANGLE +#define t1_blend_blue_values T1_BLEND_BLUE_VALUES +#define t1_blend_other_blues T1_BLEND_OTHER_BLUES +#define t1_blend_standard_widths T1_BLEND_STANDARD_WIDTH +#define t1_blend_standard_height T1_BLEND_STANDARD_HEIGHT +#define t1_blend_stem_snap_widths T1_BLEND_STEM_SNAP_WIDTHS +#define t1_blend_stem_snap_heights T1_BLEND_STEM_SNAP_HEIGHTS +#define t1_blend_blue_scale T1_BLEND_BLUE_SCALE +#define t1_blend_blue_shift T1_BLEND_BLUE_SHIFT +#define t1_blend_family_blues T1_BLEND_FAMILY_BLUES +#define t1_blend_family_other_blues T1_BLEND_FAMILY_OTHER_BLUES +#define t1_blend_force_bold T1_BLEND_FORCE_BOLD +#define t1_blend_max T1_BLEND_MAX + + /* */ + + + /* maximum number of Multiple Masters designs, as defined in the spec */ +#define T1_MAX_MM_DESIGNS 16 + + /* maximum number of Multiple Masters axes, as defined in the spec */ +#define T1_MAX_MM_AXIS 4 + + /* maximum number of elements in a design map */ +#define T1_MAX_MM_MAP_POINTS 20 + + + /* this structure is used to store the BlendDesignMap entry for an axis */ + typedef struct PS_DesignMap_ + { + FT_Byte num_points; + FT_Long* design_points; + FT_Fixed* blend_points; + + } PS_DesignMapRec, *PS_DesignMap; + + /* backward compatible definition */ + typedef PS_DesignMapRec T1_DesignMap; + + + typedef struct PS_BlendRec_ + { + FT_UInt num_designs; + FT_UInt num_axis; + + FT_String* axis_names[T1_MAX_MM_AXIS]; + FT_Fixed* design_pos[T1_MAX_MM_DESIGNS]; + PS_DesignMapRec design_map[T1_MAX_MM_AXIS]; + + FT_Fixed* weight_vector; + FT_Fixed* default_weight_vector; + + PS_FontInfo font_infos[T1_MAX_MM_DESIGNS + 1]; + PS_Private privates [T1_MAX_MM_DESIGNS + 1]; + + FT_ULong blend_bitflags; + + FT_BBox* bboxes [T1_MAX_MM_DESIGNS + 1]; + + /* since 2.3.0 */ + + /* undocumented, optional: the default design instance; */ + /* corresponds to default_weight_vector -- */ + /* num_default_design_vector == 0 means it is not present */ + /* in the font and associated metrics files */ + FT_UInt default_design_vector[T1_MAX_MM_DESIGNS]; + FT_UInt num_default_design_vector; + + } PS_BlendRec, *PS_Blend; + + + /* backward compatible definition */ + typedef PS_BlendRec T1_Blend; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceDictRec */ + /* */ + /* <Description> */ + /* A structure used to represent data in a CID top-level dictionary. */ + /* */ + typedef struct CID_FaceDictRec_ + { + PS_PrivateRec private_dict; + + FT_UInt len_buildchar; + FT_Fixed forcebold_threshold; + FT_Pos stroke_width; + FT_Fixed expansion_factor; + + FT_Byte paint_type; + FT_Byte font_type; + FT_Matrix font_matrix; + FT_Vector font_offset; + + FT_UInt num_subrs; + FT_ULong subrmap_offset; + FT_Int sd_bytes; + + } CID_FaceDictRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceDict */ + /* */ + /* <Description> */ + /* A handle to a @CID_FaceDictRec structure. */ + /* */ + typedef struct CID_FaceDictRec_* CID_FaceDict; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FontDict */ + /* */ + /* <Description> */ + /* This type is equivalent to @CID_FaceDictRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef CID_FaceDictRec CID_FontDict; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceInfoRec */ + /* */ + /* <Description> */ + /* A structure used to represent CID Face information. */ + /* */ + typedef struct CID_FaceInfoRec_ + { + FT_String* cid_font_name; + FT_Fixed cid_version; + FT_Int cid_font_type; + + FT_String* registry; + FT_String* ordering; + FT_Int supplement; + + PS_FontInfoRec font_info; + FT_BBox font_bbox; + FT_ULong uid_base; + + FT_Int num_xuid; + FT_ULong xuid[16]; + + FT_ULong cidmap_offset; + FT_Int fd_bytes; + FT_Int gd_bytes; + FT_ULong cid_count; + + FT_Int num_dicts; + CID_FaceDict font_dicts; + + FT_ULong data_offset; + + } CID_FaceInfoRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_FaceInfo */ + /* */ + /* <Description> */ + /* A handle to a @CID_FaceInfoRec structure. */ + /* */ + typedef struct CID_FaceInfoRec_* CID_FaceInfo; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* CID_Info */ + /* */ + /* <Description> */ + /* This type is equivalent to @CID_FaceInfoRec. It is deprecated but */ + /* kept to maintain source compatibility between various versions of */ + /* FreeType. */ + /* */ + typedef CID_FaceInfoRec CID_Info; + + + /************************************************************************ + * + * @function: + * FT_Has_PS_Glyph_Names + * + * @description: + * Return true if a given face provides reliable PostScript glyph + * names. This is similar to using the @FT_HAS_GLYPH_NAMES macro, + * except that certain fonts (mostly TrueType) contain incorrect + * glyph name tables. + * + * When this function returns true, the caller is sure that the glyph + * names returned by @FT_Get_Glyph_Name are reliable. + * + * @input: + * face :: + * face handle + * + * @return: + * Boolean. True if glyph names are reliable. + * + */ + FT_EXPORT( FT_Int ) + FT_Has_PS_Glyph_Names( FT_Face face ); + + + /************************************************************************ + * + * @function: + * FT_Get_PS_Font_Info + * + * @description: + * Retrieve the @PS_FontInfoRec structure corresponding to a given + * PostScript font. + * + * @input: + * face :: + * PostScript face handle. + * + * @output: + * afont_info :: + * Output font info structure pointer. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * String pointers within the @PS_FontInfoRec structure are owned by + * the face and don't need to be freed by the caller. Missing entries + * in the font's FontInfo dictionary are represented by NULL pointers. + * + * If the font's format is not PostScript-based, this function will + * return the `FT_Err_Invalid_Argument' error code. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_PS_Font_Info( FT_Face face, + PS_FontInfo afont_info ); + + + /************************************************************************ + * + * @function: + * FT_Get_PS_Font_Private + * + * @description: + * Retrieve the @PS_PrivateRec structure corresponding to a given + * PostScript font. + * + * @input: + * face :: + * PostScript face handle. + * + * @output: + * afont_private :: + * Output private dictionary structure pointer. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The string pointers within the @PS_PrivateRec structure are owned by + * the face and don't need to be freed by the caller. + * + * If the font's format is not PostScript-based, this function returns + * the `FT_Err_Invalid_Argument' error code. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_PS_Font_Private( FT_Face face, + PS_Private afont_private ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* T1_EncodingType */ + /* */ + /* <Description> */ + /* An enumeration describing the `Encoding' entry in a Type 1 */ + /* dictionary. */ + /* */ + /* <Values> */ + /* T1_ENCODING_TYPE_NONE :: */ + /* T1_ENCODING_TYPE_ARRAY :: */ + /* T1_ENCODING_TYPE_STANDARD :: */ + /* T1_ENCODING_TYPE_ISOLATIN1 :: */ + /* T1_ENCODING_TYPE_EXPERT :: */ + /* */ + /* <Since> */ + /* 2.4.8 */ + /* */ + typedef enum T1_EncodingType_ + { + T1_ENCODING_TYPE_NONE = 0, + T1_ENCODING_TYPE_ARRAY, + T1_ENCODING_TYPE_STANDARD, + T1_ENCODING_TYPE_ISOLATIN1, + T1_ENCODING_TYPE_EXPERT + + } T1_EncodingType; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* PS_Dict_Keys */ + /* */ + /* <Description> */ + /* An enumeration used in calls to @FT_Get_PS_Font_Value to identify */ + /* the Type~1 dictionary entry to retrieve. */ + /* */ + /* <Values> */ + /* PS_DICT_FONT_TYPE :: */ + /* PS_DICT_FONT_MATRIX :: */ + /* PS_DICT_FONT_BBOX :: */ + /* PS_DICT_PAINT_TYPE :: */ + /* PS_DICT_FONT_NAME :: */ + /* PS_DICT_UNIQUE_ID :: */ + /* PS_DICT_NUM_CHAR_STRINGS :: */ + /* PS_DICT_CHAR_STRING_KEY :: */ + /* PS_DICT_CHAR_STRING :: */ + /* PS_DICT_ENCODING_TYPE :: */ + /* PS_DICT_ENCODING_ENTRY :: */ + /* PS_DICT_NUM_SUBRS :: */ + /* PS_DICT_SUBR :: */ + /* PS_DICT_STD_HW :: */ + /* PS_DICT_STD_VW :: */ + /* PS_DICT_NUM_BLUE_VALUES :: */ + /* PS_DICT_BLUE_VALUE :: */ + /* PS_DICT_BLUE_FUZZ :: */ + /* PS_DICT_NUM_OTHER_BLUES :: */ + /* PS_DICT_OTHER_BLUE :: */ + /* PS_DICT_NUM_FAMILY_BLUES :: */ + /* PS_DICT_FAMILY_BLUE :: */ + /* PS_DICT_NUM_FAMILY_OTHER_BLUES :: */ + /* PS_DICT_FAMILY_OTHER_BLUE :: */ + /* PS_DICT_BLUE_SCALE :: */ + /* PS_DICT_BLUE_SHIFT :: */ + /* PS_DICT_NUM_STEM_SNAP_H :: */ + /* PS_DICT_STEM_SNAP_H :: */ + /* PS_DICT_NUM_STEM_SNAP_V :: */ + /* PS_DICT_STEM_SNAP_V :: */ + /* PS_DICT_FORCE_BOLD :: */ + /* PS_DICT_RND_STEM_UP :: */ + /* PS_DICT_MIN_FEATURE :: */ + /* PS_DICT_LEN_IV :: */ + /* PS_DICT_PASSWORD :: */ + /* PS_DICT_LANGUAGE_GROUP :: */ + /* PS_DICT_VERSION :: */ + /* PS_DICT_NOTICE :: */ + /* PS_DICT_FULL_NAME :: */ + /* PS_DICT_FAMILY_NAME :: */ + /* PS_DICT_WEIGHT :: */ + /* PS_DICT_IS_FIXED_PITCH :: */ + /* PS_DICT_UNDERLINE_POSITION :: */ + /* PS_DICT_UNDERLINE_THICKNESS :: */ + /* PS_DICT_FS_TYPE :: */ + /* PS_DICT_ITALIC_ANGLE :: */ + /* */ + /* <Since> */ + /* 2.4.8 */ + /* */ + typedef enum PS_Dict_Keys_ + { + /* conventionally in the font dictionary */ + PS_DICT_FONT_TYPE, /* FT_Byte */ + PS_DICT_FONT_MATRIX, /* FT_Fixed */ + PS_DICT_FONT_BBOX, /* FT_Fixed */ + PS_DICT_PAINT_TYPE, /* FT_Byte */ + PS_DICT_FONT_NAME, /* FT_String* */ + PS_DICT_UNIQUE_ID, /* FT_Int */ + PS_DICT_NUM_CHAR_STRINGS, /* FT_Int */ + PS_DICT_CHAR_STRING_KEY, /* FT_String* */ + PS_DICT_CHAR_STRING, /* FT_String* */ + PS_DICT_ENCODING_TYPE, /* T1_EncodingType */ + PS_DICT_ENCODING_ENTRY, /* FT_String* */ + + /* conventionally in the font Private dictionary */ + PS_DICT_NUM_SUBRS, /* FT_Int */ + PS_DICT_SUBR, /* FT_String* */ + PS_DICT_STD_HW, /* FT_UShort */ + PS_DICT_STD_VW, /* FT_UShort */ + PS_DICT_NUM_BLUE_VALUES, /* FT_Byte */ + PS_DICT_BLUE_VALUE, /* FT_Short */ + PS_DICT_BLUE_FUZZ, /* FT_Int */ + PS_DICT_NUM_OTHER_BLUES, /* FT_Byte */ + PS_DICT_OTHER_BLUE, /* FT_Short */ + PS_DICT_NUM_FAMILY_BLUES, /* FT_Byte */ + PS_DICT_FAMILY_BLUE, /* FT_Short */ + PS_DICT_NUM_FAMILY_OTHER_BLUES, /* FT_Byte */ + PS_DICT_FAMILY_OTHER_BLUE, /* FT_Short */ + PS_DICT_BLUE_SCALE, /* FT_Fixed */ + PS_DICT_BLUE_SHIFT, /* FT_Int */ + PS_DICT_NUM_STEM_SNAP_H, /* FT_Byte */ + PS_DICT_STEM_SNAP_H, /* FT_Short */ + PS_DICT_NUM_STEM_SNAP_V, /* FT_Byte */ + PS_DICT_STEM_SNAP_V, /* FT_Short */ + PS_DICT_FORCE_BOLD, /* FT_Bool */ + PS_DICT_RND_STEM_UP, /* FT_Bool */ + PS_DICT_MIN_FEATURE, /* FT_Short */ + PS_DICT_LEN_IV, /* FT_Int */ + PS_DICT_PASSWORD, /* FT_Long */ + PS_DICT_LANGUAGE_GROUP, /* FT_Long */ + + /* conventionally in the font FontInfo dictionary */ + PS_DICT_VERSION, /* FT_String* */ + PS_DICT_NOTICE, /* FT_String* */ + PS_DICT_FULL_NAME, /* FT_String* */ + PS_DICT_FAMILY_NAME, /* FT_String* */ + PS_DICT_WEIGHT, /* FT_String* */ + PS_DICT_IS_FIXED_PITCH, /* FT_Bool */ + PS_DICT_UNDERLINE_POSITION, /* FT_Short */ + PS_DICT_UNDERLINE_THICKNESS, /* FT_UShort */ + PS_DICT_FS_TYPE, /* FT_UShort */ + PS_DICT_ITALIC_ANGLE, /* FT_Long */ + + PS_DICT_MAX = PS_DICT_ITALIC_ANGLE + + } PS_Dict_Keys; + + + /************************************************************************ + * + * @function: + * FT_Get_PS_Font_Value + * + * @description: + * Retrieve the value for the supplied key from a PostScript font. + * + * @input: + * face :: + * PostScript face handle. + * + * key :: + * An enumeration value representing the dictionary key to retrieve. + * + * idx :: + * For array values, this specifies the index to be returned. + * + * value :: + * A pointer to memory into which to write the value. + * + * valen_len :: + * The size, in bytes, of the memory supplied for the value. + * + * @output: + * value :: + * The value matching the above key, if it exists. + * + * @return: + * The amount of memory (in bytes) required to hold the requested + * value (if it exists, -1 otherwise). + * + * @note: + * The values returned are not pointers into the internal structures of + * the face, but are `fresh' copies, so that the memory containing them + * belongs to the calling application. This also enforces the + * `read-only' nature of these values, i.e., this function cannot be + * used to manipulate the face. + * + * `value' is a void pointer because the values returned can be of + * various types. + * + * If either `value' is NULL or `value_len' is too small, just the + * required memory size for the requested entry is returned. + * + * The `idx' parameter is used, not only to retrieve elements of, for + * example, the FontMatrix or FontBBox, but also to retrieve name keys + * from the CharStrings dictionary, and the charstrings themselves. It + * is ignored for atomic values. + * + * PS_DICT_BLUE_SCALE returns a value that is scaled up by 1000. To + * get the value as in the font stream, you need to divide by + * 65536000.0 (to remove the FT_Fixed scale, and the x1000 scale). + * + * IMPORTANT: Only key/value pairs read by the FreeType interpreter can + * be retrieved. So, for example, PostScript procedures such as NP, + * ND, and RD are not available. Arbitrary keys are, obviously, not be + * available either. + * + * If the font's format is not PostScript-based, this function returns + * the `FT_Err_Invalid_Argument' error code. + * + * @since: + * 2.4.8 + * + */ + FT_EXPORT( FT_Long ) + FT_Get_PS_Font_Value( FT_Face face, + PS_Dict_Keys key, + FT_UInt idx, + void *value, + FT_Long value_len ); + + /* */ + +FT_END_HEADER + +#endif /* T1TABLES_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/ttnameid.h b/freetype/include/freetype2/freetype/ttnameid.h new file mode 100644 index 0000000..8605183 --- /dev/null +++ b/freetype/include/freetype2/freetype/ttnameid.h @@ -0,0 +1,1236 @@ +/***************************************************************************/ +/* */ +/* ttnameid.h */ +/* */ +/* TrueType name ID definitions (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTNAMEID_H_ +#define TTNAMEID_H_ + + +#include <ft2build.h> + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* truetype_tables */ + /* */ + + + /*************************************************************************/ + /* */ + /* Possible values for the `platform' identifier code in the name */ + /* records of an SFNT `name' table. */ + /* */ + /*************************************************************************/ + + + /*********************************************************************** + * + * @enum: + * TT_PLATFORM_XXX + * + * @description: + * A list of valid values for the `platform_id' identifier code in + * @FT_CharMapRec and @FT_SfntName structures. + * + * @values: + * TT_PLATFORM_APPLE_UNICODE :: + * Used by Apple to indicate a Unicode character map and/or name entry. + * See @TT_APPLE_ID_XXX for corresponding `encoding_id' values. Note + * that name entries in this format are coded as big-endian UCS-2 + * character codes _only_. + * + * TT_PLATFORM_MACINTOSH :: + * Used by Apple to indicate a MacOS-specific charmap and/or name entry. + * See @TT_MAC_ID_XXX for corresponding `encoding_id' values. Note that + * most TrueType fonts contain an Apple roman charmap to be usable on + * MacOS systems (even if they contain a Microsoft charmap as well). + * + * TT_PLATFORM_ISO :: + * This value was used to specify ISO/IEC 10646 charmaps. It is however + * now deprecated. See @TT_ISO_ID_XXX for a list of corresponding + * `encoding_id' values. + * + * TT_PLATFORM_MICROSOFT :: + * Used by Microsoft to indicate Windows-specific charmaps. See + * @TT_MS_ID_XXX for a list of corresponding `encoding_id' values. + * Note that most fonts contain a Unicode charmap using + * (TT_PLATFORM_MICROSOFT, @TT_MS_ID_UNICODE_CS). + * + * TT_PLATFORM_CUSTOM :: + * Used to indicate application-specific charmaps. + * + * TT_PLATFORM_ADOBE :: + * This value isn't part of any font format specification, but is used + * by FreeType to report Adobe-specific charmaps in an @FT_CharMapRec + * structure. See @TT_ADOBE_ID_XXX. + */ + +#define TT_PLATFORM_APPLE_UNICODE 0 +#define TT_PLATFORM_MACINTOSH 1 +#define TT_PLATFORM_ISO 2 /* deprecated */ +#define TT_PLATFORM_MICROSOFT 3 +#define TT_PLATFORM_CUSTOM 4 +#define TT_PLATFORM_ADOBE 7 /* artificial */ + + + /*********************************************************************** + * + * @enum: + * TT_APPLE_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_APPLE_UNICODE charmaps and name entries. + * + * @values: + * TT_APPLE_ID_DEFAULT :: + * Unicode version 1.0. + * + * TT_APPLE_ID_UNICODE_1_1 :: + * Unicode 1.1; specifies Hangul characters starting at U+34xx. + * + * TT_APPLE_ID_ISO_10646 :: + * Deprecated (identical to preceding). + * + * TT_APPLE_ID_UNICODE_2_0 :: + * Unicode 2.0 and beyond (UTF-16 BMP only). + * + * TT_APPLE_ID_UNICODE_32 :: + * Unicode 3.1 and beyond, using UTF-32. + * + * TT_APPLE_ID_VARIANT_SELECTOR :: + * From Adobe, not Apple. Not a normal cmap. Specifies variations + * on a real cmap. + * + * TT_APPLE_ID_FULL_UNICODE :: + * Used for fallback fonts that provide complete Unicode coverage with + * a type~13 cmap. + */ + +#define TT_APPLE_ID_DEFAULT 0 /* Unicode 1.0 */ +#define TT_APPLE_ID_UNICODE_1_1 1 /* specify Hangul at U+34xx */ +#define TT_APPLE_ID_ISO_10646 2 /* deprecated */ +#define TT_APPLE_ID_UNICODE_2_0 3 /* or later */ +#define TT_APPLE_ID_UNICODE_32 4 /* 2.0 or later, full repertoire */ +#define TT_APPLE_ID_VARIANT_SELECTOR 5 /* variation selector data */ +#define TT_APPLE_ID_FULL_UNICODE 6 /* used with type 13 cmaps */ + + + /*********************************************************************** + * + * @enum: + * TT_MAC_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_MACINTOSH charmaps and name entries. + */ + +#define TT_MAC_ID_ROMAN 0 +#define TT_MAC_ID_JAPANESE 1 +#define TT_MAC_ID_TRADITIONAL_CHINESE 2 +#define TT_MAC_ID_KOREAN 3 +#define TT_MAC_ID_ARABIC 4 +#define TT_MAC_ID_HEBREW 5 +#define TT_MAC_ID_GREEK 6 +#define TT_MAC_ID_RUSSIAN 7 +#define TT_MAC_ID_RSYMBOL 8 +#define TT_MAC_ID_DEVANAGARI 9 +#define TT_MAC_ID_GURMUKHI 10 +#define TT_MAC_ID_GUJARATI 11 +#define TT_MAC_ID_ORIYA 12 +#define TT_MAC_ID_BENGALI 13 +#define TT_MAC_ID_TAMIL 14 +#define TT_MAC_ID_TELUGU 15 +#define TT_MAC_ID_KANNADA 16 +#define TT_MAC_ID_MALAYALAM 17 +#define TT_MAC_ID_SINHALESE 18 +#define TT_MAC_ID_BURMESE 19 +#define TT_MAC_ID_KHMER 20 +#define TT_MAC_ID_THAI 21 +#define TT_MAC_ID_LAOTIAN 22 +#define TT_MAC_ID_GEORGIAN 23 +#define TT_MAC_ID_ARMENIAN 24 +#define TT_MAC_ID_MALDIVIAN 25 +#define TT_MAC_ID_SIMPLIFIED_CHINESE 25 +#define TT_MAC_ID_TIBETAN 26 +#define TT_MAC_ID_MONGOLIAN 27 +#define TT_MAC_ID_GEEZ 28 +#define TT_MAC_ID_SLAVIC 29 +#define TT_MAC_ID_VIETNAMESE 30 +#define TT_MAC_ID_SINDHI 31 +#define TT_MAC_ID_UNINTERP 32 + + + /*********************************************************************** + * + * @enum: + * TT_ISO_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_ISO charmaps and name entries. + * + * Their use is now deprecated. + * + * @values: + * TT_ISO_ID_7BIT_ASCII :: + * ASCII. + * TT_ISO_ID_10646 :: + * ISO/10646. + * TT_ISO_ID_8859_1 :: + * Also known as Latin-1. + */ + +#define TT_ISO_ID_7BIT_ASCII 0 +#define TT_ISO_ID_10646 1 +#define TT_ISO_ID_8859_1 2 + + + /*********************************************************************** + * + * @enum: + * TT_MS_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_MICROSOFT charmaps and name entries. + * + * @values: + * TT_MS_ID_SYMBOL_CS :: + * Microsoft symbol encoding. See @FT_ENCODING_MS_SYMBOL. + * + * TT_MS_ID_UNICODE_CS :: + * Microsoft WGL4 charmap, matching Unicode. See + * @FT_ENCODING_UNICODE. + * + * TT_MS_ID_SJIS :: + * Shift JIS Japanese encoding. See @FT_ENCODING_SJIS. + * + * TT_MS_ID_PRC :: + * Chinese encodings as used in the People's Republic of China (PRC). + * This means the encodings GB~2312 and its supersets GBK and + * GB~18030. See @FT_ENCODING_PRC. + * + * TT_MS_ID_BIG_5 :: + * Traditional Chinese as used in Taiwan and Hong Kong. See + * @FT_ENCODING_BIG5. + * + * TT_MS_ID_WANSUNG :: + * Korean Extended Wansung encoding. See @FT_ENCODING_WANSUNG. + * + * TT_MS_ID_JOHAB :: + * Korean Johab encoding. See @FT_ENCODING_JOHAB. + * + * TT_MS_ID_UCS_4 :: + * UCS-4 or UTF-32 charmaps. This has been added to the OpenType + * specification version 1.4 (mid-2001). + */ + +#define TT_MS_ID_SYMBOL_CS 0 +#define TT_MS_ID_UNICODE_CS 1 +#define TT_MS_ID_SJIS 2 +#define TT_MS_ID_PRC 3 +#define TT_MS_ID_BIG_5 4 +#define TT_MS_ID_WANSUNG 5 +#define TT_MS_ID_JOHAB 6 +#define TT_MS_ID_UCS_4 10 + + /* this value is deprecated */ +#define TT_MS_ID_GB2312 TT_MS_ID_PRC + + + /*********************************************************************** + * + * @enum: + * TT_ADOBE_ID_XXX + * + * @description: + * A list of valid values for the `encoding_id' for + * @TT_PLATFORM_ADOBE charmaps. This is a FreeType-specific extension! + * + * @values: + * TT_ADOBE_ID_STANDARD :: + * Adobe standard encoding. + * TT_ADOBE_ID_EXPERT :: + * Adobe expert encoding. + * TT_ADOBE_ID_CUSTOM :: + * Adobe custom encoding. + * TT_ADOBE_ID_LATIN_1 :: + * Adobe Latin~1 encoding. + */ + +#define TT_ADOBE_ID_STANDARD 0 +#define TT_ADOBE_ID_EXPERT 1 +#define TT_ADOBE_ID_CUSTOM 2 +#define TT_ADOBE_ID_LATIN_1 3 + + + /*********************************************************************** + * + * @enum: + * TT_MAC_LANGID_XXX + * + * @description: + * Possible values of the language identifier field in the name records + * of the SFNT `name' table if the `platform' identifier code is + * @TT_PLATFORM_MACINTOSH. These values are also used as return values + * for function @FT_Get_CMap_Language_ID. + * + * The canonical source for Apple's IDs is + * + * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html + */ + +#define TT_MAC_LANGID_ENGLISH 0 +#define TT_MAC_LANGID_FRENCH 1 +#define TT_MAC_LANGID_GERMAN 2 +#define TT_MAC_LANGID_ITALIAN 3 +#define TT_MAC_LANGID_DUTCH 4 +#define TT_MAC_LANGID_SWEDISH 5 +#define TT_MAC_LANGID_SPANISH 6 +#define TT_MAC_LANGID_DANISH 7 +#define TT_MAC_LANGID_PORTUGUESE 8 +#define TT_MAC_LANGID_NORWEGIAN 9 +#define TT_MAC_LANGID_HEBREW 10 +#define TT_MAC_LANGID_JAPANESE 11 +#define TT_MAC_LANGID_ARABIC 12 +#define TT_MAC_LANGID_FINNISH 13 +#define TT_MAC_LANGID_GREEK 14 +#define TT_MAC_LANGID_ICELANDIC 15 +#define TT_MAC_LANGID_MALTESE 16 +#define TT_MAC_LANGID_TURKISH 17 +#define TT_MAC_LANGID_CROATIAN 18 +#define TT_MAC_LANGID_CHINESE_TRADITIONAL 19 +#define TT_MAC_LANGID_URDU 20 +#define TT_MAC_LANGID_HINDI 21 +#define TT_MAC_LANGID_THAI 22 +#define TT_MAC_LANGID_KOREAN 23 +#define TT_MAC_LANGID_LITHUANIAN 24 +#define TT_MAC_LANGID_POLISH 25 +#define TT_MAC_LANGID_HUNGARIAN 26 +#define TT_MAC_LANGID_ESTONIAN 27 +#define TT_MAC_LANGID_LETTISH 28 +#define TT_MAC_LANGID_SAAMISK 29 +#define TT_MAC_LANGID_FAEROESE 30 +#define TT_MAC_LANGID_FARSI 31 +#define TT_MAC_LANGID_RUSSIAN 32 +#define TT_MAC_LANGID_CHINESE_SIMPLIFIED 33 +#define TT_MAC_LANGID_FLEMISH 34 +#define TT_MAC_LANGID_IRISH 35 +#define TT_MAC_LANGID_ALBANIAN 36 +#define TT_MAC_LANGID_ROMANIAN 37 +#define TT_MAC_LANGID_CZECH 38 +#define TT_MAC_LANGID_SLOVAK 39 +#define TT_MAC_LANGID_SLOVENIAN 40 +#define TT_MAC_LANGID_YIDDISH 41 +#define TT_MAC_LANGID_SERBIAN 42 +#define TT_MAC_LANGID_MACEDONIAN 43 +#define TT_MAC_LANGID_BULGARIAN 44 +#define TT_MAC_LANGID_UKRAINIAN 45 +#define TT_MAC_LANGID_BYELORUSSIAN 46 +#define TT_MAC_LANGID_UZBEK 47 +#define TT_MAC_LANGID_KAZAKH 48 +#define TT_MAC_LANGID_AZERBAIJANI 49 +#define TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT 49 +#define TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT 50 +#define TT_MAC_LANGID_ARMENIAN 51 +#define TT_MAC_LANGID_GEORGIAN 52 +#define TT_MAC_LANGID_MOLDAVIAN 53 +#define TT_MAC_LANGID_KIRGHIZ 54 +#define TT_MAC_LANGID_TAJIKI 55 +#define TT_MAC_LANGID_TURKMEN 56 +#define TT_MAC_LANGID_MONGOLIAN 57 +#define TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT 57 +#define TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT 58 +#define TT_MAC_LANGID_PASHTO 59 +#define TT_MAC_LANGID_KURDISH 60 +#define TT_MAC_LANGID_KASHMIRI 61 +#define TT_MAC_LANGID_SINDHI 62 +#define TT_MAC_LANGID_TIBETAN 63 +#define TT_MAC_LANGID_NEPALI 64 +#define TT_MAC_LANGID_SANSKRIT 65 +#define TT_MAC_LANGID_MARATHI 66 +#define TT_MAC_LANGID_BENGALI 67 +#define TT_MAC_LANGID_ASSAMESE 68 +#define TT_MAC_LANGID_GUJARATI 69 +#define TT_MAC_LANGID_PUNJABI 70 +#define TT_MAC_LANGID_ORIYA 71 +#define TT_MAC_LANGID_MALAYALAM 72 +#define TT_MAC_LANGID_KANNADA 73 +#define TT_MAC_LANGID_TAMIL 74 +#define TT_MAC_LANGID_TELUGU 75 +#define TT_MAC_LANGID_SINHALESE 76 +#define TT_MAC_LANGID_BURMESE 77 +#define TT_MAC_LANGID_KHMER 78 +#define TT_MAC_LANGID_LAO 79 +#define TT_MAC_LANGID_VIETNAMESE 80 +#define TT_MAC_LANGID_INDONESIAN 81 +#define TT_MAC_LANGID_TAGALOG 82 +#define TT_MAC_LANGID_MALAY_ROMAN_SCRIPT 83 +#define TT_MAC_LANGID_MALAY_ARABIC_SCRIPT 84 +#define TT_MAC_LANGID_AMHARIC 85 +#define TT_MAC_LANGID_TIGRINYA 86 +#define TT_MAC_LANGID_GALLA 87 +#define TT_MAC_LANGID_SOMALI 88 +#define TT_MAC_LANGID_SWAHILI 89 +#define TT_MAC_LANGID_RUANDA 90 +#define TT_MAC_LANGID_RUNDI 91 +#define TT_MAC_LANGID_CHEWA 92 +#define TT_MAC_LANGID_MALAGASY 93 +#define TT_MAC_LANGID_ESPERANTO 94 +#define TT_MAC_LANGID_WELSH 128 +#define TT_MAC_LANGID_BASQUE 129 +#define TT_MAC_LANGID_CATALAN 130 +#define TT_MAC_LANGID_LATIN 131 +#define TT_MAC_LANGID_QUECHUA 132 +#define TT_MAC_LANGID_GUARANI 133 +#define TT_MAC_LANGID_AYMARA 134 +#define TT_MAC_LANGID_TATAR 135 +#define TT_MAC_LANGID_UIGHUR 136 +#define TT_MAC_LANGID_DZONGKHA 137 +#define TT_MAC_LANGID_JAVANESE 138 +#define TT_MAC_LANGID_SUNDANESE 139 + + /* The following codes are new as of 2000-03-10 */ +#define TT_MAC_LANGID_GALICIAN 140 +#define TT_MAC_LANGID_AFRIKAANS 141 +#define TT_MAC_LANGID_BRETON 142 +#define TT_MAC_LANGID_INUKTITUT 143 +#define TT_MAC_LANGID_SCOTTISH_GAELIC 144 +#define TT_MAC_LANGID_MANX_GAELIC 145 +#define TT_MAC_LANGID_IRISH_GAELIC 146 +#define TT_MAC_LANGID_TONGAN 147 +#define TT_MAC_LANGID_GREEK_POLYTONIC 148 +#define TT_MAC_LANGID_GREELANDIC 149 +#define TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT 150 + + + /*********************************************************************** + * + * @enum: + * TT_MS_LANGID_XXX + * + * @description: + * Possible values of the language identifier field in the name records + * of the SFNT `name' table if the `platform' identifier code is + * @TT_PLATFORM_MICROSOFT. These values are also used as return values + * for function @FT_Get_CMap_Language_ID. + * + * The canonical source for Microsoft's IDs is + * + * https://www.microsoft.com/globaldev/reference/lcid-all.mspx , + * + * however, we only provide macros for language identifiers present in + * the OpenType specification: Microsoft has abandoned the concept of + * LCIDs (language code identifiers), and format~1 of the `name' table + * provides a better mechanism for languages not covered here. + * + * More legacy values not listed in the reference can be found in the + * @FT_TRUETYPE_IDS_H header file. + */ + +#define TT_MS_LANGID_ARABIC_SAUDI_ARABIA 0x0401 +#define TT_MS_LANGID_ARABIC_IRAQ 0x0801 +#define TT_MS_LANGID_ARABIC_EGYPT 0x0C01 +#define TT_MS_LANGID_ARABIC_LIBYA 0x1001 +#define TT_MS_LANGID_ARABIC_ALGERIA 0x1401 +#define TT_MS_LANGID_ARABIC_MOROCCO 0x1801 +#define TT_MS_LANGID_ARABIC_TUNISIA 0x1C01 +#define TT_MS_LANGID_ARABIC_OMAN 0x2001 +#define TT_MS_LANGID_ARABIC_YEMEN 0x2401 +#define TT_MS_LANGID_ARABIC_SYRIA 0x2801 +#define TT_MS_LANGID_ARABIC_JORDAN 0x2C01 +#define TT_MS_LANGID_ARABIC_LEBANON 0x3001 +#define TT_MS_LANGID_ARABIC_KUWAIT 0x3401 +#define TT_MS_LANGID_ARABIC_UAE 0x3801 +#define TT_MS_LANGID_ARABIC_BAHRAIN 0x3C01 +#define TT_MS_LANGID_ARABIC_QATAR 0x4001 +#define TT_MS_LANGID_BULGARIAN_BULGARIA 0x0402 +#define TT_MS_LANGID_CATALAN_CATALAN 0x0403 +#define TT_MS_LANGID_CHINESE_TAIWAN 0x0404 +#define TT_MS_LANGID_CHINESE_PRC 0x0804 +#define TT_MS_LANGID_CHINESE_HONG_KONG 0x0C04 +#define TT_MS_LANGID_CHINESE_SINGAPORE 0x1004 +#define TT_MS_LANGID_CHINESE_MACAO 0x1404 +#define TT_MS_LANGID_CZECH_CZECH_REPUBLIC 0x0405 +#define TT_MS_LANGID_DANISH_DENMARK 0x0406 +#define TT_MS_LANGID_GERMAN_GERMANY 0x0407 +#define TT_MS_LANGID_GERMAN_SWITZERLAND 0x0807 +#define TT_MS_LANGID_GERMAN_AUSTRIA 0x0C07 +#define TT_MS_LANGID_GERMAN_LUXEMBOURG 0x1007 +#define TT_MS_LANGID_GERMAN_LIECHTENSTEIN 0x1407 +#define TT_MS_LANGID_GREEK_GREECE 0x0408 +#define TT_MS_LANGID_ENGLISH_UNITED_STATES 0x0409 +#define TT_MS_LANGID_ENGLISH_UNITED_KINGDOM 0x0809 +#define TT_MS_LANGID_ENGLISH_AUSTRALIA 0x0C09 +#define TT_MS_LANGID_ENGLISH_CANADA 0x1009 +#define TT_MS_LANGID_ENGLISH_NEW_ZEALAND 0x1409 +#define TT_MS_LANGID_ENGLISH_IRELAND 0x1809 +#define TT_MS_LANGID_ENGLISH_SOUTH_AFRICA 0x1C09 +#define TT_MS_LANGID_ENGLISH_JAMAICA 0x2009 +#define TT_MS_LANGID_ENGLISH_CARIBBEAN 0x2409 +#define TT_MS_LANGID_ENGLISH_BELIZE 0x2809 +#define TT_MS_LANGID_ENGLISH_TRINIDAD 0x2C09 +#define TT_MS_LANGID_ENGLISH_ZIMBABWE 0x3009 +#define TT_MS_LANGID_ENGLISH_PHILIPPINES 0x3409 +#define TT_MS_LANGID_ENGLISH_INDIA 0x4009 +#define TT_MS_LANGID_ENGLISH_MALAYSIA 0x4409 +#define TT_MS_LANGID_ENGLISH_SINGAPORE 0x4809 +#define TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT 0x040A +#define TT_MS_LANGID_SPANISH_MEXICO 0x080A +#define TT_MS_LANGID_SPANISH_SPAIN_MODERN_SORT 0x0C0A +#define TT_MS_LANGID_SPANISH_GUATEMALA 0x100A +#define TT_MS_LANGID_SPANISH_COSTA_RICA 0x140A +#define TT_MS_LANGID_SPANISH_PANAMA 0x180A +#define TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC 0x1C0A +#define TT_MS_LANGID_SPANISH_VENEZUELA 0x200A +#define TT_MS_LANGID_SPANISH_COLOMBIA 0x240A +#define TT_MS_LANGID_SPANISH_PERU 0x280A +#define TT_MS_LANGID_SPANISH_ARGENTINA 0x2C0A +#define TT_MS_LANGID_SPANISH_ECUADOR 0x300A +#define TT_MS_LANGID_SPANISH_CHILE 0x340A +#define TT_MS_LANGID_SPANISH_URUGUAY 0x380A +#define TT_MS_LANGID_SPANISH_PARAGUAY 0x3C0A +#define TT_MS_LANGID_SPANISH_BOLIVIA 0x400A +#define TT_MS_LANGID_SPANISH_EL_SALVADOR 0x440A +#define TT_MS_LANGID_SPANISH_HONDURAS 0x480A +#define TT_MS_LANGID_SPANISH_NICARAGUA 0x4C0A +#define TT_MS_LANGID_SPANISH_PUERTO_RICO 0x500A +#define TT_MS_LANGID_SPANISH_UNITED_STATES 0x540A +#define TT_MS_LANGID_FINNISH_FINLAND 0x040B +#define TT_MS_LANGID_FRENCH_FRANCE 0x040C +#define TT_MS_LANGID_FRENCH_BELGIUM 0x080C +#define TT_MS_LANGID_FRENCH_CANADA 0x0C0C +#define TT_MS_LANGID_FRENCH_SWITZERLAND 0x100C +#define TT_MS_LANGID_FRENCH_LUXEMBOURG 0x140C +#define TT_MS_LANGID_FRENCH_MONACO 0x180C +#define TT_MS_LANGID_HEBREW_ISRAEL 0x040D +#define TT_MS_LANGID_HUNGARIAN_HUNGARY 0x040E +#define TT_MS_LANGID_ICELANDIC_ICELAND 0x040F +#define TT_MS_LANGID_ITALIAN_ITALY 0x0410 +#define TT_MS_LANGID_ITALIAN_SWITZERLAND 0x0810 +#define TT_MS_LANGID_JAPANESE_JAPAN 0x0411 +#define TT_MS_LANGID_KOREAN_KOREA 0x0412 +#define TT_MS_LANGID_DUTCH_NETHERLANDS 0x0413 +#define TT_MS_LANGID_DUTCH_BELGIUM 0x0813 +#define TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL 0x0414 +#define TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK 0x0814 +#define TT_MS_LANGID_POLISH_POLAND 0x0415 +#define TT_MS_LANGID_PORTUGUESE_BRAZIL 0x0416 +#define TT_MS_LANGID_PORTUGUESE_PORTUGAL 0x0816 +#define TT_MS_LANGID_ROMANSH_SWITZERLAND 0x0417 +#define TT_MS_LANGID_ROMANIAN_ROMANIA 0x0418 +#define TT_MS_LANGID_RUSSIAN_RUSSIA 0x0419 +#define TT_MS_LANGID_CROATIAN_CROATIA 0x041A +#define TT_MS_LANGID_SERBIAN_SERBIA_LATIN 0x081A +#define TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC 0x0C1A +#define TT_MS_LANGID_CROATIAN_BOSNIA_HERZEGOVINA 0x101A +#define TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA 0x141A +#define TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_LATIN 0x181A +#define TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_CYRILLIC 0x1C1A +#define TT_MS_LANGID_BOSNIAN_BOSNIA_HERZ_CYRILLIC 0x201A +#define TT_MS_LANGID_SLOVAK_SLOVAKIA 0x041B +#define TT_MS_LANGID_ALBANIAN_ALBANIA 0x041C +#define TT_MS_LANGID_SWEDISH_SWEDEN 0x041D +#define TT_MS_LANGID_SWEDISH_FINLAND 0x081D +#define TT_MS_LANGID_THAI_THAILAND 0x041E +#define TT_MS_LANGID_TURKISH_TURKEY 0x041F +#define TT_MS_LANGID_URDU_PAKISTAN 0x0420 +#define TT_MS_LANGID_INDONESIAN_INDONESIA 0x0421 +#define TT_MS_LANGID_UKRAINIAN_UKRAINE 0x0422 +#define TT_MS_LANGID_BELARUSIAN_BELARUS 0x0423 +#define TT_MS_LANGID_SLOVENIAN_SLOVENIA 0x0424 +#define TT_MS_LANGID_ESTONIAN_ESTONIA 0x0425 +#define TT_MS_LANGID_LATVIAN_LATVIA 0x0426 +#define TT_MS_LANGID_LITHUANIAN_LITHUANIA 0x0427 +#define TT_MS_LANGID_TAJIK_TAJIKISTAN 0x0428 +#define TT_MS_LANGID_VIETNAMESE_VIET_NAM 0x042A +#define TT_MS_LANGID_ARMENIAN_ARMENIA 0x042B +#define TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN 0x042C +#define TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC 0x082C +#define TT_MS_LANGID_BASQUE_BASQUE 0x042D +#define TT_MS_LANGID_UPPER_SORBIAN_GERMANY 0x042E +#define TT_MS_LANGID_LOWER_SORBIAN_GERMANY 0x082E +#define TT_MS_LANGID_MACEDONIAN_MACEDONIA 0x042F +#define TT_MS_LANGID_SETSWANA_SOUTH_AFRICA 0x0432 +#define TT_MS_LANGID_ISIXHOSA_SOUTH_AFRICA 0x0434 +#define TT_MS_LANGID_ISIZULU_SOUTH_AFRICA 0x0435 +#define TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA 0x0436 +#define TT_MS_LANGID_GEORGIAN_GEORGIA 0x0437 +#define TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS 0x0438 +#define TT_MS_LANGID_HINDI_INDIA 0x0439 +#define TT_MS_LANGID_MALTESE_MALTA 0x043A +#define TT_MS_LANGID_SAMI_NORTHERN_NORWAY 0x043B +#define TT_MS_LANGID_SAMI_NORTHERN_SWEDEN 0x083B +#define TT_MS_LANGID_SAMI_NORTHERN_FINLAND 0x0C3B +#define TT_MS_LANGID_SAMI_LULE_NORWAY 0x103B +#define TT_MS_LANGID_SAMI_LULE_SWEDEN 0x143B +#define TT_MS_LANGID_SAMI_SOUTHERN_NORWAY 0x183B +#define TT_MS_LANGID_SAMI_SOUTHERN_SWEDEN 0x1C3B +#define TT_MS_LANGID_SAMI_SKOLT_FINLAND 0x203B +#define TT_MS_LANGID_SAMI_INARI_FINLAND 0x243B +#define TT_MS_LANGID_IRISH_IRELAND 0x083C +#define TT_MS_LANGID_MALAY_MALAYSIA 0x043E +#define TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM 0x083E +#define TT_MS_LANGID_KAZAKH_KAZAKHSTAN 0x043F +#define TT_MS_LANGID_KYRGYZ_KYRGYZSTAN /* Cyrillic*/ 0x0440 +#define TT_MS_LANGID_KISWAHILI_KENYA 0x0441 +#define TT_MS_LANGID_TURKMEN_TURKMENISTAN 0x0442 +#define TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN 0x0443 +#define TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC 0x0843 +#define TT_MS_LANGID_TATAR_RUSSIA 0x0444 +#define TT_MS_LANGID_BENGALI_INDIA 0x0445 +#define TT_MS_LANGID_BENGALI_BANGLADESH 0x0845 +#define TT_MS_LANGID_PUNJABI_INDIA 0x0446 +#define TT_MS_LANGID_GUJARATI_INDIA 0x0447 +#define TT_MS_LANGID_ODIA_INDIA 0x0448 +#define TT_MS_LANGID_TAMIL_INDIA 0x0449 +#define TT_MS_LANGID_TELUGU_INDIA 0x044A +#define TT_MS_LANGID_KANNADA_INDIA 0x044B +#define TT_MS_LANGID_MALAYALAM_INDIA 0x044C +#define TT_MS_LANGID_ASSAMESE_INDIA 0x044D +#define TT_MS_LANGID_MARATHI_INDIA 0x044E +#define TT_MS_LANGID_SANSKRIT_INDIA 0x044F +#define TT_MS_LANGID_MONGOLIAN_MONGOLIA /* Cyrillic */ 0x0450 +#define TT_MS_LANGID_MONGOLIAN_PRC 0x0850 +#define TT_MS_LANGID_TIBETAN_PRC 0x0451 +#define TT_MS_LANGID_WELSH_UNITED_KINGDOM 0x0452 +#define TT_MS_LANGID_KHMER_CAMBODIA 0x0453 +#define TT_MS_LANGID_LAO_LAOS 0x0454 +#define TT_MS_LANGID_GALICIAN_GALICIAN 0x0456 +#define TT_MS_LANGID_KONKANI_INDIA 0x0457 +#define TT_MS_LANGID_SYRIAC_SYRIA 0x045A +#define TT_MS_LANGID_SINHALA_SRI_LANKA 0x045B +#define TT_MS_LANGID_INUKTITUT_CANADA 0x045D +#define TT_MS_LANGID_INUKTITUT_CANADA_LATIN 0x085D +#define TT_MS_LANGID_AMHARIC_ETHIOPIA 0x045E +#define TT_MS_LANGID_TAMAZIGHT_ALGERIA 0x085F +#define TT_MS_LANGID_NEPALI_NEPAL 0x0461 +#define TT_MS_LANGID_FRISIAN_NETHERLANDS 0x0462 +#define TT_MS_LANGID_PASHTO_AFGHANISTAN 0x0463 +#define TT_MS_LANGID_FILIPINO_PHILIPPINES 0x0464 +#define TT_MS_LANGID_DHIVEHI_MALDIVES 0x0465 +#define TT_MS_LANGID_HAUSA_NIGERIA 0x0468 +#define TT_MS_LANGID_YORUBA_NIGERIA 0x046A +#define TT_MS_LANGID_QUECHUA_BOLIVIA 0x046B +#define TT_MS_LANGID_QUECHUA_ECUADOR 0x086B +#define TT_MS_LANGID_QUECHUA_PERU 0x0C6B +#define TT_MS_LANGID_SESOTHO_SA_LEBOA_SOUTH_AFRICA 0x046C +#define TT_MS_LANGID_BASHKIR_RUSSIA 0x046D +#define TT_MS_LANGID_LUXEMBOURGISH_LUXEMBOURG 0x046E +#define TT_MS_LANGID_GREENLANDIC_GREENLAND 0x046F +#define TT_MS_LANGID_IGBO_NIGERIA 0x0470 +#define TT_MS_LANGID_YI_PRC 0x0478 +#define TT_MS_LANGID_MAPUDUNGUN_CHILE 0x047A +#define TT_MS_LANGID_MOHAWK_MOHAWK 0x047C +#define TT_MS_LANGID_BRETON_FRANCE 0x047E +#define TT_MS_LANGID_UIGHUR_PRC 0x0480 +#define TT_MS_LANGID_MAORI_NEW_ZEALAND 0x0481 +#define TT_MS_LANGID_OCCITAN_FRANCE 0x0482 +#define TT_MS_LANGID_CORSICAN_FRANCE 0x0483 +#define TT_MS_LANGID_ALSATIAN_FRANCE 0x0484 +#define TT_MS_LANGID_YAKUT_RUSSIA 0x0485 +#define TT_MS_LANGID_KICHE_GUATEMALA 0x0486 +#define TT_MS_LANGID_KINYARWANDA_RWANDA 0x0487 +#define TT_MS_LANGID_WOLOF_SENEGAL 0x0488 +#define TT_MS_LANGID_DARI_AFGHANISTAN 0x048C + + /* */ + + + /* legacy macro definitions not present in OpenType 1.8.1 */ +#define TT_MS_LANGID_ARABIC_GENERAL 0x0001 +#define TT_MS_LANGID_CATALAN_SPAIN \ + TT_MS_LANGID_CATALAN_CATALAN +#define TT_MS_LANGID_CHINESE_GENERAL 0x0004 +#define TT_MS_LANGID_CHINESE_MACAU \ + TT_MS_LANGID_CHINESE_MACAO +#define TT_MS_LANGID_GERMAN_LIECHTENSTEI \ + TT_MS_LANGID_GERMAN_LIECHTENSTEIN +#define TT_MS_LANGID_ENGLISH_GENERAL 0x0009 +#define TT_MS_LANGID_ENGLISH_INDONESIA 0x3809 +#define TT_MS_LANGID_ENGLISH_HONG_KONG 0x3C09 +#define TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT \ + TT_MS_LANGID_SPANISH_SPAIN_MODERN_SORT +#define TT_MS_LANGID_SPANISH_LATIN_AMERICA 0xE40AU +#define TT_MS_LANGID_FRENCH_WEST_INDIES 0x1C0C +#define TT_MS_LANGID_FRENCH_REUNION 0x200C +#define TT_MS_LANGID_FRENCH_CONGO 0x240C + /* which was formerly: */ +#define TT_MS_LANGID_FRENCH_ZAIRE \ + TT_MS_LANGID_FRENCH_CONGO +#define TT_MS_LANGID_FRENCH_SENEGAL 0x280C +#define TT_MS_LANGID_FRENCH_CAMEROON 0x2C0C +#define TT_MS_LANGID_FRENCH_COTE_D_IVOIRE 0x300C +#define TT_MS_LANGID_FRENCH_MALI 0x340C +#define TT_MS_LANGID_FRENCH_MOROCCO 0x380C +#define TT_MS_LANGID_FRENCH_HAITI 0x3C0C +#define TT_MS_LANGID_FRENCH_NORTH_AFRICA 0xE40CU +#define TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA \ + TT_MS_LANGID_KOREAN_KOREA +#define TT_MS_LANGID_KOREAN_JOHAB_KOREA 0x0812 +#define TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND \ + TT_MS_LANGID_ROMANSH_SWITZERLAND +#define TT_MS_LANGID_MOLDAVIAN_MOLDAVIA 0x0818 +#define TT_MS_LANGID_RUSSIAN_MOLDAVIA 0x0819 +#define TT_MS_LANGID_URDU_INDIA 0x0820 +#define TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA 0x0827 +#define TT_MS_LANGID_SLOVENE_SLOVENIA \ + TT_MS_LANGID_SLOVENIAN_SLOVENIA +#define TT_MS_LANGID_FARSI_IRAN 0x0429 +#define TT_MS_LANGID_BASQUE_SPAIN \ + TT_MS_LANGID_BASQUE_BASQUE +#define TT_MS_LANGID_SORBIAN_GERMANY \ + TT_MS_LANGID_UPPER_SORBIAN_GERMANY +#define TT_MS_LANGID_SUTU_SOUTH_AFRICA 0x0430 +#define TT_MS_LANGID_TSONGA_SOUTH_AFRICA 0x0431 +#define TT_MS_LANGID_TSWANA_SOUTH_AFRICA \ + TT_MS_LANGID_SETSWANA_SOUTH_AFRICA +#define TT_MS_LANGID_VENDA_SOUTH_AFRICA 0x0433 +#define TT_MS_LANGID_XHOSA_SOUTH_AFRICA \ + TT_MS_LANGID_ISIXHOSA_SOUTH_AFRICA +#define TT_MS_LANGID_ZULU_SOUTH_AFRICA \ + TT_MS_LANGID_ISIZULU_SOUTH_AFRICA +#define TT_MS_LANGID_SAAMI_LAPONIA 0x043B + /* the next two values are incorrectly inverted */ +#define TT_MS_LANGID_IRISH_GAELIC_IRELAND 0x043C +#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM 0x083C +#define TT_MS_LANGID_YIDDISH_GERMANY 0x043D +#define TT_MS_LANGID_KAZAK_KAZAKSTAN \ + TT_MS_LANGID_KAZAKH_KAZAKHSTAN +#define TT_MS_LANGID_KIRGHIZ_KIRGHIZ_REPUBLIC \ + TT_MS_LANGID_KYRGYZ_KYRGYZSTAN +#define TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN \ + TT_MS_LANGID_KYRGYZ_KYRGYZSTAN +#define TT_MS_LANGID_SWAHILI_KENYA \ + TT_MS_LANGID_KISWAHILI_KENYA +#define TT_MS_LANGID_TATAR_TATARSTAN \ + TT_MS_LANGID_TATAR_RUSSIA +#define TT_MS_LANGID_PUNJABI_ARABIC_PAKISTAN 0x0846 +#define TT_MS_LANGID_ORIYA_INDIA \ + TT_MS_LANGID_ODIA_INDIA +#define TT_MS_LANGID_MONGOLIAN_MONGOLIA_MONGOLIAN \ + TT_MS_LANGID_MONGOLIAN_PRC +#define TT_MS_LANGID_TIBETAN_CHINA \ + TT_MS_LANGID_TIBETAN_PRC +#define TT_MS_LANGID_DZONGHKA_BHUTAN 0x0851 +#define TT_MS_LANGID_TIBETAN_BHUTAN \ + TT_MS_LANGID_DZONGHKA_BHUTAN +#define TT_MS_LANGID_WELSH_WALES \ + TT_MS_LANGID_WELSH_UNITED_KINGDOM +#define TT_MS_LANGID_BURMESE_MYANMAR 0x0455 +#define TT_MS_LANGID_GALICIAN_SPAIN \ + TT_MS_LANGID_GALICIAN_GALICIAN +#define TT_MS_LANGID_MANIPURI_INDIA /* Bengali */ 0x0458 +#define TT_MS_LANGID_SINDHI_INDIA /* Arabic */ 0x0459 +#define TT_MS_LANGID_SINDHI_PAKISTAN 0x0859 +#define TT_MS_LANGID_SINHALESE_SRI_LANKA \ + TT_MS_LANGID_SINHALA_SRI_LANKA +#define TT_MS_LANGID_CHEROKEE_UNITED_STATES 0x045C +#define TT_MS_LANGID_TAMAZIGHT_MOROCCO /* Arabic */ 0x045F +#define TT_MS_LANGID_TAMAZIGHT_MOROCCO_LATIN \ + TT_MS_LANGID_TAMAZIGHT_ALGERIA +#define TT_MS_LANGID_KASHMIRI_PAKISTAN /* Arabic */ 0x0460 +#define TT_MS_LANGID_KASHMIRI_SASIA 0x0860 +#define TT_MS_LANGID_KASHMIRI_INDIA \ + TT_MS_LANGID_KASHMIRI_SASIA +#define TT_MS_LANGID_NEPALI_INDIA 0x0861 +#define TT_MS_LANGID_DIVEHI_MALDIVES \ + TT_MS_LANGID_DHIVEHI_MALDIVES +#define TT_MS_LANGID_EDO_NIGERIA 0x0466 +#define TT_MS_LANGID_FULFULDE_NIGERIA 0x0467 +#define TT_MS_LANGID_IBIBIO_NIGERIA 0x0469 +#define TT_MS_LANGID_SEPEDI_SOUTH_AFRICA \ + TT_MS_LANGID_SESOTHO_SA_LEBOA_SOUTH_AFRICA +#define TT_MS_LANGID_SOTHO_SOUTHERN_SOUTH_AFRICA \ + TT_MS_LANGID_SESOTHO_SA_LEBOA_SOUTH_AFRICA +#define TT_MS_LANGID_KANURI_NIGERIA 0x0471 +#define TT_MS_LANGID_OROMO_ETHIOPIA 0x0472 +#define TT_MS_LANGID_TIGRIGNA_ETHIOPIA 0x0473 +#define TT_MS_LANGID_TIGRIGNA_ERYTHREA 0x0873 +#define TT_MS_LANGID_TIGRIGNA_ERYTREA \ + TT_MS_LANGID_TIGRIGNA_ERYTHREA +#define TT_MS_LANGID_GUARANI_PARAGUAY 0x0474 +#define TT_MS_LANGID_HAWAIIAN_UNITED_STATES 0x0475 +#define TT_MS_LANGID_LATIN 0x0476 +#define TT_MS_LANGID_SOMALI_SOMALIA 0x0477 +#define TT_MS_LANGID_YI_CHINA \ + TT_MS_LANGID_YI_PRC +#define TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES 0x0479 +#define TT_MS_LANGID_UIGHUR_CHINA \ + TT_MS_LANGID_UIGHUR_PRC + + + /*********************************************************************** + * + * @enum: + * TT_NAME_ID_XXX + * + * @description: + * Possible values of the `name' identifier field in the name records of + * an SFNT `name' table. These values are platform independent. + */ + +#define TT_NAME_ID_COPYRIGHT 0 +#define TT_NAME_ID_FONT_FAMILY 1 +#define TT_NAME_ID_FONT_SUBFAMILY 2 +#define TT_NAME_ID_UNIQUE_ID 3 +#define TT_NAME_ID_FULL_NAME 4 +#define TT_NAME_ID_VERSION_STRING 5 +#define TT_NAME_ID_PS_NAME 6 +#define TT_NAME_ID_TRADEMARK 7 + + /* the following values are from the OpenType spec */ +#define TT_NAME_ID_MANUFACTURER 8 +#define TT_NAME_ID_DESIGNER 9 +#define TT_NAME_ID_DESCRIPTION 10 +#define TT_NAME_ID_VENDOR_URL 11 +#define TT_NAME_ID_DESIGNER_URL 12 +#define TT_NAME_ID_LICENSE 13 +#define TT_NAME_ID_LICENSE_URL 14 + /* number 15 is reserved */ +#define TT_NAME_ID_TYPOGRAPHIC_FAMILY 16 +#define TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY 17 +#define TT_NAME_ID_MAC_FULL_NAME 18 + + /* The following code is new as of 2000-01-21 */ +#define TT_NAME_ID_SAMPLE_TEXT 19 + + /* This is new in OpenType 1.3 */ +#define TT_NAME_ID_CID_FINDFONT_NAME 20 + + /* This is new in OpenType 1.5 */ +#define TT_NAME_ID_WWS_FAMILY 21 +#define TT_NAME_ID_WWS_SUBFAMILY 22 + + /* This is new in OpenType 1.7 */ +#define TT_NAME_ID_LIGHT_BACKGROUND 23 +#define TT_NAME_ID_DARK_BACKGROUND 24 + + /* This is new in OpenType 1.8 */ +#define TT_NAME_ID_VARIATIONS_PREFIX 25 + + /* these two values are deprecated */ +#define TT_NAME_ID_PREFERRED_FAMILY TT_NAME_ID_TYPOGRAPHIC_FAMILY +#define TT_NAME_ID_PREFERRED_SUBFAMILY TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY + + + /*********************************************************************** + * + * @enum: + * TT_UCR_XXX + * + * @description: + * Possible bit mask values for the `ulUnicodeRangeX' fields in an SFNT + * `OS/2' table. + */ + + /* ulUnicodeRange1 */ + /* --------------- */ + + /* Bit 0 Basic Latin */ +#define TT_UCR_BASIC_LATIN (1L << 0) /* U+0020-U+007E */ + /* Bit 1 C1 Controls and Latin-1 Supplement */ +#define TT_UCR_LATIN1_SUPPLEMENT (1L << 1) /* U+0080-U+00FF */ + /* Bit 2 Latin Extended-A */ +#define TT_UCR_LATIN_EXTENDED_A (1L << 2) /* U+0100-U+017F */ + /* Bit 3 Latin Extended-B */ +#define TT_UCR_LATIN_EXTENDED_B (1L << 3) /* U+0180-U+024F */ + /* Bit 4 IPA Extensions */ + /* Phonetic Extensions */ + /* Phonetic Extensions Supplement */ +#define TT_UCR_IPA_EXTENSIONS (1L << 4) /* U+0250-U+02AF */ + /* U+1D00-U+1D7F */ + /* U+1D80-U+1DBF */ + /* Bit 5 Spacing Modifier Letters */ + /* Modifier Tone Letters */ +#define TT_UCR_SPACING_MODIFIER (1L << 5) /* U+02B0-U+02FF */ + /* U+A700-U+A71F */ + /* Bit 6 Combining Diacritical Marks */ + /* Combining Diacritical Marks Supplement */ +#define TT_UCR_COMBINING_DIACRITICAL_MARKS (1L << 6) /* U+0300-U+036F */ + /* U+1DC0-U+1DFF */ + /* Bit 7 Greek and Coptic */ +#define TT_UCR_GREEK (1L << 7) /* U+0370-U+03FF */ + /* Bit 8 Coptic */ +#define TT_UCR_COPTIC (1L << 8) /* U+2C80-U+2CFF */ + /* Bit 9 Cyrillic */ + /* Cyrillic Supplement */ + /* Cyrillic Extended-A */ + /* Cyrillic Extended-B */ +#define TT_UCR_CYRILLIC (1L << 9) /* U+0400-U+04FF */ + /* U+0500-U+052F */ + /* U+2DE0-U+2DFF */ + /* U+A640-U+A69F */ + /* Bit 10 Armenian */ +#define TT_UCR_ARMENIAN (1L << 10) /* U+0530-U+058F */ + /* Bit 11 Hebrew */ +#define TT_UCR_HEBREW (1L << 11) /* U+0590-U+05FF */ + /* Bit 12 Vai */ +#define TT_UCR_VAI (1L << 12) /* U+A500-U+A63F */ + /* Bit 13 Arabic */ + /* Arabic Supplement */ +#define TT_UCR_ARABIC (1L << 13) /* U+0600-U+06FF */ + /* U+0750-U+077F */ + /* Bit 14 NKo */ +#define TT_UCR_NKO (1L << 14) /* U+07C0-U+07FF */ + /* Bit 15 Devanagari */ +#define TT_UCR_DEVANAGARI (1L << 15) /* U+0900-U+097F */ + /* Bit 16 Bengali */ +#define TT_UCR_BENGALI (1L << 16) /* U+0980-U+09FF */ + /* Bit 17 Gurmukhi */ +#define TT_UCR_GURMUKHI (1L << 17) /* U+0A00-U+0A7F */ + /* Bit 18 Gujarati */ +#define TT_UCR_GUJARATI (1L << 18) /* U+0A80-U+0AFF */ + /* Bit 19 Oriya */ +#define TT_UCR_ORIYA (1L << 19) /* U+0B00-U+0B7F */ + /* Bit 20 Tamil */ +#define TT_UCR_TAMIL (1L << 20) /* U+0B80-U+0BFF */ + /* Bit 21 Telugu */ +#define TT_UCR_TELUGU (1L << 21) /* U+0C00-U+0C7F */ + /* Bit 22 Kannada */ +#define TT_UCR_KANNADA (1L << 22) /* U+0C80-U+0CFF */ + /* Bit 23 Malayalam */ +#define TT_UCR_MALAYALAM (1L << 23) /* U+0D00-U+0D7F */ + /* Bit 24 Thai */ +#define TT_UCR_THAI (1L << 24) /* U+0E00-U+0E7F */ + /* Bit 25 Lao */ +#define TT_UCR_LAO (1L << 25) /* U+0E80-U+0EFF */ + /* Bit 26 Georgian */ + /* Georgian Supplement */ +#define TT_UCR_GEORGIAN (1L << 26) /* U+10A0-U+10FF */ + /* U+2D00-U+2D2F */ + /* Bit 27 Balinese */ +#define TT_UCR_BALINESE (1L << 27) /* U+1B00-U+1B7F */ + /* Bit 28 Hangul Jamo */ +#define TT_UCR_HANGUL_JAMO (1L << 28) /* U+1100-U+11FF */ + /* Bit 29 Latin Extended Additional */ + /* Latin Extended-C */ + /* Latin Extended-D */ +#define TT_UCR_LATIN_EXTENDED_ADDITIONAL (1L << 29) /* U+1E00-U+1EFF */ + /* U+2C60-U+2C7F */ + /* U+A720-U+A7FF */ + /* Bit 30 Greek Extended */ +#define TT_UCR_GREEK_EXTENDED (1L << 30) /* U+1F00-U+1FFF */ + /* Bit 31 General Punctuation */ + /* Supplemental Punctuation */ +#define TT_UCR_GENERAL_PUNCTUATION (1L << 31) /* U+2000-U+206F */ + /* U+2E00-U+2E7F */ + + /* ulUnicodeRange2 */ + /* --------------- */ + + /* Bit 32 Superscripts And Subscripts */ +#define TT_UCR_SUPERSCRIPTS_SUBSCRIPTS (1L << 0) /* U+2070-U+209F */ + /* Bit 33 Currency Symbols */ +#define TT_UCR_CURRENCY_SYMBOLS (1L << 1) /* U+20A0-U+20CF */ + /* Bit 34 Combining Diacritical Marks For Symbols */ +#define TT_UCR_COMBINING_DIACRITICAL_MARKS_SYMB \ + (1L << 2) /* U+20D0-U+20FF */ + /* Bit 35 Letterlike Symbols */ +#define TT_UCR_LETTERLIKE_SYMBOLS (1L << 3) /* U+2100-U+214F */ + /* Bit 36 Number Forms */ +#define TT_UCR_NUMBER_FORMS (1L << 4) /* U+2150-U+218F */ + /* Bit 37 Arrows */ + /* Supplemental Arrows-A */ + /* Supplemental Arrows-B */ + /* Miscellaneous Symbols and Arrows */ +#define TT_UCR_ARROWS (1L << 5) /* U+2190-U+21FF */ + /* U+27F0-U+27FF */ + /* U+2900-U+297F */ + /* U+2B00-U+2BFF */ + /* Bit 38 Mathematical Operators */ + /* Supplemental Mathematical Operators */ + /* Miscellaneous Mathematical Symbols-A */ + /* Miscellaneous Mathematical Symbols-B */ +#define TT_UCR_MATHEMATICAL_OPERATORS (1L << 6) /* U+2200-U+22FF */ + /* U+2A00-U+2AFF */ + /* U+27C0-U+27EF */ + /* U+2980-U+29FF */ + /* Bit 39 Miscellaneous Technical */ +#define TT_UCR_MISCELLANEOUS_TECHNICAL (1L << 7) /* U+2300-U+23FF */ + /* Bit 40 Control Pictures */ +#define TT_UCR_CONTROL_PICTURES (1L << 8) /* U+2400-U+243F */ + /* Bit 41 Optical Character Recognition */ +#define TT_UCR_OCR (1L << 9) /* U+2440-U+245F */ + /* Bit 42 Enclosed Alphanumerics */ +#define TT_UCR_ENCLOSED_ALPHANUMERICS (1L << 10) /* U+2460-U+24FF */ + /* Bit 43 Box Drawing */ +#define TT_UCR_BOX_DRAWING (1L << 11) /* U+2500-U+257F */ + /* Bit 44 Block Elements */ +#define TT_UCR_BLOCK_ELEMENTS (1L << 12) /* U+2580-U+259F */ + /* Bit 45 Geometric Shapes */ +#define TT_UCR_GEOMETRIC_SHAPES (1L << 13) /* U+25A0-U+25FF */ + /* Bit 46 Miscellaneous Symbols */ +#define TT_UCR_MISCELLANEOUS_SYMBOLS (1L << 14) /* U+2600-U+26FF */ + /* Bit 47 Dingbats */ +#define TT_UCR_DINGBATS (1L << 15) /* U+2700-U+27BF */ + /* Bit 48 CJK Symbols and Punctuation */ +#define TT_UCR_CJK_SYMBOLS (1L << 16) /* U+3000-U+303F */ + /* Bit 49 Hiragana */ +#define TT_UCR_HIRAGANA (1L << 17) /* U+3040-U+309F */ + /* Bit 50 Katakana */ + /* Katakana Phonetic Extensions */ +#define TT_UCR_KATAKANA (1L << 18) /* U+30A0-U+30FF */ + /* U+31F0-U+31FF */ + /* Bit 51 Bopomofo */ + /* Bopomofo Extended */ +#define TT_UCR_BOPOMOFO (1L << 19) /* U+3100-U+312F */ + /* U+31A0-U+31BF */ + /* Bit 52 Hangul Compatibility Jamo */ +#define TT_UCR_HANGUL_COMPATIBILITY_JAMO (1L << 20) /* U+3130-U+318F */ + /* Bit 53 Phags-Pa */ +#define TT_UCR_CJK_MISC (1L << 21) /* U+A840-U+A87F */ +#define TT_UCR_KANBUN TT_UCR_CJK_MISC /* deprecated */ +#define TT_UCR_PHAGSPA + /* Bit 54 Enclosed CJK Letters and Months */ +#define TT_UCR_ENCLOSED_CJK_LETTERS_MONTHS (1L << 22) /* U+3200-U+32FF */ + /* Bit 55 CJK Compatibility */ +#define TT_UCR_CJK_COMPATIBILITY (1L << 23) /* U+3300-U+33FF */ + /* Bit 56 Hangul Syllables */ +#define TT_UCR_HANGUL (1L << 24) /* U+AC00-U+D7A3 */ + /* Bit 57 High Surrogates */ + /* High Private Use Surrogates */ + /* Low Surrogates */ + + /* According to OpenType specs v.1.3+, */ + /* setting bit 57 implies that there is */ + /* at least one codepoint beyond the */ + /* Basic Multilingual Plane that is */ + /* supported by this font. So it really */ + /* means >= U+10000. */ +#define TT_UCR_SURROGATES (1L << 25) /* U+D800-U+DB7F */ + /* U+DB80-U+DBFF */ + /* U+DC00-U+DFFF */ +#define TT_UCR_NON_PLANE_0 TT_UCR_SURROGATES + /* Bit 58 Phoenician */ +#define TT_UCR_PHOENICIAN (1L << 26) /*U+10900-U+1091F*/ + /* Bit 59 CJK Unified Ideographs */ + /* CJK Radicals Supplement */ + /* Kangxi Radicals */ + /* Ideographic Description Characters */ + /* CJK Unified Ideographs Extension A */ + /* CJK Unified Ideographs Extension B */ + /* Kanbun */ +#define TT_UCR_CJK_UNIFIED_IDEOGRAPHS (1L << 27) /* U+4E00-U+9FFF */ + /* U+2E80-U+2EFF */ + /* U+2F00-U+2FDF */ + /* U+2FF0-U+2FFF */ + /* U+3400-U+4DB5 */ + /*U+20000-U+2A6DF*/ + /* U+3190-U+319F */ + /* Bit 60 Private Use */ +#define TT_UCR_PRIVATE_USE (1L << 28) /* U+E000-U+F8FF */ + /* Bit 61 CJK Strokes */ + /* CJK Compatibility Ideographs */ + /* CJK Compatibility Ideographs Supplement */ +#define TT_UCR_CJK_COMPATIBILITY_IDEOGRAPHS (1L << 29) /* U+31C0-U+31EF */ + /* U+F900-U+FAFF */ + /*U+2F800-U+2FA1F*/ + /* Bit 62 Alphabetic Presentation Forms */ +#define TT_UCR_ALPHABETIC_PRESENTATION_FORMS (1L << 30) /* U+FB00-U+FB4F */ + /* Bit 63 Arabic Presentation Forms-A */ +#define TT_UCR_ARABIC_PRESENTATION_FORMS_A (1L << 31) /* U+FB50-U+FDFF */ + + /* ulUnicodeRange3 */ + /* --------------- */ + + /* Bit 64 Combining Half Marks */ +#define TT_UCR_COMBINING_HALF_MARKS (1L << 0) /* U+FE20-U+FE2F */ + /* Bit 65 Vertical forms */ + /* CJK Compatibility Forms */ +#define TT_UCR_CJK_COMPATIBILITY_FORMS (1L << 1) /* U+FE10-U+FE1F */ + /* U+FE30-U+FE4F */ + /* Bit 66 Small Form Variants */ +#define TT_UCR_SMALL_FORM_VARIANTS (1L << 2) /* U+FE50-U+FE6F */ + /* Bit 67 Arabic Presentation Forms-B */ +#define TT_UCR_ARABIC_PRESENTATION_FORMS_B (1L << 3) /* U+FE70-U+FEFE */ + /* Bit 68 Halfwidth and Fullwidth Forms */ +#define TT_UCR_HALFWIDTH_FULLWIDTH_FORMS (1L << 4) /* U+FF00-U+FFEF */ + /* Bit 69 Specials */ +#define TT_UCR_SPECIALS (1L << 5) /* U+FFF0-U+FFFD */ + /* Bit 70 Tibetan */ +#define TT_UCR_TIBETAN (1L << 6) /* U+0F00-U+0FFF */ + /* Bit 71 Syriac */ +#define TT_UCR_SYRIAC (1L << 7) /* U+0700-U+074F */ + /* Bit 72 Thaana */ +#define TT_UCR_THAANA (1L << 8) /* U+0780-U+07BF */ + /* Bit 73 Sinhala */ +#define TT_UCR_SINHALA (1L << 9) /* U+0D80-U+0DFF */ + /* Bit 74 Myanmar */ +#define TT_UCR_MYANMAR (1L << 10) /* U+1000-U+109F */ + /* Bit 75 Ethiopic */ + /* Ethiopic Supplement */ + /* Ethiopic Extended */ +#define TT_UCR_ETHIOPIC (1L << 11) /* U+1200-U+137F */ + /* U+1380-U+139F */ + /* U+2D80-U+2DDF */ + /* Bit 76 Cherokee */ +#define TT_UCR_CHEROKEE (1L << 12) /* U+13A0-U+13FF */ + /* Bit 77 Unified Canadian Aboriginal Syllabics */ +#define TT_UCR_CANADIAN_ABORIGINAL_SYLLABICS (1L << 13) /* U+1400-U+167F */ + /* Bit 78 Ogham */ +#define TT_UCR_OGHAM (1L << 14) /* U+1680-U+169F */ + /* Bit 79 Runic */ +#define TT_UCR_RUNIC (1L << 15) /* U+16A0-U+16FF */ + /* Bit 80 Khmer */ + /* Khmer Symbols */ +#define TT_UCR_KHMER (1L << 16) /* U+1780-U+17FF */ + /* U+19E0-U+19FF */ + /* Bit 81 Mongolian */ +#define TT_UCR_MONGOLIAN (1L << 17) /* U+1800-U+18AF */ + /* Bit 82 Braille Patterns */ +#define TT_UCR_BRAILLE (1L << 18) /* U+2800-U+28FF */ + /* Bit 83 Yi Syllables */ + /* Yi Radicals */ +#define TT_UCR_YI (1L << 19) /* U+A000-U+A48F */ + /* U+A490-U+A4CF */ + /* Bit 84 Tagalog */ + /* Hanunoo */ + /* Buhid */ + /* Tagbanwa */ +#define TT_UCR_PHILIPPINE (1L << 20) /* U+1700-U+171F */ + /* U+1720-U+173F */ + /* U+1740-U+175F */ + /* U+1760-U+177F */ + /* Bit 85 Old Italic */ +#define TT_UCR_OLD_ITALIC (1L << 21) /*U+10300-U+1032F*/ + /* Bit 86 Gothic */ +#define TT_UCR_GOTHIC (1L << 22) /*U+10330-U+1034F*/ + /* Bit 87 Deseret */ +#define TT_UCR_DESERET (1L << 23) /*U+10400-U+1044F*/ + /* Bit 88 Byzantine Musical Symbols */ + /* Musical Symbols */ + /* Ancient Greek Musical Notation */ +#define TT_UCR_MUSICAL_SYMBOLS (1L << 24) /*U+1D000-U+1D0FF*/ + /*U+1D100-U+1D1FF*/ + /*U+1D200-U+1D24F*/ + /* Bit 89 Mathematical Alphanumeric Symbols */ +#define TT_UCR_MATH_ALPHANUMERIC_SYMBOLS (1L << 25) /*U+1D400-U+1D7FF*/ + /* Bit 90 Private Use (plane 15) */ + /* Private Use (plane 16) */ +#define TT_UCR_PRIVATE_USE_SUPPLEMENTARY (1L << 26) /*U+F0000-U+FFFFD*/ + /*U+100000-U+10FFFD*/ + /* Bit 91 Variation Selectors */ + /* Variation Selectors Supplement */ +#define TT_UCR_VARIATION_SELECTORS (1L << 27) /* U+FE00-U+FE0F */ + /*U+E0100-U+E01EF*/ + /* Bit 92 Tags */ +#define TT_UCR_TAGS (1L << 28) /*U+E0000-U+E007F*/ + /* Bit 93 Limbu */ +#define TT_UCR_LIMBU (1L << 29) /* U+1900-U+194F */ + /* Bit 94 Tai Le */ +#define TT_UCR_TAI_LE (1L << 30) /* U+1950-U+197F */ + /* Bit 95 New Tai Lue */ +#define TT_UCR_NEW_TAI_LUE (1L << 31) /* U+1980-U+19DF */ + + /* ulUnicodeRange4 */ + /* --------------- */ + + /* Bit 96 Buginese */ +#define TT_UCR_BUGINESE (1L << 0) /* U+1A00-U+1A1F */ + /* Bit 97 Glagolitic */ +#define TT_UCR_GLAGOLITIC (1L << 1) /* U+2C00-U+2C5F */ + /* Bit 98 Tifinagh */ +#define TT_UCR_TIFINAGH (1L << 2) /* U+2D30-U+2D7F */ + /* Bit 99 Yijing Hexagram Symbols */ +#define TT_UCR_YIJING (1L << 3) /* U+4DC0-U+4DFF */ + /* Bit 100 Syloti Nagri */ +#define TT_UCR_SYLOTI_NAGRI (1L << 4) /* U+A800-U+A82F */ + /* Bit 101 Linear B Syllabary */ + /* Linear B Ideograms */ + /* Aegean Numbers */ +#define TT_UCR_LINEAR_B (1L << 5) /*U+10000-U+1007F*/ + /*U+10080-U+100FF*/ + /*U+10100-U+1013F*/ + /* Bit 102 Ancient Greek Numbers */ +#define TT_UCR_ANCIENT_GREEK_NUMBERS (1L << 6) /*U+10140-U+1018F*/ + /* Bit 103 Ugaritic */ +#define TT_UCR_UGARITIC (1L << 7) /*U+10380-U+1039F*/ + /* Bit 104 Old Persian */ +#define TT_UCR_OLD_PERSIAN (1L << 8) /*U+103A0-U+103DF*/ + /* Bit 105 Shavian */ +#define TT_UCR_SHAVIAN (1L << 9) /*U+10450-U+1047F*/ + /* Bit 106 Osmanya */ +#define TT_UCR_OSMANYA (1L << 10) /*U+10480-U+104AF*/ + /* Bit 107 Cypriot Syllabary */ +#define TT_UCR_CYPRIOT_SYLLABARY (1L << 11) /*U+10800-U+1083F*/ + /* Bit 108 Kharoshthi */ +#define TT_UCR_KHAROSHTHI (1L << 12) /*U+10A00-U+10A5F*/ + /* Bit 109 Tai Xuan Jing Symbols */ +#define TT_UCR_TAI_XUAN_JING (1L << 13) /*U+1D300-U+1D35F*/ + /* Bit 110 Cuneiform */ + /* Cuneiform Numbers and Punctuation */ +#define TT_UCR_CUNEIFORM (1L << 14) /*U+12000-U+123FF*/ + /*U+12400-U+1247F*/ + /* Bit 111 Counting Rod Numerals */ +#define TT_UCR_COUNTING_ROD_NUMERALS (1L << 15) /*U+1D360-U+1D37F*/ + /* Bit 112 Sundanese */ +#define TT_UCR_SUNDANESE (1L << 16) /* U+1B80-U+1BBF */ + /* Bit 113 Lepcha */ +#define TT_UCR_LEPCHA (1L << 17) /* U+1C00-U+1C4F */ + /* Bit 114 Ol Chiki */ +#define TT_UCR_OL_CHIKI (1L << 18) /* U+1C50-U+1C7F */ + /* Bit 115 Saurashtra */ +#define TT_UCR_SAURASHTRA (1L << 19) /* U+A880-U+A8DF */ + /* Bit 116 Kayah Li */ +#define TT_UCR_KAYAH_LI (1L << 20) /* U+A900-U+A92F */ + /* Bit 117 Rejang */ +#define TT_UCR_REJANG (1L << 21) /* U+A930-U+A95F */ + /* Bit 118 Cham */ +#define TT_UCR_CHAM (1L << 22) /* U+AA00-U+AA5F */ + /* Bit 119 Ancient Symbols */ +#define TT_UCR_ANCIENT_SYMBOLS (1L << 23) /*U+10190-U+101CF*/ + /* Bit 120 Phaistos Disc */ +#define TT_UCR_PHAISTOS_DISC (1L << 24) /*U+101D0-U+101FF*/ + /* Bit 121 Carian */ + /* Lycian */ + /* Lydian */ +#define TT_UCR_OLD_ANATOLIAN (1L << 25) /*U+102A0-U+102DF*/ + /*U+10280-U+1029F*/ + /*U+10920-U+1093F*/ + /* Bit 122 Domino Tiles */ + /* Mahjong Tiles */ +#define TT_UCR_GAME_TILES (1L << 26) /*U+1F030-U+1F09F*/ + /*U+1F000-U+1F02F*/ + /* Bit 123-127 Reserved for process-internal usage */ + + /* */ + + /* for backward compatibility with older FreeType versions */ +#define TT_UCR_ARABIC_PRESENTATION_A \ + TT_UCR_ARABIC_PRESENTATION_FORMS_A +#define TT_UCR_ARABIC_PRESENTATION_B \ + TT_UCR_ARABIC_PRESENTATION_FORMS_B + +#define TT_UCR_COMBINING_DIACRITICS \ + TT_UCR_COMBINING_DIACRITICAL_MARKS +#define TT_UCR_COMBINING_DIACRITICS_SYMB \ + TT_UCR_COMBINING_DIACRITICAL_MARKS_SYMB + + +FT_END_HEADER + +#endif /* TTNAMEID_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/tttables.h b/freetype/include/freetype2/freetype/tttables.h new file mode 100644 index 0000000..ce6a617 --- /dev/null +++ b/freetype/include/freetype2/freetype/tttables.h @@ -0,0 +1,846 @@ +/***************************************************************************/ +/* */ +/* tttables.h */ +/* */ +/* Basic SFNT/TrueType tables definitions and interface */ +/* (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTTABLES_H_ +#define TTTABLES_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + /*************************************************************************/ + /* */ + /* <Section> */ + /* truetype_tables */ + /* */ + /* <Title> */ + /* TrueType Tables */ + /* */ + /* <Abstract> */ + /* TrueType specific table types and functions. */ + /* */ + /* <Description> */ + /* This section contains definitions of some basic tables specific to */ + /* TrueType and OpenType as well as some routines used to access and */ + /* process them. */ + /* */ + /* <Order> */ + /* TT_Header */ + /* TT_HoriHeader */ + /* TT_VertHeader */ + /* TT_OS2 */ + /* TT_Postscript */ + /* TT_PCLT */ + /* TT_MaxProfile */ + /* */ + /* FT_Sfnt_Tag */ + /* FT_Get_Sfnt_Table */ + /* FT_Load_Sfnt_Table */ + /* FT_Sfnt_Table_Info */ + /* */ + /* FT_Get_CMap_Language_ID */ + /* FT_Get_CMap_Format */ + /* */ + /* FT_PARAM_TAG_UNPATENTED_HINTING */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_Header */ + /* */ + /* <Description> */ + /* A structure to model a TrueType font header table. All fields */ + /* follow the OpenType specification. */ + /* */ + typedef struct TT_Header_ + { + FT_Fixed Table_Version; + FT_Fixed Font_Revision; + + FT_Long CheckSum_Adjust; + FT_Long Magic_Number; + + FT_UShort Flags; + FT_UShort Units_Per_EM; + + FT_Long Created [2]; + FT_Long Modified[2]; + + FT_Short xMin; + FT_Short yMin; + FT_Short xMax; + FT_Short yMax; + + FT_UShort Mac_Style; + FT_UShort Lowest_Rec_PPEM; + + FT_Short Font_Direction; + FT_Short Index_To_Loc_Format; + FT_Short Glyph_Data_Format; + + } TT_Header; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_HoriHeader */ + /* */ + /* <Description> */ + /* A structure to model a TrueType horizontal header, the `hhea' */ + /* table, as well as the corresponding horizontal metrics table, */ + /* `hmtx'. */ + /* */ + /* <Fields> */ + /* Version :: The table version. */ + /* */ + /* Ascender :: The font's ascender, i.e., the distance */ + /* from the baseline to the top-most of all */ + /* glyph points found in the font. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of the */ + /* glyphs found in the font (maybe ASCII). */ + /* */ + /* You should use the `sTypoAscender' field */ + /* of the `OS/2' table instead if you want */ + /* the correct one. */ + /* */ + /* Descender :: The font's descender, i.e., the distance */ + /* from the baseline to the bottom-most of */ + /* all glyph points found in the font. It */ + /* is negative. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of the */ + /* glyphs found in the font (maybe ASCII). */ + /* */ + /* You should use the `sTypoDescender' */ + /* field of the `OS/2' table instead if you */ + /* want the correct one. */ + /* */ + /* Line_Gap :: The font's line gap, i.e., the distance */ + /* to add to the ascender and descender to */ + /* get the BTB, i.e., the */ + /* baseline-to-baseline distance for the */ + /* font. */ + /* */ + /* advance_Width_Max :: This field is the maximum of all advance */ + /* widths found in the font. It can be */ + /* used to compute the maximum width of an */ + /* arbitrary string of text. */ + /* */ + /* min_Left_Side_Bearing :: The minimum left side bearing of all */ + /* glyphs within the font. */ + /* */ + /* min_Right_Side_Bearing :: The minimum right side bearing of all */ + /* glyphs within the font. */ + /* */ + /* xMax_Extent :: The maximum horizontal extent (i.e., the */ + /* `width' of a glyph's bounding box) for */ + /* all glyphs in the font. */ + /* */ + /* caret_Slope_Rise :: The rise coefficient of the cursor's */ + /* slope of the cursor (slope=rise/run). */ + /* */ + /* caret_Slope_Run :: The run coefficient of the cursor's */ + /* slope. */ + /* */ + /* caret_Offset :: The cursor's offset for slanted fonts. */ + /* */ + /* Reserved :: 8~reserved bytes. */ + /* */ + /* metric_Data_Format :: Always~0. */ + /* */ + /* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */ + /* table -- this value can be smaller than */ + /* the total number of glyphs in the font. */ + /* */ + /* long_metrics :: A pointer into the `hmtx' table. */ + /* */ + /* short_metrics :: A pointer into the `hmtx' table. */ + /* */ + /* <Note> */ + /* For an OpenType variation font, the values of the following fields */ + /* can change after a call to @FT_Set_Var_Design_Coordinates (and */ + /* friends) if the font contains an `MVAR' table: `caret_Slope_Rise', */ + /* `caret_Slope_Run', and `caret_Offset'. */ + /* */ + typedef struct TT_HoriHeader_ + { + FT_Fixed Version; + FT_Short Ascender; + FT_Short Descender; + FT_Short Line_Gap; + + FT_UShort advance_Width_Max; /* advance width maximum */ + + FT_Short min_Left_Side_Bearing; /* minimum left-sb */ + FT_Short min_Right_Side_Bearing; /* minimum right-sb */ + FT_Short xMax_Extent; /* xmax extents */ + FT_Short caret_Slope_Rise; + FT_Short caret_Slope_Run; + FT_Short caret_Offset; + + FT_Short Reserved[4]; + + FT_Short metric_Data_Format; + FT_UShort number_Of_HMetrics; + + /* The following fields are not defined by the OpenType specification */ + /* but they are used to connect the metrics header to the relevant */ + /* `hmtx' table. */ + + void* long_metrics; + void* short_metrics; + + } TT_HoriHeader; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_VertHeader */ + /* */ + /* <Description> */ + /* A structure used to model a TrueType vertical header, the `vhea' */ + /* table, as well as the corresponding vertical metrics table, */ + /* `vmtx'. */ + /* */ + /* <Fields> */ + /* Version :: The table version. */ + /* */ + /* Ascender :: The font's ascender, i.e., the distance */ + /* from the baseline to the top-most of */ + /* all glyph points found in the font. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of */ + /* the glyphs found in the font (maybe */ + /* ASCII). */ + /* */ + /* You should use the `sTypoAscender' */ + /* field of the `OS/2' table instead if */ + /* you want the correct one. */ + /* */ + /* Descender :: The font's descender, i.e., the */ + /* distance from the baseline to the */ + /* bottom-most of all glyph points found */ + /* in the font. It is negative. */ + /* */ + /* This value is invalid in many fonts, as */ + /* it is usually set by the font designer, */ + /* and often reflects only a portion of */ + /* the glyphs found in the font (maybe */ + /* ASCII). */ + /* */ + /* You should use the `sTypoDescender' */ + /* field of the `OS/2' table instead if */ + /* you want the correct one. */ + /* */ + /* Line_Gap :: The font's line gap, i.e., the distance */ + /* to add to the ascender and descender to */ + /* get the BTB, i.e., the */ + /* baseline-to-baseline distance for the */ + /* font. */ + /* */ + /* advance_Height_Max :: This field is the maximum of all */ + /* advance heights found in the font. It */ + /* can be used to compute the maximum */ + /* height of an arbitrary string of text. */ + /* */ + /* min_Top_Side_Bearing :: The minimum top side bearing of all */ + /* glyphs within the font. */ + /* */ + /* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */ + /* glyphs within the font. */ + /* */ + /* yMax_Extent :: The maximum vertical extent (i.e., the */ + /* `height' of a glyph's bounding box) for */ + /* all glyphs in the font. */ + /* */ + /* caret_Slope_Rise :: The rise coefficient of the cursor's */ + /* slope of the cursor (slope=rise/run). */ + /* */ + /* caret_Slope_Run :: The run coefficient of the cursor's */ + /* slope. */ + /* */ + /* caret_Offset :: The cursor's offset for slanted fonts. */ + /* */ + /* Reserved :: 8~reserved bytes. */ + /* */ + /* metric_Data_Format :: Always~0. */ + /* */ + /* number_Of_VMetrics :: Number of VMetrics entries in the */ + /* `vmtx' table -- this value can be */ + /* smaller than the total number of glyphs */ + /* in the font. */ + /* */ + /* long_metrics :: A pointer into the `vmtx' table. */ + /* */ + /* short_metrics :: A pointer into the `vmtx' table. */ + /* */ + /* <Note> */ + /* For an OpenType variation font, the values of the following fields */ + /* can change after a call to @FT_Set_Var_Design_Coordinates (and */ + /* friends) if the font contains an `MVAR' table: `Ascender', */ + /* `Descender', `Line_Gap', `caret_Slope_Rise', `caret_Slope_Run', */ + /* and `caret_Offset'. */ + /* */ + typedef struct TT_VertHeader_ + { + FT_Fixed Version; + FT_Short Ascender; + FT_Short Descender; + FT_Short Line_Gap; + + FT_UShort advance_Height_Max; /* advance height maximum */ + + FT_Short min_Top_Side_Bearing; /* minimum top-sb */ + FT_Short min_Bottom_Side_Bearing; /* minimum bottom-sb */ + FT_Short yMax_Extent; /* ymax extents */ + FT_Short caret_Slope_Rise; + FT_Short caret_Slope_Run; + FT_Short caret_Offset; + + FT_Short Reserved[4]; + + FT_Short metric_Data_Format; + FT_UShort number_Of_VMetrics; + + /* The following fields are not defined by the OpenType specification */ + /* but they are used to connect the metrics header to the relevant */ + /* `vmtx' table. */ + + void* long_metrics; + void* short_metrics; + + } TT_VertHeader; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_OS2 */ + /* */ + /* <Description> */ + /* A structure to model a TrueType `OS/2' table. All fields comply */ + /* to the OpenType specification. */ + /* */ + /* Note that we now support old Mac fonts that do not include an */ + /* `OS/2' table. In this case, the `version' field is always set to */ + /* 0xFFFF. */ + /* */ + /* <Note> */ + /* For an OpenType variation font, the values of the following fields */ + /* can change after a call to @FT_Set_Var_Design_Coordinates (and */ + /* friends) if the font contains an `MVAR' table: `sCapHeight', */ + /* `sTypoAscender', `sTypoDescender', `sTypoLineGap', `sxHeight', */ + /* `usWinAscent', `usWinDescent', `yStrikeoutPosition', */ + /* `yStrikeoutSize', `ySubscriptXOffset', `ySubScriptXSize', */ + /* `ySubscriptYOffset', `ySubscriptYSize', `ySuperscriptXOffset', */ + /* `ySuperscriptXSize', `ySuperscriptYOffset', and */ + /* `ySuperscriptYSize'. */ + /* */ + /* Possible values for bits in the `ulUnicodeRangeX' fields are given */ + /* by the @TT_UCR_XXX macros. */ + /* */ + + typedef struct TT_OS2_ + { + FT_UShort version; /* 0x0001 - more or 0xFFFF */ + FT_Short xAvgCharWidth; + FT_UShort usWeightClass; + FT_UShort usWidthClass; + FT_UShort fsType; + FT_Short ySubscriptXSize; + FT_Short ySubscriptYSize; + FT_Short ySubscriptXOffset; + FT_Short ySubscriptYOffset; + FT_Short ySuperscriptXSize; + FT_Short ySuperscriptYSize; + FT_Short ySuperscriptXOffset; + FT_Short ySuperscriptYOffset; + FT_Short yStrikeoutSize; + FT_Short yStrikeoutPosition; + FT_Short sFamilyClass; + + FT_Byte panose[10]; + + FT_ULong ulUnicodeRange1; /* Bits 0-31 */ + FT_ULong ulUnicodeRange2; /* Bits 32-63 */ + FT_ULong ulUnicodeRange3; /* Bits 64-95 */ + FT_ULong ulUnicodeRange4; /* Bits 96-127 */ + + FT_Char achVendID[4]; + + FT_UShort fsSelection; + FT_UShort usFirstCharIndex; + FT_UShort usLastCharIndex; + FT_Short sTypoAscender; + FT_Short sTypoDescender; + FT_Short sTypoLineGap; + FT_UShort usWinAscent; + FT_UShort usWinDescent; + + /* only version 1 and higher: */ + + FT_ULong ulCodePageRange1; /* Bits 0-31 */ + FT_ULong ulCodePageRange2; /* Bits 32-63 */ + + /* only version 2 and higher: */ + + FT_Short sxHeight; + FT_Short sCapHeight; + FT_UShort usDefaultChar; + FT_UShort usBreakChar; + FT_UShort usMaxContext; + + /* only version 5 and higher: */ + + FT_UShort usLowerOpticalPointSize; /* in twips (1/20th points) */ + FT_UShort usUpperOpticalPointSize; /* in twips (1/20th points) */ + + } TT_OS2; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_Postscript */ + /* */ + /* <Description> */ + /* A structure to model a TrueType `post' table. All fields comply */ + /* to the OpenType specification. This structure does not reference */ + /* a font's PostScript glyph names; use @FT_Get_Glyph_Name to */ + /* retrieve them. */ + /* */ + /* <Note> */ + /* For an OpenType variation font, the values of the following fields */ + /* can change after a call to @FT_Set_Var_Design_Coordinates (and */ + /* friends) if the font contains an `MVAR' table: `underlinePosition' */ + /* and `underlineThickness'. */ + /* */ + typedef struct TT_Postscript_ + { + FT_Fixed FormatType; + FT_Fixed italicAngle; + FT_Short underlinePosition; + FT_Short underlineThickness; + FT_ULong isFixedPitch; + FT_ULong minMemType42; + FT_ULong maxMemType42; + FT_ULong minMemType1; + FT_ULong maxMemType1; + + /* Glyph names follow in the `post' table, but we don't */ + /* load them by default. */ + + } TT_Postscript; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_PCLT */ + /* */ + /* <Description> */ + /* A structure to model a TrueType `PCLT' table. All fields comply */ + /* to the OpenType specification. */ + /* */ + typedef struct TT_PCLT_ + { + FT_Fixed Version; + FT_ULong FontNumber; + FT_UShort Pitch; + FT_UShort xHeight; + FT_UShort Style; + FT_UShort TypeFamily; + FT_UShort CapHeight; + FT_UShort SymbolSet; + FT_Char TypeFace[16]; + FT_Char CharacterComplement[8]; + FT_Char FileName[6]; + FT_Char StrokeWeight; + FT_Char WidthType; + FT_Byte SerifStyle; + FT_Byte Reserved; + + } TT_PCLT; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* TT_MaxProfile */ + /* */ + /* <Description> */ + /* The maximum profile (`maxp') table contains many max values, which */ + /* can be used to pre-allocate arrays for speeding up glyph loading */ + /* and hinting. */ + /* */ + /* <Fields> */ + /* version :: The version number. */ + /* */ + /* numGlyphs :: The number of glyphs in this TrueType */ + /* font. */ + /* */ + /* maxPoints :: The maximum number of points in a */ + /* non-composite TrueType glyph. See also */ + /* `maxCompositePoints'. */ + /* */ + /* maxContours :: The maximum number of contours in a */ + /* non-composite TrueType glyph. See also */ + /* `maxCompositeContours'. */ + /* */ + /* maxCompositePoints :: The maximum number of points in a */ + /* composite TrueType glyph. See also */ + /* `maxPoints'. */ + /* */ + /* maxCompositeContours :: The maximum number of contours in a */ + /* composite TrueType glyph. See also */ + /* `maxContours'. */ + /* */ + /* maxZones :: The maximum number of zones used for */ + /* glyph hinting. */ + /* */ + /* maxTwilightPoints :: The maximum number of points in the */ + /* twilight zone used for glyph hinting. */ + /* */ + /* maxStorage :: The maximum number of elements in the */ + /* storage area used for glyph hinting. */ + /* */ + /* maxFunctionDefs :: The maximum number of function */ + /* definitions in the TrueType bytecode for */ + /* this font. */ + /* */ + /* maxInstructionDefs :: The maximum number of instruction */ + /* definitions in the TrueType bytecode for */ + /* this font. */ + /* */ + /* maxStackElements :: The maximum number of stack elements used */ + /* during bytecode interpretation. */ + /* */ + /* maxSizeOfInstructions :: The maximum number of TrueType opcodes */ + /* used for glyph hinting. */ + /* */ + /* maxComponentElements :: The maximum number of simple (i.e., non- */ + /* composite) glyphs in a composite glyph. */ + /* */ + /* maxComponentDepth :: The maximum nesting depth of composite */ + /* glyphs. */ + /* */ + /* <Note> */ + /* This structure is only used during font loading. */ + /* */ + typedef struct TT_MaxProfile_ + { + FT_Fixed version; + FT_UShort numGlyphs; + FT_UShort maxPoints; + FT_UShort maxContours; + FT_UShort maxCompositePoints; + FT_UShort maxCompositeContours; + FT_UShort maxZones; + FT_UShort maxTwilightPoints; + FT_UShort maxStorage; + FT_UShort maxFunctionDefs; + FT_UShort maxInstructionDefs; + FT_UShort maxStackElements; + FT_UShort maxSizeOfInstructions; + FT_UShort maxComponentElements; + FT_UShort maxComponentDepth; + + } TT_MaxProfile; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Sfnt_Tag */ + /* */ + /* <Description> */ + /* An enumeration to specify indices of SFNT tables loaded and parsed */ + /* by FreeType during initialization of an SFNT font. Used in the */ + /* @FT_Get_Sfnt_Table API function. */ + /* */ + /* <Values> */ + /* FT_SFNT_HEAD :: To access the font's @TT_Header structure. */ + /* */ + /* FT_SFNT_MAXP :: To access the font's @TT_MaxProfile structure. */ + /* */ + /* FT_SFNT_OS2 :: To access the font's @TT_OS2 structure. */ + /* */ + /* FT_SFNT_HHEA :: To access the font's @TT_HoriHeader structure. */ + /* */ + /* FT_SFNT_VHEA :: To access the font's @TT_VertHeader structure. */ + /* */ + /* FT_SFNT_POST :: To access the font's @TT_Postscript structure. */ + /* */ + /* FT_SFNT_PCLT :: To access the font's @TT_PCLT structure. */ + /* */ + typedef enum FT_Sfnt_Tag_ + { + FT_SFNT_HEAD, + FT_SFNT_MAXP, + FT_SFNT_OS2, + FT_SFNT_HHEA, + FT_SFNT_VHEA, + FT_SFNT_POST, + FT_SFNT_PCLT, + + FT_SFNT_MAX + + } FT_Sfnt_Tag; + + /* these constants are deprecated; use the corresponding `FT_Sfnt_Tag' */ + /* values instead */ +#define ft_sfnt_head FT_SFNT_HEAD +#define ft_sfnt_maxp FT_SFNT_MAXP +#define ft_sfnt_os2 FT_SFNT_OS2 +#define ft_sfnt_hhea FT_SFNT_HHEA +#define ft_sfnt_vhea FT_SFNT_VHEA +#define ft_sfnt_post FT_SFNT_POST +#define ft_sfnt_pclt FT_SFNT_PCLT + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Sfnt_Table */ + /* */ + /* <Description> */ + /* Return a pointer to a given SFNT table stored within a face. */ + /* */ + /* <Input> */ + /* face :: A handle to the source. */ + /* */ + /* tag :: The index of the SFNT table. */ + /* */ + /* <Return> */ + /* A type-less pointer to the table. This will be NULL in case of */ + /* error, or if the corresponding table was not found *OR* loaded */ + /* from the file. */ + /* */ + /* Use a typecast according to `tag' to access the structure */ + /* elements. */ + /* */ + /* <Note> */ + /* The table is owned by the face object and disappears with it. */ + /* */ + /* This function is only useful to access SFNT tables that are loaded */ + /* by the sfnt, truetype, and opentype drivers. See @FT_Sfnt_Tag for */ + /* a list. */ + /* */ + /* Here an example how to access the `vhea' table: */ + /* */ + /* { */ + /* TT_VertHeader* vert_header; */ + /* */ + /* */ + /* vert_header = */ + /* (TT_VertHeader*)FT_Get_Sfnt_Table( face, FT_SFNT_VHEA ); */ + /* } */ + /* */ + FT_EXPORT( void* ) + FT_Get_Sfnt_Table( FT_Face face, + FT_Sfnt_Tag tag ); + + + /************************************************************************** + * + * @function: + * FT_Load_Sfnt_Table + * + * @description: + * Load any SFNT font table into client memory. + * + * @input: + * face :: + * A handle to the source face. + * + * tag :: + * The four-byte tag of the table to load. Use value~0 if you want + * to access the whole font file. Otherwise, you can use one of the + * definitions found in the @FT_TRUETYPE_TAGS_H file, or forge a new + * one with @FT_MAKE_TAG. + * + * offset :: + * The starting offset in the table (or file if tag~==~0). + * + * @output: + * buffer :: + * The target buffer address. The client must ensure that the memory + * array is big enough to hold the data. + * + * @inout: + * length :: + * If the `length' parameter is NULL, try to load the whole table. + * Return an error code if it fails. + * + * Else, if `*length' is~0, exit immediately while returning the + * table's (or file) full size in it. + * + * Else the number of bytes to read from the table or file, from the + * starting offset. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * If you need to determine the table's length you should first call this + * function with `*length' set to~0, as in the following example: + * + * { + * FT_ULong length = 0; + * + * + * error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length ); + * if ( error ) { ... table does not exist ... } + * + * buffer = malloc( length ); + * if ( buffer == NULL ) { ... not enough memory ... } + * + * error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length ); + * if ( error ) { ... could not load table ... } + * } + * + * Note that structures like @TT_Header or @TT_OS2 can't be used with + * this function; they are limited to @FT_Get_Sfnt_Table. Reason is that + * those structures depend on the processor architecture, with varying + * size (e.g. 32bit vs. 64bit) or order (big endian vs. little endian). + * + */ + FT_EXPORT( FT_Error ) + FT_Load_Sfnt_Table( FT_Face face, + FT_ULong tag, + FT_Long offset, + FT_Byte* buffer, + FT_ULong* length ); + + + /************************************************************************** + * + * @function: + * FT_Sfnt_Table_Info + * + * @description: + * Return information on an SFNT table. + * + * @input: + * face :: + * A handle to the source face. + * + * table_index :: + * The index of an SFNT table. The function returns + * FT_Err_Table_Missing for an invalid value. + * + * @inout: + * tag :: + * The name tag of the SFNT table. If the value is NULL, `table_index' + * is ignored, and `length' returns the number of SFNT tables in the + * font. + * + * @output: + * length :: + * The length of the SFNT table (or the number of SFNT tables, depending + * on `tag'). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * While parsing fonts, FreeType handles SFNT tables with length zero as + * missing. + * + */ + FT_EXPORT( FT_Error ) + FT_Sfnt_Table_Info( FT_Face face, + FT_UInt table_index, + FT_ULong *tag, + FT_ULong *length ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_CMap_Language_ID */ + /* */ + /* <Description> */ + /* Return cmap language ID as specified in the OpenType standard. */ + /* Definitions of language ID values are in file @FT_TRUETYPE_IDS_H. */ + /* */ + /* <Input> */ + /* charmap :: */ + /* The target charmap. */ + /* */ + /* <Return> */ + /* The language ID of `charmap'. If `charmap' doesn't belong to an */ + /* SFNT face, just return~0 as the default value. */ + /* */ + /* For a format~14 cmap (to access Unicode IVS), the return value is */ + /* 0xFFFFFFFF. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_CMap_Language_ID( FT_CharMap charmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_CMap_Format */ + /* */ + /* <Description> */ + /* Return the format of an SFNT `cmap' table. */ + /* */ + /* <Input> */ + /* charmap :: */ + /* The target charmap. */ + /* */ + /* <Return> */ + /* The format of `charmap'. If `charmap' doesn't belong to an SFNT */ + /* face, return -1. */ + /* */ + FT_EXPORT( FT_Long ) + FT_Get_CMap_Format( FT_CharMap charmap ); + + /* */ + + +FT_END_HEADER + +#endif /* TTTABLES_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/freetype/tttags.h b/freetype/include/freetype2/freetype/tttags.h new file mode 100644 index 0000000..e5cee68 --- /dev/null +++ b/freetype/include/freetype2/freetype/tttags.h @@ -0,0 +1,121 @@ +/***************************************************************************/ +/* */ +/* tttags.h */ +/* */ +/* Tags for TrueType and OpenType tables (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTAGS_H_ +#define TTAGS_H_ + + +#include <ft2build.h> +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + +#define TTAG_avar FT_MAKE_TAG( 'a', 'v', 'a', 'r' ) +#define TTAG_BASE FT_MAKE_TAG( 'B', 'A', 'S', 'E' ) +#define TTAG_bdat FT_MAKE_TAG( 'b', 'd', 'a', 't' ) +#define TTAG_BDF FT_MAKE_TAG( 'B', 'D', 'F', ' ' ) +#define TTAG_bhed FT_MAKE_TAG( 'b', 'h', 'e', 'd' ) +#define TTAG_bloc FT_MAKE_TAG( 'b', 'l', 'o', 'c' ) +#define TTAG_bsln FT_MAKE_TAG( 'b', 's', 'l', 'n' ) +#define TTAG_CBDT FT_MAKE_TAG( 'C', 'B', 'D', 'T' ) +#define TTAG_CBLC FT_MAKE_TAG( 'C', 'B', 'L', 'C' ) +#define TTAG_CFF FT_MAKE_TAG( 'C', 'F', 'F', ' ' ) +#define TTAG_CFF2 FT_MAKE_TAG( 'C', 'F', 'F', '2' ) +#define TTAG_CID FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) +#define TTAG_cmap FT_MAKE_TAG( 'c', 'm', 'a', 'p' ) +#define TTAG_cvar FT_MAKE_TAG( 'c', 'v', 'a', 'r' ) +#define TTAG_cvt FT_MAKE_TAG( 'c', 'v', 't', ' ' ) +#define TTAG_DSIG FT_MAKE_TAG( 'D', 'S', 'I', 'G' ) +#define TTAG_EBDT FT_MAKE_TAG( 'E', 'B', 'D', 'T' ) +#define TTAG_EBLC FT_MAKE_TAG( 'E', 'B', 'L', 'C' ) +#define TTAG_EBSC FT_MAKE_TAG( 'E', 'B', 'S', 'C' ) +#define TTAG_feat FT_MAKE_TAG( 'f', 'e', 'a', 't' ) +#define TTAG_FOND FT_MAKE_TAG( 'F', 'O', 'N', 'D' ) +#define TTAG_fpgm FT_MAKE_TAG( 'f', 'p', 'g', 'm' ) +#define TTAG_fvar FT_MAKE_TAG( 'f', 'v', 'a', 'r' ) +#define TTAG_gasp FT_MAKE_TAG( 'g', 'a', 's', 'p' ) +#define TTAG_GDEF FT_MAKE_TAG( 'G', 'D', 'E', 'F' ) +#define TTAG_glyf FT_MAKE_TAG( 'g', 'l', 'y', 'f' ) +#define TTAG_GPOS FT_MAKE_TAG( 'G', 'P', 'O', 'S' ) +#define TTAG_GSUB FT_MAKE_TAG( 'G', 'S', 'U', 'B' ) +#define TTAG_gvar FT_MAKE_TAG( 'g', 'v', 'a', 'r' ) +#define TTAG_HVAR FT_MAKE_TAG( 'H', 'V', 'A', 'R' ) +#define TTAG_hdmx FT_MAKE_TAG( 'h', 'd', 'm', 'x' ) +#define TTAG_head FT_MAKE_TAG( 'h', 'e', 'a', 'd' ) +#define TTAG_hhea FT_MAKE_TAG( 'h', 'h', 'e', 'a' ) +#define TTAG_hmtx FT_MAKE_TAG( 'h', 'm', 't', 'x' ) +#define TTAG_JSTF FT_MAKE_TAG( 'J', 'S', 'T', 'F' ) +#define TTAG_just FT_MAKE_TAG( 'j', 'u', 's', 't' ) +#define TTAG_kern FT_MAKE_TAG( 'k', 'e', 'r', 'n' ) +#define TTAG_lcar FT_MAKE_TAG( 'l', 'c', 'a', 'r' ) +#define TTAG_loca FT_MAKE_TAG( 'l', 'o', 'c', 'a' ) +#define TTAG_LTSH FT_MAKE_TAG( 'L', 'T', 'S', 'H' ) +#define TTAG_LWFN FT_MAKE_TAG( 'L', 'W', 'F', 'N' ) +#define TTAG_MATH FT_MAKE_TAG( 'M', 'A', 'T', 'H' ) +#define TTAG_maxp FT_MAKE_TAG( 'm', 'a', 'x', 'p' ) +#define TTAG_META FT_MAKE_TAG( 'M', 'E', 'T', 'A' ) +#define TTAG_MMFX FT_MAKE_TAG( 'M', 'M', 'F', 'X' ) +#define TTAG_MMSD FT_MAKE_TAG( 'M', 'M', 'S', 'D' ) +#define TTAG_mort FT_MAKE_TAG( 'm', 'o', 'r', 't' ) +#define TTAG_morx FT_MAKE_TAG( 'm', 'o', 'r', 'x' ) +#define TTAG_MVAR FT_MAKE_TAG( 'M', 'V', 'A', 'R' ) +#define TTAG_name FT_MAKE_TAG( 'n', 'a', 'm', 'e' ) +#define TTAG_opbd FT_MAKE_TAG( 'o', 'p', 'b', 'd' ) +#define TTAG_OS2 FT_MAKE_TAG( 'O', 'S', '/', '2' ) +#define TTAG_OTTO FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) +#define TTAG_PCLT FT_MAKE_TAG( 'P', 'C', 'L', 'T' ) +#define TTAG_POST FT_MAKE_TAG( 'P', 'O', 'S', 'T' ) +#define TTAG_post FT_MAKE_TAG( 'p', 'o', 's', 't' ) +#define TTAG_prep FT_MAKE_TAG( 'p', 'r', 'e', 'p' ) +#define TTAG_prop FT_MAKE_TAG( 'p', 'r', 'o', 'p' ) +#define TTAG_sbix FT_MAKE_TAG( 's', 'b', 'i', 'x' ) +#define TTAG_sfnt FT_MAKE_TAG( 's', 'f', 'n', 't' ) +#define TTAG_SING FT_MAKE_TAG( 'S', 'I', 'N', 'G' ) +#define TTAG_trak FT_MAKE_TAG( 't', 'r', 'a', 'k' ) +#define TTAG_true FT_MAKE_TAG( 't', 'r', 'u', 'e' ) +#define TTAG_ttc FT_MAKE_TAG( 't', 't', 'c', ' ' ) +#define TTAG_ttcf FT_MAKE_TAG( 't', 't', 'c', 'f' ) +#define TTAG_TYP1 FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) +#define TTAG_typ1 FT_MAKE_TAG( 't', 'y', 'p', '1' ) +#define TTAG_VDMX FT_MAKE_TAG( 'V', 'D', 'M', 'X' ) +#define TTAG_vhea FT_MAKE_TAG( 'v', 'h', 'e', 'a' ) +#define TTAG_vmtx FT_MAKE_TAG( 'v', 'm', 't', 'x' ) +#define TTAG_VVAR FT_MAKE_TAG( 'V', 'V', 'A', 'R' ) +#define TTAG_wOFF FT_MAKE_TAG( 'w', 'O', 'F', 'F' ) + +/* used by "Keyboard.dfont" on legacy Mac OS X */ +#define TTAG_0xA5kbd FT_MAKE_TAG( 0xA5, 'k', 'b', 'd' ) + +/* used by "LastResort.dfont" on legacy Mac OS X */ +#define TTAG_0xA5lst FT_MAKE_TAG( 0xA5, 'l', 's', 't' ) + + +FT_END_HEADER + +#endif /* TTAGS_H_ */ + + +/* END */ diff --git a/freetype/include/freetype2/ft2build.h b/freetype/include/freetype2/ft2build.h new file mode 100644 index 0000000..e7ce99b --- /dev/null +++ b/freetype/include/freetype2/ft2build.h @@ -0,0 +1,42 @@ +/***************************************************************************/ +/* */ +/* ft2build.h */ +/* */ +/* FreeType 2 build and setup macros. */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This is the `entry point' for FreeType header file inclusions. It is */ + /* the only header file which should be included directly; all other */ + /* FreeType header files should be accessed with macro names (after */ + /* including `ft2build.h'). */ + /* */ + /* A typical example is */ + /* */ + /* #include <ft2build.h> */ + /* #include FT_FREETYPE_H */ + /* */ + /*************************************************************************/ + + +#ifndef FT2BUILD_H_ +#define FT2BUILD_H_ + +#include <freetype/config/ftheader.h> + +#endif /* FT2BUILD_H_ */ + + +/* END */ diff --git a/freetype/make.inc b/freetype/make.inc new file mode 100644 index 0000000..626a1de --- /dev/null +++ b/freetype/make.inc @@ -0,0 +1,53 @@ +## +## prebuild/third-party/freetype/make.inc +## +## History: +## 2012/05/30 - [Cao Rongrong] Created file +## +## Copyright (c) 2015 Ambarella, Inc. +## +## This file and its contents ("Software") are protected by intellectual +## property rights including, without limitation, U.S. and/or foreign +## copyrights. This Software is also the confidential and proprietary +## information of Ambarella, Inc. and its licensors. You may not use, reproduce, +## disclose, distribute, modify, or otherwise prepare derivative works of this +## Software or any portion thereof except pursuant to a signed license agreement +## or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. +## In the absence of such an agreement, you agree to promptly notify and return +## this Software to Ambarella, Inc. +## +## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, +## MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +## IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. +## + +ifeq ($(CONFIG_AMBARELLA_FREETYPE_SUPPORT), y) + +LOCAL_PATH := $(call my-dir) + +### +include $(CLEAR_VARS) + +LOCAL_TARGET := prebuild_freetype +LOCAL_SRCS := usr + +.PHONY: $(LOCAL_TARGET) + +include $(BUILD_PREBUILD) + +$(LOCAL_TARGET): $(LOCAL_MODULE) + $(call prebuild-links) + @echo "Copy $@ Done" + +$(call add-target-into-build, $(LOCAL_TARGET)) + +endif + diff --git a/gynet b/gynet new file mode 100644 index 0000000..74bd501 Binary files /dev/null and b/gynet differ diff --git a/hello_all.log b/hello_all.log new file mode 100644 index 0000000..d269654 --- /dev/null +++ b/hello_all.log @@ -0,0 +1,2668 @@ +- 0x0000007f84000b20 Free 493 was never alloc'd 0x7fa48415a4 +- 0x0000007f8c00ccc0 Free 989 was never alloc'd 0x7fa57a8528 +- 0x0000007f8c00d0c0 Free 993 was never alloc'd 0x7fa57a85b8 +- 0x0000007f8c00cfb0 Free 998 was never alloc'd 0x7fa57a8678 +- 0x0000007f84000e80 Free 1168 was never alloc'd 0x43fbec +- 0x0000007f840011a0 Free 1185 was never alloc'd 0x43fc1c +- 0x0000007f84000ea0 Free 1444 was never alloc'd 0x43fc1c +- 0x0000007f680008d0 Free 2280 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68002e20 Free 2638 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 2639 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68014020 Free 2665 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 2666 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68001530 Free 3039 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 3040 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68014020 Free 3050 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 3051 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68001530 Free 3410 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 3411 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68014020 Free 3420 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 3421 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68001530 Free 3780 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 3781 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68014020 Free 3790 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 3791 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68001530 Free 4150 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 4151 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68014020 Free 4160 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 4161 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68001530 Free 4658 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 4659 was never alloc'd 0x7fa4856ac4 +- 0x0000007f68014020 Free 4890 was never alloc'd 0x7fa4856aa8 +- 0x0000007f680008d0 Free 4891 was never alloc'd 0x7fa4856ac4 +- 0x000000000fe2baa0 Free 4892 was never alloc'd 0x42c480 +- 0x000000000fe34480 Free 4894 was never alloc'd 0x4b899c +- 0x0000007f5c001da0 Free 5170 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 5171 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 5402 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 5403 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 5682 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 5683 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 5692 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 5693 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 6202 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 6203 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 6212 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 6213 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 6714 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 6715 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 6724 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 6725 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 7226 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 7227 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 7236 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 7237 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 7738 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 7739 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 7748 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 7749 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 8250 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 8251 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 8260 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 8261 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 8762 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 8763 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 8994 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 8995 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001da0 Free 9274 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 9275 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001cc0 Free 9506 was never alloc'd 0x7fa4856aa8 +- 0x0000007f5c0008d0 Free 9507 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 9820 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 9821 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 9830 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 9831 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 10333 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 10334 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 10342 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 10343 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 10852 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 10853 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 10862 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 10863 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 11365 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 11367 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 11374 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 11375 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 11877 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 11878 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 11886 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 11887 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 12401 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 12402 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 12411 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 12412 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 12635 was never alloc'd 0x7fa484fa68 +- 0x0000007f84002e70 Free 12644 was never alloc'd 0x7fa484fa68 +- 0x0000007f54001da0 Free 12949 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 12950 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 12958 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 12959 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 13479 was never alloc'd 0x7fa484fa68 +- 0x0000007f54001da0 Free 13496 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 13497 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 13505 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 13506 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 14018 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 14019 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 14027 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 14028 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 14530 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 14531 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 14539 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 14540 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 15049 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 15050 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 15059 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 15060 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 15561 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 15562 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 15571 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 15572 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 16074 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 16075 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 16083 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 16084 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001da0 Free 16586 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 16587 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 16597 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 16598 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 17099 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 17100 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54001cc0 Free 17109 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 17110 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 17612 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 17613 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 17622 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 17623 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 18124 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 18125 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 18134 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 18135 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 18670 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 18671 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 18902 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 18903 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 19182 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 19183 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 19192 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 19193 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 19702 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 19703 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 19712 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 19713 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 20214 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 20215 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 20224 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 20225 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 20727 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 20728 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 20958 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 20959 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 21238 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 21239 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 21248 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 21249 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 21751 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 21752 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 21760 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 21761 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 22262 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 22263 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 22272 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 22273 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 22774 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 22775 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 22784 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 22785 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 23279 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 23291 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 23292 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 23527 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 23528 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 23839 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 23841 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 24075 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 24076 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 24395 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 24396 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 24631 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 24632 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 24926 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 24927 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 24935 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 24936 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 25437 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 25438 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 25447 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 25448 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 25949 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 25950 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 25959 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 25960 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 26461 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 26462 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 26693 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 26694 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 26973 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 26974 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 26983 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 26984 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 27485 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 27486 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 27495 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 27496 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 28032 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 28036 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 28041 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 28042 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 28552 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 28554 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 28561 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 28562 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 29064 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 29065 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54000b20 Free 29135 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54000b80 Free 29136 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004110 Free 29137 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001950 Free 29138 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001740 Free 29139 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54000c20 Free 29140 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 29142 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 30143 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 30144 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 30152 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 30153 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 30446 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 30447 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 30456 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 30457 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 30988 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 30989 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 31220 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 31221 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 31516 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 31517 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 31526 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 31527 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54000dc0 Free 31764 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54000d00 Free 31765 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54000c40 Free 31766 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54000b80 Free 31767 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540042c0 Free 31768 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004200 Free 31769 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004140 Free 31770 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007b10 Free 31771 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001e70 Free 31772 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007a30 Free 31773 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540079c0 Free 31774 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007aa0 Free 31775 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007560 Free 31776 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007410 Free 31777 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 31778 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 32054 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 32055 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 32064 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 32065 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 32567 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 32568 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 32576 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 32577 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 33086 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 33087 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 33318 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 33319 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 33600 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 33601 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 33835 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 33836 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 34367 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 34368 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 34377 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 34378 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 34685 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 34686 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 34695 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 34696 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 35448 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 35449 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 35461 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 35462 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 35743 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 35744 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 35753 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 35754 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 36289 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 36290 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 36521 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 36522 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 36801 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 36802 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 37033 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 37034 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 37322 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 37323 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 37331 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 37332 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 37833 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 37834 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 37843 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 37844 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 38345 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 38346 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 38355 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 38356 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 38857 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 38858 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 38867 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 38868 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 39369 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 39370 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 39379 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 39380 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 39882 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 39883 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 39891 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 39892 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 40393 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 40394 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 40625 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 40626 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 40906 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 40907 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 40915 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 40916 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 41417 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 41418 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 41427 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 41428 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 41937 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 41938 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 41947 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 41948 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 42449 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 42450 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 42518 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 42519 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 42961 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 42962 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 42971 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 42972 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 43696 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 43697 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 43705 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 43706 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 43985 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 43986 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 43995 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 43996 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 44497 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 44498 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 44507 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 44508 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 45020 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 45021 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 45029 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 45030 was never alloc'd 0x7fa4856ac4 +- 0x0000007f5c001030 Free 45563 was never alloc'd 0x4af4a4 +- 0x0000007f54004110 Free 45817 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 45818 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 45823 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 45824 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 46122 was never alloc'd 0x7fa484fa68 +- 0x0000007f60001da0 Free 46134 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 46135 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 46148 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 46149 was never alloc'd 0x7fa4856ac4 +- 0x0000007f8c133920 Free 46388 was never alloc'd 0x42c480 +- 0x0000007f60001da0 Free 46680 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 46681 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 46912 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 46913 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 47192 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 47193 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 47202 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 47203 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001da0 Free 47704 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 47705 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60001cc0 Free 47714 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 47715 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a030 Free 48292 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a060 Free 48293 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60000b40 Free 48294 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60000ba0 Free 48295 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60001f70 Free 48296 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60023310 Free 48297 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019e20 Free 48298 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60000c40 Free 48299 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 48300 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54000b20 Free 48775 was never alloc'd 0x7fa55273b8 +- 0x0000007f54004110 Free 48777 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 48778 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 49075 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 49076 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 49085 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 49086 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 49605 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 49606 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 49615 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 49616 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 50133 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 50134 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 50143 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 50144 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 50671 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 50672 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 50681 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 50682 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a2d0 Free 50921 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a210 Free 50922 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a150 Free 50923 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a090 Free 50924 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019fd0 Free 50925 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019f10 Free 50926 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019e50 Free 50927 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600035a0 Free 50928 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600034d0 Free 50929 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60003460 Free 50930 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600033f0 Free 50931 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60003530 Free 50932 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60002f90 Free 50933 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60002e40 Free 50934 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 50935 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 51437 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 51438 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 51443 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 51444 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 51949 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 51950 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 51955 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 51956 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 52235 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 52236 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 52245 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 52246 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 52747 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 52748 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 52757 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 52758 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 53260 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 53261 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 53269 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 53270 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 53772 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 53773 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 53781 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 53782 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 54317 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 54318 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 54327 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 54328 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 54829 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 54830 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 54839 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 54840 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 55578 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 55579 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 55587 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 55588 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 55904 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 55905 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 55913 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 55914 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 56670 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 56671 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 56679 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 56680 was never alloc'd 0x7fa4856ac4 ++ 0x0000007f84002d60 Alloc 56686 duplicate: 0x7fa4843928 /lib/libc.so.6:(popen+0x20)[0x7fa4843928] ++ 0x0000007f84002e70 Alloc 56687 duplicate: 0x7fa48413bc /lib/libc.so.6:(_IO_file_doallocate+0xb4)[0x7fa48413bc] +- 0x0000007f6001a790 Free 56983 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 56984 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 56993 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 56994 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 57495 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 57496 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 57505 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 57506 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 58008 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 58009 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 58017 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 58018 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 58519 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 58520 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 58529 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 58530 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 59032 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 59033 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 59041 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 59042 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 59551 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 59552 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 59561 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 59562 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 60063 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 60064 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 60073 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 60074 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 60575 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 60576 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 60585 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 60586 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 61087 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 61088 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 61097 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 61098 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 61599 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 61600 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 61609 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 61610 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 62337 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 62338 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 62343 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 62344 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 62623 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 62624 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 62633 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 62634 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 63169 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 63170 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 63401 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 63402 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 63907 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 63908 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 63913 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 63914 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 64201 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 64202 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 64433 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 64434 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 64714 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 64715 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 64723 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 64724 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 65448 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 65449 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 65457 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 65458 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 65738 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 65739 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 65747 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 65748 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 66249 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 66250 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 66481 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 66482 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 67024 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 67025 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 67030 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 67031 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 67032 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 67338 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 67339 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 67352 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 67353 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 67896 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 67897 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 67906 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 67907 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 68416 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 68417 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 68426 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 68427 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 68929 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 68930 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 68938 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 68939 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 69440 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 69441 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 69672 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 69673 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 69953 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 69955 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 69962 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 69963 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 70464 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 70465 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 70474 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 70475 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 70977 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 70979 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 70986 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 70987 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 71488 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 71489 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 71498 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 71499 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 72034 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 72035 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 72266 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 72267 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 72547 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 72548 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 72556 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 72557 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 73066 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 73067 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 73298 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 73299 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 73582 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 73583 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 73592 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 73593 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 74094 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 74095 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 74326 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 74327 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 74606 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 74607 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 74838 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 74839 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 75118 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 75119 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 75128 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 75129 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 75630 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 75631 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 75640 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 75641 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 76142 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 76143 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 76152 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 76153 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 76654 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 76655 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 76886 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 76887 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 77167 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 77168 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 77176 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 77177 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 77715 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 77716 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 77725 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 77726 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 77949 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 78258 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 78259 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 78300 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 78302 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 78492 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 78802 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 78803 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 78814 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 78815 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 79317 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 79319 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 79326 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 79327 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 79828 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 79829 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 79838 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 79839 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 80340 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 80341 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 80350 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 80351 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 80886 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 80887 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 80896 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 80897 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 81399 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 81400 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 81408 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 81409 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 81918 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 81919 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 81928 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 81929 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 82430 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 82431 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 82440 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 82441 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 82946 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 82947 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 82956 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 82957 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 83458 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 83459 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 83468 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 83469 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 83970 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 83971 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 83980 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 83981 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 84483 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 84484 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 84492 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 84493 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 84994 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 84995 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 85004 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 85005 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 85506 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 85507 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 85516 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 85517 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 86018 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 86019 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 86028 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 86029 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 86538 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 86539 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 86548 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 86549 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 87050 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 87051 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 87060 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 87061 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 87566 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 87567 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 87576 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 87577 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 88078 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 88079 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 88310 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 88311 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 88619 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 88620 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 88625 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 88626 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 88849 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 89167 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 89168 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 89399 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 89400 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 89714 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 89715 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 89946 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 89947 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 89982 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 90266 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 90267 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 90276 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 90277 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 90790 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 90791 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 90800 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 90801 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 91306 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 91307 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 91316 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 91317 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 91818 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 91819 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 91828 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 91829 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 92330 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 92331 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 92340 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 92341 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 92842 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 92843 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 92852 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 92853 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 93355 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 93356 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 93364 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 93365 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 93866 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 93867 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 93876 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 93877 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 94378 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 94379 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 94610 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 94611 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 94890 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 94891 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 95122 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 95123 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 95411 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 95412 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 95420 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 95421 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 95923 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 95925 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 95932 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 95933 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 96664 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004110 Free 96665 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 96666 was never alloc'd 0x7fa4856ac4 +- 0x0000007f600008d0 Free 96667 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 96946 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 96947 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 96956 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 96957 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 97458 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 97459 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 97468 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 97469 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 97971 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 97973 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 98202 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 98203 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 98483 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 98484 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 98492 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 98493 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 98995 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 98996 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 99004 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 99005 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 99562 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 99563 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 99794 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 99795 was never alloc'd 0x7fa4856ac4 ++ 0x0000007f84002e70 Alloc 100056 duplicate: 0x7fa48413bc /lib/libc.so.6:(_IO_file_doallocate+0xb4)[0x7fa48413bc] +- 0x0000007f54004110 Free 100121 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 100122 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 100135 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 100136 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 100669 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 100670 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 100681 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 100682 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 101406 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 101407 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 101415 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 101416 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 101695 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 101696 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 101705 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 101706 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 102207 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 102208 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 102439 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 102440 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 102719 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 102720 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 102729 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 102730 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 103232 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 103234 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 103241 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 103242 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 103744 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 103746 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 103753 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 103754 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 104493 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 104494 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 104495 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 104496 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 104775 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 104776 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 104785 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 104786 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 105288 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 105289 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 105297 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 105298 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 105799 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 105800 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 105809 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 105810 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 106312 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 106313 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 106321 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 106322 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 106823 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 106824 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 107055 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 107056 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 107336 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 107337 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 107345 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 107346 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 107848 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 107849 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 107857 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 107858 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 108393 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 108394 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 108403 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 108404 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 108906 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 108907 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 108915 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 108916 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 109425 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 109426 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 109657 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 109658 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 109937 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 109938 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 109947 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 109948 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 110686 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 110687 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 110695 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 110696 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 111003 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 111004 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 111013 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 111014 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 111543 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 111544 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 111553 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 111554 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 112081 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 112082 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 112091 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 112092 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 112594 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 112596 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 112603 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 112604 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 113105 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 113106 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 113115 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 113116 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 113625 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 113626 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 113635 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 113636 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 114137 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 114138 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 114147 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 114148 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 114649 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 114650 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 114659 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 114660 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 115162 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 115163 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 115171 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 115172 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 115674 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 115676 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 115683 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 115684 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 116408 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 116409 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 116417 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 116418 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 116697 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 116698 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 116929 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 116930 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 117432 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 117433 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 117475 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 117476 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 117756 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 117757 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 117765 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 117766 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 118275 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 118276 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 118285 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 118286 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 118787 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 118788 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 118797 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 118798 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 119300 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 119301 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 119309 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 119310 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 119811 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 119812 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 120043 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 120044 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 120323 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 120324 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 120333 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 120334 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 120835 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 120836 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 121067 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 121068 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 121348 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 121349 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 121357 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 121358 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 121878 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 121879 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 122109 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 122110 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 122421 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 122422 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 122653 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 122654 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 122968 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 122969 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 122978 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 122979 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 123202 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 123498 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 123499 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 123662 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 123663 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 124011 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 124012 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 124020 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 124021 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 124522 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 124523 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 124754 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 124755 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 125034 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 125035 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 125044 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 125045 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 125546 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 125547 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 125556 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 125557 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 126058 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 126059 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 126068 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 126069 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 126604 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 126605 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 126614 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 126615 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 127116 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 127117 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 127126 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 127127 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 127636 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 127637 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 127868 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 127869 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 128148 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 128149 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 128380 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 128381 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 128660 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 128661 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 128670 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 128671 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 129172 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 129173 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 129404 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 129405 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 129684 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 129685 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 129694 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 129695 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 130426 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 130427 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 130428 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 130429 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 130938 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 130939 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 130940 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 130941 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 131220 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 131221 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 131230 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 131231 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 131955 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 131956 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 131964 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 131965 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 132252 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 132253 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 132484 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 132485 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 132765 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 132766 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 132776 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 132778 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 133306 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 133307 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 133538 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 133539 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 133851 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540008d0 Free 133852 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 133861 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 133862 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 134395 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 134396 was never alloc'd 0x7fa4856ac4 +- 0x0000007f540078d0 Free 134466 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007930 Free 134467 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004110 Free 134468 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007ef0 Free 134469 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007ce0 Free 134472 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540079d0 Free 134475 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 134476 was never alloc'd 0x7fa4856ac4 +- 0x0000007f600034d0 Free 134619 was never alloc'd 0x7fa55273b8 +- 0x0000007f60003460 Free 134636 was never alloc'd 0x7fa55273b8 +- 0x0000007f84002e70 Free 134820 was never alloc'd 0x7fa484fa68 +- 0x0000007f6001a8a0 Free 134923 was never alloc'd 0x7fa55273b8 +- 0x0000007f600035f0 Free 134938 was never alloc'd 0x7fa55273b8 +- 0x0000007f54004110 Free 135229 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 135230 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 135239 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 135240 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 135789 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 135790 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 136021 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 136022 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 136325 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 136326 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 136335 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 136336 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 137086 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 137087 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 137095 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 137096 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a2d0 Free 137105 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a210 Free 137106 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a150 Free 137107 was never alloc'd 0x7fa4856aa8 +- 0x0000007f6001a090 Free 137108 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019fd0 Free 137109 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019f10 Free 137110 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60019e50 Free 137111 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600034d0 Free 137113 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60003460 Free 137114 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600033f0 Free 137115 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60003530 Free 137116 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60002f90 Free 137117 was never alloc'd 0x7fa4856aa8 +- 0x0000007f60002e40 Free 137118 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 137119 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 137395 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 137396 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 137405 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 137406 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 137907 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 137908 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 138139 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 138140 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 138419 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 138420 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 138429 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 138430 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 138932 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 138933 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 138941 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 138942 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 139443 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 139444 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 139675 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 139676 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 139955 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 139956 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 139965 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 139966 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 140475 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 140476 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 140485 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 140486 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 140987 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 140988 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 140997 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 140998 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 141499 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 141500 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 141509 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 141510 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 142011 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 142012 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 142021 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 142022 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 142523 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 142524 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 142755 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 142756 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 143036 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 143037 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 143045 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 143046 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 143783 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 143784 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 143789 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 143790 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 144134 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 144135 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 144144 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 144145 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 144368 was never alloc'd 0x7fa484fa68 +- 0x0000007f54004110 Free 144674 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 144675 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 144684 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 144685 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 145220 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 145221 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 145230 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 145231 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 145733 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 145735 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 145742 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 145743 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 146245 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 146246 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 146254 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 146255 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 146756 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 146757 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 146988 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 146989 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 147268 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 147269 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 147500 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 147501 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 147780 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 147781 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 147790 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 147791 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 148292 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 148293 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 148302 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 148303 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 148804 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 148805 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 148814 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 148815 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 149324 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 149325 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 149339 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 149340 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 149836 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 149837 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 149846 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 149847 was never alloc'd 0x7fa4856ac4 +- 0x0000007f6001a790 Free 150348 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 150349 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 150581 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 150582 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 150861 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 150862 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 150871 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 150872 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 151374 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 151376 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 151383 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 151384 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 151885 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 151886 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 151895 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 151896 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 152397 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 152398 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 152407 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 152408 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 152909 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 152910 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 152919 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 152920 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54007ef0 Free 153525 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54008130 Free 153526 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540078d0 Free 153527 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007930 Free 153528 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004110 Free 153529 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007f20 Free 153530 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007ce0 Free 153531 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540079d0 Free 153532 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 153533 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 153801 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 153802 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 154329 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 154330 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 154339 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 154340 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 155130 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 155131 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 155139 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 155140 was never alloc'd 0x7fa4856ac4 +- 0x0000007f8c13e630 Free 155459 was never alloc'd 0x416458 +- 0x0000007f60000b40 Free 155461 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 155462 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 155692 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 155693 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54007990 Free 155746 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540078d0 Free 155747 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004260 Free 155748 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540041a0 Free 155749 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004170 Free 155750 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004140 Free 155751 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54004110 Free 155752 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54008230 Free 155753 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001b10 Free 155754 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001a40 Free 155755 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540019d0 Free 155756 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001960 Free 155757 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001aa0 Free 155758 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54001b60 Free 155759 was never alloc'd 0x7fa4856aa8 +- 0x0000007f540013b0 Free 155760 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 155761 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 156043 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 156044 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 156275 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 156276 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 156555 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 156556 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 156787 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 156788 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 157068 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 157072 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 157077 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 157078 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 157588 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 157589 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 157597 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 157598 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 158099 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 158100 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 158109 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 158110 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 158611 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 158612 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 158621 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 158622 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 159123 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 159124 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 159133 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 159134 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 159636 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 159637 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 159645 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 159646 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 160148 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 160149 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 160157 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 160158 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 160663 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 160664 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 160895 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 160896 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 161175 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 161176 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 161407 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 161408 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 161722 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 161724 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 161731 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 161732 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 162233 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 162234 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 162243 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 162244 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 162753 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 162754 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 162985 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 162986 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 163265 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 163266 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 163275 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 163276 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 163777 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 163778 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 163787 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 163788 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 164289 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 164290 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 164521 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 164522 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 164801 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 164802 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 165033 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 165034 was never alloc'd 0x7fa4856ac4 +- 0x0000007f54004110 Free 165314 was never alloc'd 0x7fa4856aa8 +- 0x0000007f54007680 Free 165316 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 165323 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 165324 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 166066 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 166067 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 166075 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 166076 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 166614 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 166615 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 166623 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 166624 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 166938 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 166939 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 166948 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 166949 was never alloc'd 0x7fa4856ac4 +- 0x0000007f84002e70 Free 167172 was never alloc'd 0x7fa484fa68 +- 0x0000007f60000b40 Free 167465 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 167466 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 167474 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 167475 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 167976 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 167977 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 167986 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 167987 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 168488 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 168489 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 168720 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 168721 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 169000 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 169001 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 169232 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 169233 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 169512 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 169513 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 169522 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 169523 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 170025 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 170026 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 170034 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 170035 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 170570 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 170571 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 170580 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 170581 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 171082 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 171083 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 171092 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 171093 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 171603 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 171604 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 171612 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 171613 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 172114 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 172115 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 172124 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 172125 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 172626 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 172627 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 172636 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 172637 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 173138 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 173139 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 173148 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 173149 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 173651 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 173652 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 173660 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 173661 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 174162 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 174163 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 174172 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 174173 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 174674 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 174675 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 174906 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 174907 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 175186 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 175187 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 175418 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 175419 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 175698 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 175699 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 175930 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 175931 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 176218 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 176219 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 176450 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 176451 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 176955 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 176956 was never alloc'd 0x7fa4856ac4 +- 0x0000007f60000b40 Free 176964 was never alloc'd 0x7fa4856aa8 +- 0x0000007f600008d0 Free 176965 was never alloc'd 0x7fa4856ac4 +- 0x000000000fe21830 Free 176977 was never alloc'd 0x4af3ec +- 0x000000000fe20b60 Free 176978 was never alloc'd 0x4af404 +- 0x000000000fed7b30 Free 176979 was never alloc'd 0x4451d0 +- 0x0000007f680008d0 Free 177072 was never alloc'd 0x7fa4856ac4 +- 0x0000007f640008d0 Free 177167 was never alloc'd 0x7fa4856ac4 +- 0x000000000fed75d0 Free 177173 was never alloc'd 0x7fa5aa4444 +- 0x000000000fef5130 Free 177491 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5110 Free 177492 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef3ff0 Free 177493 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef3fd0 Free 177494 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef4870 Free 177495 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef4850 Free 177496 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef26a0 Free 177497 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef2680 Free 177498 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5430 Free 177499 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5410 Free 177500 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef3f70 Free 177501 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef3f50 Free 177502 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef4e70 Free 177503 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef4e50 Free 177504 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef4bf0 Free 177505 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef4bd0 Free 177506 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef1580 Free 177507 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef1520 Free 177508 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5730 Free 177509 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5710 Free 177510 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5670 Free 177511 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef5650 Free 177512 was never alloc'd 0x7fa4b9aac4 +- 0x000000000fef3b30 Free 177513 was never alloc'd 0x7fa4b9aac4 + +Memory not freed: +----------------- + Address Size Caller +0x000000001001db00 0x120 at 0x7fa5aa3b10 +0x000000001001dc30 0x120 at 0x7fa5aa3b10 +0x000000001001dd60 0x120 at 0x7fa5aa3b10 +0x000000001001de90 0x120 at 0x7fa5aa3b10 +0x000000001001e0f0 0x120 at 0x7fa5aa3b10 +0x000000001001e220 0x120 at 0x7fa5aa3b10 +0x000000001001e350 0x120 at 0x7fa5aa3b10 +0x000000001001e480 0x120 at 0x7fa5aa3b10 +0x0000007f68000b20 0x38 at 0x7fa5aa0074 +0x0000007f68014020 0x10004 at 0x7fa58be21c +0x0000007f84002d60 0x100 at 0x7fa4843928 +0x0000007f84002e70 0x1000 at 0x7fa48413bc +0x0000007f8c000b20 0x21c at 0x7fa573c5e4 +0x0000007f8c000d50 0x21c at 0x7fa573c5e4 +0x0000007f8c000f80 0x438 at 0x7fa573c5d4 +0x0000007f8c0013c0 0x21c at 0x7fa573c5e4 +0x0000007f8c0015f0 0x21c at 0x7fa573c5d4 +0x0000007f8c001820 0x21c at 0x7fa573c5e4 +0x0000007f8c001a50 0x21c at 0x7fa573c5d4 +0x0000007f8c001c80 0x21c at 0x7fa573c5e4 +0x0000007f8c001eb0 0x21c at 0x7fa573c5d4 +0x0000007f8c0020e0 0x21c at 0x7fa573c5e4 +0x0000007f8c002310 0x21c at 0x7fa573c5d4 +0x0000007f8c002540 0x21c at 0x7fa573c5e4 +0x0000007f8c002770 0x21c at 0x7fa573c5d4 +0x0000007f8c0029a0 0x21c at 0x7fa573c5e4 +0x0000007f8c002bd0 0x21c at 0x7fa573c5d4 +0x0000007f8c002e00 0x21c at 0x7fa573c5e4 +0x0000007f8c003030 0x21c at 0x7fa573c5d4 +0x0000007f8c003260 0x21c at 0x7fa573c5e4 +0x0000007f8c003490 0x21c at 0x7fa573c5d4 +0x0000007f8c0036c0 0x21c at 0x7fa573c5e4 +0x0000007f8c0038f0 0x21c at 0x7fa573c5d4 +0x0000007f8c003b20 0x21c at 0x7fa573c5e4 +0x0000007f8c003d50 0x21c at 0x7fa573c5d4 +0x0000007f8c003f80 0x21c at 0x7fa573c5e4 +0x0000007f8c0041b0 0x438 at 0x7fa573c5d4 +0x0000007f8c0045f0 0x654 at 0x7fa573c5e4 +0x0000007f8c004c50 0x21c at 0x7fa573c5d4 +0x0000007f8c004e80 0x21c at 0x7fa573c5e4 +0x0000007f8c0050b0 0x21c at 0x7fa573c5d4 +0x0000007f8c0052e0 0x21c at 0x7fa573c5e4 +0x0000007f8c005510 0x438 at 0x7fa573c5d4 +0x0000007f8c005950 0x654 at 0x7fa573c5e4 +0x0000007f8c005fb0 0x21c at 0x7fa573c5d4 +0x0000007f8c0061e0 0 at 0x7fa573c848 +0x0000007f8c006200 0 at 0x7fa573c848 +0x0000007f8c006220 0 at 0x7fa573c848 +0x0000007f8c006240 0x108 at 0x7fa573c848 +0x0000007f8c006350 0x12 at 0x7fa485a298 +0x0000007f8c006370 0x10 at 0x7fa57c4edc +0x0000007f8c006390 0 at 0x7fa573c848 +0x0000007f8c0063b0 0 at 0x7fa573c848 +0x0000007f8c0063d0 0 at 0x7fa573c848 +0x0000007f8c0063f0 0 at 0x7fa573c848 +0x0000007f8c006720 0x21c at 0x7fa573c5d4 +0x0000007f8c006950 0x21c at 0x7fa573c5e4 +0x0000007f8c006b80 0x21c at 0x7fa573c5d4 +0x0000007f8c006db0 0x21c at 0x7fa573c5e4 +0x0000007f8c006fe0 0x21c at 0x7fa573c5d4 +0x0000007f8c007210 0x21c at 0x7fa573c5e4 +0x0000007f8c007440 0x21c at 0x7fa573c5d4 +0x0000007f8c007670 0x21c at 0x7fa573c5e4 +0x0000007f8c0078a0 0x21c at 0x7fa573c5d4 +0x0000007f8c007ad0 0x21c at 0x7fa573c5e4 +0x0000007f8c007d00 0x108 at 0x7fa573c848 +0x0000007f8c007e10 0 at 0x7fa573c5d4 +0x0000007f8c007e30 0x21c at 0x7fa573c5d4 +0x0000007f8c008060 0x21c at 0x7fa573c5e4 +0x0000007f8c008290 0x21c at 0x7fa573c5d4 +0x0000007f8c0084c0 0x21c at 0x7fa573c5e4 +0x0000007f8c0086f0 0x21c at 0x7fa573c5d4 +0x0000007f8c008920 0x21c at 0x7fa573c5e4 +0x0000007f8c008b50 0x438 at 0x7fa573c5d4 +0x0000007f8c008f90 0x654 at 0x7fa573c5e4 +0x0000007f8c0095f0 0x21c at 0x7fa573c5d4 +0x0000007f8c009820 0x21c at 0x7fa573c5e4 +0x0000007f8c009a50 0x21c at 0x7fa573c5d4 +0x0000007f8c009c80 0x21c at 0x7fa573c5e4 +0x0000007f8c009eb0 0x21c at 0x7fa573c5d4 +0x0000007f8c00a0e0 0x21c at 0x7fa573c5e4 +0x0000007f8c00a310 0x21c at 0x7fa573c5d4 +0x0000007f8c00a540 0x21c at 0x7fa573c5e4 +0x0000007f8c00a770 0x21c at 0x7fa573c5d4 +0x0000007f8c00a9a0 0x21c at 0x7fa573c5e4 +0x0000007f8c00abd0 0x438 at 0x7fa573c5d4 +0x0000007f8c00b010 0x21c at 0x7fa573c5e4 +0x0000007f8c00b240 0x21c at 0x7fa573c5d4 +0x0000007f8c00b470 0x21c at 0x7fa573c5e4 +0x0000007f8c00b6a0 0x21c at 0x7fa573c5d4 +0x0000007f8c00b8d0 0x21c at 0x7fa573c5e4 +0x0000007f8c00bb00 0x21c at 0x7fa573c5d4 +0x0000007f8c00bd30 0x108 at 0x7fa573c848 +0x0000007f8c00be40 0x108 at 0x7fa573c848 +0x0000007f8c00bfc0 0x2a8 at 0x7fa573c830 +0x0000007f8c00c8b0 0 at 0x7fa573c848 +0x0000007f8c00c8d0 0 at 0x7fa573c848 +0x0000007f8c00cb80 0x30 at 0x4b7968 +0x0000007f8c00cbc0 0x84 at 0x7fa573c848 +0x0000007f8c00cc50 0 at 0x7fa573c848 +0x0000007f8c00cc70 0 at 0x7fa573c848 +0x0000007f8c00cca0 0 at 0x7fa573c848 +0x0000007f8c00ccc0 0 at 0x7fa573c848 +0x0000007f8c00cce0 0 at 0x7fa573c848 +0x0000007f8c00cd00 0x30 at 0x4b7968 +0x0000007f8c00cd40 0x210 at 0x7fa573c848 +0x0000007f8c00cf60 0x40 at 0x441508 +0x0000007f8c00cfb0 0 at 0x7fa573c5d4 +0x0000007f8c00cfd0 0x40 at 0x441508 +0x0000007f8c00d020 0 at 0x7fa573c848 +0x0000007f8c00d040 0x30 at 0x4b7968 +0x0000007f8c00d080 0x30 at 0x4b7968 +0x0000007f8c00d0f0 0 at 0x7fa573c848 +0x0000007f8c00d140 0 at 0x7fa573c848 +0x0000007f8c00d160 0x40 at 0x441508 +0x0000007f8c00d1e0 0 at 0x7fa573c848 +0x0000007f8c00d200 0x84 at 0x7fa573c848 +0x0000007f8c00d380 0x11544 at 0x40adf4 +0x0000007f8c01e8d0 0x11544 at 0x40adf4 +0x0000007f8c054740 0x11544 at 0x40adf4 +0x0000007f8c065c90 0x11544 at 0x40adf4 +0x0000007f8c0771e0 0x6540 at 0x7fa573cca4 +0x0000007f8c07d730 0x21c at 0x7fa573c5e4 +0x0000007f8c07d960 0x21c at 0x7fa573c5d4 +0x0000007f8c07db90 0x21c at 0x7fa573c5e4 +0x0000007f8c07ddc0 0x21c at 0x7fa573c5d4 +0x0000007f8c07dff0 0x654 at 0x7fa573c5e4 +0x0000007f8c07e650 0x21c at 0x7fa573c5d4 +0x0000007f8c07e880 0x21c at 0x7fa573c5e4 +0x0000007f8c07eab0 0x21c at 0x7fa573c5d4 +0x0000007f8c07ece0 0x21c at 0x7fa573c5e4 +0x0000007f8c07ef10 0x21c at 0x7fa573c5d4 +0x0000007f8c07f140 0x21c at 0x7fa573c5e4 +0x0000007f8c07f370 0x21c at 0x7fa573c5d4 +0x0000007f8c07f5a0 0x21c at 0x7fa573c5e4 +0x0000007f8c07f7d0 0x21c at 0x7fa573c5d4 +0x0000007f8c07fa00 0x21c at 0x7fa573c5e4 +0x0000007f8c07fc30 0x21c at 0x7fa573c5d4 +0x0000007f8c07fe60 0x21c at 0x7fa573c5e4 +0x0000007f8c080090 0x21c at 0x7fa573c5d4 +0x0000007f8c0802c0 0x21c at 0x7fa573c5e4 +0x0000007f8c0804f0 0x21c at 0x7fa573c5d4 +0x0000007f8c080720 0x21c at 0x7fa573c5e4 +0x0000007f8c080950 0x21c at 0x7fa573c5d4 +0x0000007f8c080b80 0x21c at 0x7fa573c5e4 +0x0000007f8c080db0 0x438 at 0x7fa573c5d4 +0x0000007f8c0811f0 0x654 at 0x7fa573c5e4 +0x0000007f8c081850 0x21c at 0x7fa573c5d4 +0x0000007f8c081a80 0x21c at 0x7fa573c5e4 +0x0000007f8c081cb0 0x21c at 0x7fa573c5d4 +0x0000007f8c081ee0 0x21c at 0x7fa573c5e4 +0x0000007f8c082110 0x21c at 0x7fa573c5d4 +0x0000007f8c082340 0x21c at 0x7fa573c5e4 +0x0000007f8c082570 0x438 at 0x7fa573c5d4 +0x0000007f8c0829b0 0x654 at 0x7fa573c5e4 +0x0000007f8c083010 0x21c at 0x7fa573c5d4 +0x0000007f8c083240 0x21c at 0x7fa573c5e4 +0x0000007f8c083470 0x21c at 0x7fa573c5d4 +0x0000007f8c0836a0 0x21c at 0x7fa573c5e4 +0x0000007f8c0838d0 0x21c at 0x7fa573c5d4 +0x0000007f8c083b00 0x438 at 0x7fa573c5e4 +0x0000007f8c083f40 0x21c at 0x7fa573c5d4 +0x0000007f8c084170 0x21c at 0x7fa573c5e4 +0x0000007f8c0843a0 0x21c at 0x7fa573c5d4 +0x0000007f8c0845d0 0x21c at 0x7fa573c5e4 +0x0000007f8c084800 0x21c at 0x7fa573c5d4 +0x0000007f8c084a30 0x21c at 0x7fa573c5e4 +0x0000007f8c084c60 0x21c at 0x7fa573c5d4 +0x0000007f8c084e90 0x21c at 0x7fa573c5e4 +0x0000007f8c0850c0 0x21c at 0x7fa573c5d4 +0x0000007f8c0852f0 0x21c at 0x7fa573c5e4 +0x0000007f8c085520 0x21c at 0x7fa573c5d4 +0x0000007f8c085750 0x21c at 0x7fa573c5e4 +0x0000007f8c085980 0x21c at 0x7fa573c5d4 +0x0000007f8c085bb0 0x21c at 0x7fa573c5e4 +0x0000007f8c085de0 0x21c at 0x7fa573c5d4 +0x0000007f8c086010 0x21c at 0x7fa573c5e4 +0x0000007f8c086240 0x21c at 0x7fa573c5d4 +0x0000007f8c086470 0x21c at 0x7fa573c5e4 +0x0000007f8c0866a0 0x21c at 0x7fa573c5d4 +0x0000007f8c0868d0 0x21c at 0x7fa573c5e4 +0x0000007f8c086b00 0x21c at 0x7fa573c5d4 +0x0000007f8c086d30 0x21c at 0x7fa573c5e4 +0x0000007f8c086f60 0x21c at 0x7fa573c5d4 +0x0000007f8c087190 0x21c at 0x7fa573c5e4 +0x0000007f8c0873c0 0x21c at 0x7fa573c5d4 +0x0000007f8c0875f0 0x654 at 0x7fa573c5e4 +0x0000007f8c087c50 0x21c at 0x7fa573c5d4 +0x0000007f8c087e80 0x21c at 0x7fa573c5e4 +0x0000007f8c0880b0 0x21c at 0x7fa573c5d4 +0x0000007f8c0882e0 0x21c at 0x7fa573c5e4 +0x0000007f8c088510 0x438 at 0x7fa573c5d4 +0x0000007f8c088950 0x654 at 0x7fa573c5e4 +0x0000007f8c088fb0 0x21c at 0x7fa573c5d4 +0x0000007f8c0891e0 0x21c at 0x7fa573c5e4 +0x0000007f8c089410 0x21c at 0x7fa573c5d4 +0x0000007f8c089640 0x21c at 0x7fa573c5e4 +0x0000007f8c089870 0x21c at 0x7fa573c5d4 +0x0000007f8c089aa0 0x21c at 0x7fa573c5e4 +0x0000007f8c089cd0 0x21c at 0x7fa573c5d4 +0x0000007f8c089f00 0x21c at 0x7fa573c5e4 +0x0000007f8c08a130 0x21c at 0x7fa573c5d4 +0x0000007f8c08a360 0x21c at 0x7fa573c5e4 +0x0000007f8c08a590 0x21c at 0x7fa573c5d4 +0x0000007f8c08a7c0 0x21c at 0x7fa573c5e4 +0x0000007f8c08a9f0 0x21c at 0x7fa573c5d4 +0x0000007f8c08ac20 0x21c at 0x7fa573c5e4 +0x0000007f8c08ae50 0x438 at 0x7fa573c5d4 +0x0000007f8c08b290 0x10e0 at 0x7fa573c5e4 +0x0000007f8c08c380 0x21c at 0x7fa573c5d4 +0x0000007f8c08c5b0 0x21c at 0x7fa573c5e4 +0x0000007f8c08c7e0 0x21c at 0x7fa573c5d4 +0x0000007f8c08ca10 0x21c at 0x7fa573c5e4 +0x0000007f8c08cc40 0x21c at 0x7fa573c5d4 +0x0000007f8c08ce70 0x21c at 0x7fa573c5e4 +0x0000007f8c08d0a0 0x21c at 0x7fa573c5d4 +0x0000007f8c08d2d0 0x21c at 0x7fa573c5e4 +0x0000007f8c08d500 0x438 at 0x7fa573c5d4 +0x0000007f8c08d940 0x654 at 0x7fa573c5e4 +0x0000007f8c08dfa0 0x21c at 0x7fa573c5d4 +0x0000007f8c08e1d0 0x21c at 0x7fa573c5e4 +0x0000007f8c08e400 0x438 at 0x7fa573c5d4 +0x0000007f8c08e840 0x654 at 0x7fa573c5e4 +0x0000007f8c08eea0 0x21c at 0x7fa573c5d4 +0x0000007f8c08f0d0 0x21c at 0x7fa573c5e4 +0x0000007f8c08f300 0x21c at 0x7fa573c5d4 +0x0000007f8c08f530 0x21c at 0x7fa573c5e4 +0x0000007f8c08f760 0x21c at 0x7fa573c5d4 +0x0000007f8c08f990 0x21c at 0x7fa573c5e4 +0x0000007f8c08fbc0 0x21c at 0x7fa573c5d4 +0x0000007f8c08fdf0 0x21c at 0x7fa573c5e4 +0x0000007f8c090020 0x21c at 0x7fa573c5d4 +0x0000007f8c090250 0x21c at 0x7fa573c5e4 +0x0000007f8c090480 0x21c at 0x7fa573c5d4 +0x0000007f8c0906b0 0x21c at 0x7fa573c5e4 +0x0000007f8c0908e0 0x21c at 0x7fa573c5d4 +0x0000007f8c090b10 0x21c at 0x7fa573c5e4 +0x0000007f8c090d40 0x21c at 0x7fa573c5d4 +0x0000007f8c090f70 0x21c at 0x7fa573c5e4 +0x0000007f8c0911a0 0x21c at 0x7fa573c5d4 +0x0000007f8c0913d0 0x21c at 0x7fa573c5e4 +0x0000007f8c091600 0x21c at 0x7fa573c5d4 +0x0000007f8c091830 0x21c at 0x7fa573c5e4 +0x0000007f8c091a60 0x21c at 0x7fa573c5d4 +0x0000007f8c091c90 0x21c at 0x7fa573c5e4 +0x0000007f8c091ec0 0x21c at 0x7fa573c5d4 +0x0000007f8c0920f0 0x21c at 0x7fa573c5e4 +0x0000007f8c092320 0x21c at 0x7fa573c5d4 +0x0000007f8c092550 0x21c at 0x7fa573c5e4 +0x0000007f8c092780 0x21c at 0x7fa573c5d4 +0x0000007f8c0929b0 0x21c at 0x7fa573c5e4 +0x0000007f8c092be0 0x21c at 0x7fa573c5d4 +0x0000007f8c092e10 0x21c at 0x7fa573c5e4 +0x0000007f8c093040 0x21c at 0x7fa573c5d4 +0x0000007f8c093270 0x21c at 0x7fa573c5e4 +0x0000007f8c0934a0 0x21c at 0x7fa573c5d4 +0x0000007f8c0936d0 0x21c at 0x7fa573c5e4 +0x0000007f8c093900 0x21c at 0x7fa573c5d4 +0x0000007f8c093b30 0x21c at 0x7fa573c5e4 +0x0000007f8c093d60 0x438 at 0x7fa573c5d4 +0x0000007f8c0941a0 0x654 at 0x7fa573c5e4 +0x0000007f8c094800 0x438 at 0x7fa573c5d4 +0x0000007f8c094c40 0x21c at 0x7fa573c5e4 +0x0000007f8c094e70 0x21c at 0x7fa573c5d4 +0x0000007f8c0950a0 0x21c at 0x7fa573c5e4 +0x0000007f8c0952d0 0x438 at 0x7fa573c5d4 +0x0000007f8c095710 0x654 at 0x7fa573c5e4 +0x0000007f8c095d70 0x21c at 0x7fa573c5d4 +0x0000007f8c095fa0 0x21c at 0x7fa573c5e4 +0x0000007f8c0961d0 0x21c at 0x7fa573c5e4 +0x0000007f8c096400 0x21c at 0x7fa573c5d4 +0x0000007f8c096630 0x21c at 0x7fa573c5e4 +0x0000007f8c096860 0x21c at 0x7fa573c5d4 +0x0000007f8c096a90 0x21c at 0x7fa573c5e4 +0x0000007f8c096cc0 0x438 at 0x7fa573c5d4 +0x0000007f8c097100 0x654 at 0x7fa573c5e4 +0x0000007f8c097760 0x21c at 0x7fa573c5d4 +0x0000007f8c097990 0x21c at 0x7fa573c5e4 +0x0000007f8c097bc0 0x21c at 0x7fa573c5d4 +0x0000007f8c097df0 0x21c at 0x7fa573c5e4 +0x0000007f8c098020 0x21c at 0x7fa573c5d4 +0x0000007f8c098250 0x21c at 0x7fa573c5e4 +0x0000007f8c098480 0x21c at 0x7fa573c5d4 +0x0000007f8c0986b0 0x21c at 0x7fa573c5e4 +0x0000007f8c0988e0 0x654 at 0x7fa573c5d4 +0x0000007f8c098f40 0x21c at 0x7fa573c5e4 +0x0000007f8c099170 0x12fc at 0x7fa573c5d4 +0x0000007f8c09a480 0x21c at 0x7fa573c5e4 +0x0000007f8c09a6b0 0x21c at 0x7fa573c5d4 +0x0000007f8c09a8e0 0x21c at 0x7fa573c5e4 +0x0000007f8c09ab10 0x21c at 0x7fa573c5d4 +0x0000007f8c09ad40 0x21c at 0x7fa573c5e4 +0x0000007f8c09af70 0xaa0 at 0x7fa573c830 +0x0000007f8c09ba20 0x420 at 0x7fa573c848 +0x0000007f8c09be50 0x440 at 0x7fa573c830 +0x0000007f8c09c2a0 0x4c8 at 0x7fa573c830 +0x0000007f8c09c770 0x4c8 at 0x7fa573c830 +0x0000007f8c09cc40 0x990 at 0x7fa573c830 +0x0000007f8c09d5e0 0x318 at 0x7fa573c848 +0x0000007f8c09d900 0x770 at 0x7fa573c830 +0x0000007f8c09e080 0x210 at 0x7fa573c848 +0x0000007f8c09e2a0 0xaa0 at 0x7fa573c830 +0x0000007f8c09ed50 0x420 at 0x7fa573c848 +0x0000007f8c09f180 0x550 at 0x7fa573c830 +0x0000007f8c09f6e0 0x7f8 at 0x7fa573c830 +0x0000007f8c09fee0 0x440 at 0x7fa573c830 +0x0000007f8c0a0330 0x550 at 0x7fa573c830 +0x0000007f8c0a0890 0x330 at 0x7fa573c830 +0x0000007f8c0a0bd0 0xaa0 at 0x7fa573c830 +0x0000007f8c0a1680 0x39c at 0x7fa573c848 +0x0000007f8c0a1a30 0x880 at 0x7fa573c830 +0x0000007f8c0a22c0 0x294 at 0x7fa573c848 +0x0000007f8c0a2560 0x110 at 0x7fa573c830 +0x0000007f8c0a2680 0x550 at 0x7fa573c830 +0x0000007f8c0a2be0 0x18c at 0x7fa573c848 +0x0000007f8c0a2d80 0xbb0 at 0x7fa573c830 +0x0000007f8c0a3940 0x420 at 0x7fa573c848 +0x0000007f8c0a3d70 0x990 at 0x7fa573c830 +0x0000007f8c0a4710 0x39c at 0x7fa573c848 +0x0000007f8c0a4ac0 0x3b8 at 0x7fa573c830 +0x0000007f8c0a4e80 0x84 at 0x7fa573c848 +0x0000007f8c0a4f10 0xcc0 at 0x7fa573c830 +0x0000007f8c0a5be0 0x550 at 0x7fa573c830 +0x0000007f8c0a6140 0x18c at 0x7fa573c848 +0x0000007f8c0a62e0 0x880 at 0x7fa573c830 +0x0000007f8c0a6b70 0x294 at 0x7fa573c848 +0x0000007f8c0a6e10 0x5d8 at 0x7fa573c830 +0x0000007f8c0a73f0 0x440 at 0x7fa573c830 +0x0000007f8c0a7840 0x84 at 0x7fa573c848 +0x0000007f8c0a78d0 0x4c8 at 0x7fa573c830 +0x0000007f8c0a7da0 0x880 at 0x7fa573c830 +0x0000007f8c0a8630 0x294 at 0x7fa573c848 +0x0000007f8c0a88d0 0x3b8 at 0x7fa573c830 +0x0000007f8c0a8c90 0x440 at 0x7fa573c830 +0x0000007f8c0a90e0 0x330 at 0x7fa573c830 +0x0000007f8c0a9420 0x550 at 0x7fa573c830 +0x0000007f8c0a9980 0x7f8 at 0x7fa573c830 +0x0000007f8c0aa180 0x84 at 0x7fa573c848 +0x0000007f8c0aa210 0x660 at 0x7fa573c830 +0x0000007f8c0aa880 0x210 at 0x7fa573c848 +0x0000007f8c0aaaa0 0x660 at 0x7fa573c830 +0x0000007f8c0ab110 0x18c at 0x7fa573c848 +0x0000007f8c0ab2b0 0xb28 at 0x7fa573c830 +0x0000007f8c0abde0 0x108 at 0x7fa573c848 +0x0000007f8c0abef0 0x990 at 0x7fa573c830 +0x0000007f8c0ac890 0x39c at 0x7fa573c848 +0x0000007f8c0acc40 0x4c8 at 0x7fa573c830 +0x0000007f8c0ad110 0x880 at 0x7fa573c830 +0x0000007f8c0ad9a0 0x5d8 at 0x7fa573c830 +0x0000007f8c0adf80 0x330 at 0x7fa573c830 +0x0000007f8c0ae2c0 0x84 at 0x7fa573c848 +0x0000007f8c0ae350 0x3b8 at 0x7fa573c830 +0x0000007f8c0ae710 0x5d8 at 0x7fa573c830 +0x0000007f8c0aecf0 0x660 at 0x7fa573c830 +0x0000007f8c0af360 0x210 at 0x7fa573c848 +0x0000007f8c0af580 0x440 at 0x7fa573c830 +0x0000007f8c0af9d0 0x108 at 0x7fa573c848 +0x0000007f8c0afae0 0x550 at 0x7fa573c830 +0x0000007f8c0b0040 0x18c at 0x7fa573c848 +0x0000007f8c0b01e0 0x770 at 0x7fa573c830 +0x0000007f8c0b0960 0x294 at 0x7fa573c848 +0x0000007f8c0b0c00 0x770 at 0x7fa573c830 +0x0000007f8c0b1380 0x294 at 0x7fa573c848 +0x0000007f8c0b1620 0x7f8 at 0x7fa573c830 +0x0000007f8c0b1e20 0x84 at 0x7fa573c848 +0x0000007f8c0b1eb0 0x770 at 0x7fa573c830 +0x0000007f8c0b2630 0x294 at 0x7fa573c848 +0x0000007f8c0b28d0 0x4c8 at 0x7fa573c830 +0x0000007f8c0b2da0 0x4c8 at 0x7fa573c830 +0x0000007f8c0b3270 0x7f8 at 0x7fa573c830 +0x0000007f8c0b3a70 0x84 at 0x7fa573c848 +0x0000007f8c0b3b00 0x990 at 0x7fa573c830 +0x0000007f8c0b44a0 0x318 at 0x7fa573c848 +0x0000007f8c0b47c0 0x440 at 0x7fa573c830 +0x0000007f8c0b4c10 0x330 at 0x7fa573c830 +0x0000007f8c0b4f50 0x210 at 0x7fa573c848 +0x0000007f8c0b5170 0x770 at 0x7fa573c830 +0x0000007f8c0b58f0 0x210 at 0x7fa573c848 +0x0000007f8c0b5b10 0x4c8 at 0x7fa573c830 +0x0000007f8c0b5fe0 0x5d8 at 0x7fa573c830 +0x0000007f8c0b65c0 0 at 0x7fa573c848 +0x0000007f8c0b65e0 0x990 at 0x7fa573c830 +0x0000007f8c0b6f80 0x318 at 0x7fa573c848 +0x0000007f8c0b72a0 0x440 at 0x7fa573c830 +0x0000007f8c0b76f0 0x84 at 0x7fa573c848 +0x0000007f8c0b7780 0x4c8 at 0x7fa573c830 +0x0000007f8c0b7c50 0 at 0x7fa573c848 +0x0000007f8c0b7c70 0x550 at 0x7fa573c830 +0x0000007f8c0b81d0 0x108 at 0x7fa573c848 +0x0000007f8c0b82e0 0xaa0 at 0x7fa573c830 +0x0000007f8c0b8d90 0x420 at 0x7fa573c848 +0x0000007f8c0b91c0 0x220 at 0x7fa573c830 +0x0000007f8c0b93f0 0x108 at 0x7fa573c848 +0x0000007f8c0b9500 0xbb0 at 0x7fa573c830 +0x0000007f8c0ba0c0 0x420 at 0x7fa573c848 +0x0000007f8c0ba4f0 0x660 at 0x7fa573c830 +0x0000007f8c0bab60 0x18c at 0x7fa573c848 +0x0000007f8c0bad00 0x660 at 0x7fa573c830 +0x0000007f8c0bb370 0x18c at 0x7fa573c848 +0x0000007f8c0bb510 0x660 at 0x7fa573c830 +0x0000007f8c0bbb80 0x5ac at 0x7fa573c848 +0x0000007f8c0bc140 0x770 at 0x7fa573c830 +0x0000007f8c0bc8c0 0x210 at 0x7fa573c848 +0x0000007f8c0bcae0 0xaa0 at 0x7fa573c830 +0x0000007f8c0bd590 0x420 at 0x7fa573c848 +0x0000007f8c0bd9c0 0xb28 at 0x7fa573c830 +0x0000007f8c0be4f0 0 at 0x7fa573c848 +0x0000007f8c0be510 0x440 at 0x7fa573c830 +0x0000007f8c0be960 0x108 at 0x7fa573c848 +0x0000007f8c0bea70 0xbb0 at 0x7fa573c830 +0x0000007f8c0bf630 0x420 at 0x7fa573c848 +0x0000007f8c0bfa60 0x440 at 0x7fa573c830 +0x0000007f8c0bfeb0 0x84 at 0x7fa573c848 +0x0000007f8c0bff40 0x880 at 0x7fa573c830 +0x0000007f8c0c07d0 0x318 at 0x7fa573c848 +0x0000007f8c0c0af0 0x4c8 at 0x7fa573c830 +0x0000007f8c0c0fc0 0 at 0x7fa573c848 +0x0000007f8c0c0fe0 0x660 at 0x7fa573c830 +0x0000007f8c0c1650 0x210 at 0x7fa573c848 +0x0000007f8c0c1870 0x440 at 0x7fa573c830 +0x0000007f8c0c1cc0 0 at 0x7fa573c848 +0x0000007f8c0c1ce0 0x14b8 at 0x7fa573c830 +0x0000007f8c0c31a0 0 at 0x7fa573c848 +0x0000007f8c0c31c0 0x990 at 0x7fa573c830 +0x0000007f8c0c3b60 0x318 at 0x7fa573c848 +0x0000007f8c0c3e80 0x550 at 0x7fa573c830 +0x0000007f8c0c43e0 0 at 0x7fa573c848 +0x0000007f8c0c4400 0x5d8 at 0x7fa573c830 +0x0000007f8c0c49e0 0 at 0x7fa573c848 +0x0000007f8c0c4a00 0x880 at 0x7fa573c830 +0x0000007f8c0c5290 0x318 at 0x7fa573c848 +0x0000007f8c0c55b0 0xb28 at 0x7fa573c830 +0x0000007f8c0c60e0 0x108 at 0x7fa573c848 +0x0000007f8c0c61f0 0x330 at 0x7fa573c830 +0x0000007f8c0c6530 0x84 at 0x7fa573c848 +0x0000007f8c0c65c0 0xb28 at 0x7fa573c830 +0x0000007f8c0c70f0 0x108 at 0x7fa573c848 +0x0000007f8c0c7200 0x550 at 0x7fa573c830 +0x0000007f8c0c7760 0x18c at 0x7fa573c848 +0x0000007f8c0c7900 0x5d8 at 0x7fa573c830 +0x0000007f8c0c7ee0 0 at 0x7fa573c848 +0x0000007f8c0c7f00 0x990 at 0x7fa573c830 +0x0000007f8c0c88a0 0x39c at 0x7fa573c848 +0x0000007f8c0c8c50 0x4c8 at 0x7fa573c830 +0x0000007f8c0c9120 0 at 0x7fa573c848 +0x0000007f8c0c9140 0x440 at 0x7fa573c830 +0x0000007f8c0c9590 0x108 at 0x7fa573c848 +0x0000007f8c0c96a0 0xaa0 at 0x7fa573c830 +0x0000007f8c0ca150 0x39c at 0x7fa573c848 +0x0000007f8c0ca500 0x4c8 at 0x7fa573c830 +0x0000007f8c0ca9d0 0x210 at 0x7fa573c848 +0x0000007f8c0cabf0 0x3b8 at 0x7fa573c830 +0x0000007f8c0cafb0 0 at 0x7fa573c848 +0x0000007f8c0cafd0 0x3b8 at 0x7fa573c830 +0x0000007f8c0cb390 0 at 0x7fa573c848 +0x0000007f8c0cb3b0 0xaa0 at 0x7fa573c830 +0x0000007f8c0cbe60 0x39c at 0x7fa573c848 +0x0000007f8c0cc210 0x4c8 at 0x7fa573c830 +0x0000007f8c0cc6e0 0 at 0x7fa573c848 +0x0000007f8c0cc700 0 at 0x7fa573c848 +0x0000007f8c0cc720 0x880 at 0x7fa573c830 +0x0000007f8c0ccfb0 0x318 at 0x7fa573c848 +0x0000007f8c0cd2d0 0xbb0 at 0x7fa573c830 +0x0000007f8c0cde90 0x420 at 0x7fa573c848 +0x0000007f8c0ce2c0 0x660 at 0x7fa573c830 +0x0000007f8c0ce930 0x18c at 0x7fa573c848 +0x0000007f8c0cead0 0x880 at 0x7fa573c830 +0x0000007f8c0cf360 0x294 at 0x7fa573c848 +0x0000007f8c0cf600 0x5d8 at 0x7fa573c830 +0x0000007f8c0cfbe0 0 at 0x7fa573c848 +0x0000007f8c0cfc00 0x660 at 0x7fa573c830 +0x0000007f8c0d0270 0x210 at 0x7fa573c848 +0x0000007f8c0d0490 0xb28 at 0x7fa573c830 +0x0000007f8c0d0fc0 0x108 at 0x7fa573c848 +0x0000007f8c0d10d0 0xcc0 at 0x7fa573c830 +0x0000007f8c0d1da0 0 at 0x7fa573c848 +0x0000007f8c0d1dc0 0x5d8 at 0x7fa573c830 +0x0000007f8c0d23a0 0 at 0x7fa573c848 +0x0000007f8c0d23c0 0x770 at 0x7fa573c830 +0x0000007f8c0d2b40 0x420 at 0x7fa573c848 +0x0000007f8c0d2f70 0x990 at 0x7fa573c830 +0x0000007f8c0d3910 0x39c at 0x7fa573c848 +0x0000007f8c0d3cc0 0x3b8 at 0x7fa573c830 +0x0000007f8c0d4080 0x84 at 0x7fa573c848 +0x0000007f8c0d4110 0x770 at 0x7fa573c830 +0x0000007f8c0d4890 0x210 at 0x7fa573c848 +0x0000007f8c0d4ab0 0x770 at 0x7fa573c830 +0x0000007f8c0d5230 0x294 at 0x7fa573c848 +0x0000007f8c0d54d0 0xb28 at 0x7fa573c830 +0x0000007f8c0d6000 0 at 0x7fa573c848 +0x0000007f8c0d6020 0x330 at 0x7fa573c830 +0x0000007f8c0d6360 0 at 0x7fa573c848 +0x0000007f8c0d6380 0xaa0 at 0x7fa573c830 +0x0000007f8c0d6e30 0x39c at 0x7fa573c848 +0x0000007f8c0d71e0 0x5d8 at 0x7fa573c830 +0x0000007f8c0d77c0 0 at 0x7fa573c848 +0x0000007f8c0d77e0 0x880 at 0x7fa573c830 +0x0000007f8c0d8070 0x318 at 0x7fa573c848 +0x0000007f8c0d8390 0x660 at 0x7fa573c830 +0x0000007f8c0d8a00 0 at 0x7fa573c848 +0x0000007f8c0d8a20 0x1650 at 0x7fa573c830 +0x0000007f8c0da080 0 at 0x7fa573c848 +0x0000007f8c0da0a0 0x330 at 0x7fa573c830 +0x0000007f8c0da3e0 0 at 0x7fa573c848 +0x0000007f8c0da400 0x4c8 at 0x7fa573c830 +0x0000007f8c0da8d0 0 at 0x7fa573c848 +0x0000007f8c0da8f0 0x60c at 0x40ded8 +0x0000007f8c0daff0 0x40 at 0x441508 +0x0000007f8c0db040 0x40 at 0x441508 +0x0000007f8c0db090 0x40 at 0x441508 +0x0000007f8c0db100 0x40 at 0x441508 +0x0000007f8c0db170 0x40 at 0x441508 +0x0000007f8c0db200 0x40 at 0x441508 +0x0000007f8c0db250 0x40 at 0x441508 +0x0000007f8c0db2e0 0x40 at 0x441508 +0x0000007f8c0db350 0x40 at 0x441508 +0x0000007f8c0db3a0 0x120 at 0x7fa5aa3b10 +0x0000007f8c0db4f0 0x40 at 0x441508 +0x0000007f8c0db540 0x40 at 0x441508 +0x0000007f8c0db590 0x40 at 0x441508 +0x0000007f8c1245d0 0x40 at 0x441508 +0x0000007f8c124620 0x40 at 0x441508 +0x0000007f8c1246b0 0x40 at 0x441508 +0x0000007f8c124700 0x40 at 0x441508 +0x0000007f8c124770 0x40 at 0x441508 +0x0000007f8c1247c0 0x40 at 0x441508 +0x0000007f8c124930 0x120 at 0x7fa5aa3b10 +0x0000007f8c124a60 0x40 at 0x441508 +0x0000007f8c124ab0 0x40 at 0x441508 +0x0000007f8c124b00 0x40 at 0x441508 +0x0000007f8c124b90 0x40 at 0x441508 +0x0000007f8c124be0 0x40 at 0x441508 +0x0000007f8c124c60 0x40 at 0x441508 +0x0000007f8c124d20 0x40 at 0x441508 +0x0000007f8c124d70 0x40 at 0x441508 +0x0000007f8c124dc0 0x40 at 0x441508 +0x0000007f8c124e30 0x40 at 0x441508 +0x0000007f8c124ec0 0x40 at 0x441508 +0x0000007f8c124f10 0x40 at 0x441508 +0x0000007f8c124f80 0x40 at 0x441508 +0x0000007f8c124fd0 0x40 at 0x441508 +0x0000007f8c1251c0 0x40 at 0x441508 +0x0000007f8c125490 0x40 at 0x441508 +0x0000007f8c1254e0 0x40 at 0x441508 +0x0000007f8c125530 0x40 at 0x441508 +0x0000007f8c125580 0x40 at 0x441508 +0x0000007f8c1255d0 0x40 at 0x441508 +0x0000007f8c125640 0x40 at 0x441508 +0x0000007f8c125690 0x40 at 0x441508 +0x0000007f8c1256e0 0x40 at 0x441508 +0x0000007f8c125760 0x40 at 0x441508 +0x0000007f8c1257b0 0x40 at 0x441508 +0x0000007f8c125800 0x40 at 0x441508 +0x0000007f8c125890 0x40 at 0x441508 +0x0000007f8c1258e0 0x40 at 0x441508 +0x0000007f8c125950 0x40 at 0x441508 +0x0000007f8c1259d0 0x40 at 0x441508 +0x0000007f8c125b00 0x40 at 0x441508 +0x0000007f8c125b50 0x40 at 0x441508 +0x0000007f8c125bc0 0x40 at 0x441508 +0x0000007f8c125c10 0x40 at 0x441508 +0x0000007f8c125d10 0x40 at 0x441508 +0x0000007f8c125e80 0x40 at 0x441508 +0x0000007f8c125ed0 0x40 at 0x441508 +0x0000007f8c125f20 0x40 at 0x441508 +0x0000007f8c126360 0x40 at 0x441508 +0x0000007f8c1264e0 0x40 at 0x441508 +0x0000007f8c126a20 0x40 at 0x441508 +0x0000007f8c126ba0 0x40 at 0x441508 +0x0000007f8c126fc0 0x40 at 0x441508 +0x0000007f8c127120 0x40 at 0x441508 +0x0000007f8c127560 0x40 at 0x441508 +0x0000007f8c1276e0 0x40 at 0x441508 +0x0000007f8c127730 0x40 at 0x441508 +0x0000007f8c127b50 0x40 at 0x441508 +0x0000007f8c127c50 0x40 at 0x441508 +0x0000007f8c127ca0 0x40 at 0x441508 +0x0000007f8c127cf0 0x40 at 0x441508 +0x0000007f8c127d40 0x40 at 0x441508 +0x0000007f8c127d90 0x40 at 0x441508 +0x0000007f8c127de0 0x40 at 0x441508 +0x0000007f8c127e30 0x40 at 0x441508 +0x0000007f8c127e80 0x40 at 0x441508 +0x0000007f8c127ef0 0x40 at 0x441508 +0x0000007f8c127f70 0x40 at 0x441508 +0x0000007f8c127fc0 0x40 at 0x441508 +0x0000007f8c128010 0x40 at 0x441508 +0x0000007f8c128060 0x40 at 0x441508 +0x0000007f8c128450 0x40 at 0x441508 +0x0000007f8c1284a0 0x40 at 0x441508 +0x0000007f8c1284f0 0x40 at 0x441508 +0x0000007f8c128540 0x40 at 0x441508 +0x0000007f8c1287a0 0x40 at 0x441508 +0x0000007f8c1287f0 0x40 at 0x441508 +0x0000007f8c128840 0x40 at 0x441508 +0x0000007f8c128890 0x40 at 0x441508 +0x0000007f8c1288e0 0x40 at 0x441508 +0x0000007f8c128930 0x40 at 0x441508 +0x0000007f8c128bb0 0x40 at 0x441508 +0x0000007f8c128f50 0x40 at 0x441508 +0x0000007f8c128fa0 0x40 at 0x441508 +0x0000007f8c128ff0 0x40 at 0x441508 +0x0000007f8c129040 0x40 at 0x441508 +0x0000007f8c129090 0x40 at 0x441508 +0x0000007f8c129310 0x40 at 0x441508 +0x0000007f8c129360 0x40 at 0x441508 +0x0000007f8c1293b0 0x40 at 0x441508 +0x0000007f8c129400 0x40 at 0x441508 +0x0000007f8c129450 0x40 at 0x441508 +0x0000007f8c1294a0 0x40 at 0x441508 +0x0000007f8c129510 0x40 at 0x441508 +0x0000007f8c129560 0x40 at 0x441508 +0x0000007f8c1295d0 0x40 at 0x441508 +0x0000007f8c129620 0x40 at 0x441508 +0x0000007f8c129670 0x40 at 0x441508 +0x0000007f8c1296f0 0x40 at 0x441508 +0x0000007f8c129740 0x40 at 0x441508 +0x0000007f8c129a80 0x40 at 0x441508 +0x0000007f8c129af0 0x40 at 0x441508 +0x0000007f8c129b40 0x40 at 0x441508 +0x0000007f8c129b90 0x40 at 0x441508 +0x0000007f8c129be0 0x40 at 0x441508 +0x0000007f8c129c60 0x40 at 0x441508 +0x0000007f8c129cb0 0x40 at 0x441508 +0x0000007f8c129d00 0x40 at 0x441508 +0x0000007f8c129d50 0x40 at 0x441508 +0x0000007f8c129da0 0x40 at 0x441508 +0x0000007f8c129df0 0x40 at 0x441508 +0x0000007f8c129e40 0x40 at 0x441508 +0x0000007f8c129e90 0x40 at 0x441508 +0x0000007f8c129ee0 0x40 at 0x441508 +0x0000007f8c129f50 0x40 at 0x441508 +0x0000007f8c129fc0 0x40 at 0x441508 +0x0000007f8c12a010 0x40 at 0x441508 +0x0000007f8c12a680 0x40 at 0x441508 +0x0000007f8c12a6d0 0x40 at 0x441508 +0x0000007f8c12a720 0x40 at 0x441508 +0x0000007f8c12a770 0x40 at 0x441508 +0x0000007f8c12a900 0x40 at 0x441508 +0x0000007f8c12a950 0x40 at 0x441508 +0x0000007f8c12aa10 0x40 at 0x441508 +0x0000007f8c12aa90 0x40 at 0x441508 +0x0000007f8c12aae0 0x40 at 0x441508 +0x0000007f8c12ab30 0x40 at 0x441508 +0x0000007f8c12abb0 0x40 at 0x441508 +0x0000007f8c12ac30 0x40 at 0x441508 +0x0000007f8c12aed0 0x40 at 0x441508 +0x0000007f8c12af20 0x40 at 0x441508 +0x0000007f8c12af70 0x40 at 0x441508 +0x0000007f8c12afc0 0x40 at 0x441508 +0x0000007f8c12b010 0x40 at 0x441508 +0x0000007f8c12b060 0x40 at 0x441508 +0x0000007f8c12b0b0 0x40 at 0x441508 +0x0000007f8c12b100 0x40 at 0x441508 +0x0000007f8c12b150 0x40 at 0x441508 +0x0000007f8c12b1a0 0x40 at 0x441508 +0x0000007f8c12b550 0x40 at 0x441508 +0x0000007f8c12b5c0 0x40 at 0x441508 +0x0000007f8c12b610 0x40 at 0x441508 +0x0000007f8c12b680 0x40 at 0x441508 +0x0000007f8c12b860 0x40 at 0x441508 +0x0000007f8c12b8b0 0x40 at 0x441508 +0x0000007f8c12b900 0x40 at 0x441508 +0x0000007f8c12b950 0x40 at 0x441508 +0x0000007f8c12b9a0 0x40 at 0x441508 +0x0000007f8c12b9f0 0x40 at 0x441508 +0x0000007f8c12ba40 0x40 at 0x441508 +0x0000007f8c12bbd0 0x40 at 0x441508 +0x0000007f8c12bc20 0x40 at 0x441508 +0x0000007f8c12bc70 0x40 at 0x441508 +0x0000007f8c12bcc0 0x40 at 0x441508 +0x0000007f8c12bd10 0x40 at 0x441508 +0x0000007f8c12bd60 0x40 at 0x441508 +0x0000007f8c12bdb0 0x40 at 0x441508 +0x0000007f8c12be00 0x40 at 0x441508 +0x0000007f8c12be70 0x40 at 0x441508 +0x0000007f8c12c000 0x40 at 0x441508 +0x0000007f8c12c050 0x40 at 0x441508 +0x0000007f8c12c0a0 0x40 at 0x441508 +0x0000007f8c12c590 0x40 at 0x441508 +0x0000007f8c12c5e0 0x40 at 0x441508 +0x0000007f8c12c650 0x40 at 0x441508 +0x0000007f8c12c7c0 0x40 at 0x441508 +0x0000007f8c12c810 0x40 at 0x441508 +0x0000007f8c12c860 0x40 at 0x441508 +0x0000007f8c12c8b0 0x40 at 0x441508 +0x0000007f8c12c900 0x40 at 0x441508 +0x0000007f8c12c950 0x40 at 0x441508 +0x0000007f8c12c9a0 0x40 at 0x441508 +0x0000007f8c12c9f0 0x40 at 0x441508 +0x0000007f8c12ca40 0x40 at 0x441508 +0x0000007f8c12ccc0 0x40 at 0x441508 +0x0000007f8c12cd10 0x40 at 0x441508 +0x0000007f8c12cd60 0x40 at 0x441508 +0x0000007f8c12cdb0 0x40 at 0x441508 +0x0000007f8c12ce00 0x40 at 0x441508 +0x0000007f8c12d220 0x40 at 0x441508 +0x0000007f8c12d740 0x40 at 0x441508 +0x0000007f8c12d790 0x40 at 0x441508 +0x0000007f8c12e2c0 0x40 at 0x441508 +0x0000007f8c12e310 0x40 at 0x441508 +0x0000007f8c12e360 0x40 at 0x441508 +0x0000007f8c12e3b0 0x40 at 0x441508 +0x0000007f8c12e400 0x40 at 0x441508 +0x0000007f8c12e5e0 0x40 at 0x441508 +0x0000007f8c12e630 0x40 at 0x441508 +0x0000007f8c12e680 0x40 at 0x441508 +0x0000007f8c12e8e0 0x40 at 0x441508 +0x0000007f8c12e930 0x40 at 0x441508 +0x0000007f8c12e980 0x40 at 0x441508 +0x0000007f8c12e9d0 0x40 at 0x441508 +0x0000007f8c12ea20 0x40 at 0x441508 +0x0000007f8c12ea90 0x40 at 0x441508 +0x0000007f8c12ecb0 0x40 at 0x441508 +0x0000007f8c12ed00 0x40 at 0x441508 +0x0000007f8c12ed70 0x40 at 0x441508 +0x0000007f8c12ede0 0x40 at 0x441508 +0x0000007f8c12ee60 0x40 at 0x441508 +0x0000007f8c12eeb0 0x40 at 0x441508 +0x0000007f8c12ef00 0x40 at 0x441508 +0x0000007f8c12ef50 0x40 at 0x441508 +0x0000007f8c12efa0 0x40 at 0x441508 +0x0000007f8c12eff0 0x40 at 0x441508 +0x0000007f8c12f040 0x40 at 0x441508 +0x0000007f8c12f090 0x40 at 0x441508 +0x0000007f8c12f0e0 0x40 at 0x441508 +0x0000007f8c12f130 0x40 at 0x441508 +0x0000007f8c12f180 0x40 at 0x441508 +0x0000007f8c12f1d0 0x40 at 0x441508 +0x0000007f8c12f220 0x40 at 0x441508 +0x0000007f8c12f270 0x40 at 0x441508 +0x0000007f8c12f2c0 0x40 at 0x441508 +0x0000007f8c12f310 0x40 at 0x441508 +0x0000007f8c12f360 0x40 at 0x441508 +0x0000007f8c12f3b0 0x40 at 0x441508 +0x0000007f8c12f420 0x40 at 0x441508 +0x0000007f8c12fab0 0x40 at 0x441508 +0x0000007f8c12fb00 0x40 at 0x441508 +0x0000007f8c12fb50 0x40 at 0x441508 +0x0000007f8c12fba0 0x40 at 0x441508 +0x0000007f8c12fbf0 0x40 at 0x441508 +0x0000007f8c12fc40 0x40 at 0x441508 +0x0000007f8c12fcb0 0x40 at 0x441508 +0x0000007f8c12fd30 0x40 at 0x441508 +0x0000007f8c12fd80 0x40 at 0x441508 +0x0000007f8c12fdd0 0x40 at 0x441508 +0x0000007f8c12fe20 0x40 at 0x441508 +0x0000007f8c12fe70 0x40 at 0x441508 +0x0000007f8c12fec0 0x40 at 0x441508 +0x0000007f8c12ffb0 0x40 at 0x441508 +0x0000007f8c130000 0x40 at 0x441508 +0x0000007f8c130050 0x40 at 0x441508 +0x0000007f8c1300a0 0x40 at 0x441508 +0x0000007f8c1300f0 0x40 at 0x441508 +0x0000007f8c130140 0x40 at 0x441508 +0x0000007f8c130190 0x40 at 0x441508 +0x0000007f8c1301e0 0x40 at 0x441508 +0x0000007f8c130230 0x40 at 0x441508 +0x0000007f8c1302a0 0x40 at 0x441508 +0x0000007f8c1302f0 0x40 at 0x441508 +0x0000007f8c130370 0x40 at 0x441508 +0x0000007f8c1303c0 0x40 at 0x441508 +0x0000007f8c130410 0x40 at 0x441508 +0x0000007f8c130460 0x40 at 0x441508 +0x0000007f8c1304b0 0x40 at 0x441508 +0x0000007f8c130500 0x40 at 0x441508 +0x0000007f8c130550 0x40 at 0x441508 +0x0000007f8c1305a0 0x40 at 0x441508 +0x0000007f8c1305f0 0x40 at 0x441508 +0x0000007f8c130640 0x40 at 0x441508 +0x0000007f8c1307d0 0x40 at 0x441508 +0x0000007f8c130820 0x40 at 0x441508 +0x0000007f8c1309b0 0x40 at 0x441508 +0x0000007f8c130a00 0x40 at 0x441508 +0x0000007f8c130a50 0x40 at 0x441508 +0x0000007f8c130aa0 0x40 at 0x441508 +0x0000007f8c130af0 0x40 at 0x441508 +0x0000007f8c130b40 0x40 at 0x441508 +0x0000007f8c130bb0 0x40 at 0x441508 +0x0000007f8c130c00 0x40 at 0x441508 +0x0000007f8c130c80 0x40 at 0x441508 +0x0000007f8c130cd0 0x40 at 0x441508 +0x0000007f8c130d20 0x40 at 0x441508 +0x0000007f8c130d70 0x40 at 0x441508 +0x0000007f8c130dc0 0x40 at 0x441508 +0x0000007f8c130e10 0x40 at 0x441508 +0x0000007f8c130e60 0x40 at 0x441508 +0x0000007f8c130eb0 0x40 at 0x441508 +0x0000007f8c130f00 0x40 at 0x441508 +0x0000007f8c130f50 0x40 at 0x441508 +0x0000007f8c130fa0 0x40 at 0x441508 +0x0000007f8c130ff0 0x40 at 0x441508 +0x0000007f8c131040 0x40 at 0x441508 +0x0000007f8c1310b0 0x40 at 0x441508 +0x0000007f8c131100 0x40 at 0x441508 +0x0000007f8c1315c0 0x40 at 0x441508 +0x0000007f8c131610 0x40 at 0x441508 +0x0000007f8c131be0 0x40 at 0x441508 +0x0000007f8c131c70 0x40 at 0x441508 +0x0000007f8c131cf0 0x40 at 0x441508 +0x0000007f8c131d40 0x40 at 0x441508 +0x0000007f8c131d90 0x40 at 0x441508 +0x0000007f8c131ff0 0x40 at 0x441508 +0x0000007f8c132040 0x40 at 0x441508 +0x0000007f8c132090 0x40 at 0x441508 +0x0000007f8c132100 0x40 at 0x441508 +0x0000007f8c132150 0x40 at 0x441508 +0x0000007f8c132600 0x40 at 0x441508 +0x0000007f8c132650 0x40 at 0x441508 +0x0000007f8c132890 0x40 at 0x441508 +0x0000007f8c1328e0 0x40 at 0x441508 +0x0000007f8c132a20 0x40 at 0x441508 +0x0000007f8c132a90 0x40 at 0x441508 +0x0000007f8c132ae0 0x40 at 0x441508 +0x0000007f8c132fd0 0x40 at 0x441508 +0x0000007f8c133020 0x40 at 0x441508 +0x0000007f8c133210 0x40 at 0x441508 +0x0000007f8c133260 0x40 at 0x441508 +0x0000007f8c1332b0 0x40 at 0x441508 +0x0000007f8c133300 0x40 at 0x441508 +0x0000007f8c133350 0x40 at 0x441508 +0x0000007f8c1333c0 0x40 at 0x441508 +0x0000007f8c133410 0x40 at 0x441508 +0x0000007f8c133460 0x40 at 0x441508 +0x0000007f8c133920 0x40 at 0x441508 +0x0000007f8c133990 0x40 at 0x441508 +0x0000007f8c1339e0 0x40 at 0x441508 +0x0000007f8c133a70 0x40 at 0x441508 +0x0000007f8c133ac0 0x40 at 0x441508 +0x0000007f8c133b10 0x40 at 0x441508 +0x0000007f8c133b60 0x40 at 0x441508 +0x0000007f8c133bb0 0x40 at 0x441508 +0x0000007f8c133c00 0x40 at 0x441508 +0x0000007f8c133c50 0x40 at 0x441508 +0x0000007f8c133ca0 0x40 at 0x441508 +0x0000007f8c133cf0 0x40 at 0x441508 +0x0000007f8c133d40 0x40 at 0x441508 +0x0000007f8c133d90 0x40 at 0x441508 +0x0000007f8c133de0 0x40 at 0x441508 +0x0000007f8c133e30 0x40 at 0x441508 +0x0000007f8c133e80 0x40 at 0x441508 +0x0000007f8c133ed0 0x40 at 0x441508 +0x0000007f8c133f20 0x40 at 0x441508 +0x0000007f8c133f70 0x40 at 0x441508 +0x0000007f8c133fc0 0x40 at 0x441508 +0x0000007f8c134010 0x40 at 0x441508 +0x0000007f8c134060 0x40 at 0x441508 +0x0000007f8c1340b0 0x40 at 0x441508 +0x0000007f8c134100 0x40 at 0x441508 +0x0000007f8c1342e0 0x40 at 0x441508 +0x0000007f8c134330 0x40 at 0x441508 +0x0000007f8c134380 0x40 at 0x441508 +0x0000007f8c1343d0 0x40 at 0x441508 +0x0000007f8c134420 0x40 at 0x441508 +0x0000007f8c134470 0x40 at 0x441508 +0x0000007f8c1344c0 0x40 at 0x441508 +0x0000007f8c134510 0x40 at 0x441508 +0x0000007f8c134560 0x40 at 0x441508 +0x0000007f8c1345b0 0x40 at 0x441508 +0x0000007f8c134600 0x40 at 0x441508 +0x0000007f8c134650 0x40 at 0x441508 +0x0000007f8c1346a0 0x40 at 0x441508 +0x0000007f8c1346f0 0x40 at 0x441508 +0x0000007f8c134740 0x40 at 0x441508 +0x0000007f8c134790 0x40 at 0x441508 +0x0000007f8c1347e0 0x40 at 0x441508 +0x0000007f8c1348d0 0x40 at 0x441508 +0x0000007f8c134920 0x40 at 0x441508 +0x0000007f8c134970 0x40 at 0x441508 +0x0000007f8c1349c0 0x40 at 0x441508 +0x0000007f8c134a10 0x40 at 0x441508 +0x0000007f8c134a60 0x40 at 0x441508 +0x0000007f8c134ab0 0x40 at 0x441508 +0x0000007f8c134b00 0x40 at 0x441508 +0x0000007f8c134b50 0x40 at 0x441508 +0x0000007f8c134ba0 0x40 at 0x441508 +0x0000007f8c134c10 0x40 at 0x441508 +0x0000007f8c134c60 0x40 at 0x441508 +0x0000007f8c134cd0 0x40 at 0x441508 +0x0000007f8c134d20 0x40 at 0x441508 +0x0000007f8c134d70 0x40 at 0x441508 +0x0000007f8c134dc0 0x40 at 0x441508 +0x0000007f8c134e30 0x40 at 0x441508 +0x0000007f8c134e80 0x40 at 0x441508 +0x0000007f8c134ed0 0x40 at 0x441508 +0x0000007f8c134f20 0x40 at 0x441508 +0x0000007f8c134f70 0x40 at 0x441508 +0x0000007f8c134fc0 0x40 at 0x441508 +0x0000007f8c135010 0x40 at 0x441508 +0x0000007f8c135060 0x40 at 0x441508 +0x0000007f8c1350b0 0x40 at 0x441508 +0x0000007f8c135120 0x40 at 0x441508 +0x0000007f8c1351a0 0x40 at 0x441508 +0x0000007f8c1351f0 0x40 at 0x441508 +0x0000007f8c135240 0x40 at 0x441508 +0x0000007f8c135290 0x40 at 0x441508 +0x0000007f8c1352e0 0x40 at 0x441508 +0x0000007f8c135330 0x40 at 0x441508 +0x0000007f8c135380 0x40 at 0x441508 +0x0000007f8c1353d0 0x40 at 0x441508 +0x0000007f8c135420 0x40 at 0x441508 +0x0000007f8c135470 0x40 at 0x441508 +0x0000007f8c1354c0 0x40 at 0x441508 +0x0000007f8c135510 0x40 at 0x441508 +0x0000007f8c135560 0x40 at 0x441508 +0x0000007f8c1355d0 0x40 at 0x441508 +0x0000007f8c135620 0x40 at 0x441508 +0x0000007f8c135670 0x40 at 0x441508 +0x0000007f8c1356c0 0x40 at 0x441508 +0x0000007f8c135710 0x40 at 0x441508 +0x0000007f8c135760 0x40 at 0x441508 +0x0000007f8c1357b0 0x40 at 0x441508 +0x0000007f8c135800 0x40 at 0x441508 +0x0000007f8c135850 0x40 at 0x441508 +0x0000007f8c1358a0 0x40 at 0x441508 +0x0000007f8c1358f0 0x40 at 0x441508 +0x0000007f8c135940 0x40 at 0x441508 +0x0000007f8c1359e0 0x40 at 0x441508 +0x0000007f8c135a30 0x40 at 0x441508 +0x0000007f8c135aa0 0x40 at 0x441508 +0x0000007f8c135af0 0x40 at 0x441508 +0x0000007f8c135b40 0x40 at 0x441508 +0x0000007f8c135cf0 0x40 at 0x441508 +0x0000007f8c135d40 0x40 at 0x441508 +0x0000007f8c135d90 0x40 at 0x441508 +0x0000007f8c135de0 0x40 at 0x441508 +0x0000007f8c135e30 0x40 at 0x441508 +0x0000007f8c135e80 0x40 at 0x441508 +0x0000007f8c136910 0x40 at 0x441508 +0x0000007f8c136960 0x40 at 0x441508 +0x0000007f8c1369b0 0x40 at 0x441508 +0x0000007f8c136a00 0x40 at 0x441508 +0x0000007f8c136a50 0x40 at 0x441508 +0x0000007f8c136aa0 0x40 at 0x441508 +0x0000007f8c136b10 0x40 at 0x441508 +0x0000007f8c136b60 0x40 at 0x441508 +0x0000007f8c136c00 0x40 at 0x441508 +0x0000007f8c136cc0 0x40 at 0x441508 +0x0000007f8c136d10 0x40 at 0x441508 +0x0000007f8c136f40 0x40 at 0x441508 +0x0000007f8c136fb0 0x40 at 0x441508 +0x0000007f8c137000 0x40 at 0x441508 +0x0000007f8c137050 0x40 at 0x441508 +0x0000007f8c1370a0 0x40 at 0x441508 +0x0000007f8c1370f0 0x40 at 0x441508 +0x0000007f8c137140 0x40 at 0x441508 +0x0000007f8c137190 0x40 at 0x441508 +0x0000007f8c1371e0 0x40 at 0x441508 +0x0000007f8c137230 0x40 at 0x441508 +0x0000007f8c137280 0x40 at 0x441508 +0x0000007f8c1372d0 0x40 at 0x441508 +0x0000007f8c137460 0x40 at 0x441508 +0x0000007f8c1374b0 0x40 at 0x441508 +0x0000007f8c137500 0x40 at 0x441508 +0x0000007f8c137550 0x40 at 0x441508 +0x0000007f8c1375a0 0x40 at 0x441508 +0x0000007f8c1375f0 0x40 at 0x441508 +0x0000007f8c137640 0x40 at 0x441508 +0x0000007f8c137690 0x40 at 0x441508 +0x0000007f8c1376e0 0x40 at 0x441508 +0x0000007f8c137730 0x40 at 0x441508 +0x0000007f8c137780 0x40 at 0x441508 +0x0000007f8c1377d0 0x40 at 0x441508 +0x0000007f8c137820 0x40 at 0x441508 +0x0000007f8c137870 0x40 at 0x441508 +0x0000007f8c137900 0x40 at 0x441508 +0x0000007f8c137950 0x40 at 0x441508 +0x0000007f8c1379a0 0x40 at 0x441508 +0x0000007f8c1379f0 0x40 at 0x441508 +0x0000007f8c137a70 0x40 at 0x441508 +0x0000007f8c137ac0 0x40 at 0x441508 +0x0000007f8c137b10 0x40 at 0x441508 +0x0000007f8c137b60 0x40 at 0x441508 +0x0000007f8c137bb0 0x40 at 0x441508 +0x0000007f8c137c00 0x40 at 0x441508 +0x0000007f8c137c70 0x40 at 0x441508 +0x0000007f8c137cc0 0x40 at 0x441508 +0x0000007f8c137d10 0x40 at 0x441508 +0x0000007f8c137d80 0x40 at 0x441508 +0x0000007f8c137e00 0x40 at 0x441508 +0x0000007f8c137e50 0x40 at 0x441508 +0x0000007f8c137ea0 0x40 at 0x441508 +0x0000007f8c137ef0 0x40 at 0x441508 +0x0000007f8c137f40 0x40 at 0x441508 +0x0000007f8c137f90 0x40 at 0x441508 +0x0000007f8c138000 0x40 at 0x441508 +0x0000007f8c138050 0x40 at 0x441508 +0x0000007f8c1381d0 0x40 at 0x441508 +0x0000007f8c138220 0x40 at 0x441508 +0x0000007f8c138270 0x40 at 0x441508 +0x0000007f8c1382c0 0x40 at 0x441508 +0x0000007f8c138330 0x40 at 0x441508 +0x0000007f8c1383b0 0x40 at 0x441508 +0x0000007f8c138400 0x40 at 0x441508 +0x0000007f8c138470 0x40 at 0x441508 +0x0000007f8c1384f0 0x40 at 0x441508 +0x0000007f8c138540 0x40 at 0x441508 +0x0000007f8c138590 0x40 at 0x441508 +0x0000007f8c138680 0x40 at 0x441508 +0x0000007f8c1386d0 0x40 at 0x441508 +0x0000007f8c138720 0x40 at 0x441508 +0x0000007f8c138770 0x40 at 0x441508 +0x0000007f8c1387c0 0x40 at 0x441508 +0x0000007f8c1388e0 0x40 at 0x441508 +0x0000007f8c138930 0x40 at 0x441508 +0x0000007f8c138980 0x40 at 0x441508 +0x0000007f8c1389f0 0x40 at 0x441508 +0x0000007f8c138a40 0x40 at 0x441508 +0x0000007f8c138bb0 0x40 at 0x441508 +0x0000007f8c138c00 0x40 at 0x441508 +0x0000007f8c138c50 0x40 at 0x441508 +0x0000007f8c138ca0 0x40 at 0x441508 +0x0000007f8c138cf0 0x40 at 0x441508 +0x0000007f8c138d40 0x40 at 0x441508 +0x0000007f8c138d90 0x40 at 0x441508 +0x0000007f8c138de0 0x40 at 0x441508 +0x0000007f8c138e50 0x40 at 0x441508 +0x0000007f8c138ea0 0x40 at 0x441508 +0x0000007f8c138f20 0x40 at 0x441508 +0x0000007f8c138f70 0x40 at 0x441508 +0x0000007f8c138fc0 0x40 at 0x441508 +0x0000007f8c139060 0x40 at 0x441508 +0x0000007f8c1390b0 0x40 at 0x441508 +0x0000007f8c139100 0x40 at 0x441508 +0x0000007f8c139150 0x40 at 0x441508 +0x0000007f8c1391a0 0x40 at 0x441508 +0x0000007f8c1392c0 0x40 at 0x441508 +0x0000007f8c139310 0x40 at 0x441508 +0x0000007f8c139360 0x40 at 0x441508 +0x0000007f8c1393b0 0x40 at 0x441508 +0x0000007f8c139400 0x40 at 0x441508 +0x0000007f8c139450 0x40 at 0x441508 +0x0000007f8c1394a0 0x40 at 0x441508 +0x0000007f8c1394f0 0x40 at 0x441508 +0x0000007f8c139540 0x40 at 0x441508 +0x0000007f8c139590 0x40 at 0x441508 +0x0000007f8c139600 0x40 at 0x441508 +0x0000007f8c139a40 0x40 at 0x441508 +0x0000007f8c139cf0 0x40 at 0x441508 +0x0000007f8c139d40 0x40 at 0x441508 +0x0000007f8c139db0 0x40 at 0x441508 +0x0000007f8c139e00 0x40 at 0x441508 +0x0000007f8c139e70 0x40 at 0x441508 +0x0000007f8c139ec0 0x40 at 0x441508 +0x0000007f8c13a370 0x40 at 0x441508 +0x0000007f8c13a3c0 0x40 at 0x441508 +0x0000007f8c13a410 0x40 at 0x441508 +0x0000007f8c13a580 0x40 at 0x441508 +0x0000007f8c13a5d0 0x40 at 0x441508 +0x0000007f8c13a620 0x40 at 0x441508 +0x0000007f8c13a780 0x40 at 0x441508 +0x0000007f8c13aaa0 0x40 at 0x441508 +0x0000007f8c13aca0 0x40 at 0x441508 +0x0000007f8c13ad10 0x40 at 0x441508 +0x0000007f8c13aea0 0x40 at 0x441508 +0x0000007f8c13aef0 0x40 at 0x441508 +0x0000007f8c13af40 0x40 at 0x441508 +0x0000007f8c13af90 0x40 at 0x441508 +0x0000007f8c13b000 0x40 at 0x441508 +0x0000007f8c13b6a0 0x40 at 0x441508 +0x0000007f8c13b6f0 0x40 at 0x441508 +0x0000007f8c13b740 0x40 at 0x441508 +0x0000007f8c13b790 0x40 at 0x441508 +0x0000007f8c13b7e0 0x40 at 0x441508 +0x0000007f8c13b830 0x40 at 0x441508 +0x0000007f8c13b880 0x40 at 0x441508 +0x0000007f8c13b8d0 0x40 at 0x441508 +0x0000007f8c13b920 0x40 at 0x441508 +0x0000007f8c13bb20 0x40 at 0x441508 +0x0000007f8c13bb70 0x40 at 0x441508 +0x0000007f8c13bbc0 0x40 at 0x441508 +0x0000007f8c13bc10 0x40 at 0x441508 +0x0000007f8c13bc60 0x40 at 0x441508 +0x0000007f8c13bcb0 0x40 at 0x441508 +0x0000007f8c13bd00 0x40 at 0x441508 +0x0000007f8c13c2c0 0x40 at 0x441508 +0x0000007f8c13c600 0x40 at 0x441508 +0x0000007f8c13c6a0 0x40 at 0x441508 +0x0000007f8c13c790 0x40 at 0x441508 +0x0000007f8c13c800 0x40 at 0x441508 +0x0000007f8c13c850 0x40 at 0x441508 +0x0000007f8c13c8d0 0x40 at 0x441508 +0x0000007f8c13c920 0x40 at 0x441508 +0x0000007f8c13c970 0x40 at 0x441508 +0x0000007f8c13cba0 0x40 at 0x441508 +0x0000007f8c13cbf0 0x40 at 0x441508 +0x0000007f8c13cc90 0x40 at 0x441508 +0x0000007f8c13cce0 0x40 at 0x441508 +0x0000007f8c13ce00 0x40 at 0x441508 +0x0000007f8c13cf90 0x40 at 0x441508 +0x0000007f8c13cfe0 0x40 at 0x441508 +0x0000007f8c13d030 0x40 at 0x441508 +0x0000007f8c13d460 0x40 at 0x441508 +0x0000007f8c13d4b0 0x40 at 0x441508 +0x0000007f8c13d610 0x40 at 0x441508 +0x0000007f8c13d690 0x40 at 0x441508 +0x0000007f8c13d6e0 0x40 at 0x441508 +0x0000007f8c13d730 0x40 at 0x441508 +0x0000007f8c13d780 0x40 at 0x441508 +0x0000007f8c13d7d0 0x40 at 0x441508 +0x0000007f8c13d820 0x40 at 0x441508 +0x0000007f8c13d870 0x40 at 0x441508 +0x0000007f8c13d930 0x40 at 0x441508 +0x0000007f8c13da00 0x40 at 0x441508 +0x0000007f8c13da50 0x40 at 0x441508 +0x0000007f8c13dbb0 0x40 at 0x441508 +0x0000007f8c13dc30 0x40 at 0x441508 +0x0000007f8c13dc80 0x40 at 0x441508 +0x0000007f8c13dcd0 0x40 at 0x441508 +0x0000007f8c13dd20 0x40 at 0x441508 +0x0000007f8c13dd70 0x40 at 0x441508 +0x0000007f8c13dde0 0x40 at 0x441508 +0x0000007f8c13de30 0x40 at 0x441508 +0x0000007f8c13ded0 0x40 at 0x441508 +0x0000007f8c13df20 0x40 at 0x441508 +0x0000007f8c13df70 0x40 at 0x441508 +0x0000007f8c13dfc0 0x40 at 0x441508 +0x0000007f8c13e0b0 0x40 at 0x441508 +0x0000007f8c13e1f0 0x40 at 0x441508 +0x0000007f8c13e240 0x40 at 0x441508 +0x0000007f8c13e3a0 0x40 at 0x441508 +0x0000007f8c13e3f0 0x40 at 0x441508 +0x0000007f8c13e440 0x40 at 0x441508 +0x0000007f8c13e490 0x40 at 0x441508 +0x0000007f8c13e500 0x40 at 0x441508 +0x0000007f8c13e590 0x40 at 0x441508 +0x0000007f8c13e5e0 0x40 at 0x441508 +0x0000007f8c13e630 0x40 at 0x441508 +0x0000007f8c13e720 0x40 at 0x441508 +0x0000007f8c13e770 0x40 at 0x441508 +0x0000007f8c13e7c0 0x40 at 0x441508 +0x0000007f8c13e950 0x40 at 0x441508 +0x0000007f8c13e9a0 0x40 at 0x441508 +0x0000007f8c13e9f0 0x40 at 0x441508 +0x0000007f8c13ea40 0x40 at 0x441508 +0x0000007f8c13ea90 0x40 at 0x441508 +0x0000007f8c13eb80 0x40 at 0x441508 +0x0000007f8c13ebd0 0x40 at 0x441508 +0x0000007f8c13ec20 0x40 at 0x441508 +0x0000007f8c13ec70 0x40 at 0x441508 +0x0000007f8c13ecc0 0x40 at 0x441508 +0x0000007f8c13ed90 0x40 at 0x441508 +0x0000007f8c13ee80 0x40 at 0x441508 +0x0000007f8c13eed0 0x40 at 0x441508 +0x0000007f8c13f0b0 0x40 at 0x441508 +0x0000007f8c13f100 0x40 at 0x441508 +0x0000007f8c13f150 0x40 at 0x441508 +0x0000007f8c13f240 0x40 at 0x441508 +0x0000007f8c13f290 0x40 at 0x441508 +0x0000007f8c13f300 0x40 at 0x441508 +0x0000007f8c13f400 0x40 at 0x441508 +0x0000007f8c13f450 0x40 at 0x441508 +0x0000007f8c13f4a0 0x40 at 0x441508 +0x0000007f8c13f540 0x40 at 0x441508 +0x0000007f8c13f5e0 0x40 at 0x441508 +0x0000007f8c13f680 0x40 at 0x441508 +0x0000007f8c13f6d0 0x40 at 0x441508 +0x0000007f8c13f770 0x40 at 0x441508 +0x0000007f8c13f9f0 0x40 at 0x441508 +0x0000007f8c13fd90 0x40 at 0x441508 +0x0000007f8c13fe30 0x40 at 0x441508 +0x0000007f8c13fed0 0x40 at 0x441508 +0x0000007f8c13ff20 0x40 at 0x441508 +0x0000007f8c140010 0x40 at 0x441508 +0x0000007f8c1401f0 0x40 at 0x441508 +0x0000007f8c140240 0x40 at 0x441508 +0x0000007f8c1402c0 0x40 at 0x441508 +0x0000007f8c140310 0x40 at 0x441508 +0x0000007f8c140a20 0x40 at 0x441508 +0x0000007f8c144a70 0x40 at 0x441508 +0x0000007f8c144ac0 0x40 at 0x441508 +0x0000007f8c144b50 0x40 at 0x441508 +0x0000007f8c144ba0 0x40 at 0x441508 +0x0000007f8c144bf0 0x40 at 0x441508 +0x0000007f8c14d620 0x85b0 at 0x7fa58be21c +0x0000007f94000b20 0x16e8 at 0x7fa57a9a18 +0x0000007f94002210 0x10 at 0x7fa57cd508 +0x0000007f94002230 0x4001 at 0x7fa57a9a58 +0x0000007f94006240 0x100 at 0x7fa57a9a6c +0x0000007f980ad010 0x27800 at 0x40decc diff --git a/include/ambarella/adc.h b/include/ambarella/adc.h new file mode 100644 index 0000000..80d1c66 --- /dev/null +++ b/include/ambarella/adc.h @@ -0,0 +1,146 @@ +/** + * adc.h + * + * Author: Roy Su <qiangsu@ambarella.com> + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBA_ADC_H__ +#define __AMBA_ADC_H__ + +/* ADC partition memory layout + * + * +-------------------------------------------------------------------------+ + * | ADC | adc_node | | adc_node | | + * | |----------| iso config |----------| tone_curve |...rgb2yuv...le... + * | hdr | next | | next | | + * +-------------------------------------------------------------------------+ + * | ^ | ^ ...... + * |__________________| |__________________| + * + */ + +/* add for smart 3a params in adc partition */ +#define ADCFW_IMG_MAGIC (0x41444346) /* 'A' 'D' 'C' 'F' */ + +/* rotation_mode */ +enum { + ROTATE_CW_0 = 0, + ROTATE_CW_90 = 1, + ROTATE_CW_180 = 2, + ROTATE_CW_270 = 3, +}; + +/* streaming mode */ +enum { + VIDEO_MODE_1080P = 0, + VIDEO_MODE_720P = 1, + VIDEO_MODE_480P = 2, +}; + +/* encode type */ +enum { + VIDEO_CODEC_NONE = 0, + VIDEO_CODEC_H264 = 1, + VIDEO_CODEC_H265 = 2, + VIDEO_CODEC_MJPEG = 3, +}; + +/* idspcfg index type */ +enum idspcfg_idx_mode { + IDSP_CFG_IDX_NORMAL = 0, + IDSP_CFG_IDX_NIGHT = 1, /* night mode */ + IDSP_CFG_IDX_BRIGHT = 2, +}; + +#define LAST_NODE_OFFSET (0xFFFFFFFF) +struct adc_node { + unsigned int pf_id; + unsigned int bin_size; + unsigned int next_offset; +}__attribute__((packed)); + +struct smart3a_file_info { /* 4 + (4 * 5) + 6 + 2 = 32 */ + unsigned int offset; + /* AWB */ + unsigned int r_gain; + unsigned int b_gain; + /* AE */ + unsigned int d_gain; + unsigned int shutter; + unsigned int agc; + /* Sensor 3 Shutter Register */ + unsigned char para0; + unsigned char para1; + unsigned char para2; + /* Sensor 2 AGC Register */ + unsigned char para3; + unsigned char para4; + unsigned char para5; + + unsigned char rev[2]; +}__attribute__((packed)); + +struct params_info { /* (4 * 1) + (5 * 4) + (5 * 4) + 32 + 2 + 18= 96 */ + unsigned char enable_audio; + unsigned char enable_fastosd; + unsigned char enable_ldc; + unsigned char rotation_mode; + + unsigned int stream0_enable; + unsigned int stream0_resolution; + unsigned int stream0_fmt; + unsigned int stream0_fps; + unsigned int stream0_bitrate; + + unsigned int stream1_enable; + unsigned int stream1_resolution; + unsigned int stream1_fmt; + unsigned int stream1_fps; + unsigned int stream1_bitrate; + + char fastosd_string[32]; + unsigned char enable_vca; //linux + unsigned char vca_frame_num; //linux + unsigned char record_sec; + unsigned char rtos_vca_enable; //rtos + unsigned char rtos_vca_frame_num; //rtos + unsigned char reserved[15]; +}__attribute__((packed)); + +struct adcfw_header { /* 4 + 4 + 2 + 2 + 20 + (32 * 5) + 96 = 288 */ + unsigned int magic; + unsigned int fw_size; /* totally fw size including the header */ + unsigned short smart3a_num; + unsigned short smart3a_size; + unsigned int adc_hdr_size; + unsigned char reserved[16]; + struct smart3a_file_info smart3a[5]; + struct params_info params_in_amboot; +}__attribute__((packed)); + +#endif diff --git a/include/ambarella/amba_bpi_defines.h b/include/ambarella/amba_bpi_defines.h new file mode 100644 index 0000000..fc0fd9d --- /dev/null +++ b/include/ambarella/amba_bpi_defines.h @@ -0,0 +1,108 @@ +/* + * amba_bpi_defines.h + * + * Histroy: + * 2019-06-14 [Cheng-Yan Li] Created file + * + * Copyright (c) 2019 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef _AMBA_BPI_DEFINES_H_ +#define _AMBA_BPI_DEFINES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + INVALID_CMD = 0, + + /* amba's chip to MCU. */ + AMB_CMD_TO_MCU_BASE = 0x10, + + /* send CMD. */ + AMB_CMD_STREAM_START = 0x10, + AMB_CMD_STREAM_STOP = 0x11, + + /* send cmd + payload. */ + AMB_CMD_DATA = 0x20, + AMB_CMD_VCA_RESULT = 0x21, + AMB_CMD_SAVE_INFO = 0x22, + AMB_CMD_VERSION = 0x23, + AMB_CMD_UPGRADE_STATUS = 0x24, //indicate the status of upgrading + + /* send cmd and receive feedback. */ + AMB_CMD_REQ_CFG = 0x30, // config + AMB_CMD_REQ_LIGHT_VAL = 0x31, // lux from light sensor + AMB_CMD_REQ_CRC_VAL = 0x32, // request whether append CRC to data + AMB_CMD_REQ_INFO = 0x33, // query batch info + + + AMB_CMD_TO_MCU_END = 0x3F, //AMB_CMD_TO_MCU_BASE + + /* MCU to amba's chip. */ + AMB_CMD_FROM_MCU_BASE = 0x40, + AMB_CMD_FORCE_STOP_STREAM = 0x40, + AMB_CMD_POWER_OFF = 0x41, + AMB_CMD_UPGRADE_DATA = 0x42, //transfer data for upgrading + AMB_CMD_STOP_UPGRADE = 0x43, //cancel the upgrading procedure + + AMB_CMD_FROM_MCU_END = 0x6F, //AMB_CMD_FROM_MCU_BASE + + /* DEBUG cmd. */ + AMB_CMD_DEBUG_BASE = 0xE0, + AMB_CMD_DEBUG_TIME = 0xE0, + + AMB_CMD_DEBUG_END = 0xFF, + +} AMB_MCU_CMD_LIST; + +/* sync with work mode definition of mcu side */ +typedef enum { + INVALID_WORK_MODE = 0, + AMB_STREAM_MODE = 1, + AMB_RECORD_MODE = 2, + AMB_QUERY_VERSION_MODE = 3, + AMB_UPGRADE_MODE = 4, +} AMB_BPI_WORK_MODE; + +typedef enum { + AMB_VCA_NONE = 0, + AMB_VCA_VEHICLE = 0x01, + AMB_VCA_PERSON = 0x02, + AMB_VCA_PET = 0x03, + + /* Add more VCA result here */ + + AMB_VCA_UNKNOWN = 0xFF, +} AMB_BPI_VCA_RESULT; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/amba_crypto.h b/include/ambarella/amba_crypto.h new file mode 100644 index 0000000..b8d76ef --- /dev/null +++ b/include/ambarella/amba_crypto.h @@ -0,0 +1,93 @@ + +/* + * amba_crypto.h + * + * History: + * 2011/05/03 - [Jian Tang] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBA_CRYPTO_H__ +#define __AMBA_CRYPTO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <linux/ioctl.h> + +#define AMBA_CRYPTO_MAGIC 'c' + +/* + * ambarella crypto APIs - 'c' + */ +enum { + IOC_CRYPTO_BASE_NUM = 0, + IOC_CRYPTO_SET_ALGO, + IOC_CRYPTO_SET_KEY, + IOC_CRYPTO_ENCRYPTE, + IOC_CRYPTO_DECRYPTE, + IOC_CRYPTO_SHA, + IOC_CRYPTO_MD5, +}; + +#define AMBA_IOC_CRYPTO_SET_ALGO _IOW(AMBA_CRYPTO_MAGIC, IOC_CRYPTO_SET_ALGO, struct amba_crypto_algo_s *) +#define AMBA_IOC_CRYPTO_SET_KEY _IOW(AMBA_CRYPTO_MAGIC, IOC_CRYPTO_SET_KEY, struct amba_crypto_key_s *) +#define AMBA_IOC_CRYPTO_ENCRYPTE _IOWR(AMBA_CRYPTO_MAGIC, IOC_CRYPTO_ENCRYPTE, struct amba_crypto_info_s *) +#define AMBA_IOC_CRYPTO_DECRYPTE _IOWR(AMBA_CRYPTO_MAGIC, IOC_CRYPTO_DECRYPTE, struct amba_crypto_info_s *) +#define AMBA_IOC_CRYPTO_SHA _IOWR(AMBA_CRYPTO_MAGIC, IOC_CRYPTO_SHA, struct amba_crypto_sha_md5_s *) +#define AMBA_IOC_CRYPTO_MD5 _IOWR(AMBA_CRYPTO_MAGIC, IOC_CRYPTO_MD5, struct amba_crypto_sha_md5_s *) + +#define AMBA_CRYPTO_ALGO_NAME_LEN (32) + +typedef struct amba_crypto_algo_s { + char cipher_algo[AMBA_CRYPTO_ALGO_NAME_LEN]; + char default_algo[AMBA_CRYPTO_ALGO_NAME_LEN]; +} amba_crypto_algo_t; + +typedef struct amba_crypto_key_s { + u8 * key; + u32 key_len; +} amba_crypto_key_t; + +typedef struct amba_crypto_info_s { + u8 * text; + u32 total_bytes; +} amba_crypto_info_t; + +typedef struct amba_crypto_sha_md5_s { + u8 * in; + u32 total_bytes; + u8 * out; +} amba_crypto_sha_md5_t; + +#ifdef __cplusplus +} +#endif + +#endif // __AMBA_CRYPTO_H__ + diff --git a/include/ambarella/amba_debug.h b/include/ambarella/amba_debug.h new file mode 100644 index 0000000..d17a7d0 --- /dev/null +++ b/include/ambarella/amba_debug.h @@ -0,0 +1,57 @@ +/* + * amba_debug.h + * + * History: + * 2008/04/10 - [Anthony Ginger] Create + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBA_DEBUG_H +#define __AMBA_DEBUG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define AMBA_DEBUG_IOC_MAGIC 'd' + +#define AMBA_DEBUG_IOC_GET_DEBUG_FLAG _IOR(AMBA_DEBUG_IOC_MAGIC, 1, int *) +#define AMBA_DEBUG_IOC_SET_DEBUG_FLAG _IOW(AMBA_DEBUG_IOC_MAGIC, 1, int *) + +struct amba_vin_test_gpio { + u32 id; + u32 data; +}; +#define AMBA_DEBUG_IOC_GET_GPIO _IOR(AMBA_DEBUG_IOC_MAGIC, 203, struct amba_vin_test_gpio *) +#define AMBA_DEBUG_IOC_SET_GPIO _IOW(AMBA_DEBUG_IOC_MAGIC, 203, struct amba_vin_test_gpio *) + +#ifdef __cplusplus +} +#endif + +#endif //AMBA_DEBUG_IOC_MAGIC + diff --git a/include/ambarella/amba_defines.h b/include/ambarella/amba_defines.h new file mode 100644 index 0000000..0b72b44 --- /dev/null +++ b/include/ambarella/amba_defines.h @@ -0,0 +1,62 @@ +/* + * amba_defines.h + * + * Histroy: + * 2012-12-12 [Louis] Created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef _AMBA_DEFINES_H_ +#define _AMBA_DEFINES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define AMBA_READ_FILE(file, buf, size) do { \ + if (read((file), (buf), (size)) < 0) { \ + printf("read error.\n"); \ + } \ + } while (0) + +#define AMBA_WRITE_FILE(file, buf, size) do { \ + if (write((file), (buf), (size)) < 0) { \ + printf("write error.\n"); \ + } \ + } while (0) + +#define AMBA_FREAD_FILE(buf, bytes, size, fp) do { \ + if (fread((buf), (bytes), (size), (fp)) < size) { \ + printf("fread error.\n"); \ + } \ + } while (0) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/amba_eis.h b/include/ambarella/amba_eis.h new file mode 100644 index 0000000..6e00fb4 --- /dev/null +++ b/include/ambarella/amba_eis.h @@ -0,0 +1,149 @@ + +/* + * amba_eis.h + * + * History: + * 2013/09/25 - [Louis Sun] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBA_EIS_H__ +#define __AMBA_EIS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct gyro_info_s { + u8 gyro_id; // gyro sensor id + + u8 gyro_pwr_gpio; // GPIO number controls gyro sensor power + u8 gyro_hps_gpio; // GPIO number controls gyro sensor hps + u8 gyro_int_gpio; // GPIO number connect to gyro sensor interrupt pin + u8 gyro_x_chan; // gyro sensor x axis channel + u8 gyro_y_chan; // gyro sensor y axis channel + u8 gyro_z_chan; // gyro sensor z axis channel + u8 gyro_t_chan; // gyro sensor t axis channel + u8 gyro_x_reg; // gyro sensor x axis reg + u8 gyro_y_reg; // gyro sensor y axis reg + u8 gyro_z_reg; // gyro sensor z axis reg + s8 gyro_x_polar; // gyro sensor x polarity + s8 gyro_y_polar; // gyro sensor y polarity + s8 gyro_z_polar; // gyro sensor z polarity + u8 vol_div_num; // numerator of voltage divider + u8 vol_div_den; // denominator of voltage divider + + u8 sensor_interface; // gyro sensor interface + u8 sensor_axis; // gyro sensor axis + u8 max_rms_noise; // gyro sensor rms noise level + u8 adc_resolution; // gyro internal adc resolution, unit in bit(s) + s8 phs_dly_in_ms; // gyro sensor phase delay, unit in ms + u8 reserved; + u16 sampling_rate; // digital gyro internal sampling rate, unit in samples / sec + u16 max_sampling_rate; // max digital gyro internal sampling rate, unit in samples / sec + u16 max_bias; // max gyro sensor bias + u16 min_bias; // min gyro sensor bias + u16 max_sense; // max gyro sensor sensitivity + u16 min_sense; // min gyro sensor sensitivity + u16 start_up_time; // gyro sensor start-up time + u16 full_scale_range; // gyro full scale range + u16 max_sclk; // max serial clock for digital interface, unit in 100khz +} gyro_info_t; + +typedef struct gyro_data_s{ + int sample_id; //incremental id of gyro data sample + s16 xg; //agular velocity on Axis-X (Gyro ) + s16 yg; //agular velocity on Axis-Y (Gyro ) + s16 zg; //agular velocity on Axis-Z (Gyro ) + s16 xa; //acceleration on Axis-X (Accelerometer) + s16 ya; //acceleration on Axis-Y (Accelerometer) + s16 za; //acceleration on Axis-Z (Accelerometer) + s16 xm; //magnetization on Axis-X (Magnetometer) + s16 ym; //magnetization on Axis-Y (Magnetometer) + s16 zm; //magnetization on Axis-Z (Magnetometer) +} gyro_data_t; + +typedef struct gyro_dev_info_s { + u32 accel_full_scale_range; + u32 accel_lsb; + u32 gyro_full_scale_range; + u32 gyro_lsb; + u32 gyro_sample_rate_in_hz; +} gyro_dev_info_t; + + +void gyro_get_info(gyro_info_t *); +typedef void (*GYRO_EIS_CALLBACK)(gyro_data_t *, void * arg); +void gyro_register_eis_callback(GYRO_EIS_CALLBACK cb, void *arg); +void gyro_unregister_eis_callback(void); +void gyro_dev_get_info(gyro_dev_info_t *); + +//this eis driver is for "EIS by Cortex with Queue", it enqueues Gyro data, and data filtering and EIS calculation is done on ARM + +#define EIS_IOC_MAGIC 'e' + + +enum EIS_IOC_ENUM { + IOC_EIS_GET_INFO = 0, + IOC_EIS_START_STAT = 1, + IOC_EIS_STOP_STAT = 2, + IOC_EIS_GET_STAT = 3, +}; + + + +#define GYRO_DATA_ENTRY_MAX_NUM 256 +//by design, eis stat read out is once per frame. +//each time, eis stat read out should be no more than GYRO_DATA_ENTRY_MAX_NUM +typedef struct amba_eis_stat_s{ + int gyro_data_count; + int discard_flag; + gyro_data_t gyro_data[GYRO_DATA_ENTRY_MAX_NUM]; +}amba_eis_stat_t; + +typedef struct amba_eis_info_s{ + int version; + int type; + int gyro_queue_max_depth; + int status; + gyro_dev_info_t gyro_dev_info; +}amba_eis_info_t; + + +//IOCTLs for driver EIS +#define AMBA_IOC_EIS_START_STAT _IO(EIS_IOC_MAGIC, IOC_EIS_START_STAT) +#define AMBA_IOC_EIS_STOP_STAT _IO(EIS_IOC_MAGIC, IOC_EIS_STOP_STAT) +#define AMBA_IOC_EIS_GET_STAT _IOR(EIS_IOC_MAGIC, IOC_EIS_GET_STAT, struct amba_eis_stat_s *) +#define AMBA_IOC_EIS_GET_INFO _IOR(EIS_IOC_MAGIC, IOC_EIS_GET_INFO, struct amba_eis_info_s *) + +#ifdef __cplusplus +} +#endif + +#endif // __AMBA_EIS_H__ + + diff --git a/include/ambarella/amba_fdet.h b/include/ambarella/amba_fdet.h new file mode 100644 index 0000000..8ac098e --- /dev/null +++ b/include/ambarella/amba_fdet.h @@ -0,0 +1,96 @@ +/* + * amba_fdet.h + * + * History: + * 2013/03/12 - [Cao Rongrong] Created file + * 2013/12/12 - [Jian Tang] Modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBA_FDET_H__ +#define __AMBA_FDET_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +enum fdet_ioctl_id +{ + FDET_IOCTL_START = 0, + FDET_IOCTL_STOP, + FDET_IOCTL_GET_RESULT = 3, + FDET_IOCTL_SET_MMAP_TYPE, + FDET_IOCTL_SET_CONFIGURATION, + FDET_IOCTL_TRACK_FACE, +}; + +enum fdet_mmap_type { + FDET_MMAP_TYPE_ORIG_BUFFER = 0, + FDET_MMAP_TYPE_TMP_BUFFER, + FDET_MMAP_TYPE_CLASSIFIER_BINARY, +}; + +enum fdet_mode { + FDET_MODE_VIDEO = 0, + FDET_MODE_STILL, +}; + +enum fdet_filtering_policy { + FDET_POLICY_WAIT_FS_COMPLETE = (1 << 0), + FDET_POLICY_DISABLE_TS = (1 << 1), + FDET_POLICY_DEBUG = (1 << 2), + FDET_POLICY_MEASURE_TIME = (1 << 3), +}; + +enum fdet_result_type { + FDET_RESULT_TYPE_FS = 0, + FDET_RESULT_TYPE_TS, +}; + +struct fdet_configuration { + int input_width; + int input_height; + int input_pitch; + int input_source; + unsigned int input_offset; + enum fdet_mode input_mode; + + enum fdet_filtering_policy policy; +}; + +struct fdet_face { + unsigned short x; + unsigned short y; + unsigned short size; + enum fdet_result_type type; +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/amba_lens_interface.h b/include/ambarella/amba_lens_interface.h new file mode 100644 index 0000000..b6faf1b --- /dev/null +++ b/include/ambarella/amba_lens_interface.h @@ -0,0 +1,125 @@ +/* + * amba_lens_interface.h + * + * History: + * 2014/10/10 - [Peter Jiao] Mod base on amba_piris.h + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBA_LENS_INTERFACE_H__ +#define __AMBA_LENS_INTERFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +enum P_IRIS_WORK_STATE { + P_IRIS_WORK_STATE_NOT_INIT = 0, //uninitialized + P_IRIS_WORK_STATE_PREPARING = 1, //doing init + P_IRIS_WORK_STATE_READY = 2, //init done , ready to adjust p-iris (normal working), or run stop (back to ready) + P_IRIS_WORK_STATE_RUNNING = 3, //running. +}; + +#define P_IRIS_IOC_MAGIC 'p' + +enum P_IRIS_IOC_ENUM { + IOC_P_IRIS_SET_POS = 0, + IOC_P_IRIS_RESET = 1, + IOC_P_IRIS_MOVE_STEPS = 2, + IOC_P_IRIS_GET_POS = 3, + IOC_P_IRIS_GET_STATE = 4, + IOC_P_IRIS_CONFIG = 5, +}; + +#define AMBA_IOC_P_IRIS_SET_POS _IOW(P_IRIS_IOC_MAGIC, IOC_P_IRIS_SET_POS, int) +#define AMBA_IOC_P_IRIS_RESET _IOW(P_IRIS_IOC_MAGIC, IOC_P_IRIS_RESET, int) +#define AMBA_IOC_P_IRIS_MOVE_STEPS _IOW(P_IRIS_IOC_MAGIC, IOC_P_IRIS_MOVE_STEPS, int) +#define AMBA_IOC_P_IRIS_GET_POS _IOR(P_IRIS_IOC_MAGIC, IOC_P_IRIS_GET_POS, int *) +#define AMBA_IOC_P_IRIS_GET_STATE _IOR(P_IRIS_IOC_MAGIC, IOC_P_IRIS_GET_STATE, int *) +#define AMBA_IOC_P_IRIS_CONFIG _IOR(P_IRIS_IOC_MAGIC, IOC_P_IRIS_CONFIG, int) + +#define P_IRIS_CONTROLLER_MAX_GPIO_NUM 3 +typedef struct amba_p_iris_cfg_s{ + int gpio_id[P_IRIS_CONTROLLER_MAX_GPIO_NUM]; //gpio_id[0]= IN1, gpio_id[1]=IN2, gpio_id[2]=EN + int gpio_val; //bit0 is IN1, bit1 is IN2 + int timer_period; //in ms + int max_mechanical; + int min_mechanical ; + int max_optical; + int min_optical; +}amba_p_iris_cfg_t; + + +#define MFZ_IOC_MAGIC 'p' + +enum MFZ_IOC_ENUM { + IOC_MFZ_GET_STATUS = 0, + IOC_MFZ_SET_ENABLE = 1, + IOC_MFZ_ZOOM_SET = 2, + IOC_MFZ_FOCUS_SET = 3, + IOC_MFZ_IRIS_SET = 4, + IOC_MFZ_ZOOM_STOP = 5, + IOC_MFZ_FOCUS_STOP = 6, +}; + +#define AMBA_IOC_MFZ_GET_STATUS _IOW(MFZ_IOC_MAGIC, IOC_MFZ_GET_STATUS, u32 *) +#define AMBA_IOC_MFZ_SET_ENABLE _IOW(MFZ_IOC_MAGIC, IOC_MFZ_SET_ENABLE, u32) +#define AMBA_IOC_MFZ_ZOOM_SET _IOR(MFZ_IOC_MAGIC, IOC_MFZ_ZOOM_SET, u32) +#define AMBA_IOC_MFZ_FOCUS_SET _IOR(MFZ_IOC_MAGIC, IOC_MFZ_FOCUS_SET, u32) +#define AMBA_IOC_MFZ_IRIS_SET _IOR(MFZ_IOC_MAGIC, IOC_MFZ_IRIS_SET, u32) +#define AMBA_IOC_MFZ_ZOOM_STOP _IOW(MFZ_IOC_MAGIC, IOC_MFZ_ZOOM_STOP, u32 *) +#define AMBA_IOC_MFZ_FOCUS_STOP _IOW(MFZ_IOC_MAGIC, IOC_MFZ_FOCUS_STOP, u32 *) + +#define MFZ_COUNT_SHIFT 16 +#define MFZ_COUNT_MASK 0xFFF +#define MFZ_DOCMD_SHIFT 28 +#define MFZ_DOCMD_MASK 0xF +#define MFZ_STATUS_MASK 0xFF +#define MFZ_STATUS_MASK_ALL 0xFFFFFF +#define MFZ_STEP_MASK 0xFFFF +#define MFZ_EXCEPT_FLAG 0xFFFF8000 +#define MFZ_ZSTEP_SHIFT 48 +#define MFZ_FSTEP_SHIFT 32 +#define MFZ_TDN_SHIFT 24 +#define MFZ_IRIS_SHIFT 16 +#define MFZ_ZOOM_SHIFT 8 +#define MFZ_ENABLE_MASK 0xF +#define MFZ_CONFIG_MASK 0xF0 +#define MFZ_ENABLE 0x11 +#define MFZ_DISABLE 0x10 +#define MFZ_DAY 0x10 +#define MFZ_NIGHT 0x11 + +#define FULL_SHIFT_STEP 8 + +#ifdef __cplusplus +} +#endif + +#endif // __AMBA_LENS_INTERFACE_H__ + diff --git a/include/ambarella/amba_netlink.h b/include/ambarella/amba_netlink.h new file mode 100644 index 0000000..6ab86f1 --- /dev/null +++ b/include/ambarella/amba_netlink.h @@ -0,0 +1,232 @@ +/* + * amba_netlink.h + * + * History: + * 2018/07/06 - [Zhaoyang Chen] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef ___AMBA_NL_H__ +#define ___AMBA_NL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define AMBA_NL_MAX_MSG_LEN (1024) + +enum AMBA_NL_OBJ { + AMBA_NL_OBJ_IMAGE = 0x00, + AMBA_NL_OBJ_SYS = 0x01, + AMBA_NL_OBJ_VP = 0x02, + AMBA_NL_OBJ_ERROR = 0x03, + AMBA_NL_OBJ_MAX_NUM = 0x04, +}; + +enum AMBA_NL_MODULE { + AMBA_NL_MODULE_DSP = 0x00, + AMBA_NL_MODULE_VIN = 0x01, + AMBA_NL_MODULE_IAV = 0x02, + AMBA_NL_MODULE_IMG = 0x03, + AMBA_NL_DEFINED_MODULE_NUM = 0x04, /* Pre-defined module num */ + AMBA_NL_MODULE_MAX_NUM = 0xFF, /* Total supported module num */ + + AMBA_NL_MODULE_FIRST = AMBA_NL_MODULE_DSP, + AMBA_NL_MODULE_CUSTOM_FIRST = AMBA_NL_DEFINED_MODULE_NUM, + AMBA_NL_MODULE_LAST = AMBA_NL_MODULE_MAX_NUM, + AMBA_NL_MODULE_INVALID = AMBA_NL_MODULE_MAX_NUM, +}; + +enum AMBA_NL_PORT { + AMBA_NL_PORT_BASE = 24, + AMBA_NL_PORT_IMAGE = AMBA_NL_PORT_BASE + AMBA_NL_OBJ_IMAGE, + AMBA_NL_PORT_SYS = AMBA_NL_PORT_BASE + AMBA_NL_OBJ_SYS, + AMBA_NL_PORT_VP = AMBA_NL_PORT_BASE + AMBA_NL_OBJ_VP, + AMBA_NL_PORT_ERROR = AMBA_NL_PORT_BASE + AMBA_NL_OBJ_ERROR, +}; + +enum AMBA_NL_MSG_IMAGE { + /* 0x18020000 */ + AMBA_NL_MSG_IMG_START_AAA = ((AMBA_NL_PORT_IMAGE) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0000), + /* 0x18020001 */ + AMBA_NL_MSG_IMG_STOP_AAA = ((AMBA_NL_PORT_IMAGE) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0001), + /* 0x18020002 */ + AMBA_NL_MSG_IMG_PREPARE_AAA = ((AMBA_NL_PORT_IMAGE) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0002), + /* 0x18020003 */ + AMBA_NL_MSG_IMG_DPTZ_MAIN = ((AMBA_NL_PORT_IMAGE) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0003), + /* 0x18020004 */ + AMBA_NL_MSG_IMG_WARP = ((AMBA_NL_PORT_IMAGE) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0004), + + AMBA_NL_MSG_IMG_LAST = ((AMBA_NL_PORT_IMAGE) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0005), + AMBA_NL_MSG_IMG_FIRST = AMBA_NL_MSG_IMG_START_AAA, +}; + +enum AMBA_NL_MSG_SYS { + /* 0x19020000 */ + AMBA_NL_MSG_SYS_THAW_DONE = ((AMBA_NL_PORT_SYS) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0000), + /* 0x19020001 */ + AMBA_NL_MSG_SYS_IDLE = ((AMBA_NL_PORT_SYS) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0001), + /* 0x19020002 */ + AMBA_NL_MSG_SYS_PREVIEW = ((AMBA_NL_PORT_SYS) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0002), + /* 0x19020003 */ + AMBA_NL_MSG_SYS_ENCODE = ((AMBA_NL_PORT_SYS) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0003), + + AMBA_NL_MSG_SYS_LAST = ((AMBA_NL_PORT_SYS) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0004), + AMBA_NL_MSG_SYS_FIRST = AMBA_NL_MSG_SYS_THAW_DONE, +}; + +enum AMBA_NL_MSG_VP { + /* 0x1A020000 */ + AMBA_NL_MSG_VP_START_INFO = ((AMBA_NL_PORT_VP) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0000), + + AMBA_NL_MSG_VP_LAST = ((AMBA_NL_PORT_VP) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0001), + AMBA_NL_MSG_VP_FIRST = AMBA_NL_MSG_VP_START_INFO, +}; + +enum AMBA_NL_MSG_ERR_DSP { + /* 0x1B000000: Failed to issue DSP cmd */ + AMBA_NL_MSG_ERR_DSP_ISSUE_CMD = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_DSP) << 16 | 0x0000), + /* 0x1B000001: DSP cmd num exceeds the limit */ + AMBA_NL_MSG_ERR_DSP_CMD_EXCEED = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_DSP) << 16 | 0x0001), + /* 0x1B000002: Invalide DSP cmd code */ + AMBA_NL_MSG_ERR_DSP_CMD_CODE = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_DSP) << 16 | 0x0002), + /* 0x1B000003: DSP triggers assertion */ + AMBA_NL_MSG_ERR_DSP_ASSERTION = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_DSP) << 16 | 0x0003), + + AMBA_NL_MSG_ERR_DSP_LAST = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_DSP) << 16 | 0x0004), + AMBA_NL_MSG_ERR_DSP_FIRST = AMBA_NL_MSG_ERR_DSP_ISSUE_CMD, +}; + +enum AMBA_NL_MSG_ERR_VIN { + /* 0x1B010000: Failed to apply VIN shutter/gain config */ + AMBA_NL_MSG_ERR_VIN_APPLY_CFG = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_VIN) << 16 | 0x0000), + /* 0x1B010001: Failed to switch context for current vin src */ + AMBA_NL_MSG_ERR_VIN_SWITCH_CTX = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_VIN) << 16 | 0x0001), + + AMBA_NL_MSG_ERR_VIN_LAST = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_VIN) << 16 | 0x0002), + AMBA_NL_MSG_ERR_VIN_FIRST = AMBA_NL_MSG_ERR_VIN_APPLY_CFG, +}; + +enum AMBA_NL_MSG_ERR_IAV { + /* 0x1B020000: Vsync lost signal from DSP */ + AMBA_NL_MSG_ERR_IAV_VSYNC_LOST = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0000), + /* 0x1B020001: Failed to sync frame sync cmd */ + AMBA_NL_MSG_ERR_IAV_FRAME_SYNC = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0001), + /* 0x1B020002: Failed to sync stream sync cmd */ + AMBA_NL_MSG_ERR_IAV_STREAM_SYNC = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0002), + /* 0x1B020003: Invalid DSP msg code */ + AMBA_NL_MSG_ERR_IAV_MSG_CODE = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0003), + /* 0x1B020004: Invalid stream ID from DSP msg */ + AMBA_NL_MSG_ERR_IAV_STREAM_ID = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0004), + /* 0x1B020005: Invalid stream state from DSP msg */ + AMBA_NL_MSG_ERR_IAV_STREAM_STATE = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0005), + + AMBA_NL_MSG_ERR_IAV_LAST = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IAV) << 16 | 0x0006), + AMBA_NL_MSG_ERR_IAV_FIRST = AMBA_NL_MSG_ERR_IAV_VSYNC_LOST, +}; + +enum AMBA_NL_MSG_ERR_IMG { + /* 0x1B030000: Incorrect chan ID for the image statistics */ + AMBA_NL_MSG_ERR_IMG_CHAN_ID = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IMG) << 16 | 0x0000), + /* 0x1B030001: DSP overwrites unread image statistics */ + AMBA_NL_MSG_ERR_IMG_STATIS_OVERWRITE = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IMG) << 16 | 0x0001), + /* 0x1B030002: DSP sends out disordered image statistics */ + AMBA_NL_MSG_ERR_IMG_STATIS_DISORDER = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IMG) << 16 | 0x0002), + /* 0x1B030003: Invalid slice num in image statistics from DSP */ + AMBA_NL_MSG_ERR_IMG_STATIS_SLICE_NUM = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IMG) << 16 | 0x0003), + + AMBA_NL_MSG_ERR_IMG_LAST = ((AMBA_NL_PORT_ERROR) << 24 | (AMBA_NL_MODULE_IMG) << 16 | 0x0004), + AMBA_NL_MSG_ERR_IMG_FIRST = AMBA_NL_MSG_ERR_IMG_CHAN_ID, +}; + +#define AMBA_NL_GET_MSG_PORT(msg) (((msg) >> 24) & 0xFF) +#define AMBA_NL_GET_MSG_MODULE(msg) (((msg) >> 16) & 0xFF) +#define AMBA_NL_GET_MSG_CODE(msg) ((msg) & 0xFFFF) + +enum AMBA_NL_MSG_SESSION { + AMBA_NL_MSG_SESS_CONNECT = 0x00, + AMBA_NL_MSG_SESS_DISCONNECT = 0x01, + AMBA_NL_MSG_SESS_NUM = 0x02, + + AMBA_NL_MSG_SESS_FIRST = AMBA_NL_MSG_SESS_CONNECT, + AMBA_NL_MSG_SESS_LAST = AMBA_NL_MSG_SESS_NUM, +}; + +enum AMBA_NL_MSG_STATUS { + AMBA_NL_MSG_STATUS_SUCCESS = 0x00, + AMBA_NL_MSG_STATUS_FAIL = 0x01, + AMBA_NL_MSG_STATUS_NUM = 0x02, + + AMBA_NL_MSG_STATUS_FIRST = AMBA_NL_MSG_STATUS_SUCCESS, + AMBA_NL_MSG_STATUS_LAST = AMBA_NL_MSG_STATUS_NUM, +}; + +enum AMBA_NL_MSG_TYPE { + AMBA_NL_MSG_TYPE_SESSION = 0x00, + AMBA_NL_MSG_TYPE_NORMAL = 0x01, + AMBA_NL_MSG_TYPE_NUM = 0x02, + + AMBA_NL_MSG_TYPE_FIRST = AMBA_NL_MSG_TYPE_SESSION, + AMBA_NL_MSG_TYPE_LAST = AMBA_NL_MSG_TYPE_NUM, +}; + +enum AMBA_NL_MSG_DIR { + AMBA_NL_MSG_DIR_MSG = 0x00, + AMBA_NL_MSG_DIR_STATUS = 0x01, + AMBA_NL_MSG_DIR_NUM = 0x02, + + AMBA_NL_MSG_DIR_FIRST = AMBA_NL_MSG_DIR_MSG, + AMBA_NL_MSG_DIR_LAST = AMBA_NL_MSG_TYPE_NUM, +}; + +#define AMBA_NL_MSG_SIZE (512) +#define AMBA_NL_MSG_HEADER_SIZE (24) +#define AMBA_NL_MSG_PAYLOAD_SIZE (AMBA_NL_MSG_SIZE - AMBA_NL_MSG_HEADER_SIZE) + +struct amba_nl_msg_vsync_data { + u16 vinc_map; + u16 reserved[3]; +}; + +struct amba_nl_msg_data { + u32 src_pid; /* The pid for the sender, 0 means kernel */ + u32 dst_pid; /* The pid for the receiver, 0 means kernel */ + u32 msg; /* The msg code */ + u8 status; /* The status for the msg, if any */ + u8 port; /* The netlink port for the msg */ + u8 type; /* The msg type, session msg or normal msg */ + u8 dir; /* The original msg or the status for the msg */ + u64 hw_tick; /* The hw tick value from hw timer */ + u8 payload[AMBA_NL_MSG_PAYLOAD_SIZE]; +}; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/amba_usb.h b/include/ambarella/amba_usb.h new file mode 100644 index 0000000..f89fdef --- /dev/null +++ b/include/ambarella/amba_usb.h @@ -0,0 +1,138 @@ +/* + * amba_usb.h + * + * History: + * 2008/7/10 - [Cao Rongrong] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef TEST_USB_STREAM_H +#define TEST_USB_STREAM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define READ_SIZE 32768 +#define WRITE_SIZE 32768 +#define SIMPLE_CMD_SIZE 32 + +/* TOKEN */ +#define AMB_COMMAND_TOKEN 0x55434D44 +#define AMB_STATUS_TOKEN 0x55525350 + +#define USB_CMD_TRY_TO_CONN 0 +#define USB_CMD_RDY_TO_RCV 1 +#define USB_CMD_RCV_DATA 2 +#define USB_CMD_RDY_TO_SND 3 +#define USB_CMD_SND_DATA 4 +#define USB_CMD_SET_MODE 5 +#define USB_CMD_RECV_REQUEST 6 + + +#define AMB_RSP_SUCCESS 0 +#define AMB_RSP_FAILED 1 + +#define AMB_CMD_PARA_UP 0 +#define AMB_CMD_PARA_DOWN 1 +#define AMB_CMD_PARA_MEASURE_SPD 2 + +#define AMB_RSP_NO_CONN 0 +#define AMB_RSP_CONNECT 1 + +#define NR_PORT 32 +#define ALL_PORT 0xffff + +#define PORT_STATUS_CHANGE 0x55 +#define PORT_NO_CONNECT 0 +#define PORT_CONNECT 1 +#define PORT_FREE_ALL 2 + +#define REQUEST_HOST_CONNECT 0xaa +#define HOST_NO_CONNECT 0 +#define HOST_CONNECT 1 + +#define FLAG_LAST_TRANS 0x01 +#define FLAG_FORCE_FINISH 0x10 + +#define AMB_DATA_STREAM_MAGIC 'u' +#define AMB_DATA_STREAM_WR_RSP _IOW(AMB_DATA_STREAM_MAGIC, 1, struct amb_usb_rsp *) +#define AMB_DATA_STREAM_RD_CMD _IOR(AMB_DATA_STREAM_MAGIC, 1, struct amb_usb_cmd *) +#define AMB_DATA_STREAM_STATUS_CHANGE _IOW(AMB_DATA_STREAM_MAGIC, 2, struct amb_usb_notify *) + +struct amb_usb_cmd { + u32 signature; + u32 command; + u32 parameter[(SIMPLE_CMD_SIZE / sizeof(u32)) - 2]; +}; + +struct amb_usb_rsp { + u32 signature; + u32 response; + u32 parameter0; + u32 parameter1; +}; + +struct amb_usb_notify { + u16 bNotifyType; + u16 port_id; + u16 value; + u16 status; +}; + +struct amb_usb_head { + u32 port_id; + u32 size; + u32 flag1; + u32 flag2; +}; + +#define USB_PORT_IDLE 0x0 +#define USB_PORT_OPEN 0x1 +#define USB_PORT_CLOSED 0x2 + +#define USB_HEAD_SIZE sizeof(struct amb_usb_head) +struct amb_usb_buf { + struct amb_usb_head head; + char buffer[0]; +}; + +enum RX_FSM { + COMMAND_PHASE = 0, + RCV_FILENAME_PHASE, + RCV_DATA_PHASE, + SND_FILENAME_PHASE, + SND_DATA_PHASE, + MEASURE_SPEED_PHASE, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* end */ + diff --git a/include/ambarella/arch_v5/AmbaDSP_Img3astatistic.h b/include/ambarella/arch_v5/AmbaDSP_Img3astatistic.h new file mode 100644 index 0000000..40fbac8 --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_Img3astatistic.h @@ -0,0 +1,213 @@ +#ifndef IMG_3A_STATiSTIC_H +#define IMG_3A_STATiSTIC_H +#include "datatype.h" +//#include "AmbaDataType.h" + +#define AMBA_IK_CFA_HISTO_COUNT (64UL) +#define AMBA_IK_RGB_HISTO_COUNT (64UL) +#define AMBA_IK_HDR_HISTO_COUNT (128UL) + +#define AMBA_IK_3A_AWB_TILE_COLUMN_COUNT 32UL +#define AMBA_IK_3A_AWB_TILE_ROW_COUNT 32UL + +#define AMBA_IK_3A_AE_TILE_COLUMN_COUNT 12UL +#define AMBA_IK_3A_AE_TILE_ROW_COUNT 8UL + +#define AMBA_IK_3A_AF_TILE_COLUMN_COUNT 12UL +#define AMBA_IK_3A_AF_TILE_ROW_COUNT 8UL + +#define AMBA_IK_3A_SLICE_MAX_COUNT 4UL + + +typedef struct { + //awb + uint16 awb_tile_col_start; + uint16 awb_tile_row_start; + uint16 awb_tile_width; + uint16 awb_tile_height; + uint16 awb_tile_active_width; + uint16 awb_tile_active_height; + uint16 awb_rgb_shift; + uint16 awb_y_shift; + uint16 awb_min_max_shift; + + //ae + uint16 ae_tile_col_start; + uint16 ae_tile_row_start; + uint16 ae_tile_width; + uint16 ae_tile_height; + uint16 ae_y_shift; + uint16 ae_linear_y_shift; + uint16 ae_min_max_shift; + + //af + uint16 af_tile_col_start; + uint16 af_tile_row_start; + uint16 af_tile_width; + uint16 af_tile_height; + uint16 af_tile_active_width; + uint16 af_tile_active_height; + uint16 af_y_shift; + uint16 af_cfa_y_shift; + + // AWB tiles + uint8 awb_tile_num_col; + uint8 awb_tile_num_row; + // AE tiles + uint8 ae_tile_num_col; + uint8 ae_tile_num_row; + // AF tiles + uint8 af_tile_num_col; + uint8 af_tile_num_row; + + // Strip info + uint8 total_slices_x; + uint8 total_slices_y; + uint8 slice_index_x; + uint8 slice_index_y; + uint16 slice_width; + uint16 slice_height; + uint16 slice_start_x; + uint16 slice_start_y; + + // Exposure + uint16 exposure_index; + uint16 total_exposures; + + // Black levels + uint16 black_red; + uint16 black_green; + uint16 black_blue; + + uint32 raw_pic_seq_num; // sequence number of raw picture used in producing this block of AAA results + uint32 iso_config_tag; + + uint32 is_rgbir_aaa : 1; + uint32 chan_index : 3; + uint32 reserved : 28; + uint32 reserved1[10]; // max 128 bytes +}__attribute__((packed)) ik_3a_header_t; + +// cfa awb +typedef struct { + uint16 sum_r; + uint16 sum_g; + uint16 sum_b; + uint16 count_min; + uint16 count_max; +} __attribute__((packed)) ik_cfa_awb_t; +// cfa ae +typedef struct { + uint16 lin_y; + uint16 count_min; + uint16 count_max; +} __attribute__((packed)) ik_cfa_ae_t; +// cfa af +typedef struct { + uint16 sum_y; + uint16 sum_fv1; + uint16 sum_fv2; +} __attribute__((packed)) ik_cfa_af_t; +//cfa histogram +typedef struct { + uint32 his_bin_r[AMBA_IK_CFA_HISTO_COUNT]; + uint32 his_bin_g[AMBA_IK_CFA_HISTO_COUNT]; + uint32 his_bin_b[AMBA_IK_CFA_HISTO_COUNT]; + uint32 his_bin_y[AMBA_IK_CFA_HISTO_COUNT]; +} __attribute__((packed)) ik_cfa_histo_t; + +typedef struct { + uint16 sum_y; + uint16 sum_fv1; + uint16 sum_fv2; +} __attribute__((packed)) ik_pg_af_t; + +// rgb ae +typedef struct { + uint16 sum_y; +} __attribute__((packed)) ik_pg_ae_t; + +// rgb histo +typedef struct { + uint32 his_bin_y[AMBA_IK_RGB_HISTO_COUNT]; + uint32 his_bin_r[AMBA_IK_RGB_HISTO_COUNT]; + uint32 his_bin_g[AMBA_IK_RGB_HISTO_COUNT]; + uint32 his_bin_b[AMBA_IK_RGB_HISTO_COUNT]; +} __attribute__((packed)) ik_pg_histo_t; + +//cfa_aaa_stat_t +typedef struct { + ik_3a_header_t header; + uint16 frame_id; + ik_cfa_awb_t awb[AMBA_IK_3A_AWB_TILE_ROW_COUNT * AMBA_IK_3A_AWB_TILE_COLUMN_COUNT]; + ik_cfa_ae_t ae[AMBA_IK_3A_AE_TILE_ROW_COUNT * AMBA_IK_3A_AE_TILE_COLUMN_COUNT]; + ik_cfa_af_t af[AMBA_IK_3A_AF_TILE_ROW_COUNT * AMBA_IK_3A_AF_TILE_COLUMN_COUNT]; + ik_cfa_histo_t histogram; +} __attribute__((packed)) ik_cfa_3a_data_t; + +//pg_aaa_stat_t +typedef struct { + ik_3a_header_t header; + uint16 frame_id; + ik_pg_af_t af[AMBA_IK_3A_AF_TILE_ROW_COUNT * AMBA_IK_3A_AF_TILE_COLUMN_COUNT]; + ik_pg_ae_t ae[AMBA_IK_3A_AE_TILE_ROW_COUNT * AMBA_IK_3A_AE_TILE_COLUMN_COUNT]; + ik_pg_histo_t histogram; +} __attribute__((packed)) ik_pg_3a_data_t; + +typedef struct { + uint8 vin_stats_type; // 0: main; 1: hdr + uint8 chan_index : 3; + uint8 is_rgbir : 1; + uint8 reserved_0 : 4; + uint8 total_exposures; + uint8 blend_index; // exposure no. + + uint8 total_slice_in_x; + uint8 slice_index_x; + uint8 total_slice_in_y; + uint8 slice_index_y; + + uint16 vin_stats_slice_left; + uint16 vin_stats_slice_width; + + uint16 vin_stats_slice_top; + uint16 vin_stats_slice_height; + + uint32 reserved[24]; + + //NOTE: expanded by ARM to support PTS + uint64 mono_pts; + uint32 dsp_pts; + uint32 reserved2; // max 128 bytes +} __attribute__((packed)) ik_cfa_histo_cfg_info_t; + +typedef struct { + uint32 histo_bin_r[AMBA_IK_HDR_HISTO_COUNT]; + uint32 histo_bin_g[AMBA_IK_HDR_HISTO_COUNT]; + uint32 histo_bin_b[AMBA_IK_HDR_HISTO_COUNT]; +} __attribute__((packed)) ik_cfa_histogram_t; + +typedef struct { + ik_cfa_histo_cfg_info_t cfg_info; + ik_cfa_histogram_t cfa_hist; /* Address of histogram statistic DSP_IMG_HDR_HIST_STAT_s */ +} __attribute__((packed)) ik_cfa_histogram_stat_t; + + +typedef enum { + DSP_3A_VIDEO = 0x00, + DSP_3A_STILL, + DSP_3A_DEC, +} DSP_3A_TYPE_e; + +typedef struct { + DSP_3A_TYPE_e Type; + uint8 SrcSliceX; + uint8 SrcSliceY; + uint32 SrcAddr[AMBA_IK_3A_SLICE_MAX_COUNT]; + uint32 SrcHistoAddr[AMBA_IK_3A_SLICE_MAX_COUNT]; + uint32 DstAddr; + uint16 ChannelIdx; +} DSP_EVENT_3A_TRANSFER_s; + + +#endif diff --git a/include/ambarella/arch_v5/AmbaDSP_ImgArchSpec.h b/include/ambarella/arch_v5/AmbaDSP_ImgArchSpec.h new file mode 100644 index 0000000..27afc88 --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_ImgArchSpec.h @@ -0,0 +1,98 @@ +#ifndef ARCH_SPEC_H +#define ARCH_SPEC_H +#include "datatype.h" + +/* AUTO COPY TO VENDER INC */ +#ifdef IK_RELEASE +#define STATIC static +#define INLINE inline +#else +#define STATIC +#define INLINE +#endif +#ifndef MAX_CONTEXT_NUM +#define MAX_CONTEXT_NUM (16U) +#endif +#ifndef MAX_CONFIG_NUM +#define MAX_CONFIG_NUM (10U) +#endif +#define MAX_CONTAINER_IDSP_CMD_NUM (10U) +#define MAX_CONTAINER_VIN_CMD_NUM (10U) +#define MAX_VIN_NUM (4U) +#define IK_MAX_HDR_EXPOSURE_NUM (3U) +#define CONTAINER_CMD_SIZE (128U) +#define AMP_TABLE_SIZE (353) + +#define AMBA_IK_PIPE_VIDEO (0x0U) +#define AMBA_IK_PIPE_STILL (0x1U) + +#define AMBA_IK_ALGO_MODE_LISO (0x0U) + +#define IK_WAIT_FOREVER (0xFFFFFFFFUL) + +typedef enum { + AMBA_IK_VIDEO_STILL_MAX = 0, +} amba_ik_still_pipe_ability_t; + +typedef enum { + AMBA_IK_VIDEO_PIPE_LINEAR = 0U, + AMBA_IK_VIDEO_PIPE_LINEAR_CE, + AMBA_IK_VIDEO_PIPE_HDR_EXPO_2, + AMBA_IK_VIDEO_PIPE_HDR_EXPO_3, + AMBA_IK_VIDEO_PIPE_LINEAR_MD, + AMBA_IK_VIDEO_PIPE_LINEAR_CE_MD, + AMBA_IK_VIDEO_PIPE_HDR_EXPO_2_MD, + AMBA_IK_VIDEO_PIPE_HDR_EXPO_3_MD, + AMBA_IK_VIDEO_PIPE_Y2Y, + AMBA_IK_VIDEO_PIPE_FUSION_CE_MD, + AMBA_IK_VIDEO_PIPE_FUSION_CE, + AMBA_IK_VIDEO_PIPE_MAX, +} amba_ik_video_pipe_ability_t; + +typedef enum { + amba_ik_init_mode_hard_init = 0x00U, + amba_ik_init_mode_soft_init = 0x01U, +}amba_ik_init_mode_t; + +typedef enum { + amba_ik_func_mode_fv = 0x00U, + amba_ik_func_mode_qv = 0x01U, + amba_ik_func_mode_piv = 0X02U, + amba_ik_func_mode_r2r = 0x04U, + amba_ik_func_mode_vhdr = 0x08U, + amba_ik_func_mode_y2y = 0x10U, + amba_ik_func_mode_md = 0x20U, + amba_ik_func_mode_y2y_bypass, +} amba_ik_func_mode_t; + +typedef struct { + uint8 pipe; + amba_ik_still_pipe_ability_t still_pipe; + amba_ik_video_pipe_ability_t video_pipe; +} ik_ability_t; + +typedef struct { + uint32 iso_config_common_update : 1 ; + uint32 iso_config_color_update : 1 ; + uint32 iso_config_mctf_update : 1 ; + uint32 iso_config_step1_update : 1 ; + uint32 iso_config_aaa_update : 1 ; // AAA setup update + uint32 iso_config_extra_update : 1 ; + uint32 iso_config_motion_update : 1 ; + uint32 iso_config_exp_update : 1 ; + uint32 reserved : 24; +} ik_iso_config_update; + +typedef struct { + uint32 ik_id; + void *p_iso_cfg; + ik_iso_config_update update; +} ik_execute_container_t; + + +#define AMBA_IK_RVAL_SUCCESS (0UL) +#define AMBA_IK_RVAL_ERROR (0xFFFFFFFFUL) +#define AMBA_IK_RVAL_AAA_SETUP_INVALID (0xFFFFFFFFUL-1UL) +#define AMBA_IK_RVAL_CTX_SIZE_ERROR (0xFFFFFFFFUL-2UL) + +#endif diff --git a/include/ambarella/arch_v5/AmbaDSP_ImgArchSystemAPI.h b/include/ambarella/arch_v5/AmbaDSP_ImgArchSystemAPI.h new file mode 100644 index 0000000..69feafe --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_ImgArchSystemAPI.h @@ -0,0 +1,114 @@ +#ifndef ARCH_SYSTEM_API_H +#define ARCH_SYSTEM_API_H + +//#include "AmbaDSP_ImgOSAL.h" +#include "datatype.h" + +typedef struct { + uint8 resered[28]; +} OS_MUTEX_TYPE; + +typedef void* (*ik_system_memcpy_t)(void *p_str1, const void *p_str2, size_t n); +typedef void* (*ik_system_memset_t)(void *p_str, int32 c, size_t n); +typedef int32 (*ik_system_memcmp_t)(const void *p_str1, const void *p_str2, size_t n); +typedef int32 (*ik_system_create_mutex_t)(OS_MUTEX_TYPE *p_mutex); +typedef int32 (*ik_system_destroy_mutex_t)(OS_MUTEX_TYPE *p_mutex); +typedef int32 (*ik_system_lock_mutex_t)(OS_MUTEX_TYPE *p_mutex, uint32 timeout); +typedef int32 (*ik_system_unlock_mutex_t)(OS_MUTEX_TYPE *p_mutex); +typedef int32 (*ik_system_print_t)(const char *p_format, ...); +typedef int32 (*ik_system_clean_cache_t)(void *p_str, size_t n); +typedef void* (*ik_system_convert_virtual_to_physical_t)(void* addr); +typedef void* (*ik_system_convert_physical_to_virtual_t)(void* addr); +typedef double64 (*ik_system_sqrt_t)(double64 x); + + +#ifdef __unix__ + +extern ik_system_memcpy_t ik_system_memcpy; +extern ik_system_memset_t ik_system_memset; +extern ik_system_memcmp_t ik_system_memcmp; +extern ik_system_create_mutex_t ik_system_create_mutex; +extern ik_system_destroy_mutex_t ik_system_destroy_mutex; +extern ik_system_lock_mutex_t ik_system_lock_mutex; +extern ik_system_unlock_mutex_t ik_system_unlock_mutex; +extern ik_system_convert_virtual_to_physical_t ik_system_virtual_to_physical_address; +extern ik_system_convert_physical_to_virtual_t ik_system_physical_to_virtual_address; +extern ik_system_print_t ik_system_print; +extern ik_system_clean_cache_t ik_system_clean_cache; +extern ik_system_sqrt_t ik_system_sqrt; + +#define amba_ik_system_memcpy ik_system_memcpy +#define amba_ik_system_memset ik_system_memset +#define amba_ik_system_memcmp ik_system_memcmp +#define amba_ik_system_create_mutex ik_system_create_mutex +#define amba_ik_system_destroy_mutex ik_system_destroy_mutex +#define amba_ik_system_lock_mutex ik_system_lock_mutex +#define amba_ik_system_unlock_mutex ik_system_unlock_mutex +#define amba_ik_system_virtual_to_physical_address ik_system_virtual_to_physical_address +#define amba_ik_system_physical_to_virtual_address ik_system_physical_to_virtual_address +#define amba_ik_system_print ik_system_print +#define amba_ik_system_clean_cache ik_system_clean_cache +#define amba_ik_system_sqrt ik_system_sqrt + +void img_arch_registe_system_memcpy(const ik_system_memcpy_t *p_system_memcpy); +void img_arch_registe_system_memset(const ik_system_memset_t *p_system_memset); +void img_arch_registe_system_memcmp(const ik_system_memcmp_t *p_system_memcmp); +void img_arch_registe_system_create_mutex(const ik_system_create_mutex_t *p_system_create_mutex); +void img_arch_registe_system_destroy_mutex(const ik_system_destroy_mutex_t *p_system_destroy_mutex); +void img_arch_registe_system_lock_mutex(const ik_system_lock_mutex_t *p_system_lock_mutex); +void img_arch_registe_system_unlock_mutex(const ik_system_unlock_mutex_t *p_system_unlock_mutex); +void img_arch_registe_system_print(const ik_system_print_t *p_system_print); +void img_arch_registe_system_clean_cache(const ik_system_clean_cache_t *p_system_clean_cache); +void img_arch_registe_system_virtual_to_physical_address(const ik_system_convert_virtual_to_physical_t *p_system_virtual_to_physical_address); +void img_arch_registe_system_physical_to_virtual_address(const ik_system_convert_physical_to_virtual_t *p_system_physical_to_virtual_address); +void img_arch_unregiste_system_memcpy(void); +void img_arch_unregiste_system_memset(void); +void img_arch_unregiste_system_memcmp(void); +void img_arch_unregiste_system_create_mutex(void); +void img_arch_unregiste_system_destroy_mutex(void); +void img_arch_unregiste_system_lock_mutex(void); +void img_arch_unregiste_system_unlock_mutex(void); +void img_arch_unregiste_system_print(void); +void img_arch_unregiste_system_clean_cache(void); +void img_arch_unregiste_system_virtual_to_physical_address(void); +void img_arch_unregiste_system_physical_to_virtual_address(void); +void img_arch_registe_system_sqrt(const ik_system_sqrt_t *p_system_sqrt); +void img_arch_unregiste_system_sqrt(void); +uint32 img_arch_check_system_control_callback_function(void); + + +#else +//rtos +#define amba_ik_system_memcpy memcpy +#define amba_ik_system_memset memset +#define amba_ik_system_memcmp memcmp +#define amba_ik_system_create_mutex AmbaKAL_MutexCreate +#define amba_ik_system_destroy_mutex AmbaKAL_MutexDelete +#define amba_ik_system_lock_mutex AmbaKAL_MutexTake +#define amba_ik_system_unlock_mutex AmbaKAL_MutexGive +#define amba_ik_system_virtual_to_physical_address AmbaMmuVirtToPhys +#define amba_ik_system_physical_to_virtual_address AmbaMmuPhysToVirt +#define amba_ik_system_print AmbaPrint +#define amba_ik_system_clean_cache AmbaCache_Clean +#define amba_ik_system_sqrt sqrt + +#endif + +typedef struct { + ik_system_memcpy_t system_memcpy; + ik_system_memset_t system_memset; + ik_system_memcmp_t system_memcmp; + ik_system_create_mutex_t system_create_mutex; + ik_system_destroy_mutex_t system_destroy_mutex; + ik_system_lock_mutex_t system_lock_mutex; + ik_system_unlock_mutex_t system_unlock_mutex; + ik_system_print_t system_print; + ik_system_clean_cache_t system_clean_cache; + ik_system_convert_virtual_to_physical_t system_virtual_to_physical_address; + ik_system_convert_physical_to_virtual_t system_physical_to_virtual_address; + ik_system_sqrt_t system_sqrt; + // FIXME: convert to virtual +} ik_system_api_t; + + +#endif diff --git a/include/ambarella/arch_v5/AmbaDSP_ImgDebugUtility.h b/include/ambarella/arch_v5/AmbaDSP_ImgDebugUtility.h new file mode 100644 index 0000000..c781fe5 --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_ImgDebugUtility.h @@ -0,0 +1,13 @@ +#ifndef IMG_DEBUG_UTILITY_H +#define IMG_DEBUG_UTILITY_H +#include "datatype.h" + +//uint32 amba_ik_set_debug_status_by_id(uint32 id, uint8 enable_func_name, uint8 enable_func_param, uint8 enable_record); +//void amba_ik_register_filter_log(uint32 (*func)(void *data, size_t size, uint32 context_id)); +uint32 ik_set_diag_case_id(uint32 context_id, uint8 diag_case_id); +uint32 ik_set_debug_level(uint32 debug_level); +uint32 ik_set_warp_debug_level(uint32 debug_level); +uint32 ik_set_static_bpc_highlight(uint32 context_id, uint32 high_light_mode); +uint32 ik_get_static_bpc_highlight(uint32 context_id, uint32 *p_high_light_mode); + +#endif diff --git a/include/ambarella/arch_v5/AmbaDSP_ImgFastboot.h b/include/ambarella/arch_v5/AmbaDSP_ImgFastboot.h new file mode 100644 index 0000000..9649566 --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_ImgFastboot.h @@ -0,0 +1,56 @@ +/** +* @file AmbaDSP_ImgFastBoot.h +* +* @copyright Copyright (c) 2015 Ambarella, Inc. +* +* This file and its contents ("Software") are protected by intellectual property rights including, without limitation, +* U.S. and/or foreign copyrights. This Software is also the confidential and proprietary information of Ambarella, Inc. +* and its licensors. You may not use, reproduce, disclose, distribute, modify, or otherwise prepare derivative works +* of this Software or any portion thereof except pursuant to a signed license agreement or nondisclosure agreement with +* Ambarella, Inc. or its authorized affiliates. In the absence of such an agreement, you agree to promptly notify and +* return this Software to Ambarella, Inc. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +* AMBARELLA, INC. OR ITS AFFILIATES 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; +* COMPUTER FAILURE OR MALFUNCTION; 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. +* +* @details Ambarella DSP Image Kernel Utility APIs +* +*/ + +#ifndef _AMBA_DSP_IMG_FASTBOOT_H_ +#define _AMBA_DSP_IMG_FASTBOOT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../basetypes.h" +#define FASTBOOT_CFGS_SIZE (768) //32bit +#define FASTBOOT_UPDATE_LIST_NUM (96) + +#define LISO_BATCH_CMD_ADDR_OFFSET (504) +#define LISO_BATCH_CMD_SIZE_OFFSET (502) +#define LISO_BATCH_CMD_UPDATE_FLAG_OFFSET0 (500) +#define LISO_BATCH_CMD_UPDATE_FLAG_OFFSET1 (508) + +typedef struct { + u32 package_size; + u32 iso_cfg_offset; + u32 hdr_cfg_offset; + u32 ce_cfg_offset; + u32 tables_size; + u32 offset_update_list[FASTBOOT_UPDATE_LIST_NUM]; + u8 cfgs[FASTBOOT_CFGS_SIZE]; + u8 tables[0]; +} amba_img_dsp_fastboot_data_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/arch_v5/AmbaDSP_ImgFilter.h b/include/ambarella/arch_v5/AmbaDSP_ImgFilter.h new file mode 100644 index 0000000..5fc3aa5 --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_ImgFilter.h @@ -0,0 +1,1519 @@ +#ifndef IMG_FILTERS_IF_H +#define IMG_FILTERS_IF_H + +#include "datatype.h" +#include "AmbaDSP_ImgArchSpec.h" +#define IK_NUM_CORING_TABLE_INDEX (256U) +#define IK_NUM_CHROMA_GAIN_CURVE (128U) +#define IK_NUM_EXPOSURE_CURVE (256U) +#define IK_NUM_TONE_CURVE (256U) +#define IK_CC_REG_SIZE (18752U) +#define IK_CC_3D_SIZE (17536U) +#define IK_CE_INPUT_TABLE_SIZE (449U) +#define IK_CE_OUTPUT_TABLE_SIZE (256U) +#define IK_CE_CORING_TABLE_SIZE (64U) +#define IK_CE_BOOST_TABLE_SIZE (64U) +#define IK_NUM_THREE_D_TABLE (8192U) + +#define IK_SBP_VER_1_0 (0x20130218UL) +#define IK_WARP_DISABLE (0) +#define IK_WARP_ENABLE (1) +#define IK_WARP_ENABLE_INTERNAL (2) +#define IK_WARP_VIDEO_MAXHORGRID (128UL) +#define IK_WARP_VIDEO_MAXVERGRID (96UL) +#define IK_WARP_MAX_SLICE_NUMBER (6UL) + +typedef struct { + uint32 step; + uint32 mode; + uint32 channel_id; + uint32 tile_x; + uint32 tile_y; + uint32 pic_num; +} img_dsp_img_debug_mode_t; + +typedef struct { + uint32 vin_id; + uint32 sensor_resolution; /* Number of bits for data representation */ + uint32 sensor_pattern; /* Bayer patterns RG, BG, GR, GB */ + uint32 sensor_mode; /* 0: normal 1:RGB-IR 2:RCCC */ + uint32 compression; + int32 compression_offset; + uint32 sensor_readout_mode; +} ik_vin_sensor_info_t; + +typedef struct { + uint32 global_dgain; // 12.12 format, default = 4096 +} ik_global_dgain_t; + +typedef struct { + uint32 ae_gain; // 12.12 format, default = 4096 +} ik_ae_gain_t; + +typedef struct { + uint32 gain_r; + uint32 gain_g; + uint32 gain_b; +} ik_wb_gain_t; + +typedef struct { + uint32 enable; + uint32 alpha_rr; + uint32 alpha_rb; + uint32 alpha_br; + uint32 alpha_bb; + uint32 saturation_level; +} ik_cfa_leakage_filter_t; + +typedef struct { + uint32 enable; + uint32 thresh; + uint32 log_fractional_correct; +} ik_anti_aliasing_t; + +typedef struct { + uint32 enable; + uint32 hot_pixel_strength; + uint32 dark_pixel_strength; + uint32 correction_method; +} ik_dynamic_bad_pixel_correction_t; + +typedef struct { + uint32 enable; + uint32 noise_level[3]; /* R/G/B, 0-8192 */ + uint32 original_blend_str[3]; /* R/G/B, 0-256 */ + uint32 extent_regular[3]; /* R/G/B, 0-256 */ + uint32 extent_fine[3]; /* R/G/B, 0-256 */ + uint32 strength_fine[3]; /* R/G/B, 0-256 */ + uint32 selectivity_regular; /* 0-256 */ + uint32 selectivity_fine; /* 0-256 */ + uint32 directional_enable; + uint32 directional_horvert_edge_strength; + uint32 directional_horvert_strength_bias; + uint32 directional_horvert_original_blend_strength; +} ik_cfa_noise_filter_t; + +typedef struct { + uint32 level_red; /* 14:0 */ + uint32 level_green_even; + uint32 level_green_odd; + uint32 level_blue; +} ik_dgain_saturation_level_t; + +typedef struct { + uint32 enable; + uint32 activity_thresh; + uint32 activity_difference_thresh; + uint32 grad_clip_thresh; + uint32 grad_noise_thresh; + uint32 alias_interpolation_strength; + uint32 alias_interpolation_thresh; +} ik_demosaic_t; + +typedef struct { + uint8 reg_setting_table[IK_CC_REG_SIZE]; +} ik_color_correction_reg_t; + +typedef struct { + uint8 matrix_three_d_table[IK_CC_3D_SIZE]; +} ik_color_correction_t; + +typedef struct { + uint32 tone_curve_red[IK_NUM_TONE_CURVE]; + uint32 tone_curve_green[IK_NUM_TONE_CURVE]; + uint32 tone_curve_blue[IK_NUM_TONE_CURVE]; +} ik_tone_curve_t; + +typedef struct { + int32 matrix_values[9]; + int32 y_offset; + int32 u_offset; + int32 v_offset; +} ik_rgb_to_yuv_matrix_t; + +typedef struct { + uint32 mode; + int32 ircorrect_offset_b; + int32 ircorrect_offset_gb; + int32 ircorrect_offset_gr; + int32 ircorrect_offset_r; + uint32 mul_base_val; + uint32 mul_delta_high; + uint32 mul_high; + uint32 mul_high_val; + uint32 maintain_color_balance; +} ik_rgb_ir_t; + +typedef struct { + uint32 enable; + uint32 gain_curve[IK_NUM_CHROMA_GAIN_CURVE]; +} ik_chroma_scale_t; + +typedef struct { + uint32 enable; + uint32 cb_adaptive_strength; + uint32 cr_adaptive_strength; + uint32 cb_non_adaptive_strength; + uint32 cr_non_adaptive_strength; + uint32 cb_adaptive_amount; + uint32 cr_adaptive_amount; +} ik_chroma_median_filter_t; + +typedef struct { + uint32 use_sharpen_not_asf; +} ik_first_luma_process_mode_t; + +typedef struct { + uint32 temporal_alpha0; // 0-255 + uint32 temporal_alpha1; // 0-255 + uint32 temporal_alpha2; // 0-255 + uint32 temporal_alpha3; // 0-255 + uint32 temporal_t0; // 0-63 + uint32 temporal_t1; // 0-63 + uint32 temporal_t2; // 0-63 + uint32 temporal_t3; // 0-63 +} ik_video_mctf_curve_t; + +typedef struct { + uint32 low; + uint32 low_delta; + uint32 low_strength; + uint32 mid_strength; + uint32 high; + uint32 high_delta; + uint32 high_strength; +} ik_level_t; + +typedef struct { + uint32 low; + uint32 low_delta; + uint32 low_strength; + uint32 mid_strength; + uint32 high; + uint32 high_delta; + uint32 high_strength; + uint32 method; +} ik_level_method_t; + +typedef struct { + uint32 alpha_min_up; + uint32 alpha_max_up; + uint32 t0_up; + uint32 t1_up; + uint32 alpha_min_down; + uint32 alpha_max_down; + uint32 t0_down; + uint32 t1_down; +} ik_full_adaptation_t; + +typedef struct { + uint32 specify; + uint32 per_dir_fir_iso_strengths[9]; + uint32 per_dir_fir_dir_strengths[9]; + uint32 per_dir_fir_dir_amounts[9]; + int32 coefs[9][25]; + uint32 strength_iso; + uint32 strength_dir; + uint32 wide_edge_detect; +} ik_asf_fir_t; + +typedef struct { + uint32 enable; + ik_asf_fir_t fir; + uint32 directional_decide_t0; + uint32 directional_decide_t1; + ik_full_adaptation_t adapt; + ik_level_t level_str_adjust; + ik_level_t t0_t1_div; + uint32 max_change_not_t0_t1_alpha; + uint32 max_change_up; + uint32 max_change_down; +} ik_adv_spatial_filter_t; + +typedef ik_level_t ik_first_sharpen_coring_idx_scale_t; +typedef ik_level_method_t ik_final_sharpen_coring_idx_scale_t; +typedef ik_level_t ik_first_sharpen_min_coring_result_t; +typedef ik_level_method_t ik_final_sharpen_min_coring_result_t; +typedef ik_level_method_t ik_final_sharpen_max_coring_result_t; +typedef ik_level_t ik_first_sharpen_scale_coring_t; +typedef ik_level_method_t ik_final_sharpen_scale_coring_t; + +typedef struct { + uint8 y_tone_offset; + uint8 y_tone_shift; + uint8 u_tone_offset; + uint8 u_tone_shift; + uint8 u_tone_bits; + uint8 v_tone_offset; + uint8 v_tone_shift; + uint8 v_tone_bits; + uint8 three_d[IK_NUM_THREE_D_TABLE]; +} ik_table_indexing_t; + +typedef ik_table_indexing_t ik_final_sharpen_both_three_d_table_t; + +typedef struct { + uint32 up5x5; + uint32 down5x5; + uint32 up; + uint32 down; +} ik_max_change_t; + +typedef struct { + uint32 enable; + uint32 mode; + uint32 edge_thresh; + uint32 wide_edge_detect; + uint32 max_change_up5x5; + uint32 max_change_down5x5; +} ik_first_sharpen_both_t; + +typedef struct { + uint32 enable; + uint32 mode; + uint32 edge_thresh; + uint32 wide_edge_detect; + ik_max_change_t max_change; + uint32 narrow_nonsmooth_detect_sub[17]; + uint32 narrow_nonsmooth_detect_shift; + ik_level_method_t method_6_lev; + uint32 method_6_use_local; +} ik_final_sharpen_both_t; + +typedef struct { + uint32 specify; + uint32 per_dir_fir_iso_strengths[9]; + uint32 per_dir_fir_dir_strengths[9]; + uint32 per_dir_fir_dir_amounts[9]; + int32 coefs[9][25]; + uint32 strength_iso; + uint32 strength_dir; +} ik_sharpen_noise_sharpen_fir_t; + +typedef ik_sharpen_noise_sharpen_fir_t ik_first_sharpen_fir_t; + +typedef struct { + uint32 specify; + uint32 per_dir_fir_iso_strengths[9]; + uint32 per_dir_fir_dir_strengths[9]; + uint32 per_dir_fir_dir_amounts[9]; + int32 coefs[9][25]; + uint32 strength_iso; + uint32 strength_dir; + uint32 pos_fir_artifact_reduce_enable; + uint32 pos_fir_artifact_reduce_strength; + uint32 over_shoot_reduce_allow; + uint32 over_shoot_reduce_strength; + uint32 under_shoot_reduce_allow; + uint32 under_shoot_reduce_strength; +} ik_final_sharpen_fir_t; + +typedef struct { + uint32 enable; + uint32 max_change_method; + uint32 max_change_table[32]; + uint32 noise_level_method; + uint32 noise_level_table[32]; + uint32 size; + uint32 str_a_method; + uint32 str_a_table[32]; + uint32 str_b_method; + uint32 str_b_table[32]; +} ik_sharpen_noise_advanced_iso_t; + +typedef struct { + uint32 max_change_up; // 0:255 + uint32 max_change_down; // 0:255 + ik_sharpen_noise_sharpen_fir_t spatial_fir; + ik_level_t level_str_adjust; + uint32 level_str_adjust_not_t0_t1_level_based; // 0:10 + uint32 t0; // 0:255 t0 <= t1, t1 - t0 <= 15 + uint32 t1; // 0:255 + uint32 alpha_min; // 0:16 + uint32 alpha_max; // 0:16 +} ik_first_sharpen_noise_t; + +typedef struct { + uint32 max_change_up; // 0:255 + uint32 max_change_down; // 0:255 + ik_sharpen_noise_sharpen_fir_t spatial_fir; + ik_level_method_t level_str_adjust; + uint32 level_str_adjust_not_t0_t1_level_based; // 0:1 + uint32 t0; // 0:255 t0 <= t1, t1 - t0 <= 15 + uint32 t1; // 0:255 + uint32 alpha_min; // 0:16 + uint32 alpha_max; // 0:16 + uint32 directional_decide_t0; + uint32 directional_decide_t1; + ik_sharpen_noise_advanced_iso_t advanced_iso; +} ik_final_sharpen_noise_t; + +typedef struct { + uint32 coring[IK_NUM_CORING_TABLE_INDEX]; + uint32 fractional_bits; +} ik_first_sharpen_coring_t; + +typedef struct { + uint32 coring[IK_NUM_CORING_TABLE_INDEX]; + uint32 fractional_bits; +} ik_final_sharpen_coring_t; + +typedef struct { + uint32 low; + uint32 low_delta; + uint32 low_strength; + uint32 mid_strength; + uint32 high; + uint32 high_delta; + uint32 high_strength; +} ik_first_sharpen_max_coring_result_t; + +typedef struct { + uint32 enable; + uint32 noise_level_cb; + uint32 noise_level_cr; /* 0-255 */ + uint32 original_blend_strength_cb; /* Cb 0-256 */ + uint32 original_blend_strength_cr; /* Cr 0-256 */ + uint32 radius; +} ik_chroma_filter_t; + +typedef struct { + uint32 max_chroma_radius; +} ik_variable_range_t; + +typedef struct { + uint32 narrow_enable; + uint32 wide_enable; + uint32 wide_safety; + uint32 wide_thresh; +} ik_grgb_mismatch_t; + +typedef struct { + uint32 ta_frames_combine_num1; + uint32 ta_frames_combine_num2; + //cv2 + ik_level_method_t y_3d_64_maxchange; + uint32 y_10; +} ik_mctf_internal_t; + + typedef struct { + uint32 cmd_code; + uint32 mode; + uint32 param1; + uint32 param2; + uint32 param3; + uint32 param4; + uint32 param5; + uint32 param6; + uint32 param7; + uint32 param8; +} ik_idsp_debug_internal_t; + +typedef struct { + uint32 enable; // 0,1 + uint32 y_combine_strength; // 0:256 + uint32 y_strength_3d; // 0:256 + uint32 y_spatial_weighting[64]; // 0:255 + uint32 y_temporal_max_change; // 0:255 + uint32 cb_strength_3d; // 0:256 + uint32 cb_spatial_weighting[64]; // 0:255 + uint32 cb_temporal_max_change; // 0:255 + uint32 cr_strength_3d; // 0:256 + uint32 cr_spatial_weighting[64]; // 0:255 + uint32 cr_temporal_max_change; // 0:255 + ik_video_mctf_curve_t y_curve; + ik_video_mctf_curve_t cb_curve; + ik_video_mctf_curve_t cr_curve; + uint32 y_spat_smth_direct_decide_t0; + uint32 y_spat_smth_direct_decide_t1; + uint32 cb_spat_smth_direct_decide_t0; + uint32 cb_spat_smth_direct_decide_t1; + uint32 cr_spat_smth_direct_decide_t0; + uint32 cr_spat_smth_direct_decide_t1; + uint32 y_temporal_max_change_not_t0_t1_level_based; // 0:1 + ik_level_method_t y_temporal_either_max_change_or_t0_t1_add; + uint32 cb_temporal_max_change_not_t0_t1_level_based; // 0:1 + ik_level_method_t cb_temporal_either_max_change_or_t0_t1_add; + uint32 cr_temporal_max_change_not_t0_t1_level_based; // 0:1 + ik_level_method_t cr_temporal_either_max_change_or_t0_t1_add; + //cv2 + uint32 y_narrow_nonsmooth_detect_sub[17]; + uint32 y_narrow_nonsmooth_detect_shift; + uint32 use_level_based_ta; + //spat_blend level + ik_level_method_t y_spat_blend; + ik_level_method_t cb_spat_blend; + ik_level_method_t cr_spat_blend; + //advanced iso + uint32 y_advanced_iso_max_change_table[32]; + uint32 y_advanced_iso_max_change_method; + uint32 y_advanced_iso_size; + uint32 y_advanced_iso_noise_level; + uint32 y_advanced_iso_enable; + uint32 cb_advanced_iso_max_change_table[32]; + uint32 cb_advanced_iso_max_change_method; + uint32 cb_advanced_iso_size; + uint32 cb_advanced_iso_noise_level; + uint32 cb_advanced_iso_enable; + uint32 cr_advanced_iso_max_change_table[32]; + uint32 cr_advanced_iso_max_change_method; + uint32 cr_advanced_iso_size; + uint32 cr_advanced_iso_noise_level; + uint32 cr_advanced_iso_enable; + //3d max change level + ik_level_method_t y_3d_maxchange; + ik_level_method_t cb_3d_maxchange; + ik_level_method_t cr_3d_maxchange; + //overall max change level + ik_level_method_t y_overall_max_change; + ik_level_method_t cb_overall_max_change; + ik_level_method_t cr_overall_max_change; + //spat filt max smth change level + ik_level_method_t y_spat_filt_max_smth_change; + ik_level_method_t cb_spat_filt_max_smth_change; + ik_level_method_t cr_spat_filt_max_smth_change; + /*spat_smth_dir*/ + uint32 y_spat_smth_wide_edge_detect; //0:8 + uint32 y_spat_smth_edge_thresh; //0:2047 + ik_level_method_t y_spat_smth_dir; + uint32 cb_spat_smth_wide_edge_detect;//0:8 + uint32 cb_spat_smth_edge_thresh;//0:2047 + ik_level_method_t cb_spat_smth_dir; + uint32 cr_spat_smth_wide_edge_detect;//0:8 + uint32 cr_spat_smth_edge_thresh;//0:2047 + ik_level_method_t cr_spat_smth_dir; + /*spat_smth_iso*/ + ik_level_method_t y_spat_smth_iso; + ik_level_method_t cb_spat_smth_iso; + ik_level_method_t cr_spat_smth_iso; + //level based ta level + ik_level_method_t y_level_based_ta; + ik_level_method_t cb_level_based_ta; + ik_level_method_t cr_level_based_ta; + //temporal min target + ik_level_method_t y_temporal_min_target; + ik_level_method_t cb_temporal_min_target; + ik_level_method_t cr_temporal_min_target; + //spatial max temporal level + uint32 y_spatial_max_change; //0:255 + ik_level_method_t y_spatial_max_temporal; + uint32 cb_spatial_max_change;//0:255 + ik_level_method_t cb_spatial_max_temporal; + uint32 cr_spatial_max_change;//0:255 + ik_level_method_t cr_spatial_max_temporal; +// int32 y_spat_smth_favour_1_4; +// int32 y_spat_smth_favour_1_8; + uint32 local_lighting; + uint32 compression_enable; + uint32 y_temporal_ghost_prevent; + uint32 cb_temporal_ghost_prevent; + uint32 cr_temporal_ghost_prevent; + uint32 y_temporal_artifact_guard; + uint32 cb_temporal_artifact_guard; + uint32 cr_temporal_artifact_guard; + uint32 compression_bit_rate_luma; + uint32 compression_bit_rate_chroma; + uint32 compression_dither_disable; +} ik_video_mctf_t; + +typedef struct { + uint32 max; // 0:15 + uint32 min; // 0:15 + uint32 motion_response; // 0:16383 + uint32 noise_base; // 0:4095 + uint32 still_thresh; // 0:4095 +} ik_video_mctf_ta_y_t; + +typedef struct { + uint32 max; // 0:15 + uint32 min; // 0:15 + uint32 motion_response; // 0:16383 + uint32 noise_base; // 0:4095 + uint32 still_thresh; // 0:4095 +} ik_video_mctf_ta_cb_t; + +typedef struct { + uint32 max; // 0:15 + uint32 min; // 0:15 + uint32 motion_response; // 0:16383 + uint32 noise_base; // 0:4095 + uint32 still_thresh; // 0:4095 +} ik_video_mctf_ta_cr_t; + +typedef struct { + uint32 edge_adjust_b; // 0:2047 + uint32 edge_adjust_l; // 0:2047 + uint32 edge_adjust_r; // 0:2047 + uint32 edge_adjust_t; // 0:2047 + //uint32 frames_combine_num1; // 1:6 + //uint32 frames_combine_num2; // 1:6 + uint32 slow_mo_sensitivity; // 0:11 + uint32 score_noise_robust; // 0:1 + uint32 lev_adjust_low; // 0:255 + uint32 lev_adjust_low_delta; // 0:7 + uint32 lev_adjust_low_strength; // 0:255 + uint32 lev_adjust_mid_strength; // 0:255 + uint32 lev_adjust_high; // 0:255 + uint32 lev_adjust_high_delta; // 0:7 + uint32 lev_adjust_high_strength; // 0:255 + ik_video_mctf_ta_y_t y_mctf_ta; + ik_video_mctf_ta_cb_t cb_mctf_ta; + ik_video_mctf_ta_cr_t cr_mctf_ta; +} ik_video_mctf_ta_t; + +typedef struct { + uint32 enable; + uint32 lev_add_1_method; + uint32 lev_add_1_table[64]; + uint32 lev_add_2_method; + uint32 lev_add_2_table[64]; + uint32 lev_mul_1_method; + uint32 lev_mul_1_table[64]; + uint32 lev_mul_2_method; + uint32 lev_mul_2_table[64]; + uint32 local_lighting; + uint32 motion_response; + uint32 noise_base; + uint32 slow_mo_sensitivity; +} ik_motion_detect_t; + +typedef struct { + uint8 pos_dep[33][33]; + uint8 reserved[3]; +} ik_pos_dep33_t; + +typedef struct { + uint32 local_lighting_radius; +} ik_motion_detect_and_mctf_t; + +typedef struct { + uint32 factor_num; /* subsamping factor (numerator) */ + uint32 factor_den; /* subsamping factor (denominator) */ +} ik_sensor_subsampling_t; + +typedef struct { + uint32 start_x; // Unit in pixel. Before downsample. + uint32 start_y; // Unit in pixel. Before downsample. + uint32 width; // Unit in pixel. After downsample. + uint32 height; // Unit in pixel. After downsample. + ik_sensor_subsampling_t h_sub_sample; + ik_sensor_subsampling_t v_sub_sample; +} ik_vin_sensor_geometry_t; + +typedef struct { + uint32 version; + uint32 num_radial_bins_coarse; //coarse + fine <= 128 + uint32 size_radial_bins_coarse_log; //valid range 0~8 + uint32 num_radial_bins_fine; + uint32 size_radial_bins_fine_log; //valid range 0~8 + uint32 model_center_x_R; // 4 individual bayer components optical center x, relative to calib window. + uint32 model_center_x_Gr; + uint32 model_center_x_B; + uint32 model_center_x_Gb; + uint32 model_center_y_R; // 4 individual bayer components optical center x, relative to calib window. + uint32 model_center_y_Gr; + uint32 model_center_y_B; + uint32 model_center_y_Gb; + uint32 vig_gain_tbl_R[4][128]; // pointer to [4 bayer chan][4 direction][128 vertices] 0:9b mult 10:13b shift, 32bit for each gain(hw format) + uint32 vig_gain_tbl_Gr[4][128]; + uint32 vig_gain_tbl_B[4][128]; + uint32 vig_gain_tbl_Gb[4][128]; +} ik_calib_vignette_info_t; + +typedef struct { + uint32 calib_mode_enable; + ik_vin_sensor_geometry_t current_vin_sensor_geo; + ik_calib_vignette_info_t calib_vignette_info; +} ik_vignette_t; + +typedef struct { + uint32 version; /* 0x20130218 */ + uint8 *sbp_buffer; +} ik_calib_sbp_info_t; + +typedef struct { + ik_vin_sensor_geometry_t vin_sensor_geo;/* Vin sensor geometry when calibrating. */ + ik_calib_sbp_info_t calib_sbp_info; +} ik_static_bad_pxl_cor_t; + +typedef struct { + uint32 enable; +} ik_deferred_blc_level_t; + +typedef struct { + int32 black_r; + int32 black_gr; + int32 black_gb; + int32 black_b; +} ik_static_blc_level_t; + +typedef struct { + uint32 cfa_cut_off_freq; /* 0:M, 1:M-2, 2:M-4, 3:M-6, 4:M-8, 5:M-10, 6:M-12, 7:M-14 */ + uint32 main_cut_off_freq; +} ik_resampler_strength_t; + +typedef struct { + uint32 x_offset[IK_MAX_HDR_EXPOSURE_NUM]; + uint32 y_offset[IK_MAX_HDR_EXPOSURE_NUM]; +} ik_hdr_raw_info_t; + +typedef struct { + uint32 r_gain; // 12.12 format + uint32 g_gain; // 12.12 format + uint32 b_gain; // 12.12 format + uint32 shutter_ratio; +} ik_frontend_wb_gain_t; + +typedef struct { + uint32 level_red; // 0:16383 + uint32 level_green_even; // 0:16383 + uint32 level_green_odd; // 0:16383 + uint32 level_bule; // 0:16383 + uint32 pre_level_red; // 0:16383 + uint32 pre_level_green_even; // 0:16383 + uint32 pre_level_green_odd; // 0:16383 + uint32 pre_level_bule; // 0:16383 + uint32 post_level_red; // 0:16383 + uint32 post_level_green_even; // 0:16383 + uint32 post_level_green_odd; // 0:16383 + uint32 post_level_bule; // 0:16383 +} ik_frontend_dgain_saturation_level_t; + +typedef struct { + uint32 enable; + uint32 delta_t0; + uint32 delta_t1; + uint32 flicker_threshold; + uint32 t0_offset; + uint32 t1_offset; +} ik_hdr_blend_t; + +typedef struct { + uint32 enable; + uint32 luma_avg_method; + + int32 luma_avg_weight_r; + int32 luma_avg_weight_gr; + int32 luma_avg_weight_gb; + int32 luma_avg_weight_b; + + uint32 fir_enable; + uint32 fir_coeff[3]; + uint32 coring_index_scale_shift; + + uint32 coring_index_scale_low; + uint32 coring_index_scale_low_delta; + uint32 coring_index_scale_low_strength; + uint32 coring_index_scale_mid_strength; + uint32 coring_index_scale_high; + uint32 coring_index_scale_high_delta; + uint32 coring_index_scale_high_strength; + + uint32 coring_gain_shift; + uint32 coring_gain_low; + uint32 coring_gain_low_delta; + uint32 coring_gain_low_strength; + uint32 coring_gain_mid_strength; + uint32 coring_gain_high; + uint32 coring_gain_high_delta; + uint32 coring_gain_high_strength; + + uint32 coring_table[IK_CE_CORING_TABLE_SIZE]; + //cv2 + uint32 boost_gain_shift; + int32 boost_table[IK_CE_BOOST_TABLE_SIZE]; + uint32 boost_table_size_exp; + + uint32 radius; + uint32 epsilon; +} ik_ce_t; + +typedef struct { + uint32 input_enable; + uint32 input_table[IK_CE_INPUT_TABLE_SIZE]; +} ik_ce_input_table_t; + +typedef struct { + uint32 output_enable; + uint32 output_shift; + uint32 output_table[IK_CE_OUTPUT_TABLE_SIZE]; +} ik_ce_output_table_t; + +typedef struct { + uint32 awb_tile_num_col; + uint32 awb_tile_num_row; + uint32 awb_tile_col_start; + uint32 awb_tile_row_start; + uint32 awb_tile_width; + uint32 awb_tile_height; + uint32 awb_tile_active_width; + uint32 awb_tile_active_height; + uint32 awb_pix_min_value; + uint32 awb_pix_max_value; + uint32 ae_tile_num_col; + uint32 ae_tile_num_row; + uint32 ae_tile_col_start; + uint32 ae_tile_row_start; + uint32 ae_tile_width; + uint32 ae_tile_height; + uint32 ae_pix_min_value; + uint32 ae_pix_max_value; + uint32 af_tile_num_col; + uint32 af_tile_num_row; + uint32 af_tile_col_start; + uint32 af_tile_row_start; + uint32 af_tile_width; + uint32 af_tile_height; + uint32 af_tile_active_width; + uint32 af_tile_active_height; + uint32 six_minus_cfa_input_shift; +} ik_aaa_stat_info_t; + +typedef struct { + uint32 af_horizontal_filter1_mode; + uint32 af_horizontal_filter1_stage1_enb; + uint32 af_horizontal_filter1_stage2_enb; + uint32 af_horizontal_filter1_stage3_enb; + int32 af_horizontal_filter1_gain[7]; + uint32 af_horizontal_filter1_shift[4]; + uint32 af_horizontal_filter1_bias_off; + uint32 af_horizontal_filter1_thresh; + uint32 af_horizontal_filter2_mode; + uint32 af_horizontal_filter2_stage1_enb; + uint32 af_horizontal_filter2_stage2_enb; + uint32 af_horizontal_filter2_stage3_enb; + int32 af_horizontal_filter2_gain[7]; + uint32 af_horizontal_filter2_shift[4]; + uint32 af_horizontal_filter2_bias_off; + uint32 af_horizontal_filter2_thresh; + uint32 af_tile_fv1_horizontal_shift; + uint32 af_tile_fv2_horizontal_shift; +} ik_af_stat_ex_info_t; + +typedef struct { + uint32 af_horizontal_filter1_mode; + uint32 af_horizontal_filter1_stage1_enb; + uint32 af_horizontal_filter1_stage2_enb; + uint32 af_horizontal_filter1_stage3_enb; + int32 af_horizontal_filter1_gain[7]; + uint32 af_horizontal_filter1_shift[4]; + uint32 af_horizontal_filter1_bias_off; + uint32 af_horizontal_filter1_thresh; + uint32 af_vertical_filter1_thresh; + uint32 af_horizontal_filter2_mode; + uint32 af_horizontal_filter2_stage1_enb; + uint32 af_horizontal_filter2_stage2_enb; + uint32 af_horizontal_filter2_stage3_enb; + int32 af_horizontal_filter2_gain[7]; + uint32 af_horizontal_filter2_shift[4]; + uint32 af_horizontal_filter2_bias_off; + uint32 af_horizontal_filter2_thresh; + uint32 af_vertical_filter2_thresh; + uint32 af_tile_fv1_horizontal_shift; + uint32 af_tile_fv1_vertical_shift; + uint32 af_tile_fv1_horizontal_weight; + uint32 af_tile_fv1_vertical_weight; + uint32 af_tile_fv2_horizontal_shift; + uint32 af_tile_fv2_vertical_shift; + uint32 af_tile_fv2_horizontal_weight; + uint32 af_tile_fv2_vertical_weight; +} ik_pg_af_stat_ex_info_t; + +typedef struct { + // TODO: + uint32 reserved; +} ik_aaa_float_info_t; + +typedef struct { + uint32 start_x; /* Unit in pixel*/ + uint32 start_y; + uint32 width; + uint32 height; +} ik_window_geomery_t; + +typedef struct { + uint32 width; /* Unit in pixel*/ + uint32 height; +} ik_window_dimension_t; + +typedef struct { + uint32 left_top_x; /* 16.16 format*/ + uint32 left_top_y; /* 16.16 format*/ + uint32 right_bot_x; /* 16.16 format*/ + uint32 right_bot_y; /* 16.16 format*/ +} ik_win_coordintates_t; + +typedef struct { + ik_window_dimension_t *input_win_dim; + ik_window_dimension_t *main_win_dim; + ik_window_dimension_t *out_cfa_win_dim; +} ik_warp_calc_cfa_info_t; + +typedef int32 (*ik_win_calc_cb_func_t)(ik_warp_calc_cfa_info_t *info); + +typedef struct { + ik_vin_sensor_geometry_t vin_sensor; + ik_window_dimension_t cfa_window; + ik_window_dimension_t main; + ik_window_dimension_t prev[3]; + ik_window_dimension_t thumbnail; + ik_window_dimension_t screennail; +} ik_window_size_info_t; + +typedef struct { + int16 x; + int16 y; +} ik_grid_point_t; + +typedef struct { + uint32 version; /* 0x20170101 */ + uint32 hor_grid_num; /* Horizontal grid number. */ + uint32 ver_grid_num; /* Vertical grid number. */ + uint32 tile_width_exp; /* 4:16, 5:32, 6:64, 7:128, 8:256, 9:512 */ + uint32 tile_height_exp; /* 4:16, 5:32, 6:64, 7:128, 8:256, 9:512 */ + ik_vin_sensor_geometry_t vin_sensor_geo; /* Vin sensor geometry when calibrating. */ + uint32 enb_2_stage_compensation : 1; /*1:enable, 0 disable*/ + uint32 reserved : 31; /* Reserved for extention. */ + ik_grid_point_t *pwarp; /* Warp grid vector arrey. */ +} ik_warp_info_t; + +typedef struct _img_dsp_core_dsp_warp_video_context_s_ { + int16 warp_hor[IK_WARP_VIDEO_MAXHORGRID * IK_WARP_VIDEO_MAXVERGRID]; + int16 warp_ver[IK_WARP_VIDEO_MAXHORGRID * IK_WARP_VIDEO_MAXVERGRID]; + int16 warp_ver_slice[IK_WARP_MAX_SLICE_NUMBER][IK_WARP_VIDEO_MAXHORGRID * IK_WARP_VIDEO_MAXVERGRID]; //use physical map + uint32 max_sliceNum; +} ik_warp_video_stitch_t; + +typedef struct { + uint32 version; /* 0x20130125 */ + uint32 hor_grid_num; /* Horizontal grid number. */ + uint32 ver_grid_num; /* Vertical grid number. */ + uint32 tile_width_exp; /* 4:16, 5:32, 6:64, 7:128, 8:256, 9:512 */ + uint32 tile_height_exp; /* 4:16, 5:32, 6:64, 7:128, 8:256, 9:512 */ + ik_vin_sensor_geometry_t vin_sensor_geo; /* Vin sensor geometry when calibrating. */ + uint32 Enb2StageCompensation : 1; + uint32 Reserved : 31; /* Reserved for extention. */ + ik_grid_point_t cawarp_red[1536]; /* Warp grid vector arrey. */ + ik_grid_point_t cawarp_blue[1536]; /* Warp grid vector arrey. */ +} ik_cawarp_info_t; + +typedef struct { + ik_cawarp_info_t calib_cawarp_info; + ik_window_size_info_t w_size_info; +} ik_cawarp_compensation_t; + +typedef struct { + uint32 enable; + uint32 zoom_x; /* 16.16 format*/ + uint32 zoom_y; /* 16.16 format*/ + int32 shift_x; /* 16.16 format, unit in pixel in VinSensorGeo domain.*/ + int32 shift_y; /* 16.16 format, unit in pixel in VinSensorGeo domain.*/ +} ik_dzoom_info_t; + +typedef struct { + uint32 enable; + uint32 left; + uint32 right; + uint32 top; + uint32 bottom; +} ik_dummy_margin_range_t; + +typedef struct { + uint32 enable; + ik_window_geomery_t active_geo; +} ik_vin_active_window_t; + +typedef struct { + ik_warp_info_t calib_warp_info; + ik_window_size_info_t w_size_info; +} ik_warp_compensation_t; + +typedef enum { + IK_WARP_CORE_SENSOR_H_FLIP = 1, + IK_WARP_CORE_SENSOR_V_FLIP = 2, + IK_WARP_CORE_DMA_H_FLIP = 4, + IK_WARP_CORE_DMA_V_FLIP = 8, +} ik_warp_flip_mode_e; + +typedef struct { + uint32 enable; +} ik_warp_multi_slice_info_t; + +typedef struct { + uint32 min_radius; + uint32 max_radius; +} ik_ce_radius_range_t; + +/* system performance */ +typedef struct { + int32 time_scale; /* fps */ + int32 num_units_in_tick; /* fps */ + int32 frame_length_lines; /* vb */ + int32 idsp_clock; /* clock */ +} ik_system_performance_info_t; + + +typedef struct { + int32 internal0; + int32 internal1; + int32 internal2; + int32 internal3; +} ik_bld_internal0_t; + +typedef struct { + uint32 enable; + uint32 pixel_map_width; + uint32 pixel_map_height; + uint32 pixel_map_pitch; + uint8 *p_map; +} ik_static_bad_pixel_correction_internal_t; + +typedef struct { + /* warp part */ + uint32 enable; + uint32 grid_array_width; + uint32 grid_array_height; + uint32 horz_grid_spacing_exponent; + uint32 vert_grid_spacing_exponent; + //uint32 vert_warp_enable; + uint32 vert_warp_grid_array_width; + uint32 vert_warp_grid_array_height; + uint32 vert_warp_horzgrid_spacing_exponent; + uint32 vert_warp_vert_grid_spacing_exponent; + int16 *pwarp_horizontal_table; + int16 *pwarp_vertical_table; + + /* dzoom part */ + //uint32 actual_left_top_x; + //uint32 actual_left_top_y; + //uint32 actual_right_bot_x; + //uint32 actual_right_bot_y; + //uint32 zoom_x; + //uint32 zoom_y; + //uint32 x_center_offset; + //uint32 y_center_offset; + //int32 horskewphaseinc; + //uint32 forcev4tapdisable; + //uint32 dummy_window_x_left; + //uint32 dummy_window_y_top; + //uint32 dummy_window_width; + //uint32 dummy_window_height; + //uint32 cfa_output_width; + //uint32 cfa_output_height; + //uint32 extra_sec2_ver_out_vid_mode; +} ik_warp_internal_info_t; + +typedef struct { + uint32 horz_warp_enable; + uint32 vert_warp_enable; + uint32 horz_pass_grid_array_width; + uint32 horz_pass_grid_array_height; + uint32 horz_pass_horz_grid_spacing_exponent; + uint32 horz_pass_vert_grid_spacing_exponent; + uint32 vert_pass_grid_array_width; + uint32 vert_pass_grid_array_height; + uint32 vert_pass_horz_grid_spacing_exponent; + uint32 vert_pass_vert_grid_spacing_exponent; + int16 warp_horztable_red[1536]; + int16 warp_verttable_red[1536]; + int16 warp_horztable_blue[1536]; + int16 warp_verttable_blue[1536]; +} ik_cawarp_internal_info_t; + +typedef struct { + uint32 decompand_enable; + uint32 decompand_table[145]; +} ik_frontend_tone_curve_t; + +typedef struct { + uint32 crop_enable; + uint32 crop_col_start; + uint32 crop_row_start; + uint32 crop_width; + uint32 crop_height; +}ik_vin_histogram_info_t; + +typedef struct { + uint32 ae_tile_mask[8]; +} ik_histogram_info_t; + +typedef struct { + uint32 enable; +} ik_negative_image_t; + +typedef struct { + uint32 enable; + int32 freq_blend_fir[10]; + uint32 act_sub; + uint32 act_mul; + uint32 sat_sub; + uint32 sat_mul; + uint32 sat_and_act_mul; + uint32 min_rgb; + uint32 max_rgb; + uint32 luma_lu[16]; + uint32 luma_diff_table[256]; +} ik_fusion_t; + + +typedef struct { + uint32 T0T1_add_high_cb; + uint32 T0T1_add_high_cr; + uint32 T0T1_add_high_delta_cb; + uint32 T0T1_add_high_delta_cr; + uint32 T0T1_add_high_strength_cb; + uint32 T0T1_add_high_strength_cr; + uint32 T0T1_add_low_cb; + uint32 T0T1_add_low_cr; + uint32 T0T1_add_low_delta_cb; + uint32 T0T1_add_low_delta_cr; + uint32 T0T1_add_low_strength_cb; + uint32 T0T1_add_low_strength_cr; + uint32 T0T1_add_mid_strength_cb; + uint32 T0T1_add_mid_strength_cr; + uint32 T0_cb; + uint32 T0_cr; + uint32 T1_cb; + uint32 T1_cr; + uint32 alpha_max_cb; + uint32 alpha_max_cr; + uint32 alpha_min_cb; + uint32 alpha_min_cr; + uint32 max_change_high_cb; + uint32 max_change_high_cr; + uint32 max_change_high_delta_cb; + uint32 max_change_high_delta_cr; + uint32 max_change_high_strength_cb; + uint32 max_change_high_strength_cr; + uint32 max_change_low_cb; + uint32 max_change_low_cr; + uint32 max_change_low_delta_cb; + uint32 max_change_low_delta_cr; + uint32 max_change_low_strength_cb; + uint32 max_change_low_strength_cr; + uint32 max_change_mid_strength_cb; + uint32 max_change_mid_strength_cr; +} ik_wide_chroma_filter_combine_t; +typedef struct { + /* 3a statistic */ + ik_aaa_stat_info_t aaa_stat_info; + ik_af_stat_ex_info_t af_stat_ex_info; + ik_pg_af_stat_ex_info_t pg_af_stat_ex_info; + ik_aaa_float_info_t aaa_float_tile_info; + + /* calibration */ + ik_window_size_info_t window_size_info; + ik_warp_info_t calib_warp_info; + ik_cawarp_info_t calib_ca_warp_info; + ik_static_bad_pxl_cor_t static_bpc; + ik_vignette_t vignette_compensation; + ik_dzoom_info_t dzoom_info; + uint32 sbp_enable; + uint32 warp_enable; + uint32 ca_warp_enable; + ik_dummy_margin_range_t dmy_range; + int32 flip_mode; + + /* normal filters */ + ik_static_blc_level_t static_blc; + ik_deferred_blc_level_t deferred_blc; + ik_wb_gain_t before_ce_wb_gain; + ik_wb_gain_t after_ce_wb_gain; + ik_ae_gain_t ae_gain; + ik_global_dgain_t global_dgain; + ik_cfa_leakage_filter_t cfa_leakage_filter; + ik_anti_aliasing_t anti_aliasing; + ik_dynamic_bad_pixel_correction_t dynamic_bpc; + ik_grgb_mismatch_t grgb_mismatch; + ik_cfa_noise_filter_t cfa_noise_filter; + ik_demosaic_t demosaic; + ik_color_correction_reg_t color_correction_reg; + ik_color_correction_t color_correction; + ik_tone_curve_t tone_curve; + ik_rgb_to_yuv_matrix_t rgb_to_yuv_matrix; + ik_rgb_ir_t rgb_ir; + ik_chroma_scale_t chroma_scale; + ik_chroma_median_filter_t chroma_median_filter; + ik_first_luma_process_mode_t first_luma_process_mode; + ik_adv_spatial_filter_t advance_spatial_filter; + ik_first_sharpen_both_t first_sharpen_both; + ik_first_sharpen_noise_t first_sharpen_noise; + ik_first_sharpen_fir_t first_sharpen_fir; + ik_first_sharpen_coring_t first_sharpen_coring; + + ik_first_sharpen_coring_idx_scale_t first_sharpen_coring_idx_scale; + ik_first_sharpen_min_coring_result_t first_sharpen_min_coring_result; + ik_first_sharpen_max_coring_result_t first_sharpen_max_coring_result; + ik_first_sharpen_scale_coring_t first_sharpen_scale_coring; + ik_final_sharpen_both_t final_sharpen_both; + ik_final_sharpen_noise_t final_sharpen_noise; + ik_final_sharpen_fir_t final_sharpen_fir; + ik_final_sharpen_coring_t final_sharpen_coring; + ik_final_sharpen_coring_idx_scale_t final_sharpen_coring_idx_scale; + ik_final_sharpen_min_coring_result_t final_sharpen_min_coring_result; + ik_final_sharpen_max_coring_result_t final_sharpen_max_coring_result; + ik_final_sharpen_scale_coring_t final_sharpen_scale_coring; + ik_final_sharpen_both_three_d_table_t final_sharpen_both_three_d_table; + ik_chroma_filter_t chroma_filter; + ik_video_mctf_t video_mctf; + ik_video_mctf_ta_t video_mctf_ta; + ik_video_mctf_ta_y_t video_mctf_ta_y; + ik_video_mctf_ta_cb_t video_mctf_ta_cb; + ik_video_mctf_ta_cr_t video_mctf_ta_cr; + + /* hdr */ + ik_hdr_raw_info_t hdr_raw_info; + ik_static_blc_level_t exp0_frontend_static_blc; + ik_static_blc_level_t exp1_frontend_static_blc; + ik_static_blc_level_t exp2_frontend_static_blc; + + ik_frontend_wb_gain_t exp0_frontend_wb_gain; + ik_frontend_wb_gain_t exp1_frontend_wb_gain; + ik_frontend_wb_gain_t exp2_frontend_wb_gain; + + ik_frontend_dgain_saturation_level_t exp0_dgain_saturation_level; + ik_frontend_dgain_saturation_level_t exp1_dgain_saturation_level; + ik_frontend_dgain_saturation_level_t exp2_dgain_saturation_level; + + ik_ce_t ce; + ik_ce_input_table_t ce_input_table; + ik_ce_output_table_t ce_out_table; + + ik_hdr_blend_t hdr_blend; + +} ik_user_parameters_t; + +uint32 ik_set_vin_sensor_info(uint32 context_id, const ik_vin_sensor_info_t *p_sensor_info); +uint32 ik_get_vin_sensor_info(uint32 context_id, ik_vin_sensor_info_t *p_sensor_info); + +uint32 ik_set_before_ce_wb_gain(uint32 context_id, const ik_wb_gain_t *p_before_ce_wb_gain); +uint32 ik_get_before_ce_wb_gain(uint32 context_id, ik_wb_gain_t *p_before_ce_wb_gain); + +uint32 ik_set_after_ce_wb_gain(uint32 context_id, const ik_wb_gain_t *p_after_ce_wb_gain); +uint32 ik_get_after_ce_wb_gain(uint32 context_id, ik_wb_gain_t *p_after_ce_wb_gain); + +uint32 ik_set_cfa_leakage_filter(uint32 context_id, const ik_cfa_leakage_filter_t *p_cfa_leakage_filter); +uint32 ik_get_cfa_leakage_filter(uint32 context_id, ik_cfa_leakage_filter_t *p_cfa_leakage_filter); + +uint32 ik_set_grgb_mismatch(uint32 context_id, const ik_grgb_mismatch_t *p_grgb_mismatch); +uint32 ik_get_grgb_mismatch(uint32 context_id, ik_grgb_mismatch_t *p_grgb_mismatch); + +uint32 ik_set_anti_aliasing(uint32 context_id, const ik_anti_aliasing_t *p_anti_aliasing); +uint32 ik_get_anti_aliasing(uint32 context_id, ik_anti_aliasing_t *p_anti_aliasing); + +uint32 ik_set_dynamic_bad_pixel_corr(uint32 context_id, const ik_dynamic_bad_pixel_correction_t *p_dynamic_bpc); +uint32 ik_get_dynamic_bad_pixel_corr(uint32 context_id, ik_dynamic_bad_pixel_correction_t *p_dynamic_bpc); + +uint32 ik_set_cfa_noise_filter(uint32 context_id, const ik_cfa_noise_filter_t *p_cfa_noise_filter); +uint32 ik_get_cfa_noise_filter(uint32 context_id, ik_cfa_noise_filter_t *p_cfa_noise_filter); + +uint32 ik_set_demosaic(uint32 context_id, const ik_demosaic_t *p_demosaic); +uint32 ik_get_demosaic(uint32 context_id, ik_demosaic_t *p_demosaic); + +uint32 ik_set_color_correction_reg(uint32 context_id, const ik_color_correction_reg_t *p_color_correction_reg); +uint32 ik_get_color_correction_reg(uint32 context_id, ik_color_correction_reg_t *p_color_correction_reg); + +uint32 ik_set_color_correction(uint32 context_id, const ik_color_correction_t *p_color_correction); +uint32 ik_get_color_correction(uint32 context_id, ik_color_correction_t *p_color_correction); + +uint32 ik_set_tone_curve(uint32 context_id, const ik_tone_curve_t *p_tone_curve); +uint32 ik_get_tone_curve(uint32 context_id, ik_tone_curve_t *p_tone_curve); + +uint32 ik_set_rgb_to_yuv_matrix(uint32 context_id, const ik_rgb_to_yuv_matrix_t *p_rgb_to_yuv_matrix); +uint32 ik_get_rgb_to_yuv_matrix(uint32 context_id, ik_rgb_to_yuv_matrix_t *p_rgb_to_yuv_matrix); + +uint32 ik_set_rgb_ir(uint32 context_id, const ik_rgb_ir_t *p_rgb_ir); +uint32 ik_get_rgb_ir(uint32 context_id, ik_rgb_ir_t *p_rgb_ir); + +uint32 ik_set_chroma_scale(uint32 context_id, const ik_chroma_scale_t *p_chroma_scale); +uint32 ik_get_chroma_scale(uint32 context_id, ik_chroma_scale_t *p_chroma_scale); + +uint32 ik_set_chroma_filter(uint32 context_id, const ik_chroma_filter_t *p_chroma_filter); +uint32 ik_get_chroma_filter(uint32 context_id, ik_chroma_filter_t *p_chroma_filter); + +uint32 ik_set_variable_range(uint32 context_id, const ik_variable_range_t *p_variable_range); +uint32 ik_get_variable_range(uint32 context_id, ik_variable_range_t *p_variable_range); + +uint32 ik_set_chroma_median_filter(uint32 context_id, const ik_chroma_median_filter_t *p_chroma_median_filter); +uint32 ik_get_chroma_median_filter(uint32 context_id, ik_chroma_median_filter_t *p_chroma_median_filter); + +uint32 ik_set_fst_luma_process_mode(uint32 context_id, const ik_first_luma_process_mode_t *p_first_luma_process_mode); +uint32 ik_get_fst_luma_process_mode(uint32 context_id, ik_first_luma_process_mode_t *p_first_luma_process_mode); + +uint32 ik_set_adv_spatial_filter(uint32 context_id, const ik_adv_spatial_filter_t *p_advance_spatial_filter); +uint32 ik_get_adv_spatial_filter(uint32 context_id, ik_adv_spatial_filter_t *p_advance_spatial_filter); + +uint32 ik_set_fst_shp_both(uint32 context_id, const ik_first_sharpen_both_t *p_first_sharpen_both); +uint32 ik_get_fst_shp_both(uint32 context_id, ik_first_sharpen_both_t *p_first_sharpen_both); + +uint32 ik_set_fst_shp_fir(uint32 context_id, const ik_first_sharpen_fir_t *p_first_sharpen_fir); +uint32 ik_get_fst_shp_fir(uint32 context_id, ik_first_sharpen_fir_t *p_first_sharpen_fir); + +uint32 ik_set_fst_shp_noise(uint32 context_id, const ik_first_sharpen_noise_t *p_first_sharpen_noise); +uint32 ik_get_fst_shp_noise(uint32 context_id, ik_first_sharpen_noise_t *p_first_sharpen_noise); + +uint32 ik_set_fst_shp_coring(uint32 context_id, const ik_first_sharpen_coring_t *p_first_sharpen_coring); +uint32 ik_get_fst_shp_coring(uint32 context_id, ik_first_sharpen_coring_t *p_first_sharpen_coring); + +uint32 ik_set_fst_shp_coring_idx_scale(uint32 context_id, const ik_first_sharpen_coring_idx_scale_t *p_first_sharpen_coring_idx_scale); +uint32 ik_get_fst_shp_coring_idx_scale(uint32 context_id, ik_first_sharpen_coring_idx_scale_t *p_first_sharpen_coring_idx_scale); + +uint32 ik_set_fst_shp_min_coring_rslt(uint32 context_id, const ik_first_sharpen_min_coring_result_t *p_first_sharpen_min_coring_result); +uint32 ik_get_fst_shp_min_coring_rslt(uint32 context_id, ik_first_sharpen_min_coring_result_t *p_first_sharpen_min_coring_result); + +uint32 ik_set_fst_shp_max_coring_rslt(uint32 context_id, const ik_first_sharpen_max_coring_result_t *p_first_sharpen_max_coring_result); +uint32 ik_get_fst_shp_max_coring_rslt(uint32 context_id, ik_first_sharpen_max_coring_result_t *p_first_sharpen_max_coring_result); + +uint32 ik_set_fst_shp_scale_coring(uint32 context_id, const ik_first_sharpen_scale_coring_t *p_first_sharpen_scale_coring); +uint32 ik_get_fst_shp_scale_coring(uint32 context_id, ik_first_sharpen_scale_coring_t *p_first_sharpen_scale_coring); + +uint32 ik_set_fnl_shp_both(uint32 context_id, const ik_final_sharpen_both_t *p_final_sharpen_both); +uint32 ik_get_fnl_shp_both(uint32 context_id, ik_final_sharpen_both_t *p_final_sharpen_both); + +uint32 ik_set_fnl_shp_fir(uint32 context_id, const ik_final_sharpen_fir_t *p_final_sharpen_fir); +uint32 ik_get_fnl_shp_fir(uint32 context_id, ik_final_sharpen_fir_t *p_final_sharpen_fir); + +uint32 ik_set_fnl_shp_noise(uint32 context_id, const ik_final_sharpen_noise_t *p_final_sharpen_noise); +uint32 ik_get_fnl_shp_noise(uint32 context_id, ik_final_sharpen_noise_t *p_final_sharpen_noise); + +uint32 ik_set_fnl_shp_coring(uint32 context_id, const ik_final_sharpen_coring_t *p_final_sharpen_coring); +uint32 ik_get_fnl_shp_coring(uint32 context_id, ik_final_sharpen_coring_t *p_final_sharpen_coring); + +uint32 ik_set_fnl_shp_coring_idx_scale(uint32 context_id, const ik_final_sharpen_coring_idx_scale_t *p_final_sharpen_coring_idx_scale); +uint32 ik_get_fnl_shp_coring_idx_scale(uint32 context_id, ik_final_sharpen_coring_idx_scale_t *p_final_sharpen_coring_idx_scale); + +uint32 ik_set_fnl_shp_min_coring_rslt(uint32 context_id, const ik_final_sharpen_min_coring_result_t *p_final_sharpen_min_coring_result); +uint32 ik_get_fnl_shp_min_coring_rslt(uint32 context_id, ik_final_sharpen_min_coring_result_t *p_final_sharpen_min_coring_result); + +uint32 ik_set_fnl_shp_max_coring_rslt(uint32 context_id, const ik_final_sharpen_max_coring_result_t *p_final_sharpen_max_coring_result); +uint32 ik_get_fnl_shp_max_coring_rslt(uint32 context_id, ik_final_sharpen_max_coring_result_t *p_final_sharpen_max_coring_result); + +uint32 ik_set_fnl_shp_scale_coring(uint32 context_id, const ik_final_sharpen_scale_coring_t *p_final_sharpen_scale_coring); +uint32 ik_get_fnl_shp_scale_coring(uint32 context_id, ik_final_sharpen_scale_coring_t *p_final_sharpen_scale_coring); + +uint32 ik_set_fnl_shp_three_d_table(uint32 context_id, const ik_final_sharpen_both_three_d_table_t *p_final_sharpen_both_three_d_table); +uint32 ik_get_fnl_shp_three_d_table(uint32 context_id, ik_final_sharpen_both_three_d_table_t *p_final_sharpen_both_three_d_table); + +uint32 ik_set_video_mctf(uint32 context_id, const ik_video_mctf_t *p_video_mctf); +uint32 ik_get_video_mctf(uint32 context_id, ik_video_mctf_t *p_video_mctf); + +uint32 ik_set_video_mctf_ta(uint32 context_id, const ik_video_mctf_ta_t *p_video_mctf_ta); +uint32 ik_get_video_mctf_ta(uint32 context_id, ik_video_mctf_ta_t *p_video_mctf_ta); + +uint32 ik_set_video_mctf_and_fnl_shp(uint32 context_id, const ik_pos_dep33_t *p_video_mctf_and_final_sharpen); +uint32 ik_get_video_mctf_and_fnl_shp(uint32 context_id, ik_pos_dep33_t *p_video_mctf_and_final_sharpen); + +uint32 ik_set_motion_detect(uint32 context_id, const ik_motion_detect_t *p_motion_detect); +uint32 ik_get_motion_detect(uint32 context_id, ik_motion_detect_t *p_motion_detect); + +uint32 ik_set_motion_detect_pos_dep(uint32 context_id, const ik_pos_dep33_t *p_motion_detect_pos_dep); +uint32 ik_get_motion_detect_pos_dep(uint32 context_id, ik_pos_dep33_t *p_motion_detect_pos_dep); + +uint32 ik_set_motion_detect_and_mctf(uint32 context_id, const ik_motion_detect_and_mctf_t *p_motion_detect_and_mctf); +uint32 ik_get_motion_detect_and_mctf(uint32 context_id, ik_motion_detect_and_mctf_t *p_motion_detect_and_mctf); + +uint32 ik_set_dzoom_info(uint32 context_id, const ik_dzoom_info_t *p_dzoom_info); +uint32 ik_get_dzoom_info(uint32 context_id, ik_dzoom_info_t *p_dzoom_info);; + +uint32 ik_set_window_size_info(uint32 context_id, const ik_window_size_info_t *p_window_size_info); +uint32 ik_get_window_size_info(uint32 context_id, ik_window_size_info_t *p_window_size_info); + +uint32 ik_set_dummy_margin_range(uint32 context_id, const ik_dummy_margin_range_t *p_dmy_margin_range); +uint32 ik_get_dummy_margin_range(uint32 context_id, ik_dummy_margin_range_t *p_dmy_margin_range); + +uint32 ik_set_vin_active_win(uint32 context_id, const ik_vin_active_window_t *p_vin_active_win); +uint32 ik_get_vin_active_win(uint32 context_id, ik_vin_active_window_t *p_vin_active_win); + +uint32 ik_set_system_performance_info(uint32 context_id, const ik_system_performance_info_t *p_sys_performance_info); +uint32 ik_get_system_performance_info(uint32 context_id, ik_system_performance_info_t *p_sys_performance_info); + +uint32 ik_set_resampler_strength(uint32 context_id, const ik_resampler_strength_t *p_resampler_strength); +uint32 ik_get_resampler_strength(uint32 context_id, ik_resampler_strength_t *p_resampler_strength); + + +/* Calibration filters */ +uint32 ik_set_warp_enb(uint32 context_id, const uint32 enb); +uint32 ik_get_warp_enb(uint32 context_id, uint32 *p_enb); + +uint32 ik_set_warp_info(uint32 context_id, const ik_warp_info_t *p_calib_warp_info); +uint32 ik_get_warp_info(uint32 context_id, ik_warp_info_t *p_calib_warp_info); + +uint32 ik_set_cawarp_enb(uint32 context_id, const uint32 enb); +uint32 ik_get_cawarp_enb(uint32 context_id, uint32 *p_enb); + +uint32 ik_set_cawarp_info(uint32 context_id, const ik_cawarp_info_t *p_calib_ca_warp_info); +uint32 ik_get_cawarp_info(uint32 context_id, ik_cawarp_info_t *p_calib_ca_warp_info); + +uint32 ik_set_static_bad_pxl_corr_enb(uint32 context_id, const uint32 enb); +uint32 ik_get_static_bad_pxl_corr_enb(uint32 context_id, uint32 *p_enb); + +uint32 ik_set_static_bad_pxl_corr(uint32 context_id, const ik_static_bad_pxl_cor_t *p_static_bpc); +uint32 ik_get_static_bad_pxl_corr(uint32 context_id, ik_static_bad_pxl_cor_t *p_static_bpc); + +uint32 ik_set_vignette_enb(uint32 context_id, const uint32 enb); +uint32 ik_get_vignette_enb(uint32 context_id, uint32 *p_enb); + +uint32 ik_set_vignette(uint32 context_id, const ik_vignette_t *p_vignette); +uint32 ik_get_vignette(uint32 context_id, ik_vignette_t *p_vignette); + +uint32 ik_set_static_bad_pxl_corr_itnl(uint32 context_id, const ik_static_bad_pixel_correction_internal_t *p_static_bpc_internal); +uint32 ik_get_static_bad_pxl_corr_itnl(uint32 context_id, ik_static_bad_pixel_correction_internal_t *p_static_bpc_internal); + +uint32 ik_set_cawarp_internal(uint32 context_id, const ik_cawarp_internal_info_t *p_cawarp_internal); +uint32 ik_get_cawarp_internal(uint32 context_id, ik_cawarp_internal_info_t *p_cawarp_internal); + +uint32 ik_set_warp_internal(uint32 context_id,const ik_warp_internal_info_t *p_warp_dzoom_internal); +uint32 ik_get_warp_internal(uint32 context_id,ik_warp_internal_info_t *p_warp_dzoom_internal); + + +/* HDR filters */ +uint32 ik_set_exp0_frontend_static_blc(uint32 context_id, const ik_static_blc_level_t *p_exp0_frontend_static_blc); +uint32 ik_get_exp0_frontend_static_blc(uint32 context_id, ik_static_blc_level_t *p_exp0_frontend_static_blc); + +uint32 ik_set_exp1_frontend_static_blc(uint32 context_id, const ik_static_blc_level_t *p_exp1_frontend_static_blc); +uint32 ik_get_exp1_frontend_static_blc(uint32 context_id, ik_static_blc_level_t *p_exp1_frontend_static_blc); + +uint32 ik_set_exp2_frontend_static_blc(uint32 context_id, const ik_static_blc_level_t *p_exp2_frontend_static_blc); +uint32 ik_get_exp2_frontend_static_blc(uint32 context_id, ik_static_blc_level_t *p_exp2_frontend_static_blc); + +uint32 ik_set_exp0_frontend_wb_gain(uint32 context_id, const ik_frontend_wb_gain_t *p_exp0_frontend_wb_gain); +uint32 ik_get_exp0_frontend_wb_gain(uint32 context_id, ik_frontend_wb_gain_t *p_exp0_frontend_wb_gain); + +uint32 ik_set_exp1_frontend_wb_gain(uint32 context_id, const ik_frontend_wb_gain_t *p_exp1_frontend_wb_gain); +uint32 ik_get_exp1_frontend_wb_gain(uint32 context_id, ik_frontend_wb_gain_t *p_exp1_frontend_wb_gain); + +uint32 ik_set_exp2_frontend_wb_gain(uint32 context_id, const ik_frontend_wb_gain_t *p_exp2_frontend_wb_gain); +uint32 ik_get_exp2_frontend_wb_gain(uint32 context_id, ik_frontend_wb_gain_t *p_exp2_frontend_wb_gain); + +uint32 ik_set_ce(uint32 context_id, const ik_ce_t *p_ce); +uint32 ik_get_ce(uint32 context_id, ik_ce_t *p_ce); + +uint32 ik_set_ce_input_table(uint32 context_id, const ik_ce_input_table_t *p_ce_input_table); +uint32 ik_get_ce_input_table(uint32 context_id, ik_ce_input_table_t *p_ce_input_table); + +uint32 ik_set_ce_out_table(uint32 context_id, const ik_ce_output_table_t *p_ce_out_table); +uint32 ik_get_ce_out_table(uint32 context_id, ik_ce_output_table_t *p_ce_out_table); + +uint32 ik_set_hdr_blend(uint32 context_id, const ik_hdr_blend_t *p_hdr_blend); +uint32 ik_get_hdr_blend(uint32 context_id, ik_hdr_blend_t *p_hdr_blend); + +uint32 ik_set_aaa_stat_info(uint32 context_id, const ik_aaa_stat_info_t *p_stat_info); +uint32 ik_get_aaa_stat_info(uint32 context_id, ik_aaa_stat_info_t *p_stat_info); + +uint32 ik_set_af_stat_ex_info(uint32 context_id, const ik_af_stat_ex_info_t *p_af_stat_ex_info); +uint32 ik_get_af_stat_ex_info(uint32 context_id, ik_af_stat_ex_info_t *p_af_stat_ex_info); + +uint32 ik_set_pg_af_stat_ex_info(uint32 context_id, const ik_pg_af_stat_ex_info_t *p_pg_af_stat_ex_info); +uint32 ik_get_pg_af_stat_ex_info(uint32 context_id, ik_pg_af_stat_ex_info_t *p_pg_af_stat_ex_info); + +uint32 ik_set_frontend_tone_curve(uint32 context_id, const ik_frontend_tone_curve_t *p_fe_tc); +uint32 ik_get_frontend_tone_curve(uint32 context_id, ik_frontend_tone_curve_t *p_fe_tc); + +uint32 ik_set_hdr_raw_offset(uint32 context_id, const ik_hdr_raw_info_t *p_hdr_raw_info); +uint32 ik_get_hdr_raw_offset(uint32 context_id, ik_hdr_raw_info_t *p_hdr_raw_info); + +uint32 ik_set_vin_histogram_info(uint32 context_id, const ik_vin_histogram_info_t *p_hist_info); +uint32 ik_get_vin_histogram_info(uint32 context_id, ik_vin_histogram_info_t *p_hist_info); + +uint32 ik_set_histogram_info(uint32 context_id, const ik_histogram_info_t *p_hist_info); +uint32 ik_get_histogram_info(uint32 context_id, ik_histogram_info_t *p_hist_info); + +uint32 ik_set_pg_histogram_info(uint32 context_id, const ik_histogram_info_t *p_hist_info); +uint32 ik_get_pg_histogram_info(uint32 context_id, ik_histogram_info_t *p_hist_info); + +uint32 ik_set_y2y_use_cc_enable_info(uint32 context_id, const uint32 enable); +uint32 ik_get_y2y_use_cc_enable_info(uint32 context_id, uint32 *enable); + +uint32 ik_set_negative_image(uint32 context_id, const ik_negative_image_t *p_neg_image); +uint32 ik_get_negative_image(uint32 context_id, ik_negative_image_t *p_neg_image); + +uint32 ik_set_fusion(uint32 context_id, const ik_fusion_t *p_fusion); +uint32 ik_get_fusion(uint32 context_id, ik_fusion_t *p_fusion); +uint32 ik_set_mono_static_bad_pxl_corr(uint32 context_id, const ik_static_bad_pxl_cor_t *p_static_bpc); +uint32 ik_get_mono_static_bad_pxl_corr(uint32 context_id, ik_static_bad_pxl_cor_t *p_static_bpc); +uint32 ik_set_mono_vignette(uint32 context_id, const ik_vignette_t *p_vignette); +uint32 ik_get_mono_vignette(uint32 context_id, ik_vignette_t *p_vignette); +uint32 ik_set_mono_before_ce_wb_gain(uint32 context_id, const ik_wb_gain_t *p_before_ce_wb_gain); +uint32 ik_get_mono_before_ce_wb_gain(uint32 context_id, ik_wb_gain_t *p_before_ce_wb_gain); +uint32 ik_set_mono_after_ce_wb_gain(uint32 context_id, const ik_wb_gain_t *p_after_ce_wb_gain); +uint32 ik_get_mono_after_ce_wb_gain(uint32 context_id, ik_wb_gain_t *p_after_ce_wb_gain); +uint32 ik_set_mono_cfa_leakage_filter(uint32 context_id, const ik_cfa_leakage_filter_t *p_cfa_leakage_filter); +uint32 ik_get_mono_cfa_leakage_filter(uint32 context_id, ik_cfa_leakage_filter_t *p_cfa_leakage_filter); +uint32 ik_set_mono_anti_aliasing(uint32 context_id, const ik_anti_aliasing_t *p_anti_aliasing); +uint32 ik_get_mono_anti_aliasing(uint32 context_id, ik_anti_aliasing_t *p_anti_aliasing); +uint32 ik_set_mono_dynamic_bad_pixel_corr(uint32 context_id, const ik_dynamic_bad_pixel_correction_t *p_dynamic_bpc); +uint32 ik_get_mono_dynamic_bad_pixel_corr(uint32 context_id, ik_dynamic_bad_pixel_correction_t *p_dynamic_bpc); +uint32 ik_set_mono_grgb_mismatch(uint32 context_id, const ik_grgb_mismatch_t *p_grgb_mismatch); +uint32 ik_get_mono_grgb_mismatch(uint32 context_id, ik_grgb_mismatch_t *p_grgb_mismatch); +uint32 ik_set_mono_cfa_noise_filter(uint32 context_id, const ik_cfa_noise_filter_t *p_cfa_noise_filter); +uint32 ik_get_mono_cfa_noise_filter(uint32 context_id, ik_cfa_noise_filter_t *p_cfa_noise_filter); +uint32 ik_set_mono_demosaic(uint32 context_id, const ik_demosaic_t *p_demosaic); +uint32 ik_get_mono_demosaic(uint32 context_id, ik_demosaic_t *p_demosaic); +uint32 ik_set_mono_color_correction_reg(uint32 context_id, const ik_color_correction_reg_t *p_color_correction_reg); +uint32 ik_get_mono_color_correction_reg(uint32 context_id, ik_color_correction_reg_t *p_color_correction_reg); +uint32 ik_set_mono_color_correction(uint32 context_id, const ik_color_correction_t *p_color_correction); +uint32 ik_get_mono_color_correction(uint32 context_id, ik_color_correction_t *p_color_correction); +uint32 ik_set_mono_tone_curve(uint32 context_id, const ik_tone_curve_t *p_tone_curve); +uint32 ik_get_mono_tone_curve(uint32 context_id, ik_tone_curve_t *p_tone_curve); +uint32 ik_set_mono_rgb_to_yuv_matrix(uint32 context_id, const ik_rgb_to_yuv_matrix_t *p_rgb_to_yuv_matrix); +uint32 ik_get_mono_rgb_to_yuv_matrix(uint32 context_id, ik_rgb_to_yuv_matrix_t *p_rgb_to_yuv_matrix); +uint32 ik_set_mono_fst_luma_process_mode(uint32 context_id, const ik_first_luma_process_mode_t *p_first_luma_process_mode); +uint32 ik_get_mono_fst_luma_process_mode(uint32 context_id, ik_first_luma_process_mode_t *p_first_luma_process_mode); +uint32 ik_set_mono_adv_spatial_filter(uint32 context_id, const ik_adv_spatial_filter_t *p_advance_spatial_filter); +uint32 ik_get_mono_adv_spatial_filter(uint32 context_id, ik_adv_spatial_filter_t *p_advance_spatial_filter); +uint32 ik_set_mono_fst_shp_both(uint32 context_id, const ik_first_sharpen_both_t *p_first_sharpen_both); +uint32 ik_get_mono_fst_shp_both(uint32 context_id, ik_first_sharpen_both_t *p_first_sharpen_both); +uint32 ik_set_mono_fst_shp_noise(uint32 context_id, const ik_first_sharpen_noise_t *p_first_sharpen_noise); +uint32 ik_get_mono_fst_shp_noise(uint32 context_id, ik_first_sharpen_noise_t *p_first_sharpen_noise); +uint32 ik_set_mono_fst_shp_fir(uint32 context_id, const ik_first_sharpen_fir_t *p_first_sharpen_fir); +uint32 ik_get_mono_fst_shp_fir(uint32 context_id, ik_first_sharpen_fir_t *p_first_sharpen_fir); +uint32 ik_set_mono_fst_shp_coring(uint32 context_id, const ik_first_sharpen_coring_t *p_first_sharpen_coring); +uint32 ik_get_mono_fst_shp_coring(uint32 context_id, ik_first_sharpen_coring_t *p_first_sharpen_coring); +uint32 ik_set_mono_fst_shp_coring_idx_scale(uint32 context_id, const ik_first_sharpen_coring_idx_scale_t *p_first_sharpen_coring_idx_scale); +uint32 ik_get_mono_fst_shp_coring_idx_scale(uint32 context_id, ik_first_sharpen_coring_idx_scale_t *p_first_sharpen_coring_idx_scale); +uint32 ik_set_mono_fst_shp_min_coring_rslt(uint32 context_id, const ik_first_sharpen_min_coring_result_t *p_first_sharpen_min_coring_result); +uint32 ik_get_mono_fst_shp_min_coring_rslt(uint32 context_id, ik_first_sharpen_min_coring_result_t *p_first_sharpen_min_coring_result); +uint32 ik_set_mono_fst_shp_max_coring_rslt(uint32 context_id, const ik_first_sharpen_max_coring_result_t *p_first_sharpen_max_coring_result); +uint32 ik_get_mono_fst_shp_max_coring_rslt(uint32 context_id, ik_first_sharpen_max_coring_result_t *p_first_sharpen_max_coring_result); +uint32 ik_set_mono_fst_shp_scale_coring(uint32 context_id, const ik_first_sharpen_scale_coring_t *p_first_sharpen_scale_coring); +uint32 ik_get_mono_fst_shp_scale_coring(uint32 context_id, ik_first_sharpen_scale_coring_t *p_first_sharpen_scale_coring); +uint32 ik_set_wide_chroma_filter(uint32 context_id, const ik_chroma_filter_t *p_chroma_filter); +uint32 ik_get_wide_chroma_filter(uint32 context_id, ik_chroma_filter_t *p_chroma_filter); +uint32 ik_set_wide_chroma_filter_combine(uint32 context_id, const ik_wide_chroma_filter_combine_t *p_chroma_filter_combine); +uint32 ik_get_wide_chroma_filter_combine(uint32 context_id, ik_wide_chroma_filter_combine_t *p_chroma_filter_combine); +uint32 ik_set_mono_exp0_frontend_static_blc(uint32 context_id, const ik_static_blc_level_t *p_exp0_frontend_static_blc); +uint32 ik_get_mono_exp0_frontend_static_blc(uint32 context_id, ik_static_blc_level_t *p_exp0_frontend_static_blc); +uint32 ik_set_mono_exp0_frontend_wb_gain(uint32 context_id, const ik_frontend_wb_gain_t *p_exp0_frontend_wb_gain); +uint32 ik_get_mono_exp0_frontend_wb_gain(uint32 context_id, ik_frontend_wb_gain_t *p_exp0_frontend_wb_gain); +uint32 ik_set_mono_ce(uint32 context_id, const ik_ce_t *p_ce); +uint32 ik_get_mono_ce(uint32 context_id, ik_ce_t *p_ce); +uint32 ik_set_mono_ce_input_table(uint32 context_id, const ik_ce_input_table_t *p_ce_input_table); +uint32 ik_get_mono_ce_input_table(uint32 context_id, ik_ce_input_table_t *p_ce_input_table); +uint32 ik_set_mono_ce_out_table(uint32 context_id, const ik_ce_output_table_t *p_ce_out_table); +uint32 ik_get_mono_ce_out_table(uint32 context_id, ik_ce_output_table_t *p_ce_out_table); + +uint32 ik_set_dewarp_fst_shp_both(uint32 context_id, const ik_first_sharpen_both_t *p_first_sharpen_both); +uint32 ik_get_dewarp_fst_shp_both(uint32 context_id, ik_first_sharpen_both_t *p_first_sharpen_both); + +uint32 ik_set_dewarp_fst_shp_fir(uint32 context_id, const ik_first_sharpen_fir_t *p_first_sharpen_fir); +uint32 ik_get_dewarp_fst_shp_fir(uint32 context_id, ik_first_sharpen_fir_t *p_first_sharpen_fir); + +uint32 ik_set_dewarp_fst_shp_noise(uint32 context_id, const ik_first_sharpen_noise_t *p_first_sharpen_noise); +uint32 ik_get_dewarp_fst_shp_noise(uint32 context_id, ik_first_sharpen_noise_t *p_first_sharpen_noise); + +uint32 ik_set_dewarp_fst_shp_coring(uint32 context_id, const ik_first_sharpen_coring_t *p_first_sharpen_coring); +uint32 ik_get_dewarp_fst_shp_coring(uint32 context_id, ik_first_sharpen_coring_t *p_first_sharpen_coring); + +uint32 ik_set_dewarp_fst_shp_coring_idx_scale(uint32 context_id, const ik_first_sharpen_coring_idx_scale_t *p_first_sharpen_coring_idx_scale); +uint32 ik_get_dewarp_fst_shp_coring_idx_scale(uint32 context_id, ik_first_sharpen_coring_idx_scale_t *p_first_sharpen_coring_idx_scale); + +uint32 ik_set_dewarp_fst_shp_min_coring_rslt(uint32 context_id, const ik_first_sharpen_min_coring_result_t *p_first_sharpen_min_coring_result); +uint32 ik_get_dewarp_fst_shp_min_coring_rslt(uint32 context_id, ik_first_sharpen_min_coring_result_t *p_first_sharpen_min_coring_result); + +uint32 ik_set_dewarp_fst_shp_max_coring_rslt(uint32 context_id, const ik_first_sharpen_max_coring_result_t *p_first_sharpen_max_coring_result); +uint32 ik_get_dewarp_fst_shp_max_coring_rslt(uint32 context_id, ik_first_sharpen_max_coring_result_t *p_first_sharpen_max_coring_result); + +uint32 ik_set_dewarp_fst_shp_scale_coring(uint32 context_id, const ik_first_sharpen_scale_coring_t *p_first_sharpen_scale_coring); +uint32 ik_get_dewarp_fst_shp_scale_coring(uint32 context_id, ik_first_sharpen_scale_coring_t *p_first_sharpen_scale_coring); + +#endif diff --git a/include/ambarella/arch_v5/AmbaDSP_ImgUtility.h b/include/ambarella/arch_v5/AmbaDSP_ImgUtility.h new file mode 100644 index 0000000..9d4b277 --- /dev/null +++ b/include/ambarella/arch_v5/AmbaDSP_ImgUtility.h @@ -0,0 +1,43 @@ +#ifndef IMG_UTILITY_H +#define IMG_UTILITY_H + +#include "datatype.h" +//#include "AmbaDSP_ImgOSAL.h" +#include "AmbaDSP_ImgFilter.h" +//#include "AmbaDSP_ImgArchSpec.h" +#include "AmbaDSP_ImgArchSystemAPI.h" + +typedef struct { + uintptr iso_config_addr; + uint32 iso_config_tag; + // update flags +} executed_iso_config_result_t; + +typedef struct { + uintptr hdr_ce_config_addr; + uint32 hdr_ce_config_tag; + // update flags +} executed_hdr_ce_config_result_t; + +typedef struct { + uint32 context_number; + struct { + uint32 config_number; + ik_ability_t *ability; + ik_user_parameters_t *default_setting; + } config_setting[MAX_CONTEXT_NUM]; +} ik_context_setting_t; + +uint32 ik_import_system_callback_func(const ik_system_api_t *p_sys_api); +uint32 ik_query_arch_memory_size(const ik_context_setting_t *p_setting_of_each_context, size_t *p_total_ctx_size); +uint32 ik_init_arch(const ik_context_setting_t *p_setting_of_each_context, void* p_mem_addr, size_t mem_size, uint32 ik_init_mode); +uint32 ik_get_filter_default_values(ik_user_parameters_t *p_default_values); +uint32 ik_init_context(uint32 context_id, const ik_ability_t *p_ability, const ik_user_parameters_t *p_default_values); +uint32 ik_get_context_ability(uint32 context_id, ik_ability_t *p_ability); +uint32 ik_execute_config(uint32 context_id, ik_execute_container_t *p_execute_container); +uint32 ik_lock_config(uint32 config_tag); +uint32 ik_query_debug_config_size(size_t *p_size); +uint32 ik_dump_debug_config(uint32 context_id, uint32 previous_count, void *p_user_buffer, size_t size); + + +#endif diff --git a/include/ambarella/arch_v5/ambas_imgproc_arch.h b/include/ambarella/arch_v5/ambas_imgproc_arch.h new file mode 100644 index 0000000..16b189c --- /dev/null +++ b/include/ambarella/arch_v5/ambas_imgproc_arch.h @@ -0,0 +1,621 @@ +/* + * ambas_imgproc_arch.h + * + * History: + * 2012/10/10 - [Cao Rongrong] created file + * 2013/12/12 - [Jian Tang] modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __AMBAS_IMGPROC_ARCH_H__ +#define __AMBAS_IMGPROC_ARCH_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "config.h" + +#define IMG_MAX_VIN_CHANNEL_NUM (8) +#define MAX_3A_STATS_SLICE_ROW (2) +#define MAX_3A_STATS_SLICE_COL (2) +#define MAX_SLICE_FOR_STAT (8) +#define MAX_STATS_FRAME_NUM (2) + +#define INVALID_AAA_DATA_ENTRY (0xFF) +#define RGB_AAA_DATA_BLOCK (2176) +#define CFA_AAA_DATA_BLOCK (12672) +#define VIN_AAA_DATA_BLOCK (2176) + +#define MAX_EXPOSURE_NUM (3) + +#define SENSOR_HIST_ROW_NUM (2) +#define SENSOR_HIST_DATA_PITCH (2080 * 2) +#define SENSOR_HIST_DATA_BLOCK (SENSOR_HIST_DATA_PITCH * SENSOR_HIST_ROW_NUM * 2) +#define VIN_HISTOGRAM_BIN_NUM (128) +#define HIST_BIN_NUM (64) + +#define COMP_LUT_ENTRY_NUM (45) +#define DECOMP_LUT_ENTRY_NUM (145) + + + +typedef struct{ + // 1 u32 + u16 awb_tile_col_start; + u16 awb_tile_row_start; + // 2 u32 + u16 awb_tile_width; + u16 awb_tile_height; + // 3 u32 + u16 awb_tile_active_width; + u16 awb_tile_active_height; + //4 u32 + u16 awb_rgb_shift; + u16 awb_y_shift; + //5 u32 + u16 awb_min_max_shift; + u16 ae_tile_col_start; + //6 u32 + u16 ae_tile_row_start; + u16 ae_tile_width; + //7 u32 + u16 ae_tile_height; + u16 ae_y_shift; + //8 u32 + u16 ae_linear_y_shift; + u16 ae_min_max_shift; + + //9 u32 + u16 af_tile_col_start; + u16 af_tile_row_start; + + //10 u32 + u16 af_tile_width; + u16 af_tile_height; + + //11 u32 + u16 af_tile_active_width; + u16 af_tile_active_height; + + //12 u32 + u16 af_y_shift; + u16 af_cfa_y_shift; + + //13 u32 + u8 awb_tile_num_col; + u8 awb_tile_num_row; + u8 ae_tile_num_col; + u8 ae_tile_num_row; + + //14 u32 + u8 af_tile_num_col; + u8 af_tile_num_row; + u8 total_slices_x; + u8 total_slices_y; + + //15 u32 + u8 slice_index_x; + u8 slice_index_y; + u16 slice_width; + + //16 u32 + u16 slice_height; + u16 slice_start_x; + + //17 u32 + u32 slice_start_y : 16; + u32 chan_index : 4; + u32 fusion_ir_step : 1; + u32 reserved : 11; + + //18 + u32 raw_pic_seq_num; // sequence number of raw picture used in producing this block of AAA results + //19 + u32 iso_config_tag; + u32 reserved1[9]; + + //NOTE: expanded by ARM to support PTS + u64 mono_pts; + u32 dsp_pts; + u32 reserved2; // max 128 bytes +}aaa_tile_info_t; + +typedef struct +{ + u32 vin_stats_type : 8; /* 0: main; 1: hdr; 2: hdr2 */ + u32 chan_index : 3; + u32 is_rgbir : 1; + u32 fusion_ir_step : 1; + u32 reserved_0 : 3; + u32 total_exposures : 8; + u32 blend_index : 8; /* exposure no. */ + + u8 total_slice_in_x; + u8 slice_index_x; + u8 total_slice_in_y; + u8 slice_index_y; + + u16 vin_stats_slice_left; + u16 vin_stats_slice_width; + + u16 vin_stats_slice_top; + u16 vin_stats_slice_height; + + u32 reserved[24]; + + //NOTE: expanded by ARM to support PTS + u64 mono_pts; + u32 dsp_pts; + u32 reserved2; // max 128 bytes +}vin_stats_config_info_t ; + +struct af_stat { + u16 sum_fy; + u16 sum_fv1; + u16 sum_fv2; +}; + +struct rgb_histogram_stat { + u32 his_bin_y[HIST_BIN_NUM]; + u32 his_bin_r[HIST_BIN_NUM]; + u32 his_bin_g[HIST_BIN_NUM]; + u32 his_bin_b[HIST_BIN_NUM]; +}; + +struct rgb_aaa_stat { + aaa_tile_info_t aaa_tile_info; + u16 frame_id; + struct af_stat af_stat[96]; + u16 ae_sum_y[96]; + struct rgb_histogram_stat histogram_stat; + u8 reserved[249]; +}; + + +struct cfa_awb_stat { + u16 sum_r; + u16 sum_g; + u16 sum_b; + u16 count_min; + u16 count_max; +}; + +struct cfa_ae_stat { + u16 lin_y; + u16 count_min; + u16 count_max; +}; + +struct cfa_af_stat { + u16 sum_fy; + u16 sum_fv1; + u16 sum_fv2; +}; + +struct cfa_histogram_stat { + u32 his_bin_r[HIST_BIN_NUM]; + u32 his_bin_g[HIST_BIN_NUM]; + u32 his_bin_b[HIST_BIN_NUM]; + u32 his_bin_y[HIST_BIN_NUM]; +}; + +struct cfa_aaa_stat { + aaa_tile_info_t aaa_tile_info; + u16 frame_id; + struct cfa_awb_stat awb_stat[1024]; + struct cfa_ae_stat ae_stat[96]; + struct af_stat af_stat[96]; + struct cfa_histogram_stat histogram_stat; + u8 reserved[121]; +}; + +struct vin_hist_stat{ + u32 hist_bin_r[VIN_HISTOGRAM_BIN_NUM]; + u32 hist_bin_g[VIN_HISTOGRAM_BIN_NUM]; + u32 hist_bin_b[VIN_HISTOGRAM_BIN_NUM]; + u32 hist_bin_ir[VIN_HISTOGRAM_BIN_NUM]; +}; + +struct vin_aaa_stat{ + vin_stats_config_info_t vin_stats_config_info; + struct vin_hist_stat vin_histogram_stats; +}; + +struct contrast_enhance_info{ + u16 low_pass_radius; // 0: 16x, 1: 32x, 2: 60x + u16 enhance_gain; // unit: 1024; 0 : off +}; + +struct img_statistics { + u8 *enable_pts; + u8 *rgb_data_valid; + u8 *cfa_data_valid; + u8 *sensor_data_valid; + u8 *vin_data_valid; + void *rgb_statis; + void *cfa_statis; + void *sensor_statis; + void *vin_statis; + u8 *resend_all_cfg; +}; + +struct aaa_statistics_ex { + u8 af_horizontal_filter1_mode; + u8 af_horizontal_filter1_stage1_enb; + u8 af_horizontal_filter1_stage2_enb; + u8 af_horizontal_filter1_stage3_enb; + s16 af_horizontal_filter1_gain[7]; + u16 af_horizontal_filter1_shift[4]; + u16 af_horizontal_filter1_bias_off; + u16 af_horizontal_filter1_thresh; + u16 af_vertical_filter1_thresh; + u16 af_tile_fv1_horizontal_shift; + u16 af_tile_fv1_vertical_shift; + u16 af_tile_fv1_horizontal_weight; + u16 af_tile_fv1_vertical_weight; + + u8 af_horizontal_filter2_mode; + u8 af_horizontal_filter2_stage1_enb; + u8 af_horizontal_filter2_stage2_enb; + u8 af_horizontal_filter2_stage3_enb; + s16 af_horizontal_filter2_gain[7]; + u16 af_horizontal_filter2_shift[4]; + u16 af_horizontal_filter2_bias_off; + u16 af_horizontal_filter2_thresh; + u16 af_vertical_filter2_thresh; + u16 af_tile_fv2_horizontal_shift; + u16 af_tile_fv2_vertical_shift; + u16 af_tile_fv2_horizontal_weight; + u16 af_tile_fv2_vertical_weight; +}; +#if 0 +#define DUMP_IDSP_0 0 +#define DUMP_IDSP_1 1 +#define DUMP_IDSP_2 2 +#define DUMP_IDSP_3 3 +#define DUMP_IDSP_4 4 +#define DUMP_IDSP_5 5 +#define DUMP_IDSP_6 6 +#define DUMP_IDSP_7 7 +#define DUMP_IDSP_100 100 +#define DUMP_FPN 200 +#define DUMP_VIGNETTE 201 +#define MAX_DUMP_BUFFER_SIZE 256*1024 +#endif +typedef struct idsp_config_info_s { + u8* addr; + u32 addr_long; + u32 id_section; +}idsp_config_info_t; + + +struct raw2enc_raw_feed_info +{ + u32 raw_daddr_offset; /* offset from sensor raw start daddr to the start address of ik */ + u32 raw_hdec_daddr_offset; + u32 preblend_daddr_offset; + u32 raw_size; /* offset from sensor_raw_start_daddr to the start address of the next frame in DRAM */ + u32 raw_hdec_size; + u32 preblend_size; + u32 raw_dpitch : 16; /* buffer pitch in bytes */ + u32 raw_hdec_dpitch : 16; /* buffer pitch in bytes */ + u32 preblend_dpitch : 16; /* buffer pitch in bytes */ + u32 num_frames : 8; /* num of frames stored in DRAM starting from sensor_raw_start_daddr */ + u32 reserved : 8; +}; + +typedef struct idsp_iso_config_update_flag_s { + u32 iso_config_common_update : 1 ; + u32 iso_config_color_update : 1 ; + u32 iso_config_mctf_update : 1 ; + u32 iso_config_step1_update : 1 ; + u32 iso_config_aaa_update : 1 ; // AAA setup update + u32 iso_config_extra_update : 1 ; + u32 iso_config_motion_update : 1 ; + u32 iso_config_exp_update : 1 ; + u32 reserved : 24 ; +} idsp_iso_config_update_flag_t; + +typedef struct idsp_iso_config_s { + u32 ik_id; + unsigned long iso_addr_offset; + + /* config update flags */ + union { + idsp_iso_config_update_flag_t flag; + u32 word; + } loadcfg_type; +} idsp_iso_config_t; + +typedef struct idsp_hdr_config_s { + u32 raw_offset[MAX_EXPOSURE_NUM]; + u8 expo_num; +} idsp_hdr_config_t; + +typedef enum { + IDSP_CFG_TYPE_ISO = (1 << 0), + IDSP_CFG_TYPE_HDR = (1 << 1), +} IDSP_CFG_TYPE; + +typedef struct idsp_config_s { + u32 chan_id; + u32 cfg_map; + idsp_iso_config_t iso_cfg; + idsp_hdr_config_t hdr_cfg; +} idsp_config_t; + +typedef struct idsp_delay_info_s { + u32 delay[IMG_MAX_VIN_CHANNEL_NUM]; // unit: vsync +} idsp_delay_info_t; + +struct img_statistics_report_rate { + u8 multi_factor[IMG_MAX_VIN_CHANNEL_NUM]; + u8 div_factor[IMG_MAX_VIN_CHANNEL_NUM]; +}; + +typedef struct { + u32 cfg_buf_addr; + u32 cfg_buf_size; +} debug_cfg_info_t; + +typedef struct { + u32 y_addr; + u32 uv_addr; + u16 y_pitch; + u16 y_width; + u16 y_height; + u16 uv_pitch; + u16 uv_width; + u16 uv_height; +} debug_yuv_info_t; + +typedef struct { + u32 addr; + u16 pitch; + u16 width; + u16 height; + u16 reserved; +} debug_buf_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t sec4_cfg; + debug_cfg_info_t sec2_cfg; + + debug_yuv_info_t sec2_raw2yuv; + debug_buf_info_t sec2_me1; +} debug_c2y_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t me1_smooth_sec2_cfg; + debug_cfg_info_t me1_smooth_sec6_cfg; + debug_cfg_info_t me1_smooth_sec5_cfg; + + debug_buf_info_t vwarp_me1; + debug_buf_info_t me1_dn3; +} debug_me1_smooth_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t sec2_cfg[3]; /* 0: mda, 1: mdb, 2: mdc */ + debug_cfg_info_t sec6_cfg; + debug_cfg_info_t sec5_cfg; + debug_cfg_info_t mctf_cfg; + + debug_buf_info_t md_mb_b; + debug_buf_info_t md_mb_c; + debug_buf_info_t mo_asf; + + debug_cfg_info_t ALPHA_MO1_cfg; + debug_cfg_info_t ALPHA_MO_cfg; + + debug_buf_info_t ALPHA_MO_B; + debug_buf_info_t ALPHA_MO_C; +} debug_md_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t mctf_cfg; + debug_cfg_info_t mcts_cfg; + + debug_buf_info_t sec3_me1; + debug_yuv_info_t mctf; + debug_yuv_info_t mcts; + debug_buf_info_t mctf_2bit; +} debug_vwarp_mctf_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t C2Y_IR_ce_cfg; + debug_cfg_info_t C2Y_IR_cfg; + debug_cfg_info_t MonoDn1_cfg; + debug_cfg_info_t MonoDn2_cfg; + + debug_buf_info_t C2Y_IR; + debug_buf_info_t C2Y_IR_me1; + debug_buf_info_t MonoDn2; +} debug_mono_1_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t C2Y_RGB_ce_cfg; + debug_cfg_info_t C2Y_RGB_cfg; + debug_cfg_info_t FusCDown_cfg; + + debug_yuv_info_t C2Y_RGB; + debug_buf_info_t C2Y_RGB_me1; + debug_buf_info_t FusCDown; +} debug_mono_2_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t RGB_Dn1_cfg; + debug_cfg_info_t PadME1_cfg; + debug_cfg_info_t FusEdge_mcts_cfg; + debug_cfg_info_t FusEdgeDn1_cfg; + debug_cfg_info_t FusEdgeDn2_cfg; + debug_cfg_info_t Alpha1_cfg; + + debug_buf_info_t RGB_Dn1; + debug_buf_info_t Alpha1; +} debug_mono_3_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t RGB_Dn2_cfg; + debug_cfg_info_t RGB_Dn3_cfg; + debug_cfg_info_t RGB_Smh_cfg; + debug_cfg_info_t MonoDn3_cfg; + debug_cfg_info_t MonoSmhUp_cfg; + + debug_buf_info_t RGB_Smh; + debug_buf_info_t MonoSmhUp; +} debug_mono_4_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t Alpha2_cfg; + debug_cfg_info_t ToUV_cfg; + debug_cfg_info_t RGBUp_cfg; + + debug_buf_info_t Alpha2_Blend; +} debug_mono_5_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t C_FiltB_luma_cfg; + debug_cfg_info_t C_FiltB_cfg; + debug_cfg_info_t C_MCTFA_mctf_cfg; + debug_cfg_info_t C_MCTFA_mcts_cfg; + + debug_buf_info_t C_up4VWarp; +} debug_mono_6_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t Alpha_cfg; + debug_cfg_info_t Alpha_MCTF_mctf_cfg; + debug_cfg_info_t Alpha_MCTF_mcts_cfg; + + debug_buf_info_t Alpha_MCTF_mctf; + debug_buf_info_t Alpha_MCTF_mcts; +} debug_mono_7_info_t; + +typedef struct { + u32 cap_seq_no; + + debug_cfg_info_t Alpha_SmthUp_cfg; + debug_cfg_info_t Freq_Blend_mctf_cfg; + debug_cfg_info_t Freq_Blend_mcts_cfg; + + debug_buf_info_t Freq_Blend; +} debug_mono_8_info_t; + +typedef struct { + u32 chan_id : 8; + u32 reserved : 24; + debug_c2y_info_t c2y; + debug_vwarp_mctf_info_t vwarp_mctf; + debug_me1_smooth_info_t me1_smooth; + debug_md_info_t md; +} liso_debug_info_t; + +typedef struct { + u32 chan_id : 8; + u32 reserved : 24; + debug_vwarp_mctf_info_t vwarp_mctf; + debug_me1_smooth_info_t me1_smooth; + debug_md_info_t md; + debug_mono_1_info_t mono_1; + debug_mono_2_info_t mono_2; + debug_mono_3_info_t mono_3; + debug_mono_4_info_t mono_4; + debug_mono_5_info_t mono_5; + debug_mono_6_info_t mono_6; + debug_mono_7_info_t mono_7; + debug_mono_8_info_t mono_8; +} fusion_debug_info_t; + +struct img_idsp_debug_info { + u32 chan_id; + union { + liso_debug_info_t debug_info; + fusion_debug_info_t fusion_debug_info; + }; +}; + +typedef enum { + LISO_SHARE = 0x00, + LISO_CALIB = 0x01, + LISO_COLOR = 0x02, + LISO_RAW2YUV = 0x03, + LISO_EXTRA = 0x04, + LISO_FLOW = 0x05, + LISO_MCTF = 0x06, + LISO_ME1_SMOOTH = 0x07, + LISO_MD_A = 0x08, + LISO_MD_B = 0x09, + LISO_MD_C = 0x0A, + LISO_MD_MB = 0x0B, + LISO_HDR_CE = 0x0C, + LISO_EXPOSURE_0 = 0x0D, + LISO_EXPOSURE_1 = 0x0E, + LISO_EXPOSURE_2 = 0x0F, + LISO_PREP_CE = 0x10, + LISO_CONFIG_ID_TOTAL = 0x11, +} LISO_CONFIG_ID; + +struct img_idsp_debug_setup { + u32 chan_id : 8; + u32 report_enable : 1; + u32 break_point_enable : 1; + u32 reserved0 : 6; + u32 break_point_cfg_id : 8; /* enum LISO_CONFIG_ID */ + u32 reserved1 : 8; + u32 break_point_frame_num; /* 0xFFFFFFFF means next frame immediately */ +}; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/arch_v5/ambas_imgproc_ioctl_arch.h b/include/ambarella/arch_v5/ambas_imgproc_ioctl_arch.h new file mode 100644 index 0000000..1d23eca --- /dev/null +++ b/include/ambarella/arch_v5/ambas_imgproc_ioctl_arch.h @@ -0,0 +1,71 @@ +/* + * ambas_imgproc_ioctl_arch.h + * + * History: + * 2015/06/12 - [Jian Tang] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef AMBAS_IMGPROC_IOCTL_ARCH_H +#define AMBAS_IMGPROC_IOCTL_ARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <linux/ioctl.h> + +/* + * image processing APIs - 'p' + */ +#define IAVIOC_IMAGE_MAGIC 'p' +#define IAVIMG_IO(nr) _IO(IAVIOC_IMAGE_MAGIC, nr) +#define IAVIMG_IOR(nr, size) _IOR(IAVIOC_IMAGE_MAGIC, nr, size) +#define IAVIMG_IOW(nr, size) _IOW(IAVIOC_IMAGE_MAGIC, nr, size) +#define IAVIMG_IOWR(nr, size) _IOWR(IAVIOC_IMAGE_MAGIC, nr, size) + +typedef enum { + /* AAA control, start from 0x80 */ + IOC_IMG_GET_STATISTICS = 0x80, + IOC_IMG_GET_IDSP_CFG = 0x81, + IOC_IMG_SETUP_IDSP_DEBUG = 0x82, + +} IAV_IMG_IOC; + +#define IAV_IOC_IMG_GET_STATISTICS IAVIMG_IOR(IOC_IMG_GET_STATISTICS, u32) +#define IAV_IOC_IMG_GET_LATEST_STATISTICS IAVIMG_IOR(IOC_IMG_GET_STATISTICS, u16) +#define IAV_IOC_IMG_SET_STATISTICS_REPORT_RATE IAVIMG_IOW(IOC_IMG_GET_STATISTICS, u8) +#define IAV_IOC_IMG_GET_STATISTICS_REPORT_RATE IAVIMG_IOR(IOC_IMG_GET_STATISTICS, u8) +#define IAV_IOC_IMG_GET_IDSP_CFG IAVIMG_IOR(IOC_IMG_GET_IDSP_CFG, u32) +#define IAV_IOC_IMG_SETUP_IDSP_DEBUG IAVIMG_IOR(IOC_IMG_SETUP_IDSP_DEBUG, u32) + +#ifdef __cplusplus +} +#endif + +#endif // AMBAS_IMGPROC_IOCTL_ARCH_H + diff --git a/include/ambarella/arch_v5/datatype.h b/include/ambarella/arch_v5/datatype.h new file mode 100644 index 0000000..33a2815 --- /dev/null +++ b/include/ambarella/arch_v5/datatype.h @@ -0,0 +1,26 @@ +#ifndef DATATYPE_H +#define DATATYPE_H + +typedef signed char int8; +typedef unsigned char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned uint32; +typedef long long int64; +typedef unsigned long long uint64; +typedef long intptr; +typedef unsigned long uintptr; + +typedef float float32; +typedef double double64; + +#ifndef __SIZE_T__ +#define __SIZE_T__ +typedef unsigned int size_t; +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif +#endif diff --git a/include/ambarella/arch_v5/iav_fastboot.h b/include/ambarella/arch_v5/iav_fastboot.h new file mode 100644 index 0000000..6fcc1fc --- /dev/null +++ b/include/ambarella/arch_v5/iav_fastboot.h @@ -0,0 +1,151 @@ +/* + * iav_fastboot.h + * + * History: + * 2016/03/10 - [Xu Liang] Created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_FASTBOOT_H__ +#define __IAV_FASTBOOT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +enum preload_file_id { + PF_ISO_CFG = 0, + PF_TONE_CURVE = 1, + PF_RGB2YUV_MAT = 2, + PF_LOCAL_EXPO = 3, + PF_MAX_NUM, + PF_FIRST = PF_ISO_CFG, + PF_LAST = PF_MAX_NUM, +}; + +#define MAX_FILE_NAME (64) + +#define PRELOAD_ISO_CONFIG "/tmp/idsp_iso_cfg.bin" +#define PRELOAD_TONE_CURVE "/tmp/idsp_tone_curve" +#define PRELOAD_RGB2YUV_MAT "/tmp/idsp_rgb2yuv" +#define PRELOAD_LOCAL_EXPO "/tmp/idsp_local_expo" +#define PRELOAD_AWB_FILE "/tmp/idsp_awb" +#define PRELOAD_AE_FILE "/tmp/idsp_ae" + +enum iav_fb_bin_id { + IAV_FB_VIN_VIDEO_FORMAT = 0, + IAV_FB_VIN_DSP_CONFIG = 1, + IAV_FB_ENC_CONFIG = 2, + IAV_FB_SRCBUF_CONFIG = 3, + IAV_FB_VOUT0_SETUP = 4, + IAV_FB_VOUT1_SETUP = 5, + IAV_FB_DATA_MAX_NUM, + IAV_FB_DATA_FIRST = IAV_FB_VIN_VIDEO_FORMAT, + IAV_FB_DATA_LAST = IAV_FB_DATA_MAX_NUM, +}; + +struct iav_fb_aeb { + /* AWB */ + unsigned int r_gain; + unsigned int b_gain; + /* AE */ + unsigned int d_gain; + unsigned int shutter_row; + unsigned int agc_index; +}; + +struct iav_fb_node { + unsigned int offset; + unsigned int size; +}; + +enum iav_fb_vout_dram_id { + IAV_FB_VOUT_HEADER = 0, + IAV_FB_VOUT_DISPLAY = 1, + IAV_FB_VOUT_DVE = 2, + IAV_FB_VOUT_OSD_CLUT = 3, + IAV_FB_VOUT_OSD_BUF_INFO = 4, + IAV_FB_VOUT_OSD_BUF_DRAM = 5, + IAV_FB_VOUT_TIMING = 6, + IAV_FB_VOUT_DATA_MAX_NUM, + IAV_FB_VOUT_DATA_FIRST = IAV_FB_VOUT_HEADER, + IAV_FB_VOUT_DATA_LAST = IAV_FB_VOUT_DATA_MAX_NUM, +}; + +struct amba_fb_vout_config_data { + unsigned int vout_id : 2; + unsigned int enabled : 1; + unsigned int reserved : 29; + struct iav_fb_node vout_mem[IAV_FB_VOUT_DATA_MAX_NUM]; +}; + +struct amba_fb_bpi_info { + u32 work_mode : 4; + u32 rtos_vca_enable : 1; + u32 rtos_vca_classes : 3; + u32 rtos_vca_result : 4; + u32 reserved0 : 4; + u32 record_sec : 8; + u32 linux_vca_eable : 1; + u32 reserved1 : 7; +}; + +#define FB_MAX_CHAN_NUM 2 +#define FB_MAX_VIN_NUM 2 +#define FB_HEADER_SIZE 256 + +struct iav_fb_hdr { /* 4 + 8 + 8 + 8 * 2 + 4 + 20 * 2 + 8 * 6 + 128 = 256 */ + unsigned int dsp_status; + + unsigned int header_size : 16; + unsigned int fast_thaw : 1; + unsigned int night_mode : 1; + unsigned int prev_id : 4; + unsigned int reserved : 2; + unsigned int active_vin_num : 4; + unsigned int rtos_log_level : 4; + unsigned int light_value; + + unsigned int bin_offset; + struct amba_fb_bpi_info info; + + unsigned int vinc_chan_map[FB_MAX_VIN_NUM]; + unsigned int sensor_ctrl_map[FB_MAX_VIN_NUM]; + + unsigned char shutter_max[FB_MAX_CHAN_NUM]; /* unit: denominator seconds */ + unsigned char agc_max[FB_MAX_CHAN_NUM]; /* unit: db */ + + struct iav_fb_aeb pre_aeb[FB_MAX_CHAN_NUM]; + struct iav_fb_node bin[IAV_FB_DATA_MAX_NUM]; + unsigned char reserve1[128]; +}__attribute__((packed)); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/arch_v5/iav_ioctl.h b/include/ambarella/arch_v5/iav_ioctl.h new file mode 100644 index 0000000..d7ff149 --- /dev/null +++ b/include/ambarella/arch_v5/iav_ioctl.h @@ -0,0 +1,3489 @@ +/* + * iav_ioctl.h + * + * History: + * 2013/03/12 - [Cao Rongrong] Created file + * 2013/12/12 - [Jian Tang] Modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_IOCTL_H__ +#define __IAV_IOCTL_H__ + +/*! @file iav_ioctl.h + * @brief This file defines IAV driver ioctl api. + */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "basetypes.h" +#include <linux/ioctl.h> +#include "config.h" + +#include "iav_common.h" +#include "iav_vin_ioctl.h" +#include "iav_vout_ioctl.h" +#include "ambas_imgproc_arch.h" + + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ + +/*! @macros IAV_MAX_CHANNEL_NUM + * @brief define max channel number. + */ +#ifndef IAV_MAX_CHANNEL_NUM +#define IAV_MAX_CHANNEL_NUM (8) +#endif + +/*! @macros IAV_HEVC_TILE_NUM + * @brief define iav hevc encode tile number. + */ +#define IAV_HEVC_TILE_NUM (3) + +/*! @macros IAV_MAX_CANVAS_BUF_NUM + * @brief define iav max canvas buffer number. + */ +#define IAV_MAX_CANVAS_BUF_NUM (12) + +/*! @macros IAV_MAX_PYRAMID_LAYERS + * @brief define iav max pyramid layer number. + */ +#define IAV_MAX_PYRAMID_LAYERS (6) + +/*! @macros IAV_MAX_PASS_NUM + * @brief define iav max pass number for each channel. + */ +#define IAV_MAX_PASS_NUM (2) + +/*! @macros VIN_INSTANCES + * @brief define vin instance number, 6 real vinc + 1 virtual vinc. + */ +#define VIN_INSTANCES (6 + 1) + +/*! @macros VIN_CONTROLLER_NUM + * @brief define vin controller number, equal to VIN_INSTANCES. + */ +#define VIN_CONTROLLER_NUM VIN_INSTANCES + +/*! @macros IAV_MIN_VP_DRAM_PRIORITY + * @brief define vp dram priority minimum value. + */ +#if defined(CONFIG_ARCH_CV2) || defined(CONFIG_ARCH_CV22) || defined(CONFIG_ARCH_CV25) +#define IAV_MIN_VP_DRAM_PRIORITY (2) +#else +#define IAV_MIN_VP_DRAM_PRIORITY (0) +#endif + +/*! @macros IAV_MAX_VP_DRAM_PRIORITY + * @brief define vp dram priority maximum value. + */ + +#if defined(CONFIG_ARCH_CV2) +#define IAV_MAX_VP_DRAM_PRIORITY (7) +#elif defined(CONFIG_ARCH_CV22) || defined(CONFIG_ARCH_CV25) +#define IAV_MAX_VP_DRAM_PRIORITY (5) +#else +#define IAV_MAX_VP_DRAM_PRIORITY (0) +#endif + +/*! @macros LPDDR4_ALIGN + * @brief define lpddr4 align value. + */ +#define LPDDR4_ALIGN (64) + +/*! @macros UNIQUE_ID_SIZE + * @brief define unique ID size. + */ +#define UNIQUE_ID_SIZE (32) + +/*! @enum dsp_mode + * @brief DSP mode enum to list dsp mode state. + */ +enum dsp_mode { + DSP_CURRENT_MODE = 0xFF, /*!< 0xFF */ + DSP_NORMAL_ISO_MODE = 0x0, /*!< 0x0 */ + DSP_MULTI_REGION_WARP_MODE = 0x1, /*!< 0x1 */ + DSP_FUSION_MODE = 0x2, /*!< 0x2 */ + DSP_MULTI_PASS_IDSP_ROTATE_MODE = 0x3, /*!< 0x3 */ + DSP_HDR_LINE_INTERLEAVED_MODE = 0x5, /*!< 0x5 */ + DSP_ENCODE_MODE_TOTAL_NUM = 0x6, /*!< 0x6 */ + DSP_ENCODE_MODE_FIRST = DSP_NORMAL_ISO_MODE, /*!< DSP_NORMAL_ISO_MODE */ + DSP_ENCODE_MODE_LAST = DSP_ENCODE_MODE_TOTAL_NUM, /*!< DSP_ENCODE_MODE_TOTAL_NUM */ +}; + +/*! @enum dsp_vout_profile + * @brief DSP vout profile enumeration. + */ +enum dsp_vout_profile { + DSP_VOUT_PROFILE_DEFAULT = 0, /*!< 0, vout0 no osd, vout1 with osd, stream osd */ + DSP_VOUT_PROFILE_4K_WITH_16BIT_OSD = 1, /*!< 1, vout0 4k with osd, vout1 4k with osd */ + DSP_VOUT_PROFILE_VOUT0_D640_VOUT1_M720 = 2, /*!< 2, vout0 640, vout1 720 with osd, stream osd */ + DSP_VOUT_PROFILE_VOUT1_720P_WITH_16BIT_OSD = 3, /*!< 3, vout0 default, vout1 720p with 16bit osd, stream osd */ + DSP_VOUT_PROFILE_VOUT0_720P_WITH_16BIT_OSD = 4, /*!< 4, vout1 default, vout0 720p with 16bit osd, stream osd */ + DSP_VOUT_PROFILE_NUM /*!< 5 */ +}; + +/*! @enum hevc_perf_mode + * @brief hevc perf mode enumeration. + */ +enum hevc_perf_mode { + IAV_HEVC_PERF_MODE_DEFAULT = 0, + IAV_HEVC_PERF_MODE_FAST = 1, + IAV_HEVC_PERF_MODE_FASTEST = 2, + IAV_HEVC_PERF_MODE_NUM = 3, + IAV_HEVC_PERF_MODE_FIRST = IAV_HEVC_PERF_MODE_DEFAULT, + IAV_HEVC_PERF_MODE_LAST = IAV_HEVC_PERF_MODE_NUM, +}; + +/*! @enum iav_chip_id + * @brief iav chip id enumeration. + */ +enum iav_chip_id { + IAV_CHIP_ID_UNKNOWN = -1, /*!< -1 */ + + /* CV2 */ + IAV_CHIP_ID_CV2_55 = 0, /*!< 0 */ + IAV_CHIP_ID_CV2_66 = 1, /*!< 1 */ + IAV_CHIP_ID_CV2_66_TEST = 2, /*!< 2 */ + IAV_CHIP_ID_CV2_88 = 3, /*!< 3 */ + IAV_CHIP_ID_CV2_99 = 4, /*!< 4 */ + IAV_CHIP_ID_CV2_LAST = 5, /*!< 5 */ + IAV_CHIP_ID_CV2_FIRST = IAV_CHIP_ID_CV2_55, /*!< IAV_CHIP_ID_CV2_55 */ + IAV_CHIP_ID_CV2_NUM = IAV_CHIP_ID_CV2_LAST - IAV_CHIP_ID_CV2_FIRST, /*!< IAV_CHIP_ID_CV2_LAST - IAV_CHIP_ID_CV2_FIRST */ + + /* CV2 Auto */ + IAV_CHIP_ID_CV2AQ_76 = 0x20, /*!< 0x20 */ + IAV_CHIP_ID_CV2AX_81 = 0x21, /*!< 0x21 */ + IAV_CHIP_ID_CV2AX_86 = 0x22, /*!< 0x22 */ + IAV_CHIP_ID_CV2AX_99 = 0x23, /*!< 0x23 */ + IAV_CHIP_ID_CV2AQ_99 = 0x24, /*!< 0x24 */ + IAV_CHIP_ID_CV2AUTO_LAST = 0x25, /*!< 0x25 */ + IAV_CHIP_ID_CV2AUTO_FIRST = IAV_CHIP_ID_CV2AQ_76, /*!< IAV_CHIP_ID_CV2AQ_76 */ + IAV_CHIP_ID_CV2AUTO_NUM = IAV_CHIP_ID_CV2AUTO_LAST - IAV_CHIP_ID_CV2AUTO_FIRST, /*!< IAV_CHIP_ID_CV2AUTO_LAST - IAV_CHIP_ID_CV2AUTO_FIRST */ + + /* CV22 */ + IAV_CHIP_ID_CV22_55 = 0, /*!< 0 */ + IAV_CHIP_ID_CV22_66 = 1, /*!< 1 */ + IAV_CHIP_ID_CV22_88 = 2, /*!< 2 */ + IAV_CHIP_ID_CV22_99 = 3, /*!< 3 */ + IAV_CHIP_ID_CV22_55N = 4, /*!< 4 */ + IAV_CHIP_ID_CV22_66N = 5, /*!< 5 */ + IAV_CHIP_ID_CV22_88N = 6, /*!< 6 */ + IAV_CHIP_ID_CV22_99N = 7, /*!< 7 */ + IAV_CHIP_ID_CV22_LAST = 8, /*!< 8 */ + IAV_CHIP_ID_CV22_FIRST = IAV_CHIP_ID_CV22_55, /*!< IAV_CHIP_ID_CV22_55 */ + IAV_CHIP_ID_CV22_NUM = IAV_CHIP_ID_CV22_LAST - IAV_CHIP_ID_CV22_FIRST, /*!< IAV_CHIP_ID_CV22_LAST - IAV_CHIP_ID_CV22_FIRST */ + + /* CV22 Auto */ + IAV_CHIP_ID_CV22AQ_16 = 0x20, /*!< 0x20 */ + IAV_CHIP_ID_CV22AQ_26 = 0x21, /*!< 0x21 */ + IAV_CHIP_ID_CV22AQ_36 = 0x22, /*!< 0x22 */ + IAV_CHIP_ID_CV22AQ_76 = 0x23, /*!< 0x23 */ + IAV_CHIP_ID_CV22AX_16 = 0x24, /*!< 0x24 */ + IAV_CHIP_ID_CV22AX_26 = 0x25, /*!< 0x25 */ + IAV_CHIP_ID_CV22AX_36 = 0x26, /*!< 0x26 */ + IAV_CHIP_ID_CV22AX_76 = 0x27, /*!< 0x27 */ + IAV_CHIP_ID_CV22A_26 = 0x28, /*!< 0x28 */ + IAV_CHIP_ID_CV22A_36 = 0x29, /*!< 0x29 */ + IAV_CHIP_ID_CV22A_99 = 0x2A, /*!< 0x2A */ + IAV_CHIP_ID_CV22AX_99 = 0x2B, /*!< 0x2B */ + IAV_CHIP_ID_CV22AQ_99 = 0x2C, /*!< 0x2C */ + + IAV_CHIP_ID_CV22AUTO_LAST = 0x2D, /*!< 0x2D */ + IAV_CHIP_ID_CV22AUTO_FIRST = IAV_CHIP_ID_CV22AQ_16, /*!< IAV_CHIP_ID_CV22AQ_16 */ + IAV_CHIP_ID_CV22AUTO_NUM = IAV_CHIP_ID_CV22AUTO_LAST - IAV_CHIP_ID_CV22AUTO_FIRST, /*!< IAV_CHIP_ID_CV22AUTO_LAST - IAV_CHIP_ID_CV22AUTO_FIRST */ + + /* CV25 */ + IAV_CHIP_ID_CV25_33 = 0, /*!< 0 */ + IAV_CHIP_ID_CV25_66 = 1, /*!< 1 */ + IAV_CHIP_ID_CV25_99 = 2, /*!< 2 */ + IAV_CHIP_ID_CV25_33M = 3, /*!< 3 */ + IAV_CHIP_ID_CV25_55M = 4, /*!< 4 */ + IAV_CHIP_ID_CV25_99M = 5, /*!< 5 */ + IAV_CHIP_ID_CV25_88 = 6, /*!< 6 */ + IAV_CHIP_ID_CV25_LAST = 7, /*!< 7 */ + IAV_CHIP_ID_CV25_FIRST = IAV_CHIP_ID_CV25_33, /*!< IAV_CHIP_ID_CV25_33 */ + IAV_CHIP_ID_CV25_NUM = IAV_CHIP_ID_CV25_LAST - IAV_CHIP_ID_CV25_FIRST, /*!< IAV_CHIP_ID_CV25_LAST - IAV_CHIP_ID_CV25_FIRST */ + + /* CV25 Auto */ + IAV_CHIP_ID_CV25AQ_16 = 0x20, /*!< 0x20 */ + IAV_CHIP_ID_CV25AQ_26 = 0x21, /*!< 0x21 */ + IAV_CHIP_ID_CV25AQ_36 = 0x22, /*!< 0x22 */ + IAV_CHIP_ID_CV25AQ_76 = 0x23, /*!< 0x23 */ + IAV_CHIP_ID_CV25AX_26 = 0x24, /*!< 0x24 */ + IAV_CHIP_ID_CV25AX_36 = 0x25, /*!< 0x25 */ + IAV_CHIP_ID_CV25AX_76 = 0x26, /*!< 0x26 */ + IAV_CHIP_ID_CV25AX_86 = 0x27, /*!< 0x27 */ + IAV_CHIP_ID_CV25A_26 = 0x28, /*!< 0x28 */ + IAV_CHIP_ID_CV25A_36 = 0x29, /*!< 0x29 */ + IAV_CHIP_ID_CV25A_76 = 0x2A, /*!< 0x2A */ + IAV_CHIP_ID_CV25A_86 = 0x2B, /*!< 0x2B */ + IAV_CHIP_ID_CV25A_99 = 0x2C, /*!< 0x2C */ + IAV_CHIP_ID_CV25AX_99 = 0x2D, /*!< 0x2D */ + IAV_CHIP_ID_CV25AQ_99 = 0x2E, /*!< 0x2E */ + + IAV_CHIP_ID_CV25AUTO_LAST = 0x2F, /*!< 0x2F */ + IAV_CHIP_ID_CV25AUTO_FIRST = IAV_CHIP_ID_CV25AQ_16, /*!< IAV_CHIP_ID_CV25AQ_16 */ + IAV_CHIP_ID_CV25AUTO_NUM = IAV_CHIP_ID_CV25AUTO_LAST - IAV_CHIP_ID_CV25AUTO_FIRST, /*!< IAV_CHIP_ID_CV25AUTO_LAST - IAV_CHIP_ID_CV25AUTO_FIRST */ + + /* S6LM */ + IAV_CHIP_ID_S6LM_22 = 0, /*!< 0 */ + IAV_CHIP_ID_S6LM_33 = 1, /*!< 1 */ + IAV_CHIP_ID_S6LM_55 = 2, /*!< 2 */ + IAV_CHIP_ID_S6LM_99 = 3, /*!< 3 */ + IAV_CHIP_ID_S6LM_LAST = 4, /*!< 4 */ + IAV_CHIP_ID_S6LM_FIRST = IAV_CHIP_ID_S6LM_22, /*!< IAV_CHIP_ID_S6LM_22 */ + IAV_CHIP_ID_S6LM_NUM = IAV_CHIP_ID_S6LM_LAST - IAV_CHIP_ID_S6LM_FIRST, /*!< IAV_CHIP_ID_S6LM_LAST - IAV_CHIP_ID_S6LM_FIRST */ +}; + +/*! @} */ /* End of iav-ioctl-general-helper */ + + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_driver_version { + int arch; /*!< Chip arch ID */ + int model; /*!< Chip model ID */ + int major; /*!< Major of the device driver version */ + int minor; /*!< Minor of the device driver version */ + int patch; /*!< Patch of the device driver version */ + u32 mod_time; /*!< Last modification time of the device driver */ + char description[64]; /*!< Description of the device driver */ + u32 api_version; /*!< API version */ + u32 idsp_version; /*!< IDSP version */ + u32 reserved[2]; +}; + +struct iav_driver_dsp_info { + struct iav_driver_version drv_ver; /*!< Driver version information */ + u32 dspid; /*!< DSP Chip ID */ + u8 dspout[4]; /*!< Output hash ID */ + u8 dspin[8]; /*!< Input hash ID */ +}; + +struct iav_dsp_hash { + u8 input[32]; /*!< dsp hash input */ + u8 output[4]; /*!< dsp hash output */ +}; + +struct iav_unique_id { + u8 unique_id[UNIQUE_ID_SIZE]; /*!< dsp unique ID */ +}; + +struct iav_dsp_auth_unique_id { + u8 customer_name[32]; /*!< customer name */ + u8 customer_certificate[896]; /*!< customer certificate */ + u8 unique_id_signature[256]; /*!< unique ID's signature */ + u8 arm_nonce[32]; /*!< arm challenge (nonce) */ + u8 dsp_auth_result[32]; /*!< dsp responce */ + u8 dsp_out_nonce[32]; /*!< dsp challenge (nonce) */ +}; + +struct iav_dsp_auth_arm { + u8 arm_response[32]; /*!< arm responce */ +}; + +struct iav_dsplog_setup { + int cmd; /*!< Not currently supported. */ + u32 args[8]; /*!< arg[0] is used to define module while arg[1] is its log level + Log level: + 0 : MINIMAL + 1 : NORMAL + 2 : VERBOSE + 3 : DEBUG */ + u32 reserved; +}; + +struct iav_dsp_vp_cfg { + u32 vp_enable : 1; + u32 reserved : 31; + u32 cmd_addr; + u32 cmd_size; + u32 msg_addr; // including msg queue info and msg queue + u32 msg_size; + u32 vp_algo_id; +}; + +struct iav_dsp_boot_params { + u8 vout_profile; /*!< Specify VOUT profile to configure, @sa dsp_vout_profile */ + u8 osd_profile[VOUT_NUM]; /*!< Specify VOUT OSD profile to configure */ + u8 vout_profile_flag : 1; /*!< Flag to config VOUT profile */ + u8 vout_osd_profile_flag : 1; /*!< Flag to config VOUT OSD profile */ + u8 debug_chip_id_flag: 1; /*!< Flag to config debug-chip-id */ + u8 reserved1 : 5; + u8 debug_chip_id; /*!< Specify debug-chip-id to do simulation, @sa iav_chip_id + It's ONLY for internal debug purpose and works ONLY on engineering chip samples. */ + u8 reserved2[3]; +}; + +struct iav_idle_params { + u8 poweroff_vin; /*!< Flag to power off all VIN controller when DSP enter IDLE mode. */ + u8 reserved[3]; + struct iav_dsp_boot_params dsp_boot_params; /*!< Parameters ONLY used in DSP boot stage */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_state { + IAV_STATE_INIT = -1, /*!< -1 */ + IAV_STATE_IDLE = 0, /*!< 0 */ + IAV_STATE_PREVIEW = 1, /*!< 1 */ + IAV_STATE_ENCODING = 2, /*!< 2 */ + IAV_STATE_STILL_CAPTURE = 3, /*!< 3 */ + IAV_STATE_DECODING = 4, /*!< 4 */ + IAV_STATE_TRANSCODING = 5, /*!< 5 */ + IAV_STATE_DUPLEX = 6, /*!< 6 */ + IAV_STATE_EXITING_PREVIEW = 7, /*!< 7 */ +}; + +enum iav_boot_mode { + SYSTEM_NORMAL_BOOT = 0, /*!< 0 */ + SYSTEM_FAST_BOOT = 1, /*!< 1 */ +}; + +enum iav_system_query_source { + SYSTEM_PROCESS_GENERIC = 0, /*!< 0 */ + SYSTEM_PROCESS_IMAGE = 1, /*!< 1 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + + +/*! @addtogroup iav-ioctl-general-struct + */ +struct iav_system_info { + u16 query_source; /*!< Query Source ID, @sa iav_system_query_source */ + u16 boot_mode; /*!< System Boot Mode, @sa iav_boot_mode */ + u16 reserved[2]; +}; + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_canvas_type { + IAV_CANVAS_TYPE_OFF = 0, /*!< 0 */ + IAV_CANVAS_TYPE_ENCODE = 1, /*!< 1 */ + IAV_CANVAS_TYPE_PREVIEW = 2, /*!< 2 */ + IAV_CANVAS_TYPE_NUM = 3, /*!< 3 */ +}; + +enum iav_canvas_state { + IAV_CANVAS_STATE_UNKNOWN = 0, /*!< 0 */ + IAV_CANVAS_STATE_IDLE = 1, /*!< 1 */ + IAV_CANVAS_STATE_BUSY = 2, /*!< 2 */ + IAV_CANVAS_STATE_ERROR = 255, /*!< 255 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + */ +struct iav_canvas_info { + u32 canvas_id : 8; /*!< Canvas ID */ + u32 reserved : 24; + enum iav_canvas_type type; /*!< Canvas Type enumeration, @sa iav_canvas_type */ + enum iav_canvas_state state; /*!< Canvas State enumeration, @sa iav_canvas_state */ +}; + +/*! @addtogroup iav-ioctl-general-helper + */ +enum iav_stream_state { + IAV_STREAM_STATE_IDLE = 0, /*!< 0 */ + IAV_STREAM_STATE_STARTING = 1, /*!< 1 */ + IAV_STREAM_STATE_ENCODING = 2, /*!< 2 */ + IAV_STREAM_STATE_STOPPING = 3, /*!< 3 */ + IAV_STREAM_STATE_UNKNOWN = 255, /*!< 255 */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_stream_info { + u32 id; /*!< Stream ID */ + enum iav_stream_state state; /*!< Stream State enumeration, @sa iav_stream_state */ +}; + +struct iav_privacy_mask_info { + u8 channel_id; /*!< Specify the channel ID to get privacy mask information */ + u8 multi_factor; /*!< It reports the IDSP PM buffer to Main buffer scaling factor */ + u16 buffer_width; /*!< It reports the IDSP PM buffer width */ + u16 buffer_height; /*!< It reports the IDSP PM buffer height */ + u16 buffer_pitch; /*!< It reports the IDSP PM buffer pitch */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + */ +enum iav_info_id { + IAV_INFO_SYSTEM = 0x00, /*!< 0x00 */ + IAV_INFO_DRIVER = 0x01, /*!< 0x01 */ + IAV_INFO_CANVAS = 0x02, /*!< 0x02 */ + IAV_INFO_STREAM = 0x03, /*!< 0x03 */ + IAV_INFO_MASK = 0x04, /*!< 0x04 */ + IAV_INFO_WAFER_ID = 0x05, /*!< 0x05 */ + IAV_INFO_UNIQUE_ID = 0x06, /*!< 0x06 */ + IAV_INFO_NUM = 0x07, /*!< 0x07 */ +}; + +enum iav_dsp_auth_type { + DSP_AUTH_UNIQUE_ID = 0, /*!< 0x00 */ + DSP_AUTH_ARM = 1, /*!< 0x01 */ +}; + +/*! @addtogroup iav-ioctl-general-struct + */ +struct iav_queryinfo { + enum iav_info_id qid; + union { + struct iav_system_info system_info; /*!< Query system info */ + struct iav_driver_version driver; /*!< Query driver version */ + struct iav_canvas_info canvas; /*!< Query canvas info, such as state / type */ + struct iav_stream_info stream; /*!< Query stream info, such as state */ + struct iav_privacy_mask_info mask_info; /*!< Query privacy mask info */ + struct iav_unique_id unique_id; /*!< Query unique ID */ + u64 chip_wafer_id; /*!< Query Chip Unique Wafer ID */ + } arg; +}; + +/*! @addtogroup iav-ioctl-general-struct + */ +struct iav_dsp_auth { + enum iav_dsp_auth_type type; + union { + struct iav_dsp_auth_unique_id auth_unique_id; + struct iav_dsp_auth_arm auth_arm; + } auth; +}; + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_system_params { + IAV_STREAM_MAX_NUM_IMPL = 10, /*!< 10 */ + IAV_STREAM_MAX_NUM_EXTRA = 3, /*!< 3 */ + IAV_STREAM_MAX_NUM_ALL = (IAV_STREAM_MAX_NUM_IMPL + IAV_STREAM_MAX_NUM_EXTRA), /*!< IAV_STREAM_MAX_NUM_IMPL + IAV_STREAM_MAX_NUM_EXTRA */ +}; + +enum iav_hdr_type { + HDR_TYPE_OFF = 0, /*!< 0 */ + HDR_TYPE_BASIC = 1, /*!< 1 */ + HDR_TYPE_ADV_WITH_CE = 2, /*!< 2 */ + HDR_TYPE_TOTAL_NUM = 3, /*!< 3 */ +}; + +enum iav_iso_type { + ISO_TYPE_LOW = 0, /*!< 0 */ + ISO_TYPE_MIDDLE = 1, /*!< 1 */ + ISO_TYPE_ADVANCED = 2, /*!< 2 */ + ISO_TYPE_CISO = 3, /*!< 3 */ + ISO_TYPE_HIGH = 4, /*!< 4 */ + ISO_TYPE_FUSION = 5, /*!< 5 */ + ISO_TYPE_TOTAL_NUM = 6, /*!< 6 */ + ISO_TYPE_FIRST = ISO_TYPE_LOW, /*!< ISO_TYPE_LOW */ + ISO_TYPE_LAST = ISO_TYPE_TOTAL_NUM, /*!< ISO_TYPE_TOTAL_NUM */ +}; + +enum iav_max_vwarp_waitlines_count { + VWARP_WAITLINES_MIN = 0, /*!< 0 */ + VWARP_WAITLINES_MAX = 255, /*!< 255 */ +}; + +enum iav_eis_delay_count { + EIS_DELAY_COUNT_OFF = 0, /*!< 0 */ + EIS_DELAY_COUNT_MAX = 3, /*!< 3 */ +}; + +enum iav_back_pressure_margin { + BACK_PRESSURE_MARGIN_OFF = 0, /*!< 0 */ + BACK_PRESSURE_MARGIN_MAX = 3, /*!< 3 */ +}; + +enum iav_me0_scale { + ME0_SCALE_OFF = 0, /*!< 0 */ + ME0_SCALE_8X = 1, /*!< 1 */ + ME0_SCALE_16X = 2, /*!< 2 */ + ME0_SCALE_TOTAL_NUM = 3, /*!< 3 */ +}; + +enum iav_debug_type { + DEBUG_TYPE_STITCH = (1 << 0), /*!< 1 << 0 */ + DEBUG_TYPE_CHIP_ID = (1 << 1), /*!< 1 << 1 */ + DEBUG_TYPE_MAX_CHROMA_RADIUS = (1 << 2), /*!< 1 << 2 */ + DEBUG_TYPE_SKIP_EFM_MB = (1 << 3), /*!< 1 << 3 */ + DEBUG_TYPE_BREAK_POINT = (1 << 4), /*!< 1 << 4 */ + DEBUG_TYPE_VP_DRAM_PRIORITY = (1 << 5), /*!< 1 << 5 */ + DEBUG_TYPE_VSYNC_LOSS_TIMEOUT = (1 << 6), /*!< 1 << 6 */ + DEBUG_TYPE_HEVC_ENC_MODE = (1 << 7), /*!< 1 << 7 */ + DEBUG_TYPE_DUMP_DSP_CMD = (1 << 8), /*!< 1 << 8 */ + +}; + +/*! @enum iav vsync loss timeout + * @brief vsync loss timeout limitation + */ +enum iav_vsync_loss_timeout { + IAV_VSYNC_LOSS_TIMEOUT_MIN = 32, /*!< 32ms */ + IAV_VSYNC_LOSS_TIMEOUT_DEFAULT = 2048, /*!< 2048ms */ + IAV_VSYNC_LOSS_TIMEOUT_MAX = 4095, /*!< 4095ms */ +}; + +/*! @enum iav extra raw dram buf + * @brief iav extra raw dram buffer limitation + */ +enum iav_extra_raw_dram_buf { + IAV_EXTRA_RAW_DRAM_BUF_MIN = 0, + IAV_EXTRA_RAW_DRAM_BUF_MAX = 128, +}; + +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_srcbuf_id { + IAV_SRCBUF_MN = 0, /*!< 0, main buffer */ + IAV_SRCBUF_PC = 1, /*!< 1, 2nd buffer */ + IAV_SRCBUF_PB = 2, /*!< 2, 3rd buffer */ + IAV_SRCBUF_PA = 3, /*!< 3, 4th buffer */ + IAV_SRCBUF_PD = 4, /*!< 4, 5th buffer */ + IAV_SRCBUF_PE = 5, /*!< 5, 6th buffer */ + IAV_SRCBUF_PMN = 6, /*!< 6, virtual pre-main buffer, only for dewarp mode */ + IAV_SRCBUF_NUM = 7, /*!< 7 */ + + IAV_SRCBUF_EFM = 16, /*!< 16, EFM buffer ID for both single and multi VIN */ + + /* For user space convenience */ + IAV_SRCBUF_1 = IAV_SRCBUF_MN, /*!< IAV_SRCBUF_MN */ + IAV_SRCBUF_2 = IAV_SRCBUF_PC, /*!< IAV_SRCBUF_PC */ + IAV_SRCBUF_3 = IAV_SRCBUF_PB, /*!< IAV_SRCBUF_PB */ + IAV_SRCBUF_4 = IAV_SRCBUF_PA, /*!< IAV_SRCBUF_PA */ + IAV_SRCBUF_5 = IAV_SRCBUF_PD, /*!< IAV_SRCBUF_PD */ + IAV_SRCBUF_6 = IAV_SRCBUF_PE, /*!< IAV_SRCBUF_PE */ + + IAV_SRCBUF_FIRST = IAV_SRCBUF_MN, /*!< IAV_SRCBUF_MN */ + IAV_SRCBUF_LAST = IAV_SRCBUF_PMN, /*!< IAV_SRCBUF_PMN */ + IAV_SRCBUF_LAST_PMN = IAV_SRCBUF_PMN + 1, /*!< IAV_SRCBUF_PMN + 1 */ + IAV_SUB_SRCBUF_FIRST = IAV_SRCBUF_PC, /*!< IAV_SRCBUF_PC */ + IAV_SUB_SRCBUF_LAST = IAV_SRCBUF_PMN, /*!< IAV_SRCBUF_PMN */ +}; + +#define IAV_SRCBUF_INPUT_H_ALIGN (4) +#define IAV_SRCBUF_INPUT_V_ALIGN (2) +#define IAV_SRCBUF_OUTPUT_X_ALIGN (2) +#define IAV_SRCBUF_OUTPUT_Y_ALIGN (4) +#define IAV_SRCBUF_OUTPUT_WIDTH_ALIGN (32) +#define IAV_SRCBUF_OUTPUT_HEIGHT_ALIGN (16) + +enum iav_codec_option { + IAV_CODEC_H265_H264_MJPEG = 0x0, /*!< 0x0 */ + IAV_CODEC_H265_MJPEG = 0x1, /*!< 0x1 */ + IAV_CODEC_H264_MJPEG = 0x2, /*!< 0x2 */ + IAV_CODEC_MJPEG_ONLY = 0x3, /*!< 0x3 */ + IAV_CODEC_TOTAL_NUM = 0x4, /*!< 0x4 */ +}; + +enum iav_srcbuf_state { + IAV_SRCBUF_STATE_UNKNOWN = 0, /*!< 0 */ + IAV_SRCBUF_STATE_IDLE = 1, /*!< 1 */ + IAV_SRCBUF_STATE_BUSY = 2, /*!< 2 */ + IAV_SRCBUF_STATE_ERROR = 255, /*!< 255 */ +}; + +enum iav_pyramid_scale { + IAV_PYRAMID_SCALE_SQRT2 = 0, /*!< 0, 1/sqrt(2) for each layers, both width and height */ + IAV_PYRAMID_SCALE_2X = 1, /*!< 1, 1/2 for each layers, both width and height */ + IAV_PYRAMID_SCALE_ARBITRARY = 2, /*!< 2, arbitrary size for pyramid layer 1 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_pyramid_cfg { + u32 chan_id : 4; /*!< input channel ID */ + u32 enable : 1; /*!< This is a flag to specify if the pyramid is enabled */ + u32 reserved0 : 3; + u32 input_buf_id : 8; /*!< input source buffer ID */ + u32 layers_map : 6; /*!< bit map for pyramid layers, one bit for one layer */ + u32 manual_feed : 1; /*!< bit flag to control manual feed mode. 1 means using manual feed, 0 means using internal buffer. */ + u32 reserved1 : 1; + u32 item_num : 8; /*!< pyramid buffer item num for manuall feed case. Only valid when @b manual_feed is set. */ + enum iav_pyramid_scale scale_type; /*!< pyramid scale type, @sa iav_pyramid_scale */ + unsigned long buf_addr; /*!< External pyramid buffer addr. Only valid when @b manual_feed is set. */ + u32 buf_size; /*!< External pyramid buffer size. Only valid when @b manual_feed is set. */ + u8 frame_rate; /*!< Frame rate for the pyramid output layers. */ + u8 reserved2[3]; + struct iav_rect crop_win[IAV_MAX_PYRAMID_LAYERS]; /*!< Cropping window in each layer output coordinate */ + struct iav_window rescale_size; /*!< Rescale size for pyramid layer 1. The scale factor of W or H (layer0 -> layer1) must + be in the range of <b>1/8X (Upscale) to 8X (Downscale)</b>, while the scale factor from layerN (1<= N < 5) to layerN+1 is + fixed 2X (Downscale) in both width & height. Only valid when <b>"scale_type == IAV_PYRAMID_SCALE_ARBITRARY"</b>. */ +}; + +struct iav_buf_cfg { + struct iav_rect input; /*!< Source Buffer input offset and size */ + struct iav_rect output; /*!< Source Buffer output offset and size */ + u32 canvas_id : 8; /*!< Canvas ID */ + u32 reserved : 24; +}; + +struct iav_dptz { + u8 channel_id; /*!< Channel ID */ + u8 pass_id; /*!< Pass ID */ + u8 buf_id; /*!< Source Buffer ID */ + u8 reserved; + struct iav_buf_cfg buf_cfg; /*!< Source Buffer configuration */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_sync_type { + IAV_FRAME_SYNC = 0, /*!< 0 */ + IAV_STREAM_SYNC = 1, /*!< 1 */ +}; + +#define IAV_INVALID_CANVAS_ID (0xFF) +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_stream_resource { + struct iav_window max_size; /*!< The maximum resolution for encode streams, which is used for allocating memory in DSP. It is recommended not to exceed the main source buffer resolution. */ + struct iav_window efm_size; /*!< The efm buffer size and only used when efm_enable is 1. */ + u32 max_M : 8; /*!< The maximum GOP M for each streams. Streams will have B frames when M > 1. Stream A can have larger range of M from 1 to 3, while the other streams are limited to 1. */ + u32 fast_seek_enable : 1; /*!< Fast seek enable flag for each stream. */ + u32 two_ref_enable : 1; /*!< Two ref enable flag for each stream. */ + u32 max_svct_layers_minus_1 : 2;/*!< This is a flag to specify the value for the maximum SVCT layers minus 1. */ + u32 max_num_minus_1_ltrs : 1; /*!< Maximum long term number minus 1 for stream */ + u32 codec_enable : 3; /*!< Stream codec configuration @sa iav_codec_option */ + u32 stream_mv_statis_enable : 1;/*!< This is a flag to enable MV(motion vector) dump for each stream. */ + u32 efm_enable : 1; /*!< This is a flag to enable / disable encoding from memory */ + u32 efm_buf_num : 4; /*!< The efm buffer number in one efm buffer pool and only used when efm_enable is 1 */ + u32 efm_skip_waiting : 1; /*!< The efm_skip_waiting skip waiting for encoding start/stop status when it's value is 1 and only used when efm_enable is 1 */ + u32 reserved : 9; +}; + +struct iav_canvas_order { + u32 id : 5; /*!< Canvas ID */ + u32 valid : 1; /*!< This is a flag to enable / disable Canvas Channel Order. */ + u32 chan_num : 4; /*!< The total number of channels whose source buffers are on current Canvas. */ + u32 reserved : 22; + u8 chan_order[IAV_MAX_CHANNEL_NUM]; /*!< Channel orders */ +}; + +struct iav_canvas_fps { + u32 id : 5; /*!< Canvas ID */ + u32 reserved : 27; + u32 frame_rate; /*!< Canvas frame rate */ +}; + +struct iav_canvas_cfg { + struct iav_window max; /*!< Canvas width and height */ + enum iav_canvas_type type; /*!< Canvas Type, @sa iav_canvas_type */ + s8 extra_dram_buf; /*!< The extra dram buffer number for current Canvas. Valid range -3~4. */ + u8 vout_id : 1; /*!< This is a flag to set VOUT ID. It is valid only when Canvas Type is IAV_CANVAS_TYPE_PREVIEW. */ + u8 vout_YUV422 : 1; /*!< Specify VOUT YUV data format. 0: YUV420; 1: YUV422 */ + u8 reserved : 6; + u8 frame_rate; /*!< Frame rate for the canvas containing sub source buffers. */ + u8 reserved1[1]; + struct iav_canvas_order order; /*!< Canvas Channel Order, @sa iav_canvas_order */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum IAV_BLEND_AREA { + IAV_BLEND_LEFT_OR_TOP = 0, /*!< 0, This stands for left channel or top channel. */ + IAV_BLEND_RIGHT_OR_BOT = 1, /*!< 1, This stands for right channel or bottom channel. */ + IAV_BLEND_NUM = 2, /*!< 2 */ + IAV_BLEND_INVALID = 0xFF, /*!< 0xFF */ +}; + +enum IAV_BLEND_PARAM { + IAV_BLEND_NONBLOCK = (1 << 0), /*!< 1 << 0 */ + IAV_BLEND_ALPHA_ADDR_INVALID = 0xFFFFFFFF, /*!< 0xFFFFFFFF */ + IAV_BLEND_OVERLAP_AREA_MAX = 0x7, /*!< 0x7. Maximum overlap area number. */ +}; + +enum IAV_BLEND_TYPE { + IAV_BLEND_TYPE_NONE = 0, /*!< 0 */ + IAV_BLEND_TYPE_HOR = 1, /*!< 1, This is to specify multi-channel stitched horizontally (Left & Right). */ + IAV_BLEND_TYPE_VER = 2, /*!< 2, This is to specify multi-channel stitched vertically (Top & Bottom). */ + IAV_BLEND_TYPE_NUM, /*!< 3 */ + + IAV_BLEND_TYPE_FIRST = IAV_BLEND_TYPE_NONE, /*!< IAV_BLEND_TYPE_NONE */ + IAV_BLEND_TYPE_LAST = IAV_BLEND_TYPE_NUM, /*!< IAV_BLEND_TYPE_NUM */ +}; + +#define IAV_CUSTOM_SEI_SIZE_MIN (16) +#define IAV_CUSTOM_SEI_SIZE_MAX (0x8000) + +enum iav_yuv_format { + IAV_YUV_FORMAT_YUV422 = 0, /*!< 0 */ + IAV_YUV_FORMAT_YUV420 = 1, /*!< 1 */ + IAV_YUV_FORMAT_YUV400 = 2, /*!< 2 */ +}; + +#define IAV_IMG_SCALE_BUF_ALIGN (4) +#define IAV_IMG_SCALE_BUF_PITCH_ALIGN (64) +#define IAV_IMG_SCALE_Q_DEPTH_MAX (16) +#define IAV_IMG_SCALE_Q_DEPTH_MIN (8) + +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_pass_cfg { + u8 input_pass_id; /*!< Input pass ID for current pass */ + u8 input_buf_id; /*!< Input buffer ID for current pass, fixed from Main (0) only */ + u8 reserved[2]; +}; + +struct iav_chan_cfg { + u8 vsrc_id; /*!< VIN Source ID from which current channel gets the raw data */ + u8 pass_num; /*!< Total pass num for current channel */ + u8 reserved0[2]; + struct iav_rect input; /*!< The capture raw area from VIN. Currently always default to the whole VIN area. */ + struct iav_pass_cfg pass_cfg[IAV_MAX_PASS_NUM]; + struct iav_window buf_max[IAV_MAX_PASS_NUM][IAV_SRCBUF_NUM]; /*!< The maximum resolution(only width is needed) + for source buffers, which is used for allocating line buffers in DSP. It is recommended not + to exceed the sensor resolution. */ + u16 max_padding_width; /*!< The maximum padding width for LDC stitching. It should only be set when @b lens_warp_enable = 1. */ + u16 max_main_input_width; /*!< The maximum input width for main buffer. This param needs to be configured when user application + wants to get a small main buffer input size like 720x480 with a large vin size like 3840x2160. If + this param is set, main buffer input width cannot exceed it through run-time update during Prevew / + Encoding state. Default is 0(equals to VIN raw width). */ + u8 idsp_fps; /*!< IDSP output FPS. Since CV22 supports FPS downsampling, customers can use this parameter to select + a channel FPS lower than VIN FPS. Default is 0(equals to VIN FPS). */ + u8 blend_left_or_top : 1; /*!< This is a flag to enable / disable left / top channel blend. It's ONLY available when + system is NOT IAV_BLEND_TYPE_NONE. */ + u8 blend_right_or_bot : 1; /*!< This is a flag to enable / disable right / bot channel blend. It's ONLY available when + system is NOT IAV_BLEND_TYPE_NONE. */ + u8 mctf_cmpr : 1; /*!< This is a flag to enable / disable mctf compression. Default is 1. */ + u8 mctf_10bit_ref : 1; /*!< This is a flag to enable / disable mctf 10-bit reference. Default is 0. */ + u8 main_burst_tile : 1; /*!< This is a flag to enable / disable main burst tile mode. Default is 1. */ + u8 vin_overflow_protection : 1; /*!< This is a flag to enable / disable VIN overflow protection. */ + u8 lens_warp_enable : 1; /*!< This is a flag to enable / disable lens warp. It must be enabled if user want to test LDC function. */ + u8 use_vsrc_ctx_pattern : 1; /*!< This is a flag to enable / disable vsrc_ctx pattern mode. */ + u8 img_stats_src_chan; /*!< The source channel ID whose 3A statistic data is used to do 3A control for current channel. + Generally, each channel uses its own 3A statistic data to do 3A control. While for application + cases like multi-channel from single vin or stitching among different channels, all channels + can use the same channel's 3A statistic data to do 3A control. */ + u8 vsrc_ctx; /*!< Specify the sensor Context ID of vsrc_id for current channel. + For dual-context supported sensors, vsrc_ctx can be set to 1. Else, only 0 is used. */ + u32 vsrc_ctx_pattern; /*!< vsrc_ctx pattern. Only valid when use_vsrc_ctx_pattern = 1. */ + u32 vsrc_ctx_pattern_mask; /*!< vsrc_ctx pattern mask. Only valid when use_vsrc_ctx_pattern = 1. */ + u32 sensor_ctrl : 1; /*!< This is a flag to enable / disable setting shutter/agc control to current channel's + VIN Source. When current channel is a virtual channel in multi-channel from single vin case, + need to set this flag to 0. Default is 1. */ + u32 expo_num : 3; /*!< Exposure number. Valid range is 1~4. By default, IAV driver sets expo_num + according to hdr_mode in struct vindev_mode */ + u32 hdr_type : 2; /*!< Current Channel's HDR mode. @b Read @b Only. */ + u32 low_delay_vin_vout : 1; /*!< This is a flag to enable / disable low delay vin / vout. Only valid in enc-mode 0. */ + u32 max_vwarp_wait_lines : 10; /*!< Specify maximum vwarp wait lines for LDC and fisheye dewarp use case. */ + u32 invert_mode : 1; /*!< This is a flag to enable / disable invert mode. Default is 0. */ + u32 packing_mode_enable : 1; /*!< This is a flag to enable / disable VIN packing mode. Only valid when raw_capture_enable = 1. */ + u32 rotate_cw : 1; /*!< Channel clockwise 90 degree rotation flag; 0: No clockwise rotation of 90; 1: A clockwise rotation of 90. */ + u32 hflip : 1; /*!< Channel horizontal flip flag; 0: No horizontal flip; 1: Horizontal flip */ + u32 vflip : 1; /*!< Channel vertical flip flag; 0: No vertical flip; 1: Vertical flip */ + u32 extra_downscale_enable : 1; /*!< Enable extra downscale if downscale >= 6X. Default is 0. */ + u32 is_still_fusion_proc : 1; /*!< This is a flag to show if current channel does still fusion or video fusion. @b Read @b Only. */ + u32 fusion_mode_flags : 8; /*!< This is a flag to show if current channel processes RGB or IR input in + DSP_FUSION_MODE. 255: RGB input; 2: IR input. @b Read @b Only. */ + u16 max_warp_input_width; /*!< The maximum warp input width. */ + u16 max_warp_output_width; /*!< The maximum warp output width. */ +}; + +struct iav_img_scale_cfg { + u8 enable : 1; /*!< This is a flag to enable img scale */ + u8 reserved1 : 7; + u8 src_buf_id; /*!< Read only. Show src_buf_id used by img scale */ + u8 job_queue_depth; /*!< Specify the depth of scaling task queue inside DSP */ + u8 reserved2; + u16 max_input_width; /*!< Specify max input width */ + u16 max_output_width; /*!< Specify max output width */ +}; + +struct iav_scale_buf_info { + u32 pid; /*!< Specify memory partition id. Only valid when use_phys = 0 */ + u32 use_phys : 1; /*!< This is a flag to specify if the buffer start address is physcial + address (use_phys = 1) or offset within a memory partition (use_phys = 0). */ + u32 reserved : 31; + union { + unsigned long y_offset; /*!< Specify Y buffer offset within the memory partition. Only valid when use_phys = 0 */ + unsigned long y_addr; /*!< Specify Y buffer physical address. Only valid when use_phys = 1 */ + }; + union { + unsigned long uv_offset; /*!< Specify UV buffer offset within the memory partition. Only valid when use_phys = 0 */ + unsigned long uv_addr; /*!< Specify UV buffer physical address. Only valid when use_phys = 1 */ + }; + u16 pitch; /*!< buffer pitch */ + u16 height; /*!< buffer height */ +}; + +struct iav_img_scale { + enum iav_yuv_format format; /*!< YUV format */ + + struct iav_rect input; /*!< input crop window in input_buf domain. */ + struct iav_window output; /*!< output size in output_buf domain. */ + + struct iav_scale_buf_info input_buf; /*!< input YUV buffer. Y is planar format, UV is interleaved format. */ + struct iav_scale_buf_info output_buf; /*!< output YUV buffer. Y is planar format, UV is interleaved format. */ + + u32 non_block_flag : 1; /*!< non-blocking call flag */ + u32 reserved : 31; + + u64 task_id; /*!< Output param: the unique task id of current image scaling task. */ +}; + +struct iav_wait_img_scale { + u64 task_id; /*!< Unique image scaling task id */ +}; + +struct iav_system_resource { + u8 encode_mode; /*!< Encode modes for different cases. @sa dsp_mode. + 0x00: Advanced ISO mode. This is the mode for lowest latency from VIN to VOUT. + 0x01: Multiple Region Warp mode. This is the mode for multi-region fisheye dewarp. + 0x02: Sensor Fusion mode. This is the mode for Video or Image fusion. + 0x03: Multiple Pass IDSP Rotation mode. This is the mode for multi-pass scale with rotation. + 0x05: Line interleaved HDR mode. This is the mode for 3X HDR and multi-pass scale. + 0xFF: Current encode mode. This is the mode to get current encode mode number. */ + u8 max_stream_num; /*!< The maximum supported stream number in the specified encode mode */ + u8 canvas_num; /*!< Canvas number. @sa IAV_MAX_CANVAS_BUF_NUM */ + u8 chan_num; /*!< Channel number. @sa IAV_MAX_CHANNEL_NUM */ + + /* Read only */ + u32 raw_pitch_in_bytes; /*!< @b Read @b only. It indicates the raw pitch in bytes. */ + u32 total_memory_size : 8; /*!< @b Read @b only. It indicates the total DRAM size used in the system. */ + u32 iso_type : 3; /*!< @b Read @b only. This is a flag to specify the ISO type */ + u32 is_stitched : 1; /*!< @b Read @b only. This is a flag to specify whether VIN is stitched or not */ + u32 vout_only : 1; /*!< @b Read @b only. This is a flag to specify whether to use VOUT only or not */ + u32 reserved1 : 19; + + /* Writable for different configuration */ + u32 raw_capture_enable : 1; /*!< This is a flag to enable / disable raw capture function. It's only valid in some encode modes. */ + u32 mixer_a_enable : 1; /*!< This is a flag to enable / disable mixer a */ + u32 mixer_b_enable : 1; /*!< This is a flag to enable / disable mixer b */ + u32 osd_from_mixer_a : 1; /*!< This is a flag to specify mixer a used for OSD */ + u32 osd_from_mixer_b : 1; /*!< This is a flag to specify mixer b used for OSD */ + u32 vsync_detection_disable : 1;/*!< Disable vsync detection or not */ + u32 me0_scale : 2; /*!< This is a flag to indicate ME0 scale factor, @sa iav_me0_scale */ + u32 eis_delay_count : 2; /*!< This is a flag to specify EIS delay frame num */ + u32 back_pressure_margin : 2; /*!< Back pressure margin count */ + u32 hevc_off : 1; /*!< Disable HEVC encoding */ + u32 enc_sync_type : 1; /*!< Select frame synchronization or stream synchronization */ + u32 enc_raw_rgb : 1; /*!< This is a flag to enable / disable encoding from raw CFA data */ + u32 enc_raw_yuv : 1; /*!< This is a flag to enable / disable encoding from raw YUV data(must be YUV422 format) */ + + u32 emirror_vout_sync_enable : 1;/*!< This is a flag to enable / disable emirror vout sync. */ + u32 custom_sei : 1; /*!< This is a flag to enable / disable allocating customized SEI buffer from DSP. */ + u32 blend_stitch_type : 2; /*!< Specify blend type for multi-channel stitching, @sa IAV_BLEND_TYPE */ + u32 hevc_pjpeg_size_MB_per_tile : 4; /*!< Specify the DRAM size of HEVC and PJPEG encoding buffer. */ + u32 prev_bottom_repeat_disabled : 1; /*!< Disable preview buffer bottom repeat. Tell DSP to not repeat + last line 8x times for the height alignment. This is ONLY used for + the canvas composite from multi-channel preview buffers. */ + u32 vsync_loss_dummy_frame_enable : 1; /*!< When enabling this flag, DSP will use PM to cover the whole vysnc-loss channel. */ + u32 reserved2 : 6; + + struct iav_window raw_size; /*!< The maximum resolution for raw data, which is used for allocating memory in DSP. + This is only used when enc_raw_rgb or enc_raw_yuv is enabled. */ + + u32 custom_sei_buf_size; /*!< The buffer size of customized SEI. It is used for allocating memory in DSP. + Only valid when @b custom_sei is enabled. */ + u16 custom_sei_buf_num; /*!< The maximum number of customized SEI buffers can be requested + from DSP. Only valid when @b custom_sei is enabled. */ + u16 enc_dummy_latency; /*!< The latency of frame count before encode */ + u8 extra_raw_dram_buf_num; /*!< The number of extra raw dram buffer */ + u8 reserved3[15]; + + struct iav_stream_resource stream[IAV_STREAM_MAX_NUM_ALL]; /*!< Stream Resource */ + struct iav_chan_cfg chan_cfg[IAV_MAX_CHANNEL_NUM]; /*!< Channel configuration */ + struct iav_canvas_cfg canvas_cfg[IAV_MAX_CANVAS_BUF_NUM]; /*!< Canvas configuration */ + struct iav_img_scale_cfg img_scale_cfg; /*!< img scale configuration */ + + /* Debug only */ + u32 debug_enable_map; /*!< This is a bit map to specify debug options. @sa iav_debug_type + Bit 0: Enable / Disable debug stitch option + Bit 1: Enable / Disable debug chip ID option + Bit 2: Enable / Disable debug maximum chroma radius + Bit 3: Enable / Disable debug skip macro block calculation for EFM streams + Bit 4: Enable / Disable debug break point for ISP + Bit 5: Set debug vp dram priority + Bit 6: Set debug vsync loss timeout time + Bit 7: Set debug hevc encode mode + Bit 8: Enable / Disable debug dsp cmd */ + + u32 debug_stitched : 1; /*!< This is a debug flag to specify the debug stitched option */ + u32 debug_chip_id : 6; /*!< This is a debug option to specify the debug chip ID */ + u32 debug_max_chroma_radius : 2; /*!< This is a debug option to specify the maximum chroma radius, @sa iav_chroma_radius_num */ + u32 debug_skip_efm_mb : 1; /*!< This is a debug flag to specify the debug skip efm MB in total MB calculation */ + u32 debug_break_point : 1; /*!< This is a debug flag to specify IK debug point or not. 0: Disable, 1: Enable */ + u32 debug_hevc_enc_mode : 3; /*!< This is debug flag to specify HEVC encode mode. */ + u32 debug_vp_dram_priority : 3; /*!< This is a debug option to specify the DRAM R/W priority of VP.*/ + u32 debug_vsync_loss_timeout : 12; /*!< This is a debug option to specify the vsync loss timeout time(ms).*/ + u32 debug_dump_dsp_cmd : 1; /*!< This is a debug option to enable dump dsp default cmd queue for fastboot. 0: Disable, 1: Enable */ + u32 reserved4 : 2; +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum iav_chroma_radius_num { + CHROMA_RADIUS_32 = 0, /*!< 0 */ + CHROMA_RADIUS_64 = 1, /*!< 1 */ + CHROMA_RADIUS_128 = 2, /*!< 2 */ + CHROMA_RADIUS_TOTAL_NUM, +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_enc_mode_cap { + struct iav_window min_main; /*!< The min resolution for main buffer */ + struct iav_window max_main; /*!< The max resolution for main buffer */ + struct iav_window min_enc; /*!< The min resolution for encoding */ + u8 encode_mode; /*!< Encode modes for different cases */ + u8 max_streams_num; /*!< Maximum supported stream number */ + u8 max_chroma_radius : 2; /*!< Maximum chroma radius, @sa iav_chroma_radius_num */ + u8 max_wide_chroma_radius : 2; /*!< Maximum wide chroma radius, @sa iav_chroma_radius_num */ + u8 reserved0 : 4; + u8 reserved1; + u32 max_encode_MB; /*!< The maximum encode macro blocks */ + u32 raw_cap_possible : 1; /*!< Possibility to enable raw picture capture */ + u32 vout_swap_possible : 1; /*!< Possibility to support swap VOUT function */ + u32 lens_warp_possible : 1; /*!< Possibility to support lens warp */ + u32 iso_type_possible : 3; /*!< Possibility of supported ISO types */ + u32 enc_raw_rgb_possible : 1; /*!< Possibility to support encode from raw CFA data input function. It's not available and it's for internal debug only. */ + u32 high_mp_possible : 1; /*!< Possibility to support high mega pixels encoding */ + u32 linear_possible : 1; /*!< Possibility to support sensor Linear mode */ + u32 hdr_2x_possible : 2; /*!< Possibility of support HDR 2X types */ + u32 hdr_3x_possible : 2; /*!< Possibility of support HDR 3X types */ + u32 wcr_possible : 1; /*!< Possibility to support wide chroma noise filter */ + u32 me0_possible : 2; /*!< Possibility to support ME0 scale factor */ + u32 enc_from_mem_possible : 1; /*!< Possibility to support encode from memory */ + u32 enc_raw_yuv_possible : 1; /*!< Possibility to support encode from raw YUV data input function. It's not available and it's for internal debug only. */ + u32 ce_possible : 1; /*!< Possibility to support CE function */ + u32 stitch_hor_possible : 1; /*!< Possibility to support horizontal stitching. */ + u32 stitch_ver_possible : 1; /*!< Possibility to support vertical stitching. */ + u32 eis_delay_cnt_possible : 1; /*!< Possibility to support eis delay. */ + u32 dvr_possible : 1; /*!< Possibility to support digital video recording. */ + u32 vwarp_wait_lines_possible : 1; /*!< Possibility to support vwarp wait lines. */ + u32 multi_pass_possible : 1; /*!< Possibility to support multiple scaler pass. */ + u32 chan_rotate_possible : 1; /*!< Possibility to support channel rotation and flip. */ + u32 reserved_possible : 6; +}; + +struct iav_enc_buf_cap { + u8 buf_id; /*!< @sa iav_srcbuf_id */ + u8 pass_id; /*!< Pass ID */ + u8 reserved0[2]; + struct iav_window max; /*!< The maximum resolution of the buffer */ + u16 max_zoom_in_factor; /*!< Maximum supported zoom in factor */ + u16 max_zoom_out_factor; /*!< Maximum supported zoom out factor */ + u16 max_stitch_zoom_out_factor; /*!< Maximum supported zoom out factor for stitched case */ + u16 reserved1; +}; + +struct iav_mem_info { + unsigned long addr; /*!< Start address of memory partition */ + unsigned long length; /*!< Size of the memory partition. */ + unsigned long offset; /*!< Offset related to start address. */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum iav_mem_part_id { + IAV_PART_DSP = 0, /*!< 0, Partition ID for DSP partition */ + IAV_PART_BSB = 1, /*!< 1, Partition ID for bit stream partition */ + IAV_PART_USR = 2, /*!< 2, Partition ID for user data partition */ + IAV_PART_MV = 3, /*!< 3, Partition ID for motion vector partition */ + IAV_PART_OVERLAY = 4, /*!< 4, Partition ID for overlay partition */ + IAV_PART_QPMATRIX = 5, /*!< 5, Partition ID for QP ROI matrix partition */ + IAV_PART_WARP = 6, /*!< 6, Partition ID for warp vector partition */ + IAV_PART_QUANT = 7, /*!< 7, Partition ID for JPEG quant matrix table partition */ + IAV_PART_IMG = 8, /*!< 8, Partition ID for image partition */ + IAV_PART_MASK = 9, /*!< 9, Partition ID for IDSP PM partition */ + IAV_PART_FB_DATA = 10, /*!< 10, Partition ID for fast boot data partition */ + IAV_PART_FB_AUDIO = 11, /*!< 11, Partition ID for fast boot audio partition */ + IAV_PART_INTRA_PB = 12, /*!< 12, Partition ID for INTRA PB partition */ + IAV_PART_STAT = 13, /*!< 13, Partition ID for picture statistics */ + IAV_PART_BLEND_ALPHA = 14, /*!< 14, Partition ID for blend alpha buffer */ + IAV_PART_BSH = 15, /*!< 15, for internal use */ + IAV_PART_DSP_DEF_CMD = 16, /*!< 16, for internal use */ + IAV_PART_DSP_UCODE = 17, /*!< 17, Partition ID for UCODE partition */ + IAV_PART_DSP_LOG = 18, /*!< 18, for internal use */ + IAV_PART_DSP_FIFO = 19, /*!< 19, for internal use */ + IAV_PART_DSP_RSV = 20, /*!< 20, for internal use */ + IAV_PART_IAV_RSV = 21, /*!< 21, for internal use */ + IAV_PART_PREALLOC = 22, /*!< 22, for internal use */ + IAV_PART_PREALLOC2 = 23, /*!< 23, for internal use */ + IAV_PART_PYRAMID_POOL = 24, /*!< 24, Partition ID for Pyramid buffer pool in Pyramid manual-feed mode or in decode mode */ + IAV_PART_QPMATRIX_RAW = 25, /*!< 25, Partition ID for QPMATRIX_RAW partition */ + IAV_PART_NUM, /*!< 26, total number of memory partition */ + IAV_PART_FIRST = IAV_PART_DSP, /*!< IAV_PART_DSP */ + IAV_PART_LAST = IAV_PART_NUM, /*!< IAV_PART_NUM */ + + IAV_PART_USR_CUSTOM_ID_FIRST = 192, /*!< 192, First customer ID for user memory partition */ + IAV_PART_USR_CUSTOM_ID_LAST = 255, /*!< 255, Last customer ID for user memory partition */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_mem_part_info { + u32 pid; /*!< Memory partiton item ID, @sa iav_mem_part_id */ + struct iav_mem_info mem; /*!< Memory partition description. */ +}; + +struct iav_alloc_mem_part { + u32 pid; /*!< The IAV/DSP sub-partition ID to be allocated, @sa iav_mem_part_id. + For anonymous memory partition allocation, pid is the output parameter + and an unique ID that represents this allocated memory partition. */ + u32 enable_cache : 1; /*!< This flag enables or disables the cache when the memory partition is mapped to the user space. + (@b Note: Currently, this flag is only valid for anonymous memory partitions.) */ + u32 reserved0 : 31; + unsigned long length; /*!< As input: the mem part size to be allocated. + As output: the real size of the allocated mem part. */ + unsigned long offset; /*!< the physical address of the allocated mem part. */ +}; + +struct iav_free_mem_part { + u32 pid; /*!< The mem part to be freed, @sa iav_mem_part_id */ +}; + +struct iav_feed_pyramid { + u8 chan_id; /*!< Specifies the channel ID that needs to feed the pyramid buffer. */ + u8 reserved0[3]; +}; + +struct iav_mem_canvas_info { + u32 id_map; /*!< The canvas id map for the queried canvases' memory blocks. */ + struct iav_mem_info yuv[IAV_MAX_CANVAS_BUF_NUM]; /*!< The memory partition information of YUV buffer. */ + struct iav_mem_info me[IAV_MAX_CANVAS_BUF_NUM]; /*!< The memory partition information of ME buffer. */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum iav_mem_id { + IAV_MEM_PARTITION = 0x00, /*!< 0x00 */ + IAV_MEM_CANVAS = 0x01, /*!< 0x01 */ + IAV_MEM_NUM = 0x02, /*!< 0x02 */ +}; + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_querymem { + enum iav_mem_id mid; /*!< Query memory block item ID, @sa iav_mem_id */ + union { + struct iav_mem_part_info partition; + struct iav_mem_canvas_info canvas; + } arg; +}; + + +/*! @addtogroup iav-ioctl-general-helper */ +#define IAV_GDMA_MAX_WIDTH (4096) + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_gdma_copy { + union { + unsigned long src_offset; /*!< The offset of the source, based on the start address of its memory partition. + Use this parameter is only when @b src_use_phys = 0 and @b src_mmap_type are set properly. */ + unsigned long src_addr; /*!< The physical address of the source. This parameter is used only when @b src_use_phys = 1. */ + }; + union { + unsigned long dst_offset; /*!< The offset of the destination based on the memory partition start address. + This parameter is used only when @b dst_use_phys = 0 and @b dst_mmap_type are set properly. */ + unsigned long dst_addr; /*!< The physical address of the destination. This parameter is used only when @b dst_use_phys = 1. */ + }; + u16 src_pitch; /*!< Data pitch of the source */ + u16 dst_pitch; /*!< Data pitch of the destination */ + u16 src_use_phys : 1; /*!< A flag that determines whether @b src_addr or @b src_offset are used. */ + u16 dst_use_phys : 1; /*!< A flag that determines whether @b dst_addr or @b dst_offset are used. */ + u16 reserved : 14; + u16 width; /*!< The width of the memory copy region */ + u32 height; /*!< The height of the memory copy region */ + u32 src_mmap_type; /*!< The memory partition ID of the source */ + u32 dst_mmap_type; /*!< The memory partition ID of the destination */ +}; + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_desc_id { + IAV_DESC_FRAME = 0, /*!< 0, Query frame info after encoding */ + IAV_DESC_STATIS = 1, /*!< 1 */ + IAV_DESC_RAW = 2, /*!< 2 */ + IAV_DESC_SLICE = 3, /*!< 3 */ + IAV_DESC_PRE_FRAME = 4, /*!< 4 */ + IAV_DESC_PRE_COUNT = 5, /*!< 5 */ + IAV_DESC_CANVAS = 6, /*!< 6 */ + IAV_DESC_BLEND_YUV = 7, /*!< 7 */ + IAV_DESC_PYRAMID = 8, /*!< 8 */ + IAV_DESC_NUM = 9, /*!< 9 */ + IAV_DESC_FIRST = IAV_DESC_FRAME, /*!< IAV_DESC_FRAME */ + IAV_DESC_LAST = IAV_DESC_NUM, /*!< IAV_DESC_NUM */ +}; + +enum iav_stream_type { + IAV_STREAM_TYPE_NONE = 0x0, /*!< 0x0 */ + IAV_STREAM_TYPE_H264 = 0x1, /*!< 0x1 */ + IAV_STREAM_TYPE_MJPEG = 0x2, /*!< 0x2 */ + IAV_STREAM_TYPE_H265 = 0x3, /*!< 0x3 */ + IAV_STREAM_TYPE_NUM = 0x4, /*!< 0x4 */ + IAV_STREAM_TYPE_INVALID = 0xFF, /*!< 0xFF */ +}; + +enum iav_pic_type { + IAV_PIC_TYPE_MJPEG_FRAME = 0, /*!< 0 */ + IAV_PIC_TYPE_IDR_FRAME = 1, /*!< 1 */ + IAV_PIC_TYPE_I_FRAME = 2, /*!< 2 */ + IAV_PIC_TYPE_P_FRAME = 3, /*!< 3 */ + IAV_PIC_TYPE_B_FRAME = 4, /*!< 4 */ + IAV_PIC_TYPE_P_FAST_SEEK_FRAME = 5, /*!< 5 */ + /* Value 6 is reseved for furture extension */ + IAV_PIC_TYPE_END_FRAME = 7, /*!< 7 */ +}; + +enum iav_statis_type { + IAV_ENC_STATIS_MV = 0x0, /*!< 0x0 */ + IAV_ENC_STATIS_HEVC = 0x1, /*!< 0x1 */ + IAV_ENC_STATIS_AVC = 0x2, /*!< 0x2 */ + IAV_ENC_STATIS_NUM = 0x3, /*!< 0x3 */ + IAV_ENC_STATIS_FIRST = IAV_ENC_STATIS_MV, /*!< IAV_ENC_STATIS_MV */ + IAV_ENC_STATIS_LAST = IAV_ENC_STATIS_NUM, /*!< IAV_ENC_STATIS_NUM */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_framedesc { + u32 id; /*!< Stream ID, -1 for read bits of all streams */ + u32 time_ms; /*!< timeout in ms. -1 (0xFFFFFFFF) means non-blocking, 0 means blocking */ + enum iav_stream_type stream_type; /*!< Stream type of the frame */ + u32 pic_type : 3; /*!< Picture type of the frame */ + u32 stream_end : 1; /*!< Flag for stream end */ + u32 reserved1 : 4; + u32 jpeg_quality : 8; /*!< Quality value for MJPEG. Valid range [0~100]. */ + u32 bitrate_kbps : 16; /*!< Real bitrate in kbps for H264 / H265 */ + u32 frame_num; /*!< Frame number of the frame */ + u32 session_id; /*!< Session ID of the stream for the frame */ + u32 size; /*!< Coded bits size for the frame */ + u32 slice_id : 8; /*!< Slice ID */ + u32 slice_num : 8; /*!< Total slice number */ + u32 tile_id : 2; /*!< Tile ID */ + u32 tile_num : 2; /*!< Total tile number */ + u32 is_ltr_frame : 1; /*!< Is long term reference frame or not */ + u32 reserved2 : 11; + u64 arm_pts; /*!< System PTS for the frame */ + u64 dsp_pts; /*!< DSP PTS for the frame */ + u64 enc_done_ts; /*!< The encode done time stamp for the frame */ + struct iav_window reso; /*!< Resolution of the encoded frame */ + unsigned long data_addr_offset; /*!< Address offset for frame coded bits */ + unsigned long mv_data_offset; /*!< Offset for MV data, @sa iav_mv */ + u16 sliceheader_offset; + u16 reserved3; +}; + +struct iav_slicedesc { + u32 id; /*!< Stream ID, -1 for read bits of all streams */ + u32 time_ms; /*!< timeout in ms; -1 (0xFFFFFFFF) means non-blocking, 0 means blocking */ + enum iav_stream_type stream_type;/*!< Stream type of the frame */ + u32 pic_type : 3; /*!< Picture type of the frame */ + u32 stream_end : 1; /*!< Flag for stream end */ + u32 reserved1 : 4; + u32 jpeg_quality : 8; /*!< Quality value for MJPEG. Valid range [0~100]. */ + u32 bitrate_kbps : 16; /*!< Real bitrate in kbps for H264 / H265 */ + u32 frame_num; /*!< Frame number of the frame */ + u32 session_id; /*!< Session ID of the stream for the frame */ + u64 arm_pts; /*!< System PTS for the frame */ + u64 dsp_pts; /*!< DSP PTS for the frame */ + u64 enc_done_ts; /*!< The encode done timestamp for the frame */ + struct iav_window reso; /*!< Resolution of the encoded frame */ + u32 slice_id : 4; /*!< Slice ID */ + u32 slice_num : 4; /*!< Total slice number */ + u32 tile_id : 2; /*!< Tile ID */ + u32 tile_num : 2; /*!< Total tile number */ + u32 reserved2 : 20; + u32 size[IAV_HEVC_TILE_NUM]; /*!< Coded bits size for the slice */ + unsigned long data_addr_offset[IAV_HEVC_TILE_NUM]; /*!< Address offset for slice coded bits */ +}; + +/* mv descriptor reported by DSP */ +struct iav_mv { + s32 x : 15; /*!< Bit [14:0] is the x component in signed 15-bit format. */ + s32 y : 12; /*!< Bit [26:15] is the y component in signed 12-bit format. */ + s32 reserved : 5; +}; + +struct iav_statisdesc { + u32 id; /*!< Stream ID, -1 for read bits of all streams */ + u32 time_ms; /*!< timeout in ms; -1 (0xFFFFFFFF) means non-blocking, 0 means blocking */ + u32 width; /*!< Width offset for frame */ + u32 height; /*!< Height offset for frame */ + u32 pitch; /*!< Pitch offset for frame */ + u32 dsp_pts; /*!< DSP PTS for the frame */ + u64 arm_pts; /*!< ARM PTS for the frame */ + u32 frame_num; /*!< Frame number of the frame */ + u32 session_id; /*!< Session ID */ + u32 size; /*!< Unit size of the frame MV dump data */ + enum iav_statis_type statis_type; /*!< Statis type */ + unsigned long data_addr_offset; /*!< Address offset for frame statistic data */ +}; + +struct iav_pre_framedesc { + u16 stream_id : 8; /*!< Stream ID, -1 for read bits of all streams */ + u16 pic_type : 3; /*!< Frame type as I, P, B */ + u16 is_ltr : 1; /*!< Long term reference P frame flag */ + u16 reserved : 4; + u16 y_pitch; /*!< YUV data pitch */ + u16 me1_pitch; /*!< ME1 data Pitch */ + u16 me0_pitch; /*!< ME0 data Pitch */ + u64 frame_no; /*!< Frame number */ + unsigned long y_addr_offset; /*!< Y data offset */ + unsigned long uv_addr_offset;/*!< UV data offset */ + unsigned long me1_addr_offset; /*!< ME1 data offset */ + unsigned long me0_addr_offset; /*!< ME0 data offset */ +}; + +struct iav_pre_countdesc { + u32 non_block_flag : 1; /*!< Query without block flag */ + u32 reserved : 31; + u8 stream_cap_count[IAV_STREAM_MAX_NUM_ALL]; /*!< Frame information count for every stream */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + + +/*! @addtogroup iav-ioctl-general-helper */ +enum IAV_BUFCAP_FLAG { + IAV_BUFCAP_NONBLOCK = (1 << 0), /*!< 1 << 0 */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_rawbufdesc { + u32 width; /*!< Width of the raw picture */ + u32 height; /*!< Height of the raw picture */ + u32 pitch; /*!< Pitch size of the raw picture */ + u32 non_block_flag : 1; /*!< Block read flag of the raw picture */ + u32 reserved1 : 23; + u32 vin_id : 8; /*!< VIN controller ID */ + u64 mono_pts; /*!< Monotonic PTS of the raw picture */ + unsigned long raw_addr_offset; /*!< Address offset for frame raw picture */ + u32 dsp_pts; /*!< DSP PTS of the raw picture */ +}; + +struct iav_yuv_cap { + u32 width; /*!< Width of the YUV data */ + u32 height; /*!< Height of the YUV data */ + u32 pitch; /*!< Pitch size of the YUV data */ + u32 seq_num; /*!< Sequence number of the YUV data */ + u32 format; /*!< Format of the YUV data */ + u32 dsp_pts; /*!< Intermediate PTS from DSP */ + u64 mono_pts; /*!< Monotonic PTS of the YUV data */ + unsigned long y_addr_offset; /*!< Address offset for frame Y data */ + unsigned long uv_addr_offset;/*!< Address offset for frame UV data */ +}; + +struct iav_me_cap { + u32 width; /*!< Width of the frame ME data */ + u32 height; /*!< Height of the frame ME data */ + u32 pitch; /*!< Pitch size of the frame ME data */ + u32 seq_num; /*!< Sequence number of the frame ME data */ + u32 dsp_pts; /*!< Intermediate PTS from DSP */ + u64 mono_pts; /*!< Monotonic PTS of the frame ME data */ + unsigned long data_addr_offset; /*!< Address offset for frame ME data */ +}; + +struct iav_canvasdesc { + u32 non_block_flag : 1; /*!< Block flag */ + u32 canvas_id : 8; /*!< Canvas ID */ + u32 reserved : 23; + struct iav_yuv_cap yuv; /*!< YUV description item */ + struct iav_me_cap me1; /*!< ME1 YUV description item */ + struct iav_me_cap me0; /*!< ME0 description item */ +}; + +struct iav_blenddesc { + u32 non_block_flag : 1; /*!< Block read flag of the blend description */ + u32 reserved : 31; + struct iav_yuv_cap yuv[IAV_BLEND_OVERLAP_AREA_MAX][IAV_BLEND_NUM]; /*!< YUV buffer information of overlapped areas */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +#define AVC_HIST_X (16) + +#define HEVC_MV_HIST_X (2) +#define HEVC_MV_HIST_Y (2) +#define HEVC_MV_HIST_K (128) +#define HEVC_QP_HIST_X (64) +#define HEVC_INTER_CNT_U8_X (5) +#define HEVC_INTER_CNT_U16_X (3) +#define HEVC_INTER_CNT_U32_X (3) +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_pic_stats_avc { + /* h264_xfHisto_t */ + u32 rsvd[16]; + u16 xfMbCatHisto[AVC_HIST_X]; /*!< Macro blocks number with corresponding QP value */ + u32 rsvd1; + + /* Nom QP Table */ + u8 qp[AVC_HIST_X]; /*!< QP values used in one encoded frame*/ + u32 reserved[1059]; + +}; + +struct iav_pic_stats_hevc { + u32 mv_histogram[HEVC_MV_HIST_X][HEVC_MV_HIST_Y][HEVC_MV_HIST_K]; // [L0/L1][x/y][abs_mv at CU8 granularity] + u32 reserved_0[30]; + u32 qp_histogram[HEVC_QP_HIST_X]; // [QP value at CU8 granularity] + u32 intra_counter_pu4; + u32 intra_counter_pu8; + u32 intra_counter_pu16; + u32 intra_counter_pu32; + u32 inter_counter_cu8[HEVC_INTER_CNT_U8_X]; // indexed by (skip/tu4_merge/tu4_mvp/tu8_merge/tu8_mvp) + u32 inter_counter_cu16[HEVC_INTER_CNT_U16_X]; // indexed by (skip/merge/mvp) + u32 inter_counter_cu32[HEVC_INTER_CNT_U32_X]; // indexed by (skip/merge/mvp) + u32 pcm_counter_cu32; + u32 reserved_1[466]; +}; + +struct iav_pyramiddesc { + u32 chan_id : 8; /*!< Channel ID */ + u32 non_block_flag : 1; /*!< Block read flag of the pyramid description */ + u32 layers_map : 6; /*!< Layer bit map. Each bit stands for one layer. 1 means enable this layer, 0 means disable this layer. */ + u32 reserved : 17; + struct iav_yuv_cap layers[IAV_MAX_PYRAMID_LAYERS]; /*!< YUV buffer information of enabled pyramid layers */ + u64 seq_num; /*!< The sequence number of current pyramid description */ +}; + +struct iav_querydesc { + enum iav_desc_id qid; /*!< query desc id */ + union { + struct iav_framedesc frame; + struct iav_statisdesc statis; + struct iav_rawbufdesc raw; + struct iav_canvasdesc canvas; + struct iav_slicedesc slice; + struct iav_pre_framedesc pre_frame; + struct iav_pre_countdesc pre_count; + struct iav_blenddesc blend; + struct iav_pyramiddesc pyramid; + } arg; +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_stream_op { + IAV_STREAM_OP_STOP = 0, /*!< 0 */ + IAV_STREAM_OP_START = 1, /*!< 1 */ +}; + +enum iav_chroma_format { + H264_CHROMA_YUV420 = 0, /*!< 0 */ + H264_CHROMA_MONO = 1, /*!< 1 */ + + JPEG_CHROMA_MONO = 0, /*!< 0 */ + JPEG_CHROMA_YUV420 = 1, /*!< 1 */ + JPEG_CHROMA_YUV422 = 2, /*!< 2 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_stream_fps { + u32 fps_multi; /*!< Multiple value for fps configuration */ + u32 fps_div; /*!< Divisor value for fps configuration */ + u32 abs_fps : 8; /*!< Absolute frame rate value. Only valid when @b abs_fps_enable is set. */ + u32 abs_fps_enable : 1; /*!< Flag to enable / disable abs FPS */ + u32 is_update_frame_rate_to_next_GOP: 1; /*!< Flag to update frame rate to next GOP. */ + u32 reserved : 22; +}; + +/*! @addtogroup iav-ioctl-general-helper */ +#define UNUSED_DURATION_NUM (1) + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_stream_format { + enum iav_stream_type type;/*!< @sa iav_stream_type */ + struct iav_rect enc_win;/*!< Encode window from source buffer */ + u32 duration : 16; /*!< Encode duration (in frames) for the stream */ + u32 enc_src_id : 8; /*!< Encode source canvas id, 0~10: Canvas 0~10, 16: EFM */ + u32 hflip : 1; /*!< Stream horizontal flip flag. 0: No horizontal flip; 1: Horizontal flip */ + u32 vflip : 1; /*!< Stream vertical flip flag. 0: No vertical flip; 1: Vertical flip */ + u32 rotate_cw : 1; /*!< Stream clockwise 90 rotation flag. + 0: No clockwise rotation of 90; 1: Clockwise rotation of 90. */ + u32 reserved : 5; + u32 efm_customize_fps; /*!< Specify the arbitrary frame rate for EFM stream */ +}; + +struct iav_fps_suggest { + u32 fps_keep_map; /*!< Bit map for stream fps keep or not: 1: Keep; 0: Not keep */ + u32 stream_exclude_map; /*!< Bit map for stream exclusion: 1: Exclude; 0: Not exclude */ + u32 stream_fps_suggest[IAV_STREAM_MAX_NUM_ALL]; /*!< Stream FPS suggest result in 16.16 Format */ + u32 vin_target_fps[VIN_INSTANCES]; /*!< VIN target fps in 16.16 Format */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum GOP_IDR_INTV { + MIN_IDR_INTV = 1, /*!< 1 */ + MAX_IDR_INTV = 128, /*!< 128 */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_h26x_gop { + u32 id; /*!< Related stream id. */ + u32 N; /*!< GOP length. */ + u32 idr_interval; /*!< GOP number between two idr.*/ + u32 is_update_N_to_next_GOP; /*!< Flag to GOP length update mode. 0: Update immediately. 1: Update at next gop. */ +}; + +struct iav_bitrate { + u32 id; /*!< Stream ID */ + u32 average_bitrate; /*!< The target average bitrate */ + u32 vbr_setting : 8; /*!< 1: IAV_BRC_CBR (obsolete); 2: IAV_BRC_PCBR (obsolete); 3: IAV_BRC_VBR (obsolete); + 4: IAV_BRC_SCBR; 5: IAV_BRC_SVBR (obsolete). This field must always be set to IAV_BRC_SCBR (Smart Constant Bitrate Control). */ + u32 qp_min_on_I : 8; /*!< This field specifies the minimum QP allowed for I picture. The valid range is 0 to 51 (inclusive). + The default value is 1. */ + u32 qp_max_on_I : 8; /*!< This field specifies the maximum QP allowed for I picture. The valid range is 0 to 51 (inclusive). + The default value is 51. */ + u32 qp_min_on_P : 8; /*!< This field specifies the minimum QP allowed for P picture. The valid range is 0 to 51 (inclusive). + The default value is 1. */ + u32 qp_max_on_P : 8; /*!< This field specifies the maximum QP allowed for P picture. The valid range is 0 to 51 (inclusive). + The default value is 51. */ + u32 qp_min_on_B : 8; /*!< This field specifies the minimum QP allowed for B picture. Not supported yet. */ + u32 qp_max_on_B : 8; /*!< This field specifies the maximum QP allowed for B picture. Not supported yet. */ + u32 i_qp_reduce : 8; /*!< This field specifies how much better to make I QP relative to P QP. To increase the ratio of I QP/ P QP, + use a small value. To reduce the ratio of I QP/ P QP, use a large value. The valid range is 1 to 10 (inclusive). + The default value is 1. */ + u32 p_qp_reduce : 8; /*!< This field specifies how much better to make P QP relative to B QP. To increase the ratio of P QP/ B QP, + use a small value. To reduce the ratio of P QP/ B QP, use a large value. The valid range is 1 to 5 (inclusive). + The default value is 1. */ + u32 adapt_qp : 8; /*!< This field specifies the strength of adaptive quantization. The valid range is 0 to 4 (inclusive). + The default value is 0. */ + u32 skip_flag : 8; /*!< When smart RC is used (bitrate_control = 4), this field specifies the criteria for RC to skip frames.(Bitwise OR) + Bit 0: RC will skip the frame based on the size of the compressed picture. + Bit 1: RC will skip the frame based on CPB size. + Bit 2: RC will skip the frame when the target bit rate is to be exceeded and the maximum QP is reached. + The default value is 0 (no frame skipping). */ + u32 q_qp_reduce : 8; /*!< Relative to P frame */ + u32 qp_max_on_Q : 8; /*!< Maximum QP allowed for Q frame */ + u32 qp_min_on_Q : 8; /*!< Minimum QP allowed for Q frame */ + u32 log_q_num_minus_1 : 3; /*!< 128 */ + u32 skip_flag_mode : 1; /*!< skip mode flag. 0: handle skip frame through drop frame. 1: through repeat frame.*/ + u32 reserved0 : 12; + u32 max_i_size_KB; /*!< Maximum I frame size */ + u32 qp_min_on_C : 8; /*!< This field specifies the minimum QP allowed for C picture. The valid range is 0 to 51 (inclusive). + The default value is 1. */ + u32 qp_max_on_C : 8; /*!< This field specifies the maximum QP allowed for C picture. The valid range is 0 to 51 (inclusive). + The default value is 51. */ + u32 qp_min_on_D : 8; /*!< This field specifies the minimum QP allowed for D picture. The valid range is 0 to 51 (inclusive). + The default value is 1. */ + u32 qp_max_on_D : 8; /*!< This field specifies the maximum QP allowed for D picture. The valid range is 0 to 51 (inclusive). + The default value is 51. */ + u32 b_qp_reduce : 8; /*!< This field specifies how much better to make b QP relative to B QP. To increase the ratio of b QP/ P-QP, + use a small value. To reduce the ratio of B QP/ P QP, use a large value. The valid range is 1 to 10 (inclusive). + The default value is 1. */ + u32 c_qp_reduce : 8; /*!< This field specifies how much better to make c QP relative to B QP. To increase the ratio of b QP/ P-QP, + use a small value. To reduce the ratio of C QP/ P QP, use a large value. The valid range is 1 to 10 (inclusive). + The default value is 1. */ + u32 svbr_ness : 10; /*!< obsolete */ + u32 cbr_stable_br_adjust : 4; /*!< Not used yet */ + u32 reserved1 : 2; + u32 vbr_min_bitrate; /*!< obsolete */ + u32 vbr_max_bitrate; /*!< obsolete */ +}; + +struct iav_h26x_weighted_pred { + u16 wp_enable; /*!< Enable Weighted Prediction */ + u16 luma_log2_weight_denom; /*!< Specify luma-log2-wegiht-denom */ + s16 luma_weight[2]; /*!< Set luma-weight[0]/luma-weight[1] */ + s16 luma_offset[2]; /*!< Set luma-offset[0]/luma-offset[1] */ +}; + +struct iav_custom_sei { + u16 enable : 1; /*!< Enable customized SEI */ + u16 repeat : 1; /*!< Repeat customized SEI in latter encoded frames */ + u16 reserved : 14; + u16 frame_idx; /*!< Frame index of customized SEI buffer that will be fed to DSP */ + u32 size; /*!< Real size of customized SEI data */ +}; + +struct iav_rc_strategy { + u32 abs_br_flag : 1; /*!< Flag for abs_br */ + u32 reserved : 31; +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +typedef enum { + QP_FRAME_I = 0, /*!< 0 */ + QP_FRAME_P = 1, /*!< 1 */ + QP_FRAME_B = 2, /*!< 2 */ + QP_FRAME_TYPE_NUM = 3, /*!< 3 */ +} QP_FRAME_TYPES; + +typedef enum { + QPROI_TYPE_CATEGORY = 0, /*!< 0 */ + QPROI_TYPE_QP_OFFSET = 1, /*!< 1 */ +} QPROI_TYPE; + +#define MD_CAT_MAX_NUM (8) + +typedef enum { + MD_CAT_LUT_TYPE_DEFAULT = 0, /*!< 0, For this CTB, it's coded as default option from DSP internal RC. */ + MD_CAT_LUT_TYPE_FORCED_ZMV = 1, /*!< 1, For this CTB, it's forced to code with Zero Motion Vector (ZMV). */ + MD_CAT_LUT_TYPE_FORCED_INTRA = 2, /*!< 2, For this CTB, it's forced to code as intra. */ + MD_CAT_LUT_TYPE_UNCOVERED_AREA = 3, /*!< 3, For this CTB, it's detected to be uncovered and is not expected to + get good prediction from any of its references. It will be coded as intra. + In conjunction, ARM should config a negative QP adjust value for these + CTBs so that they are coded as high quality. */ + MD_CAT_LUT_TYPE_BIAS_SKIP = 4, /*!< 4, For this CTB, it's bias heavily towards skipped. */ + /* more to come */ + MD_CAT_LUT_NUM = 5, /*!< 5 */ + MD_CAT_LUT_FIRST = MD_CAT_LUT_TYPE_DEFAULT, /*!< MD_CAT_LUT_TYPE_DEFAULT */ + MD_CAT_LUT_LAST = MD_CAT_LUT_NUM, /*!< MD_CAT_LUT_NUM */ +} MD_CAT_LUT_TYPE; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_h264_qproi_data { + u8 category; /*!< Macroblock level control for user_class */ + s8 qp_adjust; /*!< Macroblock level control for qp_offset. The qp_offset is added onto + the existing QP already calculated by RC and User class bin. The final + QP from RC + qp_offset is then used for this MB. */ + u8 zmv_threshold_val; /*!< Macroblock level control of threshold for zero MV. If MB's sum of Mvs + is less than this value, skip mode is encouraged. Value 8 can be used + for low bit rate at good lighting. Value 24 can be used for low bit + rate at low lighting (high noise). */ + u8 force_zmv_ref0 : 1; /*!< Macroblock level control to force zmv on reference candidate 0. When + this flag is on, force zero MV will be adopted for the target MB, if + reference 0 is used. */ + u8 force_zmv_ref1 : 1; /*!< Macroblock level control to force zmv on reference candidate 1. When + this flag is on, force zero MV will be adopted for the target MB, if + reference 1 is used. */ + u8 reserved : 6; +}; + +struct iav_h265_qproi_data { + union { + struct { + u32 cu16_0 : 3; /*!< Select md_category for 16x16 CU[0]. 0: default; 1: used as force zmv flag. */ + u32 cu16_1 : 3; /*!< Select md_category for 16x16 CU[1]. 0: default; 1: used as force zmv flag. */ + u32 cu16_2 : 3; /*!< Select md_category for 16x16 CU[2]. 0: default; 1: used as force zmv flag. */ + u32 cu16_3 : 3; /*!< Select md_category for 16x16 CU[3]. 0: default; 1: used as force zmv flag. */ + u32 cu32 : 3; /*!< Select md_category for 32x32 CU. 0: default; 1: used as force zmv flag. */ + u32 reserved_0 : 17; + }; + u32 dword1; + } category; + union { + struct { + s32 reserved_1 : 8; + s32 cu32 : 7; /*!< qp_adjust value for 32x32 CU. Valid range of -51 to 51 inclusive. */ + s32 reserved_2 : 17; + }; + u32 dword2; + } qp_adjust_32; + union { + struct { + s32 cu16_0 : 7; /*!< qp_adjust value for 16x16 CU[0]. Valid range of -51 to 51 inclusive. */ + s32 reserved_3 : 1; + s32 cu16_1 : 7; /*!< qp_adjust value for 16x16 CU[1]. Valid range of -51 to 51 inclusive. */ + s32 reserved_4 : 1; + s32 cu16_2 : 7; /*!< qp_adjust value for 16x16 CU[2]. Valid range of -51 to 51 inclusive. */ + s32 reserved_5 : 1; + s32 cu16_3 : 7; /*!< qp_adjust value for 16x16 CU[3]. Valid range of -51 to 51 inclusive. */ + s32 reserved_6 : 1; + }; + u32 dword3; + } qp_adjust_16; +}; + +struct iav_qpmatrix { + u32 id; /*!< Stream ID */ + u32 enable : 1; /*!< whether qp matrix is enabled */ + u32 qpm_no_update : 1; /*!< 1: No need from app to set the QP matrix data to IAV/DSP, just configure some other parameters. + 0: App needs to set the QP matrix data (already configured at app side) to IAV/DSP. */ + u32 qpm_no_check : 1; /*!< 1: No need for IAV to check the QP matrix data to IAV/DSP, app already guarantees the validness + for the qp matrix data. + 0: IAV needs to check the QP matrix data (already configured at app side) to IAV/DSP. */ + u32 init_qpm : 1; /*!< Init QP matrix flag to set OP */ + u32 qpm_raw : 1; /*!< QP matrix raw mapped flag for get/set op */ + u32 reserved0 : 27; + u32 data_size; /*!< The size for the QP ROI matrix */ + u32 reserved1; + unsigned long data_offset; /*!< The address offset for the QP ROI. The structure @sa iav_h264_qproi_data + or @sa iav_h265_qproi_data shows the data format. */ +}; + +struct iav_h26x_enc_param { + u32 id; + u16 user1_intra_bias; + u16 user1_direct_bias; + u16 user2_intra_bias; + u16 user2_direct_bias; +}; +/*! @} */ /* End of iav-ioctl-general-stuct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum { + IAV_ONE_BITS_INFO_PER_TILE = 0, /*!< 0 */ + IAV_ONE_BITS_INFO_PER_FRAME = 255, /*!< 255 */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_h26x_slice { + u32 slice_num : 8; /*!< Specify HEVC slice row number, from 0~255. For HEVC only */ + u32 slices_per_info : 8;/*!< Specify HEVC slices per bits information. For HEVC only */ + u32 reserved : 16; +}; + +struct iav_h26x_pskip { + u32 repeat_enable : 1; /*!< Enable repeat P-skip frame pattern */ + u32 reserved1 : 15; + u32 repeat_num : 8; /*!< Specify the skipped frame number to repeat */ + u32 reserved2 : 8; +}; + +struct iav_h26x_drop_frame { + u32 repeat_enable : 1; /*!< Enable repeat drop frame pattern */ + u32 reserved1 : 15; + u32 drop_num : 8; /*!< Specify the dropped frame number to repeat */ + u32 reserved2 : 8; +}; + +struct iav_h26x_sar { + u16 sar_width; /*!< Specify customized SAR width */ + u16 sar_height; /*!< Specify customized SAR height */ +}; +/*! @} */ /* End of iav-ioctl-general-stuct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_streamcfg_id { + /* Stream config for H264 & H265 & MJPEG (0x0000 ~ 0x0FFF) */ + IAV_STMCFG_FORMAT = 0x0000, /*!< 0x0000, Stream config for H264 & H265 & MJPEG (0x0000 ~ 0x0FFF) */ + IAV_STMCFG_FPS = 0x0001, /*!< 0x0001 */ + IAV_STMCFG_OFFSET = 0x0002, /*!< 0x0002 */ + IAV_STMCFG_CHROMA = 0x0003, /*!< 0x0003 */ + IAV_STMCFG_DUMMY_LATENCY = 0x0004, /*!< 0x0004 */ + IAV_STMCFG_CUSTOM_SEI = 0x0005, /*!< 0x0005 */ + IAV_STMCFG_NUM = 0x0006, /*!< 0x0006 */ + IAV_STMCFG_FIRST = IAV_STMCFG_FPS, /*!< IAV_STMCFG_FPS */ + IAV_STMCFG_LAST = IAV_STMCFG_NUM, /*!< IAV_STMCFG_NUM */ + + /* H264 config (0x1000 ~ 0x1FFF) */ + IAV_H264_CFG_GOP = 0x1000, /*!< 0x1000, H264 config (0x1000 ~ 0x1FFF) */ + IAV_H264_CFG_BITRATE = 0x1001, /*!< 0x1001 */ + IAV_H264_CFG_FORCE_IDR = 0x1002, /*!< 0x1002 */ + IAV_H264_CFG_QP_LIMIT = 0x1003, /*!< 0x1003 */ + IAV_H264_CFG_ENC_PARAM = 0x1004, /*!< 0x1004 */ + IAV_H264_CFG_QP_ROI = 0x1005, /*!< 0x1005 */ + IAV_H264_CFG_ZMV_THRESHOLD = 0x1006, /*!< 0x1006 */ + IAV_H264_CFG_FORCE_FAST_SEEK = 0x1007, /*!< 0x1007 */ + IAV_H264_CFG_FRAME_DROP = 0x1008, /*!< 0x1008 */ + IAV_H264_CFG_RC_STRATEGY = 0x1009, /*!< 0x1009 */ + IAV_H264_CFG_SLICE = 0x100A, /*!< 0x100A */ + IAV_H264_CFG_STATIS = 0x100B, /*!< 0x100B */ + IAV_H264_CFG_FORCE_PSKIP = 0x100C, /*!< 0x100C */ + IAV_H264_CFG_SAR = 0x100D, /*!< 0x100D */ + IAV_H264_CFG_WEIGHTED_PRED = 0x100E, /*!< 0x100E */ + IAV_H264_CFG_FAST_SEEK_INTERVAL = 0x100F, /*!< 0x100F */ + IAV_H264_CFG_NUM = 0x1010, /*!< 0x1010 */ + IAV_H264_CFG_FIRST = IAV_H264_CFG_GOP, /*!< IAV_H264_CFG_GOP */ + IAV_H264_CFG_LAST = IAV_H264_CFG_NUM, /*!< IAV_H264_CFG_NUM */ + + /* MJPEG config (0x2000 ~ 0x2FFF) */ + IAV_MJPEG_CFG_QUALITY = 0x2000, /*!< 0x2000, MJPEG config (0x2000 ~ 0x2FFF) */ + IAV_MJPEG_CFG_NUM = 0x2001, /*!< 0x2001 */ + IAV_MJPEG_CFG_FIRST = IAV_MJPEG_CFG_QUALITY, /*!< IAV_MJPEG_CFG_QUALITY */ + IAV_MJPEG_CFG_LAST = IAV_MJPEG_CFG_NUM, /*!< IAV_MJPEG_CFG_NUM */ + + /* H265 config (0x3000 ~ 0x3FFF) */ + IAV_H265_CFG_GOP = 0x3000, /*!< 0x3000, H265 config (0x3000 ~ 0x3FFF) */ + IAV_H265_CFG_BITRATE = 0x3001, /*!< 0x3001 */ + IAV_H265_CFG_FORCE_IDR = 0x3002, /*!< 0x3002 */ + IAV_H265_CFG_QP_LIMIT = 0x3003, /*!< 0x3003 */ + IAV_H265_CFG_ENC_PARAM = 0x3004, /*!< 0x3004 */ + IAV_H265_CFG_QP_ROI = 0x3005, /*!< 0x3005 */ + IAV_H265_CFG_ZMV_THRESHOLD = 0x3006, /*!< 0x3006 */ + IAV_H265_CFG_FORCE_FAST_SEEK = 0x3007, /*!< 0x3007 */ + IAV_H265_CFG_FRAME_DROP = 0x3008, /*!< 0x3008 */ + IAV_H265_CFG_RC_STRATEGY = 0x3009, /*!< 0x3009 */ + IAV_H265_CFG_SLICE = 0x300A, /*!< 0x300A */ + IAV_H265_CFG_MD_CAT_LUT = 0x300B, /*!< 0x300B */ + IAV_H265_CFG_FORCE_PSKIP = 0x300C, /*!< 0x300C */ + IAV_H265_CFG_SAR = 0x300D, /*!< 0x300D */ + IAV_H265_CFG_WEIGHTED_PRED = 0x300E, /*!< 0x300E */ + IAV_H265_CFG_FAST_SEEK_INTERVAL = 0x300F, /*!< 0x300F */ + IAV_H265_CFG_NUM = 0x3010, /*!< 0x3010 */ + IAV_H265_CFG_FIRST = IAV_H265_CFG_GOP, /*!< IAV_H265_CFG_GOP */ + IAV_H265_CFG_LAST = IAV_H265_CFG_NUM, /*!< IAV_H265_CFG_NUM */ +}; + +enum roi_cat_type { + ROI_CAT_MIN = 0, /*!< 0 */ + ROI_CAT_MAX = 7, /*!< 7 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_stream_cfg { + u32 id; /*!< Stream ID */ + enum iav_streamcfg_id cid; /*!< Stream configured ID, @sa iav_streamcfg_id */ + union { + struct iav_stream_format format; + struct iav_stream_fps fps; + struct iav_offset enc_offset; + enum iav_chroma_format chroma; + u32 stream_dummy_latency; /*!< Stream dummy latency */ + u32 mv_threshold; /*!< MV threshold for bitrate control */ + struct iav_custom_sei custom_sei; + + struct iav_h26x_gop h264_gop; + struct iav_bitrate h264_rc; + struct iav_rc_strategy h264_rc_strategy; + struct iav_qpmatrix h264_roi; + struct iav_h26x_enc_param h264_enc; + struct iav_h26x_slice h264_slice; + struct iav_h26x_pskip h264_pskip; + struct iav_h26x_drop_frame h264_drop_frame; + int h264_force_idr; /*!< Flag for force IDR */ + u32 h264_force_fast_seek; /*!< Flag for force fast seek frame insertion */ + u32 h264_fast_seek_interval; /*!< Flag for fast seek interval */ + u32 h264_statis; /*!< H.264 MV dump flag */ + struct iav_h26x_sar h264_sar; + struct iav_h26x_weighted_pred h264_wp; + + u32 mjpeg_quality; /*!< Quality value for MJPEG stream */ + + /* H265 shares same structure with H264 */ + struct iav_h26x_gop h265_gop; + struct iav_bitrate h265_rc; + struct iav_rc_strategy h265_rc_strategy; + struct iav_qpmatrix h265_roi; + struct iav_h26x_enc_param h265_enc; + struct iav_h26x_slice h265_slice; + struct iav_h26x_pskip h265_pskip; + struct iav_h26x_drop_frame h265_drop_frame; + int h265_force_idr; /*!< Flag for force IDR */ + u32 h265_force_fast_seek; /*!< Flag for force fast seek frame insertion */ + u32 h265_fast_seek_interval; /*< Flag for fast seek interval */ + u8 h265_md_cat_lut[MD_CAT_MAX_NUM]; /*!< H.265 MD category mapping look up table */ + struct iav_h26x_sar h265_sar; + struct iav_h26x_weighted_pred h265_wp; + } arg; /*!< The stream configuration items */ + u32 dsp_pts; /*!< The DSP PTS for the stream configurations */ +}; + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_h264_profile { + H264_PROFILE_MAIN = 1, /*!< 1 */ + H264_PROFILE_HIGH = 2, /*!< 2 */ + H264_PROFILE_NUM = 3, /*!< 3 */ + H264_PROFILE_FIRST = H264_PROFILE_MAIN, /*!< H264_PROFILE_MAIN */ + H264_PROFILE_LAST = H264_PROFILE_NUM, /*!< H264_PROFILE_NUM */ +}; + +enum iav_h264_au_type { + H264_NO_AUD_NO_SEI = 0, /*!< 0 */ + H264_AUD_BEFORE_SPS_WITH_SEI = 1, /*!< 1 */ + H264_AUD_AFTER_SPS_WITH_SEI = 2, /*!< 2 */ + H264_NO_AUD_WITH_SEI = 3, /*!< 3 */ + H264_AU_TYPE_NUM = 4, /*!< 4 */ +}; + +enum iav_h264_aqp_type { + H264_AQP_TYPE_DEFAULT = 0, /*!< 0, Default option in internal RC. */ + H264_AQP_TYPE_FRAME_QP = 1, /*!< 1, Frame QP for frame size decision. */ + H264_AQP_TYPE_MB_QP = 2, /*!< 2, MB QP for frame size decision. */ + H264_AQP_TYPE_NUM = 3, /*!< 3 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_pic_info { + u32 rate; + u32 scale; + u16 width; + u16 height; +}; + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_ltr_num_log2 { + IAV_LTR_NUM_LOG2_MIN = 1, /*!< 1 */ + IAV_LTR_NUM_LOG2_MAX = 8, /*!< 8 */ +}; + +enum iav_ltr_type { + IAV_LTR_TYPE_SINGLE = 1, /*!< 1 */ + IAV_LTR_TYPE_TWO = 2, /*!< 2 */ + IAV_LTR_TYPE_NUM = IAV_LTR_TYPE_TWO, /*!< IAV_LTR_TYPE_TWO */ +}; + +enum iav_two_ltr_mode { + IAV_TWO_LTR_FAST_SEEK = 0, /*!< 0 */ + IAV_TWO_LTR_PREV_PREV = 1, /*!< 1 */ + IAV_TWO_LTR_MODE_NUM = 2, /*!< 2 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_h26x_cfg { + u32 id; /*!< Stream ID */ + u32 gop_structure : 8; /*!< @sa iav_gop_model */ + u32 M : 8; /*!< Number of pictures between reference P pictures */ + u32 N : 16; /*!< Number of pictures between reference I pictures, should be no larger than 4095 */ + u32 idr_interval : 8; /*!< Indicate the number of GOP's after which an IDR picture should happen */ + u32 profile : 8; /*!< This field specifies the profile level. The default is the main profile for stream configuration. + 0: Baseline profile + 1: Main profile + 2: High profile */ + u32 au_type : 8; /*!< This field specifies the NAL unit structure. + 0: No AUD, no SEI header info + 1: Add AUD before SPS, PPS, with SEI in the end + 2: Add AUD after SPS, PPS, with SEI in the end + 3: No AUD, with SEI in the end. */ + u32 chroma_format : 8; /*!< Chroma format */ + u32 cpb_buf_idc : 8; /*!< CPB buffer size indicator. 0 indicates using a buffer size that matches the profile and level which are based on the encoding size. */ + u32 is_update_N_to_next_GOP : 1; /*!< Flag to update GOP length to next GOP */ + u32 reserved0 : 23; + u32 cpb_user_size; /*!< This field specifies the CPB buffer size */ + u32 en_panic_rc : 2; /*!< Flag for panic mode of RC */ + u32 cpb_cmp_idc : 2; /*!< Flag for CPB settings */ + u32 fast_rc_idc : 4; /*!< Flag for fast RC mode */ + u32 mv_threshold : 1; /*!< Motion vector threshold */ + u32 long_start_code : 1;/*!< Flag for long start code */ + u32 dblk_custom_flag : 1; /*!< Flag for dblk */ + u32 two_ltrs_mode : 1; /*!< 0: two long term + fast seek; 1: two long term + prev prev q */ + u32 ltrs_type: 2; /*!< Type of long term references. Default is 0. + 0: No long term ref frame + 1: 1 long term ref frame + 2: 2 long term ref frames. */ + u32 rserved0 : 2; + u32 log2_num_ltrp_per_gop : 8; /*!< Number of long-term reference picture in a GoP */ + u32 fast_seek_intvl : 8; /*!< The fast seek interval for long term frames */ + u16 user1_intra_bias; /*!< The intra bias for user class 1, range from 0 to 9 */ + u16 user1_direct_bias; /*!< The direct bias for user class 1, range from 0 to 9 */ + u16 user2_intra_bias; /*!< The intra bias for user class 2, range from 0 to 9 */ + u16 user2_direct_bias; /*!< The direct bias for user class 2, range from 0 to 9 */ + s32 deblocking_filter_alpha : 4; /*!< The deblocking filter range is -6 to 6 */ + s32 deblocking_filter_beta : 4; /*!< The deblocking filter range is -6 to 6 */ + u32 deblocking_filter_enable : 2;/*!< Flag for deblocking filter */ + u32 aqp_type : 2; /*!< AQP type for frame size decision, @sa iav_h264_aqp_type: + 0: Default option + 1: Frame QP for frame size decision + 2: MB QP for frame size decision */ + u32 wp_mode : 2; /*!< Weighted predict mode: + 0: Disable WP, + 1: WP for P frame, + 2: WP for B frame, + 3: WP for P&B frame */ + u32 reserved1 : 18; + struct iav_pic_info pic_info; /*!< Picture information for decoding (rate / scale) */ +}; + + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_gop_model{ + IAV_GOP_SIMPLE = 0, /*!< 0, simpe GOP (I & P frames), MPEG2 alike */ + IAV_GOP_ADVANCED = 1, /*!< 1, hierachical GOP */ + IAV_GOP_SVCT_2 = 2, /*!< 2, 2 level SVCT*/ + IAV_GOP_SVCT_3 = 3, /*!< 3, 3 level SVCT */ + IAV_GOP_SVCT_4 = 4, /*!< 4, 4 level SVCT */ + IAV_GOP_FAST_SEEK = 5, /*!< 5, fast seek GOP */ + IAV_GOP_2_REF = 6, /*!< 6, 2 ref GOP */ + IAV_GOP_FAST_SEEK_2_REF = 7, /*!< 7, 2 ref with fast seek GOP */ + IAV_GOP_NON_REF_P = 8, /*!< 8, all P refers from I. App can drop P anytime from the GOP. + This GOP enable fast reverse play. */ +}; + +enum iav_bitrate_control_params { + /* QP limit parameters */ + H264_AQP_MAX = 4, /*!< 4, QP limit parameters */ + H264_QP_MAX = 51, /*!< 51 */ + H264_QP_MIN = 0, /*!< 0 */ + H264_I_QP_REDUCE_MAX = 10, /*!< 10 */ + H264_I_QP_REDUCE_MIN = 1, /*!< 1 */ + H264_P_QP_REDUCE_MAX = 5, /*!< 5 */ + H264_P_QP_REDUCE_MIN = 1, /*!< 1 */ + H264_B_QP_REDUCE_MAX = 5, /*!< 5 */ + H264_B_QP_REDUCE_MIN = 0, /*!< 0 */ + H264_C_QP_REDUCE_MAX = 5, /*!< 5 */ + H264_C_QP_REDUCE_MIN = 0, /*!< 0 */ + H264_Q_QP_REDUCE_MAX = 10, /*!< 10 */ + H264_Q_QP_REDUCE_MIN = 1, /*!< 1 */ + /* skip frame flag */ + H264_WITHOUT_FRAME_DROP = 0, /*!< 0, skip frame flag */ + H264_WITH_FRAME_DROP = 6, /*!< 6 */ + H264_LOG_Q_NUM_MINUS_1_MAX = 4, /*!< 4 */ + H264_I_SIZE_KB_MAX = 8192, /*!< 8192 */ + /* svbr control */ + H264_SVBR_NESS_MIN = 1, /*!< 1, svbr control */ + H264_SVBR_NESS_MAX = 200, /*!< 200 */ + H264_SVBR_MULTI_MAX = 5, /*!< 5 */ + /* cbr stable br adjust */ + H264_CBR_STABLE_BR_ADJUST_MIN = 0, /*!< 0, cbr stable br adjust */ + H264_CBR_STABLE_BR_ADJUST_MAX = 10, /*!< 10 */ +}; + +enum { + /* bitrate control */ + IAV_BRC_CBR = 1, /*!< 1 */ + IAV_BRC_PCBR = 2, /*!< 2 */ + IAV_BRC_VBR = 3, /*!< 3 */ + IAV_BRC_SCBR = 4, /*!< 4, smart CBR */ + IAV_BRC_SVBR = 5, /*!< 5 */ +}; + +enum { + WP_FOR_NONE = 0, /*!< 0 */ + WP_FOR_P = 1, /*!< 1 */ + WP_FOR_B = 2, /*!< 2 */ + WP_FOR_PB = 3, /*!< 3 */ + WP_MODE_NUM, /*!< 4 */ + WP_MODE_FIRST = WP_FOR_NONE, /*!< WP_FOR_NONE */ + WP_MODE_LAST = WP_MODE_NUM, /*!< WP_MODE_NUM */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_mjpeg_cfg { + u32 id; /*!< Stream ID */ + u32 chroma_format : 8; /*!< Chroma format, @sa iav_chroma_format */ + u32 quality : 8; /*!< 1 ~ 100, 100 is best quality. The bigger quality value, + the larger frame size it is (especially for high mega resolution). */ + u32 reserved1 : 16; + u32 restart_interval; /*!< restart interval MB for mjpeg. 0 : handle in ucode. >0 : user specified. */ +}; + +struct iav_overlay_area { + u16 enable : 1; /*!< 0: Disable; 1: Enable */ + u16 reserved1 : 15; + u16 start_x; /*!< Offset x of the overlay area */ + u16 start_y; /*!< Offset y of the overlay area */ + u16 width; /*!< Width of the overlay area */ + u16 pitch; /*!< Pitch of the overlay area */ + u16 height; /*!< Height of the overlay area */ + u32 total_size; /*!< Total byte size of the overlay area */ + unsigned long clut_addr_offset; /*!< CLUT address for the overlay area */ + unsigned long data_addr_offset; /*!< Overlay data buffer (without CLUT) */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +#define MAX_NUM_OVERLAY_AREA (10) + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_overlay_insert { + u32 id; /*!< Stream ID */ + u32 enable: 1; /*!< Flag to enable / disable overlay insertion */ + u32 osd_insert_always: 1; /*!< Flag to insert overlay all the time no matter the stream encoding is started or not. */ + u32 reserved : 30; + struct iav_overlay_area area[MAX_NUM_OVERLAY_AREA]; /*!< Parameters for each overlay area */ +}; + +struct iav_fastosd_string_area { + u8 enable; /*!< Enable flag */ + u8 string_length;/*!< String length */ + u16 string_output_pitch; /*!< Pitch of string output */ + u16 offset_x; /*!< X offset */ + u16 offset_y; /*!< Y offset */ + /* if each char's width is const, + * overall_string_width = num_of_char_in_string * width_of_char_font + */ + u32 overall_string_width; /*!< Total width, if each char's width is const, + overall_string_width = num_of_char_in_string * width_of_char_font */ + u32 reserved; + + unsigned long string_output_offset; /*!< Memory to store the output overlay string content, which is generated by DSP. */ + unsigned long string_offset; /*!< DSP OVERLAY STRING START */ + unsigned long clut_offset; /*!< Memory for overlay CLUT content. */ +}; + +struct iav_fastosd_insert { + u8 enable; /*!< Enable flag */ + u8 id; /*!< Stream ID */ + u8 string_num_region; /*!< Total FastOSD number */ + u8 reserved; + + u16 font_map_pitch; /*!< Font map pitch */ + u16 font_map_height; /*!< Font map height */ + unsigned long font_map_offset; /*!< Font map offset */ + unsigned long font_index_offset; /*!< Font index offset */ + + struct iav_fastosd_string_area string_area[MAX_NUM_OVERLAY_AREA]; /*!< Parameters for each FastOSD area */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum iav_warp_params { + MAX_NUM_WARP_AREAS = 12, /*!< 12, Maximum warp area number from DSP point of view. */ + MAX_NUM_WARP_VIEW = 12, /*!< 12, Maximum warp view number from user point of view. */ + + MAX_GRID_WIDTH = 128, /*!< 128, Maximum grid width (column) for warp vector table. */ + MAX_GRID_HEIGHT = 96, /*!< 96, Maximum grid height (row) for warp vector table. */ + MAX_WARP_TABLE_SIZE = (MAX_GRID_WIDTH * MAX_GRID_HEIGHT), /*!< MAX_GRID_WIDTH * MAX_GRID_HEIGHT */ + MAX_WARP_VECT_PART_SIZE = (MAX_NUM_WARP_AREAS * \ + MAX_WARP_TABLE_SIZE * sizeof(s16) * 2), /*!< MAX_NUM_WARP_AREAS * MAX_WARP_TABLE_SIZE * sizeof(s16) * 2 */ + MAX_GRID_WIDTH_LDC = MAX_GRID_WIDTH, /*!< MAX_GRID_WIDTH */ + MAX_WARP_TABLE_SIZE_LDC = (MAX_GRID_WIDTH_LDC * MAX_GRID_HEIGHT), /*!< MAX_GRID_WIDTH_LDC * MAX_GRID_HEIGHT */ + + GRID_SPACING_PIXEL_8 = 0, /*!< 0 */ + GRID_SPACING_PIXEL_16 = 1, /*!< 1 */ + GRID_SPACING_PIXEL_32 = 2, /*!< 2 */ + GRID_SPACING_PIXEL_64 = 3, /*!< 3 */ + GRID_SPACING_PIXEL_128 = 4, /*!< 4 */ + GRID_SPACING_PIXEL_256 = 5, /*!< 5 */ + GRID_SPACING_PIXEL_512 = 6, /*!< 6 */ + + WARP_AREA_H_OFFSET = 0, /*!< 0 */ + WARP_AREA_V_OFFSET = 1, /*!< 1 */ + WARP_AREA_VECTOR_NUM = 2, /*!< 2 */ + + WARP_AREA_CHANGE = 0, /*!< 0, This is to change the selected warp area configuration on the fly. */ + WARP_AREA_UPDATE = 1, /*!< 1, This is to update all warp areas configuration at the same time. */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_warp_map { + u8 enable; /*!< Flag to enable / disable warp vector table. */ + u8 output_grid_col; /*!< Grid columns */ + u8 output_grid_row; /*!< Grid rows */ + u8 h_spacing : 4; /*!< H-spacing */ + u8 v_spacing : 4; /*!< V-spacing */ + u32 reserved; + unsigned long data_addr_offset; /*!< Warp table DRAM offset */ +}; + +struct iav_warp_area { + u8 enable; /*!< Area enable flag */ + u8 rotate_flip; /*!< rotate and flip flag */ + u8 output_to_intermediate_buf : 1; /*!< This flag is ONLY for the 1st pass of warp pipeline two pass mode. */ + u8 input_from_intermediate_buf : 1; /*!< This flag is ONLY for the 2nd pass of warp pipeline two pass mode. */ + u8 reserved1 : 6; + u8 reserved2; + struct iav_rect input; /*!< Warp area input window */ + struct iav_rect output; /*!< Warp area output window */ + struct iav_warp_map h_map; /*!< h-warp map */ + struct iav_warp_map v_map; /*!< v-warp map */ +}; + +struct iav_warp_main { + u8 keep_dptz[IAV_SRCBUF_NUM]; /*!< Keep DPTZ attribute for each source buffer output */ + struct iav_warp_area area[MAX_NUM_WARP_AREAS]; /*!< Warp area configuration */ + u8 area_num_per_view[MAX_NUM_WARP_VIEW]; /*!< Specify the number of warp areas for each warp view. */ +}; + +struct iav_warp_dptz { + u16 buf_id; /*!< Source buffer ID */ + u16 updated_area_map; /*!< The bit map of areas to be updated. */ + struct iav_rect input[MAX_NUM_WARP_AREAS]; /*!< Input window of each updated area. */ + struct iav_rect output[MAX_NUM_WARP_AREAS]; /*!< Output window of each updated area. */ +}; + +struct iav_pyramid_roi { + u32 chan_id : 8; /*!< Channel ID */ + u32 layers_map : 6; /*!< Pyramid layer bit map */ + u32 reserved0 : 18; + struct iav_rect crop_win[IAV_MAX_PYRAMID_LAYERS]; /*!< crop window */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum iav_warp_ctrl_id { + IAV_WARP_CTRL_MAIN = 0, /*!< 0, This is to configure multi-region warp area parameters for post main. */ + IAV_WARP_CTRL_DPTZ = 1, /*!< 1, This is to configure multi-region warp DPTZ from post main to sub source buffers. */ + IAV_WARP_CTRL_ENCOFS = 2, /*!< 2, This is to configure stream encode offset synchronized with warp DPTZ effect. */ + IAV_WARP_CTRL_NUM = 3, /*!< 3 */ + IAV_WARP_CTRL_FIRST = IAV_WARP_CTRL_MAIN, /*!< IAV_WARP_CTRL_MAIN */ + IAV_WARP_CTRL_LAST = IAV_WARP_CTRL_NUM, /*!< IAV_WARP_CTRL_NUM */ +}; + +/*! @addtogroup iav-ioctl-general-struct */ +struct iav_warp_ctrl { + enum iav_warp_ctrl_id cid; /*!< Config class ID, @sa iav_warp_ctrl_id */ + u16 channel_id; /*!< Channel ID */ + u16 warp_area_behavior : 2; /*!< Specify warp are behavior. 0 is to change the selected warp area configuration on the fly, + 1 is to update all warp areas configuration at the same time. */ + u16 reserved : 14; + union { + struct iav_warp_main main; + struct iav_warp_dptz dptz; + } arg; /*!< Warp configuration */ +}; + +/*! @addtogroup iav-ioctl-general-helper */ +enum iav_video_proc_id { + IAV_VIDEO_PROC_DPTZ = 0x00, /*!< 0x00, This is to configure DPTZ parameters on the fly. */ + IAV_VIDEO_PROC_MASK = 0x01, /*!< 0x01, This is to configure privacy mask on the fly. */ + IAV_VIDEO_PROC_CANVAS_ORDER = 0x02, /*!< 0x02, This is to configure channel order in one canvas on the fly. */ + IAV_VIDEO_PROC_MULTI_BLEND = 0x03, /*!< 0x03, This is to configure multi-channel blend overlap area parameters on the fly. */ + IAV_VIDEO_PROC_BLEND_DPTZ = 0x04, /*!< 0x04, This is to configure multi-channel blend DPTZ parameters on the fly. */ + IAV_VIDEO_PROC_PYRAMID_ROI = 0x05, /*!< 0x05, This is to configure pyramid ROI parameters on the fly. */ + IAV_VIDEO_PROC_CANVAS_FPS = 0x06, /*!< 0x06, This is to configure canvas frame rate on the fly. */ + IAV_VIDEO_PROC_NUM = 0x07, /*!< 0x07 */ + IAV_VIDEO_PROC_FIRST = IAV_VIDEO_PROC_DPTZ, /*!< IAV_VIDEO_PROC_DPTZ */ + IAV_VIDEO_PROC_LAST = IAV_VIDEO_PROC_NUM /*!< IAV_VIDEO_PROC_NUM */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_privacy_mask { + u8 channel_id; /*!< Channel ID */ + u8 enable; /*!< 0: disable, 1: enable */ + u8 y; /*!< y of the mask color */ + u8 u; /*!< u of the mask color */ + u8 v; /*!< v of the mask color */ + u8 reserved0; + u16 buf_pitch; /*!< Buffer pitch (in byte unit) is aligned to 32 bytes. The unit depends on the privacy mask type. */ + u16 buf_height; /*!< Buffer height is in pixel unit and equal to main buffer height. */ + u16 reserved1[3]; + unsigned long data_addr_offset; /*!< Start address of privacy mask data */ +}; + +struct iav_overlap_area { + u16 width; /*!< Width of blend overlap area. */ + u16 height; /*!< Height of blend overlap area. */ + u16 pitch; /*!< Pitch of blend overlap area. It must be alighed to 64 bytes. */ + u16 update_alpha_enable : 1; /*!< This is a flag to enable / disable updating alpha table. */ + u16 reserved : 15; + u8 chan_id[IAV_BLEND_NUM]; /*!< Channel ID of overlapped areas */ + unsigned long alpha_addr_offset[IAV_BLEND_NUM]; /*!< Offset of Alpha table memory */ +}; + +struct iav_blend_overlap { + u8 active_overlap_num; /*!< Active blend overlap number. @sa IAV_BLEND_OVERLAP_AREA_MAX */ + u8 reserved[3]; + struct iav_overlap_area mc_overlap[IAV_BLEND_OVERLAP_AREA_MAX]; /*!< Overlap area configuration */ +}; + +struct iav_blend_dptz_info { + u32 enable : 1; /*!< Blend DPTZ enable flag */ + u32 reserved : 31; + struct iav_rect input; /*!< Blend DPTZ input window */ + struct iav_rect output; /*!< Blend DPTZ output window */ +}; + +struct iav_blend_dptz { + struct iav_blend_dptz_info dptz[IAV_SRCBUF_NUM]; /*!< Blend DPTZ configuration */ +}; + +struct iav_video_proc { + enum iav_video_proc_id cid; /*!< Configuration item ID, @sa iav_video_proc_id */ + union { + struct iav_dptz dptz; + struct iav_privacy_mask mask; + struct iav_canvas_order canvas_order; + struct iav_blend_overlap blend_overlap; + struct iav_blend_dptz blend_dptz; + struct iav_pyramid_roi pyramid_roi; + struct iav_canvas_fps canvas_fps; + } arg; /*!< Configuration items */ +}; + +struct iav_apply_flag { + int apply; + u32 param; +}; + +struct iav_efm_get_pool_info { + u32 stream_id; /*!< EFM stream id*/ + u32 yuv_buf_num; /*!< EFM YUV buffer number */ + u32 yuv_pitch; /*!< YUV pitch */ + u32 me_buf_num; /*!< EFM ME buffer number */ + u32 me1_pitch; /*!< ME1 pitch */ + u32 me0_pitch; /*!< ME0 pitch */ + struct iav_window yuv_size; /*!< YUV size */ + struct iav_window me1_size; /*!< ME1 size */ + struct iav_window me0_size; /*!< ME0 size */ + u32 chroma_format; /*!< Chroma_format: 0: Mono; 1: YUV420; 2: YUV422; 3: YUV444. */ +}; + +struct iav_efm_request_frame { + u32 stream_id; /*!< EFM stream id*/ + u32 frame_idx; /*!< EFM frame index */ + unsigned long yuv_luma_offset; /*!< YUV Luma data offset */ + unsigned long yuv_chroma_offset;/*!< YUV Chromatic data offset */ + unsigned long me1_offset; /*!< ME1 data offset */ + unsigned long me0_offset; /*!< ME0 data offset */ +}; + +struct iav_efm_handshake_frame { + u32 stream_id; /*!< EFM stream ID */ + u32 frame_idx; /*!< EFM frame index */ + u32 frame_pts; /*!< EFM frame PTS */ + u8 is_last_frame; /*!< Flag for last_frame */ + u8 use_hw_pts; /*!< HW PTS, only apply to real time's case */ + u8 reserved[2]; +}; + +struct iav_custom_sei_request_buf { + u32 frame_idx; /*!< customized SEI buffer frame index */ + u32 offset; /*!< customized SEI buffer offset */ + u32 size; /*!< customized SEI buffer size */ +}; + +struct iav_raw_enc_setup { + u32 vinc_id; /*!< VIN Control ID */ + u32 raw_frame_size; /*!< RAW data size */ + u32 raw_hdec_size; /*!< HDEC data size */ + u32 preblend_size; /*!< Preblend data size */ + u32 pitch : 16; /*!< RAW data pitch */ + u32 raw_hdec_dpitch : 16; /*!< HDEC data pitch */ + u32 preblend_dpitch : 16; /*!< Pre-blend data pitch */ + u32 raw_frame_num : 8; /*!< RAW frame number */ + u32 reserved : 8; + u64 frame_pts; /*!< Frame PTS */ + unsigned long raw_daddr_offset; /*!< RAW data DRAM offset */ + unsigned long raw_hdec_daddr_offset; /*!< HDEC data DRAM offset */ + unsigned long preblend_daddr_offset; /*!< Pre-blend data DRAM offset */ +}; + +struct iav_apply_frame_sync { + u32 dsp_pts; /*!< Specify the PTS of synchronized frame to apply frame sync parameters. */ + u32 stream_updated_map : 16; /*!< The stream id bit map to update sync parameters. */ + u32 force_update : 1; /*!< Force to update sync parameters if the frame PTS is not found from the internal queue. */ + u32 reserved : 15; + u64 stream_frame_num[IAV_STREAM_MAX_NUM_ALL]; /*!< The frame number to apply stream sync parameters. */ +}; + +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_vcap_state { + IAV_VCAP_STATE_ACTIVE = 0, /*!< 0 */ + IAV_VCAP_STATE_IDLE = 1, /*!< 1 */ +}; + +enum iav_vcap_cfg_id { + IAV_VCAP_CFG_STATE = 0x0000, /*!< 0x0000 */ + IAV_VCAP_REPEAT_FRAME = 0x0001, /*!< 0x0001 */ + IAV_VCAP_CFG_NUM, /*!< 0x0002 */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_vcap_state_cfg { + u32 vinc_map; /*!< VIN control ID map */ + enum iav_vcap_state state[VIN_CONTROLLER_NUM]; /*!< vcap states */ +}; + +struct iav_vcap_cfg { + enum iav_vcap_cfg_id cid; /*!< VCAP configuration ID */ + union { + struct iav_vcap_state_cfg state_cfg; + u16 vinc_id; + } arg; +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper */ +enum vin_idsp_apply_map { + IAV_APPLY_NONE = 0, /*!< 0 */ + IAV_APPLY_VIN_CFG = (1 << 0), /*!< 1 << 0 */ + IAV_APPLY_IDSP_CFG = (1 << 1), /*!< 1 << 1 */ + IAV_APPLY_ALL_CFG = (IAV_APPLY_VIN_CFG | IAV_APPLY_IDSP_CFG), /*!< IAV_APPLY_VIN_CFG | IAV_APPLY_IDSP_CFG */ +}; + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_vin_idsp_config { + struct vindev_wdr_gp_info vin_cfg; + struct idsp_config_s idsp_cfg; + enum vin_idsp_apply_map apply_map; + u8 resend_all_cfg_done[IMG_MAX_VIN_CHANNEL_NUM]; +}; + +struct iav_vin_compand_config { + u8 vsrc_id; + u8 comp_en; + u8 decomp_en; + u8 reserved[1]; + u16 comp_lut[COMP_LUT_ENTRY_NUM]; + u16 reserved1; + u32 decomp_lut[DECOMP_LUT_ENTRY_NUM]; +}; + +struct iav_vin_delay_info { + struct vindev_sht_agc_seq sht_agc[IMG_MAX_VIN_CHANNEL_NUM]; +}; + +struct iav_vin_idsp_delay_info { + struct iav_vin_delay_info vin; + struct idsp_delay_info_s idsp; +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + +/*! @addtogroup iav-ioctl-general-helper + * @{ + */ +enum iav_nalu_type_h264 { + NT_NON_IDR = 1, /*!< 1 */ + NT_IDR = 5, /*!< 5 */ + NT_SEI = 6, /*!< 6 */ + NT_SPS = 7, /*!< 7 */ + NT_PPS = 8, /*!< 8 */ + NT_AUD = 9, /*!< 9 */ +}; + +enum iav_nalu_type_h265 { + TRAIL_N = 0, /*!< 0 */ + TRAIL_R = 1, /*!< 1 */ + TSA_N = 2, /*!< 2 */ + TSA_R = 3, /*!< 3 */ + STSA_N = 4, /*!< 4 */ + STSA_R = 5, /*!< 5 */ + IDR_W_RADL = 19, /*!< 19 */ + IDR_N_LP = 20, /*!< 20 */ +}; + +enum iav_debugcfg_module { + IAV_DEBUG_IAV = (1 << 0), /*!< 1 << 0 */ + IAV_DEBUG_DSP = (1 << 1), /*!< 1 << 1 */ + IAV_DEBUG_VIN = (1 << 2), /*!< 1 << 2 */ + IAV_DEBUG_VOUT = (1 << 3), /*!< 1 << 3 */ + IAV_DEBUG_AAA = (1 << 4), /*!< 1 << 4 */ +}; + +enum iav_debugcfg_id { + IAV_DEBUGCFG_CHECK = 0x0000, /*!< 0x0000 */ + IAV_DEBUGCFG_MODULE = 0x0001, /*!< 0x0001 */ + IAV_DEBUGCFG_AUDIT_INT = 0x0002, /*!< 0x0002 */ + IAV_DEBUGCFG_AUDIT_IOCTL = 0x0003, /*!< 0x0003 */ + IAV_DEBUGCFG_CHECK_SYS_PERF = 0x0004, /*!< 0x0004 */ + IAV_DEBUGCFG_AUDIT_YUV_DELAY = 0x0005, /*!< 0x0005 */ + IAV_DEBUGCFG_NUM = 0x0006, /*!< 0x0006 */ + IAV_DEBUGCFG_FIRST = IAV_DEBUGCFG_CHECK, /*!< IAV_DEBUGCFG_CHECK */ + IAV_DEBUGCFG_LAST = IAV_DEBUGCFG_NUM, /*!< IAV_DEBUGCFG_NUM */ + + IAV_DEBUGCFG_CHECK_ALL = IAV_DEBUGCFG_CHECK, /*!< IAV_DEBUGCFG_CHECK */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + +/*! @addtogroup iav-ioctl-general-struct + * @{ + */ +struct iav_debug_module { + u8 enable; + u8 reserved[3]; + u32 flags; + u32 args[4]; +}; + +struct iav_debug_audit { + u32 id; + u32 enable : 1; + u32 reserved : 31; + u64 cnt; + u64 sum; + u32 max; + u32 min; +}; + +struct iav_debug_cfg { + u32 id; /*!< Not currently supported */ + enum iav_debugcfg_id cid; /*!< Debug configuration item ID */ + union { + u32 enable; /*!< If IAV, there is no need to check if it is enabled or not */ + struct iav_debug_module module; /*!< Custom debug module configuration */ + struct iav_debug_audit audit; /*!< IAV Audit debugging configuration */ + } arg; /*!< IAV debug configuration */ +}; +/*! @} */ /* End of iav-ioctl-general-struct */ + + +/*! + * @addtogroup iav-ioctl-dec-helper + * @{ + */ +#define DIAV_MAX_DECODER_NUMBER 8 +#define DIAV_MAX_DECODE_VOUT_NUMBER 2 + +#define DIAV_MAX_INTRA_DECODE_CMD_NUMBER 4 +#define DIAV_MAX_INTRA_FB_NUMBER 4 +#define DIAV_MAX_INTRA_YUV2YUV_DST_FB_NUMBER 3 + +enum { + IAV_DECODER_TYPE_INVALID = 0x00, /*!< 0x00 */ + IAV_DECODER_TYPE_INTRA = 0x02, /*!< 0x02 */ + IAV_DECODER_TYPE_H264 = 0x03, /*!< 0x03 */ + IAV_DECODER_TYPE_H265 = 0x04, /*!< 0x04 */ + + IAV_DECODER_TYPE_MJPEG = 0x06, /*!< 0x06 */ +}; + +enum { + IAV_TRICK_PLAY_PAUSE = 0, /*!< 0 */ + IAV_TRICK_PLAY_RESUME = 1, /*!< 1 */ + IAV_TRICK_PLAY_STEP = 2, /*!< 2 */ +}; + +enum { + IAV_PB_DIRECTION_FW = 0, /*!< 0 */ + IAV_PB_DIRECTION_BW = 1, /*!< 1 */ +}; + +enum { + IAV_PB_SCAN_MODE_ALL_FRAMES = 0, /*!< 0 */ + IAV_PB_SCAN_MODE_I_ONLY = 1, /*!< 1 */ +}; + +enum { + IAV_DSP_BUFFER_PIX_FMT_420 = 1, /*!< 1 */ + IAV_DSP_BUFFER_PIX_FMT_422 = 2, /*!< 2 */ +}; +/*! @} */ /* End of iav-ioctl-dec-helper */ + +/*! @addtogroup iav-ioctl-dec-struct + * @{ + */ +struct iav_decode_vout_config { + u8 vout_id; /*!< VOUT ID */ + u8 enable; /*!< VOUT is enable or not */ + u8 flip; /*!< VOUT is flip or not */ + u8 rotate; /*!< VOUT is rotate or not */ + + u16 target_win_offset_x; /*!< Display window offset x */ + u16 target_win_offset_y; /*!< Display window offset y */ + + u16 target_win_width; /*!< Display window width */ + u16 target_win_height; /*!< Display window height */ + + u32 zoom_factor_x; /*!< Zoom factor x */ + u32 zoom_factor_y; /*!< Zoom factor y */ + + u32 vout_mode; /*!< VOUT mode */ + u32 reserved; +}; + +struct iav_decode_mode_config { + u8 b_support_ff_fb_bw; /*!< Playback will support fast FW/BW. Please note that this can need more DRAM usage in DSP if enabled. */ + u8 debug_max_frame_per_interrupt; /*!< Debug option, please ignore, fill 0. */ + u8 debug_use_dproc; /*!< Debug option, please ignore, fill 0. */ + u8 num_decoder; /*!< Number of decoder. */ + + u32 max_vout0_width; /*!< Maximum LCD' width (for DSP's DRAM allocation) */ + u32 max_vout0_height; /*!< Maximum LCD' height (for DSP's DRAM allocation) */ + + u32 max_vout1_width; /*!< Maximum HDMI' width (for DSP's DRAM allocation) */ + u32 max_vout1_height; /*!< Maximum HDMI' height (for DSP's DRAM allocation) */ + + u16 max_n_to_m_ratio; /*!< Maximum GOP size (for DSP DRAM allocation), If FW/BW are not enabled, can set it to 0. */ + u8 b_support_all_frame_backward; /*!< Output: Support all frames backward or not. */ + u8 num_vout; /*!< Number of VOUT */ + + u8 decoder_type[DIAV_MAX_DECODER_NUMBER]; /*!< Decoder type */ + u8 enable_vout[DIAV_MAX_DECODER_NUMBER]; /*!< Enable / Disable VOUT for each decoder */ + u32 max_frm_width[DIAV_MAX_DECODER_NUMBER]; /*!< Maximum Video Width for each decoder */ + u32 max_frm_height[DIAV_MAX_DECODER_NUMBER]; /*!< Maximum Video Height for each decoder */ + struct iav_pyramid_cfg pyramid[DIAV_MAX_DECODER_NUMBER]; /*!< Pyramid buffer configuration for each decoder */ +}; + +struct iav_decoder_info { + u8 decoder_id; /*!< Decoder instance ID */ + u8 decoder_type;/*!< Decoder type, see IAV_DECODER_TYPE */ + u8 num_vout; /*!< Number of VOUT */ + u8 setup_done; /*!< Ignore it */ + + u32 width; /*!< Video width */ + u32 height; /*!< Video height */ + + u32 bsb_size; /*!< Size of bitstream-buffer */ + unsigned long bsb_start_offset; /*!< Start offset of bitstream-buffer */ + + struct iav_decode_vout_config vout_configs[DIAV_MAX_DECODE_VOUT_NUMBER]; /*!< VOUT configuration */ +}; + +struct iav_decode_video { + u8 decoder_id; /*!< Decoder ID */ + u8 num_frames; /*!< Number of frames in bitstream */ + u8 reserved[2]; + + u32 first_frame_display; /*!< Specify the PTS of first frame that will be displayed. The former frames will be dropped. */ + + unsigned long start_ptr_offset; /*!< Video data's start offset in bitstream buffer */ + unsigned long end_ptr_offset; /*!< Video data's end offset in bitstream buffer */ +}; + +struct iav_decode_jpeg { + u8 decoder_id; /*!< Decoder ID */ + u8 reserved[3]; + u32 size; /*!< Size of JPEG data */ + unsigned long start_offset; /*!< JPEG data start offset in bitstream buffer */ +}; + +struct iav_decode_bsb { + u8 decoder_id; /*!< Decoder ID */ + u8 reserved[7]; + + unsigned long start_offset; /*!< Request free zoom's start offset */ + u32 room; /*!< Request free zoom's size, minus 256 byte for avoid read_offset == write_offset*/ + + //read only + u32 free_room; /*!< DSP's free zoom (read only) */ + unsigned long dsp_read_offset; /*!< DSP's read offset (read only) */ +}; + +struct iav_decode_stop { + u8 decoder_id; /*!< Decoder ID */ + u8 stop_flag; /*!< Stop flag: 0: End the playback + 1: Keep showing last frame, will continue playback when feeding new data */ + u8 reserved[6]; +}; + +struct iav_decode_trick_play { + u8 decoder_id; /*!< Decoder ID */ + u8 trick_play; /*!< Trick play type, see IAV_TRICK_PLAY */ + u8 reserved[6]; +}; + +struct iav_decode_speed { + u8 decoder_id; /*!< Decoder ID */ + u8 reserved[3]; + + u8 direction; /*!< See IAV_PB_DIRECTION, 0: forward, 1: backward*/ + u8 scan_mode; /*!< See IAV_PB_SCAN_MODE */ + u16 speed; /*!< Playback speed, 8.8 fix point format */ +}; + +struct iav_decode_wait_eos { + u8 decoder_id; /*!< Decoder ID */ + u8 timeout_ticks; /*!< time out ticks, 0: No timeout */ + u8 reserved[6]; +}; + +struct iav_intraplay_frame_buffer { + u8 buffer_id; + u8 ch_fmt; + + u16 buf_pitch; + + u16 buf_width; + u16 buf_height; + + unsigned long lu_buf_offset; + unsigned long ch_buf_offset; + + u16 img_width; + u16 img_height; + u16 img_offset_x; + u16 img_offset_y; + + u32 buffer_size; + u32 reserved; +}; + +struct iav_intraplay_decode_bitstream { + u32 bits_fifo_start; + u32 bits_fifo_end; +}; + +struct iav_intraplay_display_desc { + u8 vout_id; + u8 vid_win_update; + u8 vid_win_rotate; + u8 vid_flip; + u8 reserved[4]; + + u16 vid_win_width; + u16 vid_win_height; + u16 vid_win_offset_x; + u16 vid_win_offset_y; +}; + +struct iav_intraplay_reset_buffers { + u8 decoder_id; + u8 max_num; + u8 reserved[6]; +}; + +struct iav_intraplay_decode { + u8 decoder_id; + u8 num; + u8 decode_type; + u8 reserved[5]; + + struct iav_intraplay_decode_bitstream bitstreams[DIAV_MAX_INTRA_DECODE_CMD_NUMBER]; + struct iav_intraplay_frame_buffer buffers[DIAV_MAX_INTRA_DECODE_CMD_NUMBER]; +}; + +struct iav_intraplay_yuv2yuv { + u8 decoder_id; + u8 num; + u8 rotate; + u8 flip; + u8 luma_gain; + u8 reserved[3]; + + struct iav_intraplay_frame_buffer src_buf; + struct iav_intraplay_frame_buffer dst_buf[DIAV_MAX_INTRA_YUV2YUV_DST_FB_NUMBER]; +}; + +struct iav_intraplay_display { + u8 decoder_id; + u8 num; + u8 reserved[6]; + + struct iav_intraplay_frame_buffer buffers[DIAV_MAX_INTRA_DECODE_CMD_NUMBER]; + struct iav_intraplay_display_desc desc[DIAV_MAX_INTRA_DECODE_CMD_NUMBER]; +}; + +struct iav_decode_status { + u8 decoder_id; /*!< Decoder ID */ + u8 is_started; /*!< Decoder is started */ + u8 is_send_stop_cmd; /*!< Decoder has been sent stop command */ + u8 reserved[5]; + + u32 last_pts; /*!< Last showing frame's pts */ + + u32 decode_state; /*!< DSP decode status */ + u32 error_status; /*!< DSP decode error status */ + u32 total_error_count; /*!< Total DSP met errors */ + u32 decoded_pic_number; /*!< Total decoded picture number */ + + //bit stream buffer + u32 room; /*!< Free zoom left in bitstream buffer, + minus 256 byte for avoid read_offset == write_offset */ + unsigned long write_offset; /*!< ARM write offset, in bitstream buffer */ + unsigned long dsp_read_offset; /*!< DSP read offset, in bitstream buffer */ + u32 free_room; /*!< DSP reported free zoom */ + + //debug + u32 irq_count; /*!< IRQ count. Debug only. */ + unsigned long yuv422_y_addr; /*!< Luma address of display frame */ + unsigned long yuv422_uv_addr; /*!< Chroma address of display frame */ +}; +/*! @} */ /* End of iav-ioctl-dec-struct */ + +/*! + * @addtogroup iav-ioctl-general-helper + * @{ + */ + + /*! @macros IAVENCIOC_MAGIC + * @brief IAVENCIOC_MAGIC. + */ +#define IAVENCIOC_MAGIC 'V' + +/*! @macros IAVENC_IO(nr) + * @brief ioctl none of (nr). + */ +#define IAVENC_IO(nr) _IO(IAVENCIOC_MAGIC, nr) + +/*! @macros IAVENC_IOR(nr) + * @brief ioctl read of (nr). + */ +#define IAVENC_IOR(nr, size) _IOR(IAVENCIOC_MAGIC, nr, size) + +/*! @macros IAVENC_IOW(nr) + * @brief ioctl write of (nr). + */ +#define IAVENC_IOW(nr, size) _IOW(IAVENCIOC_MAGIC, nr, size) + +/*! @macros IAVENC_IOWR(nr) + * @brief ioctl read write of (nr). + */ +#define IAVENC_IOWR(nr, size) _IOWR(IAVENCIOC_MAGIC, nr, size) + +/*! @enum IAV_ENC_IOC + * @brief IAV_ENC_IOC Enumerations + */ +enum IAV_ENC_IOC { + + IOC_STATE = 0x00, /*!< 0x00, For DSP & Driver (0x00 ~ 0x0F) */ + IOC_CHIP_ID = 0x01, /*!< 0x01 */ + IOC_DSP_LOG = 0x02, /*!< 0x02 */ + IOC_DSP_INFO = 0x03, /*!< 0x03 */ + IOC_DSP_HASH = 0x04, /*!< 0x04 */ + IOC_DSP_VP_CFG = 0x05, /*!< 0x05 */ + IOC_QUERY_INFO = 0x06, /*!< 0x06 */ + IOC_QUERY_ENC_MODE_CAP = 0x07, /*!< 0x07 */ + IOC_QUERY_ENC_BUF_CAP = 0x08, /*!< 0x08 */ + IOC_DSP_AUTH = 0x09, /*!< 0x09 */ + + IOC_ENTER_IDLE = 0x10, /*!< 0x10, For system (0x10 ~ 0x2F) */ + IOC_ENABLE_PREVIEW = 0x11, /*!< 0x11 */ + IOC_START_ENCODE = 0x12, /*!< 0x12 */ + IOC_STOP_ENCODE = 0x13, /*!< 0x13 */ + IOC_ABORT_ENCODE = 0x14, /*!< 0x14 */ + IOC_SYSTEM_RESOURCE = 0x15, /*!< 0x15 */ + IOC_GDMA_COPY = 0x16, /*!< 0x16 */ + IOC_QUERY_DESC = 0x17, /*!< 0x17 */ + IOC_QUERY_MEMBLOCK = 0x18, /*!< 0x18 */ + IOC_EFM_PROC = 0x19, /*!< 0x19 */ + IOC_RAW_ENC = 0x1A, /*!< 0x1A */ + IOC_MEM_PART = 0x1B, /*!< 0x1B */ + IOC_PYRAMID_BUF = 0x1C, /*!< 0x1C */ + IOC_CUSTOM_SEI_PROC = 0x1D, /*!< 0x1D */ + IOC_PYRAMID_CFG = 0x1E, /*!< 0x1E */ + + + IOC_STREAM_CFG = 0x30, /*!< 0x30, For encode control (0x30 ~ 0x5F) */ + IOC_H264_CFG = 0x31, /*!< 0x31 */ + IOC_H265_CFG = 0x32, /*!< 0x32 */ + IOC_MJPEG_CFG = 0x33, /*!< 0x33 */ + IOC_FRAME_SYNC = 0x34, /*!< 0x34 */ + IOC_OVERLAY_INSERT = 0x35, /*!< 0x35 */ + IOC_FASTOSD_INSERT = 0x36, /*!< 0x36 */ + IOC_FPS_SUGGEST = 0x37, /*!< 0x37 */ + + + IOC_VCAP_CFG = 0x60, /*!< 0x60, For VIN & IDSP & VCAP control (0x60 ~ 0x6F) */ + IOC_WARP_CTRL = 0x61, /*!< 0x61 */ + IOC_VIDEO_PROC = 0x62, /*!< 0x62 */ + IOC_VIN_IDSP = 0x63, /*!< 0x63 */ + IOC_WAIT_IDSP_FRAME = 0x64, /*!< 0x64 */ + IOC_VIN_COMP = 0x65, /*!< 0x65 */ + IOC_IMG_SCALE = 0x66, /*!< 0x66 */ + + IOC_TEST = 0xD0, /*!< 0xD0, For Misc setting (0xD0 ~ 0xEF) */ + IOC_DEBUG = 0xD1, /*!< 0xD1 */ + + + IOC_CUSTOM = 0xF0, /*!< 0xF0, Reserved (0xF0 ~ 0xFF) */ +}; +/*! @} */ /* End of iav-ioctl-general-helper */ + + +/*! + * @addtogroup iav-ioc-enc-use-drv + * @{ + */ + +/*! + * This API can be invoked during any state to return the current device driver state. + */ +#define IAV_IOC_GET_IAV_STATE IAVENC_IOR(IOC_STATE, u32) + +/*! + * This API can be invoked during any state to retrieve chip ID information after the DSP is booted. + */ +#define IAV_IOC_GET_CHIP_ID IAVENC_IOR(IOC_CHIP_ID, u32) + +/*! + * This API sets the DSP log level for the debug. + */ +#define IAV_IOC_SET_DSP_LOG IAVENC_IOW(IOC_DSP_LOG, struct iav_dsplog_setup *) + +/*! + * This API can be used to return the current device driver state. + */ +#define IAV_IOC_DRV_DSP_INFO IAVENC_IOWR(IOC_DSP_INFO, struct iav_driver_dsp_info *) + +#define IAV_IOC_GET_DSP_HASH IAVENC_IOWR(IOC_DSP_HASH, struct iav_dsp_hash *) +#define IAV_IOC_SET_DSP_VP_CFG IAVENC_IOW(IOC_DSP_VP_CFG, struct iav_dsp_vp_cfg *) +#define IAV_IOC_GET_DSP_VP_CFG IAVENC_IOWR(IOC_DSP_VP_CFG, struct iav_dsp_vp_cfg *) + +/*! + * This API can be invoked during any state to query IAV information such as + * the boot mode, driver version, canvas, stream and privacy mask information. + */ +#define IAV_IOC_QUERY_INFO IAVENC_IOWR(IOC_QUERY_INFO, struct iav_queryinfo *) + +/*! + * This API can be used to do mutual authentication with DSP. + */ +#define IAV_IOC_DSP_AUTH IAVENC_IOWR(IOC_DSP_AUTH, struct iav_dsp_auth *) + +/*! @} */ /* End of iav-ioc-enc-use-drv */ + +/*! + * @addtogroup iav-ioc-enc-use-pyra + * @{ + */ +/*! + * This API can be used during the previewing or encoding states to feed pyramid + * buffers in the pyramid manual-feed mode. + */ +#define IAV_IOC_FEED_PYRAMID_BUF IAVENC_IOW(IOC_PYRAMID_BUF, struct iav_feed_pyramid *) + +/*! + * This API can be used during any state to release the pyramid buffer locked + * by IAV_IOC_QUERY_DESC (IAV_DESC_PYRAMID) in the pyramid manual-feed mode. + */ +#define IAV_IOC_RELEASE_PYRAMID_BUF IAVENC_IOWR(IOC_PYRAMID_BUF, struct iav_pyramiddesc *) +/*! @} */ /* End of iav-ioc-enc-use-pyra */ + + +/*! + * @addtogroup iav-ioc-enc-use-sys + * @{ + */ + +/*! + * This API can be invoked to disable preview and if successful, it brings the + * driver to enter the IDLE state. + */ +#define IAV_IOC_ENTER_IDLE IAVENC_IOW(IOC_ENTER_IDLE, u8) + +/*! + * This API can be invoked to enable preview and encoding can be started only + * in the preview state. + */ +#define IAV_IOC_ENABLE_PREVIEW IAVENC_IOW(IOC_ENABLE_PREVIEW, u8) + +/*! + * This API can be invoked during the stream-ready state to start stream encoding. + * Multiple streams can be encoded together if they are configured and in the + * ready state. + */ +#define IAV_IOC_START_ENCODE IAVENC_IOW(IOC_START_ENCODE, u32) + +/*! + * This API can be invoked during the stream-encoding state to stop stream encoding. + * Multiple streams can be stopped from encoding at the same time. + */ +#define IAV_IOC_STOP_ENCODE IAVENC_IOW(IOC_STOP_ENCODE, u32) + +/*! + * This API can be invoked during stream state transition from START to STOP or + * from STOP to START. It is used to abort such transitions. + */ +#define IAV_IOC_ABORT_ENCODE IAVENC_IOW(IOC_ABORT_ENCODE, u8) + +/*! + * This API can be invoked during the IDLE state to setup the encoding related + * system limit, which will otherwise have a default value. It must be issued + * before any of the APIs are called in the IDLE state. The configuration of + * the limit depends on how much memory has been allocated to DSP, how many + * features the DSP needs to support, and which encode mode the application uses. + */ +#define IAV_IOC_SET_SYSTEM_RESOURCE IAVENC_IOW(IOC_SYSTEM_RESOURCE, u8) + +/*! + * This API can be invoked during any state to get encoding related system limit. + * It is used to retrieve the default system resource limit for each encode mode. + */ +#define IAV_IOC_GET_SYSTEM_RESOURCE IAVENC_IOWR(IOC_SYSTEM_RESOURCE, u8) + +/*! + * This API can be invoked during the IDLE state to setup the pyramid related + * configuration for a specified channel, which will otherwise have a default + * value. It should be issued together with the system resource setup IOCTL. + */ +#define IAV_IOC_SET_PYRAMID_CFG IAVENC_IOW(IOC_PYRAMID_CFG, u8) + +/*! + * This API can be invoked during any state to get pyramid related + * configuration for a specified channel. + */ +#define IAV_IOC_GET_PYRAMID_CFG IAVENC_IOWR(IOC_PYRAMID_CFG, u8) + +/*! + * This API can be invoked at any state to use the GDMA device to perform memory + * copying between large memory partitions. As the GDMA device is a module dedi- + * cated for memory copy, it can free up the CPU cycles. + * + * The GDMA device must access contiguous physical memory addresses. It cannot + * access any virtual memory space allocated by user applications, meaning that + * this API cannot replace the general memory copy function "memcpy". The GDMA + * device can support linear memory copy in one and two dimensions. For the two + * dimensional copy, the pitch of the source and destination can be different, + * but the total memory size needs to be identical. + * + * The IAV driver supports the function of memory mapping from the physical + * memory to the user's virtual memory for most IAV/DSP memory partitions and + * all anonymous memory partitions, such as privacy mask, overlay, bit stream + * buffer, DSP and so on. User applications can call a GDMA copy API to perform + * memory copying among these memory partitions. + */ +#define IAV_IOC_GDMA_COPY IAVENC_IOW(IOC_GDMA_COPY, struct iav_gdma_copy *) + +/*! + * This API can be invoked during any state to query the system capability of each + * function for the specified encode mode. + */ +#define IAV_IOC_QUERY_ENC_MODE_CAP IAVENC_IOWR(IOC_QUERY_ENC_MODE_CAP, struct iav_enc_mode_cap *) + +/*! + * This API can be invoked during any state to query the source buffer capability of + * the specified buffer. + */ +#define IAV_IOC_QUERY_ENC_BUF_CAP IAVENC_IOWR(IOC_QUERY_ENC_BUF_CAP, struct iav_enc_buf_cap *) +/*! @} */ /* End of iav-ioc-enc-use-sys */ + +/*! + * @addtogroup iav-ioc-enc-img-scale + * @{ + */ +/*! + * This API can be invoked during preview/encoding state to do arbitrary image scale. + * For more information about arbitrary image scaler, refer to @ref ut_img_scale. + * + * Application needs to prepare the memory for the input buffer and the output buffer + * before calling image scale function. + */ +#define IAV_IOC_SET_IMG_SCALE IAVENC_IOWR(IOC_IMG_SCALE, struct iav_img_scale *) + +/*! + * This API can be invoked during preview/encoding state to wait for image scaling task finished. + * @note + * 1. This API is invoked only when member param: non_block_flag in struct iav_img_scale is 1. + * 2. When ioctl IAV_IOC_SET_IMG_SCALE is invoked multiple times in non-blocking way, DSP will + * process these taskes sequentially. So user applicate only needs to wait for the last image + * scaling task. Once the last task finished, all other prior tasks are also finished. + */ +#define IAV_IOC_WAIT_IMG_SCALE IAVENC_IOW(IOC_IMG_SCALE, struct iav_wait_img_scale *) + +/*! @} */ /* End of iav-ioc-enc-img-scale */ + +/*! + * @addtogroup iav-ioc-enc-use-efm + * @{ + */ +/*! + * This API can be invoked during preview/encoding state to get EFM related + * parameters. + */ +#define IAV_IOC_EFM_GET_POOL_INFO IAVENC_IOR(IOC_EFM_PROC, struct iav_efm_get_pool_info *) + +/*! + * This API can be invoked during preview/encoding state to get one EFM frame + * for processing. + */ +#define IAV_IOC_EFM_REQUEST_FRAME IAVENC_IOWR(IOC_EFM_PROC, struct iav_efm_request_frame *) + +/*! + * This API can be invoked during preview/encoding state to trigger DSP to start + * encoding the EFM stream. + */ +#define IAV_IOC_EFM_HANDSHAKE_FRAME IAVENC_IOW(IOC_EFM_PROC, struct iav_efm_handshake_frame *) +/*! @} */ /* End of iav-ioc-enc-use-efm */ + +/*! + * @addtogroup iav-ioc-enc-use-efr + * @{ + */ +/*! + * This API can be invoked during IDLE state to set the raw encode config. + */ +#define IAV_IOC_SET_RAW_ENCODE IAVENC_IOW(IOC_RAW_ENC, struct iav_raw_enc_setup *) + +/*! + * This API can be invoked during ANY state to get raw encode config. + */ +#define IAV_IOC_GET_RAW_ENCODE IAVENC_IOR(IOC_RAW_ENC, struct iav_raw_enc_setup *) + +/*! + * This API can be invoked during ANY state to wait for the raw encode ready signal. + */ +#define IAV_IOC_WAIT_RAW_ENCODE IAVENC_IOW(IOC_RAW_ENC, u8) + +/*! @} */ /* End of iav-ioc-enc-use-efr */ + +/*! + * @addtogroup iav-ioc-enc-use-mem + * @{ + */ + +/*! + * This API can be invoked during preview/encoding state to get one customized SEI buffer. + */ +#define IAV_IOC_CUSTOM_SEI_REQUEST_BUF IAVENC_IOWR(IOC_CUSTOM_SEI_PROC, struct iav_custom_sei_request_buf *) + +/*! + * This API queries the frame-based data descriptions. The frame-based data + * includes frame bit stream data, frame statistic data, frame raw data, frame + * YUV data, frame ME1 data, and bit stream info data for smart rate control library. + */ +#define IAV_IOC_QUERY_DESC IAVENC_IOWR(IOC_QUERY_DESC, struct iav_querydesc *) + +/*! + * This API queries the physical addresses for all the memory partitions shared + * between IAV and user application and the memory blocks of all canvases inside + * the DSP buffer. The start addresses, lengths, and data offsets of all memory + * partitions and canvases' YUV & ME are returned in information. + * + * The application should further map the physical addresses into user space + * virtual addresses, before operating the buffers. + */ +#define IAV_IOC_QUERY_MEMBLOCK IAVENC_IOWR(IOC_QUERY_MEMBLOCK, struct iav_querymem *) + +/*! + * This API can be used during any state to allocate the IAV/DSP sub-partitions. + */ +#define IAV_IOC_ALLOC_MEM_PART IAVENC_IOWR(IOC_MEM_PART, u8) + +/*! + * This API can be used during any state to allocate anonymous memory partitions. + * It allows user applications to allocate their own physically continuous memory. + */ +#define IAV_IOC_ALLOC_ANON_MEM_PART IAVENC_IOWR(IOC_MEM_PART, u32) + +/*! + * This API can be used during any state to free up a specified IAV/DSP sub- + * partition or an anonymous memory partition. + */ +#define IAV_IOC_FREE_MEM_PART IAVENC_IOW(IOC_MEM_PART, struct iav_free_mem_part *) + + +/*! @} */ /* End of iav-ioc-enc-use-mem */ + +/*! + * @addtogroup iav-ioc-enc-use-stm + * @{ + */ + +/*! + * This API can be invoked during the preview/encoding state to set stream configurations. + * All run time changeable configurations can be set via this IOCTL. + */ +#define IAV_IOC_SET_STREAM_CONFIG IAVENC_IOW(IOC_STREAM_CFG, struct iav_stream_cfg *) + +/*! + * This API can be invoked during ANY state to get stream configurations. + */ +#define IAV_IOC_GET_STREAM_CONFIG IAVENC_IOWR(IOC_STREAM_CFG, struct iav_stream_cfg *) + +/*! + * This API can be invoked during the stream idle state to perform H.264 + * encoding configuration for a particular stream. + */ +#define IAV_IOC_SET_H264_CONFIG IAVENC_IOW(IOC_H264_CFG, struct iav_h26x_cfg *) + +/*! + * This API can be invoked during any state to read the H.264 encoding configuration. + */ +#define IAV_IOC_GET_H264_CONFIG IAVENC_IOWR(IOC_H264_CFG, struct iav_h26x_cfg *) + +/*! + * This API can be invoked during the stream idle state to perform H.265 + * encoding configuration for a particular stream. + */ +#define IAV_IOC_SET_H265_CONFIG IAVENC_IOW(IOC_H265_CFG, struct iav_h26x_cfg *) + +/*! + * This API can be invoked during any state to read the H.265 encoding configuration. + */ +#define IAV_IOC_GET_H265_CONFIG IAVENC_IOWR(IOC_H265_CFG, struct iav_h26x_cfg *) + +/*! + * This API can be invoked during the stream idle state to configure MJPEG + * encoding quality and chrome format. The quality of the MJPEG can be configured + * while the streams are encoding. + * + * In the CV22 implementation, MJPEG only supports YUV420 and mono-chrome format. + */ +#define IAV_IOC_SET_MJPEG_CONFIG IAVENC_IOW(IOC_MJPEG_CFG, struct iav_mjpeg_cfg *) + +/*! + * This API can be invoked during any state to read the MJPEG encoding quality + * and chroma format. + */ +#define IAV_IOC_GET_MJPEG_CONFIG IAVENC_IOWR(IOC_MJPEG_CFG, struct iav_mjpeg_cfg *) + +/*! + * This API can be invoked during ANY state to get frame sync related parameters. + */ +#define IAV_IOC_GET_FRAME_SYNC_PROC IAVENC_IOWR(IOC_FRAME_SYNC, struct iav_stream_cfg *) + +/*! + * This API can be invoked during ANY state to configure frame sync related parameters. + */ +#define IAV_IOC_CFG_FRAME_SYNC_PROC IAVENC_IOW(IOC_FRAME_SYNC, struct iav_stream_cfg *) + +/*! + * This API can be invoked during ENCODING state to configure frame sync related + * parameters. + */ +#define IAV_IOC_APPLY_FRAME_SYNC_PROC IAVENC_IOW(IOC_FRAME_SYNC, u8) + +/*! + * This API can be invoked during preview/encoding state to get the suggested FPS. + */ +#define IAV_IOC_GET_FPS_SUGGEST IAVENC_IOWR(IOC_FPS_SUGGEST, struct iav_fps_suggest *) +/*! @} */ /* End of iav-ioc-enc-use-stm */ + +/*! + * @addtogroup iav-ioc-enc-use-ovl + * @{ + */ + +/*! + * These API can be used to insert a selected picture into the video stream as + * an overlay. It is intended for the OSD overlay library use, and it is + * supported by H.264, H. 265 and MJPEG. Because the picture data is added to + * the video data before encoding, it is also referred to as "OSD blending". + * + * It is the responsibility of the application to draw different overlay content + * in the memory partition. The application needs to call the "mmap" system in + * order to map the overlay memory partition before drawing the new content. + * + * In CV22 implementation, the overlay is added to the source buffer. This means + * that if the two streams share the same source buffer, the OSD overlay will + * be affected. Refer to user guide documentation for details. + */ +#define IAV_IOC_SET_OVERLAY_INSERT IAVENC_IOW(IOC_OVERLAY_INSERT, struct iav_overlay_insert *) + +/*! + * This API can be used to retrieve the overlay information that has already + * been inserted into the specified video stream. + */ +#define IAV_IOC_GET_OVERLAY_INSERT IAVENC_IOWR(IOC_OVERLAY_INSERT, struct iav_overlay_insert *) + +/*! + * This API is similar to IAV_IOC_SET_OVERLAY_INSERT. The only difference is + * FastOSD: the API tells DSP the specific region and number of regions that + * need to perform FastOSD. + */ +#define IAV_IOC_SET_FASTOSD_INSERT IAVENC_IOW(IOC_FASTOSD_INSERT, struct iav_fastosd_insert *) + +/*! + * This API can be used to retrieve the fast osd information that has already + * been inserted into the specified video stream. + */ +#define IAV_IOC_GET_FASTOSD_INSERT IAVENC_IOWR(IOC_FASTOSD_INSERT, struct iav_fastosd_insert *) +/*! @} */ /* End of iav-ioc-enc-use-ovl */ + +/*! + * @addtogroup iav-ioc-enc-use-vcap + * @{ + */ + +/*! + * This API can be invoked during @b IDLE state to set the VCAP configuration. + */ +#define IAV_IOC_SET_VCAP_CFG IAVENC_IOW(IOC_VCAP_CFG, struct iav_vcap_cfg *) + +/*! + * This API can be invoked during @b ANY state to get the VCAP config. + */ +#define IAV_IOC_GET_VCAP_CFG IAVENC_IOWR(IOC_VCAP_CFG, struct iav_vcap_cfg *) +/*! @} */ /* End of iav-ioc-enc-use-vcap */ + +/*! + * @addtogroup iav-ioc-enc-use-warp IAV WARP + * @{ + */ + +/*! + * This API can be invoked during preview/encode state to configure the single + * region warp parameters. + */ +#define IAV_IOC_CFG_WARP_CTRL IAVENC_IOW(IOC_WARP_CTRL, struct iav_warp_ctrl *) + +/*! + * This API can be invoked during preview/encode state to get the single region + * warp parameters. + */ +#define IAV_IOC_GET_WARP_CTRL IAVENC_IOWR(IOC_WARP_CTRL, struct iav_warp_ctrl *) + +/*! + * This API can be invoked during the preview/encode state to APPLY single + * region warp parameters. + */ +#define IAV_IOC_APPLY_WARP_CTRL IAVENC_IOW(IOC_WARP_CTRL, u8) +/*! @} */ /* End of iav-ioc-enc-use-warp */ + +/*! + * @addtogroup iav-ioc-enc-use-vproc IAV VPROC + * @{ + */ + +/*! + * This API can be invoked during ANY state to get configurations of Privacy Mask, + * DPTZ(digital pan / tile / zoom), Canvas Channel Order, Multi-Channel Blend, + * pyramid ROI and so on. + */ +#define IAV_IOC_GET_VIDEO_PROC IAVENC_IOWR(IOC_VIDEO_PROC, struct iav_video_proc *) + +/*! + * This API can be invoked during ANY state to configure Privacy Mask, + * DPTZ(digital pan / tile / zoom), Canvas Channel Order, Multi-Channel Blend + * and so on at run-time. When all configurations are configured through this + * API during PREVIEW/ENCODING state, API IAV_IOC_APPLY_VIDEO_PROC should be + * invoked to kick off these configurations to DSP. + */ +#define IAV_IOC_CFG_VIDEO_PROC IAVENC_IOW(IOC_VIDEO_PROC, struct iav_video_proc *) + +/*! + * This API can be invoked during PREVIEW/ENCODING state to kick off the + * configurations set by API IAV_IOC_CFG_VIDEO_PROC to DSP at run-time. + */ +#define IAV_IOC_APPLY_VIDEO_PROC IAVENC_IOW(IOC_VIDEO_PROC, u8) +/*! @} */ /* End of iav-ioc-enc-use-vproc */ + +/*! + * @addtogroup iav-ioc-enc-use-vin + * @{ + */ + +/*! + * This API can be invoked to set vin idsp cfg. + */ +#define IAV_IOC_SET_VIN_IDSP_CFG IAVENC_IOW(IOC_VIN_IDSP, struct iav_vin_idsp_config *) + +/*! + * This API can be invoked get the vin idsp cfg. + */ +#define IAV_IOC_GET_VIN_IDSP_CFG IAVENC_IOWR(IOC_VIN_IDSP, struct iav_vin_idsp_config *) + +/*! + * This API can be invoked to set idsp delay info + * warp parameters. + */ +#define IAV_IOC_SET_VIN_IDSP_DELAY_INFO IAVENC_IOW(IOC_VIN_IDSP, u8) + +/*! + * This API can be invoked during the PREVIEW / ENCODING state to wait until the + * next valid IDSP frame. It is useful for applications that need to synchronize + * with the IDSP frame rate. + * + * For multi-channel cases, when the IDSP resampling frame rate feature is enabled + * and the channels have different IDSP resampling frame rates, ensure the application + * specifies the channel ID, because the next frame will need to wait. The application + * can also specify a channel map for multi-channel cases. If this is the case, + * the IAV driver will wait for the next frame of the channel with the lowest + * IDSP frame rate. + */ +#define IAV_IOC_WAIT_NEXT_IDSP_FRAME IAVENC_IOW(IOC_WAIT_IDSP_FRAME, u8) + +/*! + * This API can be invoked during preview/encode state to get the single region + * warp parameters. + */ +#define IAV_IOC_SET_VIN_COMPAND_CFG IAVENC_IOW(IOC_VIN_COMP, struct iav_vin_compand_config *) + +/*! + * This API can be invoked during preview/encode state to get the single region + * warp parameters. + */ +#define IAV_IOC_GET_VIN_COMPAND_CFG IAVENC_IOWR(IOC_VIN_COMP, struct iav_vin_compand_config *) +/*! @} */ /* End of iav-ioc-enc-use-vin */ + +/*! + * @addtogroup iav-ioc-enc-use-dbg + * @{ + */ +/*! + * This API can be invoked during any state to set the IAV debug configuration. + */ +#define IAV_IOC_SET_DEBUG_CONFIG IAVENC_IOW(IOC_DEBUG, struct iav_debug_cfg *) + +/*! + * This API can be invoked during any state to fetch the IAV debug configuration. + */ +#define IAV_IOC_GET_DEBUG_CONFIG IAVENC_IOR(IOC_DEBUG, struct iav_debug_cfg *) +/*! @} */ /* End of iav-ioc-enc-use-dbg */ + + +/*! + * @addtogroup iav-ioc-enc-use-usr + * @{ + */ + +/*! + * This API can be invoked during any state for customized commands. + */ +#define IAV_IOC_CUSTOM_CMDS IAVENC_IOWR(IOC_CUSTOM, u8) +/*! @} */ /* End of iav-ioc-enc-use-usr */ + + + +/*! + * @addtogroup iav-ioctl-dec-helper + * @{ + */ +#define IAVDECIOC_MAGIC 'D' +#define IAVDEC_IO(nr) _IO(IAVDECIOC_MAGIC, nr) +#define IAVDEC_IOR(nr, size) _IOR(IAVDECIOC_MAGIC, nr, size) +#define IAVDEC_IOW(nr, size) _IOW(IAVDECIOC_MAGIC, nr, size) +#define IAVDEC_IOWR(nr, size) _IOWR(IAVDECIOC_MAGIC, nr, size) + +typedef enum { + /* For decode control (0x00 ~ 0x1F) */ + IOC_ENTER_DECODE_MODE = 0x00, /*!< 0x00, For decode control (0x00 ~ 0x1F) */ + IOC_LEAVE_DECODE_MODE = 0x01, /*!< 0x01 */ + IOC_CREATE_DECODER = 0x02, /*!< 0x02 */ + IOC_DESTROY_DECODER = 0x03, /*!< 0x03 */ + IOC_DECODE_START = 0x04, /*!< 0x04 */ + IOC_DECODE_STOP = 0x05, /*!< 0x05 */ + IOC_DECODE_VIDEO = 0x06, /*!< 0x06 */ + IOC_DECODE_JPEG = 0x07, /*!< 0x07 */ + IOC_WAIT_DECODE_BSB = 0x08, /*!< 0x08 */ + IOC_INTRAPLAY_RESET_BUFFERS = 0x09, /*!< 0x09 */ + IOC_INTRAPLAY_REQUEST_BUFFER = 0x0A, /*!< 0x0A */ + IOC_INTRAPLAY_DECODE = 0x0B, /*!< 0x0B */ + IOC_INTRAPLAY_YUV2YUV = 0x0C, /*!< 0x0C */ + IOC_INTRAPLAY_DISPLAY = 0x0D, /*!< 0x0D */ + IOC_DECODE_TRICK_PLAY = 0x0E, /*!< 0x0E */ + IOC_DECODE_SPEED = 0x0F, /*!< 0x0F */ + IOC_WAIT_PLAYBACK_EOS = 0x10, /*!< 0x10 */ + + /* For decode status (0x30 ~ 0x3F) */ + IOC_QUERY_DECODE_STATUS = 0x30, /*!< 0x30, For decode status (0x30 ~ 0x3F) */ + IOC_QUERY_DECODE_BSB = 0x31, /*!< 0x31 */ +} IAV_DEC_IOC; + +/*! @} */ /* iav-ioctl-dec-helper */ + +/*! @addtogroup iav-ioctl-dec-api + * @{ + */ + +/*! + * This API can be invoked to allow the video to enter the decode mode. + * This transition can only be done when the DSP is in the idle mode or after it boots up. + */ +#define IAV_IOC_ENTER_DECODE_MODE IAVDEC_IOWR(IOC_ENTER_DECODE_MODE, struct iav_decode_mode_config *) + +/*! + * This API can be invoked to leave the decode mode. Only when the DSP in the decode mode, this transition can be done. + * It will make the DSP go into the idle mode. + */ +#define IAV_IOC_LEAVE_DECODE_MODE IAVDEC_IO(IOC_LEAVE_DECODE_MODE) + +/*! + * This API can be invoked to create a decoder instance. + * Only when the DSP is in the decode mode, this API is valid. + */ +#define IAV_IOC_CREATE_DECODER IAVDEC_IOWR(IOC_CREATE_DECODER, struct iav_decoder_info *) + +/*! + * This API can be invoked to destroy a decoder instance and it is valid only when the DSP is in the decode mode. + */ +#define IAV_IOC_DESTROY_DECODER IAVDEC_IOW(IOC_DESTROY_DECODER, u8) + +/*! + * This API can be invoked to start the decode process and it is valid only when the DSP in the decode mode. + */ +#define IAV_IOC_DECODE_START IAVDEC_IOW(IOC_DECODE_START, u8) + +/*! + * This API can be invoked to stop the decode process and it is only valid when the DSP is in the decode mode. + */ +#define IAV_IOC_DECODE_STOP IAVDEC_IOW(IOC_DECODE_STOP, struct iav_decode_stop *) + + +/*! + * This API can be invoked to decode the video bitstream. + * It is only valid when DSP is in the decode mode. + */ +#define IAV_IOC_DECODE_VIDEO IAVDEC_IOW(IOC_DECODE_VIDEO, struct iav_decode_video *) + +/*! + * This API can be invoked to decode JPEG bit stream. + * This API is valid only when the DSP is in the decode mode. + */ +#define IAV_IOC_DECODE_JPEG IAVDEC_IOW(IOC_DECODE_JPEG, struct iav_decode_jpeg *) + +/*! + * This API can be invoked for a wait-free zoom in the bitstream buffer. + * This API is valid only when DSP is in the decode mode. + */ +#define IAV_IOC_WAIT_DECODE_BSB IAVDEC_IOWR(IOC_WAIT_DECODE_BSB, struct iav_decode_bsb *) + +/*! + * This API can be invoked to perform trick play in the playback. + * It is only valid when the DSP is in the decode mode. + */ +#define IAV_IOC_DECODE_TRICK_PLAY IAVDEC_IOW(IOC_DECODE_TRICK_PLAY, struct iav_decode_trick_play *) + +/*! + * This API can be invoked to update the playback speed and direction. + * This API is valid only when the DSP is in the decode mode. + */ +#define IAV_IOC_DECODE_SPEED IAVDEC_IOW(IOC_DECODE_SPEED, struct iav_decode_speed *) + +/*! + * This API can be invoked to query decoding status and it is only valid when the DSP is in the decode mode. + */ +#define IAV_IOC_QUERY_DECODE_STATUS IAVDEC_IOR(IOC_QUERY_DECODE_STATUS, struct iav_decode_status *) + +/*! + * This API can be invoked to query the bitstream buffer and it is only valid when the DSP is in the decode mode. + */ +#define IAV_IOC_QUERY_DECODE_BSB IAVDEC_IOR(IOC_QUERY_DECODE_BSB, struct iav_decode_bsb *) + +/*! + * This API can be invoked to wait until the total stream is decoded by DSP. It is only valid when the DSP is in the decode mode. + */ +#define IAV_IOC_WAIT_PLAYBACK_EOS IAVDEC_IOW(IOC_WAIT_PLAYBACK_EOS, struct iav_decode_wait_eos *) + +#define IAV_IOC_INTRAPLAY_RESET_BUFFERS IAVDEC_IOW(IOC_INTRAPLAY_RESET_BUFFERS, struct iav_intraplay_reset_buffers *) +#define IAV_IOC_INTRAPLAY_REQUEST_BUFFER IAVDEC_IOWR(IOC_INTRAPLAY_REQUEST_BUFFER, struct iav_intraplay_frame_buffer *) +#define IAV_IOC_INTRAPLAY_DECODE IAVDEC_IOW(IOC_INTRAPLAY_DECODE, struct iav_intraplay_decode *) +#define IAV_IOC_INTRAPLAY_YUV2YUV IAVDEC_IOW(IOC_INTRAPLAY_YUV2YUV, struct iav_intraplay_yuv2yuv *) +#define IAV_IOC_INTRAPLAY_DISPLAY IAVDEC_IOW(IOC_INTRAPLAY_DISPLAY, struct iav_intraplay_display *) +/*! @} */ /* End of iav-ioctl-dec-api */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/arch_v5/img_api_arch.h b/include/ambarella/arch_v5/img_api_arch.h new file mode 100644 index 0000000..ca67417 --- /dev/null +++ b/include/ambarella/arch_v5/img_api_arch.h @@ -0,0 +1,165 @@ +/* + * img_api_arch.h + * + * History: + * 2012/10/10 - [Cao Rongrong] created file + * 2013/12/12 - [Jian Tang] modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef IMG_API_ADV_ARCH_H +#define IMG_API_ADV_ARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#include "config.h" +#include "basetypes.h" + +// basic 3A related APIs +int img_config_vin_channel_num(int num); +int img_lib_init(int fd_iav,img_config_info_t* p_img_cfg); +int img_lib_deinit(img_lib_deinit_config_t* p_cfg); +void img_algo_get_lib_version(img_lib_version_t* p_img_algo_info ); +int img_config_pipeline(int fd_iav,img_config_info_t * p_img_cfg); +int img_config_aaa(aaa_config_ptr_t* p_ptr_bin,int vin_index); +int img_prepare_isp(int fd_iav);//called before start aaa, after config pipline, load_cc_container +int img_start_aaa(int fd_iav); +int img_stop_aaa(void); +int img_register_aaa_algorithm(aaa_api_t custom_aaa_api); +int img_get_mem_info(uintptr *user_start, u32 *buff_size); +int img_get_sbp_buf(uintptr* sbp_start, size_t* buf_size); +int img_adj_load_cc_binary(cc_binary_addr_t* addr,u8* reg_addr); +int img_adj_init_isp_param(u32 vin_index,adj_isp_param_t* p_adj_param); +int img_dynamic_load_containers(adj_isp_param_t* p_fc,u32 vin_index); +int img_dynamic_load_cc_bin(cc_binary_addr_t* addr,u32 vin_index); +//3a ctrl +int img_enable_ae(int* enable,u32 update_vin_channel); +int img_enable_awb(int* enable,u32 update_vin_channel); +int img_enable_af(int* enable,u32 update_vin_channel); +int img_enable_adj(int* enable,u32 update_vin_channel); +int img_get_ae_cntl_status(int* enable); +int img_get_awb_cntl_status(int* enable); +int img_get_adj_cntl_status(int* enable); +// sensor ctrl +int img_channel_to_vsrc_mapping(int fd_iav);//it is expected to used before sensor set/get +int img_get_sensor_agc(int channel_id); +int img_get_sensor_shutter(int channel_id); +int img_set_sensor_agc(int fd_iav,u32 gain_tbl_idx,int channel_id);//linear mode ,set to sensor directly +int img_set_sensor_shutter(int fd_iav,u32 shutter_row,int channel_id);//linear mode ,set to sensor directly +int img_sensor_shutter_time_to_row( int fd_iav,int shutter_time, int* shutter_row, int channel_id);//hdr mode ,set to sensor directly +int img_set_hdr_sensor_shutter_agc_group(int fd_iav,hdr_sensor_gp_t * p_sensor_gp,int chan_id);//hdr mode ,set to sensor directly +int img_get_hdr_sensor_agc_group(int fd_iav,hdr_gain_gp_t * p_gain_gp,int chan_id); +int img_get_hdr_sensor_shutter_group(int fd_iav,hdr_shutter_gp_t * p_sht_gp,int chan_id); +//ae +int img_set_ae_speed(u8* speed_level,u32 update_vin_channel);//0 -7, 7 is the fastest +int img_set_ae_exp_lines(ae_lines_config_t* p_ae_line_cfg,u32 update_vin_channel); +int img_set_ae_target_ratio(u16* target_ratio,u32 update_vin_channel); +int img_set_ae_loosen_belt(u16* belt,u32 update_vin_channel); +int img_set_ae_meter_config(ae_meter_config_t* p_meter_cfg,u32 update_vin_channel); +int img_set_ae_auto_knee(u8* auto_knee,u32 update_vin_channel);// 0-255 +int img_register_custom_aeflow_func(ae_flow_func_t* custom_ae_flow_func); +int img_get_ae_cfa_luma(u16* ae_cfa_luma); +int img_get_ae_rgb_luma(u16* ae_rgb_luma); +int img_get_ae_system_gain(u32* ae_system_gain);//db =ae_system_gain[]>>24 +int img_get_ae_stable(u8* ae_stable_flag);//return 0: AE adjusting; 1: AE stable; 2: AE reach to high light limit; 3: AE reach to low light limit. +int img_get_ae_cursor(u8* ae_cursor); +int img_get_ae_target_ratio(u16* ae_target_ratio); +int img_get_ae_target(u16* ae_target); +int img_get_ae_piris_info(piris_info_t* piris_info); //success: return 0, failed: return -1 +int img_format_ae_line(int fd_iav,line_t * ae_lines,int line_num,u32 db_step,int channel_id);//shutter_index to shutter_row used in ae algo +//int img_config_auto_knee_info(img_auto_knee_config_info_t* config); + +//awb +int img_get_awb_gain_comp(wb_gain_t *comp_gain, wb_cali_comp_t *direction); +int img_get_awb_manual_gain(wb_gain_t* p_wb_gain); +int img_set_awb_custom_gain(wb_gain_t* p_cus_gain,u32 update_vin_channel); +int img_set_awb_cali_config(awb_cali_info_t* p_awb_cali_info,u32 update_vin_channel); +int img_set_awb_speed(u8* p_awb_spd,u32 update_vin_channel); +int img_set_awb_failure_remedy(awb_failure_remedy_t* awb_failure_remedy,u32 update_vin_channel); +int img_get_awb_mode(awb_control_mode_t *p_awb_mode); +int img_set_awb_mode(awb_control_mode_t *p_awb_mode,u32 update_vin_channel); +int img_get_awb_method(awb_work_method_t *p_awb_method); +int img_set_awb_method(awb_work_method_t *p_awb_method,u32 update_vin_channel); +int img_get_awb_env(awb_environment_t *p_awb_env); +int img_set_awb_env(awb_environment_t *p_awb_env,u32 update_vin_channel); +//af +int img_register_lens_drv(lens_dev_drv_t custom_lens_drv); +int img_lens_init(void); +int img_config_lens_info(lens_ID lensID); +int img_load_lens_param(lens_param_t *p_lens_param); +int img_config_lens_cali(lens_cali_t *p_lens_cali); +int img_af_set_range(af_range_t * p_af_range); +int img_af_set_mode(af_mode mode); +int img_af_set_roi(af_ROI_config_t* af_ROI); +int img_af_set_zoom_idx(u16 zoom_idx); +int img_af_set_focus_idx(s32 focus_idx); +int img_af_set_focus_offset(s8 focus_offset); +//int img_af_set_reset(void); +void img_af_load_param(void* p_af_param, void* p_zoom_map); +int img_af_set_statistics(int fd_iav, af_statistics_ex_t *paf_ex); +int img_af_set_brake(void); //force brake while zoom in or out +int img_af_set_debug(s32 debug); //only for internal debug +int img_af_get_work_state(u16 zoom_idx); //get af working state on specific zoom index +int img_af_set_aux_zoom(u8 aux_zoom_enb); //set aux zoom enable/disable +int img_af_set_one_push(void); //only valid in SAF mode +int img_af_set_interval_time(u8 time_sec); //set IAF mode interval time in second (time_sec>0) +int img_af_set_sensitivity(u16 sensitivity); //set CAF mode AF trigger threshold (2000<sensitivity<16000) + +//calibartion +int img_calc_vignette(vignette_calc_t *p_vig_cal_setup, ik_calib_vignette_info_t *vig_result); +int img_cali_bad_pixel(badpix_cal_t*pCali_badpix_setup); + +//property +int img_get_adj_config_info(api_adj_stuff_t* p_adj_cfg); +int img_set_color_style(img_color_style* mode,u32 update_vin_channel); +int img_set_color_hue(int* hue,u32 update_vin_channel); //-15 - +15: -30deg - +30 deg +int img_set_color_brightness(int* brightness,u32 update_vin_channel); //-255 - +255 +int img_set_contrast(contrast_config_t* p_contrast_cfg,u32 update_vin_channel); +int img_set_color_saturation(int* saturation,u32 update_vin_channel);//unit = 64 +int img_set_bw_mode(int* mode,u32 update_vin_channel);// 0: diable, 1: enable +int img_set_sharpening_strength(int* str_level,u32 update_vin_channel);//default =6, 0-11 +int img_get_img_property(image_property_t *p_img_prop); +int img_set_mctf_strength(int* str_level,u32 update_vin_channel);//default = 6 ,0 ~11 +int img_set_mctf_property_ratio(mctf_property_t* p_mctf_property,u32 update_vin_channel);//unit: 64,64 +int img_set_sharpen_property_ratio(sharpen_property_t* p_shp_property,u32 update_vin_channel);//unit: 64,64,16,64,fractionalBits =1,2,3 +int img_set_wb_property_ratio(wb_ratio_t* p_wb_ratio,u32 update_vin_channel); +int img_get_wb_property_ratio(wb_ratio_t* p_wb_ratio); +int img_set_ce_input_cntl(ce_input_cntl_t* p_input_table_cntl,u32 update_vin_channel); +int img_set_ce_output_cntl(ce_output_cntl_t* p_output_table_cntl,u32 update_vin_channel); +int img_set_ce_boost_cntl(ce_boost_cntl_t* p_boost_table_cntl,u32 update_vin_channel); +int img_set_log_level(int level);//ae=0x1,awb=0x2,af=0x4,parser=0x8,main=0x10,hdr=0x20 +//int img_set_dsp_variable_range(img_adj_variable_range_t* variable_range); + + +#ifdef __cplusplus +} +#endif + +#endif // IMG_API_H + diff --git a/include/ambarella/arch_v5/img_customer_interface_arch.h b/include/ambarella/arch_v5/img_customer_interface_arch.h new file mode 100644 index 0000000..59b77eb --- /dev/null +++ b/include/ambarella/arch_v5/img_customer_interface_arch.h @@ -0,0 +1,109 @@ +/* + * img_customer_interface_arch.h + * + * History: + * 2012/10/10 - [Cao Rongrong] created file + * 2013/12/12 - [Jian Tang] modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IMG_CUSTOMER_INTERFACE_H__ +#define __IMG_CUSTOMER_INTERFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#endif // __IMG_CUSTOMER_INTERFACE_H__ + +int img_config_vin_channel_num(int num); +int img_config_pipeline(int fd_iav,img_config_info_t * p_img_cfg); + +int img_adj_retrieve_filters(aaa_output_t* p_aaa_output,chan_aaa_config_info_t* p_chan_aaa_cfg); +int img_adj_init_misc(int fd_iav,img_config_info_t* p_img_config,chan_aaa_config_info_t* p_chan_aaa_cfg); +int img_get_aaa_stats(int fd_iav,struct img_statistics* p_aaa_data); +int img_get_lastest_aaa_stats(int fd_iav,struct img_statistics* p_aaa_data); +int parse_aaa_data(struct img_statistics* p_data,img_config_info_t* p_img_cfg,multi_vin_chan_aaa_stats_t* p_mv_chan_aaa_stats); +int config_parser_dgain(u32 dgain,u32 index); +int img_runtime_adj(int* ev_index, aaa_output_t* p_aaa_output,void* p_stats,chan_aaa_config_info_t* p_chan_aaa_cfg); +int hal_channel_to_vsrc_mapping(int fd_iav); +int hal_init_vin_tick(); +int hal_get_vin_tick(); +int hal_deinit_vin_tick(); +//awb +int awb_flow_control_init(chan_aaa_config_info_t* p_chan_aaa_cfg); +int awb_flow_control(multi_vin_chan_aaa_stats_t* p_aaa_data, aaa_output_t *p_aaa_output); +int awb_flow_deinit(); +int awb_flow_config_instance_num(int num); +int awb_flow_get_manual_gain(wb_gain_t* p_wb_gain); +int awb_flow_set_custom_gain(wb_gain_t* p_wb_gain,u32 update_vin_chan); +int awb_flow_get_gain_comp(wb_gain_t *comp_gain, wb_cali_comp_t *direction); +int awb_flow_set_cali_shift(wb_gain_t *p_wb_org_gain, wb_gain_t *p_wb_ref_gain,u32 update_vin_chan); +int awb_flow_set_cali_thre(u16 *p_r_th, u16 *p_b_th,u32 update_vin_chan); +int awb_flow_set_speed(u8* p_speed,u32 update_vin_chan); +int awb_flow_set_failure_remedy(awb_failure_remedy_t* p_remedy,u32 update_vin_chan); +int awb_flow_get_method(awb_work_method_t* p_method); +int awb_flow_set_method(awb_work_method_t* p_method,u32 update_vin_chan); +int awb_flow_get_mode(awb_control_mode_t* p_mode); +int awb_flow_set_mode(awb_control_mode_t* p_mode,u32 update_vin_chan); +int awb_flow_get_environment(awb_environment_t* p_env); +int awb_flow_set_environment(awb_environment_t* p_env,u32 update_vin_chan); +int awb_flow_set_wb_ratio(adj_aeawb_control_t* p_aeawb_ctl,int index); +int awb_flow_set_log_level(int log_level); +int awb_flow_enable(int* enable,u32 update_vin_chan); +int awb_flow_get_enable(int* enable); +void awb_flow_pre_config(int awb_inst_index,wb_gain_t* wb_gain); +void revert_awb_hdr_statis(aaa_output_t* p_aaa_op, chan_aaa_stats_t *p_aaa_stat,img_config_info_t* p_img_cfg); + +//adj +int img_adj_enable(int* enable,u32 update_vin_channel); +//dynamic load containers +int img_adj_update_idle_container(u32 vin_index,adj_isp_param_t* p_adj_param); +void img_adj_flip_containers(u32 update_vin_chan); +int img_adj_sync_containers(u32 update_vin_chan); +void img_adj_reset_filters(u32 update_vin_chan); +int cc_3d_interpolation(void *p_cc_out, void *p_cc_pre, void *p_cc_next, int pre_wgt, int next_wgt); + + +//dynamic load cc +int img_adj_update_idle_cc(cc_binary_addr_t* addr,u32 vin_index); +void img_adj_flip_cc(u32 update_vin_chan); +//property +int adj_set_color_style(img_color_style* style,u32 update_vin_channel); +int adj_set_hue(int* hue,u32 update_vin_channel); +int adj_set_brightness(int* bright,u32 update_vin_channel); +int adj_set_contrast(contrast_config_t* contrast,u32 update_vin_chan); +int adj_set_saturation(int* saturation,u32 update_vin_channel); +int adj_set_bw_mode(int* enable,u32 update_vin_channel); +int adj_set_sharpening_level(int* level,u32 update_vin_channel); +int adj_set_mctf_level(int* level,u32 update_vin_channel); +void adj_set_mctf_property_ratio(mctf_property_t* p_mctf_property,u32 update_vin_channel); +void adj_set_sharpeness_property_ratio(sharpen_property_t* p_shp_property,u32 update_vin_channel); + +#ifdef __cplusplus +} +#endif diff --git a/include/ambarella/arch_v5/img_flow_api.h b/include/ambarella/arch_v5/img_flow_api.h new file mode 100644 index 0000000..012bcc5 --- /dev/null +++ b/include/ambarella/arch_v5/img_flow_api.h @@ -0,0 +1,82 @@ +/* + * img_flow_api.h + * + * History: + * Jan 7, 2019 - [thuang] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef _IMG_FLOW_API_H_ +#define _IMG_FLOW_API_H_ + +/********************************* + * + * for debug + * + *********************************/ + + +#include "stdio.h" +#include"img_struct_arch.h" +enum { + FILE_CC_3D_0 = 0, + FILE_CC_3D_1, + FILE_CC_3D_2, + FILE_CC_3D_3, + FILE_CC_REG, + FILE_ADJ, + FILE_AEB, + FILE_LEN, + FILE_AAA_CFG, + FILE_CALI, + FILE_TYPE_NUM, +} FILE_TYPE; + +typedef struct { + u8 chan_id;//input + u8 file_type_id;//input + u8 reserved[6]; + char filename[64]; + u8 *buf; + u32 size; +} bin_file_t; + +typedef struct { + int (*do_update_prepare_aaa_data)(bin_file_t *bin_data); + int (*do_extra_prepare_aaa)(); + int (*do_extra_start_aaa)(); + int (*do_extra_stop_aaa)(); +} img_flow_extra_func_t; + +int create_img_flow(int fd); +int destroy_img_flow(void); +void get_img_config(img_config_info_t *img_cfg); +void register_img_flow_api(img_flow_extra_func_t *p_extra_func); +void get_aaa_file_info(bin_file_t *file_info); + +#endif // _IMG_FLOW_API_H_ + diff --git a/include/ambarella/arch_v5/img_struct_arch.h b/include/ambarella/arch_v5/img_struct_arch.h new file mode 100644 index 0000000..0117db5 --- /dev/null +++ b/include/ambarella/arch_v5/img_struct_arch.h @@ -0,0 +1,1408 @@ +/* + * img_struct_arch.h + * + * History: + * 2018/05/08 - [HuangTeng] created file + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef IMG_ADV_STRUCT_ARCH_H +#define IMG_ADV_STRUCT_ARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "basetypes.h" +//#include "AmbaDataType.h" +//#include "img_abs_filter.h" +//#include "AmbaDSP_ImgDef.h" +#include "AmbaDSP_ImgFilter.h" +#include "AmbaDSP_Img3astatistic.h" +#include"iav_vin_ioctl.h" +#include"ambas_imgproc_arch.h" + +#define ADJ_VERSION 01 +#define AEB_VERSION 01 +#define VIN0_VSYNC "/proc/ambarella/vin0_idsp" +#define AAA_CALI_FILES_PATH "/ambarella/calibration" + + +#define MAX_AWB_TILE_COL (32) +#define MAX_AWB_TILE_ROW (32) +#define MAX_AWB_TILE_NUM (MAX_AWB_TILE_COL * MAX_AWB_TILE_ROW) +#define MAX_AE_TILE_COL (12) +#define MAX_AE_TILE_ROW (8) +#define MAX_AE_TILE_NUM (MAX_AE_TILE_COL * MAX_AE_TILE_ROW) +#define MAX_AF_TILE_COL (12) +#define MAX_AF_TILE_ROW (8) +#define MAX_AF_TILE_NUM (MAX_AF_TILE_COL * MAX_AF_TILE_ROW) +#define MAX_SHT_NL_TABLE_SIZE (64) +#define STEP16_GAIN_TABLE_SIZE (161) +#define STEP20_GAIN_TABLE_SIZE (201) +#define STEP57_GAIN_TABLE_SIZE (571) +#define STEP60_GAIN_TABLE_SIZE (601) +#define STEP64_GAIN_TABLE_SIZE (641) +#define STEP72_GAIN_TABLE_SIZE (721) +#define MAX_GAIN_TABLE_SIZE STEP72_GAIN_TABLE_SIZE +#define MIN_HDR_EXPOSURE_NUM (1) +#define MIN_HDR_EXPOSURE_RATIO (1) +#define MAX_HDR_EXPOSURE_RATIO (128) +#define HDR_EXPOSURE_RATIO_SHIFT (4) +#define HDR_EXPOSURE_RATIO_UNIT (1 << HDR_EXPOSURE_RATIO_SHIFT) +#define MAX_RATIO_TO_GAIN_TABLE_SIZE (MAX_HDR_EXPOSURE_RATIO) +#define INVALID_DYNA_SHT_RATIO (65537) +#define SHUTTER_STEP_FOR_ADJ_INTERPO (256) +#define CE_BOOST_STR_SIZE (4) +#define MAX_AE_LINES_NUM (32) + +#define SHUTTER_INVALID 0 +#define SHUTTER_1 512000000 //(512000000 / 1) +#define SHUTTER_1BY2 256000000 //(512000000 / 2) +#define SHUTTER_1BY3 170666667 //(512000000 / 3) +#define SHUTTER_1BY3P125 163840000 //(512000000 / 25 * 8) +#define SHUTTER_1BY4 128000000 //(512000000 / 4) +#define SHUTTER_1BY5 102400000 //(512000000 / 5) +#define SHUTTER_1BY6 85333333 //(512000000 / 6) +#define SHUTTER_1BY6P25 81920000 //(512000000 / 25 * 4) +#define SHUTTER_1BY7P5 68266667 //(512000000 / 15 * 2) +#define SHUTTER_1BY10 51200000 //(512000000 / 10) +#define SHUTTER_1BY12P5 40960000 //(512000000 / 25 * 2) +#define SHUTTER_1BY15 34133333 //(512000000 / 15) +#define SHUTTER_1BY20 25600000 //(512000000 / 20) +#define SHUTTER_1BY24 21333333 //(512000000 / 24) +#define SHUTTER_1BY25 20480000 //(512000000 / 25) +#define SHUTTER_1BY30 17066667 //(512000000 / 30) +#define SHUTTER_1BY31 16516129 //(512000000 / 31) +#define SHUTTER_1BY33 15360000 //(512000000 / 33.3) +#define SHUTTER_1BY36 14222222 //(512000000 / 36 ) +#define SHUTTER_1BY40 12800000 //(512000000 / 40) +#define SHUTTER_1BY50 10240000 //(512000000 / 50) +#define SHUTTER_1BY60 8533333 //(512000000 / 60) +#define SHUTTER_1BY70 7314285 //(512000000 / 70) +#define SHUTTER_1BY90 5688888 //(512000000 / 90) +#define SHUTTER_1BY100 5120000 //(512000000 / 100) +#define SHUTTER_1BY120 4266667 //(512000000 / 120) +#define SHUTTER_1BY200 2560000 //(512000000 / 200) +#define SHUTTER_1BY240 2133333 //(512000000 / 240) +#define SHUTTER_1BY320 1600000 //(512000000 / 320) +#define SHUTTER_1BY480 1066667 //(512000000 / 480) +#define SHUTTER_1BY960 533333 //(512000000 / 960) +#define SHUTTER_1BY1024 500000 //(512000000 / 1024) +#define SHUTTER_1BY2000 256000 //(512000000 / 2000) +#define SHUTTER_1BY4000 128000 //(512000000 / 4000) +#define SHUTTER_1BY8000 64000 //(512000000 / 8000) +#define SHUTTER_1BY16000 32000 //(512000000 / 16000) +#define SHUTTER_1BY32000 16000 //(512000000 /32000) +#define SHUTTER_1BY64000 8000 //(512000000 /64000) + +typedef enum { + ISO_AUTO = 0, + ISO_100 = 0, //0db + ISO_150 = 3, //3db + ISO_200 = 6, //6db + ISO_300 = 9, //9db + ISO_400 = 12, //12db + ISO_600 = 15, //15db + ISO_800 = 18, //18db + ISO_1200 = 21, //21db + ISO_1600 = 24, //24db + ISO_2400 = 27, //27db + ISO_3200 = 30, //30db + ISO_4800 = 33, //33db + ISO_6400 = 36, //36db + ISO_9600 = 39, //39db + ISO_12800 = 42, //42db + ISO_19200 = 45, //45db + ISO_25600 = 48, //48db + ISO_51200 = 54, //54db + ISO_102400 = 60,//60db + ISO_204800 = 66,//66db + ISO_409600 = 72, // 72db +}ae_iso_mode; + +#define IRIS_FNO_TABLE_LENGTH (2522) +#define IRIS_FNO_TABLE_LENGTH_1 (IRIS_FNO_TABLE_LENGTH-1) +typedef enum { + APERTURE_AUTO = 0, + APERTURE_F64 = IRIS_FNO_TABLE_LENGTH_1-1881, + APERTURE_F45 = IRIS_FNO_TABLE_LENGTH_1-1752, + APERTURE_F32 = IRIS_FNO_TABLE_LENGTH_1-1624, + APERTURE_F22 = IRIS_FNO_TABLE_LENGTH_1-1496, + APERTURE_F16 = IRIS_FNO_TABLE_LENGTH_1-1367, + APERTURE_F11 = IRIS_FNO_TABLE_LENGTH_1-1239, + APERTURE_F8 = IRIS_FNO_TABLE_LENGTH_1-1110, + APERTURE_F5P6 = IRIS_FNO_TABLE_LENGTH_1-982, + APERTURE_F4 = IRIS_FNO_TABLE_LENGTH_1-853, + APERTURE_F2P8 = IRIS_FNO_TABLE_LENGTH_1-725, + APERTURE_F2 = IRIS_FNO_TABLE_LENGTH_1-596, + APERTURE_F1P6 = IRIS_FNO_TABLE_LENGTH_1-514, + APERTURE_F1P4 = IRIS_FNO_TABLE_LENGTH_1-468, + APERTURE_F1P2 = IRIS_FNO_TABLE_LENGTH_1-407, +}ae_aperture_mode; + +typedef struct joint_s { +/* s16 shutter; // shall be values in ae_shutter_mode + s16 gain; //shall be values in ae_iso_mode + s16 aperture; //shall be values in ae_aperture_mode +*/ + s32 factor[3]; //0-shutter, 1-gain, 2-iris +}joint_t; + +typedef struct line_s { + joint_t start; + joint_t end; +}line_t; + +typedef struct aaa_tile_report_s { + u16 awb_tile; + u16 ae_tile; + u16 af_tile; +}aaa_tile_report_t; + +typedef struct af_statistics_ex_s { + u8 af_horizontal_filter1_mode; + u8 af_horizontal_filter1_stage1_enb; + u8 af_horizontal_filter1_stage2_enb; + u8 af_horizontal_filter1_stage3_enb; + s16 af_horizontal_filter1_gain[7]; + u16 af_horizontal_filter1_shift[4]; + u16 af_horizontal_filter1_bias_off; + u16 af_horizontal_filter1_thresh; + u8 af_horizontal_filter2_mode; + u8 af_horizontal_filter2_stage1_enb; + u8 af_horizontal_filter2_stage2_enb; + u8 af_horizontal_filter2_stage3_enb; + s16 af_horizontal_filter2_gain[7]; + u16 af_horizontal_filter2_shift[4]; + u16 af_horizontal_filter2_bias_off; + u16 af_horizontal_filter2_thresh; + u16 af_tile_fv1_horizontal_shift; + u16 af_tile_fv1_vertical_shift; + u16 af_tile_fv1_horizontal_weight; + u16 af_tile_fv1_vertical_weight; + u16 af_tile_fv2_horizontal_shift; + u16 af_tile_fv2_vertical_shift; + u16 af_tile_fv2_horizontal_weight; + u16 af_tile_fv2_vertical_weight; +} af_statistics_ex_t;//to be removed + +typedef struct statistics_config_s { + u8 enable; + u8 auto_shift; + u16 awb_tile_num_col; + u16 awb_tile_num_row; + u16 awb_tile_col_start; + u16 awb_tile_row_start; + u16 awb_tile_width; + u16 awb_tile_height; + u16 awb_tile_active_width; + u16 awb_tile_active_height; + u16 awb_pix_min_value; + u16 awb_pix_max_value; + u16 ae_tile_num_col; + u16 ae_tile_num_row; + u16 ae_tile_col_start; + u16 ae_tile_row_start; + u16 ae_tile_width; + u16 ae_tile_height; + u16 af_tile_num_col; + u16 af_tile_num_row; + u16 af_tile_col_start; + u16 af_tile_row_start; + u16 af_tile_width; + u16 af_tile_height; + u16 af_tile_active_width; + u16 af_tile_active_height; + u16 ae_pix_min_value; + u16 ae_pix_max_value; +}statistics_config_t; + +typedef struct float_tile_config_s{ + u16 tile_col_start; + u16 tile_row_start; + u16 tile_width; + u16 tile_height; + u16 tile_shift; +}float_tile_config_t; + +typedef struct float_statistics_config_s{ + u16 number_of_tiles; + float_tile_config_t float_tiles_config[32]; +}float_statistics_config_t; + +typedef struct awb_data_s { + u32 r_sum; + u32 g_sum; + u32 b_sum; + u32 pixel_cnt; +}awb_data_t; + +typedef struct ae_data_s { + u32 lin_y; + u32 non_lin_y; +}ae_data_t; + + +//RAW statistics for customer 3A +typedef struct af_stat_s { + u16 sum_fy; + u16 sum_fv1; + u16 sum_fv2; +}af_stat_t; +typedef struct rgb_histogram_stat_s { + u32 his_bin_y[HIST_BIN_NUM]; + u32 his_bin_r[HIST_BIN_NUM]; + u32 his_bin_g[HIST_BIN_NUM]; + u32 his_bin_b[HIST_BIN_NUM]; +}rgb_histogram_stat_t; + +typedef struct float_rgb_af_stat_s{ + u32 sum_fv1; + u32 sum_fv2; +}float_rgb_af_stat_t; + +typedef struct cfa_awb_stat_s { + u16 sum_r; + u16 sum_g; + u16 sum_b; + u16 count_min; + u16 count_max; +}cfa_awb_stat_t; + +typedef struct cfa_ae_stat_s { + u16 lin_y; + u16 count_min; + u16 count_max; +}cfa_ae_stat_t; + +typedef struct cfa_histogram_stat_s { + u32 his_bin_r[HIST_BIN_NUM]; + u32 his_bin_g[HIST_BIN_NUM]; + u32 his_bin_b[HIST_BIN_NUM]; + u32 his_bin_y[HIST_BIN_NUM]; +}cfa_histogram_stat_t; + +typedef struct embed_hist_stat_s{ + u8 valid; + u16 frame_cnt; + u16 frame_id; + u32 mean; + u32 hist_begin; + u32 hist_end; + u32 mean_low_end; + u32 perc_low_end; + u32 norm_abs_dev; + u32 hist_bin_data[256]; +}embed_hist_stat_t; + +/////////awb +typedef struct adj_aeawb_control_s { + u32 low_temp_r_target; + u32 low_temp_b_target; + u32 d50_r_target; + u32 d50_b_target; + u32 high_temp_r_target; + u32 high_temp_b_target; +} adj_aeawb_control_t; + +#define AWB_UNIT_GAIN (1024) +#define AWB_UNIT_RATIO (128) +#define WB_DGAIN_UNIT (4096) +#define WB_DGAIN_UNIT_SHIFT (12) + +typedef enum{ + WB_ENV_INDOOR = 0, + WB_ENV_INCANDESCENT, + WB_ENV_D4000, + WB_ENV_D5000, + WB_ENV_SUNNY, + WB_ENV_CLOUDY, + WB_ENV_FLASH, + WB_ENV_FLUORESCENT, + WB_ENV_FLUORESCENT_H, + WB_ENV_UNDERWATER, + WB_ENV_CUSTOM, + WB_ENV_OUTDOOR, + WB_ENV_AUTOMATIC, + WB_ENV_NUMBER, +}awb_environment_t; + +typedef enum { + WB_AUTOMATIC = 0, + WB_INCANDESCENT, // 2800K + WB_D4000, + WB_D5000, + WB_SUNNY, // 6500K + WB_CLOUDY, // 7500K + WB_FLASH, + WB_FLUORESCENT, + WB_FLUORESCENT_H, + WB_UNDERWATER, + WB_CUSTOM, + WB_OUTDOOR, + WB_MODE_NUMBER, +}awb_control_mode_t; + +typedef enum { + AWB_NORMAL = 0, + AWB_MANUAL, + AWB_GREY_WORLD, + AWB_METHOD_NUMBER, +}awb_work_method_t; + +typedef enum{ + AWB_FAIL_DO_NOTHING = 0, + AWB_FAIL_CONST_GAIN, + AWB_FAIL_NUMBER, +}awb_failure_remedy_t; + +typedef struct wb_gain_s { + u32 r_gain; + u32 g_gain; + u32 b_gain; +} wb_gain_t; + +typedef struct awb_gain_s { + u16 video_gain_update; + u16 shutter_ratio[MAX_EXPOSURE_NUM]; + wb_gain_t video_wb_gain; +}awb_gain_t; + +typedef struct awb_diff_data_s{ + wb_gain_t _pre_raw_wb_gain; + u32 _d_50_a_diff; + u32 _d_40_a_diff; + u8 _spd_flg; + u8 _diff_first_flg; + u8 _d_a_diff_flg; + u8 _diff_flg; + s32 _diff_count; + u32 _diff; + u32 _raw_diff; + u32 _diff_same; +}awb_diff_data_t; + +typedef struct awb_lut_unit_s { + u16 gr_min; + u16 gr_max; + u16 gb_min; + u16 gb_max; + s16 y_a_min_slope; + s16 y_a_min; + s16 y_a_max_slope; + s16 y_a_max; + s16 y_b_min_slope; + s16 y_b_min; + s16 y_b_max_slope; + s16 y_b_max; + s8 weight; +} awb_lut_unit_t; + +#define MAX_AWB_WR_NUM (20) +typedef struct awb_lut_s { + u8 lut_no; + awb_lut_unit_t awb_lut[MAX_AWB_WR_NUM]; +} awb_lut_t; +typedef struct awb_lut_idx_s{ + u8 start; + u8 num; +}awb_lut_idx_t; +typedef enum{ + COMP_FWD = 0, + COMP_BWD, +}wb_cali_comp_t; +typedef struct white_adj_s { + s32 r_ratio; + s32 b_ratio; +}white_adj_t; +typedef struct wb_cali_s{ + wb_gain_t org_gain[2]; + wb_gain_t ref_gain[2]; + wb_gain_t comp_gain[2]; + u16 thre_r; + u16 thre_b; +}wb_cali_t; +typedef struct img_awb_param_s { + wb_gain_t menu_gain[WB_MODE_NUMBER]; + awb_lut_t wr_table; + awb_lut_idx_t awb_lut_idx[MAX_AWB_WR_NUM]; +}img_awb_param_t; + +////////////////////AE +typedef enum { + AE_SPOT_METERING = 0, + AE_CENTER_METERING, + AE_AVERAGE_METERING, + AE_CUSTOM_METERING, + AE_HISTOGRAM_RGB_METERING, + AE_HISTOGRAM_METERING, + AE_METERING_TYPE_NUMBER, +}ae_metering_mode; + +typedef struct ae_output_s { + u32 shutter_update; + u32 shutter_index; + u32 agc_update; + u32 agc_index; + u32 dgain_update; + u32 dgain; + u32 iris_update; + u32 iris_index; +}ae_output_t; +//AF///////////////////////////////////////////////////// +/** + * The supported Lens ID + */ +typedef enum{ +/* fixed lens ID list */ + LENS_CMOUNT_ID = 0, +/*p-iris lens ID list*/ + LENS_M13VP288IR_ID = 2, +/*MFZ lens ID list*/ + LENS_MZ128BP2810ICR_ID = 10, +/*custom lens ID list*/ + LENS_CUSTOM_ID = 900, +}lens_ID; + +#define MAX_PIRIS_TABLE_SIZE IRIS_FNO_TABLE_LENGTH + +typedef enum{ + PIRIS_DGAIN_TABLE = 0x0, + PIRIS_FNO_SCOPE = 0X1, + PIRIS_STEP_TABLE = 0x2, + PIRIS_ID_NUM, +}lens_piris_id; + +typedef struct{ + int lens_piris_id; + int array_size; +}lens_piris_header_t; + +typedef struct{ + lens_piris_header_t header; + u16 table[MAX_PIRIS_TABLE_SIZE]; +}lens_piris_dgain_table_t; + +typedef struct{ + lens_piris_header_t header; + int table[2]; + u32 reserved[4]; +}lens_piris_fno_scope_t; + +typedef struct{ + lens_piris_header_t header; + u16 table[MAX_PIRIS_TABLE_SIZE]; +}lens_piris_step_table_t; + +typedef struct{ + const int *scope; + const u16 *table; + int tbl_size; + const lens_piris_dgain_table_t *dgain; + //add here +}piris_param_t; + +typedef struct{ + piris_param_t piris_std; + //add here +}lens_param_t; + +typedef enum{ + NORMAL_RUN = 0x0, //default + PIRIS_CALI = 0x1, //bit0 + BACK_FOCUS_CALI = 0x2, //bit1 + //add here +}lens_cali_mode; + +typedef struct{ + u16 step_size; + //add here +}piris_cali_t; + +typedef struct{ + lens_cali_mode act_mode; + piris_cali_t piris_cfg; + //add here +}lens_cali_t; + +typedef struct{ + int f_number; //revert piris FNO value is mul with 65536 (<<16) + int motor_step; //revert piris motor step filled in xxx_piris_param.c +}piris_info_t; + +typedef struct{ + int (*set_IRCut)(u8 enable); + int (*set_shutter_speed)(u8 ex_mode, u16 ex_time); + int (*lens_init)(void); + int (*lens_park)(void); + int (*zoom_stop)(void); + int (*focus_near)(u16 pps, u32 distance); + int (*focus_far)(u16 pps, u32 distance); + int (*zoom_in)(u16 pps, u32 distance); + int (*zoom_out)(u16 pps, u32 distance); + int (*focus_stop)(void); + int (*set_aperture)(u16 aperture_idx); + int (*set_mechanical_shutter)(u8 me_shutter); + void (*set_zoom_pi)(u8 pi_n); + void (*set_focus_pi)(u8 pi_n); + int (*lens_standby)(u8 en); + int (*isFocusRuning)(void); + int (*isZoomRuning)(void); + int (*lens_cali)(lens_cali_t *p_lens_cali); + int (*load_param)(lens_param_t *p_lens_param, void *p_af_config, u8 cali_flag); + int (*get_iris_state)(int *iris_state); + int (*lens_enable)(u8 zoom_enb, u8 focus_enb); + int (*zoom_set)(s32 target, s16 ratio); + int (*focus_set)(s32 target, s16 ratio); + int (*iris_IRCut_set)(void); + int (*update_status)(int fd_iav); + void (*lens_deinit)(void); +} lens_dev_drv_t; +typedef struct{ // for algo internal use + u8 focus_update; + u8 zoom_update; + s32 focus_pulse; + s32 zoom_pulse; + s16 pps; + ik_af_stat_ex_info_t af_stat_config; + u8 af_stat_config_update; +}lens_control_t; +typedef struct{ + s32 far_bd; + s32 near_bd; +}af_range_t; +typedef enum{ + CAF = 0, + SAF = 1, + IAF = 2, + MANUAL = 3, + CALIB = 4, + DEBUG = 5, +}af_mode; +typedef struct{ + u32 tiles[MAX_AF_TILE_NUM]; +}af_ROI_config_t; + +typedef struct{ + af_mode workingMode; + af_ROI_config_t af_window; + u8 zoom_idx; + s32 focus_idx; //only avilable in MANUAL mode +}af_control_t; + +typedef struct af_fir_s{ + s8 coff[9]; +}af_fir_t; + +typedef struct{ + u16 pps_max; + u8 fv3_enable; + u16 skip_frame_TH; + u16 ev_idx_diff_TH; + u8 Csf;//Coarse CAF step_factor + u8 Fsf; //Fine CAF step_factor + u8 Cpk_th;//Coarse CAF peak down threshold + u8 Fpk_th;//Fine CAF peak down threshold +}zoom_param_t; + +typedef struct{ + s16 init_pps; + u8 init_zoom_idx; + af_fir_t spacial_fir; + u16 DOF_param; + zoom_param_t zoom_param[32]; +}af_param_t; + +#define ZOOM_STEP (32) + +typedef struct{ + s32 a; + s32 b; + s32 c; + u32 zoom_pluse; + u16 total_step; +} zoom_t; + +///adj//////////////////////////////////////////////////////// +typedef struct{ + struct vindev_aaa_info aaa_info; +}img_vin_info_t; + +typedef struct delay_gp_s{ + u8 delay[MAX_EXPOSURE_NUM]; + u8 reserved; +}delay_gp_t; + +typedef struct hdr_delay_s{ + delay_gp_t sht_delay; + delay_gp_t agc_delay; + delay_gp_t dgain_delay; + delay_gp_t offset_delay; +}hdr_delay_t; + +typedef struct raw_offset_table_s{ + u32 offset[MAX_EXPOSURE_NUM]; +}raw_offset_table_t; + +typedef struct raw_offset_coef_s{ + int long_padding; + int short_padding; +}raw_offset_coef_t; + +typedef struct raw_offset_config_s{ + u32 mode; // 0: raw offset table, static; 1: raw_offset coef, dynamic + raw_offset_table_t offset_tbl; + raw_offset_coef_t offset_coef; +}raw_offset_config_t; + +typedef struct{ + u32 min;//unit 128 + u32 max; +}img_limitation_t; + +typedef struct{ + img_limitation_t limit_cfg_2x[MAX_EXPOSURE_NUM-1]; + img_limitation_t limit_cfg_3x[MAX_EXPOSURE_NUM]; +}shutter_limit_config_t; + +typedef struct sensor_config_s{ + u32 max_gain_db;//<60 + u32 max_global_gain_db; + u32 max_single_gain_db; + u32 shutter_delay;//1,2,3 + u32 agc_delay;//1,2 + hdr_delay_t hdr_delay; // delay group for HDR + raw_offset_coef_t hdr_offset_coef; // sensor offset for HDR + struct vindev_aaa_info vin_dev_aaa_info; + + shutter_limit_config_t shutter_limit_cfg; +}sensor_config_t; + +typedef struct point_pos_s{ + int x; + int y; +}point_pos_t; + +///hdr/////////////// +typedef enum{ + HDR_1X = 1, + HDR_2X, + HDR_3X, + HDR_4X, +}hdr_expo_t; + +typedef struct hdr_shutter_gp_s{ + u32 shutter_info[MAX_EXPOSURE_NUM]; +}hdr_shutter_gp_t; + +typedef struct hdr_gain_gp_s{ + u32 gain_info[MAX_EXPOSURE_NUM]; +}hdr_gain_gp_t; + +typedef struct hdr_sensor_gp_s { + hdr_expo_t expo_num; + hdr_shutter_gp_t shutter_gp; + hdr_gain_gp_t agc_gp; +}hdr_sensor_gp_t; + +typedef enum{ + DELAY_NO_CHECK = 0, + DELAY_SHUTTER_CHECK = 1, + DELAY_AGC_CHECK = 2, + DELAY_DGAIN_CHECK = 3, + DELAY_BOTH_SHUTTER_AGC_CHECK = 4, + DELAY_RAW_OFFSET_CHECK = 5, + DELAY_SHUTTER_DOWN_CONTINUOUS_CHECK = 6, + DELAY_SHUTTER_UP_CONTINUOUS_CHECK = 7, + DELAY_AGC_DOWN_CONTINUOUS_CHECK = 8, + DELAY_AGC_UP_CONTINUOUS_CHECK = 9, + DELAY_CHECK_NUM, +} delay_check_mode_t; + +typedef struct hdr_delay_check_cfg_s { + delay_check_mode_t mode; + u32 long_shutter; + u32 long_agc; + u32 long_dgain; + void *fp_log; +} hdr_delay_check_cfg_t; + +//#### new start here + +#define ADJ_MAX_ENTRY_NUM (20) +#define ADJ_MAX_INNER_TBL_NUM (4) + +#define MW_AAA_DATA_FILETER_BITS (16) +#define FILTER_ID_MASK ((1 << MW_AAA_DATA_FILETER_BITS) - 1) + +typedef enum{ + ADJ_AE_PROP = 0x0, + ADJ_WB_RATIO = 0x1, + ADJ_BLC = 0x2, + ADJ_ANTIALIASING = 0x3, + ADJ_LEAKAGE = 0x4, + ADJ_GRGB_MISMATCH = 0x5, + ADJ_DPC = 0x6, + ADJ_CFA_NOISE_FILTER = 0x7, + ADJ_DEMOSAIC = 0x8, + ADJ_CC = 0x9, + ADJ_TONE = 0xA, + ADJ_RGB2YUV = 0xB, + ADJ_CHROMA_SCALE = 0xC, + ADJ_CHROMA_MEDIAN = 0xD, + ADJ_1STMODE_SEL = 0xE, + ADJ_ASF = 0xF, + ADJ_1ST_SHPBOTH = 0x10, + ADJ_1ST_SHPNOISE = 0x11, + ADJ_1ST_SHPFIR = 0x12, + ADJ_1ST_SHPCORING = 0x13, + ADJ_1ST_SHPCORING_INDEX_SCALE = 0x14, + ADJ_1ST_SHPCORING_MIN_RESULT = 0x15, + ADJ_1ST_SHPCORING_MAX_RESULT = 0x16, + ADJ_1ST_SHPCORING_SCALE_CORING = 0x17, + ADJ_FINAL_SHPBOTH = 0x18, + ADJ_FINAL_SHPNOISE = 0x19, + ADJ_FINAL_SHPFIR = 0x1A, + ADJ_FINAL_SHPCORING = 0x1B, + ADJ_FINAL_SHPCORING_INDEX_SCALE = 0x1C, + ADJ_FINAL_SHPCORING_MIN_RESULT = 0x1D, + ADJ_FINAL_SHPCORING_MAX_RESULT = 0x1E, + ADJ_FINAL_SHPCORING_SCALE_CORING = 0x1F, + ADJ_CHROMANF = 0x20, + ADJ_VIDEO_MCTF = 0x21, + ADJ_TEMPORAL_ADJUST = 0x22, + ADJ_VIDEO_MCTF_AND_FINAL_SHP = 0x23, + ADJ_MOTION_DETECT = 0x24, + ADJ_MOTION_DETECT_POS_DEP = 0x25, + ADJ_MOTION_DETECT_AND_MCTF = 0x26, + ADJ_CE = 0x27, + ADJ_CE_IO = 0x28, + ADJ_HDR = 0x29, + ADJ_RGBIR=0X2A, + ADJ_FILTER_NUM, +}filter_id; + +#define TOTAL_FILTER_NUM (4) //There is only 1 struct in aeb/adj file now. + +typedef struct img_lib_version_s { + int major; + int minor; + int patch; + u32 mod_time; + char description[64]; +} img_lib_version_t; +//new img algo start here +typedef struct cc_binary_addr_s{ + void* cc_0; + void* cc_1; + void* cc_2; + void* cc_3; + void* reg; +}cc_binary_addr_t; + +typedef struct{ + u32 mode; + u32 strength; +}contrast_config_t; + +typedef struct image_property_s { + int brightness; + int saturation; + int hue; + contrast_config_t contrast_config; +} image_property_t; +typedef enum { + IMG_COLOR_TV = 0, + IMG_COLOR_PC, + IMG_COLOR_STILL, + IMG_COLOR_CUSTOM, + IMG_COLOR_NUMBER, +}img_color_style; + +///calibration////// +typedef struct vignette_calc_s { + ik_static_blc_level_t black_level; + u32 bayer_pattern; + u16* raw_address; + u16 raw_width; + u16 raw_height; + u16 raw_pitch; + u16 compensate_ratio; //1024 for fully compensated , 0 for no compensation +} vignette_calc_t; + +typedef struct badpix_cal_s { + u8* badpixmap_buf; + u32* raw_buff; + u32 cap_width; + u32 cap_height; + u32 badpix_type; // hot pixel for cold pixel +#define FPN_DETECT_HOT_PIXEL (0x00) +#define FPN_DETECT_COLD_PIXEL (0x01) + u32 block_h; + u32 block_w; + u32 threshold_mode; +#define BADPIXEL_THRESHOLD_RELATIVE_TO_AVERAGE (0) +#define BADPIXEL_THRESHOLD_DIFFERENCE_TO_AVERAGE (1) + u32 upper_thres; + u32 lower_thres; +} badpix_cal_t; + +typedef struct img_cap_config_s{ +//input + int cap_mode;//cap_mode,1:raw,2:yuv,3:me1 + int cap_count; + int fixed_ae; + int shutter_row; + int agc_table_index; +//output + u32 cap_width; + u32 cap_height; + u32 cap_pitch; + u32 cap_size; +}img_cap_config_t; + +typedef enum{ + ISP_PIPELINE_LISO = 0,//supported + ISP_PIPELINE_MID_LISO,//not supported + ISP_PIPELINE_ADV_LISO,//supported! + ISP_PIPELINE_CLISO,//not supported + ISP_PIPELINE_HISO,//not supported + ISP_PIPELINE_FUSION, + ISP_PIPELINE_NUMBER, +}isp_pipeline_t; + +typedef enum{ + SENSOR_INPUT_RGB_RAW =0, + SENSOR_INPUT_RGBIR, + SENSOR_INPUT_RCCC, + SENSOR_INPUT_RCCB, + SENSOR_INPUT_MONO, + YUV_INPUT, + IMG_VIN_TYPE_NUM, +}img_vin_type_list; + +typedef struct { + u32 enable; + u32 clip_permillage; + u32 clip_bin; //only for hdr 128bin histogram now + u32 wl_inc; //dont care for now + u32 wl_reduce; //dont care for now +}ae_pw_cfg_t; + +typedef struct{ + u32 min_ratio;//unit 128 + u32 max_ratio; +}shutter_ratio_limitation_t; + +typedef struct{ + u32 target_value_for_linear; + u32 target_value_for_hdr_2x; + u32 target_value_for_hdr_3x; + u32 target_value_for_buildin; + u32 target_value[4]; +}ae_target_t; +typedef struct{ + u8 is_fix_ratio;//0 or 1 + u8 reserved[3]; + u16 fix_ratio[2];//0:L/M,1:M/S +}ratio_config_t; + +typedef struct{ + u32 under_low_light_pixel_bin_num; + u32 ideal_under_low_light_pixel_cnt_threshold_milli; + u32 good_expo_pixel_bin_index; + u32 over_expo_pixel_bin_index; + u32 short_clip_bin; + u32 short_clip_permillage; + u32 extra_target_ratio_floor; + u32 extra_target_ratio_ceiling; +}ae_extra_config_t; + +typedef struct{ + ae_target_t target; + shutter_ratio_limitation_t sht_ratio_limitaion; + ae_extra_config_t extra_cfg_for_linear; + ae_extra_config_t extra_cfg_for_hdr_2x; + ae_extra_config_t extra_cfg_for_hdr_3x; + ae_extra_config_t extra_cfg_for_buildin; +}ae_prop_t; + +typedef enum{ + AMBA_AAA_FLOW_FOR_LINEAR, + AMBA_AAA_FLOW_FOR_AR_BUILDIN_WDR, + AMBA_AAA_FLOW_FOR_2X, + AMBA_AAA_FLOW_FOR_2X_GAIN_HDR, + AMBA_AAA_FLOW_FOR_2X_SHUTTER_HDR, + AMBA_AAA_FLOW_FOR_3X, + AMBA_AAA_FLOW_FOR_3X_SHUTTER_HDR, + AMBA_AAA_FLOW_FOR_DUAL_GAIN_VS_HDR,/* DCG + Multi-shutter==>3X */ + AMBA_AAA_FLOW_FOR_DUAL_GAIN_CMPR_VS_HDR,/* DCG build-in + Multi-shutter ,eg:OV2770==>3X*/ + AMBA_AAA_FLOW_FOR_4X, + AMBA_AAA_FLOW_TYPE_NUM, +}amba_aaa_flow_type_list; + +typedef enum{ + IPC, + DMS, + BWC, + ADAS, + ITS, + APPLICATION_TYPE_NUM, +}amba_aaa_application; + +typedef struct{ + isp_pipeline_t isp_pipeline; + u32 amba_aaa_flow_type;//amba_aaa_flow_type_list + u32 expo_num; + u8 vsrc_id; + u8 sensor_ctrl; + u16 raw_width; + u16 raw_height; + u16 main_width; + u16 main_height; + int raw_pitch; + int raw_resolution; + int raw_bayer; + int master_chan_id; + int img_vin_type;//img_vin_type_list + u32 application_type; + u32 reserved[17]; +}img_config_info_t; + +typedef struct{ + int mctf_alpha_ratio; + int mctf_threshold_ratio; + int mctf_adv_iso_noise_level_ratio; + int mctf_temporal_max_change_ratio; + int motion_detect_noise_base_ratio; +}mctf_property_t; + +typedef struct{ + int cfa_noise_level_ratio;//unit 64 + int cfa_extent_regular_ratio;//unit 64 + int both_max_change_ratio;//unit 16 + int sharpen_CoringidxScale_ratio;//unit 64 + int sharpen_fractionalBits;//0-3 + //added since May 5th + int asf_alpha_max_ratio;//unit 64 + int asf_level_str_adj_str_ratio;//unit 64 + int asf_directional_decide_ratio;//unit 64 + int final_sharpen_fir_specify_ratio;//unit 64 + int final_sharpen_fir_str_dir_ratio;//unit 64 + int final_sharpen_fir_str_iso_ratio;//unit 64 + int final_sharpen_sacle_coring_ratio;//unit 64 +}sharpen_property_t; + +typedef struct{ + u32 mode;// 1:auto; 0:manual + u32 boost_str[CE_BOOST_STR_SIZE];//unit 128 range: 1:255 + s32 boost_table[IK_CE_BOOST_TABLE_SIZE]; +}ce_boost_cntl_t; + +typedef struct{ + u32 mode;// 1:auto; 0:manual + u32 input_str;//unit 128 range:1-255 + u32 input_table[IK_CE_INPUT_TABLE_SIZE]; +}ce_input_cntl_t; + +typedef struct{ + u32 mode;// 1:auto; 0:manual + u32 output_str;//unit 128 range: 1:255 + u32 output_table[IK_CE_OUTPUT_TABLE_SIZE]; +}ce_output_cntl_t; + +#define MAX_AUTO_KNEE_ROI (16) +typedef struct{ + int min; + int mid; + int max; +}auto_knee_roi_histo_level_t; +typedef struct{ + int enable; + int src_mode;//0:cfa, 1: rgb + int roi_low; + int roi_high; + int histo_min_no; + int histo_mid_min_no; + int histo_mid_max_no; + int histo_max_no; + auto_knee_roi_histo_level_t level[MAX_AUTO_KNEE_ROI]; +}img_auto_knee_config_info_t; + +typedef struct{ + u32 update_flag; + u32 offset[MAX_EXPOSURE_NUM]; +}raw_offset_info_t; + +typedef struct{ + ae_output_t ae_output[MAX_EXPOSURE_NUM]; + awb_gain_t awb_output; + lens_control_t lens_ctrl; + raw_offset_info_t raw_offset_info; + u32 extra_gain; +}aaa_output_t; + +typedef struct{ + aaa_tile_info_t tile_info; + awb_data_t awb_info[MAX_AWB_TILE_NUM]; + ae_data_t ae_info[MAX_AE_TILE_NUM]; + af_stat_t af_info[MAX_AF_TILE_NUM]; + af_stat_t af_rgb_info[MAX_AF_TILE_NUM]; + cfa_histogram_stat_t cfa_hist; + rgb_histogram_stat_t rgb_hist; +}img_normal_stats_t; + +typedef struct{ +}img_vin_stats_t; + +typedef struct{ + img_normal_stats_t normal_stats;//MAX_STATS_FRAME_NUM=2,0:RGB,1:IR + struct vin_hist_stat vin_hist_info[MAX_EXPOSURE_NUM]; + embed_hist_stat_t sensor_hist_info; +}img_aaa_stats_t; + +typedef struct{ + img_aaa_stats_t img_aaa_stats; + img_aaa_stats_t img_aaa_stats_ir; + aaa_tile_report_t tile_config_info; +}chan_aaa_stats_t; + +typedef struct{ + chan_aaa_stats_t chan_aaa_stats[IMG_MAX_VIN_CHANNEL_NUM]; + u32 stats_update_flag[IMG_MAX_VIN_CHANNEL_NUM]; +}multi_vin_chan_aaa_stats_t; + +typedef struct{ + line_t lines[MAX_AE_LINES_NUM]; + u32 line_num; + u32 line_belt; +}ae_line_info_t; + +typedef struct{ + ae_line_info_t ae_line_info[MAX_EXPOSURE_NUM]; +}ae_lines_config_t; + +typedef struct{ + ae_lines_config_t cfg_ae_lines; + u32 cfg_ae_gain_tbl_size; + u32 cfg_ae_sht_nl_tbl_size; + u32 cfg_ae_ratio_to_gain_tbl_size; + u32 cfg_ae_gain_tbl[MAX_GAIN_TABLE_SIZE]; + u32 cfg_ae_sht_nl_tbl[MAX_SHT_NL_TABLE_SIZE]; + u32 cfg_ae_ratio_to_gain_tbl[MAX_RATIO_TO_GAIN_TABLE_SIZE]; +}img_ae_param_t; + +typedef struct { + img_ae_param_t* p_ae_param; + img_awb_param_t* p_awb_param; + ik_aaa_stat_info_t* p_tile_cfg; + sensor_config_t* p_sensor_cfg; + u32* p_decompand_table; + u16* p_compand_table; + u32* p_ratio_to_gain_table; +}aaa_config_ptr_t; + +typedef struct{ + ik_aaa_stat_info_t img_tile_config; + img_ae_param_t img_ae_param; + img_awb_param_t img_awb_param; + sensor_config_t sensor_config; + af_param_t af_param; + zoom_t zoom_map[ZOOM_STEP]; + u32 decompress_table[DECOMP_LUT_ENTRY_NUM]; + u16 compress_table[COMP_LUT_ENTRY_NUM]; + u16 reserved; +}chan_aaa_config_info_t; + +typedef struct aaa_api_s{ + int (*p_ae_flow_control_init)(); + int (*p_ae_flow_control)(int fd_iav,multi_vin_chan_aaa_stats_t* p_aaa_data,aaa_output_t *p_ae_output); + int (*p_awb_flow_control_init)(); + int (*p_awb_flow_control)(multi_vin_chan_aaa_stats_t* p_aaa_data, aaa_output_t *p_awb_gain); + int (*p_calc_adj_index)(int* adj_index); + int (*p_af_flow_control_init)(af_control_t* p_af_control,chan_aaa_config_info_t* p_chan_aaa_cfg,aaa_output_t *p_aaa_output); + int (*p_af_flow_control)(af_control_t* p_af_control,multi_vin_chan_aaa_stats_t* p_aaa_data,aaa_output_t *p_aaa_output,u8 lens_runing_flag); + void (*p_af_set_range)(af_range_t* p_af_range); + void (*p_af_set_calib_param)(void* p_calib_param); +}aaa_api_t; +typedef struct ae_flow_func_s{ + u32 (*p_ae_flow_calc_luma_stat)(void* thisp,chan_aaa_stats_t* p_aaa_data); + u16 (*p_ae_flow_calc_target)(void* thisp,chan_aaa_stats_t* p_aaa_data); + int (*p_ae_flow_dc_iris_cntl)(int flag,int luma_diff,int* stat); +}ae_flow_func_t; + +#define MAX_AE_SPEED_LEVEL (8) +#define IMG_LOG_LEVEL_AE (0x1) +#define IMG_LOG_LEVEL_AWB (0x2) +#define IMG_LOG_LEVEL_AF (0x4) +#define IMG_LOG_LEVEL_PARSER (0x8) +#define IMG_LOG_LEVEL_MAIN (0x10) +#define IMG_LOG_LEVEL_HDR (0x20) + +typedef struct img_lib_deinit_config_s{ + u32 reserved; +}img_lib_deinit_config_t; + +typedef struct img_adj_variable_range_s{ + u32 max_chroma_radius; + +}img_adj_variable_range_t; + +typedef struct{ + int filter_id; + int auto_adj_argu; //-1 not in use, 0 no interpo, 1 interpo, 2 only for init + int filter_update_freq;//frame num + int filter_update_cnt;//internal,no need to config + int filter_update_flag;//internal,no need to config + int force_commit_flag;//internal,no need to config +}filter_header_t; + +typedef struct{ + u32 cs_ratio; + ik_chroma_scale_t chroma_scale; +}cs_pkg_t; + +typedef struct{ + u32 r_gain[3];//0:28k,1:50k,2:75k + u32 b_gain[3]; + u32 interpo_ev[2];//0:low,1:high + u32 interpo_alpha[2];//0:low,1:high +// uintptr_t reg; +// uintptr_t cc_bin_addr[5]; +}cc_pkg_t; + +typedef struct{ + ik_rgb_to_yuv_matrix_t r2y_for_pc; + ik_rgb_to_yuv_matrix_t r2y_for_tv; + ik_rgb_to_yuv_matrix_t r2y_for_custom; +}r2y_pkg_t; + +typedef struct{ + u32 coring[IK_NUM_CORING_TABLE_INDEX]; +}shp_coring_pkg_t; + +typedef struct{ + ik_static_blc_level_t blc_for_linear; + ik_static_blc_level_t blc_for_build_in_wdr; + ik_static_blc_level_t blc_for_hdr[MAX_EXPOSURE_NUM]; +}blc_pkg_t; + +typedef struct{ + ik_ce_input_table_t ce_input_table; + ik_ce_output_table_t ce_output_table; +}ce_input_and_output_pkg_t; + +typedef struct{ + ik_ce_t ce_pkg; +}ce_pkg_t; + +typedef struct{ + ik_frontend_wb_gain_t fe_wb_gain[MAX_EXPOSURE_NUM]; + ik_hdr_blend_t hdr_blend; +}hdr_ctrl_pkg_t; + +typedef struct{ + u32 hdr_blend_thre; + u32 hdr_flicker_thre; + u32 hdr_prop_c; + u32 hdr_prop_d; +}hdr_prop_info_t; + +typedef struct{ + ae_prop_t fc_ae_prop[ADJ_MAX_ENTRY_NUM]; + adj_aeawb_control_t fc_wb_ratio[ADJ_MAX_ENTRY_NUM]; + /* normal filters */ + blc_pkg_t fc_blc[ADJ_MAX_ENTRY_NUM]; + ik_anti_aliasing_t fc_antialiasing[ADJ_MAX_ENTRY_NUM]; + ik_cfa_leakage_filter_t fc_cfa_leakage_filter[ADJ_MAX_ENTRY_NUM]; + ik_grgb_mismatch_t fc_grgbmismatch[ADJ_MAX_ENTRY_NUM]; + ik_dynamic_bad_pixel_correction_t fc_dpc[ADJ_MAX_ENTRY_NUM]; + ik_cfa_noise_filter_t fc_cfa_noise_filter[ADJ_MAX_ENTRY_NUM]; + ik_demosaic_t fc_demosaic[ADJ_MAX_ENTRY_NUM]; + cc_pkg_t fc_cc_pkg; + ik_tone_curve_t fc_tone; + r2y_pkg_t fc_rgb2yuv; + cs_pkg_t fc_cs_pkg[ADJ_MAX_ENTRY_NUM]; + ik_chroma_median_filter_t fc_chroma_median_filter[ADJ_MAX_ENTRY_NUM]; + ik_first_luma_process_mode_t fc_1st_luma_process_mode; + ik_adv_spatial_filter_t fc_asf[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_both_t fc_1st_shpboth[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_noise_t fc_1st_shpnoise[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_fir_t fc_1st_shpfir[ADJ_MAX_ENTRY_NUM]; + shp_coring_pkg_t fc_1st_shpcoring[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_coring_idx_scale_t fc_1st_shpcoring_idx_scale[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_min_coring_result_t fc_1st_shp_min_coring_result[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_max_coring_result_t fc_1st_shp_max_coring_result[ADJ_MAX_ENTRY_NUM]; + ik_first_sharpen_scale_coring_t fc_1st_shp_scale_coring[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_both_t fc_final_shpboth[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_noise_t fc_final_shpnoise[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_fir_t fc_final_shpfir[ADJ_MAX_ENTRY_NUM]; + shp_coring_pkg_t fc_final_shpcoring[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_coring_idx_scale_t fc_final_shpcoring_idx_scale[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_min_coring_result_t fc_final_shpcoring_min_result[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_max_coring_result_t fc_final_shpcoring_max_result[ADJ_MAX_ENTRY_NUM]; + ik_final_sharpen_scale_coring_t fc_final_shpcoring_scale_coring[ADJ_MAX_ENTRY_NUM]; + ik_chroma_filter_t fc_chroma_filter[ADJ_MAX_ENTRY_NUM]; + ik_video_mctf_t fc_video_mctf[ADJ_MAX_ENTRY_NUM]; + ik_video_mctf_ta_t fc_mctf_ta[ADJ_MAX_ENTRY_NUM]; + ik_pos_dep33_t fc_mctf_and_final_shp; + ik_motion_detect_t fc_motion_detect[ADJ_MAX_ENTRY_NUM]; + ik_pos_dep33_t fc_motion_detect_pos_dep; + ik_motion_detect_and_mctf_t fc_motion_detect_and_mctf[ADJ_MAX_ENTRY_NUM]; + ik_ce_t fc_ce[ADJ_MAX_ENTRY_NUM]; + ce_input_and_output_pkg_t fc_ce_io_pkg; + hdr_prop_info_t fc_hdr_info[ADJ_MAX_ENTRY_NUM]; + ik_rgb_ir_t fc_rgbir[ADJ_MAX_ENTRY_NUM]; +}filter_container_pkg_t; + +typedef struct { + u32 mod_date; + u32 mod_time; + u32 version; + u32 sensor_id; + u32 chip_id; + u32 reserved[3]; +} img_version_t; + +typedef struct{ + img_version_t adj_version; + filter_header_t fc_header[ADJ_FILTER_NUM]; + filter_container_pkg_t fc_pkg; +}adj_isp_param_t; + +typedef struct{ + img_version_t aeb_version; + ik_aaa_stat_info_t tile_config; + ae_lines_config_t cfg_ae_lines_for_expo_1x; + ae_lines_config_t cfg_ae_lines_for_expo_2x; + ae_lines_config_t cfg_ae_lines_for_expo_3x; + ae_lines_config_t cfg_ae_lines_for_others[2];//0 for buildin, + u32 cfg_ae_gain_tbl_size; + u32 cfg_ae_sht_nl_tbl_size; + u32 cfg_ae_ratio_to_gain_tbl_size; + u32 cfg_ae_gain_tbl[MAX_GAIN_TABLE_SIZE]; + u32 cfg_ae_sht_nl_tbl[MAX_SHT_NL_TABLE_SIZE]; + u32 cfg_ae_ratio_to_gain_tbl[MAX_RATIO_TO_GAIN_TABLE_SIZE]; + img_awb_param_t awb_param; + sensor_config_t sensor_config; + u32 decompand_table[DECOMP_LUT_ENTRY_NUM]; + u16 compand_table[COMP_LUT_ENTRY_NUM]; + u16 reserved; +}aeb_param_t; + +#define STATS_BLOCK_NUM_PER_CHAN (MAX_STATS_FRAME_NUM*MAX_SLICE_FOR_STAT) +#define VIN_STATS_BLOCK_NUM_PER_CHAN (MAX_EXPOSURE_NUM*STATS_BLOCK_NUM_PER_CHAN) + +typedef struct{ + struct rgb_aaa_stat rgb_stat[IMG_MAX_VIN_CHANNEL_NUM*STATS_BLOCK_NUM_PER_CHAN]; + struct cfa_aaa_stat cfa_stat[IMG_MAX_VIN_CHANNEL_NUM*STATS_BLOCK_NUM_PER_CHAN]; + u8 sensor_hist_stat[IMG_MAX_VIN_CHANNEL_NUM*SENSOR_HIST_DATA_BLOCK]; + struct vin_aaa_stat vin_stat[IMG_MAX_VIN_CHANNEL_NUM*VIN_STATS_BLOCK_NUM_PER_CHAN]; + u8 rgb_stat_valid[IMG_MAX_VIN_CHANNEL_NUM]; + u8 cfa_stat_valid[IMG_MAX_VIN_CHANNEL_NUM]; + u8 sensor_hist_valid[IMG_MAX_VIN_CHANNEL_NUM]; + u8 vin_stat_valid[IMG_MAX_VIN_CHANNEL_NUM]; +}img_stats_data_t; + +typedef struct +{ + u32 mode; + u8 meter_roi[MAX_AE_TILE_NUM]; +}ae_meter_config_t; + +typedef struct{ + u16 awb_cali_thre_r; + u16 awb_cali_thre_b; + wb_gain_t awb_cali_shift_org_gain[2]; + wb_gain_t awb_cali_shift_ref_gain[2]; +}awb_cali_info_t; + +typedef struct{ + int ae_enable; + ae_meter_config_t ae_meter_cfg; + ae_lines_config_t ae_lines_cfg; + u8 ae_speed_level; + u8 ae_auto_knee; + u16 ae_target_ratio; +}api_ae_stuff_t; + +typedef struct{ + api_ae_stuff_t api_ae_stuff; + u32 pre_init_agc_index; + u32 pre_init_shutter_row; + u32 pre_init_iris_index; + u32 pre_init_dgain; +}ae_config_t; + +typedef struct{ + int awb_enable; + awb_environment_t awb_env; + awb_control_mode_t awb_mode; + awb_work_method_t awb_method; + awb_failure_remedy_t awb_failure_remedy; + int awb_speed; + wb_gain_t cus_gain; + awb_cali_info_t awb_cali_info; +}api_awb_stuff_t; + +typedef struct{ + api_awb_stuff_t api_awb_stuff; + wb_gain_t awb_pre_init_point; + u32 awb_pre_ratio; +}awb_config_t; + +typedef struct{ + u8 wb_r_ratio; + u8 wb_b_ratio; + u8 reserved[2]; +}wb_ratio_t; +typedef struct{ + int adj_enable; + img_color_style rgb2yuv_style; + image_property_t img_property; + sharpen_property_t sharpen_property; + mctf_property_t mctf_property; + ce_input_cntl_t input_table_cntl; + ce_output_cntl_t output_table_cntl; + ce_boost_cntl_t boost_table_cntl; + int bw_mode; + int shp_str_level; + int mctf_str_level; + wb_ratio_t wb_ratio; +}api_adj_stuff_t; + + +#define UPDATE_ALL_VIN_CHANS (0xFFFF) +#define UPDATE_VIN_CHAN_INDEX(index) (1<<index)//index =0~(vin channel max-1) +#define NO_EXTRA_LIMITATION (0xffffffff) +#ifdef __cplusplus +} +#endif +#endif + + diff --git a/include/ambarella/arch_v5/stereo.h b/include/ambarella/arch_v5/stereo.h new file mode 100644 index 0000000..354df14 --- /dev/null +++ b/include/ambarella/arch_v5/stereo.h @@ -0,0 +1,124 @@ +/* + * stereo.h + * + * History: + * 2018/09/17 - [Xu Liang] created file + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __STEREO_H__ +#define __STEREO_H__ + +/*! @file stereo.h + * @brief This file defines stereo message type. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +/*! @addtogroup stereo-helper + * @{ + */ +/*! @macros MAX_OBJECT_NUMBER + * @brief define max object detection number. + */ +#define MAX_OBJECT_NUMBER (32) + +/*! @macros BBOX_POINT_NUMBER + * @brief define 3d BBOX point number. + */ +#define BBOX_POINT_NUMBER (8) + +/*! @macros SPU_OUTPUT_SERVER + * @brief define spu socket server. + */ +#define SPU_OUTPUT_SERVER "/tmp/spu_output.server" +/*! @} */ /* End of stereo-helper */ + +/*! @addtogroup stereo-struct + * @{ + */ +typedef struct pinhole_camera_t { + uint32_t id; /*!< input number into arm vo task. */ + uint32_t width; /*!< image width */ + uint32_t height; /*!< image height */ + float ku; /*!< horizontal scale factor [px] */ + float kv; /*!< vertical scale factor [px] */ + float u0; /*!< x coord of principal point [px] */ + float v0; /*!< y coord of principal point [px] */ + float baseline; /*!< baseline for stereo views, 0.0f for monocular [m] */ + float camera_to_body_orientation[4]; /*!< a quaternion representing the camera orientation expressed in the body reference system */ + float camera_to_body_position[3]; /*!< a vector representing the camera position expressed in the body reference system [m] */ +} pinhole_camera_t; + +typedef struct visual_point2d_s { + uint16_t u; /*!< x coordinate */ + uint16_t v; /*!< y coordinate */ +} visual_point2d_t; + +typedef struct visual_object_s { + uint32_t object_id; /*!< object id */ + visual_point2d_t bbox[BBOX_POINT_NUMBER]; /*!< coordinate[pixel] */ + uint16_t width; /*!< object width[cm] */ + uint16_t height; /*!< object height[cm] */ + uint16_t depth; /*!< object depth[cm] */ + uint16_t distance; /*!< object distance[cm] */ + uint16_t distance_from_gnd; /*!< object distance from ground[cm] */ + uint16_t is_positive; /*!< 1-true, 0-false */ +} visual_object_t; + +typedef struct visual_format_s { + uint32_t object_cnt; /*!< object number */ + pinhole_camera_t pinhole_camera; /*!< pinhole camera information*/ + visual_object_t visual_object[MAX_OBJECT_NUMBER]; /*!< object information */ +} visual_format_t; + +typedef struct dsi_info_s { + uint32_t img_width; /*!< dsi width */ + uint32_t img_pitch; /*!< dsi pitch */ + uint32_t img_height; /*!< dsi height */ + uint32_t dsi_offset; /*!< dsi offset */ +} dsi_info_t; + +typedef struct spu_output_msg_s { + dsi_info_t dsi_info; /*!< dsi information */ + visual_format_t visual_format; /*!< visual format */ + dsi_info_t msb_stream_info; /*!< MSB5p3 stream info */ + dsi_info_t lsb_stream_info; /*!< LSB5p3 stream info */ + dsi_info_t stream_me1_info; /*!< me1 info for above two streams */ + dsi_info_t stream_me0_info; /*!< me0 info for above two streams */ +} spu_output_msg_t; + +/*! @} */ /* End of stereo-struct */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/arch_v5/vp_config.h b/include/ambarella/arch_v5/vp_config.h new file mode 100644 index 0000000..51b5029 --- /dev/null +++ b/include/ambarella/arch_v5/vp_config.h @@ -0,0 +1,127 @@ +/* + * vp_config.h + * + * History: + * 2017/12/27 - [Hao Qian] created file + * + * Copyright (c) 2017 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __VP_CONFIG_H__ +#define __VP_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define SERVER_NAME "/tmp/vp_cfg.server" + +enum IPC_MSG_TYPE { + IPC_MSG_TYPE_SESSION = 0, + IPC_MSG_TYPE_NOTICE = 1, + IPC_MSG_TYPE_REQUEST = 2, + IPC_MSG_TYPE_REPORT = 3, +}; + +enum IPC_SESSION_CMD { + IPC_SESS_CMD_CONNECT = 0, + IPC_SESS_CMD_DISCONNECT = 1, + IPC_SESS_CMD_NUM, + IPC_SESS_CMD_FIRST = IPC_SESS_CMD_CONNECT, + NIPC_SESS_CMD_LAST = IPC_SESS_CMD_NUM, +}; + +enum IPC_NOTICE_SYS { + IPC_NOTICE_SYS_VP_START = 0, + IPC_NOTICE_SYS_VP_STOP = 1, + IPC_NOTICE_SYS_NUM, + IPC_NOTICE_SYS_FIRST = IPC_NOTICE_SYS_VP_START, + IPC_NOTICE_SYS_LAST = IPC_NOTICE_SYS_NUM, +}; + +enum NL_REQUEST_VP_INFO { + IPC_REQ_VP_START_WITH_ALGO = 0, + IPC_REQ_VP_STATUS = 1, + IPC_REQ_VP_RESULT = 2, + IPC_REQ_IMG_NUM, + IPC_REQ_IMG_FIRST = IPC_REQ_VP_START_WITH_ALGO, + IPC_REQ_IMG_LAST = IPC_REQ_IMG_NUM, +}; + +enum IPC_REPORT_VP_INFO { + IPC_RPT_IAV_VP_ALGO_REQUIREMENT = 1, + IPC_RPT_IAV_NUM, + IPC_RPT_IAV_FIRST = IPC_RPT_IAV_VP_ALGO_REQUIREMENT, + IPC_RPT_IAV_LAST = IPC_RPT_IAV_NUM, +}; + +enum IPC_CMD_STATUS { + IPC_CMD_STATUS_SUCCESS = 0, + IPC_CMD_STATUS_FAIL = 1, +}; + +enum IPC_MSG_DIR { + IPC_MSG_DIR_CMD = 0, + IPC_MSG_DIR_STATUS = 1, +}; + +enum VP_ALGO_ID { + VP_ALGO_MTCNN = 0, + VP_ALGO_YOLO = 1, + VP_ALGO_NUM, + VP_ALGO_FIRST = VP_ALGO_MTCNN, + VP_ALGO_LAST = VP_ALGO_NUM, +}; + +typedef struct vp_algo_env_s { + u32 algo_id; + u32 pyrmd1_width; + u32 pyrmd1_height; + u32 pyrmd2_width; + u32 pyrmd2_height; + /* TODO: Remove following lines if they are fixed address */ + u32 vp_cmd_addr; + u32 vp_cmd_size; + u32 vp_msg_addr; +} vp_algo_env_t; + +#define IPC_MSG_SIZE (128) +#define IPC_MSG_HEADER_SIZE (16) +#define IPC_MSG_PAYLOAD_SIZE (IPC_MSG_SIZE - IPC_MSG_HEADER_SIZE) + +typedef struct ipc_msg_s { + u32 type; + u32 dir; + u32 cmd; + u32 status; + u8 payload[IPC_MSG_PAYLOAD_SIZE]; +} ipc_msg_t; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/include/ambarella/basetypes.h b/include/ambarella/basetypes.h new file mode 100644 index 0000000..649abee --- /dev/null +++ b/include/ambarella/basetypes.h @@ -0,0 +1,191 @@ +/* + * basetypes.h + * + * Histroy: + * 2012-12-12 [Louis] Created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef _BASE_TYPES_H_ +#define _BASE_TYPES_H_ + +/*! @file basetypes.h + * @brief This file defines basic types used in all IAV driver and header files + */ +#ifdef __cplusplus +extern "C" { +#endif + +/*! @addtogroup iav-basetype + * @{ + */ + +/*! + * @defgroup iav-typedef IAV Typedef + * @{ + */ +typedef unsigned char u8; /*!< UNSIGNED 8-bit data type */ +typedef unsigned short u16; /*!< UNSIGNED 16-bit data type */ +typedef unsigned int u32; /*!< UNSIGNED 32-bit data type */ +typedef unsigned long long u64; /*!< UNSIGNED 64-bit data type */ +typedef signed char s8; /*!< SIGNED 8-bit data type */ +typedef signed short s16; /*!< SIGNED 16-bit data type */ +typedef signed int s32; /*!< SIGNED 32-bit data type */ +typedef signed long long s64; /*!< SIGNED 64-bit data type */ +/*! @} */ + +/*! + * @defgroup iav-define IAV Macros + * @breif All IAV Macros Definition + * @{ + */ +/*! + * @defgroup iav-define-common IAV Common Macros + * @brief Common IAV Macros + * @{ + */ +/*! @macros AMBA_API + * @brief API function attribute */ +#define AMBA_API __attribute__((visibility("default"))) + +/*! @macros ARRAY_SIZE + * @breif Helper macro to calculate array size */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif +/*! @} */ /* End of iav-define-common */ + +/*! @} */ /* End of iav-define */ + +/* ==========================================================================*/ + +/*! + * @defgroup iav-structure IAV Data Structures + * @ingroup iav-structure-common + * @brief Common IAV Data Structure + * @{ + */ +/*! @struct iav_window + * @brief IAV Window Size + */ +struct iav_window { + u32 width; //!< Window width + u32 height; //!< Window height +}; + +/*! @struct iav_offset + * @brief IAV Window Starting Point + */ +struct iav_offset { + u32 x; //!< Offset X + u32 y; //!< Offset Y +}; + +/*! @struct iav_rect + * @brief IAV rectangle + */ +struct iav_rect { + u32 x; //!< Offset X + u32 y; //!< Offset Y + u32 width; //!< Width + u32 height; //!< Height +}; +/* @} */ + +/*! + * @ingroup iav-define-common + * @{ + */ + +/*! @macros rect_init(_x, _y, _w, _h) + * @brief struct @sa iav_rect init macro + */ +#define rect_init(_x, _y, _w, _h)( \ +{ \ + struct iav_rect _r; \ + _r.x = (_x); _r.y = (_y); _r.width = (_w); _r.height = (_h); \ + _r; \ +}) + +/*! @macros win_init(w, h) + * @brief @sa rect_init(_x, _y, _w, _h) + */ +#define win_init(w, h) rect_init(0, 0, w, h) + +/*! @macros win_invalid(w) + * @sa iav_window + */ +#define win_invalid(w) ((w).width == 0 || (w).height == 0) + +/*! @macros rect_invalid(w) + * @sa iav_rect + */ +#define rect_invalid(w) (win_invalid(w) || (w).x > 0xffff || (w).y > 0xffff) + +/*! return 1 if r1 contains r2 */ +#define rect_contain(r1, r2) ({ \ + u32 _x1 = (r1).x, _y1 = (r1).y, _w1 = (r1).width, _h1 = (r1).height; \ + u32 _x2 = (r2).x, _y2 = (r2).y, _w2 = (r2).width, _h2 = (r2).height; \ + _x1 <= _x2 && (_x1 + _w1) >= (_x2 + _w2) && \ + _y1 <= _y2 && (_y1 + _h1) >= (_y2 + _h2) ? 1 : 0; \ + }) +/*! @} */ + +/* ==========================================================================*/ + +/*! + * @defgroup IAV Helper Function + * @brief IAV Helper Functions + * @{ + */ +/*! Helper function to set a perticular bit + * @param bit_map Pointer to an actual bitmap to be set + * @param nr The bit number, which will be set + */ +static inline void iav_set_bit(u32 *bit_map, int nr) +{ + *bit_map |= (1 << nr); +} + +/*! Helper function to test if a perticular bit is set + * @param bit_map Pointer to an actual bitmap to be tested + * @param nr The bit number, which will be tested + */ +static inline int iav_test_bit(u32 *bit_map, int nr) +{ + return !!((*bit_map) & (1 << nr)); +} +/* @} */ + +/* ==========================================================================*/ +/* @} */ /* IAV API */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/cavalry/cavalry_gen.h b/include/ambarella/cavalry/cavalry_gen.h new file mode 100644 index 0000000..c6d5153 --- /dev/null +++ b/include/ambarella/cavalry/cavalry_gen.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2018-2018 Ambarella, Inc. + * 2018/08/17 - [Monica Yang] created file + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign copyrights. + * This Software is also the confidential and proprietary information of + * Ambarella, Inc. and its licensors. You may not use, reproduce, disclose, + * distribute, modify, or otherwise prepare derivative works of this Software + * or any portion thereof except pursuant to a signed license agreement or + * nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and + * return this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; + * 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. + */ + +#ifndef __CAVALRY_GEN_H__ +#define __CAVALRY_GEN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#define CAVALRY_GEN_VERSION (0x02010007) +#define CAVALRY_FILENAME_MAX (128) +#define CAVALRY_VAR_NAME_MAX (128) +#define CAVALRY_IO_NAME_MAX (512) +#define CAVALRY_IO_DEMNGL_NAME_MAX (512) +#define CAVALRY_IO_PARENT_NAME_MAX (64) +#define CAVALRY_VPROC_VAR_NAME_MAX (32) +#define CAVALRY_VPROC_SMB_NAME_MAX (16) +#define CAVALRY_PATH_MAX (2048) +#define CAVALRY_LINE_LEN_MAX (1024) + +/* cavalry_gen will set invalid value if not found data_format */ +typedef enum datasize_type_s { + DATASIZE_8_BITS = 0, + DATASIZE_16_BITS = 1, + DATASIZE_32_BITS = 2, + DATASIZE_64_BITS = 3, + DATASIZE_INVALID = 0xFF, +} datasize_type_t; + +/* header info */ +typedef struct cavalry_gen_header_s { + uint32_t version_info; + uint32_t version_hash; + uint32_t dvi_num; +} cavalry_gen_header_t; + +/*per dvi descriptor */ +typedef struct dvi_desc_s { + uint8_t dvi_id; + uint8_t vproc_id; + uint8_t dvi_ppv; + uint8_t reserve_dvi; + uint32_t dvi_img_vaddr; + uint32_t dvi_img_size; + uint32_t dvi_dag_vaddr; + uint32_t input_num; + uint32_t output_num; + uint32_t dvi_pkg_size; + char dag_name[CAVALRY_VAR_NAME_MAX]; +} dvi_desc_t; + +/*per port descriptor (HMB_input HMB_output) */ +typedef struct io_descriptor_s{ + uint32_t port_dim_p; + uint32_t port_dim_d; + uint32_t port_dim_h; + uint32_t port_dim_w; + uint32_t port_pitch; /* dpitch_num_bytes */ + uint32_t port_pitch_offset; + uint32_t port_pitch_bsize: 6; + uint32_t port_dram_format: 4; + uint32_t port_dim_bitvector: 1; + uint32_t port_drotate: 1; + uint32_t port_hflip: 1; + uint32_t port_vflip: 1; + uint32_t port_dflip: 1; + uint32_t port_pflip: 1; + uint32_t reserve_port: 7; + uint32_t port_slice_total_num : 4; + uint32_t port_slice_seq : 4; + uint32_t port_is_main_io: 1; + uint32_t port_slice_byte_offset; + char port_slice_parent_name[CAVALRY_IO_PARENT_NAME_MAX]; + + uint32_t port_drotate_bit_offset; + uint32_t port_hflip_bit_offset; + uint32_t port_vflip_bit_offset; + uint32_t port_dflip_bit_offset; + uint32_t port_pflip_bit_offset; + + uint8_t port_data_sign; /*data format: sign, datasize, expoffset, expbits*/ + uint8_t port_data_size; + int8_t port_data_expoffset; + uint8_t port_data_expbits; + + uint32_t port_size; + uint32_t port_byte_offset; /* dbase_byte_offset */ + char port_name[CAVALRY_IO_NAME_MAX]; + char port_demangled_name[CAVALRY_IO_DEMNGL_NAME_MAX]; +} io_descriptor_t; + +/* vproc descriptors */ +typedef struct vproc_desc_s { + uint32_t var_num; + uint32_t smb_num; + uint32_t vproc_pkg_size; +}vproc_desc_t; + +/* functional parameters */ +typedef struct func_variable_s{ + char var_name[CAVALRY_VPROC_VAR_NAME_MAX]; + uint32_t var_boffset; + uint32_t var_bsize; +} func_variable_t; + +/* SMB descriptor */ +typedef struct smb_descriptor_s{ + char smb_name[CAVALRY_VPROC_SMB_NAME_MAX]; + uint32_t vbase_byte_offset; +} smb_descriptor_t; + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/cavalry/cavalry_ioctl.h b/include/ambarella/cavalry/cavalry_ioctl.h new file mode 100644 index 0000000..1cef4f8 --- /dev/null +++ b/include/ambarella/cavalry/cavalry_ioctl.h @@ -0,0 +1,388 @@ +/* + * Copyright (c) 2018-2018 Ambarella, Inc. + * 2018/06/01 - [Zhikan Yang] created file + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign copyrights. + * This Software is also the confidential and proprietary information of + * Ambarella, Inc. and its licensors. You may not use, reproduce, disclose, + * distribute, modify, or otherwise prepare derivative works of this Software + * or any portion thereof except pursuant to a signed license agreement or + * nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and + * return this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; + * 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. + */ + +#ifndef __CAVALRY_IOCTL_H__ +#define __CAVALRY_IOCTL_H__ + +#include <linux/ioctl.h> + +#define CAVALRY_DEV_NODE "/dev/cavalry" + +#define MAX_PORT_CNT (128) +#define MAX_POKE_CNT (64) +#define MAX_DAG_CNT (256) + +#define VERSION_INFO_OFFSET (0x40) + +#define CAVALRY_SLOT_ID_OFFSET (0x04) + +#define CAVALRY_HARRIS_H_BLOCKS (8) +#define CAVALRY_HARRIS_V_BLOCKS (8) +#define CAVALRY_HARRIS_MAX_POINTS_PER_BLOCK (32) + +#define FEX_MIN_NMS_WINDOW (1) +#define FEX_MAX_NMS_WINDOW (8) + +typedef enum { + CHIP_TYPE_CV22 = 0, + CHIP_TYPE_CV2 = 1, + CHIP_TYPE_CV25 = 2, +} chip_type_t; + +typedef enum { + CAVALRY_LOG_LEVEL_SILENT = 0, + CAVALRY_LOG_LEVEL_MINIMAL, + CAVALRY_LOG_LEVEL_NORMAL, + CAVALRY_LOG_LEVEL_VERBOSE, + CAVALRY_LOG_LEVEL_DEBUG, + CAVALRY_LOG_LEVEL_NUM, + CAVALRY_LOG_LEVEL_FIRST = CAVALRY_LOG_LEVEL_SILENT, + CAVALRY_LOG_LEVEL_LAST = CAVALRY_LOG_LEVEL_DEBUG, +} cavalry_log_level_t; + +struct cavalry_set_log_level { + cavalry_log_level_t log_level; + uint32_t rval; +}; + +struct version_info_s { + uint32_t chip; + uint32_t ucode_version; + uint32_t build_date; + uint32_t git_hash; + uint32_t hotlink_fw_version; +}; + +typedef enum { + CAVALRY_MEM_ALL = 0x00, + CAVALRY_MEM_CMD = 0x01, + CAVALRY_MEM_MSG = 0x02, + CAVALRY_MEM_LOG = 0x03, + CAVALRY_MEM_CMD_FEX = 0x04, + CAVALRY_MEM_MSG_FEX = 0x05, + CAVALRY_MEM_CMD_FMA = 0x06, + CAVALRY_MEM_MSG_FMA = 0x07, + CAVALRY_MEM_UCODE = 0x08, + CAVALRY_MEM_HOTLINK_SLOT0 = 0x09, + CAVALRY_MEM_HOTLINK_SLOT1 = 0x0A, + CAVALRY_MEM_HOTLINK_SLOT2 = 0x0B, + CAVALRY_MEM_HOTLINK_SLOT3 = 0x0C, + CAVALRY_MEM_USER = 0x0D, + CAVALRY_MEM_NUM = 0x0E, + CAVALRY_MEM_FIRST = CAVALRY_MEM_ALL, + CAVALRY_MEM_LAST = CAVALRY_MEM_USER, +} CAVALRY_MEM; + +struct cavalry_log_entry { + uint32_t seq_num; + uint8_t thread_id; + uint8_t slot_id; + uint8_t reserved[2]; + uint32_t format_offset; + uint32_t arg1; + uint32_t arg2; + uint32_t arg3; + uint32_t arg4; + uint32_t arg5; +}; + +struct cavalry_querybuf { + CAVALRY_MEM buf; + unsigned long length; + unsigned long offset; +}; + +struct cavalry_port_desc { + uint32_t port_dram_addr; + uint32_t port_boffset_in_dag; + uint32_t port_bsize; + uint32_t port_daddr_increment; +}; + +struct cavalry_poke_desc { + uint32_t poke_val; + uint32_t poke_vaddr; + uint32_t poke_bsize; +}; + +struct cavalry_dag_desc { + uint32_t dvi_mode : 1; + uint32_t use_ping_pong_vmem : 1; + uint32_t reserved : 14; + uint32_t dag_loop_cnt : 16; + uint32_t dvi_dram_addr; + uint32_t dvi_img_vaddr; + uint32_t dvi_img_size; + uint32_t dvi_dag_vaddr; + + uint32_t reserved1[4]; + + uint32_t port_cnt; + uint32_t poke_cnt; + struct cavalry_port_desc port_desc[MAX_PORT_CNT]; + struct cavalry_poke_desc poke_desc[MAX_POKE_CNT]; +}; + +typedef enum { + MSG_RVAL_NONE, + MSG_RVAL_INVALID_CMD, + MSG_RVAL_INVALID_DAGCNT, + MSG_RVAL_INVALID_DAGDESC, + MSG_RVAL_INVALID_SLOT_ID, + MSG_RVAL_FEX_INSUFFICIENT_DRAM, + MSG_RVAL_FMA_INSUFFICIENT_DRAM, + MSG_RVAL_VP_RESERVED_VMEM_TRASHED, +} cavalry_msg_rval_t; + +typedef enum { + HOTLINK_SLOT_0 = 0, + HOTLINK_SLOT_1 = 1, + HOTLINK_SLOT_2 = 2, + HOTLINK_SLOT_3 = 3, + HOTLINK_SLOT_NUM = 4, + HOTLINK_SLOT_FIRST = HOTLINK_SLOT_0, + HOTLINK_SLOT_LAST = HOTLINK_SLOT_3, + HOTLINK_SLOT_CAVALRY_FRAMEWORK = 0xFF, +} hotlink_slot_t; + +typedef enum { + CAVALRY_FMA_MODE_TEMPORAL = 0, + CAVALRY_FMA_MODE_STEREO, + CAVALRY_FMA_MODE_NUM, + CAVALRY_FMA_MODE_FIRST = CAVALRY_FMA_MODE_TEMPORAL, + CAVALRY_FMA_MODE_LAST = CAVALRY_FMA_MODE_STEREO, +} cavalry_fma_mode_t; + +struct cavalry_run_dags { + uint32_t rval; + uint32_t start_tick; + uint32_t end_tick; + uint32_t finish_dags; + uint32_t dag_cnt; + struct cavalry_dag_desc dag_desc[MAX_DAG_CNT]; +}; + +struct cavalry_early_quit { + uint32_t early_quit_all : 1; + uint32_t reserved : 31; +}; + +struct cavalry_mem { + uint32_t cache_en : 1; /* 0: nocached; 1: cached */ + uint32_t reserved : 31; + + unsigned long length; /* as input: the mem part size to be allocated + as return: the real size of the allocated mem part */ + unsigned long offset; /* the physical address of the allocated mem part */ +}; + +struct cavalry_cache_mem { + uint32_t clean : 1; /* do after arm write: cache -> dram */ + uint32_t invalid : 1; /* do before arm read: dram -> cache */ + uint32_t reserved : 30; + + unsigned long length; + + unsigned long offset; /* the physical address of the allocated mem part */ +}; + +struct cavalry_usage_mem { + unsigned long used_length; + unsigned long free_length; +}; + +struct cavalry_run_hotlink_slot { + uint8_t slot_id; + uint8_t reserved0[3]; + uint32_t arg_daddr; + uint32_t slot_rval; + uint32_t start_tick; + uint32_t end_tick; +}; + +struct cavalry_fex_query { + /* Input */ + uint16_t img_width; + uint16_t img_height; + uint16_t img_pitch; + uint16_t harris_en : 2; + uint16_t stereo_en : 1; + uint16_t dump_harris_score : 1; + uint16_t reserved1 : 12; + /* Output */ + uint32_t dram_required; +}; + +typedef enum { + FEX_CFG_MASK_NMS_THRESHOLD = (1 << 0), + FEX_CFG_MASK_NMS_WINDOW_FOR_HARRIS = (1 << 1), + FEX_CFG_MASK_ALL = FEX_CFG_MASK_NMS_THRESHOLD | FEX_CFG_MASK_NMS_WINDOW_FOR_HARRIS, +} fex_cfg_mask_t; + +struct fex_user_cfg { + uint32_t cfg_mask; + uint16_t nms_threshold; + uint16_t nms_window_for_harris : 4; + uint16_t reserved2 : 12; +}; + +typedef enum { + STEREO_PROFILE_DEFAULT = 0, + STEREO_PROFILE_1, + STEREO_PROFILE_NUM, +} stereo_profile_t; + +struct cavalry_fex_run { + /* Input */ + uint16_t img_width; + uint16_t img_height; + uint16_t img_pitch; + uint16_t harris_en : 2; + uint16_t stereo_en : 1; + uint16_t stereo_profile : 5; + uint16_t dump_harris_score : 1; + uint16_t reserved1 : 7; + struct fex_user_cfg fex_cfg; + uint32_t output_daddr; + uint32_t output_size; + uint32_t luma_daddr[2]; + + /* Output */ + uint32_t rval; + uint32_t disparity_daddr; + uint32_t disparity_size; + uint32_t invalid_disparities; + uint16_t disparity_width; + uint16_t disparity_height; + uint16_t disparity_pitch; + uint16_t reserved2; + uint32_t harris_count_daddr[2]; + uint32_t harris_count_size[2]; + uint32_t harris_point_daddr[2]; + uint32_t harris_point_size[2]; + uint32_t brief_descriptor_daddr[2]; + uint32_t brief_descriptor_size[2]; + uint32_t start_tick; + uint32_t end_tick; +}; + +struct cavalry_fma_query { + /* Output */ + uint32_t dram_required; +}; + +typedef enum { + FMA_CFG_MASK_MIN_THRESHOLD = (1 << 0), + FMA_CFG_MASK_RATIO_THRESHOLD = (1 << 1), + FMA_CFG_MASK_WIN_WIDTH = (1 << 2), + FMA_CFG_MASK_WIN_HEIGHT = (1 << 3), + FMA_CFG_MASK_X_THRESHOLD_R = (1 << 4), + FMA_CFG_MASK_X_THRESHOLD_L = (1 << 5), + FMA_CFG_MASK_Y_THRESHOLD_U = (1 << 6), + FMA_CFG_MASK_Y_THRESHOLD_D = (1 << 7), + FMA_CFG_MASK_ALL = FMA_CFG_MASK_MIN_THRESHOLD | FMA_CFG_MASK_RATIO_THRESHOLD | + FMA_CFG_MASK_WIN_WIDTH | FMA_CFG_MASK_WIN_HEIGHT | + FMA_CFG_MASK_X_THRESHOLD_R | FMA_CFG_MASK_X_THRESHOLD_L | + FMA_CFG_MASK_Y_THRESHOLD_U | FMA_CFG_MASK_Y_THRESHOLD_D, +} fma_cfg_mask_t; + +struct fma_user_cfg { + uint32_t cfg_mask; + uint32_t min_threshold; + + uint16_t ratio_threshold; + uint16_t reserved; + + uint16_t win_width; + uint16_t win_height; + + uint16_t x_threshold_r; + uint16_t x_threshold_l; + uint16_t y_threshold_u; + uint16_t y_threshold_d; +}; + +struct cavalry_fma_run { + /* Input */ + uint32_t output_daddr; + uint32_t output_size; + uint32_t target_coord_daddr; + uint32_t target_descriptor_daddr; + uint32_t reference_coord_daddr; + uint32_t reference_descriptor_daddr; + uint32_t mode : 1; // 0 for temporal, 1 for stereo + uint32_t reserved1 : 31; + struct fma_user_cfg stereo_cfg; + struct fma_user_cfg temporal_cfg; + + /* Output */ + uint32_t rval; + uint32_t result_score_daddr; + uint32_t result_score_size; + uint32_t result_index_daddr; + uint32_t result_index_size; + uint32_t temporal_coord_daddr; + uint32_t temporal_coord_size; + uint32_t start_tick; + uint32_t end_tick; +}; + +struct cavalry_stats_get { + uint32_t is_vp_idle : 1; + uint32_t reserved : 31; + int vp_current_pid; +}; + +#define CAVALRY_QUERY_BUF _IOWR ('C', 0x0, struct cavalry_querybuf *) +#define CAVALRY_START_VP _IOWR ('C', 0x1, void *) +#define CAVALRY_STOP_VP _IOWR ('C', 0x2, void *) +#define CAVALRY_RUN_DAGS _IOWR ('C', 0x3, struct cavalry_run_dags *) +#define CAVALRY_START_LOG _IOWR ('C', 0x4, void *) +#define CAVALRY_STOP_LOG _IOWR ('C', 0x5, void *) +#define CAVALRY_EARLY_QUIT _IOWR ('C', 0x6, struct cavalry_early_quit *) + +/* cv user memory ioctl */ +#define CAVALRY_ALLOC_MEM _IOWR ('C', 0x7, struct cavalry_mem *) +#define CAVALRY_FREE_MEM _IOWR ('C', 0x8, struct cavalry_mem *) +#define CAVALRY_SYNC_CACHE_MEM _IOWR ('C', 0x9, struct cavalry_cache_mem *) +#define CAVALRY_GET_USAGE_MEM _IOWR ('C', 0xA, struct cavalry_usage_mem *) + +#define CAVALRY_RUN_HOTLINK_SLOT _IOWR ('C', 0xB, struct cavalry_run_hotlink_slot *) +#define CAVALRY_SET_HOTLINK_SLOT_CFG _IOWR ('C', 0xC, uint32_t *) +#define CAVALRY_GET_HOTLINK_SLOT_CFG _IOWR ('C', 0xD, uint32_t *) + +#define CAVALRY_FEX_QUERY _IOWR ('C', 0xE, struct cavalry_fex_query *) +#define CAVALRY_FEX_RUN _IOWR ('C', 0xF, struct cavalry_fex_run *) + +#define CAVALRY_FMA_QUERY _IOWR ('C', 0x10, struct cavalry_fma_query *) +#define CAVALRY_FMA_RUN _IOWR ('C', 0x11, struct cavalry_fma_run *) + +#define CAVALRY_SET_LOG_LEVEL _IOWR ('C', 0x12, struct cavalry_set_log_level *) + +#define CAVALRY_GET_STATS _IOWR ('C', 0x13, struct cavalry_stats_get *) + +#endif //__CAVALRY_IOCTL_H__ diff --git a/include/ambarella/cavalry_mem.h b/include/ambarella/cavalry_mem.h new file mode 100644 index 0000000..b8a253f --- /dev/null +++ b/include/ambarella/cavalry_mem.h @@ -0,0 +1,91 @@ +/******************************************************************************* + * cavalry_mem.h + * + * History: + * 2018/09/18 - [Tao Wu] created for CV22 + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise iproare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#ifndef _CAVALRY_MEM_H_ +#define _CAVALRY_MEM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef IN +#define IN +#endif + +#ifndef OUT +#define OUT +#endif + +#ifndef INOUT +#define INOUT +#endif + +struct cavalry_mem_version { + uint32_t major; + uint32_t minor; + uint32_t patch; + unsigned int mod_time; + char description[64]; +}; + +#ifndef AMBA_API +#define AMBA_API __attribute__((visibility("default"))) +#endif + + +/* Library API */ +AMBA_API int cavalry_mem_init(IN int fd_cav, IN uint8_t verbose); +AMBA_API int cavalry_mem_get_version(struct cavalry_mem_version *ver); +AMBA_API void cavalry_mem_exit(void); + + +/* Memory API */ +AMBA_API int cavalry_mem_alloc(INOUT unsigned long *psize, + OUT unsigned long *pphys, OUT void **pvirt, IN uint8_t cache_en, IN uint8_t auto_recycle); //auto_recycle +AMBA_API int cavalry_mem_free(IN unsigned long size, + IN unsigned long phys, IN void *virt); + + +/* cavalry_mem_sync_cache: + * clean: do after arm write (cache -> dram) + * invalid: do before arm read (dram -> cache) */ +AMBA_API int cavalry_mem_sync_cache( + IN unsigned long size, IN unsigned long phys, + IN uint8_t clean, IN uint8_t invalid); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/cryptochip_ioctl.h b/include/ambarella/cryptochip_ioctl.h new file mode 100644 index 0000000..cf7b81f --- /dev/null +++ b/include/ambarella/cryptochip_ioctl.h @@ -0,0 +1,429 @@ +/** + * cryptochip_ioctl.h + * + * History: + * 2015/06/04 - [Zhi He] Created file + * + * Copyright (c) 2015 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + */ + +#ifndef __CRYPTOCHIP_IOCTL_H__ +#define __CRYPTOCHIP_IOCTL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <linux/ioctl.h> + +#define CRYPTOCHIP_MAGIC 'C' + +#define CRYPTOCHIP_IO(nr) _IO(CRYPTOCHIP_MAGIC, nr) +#define CRYPTOCHIP_IOR(nr, size) _IOR(CRYPTOCHIP_MAGIC, nr, size) +#define CRYPTOCHIP_IOW(nr, size) _IOW(CRYPTOCHIP_MAGIC, nr, size) +#define CRYPTOCHIP_IOWR(nr, size) _IOWR(CRYPTOCHIP_MAGIC, nr, size) + +#define DCC_INIT_DEFAULT_I2C_ADDRESS 0xc8 +#define DCC_INIT_OTP_MODE_READ_ONLY 0xaa +#define DCC_INIT_OTP_MODE_CONSUMPTION 0x55 +#define DCC_INIT_OTP_MODE_LEGACY 0x00 +#define DCC_INIT_DEFAULT_EXPERIMENTAL_CHECK_MAC_CONFIG 0x81 +#define DCC_INIT_DEFAULT_CHECK_MAC_CONFIG 0x00 +#define DCC_INIT_DEFAULT_SELECTOR_MODE 0x00 + +#define DCC_INIT_SLOT_CONFIG1_READ_SLOT_MASK 0x0f +#define DCC_INIT_SLOT_CONFIG1_CHECK_ONLY_BIT 0x10 +#define DCC_INIT_SLOT_CONFIG1_SINGLE_USE_BIT 0x20 +#define DCC_INIT_SLOT_CONFIG1_ENCRYPT_READ_BIT 0x40 +#define DCC_INIT_SLOT_CONFIG1_IS_SECRET_BIT 0x80 + +#define DCC_INIT_SLOT_CONFIG2_WRITE_SLOT_MASK 0x0f +#define DCC_INIT_SLOT_CONFIG2_ENCRYPT_WRITE_BIT 0x40 +#define DCC_INIT_SLOT_CONFIG2_NON_WRITE_FLAG 0x80 + +#define DCC_DATA_SLOT_LENGTH 32 +#define DCC_CONFIG_ZONE_PROGRAM_OFFSET 16 + +#define DCC_MODE_FALG_SN_23_47 (1 << 6) +#define DCC_MODE_FALG_OPT_64 (1 << 5) +#define DCC_MODE_FALG_OPT_88 (1 << 4) +#define DCC_MODE_FALG_TEMPKEY_SOURCE_FLAG (1 << 2) +#define DCC_MODE_FALG_TEMPKEY_OR_DATA_SLOT (1 << 1) +#define DCC_MODE_FALG_TEMPKEY_OR_CHALLENGE (1 << 0) + +#define DCC_RANDOM_MODE_UPDATE_SEED 0x00 +#define DCC_RANDOM_MODE_NOT_UPDATE_SEED 0x01 +#define DCC_NOUCE_MODE_PASS_THROUGH 0x03 + +#define DCC_CRYPT_BIT (1 << 6) +#define DCC_ACCESS_DATA_SLOT (1 << 7) + +typedef enum { + CRYPTOCHIP_ZONE_CONFIG = 0x00, + CRYPTOCHIP_ZONE_OTP = 0x01, + CRYPTOCHIP_ZONE_DATA = 0x02, +} CRYPTOCHIP_ZONE; + +typedef enum { + //atomic transaction + IOC_TRANSACTION_GENERATE_SIGNATURE = 0x01, + IOC_TRANSACTION_VERIFY_SIGNATURE = 0x02, + IOC_TRANSACTION_PREPARE_CRYPT_ACCESS = 0x03, + IOC_TRANSACTION_GET_SERIAL_NUMBER = 0x04, + IOC_TRANSACTION_ENCRYPT_WRITE = 0x05, + IOC_TRANSACTION_DECRYPT_READ = 0x06, + + IOC_TRANSACTION_SHOW_CONFIG_ZONE = 0x07, + IOC_TRANSACTION_SHOW_OTP_ZONE = 0x08, + IOC_TRANSACTION_SHOW_DATA_ZONE = 0x09, + + IOC_TRANSACTION_PLAINTEXT_WRITE = 0x0a, + IOC_TRANSACTION_PLAINTEXT_READ = 0x0b, + + //for factory inistialize only + IOC_TRANSACTION_WRITE_CONFIG_ZONE = 0x20, + IOC_TRANSACTION_WRITE_OTP_ZONE = 0x21, + IOC_TRANSACTION_WRITE_DATA_ZONE = 0x22, + + IOC_TRANSACTION_INITIALIZE_CONFIG_ZONE = 0x23, + IOC_TRANSACTION_INITIALIZE_OTP_AND_DATA_ZONE = 0x24, + + //debug use only + IOC_TRANSACTION_LOCK_CONFIG_ZONE = 0x30, + IOC_TRANSACTION_INITIALIZE_OTP_AND_DATA_ZONE_FORCE_LOCK = 0x31, + IOC_TRANSACTION_PREPARE_CRYPT_ACCESS_PASS_THROUGH = 0x32, + + //operation can be used to build up customized transaction + IOC_CHECK_MAC = 0x41, + IOC_DERIVE_KEY = 0x42, + IOC_DEVICE_REVISION = 0x43, + IOC_GEN_DIGEST = 0x44, + IOC_HMAC = 0x45, + IOC_MAC = 0x46, + IOC_NONCE = 0x47, + IOC_RANDOM = 0x49, + IOC_READ = 0x4a, + IOC_SHA = 0x4b, + IOC_UPDATE_EXTRA = 0x4c, + IOC_WRITE = 0x4d, + + IOC_LOCK = 0x51, + IOC_PAUSE = 0x52, + + IOC_BEGIN_TRANSACTION = 0x54, + IOC_END_TRANSACTION = 0x55, + + //utils api + IOC_SET_TIMING = 0x71, + IOC_GET_TIMING = 0x72, +} CRYPTOCHIP_IOC; + +typedef enum { + EATSHA_CMD_TAG_CHECK_MAC = 0x28, + EATSHA_CMD_TAG_DERIVE_KEY = 0x1c, + EATSHA_CMD_TAG_DEVICE_REVISION = 0x30, + EATSHA_CMD_TAG_GEN_DIGEST = 0x15, + EATSHA_CMD_TAG_HMAC = 0x11, + EATSHA_CMD_TAG_LOCK = 0x17, + EATSHA_CMD_TAG_MAC = 0x08, + EATSHA_CMD_TAG_NONCE = 0x16, + EATSHA_CMD_TAG_PAUSE = 0x01, + EATSHA_CMD_TAG_RANDOM = 0x1b, + EATSHA_CMD_TAG_READ = 0x02, + EATSHA_CMD_TAG_SHA = 0x47, + EATSHA_CMD_TAG_UPDATE_EXTRA = 0x20, + EATSHA_CMD_TAG_WRITE = 0x12, +} EATSHA_CMD_TAG; + +typedef enum { + EATSHA_RESPONCE_TAG_SUCCESS = 0x00, + EATSHA_RESPONCE_TAG_CHECKMAC_FAIL = 0x01, + EATSHA_RESPONCE_TAG_CMD_PARSE_ERROR = 0x03, + EATSHA_RESPONCE_TAG_EXECUTION_ERROR = 0x0f, + EATSHA_RESPONCE_TAG_AWAKE_NOTIFY = 0x11, + EATSHA_RESPONCE_TAG_CRC_TRANS_ERROR = 0xff, +} EATSHA_RESPONCE_TAG; + +struct cryptochip_transaction_signature { + unsigned char private_slot; + unsigned char reserved_0; + unsigned char reserved_1; + unsigned char reserved_2; + + unsigned char digest[DCC_DATA_SLOT_LENGTH]; + unsigned char sig[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_transaction_prepare_crypt_access { + //nonce + unsigned char random[DCC_DATA_SLOT_LENGTH]; + unsigned char input[32]; //in out + + //gendig + unsigned char zone; + unsigned char slot_id; + unsigned char b_pass_through; + unsigned char reserved1; + + unsigned char otherdata[4]; + + unsigned char digest_input_prefix[32]; +}; + +struct cryptochip_transaction_crypt_access { + unsigned char data_slot; + unsigned char reserved_0; + unsigned char reserved_1; + unsigned char reserved_2; + + unsigned char data[DCC_DATA_SLOT_LENGTH]; + unsigned char mac[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_transaction_plaintext_access { + unsigned char is_4bytes; + unsigned char zone; + unsigned char slot;// for 32 bytes access + unsigned char address; //for 4 bytes access + + unsigned char data[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_transaction_get_serial_number { + unsigned char serial_number[16]; +}; + +struct cryptochip_transaction_config_zone { + unsigned char config_zone[88]; +}; + +struct cryptochip_transaction_otp_zone { + unsigned char otp_zone[64]; +}; + +struct cryptochip_transaction_data_zone { + unsigned char data_zone[512]; +}; + +struct cryptochip_transaction_program_otp_and_data_zone { + unsigned char data_zone[512]; + unsigned char otp_zone[64]; +}; + +struct cryptochip_mac { + unsigned char mode; + unsigned char reserved0; + unsigned char slotid[2]; + + unsigned char challenge[DCC_DATA_SLOT_LENGTH]; + unsigned char digest[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_check_mac { + unsigned char mode; + unsigned char reserved0; + unsigned char slotid[2]; + + unsigned char challenge[DCC_DATA_SLOT_LENGTH]; + unsigned char digest[DCC_DATA_SLOT_LENGTH]; + + unsigned char otherdata[16]; // 13 bytes ared used +}; + +struct cryptochip_derive_key { + unsigned char mode; + unsigned char use_optional_data; + unsigned char target_slotid[2]; + + unsigned char optional_data[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_device_revision { + unsigned char revision[4]; +}; + +struct cryptochip_gen_digest { + unsigned char zone; + unsigned char use_other_data; + unsigned char slotid[2]; + + unsigned char other_data[4]; +}; + +struct cryptochip_hmac { + unsigned char mode; + unsigned char reserved_0; + unsigned char slotid[2]; + + unsigned char hmac_digest[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_nonce { + unsigned char random_mode; + unsigned char reserved_0; + unsigned char reserved_1; + unsigned char reserved_2; + + unsigned char in_out[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_random { + unsigned char random_mode; + unsigned char reserved_0; + unsigned char reserved_1; + unsigned char reserved_2; + + unsigned char random_out[DCC_DATA_SLOT_LENGTH]; +}; + +#define DCC_SHA_MODE_INIT 0x00 +#define DCC_SHA_MODE_COMPUTE 0x01 +struct cryptochip_sha { + unsigned char sha_mode; + unsigned char reserved_0; + unsigned char reserved_1; + unsigned char reserved_2; + + unsigned char data_input[64]; + unsigned char sha_digest[DCC_DATA_SLOT_LENGTH]; +}; + +#define DCC_UE_MODE_UPDATE_84 0x00 +#define DCC_UE_MODE_UPDATE_85 0x01 +#define DCC_UE_MODE_DECREASE 0x02 +struct cryptochip_update_extra { + unsigned char ue_mode; + unsigned char lsb; + unsigned char reserved_1; + unsigned char reserved_2; +}; + +struct cryptochip_read { + unsigned char zone; + unsigned char dec; + unsigned char address[2]; + + unsigned char data[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_write { + unsigned char zone; + unsigned char enc; + unsigned char address[2]; + + unsigned char data[DCC_DATA_SLOT_LENGTH]; + unsigned char mac[DCC_DATA_SLOT_LENGTH]; +}; + +struct cryptochip_lock { + unsigned char zone; + unsigned char reserved_0; + unsigned char summary[2]; +}; + +struct cryptochip_pause { + unsigned char selector; + unsigned char reserved_0; + unsigned char reserved_1; + unsigned char reserved_2; +}; + +struct atsha204_timing_param { + unsigned char max; + unsigned char min; + unsigned char cur; + unsigned char typical; +}; + +struct atsha204_timing { + struct atsha204_timing_param derive_key; + struct atsha204_timing_param dev_rev; + struct atsha204_timing_param gen_dig; + struct atsha204_timing_param hmac; + struct atsha204_timing_param check_mac; + struct atsha204_timing_param lock; + struct atsha204_timing_param mac; + struct atsha204_timing_param nonce; + struct atsha204_timing_param pause; + struct atsha204_timing_param random; + struct atsha204_timing_param read; + struct atsha204_timing_param sha; + struct atsha204_timing_param update_extra; + struct atsha204_timing_param write; +}; + +#define CRYPTOCHIP_IOC_TRANSACTION_GENERATE_SIGNATURE CRYPTOCHIP_IOWR(IOC_TRANSACTION_GENERATE_SIGNATURE, struct cryptochip_transaction_signature *) +#define CRYPTOCHIP_IOC_TRANSACTION_VERIFY_SIGNATURE CRYPTOCHIP_IOWR(IOC_TRANSACTION_VERIFY_SIGNATURE, struct cryptochip_transaction_signature *) +#define CRYPTOCHIP_IOC_TRANSACTION_PREPARE_CRYPT_ACCESS CRYPTOCHIP_IOWR(IOC_TRANSACTION_PREPARE_CRYPT_ACCESS, struct cryptochip_transaction_prepare_crypt_access *) +#define CRYPTOCHIP_IOC_TRANSACTION_GET_SERIAL_NUMBER CRYPTOCHIP_IOR(IOC_TRANSACTION_GET_SERIAL_NUMBER, struct cryptochip_transaction_get_serial_number *) +#define CRYPTOCHIP_IOC_TRANSACTION_ENCRYPT_WRITE CRYPTOCHIP_IOW(IOC_TRANSACTION_ENCRYPT_WRITE, struct cryptochip_transaction_crypt_access *) +#define CRYPTOCHIP_IOC_TRANSACTION_DECRYPT_READ CRYPTOCHIP_IOWR(IOC_TRANSACTION_DECRYPT_READ, struct cryptochip_transaction_crypt_access *) + +#define CRYPTOCHIP_IOC_TRANSACTION_SHOW_CONFIG_ZONE CRYPTOCHIP_IOR(IOC_TRANSACTION_SHOW_CONFIG_ZONE, struct cryptochip_transaction_config_zone *) +#define CRYPTOCHIP_IOC_TRANSACTION_SHOW_OTP_ZONE CRYPTOCHIP_IOR(IOC_TRANSACTION_SHOW_OTP_ZONE, struct cryptochip_transaction_otp_zone *) +#define CRYPTOCHIP_IOC_TRANSACTION_SHOW_DATA_ZONE CRYPTOCHIP_IOR(IOC_TRANSACTION_SHOW_DATA_ZONE, struct cryptochip_transaction_data_zone *) + +#define CRYPTOCHIP_IOC_TRANSACTION_PLAINTEXT_WRITE CRYPTOCHIP_IOW(IOC_TRANSACTION_PLAINTEXT_WRITE, struct cryptochip_transaction_plaintext_access *) +#define CRYPTOCHIP_IOC_TRANSACTION_PLAINTEXT_READ CRYPTOCHIP_IOWR(IOC_TRANSACTION_PLAINTEXT_READ, struct cryptochip_transaction_plaintext_access *) + +#define CRYPTOCHIP_IOC_TRANSACTION_WRITE_CONFIG_ZONE CRYPTOCHIP_IOW(IOC_TRANSACTION_WRITE_CONFIG_ZONE, struct cryptochip_transaction_config_zone *) +#define CRYPTOCHIP_IOC_TRANSACTION_WRITE_OTP_ZONE CRYPTOCHIP_IOW(IOC_TRANSACTION_WRITE_OTP_ZONE, struct cryptochip_transaction_otp_zone *) +#define CRYPTOCHIP_IOC_TRANSACTION_WRITE_DATA_ZONE CRYPTOCHIP_IOW(IOC_TRANSACTION_WRITE_DATA_ZONE, struct cryptochip_transaction_data_zone *) + +#define CRYPTOCHIP_IOC_TRANSACTION_INITIALIZE_CONFIG_ZONE CRYPTOCHIP_IOWR(IOC_TRANSACTION_INITIALIZE_CONFIG_ZONE, struct cryptochip_transaction_config_zone *) +#define CRYPTOCHIP_IOC_TRANSACTION_INITIALIZE_OTP_AND_DATA_ZONE CRYPTOCHIP_IOW(IOC_TRANSACTION_INITIALIZE_OTP_AND_DATA_ZONE, struct cryptochip_transaction_program_otp_and_data_zone *) + +#define CRYPTOCHIP_IOC_TRANSACTION_LOCK_CONFIG_ZONE CRYPTOCHIP_IO(IOC_TRANSACTION_LOCK_CONFIG_ZONE) +#define CRYPTOCHIP_IOC_TRANSACTION_INITIALIZE_OTP_AND_DATA_ZONE_FORCE_LOCK CRYPTOCHIP_IOW(IOC_TRANSACTION_INITIALIZE_OTP_AND_DATA_ZONE_FORCE_LOCK, struct cryptochip_transaction_program_otp_and_data_zone *) +#define CRYPTOCHIP_IOC_TRANSACTION_PREPARE_CRYPT_ACCESS_PASS_THROUGH CRYPTOCHIP_IOWR(IOC_TRANSACTION_PREPARE_CRYPT_ACCESS_PASS_THROUGH, struct cryptochip_transaction_prepare_crypt_access *) + +#define CRYPTOCHIP_IOC_MAC CRYPTOCHIP_IOWR(IOC_MAC, struct cryptochip_mac *) +#define CRYPTOCHIP_IOC_CHECK_MAC CRYPTOCHIP_IOWR(IOC_CHECK_MAC, struct cryptochip_check_mac *) +#define CRYPTOCHIP_IOC_DERIVE_KEY CRYPTOCHIP_IOWR(IOC_DERIVE_KEY, struct cryptochip_derive_key *) +#define CRYPTOCHIP_IOC_DEVICE_REVISION CRYPTOCHIP_IOR(IOC_DEVICE_REVISION, struct cryptochip_device_revision *) +#define CRYPTOCHIP_IOC_IOC_GEN_DIGEST CRYPTOCHIP_IOW(IOC_GEN_DIGEST, struct cryptochip_gen_digest *) +#define CRYPTOCHIP_IOC_HMAC CRYPTOCHIP_IOWR(IOC_HMAC, struct cryptochip_hmac *) +#define CRYPTOCHIP_IOC_NONCE CRYPTOCHIP_IOWR(IOC_NONCE, struct cryptochip_nonce *) +#define CRYPTOCHIP_IOC_RANDOM CRYPTOCHIP_IOWR(IOC_RANDOM, struct cryptochip_random *) +#define CRYPTOCHIP_IOC_SHA CRYPTOCHIP_IOWR(IOC_SHA, struct cryptochip_sha *) +#define CRYPTOCHIP_IOC_UPDATE_EXTRA CRYPTOCHIP_IOWR(IOC_UPDATE_EXTRA, struct cryptochip_update_extra *) +#define CRYPTOCHIP_IOC_READ CRYPTOCHIP_IOWR(IOC_READ, struct cryptochip_read *) +#define CRYPTOCHIP_IOC_WRITE CRYPTOCHIP_IOWR(IOC_WRITE, struct cryptochip_write *) + +#define CRYPTOCHIP_IOC_LOCK CRYPTOCHIP_IOW(IOC_LOCK, struct cryptochip_lock *) +#define CRYPTOCHIP_IOC_PAUSE CRYPTOCHIP_IOW(IOC_PAUSE, struct cryptochip_pause *) + +#define CRYPTOCHIP_IOC_BEGIN_TRANSACTION CRYPTOCHIP_IO(IOC_BEGIN_TRANSACTION) +#define CRYPTOCHIP_IOC_END_TRANSACTION CRYPTOCHIP_IO(IOC_END_TRANSACTION) + +#define CRYPTOCHIP_IOC_SET_TIMING CRYPTOCHIP_IOW(IOC_SET_TIMING, struct atsha204_timing) +#define CRYPTOCHIP_IOC_GET_TIMING CRYPTOCHIP_IOR(IOC_GET_TIMING, struct atsha204_timing) + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/dsplog_drv.h b/include/ambarella/dsplog_drv.h new file mode 100644 index 0000000..d157cc8 --- /dev/null +++ b/include/ambarella/dsplog_drv.h @@ -0,0 +1,70 @@ +/* + * dsplog_drv.h + * + * History: + * 2013/09/30 - [Louis Sun] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ +#ifndef __DSP_LOG_DRV_H__ +#define __DSP_LOG_DRV_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#define DSPLOG_IOC_MAGIC 'p' + + +enum DSPLOG_IOC_ENUM { + IOC_DSPLOG_START_CAPUTRE = 0, + IOC_DSPLOG_STOP_CAPTURE = 1, + IOC_DSPLOG_SET_LOG_LEVEL = 2, + IOC_DSPLOG_GET_LOG_LEVEL = 3, + IOC_DSPLOG_PARSE_LOG = 4, +}; + + + + +//IOCTLs for driver DSPLOG +#define AMBA_IOC_DSPLOG_START_CAPUTRE _IO(DSPLOG_IOC_MAGIC, IOC_DSPLOG_START_CAPUTRE) +#define AMBA_IOC_DSPLOG_STOP_CAPTURE _IO(DSPLOG_IOC_MAGIC, IOC_DSPLOG_STOP_CAPTURE) +#define AMBA_IOC_DSPLOG_SET_LOG_LEVEL _IOW(DSPLOG_IOC_MAGIC,IOC_DSPLOG_SET_LOG_LEVEL, int) +#define AMBA_IOC_DSPLOG_GET_LOG_LEVEL _IOR(DSPLOG_IOC_MAGIC,IOC_DSPLOG_GET_LOG_LEVEL, int *) +#define AMBA_IOC_DSPLOG_PARSE_LOG _IOW(DSPLOG_IOC_MAGIC,IOC_DSPLOG_PARSE_LOG, int ) + + + +//int read(int fd, unsigned char * buffer, unsigned int max_size); + +#ifdef __cplusplus +} +#endif + +#endif //__DSP_LOG_DRV_H__ + diff --git a/include/ambarella/ft2build.h b/include/ambarella/ft2build.h new file mode 100644 index 0000000..e7ce99b --- /dev/null +++ b/include/ambarella/ft2build.h @@ -0,0 +1,42 @@ +/***************************************************************************/ +/* */ +/* ft2build.h */ +/* */ +/* FreeType 2 build and setup macros. */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This is the `entry point' for FreeType header file inclusions. It is */ + /* the only header file which should be included directly; all other */ + /* FreeType header files should be accessed with macro names (after */ + /* including `ft2build.h'). */ + /* */ + /* A typical example is */ + /* */ + /* #include <ft2build.h> */ + /* #include FT_FREETYPE_H */ + /* */ + /*************************************************************************/ + + +#ifndef FT2BUILD_H_ +#define FT2BUILD_H_ + +#include <freetype/config/ftheader.h> + +#endif /* FT2BUILD_H_ */ + + +/* END */ diff --git a/include/ambarella/iav_common.h b/include/ambarella/iav_common.h new file mode 100644 index 0000000..2275662 --- /dev/null +++ b/include/ambarella/iav_common.h @@ -0,0 +1,457 @@ +/* + * iav_common.h + * + * History: + * 2013/09/04 - [Cao Rongrong] Created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_COMMON_H__ +#define __IAV_COMMON_H__ +/*! @file iav_common.h + * @brief This file defines common enumerations used in all IAV driver and header files + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*! @addtogroup iav-common-helper + * @{ + */ + +/** @enum amba_chip_arch + * @brief AMBA CHIP ARCH definition + */ +enum amba_chip_arch { + AMBA_CHIP_ARCH_UNKNOWN = 0xFFFF, /*!< 0xFFFF */ + AMBA_CHIP_ARCH_S5 = 11000, /*!< 11000 */ + AMBA_CHIP_ARCH_S2L = 12000, /*!< 12000 */ + AMBA_CHIP_ARCH_S3L = 13000, /*!< 13000 */ + AMBA_CHIP_ARCH_S5L = 16000, /*!< 16000 */ + AMBA_CHIP_ARCH_S6LM = 17000, /*!< 17000 */ + AMBA_CHIP_ARCH_CV1 = 20000, /*!< 20000 */ + AMBA_CHIP_ARCH_CV2 = 21000, /*!< 21000 */ + AMBA_CHIP_ARCH_CV22 = 22000, /*!< 22000 */ + AMBA_CHIP_ARCH_CV25 = 25000, /*!< 25000 */ +}; + +/*! @enum amba_video_format + * @brief AMBA Video Format Enumerations + */ +enum amba_video_format { + AMBA_VIDEO_FORMAT_AUTO = 0, /*!< 0 */ + AMBA_VIDEO_FORMAT_INTERLACE = 1, /*!< 1 */ + AMBA_VIDEO_FORMAT_PROGRESSIVE = 2, /*!< 2 */ +}; + +/*! @enum amba_video_type + * @brief AMBA Video Type Enumerations + */ +enum amba_video_type { + AMBA_VIDEO_TYPE_AUTO = 0, /*!< 0 */ + AMBA_VIDEO_TYPE_YUV_601 = 1, /*!< 1 */ + AMBA_VIDEO_TYPE_YUV_656 = 2, /*!< 2 */ + AMBA_VIDEO_TYPE_RGB_601 = 3, /*!< 3 */ + AMBA_VIDEO_TYPE_RGB_656 = 4, /*!< 4 */ + AMBA_VIDEO_TYPE_RGB_RAW = 5, /*!< 5 */ + AMBA_VIDEO_TYPE_YUV_BT1120 = 6, /*!< 6 */ + AMBA_VIDEO_TYPE_RGB_BT1120 = 7, /*!< 7 */ +}; + +/*! @macros AMBA_VIDEO_FPS(fps) + * @brief Formula of video fps.Input fps would be in enum amba_video_fps + */ +#define AMBA_VIDEO_FPS(fps) (512000000 / fps) + +/*! @enum amba_video_fps + * @brief AMBA Video FPS Enumerations + */ +enum amba_video_fps { + AMBA_VIDEO_FPS_AUTO = 0, /*!< 0 */ + AMBA_VIDEO_FPS_1 = 512000000, /*!< 512000000 */ + AMBA_VIDEO_FPS_2 = 256000000, /*!< 256000000 */ + AMBA_VIDEO_FPS_3 = 170666667, /*!< 170666667 */ + AMBA_VIDEO_FPS_4 = 128000000, /*!< 128000000 */ + AMBA_VIDEO_FPS_5 = 102400000, /*!< 102400000 */ + AMBA_VIDEO_FPS_6 = 85333333, /*!< 85333333 */ + AMBA_VIDEO_FPS_10 = 51200000, /*!< 51200000 */ + AMBA_VIDEO_FPS_12 = 42666667, /*!< 42666667 */ + AMBA_VIDEO_FPS_13 = 39384615, /*!< 39384615 */ + AMBA_VIDEO_FPS_14 = 36571428, /*!< 36571428 */ + AMBA_VIDEO_FPS_15 = 34133333, /*!< 34133333 */ + AMBA_VIDEO_FPS_20 = 25600000, /*!< 25600000 */ + AMBA_VIDEO_FPS_24 = 21333333, /*!< 21333333 */ + AMBA_VIDEO_FPS_25 = 20480000, /*!< 20480000 */ + AMBA_VIDEO_FPS_30 = 17066667, /*!< 17066667 */ + AMBA_VIDEO_FPS_50 = 10240000, /*!< 10240000 */ + AMBA_VIDEO_FPS_60 = 8533333, /*!< 8533333 */ + AMBA_VIDEO_FPS_120 = 4266667, /*!< 4266667 */ + AMBA_VIDEO_FPS_29_97 = 17083750, /*!< 17083750 */ + AMBA_VIDEO_FPS_59_94 = 8541875, /*!< 8541875 */ + AMBA_VIDEO_FPS_23_976 = 21354688, /*!< 21354688 */ + AMBA_VIDEO_FPS_12_5 = 40960000, /*!< 40960000 */ + AMBA_VIDEO_FPS_6_25 = 81920000, /*!< 81920000 */ + AMBA_VIDEO_FPS_3_125 = 163840000, /*!< 163840000 */ + AMBA_VIDEO_FPS_7_5 = 68266667, /*!< 68266667 */ + AMBA_VIDEO_FPS_3_75 = 136533333, /*!< 136533333 */ +}; + +/*! @enum amba_video_mode + * @brief AMBA Video Mode Enumerations + */ +enum amba_video_mode { + AMBA_VIDEO_MODE_AUTO = 0, /*!< 0, default mode*/ + + AMBA_VIDEO_MODE_240_400, + AMBA_VIDEO_MODE_320_240, + AMBA_VIDEO_MODE_320_288, + AMBA_VIDEO_MODE_320_480, + AMBA_VIDEO_MODE_360_240, + AMBA_VIDEO_MODE_360_288, + AMBA_VIDEO_MODE_480_240, + AMBA_VIDEO_MODE_480_640, + AMBA_VIDEO_MODE_480_800, + AMBA_VIDEO_MODE_640_480, + AMBA_VIDEO_MODE_640_512, + AMBA_VIDEO_MODE_720_240, + AMBA_VIDEO_MODE_720_480, + AMBA_VIDEO_MODE_720_576, + AMBA_VIDEO_MODE_800_480, + AMBA_VIDEO_MODE_848_480, + AMBA_VIDEO_MODE_800_600, + AMBA_VIDEO_MODE_960_240, + AMBA_VIDEO_MODE_960_540, + AMBA_VIDEO_MODE_1024_600, + AMBA_VIDEO_MODE_1024_768, + AMBA_VIDEO_MODE_1152_576, + AMBA_VIDEO_MODE_1152_648, + AMBA_VIDEO_MODE_1280_320, + AMBA_VIDEO_MODE_1280_720, + AMBA_VIDEO_MODE_1280_800, + AMBA_VIDEO_MODE_1280_960, + AMBA_VIDEO_MODE_1280_1024, + AMBA_VIDEO_MODE_1296_1032, + AMBA_VIDEO_MODE_1400_1050, + AMBA_VIDEO_MODE_1440_900, + AMBA_VIDEO_MODE_1600_1200, + AMBA_VIDEO_MODE_1600_1600, + AMBA_VIDEO_MODE_1632_1632, + AMBA_VIDEO_MODE_1640_1232, + AMBA_VIDEO_MODE_1680_1050, + AMBA_VIDEO_MODE_1728_486, + AMBA_VIDEO_MODE_1920_1080, + AMBA_VIDEO_MODE_1920_1200, + AMBA_VIDEO_MODE_1920_1440, + AMBA_VIDEO_MODE_1920_1920, + AMBA_VIDEO_MODE_2048_1080, + AMBA_VIDEO_MODE_2048_1152, + AMBA_VIDEO_MODE_2048_1536, + AMBA_VIDEO_MODE_2048_2048, + AMBA_VIDEO_MODE_2208_1242, + AMBA_VIDEO_MODE_2304_1296, + AMBA_VIDEO_MODE_2304_1536, + AMBA_VIDEO_MODE_2304_1728, + AMBA_VIDEO_MODE_2432_2048, + AMBA_VIDEO_MODE_2520_1424, + AMBA_VIDEO_MODE_2560_1440, + AMBA_VIDEO_MODE_2560_2048, + AMBA_VIDEO_MODE_2592_1944, + AMBA_VIDEO_MODE_2688_1512, + AMBA_VIDEO_MODE_2688_1520, + AMBA_VIDEO_MODE_2688_1944, + AMBA_VIDEO_MODE_3072_1728, + AMBA_VIDEO_MODE_3072_2048, + AMBA_VIDEO_MODE_3280_1852, + AMBA_VIDEO_MODE_3280_2464, + AMBA_VIDEO_MODE_3840_2160, + AMBA_VIDEO_MODE_4000_3000, + AMBA_VIDEO_MODE_4016_3016, + AMBA_VIDEO_MODE_4096_2160, + AMBA_VIDEO_MODE_5472_3648, + AMBA_VIDEO_MODE_7680_4320, + AMBA_VIDEO_MODE_1920_2160, + AMBA_VIDEO_MODE_3008_3000, + AMBA_VIDEO_MODE_1792_1792, + AMBA_VIDEO_MODE_2000_1118, + AMBA_VIDEO_MODE_1312_996, + AMBA_VIDEO_MODE_1920_480, + AMBA_VIDEO_MODE_1920_640, + AMBA_VIDEO_MODE_1920_720, + AMBA_VIDEO_MODE_3264_2448, + AMBA_VIDEO_MODE_1856_1856, + AMBA_VIDEO_MODE_3008_3008, + AMBA_VIDEO_MODE_1536_1536, + AMBA_VIDEO_MODE_2176_2160, + AMBA_VIDEO_MODE_2880_1856, + AMBA_VIDEO_MODE_2448_2064, + AMBA_VIDEO_MODE_1952_1112, + AMBA_VIDEO_MODE_1200_1920, + AMBA_VIDEO_MODE_1824_944, + AMBA_VIDEO_MODE_1280_1080, + AMBA_VIDEO_MODE_6016_4008, + AMBA_VIDEO_MODE_4768_3184, + AMBA_VIDEO_MODE_1280_1000, + AMBA_VIDEO_MODE_2592_1440, + AMBA_VIDEO_MODE_2880_1080, + + AMBA_VIDEO_MODE_NUM, + + /* alias name */ + AMBA_VIDEO_MODE_HVGA = AMBA_VIDEO_MODE_320_480, /*!< AMBA_VIDEO_MODE_320_480 */ + AMBA_VIDEO_MODE_VGA = AMBA_VIDEO_MODE_640_480, /*!< AMBA_VIDEO_MODE_640_480 */ + AMBA_VIDEO_MODE_WVGA = AMBA_VIDEO_MODE_800_480, /*!< AMBA_VIDEO_MODE_800_480 */ + AMBA_VIDEO_MODE_SVGA = AMBA_VIDEO_MODE_800_600, /*!< AMBA_VIDEO_MODE_800_600 */ + AMBA_VIDEO_MODE_WSVGA = AMBA_VIDEO_MODE_1024_600, /*!< AMBA_VIDEO_MODE_1024_600 */ + AMBA_VIDEO_MODE_XGA = AMBA_VIDEO_MODE_1024_768, /*!< AMBA_VIDEO_MODE_1024_768 */ + AMBA_VIDEO_MODE_WXGA = AMBA_VIDEO_MODE_1280_800, /*!< AMBA_VIDEO_MODE_1280_800 */ + AMBA_VIDEO_MODE_SXGA = AMBA_VIDEO_MODE_1280_1024, /*!< AMBA_VIDEO_MODE_1280_1024 */ + AMBA_VIDEO_MODE_SXGAP = AMBA_VIDEO_MODE_1400_1050, /*!< AMBA_VIDEO_MODE_1400_1050 */ + AMBA_VIDEO_MODE_WSXGA = AMBA_VIDEO_MODE_1440_900, /*!< AMBA_VIDEO_MODE_1440_900 */ + AMBA_VIDEO_MODE_UXGA = AMBA_VIDEO_MODE_1600_1200, /*!< AMBA_VIDEO_MODE_1600_1200 */ + AMBA_VIDEO_MODE_WSXGAP = AMBA_VIDEO_MODE_1680_1050, /*!< AMBA_VIDEO_MODE_1680_1050 */ + AMBA_VIDEO_MODE_WUXGA = AMBA_VIDEO_MODE_1920_1200, /*!< AMBA_VIDEO_MODE_1920_1200 */ + AMBA_VIDEO_MODE_QXGA = AMBA_VIDEO_MODE_2048_1536, /*!< AMBA_VIDEO_MODE_2048_1536 */ + AMBA_VIDEO_MODE_QSXGA = AMBA_VIDEO_MODE_2592_1944, /*!< AMBA_VIDEO_MODE_2592_1944 */ + AMBA_VIDEO_MODE_1080P = AMBA_VIDEO_MODE_1920_1080, /*!< AMBA_VIDEO_MODE_1920_1080 */ + AMBA_VIDEO_MODE_1080I = AMBA_VIDEO_MODE_1920_1080, /*!< AMBA_VIDEO_MODE_1920_1080 */ + AMBA_VIDEO_MODE_720P = AMBA_VIDEO_MODE_1280_720, /*!< AMBA_VIDEO_MODE_1280_720 */ + AMBA_VIDEO_MODE_576P = AMBA_VIDEO_MODE_720_576, /*!< AMBA_VIDEO_MODE_720_576 */ + AMBA_VIDEO_MODE_480P = AMBA_VIDEO_MODE_720_480, /*!< AMBA_VIDEO_MODE_720_480 */ + AMBA_VIDEO_MODE_576I = AMBA_VIDEO_MODE_720_576, /*!< AMBA_VIDEO_MODE_720_576 */ + AMBA_VIDEO_MODE_480I = AMBA_VIDEO_MODE_720_480, /*!< AMBA_VIDEO_MODE_720_480 */ + AMBA_VIDEO_MODE_D1_PAL = AMBA_VIDEO_MODE_720_576, /*!< AMBA_VIDEO_MODE_720_576 */ + AMBA_VIDEO_MODE_D1_NTSC = AMBA_VIDEO_MODE_720_480, /*!< AMBA_VIDEO_MODE_720_480 */ + + /* misc */ + AMBA_VIDEO_MODE_OFF = 0xF000, /*!< 0xF000 */ + AMBA_VIDEO_MODE_NOT_SUPPORT = -1, /*!< -1 */ + AMBA_VIDEO_MODE_CURRENT = -2, /*!< -2 */ + AMBA_VIDEO_MODE_INVALID = AMBA_VIDEO_MODE_NUM + 1, /*!< AMBA_VIDEO_MODE_NUM + 1 */ +}; + +/*! @enum amba_video_bits + * @brief AMBA Video Bits Enumerations + */ +enum amba_video_bits { + AMBA_VIDEO_BITS_AUTO = 0, /*!< 0 */ + AMBA_VIDEO_BITS_8 = 8, /*!< 8 */ + AMBA_VIDEO_BITS_10 = 10, /*!< 10 */ + AMBA_VIDEO_BITS_12 = 12, /*!< 12 */ + AMBA_VIDEO_BITS_14 = 14, /*!< 14 */ + AMBA_VIDEO_BITS_16 = 16, /*!< 16 */ +}; + +/*! @enum amba_video_ratio + * @brief AMBA Video Ration Enumerations + */ +enum amba_video_ratio { + AMBA_VIDEO_RATIO_AUTO = 0x0, /*!< 0x0 */ + AMBA_VIDEO_RATIO_4_3 = 0x1, /*!< 0x1 */ + AMBA_VIDEO_RATIO_16_9 = 0x2, /*!< 0x2 */ + AMBA_VIDEO_RATIO_1_1 = 0x4, /*!< 0x4 */ +}; + +/*! @enum amba_video_system + * @brief AMBA Video Ration Enumerations + */ +enum amba_video_system { + AMBA_VIDEO_SYSTEM_AUTO = 0x0, /*!< 0x0 */ + AMBA_VIDEO_SYSTEM_NTSC = 0x1, /*!< 0x1 */ + AMBA_VIDEO_SYSTEM_PAL = 0x2, /*!< 0x2 */ + AMBA_VIDEO_SYSTEM_SECAM = 0x4, /*!< 0x4 */ + AMBA_VIDEO_SYSTEM_ALL = 0xf, /*!< 0xf */ +}; + +enum amba_video_hdr_mode { + AMBA_VIDEO_LINEAR_MODE = 0, /*!< 0 */ + AMBA_VIDEO_2X_HDR_MODE, + AMBA_VIDEO_3X_HDR_MODE, + AMBA_VIDEO_4X_HDR_MODE, + + AMBA_VIDEO_INT_HDR_MODE = 15, /*!< 15 */ + + AMBA_VIDEO_MODE_TOTAL_NUM, + + AMBA_VIDEO_HDR_MODE_INVALID = 0xFF, /*!< 0xFF */ + + AMBA_VIDEO_MODE_FIRST = 0,/*!< 0 */ + AMBA_VIDEO_MODE_LAST = AMBA_VIDEO_MODE_TOTAL_NUM, /*!< AMBA_VIDEO_MODE_TOTAL_NUM */ +}; +/*! @} */ /* iav-common-helper */ + + +/*! @addtogroup iav-common-struct + * @{ + */ + +/*! @struct amba_video_info + * @brief Amba video info + */ +struct amba_video_info { + u32 mode; /*!< Video mode, @sa amba_video_mode */ + u32 width; /*!< Window width */ + u32 height; /*!< Window height */ + u32 max_fps; /*!< Video max fps */ + u32 fps; /*!< Video fps */ + u8 format; /*!< Video format */ + u8 type; /*!< Video type */ + u8 bits; /*!< Video encode bit width */ + u8 ratio; /*!< Width-height ratio */ + u8 system; /*!< Video system type */ + u8 flip; /*!< Video flip */ + u8 rotate; /*!< Video rotate */ + u8 hdr_mode; /*!< Video rotate */ + u32 rev; /*!< Struct definition revision */ +}; +/*! @} */ /* iav-common-struct */ + +/*! + * @addtogroup iav-common-helper + * @{ + */ +/*! @macros DIV_ROUND(x,d) + * @brief div_round in 32-bit. + */ +#ifndef DIV_ROUND +#define DIV_ROUND(x, d) (((x) + ((d) - 1)) / (d)) +#endif + +/*! @macros DIV_CLOSEST(x,d) + * @brief div_closest in 32-bit. + */ +#ifndef DIV_CLOSEST +#define DIV_CLOSEST(x, d) (((x) + ((d) / 2)) / (d)) +#endif + +/*! + * @macros DIV64_ROUND(x,d) + * @brief div_round in 64-bit. + */ +#ifndef DIV64_ROUND +#define DIV64_ROUND(x, d) ({u64 _tmp = (x)+((d) - 1); do_div(_tmp, d); _tmp;}) +#endif + +/*! + * @macros DIV64_CLOSEST(x,d) + * @brief div_closet in 64-bit. + */ +#ifndef DIV64_CLOSEST +#define DIV64_CLOSEST(x, d) ({u64 _tmp = (x)+((d)/2); do_div(_tmp, d); _tmp;}) +#endif + +/*! + * @macros ROUND_UP(x,d) + * @brief round up func. + */ +#ifndef ROUND_UP +#define ROUND_UP(x, n) ( ((x)+(n)-1u) & ~((n)-1u) ) +#endif + +/*! + * @macros ROUND_DOWN(x,d) + * @brief round down func. + */ +#ifndef ROUND_DOWN +#define ROUND_DOWN(x, n) ((x) & ~((n) - 1)) +#endif + +/*! + * @macros MIN(a, b) + * @brief return minimum value of a and b. + */ +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif + +/*! + * @macros MAX(a, b) + * @brief return maximum value of a and b. + */ +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +/*! + * @macros ABS(x) + * @brief return absolute value of x. + */ +#ifndef ABS +#define ABS(x) ({ \ + int __x = (x); \ + (__x < 0) ? -__x : __x; \ + }) +#endif + +/*! + * @macros ARRAY_SIZE(array) + * @brief return array_size of input array. + */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) +#endif + +/*! + * @macros BIT(n) + * @brief bit n. + */ +#ifndef BIT +#define BIT(n) (1 << (n)) +#endif + +/*! + * @macros TEST_BIT(x, n) + * @brief test if the (n) th bit of (x) is 1. + */ +#ifndef TEST_BIT +#define TEST_BIT(x, n) ((x) & (1 << (n))) +#endif + +/*! + * @macros SET_BIT(x, n) + * @brief set the (n)th bit of (x) to 1. + */ +#ifndef SET_BIT +#define SET_BIT(x, n) do {x = (x | (1 << (n)));} while(0); +#endif + +/*! + * @macros CLEAR_BIT(x, n) + * @brief set the (n)th bit of (x) to 0. + */ +#ifndef CLEAR_BIT +#define CLEAR_BIT(x, n) do {x = (x & (~(1 << (n))));} while(0); +#endif +/*! @} */ /* End of iav-common-helper */ + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/iav_netlink.h b/include/ambarella/iav_netlink.h new file mode 100644 index 0000000..3c1f352 --- /dev/null +++ b/include/ambarella/iav_netlink.h @@ -0,0 +1,141 @@ +/* + * iav_netlink.h + * + * History: + * 2014/07/25 - [Zhaoyang Chen] created file + * 2015/07/24 - [Jian Tang] modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef ___IAV_NETLINK_H__ +#define ___IAV_NETLINK_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_NETLINK_REQUESTS (5) + +#define MAX_NL_MSG_LEN (1024) + +enum NL_OBJ_INDEX { + NL_OBJ_IMAGE = 0, + NL_OBJ_VSYNC = 1, + NL_OBJ_SYS = 2, + NL_OBJ_VP = 3, + NL_OBJ_MAX_NUM, +}; + +enum NL_PORT_INDEX { + NL_PORT_BASE = 24, + NL_PORT_IMAGE = NL_PORT_BASE + NL_OBJ_IMAGE, + NL_PORT_VSYNC = NL_PORT_BASE + NL_OBJ_VSYNC, + NL_PORT_SYS = NL_PORT_BASE + NL_OBJ_SYS, + NL_PORT_VP = NL_PORT_BASE + NL_OBJ_VP, +}; + +enum NL_REQUEST_IMAGE { + NL_REQ_IMG_START_AAA = 0, + NL_REQ_IMG_STOP_AAA = 1, + NL_REQ_IMG_PREPARE_AAA = 2, + NL_REQ_IMG_DPTZ_MAIN = 3, + NL_REQ_IMG_WARP = 4, + NL_REQ_IMG_NUM, + NL_REQ_IMG_FIRST = NL_REQ_IMG_START_AAA, + NL_REQ_IMG_LAST = NL_REQ_IMG_NUM, +}; + +enum NL_REQUEST_VP { + NL_REQ_VP_START_INFO = 0, + NL_REQ_VP_NUM, + NL_REQ_VP_FIRST = NL_REQ_VP_START_INFO, + NL_REQ_VP_LAST = NL_REQ_VP_NUM, +}; + +enum NL_REQUEST_VSYNC { + NL_REQ_VSYNC_RESTORE = 0, + NL_REQ_VSYNC_NUM, + NL_REQ_VSYNC_FIRST = NL_REQ_VSYNC_RESTORE, + NL_REQ_VSYNC_LAST = NL_REQ_VSYNC_NUM, +}; + +enum NL_NOTICE_SYS { + NL_NOTICE_SYS_THAW_DONE = 0, + NL_NOTICE_SYS_NUM, + NL_NOTICE_SYS_FIRST = NL_NOTICE_SYS_THAW_DONE, + NL_NOTICE_SYS_LAST = NL_NOTICE_SYS_NUM, +}; + +enum NL_SESSION_CMD { + NL_SESS_CMD_CONNECT = 0, + NL_SESS_CMD_DISCONNECT = 1, + NL_SESS_CMD_NUM, + NL_SESS_CMD_FIRST = NL_SESS_CMD_CONNECT, + NL_SESS_CMD_LAST = NL_SESS_CMD_NUM, +}; + +enum NL_CMD_STATUS { + NL_CMD_STATUS_SUCCESS = 0, + NL_CMD_STATUS_FAIL = 1, +}; + +enum NL_MSG_TYPE { + NL_MSG_TYPE_SESSION = 0, + NL_MSG_TYPE_REQUEST = 1, + NL_MSG_TYPE_NOTICE = 2, +}; + +enum NL_MSG_DIR { + NL_MSG_DIR_CMD = 0, + NL_MSG_DIR_STATUS = 1, +}; + +#define NL_MSG_SIZE (128) +#define NL_MSG_HEADER_SIZE (24) +#define NL_MSG_PAYLOAD_SIZE (NL_MSG_SIZE - NL_MSG_HEADER_SIZE) + +struct nl_vsync_restore_data { + u8 vinc_map; + u8 reserved[7]; +}; + +struct nl_msg_data { + u32 pid; + u32 port; + u32 type; + u32 dir; + u32 cmd; + u32 status; + u8 payload[NL_MSG_PAYLOAD_SIZE]; +}; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/iav_ucode_ioctl.h b/include/ambarella/iav_ucode_ioctl.h new file mode 100644 index 0000000..25bc7c9 --- /dev/null +++ b/include/ambarella/iav_ucode_ioctl.h @@ -0,0 +1,142 @@ +/* + * iav_ucode_ioctl.h + * + * History: + * 2012/10/25 - [Cao Rongrong] Created file + * 2015/10/14 - [Jian Tang] Modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __UCODE_IOCTL_ARCH_H__ +#define __UCODE_IOCTL_ARCH_H__ + +/*! @file iav_ucode_ioctl.h + * @brief This file defines video output configuration ioctl + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +#include <linux/ioctl.h> + +/*! @addtogroup iav-ioctl-ucode-helper */ +#define UCODE_LOAD_ITEM_MAX 4 + +/*! @addtogroup iav-ioctl-ucode-struct + * @{ + */ +typedef struct ucode_load_item_s { + unsigned long addr_offset; /*!< ucode address offset */ + char filename[24]; /*!< ucode file name */ +} ucode_load_item_t; + +typedef struct ucode_load_info_s { + unsigned long map_size; /*!< ucode map size */ + unsigned long nr_item; /*!< ucode nr item */ + ucode_load_item_t items[UCODE_LOAD_ITEM_MAX]; /*!< ucode item info */ +} ucode_load_info_t; + +typedef struct ucode_version_s { + u16 year; /*!< ucode modifed time: year */ + u8 month; /*!< ucode modifed time: month */ + u8 day; /*!< ucode modifed time: day */ + u32 edition_num; /*!< ucode edition number */ + u32 edition_ver; /*!< ucode edition version */ + u32 chip_arch; /*!< ucode chip arch, @sa ucode_arch */ +} ucode_version_t; +/*! @} */ /* End of iav-ioctl-ucode-struct */ + +/*! @addtogroup iav-ioctl-ucode-helper + * @{ + */ +/* + * Ucode IOCTL definitions + */ +#define UCODE_IOC_MAGIC 'u' + +typedef enum { + // Basic functions (0x00 ~ 0x2F) + IOC_GET_UCODE_INFO = 0x00, /*!< 0x00, Basic functions */ + IOC_GET_UCODE_VERSION = 0x01, /*!< 0x01 */ + IOC_UPDATE_UCODE = 0x02, /*!< 0x02 */ + + // Reserved: 0x30 ~ 0xFF +} UCODE_IOC; + +enum ucode_arch { + UCODE_ARCH_UNKNOWN = 0xFFFF, /*!< 0xFFFF */ + UCODE_ARCH_A5S = 0, /*!< 0 */ + UCODE_ARCH_S2 = 1, /*!< 1 */ + UCODE_ARCH_S2L = 2, /*!< 2 */ + UCODE_ARCH_S2E = 3, /*!< 3 */ + UCODE_ARCH_S3L = 4, /*!< 4 */ + UCODE_ARCH_S5 = 5, /*!< 5 */ + UCODE_ARCH_S5L = 6, /*!< 6 */ + UCODE_ARCH_CV1 = 7, /*!< 7 */ + UCODE_ARCH_CV22 = 8, /*!< 8 */ + UCODE_ARCH_CV2 = 9, /*!< 9 */ + UCODE_ARCH_CV25 = 10, /*!< 10 */ + UCODE_ARCH_S6LM = 11, /*!< 11 */ + + UCODE_ARCH_NUM, + UCODE_ARCH_FIRST = 0, /*!< 0 */ + UCODE_ARCH_LAST = UCODE_ARCH_NUM, /*!< UCODE_ARCH_NUM */ + + /* For new chips */ +}; +/*! @} */ /* End of iav-ioctl-ucode-helper */ + +/*! @addtogroup iav-ioctl-ucode-api + * @{ + */ + +/*! + * This API retrieve ucode load information to enable the application level program to load the ucode to a corresponding memory position. + */ +#define IAV_IOC_GET_UCODE_INFO _IOR(UCODE_IOC_MAGIC, IOC_GET_UCODE_INFO, ucode_load_info_t) + +/*! + * This API can be used to retrieve the current ucode version + */ +#define IAV_IOC_GET_UCODE_VERSION _IOR(UCODE_IOC_MAGIC, IOC_GET_UCODE_VERSION, ucode_version_t) + +/*! + * This API can be used to update ucode. + */ +#define IAV_IOC_UPDATE_UCODE _IOW(UCODE_IOC_MAGIC, IOC_UPDATE_UCODE, int) +/*! @} */ /* End of iav-ioctl-ucode-api */ + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/ambarella/iav_vin_common.h b/include/ambarella/iav_vin_common.h new file mode 100644 index 0000000..56f7c4d --- /dev/null +++ b/include/ambarella/iav_vin_common.h @@ -0,0 +1,532 @@ +/* + * iav_vin_common.h + * + * History: + * 2013/09/04 - [Cao Rongrong] Created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_VIN_COMMON_H__ +#define __IAV_VIN_COMMON_H__ + +/*! @file iav_vin_common.h + * @brief This file defines IAV Video Input Configuration structures. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ==========================================================================*/ +#include"iav_common.h" + +/*! @addtogroup iav-ioctl-vin-helper + * @{ + */ +/* ==========================================================================*/ +#define AMBA_VINDEV_MAX_NUM 32 +#define AMBA_VINC_MAX_NUM 8 + +/* ==========================================================================*/ +enum vindev_type { + VINDEV_TYPE_SENSOR = 0, /*!< 0 */ + VINDEV_TYPE_DECODER = 1, /*!< 1 */ +}; + +enum vindev_subtype { + VINDEV_SUBTYPE_CMOS = 0x000, /*!< 0x000 */ + VINDEV_SUBTYPE_CCD = 0x001, /*!< 0x001 */ + VINDEV_SUBTYPE_CVBS = 0x100, /*!< 0x100 */ + VINDEV_SUBTYPE_SVIDEO = 0x101, /*!< 0x101 */ + VINDEV_SUBTYPE_YPBPR = 0x102, /*!< 0x102 */ + VINDEV_SUBTYPE_HDMI = 0x103, /*!< 0x103 */ + VINDEV_SUBTYPE_VGA = 0x104, /*!< 0x104 */ + VINDEV_SUBTYPE_SDI = 0x105, /*!< 0x105 */ +}; + +enum amba_vindev_mirror_pattern_e { + VINDEV_MIRROR_NONE = 0, /*!< 0 */ + VINDEV_MIRROR_VERTICALLY = 1, /*!< 1 */ + VINDEV_MIRROR_HORRIZONTALLY = 2, /*!< 2 */ + VINDEV_MIRROR_HORRIZONTALLY_VERTICALLY = 3, /*!< 3 */ + VINDEV_MIRROR_AUTO = 255, /*!< 255 */ +}; + +enum amba_vindev_bayer_pattern_e { + VINDEV_BAYER_PATTERN_RG = 0, /*!< 0 */ + VINDEV_BAYER_PATTERN_BG = 1, /*!< 1 */ + VINDEV_BAYER_PATTERN_GR = 2, /*!< 2 */ + VINDEV_BAYER_PATTERN_GB = 3, /*!< 3 */ + /* RGB/IR CFA, IR instead of B */ + VINDEV_BAYER_PATTERN_RG_GI = 4, /*!< 4 */ + VINDEV_BAYER_PATTERN_IG_GR = 5, /*!< 5 */ + VINDEV_BAYER_PATTERN_GR_IG = 6, /*!< 6 */ + VINDEV_BAYER_PATTERN_GI_RG = 7, /*!< 7 */ + /* RGB/IR CFA, IR instead of R */ + VINDEV_BAYER_PATTERN_BG_GI = 8, /*!< 8 */ + VINDEV_BAYER_PATTERN_IG_GB = 9, /*!< 9 */ + VINDEV_BAYER_PATTERN_GB_IG = 10, /*!< 10 */ + VINDEV_BAYER_PATTERN_GI_BG = 11, /*!< 11 */ + /* RCCB CFA */ + VINDEV_BAYER_PATTERN_RCCB = 12, /*!< 12 */ + VINDEV_BAYER_PATTERN_BCCR = 13, /*!< 13 */ + VINDEV_BAYER_PATTERN_CRBC = 14, /*!< 14 */ + VINDEV_BAYER_PATTERN_CBRC = 15, /*!< 15 */ + /* RCCC CFA */ + VINDEV_BAYER_PATTERN_RCCC = 16, /*!< 16 */ + VINDEV_BAYER_PATTERN_CCCR = 17, /*!< 17 */ + VINDEV_BAYER_PATTERN_CRCC = 18, /*!< 18 */ + VINDEV_BAYER_PATTERN_CCRC = 19, /*!< 19 */ + /* MONO CFA */ + VINDEV_BAYER_PATTERN_MONO = 254, /*!< 254 */ + + VINDEV_BAYER_PATTERN_AUTO = 255, /*!< 255 */ +}; + +enum vindev_reg_context { + VINDEV_REG_CONTEXT_A = 0, /*!< 0 */ + VINDEV_REG_CONTEXT_B = 1, /*!< 1 */ + VINDEV_REG_CONTEXT_C = 2, /*!< 2 */ + VINDEV_REG_CONTEXT_D = 3, /*!< 3 */ + VINDEV_REG_CONTEXT_NUM = 4, /*!< 4 */ +}; + +enum sensor_list { + /* Onsemi Sensor */ + SENSOR_MT9J001 = 0x00000000, /*!< 0x00000000 */ + SENSOR_MT9M033 = 0x00000001, /*!< 0x00000001 */ + SENSOR_MT9P001 = 0x00000002, /*!< 0x00000002 */ + SENSOR_MT9V136 = 0x00000003, /*!< 0x00000003 */ + SENSOR_MT9T002 = 0x00000004, /*!< 0x00000004 */ + SENSOR_AR0331 = 0x00000005, /*!< 0x00000005 */ + SENSOR_AR0130 = 0x00000006, /*!< 0x00000006 */ + SENSOR_AR0141 = 0x00000007, /*!< 0x00000007 */ + SENSOR_AR0230 = 0x00000008, /*!< 0x00000008 */ + SENSOR_AR0237 = 0x00000009, /*!< 0x00000009 */ + SENSOR_AR0239 = 0x0000000A, /*!< 0x0000000A */ + SENSOR_AR0521 = 0x0000000B, /*!< 0x0000000B */ + SENSOR_AR0144 = 0x0000000C, /*!< 0x0000000C */ + SENSOR_AR0144_RGB = 0x0000000D, /*!< 0x0000000D */ + SENSOR_AR0143 = 0x0000000E, /*!< 0x0000000E */ + SENSOR_AR0221 = 0x0000000F, /*!< 0x0000000F */ + SENSOR_AR0233 = 0x00000010, /*!< 0x00000010 */ + SENSOR_AR0231 = 0x00000011, /*!< 0x00000011 */ + SENSOR_AR0132 = 0x00000012, /*!< 0x00000012 */ + SENSOR_AR0237_RGBIR = 0x00000013, /*!< 0x00000013 */ + SENSOR_AR0138 = 0x00000014, /*!< 0x00000014 */ + SENSOR_AR0431 = 0x00000015, /*!< 0x00000015 */ + SENSOR_AR0135 = 0x00000016, /*!< 0x00000016 */ + SENSOR_AR0323 = 0x00000017, /*!< 0x00000017 */ + SENSOR_AR0220 = 0x00000018, /*!< 0x00000018 */ + + /* OV Sensor */ + SENSOR_OV10620 = 0x00001000, /*!< 0x00001000 */ + SENSOR_OV14810 = 0x00001001, /*!< 0x00001001 */ + SENSOR_OV2710 = 0x00001002, /*!< 0x00001002 */ + SENSOR_OV5653 = 0x00001003, /*!< 0x00001003 */ + SENSOR_OV7720 = 0x00001004, /*!< 0x00001004 */ + SENSOR_OV7725 = 0x00001005, /*!< 0x00001005 */ + SENSOR_OV7740 = 0x00001006, /*!< 0x00001006 */ + SENSOR_OV9710 = 0x00001007, /*!< 0x00001007 */ + SENSOR_OV10630 = 0x00001008, /*!< 0x00001008 */ + SENSOR_OV9726 = 0x00001009, /*!< 0x00001009 */ + SENSOR_OV4689 = 0x0000100A, /*!< 0x0000100A */ + SENSOR_OV9718 = 0x0000100B, /*!< 0x0000100B */ + SENSOR_OV5658 = 0x0000100C, /*!< 0x0000100C */ + SENSOR_OV9750 = 0x0000100D, /*!< 0x0000100D */ + SENSOR_OV9732 = 0x0000100E, /*!< 0x0000100E */ + SENSOR_OV2718 = 0x0000100F, /*!< 0x0000100F */ + SENSOR_OV7251 = 0x00001010, /*!< 0x00001010 */ + SENSOR_OV10823 = 0x00001011, /*!< 0x00001011 */ + SENSOR_OV9281 = 0x00001012, /*!< 0x00001012 */ + SENSOR_OS08A10 = 0x00001013, /*!< 0x00001013 */ + SENSOR_OV2732 = 0x00001014, /*!< 0x00001014 */ + SENSOR_OV2735 = 0x00001015, /*!< 0x00001015 */ + SENSOR_OV2770 = 0x00001016, /*!< 0x00001016*/ + SENSOR_OS05A10 = 0x00001017, /*!< 0x00001017 */ + SENSOR_OS02A1Q = 0x00001018, /*!< 0x00001018 */ + SENSOR_OV8856 = 0x00001019, /*!< 0x00001019 */ + SENSOR_OV10640 = 0x0000101A, /*!< 0x0000101A */ + SENSOR_OX01A10 = 0x0000101B, /*!< 0x0000101B */ + SENSOR_OV9284 = 0x0000101C, /*!< 0x0000101C */ + SENSOR_OVM7690 = 0x0000101D, /*!< 0x0000101D */ + SENSOR_OV2775 = 0x0000101E, /*!< 0x0000101E*/ + SENSOR_OV9755 = 0x0000101F, /*!< 0x0000101F */ + SENSOR_OS02C10 = 0x00001020, /*!< 0x00001020 */ + SENSOR_OS04A10 = 0x00001021, /*!< 0x00001021 */ + + /* Samsung Sensor */ + SENSOR_S5K3E2FX = 0x00002000, /*!< 0x00002000 */ + SENSOR_S5K4AWFX = 0x00002001, /*!< 0x00002001 */ + SENSOR_S5K5B3GX = 0x00002002, /*!< 0x00002002 */ + + /* Sony Sensor */ + SENSOR_IMX035 = 0x00003000, /*!< 0x00003000 */ + SENSOR_IMX036 = 0x00003001, /*!< 0x00003001 */ + SENSOR_IMX072 = 0x00003002, /*!< 0x00003002 */ + SENSOR_IMX122 = 0x00003003, /*!< 0x00003003 */ + SENSOR_IMX121 = 0x00003004, /*!< 0x00003004 */ + SENSOR_IMX104 = 0x00003005, /*!< 0x00003005 */ + SENSOR_IMX136 = 0x00003006, /*!< 0x00003006 */ + SENSOR_IMX105 = 0x00003007, /*!< 0x00003007 */ + SENSOR_IMX172 = 0x00003008, /*!< 0x00003008 */ + SENSOR_IMX178 = 0x00003009, /*!< 0x00003009 */ + SENSOR_IMX123 = 0x0000300A, /*!< 0x0000300A */ + SENSOR_IMX123_DCG = 0x0000300B, /*!< 0x0000300B */ + SENSOR_IMX322 = 0x0000300C, /*!< 0x0000300C */ + SENSOR_IMX124 = 0x0000300D, /*!< 0x0000300D */ + SENSOR_IMX224 = 0x0000300E, /*!< 0x0000300E */ + SENSOR_IMX174 = 0x0000300F, /*!< 0x0000300F */ + SENSOR_IMX291 = 0x00003010, /*!< 0x00003010 */ + SENSOR_IMX185 = 0x00003011, /*!< 0x00003011 */ + SENSOR_IMX226 = 0x00003012, /*!< 0x00003012 */ + SENSOR_IMX290 = 0x00003013, /*!< 0x00003013 */ + SENSOR_IMX274 = 0x00003014, /*!< 0x00003014 */ + SENSOR_IMX377 = 0x00003015, /*!< 0x00003015 */ + SENSOR_IMX183 = 0x00003016, /*!< 0x00003016 */ + SENSOR_IMX277 = 0x00003017, /*!< 0x00003017 */ + SENSOR_IMX408 = 0x00003018, /*!< 0x00003018 */ + SENSOR_IMX117 = 0x00003019, /*!< 0x00003019 */ + SENSOR_IMX335 = 0x0000301A, /*!< 0x0000301A */ + SENSOR_IMX577 = 0x0000301B, /*!< 0x0000301B */ + SENSOR_IMX390 = 0x0000301C, /*!< 0x0000301C */ + SENSOR_IMX415 = 0x0000301D, /*!< 0x0000301D */ + SENSOR_IMX412 = 0x0000301E, /*!< 0x0000301E */ + SENSOR_IMX265 = 0x0000301F, /*!< 0x0000301F */ + SENSOR_IMX250 = 0x00003020, /*!< 0x00003020 */ + SENSOR_IMX299 = 0x00003021, /*!< 0x00003021 */ + SENSOR_IMX326 = 0x00003022, /*!< 0x00003022 */ + SENSOR_IMX307 = 0x00003023, /*!< 0x00003023 */ + SENSOR_IMX385 = 0x00003024, /*!< 0x00003024 */ + SENSOR_IMX334 = 0x00003025, /*!< 0x00003025 */ + SENSOR_IMX327 = 0x00003026, /*!< 0x00003026 */ + SENSOR_IMX264 = 0x00003027, /*!< 0x00003027 */ + SENSOR_IMX490 = 0x00003028, /*!< 0x00003028 */ + + /* Panasonic Sensor */ + SENSOR_MN34041PL = 0x00004000, /*!< 0x00004000 */ + SENSOR_MN34031PL = 0x00004001, /*!< 0x00004001 */ + SENSOR_MN34220PL = 0x00004002, /*!< 0x00004002 */ + SENSOR_MN34210PL = 0x00004003, /*!< 0x00004003 */ + SENSOR_MN34227PL = 0x00004004, /*!< 0x00004004 */ + SENSOR_MN34420PL = 0x00004005, /*!< 0x00004005 */ + SENSOR_MN34422PL = 0x00004006, /*!< 0x00004006 */ + SENSOR_MN34424PL = 0x00004007, /*!< 0x00004007 */ + + /* altera fpga vin */ + SENSOR_ALTERA_FPGA = 0x00005000, /*!< 0x00005000 */ + + /* Dummy Sensor */ + SENSOR_AMBDS = 0x00006000, /*!< 0x00006000 */ + + /* Cista Sensor */ + SENSOR_C2390 = 0x00007000, /*!< 0x00007000 */ + + /* Brillnics Sensor */ + SENSOR_BRV0500 = 0x00008000, /*!< 0x00008000 */ + SENSOR_BRV0200 = 0x00008001, /*!< 0x00008001 */ + + /* SOI Sensor */ + SENSOR_JX_F22 = 0x00009000, /*!< 0x00009000 */ + SENSOR_JX_K02 = 0x00009001, /*!< 0x00009001 */ + SENSOR_JX_F23 = 0x00009002, /*!< 0x00009002 */ + + /* Smartsens Sensor */ + SENSOR_SC130GS = 0x0000A000, /*!< 0x0000A000 */ + SENSOR_SC2135 = 0x0000A001, /*!< 0x0000A001 */ + SENSOR_SC2235 = 0x0000A002, /*!< 0x0000A002 */ + SENSOR_SC5238 = 0x0000A003, /*!< 0x0000A003 */ + SENSOR_SC5300 = 0x0000A004, /*!< 0x0000A004 */ + SENSOR_SC2310 = 0x0000A005, /*!< 0x0000A005 */ + + /* Himax sensor */ + SENSOR_HM2140 = 0x0000B000, /*!< 0x0000B000 */ + SENSOR_HM5532 = 0x0000B001, /*!< 0x0000B001 */ + + /* Prime sensor */ + SENSOR_PS5270 = 0x0000C000, /*!< 0x0000C000 */ + SENSOR_PS5250 = 0x0000C001, /*!< 0x0000C001 */ + SENSOR_PS5260 = 0x0000C002, /*!< 0x0000C002 */ + + /* Customized Sensor */ + SENSOR_CUSTOM_FIRST = 0x00010000, /*!< 0x00010000 */ + + /* ADI Decoder */ + DECODER_ADV7403 = 0x80000000, /*!< 0x80000000 */ + DECODER_ADV7441A = 0x80000001, /*!< 0x80000001 */ + DECODER_ADV7443 = 0x80000002, /*!< 0x80000002 */ + + /* RICHNEX Decoder */ + DECODER_RN6240 = 0x80001000, /*!< 0x80001000 */ + + /* TI Decoder */ + DECODER_TVP5150 = 0x80002000, /*!< 0x80002000 */ + + /* Techwell Decoder */ + DECODER_TW2864 = 0x80003000, /*!< 0x80003000 */ + DECODER_TW9910 = 0x80003001, /*!< 0x80003001 */ + + DECODER_GS2970 = 0x80004000, /*!< 0x80004000 */ + + /* Toshiba Decoder */ + DECODER_TC358840 = 0x80005000, /*!< 0x80005000 */ + + /* Lontium Decoder */ + DECODER_LT6911 = 0x80006000, /*!< 0x80006000 */ + + /* Dummy Decoder */ + DECODER_AMBDD = 0x8FFFFFFF, /*!< 0x8FFFFFFF */ +}; + +enum vindev_set_type { + VINDEV_SET_AGC_ONLY = 0, /*!< 0 */ + VINDEV_SET_SHT_ONLY = 1, /*!< 1 */ + VINDEV_SET_AGC_SHT = 2, /*!< 2 */ +}; +/*! @} */ /* End of iav-ioctl-vin-helper */ + + +/* ==========================================================================*/ +/*! @addtogroup iav-ioctl-vin-struct + * @{ + */ +struct vindev_devinfo { + unsigned int vsrc_id; /*!< Source ID */ + unsigned int vinc_id; /*!< VIN controller ID */ + char name[32]; /*!< The name of the VIN source */ + unsigned int dev_type; /*!< The type of the VIN source, @sa vindev_type */ + unsigned int sub_type; /*!< VIN source sub type, @sa vindev_subtype */ + unsigned int sensor_id; /*!< Sensor ID */ + unsigned int vsrc_num; /*!< Total VIN Source number registered */ + unsigned int vsrc_ctx_switch_cap : 1; /*!< Possibility to support sensor context switch */ + unsigned int reserved0 : 31; +}; + +struct vindev_mode { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int video_mode; /*!< Video mode, @sa amba_video_mode */ + unsigned int hdr_mode; /*!< HDR mode, @sa amba_video_hdr_mode */ + unsigned int bits; /*!< Bits depth */ + unsigned int vsrc_ctx_auto_switch; /*!< Enable sensor context auto switch */ +}; + +struct vindev_fps { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int fps; /*!< Video frame rate, @sa amba_video_fps */ +}; + +struct vindev_video_info { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + struct amba_video_info info; /*!< Video infomation of the current VIN source */ +}; + +struct vindev_shutter { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vsrc_ctx; /*!< Context ID of current Sensor */ + unsigned int shutter; /*!< The parameter shutter_time is expressed in Q9 format, which is 512000000*time_in_sec. + For example, 1/30 sec can be expressed as 512000000/30 = 17066667 = 0x1046aab */ +}; + +struct vindev_shutter_row { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int shutter_row; /*!< Shutter Row */ +}; + +struct vindev_agc_shutter { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vsrc_ctx; /*!< Context ID of current Sensor */ + unsigned int shutter_row; /*!< Shutter Row */ + unsigned int agc_idx; /*!< AGC index of the current VIN source */ + unsigned int mode; /*!< @sa vindev_set_type */ +}; + +struct vindev_agc { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vsrc_ctx; /*!< Context ID of current Sensor */ + unsigned int agc; /*!< AGC value of the current VIN source */ + unsigned int agc_max; /*!< AGC max value of the current VIN source */ + unsigned int agc_min; /*!< AGC min value of the current VIN source */ + unsigned int agc_step; /*!< AGC step of the current VIN source */ + unsigned int wdr_again_idx_min; /*!< Minimum index of analog gain for sensor WDR mode */ + unsigned int wdr_again_idx_max; /*!< Maximum index of analog gain for sensor WDR mode */ + unsigned int wdr_dgain_idx_min; /*!< Minimum index of digital gain for sensor WDR mode */ + unsigned int wdr_dgain_idx_max; /*!< Maximum index of digital gain for sensor WDR mode */ +}; + +struct vindev_mirror { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int pattern; /*!< Mirror pattern for the sensor, @sa amba_vindev_mirror_pattern_e */ + unsigned int bayer_pattern; /*!< Bayer pattern for the sensor, @sa amba_vindev_bayer_pattern_e */ +}; + +struct vindev_reg { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int addr; /*!< Register DRAM address */ + unsigned int data; /*!< Register Value */ +}; + +struct vindev_eisinfo { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vb_time; /*!< Vb time, ns */ + unsigned short sensor_cell_width; /*!< Sensor cell width, um * 100 */ + unsigned short sensor_cell_height; /*!< Sensor cell height, um * 100*/ + unsigned char column_bin; /*!< Column of binning pixels */ + unsigned char row_bin; /*!< Row of binning pixels */ +}; + +struct vindev_wdr_gain_info { + unsigned int vsrc_id; + unsigned int vsrc_ctx; + unsigned int gain_idx; +}; + +struct vindev_aaa_info { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int sensor_id; /*!< Sensor ID of the current VIN */ + unsigned int bayer_pattern; /*!< Bayer pattern of current VIN */ + unsigned int agc_max; /*!< AGC max value of the current VIN source */ + unsigned int agc_min; /*!< AGC min value of the current VIN source */ + unsigned int agc_step; /*!< The minimum AGC step unit */ + unsigned int wdr_again_idx_min; /*!< Minimum index of analog gain for sensor WDR mode */ + unsigned int wdr_again_idx_max; /*!< Maximum index of analog gain for sensor WDR mode */ + unsigned int wdr_dgain_idx_min; /*!< Minimum index of digital gain for sensor WDR mode */ + unsigned int wdr_dgain_idx_max; /*!< Maximum index of digital gain for sensor WDR mode */ + unsigned int hdr_mode; /*!< HDR mode of current VIN */ + unsigned int hdr_long_offset; /*!< Line offset of the longest exposure frame */ + unsigned int hdr_short1_offset; /*!< Line offset of the medium exposure frame */ + unsigned int hdr_short2_offset; /*!< Line offset of the above medium exposure frame */ + unsigned int hdr_short3_offset; /*!< Line offset of the shortest exposure frame */ + unsigned int pixel_size; /*!< Pixel size in micro meter of the current sensor */ + unsigned int dual_gain_mode; /*!< Flag to indicate if the current VIN supports the dual gain mode */ + unsigned int line_time; /*!< The time duration of each capture line */ + unsigned int vb_time; /*!< The time duration of video blank */ + unsigned int ll_mode; /*!< ll mode */ + unsigned int sht0_max; /*!< The maximum shutter value */ + unsigned int sht1_max; /*!< The maximum shutter value */ + unsigned int sht2_max; /*!< The maximum shutter value */ + unsigned int sht0_min; /*!< The minimum shutter value */ + unsigned int sht1_min; /*!< The minimum shutter value */ + unsigned int sht2_min; /*!< The minimum shutter value */ + unsigned int wdr0_ratio; /*!< long:short1 ratio */ + unsigned int wdr1_ratio; /*!< short1:short2 ratio */ + unsigned int wdr2_ratio; /*!< short2:short3 ratio */ +}; + +struct vindev_dgain_ratio { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vsrc_ctx; /*!< Context ID of current Sensor */ + unsigned int r_ratio; /*!< Value of r_ratio */ + unsigned int gr_ratio; /*!< Value of gr_ratio */ + unsigned int gb_ratio; /*!< Value of gb_ratio */ + unsigned int b_ratio; /*!< Value of b_ratio */ +}; + +struct vindev_chip_status { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + int temperature; /*!< Chip temperature */ + int access_status; /*!< Access status */ +}; +/*! @} */ /* End of iav-ioctl-vin-struct */ + + +/*! @addtogroup iav-ioctl-vin-helper */ +#define VINDEV_WDR_CFG_DELAY_MAX 8 + +/*! @addtogroup iav-ioctl-vin-struct + * @{ + */ +struct vindev_wdr_gp_s { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vsrc_ctx; /*!< Context ID of current Sensor */ + unsigned int l; + unsigned int s1; + unsigned int s2; + unsigned int s3; + unsigned int s1_offset; + unsigned int s2_offset; +}; + +struct vindev_wdr_gp_info { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int vsrc_ctx; /*!< Context ID of current Sensor */ + struct vindev_wdr_gp_s shutter_gp; /*!< Shutter */ + struct vindev_wdr_gp_s again_gp; /*!< Again */ + struct vindev_wdr_gp_s dgain_gp; /*!< Dgain */ + struct vindev_wdr_gp_s rhs_gp; /*!< RHS */ +}; +/*! @} */ /* End of iav-ioctl-vin-struct */ + + +/*! @addtogroup iav-ioctl-vin-helper + * @{ + */ +#define VINDEV_SHT_AGC_DELAY_MAX 8 +#define VINDEV_SHT_AGC_DELAY_INVALID VINDEV_SHT_AGC_DELAY_MAX +#define VINDEV_SHT_AGC_PARAM_NUM 4 +/*! @} */ /* End of iav-ioctl-vin-struct */ + +/*! @addtogroup iav-ioctl-vin-struct + * @{ + */ +struct vindev_sht_agc_seq { + unsigned short vsrc_id; + unsigned short max_exposure_num; + unsigned int shutter_delays[VINDEV_SHT_AGC_PARAM_NUM]; // unit: vsync + unsigned int again_delays[VINDEV_SHT_AGC_PARAM_NUM]; // unit: vsync + unsigned int dgain_delays[VINDEV_SHT_AGC_PARAM_NUM]; // unit: vsync +}; + +struct vindev_ae_check { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + char ae_check_flag; /*!< AE check flag */ +}; + +struct vindev_stream_mode { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + char stream_mode; /*!< steam mode */ +}; + +struct vindev_low_light_info { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ + unsigned int ll_mode; /*!< Low light mode */ +}; + +struct vindev_switch_vsrc_ctx { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ +}; + +struct vindev_lock_vsrc_ctx_frame_cnt { + unsigned int vsrc_id; /*!< Source ID of the current VIN */ +}; +/*! @} */ /* End of iav-ioctl-vin-struct */ + +#ifdef __cplusplus +} +#endif + +#endif //__IAV_VIN_IOCTL_H__ + diff --git a/include/ambarella/iav_vin_ioctl.h b/include/ambarella/iav_vin_ioctl.h new file mode 100644 index 0000000..96a2520 --- /dev/null +++ b/include/ambarella/iav_vin_ioctl.h @@ -0,0 +1,284 @@ +/* + * iav_vin_ioctl.h + * + * History: + * 2013/09/04 - [Cao Rongrong] Created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_VIN_IOCTL_H__ +#define __IAV_VIN_IOCTL_H__ + +/*! @file iav_vin_ioctl.h + * @brief This file defines IAV Video Input Configuration IOCTL api. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ==========================================================================*/ +#include <linux/ioctl.h> +#include"iav_vin_common.h" + +/*! @addtogroup iav-ioctl-vin-helper + * @{ + */ + +/* ==========================================================================*/ +#define VINIOC_MAGIC 's' +#define VIN_IO(nr) _IO(VINIOC_MAGIC, nr) +#define VIN_IOR(nr, size) _IOR(VINIOC_MAGIC, nr, size) +#define VIN_IOW(nr, size) _IOW(VINIOC_MAGIC, nr, size) +#define VIN_IOWR(nr, size) _IOWR(VINIOC_MAGIC, nr, size) + +enum { + IOC_VIN_DEVINFO = 0x01, /*!< 0x01 */ + IOC_VIN_MODE = 0x03, /*!< 0x03 */ + IOC_VIN_FPS = 0x04, /*!< 0x04 */ + IOC_VIN_VIDEOINFO = 0x05, /*!< 0x05 */ + IOC_VIN_SHUTTER = 0x06, /*!< 0x06 */ + IOC_VIN_AGC = 0x07, /*!< 0x07 */ + IOC_VIN_AGC_SHUTTER = 0x08, /*!< 0x08 */ + IOC_VIN_DGAIN_RATIO = 0x09, /*!< 0x09 */ + IOC_VIN_MIRROR = 0x0A, /*!< 0x0A */ + IOC_VIN_EISINFO = 0x0B, /*!< 0x0B */ + IOC_VIN_REG = 0x0C, /*!< 0x0C */ + IOC_VIN_SHUTTER2ROW = 0x0D, /*!< 0x0D */ + IOC_VIN_WDR_AGAIN_INDEX = 0x0E, /*!< 0x0E */ + IOC_VIN_WDR_AGAIN_INDEX_GP = 0x0F, /*!< 0x0F */ + IOC_VIN_WDR_DGAIN_INDEX_GP = 0x10, /*!< 0x10 */ + IOC_VIN_WDR_SHUTTER_ROW_GP = 0x11, /*!< 0x11 */ + IOC_VIN_WDR_SHUTTER2ROW = 0x12, /*!< 0x12 */ + IOC_VIN_AAAINFO = 0x13, /*!< 0x13 */ + IOC_VIN_CHIP_STATUS = 0x14, /*!< 0x14 */ + IOC_VIN_WDR_ROW_GP = 0x15, /*!< 0x15 */ + IOC_VIN_SET_AE_CHECK = 0x16, /*!< 0x16 */ + IOC_VIN_PENDING_SHT_AGC = 0x17, /*!< 0x17 */ + IOC_VIN_PENDING_SHT_AGC_SEQ = 0x18, /*!< 0x18 */ + IOC_VIN_AAA_COMPENSATION = 0x19, /*!< 0x19 */ + IOC_VIN_SET_STREAM_MODE = 0x1A, /*!< 0x1A */ + IOC_VIN_SET_LOW_LIGHT_MODE = 0x1B, /*!< 0x1B */ + IOC_VIN_SWITCH_VSRC_CTX = 0x1C, /*!< 0x1C */ + IOC_VIN_LOCK_VSRC_CTX_FRAME_CNT = 0x1D, /*!< 0x1D */ +}; +/*! @} */ /* End of iav-ioctl-vin-helper */ + +/*! @addtogroup iav-ioctl-vin-api + * @{ + */ +/* ==========================================================================*/ +/*! + * This API can be used to retrieve the current active source identifier, the source type (sensor or YUV input), and the name of the source. + */ +#define IAV_IOC_VIN_GET_DEVINFO VIN_IOR(IOC_VIN_DEVINFO, struct vindev_devinfo *) + +/*! + * This API can be used to set the current active source mode. + * For video mode, @b AMBA_VIDEO_MODE_AUTO will detect the input format, and will select the default video mode for the sensor. + * Please refer to @link iav_common.h iav_common.h @endlink for more video modes. + */ +#define IAV_IOC_VIN_SET_MODE VIN_IOW(IOC_VIN_MODE, struct vindev_mode *) + +/*! + * This API can be used to get the current active source mode. + * For video mode, @b AMBA_VIDEO_MODE_AUTO will detect the input format, and will select the default video mode for the sensor. + * Please refer to @link iav_common.h iav_common.h @endlink for more video modes. + */ +#define IAV_IOC_VIN_GET_MODE VIN_IOR(IOC_VIN_MODE, struct vindev_mode *) + +/*! + * This API can be used to set the current active source video frame rate. This API is valid only when the source is RGB sensor input. + * The frame rate (frame length) can be directly compared with shutter time. + * Please refer to @link iav_common.h iav_common.h @endlink for more frame rate macro definitions. + */ +#define IAV_IOC_VIN_SET_FPS VIN_IOW(IOC_VIN_FPS, struct vindev_fps *) + +/*! + * This API can be used to get the current active source video frame rate. This API is valid only when the source is RGB sensor input. + * The frame rate (frame length) can be directly compared with shutter time. + * The parameter fps is expressed as frame length, or frame interval, in Q9 format, which is 512000000*time_in_sec. For example, + * 30 fps can be expressed as 512000000 * 1/30 = 17066667 = 0x1046aab. + * Please refer to @link iav_common.h iav_common.h @endlink for more frame rate macro definitions. + */ +#define IAV_IOC_VIN_GET_FPS VIN_IOR(IOC_VIN_FPS, struct vindev_fps *) + +/*! + * This API can be used to retrieve the current active source video information + */ +#define IAV_IOC_VIN_GET_VIDEOINFO VIN_IOR(IOC_VIN_VIDEOINFO, struct vindev_video_info *) + +/*! + * This API can be used to configure the current active sensor shutter time in Q9 format. + * The shutter time can be directly compared with the frame rate (frame length). + */ +#define IAV_IOC_VIN_SET_SHUTTER VIN_IOW(IOC_VIN_SHUTTER, struct vindev_shutter *) + +/*! + * This API can be used to get the current active sensor shutter time in Q9 format. + * The shutter time can be directly compared with the frame rate (frame length). + */ +#define IAV_IOC_VIN_GET_SHUTTER VIN_IOR(IOC_VIN_SHUTTER, struct vindev_shutter *) + +/*! + * This API can be used to configure the current active sensor AGC information. + */ +#define IAV_IOC_VIN_SET_AGC VIN_IOW(IOC_VIN_AGC, struct vindev_agc *) + +/*! + * This API can be used to get the current active sensor AGC information. + */ +#define IAV_IOC_VIN_GET_AGC VIN_IOR(IOC_VIN_AGC, struct vindev_agc *) + +/*! + * This API can be used to configure the readout mode of the sensor. The mirror pattern decides whether to + * read the pixels from the default order or to reverse the order in row style or column style or both. + * The need for sensor mirroring has been diminished somewhat by the CV22's encoding rotation capability. + * Please refer to the @link IAV_IOC_SET_STREAM_CONFIG IAV_IOC_SET_STREAM_CONFIG(IAV_STMCFG_FORMAT) @endlink API + */ +#define IAV_IOC_VIN_SET_MIRROR VIN_IOW(IOC_VIN_MIRROR, struct vindev_mirror *) + +/*! + * This API can be used to get the read-out mode of the sensor. The mirror pattern decides whether to read + * the pixels from the default order or to reverse the order in a row or column style or both. + */ +#define IAV_IOC_VIN_GET_MIRROR VIN_IOR(IOC_VIN_MIRROR, struct vindev_mirror *) + +/*! + * This API can be used to get the 3A algorithm required information from the sensor driver. + */ +#define IAV_IOC_VIN_GET_AAAINFO VIN_IOR(IOC_VIN_AAAINFO, struct vindev_aaa_info *) + +/*! + * This API can be used to set the current active sensor AGC index to the AGC Table. + */ +#define IAV_IOC_VIN_SET_AGC_SHUTTER VIN_IOW(IOC_VIN_AGC_SHUTTER, struct vindev_agc_shutter *) + +/*! + * This API can be used to set the current active sensor Dgain. + */ +#define IAV_IOC_VIN_SET_DGAIN_RATIO VIN_IOW(IOC_VIN_DGAIN_RATIO, struct vindev_dgain_ratio *) + +/*! + * This API can be used to get the current active sensor Dgain. + */ +#define IAV_IOC_VIN_GET_DGAIN_RATIO VIN_IOR(IOC_VIN_DGAIN_RATIO, struct vindev_dgain_ratio *) + +/*! + * This API can be used to set the current active sensor EIS information. + */ +#define IAV_IOC_VIN_GET_EISINFO VIN_IOR(IOC_VIN_EISINFO, struct vindev_eisinfo *) + +/*! + * This API can be used to set the current active sensor register. + */ +#define IAV_IOC_VIN_SET_REG VIN_IOW(IOC_VIN_REG, struct vindev_reg *) + +/*! + * This API can be used to get the current active sensor register. + */ +#define IAV_IOC_VIN_GET_REG VIN_IOR(IOC_VIN_REG, struct vindev_reg *) + +/*! + * This API can be used to set the current active sensor chip status. + */ +#define IAV_IOC_VIN_GET_CHIP_STATUS VIN_IOR(IOC_VIN_CHIP_STATUS, struct vindev_chip_status *) + +/*! + * This API can be used to set the current active sensor AE check flag. + */ +#define IAV_IOC_VIN_SET_AE_CHECK VIN_IOW(IOC_VIN_SET_AE_CHECK, struct vindev_ae_check *) + +/*! + * This API can be used to set the current active sensor shutter row. + */ +#define IAV_IOC_VIN_SHUTTER2ROW VIN_IOWR(IOC_VIN_SHUTTER2ROW, struct vindev_shutter_row *) + +/*! + * This API can be used to get the current active WDR sensor shutter row. + */ +#define IAV_IOC_VIN_GET_WDR_SHUTTER_ROW_GP VIN_IOR(IOC_VIN_WDR_SHUTTER_ROW_GP, struct vindev_wdr_gp_s *) + +/*! + * This API can be used to get the current active WDR sensor AGC index. + */ +#define IAV_IOC_VIN_GET_WDR_AGAIN_INDEX_GP VIN_IOR(IOC_VIN_WDR_AGAIN_INDEX_GP, struct vindev_wdr_gp_s *) + +/*! + * This API can be used to get the current active WDR sensor Dgain. + */ +#define IAV_IOC_VIN_GET_WDR_DGAIN_INDEX_GP VIN_IOR(IOC_VIN_WDR_DGAIN_INDEX_GP, struct vindev_wdr_gp_s *) + +/*! + * This API can be used to set the current active WDR sensor shutter row. + */ +#define IAV_IOC_VIN_WDR_SHUTTER2ROW VIN_IOWR(IOC_VIN_WDR_SHUTTER2ROW, struct vindev_wdr_gp_s *) + +/*! + * This API can be used to set the current active WDR sensor parameters. + */ +#define IAV_IOC_VIN_SET_WDR_GP VIN_IOW(IOC_VIN_WDR_ROW_GP, struct vindev_wdr_gp_info *) + + +#define IAV_IOC_VIN_SET_PENDING_SHT_AGC VIN_IOW(IOC_VIN_PENDING_SHT_AGC, struct vindev_wdr_gp_info *) +#define IAV_IOC_VIN_SET_PENDING_SHT_AGC_SEQ VIN_IOW(IOC_VIN_PENDING_SHT_AGC_SEQ, struct vindev_sht_agc_seq *) + +/*! + * This API can be used to set the current active AAA compensation. + */ +#define IAV_IOC_VIN_AAA_COMPENSATION VIN_IOWR(IOC_VIN_AAA_COMPENSATION, struct vindev_wdr_gp_info *) + +/*! + * This API can be used to set the current active sensor into test stream mode. + */ +#define IAV_IOC_VIN_SET_STREAM_MODE VIN_IOW(IOC_VIN_SET_STREAM_MODE, struct vindev_stream_mode *) + +/*! + * This API can be used to set the current active sensor low light mode. + */ +#define IAV_IOC_VIN_SET_LOW_LIGHT_MODE VIN_IOW(IOC_VIN_SET_LOW_LIGHT_MODE, struct vindev_low_light_info *) + +/*! + * This API can be used to switch contexts for sensors with dual contexts supported like AR0230. + */ +#define IAV_IOC_VIN_SWITCH_VSRC_CTX VIN_IOW(IOC_VIN_SWITCH_VSRC_CTX, struct vindev_switch_vsrc_ctx *) + +/*! + * This API can be used to bind internal frame count to each vsrc context for sensors with dual contexts supported like AR0230. + */ +#define IAV_IOC_VIN_LOCK_VSRC_CTX_FRAME_CNT VIN_IOW(IOC_VIN_LOCK_VSRC_CTX_FRAME_CNT, struct vindev_lock_vsrc_ctx_frame_cnt *) + +/* ==========================================================================*/ +/*! @} */ /* End of iav-ioctl-vin-api */ + + +#ifdef __cplusplus +} +#endif + +#endif //__IAV_VIN_IOCTL_H__ + diff --git a/include/ambarella/iav_vout_common.h b/include/ambarella/iav_vout_common.h new file mode 100644 index 0000000..c72d9ce --- /dev/null +++ b/include/ambarella/iav_vout_common.h @@ -0,0 +1,478 @@ +/* + * iav_vout_common.h + * + * History: + * 2008/04/02 - [Oliver Li] created file + * 2011/06/10 - [Jian Tang] modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_VOUT_COMMON_H__ +#define __IAV_VOUT_COMMON_H__ + +/*! @file iav_vout_common.h + * @brief This file defines video output configuration ioctl + */ + + +#ifdef __cplusplus +extern "C" { +#endif + +/*! @addtogroup iav-ioctl-vout-helper + * @{ + */ +#define VOUT_LCD 0 +#define VOUT_TV 1 +#define VOUT_NUM 2 + +#define VOUT_TYPE_LCD 0 +#define VOUT_TYPE_HDMI 1 +#define VOUT_TYPE_CVBS 2 +#define VOUT_TYPE_MIPI_DSI 3 +#define VOUT_TYPE_MIPI_CSI 4 +#define VOUT_TYPE_FPD_LINK 5 +#define VOUT_TYPE_SLVS 6 + +/* VOUT flip type, it's related to DSP command, so don't change the order */ +enum { + VOUT_FLIP_NO = 0, /*!< 0, No flip */ + VOUT_FLIP_HV, /*!< 1, Horizontal and Vertical */ + VOUT_FLIP_H, /*!< 2, Horizontal */ + VOUT_FLIP_V, /*!< 3, Vertical */ +}; + +/* HDMI color space, it's related to AVI InfoFrame, so don't change the order */ +enum { + VOUT_HDMI_CS_RGB = 0, /*!< 0 */ + VOUT_HDMI_CS_YCBCR_422, /*!< 1 */ + VOUT_HDMI_CS_YCBCR_444, /*!< 2 */ +}; + +enum { + VOUT_HDMI_AUTOSCAN = 0, /*!< 0 */ + VOUT_HDMI_OVERSCAN, /*!< 1 */ + VOUT_HDMI_UNDERSCAN, /*!< 2 */ +}; +/*! @} */ /* End of iav-ioctl-vout-helper */ + + +/*! @addtogroup iav-ioctl-vout-struct + * @{ + */ +struct voutdev_format { + unsigned int id; /*!< VOUT ID */ + unsigned int type; /*!< sink type: CVBS, HDMI or LCD */ + unsigned int mode; /*!< VOUT mode (resolution index) */ + unsigned int interlaced;/*!< VOUT interlaced or progressive */ + unsigned int fps; /*!< VOUT FPS */ + unsigned int vout_append_enable : 1; /*!< VOUT append enable flag */ + unsigned int reserved : 31; +}; + +struct vout_params { + unsigned int id; /*!< VOUT ID */ + struct iav_rect vout_win; /*!< VOUT window size */ + struct iav_rect video_win; /*!< VOUT video size */ + struct iav_rect osd_win; /*!< VOUT OSD size */ + struct iav_rect osd_rescaler_win; /*!< VOUT OSD rescale output size */ + unsigned int fps; /*!< VOUT frame rate */ + + unsigned int video_rotate : 1; /*!< VOUT Video rotate */ + unsigned int video_flip : 2; /*!< VOUT Video flip */ + unsigned int osd_flip : 2; /*!< VOUT OSD flip */ + unsigned int osd_rescaler_en : 1; /*!< VOUT OSD rescaler enable flag */ + unsigned int video_enable : 1; /*!< VOUT Video enable flag */ + unsigned int osd_enable : 1; /*!< VOUT OSD enable flag */ + unsigned int own_mixer : 1; /*!< VOUT Own mixer flag */ + unsigned int reserved : 23; +}; + +struct vout_onoff { + unsigned int id; /*!< VOUT ID */ + unsigned int on; /*!< 0: off, 1: on */ +}; +/*! @} */ /* End of iav-ioctl-vout-struct */ +/* ==========================================================================*/ + +/*! @addtogroup iav-ioctl-vout-helper + * @{ + */ + +#define AMBA_VOUT_NAME_LENGTH (32) + +#define AMBA_VOUT_SOURCE_TYPE_DVE (1 << 0) +#define AMBA_VOUT_SOURCE_TYPE_DIGITAL (1 << 1) +#define AMBA_VOUT_SOURCE_TYPE_HDMI (1 << 2) +#define AMBA_VOUT_SOURCE_TYPE_MIPI (1 << 3) + +#define AMBA_VOUT_SOURCE_STARTING_ID (0) +#define AMBA_VOUT_SINK_STARTING_ID (0) + +enum amba_vout_display_device_type { + AMBA_VOUT_DISPLAY_DEVICE_LCD = 0, + AMBA_VOUT_DISPLAY_DEVICE_HDMI, +}; + +enum amba_vout_output_port_id { + AMBA_VOUT_OUTPUT_DVE = AMBA_VOUT_SOURCE_TYPE_DVE, + AMBA_VOUT_OUTPUT_DIGITAL = AMBA_VOUT_SOURCE_TYPE_DIGITAL, + AMBA_VOUT_OUTPUT_HDMI = AMBA_VOUT_SOURCE_TYPE_HDMI, + AMBA_VOUT_OUTPUT_MIPI = AMBA_VOUT_SOURCE_TYPE_MIPI, +}; + +enum amba_vout_sink_type { + AMBA_VOUT_SINK_TYPE_AUTO = 0, + AMBA_VOUT_SINK_TYPE_CVBS = ((0 << 16) | AMBA_VOUT_SOURCE_TYPE_DVE), + AMBA_VOUT_SINK_TYPE_SVIDEO = ((1 << 16) | AMBA_VOUT_SOURCE_TYPE_DVE), + AMBA_VOUT_SINK_TYPE_YPBPR = ((2 << 16) | AMBA_VOUT_SOURCE_TYPE_DVE), + AMBA_VOUT_SINK_TYPE_HDMI = ((0 << 16) | AMBA_VOUT_SOURCE_TYPE_HDMI), + AMBA_VOUT_SINK_TYPE_DIGITAL = ((0 << 16) | AMBA_VOUT_SOURCE_TYPE_DIGITAL), + AMBA_VOUT_SINK_TYPE_MIPI = ((0 << 16) | AMBA_VOUT_SOURCE_TYPE_MIPI), +}; + +enum amba_vout_display_input { + AMBA_VOUT_INPUT_FROM_MIXER = 0, + AMBA_VOUT_INPUT_FROM_SMEM, +}; + +enum amba_vout_flip_info { + AMBA_VOUT_FLIP_NORMAL = 0, + AMBA_VOUT_FLIP_HV, + AMBA_VOUT_FLIP_HORIZONTAL, + AMBA_VOUT_FLIP_VERTICAL, +}; + +enum amba_vout_rotate_info { + AMBA_VOUT_ROTATE_NORMAL, + AMBA_VOUT_ROTATE_90, +}; + +enum amba_vout_tailored_info { + AMBA_VOUT_OSD_NO_CSC = 0x01, /*!< No Software CSC */ + AMBA_VOUT_OSD_AUTO_COPY = 0x02, /*!< Auto copy to other fb */ +}; + +enum amba_vout_mixer_csc { + AMBA_VOUT_MIXER_DISABLE = 0x00, /*!< No Mixer CSC */ + AMBA_VOUT_MIXER_ENABLE_FOR_VIDEO = 0x01, /*!< Mixer CSC for video */ + AMBA_VOUT_MIXER_ENABLE_FOR_OSD = 0x02, /*!< Mixer CSC for OSD */ +}; + +enum amba_vout_hdmi_color_space { + AMBA_VOUT_HDMI_CS_AUTO = 0, + AMBA_VOUT_HDMI_CS_RGB, + AMBA_VOUT_HDMI_CS_YCBCR_444, + AMBA_VOUT_HDMI_CS_YCBCR_422, +}; + +enum amba_vout_hdmi_overscan { + AMBA_VOUT_HDMI_OVERSCAN_AUTO = 0, + AMBA_VOUT_HDMI_NON_FORCE_OVERSCAN, + AMBA_VOUT_HDMI_FORCE_OVERSCAN, +}; + +enum amba_vout_sink_state { + AMBA_VOUT_SINK_STATE_IDLE = 0, + AMBA_VOUT_SINK_STATE_RUNNING, + AMBA_VOUT_SINK_STATE_SUSPENDED, +}; + +enum amba_vout_lcd_mode_info { + AMBA_VOUT_LCD_MODE_DISABLE = 0, + AMBA_VOUT_LCD_MODE_1COLOR_PER_DOT, + AMBA_VOUT_LCD_MODE_3COLORS_PER_DOT, + AMBA_VOUT_LCD_MODE_RGB565, + AMBA_VOUT_LCD_MODE_3COLORS_DUMMY_PER_DOT, + AMBA_VOUT_LCD_MODE_RGB888, +}; + +enum amba_vout_lcd_seq_info { + AMBA_VOUT_LCD_SEQ_R0_G1_B2 = 0, + AMBA_VOUT_LCD_SEQ_R0_B1_G2, + AMBA_VOUT_LCD_SEQ_G0_R1_B2, + AMBA_VOUT_LCD_SEQ_G0_B1_R2, + AMBA_VOUT_LCD_SEQ_B0_R1_G2, + AMBA_VOUT_LCD_SEQ_B0_G1_R2, +}; + +enum amba_vout_lcd_clk_edge_info { + AMBA_VOUT_LCD_CLK_RISING_EDGE = 0, + AMBA_VOUT_LCD_CLK_FALLING_EDGE, +}; + +enum amba_vout_lcd_hvld_pol_info { + AMBA_VOUT_LCD_HVLD_POL_LOW = 0, + AMBA_VOUT_LCD_HVLD_POL_HIGH, +}; + +enum amba_vout_lcd_model { + AMBA_VOUT_LCD_MODEL_DIGITAL = 0, + AMBA_VOUT_LCD_MODEL_AUO27, + AMBA_VOUT_LCD_MODEL_P28K, + AMBA_VOUT_LCD_MODEL_TPO489, + AMBA_VOUT_LCD_MODEL_TPO648, + AMBA_VOUT_LCD_MODEL_TD043, + AMBA_VOUT_LCD_MODEL_WDF2440, + AMBA_VOUT_LCD_MODEL_1P3831, + AMBA_VOUT_LCD_MODEL_1P3828, + AMBA_VOUT_LCD_MODEL_EJ080NA, + AMBA_VOUT_LCD_MODEL_AT070TNA2, + AMBA_VOUT_LCD_MODEL_E330QHD, + AMBA_VOUT_LCD_MODEL_PPGA3, +}; + +enum amba_vout_sink_plug { + AMBA_VOUT_SINK_PLUGGED = 0, + AMBA_VOUT_SINK_REMOVED, +}; + +enum ddd_structure { + DDD_FRAME_PACKING = 0, + DDD_FIELD_ALTERNATIVE = 1, + DDD_LINE_ALTERNATIVE = 2, + DDD_SIDE_BY_SIDE_FULL = 3, + DDD_L_DEPTH = 4, + DDD_L_DEPTH_GRAPHICS_DEPTH = 5, + DDD_TOP_AND_BOTTOM = 6, + DDD_RESERVED = 7, + + DDD_SIDE_BY_SIDE_HALF = 8, + + DDD_UNSUPPORTED = 16, +}; +/*! @} */ /* End of iav-ioctl-vout-helper */ + +/*! @addtogroup iav-ioctl-vout-struct + * @{ + */ +struct amba_vout_bg_color_info { + u8 y; + u8 cb; + u8 cr; +}; + +struct amba_vout_video_size { + u32 specified; + u16 vout_width; /*!< Vout width */ + u16 vout_height; /*!< Vout height */ + u16 video_width; /*!< Video width */ + u16 video_height; /*!< Video height */ +}; + +struct amba_vout_video_offset { + u32 specified; + s16 offset_x; + s16 offset_y; +}; + +struct amba_vout_osd_size { + u16 width; + u16 height; +}; + +struct amba_vout_osd_rescale { + u32 enable; + u16 width; + u16 height; +}; + +struct amba_vout_osd_offset { + u32 specified; + s16 offset_x; + s16 offset_y; +}; + +struct amba_vout_lcd_info { + enum amba_vout_lcd_mode_info mode; + enum amba_vout_lcd_seq_info seqt; + enum amba_vout_lcd_seq_info seqb; + enum amba_vout_lcd_clk_edge_info dclk_edge; + enum amba_vout_lcd_hvld_pol_info hvld_pol; + u32 dclk_freq_hz; /*!< PLL_CLK_XXX */ + enum amba_vout_lcd_model model; +}; +/*! @} */ /* End of iav-ioctl-vout-struct */ + +/*! @addtogroup iav-ioctl-vout-helper */ +typedef enum { + COLORIMETRY_NO_DATA = 0, + COLORIMETRY_ITU601 = 1, + COLORIMETRY_ITU709 = 2, + COLORIMETRY_EXTENDED = 3, +} colorimetry_t; + +/*! @addtogroup iav-ioctl-vout-struct + * @{ + */ +typedef struct { + enum amba_video_mode vmode; + char name[32]; + + u32 pixel_clock; /*!< kHz */ + + u16 hsync_offset; /*!< pixels */ + u16 hsync_width; /*!< pixels */ + u16 h_blanking; /*!< pixels */ + u16 h_active; /*!< pixels */ + + u16 vsync_offset; /*!< lines */ + u16 vsync_width; /*!< lines */ + u16 v_blanking; /*!< lines */ + u16 v_active; /*!< lines */ + + u8 interlace; /*!< 1: Interlace; 0: Progressive */ + u8 hsync_polarity; /*!< 1: Positive; 0: Negative */ + u8 vsync_polarity; /*!< 1: Positive; 0: Negative */ + + u8 pixel_repetition; /*!< repetition times */ + u32 aspect_ratio; /*!< 16:9, 4:3, ... */ + colorimetry_t colorimetry; /*!< ITU601, ITU709 */ +} amba_hdmi_video_timing_t; + + +struct amba_video_sink_mode { + /* Sink */ + int id; /*!< Sink ID */ + u32 mode; /*!< enum amba_video_mode */ + u32 ratio; /*!< AMBA_VIDEO_RATIO */ + u32 bits; /*!< AMBA_VIDEO_BITS */ + u32 type; /*!< AMBA_VIDEO_TYPE */ + u32 format; /*!< AMBA_VIDEO_FORMAT */ + u32 frame_rate; /*!< AMBA_VIDEO_FPS */ + int csc_en; /*!< enable csc or not */ + struct amba_vout_bg_color_info bg_color; + enum amba_vout_display_input display_input; /*!< input from SMEM or Mixer */ + enum amba_vout_sink_type sink_type; + enum amba_vout_mixer_csc mixer_csc; + + /* Video */ + int video_en; /*!< enable video or not */ + struct amba_vout_video_size video_size; /*!< video size */ + struct amba_vout_video_offset video_offset; /*!< video offset */ + enum amba_vout_flip_info video_flip; /*!< flip */ + enum amba_vout_rotate_info video_rotate; /*!< rotate */ + + /* OSD */ + int fb_id; /*!< frame buffer id */ + struct amba_vout_osd_size osd_size; /*!< OSD size */ + struct amba_vout_osd_rescale osd_rescale; /*!< OSD rescale */ + struct amba_vout_osd_offset osd_offset; /*!< OSD offset */ + enum amba_vout_flip_info osd_flip; /*!< flip */ + enum amba_vout_rotate_info osd_rotate; /*!< rotate */ + enum amba_vout_tailored_info osd_tailor; /*!< no csc, auto copy */ + + /* Misc */ + u32 direct_to_dsp; /*!< bypass iav */ + struct amba_vout_lcd_info lcd_cfg; /*!< LCD only */ + enum amba_vout_hdmi_color_space hdmi_color_space;/*!< HDMI only */ + enum ddd_structure hdmi_3d_structure;/*!< HDMI only */ + enum amba_vout_hdmi_overscan hdmi_overscan; /*!< HDMI only */ + const amba_hdmi_video_timing_t *hdmi_displayer_timing; /*!< HDMI only */ +}; + +struct amba_vout_sink_info { + int id; /*!< Sink ID */ + int source_id; + char name[AMBA_VOUT_NAME_LENGTH]; + enum amba_vout_sink_type sink_type; + struct amba_video_sink_mode sink_mode; + enum amba_vout_sink_state state; + enum amba_vout_sink_plug hdmi_plug; + enum amba_video_mode hdmi_modes[32]; + enum amba_video_mode hdmi_native_mode; + u16 hdmi_native_width; + u16 hdmi_native_height; + enum amba_vout_hdmi_overscan hdmi_overscan; + +}; + +typedef struct iav_vout_fb_sel_s { + int vout_id; + int fb_id; +} iav_vout_fb_sel_t; + +typedef struct iav_vout_enable_video_s { + int vout_id; + int video_en; +} iav_vout_enable_video_t; + +typedef struct iav_vout_flip_video_s { + int vout_id; + int flip; +} iav_vout_flip_video_t; + +typedef struct iav_vout_rotate_video_s { + int vout_id; + int rotate; +} iav_vout_rotate_video_t; + +typedef struct iav_vout_enable_csc_s { + int vout_id; + int csc_en; +} iav_vout_enable_csc_t; + +typedef struct iav_vout_change_video_size_s { + int vout_id; + int width; + int height; +} iav_vout_change_video_size_t; + +typedef struct iav_vout_change_video_offset_s { + int vout_id; + int specified; + int offset_x; + int offset_y; +} iav_vout_change_video_offset_t; + +typedef struct iav_vout_flip_osd_s { + int vout_id; + int flip; +} iav_vout_flip_osd_t; + +typedef struct iav_vout_enable_osd_rescaler_s { + int vout_id; + int enable; + int width; + int height; +} iav_vout_enable_osd_rescaler_t; + +typedef struct iav_vout_change_osd_offset_s { + int vout_id; + int specified; + int offset_x; + int offset_y; +} iav_vout_change_osd_offset_t; +/*! @} */ /* End of iav-ioctl-vout-struct */ + +#ifdef __cplusplus +} +#endif + +#endif // __IAV_IOCTL_ARCH_H__ + + diff --git a/include/ambarella/iav_vout_ioctl.h b/include/ambarella/iav_vout_ioctl.h new file mode 100644 index 0000000..b2c1ec4 --- /dev/null +++ b/include/ambarella/iav_vout_ioctl.h @@ -0,0 +1,145 @@ +/* + * iav_vout_ioctl.h + * + * History: + * 2008/04/02 - [Oliver Li] created file + * 2011/06/10 - [Jian Tang] modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __IAV_VOUT_IOCTL_H__ +#define __IAV_VOUT_IOCTL_H__ + +/*! @file iav_vout_ioctl.h + * @brief This file defines video output configuration ioctl + */ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include <linux/ioctl.h> +#include "iav_vout_common.h" + +/*! @addtogroup iav-ioctl-vout-helper + * @{ + */ +#define VOUTIOC_MAGIC 'v' + +#define VOUT_IO(nr) _IO(VOUTIOC_MAGIC, nr) +#define VOUT_IOR(nr, size) _IOR(VOUTIOC_MAGIC, nr, size) +#define VOUT_IOW(nr, size) _IOW(VOUTIOC_MAGIC, nr, size) +#define VOUT_IOWR(nr, size) _IOWR(VOUTIOC_MAGIC, nr, size) +/*! @} */ /* End of iav-ioctl-vout-helper */ + +/*! @addtogroup iav-ioctl-vout-api + * @{ + */ + +/*! + * This API can be used to set the VOUT device format. + */ +#define IAV_IOC_VOUT_SET_MODE VOUT_IOW(0x01, struct voutdev_format) + +/*! + * This API can be used to get the params of VOUT. + */ +#define IAV_IOC_VOUT_GET_PARAMS VOUT_IOR(0x02, struct vout_params) + +/*! + * This API can be used to set the params of VOUT. + */ +#define IAV_IOC_VOUT_SET_PARAMS VOUT_IOW(0x03, struct vout_params) + +/*! + * This API can be used to turn on/off VOUT. + */ +#define IAV_IOC_VOUT_SWITCH_VIDEO VOUT_IOW(0x04, struct vout_onoff) + +/*! @} */ /* End of iav-ioctl-vout-api */ +/*===========================================================================*/ + +/*! @addtogroup iav-ioctl-vout-helper + * @{ + */ +/* + * general APIs - VOUTIOC_MAGIC + */ +enum { + // For VOUT, from 0x20 to 0x3F + IOC_VOUT_HALT = 0x20, + IOC_VOUT_SELECT_DEV = 0x21, + IOC_VOUT_CONFIGURE_SINK = 0x22, + IOC_VOUT_SELECT_FB = 0x23, + IOC_VOUT_ENABLE_VIDEO = 0x24, + IOC_VOUT_FLIP_VIDEO = 0x25, + IOC_VOUT_ROTATE_VIDEO = 0x26, + IOC_VOUT_ENABLE_CSC = 0x27, + IOC_VOUT_CHANGE_VIDEO_SIZE = 0x28, + IOC_VOUT_CHANGE_VIDEO_OFFSET = 0x29, + IOC_VOUT_FLIP_OSD = 0x2A, + IOC_VOUT_ENABLE_OSD_RESCALER = 0x2B, + IOC_VOUT_CHANGE_OSD_OFFSET = 0x2C, + IOC_VOUT_GET_SINK_NUM = 0x2D, + IOC_VOUT_GET_SINK_INFO = 0x2E, +}; + +#define _IAV_IO(IOCTL) _IO(VOUTIOC_MAGIC, IOCTL) +#define _IAV_IOR(IOCTL, param) _IOR(VOUTIOC_MAGIC, IOCTL, param) +#define _IAV_IOW(IOCTL, param) _IOW(VOUTIOC_MAGIC, IOCTL, param) +#define _IAV_IOWR(IOCTL, param) _IOWR(VOUTIOC_MAGIC, IOCTL, param) +/*! @} */ /* End of iav-ioctl-vout-helper */ + +/*! @addtogroup iav-ioctl-vout-api + * @{ + */ +#define IAV_IOC_VOUT_HALT _IAV_IOW(IOC_VOUT_HALT, int) +#define IAV_IOC_VOUT_SELECT_DEV _IAV_IOW(IOC_VOUT_SELECT_DEV, int) +#define IAV_IOC_VOUT_CONFIGURE_SINK _IAV_IOW(IOC_VOUT_CONFIGURE_SINK, struct amba_video_sink_mode *) +#define IAV_IOC_VOUT_SELECT_FB _IAV_IOW(IOC_VOUT_SELECT_FB, struct iav_vout_fb_sel_s *) +#define IAV_IOC_VOUT_ENABLE_VIDEO _IAV_IOW(IOC_VOUT_ENABLE_VIDEO, struct iav_vout_enable_video_s *) +#define IAV_IOC_VOUT_FLIP_VIDEO _IAV_IOW(IOC_VOUT_FLIP_VIDEO, struct iav_vout_flip_video_s *) +#define IAV_IOC_VOUT_ROTATE_VIDEO _IAV_IOW(IOC_VOUT_ROTATE_VIDEO, struct iav_vout_rotate_video_s *) +#define IAV_IOC_VOUT_ENABLE_CSC _IAV_IOW(IOC_VOUT_ENABLE_CSC, struct iav_vout_enable_csc_s *) +#define IAV_IOC_VOUT_CHANGE_VIDEO_SIZE _IAV_IOW(IOC_VOUT_CHANGE_VIDEO_SIZE, struct iav_vout_change_video_size_s *) +#define IAV_IOC_VOUT_CHANGE_VIDEO_OFFSET _IAV_IOW(IOC_VOUT_CHANGE_VIDEO_OFFSET, struct iav_vout_change_video_offset_s *) +#define IAV_IOC_VOUT_FLIP_OSD _IAV_IOW(IOC_VOUT_FLIP_OSD, struct iav_vout_flip_osd_s *) +#define IAV_IOC_VOUT_ENABLE_OSD_RESCALER _IAV_IOW(IOC_VOUT_ENABLE_OSD_RESCALER, struct iav_vout_enable_osd_rescaler_s *) +#define IAV_IOC_VOUT_CHANGE_OSD_OFFSET _IAV_IOW(IOC_VOUT_CHANGE_OSD_OFFSET, struct iav_vout_change_osd_offset_s *) +#define IAV_IOC_VOUT_GET_SINK_NUM _IAV_IOR(IOC_VOUT_GET_SINK_NUM, int *) +#define IAV_IOC_VOUT_GET_SINK_INFO _IAV_IOR(IOC_VOUT_GET_SINK_INFO, struct amba_vout_sink_info *) + +/*! @} */ /* End of iav-ioctl-vout-helper */ + +#ifdef __cplusplus +} +#endif + +#endif // __IAV_IOCTL_ARCH_H__ + + diff --git a/include/ambarella/img_dev.h b/include/ambarella/img_dev.h new file mode 100644 index 0000000..8373fe8 --- /dev/null +++ b/include/ambarella/img_dev.h @@ -0,0 +1,67 @@ +/* + * img_dev.c + * + * History: + * 2014/09/17 - [Bin Wang] Created this file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ +#ifndef __IMG_DEV_H__ +#define __IMG_DEV_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "devices.h" + +/* dc_iris.c */ +u32 dc_iris_is_supported(void); +int dc_iris_init(void); +int dc_iris_deinit(void); +int dc_iris_enable(void); +int dc_iris_disable(void); +int dc_iris_update_duty(int duty_cycle); + +/* ir_led.c */ +s32 ir_led_set_vsrc_id(u32 vsrc_id); +u32 ir_led_is_supported(void); +s32 ir_led_init(u32 init); +s32 ir_led_get_brightness(void); +s32 ir_led_set_brightness(s32 brightness); +s32 ir_led_get_state(void); +s32 ir_led_set_state(u32 value); +s32 ir_led_get_adc_value(u32 *value); +u32 ir_cut_is_supported(void); +s32 ir_cut_init(u32 init); +s32 ir_cut_set_state(u32 value); +s32 ir_cut_get_state(void); + +#ifdef __cplusplus +} +#endif + +#endif // __IMG_DEV_H__ diff --git a/include/ambarella/lib_data_process.h b/include/ambarella/lib_data_process.h new file mode 100644 index 0000000..e3f7375 --- /dev/null +++ b/include/ambarella/lib_data_process.h @@ -0,0 +1,351 @@ +/******************************************************************************* + * @file lib_data_process.h + * @brief This file shows the dproc library API. + * + * History: + * 2018/10/23 - [Hao Qian] created file + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#ifndef _DPROC_LIB_H +#define _DPROC_LIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#define AMBA_API __attribute__((visibility("default"))) + +/*! + * @addtogroup dproc-helper + * @{ + */ + +/*! + * @brief Define the layer type of dproc. + */ +enum dproc_layer_type { + DPROC_SSD_DETECTION_OUT = 0, /*!< for SSD */ + DPROC_YOLOV3_OUT = 1, /*!< for YOLOV3 or TINY_YOLOV3 */ + DPROC_TYPE_NUM, +}; + + +/*************** Share Structure ***************/ +/*! + * @brief Description of the parameters of the bounding box. + */ +typedef struct dproc_bbox_param_s { + float x_min; /*!< X-coordinate of starting point */ + float y_min; /*!< Y-coordinate of starting point */ + float x_max; /*!< X-coordinate of end point */ + float y_max; /*!< Y-coordinate of end point */ +} dproc_bbox_param_t; +/*************** Share Structure ***************/ + + +/*************** SSD detection_out ***************/ +/*! + * @brief Some debugging information for SSD. + */ +typedef struct dproc_ssd_class_dbg_info_s { + int num_bboxes_above_threshold; /*!< The number of bbox that exceed the threshold */ + int num_bboxes_post_nms; /*!< The number of bbox returned by nms() */ +} dproc_ssd_class_dbg_info_t; + +/*! + * @brief Description of the coordinate type of the bounding box. + */ +typedef enum amba_bbox_codetype_s { + AMBA_BBOX_CORNER = 0, + AMBA_BBOX_CENTER_SIZE = 1, /*!< The coordinate type of the bbox is CENTER */ + AMBA_BBOX_CORNER_SIZE = 2, /*!< The coordinate type of the bbox is CORNER */ + AMBA_BBOX_NUM_CODETYPE, +} amba_bbox_codetype_t; + +/*************** TF SSD Scale ***************/ +/*! + * @brief Description of the scale factors of SSD for TF. + */ +typedef struct ssd_tf_scale_factors_s { + uint32_t center_x_scale; /*!< The scale value of X-coordinate for the center point of bbox */ + uint32_t center_y_scale; /*!< The scale value of Y-coordinate for the center point of bbox */ + uint32_t width_scale; /*!< The scale value of the width of bbox */ + uint32_t height_scale; /*!< The scale value of the height of bbox */ +} ssd_tf_scale_factors_t; +/*************** TF SSD Scale ***************/ + +/*! + * @brief Description of the configuration of SSD detection output. + */ +typedef struct dproc_ssd_detection_output_config_s { + /* basic related */ + uint16_t img_width; /*!< the width of output image */ + uint16_t img_height; /*!< the height of output image */ + uint32_t num_classes; /*!< the number of classes */ + uint32_t background_label_id; /*!< the label id of background */ + uint32_t mbox_loc_num_elements; /*!< Number of all elements */ + uint32_t num_all_bboxes; /*!< Number of all bboxes */ + + /* detection related */ + float conf_threshold; /*!< the threshold for filter_bboxes */ + uint32_t keep_top_k; /*!< Keep the maximum number of objects */ + + /* nms related */ + float nms_threshold; /*!< the threshold for nms */ + uint32_t nms_top_k; /*!< keep the maximum number of objects by nms*/ + + /* bounding box related */ + /*! + * refer to struct @ref amba_bbox_codetype_s, SSD supports CENTER_SIZE + */ + amba_bbox_codetype_t code_type; + uint32_t share_location : 1; /*!< only supports True */ + uint32_t unnormalized : 1; /*!< whether the parameter is unnormalized */ + uint32_t reserved : 30; + + /* TF Related */ + /*! + * refer to struct @ref ssd_tf_scale_factors_s. + */ + ssd_tf_scale_factors_t scale_factors; + +} dproc_ssd_detection_output_config_t; + +/*! + * @brief Output parameters after running SSD. + */ +typedef struct dproc_run_ssd_detection_output_param_s { + uint8_t *mbox_loc; /*!< output from cavalry */ + uint8_t *mbox_conf_flatten; /*!< output from cavalry */ + + /*! + * Binary which is generated by CV offline tool. + */ + float *mbox_priorbox; +} dproc_run_ssd_detection_output_param_t; + +/*! + * @brief Description of the result of SSD detection output. + */ +typedef struct dproc_ssd_detection_output_result_s { + int label; /*!< label id */ + float score; /*!< score */ + + dproc_bbox_param_t bbox; /*!< refer to struct @ref dproc_bbox_param_s. */ +} dproc_ssd_detection_output_result_t; +/*************** SSD detection_out ***************/ + + +/*************** Yolov3 yolo layer ***************/ +/*! + * @brief The number of anchor for TINY_YOLOV3. It is a constant. + */ +#define TINY_YOLOV3_ANCHOR_NUM 12 + +/*! + * @brief The number of anchor for YOLOV3. It is a constant. + */ +#define YOLOV3_ANCHOR_NUM 18 + +/*! + * @brief The number of feature map for YOLOV3 or TINY_YOLOV3. + */ +typedef enum amba_yolov3_feature_type_s { + AMBA_YOLOV3_FEATURE_MAP_32 = 0, + AMBA_YOLOV3_FEATURE_MAP_16 = 1, + AMBA_YOLOV3_FEATURE_MAP_8 = 2, /*!< For TINY_YOLOV3 */ + AMBA_YOLOV3_FEATURE_NUM = 3, /*!< For YOLOV3 */ +} amba_yolov3_feature_type_t; + +/*! + * @brief Description of the configuration of YOLOV3 detection output. + */ +typedef struct dproc_yolov3_output_config_s { + /* basic related */ + uint16_t img_width; /*!< the width of output image */ + uint16_t img_height; /*!< the height of output image */ + uint32_t num_classes; /*!< the number of classes */ + + /* detection and nms threshold */ + float conf_threshold; /*!< the threshold for yolov3_layer */ + float nms_threshold; /*!< the threshold for nms */ + + /* anchors */ + float *anchors; /*!< Address of the storage anchor */ + + /* others */ + uint32_t tiny_enable : 1; /*!< default is full yolov3, use this to enable tiny_yolov3 */ + uint32_t unnormalized : 1; /*!< whether the parameter is unnormalized */ + uint32_t padding_disable : 1; /*!< whether padding is disabled */ + uint32_t reserved : 29; + +} dproc_yolov3_output_config_t; + +/*! + * @brief Description of the parameters of YOLOV3 output. + */ +typedef struct dproc_run_yolov3_output_param_s { + /*! + * Output from cavalry. + * YOLOV3 use 3 feature maps, TINY_YOLOV3 only use 2 feature maps. + */ + float *feature_map[AMBA_YOLOV3_FEATURE_NUM]; +} dproc_run_yolov3_output_param_t; + +/*! + * @brief Description of the parameters of YOLOV3 output result. + */ +typedef struct dproc_yolov3_output_result_s { + uint32_t valid : 1; + uint32_t reserved : 31; + int label; + float score; + + dproc_bbox_param_t bbox; /*!< refer to struct @ref dproc_bbox_param_s. */ +} dproc_yolov3_output_result_t; +/*************** Yolov3 yolo layer ***************/ + + +/*! + * @brief Description of the configuration of dproc. + */ +typedef struct dproc_config_s { + enum dproc_layer_type layer_type; /*!< refer to enum @ref dproc_layer_type. */ + + union { + /*! + * refer to struct @ref dproc_ssd_detection_output_config_s. + */ + dproc_ssd_detection_output_config_t ssd_config; + /*! + * refer to struct @ref dproc_yolov3_output_config_s. + */ + dproc_yolov3_output_config_t yolov3_config; + } arg; +} dproc_config_t; + +/*! + * @brief Description of the running parameters of dproc. + */ +typedef struct dproc_run_param_s { + enum dproc_layer_type layer_type; /*!< refer to enum @ref dproc_layer_type */ + + union { + /*! + * refer to struct @ref dproc_run_ssd_detection_output_param_s. + */ + dproc_run_ssd_detection_output_param_t ssd_param; + /*! + * refer to struct @ref dproc_run_yolov3_output_param_s. + */ + dproc_run_yolov3_output_param_t yolov3_param; + } arg; +} dproc_run_param_t; + +/*! + * @brief Describe the results after running dproc. + */ +typedef struct dproc_result_s { + union { + /*! + * refer to struct @ref dproc_ssd_detection_output_result_s. + */ + dproc_ssd_detection_output_result_t *ssd_result; + /*! + * refer to struct @ref dproc_yolov3_output_result_s. + */ + dproc_yolov3_output_result_t *yolov3_result; + } arg; + + union { + /*! + * refer to struct @ref dproc_ssd_class_dbg_info_s. + */ + dproc_ssd_class_dbg_info_t *ssd_debug_info; + } arg_debug; +} dproc_result_t; + +/*! @} */ + + +/*! + * @addtogroup dproc-api + * @{ + */ + +/*! + * This API initializes control parameters for dproc. + * Call it before running the library. + * + * @param config The required configuration for dproc initialization. + * <br> User can refer to struct @ref dproc_config_s. + * @return 0: success; -1: error. + */ +AMBA_API int dproc_init(int dproc_ctx_id, dproc_config_t *config); + +/*! + * This API performs corresponding data processing on the output data + * of different network models. The currently supported models are + * SSD, YOLOV3, TINY_YOLOV3. + * Call this API after initialization. + * + * @param run_param The running parameters for dproc. + * <br> User can refer to struct @ref dproc_run_param_s. + * + * @param result The results after running dproc. + * <br> User can refer to struct @ref dproc_result_s. + * + * @return 0: success; -1: error. + */ +AMBA_API int dproc_run(dproc_run_param_t *run_param, dproc_result_t *result, int dproc_ctx_id); + +/*! + * This API is used to release the library session. + * Call this API at the very end. + * + * @param layer_type The layer type of dproc. + * <br> User can refer to enum @ref dproc_layer_type. + * + * @return 0: success; -1: error. + */ +AMBA_API int dproc_deinit(enum dproc_layer_type layer_type, int dproc_ctx_id); + +/*! @} */ + +#ifdef __cplusplus +} +#endif + +#endif //_DPROC_LIB_H + diff --git a/include/ambarella/lib_smartfb.h b/include/ambarella/lib_smartfb.h new file mode 100644 index 0000000..aab544a --- /dev/null +++ b/include/ambarella/lib_smartfb.h @@ -0,0 +1,213 @@ +/******************************************************************************* + * lib_smartfb.h + * + * History: + * 2017/07/25 - [Hao Qian] created file + * + * Copyright (c) 2017 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#ifndef _SMARTFB_LIB_H +#define _SMARTFB_LIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_TEXT_SIZE (200) +#define MAX_LINE_THICKNESS (10) +#define MAX_CAP_AREA_NUM (10) +#define MAX_NAME_SIZE (32) + +#include "basetypes.h" + +enum smartfb_vout_id { + SMARTFB_DIGITAL_VOUT = 0, + SMARTFB_ANALOG_VOUT = 1, + SMARTFB_VOUT_NUM, +}; + +enum smartfb_mode_name { + SMARTFB_MODE_CLUT8BPP = 0, + SMARTFB_MODE_ARGB8888 = 1, + SMARTFB_MODE_NUM, + SMARTFB_MODE_INVALID = 0xFF, +}; + +enum smartfb_color { + SMARTFB_COLOR_RED = 0, + SMARTFB_COLOR_LIME = 1, + SMARTFB_COLOR_BLUE = 2, + SMARTFB_COLOR_MAGENTA = 3, + SMARTFB_COLOR_SPRING_GREEN = 4, + SMARTFB_COLOR_MEDIUM_SLATE_BLUE = 5, + SMARTFB_COLOR_YELLOW = 6, + SMARTFB_COLOR_DARK_ORANGE = 7, + SMARTFB_COLOR_CYAN = 8, + SMARTFB_COLOR_GREEN = 9, + SMARTFB_COLOR_BLUE_VIOLET = 10, + SMARTFB_COLOR_VIOLET = 11, + SMARTFB_COLOR_DEEP_PINK = 12, + SMARTFB_COLOR_NAVY = 13, + SMARTFB_COLOR_MAROON = 14, + SMARTFB_COLOR_PURPLE = 15, + SMARTFB_COLOR_SALMON = 16, + SMARTFB_COLOR_OLIVE = 17, + SMARTFB_COLOR_MOCCASIN = 18, + SMARTFB_COLOR_TEAL = 19, + SMARTFB_COLOR_GRAY = 20, + SMARTFB_COLOR_WHITE = 21, + SMARTFB_COLOR_BLACK = 22, + SMARTFB_COLOR_NUM, +}; + +enum smartfb_alpha { + SMARTFB_ALPHA_LEVEL0 = 0, // alpha = 0 + SMARTFB_ALPHA_LEVEL1 = 1, // alpha = 32 + SMARTFB_ALPHA_LEVEL2 = 2, // alpha = 64 + SMARTFB_ALPHA_LEVEL3 = 3, // alpha = 96 + SMARTFB_ALPHA_LEVEL4 = 4, // alpha = 128 + SMARTFB_ALPHA_LEVEL5 = 5, // alpha = 160 + SMARTFB_ALPHA_LEVEL6 = 6, // alpha = 192 + SMARTFB_ALPHA_LEVEL7 = 7, // alpha = 255 + SMARTFB_ALPHA_NUM, +}; + +typedef struct smartfb_init_s { + enum smartfb_vout_id vout; +} smartfb_init_t; + +typedef struct smartfb_obj_s { + u16 offset_x; + u16 offset_y; + u8 color; + u8 bg_color; + u8 bg_alpha; + u8 reserved; +} smartfb_obj_t; + +typedef struct smartfb_box_s { + smartfb_obj_t obj; + u16 width; + u16 height; + u8 line_thickness; + u8 reserved[3]; +} smartfb_box_t; + +typedef struct smartfb_cap_area_s { + char name[MAX_NAME_SIZE]; + u16 offset_x; + u16 offset_y; + u16 width; + u16 height; +} smartfb_cap_area_t; + +typedef struct smartfb_textbox_s { + smartfb_box_t box; + u8 font_size; + u8 outline; // to do + u8 bold; + u8 italic; + u32 wrap_line : 1; + u32 reserved : 31; + char text[MAX_TEXT_SIZE]; +} smartfb_textbox_t; + +typedef struct smartfb_line_s { + u32 start_x; + u32 start_y; + u32 end_x; + u32 end_y; + u8 line_thickness; + u8 color; + u8 reserved[2]; +} smartfb_line_t; + +typedef struct smartfb_circle_s { + u16 center_x; + u16 center_y; + u16 radius; + u8 color; + u8 alpha; +} smartfb_circle_t; + +typedef struct smartfb_iav_yuv_cap_params_s { + u8 *y_vir_base_addr; /*!< y_virtual_base_address is based on YUV data resolution */ + u8 *uv_vir_base_addr; /*!< uv_virtual_base_address is based on YUV data resolution */ + u32 pitch; /*!< pitch size is based on YUV data resolution */ + u32 width; /*!< Width is based on YUV data resolution */ + u32 height; /*!< Height is based on YUV data resolution */ +} smartfb_iav_yuv_cap_params_t; + +typedef struct smartfb_mosaic_s { + smartfb_iav_yuv_cap_params_t yuv_params; + u32 offset_x; /*!< mosaic_offset_x is based on frame buffer resolution */ + u32 offset_y; /*!< mosaic_offset_y is based on frame buffer resolution */ + u32 width; /*!< mosaic_width is based on frame buffer resolution */ + u32 height; /*!< mosaic_height is based on frame buffer resolution */ + u32 grid_width; /*!< mosaic_grid_width is based on frame buffer resolution */ + u32 grid_height; /*!< mosaic_grid_height is based on frame buffer resolution */ +} smartfb_mosaic_t; + +/* Basix API */ +AMBA_API int smartfb_init(smartfb_init_t *fb_init); +AMBA_API int smartfb_deinit(void); +AMBA_API int smartfb_clear(void); //Blank VOUT and Clear fmem +AMBA_API int smartfb_display(void); // Display fmem in VOUT + +/* Draw differe obj to fmem */ +AMBA_API int smartfb_draw_box(smartfb_box_t *fb_box); +AMBA_API int smartfb_draw_textbox(smartfb_textbox_t *fb_textbox); + +AMBA_API int smartfb_draw_line(smartfb_line_t *fb_line); +AMBA_API int smartfb_draw_circle(smartfb_circle_t *fb_circle); +AMBA_API int smartfb_draw_mosaic(smartfb_mosaic_t *fb_mosaic); +/* All interfaces use clut8bpp by default, except for some interfaces with "argb8888" suffix like this. */ +AMBA_API int smartfb_draw_mosaic_with_argb8888(smartfb_mosaic_t *fb_mosaic); + +AMBA_API int smartfb_set_clut(u16 *r_table, u16 *g_table, u16 *b_table, u16 *trans_table); +AMBA_API u8 *smartfb_get_fb_mem(void); +AMBA_API int smartfb_get_var(struct fb_var_screeninfo *fb_var); +AMBA_API int smartfb_get_fix(struct fb_fix_screeninfo *fb_fix); +AMBA_API u32 smartfb_get_fb_bpp(void); +AMBA_API enum smartfb_mode_name smartfb_get_fb_mode_name(void); +AMBA_API int smartfb_get_specific_text(smartfb_textbox_t *fb_textbox, + wchar_t *pattern_addr, u8 *mem, int convert_num); +AMBA_API u32 smartfb_get_fb_yoffset(void); +AMBA_API int smartfb_clear_buffer(void); +AMBA_API int smartfb_save_capture_area_buffer(smartfb_cap_area_t *fb_cap_area); +AMBA_API int smartfb_modify_capture_area_buffer(smartfb_cap_area_t *fb_cap_area, char *area_name); +AMBA_API int smartfb_delete_capture_area_buffer(char *area_name); +AMBA_API int smartfb_delete_all_capture_area_buffer(void); +AMBA_API int smartfb_restore_capture_area_buffer(char *area_name); +AMBA_API int smartfb_restore_all_capture_area_buffer(void); + +#ifdef __cplusplus +} +#endif + +#endif //_SMARTFB_LIB_H + diff --git a/include/ambarella/lib_smartfb_priv.h b/include/ambarella/lib_smartfb_priv.h new file mode 100644 index 0000000..825d5b1 --- /dev/null +++ b/include/ambarella/lib_smartfb_priv.h @@ -0,0 +1,107 @@ +/******************************************************************************* + * lib_smartfb_priv.h + * + * History: + * 2017/07/25 - [Hao Qian] created file + * + * Copyright (c) 2017 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#ifndef _SMARTFB_LIB_PRIV_H +#define _SMARTFB_LIB_PRIV_H + +#include "lib_smartfb.h" + +#ifndef LINE_SPACING +#define LINE_SPACING(x) ((x) * 3 / 2) +#endif + +#define SMARTFB_MAX_STRING_LEN (32) +#define SMARTFB_BITS_PER_PIXEL_8 (8) +#define SMARTFB_BITS_PER_PIXEL_32 (32) +#define SMARTFB_MOSAIC_USED_COLOR_TAB_NUM (64) +#define SMARTFB_USED_COLOR_TAB_NUM (SMARTFB_COLOR_NUM * SMARTFB_ALPHA_NUM) + +enum line_type { + SMARTFB_LINE_DEGREE0_0 = 0, + SMARTFB_LINE_DEGREE0_45 = 1, + SMARTFB_LINE_DEGREE45_90 = 2, + SMARTFB_LINE_DEGREE90_90 = 3, + SMARTFB_LINE_DEGREE90_135 = 4, + SMARTFB_LINE_DEGREE135_180 = 5, + SMARTFB_LINE_TYPE_NUM, +}; + +typedef struct fb_color_s { + u16 r; + u16 g; + u16 b; +} fb_color_t; + +struct fb_cmap_user { + u32 start; /* First entry */ + u32 len; /* Number of entries */ + u16 *r; + u16 *g; + u16 *b; + u16 *transparent; /* transparency, can be NULL */ +}; + +typedef struct smartfb_saved_cap_area_params_s { + u16 offset_x; + u16 offset_y; + u16 width; + u16 height; + char name[MAX_NAME_SIZE]; + u8 *buffer; +} smartfb_saved_cap_area_params_t; + +typedef struct smartfb_saved_cap_area_s { + smartfb_saved_cap_area_params_t params[MAX_CAP_AREA_NUM]; + u32 used_map : MAX_CAP_AREA_NUM; + u32 reserved : (32 - MAX_CAP_AREA_NUM); +} smartfb_saved_cap_area_t; + +typedef struct smartfb_context_s { + u8 *fb_mem; + u32 init_done : 1; + u32 cycle_buffer_num : 4; + u32 cur_cycle_buffer : 4; + u32 drawed_cycle_buffer : 4; + u32 mode_name : 1; + u32 reserved : 18; + int fb; + + // linux fb header + struct fb_var_screeninfo var; + struct fb_fix_screeninfo fix; + + // saved capture area + smartfb_saved_cap_area_t saved_areas; +} smartfb_context_t; + +#endif //_SMARTFB_LIB_PRIV_H + diff --git a/include/ambarella/mw_api.h b/include/ambarella/mw_api.h new file mode 100644 index 0000000..cb1af13 --- /dev/null +++ b/include/ambarella/mw_api.h @@ -0,0 +1,188 @@ +/* + * mw_api.h + * + * History: + * 2013/03/12 - [Cao Rongrong] Created file + * 2013/12/12 - [Jian Tang] Modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __MW_API_H__ +#define __MW_API_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "basetypes.h" + +#ifndef AMBA_API +#define AMBA_API __attribute__((visibility("default"))) +#endif + +/********************** Image global configuration **********************/ +AMBA_API int mw_start_aaa(int fd_iav); +AMBA_API int mw_stop_aaa(void); +AMBA_API int mw_init_mctf(int fd_iav); +AMBA_API int mw_get_iav_state(int fd, int *pState); +/********************** Exposure Control Settings **********************/ +AMBA_API int mw_enable_ae(int enable); +AMBA_API int mw_get_ae_param(mw_ae_param *ae_param); +AMBA_API int mw_set_ae_param(mw_ae_param *ae_param); +AMBA_API int mw_get_exposure_level(int *pExposure_level); +AMBA_API int mw_get_shutter_time(int fd_iav, int *pShutter_time); +AMBA_API int mw_get_sensor_gain(int fd_iav, int *pGain_db); +AMBA_API int mw_get_sensor_ir_normal_diff(int *pSensorDiff); +AMBA_API int mw_get_sensor_agc(int *pAgc); +AMBA_API int mw_get_ae_metering_mode(mw_ae_metering_mode *pMode); +AMBA_API int mw_set_ae_metering_mode(mw_ae_metering_mode mode); +AMBA_API int mw_get_ae_metering_table(mw_ae_metering_table *pAe_metering_table); +AMBA_API int mw_set_ae_metering_table(mw_ae_metering_table *pAe_metering_table); +AMBA_API int mw_is_dc_iris_supported(void); +AMBA_API int mw_enable_dc_iris_control(int enable); +AMBA_API int mw_set_dc_iris_pid_coef(mw_dc_iris_pid_coef *pPid_coef); +AMBA_API int mw_get_dc_iris_pid_coef(mw_dc_iris_pid_coef *pPid_coef); +AMBA_API int mw_is_ir_led_supported(void); +AMBA_API int mw_set_ir_led_param(mw_ir_led_control_param *pParam); +AMBA_API int mw_get_ir_led_param(mw_ir_led_control_param *pParam); +AMBA_API int mw_set_ir_led_brightness(int brightness); +AMBA_API int mw_get_ae_luma_value(mw_luma_value *pLuma); +AMBA_API int mw_get_ae_lines(mw_ae_line *lines, u32 line_num); +AMBA_API int mw_set_ae_lines(mw_ae_line *lines, u32 line_num); +AMBA_API int mw_get_ae_points(mw_ae_point *point_arr, u32 point_num); +AMBA_API int mw_set_ae_points(mw_ae_point *point_arr, u32 point_num); +AMBA_API int mw_set_ae_area(int enable); +AMBA_API int mw_set_sensor_gain(int fd_iav, int *pGain_db); +AMBA_API int mw_set_shutter_time(int fd_iav, int *shutter_time); +AMBA_API int mw_set_exposure_level(int *pExposure_level); + +/********************** White Balance Settings **********************/ +AMBA_API int mw_enable_awb(int enable); +AMBA_API int mw_get_awb_param(mw_awb_param *pAWB); +AMBA_API int mw_set_awb_param(mw_awb_param *pAWB); +AMBA_API int mw_get_awb_method(mw_white_balance_method *pWb_method); +AMBA_API int mw_set_awb_method(mw_white_balance_method wb_method); +AMBA_API int mw_set_white_balance_mode(mw_white_balance_mode wb_mode); +AMBA_API int mw_get_white_balance_mode(mw_white_balance_mode *pWb_mode); +AMBA_API int mw_set_awb_custom_gain(mw_wb_gain *pGain); +AMBA_API int mw_get_awb_manual_gain(mw_wb_gain *pGain); + +/********************** Image Adjustment Settings **********************/ +AMBA_API int mw_get_image_param(mw_image_param *pImage); +AMBA_API int mw_set_image_param(mw_image_param *pImage); +AMBA_API int mw_get_saturation(int *pSaturation); +AMBA_API int mw_set_saturation(int saturation); +AMBA_API int mw_get_brightness(int *pBrightness); +AMBA_API int mw_set_brightness(int brightness); +AMBA_API int mw_get_contrast(int *pContrast); +AMBA_API int mw_set_contrast(int contrast); +AMBA_API int mw_get_sharpness(int *pSharpness); +AMBA_API int mw_set_sharpness(int sharpness); + +/********************** Image Enhancement Settings **********************/ +AMBA_API int mw_get_mctf_strength(u32 *pStrength); +AMBA_API int mw_set_mctf_strength(u32 strength); +AMBA_API int mw_get_auto_local_exposure_mode(u32 *pMode); +AMBA_API int mw_set_auto_local_exposure_mode(u32 mode); +AMBA_API int mw_set_local_exposure_curve(int fd_iav, mw_local_exposure_curve *pLocal_exposure); +AMBA_API int mw_enable_backlight_compensation(int enable); +AMBA_API int mw_enable_day_night_mode(int enable); +AMBA_API int mw_set_auto_color_contrast(u32 enable); +AMBA_API int mw_get_auto_color_contrast(u32 *pEnable); +AMBA_API int mw_set_auto_color_contrast_strength (u32 value); +AMBA_API int mw_get_adj_status(int *pEnable); +AMBA_API int mw_enable_adj(int enable); +AMBA_API int mw_get_chroma_noise_strength(int *pStrength); +AMBA_API int mw_set_chroma_noise_strength(int strength); +AMBA_API int mw_get_auto_wdr_strength(int *pStrength); +AMBA_API int mw_set_auto_wdr_strength(int strength); +AMBA_API int mw_set_sharpen_filter(int sharpen); +AMBA_API int mw_get_sharpen_filter(void); + +/********************** Image auto focus Settings **********************/ +AMBA_API int mw_get_af_param(mw_af_param *pAF); +AMBA_API int mw_set_af_param(mw_af_param *pAF); + +/********************** Calibration related APIs **********************/ +AMBA_API int mw_load_calibration_file(mw_cali_file *pFile); + +/********************** Motion detection related APIs **********************/ +AMBA_API int mw_md_get_motion_event(int *p_motion_event); +AMBA_API int mw_md_callback_setup(alarm_handle_func alarm_handler); +AMBA_API int mw_md_get_roi_info(int roi_idx, mw_roi_info *roi_info); +AMBA_API int mw_md_set_roi_info(int roi_idx, const mw_roi_info *roi_info); +AMBA_API int mw_md_clear_roi(int roi_idx); +AMBA_API int mw_md_roi_region_display(void); +AMBA_API int mw_md_thread_start(void); +AMBA_API int mw_md_thread_stop(void); +void mw_md_print_event(int flag); + +/**********************Others APIs **********************************/ +AMBA_API int mw_get_version_info(mw_version_info *pVersion); +AMBA_API int mw_get_log_level(int *pLog); +AMBA_API int mw_set_log_level(mw_log_level log); +AMBA_API int mw_get_lib_version(mw_aaa_lib_version *pAlgo_lib_version, + mw_aaa_lib_version *pDsp_lib_version); +AMBA_API int mw_display_adj_bin_version(void); +AMBA_API int mw_load_aaa_param_file(char *pFile_name, int type); +AMBA_API int mw_get_sys_info(mw_sys_info *pMw_sys_info); +AMBA_API int mw_get_image_statistics(mw_image_stat_info *pInfo); +AMBA_API int mw_load_config_file(char *filename); +AMBA_API int mw_save_config_file(char *filename); +AMBA_API int mw_load_adj_param(mw_adj_file_param *contents); +AMBA_API int mw_save_adj_param(mw_adj_file_param *contents); +AMBA_API int mw_set_lens_id(int id); +AMBA_API int mw_set_auto_knee_strength (int strength); +AMBA_API int mw_get_auto_knee_strength (int *pStrength); +AMBA_API int mw_enable_auto_dump_cfg(int enable); +AMBA_API int mw_set_hdr_blend_config(mw_hdr_blend_info *pBlend_cfg); +AMBA_API int mw_get_hdr_blend_config(mw_hdr_blend_info *pBlend_cfg); +AMBA_API int mw_set_wdr_luma_config(mw_wdr_luma_info *pWdr_luma_cfg); +AMBA_API int mw_get_wdr_luma_config(mw_wdr_luma_info *pWdr_luma_cfg); +AMBA_API int mw_set_video_freeze(int enable); + +AMBA_API int mw_get_dynamic_shutter_ratio(mw_dyna_shutter_ratio *dyna_ratio); +AMBA_API int mw_set_dynamic_shutter_ratio(mw_dyna_shutter_ratio *dyna_ratio); +AMBA_API int mw_get_pw_cfg(mw_pw_cfg *pw_cfg); +AMBA_API int mw_set_pw_cfg(mw_pw_cfg *pw_cfg); + +AMBA_API int mw_get_vin_src_id(u8 *pvin_src_id); +AMBA_API int mw_set_vin_src_id(u8 vin_src_id); +AMBA_API int mw_set_img_log_level(u32 level); + +AMBA_API int mw_get_chan_src_id(u8 *pchan_src_id); +AMBA_API int mw_set_chan_src_id(u8 chan_src_id); +AMBA_API int mw_get_sys_multi_chan_info(mw_sys_multi_chan_info *pMw_info); +AMBA_API int mw_enable_hdrplus(u32 enable_chan_map); +AMBA_API int mw_rt_change_hdr_mask(u32 hdr_mask); + +#ifdef __cplusplus +} +#endif + +#endif // __MW_API_H__ + diff --git a/include/ambarella/mw_struct.h b/include/ambarella/mw_struct.h new file mode 100644 index 0000000..be7f2fc --- /dev/null +++ b/include/ambarella/mw_struct.h @@ -0,0 +1,522 @@ +/* + * mw_struct.h + * + * History: + * 2013/03/12 - [Cao Rongrong] Created file + * 2013/12/12 - [Jian Tang] Modified file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + */ + +#ifndef __MW_STRUCT_H__ +#define __MW_STRUCT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "basetypes.h" +#include "config.h" + +typedef u32 mw_id; +typedef u32 mw_stream; + +#define MW_MAX_CHANNEL_NUM (8) +#define MW_MAX_STREAM_NUM (4) +#define MW_MAX_BUFFER_NUM (4) +#define MW_NUM_EXPOSURE_CURVE (256) +#define MW_MAX_ROI_NUM (4) +#define MW_MAX_MD_THRESHOLD (200) + +#define MW_MAX_HDR_EXPOSURE_NUM (4) + +#define MW_TRANSPARENT (0) +#define MW_NONTRANSPARENT (255) +#define MW_OSD_AREA_NUM (3) +#define MW_OSD_CLUT_NUM (MW_MAX_STREAM_NUM * MW_OSD_AREA_NUM) +#define MW_OSD_CLUT_SIZE (1024) +#define MW_OSD_CLUT_OFFSET (0) +#define MW_OSD_YUV_OFFSET (MW_OSD_CLUT_NUM * MW_OSD_CLUT_SIZE) +#define MW_ADJ_FILTER_NUM 64 +#ifdef CONFIG_ARCH_S5 +#define MW_MAX_AE_TILE_COL 24 +#define MW_MAX_AE_TILE_ROW 16 +#else +#define MW_MAX_AE_TILE_COL 12 +#define MW_MAX_AE_TILE_ROW 8 +#endif + +#define SHUTTER_INVALID 0 +#define SHUTTER_1_SEC 512000000 //(512000000 / 1) +#define SHUTTER_1BY2_SEC 256000000 //(512000000 / 2) +#define SHUTTER_1BY3_SEC 170666667 //(512000000 / 3) +#define SHUTTER_1BY3P125_SEC 163840000 //(512000000 / 25 * 8) +#define SHUTTER_1BY4_SEC 128000000 //(512000000 / 4) +#define SHUTTER_1BY5_SEC 102400000 //(512000000 / 5) +#define SHUTTER_1BY6_SEC 85333333 //(512000000 / 6) +#define SHUTTER_1BY6P25_SEC 81920000 //(512000000 / 25 * 4) +#define SHUTTER_1BY7P5_SEC 68266667 //(512000000 / 15 * 2) +#define SHUTTER_1BY10_SEC 51200000 //(512000000 / 10) +#define SHUTTER_1BY12P5_SEC 40960000 //(512000000 / 25 * 2) +#define SHUTTER_1BY15_SEC 34133333 //(512000000 / 15) +#define SHUTTER_1BY20_SEC 25600000 //(512000000 / 20) +#define SHUTTER_1BY24_SEC 21333333 //(512000000 / 24) +#define SHUTTER_1BY25_SEC 20480000 //(512000000 / 25) +#define SHUTTER_1BY30_SEC 17066667 //(512000000 / 30) +#define SHUTTER_1BY33_SEC 15360000 //(512000000 / 33.3) +#define SHUTTER_1BY40_SEC 12800000 //(512000000 / 40) +#define SHUTTER_1BY50_SEC 10240000 //(512000000 / 50) +#define SHUTTER_1BY60_SEC 8533333 //(512000000 / 60) +#define SHUTTER_1BY100_SEC 5120000 //(512000000 / 100) +#define SHUTTER_1BY120_SEC 4266667 //(512000000 / 120) +#define SHUTTER_1BY240_SEC 2133333 //(512000000 / 240) +#define SHUTTER_1BY480_SEC 1066667 //(512000000 / 480) +#define SHUTTER_1BY960_SEC 533333 //(512000000 / 960) +#define SHUTTER_1BY1024_SEC 500000 //(512000000 / 1024) +#define SHUTTER_1BY8000_SEC 64000 //(512000000 / 8000) +#define SHUTTER_1BY16000_SEC 32000 //(512000000 / 16000) +#define SHUTTER_1BY32000_SEC 16000 //(512000000 /32000) + +#define LENS_FNO_UNIT 65536 + +typedef enum { + MW_ERROR_LEVEL = 0, + MW_MSG_LEVEL = 1, + MW_INFO_LEVEL = 2, + MW_DEBUG_LEVEL = 3, + MW_LOG_LEVEL_NUM, +} MW_LOG_LEVEL; + +typedef int mw_log_level; + +typedef enum { + MW_LE_STOP = 0, + MW_LE_AUTO, + MW_LE_2X, + MW_LE_3X, + MW_LE_4X, + MW_LE_TOTAL_NUM, +} mw_local_exposure_mode; + + +typedef enum { + MW_ANTI_FLICKER_50HZ = 0, + MW_ANTI_FLICKER_60HZ = 1, +} mw_anti_flicker_mode; + + +typedef enum { + MW_WB_NORMAL_METHOD = 0, + MW_WB_CUSTOM_METHOD, + MW_WB_GREY_WORLD_METHOD, + MW_WB_METHOD_NUMBER, +} mw_white_balance_method; + + +typedef enum { + MW_WB_AUTO = 0, + MW_WB_INCANDESCENT, // 2800K + MW_WB_D4000, + MW_WB_D5000, + MW_WB_SUNNY, // 6500K + MW_WB_CLOUDY, // 7500K + MW_WB_FLASH, + MW_WB_FLUORESCENT, + MW_WB_FLUORESCENT_H, + MW_WB_UNDERWATER, + MW_WB_CUSTOM, // custom + MW_WB_MODE_NUMBER, +} mw_white_balance_mode; + +typedef struct { + int arch; + int model; + int major; + int minor; + int patch; + char description[64]; +} mw_driver_info; + + +typedef struct { + u32 major; + u32 minor; + u32 patch; + u32 update_time; +} mw_version_info; + +typedef struct { + int major; + int minor; + int patch; + u32 mod_time; + char description[64]; +} mw_aaa_lib_version; + +typedef struct { + int p_coef; + int i_coef; + int d_coef; +} mw_dc_iris_pid_coef; + +typedef struct { + int open_threshold; //about 500 in 3lux ambient light + int close_threshold; //about 510 in 10lux ambient light + int open_delay; + int close_delay; + int threshold_1X; //about 490, depends on customization + int threshold_2X; //about 480 + int threshold_3X; //about 470 + int over_exp_threshold; //about 1000, depends on customization + int not_over_exp_threshold; //about 800 +} mw_ir_led_control_param; + +typedef enum { + MW_IR_LED_MODE_OFF = 0, + MW_IR_LED_MODE_ON = 1, + MW_IR_LED_MODE_AUTO = 2 +} mw_ir_led_mode; + +typedef enum { + MW_SHUTTER = 0, + MW_DGAIN, + MW_IRIS, + MW_TOTAL_DIMENSION +} mw_ae_point_dimension; + + +typedef enum { + MW_AE_START_POINT = 0, + MW_AE_END_POINT, +} mw_ae_point_position; + + +typedef struct { + s32 factor[3]; // 0:shutter, 1:gain, 2:iris + u32 pos; // 0:start, 1:end +} mw_ae_point; + + +typedef struct { + mw_ae_point start; + mw_ae_point end; +} mw_ae_line; + + +typedef enum { + MW_AE_SPOT_METERING = 0, + MW_AE_CENTER_METERING, + MW_AE_AVERAGE_METERING, + MW_AE_CUSTOM_METERING, + MW_AE_TILE_METERING, + MW_AE_Y_ORDER_METERING, + MW_AE_EXTERN_DESIGN_METERING, + MW_AE_METERING_TYPE_NUMBER, +} mw_ae_metering_mode; + + +typedef struct { + int metering_weight[MW_MAX_AE_TILE_COL * MW_MAX_AE_TILE_ROW]; +} mw_ae_metering_table; + + +typedef struct { + s32 saturation; + s32 brightness; + s32 hue; + s32 contrast; + s32 sharpness; +} mw_image_param; + + +typedef struct { + char lect_filename[64]; // local exposure curve table filename + u32 lect_reload; + char gct_filename[64]; // gamma curve table filename + u32 gct_reload; +} mw_iq_param; + +#define MW_WB_MODE_HOLD (100) + +typedef struct { + u32 wb_mode; +} mw_awb_param; + + +typedef struct { + u32 lens_type; + u16 af_mode; + u16 af_tile_mode; + u16 zm_dist; + u16 fs_dist; + u16 fs_near; + u16 fs_far; +} mw_af_param; + + +typedef struct { + u32 agc; + u32 shutter; +} mw_image_stat_info; + + +typedef struct { + u16 rgb_luma; + u16 cfa_luma; +} mw_luma_value; + + +typedef struct { + u32 r_gain; + u32 g_gain; + u32 b_gain; + u16 d_gain; + u16 reserved; +} mw_wb_gain; + + +typedef struct { + u16 gain_curve_table[MW_NUM_EXPOSURE_CURVE]; +} mw_local_exposure_curve; + +typedef enum { + NO_MOTION = 0, + IN_MOTION, +} mw_motion_status_type; + + +typedef enum { + EVENT_NO_MOTION = 0, + EVENT_MOTION_START, + EVENT_MOTION_END, +} mw_motion_event_type; + + +typedef int (*alarm_handle_func)(const int *p_motion_event); + + +typedef struct { + u16 x; + u16 y; + u16 width; + u16 height; + u16 threshold; + u16 sensitivity; + u16 valid; +} mw_roi_info; + + +typedef struct { + char bad_pixel[64]; // for bad pixel calibration data + char wb[64]; // for white balance calibration data + char shading[64]; // for lens shading calibration data +} mw_cali_file; + + +typedef struct { + u8 hdr_mode; + u8 hdr_expo_num; + u8 hdr_shutter_mode; + u8 isp_pipeline; + u16 hdr_method; + u16 main_width; + u16 main_height; + u16 ce_enable : 1; + u16 ta_enable : 1; + u16 mctf_cmpr : 1; + u16 raw_cap_enable : 1; + u16 perf_type : 1; + u16 stitch_enable : 1; + u16 reserved : 10; + int raw_pitch; + u8 vin_num; + u8 cur_vin_id; + u8 chan_num; + u8 cur_chan_id; +} mw_sys_res; + +/* ratio range is (MIN_HDR_EXPOSURE_RATIO ~ MAX_HDR_EXPOSURE_RATIO) * HDR_EXPOSURE_RATIO_UNIT; + * ratio between each two exposures for S5; + * mw_hdr_blend_info[0].expo_ratio is invalid; + * mw_hdr_blend_info[1].expo_ratio is ratio between Frame 1 and Frame 0; + * mw_hdr_blend_info[2].expo_ratio is ratio between Frame 2 and Frame 1; + * ratio For S2L / S3L / S5L, + * just using mw_hdr_blend_info[0].expo_ratio for all frames. */ +typedef struct { + u16 expo_ratio; // one param for all frames, 16 * 4 ~ 16 * 128 + u16 boost_factor; // one param for all frames, 0 ~ 256, 0 means no boost +} mw_hdr_blend_info; + +typedef struct { + u8 radius; + u8 luma_weight_red; + u8 luma_weight_green; + u8 luma_weight_blue; + u8 luma_weight_shift; +}mw_wdr_luma_info; + +typedef struct { + u32 step; + u32 line_time; +} mw_sensor; + +typedef struct { + mw_sys_res res; + mw_sensor sensor; +} mw_sys_info; + +typedef struct { + u8 chan_num; + u8 cur_chan_id; + u8 reserved[6]; + mw_sys_res res[MW_MAX_CHANNEL_NUM]; + mw_sensor sensor[MW_MAX_CHANNEL_NUM]; +} mw_sys_multi_chan_info; + +typedef struct { + u32 FNO_min; + u32 FNO_max; + u32 aperture_min; + u32 aperture_max; +} mw_aperture_param; + +typedef struct { + mw_anti_flicker_mode anti_flicker_mode; + u32 shutter_time_min; + u32 shutter_time_max; + u32 sensor_gain_max; + u32 slow_shutter_enable; + u32 ir_led_mode; + u32 current_vin_fps; + int ae_level[4]; + mw_aperture_param lens_aperture; + mw_ae_metering_mode ae_metering_mode; + mw_ae_metering_table ae_metering_table; + u32 tone_curve_duration; + u16 chan_id; + u16 reserved; +} mw_ae_param; + +#define FILE_NAME_LENGTH 96 + +typedef enum { + FILE_TYPE_ADJ = 0, + FILE_TYPE_AEB = 1, + FILE_TYPE_CONFIG = 2, + FILE_TYPE_PIRIS = 3, + FILE_TYPE_TOTAL_NUM, + FILE_TYPE_FIRST = FILE_TYPE_ADJ, + FILE_TYPE_LAST = FILE_TYPE_TOTAL_NUM, +} MW_AAA_FILE_TYPE; + +typedef enum { + MW_AAA_SUCCESS = 0, + MW_AAA_INIT_FAIL = -1, + MW_AAA_DEINIT_FAIL = -2, + MW_AAA_NL_INIT_FAIL = -3, + MW_AAA_INTERRUPTED = -4, + MW_AAA_SET_FAIL = -5, + MW_AAA_GET_FAIL = -6, +} MW_AAA_RESULT; + + +/******************************************************* + * + * Parse Configuration Parameters + * + *******************************************************/ +typedef enum { + MAP_TO_U32 = 0, + MAP_TO_U16, + MAP_TO_U8, + MAP_TO_S32, + MAP_TO_S16, + MAP_TO_S8, + MAP_TO_DOUBLE, + MAP_TO_STRING, +} mapping_data_type; + + +typedef enum { + NO_LIMIT = 0, + MIN_MAX_LIMIT, + MIN_LIMIT, + MAX_LIMIT, +} mapping_data_constraint; + + +typedef struct { + char * TokenName; // name + void * Address; // address + mapping_data_type Type; // type: 0 - u32, 1 - u16, 2 - u8, 3 - int(s32), 4 - double, 5 - char[]> + double Default; // default value> + mapping_data_constraint ParamLimits; // 0 - no limits, 1 - min and max limits, 2 - only min limit, 3 - only max limit + double MinLimit; // Minimun value + double MaxLimit; // Maximun value + int StringLengthLimit; // Dimension of type char[] +} Mapping; + +typedef struct { + u32 apply : 1; //input params + u32 done : 1; //output params + u32 reserved : 30; +} mw_operate; + +typedef struct { + char filename[FILE_NAME_LENGTH]; + mw_operate flag[MW_ADJ_FILTER_NUM]; +} mw_adj_file_param; + +typedef struct { + u32 enable; + u32 min_ratio; + u32 max_ratio; +} mw_dyna_shutter_ratio; + +typedef struct { + u32 enable; + u32 clip_permillage; + u32 clip_bin; //only for hdr 128bin histogram now + u32 wl_inc; //dont care for now + u32 wl_reduce; //dont care for now +} mw_pw_cfg; + +typedef enum { + IMG_LOG_OFF = 0, + IMG_LOG_AE = 1 << 0, + IMG_LOG_AWB = 1 << 1, + IMG_LOG_AF = 1 << 2, + IMG_LOG_PARSER = 1 << 3, + IMG_LOG_MAIN = 1 << 4, + IMG_LOG_HDR = 1 << 5, +} img_log_level; + +#ifdef __cplusplus +} +#endif + +#endif // __MW_STRUCT_H__ + diff --git a/include/ambarella/nnctrl.h b/include/ambarella/nnctrl.h new file mode 100644 index 0000000..091392c --- /dev/null +++ b/include/ambarella/nnctrl.h @@ -0,0 +1,240 @@ +/******************************************************************************* + * nnctrl.h + * + * History: + * 2018/08/22 - [Tao Wu] created for CV22 + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise iproare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#ifndef _NNCTL_H_ +#define _NNCTL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> +#include <cavalry_gen.h> + +#ifndef IN +#define IN +#endif + +#ifndef OUT +#define OUT +#endif + +#ifndef INOUT +#define INOUT +#endif + +struct nnctrl_version { + uint32_t major; + uint32_t minor; + uint32_t patch; + uint32_t cavalry_parser; + unsigned int mod_time; + char description[64]; +}; + +struct net_cfg { + IN const char *net_file; /* filename of NET.bin generated by cavalry_gen */ + IN const uint8_t *net_feed_virt; /* virtual memory of NET.bin */ + + IN uint32_t verbose : 1; + IN uint32_t reuse_mem : 1; + IN uint32_t print_time : 1; + uint32_t reserved_0 : 29; + + IN uint32_t net_loop_cnt; /* Load dvi once and run dvi multi-times (N). + * It will save (N-1) dvi loading time. + * blob_mem_total (IN, ..., OUT) will multiple (N) times */ + + OUT uint32_t net_mem_total; /* every dvi and blob 32 aligned */ + OUT uint32_t dvi_mem_total; /* non 32 aligned */ + OUT uint32_t blob_mem_total; /* non 32 aligned */ + OUT uint32_t bandwidth_total; /* non 32 aligned */ +}; + +struct net_mem { + uint8_t *virt_addr; /* The virtual address mmap by app for network */ + uint32_t phy_addr; /* The absolute physical address */ + uint32_t mem_size; /* The memory size assigned by app */ +}; + +struct io_dim { + uint32_t plane; + uint32_t depth; + uint32_t height; + uint32_t width; + + uint32_t pitch; /* Alignment of width */ + uint32_t pitch_byte_offset; /* define as *_dpitchm1_byte_offset in <vas>.h */ + uint32_t pitch_bsize : 6; /* define as *_dpitchm1_bsize in <vas>.h */ + uint32_t bitvector : 1; /* 0: false; 1: true */ + uint32_t reserved_0 : 1; + uint32_t dram_fmt : 8; /* Internal use */ + uint32_t reserved_1 : 16; +}; + +struct io_data_fmt { + uint8_t sign; + uint8_t size; + int8_t expoffset; + uint8_t expbits; +}; + +enum ROTATE_FILP_BITMAP { + DROTATE_BIT = 0, + HFLIP_BIT = 1, + VFLIP_BIT = 2, + DFLIP_BIT = 3, + PFLIP_BIT = 4, + ROTATE_FLIP_BIT_NUM, +}; + +struct input_desc { + IN const char *name; /* Set by APP */ + INOUT uint8_t *virt; /* return absolute virtual address if no_mem is 0 */ + INOUT uint32_t addr; /* Set by APP if set no_mem, otherwise get from Library; + * absolute physical address */ + INOUT uint32_t size; /* Set by APP if set no_mem, otherwise get from Library */ + + IN uint32_t no_mem : 1; /* Not allocate memory for input port by this lib, + * since it may from yuv addr in live mode */ + + IN uint32_t rotate_flip_bitmap : 5; /* Bitmap for 5 field, order (High -> Low): + * 4: pflip; 3: dflip; 2: vflip; 1: hflip; 0: rotate. */ + uint32_t reserved_0 : 2; + uint32_t reserved_1 : 8; + IN uint32_t update_pitch : 16; /* Run time change the pitch of input. + * Do not minus one on real pitch, library will minus one internal */ + + OUT struct io_dim dim; + OUT struct io_data_fmt data_fmt; +}; + +struct output_desc { + IN const char *name; /* Set by APP */ + INOUT uint8_t *virt; /* return absolute virtual address if no_mem is 0 */ + INOUT uint32_t addr; /* Set by APP if set no_mem, otherwise get from Library; + * absolute physical address */ + OUT uint32_t size; /* Get from Library */ + + IN uint32_t no_mem : 1; /* Not allocate memory for output port by this lib */ + IN uint32_t rotate_flip_bitmap : 5; /* Bitmap for 5 field, order (High -> Low): + * 4: pflip; 3: dflip; 2: vflip; 1: hflip; 0: rotate. */ + uint32_t reserved_0 : 26; + + OUT struct io_dim dim; + OUT struct io_data_fmt data_fmt; +}; + +/* Neural Network's external input and output*/ +#define MAX_IO_NUM (16) + +struct net_input_cfg { + IN uint32_t in_num; + struct input_desc in_desc[MAX_IO_NUM]; +}; + +struct net_output_cfg { + IN uint32_t out_num; + struct output_desc out_desc[MAX_IO_NUM]; +}; + +struct net_dvi_cfg { + uint8_t *virt; /* absolute virtual address */ + uint32_t addr; /* absolute physical address */ + dvi_desc_t dvi_desc; +}; + +struct net_run_cfg { + uint32_t net_loop_cnt; //1 + uint32_t single_dag_run : 1; //1 /* For debug every dag execute time, * should disable in real case */ + uint32_t reserved_0 : 31;//26//29//31 +}; + +struct net_result { + float vp_time_us; +}; + +#ifndef AMBA_API +#define AMBA_API __attribute__((visibility("default"))) +#endif + + +/* Neural Network Control Library API */ +AMBA_API int nnctrl_init(IN int fd_cav, IN uint8_t verbose); +AMBA_API int nnctrl_get_version(struct nnctrl_version *ver); +AMBA_API int nnctrl_suspend_net(uint8_t quit_all); +AMBA_API void nnctrl_exit(void); + + +/* Nerual Network API */ +AMBA_API int nnctrl_init_net(INOUT struct net_cfg *net_cf, + INOUT struct net_input_cfg *net_in, INOUT struct net_output_cfg *net_out); +AMBA_API int nnctrl_load_net(IN int net_id, IN struct net_mem *net_m, + INOUT struct net_input_cfg *net_in, INOUT struct net_output_cfg *net_out); + +AMBA_API int nnctrl_get_net_io_cfg(IN int net_id, + OUT struct net_input_cfg *net_in, OUT struct net_output_cfg *net_out); +AMBA_API int nnctrl_set_net_io_cfg(IN int net_id, + IN struct net_input_cfg *net_in, IN struct net_output_cfg *net_out); + +AMBA_API int nnctrl_query_dvi(IN int net_id, IN uint32_t dvi_id, + OUT struct net_dvi_cfg *net_dvi); + +/* nnctrl_run_net +* +* The function returns 0 if ok, +* -EINTR if it was interrupted by a signal, +* -EAGAIN if after call nnctrl_suspend_net. +*/ +AMBA_API int nnctrl_run_net(IN int net_id, + OUT struct net_result *net_ret, IN struct net_run_cfg *net_rev, + IN struct net_input_cfg *net_in, IN struct net_output_cfg *net_out); + +/* nnctrl_resume_net +* +* The function returns 0 if ok, +* -EINTR if it was interrupted by a signal, +* -EAGAIN if after call nnctrl_suspend_net. +*/ +AMBA_API int nnctrl_resume_net(IN int net_id, OUT struct net_result *net_ret); + +AMBA_API int nnctrl_exit_net(IN int net_id); + + +/* Dump Neural Network dvi, dump blob if reuse_mem equal zero */ +AMBA_API int nnctrl_dump_net(IN int net_id, IN const char *path); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/ambarella/nnctrl_live_utils.h b/include/ambarella/nnctrl_live_utils.h new file mode 100644 index 0000000..a31a9ca --- /dev/null +++ b/include/ambarella/nnctrl_live_utils.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * nnctrl_live_utils.h + * + * History: + * 2019/08/26 - [Albert Zhang] created + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct data_desc { + int8_t sign; + int8_t size; + int8_t expoffset; + int8_t expbits; + + uint32_t plane; + uint32_t depth; + uint32_t height; + uint32_t width; + uint32_t pitch; +}; +#ifndef MAX_IO_NUM +#define MAX_IO_NUM (16) +#endif +struct net_out_bin_desc { + uint32_t bin_num; + uint32_t port_name_length[MAX_IO_NUM]; + char port_name[MAX_IO_NUM][512]; + struct data_desc data_desc[MAX_IO_NUM]; +}; \ No newline at end of file diff --git a/include/ambarella/text_insert.h b/include/ambarella/text_insert.h new file mode 100644 index 0000000..a3b7ca3 --- /dev/null +++ b/include/ambarella/text_insert.h @@ -0,0 +1,95 @@ +/******************************************************************************* + * text_insert.h + * + * History: + * 2011/02/25 - [Qian Shen] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#ifndef _TEXT2BITMAP_LIB_H +#define _TEXT2BITMAP_LIB_H + + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_BYTE_SIZE 128 + +#ifndef _BASE_TYPES_H_ +typedef unsigned char u8; /**< UNSIGNED 8-bit data type */ +typedef unsigned short u16;/**< UNSIGNED 16-bit data type */ +typedef unsigned int u32; /**< UNSIGNED 32-bit data type */ +typedef unsigned long long u64; /**< UNSIGNED 64-bit data type */ +typedef signed char s8; /**< SIGNED 8-bit data type */ +typedef signed short s16; /**< SIGNED 16-bit data type */ +typedef signed int s32; /**< SIGNED 32-bit data type */ +#endif + +typedef struct { + int major; + int minor; + int patch; + unsigned int mod_time; + char description[64]; +} version_t; + +typedef struct font_attribute_s { + char type[MAX_BYTE_SIZE]; + u32 size; + u32 outline_width; // 0: no outline + s32 hori_bold; // 0: no bold at all; positive is bold, negetive is thin in horizontal + s32 vert_bold; // 0: no bold at all; positive is bold, negetive is thin in vertical + u32 italic; // 0 is normal (no italic), 100 is 100% italic + u32 disable_anti_alias; // 0: anti-alias is enabled, 1: disable anti-alias. Default is 0. +} font_attribute_t; + +typedef struct bitmap_info_s { + int width; + int height; +} bitmap_info_t; + +typedef struct pixel_type_s { + u8 pixel_background; + u8 pixel_font; + u8 pixel_outline; + u8 reserved; +} pixel_type_t; + +int text2bitmap_lib_init(pixel_type_t *type); +int text2bitmap_set_font_attribute(const font_attribute_t *font_attr); +int text2bitmap_get_font_attribute(font_attribute_t *font_attr); +int text2bitmap_convert_character(u32 ui_char_code, u8 *bmp_addr, u16 buf_height, u16 buf_pitch, int offset_x, bitmap_info_t *bmp_info); +int text2bitmap_lib_deinit(void); +int text2bitmap_get_version(version_t* version); + +#ifdef __cplusplus +} +#endif + +#endif //_TEXT2BITMAP_LIB_H + diff --git a/include/ambarella/vproc.h b/include/ambarella/vproc.h new file mode 100644 index 0000000..89b5a71 --- /dev/null +++ b/include/ambarella/vproc.h @@ -0,0 +1,546 @@ +/******************************************************************************* + * vproc.h + * + * History: + * 2018/08/03 - [Hao Wang] created for CV22 + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise iproare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#ifndef _VPROC_H_ +#define _VPROC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define IN +#define OUT +#define IN_OUT + +struct vproc_version { + uint32_t major; + uint32_t minor; + uint32_t patch; + unsigned int mod_time; + char description[64]; +}; + +typedef enum data_type_s { + DT_FX8 = 0, + DT_FX16 = 1, + DT_FP16 = 2, +} data_type_t; + +typedef enum color_space_s { + /* General vector*/ + CS_VECT = 0, + + /* RGB list*/ + CS_RGB = 1, // AMB RGB format, refering to plane-interleaved RGB data + CS_BGR = 2, // AMB BGR format, refering to plane-interleaved BGR data + CS_RGB_ITL = 3, // OpenCV RGB format, refering to element-interleaved RGB data + CS_BGR_ITL = 4, // OpenCV BGR format, refering to element-interleaved BGR data + CS_RGB_LAST, + CS_RGB_FIRST = CS_RGB, + + /* YUV list*/ + CS_NV12 = 10, // NV12 data + CS_Y = 11, // single channel, i.e. y data + CS_ITL = 12, // element-interleaved channel, i.e. uv data + CS_YUV_LAST, + CS_YUV_FIRST = CS_NV12, +} color_space_t; + +typedef enum cvt_code_s { + FX8_2_FX8 = 0, + FX8_2_FX16 = 1, + FX8_2_FP16 = 2, + FX16_2_FX16 = 3, + FX16_2_FX8 = 4, + FX16_2_FP16 = 5, + FP16_2_FP16 = 6, + FP16_2_FX8 = 7, + FP16_2_FX16 = 8, + FP32_2_FX8 = 9, + FP32_2_FX16 = 10, + FP32_2_FP16 = 11, + FX8_2_FP32 = 12, + FX16_2_FP32 = 13, + FP16_2_FP32 = 14, + FP32_2_FP32 = 15, +} cvt_code_t; + +typedef struct roi_area_s { + uint32_t xoffset; // start x postion + uint32_t yoffset; // start y position + uint32_t width; // width of ROI + uint32_t height; // height of ROI +} roi_area_t; + +typedef struct vect_shape_s { + uint32_t p; // PLANE + uint32_t d; // DEPTH + uint32_t h; // HEIGHT + uint32_t w; // WIDTH +} vect_shape_t; + +typedef struct data_format_s{ + int8_t sign; // Sign bit: 0 for unsigned, 1 for sined + int8_t datasize; // 0 for 8bit, 1 for 16bit + int8_t exp_offset; // Q value for quantized data + int8_t exp_bits; // exp bits for floating point +} data_format_t; + +typedef struct vect_desc_s { + uint32_t data_addr; + uint32_t pitch; + vect_shape_t shape; + data_format_t data_format; + color_space_t color_space; + roi_area_t roi; +} vect_desc_t; + +typedef struct deformation_extra_s { + int32_t uv_offset; +} deformation_extra_t; + +typedef struct polish_extra_s { + vect_desc_t *mean; + float scale; +} polish_extra_t; + +/* Define yuv2rgb_mat as below + [R G B]T = [yc 0 rv; yc -gu -gv; yc bu 0] x [Y-yb U-128 V-128]T + + Default values: + yc = 1 + rv = 1.402 + gu = 0.344136 + gv = 0.714136 + bu = 1.772 + yb = 0 +*/ +typedef struct yuv2rgb_mat_s { + float yc; + float rv; + float gu; + float gv; + float bu; + float yb; +} yuv2rgb_mat_t; + + +typedef struct harris_cfg_s { + float threshold; + uint32_t nms_size; +} harris_cfg_t; + + +typedef struct optlk_cfg_s { + float resp_threshold; //resp = r1*r2 - k * (r1 + r2)^2 + int32_t with_k; //one: k=0.04, zero: k=0 +} optlk_cfg_t; + +typedef struct bw_cfg_s { + int32_t with_abs; //zero: no-abs non-zero:with-abs + float bw_threshold; + uint32_t compare_method; //0:> 1:< 2:>= 3:<= 4:== 5:!= + uint8_t black_value; + uint8_t white_value; +} bw_cfg_t; + + + + +#ifndef AMBA_API +#define AMBA_API __attribute__((visibility("default"))) +#endif + +/* Get vproc libarary version + +*/ +AMBA_API int vproc_get_version(struct vproc_version *ver); + +/* Init vproc libarary + + @param bin_name Bin file to load. + @param size Avaiable size for bin loading. +*/ +AMBA_API int vproc_init(IN const char *bin_name, + IN_OUT uint32_t *size); + +/* Init vproc libarary + + @param virt Virtual address that keeps vproc bin data. + @param size Avaiable size for bin loading. +*/ +AMBA_API int vproc_init_from_mem(void *feed_virt, + IN_OUT uint32_t *size); + +/* Load vproc libarary + + @param fd_cavalry + @param virt_addr Virtual address to load bin. + @param phy_addr Start address to load bin. + @param size Malloced dram size. +*/ +AMBA_API int vproc_load(IN int fd_cavalry, + IN uint8_t *virt_addr, + IN uint32_t phy_addr, + IN uint32_t size); + +/* Exit vproc libarary +*/ +AMBA_API int vproc_exit(); + +/* Run vproc_crop, cropping area is the ROI in input vector. + + @param src Input vector. + @param dst Output vector. +*/ +AMBA_API int vproc_crop(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_resize_vect_batch + + @param src Input vector. + @param dst Output vector. + @param batch_num Number of loop. +*/ +AMBA_API int vproc_resize_vect_batch(vect_desc_t *src_vect, + vect_desc_t *dst_vect, int count); + +/* Run vproc_resize + + @param src Input vector. + @param dst Output vector. +*/ +AMBA_API int vproc_resize(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_resize_single_channel. Support one channel data which could be + Y-Channel, R-Channel, G-Channel, B-Channel and so on. + + @param src Input vector. + @param dst Output vector. +*/ +AMBA_API int vproc_resize_single_channel(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_resize_interleave_channel. Support 2-channel interleaved whick + looks like: + UVUVUVUVUVUV + UVUVUVUVUVUV + UVUVUVUVUVUV + + @param src Input vector. + @param dst Output vector. +*/ +AMBA_API int vproc_resize_interleave_channel(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_yuv2rgb_420 + + @param y Y-Channel data. + @param uv UV-Channle data. + @param rgb RGB-Channel data. + @param yuv2rgb_mat YUV to RGB conversion matrix. +*/ +AMBA_API int vproc_yuv2rgb_420(IN vect_desc_t *y, + IN vect_desc_t *uv, + OUT vect_desc_t *rgb, + IN yuv2rgb_mat_t *yuv2rgb_mat); + +/* Run vproc_submean + + @param src Input vector. + @param mean Mean data. + @param dst Ouput data. +*/ +AMBA_API int vproc_submean(IN vect_desc_t *src, + IN vect_desc_t *mean, + OUT vect_desc_t *dst); + +/* Run vproc_scale_ext + + @param src Input data. + @param dst Ouput data. + @param scl scale factor. +*/ +AMBA_API int vproc_scale_ext(IN vect_desc_t *src, + OUT vect_desc_t *dst, + IN float scl); + +/* Run vproc_dtcvt + + @param src Input data. + @param dst Ouput data. +*/ +AMBA_API int vproc_dtcvt(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_rotate + + @param src Input data. + @param dst Ouput data. + @param rotate_flip_bitmap Input rotate_flip_bitmap. + 4: pflip; 3: dflip; 2: vflip; 1: hflip; 0: rotate. E.g. vflip+rotate: 0x05 (00101) +*/ +AMBA_API int vproc_rotate(IN vect_desc_t *src, + OUT vect_desc_t *dst, IN uint32_t src_rotate_flip_bitmap); + +/* Run vproc_imcvt + + @param src Input data. + @param dst Ouput data. +*/ +AMBA_API int vproc_imcvt(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_10bitpackedfx16_to_uint16 + + @param src Input data. + @param dst Ouput data. +*/ +AMBA_API int vproc_10bitpacked_to_uint16(IN vect_desc_t *src, + OUT vect_desc_t *dst); + +/* Run vproc_image_deformation + + A high-level API handles image deformation operations, such as yuv2rgb, + resize which internally calls low-level APIs. + +*/ +AMBA_API int vproc_image_deformation(IN vect_desc_t *src, + OUT vect_desc_t *dst, IN deformation_extra_t *dext); + +/* Run vproc_data_polish + + A high-level API handles data pre-processing operations, such as + mean subtraction, scale, data format conversion, which internally + calls low-level APIs. + +*/ +AMBA_API int vproc_data_polish(IN vect_desc_t *src, + OUT vect_desc_t *dst, IN polish_extra_t *pext); +/* Run vproc_harris + + @param im_vect Input data. + @param threshold Harris Point select threshold. + @param det_bit_vect Ouput data. + @param resp_vect the harris reponse. + @param maxresp_vect the peak of the harris reponse. +*/ +AMBA_API int vproc_harris(IN vect_desc_t *im_vect, IN float threshold, + OUT vect_desc_t *det_bit_vect, OUT vect_desc_t *resp_vect, OUT vect_desc_t *maxresp_vect); + + +/* Run vproc_harris + + @param im_vect Input data. + @param harris_param, include threshold, nms window size. + @param det_bit_vect Ouput data. + @param resp_vect the harris reponse. + @param maxresp_vect the peak of the harris reponse. +*/ +AMBA_API int vproc_harris_ext(IN vect_desc_t *im_vect, IN harris_cfg_t *harris_param, + OUT vect_desc_t *det_bit_vect, OUT vect_desc_t *resp_vect, OUT vect_desc_t *maxresp_vect); + + +/* Run vproc_cvfilter_init + + @param None. + perfom to initilize the cvfilter module +*/ +AMBA_API int vproc_cvfilter_init(void); +/* Run vproc_cvfilter_release + @param None. + perfom to release the resource from cvfilter module +*/ +AMBA_API int vproc_cvfilter_release(void); + + +/* Run vproc_cvfilter + @param im_vect Input data. + @param ker_vect kernel vector. + @param out_vect Ouput data. +*/ +AMBA_API int vproc_cvfilter(IN vect_desc_t *im_vect, IN float* ker_content, + IN uint32_t ker_h, IN uint32_t ker_w, OUT vect_desc_t *out_vect); + +/* Run vproc_lpcvfilter + @param im_vect Input data. + @param ker_vect kernel vector. + @param out_vect Ouput data. +*/ +AMBA_API int vproc_lpcvfilter(IN vect_desc_t *im_vect, IN float* ker_content, + IN uint32_t ker_h, IN uint32_t ker_w, OUT vect_desc_t *out_vect); + + +/* Run vproc_morph_init + + @param None. + perfom to initilize the morph module +*/ +AMBA_API int vproc_morph_init(void); +/* Run vproc_morph_release + @param None. + perfom to release the resource from morph module +*/ +AMBA_API int vproc_morph_release(void); + + +/* Run vproc_morph + + @param im_vect Input data. + @param out_vect Ouput data. + @param morph_h height of morph kernel. + @param morph_w width of morph kernel. + @param ker_data kernel data. + @param morph_method morph method selection. +*/ +AMBA_API int vproc_morph(IN vect_desc_t *im_vect, OUT vect_desc_t *out_vect, + IN int morph_h, IN int morph_w, IN float* ker_data, IN int morph_method); + +/* Run vproc_perspect_init + + @param im_h input height. + @param im_w input width. +*/ +AMBA_API void* vproc_perspect_init(IN int im_h, IN int im_w); + +/* Run vproc_perspect_release + @param handler. +*/ +AMBA_API int vproc_perspect_release(IN void* handler); + + +/* Run vproc_perspect_load_warp_mat + @param handler. + @param prj_mat_vect Perspective Matrix. +*/ +AMBA_API int vproc_perspect_load_warp_mat(IN void* handler, IN vect_desc_t *prj_mat_vect); + +/* Run vproc_perspect_warp + @param handler. + @param im_src input image. + @param warp_out warp out image. +*/ +AMBA_API int vproc_perspect_warp(IN void* handler, IN vect_desc_t *im_src, OUT vect_desc_t *warp_out); + +/* Run vproc_optlk_init + + @param None. + perfom to initilize the optical LK module +*/ +AMBA_API int vproc_optlk_init(void); +/* Run vproc_optlk_release + @param None. + perfom to release the resource from optical LK module +*/ +AMBA_API int vproc_optlk_release(void); + +/* Run vproc_optlk + @param im0_vect. + @param im1_vect. + @param optwin_coeff. + @param optwin_h + @param optwin_w + @param opt_param. + @param dxy_vect. + @param peak_vect. +*/ +AMBA_API int vproc_optlk(IN vect_desc_t *im0_vect, IN vect_desc_t *im1_vect, + IN float* optwin_data, IN uint32_t optwin_h, IN uint32_t optwin_w, IN optlk_cfg_t *opt_param, + OUT vect_desc_t *dxy_vect, OUT vect_desc_t *peak_vect); + + +/* Run vproc_cdist_init + + @param None. + perfom to initilize the cdist(cosine distance) module +*/ +AMBA_API int vproc_cdist_init(void); + +/* Run vproc_cdist_release + @param None. + perfom to release the resource from cdist(cosine distance) module +*/ +AMBA_API int vproc_cdist_release(void); + +/* Run vproc_cdist + @param in1_vect , intput vector 1 + @param in2_vect, input vector 2 + @param cdist_val, output cosine distance value +*/ +AMBA_API int vproc_cdist(IN vect_desc_t *in1_vect, IN vect_desc_t *in2_vect, OUT float *cdist_val); + +/* Run vproc_imhist + @param grayim_vect, input grayscale image data vector + @param histout_vect, output histogram bins vector +*/ +AMBA_API int vproc_imhist(IN vect_desc_t *grayim_vect, OUT vect_desc_t *histout_vect); + +/* Run vproc_bw + + @param im_vect input 2D vector. + @param bw_vect output black-white map. + @param param config parameters. +*/ +AMBA_API int vproc_bw(IN vect_desc_t *im_vect, OUT vect_desc_t *bw_vect, IN bw_cfg_t* param); + + +/* Run vproc_memcpy + + @param dst_phy_addr Destination data physical address. + @param src_phy_addr Source data physical address. + @param size copy size. +*/ +AMBA_API int vproc_memcpy(IN uint32_t dst_phy_addr, IN uint32_t src_phy_addr, IN uint32_t size); + +/* Run dsi_split_query + @param input dsi_u16's width + @param input dsi_u16's height + @param required size +*/ +AMBA_API void dsi_split_query(IN uint32_t dsi_w, IN uint32_t dsi_h, OUT uint32_t *size); + +/* Run dsi_split_run + @param input dsi_u16 vector descriptor + @param physical address allocated for dsi_split + @param virtual address allocated for dsi_split + @param msb_stream info + @param lsb_stream info +*/ +AMBA_API int dsi_split_run(IN vect_desc_t *dsi_u16, IN uint32_t dsi_split_mem, + IN void *dsi_split_virt, OUT vect_desc_t *msb_stream, OUT vect_desc_t *lsb_stream); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/opencv/cv.h b/include/opencv/cv.h new file mode 100644 index 0000000..19a74e2 --- /dev/null +++ b/include/opencv/cv.h @@ -0,0 +1,73 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CV_H +#define OPENCV_OLD_CV_H + +#if defined(_MSC_VER) + #define CV_DO_PRAGMA(x) __pragma(x) + #define __CVSTR2__(x) #x + #define __CVSTR1__(x) __CVSTR2__(x) + #define __CVMSVCLOC__ __FILE__ "("__CVSTR1__(__LINE__)") : " + #define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (__CVMSVCLOC__ _msg)) +#elif defined(__GNUC__) + #define CV_DO_PRAGMA(x) _Pragma (#x) + #define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (_msg)) +#else + #define CV_DO_PRAGMA(x) + #define CV_MSG_PRAGMA(_msg) +#endif +#define CV_WARNING(x) CV_MSG_PRAGMA("Warning: " #x) + +//CV_WARNING("This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module") + +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" +#include "opencv2/objdetect/objdetect_c.h" + +#if !defined(CV_IMPL) +#define CV_IMPL extern "C" +#endif //CV_IMPL + +#endif // __OPENCV_OLD_CV_H_ diff --git a/include/opencv/cv.hpp b/include/opencv/cv.hpp new file mode 100644 index 0000000..8673956 --- /dev/null +++ b/include/opencv/cv.hpp @@ -0,0 +1,60 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CV_HPP +#define OPENCV_OLD_CV_HPP + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "cv.h" +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/photo.hpp" +#include "opencv2/video.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/calib3d.hpp" +#include "opencv2/objdetect.hpp" + +#endif diff --git a/include/opencv/cvaux.h b/include/opencv/cvaux.h new file mode 100644 index 0000000..c0367cc --- /dev/null +++ b/include/opencv/cvaux.h @@ -0,0 +1,57 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_AUX_H +#define OPENCV_OLD_AUX_H + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" +#include "opencv2/objdetect/objdetect_c.h" + +#endif + +/* End of file. */ diff --git a/include/opencv/cvaux.hpp b/include/opencv/cvaux.hpp new file mode 100644 index 0000000..4888eef --- /dev/null +++ b/include/opencv/cvaux.hpp @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_AUX_HPP +#define OPENCV_OLD_AUX_HPP + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "cvaux.h" +#include "opencv2/core/utility.hpp" + +#endif diff --git a/include/opencv/cvwimage.h b/include/opencv/cvwimage.h new file mode 100644 index 0000000..ec0ab14 --- /dev/null +++ b/include/opencv/cvwimage.h @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////////// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2008, Google, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation or contributors may not 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 the Intel Corporation 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. + + +#ifndef OPENCV_OLD_WIMAGE_HPP +#define OPENCV_OLD_WIMAGE_HPP + +#include "opencv2/core/wimage.hpp" + +#endif diff --git a/include/opencv/cxcore.h b/include/opencv/cxcore.h new file mode 100644 index 0000000..dc070c7 --- /dev/null +++ b/include/opencv/cxcore.h @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CXCORE_H +#define OPENCV_OLD_CXCORE_H + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "opencv2/core/core_c.h" + +#endif diff --git a/include/opencv/cxcore.hpp b/include/opencv/cxcore.hpp new file mode 100644 index 0000000..c371677 --- /dev/null +++ b/include/opencv/cxcore.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CXCORE_HPP +#define OPENCV_OLD_CXCORE_HPP + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "cxcore.h" +#include "opencv2/core.hpp" + +#endif diff --git a/include/opencv/cxeigen.hpp b/include/opencv/cxeigen.hpp new file mode 100644 index 0000000..1d3df91 --- /dev/null +++ b/include/opencv/cxeigen.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_EIGEN_HPP +#define OPENCV_OLD_EIGEN_HPP + +#include "opencv2/core/eigen.hpp" + +#endif diff --git a/include/opencv/cxmisc.h b/include/opencv/cxmisc.h new file mode 100644 index 0000000..9b9bc82 --- /dev/null +++ b/include/opencv/cxmisc.h @@ -0,0 +1,8 @@ +#ifndef OPENCV_OLD_CXMISC_H +#define OPENCV_OLD_CXMISC_H + +#ifdef __cplusplus +# include "opencv2/core/utility.hpp" +#endif + +#endif diff --git a/include/opencv/highgui.h b/include/opencv/highgui.h new file mode 100644 index 0000000..69b394e --- /dev/null +++ b/include/opencv/highgui.h @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_HIGHGUI_H +#define OPENCV_OLD_HIGHGUI_H + +#include "opencv2/core/core_c.h" +#include "opencv2/highgui/highgui_c.h" + +#endif diff --git a/include/opencv/ml.h b/include/opencv/ml.h new file mode 100644 index 0000000..0c376ba --- /dev/null +++ b/include/opencv/ml.h @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_ML_H +#define OPENCV_OLD_ML_H + +#include "opencv2/core/core_c.h" +#include "opencv2/ml.hpp" + +#endif diff --git a/include/opencv2/aruco.hpp b/include/opencv2/aruco.hpp new file mode 100644 index 0000000..ba802a6 --- /dev/null +++ b/include/opencv2/aruco.hpp @@ -0,0 +1,597 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_ARUCO_HPP__ +#define __OPENCV_ARUCO_HPP__ + +#include <opencv2/core.hpp> +#include <vector> +#include "opencv2/aruco/dictionary.hpp" + +/** + * @defgroup aruco ArUco Marker Detection + * This module is dedicated to square fiducial markers (also known as Augmented Reality Markers) + * These markers are useful for easy, fast and robust camera pose estimation.ç + * + * The main functionalities are: + * - Detection of markers in an image + * - Pose estimation from a single marker or from a board/set of markers + * - Detection of ChArUco board for high subpixel accuracy + * - Camera calibration from both, ArUco boards and ChArUco boards. + * - Detection of ChArUco diamond markers + * The samples directory includes easy examples of how to use the module. + * + * The implementation is based on the ArUco Library by R. Muñoz-Salinas and S. Garrido-Jurado @cite Aruco2014. + * + * Markers can also be detected based on the AprilTag 2 @cite wang2016iros fiducial detection method. + * + * @sa S. Garrido-Jurado, R. Muñoz-Salinas, F. J. Madrid-Cuevas, and M. J. Marín-Jiménez. 2014. + * "Automatic generation and detection of highly reliable fiducial markers under occlusion". + * Pattern Recogn. 47, 6 (June 2014), 2280-2292. DOI=10.1016/j.patcog.2014.01.005 + * + * @sa http://www.uco.es/investiga/grupos/ava/node/26 + * + * This module has been originally developed by Sergio Garrido-Jurado as a project + * for Google Summer of Code 2015 (GSoC 15). + * + * +*/ + +namespace cv { +namespace aruco { + +//! @addtogroup aruco +//! @{ + +enum CornerRefineMethod{ + CORNER_REFINE_NONE, ///< Tag and corners detection based on the ArUco approach + CORNER_REFINE_SUBPIX, ///< ArUco approach and refine the corners locations using corner subpixel accuracy + CORNER_REFINE_CONTOUR, ///< ArUco approach and refine the corners locations using the contour-points line fitting + CORNER_REFINE_APRILTAG, ///< Tag and corners detection based on the AprilTag 2 approach @cite wang2016iros +}; + +/** + * @brief Parameters for the detectMarker process: + * - adaptiveThreshWinSizeMin: minimum window size for adaptive thresholding before finding + * contours (default 3). + * - adaptiveThreshWinSizeMax: maximum window size for adaptive thresholding before finding + * contours (default 23). + * - adaptiveThreshWinSizeStep: increments from adaptiveThreshWinSizeMin to adaptiveThreshWinSizeMax + * during the thresholding (default 10). + * - adaptiveThreshConstant: constant for adaptive thresholding before finding contours (default 7) + * - minMarkerPerimeterRate: determine minimum perimeter for marker contour to be detected. This + * is defined as a rate respect to the maximum dimension of the input image (default 0.03). + * - maxMarkerPerimeterRate: determine maximum perimeter for marker contour to be detected. This + * is defined as a rate respect to the maximum dimension of the input image (default 4.0). + * - polygonalApproxAccuracyRate: minimum accuracy during the polygonal approximation process to + * determine which contours are squares. + * - minCornerDistanceRate: minimum distance between corners for detected markers relative to its + * perimeter (default 0.05) + * - minDistanceToBorder: minimum distance of any corner to the image border for detected markers + * (in pixels) (default 3) + * - minMarkerDistanceRate: minimum mean distance beetween two marker corners to be considered + * similar, so that the smaller one is removed. The rate is relative to the smaller perimeter + * of the two markers (default 0.05). + * - cornerRefinementMethod: corner refinement method. (CORNER_REFINE_NONE, no refinement. + * CORNER_REFINE_SUBPIX, do subpixel refinement. CORNER_REFINE_CONTOUR use contour-Points, + * CORNER_REFINE_APRILTAG use the AprilTag2 approach) + * - cornerRefinementWinSize: window size for the corner refinement process (in pixels) (default 5). + * - cornerRefinementMaxIterations: maximum number of iterations for stop criteria of the corner + * refinement process (default 30). + * - cornerRefinementMinAccuracy: minimum error for the stop cristeria of the corner refinement + * process (default: 0.1) + * - markerBorderBits: number of bits of the marker border, i.e. marker border width (default 1). + * - perspectiveRemovePixelPerCell: number of bits (per dimension) for each cell of the marker + * when removing the perspective (default 8). + * - perspectiveRemoveIgnoredMarginPerCell: width of the margin of pixels on each cell not + * considered for the determination of the cell bit. Represents the rate respect to the total + * size of the cell, i.e. perspectiveRemovePixelPerCell (default 0.13) + * - maxErroneousBitsInBorderRate: maximum number of accepted erroneous bits in the border (i.e. + * number of allowed white bits in the border). Represented as a rate respect to the total + * number of bits per marker (default 0.35). + * - minOtsuStdDev: minimun standard deviation in pixels values during the decodification step to + * apply Otsu thresholding (otherwise, all the bits are set to 0 or 1 depending on mean higher + * than 128 or not) (default 5.0) + * - errorCorrectionRate error correction rate respect to the maximun error correction capability + * for each dictionary. (default 0.6). + * - aprilTagMinClusterPixels: reject quads containing too few pixels. + * - aprilTagMaxNmaxima: how many corner candidates to consider when segmenting a group of pixels into a quad. + * - aprilTagCriticalRad: Reject quads where pairs of edges have angles that are close to straight or close to + * 180 degrees. Zero means that no quads are rejected. (In radians). + * - aprilTagMaxLineFitMse: When fitting lines to the contours, what is the maximum mean squared error + * allowed? This is useful in rejecting contours that are far from being quad shaped; rejecting + * these quads "early" saves expensive decoding processing. + * - aprilTagMinWhiteBlackDiff: When we build our model of black & white pixels, we add an extra check that + * the white model must be (overall) brighter than the black model. How much brighter? (in pixel values, [0,255]). + * - aprilTagDeglitch: should the thresholded image be deglitched? Only useful for very noisy images + * - aprilTagQuadDecimate: Detection of quads can be done on a lower-resolution image, improving speed at a + * cost of pose accuracy and a slight decrease in detection rate. Decoding the binary payload is still + * done at full resolution. + * - aprilTagQuadSigma: What Gaussian blur should be applied to the segmented image (used for quad detection?) + * Parameter is the standard deviation in pixels. Very noisy images benefit from non-zero values (e.g. 0.8). + */ +struct CV_EXPORTS_W DetectorParameters { + + DetectorParameters(); + + CV_WRAP static Ptr<DetectorParameters> create(); + + CV_PROP_RW int adaptiveThreshWinSizeMin; + CV_PROP_RW int adaptiveThreshWinSizeMax; + CV_PROP_RW int adaptiveThreshWinSizeStep; + CV_PROP_RW double adaptiveThreshConstant; + CV_PROP_RW double minMarkerPerimeterRate; + CV_PROP_RW double maxMarkerPerimeterRate; + CV_PROP_RW double polygonalApproxAccuracyRate; + CV_PROP_RW double minCornerDistanceRate; + CV_PROP_RW int minDistanceToBorder; + CV_PROP_RW double minMarkerDistanceRate; + CV_PROP_RW int cornerRefinementMethod; + CV_PROP_RW int cornerRefinementWinSize; + CV_PROP_RW int cornerRefinementMaxIterations; + CV_PROP_RW double cornerRefinementMinAccuracy; + CV_PROP_RW int markerBorderBits; + CV_PROP_RW int perspectiveRemovePixelPerCell; + CV_PROP_RW double perspectiveRemoveIgnoredMarginPerCell; + CV_PROP_RW double maxErroneousBitsInBorderRate; + CV_PROP_RW double minOtsuStdDev; + CV_PROP_RW double errorCorrectionRate; + + // April :: User-configurable parameters. + CV_PROP_RW float aprilTagQuadDecimate; + CV_PROP_RW float aprilTagQuadSigma; + + // April :: Internal variables + CV_PROP_RW int aprilTagMinClusterPixels; + CV_PROP_RW int aprilTagMaxNmaxima; + CV_PROP_RW float aprilTagCriticalRad; + CV_PROP_RW float aprilTagMaxLineFitMse; + CV_PROP_RW int aprilTagMinWhiteBlackDiff; + CV_PROP_RW int aprilTagDeglitch; +}; + + + +/** + * @brief Basic marker detection + * + * @param image input image + * @param dictionary indicates the type of markers that will be searched + * @param corners vector of detected marker corners. For each marker, its four corners + * are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, + * the dimensions of this array is Nx4. The order of the corners is clockwise. + * @param ids vector of identifiers of the detected markers. The identifier is of type int + * (e.g. std::vector<int>). For N detected markers, the size of ids is also N. + * The identifiers have the same order than the markers in the imgPoints array. + * @param parameters marker detection parameters + * @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a + * correct codification. Useful for debugging purposes. + * @param cameraMatrix optional input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeff optional vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * + * Performs marker detection in the input image. Only markers included in the specific dictionary + * are searched. For each detected marker, it returns the 2D position of its corner in the image + * and its corresponding identifier. + * Note that this function does not perform pose estimation. + * @sa estimatePoseSingleMarkers, estimatePoseBoard + * + */ +CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners, + OutputArray ids, const Ptr<DetectorParameters> ¶meters = DetectorParameters::create(), + OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray()); + + + +/** + * @brief Pose estimation for single markers + * + * @param corners vector of already detected markers corners. For each marker, its four corners + * are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, + * the dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @sa detectMarkers + * @param markerLength the length of the markers' side. The returning translation vectors will + * be in the same unit. Normally, unit is meters. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvecs array of output rotation vectors (@sa Rodrigues) (e.g. std::vector<cv::Vec3d>). + * Each element in rvecs corresponds to the specific marker in imgPoints. + * @param tvecs array of output translation vectors (e.g. std::vector<cv::Vec3d>). + * Each element in tvecs corresponds to the specific marker in imgPoints. + * @param _objPoints array of object points of all the marker corners + * + * This function receives the detected markers and returns their pose estimation respect to + * the camera individually. So for each marker, one rotation and translation vector is returned. + * The returned transformation is the one that transforms points from each marker coordinate system + * to the camera coordinate system. + * The marker corrdinate system is centered on the middle of the marker, with the Z axis + * perpendicular to the marker plane. + * The coordinates of the four corners of the marker in its own coordinate system are: + * (-markerLength/2, markerLength/2, 0), (markerLength/2, markerLength/2, 0), + * (markerLength/2, -markerLength/2, 0), (-markerLength/2, -markerLength/2, 0) + */ +CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray()); + + + +/** + * @brief Board of markers + * + * A board is a set of markers in the 3D space with a common cordinate system. + * The common form of a board of marker is a planar (2D) board, however any 3D layout can be used. + * A Board object is composed by: + * - The object points of the marker corners, i.e. their coordinates respect to the board system. + * - The dictionary which indicates the type of markers of the board + * - The identifier of all the markers in the board. + */ +class CV_EXPORTS_W Board { + + public: + /** + * @brief Provide way to create Board by passing nessesary data. Specially needed in Python. + * + * @param objPoints array of object points of all the marker corners in the board + * @param dictionary the dictionary of markers employed for this board + * @param ids vector of the identifiers of the markers in the board + * + */ + CV_WRAP static Ptr<Board> create(InputArrayOfArrays objPoints, const Ptr<Dictionary> &dictionary, InputArray ids); + /// array of object points of all the marker corners in the board + /// each marker include its 4 corners in CCW order. For M markers, the size is Mx4. + CV_PROP std::vector< std::vector< Point3f > > objPoints; + + /// the dictionary of markers employed for this board + CV_PROP Ptr<Dictionary> dictionary; + + /// vector of the identifiers of the markers in the board (same size than objPoints) + /// The identifiers refers to the board dictionary + CV_PROP std::vector< int > ids; +}; + + + +/** + * @brief Planar board with grid arrangement of markers + * More common type of board. All markers are placed in the same plane in a grid arrangment. + * The board can be drawn using drawPlanarBoard() function (@sa drawPlanarBoard) + */ +class CV_EXPORTS_W GridBoard : public Board { + + public: + /** + * @brief Draw a GridBoard + * + * @param outSize size of the output image in pixels. + * @param img output image with the board. The size of this image will be outSize + * and the board will be on the center, keeping the board proportions. + * @param marginSize minimum margins (in pixels) of the board in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of the GridBoard, ready to be printed. + */ + CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); + + + /** + * @brief Create a GridBoard object + * + * @param markersX number of markers in X direction + * @param markersY number of markers in Y direction + * @param markerLength marker side length (normally in meters) + * @param markerSeparation separation between two markers (same unit as markerLength) + * @param dictionary dictionary of markers indicating the type of markers + * @param firstMarker id of first marker in dictionary to use on board. + * @return the output GridBoard object + * + * This functions creates a GridBoard object given the number of markers in each direction and + * the marker size and marker separation. + */ + CV_WRAP static Ptr<GridBoard> create(int markersX, int markersY, float markerLength, + float markerSeparation, const Ptr<Dictionary> &dictionary, int firstMarker = 0); + + /** + * + */ + CV_WRAP Size getGridSize() const { return Size(_markersX, _markersY); } + + /** + * + */ + CV_WRAP float getMarkerLength() const { return _markerLength; } + + /** + * + */ + CV_WRAP float getMarkerSeparation() const { return _markerSeparation; } + + + private: + // number of markers in X and Y directions + int _markersX, _markersY; + + // marker side lenght (normally in meters) + float _markerLength; + + // separation between markers in the grid + float _markerSeparation; +}; + + + +/** + * @brief Pose estimation for a board of markers + * + * @param corners vector of already detected markers corners. For each marker, its four corners + * are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, the + * dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @param ids list of identifiers for each marker in corners + * @param board layout of markers in the board. The layout is composed by the marker identifiers + * and the positions of each marker corner in the board reference system. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board + * (see cv::Rodrigues). Used as initial guess if not empty. + * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board. + * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not. + * Used as initial guess if not empty. + * + * This function receives the detected markers and returns the pose of a marker board composed + * by those markers. + * A Board of marker has a single world coordinate system which is defined by the board layout. + * The returned transformation is the one that transforms points from the board coordinate system + * to the camera coordinate system. + * Input markers that are not included in the board layout are ignored. + * The function returns the number of markers from the input employed for the board pose estimation. + * Note that returning a 0 means the pose has not been estimated. + */ +CV_EXPORTS_W int estimatePoseBoard(InputArrayOfArrays corners, InputArray ids, const Ptr<Board> &board, + InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, + OutputArray tvec, bool useExtrinsicGuess = false); + + + + +/** + * @brief Refind not detected markers based on the already detected and the board layout + * + * @param image input image + * @param board layout of markers in the board. + * @param detectedCorners vector of already detected marker corners. + * @param detectedIds vector of already detected marker identifiers. + * @param rejectedCorners vector of rejected candidates during the marker detection process. + * @param cameraMatrix optional input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs optional vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param minRepDistance minimum distance between the corners of the rejected candidate and the + * reprojected marker in order to consider it as a correspondence. + * @param errorCorrectionRate rate of allowed erroneous bits respect to the error correction + * capability of the used dictionary. -1 ignores the error correction step. + * @param checkAllOrders Consider the four posible corner orders in the rejectedCorners array. + * If it set to false, only the provided corner order is considered (default true). + * @param recoveredIdxs Optional array to returns the indexes of the recovered candidates in the + * original rejectedCorners array. + * @param parameters marker detection parameters + * + * This function tries to find markers that were not detected in the basic detecMarkers function. + * First, based on the current detected marker and the board layout, the function interpolates + * the position of the missing markers. Then it tries to find correspondence between the reprojected + * markers and the rejected candidates based on the minRepDistance and errorCorrectionRate + * parameters. + * If camera parameters and distortion coefficients are provided, missing markers are reprojected + * using projectPoint function. If not, missing marker projections are interpolated using global + * homography, and all the marker corners in the board must have the same Z coordinate. + */ +CV_EXPORTS_W void refineDetectedMarkers( + InputArray image,const Ptr<Board> &board, InputOutputArrayOfArrays detectedCorners, + InputOutputArray detectedIds, InputOutputArrayOfArrays rejectedCorners, + InputArray cameraMatrix = noArray(), InputArray distCoeffs = noArray(), + float minRepDistance = 10.f, float errorCorrectionRate = 3.f, bool checkAllOrders = true, + OutputArray recoveredIdxs = noArray(), const Ptr<DetectorParameters> ¶meters = DetectorParameters::create()); + + + +/** + * @brief Draw detected markers in image + * + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param corners positions of marker corners on input image. + * (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, the dimensions of + * this array should be Nx4. The order of the corners should be clockwise. + * @param ids vector of identifiers for markers in markersCorners . + * Optional, if not provided, ids are not painted. + * @param borderColor color of marker borders. Rest of colors (text color and first corner color) + * are calculated based on this one to improve visualization. + * + * Given an array of detected marker corners and its corresponding ids, this functions draws + * the markers in the image. The marker borders are painted and the markers identifiers if provided. + * Useful for debugging purposes. + */ +CV_EXPORTS_W void drawDetectedMarkers(InputOutputArray image, InputArrayOfArrays corners, + InputArray ids = noArray(), + Scalar borderColor = Scalar(0, 255, 0)); + + + +/** + * @brief Draw coordinate system axis from pose estimation + * + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvec rotation vector of the coordinate system that will be drawn. (@sa Rodrigues). + * @param tvec translation vector of the coordinate system that will be drawn. + * @param length length of the painted axis in the same unit than tvec (usually in meters) + * + * Given the pose estimation of a marker or board, this function draws the axis of the world + * coordinate system, i.e. the system centered on the marker/board. Useful for debugging purposes. + */ +CV_EXPORTS_W void drawAxis(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs, + InputArray rvec, InputArray tvec, float length); + + + +/** + * @brief Draw a canonical marker image + * + * @param dictionary dictionary of markers indicating the type of markers + * @param id identifier of the marker that will be returned. It has to be a valid id + * in the specified dictionary. + * @param sidePixels size of the image in pixels + * @param img output image with the marker + * @param borderBits width of the marker border. + * + * This function returns a marker image in its canonical form (i.e. ready to be printed) + */ +CV_EXPORTS_W void drawMarker(const Ptr<Dictionary> &dictionary, int id, int sidePixels, OutputArray img, + int borderBits = 1); + + + +/** + * @brief Draw a planar board + * @sa _drawPlanarBoardImpl + * + * @param board layout of the board that will be drawn. The board should be planar, + * z coordinate is ignored + * @param outSize size of the output image in pixels. + * @param img output image with the board. The size of this image will be outSize + * and the board will be on the center, keeping the board proportions. + * @param marginSize minimum margins (in pixels) of the board in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of a planar board, ready to be printed. It assumes + * the Board layout specified is planar by ignoring the z coordinates of the object points. + */ +CV_EXPORTS_W void drawPlanarBoard(const Ptr<Board> &board, Size outSize, OutputArray img, + int marginSize = 0, int borderBits = 1); + + + +/** + * @brief Implementation of drawPlanarBoard that accepts a raw Board pointer. + */ +void _drawPlanarBoardImpl(Board *board, Size outSize, OutputArray img, + int marginSize = 0, int borderBits = 1); + + + +/** + * @brief Calibrate a camera using aruco markers + * + * @param corners vector of detected marker corners in all frames. + * The corners should have the same format returned by detectMarkers (see #detectMarkers). + * @param ids list of identifiers for each marker in corners + * @param counter number of markers in each frame so that corners and ids can be split + * @param board Marker Board layout + * @param imageSize Size of the image used only to initialize the intrinsic camera matrix. + * @param cameraMatrix Output 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS + * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be + * initialized before calling the function. + * @param distCoeffs Output vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view + * (e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding + * k-th translation vector (see the next output parameter description) brings the board pattern + * from the model coordinate space (in which object points are specified) to the world coordinate + * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1). + * @param tvecs Output vector of translation vectors estimated for each pattern view. + * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + * Order of deviations values: + * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. + * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + * \f$R_i, T_i\f$ are concatenated 1x3 vectors. + * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view. + * @param flags flags Different flags for the calibration process (see #calibrateCamera for details). + * @param criteria Termination criteria for the iterative optimization algorithm. + * + * This function calibrates a camera using an Aruco Board. The function receives a list of + * detected markers from several views of the Board. The process is similar to the chessboard + * calibration in calibrateCamera(). The function returns the final re-projection error. + */ +CV_EXPORTS_AS(calibrateCameraArucoExtended) double calibrateCameraAruco( + InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr<Board> &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + + +/** @brief It's the same function as #calibrateCameraAruco but without calibration error estimation. + */ +CV_EXPORTS_W double calibrateCameraAruco( + InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr<Board> &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + + +/** + * @brief Given a board configuration and a set of detected markers, returns the corresponding + * image points and object points to call solvePnP + * + * @param board Marker board layout. + * @param detectedCorners List of detected marker corners of the board. + * @param detectedIds List of identifiers for each marker. + * @param objPoints Vector of vectors of board marker points in the board coordinate space. + * @param imgPoints Vector of vectors of the projections of board marker corner points. +*/ +CV_EXPORTS_W void getBoardObjectAndImagePoints(const Ptr<Board> &board, InputArrayOfArrays detectedCorners, + InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints); + + +//! @} +} +} + +#endif diff --git a/include/opencv2/aruco/charuco.hpp b/include/opencv2/aruco/charuco.hpp new file mode 100644 index 0000000..be535c7 --- /dev/null +++ b/include/opencv2/aruco/charuco.hpp @@ -0,0 +1,343 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_CHARUCO_HPP__ +#define __OPENCV_CHARUCO_HPP__ + +#include <opencv2/core.hpp> +#include <vector> +#include <opencv2/aruco.hpp> + + +namespace cv { +namespace aruco { + +//! @addtogroup aruco +//! @{ + + +/** + * @brief ChArUco board + * Specific class for ChArUco boards. A ChArUco board is a planar board where the markers are placed + * inside the white squares of a chessboard. The benefits of ChArUco boards is that they provide + * both, ArUco markers versatility and chessboard corner precision, which is important for + * calibration and pose estimation. + * This class also allows the easy creation and drawing of ChArUco boards. + */ +class CV_EXPORTS_W CharucoBoard : public Board { + + public: + // vector of chessboard 3D corners precalculated + CV_PROP std::vector< Point3f > chessboardCorners; + + // for each charuco corner, nearest marker id and nearest marker corner id of each marker + CV_PROP std::vector< std::vector< int > > nearestMarkerIdx; + CV_PROP std::vector< std::vector< int > > nearestMarkerCorners; + + /** + * @brief Draw a ChArUco board + * + * @param outSize size of the output image in pixels. + * @param img output image with the board. The size of this image will be outSize + * and the board will be on the center, keeping the board proportions. + * @param marginSize minimum margins (in pixels) of the board in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of the ChArUco board, ready to be printed. + */ + CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); + + + /** + * @brief Create a CharucoBoard object + * + * @param squaresX number of chessboard squares in X direction + * @param squaresY number of chessboard squares in Y direction + * @param squareLength chessboard square side length (normally in meters) + * @param markerLength marker side length (same unit than squareLength) + * @param dictionary dictionary of markers indicating the type of markers. + * The first markers in the dictionary are used to fill the white chessboard squares. + * @return the output CharucoBoard object + * + * This functions creates a CharucoBoard object given the number of squares in each direction + * and the size of the markers and chessboard squares. + */ + CV_WRAP static Ptr<CharucoBoard> create(int squaresX, int squaresY, float squareLength, + float markerLength, const Ptr<Dictionary> &dictionary); + + /** + * + */ + CV_WRAP Size getChessboardSize() const { return Size(_squaresX, _squaresY); } + + /** + * + */ + CV_WRAP float getSquareLength() const { return _squareLength; } + + /** + * + */ + CV_WRAP float getMarkerLength() const { return _markerLength; } + + private: + void _getNearestMarkerCorners(); + + // number of markers in X and Y directions + int _squaresX, _squaresY; + + // size of chessboard squares side (normally in meters) + float _squareLength; + + // marker side lenght (normally in meters) + float _markerLength; +}; + + + + +/** + * @brief Interpolate position of ChArUco board corners + * @param markerCorners vector of already detected markers corners. For each marker, its four + * corners are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, the + * dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @param markerIds list of identifiers for each marker in corners + * @param image input image necesary for corner refinement. Note that markers are not detected and + * should be sent in corners and ids parameters. + * @param board layout of ChArUco board. + * @param charucoCorners interpolated chessboard corners + * @param charucoIds interpolated chessboard corners identifiers + * @param cameraMatrix optional 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs optional vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param minMarkers number of adjacent markers that must be detected to return a charuco corner + * + * This function receives the detected markers and returns the 2D position of the chessboard corners + * from a ChArUco board using the detected Aruco markers. If camera parameters are provided, + * the process is based in an approximated pose estimation, else it is based on local homography. + * Only visible corners are returned. For each corner, its corresponding identifier is + * also returned in charucoIds. + * The function returns the number of interpolated corners. + */ +CV_EXPORTS_W int interpolateCornersCharuco(InputArrayOfArrays markerCorners, InputArray markerIds, + InputArray image, const Ptr<CharucoBoard> &board, + OutputArray charucoCorners, OutputArray charucoIds, + InputArray cameraMatrix = noArray(), + InputArray distCoeffs = noArray(), int minMarkers = 2); + + + + +/** + * @brief Pose estimation for a ChArUco board given some of their corners + * @param charucoCorners vector of detected charuco corners + * @param charucoIds list of identifiers for each corner in charucoCorners + * @param board layout of ChArUco board. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board + * (see cv::Rodrigues). + * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board. + * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not. + * + * This function estimates a Charuco board pose from some detected corners. + * The function checks if the input corners are enough and valid to perform pose estimation. + * If pose estimation is valid, returns true, else returns false. + */ +CV_EXPORTS_W bool estimatePoseCharucoBoard(InputArray charucoCorners, InputArray charucoIds, + const Ptr<CharucoBoard> &board, InputArray cameraMatrix, + InputArray distCoeffs, OutputArray rvec, OutputArray tvec, + bool useExtrinsicGuess = false); + + + + +/** + * @brief Draws a set of Charuco corners + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param charucoCorners vector of detected charuco corners + * @param charucoIds list of identifiers for each corner in charucoCorners + * @param cornerColor color of the square surrounding each corner + * + * This function draws a set of detected Charuco corners. If identifiers vector is provided, it also + * draws the id of each corner. + */ +CV_EXPORTS_W void drawDetectedCornersCharuco(InputOutputArray image, InputArray charucoCorners, + InputArray charucoIds = noArray(), + Scalar cornerColor = Scalar(255, 0, 0)); + + + +/** + * @brief Calibrate a camera using Charuco corners + * + * @param charucoCorners vector of detected charuco corners per frame + * @param charucoIds list of identifiers for each corner in charucoCorners per frame + * @param board Marker Board layout + * @param imageSize input image size + * @param cameraMatrix Output 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS + * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be + * initialized before calling the function. + * @param distCoeffs Output vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view + * (e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding + * k-th translation vector (see the next output parameter description) brings the board pattern + * from the model coordinate space (in which object points are specified) to the world coordinate + * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1). + * @param tvecs Output vector of translation vectors estimated for each pattern view. + * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + * Order of deviations values: + * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. + * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + * \f$R_i, T_i\f$ are concatenated 1x3 vectors. + * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view. + * @param flags flags Different flags for the calibration process (see #calibrateCamera for details). + * @param criteria Termination criteria for the iterative optimization algorithm. + * + * This function calibrates a camera using a set of corners of a Charuco Board. The function + * receives a list of detected corners and its identifiers from several views of the Board. + * The function returns the final re-projection error. + */ +CV_EXPORTS_AS(calibrateCameraCharucoExtended) double calibrateCameraCharuco( + InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr<CharucoBoard> &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + +/** @brief It's the same function as #calibrateCameraCharuco but without calibration error estimation. +*/ +CV_EXPORTS_W double calibrateCameraCharuco( + InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr<CharucoBoard> &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + + + +/** + * @brief Detect ChArUco Diamond markers + * + * @param image input image necessary for corner subpixel. + * @param markerCorners list of detected marker corners from detectMarkers function. + * @param markerIds list of marker ids in markerCorners. + * @param squareMarkerLengthRate rate between square and marker length: + * squareMarkerLengthRate = squareLength/markerLength. The real units are not necessary. + * @param diamondCorners output list of detected diamond corners (4 corners per diamond). The order + * is the same than in marker corners: top left, top right, bottom right and bottom left. Similar + * format than the corners returned by detectMarkers (e.g std::vector<std::vector<cv::Point2f> > ). + * @param diamondIds ids of the diamonds in diamondCorners. The id of each diamond is in fact of + * type Vec4i, so each diamond has 4 ids, which are the ids of the aruco markers composing the + * diamond. + * @param cameraMatrix Optional camera calibration matrix. + * @param distCoeffs Optional camera distortion coefficients. + * + * This function detects Diamond markers from the previous detected ArUco markers. The diamonds + * are returned in the diamondCorners and diamondIds parameters. If camera calibration parameters + * are provided, the diamond search is based on reprojection. If not, diamond search is based on + * homography. Homography is faster than reprojection but can slightly reduce the detection rate. + */ +CV_EXPORTS_W void detectCharucoDiamond(InputArray image, InputArrayOfArrays markerCorners, + InputArray markerIds, float squareMarkerLengthRate, + OutputArrayOfArrays diamondCorners, OutputArray diamondIds, + InputArray cameraMatrix = noArray(), + InputArray distCoeffs = noArray()); + + + +/** + * @brief Draw a set of detected ChArUco Diamond markers + * + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param diamondCorners positions of diamond corners in the same format returned by + * detectCharucoDiamond(). (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, + * the dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @param diamondIds vector of identifiers for diamonds in diamondCorners, in the same format + * returned by detectCharucoDiamond() (e.g. std::vector<Vec4i>). + * Optional, if not provided, ids are not painted. + * @param borderColor color of marker borders. Rest of colors (text color and first corner color) + * are calculated based on this one. + * + * Given an array of detected diamonds, this functions draws them in the image. The marker borders + * are painted and the markers identifiers if provided. + * Useful for debugging purposes. + */ +CV_EXPORTS_W void drawDetectedDiamonds(InputOutputArray image, InputArrayOfArrays diamondCorners, + InputArray diamondIds = noArray(), + Scalar borderColor = Scalar(0, 0, 255)); + + + + +/** + * @brief Draw a ChArUco Diamond marker + * + * @param dictionary dictionary of markers indicating the type of markers. + * @param ids list of 4 ids for each ArUco marker in the ChArUco marker. + * @param squareLength size of the chessboard squares in pixels. + * @param markerLength size of the markers in pixels. + * @param img output image with the marker. The size of this image will be + * 3*squareLength + 2*marginSize,. + * @param marginSize minimum margins (in pixels) of the marker in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of a ChArUco marker, ready to be printed. + */ +// TODO cannot be exported yet; conversion from/to Vec4i is not wrapped in core +CV_EXPORTS void drawCharucoDiamond(const Ptr<Dictionary> &dictionary, Vec4i ids, int squareLength, + int markerLength, OutputArray img, int marginSize = 0, + int borderBits = 1); + + + + +//! @} +} +} + +#endif diff --git a/include/opencv2/aruco/dictionary.hpp b/include/opencv2/aruco/dictionary.hpp new file mode 100644 index 0000000..27c7e5d --- /dev/null +++ b/include/opencv2/aruco/dictionary.hpp @@ -0,0 +1,212 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_DICTIONARY_HPP__ +#define __OPENCV_DICTIONARY_HPP__ + +#include <opencv2/core.hpp> + +namespace cv { +namespace aruco { + +//! @addtogroup aruco +//! @{ + + +/** + * @brief Dictionary/Set of markers. It contains the inner codification + * + * bytesList contains the marker codewords where + * - bytesList.rows is the dictionary size + * - each marker is encoded using `nbytes = ceil(markerSize*markerSize/8.)` + * - each row contains all 4 rotations of the marker, so its length is `4*nbytes` + * + * `bytesList.ptr(i)[k*nbytes + j]` is then the j-th byte of i-th marker, in its k-th rotation. + */ +class CV_EXPORTS_W Dictionary { + + public: + CV_PROP_RW Mat bytesList; // marker code information + CV_PROP_RW int markerSize; // number of bits per dimension + CV_PROP_RW int maxCorrectionBits; // maximum number of bits that can be corrected + + + /** + */ + Dictionary(const Mat &_bytesList = Mat(), int _markerSize = 0, int _maxcorr = 0); + + + /** + Dictionary(const Dictionary &_dictionary); + */ + + + /** + */ + Dictionary(const Ptr<Dictionary> &_dictionary); + + + /** + * @see generateCustomDictionary + */ + CV_WRAP_AS(create) static Ptr<Dictionary> create(int nMarkers, int markerSize, int randomSeed=0); + + + /** + * @see generateCustomDictionary + */ + CV_WRAP_AS(create_from) static Ptr<Dictionary> create(int nMarkers, int markerSize, + const Ptr<Dictionary> &baseDictionary, int randomSeed=0); + + /** + * @see getPredefinedDictionary + */ + CV_WRAP static Ptr<Dictionary> get(int dict); + + /** + * @brief Given a matrix of bits. Returns whether if marker is identified or not. + * It returns by reference the correct id (if any) and the correct rotation + */ + bool identify(const Mat &onlyBits, int &idx, int &rotation, double maxCorrectionRate) const; + + /** + * @brief Returns the distance of the input bits to the specific id. If allRotations is true, + * the four posible bits rotation are considered + */ + int getDistanceToId(InputArray bits, int id, bool allRotations = true) const; + + + /** + * @brief Draw a canonical marker image + */ + CV_WRAP void drawMarker(int id, int sidePixels, OutputArray _img, int borderBits = 1) const; + + + /** + * @brief Transform matrix of bits to list of bytes in the 4 rotations + */ + CV_WRAP static Mat getByteListFromBits(const Mat &bits); + + + /** + * @brief Transform list of bytes to matrix of bits + */ + CV_WRAP static Mat getBitsFromByteList(const Mat &byteList, int markerSize); +}; + + + + +/** + * @brief Predefined markers dictionaries/sets + * Each dictionary indicates the number of bits and the number of markers contained + * - DICT_ARUCO_ORIGINAL: standard ArUco Library Markers. 1024 markers, 5x5 bits, 0 minimum + distance + */ +enum PREDEFINED_DICTIONARY_NAME { + DICT_4X4_50 = 0, + DICT_4X4_100, + DICT_4X4_250, + DICT_4X4_1000, + DICT_5X5_50, + DICT_5X5_100, + DICT_5X5_250, + DICT_5X5_1000, + DICT_6X6_50, + DICT_6X6_100, + DICT_6X6_250, + DICT_6X6_1000, + DICT_7X7_50, + DICT_7X7_100, + DICT_7X7_250, + DICT_7X7_1000, + DICT_ARUCO_ORIGINAL, + DICT_APRILTAG_16h5, ///< 4x4 bits, minimum hamming distance between any two codes = 5, 30 codes + DICT_APRILTAG_25h9, ///< 5x5 bits, minimum hamming distance between any two codes = 9, 35 codes + DICT_APRILTAG_36h10, ///< 6x6 bits, minimum hamming distance between any two codes = 10, 2320 codes + DICT_APRILTAG_36h11 ///< 6x6 bits, minimum hamming distance between any two codes = 11, 587 codes +}; + + +/** + * @brief Returns one of the predefined dictionaries defined in PREDEFINED_DICTIONARY_NAME + */ +CV_EXPORTS Ptr<Dictionary> getPredefinedDictionary(PREDEFINED_DICTIONARY_NAME name); + + +/** + * @brief Returns one of the predefined dictionaries referenced by DICT_*. + */ +CV_EXPORTS_W Ptr<Dictionary> getPredefinedDictionary(int dict); + + +/** + * @see generateCustomDictionary + */ +CV_EXPORTS_AS(custom_dictionary) Ptr<Dictionary> generateCustomDictionary( + int nMarkers, + int markerSize, + int randomSeed=0); + + +/** + * @brief Generates a new customizable marker dictionary + * + * @param nMarkers number of markers in the dictionary + * @param markerSize number of bits per dimension of each markers + * @param baseDictionary Include the markers in this dictionary at the beginning (optional) + * @param randomSeed a user supplied seed for theRNG() + * + * This function creates a new dictionary composed by nMarkers markers and each markers composed + * by markerSize x markerSize bits. If baseDictionary is provided, its markers are directly + * included and the rest are generated based on them. If the size of baseDictionary is higher + * than nMarkers, only the first nMarkers in baseDictionary are taken and no new marker is added. + */ +CV_EXPORTS_AS(custom_dictionary_from) Ptr<Dictionary> generateCustomDictionary( + int nMarkers, + int markerSize, + const Ptr<Dictionary> &baseDictionary, + int randomSeed=0); + + + +//! @} +} +} + +#endif diff --git a/include/opencv2/bgsegm.hpp b/include/opencv2/bgsegm.hpp new file mode 100644 index 0000000..8ace5d9 --- /dev/null +++ b/include/opencv2/bgsegm.hpp @@ -0,0 +1,380 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_BGSEGM_HPP__ +#define __OPENCV_BGSEGM_HPP__ + +#include "opencv2/video.hpp" + +#ifdef __cplusplus + +/** @defgroup bgsegm Improved Background-Foreground Segmentation Methods +*/ + +namespace cv +{ +namespace bgsegm +{ + +//! @addtogroup bgsegm +//! @{ + +/** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm. + +The class implements the algorithm described in @cite KB2001 . + */ +class CV_EXPORTS_W BackgroundSubtractorMOG : public BackgroundSubtractor +{ +public: + CV_WRAP virtual int getHistory() const = 0; + CV_WRAP virtual void setHistory(int nframes) = 0; + + CV_WRAP virtual int getNMixtures() const = 0; + CV_WRAP virtual void setNMixtures(int nmix) = 0; + + CV_WRAP virtual double getBackgroundRatio() const = 0; + CV_WRAP virtual void setBackgroundRatio(double backgroundRatio) = 0; + + CV_WRAP virtual double getNoiseSigma() const = 0; + CV_WRAP virtual void setNoiseSigma(double noiseSigma) = 0; +}; + +/** @brief Creates mixture-of-gaussian background subtractor + +@param history Length of the history. +@param nmixtures Number of Gaussian mixtures. +@param backgroundRatio Background ratio. +@param noiseSigma Noise strength (standard deviation of the brightness or each color channel). 0 +means some automatic value. + */ +CV_EXPORTS_W Ptr<BackgroundSubtractorMOG> + createBackgroundSubtractorMOG(int history=200, int nmixtures=5, + double backgroundRatio=0.7, double noiseSigma=0); + + +/** @brief Background Subtractor module based on the algorithm given in @cite Gold2012 . + + Takes a series of images and returns a sequence of mask (8UC1) + images of the same size, where 255 indicates Foreground and 0 represents Background. + This class implements an algorithm described in "Visual Tracking of Human Visitors under + Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere, + A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012. + */ +class CV_EXPORTS_W BackgroundSubtractorGMG : public BackgroundSubtractor +{ +public: + /** @brief Returns total number of distinct colors to maintain in histogram. + */ + CV_WRAP virtual int getMaxFeatures() const = 0; + /** @brief Sets total number of distinct colors to maintain in histogram. + */ + CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; + + /** @brief Returns the learning rate of the algorithm. + + It lies between 0.0 and 1.0. It determines how quickly features are "forgotten" from + histograms. + */ + CV_WRAP virtual double getDefaultLearningRate() const = 0; + /** @brief Sets the learning rate of the algorithm. + */ + CV_WRAP virtual void setDefaultLearningRate(double lr) = 0; + + /** @brief Returns the number of frames used to initialize background model. + */ + CV_WRAP virtual int getNumFrames() const = 0; + /** @brief Sets the number of frames used to initialize background model. + */ + CV_WRAP virtual void setNumFrames(int nframes) = 0; + + /** @brief Returns the parameter used for quantization of color-space. + + It is the number of discrete levels in each channel to be used in histograms. + */ + CV_WRAP virtual int getQuantizationLevels() const = 0; + /** @brief Sets the parameter used for quantization of color-space + */ + CV_WRAP virtual void setQuantizationLevels(int nlevels) = 0; + + /** @brief Returns the prior probability that each individual pixel is a background pixel. + */ + CV_WRAP virtual double getBackgroundPrior() const = 0; + /** @brief Sets the prior probability that each individual pixel is a background pixel. + */ + CV_WRAP virtual void setBackgroundPrior(double bgprior) = 0; + + /** @brief Returns the kernel radius used for morphological operations + */ + CV_WRAP virtual int getSmoothingRadius() const = 0; + /** @brief Sets the kernel radius used for morphological operations + */ + CV_WRAP virtual void setSmoothingRadius(int radius) = 0; + + /** @brief Returns the value of decision threshold. + + Decision value is the value above which pixel is determined to be FG. + */ + CV_WRAP virtual double getDecisionThreshold() const = 0; + /** @brief Sets the value of decision threshold. + */ + CV_WRAP virtual void setDecisionThreshold(double thresh) = 0; + + /** @brief Returns the status of background model update + */ + CV_WRAP virtual bool getUpdateBackgroundModel() const = 0; + /** @brief Sets the status of background model update + */ + CV_WRAP virtual void setUpdateBackgroundModel(bool update) = 0; + + /** @brief Returns the minimum value taken on by pixels in image sequence. Usually 0. + */ + CV_WRAP virtual double getMinVal() const = 0; + /** @brief Sets the minimum value taken on by pixels in image sequence. + */ + CV_WRAP virtual void setMinVal(double val) = 0; + + /** @brief Returns the maximum value taken on by pixels in image sequence. e.g. 1.0 or 255. + */ + CV_WRAP virtual double getMaxVal() const = 0; + /** @brief Sets the maximum value taken on by pixels in image sequence. + */ + CV_WRAP virtual void setMaxVal(double val) = 0; +}; + +/** @brief Creates a GMG Background Subtractor + +@param initializationFrames number of frames used to initialize the background models. +@param decisionThreshold Threshold value, above which it is marked foreground, else background. + */ +CV_EXPORTS_W Ptr<BackgroundSubtractorGMG> createBackgroundSubtractorGMG(int initializationFrames=120, + double decisionThreshold=0.8); + +/** @brief Background subtraction based on counting. + + About as fast as MOG2 on a high end system. + More than twice faster than MOG2 on cheap hardware (benchmarked on Raspberry Pi3). + + %Algorithm by Sagi Zeevi ( https://github.com/sagi-z/BackgroundSubtractorCNT ) +*/ +class CV_EXPORTS_W BackgroundSubtractorCNT : public BackgroundSubtractor +{ +public: + // BackgroundSubtractor interface + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; + + /** @brief Returns number of frames with same pixel color to consider stable. + */ + CV_WRAP virtual int getMinPixelStability() const = 0; + /** @brief Sets the number of frames with same pixel color to consider stable. + */ + CV_WRAP virtual void setMinPixelStability(int value) = 0; + + /** @brief Returns maximum allowed credit for a pixel in history. + */ + CV_WRAP virtual int getMaxPixelStability() const = 0; + /** @brief Sets the maximum allowed credit for a pixel in history. + */ + CV_WRAP virtual void setMaxPixelStability(int value) = 0; + + /** @brief Returns if we're giving a pixel credit for being stable for a long time. + */ + CV_WRAP virtual bool getUseHistory() const = 0; + /** @brief Sets if we're giving a pixel credit for being stable for a long time. + */ + CV_WRAP virtual void setUseHistory(bool value) = 0; + + /** @brief Returns if we're parallelizing the algorithm. + */ + CV_WRAP virtual bool getIsParallel() const = 0; + /** @brief Sets if we're parallelizing the algorithm. + */ + CV_WRAP virtual void setIsParallel(bool value) = 0; +}; + +/** @brief Creates a CNT Background Subtractor + +@param minPixelStability number of frames with same pixel color to consider stable +@param useHistory determines if we're giving a pixel credit for being stable for a long time +@param maxPixelStability maximum allowed credit for a pixel in history +@param isParallel determines if we're parallelizing the algorithm + */ + +CV_EXPORTS_W Ptr<BackgroundSubtractorCNT> +createBackgroundSubtractorCNT(int minPixelStability = 15, + bool useHistory = true, + int maxPixelStability = 15*60, + bool isParallel = true); + +enum LSBPCameraMotionCompensation { + LSBP_CAMERA_MOTION_COMPENSATION_NONE = 0, + LSBP_CAMERA_MOTION_COMPENSATION_LK +}; + +/** @brief Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper. + +This algorithm demonstrates better performance on CDNET 2014 dataset compared to other algorithms in OpenCV. + */ +class CV_EXPORTS_W BackgroundSubtractorGSOC : public BackgroundSubtractor +{ +public: + // BackgroundSubtractor interface + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; + + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; +}; + +/** @brief Background Subtraction using Local SVD Binary Pattern. More details about the algorithm can be found at @cite LGuo2016 + */ +class CV_EXPORTS_W BackgroundSubtractorLSBP : public BackgroundSubtractor +{ +public: + // BackgroundSubtractor interface + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; + + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; +}; + +/** @brief This is for calculation of the LSBP descriptors. + */ +class CV_EXPORTS_W BackgroundSubtractorLSBPDesc +{ +public: + static void calcLocalSVDValues(OutputArray localSVDValues, const Mat& frame); + + static void computeFromLocalSVDValues(OutputArray desc, const Mat& localSVDValues, const Point2i* LSBPSamplePoints); + + static void compute(OutputArray desc, const Mat& frame, const Point2i* LSBPSamplePoints); +}; + +/** @brief Creates an instance of BackgroundSubtractorGSOC algorithm. + +Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper. + +@param mc Whether to use camera motion compensation. +@param nSamples Number of samples to maintain at each point of the frame. +@param replaceRate Probability of replacing the old sample - how fast the model will update itself. +@param propagationRate Probability of propagating to neighbors. +@param hitsThreshold How many positives the sample must get before it will be considered as a possible replacement. +@param alpha Scale coefficient for threshold. +@param beta Bias coefficient for threshold. +@param blinkingSupressionDecay Blinking supression decay factor. +@param blinkingSupressionMultiplier Blinking supression multiplier. +@param noiseRemovalThresholdFacBG Strength of the noise removal for background points. +@param noiseRemovalThresholdFacFG Strength of the noise removal for foreground points. + */ +CV_EXPORTS_W Ptr<BackgroundSubtractorGSOC> createBackgroundSubtractorGSOC(int mc = LSBP_CAMERA_MOTION_COMPENSATION_NONE, int nSamples = 20, float replaceRate = 0.003f, float propagationRate = 0.01f, int hitsThreshold = 32, float alpha = 0.01f, float beta = 0.0022f, float blinkingSupressionDecay = 0.1f, float blinkingSupressionMultiplier = 0.1f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f); + +/** @brief Creates an instance of BackgroundSubtractorLSBP algorithm. + +Background Subtraction using Local SVD Binary Pattern. More details about the algorithm can be found at @cite LGuo2016 + +@param mc Whether to use camera motion compensation. +@param nSamples Number of samples to maintain at each point of the frame. +@param LSBPRadius LSBP descriptor radius. +@param Tlower Lower bound for T-values. See @cite LGuo2016 for details. +@param Tupper Upper bound for T-values. See @cite LGuo2016 for details. +@param Tinc Increase step for T-values. See @cite LGuo2016 for details. +@param Tdec Decrease step for T-values. See @cite LGuo2016 for details. +@param Rscale Scale coefficient for threshold values. +@param Rincdec Increase/Decrease step for threshold values. +@param noiseRemovalThresholdFacBG Strength of the noise removal for background points. +@param noiseRemovalThresholdFacFG Strength of the noise removal for foreground points. +@param LSBPthreshold Threshold for LSBP binary string. +@param minCount Minimal number of matches for sample to be considered as foreground. + */ +CV_EXPORTS_W Ptr<BackgroundSubtractorLSBP> createBackgroundSubtractorLSBP(int mc = LSBP_CAMERA_MOTION_COMPENSATION_NONE, int nSamples = 20, int LSBPRadius = 16, float Tlower = 2.0f, float Tupper = 32.0f, float Tinc = 1.0f, float Tdec = 0.05f, float Rscale = 10.0f, float Rincdec = 0.005f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f, int LSBPthreshold = 8, int minCount = 2); + +/** @brief Synthetic frame sequence generator for testing background subtraction algorithms. + + It will generate the moving object on top of the background. + It will apply some distortion to the background to make the test more complex. + */ +class CV_EXPORTS_W SyntheticSequenceGenerator : public Algorithm +{ +private: + const double amplitude; + const double wavelength; + const double wavespeed; + const double objspeed; + unsigned timeStep; + Point2d pos; + Point2d dir; + Mat background; + Mat object; + RNG rng; + +public: + /** @brief Creates an instance of SyntheticSequenceGenerator. + + @param background Background image for object. + @param object Object image which will move slowly over the background. + @param amplitude Amplitude of wave distortion applied to background. + @param wavelength Length of waves in distortion applied to background. + @param wavespeed How fast waves will move. + @param objspeed How fast object will fly over background. + */ + CV_WRAP SyntheticSequenceGenerator(InputArray background, InputArray object, double amplitude, double wavelength, double wavespeed, double objspeed); + + /** @brief Obtain the next frame in the sequence. + + @param frame Output frame. + @param gtMask Output ground-truth (reference) segmentation mask object/background. + */ + CV_WRAP void getNextFrame(OutputArray frame, OutputArray gtMask); +}; + +/** @brief Creates an instance of SyntheticSequenceGenerator. + +@param background Background image for object. +@param object Object image which will move slowly over the background. +@param amplitude Amplitude of wave distortion applied to background. +@param wavelength Length of waves in distortion applied to background. +@param wavespeed How fast waves will move. +@param objspeed How fast object will fly over background. + */ +CV_EXPORTS_W Ptr<SyntheticSequenceGenerator> createSyntheticSequenceGenerator(InputArray background, InputArray object, double amplitude = 2.0, double wavelength = 20.0, double wavespeed = 0.2, double objspeed = 6.0); + +//! @} + +} +} + +#endif +#endif diff --git a/include/opencv2/bioinspired.hpp b/include/opencv2/bioinspired.hpp new file mode 100644 index 0000000..9c7e23b --- /dev/null +++ b/include/opencv2/bioinspired.hpp @@ -0,0 +1,60 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_BIOINSPIRED_HPP__ +#define __OPENCV_BIOINSPIRED_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/bioinspired/retina.hpp" +#include "opencv2/bioinspired/retinafasttonemapping.hpp" +#include "opencv2/bioinspired/transientareassegmentationmodule.hpp" + +/** @defgroup bioinspired Biologically inspired vision models and derivated tools + +The module provides biological visual systems models (human visual system and others). It also +provides derivated objects that take advantage of those bio-inspired models. + +@ref bioinspired_retina + +*/ + +#endif diff --git a/include/opencv2/bioinspired/bioinspired.hpp b/include/opencv2/bioinspired/bioinspired.hpp new file mode 100644 index 0000000..40be285 --- /dev/null +++ b/include/opencv2/bioinspired/bioinspired.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/bioinspired.hpp" diff --git a/include/opencv2/bioinspired/retina.hpp b/include/opencv2/bioinspired/retina.hpp new file mode 100644 index 0000000..d97a80f --- /dev/null +++ b/include/opencv2/bioinspired/retina.hpp @@ -0,0 +1,454 @@ +/*#****************************************************************************** + ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + ** + ** 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. + ** + ** + ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. + ** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping. + ** + ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) + ** + ** Creation - enhancement process 2007-2015 + ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France + ** + ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). + ** Refer to the following research paper for more information: + ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: + ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + ** + ** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : + ** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: + ** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 + ** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. + ** ====> more informations in the above cited Jeanny Heraults's book. + ** + ** License Agreement + ** For Open Source Computer Vision Library + ** + ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. + ** + ** For Human Visual System tools (bioinspired) + ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. + ** + ** Third party copyrights are property of their respective owners. + ** + ** 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. + ** + ** * The name of the copyright holders may not 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 the Intel Corporation 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. + *******************************************************************************/ + +#ifndef __OPENCV_BIOINSPIRED_RETINA_HPP__ +#define __OPENCV_BIOINSPIRED_RETINA_HPP__ + +/** +@file +@date Jul 19, 2011 +@author Alexandre Benoit +*/ + +#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support + + +namespace cv{ +namespace bioinspired{ + +//! @addtogroup bioinspired +//! @{ + +enum { + RETINA_COLOR_RANDOM, //!< each pixel position is either R, G or B in a random choice + RETINA_COLOR_DIAGONAL,//!< color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR... + RETINA_COLOR_BAYER//!< standard bayer sampling +}; + + +/** @brief retina model parameters structure + + For better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel + + Here is the default configuration file of the retina module. It gives results such as the first + retina output shown on the top of this page. + + @code{xml} + <?xml version="1.0"?> + <opencv_storage> + <OPLandIPLparvo> + <colorMode>1</colorMode> + <normaliseOutput>1</normaliseOutput> + <photoreceptorsLocalAdaptationSensitivity>7.5e-01</photoreceptorsLocalAdaptationSensitivity> + <photoreceptorsTemporalConstant>9.0e-01</photoreceptorsTemporalConstant> + <photoreceptorsSpatialConstant>5.3e-01</photoreceptorsSpatialConstant> + <horizontalCellsGain>0.01</horizontalCellsGain> + <hcellsTemporalConstant>0.5</hcellsTemporalConstant> + <hcellsSpatialConstant>7.</hcellsSpatialConstant> + <ganglionCellsSensitivity>7.5e-01</ganglionCellsSensitivity></OPLandIPLparvo> + <IPLmagno> + <normaliseOutput>1</normaliseOutput> + <parasolCells_beta>0.</parasolCells_beta> + <parasolCells_tau>0.</parasolCells_tau> + <parasolCells_k>7.</parasolCells_k> + <amacrinCellsTemporalCutFrequency>2.0e+00</amacrinCellsTemporalCutFrequency> + <V0CompressionParameter>9.5e-01</V0CompressionParameter> + <localAdaptintegration_tau>0.</localAdaptintegration_tau> + <localAdaptintegration_k>7.</localAdaptintegration_k></IPLmagno> + </opencv_storage> + @endcode + + Here is the 'realistic" setup used to obtain the second retina output shown on the top of this page. + + @code{xml} + <?xml version="1.0"?> + <opencv_storage> + <OPLandIPLparvo> + <colorMode>1</colorMode> + <normaliseOutput>1</normaliseOutput> + <photoreceptorsLocalAdaptationSensitivity>8.9e-01</photoreceptorsLocalAdaptationSensitivity> + <photoreceptorsTemporalConstant>9.0e-01</photoreceptorsTemporalConstant> + <photoreceptorsSpatialConstant>5.3e-01</photoreceptorsSpatialConstant> + <horizontalCellsGain>0.3</horizontalCellsGain> + <hcellsTemporalConstant>0.5</hcellsTemporalConstant> + <hcellsSpatialConstant>7.</hcellsSpatialConstant> + <ganglionCellsSensitivity>8.9e-01</ganglionCellsSensitivity></OPLandIPLparvo> + <IPLmagno> + <normaliseOutput>1</normaliseOutput> + <parasolCells_beta>0.</parasolCells_beta> + <parasolCells_tau>0.</parasolCells_tau> + <parasolCells_k>7.</parasolCells_k> + <amacrinCellsTemporalCutFrequency>2.0e+00</amacrinCellsTemporalCutFrequency> + <V0CompressionParameter>9.5e-01</V0CompressionParameter> + <localAdaptintegration_tau>0.</localAdaptintegration_tau> + <localAdaptintegration_k>7.</localAdaptintegration_k></IPLmagno> + </opencv_storage> + @endcode + */ + struct RetinaParameters{ + //! Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters + struct OPLandIplParvoParameters{ + OPLandIplParvoParameters():colorMode(true), + normaliseOutput(true), + photoreceptorsLocalAdaptationSensitivity(0.75f), + photoreceptorsTemporalConstant(0.9f), + photoreceptorsSpatialConstant(0.53f), + horizontalCellsGain(0.01f), + hcellsTemporalConstant(0.5f), + hcellsSpatialConstant(7.f), + ganglionCellsSensitivity(0.75f) { } // default setup + bool colorMode, normaliseOutput; + float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity; + }; + //! Inner Plexiform Layer Magnocellular channel (IplMagno) + struct IplMagnoParameters{ + IplMagnoParameters(): + normaliseOutput(true), + parasolCells_beta(0.f), + parasolCells_tau(0.f), + parasolCells_k(7.f), + amacrinCellsTemporalCutFrequency(2.0f), + V0CompressionParameter(0.95f), + localAdaptintegration_tau(0.f), + localAdaptintegration_k(7.f) { } // default setup + bool normaliseOutput; + float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k; + }; + OPLandIplParvoParameters OPLandIplParvo; + IplMagnoParameters IplMagno; + }; + + + +/** @brief class which allows the Gipsa/Listic Labs model to be used with OpenCV. + +This retina model allows spatio-temporal image processing (applied on still images, video sequences). +As a summary, these are the retina model properties: +- It applies a spectral whithening (mid-frequency details enhancement) +- high frequency spatio-temporal noise reduction +- low frequency luminance to be reduced (luminance range compression) +- local logarithmic luminance compression allows details to be enhanced in low light conditions + +USE : this model can be used basically for spatio-temporal video effects but also for : + _using the getParvo method output matrix : texture analysiswith enhanced signal to noise ratio and enhanced details robust against input images luminance ranges + _using the getMagno method output matrix : motion analysis also with the previously cited properties + +for more information, reer to the following papers : +Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 +Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + +The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : +take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: +B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 +take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. +more informations in the above cited Jeanny Heraults's book. + */ +class CV_EXPORTS_W Retina : public Algorithm { + +public: + + + /** @brief Retreive retina input buffer size + @return the retina input buffer size + */ + CV_WRAP virtual Size getInputSize()=0; + + /** @brief Retreive retina output buffer size that can be different from the input if a spatial log + transformation is applied + @return the retina output buffer size + */ + CV_WRAP virtual Size getOutputSize()=0; + + /** @brief Try to open an XML retina parameters file to adjust current retina instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param retinaParameterFile the parameters filename + @param applyDefaultSetupOnFailure set to true if an error must be thrown on error + + You can retrieve the current parameters structure using the method Retina::getParameters and update + it before running method Retina::setup. + */ + CV_WRAP virtual void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true)=0; + + /** @overload + @param fs the open Filestorage which contains retina parameters + @param applyDefaultSetupOnFailure set to true if an error must be thrown on error + */ + virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0; + + /** @overload + @param newParameters a parameters structures updated with the new target configuration. + */ + virtual void setup(RetinaParameters newParameters)=0; + + /** + @return the current parameters setup + */ + virtual RetinaParameters getParameters()=0; + + /** @brief Outputs a string showing the used parameters setup + @return a string which contains formated parameters information + */ + CV_WRAP virtual const String printSetup()=0; + + /** @brief Write xml/yml formated parameters information + @param fs the filename of the xml file that will be open and writen with formatted parameters + information + */ + CV_WRAP virtual void write( String fs ) const=0; + + /** @overload */ + virtual void write( FileStorage& fs ) const CV_OVERRIDE = 0; + + /** @brief Setup the OPL and IPL parvo channels (see biologocal model) + + OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering + which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance + (low frequency energy) IPL parvo is the OPL next processing stage, it refers to a part of the + Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision. See + reference papers for more informations. + for more informations, please have a look at the paper Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + @param colorMode specifies if (true) color is processed of not (false) to then processing gray + level image + @param normaliseOutput specifies if (true) output is rescaled between 0 and 255 of not (false) + @param photoreceptorsLocalAdaptationSensitivity the photoreceptors sensitivity renage is 0-1 + (more log compression effect when value increases) + @param photoreceptorsTemporalConstant the time constant of the first order low pass filter of + the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is + frames, typical value is 1 frame + @param photoreceptorsSpatialConstant the spatial constant of the first order low pass filter of + the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is + pixels, typical value is 1 pixel + @param horizontalCellsGain gain of the horizontal cells network, if 0, then the mean value of + the output is zero, if the parameter is near 1, then, the luminance is not filtered and is + still reachable at the output, typicall value is 0 + @param HcellsTemporalConstant the time constant of the first order low pass filter of the + horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is + frames, typical value is 1 frame, as the photoreceptors + @param HcellsSpatialConstant the spatial constant of the first order low pass filter of the + horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, + typical value is 5 pixel, this value is also used for local contrast computing when computing + the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular + channel model) + @param ganglionCellsSensitivity the compression strengh of the ganglion cells local adaptation + output, set a value between 0.6 and 1 for best results, a high value increases more the low + value sensitivity... and the output saturates faster, recommended value: 0.7 + */ + CV_WRAP virtual void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7f, const float photoreceptorsTemporalConstant=0.5f, const float photoreceptorsSpatialConstant=0.53f, const float horizontalCellsGain=0.f, const float HcellsTemporalConstant=1.f, const float HcellsSpatialConstant=7.f, const float ganglionCellsSensitivity=0.7f)=0; + + /** @brief Set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel + + this channel processes signals output from OPL processing stage in peripheral vision, it allows + motion information enhancement. It is decorrelated from the details channel. See reference + papers for more details. + + @param normaliseOutput specifies if (true) output is rescaled between 0 and 255 of not (false) + @param parasolCells_beta the low pass filter gain used for local contrast adaptation at the + IPL level of the retina (for ganglion cells local adaptation), typical value is 0 + @param parasolCells_tau the low pass filter time constant used for local contrast adaptation + at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical + value is 0 (immediate response) + @param parasolCells_k the low pass filter spatial constant used for local contrast adaptation + at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical + value is 5 + @param amacrinCellsTemporalCutFrequency the time constant of the first order high pass fiter of + the magnocellular way (motion information channel), unit is frames, typical value is 1.2 + @param V0CompressionParameter the compression strengh of the ganglion cells local adaptation + output, set a value between 0.6 and 1 for best results, a high value increases more the low + value sensitivity... and the output saturates faster, recommended value: 0.95 + @param localAdaptintegration_tau specifies the temporal constant of the low pas filter + involved in the computation of the local "motion mean" for the local adaptation computation + @param localAdaptintegration_k specifies the spatial constant of the low pas filter involved + in the computation of the local "motion mean" for the local adaptation computation + */ + CV_WRAP virtual void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0.f, const float parasolCells_tau=0.f, const float parasolCells_k=7.f, const float amacrinCellsTemporalCutFrequency=1.2f, const float V0CompressionParameter=0.95f, const float localAdaptintegration_tau=0.f, const float localAdaptintegration_k=7.f)=0; + + /** @brief Method which allows retina to be applied on an input image, + + after run, encapsulated retina module is ready to deliver its outputs using dedicated + acccessors, see getParvo and getMagno methods + @param inputImage the input Mat image to be processed, can be gray level or BGR coded in any + format (from 8bit to 16bits) + */ + CV_WRAP virtual void run(InputArray inputImage)=0; + + /** @brief Method which processes an image in the aim to correct its luminance correct + backlight problems, enhance details in shadows. + + This method is designed to perform High Dynamic Range image tone mapping (compress \>8bit/pixel + images to 8bit/pixel). This is a simplified version of the Retina Parvocellular model + (simplified version of the run/getParvo methods call) since it does not include the + spatio-temporal filter modelling the Outer Plexiform Layer of the retina that performs spectral + whitening and many other stuff. However, it works great for tone mapping and in a faster way. + + Check the demos and experiments section to see examples and the way to perform tone mapping + using the original retina model and the method. + + @param inputImage the input image to process (should be coded in float format : CV_32F, + CV_32FC1, CV_32F_C3, CV_32F_C4, the 4th channel won't be considered). + @param outputToneMappedImage the output 8bit/channel tone mapped image (CV_8U or CV_8UC3 format). + */ + CV_WRAP virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0; + + /** @brief Accessor of the details channel of the retina (models foveal vision). + + Warning, getParvoRAW methods return buffers that are not rescaled within range [0;255] while + the non RAW method allows a normalized matrix to be retrieved. + + @param retinaOutput_parvo the output buffer (reallocated if necessary), format can be : + - a Mat, this output is rescaled for standard 8bits image processing use in OpenCV + - RAW methods actually return a 1D matrix (encoding is R1, R2, ... Rn, G1, G2, ..., Gn, B1, + B2, ...Bn), this output is the original retina filter model output, without any + quantification or rescaling. + @see getParvoRAW + */ + CV_WRAP virtual void getParvo(OutputArray retinaOutput_parvo)=0; + + /** @brief Accessor of the details channel of the retina (models foveal vision). + @see getParvo + */ + CV_WRAP virtual void getParvoRAW(OutputArray retinaOutput_parvo)=0; + + /** @brief Accessor of the motion channel of the retina (models peripheral vision). + + Warning, getMagnoRAW methods return buffers that are not rescaled within range [0;255] while + the non RAW method allows a normalized matrix to be retrieved. + @param retinaOutput_magno the output buffer (reallocated if necessary), format can be : + - a Mat, this output is rescaled for standard 8bits image processing use in OpenCV + - RAW methods actually return a 1D matrix (encoding is M1, M2,... Mn), this output is the + original retina filter model output, without any quantification or rescaling. + @see getMagnoRAW + */ + CV_WRAP virtual void getMagno(OutputArray retinaOutput_magno)=0; + + /** @brief Accessor of the motion channel of the retina (models peripheral vision). + @see getMagno + */ + CV_WRAP virtual void getMagnoRAW(OutputArray retinaOutput_magno)=0; + + /** @overload */ + CV_WRAP virtual const Mat getMagnoRAW() const=0; + /** @overload */ + CV_WRAP virtual const Mat getParvoRAW() const=0; + + /** @brief Activate color saturation as the final step of the color demultiplexing process -\> this + saturation is a sigmoide function applied to each channel of the demultiplexed image. + @param saturateColors boolean that activates color saturation (if true) or desactivate (if false) + @param colorSaturationValue the saturation factor : a simple factor applied on the chrominance + buffers + */ + CV_WRAP virtual void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0f)=0; + + /** @brief Clears all retina buffers + + (equivalent to opening the eyes after a long period of eye close ;o) whatchout the temporal + transition occuring just after this method call. + */ + CV_WRAP virtual void clearBuffers()=0; + + /** @brief Activate/desactivate the Magnocellular pathway processing (motion information extraction), by + default, it is activated + @param activate true if Magnocellular output should be activated, false if not... if activated, + the Magnocellular output can be retrieved using the **getMagno** methods + */ + CV_WRAP virtual void activateMovingContoursProcessing(const bool activate)=0; + + /** @brief Activate/desactivate the Parvocellular pathway processing (contours information extraction), by + default, it is activated + @param activate true if Parvocellular (contours information extraction) output should be + activated, false if not... if activated, the Parvocellular output can be retrieved using the + Retina::getParvo methods + */ + CV_WRAP virtual void activateContoursProcessing(const bool activate)=0; + + /** @overload */ + CV_WRAP static Ptr<Retina> create(Size inputSize); + /** @brief Constructors from standardized interfaces : retreive a smart pointer to a Retina instance + + @param inputSize the input frame size + @param colorMode the chosen processing mode : with or without color processing + @param colorSamplingMethod specifies which kind of color sampling will be used : + - cv::bioinspired::RETINA_COLOR_RANDOM: each pixel position is either R, G or B in a random choice + - cv::bioinspired::RETINA_COLOR_DIAGONAL: color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR... + - cv::bioinspired::RETINA_COLOR_BAYER: standard bayer sampling + @param useRetinaLogSampling activate retina log sampling, if true, the 2 following parameters can + be used + @param reductionFactor only usefull if param useRetinaLogSampling=true, specifies the reduction + factor of the output frame (as the center (fovea) is high resolution and corners can be + underscaled, then a reduction of the output is allowed without precision leak + @param samplingStrenght only usefull if param useRetinaLogSampling=true, specifies the strenght of + the log scale that is applied + */ + CV_WRAP static Ptr<Retina> create(Size inputSize, const bool colorMode, + int colorSamplingMethod=RETINA_COLOR_BAYER, + const bool useRetinaLogSampling=false, + const float reductionFactor=1.0f, const float samplingStrenght=10.0f); +}; + +//! @} + +} +} +#endif /* __OPENCV_BIOINSPIRED_RETINA_HPP__ */ diff --git a/include/opencv2/bioinspired/retinafasttonemapping.hpp b/include/opencv2/bioinspired/retinafasttonemapping.hpp new file mode 100644 index 0000000..ba1a872 --- /dev/null +++ b/include/opencv2/bioinspired/retinafasttonemapping.hpp @@ -0,0 +1,138 @@ + +/*#****************************************************************************** + ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + ** + ** 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. + ** + ** + ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. + ** + ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) + ** + ** Creation - enhancement process 2007-2013 + ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France + ** + ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). + ** Refer to the following research paper for more information: + ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: + ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + ** + ** + ** + ** + ** + ** This class is based on image processing tools of the author and already used within the Retina class (this is the same code as method retina::applyFastToneMapping, but in an independent class, it is ligth from a memory requirement point of view). It implements an adaptation of the efficient tone mapping algorithm propose by David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite: + ** -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816 + ** + ** + ** License Agreement + ** For Open Source Computer Vision Library + ** + ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. + ** + ** For Human Visual System tools (bioinspired) + ** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. + ** + ** Third party copyrights are property of their respective owners. + ** + ** 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. + ** + ** * The name of the copyright holders may not 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 the Intel Corporation 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. + *******************************************************************************/ + +#ifndef __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ +#define __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ + +/** +@file +@date May 26, 2013 +@author Alexandre Benoit + */ + +#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support + +namespace cv{ +namespace bioinspired{ + +//! @addtogroup bioinspired +//! @{ + +/** @brief a wrapper class which allows the tone mapping algorithm of Meylan&al(2007) to be used with OpenCV. + +This algorithm is already implemented in thre Retina class (retina::applyFastToneMapping) but used it does not require all the retina model to be allocated. This allows a light memory use for low memory devices (smartphones, etc. +As a summary, these are the model properties: +- 2 stages of local luminance adaptation with a different local neighborhood for each. +- first stage models the retina photorecetors local luminance adaptation +- second stage models th ganglion cells local information adaptation +- compared to the initial publication, this class uses spatio-temporal low pass filters instead of spatial only filters. + this can help noise robustness and temporal stability for video sequence use cases. + +for more information, read to the following papers : +Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 +regarding spatio-temporal filter and the bigger retina model : +Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. +*/ +class CV_EXPORTS_W RetinaFastToneMapping : public Algorithm +{ +public: + + /** @brief applies a luminance correction (initially High Dynamic Range (HDR) tone mapping) + + using only the 2 local adaptation stages of the retina parvocellular channel : photoreceptors + level and ganlion cells level. Spatio temporal filtering is applied but limited to temporal + smoothing and eventually high frequencies attenuation. This is a lighter method than the one + available using the regular retina::run method. It is then faster but it does not include + complete temporal filtering nor retina spectral whitening. Then, it can have a more limited + effect on images with a very high dynamic range. This is an adptation of the original still + image HDR tone mapping algorithm of David Alleyson, Sabine Susstruck and Laurence Meylan's + work, please cite: -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local + Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of + America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816 + + @param inputImage the input image to process RGB or gray levels + @param outputToneMappedImage the output tone mapped image + */ + CV_WRAP virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0; + + /** @brief updates tone mapping behaviors by adjusing the local luminance computation area + + @param photoreceptorsNeighborhoodRadius the first stage local adaptation area + @param ganglioncellsNeighborhoodRadius the second stage local adaptation area + @param meanLuminanceModulatorK the factor applied to modulate the meanLuminance information + (default is 1, see reference paper) + */ + CV_WRAP virtual void setup(const float photoreceptorsNeighborhoodRadius=3.f, const float ganglioncellsNeighborhoodRadius=1.f, const float meanLuminanceModulatorK=1.f)=0; + + CV_WRAP static Ptr<RetinaFastToneMapping> create(Size inputSize); +}; + + +//! @} + +} +} +#endif /* __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ */ diff --git a/include/opencv2/bioinspired/transientareassegmentationmodule.hpp b/include/opencv2/bioinspired/transientareassegmentationmodule.hpp new file mode 100644 index 0000000..115269e --- /dev/null +++ b/include/opencv2/bioinspired/transientareassegmentationmodule.hpp @@ -0,0 +1,204 @@ +/*#****************************************************************************** + ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + ** + ** 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. + ** + ** + ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. + ** TransientAreasSegmentationModule Use: extract areas that present spatio-temporal changes. + ** => It should be used at the output of the cv::bioinspired::Retina::getMagnoRAW() output that enhances spatio-temporal changes + ** + ** Maintainers : Listic lab (code author current affiliation & applications) + ** + ** Creation - enhancement process 2007-2015 + ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France + ** + ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). + ** Refer to the following research paper for more information: + ** Strat, S.T.; Benoit, A.; Lambert, P., "Retina enhanced bag of words descriptors for video classification," Signal Processing Conference (EUSIPCO), 2014 Proceedings of the 22nd European , vol., no., pp.1307,1311, 1-5 Sept. 2014 (http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6952461&isnumber=6951911) + ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: + ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + ** + ** + ** License Agreement + ** For Open Source Computer Vision Library + ** + ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. + ** + ** For Human Visual System tools (bioinspired) + ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. + ** + ** Third party copyrights are property of their respective owners. + ** + ** 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. + ** + ** * The name of the copyright holders may not 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 the Intel Corporation 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. + *******************************************************************************/ + +#ifndef SEGMENTATIONMODULE_HPP_ +#define SEGMENTATIONMODULE_HPP_ + +/** +@file +@date 2007-2013 +@author Alexandre BENOIT, benoit.alexandre.vision@gmail.com +*/ + +#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support + +namespace cv +{ +namespace bioinspired +{ +//! @addtogroup bioinspired +//! @{ + +/** @brief parameter structure that stores the transient events detector setup parameters +*/ +struct SegmentationParameters{ // CV_EXPORTS_W_MAP to export to python native dictionnaries + // default structure instance construction with default values + SegmentationParameters(): + thresholdON(100), + thresholdOFF(100), + localEnergy_temporalConstant(0.5), + localEnergy_spatialConstant(5), + neighborhoodEnergy_temporalConstant(1), + neighborhoodEnergy_spatialConstant(15), + contextEnergy_temporalConstant(1), + contextEnergy_spatialConstant(75){}; + // all properties list + float thresholdON; + float thresholdOFF; + //! the time constant of the first order low pass filter, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 0.5 frame + float localEnergy_temporalConstant; + //! the spatial constant of the first order low pass filter, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 5 pixel + float localEnergy_spatialConstant; + //! local neighborhood energy filtering parameters : the aim is to get information about the energy neighborhood to perform a center surround energy analysis + float neighborhoodEnergy_temporalConstant; + float neighborhoodEnergy_spatialConstant; + //! context neighborhood energy filtering parameters : the aim is to get information about the energy on a wide neighborhood area to filtered out local effects + float contextEnergy_temporalConstant; + float contextEnergy_spatialConstant; +}; + +/** @brief class which provides a transient/moving areas segmentation module + +perform a locally adapted segmentation by using the retina magno input data Based on Alexandre +BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur" + +3 spatio temporal filters are used: +- a first one which filters the noise and local variations of the input motion energy +- a second (more powerfull low pass spatial filter) which gives the neighborhood motion energy the +segmentation consists in the comparison of these both outputs, if the local motion energy is higher +to the neighborhood otion energy, then the area is considered as moving and is segmented +- a stronger third low pass filter helps decision by providing a smooth information about the +"motion context" in a wider area + */ + +class CV_EXPORTS_W TransientAreasSegmentationModule: public Algorithm +{ +public: + + + /** @brief return the sze of the manage input and output images + */ + CV_WRAP virtual Size getSize()=0; + + /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param segmentationParameterFile : the parameters filename + @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error + */ + CV_WRAP virtual void setup(String segmentationParameterFile="", const bool applyDefaultSetupOnFailure=true)=0; + + /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param fs : the open Filestorage which contains segmentation parameters + @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error + */ + virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0; + + /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param newParameters : a parameters structures updated with the new target configuration + */ + virtual void setup(SegmentationParameters newParameters)=0; + + /** @brief return the current parameters setup + */ + virtual SegmentationParameters getParameters()=0; + + /** @brief parameters setup display method + @return a string which contains formatted parameters information + */ + CV_WRAP virtual const String printSetup()=0; + + /** @brief write xml/yml formated parameters information + @param fs : the filename of the xml file that will be open and writen with formatted parameters information + */ + CV_WRAP virtual void write( String fs ) const=0; + + /** @brief write xml/yml formated parameters information + @param fs : a cv::Filestorage object ready to be filled + */ + virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE = 0; + + /** @brief main processing method, get result using methods getSegmentationPicture() + @param inputToSegment : the image to process, it must match the instance buffer size ! + @param channelIndex : the channel to process in case of multichannel images + */ + CV_WRAP virtual void run(InputArray inputToSegment, const int channelIndex=0)=0; + + /** @brief access function + @return the last segmentation result: a boolean picture which is resampled between 0 and 255 for a display purpose + */ + CV_WRAP virtual void getSegmentationPicture(OutputArray transientAreas)=0; + + /** @brief cleans all the buffers of the instance + */ + CV_WRAP virtual void clearAllBuffers()=0; + + /** @brief allocator + @param inputSize : size of the images input to segment (output will be the same size) + */ + CV_WRAP static Ptr<TransientAreasSegmentationModule> create(Size inputSize); +}; + +//! @} + +}} // namespaces end : cv and bioinspired + + +#endif + + diff --git a/include/opencv2/calib3d.hpp b/include/opencv2/calib3d.hpp new file mode 100644 index 0000000..3808526 --- /dev/null +++ b/include/opencv2/calib3d.hpp @@ -0,0 +1,2618 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CALIB3D_HPP +#define OPENCV_CALIB3D_HPP + +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/core/affine.hpp" + +/** + @defgroup calib3d Camera Calibration and 3D Reconstruction + +The functions in this section use a so-called pinhole camera model. In this model, a scene view is +formed by projecting 3D points into the image plane using a perspective transformation. + +\f[s \; m' = A [R|t] M'\f] + +or + +\f[s \vecthree{u}{v}{1} = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} +\begin{bmatrix} +r_{11} & r_{12} & r_{13} & t_1 \\ +r_{21} & r_{22} & r_{23} & t_2 \\ +r_{31} & r_{32} & r_{33} & t_3 +\end{bmatrix} +\begin{bmatrix} +X \\ +Y \\ +Z \\ +1 +\end{bmatrix}\f] + +where: + +- \f$(X, Y, Z)\f$ are the coordinates of a 3D point in the world coordinate space +- \f$(u, v)\f$ are the coordinates of the projection point in pixels +- \f$A\f$ is a camera matrix, or a matrix of intrinsic parameters +- \f$(cx, cy)\f$ is a principal point that is usually at the image center +- \f$fx, fy\f$ are the focal lengths expressed in pixel units. + +Thus, if an image from the camera is scaled by a factor, all of these parameters should be scaled +(multiplied/divided, respectively) by the same factor. The matrix of intrinsic parameters does not +depend on the scene viewed. So, once estimated, it can be re-used as long as the focal length is +fixed (in case of zoom lens). The joint rotation-translation matrix \f$[R|t]\f$ is called a matrix of +extrinsic parameters. It is used to describe the camera motion around a static scene, or vice versa, +rigid motion of an object in front of a still camera. That is, \f$[R|t]\f$ translates coordinates of a +point \f$(X, Y, Z)\f$ to a coordinate system, fixed with respect to the camera. The transformation above +is equivalent to the following (when \f$z \ne 0\f$ ): + +\f[\begin{array}{l} +\vecthree{x}{y}{z} = R \vecthree{X}{Y}{Z} + t \\ +x' = x/z \\ +y' = y/z \\ +u = f_x*x' + c_x \\ +v = f_y*y' + c_y +\end{array}\f] + +The following figure illustrates the pinhole camera model. + +![Pinhole camera model](pics/pinhole_camera_model.png) + +Real lenses usually have some distortion, mostly radial distortion and slight tangential distortion. +So, the above model is extended as: + +\f[\begin{array}{l} +\vecthree{x}{y}{z} = R \vecthree{X}{Y}{Z} + t \\ +x' = x/z \\ +y' = y/z \\ +x'' = x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + 2 p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4 \\ +y'' = y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ +\text{where} \quad r^2 = x'^2 + y'^2 \\ +u = f_x*x'' + c_x \\ +v = f_y*y'' + c_y +\end{array}\f] + +\f$k_1\f$, \f$k_2\f$, \f$k_3\f$, \f$k_4\f$, \f$k_5\f$, and \f$k_6\f$ are radial distortion coefficients. \f$p_1\f$ and \f$p_2\f$ are +tangential distortion coefficients. \f$s_1\f$, \f$s_2\f$, \f$s_3\f$, and \f$s_4\f$, are the thin prism distortion +coefficients. Higher-order coefficients are not considered in OpenCV. + +The next figures show two common types of radial distortion: barrel distortion (typically \f$ k_1 < 0 \f$) and pincushion distortion (typically \f$ k_1 > 0 \f$). + +![](pics/distortion_examples.png) +![](pics/distortion_examples2.png) + +In some cases the image sensor may be tilted in order to focus an oblique plane in front of the +camera (Scheimpfug condition). This can be useful for particle image velocimetry (PIV) or +triangulation with a laser fan. The tilt causes a perspective distortion of \f$x''\f$ and +\f$y''\f$. This distortion can be modelled in the following way, see e.g. @cite Louhichi07. + +\f[\begin{array}{l} +s\vecthree{x'''}{y'''}{1} = +\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}(\tau_x, \tau_y)} +{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} +{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ +u = f_x*x''' + c_x \\ +v = f_y*y''' + c_y +\end{array}\f] + +where the matrix \f$R(\tau_x, \tau_y)\f$ is defined by two rotations with angular parameter \f$\tau_x\f$ +and \f$\tau_y\f$, respectively, + +\f[ +R(\tau_x, \tau_y) = +\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)} +\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} = +\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)} +{0}{\cos(\tau_x)}{\sin(\tau_x)} +{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}. +\f] + +In the functions below the coefficients are passed or returned as + +\f[(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f] + +vector. That is, if the vector contains four elements, it means that \f$k_3=0\f$ . The distortion +coefficients do not depend on the scene viewed. Thus, they also belong to the intrinsic camera +parameters. And they remain the same regardless of the captured image resolution. If, for example, a +camera has been calibrated on images of 320 x 240 resolution, absolutely the same distortion +coefficients can be used for 640 x 480 images from the same camera while \f$f_x\f$, \f$f_y\f$, \f$c_x\f$, and +\f$c_y\f$ need to be scaled appropriately. + +The functions below use the above model to do the following: + +- Project 3D points to the image plane given intrinsic and extrinsic parameters. +- Compute extrinsic parameters given intrinsic parameters, a few 3D points, and their +projections. +- Estimate intrinsic and extrinsic camera parameters from several views of a known calibration +pattern (every view is described by several 3D-2D point correspondences). +- Estimate the relative position and orientation of the stereo camera "heads" and compute the +*rectification* transformation that makes the camera optical axes parallel. + +@note + - A calibration sample for 3 cameras in horizontal position can be found at + opencv_source_code/samples/cpp/3calibration.cpp + - A calibration sample based on a sequence of images can be found at + opencv_source_code/samples/cpp/calibration.cpp + - A calibration sample in order to do 3D reconstruction can be found at + opencv_source_code/samples/cpp/build3dmodel.cpp + - A calibration example on stereo calibration can be found at + opencv_source_code/samples/cpp/stereo_calib.cpp + - A calibration example on stereo matching can be found at + opencv_source_code/samples/cpp/stereo_match.cpp + - (Python) A camera calibration sample can be found at + opencv_source_code/samples/python/calibrate.py + + @{ + @defgroup calib3d_fisheye Fisheye camera model + + Definitions: Let P be a point in 3D of coordinates X in the world reference frame (stored in the + matrix X) The coordinate vector of P in the camera reference frame is: + + \f[Xc = R X + T\f] + + where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om); call x, y + and z the 3 coordinates of Xc: + + \f[x = Xc_1 \\ y = Xc_2 \\ z = Xc_3\f] + + The pinhole projection coordinates of P is [a; b] where + + \f[a = x / z \ and \ b = y / z \\ r^2 = a^2 + b^2 \\ \theta = atan(r)\f] + + Fisheye distortion: + + \f[\theta_d = \theta (1 + k_1 \theta^2 + k_2 \theta^4 + k_3 \theta^6 + k_4 \theta^8)\f] + + The distorted point coordinates are [x'; y'] where + + \f[x' = (\theta_d / r) a \\ y' = (\theta_d / r) b \f] + + Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where: + + \f[u = f_x (x' + \alpha y') + c_x \\ + v = f_y y' + c_y\f] + + @defgroup calib3d_c C API + + @} + */ + +namespace cv +{ + +//! @addtogroup calib3d +//! @{ + +//! type of the robust estimation algorithm +enum { LMEDS = 4, //!< least-median of squares algorithm + RANSAC = 8, //!< RANSAC algorithm + RHO = 16 //!< RHO algorithm + }; + +enum { SOLVEPNP_ITERATIVE = 0, + SOLVEPNP_EPNP = 1, //!< EPnP: Efficient Perspective-n-Point Camera Pose Estimation @cite lepetit2009epnp + SOLVEPNP_P3P = 2, //!< Complete Solution Classification for the Perspective-Three-Point Problem @cite gao2003complete + SOLVEPNP_DLS = 3, //!< A Direct Least-Squares (DLS) Method for PnP @cite hesch2011direct + SOLVEPNP_UPNP = 4, //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation @cite penate2013exhaustive + SOLVEPNP_AP3P = 5, //!< An Efficient Algebraic Solution to the Perspective-Three-Point Problem @cite Ke17 + SOLVEPNP_MAX_COUNT //!< Used for count +}; + +enum { CALIB_CB_ADAPTIVE_THRESH = 1, + CALIB_CB_NORMALIZE_IMAGE = 2, + CALIB_CB_FILTER_QUADS = 4, + CALIB_CB_FAST_CHECK = 8 + }; + +enum { CALIB_CB_SYMMETRIC_GRID = 1, + CALIB_CB_ASYMMETRIC_GRID = 2, + CALIB_CB_CLUSTERING = 4 + }; + +enum { CALIB_USE_INTRINSIC_GUESS = 0x00001, + CALIB_FIX_ASPECT_RATIO = 0x00002, + CALIB_FIX_PRINCIPAL_POINT = 0x00004, + CALIB_ZERO_TANGENT_DIST = 0x00008, + CALIB_FIX_FOCAL_LENGTH = 0x00010, + CALIB_FIX_K1 = 0x00020, + CALIB_FIX_K2 = 0x00040, + CALIB_FIX_K3 = 0x00080, + CALIB_FIX_K4 = 0x00800, + CALIB_FIX_K5 = 0x01000, + CALIB_FIX_K6 = 0x02000, + CALIB_RATIONAL_MODEL = 0x04000, + CALIB_THIN_PRISM_MODEL = 0x08000, + CALIB_FIX_S1_S2_S3_S4 = 0x10000, + CALIB_TILTED_MODEL = 0x40000, + CALIB_FIX_TAUX_TAUY = 0x80000, + CALIB_USE_QR = 0x100000, //!< use QR instead of SVD decomposition for solving. Faster but potentially less precise + CALIB_FIX_TANGENT_DIST = 0x200000, + // only for stereo + CALIB_FIX_INTRINSIC = 0x00100, + CALIB_SAME_FOCAL_LENGTH = 0x00200, + // for stereo rectification + CALIB_ZERO_DISPARITY = 0x00400, + CALIB_USE_LU = (1 << 17), //!< use LU instead of SVD decomposition for solving. much faster but potentially less precise + CALIB_USE_EXTRINSIC_GUESS = (1 << 22) //!< for stereoCalibrate + }; + +//! the algorithm for finding fundamental matrix +enum { FM_7POINT = 1, //!< 7-point algorithm + FM_8POINT = 2, //!< 8-point algorithm + FM_LMEDS = 4, //!< least-median algorithm. 7-point algorithm is used. + FM_RANSAC = 8 //!< RANSAC algorithm. It needs at least 15 points. 7-point algorithm is used. + }; + +enum HandEyeCalibrationMethod +{ + CALIB_HAND_EYE_TSAI = 0, //!< A New Technique for Fully Autonomous and Efficient 3D Robotics Hand/Eye Calibration @cite Tsai89 + CALIB_HAND_EYE_PARK = 1, //!< Robot Sensor Calibration: Solving AX = XB on the Euclidean Group @cite Park94 + CALIB_HAND_EYE_HORAUD = 2, //!< Hand-eye Calibration @cite Horaud95 + CALIB_HAND_EYE_ANDREFF = 3, //!< On-line Hand-Eye Calibration @cite Andreff99 + CALIB_HAND_EYE_DANIILIDIS = 4 //!< Hand-Eye Calibration Using Dual Quaternions @cite Daniilidis98 +}; + + +/** @brief Converts a rotation matrix to a rotation vector or vice versa. + +@param src Input rotation vector (3x1 or 1x3) or rotation matrix (3x3). +@param dst Output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively. +@param jacobian Optional output Jacobian matrix, 3x9 or 9x3, which is a matrix of partial +derivatives of the output array components with respect to the input array components. + +\f[\begin{array}{l} \theta \leftarrow norm(r) \\ r \leftarrow r/ \theta \\ R = \cos{\theta} I + (1- \cos{\theta} ) r r^T + \sin{\theta} \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} \end{array}\f] + +Inverse transformation can be also done easily, since + +\f[\sin ( \theta ) \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} = \frac{R - R^T}{2}\f] + +A rotation vector is a convenient and most compact representation of a rotation matrix (since any +rotation matrix has just 3 degrees of freedom). The representation is used in the global 3D geometry +optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP . + */ +CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); + +/** @example samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp +An example program about pose estimation from coplanar points + +Check @ref tutorial_homography "the corresponding tutorial" for more details +*/ + +/** @brief Finds a perspective transformation between two planes. + +@param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2 +or vector\<Point2f\> . +@param dstPoints Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or +a vector\<Point2f\> . +@param method Method used to compute a homography matrix. The following methods are possible: +- **0** - a regular method using all the points, i.e., the least squares method +- **RANSAC** - RANSAC-based robust method +- **LMEDS** - Least-Median robust method +- **RHO** - PROSAC-based robust method +@param ransacReprojThreshold Maximum allowed reprojection error to treat a point pair as an inlier +(used in the RANSAC and RHO methods only). That is, if +\f[\| \texttt{dstPoints} _i - \texttt{convertPointsHomogeneous} ( \texttt{H} * \texttt{srcPoints} _i) \|_2 > \texttt{ransacReprojThreshold}\f] +then the point \f$i\f$ is considered as an outlier. If srcPoints and dstPoints are measured in pixels, +it usually makes sense to set this parameter somewhere in the range of 1 to 10. +@param mask Optional output mask set by a robust method ( RANSAC or LMEDS ). Note that the input +mask values are ignored. +@param maxIters The maximum number of RANSAC iterations. +@param confidence Confidence level, between 0 and 1. + +The function finds and returns the perspective transformation \f$H\f$ between the source and the +destination planes: + +\f[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\f] + +so that the back-projection error + +\f[\sum _i \left ( x'_i- \frac{h_{11} x_i + h_{12} y_i + h_{13}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2+ \left ( y'_i- \frac{h_{21} x_i + h_{22} y_i + h_{23}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2\f] + +is minimized. If the parameter method is set to the default value 0, the function uses all the point +pairs to compute an initial homography estimate with a simple least-squares scheme. + +However, if not all of the point pairs ( \f$srcPoints_i\f$, \f$dstPoints_i\f$ ) fit the rigid perspective +transformation (that is, there are some outliers), this initial estimate will be poor. In this case, +you can use one of the three robust methods. The methods RANSAC, LMeDS and RHO try many different +random subsets of the corresponding point pairs (of four pairs each, collinear pairs are discarded), estimate the homography matrix +using this subset and a simple least-squares algorithm, and then compute the quality/goodness of the +computed homography (which is the number of inliers for RANSAC or the least median re-projection error for +LMeDS). The best subset is then used to produce the initial estimate of the homography matrix and +the mask of inliers/outliers. + +Regardless of the method, robust or not, the computed homography matrix is refined further (using +inliers only in case of a robust method) with the Levenberg-Marquardt method to reduce the +re-projection error even more. + +The methods RANSAC and RHO can handle practically any ratio of outliers but need a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. Finally, if there are no outliers and the +noise is rather small, use the default method (method=0). + +The function is used to find initial intrinsic and extrinsic matrices. Homography matrix is +determined up to a scale. Thus, it is normalized so that \f$h_{33}=1\f$. Note that whenever an \f$H\f$ matrix +cannot be estimated, an empty one will be returned. + +@sa +getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, +perspectiveTransform + */ +CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints, + int method = 0, double ransacReprojThreshold = 3, + OutputArray mask=noArray(), const int maxIters = 2000, + const double confidence = 0.995); + +/** @overload */ +CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints, + OutputArray mask, int method = 0, double ransacReprojThreshold = 3 ); + +/** @brief Computes an RQ decomposition of 3x3 matrices. + +@param src 3x3 input matrix. +@param mtxR Output 3x3 upper-triangular matrix. +@param mtxQ Output 3x3 orthogonal matrix. +@param Qx Optional output 3x3 rotation matrix around x-axis. +@param Qy Optional output 3x3 rotation matrix around y-axis. +@param Qz Optional output 3x3 rotation matrix around z-axis. + +The function computes a RQ decomposition using the given rotations. This function is used in +decomposeProjectionMatrix to decompose the left 3x3 submatrix of a projection matrix into a camera +and a rotation matrix. + +It optionally returns three rotation matrices, one for each axis, and the three Euler angles in +degrees (as the return value) that could be used in OpenGL. Note, there is always more than one +sequence of rotations about the three principal axes that results in the same orientation of an +object, e.g. see @cite Slabaugh . Returned tree rotation matrices and corresponding three Euler angles +are only one of the possible solutions. + */ +CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ, + OutputArray Qx = noArray(), + OutputArray Qy = noArray(), + OutputArray Qz = noArray()); + +/** @brief Decomposes a projection matrix into a rotation matrix and a camera matrix. + +@param projMatrix 3x4 input projection matrix P. +@param cameraMatrix Output 3x3 camera matrix K. +@param rotMatrix Output 3x3 external rotation matrix R. +@param transVect Output 4x1 translation vector T. +@param rotMatrixX Optional 3x3 rotation matrix around x-axis. +@param rotMatrixY Optional 3x3 rotation matrix around y-axis. +@param rotMatrixZ Optional 3x3 rotation matrix around z-axis. +@param eulerAngles Optional three-element vector containing three Euler angles of rotation in +degrees. + +The function computes a decomposition of a projection matrix into a calibration and a rotation +matrix and the position of a camera. + +It optionally returns three rotation matrices, one for each axis, and three Euler angles that could +be used in OpenGL. Note, there is always more than one sequence of rotations about the three +principal axes that results in the same orientation of an object, e.g. see @cite Slabaugh . Returned +tree rotation matrices and corresponding three Euler angles are only one of the possible solutions. + +The function is based on RQDecomp3x3 . + */ +CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix, + OutputArray rotMatrix, OutputArray transVect, + OutputArray rotMatrixX = noArray(), + OutputArray rotMatrixY = noArray(), + OutputArray rotMatrixZ = noArray(), + OutputArray eulerAngles =noArray() ); + +/** @brief Computes partial derivatives of the matrix product for each multiplied matrix. + +@param A First multiplied matrix. +@param B Second multiplied matrix. +@param dABdA First output derivative matrix d(A\*B)/dA of size +\f$\texttt{A.rows*B.cols} \times {A.rows*A.cols}\f$ . +@param dABdB Second output derivative matrix d(A\*B)/dB of size +\f$\texttt{A.rows*B.cols} \times {B.rows*B.cols}\f$ . + +The function computes partial derivatives of the elements of the matrix product \f$A*B\f$ with regard to +the elements of each of the two input matrices. The function is used to compute the Jacobian +matrices in stereoCalibrate but can also be used in any other similar optimization function. + */ +CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB ); + +/** @brief Combines two rotation-and-shift transformations. + +@param rvec1 First rotation vector. +@param tvec1 First translation vector. +@param rvec2 Second rotation vector. +@param tvec2 Second translation vector. +@param rvec3 Output rotation vector of the superposition. +@param tvec3 Output translation vector of the superposition. +@param dr3dr1 +@param dr3dt1 +@param dr3dr2 +@param dr3dt2 +@param dt3dr1 +@param dt3dt1 +@param dt3dr2 +@param dt3dt2 Optional output derivatives of rvec3 or tvec3 with regard to rvec1, rvec2, tvec1 and +tvec2, respectively. + +The functions compute: + +\f[\begin{array}{l} \texttt{rvec3} = \mathrm{rodrigues} ^{-1} \left ( \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \mathrm{rodrigues} ( \texttt{rvec1} ) \right ) \\ \texttt{tvec3} = \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \texttt{tvec1} + \texttt{tvec2} \end{array} ,\f] + +where \f$\mathrm{rodrigues}\f$ denotes a rotation vector to a rotation matrix transformation, and +\f$\mathrm{rodrigues}^{-1}\f$ denotes the inverse transformation. See Rodrigues for details. + +Also, the functions can compute the derivatives of the output vectors with regards to the input +vectors (see matMulDeriv ). The functions are used inside stereoCalibrate but can also be used in +your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a +function that contains a matrix multiplication. + */ +CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1, + InputArray rvec2, InputArray tvec2, + OutputArray rvec3, OutputArray tvec3, + OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(), + OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(), + OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(), + OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() ); + +/** @brief Projects 3D points to an image plane. + +@param objectPoints Array of object points, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or +vector\<Point3f\> ), where N is the number of points in the view. +@param rvec Rotation vector. See Rodrigues for details. +@param tvec Translation vector. +@param cameraMatrix Camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is empty, the zero distortion coefficients are assumed. +@param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or +vector\<Point2f\> . +@param jacobian Optional output 2Nx(10+\<numDistCoeffs\>) jacobian matrix of derivatives of image +points with respect to components of the rotation vector, translation vector, focal lengths, +coordinates of the principal point and the distortion coefficients. In the old interface different +components of the jacobian are returned via different output parameters. +@param aspectRatio Optional "fixed aspect ratio" parameter. If the parameter is not 0, the +function assumes that the aspect ratio (*fx/fy*) is fixed and correspondingly adjusts the jacobian +matrix. + +The function computes projections of 3D points to the image plane given intrinsic and extrinsic +camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of +image points coordinates (as functions of all the input parameters) with respect to the particular +parameters, intrinsic and/or extrinsic. The Jacobians are used during the global optimization in +calibrateCamera, solvePnP, and stereoCalibrate . The function itself can also be used to compute a +re-projection error given the current intrinsic and extrinsic parameters. + +@note By setting rvec=tvec=(0,0,0) or by setting cameraMatrix to a 3x3 identity matrix, or by +passing zero distortion coefficients, you can get various useful partial cases of the function. This +means that you can compute the distorted coordinates for a sparse set of points or apply a +perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup. + */ +CV_EXPORTS_W void projectPoints( InputArray objectPoints, + InputArray rvec, InputArray tvec, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray imagePoints, + OutputArray jacobian = noArray(), + double aspectRatio = 0 ); + +/** @example samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp +An example program about homography from the camera displacement + +Check @ref tutorial_homography "the corresponding tutorial" for more details +*/ + +/** @brief Finds an object pose from 3D-2D point correspondences. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or +1xN/Nx1 3-channel, where N is the number of points. vector\<Point3f\> can be also passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\<Point2f\> can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvec Output rotation vector (see @ref Rodrigues ) that, together with tvec , brings points from +the model coordinate system to the camera coordinate system. +@param tvec Output translation vector. +@param useExtrinsicGuess Parameter used for #SOLVEPNP_ITERATIVE. If true (1), the function uses +the provided rvec and tvec values as initial approximations of the rotation and translation +vectors, respectively, and further optimizes them. +@param flags Method for solving a PnP problem: +- **SOLVEPNP_ITERATIVE** Iterative method is based on Levenberg-Marquardt optimization. In +this case the function finds such a pose that minimizes reprojection error, that is the sum +of squared distances between the observed projections imagePoints and the projected (using +projectPoints ) objectPoints . +- **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_AP3P** Method is based on the paper of T. Ke, S. Roumeliotis +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the +paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" (@cite lepetit2009epnp). +- **SOLVEPNP_DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis. +"A Direct Least-Squares (DLS) Method for PnP" (@cite hesch2011direct). +- **SOLVEPNP_UPNP** Method is based on the paper of A.Penate-Sanchez, J.Andrade-Cetto, +F.Moreno-Noguer. "Exhaustive Linearization for Robust Camera Pose and Focal Length +Estimation" (@cite penate2013exhaustive). In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$ +assuming that both have the same value. Then the cameraMatrix is updated with the estimated +focal length. +- **SOLVEPNP_AP3P** Method is based on the paper of Tong Ke and Stergios I. Roumeliotis. +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). In this case the +function requires exactly four object and image points. + +The function estimates the object pose given a set of object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients, see the figure below +(more precisely, the X-axis of the camera frame is pointing to the right, the Y-axis downward +and the Z-axis forward). + +![](pnp.jpg) + +Points expressed in the world frame \f$ \bf{X}_w \f$ are projected into the image plane \f$ \left[ u, v \right] \f$ +using the perspective projection model \f$ \Pi \f$ and the camera intrinsic parameters matrix \f$ \bf{A} \f$: + +\f[ + \begin{align*} + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \bf{A} \hspace{0.1em} \Pi \hspace{0.2em} ^{c}\bf{M}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + f_x & 0 & c_x \\ + 0 & f_y & c_y \\ + 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + 0 & 0 & 1 & 0 + \end{bmatrix} + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +The estimated pose is thus the rotation (`rvec`) and the translation (`tvec`) vectors that allow to transform +a 3D point expressed in the world frame into the camera frame: + +\f[ + \begin{align*} + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \hspace{0.2em} ^{c}\bf{M}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +@note + - An example of how to use solvePnP for planar augmented reality can be found at + opencv_source_code/samples/python/plane_ar.py + - If you are using Python: + - Numpy array slices won't work as input because solvePnP requires contiguous + arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of + modules/calib3d/src/solvepnp.cpp version 2.4.9) + - The P3P algorithm requires image points to be in an array of shape (N,1,2) due + to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) + which requires 2-channel information. + - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of + it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = + np.ascontiguousarray(D[:,:2]).reshape((N,1,2)) + - The methods **SOLVEPNP_DLS** and **SOLVEPNP_UPNP** cannot be used as the current implementations are + unstable and sometimes give completely wrong results. If you pass one of these two + flags, **SOLVEPNP_EPNP** method will be used instead. + - The minimum number of points is 4 in the general case. In the case of **SOLVEPNP_P3P** and **SOLVEPNP_AP3P** + methods, it is required to use exactly 4 points (the first 3 points are used to estimate all the solutions + of the P3P problem, the last one is used to retain the best solution that minimizes the reprojection error). + - With **SOLVEPNP_ITERATIVE** method and `useExtrinsicGuess=true`, the minimum number of points is 3 (3 points + are sufficient to compute a pose but there are up to 4 solutions). The initial solution should be close to the + global solution to converge. + */ +CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, + bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE ); + +/** @brief Finds an object pose from 3D-2D point correspondences using the RANSAC scheme. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or +1xN/Nx1 3-channel, where N is the number of points. vector\<Point3f\> can be also passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\<Point2f\> can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvec Output rotation vector (see Rodrigues ) that, together with tvec , brings points from +the model coordinate system to the camera coordinate system. +@param tvec Output translation vector. +@param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses +the provided rvec and tvec values as initial approximations of the rotation and translation +vectors, respectively, and further optimizes them. +@param iterationsCount Number of iterations. +@param reprojectionError Inlier threshold value used by the RANSAC procedure. The parameter value +is the maximum allowed distance between the observed and computed point projections to consider it +an inlier. +@param confidence The probability that the algorithm produces a useful result. +@param inliers Output vector that contains indices of inliers in objectPoints and imagePoints . +@param flags Method for solving a PnP problem (see solvePnP ). + +The function estimates an object pose given a set of object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients. This function finds such +a pose that minimizes reprojection error, that is, the sum of squared distances between the observed +projections imagePoints and the projected (using projectPoints ) objectPoints. The use of RANSAC +makes the function resistant to outliers. + +@note + - An example of how to use solvePNPRansac for object detection can be found at + opencv_source_code/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/ + - The default method used to estimate the camera pose for the Minimal Sample Sets step + is #SOLVEPNP_EPNP. Exceptions are: + - if you choose #SOLVEPNP_P3P or #SOLVEPNP_AP3P, these methods will be used. + - if the number of input points is equal to 4, #SOLVEPNP_P3P is used. + - The method used to estimate the camera pose using all the inliers is defined by the + flags parameters unless it is equal to #SOLVEPNP_P3P or #SOLVEPNP_AP3P. In this case, + the method #SOLVEPNP_EPNP will be used instead. + */ +CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, + bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, double confidence = 0.99, + OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE ); +/** @brief Finds an object pose from 3 3D-2D point correspondences. + +@param objectPoints Array of object points in the object coordinate space, 3x3 1-channel or +1x3/3x1 3-channel. vector\<Point3f\> can be also passed here. +@param imagePoints Array of corresponding image points, 3x2 1-channel or 1x3/3x1 2-channel. + vector\<Point2f\> can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvecs Output rotation vectors (see Rodrigues ) that, together with tvecs , brings points from +the model coordinate system to the camera coordinate system. A P3P problem has up to 4 solutions. +@param tvecs Output translation vectors. +@param flags Method for solving a P3P problem: +- **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +- **SOLVEPNP_AP3P** Method is based on the paper of Tong Ke and Stergios I. Roumeliotis. +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). + +The function estimates the object pose given 3 object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients. + */ +CV_EXPORTS_W int solveP3P( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags ); + +/** @brief Finds an initial camera matrix from 3D-2D point correspondences. + +@param objectPoints Vector of vectors of the calibration pattern points in the calibration pattern +coordinate space. In the old interface all the per-view vectors are concatenated. See +calibrateCamera for details. +@param imagePoints Vector of vectors of the projections of the calibration pattern points. In the +old interface all the per-view vectors are concatenated. +@param imageSize Image size in pixels used to initialize the principal point. +@param aspectRatio If it is zero or negative, both \f$f_x\f$ and \f$f_y\f$ are estimated independently. +Otherwise, \f$f_x = f_y * \texttt{aspectRatio}\f$ . + +The function estimates and returns an initial camera matrix for the camera calibration process. +Currently, the function only supports planar calibration patterns, which are patterns where each +object point has z-coordinate =0. + */ +CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, + Size imageSize, double aspectRatio = 1.0 ); + +/** @brief Finds the positions of internal corners of the chessboard. + +@param image Source chessboard view. It must be an 8-bit grayscale or color image. +@param patternSize Number of inner corners per a chessboard row and column +( patternSize = cvSize(points_per_row,points_per_colum) = cvSize(columns,rows) ). +@param corners Output array of detected corners. +@param flags Various operation flags that can be zero or a combination of the following values: +- **CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black +and white, rather than a fixed threshold level (computed from the average image brightness). +- **CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before +applying fixed or adaptive thresholding. +- **CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, +square-like shape) to filter out false quads extracted at the contour retrieval stage. +- **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners, +and shortcut the call if none is found. This can drastically speed up the call in the +degenerate condition when no chessboard is observed. + +The function attempts to determine whether the input image is a view of the chessboard pattern and +locate the internal chessboard corners. The function returns a non-zero value if all of the corners +are found and they are placed in a certain order (row by row, left to right in every row). +Otherwise, if the function fails to find all the corners or reorder them, it returns 0. For example, +a regular chessboard has 8 x 8 squares and 7 x 7 internal corners, that is, points where the black +squares touch each other. The detected coordinates are approximate, and to determine their positions +more accurately, the function calls cornerSubPix. You also may use the function cornerSubPix with +different parameters if returned coordinates are not accurate enough. + +Sample usage of detecting and drawing chessboard corners: : +@code + Size patternsize(8,6); //interior number of corners + Mat gray = ....; //source image + vector<Point2f> corners; //this will be filled by the detected corners + + //CALIB_CB_FAST_CHECK saves a lot of time on images + //that do not contain any chessboard corners + bool patternfound = findChessboardCorners(gray, patternsize, corners, + CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + + CALIB_CB_FAST_CHECK); + + if(patternfound) + cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), + TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1)); + + drawChessboardCorners(img, patternsize, Mat(corners), patternfound); +@endcode +@note The function requires white space (like a square-thick border, the wider the better) around +the board to make the detection more robust in various environments. Otherwise, if there is no +border and the background is dark, the outer black squares cannot be segmented properly and so the +square grouping and ordering algorithm fails. + */ +CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, + int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE ); + +//! finds subpixel-accurate positions of the chessboard corners +CV_EXPORTS bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size ); + +/** @brief Renders the detected chessboard corners. + +@param image Destination image. It must be an 8-bit color image. +@param patternSize Number of inner corners per a chessboard row and column +(patternSize = cv::Size(points_per_row,points_per_column)). +@param corners Array of detected corners, the output of findChessboardCorners. +@param patternWasFound Parameter indicating whether the complete board was found or not. The +return value of findChessboardCorners should be passed here. + +The function draws individual chessboard corners detected either as red circles if the board was not +found, or as colored corners connected with lines if the board was found. + */ +CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize, + InputArray corners, bool patternWasFound ); + +/** @brief Draw axes of the world/object coordinate system from pose estimation. @sa solvePnP + +@param image Input/output image. It must have 1 or 3 channels. The number of channels is not altered. +@param cameraMatrix Input 3x3 floating-point matrix of camera intrinsic parameters. +\f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is empty, the zero distortion coefficients are assumed. +@param rvec Rotation vector (see @ref Rodrigues ) that, together with tvec , brings points from +the model coordinate system to the camera coordinate system. +@param tvec Translation vector. +@param length Length of the painted axes in the same unit than tvec (usually in meters). +@param thickness Line thickness of the painted axes. + +This function draws the axes of the world/object coordinate system w.r.t. to the camera frame. +OX is drawn in red, OY in green and OZ in blue. + */ +CV_EXPORTS_W void drawFrameAxes(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs, + InputArray rvec, InputArray tvec, float length, int thickness=3); + +struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters +{ + CV_WRAP CirclesGridFinderParameters(); + CV_PROP_RW cv::Size2f densityNeighborhoodSize; + CV_PROP_RW float minDensity; + CV_PROP_RW int kmeansAttempts; + CV_PROP_RW int minDistanceToAddKeypoint; + CV_PROP_RW int keypointScale; + CV_PROP_RW float minGraphConfidence; + CV_PROP_RW float vertexGain; + CV_PROP_RW float vertexPenalty; + CV_PROP_RW float existingVertexGain; + CV_PROP_RW float edgeGain; + CV_PROP_RW float edgePenalty; + CV_PROP_RW float convexHullFactor; + CV_PROP_RW float minRNGEdgeSwitchDist; + + enum GridType + { + SYMMETRIC_GRID, ASYMMETRIC_GRID + }; + GridType gridType; +}; + +struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters2 : public CirclesGridFinderParameters +{ + CV_WRAP CirclesGridFinderParameters2(); + + CV_PROP_RW float squareSize; //!< Distance between two adjacent points. Used by CALIB_CB_CLUSTERING. + CV_PROP_RW float maxRectifiedDistance; //!< Max deviation from predicion. Used by CALIB_CB_CLUSTERING. +}; + +/** @brief Finds centers in the grid of circles. + +@param image grid view of input circles; it must be an 8-bit grayscale or color image. +@param patternSize number of circles per row and column +( patternSize = Size(points_per_row, points_per_colum) ). +@param centers output array of detected centers. +@param flags various operation flags that can be one of the following values: +- **CALIB_CB_SYMMETRIC_GRID** uses symmetric pattern of circles. +- **CALIB_CB_ASYMMETRIC_GRID** uses asymmetric pattern of circles. +- **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to +perspective distortions but much more sensitive to background clutter. +@param blobDetector feature detector that finds blobs like dark circles on light background. +@param parameters struct for finding circles in a grid pattern. + +The function attempts to determine whether the input image contains a grid of circles. If it is, the +function locates centers of the circles. The function returns a non-zero value if all of the centers +have been found and they have been placed in a certain order (row by row, left to right in every +row). Otherwise, if the function fails to find all the corners or reorder them, it returns 0. + +Sample usage of detecting and drawing the centers of circles: : +@code + Size patternsize(7,7); //number of centers + Mat gray = ....; //source image + vector<Point2f> centers; //this will be filled by the detected centers + + bool patternfound = findCirclesGrid(gray, patternsize, centers); + + drawChessboardCorners(img, patternsize, Mat(centers), patternfound); +@endcode +@note The function requires white space (like a square-thick border, the wider the better) around +the board to make the detection more robust in various environments. + */ +CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr<FeatureDetector> &blobDetector, + CirclesGridFinderParameters parameters); + +/** @overload */ +CV_EXPORTS_W bool findCirclesGrid2( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr<FeatureDetector> &blobDetector, + CirclesGridFinderParameters2 parameters); + +/** @overload */ +CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, + OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID, + const Ptr<FeatureDetector> &blobDetector = SimpleBlobDetector::create()); + +/** @brief Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. + +@param objectPoints In the new interface it is a vector of vectors of calibration pattern points in +the calibration pattern coordinate space (e.g. std::vector<std::vector<cv::Vec3f>>). The outer +vector contains as many elements as the number of the pattern views. If the same calibration pattern +is shown in each view and it is fully visible, all the vectors will be the same. Although, it is +possible to use partially occluded patterns, or even different patterns in different views. Then, +the vectors will be different. The points are 3D, but since they are in a pattern coordinate system, +then, if the rig is planar, it may make sense to put the model to a XY coordinate plane so that +Z-coordinate of each input object point is 0. +In the old interface all the vectors of object points from different views are concatenated +together. +@param imagePoints In the new interface it is a vector of vectors of the projections of calibration +pattern points (e.g. std::vector<std::vector<cv::Vec2f>>). imagePoints.size() and +objectPoints.size() and imagePoints[i].size() must be equal to objectPoints[i].size() for each i. +In the old interface all the vectors of object points from different views are concatenated +together. +@param imageSize Size of the image used only to initialize the intrinsic camera matrix. +@param cameraMatrix Output 3x3 floating-point camera matrix +\f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS +and/or CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be +initialized before calling the function. +@param distCoeffs Output vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. +@param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view +(e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding +k-th translation vector (see the next output parameter description) brings the calibration pattern +from the model coordinate space (in which object points are specified) to the world coordinate +space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). +@param tvecs Output vector of translation vectors estimated for each pattern view. +@param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + Order of deviations values: +\f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. +@param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + \f$R_i, T_i\f$ are concatenated 1x3 vectors. + @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. +@param flags Different flags that may be zero or a combination of the following values: +- **CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of +fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image +center ( imageSize is used), and focal distances are computed in a least-squares fashion. +Note, that if intrinsic parameters are known, there is no need to use this function just to +estimate extrinsic parameters. Use solvePnP instead. +- **CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global +optimization. It stays at the center or at a different location specified when +CALIB_USE_INTRINSIC_GUESS is set too. +- **CALIB_FIX_ASPECT_RATIO** The functions considers only fy as a free parameter. The +ratio fx/fy stays the same as in the input cameraMatrix . When +CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are +ignored, only their ratio is computed and used further. +- **CALIB_ZERO_TANGENT_DIST** Tangential distortion coefficients \f$(p_1, p_2)\f$ are set +to zeros and stay zero. +- **CALIB_FIX_K1,...,CALIB_FIX_K6** The corresponding radial distortion +coefficient is not changed during the optimization. If CALIB_USE_INTRINSIC_GUESS is +set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the rational model and return 8 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the thin prism model and return 12 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the tilted sensor model and return 14 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +@param criteria Termination criteria for the iterative optimization algorithm. + +@return the overall RMS re-projection error. + +The function estimates the intrinsic camera parameters and extrinsic parameters for each of the +views. The algorithm is based on @cite Zhang2000 and @cite BouguetMCT . The coordinates of 3D object +points and their corresponding 2D projections in each view must be specified. That may be achieved +by using an object with a known geometry and easily detectable feature points. Such an object is +called a calibration rig or calibration pattern, and OpenCV has built-in support for a chessboard as +a calibration rig (see findChessboardCorners ). Currently, initialization of intrinsic parameters +(when CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration +patterns (where Z-coordinates of the object points must be all zeros). 3D calibration rigs can also +be used as long as initial cameraMatrix is provided. + +The algorithm performs the following steps: + +- Compute the initial intrinsic parameters (the option only available for planar calibration + patterns) or read them from the input parameters. The distortion coefficients are all set to + zeros initially unless some of CALIB_FIX_K? are specified. + +- Estimate the initial camera pose as if the intrinsic parameters have been already known. This is + done using solvePnP . + +- Run the global Levenberg-Marquardt optimization algorithm to minimize the reprojection error, + that is, the total sum of squared distances between the observed feature points imagePoints and + the projected (using the current estimates for camera parameters and the poses) object points + objectPoints. See projectPoints for details. + +@note + If you use a non-square (=non-NxN) grid and findChessboardCorners for calibration, and + calibrateCamera returns bad values (zero distortion coefficients, an image center very far from + (w/2-0.5,h/2-0.5), and/or large differences between \f$f_x\f$ and \f$f_y\f$ (ratios of 10:1 or more)), + then you have probably used patternSize=cvSize(rows,cols) instead of using + patternSize=cvSize(cols,rows) in findChessboardCorners . + +@sa + findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort + */ +CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, + OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @overload double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviations, OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ) + */ +CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @brief Computes useful camera characteristics from the camera matrix. + +@param cameraMatrix Input camera matrix that can be estimated by calibrateCamera or +stereoCalibrate . +@param imageSize Input image size in pixels. +@param apertureWidth Physical width in mm of the sensor. +@param apertureHeight Physical height in mm of the sensor. +@param fovx Output field of view in degrees along the horizontal sensor axis. +@param fovy Output field of view in degrees along the vertical sensor axis. +@param focalLength Focal length of the lens in mm. +@param principalPoint Principal point in mm. +@param aspectRatio \f$f_y/f_x\f$ + +The function computes various useful camera characteristics from the previously estimated camera +matrix. + +@note + Do keep in mind that the unity measure 'mm' stands for whatever unit of measure one chooses for + the chessboard pitch (it can thus be any value). + */ +CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize, + double apertureWidth, double apertureHeight, + CV_OUT double& fovx, CV_OUT double& fovy, + CV_OUT double& focalLength, CV_OUT Point2d& principalPoint, + CV_OUT double& aspectRatio ); + +/** @brief Calibrates the stereo camera. + +@param objectPoints Vector of vectors of the calibration pattern points. +@param imagePoints1 Vector of vectors of the projections of the calibration pattern points, +observed by the first camera. +@param imagePoints2 Vector of vectors of the projections of the calibration pattern points, +observed by the second camera. +@param cameraMatrix1 Input/output first camera matrix: +\f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If +any of CALIB_USE_INTRINSIC_GUESS , CALIB_FIX_ASPECT_RATIO , +CALIB_FIX_INTRINSIC , or CALIB_FIX_FOCAL_LENGTH are specified, some or all of the +matrix components must be initialized. See the flags description for details. +@param distCoeffs1 Input/output vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. The output vector length depends on the flags. +@param cameraMatrix2 Input/output second camera matrix. The parameter is similar to cameraMatrix1 +@param distCoeffs2 Input/output lens distortion coefficients for the second camera. The parameter +is similar to distCoeffs1 . +@param imageSize Size of the image used only to initialize intrinsic camera matrix. +@param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. +@param T Output translation vector between the coordinate systems of the cameras. +@param E Output essential matrix. +@param F Output fundamental matrix. +@param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. +@param flags Different flags that may be zero or a combination of the following values: +- **CALIB_FIX_INTRINSIC** Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F +matrices are estimated. +- **CALIB_USE_INTRINSIC_GUESS** Optimize some or all of the intrinsic parameters +according to the specified flags. Initial values are provided by the user. +- **CALIB_USE_EXTRINSIC_GUESS** R, T contain valid initial values that are optimized further. +Otherwise R, T are initialized to the median value of the pattern views (each dimension separately). +- **CALIB_FIX_PRINCIPAL_POINT** Fix the principal points during the optimization. +- **CALIB_FIX_FOCAL_LENGTH** Fix \f$f^{(j)}_x\f$ and \f$f^{(j)}_y\f$ . +- **CALIB_FIX_ASPECT_RATIO** Optimize \f$f^{(j)}_y\f$ . Fix the ratio \f$f^{(j)}_x/f^{(j)}_y\f$ +. +- **CALIB_SAME_FOCAL_LENGTH** Enforce \f$f^{(0)}_x=f^{(1)}_x\f$ and \f$f^{(0)}_y=f^{(1)}_y\f$ . +- **CALIB_ZERO_TANGENT_DIST** Set tangential distortion coefficients for each camera to +zeros and fix there. +- **CALIB_FIX_K1,...,CALIB_FIX_K6** Do not change the corresponding radial +distortion coefficient during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, +the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward +compatibility, this extra flag should be explicitly specified to make the calibration +function use the rational model and return 8 coefficients. If the flag is not set, the +function computes and returns only 5 distortion coefficients. +- **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the thin prism model and return 12 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the tilted sensor model and return 14 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +@param criteria Termination criteria for the iterative optimization algorithm. + +The function estimates transformation between two cameras making a stereo pair. If you have a stereo +camera where the relative position and orientation of two cameras is fixed, and if you computed +poses of an object relative to the first camera and to the second camera, (R1, T1) and (R2, T2), +respectively (this can be done with solvePnP ), then those poses definitely relate to each other. +This means that, given ( \f$R_1\f$,\f$T_1\f$ ), it should be possible to compute ( \f$R_2\f$,\f$T_2\f$ ). You only +need to know the position and orientation of the second camera relative to the first camera. This is +what the described function does. It computes ( \f$R\f$,\f$T\f$ ) so that: + +\f[R_2=R*R_1\f] +\f[T_2=R*T_1 + T,\f] + +Optionally, it computes the essential matrix E: + +\f[E= \vecthreethree{0}{-T_2}{T_1}{T_2}{0}{-T_0}{-T_1}{T_0}{0} *R\f] + +where \f$T_i\f$ are components of the translation vector \f$T\f$ : \f$T=[T_0, T_1, T_2]^T\f$ . And the function +can also compute the fundamental matrix F: + +\f[F = cameraMatrix2^{-T} E cameraMatrix1^{-1}\f] + +Besides the stereo-related information, the function can also perform a full calibration of each of +two cameras. However, due to the high dimensionality of the parameter space and noise in the input +data, the function can diverge from the correct solution. If the intrinsic parameters can be +estimated with high accuracy for each of the cameras individually (for example, using +calibrateCamera ), you are recommended to do so and then pass CALIB_FIX_INTRINSIC flag to the +function along with the computed intrinsic parameters. Otherwise, if all the parameters are +estimated at once, it makes sense to restrict some parameters, for example, pass +CALIB_SAME_FOCAL_LENGTH and CALIB_ZERO_TANGENT_DIST flags, which is usually a +reasonable assumption. + +Similarly to calibrateCamera , the function minimizes the total re-projection error for all the +points in all the available views from both cameras. The function returns the final value of the +re-projection error. + */ +CV_EXPORTS_AS(stereoCalibrateExtended) double stereoCalibrate( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, + InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, + Size imageSize, InputOutputArray R,InputOutputArray T, OutputArray E, OutputArray F, + OutputArray perViewErrors, int flags = CALIB_FIX_INTRINSIC, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) ); + +/// @overload +CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, + InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, + Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F, + int flags = CALIB_FIX_INTRINSIC, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) ); + +/** @brief Computes rectification transforms for each head of a calibrated stereo camera. + +@param cameraMatrix1 First camera matrix. +@param distCoeffs1 First camera distortion parameters. +@param cameraMatrix2 Second camera matrix. +@param distCoeffs2 Second camera distortion parameters. +@param imageSize Size of the image used for stereo calibration. +@param R Rotation matrix between the coordinate systems of the first and the second cameras. +@param T Translation vector between coordinate systems of the cameras. +@param R1 Output 3x3 rectification transform (rotation matrix) for the first camera. +@param R2 Output 3x3 rectification transform (rotation matrix) for the second camera. +@param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first +camera. +@param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second +camera. +@param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). +@param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set, +the function makes the principal points of each camera have the same pixel coordinates in the +rectified views. And if the flag is not set, the function may still shift the images in the +horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the +useful image area. +@param alpha Free scaling parameter. If it is -1 or absent, the function performs the default +scaling. Otherwise, the parameter should be between 0 and 1. alpha=0 means that the rectified +images are zoomed and shifted so that only valid pixels are visible (no black areas after +rectification). alpha=1 means that the rectified image is decimated and shifted so that all the +pixels from the original images from the cameras are retained in the rectified images (no source +image pixels are lost). Obviously, any intermediate value yields an intermediate result between +those two extreme cases. +@param newImageSize New image resolution after rectification. The same size should be passed to +initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) +is passed (default), it is set to the original imageSize . Setting it to larger value can help you +preserve details in the original image, especially when there is a big radial distortion. +@param validPixROI1 Optional output rectangles inside the rectified images where all the pixels +are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller +(see the picture below). +@param validPixROI2 Optional output rectangles inside the rectified images where all the pixels +are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller +(see the picture below). + +The function computes the rotation matrices for each camera that (virtually) make both camera image +planes the same plane. Consequently, this makes all the epipolar lines parallel and thus simplifies +the dense stereo correspondence problem. The function takes the matrices computed by stereoCalibrate +as input. As output, it provides two rotation matrices and also two projection matrices in the new +coordinates. The function distinguishes the following two cases: + +- **Horizontal stereo**: the first and the second camera views are shifted relative to each other + mainly along the x axis (with possible small vertical shift). In the rectified images, the + corresponding epipolar lines in the left and right cameras are horizontal and have the same + y-coordinate. P1 and P2 look like: + + \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx_1 & 0 \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f] + + \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx_2 & T_x*f \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] + + where \f$T_x\f$ is a horizontal shift between the cameras and \f$cx_1=cx_2\f$ if + CALIB_ZERO_DISPARITY is set. + +- **Vertical stereo**: the first and the second camera views are shifted relative to each other + mainly in vertical direction (and probably a bit in the horizontal direction too). The epipolar + lines in the rectified images are vertical and have the same x-coordinate. P1 and P2 look like: + + \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_1 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f] + + \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_2 & T_y*f \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] + + where \f$T_y\f$ is a vertical shift between the cameras and \f$cy_1=cy_2\f$ if CALIB_ZERO_DISPARITY is + set. + +As you can see, the first three columns of P1 and P2 will effectively be the new "rectified" camera +matrices. The matrices, together with R1 and R2 , can then be passed to initUndistortRectifyMap to +initialize the rectification map for each camera. + +See below the screenshot from the stereo_calib.cpp sample. Some red horizontal lines pass through +the corresponding image regions. This means that the images are well rectified, which is what most +stereo correspondence algorithms rely on. The green rectangles are roi1 and roi2 . You see that +their interiors are all valid pixels. + +![image](pics/stereo_undistort.jpg) + */ +CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1, + InputArray cameraMatrix2, InputArray distCoeffs2, + Size imageSize, InputArray R, InputArray T, + OutputArray R1, OutputArray R2, + OutputArray P1, OutputArray P2, + OutputArray Q, int flags = CALIB_ZERO_DISPARITY, + double alpha = -1, Size newImageSize = Size(), + CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 ); + +/** @brief Computes a rectification transform for an uncalibrated stereo camera. + +@param points1 Array of feature points in the first image. +@param points2 The corresponding points in the second image. The same formats as in +findFundamentalMat are supported. +@param F Input fundamental matrix. It can be computed from the same set of point pairs using +findFundamentalMat . +@param imgSize Size of the image. +@param H1 Output rectification homography matrix for the first image. +@param H2 Output rectification homography matrix for the second image. +@param threshold Optional threshold used to filter out the outliers. If the parameter is greater +than zero, all the point pairs that do not comply with the epipolar geometry (that is, the points +for which \f$|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}\f$ ) are +rejected prior to computing the homographies. Otherwise, all the points are considered inliers. + +The function computes the rectification transformations without knowing intrinsic parameters of the +cameras and their relative position in the space, which explains the suffix "uncalibrated". Another +related difference from stereoRectify is that the function outputs not the rectification +transformations in the object (3D) space, but the planar perspective transformations encoded by the +homography matrices H1 and H2 . The function implements the algorithm @cite Hartley99 . + +@note + While the algorithm does not need to know the intrinsic parameters of the cameras, it heavily + depends on the epipolar geometry. Therefore, if the camera lenses have a significant distortion, + it would be better to correct it before computing the fundamental matrix and calling this + function. For example, distortion coefficients can be estimated for each head of stereo camera + separately by using calibrateCamera . Then, the images can be corrected using undistort , or + just the point coordinates can be corrected with undistortPoints . + */ +CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2, + InputArray F, Size imgSize, + OutputArray H1, OutputArray H2, + double threshold = 5 ); + +//! computes the rectification transformations for 3-head camera, where all the heads are on the same line. +CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1, + InputArray cameraMatrix2, InputArray distCoeffs2, + InputArray cameraMatrix3, InputArray distCoeffs3, + InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3, + Size imageSize, InputArray R12, InputArray T12, + InputArray R13, InputArray T13, + OutputArray R1, OutputArray R2, OutputArray R3, + OutputArray P1, OutputArray P2, OutputArray P3, + OutputArray Q, double alpha, Size newImgSize, + CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags ); + +/** @brief Returns the new camera matrix based on the free scaling parameter. + +@param cameraMatrix Input camera matrix. +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param imageSize Original image size. +@param alpha Free scaling parameter between 0 (when all the pixels in the undistorted image are +valid) and 1 (when all the source image pixels are retained in the undistorted image). See +stereoRectify for details. +@param newImgSize Image size after rectification. By default, it is set to imageSize . +@param validPixROI Optional output rectangle that outlines all-good-pixels region in the +undistorted image. See roi1, roi2 description in stereoRectify . +@param centerPrincipalPoint Optional flag that indicates whether in the new camera matrix the +principal point should be at the image center or not. By default, the principal point is chosen to +best fit a subset of the source image (determined by alpha) to the corrected image. +@return new_camera_matrix Output new camera matrix. + +The function computes and returns the optimal new camera matrix based on the free scaling parameter. +By varying this parameter, you may retrieve only sensible pixels alpha=0 , keep all the original +image pixels if there is valuable information in the corners alpha=1 , or get something in between. +When alpha\>0 , the undistorted result is likely to have some black pixels corresponding to +"virtual" pixels outside of the captured distorted image. The original camera matrix, distortion +coefficients, the computed new camera matrix, and newImageSize should be passed to +initUndistortRectifyMap to produce the maps for remap . + */ +CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, double alpha, Size newImgSize = Size(), + CV_OUT Rect* validPixROI = 0, + bool centerPrincipalPoint = false); + +/** @brief Computes Hand-Eye calibration: \f$_{}^{g}\textrm{T}_c\f$ + +@param[in] R_gripper2base Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the gripper frame to the robot base frame (\f$_{}^{b}\textrm{T}_g\f$). +This is a vector (`vector<Mat>`) that contains the rotation matrices for all the transformations +from gripper frame to robot base frame. +@param[in] t_gripper2base Translation part extracted from the homogeneous matrix that transforms a point +expressed in the gripper frame to the robot base frame (\f$_{}^{b}\textrm{T}_g\f$). +This is a vector (`vector<Mat>`) that contains the translation vectors for all the transformations +from gripper frame to robot base frame. +@param[in] R_target2cam Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the target frame to the camera frame (\f$_{}^{c}\textrm{T}_t\f$). +This is a vector (`vector<Mat>`) that contains the rotation matrices for all the transformations +from calibration target frame to camera frame. +@param[in] t_target2cam Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the target frame to the camera frame (\f$_{}^{c}\textrm{T}_t\f$). +This is a vector (`vector<Mat>`) that contains the translation vectors for all the transformations +from calibration target frame to camera frame. +@param[out] R_cam2gripper Estimated rotation part extracted from the homogeneous matrix that transforms a point +expressed in the camera frame to the gripper frame (\f$_{}^{g}\textrm{T}_c\f$). +@param[out] t_cam2gripper Estimated translation part extracted from the homogeneous matrix that transforms a point +expressed in the camera frame to the gripper frame (\f$_{}^{g}\textrm{T}_c\f$). +@param[in] method One of the implemented Hand-Eye calibration method, see cv::HandEyeCalibrationMethod + +The function performs the Hand-Eye calibration using various methods. One approach consists in estimating the +rotation then the translation (separable solutions) and the following methods are implemented: + - R. Tsai, R. Lenz A New Technique for Fully Autonomous and Efficient 3D Robotics Hand/EyeCalibration \cite Tsai89 + - F. Park, B. Martin Robot Sensor Calibration: Solving AX = XB on the Euclidean Group \cite Park94 + - R. Horaud, F. Dornaika Hand-Eye Calibration \cite Horaud95 + +Another approach consists in estimating simultaneously the rotation and the translation (simultaneous solutions), +with the following implemented method: + - N. Andreff, R. Horaud, B. Espiau On-line Hand-Eye Calibration \cite Andreff99 + - K. Daniilidis Hand-Eye Calibration Using Dual Quaternions \cite Daniilidis98 + +The following picture describes the Hand-Eye calibration problem where the transformation between a camera ("eye") +mounted on a robot gripper ("hand") has to be estimated. + +![](pics/hand-eye_figure.png) + +The calibration procedure is the following: + - a static calibration pattern is used to estimate the transformation between the target frame + and the camera frame + - the robot gripper is moved in order to acquire several poses + - for each pose, the homogeneous transformation between the gripper frame and the robot base frame is recorded using for + instance the robot kinematics +\f[ + \begin{bmatrix} + X_b\\ + Y_b\\ + Z_b\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{b}\textrm{R}_g & _{}^{b}\textrm{t}_g \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_g\\ + Y_g\\ + Z_g\\ + 1 + \end{bmatrix} +\f] + - for each pose, the homogeneous transformation between the calibration target frame and the camera frame is recorded using + for instance a pose estimation method (PnP) from 2D-3D point correspondences +\f[ + \begin{bmatrix} + X_c\\ + Y_c\\ + Z_c\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{c}\textrm{R}_t & _{}^{c}\textrm{t}_t \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_t\\ + Y_t\\ + Z_t\\ + 1 + \end{bmatrix} +\f] + +The Hand-Eye calibration procedure returns the following homogeneous transformation +\f[ + \begin{bmatrix} + X_g\\ + Y_g\\ + Z_g\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{g}\textrm{R}_c & _{}^{g}\textrm{t}_c \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_c\\ + Y_c\\ + Z_c\\ + 1 + \end{bmatrix} +\f] + +This problem is also known as solving the \f$\mathbf{A}\mathbf{X}=\mathbf{X}\mathbf{B}\f$ equation: +\f[ + \begin{align*} + ^{b}{\textrm{T}_g}^{(1)} \hspace{0.2em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(1)} &= + \hspace{0.1em} ^{b}{\textrm{T}_g}^{(2)} \hspace{0.2em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(2)} \\ + + (^{b}{\textrm{T}_g}^{(2)})^{-1} \hspace{0.2em} ^{b}{\textrm{T}_g}^{(1)} \hspace{0.2em} ^{g}\textrm{T}_c &= + \hspace{0.1em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(2)} (^{c}{\textrm{T}_t}^{(1)})^{-1} \\ + + \textrm{A}_i \textrm{X} &= \textrm{X} \textrm{B}_i \\ + \end{align*} +\f] + +\note +Additional information can be found on this [website](http://campar.in.tum.de/Chair/HandEyeCalibration). +\note +A minimum of 2 motions with non parallel rotation axes are necessary to determine the hand-eye transformation. +So at least 3 different poses are required, but it is strongly recommended to use many more poses. + + */ +CV_EXPORTS_W void calibrateHandEye( InputArrayOfArrays R_gripper2base, InputArrayOfArrays t_gripper2base, + InputArrayOfArrays R_target2cam, InputArrayOfArrays t_target2cam, + OutputArray R_cam2gripper, OutputArray t_cam2gripper, + HandEyeCalibrationMethod method=CALIB_HAND_EYE_TSAI ); + +/** @brief Converts points from Euclidean to homogeneous space. + +@param src Input vector of N-dimensional points. +@param dst Output vector of N+1-dimensional points. + +The function converts points from Euclidean to homogeneous space by appending 1's to the tuple of +point coordinates. That is, each point (x1, x2, ..., xn) is converted to (x1, x2, ..., xn, 1). + */ +CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst ); + +/** @brief Converts points from homogeneous to Euclidean space. + +@param src Input vector of N-dimensional points. +@param dst Output vector of N-1-dimensional points. + +The function converts points homogeneous to Euclidean space using perspective projection. That is, +each point (x1, x2, ... x(n-1), xn) is converted to (x1/xn, x2/xn, ..., x(n-1)/xn). When xn=0, the +output point coordinates will be (0,0,0,...). + */ +CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst ); + +/** @brief Converts points to/from homogeneous coordinates. + +@param src Input array or vector of 2D, 3D, or 4D points. +@param dst Output vector of 2D, 3D, or 4D points. + +The function converts 2D or 3D points from/to homogeneous coordinates by calling either +convertPointsToHomogeneous or convertPointsFromHomogeneous. + +@note The function is obsolete. Use one of the previous two functions instead. + */ +CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst ); + +/** @brief Calculates a fundamental matrix from the corresponding points in two images. + +@param points1 Array of N points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param method Method for computing a fundamental matrix. +- **CV_FM_7POINT** for a 7-point algorithm. \f$N = 7\f$ +- **CV_FM_8POINT** for an 8-point algorithm. \f$N \ge 8\f$ +- **CV_FM_RANSAC** for the RANSAC algorithm. \f$N \ge 8\f$ +- **CV_FM_LMEDS** for the LMedS algorithm. \f$N \ge 8\f$ +@param ransacReprojThreshold Parameter used only for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param confidence Parameter used for the RANSAC and LMedS methods only. It specifies a desirable level +of confidence (probability) that the estimated matrix is correct. +@param mask + +The epipolar geometry is described by the following equation: + +\f[[p_2; 1]^T F [p_1; 1] = 0\f] + +where \f$F\f$ is a fundamental matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the +second images, respectively. + +The function calculates the fundamental matrix using one of four methods listed above and returns +the found fundamental matrix. Normally just one matrix is found. But in case of the 7-point +algorithm, the function may return up to 3 solutions ( \f$9 \times 3\f$ matrix that stores all 3 +matrices sequentially). + +The calculated fundamental matrix may be passed further to computeCorrespondEpilines that finds the +epipolar lines corresponding to the specified points. It can also be passed to +stereoRectifyUncalibrated to compute the rectification transformation. : +@code + // Example. Estimation of fundamental matrix using the RANSAC algorithm + int point_count = 100; + vector<Point2f> points1(point_count); + vector<Point2f> points2(point_count); + + // initialize the points here ... + for( int i = 0; i < point_count; i++ ) + { + points1[i] = ...; + points2[i] = ...; + } + + Mat fundamental_matrix = + findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99); +@endcode + */ +CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2, + int method = FM_RANSAC, + double ransacReprojThreshold = 3., double confidence = 0.99, + OutputArray mask = noArray() ); + +/** @overload */ +CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2, + OutputArray mask, int method = FM_RANSAC, + double ransacReprojThreshold = 3., double confidence = 0.99 ); + +/** @brief Calculates an essential matrix from the corresponding points in two images. + +@param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should +be floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param method Method for computing an essential matrix. +- **RANSAC** for the RANSAC algorithm. +- **LMEDS** for the LMedS algorithm. +@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of +confidence (probability) that the estimated matrix is correct. +@param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 +for the other points. The array is computed only in the RANSAC and LMedS methods. + +This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 . +@cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation: + +\f[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\f] + +where \f$E\f$ is an essential matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the +second images, respectively. The result of this function may be passed further to +decomposeEssentialMat or recoverPose to recover the relative pose between cameras. + */ +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + InputArray cameraMatrix, int method = RANSAC, + double prob = 0.999, double threshold = 1.0, + OutputArray mask = noArray() ); + +/** @overload +@param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should +be floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param focal focal length of the camera. Note that this function assumes that points1 and points2 +are feature points from cameras with same focal length and principal point. +@param pp principal point of the camera. +@param method Method for computing a fundamental matrix. +- **RANSAC** for the RANSAC algorithm. +- **LMEDS** for the LMedS algorithm. +@param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of +confidence (probability) that the estimated matrix is correct. +@param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 +for the other points. The array is computed only in the RANSAC and LMedS methods. + +This function differs from the one above that it computes camera matrix from focal length and +principal point: + +\f[K = +\begin{bmatrix} +f & 0 & x_{pp} \\ +0 & f & y_{pp} \\ +0 & 0 & 1 +\end{bmatrix}\f] + */ +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + double focal = 1.0, Point2d pp = Point2d(0, 0), + int method = RANSAC, double prob = 0.999, + double threshold = 1.0, OutputArray mask = noArray() ); + +/** @brief Decompose an essential matrix to possible rotations and translation. + +@param E The input essential matrix. +@param R1 One possible rotation matrix. +@param R2 Another possible rotation matrix. +@param t One possible translation. + +This function decompose an essential matrix E using svd decomposition @cite HartleyZ00 . Generally 4 +possible poses exists for a given E. They are \f$[R_1, t]\f$, \f$[R_1, -t]\f$, \f$[R_2, t]\f$, \f$[R_2, -t]\f$. By +decomposing E, you can only get the direction of the translation, so the function returns unit t. + */ +CV_EXPORTS_W void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t ); + +/** @brief Recover relative camera rotation and translation from an estimated essential matrix and the +corresponding points in two images, using cheirality check. Returns the number of inliers which pass +the check. + +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. +This function decomposes an essential matrix using decomposeEssentialMat and then verifies possible +pose hypotheses by doing cheirality check. The cheirality check basically means that the +triangulated 3D points should have positive depth. Some details can be found in @cite Nister03 . + +This function can be used to process output E and mask from findEssentialMat. In this scenario, +points1 and points2 are the same input for findEssentialMat. : +@code + // Example. Estimation of fundamental matrix using the RANSAC algorithm + int point_count = 100; + vector<Point2f> points1(point_count); + vector<Point2f> points2(point_count); + + // initialize the points here ... + for( int i = 0; i < point_count; i++ ) + { + points1[i] = ...; + points2[i] = ...; + } + + // cametra matrix with both focal lengths = 1, and principal point = (0, 0) + Mat cameraMatrix = Mat::eye(3, 3, CV_64F); + + Mat E, R, t, mask; + + E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask); + recoverPose(E, points1, points2, cameraMatrix, R, t, mask); +@endcode + */ +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + InputArray cameraMatrix, OutputArray R, OutputArray t, + InputOutputArray mask = noArray() ); + +/** @overload +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param focal Focal length of the camera. Note that this function assumes that points1 and points2 +are feature points from cameras with same focal length and principal point. +@param pp principal point of the camera. +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. + +This function differs from the one above that it computes camera matrix from focal length and +principal point: + +\f[K = +\begin{bmatrix} +f & 0 & x_{pp} \\ +0 & f & y_{pp} \\ +0 & 0 & 1 +\end{bmatrix}\f] + */ +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + OutputArray R, OutputArray t, + double focal = 1.0, Point2d pp = Point2d(0, 0), + InputOutputArray mask = noArray() ); + +/** @overload +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1. +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param distanceThresh threshold distance which is used to filter out far away points (i.e. infinite points). +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. +@param triangulatedPoints 3d points which were reconstructed by triangulation. + */ + +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + InputArray cameraMatrix, OutputArray R, OutputArray t, double distanceThresh, InputOutputArray mask = noArray(), + OutputArray triangulatedPoints = noArray()); + +/** @brief For points in an image of a stereo pair, computes the corresponding epilines in the other image. + +@param points Input points. \f$N \times 1\f$ or \f$1 \times N\f$ matrix of type CV_32FC2 or +vector\<Point2f\> . +@param whichImage Index of the image (1 or 2) that contains the points . +@param F Fundamental matrix that can be estimated using findFundamentalMat or stereoRectify . +@param lines Output vector of the epipolar lines corresponding to the points in the other image. +Each line \f$ax + by + c=0\f$ is encoded by 3 numbers \f$(a, b, c)\f$ . + +For every point in one of the two images of a stereo pair, the function finds the equation of the +corresponding epipolar line in the other image. + +From the fundamental matrix definition (see findFundamentalMat ), line \f$l^{(2)}_i\f$ in the second +image for the point \f$p^{(1)}_i\f$ in the first image (when whichImage=1 ) is computed as: + +\f[l^{(2)}_i = F p^{(1)}_i\f] + +And vice versa, when whichImage=2, \f$l^{(1)}_i\f$ is computed from \f$p^{(2)}_i\f$ as: + +\f[l^{(1)}_i = F^T p^{(2)}_i\f] + +Line coefficients are defined up to a scale. They are normalized so that \f$a_i^2+b_i^2=1\f$ . + */ +CV_EXPORTS_W void computeCorrespondEpilines( InputArray points, int whichImage, + InputArray F, OutputArray lines ); + +/** @brief Reconstructs points by triangulation. + +@param projMatr1 3x4 projection matrix of the first camera. +@param projMatr2 3x4 projection matrix of the second camera. +@param projPoints1 2xN array of feature points in the first image. In case of c++ version it can +be also a vector of feature points or two-channel matrix of size 1xN or Nx1. +@param projPoints2 2xN array of corresponding points in the second image. In case of c++ version +it can be also a vector of feature points or two-channel matrix of size 1xN or Nx1. +@param points4D 4xN array of reconstructed points in homogeneous coordinates. + +The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their +observations with a stereo camera. Projections matrices can be obtained from stereoRectify. + +@note + Keep in mind that all input data should be of float type in order for this function to work. + +@sa + reprojectImageTo3D + */ +CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2, + InputArray projPoints1, InputArray projPoints2, + OutputArray points4D ); + +/** @brief Refines coordinates of corresponding points. + +@param F 3x3 fundamental matrix. +@param points1 1xN array containing the first set of points. +@param points2 1xN array containing the second set of points. +@param newPoints1 The optimized points1. +@param newPoints2 The optimized points2. + +The function implements the Optimal Triangulation Method (see Multiple View Geometry for details). +For each given point correspondence points1[i] \<-\> points2[i], and a fundamental matrix F, it +computes the corrected correspondences newPoints1[i] \<-\> newPoints2[i] that minimize the geometric +error \f$d(points1[i], newPoints1[i])^2 + d(points2[i],newPoints2[i])^2\f$ (where \f$d(a,b)\f$ is the +geometric distance between points \f$a\f$ and \f$b\f$ ) subject to the epipolar constraint +\f$newPoints2^T * F * newPoints1 = 0\f$ . + */ +CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2, + OutputArray newPoints1, OutputArray newPoints2 ); + +/** @brief Filters off small noise blobs (speckles) in the disparity map + +@param img The input 16-bit signed disparity image +@param newVal The disparity value used to paint-off the speckles +@param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not +affected by the algorithm +@param maxDiff Maximum difference between neighbor disparity pixels to put them into the same +blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point +disparity map, where disparity values are multiplied by 16, this scale factor should be taken into +account when specifying this parameter value. +@param buf The optional temporary buffer to avoid memory allocation within the function. + */ +CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, + int maxSpeckleSize, double maxDiff, + InputOutputArray buf = noArray() ); + +//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) +CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, + int minDisparity, int numberOfDisparities, + int SADWindowSize ); + +//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm +CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost, + int minDisparity, int numberOfDisparities, + int disp12MaxDisp = 1 ); + +/** @brief Reprojects a disparity image to 3D space. + +@param disparity Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit +floating-point disparity image. If 16-bit signed format is used, the values are assumed to have no +fractional bits. +@param _3dImage Output 3-channel floating-point image of the same size as disparity . Each +element of _3dImage(x,y) contains 3D coordinates of the point (x,y) computed from the disparity +map. +@param Q \f$4 \times 4\f$ perspective transformation matrix that can be obtained with stereoRectify. +@param handleMissingValues Indicates, whether the function should handle missing values (i.e. +points where the disparity was not computed). If handleMissingValues=true, then pixels with the +minimal disparity that corresponds to the outliers (see StereoMatcher::compute ) are transformed +to 3D points with a very large Z value (currently set to 10000). +@param ddepth The optional output array depth. If it is -1, the output image will have CV_32F +depth. ddepth can also be set to CV_16S, CV_32S or CV_32F. + +The function transforms a single-channel disparity map to a 3-channel image representing a 3D +surface. That is, for each pixel (x,y) and the corresponding disparity d=disparity(x,y) , it +computes: + +\f[\begin{array}{l} [X \; Y \; Z \; W]^T = \texttt{Q} *[x \; y \; \texttt{disparity} (x,y) \; 1]^T \\ \texttt{\_3dImage} (x,y) = (X/W, \; Y/W, \; Z/W) \end{array}\f] + +The matrix Q can be an arbitrary \f$4 \times 4\f$ matrix (for example, the one computed by +stereoRectify). To reproject a sparse set of points {(x,y,d),...} to 3D space, use +perspectiveTransform . + */ +CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity, + OutputArray _3dImage, InputArray Q, + bool handleMissingValues = false, + int ddepth = -1 ); + +/** @brief Calculates the Sampson Distance between two points. + +The function cv::sampsonDistance calculates and returns the first order approximation of the geometric error as: +\f[ +sd( \texttt{pt1} , \texttt{pt2} )= +\frac{(\texttt{pt2}^t \cdot \texttt{F} \cdot \texttt{pt1})^2} +{((\texttt{F} \cdot \texttt{pt1})(0))^2 + +((\texttt{F} \cdot \texttt{pt1})(1))^2 + +((\texttt{F}^t \cdot \texttt{pt2})(0))^2 + +((\texttt{F}^t \cdot \texttt{pt2})(1))^2} +\f] +The fundamental matrix may be calculated using the cv::findFundamentalMat function. See @cite HartleyZ00 11.4.3 for details. +@param pt1 first homogeneous 2d point +@param pt2 second homogeneous 2d point +@param F fundamental matrix +@return The computed Sampson distance. +*/ +CV_EXPORTS_W double sampsonDistance(InputArray pt1, InputArray pt2, InputArray F); + +/** @brief Computes an optimal affine transformation between two 3D point sets. + +It computes +\f[ +\begin{bmatrix} +x\\ +y\\ +z\\ +\end{bmatrix} += +\begin{bmatrix} +a_{11} & a_{12} & a_{13}\\ +a_{21} & a_{22} & a_{23}\\ +a_{31} & a_{32} & a_{33}\\ +\end{bmatrix} +\begin{bmatrix} +X\\ +Y\\ +Z\\ +\end{bmatrix} ++ +\begin{bmatrix} +b_1\\ +b_2\\ +b_3\\ +\end{bmatrix} +\f] + +@param src First input 3D point set containing \f$(X,Y,Z)\f$. +@param dst Second input 3D point set containing \f$(x,y,z)\f$. +@param out Output 3D affine transformation matrix \f$3 \times 4\f$ of the form +\f[ +\begin{bmatrix} +a_{11} & a_{12} & a_{13} & b_1\\ +a_{21} & a_{22} & a_{23} & b_2\\ +a_{31} & a_{32} & a_{33} & b_3\\ +\end{bmatrix} +\f] +@param inliers Output vector indicating which points are inliers (1-inlier, 0-outlier). +@param ransacThreshold Maximum reprojection error in the RANSAC algorithm to consider a point as +an inlier. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. + +The function estimates an optimal 3D affine transformation between two 3D point sets using the +RANSAC algorithm. + */ +CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, + OutputArray out, OutputArray inliers, + double ransacThreshold = 3, double confidence = 0.99); + +/** @brief Computes an optimal affine transformation between two 2D point sets. + +It computes +\f[ +\begin{bmatrix} +x\\ +y\\ +\end{bmatrix} += +\begin{bmatrix} +a_{11} & a_{12}\\ +a_{21} & a_{22}\\ +\end{bmatrix} +\begin{bmatrix} +X\\ +Y\\ +\end{bmatrix} ++ +\begin{bmatrix} +b_1\\ +b_2\\ +\end{bmatrix} +\f] + +@param from First input 2D point set containing \f$(X,Y)\f$. +@param to Second input 2D point set containing \f$(x,y)\f$. +@param inliers Output vector indicating which points are inliers (1-inlier, 0-outlier). +@param method Robust method used to compute transformation. The following methods are possible: +- cv::RANSAC - RANSAC-based robust method +- cv::LMEDS - Least-Median robust method +RANSAC is the default method. +@param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider +a point as an inlier. Applies only to RANSAC. +@param maxIters The maximum number of robust method iterations. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. +@param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). +Passing 0 will disable refining, so the output matrix will be output of robust method. + +@return Output 2D affine transformation matrix \f$2 \times 3\f$ or empty matrix if transformation +could not be estimated. The returned matrix has the following form: +\f[ +\begin{bmatrix} +a_{11} & a_{12} & b_1\\ +a_{21} & a_{22} & b_2\\ +\end{bmatrix} +\f] + +The function estimates an optimal 2D affine transformation between two 2D point sets using the +selected robust algorithm. + +The computed transformation is then refined further (using only inliers) with the +Levenberg-Marquardt method to reduce the re-projection error even more. + +@note +The RANSAC method can handle practically any ratio of outliers but needs a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. + +@sa estimateAffinePartial2D, getAffineTransform +*/ +CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray from, InputArray to, OutputArray inliers = noArray(), + int method = RANSAC, double ransacReprojThreshold = 3, + size_t maxIters = 2000, double confidence = 0.99, + size_t refineIters = 10); + +/** @brief Computes an optimal limited affine transformation with 4 degrees of freedom between +two 2D point sets. + +@param from First input 2D point set. +@param to Second input 2D point set. +@param inliers Output vector indicating which points are inliers. +@param method Robust method used to compute transformation. The following methods are possible: +- cv::RANSAC - RANSAC-based robust method +- cv::LMEDS - Least-Median robust method +RANSAC is the default method. +@param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider +a point as an inlier. Applies only to RANSAC. +@param maxIters The maximum number of robust method iterations. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. +@param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). +Passing 0 will disable refining, so the output matrix will be output of robust method. + +@return Output 2D affine transformation (4 degrees of freedom) matrix \f$2 \times 3\f$ or +empty matrix if transformation could not be estimated. + +The function estimates an optimal 2D affine transformation with 4 degrees of freedom limited to +combinations of translation, rotation, and uniform scaling. Uses the selected algorithm for robust +estimation. + +The computed transformation is then refined further (using only inliers) with the +Levenberg-Marquardt method to reduce the re-projection error even more. + +Estimated transformation matrix is: +\f[ \begin{bmatrix} \cos(\theta) \cdot s & -\sin(\theta) \cdot s & t_x \\ + \sin(\theta) \cdot s & \cos(\theta) \cdot s & t_y +\end{bmatrix} \f] +Where \f$ \theta \f$ is the rotation angle, \f$ s \f$ the scaling factor and \f$ t_x, t_y \f$ are +translations in \f$ x, y \f$ axes respectively. + +@note +The RANSAC method can handle practically any ratio of outliers but need a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. + +@sa estimateAffine2D, getAffineTransform +*/ +CV_EXPORTS_W cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, OutputArray inliers = noArray(), + int method = RANSAC, double ransacReprojThreshold = 3, + size_t maxIters = 2000, double confidence = 0.99, + size_t refineIters = 10); + +/** @example samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp +An example program with homography decomposition. + +Check @ref tutorial_homography "the corresponding tutorial" for more details. +*/ + +/** @brief Decompose a homography matrix to rotation(s), translation(s) and plane normal(s). + +@param H The input homography matrix between two images. +@param K The input intrinsic camera calibration matrix. +@param rotations Array of rotation matrices. +@param translations Array of translation matrices. +@param normals Array of plane normal matrices. + +This function extracts relative camera motion between two views observing a planar object from the +homography H induced by the plane. The intrinsic camera matrix K must also be provided. The function +may return up to four mathematical solution sets. At least two of the solutions may further be +invalidated if point correspondences are available by applying positive depth constraint (all points +must be in front of the camera). The decomposition method is described in detail in @cite Malis . + */ +CV_EXPORTS_W int decomposeHomographyMat(InputArray H, + InputArray K, + OutputArrayOfArrays rotations, + OutputArrayOfArrays translations, + OutputArrayOfArrays normals); + +/** @brief Filters homography decompositions based on additional information. + +@param rotations Vector of rotation matrices. +@param normals Vector of plane normal matrices. +@param beforePoints Vector of (rectified) visible reference points before the homography is applied +@param afterPoints Vector of (rectified) visible reference points after the homography is applied +@param possibleSolutions Vector of int indices representing the viable solution set after filtering +@param pointsMask optional Mat/Vector of 8u type representing the mask for the inliers as given by the findHomography function + +This function is intended to filter the output of the decomposeHomographyMat based on additional +information as described in @cite Malis . The summary of the method: the decomposeHomographyMat function +returns 2 unique solutions and their "opposites" for a total of 4 solutions. If we have access to the +sets of points visible in the camera frame before and after the homography transformation is applied, +we can determine which are the true potential solutions and which are the opposites by verifying which +homographies are consistent with all visible reference points being in front of the camera. The inputs +are left unchanged; the filtered solution set is returned as indices into the existing one. + +*/ +CV_EXPORTS_W void filterHomographyDecompByVisibleRefpoints(InputArrayOfArrays rotations, + InputArrayOfArrays normals, + InputArray beforePoints, + InputArray afterPoints, + OutputArray possibleSolutions, + InputArray pointsMask = noArray()); + +/** @brief The base class for stereo correspondence algorithms. + */ +class CV_EXPORTS_W StereoMatcher : public Algorithm +{ +public: + enum { DISP_SHIFT = 4, + DISP_SCALE = (1 << DISP_SHIFT) + }; + + /** @brief Computes disparity map for the specified stereo pair + + @param left Left 8-bit single-channel image. + @param right Right image of the same size and the same type as the left one. + @param disparity Output disparity map. It has the same size as the input images. Some algorithms, + like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value + has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map. + */ + CV_WRAP virtual void compute( InputArray left, InputArray right, + OutputArray disparity ) = 0; + + CV_WRAP virtual int getMinDisparity() const = 0; + CV_WRAP virtual void setMinDisparity(int minDisparity) = 0; + + CV_WRAP virtual int getNumDisparities() const = 0; + CV_WRAP virtual void setNumDisparities(int numDisparities) = 0; + + CV_WRAP virtual int getBlockSize() const = 0; + CV_WRAP virtual void setBlockSize(int blockSize) = 0; + + CV_WRAP virtual int getSpeckleWindowSize() const = 0; + CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0; + + CV_WRAP virtual int getSpeckleRange() const = 0; + CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0; + + CV_WRAP virtual int getDisp12MaxDiff() const = 0; + CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0; +}; + + +/** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and +contributed to OpenCV by K. Konolige. + */ +class CV_EXPORTS_W StereoBM : public StereoMatcher +{ +public: + enum { PREFILTER_NORMALIZED_RESPONSE = 0, + PREFILTER_XSOBEL = 1 + }; + + CV_WRAP virtual int getPreFilterType() const = 0; + CV_WRAP virtual void setPreFilterType(int preFilterType) = 0; + + CV_WRAP virtual int getPreFilterSize() const = 0; + CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0; + + CV_WRAP virtual int getPreFilterCap() const = 0; + CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; + + CV_WRAP virtual int getTextureThreshold() const = 0; + CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0; + + CV_WRAP virtual int getUniquenessRatio() const = 0; + CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; + + CV_WRAP virtual int getSmallerBlockSize() const = 0; + CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0; + + CV_WRAP virtual Rect getROI1() const = 0; + CV_WRAP virtual void setROI1(Rect roi1) = 0; + + CV_WRAP virtual Rect getROI2() const = 0; + CV_WRAP virtual void setROI2(Rect roi2) = 0; + + /** @brief Creates StereoBM object + + @param numDisparities the disparity search range. For each pixel algorithm will find the best + disparity from 0 (default minimum disparity) to numDisparities. The search range can then be + shifted by changing the minimum disparity. + @param blockSize the linear size of the blocks compared by the algorithm. The size should be odd + (as the block is centered at the current pixel). Larger block size implies smoother, though less + accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher + chance for algorithm to find a wrong correspondence. + + The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for + a specific stereo pair. + */ + CV_WRAP static Ptr<StereoBM> create(int numDisparities = 0, int blockSize = 21); +}; + +/** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original +one as follows: + +- By default, the algorithm is single-pass, which means that you consider only 5 directions +instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the +algorithm but beware that it may consume a lot of memory. +- The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the +blocks to single pixels. +- Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi +sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well. +- Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for +example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness +check, quadratic interpolation and speckle filtering). + +@note + - (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found + at opencv_source_code/samples/python/stereo_match.py + */ +class CV_EXPORTS_W StereoSGBM : public StereoMatcher +{ +public: + enum + { + MODE_SGBM = 0, + MODE_HH = 1, + MODE_SGBM_3WAY = 2, + MODE_HH4 = 3 + }; + + CV_WRAP virtual int getPreFilterCap() const = 0; + CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; + + CV_WRAP virtual int getUniquenessRatio() const = 0; + CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; + + CV_WRAP virtual int getP1() const = 0; + CV_WRAP virtual void setP1(int P1) = 0; + + CV_WRAP virtual int getP2() const = 0; + CV_WRAP virtual void setP2(int P2) = 0; + + CV_WRAP virtual int getMode() const = 0; + CV_WRAP virtual void setMode(int mode) = 0; + + /** @brief Creates StereoSGBM object + + @param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes + rectification algorithms can shift images, so this parameter needs to be adjusted accordingly. + @param numDisparities Maximum disparity minus minimum disparity. The value is always greater than + zero. In the current implementation, this parameter must be divisible by 16. + @param blockSize Matched block size. It must be an odd number \>=1 . Normally, it should be + somewhere in the 3..11 range. + @param P1 The first parameter controlling the disparity smoothness. See below. + @param P2 The second parameter controlling the disparity smoothness. The larger the values are, + the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1 + between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor + pixels. The algorithm requires P2 \> P1 . See stereo_match.cpp sample where some reasonably good + P1 and P2 values are shown (like 8\*number_of_image_channels\*SADWindowSize\*SADWindowSize and + 32\*number_of_image_channels\*SADWindowSize\*SADWindowSize , respectively). + @param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right + disparity check. Set it to a non-positive value to disable the check. + @param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first + computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval. + The result values are passed to the Birchfield-Tomasi pixel cost function. + @param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function + value should "win" the second best value to consider the found match correct. Normally, a value + within the 5-15 range is good enough. + @param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles + and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the + 50-200 range. + @param speckleRange Maximum disparity variation within each connected component. If you do speckle + filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. + Normally, 1 or 2 is good enough. + @param mode Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming + algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and + huge for HD-size pictures. By default, it is set to false . + + The first constructor initializes StereoSGBM with all the default parameters. So, you only have to + set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter + to a custom value. + */ + CV_WRAP static Ptr<StereoSGBM> create(int minDisparity = 0, int numDisparities = 16, int blockSize = 3, + int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, + int preFilterCap = 0, int uniquenessRatio = 0, + int speckleWindowSize = 0, int speckleRange = 0, + int mode = StereoSGBM::MODE_SGBM); +}; + +//! @} calib3d + +/** @brief The methods in this namespace use a so-called fisheye camera model. + @ingroup calib3d_fisheye +*/ +namespace fisheye +{ +//! @addtogroup calib3d_fisheye +//! @{ + + enum{ + CALIB_USE_INTRINSIC_GUESS = 1 << 0, + CALIB_RECOMPUTE_EXTRINSIC = 1 << 1, + CALIB_CHECK_COND = 1 << 2, + CALIB_FIX_SKEW = 1 << 3, + CALIB_FIX_K1 = 1 << 4, + CALIB_FIX_K2 = 1 << 5, + CALIB_FIX_K3 = 1 << 6, + CALIB_FIX_K4 = 1 << 7, + CALIB_FIX_INTRINSIC = 1 << 8, + CALIB_FIX_PRINCIPAL_POINT = 1 << 9 + }; + + /** @brief Projects points using fisheye model + + @param objectPoints Array of object points, 1xN/Nx1 3-channel (or vector\<Point3f\> ), where N is + the number of points in the view. + @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or + vector\<Point2f\>. + @param affine + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param alpha The skew coefficient. + @param jacobian Optional output 2Nx15 jacobian matrix of derivatives of image points with respect + to components of the focal lengths, coordinates of the principal point, distortion coefficients, + rotation vector, translation vector, and the skew. In the old interface different components of + the jacobian are returned via different output parameters. + + The function computes projections of 3D points to the image plane given intrinsic and extrinsic + camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of + image points coordinates (as functions of all the input parameters) with respect to the particular + parameters, intrinsic and/or extrinsic. + */ + CV_EXPORTS void projectPoints(InputArray objectPoints, OutputArray imagePoints, const Affine3d& affine, + InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray()); + + /** @overload */ + CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, + InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray()); + + /** @brief Distorts 2D points using fisheye model. + + @param undistorted Array of object points, 1xN/Nx1 2-channel (or vector\<Point2f\> ), where N is + the number of points in the view. + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param alpha The skew coefficient. + @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\<Point2f\> . + + Note that the function assumes the camera matrix of the undistorted points to be identity. + This means if you want to transform back points undistorted with undistortPoints() you have to + multiply them with \f$P^{-1}\f$. + */ + CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0); + + /** @brief Undistorts 2D points using fisheye model + + @param distorted Array of object points, 1xN/Nx1 2-channel (or vector\<Point2f\> ), where N is the + number of points in the view. + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param undistorted Output array of image points, 1xN/Nx1 2-channel, or vector\<Point2f\> . + */ + CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, + InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray()); + + /** @brief Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero + distortion is used, if R or P is empty identity matrixes are used. + + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param size Undistorted image size. + @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() + for details. + @param map1 The first output map. + @param map2 The second output map. + */ + CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray R, InputArray P, + const cv::Size& size, int m1type, OutputArray map1, OutputArray map2); + + /** @brief Transforms an image to compensate for fisheye lens distortion. + + @param distorted image with fisheye lens distortion. + @param undistorted Output image with compensated fisheye lens distortion. + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param Knew Camera matrix of the distorted image. By default, it is the identity matrix but you + may additionally scale and shift the result by using a different matrix. + @param new_size + + The function transforms an image to compensate radial and tangential lens distortion. + + The function is simply a combination of fisheye::initUndistortRectifyMap (with unity R ) and remap + (with bilinear interpolation). See the former function for details of the transformation being + performed. + + See below the results of undistortImage. + - a\) result of undistort of perspective camera model (all possible coefficients (k_1, k_2, k_3, + k_4, k_5, k_6) of distortion were optimized under calibration) + - b\) result of fisheye::undistortImage of fisheye camera model (all possible coefficients (k_1, k_2, + k_3, k_4) of fisheye distortion were optimized under calibration) + - c\) original image was captured with fisheye lens + + Pictures a) and b) almost the same. But if we consider points of image located far from the center + of image, we can notice that on image a) these points are distorted. + + ![image](pics/fisheye_undistorted.jpg) + */ + CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, + InputArray K, InputArray D, InputArray Knew = cv::noArray(), const Size& new_size = Size()); + + /** @brief Estimates new camera matrix for undistortion or rectification. + + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param image_size + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param balance Sets the new focal length in range between the min focal length and the max focal + length. Balance is in range of [0, 1]. + @param new_size + @param fov_scale Divisor for new focal length. + */ + CV_EXPORTS_W void estimateNewCameraMatrixForUndistortRectify(InputArray K, InputArray D, const Size &image_size, InputArray R, + OutputArray P, double balance = 0.0, const Size& new_size = Size(), double fov_scale = 1.0); + + /** @brief Performs camera calibaration + + @param objectPoints vector of vectors of calibration pattern points in the calibration pattern + coordinate space. + @param imagePoints vector of vectors of the projections of calibration pattern points. + imagePoints.size() and objectPoints.size() and imagePoints[i].size() must be equal to + objectPoints[i].size() for each i. + @param image_size Size of the image used only to initialize the intrinsic camera matrix. + @param K Output 3x3 floating-point camera matrix + \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If + fisheye::CALIB_USE_INTRINSIC_GUESS/ is specified, some or all of fx, fy, cx, cy must be + initialized before calling the function. + @param D Output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view. + That is, each k-th rotation vector together with the corresponding k-th translation vector (see + the next output parameter description) brings the calibration pattern from the model coordinate + space (in which object points are specified) to the world coordinate space, that is, a real + position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). + @param tvecs Output vector of translation vectors estimated for each pattern view. + @param flags Different flags that may be zero or a combination of the following values: + - **fisheye::CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of + fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image + center ( imageSize is used), and focal distances are computed in a least-squares fashion. + - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration + of intrinsic optimization. + - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. + - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. + - **fisheye::CALIB_FIX_K1..fisheye::CALIB_FIX_K4** Selected distortion coefficients + are set to zeros and stay zero. + - **fisheye::CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global +optimization. It stays at the center or at a different location specified when CALIB_USE_INTRINSIC_GUESS is set too. + @param criteria Termination criteria for the iterative optimization algorithm. + */ + CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size, + InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)); + + /** @brief Stereo rectification for fisheye camera model + + @param K1 First camera matrix. + @param D1 First camera distortion parameters. + @param K2 Second camera matrix. + @param D2 Second camera distortion parameters. + @param imageSize Size of the image used for stereo calibration. + @param R Rotation matrix between the coordinate systems of the first and the second + cameras. + @param tvec Translation vector between coordinate systems of the cameras. + @param R1 Output 3x3 rectification transform (rotation matrix) for the first camera. + @param R2 Output 3x3 rectification transform (rotation matrix) for the second camera. + @param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first + camera. + @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second + camera. + @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). + @param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set, + the function makes the principal points of each camera have the same pixel coordinates in the + rectified views. And if the flag is not set, the function may still shift the images in the + horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the + useful image area. + @param newImageSize New image resolution after rectification. The same size should be passed to + initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) + is passed (default), it is set to the original imageSize . Setting it to larger value can help you + preserve details in the original image, especially when there is a big radial distortion. + @param balance Sets the new focal length in range between the min focal length and the max focal + length. Balance is in range of [0, 1]. + @param fov_scale Divisor for new focal length. + */ + CV_EXPORTS_W void stereoRectify(InputArray K1, InputArray D1, InputArray K2, InputArray D2, const Size &imageSize, InputArray R, InputArray tvec, + OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(), + double balance = 0.0, double fov_scale = 1.0); + + /** @brief Performs stereo calibration + + @param objectPoints Vector of vectors of the calibration pattern points. + @param imagePoints1 Vector of vectors of the projections of the calibration pattern points, + observed by the first camera. + @param imagePoints2 Vector of vectors of the projections of the calibration pattern points, + observed by the second camera. + @param K1 Input/output first camera matrix: + \f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If + any of fisheye::CALIB_USE_INTRINSIC_GUESS , fisheye::CALIB_FIX_INTRINSIC are specified, + some or all of the matrix components must be initialized. + @param D1 Input/output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$ of 4 elements. + @param K2 Input/output second camera matrix. The parameter is similar to K1 . + @param D2 Input/output lens distortion coefficients for the second camera. The parameter is + similar to D1 . + @param imageSize Size of the image used only to initialize intrinsic camera matrix. + @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. + @param T Output translation vector between the coordinate systems of the cameras. + @param flags Different flags that may be zero or a combination of the following values: + - **fisheye::CALIB_FIX_INTRINSIC** Fix K1, K2? and D1, D2? so that only R, T matrices + are estimated. + - **fisheye::CALIB_USE_INTRINSIC_GUESS** K1, K2 contains valid initial values of + fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image + center (imageSize is used), and focal distances are computed in a least-squares fashion. + - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration + of intrinsic optimization. + - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. + - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. + - **fisheye::CALIB_FIX_K1..4** Selected distortion coefficients are set to zeros and stay + zero. + @param criteria Termination criteria for the iterative optimization algorithm. + */ + CV_EXPORTS_W double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize, + OutputArray R, OutputArray T, int flags = fisheye::CALIB_FIX_INTRINSIC, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)); + +//! @} calib3d_fisheye +} // end namespace fisheye + +} //end namespace cv + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/calib3d/calib3d_c.h" +#endif + +#endif diff --git a/include/opencv2/calib3d/calib3d.hpp b/include/opencv2/calib3d/calib3d.hpp new file mode 100644 index 0000000..b3da45e --- /dev/null +++ b/include/opencv2/calib3d/calib3d.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/calib3d.hpp" diff --git a/include/opencv2/calib3d/calib3d_c.h b/include/opencv2/calib3d/calib3d_c.h new file mode 100644 index 0000000..8ec6390 --- /dev/null +++ b/include/opencv2/calib3d/calib3d_c.h @@ -0,0 +1,427 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CALIB3D_C_H +#define OPENCV_CALIB3D_C_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup calib3d_c + @{ + */ + +/****************************************************************************************\ +* Camera Calibration, Pose Estimation and Stereo * +\****************************************************************************************/ + +typedef struct CvPOSITObject CvPOSITObject; + +/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */ +CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count ); + + +/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of + an object given its model and projection in a weak-perspective case */ +CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points, + double focal_length, CvTermCriteria criteria, + float* rotation_matrix, float* translation_vector); + +/* Releases CvPOSITObject structure */ +CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object ); + +/* updates the number of RANSAC iterations */ +CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob, + int model_points, int max_iters ); + +CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst ); + +/* Calculates fundamental matrix given a set of corresponding points */ +#define CV_FM_7POINT 1 +#define CV_FM_8POINT 2 + +#define CV_LMEDS 4 +#define CV_RANSAC 8 + +#define CV_FM_LMEDS_ONLY CV_LMEDS +#define CV_FM_RANSAC_ONLY CV_RANSAC +#define CV_FM_LMEDS CV_LMEDS +#define CV_FM_RANSAC CV_RANSAC + +enum +{ + CV_ITERATIVE = 0, + CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" + CV_P3P = 2, // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem" + CV_DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP" +}; + +CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, + CvMat* fundamental_matrix, + int method CV_DEFAULT(CV_FM_RANSAC), + double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99), + CvMat* status CV_DEFAULT(NULL) ); + +/* For each input point on one of images + computes parameters of the corresponding + epipolar line on the other image */ +CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points, + int which_image, + const CvMat* fundamental_matrix, + CvMat* correspondent_lines ); + +/* Triangulation functions */ + +CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, + CvMat* projPoints1, CvMat* projPoints2, + CvMat* points4D); + +CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2, + CvMat* new_points1, CvMat* new_points2); + + +/* Computes the optimal new camera matrix according to the free scaling parameter alpha: + alpha=0 - only valid pixels will be retained in the undistorted image + alpha=1 - all the source image pixels will be retained in the undistorted image +*/ +CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix, + const CvMat* dist_coeffs, + CvSize image_size, double alpha, + CvMat* new_camera_matrix, + CvSize new_imag_size CV_DEFAULT(cvSize(0,0)), + CvRect* valid_pixel_ROI CV_DEFAULT(0), + int center_principal_point CV_DEFAULT(0)); + +/* Converts rotation vector to rotation matrix or vice versa */ +CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst, + CvMat* jacobian CV_DEFAULT(0) ); + +/* Finds perspective transformation between the object plane and image (view) plane */ +CVAPI(int) cvFindHomography( const CvMat* src_points, + const CvMat* dst_points, + CvMat* homography, + int method CV_DEFAULT(0), + double ransacReprojThreshold CV_DEFAULT(3), + CvMat* mask CV_DEFAULT(0), + int maxIters CV_DEFAULT(2000), + double confidence CV_DEFAULT(0.995)); + +/* Computes RQ decomposition for 3x3 matrices */ +CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, + CvMat *matrixQx CV_DEFAULT(NULL), + CvMat *matrixQy CV_DEFAULT(NULL), + CvMat *matrixQz CV_DEFAULT(NULL), + CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); + +/* Computes projection matrix decomposition */ +CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr, + CvMat *rotMatr, CvMat *posVect, + CvMat *rotMatrX CV_DEFAULT(NULL), + CvMat *rotMatrY CV_DEFAULT(NULL), + CvMat *rotMatrZ CV_DEFAULT(NULL), + CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); + +/* Computes d(AB)/dA and d(AB)/dB */ +CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB ); + +/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)), + t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */ +CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1, + const CvMat* _rvec2, const CvMat* _tvec2, + CvMat* _rvec3, CvMat* _tvec3, + CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0), + CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0), + CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0), + CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) ); + +/* Projects object points to the view plane using + the specified extrinsic and intrinsic camera parameters */ +CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector, + const CvMat* translation_vector, const CvMat* camera_matrix, + const CvMat* distortion_coeffs, CvMat* image_points, + CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL), + CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL), + CvMat* dpddist CV_DEFAULT(NULL), + double aspect_ratio CV_DEFAULT(0)); + +/* Finds extrinsic camera parameters from + a few known corresponding point pairs and intrinsic parameters */ +CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points, + const CvMat* image_points, + const CvMat* camera_matrix, + const CvMat* distortion_coeffs, + CvMat* rotation_vector, + CvMat* translation_vector, + int use_extrinsic_guess CV_DEFAULT(0) ); + +/* Computes initial estimate of the intrinsic camera parameters + in case of planar calibration target (e.g. chessboard) */ +CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points, + const CvMat* image_points, + const CvMat* npoints, CvSize image_size, + CvMat* camera_matrix, + double aspect_ratio CV_DEFAULT(1.) ); + +#define CV_CALIB_CB_ADAPTIVE_THRESH 1 +#define CV_CALIB_CB_NORMALIZE_IMAGE 2 +#define CV_CALIB_CB_FILTER_QUADS 4 +#define CV_CALIB_CB_FAST_CHECK 8 + +// Performs a fast check if a chessboard is in the input image. This is a workaround to +// a problem of cvFindChessboardCorners being slow on images with no chessboard +// - src: input image +// - size: chessboard size +// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, +// 0 if there is no chessboard, -1 in case of error +CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size); + + /* Detects corners on a chessboard calibration pattern */ +CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size, + CvPoint2D32f* corners, + int* corner_count CV_DEFAULT(NULL), + int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) ); + +/* Draws individual chessboard corners or the whole chessboard detected */ +CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, + CvPoint2D32f* corners, + int count, int pattern_was_found ); + +#define CV_CALIB_USE_INTRINSIC_GUESS 1 +#define CV_CALIB_FIX_ASPECT_RATIO 2 +#define CV_CALIB_FIX_PRINCIPAL_POINT 4 +#define CV_CALIB_ZERO_TANGENT_DIST 8 +#define CV_CALIB_FIX_FOCAL_LENGTH 16 +#define CV_CALIB_FIX_K1 32 +#define CV_CALIB_FIX_K2 64 +#define CV_CALIB_FIX_K3 128 +#define CV_CALIB_FIX_K4 2048 +#define CV_CALIB_FIX_K5 4096 +#define CV_CALIB_FIX_K6 8192 +#define CV_CALIB_RATIONAL_MODEL 16384 +#define CV_CALIB_THIN_PRISM_MODEL 32768 +#define CV_CALIB_FIX_S1_S2_S3_S4 65536 +#define CV_CALIB_TILTED_MODEL 262144 +#define CV_CALIB_FIX_TAUX_TAUY 524288 +#define CV_CALIB_FIX_TANGENT_DIST 2097152 + +#define CV_CALIB_NINTRINSIC 18 + +/* Finds intrinsic and extrinsic camera parameters + from a few views of known calibration pattern */ +CVAPI(double) cvCalibrateCamera2( const CvMat* object_points, + const CvMat* image_points, + const CvMat* point_counts, + CvSize image_size, + CvMat* camera_matrix, + CvMat* distortion_coeffs, + CvMat* rotation_vectors CV_DEFAULT(NULL), + CvMat* translation_vectors CV_DEFAULT(NULL), + int flags CV_DEFAULT(0), + CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( + CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) ); + +/* Computes various useful characteristics of the camera from the data computed by + cvCalibrateCamera2 */ +CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix, + CvSize image_size, + double aperture_width CV_DEFAULT(0), + double aperture_height CV_DEFAULT(0), + double *fovx CV_DEFAULT(NULL), + double *fovy CV_DEFAULT(NULL), + double *focal_length CV_DEFAULT(NULL), + CvPoint2D64f *principal_point CV_DEFAULT(NULL), + double *pixel_aspect_ratio CV_DEFAULT(NULL)); + +#define CV_CALIB_FIX_INTRINSIC 256 +#define CV_CALIB_SAME_FOCAL_LENGTH 512 + +/* Computes the transformation from one camera coordinate system to another one + from a few correspondent views of the same calibration target. Optionally, calibrates + both cameras */ +CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1, + const CvMat* image_points2, const CvMat* npoints, + CvMat* camera_matrix1, CvMat* dist_coeffs1, + CvMat* camera_matrix2, CvMat* dist_coeffs2, + CvSize image_size, CvMat* R, CvMat* T, + CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0), + int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC), + CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( + CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)) ); + +#define CV_CALIB_ZERO_DISPARITY 1024 + +/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both + views parallel (=> to make all the epipolar lines horizontal or vertical) */ +CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2, + const CvMat* dist_coeffs1, const CvMat* dist_coeffs2, + CvSize image_size, const CvMat* R, const CvMat* T, + CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2, + CvMat* Q CV_DEFAULT(0), + int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY), + double alpha CV_DEFAULT(-1), + CvSize new_image_size CV_DEFAULT(cvSize(0,0)), + CvRect* valid_pix_ROI1 CV_DEFAULT(0), + CvRect* valid_pix_ROI2 CV_DEFAULT(0)); + +/* Computes rectification transformations for uncalibrated pair of images using a set + of point correspondences */ +CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2, + const CvMat* F, CvSize img_size, + CvMat* H1, CvMat* H2, + double threshold CV_DEFAULT(5)); + + + +/* stereo correspondence parameters and functions */ + +#define CV_STEREO_BM_NORMALIZED_RESPONSE 0 +#define CV_STEREO_BM_XSOBEL 1 + +/* Block matching algorithm structure */ +typedef struct CvStereoBMState +{ + // pre-filtering (normalization of input images) + int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now + int preFilterSize; // averaging window size: ~5x5..21x21 + int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap] + + // correspondence using Sum of Absolute Difference (SAD) + int SADWindowSize; // ~5x5..21x21 + int minDisparity; // minimum disparity (can be negative) + int numberOfDisparities; // maximum disparity - minimum disparity (> 0) + + // post-filtering + int textureThreshold; // the disparity is only computed for pixels + // with textured enough neighborhood + int uniquenessRatio; // accept the computed disparity d* only if + // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.) + // for any d != d*+/-1 within the search range. + int speckleWindowSize; // disparity variation window + int speckleRange; // acceptable range of variation in window + + int trySmallerWindows; // if 1, the results may be more accurate, + // at the expense of slower processing + CvRect roi1, roi2; + int disp12MaxDiff; + + // temporary buffers + CvMat* preFilteredImg0; + CvMat* preFilteredImg1; + CvMat* slidingSumBuf; + CvMat* cost; + CvMat* disp; +} CvStereoBMState; + +#define CV_STEREO_BM_BASIC 0 +#define CV_STEREO_BM_FISH_EYE 1 +#define CV_STEREO_BM_NARROW 2 + +CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC), + int numberOfDisparities CV_DEFAULT(0)); + +CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state ); + +CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right, + CvArr* disparity, CvStereoBMState* state ); + +CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity, + int numberOfDisparities, int SADWindowSize ); + +CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost, + int minDisparity, int numberOfDisparities, + int disp12MaxDiff CV_DEFAULT(1) ); + +/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */ +CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage, + CvArr* _3dImage, const CvMat* Q, + int handleMissingValues CV_DEFAULT(0) ); + +/** @} calib3d_c */ + +#ifdef __cplusplus +} // extern "C" + +////////////////////////////////////////////////////////////////////////////////////////// +class CV_EXPORTS CvLevMarq +{ +public: + CvLevMarq(); + CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + ~CvLevMarq(); + void init( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + bool update( const CvMat*& param, CvMat*& J, CvMat*& err ); + bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm ); + + void clear(); + void step(); + enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; + + cv::Ptr<CvMat> mask; + cv::Ptr<CvMat> prevParam; + cv::Ptr<CvMat> param; + cv::Ptr<CvMat> J; + cv::Ptr<CvMat> err; + cv::Ptr<CvMat> JtJ; + cv::Ptr<CvMat> JtJN; + cv::Ptr<CvMat> JtErr; + cv::Ptr<CvMat> JtJV; + cv::Ptr<CvMat> JtJW; + double prevErrNorm, errNorm; + int lambdaLg10; + CvTermCriteria criteria; + int state; + int iters; + bool completeSymmFlag; + int solveMethod; +}; + +#endif + +#endif /* OPENCV_CALIB3D_C_H */ diff --git a/include/opencv2/ccalib.hpp b/include/opencv2/ccalib.hpp new file mode 100644 index 0000000..c9b9391 --- /dev/null +++ b/include/opencv2/ccalib.hpp @@ -0,0 +1,157 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2014, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_CCALIB_HPP__ +#define __OPENCV_CCALIB_HPP__ + +#include <opencv2/core.hpp> +#include <opencv2/features2d.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/calib3d.hpp> + +#include <vector> + +/** @defgroup ccalib Custom Calibration Pattern for 3D reconstruction +*/ + +namespace cv{ namespace ccalib{ + +//! @addtogroup ccalib +//! @{ + +class CV_EXPORTS CustomPattern : public Algorithm +{ +public: + CustomPattern(); + virtual ~CustomPattern(); + + bool create(InputArray pattern, const Size2f boardSize, OutputArray output = noArray()); + + bool findPattern(InputArray image, OutputArray matched_features, OutputArray pattern_points, const double ratio = 0.7, + const double proj_error = 8.0, const bool refine_position = false, OutputArray out = noArray(), + OutputArray H = noArray(), OutputArray pattern_corners = noArray()); + + bool isInitialized(); + + void getPatternPoints(std::vector<KeyPoint>& original_points); + /**< + Returns a vector<Point> of the original points. + */ + double getPixelSize(); + /**< + Get the pixel size of the pattern + */ + + bool setFeatureDetector(Ptr<FeatureDetector> featureDetector); + bool setDescriptorExtractor(Ptr<DescriptorExtractor> extractor); + bool setDescriptorMatcher(Ptr<DescriptorMatcher> matcher); + + Ptr<FeatureDetector> getFeatureDetector(); + Ptr<DescriptorExtractor> getDescriptorExtractor(); + Ptr<DescriptorMatcher> getDescriptorMatcher(); + + double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + /**< + Calls the calirateCamera function with the same inputs. + */ + + bool findRt(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE); + bool findRt(InputArray image, InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE); + /**< + Uses solvePnP to find the rotation and translation of the pattern + with respect to the camera frame. + */ + + bool findRtRANSAC(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, int minInliersCount = 100, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE); + bool findRtRANSAC(InputArray image, InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, int minInliersCount = 100, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE); + /**< + Uses solvePnPRansac() + */ + + void drawOrientation(InputOutputArray image, InputArray tvec, InputArray rvec, InputArray cameraMatrix, + InputArray distCoeffs, double axis_length = 3, int axis_width = 2); + /**< + pattern_corners -> projected over the image position of the edges of the pattern. + */ + +private: + + Mat img_roi; + std::vector<Point2f> obj_corners; + double pxSize; + + bool initialized; + + Ptr<FeatureDetector> detector; + Ptr<DescriptorExtractor> descriptorExtractor; + Ptr<DescriptorMatcher> descriptorMatcher; + + std::vector<KeyPoint> keypoints; + std::vector<Point3f> points3d; + Mat descriptor; + + bool init(Mat& image, const float pixel_size, OutputArray output = noArray()); + bool findPatternPass(const Mat& image, std::vector<Point2f>& matched_features, std::vector<Point3f>& pattern_points, + Mat& H, std::vector<Point2f>& scene_corners, const double pratio, const double proj_error, + const bool refine_position = false, const Mat& mask = Mat(), OutputArray output = noArray()); + void scaleFoundPoints(const double squareSize, const std::vector<KeyPoint>& corners, std::vector<Point3f>& pts3d); + void check_matches(std::vector<Point2f>& matched, const std::vector<Point2f>& pattern, std::vector<DMatch>& good, std::vector<Point3f>& pattern_3d, const Mat& H); + + void keypoints2points(const std::vector<KeyPoint>& in, std::vector<Point2f>& out); + void updateKeypointsPos(std::vector<KeyPoint>& in, const std::vector<Point2f>& new_pos); + void refinePointsPos(const Mat& img, std::vector<Point2f>& p); + void refineKeypointsPos(const Mat& img, std::vector<KeyPoint>& kp); +}; + +//! @} + +}} // namespace ccalib, cv + +#endif diff --git a/include/opencv2/ccalib/multicalib.hpp b/include/opencv2/ccalib/multicalib.hpp new file mode 100644 index 0000000..686d7a5 --- /dev/null +++ b/include/opencv2/ccalib/multicalib.hpp @@ -0,0 +1,212 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, +// all rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_MULTICAMERACALIBRATION_HPP__ +#define __OPENCV_MULTICAMERACALIBRATION_HPP__ + +#include "opencv2/ccalib/randpattern.hpp" +#include "opencv2/ccalib/omnidir.hpp" +#include <string> +#include <iostream> + +namespace cv { namespace multicalib { + +//! @addtogroup ccalib +//! @{ + +#define HEAD -1 +#define INVALID -2 + +/** @brief Class for multiple camera calibration that supports pinhole camera and omnidirection camera. +For omnidirectional camera model, please refer to omnidir.hpp in ccalib module. +It first calibrate each camera individually, then a bundle adjustment like optimization is applied to +refine extrinsic parameters. So far, it only support "random" pattern for calibration, +see randomPattern.hpp in ccalib module for details. +Images that are used should be named by "cameraIdx-timestamp.*", several images with the same timestamp +means that they are the same pattern that are photographed. cameraIdx should start from 0. + +For more details, please refer to paper + B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System + Calibration Toolbox Using A Feature Descriptor-Based Calibration + Pattern", in IROS 2013. +*/ + +class CV_EXPORTS MultiCameraCalibration +{ +public: + enum { + PINHOLE, + OMNIDIRECTIONAL + //FISHEYE + }; + + // an edge connects a camera and pattern + struct edge + { + int cameraVertex; // vertex index for camera in this edge + int photoVertex; // vertex index for pattern in this edge + int photoIndex; // photo index among photos for this camera + Mat transform; // transform from pattern to camera + + edge(int cv, int pv, int pi, Mat trans) + { + cameraVertex = cv; + photoVertex = pv; + photoIndex = pi; + transform = trans; + } + }; + + struct vertex + { + Mat pose; // relative pose to the first camera. For camera vertex, it is the + // transform from the first camera to this camera, for pattern vertex, + // it is the transform from pattern to the first camera + int timestamp; // timestamp of photo, only available for photo vertex + + vertex(Mat po, int ts) + { + pose = po; + timestamp = ts; + } + + vertex() + { + pose = Mat::eye(4, 4, CV_32F); + timestamp = -1; + } + }; + /* @brief Constructor + @param cameraType camera type, PINHOLE or OMNIDIRECTIONAL + @param nCameras number of cameras + @fileName filename of string list that are used for calibration, the file is generated + by imagelist_creator from OpenCv samples. The first one in the list is the pattern filename. + @patternWidth the physical width of pattern, in user defined unit. + @patternHeight the physical height of pattern, in user defined unit. + @showExtration whether show extracted features and feature filtering. + @nMiniMatches minimal number of matched features for a frame. + @flags Calibration flags + @criteria optimization stopping criteria. + @detector feature detector that detect feature points in pattern and images. + @descriptor feature descriptor. + @matcher feature matcher. + */ + MultiCameraCalibration(int cameraType, int nCameras, const std::string& fileName, float patternWidth, + float patternHeight, int verbose = 0, int showExtration = 0, int nMiniMatches = 20, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 200, 1e-7), + Ptr<FeatureDetector> detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.006f), + Ptr<DescriptorExtractor> descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.006f), + Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-L1")); + + /* @brief load images + */ + void loadImages(); + + /* @brief initialize multiple camera calibration. It calibrates each camera individually. + */ + void initialize(); + + /* @brief optimization extrinsic parameters + */ + double optimizeExtrinsics(); + + /* @brief run multi-camera camera calibration, it runs loadImage(), initialize() and optimizeExtrinsics() + */ + double run(); + + /* @brief write camera parameters to file. + */ + void writeParameters(const std::string& filename); + +private: + std::vector<std::string> readStringList(); + + int getPhotoVertex(int timestamp); + + void graphTraverse(const Mat& G, int begin, std::vector<int>& order, std::vector<int>& pre); + + void findRowNonZero(const Mat& row, Mat& idx); + + void computeJacobianExtrinsic(const Mat& extrinsicParams, Mat& JTJ_inv, Mat& JTE); + + void computePhotoCameraJacobian(const Mat& rvecPhoto, const Mat& tvecPhoto, const Mat& rvecCamera, + const Mat& tvecCamera, Mat& rvecTran, Mat& tvecTran, const Mat& objectPoints, const Mat& imagePoints, const Mat& K, + const Mat& distort, const Mat& xi, Mat& jacobianPhoto, Mat& jacobianCamera, Mat& E); + + void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1, + Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2); + + void JRodriguesMatlab(const Mat& src, Mat& dst); + void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB); + + double computeProjectError(Mat& parameters); + + void vector2parameters(const Mat& parameters, std::vector<Vec3f>& rvecVertex, std::vector<Vec3f>& tvecVertexs); + void parameters2vector(const std::vector<Vec3f>& rvecVertex, const std::vector<Vec3f>& tvecVertex, Mat& parameters); + + int _camType; //PINHOLE, FISHEYE or OMNIDIRECTIONAL + int _nCamera; + int _nMiniMatches; + int _flags; + int _verbose; + double _error; + float _patternWidth, _patternHeight; + TermCriteria _criteria; + std::string _filename; + int _showExtraction; + Ptr<FeatureDetector> _detector; + Ptr<DescriptorExtractor> _descriptor; + Ptr<DescriptorMatcher> _matcher; + + std::vector<edge> _edgeList; + std::vector<vertex> _vertexList; + std::vector<std::vector<cv::Mat> > _objectPointsForEachCamera; + std::vector<std::vector<cv::Mat> > _imagePointsForEachCamera; + std::vector<cv::Mat> _cameraMatrix; + std::vector<cv::Mat> _distortCoeffs; + std::vector<cv::Mat> _xi; + std::vector<std::vector<Mat> > _omEachCamera, _tEachCamera; +}; + +//! @} + +}} // namespace multicalib, cv +#endif \ No newline at end of file diff --git a/include/opencv2/ccalib/omnidir.hpp b/include/opencv2/ccalib/omnidir.hpp new file mode 100644 index 0000000..140aede --- /dev/null +++ b/include/opencv2/ccalib/omnidir.hpp @@ -0,0 +1,310 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, +// all rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#include <opencv2/core.hpp> +#include <vector> + +#ifndef __OPENCV_OMNIDIR_HPP__ +#define __OPENCV_OMNIDIR_HPP__ + +namespace cv +{ +namespace omnidir +{ + //! @addtogroup ccalib + //! @{ + + enum { + CALIB_USE_GUESS = 1, + CALIB_FIX_SKEW = 2, + CALIB_FIX_K1 = 4, + CALIB_FIX_K2 = 8, + CALIB_FIX_P1 = 16, + CALIB_FIX_P2 = 32, + CALIB_FIX_XI = 64, + CALIB_FIX_GAMMA = 128, + CALIB_FIX_CENTER = 256 + }; + + enum{ + RECTIFY_PERSPECTIVE = 1, + RECTIFY_CYLINDRICAL = 2, + RECTIFY_LONGLATI = 3, + RECTIFY_STEREOGRAPHIC = 4 + }; + + enum{ + XYZRGB = 1, + XYZ = 2 + }; +/** + * This module was accepted as a GSoC 2015 project for OpenCV, authored by + * Baisheng Lai, mentored by Bo Li. + */ + + /** @brief Projects points for omnidirectional camera using CMei's model + + @param objectPoints Object points in world coordinate, vector of vector of Vec3f or Mat of + 1xN/Nx1 3-channel of type CV_32F and N is the number of points. 64F is also acceptable. + @param imagePoints Output array of image points, vector of vector of Vec2f or + 1xN/Nx1 2-channel of type CV_32F. 64F is also acceptable. + @param rvec vector of rotation between world coordinate and camera coordinate, i.e., om + @param tvec vector of translation between pattern coordinate and camera coordinate + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. + @param xi The parameter xi for CMei's model + @param jacobian Optional output 2Nx16 of type CV_64F jacobian matrix, contains the derivatives of + image pixel points wrt parameters including \f$om, T, f_x, f_y, s, c_x, c_y, xi, k_1, k_2, p_1, p_2\f$. + This matrix will be used in calibration by optimization. + + The function projects object 3D points of world coordinate to image pixels, parameter by intrinsic + and extrinsic parameters. Also, it optionally compute a by-product: the jacobian matrix containing + contains the derivatives of image pixel points wrt intrinsic and extrinsic parameters. + */ + CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, + InputArray K, double xi, InputArray D, OutputArray jacobian = noArray()); + + /** @brief Undistort 2D image points for omnidirectional camera using CMei's model + + @param distorted Array of distorted image points, vector of Vec2f + or 1xN/Nx1 2-channel Mat of type CV_32F, 64F depth is also acceptable + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. + @param xi The parameter xi for CMei's model + @param R Rotation trainsform between the original and object space : 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param undistorted array of normalized object points, vector of Vec2f/Vec2d or 1xN/Nx1 2-channel Mat with the same + depth of distorted points. + */ + CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, InputArray R); + + /** @brief Computes undistortion and rectification maps for omnidirectional camera image transform by a rotation R. + It output two maps that are used for cv::remap(). If D is empty then zero distortion is used, + if R or P is empty then identity matrices are used. + + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$, with depth CV_32F or CV_64F + @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$, with depth CV_32F or CV_64F + @param xi The parameter xi for CMei's model + @param R Rotation transform between the original and object space : 3x3 1-channel, or vector: 3x1/1x3, with depth CV_32F or CV_64F + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param size Undistorted image size. + @param mltype Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() + for details. + @param map1 The first output map. + @param map2 The second output map. + @param flags Flags indicates the rectification type, RECTIFY_PERSPECTIVE, RECTIFY_CYLINDRICAL, RECTIFY_LONGLATI and RECTIFY_STEREOGRAPHIC + are supported. + */ + CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray xi, InputArray R, InputArray P, const cv::Size& size, + int mltype, OutputArray map1, OutputArray map2, int flags); + + /** @brief Undistort omnidirectional images to perspective images + + @param distorted The input omnidirectional image. + @param undistorted The output undistorted image. + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. + @param xi The parameter xi for CMei's model. + @param flags Flags indicates the rectification type, RECTIFY_PERSPECTIVE, RECTIFY_CYLINDRICAL, RECTIFY_LONGLATI and RECTIFY_STEREOGRAPHIC + @param Knew Camera matrix of the distorted image. If it is not assigned, it is just K. + @param new_size The new image size. By default, it is the size of distorted. + @param R Rotation matrix between the input and output images. By default, it is identity matrix. + */ + CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, int flags, + InputArray Knew = cv::noArray(), const Size& new_size = Size(), InputArray R = Mat::eye(3, 3, CV_64F)); + + /** @brief Perform omnidirectional camera calibration, the default depth of outputs is CV_64F. + + @param objectPoints Vector of vector of Vec3f object points in world (pattern) coordinate. + It also can be vector of Mat with size 1xN/Nx1 and type CV_32FC3. Data with depth of 64_F is also acceptable. + @param imagePoints Vector of vector of Vec2f corresponding image points of objectPoints. It must be the same + size and the same type with objectPoints. + @param size Image size of calibration images. + @param K Output calibrated camera matrix. + @param xi Output parameter xi for CMei's model + @param D Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ + @param rvecs Output rotations for each calibration images + @param tvecs Output translation for each calibration images + @param flags The flags that control calibrate + @param criteria Termination criteria for optimization + @param idx Indices of images that pass initialization, which are really used in calibration. So the size of rvecs is the + same as idx.total(). + */ + CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size size, + InputOutputArray K, InputOutputArray xi, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags, TermCriteria criteria, OutputArray idx=noArray()); + + /** @brief Stereo calibration for omnidirectional camera model. It computes the intrinsic parameters for two + cameras and the extrinsic parameters between two cameras. The default depth of outputs is CV_64F. + + @param objectPoints Object points in world (pattern) coordinate. Its type is vector<vector<Vec3f> >. + It also can be vector of Mat with size 1xN/Nx1 and type CV_32FC3. Data with depth of 64_F is also acceptable. + @param imagePoints1 The corresponding image points of the first camera, with type vector<vector<Vec2f> >. + It must be the same size and the same type as objectPoints. + @param imagePoints2 The corresponding image points of the second camera, with type vector<vector<Vec2f> >. + It must be the same size and the same type as objectPoints. + @param imageSize1 Image size of calibration images of the first camera. + @param imageSize2 Image size of calibration images of the second camera. + @param K1 Output camera matrix for the first camera. + @param xi1 Output parameter xi of Mei's model for the first camera + @param D1 Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the first camera + @param K2 Output camera matrix for the first camera. + @param xi2 Output parameter xi of CMei's model for the second camera + @param D2 Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the second camera + @param rvec Output rotation between the first and second camera + @param tvec Output translation between the first and second camera + @param rvecsL Output rotation for each image of the first camera + @param tvecsL Output translation for each image of the first camera + @param flags The flags that control stereoCalibrate + @param criteria Termination criteria for optimization + @param idx Indices of image pairs that pass initialization, which are really used in calibration. So the size of rvecs is the + same as idx.total(). + @ + */ + CV_EXPORTS_W double stereoCalibrate(InputOutputArrayOfArrays objectPoints, InputOutputArrayOfArrays imagePoints1, InputOutputArrayOfArrays imagePoints2, + const Size& imageSize1, const Size& imageSize2, InputOutputArray K1, InputOutputArray xi1, InputOutputArray D1, InputOutputArray K2, InputOutputArray xi2, + InputOutputArray D2, OutputArray rvec, OutputArray tvec, OutputArrayOfArrays rvecsL, OutputArrayOfArrays tvecsL, int flags, TermCriteria criteria, OutputArray idx=noArray()); + + /** @brief Stereo rectification for omnidirectional camera model. It computes the rectification rotations for two cameras + + @param R Rotation between the first and second camera + @param T Translation between the first and second camera + @param R1 Output 3x3 rotation matrix for the first camera + @param R2 Output 3x3 rotation matrix for the second camera + */ + CV_EXPORTS_W void stereoRectify(InputArray R, InputArray T, OutputArray R1, OutputArray R2); + + /** @brief Stereo 3D reconstruction from a pair of images + + @param image1 The first input image + @param image2 The second input image + @param K1 Input camera matrix of the first camera + @param D1 Input distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the first camera + @param xi1 Input parameter xi for the first camera for CMei's model + @param K2 Input camera matrix of the second camera + @param D2 Input distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the second camera + @param xi2 Input parameter xi for the second camera for CMei's model + @param R Rotation between the first and second camera + @param T Translation between the first and second camera + @param flag Flag of rectification type, RECTIFY_PERSPECTIVE or RECTIFY_LONGLATI + @param numDisparities The parameter 'numDisparities' in StereoSGBM, see StereoSGBM for details. + @param SADWindowSize The parameter 'SADWindowSize' in StereoSGBM, see StereoSGBM for details. + @param disparity Disparity map generated by stereo matching + @param image1Rec Rectified image of the first image + @param image2Rec rectified image of the second image + @param newSize Image size of rectified image, see omnidir::undistortImage + @param Knew New camera matrix of rectified image, see omnidir::undistortImage + @param pointCloud Point cloud of 3D reconstruction, with type CV_64FC3 + @param pointType Point cloud type, it can be XYZRGB or XYZ + */ + CV_EXPORTS_W void stereoReconstruct(InputArray image1, InputArray image2, InputArray K1, InputArray D1, InputArray xi1, + InputArray K2, InputArray D2, InputArray xi2, InputArray R, InputArray T, int flag, int numDisparities, int SADWindowSize, + OutputArray disparity, OutputArray image1Rec, OutputArray image2Rec, const Size& newSize = Size(), InputArray Knew = cv::noArray(), + OutputArray pointCloud = cv::noArray(), int pointType = XYZRGB); + +namespace internal +{ + void initializeCalibration(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size size, OutputArrayOfArrays omAll, + OutputArrayOfArrays tAll, OutputArray K, double& xi, OutputArray idx = noArray()); + + void initializeStereoCalibration(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + const Size& size1, const Size& size2, OutputArray om, OutputArray T, OutputArrayOfArrays omL, OutputArrayOfArrays tL, OutputArray K1, OutputArray D1, OutputArray K2, OutputArray D2, + double &xi1, double &xi2, int flags, OutputArray idx); + + void computeJacobian(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray parameters, Mat& JTJ_inv, Mat& JTE, int flags, + double epsilon); + + void computeJacobianStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputArray parameters, Mat& JTJ_inv, Mat& JTE, int flags, double epsilon); + + void encodeParameters(InputArray K, InputArrayOfArrays omAll, InputArrayOfArrays tAll, InputArray distoaration, double xi, OutputArray parameters); + + void encodeParametersStereo(InputArray K1, InputArray K2, InputArray om, InputArray T, InputArrayOfArrays omL, InputArrayOfArrays tL, + InputArray D1, InputArray D2, double xi1, double xi2, OutputArray parameters); + + void decodeParameters(InputArray paramsters, OutputArray K, OutputArrayOfArrays omAll, OutputArrayOfArrays tAll, OutputArray distoration, double& xi); + + void decodeParametersStereo(InputArray parameters, OutputArray K1, OutputArray K2, OutputArray om, OutputArray T, OutputArrayOfArrays omL, + OutputArrayOfArrays tL, OutputArray D1, OutputArray D2, double& xi1, double& xi2); + + void estimateUncertainties(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray parameters, Mat& errors, Vec2d& std_error, double& rms, int flags); + + void estimateUncertaintiesStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputArray parameters, Mat& errors, + Vec2d& std_error, double& rms, int flags); + + double computeMeanReproErr(InputArrayOfArrays imagePoints, InputArrayOfArrays proImagePoints); + + double computeMeanReproErr(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray K, InputArray D, double xi, InputArrayOfArrays omAll, + InputArrayOfArrays tAll); + + double computeMeanReproErrStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputArray K1, InputArray K2, + InputArray D1, InputArray D2, double xi1, double xi2, InputArray om, InputArray T, InputArrayOfArrays omL, InputArrayOfArrays TL); + + void subMatrix(const Mat& src, Mat& dst, const std::vector<int>& cols, const std::vector<int>& rows); + + void flags2idx(int flags, std::vector<int>& idx, int n); + + void flags2idxStereo(int flags, std::vector<int>& idx, int n); + + void fillFixed(Mat&G, int flags, int n); + + void fillFixedStereo(Mat& G, int flags, int n); + + double findMedian(const Mat& row); + + Vec3d findMedian3(InputArray mat); + + void getInterset(InputArray idx1, InputArray idx2, OutputArray inter1, OutputArray inter2, OutputArray inter_ori); + + void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1, + Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2); + + //void JRodriguesMatlab(const Mat& src, Mat& dst); + + //void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB); +} // internal + +//! @} + +} // omnidir + +} //cv +#endif diff --git a/include/opencv2/ccalib/randpattern.hpp b/include/opencv2/ccalib/randpattern.hpp new file mode 100644 index 0000000..fb362bd --- /dev/null +++ b/include/opencv2/ccalib/randpattern.hpp @@ -0,0 +1,184 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, +// all rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_RANDOMPATTERN_HPP__ +#define __OPENCV_RANDOMPATTERN_HPP__ + +#include "opencv2/features2d.hpp" +#include "opencv2/highgui.hpp" + +namespace cv { namespace randpattern { + + +//! @addtogroup ccalib +//! @{ + +/** @brief Class for finding features points and corresponding 3D in world coordinate of +a "random" pattern, which can be to be used in calibration. It is useful when pattern is +partly occluded or only a part of pattern can be observed in multiple cameras calibration. +The pattern can be generated by RandomPatternGenerator class described in this file. + +Please refer to paper + B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System + Calibration Toolbox Using A Feature Descriptor-Based Calibration + Pattern", in IROS 2013. +*/ + +class CV_EXPORTS RandomPatternCornerFinder +{ +public: + + /* @brief Construct RandomPatternCornerFinder object + + @param patternWidth the real width of "random" pattern in a user defined unit. + @param patternHeight the real height of "random" pattern in a user defined unit. + @param nMiniMatch number of minimal matches, otherwise that image is abandoned + @depth depth of output objectPoints and imagePoints, set it to be CV_32F or CV_64F. + @showExtraction whether show feature extraction, 0 for no and 1 for yes. + @detector feature detector to detect feature points in pattern and images. + @descriptor feature descriptor. + @matcher feature matcher. + */ + RandomPatternCornerFinder(float patternWidth, float patternHeight, + int nminiMatch = 20, int depth = CV_32F, int verbose = 0, int showExtraction = 0, + Ptr<FeatureDetector> detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.005f), + Ptr<DescriptorExtractor> descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.005f), + Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-L1")); + + /* @brief Load pattern image and compute features for pattern + @param patternImage image for "random" pattern generated by RandomPatternGenerator, run it first. + */ + void loadPattern(const cv::Mat &patternImage); + + /* @brief Load pattern and features + @param patternImage image for "random" pattern generated by RandomPatternGenerator, run it first. + @param patternKeyPoints keyPoints created from a FeatureDetector. + @param patternDescriptors descriptors created from a DescriptorExtractor. + */ + void loadPattern(const cv::Mat &patternImage, const std::vector<cv::KeyPoint> &patternKeyPoints, const cv::Mat &patternDescriptors); + + /* @brief Compute matched object points and image points which are used for calibration + The objectPoints (3D) and imagePoints (2D) are stored inside the class. Run getObjectPoints() + and getImagePoints() to get them. + + @param inputImages vector of 8-bit grayscale images containing "random" pattern + that are used for calibration. + */ + void computeObjectImagePoints(std::vector<cv::Mat> inputImages); + + //void computeObjectImagePoints2(std::vector<cv::Mat> inputImages); + + /* @brief Compute object and image points for a single image. It returns a vector<Mat> that + the first element stores the imagePoints and the second one stores the objectPoints. + + @param inputImage single input image for calibration + */ + std::vector<cv::Mat> computeObjectImagePointsForSingle(cv::Mat inputImage); + + /* @brief Get object(3D) points + */ + const std::vector<cv::Mat> &getObjectPoints(); + + /* @brief and image(2D) points + */ + const std::vector<cv::Mat> &getImagePoints(); + +private: + + std::vector<cv::Mat> _objectPonits, _imagePoints; + float _patternWidth, _patternHeight; + cv::Size _patternImageSize; + int _nminiMatch; + int _depth; + int _verbose; + + Ptr<FeatureDetector> _detector; + Ptr<DescriptorExtractor> _descriptor; + Ptr<DescriptorMatcher> _matcher; + Mat _descriptorPattern; + std::vector<cv::KeyPoint> _keypointsPattern; + Mat _patternImage; + int _showExtraction; + + void keyPoints2MatchedLocation(const std::vector<cv::KeyPoint>& imageKeypoints, + const std::vector<cv::KeyPoint>& patternKeypoints, const std::vector<cv::DMatch> matchces, + cv::Mat& matchedImagelocation, cv::Mat& matchedPatternLocation); + void getFilteredLocation(cv::Mat& imageKeypoints, cv::Mat& patternKeypoints, const cv::Mat mask); + void getObjectImagePoints(const cv::Mat& imageKeypoints, const cv::Mat& patternKeypoints); + void crossCheckMatching( cv::Ptr<DescriptorMatcher>& descriptorMatcher, + const Mat& descriptors1, const Mat& descriptors2, + std::vector<DMatch>& filteredMatches12, int knn=1 ); + void drawCorrespondence(const Mat& image1, const std::vector<cv::KeyPoint> keypoint1, + const Mat& image2, const std::vector<cv::KeyPoint> keypoint2, const std::vector<cv::DMatch> matchces, + const Mat& mask1, const Mat& mask2, const int step); +}; + +/* @brief Class to generate "random" pattern image that are used for RandomPatternCornerFinder +Please refer to paper +B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System +Calibration Toolbox Using A Feature Descriptor-Based Calibration +Pattern", in IROS 2013. +*/ +class CV_EXPORTS RandomPatternGenerator +{ +public: + /* @brief Construct RandomPatternGenerator + + @param imageWidth image width of the generated pattern image + @param imageHeight image height of the generated pattern image + */ + RandomPatternGenerator(int imageWidth, int imageHeight); + + /* @brief Generate pattern + */ + void generatePattern(); + /* @brief Get pattern + */ + cv::Mat getPattern(); +private: + cv::Mat _pattern; + int _imageWidth, _imageHeight; +}; + +//! @} + +}} //namespace randpattern, cv +#endif \ No newline at end of file diff --git a/include/opencv2/core.hpp b/include/opencv2/core.hpp new file mode 100644 index 0000000..089c0db --- /dev/null +++ b/include/opencv2/core.hpp @@ -0,0 +1,3285 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Copyright (C) 2015, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_HPP +#define OPENCV_CORE_HPP + +#ifndef __cplusplus +# error core.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/version.hpp" +#include "opencv2/core/base.hpp" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/traits.hpp" +#include "opencv2/core/matx.hpp" +#include "opencv2/core/types.hpp" +#include "opencv2/core/mat.hpp" +#include "opencv2/core/persistence.hpp" + +/** +@defgroup core Core functionality +@{ + @defgroup core_basic Basic structures + @defgroup core_c C structures and operations + @{ + @defgroup core_c_glue Connections with C++ + @} + @defgroup core_array Operations on arrays + @defgroup core_xml XML/YAML Persistence + @defgroup core_cluster Clustering + @defgroup core_utils Utility and system functions and macros + @{ + @defgroup core_utils_sse SSE utilities + @defgroup core_utils_neon NEON utilities + @defgroup core_utils_softfloat Softfloat support + @defgroup core_utils_samples Utility functions for OpenCV samples + @} + @defgroup core_opengl OpenGL interoperability + @defgroup core_ipp Intel IPP Asynchronous C/C++ Converters + @defgroup core_optim Optimization Algorithms + @defgroup core_directx DirectX interoperability + @defgroup core_eigen Eigen support + @defgroup core_opencl OpenCL support + @defgroup core_va_intel Intel VA-API/OpenCL (CL-VA) interoperability + @defgroup core_hal Hardware Acceleration Layer + @{ + @defgroup core_hal_functions Functions + @defgroup core_hal_interface Interface + @defgroup core_hal_intrin Universal intrinsics + @{ + @defgroup core_hal_intrin_impl Private implementation helpers + @} + @} +@} + */ + +namespace cv { + +//! @addtogroup core_utils +//! @{ + +/*! @brief Class passed to an error. + +This class encapsulates all or almost all necessary +information about the error happened in the program. The exception is +usually constructed and thrown implicitly via CV_Error and CV_Error_ macros. +@see error + */ +class CV_EXPORTS Exception : public std::exception +{ +public: + /*! + Default constructor + */ + Exception(); + /*! + Full constructor. Normally the constructor is not called explicitly. + Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used. + */ + Exception(int _code, const String& _err, const String& _func, const String& _file, int _line); + virtual ~Exception() throw(); + + /*! + \return the error description and the context as a text string. + */ + virtual const char *what() const throw() CV_OVERRIDE; + void formatMessage(); + + String msg; ///< the formatted error message + + int code; ///< error code @see CVStatus + String err; ///< error description + String func; ///< function name. Available only when the compiler supports getting it + String file; ///< source file name where the error has occurred + int line; ///< line number in the source file where the error has occurred +}; + +/*! @brief Signals an error and raises the exception. + +By default the function prints information about the error to stderr, +then it either stops if cv::setBreakOnError() had been called before or raises the exception. +It is possible to alternate error processing by using #redirectError(). +@param exc the exception raisen. +@deprecated drop this version + */ +CV_EXPORTS void error( const Exception& exc ); + +enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently + SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted + //!< independently; this flag and the previous one are + //!< mutually exclusive. + SORT_ASCENDING = 0, //!< each matrix row is sorted in the ascending + //!< order. + SORT_DESCENDING = 16 //!< each matrix row is sorted in the + //!< descending order; this flag and the previous one are also + //!< mutually exclusive. + }; + +//! @} core_utils + +//! @addtogroup core +//! @{ + +//! Covariation flags +enum CovarFlags { + /** The output covariance matrix is calculated as: + \f[\texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...],\f] + The covariance matrix will be nsamples x nsamples. Such an unusual covariance matrix is used + for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for + face recognition). Eigenvalues of this "scrambled" matrix match the eigenvalues of the true + covariance matrix. The "true" eigenvectors can be easily calculated from the eigenvectors of + the "scrambled" covariance matrix. */ + COVAR_SCRAMBLED = 0, + /**The output covariance matrix is calculated as: + \f[\texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...] \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T,\f] + covar will be a square matrix of the same size as the total number of elements in each input + vector. One and only one of #COVAR_SCRAMBLED and #COVAR_NORMAL must be specified.*/ + COVAR_NORMAL = 1, + /** If the flag is specified, the function does not calculate mean from + the input vectors but, instead, uses the passed mean vector. This is useful if mean has been + pre-calculated or known in advance, or if the covariance matrix is calculated by parts. In + this case, mean is not a mean vector of the input sub-set of vectors but rather the mean + vector of the whole set.*/ + COVAR_USE_AVG = 2, + /** If the flag is specified, the covariance matrix is scaled. In the + "normal" mode, scale is 1./nsamples . In the "scrambled" mode, scale is the reciprocal of the + total number of elements in each input vector. By default (if the flag is not specified), the + covariance matrix is not scaled ( scale=1 ).*/ + COVAR_SCALE = 4, + /** If the flag is + specified, all the input vectors are stored as rows of the samples matrix. mean should be a + single-row vector in this case.*/ + COVAR_ROWS = 8, + /** If the flag is + specified, all the input vectors are stored as columns of the samples matrix. mean should be a + single-column vector in this case.*/ + COVAR_COLS = 16 +}; + +//! k-Means flags +enum KmeansFlags { + /** Select random initial centers in each attempt.*/ + KMEANS_RANDOM_CENTERS = 0, + /** Use kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007].*/ + KMEANS_PP_CENTERS = 2, + /** During the first (and possibly the only) attempt, use the + user-supplied labels instead of computing them from the initial centers. For the second and + further attempts, use the random or semi-random centers. Use one of KMEANS_\*_CENTERS flag + to specify the exact method.*/ + KMEANS_USE_INITIAL_LABELS = 1 +}; + +//! type of line +enum LineTypes { + FILLED = -1, + LINE_4 = 4, //!< 4-connected line + LINE_8 = 8, //!< 8-connected line + LINE_AA = 16 //!< antialiased line +}; + +//! Only a subset of Hershey fonts <https://en.wikipedia.org/wiki/Hershey_fonts> are supported +enum HersheyFonts { + FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font + FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font + FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX) + FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font + FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX) + FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX + FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font + FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX + FONT_ITALIC = 16 //!< flag for italic font +}; + +enum ReduceTypes { REDUCE_SUM = 0, //!< the output is the sum of all rows/columns of the matrix. + REDUCE_AVG = 1, //!< the output is the mean vector of all rows/columns of the matrix. + REDUCE_MAX = 2, //!< the output is the maximum (column/row-wise) of all rows/columns of the matrix. + REDUCE_MIN = 3 //!< the output is the minimum (column/row-wise) of all rows/columns of the matrix. + }; + + +/** @brief Swaps two matrices +*/ +CV_EXPORTS void swap(Mat& a, Mat& b); +/** @overload */ +CV_EXPORTS void swap( UMat& a, UMat& b ); + +//! @} core + +//! @addtogroup core_array +//! @{ + +/** @brief Computes the source location of an extrapolated pixel. + +The function computes and returns the coordinate of a donor pixel corresponding to the specified +extrapolated pixel when using the specified extrapolation border mode. For example, if you use +cv::BORDER_WRAP mode in the horizontal direction, cv::BORDER_REFLECT_101 in the vertical direction and +want to compute value of the "virtual" pixel Point(-5, 100) in a floating-point image img , it +looks like: +@code{.cpp} + float val = img.at<float>(borderInterpolate(100, img.rows, cv::BORDER_REFLECT_101), + borderInterpolate(-5, img.cols, cv::BORDER_WRAP)); +@endcode +Normally, the function is not called directly. It is used inside filtering functions and also in +copyMakeBorder. +@param p 0-based coordinate of the extrapolated pixel along one of the axes, likely \<0 or \>= len +@param len Length of the array along the corresponding axis. +@param borderType Border type, one of the #BorderTypes, except for #BORDER_TRANSPARENT and +#BORDER_ISOLATED . When borderType==#BORDER_CONSTANT , the function always returns -1, regardless +of p and len. + +@sa copyMakeBorder +*/ +CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType); + +/** @example samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +An example using copyMakeBorder function. +Check @ref tutorial_copyMakeBorder "the corresponding tutorial" for more details +*/ + +/** @brief Forms a border around an image. + +The function copies the source image into the middle of the destination image. The areas to the +left, to the right, above and below the copied source image will be filled with extrapolated +pixels. This is not what filtering functions based on it do (they extrapolate pixels on-fly), but +what other more complex functions, including your own, may do to simplify image boundary handling. + +The function supports the mode when src is already in the middle of dst . In this case, the +function does not copy src itself but simply constructs the border, for example: + +@code{.cpp} + // let border be the same in all directions + int border=2; + // constructs a larger image to fit both the image and the border + Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth()); + // select the middle part of it w/o copying data + Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows)); + // convert image from RGB to grayscale + cvtColor(rgb, gray, COLOR_RGB2GRAY); + // form a border in-place + copyMakeBorder(gray, gray_buf, border, border, + border, border, BORDER_REPLICATE); + // now do some custom filtering ... + ... +@endcode +@note When the source image is a part (ROI) of a bigger image, the function will try to use the +pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as +if src was not a ROI, use borderType | #BORDER_ISOLATED. + +@param src Source image. +@param dst Destination image of the same type as src and the size Size(src.cols+left+right, +src.rows+top+bottom) . +@param top +@param bottom +@param left +@param right Parameter specifying how many pixels in each direction from the source image rectangle +to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs +to be built. +@param borderType Border type. See borderInterpolate for details. +@param value Border value if borderType==BORDER_CONSTANT . + +@sa borderInterpolate +*/ +CV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst, + int top, int bottom, int left, int right, + int borderType, const Scalar& value = Scalar() ); + +/** @brief Calculates the per-element sum of two arrays or an array and a scalar. + +The function add calculates: +- Sum of two arrays when both input arrays have the same size and the same number of channels: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f] +- Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of +elements as `src1.channels()`: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f] +- Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of +elements as `src2.channels()`: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} + \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f] +where `I` is a multi-dimensional index of array elements. In case of multi-channel arrays, each +channel is processed independently. + +The first function in the list above can be replaced with matrix expressions: +@code{.cpp} + dst = src1 + src2; + dst += src1; // equivalent to add(dst, src1, dst); +@endcode +The input arrays and the output array can all have the same or different depths. For example, you +can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit +floating-point array. Depth of the output array is determined by the dtype parameter. In the second +and third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can +be set to the default -1. In this case, the output array will have the same depth as the input +array, be it src1, src2 or both. +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and number of channels as the input array(s); the +depth is defined by dtype or src1/src2. +@param mask optional operation mask - 8-bit single channel array, that specifies elements of the +output array to be changed. +@param dtype optional depth of the output array (see the discussion below). +@sa subtract, addWeighted, scaleAdd, Mat::convertTo +*/ +CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, + InputArray mask = noArray(), int dtype = -1); + +/** @brief Calculates the per-element difference between two arrays or array and a scalar. + +The function subtract calculates: +- Difference between two arrays, when both input arrays have the same size and the same number of +channels: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f] +- Difference between an array and a scalar, when src2 is constructed from Scalar or has the same +number of elements as `src1.channels()`: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f] +- Difference between a scalar and an array, when src1 is constructed from Scalar or has the same +number of elements as `src2.channels()`: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} - \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f] +- The reverse difference between a scalar and an array in the case of `SubRS`: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src2} - \texttt{src1}(I) ) \quad \texttt{if mask}(I) \ne0\f] +where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each +channel is processed independently. + +The first function in the list above can be replaced with matrix expressions: +@code{.cpp} + dst = src1 - src2; + dst -= src1; // equivalent to subtract(dst, src1, dst); +@endcode +The input arrays and the output array can all have the same or different depths. For example, you +can subtract to 8-bit unsigned arrays and store the difference in a 16-bit signed array. Depth of +the output array is determined by dtype parameter. In the second and third cases above, as well as +in the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this +case the output array will have the same depth as the input array, be it src1, src2 or both. +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array of the same size and the same number of channels as the input array. +@param mask optional operation mask; this is an 8-bit single channel array that specifies elements +of the output array to be changed. +@param dtype optional depth of the output array +@sa add, addWeighted, scaleAdd, Mat::convertTo + */ +CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, + InputArray mask = noArray(), int dtype = -1); + + +/** @brief Calculates the per-element scaled product of two arrays. + +The function multiply calculates the per-element product of two arrays: + +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f] + +There is also a @ref MatrixExpressions -friendly variant of the first function. See Mat::mul . + +For a not-per-element matrix product, see gemm . + +@note Saturation is not applied when the output array has the depth +CV_32S. You may even get result of an incorrect sign in the case of +overflow. +@param src1 first input array. +@param src2 second input array of the same size and the same type as src1. +@param dst output array of the same size and type as src1. +@param scale optional scale factor. +@param dtype optional depth of the output array +@sa add, subtract, divide, scaleAdd, addWeighted, accumulate, accumulateProduct, accumulateSquare, +Mat::convertTo +*/ +CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, + OutputArray dst, double scale = 1, int dtype = -1); + +/** @brief Performs per-element division of two arrays or a scalar by an array. + +The function cv::divide divides one array by another: +\f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f] +or a scalar by an array when there is no src1 : +\f[\texttt{dst(I) = saturate(scale/src2(I))}\f] + +When src2(I) is zero, dst(I) will also be zero. Different channels of +multi-channel arrays are processed independently. + +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array. +@param src2 second input array of the same size and type as src1. +@param scale scalar factor. +@param dst output array of the same size and type as src2. +@param dtype optional depth of the output array; if -1, dst will have depth src2.depth(), but in +case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth(). +@sa multiply, add, subtract +*/ +CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, + double scale = 1, int dtype = -1); + +/** @overload */ +CV_EXPORTS_W void divide(double scale, InputArray src2, + OutputArray dst, int dtype = -1); + +/** @brief Calculates the sum of a scaled array and another array. + +The function scaleAdd is one of the classical primitive linear algebra operations, known as DAXPY +or SAXPY in [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms). It calculates +the sum of a scaled array and another array: +\f[\texttt{dst} (I)= \texttt{scale} \cdot \texttt{src1} (I) + \texttt{src2} (I)\f] +The function can also be emulated with a matrix expression, for example: +@code{.cpp} + Mat A(3, 3, CV_64F); + ... + A.row(0) = A.row(1)*2 + A.row(2); +@endcode +@param src1 first input array. +@param alpha scale factor for the first array. +@param src2 second input array of the same size and type as src1. +@param dst output array of the same size and type as src1. +@sa add, addWeighted, subtract, Mat::dot, Mat::convertTo +*/ +CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst); + +/** @example samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +Check @ref tutorial_trackbar "the corresponding tutorial" for more details +*/ + +/** @brief Calculates the weighted sum of two arrays. + +The function addWeighted calculates the weighted sum of two arrays as follows: +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f] +where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each +channel is processed independently. +The function can be replaced with a matrix expression: +@code{.cpp} + dst = src1*alpha + src2*beta + gamma; +@endcode +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array. +@param alpha weight of the first array elements. +@param src2 second input array of the same size and channel number as src1. +@param beta weight of the second array elements. +@param gamma scalar added to each sum. +@param dst output array that has the same size and number of channels as the input arrays. +@param dtype optional depth of the output array; when both input arrays have the same depth, dtype +can be set to -1, which will be equivalent to src1.depth(). +@sa add, subtract, scaleAdd, Mat::convertTo +*/ +CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2, + double beta, double gamma, OutputArray dst, int dtype = -1); + +/** @brief Scales, calculates absolute values, and converts the result to 8-bit. + +On each element of the input array, the function convertScaleAbs +performs three operations sequentially: scaling, taking an absolute +value, conversion to an unsigned 8-bit type: +\f[\texttt{dst} (I)= \texttt{saturate\_cast<uchar>} (| \texttt{src} (I)* \texttt{alpha} + \texttt{beta} |)\f] +In case of multi-channel arrays, the function processes each channel +independently. When the output is not 8-bit, the operation can be +emulated by calling the Mat::convertTo method (or by using matrix +expressions) and then by calculating an absolute value of the result. +For example: +@code{.cpp} + Mat_<float> A(30,30); + randu(A, Scalar(-100), Scalar(100)); + Mat_<float> B = A*5 + 3; + B = abs(B); + // Mat_<float> B = abs(A*5+3) will also do the job, + // but it will allocate a temporary matrix +@endcode +@param src input array. +@param dst output array. +@param alpha optional scale factor. +@param beta optional delta added to the scaled values. +@sa Mat::convertTo, cv::abs(const Mat&) +*/ +CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst, + double alpha = 1, double beta = 0); + +/** @brief Converts an array to half precision floating number. + +This function converts FP32 (single precision floating point) from/to FP16 (half precision floating point). CV_16S format is used to represent FP16 data. +There are two use modes (src -> dst): CV_32F -> CV_16S and CV_16S -> CV_32F. The input array has to have type of CV_32F or +CV_16S to represent the bit depth. If the input array is neither of them, the function will raise an error. +The format of half precision floating point is defined in IEEE 754-2008. + +@param src input array. +@param dst output array. +*/ +CV_EXPORTS_W void convertFp16(InputArray src, OutputArray dst); + +/** @brief Performs a look-up table transform of an array. + +The function LUT fills the output array with values from the look-up table. Indices of the entries +are taken from the input array. That is, the function processes each element of src as follows: +\f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I) + d)}\f] +where +\f[d = \fork{0}{if \(\texttt{src}\) has depth \(\texttt{CV_8U}\)}{128}{if \(\texttt{src}\) has depth \(\texttt{CV_8S}\)}\f] +@param src input array of 8-bit elements. +@param lut look-up table of 256 elements; in case of multi-channel input array, the table should +either have a single channel (in this case the same table is used for all channels) or the same +number of channels as in the input array. +@param dst output array of the same size and number of channels as src, and the same depth as lut. +@sa convertScaleAbs, Mat::convertTo +*/ +CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst); + +/** @brief Calculates the sum of array elements. + +The function cv::sum calculates and returns the sum of array elements, +independently for each channel. +@param src input array that must have from 1 to 4 channels. +@sa countNonZero, mean, meanStdDev, norm, minMaxLoc, reduce +*/ +CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src); + +/** @brief Counts non-zero array elements. + +The function returns the number of non-zero elements in src : +\f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f] +@param src single-channel array. +@sa mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix +*/ +CV_EXPORTS_W int countNonZero( InputArray src ); + +/** @brief Returns the list of locations of non-zero pixels + +Given a binary matrix (likely returned from an operation such +as threshold(), compare(), >, ==, etc, return all of +the non-zero indices as a cv::Mat or std::vector<cv::Point> (x,y) +For example: +@code{.cpp} + cv::Mat binaryImage; // input, binary image + cv::Mat locations; // output, locations of non-zero pixels + cv::findNonZero(binaryImage, locations); + + // access pixel coordinates + Point pnt = locations.at<Point>(i); +@endcode +or +@code{.cpp} + cv::Mat binaryImage; // input, binary image + vector<Point> locations; // output, locations of non-zero pixels + cv::findNonZero(binaryImage, locations); + + // access pixel coordinates + Point pnt = locations[i]; +@endcode +@param src single-channel array (type CV_8UC1) +@param idx the output array, type of cv::Mat or std::vector<Point>, corresponding to non-zero indices in the input +*/ +CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx ); + +/** @brief Calculates an average (mean) of array elements. + +The function cv::mean calculates the mean value M of array elements, +independently for each channel, and return it: +\f[\begin{array}{l} N = \sum _{I: \; \texttt{mask} (I) \ne 0} 1 \\ M_c = \left ( \sum _{I: \; \texttt{mask} (I) \ne 0}{ \texttt{mtx} (I)_c} \right )/N \end{array}\f] +When all the mask elements are 0's, the function returns Scalar::all(0) +@param src input array that should have from 1 to 4 channels so that the result can be stored in +Scalar_ . +@param mask optional operation mask. +@sa countNonZero, meanStdDev, norm, minMaxLoc +*/ +CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray()); + +/** Calculates a mean and standard deviation of array elements. + +The function cv::meanStdDev calculates the mean and the standard deviation M +of array elements independently for each channel and returns it via the +output parameters: +\f[\begin{array}{l} N = \sum _{I, \texttt{mask} (I) \ne 0} 1 \\ \texttt{mean} _c = \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c = \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c - \texttt{mean} _c \right )^2}{N}} \end{array}\f] +When all the mask elements are 0's, the function returns +mean=stddev=Scalar::all(0). +@note The calculated standard deviation is only the diagonal of the +complete normalized covariance matrix. If the full matrix is needed, you +can reshape the multi-channel array M x N to the single-channel array +M\*N x mtx.channels() (only possible when the matrix is continuous) and +then pass the matrix to calcCovarMatrix . +@param src input array that should have from 1 to 4 channels so that the results can be stored in +Scalar_ 's. +@param mean output parameter: calculated mean value. +@param stddev output parameter: calculated standard deviation. +@param mask optional operation mask. +@sa countNonZero, mean, norm, minMaxLoc, calcCovarMatrix +*/ +CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev, + InputArray mask=noArray()); + +/** @brief Calculates the absolute norm of an array. + +This version of #norm calculates the absolute norm of src1. The type of norm to calculate is specified using #NormTypes. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ + \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ + \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ + \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ + \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. +\f} +The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$. +It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$. +![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png) + +When the mask parameter is specified and it is not empty, the norm is + +If normType is not specified, #NORM_L2 is used. +calculated only over the region specified by the mask. + +Multi-channel input arrays are treated as single-channel arrays, that is, +the results for all channels are combined. + +Hamming norms can only be calculated with CV_8U depth arrays. + +@param src1 first input array. +@param normType type of the norm (see #NormTypes). +@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type. +*/ +CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray()); + +/** @brief Calculates an absolute difference norm or a relative difference norm. + +This version of cv::norm calculates the absolute difference norm +or the relative difference norm of arrays src1 and src2. +The type of norm to calculate is specified using #NormTypes. + +@param src1 first input array. +@param src2 second input array of the same size and the same type as src1. +@param normType type of the norm (see #NormTypes). +@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type. +*/ +CV_EXPORTS_W double norm(InputArray src1, InputArray src2, + int normType = NORM_L2, InputArray mask = noArray()); +/** @overload +@param src first input array. +@param normType type of the norm (see #NormTypes). +*/ +CV_EXPORTS double norm( const SparseMat& src, int normType ); + +/** @brief Computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric. + +This function calculates the Peak Signal-to-Noise Ratio (PSNR) image quality metric in decibels (dB), between two input arrays src1 and src2. Arrays must have depth CV_8U. + +The PSNR is calculated as follows: + +\f[ +\texttt{PSNR} = 10 \cdot \log_{10}{\left( \frac{R^2}{MSE} \right) } +\f] + +where R is the maximum integer value of depth CV_8U (255) and MSE is the mean squared error between the two arrays. + +@param src1 first input array. +@param src2 second input array of the same size as src1. + + */ +CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2); + +/** @brief naive nearest neighbor finder + +see http://en.wikipedia.org/wiki/Nearest_neighbor_search +@todo document + */ +CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2, + OutputArray dist, int dtype, OutputArray nidx, + int normType = NORM_L2, int K = 0, + InputArray mask = noArray(), int update = 0, + bool crosscheck = false); + +/** @brief Normalizes the norm or value range of an array. + +The function cv::normalize normalizes scale and shift the input array elements so that +\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f] +(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that +\f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f] + +when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be +normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this +sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or +min-max but modify the whole array, you can use norm and Mat::convertTo. + +In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, +the range transformation for sparse matrices is not allowed since it can shift the zero level. + +Possible usage with some positive example data: +@code{.cpp} + vector<double> positiveData = { 2.0, 8.0, 10.0 }; + vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax; + + // Norm to probability (total count) + // sum(numbers) = 20.0 + // 2.0 0.1 (2.0/20.0) + // 8.0 0.4 (8.0/20.0) + // 10.0 0.5 (10.0/20.0) + normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1); + + // Norm to unit vector: ||positiveData|| = 1.0 + // 2.0 0.15 + // 8.0 0.62 + // 10.0 0.77 + normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2); + + // Norm to max element + // 2.0 0.2 (2.0/10.0) + // 8.0 0.8 (8.0/10.0) + // 10.0 1.0 (10.0/10.0) + normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF); + + // Norm to range [0.0;1.0] + // 2.0 0.0 (shift to left border) + // 8.0 0.75 (6.0/8.0) + // 10.0 1.0 (shift to right border) + normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX); +@endcode + +@param src input array. +@param dst output array of the same size as src . +@param alpha norm value to normalize to or the lower range boundary in case of the range +normalization. +@param beta upper range boundary in case of the range normalization; it is not used for the norm +normalization. +@param norm_type normalization type (see cv::NormTypes). +@param dtype when negative, the output array has the same type as src; otherwise, it has the same +number of channels as src and the depth =CV_MAT_DEPTH(dtype). +@param mask optional operation mask. +@sa norm, Mat::convertTo, SparseMat::convertTo +*/ +CV_EXPORTS_W void normalize( InputArray src, InputOutputArray dst, double alpha = 1, double beta = 0, + int norm_type = NORM_L2, int dtype = -1, InputArray mask = noArray()); + +/** @overload +@param src input array. +@param dst output array of the same size as src . +@param alpha norm value to normalize to or the lower range boundary in case of the range +normalization. +@param normType normalization type (see cv::NormTypes). +*/ +CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType ); + +/** @brief Finds the global minimum and maximum in an array. + +The function cv::minMaxLoc finds the minimum and maximum element values and their positions. The +extremums are searched across the whole array or, if mask is not an empty array, in the specified +array region. + +The function do not work with multi-channel arrays. If you need to find minimum or maximum +elements across all the channels, use Mat::reshape first to reinterpret the array as +single-channel. Or you may extract the particular channel using either extractImageCOI , or +mixChannels , or split . +@param src input single-channel array. +@param minVal pointer to the returned minimum value; NULL is used if not required. +@param maxVal pointer to the returned maximum value; NULL is used if not required. +@param minLoc pointer to the returned minimum location (in 2D case); NULL is used if not required. +@param maxLoc pointer to the returned maximum location (in 2D case); NULL is used if not required. +@param mask optional mask used to select a sub-array. +@sa max, min, compare, inRange, extractImageCOI, mixChannels, split, Mat::reshape +*/ +CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal, + CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0, + CV_OUT Point* maxLoc = 0, InputArray mask = noArray()); + + +/** @brief Finds the global minimum and maximum in an array + +The function cv::minMaxIdx finds the minimum and maximum element values and their positions. The +extremums are searched across the whole array or, if mask is not an empty array, in the specified +array region. The function does not work with multi-channel arrays. If you need to find minimum or +maximum elements across all the channels, use Mat::reshape first to reinterpret the array as +single-channel. Or you may extract the particular channel using either extractImageCOI , or +mixChannels , or split . In case of a sparse matrix, the minimum is found among non-zero elements +only. +@note When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is +a single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2 +dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be +(i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be +(0,j1)/(0,j2)). +@param src input single-channel array. +@param minVal pointer to the returned minimum value; NULL is used if not required. +@param maxVal pointer to the returned maximum value; NULL is used if not required. +@param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required; +Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element +in each dimension are stored there sequentially. +@param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required. +@param mask specified array region +*/ +CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal = 0, + int* minIdx = 0, int* maxIdx = 0, InputArray mask = noArray()); + +/** @overload +@param a input single-channel array. +@param minVal pointer to the returned minimum value; NULL is used if not required. +@param maxVal pointer to the returned maximum value; NULL is used if not required. +@param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required; +Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element +in each dimension are stored there sequentially. +@param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required. +*/ +CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal, + double* maxVal, int* minIdx = 0, int* maxIdx = 0); + +/** @brief Reduces a matrix to a vector. + +The function #reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of +1D vectors and performing the specified operation on the vectors until a single row/column is +obtained. For example, the function can be used to compute horizontal and vertical projections of a +raster image. In case of #REDUCE_MAX and #REDUCE_MIN , the output image should have the same type as the source one. +In case of #REDUCE_SUM and #REDUCE_AVG , the output may have a larger element bit-depth to preserve accuracy. +And multi-channel arrays are also supported in these two reduction modes. + +The following code demonstrates its usage for a single channel matrix. +@snippet snippets/core_reduce.cpp example + +And the following code demonstrates its usage for a two-channel matrix. +@snippet snippets/core_reduce.cpp example2 + +@param src input 2D matrix. +@param dst output vector. Its size and type is defined by dim and dtype parameters. +@param dim dimension index along which the matrix is reduced. 0 means that the matrix is reduced to +a single row. 1 means that the matrix is reduced to a single column. +@param rtype reduction operation that could be one of #ReduceTypes +@param dtype when negative, the output vector will have the same type as the input matrix, +otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()). +@sa repeat +*/ +CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype = -1); + +/** @brief Creates one multi-channel array out of several single-channel ones. + +The function cv::merge merges several arrays to make a single multi-channel array. That is, each +element of the output array will be a concatenation of the elements of the input arrays, where +elements of i-th input array are treated as mv[i].channels()-element vectors. + +The function cv::split does the reverse operation. If you need to shuffle channels in some other +advanced way, use cv::mixChannels. + +The following example shows how to merge 3 single channel matrices into a single 3-channel matrix. +@snippet snippets/core_merge.cpp example + +@param mv input array of matrices to be merged; all the matrices in mv must have the same +size and the same depth. +@param count number of input matrices when mv is a plain C array; it must be greater than zero. +@param dst output array of the same size and the same depth as mv[0]; The number of channels will +be equal to the parameter count. +@sa mixChannels, split, Mat::reshape +*/ +CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst); + +/** @overload +@param mv input vector of matrices to be merged; all the matrices in mv must have the same +size and the same depth. +@param dst output array of the same size and the same depth as mv[0]; The number of channels will +be the total number of channels in the matrix array. + */ +CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst); + +/** @brief Divides a multi-channel array into several single-channel arrays. + +The function cv::split splits a multi-channel array into separate single-channel arrays: +\f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f] +If you need to extract a single channel or do some other sophisticated channel permutation, use +mixChannels . + +The following example demonstrates how to split a 3-channel matrix into 3 single channel matrices. +@snippet snippets/core_split.cpp example + +@param src input multi-channel array. +@param mvbegin output array; the number of arrays must match src.channels(); the arrays themselves are +reallocated, if needed. +@sa merge, mixChannels, cvtColor +*/ +CV_EXPORTS void split(const Mat& src, Mat* mvbegin); + +/** @overload +@param m input multi-channel array. +@param mv output vector of arrays; the arrays themselves are reallocated, if needed. +*/ +CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv); + +/** @brief Copies specified channels from input arrays to the specified channels of +output arrays. + +The function cv::mixChannels provides an advanced mechanism for shuffling image channels. + +cv::split,cv::merge,cv::extractChannel,cv::insertChannel and some forms of cv::cvtColor are partial cases of cv::mixChannels. + +In the example below, the code splits a 4-channel BGRA image into a 3-channel BGR (with B and R +channels swapped) and a separate alpha-channel image: +@code{.cpp} + Mat bgra( 100, 100, CV_8UC4, Scalar(255,0,0,255) ); + Mat bgr( bgra.rows, bgra.cols, CV_8UC3 ); + Mat alpha( bgra.rows, bgra.cols, CV_8UC1 ); + + // forming an array of matrices is a quite efficient operation, + // because the matrix data is not copied, only the headers + Mat out[] = { bgr, alpha }; + // bgra[0] -> bgr[2], bgra[1] -> bgr[1], + // bgra[2] -> bgr[0], bgra[3] -> alpha[0] + int from_to[] = { 0,2, 1,1, 2,0, 3,3 }; + mixChannels( &bgra, 1, out, 2, from_to, 4 ); +@endcode +@note Unlike many other new-style C++ functions in OpenCV (see the introduction section and +Mat::create ), cv::mixChannels requires the output arrays to be pre-allocated before calling the +function. +@param src input array or vector of matrices; all of the matrices must have the same size and the +same depth. +@param nsrcs number of matrices in `src`. +@param dst output array or vector of matrices; all the matrices **must be allocated**; their size and +depth must be the same as in `src[0]`. +@param ndsts number of matrices in `dst`. +@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is +a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in +dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to +src[0].channels()-1, the second input image channels are indexed from src[0].channels() to +src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image +channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is +filled with zero . +@param npairs number of index pairs in `fromTo`. +@sa split, merge, extractChannel, insertChannel, cvtColor +*/ +CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, + const int* fromTo, size_t npairs); + +/** @overload +@param src input array or vector of matrices; all of the matrices must have the same size and the +same depth. +@param dst output array or vector of matrices; all the matrices **must be allocated**; their size and +depth must be the same as in src[0]. +@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is +a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in +dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to +src[0].channels()-1, the second input image channels are indexed from src[0].channels() to +src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image +channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is +filled with zero . +@param npairs number of index pairs in fromTo. +*/ +CV_EXPORTS void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst, + const int* fromTo, size_t npairs); + +/** @overload +@param src input array or vector of matrices; all of the matrices must have the same size and the +same depth. +@param dst output array or vector of matrices; all the matrices **must be allocated**; their size and +depth must be the same as in src[0]. +@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is +a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in +dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to +src[0].channels()-1, the second input image channels are indexed from src[0].channels() to +src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image +channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is +filled with zero . +*/ +CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst, + const std::vector<int>& fromTo); + +/** @brief Extracts a single channel from src (coi is 0-based index) +@param src input array +@param dst output array +@param coi index of channel to extract +@sa mixChannels, split +*/ +CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi); + +/** @brief Inserts a single channel to dst (coi is 0-based index) +@param src input array +@param dst output array +@param coi index of channel for insertion +@sa mixChannels, merge +*/ +CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi); + +/** @brief Flips a 2D array around vertical, horizontal, or both axes. + +The function cv::flip flips the array in one of three different ways (row +and column indices are 0-based): +\f[\texttt{dst} _{ij} = +\left\{ +\begin{array}{l l} +\texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\ +\texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\ +\texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\ +\end{array} +\right.\f] +The example scenarios of using the function are the following: +* Vertical flipping of the image (flipCode == 0) to switch between + top-left and bottom-left image origin. This is a typical operation + in video processing on Microsoft Windows\* OS. +* Horizontal flipping of the image with the subsequent horizontal + shift and absolute difference calculation to check for a + vertical-axis symmetry (flipCode \> 0). +* Simultaneous horizontal and vertical flipping of the image with + the subsequent shift and absolute difference calculation to check + for a central symmetry (flipCode \< 0). +* Reversing the order of point arrays (flipCode \> 0 or + flipCode == 0). +@param src input array. +@param dst output array of the same size and type as src. +@param flipCode a flag to specify how to flip the array; 0 means +flipping around the x-axis and positive value (for example, 1) means +flipping around y-axis. Negative value (for example, -1) means flipping +around both axes. +@sa transpose , repeat , completeSymm +*/ +CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode); + +enum RotateFlags { + ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise + ROTATE_180 = 1, //!<Rotate 180 degrees clockwise + ROTATE_90_COUNTERCLOCKWISE = 2, //!<Rotate 270 degrees clockwise +}; +/** @brief Rotates a 2D array in multiples of 90 degrees. +The function cv::rotate rotates the array in one of three different ways: +* Rotate by 90 degrees clockwise (rotateCode = ROTATE_90_CLOCKWISE). +* Rotate by 180 degrees clockwise (rotateCode = ROTATE_180). +* Rotate by 270 degrees clockwise (rotateCode = ROTATE_90_COUNTERCLOCKWISE). +@param src input array. +@param dst output array of the same type as src. The size is the same with ROTATE_180, +and the rows and cols are switched for ROTATE_90_CLOCKWISE and ROTATE_90_COUNTERCLOCKWISE. +@param rotateCode an enum to specify how to rotate the array; see the enum #RotateFlags +@sa transpose , repeat , completeSymm, flip, RotateFlags +*/ +CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode); + +/** @brief Fills the output array with repeated copies of the input array. + +The function cv::repeat duplicates the input array one or more times along each of the two axes: +\f[\texttt{dst} _{ij}= \texttt{src} _{i\mod src.rows, \; j\mod src.cols }\f] +The second variant of the function is more convenient to use with @ref MatrixExpressions. +@param src input array to replicate. +@param ny Flag to specify how many times the `src` is repeated along the +vertical axis. +@param nx Flag to specify how many times the `src` is repeated along the +horizontal axis. +@param dst output array of the same type as `src`. +@sa cv::reduce +*/ +CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst); + +/** @overload +@param src input array to replicate. +@param ny Flag to specify how many times the `src` is repeated along the +vertical axis. +@param nx Flag to specify how many times the `src` is repeated along the +horizontal axis. + */ +CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx); + +/** @brief Applies horizontal concatenation to given matrices. + +The function horizontally concatenates two or more cv::Mat matrices (with the same number of rows). +@code{.cpp} + cv::Mat matArray[] = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)), + cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)), + cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::hconcat( matArray, 3, out ); + //out: + //[1, 2, 3; + // 1, 2, 3; + // 1, 2, 3; + // 1, 2, 3] +@endcode +@param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth. +@param nsrc number of matrices in src. +@param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src. +@sa cv::vconcat(const Mat*, size_t, OutputArray), @sa cv::vconcat(InputArrayOfArrays, OutputArray) and @sa cv::vconcat(InputArray, InputArray, OutputArray) +*/ +CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst); +/** @overload + @code{.cpp} + cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 4, + 2, 5, + 3, 6); + cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 7, 10, + 8, 11, + 9, 12); + + cv::Mat C; + cv::hconcat(A, B, C); + //C: + //[1, 4, 7, 10; + // 2, 5, 8, 11; + // 3, 6, 9, 12] + @endcode + @param src1 first input array to be considered for horizontal concatenation. + @param src2 second input array to be considered for horizontal concatenation. + @param dst output array. It has the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2. + */ +CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst); +/** @overload + @code{.cpp} + std::vector<cv::Mat> matrices = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)), + cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)), + cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::hconcat( matrices, out ); + //out: + //[1, 2, 3; + // 1, 2, 3; + // 1, 2, 3; + // 1, 2, 3] + @endcode + @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth. + @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src. +same depth. + */ +CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst); + +/** @brief Applies vertical concatenation to given matrices. + +The function vertically concatenates two or more cv::Mat matrices (with the same number of cols). +@code{.cpp} + cv::Mat matArray[] = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::vconcat( matArray, 3, out ); + //out: + //[1, 1, 1, 1; + // 2, 2, 2, 2; + // 3, 3, 3, 3] +@endcode +@param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth. +@param nsrc number of matrices in src. +@param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src. +@sa cv::hconcat(const Mat*, size_t, OutputArray), @sa cv::hconcat(InputArrayOfArrays, OutputArray) and @sa cv::hconcat(InputArray, InputArray, OutputArray) +*/ +CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst); +/** @overload + @code{.cpp} + cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 7, + 2, 8, + 3, 9); + cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 4, 10, + 5, 11, + 6, 12); + + cv::Mat C; + cv::vconcat(A, B, C); + //C: + //[1, 7; + // 2, 8; + // 3, 9; + // 4, 10; + // 5, 11; + // 6, 12] + @endcode + @param src1 first input array to be considered for vertical concatenation. + @param src2 second input array to be considered for vertical concatenation. + @param dst output array. It has the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2. + */ +CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst); +/** @overload + @code{.cpp} + std::vector<cv::Mat> matrices = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::vconcat( matrices, out ); + //out: + //[1, 1, 1, 1; + // 2, 2, 2, 2; + // 3, 3, 3, 3] + @endcode + @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth + @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src. +same depth. + */ +CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst); + +/** @brief computes bitwise conjunction of the two arrays (dst = src1 & src2) +Calculates the per-element bit-wise conjunction of two arrays or an +array and a scalar. + +The function cv::bitwise_and calculates the per-element bit-wise logical conjunction for: +* Two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +* An array and a scalar when src2 is constructed from Scalar or has + the same number of elements as `src1.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} \quad \texttt{if mask} (I) \ne0\f] +* A scalar and an array when src1 is constructed from Scalar or has + the same number of elements as `src2.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +In case of floating-point arrays, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel arrays, each channel is processed +independently. In the second and third cases above, the scalar is first +converted to the array type. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as the input +arrays. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, + OutputArray dst, InputArray mask = noArray()); + +/** @brief Calculates the per-element bit-wise disjunction of two arrays or an +array and a scalar. + +The function cv::bitwise_or calculates the per-element bit-wise logical disjunction for: +* Two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +* An array and a scalar when src2 is constructed from Scalar or has + the same number of elements as `src1.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} \quad \texttt{if mask} (I) \ne0\f] +* A scalar and an array when src1 is constructed from Scalar or has + the same number of elements as `src2.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +In case of floating-point arrays, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel arrays, each channel is processed +independently. In the second and third cases above, the scalar is first +converted to the array type. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as the input +arrays. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, + OutputArray dst, InputArray mask = noArray()); + +/** @brief Calculates the per-element bit-wise "exclusive or" operation on two +arrays or an array and a scalar. + +The function cv::bitwise_xor calculates the per-element bit-wise logical "exclusive-or" +operation for: +* Two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +* An array and a scalar when src2 is constructed from Scalar or has + the same number of elements as `src1.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} \quad \texttt{if mask} (I) \ne0\f] +* A scalar and an array when src1 is constructed from Scalar or has + the same number of elements as `src2.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +In case of floating-point arrays, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel arrays, each channel is processed +independently. In the 2nd and 3rd cases above, the scalar is first +converted to the array type. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as the input +arrays. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, + OutputArray dst, InputArray mask = noArray()); + +/** @brief Inverts every bit of an array. + +The function cv::bitwise_not calculates per-element bit-wise inversion of the input +array: +\f[\texttt{dst} (I) = \neg \texttt{src} (I)\f] +In case of a floating-point input array, its machine-specific bit +representation (usually IEEE754-compliant) is used for the operation. In +case of multi-channel arrays, each channel is processed independently. +@param src input array. +@param dst output array that has the same size and type as the input +array. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, + InputArray mask = noArray()); + +/** @brief Calculates the per-element absolute difference between two arrays or between an array and a scalar. + +The function cv::absdiff calculates: +* Absolute difference between two arrays when they have the same + size and type: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f] +* Absolute difference between an array and a scalar when the second + array is constructed from Scalar or has as many elements as the + number of channels in `src1`: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2} |)\f] +* Absolute difference between a scalar and an array when the first + array is constructed from Scalar or has as many elements as the + number of channels in `src2`: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1} - \texttt{src2}(I) |)\f] + where I is a multi-dimensional index of array elements. In case of + multi-channel arrays, each channel is processed independently. +@note Saturation is not applied when the arrays have the depth CV_32S. +You may even get a negative value in the case of overflow. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as input arrays. +@sa cv::abs(const Mat&) +*/ +CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst); + +/** @brief Checks if array elements lie between the elements of two other arrays. + +The function checks the range as follows: +- For every element of a single-channel input array: + \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0\f] +- For two-channel arrays: + \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0 \land \texttt{lowerb} (I)_1 \leq \texttt{src} (I)_1 \leq \texttt{upperb} (I)_1\f] +- and so forth. + +That is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the +specified 1D, 2D, 3D, ... box and 0 otherwise. + +When the lower and/or upper boundary parameters are scalars, the indexes +(I) at lowerb and upperb in the above formulas should be omitted. +@param src first input array. +@param lowerb inclusive lower boundary array or a scalar. +@param upperb inclusive upper boundary array or a scalar. +@param dst output array of the same size as src and CV_8U type. +*/ +CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb, + InputArray upperb, OutputArray dst); + +/** @brief Performs the per-element comparison of two arrays or an array and scalar value. + +The function compares: +* Elements of two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \,\texttt{cmpop}\, \texttt{src2} (I)\f] +* Elements of src1 with a scalar src2 when src2 is constructed from + Scalar or has a single element: + \f[\texttt{dst} (I) = \texttt{src1}(I) \,\texttt{cmpop}\, \texttt{src2}\f] +* src1 with elements of src2 when src1 is constructed from Scalar or + has a single element: + \f[\texttt{dst} (I) = \texttt{src1} \,\texttt{cmpop}\, \texttt{src2} (I)\f] +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: +@code{.cpp} + Mat dst1 = src1 >= src2; + Mat dst2 = src1 < 8; + ... +@endcode +@param src1 first input array or a scalar; when it is an array, it must have a single channel. +@param src2 second input array or a scalar; when it is an array, it must have a single channel. +@param dst output array of type ref CV_8U that has the same size and the same number of channels as + the input arrays. +@param cmpop a flag, that specifies correspondence between the arrays (cv::CmpTypes) +@sa checkRange, min, max, threshold +*/ +CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop); + +/** @brief Calculates per-element minimum of two arrays or an array and a scalar. + +The function cv::min calculates the per-element minimum of two arrays: +\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f] +or array and a scalar: +\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{value} )\f] +@param src1 first input array. +@param src2 second input array of the same size and type as src1. +@param dst output array of the same size and type as src1. +@sa max, compare, inRange, minMaxLoc +*/ +CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst); + +/** @brief Calculates per-element maximum of two arrays or an array and a scalar. + +The function cv::max calculates the per-element maximum of two arrays: +\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f] +or array and a scalar: +\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{value} )\f] +@param src1 first input array. +@param src2 second input array of the same size and type as src1 . +@param dst output array of the same size and type as src1. +@sa min, compare, inRange, minMaxLoc, @ref MatrixExpressions +*/ +CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst); + +/** @brief Calculates a square root of array elements. + +The function cv::sqrt calculates a square root of each input array element. +In case of multi-channel arrays, each channel is processed +independently. The accuracy is approximately the same as of the built-in +std::sqrt . +@param src input floating-point array. +@param dst output array of the same size and type as src. +*/ +CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst); + +/** @brief Raises every array element to a power. + +The function cv::pow raises every element of the input array to power : +\f[\texttt{dst} (I) = \fork{\texttt{src}(I)^{power}}{if \(\texttt{power}\) is integer}{|\texttt{src}(I)|^{power}}{otherwise}\f] + +So, for a non-integer power exponent, the absolute values of input array +elements are used. However, it is possible to get true values for +negative values using some extra operations. In the example below, +computing the 5th root of array src shows: +@code{.cpp} + Mat mask = src < 0; + pow(src, 1./5, dst); + subtract(Scalar::all(0), dst, dst, mask); +@endcode +For some values of power, such as integer values, 0.5 and -0.5, +specialized faster algorithms are used. + +Special values (NaN, Inf) are not handled. +@param src input array. +@param power exponent of power. +@param dst output array of the same size and type as src. +@sa sqrt, exp, log, cartToPolar, polarToCart +*/ +CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst); + +/** @brief Calculates the exponent of every array element. + +The function cv::exp calculates the exponent of every element of the input +array: +\f[\texttt{dst} [I] = e^{ src(I) }\f] + +The maximum relative error is about 7e-6 for single-precision input and +less than 1e-10 for double-precision input. Currently, the function +converts denormalized values to zeros on output. Special values (NaN, +Inf) are not handled. +@param src input array. +@param dst output array of the same size and type as src. +@sa log , cartToPolar , polarToCart , phase , pow , sqrt , magnitude +*/ +CV_EXPORTS_W void exp(InputArray src, OutputArray dst); + +/** @brief Calculates the natural logarithm of every array element. + +The function cv::log calculates the natural logarithm of every element of the input array: +\f[\texttt{dst} (I) = \log (\texttt{src}(I)) \f] + +Output on zero, negative and special (NaN, Inf) values is undefined. + +@param src input array. +@param dst output array of the same size and type as src . +@sa exp, cartToPolar, polarToCart, phase, pow, sqrt, magnitude +*/ +CV_EXPORTS_W void log(InputArray src, OutputArray dst); + +/** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle. + +The function cv::polarToCart calculates the Cartesian coordinates of each 2D +vector represented by the corresponding elements of magnitude and angle: +\f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f] + +The relative accuracy of the estimated coordinates is about 1e-6. +@param magnitude input floating-point array of magnitudes of 2D vectors; +it can be an empty matrix (=Mat()), in this case, the function assumes +that all the magnitudes are =1; if it is not empty, it must have the +same size and type as angle. +@param angle input floating-point array of angles of 2D vectors. +@param x output array of x-coordinates of 2D vectors; it has the same +size and type as angle. +@param y output array of y-coordinates of 2D vectors; it has the same +size and type as angle. +@param angleInDegrees when true, the input angles are measured in +degrees, otherwise, they are measured in radians. +@sa cartToPolar, magnitude, phase, exp, log, pow, sqrt +*/ +CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle, + OutputArray x, OutputArray y, bool angleInDegrees = false); + +/** @brief Calculates the magnitude and angle of 2D vectors. + +The function cv::cartToPolar calculates either the magnitude, angle, or both +for every 2D vector (x(I),y(I)): +\f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f] + +The angles are calculated with accuracy about 0.3 degrees. For the point +(0,0), the angle is set to 0. +@param x array of x-coordinates; this must be a single-precision or +double-precision floating-point array. +@param y array of y-coordinates, that must have the same size and same type as x. +@param magnitude output array of magnitudes of the same size and type as x. +@param angle output array of angles that has the same size and type as +x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees). +@param angleInDegrees a flag, indicating whether the angles are measured +in radians (which is by default), or in degrees. +@sa Sobel, Scharr +*/ +CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y, + OutputArray magnitude, OutputArray angle, + bool angleInDegrees = false); + +/** @brief Calculates the rotation angle of 2D vectors. + +The function cv::phase calculates the rotation angle of each 2D vector that +is formed from the corresponding elements of x and y : +\f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f] + +The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 , +the corresponding angle(I) is set to 0. +@param x input floating-point array of x-coordinates of 2D vectors. +@param y input array of y-coordinates of 2D vectors; it must have the +same size and the same type as x. +@param angle output array of vector angles; it has the same size and +same type as x . +@param angleInDegrees when true, the function calculates the angle in +degrees, otherwise, they are measured in radians. +*/ +CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle, + bool angleInDegrees = false); + +/** @brief Calculates the magnitude of 2D vectors. + +The function cv::magnitude calculates the magnitude of 2D vectors formed +from the corresponding elements of x and y arrays: +\f[\texttt{dst} (I) = \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}\f] +@param x floating-point array of x-coordinates of the vectors. +@param y floating-point array of y-coordinates of the vectors; it must +have the same size as x. +@param magnitude output array of the same size and type as x. +@sa cartToPolar, polarToCart, phase, sqrt +*/ +CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude); + +/** @brief Checks every element of an input array for invalid values. + +The function cv::checkRange checks that every array element is neither NaN nor infinite. When minVal \> +-DBL_MAX and maxVal \< DBL_MAX, the function also checks that each value is between minVal and +maxVal. In case of multi-channel arrays, each channel is processed independently. If some values +are out of range, position of the first outlier is stored in pos (when pos != NULL). Then, the +function either returns false (when quiet=true) or throws an exception. +@param a input array. +@param quiet a flag, indicating whether the functions quietly return false when the array elements +are out of range or they throw an exception. +@param pos optional output parameter, when not NULL, must be a pointer to array of src.dims +elements. +@param minVal inclusive lower boundary of valid values range. +@param maxVal exclusive upper boundary of valid values range. +*/ +CV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0, + double minVal = -DBL_MAX, double maxVal = DBL_MAX); + +/** @brief converts NaN's to the given number +*/ +CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0); + +/** @brief Performs generalized matrix multiplication. + +The function cv::gemm performs generalized matrix multiplication similar to the +gemm functions in BLAS level 3. For example, +`gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)` +corresponds to +\f[\texttt{dst} = \texttt{alpha} \cdot \texttt{src1} ^T \cdot \texttt{src2} + \texttt{beta} \cdot \texttt{src3} ^T\f] + +In case of complex (two-channel) data, performed a complex matrix +multiplication. + +The function can be replaced with a matrix expression. For example, the +above call can be replaced with: +@code{.cpp} + dst = alpha*src1.t()*src2 + beta*src3.t(); +@endcode +@param src1 first multiplied input matrix that could be real(CV_32FC1, +CV_64FC1) or complex(CV_32FC2, CV_64FC2). +@param src2 second multiplied input matrix of the same type as src1. +@param alpha weight of the matrix product. +@param src3 third optional delta matrix added to the matrix product; it +should have the same type as src1 and src2. +@param beta weight of src3. +@param dst output matrix; it has the proper size and the same type as +input matrices. +@param flags operation flags (cv::GemmFlags) +@sa mulTransposed , transform +*/ +CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, + InputArray src3, double beta, OutputArray dst, int flags = 0); + +/** @brief Calculates the product of a matrix and its transposition. + +The function cv::mulTransposed calculates the product of src and its +transposition: +\f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} )^T ( \texttt{src} - \texttt{delta} )\f] +if aTa=true , and +\f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} ) ( \texttt{src} - \texttt{delta} )^T\f] +otherwise. The function is used to calculate the covariance matrix. With +zero delta, it can be used as a faster substitute for general matrix +product A\*B when B=A' +@param src input single-channel matrix. Note that unlike gemm, the +function can multiply not only floating-point matrices. +@param dst output square matrix. +@param aTa Flag specifying the multiplication ordering. See the +description below. +@param delta Optional delta matrix subtracted from src before the +multiplication. When the matrix is empty ( delta=noArray() ), it is +assumed to be zero, that is, nothing is subtracted. If it has the same +size as src , it is simply subtracted. Otherwise, it is "repeated" (see +repeat ) to cover the full src and then subtracted. Type of the delta +matrix, when it is not empty, must be the same as the type of created +output matrix. See the dtype parameter description below. +@param scale Optional scale factor for the matrix product. +@param dtype Optional type of the output matrix. When it is negative, +the output matrix will have the same type as src . Otherwise, it will be +type=CV_MAT_DEPTH(dtype) that should be either CV_32F or CV_64F . +@sa calcCovarMatrix, gemm, repeat, reduce +*/ +CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa, + InputArray delta = noArray(), + double scale = 1, int dtype = -1 ); + +/** @brief Transposes a matrix. + +The function cv::transpose transposes the matrix src : +\f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f] +@note No complex conjugation is done in case of a complex matrix. It +should be done separately if needed. +@param src input array. +@param dst output array of the same type as src. +*/ +CV_EXPORTS_W void transpose(InputArray src, OutputArray dst); + +/** @brief Performs the matrix transformation of every array element. + +The function cv::transform performs the matrix transformation of every +element of the array src and stores the results in dst : +\f[\texttt{dst} (I) = \texttt{m} \cdot \texttt{src} (I)\f] +(when m.cols=src.channels() ), or +\f[\texttt{dst} (I) = \texttt{m} \cdot [ \texttt{src} (I); 1]\f] +(when m.cols=src.channels()+1 ) + +Every element of the N -channel array src is interpreted as N -element +vector that is transformed using the M x N or M x (N+1) matrix m to +M-element vector - the corresponding element of the output array dst . + +The function may be used for geometrical transformation of +N -dimensional points, arbitrary linear color space transformation (such +as various kinds of RGB to YUV transforms), shuffling the image +channels, and so forth. +@param src input array that must have as many channels (1 to 4) as +m.cols or m.cols-1. +@param dst output array of the same size and depth as src; it has as +many channels as m.rows. +@param m transformation 2x2 or 2x3 floating-point matrix. +@sa perspectiveTransform, getAffineTransform, estimateAffine2D, warpAffine, warpPerspective +*/ +CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m ); + +/** @brief Performs the perspective matrix transformation of vectors. + +The function cv::perspectiveTransform transforms every element of src by +treating it as a 2D or 3D vector, in the following way: +\f[(x, y, z) \rightarrow (x'/w, y'/w, z'/w)\f] +where +\f[(x', y', z', w') = \texttt{mat} \cdot \begin{bmatrix} x & y & z & 1 \end{bmatrix}\f] +and +\f[w = \fork{w'}{if \(w' \ne 0\)}{\infty}{otherwise}\f] + +Here a 3D vector transformation is shown. In case of a 2D vector +transformation, the z component is omitted. + +@note The function transforms a sparse set of 2D or 3D vectors. If you +want to transform an image using perspective transformation, use +warpPerspective . If you have an inverse problem, that is, you want to +compute the most probable perspective transformation out of several +pairs of corresponding points, you can use getPerspectiveTransform or +findHomography . +@param src input two-channel or three-channel floating-point array; each +element is a 2D/3D vector to be transformed. +@param dst output array of the same size and type as src. +@param m 3x3 or 4x4 floating-point transformation matrix. +@sa transform, warpPerspective, getPerspectiveTransform, findHomography +*/ +CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m ); + +/** @brief Copies the lower or the upper half of a square matrix to its another half. + +The function cv::completeSymm copies the lower or the upper half of a square matrix to +its another half. The matrix diagonal remains unchanged: + - \f$\texttt{m}_{ij}=\texttt{m}_{ji}\f$ for \f$i > j\f$ if + lowerToUpper=false + - \f$\texttt{m}_{ij}=\texttt{m}_{ji}\f$ for \f$i < j\f$ if + lowerToUpper=true + +@param m input-output floating-point square matrix. +@param lowerToUpper operation flag; if true, the lower half is copied to +the upper half. Otherwise, the upper half is copied to the lower half. +@sa flip, transpose +*/ +CV_EXPORTS_W void completeSymm(InputOutputArray m, bool lowerToUpper = false); + +/** @brief Initializes a scaled identity matrix. + +The function cv::setIdentity initializes a scaled identity matrix: +\f[\texttt{mtx} (i,j)= \fork{\texttt{value}}{ if \(i=j\)}{0}{otherwise}\f] + +The function can also be emulated using the matrix initializers and the +matrix expressions: +@code + Mat A = Mat::eye(4, 3, CV_32F)*5; + // A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]] +@endcode +@param mtx matrix to initialize (not necessarily square). +@param s value to assign to diagonal elements. +@sa Mat::zeros, Mat::ones, Mat::setTo, Mat::operator= +*/ +CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1)); + +/** @brief Returns the determinant of a square floating-point matrix. + +The function cv::determinant calculates and returns the determinant of the +specified matrix. For small matrices ( mtx.cols=mtx.rows\<=3 ), the +direct method is used. For larger matrices, the function uses LU +factorization with partial pivoting. + +For symmetric positively-determined matrices, it is also possible to use +eigen decomposition to calculate the determinant. +@param mtx input matrix that must have CV_32FC1 or CV_64FC1 type and +square size. +@sa trace, invert, solve, eigen, @ref MatrixExpressions +*/ +CV_EXPORTS_W double determinant(InputArray mtx); + +/** @brief Returns the trace of a matrix. + +The function cv::trace returns the sum of the diagonal elements of the +matrix mtx . +\f[\mathrm{tr} ( \texttt{mtx} ) = \sum _i \texttt{mtx} (i,i)\f] +@param mtx input matrix. +*/ +CV_EXPORTS_W Scalar trace(InputArray mtx); + +/** @brief Finds the inverse or pseudo-inverse of a matrix. + +The function cv::invert inverts the matrix src and stores the result in dst +. When the matrix src is singular or non-square, the function calculates +the pseudo-inverse matrix (the dst matrix) so that norm(src\*dst - I) is +minimal, where I is an identity matrix. + +In case of the #DECOMP_LU method, the function returns non-zero value if +the inverse has been successfully calculated and 0 if src is singular. + +In case of the #DECOMP_SVD method, the function returns the inverse +condition number of src (the ratio of the smallest singular value to the +largest singular value) and 0 if src is singular. The SVD method +calculates a pseudo-inverse matrix if src is singular. + +Similarly to #DECOMP_LU, the method #DECOMP_CHOLESKY works only with +non-singular square matrices that should also be symmetrical and +positively defined. In this case, the function stores the inverted +matrix in dst and returns non-zero. Otherwise, it returns 0. + +@param src input floating-point M x N matrix. +@param dst output matrix of N x M size and the same type as src. +@param flags inversion method (cv::DecompTypes) +@sa solve, SVD +*/ +CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_LU); + +/** @brief Solves one or more linear systems or least-squares problems. + +The function cv::solve solves a linear system or least-squares problem (the +latter is possible with SVD or QR methods, or by specifying the flag +#DECOMP_NORMAL ): +\f[\texttt{dst} = \arg \min _X \| \texttt{src1} \cdot \texttt{X} - \texttt{src2} \|\f] + +If #DECOMP_LU or #DECOMP_CHOLESKY method is used, the function returns 1 +if src1 (or \f$\texttt{src1}^T\texttt{src1}\f$ ) is non-singular. Otherwise, +it returns 0. In the latter case, dst is not valid. Other methods find a +pseudo-solution in case of a singular left-hand side part. + +@note If you want to find a unity-norm solution of an under-defined +singular system \f$\texttt{src1}\cdot\texttt{dst}=0\f$ , the function solve +will not do the work. Use SVD::solveZ instead. + +@param src1 input matrix on the left-hand side of the system. +@param src2 input matrix on the right-hand side of the system. +@param dst output solution. +@param flags solution (matrix inversion) method (#DecompTypes) +@sa invert, SVD, eigen +*/ +CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, + OutputArray dst, int flags = DECOMP_LU); + +/** @brief Sorts each row or each column of a matrix. + +The function cv::sort sorts each matrix row or each matrix column in +ascending or descending order. So you should pass two operation flags to +get desired behaviour. If you want to sort matrix rows or columns +lexicographically, you can use STL std::sort generic function with the +proper comparison predicate. + +@param src input single-channel array. +@param dst output array of the same size and type as src. +@param flags operation flags, a combination of #SortFlags +@sa sortIdx, randShuffle +*/ +CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags); + +/** @brief Sorts each row or each column of a matrix. + +The function cv::sortIdx sorts each matrix row or each matrix column in the +ascending or descending order. So you should pass two operation flags to +get desired behaviour. Instead of reordering the elements themselves, it +stores the indices of sorted elements in the output array. For example: +@code + Mat A = Mat::eye(3,3,CV_32F), B; + sortIdx(A, B, SORT_EVERY_ROW + SORT_ASCENDING); + // B will probably contain + // (because of equal elements in A some permutations are possible): + // [[1, 2, 0], [0, 2, 1], [0, 1, 2]] +@endcode +@param src input single-channel array. +@param dst output integer array of the same size as src. +@param flags operation flags that could be a combination of cv::SortFlags +@sa sort, randShuffle +*/ +CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags); + +/** @brief Finds the real roots of a cubic equation. + +The function solveCubic finds the real roots of a cubic equation: +- if coeffs is a 4-element vector: +\f[\texttt{coeffs} [0] x^3 + \texttt{coeffs} [1] x^2 + \texttt{coeffs} [2] x + \texttt{coeffs} [3] = 0\f] +- if coeffs is a 3-element vector: +\f[x^3 + \texttt{coeffs} [0] x^2 + \texttt{coeffs} [1] x + \texttt{coeffs} [2] = 0\f] + +The roots are stored in the roots array. +@param coeffs equation coefficients, an array of 3 or 4 elements. +@param roots output array of real roots that has 1 or 3 elements. +@return number of real roots. It can be 0, 1 or 2. +*/ +CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots); + +/** @brief Finds the real or complex roots of a polynomial equation. + +The function cv::solvePoly finds real and complex roots of a polynomial equation: +\f[\texttt{coeffs} [n] x^{n} + \texttt{coeffs} [n-1] x^{n-1} + ... + \texttt{coeffs} [1] x + \texttt{coeffs} [0] = 0\f] +@param coeffs array of polynomial coefficients. +@param roots output (complex) array of roots. +@param maxIters maximum number of iterations the algorithm does. +*/ +CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters = 300); + +/** @brief Calculates eigenvalues and eigenvectors of a symmetric matrix. + +The function cv::eigen calculates just eigenvalues, or eigenvalues and eigenvectors of the symmetric +matrix src: +@code + src*eigenvectors.row(i).t() = eigenvalues.at<srcType>(i)*eigenvectors.row(i).t() +@endcode + +@note Use cv::eigenNonSymmetric for calculation of real eigenvalues and eigenvectors of non-symmetric matrix. + +@param src input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical +(src ^T^ == src). +@param eigenvalues output vector of eigenvalues of the same type as src; the eigenvalues are stored +in the descending order. +@param eigenvectors output matrix of eigenvectors; it has the same size and type as src; the +eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding +eigenvalues. +@sa eigenNonSymmetric, completeSymm , PCA +*/ +CV_EXPORTS_W bool eigen(InputArray src, OutputArray eigenvalues, + OutputArray eigenvectors = noArray()); + +/** @brief Calculates eigenvalues and eigenvectors of a non-symmetric matrix (real eigenvalues only). + +@note Assumes real eigenvalues. + +The function calculates eigenvalues and eigenvectors (optional) of the square matrix src: +@code + src*eigenvectors.row(i).t() = eigenvalues.at<srcType>(i)*eigenvectors.row(i).t() +@endcode + +@param src input matrix (CV_32FC1 or CV_64FC1 type). +@param eigenvalues output vector of eigenvalues (type is the same type as src). +@param eigenvectors output matrix of eigenvectors (type is the same type as src). The eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding eigenvalues. +@sa eigen +*/ +CV_EXPORTS_W void eigenNonSymmetric(InputArray src, OutputArray eigenvalues, + OutputArray eigenvectors); + +/** @brief Calculates the covariance matrix of a set of vectors. + +The function cv::calcCovarMatrix calculates the covariance matrix and, optionally, the mean vector of +the set of input vectors. +@param samples samples stored as separate matrices +@param nsamples number of samples +@param covar output covariance matrix of the type ctype and square size. +@param mean input or output (depending on the flags) array as the average value of the input vectors. +@param flags operation flags as a combination of #CovarFlags +@param ctype type of the matrixl; it equals 'CV_64F' by default. +@sa PCA, mulTransposed, Mahalanobis +@todo InputArrayOfArrays +*/ +CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean, + int flags, int ctype = CV_64F); + +/** @overload +@note use #COVAR_ROWS or #COVAR_COLS flag +@param samples samples stored as rows/columns of a single matrix. +@param covar output covariance matrix of the type ctype and square size. +@param mean input or output (depending on the flags) array as the average value of the input vectors. +@param flags operation flags as a combination of #CovarFlags +@param ctype type of the matrixl; it equals 'CV_64F' by default. +*/ +CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar, + InputOutputArray mean, int flags, int ctype = CV_64F); + +/** wrap PCA::operator() */ +CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, int maxComponents = 0); + +/** wrap PCA::operator() and add eigenvalues output parameter */ +CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + int maxComponents = 0); + +/** wrap PCA::operator() */ +CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, double retainedVariance); + +/** wrap PCA::operator() and add eigenvalues output parameter */ +CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + double retainedVariance); + +/** wrap PCA::project */ +CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean, + InputArray eigenvectors, OutputArray result); + +/** wrap PCA::backProject */ +CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean, + InputArray eigenvectors, OutputArray result); + +/** wrap SVD::compute */ +CV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags = 0 ); + +/** wrap SVD::backSubst */ +CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt, + InputArray rhs, OutputArray dst ); + +/** @brief Calculates the Mahalanobis distance between two vectors. + +The function cv::Mahalanobis calculates and returns the weighted distance between two vectors: +\f[d( \texttt{vec1} , \texttt{vec2} )= \sqrt{\sum_{i,j}{\texttt{icovar(i,j)}\cdot(\texttt{vec1}(I)-\texttt{vec2}(I))\cdot(\texttt{vec1(j)}-\texttt{vec2(j)})} }\f] +The covariance matrix may be calculated using the #calcCovarMatrix function and then inverted using +the invert function (preferably using the #DECOMP_SVD method, as the most accurate). +@param v1 first 1D input vector. +@param v2 second 1D input vector. +@param icovar inverse covariance matrix. +*/ +CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar); + +/** @brief Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array. + +The function cv::dft performs one of the following: +- Forward the Fourier transform of a 1D vector of N elements: + \f[Y = F^{(N)} \cdot X,\f] + where \f$F^{(N)}_{jk}=\exp(-2\pi i j k/N)\f$ and \f$i=\sqrt{-1}\f$ +- Inverse the Fourier transform of a 1D vector of N elements: + \f[\begin{array}{l} X'= \left (F^{(N)} \right )^{-1} \cdot Y = \left (F^{(N)} \right )^* \cdot y \\ X = (1/N) \cdot X, \end{array}\f] + where \f$F^*=\left(\textrm{Re}(F^{(N)})-\textrm{Im}(F^{(N)})\right)^T\f$ +- Forward the 2D Fourier transform of a M x N matrix: + \f[Y = F^{(M)} \cdot X \cdot F^{(N)}\f] +- Inverse the 2D Fourier transform of a M x N matrix: + \f[\begin{array}{l} X'= \left (F^{(M)} \right )^* \cdot Y \cdot \left (F^{(N)} \right )^* \\ X = \frac{1}{M \cdot N} \cdot X' \end{array}\f] + +In case of real (single-channel) data, the output spectrum of the forward Fourier transform or input +spectrum of the inverse Fourier transform can be represented in a packed format called *CCS* +(complex-conjugate-symmetrical). It was borrowed from IPL (Intel\* Image Processing Library). Here +is how 2D *CCS* spectrum looks: +\f[\begin{bmatrix} Re Y_{0,0} & Re Y_{0,1} & Im Y_{0,1} & Re Y_{0,2} & Im Y_{0,2} & \cdots & Re Y_{0,N/2-1} & Im Y_{0,N/2-1} & Re Y_{0,N/2} \\ Re Y_{1,0} & Re Y_{1,1} & Im Y_{1,1} & Re Y_{1,2} & Im Y_{1,2} & \cdots & Re Y_{1,N/2-1} & Im Y_{1,N/2-1} & Re Y_{1,N/2} \\ Im Y_{1,0} & Re Y_{2,1} & Im Y_{2,1} & Re Y_{2,2} & Im Y_{2,2} & \cdots & Re Y_{2,N/2-1} & Im Y_{2,N/2-1} & Im Y_{1,N/2} \\ \hdotsfor{9} \\ Re Y_{M/2-1,0} & Re Y_{M-3,1} & Im Y_{M-3,1} & \hdotsfor{3} & Re Y_{M-3,N/2-1} & Im Y_{M-3,N/2-1}& Re Y_{M/2-1,N/2} \\ Im Y_{M/2-1,0} & Re Y_{M-2,1} & Im Y_{M-2,1} & \hdotsfor{3} & Re Y_{M-2,N/2-1} & Im Y_{M-2,N/2-1}& Im Y_{M/2-1,N/2} \\ Re Y_{M/2,0} & Re Y_{M-1,1} & Im Y_{M-1,1} & \hdotsfor{3} & Re Y_{M-1,N/2-1} & Im Y_{M-1,N/2-1}& Re Y_{M/2,N/2} \end{bmatrix}\f] + +In case of 1D transform of a real vector, the output looks like the first row of the matrix above. + +So, the function chooses an operation mode depending on the flags and size of the input array: +- If #DFT_ROWS is set or the input array has a single row or single column, the function + performs a 1D forward or inverse transform of each row of a matrix when #DFT_ROWS is set. + Otherwise, it performs a 2D transform. +- If the input array is real and #DFT_INVERSE is not set, the function performs a forward 1D or + 2D transform: + - When #DFT_COMPLEX_OUTPUT is set, the output is a complex matrix of the same size as + input. + - When #DFT_COMPLEX_OUTPUT is not set, the output is a real matrix of the same size as + input. In case of 2D transform, it uses the packed format as shown above. In case of a + single 1D transform, it looks like the first row of the matrix above. In case of + multiple 1D transforms (when using the #DFT_ROWS flag), each row of the output matrix + looks like the first row of the matrix above. +- If the input array is complex and either #DFT_INVERSE or #DFT_REAL_OUTPUT are not set, the + output is a complex array of the same size as input. The function performs a forward or + inverse 1D or 2D transform of the whole input array or each row of the input array + independently, depending on the flags DFT_INVERSE and DFT_ROWS. +- When #DFT_INVERSE is set and the input array is real, or it is complex but #DFT_REAL_OUTPUT + is set, the output is a real array of the same size as input. The function performs a 1D or 2D + inverse transformation of the whole input array or each individual row, depending on the flags + #DFT_INVERSE and #DFT_ROWS. + +If #DFT_SCALE is set, the scaling is done after the transformation. + +Unlike dct , the function supports arrays of arbitrary size. But only those arrays are processed +efficiently, whose sizes can be factorized in a product of small prime numbers (2, 3, and 5 in the +current implementation). Such an efficient DFT size can be calculated using the getOptimalDFTSize +method. + +The sample below illustrates how to calculate a DFT-based convolution of two 2D real arrays: +@code + void convolveDFT(InputArray A, InputArray B, OutputArray C) + { + // reallocate the output array if needed + C.create(abs(A.rows - B.rows)+1, abs(A.cols - B.cols)+1, A.type()); + Size dftSize; + // calculate the size of DFT transform + dftSize.width = getOptimalDFTSize(A.cols + B.cols - 1); + dftSize.height = getOptimalDFTSize(A.rows + B.rows - 1); + + // allocate temporary buffers and initialize them with 0's + Mat tempA(dftSize, A.type(), Scalar::all(0)); + Mat tempB(dftSize, B.type(), Scalar::all(0)); + + // copy A and B to the top-left corners of tempA and tempB, respectively + Mat roiA(tempA, Rect(0,0,A.cols,A.rows)); + A.copyTo(roiA); + Mat roiB(tempB, Rect(0,0,B.cols,B.rows)); + B.copyTo(roiB); + + // now transform the padded A & B in-place; + // use "nonzeroRows" hint for faster processing + dft(tempA, tempA, 0, A.rows); + dft(tempB, tempB, 0, B.rows); + + // multiply the spectrums; + // the function handles packed spectrum representations well + mulSpectrums(tempA, tempB, tempA); + + // transform the product back from the frequency domain. + // Even though all the result rows will be non-zero, + // you need only the first C.rows of them, and thus you + // pass nonzeroRows == C.rows + dft(tempA, tempA, DFT_INVERSE + DFT_SCALE, C.rows); + + // now copy the result back to C. + tempA(Rect(0, 0, C.cols, C.rows)).copyTo(C); + + // all the temporary buffers will be deallocated automatically + } +@endcode +To optimize this sample, consider the following approaches: +- Since nonzeroRows != 0 is passed to the forward transform calls and since A and B are copied to + the top-left corners of tempA and tempB, respectively, it is not necessary to clear the whole + tempA and tempB. It is only necessary to clear the tempA.cols - A.cols ( tempB.cols - B.cols) + rightmost columns of the matrices. +- This DFT-based convolution does not have to be applied to the whole big arrays, especially if B + is significantly smaller than A or vice versa. Instead, you can calculate convolution by parts. + To do this, you need to split the output array C into multiple tiles. For each tile, estimate + which parts of A and B are required to calculate convolution in this tile. If the tiles in C are + too small, the speed will decrease a lot because of repeated work. In the ultimate case, when + each tile in C is a single pixel, the algorithm becomes equivalent to the naive convolution + algorithm. If the tiles are too big, the temporary arrays tempA and tempB become too big and + there is also a slowdown because of bad cache locality. So, there is an optimal tile size + somewhere in the middle. +- If different tiles in C can be calculated in parallel and, thus, the convolution is done by + parts, the loop can be threaded. + +All of the above improvements have been implemented in #matchTemplate and #filter2D . Therefore, by +using them, you can get the performance even better than with the above theoretically optimal +implementation. Though, those two functions actually calculate cross-correlation, not convolution, +so you need to "flip" the second convolution operand B vertically and horizontally using flip . +@note +- An example using the discrete fourier transform can be found at + opencv_source_code/samples/cpp/dft.cpp +- (Python) An example using the dft functionality to perform Wiener deconvolution can be found + at opencv_source/samples/python/deconvolution.py +- (Python) An example rearranging the quadrants of a Fourier image can be found at + opencv_source/samples/python/dft.py +@param src input array that could be real or complex. +@param dst output array whose size and type depends on the flags . +@param flags transformation flags, representing a combination of the #DftFlags +@param nonzeroRows when the parameter is not zero, the function assumes that only the first +nonzeroRows rows of the input array (#DFT_INVERSE is not set) or only the first nonzeroRows of the +output array (#DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the +rows more efficiently and save some time; this technique is very useful for calculating array +cross-correlation or convolution using DFT. +@sa dct , getOptimalDFTSize , mulSpectrums, filter2D , matchTemplate , flip , cartToPolar , +magnitude , phase +*/ +CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0); + +/** @brief Calculates the inverse Discrete Fourier Transform of a 1D or 2D array. + +idft(src, dst, flags) is equivalent to dft(src, dst, flags | #DFT_INVERSE) . +@note None of dft and idft scales the result by default. So, you should pass #DFT_SCALE to one of +dft or idft explicitly to make these transforms mutually inverse. +@sa dft, dct, idct, mulSpectrums, getOptimalDFTSize +@param src input floating-point real or complex array. +@param dst output array whose size and type depend on the flags. +@param flags operation flags (see dft and #DftFlags). +@param nonzeroRows number of dst rows to process; the rest of the rows have undefined content (see +the convolution sample in dft description. +*/ +CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0); + +/** @brief Performs a forward or inverse discrete Cosine transform of 1D or 2D array. + +The function cv::dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D +floating-point array: +- Forward Cosine transform of a 1D vector of N elements: + \f[Y = C^{(N)} \cdot X\f] + where + \f[C^{(N)}_{jk}= \sqrt{\alpha_j/N} \cos \left ( \frac{\pi(2k+1)j}{2N} \right )\f] + and + \f$\alpha_0=1\f$, \f$\alpha_j=2\f$ for *j \> 0*. +- Inverse Cosine transform of a 1D vector of N elements: + \f[X = \left (C^{(N)} \right )^{-1} \cdot Y = \left (C^{(N)} \right )^T \cdot Y\f] + (since \f$C^{(N)}\f$ is an orthogonal matrix, \f$C^{(N)} \cdot \left(C^{(N)}\right)^T = I\f$ ) +- Forward 2D Cosine transform of M x N matrix: + \f[Y = C^{(N)} \cdot X \cdot \left (C^{(N)} \right )^T\f] +- Inverse 2D Cosine transform of M x N matrix: + \f[X = \left (C^{(N)} \right )^T \cdot X \cdot C^{(N)}\f] + +The function chooses the mode of operation by looking at the flags and size of the input array: +- If (flags & #DCT_INVERSE) == 0 , the function does a forward 1D or 2D transform. Otherwise, it + is an inverse 1D or 2D transform. +- If (flags & #DCT_ROWS) != 0 , the function performs a 1D transform of each row. +- If the array is a single column or a single row, the function performs a 1D transform. +- If none of the above is true, the function performs a 2D transform. + +@note Currently dct supports even-size arrays (2, 4, 6 ...). For data analysis and approximation, you +can pad the array when necessary. +Also, the function performance depends very much, and not monotonically, on the array size (see +getOptimalDFTSize ). In the current implementation DCT of a vector of size N is calculated via DFT +of a vector of size N/2 . Thus, the optimal DCT size N1 \>= N can be calculated as: +@code + size_t getOptimalDCTSize(size_t N) { return 2*getOptimalDFTSize((N+1)/2); } + N1 = getOptimalDCTSize(N); +@endcode +@param src input floating-point array. +@param dst output array of the same size and type as src . +@param flags transformation flags as a combination of cv::DftFlags (DCT_*) +@sa dft , getOptimalDFTSize , idct +*/ +CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags = 0); + +/** @brief Calculates the inverse Discrete Cosine Transform of a 1D or 2D array. + +idct(src, dst, flags) is equivalent to dct(src, dst, flags | DCT_INVERSE). +@param src input floating-point single-channel array. +@param dst output array of the same size and type as src. +@param flags operation flags. +@sa dct, dft, idft, getOptimalDFTSize +*/ +CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0); + +/** @brief Performs the per-element multiplication of two Fourier spectrums. + +The function cv::mulSpectrums performs the per-element multiplication of the two CCS-packed or complex +matrices that are results of a real or complex Fourier transform. + +The function, together with dft and idft , may be used to calculate convolution (pass conjB=false ) +or correlation (pass conjB=true ) of two arrays rapidly. When the arrays are complex, they are +simply multiplied (per element) with an optional conjugation of the second-array elements. When the +arrays are real, they are assumed to be CCS-packed (see dft for details). +@param a first input array. +@param b second input array of the same size and type as src1 . +@param c output array of the same size and type as src1 . +@param flags operation flags; currently, the only supported flag is cv::DFT_ROWS, which indicates that +each row of src1 and src2 is an independent 1D Fourier spectrum. If you do not want to use this flag, then simply add a `0` as value. +@param conjB optional flag that conjugates the second input array before the multiplication (true) +or not (false). +*/ +CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c, + int flags, bool conjB = false); + +/** @brief Returns the optimal DFT size for a given vector size. + +DFT performance is not a monotonic function of a vector size. Therefore, when you calculate +convolution of two arrays or perform the spectral analysis of an array, it usually makes sense to +pad the input data with zeros to get a bit larger array that can be transformed much faster than the +original one. Arrays whose size is a power-of-two (2, 4, 8, 16, 32, ...) are the fastest to process. +Though, the arrays whose size is a product of 2's, 3's, and 5's (for example, 300 = 5\*5\*3\*2\*2) +are also processed quite efficiently. + +The function cv::getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize +so that the DFT of a vector of size N can be processed efficiently. In the current implementation N += 2 ^p^ \* 3 ^q^ \* 5 ^r^ for some integer p, q, r. + +The function returns a negative number if vecsize is too large (very close to INT_MAX ). + +While the function cannot be used directly to estimate the optimal vector size for DCT transform +(since the current DCT implementation supports only even-size vectors), it can be easily processed +as getOptimalDFTSize((vecsize+1)/2)\*2. +@param vecsize vector size. +@sa dft , dct , idft , idct , mulSpectrums +*/ +CV_EXPORTS_W int getOptimalDFTSize(int vecsize); + +/** @brief Returns the default random number generator. + +The function cv::theRNG returns the default random number generator. For each thread, there is a +separate random number generator, so you can use the function safely in multi-thread environments. +If you just need to get a single random number using this generator or initialize an array, you can +use randu or randn instead. But if you are going to generate many random numbers inside a loop, it +is much faster to use this function to retrieve the generator and then use RNG::operator _Tp() . +@sa RNG, randu, randn +*/ +CV_EXPORTS RNG& theRNG(); + +/** @brief Sets state of default random number generator. + +The function cv::setRNGSeed sets state of default random number generator to custom value. +@param seed new state for default random number generator +@sa RNG, randu, randn +*/ +CV_EXPORTS_W void setRNGSeed(int seed); + +/** @brief Generates a single uniformly-distributed random number or an array of random numbers. + +Non-template variant of the function fills the matrix dst with uniformly-distributed +random numbers from the specified range: +\f[\texttt{low} _c \leq \texttt{dst} (I)_c < \texttt{high} _c\f] +@param dst output array of random numbers; the array must be pre-allocated. +@param low inclusive lower boundary of the generated random numbers. +@param high exclusive upper boundary of the generated random numbers. +@sa RNG, randn, theRNG +*/ +CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high); + +/** @brief Fills the array with normally distributed random numbers. + +The function cv::randn fills the matrix dst with normally distributed random numbers with the specified +mean vector and the standard deviation matrix. The generated random numbers are clipped to fit the +value range of the output array data type. +@param dst output array of random numbers; the array must be pre-allocated and have 1 to 4 channels. +@param mean mean value (expectation) of the generated random numbers. +@param stddev standard deviation of the generated random numbers; it can be either a vector (in +which case a diagonal standard deviation matrix is assumed) or a square matrix. +@sa RNG, randu +*/ +CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev); + +/** @brief Shuffles the array elements randomly. + +The function cv::randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and +swapping them. The number of such swap operations will be dst.rows\*dst.cols\*iterFactor . +@param dst input/output numerical 1D array. +@param iterFactor scale factor that determines the number of random swap operations (see the details +below). +@param rng optional random number generator used for shuffling; if it is zero, theRNG () is used +instead. +@sa RNG, sort +*/ +CV_EXPORTS_W void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG* rng = 0); + +/** @brief Principal Component Analysis + +The class is used to calculate a special basis for a set of vectors. The +basis will consist of eigenvectors of the covariance matrix calculated +from the input set of vectors. The class %PCA can also transform +vectors to/from the new coordinate space defined by the basis. Usually, +in this new coordinate system, each vector from the original set (and +any linear combination of such vectors) can be quite accurately +approximated by taking its first few components, corresponding to the +eigenvectors of the largest eigenvalues of the covariance matrix. +Geometrically it means that you calculate a projection of the vector to +a subspace formed by a few eigenvectors corresponding to the dominant +eigenvalues of the covariance matrix. And usually such a projection is +very close to the original vector. So, you can represent the original +vector from a high-dimensional space with a much shorter vector +consisting of the projected vector's coordinates in the subspace. Such a +transformation is also known as Karhunen-Loeve Transform, or KLT. +See http://en.wikipedia.org/wiki/Principal_component_analysis + +The sample below is the function that takes two matrices. The first +function stores a set of vectors (a row per vector) that is used to +calculate PCA. The second function stores another "test" set of vectors +(a row per vector). First, these vectors are compressed with PCA, then +reconstructed back, and then the reconstruction error norm is computed +and printed for each vector. : + +@code{.cpp} +using namespace cv; + +PCA compressPCA(const Mat& pcaset, int maxComponents, + const Mat& testset, Mat& compressed) +{ + PCA pca(pcaset, // pass the data + Mat(), // we do not have a pre-computed mean vector, + // so let the PCA engine to compute it + PCA::DATA_AS_ROW, // indicate that the vectors + // are stored as matrix rows + // (use PCA::DATA_AS_COL if the vectors are + // the matrix columns) + maxComponents // specify, how many principal components to retain + ); + // if there is no test data, just return the computed basis, ready-to-use + if( !testset.data ) + return pca; + CV_Assert( testset.cols == pcaset.cols ); + + compressed.create(testset.rows, maxComponents, testset.type()); + + Mat reconstructed; + for( int i = 0; i < testset.rows; i++ ) + { + Mat vec = testset.row(i), coeffs = compressed.row(i), reconstructed; + // compress the vector, the result will be stored + // in the i-th row of the output matrix + pca.project(vec, coeffs); + // and then reconstruct it + pca.backProject(coeffs, reconstructed); + // and measure the error + printf("%d. diff = %g\n", i, norm(vec, reconstructed, NORM_L2)); + } + return pca; +} +@endcode +@sa calcCovarMatrix, mulTransposed, SVD, dft, dct +*/ +class CV_EXPORTS PCA +{ +public: + enum Flags { DATA_AS_ROW = 0, //!< indicates that the input samples are stored as matrix rows + DATA_AS_COL = 1, //!< indicates that the input samples are stored as matrix columns + USE_AVG = 2 //! + }; + + /** @brief default constructor + + The default constructor initializes an empty %PCA structure. The other + constructors initialize the structure and call PCA::operator()(). + */ + PCA(); + + /** @overload + @param data input samples stored as matrix rows or matrix columns. + @param mean optional mean value; if the matrix is empty (@c noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout (PCA::Flags) + @param maxComponents maximum number of components that %PCA should + retain; by default, all the components are retained. + */ + PCA(InputArray data, InputArray mean, int flags, int maxComponents = 0); + + /** @overload + @param data input samples stored as matrix rows or matrix columns. + @param mean optional mean value; if the matrix is empty (noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout (PCA::Flags) + @param retainedVariance Percentage of variance that PCA should retain. + Using this parameter will let the PCA decided how many components to + retain but it will always keep at least 2. + */ + PCA(InputArray data, InputArray mean, int flags, double retainedVariance); + + /** @brief performs %PCA + + The operator performs %PCA of the supplied dataset. It is safe to reuse + the same PCA structure for multiple datasets. That is, if the structure + has been previously used with another dataset, the existing internal + data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref + mean are allocated and computed. + + The computed @ref eigenvalues are sorted from the largest to the smallest and + the corresponding @ref eigenvectors are stored as eigenvectors rows. + + @param data input samples stored as the matrix rows or as the matrix + columns. + @param mean optional mean value; if the matrix is empty (noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout. (Flags) + @param maxComponents maximum number of components that PCA should + retain; by default, all the components are retained. + */ + PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents = 0); + + /** @overload + @param data input samples stored as the matrix rows or as the matrix + columns. + @param mean optional mean value; if the matrix is empty (noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout. (PCA::Flags) + @param retainedVariance Percentage of variance that %PCA should retain. + Using this parameter will let the %PCA decided how many components to + retain but it will always keep at least 2. + */ + PCA& operator()(InputArray data, InputArray mean, int flags, double retainedVariance); + + /** @brief Projects vector(s) to the principal component subspace. + + The methods project one or more vectors to the principal component + subspace, where each vector projection is represented by coefficients in + the principal component basis. The first form of the method returns the + matrix that the second form writes to the result. So the first form can + be used as a part of expression while the second form can be more + efficient in a processing loop. + @param vec input vector(s); must have the same dimensionality and the + same layout as the input data used at %PCA phase, that is, if + DATA_AS_ROW are specified, then `vec.cols==data.cols` + (vector dimensionality) and `vec.rows` is the number of vectors to + project, and the same is true for the PCA::DATA_AS_COL case. + */ + Mat project(InputArray vec) const; + + /** @overload + @param vec input vector(s); must have the same dimensionality and the + same layout as the input data used at PCA phase, that is, if + DATA_AS_ROW are specified, then `vec.cols==data.cols` + (vector dimensionality) and `vec.rows` is the number of vectors to + project, and the same is true for the PCA::DATA_AS_COL case. + @param result output vectors; in case of PCA::DATA_AS_COL, the + output matrix has as many columns as the number of input vectors, this + means that `result.cols==vec.cols` and the number of rows match the + number of principal components (for example, `maxComponents` parameter + passed to the constructor). + */ + void project(InputArray vec, OutputArray result) const; + + /** @brief Reconstructs vectors from their PC projections. + + The methods are inverse operations to PCA::project. They take PC + coordinates of projected vectors and reconstruct the original vectors. + Unless all the principal components have been retained, the + reconstructed vectors are different from the originals. But typically, + the difference is small if the number of components is large enough (but + still much smaller than the original vector dimensionality). As a + result, PCA is used. + @param vec coordinates of the vectors in the principal component + subspace, the layout and size are the same as of PCA::project output + vectors. + */ + Mat backProject(InputArray vec) const; + + /** @overload + @param vec coordinates of the vectors in the principal component + subspace, the layout and size are the same as of PCA::project output + vectors. + @param result reconstructed vectors; the layout and size are the same as + of PCA::project input vectors. + */ + void backProject(InputArray vec, OutputArray result) const; + + /** @brief write PCA objects + + Writes @ref eigenvalues @ref eigenvectors and @ref mean to specified FileStorage + */ + void write(FileStorage& fs) const; + + /** @brief load PCA objects + + Loads @ref eigenvalues @ref eigenvectors and @ref mean from specified FileNode + */ + void read(const FileNode& fn); + + Mat eigenvectors; //!< eigenvectors of the covariation matrix + Mat eigenvalues; //!< eigenvalues of the covariation matrix + Mat mean; //!< mean value subtracted before the projection and added after the back projection +}; + +/** @example samples/cpp/pca.cpp +An example using %PCA for dimensionality reduction while maintaining an amount of variance +*/ + +/** @example samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp +Check @ref tutorial_introduction_to_pca "the corresponding tutorial" for more details +*/ + +/** +@brief Linear Discriminant Analysis +@todo document this class +*/ +class CV_EXPORTS LDA +{ +public: + /** @brief constructor + Initializes a LDA with num_components (default 0). + */ + explicit LDA(int num_components = 0); + + /** Initializes and performs a Discriminant Analysis with Fisher's + Optimization Criterion on given data in src and corresponding labels + in labels. If 0 (or less) number of components are given, they are + automatically determined for given data in computation. + */ + LDA(InputArrayOfArrays src, InputArray labels, int num_components = 0); + + /** Serializes this object to a given filename. + */ + void save(const String& filename) const; + + /** Deserializes this object from a given filename. + */ + void load(const String& filename); + + /** Serializes this object to a given cv::FileStorage. + */ + void save(FileStorage& fs) const; + + /** Deserializes this object from a given cv::FileStorage. + */ + void load(const FileStorage& node); + + /** destructor + */ + ~LDA(); + + /** Compute the discriminants for data in src (row aligned) and labels. + */ + void compute(InputArrayOfArrays src, InputArray labels); + + /** Projects samples into the LDA subspace. + src may be one or more row aligned samples. + */ + Mat project(InputArray src); + + /** Reconstructs projections from the LDA subspace. + src may be one or more row aligned projections. + */ + Mat reconstruct(InputArray src); + + /** Returns the eigenvectors of this LDA. + */ + Mat eigenvectors() const { return _eigenvectors; } + + /** Returns the eigenvalues of this LDA. + */ + Mat eigenvalues() const { return _eigenvalues; } + + static Mat subspaceProject(InputArray W, InputArray mean, InputArray src); + static Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src); + +protected: + bool _dataAsRow; // unused, but needed for 3.0 ABI compatibility. + int _num_components; + Mat _eigenvectors; + Mat _eigenvalues; + void lda(InputArrayOfArrays src, InputArray labels); +}; + +/** @brief Singular Value Decomposition + +Class for computing Singular Value Decomposition of a floating-point +matrix. The Singular Value Decomposition is used to solve least-square +problems, under-determined linear systems, invert matrices, compute +condition numbers, and so on. + +If you want to compute a condition number of a matrix or an absolute value of +its determinant, you do not need `u` and `vt`. You can pass +flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u +and vt must be computed, which is not necessary most of the time. + +@sa invert, solve, eigen, determinant +*/ +class CV_EXPORTS SVD +{ +public: + enum Flags { + /** allow the algorithm to modify the decomposed matrix; it can save space and speed up + processing. currently ignored. */ + MODIFY_A = 1, + /** indicates that only a vector of singular values `w` is to be processed, while u and vt + will be set to empty matrices */ + NO_UV = 2, + /** when the matrix is not square, by default the algorithm produces u and vt matrices of + sufficiently large size for the further A reconstruction; if, however, FULL_UV flag is + specified, u and vt will be full-size square orthogonal matrices.*/ + FULL_UV = 4 + }; + + /** @brief the default constructor + + initializes an empty SVD structure + */ + SVD(); + + /** @overload + initializes an empty SVD structure and then calls SVD::operator() + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param flags operation flags (SVD::Flags) + */ + SVD( InputArray src, int flags = 0 ); + + /** @brief the operator that performs SVD. The previously allocated u, w and vt are released. + + The operator performs the singular value decomposition of the supplied + matrix. The u,`vt` , and the vector of singular values w are stored in + the structure. The same SVD structure can be reused many times with + different matrices. Each time, if needed, the previous u,`vt` , and w + are reclaimed and the new matrices are created, which is all handled by + Mat::create. + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param flags operation flags (SVD::Flags) + */ + SVD& operator ()( InputArray src, int flags = 0 ); + + /** @brief decomposes matrix and stores the results to user-provided matrices + + The methods/functions perform SVD of matrix. Unlike SVD::SVD constructor + and SVD::operator(), they store the results to the user-provided + matrices: + + @code{.cpp} + Mat A, w, u, vt; + SVD::compute(A, w, u, vt); + @endcode + + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param w calculated singular values + @param u calculated left singular vectors + @param vt transposed matrix of right singular vectors + @param flags operation flags - see SVD::Flags. + */ + static void compute( InputArray src, OutputArray w, + OutputArray u, OutputArray vt, int flags = 0 ); + + /** @overload + computes singular values of a matrix + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param w calculated singular values + @param flags operation flags - see SVD::Flags. + */ + static void compute( InputArray src, OutputArray w, int flags = 0 ); + + /** @brief performs back substitution + */ + static void backSubst( InputArray w, InputArray u, + InputArray vt, InputArray rhs, + OutputArray dst ); + + /** @brief solves an under-determined singular linear system + + The method finds a unit-length solution x of a singular linear system + A\*x = 0. Depending on the rank of A, there can be no solutions, a + single solution or an infinite number of solutions. In general, the + algorithm solves the following problem: + \f[dst = \arg \min _{x: \| x \| =1} \| src \cdot x \|\f] + @param src left-hand-side matrix. + @param dst found solution. + */ + static void solveZ( InputArray src, OutputArray dst ); + + /** @brief performs a singular value back substitution. + + The method calculates a back substitution for the specified right-hand + side: + + \f[\texttt{x} = \texttt{vt} ^T \cdot diag( \texttt{w} )^{-1} \cdot \texttt{u} ^T \cdot \texttt{rhs} \sim \texttt{A} ^{-1} \cdot \texttt{rhs}\f] + + Using this technique you can either get a very accurate solution of the + convenient linear system, or the best (in the least-squares terms) + pseudo-solution of an overdetermined linear system. + + @param rhs right-hand side of a linear system (u\*w\*v')\*dst = rhs to + be solved, where A has been previously decomposed. + + @param dst found solution of the system. + + @note Explicit SVD with the further back substitution only makes sense + if you need to solve many linear systems with the same left-hand side + (for example, src ). If all you need is to solve a single system + (possibly with multiple rhs immediately available), simply call solve + add pass #DECOMP_SVD there. It does absolutely the same thing. + */ + void backSubst( InputArray rhs, OutputArray dst ) const; + + /** @todo document */ + template<typename _Tp, int m, int n, int nm> static + void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt ); + + /** @todo document */ + template<typename _Tp, int m, int n, int nm> static + void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w ); + + /** @todo document */ + template<typename _Tp, int m, int n, int nm, int nb> static + void backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst ); + + Mat u, w, vt; +}; + +/** @brief Random Number Generator + +Random number generator. It encapsulates the state (currently, a 64-bit +integer) and has methods to return scalar random values and to fill +arrays with random values. Currently it supports uniform and Gaussian +(normal) distributions. The generator uses Multiply-With-Carry +algorithm, introduced by G. Marsaglia ( +<http://en.wikipedia.org/wiki/Multiply-with-carry> ). +Gaussian-distribution random numbers are generated using the Ziggurat +algorithm ( <http://en.wikipedia.org/wiki/Ziggurat_algorithm> ), +introduced by G. Marsaglia and W. W. Tsang. +*/ +class CV_EXPORTS RNG +{ +public: + enum { UNIFORM = 0, + NORMAL = 1 + }; + + /** @brief constructor + + These are the RNG constructors. The first form sets the state to some + pre-defined value, equal to 2\*\*32-1 in the current implementation. The + second form sets the state to the specified value. If you passed state=0 + , the constructor uses the above default value instead to avoid the + singular random number sequence, consisting of all zeros. + */ + RNG(); + /** @overload + @param state 64-bit value used to initialize the RNG. + */ + RNG(uint64 state); + /**The method updates the state using the MWC algorithm and returns the + next 32-bit random number.*/ + unsigned next(); + + /**Each of the methods updates the state using the MWC algorithm and + returns the next random number of the specified type. In case of integer + types, the returned number is from the available value range for the + specified type. In case of floating-point types, the returned value is + from [0,1) range. + */ + operator uchar(); + /** @overload */ + operator schar(); + /** @overload */ + operator ushort(); + /** @overload */ + operator short(); + /** @overload */ + operator unsigned(); + /** @overload */ + operator int(); + /** @overload */ + operator float(); + /** @overload */ + operator double(); + + /** @brief returns a random integer sampled uniformly from [0, N). + + The methods transform the state using the MWC algorithm and return the + next random number. The first form is equivalent to RNG::next . The + second form returns the random number modulo N , which means that the + result is in the range [0, N) . + */ + unsigned operator ()(); + /** @overload + @param N upper non-inclusive boundary of the returned random number. + */ + unsigned operator ()(unsigned N); + + /** @brief returns uniformly distributed integer random number from [a,b) range + + The methods transform the state using the MWC algorithm and return the + next uniformly-distributed random number of the specified type, deduced + from the input parameter type, from the range [a, b) . There is a nuance + illustrated by the following sample: + + @code{.cpp} + RNG rng; + + // always produces 0 + double a = rng.uniform(0, 1); + + // produces double from [0, 1) + double a1 = rng.uniform((double)0, (double)1); + + // produces float from [0, 1) + float b = rng.uniform(0.f, 1.f); + + // produces double from [0, 1) + double c = rng.uniform(0., 1.); + + // may cause compiler error because of ambiguity: + // RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)? + double d = rng.uniform(0, 0.999999); + @endcode + + The compiler does not take into account the type of the variable to + which you assign the result of RNG::uniform . The only thing that + matters to the compiler is the type of a and b parameters. So, if you + want a floating-point random number, but the range boundaries are + integer numbers, either put dots in the end, if they are constants, or + use explicit type cast operators, as in the a1 initialization above. + @param a lower inclusive boundary of the returned random number. + @param b upper non-inclusive boundary of the returned random number. + */ + int uniform(int a, int b); + /** @overload */ + float uniform(float a, float b); + /** @overload */ + double uniform(double a, double b); + + /** @brief Fills arrays with random numbers. + + @param mat 2D or N-dimensional matrix; currently matrices with more than + 4 channels are not supported by the methods, use Mat::reshape as a + possible workaround. + @param distType distribution type, RNG::UNIFORM or RNG::NORMAL. + @param a first distribution parameter; in case of the uniform + distribution, this is an inclusive lower boundary, in case of the normal + distribution, this is a mean value. + @param b second distribution parameter; in case of the uniform + distribution, this is a non-inclusive upper boundary, in case of the + normal distribution, this is a standard deviation (diagonal of the + standard deviation matrix or the full standard deviation matrix). + @param saturateRange pre-saturation flag; for uniform distribution only; + if true, the method will first convert a and b to the acceptable value + range (according to the mat datatype) and then will generate uniformly + distributed random numbers within the range [saturate(a), saturate(b)), + if saturateRange=false, the method will generate uniformly distributed + random numbers in the original range [a, b) and then will saturate them, + it means, for example, that + <tt>theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX)</tt> will likely + produce array mostly filled with 0's and 255's, since the range (0, 255) + is significantly smaller than [-DBL_MAX, DBL_MAX). + + Each of the methods fills the matrix with the random values from the + specified distribution. As the new numbers are generated, the RNG state + is updated accordingly. In case of multiple-channel images, every + channel is filled independently, which means that RNG cannot generate + samples from the multi-dimensional Gaussian distribution with + non-diagonal covariance matrix directly. To do that, the method + generates samples from multi-dimensional standard Gaussian distribution + with zero mean and identity covariation matrix, and then transforms them + using transform to get samples from the specified Gaussian distribution. + */ + void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false ); + + /** @brief Returns the next random number sampled from the Gaussian distribution + @param sigma standard deviation of the distribution. + + The method transforms the state using the MWC algorithm and returns the + next random number from the Gaussian distribution N(0,sigma) . That is, + the mean value of the returned random numbers is zero and the standard + deviation is the specified sigma . + */ + double gaussian(double sigma); + + uint64 state; + + bool operator ==(const RNG& other) const; +}; + +/** @brief Mersenne Twister random number generator + +Inspired by http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c +@todo document +*/ +class CV_EXPORTS RNG_MT19937 +{ +public: + RNG_MT19937(); + RNG_MT19937(unsigned s); + void seed(unsigned s); + + unsigned next(); + + operator int(); + operator unsigned(); + operator float(); + operator double(); + + unsigned operator ()(unsigned N); + unsigned operator ()(); + + /** @brief returns uniformly distributed integer random number from [a,b) range*/ + int uniform(int a, int b); + /** @brief returns uniformly distributed floating-point random number from [a,b) range*/ + float uniform(float a, float b); + /** @brief returns uniformly distributed double-precision floating-point random number from [a,b) range*/ + double uniform(double a, double b); + +private: + enum PeriodParameters {N = 624, M = 397}; + unsigned state[N]; + int mti; +}; + +//! @} core_array + +//! @addtogroup core_cluster +//! @{ + +/** @example samples/cpp/kmeans.cpp +An example on K-means clustering +*/ + +/** @brief Finds centers of clusters and groups input samples around the clusters. + +The function kmeans implements a k-means algorithm that finds the centers of cluster_count clusters +and groups the input samples around the clusters. As an output, \f$\texttt{bestLabels}_i\f$ contains a +0-based cluster index for the sample stored in the \f$i^{th}\f$ row of the samples matrix. + +@note +- (Python) An example on K-means clustering can be found at + opencv_source_code/samples/python/kmeans.py +@param data Data for clustering. An array of N-Dimensional points with float coordinates is needed. +Examples of this array can be: +- Mat points(count, 2, CV_32F); +- Mat points(count, 1, CV_32FC2); +- Mat points(1, count, CV_32FC2); +- std::vector\<cv::Point2f\> points(sampleCount); +@param K Number of clusters to split the set by. +@param bestLabels Input/output integer array that stores the cluster indices for every sample. +@param criteria The algorithm termination criteria, that is, the maximum number of iterations and/or +the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of the cluster +centers moves by less than criteria.epsilon on some iteration, the algorithm stops. +@param attempts Flag to specify the number of times the algorithm is executed using different +initial labellings. The algorithm returns the labels that yield the best compactness (see the last +function parameter). +@param flags Flag that can take values of cv::KmeansFlags +@param centers Output matrix of the cluster centers, one row per each cluster center. +@return The function returns the compactness measure that is computed as +\f[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\f] +after every attempt. The best (minimum) value is chosen and the corresponding labels and the +compactness value are returned by the function. Basically, you can use only the core of the +function, set the number of attempts to 1, initialize labels each time using a custom algorithm, +pass them with the ( flags = #KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best +(most-compact) clustering. +*/ +CV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels, + TermCriteria criteria, int attempts, + int flags, OutputArray centers = noArray() ); + +//! @} core_cluster + +//! @addtogroup core_basic +//! @{ + +/////////////////////////////// Formatted output of cv::Mat /////////////////////////// + +/** @todo document */ +class CV_EXPORTS Formatted +{ +public: + virtual const char* next() = 0; + virtual void reset() = 0; + virtual ~Formatted(); +}; + +/** @todo document */ +class CV_EXPORTS Formatter +{ +public: + enum { FMT_DEFAULT = 0, + FMT_MATLAB = 1, + FMT_CSV = 2, + FMT_PYTHON = 3, + FMT_NUMPY = 4, + FMT_C = 5 + }; + + virtual ~Formatter(); + + virtual Ptr<Formatted> format(const Mat& mtx) const = 0; + + virtual void set32fPrecision(int p = 8) = 0; + virtual void set64fPrecision(int p = 16) = 0; + virtual void setMultiline(bool ml = true) = 0; + + static Ptr<Formatter> get(int fmt = FMT_DEFAULT); + +}; + +static inline +String& operator << (String& out, Ptr<Formatted> fmtd) +{ + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + out += cv::String(str); + return out; +} + +static inline +String& operator << (String& out, const Mat& mtx) +{ + return out << Formatter::get()->format(mtx); +} + +//////////////////////////////////////// Algorithm //////////////////////////////////// + +class CV_EXPORTS Algorithm; + +template<typename _Tp> struct ParamType {}; + + +/** @brief This is a base class for all more or less complex algorithms in OpenCV + +especially for classes of algorithms, for which there can be multiple implementations. The examples +are stereo correspondence (for which there are algorithms like block matching, semi-global block +matching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians +models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck +etc.). + +Here is example of SimpleBlobDetector use in your application via Algorithm interface: +@snippet snippets/core_various.cpp Algorithm +*/ +class CV_EXPORTS_W Algorithm +{ +public: + Algorithm(); + virtual ~Algorithm(); + + /** @brief Clears the algorithm state + */ + CV_WRAP virtual void clear() {} + + /** @brief Stores algorithm parameters in a file storage + */ + virtual void write(FileStorage& fs) const { CV_UNUSED(fs); } + + /** @brief simplified API for language bindings + * @overload + */ + CV_WRAP void write(const Ptr<FileStorage>& fs, const String& name = String()) const; + + /** @brief Reads algorithm parameters from a file storage + */ + CV_WRAP virtual void read(const FileNode& fn) { CV_UNUSED(fn); } + + /** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read + */ + CV_WRAP virtual bool empty() const { return false; } + + /** @brief Reads algorithm from the file node + + This is static template method of Algorithm. It's usage is following (in the case of SVM): + @code + cv::FileStorage fsRead("example.xml", FileStorage::READ); + Ptr<SVM> svm = Algorithm::read<SVM>(fsRead.root()); + @endcode + In order to make this method work, the derived class must overwrite Algorithm::read(const + FileNode& fn) and also have static create() method without parameters + (or with all the optional parameters) + */ + template<typename _Tp> static Ptr<_Tp> read(const FileNode& fn) + { + Ptr<_Tp> obj = _Tp::create(); + obj->read(fn); + return !obj->empty() ? obj : Ptr<_Tp>(); + } + + /** @brief Loads algorithm from the file + + @param filename Name of the file to read. + @param objname The optional name of the node to read (if empty, the first top-level node will be used) + + This is static template method of Algorithm. It's usage is following (in the case of SVM): + @code + Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml"); + @endcode + In order to make this method work, the derived class must overwrite Algorithm::read(const + FileNode& fn). + */ + template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String()) + { + FileStorage fs(filename, FileStorage::READ); + CV_Assert(fs.isOpened()); + FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]; + if (fn.empty()) return Ptr<_Tp>(); + Ptr<_Tp> obj = _Tp::create(); + obj->read(fn); + return !obj->empty() ? obj : Ptr<_Tp>(); + } + + /** @brief Loads algorithm from a String + + @param strModel The string variable containing the model you want to load. + @param objname The optional name of the node to read (if empty, the first top-level node will be used) + + This is static template method of Algorithm. It's usage is following (in the case of SVM): + @code + Ptr<SVM> svm = Algorithm::loadFromString<SVM>(myStringModel); + @endcode + */ + template<typename _Tp> static Ptr<_Tp> loadFromString(const String& strModel, const String& objname=String()) + { + FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY); + FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]; + Ptr<_Tp> obj = _Tp::create(); + obj->read(fn); + return !obj->empty() ? obj : Ptr<_Tp>(); + } + + /** Saves the algorithm to a file. + In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */ + CV_WRAP virtual void save(const String& filename) const; + + /** Returns the algorithm string identifier. + This string is used as top level xml/yml node tag when the object is saved to a file or string. */ + CV_WRAP virtual String getDefaultName() const; + +protected: + void writeFormat(FileStorage& fs) const; +}; + +struct Param { + enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, + UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 }; +}; + + + +template<> struct ParamType<bool> +{ + typedef bool const_param_type; + typedef bool member_type; + + enum { type = Param::BOOLEAN }; +}; + +template<> struct ParamType<int> +{ + typedef int const_param_type; + typedef int member_type; + + enum { type = Param::INT }; +}; + +template<> struct ParamType<double> +{ + typedef double const_param_type; + typedef double member_type; + + enum { type = Param::REAL }; +}; + +template<> struct ParamType<String> +{ + typedef const String& const_param_type; + typedef String member_type; + + enum { type = Param::STRING }; +}; + +template<> struct ParamType<Mat> +{ + typedef const Mat& const_param_type; + typedef Mat member_type; + + enum { type = Param::MAT }; +}; + +template<> struct ParamType<std::vector<Mat> > +{ + typedef const std::vector<Mat>& const_param_type; + typedef std::vector<Mat> member_type; + + enum { type = Param::MAT_VECTOR }; +}; + +template<> struct ParamType<Algorithm> +{ + typedef const Ptr<Algorithm>& const_param_type; + typedef Ptr<Algorithm> member_type; + + enum { type = Param::ALGORITHM }; +}; + +template<> struct ParamType<float> +{ + typedef float const_param_type; + typedef float member_type; + + enum { type = Param::FLOAT }; +}; + +template<> struct ParamType<unsigned> +{ + typedef unsigned const_param_type; + typedef unsigned member_type; + + enum { type = Param::UNSIGNED_INT }; +}; + +template<> struct ParamType<uint64> +{ + typedef uint64 const_param_type; + typedef uint64 member_type; + + enum { type = Param::UINT64 }; +}; + +template<> struct ParamType<uchar> +{ + typedef uchar const_param_type; + typedef uchar member_type; + + enum { type = Param::UCHAR }; +}; + +template<> struct ParamType<Scalar> +{ + typedef const Scalar& const_param_type; + typedef Scalar member_type; + + enum { type = Param::SCALAR }; +}; + +//! @} core_basic + +} //namespace cv + +#include "opencv2/core/operations.hpp" +#include "opencv2/core/cvstd.inl.hpp" +#include "opencv2/core/utility.hpp" +#include "opencv2/core/optim.hpp" +#include "opencv2/core/ovx.hpp" + +#endif /*OPENCV_CORE_HPP*/ diff --git a/include/opencv2/core/affine.hpp b/include/opencv2/core/affine.hpp new file mode 100644 index 0000000..7e2ed30 --- /dev/null +++ b/include/opencv2/core/affine.hpp @@ -0,0 +1,678 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_AFFINE3_HPP +#define OPENCV_CORE_AFFINE3_HPP + +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv +{ + +//! @addtogroup core +//! @{ + + /** @brief Affine transform + * + * It represents a 4x4 homogeneous transformation matrix \f$T\f$ + * + * \f[T = + * \begin{bmatrix} + * R & t\\ + * 0 & 1\\ + * \end{bmatrix} + * \f] + * + * where \f$R\f$ is a 3x3 rotation matrix and \f$t\f$ is a 3x1 translation vector. + * + * You can specify \f$R\f$ either by a 3x3 rotation matrix or by a 3x1 rotation vector, + * which is converted to a 3x3 rotation matrix by the Rodrigues formula. + * + * To construct a matrix \f$T\f$ representing first rotation around the axis \f$r\f$ with rotation + * angle \f$|r|\f$ in radian (right hand rule) and then translation by the vector \f$t\f$, you can use + * + * @code + * cv::Vec3f r, t; + * cv::Affine3f T(r, t); + * @endcode + * + * If you already have the rotation matrix \f$R\f$, then you can use + * + * @code + * cv::Matx33f R; + * cv::Affine3f T(R, t); + * @endcode + * + * To extract the rotation matrix \f$R\f$ from \f$T\f$, use + * + * @code + * cv::Matx33f R = T.rotation(); + * @endcode + * + * To extract the translation vector \f$t\f$ from \f$T\f$, use + * + * @code + * cv::Vec3f t = T.translation(); + * @endcode + * + * To extract the rotation vector \f$r\f$ from \f$T\f$, use + * + * @code + * cv::Vec3f r = T.rvec(); + * @endcode + * + * Note that since the mapping from rotation vectors to rotation matrices + * is many to one. The returned rotation vector is not necessarily the one + * you used before to set the matrix. + * + * If you have two transformations \f$T = T_1 * T_2\f$, use + * + * @code + * cv::Affine3f T, T1, T2; + * T = T2.concatenate(T1); + * @endcode + * + * To get the inverse transform of \f$T\f$, use + * + * @code + * cv::Affine3f T, T_inv; + * T_inv = T.inv(); + * @endcode + * + */ + template<typename T> + class Affine3 + { + public: + typedef T float_type; + typedef Matx<float_type, 3, 3> Mat3; + typedef Matx<float_type, 4, 4> Mat4; + typedef Vec<float_type, 3> Vec3; + + //! Default constructor. It represents a 4x4 identity matrix. + Affine3(); + + //! Augmented affine matrix + Affine3(const Mat4& affine); + + /** + * The resulting 4x4 matrix is + * + * \f[ + * \begin{bmatrix} + * R & t\\ + * 0 & 1\\ + * \end{bmatrix} + * \f] + * + * @param R 3x3 rotation matrix. + * @param t 3x1 translation vector. + */ + Affine3(const Mat3& R, const Vec3& t = Vec3::all(0)); + + /** + * Rodrigues vector. + * + * The last row of the current matrix is set to [0,0,0,1]. + * + * @param rvec 3x1 rotation vector. Its direction indicates the rotation axis and its length + * indicates the rotation angle in radian (using right hand rule). + * @param t 3x1 translation vector. + */ + Affine3(const Vec3& rvec, const Vec3& t = Vec3::all(0)); + + /** + * Combines all constructors above. Supports 4x4, 3x4, 3x3, 1x3, 3x1 sizes of data matrix. + * + * The last row of the current matrix is set to [0,0,0,1] when data is not 4x4. + * + * @param data 1-channel matrix. + * when it is 4x4, it is copied to the current matrix and t is not used. + * When it is 3x4, it is copied to the upper part 3x4 of the current matrix and t is not used. + * When it is 3x3, it is copied to the upper left 3x3 part of the current matrix. + * When it is 3x1 or 1x3, it is treated as a rotation vector and the Rodrigues formula is used + * to compute a 3x3 rotation matrix. + * @param t 3x1 translation vector. It is used only when data is neither 4x4 nor 3x4. + */ + explicit Affine3(const Mat& data, const Vec3& t = Vec3::all(0)); + + //! From 16-element array + explicit Affine3(const float_type* vals); + + //! Create an 4x4 identity transform + static Affine3 Identity(); + + /** + * Rotation matrix. + * + * Copy the rotation matrix to the upper left 3x3 part of the current matrix. + * The remaining elements of the current matrix are not changed. + * + * @param R 3x3 rotation matrix. + * + */ + void rotation(const Mat3& R); + + /** + * Rodrigues vector. + * + * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected. + * + * @param rvec 3x1 rotation vector. The direction indicates the rotation axis and + * its length indicates the rotation angle in radian (using the right thumb convention). + */ + void rotation(const Vec3& rvec); + + /** + * Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix. + * + * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected. + * + * @param data 1-channel matrix. + * When it is a 3x3 matrix, it sets the upper left 3x3 part of the current matrix. + * When it is a 1x3 or 3x1 matrix, it is used as a rotation vector. The Rodrigues formula + * is used to compute the rotation matrix and sets the upper left 3x3 part of the current matrix. + */ + void rotation(const Mat& data); + + /** + * Copy the 3x3 matrix L to the upper left part of the current matrix + * + * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected. + * + * @param L 3x3 matrix. + */ + void linear(const Mat3& L); + + /** + * Copy t to the first three elements of the last column of the current matrix + * + * It sets the upper right 3x1 part of the matrix. The remaining part is unaffected. + * + * @param t 3x1 translation vector. + */ + void translation(const Vec3& t); + + //! @return the upper left 3x3 part + Mat3 rotation() const; + + //! @return the upper left 3x3 part + Mat3 linear() const; + + //! @return the upper right 3x1 part + Vec3 translation() const; + + //! Rodrigues vector. + //! @return a vector representing the upper left 3x3 rotation matrix of the current matrix. + //! @warning Since the mapping between rotation vectors and rotation matrices is many to one, + //! this function returns only one rotation vector that represents the current rotation matrix, + //! which is not necessarily the same one set by `rotation(const Vec3& rvec)`. + Vec3 rvec() const; + + //! @return the inverse of the current matrix. + Affine3 inv(int method = cv::DECOMP_SVD) const; + + //! a.rotate(R) is equivalent to Affine(R, 0) * a; + Affine3 rotate(const Mat3& R) const; + + //! a.rotate(rvec) is equivalent to Affine(rvec, 0) * a; + Affine3 rotate(const Vec3& rvec) const; + + //! a.translate(t) is equivalent to Affine(E, t) * a, where E is an identity matrix + Affine3 translate(const Vec3& t) const; + + //! a.concatenate(affine) is equivalent to affine * a; + Affine3 concatenate(const Affine3& affine) const; + + template <typename Y> operator Affine3<Y>() const; + + template <typename Y> Affine3<Y> cast() const; + + Mat4 matrix; + +#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H + Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine); + Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine); + operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const; + operator Eigen::Transform<T, 3, Eigen::Affine>() const; +#endif + }; + + template<typename T> static + Affine3<T> operator*(const Affine3<T>& affine1, const Affine3<T>& affine2); + + //! V is a 3-element vector with member fields x, y and z + template<typename T, typename V> static + V operator*(const Affine3<T>& affine, const V& vector); + + typedef Affine3<float> Affine3f; + typedef Affine3<double> Affine3d; + + static Vec3f operator*(const Affine3f& affine, const Vec3f& vector); + static Vec3d operator*(const Affine3d& affine, const Vec3d& vector); + + template<typename _Tp> class DataType< Affine3<_Tp> > + { + public: + typedef Affine3<_Tp> value_type; + typedef Affine3<typename DataType<_Tp>::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 16, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; + }; + + namespace traits { + template<typename _Tp> + struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; }; + template<typename _Tp> + struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; }; + } // namespace + +//! @} core + +} + +//! @cond IGNORED + +/////////////////////////////////////////////////////////////////////////////////// +// Implementation + +template<typename T> inline +cv::Affine3<T>::Affine3() + : matrix(Mat4::eye()) +{} + +template<typename T> inline +cv::Affine3<T>::Affine3(const Mat4& affine) + : matrix(affine) +{} + +template<typename T> inline +cv::Affine3<T>::Affine3(const Mat3& R, const Vec3& t) +{ + rotation(R); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template<typename T> inline +cv::Affine3<T>::Affine3(const Vec3& _rvec, const Vec3& t) +{ + rotation(_rvec); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template<typename T> inline +cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t) +{ + CV_Assert(data.type() == cv::traits::Type<T>::value); + CV_Assert(data.channels() == 1); + + if (data.cols == 4 && data.rows == 4) + { + data.copyTo(matrix); + return; + } + else if (data.cols == 4 && data.rows == 3) + { + rotation(data(Rect(0, 0, 3, 3))); + translation(data(Rect(3, 0, 1, 3))); + } + else + { + rotation(data); + translation(t); + } + + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template<typename T> inline +cv::Affine3<T>::Affine3(const float_type* vals) : matrix(vals) +{} + +template<typename T> inline +cv::Affine3<T> cv::Affine3<T>::Identity() +{ + return Affine3<T>(cv::Affine3<T>::Mat4::eye()); +} + +template<typename T> inline +void cv::Affine3<T>::rotation(const Mat3& R) +{ + linear(R); +} + +template<typename T> inline +void cv::Affine3<T>::rotation(const Vec3& _rvec) +{ + double theta = norm(_rvec); + + if (theta < DBL_EPSILON) + rotation(Mat3::eye()); + else + { + double c = std::cos(theta); + double s = std::sin(theta); + double c1 = 1. - c; + double itheta = (theta != 0) ? 1./theta : 0.; + + Point3_<T> r = _rvec*itheta; + + Mat3 rrt( r.x*r.x, r.x*r.y, r.x*r.z, r.x*r.y, r.y*r.y, r.y*r.z, r.x*r.z, r.y*r.z, r.z*r.z ); + Mat3 r_x( 0, -r.z, r.y, r.z, 0, -r.x, -r.y, r.x, 0 ); + + // R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x] + // where [r_x] is [0 -rz ry; rz 0 -rx; -ry rx 0] + Mat3 R = c*Mat3::eye() + c1*rrt + s*r_x; + + rotation(R); + } +} + +//Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix; +template<typename T> inline +void cv::Affine3<T>::rotation(const cv::Mat& data) +{ + CV_Assert(data.type() == cv::traits::Type<T>::value); + CV_Assert(data.channels() == 1); + + if (data.cols == 3 && data.rows == 3) + { + Mat3 R; + data.copyTo(R); + rotation(R); + } + else if ((data.cols == 3 && data.rows == 1) || (data.cols == 1 && data.rows == 3)) + { + Vec3 _rvec; + data.reshape(1, 3).copyTo(_rvec); + rotation(_rvec); + } + else + CV_Error(Error::StsError, "Input matrix can only be 3x3, 1x3 or 3x1"); +} + +template<typename T> inline +void cv::Affine3<T>::linear(const Mat3& L) +{ + matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2]; + matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5]; + matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8]; +} + +template<typename T> inline +void cv::Affine3<T>::translation(const Vec3& t) +{ + matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2]; +} + +template<typename T> inline +typename cv::Affine3<T>::Mat3 cv::Affine3<T>::rotation() const +{ + return linear(); +} + +template<typename T> inline +typename cv::Affine3<T>::Mat3 cv::Affine3<T>::linear() const +{ + typename cv::Affine3<T>::Mat3 R; + R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2]; + R.val[3] = matrix.val[4]; R.val[4] = matrix.val[5]; R.val[5] = matrix.val[ 6]; + R.val[6] = matrix.val[8]; R.val[7] = matrix.val[9]; R.val[8] = matrix.val[10]; + return R; +} + +template<typename T> inline +typename cv::Affine3<T>::Vec3 cv::Affine3<T>::translation() const +{ + return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]); +} + +template<typename T> inline +typename cv::Affine3<T>::Vec3 cv::Affine3<T>::rvec() const +{ + cv::Vec3d w; + cv::Matx33d u, vt, R = rotation(); + cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A); + R = u * vt; + + double rx = R.val[7] - R.val[5]; + double ry = R.val[2] - R.val[6]; + double rz = R.val[3] - R.val[1]; + + double s = std::sqrt((rx*rx + ry*ry + rz*rz)*0.25); + double c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5; + c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c; + double theta = acos(c); + + if( s < 1e-5 ) + { + if( c > 0 ) + rx = ry = rz = 0; + else + { + double t; + t = (R.val[0] + 1) * 0.5; + rx = std::sqrt(std::max(t, 0.0)); + t = (R.val[4] + 1) * 0.5; + ry = std::sqrt(std::max(t, 0.0)) * (R.val[1] < 0 ? -1.0 : 1.0); + t = (R.val[8] + 1) * 0.5; + rz = std::sqrt(std::max(t, 0.0)) * (R.val[2] < 0 ? -1.0 : 1.0); + + if( fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R.val[5] > 0) != (ry*rz > 0) ) + rz = -rz; + theta /= std::sqrt(rx*rx + ry*ry + rz*rz); + rx *= theta; + ry *= theta; + rz *= theta; + } + } + else + { + double vth = 1/(2*s); + vth *= theta; + rx *= vth; ry *= vth; rz *= vth; + } + + return cv::Vec3d(rx, ry, rz); +} + +template<typename T> inline +cv::Affine3<T> cv::Affine3<T>::inv(int method) const +{ + return matrix.inv(method); +} + +template<typename T> inline +cv::Affine3<T> cv::Affine3<T>::rotate(const Mat3& R) const +{ + Mat3 Lc = linear(); + Vec3 tc = translation(); + Mat4 result; + result.val[12] = result.val[13] = result.val[14] = 0; + result.val[15] = 1; + + for(int j = 0; j < 3; ++j) + { + for(int i = 0; i < 3; ++i) + { + float_type value = 0; + for(int k = 0; k < 3; ++k) + value += R(j, k) * Lc(k, i); + result(j, i) = value; + } + + result(j, 3) = R.row(j).dot(tc.t()); + } + return result; +} + +template<typename T> inline +cv::Affine3<T> cv::Affine3<T>::rotate(const Vec3& _rvec) const +{ + return rotate(Affine3f(_rvec).rotation()); +} + +template<typename T> inline +cv::Affine3<T> cv::Affine3<T>::translate(const Vec3& t) const +{ + Mat4 m = matrix; + m.val[ 3] += t[0]; + m.val[ 7] += t[1]; + m.val[11] += t[2]; + return m; +} + +template<typename T> inline +cv::Affine3<T> cv::Affine3<T>::concatenate(const Affine3<T>& affine) const +{ + return (*this).rotate(affine.rotation()).translate(affine.translation()); +} + +template<typename T> template <typename Y> inline +cv::Affine3<T>::operator Affine3<Y>() const +{ + return Affine3<Y>(matrix); +} + +template<typename T> template <typename Y> inline +cv::Affine3<Y> cv::Affine3<T>::cast() const +{ + return Affine3<Y>(matrix); +} + +template<typename T> inline +cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2) +{ + return affine2.concatenate(affine1); +} + +template<typename T, typename V> inline +V cv::operator*(const cv::Affine3<T>& affine, const V& v) +{ + const typename Affine3<T>::Mat4& m = affine.matrix; + + V r; + r.x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3]; + r.y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7]; + r.z = m.val[8] * v.x + m.val[9] * v.y + m.val[10] * v.z + m.val[11]; + return r; +} + +static inline +cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v) +{ + const cv::Matx44f& m = affine.matrix; + cv::Vec3f r; + r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3]; + r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7]; + r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11]; + return r; +} + +static inline +cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) +{ + const cv::Matx44d& m = affine.matrix; + cv::Vec3d r; + r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3]; + r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7]; + r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11]; + return r; +} + + + +#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H + +template<typename T> inline +cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine) +{ + cv::Mat(4, 4, cv::traits::Type<T>::value, affine.matrix().data()).copyTo(matrix); +} + +template<typename T> inline +cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine) +{ + Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine; + cv::Mat(4, 4, cv::traits::Type<T>::value, a.matrix().data()).copyTo(matrix); +} + +template<typename T> inline +cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const +{ + Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> r; + cv::Mat hdr(4, 4, cv::traits::Type<T>::value, r.matrix().data()); + cv::Mat(matrix, false).copyTo(hdr); + return r; +} + +template<typename T> inline +cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine>() const +{ + return this->operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>(); +} + +#endif /* defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H */ + +//! @endcond + +#endif /* __cplusplus */ + +#endif /* OPENCV_CORE_AFFINE3_HPP */ diff --git a/include/opencv2/core/base.hpp b/include/opencv2/core/base.hpp new file mode 100644 index 0000000..31cd7a8 --- /dev/null +++ b/include/opencv2/core/base.hpp @@ -0,0 +1,707 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2014, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_BASE_HPP +#define OPENCV_CORE_BASE_HPP + +#ifndef __cplusplus +# error base.hpp header must be compiled as C++ +#endif + +#include "opencv2/opencv_modules.hpp" + +#include <climits> +#include <algorithm> + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" + +namespace cv +{ + +//! @addtogroup core_utils +//! @{ + +namespace Error { +//! error codes +enum Code { + StsOk= 0, //!< everything is ok + StsBackTrace= -1, //!< pseudo error for back trace + StsError= -2, //!< unknown /unspecified error + StsInternal= -3, //!< internal error (bad state) + StsNoMem= -4, //!< insufficient memory + StsBadArg= -5, //!< function arg/param is bad + StsBadFunc= -6, //!< unsupported function + StsNoConv= -7, //!< iteration didn't converge + StsAutoTrace= -8, //!< tracing + HeaderIsNull= -9, //!< image header is NULL + BadImageSize= -10, //!< image size is invalid + BadOffset= -11, //!< offset is invalid + BadDataPtr= -12, //!< + BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix. + BadModelOrChSeq= -14, //!< + BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices. + BadNumChannel1U= -16, //!< + BadDepth= -17, //!< input image depth is not supported by the function + BadAlphaChannel= -18, //!< + BadOrder= -19, //!< number of dimensions is out of range + BadOrigin= -20, //!< incorrect input origin + BadAlign= -21, //!< incorrect input align + BadCallBack= -22, //!< + BadTileSize= -23, //!< + BadCOI= -24, //!< input COI is not supported + BadROISize= -25, //!< incorrect input roi + MaskIsTiled= -26, //!< + StsNullPtr= -27, //!< null pointer + StsVecLengthErr= -28, //!< incorrect vector length + StsFilterStructContentErr= -29, //!< incorrect filter structure content + StsKernelStructContentErr= -30, //!< incorrect transform kernel content + StsFilterOffsetErr= -31, //!< incorrect filter offset value + StsBadSize= -201, //!< the input/output structure size is incorrect + StsDivByZero= -202, //!< division by zero + StsInplaceNotSupported= -203, //!< in-place operation is not supported + StsObjectNotFound= -204, //!< request can't be completed + StsUnmatchedFormats= -205, //!< formats of input/output arrays differ + StsBadFlag= -206, //!< flag is wrong or not supported + StsBadPoint= -207, //!< bad CvPoint + StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1) + StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match + StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function + StsOutOfRange= -211, //!< some of parameters are out of range + StsParseError= -212, //!< invalid syntax/structure of the parsed file + StsNotImplemented= -213, //!< the requested function/feature is not implemented + StsBadMemBlock= -214, //!< an allocated block has been corrupted + StsAssert= -215, //!< assertion failed + GpuNotSupported= -216, //!< no CUDA support + GpuApiCallError= -217, //!< GPU API call error + OpenGlNotSupported= -218, //!< no OpenGL support + OpenGlApiCallError= -219, //!< OpenGL API call error + OpenCLApiCallError= -220, //!< OpenCL API call error + OpenCLDoubleNotSupported= -221, + OpenCLInitError= -222, //!< OpenCL initialization error + OpenCLNoAMDBlasFft= -223 +}; +} //Error + +//! @} core_utils + +//! @addtogroup core_array +//! @{ + +//! matrix decomposition types +enum DecompTypes { + /** Gaussian elimination with the optimal pivot element chosen. */ + DECOMP_LU = 0, + /** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix + src1 can be singular */ + DECOMP_SVD = 1, + /** eigenvalue decomposition; the matrix src1 must be symmetrical */ + DECOMP_EIG = 2, + /** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively + defined */ + DECOMP_CHOLESKY = 3, + /** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */ + DECOMP_QR = 4, + /** while all the previous flags are mutually exclusive, this flag can be used together with + any of the previous; it means that the normal equations + \f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are + solved instead of the original system + \f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */ + DECOMP_NORMAL = 16 +}; + +/** norm types + +src1 and src2 denote input arrays. +*/ + +enum NormTypes { + /** + \f[ + norm = \forkthree + {\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } + {\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } + {\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) } + \f] + */ + NORM_INF = 1, + /** + \f[ + norm = \forkthree + {\| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\)} + { \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } + { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) } + \f]*/ + NORM_L1 = 2, + /** + \f[ + norm = \forkthree + { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } + { \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } + { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) } + \f] + */ + NORM_L2 = 4, + /** + \f[ + norm = \forkthree + { \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)} + { \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) } + { \left(\frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}}\right)^2 }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) } + \f] + */ + NORM_L2SQR = 5, + /** + In the case of one input array, calculates the Hamming distance of the array from zero, + In the case of two input arrays, calculates the Hamming distance between the arrays. + */ + NORM_HAMMING = 6, + /** + Similar to NORM_HAMMING, but in the calculation, each two bits of the input sequence will + be added and treated as a single bit to be used in the same calculation as NORM_HAMMING. + */ + NORM_HAMMING2 = 7, + NORM_TYPE_MASK = 7, //!< bit-mask which can be used to separate norm type from norm flags + NORM_RELATIVE = 8, //!< flag + NORM_MINMAX = 32 //!< flag + }; + +//! comparison types +enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2. + CMP_GT = 1, //!< src1 is greater than src2. + CMP_GE = 2, //!< src1 is greater than or equal to src2. + CMP_LT = 3, //!< src1 is less than src2. + CMP_LE = 4, //!< src1 is less than or equal to src2. + CMP_NE = 5 //!< src1 is unequal to src2. + }; + +//! generalized matrix multiplication flags +enum GemmFlags { GEMM_1_T = 1, //!< transposes src1 + GEMM_2_T = 2, //!< transposes src2 + GEMM_3_T = 4 //!< transposes src3 + }; + +enum DftFlags { + /** performs an inverse 1D or 2D transform instead of the default forward + transform. */ + DFT_INVERSE = 1, + /** scales the result: divide it by the number of array elements. Normally, it is + combined with DFT_INVERSE. */ + DFT_SCALE = 2, + /** performs a forward or inverse transform of every individual row of the input + matrix; this flag enables you to transform multiple vectors simultaneously and can be used to + decrease the overhead (which is sometimes several times larger than the processing itself) to + perform 3D and higher-dimensional transformations and so forth.*/ + DFT_ROWS = 4, + /** performs a forward transformation of 1D or 2D real array; the result, + though being a complex array, has complex-conjugate symmetry (*CCS*, see the function + description below for details), and such an array can be packed into a real array of the same + size as input, which is the fastest option and which is what the function does by default; + however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) - + pass the flag to enable the function to produce a full-size complex output array. */ + DFT_COMPLEX_OUTPUT = 16, + /** performs an inverse transformation of a 1D or 2D complex array; the + result is normally a complex array of the same size, however, if the input array has + conjugate-complex symmetry (for example, it is a result of forward transformation with + DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not + check whether the input is symmetrical or not, you can pass the flag and then the function + will assume the symmetry and produce the real output array (note that when the input is packed + into a real array and inverse transformation is executed, the function treats the input as a + packed complex-conjugate symmetrical array, and the output will also be a real array). */ + DFT_REAL_OUTPUT = 32, + /** specifies that input is complex input. If this flag is set, the input must have 2 channels. + On the other hand, for backwards compatibility reason, if input has 2 channels, input is + already considered complex. */ + DFT_COMPLEX_INPUT = 64, + /** performs an inverse 1D or 2D transform instead of the default forward transform. */ + DCT_INVERSE = DFT_INVERSE, + /** performs a forward or inverse transform of every individual row of the input + matrix. This flag enables you to transform multiple vectors simultaneously and can be used to + decrease the overhead (which is sometimes several times larger than the processing itself) to + perform 3D and higher-dimensional transforms and so forth.*/ + DCT_ROWS = DFT_ROWS +}; + +//! Various border types, image boundaries are denoted with `|` +//! @see borderInterpolate, copyMakeBorder +enum BorderTypes { + BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i` + BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh` + BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb` + BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg` + BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba` + BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno` + + BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_ISOLATED = 16 //!< do not look outside of ROI +}; + +//! @} core_array + +//! @addtogroup core_utils +//! @{ + +/*! @brief Signals an error and raises the exception. + +By default the function prints information about the error to stderr, +then it either stops if setBreakOnError() had been called before or raises the exception. +It is possible to alternate error processing by using redirectError(). +@param _code - error code (Error::Code) +@param _err - error description +@param _func - function name. Available only when the compiler supports getting it +@param _file - source file name where the error has occurred +@param _line - line number in the source file where the error has occurred +@see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert + */ +CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line); + +#ifdef __GNUC__ +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Winvalid-noreturn" +# endif +#endif + +/** same as cv::error, but does not return */ +CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const char* _func, const char* _file, int _line) +{ + error(_code, _err, _func, _file, _line); +#ifdef __GNUC__ +# if !defined __clang__ && !defined __APPLE__ + // this suppresses this warning: "noreturn" function does return [enabled by default] + __builtin_trap(); + // or use infinite loop: for (;;) {} +# endif +#endif +} +#ifdef __GNUC__ +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic pop +# endif +#endif + +#ifdef CV_STATIC_ANALYSIS + +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#define CV_Error(...) do { abort(); } while (0) +#define CV_Error_( code, args ) do { cv::format args; abort(); } while (0) +#define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0) +#define CV_ErrorNoReturn CV_Error +#define CV_ErrorNoReturn_ CV_Error_ + +#else // CV_STATIC_ANALYSIS + +/** @brief Call the error handler. + +Currently, the error handler prints the error code and the error message to the standard +error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that +the execution stack and all the parameters can be analyzed by the debugger. In the Release +configuration, the exception is thrown. + +@param code one of Error::Code +@param msg error message +*/ +#define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ ) + +/** @brief Call the error handler. + +This macro can be used to construct an error message on-fly to include some dynamic information, +for example: +@code + // note the extra parentheses around the formatted text message + CV_Error_(Error::StsOutOfRange, + ("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue)); +@endcode +@param code one of Error::Code +@param args printf-like formatted error message in parentheses +*/ +#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ ) + +/** @brief Checks a condition at runtime and throws exception if it fails + +The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros +raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release +configurations while CV_DbgAssert is only retained in the Debug configuration. +*/ +#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) + +//! @cond IGNORED +#define CV__ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ ) +#define CV__ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ ) +#ifdef __OPENCV_BUILD +#undef CV_Error +#define CV_Error CV__ErrorNoReturn +#undef CV_Error_ +#define CV_Error_ CV__ErrorNoReturn_ +#undef CV_Assert +#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::errorNoReturn( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) +#else +// backward compatibility +#define CV_ErrorNoReturn CV__ErrorNoReturn +#define CV_ErrorNoReturn_ CV__ErrorNoReturn_ +#endif +//! @endcond + +#endif // CV_STATIC_ANALYSIS + +//! @cond IGNORED + +#if defined OPENCV_FORCE_MULTIARG_ASSERT_CHECK && defined CV_STATIC_ANALYSIS +#warning "OPENCV_FORCE_MULTIARG_ASSERT_CHECK can't be used with CV_STATIC_ANALYSIS" +#undef OPENCV_FORCE_MULTIARG_ASSERT_CHECK +#endif + +#ifdef OPENCV_FORCE_MULTIARG_ASSERT_CHECK +#define CV_Assert_1( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) +#else +#define CV_Assert_1 CV_Assert +#endif +#define CV_Assert_2( expr1, expr2 ) CV_Assert_1(expr1); CV_Assert_1(expr2) +#define CV_Assert_3( expr1, expr2, expr3 ) CV_Assert_2(expr1, expr2); CV_Assert_1(expr3) +#define CV_Assert_4( expr1, expr2, expr3, expr4 ) CV_Assert_3(expr1, expr2, expr3); CV_Assert_1(expr4) +#define CV_Assert_5( expr1, expr2, expr3, expr4, expr5 ) CV_Assert_4(expr1, expr2, expr3, expr4); CV_Assert_1(expr5) +#define CV_Assert_6( expr1, expr2, expr3, expr4, expr5, expr6 ) CV_Assert_5(expr1, expr2, expr3, expr4, expr5); CV_Assert_1(expr6) +#define CV_Assert_7( expr1, expr2, expr3, expr4, expr5, expr6, expr7 ) CV_Assert_6(expr1, expr2, expr3, expr4, expr5, expr6 ); CV_Assert_1(expr7) +#define CV_Assert_8( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ) CV_Assert_7(expr1, expr2, expr3, expr4, expr5, expr6, expr7 ); CV_Assert_1(expr8) +#define CV_Assert_9( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ) CV_Assert_8(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ); CV_Assert_1(expr9) +#define CV_Assert_10( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9, expr10 ) CV_Assert_9(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ); CV_Assert_1(expr10) + +#define CV_Assert_N(...) do { __CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__); } while(0) + +#ifdef OPENCV_FORCE_MULTIARG_ASSERT_CHECK +#undef CV_Assert +#define CV_Assert CV_Assert_N +#endif +//! @endcond + +#if defined _DEBUG || defined CV_STATIC_ANALYSIS +# define CV_DbgAssert(expr) CV_Assert(expr) +#else +/** replaced with CV_Assert(expr) in Debug configuration */ +# define CV_DbgAssert(expr) +#endif + +/* + * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor + * bit count of A exclusive XOR'ed with B + */ +struct CV_EXPORTS Hamming +{ + enum { normType = NORM_HAMMING }; + typedef unsigned char ValueType; + typedef int ResultType; + + /** this will count the bits in a ^ b + */ + ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const; +}; + +typedef Hamming HammingLUT; + +/////////////////////////////////// inline norms //////////////////////////////////// + +template<typename _Tp> inline _Tp cv_abs(_Tp x) { return std::abs(x); } +inline int cv_abs(uchar x) { return x; } +inline int cv_abs(schar x) { return std::abs(x); } +inline int cv_abs(ushort x) { return x; } +inline int cv_abs(short x) { return std::abs(x); } + +template<typename _Tp, typename _AccTp> static inline +_AccTp normL2Sqr(const _Tp* a, int n) +{ + _AccTp s = 0; + int i=0; +#if CV_ENABLE_UNROLLED + for( ; i <= n - 4; i += 4 ) + { + _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3]; + s += v0*v0 + v1*v1 + v2*v2 + v3*v3; + } +#endif + for( ; i < n; i++ ) + { + _AccTp v = a[i]; + s += v*v; + } + return s; +} + +template<typename _Tp, typename _AccTp> static inline +_AccTp normL1(const _Tp* a, int n) +{ + _AccTp s = 0; + int i = 0; +#if CV_ENABLE_UNROLLED + for(; i <= n - 4; i += 4 ) + { + s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) + + (_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]); + } +#endif + for( ; i < n; i++ ) + s += cv_abs(a[i]); + return s; +} + +template<typename _Tp, typename _AccTp> static inline +_AccTp normInf(const _Tp* a, int n) +{ + _AccTp s = 0; + for( int i = 0; i < n; i++ ) + s = std::max(s, (_AccTp)cv_abs(a[i])); + return s; +} + +template<typename _Tp, typename _AccTp> static inline +_AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n) +{ + _AccTp s = 0; + int i= 0; +#if CV_ENABLE_UNROLLED + for(; i <= n - 4; i += 4 ) + { + _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]); + s += v0*v0 + v1*v1 + v2*v2 + v3*v3; + } +#endif + for( ; i < n; i++ ) + { + _AccTp v = _AccTp(a[i] - b[i]); + s += v*v; + } + return s; +} + +static inline float normL2Sqr(const float* a, const float* b, int n) +{ + float s = 0.f; + for( int i = 0; i < n; i++ ) + { + float v = a[i] - b[i]; + s += v*v; + } + return s; +} + +template<typename _Tp, typename _AccTp> static inline +_AccTp normL1(const _Tp* a, const _Tp* b, int n) +{ + _AccTp s = 0; + int i= 0; +#if CV_ENABLE_UNROLLED + for(; i <= n - 4; i += 4 ) + { + _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]); + s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3); + } +#endif + for( ; i < n; i++ ) + { + _AccTp v = _AccTp(a[i] - b[i]); + s += std::abs(v); + } + return s; +} + +inline float normL1(const float* a, const float* b, int n) +{ + float s = 0.f; + for( int i = 0; i < n; i++ ) + { + s += std::abs(a[i] - b[i]); + } + return s; +} + +inline int normL1(const uchar* a, const uchar* b, int n) +{ + int s = 0; + for( int i = 0; i < n; i++ ) + { + s += std::abs(a[i] - b[i]); + } + return s; +} + +template<typename _Tp, typename _AccTp> static inline +_AccTp normInf(const _Tp* a, const _Tp* b, int n) +{ + _AccTp s = 0; + for( int i = 0; i < n; i++ ) + { + _AccTp v0 = a[i] - b[i]; + s = std::max(s, std::abs(v0)); + } + return s; +} + +/** @brief Computes the cube root of an argument. + + The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly. + NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for + single-precision data. + @param val A function argument. + */ +CV_EXPORTS_W float cubeRoot(float val); + +/** @brief Calculates the angle of a 2D vector in degrees. + + The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured + in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees. + @param x x-coordinate of the vector. + @param y y-coordinate of the vector. + */ +CV_EXPORTS_W float fastAtan2(float y, float x); + +/** proxy for hal::LU */ +CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); +/** proxy for hal::LU */ +CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); +/** proxy for hal::Cholesky */ +CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); +/** proxy for hal::Cholesky */ +CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); + +////////////////// forward declarations for important OpenCV types ////////////////// + +//! @cond IGNORED + +template<typename _Tp, int cn> class Vec; +template<typename _Tp, int m, int n> class Matx; + +template<typename _Tp> class Complex; +template<typename _Tp> class Point_; +template<typename _Tp> class Point3_; +template<typename _Tp> class Size_; +template<typename _Tp> class Rect_; +template<typename _Tp> class Scalar_; + +class CV_EXPORTS RotatedRect; +class CV_EXPORTS Range; +class CV_EXPORTS TermCriteria; +class CV_EXPORTS KeyPoint; +class CV_EXPORTS DMatch; +class CV_EXPORTS RNG; + +class CV_EXPORTS Mat; +class CV_EXPORTS MatExpr; + +class CV_EXPORTS UMat; + +class CV_EXPORTS SparseMat; +typedef Mat MatND; + +template<typename _Tp> class Mat_; +template<typename _Tp> class SparseMat_; + +class CV_EXPORTS MatConstIterator; +class CV_EXPORTS SparseMatIterator; +class CV_EXPORTS SparseMatConstIterator; +template<typename _Tp> class MatIterator_; +template<typename _Tp> class MatConstIterator_; +template<typename _Tp> class SparseMatIterator_; +template<typename _Tp> class SparseMatConstIterator_; + +namespace ogl +{ + class CV_EXPORTS Buffer; + class CV_EXPORTS Texture2D; + class CV_EXPORTS Arrays; +} + +namespace cuda +{ + class CV_EXPORTS GpuMat; + class CV_EXPORTS HostMem; + class CV_EXPORTS Stream; + class CV_EXPORTS Event; +} + +namespace cudev +{ + template <typename _Tp> class GpuMat_; +} + +namespace ipp +{ +#if OPENCV_ABI_COMPATIBILITY > 300 +CV_EXPORTS unsigned long long getIppFeatures(); +#else +CV_EXPORTS int getIppFeatures(); +#endif +CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, + int line = 0); +CV_EXPORTS int getIppStatus(); +CV_EXPORTS String getIppErrorLocation(); +CV_EXPORTS_W bool useIPP(); +CV_EXPORTS_W void setUseIPP(bool flag); +CV_EXPORTS_W String getIppVersion(); + +// IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results +// but have internal accuracy differences which have too much direct or indirect impact on accuracy tests. +CV_EXPORTS_W bool useIPP_NotExact(); +CV_EXPORTS_W void setUseIPP_NotExact(bool flag); +#if OPENCV_ABI_COMPATIBILITY < 400 +CV_EXPORTS_W bool useIPP_NE(); +CV_EXPORTS_W void setUseIPP_NE(bool flag); +#endif + +} // ipp + +//! @endcond + +//! @} core_utils + + + + +} // cv + +#include "opencv2/core/neon_utils.hpp" +#include "opencv2/core/vsx_utils.hpp" +#include "opencv2/core/check.hpp" + +#endif //OPENCV_CORE_BASE_HPP diff --git a/include/opencv2/core/bindings_utils.hpp b/include/opencv2/core/bindings_utils.hpp new file mode 100644 index 0000000..c1123f2 --- /dev/null +++ b/include/opencv2/core/bindings_utils.hpp @@ -0,0 +1,23 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_BINDINGS_UTILS_HPP +#define OPENCV_CORE_BINDINGS_UTILS_HPP + +namespace cv { namespace utils { +//! @addtogroup core_utils +//! @{ + +CV_EXPORTS_W String dumpInputArray(InputArray argument); + +CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument); + +CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument); + +CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argument); + +//! @} +}} // namespace + +#endif // OPENCV_CORE_BINDINGS_UTILS_HPP diff --git a/include/opencv2/core/bufferpool.hpp b/include/opencv2/core/bufferpool.hpp new file mode 100644 index 0000000..4698e5d --- /dev/null +++ b/include/opencv2/core/bufferpool.hpp @@ -0,0 +1,40 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. + +#ifndef OPENCV_CORE_BUFFER_POOL_HPP +#define OPENCV_CORE_BUFFER_POOL_HPP + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4265) +#endif + +namespace cv +{ + +//! @addtogroup core +//! @{ + +class BufferPoolController +{ +protected: + ~BufferPoolController() { } +public: + virtual size_t getReservedSize() const = 0; + virtual size_t getMaxReservedSize() const = 0; + virtual void setMaxReservedSize(size_t size) = 0; + virtual void freeAllReservedBuffers() = 0; +}; + +//! @} + +} + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif // OPENCV_CORE_BUFFER_POOL_HPP diff --git a/include/opencv2/core/check.hpp b/include/opencv2/core/check.hpp new file mode 100644 index 0000000..bf44138 --- /dev/null +++ b/include/opencv2/core/check.hpp @@ -0,0 +1,157 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_CHECK_HPP +#define OPENCV_CORE_CHECK_HPP + +#include <opencv2/core/base.hpp> + +namespace cv { + +/** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or "<invalid depth>" */ +CV_EXPORTS const char* depthToString(int depth); + +/** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or "<invalid type>" */ +CV_EXPORTS const String typeToString(int type); + + +//! @cond IGNORED +namespace detail { + +/** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or NULL */ +CV_EXPORTS const char* depthToString_(int depth); + +/** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or cv::String() */ +CV_EXPORTS const cv::String typeToString_(int type); + +enum TestOp { + TEST_CUSTOM = 0, + TEST_EQ = 1, + TEST_NE = 2, + TEST_LE = 3, + TEST_LT = 4, + TEST_GE = 5, + TEST_GT = 6, + CV__LAST_TEST_OP +}; + +struct CheckContext { + const char* func; + const char* file; + int line; + enum TestOp testOp; + const char* message; + const char* p1_str; + const char* p2_str; +}; + +#ifndef CV__CHECK_FILENAME +# define CV__CHECK_FILENAME __FILE__ +#endif + +#ifndef CV__CHECK_FUNCTION +# if defined _MSC_VER +# define CV__CHECK_FUNCTION __FUNCSIG__ +# elif defined __GNUC__ +# define CV__CHECK_FUNCTION __PRETTY_FUNCTION__ +# else +# define CV__CHECK_FUNCTION "<unknown>" +# endif +#endif + +#define CV__CHECK_LOCATION_VARNAME(id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_check_, id), __LINE__) +#define CV__DEFINE_CHECK_CONTEXT(id, message, testOp, p1_str, p2_str) \ + static const cv::detail::CheckContext CV__CHECK_LOCATION_VARNAME(id) = \ + { CV__CHECK_FUNCTION, CV__CHECK_FILENAME, __LINE__, testOp, message, p1_str, p2_str } + +CV_EXPORTS void CV_NORETURN check_failed_auto(const int v1, const int v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const float v1, const float v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const double v1, const double v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v1, const int v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v1, const int v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx); + +CV_EXPORTS void CV_NORETURN check_failed_auto(const int v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const float v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const double v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v, const CheckContext& ctx); + + +#define CV__TEST_EQ(v1, v2) ((v1) == (v2)) +#define CV__TEST_NE(v1, v2) ((v1) != (v2)) +#define CV__TEST_LE(v1, v2) ((v1) <= (v2)) +#define CV__TEST_LT(v1, v2) ((v1) < (v2)) +#define CV__TEST_GE(v1, v2) ((v1) >= (v2)) +#define CV__TEST_GT(v1, v2) ((v1) > (v2)) + +#define CV__CHECK(id, op, type, v1, v2, v1_str, v2_str, msg_str) do { \ + if(CV__TEST_##op((v1), (v2))) ; else { \ + CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_ ## op, v1_str, v2_str); \ + cv::detail::check_failed_ ## type((v1), (v2), CV__CHECK_LOCATION_VARNAME(id)); \ + } \ +} while (0) + +#define CV__CHECK_CUSTOM_TEST(id, type, v, test_expr, v_str, test_expr_str, msg_str) do { \ + if(!!(test_expr)) ; else { \ + CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_CUSTOM, v_str, test_expr_str); \ + cv::detail::check_failed_ ## type((v), CV__CHECK_LOCATION_VARNAME(id)); \ + } \ +} while (0) + +} // namespace +//! @endcond + + +/// Supported values of these types: int, float, double +#define CV_CheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg) + +/// Check with additional "decoding" of type values in error message +#define CV_CheckTypeEQ(t1, t2, msg) CV__CHECK(_, EQ, MatType, t1, t2, #t1, #t2, msg) +/// Check with additional "decoding" of depth values in error message +#define CV_CheckDepthEQ(d1, d2, msg) CV__CHECK(_, EQ, MatDepth, d1, d2, #d1, #d2, msg) + +#define CV_CheckChannelsEQ(c1, c2, msg) CV__CHECK(_, EQ, MatChannels, c1, c2, #c1, #c2, msg) + +/// Example: type == CV_8UC1 || type == CV_8UC3 +#define CV_CheckType(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatType, t, (test_expr), #t, #test_expr, msg) + +/// Example: depth == CV_32F || depth == CV_64F +#define CV_CheckDepth(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatDepth, t, (test_expr), #t, #test_expr, msg) + +/// Example: v == A || v == B +#define CV_Check(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg) + +/// Some complex conditions: CV_Check(src2, src2.empty() || (src2.type() == src1.type() && src2.size() == src1.size()), "src2 should have same size/type as src1") +// TODO define pretty-printers + +#ifndef NDEBUG +#define CV_DbgCheck(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg) +#define CV_DbgCheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg) +#else +#define CV_DbgCheck(v, test_expr, msg) do { } while (0) +#define CV_DbgCheckEQ(v1, v2, msg) do { } while (0) +#define CV_DbgCheckNE(v1, v2, msg) do { } while (0) +#define CV_DbgCheckLE(v1, v2, msg) do { } while (0) +#define CV_DbgCheckLT(v1, v2, msg) do { } while (0) +#define CV_DbgCheckGE(v1, v2, msg) do { } while (0) +#define CV_DbgCheckGT(v1, v2, msg) do { } while (0) +#endif + +} // namespace + +#endif // OPENCV_CORE_CHECK_HPP diff --git a/include/opencv2/core/core.hpp b/include/opencv2/core/core.hpp new file mode 100644 index 0000000..4389183 --- /dev/null +++ b/include/opencv2/core/core.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/core.hpp" diff --git a/include/opencv2/core/core_c.h b/include/opencv2/core/core_c.h new file mode 100644 index 0000000..e5fe516 --- /dev/null +++ b/include/opencv2/core/core_c.h @@ -0,0 +1,3175 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + + +#ifndef OPENCV_CORE_C_H +#define OPENCV_CORE_C_H + +#include "opencv2/core/types_c.h" + +#ifdef __cplusplus +# ifdef _MSC_VER +/* disable warning C4190: 'function' has C-linkage specified, but returns UDT 'typename' + which is incompatible with C + + It is OK to disable it because we only extend few plain structures with + C++ construrtors for simpler interoperability with C++ API of the library +*/ +# pragma warning(disable:4190) +# elif defined __clang__ && __clang_major__ >= 3 +# pragma GCC diagnostic ignored "-Wreturn-type-c-linkage" +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup core_c + @{ +*/ + +/****************************************************************************************\ +* Array allocation, deallocation, initialization and access to elements * +\****************************************************************************************/ + +/** `malloc` wrapper. + If there is no enough memory, the function + (as well as other OpenCV functions that call cvAlloc) + raises an error. */ +CVAPI(void*) cvAlloc( size_t size ); + +/** `free` wrapper. + Here and further all the memory releasing functions + (that all call cvFree) take double pointer in order to + to clear pointer to the data after releasing it. + Passing pointer to NULL pointer is Ok: nothing happens in this case +*/ +CVAPI(void) cvFree_( void* ptr ); +#define cvFree(ptr) (cvFree_(*(ptr)), *(ptr)=0) + +/** @brief Creates an image header but does not allocate the image data. + +@param size Image width and height +@param depth Image depth (see cvCreateImage ) +@param channels Number of channels (see cvCreateImage ) + */ +CVAPI(IplImage*) cvCreateImageHeader( CvSize size, int depth, int channels ); + +/** @brief Initializes an image header that was previously allocated. + +The returned IplImage\* points to the initialized header. +@param image Image header to initialize +@param size Image width and height +@param depth Image depth (see cvCreateImage ) +@param channels Number of channels (see cvCreateImage ) +@param origin Top-left IPL_ORIGIN_TL or bottom-left IPL_ORIGIN_BL +@param align Alignment for image rows, typically 4 or 8 bytes + */ +CVAPI(IplImage*) cvInitImageHeader( IplImage* image, CvSize size, int depth, + int channels, int origin CV_DEFAULT(0), + int align CV_DEFAULT(4)); + +/** @brief Creates an image header and allocates the image data. + +This function call is equivalent to the following code: +@code + header = cvCreateImageHeader(size, depth, channels); + cvCreateData(header); +@endcode +@param size Image width and height +@param depth Bit depth of image elements. See IplImage for valid depths. +@param channels Number of channels per pixel. See IplImage for details. This function only creates +images with interleaved channels. + */ +CVAPI(IplImage*) cvCreateImage( CvSize size, int depth, int channels ); + +/** @brief Deallocates an image header. + +This call is an analogue of : +@code + if(image ) + { + iplDeallocate(*image, IPL_IMAGE_HEADER | IPL_IMAGE_ROI); + *image = 0; + } +@endcode +but it does not use IPL functions by default (see the CV_TURN_ON_IPL_COMPATIBILITY macro). +@param image Double pointer to the image header + */ +CVAPI(void) cvReleaseImageHeader( IplImage** image ); + +/** @brief Deallocates the image header and the image data. + +This call is a shortened form of : +@code + if(*image ) + { + cvReleaseData(*image); + cvReleaseImageHeader(image); + } +@endcode +@param image Double pointer to the image header +*/ +CVAPI(void) cvReleaseImage( IplImage** image ); + +/** Creates a copy of IPL image (widthStep may differ) */ +CVAPI(IplImage*) cvCloneImage( const IplImage* image ); + +/** @brief Sets the channel of interest in an IplImage. + +If the ROI is set to NULL and the coi is *not* 0, the ROI is allocated. Most OpenCV functions do +*not* support the COI setting, so to process an individual image/matrix channel one may copy (via +cvCopy or cvSplit) the channel to a separate image/matrix, process it and then copy the result +back (via cvCopy or cvMerge) if needed. +@param image A pointer to the image header +@param coi The channel of interest. 0 - all channels are selected, 1 - first channel is selected, +etc. Note that the channel indices become 1-based. + */ +CVAPI(void) cvSetImageCOI( IplImage* image, int coi ); + +/** @brief Returns the index of the channel of interest. + +Returns the channel of interest of in an IplImage. Returned values correspond to the coi in +cvSetImageCOI. +@param image A pointer to the image header + */ +CVAPI(int) cvGetImageCOI( const IplImage* image ); + +/** @brief Sets an image Region Of Interest (ROI) for a given rectangle. + +If the original image ROI was NULL and the rect is not the whole image, the ROI structure is +allocated. + +Most OpenCV functions support the use of ROI and treat the image rectangle as a separate image. For +example, all of the pixel coordinates are counted from the top-left (or bottom-left) corner of the +ROI, not the original image. +@param image A pointer to the image header +@param rect The ROI rectangle + */ +CVAPI(void) cvSetImageROI( IplImage* image, CvRect rect ); + +/** @brief Resets the image ROI to include the entire image and releases the ROI structure. + +This produces a similar result to the following, but in addition it releases the ROI structure. : +@code + cvSetImageROI(image, cvRect(0, 0, image->width, image->height )); + cvSetImageCOI(image, 0); +@endcode +@param image A pointer to the image header + */ +CVAPI(void) cvResetImageROI( IplImage* image ); + +/** @brief Returns the image ROI. + +If there is no ROI set, cvRect(0,0,image-\>width,image-\>height) is returned. +@param image A pointer to the image header + */ +CVAPI(CvRect) cvGetImageROI( const IplImage* image ); + +/** @brief Creates a matrix header but does not allocate the matrix data. + +The function allocates a new matrix header and returns a pointer to it. The matrix data can then be +allocated using cvCreateData or set explicitly to user-allocated data via cvSetData. +@param rows Number of rows in the matrix +@param cols Number of columns in the matrix +@param type Type of the matrix elements, see cvCreateMat + */ +CVAPI(CvMat*) cvCreateMatHeader( int rows, int cols, int type ); + +#define CV_AUTOSTEP 0x7fffffff + +/** @brief Initializes a pre-allocated matrix header. + +This function is often used to process raw data with OpenCV matrix functions. For example, the +following code computes the matrix product of two matrices, stored as ordinary arrays: +@code + double a[] = { 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12 }; + + double b[] = { 1, 5, 9, + 2, 6, 10, + 3, 7, 11, + 4, 8, 12 }; + + double c[9]; + CvMat Ma, Mb, Mc ; + + cvInitMatHeader(&Ma, 3, 4, CV_64FC1, a); + cvInitMatHeader(&Mb, 4, 3, CV_64FC1, b); + cvInitMatHeader(&Mc, 3, 3, CV_64FC1, c); + + cvMatMulAdd(&Ma, &Mb, 0, &Mc); + // the c array now contains the product of a (3x4) and b (4x3) +@endcode +@param mat A pointer to the matrix header to be initialized +@param rows Number of rows in the matrix +@param cols Number of columns in the matrix +@param type Type of the matrix elements, see cvCreateMat . +@param data Optional: data pointer assigned to the matrix header +@param step Optional: full row width in bytes of the assigned data. By default, the minimal +possible step is used which assumes there are no gaps between subsequent rows of the matrix. + */ +CVAPI(CvMat*) cvInitMatHeader( CvMat* mat, int rows, int cols, + int type, void* data CV_DEFAULT(NULL), + int step CV_DEFAULT(CV_AUTOSTEP) ); + +/** @brief Creates a matrix header and allocates the matrix data. + +The function call is equivalent to the following code: +@code + CvMat* mat = cvCreateMatHeader(rows, cols, type); + cvCreateData(mat); +@endcode +@param rows Number of rows in the matrix +@param cols Number of columns in the matrix +@param type The type of the matrix elements in the form +CV_\<bit depth\>\<S|U|F\>C\<number of channels\> , where S=signed, U=unsigned, F=float. For +example, CV _ 8UC1 means the elements are 8-bit unsigned and the there is 1 channel, and CV _ +32SC2 means the elements are 32-bit signed and there are 2 channels. + */ +CVAPI(CvMat*) cvCreateMat( int rows, int cols, int type ); + +/** @brief Deallocates a matrix. + +The function decrements the matrix data reference counter and deallocates matrix header. If the data +reference counter is 0, it also deallocates the data. : +@code + if(*mat ) + cvDecRefData(*mat); + cvFree((void**)mat); +@endcode +@param mat Double pointer to the matrix + */ +CVAPI(void) cvReleaseMat( CvMat** mat ); + +/** @brief Decrements an array data reference counter. + +The function decrements the data reference counter in a CvMat or CvMatND if the reference counter + +pointer is not NULL. If the counter reaches zero, the data is deallocated. In the current +implementation the reference counter is not NULL only if the data was allocated using the +cvCreateData function. The counter will be NULL in other cases such as: external data was assigned +to the header using cvSetData, header is part of a larger matrix or image, or the header was +converted from an image or n-dimensional matrix header. +@param arr Pointer to an array header + */ +CV_INLINE void cvDecRefData( CvArr* arr ) +{ + if( CV_IS_MAT( arr )) + { + CvMat* mat = (CvMat*)arr; + mat->data.ptr = NULL; + if( mat->refcount != NULL && --*mat->refcount == 0 ) + cvFree( &mat->refcount ); + mat->refcount = NULL; + } + else if( CV_IS_MATND( arr )) + { + CvMatND* mat = (CvMatND*)arr; + mat->data.ptr = NULL; + if( mat->refcount != NULL && --*mat->refcount == 0 ) + cvFree( &mat->refcount ); + mat->refcount = NULL; + } +} + +/** @brief Increments array data reference counter. + +The function increments CvMat or CvMatND data reference counter and returns the new counter value if +the reference counter pointer is not NULL, otherwise it returns zero. +@param arr Array header + */ +CV_INLINE int cvIncRefData( CvArr* arr ) +{ + int refcount = 0; + if( CV_IS_MAT( arr )) + { + CvMat* mat = (CvMat*)arr; + if( mat->refcount != NULL ) + refcount = ++*mat->refcount; + } + else if( CV_IS_MATND( arr )) + { + CvMatND* mat = (CvMatND*)arr; + if( mat->refcount != NULL ) + refcount = ++*mat->refcount; + } + return refcount; +} + + +/** Creates an exact copy of the input matrix (except, may be, step value) */ +CVAPI(CvMat*) cvCloneMat( const CvMat* mat ); + + +/** @brief Returns matrix header corresponding to the rectangular sub-array of input image or matrix. + +The function returns header, corresponding to a specified rectangle of the input array. In other + +words, it allows the user to treat a rectangular part of input array as a stand-alone array. ROI is +taken into account by the function so the sub-array of ROI is actually extracted. +@param arr Input array +@param submat Pointer to the resultant sub-array header +@param rect Zero-based coordinates of the rectangle of interest + */ +CVAPI(CvMat*) cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect ); +#define cvGetSubArr cvGetSubRect + +/** @brief Returns array row or row span. + +The function returns the header, corresponding to a specified row/row span of the input array. +cvGetRow(arr, submat, row) is a shortcut for cvGetRows(arr, submat, row, row+1). +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param start_row Zero-based index of the starting row (inclusive) of the span +@param end_row Zero-based index of the ending row (exclusive) of the span +@param delta_row Index step in the row span. That is, the function extracts every delta_row -th +row from start_row and up to (but not including) end_row . + */ +CVAPI(CvMat*) cvGetRows( const CvArr* arr, CvMat* submat, + int start_row, int end_row, + int delta_row CV_DEFAULT(1)); + +/** @overload +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param row Zero-based index of the selected row +*/ +CV_INLINE CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row ) +{ + return cvGetRows( arr, submat, row, row + 1, 1 ); +} + + +/** @brief Returns one of more array columns. + +The function returns the header, corresponding to a specified column span of the input array. That + +is, no data is copied. Therefore, any modifications of the submatrix will affect the original array. +If you need to copy the columns, use cvCloneMat. cvGetCol(arr, submat, col) is a shortcut for +cvGetCols(arr, submat, col, col+1). +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param start_col Zero-based index of the starting column (inclusive) of the span +@param end_col Zero-based index of the ending column (exclusive) of the span + */ +CVAPI(CvMat*) cvGetCols( const CvArr* arr, CvMat* submat, + int start_col, int end_col ); + +/** @overload +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param col Zero-based index of the selected column +*/ +CV_INLINE CvMat* cvGetCol( const CvArr* arr, CvMat* submat, int col ) +{ + return cvGetCols( arr, submat, col, col + 1 ); +} + +/** @brief Returns one of array diagonals. + +The function returns the header, corresponding to a specified diagonal of the input array. +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param diag Index of the array diagonal. Zero value corresponds to the main diagonal, -1 +corresponds to the diagonal above the main, 1 corresponds to the diagonal below the main, and so +forth. + */ +CVAPI(CvMat*) cvGetDiag( const CvArr* arr, CvMat* submat, + int diag CV_DEFAULT(0)); + +/** low-level scalar <-> raw data conversion functions */ +CVAPI(void) cvScalarToRawData( const CvScalar* scalar, void* data, int type, + int extend_to_12 CV_DEFAULT(0) ); + +CVAPI(void) cvRawDataToScalar( const void* data, int type, CvScalar* scalar ); + +/** @brief Creates a new matrix header but does not allocate the matrix data. + +The function allocates a header for a multi-dimensional dense array. The array data can further be +allocated using cvCreateData or set explicitly to user-allocated data via cvSetData. +@param dims Number of array dimensions +@param sizes Array of dimension sizes +@param type Type of array elements, see cvCreateMat + */ +CVAPI(CvMatND*) cvCreateMatNDHeader( int dims, const int* sizes, int type ); + +/** @brief Creates the header and allocates the data for a multi-dimensional dense array. + +This function call is equivalent to the following code: +@code + CvMatND* mat = cvCreateMatNDHeader(dims, sizes, type); + cvCreateData(mat); +@endcode +@param dims Number of array dimensions. This must not exceed CV_MAX_DIM (32 by default, but can be +changed at build time). +@param sizes Array of dimension sizes. +@param type Type of array elements, see cvCreateMat . + */ +CVAPI(CvMatND*) cvCreateMatND( int dims, const int* sizes, int type ); + +/** @brief Initializes a pre-allocated multi-dimensional array header. + +@param mat A pointer to the array header to be initialized +@param dims The number of array dimensions +@param sizes An array of dimension sizes +@param type Type of array elements, see cvCreateMat +@param data Optional data pointer assigned to the matrix header + */ +CVAPI(CvMatND*) cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes, + int type, void* data CV_DEFAULT(NULL) ); + +/** @brief Deallocates a multi-dimensional array. + +The function decrements the array data reference counter and releases the array header. If the +reference counter reaches 0, it also deallocates the data. : +@code + if(*mat ) + cvDecRefData(*mat); + cvFree((void**)mat); +@endcode +@param mat Double pointer to the array + */ +CV_INLINE void cvReleaseMatND( CvMatND** mat ) +{ + cvReleaseMat( (CvMat**)mat ); +} + +/** Creates a copy of CvMatND (except, may be, steps) */ +CVAPI(CvMatND*) cvCloneMatND( const CvMatND* mat ); + +/** @brief Creates sparse array. + +The function allocates a multi-dimensional sparse array. Initially the array contain no elements, +that is PtrND and other related functions will return 0 for every index. +@param dims Number of array dimensions. In contrast to the dense matrix, the number of dimensions is +practically unlimited (up to \f$2^{16}\f$ ). +@param sizes Array of dimension sizes +@param type Type of array elements. The same as for CvMat + */ +CVAPI(CvSparseMat*) cvCreateSparseMat( int dims, const int* sizes, int type ); + +/** @brief Deallocates sparse array. + +The function releases the sparse array and clears the array pointer upon exit. +@param mat Double pointer to the array + */ +CVAPI(void) cvReleaseSparseMat( CvSparseMat** mat ); + +/** Creates a copy of CvSparseMat (except, may be, zero items) */ +CVAPI(CvSparseMat*) cvCloneSparseMat( const CvSparseMat* mat ); + +/** @brief Initializes sparse array elements iterator. + +The function initializes iterator of sparse array elements and returns pointer to the first element, +or NULL if the array is empty. +@param mat Input array +@param mat_iterator Initialized iterator + */ +CVAPI(CvSparseNode*) cvInitSparseMatIterator( const CvSparseMat* mat, + CvSparseMatIterator* mat_iterator ); + +/** @brief Returns the next sparse matrix element + +The function moves iterator to the next sparse matrix element and returns pointer to it. In the +current version there is no any particular order of the elements, because they are stored in the +hash table. The sample below demonstrates how to iterate through the sparse matrix: +@code + // print all the non-zero sparse matrix elements and compute their sum + double sum = 0; + int i, dims = cvGetDims(sparsemat); + CvSparseMatIterator it; + CvSparseNode* node = cvInitSparseMatIterator(sparsemat, &it); + + for(; node != 0; node = cvGetNextSparseNode(&it)) + { + int* idx = CV_NODE_IDX(array, node); + float val = *(float*)CV_NODE_VAL(array, node); + printf("M"); + for(i = 0; i < dims; i++ ) + printf("[%d]", idx[i]); + printf("=%g\n", val); + + sum += val; + } + + printf("nTotal sum = %g\n", sum); +@endcode +@param mat_iterator Sparse array iterator + */ +CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* mat_iterator ) +{ + if( mat_iterator->node->next ) + return mat_iterator->node = mat_iterator->node->next; + else + { + int idx; + for( idx = ++mat_iterator->curidx; idx < mat_iterator->mat->hashsize; idx++ ) + { + CvSparseNode* node = (CvSparseNode*)mat_iterator->mat->hashtable[idx]; + if( node ) + { + mat_iterator->curidx = idx; + return mat_iterator->node = node; + } + } + return NULL; + } +} + + +#define CV_MAX_ARR 10 + +/** matrix iterator: used for n-ary operations on dense arrays */ +typedef struct CvNArrayIterator +{ + int count; /**< number of arrays */ + int dims; /**< number of dimensions to iterate */ + CvSize size; /**< maximal common linear size: { width = size, height = 1 } */ + uchar* ptr[CV_MAX_ARR]; /**< pointers to the array slices */ + int stack[CV_MAX_DIM]; /**< for internal use */ + CvMatND* hdr[CV_MAX_ARR]; /**< pointers to the headers of the + matrices that are processed */ +} +CvNArrayIterator; + +#define CV_NO_DEPTH_CHECK 1 +#define CV_NO_CN_CHECK 2 +#define CV_NO_SIZE_CHECK 4 + +/** initializes iterator that traverses through several arrays simulteneously + (the function together with cvNextArraySlice is used for + N-ari element-wise operations) */ +CVAPI(int) cvInitNArrayIterator( int count, CvArr** arrs, + const CvArr* mask, CvMatND* stubs, + CvNArrayIterator* array_iterator, + int flags CV_DEFAULT(0) ); + +/** returns zero value if iteration is finished, non-zero (slice length) otherwise */ +CVAPI(int) cvNextNArraySlice( CvNArrayIterator* array_iterator ); + + +/** @brief Returns type of array elements. + +The function returns type of the array elements. In the case of IplImage the type is converted to +CvMat-like representation. For example, if the image has been created as: +@code + IplImage* img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3); +@endcode +The code cvGetElemType(img) will return CV_8UC3. +@param arr Input array + */ +CVAPI(int) cvGetElemType( const CvArr* arr ); + +/** @brief Return number of array dimensions + +The function returns the array dimensionality and the array of dimension sizes. In the case of +IplImage or CvMat it always returns 2 regardless of number of image/matrix rows. For example, the +following code calculates total number of array elements: +@code + int sizes[CV_MAX_DIM]; + int i, total = 1; + int dims = cvGetDims(arr, size); + for(i = 0; i < dims; i++ ) + total *= sizes[i]; +@endcode +@param arr Input array +@param sizes Optional output vector of the array dimension sizes. For 2d arrays the number of rows +(height) goes first, number of columns (width) next. + */ +CVAPI(int) cvGetDims( const CvArr* arr, int* sizes CV_DEFAULT(NULL) ); + + +/** @brief Returns array size along the specified dimension. + +@param arr Input array +@param index Zero-based dimension index (for matrices 0 means number of rows, 1 means number of +columns; for images 0 means height, 1 means width) + */ +CVAPI(int) cvGetDimSize( const CvArr* arr, int index ); + + +/** @brief Return pointer to a particular array element. + +The functions return a pointer to a specific array element. Number of array dimension should match +to the number of indices passed to the function except for cvPtr1D function that can be used for +sequential access to 1D, 2D or nD dense arrays. + +The functions can be used for sparse arrays as well - if the requested node does not exist they +create it and set it to zero. + +All these as well as other functions accessing array elements ( cvGetND , cvGetRealND , cvSet +, cvSetND , cvSetRealND ) raise an error in case if the element index is out of range. +@param arr Input array +@param idx0 The first zero-based component of the element index +@param type Optional output parameter: type of matrix elements + */ +CVAPI(uchar*) cvPtr1D( const CvArr* arr, int idx0, int* type CV_DEFAULT(NULL)); +/** @overload */ +CVAPI(uchar*) cvPtr2D( const CvArr* arr, int idx0, int idx1, int* type CV_DEFAULT(NULL) ); +/** @overload */ +CVAPI(uchar*) cvPtr3D( const CvArr* arr, int idx0, int idx1, int idx2, + int* type CV_DEFAULT(NULL)); +/** @overload +@param arr Input array +@param idx Array of the element indices +@param type Optional output parameter: type of matrix elements +@param create_node Optional input parameter for sparse matrices. Non-zero value of the parameter +means that the requested element is created if it does not exist already. +@param precalc_hashval Optional input parameter for sparse matrices. If the pointer is not NULL, +the function does not recalculate the node hash value, but takes it from the specified location. +It is useful for speeding up pair-wise operations (TODO: provide an example) +*/ +CVAPI(uchar*) cvPtrND( const CvArr* arr, const int* idx, int* type CV_DEFAULT(NULL), + int create_node CV_DEFAULT(1), + unsigned* precalc_hashval CV_DEFAULT(NULL)); + +/** @brief Return a specific array element. + +The functions return a specific array element. In the case of a sparse array the functions return 0 +if the requested node does not exist (no new node is created by the functions). +@param arr Input array +@param idx0 The first zero-based component of the element index + */ +CVAPI(CvScalar) cvGet1D( const CvArr* arr, int idx0 ); +/** @overload */ +CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 ); +/** @overload */ +CVAPI(CvScalar) cvGet3D( const CvArr* arr, int idx0, int idx1, int idx2 ); +/** @overload +@param arr Input array +@param idx Array of the element indices +*/ +CVAPI(CvScalar) cvGetND( const CvArr* arr, const int* idx ); + +/** @brief Return a specific element of single-channel 1D, 2D, 3D or nD array. + +Returns a specific element of a single-channel array. If the array has multiple channels, a runtime +error is raised. Note that Get?D functions can be used safely for both single-channel and +multiple-channel arrays though they are a bit slower. + +In the case of a sparse array the functions return 0 if the requested node does not exist (no new +node is created by the functions). +@param arr Input array. Must have a single channel. +@param idx0 The first zero-based component of the element index + */ +CVAPI(double) cvGetReal1D( const CvArr* arr, int idx0 ); +/** @overload */ +CVAPI(double) cvGetReal2D( const CvArr* arr, int idx0, int idx1 ); +/** @overload */ +CVAPI(double) cvGetReal3D( const CvArr* arr, int idx0, int idx1, int idx2 ); +/** @overload +@param arr Input array. Must have a single channel. +@param idx Array of the element indices +*/ +CVAPI(double) cvGetRealND( const CvArr* arr, const int* idx ); + +/** @brief Change the particular array element. + +The functions assign the new value to a particular array element. In the case of a sparse array the +functions create the node if it does not exist yet. +@param arr Input array +@param idx0 The first zero-based component of the element index +@param value The assigned value + */ +CVAPI(void) cvSet1D( CvArr* arr, int idx0, CvScalar value ); +/** @overload */ +CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value ); +/** @overload */ +CVAPI(void) cvSet3D( CvArr* arr, int idx0, int idx1, int idx2, CvScalar value ); +/** @overload +@param arr Input array +@param idx Array of the element indices +@param value The assigned value +*/ +CVAPI(void) cvSetND( CvArr* arr, const int* idx, CvScalar value ); + +/** @brief Change a specific array element. + +The functions assign a new value to a specific element of a single-channel array. If the array has +multiple channels, a runtime error is raised. Note that the Set\*D function can be used safely for +both single-channel and multiple-channel arrays, though they are a bit slower. + +In the case of a sparse array the functions create the node if it does not yet exist. +@param arr Input array +@param idx0 The first zero-based component of the element index +@param value The assigned value + */ +CVAPI(void) cvSetReal1D( CvArr* arr, int idx0, double value ); +/** @overload */ +CVAPI(void) cvSetReal2D( CvArr* arr, int idx0, int idx1, double value ); +/** @overload */ +CVAPI(void) cvSetReal3D( CvArr* arr, int idx0, + int idx1, int idx2, double value ); +/** @overload +@param arr Input array +@param idx Array of the element indices +@param value The assigned value +*/ +CVAPI(void) cvSetRealND( CvArr* arr, const int* idx, double value ); + +/** clears element of ND dense array, + in case of sparse arrays it deletes the specified node */ +CVAPI(void) cvClearND( CvArr* arr, const int* idx ); + +/** @brief Returns matrix header for arbitrary array. + +The function returns a matrix header for the input array that can be a matrix - CvMat, an image - +IplImage, or a multi-dimensional dense array - CvMatND (the third option is allowed only if +allowND != 0) . In the case of matrix the function simply returns the input pointer. In the case of +IplImage\* or CvMatND it initializes the header structure with parameters of the current image ROI +and returns &header. Because COI is not supported by CvMat, it is returned separately. + +The function provides an easy way to handle both types of arrays - IplImage and CvMat using the same +code. Input array must have non-zero data pointer, otherwise the function will report an error. + +@note If the input array is IplImage with planar data layout and COI set, the function returns the +pointer to the selected plane and COI == 0. This feature allows user to process IplImage structures +with planar data layout, even though OpenCV does not support such images. +@param arr Input array +@param header Pointer to CvMat structure used as a temporary buffer +@param coi Optional output parameter for storing COI +@param allowND If non-zero, the function accepts multi-dimensional dense arrays (CvMatND\*) and +returns 2D matrix (if CvMatND has two dimensions) or 1D matrix (when CvMatND has 1 dimension or +more than 2 dimensions). The CvMatND array must be continuous. +@sa cvGetImage, cvarrToMat. + */ +CVAPI(CvMat*) cvGetMat( const CvArr* arr, CvMat* header, + int* coi CV_DEFAULT(NULL), + int allowND CV_DEFAULT(0)); + +/** @brief Returns image header for arbitrary array. + +The function returns the image header for the input array that can be a matrix (CvMat) or image +(IplImage). In the case of an image the function simply returns the input pointer. In the case of +CvMat it initializes an image_header structure with the parameters of the input matrix. Note that +if we transform IplImage to CvMat using cvGetMat and then transform CvMat back to IplImage using +this function, we will get different headers if the ROI is set in the original image. +@param arr Input array +@param image_header Pointer to IplImage structure used as a temporary buffer + */ +CVAPI(IplImage*) cvGetImage( const CvArr* arr, IplImage* image_header ); + + +/** @brief Changes the shape of a multi-dimensional array without copying the data. + +The function is an advanced version of cvReshape that can work with multi-dimensional arrays as +well (though it can work with ordinary images and matrices) and change the number of dimensions. + +Below are the two samples from the cvReshape description rewritten using cvReshapeMatND: +@code + IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3); + IplImage gray_img_hdr, *gray_img; + gray_img = (IplImage*)cvReshapeMatND(color_img, sizeof(gray_img_hdr), &gray_img_hdr, 1, 0, 0); + ... + int size[] = { 2, 2, 2 }; + CvMatND* mat = cvCreateMatND(3, size, CV_32F); + CvMat row_header, *row; + row = (CvMat*)cvReshapeMatND(mat, sizeof(row_header), &row_header, 0, 1, 0); +@endcode +In C, the header file for this function includes a convenient macro cvReshapeND that does away with +the sizeof_header parameter. So, the lines containing the call to cvReshapeMatND in the examples +may be replaced as follow: +@code + gray_img = (IplImage*)cvReshapeND(color_img, &gray_img_hdr, 1, 0, 0); + ... + row = (CvMat*)cvReshapeND(mat, &row_header, 0, 1, 0); +@endcode +@param arr Input array +@param sizeof_header Size of output header to distinguish between IplImage, CvMat and CvMatND +output headers +@param header Output header to be filled +@param new_cn New number of channels. new_cn = 0 means that the number of channels remains +unchanged. +@param new_dims New number of dimensions. new_dims = 0 means that the number of dimensions +remains the same. +@param new_sizes Array of new dimension sizes. Only new_dims-1 values are used, because the +total number of elements must remain the same. Thus, if new_dims = 1, new_sizes array is not +used. + */ +CVAPI(CvArr*) cvReshapeMatND( const CvArr* arr, + int sizeof_header, CvArr* header, + int new_cn, int new_dims, int* new_sizes ); + +#define cvReshapeND( arr, header, new_cn, new_dims, new_sizes ) \ + cvReshapeMatND( (arr), sizeof(*(header)), (header), \ + (new_cn), (new_dims), (new_sizes)) + +/** @brief Changes shape of matrix/image without copying data. + +The function initializes the CvMat header so that it points to the same data as the original array +but has a different shape - different number of channels, different number of rows, or both. + +The following example code creates one image buffer and two image headers, the first is for a +320x240x3 image and the second is for a 960x240x1 image: +@code + IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3); + CvMat gray_mat_hdr; + IplImage gray_img_hdr, *gray_img; + cvReshape(color_img, &gray_mat_hdr, 1); + gray_img = cvGetImage(&gray_mat_hdr, &gray_img_hdr); +@endcode +And the next example converts a 3x3 matrix to a single 1x9 vector: +@code + CvMat* mat = cvCreateMat(3, 3, CV_32F); + CvMat row_header, *row; + row = cvReshape(mat, &row_header, 0, 1); +@endcode +@param arr Input array +@param header Output header to be filled +@param new_cn New number of channels. 'new_cn = 0' means that the number of channels remains +unchanged. +@param new_rows New number of rows. 'new_rows = 0' means that the number of rows remains +unchanged unless it needs to be changed according to new_cn value. +*/ +CVAPI(CvMat*) cvReshape( const CvArr* arr, CvMat* header, + int new_cn, int new_rows CV_DEFAULT(0) ); + +/** Repeats source 2d array several times in both horizontal and + vertical direction to fill destination array */ +CVAPI(void) cvRepeat( const CvArr* src, CvArr* dst ); + +/** @brief Allocates array data + +The function allocates image, matrix or multi-dimensional dense array data. Note that in the case of +matrix types OpenCV allocation functions are used. In the case of IplImage they are used unless +CV_TURN_ON_IPL_COMPATIBILITY() has been called before. In the latter case IPL functions are used +to allocate the data. +@param arr Array header + */ +CVAPI(void) cvCreateData( CvArr* arr ); + +/** @brief Releases array data. + +The function releases the array data. In the case of CvMat or CvMatND it simply calls +cvDecRefData(), that is the function can not deallocate external data. See also the note to +cvCreateData . +@param arr Array header + */ +CVAPI(void) cvReleaseData( CvArr* arr ); + +/** @brief Assigns user data to the array header. + +The function assigns user data to the array header. Header should be initialized before using +cvCreateMatHeader, cvCreateImageHeader, cvCreateMatNDHeader, cvInitMatHeader, +cvInitImageHeader or cvInitMatNDHeader. +@param arr Array header +@param data User data +@param step Full row length in bytes + */ +CVAPI(void) cvSetData( CvArr* arr, void* data, int step ); + +/** @brief Retrieves low-level information about the array. + +The function fills output variables with low-level information about the array data. All output + +parameters are optional, so some of the pointers may be set to NULL. If the array is IplImage with +ROI set, the parameters of ROI are returned. + +The following example shows how to get access to array elements. It computes absolute values of the +array elements : +@code + float* data; + int step; + CvSize size; + + cvGetRawData(array, (uchar**)&data, &step, &size); + step /= sizeof(data[0]); + + for(int y = 0; y < size.height; y++, data += step ) + for(int x = 0; x < size.width; x++ ) + data[x] = (float)fabs(data[x]); +@endcode +@param arr Array header +@param data Output pointer to the whole image origin or ROI origin if ROI is set +@param step Output full row length in bytes +@param roi_size Output ROI size + */ +CVAPI(void) cvGetRawData( const CvArr* arr, uchar** data, + int* step CV_DEFAULT(NULL), + CvSize* roi_size CV_DEFAULT(NULL)); + +/** @brief Returns size of matrix or image ROI. + +The function returns number of rows (CvSize::height) and number of columns (CvSize::width) of the +input matrix or image. In the case of image the size of ROI is returned. +@param arr array header + */ +CVAPI(CvSize) cvGetSize( const CvArr* arr ); + +/** @brief Copies one array to another. + +The function copies selected elements from an input array to an output array: + +\f[\texttt{dst} (I)= \texttt{src} (I) \quad \text{if} \quad \texttt{mask} (I) \ne 0.\f] + +If any of the passed arrays is of IplImage type, then its ROI and COI fields are used. Both arrays +must have the same type, the same number of dimensions, and the same size. The function can also +copy sparse arrays (mask is not supported in this case). +@param src The source array +@param dst The destination array +@param mask Operation mask, 8-bit single channel array; specifies elements of the destination array +to be changed + */ +CVAPI(void) cvCopy( const CvArr* src, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Sets every element of an array to a given value. + +The function copies the scalar value to every selected element of the destination array: +\f[\texttt{arr} (I)= \texttt{value} \quad \text{if} \quad \texttt{mask} (I) \ne 0\f] +If array arr is of IplImage type, then is ROI used, but COI must not be set. +@param arr The destination array +@param value Fill value +@param mask Operation mask, 8-bit single channel array; specifies elements of the destination +array to be changed + */ +CVAPI(void) cvSet( CvArr* arr, CvScalar value, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Clears the array. + +The function clears the array. In the case of dense arrays (CvMat, CvMatND or IplImage), +cvZero(array) is equivalent to cvSet(array,cvScalarAll(0),0). In the case of sparse arrays all the +elements are removed. +@param arr Array to be cleared + */ +CVAPI(void) cvSetZero( CvArr* arr ); +#define cvZero cvSetZero + + +/** Splits a multi-channel array into the set of single-channel arrays or + extracts particular [color] plane */ +CVAPI(void) cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1, + CvArr* dst2, CvArr* dst3 ); + +/** Merges a set of single-channel arrays into the single multi-channel array + or inserts one particular [color] plane to the array */ +CVAPI(void) cvMerge( const CvArr* src0, const CvArr* src1, + const CvArr* src2, const CvArr* src3, + CvArr* dst ); + +/** Copies several channels from input arrays to + certain channels of output arrays */ +CVAPI(void) cvMixChannels( const CvArr** src, int src_count, + CvArr** dst, int dst_count, + const int* from_to, int pair_count ); + +/** @brief Converts one array to another with optional linear transformation. + +The function has several different purposes, and thus has several different names. It copies one +array to another with optional scaling, which is performed first, and/or optional type conversion, +performed after: + +\f[\texttt{dst} (I) = \texttt{scale} \texttt{src} (I) + ( \texttt{shift} _0, \texttt{shift} _1,...)\f] + +All the channels of multi-channel arrays are processed independently. + +The type of conversion is done with rounding and saturation, that is if the result of scaling + +conversion can not be represented exactly by a value of the destination array element type, it is +set to the nearest representable value on the real axis. +@param src Source array +@param dst Destination array +@param scale Scale factor +@param shift Value added to the scaled source array elements + */ +CVAPI(void) cvConvertScale( const CvArr* src, CvArr* dst, + double scale CV_DEFAULT(1), + double shift CV_DEFAULT(0) ); +#define cvCvtScale cvConvertScale +#define cvScale cvConvertScale +#define cvConvert( src, dst ) cvConvertScale( (src), (dst), 1, 0 ) + + +/** Performs linear transformation on every source array element, + stores absolute value of the result: + dst(x,y,c) = abs(scale*src(x,y,c)+shift). + destination array must have 8u type. + In other cases one may use cvConvertScale + cvAbsDiffS */ +CVAPI(void) cvConvertScaleAbs( const CvArr* src, CvArr* dst, + double scale CV_DEFAULT(1), + double shift CV_DEFAULT(0) ); +#define cvCvtScaleAbs cvConvertScaleAbs + + +/** checks termination criteria validity and + sets eps to default_eps (if it is not set), + max_iter to default_max_iters (if it is not set) +*/ +CVAPI(CvTermCriteria) cvCheckTermCriteria( CvTermCriteria criteria, + double default_eps, + int default_max_iters ); + +/****************************************************************************************\ +* Arithmetic, logic and comparison operations * +\****************************************************************************************/ + +/** dst(mask) = src1(mask) + src2(mask) */ +CVAPI(void) cvAdd( const CvArr* src1, const CvArr* src2, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(mask) = src(mask) + value */ +CVAPI(void) cvAddS( const CvArr* src, CvScalar value, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(mask) = src1(mask) - src2(mask) */ +CVAPI(void) cvSub( const CvArr* src1, const CvArr* src2, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(mask) = src(mask) - value = src(mask) + (-value) */ +CV_INLINE void cvSubS( const CvArr* src, CvScalar value, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)) +{ + cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]), + dst, mask ); +} + +/** dst(mask) = value - src(mask) */ +CVAPI(void) cvSubRS( const CvArr* src, CvScalar value, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src1(idx) * src2(idx) * scale + (scaled element-wise multiplication of 2 arrays) */ +CVAPI(void) cvMul( const CvArr* src1, const CvArr* src2, + CvArr* dst, double scale CV_DEFAULT(1) ); + +/** element-wise division/inversion with scaling: + dst(idx) = src1(idx) * scale / src2(idx) + or dst(idx) = scale / src2(idx) if src1 == 0 */ +CVAPI(void) cvDiv( const CvArr* src1, const CvArr* src2, + CvArr* dst, double scale CV_DEFAULT(1)); + +/** dst = src1 * scale + src2 */ +CVAPI(void) cvScaleAdd( const CvArr* src1, CvScalar scale, + const CvArr* src2, CvArr* dst ); +#define cvAXPY( A, real_scalar, B, C ) cvScaleAdd(A, cvRealScalar(real_scalar), B, C) + +/** dst = src1 * alpha + src2 * beta + gamma */ +CVAPI(void) cvAddWeighted( const CvArr* src1, double alpha, + const CvArr* src2, double beta, + double gamma, CvArr* dst ); + +/** @brief Calculates the dot product of two arrays in Euclidean metrics. + +The function calculates and returns the Euclidean dot product of two arrays. + +\f[src1 \bullet src2 = \sum _I ( \texttt{src1} (I) \texttt{src2} (I))\f] + +In the case of multiple channel arrays, the results for all channels are accumulated. In particular, +cvDotProduct(a,a) where a is a complex vector, will return \f$||\texttt{a}||^2\f$. The function can +process multi-dimensional arrays, row by row, layer by layer, and so on. +@param src1 The first source array +@param src2 The second source array + */ +CVAPI(double) cvDotProduct( const CvArr* src1, const CvArr* src2 ); + +/** dst(idx) = src1(idx) & src2(idx) */ +CVAPI(void) cvAnd( const CvArr* src1, const CvArr* src2, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src(idx) & value */ +CVAPI(void) cvAndS( const CvArr* src, CvScalar value, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src1(idx) | src2(idx) */ +CVAPI(void) cvOr( const CvArr* src1, const CvArr* src2, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src(idx) | value */ +CVAPI(void) cvOrS( const CvArr* src, CvScalar value, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src1(idx) ^ src2(idx) */ +CVAPI(void) cvXor( const CvArr* src1, const CvArr* src2, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src(idx) ^ value */ +CVAPI(void) cvXorS( const CvArr* src, CvScalar value, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = ~src(idx) */ +CVAPI(void) cvNot( const CvArr* src, CvArr* dst ); + +/** dst(idx) = lower(idx) <= src(idx) < upper(idx) */ +CVAPI(void) cvInRange( const CvArr* src, const CvArr* lower, + const CvArr* upper, CvArr* dst ); + +/** dst(idx) = lower <= src(idx) < upper */ +CVAPI(void) cvInRangeS( const CvArr* src, CvScalar lower, + CvScalar upper, CvArr* dst ); + +#define CV_CMP_EQ 0 +#define CV_CMP_GT 1 +#define CV_CMP_GE 2 +#define CV_CMP_LT 3 +#define CV_CMP_LE 4 +#define CV_CMP_NE 5 + +/** The comparison operation support single-channel arrays only. + Destination image should be 8uC1 or 8sC1 */ + +/** dst(idx) = src1(idx) _cmp_op_ src2(idx) */ +CVAPI(void) cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmp_op ); + +/** dst(idx) = src1(idx) _cmp_op_ value */ +CVAPI(void) cvCmpS( const CvArr* src, double value, CvArr* dst, int cmp_op ); + +/** dst(idx) = min(src1(idx),src2(idx)) */ +CVAPI(void) cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** dst(idx) = max(src1(idx),src2(idx)) */ +CVAPI(void) cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** dst(idx) = min(src(idx),value) */ +CVAPI(void) cvMinS( const CvArr* src, double value, CvArr* dst ); + +/** dst(idx) = max(src(idx),value) */ +CVAPI(void) cvMaxS( const CvArr* src, double value, CvArr* dst ); + +/** dst(x,y,c) = abs(src1(x,y,c) - src2(x,y,c)) */ +CVAPI(void) cvAbsDiff( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** dst(x,y,c) = abs(src(x,y,c) - value(c)) */ +CVAPI(void) cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value ); +#define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0)) + +/****************************************************************************************\ +* Math operations * +\****************************************************************************************/ + +/** Does cartesian->polar coordinates conversion. + Either of output components (magnitude or angle) is optional */ +CVAPI(void) cvCartToPolar( const CvArr* x, const CvArr* y, + CvArr* magnitude, CvArr* angle CV_DEFAULT(NULL), + int angle_in_degrees CV_DEFAULT(0)); + +/** Does polar->cartesian coordinates conversion. + Either of output components (magnitude or angle) is optional. + If magnitude is missing it is assumed to be all 1's */ +CVAPI(void) cvPolarToCart( const CvArr* magnitude, const CvArr* angle, + CvArr* x, CvArr* y, + int angle_in_degrees CV_DEFAULT(0)); + +/** Does powering: dst(idx) = src(idx)^power */ +CVAPI(void) cvPow( const CvArr* src, CvArr* dst, double power ); + +/** Does exponention: dst(idx) = exp(src(idx)). + Overflow is not handled yet. Underflow is handled. + Maximal relative error is ~7e-6 for single-precision input */ +CVAPI(void) cvExp( const CvArr* src, CvArr* dst ); + +/** Calculates natural logarithms: dst(idx) = log(abs(src(idx))). + Logarithm of 0 gives large negative number(~-700) + Maximal relative error is ~3e-7 for single-precision output +*/ +CVAPI(void) cvLog( const CvArr* src, CvArr* dst ); + +/** Fast arctangent calculation */ +CVAPI(float) cvFastArctan( float y, float x ); + +/** Fast cubic root calculation */ +CVAPI(float) cvCbrt( float value ); + +#define CV_CHECK_RANGE 1 +#define CV_CHECK_QUIET 2 +/** Checks array values for NaNs, Infs or simply for too large numbers + (if CV_CHECK_RANGE is set). If CV_CHECK_QUIET is set, + no runtime errors is raised (function returns zero value in case of "bad" values). + Otherwise cvError is called */ +CVAPI(int) cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0), + double min_val CV_DEFAULT(0), double max_val CV_DEFAULT(0)); +#define cvCheckArray cvCheckArr + +#define CV_RAND_UNI 0 +#define CV_RAND_NORMAL 1 + +/** @brief Fills an array with random numbers and updates the RNG state. + +The function fills the destination array with uniformly or normally distributed random numbers. +@param rng CvRNG state initialized by cvRNG +@param arr The destination array +@param dist_type Distribution type +> - **CV_RAND_UNI** uniform distribution +> - **CV_RAND_NORMAL** normal or Gaussian distribution +@param param1 The first parameter of the distribution. In the case of a uniform distribution it is +the inclusive lower boundary of the random numbers range. In the case of a normal distribution it +is the mean value of the random numbers. +@param param2 The second parameter of the distribution. In the case of a uniform distribution it +is the exclusive upper boundary of the random numbers range. In the case of a normal distribution +it is the standard deviation of the random numbers. +@sa randu, randn, RNG::fill. + */ +CVAPI(void) cvRandArr( CvRNG* rng, CvArr* arr, int dist_type, + CvScalar param1, CvScalar param2 ); + +CVAPI(void) cvRandShuffle( CvArr* mat, CvRNG* rng, + double iter_factor CV_DEFAULT(1.)); + +#define CV_SORT_EVERY_ROW 0 +#define CV_SORT_EVERY_COLUMN 1 +#define CV_SORT_ASCENDING 0 +#define CV_SORT_DESCENDING 16 + +CVAPI(void) cvSort( const CvArr* src, CvArr* dst CV_DEFAULT(NULL), + CvArr* idxmat CV_DEFAULT(NULL), + int flags CV_DEFAULT(0)); + +/** Finds real roots of a cubic equation */ +CVAPI(int) cvSolveCubic( const CvMat* coeffs, CvMat* roots ); + +/** Finds all real and complex roots of a polynomial equation */ +CVAPI(void) cvSolvePoly(const CvMat* coeffs, CvMat *roots2, + int maxiter CV_DEFAULT(20), int fig CV_DEFAULT(100)); + +/****************************************************************************************\ +* Matrix operations * +\****************************************************************************************/ + +/** @brief Calculates the cross product of two 3D vectors. + +The function calculates the cross product of two 3D vectors: +\f[\texttt{dst} = \texttt{src1} \times \texttt{src2}\f] +or: +\f[\begin{array}{l} \texttt{dst} _1 = \texttt{src1} _2 \texttt{src2} _3 - \texttt{src1} _3 \texttt{src2} _2 \\ \texttt{dst} _2 = \texttt{src1} _3 \texttt{src2} _1 - \texttt{src1} _1 \texttt{src2} _3 \\ \texttt{dst} _3 = \texttt{src1} _1 \texttt{src2} _2 - \texttt{src1} _2 \texttt{src2} _1 \end{array}\f] +@param src1 The first source vector +@param src2 The second source vector +@param dst The destination vector + */ +CVAPI(void) cvCrossProduct( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** Matrix transform: dst = A*B + C, C is optional */ +#define cvMatMulAdd( src1, src2, src3, dst ) cvGEMM( (src1), (src2), 1., (src3), 1., (dst), 0 ) +#define cvMatMul( src1, src2, dst ) cvMatMulAdd( (src1), (src2), NULL, (dst)) + +#define CV_GEMM_A_T 1 +#define CV_GEMM_B_T 2 +#define CV_GEMM_C_T 4 +/** Extended matrix transform: + dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */ +CVAPI(void) cvGEMM( const CvArr* src1, const CvArr* src2, double alpha, + const CvArr* src3, double beta, CvArr* dst, + int tABC CV_DEFAULT(0)); +#define cvMatMulAddEx cvGEMM + +/** Transforms each element of source array and stores + resultant vectors in destination array */ +CVAPI(void) cvTransform( const CvArr* src, CvArr* dst, + const CvMat* transmat, + const CvMat* shiftvec CV_DEFAULT(NULL)); +#define cvMatMulAddS cvTransform + +/** Does perspective transform on every element of input array */ +CVAPI(void) cvPerspectiveTransform( const CvArr* src, CvArr* dst, + const CvMat* mat ); + +/** Calculates (A-delta)*(A-delta)^T (order=0) or (A-delta)^T*(A-delta) (order=1) */ +CVAPI(void) cvMulTransposed( const CvArr* src, CvArr* dst, int order, + const CvArr* delta CV_DEFAULT(NULL), + double scale CV_DEFAULT(1.) ); + +/** Tranposes matrix. Square matrices can be transposed in-place */ +CVAPI(void) cvTranspose( const CvArr* src, CvArr* dst ); +#define cvT cvTranspose + +/** Completes the symmetric matrix from the lower (LtoR=0) or from the upper (LtoR!=0) part */ +CVAPI(void) cvCompleteSymm( CvMat* matrix, int LtoR CV_DEFAULT(0) ); + +/** Mirror array data around horizontal (flip=0), + vertical (flip=1) or both(flip=-1) axises: + cvFlip(src) flips images vertically and sequences horizontally (inplace) */ +CVAPI(void) cvFlip( const CvArr* src, CvArr* dst CV_DEFAULT(NULL), + int flip_mode CV_DEFAULT(0)); +#define cvMirror cvFlip + + +#define CV_SVD_MODIFY_A 1 +#define CV_SVD_U_T 2 +#define CV_SVD_V_T 4 + +/** Performs Singular Value Decomposition of a matrix */ +CVAPI(void) cvSVD( CvArr* A, CvArr* W, CvArr* U CV_DEFAULT(NULL), + CvArr* V CV_DEFAULT(NULL), int flags CV_DEFAULT(0)); + +/** Performs Singular Value Back Substitution (solves A*X = B): + flags must be the same as in cvSVD */ +CVAPI(void) cvSVBkSb( const CvArr* W, const CvArr* U, + const CvArr* V, const CvArr* B, + CvArr* X, int flags ); + +#define CV_LU 0 +#define CV_SVD 1 +#define CV_SVD_SYM 2 +#define CV_CHOLESKY 3 +#define CV_QR 4 +#define CV_NORMAL 16 + +/** Inverts matrix */ +CVAPI(double) cvInvert( const CvArr* src, CvArr* dst, + int method CV_DEFAULT(CV_LU)); +#define cvInv cvInvert + +/** Solves linear system (src1)*(dst) = (src2) + (returns 0 if src1 is a singular and CV_LU method is used) */ +CVAPI(int) cvSolve( const CvArr* src1, const CvArr* src2, CvArr* dst, + int method CV_DEFAULT(CV_LU)); + +/** Calculates determinant of input matrix */ +CVAPI(double) cvDet( const CvArr* mat ); + +/** Calculates trace of the matrix (sum of elements on the main diagonal) */ +CVAPI(CvScalar) cvTrace( const CvArr* mat ); + +/** Finds eigen values and vectors of a symmetric matrix */ +CVAPI(void) cvEigenVV( CvArr* mat, CvArr* evects, CvArr* evals, + double eps CV_DEFAULT(0), + int lowindex CV_DEFAULT(-1), + int highindex CV_DEFAULT(-1)); + +///* Finds selected eigen values and vectors of a symmetric matrix */ +//CVAPI(void) cvSelectedEigenVV( CvArr* mat, CvArr* evects, CvArr* evals, +// int lowindex, int highindex ); + +/** Makes an identity matrix (mat_ij = i == j) */ +CVAPI(void) cvSetIdentity( CvArr* mat, CvScalar value CV_DEFAULT(cvRealScalar(1)) ); + +/** Fills matrix with given range of numbers */ +CVAPI(CvArr*) cvRange( CvArr* mat, double start, double end ); + +/** @anchor core_c_CovarFlags +@name Flags for cvCalcCovarMatrix +@see cvCalcCovarMatrix + @{ +*/ + +/** flag for cvCalcCovarMatrix, transpose([v1-avg, v2-avg,...]) * [v1-avg,v2-avg,...] */ +#define CV_COVAR_SCRAMBLED 0 + +/** flag for cvCalcCovarMatrix, [v1-avg, v2-avg,...] * transpose([v1-avg,v2-avg,...]) */ +#define CV_COVAR_NORMAL 1 + +/** flag for cvCalcCovarMatrix, do not calc average (i.e. mean vector) - use the input vector instead + (useful for calculating covariance matrix by parts) */ +#define CV_COVAR_USE_AVG 2 + +/** flag for cvCalcCovarMatrix, scale the covariance matrix coefficients by number of the vectors */ +#define CV_COVAR_SCALE 4 + +/** flag for cvCalcCovarMatrix, all the input vectors are stored in a single matrix, as its rows */ +#define CV_COVAR_ROWS 8 + +/** flag for cvCalcCovarMatrix, all the input vectors are stored in a single matrix, as its columns */ +#define CV_COVAR_COLS 16 + +/** @} */ + +/** Calculates covariation matrix for a set of vectors +@see @ref core_c_CovarFlags "flags" +*/ +CVAPI(void) cvCalcCovarMatrix( const CvArr** vects, int count, + CvArr* cov_mat, CvArr* avg, int flags ); + +#define CV_PCA_DATA_AS_ROW 0 +#define CV_PCA_DATA_AS_COL 1 +#define CV_PCA_USE_AVG 2 +CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* mean, + CvArr* eigenvals, CvArr* eigenvects, int flags ); + +CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* mean, + const CvArr* eigenvects, CvArr* result ); + +CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* mean, + const CvArr* eigenvects, CvArr* result ); + +/** Calculates Mahalanobis(weighted) distance */ +CVAPI(double) cvMahalanobis( const CvArr* vec1, const CvArr* vec2, const CvArr* mat ); +#define cvMahalonobis cvMahalanobis + +/****************************************************************************************\ +* Array Statistics * +\****************************************************************************************/ + +/** Finds sum of array elements */ +CVAPI(CvScalar) cvSum( const CvArr* arr ); + +/** Calculates number of non-zero pixels */ +CVAPI(int) cvCountNonZero( const CvArr* arr ); + +/** Calculates mean value of array elements */ +CVAPI(CvScalar) cvAvg( const CvArr* arr, const CvArr* mask CV_DEFAULT(NULL) ); + +/** Calculates mean and standard deviation of pixel values */ +CVAPI(void) cvAvgSdv( const CvArr* arr, CvScalar* mean, CvScalar* std_dev, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** Finds global minimum, maximum and their positions */ +CVAPI(void) cvMinMaxLoc( const CvArr* arr, double* min_val, double* max_val, + CvPoint* min_loc CV_DEFAULT(NULL), + CvPoint* max_loc CV_DEFAULT(NULL), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @anchor core_c_NormFlags + @name Flags for cvNorm and cvNormalize + @{ +*/ +#define CV_C 1 +#define CV_L1 2 +#define CV_L2 4 +#define CV_NORM_MASK 7 +#define CV_RELATIVE 8 +#define CV_DIFF 16 +#define CV_MINMAX 32 + +#define CV_DIFF_C (CV_DIFF | CV_C) +#define CV_DIFF_L1 (CV_DIFF | CV_L1) +#define CV_DIFF_L2 (CV_DIFF | CV_L2) +#define CV_RELATIVE_C (CV_RELATIVE | CV_C) +#define CV_RELATIVE_L1 (CV_RELATIVE | CV_L1) +#define CV_RELATIVE_L2 (CV_RELATIVE | CV_L2) +/** @} */ + +/** Finds norm, difference norm or relative difference norm for an array (or two arrays) +@see ref core_c_NormFlags "flags" +*/ +CVAPI(double) cvNorm( const CvArr* arr1, const CvArr* arr2 CV_DEFAULT(NULL), + int norm_type CV_DEFAULT(CV_L2), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @see ref core_c_NormFlags "flags" */ +CVAPI(void) cvNormalize( const CvArr* src, CvArr* dst, + double a CV_DEFAULT(1.), double b CV_DEFAULT(0.), + int norm_type CV_DEFAULT(CV_L2), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @anchor core_c_ReduceFlags + @name Flags for cvReduce + @{ +*/ +#define CV_REDUCE_SUM 0 +#define CV_REDUCE_AVG 1 +#define CV_REDUCE_MAX 2 +#define CV_REDUCE_MIN 3 +/** @} */ + +/** @see @ref core_c_ReduceFlags "flags" */ +CVAPI(void) cvReduce( const CvArr* src, CvArr* dst, int dim CV_DEFAULT(-1), + int op CV_DEFAULT(CV_REDUCE_SUM) ); + +/****************************************************************************************\ +* Discrete Linear Transforms and Related Functions * +\****************************************************************************************/ + +/** @anchor core_c_DftFlags + @name Flags for cvDFT, cvDCT and cvMulSpectrums + @{ + */ +#define CV_DXT_FORWARD 0 +#define CV_DXT_INVERSE 1 +#define CV_DXT_SCALE 2 /**< divide result by size of array */ +#define CV_DXT_INV_SCALE (CV_DXT_INVERSE + CV_DXT_SCALE) +#define CV_DXT_INVERSE_SCALE CV_DXT_INV_SCALE +#define CV_DXT_ROWS 4 /**< transform each row individually */ +#define CV_DXT_MUL_CONJ 8 /**< conjugate the second argument of cvMulSpectrums */ +/** @} */ + +/** Discrete Fourier Transform: + complex->complex, + real->ccs (forward), + ccs->real (inverse) +@see core_c_DftFlags "flags" +*/ +CVAPI(void) cvDFT( const CvArr* src, CvArr* dst, int flags, + int nonzero_rows CV_DEFAULT(0) ); +#define cvFFT cvDFT + +/** Multiply results of DFTs: DFT(X)*DFT(Y) or DFT(X)*conj(DFT(Y)) +@see core_c_DftFlags "flags" +*/ +CVAPI(void) cvMulSpectrums( const CvArr* src1, const CvArr* src2, + CvArr* dst, int flags ); + +/** Finds optimal DFT vector size >= size0 */ +CVAPI(int) cvGetOptimalDFTSize( int size0 ); + +/** Discrete Cosine Transform +@see core_c_DftFlags "flags" +*/ +CVAPI(void) cvDCT( const CvArr* src, CvArr* dst, int flags ); + +/****************************************************************************************\ +* Dynamic data structures * +\****************************************************************************************/ + +/** Calculates length of sequence slice (with support of negative indices). */ +CVAPI(int) cvSliceLength( CvSlice slice, const CvSeq* seq ); + + +/** Creates new memory storage. + block_size == 0 means that default, + somewhat optimal size, is used (currently, it is 64K) */ +CVAPI(CvMemStorage*) cvCreateMemStorage( int block_size CV_DEFAULT(0)); + + +/** Creates a memory storage that will borrow memory blocks from parent storage */ +CVAPI(CvMemStorage*) cvCreateChildMemStorage( CvMemStorage* parent ); + + +/** Releases memory storage. All the children of a parent must be released before + the parent. A child storage returns all the blocks to parent when it is released */ +CVAPI(void) cvReleaseMemStorage( CvMemStorage** storage ); + + +/** Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos) + to reuse memory allocated for the storage - cvClearSeq,cvClearSet ... + do not free any memory. + A child storage returns all the blocks to the parent when it is cleared */ +CVAPI(void) cvClearMemStorage( CvMemStorage* storage ); + +/** Remember a storage "free memory" position */ +CVAPI(void) cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos ); + +/** Restore a storage "free memory" position */ +CVAPI(void) cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos ); + +/** Allocates continuous buffer of the specified size in the storage */ +CVAPI(void*) cvMemStorageAlloc( CvMemStorage* storage, size_t size ); + +/** Allocates string in memory storage */ +CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, + int len CV_DEFAULT(-1) ); + +/** Creates new empty sequence that will reside in the specified storage */ +CVAPI(CvSeq*) cvCreateSeq( int seq_flags, size_t header_size, + size_t elem_size, CvMemStorage* storage ); + +/** Changes default size (granularity) of sequence blocks. + The default size is ~1Kbyte */ +CVAPI(void) cvSetSeqBlockSize( CvSeq* seq, int delta_elems ); + + +/** Adds new element to the end of sequence. Returns pointer to the element */ +CVAPI(schar*) cvSeqPush( CvSeq* seq, const void* element CV_DEFAULT(NULL)); + + +/** Adds new element to the beginning of sequence. Returns pointer to it */ +CVAPI(schar*) cvSeqPushFront( CvSeq* seq, const void* element CV_DEFAULT(NULL)); + + +/** Removes the last element from sequence and optionally saves it */ +CVAPI(void) cvSeqPop( CvSeq* seq, void* element CV_DEFAULT(NULL)); + + +/** Removes the first element from sequence and optioanally saves it */ +CVAPI(void) cvSeqPopFront( CvSeq* seq, void* element CV_DEFAULT(NULL)); + + +#define CV_FRONT 1 +#define CV_BACK 0 +/** Adds several new elements to the end of sequence */ +CVAPI(void) cvSeqPushMulti( CvSeq* seq, const void* elements, + int count, int in_front CV_DEFAULT(0) ); + +/** Removes several elements from the end of sequence and optionally saves them */ +CVAPI(void) cvSeqPopMulti( CvSeq* seq, void* elements, + int count, int in_front CV_DEFAULT(0) ); + +/** Inserts a new element in the middle of sequence. + cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */ +CVAPI(schar*) cvSeqInsert( CvSeq* seq, int before_index, + const void* element CV_DEFAULT(NULL)); + +/** Removes specified sequence element */ +CVAPI(void) cvSeqRemove( CvSeq* seq, int index ); + + +/** Removes all the elements from the sequence. The freed memory + can be reused later only by the same sequence unless cvClearMemStorage + or cvRestoreMemStoragePos is called */ +CVAPI(void) cvClearSeq( CvSeq* seq ); + + +/** Retrieves pointer to specified sequence element. + Negative indices are supported and mean counting from the end + (e.g -1 means the last sequence element) */ +CVAPI(schar*) cvGetSeqElem( const CvSeq* seq, int index ); + +/** Calculates index of the specified sequence element. + Returns -1 if element does not belong to the sequence */ +CVAPI(int) cvSeqElemIdx( const CvSeq* seq, const void* element, + CvSeqBlock** block CV_DEFAULT(NULL) ); + +/** Initializes sequence writer. The new elements will be added to the end of sequence */ +CVAPI(void) cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer ); + + +/** Combination of cvCreateSeq and cvStartAppendToSeq */ +CVAPI(void) cvStartWriteSeq( int seq_flags, int header_size, + int elem_size, CvMemStorage* storage, + CvSeqWriter* writer ); + +/** Closes sequence writer, updates sequence header and returns pointer + to the resultant sequence + (which may be useful if the sequence was created using cvStartWriteSeq)) +*/ +CVAPI(CvSeq*) cvEndWriteSeq( CvSeqWriter* writer ); + + +/** Updates sequence header. May be useful to get access to some of previously + written elements via cvGetSeqElem or sequence reader */ +CVAPI(void) cvFlushSeqWriter( CvSeqWriter* writer ); + + +/** Initializes sequence reader. + The sequence can be read in forward or backward direction */ +CVAPI(void) cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader, + int reverse CV_DEFAULT(0) ); + + +/** Returns current sequence reader position (currently observed sequence element) */ +CVAPI(int) cvGetSeqReaderPos( CvSeqReader* reader ); + + +/** Changes sequence reader position. It may seek to an absolute or + to relative to the current position */ +CVAPI(void) cvSetSeqReaderPos( CvSeqReader* reader, int index, + int is_relative CV_DEFAULT(0)); + +/** Copies sequence content to a continuous piece of memory */ +CVAPI(void*) cvCvtSeqToArray( const CvSeq* seq, void* elements, + CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) ); + +/** Creates sequence header for array. + After that all the operations on sequences that do not alter the content + can be applied to the resultant sequence */ +CVAPI(CvSeq*) cvMakeSeqHeaderForArray( int seq_type, int header_size, + int elem_size, void* elements, int total, + CvSeq* seq, CvSeqBlock* block ); + +/** Extracts sequence slice (with or without copying sequence elements) */ +CVAPI(CvSeq*) cvSeqSlice( const CvSeq* seq, CvSlice slice, + CvMemStorage* storage CV_DEFAULT(NULL), + int copy_data CV_DEFAULT(0)); + +CV_INLINE CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL)) +{ + return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 ); +} + +/** Removes sequence slice */ +CVAPI(void) cvSeqRemoveSlice( CvSeq* seq, CvSlice slice ); + +/** Inserts a sequence or array into another sequence */ +CVAPI(void) cvSeqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); + +/** a < b ? -1 : a > b ? 1 : 0 */ +typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata ); + +/** Sorts sequence in-place given element comparison function */ +CVAPI(void) cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata CV_DEFAULT(NULL) ); + +/** Finds element in a [sorted] sequence */ +CVAPI(schar*) cvSeqSearch( CvSeq* seq, const void* elem, CvCmpFunc func, + int is_sorted, int* elem_idx, + void* userdata CV_DEFAULT(NULL) ); + +/** Reverses order of sequence elements in-place */ +CVAPI(void) cvSeqInvert( CvSeq* seq ); + +/** Splits sequence into one or more equivalence classes using the specified criteria */ +CVAPI(int) cvSeqPartition( const CvSeq* seq, CvMemStorage* storage, + CvSeq** labels, CvCmpFunc is_equal, void* userdata ); + +/************ Internal sequence functions ************/ +CVAPI(void) cvChangeSeqBlock( void* reader, int direction ); +CVAPI(void) cvCreateSeqBlock( CvSeqWriter* writer ); + + +/** Creates a new set */ +CVAPI(CvSet*) cvCreateSet( int set_flags, int header_size, + int elem_size, CvMemStorage* storage ); + +/** Adds new element to the set and returns pointer to it */ +CVAPI(int) cvSetAdd( CvSet* set_header, CvSetElem* elem CV_DEFAULT(NULL), + CvSetElem** inserted_elem CV_DEFAULT(NULL) ); + +/** Fast variant of cvSetAdd */ +CV_INLINE CvSetElem* cvSetNew( CvSet* set_header ) +{ + CvSetElem* elem = set_header->free_elems; + if( elem ) + { + set_header->free_elems = elem->next_free; + elem->flags = elem->flags & CV_SET_ELEM_IDX_MASK; + set_header->active_count++; + } + else + cvSetAdd( set_header, NULL, &elem ); + return elem; +} + +/** Removes set element given its pointer */ +CV_INLINE void cvSetRemoveByPtr( CvSet* set_header, void* elem ) +{ + CvSetElem* _elem = (CvSetElem*)elem; + assert( _elem->flags >= 0 /*&& (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total*/ ); + _elem->next_free = set_header->free_elems; + _elem->flags = (_elem->flags & CV_SET_ELEM_IDX_MASK) | CV_SET_ELEM_FREE_FLAG; + set_header->free_elems = _elem; + set_header->active_count--; +} + +/** Removes element from the set by its index */ +CVAPI(void) cvSetRemove( CvSet* set_header, int index ); + +/** Returns a set element by index. If the element doesn't belong to the set, + NULL is returned */ +CV_INLINE CvSetElem* cvGetSetElem( const CvSet* set_header, int idx ) +{ + CvSetElem* elem = (CvSetElem*)(void *)cvGetSeqElem( (CvSeq*)set_header, idx ); + return elem && CV_IS_SET_ELEM( elem ) ? elem : 0; +} + +/** Removes all the elements from the set */ +CVAPI(void) cvClearSet( CvSet* set_header ); + +/** Creates new graph */ +CVAPI(CvGraph*) cvCreateGraph( int graph_flags, int header_size, + int vtx_size, int edge_size, + CvMemStorage* storage ); + +/** Adds new vertex to the graph */ +CVAPI(int) cvGraphAddVtx( CvGraph* graph, const CvGraphVtx* vtx CV_DEFAULT(NULL), + CvGraphVtx** inserted_vtx CV_DEFAULT(NULL) ); + + +/** Removes vertex from the graph together with all incident edges */ +CVAPI(int) cvGraphRemoveVtx( CvGraph* graph, int index ); +CVAPI(int) cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx ); + + +/** Link two vertices specified by indices or pointers if they + are not connected or return pointer to already existing edge + connecting the vertices. + Functions return 1 if a new edge was created, 0 otherwise */ +CVAPI(int) cvGraphAddEdge( CvGraph* graph, + int start_idx, int end_idx, + const CvGraphEdge* edge CV_DEFAULT(NULL), + CvGraphEdge** inserted_edge CV_DEFAULT(NULL) ); + +CVAPI(int) cvGraphAddEdgeByPtr( CvGraph* graph, + CvGraphVtx* start_vtx, CvGraphVtx* end_vtx, + const CvGraphEdge* edge CV_DEFAULT(NULL), + CvGraphEdge** inserted_edge CV_DEFAULT(NULL) ); + +/** Remove edge connecting two vertices */ +CVAPI(void) cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx ); +CVAPI(void) cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, + CvGraphVtx* end_vtx ); + +/** Find edge connecting two vertices */ +CVAPI(CvGraphEdge*) cvFindGraphEdge( const CvGraph* graph, int start_idx, int end_idx ); +CVAPI(CvGraphEdge*) cvFindGraphEdgeByPtr( const CvGraph* graph, + const CvGraphVtx* start_vtx, + const CvGraphVtx* end_vtx ); +#define cvGraphFindEdge cvFindGraphEdge +#define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr + +/** Remove all vertices and edges from the graph */ +CVAPI(void) cvClearGraph( CvGraph* graph ); + + +/** Count number of edges incident to the vertex */ +CVAPI(int) cvGraphVtxDegree( const CvGraph* graph, int vtx_idx ); +CVAPI(int) cvGraphVtxDegreeByPtr( const CvGraph* graph, const CvGraphVtx* vtx ); + + +/** Retrieves graph vertex by given index */ +#define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx)) + +/** Retrieves index of a graph vertex given its pointer */ +#define cvGraphVtxIdx( graph, vtx ) ((vtx)->flags & CV_SET_ELEM_IDX_MASK) + +/** Retrieves index of a graph edge given its pointer */ +#define cvGraphEdgeIdx( graph, edge ) ((edge)->flags & CV_SET_ELEM_IDX_MASK) + +#define cvGraphGetVtxCount( graph ) ((graph)->active_count) +#define cvGraphGetEdgeCount( graph ) ((graph)->edges->active_count) + +#define CV_GRAPH_VERTEX 1 +#define CV_GRAPH_TREE_EDGE 2 +#define CV_GRAPH_BACK_EDGE 4 +#define CV_GRAPH_FORWARD_EDGE 8 +#define CV_GRAPH_CROSS_EDGE 16 +#define CV_GRAPH_ANY_EDGE 30 +#define CV_GRAPH_NEW_TREE 32 +#define CV_GRAPH_BACKTRACKING 64 +#define CV_GRAPH_OVER -1 + +#define CV_GRAPH_ALL_ITEMS -1 + +/** flags for graph vertices and edges */ +#define CV_GRAPH_ITEM_VISITED_FLAG (1 << 30) +#define CV_IS_GRAPH_VERTEX_VISITED(vtx) \ + (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG) +#define CV_IS_GRAPH_EDGE_VISITED(edge) \ + (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG) +#define CV_GRAPH_SEARCH_TREE_NODE_FLAG (1 << 29) +#define CV_GRAPH_FORWARD_EDGE_FLAG (1 << 28) + +typedef struct CvGraphScanner +{ + CvGraphVtx* vtx; /* current graph vertex (or current edge origin) */ + CvGraphVtx* dst; /* current graph edge destination vertex */ + CvGraphEdge* edge; /* current edge */ + + CvGraph* graph; /* the graph */ + CvSeq* stack; /* the graph vertex stack */ + int index; /* the lower bound of certainly visited vertices */ + int mask; /* event mask */ +} +CvGraphScanner; + +/** Creates new graph scanner. */ +CVAPI(CvGraphScanner*) cvCreateGraphScanner( CvGraph* graph, + CvGraphVtx* vtx CV_DEFAULT(NULL), + int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS)); + +/** Releases graph scanner. */ +CVAPI(void) cvReleaseGraphScanner( CvGraphScanner** scanner ); + +/** Get next graph element */ +CVAPI(int) cvNextGraphItem( CvGraphScanner* scanner ); + +/** Creates a copy of graph */ +CVAPI(CvGraph*) cvCloneGraph( const CvGraph* graph, CvMemStorage* storage ); + + +/** Does look-up transformation. Elements of the source array + (that should be 8uC1 or 8sC1) are used as indexes in lutarr 256-element table */ +CVAPI(void) cvLUT( const CvArr* src, CvArr* dst, const CvArr* lut ); + + +/******************* Iteration through the sequence tree *****************/ +typedef struct CvTreeNodeIterator +{ + const void* node; + int level; + int max_level; +} +CvTreeNodeIterator; + +CVAPI(void) cvInitTreeNodeIterator( CvTreeNodeIterator* tree_iterator, + const void* first, int max_level ); +CVAPI(void*) cvNextTreeNode( CvTreeNodeIterator* tree_iterator ); +CVAPI(void*) cvPrevTreeNode( CvTreeNodeIterator* tree_iterator ); + +/** Inserts sequence into tree with specified "parent" sequence. + If parent is equal to frame (e.g. the most external contour), + then added contour will have null pointer to parent. */ +CVAPI(void) cvInsertNodeIntoTree( void* node, void* parent, void* frame ); + +/** Removes contour from tree (together with the contour children). */ +CVAPI(void) cvRemoveNodeFromTree( void* node, void* frame ); + +/** Gathers pointers to all the sequences, + accessible from the `first`, to the single sequence */ +CVAPI(CvSeq*) cvTreeToNodeSeq( const void* first, int header_size, + CvMemStorage* storage ); + +/** The function implements the K-means algorithm for clustering an array of sample + vectors in a specified number of classes */ +#define CV_KMEANS_USE_INITIAL_LABELS 1 +CVAPI(int) cvKMeans2( const CvArr* samples, int cluster_count, CvArr* labels, + CvTermCriteria termcrit, int attempts CV_DEFAULT(1), + CvRNG* rng CV_DEFAULT(0), int flags CV_DEFAULT(0), + CvArr* _centers CV_DEFAULT(0), double* compactness CV_DEFAULT(0) ); + +/****************************************************************************************\ +* System functions * +\****************************************************************************************/ + +/** Loads optimized functions from IPP, MKL etc. or switches back to pure C code */ +CVAPI(int) cvUseOptimized( int on_off ); + +typedef IplImage* (CV_STDCALL* Cv_iplCreateImageHeader) + (int,int,int,char*,char*,int,int,int,int,int, + IplROI*,IplImage*,void*,IplTileInfo*); +typedef void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int); +typedef void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int); +typedef IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int); +typedef IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*); + +/** @brief Makes OpenCV use IPL functions for allocating IplImage and IplROI structures. + +Normally, the function is not called directly. Instead, a simple macro +CV_TURN_ON_IPL_COMPATIBILITY() is used that calls cvSetIPLAllocators and passes there pointers +to IPL allocation functions. : +@code + ... + CV_TURN_ON_IPL_COMPATIBILITY() + ... +@endcode +@param create_header pointer to a function, creating IPL image header. +@param allocate_data pointer to a function, allocating IPL image data. +@param deallocate pointer to a function, deallocating IPL image. +@param create_roi pointer to a function, creating IPL image ROI (i.e. Region of Interest). +@param clone_image pointer to a function, cloning an IPL image. + */ +CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header, + Cv_iplAllocateImageData allocate_data, + Cv_iplDeallocate deallocate, + Cv_iplCreateROI create_roi, + Cv_iplCloneImage clone_image ); + +#define CV_TURN_ON_IPL_COMPATIBILITY() \ + cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage, \ + iplDeallocate, iplCreateROI, iplCloneImage ) + +/****************************************************************************************\ +* Data Persistence * +\****************************************************************************************/ + +/********************************** High-level functions ********************************/ + +/** @brief Opens file storage for reading or writing data. + +The function opens file storage for reading or writing data. In the latter case, a new file is +created or an existing file is rewritten. The type of the read or written file is determined by the +filename extension: .xml for XML, .yml or .yaml for YAML and .json for JSON. + +At the same time, it also supports adding parameters like "example.xml?base64". + +The function returns a pointer to the CvFileStorage structure. +If the file cannot be opened then the function returns NULL. +@param filename Name of the file associated with the storage +@param memstorage Memory storage used for temporary data and for +: storing dynamic structures, such as CvSeq or CvGraph . If it is NULL, a temporary memory + storage is created and used. +@param flags Can be one of the following: +> - **CV_STORAGE_READ** the storage is open for reading +> - **CV_STORAGE_WRITE** the storage is open for writing + (use **CV_STORAGE_WRITE | CV_STORAGE_WRITE_BASE64** to write rawdata in Base64) +@param encoding + */ +CVAPI(CvFileStorage*) cvOpenFileStorage( const char* filename, CvMemStorage* memstorage, + int flags, const char* encoding CV_DEFAULT(NULL) ); + +/** @brief Releases file storage. + +The function closes the file associated with the storage and releases all the temporary structures. +It must be called after all I/O operations with the storage are finished. +@param fs Double pointer to the released file storage + */ +CVAPI(void) cvReleaseFileStorage( CvFileStorage** fs ); + +/** returns attribute value or 0 (NULL) if there is no such attribute */ +CVAPI(const char*) cvAttrValue( const CvAttrList* attr, const char* attr_name ); + +/** @brief Starts writing a new structure. + +The function starts writing a compound structure (collection) that can be a sequence or a map. After +all the structure fields, which can be scalars or structures, are written, cvEndWriteStruct should +be called. The function can be used to group some objects or to implement the write function for a +some user object (see CvTypeInfo). +@param fs File storage +@param name Name of the written structure. The structure can be accessed by this name when the +storage is read. +@param struct_flags A combination one of the following values: +- **CV_NODE_SEQ** the written structure is a sequence (see discussion of CvFileStorage ), + that is, its elements do not have a name. +- **CV_NODE_MAP** the written structure is a map (see discussion of CvFileStorage ), that + is, all its elements have names. +One and only one of the two above flags must be specified +- **CV_NODE_FLOW** the optional flag that makes sense only for YAML streams. It means that + the structure is written as a flow (not as a block), which is more compact. It is + recommended to use this flag for structures or arrays whose elements are all scalars. +@param type_name Optional parameter - the object type name. In + case of XML it is written as a type_id attribute of the structure opening tag. In the case of + YAML it is written after a colon following the structure name (see the example in + CvFileStorage description). In case of JSON it is written as a name/value pair. + Mainly it is used with user objects. When the storage is read, the + encoded type name is used to determine the object type (see CvTypeInfo and cvFindType ). +@param attributes This parameter is not used in the current implementation + */ +CVAPI(void) cvStartWriteStruct( CvFileStorage* fs, const char* name, + int struct_flags, const char* type_name CV_DEFAULT(NULL), + CvAttrList attributes CV_DEFAULT(cvAttrList())); + +/** @brief Finishes writing to a file node collection. +@param fs File storage +@sa cvStartWriteStruct. + */ +CVAPI(void) cvEndWriteStruct( CvFileStorage* fs ); + +/** @brief Writes an integer value. + +The function writes a single integer value (with or without a name) to the file storage. +@param fs File storage +@param name Name of the written value. Should be NULL if and only if the parent structure is a +sequence. +@param value The written value + */ +CVAPI(void) cvWriteInt( CvFileStorage* fs, const char* name, int value ); + +/** @brief Writes a floating-point value. + +The function writes a single floating-point value (with or without a name) to file storage. Special +values are encoded as follows: NaN (Not A Number) as .NaN, infinity as +.Inf or -.Inf. + +The following example shows how to use the low-level writing functions to store custom structures, +such as termination criteria, without registering a new type. : +@code + void write_termcriteria( CvFileStorage* fs, const char* struct_name, + CvTermCriteria* termcrit ) + { + cvStartWriteStruct( fs, struct_name, CV_NODE_MAP, NULL, cvAttrList(0,0)); + cvWriteComment( fs, "termination criteria", 1 ); // just a description + if( termcrit->type & CV_TERMCRIT_ITER ) + cvWriteInteger( fs, "max_iterations", termcrit->max_iter ); + if( termcrit->type & CV_TERMCRIT_EPS ) + cvWriteReal( fs, "accuracy", termcrit->epsilon ); + cvEndWriteStruct( fs ); + } +@endcode +@param fs File storage +@param name Name of the written value. Should be NULL if and only if the parent structure is a +sequence. +@param value The written value +*/ +CVAPI(void) cvWriteReal( CvFileStorage* fs, const char* name, double value ); + +/** @brief Writes a text string. + +The function writes a text string to file storage. +@param fs File storage +@param name Name of the written string . Should be NULL if and only if the parent structure is a +sequence. +@param str The written text string +@param quote If non-zero, the written string is put in quotes, regardless of whether they are +required. Otherwise, if the flag is zero, quotes are used only when they are required (e.g. when +the string starts with a digit or contains spaces). + */ +CVAPI(void) cvWriteString( CvFileStorage* fs, const char* name, + const char* str, int quote CV_DEFAULT(0) ); + +/** @brief Writes a comment. + +The function writes a comment into file storage. The comments are skipped when the storage is read. +@param fs File storage +@param comment The written comment, single-line or multi-line +@param eol_comment If non-zero, the function tries to put the comment at the end of current line. +If the flag is zero, if the comment is multi-line, or if it does not fit at the end of the current +line, the comment starts a new line. + */ +CVAPI(void) cvWriteComment( CvFileStorage* fs, const char* comment, + int eol_comment ); + +/** @brief Writes an object to file storage. + +The function writes an object to file storage. First, the appropriate type info is found using +cvTypeOf. Then, the write method associated with the type info is called. + +Attributes are used to customize the writing procedure. The standard types support the following +attributes (all the dt attributes have the same format as in cvWriteRawData): + +-# CvSeq + - **header_dt** description of user fields of the sequence header that follow CvSeq, or + CvChain (if the sequence is a Freeman chain) or CvContour (if the sequence is a contour or + point sequence) + - **dt** description of the sequence elements. + - **recursive** if the attribute is present and is not equal to "0" or "false", the whole + tree of sequences (contours) is stored. +-# CvGraph + - **header_dt** description of user fields of the graph header that follows CvGraph; + - **vertex_dt** description of user fields of graph vertices + - **edge_dt** description of user fields of graph edges (note that the edge weight is + always written, so there is no need to specify it explicitly) + +Below is the code that creates the YAML file shown in the CvFileStorage description: +@code + #include "cxcore.h" + + int main( int argc, char** argv ) + { + CvMat* mat = cvCreateMat( 3, 3, CV_32F ); + CvFileStorage* fs = cvOpenFileStorage( "example.yml", 0, CV_STORAGE_WRITE ); + + cvSetIdentity( mat ); + cvWrite( fs, "A", mat, cvAttrList(0,0) ); + + cvReleaseFileStorage( &fs ); + cvReleaseMat( &mat ); + return 0; + } +@endcode +@param fs File storage +@param name Name of the written object. Should be NULL if and only if the parent structure is a +sequence. +@param ptr Pointer to the object +@param attributes The attributes of the object. They are specific for each particular type (see +the discussion below). + */ +CVAPI(void) cvWrite( CvFileStorage* fs, const char* name, const void* ptr, + CvAttrList attributes CV_DEFAULT(cvAttrList())); + +/** @brief Starts the next stream. + +The function finishes the currently written stream and starts the next stream. In the case of XML +the file with multiple streams looks like this: +@code{.xml} + <opencv_storage> + <!-- stream #1 data --> + </opencv_storage> + <opencv_storage> + <!-- stream #2 data --> + </opencv_storage> + ... +@endcode +The YAML file will look like this: +@code{.yaml} + %YAML 1.0 + # stream #1 data + ... + --- + # stream #2 data +@endcode +This is useful for concatenating files or for resuming the writing process. +@param fs File storage + */ +CVAPI(void) cvStartNextStream( CvFileStorage* fs ); + +/** @brief Writes multiple numbers. + +The function writes an array, whose elements consist of single or multiple numbers. The function +call can be replaced with a loop containing a few cvWriteInt and cvWriteReal calls, but a single +call is more efficient. Note that because none of the elements have a name, they should be written +to a sequence rather than a map. +@param fs File storage +@param src Pointer to the written array +@param len Number of the array elements to write +@param dt Specification of each array element, see @ref format_spec "format specification" + */ +CVAPI(void) cvWriteRawData( CvFileStorage* fs, const void* src, + int len, const char* dt ); + +/** @brief Writes multiple numbers in Base64. + +If either CV_STORAGE_WRITE_BASE64 or cv::FileStorage::WRITE_BASE64 is used, +this function will be the same as cvWriteRawData. If neither, the main +difference is that it outputs a sequence in Base64 encoding rather than +in plain text. + +This function can only be used to write a sequence with a type "binary". + +@param fs File storage +@param src Pointer to the written array +@param len Number of the array elements to write +@param dt Specification of each array element, see @ref format_spec "format specification" +*/ +CVAPI(void) cvWriteRawDataBase64( CvFileStorage* fs, const void* src, + int len, const char* dt ); + +/** @brief Returns a unique pointer for a given name. + +The function returns a unique pointer for each particular file node name. This pointer can be then +passed to the cvGetFileNode function that is faster than cvGetFileNodeByName because it compares +text strings by comparing pointers rather than the strings' content. + +Consider the following example where an array of points is encoded as a sequence of 2-entry maps: +@code + points: + - { x: 10, y: 10 } + - { x: 20, y: 20 } + - { x: 30, y: 30 } + # ... +@endcode +Then, it is possible to get hashed "x" and "y" pointers to speed up decoding of the points. : +@code + #include "cxcore.h" + + int main( int argc, char** argv ) + { + CvFileStorage* fs = cvOpenFileStorage( "points.yml", 0, CV_STORAGE_READ ); + CvStringHashNode* x_key = cvGetHashedNode( fs, "x", -1, 1 ); + CvStringHashNode* y_key = cvGetHashedNode( fs, "y", -1, 1 ); + CvFileNode* points = cvGetFileNodeByName( fs, 0, "points" ); + + if( CV_NODE_IS_SEQ(points->tag) ) + { + CvSeq* seq = points->data.seq; + int i, total = seq->total; + CvSeqReader reader; + cvStartReadSeq( seq, &reader, 0 ); + for( i = 0; i < total; i++ ) + { + CvFileNode* pt = (CvFileNode*)reader.ptr; + #if 1 // faster variant + CvFileNode* xnode = cvGetFileNode( fs, pt, x_key, 0 ); + CvFileNode* ynode = cvGetFileNode( fs, pt, y_key, 0 ); + assert( xnode && CV_NODE_IS_INT(xnode->tag) && + ynode && CV_NODE_IS_INT(ynode->tag)); + int x = xnode->data.i; // or x = cvReadInt( xnode, 0 ); + int y = ynode->data.i; // or y = cvReadInt( ynode, 0 ); + #elif 1 // slower variant; does not use x_key & y_key + CvFileNode* xnode = cvGetFileNodeByName( fs, pt, "x" ); + CvFileNode* ynode = cvGetFileNodeByName( fs, pt, "y" ); + assert( xnode && CV_NODE_IS_INT(xnode->tag) && + ynode && CV_NODE_IS_INT(ynode->tag)); + int x = xnode->data.i; // or x = cvReadInt( xnode, 0 ); + int y = ynode->data.i; // or y = cvReadInt( ynode, 0 ); + #else // the slowest yet the easiest to use variant + int x = cvReadIntByName( fs, pt, "x", 0 ); + int y = cvReadIntByName( fs, pt, "y", 0 ); + #endif + CV_NEXT_SEQ_ELEM( seq->elem_size, reader ); + printf(" + } + } + cvReleaseFileStorage( &fs ); + return 0; + } +@endcode +Please note that whatever method of accessing a map you are using, it is still much slower than +using plain sequences; for example, in the above example, it is more efficient to encode the points +as pairs of integers in a single numeric sequence. +@param fs File storage +@param name Literal node name +@param len Length of the name (if it is known apriori), or -1 if it needs to be calculated +@param create_missing Flag that specifies, whether an absent key should be added into the hash table +*/ +CVAPI(CvStringHashNode*) cvGetHashedKey( CvFileStorage* fs, const char* name, + int len CV_DEFAULT(-1), + int create_missing CV_DEFAULT(0)); + +/** @brief Retrieves one of the top-level nodes of the file storage. + +The function returns one of the top-level file nodes. The top-level nodes do not have a name, they +correspond to the streams that are stored one after another in the file storage. If the index is out +of range, the function returns a NULL pointer, so all the top-level nodes can be iterated by +subsequent calls to the function with stream_index=0,1,..., until the NULL pointer is returned. +This function can be used as a base for recursive traversal of the file storage. +@param fs File storage +@param stream_index Zero-based index of the stream. See cvStartNextStream . In most cases, +there is only one stream in the file; however, there can be several. + */ +CVAPI(CvFileNode*) cvGetRootFileNode( const CvFileStorage* fs, + int stream_index CV_DEFAULT(0) ); + +/** @brief Finds a node in a map or file storage. + +The function finds a file node. It is a faster version of cvGetFileNodeByName (see +cvGetHashedKey discussion). Also, the function can insert a new node, if it is not in the map yet. +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. If both map and +key are NULLs, the function returns the root file node - a map that contains top-level nodes. +@param key Unique pointer to the node name, retrieved with cvGetHashedKey +@param create_missing Flag that specifies whether an absent node should be added to the map + */ +CVAPI(CvFileNode*) cvGetFileNode( CvFileStorage* fs, CvFileNode* map, + const CvStringHashNode* key, + int create_missing CV_DEFAULT(0) ); + +/** @brief Finds a node in a map or file storage. + +The function finds a file node by name. The node is searched either in map or, if the pointer is +NULL, among the top-level file storage nodes. Using this function for maps and cvGetSeqElem (or +sequence reader) for sequences, it is possible to navigate through the file storage. To speed up +multiple queries for a certain key (e.g., in the case of an array of structures) one may use a +combination of cvGetHashedKey and cvGetFileNode. +@param fs File storage +@param map The parent map. If it is NULL, the function searches in all the top-level nodes +(streams), starting with the first one. +@param name The file node name + */ +CVAPI(CvFileNode*) cvGetFileNodeByName( const CvFileStorage* fs, + const CvFileNode* map, + const char* name ); + +/** @brief Retrieves an integer value from a file node. + +The function returns an integer that is represented by the file node. If the file node is NULL, the +default_value is returned (thus, it is convenient to call the function right after cvGetFileNode +without checking for a NULL pointer). If the file node has type CV_NODE_INT, then node-\>data.i is +returned. If the file node has type CV_NODE_REAL, then node-\>data.f is converted to an integer +and returned. Otherwise the error is reported. +@param node File node +@param default_value The value that is returned if node is NULL + */ +CV_INLINE int cvReadInt( const CvFileNode* node, int default_value CV_DEFAULT(0) ) +{ + return !node ? default_value : + CV_NODE_IS_INT(node->tag) ? node->data.i : + CV_NODE_IS_REAL(node->tag) ? cvRound(node->data.f) : 0x7fffffff; +} + +/** @brief Finds a file node and returns its value. + +The function is a simple superposition of cvGetFileNodeByName and cvReadInt. +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param default_value The value that is returned if the file node is not found + */ +CV_INLINE int cvReadIntByName( const CvFileStorage* fs, const CvFileNode* map, + const char* name, int default_value CV_DEFAULT(0) ) +{ + return cvReadInt( cvGetFileNodeByName( fs, map, name ), default_value ); +} + +/** @brief Retrieves a floating-point value from a file node. + +The function returns a floating-point value that is represented by the file node. If the file node +is NULL, the default_value is returned (thus, it is convenient to call the function right after +cvGetFileNode without checking for a NULL pointer). If the file node has type CV_NODE_REAL , +then node-\>data.f is returned. If the file node has type CV_NODE_INT , then node-:math:\>data.f +is converted to floating-point and returned. Otherwise the result is not determined. +@param node File node +@param default_value The value that is returned if node is NULL + */ +CV_INLINE double cvReadReal( const CvFileNode* node, double default_value CV_DEFAULT(0.) ) +{ + return !node ? default_value : + CV_NODE_IS_INT(node->tag) ? (double)node->data.i : + CV_NODE_IS_REAL(node->tag) ? node->data.f : 1e300; +} + +/** @brief Finds a file node and returns its value. + +The function is a simple superposition of cvGetFileNodeByName and cvReadReal . +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param default_value The value that is returned if the file node is not found + */ +CV_INLINE double cvReadRealByName( const CvFileStorage* fs, const CvFileNode* map, + const char* name, double default_value CV_DEFAULT(0.) ) +{ + return cvReadReal( cvGetFileNodeByName( fs, map, name ), default_value ); +} + +/** @brief Retrieves a text string from a file node. + +The function returns a text string that is represented by the file node. If the file node is NULL, +the default_value is returned (thus, it is convenient to call the function right after +cvGetFileNode without checking for a NULL pointer). If the file node has type CV_NODE_STR , then +node-:math:\>data.str.ptr is returned. Otherwise the result is not determined. +@param node File node +@param default_value The value that is returned if node is NULL + */ +CV_INLINE const char* cvReadString( const CvFileNode* node, + const char* default_value CV_DEFAULT(NULL) ) +{ + return !node ? default_value : CV_NODE_IS_STRING(node->tag) ? node->data.str.ptr : 0; +} + +/** @brief Finds a file node by its name and returns its value. + +The function is a simple superposition of cvGetFileNodeByName and cvReadString . +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param default_value The value that is returned if the file node is not found + */ +CV_INLINE const char* cvReadStringByName( const CvFileStorage* fs, const CvFileNode* map, + const char* name, const char* default_value CV_DEFAULT(NULL) ) +{ + return cvReadString( cvGetFileNodeByName( fs, map, name ), default_value ); +} + + +/** @brief Decodes an object and returns a pointer to it. + +The function decodes a user object (creates an object in a native representation from the file +storage subtree) and returns it. The object to be decoded must be an instance of a registered type +that supports the read method (see CvTypeInfo). The type of the object is determined by the type +name that is encoded in the file. If the object is a dynamic structure, it is created either in +memory storage and passed to cvOpenFileStorage or, if a NULL pointer was passed, in temporary +memory storage, which is released when cvReleaseFileStorage is called. Otherwise, if the object is +not a dynamic structure, it is created in a heap and should be released with a specialized function +or by using the generic cvRelease. +@param fs File storage +@param node The root object node +@param attributes Unused parameter + */ +CVAPI(void*) cvRead( CvFileStorage* fs, CvFileNode* node, + CvAttrList* attributes CV_DEFAULT(NULL)); + +/** @brief Finds an object by name and decodes it. + +The function is a simple superposition of cvGetFileNodeByName and cvRead. +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param attributes Unused parameter + */ +CV_INLINE void* cvReadByName( CvFileStorage* fs, const CvFileNode* map, + const char* name, CvAttrList* attributes CV_DEFAULT(NULL) ) +{ + return cvRead( fs, cvGetFileNodeByName( fs, map, name ), attributes ); +} + + +/** @brief Initializes the file node sequence reader. + +The function initializes the sequence reader to read data from a file node. The initialized reader +can be then passed to cvReadRawDataSlice. +@param fs File storage +@param src The file node (a sequence) to read numbers from +@param reader Pointer to the sequence reader + */ +CVAPI(void) cvStartReadRawData( const CvFileStorage* fs, const CvFileNode* src, + CvSeqReader* reader ); + +/** @brief Initializes file node sequence reader. + +The function reads one or more elements from the file node, representing a sequence, to a +user-specified array. The total number of read sequence elements is a product of total and the +number of components in each array element. For example, if dt=2if, the function will read total\*3 +sequence elements. As with any sequence, some parts of the file node sequence can be skipped or read +repeatedly by repositioning the reader using cvSetSeqReaderPos. +@param fs File storage +@param reader The sequence reader. Initialize it with cvStartReadRawData . +@param count The number of elements to read +@param dst Pointer to the destination array +@param dt Specification of each array element. It has the same format as in cvWriteRawData . + */ +CVAPI(void) cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader, + int count, void* dst, const char* dt ); + +/** @brief Reads multiple numbers. + +The function reads elements from a file node that represents a sequence of scalars. +@param fs File storage +@param src The file node (a sequence) to read numbers from +@param dst Pointer to the destination array +@param dt Specification of each array element. It has the same format as in cvWriteRawData . + */ +CVAPI(void) cvReadRawData( const CvFileStorage* fs, const CvFileNode* src, + void* dst, const char* dt ); + +/** @brief Writes a file node to another file storage. + +The function writes a copy of a file node to file storage. Possible applications of the function are +merging several file storages into one and conversion between XML, YAML and JSON formats. +@param fs Destination file storage +@param new_node_name New name of the file node in the destination file storage. To keep the +existing name, use cvcvGetFileNodeName +@param node The written node +@param embed If the written node is a collection and this parameter is not zero, no extra level of +hierarchy is created. Instead, all the elements of node are written into the currently written +structure. Of course, map elements can only be embedded into another map, and sequence elements +can only be embedded into another sequence. + */ +CVAPI(void) cvWriteFileNode( CvFileStorage* fs, const char* new_node_name, + const CvFileNode* node, int embed ); + +/** @brief Returns the name of a file node. + +The function returns the name of a file node or NULL, if the file node does not have a name or if +node is NULL. +@param node File node + */ +CVAPI(const char*) cvGetFileNodeName( const CvFileNode* node ); + +/*********************************** Adding own types ***********************************/ + +/** @brief Registers a new type. + +The function registers a new type, which is described by info . The function creates a copy of the +structure, so the user should delete it after calling the function. +@param info Type info structure + */ +CVAPI(void) cvRegisterType( const CvTypeInfo* info ); + +/** @brief Unregisters the type. + +The function unregisters a type with a specified name. If the name is unknown, it is possible to +locate the type info by an instance of the type using cvTypeOf or by iterating the type list, +starting from cvFirstType, and then calling cvUnregisterType(info-\>typeName). +@param type_name Name of an unregistered type + */ +CVAPI(void) cvUnregisterType( const char* type_name ); + +/** @brief Returns the beginning of a type list. + +The function returns the first type in the list of registered types. Navigation through the list can +be done via the prev and next fields of the CvTypeInfo structure. + */ +CVAPI(CvTypeInfo*) cvFirstType(void); + +/** @brief Finds a type by its name. + +The function finds a registered type by its name. It returns NULL if there is no type with the +specified name. +@param type_name Type name + */ +CVAPI(CvTypeInfo*) cvFindType( const char* type_name ); + +/** @brief Returns the type of an object. + +The function finds the type of a given object. It iterates through the list of registered types and +calls the is_instance function/method for every type info structure with that object until one of +them returns non-zero or until the whole list has been traversed. In the latter case, the function +returns NULL. +@param struct_ptr The object pointer + */ +CVAPI(CvTypeInfo*) cvTypeOf( const void* struct_ptr ); + +/** @brief Releases an object. + +The function finds the type of a given object and calls release with the double pointer. +@param struct_ptr Double pointer to the object + */ +CVAPI(void) cvRelease( void** struct_ptr ); + +/** @brief Makes a clone of an object. + +The function finds the type of a given object and calls clone with the passed object. Of course, if +you know the object type, for example, struct_ptr is CvMat\*, it is faster to call the specific +function, like cvCloneMat. +@param struct_ptr The object to clone + */ +CVAPI(void*) cvClone( const void* struct_ptr ); + +/** @brief Saves an object to a file. + +The function saves an object to a file. It provides a simple interface to cvWrite . +@param filename File name +@param struct_ptr Object to save +@param name Optional object name. If it is NULL, the name will be formed from filename . +@param comment Optional comment to put in the beginning of the file +@param attributes Optional attributes passed to cvWrite + */ +CVAPI(void) cvSave( const char* filename, const void* struct_ptr, + const char* name CV_DEFAULT(NULL), + const char* comment CV_DEFAULT(NULL), + CvAttrList attributes CV_DEFAULT(cvAttrList())); + +/** @brief Loads an object from a file. + +The function loads an object from a file. It basically reads the specified file, find the first +top-level node and calls cvRead for that node. If the file node does not have type information or +the type information can not be found by the type name, the function returns NULL. After the object +is loaded, the file storage is closed and all the temporary buffers are deleted. Thus, to load a +dynamic structure, such as a sequence, contour, or graph, one should pass a valid memory storage +destination to the function. +@param filename File name +@param memstorage Memory storage for dynamic structures, such as CvSeq or CvGraph . It is not used +for matrices or images. +@param name Optional object name. If it is NULL, the first top-level object in the storage will be +loaded. +@param real_name Optional output parameter that will contain the name of the loaded object +(useful if name=NULL ) + */ +CVAPI(void*) cvLoad( const char* filename, + CvMemStorage* memstorage CV_DEFAULT(NULL), + const char* name CV_DEFAULT(NULL), + const char** real_name CV_DEFAULT(NULL) ); + +/*********************************** Measuring Execution Time ***************************/ + +/** helper functions for RNG initialization and accurate time measurement: + uses internal clock counter on x86 */ +CVAPI(int64) cvGetTickCount( void ); +CVAPI(double) cvGetTickFrequency( void ); + +/*********************************** CPU capabilities ***********************************/ + +CVAPI(int) cvCheckHardwareSupport(int feature); + +/*********************************** Multi-Threading ************************************/ + +/** retrieve/set the number of threads used in OpenMP implementations */ +CVAPI(int) cvGetNumThreads( void ); +CVAPI(void) cvSetNumThreads( int threads CV_DEFAULT(0) ); +/** get index of the thread being executed */ +CVAPI(int) cvGetThreadNum( void ); + + +/********************************** Error Handling **************************************/ + +/** Get current OpenCV error status */ +CVAPI(int) cvGetErrStatus( void ); + +/** Sets error status silently */ +CVAPI(void) cvSetErrStatus( int status ); + +#define CV_ErrModeLeaf 0 /* Print error and exit program */ +#define CV_ErrModeParent 1 /* Print error and continue */ +#define CV_ErrModeSilent 2 /* Don't print and continue */ + +/** Retrieves current error processing mode */ +CVAPI(int) cvGetErrMode( void ); + +/** Sets error processing mode, returns previously used mode */ +CVAPI(int) cvSetErrMode( int mode ); + +/** Sets error status and performs some additional actions (displaying message box, + writing message to stderr, terminating application etc.) + depending on the current error mode */ +CVAPI(void) cvError( int status, const char* func_name, + const char* err_msg, const char* file_name, int line ); + +/** Retrieves textual description of the error given its code */ +CVAPI(const char*) cvErrorStr( int status ); + +/** Retrieves detailed information about the last error occurred */ +CVAPI(int) cvGetErrInfo( const char** errcode_desc, const char** description, + const char** filename, int* line ); + +/** Maps IPP error codes to the counterparts from OpenCV */ +CVAPI(int) cvErrorFromIppStatus( int ipp_status ); + +typedef int (CV_CDECL *CvErrorCallback)( int status, const char* func_name, + const char* err_msg, const char* file_name, int line, void* userdata ); + +/** Assigns a new error-handling function */ +CVAPI(CvErrorCallback) cvRedirectError( CvErrorCallback error_handler, + void* userdata CV_DEFAULT(NULL), + void** prev_userdata CV_DEFAULT(NULL) ); + +/** Output nothing */ +CVAPI(int) cvNulDevReport( int status, const char* func_name, const char* err_msg, + const char* file_name, int line, void* userdata ); + +/** Output to console(fprintf(stderr,...)) */ +CVAPI(int) cvStdErrReport( int status, const char* func_name, const char* err_msg, + const char* file_name, int line, void* userdata ); + +/** Output to MessageBox(WIN32) */ +CVAPI(int) cvGuiBoxReport( int status, const char* func_name, const char* err_msg, + const char* file_name, int line, void* userdata ); + +#define OPENCV_ERROR(status,func,context) \ +cvError((status),(func),(context),__FILE__,__LINE__) + +#define OPENCV_ASSERT(expr,func,context) \ +{if (! (expr)) \ +{OPENCV_ERROR(CV_StsInternal,(func),(context));}} + +#define OPENCV_CALL( Func ) \ +{ \ +Func; \ +} + + +/** CV_FUNCNAME macro defines icvFuncName constant which is used by CV_ERROR macro */ +#ifdef CV_NO_FUNC_NAMES +#define CV_FUNCNAME( Name ) +#define cvFuncName "" +#else +#define CV_FUNCNAME( Name ) \ +static char cvFuncName[] = Name +#endif + + +/** + CV_ERROR macro unconditionally raises error with passed code and message. + After raising error, control will be transferred to the exit label. + */ +#define CV_ERROR( Code, Msg ) \ +{ \ + cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \ + __CV_EXIT__; \ +} + +/** + CV_CHECK macro checks error status after CV (or IPL) + function call. If error detected, control will be transferred to the exit + label. + */ +#define CV_CHECK() \ +{ \ + if( cvGetErrStatus() < 0 ) \ + CV_ERROR( CV_StsBackTrace, "Inner function failed." ); \ +} + + +/** + CV_CALL macro calls CV (or IPL) function, checks error status and + signals a error if the function failed. Useful in "parent node" + error processing mode + */ +#define CV_CALL( Func ) \ +{ \ + Func; \ + CV_CHECK(); \ +} + + +/** Runtime assertion macro */ +#define CV_ASSERT( Condition ) \ +{ \ + if( !(Condition) ) \ + CV_ERROR( CV_StsInternal, "Assertion: " #Condition " failed" ); \ +} + +#define __CV_BEGIN__ { +#define __CV_END__ goto exit; exit: ; } +#define __CV_EXIT__ goto exit + +/** @} core_c */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifdef __cplusplus + +//! @addtogroup core_c_glue +//! @{ + +//! class for automatic module/RTTI data registration/unregistration +struct CV_EXPORTS CvType +{ + CvType( const char* type_name, + CvIsInstanceFunc is_instance, CvReleaseFunc release=0, + CvReadFunc read=0, CvWriteFunc write=0, CvCloneFunc clone=0 ); + ~CvType(); + CvTypeInfo* info; + + static CvTypeInfo* first; + static CvTypeInfo* last; +}; + +//! @} + +#include "opencv2/core/utility.hpp" + +namespace cv +{ + +//! @addtogroup core_c_glue +//! @{ + +/////////////////////////////////////////// glue /////////////////////////////////////////// + +//! converts array (CvMat or IplImage) to cv::Mat +CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false, + bool allowND=true, int coiMode=0, + AutoBuffer<double>* buf=0); + +static inline Mat cvarrToMatND(const CvArr* arr, bool copyData=false, int coiMode=0) +{ + return cvarrToMat(arr, copyData, true, coiMode); +} + + +//! extracts Channel of Interest from CvMat or IplImage and makes cv::Mat out of it. +CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1); +//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage +CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1); + + + +////// specialized implementations of DefaultDeleter::operator() for classic OpenCV types ////// + +template<> CV_EXPORTS void DefaultDeleter<CvMat>::operator ()(CvMat* obj) const; +template<> CV_EXPORTS void DefaultDeleter<IplImage>::operator ()(IplImage* obj) const; +template<> CV_EXPORTS void DefaultDeleter<CvMatND>::operator ()(CvMatND* obj) const; +template<> CV_EXPORTS void DefaultDeleter<CvSparseMat>::operator ()(CvSparseMat* obj) const; +template<> CV_EXPORTS void DefaultDeleter<CvMemStorage>::operator ()(CvMemStorage* obj) const; + +////////////// convenient wrappers for operating old-style dynamic structures ////////////// + +template<typename _Tp> class SeqIterator; + +typedef Ptr<CvMemStorage> MemStorage; + +/*! + Template Sequence Class derived from CvSeq + + The class provides more convenient access to sequence elements, + STL-style operations and iterators. + + \note The class is targeted for simple data types, + i.e. no constructors or destructors + are called for the sequence elements. +*/ +template<typename _Tp> class Seq +{ +public: + typedef SeqIterator<_Tp> iterator; + typedef SeqIterator<_Tp> const_iterator; + + //! the default constructor + Seq(); + //! the constructor for wrapping CvSeq structure. The real element type in CvSeq should match _Tp. + Seq(const CvSeq* seq); + //! creates the empty sequence that resides in the specified storage + Seq(MemStorage& storage, int headerSize = sizeof(CvSeq)); + //! returns read-write reference to the specified element + _Tp& operator [](int idx); + //! returns read-only reference to the specified element + const _Tp& operator[](int idx) const; + //! returns iterator pointing to the beginning of the sequence + SeqIterator<_Tp> begin() const; + //! returns iterator pointing to the element following the last sequence element + SeqIterator<_Tp> end() const; + //! returns the number of elements in the sequence + size_t size() const; + //! returns the type of sequence elements (CV_8UC1 ... CV_64FC(CV_CN_MAX) ...) + int type() const; + //! returns the depth of sequence elements (CV_8U ... CV_64F) + int depth() const; + //! returns the number of channels in each sequence element + int channels() const; + //! returns the size of each sequence element + size_t elemSize() const; + //! returns index of the specified sequence element + size_t index(const _Tp& elem) const; + //! appends the specified element to the end of the sequence + void push_back(const _Tp& elem); + //! appends the specified element to the front of the sequence + void push_front(const _Tp& elem); + //! appends zero or more elements to the end of the sequence + void push_back(const _Tp* elems, size_t count); + //! appends zero or more elements to the front of the sequence + void push_front(const _Tp* elems, size_t count); + //! inserts the specified element to the specified position + void insert(int idx, const _Tp& elem); + //! inserts zero or more elements to the specified position + void insert(int idx, const _Tp* elems, size_t count); + //! removes element at the specified position + void remove(int idx); + //! removes the specified subsequence + void remove(const Range& r); + + //! returns reference to the first sequence element + _Tp& front(); + //! returns read-only reference to the first sequence element + const _Tp& front() const; + //! returns reference to the last sequence element + _Tp& back(); + //! returns read-only reference to the last sequence element + const _Tp& back() const; + //! returns true iff the sequence contains no elements + bool empty() const; + + //! removes all the elements from the sequence + void clear(); + //! removes the first element from the sequence + void pop_front(); + //! removes the last element from the sequence + void pop_back(); + //! removes zero or more elements from the beginning of the sequence + void pop_front(_Tp* elems, size_t count); + //! removes zero or more elements from the end of the sequence + void pop_back(_Tp* elems, size_t count); + + //! copies the whole sequence or the sequence slice to the specified vector + void copyTo(std::vector<_Tp>& vec, const Range& range=Range::all()) const; + //! returns the vector containing all the sequence elements + operator std::vector<_Tp>() const; + + CvSeq* seq; +}; + + +/*! + STL-style Sequence Iterator inherited from the CvSeqReader structure +*/ +template<typename _Tp> class SeqIterator : public CvSeqReader +{ +public: + //! the default constructor + SeqIterator(); + //! the constructor setting the iterator to the beginning or to the end of the sequence + SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false); + //! positions the iterator within the sequence + void seek(size_t pos); + //! reports the current iterator position + size_t tell() const; + //! returns reference to the current sequence element + _Tp& operator *(); + //! returns read-only reference to the current sequence element + const _Tp& operator *() const; + //! moves iterator to the next sequence element + SeqIterator& operator ++(); + //! moves iterator to the next sequence element + SeqIterator operator ++(int) const; + //! moves iterator to the previous sequence element + SeqIterator& operator --(); + //! moves iterator to the previous sequence element + SeqIterator operator --(int) const; + + //! moves iterator forward by the specified offset (possibly negative) + SeqIterator& operator +=(int); + //! moves iterator backward by the specified offset (possibly negative) + SeqIterator& operator -=(int); + + // this is index of the current element module seq->total*2 + // (to distinguish between 0 and seq->total) + int index; +}; + + + +// bridge C++ => C Seq API +CV_EXPORTS schar* seqPush( CvSeq* seq, const void* element=0); +CV_EXPORTS schar* seqPushFront( CvSeq* seq, const void* element=0); +CV_EXPORTS void seqPop( CvSeq* seq, void* element=0); +CV_EXPORTS void seqPopFront( CvSeq* seq, void* element=0); +CV_EXPORTS void seqPopMulti( CvSeq* seq, void* elements, + int count, int in_front=0 ); +CV_EXPORTS void seqRemove( CvSeq* seq, int index ); +CV_EXPORTS void clearSeq( CvSeq* seq ); +CV_EXPORTS schar* getSeqElem( const CvSeq* seq, int index ); +CV_EXPORTS void seqRemoveSlice( CvSeq* seq, CvSlice slice ); +CV_EXPORTS void seqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); + +template<typename _Tp> inline Seq<_Tp>::Seq() : seq(0) {} +template<typename _Tp> inline Seq<_Tp>::Seq( const CvSeq* _seq ) : seq((CvSeq*)_seq) +{ + CV_Assert(!_seq || _seq->elem_size == sizeof(_Tp)); +} + +template<typename _Tp> inline Seq<_Tp>::Seq( MemStorage& storage, + int headerSize ) +{ + CV_Assert(headerSize >= (int)sizeof(CvSeq)); + seq = cvCreateSeq(DataType<_Tp>::type, headerSize, sizeof(_Tp), storage); +} + +template<typename _Tp> inline _Tp& Seq<_Tp>::operator [](int idx) +{ return *(_Tp*)getSeqElem(seq, idx); } + +template<typename _Tp> inline const _Tp& Seq<_Tp>::operator [](int idx) const +{ return *(_Tp*)getSeqElem(seq, idx); } + +template<typename _Tp> inline SeqIterator<_Tp> Seq<_Tp>::begin() const +{ return SeqIterator<_Tp>(*this); } + +template<typename _Tp> inline SeqIterator<_Tp> Seq<_Tp>::end() const +{ return SeqIterator<_Tp>(*this, true); } + +template<typename _Tp> inline size_t Seq<_Tp>::size() const +{ return seq ? seq->total : 0; } + +template<typename _Tp> inline int Seq<_Tp>::type() const +{ return seq ? CV_MAT_TYPE(seq->flags) : 0; } + +template<typename _Tp> inline int Seq<_Tp>::depth() const +{ return seq ? CV_MAT_DEPTH(seq->flags) : 0; } + +template<typename _Tp> inline int Seq<_Tp>::channels() const +{ return seq ? CV_MAT_CN(seq->flags) : 0; } + +template<typename _Tp> inline size_t Seq<_Tp>::elemSize() const +{ return seq ? seq->elem_size : 0; } + +template<typename _Tp> inline size_t Seq<_Tp>::index(const _Tp& elem) const +{ return cvSeqElemIdx(seq, &elem); } + +template<typename _Tp> inline void Seq<_Tp>::push_back(const _Tp& elem) +{ cvSeqPush(seq, &elem); } + +template<typename _Tp> inline void Seq<_Tp>::push_front(const _Tp& elem) +{ cvSeqPushFront(seq, &elem); } + +template<typename _Tp> inline void Seq<_Tp>::push_back(const _Tp* elem, size_t count) +{ cvSeqPushMulti(seq, elem, (int)count, 0); } + +template<typename _Tp> inline void Seq<_Tp>::push_front(const _Tp* elem, size_t count) +{ cvSeqPushMulti(seq, elem, (int)count, 1); } + +template<typename _Tp> inline _Tp& Seq<_Tp>::back() +{ return *(_Tp*)getSeqElem(seq, -1); } + +template<typename _Tp> inline const _Tp& Seq<_Tp>::back() const +{ return *(const _Tp*)getSeqElem(seq, -1); } + +template<typename _Tp> inline _Tp& Seq<_Tp>::front() +{ return *(_Tp*)getSeqElem(seq, 0); } + +template<typename _Tp> inline const _Tp& Seq<_Tp>::front() const +{ return *(const _Tp*)getSeqElem(seq, 0); } + +template<typename _Tp> inline bool Seq<_Tp>::empty() const +{ return !seq || seq->total == 0; } + +template<typename _Tp> inline void Seq<_Tp>::clear() +{ if(seq) clearSeq(seq); } + +template<typename _Tp> inline void Seq<_Tp>::pop_back() +{ seqPop(seq); } + +template<typename _Tp> inline void Seq<_Tp>::pop_front() +{ seqPopFront(seq); } + +template<typename _Tp> inline void Seq<_Tp>::pop_back(_Tp* elem, size_t count) +{ seqPopMulti(seq, elem, (int)count, 0); } + +template<typename _Tp> inline void Seq<_Tp>::pop_front(_Tp* elem, size_t count) +{ seqPopMulti(seq, elem, (int)count, 1); } + +template<typename _Tp> inline void Seq<_Tp>::insert(int idx, const _Tp& elem) +{ seqInsert(seq, idx, &elem); } + +template<typename _Tp> inline void Seq<_Tp>::insert(int idx, const _Tp* elems, size_t count) +{ + CvMat m = cvMat(1, count, DataType<_Tp>::type, elems); + seqInsertSlice(seq, idx, &m); +} + +template<typename _Tp> inline void Seq<_Tp>::remove(int idx) +{ seqRemove(seq, idx); } + +template<typename _Tp> inline void Seq<_Tp>::remove(const Range& r) +{ seqRemoveSlice(seq, cvSlice(r.start, r.end)); } + +template<typename _Tp> inline void Seq<_Tp>::copyTo(std::vector<_Tp>& vec, const Range& range) const +{ + size_t len = !seq ? 0 : range == Range::all() ? seq->total : range.end - range.start; + vec.resize(len); + if( seq && len ) + cvCvtSeqToArray(seq, &vec[0], cvSlice(range)); +} + +template<typename _Tp> inline Seq<_Tp>::operator std::vector<_Tp>() const +{ + std::vector<_Tp> vec; + copyTo(vec); + return vec; +} + +template<typename _Tp> inline SeqIterator<_Tp>::SeqIterator() +{ memset(this, 0, sizeof(*this)); } + +template<typename _Tp> inline SeqIterator<_Tp>::SeqIterator(const Seq<_Tp>& _seq, bool seekEnd) +{ + cvStartReadSeq(_seq.seq, this); + index = seekEnd ? _seq.seq->total : 0; +} + +template<typename _Tp> inline void SeqIterator<_Tp>::seek(size_t pos) +{ + cvSetSeqReaderPos(this, (int)pos, false); + index = pos; +} + +template<typename _Tp> inline size_t SeqIterator<_Tp>::tell() const +{ return index; } + +template<typename _Tp> inline _Tp& SeqIterator<_Tp>::operator *() +{ return *(_Tp*)ptr; } + +template<typename _Tp> inline const _Tp& SeqIterator<_Tp>::operator *() const +{ return *(const _Tp*)ptr; } + +template<typename _Tp> inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator ++() +{ + CV_NEXT_SEQ_ELEM(sizeof(_Tp), *this); + if( ++index >= seq->total*2 ) + index = 0; + return *this; +} + +template<typename _Tp> inline SeqIterator<_Tp> SeqIterator<_Tp>::operator ++(int) const +{ + SeqIterator<_Tp> it = *this; + ++*this; + return it; +} + +template<typename _Tp> inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator --() +{ + CV_PREV_SEQ_ELEM(sizeof(_Tp), *this); + if( --index < 0 ) + index = seq->total*2-1; + return *this; +} + +template<typename _Tp> inline SeqIterator<_Tp> SeqIterator<_Tp>::operator --(int) const +{ + SeqIterator<_Tp> it = *this; + --*this; + return it; +} + +template<typename _Tp> inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator +=(int delta) +{ + cvSetSeqReaderPos(this, delta, 1); + index += delta; + int n = seq->total*2; + if( index < 0 ) + index += n; + if( index >= n ) + index -= n; + return *this; +} + +template<typename _Tp> inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator -=(int delta) +{ + return (*this += -delta); +} + +template<typename _Tp> inline ptrdiff_t operator - (const SeqIterator<_Tp>& a, + const SeqIterator<_Tp>& b) +{ + ptrdiff_t delta = a.index - b.index, n = a.seq->total; + if( delta > n || delta < -n ) + delta += delta < 0 ? n : -n; + return delta; +} + +template<typename _Tp> inline bool operator == (const SeqIterator<_Tp>& a, + const SeqIterator<_Tp>& b) +{ + return a.seq == b.seq && a.index == b.index; +} + +template<typename _Tp> inline bool operator != (const SeqIterator<_Tp>& a, + const SeqIterator<_Tp>& b) +{ + return !(a == b); +} + +//! @} + +} // cv + +#endif + +#endif diff --git a/include/opencv2/core/cuda.hpp b/include/opencv2/core/cuda.hpp new file mode 100644 index 0000000..820aba7 --- /dev/null +++ b/include/opencv2/core/cuda.hpp @@ -0,0 +1,1049 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CUDA_HPP +#define OPENCV_CORE_CUDA_HPP + +#ifndef __cplusplus +# error cuda.hpp header must be compiled as C++ +#endif + +#include "opencv2/core.hpp" +#include "opencv2/core/cuda_types.hpp" + +/** + @defgroup cuda CUDA-accelerated Computer Vision + @{ + @defgroup cudacore Core part + @{ + @defgroup cudacore_init Initialization and Information + @defgroup cudacore_struct Data Structures + @} + @} + */ + +namespace cv { namespace cuda { + +//! @addtogroup cudacore_struct +//! @{ + +//=================================================================================== +// GpuMat +//=================================================================================== + +/** @brief Base storage class for GPU memory with reference counting. + +Its interface matches the Mat interface with the following limitations: + +- no arbitrary dimensions support (only 2D) +- no functions that return references to their data (because references on GPU are not valid for + CPU) +- no expression templates technique support + +Beware that the latter limitation may lead to overloaded matrix operators that cause memory +allocations. The GpuMat class is convertible to cuda::PtrStepSz and cuda::PtrStep so it can be +passed directly to the kernel. + +@note In contrast with Mat, in most cases GpuMat::isContinuous() == false . This means that rows are +aligned to a size depending on the hardware. Single-row GpuMat is always a continuous matrix. + +@note You are not recommended to leave static or global GpuMat variables allocated, that is, to rely +on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory +release function returns error if the CUDA context has been destroyed before. + +Some member functions are described as a "Blocking Call" while some are described as a +"Non-Blocking Call". Blocking functions are synchronous to host. It is guaranteed that the GPU +operation is finished when the function returns. However, non-blocking functions are asynchronous to +host. Those functions may return even if the GPU operation is not finished. + +Compared to their blocking counterpart, non-blocking functions accept Stream as an additional +argument. If a non-default stream is passed, the GPU operation may overlap with operations in other +streams. + +@sa Mat + */ +class CV_EXPORTS GpuMat +{ +public: + class CV_EXPORTS Allocator + { + public: + virtual ~Allocator() {} + + // allocator must fill data, step and refcount fields + virtual bool allocate(GpuMat* mat, int rows, int cols, size_t elemSize) = 0; + virtual void free(GpuMat* mat) = 0; + }; + + //! default allocator + static Allocator* defaultAllocator(); + static void setDefaultAllocator(Allocator* allocator); + + //! default constructor + explicit GpuMat(Allocator* allocator = defaultAllocator()); + + //! constructs GpuMat of the specified size and type + GpuMat(int rows, int cols, int type, Allocator* allocator = defaultAllocator()); + GpuMat(Size size, int type, Allocator* allocator = defaultAllocator()); + + //! constucts GpuMat and fills it with the specified value _s + GpuMat(int rows, int cols, int type, Scalar s, Allocator* allocator = defaultAllocator()); + GpuMat(Size size, int type, Scalar s, Allocator* allocator = defaultAllocator()); + + //! copy constructor + GpuMat(const GpuMat& m); + + //! constructor for GpuMat headers pointing to user-allocated data + GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP); + GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP); + + //! creates a GpuMat header for a part of the bigger matrix + GpuMat(const GpuMat& m, Range rowRange, Range colRange); + GpuMat(const GpuMat& m, Rect roi); + + //! builds GpuMat from host memory (Blocking call) + explicit GpuMat(InputArray arr, Allocator* allocator = defaultAllocator()); + + //! destructor - calls release() + ~GpuMat(); + + //! assignment operators + GpuMat& operator =(const GpuMat& m); + + //! allocates new GpuMat data unless the GpuMat already has specified size and type + void create(int rows, int cols, int type); + void create(Size size, int type); + + //! decreases reference counter, deallocate the data when reference counter reaches 0 + void release(); + + //! swaps with other smart pointer + void swap(GpuMat& mat); + + /** @brief Performs data upload to GpuMat (Blocking call) + + This function copies data from host memory to device memory. As being a blocking call, it is + guaranteed that the copy operation is finished when this function returns. + */ + void upload(InputArray arr); + + /** @brief Performs data upload to GpuMat (Non-Blocking call) + + This function copies data from host memory to device memory. As being a non-blocking call, this + function may return even if the copy operation is not finished. + + The copy operation may be overlapped with operations in other non-default streams if \p stream is + not the default stream and \p dst is HostMem allocated with HostMem::PAGE_LOCKED option. + */ + void upload(InputArray arr, Stream& stream); + + /** @brief Performs data download from GpuMat (Blocking call) + + This function copies data from device memory to host memory. As being a blocking call, it is + guaranteed that the copy operation is finished when this function returns. + */ + void download(OutputArray dst) const; + + /** @brief Performs data download from GpuMat (Non-Blocking call) + + This function copies data from device memory to host memory. As being a non-blocking call, this + function may return even if the copy operation is not finished. + + The copy operation may be overlapped with operations in other non-default streams if \p stream is + not the default stream and \p dst is HostMem allocated with HostMem::PAGE_LOCKED option. + */ + void download(OutputArray dst, Stream& stream) const; + + //! returns deep copy of the GpuMat, i.e. the data is copied + GpuMat clone() const; + + //! copies the GpuMat content to device memory (Blocking call) + void copyTo(OutputArray dst) const; + + //! copies the GpuMat content to device memory (Non-Blocking call) + void copyTo(OutputArray dst, Stream& stream) const; + + //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Blocking call) + void copyTo(OutputArray dst, InputArray mask) const; + + //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Non-Blocking call) + void copyTo(OutputArray dst, InputArray mask, Stream& stream) const; + + //! sets some of the GpuMat elements to s (Blocking call) + GpuMat& setTo(Scalar s); + + //! sets some of the GpuMat elements to s (Non-Blocking call) + GpuMat& setTo(Scalar s, Stream& stream); + + //! sets some of the GpuMat elements to s, according to the mask (Blocking call) + GpuMat& setTo(Scalar s, InputArray mask); + + //! sets some of the GpuMat elements to s, according to the mask (Non-Blocking call) + GpuMat& setTo(Scalar s, InputArray mask, Stream& stream); + + //! converts GpuMat to another datatype (Blocking call) + void convertTo(OutputArray dst, int rtype) const; + + //! converts GpuMat to another datatype (Non-Blocking call) + void convertTo(OutputArray dst, int rtype, Stream& stream) const; + + //! converts GpuMat to another datatype with scaling (Blocking call) + void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const; + + //! converts GpuMat to another datatype with scaling (Non-Blocking call) + void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const; + + //! converts GpuMat to another datatype with scaling (Non-Blocking call) + void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const; + + void assignTo(GpuMat& m, int type=-1) const; + + //! returns pointer to y-th row + uchar* ptr(int y = 0); + const uchar* ptr(int y = 0) const; + + //! template version of the above method + template<typename _Tp> _Tp* ptr(int y = 0); + template<typename _Tp> const _Tp* ptr(int y = 0) const; + + template <typename _Tp> operator PtrStepSz<_Tp>() const; + template <typename _Tp> operator PtrStep<_Tp>() const; + + //! returns a new GpuMat header for the specified row + GpuMat row(int y) const; + + //! returns a new GpuMat header for the specified column + GpuMat col(int x) const; + + //! ... for the specified row span + GpuMat rowRange(int startrow, int endrow) const; + GpuMat rowRange(Range r) const; + + //! ... for the specified column span + GpuMat colRange(int startcol, int endcol) const; + GpuMat colRange(Range r) const; + + //! extracts a rectangular sub-GpuMat (this is a generalized form of row, rowRange etc.) + GpuMat operator ()(Range rowRange, Range colRange) const; + GpuMat operator ()(Rect roi) const; + + //! creates alternative GpuMat header for the same data, with different + //! number of channels and/or different number of rows + GpuMat reshape(int cn, int rows = 0) const; + + //! locates GpuMat header within a parent GpuMat + void locateROI(Size& wholeSize, Point& ofs) const; + + //! moves/resizes the current GpuMat ROI inside the parent GpuMat + GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright); + + //! returns true iff the GpuMat data is continuous + //! (i.e. when there are no gaps between successive rows) + bool isContinuous() const; + + //! returns element size in bytes + size_t elemSize() const; + + //! returns the size of element channel in bytes + size_t elemSize1() const; + + //! returns element type + int type() const; + + //! returns element type + int depth() const; + + //! returns number of channels + int channels() const; + + //! returns step/elemSize1() + size_t step1() const; + + //! returns GpuMat size : width == number of columns, height == number of rows + Size size() const; + + //! returns true if GpuMat data is NULL + bool empty() const; + + //! internal use method: updates the continuity flag + void updateContinuityFlag(); + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + + //! the number of rows and columns + int rows, cols; + + //! a distance between successive rows in bytes; includes the gap if any + size_t step; + + //! pointer to the data + uchar* data; + + //! pointer to the reference counter; + //! when GpuMat points to user-allocated data, the pointer is NULL + int* refcount; + + //! helper fields used in locateROI and adjustROI + uchar* datastart; + const uchar* dataend; + + //! allocator + Allocator* allocator; +}; + +/** @brief Creates a continuous matrix. + +@param rows Row count. +@param cols Column count. +@param type Type of the matrix. +@param arr Destination matrix. This parameter changes only if it has a proper type and area ( +\f$\texttt{rows} \times \texttt{cols}\f$ ). + +Matrix is called continuous if its elements are stored continuously, that is, without gaps at the +end of each row. + */ +CV_EXPORTS void createContinuous(int rows, int cols, int type, OutputArray arr); + +/** @brief Ensures that the size of a matrix is big enough and the matrix has a proper type. + +@param rows Minimum desired number of rows. +@param cols Minimum desired number of columns. +@param type Desired matrix type. +@param arr Destination matrix. + +The function does not reallocate memory if the matrix has proper attributes already. + */ +CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr); + +/** @brief BufferPool for use with CUDA streams + +BufferPool utilizes Stream's allocator to create new buffers for GpuMat's. It is +only useful when enabled with #setBufferPoolUsage. + +@code + setBufferPoolUsage(true); +@endcode + +@note #setBufferPoolUsage must be called \em before any Stream declaration. + +Users may specify custom allocator for Stream and may implement their own stream based +functions utilizing the same underlying GPU memory management. + +If custom allocator is not specified, BufferPool utilizes StackAllocator by +default. StackAllocator allocates a chunk of GPU device memory beforehand, +and when GpuMat is declared later on, it is given the pre-allocated memory. +This kind of strategy reduces the number of calls for memory allocating APIs +such as cudaMalloc or cudaMallocPitch. + +Below is an example that utilizes BufferPool with StackAllocator: + +@code + #include <opencv2/opencv.hpp> + + using namespace cv; + using namespace cv::cuda + + int main() + { + setBufferPoolUsage(true); // Tell OpenCV that we are going to utilize BufferPool + setBufferPoolConfig(getDevice(), 1024 * 1024 * 64, 2); // Allocate 64 MB, 2 stacks (default is 10 MB, 5 stacks) + + Stream stream1, stream2; // Each stream uses 1 stack + BufferPool pool1(stream1), pool2(stream2); + + GpuMat d_src1 = pool1.getBuffer(4096, 4096, CV_8UC1); // 16MB + GpuMat d_dst1 = pool1.getBuffer(4096, 4096, CV_8UC3); // 48MB, pool1 is now full + + GpuMat d_src2 = pool2.getBuffer(1024, 1024, CV_8UC1); // 1MB + GpuMat d_dst2 = pool2.getBuffer(1024, 1024, CV_8UC3); // 3MB + + cvtColor(d_src1, d_dst1, CV_GRAY2BGR, 0, stream1); + cvtColor(d_src2, d_dst2, CV_GRAY2BGR, 0, stream2); + } +@endcode + +If we allocate another GpuMat on pool1 in the above example, it will be carried out by +the DefaultAllocator since the stack for pool1 is full. + +@code + GpuMat d_add1 = pool1.getBuffer(1024, 1024, CV_8UC1); // Stack for pool1 is full, memory is allocated with DefaultAllocator +@endcode + +If a third stream is declared in the above example, allocating with #getBuffer +within that stream will also be carried out by the DefaultAllocator because we've run out of +stacks. + +@code + Stream stream3; // Only 2 stacks were allocated, we've run out of stacks + BufferPool pool3(stream3); + GpuMat d_src3 = pool3.getBuffer(1024, 1024, CV_8UC1); // Memory is allocated with DefaultAllocator +@endcode + +@warning When utilizing StackAllocator, deallocation order is important. + +Just like a stack, deallocation must be done in LIFO order. Below is an example of +erroneous usage that violates LIFO rule. If OpenCV is compiled in Debug mode, this +sample code will emit CV_Assert error. + +@code + int main() + { + setBufferPoolUsage(true); // Tell OpenCV that we are going to utilize BufferPool + Stream stream; // A default size (10 MB) stack is allocated to this stream + BufferPool pool(stream); + + GpuMat mat1 = pool.getBuffer(1024, 1024, CV_8UC1); // Allocate mat1 (1MB) + GpuMat mat2 = pool.getBuffer(1024, 1024, CV_8UC1); // Allocate mat2 (1MB) + + mat1.release(); // erroneous usage : mat2 must be deallocated before mat1 + } +@endcode + +Since C++ local variables are destroyed in the reverse order of construction, +the code sample below satisfies the LIFO rule. Local GpuMat's are deallocated +and the corresponding memory is automatically returned to the pool for later usage. + +@code + int main() + { + setBufferPoolUsage(true); // Tell OpenCV that we are going to utilize BufferPool + setBufferPoolConfig(getDevice(), 1024 * 1024 * 64, 2); // Allocate 64 MB, 2 stacks (default is 10 MB, 5 stacks) + + Stream stream1, stream2; // Each stream uses 1 stack + BufferPool pool1(stream1), pool2(stream2); + + for (int i = 0; i < 10; i++) + { + GpuMat d_src1 = pool1.getBuffer(4096, 4096, CV_8UC1); // 16MB + GpuMat d_dst1 = pool1.getBuffer(4096, 4096, CV_8UC3); // 48MB, pool1 is now full + + GpuMat d_src2 = pool2.getBuffer(1024, 1024, CV_8UC1); // 1MB + GpuMat d_dst2 = pool2.getBuffer(1024, 1024, CV_8UC3); // 3MB + + d_src1.setTo(Scalar(i), stream1); + d_src2.setTo(Scalar(i), stream2); + + cvtColor(d_src1, d_dst1, CV_GRAY2BGR, 0, stream1); + cvtColor(d_src2, d_dst2, CV_GRAY2BGR, 0, stream2); + // The order of destruction of the local variables is: + // d_dst2 => d_src2 => d_dst1 => d_src1 + // LIFO rule is satisfied, this code runs without error + } + } +@endcode + */ +class CV_EXPORTS BufferPool +{ +public: + + //! Gets the BufferPool for the given stream. + explicit BufferPool(Stream& stream); + + //! Allocates a new GpuMat of given size and type. + GpuMat getBuffer(int rows, int cols, int type); + + //! Allocates a new GpuMat of given size and type. + GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } + + //! Returns the allocator associated with the stream. + Ptr<GpuMat::Allocator> getAllocator() const { return allocator_; } + +private: + Ptr<GpuMat::Allocator> allocator_; +}; + +//! BufferPool management (must be called before Stream creation) +CV_EXPORTS void setBufferPoolUsage(bool on); +CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount); + +//=================================================================================== +// HostMem +//=================================================================================== + +/** @brief Class with reference counting wrapping special memory type allocation functions from CUDA. + +Its interface is also Mat-like but with additional memory type parameters. + +- **PAGE_LOCKED** sets a page locked memory type used commonly for fast and asynchronous + uploading/downloading data from/to GPU. +- **SHARED** specifies a zero copy memory allocation that enables mapping the host memory to GPU + address space, if supported. +- **WRITE_COMBINED** sets the write combined buffer that is not cached by CPU. Such buffers are + used to supply GPU with data when GPU only reads it. The advantage is a better CPU cache + utilization. + +@note Allocation size of such memory types is usually limited. For more details, see *CUDA 2.2 +Pinned Memory APIs* document or *CUDA C Programming Guide*. + */ +class CV_EXPORTS HostMem +{ +public: + enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 }; + + static MatAllocator* getAllocator(AllocType alloc_type = PAGE_LOCKED); + + explicit HostMem(AllocType alloc_type = PAGE_LOCKED); + + HostMem(const HostMem& m); + + HostMem(int rows, int cols, int type, AllocType alloc_type = PAGE_LOCKED); + HostMem(Size size, int type, AllocType alloc_type = PAGE_LOCKED); + + //! creates from host memory with coping data + explicit HostMem(InputArray arr, AllocType alloc_type = PAGE_LOCKED); + + ~HostMem(); + + HostMem& operator =(const HostMem& m); + + //! swaps with other smart pointer + void swap(HostMem& b); + + //! returns deep copy of the matrix, i.e. the data is copied + HostMem clone() const; + + //! allocates new matrix data unless the matrix already has specified size and type. + void create(int rows, int cols, int type); + void create(Size size, int type); + + //! creates alternative HostMem header for the same data, with different + //! number of channels and/or different number of rows + HostMem reshape(int cn, int rows = 0) const; + + //! decrements reference counter and released memory if needed. + void release(); + + //! returns matrix header with disabled reference counting for HostMem data. + Mat createMatHeader() const; + + /** @brief Maps CPU memory to GPU address space and creates the cuda::GpuMat header without reference counting + for it. + + This can be done only if memory was allocated with the SHARED flag and if it is supported by the + hardware. Laptops often share video and CPU memory, so address spaces can be mapped, which + eliminates an extra copy. + */ + GpuMat createGpuMatHeader() const; + + // Please see cv::Mat for descriptions + bool isContinuous() const; + size_t elemSize() const; + size_t elemSize1() const; + int type() const; + int depth() const; + int channels() const; + size_t step1() const; + Size size() const; + bool empty() const; + + // Please see cv::Mat for descriptions + int flags; + int rows, cols; + size_t step; + + uchar* data; + int* refcount; + + uchar* datastart; + const uchar* dataend; + + AllocType alloc_type; +}; + +/** @brief Page-locks the memory of matrix and maps it for the device(s). + +@param m Input matrix. + */ +CV_EXPORTS void registerPageLocked(Mat& m); + +/** @brief Unmaps the memory of matrix and makes it pageable again. + +@param m Input matrix. + */ +CV_EXPORTS void unregisterPageLocked(Mat& m); + +//=================================================================================== +// Stream +//=================================================================================== + +/** @brief This class encapsulates a queue of asynchronous calls. + +@note Currently, you may face problems if an operation is enqueued twice with different data. Some +functions use the constant GPU memory, and next call may update the memory before the previous one +has been finished. But calling different operations asynchronously is safe because each operation +has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are +also safe. + +@note The Stream class is not thread-safe. Please use different Stream objects for different CPU threads. + +@code +void thread1() +{ + cv::cuda::Stream stream1; + cv::cuda::func1(..., stream1); +} + +void thread2() +{ + cv::cuda::Stream stream2; + cv::cuda::func2(..., stream2); +} +@endcode + +@note By default all CUDA routines are launched in Stream::Null() object, if the stream is not specified by user. +In multi-threading environment the stream objects must be passed explicitly (see previous note). + */ +class CV_EXPORTS Stream +{ + typedef void (Stream::*bool_type)() const; + void this_type_does_not_support_comparisons() const {} + +public: + typedef void (*StreamCallback)(int status, void* userData); + + //! creates a new asynchronous stream + Stream(); + + //! creates a new asynchronous stream with custom allocator + Stream(const Ptr<GpuMat::Allocator>& allocator); + + /** @brief Returns true if the current stream queue is finished. Otherwise, it returns false. + */ + bool queryIfComplete() const; + + /** @brief Blocks the current CPU thread until all operations in the stream are complete. + */ + void waitForCompletion(); + + /** @brief Makes a compute stream wait on an event. + */ + void waitEvent(const Event& event); + + /** @brief Adds a callback to be called on the host after all currently enqueued items in the stream have + completed. + + @note Callbacks must not make any CUDA API calls. Callbacks must not perform any synchronization + that may depend on outstanding device work or other callbacks that are not mandated to run earlier. + Callbacks without a mandated order (in independent streams) execute in undefined order and may be + serialized. + */ + void enqueueHostCallback(StreamCallback callback, void* userData); + + //! return Stream object for default CUDA stream + static Stream& Null(); + + //! returns true if stream object is not default (!= 0) + operator bool_type() const; + + class Impl; + +private: + Ptr<Impl> impl_; + Stream(const Ptr<Impl>& impl); + + friend struct StreamAccessor; + friend class BufferPool; + friend class DefaultDeviceInitializer; +}; + +class CV_EXPORTS Event +{ +public: + enum CreateFlags + { + DEFAULT = 0x00, /**< Default event flag */ + BLOCKING_SYNC = 0x01, /**< Event uses blocking synchronization */ + DISABLE_TIMING = 0x02, /**< Event will not record timing data */ + INTERPROCESS = 0x04 /**< Event is suitable for interprocess use. DisableTiming must be set */ + }; + + explicit Event(CreateFlags flags = DEFAULT); + + //! records an event + void record(Stream& stream = Stream::Null()); + + //! queries an event's status + bool queryIfComplete() const; + + //! waits for an event to complete + void waitForCompletion(); + + //! computes the elapsed time between events + static float elapsedTime(const Event& start, const Event& end); + + class Impl; + +private: + Ptr<Impl> impl_; + Event(const Ptr<Impl>& impl); + + friend struct EventAccessor; +}; + +//! @} cudacore_struct + +//=================================================================================== +// Initialization & Info +//=================================================================================== + +//! @addtogroup cudacore_init +//! @{ + +/** @brief Returns the number of installed CUDA-enabled devices. + +Use this function before any other CUDA functions calls. If OpenCV is compiled without CUDA support, +this function returns 0. If the CUDA driver is not installed, or is incompatible, this function +returns -1. + */ +CV_EXPORTS int getCudaEnabledDeviceCount(); + +/** @brief Sets a device and initializes it for the current thread. + +@param device System index of a CUDA device starting with 0. + +If the call of this function is omitted, a default device is initialized at the fist CUDA usage. + */ +CV_EXPORTS void setDevice(int device); + +/** @brief Returns the current device index set by cuda::setDevice or initialized by default. + */ +CV_EXPORTS int getDevice(); + +/** @brief Explicitly destroys and cleans up all resources associated with the current device in the current +process. + +Any subsequent API call to this device will reinitialize the device. + */ +CV_EXPORTS void resetDevice(); + +/** @brief Enumeration providing CUDA computing features. + */ +enum FeatureSet +{ + FEATURE_SET_COMPUTE_10 = 10, + FEATURE_SET_COMPUTE_11 = 11, + FEATURE_SET_COMPUTE_12 = 12, + FEATURE_SET_COMPUTE_13 = 13, + FEATURE_SET_COMPUTE_20 = 20, + FEATURE_SET_COMPUTE_21 = 21, + FEATURE_SET_COMPUTE_30 = 30, + FEATURE_SET_COMPUTE_32 = 32, + FEATURE_SET_COMPUTE_35 = 35, + FEATURE_SET_COMPUTE_50 = 50, + + GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11, + SHARED_ATOMICS = FEATURE_SET_COMPUTE_12, + NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13, + WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30, + DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35 +}; + +//! checks whether current device supports the given feature +CV_EXPORTS bool deviceSupports(FeatureSet feature_set); + +/** @brief Class providing a set of static methods to check what NVIDIA\* card architecture the CUDA module was +built for. + +According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute +capability can always be compiled to binary code of greater or equal compute capability". + */ +class CV_EXPORTS TargetArchs +{ +public: + /** @brief The following method checks whether the module was built with the support of the given feature: + + @param feature_set Features to be checked. See :ocvcuda::FeatureSet. + */ + static bool builtWith(FeatureSet feature_set); + + /** @brief There is a set of methods to check whether the module contains intermediate (PTX) or binary CUDA + code for the given architecture(s): + + @param major Major compute capability version. + @param minor Minor compute capability version. + */ + static bool has(int major, int minor); + static bool hasPtx(int major, int minor); + static bool hasBin(int major, int minor); + + static bool hasEqualOrLessPtx(int major, int minor); + static bool hasEqualOrGreater(int major, int minor); + static bool hasEqualOrGreaterPtx(int major, int minor); + static bool hasEqualOrGreaterBin(int major, int minor); +}; + +/** @brief Class providing functionality for querying the specified GPU properties. + */ +class CV_EXPORTS DeviceInfo +{ +public: + //! creates DeviceInfo object for the current GPU + DeviceInfo(); + + /** @brief The constructors. + + @param device_id System index of the CUDA device starting with 0. + + Constructs the DeviceInfo object for the specified device. If device_id parameter is missed, it + constructs an object for the current device. + */ + DeviceInfo(int device_id); + + /** @brief Returns system index of the CUDA device starting with 0. + */ + int deviceID() const; + + //! ASCII string identifying device + const char* name() const; + + //! global memory available on device in bytes + size_t totalGlobalMem() const; + + //! shared memory available per block in bytes + size_t sharedMemPerBlock() const; + + //! 32-bit registers available per block + int regsPerBlock() const; + + //! warp size in threads + int warpSize() const; + + //! maximum pitch in bytes allowed by memory copies + size_t memPitch() const; + + //! maximum number of threads per block + int maxThreadsPerBlock() const; + + //! maximum size of each dimension of a block + Vec3i maxThreadsDim() const; + + //! maximum size of each dimension of a grid + Vec3i maxGridSize() const; + + //! clock frequency in kilohertz + int clockRate() const; + + //! constant memory available on device in bytes + size_t totalConstMem() const; + + //! major compute capability + int majorVersion() const; + + //! minor compute capability + int minorVersion() const; + + //! alignment requirement for textures + size_t textureAlignment() const; + + //! pitch alignment requirement for texture references bound to pitched memory + size_t texturePitchAlignment() const; + + //! number of multiprocessors on device + int multiProcessorCount() const; + + //! specified whether there is a run time limit on kernels + bool kernelExecTimeoutEnabled() const; + + //! device is integrated as opposed to discrete + bool integrated() const; + + //! device can map host memory with cudaHostAlloc/cudaHostGetDevicePointer + bool canMapHostMemory() const; + + enum ComputeMode + { + ComputeModeDefault, /**< default compute mode (Multiple threads can use cudaSetDevice with this device) */ + ComputeModeExclusive, /**< compute-exclusive-thread mode (Only one thread in one process will be able to use cudaSetDevice with this device) */ + ComputeModeProhibited, /**< compute-prohibited mode (No threads can use cudaSetDevice with this device) */ + ComputeModeExclusiveProcess /**< compute-exclusive-process mode (Many threads in one process will be able to use cudaSetDevice with this device) */ + }; + + //! compute mode + ComputeMode computeMode() const; + + //! maximum 1D texture size + int maxTexture1D() const; + + //! maximum 1D mipmapped texture size + int maxTexture1DMipmap() const; + + //! maximum size for 1D textures bound to linear memory + int maxTexture1DLinear() const; + + //! maximum 2D texture dimensions + Vec2i maxTexture2D() const; + + //! maximum 2D mipmapped texture dimensions + Vec2i maxTexture2DMipmap() const; + + //! maximum dimensions (width, height, pitch) for 2D textures bound to pitched memory + Vec3i maxTexture2DLinear() const; + + //! maximum 2D texture dimensions if texture gather operations have to be performed + Vec2i maxTexture2DGather() const; + + //! maximum 3D texture dimensions + Vec3i maxTexture3D() const; + + //! maximum Cubemap texture dimensions + int maxTextureCubemap() const; + + //! maximum 1D layered texture dimensions + Vec2i maxTexture1DLayered() const; + + //! maximum 2D layered texture dimensions + Vec3i maxTexture2DLayered() const; + + //! maximum Cubemap layered texture dimensions + Vec2i maxTextureCubemapLayered() const; + + //! maximum 1D surface size + int maxSurface1D() const; + + //! maximum 2D surface dimensions + Vec2i maxSurface2D() const; + + //! maximum 3D surface dimensions + Vec3i maxSurface3D() const; + + //! maximum 1D layered surface dimensions + Vec2i maxSurface1DLayered() const; + + //! maximum 2D layered surface dimensions + Vec3i maxSurface2DLayered() const; + + //! maximum Cubemap surface dimensions + int maxSurfaceCubemap() const; + + //! maximum Cubemap layered surface dimensions + Vec2i maxSurfaceCubemapLayered() const; + + //! alignment requirements for surfaces + size_t surfaceAlignment() const; + + //! device can possibly execute multiple kernels concurrently + bool concurrentKernels() const; + + //! device has ECC support enabled + bool ECCEnabled() const; + + //! PCI bus ID of the device + int pciBusID() const; + + //! PCI device ID of the device + int pciDeviceID() const; + + //! PCI domain ID of the device + int pciDomainID() const; + + //! true if device is a Tesla device using TCC driver, false otherwise + bool tccDriver() const; + + //! number of asynchronous engines + int asyncEngineCount() const; + + //! device shares a unified address space with the host + bool unifiedAddressing() const; + + //! peak memory clock frequency in kilohertz + int memoryClockRate() const; + + //! global memory bus width in bits + int memoryBusWidth() const; + + //! size of L2 cache in bytes + int l2CacheSize() const; + + //! maximum resident threads per multiprocessor + int maxThreadsPerMultiProcessor() const; + + //! gets free and total device memory + void queryMemory(size_t& totalMemory, size_t& freeMemory) const; + size_t freeMemory() const; + size_t totalMemory() const; + + /** @brief Provides information on CUDA feature support. + + @param feature_set Features to be checked. See cuda::FeatureSet. + + This function returns true if the device has the specified CUDA feature. Otherwise, it returns false + */ + bool supports(FeatureSet feature_set) const; + + /** @brief Checks the CUDA module and device compatibility. + + This function returns true if the CUDA module can be run on the specified device. Otherwise, it + returns false . + */ + bool isCompatible() const; + +private: + int device_id_; +}; + +CV_EXPORTS void printCudaDeviceInfo(int device); +CV_EXPORTS void printShortCudaDeviceInfo(int device); + +/** @brief Converts an array to half precision floating number. + +@param _src input array. +@param _dst output array. +@param stream Stream for the asynchronous version. +@sa convertFp16 +*/ +CV_EXPORTS void convertFp16(InputArray _src, OutputArray _dst, Stream& stream = Stream::Null()); + +//! @} cudacore_init + +}} // namespace cv { namespace cuda { + + +#include "opencv2/core/cuda.inl.hpp" + +#endif /* OPENCV_CORE_CUDA_HPP */ diff --git a/include/opencv2/core/cuda.inl.hpp b/include/opencv2/core/cuda.inl.hpp new file mode 100644 index 0000000..35ae2e4 --- /dev/null +++ b/include/opencv2/core/cuda.inl.hpp @@ -0,0 +1,631 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CUDAINL_HPP +#define OPENCV_CORE_CUDAINL_HPP + +#include "opencv2/core/cuda.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { + +//=================================================================================== +// GpuMat +//=================================================================================== + +inline +GpuMat::GpuMat(Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{} + +inline +GpuMat::GpuMat(int rows_, int cols_, int type_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (rows_ > 0 && cols_ > 0) + create(rows_, cols_, type_); +} + +inline +GpuMat::GpuMat(Size size_, int type_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (size_.height > 0 && size_.width > 0) + create(size_.height, size_.width, type_); +} + +inline +GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (rows_ > 0 && cols_ > 0) + { + create(rows_, cols_, type_); + setTo(s_); + } +} + +inline +GpuMat::GpuMat(Size size_, int type_, Scalar s_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (size_.height > 0 && size_.width > 0) + { + create(size_.height, size_.width, type_); + setTo(s_); + } +} + +inline +GpuMat::GpuMat(const GpuMat& m) + : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), allocator(m.allocator) +{ + if (refcount) + CV_XADD(refcount, 1); +} + +inline +GpuMat::GpuMat(InputArray arr, Allocator* allocator_) : + flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + upload(arr); +} + +inline +GpuMat::~GpuMat() +{ + release(); +} + +inline +GpuMat& GpuMat::operator =(const GpuMat& m) +{ + if (this != &m) + { + GpuMat temp(m); + swap(temp); + } + + return *this; +} + +inline +void GpuMat::create(Size size_, int type_) +{ + create(size_.height, size_.width, type_); +} + +inline +void GpuMat::swap(GpuMat& b) +{ + std::swap(flags, b.flags); + std::swap(rows, b.rows); + std::swap(cols, b.cols); + std::swap(step, b.step); + std::swap(data, b.data); + std::swap(datastart, b.datastart); + std::swap(dataend, b.dataend); + std::swap(refcount, b.refcount); + std::swap(allocator, b.allocator); +} + +inline +GpuMat GpuMat::clone() const +{ + GpuMat m; + copyTo(m); + return m; +} + +inline +void GpuMat::copyTo(OutputArray dst, InputArray mask) const +{ + copyTo(dst, mask, Stream::Null()); +} + +inline +GpuMat& GpuMat::setTo(Scalar s) +{ + return setTo(s, Stream::Null()); +} + +inline +GpuMat& GpuMat::setTo(Scalar s, InputArray mask) +{ + return setTo(s, mask, Stream::Null()); +} + +inline +void GpuMat::convertTo(OutputArray dst, int rtype) const +{ + convertTo(dst, rtype, Stream::Null()); +} + +inline +void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, double beta) const +{ + convertTo(dst, rtype, alpha, beta, Stream::Null()); +} + +inline +void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const +{ + convertTo(dst, rtype, alpha, 0.0, stream); +} + +inline +void GpuMat::assignTo(GpuMat& m, int _type) const +{ + if (_type < 0) + m = *this; + else + convertTo(m, _type); +} + +inline +uchar* GpuMat::ptr(int y) +{ + CV_DbgAssert( (unsigned)y < (unsigned)rows ); + return data + step * y; +} + +inline +const uchar* GpuMat::ptr(int y) const +{ + CV_DbgAssert( (unsigned)y < (unsigned)rows ); + return data + step * y; +} + +template<typename _Tp> inline +_Tp* GpuMat::ptr(int y) +{ + return (_Tp*)ptr(y); +} + +template<typename _Tp> inline +const _Tp* GpuMat::ptr(int y) const +{ + return (const _Tp*)ptr(y); +} + +template <class T> inline +GpuMat::operator PtrStepSz<T>() const +{ + return PtrStepSz<T>(rows, cols, (T*)data, step); +} + +template <class T> inline +GpuMat::operator PtrStep<T>() const +{ + return PtrStep<T>((T*)data, step); +} + +inline +GpuMat GpuMat::row(int y) const +{ + return GpuMat(*this, Range(y, y+1), Range::all()); +} + +inline +GpuMat GpuMat::col(int x) const +{ + return GpuMat(*this, Range::all(), Range(x, x+1)); +} + +inline +GpuMat GpuMat::rowRange(int startrow, int endrow) const +{ + return GpuMat(*this, Range(startrow, endrow), Range::all()); +} + +inline +GpuMat GpuMat::rowRange(Range r) const +{ + return GpuMat(*this, r, Range::all()); +} + +inline +GpuMat GpuMat::colRange(int startcol, int endcol) const +{ + return GpuMat(*this, Range::all(), Range(startcol, endcol)); +} + +inline +GpuMat GpuMat::colRange(Range r) const +{ + return GpuMat(*this, Range::all(), r); +} + +inline +GpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const +{ + return GpuMat(*this, rowRange_, colRange_); +} + +inline +GpuMat GpuMat::operator ()(Rect roi) const +{ + return GpuMat(*this, roi); +} + +inline +bool GpuMat::isContinuous() const +{ + return (flags & Mat::CONTINUOUS_FLAG) != 0; +} + +inline +size_t GpuMat::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t GpuMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int GpuMat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int GpuMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int GpuMat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t GpuMat::step1() const +{ + return step / elemSize1(); +} + +inline +Size GpuMat::size() const +{ + return Size(cols, rows); +} + +inline +bool GpuMat::empty() const +{ + return data == 0; +} + +static inline +GpuMat createContinuous(int rows, int cols, int type) +{ + GpuMat m; + createContinuous(rows, cols, type, m); + return m; +} + +static inline +void createContinuous(Size size, int type, OutputArray arr) +{ + createContinuous(size.height, size.width, type, arr); +} + +static inline +GpuMat createContinuous(Size size, int type) +{ + GpuMat m; + createContinuous(size, type, m); + return m; +} + +static inline +void ensureSizeIsEnough(Size size, int type, OutputArray arr) +{ + ensureSizeIsEnough(size.height, size.width, type, arr); +} + +static inline +void swap(GpuMat& a, GpuMat& b) +{ + a.swap(b); +} + +//=================================================================================== +// HostMem +//=================================================================================== + +inline +HostMem::HostMem(AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ +} + +inline +HostMem::HostMem(const HostMem& m) + : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), alloc_type(m.alloc_type) +{ + if( refcount ) + CV_XADD(refcount, 1); +} + +inline +HostMem::HostMem(int rows_, int cols_, int type_, AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ + if (rows_ > 0 && cols_ > 0) + create(rows_, cols_, type_); +} + +inline +HostMem::HostMem(Size size_, int type_, AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ + if (size_.height > 0 && size_.width > 0) + create(size_.height, size_.width, type_); +} + +inline +HostMem::HostMem(InputArray arr, AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ + arr.getMat().copyTo(*this); +} + +inline +HostMem::~HostMem() +{ + release(); +} + +inline +HostMem& HostMem::operator =(const HostMem& m) +{ + if (this != &m) + { + HostMem temp(m); + swap(temp); + } + + return *this; +} + +inline +void HostMem::swap(HostMem& b) +{ + std::swap(flags, b.flags); + std::swap(rows, b.rows); + std::swap(cols, b.cols); + std::swap(step, b.step); + std::swap(data, b.data); + std::swap(datastart, b.datastart); + std::swap(dataend, b.dataend); + std::swap(refcount, b.refcount); + std::swap(alloc_type, b.alloc_type); +} + +inline +HostMem HostMem::clone() const +{ + HostMem m(size(), type(), alloc_type); + createMatHeader().copyTo(m); + return m; +} + +inline +void HostMem::create(Size size_, int type_) +{ + create(size_.height, size_.width, type_); +} + +inline +Mat HostMem::createMatHeader() const +{ + return Mat(size(), type(), data, step); +} + +inline +bool HostMem::isContinuous() const +{ + return (flags & Mat::CONTINUOUS_FLAG) != 0; +} + +inline +size_t HostMem::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t HostMem::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int HostMem::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int HostMem::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int HostMem::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t HostMem::step1() const +{ + return step / elemSize1(); +} + +inline +Size HostMem::size() const +{ + return Size(cols, rows); +} + +inline +bool HostMem::empty() const +{ + return data == 0; +} + +static inline +void swap(HostMem& a, HostMem& b) +{ + a.swap(b); +} + +//=================================================================================== +// Stream +//=================================================================================== + +inline +Stream::Stream(const Ptr<Impl>& impl) + : impl_(impl) +{ +} + +//=================================================================================== +// Event +//=================================================================================== + +inline +Event::Event(const Ptr<Impl>& impl) + : impl_(impl) +{ +} + +//=================================================================================== +// Initialization & Info +//=================================================================================== + +inline +bool TargetArchs::has(int major, int minor) +{ + return hasPtx(major, minor) || hasBin(major, minor); +} + +inline +bool TargetArchs::hasEqualOrGreater(int major, int minor) +{ + return hasEqualOrGreaterPtx(major, minor) || hasEqualOrGreaterBin(major, minor); +} + +inline +DeviceInfo::DeviceInfo() +{ + device_id_ = getDevice(); +} + +inline +DeviceInfo::DeviceInfo(int device_id) +{ + CV_Assert( device_id >= 0 && device_id < getCudaEnabledDeviceCount() ); + device_id_ = device_id; +} + +inline +int DeviceInfo::deviceID() const +{ + return device_id_; +} + +inline +size_t DeviceInfo::freeMemory() const +{ + size_t _totalMemory = 0, _freeMemory = 0; + queryMemory(_totalMemory, _freeMemory); + return _freeMemory; +} + +inline +size_t DeviceInfo::totalMemory() const +{ + size_t _totalMemory = 0, _freeMemory = 0; + queryMemory(_totalMemory, _freeMemory); + return _totalMemory; +} + +inline +bool DeviceInfo::supports(FeatureSet feature_set) const +{ + int version = majorVersion() * 10 + minorVersion(); + return version >= feature_set; +} + + +}} // namespace cv { namespace cuda { + +//=================================================================================== +// Mat +//=================================================================================== + +namespace cv { + +inline +Mat::Mat(const cuda::GpuMat& m) + : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows) +{ + m.download(*this); +} + +} + +//! @endcond + +#endif // OPENCV_CORE_CUDAINL_HPP diff --git a/include/opencv2/core/cuda/block.hpp b/include/opencv2/core/cuda/block.hpp new file mode 100644 index 0000000..c277f0e --- /dev/null +++ b/include/opencv2/core/cuda/block.hpp @@ -0,0 +1,211 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_DEVICE_BLOCK_HPP +#define OPENCV_CUDA_DEVICE_BLOCK_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct Block + { + static __device__ __forceinline__ unsigned int id() + { + return blockIdx.x; + } + + static __device__ __forceinline__ unsigned int stride() + { + return blockDim.x * blockDim.y * blockDim.z; + } + + static __device__ __forceinline__ void sync() + { + __syncthreads(); + } + + static __device__ __forceinline__ int flattenedThreadId() + { + return threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; + } + + template<typename It, typename T> + static __device__ __forceinline__ void fill(It beg, It end, const T& value) + { + int STRIDE = stride(); + It t = beg + flattenedThreadId(); + + for(; t < end; t += STRIDE) + *t = value; + } + + template<typename OutIt, typename T> + static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value) + { + int STRIDE = stride(); + int tid = flattenedThreadId(); + value += tid; + + for(OutIt t = beg + tid; t < end; t += STRIDE, value += STRIDE) + *t = value; + } + + template<typename InIt, typename OutIt> + static __device__ __forceinline__ void copy(InIt beg, InIt end, OutIt out) + { + int STRIDE = stride(); + InIt t = beg + flattenedThreadId(); + OutIt o = out + (t - beg); + + for(; t < end; t += STRIDE, o += STRIDE) + *o = *t; + } + + template<typename InIt, typename OutIt, class UnOp> + static __device__ __forceinline__ void transform(InIt beg, InIt end, OutIt out, UnOp op) + { + int STRIDE = stride(); + InIt t = beg + flattenedThreadId(); + OutIt o = out + (t - beg); + + for(; t < end; t += STRIDE, o += STRIDE) + *o = op(*t); + } + + template<typename InIt1, typename InIt2, typename OutIt, class BinOp> + static __device__ __forceinline__ void transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op) + { + int STRIDE = stride(); + InIt1 t1 = beg1 + flattenedThreadId(); + InIt2 t2 = beg2 + flattenedThreadId(); + OutIt o = out + (t1 - beg1); + + for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, o += STRIDE) + *o = op(*t1, *t2); + } + + template<int CTA_SIZE, typename T, class BinOp> + static __device__ __forceinline__ void reduce(volatile T* buffer, BinOp op) + { + int tid = flattenedThreadId(); + T val = buffer[tid]; + + if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); } + if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); } + if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); } + if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); } + + if (tid < 32) + { + if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); } + if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); } + if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); } + if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); } + if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); } + if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); } + } + } + + template<int CTA_SIZE, typename T, class BinOp> + static __device__ __forceinline__ T reduce(volatile T* buffer, T init, BinOp op) + { + int tid = flattenedThreadId(); + T val = buffer[tid] = init; + __syncthreads(); + + if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); } + if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); } + if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); } + if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); } + + if (tid < 32) + { + if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); } + if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); } + if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); } + if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); } + if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); } + if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); } + } + __syncthreads(); + return buffer[0]; + } + + template <typename T, class BinOp> + static __device__ __forceinline__ void reduce_n(T* data, unsigned int n, BinOp op) + { + int ftid = flattenedThreadId(); + int sft = stride(); + + if (sft < n) + { + for (unsigned int i = sft + ftid; i < n; i += sft) + data[ftid] = op(data[ftid], data[i]); + + __syncthreads(); + + n = sft; + } + + while (n > 1) + { + unsigned int half = n/2; + + if (ftid < half) + data[ftid] = op(data[ftid], data[n - ftid - 1]); + + __syncthreads(); + + n = n - half; + } + } + }; +}}} + +//! @endcond + +#endif /* OPENCV_CUDA_DEVICE_BLOCK_HPP */ diff --git a/include/opencv2/core/cuda/border_interpolate.hpp b/include/opencv2/core/cuda/border_interpolate.hpp new file mode 100644 index 0000000..874f705 --- /dev/null +++ b/include/opencv2/core/cuda/border_interpolate.hpp @@ -0,0 +1,722 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_BORDER_INTERPOLATE_HPP +#define OPENCV_CUDA_BORDER_INTERPOLATE_HPP + +#include "saturate_cast.hpp" +#include "vec_traits.hpp" +#include "vec_math.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + ////////////////////////////////////////////////////////////// + // BrdConstant + + template <typename D> struct BrdRowConstant + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowConstant(int width_, const D& val_ = VecTraits<D>::all(0)) : width(width_), val(val_) {} + + template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const + { + return x >= 0 ? saturate_cast<D>(data[x]) : val; + } + + template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const + { + return x < width ? saturate_cast<D>(data[x]) : val; + } + + template <typename T> __device__ __forceinline__ D at(int x, const T* data) const + { + return (x >= 0 && x < width) ? saturate_cast<D>(data[x]) : val; + } + + int width; + D val; + }; + + template <typename D> struct BrdColConstant + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColConstant(int height_, const D& val_ = VecTraits<D>::all(0)) : height(height_), val(val_) {} + + template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return y >= 0 ? saturate_cast<D>(*(const T*)((const char*)data + y * step)) : val; + } + + template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return y < height ? saturate_cast<D>(*(const T*)((const char*)data + y * step)) : val; + } + + template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return (y >= 0 && y < height) ? saturate_cast<D>(*(const T*)((const char*)data + y * step)) : val; + } + + int height; + D val; + }; + + template <typename D> struct BrdConstant + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdConstant(int height_, int width_, const D& val_ = VecTraits<D>::all(0)) : height(height_), width(width_), val(val_) + { + } + + template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(((const T*)((const uchar*)data + y * step))[x]) : val; + } + + template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(src(y, x)) : val; + } + + int height; + int width; + D val; + }; + + ////////////////////////////////////////////////////////////// + // BrdReplicate + + template <typename D> struct BrdRowReplicate + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowReplicate(int width) : last_col(width - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdRowReplicate(int width, U) : last_col(width - 1) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::max(x, 0); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::min(x, last_col); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_low(x)]); + } + + template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_high(x)]); + } + + template <typename T> __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col(x)]); + } + + int last_col; + }; + + template <typename D> struct BrdColReplicate + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColReplicate(int height) : last_row(height - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdColReplicate(int height, U) : last_row(height - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::max(y, 0); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::min(y, last_row); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const T*)((const char*)data + idx_row_low(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const T*)((const char*)data + idx_row_high(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const T*)((const char*)data + idx_row(y) * step)); + } + + int last_row; + }; + + template <typename D> struct BrdReplicate + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdReplicate(int height, int width) : last_row(height - 1), last_col(width - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdReplicate(int height, int width, U) : last_row(height - 1), last_col(width - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::max(y, 0); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::min(y, last_row); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::max(x, 0); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::min(x, last_col); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast<D>(src(idx_row(y), idx_col(x))); + } + + int last_row; + int last_col; + }; + + ////////////////////////////////////////////////////////////// + // BrdReflect101 + + template <typename D> struct BrdRowReflect101 + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowReflect101(int width) : last_col(width - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdRowReflect101(int width, U) : last_col(width - 1) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::abs(x) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::abs(last_col - ::abs(last_col - x)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_low(x)]); + } + + template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_high(x)]); + } + + template <typename T> __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col(x)]); + } + + int last_col; + }; + + template <typename D> struct BrdColReflect101 + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColReflect101(int height) : last_row(height - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdColReflect101(int height, U) : last_row(height - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::abs(y) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::abs(last_row - ::abs(last_row - y)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row_low(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row_high(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row(y) * step)); + } + + int last_row; + }; + + template <typename D> struct BrdReflect101 + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdReflect101(int height, int width) : last_row(height - 1), last_col(width - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdReflect101(int height, int width, U) : last_row(height - 1), last_col(width - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::abs(y) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::abs(last_row - ::abs(last_row - y)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::abs(x) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::abs(last_col - ::abs(last_col - x)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast<D>(src(idx_row(y), idx_col(x))); + } + + int last_row; + int last_col; + }; + + ////////////////////////////////////////////////////////////// + // BrdReflect + + template <typename D> struct BrdRowReflect + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowReflect(int width) : last_col(width - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdRowReflect(int width, U) : last_col(width - 1) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (::abs(x) - (x < 0)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::abs(last_col - ::abs(last_col - x) + (x > last_col)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_high(::abs(x) - (x < 0)); + } + + template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_low(x)]); + } + + template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_high(x)]); + } + + template <typename T> __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col(x)]); + } + + int last_col; + }; + + template <typename D> struct BrdColReflect + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColReflect(int height) : last_row(height - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdColReflect(int height, U) : last_row(height - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (::abs(y) - (y < 0)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::abs(last_row - ::abs(last_row - y) + (y > last_row)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_high(::abs(y) - (y < 0)); + } + + template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row_low(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row_high(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row(y) * step)); + } + + int last_row; + }; + + template <typename D> struct BrdReflect + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdReflect(int height, int width) : last_row(height - 1), last_col(width - 1) {} + template <typename U> __host__ __device__ __forceinline__ BrdReflect(int height, int width, U) : last_row(height - 1), last_col(width - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (::abs(y) - (y < 0)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return /*::abs*/(last_row - ::abs(last_row - y) + (y > last_row)) /*% (last_row + 1)*/; + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (::abs(x) - (x < 0)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return (last_col - ::abs(last_col - x) + (x > last_col)); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast<D>(src(idx_row(y), idx_col(x))); + } + + int last_row; + int last_col; + }; + + ////////////////////////////////////////////////////////////// + // BrdWrap + + template <typename D> struct BrdRowWrap + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowWrap(int width_) : width(width_) {} + template <typename U> __host__ __device__ __forceinline__ BrdRowWrap(int width_, U) : width(width_) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (x >= 0) * x + (x < 0) * (x - ((x - width + 1) / width) * width); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return (x < width) * x + (x >= width) * (x % width); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_high(idx_col_low(x)); + } + + template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_low(x)]); + } + + template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col_high(x)]); + } + + template <typename T> __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast<D>(data[idx_col(x)]); + } + + int width; + }; + + template <typename D> struct BrdColWrap + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColWrap(int height_) : height(height_) {} + template <typename U> __host__ __device__ __forceinline__ BrdColWrap(int height_, U) : height(height_) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (y >= 0) * y + (y < 0) * (y - ((y - height + 1) / height) * height); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return (y < height) * y + (y >= height) * (y % height); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_high(idx_row_low(y)); + } + + template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row_low(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row_high(y) * step)); + } + + template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast<D>(*(const D*)((const char*)data + idx_row(y) * step)); + } + + int height; + }; + + template <typename D> struct BrdWrap + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdWrap(int height_, int width_) : + height(height_), width(width_) + { + } + template <typename U> + __host__ __device__ __forceinline__ BrdWrap(int height_, int width_, U) : + height(height_), width(width_) + { + } + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (y >= 0) ? y : (y - ((y - height + 1) / height) * height); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return (y < height) ? y : (y % height); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_high(idx_row_low(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (x >= 0) ? x : (x - ((x - width + 1) / width) * width); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return (x < width) ? x : (x % width); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_high(idx_col_low(x)); + } + + template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast<D>(src(idx_row(y), idx_col(x))); + } + + int height; + int width; + }; + + ////////////////////////////////////////////////////////////// + // BorderReader + + template <typename Ptr2D, typename B> struct BorderReader + { + typedef typename B::result_type elem_type; + typedef typename Ptr2D::index_type index_type; + + __host__ __device__ __forceinline__ BorderReader(const Ptr2D& ptr_, const B& b_) : ptr(ptr_), b(b_) {} + + __device__ __forceinline__ elem_type operator ()(index_type y, index_type x) const + { + return b.at(y, x, ptr); + } + + Ptr2D ptr; + B b; + }; + + // under win32 there is some bug with templated types that passed as kernel parameters + // with this specialization all works fine + template <typename Ptr2D, typename D> struct BorderReader< Ptr2D, BrdConstant<D> > + { + typedef typename BrdConstant<D>::result_type elem_type; + typedef typename Ptr2D::index_type index_type; + + __host__ __device__ __forceinline__ BorderReader(const Ptr2D& src_, const BrdConstant<D>& b) : + src(src_), height(b.height), width(b.width), val(b.val) + { + } + + __device__ __forceinline__ D operator ()(index_type y, index_type x) const + { + return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(src(y, x)) : val; + } + + Ptr2D src; + int height; + int width; + D val; + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_BORDER_INTERPOLATE_HPP diff --git a/include/opencv2/core/cuda/color.hpp b/include/opencv2/core/cuda/color.hpp new file mode 100644 index 0000000..dcce280 --- /dev/null +++ b/include/opencv2/core/cuda/color.hpp @@ -0,0 +1,309 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_COLOR_HPP +#define OPENCV_CUDA_COLOR_HPP + +#include "detail/color_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + // All OPENCV_CUDA_IMPLEMENT_*_TRAITS(ColorSpace1_to_ColorSpace2, ...) macros implements + // template <typename T> class ColorSpace1_to_ColorSpace2_traits + // { + // typedef ... functor_type; + // static __host__ __device__ functor_type create_functor(); + // }; + + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_rgba, 4, 4, 2) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgr_to_bgr555, 3, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgr_to_bgr565, 3, 0, 6) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgb_to_bgr555, 3, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgb_to_bgr565, 3, 2, 6) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgra_to_bgr555, 4, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgra_to_bgr565, 4, 0, 6) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgba_to_bgr555, 4, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgba_to_bgr565, 4, 2, 6) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_rgb, 3, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_rgb, 3, 2, 6) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_bgr, 3, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_bgr, 3, 0, 6) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_rgba, 4, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_rgba, 4, 2, 6) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_bgra, 4, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_bgra, 4, 0, 6) + + #undef OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(gray_to_bgr, 3) + OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(gray_to_bgra, 4) + + #undef OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(gray_to_bgr555, 5) + OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(gray_to_bgr565, 6) + + #undef OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(bgr555_to_gray, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(bgr565_to_gray, 6) + + #undef OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(rgb_to_gray, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(bgr_to_gray, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(rgba_to_gray, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(bgra_to_gray, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgb_to_yuv, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgba_to_yuv, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgb_to_yuv4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgba_to_yuv4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgr_to_yuv, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgra_to_yuv, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgr_to_yuv4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgra_to_yuv4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS + + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgb_to_YCrCb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgba_to_YCrCb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgb_to_YCrCb4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgba_to_YCrCb4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgr_to_YCrCb, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgra_to_YCrCb, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgr_to_YCrCb4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgra_to_YCrCb4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS + + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgb_to_xyz, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgba_to_xyz, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgb_to_xyz4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgba_to_xyz4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgr_to_xyz, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgra_to_xyz, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgr_to_xyz4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgra_to_xyz4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS + + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgb_to_hsv, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgba_to_hsv, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgb_to_hsv4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgba_to_hsv4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgr_to_hsv, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgra_to_hsv, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgr_to_hsv4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgra_to_hsv4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS + + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgb_to_hls, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgba_to_hls, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgb_to_hls4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgba_to_hls4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgr_to_hls, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgra_to_hls, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgr_to_hls4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgra_to_hls4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS + + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgb_to_lab, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgba_to_lab, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgb_to_lab4, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgba_to_lab4, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgr_to_lab, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgra_to_lab, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgr_to_lab4, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgra_to_lab4, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgb_to_lab, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgba_to_lab, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgb_to_lab4, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgba_to_lab4, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgr_to_lab, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgra_to_lab, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgr_to_lab4, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgra_to_lab4, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS + + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_rgb, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_rgb, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_rgba, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_rgba, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_bgr, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_bgr, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_bgra, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_bgra, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lrgb, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lrgb, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lrgba, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lrgba, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lbgr, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lbgr, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lbgra, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lbgra, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgb_to_luv, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgba_to_luv, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgb_to_luv4, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgba_to_luv4, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgr_to_luv, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgra_to_luv, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgr_to_luv4, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgra_to_luv4, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgb_to_luv, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgba_to_luv, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgb_to_luv4, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgba_to_luv4, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgr_to_luv, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgra_to_luv, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgr_to_luv4, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgra_to_luv4, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS + + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_rgb, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_rgb, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_rgba, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_rgba, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_bgr, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_bgr, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_bgra, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_bgra, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lrgb, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lrgb, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lrgba, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lrgba, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lbgr, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lbgr, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lbgra, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lbgra, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_COLOR_HPP diff --git a/include/opencv2/core/cuda/common.hpp b/include/opencv2/core/cuda/common.hpp new file mode 100644 index 0000000..14b1f3f --- /dev/null +++ b/include/opencv2/core/cuda/common.hpp @@ -0,0 +1,109 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_COMMON_HPP +#define OPENCV_CUDA_COMMON_HPP + +#include <cuda_runtime.h> +#include "opencv2/core/cuda_types.hpp" +#include "opencv2/core/cvdef.h" +#include "opencv2/core/base.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +#ifndef CV_PI_F + #ifndef CV_PI + #define CV_PI_F 3.14159265f + #else + #define CV_PI_F ((float)CV_PI) + #endif +#endif + +namespace cv { namespace cuda { + static inline void checkCudaError(cudaError_t err, const char* file, const int line, const char* func) + { + if (cudaSuccess != err) + cv::error(cv::Error::GpuApiCallError, cudaGetErrorString(err), func, file, line); + } +}} + +#ifndef cudaSafeCall + #define cudaSafeCall(expr) cv::cuda::checkCudaError(expr, __FILE__, __LINE__, CV_Func) +#endif + +namespace cv { namespace cuda +{ + template <typename T> static inline bool isAligned(const T* ptr, size_t size) + { + return reinterpret_cast<size_t>(ptr) % size == 0; + } + + static inline bool isAligned(size_t step, size_t size) + { + return step % size == 0; + } +}} + +namespace cv { namespace cuda +{ + namespace device + { + __host__ __device__ __forceinline__ int divUp(int total, int grain) + { + return (total + grain - 1) / grain; + } + + template<class T> inline void bindTexture(const textureReference* tex, const PtrStepSz<T>& img) + { + cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>(); + cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) ); + } + } +}} + +//! @endcond + +#endif // OPENCV_CUDA_COMMON_HPP diff --git a/include/opencv2/core/cuda/datamov_utils.hpp b/include/opencv2/core/cuda/datamov_utils.hpp new file mode 100644 index 0000000..6820d0f --- /dev/null +++ b/include/opencv2/core/cuda/datamov_utils.hpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_DATAMOV_UTILS_HPP +#define OPENCV_CUDA_DATAMOV_UTILS_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 200 + + // for Fermi memory space is detected automatically + template <typename T> struct ForceGlob + { + __device__ __forceinline__ static void Load(const T* ptr, int offset, T& val) { val = ptr[offset]; } + }; + + #else // __CUDA_ARCH__ >= 200 + + #if defined(_WIN64) || defined(__LP64__) + // 64-bit register modifier for inlined asm + #define OPENCV_CUDA_ASM_PTR "l" + #else + // 32-bit register modifier for inlined asm + #define OPENCV_CUDA_ASM_PTR "r" + #endif + + template<class T> struct ForceGlob; + + #define OPENCV_CUDA_DEFINE_FORCE_GLOB(base_type, ptx_type, reg_mod) \ + template <> struct ForceGlob<base_type> \ + { \ + __device__ __forceinline__ static void Load(const base_type* ptr, int offset, base_type& val) \ + { \ + asm("ld.global."#ptx_type" %0, [%1];" : "="#reg_mod(val) : OPENCV_CUDA_ASM_PTR(ptr + offset)); \ + } \ + }; + + #define OPENCV_CUDA_DEFINE_FORCE_GLOB_B(base_type, ptx_type) \ + template <> struct ForceGlob<base_type> \ + { \ + __device__ __forceinline__ static void Load(const base_type* ptr, int offset, base_type& val) \ + { \ + asm("ld.global."#ptx_type" %0, [%1];" : "=r"(*reinterpret_cast<uint*>(&val)) : OPENCV_CUDA_ASM_PTR(ptr + offset)); \ + } \ + }; + + OPENCV_CUDA_DEFINE_FORCE_GLOB_B(uchar, u8) + OPENCV_CUDA_DEFINE_FORCE_GLOB_B(schar, s8) + OPENCV_CUDA_DEFINE_FORCE_GLOB_B(char, b8) + OPENCV_CUDA_DEFINE_FORCE_GLOB (ushort, u16, h) + OPENCV_CUDA_DEFINE_FORCE_GLOB (short, s16, h) + OPENCV_CUDA_DEFINE_FORCE_GLOB (uint, u32, r) + OPENCV_CUDA_DEFINE_FORCE_GLOB (int, s32, r) + OPENCV_CUDA_DEFINE_FORCE_GLOB (float, f32, f) + OPENCV_CUDA_DEFINE_FORCE_GLOB (double, f64, d) + + #undef OPENCV_CUDA_DEFINE_FORCE_GLOB + #undef OPENCV_CUDA_DEFINE_FORCE_GLOB_B + #undef OPENCV_CUDA_ASM_PTR + + #endif // __CUDA_ARCH__ >= 200 +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_DATAMOV_UTILS_HPP diff --git a/include/opencv2/core/cuda/detail/color_detail.hpp b/include/opencv2/core/cuda/detail/color_detail.hpp new file mode 100644 index 0000000..bfb4055 --- /dev/null +++ b/include/opencv2/core/cuda/detail/color_detail.hpp @@ -0,0 +1,1980 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_COLOR_DETAIL_HPP +#define OPENCV_CUDA_COLOR_DETAIL_HPP + +#include "../common.hpp" +#include "../vec_traits.hpp" +#include "../saturate_cast.hpp" +#include "../limits.hpp" +#include "../functional.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + #ifndef CV_DESCALE + #define CV_DESCALE(x, n) (((x) + (1 << ((n)-1))) >> (n)) + #endif + + namespace color_detail + { + template<typename T> struct ColorChannel + { + typedef float worktype_f; + static __device__ __forceinline__ T max() { return numeric_limits<T>::max(); } + static __device__ __forceinline__ T half() { return (T)(max()/2 + 1); } + }; + + template<> struct ColorChannel<float> + { + typedef float worktype_f; + static __device__ __forceinline__ float max() { return 1.f; } + static __device__ __forceinline__ float half() { return 0.5f; } + }; + + template <typename T> static __device__ __forceinline__ void setAlpha(typename TypeVec<T, 3>::vec_type& vec, T val) + { + } + + template <typename T> static __device__ __forceinline__ void setAlpha(typename TypeVec<T, 4>::vec_type& vec, T val) + { + vec.w = val; + } + + template <typename T> static __device__ __forceinline__ T getAlpha(const typename TypeVec<T, 3>::vec_type& vec) + { + return ColorChannel<T>::max(); + } + + template <typename T> static __device__ __forceinline__ T getAlpha(const typename TypeVec<T, 4>::vec_type& vec) + { + return vec.w; + } + + enum + { + yuv_shift = 14, + xyz_shift = 12, + R2Y = 4899, + G2Y = 9617, + B2Y = 1868, + BLOCK_SIZE = 256 + }; + } + +////////////////// Various 3/4-channel to 3/4-channel RGB transformations ///////////////// + + namespace color_detail + { + template <typename T, int scn, int dcn, int bidx> struct RGB2RGB + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + dst.x = (&src.x)[bidx]; + dst.y = src.y; + dst.z = (&src.x)[bidx^2]; + setAlpha(dst, getAlpha<T>(src)); + + return dst; + } + + __host__ __device__ __forceinline__ RGB2RGB() {} + __host__ __device__ __forceinline__ RGB2RGB(const RGB2RGB&) {} + }; + + template <> struct RGB2RGB<uchar, 4, 4, 2> : unary_function<uint, uint> + { + __device__ uint operator()(uint src) const + { + uint dst = 0; + + dst |= (0xffu & (src >> 16)); + dst |= (0xffu & (src >> 8)) << 8; + dst |= (0xffu & (src)) << 16; + dst |= (0xffu & (src >> 24)) << 24; + + return dst; + } + + __host__ __device__ __forceinline__ RGB2RGB() {} + __host__ __device__ __forceinline__ RGB2RGB(const RGB2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2RGB<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +/////////// Transforming 16-bit (565 or 555) RGB to/from 24/32-bit (888[8]) RGB ////////// + + namespace color_detail + { + template <int green_bits, int bidx> struct RGB2RGB5x5Converter; + template<int bidx> struct RGB2RGB5x5Converter<6, bidx> + { + static __device__ __forceinline__ ushort cvt(const uchar3& src) + { + return (ushort)(((&src.x)[bidx] >> 3) | ((src.y & ~3) << 3) | (((&src.x)[bidx^2] & ~7) << 8)); + } + + static __device__ __forceinline__ ushort cvt(uint src) + { + uint b = 0xffu & (src >> (bidx * 8)); + uint g = 0xffu & (src >> 8); + uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + return (ushort)((b >> 3) | ((g & ~3) << 3) | ((r & ~7) << 8)); + } + }; + + template<int bidx> struct RGB2RGB5x5Converter<5, bidx> + { + static __device__ __forceinline__ ushort cvt(const uchar3& src) + { + return (ushort)(((&src.x)[bidx] >> 3) | ((src.y & ~7) << 2) | (((&src.x)[bidx^2] & ~7) << 7)); + } + + static __device__ __forceinline__ ushort cvt(uint src) + { + uint b = 0xffu & (src >> (bidx * 8)); + uint g = 0xffu & (src >> 8); + uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + uint a = 0xffu & (src >> 24); + return (ushort)((b >> 3) | ((g & ~7) << 2) | ((r & ~7) << 7) | (a * 0x8000)); + } + }; + + template<int scn, int bidx, int green_bits> struct RGB2RGB5x5; + + template<int bidx, int green_bits> struct RGB2RGB5x5<3, bidx,green_bits> : unary_function<uchar3, ushort> + { + __device__ __forceinline__ ushort operator()(const uchar3& src) const + { + return RGB2RGB5x5Converter<green_bits, bidx>::cvt(src); + } + + __host__ __device__ __forceinline__ RGB2RGB5x5() {} + __host__ __device__ __forceinline__ RGB2RGB5x5(const RGB2RGB5x5&) {} + }; + + template<int bidx, int green_bits> struct RGB2RGB5x5<4, bidx,green_bits> : unary_function<uint, ushort> + { + __device__ __forceinline__ ushort operator()(uint src) const + { + return RGB2RGB5x5Converter<green_bits, bidx>::cvt(src); + } + + __host__ __device__ __forceinline__ RGB2RGB5x5() {} + __host__ __device__ __forceinline__ RGB2RGB5x5(const RGB2RGB5x5&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(name, scn, bidx, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2RGB5x5<scn, bidx, green_bits> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template <int green_bits, int bidx> struct RGB5x52RGBConverter; + + template <int bidx> struct RGB5x52RGBConverter<5, bidx> + { + static __device__ __forceinline__ void cvt(uint src, uchar3& dst) + { + (&dst.x)[bidx] = src << 3; + dst.y = (src >> 2) & ~7; + (&dst.x)[bidx ^ 2] = (src >> 7) & ~7; + } + + static __device__ __forceinline__ void cvt(uint src, uint& dst) + { + dst = 0; + + dst |= (0xffu & (src << 3)) << (bidx * 8); + dst |= (0xffu & ((src >> 2) & ~7)) << 8; + dst |= (0xffu & ((src >> 7) & ~7)) << ((bidx ^ 2) * 8); + dst |= ((src & 0x8000) * 0xffu) << 24; + } + }; + + template <int bidx> struct RGB5x52RGBConverter<6, bidx> + { + static __device__ __forceinline__ void cvt(uint src, uchar3& dst) + { + (&dst.x)[bidx] = src << 3; + dst.y = (src >> 3) & ~3; + (&dst.x)[bidx ^ 2] = (src >> 8) & ~7; + } + + static __device__ __forceinline__ void cvt(uint src, uint& dst) + { + dst = 0xffu << 24; + + dst |= (0xffu & (src << 3)) << (bidx * 8); + dst |= (0xffu &((src >> 3) & ~3)) << 8; + dst |= (0xffu & ((src >> 8) & ~7)) << ((bidx ^ 2) * 8); + } + }; + + template <int dcn, int bidx, int green_bits> struct RGB5x52RGB; + + template <int bidx, int green_bits> struct RGB5x52RGB<3, bidx, green_bits> : unary_function<ushort, uchar3> + { + __device__ __forceinline__ uchar3 operator()(ushort src) const + { + uchar3 dst; + RGB5x52RGBConverter<green_bits, bidx>::cvt(src, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB5x52RGB() {} + __host__ __device__ __forceinline__ RGB5x52RGB(const RGB5x52RGB&) {} + + }; + + template <int bidx, int green_bits> struct RGB5x52RGB<4, bidx, green_bits> : unary_function<ushort, uint> + { + __device__ __forceinline__ uint operator()(ushort src) const + { + uint dst; + RGB5x52RGBConverter<green_bits, bidx>::cvt(src, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB5x52RGB() {} + __host__ __device__ __forceinline__ RGB5x52RGB(const RGB5x52RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(name, dcn, bidx, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB5x52RGB<dcn, bidx, green_bits> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////// Grayscale to Color //////////////////////////////// + + namespace color_detail + { + template <typename T, int dcn> struct Gray2RGB : unary_function<T, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(T src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + dst.z = dst.y = dst.x = src; + setAlpha(dst, ColorChannel<T>::max()); + + return dst; + } + __host__ __device__ __forceinline__ Gray2RGB() {} + __host__ __device__ __forceinline__ Gray2RGB(const Gray2RGB&) {} + }; + + template <> struct Gray2RGB<uchar, 4> : unary_function<uchar, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + uint dst = 0xffu << 24; + + dst |= src; + dst |= src << 8; + dst |= src << 16; + + return dst; + } + __host__ __device__ __forceinline__ Gray2RGB() {} + __host__ __device__ __forceinline__ Gray2RGB(const Gray2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(name, dcn) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Gray2RGB<T, dcn> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template <int green_bits> struct Gray2RGB5x5Converter; + template<> struct Gray2RGB5x5Converter<6> + { + static __device__ __forceinline__ ushort cvt(uint t) + { + return (ushort)((t >> 3) | ((t & ~3) << 3) | ((t & ~7) << 8)); + } + }; + + template<> struct Gray2RGB5x5Converter<5> + { + static __device__ __forceinline__ ushort cvt(uint t) + { + t >>= 3; + return (ushort)(t | (t << 5) | (t << 10)); + } + }; + + template<int green_bits> struct Gray2RGB5x5 : unary_function<uchar, ushort> + { + __device__ __forceinline__ ushort operator()(uint src) const + { + return Gray2RGB5x5Converter<green_bits>::cvt(src); + } + + __host__ __device__ __forceinline__ Gray2RGB5x5() {} + __host__ __device__ __forceinline__ Gray2RGB5x5(const Gray2RGB5x5&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(name, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Gray2RGB5x5<green_bits> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////// Color to Grayscale //////////////////////////////// + + namespace color_detail + { + template <int green_bits> struct RGB5x52GrayConverter; + template <> struct RGB5x52GrayConverter<6> + { + static __device__ __forceinline__ uchar cvt(uint t) + { + return (uchar)CV_DESCALE(((t << 3) & 0xf8) * B2Y + ((t >> 3) & 0xfc) * G2Y + ((t >> 8) & 0xf8) * R2Y, yuv_shift); + } + }; + + template <> struct RGB5x52GrayConverter<5> + { + static __device__ __forceinline__ uchar cvt(uint t) + { + return (uchar)CV_DESCALE(((t << 3) & 0xf8) * B2Y + ((t >> 2) & 0xf8) * G2Y + ((t >> 7) & 0xf8) * R2Y, yuv_shift); + } + }; + + template<int green_bits> struct RGB5x52Gray : unary_function<ushort, uchar> + { + __device__ __forceinline__ uchar operator()(uint src) const + { + return RGB5x52GrayConverter<green_bits>::cvt(src); + } + __host__ __device__ __forceinline__ RGB5x52Gray() {} + __host__ __device__ __forceinline__ RGB5x52Gray(const RGB5x52Gray&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(name, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB5x52Gray<green_bits> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template <int bidx, typename T> static __device__ __forceinline__ T RGB2GrayConvert(const T* src) + { + return (T)CV_DESCALE((unsigned)(src[bidx] * B2Y + src[1] * G2Y + src[bidx^2] * R2Y), yuv_shift); + } + + template <int bidx> static __device__ __forceinline__ uchar RGB2GrayConvert(uint src) + { + uint b = 0xffu & (src >> (bidx * 8)); + uint g = 0xffu & (src >> 8); + uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + return CV_DESCALE((uint)(b * B2Y + g * G2Y + r * R2Y), yuv_shift); + } + + template <int bidx> static __device__ __forceinline__ float RGB2GrayConvert(const float* src) + { + return src[bidx] * 0.114f + src[1] * 0.587f + src[bidx^2] * 0.299f; + } + + template <typename T, int scn, int bidx> struct RGB2Gray : unary_function<typename TypeVec<T, scn>::vec_type, T> + { + __device__ __forceinline__ T operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + return RGB2GrayConvert<bidx>(&src.x); + } + __host__ __device__ __forceinline__ RGB2Gray() {} + __host__ __device__ __forceinline__ RGB2Gray(const RGB2Gray&) {} + }; + + template <int bidx> struct RGB2Gray<uchar, 4, bidx> : unary_function<uint, uchar> + { + __device__ __forceinline__ uchar operator()(uint src) const + { + return RGB2GrayConvert<bidx>(src); + } + __host__ __device__ __forceinline__ RGB2Gray() {} + __host__ __device__ __forceinline__ RGB2Gray(const RGB2Gray&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(name, scn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2Gray<T, scn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> YUV ////////////////////////////////////// + + namespace color_detail + { + __constant__ float c_RGB2YUVCoeffs_f[5] = { 0.114f, 0.587f, 0.299f, 0.492f, 0.877f }; + __constant__ int c_RGB2YUVCoeffs_i[5] = { B2Y, G2Y, R2Y, 8061, 14369 }; + + template <int bidx, typename T, typename D> static __device__ void RGB2YUVConvert(const T* src, D& dst) + { + const int delta = ColorChannel<T>::half() * (1 << yuv_shift); + + const int Y = CV_DESCALE(src[0] * c_RGB2YUVCoeffs_i[bidx^2] + src[1] * c_RGB2YUVCoeffs_i[1] + src[2] * c_RGB2YUVCoeffs_i[bidx], yuv_shift); + const int Cr = CV_DESCALE((src[bidx^2] - Y) * c_RGB2YUVCoeffs_i[3] + delta, yuv_shift); + const int Cb = CV_DESCALE((src[bidx] - Y) * c_RGB2YUVCoeffs_i[4] + delta, yuv_shift); + + dst.x = saturate_cast<T>(Y); + dst.y = saturate_cast<T>(Cr); + dst.z = saturate_cast<T>(Cb); + } + + template <int bidx, typename D> static __device__ __forceinline__ void RGB2YUVConvert(const float* src, D& dst) + { + dst.x = src[0] * c_RGB2YUVCoeffs_f[bidx^2] + src[1] * c_RGB2YUVCoeffs_f[1] + src[2] * c_RGB2YUVCoeffs_f[bidx]; + dst.y = (src[bidx^2] - dst.x) * c_RGB2YUVCoeffs_f[3] + ColorChannel<float>::half(); + dst.z = (src[bidx] - dst.x) * c_RGB2YUVCoeffs_f[4] + ColorChannel<float>::half(); + } + + template <typename T, int scn, int dcn, int bidx> struct RGB2YUV + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator ()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + RGB2YUVConvert<bidx>(&src.x, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB2YUV() {} + __host__ __device__ __forceinline__ RGB2YUV(const RGB2YUV&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2YUV<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_YUV2RGBCoeffs_f[5] = { 2.032f, -0.395f, -0.581f, 1.140f }; + __constant__ int c_YUV2RGBCoeffs_i[5] = { 33292, -6472, -9519, 18678 }; + + template <int bidx, typename T, typename D> static __device__ void YUV2RGBConvert(const T& src, D* dst) + { + const int b = src.x + CV_DESCALE((src.z - ColorChannel<D>::half()) * c_YUV2RGBCoeffs_i[3], yuv_shift); + + const int g = src.x + CV_DESCALE((src.z - ColorChannel<D>::half()) * c_YUV2RGBCoeffs_i[2] + + (src.y - ColorChannel<D>::half()) * c_YUV2RGBCoeffs_i[1], yuv_shift); + + const int r = src.x + CV_DESCALE((src.y - ColorChannel<D>::half()) * c_YUV2RGBCoeffs_i[0], yuv_shift); + + dst[bidx] = saturate_cast<D>(b); + dst[1] = saturate_cast<D>(g); + dst[bidx^2] = saturate_cast<D>(r); + } + + template <int bidx> static __device__ uint YUV2RGBConvert(uint src) + { + const int x = 0xff & (src); + const int y = 0xff & (src >> 8); + const int z = 0xff & (src >> 16); + + const int b = x + CV_DESCALE((z - ColorChannel<uchar>::half()) * c_YUV2RGBCoeffs_i[3], yuv_shift); + + const int g = x + CV_DESCALE((z - ColorChannel<uchar>::half()) * c_YUV2RGBCoeffs_i[2] + + (y - ColorChannel<uchar>::half()) * c_YUV2RGBCoeffs_i[1], yuv_shift); + + const int r = x + CV_DESCALE((y - ColorChannel<uchar>::half()) * c_YUV2RGBCoeffs_i[0], yuv_shift); + + uint dst = 0xffu << 24; + + dst |= saturate_cast<uchar>(b) << (bidx * 8); + dst |= saturate_cast<uchar>(g) << 8; + dst |= saturate_cast<uchar>(r) << ((bidx ^ 2) * 8); + + return dst; + } + + template <int bidx, typename T> static __device__ __forceinline__ void YUV2RGBConvert(const T& src, float* dst) + { + dst[bidx] = src.x + (src.z - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[3]; + + dst[1] = src.x + (src.z - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[2] + + (src.y - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[1]; + + dst[bidx^2] = src.x + (src.y - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[0]; + } + + template <typename T, int scn, int dcn, int bidx> struct YUV2RGB + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator ()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + YUV2RGBConvert<bidx>(src, &dst.x); + setAlpha(dst, ColorChannel<T>::max()); + + return dst; + } + __host__ __device__ __forceinline__ YUV2RGB() {} + __host__ __device__ __forceinline__ YUV2RGB(const YUV2RGB&) {} + }; + + template <int bidx> struct YUV2RGB<uchar, 4, 4, bidx> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator ()(uint src) const + { + return YUV2RGBConvert<bidx>(src); + } + __host__ __device__ __forceinline__ YUV2RGB() {} + __host__ __device__ __forceinline__ YUV2RGB(const YUV2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::YUV2RGB<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> YCrCb ////////////////////////////////////// + + namespace color_detail + { + __constant__ float c_RGB2YCrCbCoeffs_f[5] = {0.299f, 0.587f, 0.114f, 0.713f, 0.564f}; + __constant__ int c_RGB2YCrCbCoeffs_i[5] = {R2Y, G2Y, B2Y, 11682, 9241}; + + template <int bidx, typename T, typename D> static __device__ void RGB2YCrCbConvert(const T* src, D& dst) + { + const int delta = ColorChannel<T>::half() * (1 << yuv_shift); + + const int Y = CV_DESCALE(src[0] * c_RGB2YCrCbCoeffs_i[bidx^2] + src[1] * c_RGB2YCrCbCoeffs_i[1] + src[2] * c_RGB2YCrCbCoeffs_i[bidx], yuv_shift); + const int Cr = CV_DESCALE((src[bidx^2] - Y) * c_RGB2YCrCbCoeffs_i[3] + delta, yuv_shift); + const int Cb = CV_DESCALE((src[bidx] - Y) * c_RGB2YCrCbCoeffs_i[4] + delta, yuv_shift); + + dst.x = saturate_cast<T>(Y); + dst.y = saturate_cast<T>(Cr); + dst.z = saturate_cast<T>(Cb); + } + + template <int bidx> static __device__ uint RGB2YCrCbConvert(uint src) + { + const int delta = ColorChannel<uchar>::half() * (1 << yuv_shift); + + const int Y = CV_DESCALE((0xffu & src) * c_RGB2YCrCbCoeffs_i[bidx^2] + (0xffu & (src >> 8)) * c_RGB2YCrCbCoeffs_i[1] + (0xffu & (src >> 16)) * c_RGB2YCrCbCoeffs_i[bidx], yuv_shift); + const int Cr = CV_DESCALE(((0xffu & (src >> ((bidx ^ 2) * 8))) - Y) * c_RGB2YCrCbCoeffs_i[3] + delta, yuv_shift); + const int Cb = CV_DESCALE(((0xffu & (src >> (bidx * 8))) - Y) * c_RGB2YCrCbCoeffs_i[4] + delta, yuv_shift); + + uint dst = 0; + + dst |= saturate_cast<uchar>(Y); + dst |= saturate_cast<uchar>(Cr) << 8; + dst |= saturate_cast<uchar>(Cb) << 16; + + return dst; + } + + template <int bidx, typename D> static __device__ __forceinline__ void RGB2YCrCbConvert(const float* src, D& dst) + { + dst.x = src[0] * c_RGB2YCrCbCoeffs_f[bidx^2] + src[1] * c_RGB2YCrCbCoeffs_f[1] + src[2] * c_RGB2YCrCbCoeffs_f[bidx]; + dst.y = (src[bidx^2] - dst.x) * c_RGB2YCrCbCoeffs_f[3] + ColorChannel<float>::half(); + dst.z = (src[bidx] - dst.x) * c_RGB2YCrCbCoeffs_f[4] + ColorChannel<float>::half(); + } + + template <typename T, int scn, int dcn, int bidx> struct RGB2YCrCb + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator ()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + RGB2YCrCbConvert<bidx>(&src.x, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB2YCrCb() {} + __host__ __device__ __forceinline__ RGB2YCrCb(const RGB2YCrCb&) {} + }; + + template <int bidx> struct RGB2YCrCb<uchar, 4, 4, bidx> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator ()(uint src) const + { + return RGB2YCrCbConvert<bidx>(src); + } + + __host__ __device__ __forceinline__ RGB2YCrCb() {} + __host__ __device__ __forceinline__ RGB2YCrCb(const RGB2YCrCb&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2YCrCb<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_YCrCb2RGBCoeffs_f[5] = {1.403f, -0.714f, -0.344f, 1.773f}; + __constant__ int c_YCrCb2RGBCoeffs_i[5] = {22987, -11698, -5636, 29049}; + + template <int bidx, typename T, typename D> static __device__ void YCrCb2RGBConvert(const T& src, D* dst) + { + const int b = src.x + CV_DESCALE((src.z - ColorChannel<D>::half()) * c_YCrCb2RGBCoeffs_i[3], yuv_shift); + const int g = src.x + CV_DESCALE((src.z - ColorChannel<D>::half()) * c_YCrCb2RGBCoeffs_i[2] + (src.y - ColorChannel<D>::half()) * c_YCrCb2RGBCoeffs_i[1], yuv_shift); + const int r = src.x + CV_DESCALE((src.y - ColorChannel<D>::half()) * c_YCrCb2RGBCoeffs_i[0], yuv_shift); + + dst[bidx] = saturate_cast<D>(b); + dst[1] = saturate_cast<D>(g); + dst[bidx^2] = saturate_cast<D>(r); + } + + template <int bidx> static __device__ uint YCrCb2RGBConvert(uint src) + { + const int x = 0xff & (src); + const int y = 0xff & (src >> 8); + const int z = 0xff & (src >> 16); + + const int b = x + CV_DESCALE((z - ColorChannel<uchar>::half()) * c_YCrCb2RGBCoeffs_i[3], yuv_shift); + const int g = x + CV_DESCALE((z - ColorChannel<uchar>::half()) * c_YCrCb2RGBCoeffs_i[2] + (y - ColorChannel<uchar>::half()) * c_YCrCb2RGBCoeffs_i[1], yuv_shift); + const int r = x + CV_DESCALE((y - ColorChannel<uchar>::half()) * c_YCrCb2RGBCoeffs_i[0], yuv_shift); + + uint dst = 0xffu << 24; + + dst |= saturate_cast<uchar>(b) << (bidx * 8); + dst |= saturate_cast<uchar>(g) << 8; + dst |= saturate_cast<uchar>(r) << ((bidx ^ 2) * 8); + + return dst; + } + + template <int bidx, typename T> __device__ __forceinline__ void YCrCb2RGBConvert(const T& src, float* dst) + { + dst[bidx] = src.x + (src.z - ColorChannel<float>::half()) * c_YCrCb2RGBCoeffs_f[3]; + dst[1] = src.x + (src.z - ColorChannel<float>::half()) * c_YCrCb2RGBCoeffs_f[2] + (src.y - ColorChannel<float>::half()) * c_YCrCb2RGBCoeffs_f[1]; + dst[bidx^2] = src.x + (src.y - ColorChannel<float>::half()) * c_YCrCb2RGBCoeffs_f[0]; + } + + template <typename T, int scn, int dcn, int bidx> struct YCrCb2RGB + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator ()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + YCrCb2RGBConvert<bidx>(src, &dst.x); + setAlpha(dst, ColorChannel<T>::max()); + + return dst; + } + __host__ __device__ __forceinline__ YCrCb2RGB() {} + __host__ __device__ __forceinline__ YCrCb2RGB(const YCrCb2RGB&) {} + }; + + template <int bidx> struct YCrCb2RGB<uchar, 4, 4, bidx> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator ()(uint src) const + { + return YCrCb2RGBConvert<bidx>(src); + } + __host__ __device__ __forceinline__ YCrCb2RGB() {} + __host__ __device__ __forceinline__ YCrCb2RGB(const YCrCb2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::YCrCb2RGB<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +////////////////////////////////////// RGB <-> XYZ /////////////////////////////////////// + + namespace color_detail + { + __constant__ float c_RGB2XYZ_D65f[9] = { 0.412453f, 0.357580f, 0.180423f, 0.212671f, 0.715160f, 0.072169f, 0.019334f, 0.119193f, 0.950227f }; + __constant__ int c_RGB2XYZ_D65i[9] = { 1689, 1465, 739, 871, 2929, 296, 79, 488, 3892 }; + + template <int bidx, typename T, typename D> static __device__ __forceinline__ void RGB2XYZConvert(const T* src, D& dst) + { + dst.z = saturate_cast<T>(CV_DESCALE(src[bidx^2] * c_RGB2XYZ_D65i[6] + src[1] * c_RGB2XYZ_D65i[7] + src[bidx] * c_RGB2XYZ_D65i[8], xyz_shift)); + dst.x = saturate_cast<T>(CV_DESCALE(src[bidx^2] * c_RGB2XYZ_D65i[0] + src[1] * c_RGB2XYZ_D65i[1] + src[bidx] * c_RGB2XYZ_D65i[2], xyz_shift)); + dst.y = saturate_cast<T>(CV_DESCALE(src[bidx^2] * c_RGB2XYZ_D65i[3] + src[1] * c_RGB2XYZ_D65i[4] + src[bidx] * c_RGB2XYZ_D65i[5], xyz_shift)); + } + + template <int bidx> static __device__ __forceinline__ uint RGB2XYZConvert(uint src) + { + const uint b = 0xffu & (src >> (bidx * 8)); + const uint g = 0xffu & (src >> 8); + const uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + + const uint x = saturate_cast<uchar>(CV_DESCALE(r * c_RGB2XYZ_D65i[0] + g * c_RGB2XYZ_D65i[1] + b * c_RGB2XYZ_D65i[2], xyz_shift)); + const uint y = saturate_cast<uchar>(CV_DESCALE(r * c_RGB2XYZ_D65i[3] + g * c_RGB2XYZ_D65i[4] + b * c_RGB2XYZ_D65i[5], xyz_shift)); + const uint z = saturate_cast<uchar>(CV_DESCALE(r * c_RGB2XYZ_D65i[6] + g * c_RGB2XYZ_D65i[7] + b * c_RGB2XYZ_D65i[8], xyz_shift)); + + uint dst = 0; + + dst |= x; + dst |= y << 8; + dst |= z << 16; + + return dst; + } + + template <int bidx, typename D> static __device__ __forceinline__ void RGB2XYZConvert(const float* src, D& dst) + { + dst.x = src[bidx^2] * c_RGB2XYZ_D65f[0] + src[1] * c_RGB2XYZ_D65f[1] + src[bidx] * c_RGB2XYZ_D65f[2]; + dst.y = src[bidx^2] * c_RGB2XYZ_D65f[3] + src[1] * c_RGB2XYZ_D65f[4] + src[bidx] * c_RGB2XYZ_D65f[5]; + dst.z = src[bidx^2] * c_RGB2XYZ_D65f[6] + src[1] * c_RGB2XYZ_D65f[7] + src[bidx] * c_RGB2XYZ_D65f[8]; + } + + template <typename T, int scn, int dcn, int bidx> struct RGB2XYZ + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + RGB2XYZConvert<bidx>(&src.x, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2XYZ() {} + __host__ __device__ __forceinline__ RGB2XYZ(const RGB2XYZ&) {} + }; + + template <int bidx> struct RGB2XYZ<uchar, 4, 4, bidx> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + return RGB2XYZConvert<bidx>(src); + } + __host__ __device__ __forceinline__ RGB2XYZ() {} + __host__ __device__ __forceinline__ RGB2XYZ(const RGB2XYZ&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2XYZ<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_XYZ2sRGB_D65f[9] = { 3.240479f, -1.53715f, -0.498535f, -0.969256f, 1.875991f, 0.041556f, 0.055648f, -0.204043f, 1.057311f }; + __constant__ int c_XYZ2sRGB_D65i[9] = { 13273, -6296, -2042, -3970, 7684, 170, 228, -836, 4331 }; + + template <int bidx, typename T, typename D> static __device__ __forceinline__ void XYZ2RGBConvert(const T& src, D* dst) + { + dst[bidx^2] = saturate_cast<D>(CV_DESCALE(src.x * c_XYZ2sRGB_D65i[0] + src.y * c_XYZ2sRGB_D65i[1] + src.z * c_XYZ2sRGB_D65i[2], xyz_shift)); + dst[1] = saturate_cast<D>(CV_DESCALE(src.x * c_XYZ2sRGB_D65i[3] + src.y * c_XYZ2sRGB_D65i[4] + src.z * c_XYZ2sRGB_D65i[5], xyz_shift)); + dst[bidx] = saturate_cast<D>(CV_DESCALE(src.x * c_XYZ2sRGB_D65i[6] + src.y * c_XYZ2sRGB_D65i[7] + src.z * c_XYZ2sRGB_D65i[8], xyz_shift)); + } + + template <int bidx> static __device__ __forceinline__ uint XYZ2RGBConvert(uint src) + { + const int x = 0xff & src; + const int y = 0xff & (src >> 8); + const int z = 0xff & (src >> 16); + + const uint r = saturate_cast<uchar>(CV_DESCALE(x * c_XYZ2sRGB_D65i[0] + y * c_XYZ2sRGB_D65i[1] + z * c_XYZ2sRGB_D65i[2], xyz_shift)); + const uint g = saturate_cast<uchar>(CV_DESCALE(x * c_XYZ2sRGB_D65i[3] + y * c_XYZ2sRGB_D65i[4] + z * c_XYZ2sRGB_D65i[5], xyz_shift)); + const uint b = saturate_cast<uchar>(CV_DESCALE(x * c_XYZ2sRGB_D65i[6] + y * c_XYZ2sRGB_D65i[7] + z * c_XYZ2sRGB_D65i[8], xyz_shift)); + + uint dst = 0xffu << 24; + + dst |= b << (bidx * 8); + dst |= g << 8; + dst |= r << ((bidx ^ 2) * 8); + + return dst; + } + + template <int bidx, typename T> static __device__ __forceinline__ void XYZ2RGBConvert(const T& src, float* dst) + { + dst[bidx^2] = src.x * c_XYZ2sRGB_D65f[0] + src.y * c_XYZ2sRGB_D65f[1] + src.z * c_XYZ2sRGB_D65f[2]; + dst[1] = src.x * c_XYZ2sRGB_D65f[3] + src.y * c_XYZ2sRGB_D65f[4] + src.z * c_XYZ2sRGB_D65f[5]; + dst[bidx] = src.x * c_XYZ2sRGB_D65f[6] + src.y * c_XYZ2sRGB_D65f[7] + src.z * c_XYZ2sRGB_D65f[8]; + } + + template <typename T, int scn, int dcn, int bidx> struct XYZ2RGB + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + XYZ2RGBConvert<bidx>(src, &dst.x); + setAlpha(dst, ColorChannel<T>::max()); + + return dst; + } + __host__ __device__ __forceinline__ XYZ2RGB() {} + __host__ __device__ __forceinline__ XYZ2RGB(const XYZ2RGB&) {} + }; + + template <int bidx> struct XYZ2RGB<uchar, 4, 4, bidx> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + return XYZ2RGBConvert<bidx>(src); + } + __host__ __device__ __forceinline__ XYZ2RGB() {} + __host__ __device__ __forceinline__ XYZ2RGB(const XYZ2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::XYZ2RGB<T, scn, dcn, bidx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +////////////////////////////////////// RGB <-> HSV /////////////////////////////////////// + + namespace color_detail + { + __constant__ int c_HsvDivTable [256] = {0, 1044480, 522240, 348160, 261120, 208896, 174080, 149211, 130560, 116053, 104448, 94953, 87040, 80345, 74606, 69632, 65280, 61440, 58027, 54973, 52224, 49737, 47476, 45412, 43520, 41779, 40172, 38684, 37303, 36017, 34816, 33693, 32640, 31651, 30720, 29842, 29013, 28229, 27486, 26782, 26112, 25475, 24869, 24290, 23738, 23211, 22706, 22223, 21760, 21316, 20890, 20480, 20086, 19707, 19342, 18991, 18651, 18324, 18008, 17703, 17408, 17123, 16846, 16579, 16320, 16069, 15825, 15589, 15360, 15137, 14921, 14711, 14507, 14308, 14115, 13926, 13743, 13565, 13391, 13221, 13056, 12895, 12738, 12584, 12434, 12288, 12145, 12006, 11869, 11736, 11605, 11478, 11353, 11231, 11111, 10995, 10880, 10768, 10658, 10550, 10445, 10341, 10240, 10141, 10043, 9947, 9854, 9761, 9671, 9582, 9495, 9410, 9326, 9243, 9162, 9082, 9004, 8927, 8852, 8777, 8704, 8632, 8561, 8492, 8423, 8356, 8290, 8224, 8160, 8097, 8034, 7973, 7913, 7853, 7795, 7737, 7680, 7624, 7569, 7514, 7461, 7408, 7355, 7304, 7253, 7203, 7154, 7105, 7057, 7010, 6963, 6917, 6872, 6827, 6782, 6739, 6695, 6653, 6611, 6569, 6528, 6487, 6447, 6408, 6369, 6330, 6292, 6254, 6217, 6180, 6144, 6108, 6073, 6037, 6003, 5968, 5935, 5901, 5868, 5835, 5803, 5771, 5739, 5708, 5677, 5646, 5615, 5585, 5556, 5526, 5497, 5468, 5440, 5412, 5384, 5356, 5329, 5302, 5275, 5249, 5222, 5196, 5171, 5145, 5120, 5095, 5070, 5046, 5022, 4998, 4974, 4950, 4927, 4904, 4881, 4858, 4836, 4813, 4791, 4769, 4748, 4726, 4705, 4684, 4663, 4642, 4622, 4601, 4581, 4561, 4541, 4522, 4502, 4483, 4464, 4445, 4426, 4407, 4389, 4370, 4352, 4334, 4316, 4298, 4281, 4263, 4246, 4229, 4212, 4195, 4178, 4161, 4145, 4128, 4112, 4096}; + __constant__ int c_HsvDivTable180[256] = {0, 122880, 61440, 40960, 30720, 24576, 20480, 17554, 15360, 13653, 12288, 11171, 10240, 9452, 8777, 8192, 7680, 7228, 6827, 6467, 6144, 5851, 5585, 5343, 5120, 4915, 4726, 4551, 4389, 4237, 4096, 3964, 3840, 3724, 3614, 3511, 3413, 3321, 3234, 3151, 3072, 2997, 2926, 2858, 2793, 2731, 2671, 2614, 2560, 2508, 2458, 2409, 2363, 2318, 2276, 2234, 2194, 2156, 2119, 2083, 2048, 2014, 1982, 1950, 1920, 1890, 1862, 1834, 1807, 1781, 1755, 1731, 1707, 1683, 1661, 1638, 1617, 1596, 1575, 1555, 1536, 1517, 1499, 1480, 1463, 1446, 1429, 1412, 1396, 1381, 1365, 1350, 1336, 1321, 1307, 1293, 1280, 1267, 1254, 1241, 1229, 1217, 1205, 1193, 1182, 1170, 1159, 1148, 1138, 1127, 1117, 1107, 1097, 1087, 1078, 1069, 1059, 1050, 1041, 1033, 1024, 1016, 1007, 999, 991, 983, 975, 968, 960, 953, 945, 938, 931, 924, 917, 910, 904, 897, 890, 884, 878, 871, 865, 859, 853, 847, 842, 836, 830, 825, 819, 814, 808, 803, 798, 793, 788, 783, 778, 773, 768, 763, 759, 754, 749, 745, 740, 736, 731, 727, 723, 719, 714, 710, 706, 702, 698, 694, 690, 686, 683, 679, 675, 671, 668, 664, 661, 657, 654, 650, 647, 643, 640, 637, 633, 630, 627, 624, 621, 617, 614, 611, 608, 605, 602, 599, 597, 594, 591, 588, 585, 582, 580, 577, 574, 572, 569, 566, 564, 561, 559, 556, 554, 551, 549, 546, 544, 541, 539, 537, 534, 532, 530, 527, 525, 523, 521, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 497, 495, 493, 492, 490, 488, 486, 484, 482}; + __constant__ int c_HsvDivTable256[256] = {0, 174763, 87381, 58254, 43691, 34953, 29127, 24966, 21845, 19418, 17476, 15888, 14564, 13443, 12483, 11651, 10923, 10280, 9709, 9198, 8738, 8322, 7944, 7598, 7282, 6991, 6722, 6473, 6242, 6026, 5825, 5638, 5461, 5296, 5140, 4993, 4855, 4723, 4599, 4481, 4369, 4263, 4161, 4064, 3972, 3884, 3799, 3718, 3641, 3567, 3495, 3427, 3361, 3297, 3236, 3178, 3121, 3066, 3013, 2962, 2913, 2865, 2819, 2774, 2731, 2689, 2648, 2608, 2570, 2533, 2497, 2461, 2427, 2394, 2362, 2330, 2300, 2270, 2241, 2212, 2185, 2158, 2131, 2106, 2081, 2056, 2032, 2009, 1986, 1964, 1942, 1920, 1900, 1879, 1859, 1840, 1820, 1802, 1783, 1765, 1748, 1730, 1713, 1697, 1680, 1664, 1649, 1633, 1618, 1603, 1589, 1574, 1560, 1547, 1533, 1520, 1507, 1494, 1481, 1469, 1456, 1444, 1432, 1421, 1409, 1398, 1387, 1376, 1365, 1355, 1344, 1334, 1324, 1314, 1304, 1295, 1285, 1276, 1266, 1257, 1248, 1239, 1231, 1222, 1214, 1205, 1197, 1189, 1181, 1173, 1165, 1157, 1150, 1142, 1135, 1128, 1120, 1113, 1106, 1099, 1092, 1085, 1079, 1072, 1066, 1059, 1053, 1046, 1040, 1034, 1028, 1022, 1016, 1010, 1004, 999, 993, 987, 982, 976, 971, 966, 960, 955, 950, 945, 940, 935, 930, 925, 920, 915, 910, 906, 901, 896, 892, 887, 883, 878, 874, 869, 865, 861, 857, 853, 848, 844, 840, 836, 832, 828, 824, 820, 817, 813, 809, 805, 802, 798, 794, 791, 787, 784, 780, 777, 773, 770, 767, 763, 760, 757, 753, 750, 747, 744, 741, 737, 734, 731, 728, 725, 722, 719, 716, 713, 710, 708, 705, 702, 699, 696, 694, 691, 688, 685}; + + template <int bidx, int hr, typename D> static __device__ void RGB2HSVConvert(const uchar* src, D& dst) + { + const int hsv_shift = 12; + const int* hdiv_table = hr == 180 ? c_HsvDivTable180 : c_HsvDivTable256; + + int b = src[bidx], g = src[1], r = src[bidx^2]; + int h, s, v = b; + int vmin = b, diff; + int vr, vg; + + v = ::max(v, g); + v = ::max(v, r); + vmin = ::min(vmin, g); + vmin = ::min(vmin, r); + + diff = v - vmin; + vr = (v == r) * -1; + vg = (v == g) * -1; + + s = (diff * c_HsvDivTable[v] + (1 << (hsv_shift-1))) >> hsv_shift; + h = (vr & (g - b)) + (~vr & ((vg & (b - r + 2 * diff)) + ((~vg) & (r - g + 4 * diff)))); + h = (h * hdiv_table[diff] + (1 << (hsv_shift-1))) >> hsv_shift; + h += (h < 0) * hr; + + dst.x = saturate_cast<uchar>(h); + dst.y = (uchar)s; + dst.z = (uchar)v; + } + + template <int bidx, int hr> static __device__ uint RGB2HSVConvert(uint src) + { + const int hsv_shift = 12; + const int* hdiv_table = hr == 180 ? c_HsvDivTable180 : c_HsvDivTable256; + + const int b = 0xff & (src >> (bidx * 8)); + const int g = 0xff & (src >> 8); + const int r = 0xff & (src >> ((bidx ^ 2) * 8)); + + int h, s, v = b; + int vmin = b, diff; + int vr, vg; + + v = ::max(v, g); + v = ::max(v, r); + vmin = ::min(vmin, g); + vmin = ::min(vmin, r); + + diff = v - vmin; + vr = (v == r) * -1; + vg = (v == g) * -1; + + s = (diff * c_HsvDivTable[v] + (1 << (hsv_shift-1))) >> hsv_shift; + h = (vr & (g - b)) + (~vr & ((vg & (b - r + 2 * diff)) + ((~vg) & (r - g + 4 * diff)))); + h = (h * hdiv_table[diff] + (1 << (hsv_shift-1))) >> hsv_shift; + h += (h < 0) * hr; + + uint dst = 0; + + dst |= saturate_cast<uchar>(h); + dst |= (0xffu & s) << 8; + dst |= (0xffu & v) << 16; + + return dst; + } + + template <int bidx, int hr, typename D> static __device__ void RGB2HSVConvert(const float* src, D& dst) + { + const float hscale = hr * (1.f / 360.f); + + float b = src[bidx], g = src[1], r = src[bidx^2]; + float h, s, v; + + float vmin, diff; + + v = vmin = r; + v = fmax(v, g); + v = fmax(v, b); + vmin = fmin(vmin, g); + vmin = fmin(vmin, b); + + diff = v - vmin; + s = diff / (float)(::fabs(v) + numeric_limits<float>::epsilon()); + diff = (float)(60. / (diff + numeric_limits<float>::epsilon())); + + h = (v == r) * (g - b) * diff; + h += (v != r && v == g) * ((b - r) * diff + 120.f); + h += (v != r && v != g) * ((r - g) * diff + 240.f); + h += (h < 0) * 360.f; + + dst.x = h * hscale; + dst.y = s; + dst.z = v; + } + + template <typename T, int scn, int dcn, int bidx, int hr> struct RGB2HSV + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + RGB2HSVConvert<bidx, hr>(&src.x, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2HSV() {} + __host__ __device__ __forceinline__ RGB2HSV(const RGB2HSV&) {} + }; + + template <int bidx, int hr> struct RGB2HSV<uchar, 4, 4, bidx, hr> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + return RGB2HSVConvert<bidx, hr>(src); + } + __host__ __device__ __forceinline__ RGB2HSV() {} + __host__ __device__ __forceinline__ RGB2HSV(const RGB2HSV&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV<T, scn, dcn, bidx, 180> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <typename T> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV<T, scn, dcn, bidx, 256> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ int c_HsvSectorData[6][3] = { {1,3,0}, {1,0,2}, {3,0,1}, {0,2,1}, {0,1,3}, {2,1,0} }; + + template <int bidx, int hr, typename T> static __device__ void HSV2RGBConvert(const T& src, float* dst) + { + const float hscale = 6.f / hr; + + float h = src.x, s = src.y, v = src.z; + float b = v, g = v, r = v; + + if (s != 0) + { + h *= hscale; + + if( h < 0 ) + do h += 6; while( h < 0 ); + else if( h >= 6 ) + do h -= 6; while( h >= 6 ); + + int sector = __float2int_rd(h); + h -= sector; + + if ( (unsigned)sector >= 6u ) + { + sector = 0; + h = 0.f; + } + + float tab[4]; + tab[0] = v; + tab[1] = v * (1.f - s); + tab[2] = v * (1.f - s * h); + tab[3] = v * (1.f - s * (1.f - h)); + + b = tab[c_HsvSectorData[sector][0]]; + g = tab[c_HsvSectorData[sector][1]]; + r = tab[c_HsvSectorData[sector][2]]; + } + + dst[bidx] = b; + dst[1] = g; + dst[bidx^2] = r; + } + + template <int bidx, int HR, typename T> static __device__ void HSV2RGBConvert(const T& src, uchar* dst) + { + float3 buf; + + buf.x = src.x; + buf.y = src.y * (1.f / 255.f); + buf.z = src.z * (1.f / 255.f); + + HSV2RGBConvert<bidx, HR>(buf, &buf.x); + + dst[0] = saturate_cast<uchar>(buf.x * 255.f); + dst[1] = saturate_cast<uchar>(buf.y * 255.f); + dst[2] = saturate_cast<uchar>(buf.z * 255.f); + } + + template <int bidx, int hr> static __device__ uint HSV2RGBConvert(uint src) + { + float3 buf; + + buf.x = src & 0xff; + buf.y = ((src >> 8) & 0xff) * (1.f/255.f); + buf.z = ((src >> 16) & 0xff) * (1.f/255.f); + + HSV2RGBConvert<bidx, hr>(buf, &buf.x); + + uint dst = 0xffu << 24; + + dst |= saturate_cast<uchar>(buf.x * 255.f); + dst |= saturate_cast<uchar>(buf.y * 255.f) << 8; + dst |= saturate_cast<uchar>(buf.z * 255.f) << 16; + + return dst; + } + + template <typename T, int scn, int dcn, int bidx, int hr> struct HSV2RGB + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + HSV2RGBConvert<bidx, hr>(src, &dst.x); + setAlpha(dst, ColorChannel<T>::max()); + + return dst; + } + __host__ __device__ __forceinline__ HSV2RGB() {} + __host__ __device__ __forceinline__ HSV2RGB(const HSV2RGB&) {} + }; + + template <int bidx, int hr> struct HSV2RGB<uchar, 4, 4, bidx, hr> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + return HSV2RGBConvert<bidx, hr>(src); + } + __host__ __device__ __forceinline__ HSV2RGB() {} + __host__ __device__ __forceinline__ HSV2RGB(const HSV2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB<T, scn, dcn, bidx, 180> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <typename T> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB<T, scn, dcn, bidx, 255> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +/////////////////////////////////////// RGB <-> HLS //////////////////////////////////////// + + namespace color_detail + { + template <int bidx, int hr, typename D> static __device__ void RGB2HLSConvert(const float* src, D& dst) + { + const float hscale = hr * (1.f / 360.f); + + float b = src[bidx], g = src[1], r = src[bidx^2]; + float h = 0.f, s = 0.f, l; + float vmin, vmax, diff; + + vmax = vmin = r; + vmax = fmax(vmax, g); + vmax = fmax(vmax, b); + vmin = fmin(vmin, g); + vmin = fmin(vmin, b); + + diff = vmax - vmin; + l = (vmax + vmin) * 0.5f; + + if (diff > numeric_limits<float>::epsilon()) + { + s = (l < 0.5f) * diff / (vmax + vmin); + s += (l >= 0.5f) * diff / (2.0f - vmax - vmin); + + diff = 60.f / diff; + + h = (vmax == r) * (g - b) * diff; + h += (vmax != r && vmax == g) * ((b - r) * diff + 120.f); + h += (vmax != r && vmax != g) * ((r - g) * diff + 240.f); + h += (h < 0.f) * 360.f; + } + + dst.x = h * hscale; + dst.y = l; + dst.z = s; + } + + template <int bidx, int hr, typename D> static __device__ void RGB2HLSConvert(const uchar* src, D& dst) + { + float3 buf; + + buf.x = src[0] * (1.f / 255.f); + buf.y = src[1] * (1.f / 255.f); + buf.z = src[2] * (1.f / 255.f); + + RGB2HLSConvert<bidx, hr>(&buf.x, buf); + + dst.x = saturate_cast<uchar>(buf.x); + dst.y = saturate_cast<uchar>(buf.y*255.f); + dst.z = saturate_cast<uchar>(buf.z*255.f); + } + + template <int bidx, int hr> static __device__ uint RGB2HLSConvert(uint src) + { + float3 buf; + + buf.x = (0xff & src) * (1.f / 255.f); + buf.y = (0xff & (src >> 8)) * (1.f / 255.f); + buf.z = (0xff & (src >> 16)) * (1.f / 255.f); + + RGB2HLSConvert<bidx, hr>(&buf.x, buf); + + uint dst = 0xffu << 24; + + dst |= saturate_cast<uchar>(buf.x); + dst |= saturate_cast<uchar>(buf.y * 255.f) << 8; + dst |= saturate_cast<uchar>(buf.z * 255.f) << 16; + + return dst; + } + + template <typename T, int scn, int dcn, int bidx, int hr> struct RGB2HLS + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + RGB2HLSConvert<bidx, hr>(&src.x, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2HLS() {} + __host__ __device__ __forceinline__ RGB2HLS(const RGB2HLS&) {} + }; + + template <int bidx, int hr> struct RGB2HLS<uchar, 4, 4, bidx, hr> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + return RGB2HLSConvert<bidx, hr>(src); + } + __host__ __device__ __forceinline__ RGB2HLS() {} + __host__ __device__ __forceinline__ RGB2HLS(const RGB2HLS&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS<T, scn, dcn, bidx, 180> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <typename T> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS<T, scn, dcn, bidx, 256> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ int c_HlsSectorData[6][3] = { {1,3,0}, {1,0,2}, {3,0,1}, {0,2,1}, {0,1,3}, {2,1,0} }; + + template <int bidx, int hr, typename T> static __device__ void HLS2RGBConvert(const T& src, float* dst) + { + const float hscale = 6.0f / hr; + + float h = src.x, l = src.y, s = src.z; + float b = l, g = l, r = l; + + if (s != 0) + { + float p2 = (l <= 0.5f) * l * (1 + s); + p2 += (l > 0.5f) * (l + s - l * s); + float p1 = 2 * l - p2; + + h *= hscale; + + if( h < 0 ) + do h += 6; while( h < 0 ); + else if( h >= 6 ) + do h -= 6; while( h >= 6 ); + + int sector; + sector = __float2int_rd(h); + + h -= sector; + + float tab[4]; + tab[0] = p2; + tab[1] = p1; + tab[2] = p1 + (p2 - p1) * (1 - h); + tab[3] = p1 + (p2 - p1) * h; + + b = tab[c_HlsSectorData[sector][0]]; + g = tab[c_HlsSectorData[sector][1]]; + r = tab[c_HlsSectorData[sector][2]]; + } + + dst[bidx] = b; + dst[1] = g; + dst[bidx^2] = r; + } + + template <int bidx, int hr, typename T> static __device__ void HLS2RGBConvert(const T& src, uchar* dst) + { + float3 buf; + + buf.x = src.x; + buf.y = src.y * (1.f / 255.f); + buf.z = src.z * (1.f / 255.f); + + HLS2RGBConvert<bidx, hr>(buf, &buf.x); + + dst[0] = saturate_cast<uchar>(buf.x * 255.f); + dst[1] = saturate_cast<uchar>(buf.y * 255.f); + dst[2] = saturate_cast<uchar>(buf.z * 255.f); + } + + template <int bidx, int hr> static __device__ uint HLS2RGBConvert(uint src) + { + float3 buf; + + buf.x = 0xff & src; + buf.y = (0xff & (src >> 8)) * (1.f / 255.f); + buf.z = (0xff & (src >> 16)) * (1.f / 255.f); + + HLS2RGBConvert<bidx, hr>(buf, &buf.x); + + uint dst = 0xffu << 24; + + dst |= saturate_cast<uchar>(buf.x * 255.f); + dst |= saturate_cast<uchar>(buf.y * 255.f) << 8; + dst |= saturate_cast<uchar>(buf.z * 255.f) << 16; + + return dst; + } + + template <typename T, int scn, int dcn, int bidx, int hr> struct HLS2RGB + : unary_function<typename TypeVec<T, scn>::vec_type, typename TypeVec<T, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<T, dcn>::vec_type operator()(const typename TypeVec<T, scn>::vec_type& src) const + { + typename TypeVec<T, dcn>::vec_type dst; + + HLS2RGBConvert<bidx, hr>(src, &dst.x); + setAlpha(dst, ColorChannel<T>::max()); + + return dst; + } + __host__ __device__ __forceinline__ HLS2RGB() {} + __host__ __device__ __forceinline__ HLS2RGB(const HLS2RGB&) {} + }; + + template <int bidx, int hr> struct HLS2RGB<uchar, 4, 4, bidx, hr> : unary_function<uint, uint> + { + __device__ __forceinline__ uint operator()(uint src) const + { + return HLS2RGBConvert<bidx, hr>(src); + } + __host__ __device__ __forceinline__ HLS2RGB() {} + __host__ __device__ __forceinline__ HLS2RGB(const HLS2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(name, scn, dcn, bidx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB<T, scn, dcn, bidx, 180> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <typename T> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB<T, scn, dcn, bidx, 255> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits<float> \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB<float, scn, dcn, bidx, 360> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> Lab ///////////////////////////////////// + + namespace color_detail + { + enum + { + LAB_CBRT_TAB_SIZE = 1024, + GAMMA_TAB_SIZE = 1024, + lab_shift = xyz_shift, + gamma_shift = 3, + lab_shift2 = (lab_shift + gamma_shift), + LAB_CBRT_TAB_SIZE_B = (256 * 3 / 2 * (1 << gamma_shift)) + }; + + __constant__ ushort c_sRGBGammaTab_b[] = {0,1,1,2,2,3,4,4,5,6,6,7,8,8,9,10,11,11,12,13,14,15,16,17,19,20,21,22,24,25,26,28,29,31,33,34,36,38,40,41,43,45,47,49,51,54,56,58,60,63,65,68,70,73,75,78,81,83,86,89,92,95,98,101,105,108,111,115,118,121,125,129,132,136,140,144,147,151,155,160,164,168,172,176,181,185,190,194,199,204,209,213,218,223,228,233,239,244,249,255,260,265,271,277,282,288,294,300,306,312,318,324,331,337,343,350,356,363,370,376,383,390,397,404,411,418,426,433,440,448,455,463,471,478,486,494,502,510,518,527,535,543,552,560,569,578,586,595,604,613,622,631,641,650,659,669,678,688,698,707,717,727,737,747,757,768,778,788,799,809,820,831,842,852,863,875,886,897,908,920,931,943,954,966,978,990,1002,1014,1026,1038,1050,1063,1075,1088,1101,1113,1126,1139,1152,1165,1178,1192,1205,1218,1232,1245,1259,1273,1287,1301,1315,1329,1343,1357,1372,1386,1401,1415,1430,1445,1460,1475,1490,1505,1521,1536,1551,1567,1583,1598,1614,1630,1646,1662,1678,1695,1711,1728,1744,1761,1778,1794,1811,1828,1846,1863,1880,1897,1915,1933,1950,1968,1986,2004,2022,2040}; + + __device__ __forceinline__ int LabCbrt_b(int i) + { + float x = i * (1.f / (255.f * (1 << gamma_shift))); + return (1 << lab_shift2) * (x < 0.008856f ? x * 7.787f + 0.13793103448275862f : ::cbrtf(x)); + } + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void RGB2LabConvert_b(const T& src, D& dst) + { + const int Lscale = (116 * 255 + 50) / 100; + const int Lshift = -((16 * 255 * (1 << lab_shift2) + 50) / 100); + + int B = blueIdx == 0 ? src.x : src.z; + int G = src.y; + int R = blueIdx == 0 ? src.z : src.x; + + if (srgb) + { + B = c_sRGBGammaTab_b[B]; + G = c_sRGBGammaTab_b[G]; + R = c_sRGBGammaTab_b[R]; + } + else + { + B <<= 3; + G <<= 3; + R <<= 3; + } + + int fX = LabCbrt_b(CV_DESCALE(B * 778 + G * 1541 + R * 1777, lab_shift)); + int fY = LabCbrt_b(CV_DESCALE(B * 296 + G * 2929 + R * 871, lab_shift)); + int fZ = LabCbrt_b(CV_DESCALE(B * 3575 + G * 448 + R * 73, lab_shift)); + + int L = CV_DESCALE(Lscale * fY + Lshift, lab_shift2); + int a = CV_DESCALE(500 * (fX - fY) + 128 * (1 << lab_shift2), lab_shift2); + int b = CV_DESCALE(200 * (fY - fZ) + 128 * (1 << lab_shift2), lab_shift2); + + dst.x = saturate_cast<uchar>(L); + dst.y = saturate_cast<uchar>(a); + dst.z = saturate_cast<uchar>(b); + } + + __device__ __forceinline__ float splineInterpolate(float x, const float* tab, int n) + { + int ix = ::min(::max(int(x), 0), n-1); + x -= ix; + tab += ix * 4; + return ((tab[3] * x + tab[2]) * x + tab[1]) * x + tab[0]; + } + + __constant__ float c_sRGBGammaTab[] = {0,7.55853e-05,0.,-7.51331e-13,7.55853e-05,7.55853e-05,-2.25399e-12,3.75665e-12,0.000151171,7.55853e-05,9.01597e-12,-6.99932e-12,0.000226756,7.55853e-05,-1.1982e-11,2.41277e-12,0.000302341,7.55853e-05,-4.74369e-12,1.19001e-11,0.000377927,7.55853e-05,3.09568e-11,-2.09095e-11,0.000453512,7.55853e-05,-3.17718e-11,1.35303e-11,0.000529097,7.55853e-05,8.81905e-12,-4.10782e-12,0.000604683,7.55853e-05,-3.50439e-12,2.90097e-12,0.000680268,7.55853e-05,5.19852e-12,-7.49607e-12,0.000755853,7.55853e-05,-1.72897e-11,2.70833e-11,0.000831439,7.55854e-05,6.39602e-11,-4.26295e-11,0.000907024,7.55854e-05,-6.39282e-11,2.70193e-11,0.000982609,7.55853e-05,1.71298e-11,-7.24017e-12,0.00105819,7.55853e-05,-4.59077e-12,1.94137e-12,0.00113378,7.55853e-05,1.23333e-12,-5.25291e-13,0.00120937,7.55853e-05,-3.42545e-13,1.59799e-13,0.00128495,7.55853e-05,1.36852e-13,-1.13904e-13,0.00136054,7.55853e-05,-2.04861e-13,2.95818e-13,0.00143612,7.55853e-05,6.82594e-13,-1.06937e-12,0.00151171,7.55853e-05,-2.52551e-12,3.98166e-12,0.00158729,7.55853e-05,9.41946e-12,-1.48573e-11,0.00166288,7.55853e-05,-3.51523e-11,5.54474e-11,0.00173846,7.55854e-05,1.3119e-10,-9.0517e-11,0.00181405,7.55854e-05,-1.40361e-10,7.37899e-11,0.00188963,7.55853e-05,8.10085e-11,-8.82272e-11,0.00196522,7.55852e-05,-1.83673e-10,1.62704e-10,0.0020408,7.55853e-05,3.04438e-10,-2.13341e-10,0.00211639,7.55853e-05,-3.35586e-10,2.25e-10,0.00219197,7.55853e-05,3.39414e-10,-2.20997e-10,0.00226756,7.55853e-05,-3.23576e-10,1.93326e-10,0.00234315,7.55853e-05,2.564e-10,-8.66446e-11,0.00241873,7.55855e-05,-3.53328e-12,-7.9578e-11,0.00249432,7.55853e-05,-2.42267e-10,1.72126e-10,0.0025699,7.55853e-05,2.74111e-10,-1.43265e-10,0.00264549,7.55854e-05,-1.55683e-10,-6.47292e-11,0.00272107,7.55849e-05,-3.4987e-10,8.67842e-10,0.00279666,7.55868e-05,2.25366e-09,-3.8723e-09,0.00287224,7.55797e-05,-9.36325e-09,1.5087e-08,0.00294783,7.56063e-05,3.58978e-08,-5.69415e-08,0.00302341,7.55072e-05,-1.34927e-07,2.13144e-07,0.003099,7.58768e-05,5.04507e-07,1.38713e-07,0.00317552,7.7302e-05,9.20646e-07,-1.55186e-07,0.00325359,7.86777e-05,4.55087e-07,4.26813e-08,0.00333276,7.97159e-05,5.83131e-07,-1.06495e-08,0.00341305,8.08502e-05,5.51182e-07,3.87467e-09,0.00349446,8.19642e-05,5.62806e-07,-1.92586e-10,0.00357698,8.30892e-05,5.62228e-07,1.0866e-09,0.00366063,8.4217e-05,5.65488e-07,5.02818e-10,0.00374542,8.53494e-05,5.66997e-07,8.60211e-10,0.00383133,8.6486e-05,5.69577e-07,7.13044e-10,0.00391839,8.76273e-05,5.71716e-07,4.78527e-10,0.00400659,8.87722e-05,5.73152e-07,1.09818e-09,0.00409594,8.99218e-05,5.76447e-07,2.50964e-10,0.00418644,9.10754e-05,5.772e-07,1.15762e-09,0.00427809,9.22333e-05,5.80672e-07,2.40865e-10,0.0043709,9.33954e-05,5.81395e-07,1.13854e-09,0.00446488,9.45616e-05,5.84811e-07,3.27267e-10,0.00456003,9.57322e-05,5.85792e-07,8.1197e-10,0.00465635,9.69062e-05,5.88228e-07,6.15823e-10,0.00475384,9.80845e-05,5.90076e-07,9.15747e-10,0.00485252,9.92674e-05,5.92823e-07,3.778e-10,0.00495238,0.000100454,5.93956e-07,8.32623e-10,0.00505343,0.000101645,5.96454e-07,4.82695e-10,0.00515567,0.000102839,5.97902e-07,9.61904e-10,0.00525911,0.000104038,6.00788e-07,3.26281e-10,0.00536375,0.00010524,6.01767e-07,9.926e-10,0.00546959,0.000106447,6.04745e-07,3.59933e-10,0.00557664,0.000107657,6.05824e-07,8.2728e-10,0.0056849,0.000108871,6.08306e-07,5.21898e-10,0.00579438,0.00011009,6.09872e-07,8.10492e-10,0.00590508,0.000111312,6.12303e-07,4.27046e-10,0.00601701,0.000112538,6.13585e-07,7.40878e-10,0.00613016,0.000113767,6.15807e-07,8.00469e-10,0.00624454,0.000115001,6.18209e-07,2.48178e-10,0.00636016,0.000116238,6.18953e-07,1.00073e-09,0.00647702,0.000117479,6.21955e-07,4.05654e-10,0.00659512,0.000118724,6.23172e-07,6.36192e-10,0.00671447,0.000119973,6.25081e-07,7.74927e-10,0.00683507,0.000121225,6.27406e-07,4.54975e-10,0.00695692,0.000122481,6.28771e-07,6.64841e-10,0.00708003,0.000123741,6.30765e-07,6.10972e-10,0.00720441,0.000125004,6.32598e-07,6.16543e-10,0.00733004,0.000126271,6.34448e-07,6.48204e-10,0.00745695,0.000127542,6.36392e-07,5.15835e-10,0.00758513,0.000128816,6.3794e-07,5.48103e-10,0.00771458,0.000130094,6.39584e-07,1.01706e-09,0.00784532,0.000131376,6.42635e-07,4.0283e-11,0.00797734,0.000132661,6.42756e-07,6.84471e-10,0.00811064,0.000133949,6.4481e-07,9.47144e-10,0.00824524,0.000135241,6.47651e-07,1.83472e-10,0.00838112,0.000136537,6.48201e-07,1.11296e-09,0.00851831,0.000137837,6.5154e-07,2.13163e-11,0.0086568,0.00013914,6.51604e-07,6.64462e-10,0.00879659,0.000140445,6.53598e-07,1.04613e-09,0.00893769,0.000141756,6.56736e-07,-1.92377e-10,0.0090801,0.000143069,6.56159e-07,1.58601e-09,0.00922383,0.000144386,6.60917e-07,-5.63754e-10,0.00936888,0.000145706,6.59226e-07,1.60033e-09,0.00951524,0.000147029,6.64027e-07,-2.49543e-10,0.00966294,0.000148356,6.63278e-07,1.26043e-09,0.00981196,0.000149687,6.67059e-07,-1.35572e-10,0.00996231,0.00015102,6.66653e-07,1.14458e-09,0.010114,0.000152357,6.70086e-07,2.13864e-10,0.010267,0.000153698,6.70728e-07,7.93856e-10,0.0104214,0.000155042,6.73109e-07,3.36077e-10,0.0105771,0.000156389,6.74118e-07,6.55765e-10,0.0107342,0.000157739,6.76085e-07,7.66211e-10,0.0108926,0.000159094,6.78384e-07,4.66116e-12,0.0110524,0.000160451,6.78398e-07,1.07775e-09,0.0112135,0.000161811,6.81631e-07,3.41023e-10,0.011376,0.000163175,6.82654e-07,3.5205e-10,0.0115398,0.000164541,6.8371e-07,1.04473e-09,0.0117051,0.000165912,6.86844e-07,1.25757e-10,0.0118717,0.000167286,6.87222e-07,3.14818e-10,0.0120396,0.000168661,6.88166e-07,1.40886e-09,0.012209,0.000170042,6.92393e-07,-3.62244e-10,0.0123797,0.000171425,6.91306e-07,9.71397e-10,0.0125518,0.000172811,6.9422e-07,2.02003e-10,0.0127253,0.0001742,6.94826e-07,1.01448e-09,0.0129002,0.000175593,6.97869e-07,3.96653e-10,0.0130765,0.00017699,6.99059e-07,1.92927e-10,0.0132542,0.000178388,6.99638e-07,6.94305e-10,0.0134333,0.00017979,7.01721e-07,7.55108e-10,0.0136138,0.000181195,7.03986e-07,1.05918e-11,0.0137957,0.000182603,7.04018e-07,1.06513e-09,0.013979,0.000184015,7.07214e-07,3.85512e-10,0.0141637,0.00018543,7.0837e-07,1.86769e-10,0.0143499,0.000186848,7.0893e-07,7.30116e-10,0.0145374,0.000188268,7.11121e-07,6.17983e-10,0.0147264,0.000189692,7.12975e-07,5.23282e-10,0.0149168,0.000191119,7.14545e-07,8.28398e-11,0.0151087,0.000192549,7.14793e-07,1.0081e-09,0.0153019,0.000193981,7.17817e-07,5.41244e-10,0.0154966,0.000195418,7.19441e-07,-3.7907e-10,0.0156928,0.000196856,7.18304e-07,1.90641e-09,0.0158903,0.000198298,7.24023e-07,-7.27387e-10,0.0160893,0.000199744,7.21841e-07,1.00317e-09,0.0162898,0.000201191,7.24851e-07,4.39949e-10,0.0164917,0.000202642,7.2617e-07,9.6234e-10,0.0166951,0.000204097,7.29057e-07,-5.64019e-10,0.0168999,0.000205554,7.27365e-07,1.29374e-09,0.0171062,0.000207012,7.31247e-07,9.77025e-10,0.017314,0.000208478,7.34178e-07,-1.47651e-09,0.0175232,0.000209942,7.29748e-07,3.06636e-09,0.0177338,0.00021141,7.38947e-07,-1.47573e-09,0.017946,0.000212884,7.3452e-07,9.7386e-10,0.0181596,0.000214356,7.37442e-07,1.30562e-09,0.0183747,0.000215835,7.41358e-07,-6.08376e-10,0.0185913,0.000217315,7.39533e-07,1.12785e-09,0.0188093,0.000218798,7.42917e-07,-1.77711e-10,0.0190289,0.000220283,7.42384e-07,1.44562e-09,0.0192499,0.000221772,7.46721e-07,-1.68825e-11,0.0194724,0.000223266,7.4667e-07,4.84533e-10,0.0196964,0.000224761,7.48124e-07,-5.85298e-11,0.0199219,0.000226257,7.47948e-07,1.61217e-09,0.0201489,0.000227757,7.52785e-07,-8.02136e-10,0.0203775,0.00022926,7.50378e-07,1.59637e-09,0.0206075,0.000230766,7.55167e-07,4.47168e-12,0.020839,0.000232276,7.55181e-07,2.48387e-10,0.021072,0.000233787,7.55926e-07,8.6474e-10,0.0213066,0.000235302,7.5852e-07,1.78299e-11,0.0215426,0.000236819,7.58573e-07,9.26567e-10,0.0217802,0.000238339,7.61353e-07,1.34529e-12,0.0220193,0.000239862,7.61357e-07,9.30659e-10,0.0222599,0.000241387,7.64149e-07,1.34529e-12,0.0225021,0.000242915,7.64153e-07,9.26567e-10,0.0227458,0.000244447,7.66933e-07,1.76215e-11,0.022991,0.00024598,7.66986e-07,8.65536e-10,0.0232377,0.000247517,7.69582e-07,2.45677e-10,0.023486,0.000249057,7.70319e-07,1.44193e-11,0.0237358,0.000250598,7.70363e-07,1.55918e-09,0.0239872,0.000252143,7.7504e-07,-6.63173e-10,0.0242401,0.000253691,7.73051e-07,1.09357e-09,0.0244946,0.000255241,7.76331e-07,1.41919e-11,0.0247506,0.000256793,7.76374e-07,7.12248e-10,0.0250082,0.000258348,7.78511e-07,8.62049e-10,0.0252673,0.000259908,7.81097e-07,-4.35061e-10,0.025528,0.000261469,7.79792e-07,8.7825e-10,0.0257902,0.000263031,7.82426e-07,6.47181e-10,0.0260541,0.000264598,7.84368e-07,2.58448e-10,0.0263194,0.000266167,7.85143e-07,1.81558e-10,0.0265864,0.000267738,7.85688e-07,8.78041e-10,0.0268549,0.000269312,7.88322e-07,3.15102e-11,0.027125,0.000270889,7.88417e-07,8.58525e-10,0.0273967,0.000272468,7.90992e-07,2.59812e-10,0.02767,0.000274051,7.91772e-07,-3.5224e-11,0.0279448,0.000275634,7.91666e-07,1.74377e-09,0.0282212,0.000277223,7.96897e-07,-1.35196e-09,0.0284992,0.000278813,7.92841e-07,1.80141e-09,0.0287788,0.000280404,7.98246e-07,-2.65629e-10,0.0290601,0.000281999,7.97449e-07,1.12374e-09,0.0293428,0.000283598,8.0082e-07,-5.04106e-10,0.0296272,0.000285198,7.99308e-07,8.92764e-10,0.0299132,0.000286799,8.01986e-07,6.58379e-10,0.0302008,0.000288405,8.03961e-07,1.98971e-10,0.0304901,0.000290014,8.04558e-07,4.08382e-10,0.0307809,0.000291624,8.05783e-07,3.01839e-11,0.0310733,0.000293236,8.05874e-07,1.33343e-09,0.0313673,0.000294851,8.09874e-07,2.2419e-10,0.031663,0.000296472,8.10547e-07,-3.67606e-10,0.0319603,0.000298092,8.09444e-07,1.24624e-09,0.0322592,0.000299714,8.13182e-07,-8.92025e-10,0.0325597,0.000301338,8.10506e-07,2.32183e-09,0.0328619,0.000302966,8.17472e-07,-9.44719e-10,0.0331657,0.000304598,8.14638e-07,1.45703e-09,0.0334711,0.000306232,8.19009e-07,-1.15805e-09,0.0337781,0.000307866,8.15535e-07,3.17507e-09,0.0340868,0.000309507,8.2506e-07,-4.09161e-09,0.0343971,0.000311145,8.12785e-07,5.74079e-09,0.0347091,0.000312788,8.30007e-07,-3.97034e-09,0.0350227,0.000314436,8.18096e-07,2.68985e-09,0.035338,0.00031608,8.26166e-07,6.61676e-10,0.0356549,0.000317734,8.28151e-07,-1.61123e-09,0.0359734,0.000319386,8.23317e-07,2.05786e-09,0.0362936,0.000321038,8.29491e-07,8.30388e-10,0.0366155,0.0003227,8.31982e-07,-1.65424e-09,0.036939,0.000324359,8.27019e-07,2.06129e-09,0.0372642,0.000326019,8.33203e-07,8.59719e-10,0.0375911,0.000327688,8.35782e-07,-1.77488e-09,0.0379196,0.000329354,8.30458e-07,2.51464e-09,0.0382498,0.000331023,8.38002e-07,-8.33135e-10,0.0385817,0.000332696,8.35502e-07,8.17825e-10,0.0389152,0.00033437,8.37956e-07,1.28718e-09,0.0392504,0.00033605,8.41817e-07,-2.2413e-09,0.0395873,0.000337727,8.35093e-07,3.95265e-09,0.0399258,0.000339409,8.46951e-07,-2.39332e-09,0.0402661,0.000341095,8.39771e-07,1.89533e-09,0.040608,0.000342781,8.45457e-07,-1.46271e-09,0.0409517,0.000344467,8.41069e-07,3.95554e-09,0.041297,0.000346161,8.52936e-07,-3.18369e-09,0.041644,0.000347857,8.43385e-07,1.32873e-09,0.0419927,0.000349548,8.47371e-07,1.59402e-09,0.0423431,0.000351248,8.52153e-07,-2.54336e-10,0.0426952,0.000352951,8.5139e-07,-5.76676e-10,0.043049,0.000354652,8.4966e-07,2.56114e-09,0.0434045,0.000356359,8.57343e-07,-2.21744e-09,0.0437617,0.000358067,8.50691e-07,2.58344e-09,0.0441206,0.000359776,8.58441e-07,-6.65826e-10,0.0444813,0.000361491,8.56444e-07,7.99218e-11,0.0448436,0.000363204,8.56684e-07,3.46063e-10,0.0452077,0.000364919,8.57722e-07,2.26116e-09,0.0455734,0.000366641,8.64505e-07,-1.94005e-09,0.045941,0.000368364,8.58685e-07,1.77384e-09,0.0463102,0.000370087,8.64007e-07,-1.43005e-09,0.0466811,0.000371811,8.59717e-07,3.94634e-09,0.0470538,0.000373542,8.71556e-07,-3.17946e-09,0.0474282,0.000375276,8.62017e-07,1.32104e-09,0.0478043,0.000377003,8.6598e-07,1.62045e-09,0.0481822,0.00037874,8.70842e-07,-3.52297e-10,0.0485618,0.000380481,8.69785e-07,-2.11211e-10,0.0489432,0.00038222,8.69151e-07,1.19716e-09,0.0493263,0.000383962,8.72743e-07,-8.52026e-10,0.0497111,0.000385705,8.70187e-07,2.21092e-09,0.0500977,0.000387452,8.76819e-07,-5.41339e-10,0.050486,0.000389204,8.75195e-07,-4.5361e-11,0.0508761,0.000390954,8.75059e-07,7.22669e-10,0.0512679,0.000392706,8.77227e-07,8.79936e-10,0.0516615,0.000394463,8.79867e-07,-5.17048e-10,0.0520568,0.000396222,8.78316e-07,1.18833e-09,0.0524539,0.000397982,8.81881e-07,-5.11022e-10,0.0528528,0.000399744,8.80348e-07,8.55683e-10,0.0532534,0.000401507,8.82915e-07,8.13562e-10,0.0536558,0.000403276,8.85356e-07,-3.84603e-10,0.05406,0.000405045,8.84202e-07,7.24962e-10,0.0544659,0.000406816,8.86377e-07,1.20986e-09,0.0548736,0.000408592,8.90006e-07,-1.83896e-09,0.0552831,0.000410367,8.84489e-07,2.42071e-09,0.0556944,0.000412143,8.91751e-07,-3.93413e-10,0.0561074,0.000413925,8.90571e-07,-8.46967e-10,0.0565222,0.000415704,8.8803e-07,3.78122e-09,0.0569388,0.000417491,8.99374e-07,-3.1021e-09,0.0573572,0.000419281,8.90068e-07,1.17658e-09,0.0577774,0.000421064,8.93597e-07,2.12117e-09,0.0581993,0.000422858,8.99961e-07,-2.21068e-09,0.0586231,0.000424651,8.93329e-07,2.9961e-09,0.0590486,0.000426447,9.02317e-07,-2.32311e-09,0.059476,0.000428244,8.95348e-07,2.57122e-09,0.0599051,0.000430043,9.03062e-07,-5.11098e-10,0.0603361,0.000431847,9.01528e-07,-5.27166e-10,0.0607688,0.000433649,8.99947e-07,2.61984e-09,0.0612034,0.000435457,9.07806e-07,-2.50141e-09,0.0616397,0.000437265,9.00302e-07,3.66045e-09,0.0620779,0.000439076,9.11283e-07,-4.68977e-09,0.0625179,0.000440885,8.97214e-07,7.64783e-09,0.0629597,0.000442702,9.20158e-07,-7.27499e-09,0.0634033,0.000444521,8.98333e-07,6.55113e-09,0.0638487,0.000446337,9.17986e-07,-4.02844e-09,0.0642959,0.000448161,9.05901e-07,2.11196e-09,0.064745,0.000449979,9.12236e-07,3.03125e-09,0.0651959,0.000451813,9.2133e-07,-6.78648e-09,0.0656486,0.000453635,9.00971e-07,9.21375e-09,0.0661032,0.000455464,9.28612e-07,-7.71684e-09,0.0665596,0.000457299,9.05462e-07,6.7522e-09,0.0670178,0.00045913,9.25718e-07,-4.3907e-09,0.0674778,0.000460968,9.12546e-07,3.36e-09,0.0679397,0.000462803,9.22626e-07,-1.59876e-09,0.0684034,0.000464644,9.1783e-07,3.0351e-09,0.068869,0.000466488,9.26935e-07,-3.09101e-09,0.0693364,0.000468333,9.17662e-07,1.8785e-09,0.0698057,0.000470174,9.23298e-07,3.02733e-09,0.0702768,0.00047203,9.3238e-07,-6.53722e-09,0.0707497,0.000473875,9.12768e-07,8.22054e-09,0.0712245,0.000475725,9.37429e-07,-3.99325e-09,0.0717012,0.000477588,9.2545e-07,3.01839e-10,0.0721797,0.00047944,9.26355e-07,2.78597e-09,0.0726601,0.000481301,9.34713e-07,-3.99507e-09,0.0731423,0.000483158,9.22728e-07,5.7435e-09,0.0736264,0.000485021,9.39958e-07,-4.07776e-09,0.0741123,0.000486888,9.27725e-07,3.11695e-09,0.0746002,0.000488753,9.37076e-07,-9.39394e-10,0.0750898,0.000490625,9.34258e-07,6.4055e-10,0.0755814,0.000492495,9.3618e-07,-1.62265e-09,0.0760748,0.000494363,9.31312e-07,5.84995e-09,0.0765701,0.000496243,9.48861e-07,-6.87601e-09,0.0770673,0.00049812,9.28233e-07,6.75296e-09,0.0775664,0.000499997,9.48492e-07,-5.23467e-09,0.0780673,0.000501878,9.32788e-07,6.73523e-09,0.0785701,0.000503764,9.52994e-07,-6.80514e-09,0.0790748,0.000505649,9.32578e-07,5.5842e-09,0.0795814,0.000507531,9.49331e-07,-6.30583e-10,0.0800899,0.000509428,9.47439e-07,-3.0618e-09,0.0806003,0.000511314,9.38254e-07,5.4273e-09,0.0811125,0.000513206,9.54536e-07,-3.74627e-09,0.0816267,0.000515104,9.43297e-07,2.10713e-09,0.0821427,0.000516997,9.49618e-07,2.76839e-09,0.0826607,0.000518905,9.57924e-07,-5.73006e-09,0.0831805,0.000520803,9.40733e-07,5.25072e-09,0.0837023,0.0005227,9.56486e-07,-3.71718e-10,0.084226,0.000524612,9.5537e-07,-3.76404e-09,0.0847515,0.000526512,9.44078e-07,7.97735e-09,0.085279,0.000528424,9.6801e-07,-5.79367e-09,0.0858084,0.000530343,9.50629e-07,2.96268e-10,0.0863397,0.000532245,9.51518e-07,4.6086e-09,0.0868729,0.000534162,9.65344e-07,-3.82947e-09,0.087408,0.000536081,9.53856e-07,3.25861e-09,0.087945,0.000537998,9.63631e-07,-1.7543e-09,0.088484,0.00053992,9.58368e-07,3.75849e-09,0.0890249,0.000541848,9.69644e-07,-5.82891e-09,0.0895677,0.00054377,9.52157e-07,4.65593e-09,0.0901124,0.000545688,9.66125e-07,2.10643e-09,0.0906591,0.000547627,9.72444e-07,-5.63099e-09,0.0912077,0.000549555,9.55551e-07,5.51627e-09,0.0917582,0.000551483,9.721e-07,-1.53292e-09,0.0923106,0.000553422,9.67501e-07,6.15311e-10,0.092865,0.000555359,9.69347e-07,-9.28291e-10,0.0934213,0.000557295,9.66562e-07,3.09774e-09,0.0939796,0.000559237,9.75856e-07,-4.01186e-09,0.0945398,0.000561177,9.6382e-07,5.49892e-09,0.095102,0.000563121,9.80317e-07,-3.08258e-09,0.0956661,0.000565073,9.71069e-07,-6.19176e-10,0.0962321,0.000567013,9.69212e-07,5.55932e-09,0.0968001,0.000568968,9.8589e-07,-6.71704e-09,0.09737,0.00057092,9.65738e-07,6.40762e-09,0.0979419,0.00057287,9.84961e-07,-4.0122e-09,0.0985158,0.000574828,9.72925e-07,2.19059e-09,0.0990916,0.000576781,9.79496e-07,2.70048e-09,0.0996693,0.000578748,9.87598e-07,-5.54193e-09,0.100249,0.000580706,9.70972e-07,4.56597e-09,0.100831,0.000582662,9.8467e-07,2.17923e-09,0.101414,0.000584638,9.91208e-07,-5.83232e-09,0.102,0.000586603,9.73711e-07,6.24884e-09,0.102588,0.000588569,9.92457e-07,-4.26178e-09,0.103177,0.000590541,9.79672e-07,3.34781e-09,0.103769,0.00059251,9.89715e-07,-1.67904e-09,0.104362,0.000594485,9.84678e-07,3.36839e-09,0.104958,0.000596464,9.94783e-07,-4.34397e-09,0.105555,0.000598441,9.81751e-07,6.55696e-09,0.106155,0.000600424,1.00142e-06,-6.98272e-09,0.106756,0.000602406,9.80474e-07,6.4728e-09,0.107359,0.000604386,9.99893e-07,-4.00742e-09,0.107965,0.000606374,9.8787e-07,2.10654e-09,0.108572,0.000608356,9.9419e-07,3.0318e-09,0.109181,0.000610353,1.00329e-06,-6.7832e-09,0.109793,0.00061234,9.82936e-07,9.1998e-09,0.110406,0.000614333,1.01054e-06,-7.6642e-09,0.111021,0.000616331,9.87543e-07,6.55579e-09,0.111639,0.000618326,1.00721e-06,-3.65791e-09,0.112258,0.000620329,9.96236e-07,6.25467e-10,0.112879,0.000622324,9.98113e-07,1.15593e-09,0.113503,0.000624323,1.00158e-06,2.20158e-09,0.114128,0.000626333,1.00819e-06,-2.51191e-09,0.114755,0.000628342,1.00065e-06,3.95517e-10,0.115385,0.000630345,1.00184e-06,9.29807e-10,0.116016,0.000632351,1.00463e-06,3.33599e-09,0.116649,0.00063437,1.01463e-06,-6.82329e-09,0.117285,0.000636379,9.94163e-07,9.05595e-09,0.117922,0.000638395,1.02133e-06,-7.04862e-09,0.118562,0.000640416,1.00019e-06,4.23737e-09,0.119203,0.000642429,1.0129e-06,-2.45033e-09,0.119847,0.000644448,1.00555e-06,5.56395e-09,0.120492,0.000646475,1.02224e-06,-4.9043e-09,0.121139,0.000648505,1.00753e-06,-8.47952e-10,0.121789,0.000650518,1.00498e-06,8.29622e-09,0.122441,0.000652553,1.02987e-06,-9.98538e-09,0.123094,0.000654582,9.99914e-07,9.2936e-09,0.12375,0.00065661,1.02779e-06,-4.83707e-09,0.124407,0.000658651,1.01328e-06,2.60411e-09,0.125067,0.000660685,1.0211e-06,-5.57945e-09,0.125729,0.000662711,1.00436e-06,1.22631e-08,0.126392,0.000664756,1.04115e-06,-1.36704e-08,0.127058,0.000666798,1.00014e-06,1.26161e-08,0.127726,0.000668836,1.03798e-06,-6.99155e-09,0.128396,0.000670891,1.01701e-06,4.48836e-10,0.129068,0.000672926,1.01836e-06,5.19606e-09,0.129742,0.000674978,1.03394e-06,-6.3319e-09,0.130418,0.000677027,1.01495e-06,5.2305e-09,0.131096,0.000679073,1.03064e-06,3.11123e-10,0.131776,0.000681135,1.03157e-06,-6.47511e-09,0.132458,0.000683179,1.01215e-06,1.06882e-08,0.133142,0.000685235,1.04421e-06,-6.47519e-09,0.133829,0.000687304,1.02479e-06,3.11237e-10,0.134517,0.000689355,1.02572e-06,5.23035e-09,0.135207,0.000691422,1.04141e-06,-6.3316e-09,0.1359,0.000693486,1.02242e-06,5.19484e-09,0.136594,0.000695546,1.038e-06,4.53497e-10,0.137291,0.000697623,1.03936e-06,-7.00891e-09,0.137989,0.000699681,1.01834e-06,1.2681e-08,0.13869,0.000701756,1.05638e-06,-1.39128e-08,0.139393,0.000703827,1.01464e-06,1.31679e-08,0.140098,0.000705896,1.05414e-06,-8.95659e-09,0.140805,0.000707977,1.02727e-06,7.75742e-09,0.141514,0.000710055,1.05055e-06,-7.17182e-09,0.142225,0.000712135,1.02903e-06,6.02862e-09,0.142938,0.000714211,1.04712e-06,-2.04163e-09,0.143653,0.000716299,1.04099e-06,2.13792e-09,0.144371,0.000718387,1.04741e-06,-6.51009e-09,0.14509,0.000720462,1.02787e-06,9.00123e-09,0.145812,0.000722545,1.05488e-06,3.07523e-10,0.146535,0.000724656,1.0558e-06,-1.02312e-08,0.147261,0.000726737,1.02511e-06,1.0815e-08,0.147989,0.000728819,1.05755e-06,-3.22681e-09,0.148719,0.000730925,1.04787e-06,2.09244e-09,0.14945,0.000733027,1.05415e-06,-5.143e-09,0.150185,0.00073512,1.03872e-06,3.57844e-09,0.150921,0.000737208,1.04946e-06,5.73027e-09,0.151659,0.000739324,1.06665e-06,-1.15983e-08,0.152399,0.000741423,1.03185e-06,1.08605e-08,0.153142,0.000743519,1.06443e-06,-2.04106e-09,0.153886,0.000745642,1.05831e-06,-2.69642e-09,0.154633,0.00074775,1.05022e-06,-2.07425e-09,0.155382,0.000749844,1.044e-06,1.09934e-08,0.156133,0.000751965,1.07698e-06,-1.20972e-08,0.156886,0.000754083,1.04069e-06,7.59288e-09,0.157641,0.000756187,1.06347e-06,-3.37305e-09,0.158398,0.000758304,1.05335e-06,5.89921e-09,0.159158,0.000760428,1.07104e-06,-5.32248e-09,0.159919,0.000762554,1.05508e-06,4.8927e-10,0.160683,0.000764666,1.05654e-06,3.36547e-09,0.161448,0.000766789,1.06664e-06,9.50081e-10,0.162216,0.000768925,1.06949e-06,-7.16568e-09,0.162986,0.000771043,1.04799e-06,1.28114e-08,0.163758,0.000773177,1.08643e-06,-1.42774e-08,0.164533,0.000775307,1.0436e-06,1.44956e-08,0.165309,0.000777438,1.08708e-06,-1.39025e-08,0.166087,0.00077957,1.04538e-06,1.13118e-08,0.166868,0.000781695,1.07931e-06,-1.54224e-09,0.167651,0.000783849,1.07468e-06,-5.14312e-09,0.168436,0.000785983,1.05925e-06,7.21381e-09,0.169223,0.000788123,1.0809e-06,-8.81096e-09,0.170012,0.000790259,1.05446e-06,1.31289e-08,0.170803,0.000792407,1.09385e-06,-1.39022e-08,0.171597,0.000794553,1.05214e-06,1.26775e-08,0.172392,0.000796695,1.09018e-06,-7.00557e-09,0.17319,0.000798855,1.06916e-06,4.43796e-10,0.17399,0.000800994,1.07049e-06,5.23031e-09,0.174792,0.000803151,1.08618e-06,-6.46397e-09,0.175596,0.000805304,1.06679e-06,5.72444e-09,0.176403,0.000807455,1.08396e-06,-1.53254e-09,0.177211,0.000809618,1.07937e-06,4.05673e-10,0.178022,0.000811778,1.08058e-06,-9.01916e-11,0.178835,0.000813939,1.08031e-06,-4.49821e-11,0.17965,0.000816099,1.08018e-06,2.70234e-10,0.180467,0.00081826,1.08099e-06,-1.03603e-09,0.181286,0.000820419,1.07788e-06,3.87392e-09,0.182108,0.000822587,1.0895e-06,4.41522e-10,0.182932,0.000824767,1.09083e-06,-5.63997e-09,0.183758,0.000826932,1.07391e-06,7.21707e-09,0.184586,0.000829101,1.09556e-06,-8.32718e-09,0.185416,0.000831267,1.07058e-06,1.11907e-08,0.186248,0.000833442,1.10415e-06,-6.63336e-09,0.187083,0.00083563,1.08425e-06,4.41484e-10,0.187919,0.0008378,1.08557e-06,4.86754e-09,0.188758,0.000839986,1.10017e-06,-5.01041e-09,0.189599,0.000842171,1.08514e-06,2.72811e-10,0.190443,0.000844342,1.08596e-06,3.91916e-09,0.191288,0.000846526,1.09772e-06,-1.04819e-09,0.192136,0.000848718,1.09457e-06,2.73531e-10,0.192985,0.000850908,1.0954e-06,-4.58916e-11,0.193837,0.000853099,1.09526e-06,-9.01158e-11,0.194692,0.000855289,1.09499e-06,4.06506e-10,0.195548,0.00085748,1.09621e-06,-1.53595e-09,0.196407,0.000859668,1.0916e-06,5.73717e-09,0.197267,0.000861869,1.10881e-06,-6.51164e-09,0.19813,0.000864067,1.08928e-06,5.40831e-09,0.198995,0.000866261,1.1055e-06,-2.20401e-10,0.199863,0.000868472,1.10484e-06,-4.52652e-09,0.200732,0.000870668,1.09126e-06,3.42508e-09,0.201604,0.000872861,1.10153e-06,5.72762e-09,0.202478,0.000875081,1.11872e-06,-1.14344e-08,0.203354,0.000877284,1.08441e-06,1.02076e-08,0.204233,0.000879484,1.11504e-06,4.06355e-10,0.205113,0.000881715,1.11626e-06,-1.18329e-08,0.205996,0.000883912,1.08076e-06,1.71227e-08,0.206881,0.000886125,1.13213e-06,-1.19546e-08,0.207768,0.000888353,1.09626e-06,8.93465e-10,0.208658,0.000890548,1.09894e-06,8.38062e-09,0.209549,0.000892771,1.12408e-06,-4.61353e-09,0.210443,0.000895006,1.11024e-06,-4.82756e-09,0.211339,0.000897212,1.09576e-06,9.02245e-09,0.212238,0.00089943,1.12283e-06,-1.45997e-09,0.213138,0.000901672,1.11845e-06,-3.18255e-09,0.214041,0.000903899,1.1089e-06,-7.11073e-10,0.214946,0.000906115,1.10677e-06,6.02692e-09,0.215853,0.000908346,1.12485e-06,-8.49548e-09,0.216763,0.00091057,1.09936e-06,1.30537e-08,0.217675,0.000912808,1.13852e-06,-1.3917e-08,0.218588,0.000915044,1.09677e-06,1.28121e-08,0.219505,0.000917276,1.13521e-06,-7.5288e-09,0.220423,0.000919523,1.11262e-06,2.40205e-09,0.221344,0.000921756,1.11983e-06,-2.07941e-09,0.222267,0.000923989,1.11359e-06,5.91551e-09,0.223192,0.000926234,1.13134e-06,-6.68149e-09,0.224119,0.000928477,1.11129e-06,5.90929e-09,0.225049,0.000930717,1.12902e-06,-2.05436e-09,0.22598,0.000932969,1.12286e-06,2.30807e-09,0.226915,0.000935222,1.12978e-06,-7.17796e-09,0.227851,0.00093746,1.10825e-06,1.15028e-08,0.228789,0.000939711,1.14276e-06,-9.03083e-09,0.22973,0.000941969,1.11566e-06,9.71932e-09,0.230673,0.00094423,1.14482e-06,-1.49452e-08,0.231619,0.000946474,1.09998e-06,2.02591e-08,0.232566,0.000948735,1.16076e-06,-2.13879e-08,0.233516,0.000950993,1.0966e-06,2.05888e-08,0.234468,0.000953247,1.15837e-06,-1.62642e-08,0.235423,0.000955515,1.10957e-06,1.46658e-08,0.236379,0.000957779,1.15357e-06,-1.25966e-08,0.237338,0.000960048,1.11578e-06,5.91793e-09,0.238299,0.000962297,1.13353e-06,3.82602e-09,0.239263,0.000964576,1.14501e-06,-6.3208e-09,0.240229,0.000966847,1.12605e-06,6.55613e-09,0.241197,0.000969119,1.14572e-06,-5.00268e-09,0.242167,0.000971395,1.13071e-06,-1.44659e-09,0.243139,0.000973652,1.12637e-06,1.07891e-08,0.244114,0.000975937,1.15874e-06,-1.19073e-08,0.245091,0.000978219,1.12302e-06,7.03782e-09,0.246071,0.000980486,1.14413e-06,-1.34276e-09,0.247052,0.00098277,1.1401e-06,-1.66669e-09,0.248036,0.000985046,1.1351e-06,8.00935e-09,0.249022,0.00098734,1.15913e-06,-1.54694e-08,0.250011,0.000989612,1.11272e-06,2.4066e-08,0.251002,0.000991909,1.18492e-06,-2.11901e-08,0.251995,0.000994215,1.12135e-06,1.08973e-09,0.25299,0.000996461,1.12462e-06,1.68311e-08,0.253988,0.000998761,1.17511e-06,-8.8094e-09,0.254987,0.00100109,1.14868e-06,-1.13958e-08,0.25599,0.00100335,1.1145e-06,2.45902e-08,0.256994,0.00100565,1.18827e-06,-2.73603e-08,0.258001,0.00100795,1.10618e-06,2.52464e-08,0.25901,0.00101023,1.18192e-06,-1.40207e-08,0.260021,0.00101256,1.13986e-06,1.03387e-09,0.261035,0.00101484,1.14296e-06,9.8853e-09,0.262051,0.00101715,1.17262e-06,-1.07726e-08,0.263069,0.00101947,1.1403e-06,3.40272e-09,0.26409,0.00102176,1.15051e-06,-2.83827e-09,0.265113,0.00102405,1.142e-06,7.95039e-09,0.266138,0.00102636,1.16585e-06,8.39047e-10,0.267166,0.00102869,1.16836e-06,-1.13066e-08,0.268196,0.00103099,1.13444e-06,1.4585e-08,0.269228,0.00103331,1.1782e-06,-1.72314e-08,0.270262,0.00103561,1.1265e-06,2.45382e-08,0.271299,0.00103794,1.20012e-06,-2.13166e-08,0.272338,0.00104028,1.13617e-06,1.12364e-09,0.273379,0.00104255,1.13954e-06,1.68221e-08,0.274423,0.00104488,1.19001e-06,-8.80736e-09,0.275469,0.00104723,1.16358e-06,-1.13948e-08,0.276518,0.00104953,1.1294e-06,2.45839e-08,0.277568,0.00105186,1.20315e-06,-2.73361e-08,0.278621,0.00105418,1.12114e-06,2.51559e-08,0.279677,0.0010565,1.19661e-06,-1.36832e-08,0.280734,0.00105885,1.15556e-06,-2.25706e-10,0.281794,0.00106116,1.15488e-06,1.45862e-08,0.282857,0.00106352,1.19864e-06,-2.83167e-08,0.283921,0.00106583,1.11369e-06,3.90759e-08,0.284988,0.00106817,1.23092e-06,-3.85801e-08,0.286058,0.00107052,1.11518e-06,2.58375e-08,0.287129,0.00107283,1.19269e-06,-5.16498e-09,0.288203,0.0010752,1.1772e-06,-5.17768e-09,0.28928,0.00107754,1.16167e-06,-3.92671e-09,0.290358,0.00107985,1.14988e-06,2.08846e-08,0.29144,0.00108221,1.21254e-06,-2.00072e-08,0.292523,0.00108458,1.15252e-06,-4.60659e-10,0.293609,0.00108688,1.15114e-06,2.18499e-08,0.294697,0.00108925,1.21669e-06,-2.73343e-08,0.295787,0.0010916,1.13468e-06,2.78826e-08,0.29688,0.00109395,1.21833e-06,-2.45915e-08,0.297975,0.00109632,1.14456e-06,1.08787e-08,0.299073,0.00109864,1.17719e-06,1.08788e-08,0.300172,0.00110102,1.20983e-06,-2.45915e-08,0.301275,0.00110337,1.13605e-06,2.78828e-08,0.302379,0.00110573,1.2197e-06,-2.73348e-08,0.303486,0.00110808,1.1377e-06,2.18518e-08,0.304595,0.00111042,1.20325e-06,-4.67556e-10,0.305707,0.00111283,1.20185e-06,-1.99816e-08,0.306821,0.00111517,1.14191e-06,2.07891e-08,0.307937,0.00111752,1.20427e-06,-3.57026e-09,0.309056,0.00111992,1.19356e-06,-6.50797e-09,0.310177,0.00112228,1.17404e-06,-2.00165e-10,0.3113,0.00112463,1.17344e-06,7.30874e-09,0.312426,0.001127,1.19536e-06,7.67424e-10,0.313554,0.00112939,1.19767e-06,-1.03784e-08,0.314685,0.00113176,1.16653e-06,1.09437e-08,0.315818,0.00113412,1.19936e-06,-3.59406e-09,0.316953,0.00113651,1.18858e-06,3.43251e-09,0.318091,0.0011389,1.19888e-06,-1.0136e-08,0.319231,0.00114127,1.16847e-06,7.30915e-09,0.320374,0.00114363,1.1904e-06,1.07018e-08,0.321518,0.00114604,1.2225e-06,-2.03137e-08,0.322666,0.00114842,1.16156e-06,1.09484e-08,0.323815,0.00115078,1.19441e-06,6.32224e-09,0.324967,0.00115319,1.21337e-06,-6.43509e-09,0.326122,0.00115559,1.19407e-06,-1.03842e-08,0.327278,0.00115795,1.16291e-06,1.81697e-08,0.328438,0.00116033,1.21742e-06,-2.6901e-09,0.329599,0.00116276,1.20935e-06,-7.40939e-09,0.330763,0.00116515,1.18713e-06,2.52533e-09,0.331929,0.00116754,1.1947e-06,-2.69191e-09,0.333098,0.00116992,1.18663e-06,8.24218e-09,0.334269,0.00117232,1.21135e-06,-4.74377e-10,0.335443,0.00117474,1.20993e-06,-6.34471e-09,0.336619,0.00117714,1.1909e-06,-3.94922e-09,0.337797,0.00117951,1.17905e-06,2.21417e-08,0.338978,0.00118193,1.24547e-06,-2.50128e-08,0.340161,0.00118435,1.17043e-06,1.8305e-08,0.341346,0.00118674,1.22535e-06,-1.84048e-08,0.342534,0.00118914,1.17013e-06,2.55121e-08,0.343725,0.00119156,1.24667e-06,-2.40389e-08,0.344917,0.00119398,1.17455e-06,1.10389e-08,0.346113,0.00119636,1.20767e-06,9.68574e-09,0.34731,0.0011988,1.23673e-06,-1.99797e-08,0.34851,0.00120122,1.17679e-06,1.06284e-08,0.349713,0.0012036,1.20867e-06,7.26868e-09,0.350917,0.00120604,1.23048e-06,-9.90072e-09,0.352125,0.00120847,1.20078e-06,2.53177e-09,0.353334,0.00121088,1.20837e-06,-2.26199e-10,0.354546,0.0012133,1.20769e-06,-1.62705e-09,0.355761,0.00121571,1.20281e-06,6.73435e-09,0.356978,0.00121813,1.22302e-06,4.49207e-09,0.358197,0.00122059,1.23649e-06,-2.47027e-08,0.359419,0.00122299,1.16238e-06,3.47142e-08,0.360643,0.00122542,1.26653e-06,-2.47472e-08,0.36187,0.00122788,1.19229e-06,4.66965e-09,0.363099,0.00123028,1.20629e-06,6.06872e-09,0.36433,0.00123271,1.2245e-06,8.57729e-10,0.365564,0.00123516,1.22707e-06,-9.49952e-09,0.366801,0.00123759,1.19858e-06,7.33792e-09,0.36804,0.00124001,1.22059e-06,9.95025e-09,0.369281,0.00124248,1.25044e-06,-1.73366e-08,0.370525,0.00124493,1.19843e-06,-2.08464e-10,0.371771,0.00124732,1.1978e-06,1.81704e-08,0.373019,0.00124977,1.25232e-06,-1.28683e-08,0.37427,0.00125224,1.21371e-06,3.50042e-09,0.375524,0.00125468,1.22421e-06,-1.1335e-09,0.37678,0.00125712,1.22081e-06,1.03345e-09,0.378038,0.00125957,1.22391e-06,-3.00023e-09,0.379299,0.00126201,1.21491e-06,1.09676e-08,0.380562,0.00126447,1.24781e-06,-1.10676e-08,0.381828,0.00126693,1.21461e-06,3.50042e-09,0.383096,0.00126937,1.22511e-06,-2.93403e-09,0.384366,0.00127181,1.21631e-06,8.23574e-09,0.385639,0.00127427,1.24102e-06,-2.06607e-10,0.386915,0.00127675,1.2404e-06,-7.40935e-09,0.388193,0.00127921,1.21817e-06,4.1761e-11,0.389473,0.00128165,1.21829e-06,7.24223e-09,0.390756,0.0012841,1.24002e-06,7.91564e-10,0.392042,0.00128659,1.2424e-06,-1.04086e-08,0.393329,0.00128904,1.21117e-06,1.10405e-08,0.39462,0.0012915,1.24429e-06,-3.951e-09,0.395912,0.00129397,1.23244e-06,4.7634e-09,0.397208,0.00129645,1.24673e-06,-1.51025e-08,0.398505,0.0012989,1.20142e-06,2.58443e-08,0.399805,0.00130138,1.27895e-06,-2.86702e-08,0.401108,0.00130385,1.19294e-06,2.92318e-08,0.402413,0.00130632,1.28064e-06,-2.86524e-08,0.403721,0.0013088,1.19468e-06,2.57731e-08,0.405031,0.00131127,1.272e-06,-1.48355e-08,0.406343,0.00131377,1.2275e-06,3.76652e-09,0.407658,0.00131623,1.23879e-06,-2.30784e-10,0.408976,0.00131871,1.2381e-06,-2.84331e-09,0.410296,0.00132118,1.22957e-06,1.16041e-08,0.411618,0.00132367,1.26438e-06,-1.37708e-08,0.412943,0.00132616,1.22307e-06,1.36768e-08,0.41427,0.00132865,1.2641e-06,-1.1134e-08,0.4156,0.00133114,1.2307e-06,1.05714e-09,0.416933,0.00133361,1.23387e-06,6.90538e-09,0.418267,0.00133609,1.25459e-06,1.12372e-09,0.419605,0.00133861,1.25796e-06,-1.14002e-08,0.420945,0.00134109,1.22376e-06,1.46747e-08,0.422287,0.00134358,1.26778e-06,-1.7496e-08,0.423632,0.00134606,1.21529e-06,2.5507e-08,0.424979,0.00134857,1.29182e-06,-2.49272e-08,0.426329,0.00135108,1.21703e-06,1.45972e-08,0.427681,0.00135356,1.26083e-06,-3.65935e-09,0.429036,0.00135607,1.24985e-06,4.00178e-11,0.430393,0.00135857,1.24997e-06,3.49917e-09,0.431753,0.00136108,1.26047e-06,-1.40366e-08,0.433116,0.00136356,1.21836e-06,2.28448e-08,0.43448,0.00136606,1.28689e-06,-1.77378e-08,0.435848,0.00136858,1.23368e-06,1.83043e-08,0.437218,0.0013711,1.28859e-06,-2.56769e-08,0.43859,0.0013736,1.21156e-06,2.47987e-08,0.439965,0.0013761,1.28595e-06,-1.39133e-08,0.441342,0.00137863,1.24421e-06,1.05202e-09,0.442722,0.00138112,1.24737e-06,9.70507e-09,0.444104,0.00138365,1.27649e-06,-1.00698e-08,0.445489,0.00138617,1.24628e-06,7.72123e-10,0.446877,0.00138867,1.24859e-06,6.98132e-09,0.448267,0.00139118,1.26954e-06,1.10477e-09,0.449659,0.00139373,1.27285e-06,-1.14003e-08,0.451054,0.00139624,1.23865e-06,1.4694e-08,0.452452,0.00139876,1.28273e-06,-1.75734e-08,0.453852,0.00140127,1.23001e-06,2.5797e-08,0.455254,0.00140381,1.3074e-06,-2.60097e-08,0.456659,0.00140635,1.22937e-06,1.86371e-08,0.458067,0.00140886,1.28529e-06,-1.8736e-08,0.459477,0.00141137,1.22908e-06,2.65048e-08,0.46089,0.00141391,1.30859e-06,-2.76784e-08,0.462305,0.00141645,1.22556e-06,2.46043e-08,0.463722,0.00141897,1.29937e-06,-1.11341e-08,0.465143,0.00142154,1.26597e-06,-9.87033e-09,0.466565,0.00142404,1.23636e-06,2.08131e-08,0.467991,0.00142657,1.2988e-06,-1.37773e-08,0.469419,0.00142913,1.25746e-06,4.49378e-09,0.470849,0.00143166,1.27094e-06,-4.19781e-09,0.472282,0.00143419,1.25835e-06,1.22975e-08,0.473717,0.00143674,1.29524e-06,-1.51902e-08,0.475155,0.00143929,1.24967e-06,1.86608e-08,0.476596,0.00144184,1.30566e-06,-2.96506e-08,0.478039,0.00144436,1.2167e-06,4.03368e-08,0.479485,0.00144692,1.33771e-06,-4.22896e-08,0.480933,0.00144947,1.21085e-06,3.94148e-08,0.482384,0.00145201,1.32909e-06,-2.59626e-08,0.483837,0.00145459,1.2512e-06,4.83124e-09,0.485293,0.0014571,1.2657e-06,6.63757e-09,0.486751,0.00145966,1.28561e-06,-1.57911e-09,0.488212,0.00146222,1.28087e-06,-3.21468e-10,0.489676,0.00146478,1.27991e-06,2.86517e-09,0.491142,0.00146735,1.2885e-06,-1.11392e-08,0.49261,0.00146989,1.25508e-06,1.18893e-08,0.494081,0.00147244,1.29075e-06,-6.61574e-09,0.495555,0.001475,1.27091e-06,1.45736e-08,0.497031,0.00147759,1.31463e-06,-2.18759e-08,0.49851,0.00148015,1.249e-06,1.33252e-08,0.499992,0.00148269,1.28897e-06,-1.62277e-09,0.501476,0.00148526,1.28411e-06,-6.83421e-09,0.502962,0.00148781,1.2636e-06,2.89596e-08,0.504451,0.00149042,1.35048e-06,-4.93997e-08,0.505943,0.00149298,1.20228e-06,4.94299e-08,0.507437,0.00149553,1.35057e-06,-2.91107e-08,0.508934,0.00149814,1.26324e-06,7.40848e-09,0.510434,0.00150069,1.28547e-06,-5.23187e-10,0.511936,0.00150326,1.2839e-06,-5.31585e-09,0.51344,0.00150581,1.26795e-06,2.17866e-08,0.514947,0.00150841,1.33331e-06,-2.22257e-08,0.516457,0.00151101,1.26663e-06,7.51178e-09,0.517969,0.00151357,1.28917e-06,-7.82128e-09,0.519484,0.00151613,1.2657e-06,2.37733e-08,0.521002,0.00151873,1.33702e-06,-2.76674e-08,0.522522,0.00152132,1.25402e-06,2.72917e-08,0.524044,0.00152391,1.3359e-06,-2.18949e-08,0.525569,0.00152652,1.27021e-06,6.83372e-10,0.527097,0.00152906,1.27226e-06,1.91613e-08,0.528628,0.00153166,1.32974e-06,-1.77241e-08,0.53016,0.00153427,1.27657e-06,-7.86963e-09,0.531696,0.0015368,1.25296e-06,4.92027e-08,0.533234,0.00153945,1.40057e-06,-6.9732e-08,0.534775,0.00154204,1.19138e-06,5.09114e-08,0.536318,0.00154458,1.34411e-06,-1.4704e-08,0.537864,0.00154722,1.3e-06,7.9048e-09,0.539413,0.00154984,1.32371e-06,-1.69152e-08,0.540964,0.00155244,1.27297e-06,1.51355e-10,0.542517,0.00155499,1.27342e-06,1.63099e-08,0.544074,0.00155758,1.32235e-06,-5.78647e-09,0.545633,0.00156021,1.30499e-06,6.83599e-09,0.547194,0.00156284,1.3255e-06,-2.15575e-08,0.548758,0.00156543,1.26083e-06,1.97892e-08,0.550325,0.00156801,1.32019e-06,2.00525e-09,0.551894,0.00157065,1.32621e-06,-2.78103e-08,0.553466,0.00157322,1.24278e-06,4.96314e-08,0.555041,0.00157586,1.39167e-06,-5.1506e-08,0.556618,0.00157849,1.23716e-06,3.71835e-08,0.558198,0.00158107,1.34871e-06,-3.76233e-08,0.55978,0.00158366,1.23584e-06,5.37052e-08,0.561365,0.00158629,1.39695e-06,-5.79884e-08,0.562953,0.00158891,1.22299e-06,5.90392e-08,0.564543,0.00159153,1.4001e-06,-5.89592e-08,0.566136,0.00159416,1.22323e-06,5.7588e-08,0.567731,0.00159678,1.39599e-06,-5.21835e-08,0.569329,0.00159941,1.23944e-06,3.19369e-08,0.57093,0.00160199,1.33525e-06,-1.59594e-08,0.572533,0.00160461,1.28737e-06,3.19006e-08,0.574139,0.00160728,1.38307e-06,-5.20383e-08,0.575748,0.00160989,1.22696e-06,5.70431e-08,0.577359,0.00161251,1.39809e-06,-5.69247e-08,0.578973,0.00161514,1.22731e-06,5.14463e-08,0.580589,0.00161775,1.38165e-06,-2.9651e-08,0.582208,0.00162042,1.2927e-06,7.55339e-09,0.58383,0.00162303,1.31536e-06,-5.62636e-10,0.585455,0.00162566,1.31367e-06,-5.30281e-09,0.587081,0.00162827,1.29776e-06,2.17738e-08,0.588711,0.00163093,1.36309e-06,-2.21875e-08,0.590343,0.00163359,1.29652e-06,7.37164e-09,0.591978,0.00163621,1.31864e-06,-7.29907e-09,0.593616,0.00163882,1.29674e-06,2.18247e-08,0.595256,0.00164148,1.36221e-06,-2.03952e-08,0.596899,0.00164414,1.30103e-06,1.51241e-10,0.598544,0.00164675,1.30148e-06,1.97902e-08,0.600192,0.00164941,1.36085e-06,-1.97074e-08,0.601843,0.00165207,1.30173e-06,-5.65175e-10,0.603496,0.00165467,1.30004e-06,2.1968e-08,0.605152,0.00165734,1.36594e-06,-2.77024e-08,0.606811,0.00165999,1.28283e-06,2.92369e-08,0.608472,0.00166264,1.37054e-06,-2.96407e-08,0.610136,0.00166529,1.28162e-06,2.97215e-08,0.611803,0.00166795,1.37079e-06,-2.96408e-08,0.613472,0.0016706,1.28186e-06,2.92371e-08,0.615144,0.00167325,1.36957e-06,-2.77031e-08,0.616819,0.00167591,1.28647e-06,2.19708e-08,0.618496,0.00167855,1.35238e-06,-5.75407e-10,0.620176,0.00168125,1.35065e-06,-1.9669e-08,0.621858,0.00168389,1.29164e-06,1.96468e-08,0.623544,0.00168653,1.35058e-06,6.86403e-10,0.625232,0.00168924,1.35264e-06,-2.23924e-08,0.626922,0.00169187,1.28547e-06,2.92788e-08,0.628615,0.00169453,1.3733e-06,-3.51181e-08,0.630311,0.00169717,1.26795e-06,5.15889e-08,0.63201,0.00169987,1.42272e-06,-5.2028e-08,0.633711,0.00170255,1.26663e-06,3.73139e-08,0.635415,0.0017052,1.37857e-06,-3.76227e-08,0.637121,0.00170784,1.2657e-06,5.35722e-08,0.63883,0.00171054,1.42642e-06,-5.74567e-08,0.640542,0.00171322,1.25405e-06,5.70456e-08,0.642257,0.0017159,1.42519e-06,-5.15163e-08,0.643974,0.00171859,1.27064e-06,2.98103e-08,0.645694,0.00172122,1.36007e-06,-8.12016e-09,0.647417,0.00172392,1.33571e-06,2.67039e-09,0.649142,0.0017266,1.34372e-06,-2.56152e-09,0.65087,0.00172928,1.33604e-06,7.57571e-09,0.6526,0.00173197,1.35876e-06,-2.77413e-08,0.654334,0.00173461,1.27554e-06,4.3785e-08,0.65607,0.00173729,1.40689e-06,-2.81896e-08,0.657808,0.00174002,1.32233e-06,9.36893e-09,0.65955,0.00174269,1.35043e-06,-9.28617e-09,0.661294,0.00174536,1.32257e-06,2.77757e-08,0.66304,0.00174809,1.4059e-06,-4.2212e-08,0.66479,0.00175078,1.27926e-06,2.1863e-08,0.666542,0.0017534,1.34485e-06,1.43648e-08,0.668297,0.00175613,1.38795e-06,-1.97177e-08,0.670054,0.00175885,1.3288e-06,4.90115e-09,0.671814,0.00176152,1.3435e-06,1.13232e-10,0.673577,0.00176421,1.34384e-06,-5.3542e-09,0.675343,0.00176688,1.32778e-06,2.13035e-08,0.677111,0.0017696,1.39169e-06,-2.02553e-08,0.678882,0.00177232,1.33092e-06,1.13005e-10,0.680656,0.00177499,1.33126e-06,1.98031e-08,0.682432,0.00177771,1.39067e-06,-1.97211e-08,0.684211,0.00178043,1.33151e-06,-5.2349e-10,0.685993,0.00178309,1.32994e-06,2.18151e-08,0.687777,0.00178582,1.39538e-06,-2.71325e-08,0.689564,0.00178853,1.31398e-06,2.71101e-08,0.691354,0.00179124,1.39531e-06,-2.17035e-08,0.693147,0.00179396,1.3302e-06,9.92865e-11,0.694942,0.00179662,1.3305e-06,2.13063e-08,0.69674,0.00179935,1.39442e-06,-2.57198e-08,0.698541,0.00180206,1.31726e-06,2.19682e-08,0.700344,0.00180476,1.38317e-06,-2.54852e-09,0.70215,0.00180752,1.37552e-06,-1.17741e-08,0.703959,0.00181023,1.3402e-06,-9.95999e-09,0.705771,0.00181288,1.31032e-06,5.16141e-08,0.707585,0.00181566,1.46516e-06,-7.72869e-08,0.709402,0.00181836,1.2333e-06,7.87197e-08,0.711222,0.00182106,1.46946e-06,-5.87781e-08,0.713044,0.00182382,1.29312e-06,3.71834e-08,0.714869,0.00182652,1.40467e-06,-3.03511e-08,0.716697,0.00182924,1.31362e-06,2.46161e-08,0.718528,0.00183194,1.38747e-06,-8.5087e-09,0.720361,0.00183469,1.36194e-06,9.41892e-09,0.722197,0.00183744,1.3902e-06,-2.91671e-08,0.724036,0.00184014,1.3027e-06,4.76448e-08,0.725878,0.00184288,1.44563e-06,-4.22028e-08,0.727722,0.00184565,1.31902e-06,1.95682e-09,0.729569,0.00184829,1.3249e-06,3.43754e-08,0.731419,0.00185104,1.42802e-06,-2.0249e-08,0.733271,0.00185384,1.36727e-06,-1.29838e-08,0.735126,0.00185654,1.32832e-06,1.25794e-08,0.736984,0.00185923,1.36606e-06,2.22711e-08,0.738845,0.00186203,1.43287e-06,-4.20594e-08,0.740708,0.00186477,1.3067e-06,2.67571e-08,0.742574,0.00186746,1.38697e-06,-5.36424e-09,0.744443,0.00187022,1.37087e-06,-5.30023e-09,0.746315,0.00187295,1.35497e-06,2.65653e-08,0.748189,0.00187574,1.43467e-06,-4.13564e-08,0.750066,0.00187848,1.3106e-06,1.9651e-08,0.751946,0.00188116,1.36955e-06,2.23572e-08,0.753828,0.00188397,1.43663e-06,-4.9475e-08,0.755714,0.00188669,1.2882e-06,5.63335e-08,0.757602,0.00188944,1.4572e-06,-5.66499e-08,0.759493,0.00189218,1.28725e-06,5.10567e-08,0.761386,0.00189491,1.44042e-06,-2.83677e-08,0.763283,0.00189771,1.35532e-06,2.80962e-09,0.765182,0.00190042,1.36375e-06,1.71293e-08,0.767083,0.0019032,1.41513e-06,-1.17221e-08,0.768988,0.001906,1.37997e-06,-2.98453e-08,0.770895,0.00190867,1.29043e-06,7.14987e-08,0.772805,0.00191146,1.50493e-06,-7.73354e-08,0.774718,0.00191424,1.27292e-06,5.90292e-08,0.776634,0.00191697,1.45001e-06,-3.9572e-08,0.778552,0.00191975,1.33129e-06,3.9654e-08,0.780473,0.00192253,1.45026e-06,-5.94395e-08,0.782397,0.00192525,1.27194e-06,7.88945e-08,0.784324,0.00192803,1.50862e-06,-7.73249e-08,0.786253,0.00193082,1.27665e-06,5.15913e-08,0.788185,0.00193352,1.43142e-06,-9.83099e-09,0.79012,0.00193636,1.40193e-06,-1.22672e-08,0.792058,0.00193912,1.36513e-06,-7.05275e-10,0.793999,0.00194185,1.36301e-06,1.50883e-08,0.795942,0.00194462,1.40828e-06,-4.33147e-11,0.797888,0.00194744,1.40815e-06,-1.49151e-08,0.799837,0.00195021,1.3634e-06,9.93244e-11,0.801788,0.00195294,1.3637e-06,1.45179e-08,0.803743,0.00195571,1.40725e-06,1.43363e-09,0.8057,0.00195853,1.41155e-06,-2.02525e-08,0.80766,0.00196129,1.35079e-06,1.99718e-08,0.809622,0.00196405,1.41071e-06,-3.01649e-11,0.811588,0.00196687,1.41062e-06,-1.9851e-08,0.813556,0.00196964,1.35107e-06,1.98296e-08,0.815527,0.0019724,1.41056e-06,1.37485e-10,0.817501,0.00197522,1.41097e-06,-2.03796e-08,0.819477,0.00197798,1.34983e-06,2.17763e-08,0.821457,0.00198074,1.41516e-06,-7.12085e-09,0.823439,0.00198355,1.3938e-06,6.70707e-09,0.825424,0.00198636,1.41392e-06,-1.97074e-08,0.827412,0.00198913,1.35479e-06,1.25179e-08,0.829402,0.00199188,1.39235e-06,2.92405e-08,0.831396,0.00199475,1.48007e-06,-6.98755e-08,0.833392,0.0019975,1.27044e-06,7.14477e-08,0.835391,0.00200026,1.48479e-06,-3.71014e-08,0.837392,0.00200311,1.37348e-06,1.73533e-08,0.839397,0.00200591,1.42554e-06,-3.23118e-08,0.841404,0.00200867,1.32861e-06,5.2289e-08,0.843414,0.00201148,1.48547e-06,-5.76348e-08,0.845427,0.00201428,1.31257e-06,5.9041e-08,0.847443,0.00201708,1.48969e-06,-5.93197e-08,0.849461,0.00201988,1.31173e-06,5.90289e-08,0.851482,0.00202268,1.48882e-06,-5.75864e-08,0.853507,0.00202549,1.31606e-06,5.21075e-08,0.855533,0.00202828,1.47238e-06,-3.16344e-08,0.857563,0.00203113,1.37748e-06,1.48257e-08,0.859596,0.00203393,1.42196e-06,-2.76684e-08,0.861631,0.00203669,1.33895e-06,3.62433e-08,0.863669,0.00203947,1.44768e-06,1.90463e-09,0.86571,0.00204237,1.45339e-06,-4.38617e-08,0.867754,0.00204515,1.32181e-06,5.43328e-08,0.8698,0.00204796,1.48481e-06,-5.42603e-08,0.87185,0.00205076,1.32203e-06,4.34989e-08,0.873902,0.00205354,1.45252e-06,-5.26029e-10,0.875957,0.00205644,1.45095e-06,-4.13949e-08,0.878015,0.00205922,1.32676e-06,4.68962e-08,0.880075,0.00206201,1.46745e-06,-2.69807e-08,0.882139,0.00206487,1.38651e-06,1.42181e-09,0.884205,0.00206764,1.39077e-06,2.12935e-08,0.886274,0.00207049,1.45465e-06,-2.69912e-08,0.888346,0.00207332,1.37368e-06,2.70664e-08,0.890421,0.00207615,1.45488e-06,-2.16698e-08,0.892498,0.00207899,1.38987e-06,8.14756e-12,0.894579,0.00208177,1.38989e-06,2.16371e-08,0.896662,0.00208462,1.45481e-06,-2.6952e-08,0.898748,0.00208744,1.37395e-06,2.65663e-08,0.900837,0.00209027,1.45365e-06,-1.97084e-08,0.902928,0.00209312,1.39452e-06,-7.33731e-09,0.905023,0.00209589,1.37251e-06,4.90578e-08,0.90712,0.00209878,1.51968e-06,-6.96845e-08,0.90922,0.00210161,1.31063e-06,5.08664e-08,0.911323,0.00210438,1.46323e-06,-1.45717e-08,0.913429,0.00210727,1.41952e-06,7.42038e-09,0.915538,0.00211013,1.44178e-06,-1.51097e-08,0.917649,0.00211297,1.39645e-06,-6.58618e-09,0.919764,0.00211574,1.37669e-06,4.14545e-08,0.921881,0.00211862,1.50105e-06,-4.00222e-08,0.924001,0.0021215,1.38099e-06,-5.7518e-10,0.926124,0.00212426,1.37926e-06,4.23229e-08,0.92825,0.00212714,1.50623e-06,-4.9507e-08,0.930378,0.00213001,1.35771e-06,3.64958e-08,0.93251,0.00213283,1.4672e-06,-3.68713e-08,0.934644,0.00213566,1.35658e-06,5.13848e-08,0.936781,0.00213852,1.51074e-06,-4.94585e-08,0.938921,0.0021414,1.36236e-06,2.72399e-08,0.941064,0.0021442,1.44408e-06,1.0372e-10,0.943209,0.00214709,1.44439e-06,-2.76547e-08,0.945358,0.0021499,1.36143e-06,5.09106e-08,0.947509,0.00215277,1.51416e-06,-5.67784e-08,0.949663,0.00215563,1.34382e-06,5.69935e-08,0.95182,0.00215849,1.5148e-06,-5.19861e-08,0.95398,0.00216136,1.35885e-06,3.17417e-08,0.956143,0.00216418,1.45407e-06,-1.53758e-08,0.958309,0.00216704,1.40794e-06,2.97615e-08,0.960477,0.00216994,1.49723e-06,-4.40657e-08,0.962649,0.00217281,1.36503e-06,2.72919e-08,0.964823,0.00217562,1.44691e-06,-5.49729e-09,0.967,0.0021785,1.43041e-06,-5.30273e-09,0.96918,0.00218134,1.41451e-06,2.67084e-08,0.971363,0.00218425,1.49463e-06,-4.19265e-08,0.973548,0.00218711,1.36885e-06,2.17881e-08,0.975737,0.00218992,1.43422e-06,1.43789e-08,0.977928,0.00219283,1.47735e-06,-1.96989e-08,0.980122,0.00219572,1.41826e-06,4.81221e-09,0.98232,0.00219857,1.43269e-06,4.50048e-10,0.98452,0.00220144,1.43404e-06,-6.61237e-09,0.986722,0.00220429,1.41421e-06,2.59993e-08,0.988928,0.0022072,1.4922e-06,-3.77803e-08,0.991137,0.00221007,1.37886e-06,5.9127e-09,0.993348,0.00221284,1.3966e-06,1.33339e-07,0.995563,0.00221604,1.79662e-06,-5.98872e-07,0.99778,0.00222015,0.,0.}; + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void RGB2LabConvert_f(const T& src, D& dst) + { + const float _1_3 = 1.0f / 3.0f; + const float _a = 16.0f / 116.0f; + + float B = blueIdx == 0 ? src.x : src.z; + float G = src.y; + float R = blueIdx == 0 ? src.z : src.x; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + } + + float X = B * 0.189828f + G * 0.376219f + R * 0.433953f; + float Y = B * 0.072169f + G * 0.715160f + R * 0.212671f; + float Z = B * 0.872766f + G * 0.109477f + R * 0.017758f; + + float FX = X > 0.008856f ? ::powf(X, _1_3) : (7.787f * X + _a); + float FY = Y > 0.008856f ? ::powf(Y, _1_3) : (7.787f * Y + _a); + float FZ = Z > 0.008856f ? ::powf(Z, _1_3) : (7.787f * Z + _a); + + float L = Y > 0.008856f ? (116.f * FY - 16.f) : (903.3f * Y); + float a = 500.f * (FX - FY); + float b = 200.f * (FY - FZ); + + dst.x = L; + dst.y = a; + dst.z = b; + } + + template <typename T, int scn, int dcn, bool srgb, int blueIdx> struct RGB2Lab; + template <int scn, int dcn, bool srgb, int blueIdx> + struct RGB2Lab<uchar, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<uchar, scn>::vec_type, typename TypeVec<uchar, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<uchar, dcn>::vec_type operator ()(const typename TypeVec<uchar, scn>::vec_type& src) const + { + typename TypeVec<uchar, dcn>::vec_type dst; + + RGB2LabConvert_b<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Lab() {} + __host__ __device__ __forceinline__ RGB2Lab(const RGB2Lab&) {} + }; + template <int scn, int dcn, bool srgb, int blueIdx> + struct RGB2Lab<float, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<float, scn>::vec_type, typename TypeVec<float, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<float, dcn>::vec_type operator ()(const typename TypeVec<float, scn>::vec_type& src) const + { + typename TypeVec<float, dcn>::vec_type dst; + + RGB2LabConvert_f<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Lab() {} + __host__ __device__ __forceinline__ RGB2Lab(const RGB2Lab&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2Lab<T, scn, dcn, srgb, blueIdx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_sRGBInvGammaTab[] = {0,0.0126255,0.,-8.33961e-06,0.0126172,0.0126005,-2.50188e-05,4.1698e-05,0.0252344,0.0126756,0.000100075,-0.000158451,0.0378516,0.0124004,-0.000375277,-0.000207393,0.0496693,0.0110276,-0.000997456,0.00016837,0.0598678,0.00953783,-0.000492346,2.07235e-05,0.068934,0.00861531,-0.000430176,3.62876e-05,0.0771554,0.00786382,-0.000321313,1.87625e-05,0.0847167,0.00727748,-0.000265025,1.53594e-05,0.0917445,0.00679351,-0.000218947,1.10545e-05,0.0983301,0.00638877,-0.000185784,8.66984e-06,0.104542,0.00604322,-0.000159774,6.82996e-06,0.110432,0.00574416,-0.000139284,5.51008e-06,0.116042,0.00548212,-0.000122754,4.52322e-06,0.121406,0.00525018,-0.000109184,3.75557e-06,0.126551,0.00504308,-9.79177e-05,3.17134e-06,0.131499,0.00485676,-8.84037e-05,2.68469e-06,0.13627,0.004688,-8.03496e-05,2.31725e-06,0.14088,0.00453426,-7.33978e-05,2.00868e-06,0.145343,0.00439349,-6.73718e-05,1.74775e-06,0.149671,0.00426399,-6.21286e-05,1.53547e-06,0.153875,0.00414434,-5.75222e-05,1.364e-06,0.157963,0.00403338,-5.34301e-05,1.20416e-06,0.161944,0.00393014,-4.98177e-05,1.09114e-06,0.165825,0.00383377,-4.65443e-05,9.57987e-07,0.169613,0.00374356,-4.36703e-05,8.88359e-07,0.173314,0.00365888,-4.10052e-05,7.7849e-07,0.176933,0.00357921,-3.86697e-05,7.36254e-07,0.180474,0.00350408,-3.6461e-05,6.42534e-07,0.183942,0.00343308,-3.45334e-05,6.12614e-07,0.187342,0.00336586,-3.26955e-05,5.42894e-07,0.190675,0.00330209,-3.10669e-05,5.08967e-07,0.193947,0.00324149,-2.954e-05,4.75977e-07,0.197159,0.00318383,-2.8112e-05,4.18343e-07,0.200315,0.00312887,-2.6857e-05,4.13651e-07,0.203418,0.00307639,-2.5616e-05,3.70847e-07,0.206469,0.00302627,-2.45035e-05,3.3813e-07,0.209471,0.00297828,-2.34891e-05,3.32999e-07,0.212426,0.0029323,-2.24901e-05,2.96826e-07,0.215336,0.00288821,-2.15996e-05,2.82736e-07,0.218203,0.00284586,-2.07514e-05,2.70961e-07,0.221029,0.00280517,-1.99385e-05,2.42744e-07,0.223814,0.00276602,-1.92103e-05,2.33277e-07,0.226561,0.0027283,-1.85105e-05,2.2486e-07,0.229271,0.00269195,-1.78359e-05,2.08383e-07,0.231945,0.00265691,-1.72108e-05,1.93305e-07,0.234585,0.00262307,-1.66308e-05,1.80687e-07,0.237192,0.00259035,-1.60888e-05,1.86632e-07,0.239766,0.00255873,-1.55289e-05,1.60569e-07,0.24231,0.00252815,-1.50472e-05,1.54566e-07,0.244823,0.00249852,-1.45835e-05,1.59939e-07,0.247307,0.00246983,-1.41037e-05,1.29549e-07,0.249763,0.00244202,-1.3715e-05,1.41429e-07,0.252191,0.00241501,-1.32907e-05,1.39198e-07,0.254593,0.00238885,-1.28731e-05,1.06444e-07,0.256969,0.00236342,-1.25538e-05,1.2048e-07,0.25932,0.00233867,-1.21924e-05,1.26892e-07,0.261647,0.00231467,-1.18117e-05,8.72084e-08,0.26395,0.00229131,-1.15501e-05,1.20323e-07,0.26623,0.00226857,-1.11891e-05,8.71514e-08,0.268487,0.00224645,-1.09276e-05,9.73165e-08,0.270723,0.00222489,-1.06357e-05,8.98259e-08,0.272937,0.00220389,-1.03662e-05,7.98218e-08,0.275131,0.00218339,-1.01267e-05,9.75254e-08,0.277304,0.00216343,-9.83416e-06,6.65195e-08,0.279458,0.00214396,-9.63461e-06,8.34313e-08,0.281592,0.00212494,-9.38431e-06,7.65919e-08,0.283708,0.00210641,-9.15454e-06,5.7236e-08,0.285805,0.00208827,-8.98283e-06,8.18939e-08,0.287885,0.00207055,-8.73715e-06,6.2224e-08,0.289946,0.00205326,-8.55047e-06,5.66388e-08,0.291991,0.00203633,-8.38056e-06,6.88491e-08,0.294019,0.00201978,-8.17401e-06,5.53955e-08,0.296031,0.00200359,-8.00782e-06,6.71971e-08,0.298027,0.00198778,-7.80623e-06,3.34439e-08,0.300007,0.00197227,-7.7059e-06,6.7248e-08,0.301971,0.00195706,-7.50416e-06,5.51915e-08,0.303921,0.00194221,-7.33858e-06,3.98124e-08,0.305856,0.00192766,-7.21915e-06,5.37795e-08,0.307776,0.00191338,-7.05781e-06,4.30919e-08,0.309683,0.00189939,-6.92853e-06,4.20744e-08,0.311575,0.00188566,-6.80231e-06,5.68321e-08,0.313454,0.00187223,-6.63181e-06,2.86195e-08,0.31532,0.00185905,-6.54595e-06,3.73075e-08,0.317172,0.00184607,-6.43403e-06,6.05684e-08,0.319012,0.00183338,-6.25233e-06,1.84426e-08,0.320839,0.00182094,-6.197e-06,4.44757e-08,0.322654,0.00180867,-6.06357e-06,4.20729e-08,0.324456,0.00179667,-5.93735e-06,2.56511e-08,0.326247,0.00178488,-5.8604e-06,3.41368e-08,0.328026,0.00177326,-5.75799e-06,4.64177e-08,0.329794,0.00176188,-5.61874e-06,1.86107e-08,0.33155,0.0017507,-5.5629e-06,2.81511e-08,0.333295,0.00173966,-5.47845e-06,4.75987e-08,0.335029,0.00172884,-5.33565e-06,1.98726e-08,0.336753,0.00171823,-5.27604e-06,2.19226e-08,0.338466,0.00170775,-5.21027e-06,4.14483e-08,0.340169,0.00169745,-5.08592e-06,2.09017e-08,0.341861,0.00168734,-5.02322e-06,2.39561e-08,0.343543,0.00167737,-4.95135e-06,3.22852e-08,0.345216,0.00166756,-4.85449e-06,2.57173e-08,0.346878,0.00165793,-4.77734e-06,1.38569e-08,0.348532,0.00164841,-4.73577e-06,3.80634e-08,0.350175,0.00163906,-4.62158e-06,1.27043e-08,0.35181,0.00162985,-4.58347e-06,3.03279e-08,0.353435,0.00162078,-4.49249e-06,1.49961e-08,0.355051,0.00161184,-4.4475e-06,2.88977e-08,0.356659,0.00160303,-4.3608e-06,1.84241e-08,0.358257,0.00159436,-4.30553e-06,1.6616e-08,0.359848,0.0015858,-4.25568e-06,3.43218e-08,0.361429,0.00157739,-4.15272e-06,-4.89172e-09,0.363002,0.00156907,-4.16739e-06,4.48498e-08,0.364567,0.00156087,-4.03284e-06,4.30676e-09,0.366124,0.00155282,-4.01992e-06,2.73303e-08,0.367673,0.00154486,-3.93793e-06,5.58036e-09,0.369214,0.001537,-3.92119e-06,3.97554e-08,0.370747,0.00152928,-3.80193e-06,-1.55904e-08,0.372272,0.00152163,-3.8487e-06,5.24081e-08,0.37379,0.00151409,-3.69147e-06,-1.52272e-08,0.375301,0.00150666,-3.73715e-06,3.83028e-08,0.376804,0.0014993,-3.62225e-06,1.10278e-08,0.378299,0.00149209,-3.58916e-06,6.99326e-09,0.379788,0.00148493,-3.56818e-06,2.06038e-08,0.381269,0.00147786,-3.50637e-06,2.98009e-08,0.382744,0.00147093,-3.41697e-06,-2.05978e-08,0.384211,0.00146404,-3.47876e-06,5.25899e-08,0.385672,0.00145724,-3.32099e-06,-1.09471e-08,0.387126,0.00145056,-3.35383e-06,2.10009e-08,0.388573,0.00144392,-3.29083e-06,1.63501e-08,0.390014,0.00143739,-3.24178e-06,3.00641e-09,0.391448,0.00143091,-3.23276e-06,3.12282e-08,0.392875,0.00142454,-3.13908e-06,-8.70932e-09,0.394297,0.00141824,-3.16521e-06,3.34114e-08,0.395712,0.00141201,-3.06497e-06,-5.72754e-09,0.397121,0.00140586,-3.08215e-06,1.9301e-08,0.398524,0.00139975,-3.02425e-06,1.7931e-08,0.39992,0.00139376,-2.97046e-06,-1.61822e-09,0.401311,0.00138781,-2.97531e-06,1.83442e-08,0.402696,0.00138192,-2.92028e-06,1.76485e-08,0.404075,0.00137613,-2.86733e-06,4.68617e-10,0.405448,0.00137039,-2.86593e-06,1.02794e-08,0.406816,0.00136469,-2.83509e-06,1.80179e-08,0.408178,0.00135908,-2.78104e-06,7.05594e-09,0.409534,0.00135354,-2.75987e-06,1.33633e-08,0.410885,0.00134806,-2.71978e-06,-9.04568e-10,0.41223,0.00134261,-2.72249e-06,2.0057e-08,0.41357,0.00133723,-2.66232e-06,1.00841e-08,0.414905,0.00133194,-2.63207e-06,-7.88835e-10,0.416234,0.00132667,-2.63444e-06,2.28734e-08,0.417558,0.00132147,-2.56582e-06,-1.29785e-09,0.418877,0.00131633,-2.56971e-06,1.21205e-08,0.420191,0.00131123,-2.53335e-06,1.24202e-08,0.421499,0.0013062,-2.49609e-06,-2.19681e-09,0.422803,0.0013012,-2.50268e-06,2.61696e-08,0.424102,0.00129628,-2.42417e-06,-1.30747e-08,0.425396,0.00129139,-2.46339e-06,2.6129e-08,0.426685,0.00128654,-2.38501e-06,-2.03454e-09,0.427969,0.00128176,-2.39111e-06,1.18115e-08,0.429248,0.00127702,-2.35567e-06,1.43932e-08,0.430523,0.00127235,-2.31249e-06,-9.77965e-09,0.431793,0.00126769,-2.34183e-06,2.47253e-08,0.433058,0.00126308,-2.26766e-06,2.85278e-10,0.434319,0.00125855,-2.2668e-06,3.93614e-09,0.435575,0.00125403,-2.25499e-06,1.37722e-08,0.436827,0.00124956,-2.21368e-06,5.79803e-10,0.438074,0.00124513,-2.21194e-06,1.37112e-08,0.439317,0.00124075,-2.1708e-06,4.17973e-09,0.440556,0.00123642,-2.15826e-06,-6.27703e-10,0.44179,0.0012321,-2.16015e-06,2.81332e-08,0.44302,0.00122787,-2.07575e-06,-2.24985e-08,0.444246,0.00122365,-2.14324e-06,3.20586e-08,0.445467,0.00121946,-2.04707e-06,-1.6329e-08,0.446685,0.00121532,-2.09605e-06,3.32573e-08,0.447898,0.00121122,-1.99628e-06,-2.72927e-08,0.449107,0.00120715,-2.07816e-06,4.6111e-08,0.450312,0.00120313,-1.93983e-06,-3.79416e-08,0.451514,0.00119914,-2.05365e-06,4.60507e-08,0.452711,0.00119517,-1.9155e-06,-2.7052e-08,0.453904,0.00119126,-1.99666e-06,3.23551e-08,0.455093,0.00118736,-1.89959e-06,-1.29613e-08,0.456279,0.00118352,-1.93848e-06,1.94905e-08,0.45746,0.0011797,-1.88e-06,-5.39588e-09,0.458638,0.00117593,-1.89619e-06,2.09282e-09,0.459812,0.00117214,-1.88991e-06,2.68267e-08,0.460982,0.00116844,-1.80943e-06,-1.99925e-08,0.462149,0.00116476,-1.86941e-06,2.3341e-08,0.463312,0.00116109,-1.79939e-06,-1.37674e-08,0.464471,0.00115745,-1.84069e-06,3.17287e-08,0.465627,0.00115387,-1.7455e-06,-2.37407e-08,0.466779,0.00115031,-1.81673e-06,3.34315e-08,0.467927,0.00114677,-1.71643e-06,-2.05786e-08,0.469073,0.00114328,-1.77817e-06,1.90802e-08,0.470214,0.00113978,-1.72093e-06,3.86247e-09,0.471352,0.00113635,-1.70934e-06,-4.72759e-09,0.472487,0.00113292,-1.72352e-06,1.50478e-08,0.473618,0.00112951,-1.67838e-06,4.14108e-09,0.474746,0.00112617,-1.66595e-06,-1.80986e-09,0.47587,0.00112283,-1.67138e-06,3.09816e-09,0.476991,0.0011195,-1.66209e-06,1.92198e-08,0.478109,0.00111623,-1.60443e-06,-2.03726e-08,0.479224,0.00111296,-1.66555e-06,3.2468e-08,0.480335,0.00110973,-1.56814e-06,-2.00922e-08,0.481443,0.00110653,-1.62842e-06,1.80983e-08,0.482548,0.00110333,-1.57413e-06,7.30362e-09,0.48365,0.0011002,-1.55221e-06,-1.75107e-08,0.484749,0.00109705,-1.60475e-06,3.29373e-08,0.485844,0.00109393,-1.50594e-06,-2.48315e-08,0.486937,0.00109085,-1.58043e-06,3.65865e-08,0.488026,0.0010878,-1.47067e-06,-3.21078e-08,0.489112,0.00108476,-1.56699e-06,3.22397e-08,0.490195,0.00108172,-1.47027e-06,-7.44391e-09,0.491276,0.00107876,-1.49261e-06,-2.46428e-09,0.492353,0.00107577,-1.5e-06,1.73011e-08,0.493427,0.00107282,-1.4481e-06,-7.13552e-09,0.494499,0.0010699,-1.4695e-06,1.1241e-08,0.495567,0.001067,-1.43578e-06,-8.02637e-09,0.496633,0.0010641,-1.45986e-06,2.08645e-08,0.497695,0.00106124,-1.39726e-06,-1.58271e-08,0.498755,0.0010584,-1.44475e-06,1.26415e-08,0.499812,0.00105555,-1.40682e-06,2.48655e-08,0.500866,0.00105281,-1.33222e-06,-5.24988e-08,0.501918,0.00104999,-1.48972e-06,6.59206e-08,0.502966,0.00104721,-1.29196e-06,-3.237e-08,0.504012,0.00104453,-1.38907e-06,3.95479e-09,0.505055,0.00104176,-1.3772e-06,1.65509e-08,0.506096,0.00103905,-1.32755e-06,-1.05539e-08,0.507133,0.00103637,-1.35921e-06,2.56648e-08,0.508168,0.00103373,-1.28222e-06,-3.25007e-08,0.509201,0.00103106,-1.37972e-06,4.47336e-08,0.51023,0.00102844,-1.24552e-06,-2.72245e-08,0.511258,0.00102587,-1.32719e-06,4.55952e-09,0.512282,0.00102323,-1.31352e-06,8.98645e-09,0.513304,0.00102063,-1.28656e-06,1.90992e-08,0.514323,0.00101811,-1.22926e-06,-2.57786e-08,0.51534,0.00101557,-1.30659e-06,2.44104e-08,0.516355,0.00101303,-1.23336e-06,-1.22581e-08,0.517366,0.00101053,-1.27014e-06,2.4622e-08,0.518376,0.00100806,-1.19627e-06,-2.66253e-08,0.519383,0.00100559,-1.27615e-06,2.22744e-08,0.520387,0.00100311,-1.20932e-06,-2.8679e-09,0.521389,0.00100068,-1.21793e-06,-1.08029e-08,0.522388,0.000998211,-1.25034e-06,4.60795e-08,0.523385,0.000995849,-1.1121e-06,-5.4306e-08,0.52438,0.000993462,-1.27502e-06,5.19354e-08,0.525372,0.000991067,-1.11921e-06,-3.42262e-08,0.526362,0.000988726,-1.22189e-06,2.53646e-08,0.52735,0.000986359,-1.14579e-06,-7.62782e-09,0.528335,0.000984044,-1.16868e-06,5.14668e-09,0.529318,0.000981722,-1.15324e-06,-1.29589e-08,0.530298,0.000979377,-1.19211e-06,4.66888e-08,0.531276,0.000977133,-1.05205e-06,-5.45868e-08,0.532252,0.000974865,-1.21581e-06,5.24495e-08,0.533226,0.000972591,-1.05846e-06,-3.60019e-08,0.534198,0.000970366,-1.16647e-06,3.19537e-08,0.535167,0.000968129,-1.07061e-06,-3.2208e-08,0.536134,0.000965891,-1.16723e-06,3.72738e-08,0.537099,0.000963668,-1.05541e-06,2.32205e-09,0.538061,0.000961564,-1.04844e-06,-4.65618e-08,0.539022,0.000959328,-1.18813e-06,6.47159e-08,0.53998,0.000957146,-9.93979e-07,-3.3488e-08,0.540936,0.000955057,-1.09444e-06,9.63166e-09,0.54189,0.000952897,-1.06555e-06,-5.03871e-09,0.542842,0.000950751,-1.08066e-06,1.05232e-08,0.543792,0.000948621,-1.04909e-06,2.25503e-08,0.544739,0.000946591,-9.81444e-07,-4.11195e-08,0.545685,0.000944504,-1.1048e-06,2.27182e-08,0.546628,0.000942363,-1.03665e-06,9.85146e-09,0.54757,0.000940319,-1.00709e-06,-2.51938e-09,0.548509,0.000938297,-1.01465e-06,2.25858e-10,0.549446,0.000936269,-1.01397e-06,1.61598e-09,0.550381,0.000934246,-1.00913e-06,-6.68983e-09,0.551315,0.000932207,-1.0292e-06,2.51434e-08,0.552246,0.000930224,-9.53765e-07,-3.42793e-08,0.553175,0.000928214,-1.0566e-06,5.23688e-08,0.554102,0.000926258,-8.99497e-07,-5.59865e-08,0.555028,0.000924291,-1.06746e-06,5.23679e-08,0.555951,0.000922313,-9.10352e-07,-3.42763e-08,0.556872,0.00092039,-1.01318e-06,2.51326e-08,0.557792,0.000918439,-9.37783e-07,-6.64954e-09,0.558709,0.000916543,-9.57732e-07,1.46554e-09,0.559625,0.000914632,-9.53335e-07,7.87281e-10,0.560538,0.000912728,-9.50973e-07,-4.61466e-09,0.56145,0.000910812,-9.64817e-07,1.76713e-08,0.56236,0.000908935,-9.11804e-07,-6.46564e-09,0.563268,0.000907092,-9.312e-07,8.19121e-09,0.564174,0.000905255,-9.06627e-07,-2.62992e-08,0.565078,0.000903362,-9.85524e-07,3.74007e-08,0.565981,0.000901504,-8.73322e-07,-4.0942e-09,0.566882,0.000899745,-8.85605e-07,-2.1024e-08,0.56778,0.00089791,-9.48677e-07,2.85854e-08,0.568677,0.000896099,-8.62921e-07,-3.3713e-08,0.569573,0.000894272,-9.64059e-07,4.6662e-08,0.570466,0.000892484,-8.24073e-07,-3.37258e-08,0.571358,0.000890734,-9.25251e-07,2.86365e-08,0.572247,0.00088897,-8.39341e-07,-2.12155e-08,0.573135,0.000887227,-9.02988e-07,-3.37913e-09,0.574022,0.000885411,-9.13125e-07,3.47319e-08,0.574906,0.000883689,-8.08929e-07,-1.63394e-08,0.575789,0.000882022,-8.57947e-07,-2.8979e-08,0.57667,0.00088022,-9.44885e-07,7.26509e-08,0.57755,0.000878548,-7.26932e-07,-8.28106e-08,0.578427,0.000876845,-9.75364e-07,7.97774e-08,0.579303,0.000875134,-7.36032e-07,-5.74849e-08,0.580178,0.00087349,-9.08486e-07,3.09529e-08,0.58105,0.000871765,-8.15628e-07,-6.72206e-09,0.581921,0.000870114,-8.35794e-07,-4.06451e-09,0.582791,0.00086843,-8.47987e-07,2.29799e-08,0.583658,0.000866803,-7.79048e-07,-2.82503e-08,0.584524,0.00086516,-8.63799e-07,3.04167e-08,0.585388,0.000863524,-7.72548e-07,-3.38119e-08,0.586251,0.000861877,-8.73984e-07,4.52264e-08,0.587112,0.000860265,-7.38305e-07,-2.78842e-08,0.587972,0.000858705,-8.21958e-07,6.70567e-09,0.58883,0.000857081,-8.01841e-07,1.06161e-09,0.589686,0.000855481,-7.98656e-07,-1.09521e-08,0.590541,0.00085385,-8.31512e-07,4.27468e-08,0.591394,0.000852316,-7.03272e-07,-4.08257e-08,0.592245,0.000850787,-8.25749e-07,1.34677e-09,0.593095,0.000849139,-8.21709e-07,3.54387e-08,0.593944,0.000847602,-7.15393e-07,-2.38924e-08,0.59479,0.0008461,-7.8707e-07,5.26143e-10,0.595636,0.000844527,-7.85491e-07,2.17879e-08,0.596479,0.000843021,-7.20127e-07,-2.80733e-08,0.597322,0.000841497,-8.04347e-07,3.09005e-08,0.598162,0.000839981,-7.11646e-07,-3.5924e-08,0.599002,0.00083845,-8.19418e-07,5.3191e-08,0.599839,0.000836971,-6.59845e-07,-5.76307e-08,0.600676,0.000835478,-8.32737e-07,5.81227e-08,0.60151,0.000833987,-6.58369e-07,-5.56507e-08,0.602344,0.000832503,-8.25321e-07,4.52706e-08,0.603175,0.000830988,-6.89509e-07,-6.22236e-09,0.604006,0.000829591,-7.08176e-07,-2.03811e-08,0.604834,0.000828113,-7.6932e-07,2.8142e-08,0.605662,0.000826659,-6.84894e-07,-3.25822e-08,0.606488,0.000825191,-7.8264e-07,4.25823e-08,0.607312,0.000823754,-6.54893e-07,-1.85376e-08,0.608135,0.000822389,-7.10506e-07,-2.80365e-08,0.608957,0.000820883,-7.94616e-07,7.1079e-08,0.609777,0.000819507,-5.81379e-07,-7.74655e-08,0.610596,0.000818112,-8.13775e-07,5.9969e-08,0.611413,0.000816665,-6.33868e-07,-4.32013e-08,0.612229,0.000815267,-7.63472e-07,5.32313e-08,0.613044,0.0008139,-6.03778e-07,-5.05148e-08,0.613857,0.000812541,-7.55323e-07,2.96187e-08,0.614669,0.000811119,-6.66466e-07,-8.35545e-09,0.615479,0.000809761,-6.91533e-07,3.80301e-09,0.616288,0.00080839,-6.80124e-07,-6.85666e-09,0.617096,0.000807009,-7.00694e-07,2.36237e-08,0.617903,0.000805678,-6.29822e-07,-2.80336e-08,0.618708,0.000804334,-7.13923e-07,2.8906e-08,0.619511,0.000802993,-6.27205e-07,-2.79859e-08,0.620314,0.000801655,-7.11163e-07,2.34329e-08,0.621114,0.000800303,-6.40864e-07,-6.14108e-09,0.621914,0.000799003,-6.59287e-07,1.13151e-09,0.622712,0.000797688,-6.55893e-07,1.61507e-09,0.62351,0.000796381,-6.51048e-07,-7.59186e-09,0.624305,0.000795056,-6.73823e-07,2.87524e-08,0.6251,0.000793794,-5.87566e-07,-4.7813e-08,0.625893,0.000792476,-7.31005e-07,4.32901e-08,0.626685,0.000791144,-6.01135e-07,-6.13814e-09,0.627475,0.000789923,-6.19549e-07,-1.87376e-08,0.628264,0.000788628,-6.75762e-07,2.14837e-08,0.629052,0.000787341,-6.11311e-07,-7.59265e-09,0.629839,0.000786095,-6.34089e-07,8.88692e-09,0.630625,0.000784854,-6.07428e-07,-2.7955e-08,0.631409,0.000783555,-6.91293e-07,4.33285e-08,0.632192,0.000782302,-5.61307e-07,-2.61497e-08,0.632973,0.000781101,-6.39757e-07,1.6658e-09,0.633754,0.000779827,-6.34759e-07,1.94866e-08,0.634533,0.000778616,-5.76299e-07,-2.00076e-08,0.635311,0.000777403,-6.36322e-07,9.39091e-10,0.636088,0.000776133,-6.33505e-07,1.62512e-08,0.636863,0.000774915,-5.84751e-07,-6.33937e-09,0.637638,0.000773726,-6.03769e-07,9.10609e-09,0.638411,0.000772546,-5.76451e-07,-3.00849e-08,0.639183,0.000771303,-6.66706e-07,5.1629e-08,0.639953,0.000770125,-5.11819e-07,-5.7222e-08,0.640723,0.000768929,-6.83485e-07,5.80497e-08,0.641491,0.000767736,-5.09336e-07,-5.57674e-08,0.642259,0.000766551,-6.76638e-07,4.58105e-08,0.643024,0.000765335,-5.39206e-07,-8.26541e-09,0.643789,0.000764231,-5.64002e-07,-1.27488e-08,0.644553,0.000763065,-6.02249e-07,-3.44168e-10,0.645315,0.00076186,-6.03281e-07,1.41254e-08,0.646077,0.000760695,-5.60905e-07,3.44727e-09,0.646837,0.000759584,-5.50563e-07,-2.79144e-08,0.647596,0.000758399,-6.34307e-07,4.86057e-08,0.648354,0.000757276,-4.88489e-07,-4.72989e-08,0.64911,0.000756158,-6.30386e-07,2.13807e-08,0.649866,0.000754961,-5.66244e-07,2.13808e-08,0.65062,0.000753893,-5.02102e-07,-4.7299e-08,0.651374,0.000752746,-6.43999e-07,4.86059e-08,0.652126,0.000751604,-4.98181e-07,-2.79154e-08,0.652877,0.000750524,-5.81927e-07,3.45089e-09,0.653627,0.000749371,-5.71575e-07,1.41119e-08,0.654376,0.00074827,-5.29239e-07,-2.93748e-10,0.655123,0.00074721,-5.3012e-07,-1.29368e-08,0.65587,0.000746111,-5.68931e-07,-7.56355e-09,0.656616,0.000744951,-5.91621e-07,4.3191e-08,0.65736,0.000743897,-4.62048e-07,-4.59911e-08,0.658103,0.000742835,-6.00022e-07,2.15642e-08,0.658846,0.0007417,-5.35329e-07,1.93389e-08,0.659587,0.000740687,-4.77312e-07,-3.93152e-08,0.660327,0.000739615,-5.95258e-07,1.87126e-08,0.661066,0.00073848,-5.3912e-07,2.40695e-08,0.661804,0.000737474,-4.66912e-07,-5.53859e-08,0.662541,0.000736374,-6.33069e-07,7.82648e-08,0.663277,0.000735343,-3.98275e-07,-7.88593e-08,0.664012,0.00073431,-6.34853e-07,5.83585e-08,0.664745,0.000733215,-4.59777e-07,-3.53656e-08,0.665478,0.000732189,-5.65874e-07,2.34994e-08,0.66621,0.000731128,-4.95376e-07,9.72743e-10,0.66694,0.00073014,-4.92458e-07,-2.73903e-08,0.66767,0.000729073,-5.74629e-07,4.89839e-08,0.668398,0.000728071,-4.27677e-07,-4.93359e-08,0.669126,0.000727068,-5.75685e-07,2.91504e-08,0.669853,0.000726004,-4.88234e-07,-7.66109e-09,0.670578,0.000725004,-5.11217e-07,1.49392e-09,0.671303,0.000723986,-5.06735e-07,1.68533e-09,0.672026,0.000722978,-5.01679e-07,-8.23525e-09,0.672749,0.00072195,-5.26385e-07,3.12556e-08,0.67347,0.000720991,-4.32618e-07,-5.71825e-08,0.674191,0.000719954,-6.04166e-07,7.8265e-08,0.67491,0.00071898,-3.69371e-07,-7.70634e-08,0.675628,0.00071801,-6.00561e-07,5.11747e-08,0.676346,0.000716963,-4.47037e-07,-8.42615e-09,0.677062,0.000716044,-4.72315e-07,-1.747e-08,0.677778,0.000715046,-5.24725e-07,1.87015e-08,0.678493,0.000714053,-4.68621e-07,2.26856e-09,0.679206,0.000713123,-4.61815e-07,-2.77758e-08,0.679919,0.000712116,-5.45142e-07,4.92298e-08,0.68063,0.000711173,-3.97453e-07,-4.99339e-08,0.681341,0.000710228,-5.47255e-07,3.12967e-08,0.682051,0.000709228,-4.53365e-07,-1.56481e-08,0.68276,0.000708274,-5.00309e-07,3.12958e-08,0.683467,0.000707367,-4.06422e-07,-4.99303e-08,0.684174,0.000706405,-5.56213e-07,4.9216e-08,0.68488,0.00070544,-4.08565e-07,-2.77245e-08,0.685585,0.00070454,-4.91738e-07,2.07748e-09,0.686289,0.000703562,-4.85506e-07,1.94146e-08,0.686992,0.00070265,-4.27262e-07,-2.01314e-08,0.687695,0.000701735,-4.87656e-07,1.50616e-09,0.688396,0.000700764,-4.83137e-07,1.41067e-08,0.689096,0.00069984,-4.40817e-07,1.67168e-09,0.689795,0.000698963,-4.35802e-07,-2.07934e-08,0.690494,0.000698029,-4.98182e-07,2.18972e-08,0.691192,0.000697099,-4.32491e-07,-7.19092e-09,0.691888,0.000696212,-4.54064e-07,6.86642e-09,0.692584,0.000695325,-4.33464e-07,-2.02747e-08,0.693279,0.000694397,-4.94288e-07,1.46279e-08,0.693973,0.000693452,-4.50405e-07,2.13678e-08,0.694666,0.000692616,-3.86301e-07,-4.04945e-08,0.695358,0.000691721,-5.07785e-07,2.14009e-08,0.696049,0.00069077,-4.43582e-07,1.44955e-08,0.69674,0.000689926,-4.00096e-07,-1.97783e-08,0.697429,0.000689067,-4.5943e-07,5.01296e-09,0.698118,0.000688163,-4.44392e-07,-2.73521e-10,0.698805,0.000687273,-4.45212e-07,-3.91893e-09,0.699492,0.000686371,-4.56969e-07,1.59493e-08,0.700178,0.000685505,-4.09121e-07,-2.73351e-10,0.700863,0.000684686,-4.09941e-07,-1.4856e-08,0.701548,0.000683822,-4.54509e-07,9.25979e-11,0.702231,0.000682913,-4.54231e-07,1.44855e-08,0.702913,0.000682048,-4.10775e-07,1.56992e-09,0.703595,0.000681231,-4.06065e-07,-2.07652e-08,0.704276,0.000680357,-4.68361e-07,2.18864e-08,0.704956,0.000679486,-4.02701e-07,-7.17595e-09,0.705635,0.000678659,-4.24229e-07,6.81748e-09,0.706313,0.000677831,-4.03777e-07,-2.0094e-08,0.70699,0.000676963,-4.64059e-07,1.39538e-08,0.707667,0.000676077,-4.22197e-07,2.38835e-08,0.708343,0.000675304,-3.50547e-07,-4.98831e-08,0.709018,0.000674453,-5.00196e-07,5.64395e-08,0.709692,0.000673622,-3.30878e-07,-5.66657e-08,0.710365,0.00067279,-5.00875e-07,5.1014e-08,0.711037,0.000671942,-3.47833e-07,-2.81809e-08,0.711709,0.000671161,-4.32376e-07,2.10513e-09,0.712379,0.000670303,-4.2606e-07,1.97604e-08,0.713049,0.00066951,-3.66779e-07,-2.15422e-08,0.713718,0.000668712,-4.31406e-07,6.8038e-09,0.714387,0.000667869,-4.10994e-07,-5.67295e-09,0.715054,0.00066703,-4.28013e-07,1.5888e-08,0.715721,0.000666222,-3.80349e-07,1.72576e-09,0.716387,0.000665467,-3.75172e-07,-2.27911e-08,0.717052,0.000664648,-4.43545e-07,2.9834e-08,0.717716,0.00066385,-3.54043e-07,-3.69401e-08,0.718379,0.000663031,-4.64864e-07,5.83219e-08,0.719042,0.000662277,-2.89898e-07,-7.71382e-08,0.719704,0.000661465,-5.21313e-07,7.14171e-08,0.720365,0.000660637,-3.07061e-07,-2.97161e-08,0.721025,0.000659934,-3.96209e-07,-1.21575e-08,0.721685,0.000659105,-4.32682e-07,1.87412e-08,0.722343,0.000658296,-3.76458e-07,-3.2029e-09,0.723001,0.000657533,-3.86067e-07,-5.9296e-09,0.723659,0.000656743,-4.03856e-07,2.69213e-08,0.724315,0.000656016,-3.23092e-07,-4.21511e-08,0.724971,0.000655244,-4.49545e-07,2.24737e-08,0.725625,0.000654412,-3.82124e-07,1.18611e-08,0.726279,0.000653683,-3.46541e-07,-1.03132e-08,0.726933,0.000652959,-3.7748e-07,-3.02128e-08,0.727585,0.000652114,-4.68119e-07,7.15597e-08,0.728237,0.000651392,-2.5344e-07,-7.72119e-08,0.728888,0.000650654,-4.85075e-07,5.8474e-08,0.729538,0.000649859,-3.09654e-07,-3.74746e-08,0.730188,0.000649127,-4.22077e-07,3.18197e-08,0.730837,0.000648379,-3.26618e-07,-3.01997e-08,0.731485,0.000647635,-4.17217e-07,2.93747e-08,0.732132,0.000646888,-3.29093e-07,-2.76943e-08,0.732778,0.000646147,-4.12176e-07,2.17979e-08,0.733424,0.000645388,-3.46783e-07,1.07292e-10,0.734069,0.000644695,-3.46461e-07,-2.22271e-08,0.734713,0.000643935,-4.13142e-07,2.91963e-08,0.735357,0.000643197,-3.25553e-07,-3.49536e-08,0.736,0.000642441,-4.30414e-07,5.10133e-08,0.736642,0.000641733,-2.77374e-07,-4.98904e-08,0.737283,0.000641028,-4.27045e-07,2.93392e-08,0.737924,0.000640262,-3.39028e-07,-7.86156e-09,0.738564,0.000639561,-3.62612e-07,2.10703e-09,0.739203,0.000638842,-3.56291e-07,-5.6653e-10,0.739842,0.000638128,-3.57991e-07,1.59086e-10,0.740479,0.000637412,-3.57513e-07,-6.98321e-11,0.741116,0.000636697,-3.57723e-07,1.20214e-10,0.741753,0.000635982,-3.57362e-07,-4.10987e-10,0.742388,0.000635266,-3.58595e-07,1.5237e-09,0.743023,0.000634553,-3.54024e-07,-5.68376e-09,0.743657,0.000633828,-3.71075e-07,2.12113e-08,0.744291,0.00063315,-3.07441e-07,-1.95569e-08,0.744924,0.000632476,-3.66112e-07,-2.58816e-09,0.745556,0.000631736,-3.73877e-07,2.99096e-08,0.746187,0.000631078,-2.84148e-07,-5.74454e-08,0.746818,0.000630337,-4.56484e-07,8.06629e-08,0.747448,0.000629666,-2.14496e-07,-8.63922e-08,0.748077,0.000628978,-4.73672e-07,8.60918e-08,0.748706,0.000628289,-2.15397e-07,-7.91613e-08,0.749334,0.000627621,-4.5288e-07,5.17393e-08,0.749961,0.00062687,-2.97663e-07,-8.58662e-09,0.750588,0.000626249,-3.23422e-07,-1.73928e-08,0.751214,0.00062555,-3.75601e-07,1.85532e-08,0.751839,0.000624855,-3.19941e-07,2.78479e-09,0.752463,0.000624223,-3.11587e-07,-2.96923e-08,0.753087,0.000623511,-4.00664e-07,5.63799e-08,0.75371,0.000622879,-2.31524e-07,-7.66179e-08,0.754333,0.000622186,-4.61378e-07,7.12778e-08,0.754955,0.000621477,-2.47545e-07,-2.96794e-08,0.755576,0.000620893,-3.36583e-07,-1.21648e-08,0.756196,0.000620183,-3.73077e-07,1.87339e-08,0.756816,0.000619493,-3.16875e-07,-3.16622e-09,0.757435,0.00061885,-3.26374e-07,-6.0691e-09,0.758054,0.000618179,-3.44581e-07,2.74426e-08,0.758672,0.000617572,-2.62254e-07,-4.40968e-08,0.759289,0.000616915,-3.94544e-07,2.97352e-08,0.759906,0.000616215,-3.05338e-07,-1.52393e-08,0.760522,0.000615559,-3.51056e-07,3.12221e-08,0.761137,0.000614951,-2.5739e-07,-5.00443e-08,0.761751,0.000614286,-4.07523e-07,4.9746e-08,0.762365,0.00061362,-2.58285e-07,-2.97303e-08,0.762979,0.000613014,-3.47476e-07,9.57079e-09,0.763591,0.000612348,-3.18764e-07,-8.55287e-09,0.764203,0.000611685,-3.44422e-07,2.46407e-08,0.764815,0.00061107,-2.705e-07,-3.04053e-08,0.765426,0.000610437,-3.61716e-07,3.73759e-08,0.766036,0.000609826,-2.49589e-07,-5.94935e-08,0.766645,0.000609149,-4.28069e-07,8.13889e-08,0.767254,0.000608537,-1.83902e-07,-8.72483e-08,0.767862,0.000607907,-4.45647e-07,8.87901e-08,0.76847,0.000607282,-1.79277e-07,-8.90983e-08,0.769077,0.000606656,-4.46572e-07,8.87892e-08,0.769683,0.000606029,-1.80204e-07,-8.72446e-08,0.770289,0.000605407,-4.41938e-07,8.13752e-08,0.770894,0.000604768,-1.97812e-07,-5.94423e-08,0.771498,0.000604194,-3.76139e-07,3.71848e-08,0.772102,0.000603553,-2.64585e-07,-2.96922e-08,0.772705,0.000602935,-3.53661e-07,2.19793e-08,0.773308,0.000602293,-2.87723e-07,1.37955e-09,0.77391,0.000601722,-2.83585e-07,-2.74976e-08,0.774512,0.000601072,-3.66077e-07,4.9006e-08,0.775112,0.000600487,-2.19059e-07,-4.93171e-08,0.775712,0.000599901,-3.67011e-07,2.90531e-08,0.776312,0.000599254,-2.79851e-07,-7.29081e-09,0.776911,0.000598673,-3.01724e-07,1.10077e-10,0.777509,0.00059807,-3.01393e-07,6.85053e-09,0.778107,0.000597487,-2.80842e-07,-2.75123e-08,0.778704,0.000596843,-3.63379e-07,4.35939e-08,0.779301,0.000596247,-2.32597e-07,-2.7654e-08,0.779897,0.000595699,-3.15559e-07,7.41741e-09,0.780492,0.00059509,-2.93307e-07,-2.01562e-09,0.781087,0.000594497,-2.99354e-07,6.45059e-10,0.781681,0.000593901,-2.97418e-07,-5.64635e-10,0.782275,0.000593304,-2.99112e-07,1.61347e-09,0.782868,0.000592711,-2.94272e-07,-5.88926e-09,0.78346,0.000592105,-3.1194e-07,2.19436e-08,0.784052,0.000591546,-2.46109e-07,-2.22805e-08,0.784643,0.000590987,-3.1295e-07,7.57368e-09,0.785234,0.000590384,-2.90229e-07,-8.01428e-09,0.785824,0.00058978,-3.14272e-07,2.44834e-08,0.786414,0.000589225,-2.40822e-07,-3.03148e-08,0.787003,0.000588652,-3.31766e-07,3.7171e-08,0.787591,0.0005881,-2.20253e-07,-5.87646e-08,0.788179,0.000587483,-3.96547e-07,7.86782e-08,0.788766,0.000586926,-1.60512e-07,-7.71342e-08,0.789353,0.000586374,-3.91915e-07,5.10444e-08,0.789939,0.000585743,-2.38782e-07,-7.83422e-09,0.790524,0.000585242,-2.62284e-07,-1.97076e-08,0.791109,0.000584658,-3.21407e-07,2.70598e-08,0.791693,0.000584097,-2.40228e-07,-2.89269e-08,0.792277,0.000583529,-3.27008e-07,2.90431e-08,0.792861,0.000582963,-2.39879e-07,-2.76409e-08,0.793443,0.0005824,-3.22802e-07,2.1916e-08,0.794025,0.00058182,-2.57054e-07,-4.18368e-10,0.794607,0.000581305,-2.58309e-07,-2.02425e-08,0.795188,0.000580727,-3.19036e-07,2.17838e-08,0.795768,0.000580155,-2.53685e-07,-7.28814e-09,0.796348,0.000579625,-2.75549e-07,7.36871e-09,0.796928,0.000579096,-2.53443e-07,-2.21867e-08,0.797506,0.000578523,-3.20003e-07,2.17736e-08,0.798085,0.000577948,-2.54683e-07,-5.30296e-09,0.798662,0.000577423,-2.70592e-07,-5.61698e-10,0.799239,0.00057688,-2.72277e-07,7.54977e-09,0.799816,0.000576358,-2.49627e-07,-2.96374e-08,0.800392,0.00057577,-3.38539e-07,5.1395e-08,0.800968,0.000575247,-1.84354e-07,-5.67335e-08,0.801543,0.000574708,-3.54555e-07,5.63297e-08,0.802117,0.000574168,-1.85566e-07,-4.93759e-08,0.802691,0.000573649,-3.33693e-07,2.19646e-08,0.803264,0.000573047,-2.678e-07,2.1122e-08,0.803837,0.000572575,-2.04433e-07,-4.68482e-08,0.804409,0.000572026,-3.44978e-07,4.70613e-08,0.804981,0.000571477,-2.03794e-07,-2.21877e-08,0.805552,0.000571003,-2.70357e-07,-1.79153e-08,0.806123,0.000570408,-3.24103e-07,3.42443e-08,0.806693,0.000569863,-2.2137e-07,1.47556e-10,0.807263,0.000569421,-2.20928e-07,-3.48345e-08,0.807832,0.000568874,-3.25431e-07,1.99812e-08,0.808401,0.000568283,-2.65487e-07,1.45143e-08,0.808969,0.000567796,-2.21945e-07,-1.84338e-08,0.809536,0.000567297,-2.77246e-07,-3.83608e-10,0.810103,0.000566741,-2.78397e-07,1.99683e-08,0.81067,0.000566244,-2.18492e-07,-1.98848e-08,0.811236,0.000565747,-2.78146e-07,-3.38976e-11,0.811801,0.000565191,-2.78248e-07,2.00204e-08,0.812366,0.000564695,-2.18187e-07,-2.04429e-08,0.812931,0.000564197,-2.79516e-07,2.1467e-09,0.813495,0.000563644,-2.73076e-07,1.18561e-08,0.814058,0.000563134,-2.37507e-07,1.00334e-08,0.814621,0.000562689,-2.07407e-07,-5.19898e-08,0.815183,0.000562118,-3.63376e-07,7.87163e-08,0.815745,0.000561627,-1.27227e-07,-8.40616e-08,0.816306,0.000561121,-3.79412e-07,7.87163e-08,0.816867,0.000560598,-1.43263e-07,-5.19898e-08,0.817428,0.000560156,-2.99233e-07,1.00335e-08,0.817988,0.000559587,-2.69132e-07,1.18559e-08,0.818547,0.000559085,-2.33564e-07,2.14764e-09,0.819106,0.000558624,-2.27122e-07,-2.04464e-08,0.819664,0.000558108,-2.88461e-07,2.00334e-08,0.820222,0.000557591,-2.28361e-07,-8.24277e-11,0.820779,0.000557135,-2.28608e-07,-1.97037e-08,0.821336,0.000556618,-2.87719e-07,1.92925e-08,0.821893,0.000556101,-2.29841e-07,2.13831e-09,0.822448,0.000555647,-2.23427e-07,-2.78458e-08,0.823004,0.000555117,-3.06964e-07,4.96402e-08,0.823559,0.000554652,-1.58043e-07,-5.15058e-08,0.824113,0.000554181,-3.12561e-07,3.71737e-08,0.824667,0.000553668,-2.0104e-07,-3.75844e-08,0.82522,0.000553153,-3.13793e-07,5.35592e-08,0.825773,0.000552686,-1.53115e-07,-5.74431e-08,0.826326,0.000552207,-3.25444e-07,5.7004e-08,0.826878,0.000551728,-1.54433e-07,-5.13635e-08,0.827429,0.000551265,-3.08523e-07,2.92406e-08,0.82798,0.000550735,-2.20801e-07,-5.99424e-09,0.828531,0.000550276,-2.38784e-07,-5.26363e-09,0.829081,0.000549782,-2.54575e-07,2.70488e-08,0.82963,0.000549354,-1.73429e-07,-4.33268e-08,0.83018,0.000548878,-3.03409e-07,2.7049e-08,0.830728,0.000548352,-2.22262e-07,-5.26461e-09,0.831276,0.000547892,-2.38056e-07,-5.99057e-09,0.831824,0.000547397,-2.56027e-07,2.92269e-08,0.832371,0.000546973,-1.68347e-07,-5.13125e-08,0.832918,0.000546482,-3.22284e-07,5.68139e-08,0.833464,0.000546008,-1.51843e-07,-5.67336e-08,0.83401,0.000545534,-3.22043e-07,5.09113e-08,0.834555,0.000545043,-1.6931e-07,-2.77022e-08,0.8351,0.000544621,-2.52416e-07,2.92924e-10,0.835644,0.000544117,-2.51537e-07,2.65305e-08,0.836188,0.000543694,-1.71946e-07,-4.68105e-08,0.836732,0.00054321,-3.12377e-07,4.15021e-08,0.837275,0.000542709,-1.87871e-07,1.13355e-11,0.837817,0.000542334,-1.87837e-07,-4.15474e-08,0.838359,0.000541833,-3.12479e-07,4.69691e-08,0.838901,0.000541349,-1.71572e-07,-2.71196e-08,0.839442,0.000540925,-2.52931e-07,1.90462e-09,0.839983,0.000540425,-2.47217e-07,1.95011e-08,0.840523,0.000539989,-1.88713e-07,-2.03045e-08,0.841063,0.00053955,-2.49627e-07,2.11216e-09,0.841602,0.000539057,-2.4329e-07,1.18558e-08,0.842141,0.000538606,-2.07723e-07,1.00691e-08,0.842679,0.000538221,-1.77516e-07,-5.21324e-08,0.843217,0.00053771,-3.33913e-07,7.92513e-08,0.843755,0.00053728,-9.6159e-08,-8.60587e-08,0.844292,0.000536829,-3.54335e-07,8.61696e-08,0.844828,0.000536379,-9.58263e-08,-7.98057e-08,0.845364,0.000535948,-3.35243e-07,5.42394e-08,0.8459,0.00053544,-1.72525e-07,-1.79426e-08,0.846435,0.000535041,-2.26353e-07,1.75308e-08,0.84697,0.000534641,-1.73761e-07,-5.21806e-08,0.847505,0.000534137,-3.30302e-07,7.19824e-08,0.848038,0.000533692,-1.14355e-07,-5.69349e-08,0.848572,0.000533293,-2.8516e-07,3.65479e-08,0.849105,0.000532832,-1.75516e-07,-2.96519e-08,0.849638,0.000532392,-2.64472e-07,2.2455e-08,0.85017,0.000531931,-1.97107e-07,-5.63451e-10,0.850702,0.000531535,-1.98797e-07,-2.02011e-08,0.851233,0.000531077,-2.59401e-07,2.17634e-08,0.851764,0.000530623,-1.94111e-07,-7.24794e-09,0.852294,0.000530213,-2.15854e-07,7.22832e-09,0.852824,0.000529803,-1.94169e-07,-2.16653e-08,0.853354,0.00052935,-2.59165e-07,1.98283e-08,0.853883,0.000528891,-1.9968e-07,1.95678e-09,0.854412,0.000528497,-1.9381e-07,-2.76554e-08,0.85494,0.000528027,-2.76776e-07,4.90603e-08,0.855468,0.00052762,-1.29596e-07,-4.93764e-08,0.855995,0.000527213,-2.77725e-07,2.92361e-08,0.856522,0.000526745,-1.90016e-07,-7.96341e-09,0.857049,0.000526341,-2.13907e-07,2.61752e-09,0.857575,0.000525922,-2.06054e-07,-2.50665e-09,0.8581,0.000525502,-2.13574e-07,7.40906e-09,0.858626,0.000525097,-1.91347e-07,-2.71296e-08,0.859151,0.000524633,-2.72736e-07,4.15048e-08,0.859675,0.000524212,-1.48221e-07,-1.96802e-08,0.860199,0.000523856,-2.07262e-07,-2.23886e-08,0.860723,0.000523375,-2.74428e-07,4.96299e-08,0.861246,0.000522975,-1.25538e-07,-5.69216e-08,0.861769,0.000522553,-2.96303e-07,5.88473e-08,0.862291,0.000522137,-1.19761e-07,-5.92584e-08,0.862813,0.00052172,-2.97536e-07,5.8977e-08,0.863334,0.000521301,-1.20605e-07,-5.74403e-08,0.863855,0.000520888,-2.92926e-07,5.15751e-08,0.864376,0.000520457,-1.38201e-07,-2.96506e-08,0.864896,0.000520091,-2.27153e-07,7.42277e-09,0.865416,0.000519659,-2.04885e-07,-4.05057e-11,0.865936,0.00051925,-2.05006e-07,-7.26074e-09,0.866455,0.000518818,-2.26788e-07,2.90835e-08,0.866973,0.000518451,-1.39538e-07,-4.94686e-08,0.867492,0.000518024,-2.87944e-07,4.95814e-08,0.868009,0.000517597,-1.39199e-07,-2.96479e-08,0.868527,0.000517229,-2.28143e-07,9.40539e-09,0.869044,0.000516801,-1.99927e-07,-7.9737e-09,0.86956,0.000516378,-2.23848e-07,2.24894e-08,0.870077,0.000515997,-1.5638e-07,-2.23793e-08,0.870592,0.000515617,-2.23517e-07,7.42302e-09,0.871108,0.000515193,-2.01248e-07,-7.31283e-09,0.871623,0.000514768,-2.23187e-07,2.18283e-08,0.872137,0.000514387,-1.57702e-07,-2.03959e-08,0.872652,0.000514011,-2.1889e-07,1.50711e-10,0.873165,0.000513573,-2.18437e-07,1.97931e-08,0.873679,0.000513196,-1.59058e-07,-1.97183e-08,0.874192,0.000512819,-2.18213e-07,-5.24324e-10,0.874704,0.000512381,-2.19786e-07,2.18156e-08,0.875217,0.000512007,-1.54339e-07,-2.71336e-08,0.875728,0.000511616,-2.3574e-07,2.71141e-08,0.87624,0.000511226,-1.54398e-07,-2.17182e-08,0.876751,0.000510852,-2.19552e-07,1.54131e-10,0.877262,0.000510414,-2.1909e-07,2.11017e-08,0.877772,0.000510039,-1.55785e-07,-2.49562e-08,0.878282,0.000509652,-2.30654e-07,1.91183e-08,0.878791,0.000509248,-1.73299e-07,8.08751e-09,0.8793,0.000508926,-1.49036e-07,-5.14684e-08,0.879809,0.000508474,-3.03441e-07,7.85766e-08,0.880317,0.000508103,-6.77112e-08,-8.40242e-08,0.880825,0.000507715,-3.19784e-07,7.87063e-08,0.881333,0.000507312,-8.36649e-08,-5.19871e-08,0.88184,0.000506988,-2.39626e-07,1.00327e-08,0.882346,0.000506539,-2.09528e-07,1.18562e-08,0.882853,0.000506156,-1.73959e-07,2.14703e-09,0.883359,0.000505814,-1.67518e-07,-2.04444e-08,0.883864,0.000505418,-2.28851e-07,2.00258e-08,0.88437,0.00050502,-1.68774e-07,-5.42855e-11,0.884874,0.000504682,-1.68937e-07,-1.98087e-08,0.885379,0.000504285,-2.28363e-07,1.96842e-08,0.885883,0.000503887,-1.6931e-07,6.76342e-10,0.886387,0.000503551,-1.67281e-07,-2.23896e-08,0.88689,0.000503149,-2.3445e-07,2.92774e-08,0.887393,0.000502768,-1.46618e-07,-3.51152e-08,0.887896,0.00050237,-2.51963e-07,5.15787e-08,0.888398,0.00050202,-9.72271e-08,-5.19903e-08,0.8889,0.00050167,-2.53198e-07,3.71732e-08,0.889401,0.000501275,-1.41678e-07,-3.70978e-08,0.889902,0.00050088,-2.52972e-07,5.16132e-08,0.890403,0.000500529,-9.81321e-08,-5.01459e-08,0.890903,0.000500183,-2.4857e-07,2.9761e-08,0.891403,0.000499775,-1.59287e-07,-9.29351e-09,0.891903,0.000499428,-1.87167e-07,7.41301e-09,0.892402,0.000499076,-1.64928e-07,-2.03585e-08,0.892901,0.000498685,-2.26004e-07,1.44165e-08,0.893399,0.000498276,-1.82754e-07,2.22974e-08,0.893898,0.000497978,-1.15862e-07,-4.40013e-08,0.894395,0.000497614,-2.47866e-07,3.44985e-08,0.894893,0.000497222,-1.44371e-07,-3.43882e-08,0.89539,0.00049683,-2.47535e-07,4.34497e-08,0.895886,0.000496465,-1.17186e-07,-2.02012e-08,0.896383,0.00049617,-1.7779e-07,-2.22497e-08,0.896879,0.000495748,-2.44539e-07,4.95952e-08,0.897374,0.000495408,-9.57532e-08,-5.69217e-08,0.89787,0.000495045,-2.66518e-07,5.88823e-08,0.898364,0.000494689,-8.98713e-08,-5.93983e-08,0.898859,0.000494331,-2.68066e-07,5.95017e-08,0.899353,0.000493973,-8.95613e-08,-5.9399e-08,0.899847,0.000493616,-2.67758e-07,5.8885e-08,0.90034,0.000493257,-9.11033e-08,-5.69317e-08,0.900833,0.000492904,-2.61898e-07,4.96326e-08,0.901326,0.000492529,-1.13001e-07,-2.23893e-08,0.901819,0.000492236,-1.80169e-07,-1.968e-08,0.902311,0.000491817,-2.39209e-07,4.15047e-08,0.902802,0.000491463,-1.14694e-07,-2.71296e-08,0.903293,0.000491152,-1.96083e-07,7.409e-09,0.903784,0.000490782,-1.73856e-07,-2.50645e-09,0.904275,0.000490427,-1.81376e-07,2.61679e-09,0.904765,0.000490072,-1.73525e-07,-7.96072e-09,0.905255,0.000489701,-1.97407e-07,2.92261e-08,0.905745,0.000489394,-1.09729e-07,-4.93389e-08,0.906234,0.000489027,-2.57746e-07,4.89204e-08,0.906723,0.000488658,-1.10985e-07,-2.71333e-08,0.907211,0.000488354,-1.92385e-07,8.30861e-12,0.907699,0.00048797,-1.9236e-07,2.71001e-08,0.908187,0.000487666,-1.1106e-07,-4.88041e-08,0.908675,0.000487298,-2.57472e-07,4.89069e-08,0.909162,0.000486929,-1.10751e-07,-2.76143e-08,0.909649,0.000486625,-1.93594e-07,1.9457e-09,0.910135,0.000486244,-1.87757e-07,1.98315e-08,0.910621,0.000485928,-1.28262e-07,-2.16671e-08,0.911107,0.000485606,-1.93264e-07,7.23216e-09,0.911592,0.000485241,-1.71567e-07,-7.26152e-09,0.912077,0.000484877,-1.93352e-07,2.18139e-08,0.912562,0.000484555,-1.2791e-07,-2.03895e-08,0.913047,0.000484238,-1.89078e-07,1.39494e-10,0.913531,0.000483861,-1.8866e-07,1.98315e-08,0.914014,0.000483543,-1.29165e-07,-1.98609e-08,0.914498,0.000483225,-1.88748e-07,7.39912e-12,0.914981,0.000482847,-1.88726e-07,1.98313e-08,0.915463,0.000482529,-1.29232e-07,-1.9728e-08,0.915946,0.000482212,-1.88416e-07,-5.24035e-10,0.916428,0.000481833,-1.89988e-07,2.18241e-08,0.916909,0.000481519,-1.24516e-07,-2.71679e-08,0.917391,0.000481188,-2.06019e-07,2.72427e-08,0.917872,0.000480858,-1.24291e-07,-2.21985e-08,0.918353,0.000480543,-1.90886e-07,1.94644e-09,0.918833,0.000480167,-1.85047e-07,1.44127e-08,0.919313,0.00047984,-1.41809e-07,7.39438e-12,0.919793,0.000479556,-1.41787e-07,-1.44423e-08,0.920272,0.000479229,-1.85114e-07,-1.84291e-09,0.920751,0.000478854,-1.90642e-07,2.18139e-08,0.92123,0.000478538,-1.25201e-07,-2.58081e-08,0.921708,0.00047821,-2.02625e-07,2.18139e-08,0.922186,0.00047787,-1.37183e-07,-1.84291e-09,0.922664,0.00047759,-1.42712e-07,-1.44423e-08,0.923141,0.000477262,-1.86039e-07,7.34701e-12,0.923618,0.00047689,-1.86017e-07,1.44129e-08,0.924095,0.000476561,-1.42778e-07,1.94572e-09,0.924572,0.000476281,-1.36941e-07,-2.21958e-08,0.925048,0.000475941,-2.03528e-07,2.72327e-08,0.925523,0.000475615,-1.2183e-07,-2.71304e-08,0.925999,0.00047529,-2.03221e-07,2.16843e-08,0.926474,0.000474949,-1.38168e-07,-2.16005e-12,0.926949,0.000474672,-1.38175e-07,-2.16756e-08,0.927423,0.000474331,-2.03202e-07,2.71001e-08,0.927897,0.000474006,-1.21902e-07,-2.71201e-08,0.928371,0.000473681,-2.03262e-07,2.17757e-08,0.928845,0.00047334,-1.37935e-07,-3.78028e-10,0.929318,0.000473063,-1.39069e-07,-2.02636e-08,0.929791,0.000472724,-1.9986e-07,2.18276e-08,0.930263,0.000472389,-1.34377e-07,-7.44231e-09,0.930736,0.000472098,-1.56704e-07,7.94165e-09,0.931208,0.000471809,-1.32879e-07,-2.43243e-08,0.931679,0.00047147,-2.05851e-07,2.97508e-08,0.932151,0.000471148,-1.16599e-07,-3.50742e-08,0.932622,0.000470809,-2.21822e-07,5.09414e-08,0.933092,0.000470518,-6.89976e-08,-4.94821e-08,0.933563,0.000470232,-2.17444e-07,2.77775e-08,0.934033,0.00046988,-1.34111e-07,-2.02351e-09,0.934502,0.000469606,-1.40182e-07,-1.96835e-08,0.934972,0.000469267,-1.99232e-07,2.11529e-08,0.935441,0.000468932,-1.35774e-07,-5.32332e-09,0.93591,0.000468644,-1.51743e-07,1.40413e-10,0.936378,0.000468341,-1.51322e-07,4.76166e-09,0.936846,0.000468053,-1.37037e-07,-1.9187e-08,0.937314,0.000467721,-1.94598e-07,1.23819e-08,0.937782,0.000467369,-1.57453e-07,2.92642e-08,0.938249,0.000467142,-6.96601e-08,-6.98342e-08,0.938716,0.000466793,-2.79163e-07,7.12586e-08,0.939183,0.000466449,-6.53869e-08,-3.63863e-08,0.939649,0.000466209,-1.74546e-07,1.46818e-08,0.940115,0.000465904,-1.305e-07,-2.2341e-08,0.940581,0.000465576,-1.97523e-07,1.50774e-08,0.941046,0.000465226,-1.52291e-07,2.16359e-08,0.941511,0.000464986,-8.73832e-08,-4.20162e-08,0.941976,0.000464685,-2.13432e-07,2.72198e-08,0.942441,0.00046434,-1.31773e-07,-7.2581e-09,0.942905,0.000464055,-1.53547e-07,1.81263e-09,0.943369,0.000463753,-1.48109e-07,7.58386e-12,0.943832,0.000463457,-1.48086e-07,-1.84298e-09,0.944296,0.000463155,-1.53615e-07,7.36433e-09,0.944759,0.00046287,-1.31522e-07,-2.76143e-08,0.945221,0.000462524,-2.14365e-07,4.34883e-08,0.945684,0.000462226,-8.39003e-08,-2.71297e-08,0.946146,0.000461977,-1.65289e-07,5.42595e-09,0.946608,0.000461662,-1.49012e-07,5.42593e-09,0.947069,0.000461381,-1.32734e-07,-2.71297e-08,0.94753,0.000461034,-2.14123e-07,4.34881e-08,0.947991,0.000460736,-8.36585e-08,-2.76134e-08,0.948452,0.000460486,-1.66499e-07,7.36083e-09,0.948912,0.000460175,-1.44416e-07,-1.82993e-09,0.949372,0.000459881,-1.49906e-07,-4.11073e-11,0.949832,0.000459581,-1.50029e-07,1.99434e-09,0.950291,0.000459287,-1.44046e-07,-7.93627e-09,0.950751,0.000458975,-1.67855e-07,2.97507e-08,0.951209,0.000458728,-7.86029e-08,-5.1462e-08,0.951668,0.000458417,-2.32989e-07,5.6888e-08,0.952126,0.000458121,-6.2325e-08,-5.68806e-08,0.952584,0.000457826,-2.32967e-07,5.14251e-08,0.953042,0.000457514,-7.86914e-08,-2.96107e-08,0.953499,0.000457268,-1.67523e-07,7.41296e-09,0.953956,0.000456955,-1.45285e-07,-4.11262e-11,0.954413,0.000456665,-1.45408e-07,-7.24847e-09,0.95487,0.000456352,-1.67153e-07,2.9035e-08,0.955326,0.000456105,-8.00484e-08,-4.92869e-08,0.955782,0.000455797,-2.27909e-07,4.89032e-08,0.956238,0.000455488,-8.11994e-08,-2.71166e-08,0.956693,0.000455244,-1.62549e-07,-4.13678e-11,0.957148,0.000454919,-1.62673e-07,2.72821e-08,0.957603,0.000454675,-8.0827e-08,-4.94824e-08,0.958057,0.000454365,-2.29274e-07,5.14382e-08,0.958512,0.000454061,-7.49597e-08,-3.7061e-08,0.958965,0.0004538,-1.86143e-07,3.72013e-08,0.959419,0.000453539,-7.45389e-08,-5.21396e-08,0.959873,0.000453234,-2.30958e-07,5.21476e-08,0.960326,0.000452928,-7.45146e-08,-3.72416e-08,0.960778,0.000452667,-1.8624e-07,3.72143e-08,0.961231,0.000452407,-7.45967e-08,-5.20109e-08,0.961683,0.000452101,-2.30629e-07,5.16199e-08,0.962135,0.000451795,-7.57696e-08,-3.52595e-08,0.962587,0.000451538,-1.81548e-07,2.98133e-08,0.963038,0.000451264,-9.2108e-08,-2.43892e-08,0.963489,0.000451007,-1.65276e-07,8.13892e-09,0.96394,0.000450701,-1.40859e-07,-8.16647e-09,0.964391,0.000450394,-1.65358e-07,2.45269e-08,0.964841,0.000450137,-9.17775e-08,-3.03367e-08,0.965291,0.000449863,-1.82787e-07,3.7215e-08,0.965741,0.000449609,-7.11424e-08,-5.89188e-08,0.96619,0.00044929,-2.47899e-07,7.92509e-08,0.966639,0.000449032,-1.01462e-08,-7.92707e-08,0.967088,0.000448773,-2.47958e-07,5.90181e-08,0.967537,0.000448455,-7.0904e-08,-3.75925e-08,0.967985,0.0004482,-1.83681e-07,3.17471e-08,0.968433,0.000447928,-8.84401e-08,-2.97913e-08,0.968881,0.000447662,-1.77814e-07,2.78133e-08,0.969329,0.000447389,-9.4374e-08,-2.18572e-08,0.969776,0.000447135,-1.59946e-07,1.10134e-11,0.970223,0.000446815,-1.59913e-07,2.18132e-08,0.97067,0.000446561,-9.44732e-08,-2.76591e-08,0.971116,0.000446289,-1.7745e-07,2.92185e-08,0.971562,0.000446022,-8.97948e-08,-2.96104e-08,0.972008,0.000445753,-1.78626e-07,2.96185e-08,0.972454,0.000445485,-8.97706e-08,-2.92588e-08,0.972899,0.000445218,-1.77547e-07,2.78123e-08,0.973344,0.000444946,-9.41103e-08,-2.23856e-08,0.973789,0.000444691,-1.61267e-07,2.12559e-09,0.974233,0.000444374,-1.5489e-07,1.38833e-08,0.974678,0.000444106,-1.13241e-07,1.94591e-09,0.975122,0.000443886,-1.07403e-07,-2.16669e-08,0.975565,0.000443606,-1.72404e-07,2.5117e-08,0.976009,0.000443336,-9.70526e-08,-1.91963e-08,0.976452,0.000443085,-1.54642e-07,-7.93627e-09,0.976895,0.000442752,-1.7845e-07,5.09414e-08,0.977338,0.000442548,-2.56262e-08,-7.66201e-08,0.97778,0.000442266,-2.55486e-07,7.67249e-08,0.978222,0.000441986,-2.53118e-08,-5.14655e-08,0.978664,0.000441781,-1.79708e-07,9.92773e-09,0.979106,0.000441451,-1.49925e-07,1.17546e-08,0.979547,0.000441186,-1.14661e-07,2.65868e-09,0.979988,0.000440965,-1.06685e-07,-2.23893e-08,0.980429,0.000440684,-1.73853e-07,2.72939e-08,0.980869,0.000440419,-9.19716e-08,-2.71816e-08,0.98131,0.000440153,-1.73516e-07,2.18278e-08,0.98175,0.000439872,-1.08033e-07,-5.24833e-10,0.982189,0.000439654,-1.09607e-07,-1.97284e-08,0.982629,0.000439376,-1.68793e-07,1.98339e-08,0.983068,0.000439097,-1.09291e-07,-2.62901e-12,0.983507,0.000438879,-1.09299e-07,-1.98234e-08,0.983946,0.000438601,-1.68769e-07,1.96916e-08,0.984384,0.000438322,-1.09694e-07,6.6157e-10,0.984823,0.000438105,-1.0771e-07,-2.23379e-08,0.985261,0.000437823,-1.74723e-07,2.90855e-08,0.985698,0.00043756,-8.74669e-08,-3.43992e-08,0.986136,0.000437282,-1.90665e-07,4.89068e-08,0.986573,0.000437048,-4.39442e-08,-4.20188e-08,0.98701,0.000436834,-1.7e-07,-4.11073e-11,0.987446,0.000436494,-1.70124e-07,4.21832e-08,0.987883,0.00043628,-4.35742e-08,-4.94824e-08,0.988319,0.000436044,-1.92021e-07,3.6537e-08,0.988755,0.00043577,-8.24102e-08,-3.70611e-08,0.989191,0.000435494,-1.93593e-07,5.21026e-08,0.989626,0.000435263,-3.72855e-08,-5.21402e-08,0.990061,0.000435032,-1.93706e-07,3.7249e-08,0.990496,0.000434756,-8.19592e-08,-3.72512e-08,0.990931,0.000434481,-1.93713e-07,5.21511e-08,0.991365,0.00043425,-3.72595e-08,-5.21439e-08,0.991799,0.000434019,-1.93691e-07,3.72152e-08,0.992233,0.000433743,-8.20456e-08,-3.71123e-08,0.992667,0.000433468,-1.93382e-07,5.16292e-08,0.9931,0.000433236,-3.84947e-08,-5.01953e-08,0.993533,0.000433008,-1.89081e-07,2.99427e-08,0.993966,0.00043272,-9.92525e-08,-9.9708e-09,0.994399,0.000432491,-1.29165e-07,9.94051e-09,0.994831,0.000432263,-9.93434e-08,-2.97912e-08,0.995263,0.000431975,-1.88717e-07,4.96198e-08,0.995695,0.000431746,-3.98578e-08,-4.94785e-08,0.996127,0.000431518,-1.88293e-07,2.9085e-08,0.996558,0.000431229,-1.01038e-07,-7.25675e-09,0.996989,0.000431005,-1.22809e-07,-5.79945e-11,0.99742,0.000430759,-1.22983e-07,7.48873e-09,0.997851,0.000430536,-1.00516e-07,-2.98969e-08,0.998281,0.000430245,-1.90207e-07,5.24942e-08,0.998711,0.000430022,-3.27246e-08,-6.08706e-08,0.999141,0.000429774,-2.15336e-07,7.17788e-08,0.999571,0.000429392,0.,0.}; + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void Lab2RGBConvert_f(const T& src, D& dst) + { + const float lThresh = 0.008856f * 903.3f; + const float fThresh = 7.787f * 0.008856f + 16.0f / 116.0f; + + float Y, fy; + + if (src.x <= lThresh) + { + Y = src.x / 903.3f; + fy = 7.787f * Y + 16.0f / 116.0f; + } + else + { + fy = (src.x + 16.0f) / 116.0f; + Y = fy * fy * fy; + } + + float X = src.y / 500.0f + fy; + float Z = fy - src.z / 200.0f; + + if (X <= fThresh) + X = (X - 16.0f / 116.0f) / 7.787f; + else + X = X * X * X; + + if (Z <= fThresh) + Z = (Z - 16.0f / 116.0f) / 7.787f; + else + Z = Z * Z * Z; + + float B = 0.052891f * X - 0.204043f * Y + 1.151152f * Z; + float G = -0.921235f * X + 1.875991f * Y + 0.045244f * Z; + float R = 3.079933f * X - 1.537150f * Y - 0.542782f * Z; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + } + + dst.x = blueIdx == 0 ? B : R; + dst.y = G; + dst.z = blueIdx == 0 ? R : B; + setAlpha(dst, ColorChannel<float>::max()); + } + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void Lab2RGBConvert_b(const T& src, D& dst) + { + float3 srcf, dstf; + + srcf.x = src.x * (100.f / 255.f); + srcf.y = src.y - 128; + srcf.z = src.z - 128; + + Lab2RGBConvert_f<srgb, blueIdx>(srcf, dstf); + + dst.x = saturate_cast<uchar>(dstf.x * 255.f); + dst.y = saturate_cast<uchar>(dstf.y * 255.f); + dst.z = saturate_cast<uchar>(dstf.z * 255.f); + setAlpha(dst, ColorChannel<uchar>::max()); + } + + template <typename T, int scn, int dcn, bool srgb, int blueIdx> struct Lab2RGB; + template <int scn, int dcn, bool srgb, int blueIdx> + struct Lab2RGB<uchar, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<uchar, scn>::vec_type, typename TypeVec<uchar, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<uchar, dcn>::vec_type operator ()(const typename TypeVec<uchar, scn>::vec_type& src) const + { + typename TypeVec<uchar, dcn>::vec_type dst; + + Lab2RGBConvert_b<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Lab2RGB() {} + __host__ __device__ __forceinline__ Lab2RGB(const Lab2RGB&) {} + }; + template <int scn, int dcn, bool srgb, int blueIdx> + struct Lab2RGB<float, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<float, scn>::vec_type, typename TypeVec<float, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<float, dcn>::vec_type operator ()(const typename TypeVec<float, scn>::vec_type& src) const + { + typename TypeVec<float, dcn>::vec_type dst; + + Lab2RGBConvert_f<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Lab2RGB() {} + __host__ __device__ __forceinline__ Lab2RGB(const Lab2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Lab2RGB<T, scn, dcn, srgb, blueIdx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> Luv ///////////////////////////////////// + + namespace color_detail + { + __constant__ float c_LabCbrtTab[] = {0.137931,0.0114066,0.,1.18859e-07,0.149338,0.011407,3.56578e-07,-5.79396e-07,0.160745,0.0114059,-1.38161e-06,2.16892e-06,0.172151,0.0114097,5.12516e-06,-8.0814e-06,0.183558,0.0113957,-1.9119e-05,3.01567e-05,0.194965,0.0114479,7.13509e-05,-0.000112545,0.206371,0.011253,-0.000266285,-0.000106493,0.217252,0.0104009,-0.000585765,7.32149e-05,0.22714,0.00944906,-0.00036612,1.21917e-05,0.236235,0.0087534,-0.000329545,2.01753e-05,0.244679,0.00815483,-0.000269019,1.24435e-05,0.252577,0.00765412,-0.000231689,1.05618e-05,0.26001,0.00722243,-0.000200003,8.26662e-06,0.267041,0.00684723,-0.000175203,6.76746e-06,0.27372,0.00651712,-0.000154901,5.61192e-06,0.280088,0.00622416,-0.000138065,4.67009e-06,0.286179,0.00596204,-0.000124055,3.99012e-06,0.292021,0.0057259,-0.000112085,3.36032e-06,0.297638,0.00551181,-0.000102004,2.95338e-06,0.30305,0.00531666,-9.31435e-05,2.52875e-06,0.308277,0.00513796,-8.55572e-05,2.22022e-06,0.313331,0.00497351,-7.88966e-05,1.97163e-06,0.318228,0.00482163,-7.29817e-05,1.7248e-06,0.322978,0.00468084,-6.78073e-05,1.55998e-06,0.327593,0.0045499,-6.31274e-05,1.36343e-06,0.332081,0.00442774,-5.90371e-05,1.27136e-06,0.336451,0.00431348,-5.5223e-05,1.09111e-06,0.34071,0.00420631,-5.19496e-05,1.0399e-06,0.344866,0.00410553,-4.88299e-05,9.18347e-07,0.348923,0.00401062,-4.60749e-05,8.29942e-07,0.352889,0.00392096,-4.35851e-05,7.98478e-07,0.356767,0.00383619,-4.11896e-05,6.84917e-07,0.360562,0.00375586,-3.91349e-05,6.63976e-07,0.36428,0.00367959,-3.7143e-05,5.93086e-07,0.367923,0.00360708,-3.53637e-05,5.6976e-07,0.371495,0.00353806,-3.36544e-05,4.95533e-07,0.375,0.00347224,-3.21678e-05,4.87951e-07,0.378441,0.00340937,-3.0704e-05,4.4349e-07,0.38182,0.00334929,-2.93735e-05,4.20297e-07,0.38514,0.0032918,-2.81126e-05,3.7872e-07,0.388404,0.00323671,-2.69764e-05,3.596e-07,0.391614,0.00318384,-2.58976e-05,3.5845e-07,0.394772,0.00313312,-2.48223e-05,2.92765e-07,0.397881,0.00308435,-2.3944e-05,3.18232e-07,0.400942,0.00303742,-2.29893e-05,2.82046e-07,0.403957,0.00299229,-2.21432e-05,2.52315e-07,0.406927,0.00294876,-2.13862e-05,2.58416e-07,0.409855,0.00290676,-2.0611e-05,2.33939e-07,0.412741,0.00286624,-1.99092e-05,2.36342e-07,0.415587,0.00282713,-1.92001e-05,1.916e-07,0.418396,0.00278931,-1.86253e-05,2.1915e-07,0.421167,0.00275271,-1.79679e-05,1.83498e-07,0.423901,0.00271733,-1.74174e-05,1.79343e-07,0.426602,0.00268303,-1.68794e-05,1.72013e-07,0.429268,0.00264979,-1.63633e-05,1.75686e-07,0.431901,0.00261759,-1.58363e-05,1.3852e-07,0.434503,0.00258633,-1.54207e-05,1.64304e-07,0.437074,0.00255598,-1.49278e-05,1.28136e-07,0.439616,0.00252651,-1.45434e-05,1.57618e-07,0.442128,0.0024979,-1.40705e-05,1.0566e-07,0.444612,0.00247007,-1.37535e-05,1.34998e-07,0.447068,0.00244297,-1.33485e-05,1.29207e-07,0.449498,0.00241666,-1.29609e-05,9.32347e-08,0.451902,0.00239102,-1.26812e-05,1.23703e-07,0.45428,0.00236603,-1.23101e-05,9.74072e-08,0.456634,0.0023417,-1.20179e-05,1.12518e-07,0.458964,0.002318,-1.16803e-05,7.83681e-08,0.46127,0.00229488,-1.14452e-05,1.10452e-07,0.463554,0.00227232,-1.11139e-05,7.58719e-08,0.465815,0.00225032,-1.08863e-05,9.2699e-08,0.468055,0.00222882,-1.06082e-05,8.97738e-08,0.470273,0.00220788,-1.03388e-05,5.4845e-08,0.47247,0.00218736,-1.01743e-05,1.0808e-07,0.474648,0.00216734,-9.85007e-06,4.9277e-08,0.476805,0.00214779,-9.70224e-06,8.22408e-08,0.478943,0.00212863,-9.45551e-06,6.87942e-08,0.481063,0.00210993,-9.24913e-06,5.98144e-08,0.483163,0.00209161,-9.06969e-06,7.93789e-08,0.485246,0.00207371,-8.83155e-06,3.99032e-08,0.487311,0.00205616,-8.71184e-06,8.88325e-08,0.489358,0.002039,-8.44534e-06,2.20004e-08,0.491389,0.00202218,-8.37934e-06,9.13872e-08,0.493403,0.0020057,-8.10518e-06,2.96829e-08,0.495401,0.00198957,-8.01613e-06,5.81028e-08,0.497382,0.00197372,-7.84183e-06,6.5731e-08,0.499348,0.00195823,-7.64463e-06,3.66019e-08,0.501299,0.00194305,-7.53483e-06,2.62811e-08,0.503234,0.00192806,-7.45598e-06,9.66907e-08,0.505155,0.00191344,-7.16591e-06,4.18928e-09,0.507061,0.00189912,-7.15334e-06,6.53665e-08,0.508953,0.00188501,-6.95724e-06,3.23686e-08,0.510831,0.00187119,-6.86014e-06,4.35774e-08,0.512696,0.0018576,-6.72941e-06,3.17406e-08,0.514547,0.00184424,-6.63418e-06,6.78785e-08,0.516384,0.00183117,-6.43055e-06,-5.23126e-09,0.518209,0.0018183,-6.44624e-06,7.22562e-08,0.520021,0.00180562,-6.22947e-06,1.42292e-08,0.52182,0.0017932,-6.18679e-06,4.9641e-08,0.523607,0.00178098,-6.03786e-06,2.56259e-08,0.525382,0.00176898,-5.96099e-06,2.66696e-08,0.527145,0.00175714,-5.88098e-06,4.65094e-08,0.528897,0.00174552,-5.74145e-06,2.57114e-08,0.530637,0.00173411,-5.66431e-06,2.94588e-08,0.532365,0.00172287,-5.57594e-06,3.52667e-08,0.534082,0.00171182,-5.47014e-06,8.28868e-09,0.535789,0.00170091,-5.44527e-06,5.07871e-08,0.537484,0.00169017,-5.29291e-06,2.69817e-08,0.539169,0.00167967,-5.21197e-06,2.01009e-08,0.540844,0.0016693,-5.15166e-06,1.18237e-08,0.542508,0.00165903,-5.11619e-06,5.18135e-08,0.544162,0.00164896,-4.96075e-06,1.9341e-08,0.545806,0.00163909,-4.90273e-06,-9.96867e-09,0.54744,0.00162926,-4.93263e-06,8.01382e-08,0.549064,0.00161963,-4.69222e-06,-1.25601e-08,0.550679,0.00161021,-4.7299e-06,2.97067e-08,0.552285,0.00160084,-4.64078e-06,1.29426e-08,0.553881,0.0015916,-4.60195e-06,3.77327e-08,0.555468,0.00158251,-4.48875e-06,1.49412e-08,0.557046,0.00157357,-4.44393e-06,2.17118e-08,0.558615,0.00156475,-4.3788e-06,1.74206e-08,0.560176,0.00155605,-4.32653e-06,2.78152e-08,0.561727,0.00154748,-4.24309e-06,-9.47239e-09,0.563271,0.00153896,-4.27151e-06,6.9679e-08,0.564805,0.00153063,-4.06247e-06,-3.08246e-08,0.566332,0.00152241,-4.15494e-06,5.36188e-08,0.56785,0.00151426,-3.99409e-06,-4.83594e-09,0.56936,0.00150626,-4.00859e-06,2.53293e-08,0.570863,0.00149832,-3.93261e-06,2.27286e-08,0.572357,0.00149052,-3.86442e-06,2.96541e-09,0.573844,0.0014828,-3.85552e-06,2.50147e-08,0.575323,0.00147516,-3.78048e-06,1.61842e-08,0.576794,0.00146765,-3.73193e-06,2.94582e-08,0.578258,0.00146028,-3.64355e-06,-1.48076e-08,0.579715,0.00145295,-3.68798e-06,2.97724e-08,0.581164,0.00144566,-3.59866e-06,1.49272e-08,0.582606,0.00143851,-3.55388e-06,2.97285e-08,0.584041,0.00143149,-3.46469e-06,-1.46323e-08,0.585469,0.00142451,-3.50859e-06,2.88004e-08,0.58689,0.00141758,-3.42219e-06,1.864e-08,0.588304,0.00141079,-3.36627e-06,1.58482e-08,0.589712,0.00140411,-3.31872e-06,-2.24279e-08,0.591112,0.00139741,-3.38601e-06,7.38639e-08,0.592507,0.00139085,-3.16441e-06,-3.46088e-08,0.593894,0.00138442,-3.26824e-06,4.96675e-09,0.595275,0.0013779,-3.25334e-06,7.4346e-08,0.59665,0.00137162,-3.0303e-06,-6.39319e-08,0.598019,0.00136536,-3.2221e-06,6.21725e-08,0.599381,0.00135911,-3.03558e-06,-5.94423e-09,0.600737,0.00135302,-3.05341e-06,2.12091e-08,0.602087,0.00134697,-2.98979e-06,-1.92876e-08,0.603431,0.00134094,-3.04765e-06,5.5941e-08,0.604769,0.00133501,-2.87983e-06,-2.56622e-08,0.606101,0.00132917,-2.95681e-06,4.67078e-08,0.607427,0.0013234,-2.81669e-06,-4.19592e-08,0.608748,0.00131764,-2.94257e-06,6.15243e-08,0.610062,0.00131194,-2.75799e-06,-2.53244e-08,0.611372,0.00130635,-2.83397e-06,3.97739e-08,0.612675,0.0013008,-2.71465e-06,-1.45618e-08,0.613973,0.00129533,-2.75833e-06,1.84733e-08,0.615266,0.00128986,-2.70291e-06,2.73606e-10,0.616553,0.00128446,-2.70209e-06,4.00367e-08,0.617835,0.00127918,-2.58198e-06,-4.12113e-08,0.619111,0.00127389,-2.70561e-06,6.52039e-08,0.620383,0.00126867,-2.51e-06,-4.07901e-08,0.621649,0.00126353,-2.63237e-06,3.83516e-08,0.62291,0.00125838,-2.51732e-06,6.59315e-09,0.624166,0.00125337,-2.49754e-06,-5.11939e-09,0.625416,0.00124836,-2.5129e-06,1.38846e-08,0.626662,0.00124337,-2.47124e-06,9.18514e-09,0.627903,0.00123846,-2.44369e-06,8.97952e-09,0.629139,0.0012336,-2.41675e-06,1.45012e-08,0.63037,0.00122881,-2.37325e-06,-7.37949e-09,0.631597,0.00122404,-2.39538e-06,1.50169e-08,0.632818,0.00121929,-2.35033e-06,6.91648e-09,0.634035,0.00121461,-2.32958e-06,1.69219e-08,0.635248,0.00121,-2.27882e-06,-1.49997e-08,0.636455,0.0012054,-2.32382e-06,4.30769e-08,0.637659,0.00120088,-2.19459e-06,-3.80986e-08,0.638857,0.00119638,-2.30888e-06,4.97134e-08,0.640051,0.00119191,-2.15974e-06,-4.15463e-08,0.641241,0.00118747,-2.28438e-06,5.68667e-08,0.642426,0.00118307,-2.11378e-06,-7.10641e-09,0.643607,0.00117882,-2.1351e-06,-2.8441e-08,0.644784,0.00117446,-2.22042e-06,6.12658e-08,0.645956,0.00117021,-2.03663e-06,-3.78083e-08,0.647124,0.00116602,-2.15005e-06,3.03627e-08,0.648288,0.00116181,-2.05896e-06,-2.40379e-08,0.649448,0.00115762,-2.13108e-06,6.57887e-08,0.650603,0.00115356,-1.93371e-06,-6.03028e-08,0.651755,0.00114951,-2.11462e-06,5.62134e-08,0.652902,0.00114545,-1.94598e-06,-4.53417e-08,0.654046,0.00114142,-2.082e-06,6.55489e-08,0.655185,0.00113745,-1.88536e-06,-3.80396e-08,0.656321,0.00113357,-1.99948e-06,2.70049e-08,0.657452,0.00112965,-1.91846e-06,-1.03755e-08,0.65858,0.00112578,-1.94959e-06,1.44973e-08,0.659704,0.00112192,-1.9061e-06,1.1991e-08,0.660824,0.00111815,-1.87012e-06,-2.85634e-09,0.66194,0.0011144,-1.87869e-06,-5.65782e-10,0.663053,0.00111064,-1.88039e-06,5.11947e-09,0.664162,0.0011069,-1.86503e-06,3.96924e-08,0.665267,0.00110328,-1.74595e-06,-4.46795e-08,0.666368,0.00109966,-1.87999e-06,1.98161e-08,0.667466,0.00109596,-1.82054e-06,2.502e-08,0.66856,0.00109239,-1.74548e-06,-6.86593e-10,0.669651,0.0010889,-1.74754e-06,-2.22739e-08,0.670738,0.00108534,-1.81437e-06,3.01776e-08,0.671821,0.0010818,-1.72383e-06,2.07732e-08,0.672902,0.00107841,-1.66151e-06,-5.36658e-08,0.673978,0.00107493,-1.82251e-06,7.46802e-08,0.675051,0.00107151,-1.59847e-06,-6.62411e-08,0.676121,0.00106811,-1.79719e-06,7.10748e-08,0.677188,0.00106473,-1.58397e-06,-3.92441e-08,0.678251,0.00106145,-1.7017e-06,2.62973e-08,0.679311,0.00105812,-1.62281e-06,-6.34035e-09,0.680367,0.00105486,-1.64183e-06,-9.36249e-10,0.68142,0.00105157,-1.64464e-06,1.00854e-08,0.68247,0.00104831,-1.61438e-06,2.01995e-08,0.683517,0.00104514,-1.55378e-06,-3.1279e-08,0.68456,0.00104194,-1.64762e-06,4.53114e-08,0.685601,0.00103878,-1.51169e-06,-3.07573e-08,0.686638,0.00103567,-1.60396e-06,1.81133e-08,0.687672,0.00103251,-1.54962e-06,1.79085e-08,0.688703,0.00102947,-1.49589e-06,-3.01428e-08,0.689731,0.00102639,-1.58632e-06,4.30583e-08,0.690756,0.00102334,-1.45715e-06,-2.28814e-08,0.691778,0.00102036,-1.52579e-06,-1.11373e-08,0.692797,0.00101727,-1.5592e-06,6.74305e-08,0.693812,0.00101436,-1.35691e-06,-7.97709e-08,0.694825,0.0010114,-1.59622e-06,7.28391e-08,0.695835,0.00100843,-1.37771e-06,-3.27715e-08,0.696842,0.00100558,-1.47602e-06,-1.35807e-09,0.697846,0.00100262,-1.48009e-06,3.82037e-08,0.698847,0.000999775,-1.36548e-06,-3.22474e-08,0.699846,0.000996948,-1.46223e-06,3.11809e-08,0.700841,0.000994117,-1.36868e-06,-3.28714e-08,0.701834,0.000991281,-1.4673e-06,4.07001e-08,0.702824,0.000988468,-1.3452e-06,-1.07197e-08,0.703811,0.000985746,-1.37736e-06,2.17866e-09,0.704795,0.000982998,-1.37082e-06,2.00521e-09,0.705777,0.000980262,-1.3648e-06,-1.01996e-08,0.706756,0.000977502,-1.3954e-06,3.87931e-08,0.707732,0.000974827,-1.27902e-06,-2.57632e-08,0.708706,0.000972192,-1.35631e-06,4.65513e-09,0.709676,0.000969493,-1.34235e-06,7.14257e-09,0.710645,0.00096683,-1.32092e-06,2.63791e-08,0.71161,0.000964267,-1.24178e-06,-5.30543e-08,0.712573,0.000961625,-1.40095e-06,6.66289e-08,0.713533,0.000959023,-1.20106e-06,-3.46474e-08,0.714491,0.000956517,-1.305e-06,1.23559e-08,0.715446,0.000953944,-1.26793e-06,-1.47763e-08,0.716399,0.000951364,-1.31226e-06,4.67494e-08,0.717349,0.000948879,-1.17201e-06,-5.3012e-08,0.718297,0.000946376,-1.33105e-06,4.60894e-08,0.719242,0.000943852,-1.19278e-06,-1.21366e-08,0.720185,0.00094143,-1.22919e-06,2.45673e-09,0.721125,0.000938979,-1.22182e-06,2.30966e-09,0.722063,0.000936543,-1.21489e-06,-1.16954e-08,0.722998,0.000934078,-1.24998e-06,4.44718e-08,0.723931,0.000931711,-1.11656e-06,-4.69823e-08,0.724861,0.000929337,-1.25751e-06,2.4248e-08,0.725789,0.000926895,-1.18477e-06,9.5949e-09,0.726715,0.000924554,-1.15598e-06,-3.02286e-09,0.727638,0.000922233,-1.16505e-06,2.49649e-09,0.72856,0.00091991,-1.15756e-06,-6.96321e-09,0.729478,0.000917575,-1.17845e-06,2.53564e-08,0.730395,0.000915294,-1.10238e-06,-3.48578e-08,0.731309,0.000912984,-1.20695e-06,5.44704e-08,0.732221,0.000910734,-1.04354e-06,-6.38144e-08,0.73313,0.000908455,-1.23499e-06,8.15781e-08,0.734038,0.00090623,-9.90253e-07,-8.3684e-08,0.734943,0.000903999,-1.2413e-06,7.43441e-08,0.735846,0.000901739,-1.01827e-06,-3.48787e-08,0.736746,0.000899598,-1.12291e-06,5.56596e-09,0.737645,0.000897369,-1.10621e-06,1.26148e-08,0.738541,0.000895194,-1.06837e-06,3.57935e-09,0.739435,0.000893068,-1.05763e-06,-2.69322e-08,0.740327,0.000890872,-1.13842e-06,4.45448e-08,0.741217,0.000888729,-1.00479e-06,-3.20376e-08,0.742105,0.000886623,-1.1009e-06,2.40011e-08,0.74299,0.000884493,-1.0289e-06,-4.36209e-09,0.743874,0.000882422,-1.04199e-06,-6.55268e-09,0.744755,0.000880319,-1.06164e-06,3.05728e-08,0.745634,0.000878287,-9.69926e-07,-5.61338e-08,0.746512,0.000876179,-1.13833e-06,7.4753e-08,0.747387,0.000874127,-9.14068e-07,-6.40644e-08,0.74826,0.000872106,-1.10626e-06,6.22955e-08,0.749131,0.000870081,-9.19375e-07,-6.59083e-08,0.75,0.000868044,-1.1171e-06,8.21284e-08,0.750867,0.000866056,-8.70714e-07,-8.37915e-08,0.751732,0.000864064,-1.12209e-06,7.42237e-08,0.752595,0.000862042,-8.99418e-07,-3.42894e-08,0.753456,0.00086014,-1.00229e-06,3.32955e-09,0.754315,0.000858146,-9.92297e-07,2.09712e-08,0.755173,0.000856224,-9.29384e-07,-2.76096e-08,0.756028,0.000854282,-1.01221e-06,2.98627e-08,0.756881,0.000852348,-9.22625e-07,-3.22365e-08,0.757733,0.000850406,-1.01933e-06,3.94786e-08,0.758582,0.000848485,-9.00898e-07,-6.46833e-09,0.75943,0.000846664,-9.20303e-07,-1.36052e-08,0.760275,0.000844783,-9.61119e-07,1.28447e-09,0.761119,0.000842864,-9.57266e-07,8.4674e-09,0.761961,0.000840975,-9.31864e-07,2.44506e-08,0.762801,0.000839185,-8.58512e-07,-4.6665e-08,0.763639,0.000837328,-9.98507e-07,4.30001e-08,0.764476,0.00083546,-8.69507e-07,-6.12609e-09,0.76531,0.000833703,-8.87885e-07,-1.84959e-08,0.766143,0.000831871,-9.43372e-07,2.05052e-08,0.766974,0.000830046,-8.81857e-07,-3.92026e-09,0.767803,0.000828271,-8.93618e-07,-4.82426e-09,0.768631,0.000826469,-9.0809e-07,2.32172e-08,0.769456,0.000824722,-8.38439e-07,-2.84401e-08,0.77028,0.00082296,-9.23759e-07,3.09386e-08,0.771102,0.000821205,-8.30943e-07,-3.57099e-08,0.771922,0.000819436,-9.38073e-07,5.22963e-08,0.772741,0.000817717,-7.81184e-07,-5.42658e-08,0.773558,0.000815992,-9.43981e-07,4.55579e-08,0.774373,0.000814241,-8.07308e-07,-8.75656e-09,0.775186,0.0008126,-8.33578e-07,-1.05315e-08,0.775998,0.000810901,-8.65172e-07,-8.72188e-09,0.776808,0.000809145,-8.91338e-07,4.54191e-08,0.777616,0.000807498,-7.5508e-07,-5.37454e-08,0.778423,0.000805827,-9.16317e-07,5.03532e-08,0.779228,0.000804145,-7.65257e-07,-2.84584e-08,0.780031,0.000802529,-8.50632e-07,3.87579e-09,0.780833,0.00080084,-8.39005e-07,1.29552e-08,0.781633,0.0007992,-8.00139e-07,3.90804e-09,0.782432,0.000797612,-7.88415e-07,-2.85874e-08,0.783228,0.000795949,-8.74177e-07,5.0837e-08,0.784023,0.000794353,-7.21666e-07,-5.55513e-08,0.784817,0.000792743,-8.8832e-07,5.21587e-08,0.785609,0.000791123,-7.31844e-07,-3.38744e-08,0.786399,0.000789558,-8.33467e-07,2.37342e-08,0.787188,0.000787962,-7.62264e-07,-1.45775e-09,0.787975,0.000786433,-7.66638e-07,-1.79034e-08,0.788761,0.000784846,-8.20348e-07,1.34665e-08,0.789545,0.000783246,-7.79948e-07,2.3642e-08,0.790327,0.000781757,-7.09022e-07,-4.84297e-08,0.791108,0.000780194,-8.54311e-07,5.08674e-08,0.791888,0.000778638,-7.01709e-07,-3.58303e-08,0.792666,0.000777127,-8.092e-07,3.28493e-08,0.793442,0.000775607,-7.10652e-07,-3.59624e-08,0.794217,0.000774078,-8.1854e-07,5.13959e-08,0.79499,0.000772595,-6.64352e-07,-5.04121e-08,0.795762,0.000771115,-8.15588e-07,3.10431e-08,0.796532,0.000769577,-7.22459e-07,-1.41557e-08,0.797301,0.00076809,-7.64926e-07,2.55795e-08,0.798069,0.000766636,-6.88187e-07,-2.85578e-08,0.798835,0.000765174,-7.73861e-07,2.90472e-08,0.799599,0.000763714,-6.86719e-07,-2.80262e-08,0.800362,0.000762256,-7.70798e-07,2.34531e-08,0.801123,0.000760785,-7.00438e-07,-6.18144e-09,0.801884,0.000759366,-7.18983e-07,1.27263e-09,0.802642,0.000757931,-7.15165e-07,1.09101e-09,0.803399,0.000756504,-7.11892e-07,-5.63675e-09,0.804155,0.000755064,-7.28802e-07,2.14559e-08,0.80491,0.00075367,-6.64434e-07,-2.05821e-08,0.805663,0.00075228,-7.26181e-07,1.26812e-09,0.806414,0.000750831,-7.22377e-07,1.55097e-08,0.807164,0.000749433,-6.75848e-07,-3.70216e-09,0.807913,0.00074807,-6.86954e-07,-7.0105e-10,0.80866,0.000746694,-6.89057e-07,6.5063e-09,0.809406,0.000745336,-6.69538e-07,-2.53242e-08,0.810151,0.000743921,-7.45511e-07,3.51858e-08,0.810894,0.000742535,-6.39953e-07,3.79034e-09,0.811636,0.000741267,-6.28582e-07,-5.03471e-08,0.812377,0.000739858,-7.79624e-07,7.83886e-08,0.813116,0.000738534,-5.44458e-07,-8.43935e-08,0.813854,0.000737192,-7.97638e-07,8.03714e-08,0.81459,0.000735838,-5.56524e-07,-5.82784e-08,0.815325,0.00073455,-7.31359e-07,3.35329e-08,0.816059,0.000733188,-6.3076e-07,-1.62486e-08,0.816792,0.000731878,-6.79506e-07,3.14614e-08,0.817523,0.000730613,-5.85122e-07,-4.99925e-08,0.818253,0.000729293,-7.35099e-07,4.92994e-08,0.818982,0.000727971,-5.87201e-07,-2.79959e-08,0.819709,0.000726712,-6.71189e-07,3.07959e-09,0.820435,0.000725379,-6.6195e-07,1.56777e-08,0.82116,0.000724102,-6.14917e-07,-6.18564e-09,0.821883,0.000722854,-6.33474e-07,9.06488e-09,0.822606,0.000721614,-6.06279e-07,-3.00739e-08,0.823327,0.000720311,-6.96501e-07,5.16262e-08,0.824046,0.000719073,-5.41623e-07,-5.72214e-08,0.824765,0.000717818,-7.13287e-07,5.80503e-08,0.825482,0.000716566,-5.39136e-07,-5.57703e-08,0.826198,0.00071532,-7.06447e-07,4.58215e-08,0.826912,0.000714045,-5.68983e-07,-8.30636e-09,0.827626,0.000712882,-5.93902e-07,-1.25961e-08,0.828338,0.000711656,-6.3169e-07,-9.13985e-10,0.829049,0.00071039,-6.34432e-07,1.62519e-08,0.829759,0.00070917,-5.85676e-07,-4.48904e-09,0.830468,0.000707985,-5.99143e-07,1.70418e-09,0.831175,0.000706792,-5.9403e-07,-2.32768e-09,0.831881,0.000705597,-6.01014e-07,7.60648e-09,0.832586,0.000704418,-5.78194e-07,-2.80982e-08,0.83329,0.000703177,-6.62489e-07,4.51817e-08,0.833993,0.000701988,-5.26944e-07,-3.34192e-08,0.834694,0.000700834,-6.27201e-07,2.88904e-08,0.835394,0.000699666,-5.4053e-07,-2.25378e-08,0.836093,0.000698517,-6.08143e-07,1.65589e-09,0.836791,0.000697306,-6.03176e-07,1.59142e-08,0.837488,0.000696147,-5.55433e-07,-5.70801e-09,0.838184,0.000695019,-5.72557e-07,6.91792e-09,0.838878,0.000693895,-5.51803e-07,-2.19637e-08,0.839571,0.000692725,-6.17694e-07,2.13321e-08,0.840263,0.000691554,-5.53698e-07,-3.75996e-09,0.840954,0.000690435,-5.64978e-07,-6.29219e-09,0.841644,0.000689287,-5.83855e-07,2.89287e-08,0.842333,0.000688206,-4.97068e-07,-4.98181e-08,0.843021,0.000687062,-6.46523e-07,5.11344e-08,0.843707,0.000685922,-4.9312e-07,-3.55102e-08,0.844393,0.00068483,-5.9965e-07,3.13019e-08,0.845077,0.000683724,-5.05745e-07,-3.00925e-08,0.84576,0.000682622,-5.96022e-07,2.94636e-08,0.846442,0.000681519,-5.07631e-07,-2.81572e-08,0.847123,0.000680419,-5.92103e-07,2.35606e-08,0.847803,0.000679306,-5.21421e-07,-6.48045e-09,0.848482,0.000678243,-5.40863e-07,2.36124e-09,0.849159,0.000677169,-5.33779e-07,-2.96461e-09,0.849836,0.000676092,-5.42673e-07,9.49728e-09,0.850512,0.000675035,-5.14181e-07,-3.50245e-08,0.851186,0.000673902,-6.19254e-07,7.09959e-08,0.851859,0.000672876,-4.06267e-07,-7.01453e-08,0.852532,0.000671853,-6.16703e-07,3.07714e-08,0.853203,0.000670712,-5.24388e-07,6.66423e-09,0.853873,0.000669684,-5.04396e-07,2.17629e-09,0.854542,0.000668681,-4.97867e-07,-1.53693e-08,0.855211,0.000667639,-5.43975e-07,-3.03752e-10,0.855878,0.000666551,-5.44886e-07,1.65844e-08,0.856544,0.000665511,-4.95133e-07,-6.42907e-09,0.857209,0.000664501,-5.1442e-07,9.13195e-09,0.857873,0.0006635,-4.87024e-07,-3.00987e-08,0.858536,0.000662435,-5.7732e-07,5.16584e-08,0.859198,0.000661436,-4.22345e-07,-5.73255e-08,0.859859,0.000660419,-5.94322e-07,5.84343e-08,0.860518,0.000659406,-4.19019e-07,-5.72022e-08,0.861177,0.000658396,-5.90626e-07,5.11653e-08,0.861835,0.000657368,-4.3713e-07,-2.82495e-08,0.862492,0.000656409,-5.21878e-07,2.22788e-09,0.863148,0.000655372,-5.15195e-07,1.9338e-08,0.863803,0.0006544,-4.5718e-07,-1.99754e-08,0.864457,0.000653425,-5.17107e-07,9.59024e-10,0.86511,0.000652394,-5.1423e-07,1.61393e-08,0.865762,0.000651414,-4.65812e-07,-5.91149e-09,0.866413,0.000650465,-4.83546e-07,7.50665e-09,0.867063,0.00064952,-4.61026e-07,-2.4115e-08,0.867712,0.000648526,-5.33371e-07,2.93486e-08,0.86836,0.000647547,-4.45325e-07,-3.36748e-08,0.869007,0.000646555,-5.4635e-07,4.57461e-08,0.869653,0.0006456,-4.09112e-07,-3.01002e-08,0.870298,0.000644691,-4.99412e-07,1.50501e-08,0.870942,0.000643738,-4.54262e-07,-3.01002e-08,0.871585,0.000642739,-5.44563e-07,4.57461e-08,0.872228,0.000641787,-4.07324e-07,-3.36748e-08,0.872869,0.000640871,-5.08349e-07,2.93486e-08,0.873509,0.000639943,-4.20303e-07,-2.4115e-08,0.874149,0.00063903,-4.92648e-07,7.50655e-09,0.874787,0.000638067,-4.70128e-07,-5.91126e-09,0.875425,0.000637109,-4.87862e-07,1.61385e-08,0.876062,0.000636182,-4.39447e-07,9.61961e-10,0.876697,0.000635306,-4.36561e-07,-1.99863e-08,0.877332,0.000634373,-4.9652e-07,1.93785e-08,0.877966,0.000633438,-4.38384e-07,2.07697e-09,0.878599,0.000632567,-4.32153e-07,-2.76864e-08,0.879231,0.00063162,-5.15212e-07,4.90641e-08,0.879862,0.000630737,-3.6802e-07,-4.93606e-08,0.880493,0.000629852,-5.16102e-07,2.9169e-08,0.881122,0.000628908,-4.28595e-07,-7.71083e-09,0.881751,0.000628027,-4.51727e-07,1.6744e-09,0.882378,0.000627129,-4.46704e-07,1.01317e-09,0.883005,0.000626239,-4.43665e-07,-5.72703e-09,0.883631,0.000625334,-4.60846e-07,2.1895e-08,0.884255,0.000624478,-3.95161e-07,-2.22481e-08,0.88488,0.000623621,-4.61905e-07,7.4928e-09,0.885503,0.00062272,-4.39427e-07,-7.72306e-09,0.886125,0.000621818,-4.62596e-07,2.33995e-08,0.886746,0.000620963,-3.92398e-07,-2.62704e-08,0.887367,0.000620099,-4.71209e-07,2.20775e-08,0.887987,0.000619223,-4.04976e-07,-2.43496e-09,0.888605,0.000618406,-4.12281e-07,-1.23377e-08,0.889223,0.000617544,-4.49294e-07,-7.81876e-09,0.88984,0.000616622,-4.72751e-07,4.36128e-08,0.890457,0.000615807,-3.41912e-07,-4.7423e-08,0.891072,0.000614981,-4.84181e-07,2.68698e-08,0.891687,0.000614093,-4.03572e-07,-4.51384e-10,0.8923,0.000613285,-4.04926e-07,-2.50643e-08,0.892913,0.0006124,-4.80119e-07,4.11038e-08,0.893525,0.000611563,-3.56808e-07,-2.01414e-08,0.894136,0.000610789,-4.17232e-07,-2.01426e-08,0.894747,0.000609894,-4.7766e-07,4.11073e-08,0.895356,0.000609062,-3.54338e-07,-2.50773e-08,0.895965,0.000608278,-4.2957e-07,-4.02954e-10,0.896573,0.000607418,-4.30779e-07,2.66891e-08,0.89718,0.000606636,-3.50711e-07,-4.67489e-08,0.897786,0.000605795,-4.90958e-07,4.10972e-08,0.898391,0.000604936,-3.67666e-07,1.56948e-09,0.898996,0.000604205,-3.62958e-07,-4.73751e-08,0.8996,0.000603337,-5.05083e-07,6.87214e-08,0.900202,0.000602533,-2.98919e-07,-4.86966e-08,0.900805,0.000601789,-4.45009e-07,6.85589e-09,0.901406,0.00060092,-4.24441e-07,2.1273e-08,0.902007,0.000600135,-3.60622e-07,-3.23434e-08,0.902606,0.000599317,-4.57652e-07,4.84959e-08,0.903205,0.000598547,-3.12164e-07,-4.24309e-08,0.903803,0.000597795,-4.39457e-07,2.01844e-09,0.904401,0.000596922,-4.33402e-07,3.43571e-08,0.904997,0.000596159,-3.30331e-07,-2.02374e-08,0.905593,0.000595437,-3.91043e-07,-1.30123e-08,0.906188,0.000594616,-4.3008e-07,1.26819e-08,0.906782,0.000593794,-3.92034e-07,2.18894e-08,0.907376,0.000593076,-3.26366e-07,-4.06349e-08,0.907968,0.000592301,-4.4827e-07,2.1441e-08,0.90856,0.000591469,-3.83947e-07,1.44754e-08,0.909151,0.000590744,-3.40521e-07,-1.97379e-08,0.909742,0.000590004,-3.99735e-07,4.87161e-09,0.910331,0.000589219,-3.8512e-07,2.51532e-10,0.91092,0.00058845,-3.84366e-07,-5.87776e-09,0.911508,0.000587663,-4.01999e-07,2.32595e-08,0.912096,0.000586929,-3.3222e-07,-2.75554e-08,0.912682,0.000586182,-4.14887e-07,2.73573e-08,0.913268,0.000585434,-3.32815e-07,-2.22692e-08,0.913853,0.000584702,-3.99622e-07,2.11486e-09,0.914437,0.000583909,-3.93278e-07,1.38098e-08,0.915021,0.000583164,-3.51848e-07,2.25042e-09,0.915604,0.000582467,-3.45097e-07,-2.28115e-08,0.916186,0.000581708,-4.13531e-07,2.93911e-08,0.916767,0.000580969,-3.25358e-07,-3.51481e-08,0.917348,0.000580213,-4.30803e-07,5.15967e-08,0.917928,0.000579506,-2.76012e-07,-5.20296e-08,0.918507,0.000578798,-4.32101e-07,3.73124e-08,0.919085,0.000578046,-3.20164e-07,-3.76154e-08,0.919663,0.000577293,-4.3301e-07,5.35447e-08,0.92024,0.000576587,-2.72376e-07,-5.7354e-08,0.920816,0.000575871,-4.44438e-07,5.66621e-08,0.921391,0.000575152,-2.74452e-07,-5.00851e-08,0.921966,0.000574453,-4.24707e-07,2.4469e-08,0.92254,0.000573677,-3.513e-07,1.18138e-08,0.923114,0.000573009,-3.15859e-07,-1.21195e-08,0.923686,0.000572341,-3.52217e-07,-2.29403e-08,0.924258,0.000571568,-4.21038e-07,4.4276e-08,0.924829,0.000570859,-2.8821e-07,-3.49546e-08,0.9254,0.000570178,-3.93074e-07,3.59377e-08,0.92597,0.000569499,-2.85261e-07,-4.91915e-08,0.926539,0.000568781,-4.32835e-07,4.16189e-08,0.927107,0.00056804,-3.07979e-07,1.92523e-09,0.927675,0.00056743,-3.02203e-07,-4.93198e-08,0.928242,0.000566678,-4.50162e-07,7.61447e-08,0.928809,0.000566006,-2.21728e-07,-7.6445e-08,0.929374,0.000565333,-4.51063e-07,5.08216e-08,0.929939,0.000564583,-2.98599e-07,-7.63212e-09,0.930503,0.000563963,-3.21495e-07,-2.02931e-08,0.931067,0.000563259,-3.82374e-07,2.92001e-08,0.93163,0.000562582,-2.94774e-07,-3.69025e-08,0.932192,0.000561882,-4.05482e-07,5.88053e-08,0.932754,0.000561247,-2.29066e-07,-7.91094e-08,0.933315,0.000560552,-4.66394e-07,7.88184e-08,0.933875,0.000559856,-2.29939e-07,-5.73501e-08,0.934434,0.000559224,-4.01989e-07,3.13727e-08,0.934993,0.000558514,-3.07871e-07,-8.53611e-09,0.935551,0.000557873,-3.33479e-07,2.77175e-09,0.936109,0.000557214,-3.25164e-07,-2.55091e-09,0.936666,0.000556556,-3.32817e-07,7.43188e-09,0.937222,0.000555913,-3.10521e-07,-2.71766e-08,0.937778,0.00055521,-3.92051e-07,4.167e-08,0.938333,0.000554551,-2.67041e-07,-2.02941e-08,0.938887,0.000553956,-3.27923e-07,-2.00984e-08,0.93944,0.00055324,-3.88218e-07,4.10828e-08,0.939993,0.000552587,-2.6497e-07,-2.50237e-08,0.940546,0.000551982,-3.40041e-07,-5.92583e-10,0.941097,0.0005513,-3.41819e-07,2.7394e-08,0.941648,0.000550698,-2.59637e-07,-4.93788e-08,0.942199,0.000550031,-4.07773e-07,5.09119e-08,0.942748,0.000549368,-2.55038e-07,-3.50595e-08,0.943297,0.000548753,-3.60216e-07,2.97214e-08,0.943846,0.000548122,-2.71052e-07,-2.42215e-08,0.944394,0.000547507,-3.43716e-07,7.55985e-09,0.944941,0.000546842,-3.21037e-07,-6.01796e-09,0.945487,0.000546182,-3.3909e-07,1.65119e-08,0.946033,0.000545553,-2.89555e-07,-4.2498e-10,0.946578,0.000544973,-2.9083e-07,-1.4812e-08,0.947123,0.000544347,-3.35266e-07,6.83068e-11,0.947667,0.000543676,-3.35061e-07,1.45388e-08,0.94821,0.00054305,-2.91444e-07,1.38123e-09,0.948753,0.000542471,-2.87301e-07,-2.00637e-08,0.949295,0.000541836,-3.47492e-07,1.92688e-08,0.949837,0.000541199,-2.89685e-07,2.59298e-09,0.950378,0.000540628,-2.81906e-07,-2.96407e-08,0.950918,0.000539975,-3.70829e-07,5.63652e-08,0.951458,0.000539402,-2.01733e-07,-7.66107e-08,0.951997,0.000538769,-4.31565e-07,7.12638e-08,0.952535,0.00053812,-2.17774e-07,-2.96305e-08,0.953073,0.000537595,-3.06665e-07,-1.23464e-08,0.95361,0.000536945,-3.43704e-07,1.94114e-08,0.954147,0.000536316,-2.8547e-07,-5.69451e-09,0.954683,0.000535728,-3.02554e-07,3.36666e-09,0.955219,0.000535133,-2.92454e-07,-7.77208e-09,0.955753,0.000534525,-3.1577e-07,2.77216e-08,0.956288,0.000533976,-2.32605e-07,-4.35097e-08,0.956821,0.00053338,-3.63134e-07,2.7108e-08,0.957354,0.000532735,-2.8181e-07,-5.31772e-09,0.957887,0.000532156,-2.97764e-07,-5.83718e-09,0.958419,0.000531543,-3.15275e-07,2.86664e-08,0.95895,0.000530998,-2.29276e-07,-4.9224e-08,0.959481,0.000530392,-3.76948e-07,4.90201e-08,0.960011,0.000529785,-2.29887e-07,-2.76471e-08,0.96054,0.000529243,-3.12829e-07,1.96385e-09,0.961069,0.000528623,-3.06937e-07,1.97917e-08,0.961598,0.000528068,-2.47562e-07,-2.15261e-08,0.962125,0.000527508,-3.1214e-07,6.70795e-09,0.962653,0.000526904,-2.92016e-07,-5.30573e-09,0.963179,0.000526304,-3.07934e-07,1.4515e-08,0.963705,0.000525732,-2.64389e-07,6.85048e-09,0.964231,0.000525224,-2.43837e-07,-4.19169e-08,0.964756,0.00052461,-3.69588e-07,4.1608e-08,0.96528,0.000523996,-2.44764e-07,-5.30598e-09,0.965804,0.000523491,-2.60682e-07,-2.03841e-08,0.966327,0.000522908,-3.21834e-07,2.72378e-08,0.966849,0.000522346,-2.40121e-07,-2.89625e-08,0.967371,0.000521779,-3.27008e-07,2.90075e-08,0.967893,0.000521212,-2.39986e-07,-2.74629e-08,0.968414,0.00052065,-3.22374e-07,2.12396e-08,0.968934,0.000520069,-2.58656e-07,2.10922e-09,0.969454,0.000519558,-2.52328e-07,-2.96765e-08,0.969973,0.000518964,-3.41357e-07,5.6992e-08,0.970492,0.000518452,-1.70382e-07,-7.90821e-08,0.97101,0.000517874,-4.07628e-07,8.05224e-08,0.971528,0.000517301,-1.66061e-07,-6.41937e-08,0.972045,0.000516776,-3.58642e-07,5.70429e-08,0.972561,0.00051623,-1.87513e-07,-4.47686e-08,0.973077,0.00051572,-3.21819e-07,2.82237e-09,0.973593,0.000515085,-3.13352e-07,3.34792e-08,0.974108,0.000514559,-2.12914e-07,-1.75298e-08,0.974622,0.000514081,-2.65503e-07,-2.29648e-08,0.975136,0.000513481,-3.34398e-07,4.97843e-08,0.975649,0.000512961,-1.85045e-07,-5.6963e-08,0.976162,0.00051242,-3.55934e-07,5.88585e-08,0.976674,0.000511885,-1.79359e-07,-5.92616e-08,0.977185,0.000511348,-3.57143e-07,5.89785e-08,0.977696,0.000510811,-1.80208e-07,-5.74433e-08,0.978207,0.000510278,-3.52538e-07,5.15854e-08,0.978717,0.000509728,-1.97781e-07,-2.9689e-08,0.979226,0.000509243,-2.86848e-07,7.56591e-09,0.979735,0.000508692,-2.64151e-07,-5.74649e-10,0.980244,0.000508162,-2.65875e-07,-5.26732e-09,0.980752,0.000507615,-2.81677e-07,2.16439e-08,0.981259,0.000507116,-2.16745e-07,-2.17037e-08,0.981766,0.000506618,-2.81856e-07,5.56636e-09,0.982272,0.000506071,-2.65157e-07,-5.61689e-10,0.982778,0.000505539,-2.66842e-07,-3.31963e-09,0.983283,0.000504995,-2.76801e-07,1.38402e-08,0.983788,0.000504483,-2.3528e-07,7.56339e-09,0.984292,0.000504035,-2.1259e-07,-4.40938e-08,0.984796,0.000503478,-3.44871e-07,4.96026e-08,0.985299,0.000502937,-1.96064e-07,-3.51071e-08,0.985802,0.000502439,-3.01385e-07,3.12212e-08,0.986304,0.00050193,-2.07721e-07,-3.0173e-08,0.986806,0.000501424,-2.9824e-07,2.9866e-08,0.987307,0.000500917,-2.08642e-07,-2.96865e-08,0.987808,0.000500411,-2.97702e-07,2.92753e-08,0.988308,0.000499903,-2.09876e-07,-2.78101e-08,0.988807,0.0004994,-2.93306e-07,2.23604e-08,0.989307,0.000498881,-2.26225e-07,-2.02681e-09,0.989805,0.000498422,-2.32305e-07,-1.42531e-08,0.990303,0.000497915,-2.75065e-07,-5.65232e-10,0.990801,0.000497363,-2.76761e-07,1.65141e-08,0.991298,0.000496859,-2.27218e-07,-5.88639e-09,0.991795,0.000496387,-2.44878e-07,7.0315e-09,0.992291,0.000495918,-2.23783e-07,-2.22396e-08,0.992787,0.000495404,-2.90502e-07,2.23224e-08,0.993282,0.00049489,-2.23535e-07,-7.44543e-09,0.993776,0.000494421,-2.45871e-07,7.45924e-09,0.994271,0.000493951,-2.23493e-07,-2.23915e-08,0.994764,0.000493437,-2.90668e-07,2.25021e-08,0.995257,0.000492923,-2.23161e-07,-8.01218e-09,0.99575,0.000492453,-2.47198e-07,9.54669e-09,0.996242,0.000491987,-2.18558e-07,-3.01746e-08,0.996734,0.000491459,-3.09082e-07,5.1547e-08,0.997225,0.000490996,-1.54441e-07,-5.68039e-08,0.997716,0.000490517,-3.24853e-07,5.64594e-08,0.998206,0.000490036,-1.55474e-07,-4.98245e-08,0.998696,0.000489576,-3.04948e-07,2.36292e-08,0.999186,0.000489037,-2.3406e-07,1.49121e-08,0.999674,0.000488613,-1.89324e-07,-2.3673e-08,1.00016,0.000488164,-2.60343e-07,2.01754e-08,1.00065,0.000487704,-1.99816e-07,-5.70288e-08,1.00114,0.000487133,-3.70903e-07,8.87303e-08,1.00162,0.000486657,-1.04712e-07,-5.94737e-08,1.00211,0.000486269,-2.83133e-07,2.99553e-08,1.0026,0.000485793,-1.93267e-07,-6.03474e-08,1.00308,0.000485225,-3.74309e-07,9.2225e-08,1.00357,0.000484754,-9.76345e-08,-7.0134e-08,1.00405,0.000484348,-3.08036e-07,6.91016e-08,1.00454,0.000483939,-1.00731e-07,-8.70633e-08,1.00502,0.000483476,-3.61921e-07,4.07328e-08,1.0055,0.000482875,-2.39723e-07,4.33413e-08,1.00599,0.000482525,-1.09699e-07,-9.48886e-08,1.00647,0.000482021,-3.94365e-07,9.77947e-08,1.00695,0.000481526,-1.00981e-07,-5.78713e-08,1.00743,0.00048115,-2.74595e-07,1.44814e-08,1.00791,0.000480645,-2.31151e-07,-5.42665e-11,1.00839,0.000480182,-2.31314e-07,-1.42643e-08,1.00887,0.000479677,-2.74106e-07,5.71115e-08,1.00935,0.0004793,-1.02772e-07,-9.49724e-08,1.00983,0.000478809,-3.87689e-07,8.43596e-08,1.01031,0.000478287,-1.3461e-07,-4.04755e-09,1.01079,0.000478006,-1.46753e-07,-6.81694e-08,1.01127,0.000477508,-3.51261e-07,3.83067e-08,1.01174,0.00047692,-2.36341e-07,3.41521e-08,1.01222,0.00047655,-1.33885e-07,-5.57058e-08,1.0127,0.000476115,-3.01002e-07,6.94616e-08,1.01317,0.000475721,-9.26174e-08,-1.02931e-07,1.01365,0.000475227,-4.01412e-07,1.03846e-07,1.01412,0.000474736,-8.98751e-08,-7.40321e-08,1.0146,0.000474334,-3.11971e-07,7.30735e-08,1.01507,0.00047393,-9.27508e-08,-9.90527e-08,1.01554,0.000473447,-3.89909e-07,8.47188e-08,1.01602,0.000472921,-1.35753e-07,-1.40381e-09,1.01649,0.000472645,-1.39964e-07,-7.91035e-08,1.01696,0.000472128,-3.77275e-07,7.93993e-08,1.01744,0.000471612,-1.39077e-07,-7.52607e-11,1.01791,0.000471334,-1.39302e-07,-7.90983e-08,1.01838,0.000470818,-3.76597e-07,7.80499e-08,1.01885,0.000470299,-1.42448e-07,5.31733e-09,1.01932,0.00047003,-1.26496e-07,-9.93193e-08,1.01979,0.000469479,-4.24453e-07,1.53541e-07,1.02026,0.00046909,3.617e-08,-1.57217e-07,1.02073,0.000468691,-4.35482e-07,1.177e-07,1.02119,0.000468173,-8.23808e-08,-7.51659e-08,1.02166,0.000467783,-3.07878e-07,6.37538e-08,1.02213,0.000467358,-1.16617e-07,-6.064e-08,1.0226,0.000466943,-2.98537e-07,5.9597e-08,1.02306,0.000466525,-1.19746e-07,-5.85386e-08,1.02353,0.00046611,-2.95362e-07,5.53482e-08,1.024,0.000465685,-1.29317e-07,-4.36449e-08,1.02446,0.000465296,-2.60252e-07,2.20268e-11,1.02493,0.000464775,-2.60186e-07,4.35568e-08,1.02539,0.000464386,-1.29516e-07,-5.50398e-08,1.02586,0.000463961,-2.94635e-07,5.73932e-08,1.02632,0.000463544,-1.22456e-07,-5.53236e-08,1.02678,0.000463133,-2.88426e-07,4.46921e-08,1.02725,0.000462691,-1.5435e-07,-4.23534e-09,1.02771,0.000462369,-1.67056e-07,-2.77507e-08,1.02817,0.000461952,-2.50308e-07,-3.97101e-09,1.02863,0.000461439,-2.62221e-07,4.36348e-08,1.02909,0.000461046,-1.31317e-07,-5.13589e-08,1.02955,0.000460629,-2.85394e-07,4.25913e-08,1.03001,0.000460186,-1.5762e-07,2.0285e-10,1.03047,0.000459871,-1.57011e-07,-4.34027e-08,1.03093,0.000459427,-2.87219e-07,5.41987e-08,1.03139,0.000459015,-1.24623e-07,-5.4183e-08,1.03185,0.000458604,-2.87172e-07,4.33239e-08,1.03231,0.000458159,-1.572e-07,9.65817e-11,1.03277,0.000457845,-1.56911e-07,-4.37103e-08,1.03323,0.0004574,-2.88041e-07,5.55351e-08,1.03368,0.000456991,-1.21436e-07,-5.9221e-08,1.03414,0.00045657,-2.99099e-07,6.21394e-08,1.0346,0.000456158,-1.1268e-07,-7.01275e-08,1.03505,0.000455723,-3.23063e-07,9.91614e-08,1.03551,0.000455374,-2.55788e-08,-8.80996e-08,1.03596,0.000455058,-2.89878e-07,1.48184e-08,1.03642,0.000454523,-2.45422e-07,2.88258e-08,1.03687,0.000454119,-1.58945e-07,-1.09125e-08,1.03733,0.000453768,-1.91682e-07,1.48241e-08,1.03778,0.000453429,-1.4721e-07,-4.83838e-08,1.03823,0.00045299,-2.92361e-07,5.95019e-08,1.03869,0.000452584,-1.13856e-07,-7.04146e-08,1.03914,0.000452145,-3.25099e-07,1.02947e-07,1.03959,0.000451803,-1.62583e-08,-1.02955e-07,1.04004,0.000451462,-3.25123e-07,7.04544e-08,1.04049,0.000451023,-1.1376e-07,-5.96534e-08,1.04094,0.000450616,-2.9272e-07,4.89499e-08,1.04139,0.000450178,-1.45871e-07,-1.69369e-08,1.04184,0.000449835,-1.96681e-07,1.87977e-08,1.04229,0.000449498,-1.40288e-07,-5.82539e-08,1.04274,0.000449043,-3.1505e-07,9.50087e-08,1.04319,0.000448698,-3.00238e-08,-8.33623e-08,1.04364,0.000448388,-2.80111e-07,2.20363e-11,1.04409,0.000447828,-2.80045e-07,8.32742e-08,1.04454,0.000447517,-3.02221e-08,-9.47002e-08,1.04498,0.000447173,-3.14323e-07,5.7108e-08,1.04543,0.000446716,-1.42999e-07,-1.45225e-08,1.04588,0.000446386,-1.86566e-07,9.82022e-10,1.04632,0.000446016,-1.8362e-07,1.05944e-08,1.04677,0.00044568,-1.51837e-07,-4.33597e-08,1.04721,0.000445247,-2.81916e-07,4.36352e-08,1.04766,0.000444814,-1.51011e-07,-1.19717e-08,1.0481,0.000444476,-1.86926e-07,4.25158e-09,1.04855,0.000444115,-1.74171e-07,-5.03461e-09,1.04899,0.000443751,-1.89275e-07,1.58868e-08,1.04944,0.00044342,-1.41614e-07,-5.85127e-08,1.04988,0.000442961,-3.17152e-07,9.89548e-08,1.05032,0.000442624,-2.0288e-08,-9.88878e-08,1.05076,0.000442287,-3.16951e-07,5.81779e-08,1.05121,0.000441827,-1.42418e-07,-1.46144e-08,1.05165,0.000441499,-1.86261e-07,2.79892e-10,1.05209,0.000441127,-1.85421e-07,1.34949e-08,1.05253,0.000440797,-1.44937e-07,-5.42594e-08,1.05297,0.000440344,-3.07715e-07,8.43335e-08,1.05341,0.000439982,-5.47146e-08,-4.46558e-08,1.05385,0.000439738,-1.88682e-07,-2.49193e-08,1.05429,0.000439286,-2.6344e-07,2.5124e-08,1.05473,0.000438835,-1.88068e-07,4.36328e-08,1.05517,0.000438589,-5.71699e-08,-8.04459e-08,1.05561,0.000438234,-2.98508e-07,3.97324e-08,1.05605,0.000437756,-1.79311e-07,4.07258e-08,1.05648,0.000437519,-5.71332e-08,-8.34263e-08,1.05692,0.000437155,-3.07412e-07,5.45608e-08,1.05736,0.000436704,-1.4373e-07,-1.56078e-08,1.05779,0.000436369,-1.90553e-07,7.87043e-09,1.05823,0.000436012,-1.66942e-07,-1.58739e-08,1.05867,0.00043563,-2.14563e-07,5.56251e-08,1.0591,0.000435368,-4.76881e-08,-8.74172e-08,1.05954,0.000435011,-3.0994e-07,5.56251e-08,1.05997,0.000434558,-1.43064e-07,-1.58739e-08,1.06041,0.000434224,-1.90686e-07,7.87042e-09,1.06084,0.000433866,-1.67075e-07,-1.56078e-08,1.06127,0.000433485,-2.13898e-07,5.45609e-08,1.06171,0.000433221,-5.02157e-08,-8.34263e-08,1.06214,0.00043287,-3.00495e-07,4.07258e-08,1.06257,0.000432391,-1.78317e-07,3.97325e-08,1.063,0.000432154,-5.91198e-08,-8.04464e-08,1.06344,0.000431794,-3.00459e-07,4.36347e-08,1.06387,0.000431324,-1.69555e-07,2.5117e-08,1.0643,0.000431061,-9.42041e-08,-2.48934e-08,1.06473,0.000430798,-1.68884e-07,-4.47527e-08,1.06516,0.000430326,-3.03142e-07,8.46951e-08,1.06559,0.000429973,-4.90573e-08,-5.56089e-08,1.06602,0.000429708,-2.15884e-07,1.85314e-08,1.06645,0.000429332,-1.6029e-07,-1.85166e-08,1.06688,0.000428956,-2.1584e-07,5.5535e-08,1.06731,0.000428691,-4.92347e-08,-8.44142e-08,1.06774,0.000428339,-3.02477e-07,4.37032e-08,1.06816,0.000427865,-1.71368e-07,2.88107e-08,1.06859,0.000427609,-8.49356e-08,-3.97367e-08,1.06902,0.00042732,-2.04146e-07,1.09267e-08,1.06945,0.000426945,-1.71365e-07,-3.97023e-09,1.06987,0.00042659,-1.83276e-07,4.9542e-09,1.0703,0.000426238,-1.68414e-07,-1.58466e-08,1.07073,0.000425854,-2.15953e-07,5.84321e-08,1.07115,0.000425597,-4.0657e-08,-9.86725e-08,1.07158,0.00042522,-3.36674e-07,9.78392e-08,1.072,0.00042484,-4.31568e-08,-5.42658e-08,1.07243,0.000424591,-2.05954e-07,1.45377e-11,1.07285,0.000424179,-2.0591e-07,5.42076e-08,1.07328,0.00042393,-4.32877e-08,-9.76357e-08,1.0737,0.00042355,-3.36195e-07,9.79165e-08,1.07412,0.000423172,-4.24451e-08,-5.56118e-08,1.07455,0.00042292,-2.09281e-07,5.32143e-09,1.07497,0.000422518,-1.93316e-07,3.43261e-08,1.07539,0.000422234,-9.0338e-08,-2.34165e-08,1.07581,0.000421983,-1.60588e-07,-5.98692e-08,1.07623,0.000421482,-3.40195e-07,1.43684e-07,1.07666,0.000421233,9.08574e-08,-1.5724e-07,1.07708,0.000420943,-3.80862e-07,1.27647e-07,1.0775,0.000420564,2.0791e-09,-1.1493e-07,1.07792,0.000420223,-3.4271e-07,9.36534e-08,1.07834,0.000419819,-6.17499e-08,-2.12653e-08,1.07876,0.000419632,-1.25546e-07,-8.59219e-09,1.07918,0.000419355,-1.51322e-07,-6.35752e-08,1.0796,0.000418861,-3.42048e-07,1.43684e-07,1.08002,0.000418608,8.90034e-08,-1.53532e-07,1.08043,0.000418326,-3.71593e-07,1.12817e-07,1.08085,0.000417921,-3.31414e-08,-5.93184e-08,1.08127,0.000417677,-2.11097e-07,5.24697e-09,1.08169,0.00041727,-1.95356e-07,3.83305e-08,1.0821,0.000416995,-8.03642e-08,-3.93597e-08,1.08252,0.000416716,-1.98443e-07,-1.0094e-10,1.08294,0.000416319,-1.98746e-07,3.97635e-08,1.08335,0.00041604,-7.94557e-08,-3.97437e-08,1.08377,0.000415762,-1.98687e-07,1.94215e-12,1.08419,0.000415365,-1.98681e-07,3.97359e-08,1.0846,0.000415087,-7.94732e-08,-3.97362e-08,1.08502,0.000414809,-1.98682e-07,-4.31063e-13,1.08543,0.000414411,-1.98683e-07,3.97379e-08,1.08584,0.000414133,-7.94694e-08,-3.97418e-08,1.08626,0.000413855,-1.98695e-07,2.00563e-11,1.08667,0.000413458,-1.98635e-07,3.96616e-08,1.08709,0.000413179,-7.965e-08,-3.9457e-08,1.0875,0.000412902,-1.98021e-07,-1.04281e-09,1.08791,0.000412502,-2.01149e-07,4.36282e-08,1.08832,0.000412231,-7.02648e-08,-5.42608e-08,1.08874,0.000411928,-2.33047e-07,5.42057e-08,1.08915,0.000411624,-7.04301e-08,-4.33527e-08,1.08956,0.000411353,-2.00488e-07,-4.07378e-12,1.08997,0.000410952,-2.005e-07,4.3369e-08,1.09038,0.000410681,-7.03934e-08,-5.42627e-08,1.09079,0.000410378,-2.33182e-07,5.44726e-08,1.0912,0.000410075,-6.97637e-08,-4.44186e-08,1.09161,0.000409802,-2.03019e-07,3.99235e-09,1.09202,0.000409408,-1.91042e-07,2.84491e-08,1.09243,0.000409111,-1.05695e-07,1.42043e-09,1.09284,0.000408904,-1.01434e-07,-3.41308e-08,1.09325,0.000408599,-2.03826e-07,1.58937e-08,1.09366,0.000408239,-1.56145e-07,-2.94438e-08,1.09406,0.000407838,-2.44476e-07,1.01881e-07,1.09447,0.000407655,6.11676e-08,-1.39663e-07,1.09488,0.000407358,-3.57822e-07,9.91432e-08,1.09529,0.00040694,-6.03921e-08,-1.84912e-08,1.09569,0.000406764,-1.15866e-07,-2.51785e-08,1.0961,0.000406457,-1.91401e-07,-4.03115e-12,1.09651,0.000406074,-1.91413e-07,2.51947e-08,1.09691,0.000405767,-1.15829e-07,1.84346e-08,1.09732,0.00040559,-6.05254e-08,-9.89332e-08,1.09772,0.000405172,-3.57325e-07,1.3888e-07,1.09813,0.000404874,5.93136e-08,-9.8957e-08,1.09853,0.000404696,-2.37557e-07,1.853e-08,1.09894,0.000404277,-1.81968e-07,2.48372e-08,1.09934,0.000403987,-1.07456e-07,1.33047e-09,1.09975,0.000403776,-1.03465e-07,-3.01591e-08,1.10015,0.000403479,-1.93942e-07,9.66054e-11,1.10055,0.000403091,-1.93652e-07,2.97727e-08,1.10096,0.000402793,-1.04334e-07,2.19273e-11,1.10136,0.000402585,-1.04268e-07,-2.98604e-08,1.10176,0.000402287,-1.93849e-07,2.10325e-10,1.10216,0.0004019,-1.93218e-07,2.90191e-08,1.10256,0.0004016,-1.06161e-07,2.92264e-09,1.10297,0.000401397,-9.73931e-08,-4.07096e-08,1.10337,0.00040108,-2.19522e-07,4.07067e-08,1.10377,0.000400763,-9.7402e-08,-2.90783e-09,1.10417,0.000400559,-1.06126e-07,-2.90754e-08,1.10457,0.00040026,-1.93352e-07,9.00021e-14,1.10497,0.000399873,-1.93351e-07,2.9075e-08,1.10537,0.000399574,-1.06126e-07,2.90902e-09,1.10577,0.00039937,-9.73992e-08,-4.07111e-08,1.10617,0.000399053,-2.19533e-07,4.07262e-08,1.10657,0.000398736,-9.73541e-08,-2.98424e-09,1.10697,0.000398533,-1.06307e-07,-2.87892e-08,1.10736,0.000398234,-1.92674e-07,-1.06824e-09,1.10776,0.000397845,-1.95879e-07,3.30622e-08,1.10816,0.000397552,-9.66926e-08,-1.19712e-08,1.10856,0.000397323,-1.32606e-07,1.48225e-08,1.10895,0.000397102,-8.81387e-08,-4.73187e-08,1.10935,0.000396784,-2.30095e-07,5.52429e-08,1.10975,0.00039649,-6.4366e-08,-5.44437e-08,1.11014,0.000396198,-2.27697e-07,4.33226e-08,1.11054,0.000395872,-9.77293e-08,3.62656e-10,1.11094,0.000395678,-9.66414e-08,-4.47732e-08,1.11133,0.00039535,-2.30961e-07,5.95208e-08,1.11173,0.000395067,-5.23985e-08,-7.41008e-08,1.11212,0.00039474,-2.74701e-07,1.17673e-07,1.11252,0.000394543,7.83181e-08,-1.58172e-07,1.11291,0.000394225,-3.96199e-07,1.57389e-07,1.1133,0.000393905,7.59679e-08,-1.13756e-07,1.1137,0.000393716,-2.653e-07,5.92165e-08,1.11409,0.000393363,-8.76507e-08,-3.90074e-09,1.11449,0.000393176,-9.93529e-08,-4.36136e-08,1.11488,0.000392846,-2.30194e-07,5.91457e-08,1.11527,0.000392563,-5.27564e-08,-7.376e-08,1.11566,0.000392237,-2.74037e-07,1.16685e-07,1.11606,0.000392039,7.60189e-08,-1.54562e-07,1.11645,0.000391727,-3.87667e-07,1.43935e-07,1.11684,0.000391384,4.4137e-08,-6.35487e-08,1.11723,0.000391281,-1.46509e-07,-8.94896e-09,1.11762,0.000390961,-1.73356e-07,-1.98647e-08,1.11801,0.000390555,-2.3295e-07,8.8408e-08,1.1184,0.000390354,3.22736e-08,-9.53486e-08,1.11879,0.000390133,-2.53772e-07,5.45677e-08,1.11918,0.000389789,-9.0069e-08,-3.71296e-09,1.11957,0.000389598,-1.01208e-07,-3.97159e-08,1.11996,0.000389276,-2.20355e-07,4.33671e-08,1.12035,0.000388966,-9.02542e-08,-1.45431e-08,1.12074,0.000388741,-1.33883e-07,1.48052e-08,1.12113,0.000388518,-8.94678e-08,-4.46778e-08,1.12152,0.000388205,-2.23501e-07,4.46966e-08,1.12191,0.000387892,-8.94114e-08,-1.48992e-08,1.12229,0.000387669,-1.34109e-07,1.49003e-08,1.12268,0.000387445,-8.94082e-08,-4.47019e-08,1.12307,0.000387132,-2.23514e-07,4.4698e-08,1.12345,0.000386819,-8.942e-08,-1.48806e-08,1.12384,0.000386596,-1.34062e-07,1.48245e-08,1.12423,0.000386372,-8.95885e-08,-4.44172e-08,1.12461,0.00038606,-2.2284e-07,4.36351e-08,1.125,0.000385745,-9.19348e-08,-1.09139e-08,1.12539,0.000385528,-1.24677e-07,2.05584e-11,1.12577,0.000385279,-1.24615e-07,1.08317e-08,1.12616,0.000385062,-9.21198e-08,-4.33473e-08,1.12654,0.000384748,-2.22162e-07,4.33481e-08,1.12693,0.000384434,-9.21174e-08,-1.08356e-08,1.12731,0.000384217,-1.24624e-07,-5.50907e-12,1.12769,0.000383968,-1.24641e-07,1.08577e-08,1.12808,0.000383751,-9.20679e-08,-4.34252e-08,1.12846,0.000383437,-2.22343e-07,4.36337e-08,1.12884,0.000383123,-9.14422e-08,-1.19005e-08,1.12923,0.000382904,-1.27144e-07,3.96813e-09,1.12961,0.000382662,-1.15239e-07,-3.97207e-09,1.12999,0.000382419,-1.27155e-07,1.19201e-08,1.13038,0.000382201,-9.1395e-08,-4.37085e-08,1.13076,0.000381887,-2.2252e-07,4.37046e-08,1.13114,0.000381573,-9.14068e-08,-1.19005e-08,1.13152,0.000381355,-1.27108e-07,3.89734e-09,1.1319,0.000381112,-1.15416e-07,-3.68887e-09,1.13228,0.00038087,-1.26483e-07,1.08582e-08,1.13266,0.00038065,-9.39083e-08,-3.97438e-08,1.13304,0.000380343,-2.1314e-07,2.89076e-08,1.13342,0.000380003,-1.26417e-07,4.33225e-08,1.1338,0.00037988,3.55072e-09,-8.29883e-08,1.13418,0.000379638,-2.45414e-07,5.0212e-08,1.13456,0.000379298,-9.47781e-08,1.34964e-09,1.13494,0.000379113,-9.07292e-08,-5.56105e-08,1.13532,0.000378764,-2.57561e-07,1.01883e-07,1.1357,0.000378555,4.80889e-08,-1.13504e-07,1.13608,0.000378311,-2.92423e-07,1.13713e-07,1.13646,0.000378067,4.87176e-08,-1.02931e-07,1.13683,0.000377856,-2.60076e-07,5.95923e-08,1.13721,0.000377514,-8.12988e-08,-1.62288e-08,1.13759,0.000377303,-1.29985e-07,5.32278e-09,1.13797,0.000377059,-1.14017e-07,-5.06237e-09,1.13834,0.000376816,-1.29204e-07,1.49267e-08,1.13872,0.000376602,-8.44237e-08,-5.46444e-08,1.1391,0.000376269,-2.48357e-07,8.44417e-08,1.13947,0.000376026,4.96815e-09,-4.47039e-08,1.13985,0.000375902,-1.29143e-07,-2.48355e-08,1.14023,0.000375569,-2.0365e-07,2.48368e-08,1.1406,0.000375236,-1.2914e-07,4.46977e-08,1.14098,0.000375112,4.95341e-09,-8.44184e-08,1.14135,0.000374869,-2.48302e-07,5.45572e-08,1.14173,0.000374536,-8.463e-08,-1.46013e-08,1.1421,0.000374323,-1.28434e-07,3.8478e-09,1.14247,0.000374077,-1.1689e-07,-7.89941e-10,1.14285,0.000373841,-1.1926e-07,-6.88042e-10,1.14322,0.0003736,-1.21324e-07,3.54213e-09,1.1436,0.000373368,-1.10698e-07,-1.34805e-08,1.14397,0.000373107,-1.51139e-07,5.03798e-08,1.14434,0.000372767,0.,0.}; + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void RGB2LuvConvert_f(const T& src, D& dst) + { + const float _d = 1.f / (0.950456f + 15 + 1.088754f * 3); + const float _un = 13 * (4 * 0.950456f * _d); + const float _vn = 13 * (9 * _d); + + float B = blueIdx == 0 ? src.x : src.z; + float G = src.y; + float R = blueIdx == 0 ? src.z : src.x; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + } + + float X = R * 0.412453f + G * 0.357580f + B * 0.180423f; + float Y = R * 0.212671f + G * 0.715160f + B * 0.072169f; + float Z = R * 0.019334f + G * 0.119193f + B * 0.950227f; + + float L = splineInterpolate(Y * (LAB_CBRT_TAB_SIZE / 1.5f), c_LabCbrtTab, LAB_CBRT_TAB_SIZE); + L = 116.f * L - 16.f; + + const float d = (4 * 13) / ::fmaxf(X + 15 * Y + 3 * Z, numeric_limits<float>::epsilon()); + float u = L * (X * d - _un); + float v = L * ((9 * 0.25f) * Y * d - _vn); + + dst.x = L; + dst.y = u; + dst.z = v; + } + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void RGB2LuvConvert_b(const T& src, D& dst) + { + float3 srcf, dstf; + + srcf.x = src.x * (1.f / 255.f); + srcf.y = src.y * (1.f / 255.f); + srcf.z = src.z * (1.f / 255.f); + + RGB2LuvConvert_f<srgb, blueIdx>(srcf, dstf); + + dst.x = saturate_cast<uchar>(dstf.x * 2.55f); + dst.y = saturate_cast<uchar>(dstf.y * 0.72033898305084743f + 96.525423728813564f); + dst.z = saturate_cast<uchar>(dstf.z * 0.9732824427480916f + 136.259541984732824f); + } + + template <typename T, int scn, int dcn, bool srgb, int blueIdx> struct RGB2Luv; + template <int scn, int dcn, bool srgb, int blueIdx> + struct RGB2Luv<uchar, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<uchar, scn>::vec_type, typename TypeVec<uchar, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<uchar, dcn>::vec_type operator ()(const typename TypeVec<uchar, scn>::vec_type& src) const + { + typename TypeVec<uchar, dcn>::vec_type dst; + + RGB2LuvConvert_b<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Luv() {} + __host__ __device__ __forceinline__ RGB2Luv(const RGB2Luv&) {} + }; + template <int scn, int dcn, bool srgb, int blueIdx> + struct RGB2Luv<float, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<float, scn>::vec_type, typename TypeVec<float, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<float, dcn>::vec_type operator ()(const typename TypeVec<float, scn>::vec_type& src) const + { + typename TypeVec<float, dcn>::vec_type dst; + + RGB2LuvConvert_f<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Luv() {} + __host__ __device__ __forceinline__ RGB2Luv(const RGB2Luv&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2Luv<T, scn, dcn, srgb, blueIdx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void Luv2RGBConvert_f(const T& src, D& dst) + { + const float _d = 1.f / (0.950456f + 15 + 1.088754f * 3); + const float _un = 4 * 0.950456f * _d; + const float _vn = 9 * _d; + + float L = src.x; + float u = src.y; + float v = src.z; + + float Y = (L + 16.f) * (1.f / 116.f); + Y = Y * Y * Y; + + float d = (1.f / 13.f) / L; + u = u * d + _un; + v = v * d + _vn; + + float iv = 1.f / v; + float X = 2.25f * u * Y * iv; + float Z = (12 - 3 * u - 20 * v) * Y * 0.25f * iv; + + float B = 0.055648f * X - 0.204043f * Y + 1.057311f * Z; + float G = -0.969256f * X + 1.875991f * Y + 0.041556f * Z; + float R = 3.240479f * X - 1.537150f * Y - 0.498535f * Z; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + } + + dst.x = blueIdx == 0 ? B : R; + dst.y = G; + dst.z = blueIdx == 0 ? R : B; + setAlpha(dst, ColorChannel<float>::max()); + } + + template <bool srgb, int blueIdx, typename T, typename D> + __device__ __forceinline__ void Luv2RGBConvert_b(const T& src, D& dst) + { + float3 srcf, dstf; + + srcf.x = src.x * (100.f / 255.f); + srcf.y = src.y * 1.388235294117647f - 134.f; + srcf.z = src.z * 1.027450980392157f - 140.f; + + Luv2RGBConvert_f<srgb, blueIdx>(srcf, dstf); + + dst.x = saturate_cast<uchar>(dstf.x * 255.f); + dst.y = saturate_cast<uchar>(dstf.y * 255.f); + dst.z = saturate_cast<uchar>(dstf.z * 255.f); + setAlpha(dst, ColorChannel<uchar>::max()); + } + + template <typename T, int scn, int dcn, bool srgb, int blueIdx> struct Luv2RGB; + template <int scn, int dcn, bool srgb, int blueIdx> + struct Luv2RGB<uchar, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<uchar, scn>::vec_type, typename TypeVec<uchar, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<uchar, dcn>::vec_type operator ()(const typename TypeVec<uchar, scn>::vec_type& src) const + { + typename TypeVec<uchar, dcn>::vec_type dst; + + Luv2RGBConvert_b<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Luv2RGB() {} + __host__ __device__ __forceinline__ Luv2RGB(const Luv2RGB&) {} + }; + template <int scn, int dcn, bool srgb, int blueIdx> + struct Luv2RGB<float, scn, dcn, srgb, blueIdx> + : unary_function<typename TypeVec<float, scn>::vec_type, typename TypeVec<float, dcn>::vec_type> + { + __device__ __forceinline__ typename TypeVec<float, dcn>::vec_type operator ()(const typename TypeVec<float, scn>::vec_type& src) const + { + typename TypeVec<float, dcn>::vec_type dst; + + Luv2RGBConvert_f<srgb, blueIdx>(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Luv2RGB() {} + __host__ __device__ __forceinline__ Luv2RGB(const Luv2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template <typename T> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Luv2RGB<T, scn, dcn, srgb, blueIdx> functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + #undef CV_DESCALE + +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_COLOR_DETAIL_HPP diff --git a/include/opencv2/core/cuda/detail/reduce.hpp b/include/opencv2/core/cuda/detail/reduce.hpp new file mode 100644 index 0000000..8af20b0 --- /dev/null +++ b/include/opencv2/core/cuda/detail/reduce.hpp @@ -0,0 +1,365 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_REDUCE_DETAIL_HPP +#define OPENCV_CUDA_REDUCE_DETAIL_HPP + +#include <thrust/tuple.h> +#include "../warp.hpp" +#include "../warp_shuffle.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace reduce_detail + { + template <typename T> struct GetType; + template <typename T> struct GetType<T*> + { + typedef T type; + }; + template <typename T> struct GetType<volatile T*> + { + typedef T type; + }; + template <typename T> struct GetType<T&> + { + typedef T type; + }; + + template <unsigned int I, unsigned int N> + struct For + { + template <class PointerTuple, class ValTuple> + static __device__ void loadToSmem(const PointerTuple& smem, const ValTuple& val, unsigned int tid) + { + thrust::get<I>(smem)[tid] = thrust::get<I>(val); + + For<I + 1, N>::loadToSmem(smem, val, tid); + } + template <class PointerTuple, class ValTuple> + static __device__ void loadFromSmem(const PointerTuple& smem, const ValTuple& val, unsigned int tid) + { + thrust::get<I>(val) = thrust::get<I>(smem)[tid]; + + For<I + 1, N>::loadFromSmem(smem, val, tid); + } + + template <class PointerTuple, class ValTuple, class OpTuple> + static __device__ void merge(const PointerTuple& smem, const ValTuple& val, unsigned int tid, unsigned int delta, const OpTuple& op) + { + typename GetType<typename thrust::tuple_element<I, PointerTuple>::type>::type reg = thrust::get<I>(smem)[tid + delta]; + thrust::get<I>(smem)[tid] = thrust::get<I>(val) = thrust::get<I>(op)(thrust::get<I>(val), reg); + + For<I + 1, N>::merge(smem, val, tid, delta, op); + } + template <class ValTuple, class OpTuple> + static __device__ void mergeShfl(const ValTuple& val, unsigned int delta, unsigned int width, const OpTuple& op) + { + typename GetType<typename thrust::tuple_element<I, ValTuple>::type>::type reg = shfl_down(thrust::get<I>(val), delta, width); + thrust::get<I>(val) = thrust::get<I>(op)(thrust::get<I>(val), reg); + + For<I + 1, N>::mergeShfl(val, delta, width, op); + } + }; + template <unsigned int N> + struct For<N, N> + { + template <class PointerTuple, class ValTuple> + static __device__ void loadToSmem(const PointerTuple&, const ValTuple&, unsigned int) + { + } + template <class PointerTuple, class ValTuple> + static __device__ void loadFromSmem(const PointerTuple&, const ValTuple&, unsigned int) + { + } + + template <class PointerTuple, class ValTuple, class OpTuple> + static __device__ void merge(const PointerTuple&, const ValTuple&, unsigned int, unsigned int, const OpTuple&) + { + } + template <class ValTuple, class OpTuple> + static __device__ void mergeShfl(const ValTuple&, unsigned int, unsigned int, const OpTuple&) + { + } + }; + + template <typename T> + __device__ __forceinline__ void loadToSmem(volatile T* smem, T& val, unsigned int tid) + { + smem[tid] = val; + } + template <typename T> + __device__ __forceinline__ void loadFromSmem(volatile T* smem, T& val, unsigned int tid) + { + val = smem[tid]; + } + template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, + typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9> + __device__ __forceinline__ void loadToSmem(const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>& smem, + const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val, + unsigned int tid) + { + For<0, thrust::tuple_size<thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> >::value>::loadToSmem(smem, val, tid); + } + template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, + typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9> + __device__ __forceinline__ void loadFromSmem(const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>& smem, + const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val, + unsigned int tid) + { + For<0, thrust::tuple_size<thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> >::value>::loadFromSmem(smem, val, tid); + } + + template <typename T, class Op> + __device__ __forceinline__ void merge(volatile T* smem, T& val, unsigned int tid, unsigned int delta, const Op& op) + { + T reg = smem[tid + delta]; + smem[tid] = val = op(val, reg); + } + template <typename T, class Op> + __device__ __forceinline__ void mergeShfl(T& val, unsigned int delta, unsigned int width, const Op& op) + { + T reg = shfl_down(val, delta, width); + val = op(val, reg); + } + template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, + typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9, + class Op0, class Op1, class Op2, class Op3, class Op4, class Op5, class Op6, class Op7, class Op8, class Op9> + __device__ __forceinline__ void merge(const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>& smem, + const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val, + unsigned int tid, + unsigned int delta, + const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>& op) + { + For<0, thrust::tuple_size<thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> >::value>::merge(smem, val, tid, delta, op); + } + template <typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9, + class Op0, class Op1, class Op2, class Op3, class Op4, class Op5, class Op6, class Op7, class Op8, class Op9> + __device__ __forceinline__ void mergeShfl(const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val, + unsigned int delta, + unsigned int width, + const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>& op) + { + For<0, thrust::tuple_size<thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9> >::value>::mergeShfl(val, delta, width, op); + } + + template <unsigned int N> struct Generic + { + template <typename Pointer, typename Reference, class Op> + static __device__ void reduce(Pointer smem, Reference val, unsigned int tid, Op op) + { + loadToSmem(smem, val, tid); + if (N >= 32) + __syncthreads(); + + if (N >= 2048) + { + if (tid < 1024) + merge(smem, val, tid, 1024, op); + + __syncthreads(); + } + if (N >= 1024) + { + if (tid < 512) + merge(smem, val, tid, 512, op); + + __syncthreads(); + } + if (N >= 512) + { + if (tid < 256) + merge(smem, val, tid, 256, op); + + __syncthreads(); + } + if (N >= 256) + { + if (tid < 128) + merge(smem, val, tid, 128, op); + + __syncthreads(); + } + if (N >= 128) + { + if (tid < 64) + merge(smem, val, tid, 64, op); + + __syncthreads(); + } + if (N >= 64) + { + if (tid < 32) + merge(smem, val, tid, 32, op); + } + + if (tid < 16) + { + merge(smem, val, tid, 16, op); + merge(smem, val, tid, 8, op); + merge(smem, val, tid, 4, op); + merge(smem, val, tid, 2, op); + merge(smem, val, tid, 1, op); + } + } + }; + + template <unsigned int I, typename Pointer, typename Reference, class Op> + struct Unroll + { + static __device__ void loopShfl(Reference val, Op op, unsigned int N) + { + mergeShfl(val, I, N, op); + Unroll<I / 2, Pointer, Reference, Op>::loopShfl(val, op, N); + } + static __device__ void loop(Pointer smem, Reference val, unsigned int tid, Op op) + { + merge(smem, val, tid, I, op); + Unroll<I / 2, Pointer, Reference, Op>::loop(smem, val, tid, op); + } + }; + template <typename Pointer, typename Reference, class Op> + struct Unroll<0, Pointer, Reference, Op> + { + static __device__ void loopShfl(Reference, Op, unsigned int) + { + } + static __device__ void loop(Pointer, Reference, unsigned int, Op) + { + } + }; + + template <unsigned int N> struct WarpOptimized + { + template <typename Pointer, typename Reference, class Op> + static __device__ void reduce(Pointer smem, Reference val, unsigned int tid, Op op) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + CV_UNUSED(smem); + CV_UNUSED(tid); + + Unroll<N / 2, Pointer, Reference, Op>::loopShfl(val, op, N); + #else + loadToSmem(smem, val, tid); + + if (tid < N / 2) + Unroll<N / 2, Pointer, Reference, Op>::loop(smem, val, tid, op); + #endif + } + }; + + template <unsigned int N> struct GenericOptimized32 + { + enum { M = N / 32 }; + + template <typename Pointer, typename Reference, class Op> + static __device__ void reduce(Pointer smem, Reference val, unsigned int tid, Op op) + { + const unsigned int laneId = Warp::laneId(); + + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + Unroll<16, Pointer, Reference, Op>::loopShfl(val, op, warpSize); + + if (laneId == 0) + loadToSmem(smem, val, tid / 32); + #else + loadToSmem(smem, val, tid); + + if (laneId < 16) + Unroll<16, Pointer, Reference, Op>::loop(smem, val, tid, op); + + __syncthreads(); + + if (laneId == 0) + loadToSmem(smem, val, tid / 32); + #endif + + __syncthreads(); + + loadFromSmem(smem, val, tid); + + if (tid < 32) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + Unroll<M / 2, Pointer, Reference, Op>::loopShfl(val, op, M); + #else + Unroll<M / 2, Pointer, Reference, Op>::loop(smem, val, tid, op); + #endif + } + } + }; + + template <bool val, class T1, class T2> struct StaticIf; + template <class T1, class T2> struct StaticIf<true, T1, T2> + { + typedef T1 type; + }; + template <class T1, class T2> struct StaticIf<false, T1, T2> + { + typedef T2 type; + }; + + template <unsigned int N> struct IsPowerOf2 + { + enum { value = ((N != 0) && !(N & (N - 1))) }; + }; + + template <unsigned int N> struct Dispatcher + { + typedef typename StaticIf< + (N <= 32) && IsPowerOf2<N>::value, + WarpOptimized<N>, + typename StaticIf< + (N <= 1024) && IsPowerOf2<N>::value, + GenericOptimized32<N>, + Generic<N> + >::type + >::type reductor; + }; + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_REDUCE_DETAIL_HPP diff --git a/include/opencv2/core/cuda/detail/reduce_key_val.hpp b/include/opencv2/core/cuda/detail/reduce_key_val.hpp new file mode 100644 index 0000000..df37c17 --- /dev/null +++ b/include/opencv2/core/cuda/detail/reduce_key_val.hpp @@ -0,0 +1,502 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_PRED_VAL_REDUCE_DETAIL_HPP +#define OPENCV_CUDA_PRED_VAL_REDUCE_DETAIL_HPP + +#include <thrust/tuple.h> +#include "../warp.hpp" +#include "../warp_shuffle.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace reduce_key_val_detail + { + template <typename T> struct GetType; + template <typename T> struct GetType<T*> + { + typedef T type; + }; + template <typename T> struct GetType<volatile T*> + { + typedef T type; + }; + template <typename T> struct GetType<T&> + { + typedef T type; + }; + + template <unsigned int I, unsigned int N> + struct For + { + template <class PointerTuple, class ReferenceTuple> + static __device__ void loadToSmem(const PointerTuple& smem, const ReferenceTuple& data, unsigned int tid) + { + thrust::get<I>(smem)[tid] = thrust::get<I>(data); + + For<I + 1, N>::loadToSmem(smem, data, tid); + } + template <class PointerTuple, class ReferenceTuple> + static __device__ void loadFromSmem(const PointerTuple& smem, const ReferenceTuple& data, unsigned int tid) + { + thrust::get<I>(data) = thrust::get<I>(smem)[tid]; + + For<I + 1, N>::loadFromSmem(smem, data, tid); + } + + template <class ReferenceTuple> + static __device__ void copyShfl(const ReferenceTuple& val, unsigned int delta, int width) + { + thrust::get<I>(val) = shfl_down(thrust::get<I>(val), delta, width); + + For<I + 1, N>::copyShfl(val, delta, width); + } + template <class PointerTuple, class ReferenceTuple> + static __device__ void copy(const PointerTuple& svals, const ReferenceTuple& val, unsigned int tid, unsigned int delta) + { + thrust::get<I>(svals)[tid] = thrust::get<I>(val) = thrust::get<I>(svals)[tid + delta]; + + For<I + 1, N>::copy(svals, val, tid, delta); + } + + template <class KeyReferenceTuple, class ValReferenceTuple, class CmpTuple> + static __device__ void mergeShfl(const KeyReferenceTuple& key, const ValReferenceTuple& val, const CmpTuple& cmp, unsigned int delta, int width) + { + typename GetType<typename thrust::tuple_element<I, KeyReferenceTuple>::type>::type reg = shfl_down(thrust::get<I>(key), delta, width); + + if (thrust::get<I>(cmp)(reg, thrust::get<I>(key))) + { + thrust::get<I>(key) = reg; + thrust::get<I>(val) = shfl_down(thrust::get<I>(val), delta, width); + } + + For<I + 1, N>::mergeShfl(key, val, cmp, delta, width); + } + template <class KeyPointerTuple, class KeyReferenceTuple, class ValPointerTuple, class ValReferenceTuple, class CmpTuple> + static __device__ void merge(const KeyPointerTuple& skeys, const KeyReferenceTuple& key, + const ValPointerTuple& svals, const ValReferenceTuple& val, + const CmpTuple& cmp, + unsigned int tid, unsigned int delta) + { + typename GetType<typename thrust::tuple_element<I, KeyPointerTuple>::type>::type reg = thrust::get<I>(skeys)[tid + delta]; + + if (thrust::get<I>(cmp)(reg, thrust::get<I>(key))) + { + thrust::get<I>(skeys)[tid] = thrust::get<I>(key) = reg; + thrust::get<I>(svals)[tid] = thrust::get<I>(val) = thrust::get<I>(svals)[tid + delta]; + } + + For<I + 1, N>::merge(skeys, key, svals, val, cmp, tid, delta); + } + }; + template <unsigned int N> + struct For<N, N> + { + template <class PointerTuple, class ReferenceTuple> + static __device__ void loadToSmem(const PointerTuple&, const ReferenceTuple&, unsigned int) + { + } + template <class PointerTuple, class ReferenceTuple> + static __device__ void loadFromSmem(const PointerTuple&, const ReferenceTuple&, unsigned int) + { + } + + template <class ReferenceTuple> + static __device__ void copyShfl(const ReferenceTuple&, unsigned int, int) + { + } + template <class PointerTuple, class ReferenceTuple> + static __device__ void copy(const PointerTuple&, const ReferenceTuple&, unsigned int, unsigned int) + { + } + + template <class KeyReferenceTuple, class ValReferenceTuple, class CmpTuple> + static __device__ void mergeShfl(const KeyReferenceTuple&, const ValReferenceTuple&, const CmpTuple&, unsigned int, int) + { + } + template <class KeyPointerTuple, class KeyReferenceTuple, class ValPointerTuple, class ValReferenceTuple, class CmpTuple> + static __device__ void merge(const KeyPointerTuple&, const KeyReferenceTuple&, + const ValPointerTuple&, const ValReferenceTuple&, + const CmpTuple&, + unsigned int, unsigned int) + { + } + }; + + ////////////////////////////////////////////////////// + // loadToSmem + + template <typename T> + __device__ __forceinline__ void loadToSmem(volatile T* smem, T& data, unsigned int tid) + { + smem[tid] = data; + } + template <typename T> + __device__ __forceinline__ void loadFromSmem(volatile T* smem, T& data, unsigned int tid) + { + data = smem[tid]; + } + template <typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9> + __device__ __forceinline__ void loadToSmem(const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& smem, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& data, + unsigned int tid) + { + For<0, thrust::tuple_size<thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9> >::value>::loadToSmem(smem, data, tid); + } + template <typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9> + __device__ __forceinline__ void loadFromSmem(const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& smem, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& data, + unsigned int tid) + { + For<0, thrust::tuple_size<thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9> >::value>::loadFromSmem(smem, data, tid); + } + + ////////////////////////////////////////////////////// + // copyVals + + template <typename V> + __device__ __forceinline__ void copyValsShfl(V& val, unsigned int delta, int width) + { + val = shfl_down(val, delta, width); + } + template <typename V> + __device__ __forceinline__ void copyVals(volatile V* svals, V& val, unsigned int tid, unsigned int delta) + { + svals[tid] = val = svals[tid + delta]; + } + template <typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9> + __device__ __forceinline__ void copyValsShfl(const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + unsigned int delta, + int width) + { + For<0, thrust::tuple_size<thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9> >::value>::copyShfl(val, delta, width); + } + template <typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9> + __device__ __forceinline__ void copyVals(const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + unsigned int tid, unsigned int delta) + { + For<0, thrust::tuple_size<thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9> >::value>::copy(svals, val, tid, delta); + } + + ////////////////////////////////////////////////////// + // merge + + template <typename K, typename V, class Cmp> + __device__ __forceinline__ void mergeShfl(K& key, V& val, const Cmp& cmp, unsigned int delta, int width) + { + K reg = shfl_down(key, delta, width); + + if (cmp(reg, key)) + { + key = reg; + copyValsShfl(val, delta, width); + } + } + template <typename K, typename V, class Cmp> + __device__ __forceinline__ void merge(volatile K* skeys, K& key, volatile V* svals, V& val, const Cmp& cmp, unsigned int tid, unsigned int delta) + { + K reg = skeys[tid + delta]; + + if (cmp(reg, key)) + { + skeys[tid] = key = reg; + copyVals(svals, val, tid, delta); + } + } + template <typename K, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9, + class Cmp> + __device__ __forceinline__ void mergeShfl(K& key, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + const Cmp& cmp, + unsigned int delta, int width) + { + K reg = shfl_down(key, delta, width); + + if (cmp(reg, key)) + { + key = reg; + copyValsShfl(val, delta, width); + } + } + template <typename K, + typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9, + class Cmp> + __device__ __forceinline__ void merge(volatile K* skeys, K& key, + const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + const Cmp& cmp, unsigned int tid, unsigned int delta) + { + K reg = skeys[tid + delta]; + + if (cmp(reg, key)) + { + skeys[tid] = key = reg; + copyVals(svals, val, tid, delta); + } + } + template <typename KR0, typename KR1, typename KR2, typename KR3, typename KR4, typename KR5, typename KR6, typename KR7, typename KR8, typename KR9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9, + class Cmp0, class Cmp1, class Cmp2, class Cmp3, class Cmp4, class Cmp5, class Cmp6, class Cmp7, class Cmp8, class Cmp9> + __device__ __forceinline__ void mergeShfl(const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>& key, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>& cmp, + unsigned int delta, int width) + { + For<0, thrust::tuple_size<thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9> >::value>::mergeShfl(key, val, cmp, delta, width); + } + template <typename KP0, typename KP1, typename KP2, typename KP3, typename KP4, typename KP5, typename KP6, typename KP7, typename KP8, typename KP9, + typename KR0, typename KR1, typename KR2, typename KR3, typename KR4, typename KR5, typename KR6, typename KR7, typename KR8, typename KR9, + typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9, + class Cmp0, class Cmp1, class Cmp2, class Cmp3, class Cmp4, class Cmp5, class Cmp6, class Cmp7, class Cmp8, class Cmp9> + __device__ __forceinline__ void merge(const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>& skeys, + const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>& key, + const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>& cmp, + unsigned int tid, unsigned int delta) + { + For<0, thrust::tuple_size<thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9> >::value>::merge(skeys, key, svals, val, cmp, tid, delta); + } + + ////////////////////////////////////////////////////// + // Generic + + template <unsigned int N> struct Generic + { + template <class KP, class KR, class VP, class VR, class Cmp> + static __device__ void reduce(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + loadToSmem(skeys, key, tid); + loadValsToSmem(svals, val, tid); + if (N >= 32) + __syncthreads(); + + if (N >= 2048) + { + if (tid < 1024) + merge(skeys, key, svals, val, cmp, tid, 1024); + + __syncthreads(); + } + if (N >= 1024) + { + if (tid < 512) + merge(skeys, key, svals, val, cmp, tid, 512); + + __syncthreads(); + } + if (N >= 512) + { + if (tid < 256) + merge(skeys, key, svals, val, cmp, tid, 256); + + __syncthreads(); + } + if (N >= 256) + { + if (tid < 128) + merge(skeys, key, svals, val, cmp, tid, 128); + + __syncthreads(); + } + if (N >= 128) + { + if (tid < 64) + merge(skeys, key, svals, val, cmp, tid, 64); + + __syncthreads(); + } + if (N >= 64) + { + if (tid < 32) + merge(skeys, key, svals, val, cmp, tid, 32); + } + + if (tid < 16) + { + merge(skeys, key, svals, val, cmp, tid, 16); + merge(skeys, key, svals, val, cmp, tid, 8); + merge(skeys, key, svals, val, cmp, tid, 4); + merge(skeys, key, svals, val, cmp, tid, 2); + merge(skeys, key, svals, val, cmp, tid, 1); + } + } + }; + + template <unsigned int I, class KP, class KR, class VP, class VR, class Cmp> + struct Unroll + { + static __device__ void loopShfl(KR key, VR val, Cmp cmp, unsigned int N) + { + mergeShfl(key, val, cmp, I, N); + Unroll<I / 2, KP, KR, VP, VR, Cmp>::loopShfl(key, val, cmp, N); + } + static __device__ void loop(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + merge(skeys, key, svals, val, cmp, tid, I); + Unroll<I / 2, KP, KR, VP, VR, Cmp>::loop(skeys, key, svals, val, tid, cmp); + } + }; + template <class KP, class KR, class VP, class VR, class Cmp> + struct Unroll<0, KP, KR, VP, VR, Cmp> + { + static __device__ void loopShfl(KR, VR, Cmp, unsigned int) + { + } + static __device__ void loop(KP, KR, VP, VR, unsigned int, Cmp) + { + } + }; + + template <unsigned int N> struct WarpOptimized + { + template <class KP, class KR, class VP, class VR, class Cmp> + static __device__ void reduce(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + #if 0 // __CUDA_ARCH__ >= 300 + CV_UNUSED(skeys); + CV_UNUSED(svals); + CV_UNUSED(tid); + + Unroll<N / 2, KP, KR, VP, VR, Cmp>::loopShfl(key, val, cmp, N); + #else + loadToSmem(skeys, key, tid); + loadToSmem(svals, val, tid); + + if (tid < N / 2) + Unroll<N / 2, KP, KR, VP, VR, Cmp>::loop(skeys, key, svals, val, tid, cmp); + #endif + } + }; + + template <unsigned int N> struct GenericOptimized32 + { + enum { M = N / 32 }; + + template <class KP, class KR, class VP, class VR, class Cmp> + static __device__ void reduce(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + const unsigned int laneId = Warp::laneId(); + + #if 0 // __CUDA_ARCH__ >= 300 + Unroll<16, KP, KR, VP, VR, Cmp>::loopShfl(key, val, cmp, warpSize); + + if (laneId == 0) + { + loadToSmem(skeys, key, tid / 32); + loadToSmem(svals, val, tid / 32); + } + #else + loadToSmem(skeys, key, tid); + loadToSmem(svals, val, tid); + + if (laneId < 16) + Unroll<16, KP, KR, VP, VR, Cmp>::loop(skeys, key, svals, val, tid, cmp); + + __syncthreads(); + + if (laneId == 0) + { + loadToSmem(skeys, key, tid / 32); + loadToSmem(svals, val, tid / 32); + } + #endif + + __syncthreads(); + + loadFromSmem(skeys, key, tid); + + if (tid < 32) + { + #if 0 // __CUDA_ARCH__ >= 300 + loadFromSmem(svals, val, tid); + + Unroll<M / 2, KP, KR, VP, VR, Cmp>::loopShfl(key, val, cmp, M); + #else + Unroll<M / 2, KP, KR, VP, VR, Cmp>::loop(skeys, key, svals, val, tid, cmp); + #endif + } + } + }; + + template <bool val, class T1, class T2> struct StaticIf; + template <class T1, class T2> struct StaticIf<true, T1, T2> + { + typedef T1 type; + }; + template <class T1, class T2> struct StaticIf<false, T1, T2> + { + typedef T2 type; + }; + + template <unsigned int N> struct IsPowerOf2 + { + enum { value = ((N != 0) && !(N & (N - 1))) }; + }; + + template <unsigned int N> struct Dispatcher + { + typedef typename StaticIf< + (N <= 32) && IsPowerOf2<N>::value, + WarpOptimized<N>, + typename StaticIf< + (N <= 1024) && IsPowerOf2<N>::value, + GenericOptimized32<N>, + Generic<N> + >::type + >::type reductor; + }; + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_PRED_VAL_REDUCE_DETAIL_HPP diff --git a/include/opencv2/core/cuda/detail/transform_detail.hpp b/include/opencv2/core/cuda/detail/transform_detail.hpp new file mode 100644 index 0000000..1919848 --- /dev/null +++ b/include/opencv2/core/cuda/detail/transform_detail.hpp @@ -0,0 +1,392 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_TRANSFORM_DETAIL_HPP +#define OPENCV_CUDA_TRANSFORM_DETAIL_HPP + +#include "../common.hpp" +#include "../vec_traits.hpp" +#include "../functional.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace transform_detail + { + //! Read Write Traits + + template <typename T, typename D, int shift> struct UnaryReadWriteTraits + { + typedef typename TypeVec<T, shift>::vec_type read_type; + typedef typename TypeVec<D, shift>::vec_type write_type; + }; + + template <typename T1, typename T2, typename D, int shift> struct BinaryReadWriteTraits + { + typedef typename TypeVec<T1, shift>::vec_type read_type1; + typedef typename TypeVec<T2, shift>::vec_type read_type2; + typedef typename TypeVec<D, shift>::vec_type write_type; + }; + + //! Transform kernels + + template <int shift> struct OpUnroller; + template <> struct OpUnroller<1> + { + template <typename T, typename D, typename UnOp, typename Mask> + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + } + }; + template <> struct OpUnroller<2> + { + template <typename T, typename D, typename UnOp, typename Mask> + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src.y); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src1.y, src2.y); + } + }; + template <> struct OpUnroller<3> + { + template <typename T, typename D, typename UnOp, typename Mask> + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, const UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src.z); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, const BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src1.y, src2.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src1.z, src2.z); + } + }; + template <> struct OpUnroller<4> + { + template <typename T, typename D, typename UnOp, typename Mask> + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, const UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src.z); + if (mask(y, x_shifted + 3)) + dst.w = op(src.w); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, const BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src1.y, src2.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src1.z, src2.z); + if (mask(y, x_shifted + 3)) + dst.w = op(src1.w, src2.w); + } + }; + template <> struct OpUnroller<8> + { + template <typename T, typename D, typename UnOp, typename Mask> + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, const UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.a0 = op(src.a0); + if (mask(y, x_shifted + 1)) + dst.a1 = op(src.a1); + if (mask(y, x_shifted + 2)) + dst.a2 = op(src.a2); + if (mask(y, x_shifted + 3)) + dst.a3 = op(src.a3); + if (mask(y, x_shifted + 4)) + dst.a4 = op(src.a4); + if (mask(y, x_shifted + 5)) + dst.a5 = op(src.a5); + if (mask(y, x_shifted + 6)) + dst.a6 = op(src.a6); + if (mask(y, x_shifted + 7)) + dst.a7 = op(src.a7); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, const BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.a0 = op(src1.a0, src2.a0); + if (mask(y, x_shifted + 1)) + dst.a1 = op(src1.a1, src2.a1); + if (mask(y, x_shifted + 2)) + dst.a2 = op(src1.a2, src2.a2); + if (mask(y, x_shifted + 3)) + dst.a3 = op(src1.a3, src2.a3); + if (mask(y, x_shifted + 4)) + dst.a4 = op(src1.a4, src2.a4); + if (mask(y, x_shifted + 5)) + dst.a5 = op(src1.a5, src2.a5); + if (mask(y, x_shifted + 6)) + dst.a6 = op(src1.a6, src2.a6); + if (mask(y, x_shifted + 7)) + dst.a7 = op(src1.a7, src2.a7); + } + }; + + template <typename T, typename D, typename UnOp, typename Mask> + static __global__ void transformSmart(const PtrStepSz<T> src_, PtrStep<D> dst_, const Mask mask, const UnOp op) + { + typedef TransformFunctorTraits<UnOp> ft; + typedef typename UnaryReadWriteTraits<T, D, ft::smart_shift>::read_type read_type; + typedef typename UnaryReadWriteTraits<T, D, ft::smart_shift>::write_type write_type; + + const int x = threadIdx.x + blockIdx.x * blockDim.x; + const int y = threadIdx.y + blockIdx.y * blockDim.y; + const int x_shifted = x * ft::smart_shift; + + if (y < src_.rows) + { + const T* src = src_.ptr(y); + D* dst = dst_.ptr(y); + + if (x_shifted + ft::smart_shift - 1 < src_.cols) + { + const read_type src_n_el = ((const read_type*)src)[x]; + OpUnroller<ft::smart_shift>::unroll(src_n_el, ((write_type*)dst)[x], mask, op, x_shifted, y); + } + else + { + for (int real_x = x_shifted; real_x < src_.cols; ++real_x) + { + if (mask(y, real_x)) + dst[real_x] = op(src[real_x]); + } + } + } + } + + template <typename T, typename D, typename UnOp, typename Mask> + __global__ static void transformSimple(const PtrStepSz<T> src, PtrStep<D> dst, const Mask mask, const UnOp op) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < src.cols && y < src.rows && mask(y, x)) + { + dst.ptr(y)[x] = op(src.ptr(y)[x]); + } + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __global__ void transformSmart(const PtrStepSz<T1> src1_, const PtrStep<T2> src2_, PtrStep<D> dst_, + const Mask mask, const BinOp op) + { + typedef TransformFunctorTraits<BinOp> ft; + typedef typename BinaryReadWriteTraits<T1, T2, D, ft::smart_shift>::read_type1 read_type1; + typedef typename BinaryReadWriteTraits<T1, T2, D, ft::smart_shift>::read_type2 read_type2; + typedef typename BinaryReadWriteTraits<T1, T2, D, ft::smart_shift>::write_type write_type; + + const int x = threadIdx.x + blockIdx.x * blockDim.x; + const int y = threadIdx.y + blockIdx.y * blockDim.y; + const int x_shifted = x * ft::smart_shift; + + if (y < src1_.rows) + { + const T1* src1 = src1_.ptr(y); + const T2* src2 = src2_.ptr(y); + D* dst = dst_.ptr(y); + + if (x_shifted + ft::smart_shift - 1 < src1_.cols) + { + const read_type1 src1_n_el = ((const read_type1*)src1)[x]; + const read_type2 src2_n_el = ((const read_type2*)src2)[x]; + + OpUnroller<ft::smart_shift>::unroll(src1_n_el, src2_n_el, ((write_type*)dst)[x], mask, op, x_shifted, y); + } + else + { + for (int real_x = x_shifted; real_x < src1_.cols; ++real_x) + { + if (mask(y, real_x)) + dst[real_x] = op(src1[real_x], src2[real_x]); + } + } + } + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static __global__ void transformSimple(const PtrStepSz<T1> src1, const PtrStep<T2> src2, PtrStep<D> dst, + const Mask mask, const BinOp op) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < src1.cols && y < src1.rows && mask(y, x)) + { + const T1 src1_data = src1.ptr(y)[x]; + const T2 src2_data = src2.ptr(y)[x]; + dst.ptr(y)[x] = op(src1_data, src2_data); + } + } + + template <bool UseSmart> struct TransformDispatcher; + template<> struct TransformDispatcher<false> + { + template <typename T, typename D, typename UnOp, typename Mask> + static void call(PtrStepSz<T> src, PtrStepSz<D> dst, UnOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits<UnOp> ft; + + const dim3 threads(ft::simple_block_dim_x, ft::simple_block_dim_y, 1); + const dim3 grid(divUp(src.cols, threads.x), divUp(src.rows, threads.y), 1); + + transformSimple<T, D><<<grid, threads, 0, stream>>>(src, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static void call(PtrStepSz<T1> src1, PtrStepSz<T2> src2, PtrStepSz<D> dst, BinOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits<BinOp> ft; + + const dim3 threads(ft::simple_block_dim_x, ft::simple_block_dim_y, 1); + const dim3 grid(divUp(src1.cols, threads.x), divUp(src1.rows, threads.y), 1); + + transformSimple<T1, T2, D><<<grid, threads, 0, stream>>>(src1, src2, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + }; + template<> struct TransformDispatcher<true> + { + template <typename T, typename D, typename UnOp, typename Mask> + static void call(PtrStepSz<T> src, PtrStepSz<D> dst, UnOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits<UnOp> ft; + + CV_StaticAssert(ft::smart_shift != 1, ""); + + if (!isAligned(src.data, ft::smart_shift * sizeof(T)) || !isAligned(src.step, ft::smart_shift * sizeof(T)) || + !isAligned(dst.data, ft::smart_shift * sizeof(D)) || !isAligned(dst.step, ft::smart_shift * sizeof(D))) + { + TransformDispatcher<false>::call(src, dst, op, mask, stream); + return; + } + + const dim3 threads(ft::smart_block_dim_x, ft::smart_block_dim_y, 1); + const dim3 grid(divUp(src.cols, threads.x * ft::smart_shift), divUp(src.rows, threads.y), 1); + + transformSmart<T, D><<<grid, threads, 0, stream>>>(src, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static void call(PtrStepSz<T1> src1, PtrStepSz<T2> src2, PtrStepSz<D> dst, BinOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits<BinOp> ft; + + CV_StaticAssert(ft::smart_shift != 1, ""); + + if (!isAligned(src1.data, ft::smart_shift * sizeof(T1)) || !isAligned(src1.step, ft::smart_shift * sizeof(T1)) || + !isAligned(src2.data, ft::smart_shift * sizeof(T2)) || !isAligned(src2.step, ft::smart_shift * sizeof(T2)) || + !isAligned(dst.data, ft::smart_shift * sizeof(D)) || !isAligned(dst.step, ft::smart_shift * sizeof(D))) + { + TransformDispatcher<false>::call(src1, src2, dst, op, mask, stream); + return; + } + + const dim3 threads(ft::smart_block_dim_x, ft::smart_block_dim_y, 1); + const dim3 grid(divUp(src1.cols, threads.x * ft::smart_shift), divUp(src1.rows, threads.y), 1); + + transformSmart<T1, T2, D><<<grid, threads, 0, stream>>>(src1, src2, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + }; + } // namespace transform_detail +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_TRANSFORM_DETAIL_HPP diff --git a/include/opencv2/core/cuda/detail/type_traits_detail.hpp b/include/opencv2/core/cuda/detail/type_traits_detail.hpp new file mode 100644 index 0000000..a78bd2c --- /dev/null +++ b/include/opencv2/core/cuda/detail/type_traits_detail.hpp @@ -0,0 +1,191 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_TYPE_TRAITS_DETAIL_HPP +#define OPENCV_CUDA_TYPE_TRAITS_DETAIL_HPP + +#include "../common.hpp" +#include "../vec_traits.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace type_traits_detail + { + template <bool, typename T1, typename T2> struct Select { typedef T1 type; }; + template <typename T1, typename T2> struct Select<false, T1, T2> { typedef T2 type; }; + + template <typename T> struct IsSignedIntergral { enum {value = 0}; }; + template <> struct IsSignedIntergral<schar> { enum {value = 1}; }; + template <> struct IsSignedIntergral<char1> { enum {value = 1}; }; + template <> struct IsSignedIntergral<short> { enum {value = 1}; }; + template <> struct IsSignedIntergral<short1> { enum {value = 1}; }; + template <> struct IsSignedIntergral<int> { enum {value = 1}; }; + template <> struct IsSignedIntergral<int1> { enum {value = 1}; }; + + template <typename T> struct IsUnsignedIntegral { enum {value = 0}; }; + template <> struct IsUnsignedIntegral<uchar> { enum {value = 1}; }; + template <> struct IsUnsignedIntegral<uchar1> { enum {value = 1}; }; + template <> struct IsUnsignedIntegral<ushort> { enum {value = 1}; }; + template <> struct IsUnsignedIntegral<ushort1> { enum {value = 1}; }; + template <> struct IsUnsignedIntegral<uint> { enum {value = 1}; }; + template <> struct IsUnsignedIntegral<uint1> { enum {value = 1}; }; + + template <typename T> struct IsIntegral { enum {value = IsSignedIntergral<T>::value || IsUnsignedIntegral<T>::value}; }; + template <> struct IsIntegral<char> { enum {value = 1}; }; + template <> struct IsIntegral<bool> { enum {value = 1}; }; + + template <typename T> struct IsFloat { enum {value = 0}; }; + template <> struct IsFloat<float> { enum {value = 1}; }; + template <> struct IsFloat<double> { enum {value = 1}; }; + + template <typename T> struct IsVec { enum {value = 0}; }; + template <> struct IsVec<uchar1> { enum {value = 1}; }; + template <> struct IsVec<uchar2> { enum {value = 1}; }; + template <> struct IsVec<uchar3> { enum {value = 1}; }; + template <> struct IsVec<uchar4> { enum {value = 1}; }; + template <> struct IsVec<uchar8> { enum {value = 1}; }; + template <> struct IsVec<char1> { enum {value = 1}; }; + template <> struct IsVec<char2> { enum {value = 1}; }; + template <> struct IsVec<char3> { enum {value = 1}; }; + template <> struct IsVec<char4> { enum {value = 1}; }; + template <> struct IsVec<char8> { enum {value = 1}; }; + template <> struct IsVec<ushort1> { enum {value = 1}; }; + template <> struct IsVec<ushort2> { enum {value = 1}; }; + template <> struct IsVec<ushort3> { enum {value = 1}; }; + template <> struct IsVec<ushort4> { enum {value = 1}; }; + template <> struct IsVec<ushort8> { enum {value = 1}; }; + template <> struct IsVec<short1> { enum {value = 1}; }; + template <> struct IsVec<short2> { enum {value = 1}; }; + template <> struct IsVec<short3> { enum {value = 1}; }; + template <> struct IsVec<short4> { enum {value = 1}; }; + template <> struct IsVec<short8> { enum {value = 1}; }; + template <> struct IsVec<uint1> { enum {value = 1}; }; + template <> struct IsVec<uint2> { enum {value = 1}; }; + template <> struct IsVec<uint3> { enum {value = 1}; }; + template <> struct IsVec<uint4> { enum {value = 1}; }; + template <> struct IsVec<uint8> { enum {value = 1}; }; + template <> struct IsVec<int1> { enum {value = 1}; }; + template <> struct IsVec<int2> { enum {value = 1}; }; + template <> struct IsVec<int3> { enum {value = 1}; }; + template <> struct IsVec<int4> { enum {value = 1}; }; + template <> struct IsVec<int8> { enum {value = 1}; }; + template <> struct IsVec<float1> { enum {value = 1}; }; + template <> struct IsVec<float2> { enum {value = 1}; }; + template <> struct IsVec<float3> { enum {value = 1}; }; + template <> struct IsVec<float4> { enum {value = 1}; }; + template <> struct IsVec<float8> { enum {value = 1}; }; + template <> struct IsVec<double1> { enum {value = 1}; }; + template <> struct IsVec<double2> { enum {value = 1}; }; + template <> struct IsVec<double3> { enum {value = 1}; }; + template <> struct IsVec<double4> { enum {value = 1}; }; + template <> struct IsVec<double8> { enum {value = 1}; }; + + template <class U> struct AddParameterType { typedef const U& type; }; + template <class U> struct AddParameterType<U&> { typedef U& type; }; + template <> struct AddParameterType<void> { typedef void type; }; + + template <class U> struct ReferenceTraits + { + enum { value = false }; + typedef U type; + }; + template <class U> struct ReferenceTraits<U&> + { + enum { value = true }; + typedef U type; + }; + + template <class U> struct PointerTraits + { + enum { value = false }; + typedef void type; + }; + template <class U> struct PointerTraits<U*> + { + enum { value = true }; + typedef U type; + }; + template <class U> struct PointerTraits<U*&> + { + enum { value = true }; + typedef U type; + }; + + template <class U> struct UnConst + { + typedef U type; + enum { value = 0 }; + }; + template <class U> struct UnConst<const U> + { + typedef U type; + enum { value = 1 }; + }; + template <class U> struct UnConst<const U&> + { + typedef U& type; + enum { value = 1 }; + }; + + template <class U> struct UnVolatile + { + typedef U type; + enum { value = 0 }; + }; + template <class U> struct UnVolatile<volatile U> + { + typedef U type; + enum { value = 1 }; + }; + template <class U> struct UnVolatile<volatile U&> + { + typedef U& type; + enum { value = 1 }; + }; + } // namespace type_traits_detail +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_TYPE_TRAITS_DETAIL_HPP diff --git a/include/opencv2/core/cuda/detail/vec_distance_detail.hpp b/include/opencv2/core/cuda/detail/vec_distance_detail.hpp new file mode 100644 index 0000000..8283a99 --- /dev/null +++ b/include/opencv2/core/cuda/detail/vec_distance_detail.hpp @@ -0,0 +1,121 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP +#define OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP + +#include "../datamov_utils.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace vec_distance_detail + { + template <int THREAD_DIM, int N> struct UnrollVecDiffCached + { + template <typename Dist, typename T1, typename T2> + static __device__ void calcCheck(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int ind) + { + if (ind < len) + { + T1 val1 = *vecCached++; + + T2 val2; + ForceGlob<T2>::Load(vecGlob, ind, val2); + + dist.reduceIter(val1, val2); + + UnrollVecDiffCached<THREAD_DIM, N - 1>::calcCheck(vecCached, vecGlob, len, dist, ind + THREAD_DIM); + } + } + + template <typename Dist, typename T1, typename T2> + static __device__ void calcWithoutCheck(const T1* vecCached, const T2* vecGlob, Dist& dist) + { + T1 val1 = *vecCached++; + + T2 val2; + ForceGlob<T2>::Load(vecGlob, 0, val2); + vecGlob += THREAD_DIM; + + dist.reduceIter(val1, val2); + + UnrollVecDiffCached<THREAD_DIM, N - 1>::calcWithoutCheck(vecCached, vecGlob, dist); + } + }; + template <int THREAD_DIM> struct UnrollVecDiffCached<THREAD_DIM, 0> + { + template <typename Dist, typename T1, typename T2> + static __device__ __forceinline__ void calcCheck(const T1*, const T2*, int, Dist&, int) + { + } + + template <typename Dist, typename T1, typename T2> + static __device__ __forceinline__ void calcWithoutCheck(const T1*, const T2*, Dist&) + { + } + }; + + template <int THREAD_DIM, int MAX_LEN, bool LEN_EQ_MAX_LEN> struct VecDiffCachedCalculator; + template <int THREAD_DIM, int MAX_LEN> struct VecDiffCachedCalculator<THREAD_DIM, MAX_LEN, false> + { + template <typename Dist, typename T1, typename T2> + static __device__ __forceinline__ void calc(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int tid) + { + UnrollVecDiffCached<THREAD_DIM, MAX_LEN / THREAD_DIM>::calcCheck(vecCached, vecGlob, len, dist, tid); + } + }; + template <int THREAD_DIM, int MAX_LEN> struct VecDiffCachedCalculator<THREAD_DIM, MAX_LEN, true> + { + template <typename Dist, typename T1, typename T2> + static __device__ __forceinline__ void calc(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int tid) + { + UnrollVecDiffCached<THREAD_DIM, MAX_LEN / THREAD_DIM>::calcWithoutCheck(vecCached, vecGlob + tid, dist); + } + }; + } // namespace vec_distance_detail +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP diff --git a/include/opencv2/core/cuda/dynamic_smem.hpp b/include/opencv2/core/cuda/dynamic_smem.hpp new file mode 100644 index 0000000..42570c6 --- /dev/null +++ b/include/opencv2/core/cuda/dynamic_smem.hpp @@ -0,0 +1,88 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_DYNAMIC_SMEM_HPP +#define OPENCV_CUDA_DYNAMIC_SMEM_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template<class T> struct DynamicSharedMem + { + __device__ __forceinline__ operator T*() + { + extern __shared__ int __smem[]; + return (T*)__smem; + } + + __device__ __forceinline__ operator const T*() const + { + extern __shared__ int __smem[]; + return (T*)__smem; + } + }; + + // specialize for double to avoid unaligned memory access compile errors + template<> struct DynamicSharedMem<double> + { + __device__ __forceinline__ operator double*() + { + extern __shared__ double __smem_d[]; + return (double*)__smem_d; + } + + __device__ __forceinline__ operator const double*() const + { + extern __shared__ double __smem_d[]; + return (double*)__smem_d; + } + }; +}}} + +//! @endcond + +#endif // OPENCV_CUDA_DYNAMIC_SMEM_HPP diff --git a/include/opencv2/core/cuda/emulation.hpp b/include/opencv2/core/cuda/emulation.hpp new file mode 100644 index 0000000..17dc117 --- /dev/null +++ b/include/opencv2/core/cuda/emulation.hpp @@ -0,0 +1,269 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_EMULATION_HPP_ +#define OPENCV_CUDA_EMULATION_HPP_ + +#include "common.hpp" +#include "warp_reduce.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct Emulation + { + + static __device__ __forceinline__ int syncthreadsOr(int pred) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 200) + // just campilation stab + return 0; +#else + return __syncthreads_or(pred); +#endif + } + + template<int CTA_SIZE> + static __forceinline__ __device__ int Ballot(int predicate) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ >= 200) + return __ballot(predicate); +#else + __shared__ volatile int cta_buffer[CTA_SIZE]; + + int tid = threadIdx.x; + cta_buffer[tid] = predicate ? (1 << (tid & 31)) : 0; + return warp_reduce(cta_buffer); +#endif + } + + struct smem + { + enum { TAG_MASK = (1U << ( (sizeof(unsigned int) << 3) - 5U)) - 1U }; + + template<typename T> + static __device__ __forceinline__ T atomicInc(T* address, T val) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120) + T count; + unsigned int tag = threadIdx.x << ( (sizeof(unsigned int) << 3) - 5U); + do + { + count = *address & TAG_MASK; + count = tag | (count + 1); + *address = count; + } while (*address != count); + + return (count & TAG_MASK) - 1; +#else + return ::atomicInc(address, val); +#endif + } + + template<typename T> + static __device__ __forceinline__ T atomicAdd(T* address, T val) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120) + T count; + unsigned int tag = threadIdx.x << ( (sizeof(unsigned int) << 3) - 5U); + do + { + count = *address & TAG_MASK; + count = tag | (count + val); + *address = count; + } while (*address != count); + + return (count & TAG_MASK) - val; +#else + return ::atomicAdd(address, val); +#endif + } + + template<typename T> + static __device__ __forceinline__ T atomicMin(T* address, T val) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120) + T count = ::min(*address, val); + do + { + *address = count; + } while (*address > count); + + return count; +#else + return ::atomicMin(address, val); +#endif + } + }; // struct cmem + + struct glob + { + static __device__ __forceinline__ int atomicAdd(int* address, int val) + { + return ::atomicAdd(address, val); + } + static __device__ __forceinline__ unsigned int atomicAdd(unsigned int* address, unsigned int val) + { + return ::atomicAdd(address, val); + } + static __device__ __forceinline__ float atomicAdd(float* address, float val) + { + #if __CUDA_ARCH__ >= 200 + return ::atomicAdd(address, val); + #else + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(val + __int_as_float(assumed))); + } while (assumed != old); + return __int_as_float(old); + #endif + } + static __device__ __forceinline__ double atomicAdd(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(val + __longlong_as_double(assumed))); + } while (assumed != old); + return __longlong_as_double(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0; + #endif + } + + static __device__ __forceinline__ int atomicMin(int* address, int val) + { + return ::atomicMin(address, val); + } + static __device__ __forceinline__ float atomicMin(float* address, float val) + { + #if __CUDA_ARCH__ >= 120 + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(::fminf(val, __int_as_float(assumed)))); + } while (assumed != old); + return __int_as_float(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0f; + #endif + } + static __device__ __forceinline__ double atomicMin(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(::fmin(val, __longlong_as_double(assumed)))); + } while (assumed != old); + return __longlong_as_double(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0; + #endif + } + + static __device__ __forceinline__ int atomicMax(int* address, int val) + { + return ::atomicMax(address, val); + } + static __device__ __forceinline__ float atomicMax(float* address, float val) + { + #if __CUDA_ARCH__ >= 120 + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(::fmaxf(val, __int_as_float(assumed)))); + } while (assumed != old); + return __int_as_float(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0f; + #endif + } + static __device__ __forceinline__ double atomicMax(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(::fmax(val, __longlong_as_double(assumed)))); + } while (assumed != old); + return __longlong_as_double(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0; + #endif + } + }; + }; //struct Emulation +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif /* OPENCV_CUDA_EMULATION_HPP_ */ diff --git a/include/opencv2/core/cuda/filters.hpp b/include/opencv2/core/cuda/filters.hpp new file mode 100644 index 0000000..bb94212 --- /dev/null +++ b/include/opencv2/core/cuda/filters.hpp @@ -0,0 +1,286 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_FILTERS_HPP +#define OPENCV_CUDA_FILTERS_HPP + +#include "saturate_cast.hpp" +#include "vec_traits.hpp" +#include "vec_math.hpp" +#include "type_traits.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template <typename Ptr2D> struct PointFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ PointFilter(const Ptr2D& src_, float fx = 0.f, float fy = 0.f) + : src(src_) + { + CV_UNUSED(fx); + CV_UNUSED(fy); + } + + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + return src(__float2int_rz(y), __float2int_rz(x)); + } + + Ptr2D src; + }; + + template <typename Ptr2D> struct LinearFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ LinearFilter(const Ptr2D& src_, float fx = 0.f, float fy = 0.f) + : src(src_) + { + CV_UNUSED(fx); + CV_UNUSED(fy); + } + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type; + + work_type out = VecTraits<work_type>::all(0); + + const int x1 = __float2int_rd(x); + const int y1 = __float2int_rd(y); + const int x2 = x1 + 1; + const int y2 = y1 + 1; + + elem_type src_reg = src(y1, x1); + out = out + src_reg * ((x2 - x) * (y2 - y)); + + src_reg = src(y1, x2); + out = out + src_reg * ((x - x1) * (y2 - y)); + + src_reg = src(y2, x1); + out = out + src_reg * ((x2 - x) * (y - y1)); + + src_reg = src(y2, x2); + out = out + src_reg * ((x - x1) * (y - y1)); + + return saturate_cast<elem_type>(out); + } + + Ptr2D src; + }; + + template <typename Ptr2D> struct CubicFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type; + + explicit __host__ __device__ __forceinline__ CubicFilter(const Ptr2D& src_, float fx = 0.f, float fy = 0.f) + : src(src_) + { + CV_UNUSED(fx); + CV_UNUSED(fy); + } + + static __device__ __forceinline__ float bicubicCoeff(float x_) + { + float x = fabsf(x_); + if (x <= 1.0f) + { + return x * x * (1.5f * x - 2.5f) + 1.0f; + } + else if (x < 2.0f) + { + return x * (x * (-0.5f * x + 2.5f) - 4.0f) + 2.0f; + } + else + { + return 0.0f; + } + } + + __device__ elem_type operator ()(float y, float x) const + { + const float xmin = ::ceilf(x - 2.0f); + const float xmax = ::floorf(x + 2.0f); + + const float ymin = ::ceilf(y - 2.0f); + const float ymax = ::floorf(y + 2.0f); + + work_type sum = VecTraits<work_type>::all(0); + float wsum = 0.0f; + + for (float cy = ymin; cy <= ymax; cy += 1.0f) + { + for (float cx = xmin; cx <= xmax; cx += 1.0f) + { + const float w = bicubicCoeff(x - cx) * bicubicCoeff(y - cy); + sum = sum + w * src(__float2int_rd(cy), __float2int_rd(cx)); + wsum += w; + } + } + + work_type res = (!wsum)? VecTraits<work_type>::all(0) : sum / wsum; + + return saturate_cast<elem_type>(res); + } + + Ptr2D src; + }; + // for integer scaling + template <typename Ptr2D> struct IntegerAreaFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ IntegerAreaFilter(const Ptr2D& src_, float scale_x_, float scale_y_) + : src(src_), scale_x(scale_x_), scale_y(scale_y_), scale(1.f / (scale_x * scale_y)) {} + + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + float fsx1 = x * scale_x; + float fsx2 = fsx1 + scale_x; + + int sx1 = __float2int_ru(fsx1); + int sx2 = __float2int_rd(fsx2); + + float fsy1 = y * scale_y; + float fsy2 = fsy1 + scale_y; + + int sy1 = __float2int_ru(fsy1); + int sy2 = __float2int_rd(fsy2); + + typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type; + work_type out = VecTraits<work_type>::all(0.f); + + for(int dy = sy1; dy < sy2; ++dy) + for(int dx = sx1; dx < sx2; ++dx) + { + out = out + src(dy, dx) * scale; + } + + return saturate_cast<elem_type>(out); + } + + Ptr2D src; + float scale_x, scale_y ,scale; + }; + + template <typename Ptr2D> struct AreaFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ AreaFilter(const Ptr2D& src_, float scale_x_, float scale_y_) + : src(src_), scale_x(scale_x_), scale_y(scale_y_){} + + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + float fsx1 = x * scale_x; + float fsx2 = fsx1 + scale_x; + + int sx1 = __float2int_ru(fsx1); + int sx2 = __float2int_rd(fsx2); + + float fsy1 = y * scale_y; + float fsy2 = fsy1 + scale_y; + + int sy1 = __float2int_ru(fsy1); + int sy2 = __float2int_rd(fsy2); + + float scale = 1.f / (fminf(scale_x, src.width - fsx1) * fminf(scale_y, src.height - fsy1)); + + typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type; + work_type out = VecTraits<work_type>::all(0.f); + + for (int dy = sy1; dy < sy2; ++dy) + { + for (int dx = sx1; dx < sx2; ++dx) + out = out + src(dy, dx) * scale; + + if (sx1 > fsx1) + out = out + src(dy, (sx1 -1) ) * ((sx1 - fsx1) * scale); + + if (sx2 < fsx2) + out = out + src(dy, sx2) * ((fsx2 -sx2) * scale); + } + + if (sy1 > fsy1) + for (int dx = sx1; dx < sx2; ++dx) + out = out + src( (sy1 - 1) , dx) * ((sy1 -fsy1) * scale); + + if (sy2 < fsy2) + for (int dx = sx1; dx < sx2; ++dx) + out = out + src(sy2, dx) * ((fsy2 -sy2) * scale); + + if ((sy1 > fsy1) && (sx1 > fsx1)) + out = out + src( (sy1 - 1) , (sx1 - 1)) * ((sy1 -fsy1) * (sx1 -fsx1) * scale); + + if ((sy1 > fsy1) && (sx2 < fsx2)) + out = out + src( (sy1 - 1) , sx2) * ((sy1 -fsy1) * (fsx2 -sx2) * scale); + + if ((sy2 < fsy2) && (sx2 < fsx2)) + out = out + src(sy2, sx2) * ((fsy2 -sy2) * (fsx2 -sx2) * scale); + + if ((sy2 < fsy2) && (sx1 > fsx1)) + out = out + src(sy2, (sx1 - 1)) * ((fsy2 -sy2) * (sx1 -fsx1) * scale); + + return saturate_cast<elem_type>(out); + } + + Ptr2D src; + float scale_x, scale_y; + int width, haight; + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_FILTERS_HPP diff --git a/include/opencv2/core/cuda/funcattrib.hpp b/include/opencv2/core/cuda/funcattrib.hpp new file mode 100644 index 0000000..f582080 --- /dev/null +++ b/include/opencv2/core/cuda/funcattrib.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP +#define OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP + +#include <cstdio> + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template<class Func> + void printFuncAttrib(Func& func) + { + + cudaFuncAttributes attrs; + cudaFuncGetAttributes(&attrs, func); + + printf("=== Function stats ===\n"); + printf("Name: \n"); + printf("sharedSizeBytes = %d\n", attrs.sharedSizeBytes); + printf("constSizeBytes = %d\n", attrs.constSizeBytes); + printf("localSizeBytes = %d\n", attrs.localSizeBytes); + printf("maxThreadsPerBlock = %d\n", attrs.maxThreadsPerBlock); + printf("numRegs = %d\n", attrs.numRegs); + printf("ptxVersion = %d\n", attrs.ptxVersion); + printf("binaryVersion = %d\n", attrs.binaryVersion); + printf("\n"); + fflush(stdout); + } +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif /* OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP */ diff --git a/include/opencv2/core/cuda/functional.hpp b/include/opencv2/core/cuda/functional.hpp new file mode 100644 index 0000000..3b531a1 --- /dev/null +++ b/include/opencv2/core/cuda/functional.hpp @@ -0,0 +1,810 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_FUNCTIONAL_HPP +#define OPENCV_CUDA_FUNCTIONAL_HPP + +#include <functional> +#include "saturate_cast.hpp" +#include "vec_traits.hpp" +#include "type_traits.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + // Function Objects +#ifdef CV_CXX11 + template<typename Argument, typename Result> struct unary_function + { + typedef Argument argument_type; + typedef Result result_type; + }; + template<typename Argument1, typename Argument2, typename Result> struct binary_function + { + typedef Argument1 first_argument_type; + typedef Argument2 second_argument_type; + typedef Result result_type; + }; +#else + template<typename Argument, typename Result> struct unary_function : public std::unary_function<Argument, Result> {}; + template<typename Argument1, typename Argument2, typename Result> struct binary_function : public std::binary_function<Argument1, Argument2, Result> {}; +#endif + + // Arithmetic Operations + template <typename T> struct plus : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a + b; + } + __host__ __device__ __forceinline__ plus() {} + __host__ __device__ __forceinline__ plus(const plus&) {} + }; + + template <typename T> struct minus : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a - b; + } + __host__ __device__ __forceinline__ minus() {} + __host__ __device__ __forceinline__ minus(const minus&) {} + }; + + template <typename T> struct multiplies : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a * b; + } + __host__ __device__ __forceinline__ multiplies() {} + __host__ __device__ __forceinline__ multiplies(const multiplies&) {} + }; + + template <typename T> struct divides : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a / b; + } + __host__ __device__ __forceinline__ divides() {} + __host__ __device__ __forceinline__ divides(const divides&) {} + }; + + template <typename T> struct modulus : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a % b; + } + __host__ __device__ __forceinline__ modulus() {} + __host__ __device__ __forceinline__ modulus(const modulus&) {} + }; + + template <typename T> struct negate : unary_function<T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a) const + { + return -a; + } + __host__ __device__ __forceinline__ negate() {} + __host__ __device__ __forceinline__ negate(const negate&) {} + }; + + // Comparison Operations + template <typename T> struct equal_to : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a == b; + } + __host__ __device__ __forceinline__ equal_to() {} + __host__ __device__ __forceinline__ equal_to(const equal_to&) {} + }; + + template <typename T> struct not_equal_to : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a != b; + } + __host__ __device__ __forceinline__ not_equal_to() {} + __host__ __device__ __forceinline__ not_equal_to(const not_equal_to&) {} + }; + + template <typename T> struct greater : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a > b; + } + __host__ __device__ __forceinline__ greater() {} + __host__ __device__ __forceinline__ greater(const greater&) {} + }; + + template <typename T> struct less : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a < b; + } + __host__ __device__ __forceinline__ less() {} + __host__ __device__ __forceinline__ less(const less&) {} + }; + + template <typename T> struct greater_equal : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a >= b; + } + __host__ __device__ __forceinline__ greater_equal() {} + __host__ __device__ __forceinline__ greater_equal(const greater_equal&) {} + }; + + template <typename T> struct less_equal : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a <= b; + } + __host__ __device__ __forceinline__ less_equal() {} + __host__ __device__ __forceinline__ less_equal(const less_equal&) {} + }; + + // Logical Operations + template <typename T> struct logical_and : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a && b; + } + __host__ __device__ __forceinline__ logical_and() {} + __host__ __device__ __forceinline__ logical_and(const logical_and&) {} + }; + + template <typename T> struct logical_or : binary_function<T, T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a || b; + } + __host__ __device__ __forceinline__ logical_or() {} + __host__ __device__ __forceinline__ logical_or(const logical_or&) {} + }; + + template <typename T> struct logical_not : unary_function<T, bool> + { + __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a) const + { + return !a; + } + __host__ __device__ __forceinline__ logical_not() {} + __host__ __device__ __forceinline__ logical_not(const logical_not&) {} + }; + + // Bitwise Operations + template <typename T> struct bit_and : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a & b; + } + __host__ __device__ __forceinline__ bit_and() {} + __host__ __device__ __forceinline__ bit_and(const bit_and&) {} + }; + + template <typename T> struct bit_or : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a | b; + } + __host__ __device__ __forceinline__ bit_or() {} + __host__ __device__ __forceinline__ bit_or(const bit_or&) {} + }; + + template <typename T> struct bit_xor : binary_function<T, T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a, + typename TypeTraits<T>::ParameterType b) const + { + return a ^ b; + } + __host__ __device__ __forceinline__ bit_xor() {} + __host__ __device__ __forceinline__ bit_xor(const bit_xor&) {} + }; + + template <typename T> struct bit_not : unary_function<T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType v) const + { + return ~v; + } + __host__ __device__ __forceinline__ bit_not() {} + __host__ __device__ __forceinline__ bit_not(const bit_not&) {} + }; + + // Generalized Identity Operations + template <typename T> struct identity : unary_function<T, T> + { + __device__ __forceinline__ typename TypeTraits<T>::ParameterType operator()(typename TypeTraits<T>::ParameterType x) const + { + return x; + } + __host__ __device__ __forceinline__ identity() {} + __host__ __device__ __forceinline__ identity(const identity&) {} + }; + + template <typename T1, typename T2> struct project1st : binary_function<T1, T2, T1> + { + __device__ __forceinline__ typename TypeTraits<T1>::ParameterType operator()(typename TypeTraits<T1>::ParameterType lhs, typename TypeTraits<T2>::ParameterType rhs) const + { + return lhs; + } + __host__ __device__ __forceinline__ project1st() {} + __host__ __device__ __forceinline__ project1st(const project1st&) {} + }; + + template <typename T1, typename T2> struct project2nd : binary_function<T1, T2, T2> + { + __device__ __forceinline__ typename TypeTraits<T2>::ParameterType operator()(typename TypeTraits<T1>::ParameterType lhs, typename TypeTraits<T2>::ParameterType rhs) const + { + return rhs; + } + __host__ __device__ __forceinline__ project2nd() {} + __host__ __device__ __forceinline__ project2nd(const project2nd&) {} + }; + + // Min/Max Operations + +#define OPENCV_CUDA_IMPLEMENT_MINMAX(name, type, op) \ + template <> struct name<type> : binary_function<type, type, type> \ + { \ + __device__ __forceinline__ type operator()(type lhs, type rhs) const {return op(lhs, rhs);} \ + __host__ __device__ __forceinline__ name() {}\ + __host__ __device__ __forceinline__ name(const name&) {}\ + }; + + template <typename T> struct maximum : binary_function<T, T, T> + { + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType lhs, typename TypeTraits<T>::ParameterType rhs) const + { + return max(lhs, rhs); + } + __host__ __device__ __forceinline__ maximum() {} + __host__ __device__ __forceinline__ maximum(const maximum&) {} + }; + + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, uchar, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, schar, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, char, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, ushort, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, short, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, int, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, uint, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, float, ::fmax) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, double, ::fmax) + + template <typename T> struct minimum : binary_function<T, T, T> + { + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType lhs, typename TypeTraits<T>::ParameterType rhs) const + { + return min(lhs, rhs); + } + __host__ __device__ __forceinline__ minimum() {} + __host__ __device__ __forceinline__ minimum(const minimum&) {} + }; + + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, uchar, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, schar, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, char, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, ushort, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, short, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, int, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, uint, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, float, ::fmin) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, double, ::fmin) + +#undef OPENCV_CUDA_IMPLEMENT_MINMAX + + // Math functions + + template <typename T> struct abs_func : unary_function<T, T> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType x) const + { + return abs(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<unsigned char> : unary_function<unsigned char, unsigned char> + { + __device__ __forceinline__ unsigned char operator ()(unsigned char x) const + { + return x; + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<signed char> : unary_function<signed char, signed char> + { + __device__ __forceinline__ signed char operator ()(signed char x) const + { + return ::abs((int)x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<char> : unary_function<char, char> + { + __device__ __forceinline__ char operator ()(char x) const + { + return ::abs((int)x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<unsigned short> : unary_function<unsigned short, unsigned short> + { + __device__ __forceinline__ unsigned short operator ()(unsigned short x) const + { + return x; + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<short> : unary_function<short, short> + { + __device__ __forceinline__ short operator ()(short x) const + { + return ::abs((int)x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<unsigned int> : unary_function<unsigned int, unsigned int> + { + __device__ __forceinline__ unsigned int operator ()(unsigned int x) const + { + return x; + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<int> : unary_function<int, int> + { + __device__ __forceinline__ int operator ()(int x) const + { + return ::abs(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<float> : unary_function<float, float> + { + __device__ __forceinline__ float operator ()(float x) const + { + return ::fabsf(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func<double> : unary_function<double, double> + { + __device__ __forceinline__ double operator ()(double x) const + { + return ::fabs(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + +#define OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(name, func) \ + template <typename T> struct name ## _func : unary_function<T, float> \ + { \ + __device__ __forceinline__ float operator ()(typename TypeTraits<T>::ParameterType v) const \ + { \ + return func ## f(v); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; \ + template <> struct name ## _func<double> : unary_function<double, double> \ + { \ + __device__ __forceinline__ double operator ()(double v) const \ + { \ + return func(v); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; + +#define OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(name, func) \ + template <typename T> struct name ## _func : binary_function<T, T, float> \ + { \ + __device__ __forceinline__ float operator ()(typename TypeTraits<T>::ParameterType v1, typename TypeTraits<T>::ParameterType v2) const \ + { \ + return func ## f(v1, v2); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; \ + template <> struct name ## _func<double> : binary_function<double, double, double> \ + { \ + __device__ __forceinline__ double operator ()(double v1, double v2) const \ + { \ + return func(v1, v2); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; + + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(sqrt, ::sqrt) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(exp, ::exp) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(exp2, ::exp2) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(exp10, ::exp10) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(log, ::log) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(log2, ::log2) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(log10, ::log10) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(sin, ::sin) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(cos, ::cos) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(tan, ::tan) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(asin, ::asin) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(acos, ::acos) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(atan, ::atan) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(sinh, ::sinh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(cosh, ::cosh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(tanh, ::tanh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(asinh, ::asinh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(acosh, ::acosh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(atanh, ::atanh) + + OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(hypot, ::hypot) + OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(atan2, ::atan2) + OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(pow, ::pow) + + #undef OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR + #undef OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR_NO_DOUBLE + #undef OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR + + template<typename T> struct hypot_sqr_func : binary_function<T, T, float> + { + __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType src1, typename TypeTraits<T>::ParameterType src2) const + { + return src1 * src1 + src2 * src2; + } + __host__ __device__ __forceinline__ hypot_sqr_func() {} + __host__ __device__ __forceinline__ hypot_sqr_func(const hypot_sqr_func&) {} + }; + + // Saturate Cast Functor + template <typename T, typename D> struct saturate_cast_func : unary_function<T, D> + { + __device__ __forceinline__ D operator ()(typename TypeTraits<T>::ParameterType v) const + { + return saturate_cast<D>(v); + } + __host__ __device__ __forceinline__ saturate_cast_func() {} + __host__ __device__ __forceinline__ saturate_cast_func(const saturate_cast_func&) {} + }; + + // Threshold Functors + template <typename T> struct thresh_binary_func : unary_function<T, T> + { + __host__ __device__ __forceinline__ thresh_binary_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {} + + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const + { + return (src > thresh) * maxVal; + } + + __host__ __device__ __forceinline__ thresh_binary_func() {} + __host__ __device__ __forceinline__ thresh_binary_func(const thresh_binary_func& other) + : thresh(other.thresh), maxVal(other.maxVal) {} + + T thresh; + T maxVal; + }; + + template <typename T> struct thresh_binary_inv_func : unary_function<T, T> + { + __host__ __device__ __forceinline__ thresh_binary_inv_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {} + + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const + { + return (src <= thresh) * maxVal; + } + + __host__ __device__ __forceinline__ thresh_binary_inv_func() {} + __host__ __device__ __forceinline__ thresh_binary_inv_func(const thresh_binary_inv_func& other) + : thresh(other.thresh), maxVal(other.maxVal) {} + + T thresh; + T maxVal; + }; + + template <typename T> struct thresh_trunc_func : unary_function<T, T> + { + explicit __host__ __device__ __forceinline__ thresh_trunc_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {CV_UNUSED(maxVal_);} + + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const + { + return minimum<T>()(src, thresh); + } + + __host__ __device__ __forceinline__ thresh_trunc_func() {} + __host__ __device__ __forceinline__ thresh_trunc_func(const thresh_trunc_func& other) + : thresh(other.thresh) {} + + T thresh; + }; + + template <typename T> struct thresh_to_zero_func : unary_function<T, T> + { + explicit __host__ __device__ __forceinline__ thresh_to_zero_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {CV_UNUSED(maxVal_);} + + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const + { + return (src > thresh) * src; + } + + __host__ __device__ __forceinline__ thresh_to_zero_func() {} + __host__ __device__ __forceinline__ thresh_to_zero_func(const thresh_to_zero_func& other) + : thresh(other.thresh) {} + + T thresh; + }; + + template <typename T> struct thresh_to_zero_inv_func : unary_function<T, T> + { + explicit __host__ __device__ __forceinline__ thresh_to_zero_inv_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {CV_UNUSED(maxVal_);} + + __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const + { + return (src <= thresh) * src; + } + + __host__ __device__ __forceinline__ thresh_to_zero_inv_func() {} + __host__ __device__ __forceinline__ thresh_to_zero_inv_func(const thresh_to_zero_inv_func& other) + : thresh(other.thresh) {} + + T thresh; + }; + + // Function Object Adaptors + template <typename Predicate> struct unary_negate : unary_function<typename Predicate::argument_type, bool> + { + explicit __host__ __device__ __forceinline__ unary_negate(const Predicate& p) : pred(p) {} + + __device__ __forceinline__ bool operator()(typename TypeTraits<typename Predicate::argument_type>::ParameterType x) const + { + return !pred(x); + } + + __host__ __device__ __forceinline__ unary_negate() {} + __host__ __device__ __forceinline__ unary_negate(const unary_negate& other) : pred(other.pred) {} + + Predicate pred; + }; + + template <typename Predicate> __host__ __device__ __forceinline__ unary_negate<Predicate> not1(const Predicate& pred) + { + return unary_negate<Predicate>(pred); + } + + template <typename Predicate> struct binary_negate : binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool> + { + explicit __host__ __device__ __forceinline__ binary_negate(const Predicate& p) : pred(p) {} + + __device__ __forceinline__ bool operator()(typename TypeTraits<typename Predicate::first_argument_type>::ParameterType x, + typename TypeTraits<typename Predicate::second_argument_type>::ParameterType y) const + { + return !pred(x,y); + } + + __host__ __device__ __forceinline__ binary_negate() {} + __host__ __device__ __forceinline__ binary_negate(const binary_negate& other) : pred(other.pred) {} + + Predicate pred; + }; + + template <typename BinaryPredicate> __host__ __device__ __forceinline__ binary_negate<BinaryPredicate> not2(const BinaryPredicate& pred) + { + return binary_negate<BinaryPredicate>(pred); + } + + template <typename Op> struct binder1st : unary_function<typename Op::second_argument_type, typename Op::result_type> + { + __host__ __device__ __forceinline__ binder1st(const Op& op_, const typename Op::first_argument_type& arg1_) : op(op_), arg1(arg1_) {} + + __device__ __forceinline__ typename Op::result_type operator ()(typename TypeTraits<typename Op::second_argument_type>::ParameterType a) const + { + return op(arg1, a); + } + + __host__ __device__ __forceinline__ binder1st() {} + __host__ __device__ __forceinline__ binder1st(const binder1st& other) : op(other.op), arg1(other.arg1) {} + + Op op; + typename Op::first_argument_type arg1; + }; + + template <typename Op, typename T> __host__ __device__ __forceinline__ binder1st<Op> bind1st(const Op& op, const T& x) + { + return binder1st<Op>(op, typename Op::first_argument_type(x)); + } + + template <typename Op> struct binder2nd : unary_function<typename Op::first_argument_type, typename Op::result_type> + { + __host__ __device__ __forceinline__ binder2nd(const Op& op_, const typename Op::second_argument_type& arg2_) : op(op_), arg2(arg2_) {} + + __forceinline__ __device__ typename Op::result_type operator ()(typename TypeTraits<typename Op::first_argument_type>::ParameterType a) const + { + return op(a, arg2); + } + + __host__ __device__ __forceinline__ binder2nd() {} + __host__ __device__ __forceinline__ binder2nd(const binder2nd& other) : op(other.op), arg2(other.arg2) {} + + Op op; + typename Op::second_argument_type arg2; + }; + + template <typename Op, typename T> __host__ __device__ __forceinline__ binder2nd<Op> bind2nd(const Op& op, const T& x) + { + return binder2nd<Op>(op, typename Op::second_argument_type(x)); + } + + // Functor Traits + template <typename F> struct IsUnaryFunction + { + typedef char Yes; + struct No {Yes a[2];}; + + template <typename T, typename D> static Yes check(unary_function<T, D>); + static No check(...); + + static F makeF(); + + enum { value = (sizeof(check(makeF())) == sizeof(Yes)) }; + }; + + template <typename F> struct IsBinaryFunction + { + typedef char Yes; + struct No {Yes a[2];}; + + template <typename T1, typename T2, typename D> static Yes check(binary_function<T1, T2, D>); + static No check(...); + + static F makeF(); + + enum { value = (sizeof(check(makeF())) == sizeof(Yes)) }; + }; + + namespace functional_detail + { + template <size_t src_elem_size, size_t dst_elem_size> struct UnOpShift { enum { shift = 1 }; }; + template <size_t src_elem_size> struct UnOpShift<src_elem_size, 1> { enum { shift = 4 }; }; + template <size_t src_elem_size> struct UnOpShift<src_elem_size, 2> { enum { shift = 2 }; }; + + template <typename T, typename D> struct DefaultUnaryShift + { + enum { shift = UnOpShift<sizeof(T), sizeof(D)>::shift }; + }; + + template <size_t src_elem_size1, size_t src_elem_size2, size_t dst_elem_size> struct BinOpShift { enum { shift = 1 }; }; + template <size_t src_elem_size1, size_t src_elem_size2> struct BinOpShift<src_elem_size1, src_elem_size2, 1> { enum { shift = 4 }; }; + template <size_t src_elem_size1, size_t src_elem_size2> struct BinOpShift<src_elem_size1, src_elem_size2, 2> { enum { shift = 2 }; }; + + template <typename T1, typename T2, typename D> struct DefaultBinaryShift + { + enum { shift = BinOpShift<sizeof(T1), sizeof(T2), sizeof(D)>::shift }; + }; + + template <typename Func, bool unary = IsUnaryFunction<Func>::value> struct ShiftDispatcher; + template <typename Func> struct ShiftDispatcher<Func, true> + { + enum { shift = DefaultUnaryShift<typename Func::argument_type, typename Func::result_type>::shift }; + }; + template <typename Func> struct ShiftDispatcher<Func, false> + { + enum { shift = DefaultBinaryShift<typename Func::first_argument_type, typename Func::second_argument_type, typename Func::result_type>::shift }; + }; + } + + template <typename Func> struct DefaultTransformShift + { + enum { shift = functional_detail::ShiftDispatcher<Func>::shift }; + }; + + template <typename Func> struct DefaultTransformFunctorTraits + { + enum { simple_block_dim_x = 16 }; + enum { simple_block_dim_y = 16 }; + + enum { smart_block_dim_x = 16 }; + enum { smart_block_dim_y = 16 }; + enum { smart_shift = DefaultTransformShift<Func>::shift }; + }; + + template <typename Func> struct TransformFunctorTraits : DefaultTransformFunctorTraits<Func> {}; + +#define OPENCV_CUDA_TRANSFORM_FUNCTOR_TRAITS(type) \ + template <> struct TransformFunctorTraits< type > : DefaultTransformFunctorTraits< type > +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_FUNCTIONAL_HPP diff --git a/include/opencv2/core/cuda/limits.hpp b/include/opencv2/core/cuda/limits.hpp new file mode 100644 index 0000000..7e15ed6 --- /dev/null +++ b/include/opencv2/core/cuda/limits.hpp @@ -0,0 +1,128 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_LIMITS_HPP +#define OPENCV_CUDA_LIMITS_HPP + +#include <limits.h> +#include <float.h> +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ +template <class T> struct numeric_limits; + +template <> struct numeric_limits<bool> +{ + __device__ __forceinline__ static bool min() { return false; } + __device__ __forceinline__ static bool max() { return true; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits<signed char> +{ + __device__ __forceinline__ static signed char min() { return SCHAR_MIN; } + __device__ __forceinline__ static signed char max() { return SCHAR_MAX; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits<unsigned char> +{ + __device__ __forceinline__ static unsigned char min() { return 0; } + __device__ __forceinline__ static unsigned char max() { return UCHAR_MAX; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits<short> +{ + __device__ __forceinline__ static short min() { return SHRT_MIN; } + __device__ __forceinline__ static short max() { return SHRT_MAX; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits<unsigned short> +{ + __device__ __forceinline__ static unsigned short min() { return 0; } + __device__ __forceinline__ static unsigned short max() { return USHRT_MAX; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits<int> +{ + __device__ __forceinline__ static int min() { return INT_MIN; } + __device__ __forceinline__ static int max() { return INT_MAX; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits<unsigned int> +{ + __device__ __forceinline__ static unsigned int min() { return 0; } + __device__ __forceinline__ static unsigned int max() { return UINT_MAX; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits<float> +{ + __device__ __forceinline__ static float min() { return FLT_MIN; } + __device__ __forceinline__ static float max() { return FLT_MAX; } + __device__ __forceinline__ static float epsilon() { return FLT_EPSILON; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits<double> +{ + __device__ __forceinline__ static double min() { return DBL_MIN; } + __device__ __forceinline__ static double max() { return DBL_MAX; } + __device__ __forceinline__ static double epsilon() { return DBL_EPSILON; } + static const bool is_signed = true; +}; +}}} // namespace cv { namespace cuda { namespace cudev { + +//! @endcond + +#endif // OPENCV_CUDA_LIMITS_HPP diff --git a/include/opencv2/core/cuda/reduce.hpp b/include/opencv2/core/cuda/reduce.hpp new file mode 100644 index 0000000..5de3650 --- /dev/null +++ b/include/opencv2/core/cuda/reduce.hpp @@ -0,0 +1,209 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_REDUCE_HPP +#define OPENCV_CUDA_REDUCE_HPP + +#ifndef THRUST_DEBUG // eliminate -Wundef warning +#define THRUST_DEBUG 0 +#endif + +#include <thrust/tuple.h> +#include "detail/reduce.hpp" +#include "detail/reduce_key_val.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template <int N, typename T, class Op> + __device__ __forceinline__ void reduce(volatile T* smem, T& val, unsigned int tid, const Op& op) + { + reduce_detail::Dispatcher<N>::reductor::template reduce<volatile T*, T&, const Op&>(smem, val, tid, op); + } + template <int N, + typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, + typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9, + class Op0, class Op1, class Op2, class Op3, class Op4, class Op5, class Op6, class Op7, class Op8, class Op9> + __device__ __forceinline__ void reduce(const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>& smem, + const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val, + unsigned int tid, + const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>& op) + { + reduce_detail::Dispatcher<N>::reductor::template reduce< + const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>&, + const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>&, + const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>&>(smem, val, tid, op); + } + + template <unsigned int N, typename K, typename V, class Cmp> + __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, volatile V* svals, V& val, unsigned int tid, const Cmp& cmp) + { + reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<volatile K*, K&, volatile V*, V&, const Cmp&>(skeys, key, svals, val, tid, cmp); + } + template <unsigned int N, + typename K, + typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9, + class Cmp> + __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, + const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + unsigned int tid, const Cmp& cmp) + { + reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<volatile K*, K&, + const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>&, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>&, + const Cmp&>(skeys, key, svals, val, tid, cmp); + } + template <unsigned int N, + typename KP0, typename KP1, typename KP2, typename KP3, typename KP4, typename KP5, typename KP6, typename KP7, typename KP8, typename KP9, + typename KR0, typename KR1, typename KR2, typename KR3, typename KR4, typename KR5, typename KR6, typename KR7, typename KR8, typename KR9, + typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9, + typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9, + class Cmp0, class Cmp1, class Cmp2, class Cmp3, class Cmp4, class Cmp5, class Cmp6, class Cmp7, class Cmp8, class Cmp9> + __device__ __forceinline__ void reduceKeyVal(const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>& skeys, + const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>& key, + const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val, + unsigned int tid, + const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>& cmp) + { + reduce_key_val_detail::Dispatcher<N>::reductor::template reduce< + const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>&, + const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>&, + const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>&, + const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>&, + const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>& + >(skeys, key, svals, val, tid, cmp); + } + + // smem_tuple + + template <typename T0> + __device__ __forceinline__ + thrust::tuple<volatile T0*> + smem_tuple(T0* t0) + { + return thrust::make_tuple((volatile T0*) t0); + } + + template <typename T0, typename T1> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*> + smem_tuple(T0* t0, T1* t1) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1); + } + + template <typename T0, typename T1, typename T2> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*> + smem_tuple(T0* t0, T1* t1, T2* t2) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2); + } + + template <typename T0, typename T1, typename T2, typename T3> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3); + } + + template <typename T0, typename T1, typename T2, typename T3, typename T4> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4); + } + + template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5); + } + + template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6); + } + + template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7); + } + + template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*, volatile T8*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7, (volatile T8*) t8); + } + + template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> + __device__ __forceinline__ + thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*, volatile T8*, volatile T9*> + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8, T9* t9) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7, (volatile T8*) t8, (volatile T9*) t9); + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_REDUCE_HPP diff --git a/include/opencv2/core/cuda/saturate_cast.hpp b/include/opencv2/core/cuda/saturate_cast.hpp new file mode 100644 index 0000000..c3a3d1c --- /dev/null +++ b/include/opencv2/core/cuda/saturate_cast.hpp @@ -0,0 +1,292 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_SATURATE_CAST_HPP +#define OPENCV_CUDA_SATURATE_CAST_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(uchar v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(schar v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(ushort v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(short v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(uint v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(int v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(float v) { return _Tp(v); } + template<typename _Tp> __device__ __forceinline__ _Tp saturate_cast(double v) { return _Tp(v); } + + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(schar v) + { + uint res = 0; + int vi = v; + asm("cvt.sat.u8.s8 %0, %1;" : "=r"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(short v) + { + uint res = 0; + asm("cvt.sat.u8.s16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(ushort v) + { + uint res = 0; + asm("cvt.sat.u8.u16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(int v) + { + uint res = 0; + asm("cvt.sat.u8.s32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(uint v) + { + uint res = 0; + asm("cvt.sat.u8.u32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(float v) + { + uint res = 0; + asm("cvt.rni.sat.u8.f32 %0, %1;" : "=r"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast<uchar>(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + uint res = 0; + asm("cvt.rni.sat.u8.f64 %0, %1;" : "=r"(res) : "d"(v)); + return res; + #else + return saturate_cast<uchar>((float)v); + #endif + } + + template<> __device__ __forceinline__ schar saturate_cast<schar>(uchar v) + { + uint res = 0; + uint vi = v; + asm("cvt.sat.s8.u8 %0, %1;" : "=r"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast<schar>(short v) + { + uint res = 0; + asm("cvt.sat.s8.s16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast<schar>(ushort v) + { + uint res = 0; + asm("cvt.sat.s8.u16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast<schar>(int v) + { + uint res = 0; + asm("cvt.sat.s8.s32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast<schar>(uint v) + { + uint res = 0; + asm("cvt.sat.s8.u32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast<schar>(float v) + { + uint res = 0; + asm("cvt.rni.sat.s8.f32 %0, %1;" : "=r"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast<schar>(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + uint res = 0; + asm("cvt.rni.sat.s8.f64 %0, %1;" : "=r"(res) : "d"(v)); + return res; + #else + return saturate_cast<schar>((float)v); + #endif + } + + template<> __device__ __forceinline__ ushort saturate_cast<ushort>(schar v) + { + ushort res = 0; + int vi = v; + asm("cvt.sat.u16.s8 %0, %1;" : "=h"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast<ushort>(short v) + { + ushort res = 0; + asm("cvt.sat.u16.s16 %0, %1;" : "=h"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast<ushort>(int v) + { + ushort res = 0; + asm("cvt.sat.u16.s32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast<ushort>(uint v) + { + ushort res = 0; + asm("cvt.sat.u16.u32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast<ushort>(float v) + { + ushort res = 0; + asm("cvt.rni.sat.u16.f32 %0, %1;" : "=h"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast<ushort>(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + ushort res = 0; + asm("cvt.rni.sat.u16.f64 %0, %1;" : "=h"(res) : "d"(v)); + return res; + #else + return saturate_cast<ushort>((float)v); + #endif + } + + template<> __device__ __forceinline__ short saturate_cast<short>(ushort v) + { + short res = 0; + asm("cvt.sat.s16.u16 %0, %1;" : "=h"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast<short>(int v) + { + short res = 0; + asm("cvt.sat.s16.s32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast<short>(uint v) + { + short res = 0; + asm("cvt.sat.s16.u32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast<short>(float v) + { + short res = 0; + asm("cvt.rni.sat.s16.f32 %0, %1;" : "=h"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast<short>(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + short res = 0; + asm("cvt.rni.sat.s16.f64 %0, %1;" : "=h"(res) : "d"(v)); + return res; + #else + return saturate_cast<short>((float)v); + #endif + } + + template<> __device__ __forceinline__ int saturate_cast<int>(uint v) + { + int res = 0; + asm("cvt.sat.s32.u32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ int saturate_cast<int>(float v) + { + return __float2int_rn(v); + } + template<> __device__ __forceinline__ int saturate_cast<int>(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + return __double2int_rn(v); + #else + return saturate_cast<int>((float)v); + #endif + } + + template<> __device__ __forceinline__ uint saturate_cast<uint>(schar v) + { + uint res = 0; + int vi = v; + asm("cvt.sat.u32.s8 %0, %1;" : "=r"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ uint saturate_cast<uint>(short v) + { + uint res = 0; + asm("cvt.sat.u32.s16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ uint saturate_cast<uint>(int v) + { + uint res = 0; + asm("cvt.sat.u32.s32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ uint saturate_cast<uint>(float v) + { + return __float2uint_rn(v); + } + template<> __device__ __forceinline__ uint saturate_cast<uint>(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + return __double2uint_rn(v); + #else + return saturate_cast<uint>((float)v); + #endif + } +}}} + +//! @endcond + +#endif /* OPENCV_CUDA_SATURATE_CAST_HPP */ diff --git a/include/opencv2/core/cuda/scan.hpp b/include/opencv2/core/cuda/scan.hpp new file mode 100644 index 0000000..e128fb0 --- /dev/null +++ b/include/opencv2/core/cuda/scan.hpp @@ -0,0 +1,258 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_SCAN_HPP +#define OPENCV_CUDA_SCAN_HPP + +#include "opencv2/core/cuda/common.hpp" +#include "opencv2/core/cuda/utility.hpp" +#include "opencv2/core/cuda/warp.hpp" +#include "opencv2/core/cuda/warp_shuffle.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + enum ScanKind { EXCLUSIVE = 0, INCLUSIVE = 1 }; + + template <ScanKind Kind, typename T, typename F> struct WarpScan + { + __device__ __forceinline__ WarpScan() {} + __device__ __forceinline__ WarpScan(const WarpScan& other) { CV_UNUSED(other); } + + __device__ __forceinline__ T operator()( volatile T *ptr , const unsigned int idx) + { + const unsigned int lane = idx & 31; + F op; + + if ( lane >= 1) ptr [idx ] = op(ptr [idx - 1], ptr [idx]); + if ( lane >= 2) ptr [idx ] = op(ptr [idx - 2], ptr [idx]); + if ( lane >= 4) ptr [idx ] = op(ptr [idx - 4], ptr [idx]); + if ( lane >= 8) ptr [idx ] = op(ptr [idx - 8], ptr [idx]); + if ( lane >= 16) ptr [idx ] = op(ptr [idx - 16], ptr [idx]); + + if( Kind == INCLUSIVE ) + return ptr [idx]; + else + return (lane > 0) ? ptr [idx - 1] : 0; + } + + __device__ __forceinline__ unsigned int index(const unsigned int tid) + { + return tid; + } + + __device__ __forceinline__ void init(volatile T *ptr){} + + static const int warp_offset = 0; + + typedef WarpScan<INCLUSIVE, T, F> merge; + }; + + template <ScanKind Kind , typename T, typename F> struct WarpScanNoComp + { + __device__ __forceinline__ WarpScanNoComp() {} + __device__ __forceinline__ WarpScanNoComp(const WarpScanNoComp& other) { CV_UNUSED(other); } + + __device__ __forceinline__ T operator()( volatile T *ptr , const unsigned int idx) + { + const unsigned int lane = threadIdx.x & 31; + F op; + + ptr [idx ] = op(ptr [idx - 1], ptr [idx]); + ptr [idx ] = op(ptr [idx - 2], ptr [idx]); + ptr [idx ] = op(ptr [idx - 4], ptr [idx]); + ptr [idx ] = op(ptr [idx - 8], ptr [idx]); + ptr [idx ] = op(ptr [idx - 16], ptr [idx]); + + if( Kind == INCLUSIVE ) + return ptr [idx]; + else + return (lane > 0) ? ptr [idx - 1] : 0; + } + + __device__ __forceinline__ unsigned int index(const unsigned int tid) + { + return (tid >> warp_log) * warp_smem_stride + 16 + (tid & warp_mask); + } + + __device__ __forceinline__ void init(volatile T *ptr) + { + ptr[threadIdx.x] = 0; + } + + static const int warp_smem_stride = 32 + 16 + 1; + static const int warp_offset = 16; + static const int warp_log = 5; + static const int warp_mask = 31; + + typedef WarpScanNoComp<INCLUSIVE, T, F> merge; + }; + + template <ScanKind Kind , typename T, typename Sc, typename F> struct BlockScan + { + __device__ __forceinline__ BlockScan() {} + __device__ __forceinline__ BlockScan(const BlockScan& other) { CV_UNUSED(other); } + + __device__ __forceinline__ T operator()(volatile T *ptr) + { + const unsigned int tid = threadIdx.x; + const unsigned int lane = tid & warp_mask; + const unsigned int warp = tid >> warp_log; + + Sc scan; + typename Sc::merge merge_scan; + const unsigned int idx = scan.index(tid); + + T val = scan(ptr, idx); + __syncthreads (); + + if( warp == 0) + scan.init(ptr); + __syncthreads (); + + if( lane == 31 ) + ptr [scan.warp_offset + warp ] = (Kind == INCLUSIVE) ? val : ptr [idx]; + __syncthreads (); + + if( warp == 0 ) + merge_scan(ptr, idx); + __syncthreads(); + + if ( warp > 0) + val = ptr [scan.warp_offset + warp - 1] + val; + __syncthreads (); + + ptr[idx] = val; + __syncthreads (); + + return val ; + } + + static const int warp_log = 5; + static const int warp_mask = 31; + }; + + template <typename T> + __device__ T warpScanInclusive(T idata, volatile T* s_Data, unsigned int tid) + { + #if __CUDA_ARCH__ >= 300 + const unsigned int laneId = cv::cuda::device::Warp::laneId(); + + // scan on shuffl functions + #pragma unroll + for (int i = 1; i <= (OPENCV_CUDA_WARP_SIZE / 2); i *= 2) + { + const T n = cv::cuda::device::shfl_up(idata, i); + if (laneId >= i) + idata += n; + } + + return idata; + #else + unsigned int pos = 2 * tid - (tid & (OPENCV_CUDA_WARP_SIZE - 1)); + s_Data[pos] = 0; + pos += OPENCV_CUDA_WARP_SIZE; + s_Data[pos] = idata; + + s_Data[pos] += s_Data[pos - 1]; + s_Data[pos] += s_Data[pos - 2]; + s_Data[pos] += s_Data[pos - 4]; + s_Data[pos] += s_Data[pos - 8]; + s_Data[pos] += s_Data[pos - 16]; + + return s_Data[pos]; + #endif + } + + template <typename T> + __device__ __forceinline__ T warpScanExclusive(T idata, volatile T* s_Data, unsigned int tid) + { + return warpScanInclusive(idata, s_Data, tid) - idata; + } + + template <int tiNumScanThreads, typename T> + __device__ T blockScanInclusive(T idata, volatile T* s_Data, unsigned int tid) + { + if (tiNumScanThreads > OPENCV_CUDA_WARP_SIZE) + { + //Bottom-level inclusive warp scan + T warpResult = warpScanInclusive(idata, s_Data, tid); + + //Save top elements of each warp for exclusive warp scan + //sync to wait for warp scans to complete (because s_Data is being overwritten) + __syncthreads(); + if ((tid & (OPENCV_CUDA_WARP_SIZE - 1)) == (OPENCV_CUDA_WARP_SIZE - 1)) + { + s_Data[tid >> OPENCV_CUDA_LOG_WARP_SIZE] = warpResult; + } + + //wait for warp scans to complete + __syncthreads(); + + if (tid < (tiNumScanThreads / OPENCV_CUDA_WARP_SIZE) ) + { + //grab top warp elements + T val = s_Data[tid]; + //calculate exclusive scan and write back to shared memory + s_Data[tid] = warpScanExclusive(val, s_Data, tid); + } + + //return updated warp scans with exclusive scan results + __syncthreads(); + + return warpResult + s_Data[tid >> OPENCV_CUDA_LOG_WARP_SIZE]; + } + else + { + return warpScanInclusive(idata, s_Data, tid); + } + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_SCAN_HPP diff --git a/include/opencv2/core/cuda/simd_functions.hpp b/include/opencv2/core/cuda/simd_functions.hpp new file mode 100644 index 0000000..3d8c2e0 --- /dev/null +++ b/include/opencv2/core/cuda/simd_functions.hpp @@ -0,0 +1,869 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +/* + * Copyright (c) 2013 NVIDIA Corporation. All rights reserved. + * + * 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 name of NVIDIA Corporation nor the names of its 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 THE COPYRIGHT HOLDER 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. + */ + +#ifndef OPENCV_CUDA_SIMD_FUNCTIONS_HPP +#define OPENCV_CUDA_SIMD_FUNCTIONS_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + // 2 + + static __device__ __forceinline__ unsigned int vadd2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vadd2.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vadd.u32.u32.u32.sat %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = a ^ b; // sum bits + r = a + b; // actual sum + s = s ^ r; // determine carry-ins for each bit position + s = s & 0x00010000; // carry-in to high word (= carry-out from low word) + r = r - s; // subtract out carry-out from low word + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsub2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vsub2.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vsub.u32.u32.u32.sat %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = a ^ b; // sum bits + r = a - b; // actual sum + s = s ^ r; // determine carry-ins for each bit position + s = s & 0x00010000; // borrow to high word + r = r + s; // compensate for borrow from low word + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vabsdiff2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vabsdiff2.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vabsdiff.u32.u32.u32.sat %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t, u, v; + s = a & 0x0000ffff; // extract low halfword + r = b & 0x0000ffff; // extract low halfword + u = ::max(r, s); // maximum of low halfwords + v = ::min(r, s); // minimum of low halfwords + s = a & 0xffff0000; // extract high halfword + r = b & 0xffff0000; // extract high halfword + t = ::max(r, s); // maximum of high halfwords + s = ::min(r, s); // minimum of high halfwords + r = u | t; // maximum of both halfwords + s = v | s; // minimum of both halfwords + r = r - s; // |a - b| = max(a,b) - min(a,b); + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vavg2(unsigned int a, unsigned int b) + { + unsigned int r, s; + + // HAKMEM #23: a + b = 2 * (a & b) + (a ^ b) ==> + // (a + b) / 2 = (a & b) + ((a ^ b) >> 1) + s = a ^ b; + r = a & b; + s = s & 0xfffefffe; // ensure shift doesn't cross halfword boundaries + s = s >> 1; + s = r + s; + + return s; + } + + static __device__ __forceinline__ unsigned int vavrg2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vavrg2.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // HAKMEM #23: a + b = 2 * (a | b) - (a ^ b) ==> + // (a + b + 1) / 2 = (a | b) - ((a ^ b) >> 1) + unsigned int s; + s = a ^ b; + r = a | b; + s = s & 0xfffefffe; // ensure shift doesn't cross half-word boundaries + s = s >> 1; + r = r - s; + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vseteq2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.eq %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + r = r ^ c; // extract msbs, msb = 1 if r < 0x8000 + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r & ~c; // msb = 1, if r was 0x0000 + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpeq2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vseteq2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + r = r ^ c; // extract msbs, msb = 1 if r < 0x8000 + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r & ~c; // msb = 1, if r was 0x0000 + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetge2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.ge %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavrg2(a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpge2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetge2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavrg2(a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetgt2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.gt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg2(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80008000; // msbs = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpgt2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetgt2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg2(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80008000; // msbs = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetle2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.le %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg2(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmple2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetle2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg2(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetlt2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.lt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg2(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmplt2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetlt2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg2(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetne2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm ("vset2.u32.u32.ne %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r | c; // msb = 1, if r was not 0x0000 + c = c & 0x80008000; // extract msbs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpne2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetne2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r | c; // msb = 1, if r was not 0x0000 + c = c & 0x80008000; // extract msbs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vmax2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmax2.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmax.u32.u32.u32 %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t, u; + r = a & 0x0000ffff; // extract low halfword + s = b & 0x0000ffff; // extract low halfword + t = ::max(r, s); // maximum of low halfwords + r = a & 0xffff0000; // extract high halfword + s = b & 0xffff0000; // extract high halfword + u = ::max(r, s); // maximum of high halfwords + r = t | u; // combine halfword maximums + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vmin2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmin2.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmin.u32.u32.u32 %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t, u; + r = a & 0x0000ffff; // extract low halfword + s = b & 0x0000ffff; // extract low halfword + t = ::min(r, s); // minimum of low halfwords + r = a & 0xffff0000; // extract high halfword + s = b & 0xffff0000; // extract high halfword + u = ::min(r, s); // minimum of high halfwords + r = t | u; // combine halfword minimums + #endif + + return r; + } + + // 4 + + static __device__ __forceinline__ unsigned int vadd4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vadd4.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vadd.u32.u32.u32.sat %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t; + s = a ^ b; // sum bits + r = a & 0x7f7f7f7f; // clear msbs + t = b & 0x7f7f7f7f; // clear msbs + s = s & 0x80808080; // msb sum bits + r = r + t; // add without msbs, record carry-out in msbs + r = r ^ s; // sum of msb sum and carry-in bits, w/o carry-out + #endif /* __CUDA_ARCH__ >= 300 */ + + return r; + } + + static __device__ __forceinline__ unsigned int vsub4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vsub4.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vsub.u32.u32.u32.sat %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t; + s = a ^ ~b; // inverted sum bits + r = a | 0x80808080; // set msbs + t = b & 0x7f7f7f7f; // clear msbs + s = s & 0x80808080; // inverted msb sum bits + r = r - t; // subtract w/o msbs, record inverted borrows in msb + r = r ^ s; // combine inverted msb sum bits and borrows + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vavg4(unsigned int a, unsigned int b) + { + unsigned int r, s; + + // HAKMEM #23: a + b = 2 * (a & b) + (a ^ b) ==> + // (a + b) / 2 = (a & b) + ((a ^ b) >> 1) + s = a ^ b; + r = a & b; + s = s & 0xfefefefe; // ensure following shift doesn't cross byte boundaries + s = s >> 1; + s = r + s; + + return s; + } + + static __device__ __forceinline__ unsigned int vavrg4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vavrg4.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // HAKMEM #23: a + b = 2 * (a | b) - (a ^ b) ==> + // (a + b + 1) / 2 = (a | b) - ((a ^ b) >> 1) + unsigned int c; + c = a ^ b; + r = a | b; + c = c & 0xfefefefe; // ensure following shift doesn't cross byte boundaries + c = c >> 1; + r = r - c; + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vseteq4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.eq %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x00 if a == b + c = r | 0x80808080; // set msbs, to catch carry out + r = r ^ c; // extract msbs, msb = 1 if r < 0x80 + c = c - 0x01010101; // msb = 0, if r was 0x00 or 0x80 + c = r & ~c; // msb = 1, if r was 0x00 + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpeq4(unsigned int a, unsigned int b) + { + unsigned int r, t; + + #if __CUDA_ARCH__ >= 300 + r = vseteq4(a, b); + t = r << 8; // convert bool + r = t - r; // to mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + t = a ^ b; // 0x00 if a == b + r = t | 0x80808080; // set msbs, to catch carry out + t = t ^ r; // extract msbs, msb = 1 if t < 0x80 + r = r - 0x01010101; // msb = 0, if t was 0x00 or 0x80 + r = t & ~r; // msb = 1, if t was 0x00 + t = r >> 7; // build mask + t = r - t; // from + r = t | r; // msbs + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetle4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.le %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg4(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmple4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetle4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg4(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80808080; // msbs = carry-outs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetlt4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.lt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg4(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmplt4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetlt4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg4(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80808080; // msbs = carry-outs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetge4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.ge %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavrg4(a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpge4(unsigned int a, unsigned int b) + { + unsigned int r, s; + + #if __CUDA_ARCH__ >= 300 + r = vsetge4(a, b); + s = r << 8; // convert bool + r = s - r; // to mask + #else + asm ("not.b32 %0,%0;" : "+r"(b)); + r = vavrg4 (a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + r = r & 0x80808080; // msb = carry-outs + s = r >> 7; // build mask + s = r - s; // from + r = s | r; // msbs + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetgt4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.gt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg4(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpgt4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetgt4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg4(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetne4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.ne %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x00 if a == b + c = r | 0x80808080; // set msbs, to catch carry out + c = c - 0x01010101; // msb = 0, if r was 0x00 or 0x80 + c = r | c; // msb = 1, if r was not 0x00 + c = c & 0x80808080; // extract msbs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpne4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetne4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + r = a ^ b; // 0x00 if a == b + c = r | 0x80808080; // set msbs, to catch carry out + c = c - 0x01010101; // msb = 0, if r was 0x00 or 0x80 + c = r | c; // msb = 1, if r was not 0x00 + c = c & 0x80808080; // extract msbs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vabsdiff4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vabsdiff4.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vabsdiff.u32.u32.u32.sat %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = vcmpge4(a, b); // mask = 0xff if a >= b + r = a ^ b; // + s = (r & s) ^ b; // select a when a >= b, else select b => max(a,b) + r = s ^ r; // select a when b >= a, else select b => min(a,b) + r = s - r; // |a - b| = max(a,b) - min(a,b); + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vmax4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmax4.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmax.u32.u32.u32 %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = vcmpge4(a, b); // mask = 0xff if a >= b + r = a & s; // select a when b >= a + s = b & ~s; // select b when b < a + r = r | s; // combine byte selections + #endif + + return r; // byte-wise unsigned maximum + } + + static __device__ __forceinline__ unsigned int vmin4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmin4.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmin.u32.u32.u32 %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = vcmpge4(b, a); // mask = 0xff if a >= b + r = a & s; // select a when b >= a + s = b & ~s; // select b when b < a + r = r | s; // combine byte selections + #endif + + return r; + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_SIMD_FUNCTIONS_HPP diff --git a/include/opencv2/core/cuda/transform.hpp b/include/opencv2/core/cuda/transform.hpp new file mode 100644 index 0000000..42aa6ea --- /dev/null +++ b/include/opencv2/core/cuda/transform.hpp @@ -0,0 +1,75 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_TRANSFORM_HPP +#define OPENCV_CUDA_TRANSFORM_HPP + +#include "common.hpp" +#include "utility.hpp" +#include "detail/transform_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template <typename T, typename D, typename UnOp, typename Mask> + static inline void transform(PtrStepSz<T> src, PtrStepSz<D> dst, UnOp op, const Mask& mask, cudaStream_t stream) + { + typedef TransformFunctorTraits<UnOp> ft; + transform_detail::TransformDispatcher<VecTraits<T>::cn == 1 && VecTraits<D>::cn == 1 && ft::smart_shift != 1>::call(src, dst, op, mask, stream); + } + + template <typename T1, typename T2, typename D, typename BinOp, typename Mask> + static inline void transform(PtrStepSz<T1> src1, PtrStepSz<T2> src2, PtrStepSz<D> dst, BinOp op, const Mask& mask, cudaStream_t stream) + { + typedef TransformFunctorTraits<BinOp> ft; + transform_detail::TransformDispatcher<VecTraits<T1>::cn == 1 && VecTraits<T2>::cn == 1 && VecTraits<D>::cn == 1 && ft::smart_shift != 1>::call(src1, src2, dst, op, mask, stream); + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_TRANSFORM_HPP diff --git a/include/opencv2/core/cuda/type_traits.hpp b/include/opencv2/core/cuda/type_traits.hpp new file mode 100644 index 0000000..8b7a3fd --- /dev/null +++ b/include/opencv2/core/cuda/type_traits.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_TYPE_TRAITS_HPP +#define OPENCV_CUDA_TYPE_TRAITS_HPP + +#include "detail/type_traits_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template <typename T> struct IsSimpleParameter + { + enum {value = type_traits_detail::IsIntegral<T>::value || type_traits_detail::IsFloat<T>::value || + type_traits_detail::PointerTraits<typename type_traits_detail::ReferenceTraits<T>::type>::value}; + }; + + template <typename T> struct TypeTraits + { + typedef typename type_traits_detail::UnConst<T>::type NonConstType; + typedef typename type_traits_detail::UnVolatile<T>::type NonVolatileType; + typedef typename type_traits_detail::UnVolatile<typename type_traits_detail::UnConst<T>::type>::type UnqualifiedType; + typedef typename type_traits_detail::PointerTraits<UnqualifiedType>::type PointeeType; + typedef typename type_traits_detail::ReferenceTraits<T>::type ReferredType; + + enum { isConst = type_traits_detail::UnConst<T>::value }; + enum { isVolatile = type_traits_detail::UnVolatile<T>::value }; + + enum { isReference = type_traits_detail::ReferenceTraits<UnqualifiedType>::value }; + enum { isPointer = type_traits_detail::PointerTraits<typename type_traits_detail::ReferenceTraits<UnqualifiedType>::type>::value }; + + enum { isUnsignedInt = type_traits_detail::IsUnsignedIntegral<UnqualifiedType>::value }; + enum { isSignedInt = type_traits_detail::IsSignedIntergral<UnqualifiedType>::value }; + enum { isIntegral = type_traits_detail::IsIntegral<UnqualifiedType>::value }; + enum { isFloat = type_traits_detail::IsFloat<UnqualifiedType>::value }; + enum { isArith = isIntegral || isFloat }; + enum { isVec = type_traits_detail::IsVec<UnqualifiedType>::value }; + + typedef typename type_traits_detail::Select<IsSimpleParameter<UnqualifiedType>::value, + T, typename type_traits_detail::AddParameterType<T>::type>::type ParameterType; + }; +}}} + +//! @endcond + +#endif // OPENCV_CUDA_TYPE_TRAITS_HPP diff --git a/include/opencv2/core/cuda/utility.hpp b/include/opencv2/core/cuda/utility.hpp new file mode 100644 index 0000000..7f5db48 --- /dev/null +++ b/include/opencv2/core/cuda/utility.hpp @@ -0,0 +1,230 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_UTILITY_HPP +#define OPENCV_CUDA_UTILITY_HPP + +#include "saturate_cast.hpp" +#include "datamov_utils.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct CV_EXPORTS ThrustAllocator + { + typedef uchar value_type; + virtual ~ThrustAllocator(); + virtual __device__ __host__ uchar* allocate(size_t numBytes) = 0; + virtual __device__ __host__ void deallocate(uchar* ptr, size_t numBytes) = 0; + static ThrustAllocator& getAllocator(); + static void setAllocator(ThrustAllocator* allocator); + }; + #define OPENCV_CUDA_LOG_WARP_SIZE (5) + #define OPENCV_CUDA_WARP_SIZE (1 << OPENCV_CUDA_LOG_WARP_SIZE) + #define OPENCV_CUDA_LOG_MEM_BANKS ((__CUDA_ARCH__ >= 200) ? 5 : 4) // 32 banks on fermi, 16 on tesla + #define OPENCV_CUDA_MEM_BANKS (1 << OPENCV_CUDA_LOG_MEM_BANKS) + + /////////////////////////////////////////////////////////////////////////////// + // swap + + template <typename T> void __device__ __host__ __forceinline__ swap(T& a, T& b) + { + const T temp = a; + a = b; + b = temp; + } + + /////////////////////////////////////////////////////////////////////////////// + // Mask Reader + + struct SingleMask + { + explicit __host__ __device__ __forceinline__ SingleMask(PtrStepb mask_) : mask(mask_) {} + __host__ __device__ __forceinline__ SingleMask(const SingleMask& mask_): mask(mask_.mask){} + + __device__ __forceinline__ bool operator()(int y, int x) const + { + return mask.ptr(y)[x] != 0; + } + + PtrStepb mask; + }; + + struct SingleMaskChannels + { + __host__ __device__ __forceinline__ SingleMaskChannels(PtrStepb mask_, int channels_) + : mask(mask_), channels(channels_) {} + __host__ __device__ __forceinline__ SingleMaskChannels(const SingleMaskChannels& mask_) + :mask(mask_.mask), channels(mask_.channels){} + + __device__ __forceinline__ bool operator()(int y, int x) const + { + return mask.ptr(y)[x / channels] != 0; + } + + PtrStepb mask; + int channels; + }; + + struct MaskCollection + { + explicit __host__ __device__ __forceinline__ MaskCollection(PtrStepb* maskCollection_) + : maskCollection(maskCollection_) {} + + __device__ __forceinline__ MaskCollection(const MaskCollection& masks_) + : maskCollection(masks_.maskCollection), curMask(masks_.curMask){} + + __device__ __forceinline__ void next() + { + curMask = *maskCollection++; + } + __device__ __forceinline__ void setMask(int z) + { + curMask = maskCollection[z]; + } + + __device__ __forceinline__ bool operator()(int y, int x) const + { + uchar val; + return curMask.data == 0 || (ForceGlob<uchar>::Load(curMask.ptr(y), x, val), (val != 0)); + } + + const PtrStepb* maskCollection; + PtrStepb curMask; + }; + + struct WithOutMask + { + __host__ __device__ __forceinline__ WithOutMask(){} + __host__ __device__ __forceinline__ WithOutMask(const WithOutMask&){} + + __device__ __forceinline__ void next() const + { + } + __device__ __forceinline__ void setMask(int) const + { + } + + __device__ __forceinline__ bool operator()(int, int) const + { + return true; + } + + __device__ __forceinline__ bool operator()(int, int, int) const + { + return true; + } + + static __device__ __forceinline__ bool check(int, int) + { + return true; + } + + static __device__ __forceinline__ bool check(int, int, int) + { + return true; + } + }; + + /////////////////////////////////////////////////////////////////////////////// + // Solve linear system + + // solve 2x2 linear system Ax=b + template <typename T> __device__ __forceinline__ bool solve2x2(const T A[2][2], const T b[2], T x[2]) + { + T det = A[0][0] * A[1][1] - A[1][0] * A[0][1]; + + if (det != 0) + { + double invdet = 1.0 / det; + + x[0] = saturate_cast<T>(invdet * (b[0] * A[1][1] - b[1] * A[0][1])); + + x[1] = saturate_cast<T>(invdet * (A[0][0] * b[1] - A[1][0] * b[0])); + + return true; + } + + return false; + } + + // solve 3x3 linear system Ax=b + template <typename T> __device__ __forceinline__ bool solve3x3(const T A[3][3], const T b[3], T x[3]) + { + T det = A[0][0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) + - A[0][1] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) + + A[0][2] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]); + + if (det != 0) + { + double invdet = 1.0 / det; + + x[0] = saturate_cast<T>(invdet * + (b[0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) - + A[0][1] * (b[1] * A[2][2] - A[1][2] * b[2] ) + + A[0][2] * (b[1] * A[2][1] - A[1][1] * b[2] ))); + + x[1] = saturate_cast<T>(invdet * + (A[0][0] * (b[1] * A[2][2] - A[1][2] * b[2] ) - + b[0] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) + + A[0][2] * (A[1][0] * b[2] - b[1] * A[2][0]))); + + x[2] = saturate_cast<T>(invdet * + (A[0][0] * (A[1][1] * b[2] - b[1] * A[2][1]) - + A[0][1] * (A[1][0] * b[2] - b[1] * A[2][0]) + + b[0] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]))); + + return true; + } + + return false; + } +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_UTILITY_HPP diff --git a/include/opencv2/core/cuda/vec_distance.hpp b/include/opencv2/core/cuda/vec_distance.hpp new file mode 100644 index 0000000..ef6e510 --- /dev/null +++ b/include/opencv2/core/cuda/vec_distance.hpp @@ -0,0 +1,232 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_VEC_DISTANCE_HPP +#define OPENCV_CUDA_VEC_DISTANCE_HPP + +#include "reduce.hpp" +#include "functional.hpp" +#include "detail/vec_distance_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template <typename T> struct L1Dist + { + typedef int value_type; + typedef int result_type; + + __device__ __forceinline__ L1Dist() : mySum(0) {} + + __device__ __forceinline__ void reduceIter(int val1, int val2) + { + mySum = __sad(val1, val2, mySum); + } + + template <int THREAD_DIM> __device__ __forceinline__ void reduceAll(int* smem, int tid) + { + reduce<THREAD_DIM>(smem, mySum, tid, plus<int>()); + } + + __device__ __forceinline__ operator int() const + { + return mySum; + } + + int mySum; + }; + template <> struct L1Dist<float> + { + typedef float value_type; + typedef float result_type; + + __device__ __forceinline__ L1Dist() : mySum(0.0f) {} + + __device__ __forceinline__ void reduceIter(float val1, float val2) + { + mySum += ::fabs(val1 - val2); + } + + template <int THREAD_DIM> __device__ __forceinline__ void reduceAll(float* smem, int tid) + { + reduce<THREAD_DIM>(smem, mySum, tid, plus<float>()); + } + + __device__ __forceinline__ operator float() const + { + return mySum; + } + + float mySum; + }; + + struct L2Dist + { + typedef float value_type; + typedef float result_type; + + __device__ __forceinline__ L2Dist() : mySum(0.0f) {} + + __device__ __forceinline__ void reduceIter(float val1, float val2) + { + float reg = val1 - val2; + mySum += reg * reg; + } + + template <int THREAD_DIM> __device__ __forceinline__ void reduceAll(float* smem, int tid) + { + reduce<THREAD_DIM>(smem, mySum, tid, plus<float>()); + } + + __device__ __forceinline__ operator float() const + { + return sqrtf(mySum); + } + + float mySum; + }; + + struct HammingDist + { + typedef int value_type; + typedef int result_type; + + __device__ __forceinline__ HammingDist() : mySum(0) {} + + __device__ __forceinline__ void reduceIter(int val1, int val2) + { + mySum += __popc(val1 ^ val2); + } + + template <int THREAD_DIM> __device__ __forceinline__ void reduceAll(int* smem, int tid) + { + reduce<THREAD_DIM>(smem, mySum, tid, plus<int>()); + } + + __device__ __forceinline__ operator int() const + { + return mySum; + } + + int mySum; + }; + + // calc distance between two vectors in global memory + template <int THREAD_DIM, typename Dist, typename T1, typename T2> + __device__ void calcVecDiffGlobal(const T1* vec1, const T2* vec2, int len, Dist& dist, typename Dist::result_type* smem, int tid) + { + for (int i = tid; i < len; i += THREAD_DIM) + { + T1 val1; + ForceGlob<T1>::Load(vec1, i, val1); + + T2 val2; + ForceGlob<T2>::Load(vec2, i, val2); + + dist.reduceIter(val1, val2); + } + + dist.reduceAll<THREAD_DIM>(smem, tid); + } + + // calc distance between two vectors, first vector is cached in register or shared memory, second vector is in global memory + template <int THREAD_DIM, int MAX_LEN, bool LEN_EQ_MAX_LEN, typename Dist, typename T1, typename T2> + __device__ __forceinline__ void calcVecDiffCached(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, typename Dist::result_type* smem, int tid) + { + vec_distance_detail::VecDiffCachedCalculator<THREAD_DIM, MAX_LEN, LEN_EQ_MAX_LEN>::calc(vecCached, vecGlob, len, dist, tid); + + dist.reduceAll<THREAD_DIM>(smem, tid); + } + + // calc distance between two vectors in global memory + template <int THREAD_DIM, typename T1> struct VecDiffGlobal + { + explicit __device__ __forceinline__ VecDiffGlobal(const T1* vec1_, int = 0, void* = 0, int = 0, int = 0) + { + vec1 = vec1_; + } + + template <typename T2, typename Dist> + __device__ __forceinline__ void calc(const T2* vec2, int len, Dist& dist, typename Dist::result_type* smem, int tid) const + { + calcVecDiffGlobal<THREAD_DIM>(vec1, vec2, len, dist, smem, tid); + } + + const T1* vec1; + }; + + // calc distance between two vectors, first vector is cached in register memory, second vector is in global memory + template <int THREAD_DIM, int MAX_LEN, bool LEN_EQ_MAX_LEN, typename U> struct VecDiffCachedRegister + { + template <typename T1> __device__ __forceinline__ VecDiffCachedRegister(const T1* vec1, int len, U* smem, int glob_tid, int tid) + { + if (glob_tid < len) + smem[glob_tid] = vec1[glob_tid]; + __syncthreads(); + + U* vec1ValsPtr = vec1Vals; + + #pragma unroll + for (int i = tid; i < MAX_LEN; i += THREAD_DIM) + *vec1ValsPtr++ = smem[i]; + + __syncthreads(); + } + + template <typename T2, typename Dist> + __device__ __forceinline__ void calc(const T2* vec2, int len, Dist& dist, typename Dist::result_type* smem, int tid) const + { + calcVecDiffCached<THREAD_DIM, MAX_LEN, LEN_EQ_MAX_LEN>(vec1Vals, vec2, len, dist, smem, tid); + } + + U vec1Vals[MAX_LEN / THREAD_DIM]; + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_VEC_DISTANCE_HPP diff --git a/include/opencv2/core/cuda/vec_math.hpp b/include/opencv2/core/cuda/vec_math.hpp new file mode 100644 index 0000000..9085b92 --- /dev/null +++ b/include/opencv2/core/cuda/vec_math.hpp @@ -0,0 +1,930 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_VECMATH_HPP +#define OPENCV_CUDA_VECMATH_HPP + +#include "vec_traits.hpp" +#include "saturate_cast.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + +// saturate_cast + +namespace vec_math_detail +{ + template <int cn, typename VecD> struct SatCastHelper; + template <typename VecD> struct SatCastHelper<1, VecD> + { + template <typename VecS> static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits<VecD>::elem_type D; + return VecTraits<VecD>::make(saturate_cast<D>(v.x)); + } + }; + template <typename VecD> struct SatCastHelper<2, VecD> + { + template <typename VecS> static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits<VecD>::elem_type D; + return VecTraits<VecD>::make(saturate_cast<D>(v.x), saturate_cast<D>(v.y)); + } + }; + template <typename VecD> struct SatCastHelper<3, VecD> + { + template <typename VecS> static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits<VecD>::elem_type D; + return VecTraits<VecD>::make(saturate_cast<D>(v.x), saturate_cast<D>(v.y), saturate_cast<D>(v.z)); + } + }; + template <typename VecD> struct SatCastHelper<4, VecD> + { + template <typename VecS> static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits<VecD>::elem_type D; + return VecTraits<VecD>::make(saturate_cast<D>(v.x), saturate_cast<D>(v.y), saturate_cast<D>(v.z), saturate_cast<D>(v.w)); + } + }; + + template <typename VecD, typename VecS> static __device__ __forceinline__ VecD saturate_cast_helper(const VecS& v) + { + return SatCastHelper<VecTraits<VecD>::cn, VecD>::cast(v); + } +} + +template<typename T> static __device__ __forceinline__ T saturate_cast(const uchar1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const char1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const ushort1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const short1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const uint1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const int1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const float1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const double1& v) {return vec_math_detail::saturate_cast_helper<T>(v);} + +template<typename T> static __device__ __forceinline__ T saturate_cast(const uchar2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const char2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const ushort2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const short2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const uint2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const int2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const float2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const double2& v) {return vec_math_detail::saturate_cast_helper<T>(v);} + +template<typename T> static __device__ __forceinline__ T saturate_cast(const uchar3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const char3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const ushort3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const short3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const uint3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const int3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const float3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const double3& v) {return vec_math_detail::saturate_cast_helper<T>(v);} + +template<typename T> static __device__ __forceinline__ T saturate_cast(const uchar4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const char4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const ushort4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const short4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const uint4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const int4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const float4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} +template<typename T> static __device__ __forceinline__ T saturate_cast(const double4& v) {return vec_math_detail::saturate_cast_helper<T>(v);} + +// unary operators + +#define CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(op, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 operator op(const input_type ## 1 & a) \ + { \ + return VecTraits<output_type ## 1>::make(op (a.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(const input_type ## 2 & a) \ + { \ + return VecTraits<output_type ## 2>::make(op (a.x), op (a.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(const input_type ## 3 & a) \ + { \ + return VecTraits<output_type ## 3>::make(op (a.x), op (a.y), op (a.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(const input_type ## 4 & a) \ + { \ + return VecTraits<output_type ## 4>::make(op (a.x), op (a.y), op (a.z), op (a.w)); \ + } + +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, char, char) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, short, short) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, int, int) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, char, char) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, short, short) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, int, int) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, uint, uint) + +#undef CV_CUDEV_IMPLEMENT_VEC_UNARY_OP + +// unary functions + +#define CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(func_name, func, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 func_name(const input_type ## 1 & a) \ + { \ + return VecTraits<output_type ## 1>::make(func (a.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(const input_type ## 2 & a) \ + { \ + return VecTraits<output_type ## 2>::make(func (a.x), func (a.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(const input_type ## 3 & a) \ + { \ + return VecTraits<output_type ## 3>::make(func (a.x), func (a.y), func (a.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(const input_type ## 4 & a) \ + { \ + return VecTraits<output_type ## 4>::make(func (a.x), func (a.y), func (a.z), func (a.w)); \ + } + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, /*::abs*/, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::abs, char, char) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, /*::abs*/, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::abs, short, short) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::abs, int, int) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, /*::abs*/, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::fabsf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::fabs, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrt, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::exp, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::log, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sin, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cos, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tan, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asin, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acos, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atan, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::cosh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acosh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanh, double, double) + +#undef CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC + +// binary operators (vec & vec) + +#define CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(op, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 operator op(const input_type ## 1 & a, const input_type ## 1 & b) \ + { \ + return VecTraits<output_type ## 1>::make(a.x op b.x); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(const input_type ## 2 & a, const input_type ## 2 & b) \ + { \ + return VecTraits<output_type ## 2>::make(a.x op b.x, a.y op b.y); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(const input_type ## 3 & a, const input_type ## 3 & b) \ + { \ + return VecTraits<output_type ## 3>::make(a.x op b.x, a.y op b.y, a.z op b.z); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(const input_type ## 4 & a, const input_type ## 4 & b) \ + { \ + return VecTraits<output_type ## 4>::make(a.x op b.x, a.y op b.y, a.z op b.z, a.w op b.w); \ + } + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, uint, uint) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, uint, uint) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, uint, uint) + +#undef CV_CUDEV_IMPLEMENT_VEC_BINARY_OP + +// binary operators (vec & scalar) + +#define CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(op, input_type, scalar_type, output_type) \ + __device__ __forceinline__ output_type ## 1 operator op(const input_type ## 1 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 1>::make(a.x op s); \ + } \ + __device__ __forceinline__ output_type ## 1 operator op(scalar_type s, const input_type ## 1 & b) \ + { \ + return VecTraits<output_type ## 1>::make(s op b.x); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(const input_type ## 2 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 2>::make(a.x op s, a.y op s); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(scalar_type s, const input_type ## 2 & b) \ + { \ + return VecTraits<output_type ## 2>::make(s op b.x, s op b.y); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(const input_type ## 3 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 3>::make(a.x op s, a.y op s, a.z op s); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(scalar_type s, const input_type ## 3 & b) \ + { \ + return VecTraits<output_type ## 3>::make(s op b.x, s op b.y, s op b.z); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(const input_type ## 4 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 4>::make(a.x op s, a.y op s, a.z op s, a.w op s); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(scalar_type s, const input_type ## 4 & b) \ + { \ + return VecTraits<output_type ## 4>::make(s op b.x, s op b.y, s op b.z, s op b.w); \ + } + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, uint, uint, uint) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, uint, uint, uint) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, uint, uint, uint) + +#undef CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP + +// binary function (vec & vec) + +#define CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(func_name, func, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 func_name(const input_type ## 1 & a, const input_type ## 1 & b) \ + { \ + return VecTraits<output_type ## 1>::make(func (a.x, b.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(const input_type ## 2 & a, const input_type ## 2 & b) \ + { \ + return VecTraits<output_type ## 2>::make(func (a.x, b.x), func (a.y, b.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(const input_type ## 3 & a, const input_type ## 3 & b) \ + { \ + return VecTraits<output_type ## 3>::make(func (a.x, b.x), func (a.y, b.y), func (a.z, b.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(const input_type ## 4 & a, const input_type ## 4 & b) \ + { \ + return VecTraits<output_type ## 4>::make(func (a.x, b.x), func (a.y, b.y), func (a.z, b.z), func (a.w, b.w)); \ + } + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::fmaxf, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::fmax, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::fminf, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::fmin, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, char, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, short, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, int, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypot, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, char, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, short, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, int, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2, double, double) + +#undef CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC + +// binary function (vec & scalar) + +#define CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(func_name, func, input_type, scalar_type, output_type) \ + __device__ __forceinline__ output_type ## 1 func_name(const input_type ## 1 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 1>::make(func ((output_type) a.x, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 1 func_name(scalar_type s, const input_type ## 1 & b) \ + { \ + return VecTraits<output_type ## 1>::make(func ((output_type) s, (output_type) b.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(const input_type ## 2 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 2>::make(func ((output_type) a.x, (output_type) s), func ((output_type) a.y, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(scalar_type s, const input_type ## 2 & b) \ + { \ + return VecTraits<output_type ## 2>::make(func ((output_type) s, (output_type) b.x), func ((output_type) s, (output_type) b.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(const input_type ## 3 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 3>::make(func ((output_type) a.x, (output_type) s), func ((output_type) a.y, (output_type) s), func ((output_type) a.z, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(scalar_type s, const input_type ## 3 & b) \ + { \ + return VecTraits<output_type ## 3>::make(func ((output_type) s, (output_type) b.x), func ((output_type) s, (output_type) b.y), func ((output_type) s, (output_type) b.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(const input_type ## 4 & a, scalar_type s) \ + { \ + return VecTraits<output_type ## 4>::make(func ((output_type) a.x, (output_type) s), func ((output_type) a.y, (output_type) s), func ((output_type) a.z, (output_type) s), func ((output_type) a.w, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(scalar_type s, const input_type ## 4 & b) \ + { \ + return VecTraits<output_type ## 4>::make(func ((output_type) s, (output_type) b.x), func ((output_type) s, (output_type) b.y), func ((output_type) s, (output_type) b.z), func ((output_type) s, (output_type) b.w)); \ + } + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, double, double, double) + +#undef CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC + +}}} // namespace cv { namespace cuda { namespace device + +//! @endcond + +#endif // OPENCV_CUDA_VECMATH_HPP diff --git a/include/opencv2/core/cuda/vec_traits.hpp b/include/opencv2/core/cuda/vec_traits.hpp new file mode 100644 index 0000000..b5ff281 --- /dev/null +++ b/include/opencv2/core/cuda/vec_traits.hpp @@ -0,0 +1,288 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_VEC_TRAITS_HPP +#define OPENCV_CUDA_VEC_TRAITS_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template<typename T, int N> struct TypeVec; + + struct __align__(8) uchar8 + { + uchar a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ uchar8 make_uchar8(uchar a0, uchar a1, uchar a2, uchar a3, uchar a4, uchar a5, uchar a6, uchar a7) + { + uchar8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(8) char8 + { + schar a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ char8 make_char8(schar a0, schar a1, schar a2, schar a3, schar a4, schar a5, schar a6, schar a7) + { + char8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(16) ushort8 + { + ushort a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ ushort8 make_ushort8(ushort a0, ushort a1, ushort a2, ushort a3, ushort a4, ushort a5, ushort a6, ushort a7) + { + ushort8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(16) short8 + { + short a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ short8 make_short8(short a0, short a1, short a2, short a3, short a4, short a5, short a6, short a7) + { + short8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(32) uint8 + { + uint a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ uint8 make_uint8(uint a0, uint a1, uint a2, uint a3, uint a4, uint a5, uint a6, uint a7) + { + uint8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(32) int8 + { + int a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ int8 make_int8(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) + { + int8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(32) float8 + { + float a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ float8 make_float8(float a0, float a1, float a2, float a3, float a4, float a5, float a6, float a7) + { + float8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct double8 + { + double a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ double8 make_double8(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7) + { + double8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + +#define OPENCV_CUDA_IMPLEMENT_TYPE_VEC(type) \ + template<> struct TypeVec<type, 1> { typedef type vec_type; }; \ + template<> struct TypeVec<type ## 1, 1> { typedef type ## 1 vec_type; }; \ + template<> struct TypeVec<type, 2> { typedef type ## 2 vec_type; }; \ + template<> struct TypeVec<type ## 2, 2> { typedef type ## 2 vec_type; }; \ + template<> struct TypeVec<type, 3> { typedef type ## 3 vec_type; }; \ + template<> struct TypeVec<type ## 3, 3> { typedef type ## 3 vec_type; }; \ + template<> struct TypeVec<type, 4> { typedef type ## 4 vec_type; }; \ + template<> struct TypeVec<type ## 4, 4> { typedef type ## 4 vec_type; }; \ + template<> struct TypeVec<type, 8> { typedef type ## 8 vec_type; }; \ + template<> struct TypeVec<type ## 8, 8> { typedef type ## 8 vec_type; }; + + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(uchar) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(char) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(ushort) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(short) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(int) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(uint) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(float) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(double) + + #undef OPENCV_CUDA_IMPLEMENT_TYPE_VEC + + template<> struct TypeVec<schar, 1> { typedef schar vec_type; }; + template<> struct TypeVec<schar, 2> { typedef char2 vec_type; }; + template<> struct TypeVec<schar, 3> { typedef char3 vec_type; }; + template<> struct TypeVec<schar, 4> { typedef char4 vec_type; }; + template<> struct TypeVec<schar, 8> { typedef char8 vec_type; }; + + template<> struct TypeVec<bool, 1> { typedef uchar vec_type; }; + template<> struct TypeVec<bool, 2> { typedef uchar2 vec_type; }; + template<> struct TypeVec<bool, 3> { typedef uchar3 vec_type; }; + template<> struct TypeVec<bool, 4> { typedef uchar4 vec_type; }; + template<> struct TypeVec<bool, 8> { typedef uchar8 vec_type; }; + + template<typename T> struct VecTraits; + +#define OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(type) \ + template<> struct VecTraits<type> \ + { \ + typedef type elem_type; \ + enum {cn=1}; \ + static __device__ __host__ __forceinline__ type all(type v) {return v;} \ + static __device__ __host__ __forceinline__ type make(type x) {return x;} \ + static __device__ __host__ __forceinline__ type make(const type* v) {return *v;} \ + }; \ + template<> struct VecTraits<type ## 1> \ + { \ + typedef type elem_type; \ + enum {cn=1}; \ + static __device__ __host__ __forceinline__ type ## 1 all(type v) {return make_ ## type ## 1(v);} \ + static __device__ __host__ __forceinline__ type ## 1 make(type x) {return make_ ## type ## 1(x);} \ + static __device__ __host__ __forceinline__ type ## 1 make(const type* v) {return make_ ## type ## 1(*v);} \ + }; \ + template<> struct VecTraits<type ## 2> \ + { \ + typedef type elem_type; \ + enum {cn=2}; \ + static __device__ __host__ __forceinline__ type ## 2 all(type v) {return make_ ## type ## 2(v, v);} \ + static __device__ __host__ __forceinline__ type ## 2 make(type x, type y) {return make_ ## type ## 2(x, y);} \ + static __device__ __host__ __forceinline__ type ## 2 make(const type* v) {return make_ ## type ## 2(v[0], v[1]);} \ + }; \ + template<> struct VecTraits<type ## 3> \ + { \ + typedef type elem_type; \ + enum {cn=3}; \ + static __device__ __host__ __forceinline__ type ## 3 all(type v) {return make_ ## type ## 3(v, v, v);} \ + static __device__ __host__ __forceinline__ type ## 3 make(type x, type y, type z) {return make_ ## type ## 3(x, y, z);} \ + static __device__ __host__ __forceinline__ type ## 3 make(const type* v) {return make_ ## type ## 3(v[0], v[1], v[2]);} \ + }; \ + template<> struct VecTraits<type ## 4> \ + { \ + typedef type elem_type; \ + enum {cn=4}; \ + static __device__ __host__ __forceinline__ type ## 4 all(type v) {return make_ ## type ## 4(v, v, v, v);} \ + static __device__ __host__ __forceinline__ type ## 4 make(type x, type y, type z, type w) {return make_ ## type ## 4(x, y, z, w);} \ + static __device__ __host__ __forceinline__ type ## 4 make(const type* v) {return make_ ## type ## 4(v[0], v[1], v[2], v[3]);} \ + }; \ + template<> struct VecTraits<type ## 8> \ + { \ + typedef type elem_type; \ + enum {cn=8}; \ + static __device__ __host__ __forceinline__ type ## 8 all(type v) {return make_ ## type ## 8(v, v, v, v, v, v, v, v);} \ + static __device__ __host__ __forceinline__ type ## 8 make(type a0, type a1, type a2, type a3, type a4, type a5, type a6, type a7) {return make_ ## type ## 8(a0, a1, a2, a3, a4, a5, a6, a7);} \ + static __device__ __host__ __forceinline__ type ## 8 make(const type* v) {return make_ ## type ## 8(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);} \ + }; + + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(uchar) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(ushort) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(short) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(int) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(uint) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(float) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(double) + + #undef OPENCV_CUDA_IMPLEMENT_VEC_TRAITS + + template<> struct VecTraits<char> + { + typedef char elem_type; + enum {cn=1}; + static __device__ __host__ __forceinline__ char all(char v) {return v;} + static __device__ __host__ __forceinline__ char make(char x) {return x;} + static __device__ __host__ __forceinline__ char make(const char* x) {return *x;} + }; + template<> struct VecTraits<schar> + { + typedef schar elem_type; + enum {cn=1}; + static __device__ __host__ __forceinline__ schar all(schar v) {return v;} + static __device__ __host__ __forceinline__ schar make(schar x) {return x;} + static __device__ __host__ __forceinline__ schar make(const schar* x) {return *x;} + }; + template<> struct VecTraits<char1> + { + typedef schar elem_type; + enum {cn=1}; + static __device__ __host__ __forceinline__ char1 all(schar v) {return make_char1(v);} + static __device__ __host__ __forceinline__ char1 make(schar x) {return make_char1(x);} + static __device__ __host__ __forceinline__ char1 make(const schar* v) {return make_char1(v[0]);} + }; + template<> struct VecTraits<char2> + { + typedef schar elem_type; + enum {cn=2}; + static __device__ __host__ __forceinline__ char2 all(schar v) {return make_char2(v, v);} + static __device__ __host__ __forceinline__ char2 make(schar x, schar y) {return make_char2(x, y);} + static __device__ __host__ __forceinline__ char2 make(const schar* v) {return make_char2(v[0], v[1]);} + }; + template<> struct VecTraits<char3> + { + typedef schar elem_type; + enum {cn=3}; + static __device__ __host__ __forceinline__ char3 all(schar v) {return make_char3(v, v, v);} + static __device__ __host__ __forceinline__ char3 make(schar x, schar y, schar z) {return make_char3(x, y, z);} + static __device__ __host__ __forceinline__ char3 make(const schar* v) {return make_char3(v[0], v[1], v[2]);} + }; + template<> struct VecTraits<char4> + { + typedef schar elem_type; + enum {cn=4}; + static __device__ __host__ __forceinline__ char4 all(schar v) {return make_char4(v, v, v, v);} + static __device__ __host__ __forceinline__ char4 make(schar x, schar y, schar z, schar w) {return make_char4(x, y, z, w);} + static __device__ __host__ __forceinline__ char4 make(const schar* v) {return make_char4(v[0], v[1], v[2], v[3]);} + }; + template<> struct VecTraits<char8> + { + typedef schar elem_type; + enum {cn=8}; + static __device__ __host__ __forceinline__ char8 all(schar v) {return make_char8(v, v, v, v, v, v, v, v);} + static __device__ __host__ __forceinline__ char8 make(schar a0, schar a1, schar a2, schar a3, schar a4, schar a5, schar a6, schar a7) {return make_char8(a0, a1, a2, a3, a4, a5, a6, a7);} + static __device__ __host__ __forceinline__ char8 make(const schar* v) {return make_char8(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);} + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_VEC_TRAITS_HPP diff --git a/include/opencv2/core/cuda/warp.hpp b/include/opencv2/core/cuda/warp.hpp new file mode 100644 index 0000000..8af7e6a --- /dev/null +++ b/include/opencv2/core/cuda/warp.hpp @@ -0,0 +1,139 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_DEVICE_WARP_HPP +#define OPENCV_CUDA_DEVICE_WARP_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct Warp + { + enum + { + LOG_WARP_SIZE = 5, + WARP_SIZE = 1 << LOG_WARP_SIZE, + STRIDE = WARP_SIZE + }; + + /** \brief Returns the warp lane ID of the calling thread. */ + static __device__ __forceinline__ unsigned int laneId() + { + unsigned int ret; + asm("mov.u32 %0, %%laneid;" : "=r"(ret) ); + return ret; + } + + template<typename It, typename T> + static __device__ __forceinline__ void fill(It beg, It end, const T& value) + { + for(It t = beg + laneId(); t < end; t += STRIDE) + *t = value; + } + + template<typename InIt, typename OutIt> + static __device__ __forceinline__ OutIt copy(InIt beg, InIt end, OutIt out) + { + for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE) + *out = *t; + return out; + } + + template<typename InIt, typename OutIt, class UnOp> + static __device__ __forceinline__ OutIt transform(InIt beg, InIt end, OutIt out, UnOp op) + { + for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE) + *out = op(*t); + return out; + } + + template<typename InIt1, typename InIt2, typename OutIt, class BinOp> + static __device__ __forceinline__ OutIt transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op) + { + unsigned int lane = laneId(); + + InIt1 t1 = beg1 + lane; + InIt2 t2 = beg2 + lane; + for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, out += STRIDE) + *out = op(*t1, *t2); + return out; + } + + template <class T, class BinOp> + static __device__ __forceinline__ T reduce(volatile T *ptr, BinOp op) + { + const unsigned int lane = laneId(); + + if (lane < 16) + { + T partial = ptr[lane]; + + ptr[lane] = partial = op(partial, ptr[lane + 16]); + ptr[lane] = partial = op(partial, ptr[lane + 8]); + ptr[lane] = partial = op(partial, ptr[lane + 4]); + ptr[lane] = partial = op(partial, ptr[lane + 2]); + ptr[lane] = partial = op(partial, ptr[lane + 1]); + } + + return *ptr; + } + + template<typename OutIt, typename T> + static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value) + { + unsigned int lane = laneId(); + value += lane; + + for(OutIt t = beg + lane; t < end; t += STRIDE, value += STRIDE) + *t = value; + } + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif /* OPENCV_CUDA_DEVICE_WARP_HPP */ diff --git a/include/opencv2/core/cuda/warp_reduce.hpp b/include/opencv2/core/cuda/warp_reduce.hpp new file mode 100644 index 0000000..530303d --- /dev/null +++ b/include/opencv2/core/cuda/warp_reduce.hpp @@ -0,0 +1,76 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_WARP_REDUCE_HPP__ +#define OPENCV_CUDA_WARP_REDUCE_HPP__ + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template <class T> + __device__ __forceinline__ T warp_reduce(volatile T *ptr , const unsigned int tid = threadIdx.x) + { + const unsigned int lane = tid & 31; // index of thread in warp (0..31) + + if (lane < 16) + { + T partial = ptr[tid]; + + ptr[tid] = partial = partial + ptr[tid + 16]; + ptr[tid] = partial = partial + ptr[tid + 8]; + ptr[tid] = partial = partial + ptr[tid + 4]; + ptr[tid] = partial = partial + ptr[tid + 2]; + ptr[tid] = partial = partial + ptr[tid + 1]; + } + + return ptr[tid - lane]; + } +}}} // namespace cv { namespace cuda { namespace cudev { + +//! @endcond + +#endif /* OPENCV_CUDA_WARP_REDUCE_HPP__ */ diff --git a/include/opencv2/core/cuda/warp_shuffle.hpp b/include/opencv2/core/cuda/warp_shuffle.hpp new file mode 100644 index 0000000..0da54ae --- /dev/null +++ b/include/opencv2/core/cuda/warp_shuffle.hpp @@ -0,0 +1,162 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CUDA_WARP_SHUFFLE_HPP +#define OPENCV_CUDA_WARP_SHUFFLE_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ +#if __CUDACC_VER_MAJOR__ >= 9 +# define __shfl(x, y, z) __shfl_sync(0xFFFFFFFFU, x, y, z) +# define __shfl_up(x, y, z) __shfl_up_sync(0xFFFFFFFFU, x, y, z) +# define __shfl_down(x, y, z) __shfl_down_sync(0xFFFFFFFFU, x, y, z) +#endif + template <typename T> + __device__ __forceinline__ T shfl(T val, int srcLane, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return __shfl(val, srcLane, width); + #else + return T(); + #endif + } + __device__ __forceinline__ unsigned int shfl(unsigned int val, int srcLane, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return (unsigned int) __shfl((int) val, srcLane, width); + #else + return 0; + #endif + } + __device__ __forceinline__ double shfl(double val, int srcLane, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + int lo = __double2loint(val); + int hi = __double2hiint(val); + + lo = __shfl(lo, srcLane, width); + hi = __shfl(hi, srcLane, width); + + return __hiloint2double(hi, lo); + #else + return 0.0; + #endif + } + + template <typename T> + __device__ __forceinline__ T shfl_down(T val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return __shfl_down(val, delta, width); + #else + return T(); + #endif + } + __device__ __forceinline__ unsigned int shfl_down(unsigned int val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return (unsigned int) __shfl_down((int) val, delta, width); + #else + return 0; + #endif + } + __device__ __forceinline__ double shfl_down(double val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + int lo = __double2loint(val); + int hi = __double2hiint(val); + + lo = __shfl_down(lo, delta, width); + hi = __shfl_down(hi, delta, width); + + return __hiloint2double(hi, lo); + #else + return 0.0; + #endif + } + + template <typename T> + __device__ __forceinline__ T shfl_up(T val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return __shfl_up(val, delta, width); + #else + return T(); + #endif + } + __device__ __forceinline__ unsigned int shfl_up(unsigned int val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return (unsigned int) __shfl_up((int) val, delta, width); + #else + return 0; + #endif + } + __device__ __forceinline__ double shfl_up(double val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + int lo = __double2loint(val); + int hi = __double2hiint(val); + + lo = __shfl_up(lo, delta, width); + hi = __shfl_up(hi, delta, width); + + return __hiloint2double(hi, lo); + #else + return 0.0; + #endif + } +}}} + +# undef __shfl +# undef __shfl_up +# undef __shfl_down + +//! @endcond + +#endif // OPENCV_CUDA_WARP_SHUFFLE_HPP diff --git a/include/opencv2/core/cuda_stream_accessor.hpp b/include/opencv2/core/cuda_stream_accessor.hpp new file mode 100644 index 0000000..deaf356 --- /dev/null +++ b/include/opencv2/core/cuda_stream_accessor.hpp @@ -0,0 +1,86 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP +#define OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP + +#ifndef __cplusplus +# error cuda_stream_accessor.hpp header must be compiled as C++ +#endif + +/** @file cuda_stream_accessor.hpp + * This is only header file that depends on CUDA Runtime API. All other headers are independent. + */ + +#include <cuda_runtime.h> +#include "opencv2/core/cuda.hpp" + +namespace cv +{ + namespace cuda + { + +//! @addtogroup cudacore_struct +//! @{ + + /** @brief Class that enables getting cudaStream_t from cuda::Stream + */ + struct StreamAccessor + { + CV_EXPORTS static cudaStream_t getStream(const Stream& stream); + CV_EXPORTS static Stream wrapStream(cudaStream_t stream); + }; + + /** @brief Class that enables getting cudaEvent_t from cuda::Event + */ + struct EventAccessor + { + CV_EXPORTS static cudaEvent_t getEvent(const Event& event); + CV_EXPORTS static Event wrapEvent(cudaEvent_t event); + }; + +//! @} + + } +} + +#endif /* OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP */ diff --git a/include/opencv2/core/cuda_types.hpp b/include/opencv2/core/cuda_types.hpp new file mode 100644 index 0000000..45dc2ca --- /dev/null +++ b/include/opencv2/core/cuda_types.hpp @@ -0,0 +1,144 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CUDA_TYPES_HPP +#define OPENCV_CORE_CUDA_TYPES_HPP + +#ifndef __cplusplus +# error cuda_types.hpp header must be compiled as C++ +#endif + +#if defined(__OPENCV_BUILD) && defined(__clang__) +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif +#if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5 +#pragma GCC diagnostic ignored "-Wsuggest-override" +#endif + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +#ifdef __CUDACC__ + #define __CV_CUDA_HOST_DEVICE__ __host__ __device__ __forceinline__ +#else + #define __CV_CUDA_HOST_DEVICE__ +#endif + +namespace cv +{ + namespace cuda + { + + // Simple lightweight structures that encapsulates information about an image on device. + // It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile + + template <typename T> struct DevPtr + { + typedef T elem_type; + typedef int index_type; + + enum { elem_size = sizeof(elem_type) }; + + T* data; + + __CV_CUDA_HOST_DEVICE__ DevPtr() : data(0) {} + __CV_CUDA_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {} + + __CV_CUDA_HOST_DEVICE__ size_t elemSize() const { return elem_size; } + __CV_CUDA_HOST_DEVICE__ operator T*() { return data; } + __CV_CUDA_HOST_DEVICE__ operator const T*() const { return data; } + }; + + template <typename T> struct PtrSz : public DevPtr<T> + { + __CV_CUDA_HOST_DEVICE__ PtrSz() : size(0) {} + __CV_CUDA_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr<T>(data_), size(size_) {} + + size_t size; + }; + + template <typename T> struct PtrStep : public DevPtr<T> + { + __CV_CUDA_HOST_DEVICE__ PtrStep() : step(0) {} + __CV_CUDA_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {} + + size_t step; + + __CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); } + __CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); } + + __CV_CUDA_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } + __CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } + }; + + template <typename T> struct PtrStepSz : public PtrStep<T> + { + __CV_CUDA_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {} + __CV_CUDA_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_) + : PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {} + + template <typename U> + explicit PtrStepSz(const PtrStepSz<U>& d) : PtrStep<T>((T*)d.data, d.step), cols(d.cols), rows(d.rows){} + + int cols; + int rows; + }; + + typedef PtrStepSz<unsigned char> PtrStepSzb; + typedef PtrStepSz<unsigned short> PtrStepSzus; + typedef PtrStepSz<float> PtrStepSzf; + typedef PtrStepSz<int> PtrStepSzi; + + typedef PtrStep<unsigned char> PtrStepb; + typedef PtrStep<unsigned short> PtrStepus; + typedef PtrStep<float> PtrStepf; + typedef PtrStep<int> PtrStepi; + + } +} + +//! @endcond + +#endif /* OPENCV_CORE_CUDA_TYPES_HPP */ diff --git a/include/opencv2/core/cv_cpu_dispatch.h b/include/opencv2/core/cv_cpu_dispatch.h new file mode 100644 index 0000000..7f6d6b0 --- /dev/null +++ b/include/opencv2/core/cv_cpu_dispatch.h @@ -0,0 +1,252 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#if defined __OPENCV_BUILD \ + +#include "cv_cpu_config.h" +#include "cv_cpu_helper.h" + +#ifdef CV_CPU_DISPATCH_MODE +#define CV_CPU_OPTIMIZATION_NAMESPACE __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) +#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) { +#define CV_CPU_OPTIMIZATION_NAMESPACE_END } +#else +#define CV_CPU_OPTIMIZATION_NAMESPACE cpu_baseline +#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace cpu_baseline { +#define CV_CPU_OPTIMIZATION_NAMESPACE_END } +#define CV_CPU_BASELINE_MODE 1 +#endif + + +#define __CV_CPU_DISPATCH_CHAIN_END(fn, args, mode, ...) /* done */ +#define __CV_CPU_DISPATCH(fn, args, mode, ...) __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) +#define __CV_CPU_DISPATCH_EXPAND(fn, args, ...) __CV_EXPAND(__CV_CPU_DISPATCH(fn, args, __VA_ARGS__)) +#define CV_CPU_DISPATCH(fn, args, ...) __CV_CPU_DISPATCH_EXPAND(fn, args, __VA_ARGS__, END) // expand macros + + +#if defined CV_ENABLE_INTRINSICS \ + && !defined CV_DISABLE_OPTIMIZATION \ + && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ \ + +#ifdef CV_CPU_COMPILE_SSE2 +# include <emmintrin.h> +# define CV_MMX 1 +# define CV_SSE 1 +# define CV_SSE2 1 +#endif +#ifdef CV_CPU_COMPILE_SSE3 +# include <pmmintrin.h> +# define CV_SSE3 1 +#endif +#ifdef CV_CPU_COMPILE_SSSE3 +# include <tmmintrin.h> +# define CV_SSSE3 1 +#endif +#ifdef CV_CPU_COMPILE_SSE4_1 +# include <smmintrin.h> +# define CV_SSE4_1 1 +#endif +#ifdef CV_CPU_COMPILE_SSE4_2 +# include <nmmintrin.h> +# define CV_SSE4_2 1 +#endif +#ifdef CV_CPU_COMPILE_POPCNT +# ifdef _MSC_VER +# include <nmmintrin.h> +# if defined(_M_X64) +# define CV_POPCNT_U64 _mm_popcnt_u64 +# endif +# define CV_POPCNT_U32 _mm_popcnt_u32 +# else +# include <popcntintrin.h> +# if defined(__x86_64__) +# define CV_POPCNT_U64 __builtin_popcountll +# endif +# define CV_POPCNT_U32 __builtin_popcount +# endif +# define CV_POPCNT 1 +#endif +#ifdef CV_CPU_COMPILE_AVX +# include <immintrin.h> +# define CV_AVX 1 +#endif +#ifdef CV_CPU_COMPILE_FP16 +# if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) +# include <arm_neon.h> +# else +# include <immintrin.h> +# endif +# define CV_FP16 1 +#endif +#ifdef CV_CPU_COMPILE_AVX2 +# include <immintrin.h> +# define CV_AVX2 1 +#endif +#ifdef CV_CPU_COMPILE_AVX_512F +# include <immintrin.h> +# define CV_AVX_512F 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_SKX +# include <immintrin.h> +# define CV_AVX512_SKX 1 +#endif +#ifdef CV_CPU_COMPILE_FMA3 +# define CV_FMA3 1 +#endif + +#if defined _WIN32 && defined(_M_ARM) +# include <Intrin.h> +# include <arm_neon.h> +# define CV_NEON 1 +#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) +# include <arm_neon.h> +# define CV_NEON 1 +#endif + +#if defined(__ARM_NEON__) || defined(__aarch64__) +# include <arm_neon.h> +#endif + +#ifdef CV_CPU_COMPILE_VSX +# include <altivec.h> +# undef vector +# undef pixel +# undef bool +# define CV_VSX 1 +#endif + +#ifdef CV_CPU_COMPILE_VSX3 +# define CV_VSX3 1 +#endif + +#endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__ + +#if defined CV_CPU_COMPILE_AVX && !defined CV_CPU_BASELINE_COMPILE_AVX +struct VZeroUpperGuard { +#ifdef __GNUC__ + __attribute__((always_inline)) +#endif + inline VZeroUpperGuard() { _mm256_zeroupper(); } +#ifdef __GNUC__ + __attribute__((always_inline)) +#endif + inline ~VZeroUpperGuard() { _mm256_zeroupper(); } +}; +#define __CV_AVX_GUARD VZeroUpperGuard __vzeroupper_guard; CV_UNUSED(__vzeroupper_guard); +#endif + +#ifdef __CV_AVX_GUARD +#define CV_AVX_GUARD __CV_AVX_GUARD +#else +#define CV_AVX_GUARD +#endif + +#endif // __OPENCV_BUILD + + + +#if !defined __OPENCV_BUILD /* Compatibility code */ \ + && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ +#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) +# include <emmintrin.h> +# define CV_MMX 1 +# define CV_SSE 1 +# define CV_SSE2 1 +#elif defined _WIN32 && defined(_M_ARM) +# include <Intrin.h> +# include <arm_neon.h> +# define CV_NEON 1 +#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) +# include <arm_neon.h> +# define CV_NEON 1 +#elif defined(__VSX__) && defined(__PPC64__) && defined(__LITTLE_ENDIAN__) +# include <altivec.h> +# undef vector +# undef pixel +# undef bool +# define CV_VSX 1 +#endif + +#endif // !__OPENCV_BUILD && !__CUDACC (Compatibility code) + + + +#ifndef CV_MMX +# define CV_MMX 0 +#endif +#ifndef CV_SSE +# define CV_SSE 0 +#endif +#ifndef CV_SSE2 +# define CV_SSE2 0 +#endif +#ifndef CV_SSE3 +# define CV_SSE3 0 +#endif +#ifndef CV_SSSE3 +# define CV_SSSE3 0 +#endif +#ifndef CV_SSE4_1 +# define CV_SSE4_1 0 +#endif +#ifndef CV_SSE4_2 +# define CV_SSE4_2 0 +#endif +#ifndef CV_POPCNT +# define CV_POPCNT 0 +#endif +#ifndef CV_AVX +# define CV_AVX 0 +#endif +#ifndef CV_FP16 +# define CV_FP16 0 +#endif +#ifndef CV_AVX2 +# define CV_AVX2 0 +#endif +#ifndef CV_FMA3 +# define CV_FMA3 0 +#endif +#ifndef CV_AVX_512F +# define CV_AVX_512F 0 +#endif +#ifndef CV_AVX_512BW +# define CV_AVX_512BW 0 +#endif +#ifndef CV_AVX_512CD +# define CV_AVX_512CD 0 +#endif +#ifndef CV_AVX_512DQ +# define CV_AVX_512DQ 0 +#endif +#ifndef CV_AVX_512ER +# define CV_AVX_512ER 0 +#endif +#ifndef CV_AVX_512IFMA512 +# define CV_AVX_512IFMA512 0 +#endif +#ifndef CV_AVX_512PF +# define CV_AVX_512PF 0 +#endif +#ifndef CV_AVX_512VBMI +# define CV_AVX_512VBMI 0 +#endif +#ifndef CV_AVX_512VL +# define CV_AVX_512VL 0 +#endif +#ifndef CV_AVX512_SKX +# define CV_AVX512_SKX 0 +#endif + +#ifndef CV_NEON +# define CV_NEON 0 +#endif + +#ifndef CV_VSX +# define CV_VSX 0 +#endif + +#ifndef CV_VSX3 +# define CV_VSX3 0 +#endif diff --git a/include/opencv2/core/cv_cpu_helper.h b/include/opencv2/core/cv_cpu_helper.h new file mode 100644 index 0000000..ad13397 --- /dev/null +++ b/include/opencv2/core/cv_cpu_helper.h @@ -0,0 +1,340 @@ +// AUTOGENERATED, DO NOT EDIT + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE +# define CV_TRY_SSE 1 +# define CV_CPU_FORCE_SSE 1 +# define CV_CPU_HAS_SUPPORT_SSE 1 +# define CV_CPU_CALL_SSE(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE_(fn, args) return (opt_SSE::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE +# define CV_TRY_SSE 1 +# define CV_CPU_FORCE_SSE 0 +# define CV_CPU_HAS_SUPPORT_SSE (cv::checkHardwareSupport(CV_CPU_SSE)) +# define CV_CPU_CALL_SSE(fn, args) if (CV_CPU_HAS_SUPPORT_SSE) return (opt_SSE::fn args) +# define CV_CPU_CALL_SSE_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE) return (opt_SSE::fn args) +#else +# define CV_TRY_SSE 0 +# define CV_CPU_FORCE_SSE 0 +# define CV_CPU_HAS_SUPPORT_SSE 0 +# define CV_CPU_CALL_SSE(fn, args) +# define CV_CPU_CALL_SSE_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE(fn, args, mode, ...) CV_CPU_CALL_SSE(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE2 +# define CV_TRY_SSE2 1 +# define CV_CPU_FORCE_SSE2 1 +# define CV_CPU_HAS_SUPPORT_SSE2 1 +# define CV_CPU_CALL_SSE2(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE2_(fn, args) return (opt_SSE2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE2 +# define CV_TRY_SSE2 1 +# define CV_CPU_FORCE_SSE2 0 +# define CV_CPU_HAS_SUPPORT_SSE2 (cv::checkHardwareSupport(CV_CPU_SSE2)) +# define CV_CPU_CALL_SSE2(fn, args) if (CV_CPU_HAS_SUPPORT_SSE2) return (opt_SSE2::fn args) +# define CV_CPU_CALL_SSE2_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE2) return (opt_SSE2::fn args) +#else +# define CV_TRY_SSE2 0 +# define CV_CPU_FORCE_SSE2 0 +# define CV_CPU_HAS_SUPPORT_SSE2 0 +# define CV_CPU_CALL_SSE2(fn, args) +# define CV_CPU_CALL_SSE2_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE2(fn, args, mode, ...) CV_CPU_CALL_SSE2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE3 +# define CV_TRY_SSE3 1 +# define CV_CPU_FORCE_SSE3 1 +# define CV_CPU_HAS_SUPPORT_SSE3 1 +# define CV_CPU_CALL_SSE3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE3_(fn, args) return (opt_SSE3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE3 +# define CV_TRY_SSE3 1 +# define CV_CPU_FORCE_SSE3 0 +# define CV_CPU_HAS_SUPPORT_SSE3 (cv::checkHardwareSupport(CV_CPU_SSE3)) +# define CV_CPU_CALL_SSE3(fn, args) if (CV_CPU_HAS_SUPPORT_SSE3) return (opt_SSE3::fn args) +# define CV_CPU_CALL_SSE3_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE3) return (opt_SSE3::fn args) +#else +# define CV_TRY_SSE3 0 +# define CV_CPU_FORCE_SSE3 0 +# define CV_CPU_HAS_SUPPORT_SSE3 0 +# define CV_CPU_CALL_SSE3(fn, args) +# define CV_CPU_CALL_SSE3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE3(fn, args, mode, ...) CV_CPU_CALL_SSE3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSSE3 +# define CV_TRY_SSSE3 1 +# define CV_CPU_FORCE_SSSE3 1 +# define CV_CPU_HAS_SUPPORT_SSSE3 1 +# define CV_CPU_CALL_SSSE3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSSE3_(fn, args) return (opt_SSSE3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSSE3 +# define CV_TRY_SSSE3 1 +# define CV_CPU_FORCE_SSSE3 0 +# define CV_CPU_HAS_SUPPORT_SSSE3 (cv::checkHardwareSupport(CV_CPU_SSSE3)) +# define CV_CPU_CALL_SSSE3(fn, args) if (CV_CPU_HAS_SUPPORT_SSSE3) return (opt_SSSE3::fn args) +# define CV_CPU_CALL_SSSE3_(fn, args) if (CV_CPU_HAS_SUPPORT_SSSE3) return (opt_SSSE3::fn args) +#else +# define CV_TRY_SSSE3 0 +# define CV_CPU_FORCE_SSSE3 0 +# define CV_CPU_HAS_SUPPORT_SSSE3 0 +# define CV_CPU_CALL_SSSE3(fn, args) +# define CV_CPU_CALL_SSSE3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSSE3(fn, args, mode, ...) CV_CPU_CALL_SSSE3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE4_1 +# define CV_TRY_SSE4_1 1 +# define CV_CPU_FORCE_SSE4_1 1 +# define CV_CPU_HAS_SUPPORT_SSE4_1 1 +# define CV_CPU_CALL_SSE4_1(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE4_1_(fn, args) return (opt_SSE4_1::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE4_1 +# define CV_TRY_SSE4_1 1 +# define CV_CPU_FORCE_SSE4_1 0 +# define CV_CPU_HAS_SUPPORT_SSE4_1 (cv::checkHardwareSupport(CV_CPU_SSE4_1)) +# define CV_CPU_CALL_SSE4_1(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_1) return (opt_SSE4_1::fn args) +# define CV_CPU_CALL_SSE4_1_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_1) return (opt_SSE4_1::fn args) +#else +# define CV_TRY_SSE4_1 0 +# define CV_CPU_FORCE_SSE4_1 0 +# define CV_CPU_HAS_SUPPORT_SSE4_1 0 +# define CV_CPU_CALL_SSE4_1(fn, args) +# define CV_CPU_CALL_SSE4_1_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE4_1(fn, args, mode, ...) CV_CPU_CALL_SSE4_1(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE4_2 +# define CV_TRY_SSE4_2 1 +# define CV_CPU_FORCE_SSE4_2 1 +# define CV_CPU_HAS_SUPPORT_SSE4_2 1 +# define CV_CPU_CALL_SSE4_2(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE4_2_(fn, args) return (opt_SSE4_2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE4_2 +# define CV_TRY_SSE4_2 1 +# define CV_CPU_FORCE_SSE4_2 0 +# define CV_CPU_HAS_SUPPORT_SSE4_2 (cv::checkHardwareSupport(CV_CPU_SSE4_2)) +# define CV_CPU_CALL_SSE4_2(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_2) return (opt_SSE4_2::fn args) +# define CV_CPU_CALL_SSE4_2_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_2) return (opt_SSE4_2::fn args) +#else +# define CV_TRY_SSE4_2 0 +# define CV_CPU_FORCE_SSE4_2 0 +# define CV_CPU_HAS_SUPPORT_SSE4_2 0 +# define CV_CPU_CALL_SSE4_2(fn, args) +# define CV_CPU_CALL_SSE4_2_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE4_2(fn, args, mode, ...) CV_CPU_CALL_SSE4_2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_POPCNT +# define CV_TRY_POPCNT 1 +# define CV_CPU_FORCE_POPCNT 1 +# define CV_CPU_HAS_SUPPORT_POPCNT 1 +# define CV_CPU_CALL_POPCNT(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_POPCNT_(fn, args) return (opt_POPCNT::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_POPCNT +# define CV_TRY_POPCNT 1 +# define CV_CPU_FORCE_POPCNT 0 +# define CV_CPU_HAS_SUPPORT_POPCNT (cv::checkHardwareSupport(CV_CPU_POPCNT)) +# define CV_CPU_CALL_POPCNT(fn, args) if (CV_CPU_HAS_SUPPORT_POPCNT) return (opt_POPCNT::fn args) +# define CV_CPU_CALL_POPCNT_(fn, args) if (CV_CPU_HAS_SUPPORT_POPCNT) return (opt_POPCNT::fn args) +#else +# define CV_TRY_POPCNT 0 +# define CV_CPU_FORCE_POPCNT 0 +# define CV_CPU_HAS_SUPPORT_POPCNT 0 +# define CV_CPU_CALL_POPCNT(fn, args) +# define CV_CPU_CALL_POPCNT_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_POPCNT(fn, args, mode, ...) CV_CPU_CALL_POPCNT(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX +# define CV_TRY_AVX 1 +# define CV_CPU_FORCE_AVX 1 +# define CV_CPU_HAS_SUPPORT_AVX 1 +# define CV_CPU_CALL_AVX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX_(fn, args) return (opt_AVX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX +# define CV_TRY_AVX 1 +# define CV_CPU_FORCE_AVX 0 +# define CV_CPU_HAS_SUPPORT_AVX (cv::checkHardwareSupport(CV_CPU_AVX)) +# define CV_CPU_CALL_AVX(fn, args) if (CV_CPU_HAS_SUPPORT_AVX) return (opt_AVX::fn args) +# define CV_CPU_CALL_AVX_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX) return (opt_AVX::fn args) +#else +# define CV_TRY_AVX 0 +# define CV_CPU_FORCE_AVX 0 +# define CV_CPU_HAS_SUPPORT_AVX 0 +# define CV_CPU_CALL_AVX(fn, args) +# define CV_CPU_CALL_AVX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX(fn, args, mode, ...) CV_CPU_CALL_AVX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_FP16 +# define CV_TRY_FP16 1 +# define CV_CPU_FORCE_FP16 1 +# define CV_CPU_HAS_SUPPORT_FP16 1 +# define CV_CPU_CALL_FP16(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_FP16_(fn, args) return (opt_FP16::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_FP16 +# define CV_TRY_FP16 1 +# define CV_CPU_FORCE_FP16 0 +# define CV_CPU_HAS_SUPPORT_FP16 (cv::checkHardwareSupport(CV_CPU_FP16)) +# define CV_CPU_CALL_FP16(fn, args) if (CV_CPU_HAS_SUPPORT_FP16) return (opt_FP16::fn args) +# define CV_CPU_CALL_FP16_(fn, args) if (CV_CPU_HAS_SUPPORT_FP16) return (opt_FP16::fn args) +#else +# define CV_TRY_FP16 0 +# define CV_CPU_FORCE_FP16 0 +# define CV_CPU_HAS_SUPPORT_FP16 0 +# define CV_CPU_CALL_FP16(fn, args) +# define CV_CPU_CALL_FP16_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_FP16(fn, args, mode, ...) CV_CPU_CALL_FP16(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX2 +# define CV_TRY_AVX2 1 +# define CV_CPU_FORCE_AVX2 1 +# define CV_CPU_HAS_SUPPORT_AVX2 1 +# define CV_CPU_CALL_AVX2(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX2_(fn, args) return (opt_AVX2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX2 +# define CV_TRY_AVX2 1 +# define CV_CPU_FORCE_AVX2 0 +# define CV_CPU_HAS_SUPPORT_AVX2 (cv::checkHardwareSupport(CV_CPU_AVX2)) +# define CV_CPU_CALL_AVX2(fn, args) if (CV_CPU_HAS_SUPPORT_AVX2) return (opt_AVX2::fn args) +# define CV_CPU_CALL_AVX2_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX2) return (opt_AVX2::fn args) +#else +# define CV_TRY_AVX2 0 +# define CV_CPU_FORCE_AVX2 0 +# define CV_CPU_HAS_SUPPORT_AVX2 0 +# define CV_CPU_CALL_AVX2(fn, args) +# define CV_CPU_CALL_AVX2_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX2(fn, args, mode, ...) CV_CPU_CALL_AVX2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_FMA3 +# define CV_TRY_FMA3 1 +# define CV_CPU_FORCE_FMA3 1 +# define CV_CPU_HAS_SUPPORT_FMA3 1 +# define CV_CPU_CALL_FMA3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_FMA3_(fn, args) return (opt_FMA3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_FMA3 +# define CV_TRY_FMA3 1 +# define CV_CPU_FORCE_FMA3 0 +# define CV_CPU_HAS_SUPPORT_FMA3 (cv::checkHardwareSupport(CV_CPU_FMA3)) +# define CV_CPU_CALL_FMA3(fn, args) if (CV_CPU_HAS_SUPPORT_FMA3) return (opt_FMA3::fn args) +# define CV_CPU_CALL_FMA3_(fn, args) if (CV_CPU_HAS_SUPPORT_FMA3) return (opt_FMA3::fn args) +#else +# define CV_TRY_FMA3 0 +# define CV_CPU_FORCE_FMA3 0 +# define CV_CPU_HAS_SUPPORT_FMA3 0 +# define CV_CPU_CALL_FMA3(fn, args) +# define CV_CPU_CALL_FMA3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_FMA3(fn, args, mode, ...) CV_CPU_CALL_FMA3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX_512F +# define CV_TRY_AVX_512F 1 +# define CV_CPU_FORCE_AVX_512F 1 +# define CV_CPU_HAS_SUPPORT_AVX_512F 1 +# define CV_CPU_CALL_AVX_512F(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX_512F_(fn, args) return (opt_AVX_512F::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX_512F +# define CV_TRY_AVX_512F 1 +# define CV_CPU_FORCE_AVX_512F 0 +# define CV_CPU_HAS_SUPPORT_AVX_512F (cv::checkHardwareSupport(CV_CPU_AVX_512F)) +# define CV_CPU_CALL_AVX_512F(fn, args) if (CV_CPU_HAS_SUPPORT_AVX_512F) return (opt_AVX_512F::fn args) +# define CV_CPU_CALL_AVX_512F_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX_512F) return (opt_AVX_512F::fn args) +#else +# define CV_TRY_AVX_512F 0 +# define CV_CPU_FORCE_AVX_512F 0 +# define CV_CPU_HAS_SUPPORT_AVX_512F 0 +# define CV_CPU_CALL_AVX_512F(fn, args) +# define CV_CPU_CALL_AVX_512F_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX_512F(fn, args, mode, ...) CV_CPU_CALL_AVX_512F(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_SKX +# define CV_TRY_AVX512_SKX 1 +# define CV_CPU_FORCE_AVX512_SKX 1 +# define CV_CPU_HAS_SUPPORT_AVX512_SKX 1 +# define CV_CPU_CALL_AVX512_SKX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_SKX_(fn, args) return (opt_AVX512_SKX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_SKX +# define CV_TRY_AVX512_SKX 1 +# define CV_CPU_FORCE_AVX512_SKX 0 +# define CV_CPU_HAS_SUPPORT_AVX512_SKX (cv::checkHardwareSupport(CV_CPU_AVX512_SKX)) +# define CV_CPU_CALL_AVX512_SKX(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_SKX) return (opt_AVX512_SKX::fn args) +# define CV_CPU_CALL_AVX512_SKX_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_SKX) return (opt_AVX512_SKX::fn args) +#else +# define CV_TRY_AVX512_SKX 0 +# define CV_CPU_FORCE_AVX512_SKX 0 +# define CV_CPU_HAS_SUPPORT_AVX512_SKX 0 +# define CV_CPU_CALL_AVX512_SKX(fn, args) +# define CV_CPU_CALL_AVX512_SKX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_SKX(fn, args, mode, ...) CV_CPU_CALL_AVX512_SKX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_NEON +# define CV_TRY_NEON 1 +# define CV_CPU_FORCE_NEON 1 +# define CV_CPU_HAS_SUPPORT_NEON 1 +# define CV_CPU_CALL_NEON(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_NEON_(fn, args) return (opt_NEON::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_NEON +# define CV_TRY_NEON 1 +# define CV_CPU_FORCE_NEON 0 +# define CV_CPU_HAS_SUPPORT_NEON (cv::checkHardwareSupport(CV_CPU_NEON)) +# define CV_CPU_CALL_NEON(fn, args) if (CV_CPU_HAS_SUPPORT_NEON) return (opt_NEON::fn args) +# define CV_CPU_CALL_NEON_(fn, args) if (CV_CPU_HAS_SUPPORT_NEON) return (opt_NEON::fn args) +#else +# define CV_TRY_NEON 0 +# define CV_CPU_FORCE_NEON 0 +# define CV_CPU_HAS_SUPPORT_NEON 0 +# define CV_CPU_CALL_NEON(fn, args) +# define CV_CPU_CALL_NEON_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_NEON(fn, args, mode, ...) CV_CPU_CALL_NEON(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_VSX +# define CV_TRY_VSX 1 +# define CV_CPU_FORCE_VSX 1 +# define CV_CPU_HAS_SUPPORT_VSX 1 +# define CV_CPU_CALL_VSX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_VSX_(fn, args) return (opt_VSX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_VSX +# define CV_TRY_VSX 1 +# define CV_CPU_FORCE_VSX 0 +# define CV_CPU_HAS_SUPPORT_VSX (cv::checkHardwareSupport(CV_CPU_VSX)) +# define CV_CPU_CALL_VSX(fn, args) if (CV_CPU_HAS_SUPPORT_VSX) return (opt_VSX::fn args) +# define CV_CPU_CALL_VSX_(fn, args) if (CV_CPU_HAS_SUPPORT_VSX) return (opt_VSX::fn args) +#else +# define CV_TRY_VSX 0 +# define CV_CPU_FORCE_VSX 0 +# define CV_CPU_HAS_SUPPORT_VSX 0 +# define CV_CPU_CALL_VSX(fn, args) +# define CV_CPU_CALL_VSX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_VSX(fn, args, mode, ...) CV_CPU_CALL_VSX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_VSX3 +# define CV_TRY_VSX3 1 +# define CV_CPU_FORCE_VSX3 1 +# define CV_CPU_HAS_SUPPORT_VSX3 1 +# define CV_CPU_CALL_VSX3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_VSX3_(fn, args) return (opt_VSX3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_VSX3 +# define CV_TRY_VSX3 1 +# define CV_CPU_FORCE_VSX3 0 +# define CV_CPU_HAS_SUPPORT_VSX3 (cv::checkHardwareSupport(CV_CPU_VSX3)) +# define CV_CPU_CALL_VSX3(fn, args) if (CV_CPU_HAS_SUPPORT_VSX3) return (opt_VSX3::fn args) +# define CV_CPU_CALL_VSX3_(fn, args) if (CV_CPU_HAS_SUPPORT_VSX3) return (opt_VSX3::fn args) +#else +# define CV_TRY_VSX3 0 +# define CV_CPU_FORCE_VSX3 0 +# define CV_CPU_HAS_SUPPORT_VSX3 0 +# define CV_CPU_CALL_VSX3(fn, args) +# define CV_CPU_CALL_VSX3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_VSX3(fn, args, mode, ...) CV_CPU_CALL_VSX3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#define CV_CPU_CALL_BASELINE(fn, args) return (cpu_baseline::fn args) +#define __CV_CPU_DISPATCH_CHAIN_BASELINE(fn, args, mode, ...) CV_CPU_CALL_BASELINE(fn, args) /* last in sequence */ diff --git a/include/opencv2/core/cvdef.h b/include/opencv2/core/cvdef.h new file mode 100644 index 0000000..be7da7a --- /dev/null +++ b/include/opencv2/core/cvdef.h @@ -0,0 +1,763 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CVDEF_H +#define OPENCV_CORE_CVDEF_H + +//! @addtogroup core_utils +//! @{ + +#if !defined CV_DOXYGEN && !defined CV_IGNORE_DEBUG_BUILD_GUARD +#if (defined(_MSC_VER) && (defined(DEBUG) || defined(_DEBUG))) || \ + (defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_DEBUG_PEDANTIC)) +// Guard to prevent using of binary incompatible binaries / runtimes +// https://github.com/opencv/opencv/pull/9161 +#define CV__DEBUG_NS_BEGIN namespace debug_build_guard { +#define CV__DEBUG_NS_END } +namespace cv { namespace debug_build_guard { } using namespace debug_build_guard; } +#endif +#endif + +#ifndef CV__DEBUG_NS_BEGIN +#define CV__DEBUG_NS_BEGIN +#define CV__DEBUG_NS_END +#endif + + +#ifdef __OPENCV_BUILD +#include "cvconfig.h" +#endif + +#ifndef __CV_EXPAND +#define __CV_EXPAND(x) x +#endif + +#ifndef __CV_CAT +#define __CV_CAT__(x, y) x ## y +#define __CV_CAT_(x, y) __CV_CAT__(x, y) +#define __CV_CAT(x, y) __CV_CAT_(x, y) +#endif + +#define __CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N +#define __CV_VA_NUM_ARGS(...) __CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + +#if defined __GNUC__ +#define CV_Func __func__ +#elif defined _MSC_VER +#define CV_Func __FUNCTION__ +#else +#define CV_Func "" +#endif + +//! @cond IGNORED + +//////////////// static assert ///////////////// +#define CVAUX_CONCAT_EXP(a, b) a##b +#define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b) + +#if defined(__clang__) +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_static_assert) +# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition) +# elif __has_extension(c_static_assert) +# define CV_StaticAssert(condition, reason) _Static_assert((condition), reason " " #condition) +# endif +#elif defined(__GNUC__) +# if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L) +# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition) +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1600 /* MSVC 10 */ +# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition) +# endif +#endif +#ifndef CV_StaticAssert +# if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302) +# define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); }) +# else + template <bool x> struct CV_StaticAssert_failed; + template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; }; + template<int x> struct CV_StaticAssert_test {}; +# define CV_StaticAssert(condition, reason)\ + typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__) +# endif +#endif + +// Suppress warning "-Wdeprecated-declarations" / C4996 +#if defined(_MSC_VER) + #define CV_DO_PRAGMA(x) __pragma(x) +#elif defined(__GNUC__) + #define CV_DO_PRAGMA(x) _Pragma (#x) +#else + #define CV_DO_PRAGMA(x) +#endif + +#ifdef _MSC_VER +#define CV_SUPPRESS_DEPRECATED_START \ + CV_DO_PRAGMA(warning(push)) \ + CV_DO_PRAGMA(warning(disable: 4996)) +#define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop)) +#elif defined (__clang__) || ((__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 405)) +#define CV_SUPPRESS_DEPRECATED_START \ + CV_DO_PRAGMA(GCC diagnostic push) \ + CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations") +#define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop) +#else +#define CV_SUPPRESS_DEPRECATED_START +#define CV_SUPPRESS_DEPRECATED_END +#endif + +#define CV_UNUSED(name) (void)name + +#if defined __GNUC__ && !defined __EXCEPTIONS +#define CV_TRY +#define CV_CATCH(A, B) for (A B; false; ) +#define CV_CATCH_ALL if (false) +#define CV_THROW(A) abort() +#define CV_RETHROW() abort() +#else +#define CV_TRY try +#define CV_CATCH(A, B) catch(const A & B) +#define CV_CATCH_ALL catch(...) +#define CV_THROW(A) throw A +#define CV_RETHROW() throw +#endif + +//! @endcond + +// undef problematic defines sometimes defined by system headers (windows.h in particular) +#undef small +#undef min +#undef max +#undef abs +#undef Complex + +#include <limits.h> +#include "opencv2/core/hal/interface.h" + +#if defined __ICL +# define CV_ICC __ICL +#elif defined __ICC +# define CV_ICC __ICC +#elif defined __ECL +# define CV_ICC __ECL +#elif defined __ECC +# define CV_ICC __ECC +#elif defined __INTEL_COMPILER +# define CV_ICC __INTEL_COMPILER +#endif + +#ifndef CV_INLINE +# if defined __cplusplus +# define CV_INLINE static inline +# elif defined _MSC_VER +# define CV_INLINE __inline +# else +# define CV_INLINE static +# endif +#endif + +#ifndef CV_ALWAYS_INLINE +#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) +#define CV_ALWAYS_INLINE inline __attribute__((always_inline)) +#elif defined(_MSC_VER) +#define CV_ALWAYS_INLINE __forceinline +#else +#define CV_ALWAYS_INLINE inline +#endif +#endif + +#if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED) +# define CV_ENABLE_UNROLLED 0 +#else +# define CV_ENABLE_UNROLLED 1 +#endif + +#ifdef __GNUC__ +# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x))) +#elif defined _MSC_VER +# define CV_DECL_ALIGNED(x) __declspec(align(x)) +#else +# define CV_DECL_ALIGNED(x) +#endif + +/* CPU features and intrinsics support */ +#define CV_CPU_NONE 0 +#define CV_CPU_MMX 1 +#define CV_CPU_SSE 2 +#define CV_CPU_SSE2 3 +#define CV_CPU_SSE3 4 +#define CV_CPU_SSSE3 5 +#define CV_CPU_SSE4_1 6 +#define CV_CPU_SSE4_2 7 +#define CV_CPU_POPCNT 8 +#define CV_CPU_FP16 9 +#define CV_CPU_AVX 10 +#define CV_CPU_AVX2 11 +#define CV_CPU_FMA3 12 + +#define CV_CPU_AVX_512F 13 +#define CV_CPU_AVX_512BW 14 +#define CV_CPU_AVX_512CD 15 +#define CV_CPU_AVX_512DQ 16 +#define CV_CPU_AVX_512ER 17 +#define CV_CPU_AVX_512IFMA512 18 // deprecated +#define CV_CPU_AVX_512IFMA 18 +#define CV_CPU_AVX_512PF 19 +#define CV_CPU_AVX_512VBMI 20 +#define CV_CPU_AVX_512VL 21 + +#define CV_CPU_NEON 100 + +#define CV_CPU_VSX 200 +#define CV_CPU_VSX3 201 + +// CPU features groups +#define CV_CPU_AVX512_SKX 256 + +// when adding to this list remember to update the following enum +#define CV_HARDWARE_MAX_FEATURE 512 + +/** @brief Available CPU features. +*/ +enum CpuFeatures { + CPU_MMX = 1, + CPU_SSE = 2, + CPU_SSE2 = 3, + CPU_SSE3 = 4, + CPU_SSSE3 = 5, + CPU_SSE4_1 = 6, + CPU_SSE4_2 = 7, + CPU_POPCNT = 8, + CPU_FP16 = 9, + CPU_AVX = 10, + CPU_AVX2 = 11, + CPU_FMA3 = 12, + + CPU_AVX_512F = 13, + CPU_AVX_512BW = 14, + CPU_AVX_512CD = 15, + CPU_AVX_512DQ = 16, + CPU_AVX_512ER = 17, + CPU_AVX_512IFMA512 = 18, // deprecated + CPU_AVX_512IFMA = 18, + CPU_AVX_512PF = 19, + CPU_AVX_512VBMI = 20, + CPU_AVX_512VL = 21, + + CPU_NEON = 100, + + CPU_VSX = 200, + CPU_VSX3 = 201, + + CPU_AVX512_SKX = 256, //!< Skylake-X with AVX-512F/CD/BW/DQ/VL + + CPU_MAX_FEATURE = 512 // see CV_HARDWARE_MAX_FEATURE +}; + + +#include "cv_cpu_dispatch.h" + + +/* fundamental constants */ +#define CV_PI 3.1415926535897932384626433832795 +#define CV_2PI 6.283185307179586476925286766559 +#define CV_LOG2 0.69314718055994530941723212145818 + +#if defined __ARM_FP16_FORMAT_IEEE \ + && !defined __CUDACC__ +# define CV_FP16_TYPE 1 +#else +# define CV_FP16_TYPE 0 +#endif + +typedef union Cv16suf +{ + short i; + ushort u; +#if CV_FP16_TYPE + __fp16 h; +#endif +} +Cv16suf; + +typedef union Cv32suf +{ + int i; + unsigned u; + float f; +} +Cv32suf; + +typedef union Cv64suf +{ + int64 i; + uint64 u; + double f; +} +Cv64suf; + +#define OPENCV_ABI_COMPATIBILITY 300 + +#ifdef __OPENCV_BUILD +# define DISABLE_OPENCV_24_COMPATIBILITY +# define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY +#endif + +#ifdef CVAPI_EXPORTS +# if (defined _WIN32 || defined WINCE || defined __CYGWIN__) +# define CV_EXPORTS __declspec(dllexport) +# elif defined __GNUC__ && __GNUC__ >= 4 +# define CV_EXPORTS __attribute__ ((visibility ("default"))) +# endif +#endif + +#ifndef CV_EXPORTS +# define CV_EXPORTS +#endif + +#ifdef _MSC_VER +# define CV_EXPORTS_TEMPLATE +#else +# define CV_EXPORTS_TEMPLATE CV_EXPORTS +#endif + +#ifndef CV_DEPRECATED +# if defined(__GNUC__) +# define CV_DEPRECATED __attribute__ ((deprecated)) +# elif defined(_MSC_VER) +# define CV_DEPRECATED __declspec(deprecated) +# else +# define CV_DEPRECATED +# endif +#endif + +#ifndef CV_DEPRECATED_EXTERNAL +# if defined(__OPENCV_BUILD) +# define CV_DEPRECATED_EXTERNAL /* nothing */ +# else +# define CV_DEPRECATED_EXTERNAL CV_DEPRECATED +# endif +#endif + + +#ifndef CV_EXTERN_C +# ifdef __cplusplus +# define CV_EXTERN_C extern "C" +# else +# define CV_EXTERN_C +# endif +#endif + +/* special informative macros for wrapper generators */ +#define CV_EXPORTS_W CV_EXPORTS +#define CV_EXPORTS_W_SIMPLE CV_EXPORTS +#define CV_EXPORTS_AS(synonym) CV_EXPORTS +#define CV_EXPORTS_W_MAP CV_EXPORTS +#define CV_IN_OUT +#define CV_OUT +#define CV_PROP +#define CV_PROP_RW +#define CV_WRAP +#define CV_WRAP_AS(synonym) + +/****************************************************************************************\ +* Matrix type (Mat) * +\****************************************************************************************/ + +#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) +#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) +#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) +#define CV_MAT_CONT_FLAG_SHIFT 14 +#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) +#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) +#define CV_IS_CONT_MAT CV_IS_MAT_CONT +#define CV_SUBMAT_FLAG_SHIFT 15 +#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT) +#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) + +/** Size of each channel item, + 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ +#define CV_ELEM_SIZE1(type) \ + ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) + +/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */ +#define CV_ELEM_SIZE(type) \ + (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)) + +#ifndef MIN +# define MIN(a,b) ((a) > (b) ? (b) : (a)) +#endif + +#ifndef MAX +# define MAX(a,b) ((a) < (b) ? (b) : (a)) +#endif + +/****************************************************************************************\ +* static analysys * +\****************************************************************************************/ + +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#ifndef CV_STATIC_ANALYSIS +# if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__) +# define CV_STATIC_ANALYSIS 1 +# endif +#else +# if defined(CV_STATIC_ANALYSIS) && !(__CV_CAT(1, CV_STATIC_ANALYSIS) == 1) // defined and not empty +# if 0 == CV_STATIC_ANALYSIS +# undef CV_STATIC_ANALYSIS +# endif +# endif +#endif + +/****************************************************************************************\ +* Thread sanitizer * +\****************************************************************************************/ +#ifndef CV_THREAD_SANITIZER +# if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define CV_THREAD_SANITIZER +# endif +# endif +#endif + +/****************************************************************************************\ +* exchange-add operation for atomic operations on reference counters * +\****************************************************************************************/ + +#ifdef CV_XADD + // allow to use user-defined macro +#elif defined __GNUC__ || defined __clang__ +# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER +# ifdef __ATOMIC_ACQ_REL +# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL) +# else +# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4) +# endif +# else +# if defined __ATOMIC_ACQ_REL && !defined __clang__ + // version for gcc >= 4.7 +# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL) +# else +# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta)) +# endif +# endif +#elif defined _MSC_VER && !defined RC_INVOKED +# include <intrin.h> +# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) +#else + CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } +#endif + + +/****************************************************************************************\ +* CV_NORETURN attribute * +\****************************************************************************************/ + +#ifndef CV_NORETURN +# if defined(__GNUC__) +# define CV_NORETURN __attribute__((__noreturn__)) +# elif defined(_MSC_VER) && (_MSC_VER >= 1300) +# define CV_NORETURN __declspec(noreturn) +# else +# define CV_NORETURN /* nothing by default */ +# endif +#endif + + +/****************************************************************************************\ +* CV_NODISCARD attribute * +* encourages the compiler to issue a warning if the return value is discarded (C++17) * +\****************************************************************************************/ +#ifndef CV_NODISCARD +# if defined(__GNUC__) +# define CV_NODISCARD __attribute__((__warn_unused_result__)) // at least available with GCC 3.4 +# elif defined(__clang__) && defined(__has_attribute) +# if __has_attribute(__warn_unused_result__) +# define CV_NODISCARD __attribute__((__warn_unused_result__)) +# endif +# endif +#endif +#ifndef CV_NODISCARD +# define CV_NODISCARD /* nothing by default */ +#endif + + +/****************************************************************************************\ +* C++ 11 * +\****************************************************************************************/ +#ifndef CV_CXX11 +# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) +# define CV_CXX11 1 +# endif +#else +# if CV_CXX11 == 0 +# undef CV_CXX11 +# endif +#endif + + +/****************************************************************************************\ +* C++ Move semantics * +\****************************************************************************************/ + +#ifndef CV_CXX_MOVE_SEMANTICS +# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && _MSC_VER >= 1600) +# define CV_CXX_MOVE_SEMANTICS 1 +# elif defined(__clang) +# if __has_feature(cxx_rvalue_references) +# define CV_CXX_MOVE_SEMANTICS 1 +# endif +# endif +#else +# if CV_CXX_MOVE_SEMANTICS == 0 +# undef CV_CXX_MOVE_SEMANTICS +# endif +#endif + +/****************************************************************************************\ +* C++11 std::array * +\****************************************************************************************/ + +#ifndef CV_CXX_STD_ARRAY +# if __cplusplus >= 201103L || (defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) +# define CV_CXX_STD_ARRAY 1 +# include <array> +# endif +#else +# if CV_CXX_STD_ARRAY == 0 +# undef CV_CXX_STD_ARRAY +# endif +#endif + + +/****************************************************************************************\ +* C++11 override / final * +\****************************************************************************************/ + +#ifndef CV_OVERRIDE +# ifdef CV_CXX11 +# define CV_OVERRIDE override +# endif +#endif +#ifndef CV_OVERRIDE +# define CV_OVERRIDE +#endif + +#ifndef CV_FINAL +# ifdef CV_CXX11 +# define CV_FINAL final +# endif +#endif +#ifndef CV_FINAL +# define CV_FINAL +#endif + + + +// Integer types portatibility +#ifdef OPENCV_STDINT_HEADER +#include OPENCV_STDINT_HEADER +#elif defined(__cplusplus) +#if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */ +namespace cv { +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; +} +#elif defined(_MSC_VER) || __cplusplus >= 201103L +#include <cstdint> +namespace cv { +using std::int8_t; +using std::uint8_t; +using std::int16_t; +using std::uint16_t; +using std::int32_t; +using std::uint32_t; +using std::int64_t; +using std::uint64_t; +} +#else +#include <stdint.h> +namespace cv { +typedef ::int8_t int8_t; +typedef ::uint8_t uint8_t; +typedef ::int16_t int16_t; +typedef ::uint16_t uint16_t; +typedef ::int32_t int32_t; +typedef ::uint32_t uint32_t; +typedef ::int64_t int64_t; +typedef ::uint64_t uint64_t; +} +#endif +#else // pure C +#include <stdint.h> +#endif + +#ifdef __cplusplus +namespace cv +{ + +class float16_t +{ +public: +#if CV_FP16_TYPE + + float16_t() {} + explicit float16_t(float x) { h = (__fp16)x; } + operator float() const { return (float)h; } + static float16_t fromBits(ushort w) + { + Cv16suf u; + u.u = w; + float16_t result; + result.h = u.h; + return result; + } + static float16_t zero() + { + float16_t result; + result.h = (__fp16)0; + return result; + } + ushort bits() const + { + Cv16suf u; + u.h = h; + return u.u; + } +protected: + __fp16 h; + +#else + float16_t() {} + explicit float16_t(float x) + { + #if CV_AVX2 + __m128 v = _mm_load_ss(&x); + w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0)); + #else + Cv32suf in; + in.f = x; + unsigned sign = in.u & 0x80000000; + in.u ^= sign; + + if( in.u >= 0x47800000 ) + w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00); + else + { + if (in.u < 0x38800000) + { + in.f += 0.5f; + w = (ushort)(in.u - 0x3f000000); + } + else + { + unsigned t = in.u + 0xc8000fff; + w = (ushort)((t + ((in.u >> 13) & 1)) >> 13); + } + } + + w = (ushort)(w | (sign >> 16)); + #endif + } + + operator float() const + { + #if CV_AVX2 + float f; + _mm_store_ss(&f, _mm_cvtph_ps(_mm_cvtsi32_si128(w))); + return f; + #else + Cv32suf out; + + unsigned t = ((w & 0x7fff) << 13) + 0x38000000; + unsigned sign = (w & 0x8000) << 16; + unsigned e = w & 0x7c00; + + out.u = t + (1 << 23); + out.u = (e >= 0x7c00 ? t + 0x38000000 : + e == 0 ? (out.f -= 6.103515625e-05f, out.u) : t) | sign; + return out.f; + #endif + } + + static float16_t fromBits(ushort b) + { + float16_t result; + result.w = b; + return result; + } + static float16_t zero() + { + float16_t result; + result.w = (ushort)0; + return result; + } + ushort bits() const { return w; } +protected: + ushort w; + +#endif +}; + +} +#endif + +//! @} + +#ifndef __cplusplus +#include "opencv2/core/fast_math.hpp" // define cvRound(double) +#endif + +#endif // OPENCV_CORE_CVDEF_H diff --git a/include/opencv2/core/cvstd.hpp b/include/opencv2/core/cvstd.hpp new file mode 100644 index 0000000..8af1162 --- /dev/null +++ b/include/opencv2/core/cvstd.hpp @@ -0,0 +1,1040 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CVSTD_HPP +#define OPENCV_CORE_CVSTD_HPP + +#ifndef __cplusplus +# error cvstd.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" +#include <cstddef> +#include <cstring> +#include <cctype> + +#include <string> + +// import useful primitives from stl +# include <algorithm> +# include <utility> +# include <cstdlib> //for abs(int) +# include <cmath> + +namespace cv +{ + static inline uchar abs(uchar a) { return a; } + static inline ushort abs(ushort a) { return a; } + static inline unsigned abs(unsigned a) { return a; } + static inline uint64 abs(uint64 a) { return a; } + + using std::min; + using std::max; + using std::abs; + using std::swap; + using std::sqrt; + using std::exp; + using std::pow; + using std::log; +} + +namespace cv { + +//! @addtogroup core_utils +//! @{ + +//////////////////////////// memory management functions //////////////////////////// + +/** @brief Allocates an aligned memory buffer. + +The function allocates the buffer of the specified size and returns it. When the buffer size is 16 +bytes or more, the returned buffer is aligned to 16 bytes. +@param bufSize Allocated buffer size. + */ +CV_EXPORTS void* fastMalloc(size_t bufSize); + +/** @brief Deallocates a memory buffer. + +The function deallocates the buffer allocated with fastMalloc . If NULL pointer is passed, the +function does nothing. C version of the function clears the pointer *pptr* to avoid problems with +double memory deallocation. +@param ptr Pointer to the allocated buffer. + */ +CV_EXPORTS void fastFree(void* ptr); + +/*! + The STL-compliant memory Allocator based on cv::fastMalloc() and cv::fastFree() +*/ +template<typename _Tp> class Allocator +{ +public: + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + template<typename U> class rebind { typedef Allocator<U> other; }; + + explicit Allocator() {} + ~Allocator() {} + explicit Allocator(Allocator const&) {} + template<typename U> + explicit Allocator(Allocator<U> const&) {} + + // address + pointer address(reference r) { return &r; } + const_pointer address(const_reference r) { return &r; } + + pointer allocate(size_type count, const void* =0) { return reinterpret_cast<pointer>(fastMalloc(count * sizeof (_Tp))); } + void deallocate(pointer p, size_type) { fastFree(p); } + + void construct(pointer p, const _Tp& v) { new(static_cast<void*>(p)) _Tp(v); } + void destroy(pointer p) { p->~_Tp(); } + + size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } +}; + +//! @} core_utils + +//! @cond IGNORED + +namespace detail +{ + +// Metafunction to avoid taking a reference to void. +template<typename T> +struct RefOrVoid { typedef T& type; }; + +template<> +struct RefOrVoid<void>{ typedef void type; }; + +template<> +struct RefOrVoid<const void>{ typedef const void type; }; + +template<> +struct RefOrVoid<volatile void>{ typedef volatile void type; }; + +template<> +struct RefOrVoid<const volatile void>{ typedef const volatile void type; }; + +// This class would be private to Ptr, if it didn't have to be a non-template. +struct PtrOwner; + +} + +template<typename Y> +struct DefaultDeleter +{ + void operator () (Y* p) const; +}; + +//! @endcond + +//! @addtogroup core_basic +//! @{ + +/** @brief Template class for smart pointers with shared ownership + +A Ptr\<T\> pretends to be a pointer to an object of type T. Unlike an ordinary pointer, however, the +object will be automatically cleaned up once all Ptr instances pointing to it are destroyed. + +Ptr is similar to boost::shared_ptr that is part of the Boost library +(<http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm>) and std::shared_ptr from +the [C++11](http://en.wikipedia.org/wiki/C++11) standard. + +This class provides the following advantages: +- Default constructor, copy constructor, and assignment operator for an arbitrary C++ class or C + structure. For some objects, like files, windows, mutexes, sockets, and others, a copy + constructor or an assignment operator are difficult to define. For some other objects, like + complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally, + some of complex OpenCV and your own data structures may be written in C. However, copy + constructors and default constructors can simplify programming a lot. Besides, they are often + required (for example, by STL containers). By using a Ptr to such an object instead of the + object itself, you automatically get all of the necessary constructors and the assignment + operator. +- *O(1)* complexity of the above-mentioned operations. While some structures, like std::vector, + provide a copy constructor and an assignment operator, the operations may take a considerable + amount of time if the data structures are large. But if the structures are put into a Ptr, the + overhead is small and independent of the data size. +- Automatic and customizable cleanup, even for C structures. See the example below with FILE\*. +- Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers + can store only objects of the same type and the same size. The classical solution to store + objects of different types in the same container is to store pointers to the base class (Base\*) + instead but then you lose the automatic memory management. Again, by using Ptr\<Base\> instead + of raw pointers, you can solve the problem. + +A Ptr is said to *own* a pointer - that is, for each Ptr there is a pointer that will be deleted +once all Ptr instances that own it are destroyed. The owned pointer may be null, in which case +nothing is deleted. Each Ptr also *stores* a pointer. The stored pointer is the pointer the Ptr +pretends to be; that is, the one you get when you use Ptr::get or the conversion to T\*. It's +usually the same as the owned pointer, but if you use casts or the general shared-ownership +constructor, the two may diverge: the Ptr will still own the original pointer, but will itself point +to something else. + +The owned pointer is treated as a black box. The only thing Ptr needs to know about it is how to +delete it. This knowledge is encapsulated in the *deleter* - an auxiliary object that is associated +with the owned pointer and shared between all Ptr instances that own it. The default deleter is an +instance of DefaultDeleter, which uses the standard C++ delete operator; as such it will work with +any pointer allocated with the standard new operator. + +However, if the pointer must be deleted in a different way, you must specify a custom deleter upon +Ptr construction. A deleter is simply a callable object that accepts the pointer as its sole +argument. For example, if you want to wrap FILE, you may do so as follows: +@code + Ptr<FILE> f(fopen("myfile.txt", "w"), fclose); + if(!f) throw ...; + fprintf(f, ....); + ... + // the file will be closed automatically by f's destructor. +@endcode +Alternatively, if you want all pointers of a particular type to be deleted the same way, you can +specialize DefaultDeleter<T>::operator() for that type, like this: +@code + namespace cv { + template<> void DefaultDeleter<FILE>::operator ()(FILE * obj) const + { + fclose(obj); + } + } +@endcode +For convenience, the following types from the OpenCV C API already have such a specialization that +calls the appropriate release function: +- CvCapture +- CvFileStorage +- CvHaarClassifierCascade +- CvMat +- CvMatND +- CvMemStorage +- CvSparseMat +- CvVideoWriter +- IplImage +@note The shared ownership mechanism is implemented with reference counting. As such, cyclic +ownership (e.g. when object a contains a Ptr to object b, which contains a Ptr to object a) will +lead to all involved objects never being cleaned up. Avoid such situations. +@note It is safe to concurrently read (but not write) a Ptr instance from multiple threads and +therefore it is normally safe to use it in multi-threaded applications. The same is true for Mat and +other C++ OpenCV classes that use internal reference counts. +*/ +template<typename T> +struct Ptr +{ + /** Generic programming support. */ + typedef T element_type; + + /** The default constructor creates a null Ptr - one that owns and stores a null pointer. + */ + Ptr(); + + /** + If p is null, these are equivalent to the default constructor. + Otherwise, these constructors assume ownership of p - that is, the created Ptr owns and stores p + and assumes it is the sole owner of it. Don't use them if p is already owned by another Ptr, or + else p will get deleted twice. + With the first constructor, DefaultDeleter\<Y\>() becomes the associated deleter (so p will + eventually be deleted with the standard delete operator). Y must be a complete type at the point + of invocation. + With the second constructor, d becomes the associated deleter. + Y\* must be convertible to T\*. + @param p Pointer to own. + @note It is often easier to use makePtr instead. + */ + template<typename Y> +#ifdef DISABLE_OPENCV_24_COMPATIBILITY + explicit +#endif + Ptr(Y* p); + + /** @overload + @param d Deleter to use for the owned pointer. + @param p Pointer to own. + */ + template<typename Y, typename D> + Ptr(Y* p, D d); + + /** + These constructors create a Ptr that shares ownership with another Ptr - that is, own the same + pointer as o. + With the first two, the same pointer is stored, as well; for the second, Y\* must be convertible + to T\*. + With the third, p is stored, and Y may be any type. This constructor allows to have completely + unrelated owned and stored pointers, and should be used with care to avoid confusion. A relatively + benign use is to create a non-owning Ptr, like this: + @code + ptr = Ptr<T>(Ptr<T>(), dont_delete_me); // owns nothing; will not delete the pointer. + @endcode + @param o Ptr to share ownership with. + */ + Ptr(const Ptr& o); + + /** @overload + @param o Ptr to share ownership with. + */ + template<typename Y> + Ptr(const Ptr<Y>& o); + + /** @overload + @param o Ptr to share ownership with. + @param p Pointer to store. + */ + template<typename Y> + Ptr(const Ptr<Y>& o, T* p); + + /** The destructor is equivalent to calling Ptr::release. */ + ~Ptr(); + + /** + Assignment replaces the current Ptr instance with one that owns and stores same pointers as o and + then destroys the old instance. + @param o Ptr to share ownership with. + */ + Ptr& operator = (const Ptr& o); + + /** @overload */ + template<typename Y> + Ptr& operator = (const Ptr<Y>& o); + + /** If no other Ptr instance owns the owned pointer, deletes it with the associated deleter. Then sets + both the owned and the stored pointers to NULL. + */ + void release(); + + /** + `ptr.reset(...)` is equivalent to `ptr = Ptr<T>(...)`. + @param p Pointer to own. + */ + template<typename Y> + void reset(Y* p); + + /** @overload + @param d Deleter to use for the owned pointer. + @param p Pointer to own. + */ + template<typename Y, typename D> + void reset(Y* p, D d); + + /** + Swaps the owned and stored pointers (and deleters, if any) of this and o. + @param o Ptr to swap with. + */ + void swap(Ptr& o); + + /** Returns the stored pointer. */ + T* get() const; + + /** Ordinary pointer emulation. */ + typename detail::RefOrVoid<T>::type operator * () const; + + /** Ordinary pointer emulation. */ + T* operator -> () const; + + /** Equivalent to get(). */ + operator T* () const; + + /** ptr.empty() is equivalent to `!ptr.get()`. */ + bool empty() const; + + /** Returns a Ptr that owns the same pointer as this, and stores the same + pointer as this, except converted via static_cast to Y*. + */ + template<typename Y> + Ptr<Y> staticCast() const; + + /** Ditto for const_cast. */ + template<typename Y> + Ptr<Y> constCast() const; + + /** Ditto for dynamic_cast. */ + template<typename Y> + Ptr<Y> dynamicCast() const; + +#ifdef CV_CXX_MOVE_SEMANTICS + Ptr(Ptr&& o); + Ptr& operator = (Ptr&& o); +#endif + +private: + detail::PtrOwner* owner; + T* stored; + + template<typename Y> + friend struct Ptr; // have to do this for the cross-type copy constructor +}; + +/** Equivalent to ptr1.swap(ptr2). Provided to help write generic algorithms. */ +template<typename T> +void swap(Ptr<T>& ptr1, Ptr<T>& ptr2); + +/** Return whether ptr1.get() and ptr2.get() are equal and not equal, respectively. */ +template<typename T> +bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2); +template<typename T> +bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2); + +/** `makePtr<T>(...)` is equivalent to `Ptr<T>(new T(...))`. It is shorter than the latter, and it's +marginally safer than using a constructor or Ptr::reset, since it ensures that the owned pointer +is new and thus not owned by any other Ptr instance. +Unfortunately, perfect forwarding is impossible to implement in C++03, and so makePtr is limited +to constructors of T that have up to 10 arguments, none of which are non-const references. + */ +template<typename T> +Ptr<T> makePtr(); +/** @overload */ +template<typename T, typename A1> +Ptr<T> makePtr(const A1& a1); +/** @overload */ +template<typename T, typename A1, typename A2> +Ptr<T> makePtr(const A1& a1, const A2& a2); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9); +/** @overload */ +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10); + +//////////////////////////////// string class //////////////////////////////// + +class CV_EXPORTS FileNode; //for string constructor from FileNode + +class CV_EXPORTS String +{ +public: + typedef char value_type; + typedef char& reference; + typedef const char& const_reference; + typedef char* pointer; + typedef const char* const_pointer; + typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef char* iterator; + typedef const char* const_iterator; + + static const size_t npos = size_t(-1); + + String(); + String(const String& str); + String(const String& str, size_t pos, size_t len = npos); + String(const char* s); + String(const char* s, size_t n); + String(size_t n, char c); + String(const char* first, const char* last); + template<typename Iterator> String(Iterator first, Iterator last); + explicit String(const FileNode& fn); + ~String(); + + String& operator=(const String& str); + String& operator=(const char* s); + String& operator=(char c); + + String& operator+=(const String& str); + String& operator+=(const char* s); + String& operator+=(char c); + + size_t size() const; + size_t length() const; + + char operator[](size_t idx) const; + char operator[](int idx) const; + + const char* begin() const; + const char* end() const; + + const char* c_str() const; + + bool empty() const; + void clear(); + + int compare(const char* s) const; + int compare(const String& str) const; + + void swap(String& str); + String substr(size_t pos = 0, size_t len = npos) const; + + size_t find(const char* s, size_t pos, size_t n) const; + size_t find(char c, size_t pos = 0) const; + size_t find(const String& str, size_t pos = 0) const; + size_t find(const char* s, size_t pos = 0) const; + + size_t rfind(const char* s, size_t pos, size_t n) const; + size_t rfind(char c, size_t pos = npos) const; + size_t rfind(const String& str, size_t pos = npos) const; + size_t rfind(const char* s, size_t pos = npos) const; + + size_t find_first_of(const char* s, size_t pos, size_t n) const; + size_t find_first_of(char c, size_t pos = 0) const; + size_t find_first_of(const String& str, size_t pos = 0) const; + size_t find_first_of(const char* s, size_t pos = 0) const; + + size_t find_last_of(const char* s, size_t pos, size_t n) const; + size_t find_last_of(char c, size_t pos = npos) const; + size_t find_last_of(const String& str, size_t pos = npos) const; + size_t find_last_of(const char* s, size_t pos = npos) const; + + friend String operator+ (const String& lhs, const String& rhs); + friend String operator+ (const String& lhs, const char* rhs); + friend String operator+ (const char* lhs, const String& rhs); + friend String operator+ (const String& lhs, char rhs); + friend String operator+ (char lhs, const String& rhs); + + String toLowerCase() const; + + String(const std::string& str); + String(const std::string& str, size_t pos, size_t len = npos); + String& operator=(const std::string& str); + String& operator+=(const std::string& str); + operator std::string() const; + + friend String operator+ (const String& lhs, const std::string& rhs); + friend String operator+ (const std::string& lhs, const String& rhs); + +private: + char* cstr_; + size_t len_; + + char* allocate(size_t len); // len without trailing 0 + void deallocate(); + + String(int); // disabled and invalid. Catch invalid usages like, commandLineParser.has(0) problem +}; + +//! @} core_basic + +////////////////////////// cv::String implementation ///////////////////////// + +//! @cond IGNORED + +inline +String::String() + : cstr_(0), len_(0) +{} + +inline +String::String(const String& str) + : cstr_(str.cstr_), len_(str.len_) +{ + if (cstr_) + CV_XADD(((int*)cstr_)-1, 1); +} + +inline +String::String(const String& str, size_t pos, size_t len) + : cstr_(0), len_(0) +{ + pos = min(pos, str.len_); + len = min(str.len_ - pos, len); + if (!len) return; + if (len == str.len_) + { + CV_XADD(((int*)str.cstr_)-1, 1); + cstr_ = str.cstr_; + len_ = str.len_; + return; + } + memcpy(allocate(len), str.cstr_ + pos, len); +} + +inline +String::String(const char* s) + : cstr_(0), len_(0) +{ + if (!s) return; + size_t len = strlen(s); + if (!len) return; + memcpy(allocate(len), s, len); +} + +inline +String::String(const char* s, size_t n) + : cstr_(0), len_(0) +{ + if (!n) return; + if (!s) return; + memcpy(allocate(n), s, n); +} + +inline +String::String(size_t n, char c) + : cstr_(0), len_(0) +{ + if (!n) return; + memset(allocate(n), c, n); +} + +inline +String::String(const char* first, const char* last) + : cstr_(0), len_(0) +{ + size_t len = (size_t)(last - first); + if (!len) return; + memcpy(allocate(len), first, len); +} + +template<typename Iterator> inline +String::String(Iterator first, Iterator last) + : cstr_(0), len_(0) +{ + size_t len = (size_t)(last - first); + if (!len) return; + char* str = allocate(len); + while (first != last) + { + *str++ = *first; + ++first; + } +} + +inline +String::~String() +{ + deallocate(); +} + +inline +String& String::operator=(const String& str) +{ + if (&str == this) return *this; + + deallocate(); + if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1); + cstr_ = str.cstr_; + len_ = str.len_; + return *this; +} + +inline +String& String::operator=(const char* s) +{ + deallocate(); + if (!s) return *this; + size_t len = strlen(s); + if (len) memcpy(allocate(len), s, len); + return *this; +} + +inline +String& String::operator=(char c) +{ + deallocate(); + allocate(1)[0] = c; + return *this; +} + +inline +String& String::operator+=(const String& str) +{ + *this = *this + str; + return *this; +} + +inline +String& String::operator+=(const char* s) +{ + *this = *this + s; + return *this; +} + +inline +String& String::operator+=(char c) +{ + *this = *this + c; + return *this; +} + +inline +size_t String::size() const +{ + return len_; +} + +inline +size_t String::length() const +{ + return len_; +} + +inline +char String::operator[](size_t idx) const +{ + return cstr_[idx]; +} + +inline +char String::operator[](int idx) const +{ + return cstr_[idx]; +} + +inline +const char* String::begin() const +{ + return cstr_; +} + +inline +const char* String::end() const +{ + return len_ ? cstr_ + len_ : NULL; +} + +inline +bool String::empty() const +{ + return len_ == 0; +} + +inline +const char* String::c_str() const +{ + return cstr_ ? cstr_ : ""; +} + +inline +void String::swap(String& str) +{ + cv::swap(cstr_, str.cstr_); + cv::swap(len_, str.len_); +} + +inline +void String::clear() +{ + deallocate(); +} + +inline +int String::compare(const char* s) const +{ + if (cstr_ == s) return 0; + return strcmp(c_str(), s); +} + +inline +int String::compare(const String& str) const +{ + if (cstr_ == str.cstr_) return 0; + return strcmp(c_str(), str.c_str()); +} + +inline +String String::substr(size_t pos, size_t len) const +{ + return String(*this, pos, len); +} + +inline +size_t String::find(const char* s, size_t pos, size_t n) const +{ + if (n == 0 || pos + n > len_) return npos; + const char* lmax = cstr_ + len_ - n; + for (const char* i = cstr_ + pos; i <= lmax; ++i) + { + size_t j = 0; + while (j < n && s[j] == i[j]) ++j; + if (j == n) return (size_t)(i - cstr_); + } + return npos; +} + +inline +size_t String::find(char c, size_t pos) const +{ + return find(&c, pos, 1); +} + +inline +size_t String::find(const String& str, size_t pos) const +{ + return find(str.c_str(), pos, str.len_); +} + +inline +size_t String::find(const char* s, size_t pos) const +{ + if (pos >= len_ || !s[0]) return npos; + const char* lmax = cstr_ + len_; + for (const char* i = cstr_ + pos; i < lmax; ++i) + { + size_t j = 0; + while (s[j] && s[j] == i[j]) + { if(i + j >= lmax) return npos; + ++j; + } + if (!s[j]) return (size_t)(i - cstr_); + } + return npos; +} + +inline +size_t String::rfind(const char* s, size_t pos, size_t n) const +{ + if (n > len_) return npos; + if (pos > len_ - n) pos = len_ - n; + for (const char* i = cstr_ + pos; i >= cstr_; --i) + { + size_t j = 0; + while (j < n && s[j] == i[j]) ++j; + if (j == n) return (size_t)(i - cstr_); + } + return npos; +} + +inline +size_t String::rfind(char c, size_t pos) const +{ + return rfind(&c, pos, 1); +} + +inline +size_t String::rfind(const String& str, size_t pos) const +{ + return rfind(str.c_str(), pos, str.len_); +} + +inline +size_t String::rfind(const char* s, size_t pos) const +{ + return rfind(s, pos, strlen(s)); +} + +inline +size_t String::find_first_of(const char* s, size_t pos, size_t n) const +{ + if (n == 0 || pos + n > len_) return npos; + const char* lmax = cstr_ + len_; + for (const char* i = cstr_ + pos; i < lmax; ++i) + { + for (size_t j = 0; j < n; ++j) + if (s[j] == *i) + return (size_t)(i - cstr_); + } + return npos; +} + +inline +size_t String::find_first_of(char c, size_t pos) const +{ + return find_first_of(&c, pos, 1); +} + +inline +size_t String::find_first_of(const String& str, size_t pos) const +{ + return find_first_of(str.c_str(), pos, str.len_); +} + +inline +size_t String::find_first_of(const char* s, size_t pos) const +{ + if (len_ == 0) return npos; + if (pos >= len_ || !s[0]) return npos; + const char* lmax = cstr_ + len_; + for (const char* i = cstr_ + pos; i < lmax; ++i) + { + for (size_t j = 0; s[j]; ++j) + if (s[j] == *i) + return (size_t)(i - cstr_); + } + return npos; +} + +inline +size_t String::find_last_of(const char* s, size_t pos, size_t n) const +{ + if (len_ == 0) return npos; + if (pos >= len_) pos = len_ - 1; + for (const char* i = cstr_ + pos; i >= cstr_; --i) + { + for (size_t j = 0; j < n; ++j) + if (s[j] == *i) + return (size_t)(i - cstr_); + } + return npos; +} + +inline +size_t String::find_last_of(char c, size_t pos) const +{ + return find_last_of(&c, pos, 1); +} + +inline +size_t String::find_last_of(const String& str, size_t pos) const +{ + return find_last_of(str.c_str(), pos, str.len_); +} + +inline +size_t String::find_last_of(const char* s, size_t pos) const +{ + if (len_ == 0) return npos; + if (pos >= len_) pos = len_ - 1; + for (const char* i = cstr_ + pos; i >= cstr_; --i) + { + for (size_t j = 0; s[j]; ++j) + if (s[j] == *i) + return (size_t)(i - cstr_); + } + return npos; +} + +inline +String String::toLowerCase() const +{ + if (!cstr_) + return String(); + String res(cstr_, len_); + for (size_t i = 0; i < len_; ++i) + res.cstr_[i] = (char) ::tolower(cstr_[i]); + + return res; +} + +//! @endcond + +// ************************* cv::String non-member functions ************************* + +//! @relates cv::String +//! @{ + +inline +String operator + (const String& lhs, const String& rhs) +{ + String s; + s.allocate(lhs.len_ + rhs.len_); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (rhs.len_) memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_); + return s; +} + +inline +String operator + (const String& lhs, const char* rhs) +{ + String s; + size_t rhslen = strlen(rhs); + s.allocate(lhs.len_ + rhslen); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs, rhslen); + return s; +} + +inline +String operator + (const char* lhs, const String& rhs) +{ + String s; + size_t lhslen = strlen(lhs); + s.allocate(lhslen + rhs.len_); + if (lhslen) memcpy(s.cstr_, lhs, lhslen); + if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); + return s; +} + +inline +String operator + (const String& lhs, char rhs) +{ + String s; + s.allocate(lhs.len_ + 1); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + s.cstr_[lhs.len_] = rhs; + return s; +} + +inline +String operator + (char lhs, const String& rhs) +{ + String s; + s.allocate(rhs.len_ + 1); + s.cstr_[0] = lhs; + if (rhs.len_) memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_); + return s; +} + +static inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); } +static inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); } +static inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); } +static inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); } +static inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); } +static inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); } +static inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; } +static inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; } +static inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; } +static inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; } +static inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; } +static inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; } +static inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; } +static inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; } +static inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; } +static inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; } +static inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; } +static inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; } + +//! @} relates cv::String + +} // cv + +namespace std +{ + static inline void swap(cv::String& a, cv::String& b) { a.swap(b); } +} + +#include "opencv2/core/ptr.inl.hpp" + +#endif //OPENCV_CORE_CVSTD_HPP diff --git a/include/opencv2/core/cvstd.inl.hpp b/include/opencv2/core/cvstd.inl.hpp new file mode 100644 index 0000000..ed37cac --- /dev/null +++ b/include/opencv2/core/cvstd.inl.hpp @@ -0,0 +1,285 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_CVSTDINL_HPP +#define OPENCV_CORE_CVSTDINL_HPP + +#include <complex> +#include <ostream> + +//! @cond IGNORED + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4127 ) +#endif + +namespace cv +{ + +template<typename _Tp> class DataType< std::complex<_Tp> > +{ +public: + typedef std::complex<_Tp> value_type; + typedef value_type work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + depth = DataType<channel_type>::depth, + channels = 2, + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) }; + + typedef Vec<channel_type, channels> vec_type; +}; + +inline +String::String(const std::string& str) + : cstr_(0), len_(0) +{ + size_t len = str.size(); + if (len) memcpy(allocate(len), str.c_str(), len); +} + +inline +String::String(const std::string& str, size_t pos, size_t len) + : cstr_(0), len_(0) +{ + size_t strlen = str.size(); + pos = min(pos, strlen); + len = min(strlen - pos, len); + if (!len) return; + memcpy(allocate(len), str.c_str() + pos, len); +} + +inline +String& String::operator = (const std::string& str) +{ + deallocate(); + size_t len = str.size(); + if (len) memcpy(allocate(len), str.c_str(), len); + return *this; +} + +inline +String& String::operator += (const std::string& str) +{ + *this = *this + str; + return *this; +} + +inline +String::operator std::string() const +{ + return std::string(cstr_, len_); +} + +inline +String operator + (const String& lhs, const std::string& rhs) +{ + String s; + size_t rhslen = rhs.size(); + s.allocate(lhs.len_ + rhslen); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen); + return s; +} + +inline +String operator + (const std::string& lhs, const String& rhs) +{ + String s; + size_t lhslen = lhs.size(); + s.allocate(lhslen + rhs.len_); + if (lhslen) memcpy(s.cstr_, lhs.c_str(), lhslen); + if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); + return s; +} + +inline +FileNode::operator std::string() const +{ + String value; + read(*this, value, value); + return value; +} + +template<> inline +void operator >> (const FileNode& n, std::string& value) +{ + read(n, value, std::string()); +} + +template<> inline +FileStorage& operator << (FileStorage& fs, const std::string& value) +{ + return fs << cv::String(value); +} + +static inline +std::ostream& operator << (std::ostream& os, const String& str) +{ + return os << str.c_str(); +} + +static inline +std::ostream& operator << (std::ostream& out, Ptr<Formatted> fmtd) +{ + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + out << str; + return out; +} + +static inline +std::ostream& operator << (std::ostream& out, const Mat& mtx) +{ + return out << Formatter::get()->format(mtx); +} + +static inline +std::ostream& operator << (std::ostream& out, const UMat& m) +{ + return out << m.getMat(ACCESS_READ); +} + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const Complex<_Tp>& c) +{ + return out << "(" << c.re << "," << c.im << ")"; +} + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const std::vector<Point_<_Tp> >& vec) +{ + return out << Formatter::get()->format(Mat(vec)); +} + + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const std::vector<Point3_<_Tp> >& vec) +{ + return out << Formatter::get()->format(Mat(vec)); +} + + +template<typename _Tp, int m, int n> static inline +std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx) +{ + return out << Formatter::get()->format(Mat(matx)); +} + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << "]"; + return out; +} + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; + return out; +} + +template<typename _Tp, int n> static inline +std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec) +{ + out << "["; + if (cv::traits::Depth<_Tp>::value <= CV_32S) + { + for (int i = 0; i < n - 1; ++i) { + out << (int)vec[i] << ", "; + } + out << (int)vec[n-1] << "]"; + } + else + { + for (int i = 0; i < n - 1; ++i) { + out << vec[i] << ", "; + } + out << vec[n-1] << "]"; + } + + return out; +} + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size) +{ + return out << "[" << size.width << " x " << size.height << "]"; +} + +template<typename _Tp> static inline +std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect) +{ + return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; +} + +static inline std::ostream& operator << (std::ostream& out, const MatSize& msize) +{ + int i, dims = msize.dims(); + for( i = 0; i < dims; i++ ) + { + out << msize[i]; + if( i < dims-1 ) + out << " x "; + } + return out; +} + +static inline std::ostream &operator<< (std::ostream &s, cv::Range &r) +{ + return s << "[" << r.start << " : " << r.end << ")"; +} + +} // cv + +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + +//! @endcond + +#endif // OPENCV_CORE_CVSTDINL_HPP diff --git a/include/opencv2/core/directx.hpp b/include/opencv2/core/directx.hpp new file mode 100644 index 0000000..056a85a --- /dev/null +++ b/include/opencv2/core/directx.hpp @@ -0,0 +1,184 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef OPENCV_CORE_DIRECTX_HPP +#define OPENCV_CORE_DIRECTX_HPP + +#include "mat.hpp" +#include "ocl.hpp" + +#if !defined(__d3d11_h__) +struct ID3D11Device; +struct ID3D11Texture2D; +#endif + +#if !defined(__d3d10_h__) +struct ID3D10Device; +struct ID3D10Texture2D; +#endif + +#if !defined(_D3D9_H_) +struct IDirect3DDevice9; +struct IDirect3DDevice9Ex; +struct IDirect3DSurface9; +#endif + + +namespace cv { namespace directx { + +namespace ocl { +using namespace cv::ocl; + +//! @addtogroup core_directx +// This section describes OpenCL and DirectX interoperability. +// +// To enable DirectX support, configure OpenCV using CMake with WITH_DIRECTX=ON . Note, DirectX is +// supported only on Windows. +// +// To use OpenCL functionality you should first initialize OpenCL context from DirectX resource. +// +//! @{ + +// TODO static functions in the Context class +//! @brief Creates OpenCL context from D3D11 device +// +//! @param pD3D11Device - pointer to D3D11 device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device); + +//! @brief Creates OpenCL context from D3D10 device +// +//! @param pD3D10Device - pointer to D3D10 device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device); + +//! @brief Creates OpenCL context from Direct3DDevice9Ex device +// +//! @param pDirect3DDevice9Ex - pointer to Direct3DDevice9Ex device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex); + +//! @brief Creates OpenCL context from Direct3DDevice9 device +// +//! @param pDirect3DDevice9 - pointer to Direct3Device9 device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9); + +//! @} + +} // namespace cv::directx::ocl + +//! @addtogroup core_directx +//! @{ + +//! @brief Converts InputArray to ID3D11Texture2D. If destination texture format is DXGI_FORMAT_NV12 then +//! input UMat expected to be in BGR format and data will be downsampled and color-converted to NV12. +// +//! @note Note: Destination texture must be allocated by application. Function does memory copy from src to +//! pD3D11Texture2D +// +//! @param src - source InputArray +//! @param pD3D11Texture2D - destination D3D11 texture +CV_EXPORTS void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D); + +//! @brief Converts ID3D11Texture2D to OutputArray. If input texture format is DXGI_FORMAT_NV12 then +//! data will be upsampled and color-converted to BGR format. +// +//! @note Note: Destination matrix will be re-allocated if it has not enough memory to match texture size. +//! function does memory copy from pD3D11Texture2D to dst +// +//! @param pD3D11Texture2D - source D3D11 texture +//! @param dst - destination OutputArray +CV_EXPORTS void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst); + +//! @brief Converts InputArray to ID3D10Texture2D +// +//! @note Note: function does memory copy from src to +//! pD3D10Texture2D +// +//! @param src - source InputArray +//! @param pD3D10Texture2D - destination D3D10 texture +CV_EXPORTS void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D); + +//! @brief Converts ID3D10Texture2D to OutputArray +// +//! @note Note: function does memory copy from pD3D10Texture2D +//! to dst +// +//! @param pD3D10Texture2D - source D3D10 texture +//! @param dst - destination OutputArray +CV_EXPORTS void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst); + +//! @brief Converts InputArray to IDirect3DSurface9 +// +//! @note Note: function does memory copy from src to +//! pDirect3DSurface9 +// +//! @param src - source InputArray +//! @param pDirect3DSurface9 - destination D3D10 texture +//! @param surfaceSharedHandle - shared handle +CV_EXPORTS void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurface9, void* surfaceSharedHandle = NULL); + +//! @brief Converts IDirect3DSurface9 to OutputArray +// +//! @note Note: function does memory copy from pDirect3DSurface9 +//! to dst +// +//! @param pDirect3DSurface9 - source D3D10 texture +//! @param dst - destination OutputArray +//! @param surfaceSharedHandle - shared handle +CV_EXPORTS void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArray dst, void* surfaceSharedHandle = NULL); + +//! @brief Get OpenCV type from DirectX type +//! @param iDXGI_FORMAT - enum DXGI_FORMAT for D3D10/D3D11 +//! @return OpenCV type or -1 if there is no equivalent +CV_EXPORTS int getTypeFromDXGI_FORMAT(const int iDXGI_FORMAT); // enum DXGI_FORMAT for D3D10/D3D11 + +//! @brief Get OpenCV type from DirectX type +//! @param iD3DFORMAT - enum D3DTYPE for D3D9 +//! @return OpenCV type or -1 if there is no equivalent +CV_EXPORTS int getTypeFromD3DFORMAT(const int iD3DFORMAT); // enum D3DTYPE for D3D9 + +//! @} + +} } // namespace cv::directx + +#endif // OPENCV_CORE_DIRECTX_HPP diff --git a/include/opencv2/core/eigen.hpp b/include/opencv2/core/eigen.hpp new file mode 100644 index 0000000..741648e --- /dev/null +++ b/include/opencv2/core/eigen.hpp @@ -0,0 +1,280 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + + +#ifndef OPENCV_CORE_EIGEN_HPP +#define OPENCV_CORE_EIGEN_HPP + +#include "opencv2/core.hpp" + +#if defined _MSC_VER && _MSC_VER >= 1200 +#pragma warning( disable: 4714 ) //__forceinline is not inlined +#pragma warning( disable: 4127 ) //conditional expression is constant +#pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data +#endif + +namespace cv +{ + +//! @addtogroup core_eigen +//! @{ + +template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline +void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, OutputArray dst ) +{ + if( !(src.Flags & Eigen::RowMajorBit) ) + { + Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value, + (void*)src.data(), src.outerStride()*sizeof(_Tp)); + transpose(_src, dst); + } + else + { + Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value, + (void*)src.data(), src.outerStride()*sizeof(_Tp)); + _src.copyTo(dst); + } +} + +// Matx case +template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline +void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, + Matx<_Tp, _rows, _cols>& dst ) +{ + if( !(src.Flags & Eigen::RowMajorBit) ) + { + dst = Matx<_Tp, _cols, _rows>(static_cast<const _Tp*>(src.data())).t(); + } + else + { + dst = Matx<_Tp, _rows, _cols>(static_cast<const _Tp*>(src.data())); + } +} + +template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) +{ + CV_DbgAssert(src.rows == _rows && src.cols == _cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else if( src.cols == src.rows ) + { + src.convertTo(_dst, _dst.type()); + transpose(_dst, _dst); + } + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +// Matx case +template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline +void cv2eigen( const Matx<_Tp, _rows, _cols>& src, + Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) +{ + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + Mat(src).copyTo(_dst); + } +} + +template<typename _Tp> static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) +{ + dst.resize(src.rows, src.cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else if( src.cols == src.rows ) + { + src.convertTo(_dst, _dst.type()); + transpose(_dst, _dst); + } + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +// Matx case +template<typename _Tp, int _rows, int _cols> static inline +void cv2eigen( const Matx<_Tp, _rows, _cols>& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) +{ + dst.resize(_rows, _cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + Mat(src).copyTo(_dst); + } +} + +template<typename _Tp> static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) +{ + CV_Assert(src.cols == 1); + dst.resize(src.rows); + + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +// Matx case +template<typename _Tp, int _rows> static inline +void cv2eigen( const Matx<_Tp, _rows, 1>& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) +{ + dst.resize(_rows); + + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(1, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(_rows, 1, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.copyTo(_dst); + } +} + + +template<typename _Tp> static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) +{ + CV_Assert(src.rows == 1); + dst.resize(src.cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +//Matx +template<typename _Tp, int _cols> static inline +void cv2eigen( const Matx<_Tp, 1, _cols>& src, + Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) +{ + dst.resize(_cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(_cols, 1, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(1, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + Mat(src).copyTo(_dst); + } +} + +//! @} + +} // cv + +#endif diff --git a/include/opencv2/core/fast_math.hpp b/include/opencv2/core/fast_math.hpp new file mode 100644 index 0000000..d9ea28e --- /dev/null +++ b/include/opencv2/core/fast_math.hpp @@ -0,0 +1,271 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_FAST_MATH_HPP +#define OPENCV_CORE_FAST_MATH_HPP + +#include "opencv2/core/cvdef.h" + +#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) +#include <emmintrin.h> +#endif + + +//! @addtogroup core_utils +//! @{ + +/****************************************************************************************\ +* fast math * +\****************************************************************************************/ + +#ifdef __cplusplus +# include <cmath> +#else +# ifdef __BORLANDC__ +# include <fastmath.h> +# else +# include <math.h> +# endif +#endif + +#ifdef HAVE_TEGRA_OPTIMIZATION +# include "tegra_round.hpp" +#endif + +#if defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ && !defined(__CUDACC__) + // 1. general scheme + #define ARM_ROUND(_value, _asm_string) \ + int res; \ + float temp; \ + CV_UNUSED(temp); \ + __asm__(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \ + return res + // 2. version for double + #ifdef __clang__ + #define ARM_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %[value] \n vmov %[res], %[temp]") + #else + #define ARM_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %P[value] \n vmov %[res], %[temp]") + #endif + // 3. version for float + #define ARM_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]") +#endif + +/** @brief Rounds floating-point number to the nearest integer + + @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the + result is not defined. + */ +CV_INLINE int +cvRound( double value ) +{ +#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) && !defined(__CUDACC__) + __m128d t = _mm_set_sd( value ); + return _mm_cvtsd_si32(t); +#elif defined _MSC_VER && defined _M_IX86 + int t; + __asm + { + fld value; + fistp t; + } + return t; +#elif ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \ + defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION + TEGRA_ROUND_DBL(value); +#elif defined CV_ICC || defined __GNUC__ +# if defined ARM_ROUND_DBL + ARM_ROUND_DBL(value); +# else + return (int)lrint(value); +# endif +#else + /* it's ok if round does not comply with IEEE754 standard; + the tests should allow +/-1 difference when the tested functions use round */ + return (int)(value + (value >= 0 ? 0.5 : -0.5)); +#endif +} + + +/** @brief Rounds floating-point number to the nearest integer not larger than the original. + + The function computes an integer i such that: + \f[i \le \texttt{value} < i+1\f] + @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the + result is not defined. + */ +CV_INLINE int cvFloor( double value ) +{ + int i = (int)value; + return i - (i > value); +} + +/** @brief Rounds floating-point number to the nearest integer not smaller than the original. + + The function computes an integer i such that: + \f[i \le \texttt{value} < i+1\f] + @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the + result is not defined. + */ +CV_INLINE int cvCeil( double value ) +{ + int i = (int)value; + return i + (i < value); +} + +/** @brief Determines if the argument is Not A Number. + + @param value The input floating-point value + + The function returns 1 if the argument is Not A Number (as defined by IEEE754 standard), 0 + otherwise. */ +CV_INLINE int cvIsNaN( double value ) +{ + Cv64suf ieee754; + ieee754.f = value; + return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) + + ((unsigned)ieee754.u != 0) > 0x7ff00000; +} + +/** @brief Determines if the argument is Infinity. + + @param value The input floating-point value + + The function returns 1 if the argument is a plus or minus infinity (as defined by IEEE754 standard) + and 0 otherwise. */ +CV_INLINE int cvIsInf( double value ) +{ + Cv64suf ieee754; + ieee754.f = value; + return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && + (unsigned)ieee754.u == 0; +} + +#ifdef __cplusplus + +/** @overload */ +CV_INLINE int cvRound(float value) +{ +#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) && !defined(__CUDACC__) + __m128 t = _mm_set_ss( value ); + return _mm_cvtss_si32(t); +#elif defined _MSC_VER && defined _M_IX86 + int t; + __asm + { + fld value; + fistp t; + } + return t; +#elif ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \ + defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION + TEGRA_ROUND_FLT(value); +#elif defined CV_ICC || defined __GNUC__ +# if defined ARM_ROUND_FLT + ARM_ROUND_FLT(value); +# else + return (int)lrintf(value); +# endif +#else + /* it's ok if round does not comply with IEEE754 standard; + the tests should allow +/-1 difference when the tested functions use round */ + return (int)(value + (value >= 0 ? 0.5f : -0.5f)); +#endif +} + +/** @overload */ +CV_INLINE int cvRound( int value ) +{ + return value; +} + +/** @overload */ +CV_INLINE int cvFloor( float value ) +{ + int i = (int)value; + return i - (i > value); +} + +/** @overload */ +CV_INLINE int cvFloor( int value ) +{ + return value; +} + +/** @overload */ +CV_INLINE int cvCeil( float value ) +{ + int i = (int)value; + return i + (i < value); +} + +/** @overload */ +CV_INLINE int cvCeil( int value ) +{ + return value; +} + +/** @overload */ +CV_INLINE int cvIsNaN( float value ) +{ + Cv32suf ieee754; + ieee754.f = value; + return (ieee754.u & 0x7fffffff) > 0x7f800000; +} + +/** @overload */ +CV_INLINE int cvIsInf( float value ) +{ + Cv32suf ieee754; + ieee754.f = value; + return (ieee754.u & 0x7fffffff) == 0x7f800000; +} + +#endif // __cplusplus + +//! @} core_utils + +#endif diff --git a/include/opencv2/core/hal/hal.hpp b/include/opencv2/core/hal/hal.hpp new file mode 100644 index 0000000..68900ec --- /dev/null +++ b/include/opencv2/core/hal/hal.hpp @@ -0,0 +1,250 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HAL_HPP +#define OPENCV_HAL_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/hal/interface.h" + +namespace cv { namespace hal { + +//! @addtogroup core_hal_functions +//! @{ + +CV_EXPORTS int normHamming(const uchar* a, int n); +CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n); + +CV_EXPORTS int normHamming(const uchar* a, int n, int cellSize); +CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize); + +CV_EXPORTS int LU32f(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS int LU64f(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky32f(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky64f(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS void SVD32f(float* At, size_t astep, float* W, float* U, size_t ustep, float* Vt, size_t vstep, int m, int n, int flags); +CV_EXPORTS void SVD64f(double* At, size_t astep, double* W, double* U, size_t ustep, double* Vt, size_t vstep, int m, int n, int flags); +CV_EXPORTS int QR32f(float* A, size_t astep, int m, int n, int k, float* b, size_t bstep, float* hFactors); +CV_EXPORTS int QR64f(double* A, size_t astep, int m, int n, int k, double* b, size_t bstep, double* hFactors); + +CV_EXPORTS void gemm32f(const float* src1, size_t src1_step, const float* src2, size_t src2_step, + float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm64f(const double* src1, size_t src1_step, const double* src2, size_t src2_step, + double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm32fc(const float* src1, size_t src1_step, const float* src2, size_t src2_step, + float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm64fc(const double* src1, size_t src1_step, const double* src2, size_t src2_step, + double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); + +CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n); +CV_EXPORTS float normL1_(const float* a, const float* b, int n); +CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n); + +CV_EXPORTS void exp32f(const float* src, float* dst, int n); +CV_EXPORTS void exp64f(const double* src, double* dst, int n); +CV_EXPORTS void log32f(const float* src, float* dst, int n); +CV_EXPORTS void log64f(const double* src, double* dst, int n); + +CV_EXPORTS void fastAtan32f(const float* y, const float* x, float* dst, int n, bool angleInDegrees); +CV_EXPORTS void fastAtan64f(const double* y, const double* x, double* dst, int n, bool angleInDegrees); +CV_EXPORTS void magnitude32f(const float* x, const float* y, float* dst, int n); +CV_EXPORTS void magnitude64f(const double* x, const double* y, double* dst, int n); +CV_EXPORTS void sqrt32f(const float* src, float* dst, int len); +CV_EXPORTS void sqrt64f(const double* src, double* dst, int len); +CV_EXPORTS void invSqrt32f(const float* src, float* dst, int len); +CV_EXPORTS void invSqrt64f(const double* src, double* dst, int len); + +CV_EXPORTS void split8u(const uchar* src, uchar** dst, int len, int cn ); +CV_EXPORTS void split16u(const ushort* src, ushort** dst, int len, int cn ); +CV_EXPORTS void split32s(const int* src, int** dst, int len, int cn ); +CV_EXPORTS void split64s(const int64* src, int64** dst, int len, int cn ); + +CV_EXPORTS void merge8u(const uchar** src, uchar* dst, int len, int cn ); +CV_EXPORTS void merge16u(const ushort** src, ushort* dst, int len, int cn ); +CV_EXPORTS void merge32s(const int** src, int* dst, int len, int cn ); +CV_EXPORTS void merge64s(const int64** src, int64* dst, int len, int cn ); + +CV_EXPORTS void add8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void sub8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void max8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void min8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void absdiff8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void and8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void or8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void xor8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void not8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp8s(const schar* src1, size_t step1, const schar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp16s(const short* src1, size_t step1, const short* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp32s(const int* src1, size_t step1, const int* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp32f(const float* src1, size_t step1, const float* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp64f(const double* src1, size_t step1, const double* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); + +CV_EXPORTS void mul8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); + +CV_EXPORTS void div8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); + +CV_EXPORTS void recip8u( const uchar *, size_t, const uchar * src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip8s( const schar *, size_t, const schar * src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip16u( const ushort *, size_t, const ushort * src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip16s( const short *, size_t, const short * src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip32s( const int *, size_t, const int * src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip32f( const float *, size_t, const float * src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip64f( const double *, size_t, const double * src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); + +CV_EXPORTS void addWeighted8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _scalars ); +CV_EXPORTS void addWeighted8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scalars ); + +struct CV_EXPORTS DFT1D +{ + static Ptr<DFT1D> create(int len, int count, int depth, int flags, bool * useBuffer = 0); + virtual void apply(const uchar *src, uchar *dst) = 0; + virtual ~DFT1D() {} +}; + +struct CV_EXPORTS DFT2D +{ + static Ptr<DFT2D> create(int width, int height, int depth, + int src_channels, int dst_channels, + int flags, int nonzero_rows = 0); + virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0; + virtual ~DFT2D() {} +}; + +struct CV_EXPORTS DCT2D +{ + static Ptr<DCT2D> create(int width, int height, int depth, int flags); + virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0; + virtual ~DCT2D() {} +}; + +//! @} core_hal + +//============================================================================= +// for binary compatibility with 3.0 + +//! @cond IGNORED + +CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); + +CV_EXPORTS void exp(const float* src, float* dst, int n); +CV_EXPORTS void exp(const double* src, double* dst, int n); +CV_EXPORTS void log(const float* src, float* dst, int n); +CV_EXPORTS void log(const double* src, double* dst, int n); + +CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees); +CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n); +CV_EXPORTS void magnitude(const double* x, const double* y, double* dst, int n); +CV_EXPORTS void sqrt(const float* src, float* dst, int len); +CV_EXPORTS void sqrt(const double* src, double* dst, int len); +CV_EXPORTS void invSqrt(const float* src, float* dst, int len); +CV_EXPORTS void invSqrt(const double* src, double* dst, int len); + +//! @endcond + +}} //cv::hal + +#endif //OPENCV_HAL_HPP diff --git a/include/opencv2/core/hal/interface.h b/include/opencv2/core/hal/interface.h new file mode 100644 index 0000000..8f64025 --- /dev/null +++ b/include/opencv2/core/hal/interface.h @@ -0,0 +1,182 @@ +#ifndef OPENCV_CORE_HAL_INTERFACE_H +#define OPENCV_CORE_HAL_INTERFACE_H + +//! @addtogroup core_hal_interface +//! @{ + +//! @name Return codes +//! @{ +#define CV_HAL_ERROR_OK 0 +#define CV_HAL_ERROR_NOT_IMPLEMENTED 1 +#define CV_HAL_ERROR_UNKNOWN -1 +//! @} + +#ifdef __cplusplus +#include <cstddef> +#else +#include <stddef.h> +#include <stdbool.h> +#endif + +//! @name Data types +//! primitive types +//! - schar - signed 1 byte integer +//! - uchar - unsigned 1 byte integer +//! - short - signed 2 byte integer +//! - ushort - unsigned 2 byte integer +//! - int - signed 4 byte integer +//! - uint - unsigned 4 byte integer +//! - int64 - signed 8 byte integer +//! - uint64 - unsigned 8 byte integer +//! @{ +#if !defined _MSC_VER && !defined __BORLANDC__ +# if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ +# include <cstdint> +# ifdef __NEWLIB__ + typedef unsigned int uint; +# else + typedef std::uint32_t uint; +# endif +# else +# include <stdint.h> + typedef uint32_t uint; +# endif +#else + typedef unsigned uint; +#endif + +typedef signed char schar; + +#ifndef __IPL_H__ + typedef unsigned char uchar; + typedef unsigned short ushort; +#endif + +#if defined _MSC_VER || defined __BORLANDC__ + typedef __int64 int64; + typedef unsigned __int64 uint64; +# define CV_BIG_INT(n) n##I64 +# define CV_BIG_UINT(n) n##UI64 +#else + typedef int64_t int64; + typedef uint64_t uint64; +# define CV_BIG_INT(n) n##LL +# define CV_BIG_UINT(n) n##ULL +#endif + +#define CV_CN_MAX 512 +#define CV_CN_SHIFT 3 +#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) + +#define CV_8U 0 +#define CV_8S 1 +#define CV_16U 2 +#define CV_16S 3 +#define CV_32S 4 +#define CV_32F 5 +#define CV_64F 6 +#define CV_USRTYPE1 7 + +#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) +#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) + +#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) +#define CV_MAKE_TYPE CV_MAKETYPE + +#define CV_8UC1 CV_MAKETYPE(CV_8U,1) +#define CV_8UC2 CV_MAKETYPE(CV_8U,2) +#define CV_8UC3 CV_MAKETYPE(CV_8U,3) +#define CV_8UC4 CV_MAKETYPE(CV_8U,4) +#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) + +#define CV_8SC1 CV_MAKETYPE(CV_8S,1) +#define CV_8SC2 CV_MAKETYPE(CV_8S,2) +#define CV_8SC3 CV_MAKETYPE(CV_8S,3) +#define CV_8SC4 CV_MAKETYPE(CV_8S,4) +#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) + +#define CV_16UC1 CV_MAKETYPE(CV_16U,1) +#define CV_16UC2 CV_MAKETYPE(CV_16U,2) +#define CV_16UC3 CV_MAKETYPE(CV_16U,3) +#define CV_16UC4 CV_MAKETYPE(CV_16U,4) +#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) + +#define CV_16SC1 CV_MAKETYPE(CV_16S,1) +#define CV_16SC2 CV_MAKETYPE(CV_16S,2) +#define CV_16SC3 CV_MAKETYPE(CV_16S,3) +#define CV_16SC4 CV_MAKETYPE(CV_16S,4) +#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) + +#define CV_32SC1 CV_MAKETYPE(CV_32S,1) +#define CV_32SC2 CV_MAKETYPE(CV_32S,2) +#define CV_32SC3 CV_MAKETYPE(CV_32S,3) +#define CV_32SC4 CV_MAKETYPE(CV_32S,4) +#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) + +#define CV_32FC1 CV_MAKETYPE(CV_32F,1) +#define CV_32FC2 CV_MAKETYPE(CV_32F,2) +#define CV_32FC3 CV_MAKETYPE(CV_32F,3) +#define CV_32FC4 CV_MAKETYPE(CV_32F,4) +#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) + +#define CV_64FC1 CV_MAKETYPE(CV_64F,1) +#define CV_64FC2 CV_MAKETYPE(CV_64F,2) +#define CV_64FC3 CV_MAKETYPE(CV_64F,3) +#define CV_64FC4 CV_MAKETYPE(CV_64F,4) +#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) +//! @} + +//! @name Comparison operation +//! @sa cv::CmpTypes +//! @{ +#define CV_HAL_CMP_EQ 0 +#define CV_HAL_CMP_GT 1 +#define CV_HAL_CMP_GE 2 +#define CV_HAL_CMP_LT 3 +#define CV_HAL_CMP_LE 4 +#define CV_HAL_CMP_NE 5 +//! @} + +//! @name Border processing modes +//! @sa cv::BorderTypes +//! @{ +#define CV_HAL_BORDER_CONSTANT 0 +#define CV_HAL_BORDER_REPLICATE 1 +#define CV_HAL_BORDER_REFLECT 2 +#define CV_HAL_BORDER_WRAP 3 +#define CV_HAL_BORDER_REFLECT_101 4 +#define CV_HAL_BORDER_TRANSPARENT 5 +#define CV_HAL_BORDER_ISOLATED 16 +//! @} + +//! @name DFT flags +//! @{ +#define CV_HAL_DFT_INVERSE 1 +#define CV_HAL_DFT_SCALE 2 +#define CV_HAL_DFT_ROWS 4 +#define CV_HAL_DFT_COMPLEX_OUTPUT 16 +#define CV_HAL_DFT_REAL_OUTPUT 32 +#define CV_HAL_DFT_TWO_STAGE 64 +#define CV_HAL_DFT_STAGE_COLS 128 +#define CV_HAL_DFT_IS_CONTINUOUS 512 +#define CV_HAL_DFT_IS_INPLACE 1024 +//! @} + +//! @name SVD flags +//! @{ +#define CV_HAL_SVD_NO_UV 1 +#define CV_HAL_SVD_SHORT_UV 2 +#define CV_HAL_SVD_MODIFY_A 4 +#define CV_HAL_SVD_FULL_UV 8 +//! @} + +//! @name Gemm flags +//! @{ +#define CV_HAL_GEMM_1_T 1 +#define CV_HAL_GEMM_2_T 2 +#define CV_HAL_GEMM_3_T 4 +//! @} + +//! @} + +#endif diff --git a/include/opencv2/core/hal/intrin.hpp b/include/opencv2/core/hal/intrin.hpp new file mode 100644 index 0000000..460c5c5 --- /dev/null +++ b/include/opencv2/core/hal/intrin.hpp @@ -0,0 +1,429 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HAL_INTRIN_HPP +#define OPENCV_HAL_INTRIN_HPP + +#include <cmath> +#include <float.h> +#include <stdlib.h> +#include "opencv2/core/cvdef.h" + +#define OPENCV_HAL_ADD(a, b) ((a) + (b)) +#define OPENCV_HAL_AND(a, b) ((a) & (b)) +#define OPENCV_HAL_NOP(a) (a) +#define OPENCV_HAL_1ST(a, b) (a) + +// unlike HAL API, which is in cv::hal, +// we put intrinsics into cv namespace to make its +// access from within opencv code more accessible +namespace cv { + +namespace hal { + +enum StoreMode +{ + STORE_UNALIGNED = 0, + STORE_ALIGNED = 1, + STORE_ALIGNED_NOCACHE = 2 +}; + +} + +template<typename _Tp> struct V_TypeTraits +{ +}; + +#define CV_INTRIN_DEF_TYPE_TRAITS(type, int_type_, uint_type_, abs_type_, w_type_, q_type_, sum_type_, nlanes128_) \ + template<> struct V_TypeTraits<type> \ + { \ + typedef type value_type; \ + typedef int_type_ int_type; \ + typedef abs_type_ abs_type; \ + typedef uint_type_ uint_type; \ + typedef w_type_ w_type; \ + typedef q_type_ q_type; \ + typedef sum_type_ sum_type; \ + enum { nlanes128 = nlanes128_ }; \ + \ + static inline int_type reinterpret_int(type x) \ + { \ + union { type l; int_type i; } v; \ + v.l = x; \ + return v.i; \ + } \ + \ + static inline type reinterpret_from_int(int_type x) \ + { \ + union { type l; int_type i; } v; \ + v.i = x; \ + return v.l; \ + } \ + } + +CV_INTRIN_DEF_TYPE_TRAITS(uchar, schar, uchar, uchar, ushort, unsigned, unsigned, 16); +CV_INTRIN_DEF_TYPE_TRAITS(schar, schar, uchar, uchar, short, int, int, 16); +CV_INTRIN_DEF_TYPE_TRAITS(ushort, short, ushort, ushort, unsigned, uint64, unsigned, 8); +CV_INTRIN_DEF_TYPE_TRAITS(short, short, ushort, ushort, int, int64, int, 8); +CV_INTRIN_DEF_TYPE_TRAITS(unsigned, int, unsigned, unsigned, uint64, void, unsigned, 4); +CV_INTRIN_DEF_TYPE_TRAITS(int, int, unsigned, unsigned, int64, void, int, 4); +CV_INTRIN_DEF_TYPE_TRAITS(float, int, unsigned, float, double, void, float, 4); +CV_INTRIN_DEF_TYPE_TRAITS(uint64, int64, uint64, uint64, void, void, uint64, 2); +CV_INTRIN_DEF_TYPE_TRAITS(int64, int64, uint64, uint64, void, void, int64, 2); +CV_INTRIN_DEF_TYPE_TRAITS(double, int64, uint64, double, void, void, double, 2); + +#ifndef CV_DOXYGEN + +#ifdef CV_CPU_DISPATCH_MODE + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) { + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END } +#else + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE hal_baseline + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace hal_baseline { + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END } +#endif + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; +#endif +} + +#ifdef CV_DOXYGEN +# undef CV_AVX2 +# undef CV_SSE2 +# undef CV_NEON +# undef CV_VSX +# undef CV_FP16 +#endif + +#if CV_SSE2 || CV_NEON || CV_VSX +#define CV__SIMD_FORWARD 128 +#include "opencv2/core/hal/intrin_forward.hpp" +#endif + +#if CV_SSE2 + +#include "opencv2/core/hal/intrin_sse_em.hpp" +#include "opencv2/core/hal/intrin_sse.hpp" + +#elif CV_NEON + +#include "opencv2/core/hal/intrin_neon.hpp" + +#elif CV_VSX + +#include "opencv2/core/hal/intrin_vsx.hpp" + +#else + +#define CV_SIMD128_CPP 1 +#include "opencv2/core/hal/intrin_cpp.hpp" + +#endif + +// AVX2 can be used together with SSE2, so +// we define those two sets of intrinsics at once. +// Most of the intrinsics do not conflict (the proper overloaded variant is +// resolved by the argument types, e.g. v_float32x4 ~ SSE2, v_float32x8 ~ AVX2), +// but some of AVX2 intrinsics get v256_ prefix instead of v_, e.g. v256_load() vs v_load(). +// Correspondingly, the wide intrinsics (which are mapped to the "widest" +// available instruction set) will get vx_ prefix +// (and will be mapped to v256_ counterparts) (e.g. vx_load() => v256_load()) +#if CV_AVX2 + +#define CV__SIMD_FORWARD 256 +#include "opencv2/core/hal/intrin_forward.hpp" +#include "opencv2/core/hal/intrin_avx.hpp" + +#endif + +//! @cond IGNORED + +namespace cv { + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + +#ifndef CV_SIMD128 +#define CV_SIMD128 0 +#endif + +#ifndef CV_SIMD128_64F +#define CV_SIMD128_64F 0 +#endif + +#ifndef CV_SIMD256 +#define CV_SIMD256 0 +#endif + +#ifndef CV_SIMD256_64F +#define CV_SIMD256_64F 0 +#endif + +#ifndef CV_SIMD512 +#define CV_SIMD512 0 +#endif + +#ifndef CV_SIMD512_64F +#define CV_SIMD512_64F 0 +#endif + +#ifndef CV_SIMD128_FP16 +#define CV_SIMD128_FP16 0 +#endif + +#ifndef CV_SIMD256_FP16 +#define CV_SIMD256_FP16 0 +#endif + +#ifndef CV_SIMD512_FP16 +#define CV_SIMD512_FP16 0 +#endif + +//================================================================================================== + +#define CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ + inline vtyp vx_setall_##short_typ(typ v) { return prefix##_setall_##short_typ(v); } \ + inline vtyp vx_setzero_##short_typ() { return prefix##_setzero_##short_typ(); } \ + inline vtyp vx_##loadsfx(const typ* ptr) { return prefix##_##loadsfx(ptr); } \ + inline vtyp vx_##loadsfx##_aligned(const typ* ptr) { return prefix##_##loadsfx##_aligned(ptr); } \ + inline vtyp vx_##loadsfx##_low(const typ* ptr) { return prefix##_##loadsfx##_low(ptr); } \ + inline vtyp vx_##loadsfx##_halves(const typ* ptr0, const typ* ptr1) { return prefix##_##loadsfx##_halves(ptr0, ptr1); } \ + inline void vx_store(typ* ptr, const vtyp& v) { return v_store(ptr, v); } \ + inline void vx_store_aligned(typ* ptr, const vtyp& v) { return v_store_aligned(ptr, v); } \ + inline vtyp vx_lut(const typ* ptr, const int* idx) { return prefix##_lut(ptr, idx); } \ + inline vtyp vx_lut_pairs(const typ* ptr, const int* idx) { return prefix##_lut_pairs(ptr, idx); } + +#define CV_INTRIN_DEFINE_WIDE_LUT_QUAD(typ, vtyp, prefix) \ + inline vtyp vx_lut_quads(const typ* ptr, const int* idx) { return prefix##_lut_quads(ptr, idx); } + +#define CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(typ, wtyp, prefix) \ + inline wtyp vx_load_expand(const typ* ptr) { return prefix##_load_expand(ptr); } + +#define CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND_Q(typ, qtyp, prefix) \ + inline qtyp vx_load_expand_q(const typ* ptr) { return prefix##_load_expand_q(ptr); } + +#define CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(typ, vtyp, short_typ, wtyp, qtyp, prefix, loadsfx) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(typ, vtyp, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(typ, wtyp, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND_Q(typ, qtyp, prefix) + +#define CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(uchar, v_uint8, u8, v_uint16, v_uint32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(schar, v_int8, s8, v_int16, v_int32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(ushort, v_uint16, u16, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(ushort, v_uint16, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(ushort, v_uint32, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(short, v_int16, s16, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(short, v_int16, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(short, v_int32, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(int, v_int32, s32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(int, v_int32, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(int, v_int64, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(unsigned, v_uint32, u32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(unsigned, v_uint32, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(unsigned, v_uint64, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(float, v_float32, f32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(float, v_float32, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(int64, v_int64, s64, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(uint64, v_uint64, u64, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(float16_t, v_float32, prefix) + +template<typename _Tp> struct V_RegTraits +{ +}; + +#define CV_DEF_REG_TRAITS(prefix, _reg, lane_type, suffix, _u_reg, _w_reg, _q_reg, _int_reg, _round_reg) \ + template<> struct V_RegTraits<_reg> \ + { \ + typedef _reg reg; \ + typedef _u_reg u_reg; \ + typedef _w_reg w_reg; \ + typedef _q_reg q_reg; \ + typedef _int_reg int_reg; \ + typedef _round_reg round_reg; \ + } + +#if CV_SIMD128 || CV_SIMD128_CPP + CV_DEF_REG_TRAITS(v, v_uint8x16, uchar, u8, v_uint8x16, v_uint16x8, v_uint32x4, v_int8x16, void); + CV_DEF_REG_TRAITS(v, v_int8x16, schar, s8, v_uint8x16, v_int16x8, v_int32x4, v_int8x16, void); + CV_DEF_REG_TRAITS(v, v_uint16x8, ushort, u16, v_uint16x8, v_uint32x4, v_uint64x2, v_int16x8, void); + CV_DEF_REG_TRAITS(v, v_int16x8, short, s16, v_uint16x8, v_int32x4, v_int64x2, v_int16x8, void); + CV_DEF_REG_TRAITS(v, v_uint32x4, unsigned, u32, v_uint32x4, v_uint64x2, void, v_int32x4, void); + CV_DEF_REG_TRAITS(v, v_int32x4, int, s32, v_uint32x4, v_int64x2, void, v_int32x4, void); +#if CV_SIMD128_64F + CV_DEF_REG_TRAITS(v, v_float32x4, float, f32, v_float32x4, v_float64x2, void, v_int32x4, v_int32x4); +#else + CV_DEF_REG_TRAITS(v, v_float32x4, float, f32, v_float32x4, void, void, v_int32x4, v_int32x4); +#endif + CV_DEF_REG_TRAITS(v, v_uint64x2, uint64, u64, v_uint64x2, void, void, v_int64x2, void); + CV_DEF_REG_TRAITS(v, v_int64x2, int64, s64, v_uint64x2, void, void, v_int64x2, void); +#if CV_SIMD128_64F + CV_DEF_REG_TRAITS(v, v_float64x2, double, f64, v_float64x2, void, void, v_int64x2, v_int32x4); +#endif +#endif + +#if CV_SIMD256 + CV_DEF_REG_TRAITS(v256, v_uint8x32, uchar, u8, v_uint8x32, v_uint16x16, v_uint32x8, v_int8x32, void); + CV_DEF_REG_TRAITS(v256, v_int8x32, schar, s8, v_uint8x32, v_int16x16, v_int32x8, v_int8x32, void); + CV_DEF_REG_TRAITS(v256, v_uint16x16, ushort, u16, v_uint16x16, v_uint32x8, v_uint64x4, v_int16x16, void); + CV_DEF_REG_TRAITS(v256, v_int16x16, short, s16, v_uint16x16, v_int32x8, v_int64x4, v_int16x16, void); + CV_DEF_REG_TRAITS(v256, v_uint32x8, unsigned, u32, v_uint32x8, v_uint64x4, void, v_int32x8, void); + CV_DEF_REG_TRAITS(v256, v_int32x8, int, s32, v_uint32x8, v_int64x4, void, v_int32x8, void); + CV_DEF_REG_TRAITS(v256, v_float32x8, float, f32, v_float32x8, v_float64x4, void, v_int32x8, v_int32x8); + CV_DEF_REG_TRAITS(v256, v_uint64x4, uint64, u64, v_uint64x4, void, void, v_int64x4, void); + CV_DEF_REG_TRAITS(v256, v_int64x4, int64, s64, v_uint64x4, void, void, v_int64x4, void); + CV_DEF_REG_TRAITS(v256, v_float64x4, double, f64, v_float64x4, void, void, v_int64x4, v_int32x8); +#endif + +#if CV_SIMD512 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 512) +#define CV__SIMD_NAMESPACE simd512 +namespace CV__SIMD_NAMESPACE { + #define CV_SIMD 1 + #define CV_SIMD_64F CV_SIMD512_64F + #define CV_SIMD_WIDTH 64 + // TODO typedef v_uint8 / v_int32 / etc types here +} // namespace +using namespace CV__SIMD_NAMESPACE; +#elif CV_SIMD256 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 256) +#define CV__SIMD_NAMESPACE simd256 +namespace CV__SIMD_NAMESPACE { + #define CV_SIMD 1 + #define CV_SIMD_64F CV_SIMD256_64F + #define CV_SIMD_FP16 CV_SIMD256_FP16 + #define CV_SIMD_WIDTH 32 + typedef v_uint8x32 v_uint8; + typedef v_int8x32 v_int8; + typedef v_uint16x16 v_uint16; + typedef v_int16x16 v_int16; + typedef v_uint32x8 v_uint32; + typedef v_int32x8 v_int32; + typedef v_uint64x4 v_uint64; + typedef v_int64x4 v_int64; + typedef v_float32x8 v_float32; + CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v256) + #if CV_SIMD256_64F + typedef v_float64x4 v_float64; + CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v256, load) + #endif + inline void vx_cleanup() { v256_cleanup(); } +} // namespace +using namespace CV__SIMD_NAMESPACE; +#elif (CV_SIMD128 || CV_SIMD128_CPP) && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 128) +#define CV__SIMD_NAMESPACE simd128 +namespace CV__SIMD_NAMESPACE { + #define CV_SIMD CV_SIMD128 + #define CV_SIMD_64F CV_SIMD128_64F + #define CV_SIMD_WIDTH 16 + typedef v_uint8x16 v_uint8; + typedef v_int8x16 v_int8; + typedef v_uint16x8 v_uint16; + typedef v_int16x8 v_int16; + typedef v_uint32x4 v_uint32; + typedef v_int32x4 v_int32; + typedef v_uint64x2 v_uint64; + typedef v_int64x2 v_int64; + typedef v_float32x4 v_float32; + CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v) + #if CV_SIMD128_64F + typedef v_float64x2 v_float64; + CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v, load) + #endif + inline void vx_cleanup() { v_cleanup(); } +} // namespace +using namespace CV__SIMD_NAMESPACE; +#endif + +inline unsigned int trailingZeros32(unsigned int value) { +#if defined(_MSC_VER) +#if (_MSC_VER < 1700) || defined(_M_ARM) + unsigned long index = 0; + _BitScanForward(&index, value); + return (unsigned int)index; +#elif defined(__clang__) + // clang-cl doesn't export _tzcnt_u32 for non BMI systems + return value ? __builtin_ctz(value) : 32; +#else + return _tzcnt_u32(value); +#endif +#elif defined(__GNUC__) || defined(__GNUG__) + return __builtin_ctz(value); +#elif defined(__ICC) || defined(__INTEL_COMPILER) + return _bit_scan_forward(value); +#elif defined(__clang__) + return llvm.cttz.i32(value, true); +#else + static const int MultiplyDeBruijnBitPosition[32] = { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; + return MultiplyDeBruijnBitPosition[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; +#endif +} + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif + +#ifndef CV_SIMD_64F +#define CV_SIMD_64F 0 +#endif + +#ifndef CV_SIMD_FP16 +#define CV_SIMD_FP16 0 //!< Defined to 1 on native support of operations with float16x8_t / float16x16_t (SIMD256) types +#endif + + +#ifndef CV_SIMD +#define CV_SIMD 0 +#endif + +} // cv:: + +//! @endcond + +#endif diff --git a/include/opencv2/core/hal/intrin_avx.hpp b/include/opencv2/core/hal/intrin_avx.hpp new file mode 100644 index 0000000..58db714 --- /dev/null +++ b/include/opencv2/core/hal/intrin_avx.hpp @@ -0,0 +1,2772 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_INTRIN_AVX_HPP +#define OPENCV_HAL_INTRIN_AVX_HPP + +#define CV_SIMD256 1 +#define CV_SIMD256_64F 1 +#define CV_SIMD256_FP16 0 // no native operations with FP16 type. Only load/store from float32x8 are available (if CV_FP16 == 1) + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Utils //////////// + +inline __m256i _v256_combine(const __m128i& lo, const __m128i& hi) +{ return _mm256_inserti128_si256(_mm256_castsi128_si256(lo), hi, 1); } + +inline __m256 _v256_combine(const __m128& lo, const __m128& hi) +{ return _mm256_insertf128_ps(_mm256_castps128_ps256(lo), hi, 1); } + +inline __m256d _v256_combine(const __m128d& lo, const __m128d& hi) +{ return _mm256_insertf128_pd(_mm256_castpd128_pd256(lo), hi, 1); } + +inline int _v_cvtsi256_si32(const __m256i& a) +{ return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); } + +inline __m256i _v256_shuffle_odd_64(const __m256i& v) +{ return _mm256_permute4x64_epi64(v, _MM_SHUFFLE(3, 1, 2, 0)); } + +inline __m256d _v256_shuffle_odd_64(const __m256d& v) +{ return _mm256_permute4x64_pd(v, _MM_SHUFFLE(3, 1, 2, 0)); } + +template<int imm> +inline __m256i _v256_permute2x128(const __m256i& a, const __m256i& b) +{ return _mm256_permute2x128_si256(a, b, imm); } + +template<int imm> +inline __m256 _v256_permute2x128(const __m256& a, const __m256& b) +{ return _mm256_permute2f128_ps(a, b, imm); } + +template<int imm> +inline __m256d _v256_permute2x128(const __m256d& a, const __m256d& b) +{ return _mm256_permute2f128_pd(a, b, imm); } + +template<int imm, typename _Tpvec> +inline _Tpvec v256_permute2x128(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(_v256_permute2x128<imm>(a.val, b.val)); } + +template<int imm> +inline __m256i _v256_permute4x64(const __m256i& a) +{ return _mm256_permute4x64_epi64(a, imm); } + +template<int imm> +inline __m256d _v256_permute4x64(const __m256d& a) +{ return _mm256_permute4x64_pd(a, imm); } + +template<int imm, typename _Tpvec> +inline _Tpvec v256_permute4x64(const _Tpvec& a) +{ return _Tpvec(_v256_permute4x64<imm>(a.val)); } + +inline __m128i _v256_extract_high(const __m256i& v) +{ return _mm256_extracti128_si256(v, 1); } + +inline __m128 _v256_extract_high(const __m256& v) +{ return _mm256_extractf128_ps(v, 1); } + +inline __m128d _v256_extract_high(const __m256d& v) +{ return _mm256_extractf128_pd(v, 1); } + +inline __m128i _v256_extract_low(const __m256i& v) +{ return _mm256_castsi256_si128(v); } + +inline __m128 _v256_extract_low(const __m256& v) +{ return _mm256_castps256_ps128(v); } + +inline __m128d _v256_extract_low(const __m256d& v) +{ return _mm256_castpd256_pd128(v); } + +inline __m256i _v256_packs_epu32(const __m256i& a, const __m256i& b) +{ + const __m256i m = _mm256_set1_epi32(65535); + __m256i am = _mm256_min_epu32(a, m); + __m256i bm = _mm256_min_epu32(b, m); + return _mm256_packus_epi32(am, bm); +} + +///////// Types //////////// + +struct v_uint8x32 +{ + typedef uchar lane_type; + enum { nlanes = 32 }; + __m256i val; + + explicit v_uint8x32(__m256i v) : val(v) {} + v_uint8x32(uchar v0, uchar v1, uchar v2, uchar v3, + uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, + uchar v12, uchar v13, uchar v14, uchar v15, + uchar v16, uchar v17, uchar v18, uchar v19, + uchar v20, uchar v21, uchar v22, uchar v23, + uchar v24, uchar v25, uchar v26, uchar v27, + uchar v28, uchar v29, uchar v30, uchar v31) + { + val = _mm256_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, + (char)v4, (char)v5, (char)v6 , (char)v7, (char)v8, (char)v9, + (char)v10, (char)v11, (char)v12, (char)v13, (char)v14, (char)v15, + (char)v16, (char)v17, (char)v18, (char)v19, (char)v20, (char)v21, + (char)v22, (char)v23, (char)v24, (char)v25, (char)v26, (char)v27, + (char)v28, (char)v29, (char)v30, (char)v31); + } + v_uint8x32() : val(_mm256_setzero_si256()) {} + uchar get0() const { return (uchar)_v_cvtsi256_si32(val); } +}; + +struct v_int8x32 +{ + typedef schar lane_type; + enum { nlanes = 32 }; + __m256i val; + + explicit v_int8x32(__m256i v) : val(v) {} + v_int8x32(schar v0, schar v1, schar v2, schar v3, + schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, + schar v12, schar v13, schar v14, schar v15, + schar v16, schar v17, schar v18, schar v19, + schar v20, schar v21, schar v22, schar v23, + schar v24, schar v25, schar v26, schar v27, + schar v28, schar v29, schar v30, schar v31) + { + val = _mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, + v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, + v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31); + } + v_int8x32() : val(_mm256_setzero_si256()) {} + schar get0() const { return (schar)_v_cvtsi256_si32(val); } +}; + +struct v_uint16x16 +{ + typedef ushort lane_type; + enum { nlanes = 16 }; + __m256i val; + + explicit v_uint16x16(__m256i v) : val(v) {} + v_uint16x16(ushort v0, ushort v1, ushort v2, ushort v3, + ushort v4, ushort v5, ushort v6, ushort v7, + ushort v8, ushort v9, ushort v10, ushort v11, + ushort v12, ushort v13, ushort v14, ushort v15) + { + val = _mm256_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, + (short)v4, (short)v5, (short)v6, (short)v7, (short)v8, (short)v9, + (short)v10, (short)v11, (short)v12, (short)v13, (short)v14, (short)v15); + } + v_uint16x16() : val(_mm256_setzero_si256()) {} + ushort get0() const { return (ushort)_v_cvtsi256_si32(val); } +}; + +struct v_int16x16 +{ + typedef short lane_type; + enum { nlanes = 16 }; + __m256i val; + + explicit v_int16x16(__m256i v) : val(v) {} + v_int16x16(short v0, short v1, short v2, short v3, + short v4, short v5, short v6, short v7, + short v8, short v9, short v10, short v11, + short v12, short v13, short v14, short v15) + { + val = _mm256_setr_epi16(v0, v1, v2, v3, v4, v5, v6, v7, + v8, v9, v10, v11, v12, v13, v14, v15); + } + v_int16x16() : val(_mm256_setzero_si256()) {} + short get0() const { return (short)_v_cvtsi256_si32(val); } +}; + +struct v_uint32x8 +{ + typedef unsigned lane_type; + enum { nlanes = 8 }; + __m256i val; + + explicit v_uint32x8(__m256i v) : val(v) {} + v_uint32x8(unsigned v0, unsigned v1, unsigned v2, unsigned v3, + unsigned v4, unsigned v5, unsigned v6, unsigned v7) + { + val = _mm256_setr_epi32((unsigned)v0, (unsigned)v1, (unsigned)v2, + (unsigned)v3, (unsigned)v4, (unsigned)v5, (unsigned)v6, (unsigned)v7); + } + v_uint32x8() : val(_mm256_setzero_si256()) {} + unsigned get0() const { return (unsigned)_v_cvtsi256_si32(val); } +}; + +struct v_int32x8 +{ + typedef int lane_type; + enum { nlanes = 8 }; + __m256i val; + + explicit v_int32x8(__m256i v) : val(v) {} + v_int32x8(int v0, int v1, int v2, int v3, + int v4, int v5, int v6, int v7) + { + val = _mm256_setr_epi32(v0, v1, v2, v3, v4, v5, v6, v7); + } + v_int32x8() : val(_mm256_setzero_si256()) {} + int get0() const { return _v_cvtsi256_si32(val); } +}; + +struct v_float32x8 +{ + typedef float lane_type; + enum { nlanes = 8 }; + __m256 val; + + explicit v_float32x8(__m256 v) : val(v) {} + v_float32x8(float v0, float v1, float v2, float v3, + float v4, float v5, float v6, float v7) + { + val = _mm256_setr_ps(v0, v1, v2, v3, v4, v5, v6, v7); + } + v_float32x8() : val(_mm256_setzero_ps()) {} + float get0() const { return _mm_cvtss_f32(_mm256_castps256_ps128(val)); } +}; + +struct v_uint64x4 +{ + typedef uint64 lane_type; + enum { nlanes = 4 }; + __m256i val; + + explicit v_uint64x4(__m256i v) : val(v) {} + v_uint64x4(uint64 v0, uint64 v1, uint64 v2, uint64 v3) + { val = _mm256_setr_epi64x((int64)v0, (int64)v1, (int64)v2, (int64)v3); } + v_uint64x4() : val(_mm256_setzero_si256()) {} + uint64 get0() const + { + #if defined __x86_64__ || defined _M_X64 + return (uint64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val)); + #else + int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val)); + int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32))); + return (unsigned)a | ((uint64)(unsigned)b << 32); + #endif + } +}; + +struct v_int64x4 +{ + typedef int64 lane_type; + enum { nlanes = 4 }; + __m256i val; + + explicit v_int64x4(__m256i v) : val(v) {} + v_int64x4(int64 v0, int64 v1, int64 v2, int64 v3) + { val = _mm256_setr_epi64x(v0, v1, v2, v3); } + v_int64x4() : val(_mm256_setzero_si256()) {} + + int64 get0() const + { + #if defined __x86_64__ || defined _M_X64 + return (int64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val)); + #else + int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val)); + int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32))); + return (int64)((unsigned)a | ((uint64)(unsigned)b << 32)); + #endif + } +}; + +struct v_float64x4 +{ + typedef double lane_type; + enum { nlanes = 4 }; + __m256d val; + + explicit v_float64x4(__m256d v) : val(v) {} + v_float64x4(double v0, double v1, double v2, double v3) + { val = _mm256_setr_pd(v0, v1, v2, v3); } + v_float64x4() : val(_mm256_setzero_pd()) {} + double get0() const { return _mm_cvtsd_f64(_mm256_castpd256_pd128(val)); } +}; + +//////////////// Load and store operations /////////////// + +#define OPENCV_HAL_IMPL_AVX_LOADSTORE(_Tpvec, _Tp) \ + inline _Tpvec v256_load(const _Tp* ptr) \ + { return _Tpvec(_mm256_loadu_si256((const __m256i*)ptr)); } \ + inline _Tpvec v256_load_aligned(const _Tp* ptr) \ + { return _Tpvec(_mm256_load_si256((const __m256i*)ptr)); } \ + inline _Tpvec v256_load_low(const _Tp* ptr) \ + { \ + __m128i v128 = _mm_loadu_si128((const __m128i*)ptr); \ + return _Tpvec(_mm256_castsi128_si256(v128)); \ + } \ + inline _Tpvec v256_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ + { \ + __m128i vlo = _mm_loadu_si128((const __m128i*)ptr0); \ + __m128i vhi = _mm_loadu_si128((const __m128i*)ptr1); \ + return _Tpvec(_v256_combine(vlo, vhi)); \ + } \ + inline void v_store(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_si256((__m256i*)ptr, a.val); } \ + inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ + { _mm256_store_si256((__m256i*)ptr, a.val); } \ + inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ + { _mm256_stream_si256((__m256i*)ptr, a.val); } \ + inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ + { \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm256_storeu_si256((__m256i*)ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm256_stream_si256((__m256i*)ptr, a.val); \ + else \ + _mm256_store_si256((__m256i*)ptr, a.val); \ + } \ + inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_si128((__m128i*)ptr, _v256_extract_low(a.val)); } \ + inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_si128((__m128i*)ptr, _v256_extract_high(a.val)); } + +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint8x32, uchar) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int8x32, schar) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint16x16, ushort) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int16x16, short) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint32x8, unsigned) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int32x8, int) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint64x4, uint64) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int64x4, int64) + +#define OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(_Tpvec, _Tp, suffix, halfreg) \ + inline _Tpvec v256_load(const _Tp* ptr) \ + { return _Tpvec(_mm256_loadu_##suffix(ptr)); } \ + inline _Tpvec v256_load_aligned(const _Tp* ptr) \ + { return _Tpvec(_mm256_load_##suffix(ptr)); } \ + inline _Tpvec v256_load_low(const _Tp* ptr) \ + { \ + return _Tpvec(_mm256_cast##suffix##128_##suffix##256 \ + (_mm_loadu_##suffix(ptr))); \ + } \ + inline _Tpvec v256_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ + { \ + halfreg vlo = _mm_loadu_##suffix(ptr0); \ + halfreg vhi = _mm_loadu_##suffix(ptr1); \ + return _Tpvec(_v256_combine(vlo, vhi)); \ + } \ + inline void v_store(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_##suffix(ptr, a.val); } \ + inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ + { _mm256_store_##suffix(ptr, a.val); } \ + inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ + { _mm256_stream_##suffix(ptr, a.val); } \ + inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ + { \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm256_storeu_##suffix(ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm256_stream_##suffix(ptr, a.val); \ + else \ + _mm256_store_##suffix(ptr, a.val); \ + } \ + inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_##suffix(ptr, _v256_extract_low(a.val)); } \ + inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_##suffix(ptr, _v256_extract_high(a.val)); } + +OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(v_float32x8, float, ps, __m128) +OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(v_float64x4, double, pd, __m128d) + +#define OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, _Tpvecf, suffix, cast) \ + inline _Tpvec v_reinterpret_as_##suffix(const _Tpvecf& a) \ + { return _Tpvec(cast(a.val)); } + +#define OPENCV_HAL_IMPL_AVX_INIT(_Tpvec, _Tp, suffix, ssuffix, ctype_s) \ + inline _Tpvec v256_setzero_##suffix() \ + { return _Tpvec(_mm256_setzero_si256()); } \ + inline _Tpvec v256_setall_##suffix(_Tp v) \ + { return _Tpvec(_mm256_set1_##ssuffix((ctype_s)v)); } \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint8x32, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int8x32, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint16x16, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int16x16, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint32x8, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int32x8, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint64x4, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int64x4, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_float32x8, suffix, _mm256_castps_si256) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_float64x4, suffix, _mm256_castpd_si256) + +OPENCV_HAL_IMPL_AVX_INIT(v_uint8x32, uchar, u8, epi8, char) +OPENCV_HAL_IMPL_AVX_INIT(v_int8x32, schar, s8, epi8, char) +OPENCV_HAL_IMPL_AVX_INIT(v_uint16x16, ushort, u16, epi16, short) +OPENCV_HAL_IMPL_AVX_INIT(v_int16x16, short, s16, epi16, short) +OPENCV_HAL_IMPL_AVX_INIT(v_uint32x8, unsigned, u32, epi32, int) +OPENCV_HAL_IMPL_AVX_INIT(v_int32x8, int, s32, epi32, int) +OPENCV_HAL_IMPL_AVX_INIT(v_uint64x4, uint64, u64, epi64x, int64) +OPENCV_HAL_IMPL_AVX_INIT(v_int64x4, int64, s64, epi64x, int64) + +#define OPENCV_HAL_IMPL_AVX_INIT_FLT(_Tpvec, _Tp, suffix, zsuffix, cast) \ + inline _Tpvec v256_setzero_##suffix() \ + { return _Tpvec(_mm256_setzero_##zsuffix()); } \ + inline _Tpvec v256_setall_##suffix(_Tp v) \ + { return _Tpvec(_mm256_set1_##zsuffix(v)); } \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint8x32, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int8x32, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint16x16, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int16x16, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint32x8, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int32x8, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint64x4, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int64x4, suffix, cast) + +OPENCV_HAL_IMPL_AVX_INIT_FLT(v_float32x8, float, f32, ps, _mm256_castsi256_ps) +OPENCV_HAL_IMPL_AVX_INIT_FLT(v_float64x4, double, f64, pd, _mm256_castsi256_pd) + +inline v_float32x8 v_reinterpret_as_f32(const v_float32x8& a) +{ return a; } +inline v_float32x8 v_reinterpret_as_f32(const v_float64x4& a) +{ return v_float32x8(_mm256_castpd_ps(a.val)); } + +inline v_float64x4 v_reinterpret_as_f64(const v_float64x4& a) +{ return a; } +inline v_float64x4 v_reinterpret_as_f64(const v_float32x8& a) +{ return v_float64x4(_mm256_castps_pd(a.val)); } + +#if CV_FP16 +inline v_float32x8 v256_load_fp16_f32(const short* ptr) +{ + return v_float32x8(_mm256_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr))); +} + +inline void v_store_fp16(short* ptr, const v_float32x8& a) +{ + __m128i fp16_value = _mm256_cvtps_ph(a.val, 0); + _mm_store_si128((__m128i*)ptr, fp16_value); +} +#endif + +/* Recombine */ +/*#define OPENCV_HAL_IMPL_AVX_COMBINE(_Tpvec, perm) \ + inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(perm(a.val, b.val, 0x20)); } \ + inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(perm(a.val, b.val, 0x31)); } \ + inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ + { c = v_combine_low(a, b); d = v_combine_high(a, b); } + +#define OPENCV_HAL_IMPL_AVX_UNPACKS(_Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_COMBINE(_Tpvec, _mm256_permute2x128_si256) \ + inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, \ + _Tpvec& b0, _Tpvec& b1) \ + { \ + __m256i v0 = _v256_shuffle_odd_64(a0.val); \ + __m256i v1 = _v256_shuffle_odd_64(a1.val); \ + b0.val = _mm256_unpacklo_##suffix(v0, v1); \ + b1.val = _mm256_unpackhi_##suffix(v0, v1); \ + } + +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint64x4, epi64) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int64x4, epi64) +OPENCV_HAL_IMPL_AVX_COMBINE(v_float32x8, _mm256_permute2f128_ps) +OPENCV_HAL_IMPL_AVX_COMBINE(v_float64x4, _mm256_permute2f128_pd) + +inline void v_zip(const v_float32x8& a0, const v_float32x8& a1, v_float32x8& b0, v_float32x8& b1) +{ + __m256 v0 = _mm256_unpacklo_ps(a0.val, a1.val); + __m256 v1 = _mm256_unpackhi_ps(a0.val, a1.val); + v_recombine(v_float32x8(v0), v_float32x8(v1), b0, b1); +} + +inline void v_zip(const v_float64x4& a0, const v_float64x4& a1, v_float64x4& b0, v_float64x4& b1) +{ + __m256d v0 = _v_shuffle_odd_64(a0.val); + __m256d v1 = _v_shuffle_odd_64(a1.val); + b0.val = _mm256_unpacklo_pd(v0, v1); + b1.val = _mm256_unpackhi_pd(v0, v1); +}*/ + +//////////////// Variant Value reordering /////////////// + +// unpacks +#define OPENCV_HAL_IMPL_AVX_UNPACK(_Tpvec, suffix) \ + inline _Tpvec v256_unpacklo(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_unpacklo_##suffix(a.val, b.val)); } \ + inline _Tpvec v256_unpackhi(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_unpackhi_##suffix(a.val, b.val)); } + +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint64x4, epi64) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int64x4, epi64) +OPENCV_HAL_IMPL_AVX_UNPACK(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_UNPACK(v_float64x4, pd) + +// blend +#define OPENCV_HAL_IMPL_AVX_BLEND(_Tpvec, suffix) \ + template<int m> \ + inline _Tpvec v256_blend(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_blend_##suffix(a.val, b.val, m)); } + +OPENCV_HAL_IMPL_AVX_BLEND(v_uint16x16, epi16) +OPENCV_HAL_IMPL_AVX_BLEND(v_int16x16, epi16) +OPENCV_HAL_IMPL_AVX_BLEND(v_uint32x8, epi32) +OPENCV_HAL_IMPL_AVX_BLEND(v_int32x8, epi32) +OPENCV_HAL_IMPL_AVX_BLEND(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_BLEND(v_float64x4, pd) + +template<int m> +inline v_uint64x4 v256_blend(const v_uint64x4& a, const v_uint64x4& b) +{ + enum {M0 = m}; + enum {M1 = (M0 | (M0 << 2)) & 0x33}; + enum {M2 = (M1 | (M1 << 1)) & 0x55}; + enum {MM = M2 | (M2 << 1)}; + return v_uint64x4(_mm256_blend_epi32(a.val, b.val, MM)); +} +template<int m> +inline v_int64x4 v256_blend(const v_int64x4& a, const v_int64x4& b) +{ return v_int64x4(v256_blend<m>(v_uint64x4(a.val), v_uint64x4(b.val)).val); } + +// shuffle +// todo: emluate 64bit +#define OPENCV_HAL_IMPL_AVX_SHUFFLE(_Tpvec, intrin) \ + template<int m> \ + inline _Tpvec v256_shuffle(const _Tpvec& a) \ + { return _Tpvec(_mm256_##intrin(a.val, m)); } + +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_uint32x8, shuffle_epi32) +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_int32x8, shuffle_epi32) +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_float32x8, permute_ps) +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_float64x4, permute_pd) + +template<typename _Tpvec> +inline void v256_zip(const _Tpvec& a, const _Tpvec& b, _Tpvec& ab0, _Tpvec& ab1) +{ + ab0 = v256_unpacklo(a, b); + ab1 = v256_unpackhi(a, b); +} + +template<typename _Tpvec> +inline _Tpvec v256_combine_diagonal(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(_mm256_blend_epi32(a.val, b.val, 0xf0)); } + +inline v_float32x8 v256_combine_diagonal(const v_float32x8& a, const v_float32x8& b) +{ return v256_blend<0xf0>(a, b); } + +inline v_float64x4 v256_combine_diagonal(const v_float64x4& a, const v_float64x4& b) +{ return v256_blend<0xc>(a, b); } + +template<typename _Tpvec> +inline _Tpvec v256_alignr_128(const _Tpvec& a, const _Tpvec& b) +{ return v256_permute2x128<0x21>(a, b); } + +template<typename _Tpvec> +inline _Tpvec v256_alignr_64(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(_mm256_alignr_epi8(a.val, b.val, 8)); } +inline v_float64x4 v256_alignr_64(const v_float64x4& a, const v_float64x4& b) +{ return v_float64x4(_mm256_shuffle_pd(b.val, a.val, _MM_SHUFFLE(0, 0, 1, 1))); } +// todo: emulate float32 + +template<typename _Tpvec> +inline _Tpvec v256_swap_halves(const _Tpvec& a) +{ return v256_permute2x128<1>(a, a); } + +template<typename _Tpvec> +inline _Tpvec v256_reverse_64(const _Tpvec& a) +{ return v256_permute4x64<_MM_SHUFFLE(0, 1, 2, 3)>(a); } + +// ZIP +#define OPENCV_HAL_IMPL_AVX_ZIP(_Tpvec) \ + inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ + { return v256_permute2x128<0x20>(a, b); } \ + inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ + { return v256_permute2x128<0x31>(a, b); } \ + inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ + { \ + _Tpvec a1b0 = v256_alignr_128(a, b); \ + c = v256_combine_diagonal(a, a1b0); \ + d = v256_combine_diagonal(a1b0, b); \ + } \ + inline void v_zip(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& ab0, _Tpvec& ab1) \ + { \ + _Tpvec ab0ab2, ab1ab3; \ + v256_zip(a, b, ab0ab2, ab1ab3); \ + v_recombine(ab0ab2, ab1ab3, ab0, ab1); \ + } + +OPENCV_HAL_IMPL_AVX_ZIP(v_uint8x32) +OPENCV_HAL_IMPL_AVX_ZIP(v_int8x32) +OPENCV_HAL_IMPL_AVX_ZIP(v_uint16x16) +OPENCV_HAL_IMPL_AVX_ZIP(v_int16x16) +OPENCV_HAL_IMPL_AVX_ZIP(v_uint32x8) +OPENCV_HAL_IMPL_AVX_ZIP(v_int32x8) +OPENCV_HAL_IMPL_AVX_ZIP(v_uint64x4) +OPENCV_HAL_IMPL_AVX_ZIP(v_int64x4) +OPENCV_HAL_IMPL_AVX_ZIP(v_float32x8) +OPENCV_HAL_IMPL_AVX_ZIP(v_float64x4) + +////////// Arithmetic, bitwise and comparison operations ///////// + +/* Element-wise binary and unary operations */ + +/** Arithmetics **/ +#define OPENCV_HAL_IMPL_AVX_BIN_OP(bin_op, _Tpvec, intrin) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(intrin(a.val, b.val)); } \ + inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ + { a.val = intrin(a.val, b.val); return a; } + +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint8x32, _mm256_adds_epu8) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint8x32, _mm256_subs_epu8) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int8x32, _mm256_adds_epi8) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int8x32, _mm256_subs_epi8) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint16x16, _mm256_adds_epu16) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint16x16, _mm256_subs_epu16) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int16x16, _mm256_adds_epi16) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int16x16, _mm256_subs_epi16) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint32x8, _mm256_add_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint32x8, _mm256_sub_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_uint32x8, _mm256_mullo_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int32x8, _mm256_add_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int32x8, _mm256_sub_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_int32x8, _mm256_mullo_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint64x4, _mm256_add_epi64) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint64x4, _mm256_sub_epi64) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int64x4, _mm256_add_epi64) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int64x4, _mm256_sub_epi64) + +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_float32x8, _mm256_add_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_float32x8, _mm256_sub_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_float32x8, _mm256_mul_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(/, v_float32x8, _mm256_div_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_float64x4, _mm256_add_pd) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_float64x4, _mm256_sub_pd) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_float64x4, _mm256_mul_pd) +OPENCV_HAL_IMPL_AVX_BIN_OP(/, v_float64x4, _mm256_div_pd) + +// saturating multiply 8-bit, 16-bit +inline v_uint8x32 operator * (const v_uint8x32& a, const v_uint8x32& b) +{ + v_uint16x16 c, d; + v_mul_expand(a, b, c, d); + return v_pack(c, d); +} +inline v_int8x32 operator * (const v_int8x32& a, const v_int8x32& b) +{ + v_int16x16 c, d; + v_mul_expand(a, b, c, d); + return v_pack(c, d); +} +inline v_uint16x16 operator * (const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i pl = _mm256_mullo_epi16(a.val, b.val); + __m256i ph = _mm256_mulhi_epu16(a.val, b.val); + __m256i p0 = _mm256_unpacklo_epi16(pl, ph); + __m256i p1 = _mm256_unpackhi_epi16(pl, ph); + return v_uint16x16(_v256_packs_epu32(p0, p1)); +} +inline v_int16x16 operator * (const v_int16x16& a, const v_int16x16& b) +{ + __m256i pl = _mm256_mullo_epi16(a.val, b.val); + __m256i ph = _mm256_mulhi_epi16(a.val, b.val); + __m256i p0 = _mm256_unpacklo_epi16(pl, ph); + __m256i p1 = _mm256_unpackhi_epi16(pl, ph); + return v_int16x16(_mm256_packs_epi32(p0, p1)); +} +inline v_uint8x32& operator *= (v_uint8x32& a, const v_uint8x32& b) +{ a = a * b; return a; } +inline v_int8x32& operator *= (v_int8x32& a, const v_int8x32& b) +{ a = a * b; return a; } +inline v_uint16x16& operator *= (v_uint16x16& a, const v_uint16x16& b) +{ a = a * b; return a; } +inline v_int16x16& operator *= (v_int16x16& a, const v_int16x16& b) +{ a = a * b; return a; } + +/** Non-saturating arithmetics **/ +#define OPENCV_HAL_IMPL_AVX_BIN_FUNC(func, _Tpvec, intrin) \ + inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(intrin(a.val, b.val)); } + +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_uint8x32, _mm256_add_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_int8x32, _mm256_add_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_uint16x16, _mm256_add_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_int16x16, _mm256_add_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_uint8x32, _mm256_sub_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_int8x32, _mm256_sub_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_uint16x16, _mm256_sub_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_int16x16, _mm256_sub_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_mul_wrap, v_uint16x16, _mm256_mullo_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_mul_wrap, v_int16x16, _mm256_mullo_epi16) + +inline v_uint8x32 v_mul_wrap(const v_uint8x32& a, const v_uint8x32& b) +{ + __m256i ad = _mm256_srai_epi16(a.val, 8); + __m256i bd = _mm256_srai_epi16(b.val, 8); + __m256i p0 = _mm256_mullo_epi16(a.val, b.val); // even + __m256i p1 = _mm256_slli_epi16(_mm256_mullo_epi16(ad, bd), 8); // odd + + const __m256i b01 = _mm256_set1_epi32(0xFF00FF00); + return v_uint8x32(_mm256_blendv_epi8(p0, p1, b01)); +} +inline v_int8x32 v_mul_wrap(const v_int8x32& a, const v_int8x32& b) +{ + return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b))); +} + +// Multiply and expand +inline void v_mul_expand(const v_uint8x32& a, const v_uint8x32& b, + v_uint16x16& c, v_uint16x16& d) +{ + v_uint16x16 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int8x32& a, const v_int8x32& b, + v_int16x16& c, v_int16x16& d) +{ + v_int16x16 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int16x16& a, const v_int16x16& b, + v_int32x8& c, v_int32x8& d) +{ + v_int16x16 vhi = v_int16x16(_mm256_mulhi_epi16(a.val, b.val)); + + v_int16x16 v0, v1; + v_zip(v_mul_wrap(a, b), vhi, v0, v1); + + c = v_reinterpret_as_s32(v0); + d = v_reinterpret_as_s32(v1); +} + +inline void v_mul_expand(const v_uint16x16& a, const v_uint16x16& b, + v_uint32x8& c, v_uint32x8& d) +{ + v_uint16x16 vhi = v_uint16x16(_mm256_mulhi_epu16(a.val, b.val)); + + v_uint16x16 v0, v1; + v_zip(v_mul_wrap(a, b), vhi, v0, v1); + + c = v_reinterpret_as_u32(v0); + d = v_reinterpret_as_u32(v1); +} + +inline void v_mul_expand(const v_uint32x8& a, const v_uint32x8& b, + v_uint64x4& c, v_uint64x4& d) +{ + __m256i v0 = _mm256_mul_epu32(a.val, b.val); + __m256i v1 = _mm256_mul_epu32(_mm256_srli_epi64(a.val, 32), _mm256_srli_epi64(b.val, 32)); + v_zip(v_uint64x4(v0), v_uint64x4(v1), c, d); +} + +inline v_int16x16 v_mul_hi(const v_int16x16& a, const v_int16x16& b) { return v_int16x16(_mm256_mulhi_epi16(a.val, b.val)); } +inline v_uint16x16 v_mul_hi(const v_uint16x16& a, const v_uint16x16& b) { return v_uint16x16(_mm256_mulhi_epu16(a.val, b.val)); } + +/** Bitwise shifts **/ +#define OPENCV_HAL_IMPL_AVX_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, srai) \ + inline _Tpuvec operator << (const _Tpuvec& a, int imm) \ + { return _Tpuvec(_mm256_slli_##suffix(a.val, imm)); } \ + inline _Tpsvec operator << (const _Tpsvec& a, int imm) \ + { return _Tpsvec(_mm256_slli_##suffix(a.val, imm)); } \ + inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \ + { return _Tpuvec(_mm256_srli_##suffix(a.val, imm)); } \ + inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \ + { return _Tpsvec(srai(a.val, imm)); } \ + template<int imm> \ + inline _Tpuvec v_shl(const _Tpuvec& a) \ + { return _Tpuvec(_mm256_slli_##suffix(a.val, imm)); } \ + template<int imm> \ + inline _Tpsvec v_shl(const _Tpsvec& a) \ + { return _Tpsvec(_mm256_slli_##suffix(a.val, imm)); } \ + template<int imm> \ + inline _Tpuvec v_shr(const _Tpuvec& a) \ + { return _Tpuvec(_mm256_srli_##suffix(a.val, imm)); } \ + template<int imm> \ + inline _Tpsvec v_shr(const _Tpsvec& a) \ + { return _Tpsvec(srai(a.val, imm)); } + +OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint16x16, v_int16x16, epi16, _mm256_srai_epi16) +OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint32x8, v_int32x8, epi32, _mm256_srai_epi32) + +inline __m256i _mm256_srai_epi64xx(const __m256i a, int imm) +{ + __m256i d = _mm256_set1_epi64x((int64)1 << 63); + __m256i r = _mm256_srli_epi64(_mm256_add_epi64(a, d), imm); + return _mm256_sub_epi64(r, _mm256_srli_epi64(d, imm)); +} +OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint64x4, v_int64x4, epi64, _mm256_srai_epi64xx) + + +/** Bitwise logic **/ +#define OPENCV_HAL_IMPL_AVX_LOGIC_OP(_Tpvec, suffix, not_const) \ + OPENCV_HAL_IMPL_AVX_BIN_OP(&, _Tpvec, _mm256_and_##suffix) \ + OPENCV_HAL_IMPL_AVX_BIN_OP(|, _Tpvec, _mm256_or_##suffix) \ + OPENCV_HAL_IMPL_AVX_BIN_OP(^, _Tpvec, _mm256_xor_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { return _Tpvec(_mm256_xor_##suffix(a.val, not_const)); } + +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint8x32, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int8x32, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint16x16, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int16x16, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint32x8, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int32x8, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint64x4, si256, _mm256_set1_epi64x(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int64x4, si256, _mm256_set1_epi64x(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_float32x8, ps, _mm256_castsi256_ps(_mm256_set1_epi32(-1))) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_float64x4, pd, _mm256_castsi256_pd(_mm256_set1_epi32(-1))) + +/** Select **/ +#define OPENCV_HAL_IMPL_AVX_SELECT(_Tpvec, suffix) \ + inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_blendv_##suffix(b.val, a.val, mask.val)); } + +OPENCV_HAL_IMPL_AVX_SELECT(v_uint8x32, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_int8x32, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_uint16x16, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_int16x16, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_uint32x8, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_int32x8, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_SELECT(v_float64x4, pd) + +/** Comparison **/ +#define OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpvec) \ + inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ + { return ~(a == b); } \ + inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ + { return b > a; } \ + inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ + { return ~(a < b); } \ + inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ + { return b >= a; } + +#define OPENCV_HAL_IMPL_AVX_CMP_OP_INT(_Tpuvec, _Tpsvec, suffix, sbit) \ + inline _Tpuvec operator == (const _Tpuvec& a, const _Tpuvec& b) \ + { return _Tpuvec(_mm256_cmpeq_##suffix(a.val, b.val)); } \ + inline _Tpuvec operator > (const _Tpuvec& a, const _Tpuvec& b) \ + { \ + __m256i smask = _mm256_set1_##suffix(sbit); \ + return _Tpuvec(_mm256_cmpgt_##suffix( \ + _mm256_xor_si256(a.val, smask), \ + _mm256_xor_si256(b.val, smask))); \ + } \ + inline _Tpsvec operator == (const _Tpsvec& a, const _Tpsvec& b) \ + { return _Tpsvec(_mm256_cmpeq_##suffix(a.val, b.val)); } \ + inline _Tpsvec operator > (const _Tpsvec& a, const _Tpsvec& b) \ + { return _Tpsvec(_mm256_cmpgt_##suffix(a.val, b.val)); } \ + OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpuvec) \ + OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpsvec) + +OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint8x32, v_int8x32, epi8, (char)-128) +OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint16x16, v_int16x16, epi16, (short)-32768) +OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint32x8, v_int32x8, epi32, (int)0x80000000) + +#define OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(_Tpvec) \ + inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_cmpeq_epi64(a.val, b.val)); } \ + inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ + { return ~(a == b); } + +OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_uint64x4) +OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_int64x4) + +#define OPENCV_HAL_IMPL_AVX_CMP_FLT(bin_op, imm8, _Tpvec, suffix) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_cmp_##suffix(a.val, b.val, imm8)); } + +#define OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(_Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(==, _CMP_EQ_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(!=, _CMP_NEQ_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(<, _CMP_LT_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(>, _CMP_GT_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(<=, _CMP_LE_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(>=, _CMP_GE_OQ, _Tpvec, suffix) + +OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(v_float64x4, pd) + +inline v_float32x8 v_not_nan(const v_float32x8& a) +{ return v_float32x8(_mm256_cmp_ps(a.val, a.val, _CMP_ORD_Q)); } +inline v_float64x4 v_not_nan(const v_float64x4& a) +{ return v_float64x4(_mm256_cmp_pd(a.val, a.val, _CMP_ORD_Q)); } + +/** min/max **/ +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint8x32, _mm256_min_epu8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint8x32, _mm256_max_epu8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int8x32, _mm256_min_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int8x32, _mm256_max_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint16x16, _mm256_min_epu16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint16x16, _mm256_max_epu16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int16x16, _mm256_min_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int16x16, _mm256_max_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint32x8, _mm256_min_epu32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint32x8, _mm256_max_epu32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int32x8, _mm256_min_epi32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int32x8, _mm256_max_epi32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_float32x8, _mm256_min_ps) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_float32x8, _mm256_max_ps) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_float64x4, _mm256_min_pd) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_float64x4, _mm256_max_pd) + +/** Rotate **/ +template<int imm> +inline v_uint8x32 v_rotate_left(const v_uint8x32& a, const v_uint8x32& b) +{ + enum {IMM_R = (16 - imm) & 0xFF}; + enum {IMM_R2 = (32 - imm) & 0xFF}; + + if (imm == 0) return a; + if (imm == 32) return b; + if (imm > 32) return v_uint8x32(); + + __m256i swap = _mm256_permute2x128_si256(a.val, b.val, 0x03); + if (imm == 16) return v_uint8x32(swap); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(a.val, swap, IMM_R)); + return v_uint8x32(_mm256_alignr_epi8(swap, b.val, IMM_R2)); // imm < 32 +} + +template<int imm> +inline v_uint8x32 v_rotate_right(const v_uint8x32& a, const v_uint8x32& b) +{ + enum {IMM_L = (imm - 16) & 0xFF}; + + if (imm == 0) return a; + if (imm == 32) return b; + if (imm > 32) return v_uint8x32(); + + __m256i swap = _mm256_permute2x128_si256(a.val, b.val, 0x21); + if (imm == 16) return v_uint8x32(swap); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(swap, a.val, imm)); + return v_uint8x32(_mm256_alignr_epi8(b.val, swap, IMM_L)); +} + +template<int imm> +inline v_uint8x32 v_rotate_left(const v_uint8x32& a) +{ + enum {IMM_L = (imm - 16) & 0xFF}; + enum {IMM_R = (16 - imm) & 0xFF}; + + if (imm == 0) return a; + if (imm > 32) return v_uint8x32(); + + // ESAC control[3] ? [127:0] = 0 + __m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(0, 0, 2, 0)); + if (imm == 16) return v_uint8x32(swapz); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(a.val, swapz, IMM_R)); + return v_uint8x32(_mm256_slli_si256(swapz, IMM_L)); +} + +template<int imm> +inline v_uint8x32 v_rotate_right(const v_uint8x32& a) +{ + enum {IMM_L = (imm - 16) & 0xFF}; + + if (imm == 0) return a; + if (imm > 32) return v_uint8x32(); + + // ESAC control[3] ? [127:0] = 0 + __m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(2, 0, 0, 1)); + if (imm == 16) return v_uint8x32(swapz); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(swapz, a.val, imm)); + return v_uint8x32(_mm256_srli_si256(swapz, IMM_L)); +} + +#define OPENCV_HAL_IMPL_AVX_ROTATE_CAST(intrin, _Tpvec, cast) \ + template<int imm> \ + inline _Tpvec intrin(const _Tpvec& a, const _Tpvec& b) \ + { \ + enum {IMMxW = imm * sizeof(typename _Tpvec::lane_type)}; \ + v_uint8x32 ret = intrin<IMMxW>(v_reinterpret_as_u8(a), \ + v_reinterpret_as_u8(b)); \ + return _Tpvec(cast(ret.val)); \ + } \ + template<int imm> \ + inline _Tpvec intrin(const _Tpvec& a) \ + { \ + enum {IMMxW = imm * sizeof(typename _Tpvec::lane_type)}; \ + v_uint8x32 ret = intrin<IMMxW>(v_reinterpret_as_u8(a)); \ + return _Tpvec(cast(ret.val)); \ + } + +#define OPENCV_HAL_IMPL_AVX_ROTATE(_Tpvec) \ + OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, _Tpvec, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, _Tpvec, OPENCV_HAL_NOP) + +OPENCV_HAL_IMPL_AVX_ROTATE(v_int8x32) +OPENCV_HAL_IMPL_AVX_ROTATE(v_uint16x16) +OPENCV_HAL_IMPL_AVX_ROTATE(v_int16x16) +OPENCV_HAL_IMPL_AVX_ROTATE(v_uint32x8) +OPENCV_HAL_IMPL_AVX_ROTATE(v_int32x8) +OPENCV_HAL_IMPL_AVX_ROTATE(v_uint64x4) +OPENCV_HAL_IMPL_AVX_ROTATE(v_int64x4) + +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, v_float32x8, _mm256_castsi256_ps) +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, v_float32x8, _mm256_castsi256_ps) +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, v_float64x4, _mm256_castsi256_pd) +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, v_float64x4, _mm256_castsi256_pd) + +////////// Reduce and mask ///////// + +/** Reduce **/ +#define OPENCV_HAL_IMPL_AVX_REDUCE_16(_Tpvec, sctype, func, intrin) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { \ + __m128i v0 = _v256_extract_low(a.val); \ + __m128i v1 = _v256_extract_high(a.val); \ + v0 = intrin(v0, v1); \ + v0 = intrin(v0, _mm_srli_si128(v0, 8)); \ + v0 = intrin(v0, _mm_srli_si128(v0, 4)); \ + v0 = intrin(v0, _mm_srli_si128(v0, 2)); \ + return (sctype) _mm_cvtsi128_si32(v0); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_uint16x16, ushort, min, _mm_min_epu16) +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_int16x16, short, min, _mm_min_epi16) +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_uint16x16, ushort, max, _mm_max_epu16) +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_int16x16, short, max, _mm_max_epi16) + +#define OPENCV_HAL_IMPL_AVX_REDUCE_8(_Tpvec, sctype, func, intrin) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { \ + __m128i v0 = _v256_extract_low(a.val); \ + __m128i v1 = _v256_extract_high(a.val); \ + v0 = intrin(v0, v1); \ + v0 = intrin(v0, _mm_srli_si128(v0, 8)); \ + v0 = intrin(v0, _mm_srli_si128(v0, 4)); \ + return (sctype) _mm_cvtsi128_si32(v0); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_uint32x8, unsigned, min, _mm_min_epu32) +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_int32x8, int, min, _mm_min_epi32) +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_uint32x8, unsigned, max, _mm_max_epu32) +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_int32x8, int, max, _mm_max_epi32) + +#define OPENCV_HAL_IMPL_AVX_REDUCE_FLT(func, intrin) \ + inline float v_reduce_##func(const v_float32x8& a) \ + { \ + __m128 v0 = _v256_extract_low(a.val); \ + __m128 v1 = _v256_extract_high(a.val); \ + v0 = intrin(v0, v1); \ + v0 = intrin(v0, _mm_permute_ps(v0, _MM_SHUFFLE(0, 0, 3, 2))); \ + v0 = intrin(v0, _mm_permute_ps(v0, _MM_SHUFFLE(0, 0, 0, 3))); \ + return _mm_cvtss_f32(v0); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_FLT(min, _mm_min_ps) +OPENCV_HAL_IMPL_AVX_REDUCE_FLT(max, _mm_max_ps) + +inline ushort v_reduce_sum(const v_uint16x16& a) +{ + __m128i a0 = _v256_extract_low(a.val); + __m128i a1 = _v256_extract_high(a.val); + + __m128i s0 = _mm_adds_epu16(a0, a1); + s0 = _mm_adds_epu16(s0, _mm_srli_si128(s0, 8)); + s0 = _mm_adds_epu16(s0, _mm_srli_si128(s0, 4)); + s0 = _mm_adds_epu16(s0, _mm_srli_si128(s0, 2)); + + return (ushort)_mm_cvtsi128_si32(s0); +} + +inline short v_reduce_sum(const v_int16x16& a) +{ + __m256i s0 = _mm256_hadds_epi16(a.val, a.val); + s0 = _mm256_hadds_epi16(s0, s0); + s0 = _mm256_hadds_epi16(s0, s0); + + __m128i s1 = _v256_extract_high(s0); + s1 = _mm_adds_epi16(_v256_extract_low(s0), s1); + + return (short)_mm_cvtsi128_si32(s1); +} + +inline int v_reduce_sum(const v_int32x8& a) +{ + __m256i s0 = _mm256_hadd_epi32(a.val, a.val); + s0 = _mm256_hadd_epi32(s0, s0); + + __m128i s1 = _v256_extract_high(s0); + s1 = _mm_add_epi32(_v256_extract_low(s0), s1); + + return _mm_cvtsi128_si32(s1); +} + +inline unsigned v_reduce_sum(const v_uint32x8& a) +{ return v_reduce_sum(v_reinterpret_as_s32(a)); } + +inline float v_reduce_sum(const v_float32x8& a) +{ + __m256 s0 = _mm256_hadd_ps(a.val, a.val); + s0 = _mm256_hadd_ps(s0, s0); + + __m128 s1 = _v256_extract_high(s0); + s1 = _mm_add_ps(_v256_extract_low(s0), s1); + + return _mm_cvtss_f32(s1); +} + +inline double v_reduce_sum(const v_float64x4& a) +{ + __m256d s0 = _mm256_hadd_pd(a.val, a.val); + return _mm_cvtsd_f64(_mm_add_pd(_v256_extract_low(s0), _v256_extract_high(s0))); +} + +inline v_float32x8 v_reduce_sum4(const v_float32x8& a, const v_float32x8& b, + const v_float32x8& c, const v_float32x8& d) +{ + __m256 ab = _mm256_hadd_ps(a.val, b.val); + __m256 cd = _mm256_hadd_ps(c.val, d.val); + return v_float32x8(_mm256_hadd_ps(ab, cd)); +} + +inline unsigned v_reduce_sad(const v_uint8x32& a, const v_uint8x32& b) +{ + return (unsigned)_v_cvtsi256_si32(_mm256_sad_epu8(a.val, b.val)); +} +inline unsigned v_reduce_sad(const v_int8x32& a, const v_int8x32& b) +{ + __m256i half = _mm256_set1_epi8(0x7f); + return (unsigned)_v_cvtsi256_si32(_mm256_sad_epu8(_mm256_add_epi8(a.val, half), _mm256_add_epi8(b.val, half))); +} +inline unsigned v_reduce_sad(const v_uint16x16& a, const v_uint16x16& b) +{ + v_uint32x8 l, h; + v_expand(v_add_wrap(a - b, b - a), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_int16x16& a, const v_int16x16& b) +{ + v_uint32x8 l, h; + v_expand(v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_uint32x8& a, const v_uint32x8& b) +{ + return v_reduce_sum(v_max(a, b) - v_min(a, b)); +} +inline unsigned v_reduce_sad(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 m = a < b; + return v_reduce_sum(v_reinterpret_as_u32(((a - b) ^ m) - m)); +} +inline float v_reduce_sad(const v_float32x8& a, const v_float32x8& b) +{ + return v_reduce_sum((a - b) & v_float32x8(_mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff)))); +} + +/** Popcount **/ +#define OPENCV_HAL_IMPL_AVX_POPCOUNT(_Tpvec) \ + inline v_uint32x8 v_popcount(const _Tpvec& a) \ + { \ + const v_uint32x8 m1 = v256_setall_u32(0x55555555); \ + const v_uint32x8 m2 = v256_setall_u32(0x33333333); \ + const v_uint32x8 m4 = v256_setall_u32(0x0f0f0f0f); \ + v_uint32x8 p = v_reinterpret_as_u32(a); \ + p = ((p >> 1) & m1) + (p & m1); \ + p = ((p >> 2) & m2) + (p & m2); \ + p = ((p >> 4) & m4) + (p & m4); \ + p.val = _mm256_sad_epu8(p.val, _mm256_setzero_si256()); \ + return p; \ + } + +OPENCV_HAL_IMPL_AVX_POPCOUNT(v_uint8x32) +OPENCV_HAL_IMPL_AVX_POPCOUNT(v_int8x32) +OPENCV_HAL_IMPL_AVX_POPCOUNT(v_uint16x16) +OPENCV_HAL_IMPL_AVX_POPCOUNT(v_int16x16) +OPENCV_HAL_IMPL_AVX_POPCOUNT(v_uint32x8) +OPENCV_HAL_IMPL_AVX_POPCOUNT(v_int32x8) + +/** Mask **/ +inline int v_signmask(const v_int8x32& a) +{ return _mm256_movemask_epi8(a.val); } +inline int v_signmask(const v_uint8x32& a) +{ return v_signmask(v_reinterpret_as_s8(a)); } + +inline int v_signmask(const v_int16x16& a) +{ + v_int8x32 v = v_int8x32(_mm256_packs_epi16(a.val, a.val)); + return v_signmask(v) & 255; +} +inline int v_signmask(const v_uint16x16& a) +{ return v_signmask(v_reinterpret_as_s16(a)); } + +inline int v_signmask(const v_int32x8& a) +{ + __m256i a16 = _mm256_packs_epi32(a.val, a.val); + v_int8x32 v = v_int8x32(_mm256_packs_epi16(a16, a16)); + return v_signmask(v) & 15; +} +inline int v_signmask(const v_uint32x8& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } + +inline int v_signmask(const v_float32x8& a) +{ return _mm256_movemask_ps(a.val); } +inline int v_signmask(const v_float64x4& a) +{ return _mm256_movemask_pd(a.val); } + +/** Checks **/ +#define OPENCV_HAL_IMPL_AVX_CHECK(_Tpvec, and_op, allmask) \ + inline bool v_check_all(const _Tpvec& a) \ + { \ + int mask = v_signmask(v_reinterpret_as_s8(a)); \ + return and_op(mask, allmask) == allmask; \ + } \ + inline bool v_check_any(const _Tpvec& a) \ + { \ + int mask = v_signmask(v_reinterpret_as_s8(a)); \ + return and_op(mask, allmask) != 0; \ + } + +OPENCV_HAL_IMPL_AVX_CHECK(v_uint8x32, OPENCV_HAL_1ST, -1) +OPENCV_HAL_IMPL_AVX_CHECK(v_int8x32, OPENCV_HAL_1ST, -1) +OPENCV_HAL_IMPL_AVX_CHECK(v_uint16x16, OPENCV_HAL_AND, (int)0xaaaa) +OPENCV_HAL_IMPL_AVX_CHECK(v_int16x16, OPENCV_HAL_AND, (int)0xaaaa) +OPENCV_HAL_IMPL_AVX_CHECK(v_uint32x8, OPENCV_HAL_AND, (int)0x8888) +OPENCV_HAL_IMPL_AVX_CHECK(v_int32x8, OPENCV_HAL_AND, (int)0x8888) + +#define OPENCV_HAL_IMPL_AVX_CHECK_FLT(_Tpvec, allmask) \ + inline bool v_check_all(const _Tpvec& a) \ + { \ + int mask = v_signmask(a); \ + return mask == allmask; \ + } \ + inline bool v_check_any(const _Tpvec& a) \ + { \ + int mask = v_signmask(a); \ + return mask != 0; \ + } + +OPENCV_HAL_IMPL_AVX_CHECK_FLT(v_float32x8, 255) +OPENCV_HAL_IMPL_AVX_CHECK_FLT(v_float64x4, 15) + + +////////// Other math ///////// + +/** Some frequent operations **/ +#define OPENCV_HAL_IMPL_AVX_MULADD(_Tpvec, suffix) \ + inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ + { return _Tpvec(_mm256_fmadd_##suffix(a.val, b.val, c.val)); } \ + inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ + { return _Tpvec(_mm256_fmadd_##suffix(a.val, b.val, c.val)); } \ + inline _Tpvec v_sqrt(const _Tpvec& x) \ + { return _Tpvec(_mm256_sqrt_##suffix(x.val)); } \ + inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ + { return v_fma(a, a, b * b); } \ + inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ + { return v_sqrt(v_fma(a, a, b*b)); } + +OPENCV_HAL_IMPL_AVX_MULADD(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_MULADD(v_float64x4, pd) + +inline v_int32x8 v_fma(const v_int32x8& a, const v_int32x8& b, const v_int32x8& c) +{ + return a * b + c; +} + +inline v_int32x8 v_muladd(const v_int32x8& a, const v_int32x8& b, const v_int32x8& c) +{ + return v_fma(a, b, c); +} + +inline v_float32x8 v_invsqrt(const v_float32x8& x) +{ + v_float32x8 half = x * v256_setall_f32(0.5); + v_float32x8 t = v_float32x8(_mm256_rsqrt_ps(x.val)); + // todo: _mm256_fnmsub_ps + t *= v256_setall_f32(1.5) - ((t * t) * half); + return t; +} + +inline v_float64x4 v_invsqrt(const v_float64x4& x) +{ + return v256_setall_f64(1.) / v_sqrt(x); +} + +/** Absolute values **/ +#define OPENCV_HAL_IMPL_AVX_ABS(_Tpvec, suffix) \ + inline v_u##_Tpvec v_abs(const v_##_Tpvec& x) \ + { return v_u##_Tpvec(_mm256_abs_##suffix(x.val)); } + +OPENCV_HAL_IMPL_AVX_ABS(int8x32, epi8) +OPENCV_HAL_IMPL_AVX_ABS(int16x16, epi16) +OPENCV_HAL_IMPL_AVX_ABS(int32x8, epi32) + +inline v_float32x8 v_abs(const v_float32x8& x) +{ return x & v_float32x8(_mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff))); } +inline v_float64x4 v_abs(const v_float64x4& x) +{ return x & v_float64x4(_mm256_castsi256_pd(_mm256_srli_epi64(_mm256_set1_epi64x(-1), 1))); } + +/** Absolute difference **/ +inline v_uint8x32 v_absdiff(const v_uint8x32& a, const v_uint8x32& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint16x16 v_absdiff(const v_uint16x16& a, const v_uint16x16& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint32x8 v_absdiff(const v_uint32x8& a, const v_uint32x8& b) +{ return v_max(a, b) - v_min(a, b); } + +inline v_uint8x32 v_absdiff(const v_int8x32& a, const v_int8x32& b) +{ + v_int8x32 d = v_sub_wrap(a, b); + v_int8x32 m = a < b; + return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m)); +} + +inline v_uint16x16 v_absdiff(const v_int16x16& a, const v_int16x16& b) +{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); } + +inline v_uint32x8 v_absdiff(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 d = a - b; + v_int32x8 m = a < b; + return v_reinterpret_as_u32((d ^ m) - m); +} + +inline v_float32x8 v_absdiff(const v_float32x8& a, const v_float32x8& b) +{ return v_abs(a - b); } + +inline v_float64x4 v_absdiff(const v_float64x4& a, const v_float64x4& b) +{ return v_abs(a - b); } + +/** Saturating absolute difference **/ +inline v_int8x32 v_absdiffs(const v_int8x32& a, const v_int8x32& b) +{ + v_int8x32 d = a - b; + v_int8x32 m = a < b; + return (d ^ m) - m; +} +inline v_int16x16 v_absdiffs(const v_int16x16& a, const v_int16x16& b) +{ return v_max(a, b) - v_min(a, b); } + +////////// Conversions ///////// + +/** Rounding **/ +inline v_int32x8 v_round(const v_float32x8& a) +{ return v_int32x8(_mm256_cvtps_epi32(a.val)); } + +inline v_int32x8 v_round(const v_float64x4& a) +{ return v_int32x8(_mm256_castsi128_si256(_mm256_cvtpd_epi32(a.val))); } + +inline v_int32x8 v_round(const v_float64x4& a, const v_float64x4& b) +{ + __m128i ai = _mm256_cvtpd_epi32(a.val), bi = _mm256_cvtpd_epi32(b.val); + return v_int32x8(_v256_combine(ai, bi)); +} + +inline v_int32x8 v_trunc(const v_float32x8& a) +{ return v_int32x8(_mm256_cvttps_epi32(a.val)); } + +inline v_int32x8 v_trunc(const v_float64x4& a) +{ return v_int32x8(_mm256_castsi128_si256(_mm256_cvttpd_epi32(a.val))); } + +inline v_int32x8 v_floor(const v_float32x8& a) +{ return v_int32x8(_mm256_cvttps_epi32(_mm256_floor_ps(a.val))); } + +inline v_int32x8 v_floor(const v_float64x4& a) +{ return v_trunc(v_float64x4(_mm256_floor_pd(a.val))); } + +inline v_int32x8 v_ceil(const v_float32x8& a) +{ return v_int32x8(_mm256_cvttps_epi32(_mm256_ceil_ps(a.val))); } + +inline v_int32x8 v_ceil(const v_float64x4& a) +{ return v_trunc(v_float64x4(_mm256_ceil_pd(a.val))); } + +/** To float **/ +inline v_float32x8 v_cvt_f32(const v_int32x8& a) +{ return v_float32x8(_mm256_cvtepi32_ps(a.val)); } + +inline v_float32x8 v_cvt_f32(const v_float64x4& a) +{ return v_float32x8(_mm256_castps128_ps256(_mm256_cvtpd_ps(a.val))); } + +inline v_float32x8 v_cvt_f32(const v_float64x4& a, const v_float64x4& b) +{ + __m128 af = _mm256_cvtpd_ps(a.val), bf = _mm256_cvtpd_ps(b.val); + return v_float32x8(_mm256_insertf128_ps(_mm256_castps128_ps256(af), bf, 1)); +} + +inline v_float64x4 v_cvt_f64(const v_int32x8& a) +{ return v_float64x4(_mm256_cvtepi32_pd(_v256_extract_low(a.val))); } + +inline v_float64x4 v_cvt_f64_high(const v_int32x8& a) +{ return v_float64x4(_mm256_cvtepi32_pd(_v256_extract_high(a.val))); } + +inline v_float64x4 v_cvt_f64(const v_float32x8& a) +{ return v_float64x4(_mm256_cvtps_pd(_v256_extract_low(a.val))); } + +inline v_float64x4 v_cvt_f64_high(const v_float32x8& a) +{ return v_float64x4(_mm256_cvtps_pd(_v256_extract_high(a.val))); } + +////////////// Lookup table access //////////////////// + +inline v_int8x32 v256_lut(const schar* tab, const int* idx) +{ + return v_int8x32(_mm256_setr_epi8(tab[idx[ 0]], tab[idx[ 1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[ 8]], tab[idx[ 9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]], + tab[idx[16]], tab[idx[17]], tab[idx[18]], tab[idx[19]], tab[idx[20]], tab[idx[21]], tab[idx[22]], tab[idx[23]], + tab[idx[24]], tab[idx[25]], tab[idx[26]], tab[idx[27]], tab[idx[28]], tab[idx[29]], tab[idx[30]], tab[idx[31]])); +} +inline v_int8x32 v256_lut_pairs(const schar* tab, const int* idx) +{ + return v_int8x32(_mm256_setr_epi16(*(const short*)(tab + idx[ 0]), *(const short*)(tab + idx[ 1]), *(const short*)(tab + idx[ 2]), *(const short*)(tab + idx[ 3]), + *(const short*)(tab + idx[ 4]), *(const short*)(tab + idx[ 5]), *(const short*)(tab + idx[ 6]), *(const short*)(tab + idx[ 7]), + *(const short*)(tab + idx[ 8]), *(const short*)(tab + idx[ 9]), *(const short*)(tab + idx[10]), *(const short*)(tab + idx[11]), + *(const short*)(tab + idx[12]), *(const short*)(tab + idx[13]), *(const short*)(tab + idx[14]), *(const short*)(tab + idx[15]))); +} +inline v_int8x32 v256_lut_quads(const schar* tab, const int* idx) +{ + return v_int8x32(_mm256_i32gather_epi32((const int*)tab, _mm256_loadu_si256((const __m256i*)idx), 1)); +} +inline v_uint8x32 v256_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut((const schar *)tab, idx)); } +inline v_uint8x32 v256_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut_pairs((const schar *)tab, idx)); } +inline v_uint8x32 v256_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut_quads((const schar *)tab, idx)); } + +inline v_int16x16 v256_lut(const short* tab, const int* idx) +{ + return v_int16x16(_mm256_setr_epi16(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]])); +} +inline v_int16x16 v256_lut_pairs(const short* tab, const int* idx) +{ + return v_int16x16(_mm256_i32gather_epi32((const int*)tab, _mm256_loadu_si256((const __m256i*)idx), 2)); +} +inline v_int16x16 v256_lut_quads(const short* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int16x16(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 2));//Looks like intrinsic has wrong definition +#else + return v_int16x16(_mm256_i32gather_epi64((const int64*)tab, _mm_loadu_si128((const __m128i*)idx), 2)); +#endif +} +inline v_uint16x16 v256_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut((const short *)tab, idx)); } +inline v_uint16x16 v256_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut_pairs((const short *)tab, idx)); } +inline v_uint16x16 v256_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut_quads((const short *)tab, idx)); } + +inline v_int32x8 v256_lut(const int* tab, const int* idx) +{ + return v_int32x8(_mm256_i32gather_epi32(tab, _mm256_loadu_si256((const __m256i*)idx), 4)); +} +inline v_int32x8 v256_lut_pairs(const int* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int32x8(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 4)); +#else + return v_int32x8(_mm256_i32gather_epi64((const int64*)tab, _mm_loadu_si128((const __m128i*)idx), 4)); +#endif +} +inline v_int32x8 v256_lut_quads(const int* tab, const int* idx) +{ + return v_int32x8(_mm256_insertf128_si256(_mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(tab + idx[0]))), _mm_loadu_si128((const __m128i*)(tab + idx[1])), 0x1)); +} +inline v_uint32x8 v256_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut((const int *)tab, idx)); } +inline v_uint32x8 v256_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut_pairs((const int *)tab, idx)); } +inline v_uint32x8 v256_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut_quads((const int *)tab, idx)); } + +inline v_int64x4 v256_lut(const int64* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int64x4(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 8)); +#else + return v_int64x4(_mm256_i32gather_epi64(tab, _mm_loadu_si128((const __m128i*)idx), 8)); +#endif +} +inline v_int64x4 v256_lut_pairs(const int64* tab, const int* idx) +{ + return v_int64x4(_mm256_insertf128_si256(_mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(tab + idx[0]))), _mm_loadu_si128((const __m128i*)(tab + idx[1])), 0x1)); +} +inline v_uint64x4 v256_lut(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v256_lut((const int64 *)tab, idx)); } +inline v_uint64x4 v256_lut_pairs(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v256_lut_pairs((const int64 *)tab, idx)); } + +inline v_float32x8 v256_lut(const float* tab, const int* idx) +{ + return v_float32x8(_mm256_i32gather_ps(tab, _mm256_loadu_si256((const __m256i*)idx), 4)); +} +inline v_float32x8 v256_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v256_lut_pairs((const int *)tab, idx)); } +inline v_float32x8 v256_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v256_lut_quads((const int *)tab, idx)); } + +inline v_float64x4 v256_lut(const double* tab, const int* idx) +{ + return v_float64x4(_mm256_i32gather_pd(tab, _mm_loadu_si128((const __m128i*)idx), 8)); +} +inline v_float64x4 v256_lut_pairs(const double* tab, const int* idx) { return v_float64x4(_mm256_insertf128_pd(_mm256_castpd128_pd256(_mm_loadu_pd(tab + idx[0])), _mm_loadu_pd(tab + idx[1]), 0x1)); } + +inline v_int32x8 v_lut(const int* tab, const v_int32x8& idxvec) +{ + return v_int32x8(_mm256_i32gather_epi32(tab, idxvec.val, 4)); +} + +inline v_uint32x8 v_lut(const unsigned* tab, const v_int32x8& idxvec) +{ + return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec)); +} + +inline v_float32x8 v_lut(const float* tab, const v_int32x8& idxvec) +{ + return v_float32x8(_mm256_i32gather_ps(tab, idxvec.val, 4)); +} + +inline v_float64x4 v_lut(const double* tab, const v_int32x8& idxvec) +{ + return v_float64x4(_mm256_i32gather_pd(tab, _mm256_castsi256_si128(idxvec.val), 8)); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x8& idxvec, v_float32x8& x, v_float32x8& y) +{ + int CV_DECL_ALIGNED(32) idx[8]; + v_store_aligned(idx, idxvec); + __m128 z = _mm_setzero_ps(); + __m128 xy01, xy45, xy23, xy67; + xy01 = _mm_loadl_pi(z, (const __m64*)(tab + idx[0])); + xy01 = _mm_loadh_pi(xy01, (const __m64*)(tab + idx[1])); + xy45 = _mm_loadl_pi(z, (const __m64*)(tab + idx[4])); + xy45 = _mm_loadh_pi(xy45, (const __m64*)(tab + idx[5])); + __m256 xy0145 = _v256_combine(xy01, xy45); + xy23 = _mm_loadl_pi(z, (const __m64*)(tab + idx[2])); + xy23 = _mm_loadh_pi(xy23, (const __m64*)(tab + idx[3])); + xy67 = _mm_loadl_pi(z, (const __m64*)(tab + idx[6])); + xy67 = _mm_loadh_pi(xy67, (const __m64*)(tab + idx[7])); + __m256 xy2367 = _v256_combine(xy23, xy67); + + __m256 xxyy0145 = _mm256_unpacklo_ps(xy0145, xy2367); + __m256 xxyy2367 = _mm256_unpackhi_ps(xy0145, xy2367); + + x = v_float32x8(_mm256_unpacklo_ps(xxyy0145, xxyy2367)); + y = v_float32x8(_mm256_unpackhi_ps(xxyy0145, xxyy2367)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x8& idxvec, v_float64x4& x, v_float64x4& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_low(idx, idxvec); + __m128d xy0 = _mm_loadu_pd(tab + idx[0]); + __m128d xy2 = _mm_loadu_pd(tab + idx[2]); + __m128d xy1 = _mm_loadu_pd(tab + idx[1]); + __m128d xy3 = _mm_loadu_pd(tab + idx[3]); + __m256d xy02 = _v256_combine(xy0, xy2); + __m256d xy13 = _v256_combine(xy1, xy3); + + x = v_float64x4(_mm256_unpacklo_pd(xy02, xy13)); + y = v_float64x4(_mm256_unpackhi_pd(xy02, xy13)); +} + +inline v_int8x32 v_interleave_pairs(const v_int8x32& vec) +{ + return v_int8x32(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0d0e0c0b090a08, 0x0705060403010200, 0x0f0d0e0c0b090a08, 0x0705060403010200))); +} +inline v_uint8x32 v_interleave_pairs(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x32 v_interleave_quads(const v_int8x32& vec) +{ + return v_int8x32(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0b0e0a0d090c08, 0x0703060205010400, 0x0f0b0e0a0d090c08, 0x0703060205010400))); +} +inline v_uint8x32 v_interleave_quads(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x16 v_interleave_pairs(const v_int16x16& vec) +{ + return v_int16x16(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0e0b0a0d0c0908, 0x0706030205040100, 0x0f0e0b0a0d0c0908, 0x0706030205040100))); +} +inline v_uint16x16 v_interleave_pairs(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x16 v_interleave_quads(const v_int16x16& vec) +{ + return v_int16x16(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0e07060d0c0504, 0x0b0a030209080100, 0x0f0e07060d0c0504, 0x0b0a030209080100))); +} +inline v_uint16x16 v_interleave_quads(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x8 v_interleave_pairs(const v_int32x8& vec) +{ + return v_int32x8(_mm256_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0))); +} +inline v_uint32x8 v_interleave_pairs(const v_uint32x8& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x8 v_interleave_pairs(const v_float32x8& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x32 v_pack_triplets(const v_int8x32& vec) +{ + return v_int8x32(_mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(vec.val, _mm256_broadcastsi128_si256(_mm_set_epi64x(0xffffff0f0e0d0c0a, 0x0908060504020100))), + _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} +inline v_uint8x32 v_pack_triplets(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x16 v_pack_triplets(const v_int16x16& vec) +{ + return v_int16x16(_mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(vec.val, _mm256_broadcastsi128_si256(_mm_set_epi64x(0xffff0f0e0d0c0b0a, 0x0908050403020100))), + _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} +inline v_uint16x16 v_pack_triplets(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x8 v_pack_triplets(const v_int32x8& vec) +{ + return v_int32x8(_mm256_permutevar8x32_epi32(vec.val, _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} +inline v_uint32x8 v_pack_triplets(const v_uint32x8& vec) { return v_reinterpret_as_u32(v_pack_triplets(v_reinterpret_as_s32(vec))); } +inline v_float32x8 v_pack_triplets(const v_float32x8& vec) +{ + return v_float32x8(_mm256_permutevar8x32_ps(vec.val, _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} + +////////// Matrix operations ///////// + +inline v_int32x8 v_dotprod(const v_int16x16& a, const v_int16x16& b) +{ return v_int32x8(_mm256_madd_epi16(a.val, b.val)); } + +inline v_int32x8 v_dotprod(const v_int16x16& a, const v_int16x16& b, const v_int32x8& c) +{ return v_dotprod(a, b) + c; } + +#define OPENCV_HAL_AVX_SPLAT2_PS(a, im) \ + v_float32x8(_mm256_permute_ps(a.val, _MM_SHUFFLE(im, im, im, im))) + +inline v_float32x8 v_matmul(const v_float32x8& v, const v_float32x8& m0, + const v_float32x8& m1, const v_float32x8& m2, + const v_float32x8& m3) +{ + v_float32x8 v04 = OPENCV_HAL_AVX_SPLAT2_PS(v, 0); + v_float32x8 v15 = OPENCV_HAL_AVX_SPLAT2_PS(v, 1); + v_float32x8 v26 = OPENCV_HAL_AVX_SPLAT2_PS(v, 2); + v_float32x8 v37 = OPENCV_HAL_AVX_SPLAT2_PS(v, 3); + return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, v37 * m3))); +} + +inline v_float32x8 v_matmuladd(const v_float32x8& v, const v_float32x8& m0, + const v_float32x8& m1, const v_float32x8& m2, + const v_float32x8& a) +{ + v_float32x8 v04 = OPENCV_HAL_AVX_SPLAT2_PS(v, 0); + v_float32x8 v15 = OPENCV_HAL_AVX_SPLAT2_PS(v, 1); + v_float32x8 v26 = OPENCV_HAL_AVX_SPLAT2_PS(v, 2); + return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, a))); +} + +#define OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \ + inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \ + { \ + __m256i t0 = cast_from(_mm256_unpacklo_##suffix(a0.val, a1.val)); \ + __m256i t1 = cast_from(_mm256_unpacklo_##suffix(a2.val, a3.val)); \ + __m256i t2 = cast_from(_mm256_unpackhi_##suffix(a0.val, a1.val)); \ + __m256i t3 = cast_from(_mm256_unpackhi_##suffix(a2.val, a3.val)); \ + b0.val = cast_to(_mm256_unpacklo_epi64(t0, t1)); \ + b1.val = cast_to(_mm256_unpackhi_epi64(t0, t1)); \ + b2.val = cast_to(_mm256_unpacklo_epi64(t2, t3)); \ + b3.val = cast_to(_mm256_unpackhi_epi64(t2, t3)); \ + } + +OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_uint32x8, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_int32x8, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_float32x8, ps, _mm256_castps_si256, _mm256_castsi256_ps) + +//////////////// Value reordering /////////////// + +/* Expand */ +#define OPENCV_HAL_IMPL_AVX_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \ + inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ + { \ + b0.val = intrin(_v256_extract_low(a.val)); \ + b1.val = intrin(_v256_extract_high(a.val)); \ + } \ + inline _Tpwvec v_expand_low(const _Tpvec& a) \ + { return _Tpwvec(intrin(_v256_extract_low(a.val))); } \ + inline _Tpwvec v_expand_high(const _Tpvec& a) \ + { return _Tpwvec(intrin(_v256_extract_high(a.val))); } \ + inline _Tpwvec v256_load_expand(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadu_si128((const __m128i*)ptr); \ + return _Tpwvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_AVX_EXPAND(v_uint8x32, v_uint16x16, uchar, _mm256_cvtepu8_epi16) +OPENCV_HAL_IMPL_AVX_EXPAND(v_int8x32, v_int16x16, schar, _mm256_cvtepi8_epi16) +OPENCV_HAL_IMPL_AVX_EXPAND(v_uint16x16, v_uint32x8, ushort, _mm256_cvtepu16_epi32) +OPENCV_HAL_IMPL_AVX_EXPAND(v_int16x16, v_int32x8, short, _mm256_cvtepi16_epi32) +OPENCV_HAL_IMPL_AVX_EXPAND(v_uint32x8, v_uint64x4, unsigned, _mm256_cvtepu32_epi64) +OPENCV_HAL_IMPL_AVX_EXPAND(v_int32x8, v_int64x4, int, _mm256_cvtepi32_epi64) + +#define OPENCV_HAL_IMPL_AVX_EXPAND_Q(_Tpvec, _Tp, intrin) \ + inline _Tpvec v256_load_expand_q(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadl_epi64((const __m128i*)ptr); \ + return _Tpvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_AVX_EXPAND_Q(v_uint32x8, uchar, _mm256_cvtepu8_epi32) +OPENCV_HAL_IMPL_AVX_EXPAND_Q(v_int32x8, schar, _mm256_cvtepi8_epi32) + +/* pack */ +// 16 +inline v_int8x32 v_pack(const v_int16x16& a, const v_int16x16& b) +{ return v_int8x32(_v256_shuffle_odd_64(_mm256_packs_epi16(a.val, b.val))); } + +inline v_uint8x32 v_pack(const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i t = _mm256_set1_epi16(255); + __m256i a1 = _mm256_min_epu16(a.val, t); + __m256i b1 = _mm256_min_epu16(b.val, t); + return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a1, b1))); +} + +inline v_uint8x32 v_pack_u(const v_int16x16& a, const v_int16x16& b) +{ + return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a.val, b.val))); +} + +inline void v_pack_store(schar* ptr, const v_int16x16& a) +{ v_store_low(ptr, v_pack(a, a)); } + +inline void v_pack_store(uchar* ptr, const v_uint16x16& a) +{ + const __m256i m = _mm256_set1_epi16(255); + __m256i am = _mm256_min_epu16(a.val, m); + am = _v256_shuffle_odd_64(_mm256_packus_epi16(am, am)); + v_store_low(ptr, v_uint8x32(am)); +} + +inline void v_pack_u_store(uchar* ptr, const v_int16x16& a) +{ v_store_low(ptr, v_pack_u(a, a)); } + +template<int n> inline +v_uint8x32 v_rshr_pack(const v_uint16x16& a, const v_uint16x16& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + v_uint16x16 delta = v256_setall_u16((short)(1 << (n-1))); + return v_pack_u(v_reinterpret_as_s16((a + delta) >> n), + v_reinterpret_as_s16((b + delta) >> n)); +} + +template<int n> inline +void v_rshr_pack_store(uchar* ptr, const v_uint16x16& a) +{ + v_uint16x16 delta = v256_setall_u16((short)(1 << (n-1))); + v_pack_u_store(ptr, v_reinterpret_as_s16((a + delta) >> n)); +} + +template<int n> inline +v_uint8x32 v_rshr_pack_u(const v_int16x16& a, const v_int16x16& b) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + return v_pack_u((a + delta) >> n, (b + delta) >> n); +} + +template<int n> inline +void v_rshr_pack_u_store(uchar* ptr, const v_int16x16& a) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + v_pack_u_store(ptr, (a + delta) >> n); +} + +template<int n> inline +v_int8x32 v_rshr_pack(const v_int16x16& a, const v_int16x16& b) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template<int n> inline +void v_rshr_pack_store(schar* ptr, const v_int16x16& a) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + v_pack_store(ptr, (a + delta) >> n); +} + +// 32 +inline v_int16x16 v_pack(const v_int32x8& a, const v_int32x8& b) +{ return v_int16x16(_v256_shuffle_odd_64(_mm256_packs_epi32(a.val, b.val))); } + +inline v_uint16x16 v_pack(const v_uint32x8& a, const v_uint32x8& b) +{ return v_uint16x16(_v256_shuffle_odd_64(_v256_packs_epu32(a.val, b.val))); } + +inline v_uint16x16 v_pack_u(const v_int32x8& a, const v_int32x8& b) +{ return v_uint16x16(_v256_shuffle_odd_64(_mm256_packus_epi32(a.val, b.val))); } + +inline void v_pack_store(short* ptr, const v_int32x8& a) +{ v_store_low(ptr, v_pack(a, a)); } + +inline void v_pack_store(ushort* ptr, const v_uint32x8& a) +{ + const __m256i m = _mm256_set1_epi32(65535); + __m256i am = _mm256_min_epu32(a.val, m); + am = _v256_shuffle_odd_64(_mm256_packus_epi32(am, am)); + v_store_low(ptr, v_uint16x16(am)); +} + +inline void v_pack_u_store(ushort* ptr, const v_int32x8& a) +{ v_store_low(ptr, v_pack_u(a, a)); } + + +template<int n> inline +v_uint16x16 v_rshr_pack(const v_uint32x8& a, const v_uint32x8& b) +{ + // we assume that n > 0, and so the shifted 32-bit values can be treated as signed numbers. + v_uint32x8 delta = v256_setall_u32(1 << (n-1)); + return v_pack_u(v_reinterpret_as_s32((a + delta) >> n), + v_reinterpret_as_s32((b + delta) >> n)); +} + +template<int n> inline +void v_rshr_pack_store(ushort* ptr, const v_uint32x8& a) +{ + v_uint32x8 delta = v256_setall_u32(1 << (n-1)); + v_pack_u_store(ptr, v_reinterpret_as_s32((a + delta) >> n)); +} + +template<int n> inline +v_uint16x16 v_rshr_pack_u(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + return v_pack_u((a + delta) >> n, (b + delta) >> n); +} + +template<int n> inline +void v_rshr_pack_u_store(ushort* ptr, const v_int32x8& a) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + v_pack_u_store(ptr, (a + delta) >> n); +} + +template<int n> inline +v_int16x16 v_rshr_pack(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template<int n> inline +void v_rshr_pack_store(short* ptr, const v_int32x8& a) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +// 64 +// Non-saturating pack +inline v_uint32x8 v_pack(const v_uint64x4& a, const v_uint64x4& b) +{ + __m256i a0 = _mm256_shuffle_epi32(a.val, _MM_SHUFFLE(0, 0, 2, 0)); + __m256i b0 = _mm256_shuffle_epi32(b.val, _MM_SHUFFLE(0, 0, 2, 0)); + __m256i ab = _mm256_unpacklo_epi64(a0, b0); // a0, a1, b0, b1, a2, a3, b2, b3 + return v_uint32x8(_v256_shuffle_odd_64(ab)); +} + +inline v_int32x8 v_pack(const v_int64x4& a, const v_int64x4& b) +{ return v_reinterpret_as_s32(v_pack(v_reinterpret_as_u64(a), v_reinterpret_as_u64(b))); } + +inline void v_pack_store(unsigned* ptr, const v_uint64x4& a) +{ + __m256i a0 = _mm256_shuffle_epi32(a.val, _MM_SHUFFLE(0, 0, 2, 0)); + v_store_low(ptr, v_uint32x8(_v256_shuffle_odd_64(a0))); +} + +inline void v_pack_store(int* ptr, const v_int64x4& b) +{ v_pack_store((unsigned*)ptr, v_reinterpret_as_u64(b)); } + +template<int n> inline +v_uint32x8 v_rshr_pack(const v_uint64x4& a, const v_uint64x4& b) +{ + v_uint64x4 delta = v256_setall_u64((uint64)1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template<int n> inline +void v_rshr_pack_store(unsigned* ptr, const v_uint64x4& a) +{ + v_uint64x4 delta = v256_setall_u64((uint64)1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +template<int n> inline +v_int32x8 v_rshr_pack(const v_int64x4& a, const v_int64x4& b) +{ + v_int64x4 delta = v256_setall_s64((int64)1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template<int n> inline +void v_rshr_pack_store(int* ptr, const v_int64x4& a) +{ + v_int64x4 delta = v256_setall_s64((int64)1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +// pack boolean +inline v_uint8x32 v_pack_b(const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i ab = _mm256_packs_epi16(a.val, b.val); + return v_uint8x32(_v256_shuffle_odd_64(ab)); +} + +inline v_uint8x32 v_pack_b(const v_uint32x8& a, const v_uint32x8& b, + const v_uint32x8& c, const v_uint32x8& d) +{ + __m256i ab = _mm256_packs_epi32(a.val, b.val); + __m256i cd = _mm256_packs_epi32(c.val, d.val); + + __m256i abcd = _v256_shuffle_odd_64(_mm256_packs_epi16(ab, cd)); + return v_uint8x32(_mm256_shuffle_epi32(abcd, _MM_SHUFFLE(3, 1, 2, 0))); +} + +inline v_uint8x32 v_pack_b(const v_uint64x4& a, const v_uint64x4& b, const v_uint64x4& c, + const v_uint64x4& d, const v_uint64x4& e, const v_uint64x4& f, + const v_uint64x4& g, const v_uint64x4& h) +{ + __m256i ab = _mm256_packs_epi32(a.val, b.val); + __m256i cd = _mm256_packs_epi32(c.val, d.val); + __m256i ef = _mm256_packs_epi32(e.val, f.val); + __m256i gh = _mm256_packs_epi32(g.val, h.val); + + __m256i abcd = _mm256_packs_epi32(ab, cd); + __m256i efgh = _mm256_packs_epi32(ef, gh); + __m256i pkall = _v256_shuffle_odd_64(_mm256_packs_epi16(abcd, efgh)); + + __m256i rev = _mm256_alignr_epi8(pkall, pkall, 8); + return v_uint8x32(_mm256_unpacklo_epi16(pkall, rev)); +} + +/* Recombine */ +// its up there with load and store operations + +/* Extract */ +#define OPENCV_HAL_IMPL_AVX_EXTRACT(_Tpvec) \ + template<int s> \ + inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ + { return v_rotate_right<s>(a, b); } + +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint8x32) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int8x32) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint16x16) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int16x16) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint32x8) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int32x8) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint64x4) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int64x4) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_float32x8) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_float64x4) + + +///////////////////// load deinterleave ///////////////////////////// + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + + const __m256i sh = _mm256_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15, + 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15); + __m256i p0 = _mm256_shuffle_epi8(ab0, sh); + __m256i p1 = _mm256_shuffle_epi8(ab1, sh); + __m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint8x32(a0); + b = v_uint8x32(b0); +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + + const __m256i sh = _mm256_setr_epi8(0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15, + 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15); + __m256i p0 = _mm256_shuffle_epi8(ab0, sh); + __m256i p1 = _mm256_shuffle_epi8(ab1, sh); + __m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint16x16(a0); + b = v_uint16x16(b0); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + + const int sh = 0+2*4+1*16+3*64; + __m256i p0 = _mm256_shuffle_epi32(ab0, sh); + __m256i p1 = _mm256_shuffle_epi32(ab1, sh); + __m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint32x8(a0); + b = v_uint32x8(b0); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 4)); + + __m256i pl = _mm256_permute2x128_si256(ab0, ab1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(ab0, ab1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint64x4(a0); + b = v_uint64x4(b0); +} + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b, v_uint8x32& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 64)); + + __m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16); + __m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16); + + const __m256i m0 = _mm256_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, + 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, + -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1); + + __m256i b0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_low, s02_high, m0), bgr1, m1); + __m256i g0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_high, s02_low, m1), bgr1, m0); + __m256i r0 = _mm256_blendv_epi8(_mm256_blendv_epi8(bgr1, s02_low, m0), s02_high, m1); + + const __m256i + sh_b = _mm256_setr_epi8(0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13, + 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13), + sh_g = _mm256_setr_epi8(1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, + 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14), + sh_r = _mm256_setr_epi8(2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, + 2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15); + b0 = _mm256_shuffle_epi8(b0, sh_b); + g0 = _mm256_shuffle_epi8(g0, sh_g); + r0 = _mm256_shuffle_epi8(r0, sh_r); + + a = v_uint8x32(b0); + b = v_uint8x32(g0); + c = v_uint8x32(r0); +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b, v_uint16x16& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + + __m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16); + __m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16); + + const __m256i m0 = _mm256_setr_epi8(0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, + 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, + -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0); + __m256i b0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_low, s02_high, m0), bgr1, m1); + __m256i g0 = _mm256_blendv_epi8(_mm256_blendv_epi8(bgr1, s02_low, m0), s02_high, m1); + __m256i r0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_high, s02_low, m1), bgr1, m0); + const __m256i sh_b = _mm256_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11, + 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m256i sh_g = _mm256_setr_epi8(2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, + 2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13); + const __m256i sh_r = _mm256_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, + 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + b0 = _mm256_shuffle_epi8(b0, sh_b); + g0 = _mm256_shuffle_epi8(g0, sh_g); + r0 = _mm256_shuffle_epi8(r0, sh_r); + + a = v_uint16x16(b0); + b = v_uint16x16(g0); + c = v_uint16x16(r0); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b, v_uint32x8& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + + __m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16); + __m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16); + + __m256i b0 = _mm256_blend_epi32(_mm256_blend_epi32(s02_low, s02_high, 0x24), bgr1, 0x92); + __m256i g0 = _mm256_blend_epi32(_mm256_blend_epi32(s02_high, s02_low, 0x92), bgr1, 0x24); + __m256i r0 = _mm256_blend_epi32(_mm256_blend_epi32(bgr1, s02_low, 0x24), s02_high, 0x92); + + b0 = _mm256_shuffle_epi32(b0, 0x6c); + g0 = _mm256_shuffle_epi32(g0, 0xb1); + r0 = _mm256_shuffle_epi32(r0, 0xc6); + + a = v_uint32x8(b0); + b = v_uint32x8(g0); + c = v_uint32x8(r0); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b, v_uint64x4& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 4)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + + __m256i s01 = _mm256_blend_epi32(bgr0, bgr1, 0xf0); + __m256i s12 = _mm256_blend_epi32(bgr1, bgr2, 0xf0); + __m256i s20r = _mm256_permute4x64_epi64(_mm256_blend_epi32(bgr2, bgr0, 0xf0), 0x1b); + __m256i b0 = _mm256_unpacklo_epi64(s01, s20r); + __m256i g0 = _mm256_alignr_epi8(s12, s01, 8); + __m256i r0 = _mm256_unpackhi_epi64(s20r, s12); + + a = v_uint64x4(b0); + b = v_uint64x4(g0); + c = v_uint64x4(r0); +} + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b, v_uint8x32& c, v_uint8x32& d ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 64)); + __m256i bgr3 = _mm256_loadu_si256((const __m256i*)(ptr + 96)); + const __m256i sh = _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, + 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); + + __m256i p0 = _mm256_shuffle_epi8(bgr0, sh); + __m256i p1 = _mm256_shuffle_epi8(bgr1, sh); + __m256i p2 = _mm256_shuffle_epi8(bgr2, sh); + __m256i p3 = _mm256_shuffle_epi8(bgr3, sh); + + __m256i p01l = _mm256_unpacklo_epi32(p0, p1); + __m256i p01h = _mm256_unpackhi_epi32(p0, p1); + __m256i p23l = _mm256_unpacklo_epi32(p2, p3); + __m256i p23h = _mm256_unpackhi_epi32(p2, p3); + + __m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16); + __m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16); + __m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16); + __m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi32(pll, plh); + __m256i g0 = _mm256_unpackhi_epi32(pll, plh); + __m256i r0 = _mm256_unpacklo_epi32(phl, phh); + __m256i a0 = _mm256_unpackhi_epi32(phl, phh); + + a = v_uint8x32(b0); + b = v_uint8x32(g0); + c = v_uint8x32(r0); + d = v_uint8x32(a0); +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b, v_uint16x16& c, v_uint16x16& d ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + __m256i bgr3 = _mm256_loadu_si256((const __m256i*)(ptr + 48)); + const __m256i sh = _mm256_setr_epi8(0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15, + 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15); + __m256i p0 = _mm256_shuffle_epi8(bgr0, sh); + __m256i p1 = _mm256_shuffle_epi8(bgr1, sh); + __m256i p2 = _mm256_shuffle_epi8(bgr2, sh); + __m256i p3 = _mm256_shuffle_epi8(bgr3, sh); + + __m256i p01l = _mm256_unpacklo_epi32(p0, p1); + __m256i p01h = _mm256_unpackhi_epi32(p0, p1); + __m256i p23l = _mm256_unpacklo_epi32(p2, p3); + __m256i p23h = _mm256_unpackhi_epi32(p2, p3); + + __m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16); + __m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16); + __m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16); + __m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi32(pll, plh); + __m256i g0 = _mm256_unpackhi_epi32(pll, plh); + __m256i r0 = _mm256_unpacklo_epi32(phl, phh); + __m256i a0 = _mm256_unpackhi_epi32(phl, phh); + + a = v_uint16x16(b0); + b = v_uint16x16(g0); + c = v_uint16x16(r0); + d = v_uint16x16(a0); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b, v_uint32x8& c, v_uint32x8& d ) +{ + __m256i p0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i p1 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + __m256i p2 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + __m256i p3 = _mm256_loadu_si256((const __m256i*)(ptr + 24)); + + __m256i p01l = _mm256_unpacklo_epi32(p0, p1); + __m256i p01h = _mm256_unpackhi_epi32(p0, p1); + __m256i p23l = _mm256_unpacklo_epi32(p2, p3); + __m256i p23h = _mm256_unpackhi_epi32(p2, p3); + + __m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16); + __m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16); + __m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16); + __m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi32(pll, plh); + __m256i g0 = _mm256_unpackhi_epi32(pll, plh); + __m256i r0 = _mm256_unpacklo_epi32(phl, phh); + __m256i a0 = _mm256_unpackhi_epi32(phl, phh); + + a = v_uint32x8(b0); + b = v_uint32x8(g0); + c = v_uint32x8(r0); + d = v_uint32x8(a0); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b, v_uint64x4& c, v_uint64x4& d ) +{ + __m256i bgra0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgra1 = _mm256_loadu_si256((const __m256i*)(ptr + 4)); + __m256i bgra2 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + __m256i bgra3 = _mm256_loadu_si256((const __m256i*)(ptr + 12)); + + __m256i l02 = _mm256_permute2x128_si256(bgra0, bgra2, 0 + 2*16); + __m256i h02 = _mm256_permute2x128_si256(bgra0, bgra2, 1 + 3*16); + __m256i l13 = _mm256_permute2x128_si256(bgra1, bgra3, 0 + 2*16); + __m256i h13 = _mm256_permute2x128_si256(bgra1, bgra3, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi64(l02, l13); + __m256i g0 = _mm256_unpackhi_epi64(l02, l13); + __m256i r0 = _mm256_unpacklo_epi64(h02, h13); + __m256i a0 = _mm256_unpackhi_epi64(h02, h13); + + a = v_uint64x4(b0); + b = v_uint64x4(g0); + c = v_uint64x4(r0); + d = v_uint64x4(a0); +} + +///////////////////////////// store interleave ///////////////////////////////////// + +inline void v_store_interleave( uchar* ptr, const v_uint8x32& x, const v_uint8x32& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi8(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi8(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 32), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 32), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 32), xy1); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x16& x, const v_uint16x16& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi16(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi16(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 16), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 16), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 16), xy1); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x8& x, const v_uint32x8& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi32(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi32(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 8), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 8), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 8), xy1); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x4& x, const v_uint64x4& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi64(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi64(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 4), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 4), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 4), xy1); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x32& a, const v_uint8x32& b, const v_uint8x32& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + const __m256i sh_b = _mm256_setr_epi8( + 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5, + 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5); + const __m256i sh_g = _mm256_setr_epi8( + 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, + 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10); + const __m256i sh_r = _mm256_setr_epi8( + 10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, + 10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15); + + __m256i b0 = _mm256_shuffle_epi8(a.val, sh_b); + __m256i g0 = _mm256_shuffle_epi8(b.val, sh_g); + __m256i r0 = _mm256_shuffle_epi8(c.val, sh_r); + + const __m256i m0 = _mm256_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, + 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, + 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0); + + __m256i p0 = _mm256_blendv_epi8(_mm256_blendv_epi8(b0, g0, m0), r0, m1); + __m256i p1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g0, r0, m0), b0, m1); + __m256i p2 = _mm256_blendv_epi8(_mm256_blendv_epi8(r0, b0, m0), g0, m1); + + __m256i bgr0 = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i bgr1 = _mm256_permute2x128_si256(p2, p0, 0 + 3*16); + __m256i bgr2 = _mm256_permute2x128_si256(p1, p2, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 32), bgr1); + _mm256_stream_si256((__m256i*)(ptr + 64), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 32), bgr1); + _mm256_store_si256((__m256i*)(ptr + 64), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgr1); + _mm256_storeu_si256((__m256i*)(ptr + 64), bgr2); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x16& a, const v_uint16x16& b, const v_uint16x16& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + const __m256i sh_b = _mm256_setr_epi8( + 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11, + 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m256i sh_g = _mm256_setr_epi8( + 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, + 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5); + const __m256i sh_r = _mm256_setr_epi8( + 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, + 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + + __m256i b0 = _mm256_shuffle_epi8(a.val, sh_b); + __m256i g0 = _mm256_shuffle_epi8(b.val, sh_g); + __m256i r0 = _mm256_shuffle_epi8(c.val, sh_r); + + const __m256i m0 = _mm256_setr_epi8(0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, + 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, + -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0); + + __m256i p0 = _mm256_blendv_epi8(_mm256_blendv_epi8(b0, g0, m0), r0, m1); + __m256i p1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g0, r0, m0), b0, m1); + __m256i p2 = _mm256_blendv_epi8(_mm256_blendv_epi8(r0, b0, m0), g0, m1); + + __m256i bgr0 = _mm256_permute2x128_si256(p0, p2, 0 + 2*16); + //__m256i bgr1 = p1; + __m256i bgr2 = _mm256_permute2x128_si256(p0, p2, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 16), p1); + _mm256_stream_si256((__m256i*)(ptr + 32), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 16), p1); + _mm256_store_si256((__m256i*)(ptr + 32), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 16), p1); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgr2); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x8& a, const v_uint32x8& b, const v_uint32x8& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i b0 = _mm256_shuffle_epi32(a.val, 0x6c); + __m256i g0 = _mm256_shuffle_epi32(b.val, 0xb1); + __m256i r0 = _mm256_shuffle_epi32(c.val, 0xc6); + + __m256i p0 = _mm256_blend_epi32(_mm256_blend_epi32(b0, g0, 0x92), r0, 0x24); + __m256i p1 = _mm256_blend_epi32(_mm256_blend_epi32(g0, r0, 0x92), b0, 0x24); + __m256i p2 = _mm256_blend_epi32(_mm256_blend_epi32(r0, b0, 0x92), g0, 0x24); + + __m256i bgr0 = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + //__m256i bgr1 = p2; + __m256i bgr2 = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 8), p2); + _mm256_stream_si256((__m256i*)(ptr + 16), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 8), p2); + _mm256_store_si256((__m256i*)(ptr + 16), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 8), p2); + _mm256_storeu_si256((__m256i*)(ptr + 16), bgr2); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x4& a, const v_uint64x4& b, const v_uint64x4& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i s01 = _mm256_unpacklo_epi64(a.val, b.val); + __m256i s12 = _mm256_unpackhi_epi64(b.val, c.val); + __m256i s20 = _mm256_blend_epi32(c.val, a.val, 0xcc); + + __m256i bgr0 = _mm256_permute2x128_si256(s01, s20, 0 + 2*16); + __m256i bgr1 = _mm256_blend_epi32(s01, s12, 0x0f); + __m256i bgr2 = _mm256_permute2x128_si256(s20, s12, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 4), bgr1); + _mm256_stream_si256((__m256i*)(ptr + 8), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 4), bgr1); + _mm256_store_si256((__m256i*)(ptr + 8), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 4), bgr1); + _mm256_storeu_si256((__m256i*)(ptr + 8), bgr2); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x32& a, const v_uint8x32& b, + const v_uint8x32& c, const v_uint8x32& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi8(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi8(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi8(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi8(c.val, d.val); + + __m256i bgra0_ = _mm256_unpacklo_epi16(bg0, ra0); + __m256i bgra1_ = _mm256_unpackhi_epi16(bg0, ra0); + __m256i bgra2_ = _mm256_unpacklo_epi16(bg1, ra1); + __m256i bgra3_ = _mm256_unpackhi_epi16(bg1, ra1); + + __m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16); + __m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16); + __m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 32), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 64), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 96), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 32), bgra1); + _mm256_store_si256((__m256i*)(ptr + 64), bgra2); + _mm256_store_si256((__m256i*)(ptr + 96), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 64), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 96), bgra3); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x16& a, const v_uint16x16& b, + const v_uint16x16& c, const v_uint16x16& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi16(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi16(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi16(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi16(c.val, d.val); + + __m256i bgra0_ = _mm256_unpacklo_epi32(bg0, ra0); + __m256i bgra1_ = _mm256_unpackhi_epi32(bg0, ra0); + __m256i bgra2_ = _mm256_unpacklo_epi32(bg1, ra1); + __m256i bgra3_ = _mm256_unpackhi_epi32(bg1, ra1); + + __m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16); + __m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16); + __m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 16), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 32), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 48), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 16), bgra1); + _mm256_store_si256((__m256i*)(ptr + 32), bgra2); + _mm256_store_si256((__m256i*)(ptr + 48), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 16), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 48), bgra3); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x8& a, const v_uint32x8& b, + const v_uint32x8& c, const v_uint32x8& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi32(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi32(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi32(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi32(c.val, d.val); + + __m256i bgra0_ = _mm256_unpacklo_epi64(bg0, ra0); + __m256i bgra1_ = _mm256_unpackhi_epi64(bg0, ra0); + __m256i bgra2_ = _mm256_unpacklo_epi64(bg1, ra1); + __m256i bgra3_ = _mm256_unpackhi_epi64(bg1, ra1); + + __m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16); + __m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16); + __m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 8), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 16), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 24), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 8), bgra1); + _mm256_store_si256((__m256i*)(ptr + 16), bgra2); + _mm256_store_si256((__m256i*)(ptr + 24), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 8), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 16), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 24), bgra3); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x4& a, const v_uint64x4& b, + const v_uint64x4& c, const v_uint64x4& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi64(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi64(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi64(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi64(c.val, d.val); + + __m256i bgra0 = _mm256_permute2x128_si256(bg0, ra0, 0 + 2*16); + __m256i bgra1 = _mm256_permute2x128_si256(bg1, ra1, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bg0, ra0, 1 + 3*16); + __m256i bgra3 = _mm256_permute2x128_si256(bg1, ra1, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 4), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 8), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 12), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 4), bgra1); + _mm256_store_si256((__m256i*)(ptr + 8), bgra2); + _mm256_store_si256((__m256i*)(ptr + 12), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 4), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 8), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 12), bgra3); + } +} + +#define OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \ +{ \ + _Tpvec1 a1, b1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \ +{ \ + _Tpvec1 a1, b1, c1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \ +{ \ + _Tpvec1 a1, b1, c1, d1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ + d0 = v_reinterpret_as_##suffix0(d1); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, const _Tpvec0& c0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, const _Tpvec0& d0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \ +} + +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int8x32, schar, s8, v_uint8x32, uchar, u8) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int16x16, short, s16, v_uint16x16, ushort, u16) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int32x8, int, s32, v_uint32x8, unsigned, u32) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float32x8, float, f32, v_uint32x8, unsigned, u32) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int64x4, int64, s64, v_uint64x4, uint64, u64) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float64x4, double, f64, v_uint64x4, uint64, u64) + +// FP16 +inline v_float32x8 v256_load_expand(const float16_t* ptr) +{ + return v_float32x8(_mm256_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr))); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x8& a) +{ + __m128i ah = _mm256_cvtps_ph(a.val, 0); + _mm_storeu_si128((__m128i*)ptr, ah); +} + +inline void v256_cleanup() { _mm256_zeroall(); } + +//! @name Check SIMD256 support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD256() +{ + return (CV_CPU_HAS_SUPPORT_AVX2) ? true : false; +} +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: + +#endif // OPENCV_HAL_INTRIN_AVX_HPP diff --git a/include/opencv2/core/hal/intrin_cpp.hpp b/include/opencv2/core/hal/intrin_cpp.hpp new file mode 100644 index 0000000..757c67b --- /dev/null +++ b/include/opencv2/core/hal/intrin_cpp.hpp @@ -0,0 +1,2382 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HAL_INTRIN_CPP_HPP +#define OPENCV_HAL_INTRIN_CPP_HPP + +#include <limits> +#include <cstring> +#include <algorithm> +#include "opencv2/core/saturate.hpp" + +namespace cv +{ + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + +/** @addtogroup core_hal_intrin + +"Universal intrinsics" is a types and functions set intended to simplify vectorization of code on +different platforms. Currently there are two supported SIMD extensions: __SSE/SSE2__ on x86 +architectures and __NEON__ on ARM architectures, both allow working with 128 bit registers +containing packed values of different types. In case when there is no SIMD extension available +during compilation, fallback C++ implementation of intrinsics will be chosen and code will work as +expected although it could be slower. + +### Types + +There are several types representing 128-bit register as a vector of packed values, each type is +implemented as a structure based on a one SIMD register. + +- cv::v_uint8x16 and cv::v_int8x16: sixteen 8-bit integer values (unsigned/signed) - char +- cv::v_uint16x8 and cv::v_int16x8: eight 16-bit integer values (unsigned/signed) - short +- cv::v_uint32x4 and cv::v_int32x4: four 32-bit integer values (unsgined/signed) - int +- cv::v_uint64x2 and cv::v_int64x2: two 64-bit integer values (unsigned/signed) - int64 +- cv::v_float32x4: four 32-bit floating point values (signed) - float +- cv::v_float64x2: two 64-bit floating point valies (signed) - double + +@note +cv::v_float64x2 is not implemented in NEON variant, if you want to use this type, don't forget to +check the CV_SIMD128_64F preprocessor definition: +@code +#if CV_SIMD128_64F +//... +#endif +@endcode + +### Load and store operations + +These operations allow to set contents of the register explicitly or by loading it from some memory +block and to save contents of the register to memory block. + +- Constructors: +@ref v_reg::v_reg(const _Tp *ptr) "from memory", +@ref v_reg::v_reg(_Tp s0, _Tp s1) "from two values", ... +- Other create methods: +@ref v_setall_s8, @ref v_setall_u8, ..., +@ref v_setzero_u8, @ref v_setzero_s8, ... +- Memory operations: +@ref v_load, @ref v_load_aligned, @ref v_load_low, @ref v_load_halves, +@ref v_store, @ref v_store_aligned, +@ref v_store_high, @ref v_store_low + +### Value reordering + +These operations allow to reorder or recombine elements in one or multiple vectors. + +- Interleave, deinterleave (2, 3 and 4 channels): @ref v_load_deinterleave, @ref v_store_interleave +- Expand: @ref v_load_expand, @ref v_load_expand_q, @ref v_expand, @ref v_expand_low, @ref v_expand_high +- Pack: @ref v_pack, @ref v_pack_u, @ref v_pack_b, @ref v_rshr_pack, @ref v_rshr_pack_u, +@ref v_pack_store, @ref v_pack_u_store, @ref v_rshr_pack_store, @ref v_rshr_pack_u_store +- Recombine: @ref v_zip, @ref v_recombine, @ref v_combine_low, @ref v_combine_high +- Extract: @ref v_extract + + +### Arithmetic, bitwise and comparison operations + +Element-wise binary and unary operations. + +- Arithmetics: +@ref operator +(const v_reg &a, const v_reg &b) "+", +@ref operator -(const v_reg &a, const v_reg &b) "-", +@ref operator *(const v_reg &a, const v_reg &b) "*", +@ref operator /(const v_reg &a, const v_reg &b) "/", +@ref v_mul_expand + +- Non-saturating arithmetics: @ref v_add_wrap, @ref v_sub_wrap + +- Bitwise shifts: +@ref operator <<(const v_reg &a, int s) "<<", +@ref operator >>(const v_reg &a, int s) ">>", +@ref v_shl, @ref v_shr + +- Bitwise logic: +@ref operator&(const v_reg &a, const v_reg &b) "&", +@ref operator |(const v_reg &a, const v_reg &b) "|", +@ref operator ^(const v_reg &a, const v_reg &b) "^", +@ref operator ~(const v_reg &a) "~" + +- Comparison: +@ref operator >(const v_reg &a, const v_reg &b) ">", +@ref operator >=(const v_reg &a, const v_reg &b) ">=", +@ref operator <(const v_reg &a, const v_reg &b) "<", +@ref operator <=(const v_reg &a, const v_reg &b) "<=", +@ref operator==(const v_reg &a, const v_reg &b) "==", +@ref operator !=(const v_reg &a, const v_reg &b) "!=" + +- min/max: @ref v_min, @ref v_max + +### Reduce and mask + +Most of these operations return only one value. + +- Reduce: @ref v_reduce_min, @ref v_reduce_max, @ref v_reduce_sum, @ref v_popcount +- Mask: @ref v_signmask, @ref v_check_all, @ref v_check_any, @ref v_select + +### Other math + +- Some frequent operations: @ref v_sqrt, @ref v_invsqrt, @ref v_magnitude, @ref v_sqr_magnitude +- Absolute values: @ref v_abs, @ref v_absdiff, @ref v_absdiffs + +### Conversions + +Different type conversions and casts: + +- Rounding: @ref v_round, @ref v_floor, @ref v_ceil, @ref v_trunc, +- To float: @ref v_cvt_f32, @ref v_cvt_f64 +- Reinterpret: @ref v_reinterpret_as_u8, @ref v_reinterpret_as_s8, ... + +### Matrix operations + +In these operations vectors represent matrix rows/columns: @ref v_dotprod, @ref v_matmul, @ref v_transpose4x4 + +### Usability + +Most operations are implemented only for some subset of the available types, following matrices +shows the applicability of different operations to the types. + +Regular integers: + +| Operations\\Types | uint 8x16 | int 8x16 | uint 16x8 | int 16x8 | uint 32x4 | int 32x4 | +|-------------------|:-:|:-:|:-:|:-:|:-:|:-:| +|load, store | x | x | x | x | x | x | +|interleave | x | x | x | x | x | x | +|expand | x | x | x | x | x | x | +|expand_low | x | x | x | x | x | x | +|expand_high | x | x | x | x | x | x | +|expand_q | x | x | | | | | +|add, sub | x | x | x | x | x | x | +|add_wrap, sub_wrap | x | x | x | x | | | +|mul_wrap | x | x | x | x | | | +|mul | x | x | x | x | x | x | +|mul_expand | x | x | x | x | x | | +|compare | x | x | x | x | x | x | +|shift | | | x | x | x | x | +|dotprod | | | | x | | | +|logical | x | x | x | x | x | x | +|min, max | x | x | x | x | x | x | +|absdiff | x | x | x | x | x | x | +|absdiffs | | x | | x | | | +|reduce | | | | | x | x | +|mask | x | x | x | x | x | x | +|pack | x | x | x | x | x | x | +|pack_u | x | | x | | | | +|pack_b | x | | | | | | +|unpack | x | x | x | x | x | x | +|extract | x | x | x | x | x | x | +|rotate (lanes) | x | x | x | x | x | x | +|cvt_flt32 | | | | | | x | +|cvt_flt64 | | | | | | x | +|transpose4x4 | | | | | x | x | + +Big integers: + +| Operations\\Types | uint 64x2 | int 64x2 | +|-------------------|:-:|:-:| +|load, store | x | x | +|add, sub | x | x | +|shift | x | x | +|logical | x | x | +|extract | x | x | +|rotate (lanes) | x | x | + +Floating point: + +| Operations\\Types | float 32x4 | float 64x2 | +|-------------------|:-:|:-:| +|load, store | x | x | +|interleave | x | | +|add, sub | x | x | +|mul | x | x | +|div | x | x | +|compare | x | x | +|min, max | x | x | +|absdiff | x | x | +|reduce | x | | +|mask | x | x | +|unpack | x | x | +|cvt_flt32 | | x | +|cvt_flt64 | x | | +|sqrt, abs | x | x | +|float math | x | x | +|transpose4x4 | x | | +|extract | x | x | +|rotate (lanes) | x | x | + + @{ */ + +template<typename _Tp, int n> struct v_reg +{ +//! @cond IGNORED + typedef _Tp lane_type; + enum { nlanes = n }; +// !@endcond + + /** @brief Constructor + + Initializes register with data from memory + @param ptr pointer to memory block with data for register */ + explicit v_reg(const _Tp* ptr) { for( int i = 0; i < n; i++ ) s[i] = ptr[i]; } + + /** @brief Constructor + + Initializes register with two 64-bit values */ + v_reg(_Tp s0, _Tp s1) { s[0] = s0; s[1] = s1; } + + /** @brief Constructor + + Initializes register with four 32-bit values */ + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3) { s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; } + + /** @brief Constructor + + Initializes register with eight 16-bit values */ + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, + _Tp s4, _Tp s5, _Tp s6, _Tp s7) + { + s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; + s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; + } + + /** @brief Constructor + + Initializes register with sixteen 8-bit values */ + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, + _Tp s4, _Tp s5, _Tp s6, _Tp s7, + _Tp s8, _Tp s9, _Tp s10, _Tp s11, + _Tp s12, _Tp s13, _Tp s14, _Tp s15) + { + s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; + s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; + s[8] = s8; s[9] = s9; s[10] = s10; s[11] = s11; + s[12] = s12; s[13] = s13; s[14] = s14; s[15] = s15; + } + + /** @brief Default constructor + + Does not initialize anything*/ + v_reg() {} + + /** @brief Copy constructor */ + v_reg(const v_reg<_Tp, n> & r) + { + for( int i = 0; i < n; i++ ) + s[i] = r.s[i]; + } + /** @brief Access first value + + Returns value of the first lane according to register type, for example: + @code{.cpp} + v_int32x4 r(1, 2, 3, 4); + int v = r.get0(); // returns 1 + v_uint64x2 r(1, 2); + uint64_t v = r.get0(); // returns 1 + @endcode + */ + _Tp get0() const { return s[0]; } + +//! @cond IGNORED + _Tp get(const int i) const { return s[i]; } + v_reg<_Tp, n> high() const + { + v_reg<_Tp, n> c; + int i; + for( i = 0; i < n/2; i++ ) + { + c.s[i] = s[i+(n/2)]; + c.s[i+(n/2)] = 0; + } + return c; + } + + static v_reg<_Tp, n> zero() + { + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (_Tp)0; + return c; + } + + static v_reg<_Tp, n> all(_Tp s) + { + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = s; + return c; + } + + template<typename _Tp2, int n2> v_reg<_Tp2, n2> reinterpret_as() const + { + size_t bytes = std::min(sizeof(_Tp2)*n2, sizeof(_Tp)*n); + v_reg<_Tp2, n2> c; + std::memcpy(&c.s[0], &s[0], bytes); + return c; + } + + _Tp s[n]; +//! @endcond +}; + +/** @brief Sixteen 8-bit unsigned integer values */ +typedef v_reg<uchar, 16> v_uint8x16; +/** @brief Sixteen 8-bit signed integer values */ +typedef v_reg<schar, 16> v_int8x16; +/** @brief Eight 16-bit unsigned integer values */ +typedef v_reg<ushort, 8> v_uint16x8; +/** @brief Eight 16-bit signed integer values */ +typedef v_reg<short, 8> v_int16x8; +/** @brief Four 32-bit unsigned integer values */ +typedef v_reg<unsigned, 4> v_uint32x4; +/** @brief Four 32-bit signed integer values */ +typedef v_reg<int, 4> v_int32x4; +/** @brief Four 32-bit floating point values (single precision) */ +typedef v_reg<float, 4> v_float32x4; +/** @brief Two 64-bit floating point values (double precision) */ +typedef v_reg<double, 2> v_float64x2; +/** @brief Two 64-bit unsigned integer values */ +typedef v_reg<uint64, 2> v_uint64x2; +/** @brief Two 64-bit signed integer values */ +typedef v_reg<int64, 2> v_int64x2; + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_BIN_OP(bin_op) \ +template<typename _Tp, int n> inline v_reg<_Tp, n> \ + operator bin_op (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ + return c; \ +} \ +template<typename _Tp, int n> inline v_reg<_Tp, n>& \ + operator bin_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + for( int i = 0; i < n; i++ ) \ + a.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ + return a; \ +} + +/** @brief Add values + +For all types. */ +OPENCV_HAL_IMPL_BIN_OP(+) + +/** @brief Subtract values + +For all types. */ +OPENCV_HAL_IMPL_BIN_OP(-) + +/** @brief Multiply values + +For 16- and 32-bit integer types and floating types. */ +OPENCV_HAL_IMPL_BIN_OP(*) + +/** @brief Divide values + +For floating types only. */ +OPENCV_HAL_IMPL_BIN_OP(/) + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_BIT_OP(bit_op) \ +template<typename _Tp, int n> inline v_reg<_Tp, n> operator bit_op \ + (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ + V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ + return c; \ +} \ +template<typename _Tp, int n> inline v_reg<_Tp, n>& operator \ + bit_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + for( int i = 0; i < n; i++ ) \ + a.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ + V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ + return a; \ +} + +/** @brief Bitwise AND + +Only for integer types. */ +OPENCV_HAL_IMPL_BIT_OP(&) + +/** @brief Bitwise OR + +Only for integer types. */ +OPENCV_HAL_IMPL_BIT_OP(|) + +/** @brief Bitwise XOR + +Only for integer types.*/ +OPENCV_HAL_IMPL_BIT_OP(^) + +/** @brief Bitwise NOT + +Only for integer types.*/ +template<typename _Tp, int n> inline v_reg<_Tp, n> operator ~ (const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int(~V_TypeTraits<_Tp>::reinterpret_int(a.s[i])); + } + return c; +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_MATH_FUNC(func, cfunc, _Tp2) \ +template<typename _Tp, int n> inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp2, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cfunc(a.s[i]); \ + return c; \ +} + +/** @brief Square root of elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_sqrt, std::sqrt, _Tp) + +//! @cond IGNORED +OPENCV_HAL_IMPL_MATH_FUNC(v_sin, std::sin, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_cos, std::cos, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_exp, std::exp, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_log, std::log, _Tp) +//! @endcond + +/** @brief Absolute value of elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_abs, (typename V_TypeTraits<_Tp>::abs_type)std::abs, + typename V_TypeTraits<_Tp>::abs_type) + +/** @brief Round elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_round, cvRound, int) + +/** @brief Floor elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_floor, cvFloor, int) + +/** @brief Ceil elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_ceil, cvCeil, int) + +/** @brief Truncate elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_trunc, int, int) + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_MINMAX_FUNC(func, cfunc) \ +template<typename _Tp, int n> inline v_reg<_Tp, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cfunc(a.s[i], b.s[i]); \ + return c; \ +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(func, cfunc) \ +template<typename _Tp, int n> inline _Tp func(const v_reg<_Tp, n>& a) \ +{ \ + _Tp c = a.s[0]; \ + for( int i = 1; i < n; i++ ) \ + c = cfunc(c, a.s[i]); \ + return c; \ +} + +/** @brief Choose min values for each pair + +Scheme: +@code +{A1 A2 ...} +{B1 B2 ...} +-------------- +{min(A1,B1) min(A2,B2) ...} +@endcode +For all types except 64-bit integer. */ +OPENCV_HAL_IMPL_MINMAX_FUNC(v_min, std::min) + +/** @brief Choose max values for each pair + +Scheme: +@code +{A1 A2 ...} +{B1 B2 ...} +-------------- +{max(A1,B1) max(A2,B2) ...} +@endcode +For all types except 64-bit integer. */ +OPENCV_HAL_IMPL_MINMAX_FUNC(v_max, std::max) + +/** @brief Find one min value + +Scheme: +@code +{A1 A2 A3 ...} => min(A1,A2,A3,...) +@endcode +For 32-bit integer and 32-bit floating point types. */ +OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_min, std::min) + +/** @brief Find one max value + +Scheme: +@code +{A1 A2 A3 ...} => max(A1,A2,A3,...) +@endcode +For 32-bit integer and 32-bit floating point types. */ +OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_max, std::max) + +static const unsigned char popCountTable[] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; +/** @brief Count the 1 bits in the vector and return 4 values + +Scheme: +@code +{A1 A2 A3 ...} => popcount(A1) +@endcode +Any types but result will be in v_uint32x4*/ +template<typename _Tp, int n> inline v_uint32x4 v_popcount(const v_reg<_Tp, n>& a) +{ + v_uint8x16 b; + b = v_reinterpret_as_u8(a); + for( int i = 0; i < v_uint8x16::nlanes; i++ ) + { + b.s[i] = popCountTable[b.s[i]]; + } + v_uint32x4 c; + for( int i = 0; i < v_uint32x4::nlanes; i++ ) + { + c.s[i] = b.s[i*4] + b.s[i*4+1] + b.s[i*4+2] + b.s[i*4+3]; + } + return c; +} + + +//! @cond IGNORED +template<typename _Tp, int n> +inline void v_minmax( const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<_Tp, n>& minval, v_reg<_Tp, n>& maxval ) +{ + for( int i = 0; i < n; i++ ) + { + minval.s[i] = std::min(a.s[i], b.s[i]); + maxval.s[i] = std::max(a.s[i], b.s[i]); + } +} +//! @endcond + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_CMP_OP(cmp_op) \ +template<typename _Tp, int n> \ +inline v_reg<_Tp, n> operator cmp_op(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)-(int)(a.s[i] cmp_op b.s[i])); \ + return c; \ +} + +/** @brief Less-than comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(<) + +/** @brief Greater-than comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(>) + +/** @brief Less-than or equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(<=) + +/** @brief Greater-than or equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(>=) + +/** @brief Equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(==) + +/** @brief Not equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(!=) + +template<int n> +inline v_reg<float, n> v_not_nan(const v_reg<float, n>& a) +{ + typedef typename V_TypeTraits<float>::int_type itype; + v_reg<float, n> c; + for (int i = 0; i < n; i++) + c.s[i] = V_TypeTraits<float>::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); + return c; +} +template<int n> +inline v_reg<double, n> v_not_nan(const v_reg<double, n>& a) +{ + typedef typename V_TypeTraits<double>::int_type itype; + v_reg<double, n> c; + for (int i = 0; i < n; i++) + c.s[i] = V_TypeTraits<double>::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); + return c; +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_ARITHM_OP(func, bin_op, cast_op, _Tp2) \ +template<typename _Tp, int n> \ +inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef _Tp2 rtype; \ + v_reg<rtype, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cast_op(a.s[i] bin_op b.s[i]); \ + return c; \ +} + +/** @brief Add values without saturation + +For 8- and 16-bit integer values. */ +OPENCV_HAL_IMPL_ARITHM_OP(v_add_wrap, +, (_Tp), _Tp) + +/** @brief Subtract values without saturation + +For 8- and 16-bit integer values. */ +OPENCV_HAL_IMPL_ARITHM_OP(v_sub_wrap, -, (_Tp), _Tp) + +/** @brief Multiply values without saturation + +For 8- and 16-bit integer values. */ +OPENCV_HAL_IMPL_ARITHM_OP(v_mul_wrap, *, (_Tp), _Tp) + +//! @cond IGNORED +template<typename T> inline T _absdiff(T a, T b) +{ + return a > b ? a - b : b - a; +} +//! @endcond + +/** @brief Absolute difference + +Returns \f$ |a - b| \f$ converted to corresponding unsigned type. +Example: +@code{.cpp} +v_int32x4 a, b; // {1, 2, 3, 4} and {4, 3, 2, 1} +v_uint32x4 c = v_absdiff(a, b); // result is {3, 1, 1, 3} +@endcode +For 8-, 16-, 32-bit integer source types. */ +template<typename _Tp, int n> +inline v_reg<typename V_TypeTraits<_Tp>::abs_type, n> v_absdiff(const v_reg<_Tp, n>& a, const v_reg<_Tp, n> & b) +{ + typedef typename V_TypeTraits<_Tp>::abs_type rtype; + v_reg<rtype, n> c; + const rtype mask = (rtype)(std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0); + for( int i = 0; i < n; i++ ) + { + rtype ua = a.s[i] ^ mask; + rtype ub = b.s[i] ^ mask; + c.s[i] = _absdiff(ua, ub); + } + return c; +} + +/** @overload + +For 32-bit floating point values */ +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 c; + for( int i = 0; i < c.nlanes; i++ ) + c.s[i] = _absdiff(a.s[i], b.s[i]); + return c; +} + +/** @overload + +For 64-bit floating point values */ +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 c; + for( int i = 0; i < c.nlanes; i++ ) + c.s[i] = _absdiff(a.s[i], b.s[i]); + return c; +} + +/** @brief Saturating absolute difference + +Returns \f$ saturate(|a - b|) \f$ . +For 8-, 16-bit signed integer source types. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_absdiffs(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++) + c.s[i] = saturate_cast<_Tp>(std::abs(a.s[i] - b.s[i])); + return c; +} + +/** @brief Inversed square root + +Returns \f$ 1/sqrt(a) \f$ +For floating point types only. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_invsqrt(const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = 1.f/std::sqrt(a.s[i]); + return c; +} + +/** @brief Magnitude + +Returns \f$ sqrt(a^2 + b^2) \f$ +For floating point types only. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = std::sqrt(a.s[i]*a.s[i] + b.s[i]*b.s[i]); + return c; +} + +/** @brief Square of the magnitude + +Returns \f$ a^2 + b^2 \f$ +For floating point types only. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_sqr_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = a.s[i]*a.s[i] + b.s[i]*b.s[i]; + return c; +} + +/** @brief Multiply and add + + Returns \f$ a*b + c \f$ + For floating point types and signed 32bit int only. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_fma(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg<_Tp, n>& c) +{ + v_reg<_Tp, n> d; + for( int i = 0; i < n; i++ ) + d.s[i] = a.s[i]*b.s[i] + c.s[i]; + return d; +} + +/** @brief A synonym for v_fma */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_muladd(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg<_Tp, n>& c) +{ + return v_fma(a, b, c); +} + +/** @brief Dot product of elements + +Multiply values in two registers and sum adjacent result pairs. +Scheme: +@code + {A1 A2 ...} // 16-bit +x {B1 B2 ...} // 16-bit +------------- +{A1B1+A2B2 ...} // 32-bit +@endcode +Implemented only for 16-bit signed source type (v_int16x8). +*/ +template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> + v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg<w_type, n/2> c; + for( int i = 0; i < (n/2); i++ ) + c.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1]; + return c; +} + +/** @brief Dot product of elements + +Same as cv::v_dotprod, but add a third element to the sum of adjacent pairs. +Scheme: +@code + {A1 A2 ...} // 16-bit +x {B1 B2 ...} // 16-bit +------------- + {A1B1+A2B2+C1 ...} // 32-bit + +@endcode +Implemented only for 16-bit signed source type (v_int16x8). +*/ +template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> + v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, const v_reg<typename V_TypeTraits<_Tp>::w_type, n / 2>& c) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg<w_type, n/2> s; + for( int i = 0; i < (n/2); i++ ) + s.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1] + c.s[i]; + return s; +} + +/** @brief Multiply and expand + +Multiply values two registers and store results in two registers with wider pack type. +Scheme: +@code + {A B C D} // 32-bit +x {E F G H} // 32-bit +--------------- +{AE BF} // 64-bit + {CG DH} // 64-bit +@endcode +Example: +@code{.cpp} +v_uint32x4 a, b; // {1,2,3,4} and {2,2,2,2} +v_uint64x2 c, d; // results +v_mul_expand(a, b, c, d); // c, d = {2,4}, {6, 8} +@endcode +Implemented only for 16- and unsigned 32-bit source types (v_int16x8, v_uint16x8, v_uint32x4). +*/ +template<typename _Tp, int n> inline void v_mul_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& c, + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& d) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = (w_type)a.s[i]*b.s[i]; + d.s[i] = (w_type)a.s[i+(n/2)]*b.s[i+(n/2)]; + } +} + +/** @brief Multiply and extract high part + +Multiply values two registers and store high part of the results. +Implemented only for 16-bit source types (v_int16x8, v_uint16x8). Returns \f$ a*b >> 16 \f$ +*/ +template<typename _Tp, int n> inline v_reg<_Tp, n> v_mul_hi(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg<_Tp, n> c; + for (int i = 0; i < n; i++) + c.s[i] = (_Tp)(((w_type)a.s[i] * b.s[i]) >> sizeof(_Tp)*8); + return c; +} + +//! @cond IGNORED +template<typename _Tp, int n> inline void v_hsum(const v_reg<_Tp, n>& a, + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& c) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = (w_type)a.s[i*2] + a.s[i*2+1]; + } +} +//! @endcond + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_SHIFT_OP(shift_op) \ +template<typename _Tp, int n> inline v_reg<_Tp, n> operator shift_op(const v_reg<_Tp, n>& a, int imm) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = (_Tp)(a.s[i] shift_op imm); \ + return c; \ +} + +/** @brief Bitwise shift left + +For 16-, 32- and 64-bit integer values. */ +OPENCV_HAL_IMPL_SHIFT_OP(<< ) + +/** @brief Bitwise shift right + +For 16-, 32- and 64-bit integer values. */ +OPENCV_HAL_IMPL_SHIFT_OP(>> ) + +/** @brief Element shift left among vector + +For all type */ +#define OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(suffix,opA,opB) \ +template<int imm, typename _Tp, int n> inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp, n> b; \ + for (int i = 0; i < n; i++) \ + { \ + int sIndex = i opA imm; \ + if (0 <= sIndex && sIndex < n) \ + { \ + b.s[i] = a.s[sIndex]; \ + } \ + else \ + { \ + b.s[i] = 0; \ + } \ + } \ + return b; \ +} \ +template<int imm, typename _Tp, int n> inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for (int i = 0; i < n; i++) \ + { \ + int aIndex = i opA imm; \ + int bIndex = i opA imm opB n; \ + if (0 <= bIndex && bIndex < n) \ + { \ + c.s[i] = b.s[bIndex]; \ + } \ + else if (0 <= aIndex && aIndex < n) \ + { \ + c.s[i] = a.s[aIndex]; \ + } \ + else \ + { \ + c.s[i] = 0; \ + } \ + } \ + return c; \ +} + +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(left, -, +) +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(right, +, -) + +/** @brief Sum packed values + +Scheme: +@code +{A1 A2 A3 ...} => sum{A1,A2,A3,...} +@endcode +For 32-bit integer and 32-bit floating point types.*/ +template<typename _Tp, int n> inline typename V_TypeTraits<_Tp>::sum_type v_reduce_sum(const v_reg<_Tp, n>& a) +{ + typename V_TypeTraits<_Tp>::sum_type c = a.s[0]; + for( int i = 1; i < n; i++ ) + c += a.s[i]; + return c; +} + +/** @brief Sums all elements of each input vector, returns the vector of sums + + Scheme: + @code + result[0] = a[0] + a[1] + a[2] + a[3] + result[1] = b[0] + b[1] + b[2] + b[3] + result[2] = c[0] + c[1] + c[2] + c[3] + result[3] = d[0] + d[1] + d[2] + d[3] + @endcode +*/ +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + v_float32x4 r; + r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3]; + r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3]; + r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3]; + r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3]; + return r; +} + +/** @brief Sum absolute differences of values + +Scheme: +@code +{A1 A2 A3 ...} {B1 B2 B3 ...} => sum{ABS(A1-B1),abs(A2-B2),abs(A3-B3),...} +@endcode +For all types except 64-bit types.*/ +template<typename _Tp, int n> inline typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type v_reduce_sad(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type c = _absdiff(a.s[0], b.s[0]); + for (int i = 1; i < n; i++) + c += _absdiff(a.s[i], b.s[i]); + return c; +} + +/** @brief Get negative values mask + +Returned value is a bit mask with bits set to 1 on places corresponding to negative packed values indexes. +Example: +@code{.cpp} +v_int32x4 r; // set to {-1, -1, 1, 1} +int mask = v_signmask(r); // mask = 3 <== 00000000 00000000 00000000 00000011 +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> inline int v_signmask(const v_reg<_Tp, n>& a) +{ + int mask = 0; + for( int i = 0; i < n; i++ ) + mask |= (V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0) << i; + return mask; +} + +/** @brief Check if all packed values are less than zero + +Unsigned values will be casted to signed: `uchar 254 => char -2`. +For all types except 64-bit. */ +template<typename _Tp, int n> inline bool v_check_all(const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) >= 0 ) + return false; + return true; +} + +/** @brief Check if any of packed values is less than zero + +Unsigned values will be casted to signed: `uchar 254 => char -2`. +For all types except 64-bit. */ +template<typename _Tp, int n> inline bool v_check_any(const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0 ) + return true; + return false; +} + +/** @brief Per-element select (blend operation) + +Return value will be built by combining values _a_ and _b_ using the following scheme: + result[i] = mask[i] ? a[i] : b[i]; + +@note: _mask_ element values are restricted to these values: +- 0: select element from _b_ +- 0xff/0xffff/etc: select element from _a_ +(fully compatible with bitwise-based operator) +*/ +template<typename _Tp, int n> inline v_reg<_Tp, n> v_select(const v_reg<_Tp, n>& mask, + const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef V_TypeTraits<_Tp> Traits; + typedef typename Traits::int_type int_type; + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + { + int_type m = Traits::reinterpret_int(mask.s[i]); + CV_DbgAssert(m == 0 || m == (~(int_type)0)); // restrict mask values: 0 or 0xff/0xffff/etc + c.s[i] = m ? a.s[i] : b.s[i]; + } + return c; +} + +/** @brief Expand values to the wider pack type + +Copy contents of register to two registers with 2x wider pack type. +Scheme: +@code + int32x4 int64x2 int64x2 +{A B C D} ==> {A B} , {C D} +@endcode */ +template<typename _Tp, int n> inline void v_expand(const v_reg<_Tp, n>& a, + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& b0, + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& b1) +{ + for( int i = 0; i < (n/2); i++ ) + { + b0.s[i] = a.s[i]; + b1.s[i] = a.s[i+(n/2)]; + } +} + +/** @brief Expand lower values to the wider pack type + +Same as cv::v_expand, but return lower half of the vector. + +Scheme: +@code + int32x4 int64x2 +{A B C D} ==> {A B} +@endcode */ +template<typename _Tp, int n> +inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> +v_expand_low(const v_reg<_Tp, n>& a) +{ + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> b; + for( int i = 0; i < (n/2); i++ ) + b.s[i] = a.s[i]; + return b; +} + +/** @brief Expand higher values to the wider pack type + +Same as cv::v_expand_low, but expand higher half of the vector instead. + +Scheme: +@code + int32x4 int64x2 +{A B C D} ==> {C D} +@endcode */ +template<typename _Tp, int n> +inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> +v_expand_high(const v_reg<_Tp, n>& a) +{ + v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> b; + for( int i = 0; i < (n/2); i++ ) + b.s[i] = a.s[i+(n/2)]; + return b; +} + +//! @cond IGNORED +template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::int_type, n> + v_reinterpret_as_int(const v_reg<_Tp, n>& a) +{ + v_reg<typename V_TypeTraits<_Tp>::int_type, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = V_TypeTraits<_Tp>::reinterpret_int(a.s[i]); + return c; +} + +template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::uint_type, n> + v_reinterpret_as_uint(const v_reg<_Tp, n>& a) +{ + v_reg<typename V_TypeTraits<_Tp>::uint_type, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = V_TypeTraits<_Tp>::reinterpret_uint(a.s[i]); + return c; +} +//! @endcond + +/** @brief Interleave two vectors + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +--------------- + {A1 B1 A2 B2} and {A3 B3 A4 B4} +@endcode +For all types except 64-bit. +*/ +template<typename _Tp, int n> inline void v_zip( const v_reg<_Tp, n>& a0, const v_reg<_Tp, n>& a1, + v_reg<_Tp, n>& b0, v_reg<_Tp, n>& b1 ) +{ + int i; + for( i = 0; i < n/2; i++ ) + { + b0.s[i*2] = a0.s[i]; + b0.s[i*2+1] = a1.s[i]; + } + for( ; i < n; i++ ) + { + b1.s[i*2-n] = a0.s[i]; + b1.s[i*2-n+1] = a1.s[i]; + } +} + +/** @brief Load register contents from memory + +@param ptr pointer to memory block with data +@return register object + +@note Returned type will be detected from passed pointer type, for example uchar ==> cv::v_uint8x16, int ==> cv::v_int32x4, etc. + */ +template<typename _Tp> +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load(const _Tp* ptr) +{ + return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); +} + +/** @brief Load register contents from memory (aligned) + +similar to cv::v_load, but source memory block should be aligned (to 16-byte boundary) + */ +template<typename _Tp> +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr) +{ + return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); +} + +/** @brief Load 64-bits of data to lower part (high part is undefined). + +@param ptr memory block containing data for first half (0..n/2) + +@code{.cpp} +int lo[2] = { 1, 2 }; +v_int32x4 r = v_load_low(lo); +@endcode + */ +template<typename _Tp> +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +/** @brief Load register contents from two memory blocks + +@param loptr memory block containing data for first half (0..n/2) +@param hiptr memory block containing data for second half (n/2..n) + +@code{.cpp} +int lo[2] = { 1, 2 }, hi[2] = { 3, 4 }; +v_int32x4 r = v_load_halves(lo, hi); +@endcode + */ +template<typename _Tp> +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, const _Tp* hiptr) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = loptr[i]; + c.s[i+c.nlanes/2] = hiptr[i]; + } + return c; +} + +/** @brief Load register contents from memory with double expand + +Same as cv::v_load, but result pack type will be 2x wider than memory type. + +@code{.cpp} +short buf[4] = {1, 2, 3, 4}; // type is int16 +v_int32x4 r = v_load_expand(buf); // r = {1, 2, 3, 4} - type is int32 +@endcode +For 8-, 16-, 32-bit integer source types. */ +template<typename _Tp> +inline v_reg<typename V_TypeTraits<_Tp>::w_type, V_TypeTraits<_Tp>::nlanes128 / 2> +v_load_expand(const _Tp* ptr) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg<w_type, V_TypeTraits<w_type>::nlanes128> c; + for( int i = 0; i < c.nlanes; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +/** @brief Load register contents from memory with quad expand + +Same as cv::v_load_expand, but result type is 4 times wider than source. +@code{.cpp} +char buf[4] = {1, 2, 3, 4}; // type is int8 +v_int32x4 r = v_load_q(buf); // r = {1, 2, 3, 4} - type is int32 +@endcode +For 8-bit integer source types. */ +template<typename _Tp> +inline v_reg<typename V_TypeTraits<_Tp>::q_type, V_TypeTraits<_Tp>::nlanes128 / 4> +v_load_expand_q(const _Tp* ptr) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg<q_type, V_TypeTraits<q_type>::nlanes128> c; + for( int i = 0; i < c.nlanes; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +/** @brief Load and deinterleave (2 channels) + +Load data from memory deinterleave and store to 2 registers. +Scheme: +@code +{A1 B1 A2 B2 ...} ==> {A1 A2 ...}, {B1 B2 ...} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + a.s[i] = ptr[i2]; + b.s[i] = ptr[i2+1]; + } +} + +/** @brief Load and deinterleave (3 channels) + +Load data from memory deinterleave and store to 3 registers. +Scheme: +@code +{A1 B1 C1 A2 B2 C2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b, v_reg<_Tp, n>& c) +{ + int i, i3; + for( i = i3 = 0; i < n; i++, i3 += 3 ) + { + a.s[i] = ptr[i3]; + b.s[i] = ptr[i3+1]; + c.s[i] = ptr[i3+2]; + } +} + +/** @brief Load and deinterleave (4 channels) + +Load data from memory deinterleave and store to 4 registers. +Scheme: +@code +{A1 B1 C1 D1 A2 B2 C2 D2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> +inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b, v_reg<_Tp, n>& c, + v_reg<_Tp, n>& d) +{ + int i, i4; + for( i = i4 = 0; i < n; i++, i4 += 4 ) + { + a.s[i] = ptr[i4]; + b.s[i] = ptr[i4+1]; + c.s[i] = ptr[i4+2]; + d.s[i] = ptr[i4+3]; + } +} + +/** @brief Interleave and store (2 channels) + +Interleave and store data from 2 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...} ==> {A1 B1 A2 B2 ...} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + ptr[i2] = a.s[i]; + ptr[i2+1] = b.s[i]; + } +} + +/** @brief Interleave and store (3 channels) + +Interleave and store data from 3 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} ==> {A1 B1 C1 A2 B2 C2 ...} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i3; + for( i = i3 = 0; i < n; i++, i3 += 3 ) + { + ptr[i3] = a.s[i]; + ptr[i3+1] = b.s[i]; + ptr[i3+2] = c.s[i]; + } +} + +/** @brief Interleave and store (4 channels) + +Interleave and store data from 4 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} ==> {A1 B1 C1 D1 A2 B2 C2 D2 ...} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, + const v_reg<_Tp, n>& d, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i4; + for( i = i4 = 0; i < n; i++, i4 += 4 ) + { + ptr[i4] = a.s[i]; + ptr[i4+1] = b.s[i]; + ptr[i4+2] = c.s[i]; + ptr[i4+3] = d.s[i]; + } +} + +/** @brief Store data to memory + +Store register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {A B C D} +@endcode +Pointer can be unaligned. */ +template<typename _Tp, int n> +inline void v_store(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +/** @brief Store data to memory (lower half) + +Store lower half of register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {A B} +@endcode */ +template<typename _Tp, int n> +inline void v_store_low(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < (n/2); i++ ) + ptr[i] = a.s[i]; +} + +/** @brief Store data to memory (higher half) + +Store higher half of register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {C D} +@endcode */ +template<typename _Tp, int n> +inline void v_store_high(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < (n/2); i++ ) + ptr[i] = a.s[i+(n/2)]; +} + +/** @brief Store data to memory (aligned) + +Store register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {A B C D} +@endcode +Pointer __should__ be aligned by 16-byte boundary. */ +template<typename _Tp, int n> +inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template<typename _Tp, int n> +inline void v_store_aligned_nocache(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template<typename _Tp, int n> +inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +/** @brief Combine vector from first elements of two vectors + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +--------------- + {A1 A2 B1 B2} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_combine_low(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = a.s[i]; + c.s[i+(n/2)] = b.s[i]; + } + return c; +} + +/** @brief Combine vector from last elements of two vectors + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +--------------- + {A3 A4 B3 B4} +@endcode +For all types except 64-bit. */ +template<typename _Tp, int n> +inline v_reg<_Tp, n> v_combine_high(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = a.s[i+(n/2)]; + c.s[i+(n/2)] = b.s[i+(n/2)]; + } + return c; +} + +/** @brief Combine two vectors from lower and higher parts of two other vectors + +@code{.cpp} +low = cv::v_combine_low(a, b); +high = cv::v_combine_high(a, b); +@endcode */ +template<typename _Tp, int n> +inline void v_recombine(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<_Tp, n>& low, v_reg<_Tp, n>& high) +{ + for( int i = 0; i < (n/2); i++ ) + { + low.s[i] = a.s[i]; + low.s[i+(n/2)] = b.s[i]; + high.s[i] = a.s[i+(n/2)]; + high.s[i+(n/2)] = b.s[i+(n/2)]; + } +} + +/** @brief Vector extract + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +======================== +shift = 1 {A2 A3 A4 B1} +shift = 2 {A3 A4 B1 B2} +shift = 3 {A4 B1 B2 B3} +@endcode +Restriction: 0 <= shift < nlanes + +Usage: +@code +v_int32x4 a, b, c; +c = v_extract<2>(a, b); +@endcode +For all types. */ +template<int s, typename _Tp, int n> +inline v_reg<_Tp, n> v_extract(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> r; + const int shift = n - s; + int i = 0; + for (; i < shift; ++i) + r.s[i] = a.s[i+s]; + for (; i < n; ++i) + r.s[i] = b.s[i-shift]; + return r; +} + +/** @brief Round + +Rounds each value. Input type is float vector ==> output type is int vector.*/ +template<int n> inline v_reg<int, n> v_round(const v_reg<float, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvRound(a.s[i]); + return c; +} + +/** @overload */ +template<int n> inline v_reg<int, n*2> v_round(const v_reg<double, n>& a, const v_reg<double, n>& b) +{ + v_reg<int, n*2> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvRound(a.s[i]); + c.s[i+n] = cvRound(b.s[i]); + } + return c; +} + +/** @brief Floor + +Floor each value. Input type is float vector ==> output type is int vector.*/ +template<int n> inline v_reg<int, n> v_floor(const v_reg<float, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvFloor(a.s[i]); + return c; +} + +/** @brief Ceil + +Ceil each value. Input type is float vector ==> output type is int vector.*/ +template<int n> inline v_reg<int, n> v_ceil(const v_reg<float, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvCeil(a.s[i]); + return c; +} + +/** @brief Trunc + +Truncate each value. Input type is float vector ==> output type is int vector.*/ +template<int n> inline v_reg<int, n> v_trunc(const v_reg<float, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (int)(a.s[i]); + return c; +} + +/** @overload */ +template<int n> inline v_reg<int, n*2> v_round(const v_reg<double, n>& a) +{ + v_reg<int, n*2> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvRound(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @overload */ +template<int n> inline v_reg<int, n*2> v_floor(const v_reg<double, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvFloor(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @overload */ +template<int n> inline v_reg<int, n*2> v_ceil(const v_reg<double, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvCeil(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @overload */ +template<int n> inline v_reg<int, n*2> v_trunc(const v_reg<double, n>& a) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvCeil(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @brief Convert to float + +Supported input type is cv::v_int32x4. */ +template<int n> inline v_reg<float, n> v_cvt_f32(const v_reg<int, n>& a) +{ + v_reg<float, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (float)a.s[i]; + return c; +} + +template<int n> inline v_reg<float, n*2> v_cvt_f32(const v_reg<double, n>& a, const v_reg<double, n>& b) +{ + v_reg<float, n*2> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = (float)a.s[i]; + c.s[i+n] = (float)b.s[i]; + } + return c; +} + +/** @brief Convert to double + +Supported input type is cv::v_int32x4. */ +template<int n> inline v_reg<double, n> v_cvt_f64(const v_reg<int, n*2>& a) +{ + v_reg<double, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +/** @brief Convert to double + +Supported input type is cv::v_float32x4. */ +template<int n> inline v_reg<double, n> v_cvt_f64(const v_reg<float, n*2>& a) +{ + v_reg<double, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +template<typename _Tp> inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i]]; + return c; +} +template<typename _Tp> inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_pairs(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i / 2] + i % 2]; + return c; +} +template<typename _Tp> inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_quads(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i / 4] + i % 4]; + return c; +} + +template<int n> inline v_reg<int, n> v_lut(const int* tab, const v_reg<int, n>& idx) +{ + v_reg<int, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template<int n> inline v_reg<unsigned, n> v_lut(const unsigned* tab, const v_reg<int, n>& idx) +{ + v_reg<int, n> c; + for (int i = 0; i < n; i++) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template<int n> inline v_reg<float, n> v_lut(const float* tab, const v_reg<int, n>& idx) +{ + v_reg<float, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template<int n> inline v_reg<double, n> v_lut(const double* tab, const v_reg<int, n*2>& idx) +{ + v_reg<double, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template<int n> inline void v_lut_deinterleave(const float* tab, const v_reg<int, n>& idx, + v_reg<float, n>& x, v_reg<float, n>& y) +{ + for( int i = 0; i < n; i++ ) + { + int j = idx.s[i]; + x.s[i] = tab[j]; + y.s[i] = tab[j+1]; + } +} + +template<int n> inline void v_lut_deinterleave(const double* tab, const v_reg<int, n*2>& idx, + v_reg<double, n>& x, v_reg<double, n>& y) +{ + for( int i = 0; i < n; i++ ) + { + int j = idx.s[i]; + x.s[i] = tab[j]; + y.s[i] = tab[j+1]; + } +} + +template<typename _Tp, int n> inline v_reg<_Tp, n> v_interleave_pairs(const v_reg<_Tp, n>& vec) +{ + v_reg<float, n> c; + for (int i = 0; i < n/4; i++) + { + c.s[4*i ] = vec.s[4*i ]; + c.s[4*i+1] = vec.s[4*i+2]; + c.s[4*i+2] = vec.s[4*i+1]; + c.s[4*i+3] = vec.s[4*i+3]; + } + return c; +} + +template<typename _Tp, int n> inline v_reg<_Tp, n> v_interleave_quads(const v_reg<_Tp, n>& vec) +{ + v_reg<float, n> c; + for (int i = 0; i < n/8; i++) + { + c.s[8*i ] = vec.s[8*i ]; + c.s[8*i+1] = vec.s[8*i+4]; + c.s[8*i+2] = vec.s[8*i+1]; + c.s[8*i+3] = vec.s[8*i+5]; + c.s[8*i+4] = vec.s[8*i+2]; + c.s[8*i+5] = vec.s[8*i+6]; + c.s[8*i+6] = vec.s[8*i+3]; + c.s[8*i+7] = vec.s[8*i+7]; + } + return c; +} + +template<typename _Tp, int n> inline v_reg<_Tp, n> v_pack_triplets(const v_reg<_Tp, n>& vec) +{ + v_reg<float, n> c; + for (int i = 0; i < n/4; i++) + { + c.s[3*i ] = vec.s[4*i ]; + c.s[3*i+1] = vec.s[4*i+1]; + c.s[3*i+2] = vec.s[4*i+2]; + } + return c; +} + +/** @brief Transpose 4x4 matrix + +Scheme: +@code +a0 {A1 A2 A3 A4} +a1 {B1 B2 B3 B4} +a2 {C1 C2 C3 C4} +a3 {D1 D2 D3 D4} +=============== +b0 {A1 B1 C1 D1} +b1 {A2 B2 C2 D2} +b2 {A3 B3 C3 D3} +b3 {A4 B4 C4 D4} +@endcode +*/ +template<typename _Tp> +inline void v_transpose4x4( v_reg<_Tp, 4>& a0, const v_reg<_Tp, 4>& a1, + const v_reg<_Tp, 4>& a2, const v_reg<_Tp, 4>& a3, + v_reg<_Tp, 4>& b0, v_reg<_Tp, 4>& b1, + v_reg<_Tp, 4>& b2, v_reg<_Tp, 4>& b3 ) +{ + b0 = v_reg<_Tp, 4>(a0.s[0], a1.s[0], a2.s[0], a3.s[0]); + b1 = v_reg<_Tp, 4>(a0.s[1], a1.s[1], a2.s[1], a3.s[1]); + b2 = v_reg<_Tp, 4>(a0.s[2], a1.s[2], a2.s[2], a3.s[2]); + b3 = v_reg<_Tp, 4>(a0.s[3], a1.s[3], a2.s[3], a3.s[3]); +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec::zero(); } + +//! @name Init with zero +//! @{ +//! @brief Create new vector with zero elements +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, int64, s64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_setall_##suffix(_Tp val) { return _Tpvec::all(val); } + +//! @name Init with value +//! @{ +//! @brief Create new vector with elements set to a specific value +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, s64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tpvec, _Tp, suffix) \ +template<typename _Tp0, int n0> inline _Tpvec \ + v_reinterpret_as_##suffix(const v_reg<_Tp0, n0>& a) \ +{ return a.template reinterpret_as<_Tp, _Tpvec::nlanes>(); } + +//! @name Reinterpret +//! @{ +//! @brief Convert vector to different type without modifying underlying data. +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int64x2, int64, s64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_SHIFTL(_Tpvec, _Tp) \ +template<int n> inline _Tpvec v_shl(const _Tpvec& a) \ +{ return a << n; } + +//! @name Left shift +//! @{ +//! @brief Shift left +OPENCV_HAL_IMPL_C_SHIFTL(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_SHIFTL(v_int16x8, short) +OPENCV_HAL_IMPL_C_SHIFTL(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_SHIFTL(v_int32x4, int) +OPENCV_HAL_IMPL_C_SHIFTL(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_SHIFTL(v_int64x2, int64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_SHIFTR(_Tpvec, _Tp) \ +template<int n> inline _Tpvec v_shr(const _Tpvec& a) \ +{ return a >> n; } + +//! @name Right shift +//! @{ +//! @brief Shift right +OPENCV_HAL_IMPL_C_SHIFTR(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_SHIFTR(v_int16x8, short) +OPENCV_HAL_IMPL_C_SHIFTR(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_SHIFTR(v_int32x4, int) +OPENCV_HAL_IMPL_C_SHIFTR(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_SHIFTR(v_int64x2, int64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tpvec, _Tp) \ +template<int n> inline _Tpvec v_rshr(const _Tpvec& a) \ +{ \ + _Tpvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + return c; \ +} + +//! @name Rounding shift +//! @{ +//! @brief Rounding shift right +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int16x8, short) +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int32x4, int) +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \ +inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpnvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + { \ + c.s[i] = cast<_Tpn>(a.s[i]); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \ + } \ + return c; \ +} + +//! @name Pack +//! @{ +//! @brief Pack values from two vectors to one +//! +//! Return vector type have twice more elements than input vector types. Variant with _u_ suffix also +//! converts to corresponding unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +template<int n> inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpnvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + { \ + c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + } \ + return c; \ +} + +//! @name Pack with rounding shift +//! @{ +//! @brief Pack values from two vectors to one with rounding shift +//! +//! Values from the input vectors will be shifted right by _n_ bits with rounding, converted to narrower +//! type and returned in the result vector. Variant with _u_ suffix converts to unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +{ \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + ptr[i] = cast<_Tpn>(a.s[i]); \ +} + +//! @name Pack and store +//! @{ +//! @brief Store values from the input vector into memory with pack +//! +//! Values will be stored into memory with conversion to narrower type. +//! Variant with _u_ suffix converts to corresponding unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +template<int n> inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +{ \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ +} + +//! @name Pack and store with rounding shift +//! @{ +//! @brief Store values from the input vector into memory with pack +//! +//! Values will be shifted _n_ bits right with rounding, converted to narrower type and stored into +//! memory. Variant with _u_ suffix converts to unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @cond IGNORED +template<typename _Tpm, typename _Tp, int n> +inline void _pack_b(_Tpm* mptr, const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + for (int i = 0; i < n; ++i) + { + mptr[i] = (_Tpm)a.s[i]; + mptr[i + n] = (_Tpm)b.s[i]; + } +} +//! @endcond + +//! @name Pack boolean values +//! @{ +//! @brief Pack boolean values from multiple vectors to one unsigned 8-bit integer vector +//! +//! @note Must provide valid boolean values to guarantee same result for all architectures. + +/** @brief +//! For 16-bit boolean values + +Scheme: +@code +a {0xFFFF 0 0 0xFFFF 0 0xFFFF 0xFFFF 0} +b {0xFFFF 0 0xFFFF 0 0 0xFFFF 0 0xFFFF} +=============== +{ + 0xFF 0 0 0xFF 0 0xFF 0xFF 0 + 0xFF 0 0xFF 0 0 0xFF 0 0xFF +} +@endcode */ + +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + return mask; +} + +/** @overload +For 32-bit boolean values + +Scheme: +@code +a {0xFFFF.. 0 0 0xFFFF..} +b {0 0xFFFF.. 0xFFFF.. 0} +c {0xFFFF.. 0 0xFFFF.. 0} +d {0 0xFFFF.. 0 0xFFFF..} +=============== +{ + 0xFF 0 0 0xFF 0 0xFF 0xFF 0 + 0xFF 0 0xFF 0 0 0xFF 0 0xFF +} +@endcode */ + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + _pack_b(mask.s + 8, c, d); + return mask; +} + +/** @overload +For 64-bit boolean values + +Scheme: +@code +a {0xFFFF.. 0} +b {0 0xFFFF..} +c {0xFFFF.. 0} +d {0 0xFFFF..} + +e {0xFFFF.. 0} +f {0xFFFF.. 0} +g {0 0xFFFF..} +h {0 0xFFFF..} +=============== +{ + 0xFF 0 0 0xFF 0xFF 0 0 0xFF + 0xFF 0 0xFF 0 0 0xFF 0 0xFF +} +@endcode */ +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + _pack_b(mask.s + 4, c, d); + _pack_b(mask.s + 8, e, f); + _pack_b(mask.s + 12, g, h); + return mask; +} +//! @} + +/** @brief Matrix multiplication + +Scheme: +@code +{A0 A1 A2 A3} |V0| +{B0 B1 B2 B3} |V1| +{C0 C1 C2 C3} |V2| +{D0 D1 D2 D3} x |V3| +==================== +{R0 R1 R2 R3}, where: +R0 = A0V0 + A1V1 + A2V2 + A3V3, +R1 = B0V0 + B1V1 + B2V2 + B3V3 +... +@endcode +*/ +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + v.s[3]*m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + v.s[3]*m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + v.s[3]*m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]); +} + +/** @brief Matrix multiplication and add + +Scheme: +@code +{A0 A1 A2 } |V0| |D0| +{B0 B1 B2 } |V1| |D1| +{C0 C1 C2 } x |V2| + |D2| +==================== +{R0 R1 R2 R3}, where: +R0 = A0V0 + A1V1 + A2V2 + D0, +R1 = B0V0 + B1V1 + B2V2 + D1 +... +@endcode +*/ +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]); +} + +////// FP16 support /////// + +inline v_reg<float, V_TypeTraits<float>::nlanes128> +v_load_expand(const float16_t* ptr) +{ + v_reg<float, V_TypeTraits<float>::nlanes128> v; + for( int i = 0; i < v.nlanes; i++ ) + { + v.s[i] = ptr[i]; + } + return v; +} + +inline void +v_pack_store(float16_t* ptr, v_reg<float, V_TypeTraits<float>::nlanes128>& v) +{ + for( int i = 0; i < v.nlanes; i++ ) + { + ptr[i] = float16_t(v.s[i]); + } +} + +inline void v_cleanup() {} + +//! @} + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return false; +} + +//! @} + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif +} + +#endif diff --git a/include/opencv2/core/hal/intrin_forward.hpp b/include/opencv2/core/hal/intrin_forward.hpp new file mode 100644 index 0000000..4618552 --- /dev/null +++ b/include/opencv2/core/hal/intrin_forward.hpp @@ -0,0 +1,158 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef CV__SIMD_FORWARD +#error "Need to pre-define forward width" +#endif + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +/** Types **/ +#if CV__SIMD_FORWARD == 512 +// [todo] 512 +#error "AVX512 Not implemented yet" +#elif CV__SIMD_FORWARD == 256 +// 256 +#define __CV_VX(fun) v256_##fun +#define __CV_V_UINT8 v_uint8x32 +#define __CV_V_INT8 v_int8x32 +#define __CV_V_UINT16 v_uint16x16 +#define __CV_V_INT16 v_int16x16 +#define __CV_V_UINT32 v_uint32x8 +#define __CV_V_INT32 v_int32x8 +#define __CV_V_UINT64 v_uint64x4 +#define __CV_V_INT64 v_int64x4 +#define __CV_V_FLOAT32 v_float32x8 +#define __CV_V_FLOAT64 v_float64x4 +struct v_uint8x32; +struct v_int8x32; +struct v_uint16x16; +struct v_int16x16; +struct v_uint32x8; +struct v_int32x8; +struct v_uint64x4; +struct v_int64x4; +struct v_float32x8; +struct v_float64x4; +#else +// 128 +#define __CV_VX(fun) v_##fun +#define __CV_V_UINT8 v_uint8x16 +#define __CV_V_INT8 v_int8x16 +#define __CV_V_UINT16 v_uint16x8 +#define __CV_V_INT16 v_int16x8 +#define __CV_V_UINT32 v_uint32x4 +#define __CV_V_INT32 v_int32x4 +#define __CV_V_UINT64 v_uint64x2 +#define __CV_V_INT64 v_int64x2 +#define __CV_V_FLOAT32 v_float32x4 +#define __CV_V_FLOAT64 v_float64x2 +struct v_uint8x16; +struct v_int8x16; +struct v_uint16x8; +struct v_int16x8; +struct v_uint32x4; +struct v_int32x4; +struct v_uint64x2; +struct v_int64x2; +struct v_float32x4; +struct v_float64x2; +#endif + +/** Value reordering **/ + +// Expansion +void v_expand(const __CV_V_UINT8&, __CV_V_UINT16&, __CV_V_UINT16&); +void v_expand(const __CV_V_INT8&, __CV_V_INT16&, __CV_V_INT16&); +void v_expand(const __CV_V_UINT16&, __CV_V_UINT32&, __CV_V_UINT32&); +void v_expand(const __CV_V_INT16&, __CV_V_INT32&, __CV_V_INT32&); +void v_expand(const __CV_V_UINT32&, __CV_V_UINT64&, __CV_V_UINT64&); +void v_expand(const __CV_V_INT32&, __CV_V_INT64&, __CV_V_INT64&); +// Low Expansion +__CV_V_UINT16 v_expand_low(const __CV_V_UINT8&); +__CV_V_INT16 v_expand_low(const __CV_V_INT8&); +__CV_V_UINT32 v_expand_low(const __CV_V_UINT16&); +__CV_V_INT32 v_expand_low(const __CV_V_INT16&); +__CV_V_UINT64 v_expand_low(const __CV_V_UINT32&); +__CV_V_INT64 v_expand_low(const __CV_V_INT32&); +// High Expansion +__CV_V_UINT16 v_expand_high(const __CV_V_UINT8&); +__CV_V_INT16 v_expand_high(const __CV_V_INT8&); +__CV_V_UINT32 v_expand_high(const __CV_V_UINT16&); +__CV_V_INT32 v_expand_high(const __CV_V_INT16&); +__CV_V_UINT64 v_expand_high(const __CV_V_UINT32&); +__CV_V_INT64 v_expand_high(const __CV_V_INT32&); +// Load & Low Expansion +__CV_V_UINT16 __CV_VX(load_expand)(const uchar*); +__CV_V_INT16 __CV_VX(load_expand)(const schar*); +__CV_V_UINT32 __CV_VX(load_expand)(const ushort*); +__CV_V_INT32 __CV_VX(load_expand)(const short*); +__CV_V_UINT64 __CV_VX(load_expand)(const uint*); +__CV_V_INT64 __CV_VX(load_expand)(const int*); +// Load lower 8-bit and expand into 32-bit +__CV_V_UINT32 __CV_VX(load_expand_q)(const uchar*); +__CV_V_INT32 __CV_VX(load_expand_q)(const schar*); + +// Saturating Pack +__CV_V_UINT8 v_pack(const __CV_V_UINT16&, const __CV_V_UINT16&); +__CV_V_INT8 v_pack(const __CV_V_INT16&, const __CV_V_INT16&); +__CV_V_UINT16 v_pack(const __CV_V_UINT32&, const __CV_V_UINT32&); +__CV_V_INT16 v_pack(const __CV_V_INT32&, const __CV_V_INT32&); +// Non-saturating Pack +__CV_V_UINT32 v_pack(const __CV_V_UINT64&, const __CV_V_UINT64&); +__CV_V_INT32 v_pack(const __CV_V_INT64&, const __CV_V_INT64&); +// Pack signed integers with unsigned saturation +__CV_V_UINT8 v_pack_u(const __CV_V_INT16&, const __CV_V_INT16&); +__CV_V_UINT16 v_pack_u(const __CV_V_INT32&, const __CV_V_INT32&); + +/** Arithmetic, bitwise and comparison operations **/ + +// Non-saturating multiply +#if CV_VSX +template<typename Tvec> +Tvec v_mul_wrap(const Tvec& a, const Tvec& b); +#else +__CV_V_UINT8 v_mul_wrap(const __CV_V_UINT8&, const __CV_V_UINT8&); +__CV_V_INT8 v_mul_wrap(const __CV_V_INT8&, const __CV_V_INT8&); +__CV_V_UINT16 v_mul_wrap(const __CV_V_UINT16&, const __CV_V_UINT16&); +__CV_V_INT16 v_mul_wrap(const __CV_V_INT16&, const __CV_V_INT16&); +#endif + +// Multiply and expand +#if CV_VSX +template<typename Tvec, typename Twvec> +void v_mul_expand(const Tvec& a, const Tvec& b, Twvec& c, Twvec& d); +#else +void v_mul_expand(const __CV_V_UINT8&, const __CV_V_UINT8&, __CV_V_UINT16&, __CV_V_UINT16&); +void v_mul_expand(const __CV_V_INT8&, const __CV_V_INT8&, __CV_V_INT16&, __CV_V_INT16&); +void v_mul_expand(const __CV_V_UINT16&, const __CV_V_UINT16&, __CV_V_UINT32&, __CV_V_UINT32&); +void v_mul_expand(const __CV_V_INT16&, const __CV_V_INT16&, __CV_V_INT32&, __CV_V_INT32&); +void v_mul_expand(const __CV_V_UINT32&, const __CV_V_UINT32&, __CV_V_UINT64&, __CV_V_UINT64&); +void v_mul_expand(const __CV_V_INT32&, const __CV_V_INT32&, __CV_V_INT64&, __CV_V_INT64&); +#endif + +/** Cleanup **/ +#undef CV__SIMD_FORWARD +#undef __CV_VX +#undef __CV_V_UINT8 +#undef __CV_V_INT8 +#undef __CV_V_UINT16 +#undef __CV_V_INT16 +#undef __CV_V_UINT32 +#undef __CV_V_INT32 +#undef __CV_V_UINT64 +#undef __CV_V_INT64 +#undef __CV_V_FLOAT32 +#undef __CV_V_FLOAT64 + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: \ No newline at end of file diff --git a/include/opencv2/core/hal/intrin_neon.hpp b/include/opencv2/core/hal/intrin_neon.hpp new file mode 100644 index 0000000..3b946ff --- /dev/null +++ b/include/opencv2/core/hal/intrin_neon.hpp @@ -0,0 +1,1943 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HAL_INTRIN_NEON_HPP +#define OPENCV_HAL_INTRIN_NEON_HPP + +#include <algorithm> +#include "opencv2/core/utility.hpp" + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define CV_SIMD128 1 +#if defined(__aarch64__) +#define CV_SIMD128_64F 1 +#else +#define CV_SIMD128_64F 0 +#endif + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix) \ +template <typename T> static inline \ +_Tpv vreinterpretq_##suffix##_f64(T a) { return (_Tpv) a; } \ +template <typename T> static inline \ +float64x2_t vreinterpretq_f64_##suffix(T a) { return (float64x2_t) a; } +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint8x16_t, u8) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int8x16_t, s8) +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint16x8_t, u16) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int16x8_t, s16) +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint32x4_t, u32) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int32x4_t, s32) +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint64x2_t, u64) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int64x2_t, s64) +OPENCV_HAL_IMPL_NEON_REINTERPRET(float32x4_t, f32) +#endif + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + + v_uint8x16() {} + explicit v_uint8x16(uint8x16_t v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = vld1q_u8(v); + } + uchar get0() const + { + return vgetq_lane_u8(val, 0); + } + + uint8x16_t val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + + v_int8x16() {} + explicit v_int8x16(int8x16_t v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = vld1q_s8(v); + } + schar get0() const + { + return vgetq_lane_s8(val, 0); + } + + int8x16_t val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + + v_uint16x8() {} + explicit v_uint16x8(uint16x8_t v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = vld1q_u16(v); + } + ushort get0() const + { + return vgetq_lane_u16(val, 0); + } + + uint16x8_t val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + + v_int16x8() {} + explicit v_int16x8(int16x8_t v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + short v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = vld1q_s16(v); + } + short get0() const + { + return vgetq_lane_s16(val, 0); + } + + int16x8_t val; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + + v_uint32x4() {} + explicit v_uint32x4(uint32x4_t v) : val(v) {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + unsigned v[] = {v0, v1, v2, v3}; + val = vld1q_u32(v); + } + unsigned get0() const + { + return vgetq_lane_u32(val, 0); + } + + uint32x4_t val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + + v_int32x4() {} + explicit v_int32x4(int32x4_t v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + int v[] = {v0, v1, v2, v3}; + val = vld1q_s32(v); + } + int get0() const + { + return vgetq_lane_s32(val, 0); + } + int32x4_t val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + + v_float32x4() {} + explicit v_float32x4(float32x4_t v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + float v[] = {v0, v1, v2, v3}; + val = vld1q_f32(v); + } + float get0() const + { + return vgetq_lane_f32(val, 0); + } + float32x4_t val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + + v_uint64x2() {} + explicit v_uint64x2(uint64x2_t v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + uint64 v[] = {v0, v1}; + val = vld1q_u64(v); + } + uint64 get0() const + { + return vgetq_lane_u64(val, 0); + } + uint64x2_t val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + + v_int64x2() {} + explicit v_int64x2(int64x2_t v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + int64 v[] = {v0, v1}; + val = vld1q_s64(v); + } + int64 get0() const + { + return vgetq_lane_s64(val, 0); + } + int64x2_t val; +}; + +#if CV_SIMD128_64F +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + + v_float64x2() {} + explicit v_float64x2(float64x2_t v) : val(v) {} + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + val = vld1q_f64(v); + } + double get0() const + { + return vgetq_lane_f64(val, 0); + } + float64x2_t val; +}; +#endif + +#if CV_FP16 +// Workaround for old compilers +static inline int16x4_t vreinterpret_s16_f16(float16x4_t a) { return (int16x4_t)a; } +static inline float16x4_t vreinterpret_f16_s16(int16x4_t a) { return (float16x4_t)a; } + +static inline float16x4_t cv_vld1_f16(const void* ptr) +{ +#ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro + return vreinterpret_f16_s16(vld1_s16((const short*)ptr)); +#else + return vld1_f16((const __fp16*)ptr); +#endif +} +static inline void cv_vst1_f16(void* ptr, float16x4_t a) +{ +#ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro + vst1_s16((short*)ptr, vreinterpret_s16_f16(a)); +#else + vst1_f16((__fp16*)ptr, a); +#endif +} + +#ifndef vdup_n_f16 + #define vdup_n_f16(v) (float16x4_t){v, v, v, v} +#endif + +#endif // CV_FP16 + +#if CV_FP16 +inline v_float32x4 v128_load_fp16_f32(const short* ptr) +{ + float16x4_t a = cv_vld1_f16((const __fp16*)ptr); + return v_float32x4(vcvt_f32_f16(a)); +} + +inline void v_store_fp16(short* ptr, const v_float32x4& a) +{ + float16x4_t fp16 = vcvt_f16_f32(a.val); + cv_vst1_f16((short*)ptr, fp16); +} +#endif + +#define OPENCV_HAL_IMPL_NEON_INIT(_Tpv, _Tp, suffix) \ +inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(vdupq_n_##suffix((_Tp)0)); } \ +inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(vdupq_n_##suffix(v)); } \ +inline _Tpv##_t vreinterpretq_##suffix##_##suffix(_Tpv##_t v) { return v; } \ +inline v_uint8x16 v_reinterpret_as_u8(const v_##_Tpv& v) { return v_uint8x16(vreinterpretq_u8_##suffix(v.val)); } \ +inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16(vreinterpretq_s8_##suffix(v.val)); } \ +inline v_uint16x8 v_reinterpret_as_u16(const v_##_Tpv& v) { return v_uint16x8(vreinterpretq_u16_##suffix(v.val)); } \ +inline v_int16x8 v_reinterpret_as_s16(const v_##_Tpv& v) { return v_int16x8(vreinterpretq_s16_##suffix(v.val)); } \ +inline v_uint32x4 v_reinterpret_as_u32(const v_##_Tpv& v) { return v_uint32x4(vreinterpretq_u32_##suffix(v.val)); } \ +inline v_int32x4 v_reinterpret_as_s32(const v_##_Tpv& v) { return v_int32x4(vreinterpretq_s32_##suffix(v.val)); } \ +inline v_uint64x2 v_reinterpret_as_u64(const v_##_Tpv& v) { return v_uint64x2(vreinterpretq_u64_##suffix(v.val)); } \ +inline v_int64x2 v_reinterpret_as_s64(const v_##_Tpv& v) { return v_int64x2(vreinterpretq_s64_##suffix(v.val)); } \ +inline v_float32x4 v_reinterpret_as_f32(const v_##_Tpv& v) { return v_float32x4(vreinterpretq_f32_##suffix(v.val)); } + +OPENCV_HAL_IMPL_NEON_INIT(uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_INIT(int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_INIT(uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_INIT(int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_INIT(uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_NEON_INIT(int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_INIT(uint64x2, uint64, u64) +OPENCV_HAL_IMPL_NEON_INIT(int64x2, int64, s64) +OPENCV_HAL_IMPL_NEON_INIT(float32x4, float, f32) +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_INIT_64(_Tpv, suffix) \ +inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2(vreinterpretq_f64_##suffix(v.val)); } +OPENCV_HAL_IMPL_NEON_INIT(float64x2, double, f64) +OPENCV_HAL_IMPL_NEON_INIT_64(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_INIT_64(int8x16, s8) +OPENCV_HAL_IMPL_NEON_INIT_64(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_INIT_64(int16x8, s16) +OPENCV_HAL_IMPL_NEON_INIT_64(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_INIT_64(int32x4, s32) +OPENCV_HAL_IMPL_NEON_INIT_64(uint64x2, u64) +OPENCV_HAL_IMPL_NEON_INIT_64(int64x2, s64) +OPENCV_HAL_IMPL_NEON_INIT_64(float32x4, f32) +OPENCV_HAL_IMPL_NEON_INIT_64(float64x2, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_PACK(_Tpvec, _Tp, hreg, suffix, _Tpwvec, pack, mov, rshr) \ +inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + hreg a1 = mov(a.val), b1 = mov(b.val); \ + return _Tpvec(vcombine_##suffix(a1, b1)); \ +} \ +inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + hreg a1 = mov(a.val); \ + vst1_##suffix(ptr, a1); \ +} \ +template<int n> inline \ +_Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + hreg a1 = rshr(a.val, n); \ + hreg b1 = rshr(b.val, n); \ + return _Tpvec(vcombine_##suffix(a1, b1)); \ +} \ +template<int n> inline \ +void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + hreg a1 = rshr(a.val, n); \ + vst1_##suffix(ptr, a1); \ +} + +OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_uint16x8, pack, vqmovn_u16, vqrshrn_n_u16) +OPENCV_HAL_IMPL_NEON_PACK(v_int8x16, schar, int8x8_t, s8, v_int16x8, pack, vqmovn_s16, vqrshrn_n_s16) +OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_uint32x4, pack, vqmovn_u32, vqrshrn_n_u32) +OPENCV_HAL_IMPL_NEON_PACK(v_int16x8, short, int16x4_t, s16, v_int32x4, pack, vqmovn_s32, vqrshrn_n_s32) +OPENCV_HAL_IMPL_NEON_PACK(v_uint32x4, unsigned, uint32x2_t, u32, v_uint64x2, pack, vmovn_u64, vrshrn_n_u64) +OPENCV_HAL_IMPL_NEON_PACK(v_int32x4, int, int32x2_t, s32, v_int64x2, pack, vmovn_s64, vrshrn_n_s64) + +OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_int16x8, pack_u, vqmovun_s16, vqrshrun_n_s16) +OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_int32x4, pack_u, vqmovun_s32, vqrshrun_n_s32) + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + uint8x16_t ab = vcombine_u8(vmovn_u16(a.val), vmovn_u16(b.val)); + return v_uint8x16(ab); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + uint16x8_t nab = vcombine_u16(vmovn_u32(a.val), vmovn_u32(b.val)); + uint16x8_t ncd = vcombine_u16(vmovn_u32(c.val), vmovn_u32(d.val)); + return v_uint8x16(vcombine_u8(vmovn_u16(nab), vmovn_u16(ncd))); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + uint32x4_t ab = vcombine_u32(vmovn_u64(a.val), vmovn_u64(b.val)); + uint32x4_t cd = vcombine_u32(vmovn_u64(c.val), vmovn_u64(d.val)); + uint32x4_t ef = vcombine_u32(vmovn_u64(e.val), vmovn_u64(f.val)); + uint32x4_t gh = vcombine_u32(vmovn_u64(g.val), vmovn_u64(h.val)); + + uint16x8_t abcd = vcombine_u16(vmovn_u32(ab), vmovn_u32(cd)); + uint16x8_t efgh = vcombine_u16(vmovn_u32(ef), vmovn_u32(gh)); + return v_uint8x16(vcombine_u8(vmovn_u16(abcd), vmovn_u16(efgh))); +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val); + float32x4_t res = vmulq_lane_f32(m0.val, vl, 0); + res = vmlaq_lane_f32(res, m1.val, vl, 1); + res = vmlaq_lane_f32(res, m2.val, vh, 0); + res = vmlaq_lane_f32(res, m3.val, vh, 1); + return v_float32x4(res); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val); + float32x4_t res = vmulq_lane_f32(m0.val, vl, 0); + res = vmlaq_lane_f32(res, m1.val, vl, 1); + res = vmlaq_lane_f32(res, m2.val, vh, 0); + res = vaddq_f32(res, a.val); + return v_float32x4(res); +} + +#define OPENCV_HAL_IMPL_NEON_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a.val = intrin(a.val, b.val); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint8x16, vqaddq_u8) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint8x16, vqsubq_u8) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int8x16, vqaddq_s8) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int8x16, vqsubq_s8) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint16x8, vqaddq_u16) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint16x8, vqsubq_u16) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int16x8, vqaddq_s16) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int16x8, vqsubq_s16) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int32x4, vaddq_s32) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int32x4, vsubq_s32) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_int32x4, vmulq_s32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint32x4, vaddq_u32) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint32x4, vsubq_u32) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_uint32x4, vmulq_u32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float32x4, vaddq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float32x4, vsubq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float32x4, vmulq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int64x2, vaddq_s64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int64x2, vsubq_s64) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint64x2, vaddq_u64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint64x2, vsubq_u64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float32x4, vdivq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float64x2, vaddq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float64x2, vsubq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float64x2, vmulq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float64x2, vdivq_f64) +#else +inline v_float32x4 operator / (const v_float32x4& a, const v_float32x4& b) +{ + float32x4_t reciprocal = vrecpeq_f32(b.val); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + return v_float32x4(vmulq_f32(a.val, reciprocal)); +} +inline v_float32x4& operator /= (v_float32x4& a, const v_float32x4& b) +{ + float32x4_t reciprocal = vrecpeq_f32(b.val); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + a.val = vmulq_f32(a.val, reciprocal); + return a; +} +#endif + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_NEON_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_int16x8, v_int32x4) +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_uint16x8, v_uint32x4) + +// Multiply and expand +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + c.val = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val)); + d.val = vmull_s8(vget_high_s8(a.val), vget_high_s8(b.val)); +} + +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + c.val = vmull_u8(vget_low_u8(a.val), vget_low_u8(b.val)); + d.val = vmull_u8(vget_high_u8(a.val), vget_high_u8(b.val)); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + c.val = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); + d.val = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + c.val = vmull_u16(vget_low_u16(a.val), vget_low_u16(b.val)); + d.val = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ + c.val = vmull_u32(vget_low_u32(a.val), vget_low_u32(b.val)); + d.val = vmull_u32(vget_high_u32(a.val), vget_high_u32(b.val)); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + return v_int16x8(vcombine_s16( + vshrn_n_s32(vmull_s16( vget_low_s16(a.val), vget_low_s16(b.val)), 16), + vshrn_n_s32(vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)), 16) + )); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + return v_uint16x8(vcombine_u16( + vshrn_n_u32(vmull_u16( vget_low_u16(a.val), vget_low_u16(b.val)), 16), + vshrn_n_u32(vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)), 16) + )); +} + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ + int32x4_t c = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); + int32x4_t d = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)); + int32x4x2_t cd = vuzpq_s32(c, d); + return v_int32x4(vaddq_s32(cd.val[0], cd.val[1])); +} + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + v_int32x4 s = v_dotprod(a, b); + return v_int32x4(vaddq_s32(s.val , c.val)); +} + +#define OPENCV_HAL_IMPL_NEON_LOGIC_OP(_Tpvec, suffix) \ + OPENCV_HAL_IMPL_NEON_BIN_OP(&, _Tpvec, vandq_##suffix) \ + OPENCV_HAL_IMPL_NEON_BIN_OP(|, _Tpvec, vorrq_##suffix) \ + OPENCV_HAL_IMPL_NEON_BIN_OP(^, _Tpvec, veorq_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { \ + return _Tpvec(vreinterpretq_##suffix##_u8(vmvnq_u8(vreinterpretq_u8_##suffix(a.val)))); \ + } + +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint8x16, u8) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int8x16, s8) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint16x8, u16) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int16x8, s16) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint32x4, u32) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int32x4, s32) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint64x2, u64) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int64x2, s64) + +#define OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(bin_op, intrin) \ +inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \ +{ \ + return v_float32x4(vreinterpretq_f32_s32(intrin(vreinterpretq_s32_f32(a.val), vreinterpretq_s32_f32(b.val)))); \ +} \ +inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \ +{ \ + a.val = vreinterpretq_f32_s32(intrin(vreinterpretq_s32_f32(a.val), vreinterpretq_s32_f32(b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(&, vandq_s32) +OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(|, vorrq_s32) +OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(^, veorq_s32) + +inline v_float32x4 operator ~ (const v_float32x4& a) +{ + return v_float32x4(vreinterpretq_f32_s32(vmvnq_s32(vreinterpretq_s32_f32(a.val)))); +} + +#if CV_SIMD128_64F +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + return v_float32x4(vsqrtq_f32(x.val)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + v_float32x4 one = v_setall_f32(1.0f); + return one / v_sqrt(x); +} +#else +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + float32x4_t x1 = vmaxq_f32(x.val, vdupq_n_f32(FLT_MIN)); + float32x4_t e = vrsqrteq_f32(x1); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); + return v_float32x4(vmulq_f32(x.val, e)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + float32x4_t e = vrsqrteq_f32(x.val); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e); + return v_float32x4(e); +} +#endif + +#define OPENCV_HAL_IMPL_NEON_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \ +inline _Tpuvec v_abs(const _Tpsvec& a) { return v_reinterpret_as_##usuffix(_Tpsvec(vabsq_##ssuffix(a.val))); } + +OPENCV_HAL_IMPL_NEON_ABS(v_uint8x16, v_int8x16, u8, s8) +OPENCV_HAL_IMPL_NEON_ABS(v_uint16x8, v_int16x8, u16, s16) +OPENCV_HAL_IMPL_NEON_ABS(v_uint32x4, v_int32x4, u32, s32) + +inline v_float32x4 v_abs(v_float32x4 x) +{ return v_float32x4(vabsq_f32(x.val)); } + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(bin_op, intrin) \ +inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \ +{ \ + return v_float64x2(vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val)))); \ +} \ +inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \ +{ \ + a.val = vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(&, vandq_s64) +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(|, vorrq_s64) +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(^, veorq_s64) + +inline v_float64x2 operator ~ (const v_float64x2& a) +{ + return v_float64x2(vreinterpretq_f64_s32(vmvnq_s32(vreinterpretq_s32_f64(a.val)))); +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ + return v_float64x2(vsqrtq_f64(x.val)); +} + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + v_float64x2 one = v_setall_f64(1.0f); + return one / v_sqrt(x); +} + +inline v_float64x2 v_abs(v_float64x2 x) +{ return v_float64x2(vabsq_f64(x.val)); } +#endif + +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_NEON_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_min, vminq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_max, vmaxq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_min, vminq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_max, vmaxq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_min, vminq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_max, vmaxq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_min, vminq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_max, vmaxq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_min, vminq_u32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_max, vmaxq_u32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_min, vminq_s32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_max, vmaxq_s32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_min, vminq_f32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_max, vmaxq_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_min, vminq_f64) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_max, vmaxq_f64) +#endif + +#if CV_SIMD128_64F +inline int64x2_t vmvnq_s64(int64x2_t a) +{ + int64x2_t vx = vreinterpretq_s64_u32(vdupq_n_u32(0xFFFFFFFF)); + return veorq_s64(a, vx); +} +inline uint64x2_t vmvnq_u64(uint64x2_t a) +{ + uint64x2_t vx = vreinterpretq_u64_u32(vdupq_n_u32(0xFFFFFFFF)); + return veorq_u64(a, vx); +} +#endif +#define OPENCV_HAL_IMPL_NEON_INT_CMP_OP(_Tpvec, cast, suffix, not_suffix) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vceqq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vmvnq_##not_suffix(vceqq_##suffix(a.val, b.val)))); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcltq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcgtq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcleq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcgeq_##suffix(a.val, b.val))); } + +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint8x16, OPENCV_HAL_NOP, u8, u8) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int8x16, vreinterpretq_s8_u8, s8, u8) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint16x8, OPENCV_HAL_NOP, u16, u16) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int16x8, vreinterpretq_s16_u16, s16, u16) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint32x4, OPENCV_HAL_NOP, u32, u32) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int32x4, vreinterpretq_s32_u32, s32, u32) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float32x4, vreinterpretq_f32_u32, f32, u32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint64x2, OPENCV_HAL_NOP, u64, u64) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int64x2, vreinterpretq_s64_u64, s64, u64) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float64x2, vreinterpretq_f64_u64, f64, u64) +#endif + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(vreinterpretq_f32_u32(vceqq_f32(a.val, a.val))); } +#if CV_SIMD128_64F +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(vreinterpretq_f64_u64(vceqq_f64(a.val, a.val))); } +#endif + +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_add_wrap, vaddq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_add_wrap, vaddq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_add_wrap, vaddq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_add_wrap, vaddq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_sub_wrap, vsubq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_sub_wrap, vsubq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_sub_wrap, vsubq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_sub_wrap, vsubq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_mul_wrap, vmulq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_mul_wrap, vmulq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_mul_wrap, vmulq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_mul_wrap, vmulq_s16) + +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_absdiff, vabdq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_absdiff, vabdq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_absdiff, vabdq_u32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_absdiff, vabdq_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_absdiff, vabdq_f64) +#endif + +/** Saturating absolute difference **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ return v_int8x16(vqabsq_s8(vqsubq_s8(a.val, b.val))); } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_int16x8(vqabsq_s16(vqsubq_s16(a.val, b.val))); } + +#define OPENCV_HAL_IMPL_NEON_BIN_FUNC2(_Tpvec, _Tpvec2, cast, func, intrin) \ +inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec2(cast(intrin(a.val, b.val))); \ +} + +OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int8x16, v_uint8x16, vreinterpretq_u8_s8, v_absdiff, vabdq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int16x8, v_uint16x8, vreinterpretq_u16_s16, v_absdiff, vabdq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int32x4, v_uint32x4, vreinterpretq_u32_s32, v_absdiff, vabdq_s32) + +inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 x(vmlaq_f32(vmulq_f32(a.val, a.val), b.val, b.val)); + return v_sqrt(x); +} + +inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + return v_float32x4(vmlaq_f32(vmulq_f32(a.val, a.val), b.val, b.val)); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ +#if CV_SIMD128_64F + // ARMv8, which adds support for 64-bit floating-point (so CV_SIMD128_64F is defined), + // also adds FMA support both for single- and double-precision floating-point vectors + return v_float32x4(vfmaq_f32(c.val, a.val, b.val)); +#else + return v_float32x4(vmlaq_f32(c.val, a.val, b.val)); +#endif +} + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_int32x4(vmlaq_s32(c.val, a.val, b.val)); +} + +inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +#if CV_SIMD128_64F +inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 x(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val))); + return v_sqrt(x); +} + +inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val))); +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_float64x2(vfmaq_f64(c.val, a.val, b.val)); +} + +inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_fma(a, b, c); +} +#endif + +// trade efficiency for convenience +#define OPENCV_HAL_IMPL_NEON_SHIFT_OP(_Tpvec, suffix, _Tps, ssuffix) \ +inline _Tpvec operator << (const _Tpvec& a, int n) \ +{ return _Tpvec(vshlq_##suffix(a.val, vdupq_n_##ssuffix((_Tps)n))); } \ +inline _Tpvec operator >> (const _Tpvec& a, int n) \ +{ return _Tpvec(vshlq_##suffix(a.val, vdupq_n_##ssuffix((_Tps)-n))); } \ +template<int n> inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec(vshlq_n_##suffix(a.val, n)); } \ +template<int n> inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec(vshrq_n_##suffix(a.val, n)); } \ +template<int n> inline _Tpvec v_rshr(const _Tpvec& a) \ +{ return _Tpvec(vrshrq_n_##suffix(a.val, n)); } + +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint8x16, u8, schar, s8) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int8x16, s8, schar, s8) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint16x8, u16, short, s16) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int16x8, s16, short, s16) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint32x4, u32, int, s32) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int32x4, s32, int, s32) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint64x2, u64, int64, s64) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int64x2, s64, int64, s64) + +#define OPENCV_HAL_IMPL_NEON_ROTATE_OP(_Tpvec, suffix) \ +template<int n> inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ return _Tpvec(vextq_##suffix(a.val, vdupq_n_##suffix(0), n)); } \ +template<int n> inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ return _Tpvec(vextq_##suffix(vdupq_n_##suffix(0), a.val, _Tpvec::nlanes - n)); } \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \ +{ return a; } \ +template<int n> inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vextq_##suffix(a.val, b.val, n)); } \ +template<int n> inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vextq_##suffix(b.val, a.val, _Tpvec::nlanes - n)); } \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \ +{ CV_UNUSED(b); return a; } + +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint8x16, u8) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int8x16, s8) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint16x8, u16) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int16x8, s16) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint32x4, u32) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int32x4, s32) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_float32x4, f32) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint64x2, u64) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int64x2, s64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_float64x2, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(vld1q_##suffix(ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(vld1q_##suffix(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr), vdup_n_##suffix((_Tp)0))); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr0), vld1_##suffix(ptr1))); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ vst1_##suffix(ptr, vget_low_##suffix(a.val)); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ vst1_##suffix(ptr, vget_high_##suffix(a.val)); } + +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ + a0 = vp##vectorfunc##_##suffix(a0, a0); \ + return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \ +} + +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, sum, add, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, max, max, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, min, min, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, sum, add, s16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, max, max, s16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, min, min, s16) + +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ + return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, vget_high_##suffix(a.val)),0); \ +} + +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, sum, add, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, max, max, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, min, min, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, sum, add, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, max, max, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, min, min, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, sum, add, f32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, max, max, f32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, min, min, f32) + +#if CV_SIMD128_64F +inline double v_reduce_sum(const v_float64x2& a) +{ + return vgetq_lane_f64(a.val, 0) + vgetq_lane_f64(a.val, 1); +} +#endif + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + float32x4x2_t ab = vtrnq_f32(a.val, b.val); + float32x4x2_t cd = vtrnq_f32(c.val, d.val); + + float32x4_t u0 = vaddq_f32(ab.val[0], ab.val[1]); // a0+a1 b0+b1 a2+a3 b2+b3 + float32x4_t u1 = vaddq_f32(cd.val[0], cd.val[1]); // c0+c1 d0+d1 c2+c3 d2+d3 + + float32x4_t v0 = vcombine_f32(vget_low_f32(u0), vget_low_f32(u1)); + float32x4_t v1 = vcombine_f32(vget_high_f32(u0), vget_high_f32(u1)); + + return v_float32x4(vaddq_f32(v0, v1)); +} + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vabdq_u8(a.val, b.val))); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vreinterpretq_u8_s8(vabdq_s8(a.val, b.val)))); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + uint32x4_t t0 = vpaddlq_u16(vabdq_u16(a.val, b.val)); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + uint32x4_t t0 = vpaddlq_u16(vreinterpretq_u16_s16(vabdq_s16(a.val, b.val))); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + uint32x4_t t0 = vabdq_u32(a.val, b.val); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + uint32x4_t t0 = vreinterpretq_u32_s32(vabdq_s32(a.val, b.val)); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + float32x4_t t0 = vabdq_f32(a.val, b.val); + float32x2_t t1 = vpadd_f32(vget_low_f32(t0), vget_high_f32(t0)); + return vget_lane_f32(vpadd_f32(t1, t1), 0); +} + +#define OPENCV_HAL_IMPL_NEON_POPCOUNT(_Tpvec, cast) \ +inline v_uint32x4 v_popcount(const _Tpvec& a) \ +{ \ + uint8x16_t t = vcntq_u8(cast(a.val)); \ + uint16x8_t t0 = vpaddlq_u8(t); /* 16 -> 8 */ \ + uint32x4_t t1 = vpaddlq_u16(t0); /* 8 -> 4 */ \ + return v_uint32x4(t1); \ +} + +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_uint8x16, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_uint16x8, vreinterpretq_u8_u16) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_uint32x4, vreinterpretq_u8_u32) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_int8x16, vreinterpretq_u8_s8) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_int16x8, vreinterpretq_u8_s16) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_int32x4, vreinterpretq_u8_s32) + +inline int v_signmask(const v_uint8x16& a) +{ + int8x8_t m0 = vcreate_s8(CV_BIG_UINT(0x0706050403020100)); + uint8x16_t v0 = vshlq_u8(vshrq_n_u8(a.val, 7), vcombine_s8(m0, m0)); + uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(v0))); + return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 8); +} +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } + +inline int v_signmask(const v_uint16x8& a) +{ + int16x4_t m0 = vcreate_s16(CV_BIG_UINT(0x0003000200010000)); + uint16x8_t v0 = vshlq_u16(vshrq_n_u16(a.val, 15), vcombine_s16(m0, m0)); + uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(v0)); + return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 4); +} +inline int v_signmask(const v_int16x8& a) +{ return v_signmask(v_reinterpret_as_u16(a)); } + +inline int v_signmask(const v_uint32x4& a) +{ + int32x2_t m0 = vcreate_s32(CV_BIG_UINT(0x0000000100000000)); + uint32x4_t v0 = vshlq_u32(vshrq_n_u32(a.val, 31), vcombine_s32(m0, m0)); + uint64x2_t v1 = vpaddlq_u32(v0); + return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 2); +} +inline int v_signmask(const v_int32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +#if CV_SIMD128_64F +inline int v_signmask(const v_uint64x2& a) +{ + int64x1_t m0 = vdup_n_s64(0); + uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), vcombine_s64(m0, m0)); + return (int)vgetq_lane_u64(v0, 0) + ((int)vgetq_lane_u64(v0, 1) << 1); +} +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +#endif + +#define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \ +inline bool v_check_all(const v_##_Tpvec& a) \ +{ \ + _Tpvec##_t v0 = vshrq_n_##suffix(vmvnq_##suffix(a.val), shift); \ + uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ + return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) == 0; \ +} \ +inline bool v_check_any(const v_##_Tpvec& a) \ +{ \ + _Tpvec##_t v0 = vshrq_n_##suffix(a.val, shift); \ + uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ + return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) != 0; \ +} + +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint8x16, u8, 7) +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint16x8, u16, 15) +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint32x4, u32, 31) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint64x2, u64, 63) +#endif + +inline bool v_check_all(const v_int8x16& a) +{ return v_check_all(v_reinterpret_as_u8(a)); } +inline bool v_check_all(const v_int16x8& a) +{ return v_check_all(v_reinterpret_as_u16(a)); } +inline bool v_check_all(const v_int32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } + +inline bool v_check_any(const v_int8x16& a) +{ return v_check_any(v_reinterpret_as_u8(a)); } +inline bool v_check_any(const v_int16x8& a) +{ return v_check_any(v_reinterpret_as_u16(a)); } +inline bool v_check_any(const v_int32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } + +#if CV_SIMD128_64F +inline bool v_check_all(const v_int64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_int64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +#endif + +#define OPENCV_HAL_IMPL_NEON_SELECT(_Tpvec, suffix, usuffix) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(vbslq_##suffix(vreinterpretq_##usuffix##_##suffix(mask.val), a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_NEON_SELECT(v_uint8x16, u8, u8) +OPENCV_HAL_IMPL_NEON_SELECT(v_int8x16, s8, u8) +OPENCV_HAL_IMPL_NEON_SELECT(v_uint16x8, u16, u16) +OPENCV_HAL_IMPL_NEON_SELECT(v_int16x8, s16, u16) +OPENCV_HAL_IMPL_NEON_SELECT(v_uint32x4, u32, u32) +OPENCV_HAL_IMPL_NEON_SELECT(v_int32x4, s32, u32) +OPENCV_HAL_IMPL_NEON_SELECT(v_float32x4, f32, u32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_SELECT(v_float64x2, f64, u64) +#endif + +#define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = vmovl_##suffix(vget_low_##suffix(a.val)); \ + b1.val = vmovl_##suffix(vget_high_##suffix(a.val)); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ \ + return _Tpwvec(vmovl_##suffix(vget_low_##suffix(a.val))); \ +} \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ \ + return _Tpwvec(vmovl_##suffix(vget_high_##suffix(a.val))); \ +} \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + return _Tpwvec(vmovl_##suffix(vld1_##suffix(ptr))); \ +} + +OPENCV_HAL_IMPL_NEON_EXPAND(v_uint8x16, v_uint16x8, uchar, u8) +OPENCV_HAL_IMPL_NEON_EXPAND(v_int8x16, v_int16x8, schar, s8) +OPENCV_HAL_IMPL_NEON_EXPAND(v_uint16x8, v_uint32x4, ushort, u16) +OPENCV_HAL_IMPL_NEON_EXPAND(v_int16x8, v_int32x4, short, s16) +OPENCV_HAL_IMPL_NEON_EXPAND(v_uint32x4, v_uint64x2, uint, u32) +OPENCV_HAL_IMPL_NEON_EXPAND(v_int32x4, v_int64x2, int, s32) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ + typedef unsigned int CV_DECL_ALIGNED(1) unaligned_uint; + uint8x8_t v0 = vcreate_u8(*(unaligned_uint*)ptr); + uint16x4_t v1 = vget_low_u16(vmovl_u8(v0)); + return v_uint32x4(vmovl_u16(v1)); +} + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ + typedef unsigned int CV_DECL_ALIGNED(1) unaligned_uint; + int8x8_t v0 = vcreate_s8(*(unaligned_uint*)ptr); + int16x4_t v1 = vget_low_s16(vmovl_s8(v0)); + return v_int32x4(vmovl_s16(v1)); +} + +#if defined(__aarch64__) +#define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + b0.val = vzip1q_##suffix(a0.val, a1.val); \ + b1.val = vzip2q_##suffix(a0.val, a1.val); \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \ + d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \ +} +#else +#define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + _Tpvec##x2_t p = vzipq_##suffix(a0.val, a1.val); \ + b0.val = p.val[0]; \ + b1.val = p.val[1]; \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \ + d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \ +} +#endif + +OPENCV_HAL_IMPL_NEON_UNPACKS(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_UNPACKS(int8x16, s8) +OPENCV_HAL_IMPL_NEON_UNPACKS(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_UNPACKS(int16x8, s16) +OPENCV_HAL_IMPL_NEON_UNPACKS(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_UNPACKS(int32x4, s32) +OPENCV_HAL_IMPL_NEON_UNPACKS(float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_UNPACKS(float64x2, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_EXTRACT(_Tpvec, suffix) \ +template <int s> \ +inline v_##_Tpvec v_extract(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vextq_##suffix(a.val, b.val, s)); \ +} + +OPENCV_HAL_IMPL_NEON_EXTRACT(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_EXTRACT(int8x16, s8) +OPENCV_HAL_IMPL_NEON_EXTRACT(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_EXTRACT(int16x8, s16) +OPENCV_HAL_IMPL_NEON_EXTRACT(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_EXTRACT(int32x4, s32) +OPENCV_HAL_IMPL_NEON_EXTRACT(uint64x2, u64) +OPENCV_HAL_IMPL_NEON_EXTRACT(int64x2, s64) +OPENCV_HAL_IMPL_NEON_EXTRACT(float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_EXTRACT(float64x2, f64) +#endif + +#if CV_SIMD128_64F +inline v_int32x4 v_round(const v_float32x4& a) +{ + float32x4_t a_ = a.val; + int32x4_t result; + __asm__ ("fcvtns %0.4s, %1.4s" + : "=w"(result) + : "w"(a_) + : /* No clobbers */); + return v_int32x4(result); +} +#else +inline v_int32x4 v_round(const v_float32x4& a) +{ + static const int32x4_t v_sign = vdupq_n_s32(1 << 31), + v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); + + int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(a.val))); + return v_int32x4(vcvtq_s32_f32(vaddq_f32(a.val, vreinterpretq_f32_s32(v_addition)))); +} +#endif +inline v_int32x4 v_floor(const v_float32x4& a) +{ + int32x4_t a1 = vcvtq_s32_f32(a.val); + uint32x4_t mask = vcgtq_f32(vcvtq_f32_s32(a1), a.val); + return v_int32x4(vaddq_s32(a1, vreinterpretq_s32_u32(mask))); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + int32x4_t a1 = vcvtq_s32_f32(a.val); + uint32x4_t mask = vcgtq_f32(a.val, vcvtq_f32_s32(a1)); + return v_int32x4(vsubq_s32(a1, vreinterpretq_s32_u32(mask))); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(vcvtq_s32_f32(a.val)); } + +#if CV_SIMD128_64F +inline v_int32x4 v_round(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); +} + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), vmovn_s64(vcvtaq_s64_f64(b.val)))); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + int64x2_t a1 = vcvtq_s64_f64(a.val); + uint64x2_t mask = vcgtq_f64(vcvtq_f64_s64(a1), a.val); + a1 = vaddq_s64(a1, vreinterpretq_s64_u64(mask)); + return v_int32x4(vcombine_s32(vmovn_s64(a1), zero)); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + int64x2_t a1 = vcvtq_s64_f64(a.val); + uint64x2_t mask = vcgtq_f64(a.val, vcvtq_f64_s64(a1)); + a1 = vsubq_s64(a1, vreinterpretq_s64_u64(mask)); + return v_int32x4(vcombine_s32(vmovn_s64(a1), zero)); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); +} +#endif + +#define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \ +inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ + const v_##_Tpvec& a2, const v_##_Tpvec& a3, \ + v_##_Tpvec& b0, v_##_Tpvec& b1, \ + v_##_Tpvec& b2, v_##_Tpvec& b3) \ +{ \ + /* m00 m01 m02 m03 */ \ + /* m10 m11 m12 m13 */ \ + /* m20 m21 m22 m23 */ \ + /* m30 m31 m32 m33 */ \ + _Tpvec##x2_t t0 = vtrnq_##suffix(a0.val, a1.val); \ + _Tpvec##x2_t t1 = vtrnq_##suffix(a2.val, a3.val); \ + /* m00 m10 m02 m12 */ \ + /* m01 m11 m03 m13 */ \ + /* m20 m30 m22 m32 */ \ + /* m21 m31 m23 m33 */ \ + b0.val = vcombine_##suffix(vget_low_##suffix(t0.val[0]), vget_low_##suffix(t1.val[0])); \ + b1.val = vcombine_##suffix(vget_low_##suffix(t0.val[1]), vget_low_##suffix(t1.val[1])); \ + b2.val = vcombine_##suffix(vget_high_##suffix(t0.val[0]), vget_high_##suffix(t1.val[0])); \ + b3.val = vcombine_##suffix(vget_high_##suffix(t0.val[1]), vget_high_##suffix(t1.val[1])); \ +} + +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s32) +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f32) + +#define OPENCV_HAL_IMPL_NEON_INTERLEAVED(_Tpvec, _Tp, suffix) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \ +{ \ + _Tpvec##x2_t v = vld2q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \ +{ \ + _Tpvec##x3_t v = vld3q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ + c.val = v.val[2]; \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \ + v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + _Tpvec##x4_t v = vld4q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ + c.val = v.val[2]; \ + d.val = v.val[3]; \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + _Tpvec##x2_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + vst2q_##suffix(ptr, v); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + _Tpvec##x3_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + v.val[2] = c.val; \ + vst3q_##suffix(ptr, v); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, const v_##_Tpvec& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec##x4_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + v.val[2] = c.val; \ + v.val[3] = d.val; \ + vst4q_##suffix(ptr, v); \ +} + +#define OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(tp, suffix) \ +inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, v_##tp##x2& b ) \ +{ \ + tp##x1_t a0 = vld1_##suffix(ptr); \ + tp##x1_t b0 = vld1_##suffix(ptr + 1); \ + tp##x1_t a1 = vld1_##suffix(ptr + 2); \ + tp##x1_t b1 = vld1_##suffix(ptr + 3); \ + a = v_##tp##x2(vcombine_##suffix(a0, a1)); \ + b = v_##tp##x2(vcombine_##suffix(b0, b1)); \ +} \ + \ +inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, \ + v_##tp##x2& b, v_##tp##x2& c ) \ +{ \ + tp##x1_t a0 = vld1_##suffix(ptr); \ + tp##x1_t b0 = vld1_##suffix(ptr + 1); \ + tp##x1_t c0 = vld1_##suffix(ptr + 2); \ + tp##x1_t a1 = vld1_##suffix(ptr + 3); \ + tp##x1_t b1 = vld1_##suffix(ptr + 4); \ + tp##x1_t c1 = vld1_##suffix(ptr + 5); \ + a = v_##tp##x2(vcombine_##suffix(a0, a1)); \ + b = v_##tp##x2(vcombine_##suffix(b0, b1)); \ + c = v_##tp##x2(vcombine_##suffix(c0, c1)); \ +} \ + \ +inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, v_##tp##x2& b, \ + v_##tp##x2& c, v_##tp##x2& d ) \ +{ \ + tp##x1_t a0 = vld1_##suffix(ptr); \ + tp##x1_t b0 = vld1_##suffix(ptr + 1); \ + tp##x1_t c0 = vld1_##suffix(ptr + 2); \ + tp##x1_t d0 = vld1_##suffix(ptr + 3); \ + tp##x1_t a1 = vld1_##suffix(ptr + 4); \ + tp##x1_t b1 = vld1_##suffix(ptr + 5); \ + tp##x1_t c1 = vld1_##suffix(ptr + 6); \ + tp##x1_t d1 = vld1_##suffix(ptr + 7); \ + a = v_##tp##x2(vcombine_##suffix(a0, a1)); \ + b = v_##tp##x2(vcombine_##suffix(b0, b1)); \ + c = v_##tp##x2(vcombine_##suffix(c0, c1)); \ + d = v_##tp##x2(vcombine_##suffix(d0, d1)); \ +} \ + \ +inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, const v_##tp##x2& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + vst1_##suffix(ptr, vget_low_##suffix(a.val)); \ + vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \ + vst1_##suffix(ptr + 2, vget_high_##suffix(a.val)); \ + vst1_##suffix(ptr + 3, vget_high_##suffix(b.val)); \ +} \ + \ +inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, \ + const v_##tp##x2& b, const v_##tp##x2& c, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + vst1_##suffix(ptr, vget_low_##suffix(a.val)); \ + vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \ + vst1_##suffix(ptr + 2, vget_low_##suffix(c.val)); \ + vst1_##suffix(ptr + 3, vget_high_##suffix(a.val)); \ + vst1_##suffix(ptr + 4, vget_high_##suffix(b.val)); \ + vst1_##suffix(ptr + 5, vget_high_##suffix(c.val)); \ +} \ + \ +inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, const v_##tp##x2& b, \ + const v_##tp##x2& c, const v_##tp##x2& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + vst1_##suffix(ptr, vget_low_##suffix(a.val)); \ + vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \ + vst1_##suffix(ptr + 2, vget_low_##suffix(c.val)); \ + vst1_##suffix(ptr + 3, vget_low_##suffix(d.val)); \ + vst1_##suffix(ptr + 4, vget_high_##suffix(a.val)); \ + vst1_##suffix(ptr + 5, vget_high_##suffix(b.val)); \ + vst1_##suffix(ptr + 6, vget_high_##suffix(c.val)); \ + vst1_##suffix(ptr + 7, vget_high_##suffix(d.val)); \ +} + +OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_INTERLEAVED(float64x2, double, f64) +#endif + +OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(int64, s64) +OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(uint64, u64) + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(vcvtq_f32_s32(a.val)); +} + +#if CV_SIMD128_64F +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + float32x2_t zero = vdup_n_f32(0.0f); + return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), zero)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), vcvt_f32_f64(b.val))); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_low_s32(a.val)))); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_high_s32(a.val)))); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vget_low_f32(a.val))); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vget_high_f32(a.val))); +} +#endif + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[ 0]], + tab[idx[ 1]], + tab[idx[ 2]], + tab[idx[ 3]], + tab[idx[ 4]], + tab[idx[ 5]], + tab[idx[ 6]], + tab[idx[ 7]], + tab[idx[ 8]], + tab[idx[ 9]], + tab[idx[10]], + tab[idx[11]], + tab[idx[12]], + tab[idx[13]], + tab[idx[14]], + tab[idx[15]] + }; + return v_int8x16(vld1q_s8(elems)); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[4]], + tab[idx[4] + 1], + tab[idx[5]], + tab[idx[5] + 1], + tab[idx[6]], + tab[idx[6] + 1], + tab[idx[7]], + tab[idx[7] + 1] + }; + return v_int8x16(vld1q_s8(elems)); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[2] + 2], + tab[idx[2] + 3], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[3] + 2], + tab[idx[3] + 3] + }; + return v_int8x16(vld1q_s8(elems)); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]], + tab[idx[4]], + tab[idx[5]], + tab[idx[6]], + tab[idx[7]] + }; + return v_int16x8(vld1q_s16(elems)); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1] + }; + return v_int16x8(vld1q_s16(elems)); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_int16x8(vcombine_s16(vld1_s16(tab + idx[0]), vld1_s16(tab + idx[1]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_int32x4(vld1q_s32(elems)); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_int32x4(vcombine_s32(vld1_s32(tab + idx[0]), vld1_s32(tab + idx[1]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(vld1q_s32(tab + idx[0])); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(vcombine_s64(vcreate_s64(tab[idx[0]]), vcreate_s64(tab[idx[1]]))); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(vld1q_s64(tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_float32x4(vld1q_f32(elems)); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) +{ + uint64 CV_DECL_ALIGNED(32) elems[2] = + { + *(uint64*)(tab + idx[0]), + *(uint64*)(tab + idx[1]) + }; + return v_float32x4(vreinterpretq_f32_u64(vld1q_u64(elems))); +} +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) +{ + return v_float32x4(vld1q_f32(tab + idx[0])); +} + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + tab[vgetq_lane_s32(idxvec.val, 2)], + tab[vgetq_lane_s32(idxvec.val, 3)] + }; + return v_int32x4(vld1q_s32(elems)); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + unsigned CV_DECL_ALIGNED(32) elems[4] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + tab[vgetq_lane_s32(idxvec.val, 2)], + tab[vgetq_lane_s32(idxvec.val, 3)] + }; + return v_uint32x4(vld1q_u32(elems)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + tab[vgetq_lane_s32(idxvec.val, 2)], + tab[vgetq_lane_s32(idxvec.val, 3)] + }; + return v_float32x4(vld1q_f32(elems)); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + /*int CV_DECL_ALIGNED(32) idx[4]; + v_store(idx, idxvec); + + float32x4_t xy02 = vcombine_f32(vld1_f32(tab + idx[0]), vld1_f32(tab + idx[2])); + float32x4_t xy13 = vcombine_f32(vld1_f32(tab + idx[1]), vld1_f32(tab + idx[3])); + + float32x4x2_t xxyy = vuzpq_f32(xy02, xy13); + x = v_float32x4(xxyy.val[0]); + y = v_float32x4(xxyy.val[1]);*/ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + x = v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); + y = v_float32x4(tab[idx[0]+1], tab[idx[1]+1], tab[idx[2]+1], tab[idx[3]+1]); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + return v_int8x16(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0705060403010200)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0705060403010200)))); +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + return v_int8x16(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0703060205010400)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0703060205010400)))); +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + return v_int16x8(vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0706030205040100)), vtbl1_s8(vget_high_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0706030205040100))))); +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + int16x4x2_t res = vzip_s16(vget_low_s16(vec.val), vget_high_s16(vec.val)); + return v_int16x8(vcombine_s16(res.val[0], res.val[1])); +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + int32x2x2_t res = vzip_s32(vget_low_s32(vec.val), vget_high_s32(vec.val)); + return v_int32x4(vcombine_s32(res.val[0], res.val[1])); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + return v_int8x16(vextq_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0605040201000000)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0807060504020100))), vdupq_n_s8(0), 2)); +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + return v_int16x8(vreinterpretq_s16_s8(vextq_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0504030201000000)), vget_high_s8(vreinterpretq_s8_s16(vec.val))), vdupq_n_s8(0), 2))); +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +#if CV_SIMD128_64F +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[idx[0]], + tab[idx[1]] + }; + return v_float64x2(vld1q_f64(elems)); +} + +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) +{ + return v_float64x2(vld1q_f64(tab + idx[0])); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + }; + return v_float64x2(vld1q_f64(elems)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + x = v_float64x2(tab[idx[0]], tab[idx[1]]); + y = v_float64x2(tab[idx[0]+1], tab[idx[1]+1]); +} +#endif + +////// FP16 support /////// +#if CV_FP16 +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + float16x4_t v = + #ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro + (float16x4_t)vld1_s16((const short*)ptr); + #else + vld1_f16((const __fp16*)ptr); + #endif + return v_float32x4(vcvt_f32_f16(v)); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + float16x4_t hv = vcvt_f16_f32(v.val); + + #ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro + vst1_s16((short*)ptr, (int16x4_t)hv); + #else + vst1_f16((__fp16*)ptr, hv); + #endif +} +#else +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + const int N = 4; + float buf[N]; + for( int i = 0; i < N; i++ ) buf[i] = (float)ptr[i]; + return v_load(buf); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + const int N = 4; + float buf[N]; + v_store(buf, v); + for( int i = 0; i < N; i++ ) ptr[i] = float16_t(buf[i]); +} +#endif + +inline void v_cleanup() {} + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return (CV_CPU_HAS_SUPPORT_NEON) ? true : false; +} + +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif diff --git a/include/opencv2/core/hal/intrin_sse.hpp b/include/opencv2/core/hal/intrin_sse.hpp new file mode 100644 index 0000000..a5adad0 --- /dev/null +++ b/include/opencv2/core/hal/intrin_sse.hpp @@ -0,0 +1,3016 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HAL_SSE_HPP +#define OPENCV_HAL_SSE_HPP + +#include <algorithm> +#include "opencv2/core/utility.hpp" + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 +#define CV_SIMD128_FP16 0 // no native operations with FP16 type. + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + typedef __m128i vector_type; + enum { nlanes = 16 }; + + v_uint8x16() : val(_mm_setzero_si128()) {} + explicit v_uint8x16(__m128i v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + val = _mm_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, + (char)v4, (char)v5, (char)v6, (char)v7, + (char)v8, (char)v9, (char)v10, (char)v11, + (char)v12, (char)v13, (char)v14, (char)v15); + } + uchar get0() const + { + return (uchar)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + typedef __m128i vector_type; + enum { nlanes = 16 }; + + v_int8x16() : val(_mm_setzero_si128()) {} + explicit v_int8x16(__m128i v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + val = _mm_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, + (char)v4, (char)v5, (char)v6, (char)v7, + (char)v8, (char)v9, (char)v10, (char)v11, + (char)v12, (char)v13, (char)v14, (char)v15); + } + schar get0() const + { + return (schar)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + typedef __m128i vector_type; + enum { nlanes = 8 }; + + v_uint16x8() : val(_mm_setzero_si128()) {} + explicit v_uint16x8(__m128i v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + val = _mm_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, + (short)v4, (short)v5, (short)v6, (short)v7); + } + ushort get0() const + { + return (ushort)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + typedef __m128i vector_type; + enum { nlanes = 8 }; + + v_int16x8() : val(_mm_setzero_si128()) {} + explicit v_int16x8(__m128i v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + val = _mm_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, + (short)v4, (short)v5, (short)v6, (short)v7); + } + short get0() const + { + return (short)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + typedef __m128i vector_type; + enum { nlanes = 4 }; + + v_uint32x4() : val(_mm_setzero_si128()) {} + explicit v_uint32x4(__m128i v) : val(v) {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + val = _mm_setr_epi32((int)v0, (int)v1, (int)v2, (int)v3); + } + unsigned get0() const + { + return (unsigned)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + typedef __m128i vector_type; + enum { nlanes = 4 }; + + v_int32x4() : val(_mm_setzero_si128()) {} + explicit v_int32x4(__m128i v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + val = _mm_setr_epi32(v0, v1, v2, v3); + } + int get0() const + { + return _mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + typedef __m128 vector_type; + enum { nlanes = 4 }; + + v_float32x4() : val(_mm_setzero_ps()) {} + explicit v_float32x4(__m128 v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + val = _mm_setr_ps(v0, v1, v2, v3); + } + float get0() const + { + return _mm_cvtss_f32(val); + } + + __m128 val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + typedef __m128i vector_type; + enum { nlanes = 2 }; + + v_uint64x2() : val(_mm_setzero_si128()) {} + explicit v_uint64x2(__m128i v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + val = _mm_setr_epi32((int)v0, (int)(v0 >> 32), (int)v1, (int)(v1 >> 32)); + } + uint64 get0() const + { + int a = _mm_cvtsi128_si32(val); + int b = _mm_cvtsi128_si32(_mm_srli_epi64(val, 32)); + return (unsigned)a | ((uint64)(unsigned)b << 32); + } + + __m128i val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + typedef __m128i vector_type; + enum { nlanes = 2 }; + + v_int64x2() : val(_mm_setzero_si128()) {} + explicit v_int64x2(__m128i v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + val = _mm_setr_epi32((int)v0, (int)(v0 >> 32), (int)v1, (int)(v1 >> 32)); + } + int64 get0() const + { + int a = _mm_cvtsi128_si32(val); + int b = _mm_cvtsi128_si32(_mm_srli_epi64(val, 32)); + return (int64)((unsigned)a | ((uint64)(unsigned)b << 32)); + } + + __m128i val; +}; + +struct v_float64x2 +{ + typedef double lane_type; + typedef __m128d vector_type; + enum { nlanes = 2 }; + + v_float64x2() : val(_mm_setzero_pd()) {} + explicit v_float64x2(__m128d v) : val(v) {} + v_float64x2(double v0, double v1) + { + val = _mm_setr_pd(v0, v1); + } + double get0() const + { + return _mm_cvtsd_f64(val); + } + + __m128d val; +}; + +namespace hal_sse_internal +{ + template <typename to_sse_type, typename from_sse_type> + to_sse_type v_sse_reinterpret_as(const from_sse_type& val); + +#define OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(to_sse_type, from_sse_type, sse_cast_intrin) \ + template<> inline \ + to_sse_type v_sse_reinterpret_as(const from_sse_type& a) \ + { return sse_cast_intrin(a); } + + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128i, OPENCV_HAL_NOP) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128, _mm_castps_si128) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128d, _mm_castpd_si128) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128i, _mm_castsi128_ps) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128, OPENCV_HAL_NOP) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128d, _mm_castpd_ps) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128i, _mm_castsi128_pd) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128, _mm_castps_pd) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128d, OPENCV_HAL_NOP) +} + +#define OPENCV_HAL_IMPL_SSE_INITVEC(_Tpvec, _Tp, suffix, zsuffix, ssuffix, _Tps, cast) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec(_mm_setzero_##zsuffix()); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(_mm_set1_##ssuffix((_Tps)v)); } \ +template<typename _Tpvec0> inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0& a) \ +{ return _Tpvec(cast(a.val)); } + +OPENCV_HAL_IMPL_SSE_INITVEC(v_uint8x16, uchar, u8, si128, epi8, char, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_int8x16, schar, s8, si128, epi8, char, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_uint16x8, ushort, u16, si128, epi16, short, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_int16x8, short, s16, si128, epi16, short, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_uint32x4, unsigned, u32, si128, epi32, int, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_int32x4, int, s32, si128, epi32, int, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_float32x4, float, f32, ps, ps, float, _mm_castsi128_ps) +OPENCV_HAL_IMPL_SSE_INITVEC(v_float64x2, double, f64, pd, pd, double, _mm_castsi128_pd) + +inline v_uint64x2 v_setzero_u64() { return v_uint64x2(_mm_setzero_si128()); } +inline v_int64x2 v_setzero_s64() { return v_int64x2(_mm_setzero_si128()); } +inline v_uint64x2 v_setall_u64(uint64 val) { return v_uint64x2(val, val); } +inline v_int64x2 v_setall_s64(int64 val) { return v_int64x2(val, val); } + +template<typename _Tpvec> inline +v_uint64x2 v_reinterpret_as_u64(const _Tpvec& a) { return v_uint64x2(a.val); } +template<typename _Tpvec> inline +v_int64x2 v_reinterpret_as_s64(const _Tpvec& a) { return v_int64x2(a.val); } +inline v_float32x4 v_reinterpret_as_f32(const v_uint64x2& a) +{ return v_float32x4(_mm_castsi128_ps(a.val)); } +inline v_float32x4 v_reinterpret_as_f32(const v_int64x2& a) +{ return v_float32x4(_mm_castsi128_ps(a.val)); } +inline v_float64x2 v_reinterpret_as_f64(const v_uint64x2& a) +{ return v_float64x2(_mm_castsi128_pd(a.val)); } +inline v_float64x2 v_reinterpret_as_f64(const v_int64x2& a) +{ return v_float64x2(_mm_castsi128_pd(a.val)); } + +#define OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(_Tpvec, suffix) \ +inline _Tpvec v_reinterpret_as_##suffix(const v_float32x4& a) \ +{ return _Tpvec(_mm_castps_si128(a.val)); } \ +inline _Tpvec v_reinterpret_as_##suffix(const v_float64x2& a) \ +{ return _Tpvec(_mm_castpd_si128(a.val)); } + +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint8x16, u8) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int8x16, s8) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint16x8, u16) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int16x8, s16) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint32x4, u32) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int32x4, s32) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint64x2, u64) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int64x2, s64) + +inline v_float32x4 v_reinterpret_as_f32(const v_float32x4& a) {return a; } +inline v_float64x2 v_reinterpret_as_f64(const v_float64x2& a) {return a; } +inline v_float32x4 v_reinterpret_as_f32(const v_float64x2& a) {return v_float32x4(_mm_castpd_ps(a.val)); } +inline v_float64x2 v_reinterpret_as_f64(const v_float32x4& a) {return v_float64x2(_mm_castps_pd(a.val)); } + +//////////////// PACK /////////////// +inline v_uint8x16 v_pack(const v_uint16x8& a, const v_uint16x8& b) +{ + __m128i delta = _mm_set1_epi16(255); + return v_uint8x16(_mm_packus_epi16(_mm_subs_epu16(a.val, _mm_subs_epu16(a.val, delta)), + _mm_subs_epu16(b.val, _mm_subs_epu16(b.val, delta)))); +} + +inline void v_pack_store(uchar* ptr, const v_uint16x8& a) +{ + __m128i delta = _mm_set1_epi16(255); + __m128i a1 = _mm_subs_epu16(a.val, _mm_subs_epu16(a.val, delta)); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a1, a1)); +} + +inline v_uint8x16 v_pack_u(const v_int16x8& a, const v_int16x8& b) +{ return v_uint8x16(_mm_packus_epi16(a.val, b.val)); } + +inline void v_pack_u_store(uchar* ptr, const v_int16x8& a) +{ _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a.val, a.val)); } + +template<int n> inline +v_uint8x16 v_rshr_pack(const v_uint16x8& a, const v_uint16x8& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + return v_uint8x16(_mm_packus_epi16(_mm_srli_epi16(_mm_adds_epu16(a.val, delta), n), + _mm_srli_epi16(_mm_adds_epu16(b.val, delta), n))); +} + +template<int n> inline +void v_rshr_pack_store(uchar* ptr, const v_uint16x8& a) +{ + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + __m128i a1 = _mm_srli_epi16(_mm_adds_epu16(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a1, a1)); +} + +template<int n> inline +v_uint8x16 v_rshr_pack_u(const v_int16x8& a, const v_int16x8& b) +{ + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + return v_uint8x16(_mm_packus_epi16(_mm_srai_epi16(_mm_adds_epi16(a.val, delta), n), + _mm_srai_epi16(_mm_adds_epi16(b.val, delta), n))); +} + +template<int n> inline +void v_rshr_pack_u_store(uchar* ptr, const v_int16x8& a) +{ + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + __m128i a1 = _mm_srai_epi16(_mm_adds_epi16(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a1, a1)); +} + +inline v_int8x16 v_pack(const v_int16x8& a, const v_int16x8& b) +{ return v_int8x16(_mm_packs_epi16(a.val, b.val)); } + +inline void v_pack_store(schar* ptr, const v_int16x8& a) +{ _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi16(a.val, a.val)); } + +template<int n> inline +v_int8x16 v_rshr_pack(const v_int16x8& a, const v_int16x8& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + return v_int8x16(_mm_packs_epi16(_mm_srai_epi16(_mm_adds_epi16(a.val, delta), n), + _mm_srai_epi16(_mm_adds_epi16(b.val, delta), n))); +} +template<int n> inline +void v_rshr_pack_store(schar* ptr, const v_int16x8& a) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + __m128i a1 = _mm_srai_epi16(_mm_adds_epi16(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi16(a1, a1)); +} + + +// byte-wise "mask ? a : b" +inline __m128i v_select_si128(__m128i mask, __m128i a, __m128i b) +{ +#if CV_SSE4_1 + return _mm_blendv_epi8(b, a, mask); +#else + return _mm_xor_si128(b, _mm_and_si128(_mm_xor_si128(a, b), mask)); +#endif +} + +inline v_uint16x8 v_pack(const v_uint32x4& a, const v_uint32x4& b) +{ return v_uint16x8(_v128_packs_epu32(a.val, b.val)); } + +inline void v_pack_store(ushort* ptr, const v_uint32x4& a) +{ + __m128i z = _mm_setzero_si128(), maxval32 = _mm_set1_epi32(65535), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(v_select_si128(_mm_cmpgt_epi32(z, a.val), maxval32, a.val), delta32); + __m128i r = _mm_packs_epi32(a1, a1); + _mm_storel_epi64((__m128i*)ptr, _mm_sub_epi16(r, _mm_set1_epi16(-32768))); +} + +template<int n> inline +v_uint16x8 v_rshr_pack(const v_uint32x4& a, const v_uint32x4& b) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i b1 = _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(b.val, delta), n), delta32); + return v_uint16x8(_mm_sub_epi16(_mm_packs_epi32(a1, b1), _mm_set1_epi16(-32768))); +} + +template<int n> inline +void v_rshr_pack_store(ushort* ptr, const v_uint32x4& a) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + _mm_storel_epi64((__m128i*)ptr, a2); +} + +inline v_uint16x8 v_pack_u(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_uint16x8(_mm_packus_epi32(a.val, b.val)); +#else + __m128i delta32 = _mm_set1_epi32(32768); + + // preliminary saturate negative values to zero + __m128i a1 = _mm_and_si128(a.val, _mm_cmpgt_epi32(a.val, _mm_set1_epi32(0))); + __m128i b1 = _mm_and_si128(b.val, _mm_cmpgt_epi32(b.val, _mm_set1_epi32(0))); + + __m128i r = _mm_packs_epi32(_mm_sub_epi32(a1, delta32), _mm_sub_epi32(b1, delta32)); + return v_uint16x8(_mm_sub_epi16(r, _mm_set1_epi16(-32768))); +#endif +} + +inline void v_pack_u_store(ushort* ptr, const v_int32x4& a) +{ +#if CV_SSE4_1 + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi32(a.val, a.val)); +#else + __m128i delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(a.val, delta32); + __m128i r = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + _mm_storel_epi64((__m128i*)ptr, r); +#endif +} + +template<int n> inline +v_uint16x8 v_rshr_pack_u(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + __m128i delta = _mm_set1_epi32(1 << (n - 1)); + return v_uint16x8(_mm_packus_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), + _mm_srai_epi32(_mm_add_epi32(b.val, delta), n))); +#else + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + __m128i b1 = _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(b.val, delta), n), delta32); + __m128i b2 = _mm_sub_epi16(_mm_packs_epi32(b1, b1), _mm_set1_epi16(-32768)); + return v_uint16x8(_mm_unpacklo_epi64(a2, b2)); +#endif +} + +template<int n> inline +void v_rshr_pack_u_store(ushort* ptr, const v_int32x4& a) +{ +#if CV_SSE4_1 + __m128i delta = _mm_set1_epi32(1 << (n - 1)); + __m128i a1 = _mm_srai_epi32(_mm_add_epi32(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi32(a1, a1)); +#else + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + _mm_storel_epi64((__m128i*)ptr, a2); +#endif +} + +inline v_int16x8 v_pack(const v_int32x4& a, const v_int32x4& b) +{ return v_int16x8(_mm_packs_epi32(a.val, b.val)); } + +inline void v_pack_store(short* ptr, const v_int32x4& a) +{ + _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi32(a.val, a.val)); +} + +template<int n> inline +v_int16x8 v_rshr_pack(const v_int32x4& a, const v_int32x4& b) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)); + return v_int16x8(_mm_packs_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), + _mm_srai_epi32(_mm_add_epi32(b.val, delta), n))); +} + +template<int n> inline +void v_rshr_pack_store(short* ptr, const v_int32x4& a) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)); + __m128i a1 = _mm_srai_epi32(_mm_add_epi32(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi32(a1, a1)); +} + + +// [a0 0 | b0 0] [a1 0 | b1 0] +inline v_uint32x4 v_pack(const v_uint64x2& a, const v_uint64x2& b) +{ + __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); // b0 b1 0 0 + return v_uint32x4(_mm_unpacklo_epi32(v0, v1)); +} + +inline void v_pack_store(unsigned* ptr, const v_uint64x2& a) +{ + __m128i a1 = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a1); +} + +// [a0 0 | b0 0] [a1 0 | b1 0] +inline v_int32x4 v_pack(const v_int64x2& a, const v_int64x2& b) +{ + __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); // b0 b1 0 0 + return v_int32x4(_mm_unpacklo_epi32(v0, v1)); +} + +inline void v_pack_store(int* ptr, const v_int64x2& a) +{ + __m128i a1 = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a1); +} + +template<int n> inline +v_uint32x4 v_rshr_pack(const v_uint64x2& a, const v_uint64x2& b) +{ + uint64 delta = (uint64)1 << (n-1); + v_uint64x2 delta2(delta, delta); + __m128i a1 = _mm_srli_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i b1 = _mm_srli_epi64(_mm_add_epi64(b.val, delta2.val), n); + __m128i v0 = _mm_unpacklo_epi32(a1, b1); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a1, b1); // b0 b1 0 0 + return v_uint32x4(_mm_unpacklo_epi32(v0, v1)); +} + +template<int n> inline +void v_rshr_pack_store(unsigned* ptr, const v_uint64x2& a) +{ + uint64 delta = (uint64)1 << (n-1); + v_uint64x2 delta2(delta, delta); + __m128i a1 = _mm_srli_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i a2 = _mm_shuffle_epi32(a1, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a2); +} + +inline __m128i v_sign_epi64(__m128i a) +{ + return _mm_shuffle_epi32(_mm_srai_epi32(a, 31), _MM_SHUFFLE(3, 3, 1, 1)); // x m0 | x m1 +} + +inline __m128i v_srai_epi64(__m128i a, int imm) +{ + __m128i smask = v_sign_epi64(a); + return _mm_xor_si128(_mm_srli_epi64(_mm_xor_si128(a, smask), imm), smask); +} + +template<int n> inline +v_int32x4 v_rshr_pack(const v_int64x2& a, const v_int64x2& b) +{ + int64 delta = (int64)1 << (n-1); + v_int64x2 delta2(delta, delta); + __m128i a1 = v_srai_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i b1 = v_srai_epi64(_mm_add_epi64(b.val, delta2.val), n); + __m128i v0 = _mm_unpacklo_epi32(a1, b1); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a1, b1); // b0 b1 0 0 + return v_int32x4(_mm_unpacklo_epi32(v0, v1)); +} + +template<int n> inline +void v_rshr_pack_store(int* ptr, const v_int64x2& a) +{ + int64 delta = (int64)1 << (n-1); + v_int64x2 delta2(delta, delta); + __m128i a1 = v_srai_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i a2 = _mm_shuffle_epi32(a1, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a2); +} + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + __m128i ab = _mm_packs_epi16(a.val, b.val); + return v_uint8x16(ab); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + __m128i ab = _mm_packs_epi32(a.val, b.val); + __m128i cd = _mm_packs_epi32(c.val, d.val); + return v_uint8x16(_mm_packs_epi16(ab, cd)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + __m128i ab = _mm_packs_epi32(a.val, b.val); + __m128i cd = _mm_packs_epi32(c.val, d.val); + __m128i ef = _mm_packs_epi32(e.val, f.val); + __m128i gh = _mm_packs_epi32(g.val, h.val); + + __m128i abcd = _mm_packs_epi32(ab, cd); + __m128i efgh = _mm_packs_epi32(ef, gh); + return v_uint8x16(_mm_packs_epi16(abcd, efgh)); +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + __m128 v0 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val); + __m128 v1 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val); + __m128 v2 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val); + __m128 v3 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(3, 3, 3, 3)), m3.val); + + return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, v3))); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + __m128 v0 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val); + __m128 v1 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val); + __m128 v2 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val); + + return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, a.val))); +} + +#define OPENCV_HAL_IMPL_SSE_BIN_OP(bin_op, _Tpvec, intrin) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { \ + return _Tpvec(intrin(a.val, b.val)); \ + } \ + inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ + { \ + a.val = intrin(a.val, b.val); \ + return a; \ + } + +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint8x16, _mm_adds_epu8) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint8x16, _mm_subs_epu8) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int8x16, _mm_adds_epi8) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int8x16, _mm_subs_epi8) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint16x8, _mm_adds_epu16) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint16x8, _mm_subs_epu16) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int16x8, _mm_adds_epi16) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int16x8, _mm_subs_epi16) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint32x4, _mm_add_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint32x4, _mm_sub_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_uint32x4, _v128_mullo_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int32x4, _mm_add_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int32x4, _mm_sub_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_int32x4, _v128_mullo_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_float32x4, _mm_add_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_float32x4, _mm_sub_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_float32x4, _mm_mul_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(/, v_float32x4, _mm_div_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_float64x2, _mm_add_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_float64x2, _mm_sub_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_float64x2, _mm_mul_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(/, v_float64x2, _mm_div_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint64x2, _mm_add_epi64) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint64x2, _mm_sub_epi64) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int64x2, _mm_add_epi64) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int64x2, _mm_sub_epi64) + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_SSE_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_uint16x8, v_uint32x4) +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_int16x8, v_int32x4) + +// Multiply and expand +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + v_uint16x8 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + v_int16x8 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + __m128i v0 = _mm_mullo_epi16(a.val, b.val); + __m128i v1 = _mm_mulhi_epi16(a.val, b.val); + c.val = _mm_unpacklo_epi16(v0, v1); + d.val = _mm_unpackhi_epi16(v0, v1); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + __m128i v0 = _mm_mullo_epi16(a.val, b.val); + __m128i v1 = _mm_mulhi_epu16(a.val, b.val); + c.val = _mm_unpacklo_epi16(v0, v1); + d.val = _mm_unpackhi_epi16(v0, v1); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ + __m128i c0 = _mm_mul_epu32(a.val, b.val); + __m128i c1 = _mm_mul_epu32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32)); + c.val = _mm_unpacklo_epi64(c0, c1); + d.val = _mm_unpackhi_epi64(c0, c1); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) { return v_int16x8(_mm_mulhi_epi16(a.val, b.val)); } +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) { return v_uint16x8(_mm_mulhi_epu16(a.val, b.val)); } + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ + return v_int32x4(_mm_madd_epi16(a.val, b.val)); +} + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + return v_int32x4(_mm_add_epi32(_mm_madd_epi16(a.val, b.val), c.val)); +} + +#define OPENCV_HAL_IMPL_SSE_LOGIC_OP(_Tpvec, suffix, not_const) \ + OPENCV_HAL_IMPL_SSE_BIN_OP(&, _Tpvec, _mm_and_##suffix) \ + OPENCV_HAL_IMPL_SSE_BIN_OP(|, _Tpvec, _mm_or_##suffix) \ + OPENCV_HAL_IMPL_SSE_BIN_OP(^, _Tpvec, _mm_xor_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { \ + return _Tpvec(_mm_xor_##suffix(a.val, not_const)); \ + } + +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint8x16, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int8x16, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint16x8, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int16x8, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint32x4, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int32x4, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint64x2, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int64x2, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_float32x4, ps, _mm_castsi128_ps(_mm_set1_epi32(-1))) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_float64x2, pd, _mm_castsi128_pd(_mm_set1_epi32(-1))) + +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ return v_float32x4(_mm_sqrt_ps(x.val)); } + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + const __m128 _0_5 = _mm_set1_ps(0.5f), _1_5 = _mm_set1_ps(1.5f); + __m128 t = x.val; + __m128 h = _mm_mul_ps(t, _0_5); + t = _mm_rsqrt_ps(t); + t = _mm_mul_ps(t, _mm_sub_ps(_1_5, _mm_mul_ps(_mm_mul_ps(t, t), h))); + return v_float32x4(t); +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ return v_float64x2(_mm_sqrt_pd(x.val)); } + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + const __m128d v_1 = _mm_set1_pd(1.); + return v_float64x2(_mm_div_pd(v_1, _mm_sqrt_pd(x.val))); +} + +#define OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(_Tpuvec, _Tpsvec, func, suffix, subWidth) \ +inline _Tpuvec v_abs(const _Tpsvec& x) \ +{ return _Tpuvec(_mm_##func##_ep##suffix(x.val, _mm_sub_ep##subWidth(_mm_setzero_si128(), x.val))); } + +OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint8x16, v_int8x16, min, u8, i8) +OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint16x8, v_int16x8, max, i16, i16) +inline v_uint32x4 v_abs(const v_int32x4& x) +{ + __m128i s = _mm_srli_epi32(x.val, 31); + __m128i f = _mm_srai_epi32(x.val, 31); + return v_uint32x4(_mm_add_epi32(_mm_xor_si128(x.val, f), s)); +} +inline v_float32x4 v_abs(const v_float32x4& x) +{ return v_float32x4(_mm_and_ps(x.val, _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff)))); } +inline v_float64x2 v_abs(const v_float64x2& x) +{ + return v_float64x2(_mm_and_pd(x.val, + _mm_castsi128_pd(_mm_srli_epi64(_mm_set1_epi32(-1), 1)))); +} + +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_SSE_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_min, _mm_min_epu8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_max, _mm_max_epu8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_min, _mm_min_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_max, _mm_max_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float32x4, v_min, _mm_min_ps) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float32x4, v_max, _mm_max_ps) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float64x2, v_min, _mm_min_pd) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float64x2, v_max, _mm_max_pd) + +inline v_int8x16 v_min(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_SSE4_1 + return v_int8x16(_mm_min_epi8(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi8((char)-128); + return v_int8x16(_mm_xor_si128(delta, _mm_min_epu8(_mm_xor_si128(a.val, delta), + _mm_xor_si128(b.val, delta)))); +#endif +} +inline v_int8x16 v_max(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_SSE4_1 + return v_int8x16(_mm_max_epi8(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi8((char)-128); + return v_int8x16(_mm_xor_si128(delta, _mm_max_epu8(_mm_xor_si128(a.val, delta), + _mm_xor_si128(b.val, delta)))); +#endif +} +inline v_uint16x8 v_min(const v_uint16x8& a, const v_uint16x8& b) +{ +#if CV_SSE4_1 + return v_uint16x8(_mm_min_epu16(a.val, b.val)); +#else + return v_uint16x8(_mm_subs_epu16(a.val, _mm_subs_epu16(a.val, b.val))); +#endif +} +inline v_uint16x8 v_max(const v_uint16x8& a, const v_uint16x8& b) +{ +#if CV_SSE4_1 + return v_uint16x8(_mm_max_epu16(a.val, b.val)); +#else + return v_uint16x8(_mm_adds_epu16(_mm_subs_epu16(a.val, b.val), b.val)); +#endif +} +inline v_uint32x4 v_min(const v_uint32x4& a, const v_uint32x4& b) +{ +#if CV_SSE4_1 + return v_uint32x4(_mm_min_epu32(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi32((int)0x80000000); + __m128i mask = _mm_cmpgt_epi32(_mm_xor_si128(a.val, delta), _mm_xor_si128(b.val, delta)); + return v_uint32x4(v_select_si128(mask, b.val, a.val)); +#endif +} +inline v_uint32x4 v_max(const v_uint32x4& a, const v_uint32x4& b) +{ +#if CV_SSE4_1 + return v_uint32x4(_mm_max_epu32(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi32((int)0x80000000); + __m128i mask = _mm_cmpgt_epi32(_mm_xor_si128(a.val, delta), _mm_xor_si128(b.val, delta)); + return v_uint32x4(v_select_si128(mask, a.val, b.val)); +#endif +} +inline v_int32x4 v_min(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_int32x4(_mm_min_epi32(a.val, b.val)); +#else + return v_int32x4(v_select_si128(_mm_cmpgt_epi32(a.val, b.val), b.val, a.val)); +#endif +} +inline v_int32x4 v_max(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_int32x4(_mm_max_epi32(a.val, b.val)); +#else + return v_int32x4(v_select_si128(_mm_cmpgt_epi32(a.val, b.val), a.val, b.val)); +#endif +} + +#define OPENCV_HAL_IMPL_SSE_INT_CMP_OP(_Tpuvec, _Tpsvec, suffix, sbit) \ +inline _Tpuvec operator == (const _Tpuvec& a, const _Tpuvec& b) \ +{ return _Tpuvec(_mm_cmpeq_##suffix(a.val, b.val)); } \ +inline _Tpuvec operator != (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpuvec(_mm_xor_si128(_mm_cmpeq_##suffix(a.val, b.val), not_mask)); \ +} \ +inline _Tpsvec operator == (const _Tpsvec& a, const _Tpsvec& b) \ +{ return _Tpsvec(_mm_cmpeq_##suffix(a.val, b.val)); } \ +inline _Tpsvec operator != (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpsvec(_mm_xor_si128(_mm_cmpeq_##suffix(a.val, b.val), not_mask)); \ +} \ +inline _Tpuvec operator < (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + return _Tpuvec(_mm_cmpgt_##suffix(_mm_xor_si128(b.val, smask), _mm_xor_si128(a.val, smask))); \ +} \ +inline _Tpuvec operator > (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + return _Tpuvec(_mm_cmpgt_##suffix(_mm_xor_si128(a.val, smask), _mm_xor_si128(b.val, smask))); \ +} \ +inline _Tpuvec operator <= (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + __m128i not_mask = _mm_set1_epi32(-1); \ + __m128i res = _mm_cmpgt_##suffix(_mm_xor_si128(a.val, smask), _mm_xor_si128(b.val, smask)); \ + return _Tpuvec(_mm_xor_si128(res, not_mask)); \ +} \ +inline _Tpuvec operator >= (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + __m128i not_mask = _mm_set1_epi32(-1); \ + __m128i res = _mm_cmpgt_##suffix(_mm_xor_si128(b.val, smask), _mm_xor_si128(a.val, smask)); \ + return _Tpuvec(_mm_xor_si128(res, not_mask)); \ +} \ +inline _Tpsvec operator < (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + return _Tpsvec(_mm_cmpgt_##suffix(b.val, a.val)); \ +} \ +inline _Tpsvec operator > (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + return _Tpsvec(_mm_cmpgt_##suffix(a.val, b.val)); \ +} \ +inline _Tpsvec operator <= (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpsvec(_mm_xor_si128(_mm_cmpgt_##suffix(a.val, b.val), not_mask)); \ +} \ +inline _Tpsvec operator >= (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpsvec(_mm_xor_si128(_mm_cmpgt_##suffix(b.val, a.val), not_mask)); \ +} + +OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint8x16, v_int8x16, epi8, (char)-128) +OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint16x8, v_int16x8, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint32x4, v_int32x4, epi32, (int)0x80000000) + +#define OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(_Tpvec, suffix) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpeq_##suffix(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpneq_##suffix(a.val, b.val)); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmplt_##suffix(a.val, b.val)); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpgt_##suffix(a.val, b.val)); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmple_##suffix(a.val, b.val)); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpge_##suffix(a.val, b.val)); } + +OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float32x4, ps) +OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float64x2, pd) + +#define OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(_Tpvec, cast) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return cast(v_reinterpret_as_f64(a) == v_reinterpret_as_f64(b)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return cast(v_reinterpret_as_f64(a) != v_reinterpret_as_f64(b)); } + +OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_uint64x2, v_reinterpret_as_u64) +OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_int64x2, v_reinterpret_as_s64) + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(_mm_cmpord_ps(a.val, a.val)); } +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(_mm_cmpord_pd(a.val, a.val)); } + +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_add_wrap, _mm_add_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_add_wrap, _mm_add_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_add_wrap, _mm_add_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_add_wrap, _mm_add_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_sub_wrap, _mm_sub_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_sub_wrap, _mm_sub_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_sub_wrap, _mm_sub_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_sub_wrap, _mm_sub_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_mul_wrap, _mm_mullo_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_mul_wrap, _mm_mullo_epi16) + +inline v_uint8x16 v_mul_wrap(const v_uint8x16& a, const v_uint8x16& b) +{ + __m128i ad = _mm_srai_epi16(a.val, 8); + __m128i bd = _mm_srai_epi16(b.val, 8); + __m128i p0 = _mm_mullo_epi16(a.val, b.val); // even + __m128i p1 = _mm_slli_epi16(_mm_mullo_epi16(ad, bd), 8); // odd + const __m128i b01 = _mm_set1_epi32(0xFF00FF00); + return v_uint8x16(_v128_blendv_epi8(p0, p1, b01)); +} +inline v_int8x16 v_mul_wrap(const v_int8x16& a, const v_int8x16& b) +{ + return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b))); +} + +/** Absolute difference **/ + +inline v_uint8x16 v_absdiff(const v_uint8x16& a, const v_uint8x16& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint16x8 v_absdiff(const v_uint16x8& a, const v_uint16x8& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint32x4 v_absdiff(const v_uint32x4& a, const v_uint32x4& b) +{ return v_max(a, b) - v_min(a, b); } + +inline v_uint8x16 v_absdiff(const v_int8x16& a, const v_int8x16& b) +{ + v_int8x16 d = v_sub_wrap(a, b); + v_int8x16 m = a < b; + return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m)); +} +inline v_uint16x8 v_absdiff(const v_int16x8& a, const v_int16x8& b) +{ + return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); +} +inline v_uint32x4 v_absdiff(const v_int32x4& a, const v_int32x4& b) +{ + v_int32x4 d = a - b; + v_int32x4 m = a < b; + return v_reinterpret_as_u32((d ^ m) - m); +} + +/** Saturating absolute difference **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ + v_int8x16 d = a - b; + v_int8x16 m = a < b; + return (d ^ m) - m; + } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_max(a, b) - v_min(a, b); } + + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return a * b + c; +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ +#if CV_FMA3 + return v_float32x4(_mm_fmadd_ps(a.val, b.val, c.val)); +#else + return v_float32x4(_mm_add_ps(_mm_mul_ps(a.val, b.val), c.val)); +#endif +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ +#if CV_FMA3 + return v_float64x2(_mm_fmadd_pd(a.val, b.val, c.val)); +#else + return v_float64x2(_mm_add_pd(_mm_mul_pd(a.val, b.val), c.val)); +#endif +} + +#define OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(_Tpvec, _Tp, _Tpreg, suffix, absmask_vec) \ +inline _Tpvec v_absdiff(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpreg absmask = _mm_castsi128_##suffix(absmask_vec); \ + return _Tpvec(_mm_and_##suffix(_mm_sub_##suffix(a.val, b.val), absmask)); \ +} \ +inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpvec res = v_fma(a, a, b*b); \ + return _Tpvec(_mm_sqrt_##suffix(res.val)); \ +} \ +inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return v_fma(a, a, b*b); \ +} \ +inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ \ + return v_fma(a, b, c); \ +} + +OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(v_float32x4, float, __m128, ps, _mm_set1_epi32((int)0x7fffffff)) +OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(v_float64x2, double, __m128d, pd, _mm_srli_epi64(_mm_set1_epi32(-1), 1)) + +#define OPENCV_HAL_IMPL_SSE_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, srai) \ +inline _Tpuvec operator << (const _Tpuvec& a, int imm) \ +{ \ + return _Tpuvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +inline _Tpsvec operator << (const _Tpsvec& a, int imm) \ +{ \ + return _Tpsvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \ +{ \ + return _Tpuvec(_mm_srli_##suffix(a.val, imm)); \ +} \ +inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \ +{ \ + return _Tpsvec(srai(a.val, imm)); \ +} \ +template<int imm> \ +inline _Tpuvec v_shl(const _Tpuvec& a) \ +{ \ + return _Tpuvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +template<int imm> \ +inline _Tpsvec v_shl(const _Tpsvec& a) \ +{ \ + return _Tpsvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +template<int imm> \ +inline _Tpuvec v_shr(const _Tpuvec& a) \ +{ \ + return _Tpuvec(_mm_srli_##suffix(a.val, imm)); \ +} \ +template<int imm> \ +inline _Tpsvec v_shr(const _Tpsvec& a) \ +{ \ + return _Tpsvec(srai(a.val, imm)); \ +} + +OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16) +OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32) +OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64) + +namespace hal_sse_internal +{ + template <int imm, + bool is_invalid = ((imm < 0) || (imm > 16)), + bool is_first = (imm == 0), + bool is_half = (imm == 8), + bool is_second = (imm == 16), + bool is_other = (((imm > 0) && (imm < 8)) || ((imm > 8) && (imm < 16)))> + class v_sse_palignr_u8_class; + + template <int imm> + class v_sse_palignr_u8_class<imm, true, false, false, false, false>; + + template <int imm> + class v_sse_palignr_u8_class<imm, false, true, false, false, false> + { + public: + inline __m128i operator()(const __m128i& a, const __m128i&) const + { + return a; + } + }; + + template <int imm> + class v_sse_palignr_u8_class<imm, false, false, true, false, false> + { + public: + inline __m128i operator()(const __m128i& a, const __m128i& b) const + { + return _mm_unpacklo_epi64(_mm_unpackhi_epi64(a, a), b); + } + }; + + template <int imm> + class v_sse_palignr_u8_class<imm, false, false, false, true, false> + { + public: + inline __m128i operator()(const __m128i&, const __m128i& b) const + { + return b; + } + }; + + template <int imm> + class v_sse_palignr_u8_class<imm, false, false, false, false, true> + { +#if CV_SSSE3 + public: + inline __m128i operator()(const __m128i& a, const __m128i& b) const + { + return _mm_alignr_epi8(b, a, imm); + } +#else + public: + inline __m128i operator()(const __m128i& a, const __m128i& b) const + { + enum { imm2 = (sizeof(__m128i) - imm) }; + return _mm_or_si128(_mm_srli_si128(a, imm), _mm_slli_si128(b, imm2)); + } +#endif + }; + + template <int imm> + inline __m128i v_sse_palignr_u8(const __m128i& a, const __m128i& b) + { + CV_StaticAssert((imm >= 0) && (imm <= 16), "Invalid imm for v_sse_palignr_u8."); + return v_sse_palignr_u8_class<imm>()(a, b); + } +} + +template<int imm, typename _Tpvec> +inline _Tpvec v_rotate_right(const _Tpvec &a) +{ + using namespace hal_sse_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>( + _mm_srli_si128( + v_sse_reinterpret_as<__m128i>(a.val), imm2))); +} + +template<int imm, typename _Tpvec> +inline _Tpvec v_rotate_left(const _Tpvec &a) +{ + using namespace hal_sse_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>( + _mm_slli_si128( + v_sse_reinterpret_as<__m128i>(a.val), imm2))); +} + +template<int imm, typename _Tpvec> +inline _Tpvec v_rotate_right(const _Tpvec &a, const _Tpvec &b) +{ + using namespace hal_sse_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>( + v_sse_palignr_u8<imm2>( + v_sse_reinterpret_as<__m128i>(a.val), + v_sse_reinterpret_as<__m128i>(b.val)))); +} + +template<int imm, typename _Tpvec> +inline _Tpvec v_rotate_left(const _Tpvec &a, const _Tpvec &b) +{ + using namespace hal_sse_internal; + enum { imm2 = ((_Tpvec::nlanes - imm) * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as<typename _Tpvec::vector_type>( + v_sse_palignr_u8<imm2>( + v_sse_reinterpret_as<__m128i>(b.val), + v_sse_reinterpret_as<__m128i>(a.val)))); +} + +#define OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(_Tpvec, _Tp) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadu_si128((const __m128i*)ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(_mm_load_si128((const __m128i*)ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadl_epi64((const __m128i*)ptr)); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ \ + return _Tpvec(_mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i*)ptr0), \ + _mm_loadl_epi64((const __m128i*)ptr1))); \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storeu_si128((__m128i*)ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ _mm_store_si128((__m128i*)ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ _mm_stream_si128((__m128i*)ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ +{ \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm_storeu_si128((__m128i*)ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm_stream_si128((__m128i*)ptr, a.val); \ + else \ + _mm_store_si128((__m128i*)ptr, a.val); \ +} \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storel_epi64((__m128i*)ptr, a.val); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storel_epi64((__m128i*)ptr, _mm_unpackhi_epi64(a.val, a.val)); } + +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint8x16, uchar) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int8x16, schar) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint16x8, ushort) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int16x8, short) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int32x4, int) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint64x2, uint64) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int64x2, int64) + +#define OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadu_##suffix(ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(_mm_load_##suffix(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(_mm_castsi128_##suffix(_mm_loadl_epi64((const __m128i*)ptr))); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ \ + return _Tpvec(_mm_castsi128_##suffix( \ + _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i*)ptr0), \ + _mm_loadl_epi64((const __m128i*)ptr1)))); \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storeu_##suffix(ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ _mm_store_##suffix(ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ _mm_stream_##suffix(ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ +{ \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm_storeu_##suffix(ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm_stream_##suffix(ptr, a.val); \ + else \ + _mm_store_##suffix(ptr, a.val); \ +} \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storel_epi64((__m128i*)ptr, _mm_cast##suffix##_si128(a.val)); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ \ + __m128i a1 = _mm_cast##suffix##_si128(a.val); \ + _mm_storel_epi64((__m128i*)ptr, _mm_unpackhi_epi64(a1, a1)); \ +} + +OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float32x4, float, ps) +OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float64x2, double, pd) + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(_Tpvec, scalartype, func, suffix, sbit) \ +inline scalartype v_reduce_##func(const v_##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \ + return (scalartype)_mm_cvtsi128_si32(val); \ +} \ +inline unsigned scalartype v_reduce_##func(const v_u##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + __m128i smask = _mm_set1_epi16(sbit); \ + val = _mm_xor_si128(val, smask); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \ + return (unsigned scalartype)(_mm_cvtsi128_si32(val) ^ sbit); \ +} +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8_SUM(_Tpvec, scalartype, suffix) \ +inline scalartype v_reduce_sum(const v_##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 8)); \ + val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 4)); \ + val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 2)); \ + return (scalartype)_mm_cvtsi128_si32(val); \ +} \ +inline unsigned scalartype v_reduce_sum(const v_u##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 8)); \ + val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 4)); \ + val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 2)); \ + return (unsigned scalartype)_mm_cvtsi128_si32(val); \ +} +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, max, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, min, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8_SUM(int16x8, short, 16) + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(_Tpvec, scalartype, regtype, suffix, cast_from, cast_to, extract) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + regtype val = a.val; \ + val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 8))); \ + val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 4))); \ + return (scalartype)_mm_cvt##extract(val); \ +} + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + scalartype CV_DECL_ALIGNED(16) buf[4]; \ + v_store_aligned(buf, a); \ + scalartype s0 = scalar_func(buf[0], buf[1]); \ + scalartype s1 = scalar_func(buf[2], buf[3]); \ + return scalar_func(s0, s1); \ +} + +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_uint32x4, unsigned, __m128i, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_int32x4, int, __m128i, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_float32x4, float, __m128, ps, _mm_castps_si128, _mm_castsi128_ps, ss_f32) + +inline double v_reduce_sum(const v_float64x2& a) +{ + double CV_DECL_ALIGNED(32) idx[2]; + v_store_aligned(idx, a); + return idx[0] + idx[1]; +} + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ +#if CV_SSE3 + __m128 ab = _mm_hadd_ps(a.val, b.val); + __m128 cd = _mm_hadd_ps(c.val, d.val); + return v_float32x4(_mm_hadd_ps(ab, cd)); +#else + __m128 ac = _mm_add_ps(_mm_unpacklo_ps(a.val, c.val), _mm_unpackhi_ps(a.val, c.val)); + __m128 bd = _mm_add_ps(_mm_unpacklo_ps(b.val, d.val), _mm_unpackhi_ps(b.val, d.val)); + return v_float32x4(_mm_add_ps(_mm_unpacklo_ps(ac, bd), _mm_unpackhi_ps(ac, bd))); +#endif +} + +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, max, std::max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, min, std::min) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, max, std::max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, min, std::min) + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + return (unsigned)_mm_cvtsi128_si32(_mm_sad_epu8(a.val, b.val)); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + __m128i half = _mm_set1_epi8(0x7f); + return (unsigned)_mm_cvtsi128_si32(_mm_sad_epu8(_mm_add_epi8(a.val, half), + _mm_add_epi8(b.val, half))); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint32x4 l, h; + v_expand(v_absdiff(a, b), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + v_uint32x4 l, h; + v_expand(v_absdiff(a, b), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} + +#define OPENCV_HAL_IMPL_SSE_POPCOUNT(_Tpvec) \ +inline v_uint32x4 v_popcount(const _Tpvec& a) \ +{ \ + __m128i m1 = _mm_set1_epi32(0x55555555); \ + __m128i m2 = _mm_set1_epi32(0x33333333); \ + __m128i m4 = _mm_set1_epi32(0x0f0f0f0f); \ + __m128i p = a.val; \ + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 1), m1), _mm_and_si128(p, m1)); \ + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 2), m2), _mm_and_si128(p, m2)); \ + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 4), m4), _mm_and_si128(p, m4)); \ + p = _mm_adds_epi8(p, _mm_srli_si128(p, 1)); \ + p = _mm_adds_epi8(p, _mm_srli_si128(p, 2)); \ + return v_uint32x4(_mm_and_si128(p, _mm_set1_epi32(0x000000ff))); \ +} + +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_uint8x16) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_uint16x8) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_uint32x4) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_int8x16) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_int16x8) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_int32x4) + +#define OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(_Tpvec, suffix, pack_op, and_op, signmask, allmask) \ +inline int v_signmask(const _Tpvec& a) \ +{ \ + return and_op(_mm_movemask_##suffix(pack_op(a.val)), signmask); \ +} \ +inline bool v_check_all(const _Tpvec& a) \ +{ return and_op(_mm_movemask_##suffix(a.val), allmask) == allmask; } \ +inline bool v_check_any(const _Tpvec& a) \ +{ return and_op(_mm_movemask_##suffix(a.val), allmask) != 0; } + +#define OPENCV_HAL_PACKS(a) _mm_packs_epi16(a, a) +inline __m128i v_packq_epi32(__m128i a) +{ + __m128i b = _mm_packs_epi32(a, a); + return _mm_packs_epi16(b, b); +} + +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_1ST, 65535, 65535) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_1ST, 65535, 65535) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint16x8, epi8, OPENCV_HAL_PACKS, OPENCV_HAL_AND, 255, (int)0xaaaa) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int16x8, epi8, OPENCV_HAL_PACKS, OPENCV_HAL_AND, 255, (int)0xaaaa) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint32x4, epi8, v_packq_epi32, OPENCV_HAL_AND, 15, (int)0x8888) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int32x4, epi8, v_packq_epi32, OPENCV_HAL_AND, 15, (int)0x8888) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_float32x4, ps, OPENCV_HAL_NOP, OPENCV_HAL_1ST, 15, 15) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_float64x2, pd, OPENCV_HAL_NOP, OPENCV_HAL_1ST, 3, 3) + +#if CV_SSE4_1 +#define OPENCV_HAL_IMPL_SSE_SELECT(_Tpvec, cast_ret, cast, suffix) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(cast_ret(_mm_blendv_##suffix(cast(b.val), cast(a.val), cast(mask.val)))); \ +} + +OPENCV_HAL_IMPL_SSE_SELECT(v_uint8x16, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_int8x16, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint16x8, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_int16x8, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint32x4, _mm_castps_si128, _mm_castsi128_ps, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_int32x4, _mm_castps_si128, _mm_castsi128_ps, ps) +// OPENCV_HAL_IMPL_SSE_SELECT(v_uint64x2, TBD, TBD, pd) +// OPENCV_HAL_IMPL_SSE_SELECT(v_int64x2, TBD, TBD, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_float32x4, OPENCV_HAL_NOP, OPENCV_HAL_NOP, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_float64x2, OPENCV_HAL_NOP, OPENCV_HAL_NOP, pd) + +#else // CV_SSE4_1 + +#define OPENCV_HAL_IMPL_SSE_SELECT(_Tpvec, suffix) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(_mm_xor_##suffix(b.val, _mm_and_##suffix(_mm_xor_##suffix(b.val, a.val), mask.val))); \ +} + +OPENCV_HAL_IMPL_SSE_SELECT(v_uint8x16, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_int8x16, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint16x8, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_int16x8, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint32x4, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_int32x4, si128) +// OPENCV_HAL_IMPL_SSE_SELECT(v_uint64x2, si128) +// OPENCV_HAL_IMPL_SSE_SELECT(v_int64x2, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_float32x4, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_float64x2, pd) +#endif + +/* Expand */ +#define OPENCV_HAL_IMPL_SSE_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \ + inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ + { \ + b0.val = intrin(a.val); \ + b1.val = __CV_CAT(intrin, _high)(a.val); \ + } \ + inline _Tpwvec v_expand_low(const _Tpvec& a) \ + { return _Tpwvec(intrin(a.val)); } \ + inline _Tpwvec v_expand_high(const _Tpvec& a) \ + { return _Tpwvec(__CV_CAT(intrin, _high)(a.val)); } \ + inline _Tpwvec v_load_expand(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadl_epi64((const __m128i*)ptr); \ + return _Tpwvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_SSE_EXPAND(v_uint8x16, v_uint16x8, uchar, _v128_cvtepu8_epi16) +OPENCV_HAL_IMPL_SSE_EXPAND(v_int8x16, v_int16x8, schar, _v128_cvtepi8_epi16) +OPENCV_HAL_IMPL_SSE_EXPAND(v_uint16x8, v_uint32x4, ushort, _v128_cvtepu16_epi32) +OPENCV_HAL_IMPL_SSE_EXPAND(v_int16x8, v_int32x4, short, _v128_cvtepi16_epi32) +OPENCV_HAL_IMPL_SSE_EXPAND(v_uint32x4, v_uint64x2, unsigned, _v128_cvtepu32_epi64) +OPENCV_HAL_IMPL_SSE_EXPAND(v_int32x4, v_int64x2, int, _v128_cvtepi32_epi64) + +#define OPENCV_HAL_IMPL_SSE_EXPAND_Q(_Tpvec, _Tp, intrin) \ + inline _Tpvec v_load_expand_q(const _Tp* ptr) \ + { \ + __m128i a = _mm_cvtsi32_si128(*(const int*)ptr); \ + return _Tpvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_uint32x4, uchar, _v128_cvtepu8_epi32) +OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_int32x4, schar, _v128_cvtepi8_epi32) + +#define OPENCV_HAL_IMPL_SSE_UNPACKS(_Tpvec, suffix, cast_from, cast_to) \ +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) \ +{ \ + b0.val = _mm_unpacklo_##suffix(a0.val, a1.val); \ + b1.val = _mm_unpackhi_##suffix(a0.val, a1.val); \ +} \ +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ +{ \ + __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \ + return _Tpvec(cast_to(_mm_unpacklo_epi64(a1, b1))); \ +} \ +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ +{ \ + __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \ + return _Tpvec(cast_to(_mm_unpackhi_epi64(a1, b1))); \ +} \ +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) \ +{ \ + __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \ + c.val = cast_to(_mm_unpacklo_epi64(a1, b1)); \ + d.val = cast_to(_mm_unpackhi_epi64(a1, b1)); \ +} + +OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_int8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint16x8, epi16, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_int16x8, epi16, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_int32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_float32x4, ps, _mm_castps_si128, _mm_castsi128_ps) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_float64x2, pd, _mm_castpd_si128, _mm_castsi128_pd) + +template<int s, typename _Tpvec> +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) +{ + return v_rotate_right<s>(a, b); +} + +inline v_int32x4 v_round(const v_float32x4& a) +{ return v_int32x4(_mm_cvtps_epi32(a.val)); } + +inline v_int32x4 v_floor(const v_float32x4& a) +{ + __m128i a1 = _mm_cvtps_epi32(a.val); + __m128i mask = _mm_castps_si128(_mm_cmpgt_ps(_mm_cvtepi32_ps(a1), a.val)); + return v_int32x4(_mm_add_epi32(a1, mask)); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + __m128i a1 = _mm_cvtps_epi32(a.val); + __m128i mask = _mm_castps_si128(_mm_cmpgt_ps(a.val, _mm_cvtepi32_ps(a1))); + return v_int32x4(_mm_sub_epi32(a1, mask)); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(_mm_cvttps_epi32(a.val)); } + +inline v_int32x4 v_round(const v_float64x2& a) +{ return v_int32x4(_mm_cvtpd_epi32(a.val)); } + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + __m128i ai = _mm_cvtpd_epi32(a.val), bi = _mm_cvtpd_epi32(b.val); + return v_int32x4(_mm_unpacklo_epi64(ai, bi)); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + __m128i a1 = _mm_cvtpd_epi32(a.val); + __m128i mask = _mm_castpd_si128(_mm_cmpgt_pd(_mm_cvtepi32_pd(a1), a.val)); + mask = _mm_srli_si128(_mm_slli_si128(mask, 4), 8); // m0 m0 m1 m1 => m0 m1 0 0 + return v_int32x4(_mm_add_epi32(a1, mask)); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + __m128i a1 = _mm_cvtpd_epi32(a.val); + __m128i mask = _mm_castpd_si128(_mm_cmpgt_pd(a.val, _mm_cvtepi32_pd(a1))); + mask = _mm_srli_si128(_mm_slli_si128(mask, 4), 8); // m0 m0 m1 m1 => m0 m1 0 0 + return v_int32x4(_mm_sub_epi32(a1, mask)); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ return v_int32x4(_mm_cvttpd_epi32(a.val)); } + +#define OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, \ + _Tpvec& b2, _Tpvec& b3) \ +{ \ + __m128i t0 = cast_from(_mm_unpacklo_##suffix(a0.val, a1.val)); \ + __m128i t1 = cast_from(_mm_unpacklo_##suffix(a2.val, a3.val)); \ + __m128i t2 = cast_from(_mm_unpackhi_##suffix(a0.val, a1.val)); \ + __m128i t3 = cast_from(_mm_unpackhi_##suffix(a2.val, a3.val)); \ +\ + b0.val = cast_to(_mm_unpacklo_epi64(t0, t1)); \ + b1.val = cast_to(_mm_unpackhi_epi64(t0, t1)); \ + b2.val = cast_to(_mm_unpacklo_epi64(t2, t3)); \ + b3.val = cast_to(_mm_unpackhi_epi64(t2, t3)); \ +} + +OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_uint32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_int32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_float32x4, ps, _mm_castps_si128, _mm_castsi128_ps) + +// load deinterleave +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b) +{ + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + + __m128i t10 = _mm_unpacklo_epi8(t00, t01); + __m128i t11 = _mm_unpackhi_epi8(t00, t01); + + __m128i t20 = _mm_unpacklo_epi8(t10, t11); + __m128i t21 = _mm_unpackhi_epi8(t10, t11); + + __m128i t30 = _mm_unpacklo_epi8(t20, t21); + __m128i t31 = _mm_unpackhi_epi8(t20, t21); + + a.val = _mm_unpacklo_epi8(t30, t31); + b.val = _mm_unpackhi_epi8(t30, t31); +} + +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c) +{ +#if CV_SSE4_1 + const __m128i m0 = _mm_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0); + const __m128i m1 = _mm_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + __m128i s0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i s1 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + __m128i s2 = _mm_loadu_si128((const __m128i*)(ptr + 32)); + __m128i a0 = _mm_blendv_epi8(_mm_blendv_epi8(s0, s1, m0), s2, m1); + __m128i b0 = _mm_blendv_epi8(_mm_blendv_epi8(s1, s2, m0), s0, m1); + __m128i c0 = _mm_blendv_epi8(_mm_blendv_epi8(s2, s0, m0), s1, m1); + const __m128i sh_b = _mm_setr_epi8(0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13); + const __m128i sh_g = _mm_setr_epi8(1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14); + const __m128i sh_r = _mm_setr_epi8(2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15); + a0 = _mm_shuffle_epi8(a0, sh_b); + b0 = _mm_shuffle_epi8(b0, sh_g); + c0 = _mm_shuffle_epi8(c0, sh_r); + a.val = a0; + b.val = b0; + c.val = c0; +#elif CV_SSSE3 + const __m128i m0 = _mm_setr_epi8(0, 3, 6, 9, 12, 15, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14); + const __m128i m1 = _mm_alignr_epi8(m0, m0, 11); + const __m128i m2 = _mm_alignr_epi8(m0, m0, 6); + + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 32)); + + __m128i s0 = _mm_shuffle_epi8(t0, m0); + __m128i s1 = _mm_shuffle_epi8(t1, m1); + __m128i s2 = _mm_shuffle_epi8(t2, m2); + + t0 = _mm_alignr_epi8(s1, _mm_slli_si128(s0, 10), 5); + a.val = _mm_alignr_epi8(s2, t0, 5); + + t1 = _mm_alignr_epi8(_mm_srli_si128(s1, 5), _mm_slli_si128(s0, 5), 6); + b.val = _mm_alignr_epi8(_mm_srli_si128(s2, 5), t1, 5); + + t2 = _mm_alignr_epi8(_mm_srli_si128(s2, 10), s1, 11); + c.val = _mm_alignr_epi8(t2, s0, 11); +#else + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + __m128i t02 = _mm_loadu_si128((const __m128i*)(ptr + 32)); + + __m128i t10 = _mm_unpacklo_epi8(t00, _mm_unpackhi_epi64(t01, t01)); + __m128i t11 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t00, t00), t02); + __m128i t12 = _mm_unpacklo_epi8(t01, _mm_unpackhi_epi64(t02, t02)); + + __m128i t20 = _mm_unpacklo_epi8(t10, _mm_unpackhi_epi64(t11, t11)); + __m128i t21 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t10, t10), t12); + __m128i t22 = _mm_unpacklo_epi8(t11, _mm_unpackhi_epi64(t12, t12)); + + __m128i t30 = _mm_unpacklo_epi8(t20, _mm_unpackhi_epi64(t21, t21)); + __m128i t31 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t20, t20), t22); + __m128i t32 = _mm_unpacklo_epi8(t21, _mm_unpackhi_epi64(t22, t22)); + + a.val = _mm_unpacklo_epi8(t30, _mm_unpackhi_epi64(t31, t31)); + b.val = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t30, t30), t32); + c.val = _mm_unpacklo_epi8(t31, _mm_unpackhi_epi64(t32, t32)); +#endif +} + +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c, v_uint8x16& d) +{ + __m128i u0 = _mm_loadu_si128((const __m128i*)ptr); // a0 b0 c0 d0 a1 b1 c1 d1 ... + __m128i u1 = _mm_loadu_si128((const __m128i*)(ptr + 16)); // a4 b4 c4 d4 ... + __m128i u2 = _mm_loadu_si128((const __m128i*)(ptr + 32)); // a8 b8 c8 d8 ... + __m128i u3 = _mm_loadu_si128((const __m128i*)(ptr + 48)); // a12 b12 c12 d12 ... + + __m128i v0 = _mm_unpacklo_epi8(u0, u2); // a0 a8 b0 b8 ... + __m128i v1 = _mm_unpackhi_epi8(u0, u2); // a2 a10 b2 b10 ... + __m128i v2 = _mm_unpacklo_epi8(u1, u3); // a4 a12 b4 b12 ... + __m128i v3 = _mm_unpackhi_epi8(u1, u3); // a6 a14 b6 b14 ... + + u0 = _mm_unpacklo_epi8(v0, v2); // a0 a4 a8 a12 ... + u1 = _mm_unpacklo_epi8(v1, v3); // a2 a6 a10 a14 ... + u2 = _mm_unpackhi_epi8(v0, v2); // a1 a5 a9 a13 ... + u3 = _mm_unpackhi_epi8(v1, v3); // a3 a7 a11 a15 ... + + v0 = _mm_unpacklo_epi8(u0, u1); // a0 a2 a4 a6 ... + v1 = _mm_unpacklo_epi8(u2, u3); // a1 a3 a5 a7 ... + v2 = _mm_unpackhi_epi8(u0, u1); // c0 c2 c4 c6 ... + v3 = _mm_unpackhi_epi8(u2, u3); // c1 c3 c5 c7 ... + + a.val = _mm_unpacklo_epi8(v0, v1); + b.val = _mm_unpackhi_epi8(v0, v1); + c.val = _mm_unpacklo_epi8(v2, v3); + d.val = _mm_unpackhi_epi8(v2, v3); +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b) +{ + __m128i v0 = _mm_loadu_si128((__m128i*)(ptr)); // a0 b0 a1 b1 a2 b2 a3 b3 + __m128i v1 = _mm_loadu_si128((__m128i*)(ptr + 8)); // a4 b4 a5 b5 a6 b6 a7 b7 + + __m128i v2 = _mm_unpacklo_epi16(v0, v1); // a0 a4 b0 b4 a1 a5 b1 b5 + __m128i v3 = _mm_unpackhi_epi16(v0, v1); // a2 a6 b2 b6 a3 a7 b3 b7 + __m128i v4 = _mm_unpacklo_epi16(v2, v3); // a0 a2 a4 a6 b0 b2 b4 b6 + __m128i v5 = _mm_unpackhi_epi16(v2, v3); // a1 a3 a5 a7 b1 b3 b5 b7 + + a.val = _mm_unpacklo_epi16(v4, v5); // a0 a1 a2 a3 a4 a5 a6 a7 + b.val = _mm_unpackhi_epi16(v4, v5); // b0 b1 ab b3 b4 b5 b6 b7 +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c) +{ +#if CV_SSE4_1 + __m128i v0 = _mm_loadu_si128((__m128i*)(ptr)); + __m128i v1 = _mm_loadu_si128((__m128i*)(ptr + 8)); + __m128i v2 = _mm_loadu_si128((__m128i*)(ptr + 16)); + __m128i a0 = _mm_blend_epi16(_mm_blend_epi16(v0, v1, 0x92), v2, 0x24); + __m128i b0 = _mm_blend_epi16(_mm_blend_epi16(v2, v0, 0x92), v1, 0x24); + __m128i c0 = _mm_blend_epi16(_mm_blend_epi16(v1, v2, 0x92), v0, 0x24); + + const __m128i sh_a = _mm_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m128i sh_b = _mm_setr_epi8(2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13); + const __m128i sh_c = _mm_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + a0 = _mm_shuffle_epi8(a0, sh_a); + b0 = _mm_shuffle_epi8(b0, sh_b); + c0 = _mm_shuffle_epi8(c0, sh_c); + + a.val = a0; + b.val = b0; + c.val = c0; +#else + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 8)); + __m128i t02 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + + __m128i t10 = _mm_unpacklo_epi16(t00, _mm_unpackhi_epi64(t01, t01)); + __m128i t11 = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t00, t00), t02); + __m128i t12 = _mm_unpacklo_epi16(t01, _mm_unpackhi_epi64(t02, t02)); + + __m128i t20 = _mm_unpacklo_epi16(t10, _mm_unpackhi_epi64(t11, t11)); + __m128i t21 = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t10, t10), t12); + __m128i t22 = _mm_unpacklo_epi16(t11, _mm_unpackhi_epi64(t12, t12)); + + a.val = _mm_unpacklo_epi16(t20, _mm_unpackhi_epi64(t21, t21)); + b.val = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t20, t20), t22); + c.val = _mm_unpacklo_epi16(t21, _mm_unpackhi_epi64(t22, t22)); +#endif +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c, v_uint16x8& d) +{ + __m128i u0 = _mm_loadu_si128((const __m128i*)ptr); // a0 b0 c0 d0 a1 b1 c1 d1 + __m128i u1 = _mm_loadu_si128((const __m128i*)(ptr + 8)); // a2 b2 c2 d2 ... + __m128i u2 = _mm_loadu_si128((const __m128i*)(ptr + 16)); // a4 b4 c4 d4 ... + __m128i u3 = _mm_loadu_si128((const __m128i*)(ptr + 24)); // a6 b6 c6 d6 ... + + __m128i v0 = _mm_unpacklo_epi16(u0, u2); // a0 a4 b0 b4 ... + __m128i v1 = _mm_unpackhi_epi16(u0, u2); // a1 a5 b1 b5 ... + __m128i v2 = _mm_unpacklo_epi16(u1, u3); // a2 a6 b2 b6 ... + __m128i v3 = _mm_unpackhi_epi16(u1, u3); // a3 a7 b3 b7 ... + + u0 = _mm_unpacklo_epi16(v0, v2); // a0 a2 a4 a6 ... + u1 = _mm_unpacklo_epi16(v1, v3); // a1 a3 a5 a7 ... + u2 = _mm_unpackhi_epi16(v0, v2); // c0 c2 c4 c6 ... + u3 = _mm_unpackhi_epi16(v1, v3); // c1 c3 c5 c7 ... + + a.val = _mm_unpacklo_epi16(u0, u1); + b.val = _mm_unpackhi_epi16(u0, u1); + c.val = _mm_unpacklo_epi16(u2, u3); + d.val = _mm_unpackhi_epi16(u2, u3); +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b) +{ + __m128i v0 = _mm_loadu_si128((__m128i*)(ptr)); // a0 b0 a1 b1 + __m128i v1 = _mm_loadu_si128((__m128i*)(ptr + 4)); // a2 b2 a3 b3 + + __m128i v2 = _mm_unpacklo_epi32(v0, v1); // a0 a2 b0 b2 + __m128i v3 = _mm_unpackhi_epi32(v0, v1); // a1 a3 b1 b3 + + a.val = _mm_unpacklo_epi32(v2, v3); // a0 a1 a2 a3 + b.val = _mm_unpackhi_epi32(v2, v3); // b0 b1 ab b3 +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b, v_uint32x4& c) +{ + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 4)); + __m128i t02 = _mm_loadu_si128((const __m128i*)(ptr + 8)); + + __m128i t10 = _mm_unpacklo_epi32(t00, _mm_unpackhi_epi64(t01, t01)); + __m128i t11 = _mm_unpacklo_epi32(_mm_unpackhi_epi64(t00, t00), t02); + __m128i t12 = _mm_unpacklo_epi32(t01, _mm_unpackhi_epi64(t02, t02)); + + a.val = _mm_unpacklo_epi32(t10, _mm_unpackhi_epi64(t11, t11)); + b.val = _mm_unpacklo_epi32(_mm_unpackhi_epi64(t10, t10), t12); + c.val = _mm_unpacklo_epi32(t11, _mm_unpackhi_epi64(t12, t12)); +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b, v_uint32x4& c, v_uint32x4& d) +{ + v_uint32x4 s0(_mm_loadu_si128((const __m128i*)ptr)); // a0 b0 c0 d0 + v_uint32x4 s1(_mm_loadu_si128((const __m128i*)(ptr + 4))); // a1 b1 c1 d1 + v_uint32x4 s2(_mm_loadu_si128((const __m128i*)(ptr + 8))); // a2 b2 c2 d2 + v_uint32x4 s3(_mm_loadu_si128((const __m128i*)(ptr + 12))); // a3 b3 c3 d3 + + v_transpose4x4(s0, s1, s2, s3, a, b, c, d); +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b) +{ + __m128 u0 = _mm_loadu_ps(ptr); // a0 b0 a1 b1 + __m128 u1 = _mm_loadu_ps((ptr + 4)); // a2 b2 a3 b3 + + a.val = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(2, 0, 2, 0)); // a0 a1 a2 a3 + b.val = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(3, 1, 3, 1)); // b0 b1 ab b3 +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b, v_float32x4& c) +{ + __m128 t0 = _mm_loadu_ps(ptr + 0); + __m128 t1 = _mm_loadu_ps(ptr + 4); + __m128 t2 = _mm_loadu_ps(ptr + 8); + + __m128 at12 = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(0, 1, 0, 2)); + a.val = _mm_shuffle_ps(t0, at12, _MM_SHUFFLE(2, 0, 3, 0)); + + __m128 bt01 = _mm_shuffle_ps(t0, t1, _MM_SHUFFLE(0, 0, 0, 1)); + __m128 bt12 = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(0, 2, 0, 3)); + b.val = _mm_shuffle_ps(bt01, bt12, _MM_SHUFFLE(2, 0, 2, 0)); + + __m128 ct01 = _mm_shuffle_ps(t0, t1, _MM_SHUFFLE(0, 1, 0, 2)); + c.val = _mm_shuffle_ps(ct01, t2, _MM_SHUFFLE(3, 0, 2, 0)); +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b, v_float32x4& c, v_float32x4& d) +{ + __m128 t0 = _mm_loadu_ps(ptr + 0); + __m128 t1 = _mm_loadu_ps(ptr + 4); + __m128 t2 = _mm_loadu_ps(ptr + 8); + __m128 t3 = _mm_loadu_ps(ptr + 12); + __m128 t02lo = _mm_unpacklo_ps(t0, t2); + __m128 t13lo = _mm_unpacklo_ps(t1, t3); + __m128 t02hi = _mm_unpackhi_ps(t0, t2); + __m128 t13hi = _mm_unpackhi_ps(t1, t3); + a.val = _mm_unpacklo_ps(t02lo, t13lo); + b.val = _mm_unpackhi_ps(t02lo, t13lo); + c.val = _mm_unpacklo_ps(t02hi, t13hi); + d.val = _mm_unpackhi_ps(t02hi, t13hi); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); + + a = v_uint64x2(_mm_unpacklo_epi64(t0, t1)); + b = v_uint64x2(_mm_unpackhi_epi64(t0, t1)); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b, v_uint64x2& c) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); // a0, b0 + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); // c0, a1 + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 4)); // b1, c1 + + t1 = _mm_shuffle_epi32(t1, 0x4e); // a1, c0 + + a = v_uint64x2(_mm_unpacklo_epi64(t0, t1)); + b = v_uint64x2(_mm_unpacklo_epi64(_mm_unpackhi_epi64(t0, t0), t2)); + c = v_uint64x2(_mm_unpackhi_epi64(t1, t2)); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, + v_uint64x2& b, v_uint64x2& c, v_uint64x2& d) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); // a0 b0 + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); // c0 d0 + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 4)); // a1 b1 + __m128i t3 = _mm_loadu_si128((const __m128i*)(ptr + 6)); // c1 d1 + + a = v_uint64x2(_mm_unpacklo_epi64(t0, t2)); + b = v_uint64x2(_mm_unpackhi_epi64(t0, t2)); + c = v_uint64x2(_mm_unpacklo_epi64(t1, t3)); + d = v_uint64x2(_mm_unpackhi_epi64(t1, t3)); +} + +// store interleave + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi8(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi8(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 16), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 16), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + const v_uint8x16& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ +#if CV_SSE4_1 + const __m128i sh_a = _mm_setr_epi8(0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5); + const __m128i sh_b = _mm_setr_epi8(5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10); + const __m128i sh_c = _mm_setr_epi8(10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15); + __m128i a0 = _mm_shuffle_epi8(a.val, sh_a); + __m128i b0 = _mm_shuffle_epi8(b.val, sh_b); + __m128i c0 = _mm_shuffle_epi8(c.val, sh_c); + + const __m128i m0 = _mm_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0); + const __m128i m1 = _mm_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + __m128i v0 = _mm_blendv_epi8(_mm_blendv_epi8(a0, b0, m1), c0, m0); + __m128i v1 = _mm_blendv_epi8(_mm_blendv_epi8(b0, c0, m1), a0, m0); + __m128i v2 = _mm_blendv_epi8(_mm_blendv_epi8(c0, a0, m1), b0, m0); +#elif CV_SSSE3 + const __m128i m0 = _mm_setr_epi8(0, 6, 11, 1, 7, 12, 2, 8, 13, 3, 9, 14, 4, 10, 15, 5); + const __m128i m1 = _mm_setr_epi8(5, 11, 0, 6, 12, 1, 7, 13, 2, 8, 14, 3, 9, 15, 4, 10); + const __m128i m2 = _mm_setr_epi8(10, 0, 5, 11, 1, 6, 12, 2, 7, 13, 3, 8, 14, 4, 9, 15); + + __m128i t0 = _mm_alignr_epi8(b.val, _mm_slli_si128(a.val, 10), 5); + t0 = _mm_alignr_epi8(c.val, t0, 5); + __m128i v0 = _mm_shuffle_epi8(t0, m0); + + __m128i t1 = _mm_alignr_epi8(_mm_srli_si128(b.val, 5), _mm_slli_si128(a.val, 5), 6); + t1 = _mm_alignr_epi8(_mm_srli_si128(c.val, 5), t1, 5); + __m128i v1 = _mm_shuffle_epi8(t1, m1); + + __m128i t2 = _mm_alignr_epi8(_mm_srli_si128(c.val, 10), b.val, 11); + t2 = _mm_alignr_epi8(t2, a.val, 11); + __m128i v2 = _mm_shuffle_epi8(t2, m2); +#else + __m128i z = _mm_setzero_si128(); + __m128i ab0 = _mm_unpacklo_epi8(a.val, b.val); + __m128i ab1 = _mm_unpackhi_epi8(a.val, b.val); + __m128i c0 = _mm_unpacklo_epi8(c.val, z); + __m128i c1 = _mm_unpackhi_epi8(c.val, z); + + __m128i p00 = _mm_unpacklo_epi16(ab0, c0); + __m128i p01 = _mm_unpackhi_epi16(ab0, c0); + __m128i p02 = _mm_unpacklo_epi16(ab1, c1); + __m128i p03 = _mm_unpackhi_epi16(ab1, c1); + + __m128i p10 = _mm_unpacklo_epi32(p00, p01); + __m128i p11 = _mm_unpackhi_epi32(p00, p01); + __m128i p12 = _mm_unpacklo_epi32(p02, p03); + __m128i p13 = _mm_unpackhi_epi32(p02, p03); + + __m128i p20 = _mm_unpacklo_epi64(p10, p11); + __m128i p21 = _mm_unpackhi_epi64(p10, p11); + __m128i p22 = _mm_unpacklo_epi64(p12, p13); + __m128i p23 = _mm_unpackhi_epi64(p12, p13); + + p20 = _mm_slli_si128(p20, 1); + p22 = _mm_slli_si128(p22, 1); + + __m128i p30 = _mm_slli_epi64(_mm_unpacklo_epi32(p20, p21), 8); + __m128i p31 = _mm_srli_epi64(_mm_unpackhi_epi32(p20, p21), 8); + __m128i p32 = _mm_slli_epi64(_mm_unpacklo_epi32(p22, p23), 8); + __m128i p33 = _mm_srli_epi64(_mm_unpackhi_epi32(p22, p23), 8); + + __m128i p40 = _mm_unpacklo_epi64(p30, p31); + __m128i p41 = _mm_unpackhi_epi64(p30, p31); + __m128i p42 = _mm_unpacklo_epi64(p32, p33); + __m128i p43 = _mm_unpackhi_epi64(p32, p33); + + __m128i v0 = _mm_or_si128(_mm_srli_si128(p40, 2), _mm_slli_si128(p41, 10)); + __m128i v1 = _mm_or_si128(_mm_srli_si128(p41, 6), _mm_slli_si128(p42, 6)); + __m128i v2 = _mm_or_si128(_mm_srli_si128(p42, 10), _mm_slli_si128(p43, 2)); +#endif + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 16), v1); + _mm_stream_si128((__m128i*)(ptr + 32), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 16), v1); + _mm_store_si128((__m128i*)(ptr + 32), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); + _mm_storeu_si128((__m128i*)(ptr + 32), v2); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + const v_uint8x16& c, const v_uint8x16& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + // a0 a1 a2 a3 .... + // b0 b1 b2 b3 .... + // c0 c1 c2 c3 .... + // d0 d1 d2 d3 .... + __m128i u0 = _mm_unpacklo_epi8(a.val, c.val); // a0 c0 a1 c1 ... + __m128i u1 = _mm_unpackhi_epi8(a.val, c.val); // a8 c8 a9 c9 ... + __m128i u2 = _mm_unpacklo_epi8(b.val, d.val); // b0 d0 b1 d1 ... + __m128i u3 = _mm_unpackhi_epi8(b.val, d.val); // b8 d8 b9 d9 ... + + __m128i v0 = _mm_unpacklo_epi8(u0, u2); // a0 b0 c0 d0 ... + __m128i v1 = _mm_unpackhi_epi8(u0, u2); // a4 b4 c4 d4 ... + __m128i v2 = _mm_unpacklo_epi8(u1, u3); // a8 b8 c8 d8 ... + __m128i v3 = _mm_unpackhi_epi8(u1, u3); // a12 b12 c12 d12 ... + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 16), v1); + _mm_stream_si128((__m128i*)(ptr + 32), v2); + _mm_stream_si128((__m128i*)(ptr + 48), v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 16), v1); + _mm_store_si128((__m128i*)(ptr + 32), v2); + _mm_store_si128((__m128i*)(ptr + 48), v3); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); + _mm_storeu_si128((__m128i*)(ptr + 32), v2); + _mm_storeu_si128((__m128i*)(ptr + 48), v3); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, const v_uint16x8& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi16(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi16(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 8), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 8), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 8), v1); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, + const v_uint16x8& b, const v_uint16x8& c, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ +#if CV_SSE4_1 + const __m128i sh_a = _mm_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m128i sh_b = _mm_setr_epi8(10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5); + const __m128i sh_c = _mm_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + __m128i a0 = _mm_shuffle_epi8(a.val, sh_a); + __m128i b0 = _mm_shuffle_epi8(b.val, sh_b); + __m128i c0 = _mm_shuffle_epi8(c.val, sh_c); + + __m128i v0 = _mm_blend_epi16(_mm_blend_epi16(a0, b0, 0x92), c0, 0x24); + __m128i v1 = _mm_blend_epi16(_mm_blend_epi16(c0, a0, 0x92), b0, 0x24); + __m128i v2 = _mm_blend_epi16(_mm_blend_epi16(b0, c0, 0x92), a0, 0x24); +#else + __m128i z = _mm_setzero_si128(); + __m128i ab0 = _mm_unpacklo_epi16(a.val, b.val); + __m128i ab1 = _mm_unpackhi_epi16(a.val, b.val); + __m128i c0 = _mm_unpacklo_epi16(c.val, z); + __m128i c1 = _mm_unpackhi_epi16(c.val, z); + + __m128i p10 = _mm_unpacklo_epi32(ab0, c0); + __m128i p11 = _mm_unpackhi_epi32(ab0, c0); + __m128i p12 = _mm_unpacklo_epi32(ab1, c1); + __m128i p13 = _mm_unpackhi_epi32(ab1, c1); + + __m128i p20 = _mm_unpacklo_epi64(p10, p11); + __m128i p21 = _mm_unpackhi_epi64(p10, p11); + __m128i p22 = _mm_unpacklo_epi64(p12, p13); + __m128i p23 = _mm_unpackhi_epi64(p12, p13); + + p20 = _mm_slli_si128(p20, 2); + p22 = _mm_slli_si128(p22, 2); + + __m128i p30 = _mm_unpacklo_epi64(p20, p21); + __m128i p31 = _mm_unpackhi_epi64(p20, p21); + __m128i p32 = _mm_unpacklo_epi64(p22, p23); + __m128i p33 = _mm_unpackhi_epi64(p22, p23); + + __m128i v0 = _mm_or_si128(_mm_srli_si128(p30, 2), _mm_slli_si128(p31, 10)); + __m128i v1 = _mm_or_si128(_mm_srli_si128(p31, 6), _mm_slli_si128(p32, 6)); + __m128i v2 = _mm_or_si128(_mm_srli_si128(p32, 10), _mm_slli_si128(p33, 2)); +#endif + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 8), v1); + _mm_stream_si128((__m128i*)(ptr + 16), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 8), v1); + _mm_store_si128((__m128i*)(ptr + 16), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 8), v1); + _mm_storeu_si128((__m128i*)(ptr + 16), v2); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, const v_uint16x8& b, + const v_uint16x8& c, const v_uint16x8& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + // a0 a1 a2 a3 .... + // b0 b1 b2 b3 .... + // c0 c1 c2 c3 .... + // d0 d1 d2 d3 .... + __m128i u0 = _mm_unpacklo_epi16(a.val, c.val); // a0 c0 a1 c1 ... + __m128i u1 = _mm_unpackhi_epi16(a.val, c.val); // a4 c4 a5 c5 ... + __m128i u2 = _mm_unpacklo_epi16(b.val, d.val); // b0 d0 b1 d1 ... + __m128i u3 = _mm_unpackhi_epi16(b.val, d.val); // b4 d4 b5 d5 ... + + __m128i v0 = _mm_unpacklo_epi16(u0, u2); // a0 b0 c0 d0 ... + __m128i v1 = _mm_unpackhi_epi16(u0, u2); // a2 b2 c2 d2 ... + __m128i v2 = _mm_unpacklo_epi16(u1, u3); // a4 b4 c4 d4 ... + __m128i v3 = _mm_unpackhi_epi16(u1, u3); // a6 b6 c6 d6 ... + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 8), v1); + _mm_stream_si128((__m128i*)(ptr + 16), v2); + _mm_stream_si128((__m128i*)(ptr + 24), v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 8), v1); + _mm_store_si128((__m128i*)(ptr + 16), v2); + _mm_store_si128((__m128i*)(ptr + 24), v3); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 8), v1); + _mm_storeu_si128((__m128i*)(ptr + 16), v2); + _mm_storeu_si128((__m128i*)(ptr + 24), v3); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 4), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 4), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 4), v1); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + v_uint32x4 z = v_setzero_u32(), u0, u1, u2, u3; + v_transpose4x4(a, b, c, z, u0, u1, u2, u3); + + __m128i v0 = _mm_or_si128(u0.val, _mm_slli_si128(u1.val, 12)); + __m128i v1 = _mm_or_si128(_mm_srli_si128(u1.val, 4), _mm_slli_si128(u2.val, 8)); + __m128i v2 = _mm_or_si128(_mm_srli_si128(u2.val, 8), _mm_slli_si128(u3.val, 4)); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 4), v1); + _mm_stream_si128((__m128i*)(ptr + 8), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 4), v1); + _mm_store_si128((__m128i*)(ptr + 8), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 4), v1); + _mm_storeu_si128((__m128i*)(ptr + 8), v2); + } +} + +inline void v_store_interleave(unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + v_uint32x4 v0, v1, v2, v3; + v_transpose4x4(a, b, c, d, v0, v1, v2, v3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0.val); + _mm_stream_si128((__m128i*)(ptr + 4), v1.val); + _mm_stream_si128((__m128i*)(ptr + 8), v2.val); + _mm_stream_si128((__m128i*)(ptr + 12), v3.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0.val); + _mm_store_si128((__m128i*)(ptr + 4), v1.val); + _mm_store_si128((__m128i*)(ptr + 8), v2.val); + _mm_store_si128((__m128i*)(ptr + 12), v3.val); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0.val); + _mm_storeu_si128((__m128i*)(ptr + 4), v1.val); + _mm_storeu_si128((__m128i*)(ptr + 8), v2.val); + _mm_storeu_si128((__m128i*)(ptr + 12), v3.val); + } +} + +// 2-channel, float only +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128 v0 = _mm_unpacklo_ps(a.val, b.val); // a0 b0 a1 b1 + __m128 v1 = _mm_unpackhi_ps(a.val, b.val); // a2 b2 a3 b3 + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_ps(ptr, v0); + _mm_stream_ps(ptr + 4, v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_ps(ptr, v0); + _mm_store_ps(ptr + 4, v1); + } + else + { + _mm_storeu_ps(ptr, v0); + _mm_storeu_ps(ptr + 4, v1); + } +} + +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128 u0 = _mm_shuffle_ps(a.val, b.val, _MM_SHUFFLE(0, 0, 0, 0)); + __m128 u1 = _mm_shuffle_ps(c.val, a.val, _MM_SHUFFLE(1, 1, 0, 0)); + __m128 v0 = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(2, 0, 2, 0)); + __m128 u2 = _mm_shuffle_ps(b.val, c.val, _MM_SHUFFLE(1, 1, 1, 1)); + __m128 u3 = _mm_shuffle_ps(a.val, b.val, _MM_SHUFFLE(2, 2, 2, 2)); + __m128 v1 = _mm_shuffle_ps(u2, u3, _MM_SHUFFLE(2, 0, 2, 0)); + __m128 u4 = _mm_shuffle_ps(c.val, a.val, _MM_SHUFFLE(3, 3, 2, 2)); + __m128 u5 = _mm_shuffle_ps(b.val, c.val, _MM_SHUFFLE(3, 3, 3, 3)); + __m128 v2 = _mm_shuffle_ps(u4, u5, _MM_SHUFFLE(2, 0, 2, 0)); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_ps(ptr, v0); + _mm_stream_ps(ptr + 4, v1); + _mm_stream_ps(ptr + 8, v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_ps(ptr, v0); + _mm_store_ps(ptr + 4, v1); + _mm_store_ps(ptr + 8, v2); + } + else + { + _mm_storeu_ps(ptr, v0); + _mm_storeu_ps(ptr + 4, v1); + _mm_storeu_ps(ptr + 8, v2); + } +} + +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128 u0 = _mm_unpacklo_ps(a.val, c.val); + __m128 u1 = _mm_unpacklo_ps(b.val, d.val); + __m128 u2 = _mm_unpackhi_ps(a.val, c.val); + __m128 u3 = _mm_unpackhi_ps(b.val, d.val); + __m128 v0 = _mm_unpacklo_ps(u0, u1); + __m128 v2 = _mm_unpacklo_ps(u2, u3); + __m128 v1 = _mm_unpackhi_ps(u0, u1); + __m128 v3 = _mm_unpackhi_ps(u2, u3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_ps(ptr, v0); + _mm_stream_ps(ptr + 4, v1); + _mm_stream_ps(ptr + 8, v2); + _mm_stream_ps(ptr + 12, v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_ps(ptr, v0); + _mm_store_ps(ptr + 4, v1); + _mm_store_ps(ptr + 8, v2); + _mm_store_ps(ptr + 12, v3); + } + else + { + _mm_storeu_ps(ptr, v0); + _mm_storeu_ps(ptr + 4, v1); + _mm_storeu_ps(ptr + 8, v2); + _mm_storeu_ps(ptr + 12, v3); + } +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi64(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 2), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 2), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 2), v1); + } +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + const v_uint64x2& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i v1 = _mm_unpacklo_epi64(c.val, _mm_unpackhi_epi64(a.val, a.val)); + __m128i v2 = _mm_unpackhi_epi64(b.val, c.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 2), v1); + _mm_stream_si128((__m128i*)(ptr + 4), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 2), v1); + _mm_store_si128((__m128i*)(ptr + 4), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 2), v1); + _mm_storeu_si128((__m128i*)(ptr + 4), v2); + } +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + const v_uint64x2& c, const v_uint64x2& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i v1 = _mm_unpacklo_epi64(c.val, d.val); + __m128i v2 = _mm_unpackhi_epi64(a.val, b.val); + __m128i v3 = _mm_unpackhi_epi64(c.val, d.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 2), v1); + _mm_stream_si128((__m128i*)(ptr + 4), v2); + _mm_stream_si128((__m128i*)(ptr + 6), v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 2), v1); + _mm_store_si128((__m128i*)(ptr + 4), v2); + _mm_store_si128((__m128i*)(ptr + 6), v3); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 2), v1); + _mm_storeu_si128((__m128i*)(ptr + 4), v2); + _mm_storeu_si128((__m128i*)(ptr + 6), v3); + } +} + +#define OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \ +{ \ + _Tpvec1 a1, b1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \ +{ \ + _Tpvec1 a1, b1, c1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \ +{ \ + _Tpvec1 a1, b1, c1, d1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ + d0 = v_reinterpret_as_##suffix0(d1); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, const _Tpvec0& d0, \ + hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \ +} + +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int8x16, schar, s8, v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int16x8, short, s16, v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int32x4, int, s32, v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int64x2, int64, s64, v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_float64x2, double, f64, v_uint64x2, uint64, u64) + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(_mm_cvtepi32_ps(a.val)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + return v_float32x4(_mm_cvtpd_ps(a.val)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + return v_float32x4(_mm_movelh_ps(_mm_cvtpd_ps(a.val), _mm_cvtpd_ps(b.val))); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + return v_float64x2(_mm_cvtepi32_pd(a.val)); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(_mm_cvtepi32_pd(_mm_srli_si128(a.val,8))); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + return v_float64x2(_mm_cvtps_pd(a.val)); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(_mm_cvtps_pd(_mm_movehl_ps(a.val, a.val))); +} + +#if CV_FP16 +inline v_float32x4 v128_load_fp16_f32(const short* ptr) +{ + return v_float32x4(_mm_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr))); +} + +inline void v_store_fp16(short* ptr, const v_float32x4& a) +{ + __m128i fp16_value = _mm_cvtps_ph(a.val, 0); + _mm_storel_epi64((__m128i*)ptr, fp16_value); +} +#endif + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int8x16(_mm_setr_epi8(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]])); +#else + return v_int8x16(_mm_setr_epi64( + _mm_setr_pi8(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]]), + _mm_setr_pi8(tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]) + )); +#endif +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int8x16(_mm_setr_epi16(*(const short*)(tab + idx[0]), *(const short*)(tab + idx[1]), *(const short*)(tab + idx[2]), *(const short*)(tab + idx[3]), + *(const short*)(tab + idx[4]), *(const short*)(tab + idx[5]), *(const short*)(tab + idx[6]), *(const short*)(tab + idx[7]))); +#else + return v_int8x16(_mm_setr_epi64( + _mm_setr_pi16(*(const short*)(tab + idx[0]), *(const short*)(tab + idx[1]), *(const short*)(tab + idx[2]), *(const short*)(tab + idx[3])), + _mm_setr_pi16(*(const short*)(tab + idx[4]), *(const short*)(tab + idx[5]), *(const short*)(tab + idx[6]), *(const short*)(tab + idx[7])) + )); +#endif +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int8x16(_mm_setr_epi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1]), + *(const int*)(tab + idx[2]), *(const int*)(tab + idx[3]))); +#else + return v_int8x16(_mm_setr_epi64( + _mm_setr_pi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1])), + _mm_setr_pi32(*(const int*)(tab + idx[2]), *(const int*)(tab + idx[3])) + )); +#endif +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((const schar *)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((const schar *)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((const schar *)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int16x8(_mm_setr_epi16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], + tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]])); +#else + return v_int16x8(_mm_setr_epi64( + _mm_setr_pi16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]), + _mm_setr_pi16(tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]) + )); +#endif +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int16x8(_mm_setr_epi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1]), + *(const int*)(tab + idx[2]), *(const int*)(tab + idx[3]))); +#else + return v_int16x8(_mm_setr_epi64( + _mm_setr_pi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1])), + _mm_setr_pi32(*(const int*)(tab + idx[2]), *(const int*)(tab + idx[3])) + )); +#endif +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_int16x8(_mm_set_epi64x(*(const int64_t*)(tab + idx[1]), *(const int64_t*)(tab + idx[0]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((const short *)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((const short *)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((const short *)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int32x4(_mm_setr_epi32(tab[idx[0]], tab[idx[1]], + tab[idx[2]], tab[idx[3]])); +#else + return v_int32x4(_mm_setr_epi64( + _mm_setr_pi32(tab[idx[0]], tab[idx[1]]), + _mm_setr_pi32(tab[idx[2]], tab[idx[3]]) + )); +#endif +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_int32x4(_mm_set_epi64x(*(const int64_t*)(tab + idx[1]), *(const int64_t*)(tab + idx[0]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(_mm_loadu_si128((const __m128i*)(tab + idx[0]))); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((const int *)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((const int *)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((const int *)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(_mm_set_epi64x(tab[idx[1]], tab[idx[0]])); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(_mm_loadu_si128((const __m128i*)(tab + idx[0]))); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + return v_float32x4(_mm_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]])); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_pairs((const int *)tab, idx)); } +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_quads((const int *)tab, idx)); } + +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + return v_float64x2(_mm_setr_pd(tab[idx[0]], tab[idx[1]])); +} +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) { return v_float64x2(_mm_castsi128_pd(_mm_loadu_si128((const __m128i*)(tab + idx[0])))); } + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + return v_int32x4(_mm_setr_epi32(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]])); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + return v_float32x4(_mm_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]])); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + int idx[2]; + v_store_low(idx, idxvec); + return v_float64x2(_mm_setr_pd(tab[idx[0]], tab[idx[1]])); +} + +// loads pairs from the table and deinterleaves them, e.g. returns: +// x = (tab[idxvec[0], tab[idxvec[1]], tab[idxvec[2]], tab[idxvec[3]]), +// y = (tab[idxvec[0]+1], tab[idxvec[1]+1], tab[idxvec[2]+1], tab[idxvec[3]+1]) +// note that the indices are float's indices, not the float-pair indices. +// in theory, this function can be used to implement bilinear interpolation, +// when idxvec are the offsets within the image. +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + __m128 z = _mm_setzero_ps(); + __m128 xy01 = _mm_loadl_pi(z, (__m64*)(tab + idx[0])); + __m128 xy23 = _mm_loadl_pi(z, (__m64*)(tab + idx[2])); + xy01 = _mm_loadh_pi(xy01, (__m64*)(tab + idx[1])); + xy23 = _mm_loadh_pi(xy23, (__m64*)(tab + idx[3])); + __m128 xxyy02 = _mm_unpacklo_ps(xy01, xy23); + __m128 xxyy13 = _mm_unpackhi_ps(xy01, xy23); + x = v_float32x4(_mm_unpacklo_ps(xxyy02, xxyy13)); + y = v_float32x4(_mm_unpackhi_ps(xxyy02, xxyy13)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int idx[2]; + v_store_low(idx, idxvec); + __m128d xy0 = _mm_loadu_pd(tab + idx[0]); + __m128d xy1 = _mm_loadu_pd(tab + idx[1]); + x = v_float64x2(_mm_unpacklo_pd(xy0, xy1)); + y = v_float64x2(_mm_unpackhi_pd(xy0, xy1)); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ +#if CV_SSSE3 + return v_int8x16(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0d0e0c0b090a08, 0x0705060403010200))); +#else + __m128i a = _mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(3, 1, 2, 0)); + a = _mm_shufflehi_epi16(a, _MM_SHUFFLE(3, 1, 2, 0)); + a = _mm_shuffle_epi32(a, _MM_SHUFFLE(3, 1, 2, 0)); + return v_int8x16(_mm_unpacklo_epi8(a, _mm_unpackhi_epi64(a, a))); +#endif +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ +#if CV_SSSE3 + return v_int8x16(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0b0e0a0d090c08, 0x0703060205010400))); +#else + __m128i a = _mm_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0)); + return v_int8x16(_mm_unpacklo_epi8(a, _mm_unpackhi_epi64(a, a))); +#endif +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ +#if CV_SSSE3 + return v_int16x8(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0e0b0a0d0c0908, 0x0706030205040100))); +#else + __m128i a = _mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(3, 1, 2, 0)); + return v_int16x8(_mm_shufflehi_epi16(a, _MM_SHUFFLE(3, 1, 2, 0))); +#endif +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ +#if CV_SSSE3 + return v_int16x8(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0e07060d0c0504, 0x0b0a030209080100))); +#else + return v_int16x8(_mm_unpacklo_epi16(vec.val, _mm_unpackhi_epi64(vec.val, vec.val))); +#endif +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + return v_int32x4(_mm_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0))); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ +#if CV_SSSE3 + return v_int8x16(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0xffffff0f0e0d0c0a, 0x0908060504020100))); +#else + __m128i mask = _mm_set1_epi64x(0x00000000FFFFFFFF); + __m128i a = _mm_srli_si128(_mm_or_si128(_mm_andnot_si128(mask, vec.val), _mm_and_si128(mask, _mm_sll_epi32(vec.val, _mm_set_epi64x(0, 8)))), 1); + return v_int8x16(_mm_srli_si128(_mm_shufflelo_epi16(a, _MM_SHUFFLE(2, 1, 0, 3)), 2)); +#endif +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ +#if CV_SSSE3 + return v_int16x8(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0xffff0f0e0d0c0b0a, 0x0908050403020100))); +#else + return v_int16x8(_mm_srli_si128(_mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(2, 1, 0, 3)), 2)); +#endif +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +////////////// FP16 support /////////////////////////// + +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + const __m128i z = _mm_setzero_si128(), delta = _mm_set1_epi32(0x38000000); + const __m128i signmask = _mm_set1_epi32(0x80000000), maxexp = _mm_set1_epi32(0x7c000000); + const __m128 deltaf = _mm_castsi128_ps(_mm_set1_epi32(0x38800000)); + __m128i bits = _mm_unpacklo_epi16(z, _mm_loadl_epi64((const __m128i*)ptr)); // h << 16 + __m128i e = _mm_and_si128(bits, maxexp), sign = _mm_and_si128(bits, signmask); + __m128i t = _mm_add_epi32(_mm_srli_epi32(_mm_xor_si128(bits, sign), 3), delta); // ((h & 0x7fff) << 13) + delta + __m128i zt = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_add_epi32(t, _mm_set1_epi32(1 << 23))), deltaf)); + + t = _mm_add_epi32(t, _mm_and_si128(delta, _mm_cmpeq_epi32(maxexp, e))); + __m128i zmask = _mm_cmpeq_epi32(e, z); + __m128i ft = v_select_si128(zmask, zt, t); + return v_float32x4(_mm_castsi128_ps(_mm_or_si128(ft, sign))); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + const __m128i signmask = _mm_set1_epi32(0x80000000); + const __m128i rval = _mm_set1_epi32(0x3f000000); + + __m128i t = _mm_castps_si128(v.val); + __m128i sign = _mm_srai_epi32(_mm_and_si128(t, signmask), 16); + t = _mm_andnot_si128(signmask, t); + + __m128i finitemask = _mm_cmpgt_epi32(_mm_set1_epi32(0x47800000), t); + __m128i isnan = _mm_cmpgt_epi32(t, _mm_set1_epi32(0x7f800000)); + __m128i naninf = v_select_si128(isnan, _mm_set1_epi32(0x7e00), _mm_set1_epi32(0x7c00)); + __m128i tinymask = _mm_cmpgt_epi32(_mm_set1_epi32(0x38800000), t); + __m128i tt = _mm_castps_si128(_mm_add_ps(_mm_castsi128_ps(t), _mm_castsi128_ps(rval))); + tt = _mm_sub_epi32(tt, rval); + __m128i odd = _mm_and_si128(_mm_srli_epi32(t, 13), _mm_set1_epi32(1)); + __m128i nt = _mm_add_epi32(t, _mm_set1_epi32(0xc8000fff)); + nt = _mm_srli_epi32(_mm_add_epi32(nt, odd), 13); + t = v_select_si128(tinymask, tt, nt); + t = v_select_si128(finitemask, t, naninf); + t = _mm_or_si128(t, sign); + t = _mm_packs_epi32(t, t); + _mm_storel_epi64((__m128i*)ptr, t); +} + +inline void v_cleanup() {} + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return (CV_CPU_HAS_SUPPORT_SSE2) ? true : false; +} + +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif diff --git a/include/opencv2/core/hal/intrin_sse_em.hpp b/include/opencv2/core/hal/intrin_sse_em.hpp new file mode 100644 index 0000000..be27668 --- /dev/null +++ b/include/opencv2/core/hal/intrin_sse_em.hpp @@ -0,0 +1,167 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_INTRIN_SSE_EM_HPP +#define OPENCV_HAL_INTRIN_SSE_EM_HPP + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define OPENCV_HAL_SSE_WRAP_1(fun, tp) \ + inline tp _v128_##fun(const tp& a) \ + { return _mm_##fun(a); } + +#define OPENCV_HAL_SSE_WRAP_2(fun, tp) \ + inline tp _v128_##fun(const tp& a, const tp& b) \ + { return _mm_##fun(a, b); } + +#define OPENCV_HAL_SSE_WRAP_3(fun, tp) \ + inline tp _v128_##fun(const tp& a, const tp& b, const tp& c) \ + { return _mm_##fun(a, b, c); } + +///////////////////////////// XOP ///////////////////////////// + +// [todo] define CV_XOP +#if 1 // CV_XOP +inline __m128i _v128_comgt_epu32(const __m128i& a, const __m128i& b) +{ + const __m128i delta = _mm_set1_epi32((int)0x80000000); + return _mm_cmpgt_epi32(_mm_xor_si128(a, delta), _mm_xor_si128(b, delta)); +} +// wrapping XOP +#else +OPENCV_HAL_SSE_WRAP_2(_v128_comgt_epu32, __m128i) +#endif // !CV_XOP + +///////////////////////////// SSE4.1 ///////////////////////////// + +#if !CV_SSE4_1 + +/** Swizzle **/ +inline __m128i _v128_blendv_epi8(const __m128i& a, const __m128i& b, const __m128i& mask) +{ return _mm_xor_si128(a, _mm_and_si128(_mm_xor_si128(b, a), mask)); } + +/** Convert **/ +// 8 >> 16 +inline __m128i _v128_cvtepu8_epi16(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi8(a, z); +} +inline __m128i _v128_cvtepi8_epi16(const __m128i& a) +{ return _mm_srai_epi16(_mm_unpacklo_epi8(a, a), 8); } +// 8 >> 32 +inline __m128i _v128_cvtepu8_epi32(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi16(_mm_unpacklo_epi8(a, z), z); +} +inline __m128i _v128_cvtepi8_epi32(const __m128i& a) +{ + __m128i r = _mm_unpacklo_epi8(a, a); + r = _mm_unpacklo_epi8(r, r); + return _mm_srai_epi32(r, 24); +} +// 16 >> 32 +inline __m128i _v128_cvtepu16_epi32(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi16(a, z); +} +inline __m128i _v128_cvtepi16_epi32(const __m128i& a) +{ return _mm_srai_epi32(_mm_unpacklo_epi16(a, a), 16); } +// 32 >> 64 +inline __m128i _v128_cvtepu32_epi64(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi32(a, z); +} +inline __m128i _v128_cvtepi32_epi64(const __m128i& a) +{ return _mm_unpacklo_epi32(a, _mm_srai_epi32(a, 31)); } + +/** Arithmetic **/ +inline __m128i _v128_mullo_epi32(const __m128i& a, const __m128i& b) +{ + __m128i c0 = _mm_mul_epu32(a, b); + __m128i c1 = _mm_mul_epu32(_mm_srli_epi64(a, 32), _mm_srli_epi64(b, 32)); + __m128i d0 = _mm_unpacklo_epi32(c0, c1); + __m128i d1 = _mm_unpackhi_epi32(c0, c1); + return _mm_unpacklo_epi64(d0, d1); +} + +/** Math **/ +inline __m128i _v128_min_epu32(const __m128i& a, const __m128i& b) +{ return _v128_blendv_epi8(a, b, _v128_comgt_epu32(a, b)); } + +// wrapping SSE4.1 +#else +OPENCV_HAL_SSE_WRAP_1(cvtepu8_epi16, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi8_epi16, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepu8_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi8_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepu16_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi16_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepu32_epi64, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi32_epi64, __m128i) +OPENCV_HAL_SSE_WRAP_2(min_epu32, __m128i) +OPENCV_HAL_SSE_WRAP_2(mullo_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_3(blendv_epi8, __m128i) +#endif // !CV_SSE4_1 + +///////////////////////////// Revolutionary ///////////////////////////// + +/** Convert **/ +// 16 << 8 +inline __m128i _v128_cvtepu8_epi16_high(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpackhi_epi8(a, z); +} +inline __m128i _v128_cvtepi8_epi16_high(const __m128i& a) +{ return _mm_srai_epi16(_mm_unpackhi_epi8(a, a), 8); } +// 32 << 16 +inline __m128i _v128_cvtepu16_epi32_high(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpackhi_epi16(a, z); +} +inline __m128i _v128_cvtepi16_epi32_high(const __m128i& a) +{ return _mm_srai_epi32(_mm_unpackhi_epi16(a, a), 16); } +// 64 << 32 +inline __m128i _v128_cvtepu32_epi64_high(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpackhi_epi32(a, z); +} +inline __m128i _v128_cvtepi32_epi64_high(const __m128i& a) +{ return _mm_unpackhi_epi32(a, _mm_srai_epi32(a, 31)); } + +/** Miscellaneous **/ +inline __m128i _v128_packs_epu32(const __m128i& a, const __m128i& b) +{ + const __m128i m = _mm_set1_epi32(65535); + __m128i am = _v128_min_epu32(a, m); + __m128i bm = _v128_min_epu32(b, m); +#if CV_SSE4_1 + return _mm_packus_epi32(am, bm); +#else + const __m128i d = _mm_set1_epi32(32768), nd = _mm_set1_epi16(-32768); + am = _mm_sub_epi32(am, d); + bm = _mm_sub_epi32(bm, d); + am = _mm_packs_epi32(am, bm); + return _mm_sub_epi16(am, nd); +#endif +} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: + +#endif // OPENCV_HAL_INTRIN_SSE_EM_HPP \ No newline at end of file diff --git a/include/opencv2/core/hal/intrin_vsx.hpp b/include/opencv2/core/hal/intrin_vsx.hpp new file mode 100644 index 0000000..c5ceb11 --- /dev/null +++ b/include/opencv2/core/hal/intrin_vsx.hpp @@ -0,0 +1,1328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_VSX_HPP +#define OPENCV_HAL_VSX_HPP + +#include <algorithm> +#include "opencv2/core/utility.hpp" + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + vec_uchar16 val; + + explicit v_uint8x16(const vec_uchar16& v) : val(v) + {} + v_uint8x16() : val(vec_uchar16_z) + {} + v_uint8x16(vec_bchar16 v) : val(vec_uchar16_c(v)) + {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + : val(vec_uchar16_set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) + {} + uchar get0() const + { return vec_extract(val, 0); } +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + vec_char16 val; + + explicit v_int8x16(const vec_char16& v) : val(v) + {} + v_int8x16() : val(vec_char16_z) + {} + v_int8x16(vec_bchar16 v) : val(vec_char16_c(v)) + {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + : val(vec_char16_set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) + {} + schar get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + vec_ushort8 val; + + explicit v_uint16x8(const vec_ushort8& v) : val(v) + {} + v_uint16x8() : val(vec_ushort8_z) + {} + v_uint16x8(vec_bshort8 v) : val(vec_ushort8_c(v)) + {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + : val(vec_ushort8_set(v0, v1, v2, v3, v4, v5, v6, v7)) + {} + ushort get0() const + { return vec_extract(val, 0); } +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + vec_short8 val; + + explicit v_int16x8(const vec_short8& v) : val(v) + {} + v_int16x8() : val(vec_short8_z) + {} + v_int16x8(vec_bshort8 v) : val(vec_short8_c(v)) + {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + : val(vec_short8_set(v0, v1, v2, v3, v4, v5, v6, v7)) + {} + short get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + vec_uint4 val; + + explicit v_uint32x4(const vec_uint4& v) : val(v) + {} + v_uint32x4() : val(vec_uint4_z) + {} + v_uint32x4(vec_bint4 v) : val(vec_uint4_c(v)) + {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) : val(vec_uint4_set(v0, v1, v2, v3)) + {} + uint get0() const + { return vec_extract(val, 0); } +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + vec_int4 val; + + explicit v_int32x4(const vec_int4& v) : val(v) + {} + v_int32x4() : val(vec_int4_z) + {} + v_int32x4(vec_bint4 v) : val(vec_int4_c(v)) + {} + v_int32x4(int v0, int v1, int v2, int v3) : val(vec_int4_set(v0, v1, v2, v3)) + {} + int get0() const + { return vec_extract(val, 0); } +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + vec_float4 val; + + explicit v_float32x4(const vec_float4& v) : val(v) + {} + v_float32x4() : val(vec_float4_z) + {} + v_float32x4(vec_bint4 v) : val(vec_float4_c(v)) + {} + v_float32x4(float v0, float v1, float v2, float v3) : val(vec_float4_set(v0, v1, v2, v3)) + {} + float get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + vec_udword2 val; + + explicit v_uint64x2(const vec_udword2& v) : val(v) + {} + v_uint64x2() : val(vec_udword2_z) + {} + v_uint64x2(vec_bdword2 v) : val(vec_udword2_c(v)) + {} + v_uint64x2(uint64 v0, uint64 v1) : val(vec_udword2_set(v0, v1)) + {} + uint64 get0() const + { return vec_extract(val, 0); } +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + vec_dword2 val; + + explicit v_int64x2(const vec_dword2& v) : val(v) + {} + v_int64x2() : val(vec_dword2_z) + {} + v_int64x2(vec_bdword2 v) : val(vec_dword2_c(v)) + {} + v_int64x2(int64 v0, int64 v1) : val(vec_dword2_set(v0, v1)) + {} + int64 get0() const + { return vec_extract(val, 0); } +}; + +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + vec_double2 val; + + explicit v_float64x2(const vec_double2& v) : val(v) + {} + v_float64x2() : val(vec_double2_z) + {} + v_float64x2(vec_bdword2 v) : val(vec_double2_c(v)) + {} + v_float64x2(double v0, double v1) : val(vec_double2_set(v0, v1)) + {} + double get0() const + { return vec_extract(val, 0); } +}; + +//////////////// Load and store operations /////////////// + +/* + * clang-5 aborted during parse "vec_xxx_c" only if it's + * inside a function template which is defined by preprocessor macro. + * + * if vec_xxx_c defined as C++ cast, clang-5 will pass it +*/ +#define OPENCV_HAL_IMPL_VSX_INITVEC(_Tpvec, _Tp, suffix, cast) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec(); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(vec_splats((_Tp)v));} \ +template<typename _Tpvec0> inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0 &a) \ +{ return _Tpvec((cast)a.val); } + +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint8x16, uchar, u8, vec_uchar16) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int8x16, schar, s8, vec_char16) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint16x8, ushort, u16, vec_ushort8) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int16x8, short, s16, vec_short8) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint32x4, uint, u32, vec_uint4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int32x4, int, s32, vec_int4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint64x2, uint64, u64, vec_udword2) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int64x2, int64, s64, vec_dword2) +OPENCV_HAL_IMPL_VSX_INITVEC(v_float32x4, float, f32, vec_float4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_float64x2, double, f64, vec_double2) + +#define OPENCV_HAL_IMPL_VSX_LOADSTORE_C(_Tpvec, _Tp, ld, ld_a, st, st_a) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(ld(0, ptr)); } \ +inline _Tpvec v_load_aligned(VSX_UNUSED(const _Tp* ptr)) \ +{ return _Tpvec(ld_a(0, ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vec_ld_l8(ptr)); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ return _Tpvec(vec_mergesqh(vec_ld_l8(ptr0), vec_ld_l8(ptr1))); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ st(a.val, 0, ptr); } \ +inline void v_store_aligned(VSX_UNUSED(_Tp* ptr), const _Tpvec& a) \ +{ st_a(a.val, 0, ptr); } \ +inline void v_store_aligned_nocache(VSX_UNUSED(_Tp* ptr), const _Tpvec& a) \ +{ st_a(a.val, 0, ptr); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ +{ if(mode == hal::STORE_UNALIGNED) st(a.val, 0, ptr); else st_a(a.val, 0, ptr); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ vec_st_l8(a.val, ptr); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ vec_st_h8(a.val, ptr); } + +// working around gcc bug for aligned ld/st +// if runtime check for vec_ld/st fail we failback to unaligned ld/st +// https://github.com/opencv/opencv/issues/13211 +#ifdef CV_COMPILER_VSX_BROKEN_ALIGNED + #define OPENCV_HAL_IMPL_VSX_LOADSTORE(_Tpvec, _Tp) \ + OPENCV_HAL_IMPL_VSX_LOADSTORE_C(_Tpvec, _Tp, vsx_ld, vsx_ld, vsx_st, vsx_st) +#else + #define OPENCV_HAL_IMPL_VSX_LOADSTORE(_Tpvec, _Tp) \ + OPENCV_HAL_IMPL_VSX_LOADSTORE_C(_Tpvec, _Tp, vsx_ld, vec_ld, vsx_st, vec_st) +#endif + +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_uint8x16, uchar) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_int8x16, schar) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_uint16x8, ushort) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_int16x8, short) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_uint32x4, uint) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_int32x4, int) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_float32x4, float) + +OPENCV_HAL_IMPL_VSX_LOADSTORE_C(v_float64x2, double, vsx_ld, vsx_ld, vsx_st, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_C(v_uint64x2, uint64, vsx_ld2, vsx_ld2, vsx_st2, vsx_st2) +OPENCV_HAL_IMPL_VSX_LOADSTORE_C(v_int64x2, int64, vsx_ld2, vsx_ld2, vsx_st2, vsx_st2) + +//////////////// Value reordering /////////////// + +/* de&interleave */ +#define OPENCV_HAL_IMPL_VSX_INTERLEAVE(_Tp, _Tpvec) \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, _Tpvec& b) \ +{ vec_ld_deinterleave(ptr, a.val, b.val);} \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, \ + _Tpvec& b, _Tpvec& c) \ +{ vec_ld_deinterleave(ptr, a.val, b.val, c.val); } \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ +{ vec_ld_deinterleave(ptr, a.val, b.val, c.val, d.val); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ vec_st_interleave(a.val, b.val, ptr); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, \ + const _Tpvec& b, const _Tpvec& c, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ vec_st_interleave(a.val, b.val, c.val, ptr); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b, \ + const _Tpvec& c, const _Tpvec& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ vec_st_interleave(a.val, b.val, c.val, d.val, ptr); } + +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(schar, v_int8x16) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(ushort, v_uint16x8) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(short, v_int16x8) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uint, v_uint32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(int, v_int32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(float, v_float32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(double, v_float64x2) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(int64, v_int64x2) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uint64, v_uint64x2) + +/* Expand */ +#define OPENCV_HAL_IMPL_VSX_EXPAND(_Tpvec, _Tpwvec, _Tp, fl, fh) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = fh(a.val); \ + b1.val = fl(a.val); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ return _Tpwvec(fh(a.val)); } \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ return _Tpwvec(fl(a.val)); } \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ return _Tpwvec(fh(vec_ld_l8(ptr))); } + +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint8x16, v_uint16x8, uchar, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int8x16, v_int16x8, schar, vec_unpackl, vec_unpackh) +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint16x8, v_uint32x4, ushort, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int16x8, v_int32x4, short, vec_unpackl, vec_unpackh) +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint32x4, v_uint64x2, uint, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int32x4, v_int64x2, int, vec_unpackl, vec_unpackh) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ return v_uint32x4(vec_uint4_set(ptr[0], ptr[1], ptr[2], ptr[3])); } + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ return v_int32x4(vec_int4_set(ptr[0], ptr[1], ptr[2], ptr[3])); } + +/* pack */ +#define OPENCV_HAL_IMPL_VSX_PACK(_Tpvec, _Tp, _Tpwvec, _Tpvn, _Tpdel, sfnc, pkfnc, addfnc, pack) \ +inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + return _Tpvec(pkfnc(a.val, b.val)); \ +} \ +inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + vec_st_l8(pkfnc(a.val, a.val), ptr); \ +} \ +template<int n> \ +inline _Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + const __vector _Tpvn vn = vec_splats((_Tpvn)n); \ + const __vector _Tpdel delta = vec_splats((_Tpdel)((_Tpdel)1 << (n-1))); \ + return _Tpvec(pkfnc(sfnc(addfnc(a.val, delta), vn), sfnc(addfnc(b.val, delta), vn))); \ +} \ +template<int n> \ +inline void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + const __vector _Tpvn vn = vec_splats((_Tpvn)n); \ + const __vector _Tpdel delta = vec_splats((_Tpdel)((_Tpdel)1 << (n-1))); \ + vec_st_l8(pkfnc(sfnc(addfnc(a.val, delta), vn), delta), ptr); \ +} + +OPENCV_HAL_IMPL_VSX_PACK(v_uint8x16, uchar, v_uint16x8, unsigned short, unsigned short, + vec_sr, vec_packs, vec_adds, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int8x16, schar, v_int16x8, unsigned short, short, + vec_sra, vec_packs, vec_adds, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint16x8, ushort, v_uint32x4, unsigned int, unsigned int, + vec_sr, vec_packs, vec_add, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int16x8, short, v_int32x4, unsigned int, int, + vec_sra, vec_packs, vec_add, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint32x4, uint, v_uint64x2, unsigned long long, unsigned long long, + vec_sr, vec_pack, vec_add, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int32x4, int, v_int64x2, unsigned long long, long long, + vec_sra, vec_pack, vec_add, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint8x16, uchar, v_int16x8, unsigned short, short, + vec_sra, vec_packsu, vec_adds, pack_u) +OPENCV_HAL_IMPL_VSX_PACK(v_uint16x8, ushort, v_int32x4, unsigned int, int, + vec_sra, vec_packsu, vec_add, pack_u) +// Following variant is not implemented on other platforms: +//OPENCV_HAL_IMPL_VSX_PACK(v_uint32x4, uint, v_int64x2, unsigned long long, long long, +// vec_sra, vec_packsu, vec_add, pack_u) + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + vec_uchar16 ab = vec_pack(a.val, b.val); + return v_uint8x16(ab); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + vec_ushort8 ab = vec_pack(a.val, b.val); + vec_ushort8 cd = vec_pack(c.val, d.val); + return v_uint8x16(vec_pack(ab, cd)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + vec_uint4 ab = vec_pack(a.val, b.val); + vec_uint4 cd = vec_pack(c.val, d.val); + vec_uint4 ef = vec_pack(e.val, f.val); + vec_uint4 gh = vec_pack(g.val, h.val); + + vec_ushort8 abcd = vec_pack(ab, cd); + vec_ushort8 efgh = vec_pack(ef, gh); + return v_uint8x16(vec_pack(abcd, efgh)); +} + +/* Recombine */ +template <typename _Tpvec> +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) +{ + b0.val = vec_mergeh(a0.val, a1.val); + b1.val = vec_mergel(a0.val, a1.val); +} + +template <typename _Tpvec> +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(vec_mergesql(a.val, b.val)); } + +template <typename _Tpvec> +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(vec_mergesqh(a.val, b.val)); } + +template <typename _Tpvec> +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) +{ + c.val = vec_mergesqh(a.val, b.val); + d.val = vec_mergesql(a.val, b.val); +} + +////////// Arithmetic, bitwise and comparison operations ///////// + +/* Element-wise binary and unary operations */ +/** Arithmetics **/ +#define OPENCV_HAL_IMPL_VSX_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(intrin(a.val, b.val)); } \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ a.val = intrin(a.val, b.val); return a; } + +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint8x16, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint8x16, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int8x16, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int8x16, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint16x8, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint16x8, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int16x8, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int16x8, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_uint32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_int32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_float32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_float32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_float32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(/, v_float32x4, vec_div) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_float64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_float64x2, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_float64x2, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(/, v_float64x2, vec_div) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint64x2, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int64x2, vec_sub) + +// saturating multiply +#define OPENCV_HAL_IMPL_VSX_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_int16x8, v_int32x4) +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_uint16x8, v_uint32x4) + +template<typename Tvec, typename Twvec> +inline void v_mul_expand(const Tvec& a, const Tvec& b, Twvec& c, Twvec& d) +{ + Twvec p0 = Twvec(vec_mule(a.val, b.val)); + Twvec p1 = Twvec(vec_mulo(a.val, b.val)); + v_zip(p0, p1, c, d); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, v_uint64x2& c, v_uint64x2& d) +{ + c.val = vec_mul(vec_unpackhu(a.val), vec_unpackhu(b.val)); + d.val = vec_mul(vec_unpacklu(a.val), vec_unpacklu(b.val)); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + vec_int4 p0 = vec_mule(a.val, b.val); + vec_int4 p1 = vec_mulo(a.val, b.val); + static const vec_uchar16 perm = {2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31}; + return v_int16x8(vec_perm(vec_short8_c(p0), vec_short8_c(p1), perm)); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + vec_uint4 p0 = vec_mule(a.val, b.val); + vec_uint4 p1 = vec_mulo(a.val, b.val); + static const vec_uchar16 perm = {2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31}; + return v_uint16x8(vec_perm(vec_ushort8_c(p0), vec_ushort8_c(p1), perm)); +} + +/** Non-saturating arithmetics **/ +#define OPENCV_HAL_IMPL_VSX_BIN_FUNC(func, intrin) \ +template<typename _Tpvec> \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(intrin(a.val, b.val)); } + +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_add_wrap, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_sub_wrap, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_mul_wrap, vec_mul) + +/** Bitwise shifts **/ +#define OPENCV_HAL_IMPL_VSX_SHIFT_OP(_Tpvec, shr, splfunc) \ +inline _Tpvec operator << (const _Tpvec& a, int imm) \ +{ return _Tpvec(vec_sl(a.val, splfunc(imm))); } \ +inline _Tpvec operator >> (const _Tpvec& a, int imm) \ +{ return _Tpvec(shr(a.val, splfunc(imm))); } \ +template<int imm> inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec(vec_sl(a.val, splfunc(imm))); } \ +template<int imm> inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec(shr(a.val, splfunc(imm))); } + +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint8x16, vec_sr, vec_uchar16_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint16x8, vec_sr, vec_ushort8_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint32x4, vec_sr, vec_uint4_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint64x2, vec_sr, vec_udword2_sp) +// algebraic right shift +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int8x16, vec_sra, vec_uchar16_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int16x8, vec_sra, vec_ushort8_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int32x4, vec_sra, vec_uint4_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int64x2, vec_sra, vec_udword2_sp) + +/** Bitwise logic **/ +#define OPENCV_HAL_IMPL_VSX_LOGIC_OP(_Tpvec) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(&, _Tpvec, vec_and) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(|, _Tpvec, vec_or) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(^, _Tpvec, vec_xor) \ +inline _Tpvec operator ~ (const _Tpvec& a) \ +{ return _Tpvec(vec_not(a.val)); } + +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint8x16) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int8x16) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint16x8) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int16x8) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint64x2) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int64x2) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_float32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_float64x2) + +/** Bitwise select **/ +#define OPENCV_HAL_IMPL_VSX_SELECT(_Tpvec, cast) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_sel(b.val, a.val, cast(mask.val))); } + +OPENCV_HAL_IMPL_VSX_SELECT(v_uint8x16, vec_bchar16_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int8x16, vec_bchar16_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_uint16x8, vec_bshort8_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int16x8, vec_bshort8_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_uint32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_float32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_float64x2, vec_bdword2_c) + +/** Comparison **/ +#define OPENCV_HAL_IMPL_VSX_INT_CMP_OP(_Tpvec) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpeq(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpne(a.val, b.val)); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmplt(a.val, b.val)); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpgt(a.val, b.val)); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmple(a.val, b.val)); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpge(a.val, b.val)); } + +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint8x16) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int8x16) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint16x8) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int16x8) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_float32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_float64x2) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint64x2) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int64x2) + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(vec_cmpeq(a.val, a.val)); } +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(vec_cmpeq(a.val, a.val)); } + +/** min/max **/ +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_min, vec_min) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_max, vec_max) + +/** Rotate **/ +#define OPENCV_IMPL_VSX_ROTATE(_Tpvec, suffix, shf, cast) \ +template<int imm> \ +inline _Tpvec v_rotate_##suffix(const _Tpvec& a) \ +{ \ + const int wd = imm * sizeof(typename _Tpvec::lane_type); \ + if (wd > 15) \ + return _Tpvec(); \ + return _Tpvec((cast)shf(vec_uchar16_c(a.val), vec_uchar16_sp(wd << 3))); \ +} + +#define OPENCV_IMPL_VSX_ROTATE_LR(_Tpvec, cast) \ +OPENCV_IMPL_VSX_ROTATE(_Tpvec, left, vec_slo, cast) \ +OPENCV_IMPL_VSX_ROTATE(_Tpvec, right, vec_sro, cast) + +OPENCV_IMPL_VSX_ROTATE_LR(v_uint8x16, vec_uchar16) +OPENCV_IMPL_VSX_ROTATE_LR(v_int8x16, vec_char16) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint16x8, vec_ushort8) +OPENCV_IMPL_VSX_ROTATE_LR(v_int16x8, vec_short8) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint32x4, vec_uint4) +OPENCV_IMPL_VSX_ROTATE_LR(v_int32x4, vec_int4) +OPENCV_IMPL_VSX_ROTATE_LR(v_float32x4, vec_float4) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint64x2, vec_udword2) +OPENCV_IMPL_VSX_ROTATE_LR(v_int64x2, vec_dword2) +OPENCV_IMPL_VSX_ROTATE_LR(v_float64x2, vec_double2) + +template<int imm, typename _Tpvec> +inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) +{ + enum { CV_SHIFT = 16 - imm * (sizeof(typename _Tpvec::lane_type)) }; + if (CV_SHIFT == 16) + return a; +#ifdef __IBMCPP__ + return _Tpvec(vec_sld(b.val, a.val, CV_SHIFT & 15)); +#else + return _Tpvec(vec_sld(b.val, a.val, CV_SHIFT)); +#endif +} + +template<int imm, typename _Tpvec> +inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) +{ + enum { CV_SHIFT = imm * (sizeof(typename _Tpvec::lane_type)) }; + if (CV_SHIFT == 16) + return b; + return _Tpvec(vec_sld(a.val, b.val, CV_SHIFT)); +} + +#define OPENCV_IMPL_VSX_ROTATE_64_2RG(_Tpvec, suffix, rg1, rg2) \ +template<int imm> \ +inline _Tpvec v_rotate_##suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + if (imm == 1) \ + return _Tpvec(vec_permi(rg1.val, rg2.val, 2)); \ + return imm ? b : a; \ +} + +#define OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(_Tpvec) \ +OPENCV_IMPL_VSX_ROTATE_64_2RG(_Tpvec, left, b, a) \ +OPENCV_IMPL_VSX_ROTATE_64_2RG(_Tpvec, right, a, b) + +OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(v_float64x2) +OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(v_uint64x2) +OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(v_int64x2) + +/* Extract */ +template<int s, typename _Tpvec> +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) +{ return v_rotate_right<s>(a, b); } + +////////// Reduce and mask ///////// + +/** Reduce **/ +inline short v_reduce_sum(const v_int16x8& a) +{ + const vec_int4 zero = vec_int4_z; + return saturate_cast<short>(vec_extract(vec_sums(vec_sum4s(a.val, zero), zero), 3)); +} +inline ushort v_reduce_sum(const v_uint16x8& a) +{ + const vec_int4 v4 = vec_int4_c(vec_unpackhu(vec_adds(a.val, vec_sld(a.val, a.val, 8)))); + return saturate_cast<ushort>(vec_extract(vec_sums(v4, vec_int4_z), 3)); +} + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + const _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 4)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, min, vec_min) + +inline double v_reduce_sum(const v_float64x2& a) +{ + return vec_extract(vec_add(a.val, vec_permi(a.val, a.val, 3)), 0); +} + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + rs = func(rs, vec_sld(rs, rs, 4)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 2)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_uint16x8, vec_ushort8, ushort, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_uint16x8, vec_ushort8, ushort, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_int16x8, vec_short8, short, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_int16x8, vec_short8, short, min, vec_min) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + vec_float4 ac = vec_add(vec_mergel(a.val, c.val), vec_mergeh(a.val, c.val)); + ac = vec_add(ac, vec_sld(ac, ac, 8)); + + vec_float4 bd = vec_add(vec_mergel(b.val, d.val), vec_mergeh(b.val, d.val)); + bd = vec_add(bd, vec_sld(bd, bd, 8)); + return v_float32x4(vec_mergeh(ac, bd)); +} + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + const vec_uint4 zero4 = vec_uint4_z; + vec_uint4 sum4 = vec_sum4s(vec_absd(a.val, b.val), zero4); + return (unsigned)vec_extract(vec_sums(vec_int4_c(sum4), vec_int4_c(zero4)), 3); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + const vec_int4 zero4 = vec_int4_z; + vec_char16 ad = vec_abss(vec_subs(a.val, b.val)); + vec_int4 sum4 = vec_sum4s(ad, zero4); + return (unsigned)vec_extract(vec_sums(sum4, zero4), 3); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + vec_ushort8 ad = vec_absd(a.val, b.val); + VSX_UNUSED(vec_int4) sum = vec_sums(vec_int4_c(vec_unpackhu(ad)), vec_int4_c(vec_unpacklu(ad))); + return (unsigned)vec_extract(sum, 3); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + const vec_int4 zero4 = vec_int4_z; + vec_short8 ad = vec_abss(vec_subs(a.val, b.val)); + vec_int4 sum4 = vec_sum4s(ad, zero4); + return (unsigned)vec_extract(vec_sums(sum4, zero4), 3); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + const vec_uint4 ad = vec_absd(a.val, b.val); + const vec_uint4 rd = vec_add(ad, vec_sld(ad, ad, 8)); + return vec_extract(vec_add(rd, vec_sld(rd, rd, 4)), 0); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + vec_int4 ad = vec_abss(vec_sub(a.val, b.val)); + return (unsigned)vec_extract(vec_sums(ad, vec_int4_z), 3); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + const vec_float4 ad = vec_abs(vec_sub(a.val, b.val)); + const vec_float4 rd = vec_add(ad, vec_sld(ad, ad, 8)); + return vec_extract(vec_add(rd, vec_sld(rd, rd, 4)), 0); +} + +/** Popcount **/ +template<typename _Tpvec> +inline v_uint32x4 v_popcount(const _Tpvec& a) +{ return v_uint32x4(vec_popcntu(vec_uint4_c(a.val))); } + +/** Mask **/ +inline int v_signmask(const v_uint8x16& a) +{ + vec_uchar16 sv = vec_sr(a.val, vec_uchar16_sp(7)); + static const vec_uchar16 slm = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}; + sv = vec_sl(sv, slm); + vec_uint4 sv4 = vec_sum4s(sv, vec_uint4_z); + static const vec_uint4 slm4 = {0, 0, 8, 8}; + sv4 = vec_sl(sv4, slm4); + return vec_extract(vec_sums((vec_int4) sv4, vec_int4_z), 3); +} +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } + +inline int v_signmask(const v_int16x8& a) +{ + static const vec_ushort8 slm = {0, 1, 2, 3, 4, 5, 6, 7}; + vec_short8 sv = vec_sr(a.val, vec_ushort8_sp(15)); + sv = vec_sl(sv, slm); + vec_int4 svi = vec_int4_z; + svi = vec_sums(vec_sum4s(sv, svi), svi); + return vec_extract(svi, 3); +} +inline int v_signmask(const v_uint16x8& a) +{ return v_signmask(v_reinterpret_as_s16(a)); } + +inline int v_signmask(const v_int32x4& a) +{ + static const vec_uint4 slm = {0, 1, 2, 3}; + vec_int4 sv = vec_sr(a.val, vec_uint4_sp(31)); + sv = vec_sl(sv, slm); + sv = vec_sums(sv, vec_int4_z); + return vec_extract(sv, 3); +} +inline int v_signmask(const v_uint32x4& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } + +inline int v_signmask(const v_int64x2& a) +{ + VSX_UNUSED(const vec_dword2) sv = vec_sr(a.val, vec_udword2_sp(63)); + return (int)vec_extract(sv, 0) | (int)vec_extract(sv, 1) << 1; +} +inline int v_signmask(const v_uint64x2& a) +{ return v_signmask(v_reinterpret_as_s64(a)); } +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_s64(a)); } + +template<typename _Tpvec> +inline bool v_check_all(const _Tpvec& a) +{ return vec_all_lt(a.val, _Tpvec().val); } +inline bool v_check_all(const v_uint8x16& a) +{ return v_check_all(v_reinterpret_as_s8(a)); } +inline bool v_check_all(const v_uint16x8& a) +{ return v_check_all(v_reinterpret_as_s16(a)); } +inline bool v_check_all(const v_uint32x4& a) +{ return v_check_all(v_reinterpret_as_s32(a)); } +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_s32(a)); } +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_s64(a)); } + +template<typename _Tpvec> +inline bool v_check_any(const _Tpvec& a) +{ return vec_any_lt(a.val, _Tpvec().val); } +inline bool v_check_any(const v_uint8x16& a) +{ return v_check_any(v_reinterpret_as_s8(a)); } +inline bool v_check_any(const v_uint16x8& a) +{ return v_check_any(v_reinterpret_as_s16(a)); } +inline bool v_check_any(const v_uint32x4& a) +{ return v_check_any(v_reinterpret_as_s32(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_s32(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_s64(a)); } + +////////// Other math ///////// + +/** Some frequent operations **/ +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ return v_float32x4(vec_sqrt(x.val)); } +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ return v_float64x2(vec_sqrt(x.val)); } + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ return v_float32x4(vec_rsqrt(x.val)); } +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ return v_float64x2(vec_rsqrt(x.val)); } + +#define OPENCV_HAL_IMPL_VSX_MULADD(_Tpvec) \ +inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_sqrt(vec_madd(a.val, a.val, vec_mul(b.val, b.val)))); } \ +inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_madd(a.val, a.val, vec_mul(b.val, b.val))); } \ +inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ return _Tpvec(vec_madd(a.val, b.val, c.val)); } \ +inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ return _Tpvec(vec_madd(a.val, b.val, c.val)); } + +OPENCV_HAL_IMPL_VSX_MULADD(v_float32x4) +OPENCV_HAL_IMPL_VSX_MULADD(v_float64x2) + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ return a * b + c; } + +// TODO: exp, log, sin, cos + +/** Absolute values **/ +inline v_uint8x16 v_abs(const v_int8x16& x) +{ return v_uint8x16(vec_uchar16_c(vec_abs(x.val))); } + +inline v_uint16x8 v_abs(const v_int16x8& x) +{ return v_uint16x8(vec_ushort8_c(vec_abs(x.val))); } + +inline v_uint32x4 v_abs(const v_int32x4& x) +{ return v_uint32x4(vec_uint4_c(vec_abs(x.val))); } + +inline v_float32x4 v_abs(const v_float32x4& x) +{ return v_float32x4(vec_abs(x.val)); } + +inline v_float64x2 v_abs(const v_float64x2& x) +{ return v_float64x2(vec_abs(x.val)); } + +/** Absolute difference **/ +// unsigned +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_absdiff, vec_absd) + +inline v_uint8x16 v_absdiff(const v_int8x16& a, const v_int8x16& b) +{ return v_reinterpret_as_u8(v_sub_wrap(v_max(a, b), v_min(a, b))); } +inline v_uint16x8 v_absdiff(const v_int16x8& a, const v_int16x8& b) +{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); } +inline v_uint32x4 v_absdiff(const v_int32x4& a, const v_int32x4& b) +{ return v_reinterpret_as_u32(v_max(a, b) - v_min(a, b)); } + +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ return v_abs(a - b); } +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ return v_abs(a - b); } + +/** Absolute difference for signed integers **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ return v_int8x16(vec_abss(vec_subs(a.val, b.val))); } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_int16x8(vec_abss(vec_subs(a.val, b.val))); } + +////////// Conversions ///////// + +/** Rounding **/ +inline v_int32x4 v_round(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_rint(a.val))); } + +inline v_int32x4 v_round(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_rint(a.val)), vec_int4_z)); } + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_rint(a.val)), vec_ctso(vec_rint(b.val)))); } + +inline v_int32x4 v_floor(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_floor(a.val))); } + +inline v_int32x4 v_floor(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_floor(a.val)), vec_int4_z)); } + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_ceil(a.val))); } + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_ceil(a.val)), vec_int4_z)); } + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(vec_cts(a.val)); } + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(a.val), vec_int4_z)); } + +/** To float **/ +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ return v_float32x4(vec_ctf(a.val)); } + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ return v_float32x4(vec_mergesqo(vec_cvfo(a.val), vec_float4_z)); } + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ return v_float32x4(vec_mergesqo(vec_cvfo(a.val), vec_cvfo(b.val))); } + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ return v_float64x2(vec_ctdo(vec_mergeh(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ return v_float64x2(vec_ctdo(vec_mergel(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ return v_float64x2(vec_cvfo(vec_mergeh(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ return v_float64x2(vec_cvfo(vec_mergel(a.val, a.val))); } + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + return v_int8x16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + return v_reinterpret_as_s8(v_int16x8(*(const short*)(tab+idx[0]), *(const short*)(tab+idx[1]), *(const short*)(tab+idx[2]), *(const short*)(tab+idx[3]), + *(const short*)(tab+idx[4]), *(const short*)(tab+idx[5]), *(const short*)(tab+idx[6]), *(const short*)(tab+idx[7]))); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + return v_reinterpret_as_s8(v_int32x4(*(const int*)(tab+idx[0]), *(const int*)(tab+idx[1]), *(const int*)(tab+idx[2]), *(const int*)(tab+idx[3]))); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((const schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((const schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((const schar*)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + return v_int16x8(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + return v_reinterpret_as_s16(v_int32x4(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1]), *(const int*)(tab + idx[2]), *(const int*)(tab + idx[3]))); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_reinterpret_as_s16(v_int64x2(*(const int64*)(tab + idx[0]), *(const int64*)(tab + idx[1]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((const short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((const short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((const short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + return v_int32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_reinterpret_as_s32(v_int64x2(*(const int64*)(tab + idx[0]), *(const int64*)(tab + idx[1]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(vsx_ld(0, tab + idx[0])); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((const int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((const int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((const int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(tab[idx[0]], tab[idx[1]]); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(vsx_ld2(0, tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_pairs((const int*)tab, idx)); } +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) { return v_load(tab + *idx); } + +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + return v_float64x2(tab[idx[0]], tab[idx[1]]); +} +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) { return v_load(tab + *idx); } + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + const int idx[4] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1), + vec_extract(idxvec.val, 2), + vec_extract(idxvec.val, 3) + }; + return v_int32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + const int idx[4] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1), + vec_extract(idxvec.val, 2), + vec_extract(idxvec.val, 3) + }; + return v_uint32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + const int idx[4] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1), + vec_extract(idxvec.val, 2), + vec_extract(idxvec.val, 3) + }; + return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + const int idx[2] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1) + }; + return v_float64x2(tab[idx[0]], tab[idx[1]]); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + vec_float4 xy0 = vec_ld_l8(tab + vec_extract(idxvec.val, 0)); + vec_float4 xy1 = vec_ld_l8(tab + vec_extract(idxvec.val, 1)); + vec_float4 xy2 = vec_ld_l8(tab + vec_extract(idxvec.val, 2)); + vec_float4 xy3 = vec_ld_l8(tab + vec_extract(idxvec.val, 3)); + vec_float4 xy02 = vec_mergeh(xy0, xy2); // x0, x2, y0, y2 + vec_float4 xy13 = vec_mergeh(xy1, xy3); // x1, x3, y1, y3 + x.val = vec_mergeh(xy02, xy13); + y.val = vec_mergel(xy02, xy13); +} +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + vec_double2 xy0 = vsx_ld(vec_extract(idxvec.val, 0), tab); + vec_double2 xy1 = vsx_ld(vec_extract(idxvec.val, 1), tab); + x.val = vec_mergeh(xy0, xy1); + y.val = vec_mergel(xy0, xy1); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + static const vec_uchar16 perm = {0, 2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15}; + return v_int8x16(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } + +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + static const vec_uchar16 perm = {0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15}; + return v_int8x16(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + static const vec_uchar16 perm = {0,1, 4,5, 2,3, 6,7, 8,9, 12,13, 10,11, 14,15}; + return v_int16x8(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) +{ return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } + +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + static const vec_uchar16 perm = {0,1, 8,9, 2,3, 10,11, 4,5, 12,13, 6,7, 14,15}; + return v_int16x8(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) +{ return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + static const vec_uchar16 perm = {0,1,2,3, 8,9,10,11, 4,5,6,7, 12,13,14,15}; + return v_int32x4(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) +{ return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) +{ return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + static const vec_uchar16 perm = {0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, 15, 15, 15}; + return v_int8x16(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + static const vec_uchar16 perm = {0,1, 2,3, 4,5, 8,9, 10,11, 12,13, 14,15, 14,15}; + return v_int16x8(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) +{ return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) +{ return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) +{ return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) +{ return vec; } + +/////// FP16 support //////// + +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + vec_ushort8 vf16 = vec_ld_l8((const ushort*)ptr); +#if CV_VSX3 && defined(vec_extract_fp_from_shorth) + return v_float32x4(vec_extract_fp_from_shorth(vf16)); +#elif CV_VSX3 && !defined(CV_COMPILER_VSX_BROKEN_ASM) + vec_float4 vf32; + __asm__ __volatile__ ("xvcvhpsp %x0,%x1" : "=wf" (vf32) : "wa" (vec_mergeh(vf16, vf16))); + return v_float32x4(vf32); +#else + const vec_int4 z = vec_int4_z, delta = vec_int4_sp(0x38000000); + const vec_int4 signmask = vec_int4_sp(0x80000000); + const vec_int4 maxexp = vec_int4_sp(0x7c000000); + const vec_float4 deltaf = vec_float4_c(vec_int4_sp(0x38800000)); + + vec_int4 bits = vec_int4_c(vec_mergeh(vec_short8_c(z), vec_short8_c(vf16))); + vec_int4 e = vec_and(bits, maxexp), sign = vec_and(bits, signmask); + vec_int4 t = vec_add(vec_sr(vec_xor(bits, sign), vec_uint4_sp(3)), delta); // ((h & 0x7fff) << 13) + delta + vec_int4 zt = vec_int4_c(vec_sub(vec_float4_c(vec_add(t, vec_int4_sp(1 << 23))), deltaf)); + + t = vec_add(t, vec_and(delta, vec_cmpeq(maxexp, e))); + vec_bint4 zmask = vec_cmpeq(e, z); + vec_int4 ft = vec_sel(t, zt, zmask); + return v_float32x4(vec_float4_c(vec_or(ft, sign))); +#endif +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ +// fixme: Is there any buitin op or intrinsic that cover "xvcvsphp"? +#if CV_VSX3 && !defined(CV_COMPILER_VSX_BROKEN_ASM) + vec_ushort8 vf16; + __asm__ __volatile__ ("xvcvsphp %x0,%x1" : "=wa" (vf16) : "wf" (v.val)); + vec_st_l8(vec_mergesqe(vf16, vf16), ptr); +#else + const vec_int4 signmask = vec_int4_sp(0x80000000); + const vec_int4 rval = vec_int4_sp(0x3f000000); + + vec_int4 t = vec_int4_c(v.val); + vec_int4 sign = vec_sra(vec_and(t, signmask), vec_uint4_sp(16)); + t = vec_and(vec_nor(signmask, signmask), t); + + vec_bint4 finitemask = vec_cmpgt(vec_int4_sp(0x47800000), t); + vec_bint4 isnan = vec_cmpgt(t, vec_int4_sp(0x7f800000)); + vec_int4 naninf = vec_sel(vec_int4_sp(0x7c00), vec_int4_sp(0x7e00), isnan); + vec_bint4 tinymask = vec_cmpgt(vec_int4_sp(0x38800000), t); + vec_int4 tt = vec_int4_c(vec_add(vec_float4_c(t), vec_float4_c(rval))); + tt = vec_sub(tt, rval); + vec_int4 odd = vec_and(vec_sr(t, vec_uint4_sp(13)), vec_int4_sp(1)); + vec_int4 nt = vec_add(t, vec_int4_sp(0xc8000fff)); + nt = vec_sr(vec_add(nt, odd), vec_uint4_sp(13)); + t = vec_sel(nt, tt, tinymask); + t = vec_sel(naninf, t, finitemask); + t = vec_or(t, sign); + vec_st_l8(vec_packs(t, t), ptr); +#endif +} + +inline void v_cleanup() {} + + +/** Reinterpret **/ +/** its up there with load and store operations **/ + +////////// Matrix operations ///////// + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ return v_int32x4(vec_msum(a.val, b.val, vec_int4_z)); } + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_int32x4(vec_msum(a.val, b.val, c.val)); } + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + const vec_float4 v0 = vec_splat(v.val, 0); + const vec_float4 v1 = vec_splat(v.val, 1); + const vec_float4 v2 = vec_splat(v.val, 2); + VSX_UNUSED(const vec_float4) v3 = vec_splat(v.val, 3); + return v_float32x4(vec_madd(v0, m0.val, vec_madd(v1, m1.val, vec_madd(v2, m2.val, vec_mul(v3, m3.val))))); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + const vec_float4 v0 = vec_splat(v.val, 0); + const vec_float4 v1 = vec_splat(v.val, 1); + const vec_float4 v2 = vec_splat(v.val, 2); + return v_float32x4(vec_madd(v0, m0.val, vec_madd(v1, m1.val, vec_madd(v2, m2.val, a.val)))); +} + +#define OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(_Tpvec, _Tpvec2) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \ +{ \ + _Tpvec2 a02 = vec_mergeh(a0.val, a2.val); \ + _Tpvec2 a13 = vec_mergeh(a1.val, a3.val); \ + b0.val = vec_mergeh(a02, a13); \ + b1.val = vec_mergel(a02, a13); \ + a02 = vec_mergel(a0.val, a2.val); \ + a13 = vec_mergel(a1.val, a3.val); \ + b2.val = vec_mergeh(a02, a13); \ + b3.val = vec_mergel(a02, a13); \ +} +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_uint32x4, vec_uint4) +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_int32x4, vec_int4) +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_float32x4, vec_float4) + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return (CV_CPU_HAS_SUPPORT_VSX) ? true : false; +} + +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif // OPENCV_HAL_VSX_HPP diff --git a/include/opencv2/core/ippasync.hpp b/include/opencv2/core/ippasync.hpp new file mode 100644 index 0000000..c35d8d8 --- /dev/null +++ b/include/opencv2/core/ippasync.hpp @@ -0,0 +1,195 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_IPPASYNC_HPP +#define OPENCV_CORE_IPPASYNC_HPP + +#ifdef HAVE_IPP_A // this file will be removed in OpenCV 4.0 + +#include "opencv2/core.hpp" +#include <ipp_async_op.h> +#include <ipp_async_accel.h> + +namespace cv +{ + +namespace hpp +{ + +/** @addtogroup core_ipp +This section describes conversion between OpenCV and [Intel® IPP Asynchronous +C/C++](http://software.intel.com/en-us/intel-ipp-preview) library. [Getting Started +Guide](http://registrationcenter.intel.com/irc_nas/3727/ipp_async_get_started.htm) help you to +install the library, configure header and library build paths. + */ +//! @{ + + //! convert OpenCV data type to hppDataType + inline int toHppType(const int cvType) + { + int depth = CV_MAT_DEPTH(cvType); + int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U : + depth == CV_16U ? HPP_DATA_TYPE_16U : + depth == CV_16S ? HPP_DATA_TYPE_16S : + depth == CV_32S ? HPP_DATA_TYPE_32S : + depth == CV_32F ? HPP_DATA_TYPE_32F : + depth == CV_64F ? HPP_DATA_TYPE_64F : -1; + CV_Assert( hppType >= 0 ); + return hppType; + } + + //! convert hppDataType to OpenCV data type + inline int toCvType(const int hppType) + { + int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U : + hppType == HPP_DATA_TYPE_16U ? CV_16U : + hppType == HPP_DATA_TYPE_16S ? CV_16S : + hppType == HPP_DATA_TYPE_32S ? CV_32S : + hppType == HPP_DATA_TYPE_32F ? CV_32F : + hppType == HPP_DATA_TYPE_64F ? CV_64F : -1; + CV_Assert( cvType >= 0 ); + return cvType; + } + + /** @brief Convert hppiMatrix to Mat. + + This function allocates and initializes new matrix (if needed) that has the same size and type as + input matrix. Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. + @param src input hppiMatrix. + @param dst output matrix. + @param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types). + @param cn number of channels. + */ + inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn) + { + hppDataType type; + hpp32u width, height; + hppStatus sts; + + if (src == NULL) + return dst.release(); + + sts = hppiInquireMatrix(src, &type, &width, &height); + + CV_Assert( sts == HPP_STATUS_NO_ERROR); + + int matType = CV_MAKETYPE(toCvType(type), cn); + + CV_Assert(width%cn == 0); + + width /= cn; + + dst.create((int)height, (int)width, (int)matType); + + size_t newSize = (size_t)(height*(hpp32u)(dst.step)); + + sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize); + + CV_Assert( sts == HPP_STATUS_NO_ERROR); + } + + /** @brief Create Mat from hppiMatrix. + + This function allocates and initializes the Mat that has the same size and type as input matrix. + Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. + @param src input hppiMatrix. + @param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types). + @param cn number of channels. + @sa howToUseIPPAconversion, hpp::copyHppToMat, hpp::getHpp. + */ + inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn) + { + Mat dst; + copyHppToMat(src, dst, accel, cn); + return dst; + } + + /** @brief Create hppiMatrix from Mat. + + This function allocates and initializes the hppiMatrix that has the same size and type as input + matrix, returns the hppiMatrix*. + + If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details + [hppiCreateSharedMatrix](http://software.intel.com/ru-ru/node/501697). + + Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. + + @note The hppiMatrix pointer to the image buffer in system memory refers to the src.data. Control + the lifetime of the matrix and don't change its data, if there is no special need. + @param src input matrix. + @param accel accelerator instance. Supports type: + - **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions. + - **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function + accelerators. + - **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available. + @sa howToUseIPPAconversion, hpp::getMat + */ + inline hppiMatrix* getHpp(const Mat& src, hppAccel accel) + { + int htype = toHppType(src.type()); + int cn = src.channels(); + + CV_Assert(src.data); + hppAccelType accelType = hppQueryAccelType(accel); + + if (accelType!=HPP_ACCEL_TYPE_CPU) + { + hpp32u pitch, size; + hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size); + if (pitch!=0 && size!=0) + if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step)) + { + return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size); + } + } + + return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));; + } + +//! @} +}} + +#endif + +#endif diff --git a/include/opencv2/core/mat.hpp b/include/opencv2/core/mat.hpp new file mode 100644 index 0000000..2c23a2a --- /dev/null +++ b/include/opencv2/core/mat.hpp @@ -0,0 +1,3761 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_MAT_HPP +#define OPENCV_CORE_MAT_HPP + +#ifndef __cplusplus +# error mat.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/matx.hpp" +#include "opencv2/core/types.hpp" + +#include "opencv2/core/bufferpool.hpp" + +#ifdef CV_CXX11 +#include <type_traits> +#endif + +namespace cv +{ + +//! @addtogroup core_basic +//! @{ + +enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, + ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 }; + +CV__DEBUG_NS_BEGIN + +class CV_EXPORTS _OutputArray; + +//////////////////////// Input/Output Array Arguments ///////////////////////////////// + +/** @brief This is the proxy class for passing read-only input arrays into OpenCV functions. + +It is defined as: +@code + typedef const _InputArray& InputArray; +@endcode +where _InputArray is a class that can be constructed from `Mat`, `Mat_<T>`, `Matx<T, m, n>`, +`std::vector<T>`, `std::vector<std::vector<T> >`, `std::vector<Mat>`, `std::vector<Mat_<T> >`, +`UMat`, `std::vector<UMat>` or `double`. It can also be constructed from a matrix expression. + +Since this is mostly implementation-level class, and its interface may change in future versions, we +do not describe it in details. There are a few key things, though, that should be kept in mind: + +- When you see in the reference manual or in OpenCV source code a function that takes + InputArray, it means that you can actually pass `Mat`, `Matx`, `vector<T>` etc. (see above the + complete list). +- Optional input arguments: If some of the input arrays may be empty, pass cv::noArray() (or + simply cv::Mat() as you probably did before). +- The class is designed solely for passing parameters. That is, normally you *should not* + declare class members, local and global variables of this type. +- If you want to design your own function or a class method that can operate of arrays of + multiple types, you can use InputArray (or OutputArray) for the respective parameters. Inside + a function you should use _InputArray::getMat() method to construct a matrix header for the + array (without copying data). _InputArray::kind() can be used to distinguish Mat from + `vector<>` etc., but normally it is not needed. + +Here is how you can use a function that takes InputArray : +@code + std::vector<Point2f> vec; + // points or a circle + for( int i = 0; i < 30; i++ ) + vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)), + (float)(100 - 30*sin(i*CV_PI*2/5)))); + cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20)); +@endcode +That is, we form an STL vector containing points, and apply in-place affine transformation to the +vector using the 2x3 matrix created inline as `Matx<float, 2, 3>` instance. + +Here is how such a function can be implemented (for simplicity, we implement a very specific case of +it, according to the assertion statement inside) : +@code + void myAffineTransform(InputArray _src, OutputArray _dst, InputArray _m) + { + // get Mat headers for input arrays. This is O(1) operation, + // unless _src and/or _m are matrix expressions. + Mat src = _src.getMat(), m = _m.getMat(); + CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() == Size(3, 2) ); + + // [re]create the output array so that it has the proper size and type. + // In case of Mat it calls Mat::create, in case of STL vector it calls vector::resize. + _dst.create(src.size(), src.type()); + Mat dst = _dst.getMat(); + + for( int i = 0; i < src.rows; i++ ) + for( int j = 0; j < src.cols; j++ ) + { + Point2f pt = src.at<Point2f>(i, j); + dst.at<Point2f>(i, j) = Point2f(m.at<float>(0, 0)*pt.x + + m.at<float>(0, 1)*pt.y + + m.at<float>(0, 2), + m.at<float>(1, 0)*pt.x + + m.at<float>(1, 1)*pt.y + + m.at<float>(1, 2)); + } + } +@endcode +There is another related type, InputArrayOfArrays, which is currently defined as a synonym for +InputArray: +@code + typedef InputArray InputArrayOfArrays; +@endcode +It denotes function arguments that are either vectors of vectors or vectors of matrices. A separate +synonym is needed to generate Python/Java etc. wrappers properly. At the function implementation +level their use is similar, but _InputArray::getMat(idx) should be used to get header for the +idx-th component of the outer vector and _InputArray::size().area() should be used to find the +number of components (vectors/matrices) of the outer vector. + +In general, type support is limited to cv::Mat types. Other types are forbidden. +But in some cases we need to support passing of custom non-general Mat types, like arrays of cv::KeyPoint, cv::DMatch, etc. +This data is not intented to be interpreted as an image data, or processed somehow like regular cv::Mat. +To pass such custom type use rawIn() / rawOut() / rawInOut() wrappers. +Custom type is wrapped as Mat-compatible `CV_8UC<N>` values (N = sizeof(T), N <= CV_CN_MAX). + */ +class CV_EXPORTS _InputArray +{ +public: + enum { + KIND_SHIFT = 16, + FIXED_TYPE = 0x8000 << KIND_SHIFT, + FIXED_SIZE = 0x4000 << KIND_SHIFT, + KIND_MASK = 31 << KIND_SHIFT, + + NONE = 0 << KIND_SHIFT, + MAT = 1 << KIND_SHIFT, + MATX = 2 << KIND_SHIFT, + STD_VECTOR = 3 << KIND_SHIFT, + STD_VECTOR_VECTOR = 4 << KIND_SHIFT, + STD_VECTOR_MAT = 5 << KIND_SHIFT, + EXPR = 6 << KIND_SHIFT, + OPENGL_BUFFER = 7 << KIND_SHIFT, + CUDA_HOST_MEM = 8 << KIND_SHIFT, + CUDA_GPU_MAT = 9 << KIND_SHIFT, + UMAT =10 << KIND_SHIFT, + STD_VECTOR_UMAT =11 << KIND_SHIFT, + STD_BOOL_VECTOR =12 << KIND_SHIFT, + STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT, + STD_ARRAY =14 << KIND_SHIFT, + STD_ARRAY_MAT =15 << KIND_SHIFT + }; + + _InputArray(); + _InputArray(int _flags, void* _obj); + _InputArray(const Mat& m); + _InputArray(const MatExpr& expr); + _InputArray(const std::vector<Mat>& vec); + template<typename _Tp> _InputArray(const Mat_<_Tp>& m); + template<typename _Tp> _InputArray(const std::vector<_Tp>& vec); + _InputArray(const std::vector<bool>& vec); + template<typename _Tp> _InputArray(const std::vector<std::vector<_Tp> >& vec); + _InputArray(const std::vector<std::vector<bool> >&); + template<typename _Tp> _InputArray(const std::vector<Mat_<_Tp> >& vec); + template<typename _Tp> _InputArray(const _Tp* vec, int n); + template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx); + _InputArray(const double& val); + _InputArray(const cuda::GpuMat& d_mat); + _InputArray(const std::vector<cuda::GpuMat>& d_mat_array); + _InputArray(const ogl::Buffer& buf); + _InputArray(const cuda::HostMem& cuda_mem); + template<typename _Tp> _InputArray(const cudev::GpuMat_<_Tp>& m); + _InputArray(const UMat& um); + _InputArray(const std::vector<UMat>& umv); + +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> _InputArray(const std::array<_Tp, _Nm>& arr); + template<std::size_t _Nm> _InputArray(const std::array<Mat, _Nm>& arr); +#endif + + template<typename _Tp> static _InputArray rawIn(const std::vector<_Tp>& vec); +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> static _InputArray rawIn(const std::array<_Tp, _Nm>& arr); +#endif + + Mat getMat(int idx=-1) const; + Mat getMat_(int idx=-1) const; + UMat getUMat(int idx=-1) const; + void getMatVector(std::vector<Mat>& mv) const; + void getUMatVector(std::vector<UMat>& umv) const; + void getGpuMatVector(std::vector<cuda::GpuMat>& gpumv) const; + cuda::GpuMat getGpuMat() const; + ogl::Buffer getOGlBuffer() const; + + int getFlags() const; + void* getObj() const; + Size getSz() const; + + int kind() const; + int dims(int i=-1) const; + int cols(int i=-1) const; + int rows(int i=-1) const; + Size size(int i=-1) const; + int sizend(int* sz, int i=-1) const; + bool sameSize(const _InputArray& arr) const; + size_t total(int i=-1) const; + int type(int i=-1) const; + int depth(int i=-1) const; + int channels(int i=-1) const; + bool isContinuous(int i=-1) const; + bool isSubmatrix(int i=-1) const; + bool empty() const; + void copyTo(const _OutputArray& arr) const; + void copyTo(const _OutputArray& arr, const _InputArray & mask) const; + size_t offset(int i=-1) const; + size_t step(int i=-1) const; + bool isMat() const; + bool isUMat() const; + bool isMatVector() const; + bool isUMatVector() const; + bool isMatx() const; + bool isVector() const; + bool isGpuMat() const; + bool isGpuMatVector() const; + ~_InputArray(); + +protected: + int flags; + void* obj; + Size sz; + + void init(int _flags, const void* _obj); + void init(int _flags, const void* _obj, Size _sz); +}; + + +/** @brief This type is very similar to InputArray except that it is used for input/output and output function +parameters. + +Just like with InputArray, OpenCV users should not care about OutputArray, they just pass `Mat`, +`vector<T>` etc. to the functions. The same limitation as for `InputArray`: *Do not explicitly +create OutputArray instances* applies here too. + +If you want to make your function polymorphic (i.e. accept different arrays as output parameters), +it is also not very difficult. Take the sample above as the reference. Note that +_OutputArray::create() needs to be called before _OutputArray::getMat(). This way you guarantee +that the output array is properly allocated. + +Optional output parameters. If you do not need certain output array to be computed and returned to +you, pass cv::noArray(), just like you would in the case of optional input array. At the +implementation level, use _OutputArray::needed() to check if certain output array needs to be +computed or not. + +There are several synonyms for OutputArray that are used to assist automatic Python/Java/... wrapper +generators: +@code + typedef OutputArray OutputArrayOfArrays; + typedef OutputArray InputOutputArray; + typedef OutputArray InputOutputArrayOfArrays; +@endcode + */ +class CV_EXPORTS _OutputArray : public _InputArray +{ +public: + enum + { + DEPTH_MASK_8U = 1 << CV_8U, + DEPTH_MASK_8S = 1 << CV_8S, + DEPTH_MASK_16U = 1 << CV_16U, + DEPTH_MASK_16S = 1 << CV_16S, + DEPTH_MASK_32S = 1 << CV_32S, + DEPTH_MASK_32F = 1 << CV_32F, + DEPTH_MASK_64F = 1 << CV_64F, + DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1, + DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S, + DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F + }; + + _OutputArray(); + _OutputArray(int _flags, void* _obj); + _OutputArray(Mat& m); + _OutputArray(std::vector<Mat>& vec); + _OutputArray(cuda::GpuMat& d_mat); + _OutputArray(std::vector<cuda::GpuMat>& d_mat); + _OutputArray(ogl::Buffer& buf); + _OutputArray(cuda::HostMem& cuda_mem); + template<typename _Tp> _OutputArray(cudev::GpuMat_<_Tp>& m); + template<typename _Tp> _OutputArray(std::vector<_Tp>& vec); + _OutputArray(std::vector<bool>& vec); + template<typename _Tp> _OutputArray(std::vector<std::vector<_Tp> >& vec); + _OutputArray(std::vector<std::vector<bool> >&); + template<typename _Tp> _OutputArray(std::vector<Mat_<_Tp> >& vec); + template<typename _Tp> _OutputArray(Mat_<_Tp>& m); + template<typename _Tp> _OutputArray(_Tp* vec, int n); + template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx); + _OutputArray(UMat& m); + _OutputArray(std::vector<UMat>& vec); + + _OutputArray(const Mat& m); + _OutputArray(const std::vector<Mat>& vec); + _OutputArray(const cuda::GpuMat& d_mat); + _OutputArray(const std::vector<cuda::GpuMat>& d_mat); + _OutputArray(const ogl::Buffer& buf); + _OutputArray(const cuda::HostMem& cuda_mem); + template<typename _Tp> _OutputArray(const cudev::GpuMat_<_Tp>& m); + template<typename _Tp> _OutputArray(const std::vector<_Tp>& vec); + template<typename _Tp> _OutputArray(const std::vector<std::vector<_Tp> >& vec); + template<typename _Tp> _OutputArray(const std::vector<Mat_<_Tp> >& vec); + template<typename _Tp> _OutputArray(const Mat_<_Tp>& m); + template<typename _Tp> _OutputArray(const _Tp* vec, int n); + template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx); + _OutputArray(const UMat& m); + _OutputArray(const std::vector<UMat>& vec); + +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> _OutputArray(std::array<_Tp, _Nm>& arr); + template<typename _Tp, std::size_t _Nm> _OutputArray(const std::array<_Tp, _Nm>& arr); + template<std::size_t _Nm> _OutputArray(std::array<Mat, _Nm>& arr); + template<std::size_t _Nm> _OutputArray(const std::array<Mat, _Nm>& arr); +#endif + + template<typename _Tp> static _OutputArray rawOut(std::vector<_Tp>& vec); +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> static _OutputArray rawOut(std::array<_Tp, _Nm>& arr); +#endif + + bool fixedSize() const; + bool fixedType() const; + bool needed() const; + Mat& getMatRef(int i=-1) const; + UMat& getUMatRef(int i=-1) const; + cuda::GpuMat& getGpuMatRef() const; + std::vector<cuda::GpuMat>& getGpuMatVecRef() const; + ogl::Buffer& getOGlBufferRef() const; + cuda::HostMem& getHostMemRef() const; + void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; + void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; + void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; + void createSameSize(const _InputArray& arr, int mtype) const; + void release() const; + void clear() const; + void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const; + + void assign(const UMat& u) const; + void assign(const Mat& m) const; + + void assign(const std::vector<UMat>& v) const; + void assign(const std::vector<Mat>& v) const; +}; + + +class CV_EXPORTS _InputOutputArray : public _OutputArray +{ +public: + _InputOutputArray(); + _InputOutputArray(int _flags, void* _obj); + _InputOutputArray(Mat& m); + _InputOutputArray(std::vector<Mat>& vec); + _InputOutputArray(cuda::GpuMat& d_mat); + _InputOutputArray(ogl::Buffer& buf); + _InputOutputArray(cuda::HostMem& cuda_mem); + template<typename _Tp> _InputOutputArray(cudev::GpuMat_<_Tp>& m); + template<typename _Tp> _InputOutputArray(std::vector<_Tp>& vec); + _InputOutputArray(std::vector<bool>& vec); + template<typename _Tp> _InputOutputArray(std::vector<std::vector<_Tp> >& vec); + template<typename _Tp> _InputOutputArray(std::vector<Mat_<_Tp> >& vec); + template<typename _Tp> _InputOutputArray(Mat_<_Tp>& m); + template<typename _Tp> _InputOutputArray(_Tp* vec, int n); + template<typename _Tp, int m, int n> _InputOutputArray(Matx<_Tp, m, n>& matx); + _InputOutputArray(UMat& m); + _InputOutputArray(std::vector<UMat>& vec); + + _InputOutputArray(const Mat& m); + _InputOutputArray(const std::vector<Mat>& vec); + _InputOutputArray(const cuda::GpuMat& d_mat); + _InputOutputArray(const std::vector<cuda::GpuMat>& d_mat); + _InputOutputArray(const ogl::Buffer& buf); + _InputOutputArray(const cuda::HostMem& cuda_mem); + template<typename _Tp> _InputOutputArray(const cudev::GpuMat_<_Tp>& m); + template<typename _Tp> _InputOutputArray(const std::vector<_Tp>& vec); + template<typename _Tp> _InputOutputArray(const std::vector<std::vector<_Tp> >& vec); + template<typename _Tp> _InputOutputArray(const std::vector<Mat_<_Tp> >& vec); + template<typename _Tp> _InputOutputArray(const Mat_<_Tp>& m); + template<typename _Tp> _InputOutputArray(const _Tp* vec, int n); + template<typename _Tp, int m, int n> _InputOutputArray(const Matx<_Tp, m, n>& matx); + _InputOutputArray(const UMat& m); + _InputOutputArray(const std::vector<UMat>& vec); + +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> _InputOutputArray(std::array<_Tp, _Nm>& arr); + template<typename _Tp, std::size_t _Nm> _InputOutputArray(const std::array<_Tp, _Nm>& arr); + template<std::size_t _Nm> _InputOutputArray(std::array<Mat, _Nm>& arr); + template<std::size_t _Nm> _InputOutputArray(const std::array<Mat, _Nm>& arr); +#endif + + template<typename _Tp> static _InputOutputArray rawInOut(std::vector<_Tp>& vec); +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> _InputOutputArray rawInOut(std::array<_Tp, _Nm>& arr); +#endif + +}; + +/** Helper to wrap custom types. @see InputArray */ +template<typename _Tp> static inline _InputArray rawIn(_Tp& v); +/** Helper to wrap custom types. @see InputArray */ +template<typename _Tp> static inline _OutputArray rawOut(_Tp& v); +/** Helper to wrap custom types. @see InputArray */ +template<typename _Tp> static inline _InputOutputArray rawInOut(_Tp& v); + +CV__DEBUG_NS_END + +typedef const _InputArray& InputArray; +typedef InputArray InputArrayOfArrays; +typedef const _OutputArray& OutputArray; +typedef OutputArray OutputArrayOfArrays; +typedef const _InputOutputArray& InputOutputArray; +typedef InputOutputArray InputOutputArrayOfArrays; + +CV_EXPORTS InputOutputArray noArray(); + +/////////////////////////////////// MatAllocator ////////////////////////////////////// + +//! Usage flags for allocator +enum UMatUsageFlags +{ + USAGE_DEFAULT = 0, + + // buffer allocation policy is platform and usage specific + USAGE_ALLOCATE_HOST_MEMORY = 1 << 0, + USAGE_ALLOCATE_DEVICE_MEMORY = 1 << 1, + USAGE_ALLOCATE_SHARED_MEMORY = 1 << 2, // It is not equal to: USAGE_ALLOCATE_HOST_MEMORY | USAGE_ALLOCATE_DEVICE_MEMORY + + __UMAT_USAGE_FLAGS_32BIT = 0x7fffffff // Binary compatibility hint +}; + +struct CV_EXPORTS UMatData; + +/** @brief Custom array allocator +*/ +class CV_EXPORTS MatAllocator +{ +public: + MatAllocator() {} + virtual ~MatAllocator() {} + + // let's comment it off for now to detect and fix all the uses of allocator + //virtual void allocate(int dims, const int* sizes, int type, int*& refcount, + // uchar*& datastart, uchar*& data, size_t* step) = 0; + //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0; + virtual UMatData* allocate(int dims, const int* sizes, int type, + void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const = 0; + virtual bool allocate(UMatData* data, int accessflags, UMatUsageFlags usageFlags) const = 0; + virtual void deallocate(UMatData* data) const = 0; + virtual void map(UMatData* data, int accessflags) const; + virtual void unmap(UMatData* data) const; + virtual void download(UMatData* data, void* dst, int dims, const size_t sz[], + const size_t srcofs[], const size_t srcstep[], + const size_t dststep[]) const; + virtual void upload(UMatData* data, const void* src, int dims, const size_t sz[], + const size_t dstofs[], const size_t dststep[], + const size_t srcstep[]) const; + virtual void copy(UMatData* srcdata, UMatData* dstdata, int dims, const size_t sz[], + const size_t srcofs[], const size_t srcstep[], + const size_t dstofs[], const size_t dststep[], bool sync) const; + + // default implementation returns DummyBufferPoolController + virtual BufferPoolController* getBufferPoolController(const char* id = NULL) const; +}; + + +//////////////////////////////// MatCommaInitializer ////////////////////////////////// + +/** @brief Comma-separated Matrix Initializer + + The class instances are usually not created explicitly. + Instead, they are created on "matrix << firstValue" operator. + + The sample below initializes 2x2 rotation matrix: + + \code + double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180); + Mat R = (Mat_<double>(2,2) << a, -b, b, a); + \endcode +*/ +template<typename _Tp> class MatCommaInitializer_ +{ +public: + //! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat + MatCommaInitializer_(Mat_<_Tp>* _m); + //! the operator that takes the next value and put it to the matrix + template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v); + //! another form of conversion operator + operator Mat_<_Tp>() const; +protected: + MatIterator_<_Tp> it; +}; + + +/////////////////////////////////////// Mat /////////////////////////////////////////// + +// note that umatdata might be allocated together +// with the matrix data, not as a separate object. +// therefore, it does not have constructor or destructor; +// it should be explicitly initialized using init(). +struct CV_EXPORTS UMatData +{ + enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, + DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24, + USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64, + ASYNC_CLEANUP=128 + }; + UMatData(const MatAllocator* allocator); + ~UMatData(); + + // provide atomic access to the structure + void lock(); + void unlock(); + + bool hostCopyObsolete() const; + bool deviceCopyObsolete() const; + bool deviceMemMapped() const; + bool copyOnMap() const; + bool tempUMat() const; + bool tempCopiedUMat() const; + void markHostCopyObsolete(bool flag); + void markDeviceCopyObsolete(bool flag); + void markDeviceMemMapped(bool flag); + + const MatAllocator* prevAllocator; + const MatAllocator* currAllocator; + int urefcount; + int refcount; + uchar* data; + uchar* origdata; + size_t size; + + int flags; + void* handle; + void* userdata; + int allocatorFlags_; + int mapcount; + UMatData* originalUMatData; +}; + + +struct CV_EXPORTS MatSize +{ + explicit MatSize(int* _p); + int dims() const; + Size operator()() const; + const int& operator[](int i) const; + int& operator[](int i); + operator const int*() const; // TODO OpenCV 4.0: drop this + bool operator == (const MatSize& sz) const; + bool operator != (const MatSize& sz) const; + + int* p; +}; + +struct CV_EXPORTS MatStep +{ + MatStep(); + explicit MatStep(size_t s); + const size_t& operator[](int i) const; + size_t& operator[](int i); + operator size_t() const; + MatStep& operator = (size_t s); + + size_t* p; + size_t buf[2]; +protected: + MatStep& operator = (const MatStep&); +}; + +/** @example samples/cpp/cout_mat.cpp +An example demonstrating the serial out capabilities of cv::Mat +*/ + + /** @brief n-dimensional dense array class \anchor CVMat_Details + +The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It +can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel +volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms +may be better stored in a SparseMat ). The data layout of the array `M` is defined by the array +`M.step[]`, so that the address of element \f$(i_0,...,i_{M.dims-1})\f$, where \f$0\leq i_k<M.size[k]\f$, is +computed as: +\f[addr(M_{i_0,...,i_{M.dims-1}}) = M.data + M.step[0]*i_0 + M.step[1]*i_1 + ... + M.step[M.dims-1]*i_{M.dims-1}\f] +In case of a 2-dimensional array, the above formula is reduced to: +\f[addr(M_{i,j}) = M.data + M.step[0]*i + M.step[1]*j\f] +Note that `M.step[i] >= M.step[i+1]` (in fact, `M.step[i] >= M.step[i+1]*M.size[i+1]` ). This means +that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane, +and so on. M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() . + +So, the data layout in Mat is fully compatible with CvMat, IplImage, and CvMatND types from OpenCV +1.x. It is also compatible with the majority of dense array types from the standard toolkits and +SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any +array that uses *steps* (or *strides*) to compute the position of a pixel. Due to this +compatibility, it is possible to make a Mat header for user-allocated data and process it in-place +using OpenCV functions. + +There are many different ways to create a Mat object. The most popular options are listed below: + +- Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols, type[, fillValue]) +constructor. A new array of the specified size and type is allocated. type has the same meaning as +in the cvCreateMat method. For example, CV_8UC1 means a 8-bit single-channel array, CV_32FC2 +means a 2-channel (complex) floating-point array, and so on. +@code + // make a 7x7 complex matrix filled with 1+3j. + Mat M(7,7,CV_32FC2,Scalar(1,3)); + // and now turn M to a 100x60 15-channel 8-bit matrix. + // The old content will be deallocated + M.create(100,60,CV_8UC(15)); +@endcode +As noted in the introduction to this chapter, create() allocates only a new array when the shape +or type of the current array are different from the specified ones. + +- Create a multi-dimensional array: +@code + // create a 100x100x100 8-bit array + int sz[] = {100, 100, 100}; + Mat bigCube(3, sz, CV_8U, Scalar::all(0)); +@endcode +It passes the number of dimensions =1 to the Mat constructor but the created array will be +2-dimensional with the number of columns set to 1. So, Mat::dims is always \>= 2 (can also be 0 +when the array is empty). + +- Use a copy constructor or assignment operator where there can be an array or expression on the +right side (see below). As noted in the introduction, the array assignment is an O(1) operation +because it only copies the header and increases the reference counter. The Mat::clone() method can +be used to get a full (deep) copy of the array when you need it. + +- Construct a header for a part of another array. It can be a single row, single column, several +rows, several columns, rectangular region in the array (called a *minor* in algebra) or a +diagonal. Such operations are also O(1) because the new header references the same data. You can +actually modify a part of the array using this feature, for example: +@code + // add the 5-th row, multiplied by 3 to the 3rd row + M.row(3) = M.row(3) + M.row(5)*3; + // now copy the 7-th column to the 1-st column + // M.col(1) = M.col(7); // this will not work + Mat M1 = M.col(1); + M.col(7).copyTo(M1); + // create a new 320x240 image + Mat img(Size(320,240),CV_8UC3); + // select a ROI + Mat roi(img, Rect(10,10,100,100)); + // fill the ROI with (0,255,0) (which is green in RGB space); + // the original 320x240 image will be modified + roi = Scalar(0,255,0); +@endcode +Due to the additional datastart and dataend members, it is possible to compute a relative +sub-array position in the main *container* array using locateROI(): +@code + Mat A = Mat::eye(10, 10, CV_32S); + // extracts A columns, 1 (inclusive) to 3 (exclusive). + Mat B = A(Range::all(), Range(1, 3)); + // extracts B rows, 5 (inclusive) to 9 (exclusive). + // that is, C \~ A(Range(5, 9), Range(1, 3)) + Mat C = B(Range(5, 9), Range::all()); + Size size; Point ofs; + C.locateROI(size, ofs); + // size will be (width=10,height=10) and the ofs will be (x=1, y=5) +@endcode +As in case of whole matrices, if you need a deep copy, use the `clone()` method of the extracted +sub-matrices. + +- Make a header for user-allocated data. It can be useful to do the following: + -# Process "foreign" data using OpenCV (for example, when you implement a DirectShow\* filter or + a processing module for gstreamer, and so on). For example: + @code + void process_video_frame(const unsigned char* pixels, + int width, int height, int step) + { + Mat img(height, width, CV_8UC3, pixels, step); + GaussianBlur(img, img, Size(7,7), 1.5, 1.5); + } + @endcode + -# Quickly initialize small matrices and/or get a super-fast element access. + @code + double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}}; + Mat M = Mat(3, 3, CV_64F, m).inv(); + @endcode + . + Partial yet very common cases of this *user-allocated data* case are conversions from CvMat and + IplImage to Mat. For this purpose, there is function cv::cvarrToMat taking pointers to CvMat or + IplImage and the optional flag indicating whether to copy the data or not. + @snippet samples/cpp/image.cpp iplimage + +- Use MATLAB-style array initializers, zeros(), ones(), eye(), for example: +@code + // create a double-precision identity matrix and add it to M. + M += Mat::eye(M.rows, M.cols, CV_64F); +@endcode + +- Use a comma-separated initializer: +@code + // create a 3x3 double-precision identity matrix + Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1); +@endcode +With this approach, you first call a constructor of the Mat class with the proper parameters, and +then you just put `<< operator` followed by comma-separated values that can be constants, +variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation +errors. + +Once the array is created, it is automatically managed via a reference-counting mechanism. If the +array header is built on top of user-allocated data, you should handle the data by yourself. The +array data is deallocated when no one points to it. If you want to release the data pointed by a +array header before the array destructor is called, use Mat::release(). + +The next important thing to learn about the array class is element access. This manual already +described how to compute an address of each array element. Normally, you are not required to use the +formula directly in the code. If you know the array element type (which can be retrieved using the +method Mat::type() ), you can access the element \f$M_{ij}\f$ of a 2-dimensional array as: +@code + M.at<double>(i,j) += 1.f; +@endcode +assuming that `M` is a double-precision floating-point array. There are several variants of the method +at for a different number of dimensions. + +If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to +the row first, and then just use the plain C operator [] : +@code + // compute sum of positive matrix elements + // (assuming that M is a double-precision matrix) + double sum=0; + for(int i = 0; i < M.rows; i++) + { + const double* Mi = M.ptr<double>(i); + for(int j = 0; j < M.cols; j++) + sum += std::max(Mi[j], 0.); + } +@endcode +Some operations, like the one above, do not actually depend on the array shape. They just process +elements of an array one by one (or elements from multiple arrays that have the same coordinates, +for example, array addition). Such operations are called *element-wise*. It makes sense to check +whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If +yes, process them as a long single row: +@code + // compute the sum of positive matrix elements, optimized variant + double sum=0; + int cols = M.cols, rows = M.rows; + if(M.isContinuous()) + { + cols *= rows; + rows = 1; + } + for(int i = 0; i < rows; i++) + { + const double* Mi = M.ptr<double>(i); + for(int j = 0; j < cols; j++) + sum += std::max(Mi[j], 0.); + } +@endcode +In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is +smaller, which is especially noticeable in case of small matrices. + +Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows: +@code + // compute sum of positive matrix elements, iterator-based variant + double sum=0; + MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>(); + for(; it != it_end; ++it) + sum += std::max(*it, 0.); +@endcode +The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, +including std::sort(). + +@note Matrix Expressions and arithmetic see MatExpr +*/ +class CV_EXPORTS Mat +{ +public: + /** + These are various constructors that form a matrix. As noted in the AutomaticAllocation, often + the default constructor is enough, and the proper matrix will be allocated by an OpenCV function. + The constructed matrix can further be assigned to another matrix or matrix expression or can be + allocated with Mat::create . In the former case, the old content is de-referenced. + */ + Mat(); + + /** @overload + @param rows Number of rows in a 2D array. + @param cols Number of columns in a 2D array. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(int rows, int cols, int type); + + /** @overload + @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the + number of columns go in the reverse order. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(Size size, int type); + + /** @overload + @param rows Number of rows in a 2D array. + @param cols Number of columns in a 2D array. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(int rows, int cols, int type, const Scalar& s); + + /** @overload + @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the + number of columns go in the reverse order. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(Size size, int type, const Scalar& s); + + /** @overload + @param ndims Array dimensionality. + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(int ndims, const int* sizes, int type); + + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(const std::vector<int>& sizes, int type); + + /** @overload + @param ndims Array dimensionality. + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(int ndims, const int* sizes, int type, const Scalar& s); + + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(const std::vector<int>& sizes, int type, const Scalar& s); + + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + */ + Mat(const Mat& m); + + /** @overload + @param rows Number of rows in a 2D array. + @param cols Number of columns in a 2D array. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param step Number of bytes each matrix row occupies. The value should include the padding bytes at + the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed + and the actual step is calculated as cols*elemSize(). See Mat::elemSize. + */ + Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP); + + /** @overload + @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the + number of columns go in the reverse order. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param step Number of bytes each matrix row occupies. The value should include the padding bytes at + the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed + and the actual step is calculated as cols*elemSize(). See Mat::elemSize. + */ + Mat(Size size, int type, void* data, size_t step=AUTO_STEP); + + /** @overload + @param ndims Array dimensionality. + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always + set to the element size). If not specified, the matrix is assumed to be continuous. + */ + Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0); + + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always + set to the element size). If not specified, the matrix is assumed to be continuous. + */ + Mat(const std::vector<int>& sizes, int type, void* data, const size_t* steps=0); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param rowRange Range of the m rows to take. As usual, the range start is inclusive and the range + end is exclusive. Use Range::all() to take all the rows. + @param colRange Range of the m columns to take. Use Range::all() to take all the columns. + */ + Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all()); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param roi Region of interest. + */ + Mat(const Mat& m, const Rect& roi); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param ranges Array of selected ranges of m along each dimensionality. + */ + Mat(const Mat& m, const Range* ranges); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param ranges Array of selected ranges of m along each dimensionality. + */ + Mat(const Mat& m, const std::vector<Range>& ranges); + + /** @overload + @param vec STL vector whose elements form the matrix. The matrix has a single column and the number + of rows equal to the number of vector elements. Type of the matrix matches the type of vector + elements. The constructor can handle arbitrary types, for which there is a properly declared + DataType . This means that the vector elements must be primitive numbers or uni-type numerical + tuples of numbers. Mixed-type structures are not supported. The corresponding constructor is + explicit. Since STL vectors are not automatically converted to Mat instances, you should write + Mat(vec) explicitly. Unless you copy the data into the matrix ( copyData=true ), no new elements + will be added to the vector because it can potentially yield vector data reallocation, and, thus, + the matrix data pointer will be invalid. + @param copyData Flag to specify whether the underlying data of the STL vector should be copied + to (true) or shared with (false) the newly constructed matrix. When the data is copied, the + allocated buffer is managed using Mat reference counting mechanism. While the data is shared, + the reference counter is NULL, and you should not deallocate the data until the matrix is not + destructed. + */ + template<typename _Tp> explicit Mat(const std::vector<_Tp>& vec, bool copyData=false); + +#ifdef CV_CXX11 + /** @overload + */ + template<typename _Tp, typename = typename std::enable_if<std::is_arithmetic<_Tp>::value>::type> + explicit Mat(const std::initializer_list<_Tp> list); + + /** @overload + */ + template<typename _Tp> explicit Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list); +#endif + +#ifdef CV_CXX_STD_ARRAY + /** @overload + */ + template<typename _Tp, size_t _Nm> explicit Mat(const std::array<_Tp, _Nm>& arr, bool copyData=false); +#endif + + /** @overload + */ + template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true); + + /** @overload + */ + template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx, bool copyData=true); + + /** @overload + */ + template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true); + + /** @overload + */ + template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true); + + /** @overload + */ + template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer); + + //! download data from GpuMat + explicit Mat(const cuda::GpuMat& m); + + //! destructor - calls release() + ~Mat(); + + /** @brief assignment operators + + These are available assignment operators. Since they all are very different, make sure to read the + operator parameters description. + @param m Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that + no data is copied but the data is shared and the reference counter, if any, is incremented. Before + assigning new data, the old data is de-referenced via Mat::release . + */ + Mat& operator = (const Mat& m); + + /** @overload + @param expr Assigned matrix expression object. As opposite to the first form of the assignment + operation, the second form can reuse already allocated matrix if it has the right size and type to + fit the matrix expression result. It is automatically handled by the real function that the matrix + expressions is expanded to. For example, C=A+B is expanded to add(A, B, C), and add takes care of + automatic C reallocation. + */ + Mat& operator = (const MatExpr& expr); + + //! retrieve UMat from Mat + UMat getUMat(int accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; + + /** @brief Creates a matrix header for the specified matrix row. + + The method makes a new header for the specified matrix row and returns it. This is an O(1) + operation, regardless of the matrix size. The underlying data of the new matrix is shared with the + original matrix. Here is the example of one of the classical basic matrix processing operations, + axpy, used by LU and many other algorithms: + @code + inline void matrix_axpy(Mat& A, int i, int j, double alpha) + { + A.row(i) += A.row(j)*alpha; + } + @endcode + @note In the current implementation, the following code does not work as expected: + @code + Mat A; + ... + A.row(i) = A.row(j); // will not work + @endcode + This happens because A.row(i) forms a temporary header that is further assigned to another header. + Remember that each of these operations is O(1), that is, no data is copied. Thus, the above + assignment is not true if you may have expected the j-th row to be copied to the i-th row. To + achieve that, you should either turn this simple assignment into an expression or use the + Mat::copyTo method: + @code + Mat A; + ... + // works, but looks a bit obscure. + A.row(i) = A.row(j) + 0; + // this is a bit longer, but the recommended method. + A.row(j).copyTo(A.row(i)); + @endcode + @param y A 0-based row index. + */ + Mat row(int y) const; + + /** @brief Creates a matrix header for the specified matrix column. + + The method makes a new header for the specified matrix column and returns it. This is an O(1) + operation, regardless of the matrix size. The underlying data of the new matrix is shared with the + original matrix. See also the Mat::row description. + @param x A 0-based column index. + */ + Mat col(int x) const; + + /** @brief Creates a matrix header for the specified row span. + + The method makes a new header for the specified row span of the matrix. Similarly to Mat::row and + Mat::col , this is an O(1) operation. + @param startrow An inclusive 0-based start index of the row span. + @param endrow An exclusive 0-based ending index of the row span. + */ + Mat rowRange(int startrow, int endrow) const; + + /** @overload + @param r Range structure containing both the start and the end indices. + */ + Mat rowRange(const Range& r) const; + + /** @brief Creates a matrix header for the specified column span. + + The method makes a new header for the specified column span of the matrix. Similarly to Mat::row and + Mat::col , this is an O(1) operation. + @param startcol An inclusive 0-based start index of the column span. + @param endcol An exclusive 0-based ending index of the column span. + */ + Mat colRange(int startcol, int endcol) const; + + /** @overload + @param r Range structure containing both the start and the end indices. + */ + Mat colRange(const Range& r) const; + + /** @brief Extracts a diagonal from a matrix + + The method makes a new header for the specified matrix diagonal. The new matrix is represented as a + single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation. + @param d index of the diagonal, with the following values: + - `d=0` is the main diagonal. + - `d<0` is a diagonal from the lower half. For example, d=-1 means the diagonal is set + immediately below the main one. + - `d>0` is a diagonal from the upper half. For example, d=1 means the diagonal is set + immediately above the main one. + For example: + @code + Mat m = (Mat_<int>(3,3) << + 1,2,3, + 4,5,6, + 7,8,9); + Mat d0 = m.diag(0); + Mat d1 = m.diag(1); + Mat d_1 = m.diag(-1); + @endcode + The resulting matrices are + @code + d0 = + [1; + 5; + 9] + d1 = + [2; + 6] + d_1 = + [4; + 8] + @endcode + */ + Mat diag(int d=0) const; + + /** @brief creates a diagonal matrix + + The method creates a square diagonal matrix from specified main diagonal. + @param d One-dimensional matrix that represents the main diagonal. + */ + static Mat diag(const Mat& d); + + /** @brief Creates a full copy of the array and the underlying data. + + The method creates a full copy of the array. The original step[] is not taken into account. So, the + array copy is a continuous array occupying total()*elemSize() bytes. + */ + Mat clone() const CV_NODISCARD; + + /** @brief Copies the matrix to another one. + + The method copies the matrix data to another matrix. Before copying the data, the method invokes : + @code + m.create(this->size(), this->type()); + @endcode + so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the + function does not handle the case of a partial overlap between the source and the destination + matrices. + + When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, + the newly allocated matrix is initialized with all zeros before copying the data. + @param m Destination matrix. If it does not have a proper size or type before the operation, it is + reallocated. + */ + void copyTo( OutputArray m ) const; + + /** @overload + @param m Destination matrix. If it does not have a proper size or type before the operation, it is + reallocated. + @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix + elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels. + */ + void copyTo( OutputArray m, InputArray mask ) const; + + /** @brief Converts an array to another data type with optional scaling. + + The method converts source pixel values to the target data type. saturate_cast\<\> is applied at + the end to avoid possible overflows: + + \f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f] + @param m output matrix; if it does not have a proper size or type before the operation, it is + reallocated. + @param rtype desired output matrix type or, rather, the depth since the number of channels are the + same as the input has; if rtype is negative, the output matrix will have the same type as the input. + @param alpha optional scale factor. + @param beta optional delta added to the scaled values. + */ + void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; + + /** @brief Provides a functional form of convertTo. + + This is an internally used method called by the @ref MatrixExpressions engine. + @param m Destination array. + @param type Desired destination array depth (or -1 if it should be the same as the source type). + */ + void assignTo( Mat& m, int type=-1 ) const; + + /** @brief Sets all or some of the array elements to the specified value. + @param s Assigned scalar converted to the actual array type. + */ + Mat& operator = (const Scalar& s); + + /** @brief Sets all or some of the array elements to the specified value. + + This is an advanced variant of the Mat::operator=(const Scalar& s) operator. + @param value Assigned scalar converted to the actual array type. + @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix + elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels + */ + Mat& setTo(InputArray value, InputArray mask=noArray()); + + /** @brief Changes the shape and/or the number of channels of a 2D matrix without copying the data. + + The method makes a new matrix header for \*this elements. The new matrix may have a different size + and/or different number of channels. Any combination is possible if: + - No extra elements are included into the new matrix and no elements are excluded. Consequently, + the product rows\*cols\*channels() must stay the same after the transformation. + - No data is copied. That is, this is an O(1) operation. Consequently, if you change the number of + rows, or the operation changes the indices of elements row in some other way, the matrix must be + continuous. See Mat::isContinuous . + + For example, if there is a set of 3D points stored as an STL vector, and you want to represent the + points as a 3xN matrix, do the following: + @code + std::vector<Point3f> vec; + ... + Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operation + reshape(1). // make Nx3 1-channel matrix out of Nx1 3-channel. + // Also, an O(1) operation + t(); // finally, transpose the Nx3 matrix. + // This involves copying all the elements + @endcode + @param cn New number of channels. If the parameter is 0, the number of channels remains the same. + @param rows New number of rows. If the parameter is 0, the number of rows remains the same. + */ + Mat reshape(int cn, int rows=0) const; + + /** @overload */ + Mat reshape(int cn, int newndims, const int* newsz) const; + + /** @overload */ + Mat reshape(int cn, const std::vector<int>& newshape) const; + + /** @brief Transposes a matrix. + + The method performs matrix transposition by means of matrix expressions. It does not perform the + actual transposition but returns a temporary matrix transposition object that can be further used as + a part of more complex matrix expressions or can be assigned to a matrix: + @code + Mat A1 = A + Mat::eye(A.size(), A.type())*lambda; + Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I) + @endcode + */ + MatExpr t() const; + + /** @brief Inverses a matrix. + + The method performs a matrix inversion by means of matrix expressions. This means that a temporary + matrix inversion object is returned by the method and can be used further as a part of more complex + matrix expressions or can be assigned to a matrix. + @param method Matrix inversion method. One of cv::DecompTypes + */ + MatExpr inv(int method=DECOMP_LU) const; + + /** @brief Performs an element-wise multiplication or division of the two matrices. + + The method returns a temporary object encoding per-element array multiplication, with optional + scale. Note that this is not a matrix multiplication that corresponds to a simpler "\*" operator. + + Example: + @code + Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5) + @endcode + @param m Another array of the same type and the same size as \*this, or a matrix expression. + @param scale Optional scale factor. + */ + MatExpr mul(InputArray m, double scale=1) const; + + /** @brief Computes a cross-product of two 3-element vectors. + + The method computes a cross-product of two 3-element vectors. The vectors must be 3-element + floating-point vectors of the same shape and size. The result is another 3-element vector of the + same shape and type as operands. + @param m Another cross-product operand. + */ + Mat cross(InputArray m) const; + + /** @brief Computes a dot-product of two vectors. + + The method computes a dot-product of two matrices. If the matrices are not single-column or + single-row vectors, the top-to-bottom left-to-right scan ordering is used to treat them as 1D + vectors. The vectors must have the same size and type. If the matrices have more than one channel, + the dot products from all the channels are summed together. + @param m another dot-product operand. + */ + double dot(InputArray m) const; + + /** @brief Returns a zero array of the specified size and type. + + The method returns a Matlab-style zero array initializer. It can be used to quickly form a constant + array as a function parameter, part of a matrix expression, or as a matrix initializer: + @code + Mat A; + A = Mat::zeros(3, 3, CV_32F); + @endcode + In the example above, a new matrix is allocated only if A is not a 3x3 floating-point matrix. + Otherwise, the existing matrix A is filled with zeros. + @param rows Number of rows. + @param cols Number of columns. + @param type Created matrix type. + */ + static MatExpr zeros(int rows, int cols, int type); + + /** @overload + @param size Alternative to the matrix size specification Size(cols, rows) . + @param type Created matrix type. + */ + static MatExpr zeros(Size size, int type); + + /** @overload + @param ndims Array dimensionality. + @param sz Array of integers specifying the array shape. + @param type Created matrix type. + */ + static MatExpr zeros(int ndims, const int* sz, int type); + + /** @brief Returns an array of all 1's of the specified size and type. + + The method returns a Matlab-style 1's array initializer, similarly to Mat::zeros. Note that using + this method you can initialize an array with an arbitrary value, using the following Matlab idiom: + @code + Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled with 3. + @endcode + The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it + just remembers the scale factor (3 in this case) and use it when actually invoking the matrix + initializer. + @note In case of multi-channels type, only the first channel will be initialized with 1's, the + others will be set to 0's. + @param rows Number of rows. + @param cols Number of columns. + @param type Created matrix type. + */ + static MatExpr ones(int rows, int cols, int type); + + /** @overload + @param size Alternative to the matrix size specification Size(cols, rows) . + @param type Created matrix type. + */ + static MatExpr ones(Size size, int type); + + /** @overload + @param ndims Array dimensionality. + @param sz Array of integers specifying the array shape. + @param type Created matrix type. + */ + static MatExpr ones(int ndims, const int* sz, int type); + + /** @brief Returns an identity matrix of the specified size and type. + + The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to + Mat::ones, you can use a scale operation to create a scaled identity matrix efficiently: + @code + // make a 4x4 diagonal matrix with 0.1's on the diagonal. + Mat A = Mat::eye(4, 4, CV_32F)*0.1; + @endcode + @note In case of multi-channels type, identity matrix will be initialized only for the first channel, + the others will be set to 0's + @param rows Number of rows. + @param cols Number of columns. + @param type Created matrix type. + */ + static MatExpr eye(int rows, int cols, int type); + + /** @overload + @param size Alternative matrix size specification as Size(cols, rows) . + @param type Created matrix type. + */ + static MatExpr eye(Size size, int type); + + /** @brief Allocates new array data if needed. + + This is one of the key Mat methods. Most new-style OpenCV functions and methods that produce arrays + call this method for each output array. The method uses the following algorithm: + + -# If the current array shape and the type match the new ones, return immediately. Otherwise, + de-reference the previous data by calling Mat::release. + -# Initialize the new header. + -# Allocate the new data of total()\*elemSize() bytes. + -# Allocate the new, associated with the data, reference counter and set it to 1. + + Such a scheme makes the memory management robust and efficient at the same time and helps avoid + extra typing for you. This means that usually there is no need to explicitly allocate output arrays. + That is, instead of writing: + @code + Mat color; + ... + Mat gray(color.rows, color.cols, color.depth()); + cvtColor(color, gray, COLOR_BGR2GRAY); + @endcode + you can simply write: + @code + Mat color; + ... + Mat gray; + cvtColor(color, gray, COLOR_BGR2GRAY); + @endcode + because cvtColor, as well as the most of OpenCV functions, calls Mat::create() for the output array + internally. + @param rows New number of rows. + @param cols New number of columns. + @param type New matrix type. + */ + void create(int rows, int cols, int type); + + /** @overload + @param size Alternative new matrix size specification: Size(cols, rows) + @param type New matrix type. + */ + void create(Size size, int type); + + /** @overload + @param ndims New array dimensionality. + @param sizes Array of integers specifying a new array shape. + @param type New matrix type. + */ + void create(int ndims, const int* sizes, int type); + + /** @overload + @param sizes Array of integers specifying a new array shape. + @param type New matrix type. + */ + void create(const std::vector<int>& sizes, int type); + + /** @brief Increments the reference counter. + + The method increments the reference counter associated with the matrix data. If the matrix header + points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no + effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It + is called implicitly by the matrix assignment operator. The reference counter increment is an atomic + operation on the platforms that support it. Thus, it is safe to operate on the same matrices + asynchronously in different threads. + */ + void addref(); + + /** @brief Decrements the reference counter and deallocates the matrix if needed. + + The method decrements the reference counter associated with the matrix data. When the reference + counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers + are set to NULL's. If the matrix header points to an external data set (see Mat::Mat ), the + reference counter is NULL, and the method has no effect in this case. + + This method can be called manually to force the matrix data deallocation. But since this method is + automatically called in the destructor, or by any other method that changes the data pointer, it is + usually not needed. The reference counter decrement and check for 0 is an atomic operation on the + platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in + different threads. + */ + void release(); + + //! internal use function, consider to use 'release' method instead; deallocates the matrix data + void deallocate(); + //! internal use function; properly re-allocates _size, _step arrays + void copySize(const Mat& m); + + /** @brief Reserves space for the certain number of rows. + + The method reserves space for sz rows. If the matrix already has enough space to store sz rows, + nothing happens. If the matrix is reallocated, the first Mat::rows rows are preserved. The method + emulates the corresponding method of the STL vector class. + @param sz Number of rows. + */ + void reserve(size_t sz); + + /** @brief Reserves space for the certain number of bytes. + + The method reserves space for sz bytes. If the matrix already has enough space to store sz bytes, + nothing happens. If matrix has to be reallocated its previous content could be lost. + @param sz Number of bytes. + */ + void reserveBuffer(size_t sz); + + /** @brief Changes the number of matrix rows. + + The methods change the number of matrix rows. If the matrix is reallocated, the first + min(Mat::rows, sz) rows are preserved. The methods emulate the corresponding methods of the STL + vector class. + @param sz New number of rows. + */ + void resize(size_t sz); + + /** @overload + @param sz New number of rows. + @param s Value assigned to the newly added elements. + */ + void resize(size_t sz, const Scalar& s); + + //! internal function + void push_back_(const void* elem); + + /** @brief Adds elements to the bottom of the matrix. + + The methods add one or more elements to the bottom of the matrix. They emulate the corresponding + method of the STL vector class. When elem is Mat , its type and the number of columns must be the + same as in the container matrix. + @param elem Added element(s). + */ + template<typename _Tp> void push_back(const _Tp& elem); + + /** @overload + @param elem Added element(s). + */ + template<typename _Tp> void push_back(const Mat_<_Tp>& elem); + + /** @overload + @param elem Added element(s). + */ + template<typename _Tp> void push_back(const std::vector<_Tp>& elem); + + /** @overload + @param m Added line(s). + */ + void push_back(const Mat& m); + + /** @brief Removes elements from the bottom of the matrix. + + The method removes one or more rows from the bottom of the matrix. + @param nelems Number of removed rows. If it is greater than the total number of rows, an exception + is thrown. + */ + void pop_back(size_t nelems=1); + + /** @brief Locates the matrix header within a parent matrix. + + After you extracted a submatrix from a matrix using Mat::row, Mat::col, Mat::rowRange, + Mat::colRange, and others, the resultant submatrix points just to the part of the original big + matrix. However, each submatrix contains information (represented by datastart and dataend + fields) that helps reconstruct the original matrix size and the position of the extracted + submatrix within the original matrix. The method locateROI does exactly that. + @param wholeSize Output parameter that contains the size of the whole matrix containing *this* + as a part. + @param ofs Output parameter that contains an offset of *this* inside the whole matrix. + */ + void locateROI( Size& wholeSize, Point& ofs ) const; + + /** @brief Adjusts a submatrix size and position within the parent matrix. + + The method is complimentary to Mat::locateROI . The typical use of these functions is to determine + the submatrix position within the parent matrix and then shift the position somehow. Typically, it + can be required for filtering operations when pixels outside of the ROI should be taken into + account. When all the method parameters are positive, the ROI needs to grow in all directions by the + specified amount, for example: + @code + A.adjustROI(2, 2, 2, 2); + @endcode + In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted + by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the + filtering with the 5x5 kernel. + + adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the + adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is + located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not + be increased in the upward direction. + + The function is used internally by the OpenCV filtering functions, like filter2D , morphological + operations, and so on. + @param dtop Shift of the top submatrix boundary upwards. + @param dbottom Shift of the bottom submatrix boundary downwards. + @param dleft Shift of the left submatrix boundary to the left. + @param dright Shift of the right submatrix boundary to the right. + @sa copyMakeBorder + */ + Mat& adjustROI( int dtop, int dbottom, int dleft, int dright ); + + /** @brief Extracts a rectangular submatrix. + + The operators make a new header for the specified sub-array of \*this . They are the most + generalized forms of Mat::row, Mat::col, Mat::rowRange, and Mat::colRange . For example, + `A(Range(0, 10), Range::all())` is equivalent to `A.rowRange(0, 10)`. Similarly to all of the above, + the operators are O(1) operations, that is, no matrix data is copied. + @param rowRange Start and end row of the extracted submatrix. The upper boundary is not included. To + select all the rows, use Range::all(). + @param colRange Start and end column of the extracted submatrix. The upper boundary is not included. + To select all the columns, use Range::all(). + */ + Mat operator()( Range rowRange, Range colRange ) const; + + /** @overload + @param roi Extracted submatrix specified as a rectangle. + */ + Mat operator()( const Rect& roi ) const; + + /** @overload + @param ranges Array of selected ranges along each array dimension. + */ + Mat operator()( const Range* ranges ) const; + + /** @overload + @param ranges Array of selected ranges along each array dimension. + */ + Mat operator()(const std::vector<Range>& ranges) const; + + // //! converts header to CvMat; no data is copied + // operator CvMat() const; + // //! converts header to CvMatND; no data is copied + // operator CvMatND() const; + // //! converts header to IplImage; no data is copied + // operator IplImage() const; + + template<typename _Tp> operator std::vector<_Tp>() const; + template<typename _Tp, int n> operator Vec<_Tp, n>() const; + template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const; + +#ifdef CV_CXX_STD_ARRAY + template<typename _Tp, std::size_t _Nm> operator std::array<_Tp, _Nm>() const; +#endif + + /** @brief Reports whether the matrix is continuous or not. + + The method returns true if the matrix elements are stored continuously without gaps at the end of + each row. Otherwise, it returns false. Obviously, 1x1 or 1xN matrices are always continuous. + Matrices created with Mat::create are always continuous. But if you extract a part of the matrix + using Mat::col, Mat::diag, and so on, or constructed a matrix header for externally allocated data, + such matrices may no longer have this property. + + The continuity flag is stored as a bit in the Mat::flags field and is computed automatically when + you construct a matrix header. Thus, the continuity check is a very fast operation, though + theoretically it could be done as follows: + @code + // alternative implementation of Mat::isContinuous() + bool myCheckMatContinuity(const Mat& m) + { + //return (m.flags & Mat::CONTINUOUS_FLAG) != 0; + return m.rows == 1 || m.step == m.cols*m.elemSize(); + } + @endcode + The method is used in quite a few of OpenCV functions. The point is that element-wise operations + (such as arithmetic and logical operations, math functions, alpha blending, color space + transformations, and others) do not depend on the image geometry. Thus, if all the input and output + arrays are continuous, the functions can process them as very long single-row vectors. The example + below illustrates how an alpha-blending function can be implemented: + @code + template<typename T> + void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) + { + const float alpha_scale = (float)std::numeric_limits<T>::max(), + inv_scale = 1.f/alpha_scale; + + CV_Assert( src1.type() == src2.type() && + src1.type() == CV_MAKETYPE(traits::Depth<T>::value, 4) && + src1.size() == src2.size()); + Size size = src1.size(); + dst.create(size, src1.type()); + + // here is the idiom: check the arrays for continuity and, + // if this is the case, + // treat the arrays as 1D vectors + if( src1.isContinuous() && src2.isContinuous() && dst.isContinuous() ) + { + size.width *= size.height; + size.height = 1; + } + size.width *= 4; + + for( int i = 0; i < size.height; i++ ) + { + // when the arrays are continuous, + // the outer loop is executed only once + const T* ptr1 = src1.ptr<T>(i); + const T* ptr2 = src2.ptr<T>(i); + T* dptr = dst.ptr<T>(i); + + for( int j = 0; j < size.width; j += 4 ) + { + float alpha = ptr1[j+3]*inv_scale, beta = ptr2[j+3]*inv_scale; + dptr[j] = saturate_cast<T>(ptr1[j]*alpha + ptr2[j]*beta); + dptr[j+1] = saturate_cast<T>(ptr1[j+1]*alpha + ptr2[j+1]*beta); + dptr[j+2] = saturate_cast<T>(ptr1[j+2]*alpha + ptr2[j+2]*beta); + dptr[j+3] = saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale); + } + } + } + @endcode + This approach, while being very simple, can boost the performance of a simple element-operation by + 10-20 percents, especially if the image is rather small and the operation is quite simple. + + Another OpenCV idiom in this function, a call of Mat::create for the destination array, that + allocates the destination array unless it already has the proper size and type. And while the newly + allocated arrays are always continuous, you still need to check the destination array because + Mat::create does not always allocate a new matrix. + */ + bool isContinuous() const; + + //! returns true if the matrix is a submatrix of another matrix + bool isSubmatrix() const; + + /** @brief Returns the matrix element size in bytes. + + The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , + the method returns 3\*sizeof(short) or 6. + */ + size_t elemSize() const; + + /** @brief Returns the size of each matrix element channel in bytes. + + The method returns the matrix element channel size in bytes, that is, it ignores the number of + channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2. + */ + size_t elemSize1() const; + + /** @brief Returns the type of a matrix element. + + The method returns a matrix element type. This is an identifier compatible with the CvMat type + system, like CV_16SC3 or 16-bit signed 3-channel array, and so on. + */ + int type() const; + + /** @brief Returns the depth of a matrix element. + + The method returns the identifier of the matrix element depth (the type of each individual channel). + For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of + matrix types contains the following values: + - CV_8U - 8-bit unsigned integers ( 0..255 ) + - CV_8S - 8-bit signed integers ( -128..127 ) + - CV_16U - 16-bit unsigned integers ( 0..65535 ) + - CV_16S - 16-bit signed integers ( -32768..32767 ) + - CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) + - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) + - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN ) + */ + int depth() const; + + /** @brief Returns the number of matrix channels. + + The method returns the number of matrix channels. + */ + int channels() const; + + /** @brief Returns a normalized step. + + The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access an + arbitrary matrix element. + */ + size_t step1(int i=0) const; + + /** @brief Returns true if the array has no elements. + + The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and + resize() methods `M.total() == 0` does not imply that `M.data == NULL`. + */ + bool empty() const; + + /** @brief Returns the total number of array elements. + + The method returns the number of array elements (a number of pixels if the array represents an + image). + */ + size_t total() const; + + /** @brief Returns the total number of array elements. + + The method returns the number of elements within a certain sub-array slice with startDim <= dim < endDim + */ + size_t total(int startDim, int endDim=INT_MAX) const; + + /** + * @param elemChannels Number of channels or number of columns the matrix should have. + * For a 2-D matrix, when the matrix has only 1 column, then it should have + * elemChannels channels; When the matrix has only 1 channel, + * then it should have elemChannels columns. + * For a 3-D matrix, it should have only one channel. Furthermore, + * if the number of planes is not one, then the number of rows + * within every plane has to be 1; if the number of rows within + * every plane is not 1, then the number of planes has to be 1. + * @param depth The depth the matrix should have. Set it to -1 when any depth is fine. + * @param requireContinuous Set it to true to require the matrix to be continuous + * @return -1 if the requirement is not satisfied. + * Otherwise, it returns the number of elements in the matrix. Note + * that an element may have multiple channels. + * + * The following code demonstrates its usage for a 2-d matrix: + * @snippet snippets/core_mat_checkVector.cpp example-2d + * + * The following code demonstrates its usage for a 3-d matrix: + * @snippet snippets/core_mat_checkVector.cpp example-3d + */ + int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; + + /** @brief Returns a pointer to the specified matrix row. + + The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in + Mat::isContinuous to know how to use these methods. + @param i0 A 0-based row index. + */ + uchar* ptr(int i0=0); + /** @overload */ + const uchar* ptr(int i0=0) const; + + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + uchar* ptr(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + const uchar* ptr(int row, int col) const; + + /** @overload */ + uchar* ptr(int i0, int i1, int i2); + /** @overload */ + const uchar* ptr(int i0, int i1, int i2) const; + + /** @overload */ + uchar* ptr(const int* idx); + /** @overload */ + const uchar* ptr(const int* idx) const; + /** @overload */ + template<int n> uchar* ptr(const Vec<int, n>& idx); + /** @overload */ + template<int n> const uchar* ptr(const Vec<int, n>& idx) const; + + /** @overload */ + template<typename _Tp> _Tp* ptr(int i0=0); + /** @overload */ + template<typename _Tp> const _Tp* ptr(int i0=0) const; + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template<typename _Tp> _Tp* ptr(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template<typename _Tp> const _Tp* ptr(int row, int col) const; + /** @overload */ + template<typename _Tp> _Tp* ptr(int i0, int i1, int i2); + /** @overload */ + template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const; + /** @overload */ + template<typename _Tp> _Tp* ptr(const int* idx); + /** @overload */ + template<typename _Tp> const _Tp* ptr(const int* idx) const; + /** @overload */ + template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx); + /** @overload */ + template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const; + + /** @brief Returns a reference to the specified array element. + + The template methods return a reference to the specified array element. For the sake of higher + performance, the index range checks are only performed in the Debug configuration. + + Note that the variants with a single index (i) can be used to access elements of single-row or + single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and + B is an M x 1 integer matrix, you can simply write `A.at<float>(k+4)` and `B.at<int>(2*i+1)` + instead of `A.at<float>(0,k+4)` and `B.at<int>(2*i+1,0)`, respectively. + + The example below initializes a Hilbert matrix: + @code + Mat H(100, 100, CV_64F); + for(int i = 0; i < H.rows; i++) + for(int j = 0; j < H.cols; j++) + H.at<double>(i,j)=1./(i+j+1); + @endcode + + Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends + on the image from which you are trying to retrieve the data. The table below gives a better insight in this: + - If matrix is of type `CV_8U` then use `Mat.at<uchar>(y,x)`. + - If matrix is of type `CV_8S` then use `Mat.at<schar>(y,x)`. + - If matrix is of type `CV_16U` then use `Mat.at<ushort>(y,x)`. + - If matrix is of type `CV_16S` then use `Mat.at<short>(y,x)`. + - If matrix is of type `CV_32S` then use `Mat.at<int>(y,x)`. + - If matrix is of type `CV_32F` then use `Mat.at<float>(y,x)`. + - If matrix is of type `CV_64F` then use `Mat.at<double>(y,x)`. + + @param i0 Index along the dimension 0 + */ + template<typename _Tp> _Tp& at(int i0=0); + /** @overload + @param i0 Index along the dimension 0 + */ + template<typename _Tp> const _Tp& at(int i0=0) const; + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template<typename _Tp> _Tp& at(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template<typename _Tp> const _Tp& at(int row, int col) const; + + /** @overload + @param i0 Index along the dimension 0 + @param i1 Index along the dimension 1 + @param i2 Index along the dimension 2 + */ + template<typename _Tp> _Tp& at(int i0, int i1, int i2); + /** @overload + @param i0 Index along the dimension 0 + @param i1 Index along the dimension 1 + @param i2 Index along the dimension 2 + */ + template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const; + + /** @overload + @param idx Array of Mat::dims indices. + */ + template<typename _Tp> _Tp& at(const int* idx); + /** @overload + @param idx Array of Mat::dims indices. + */ + template<typename _Tp> const _Tp& at(const int* idx) const; + + /** @overload */ + template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx); + /** @overload */ + template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const; + + /** @overload + special versions for 2D arrays (especially convenient for referencing image pixels) + @param pt Element position specified as Point(j,i) . + */ + template<typename _Tp> _Tp& at(Point pt); + /** @overload + special versions for 2D arrays (especially convenient for referencing image pixels) + @param pt Element position specified as Point(j,i) . + */ + template<typename _Tp> const _Tp& at(Point pt) const; + + /** @brief Returns the matrix iterator and sets it to the first matrix element. + + The methods return the matrix read-only or read-write iterators. The use of matrix iterators is very + similar to the use of bi-directional STL iterators. In the example below, the alpha blending + function is rewritten using the matrix iterators: + @code + template<typename T> + void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) + { + typedef Vec<T, 4> VT; + + const float alpha_scale = (float)std::numeric_limits<T>::max(), + inv_scale = 1.f/alpha_scale; + + CV_Assert( src1.type() == src2.type() && + src1.type() == traits::Type<VT>::value && + src1.size() == src2.size()); + Size size = src1.size(); + dst.create(size, src1.type()); + + MatConstIterator_<VT> it1 = src1.begin<VT>(), it1_end = src1.end<VT>(); + MatConstIterator_<VT> it2 = src2.begin<VT>(); + MatIterator_<VT> dst_it = dst.begin<VT>(); + + for( ; it1 != it1_end; ++it1, ++it2, ++dst_it ) + { + VT pix1 = *it1, pix2 = *it2; + float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale; + *dst_it = VT(saturate_cast<T>(pix1[0]*alpha + pix2[0]*beta), + saturate_cast<T>(pix1[1]*alpha + pix2[1]*beta), + saturate_cast<T>(pix1[2]*alpha + pix2[2]*beta), + saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale)); + } + } + @endcode + */ + template<typename _Tp> MatIterator_<_Tp> begin(); + template<typename _Tp> MatConstIterator_<_Tp> begin() const; + + /** @brief Returns the matrix iterator and sets it to the after-last matrix element. + + The methods return the matrix read-only or read-write iterators, set to the point following the last + matrix element. + */ + template<typename _Tp> MatIterator_<_Tp> end(); + template<typename _Tp> MatConstIterator_<_Tp> end() const; + + /** @brief Runs the given functor over all matrix elements in parallel. + + The operation passed as argument has to be a function pointer, a function object or a lambda(C++11). + + Example 1. All of the operations below put 0xFF the first channel of all matrix elements: + @code + Mat image(1920, 1080, CV_8UC3); + typedef cv::Point3_<uint8_t> Pixel; + + // first. raw pointer access. + for (int r = 0; r < image.rows; ++r) { + Pixel* ptr = image.ptr<Pixel>(r, 0); + const Pixel* ptr_end = ptr + image.cols; + for (; ptr != ptr_end; ++ptr) { + ptr->x = 255; + } + } + + // Using MatIterator. (Simple but there are a Iterator's overhead) + for (Pixel &p : cv::Mat_<Pixel>(image)) { + p.x = 255; + } + + // Parallel execution with function object. + struct Operator { + void operator ()(Pixel &pixel, const int * position) { + pixel.x = 255; + } + }; + image.forEach<Pixel>(Operator()); + + // Parallel execution using C++11 lambda. + image.forEach<Pixel>([](Pixel &p, const int * position) -> void { + p.x = 255; + }); + @endcode + Example 2. Using the pixel's position: + @code + // Creating 3D matrix (255 x 255 x 255) typed uint8_t + // and initialize all elements by the value which equals elements position. + // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3). + + int sizes[] = { 255, 255, 255 }; + typedef cv::Point3_<uint8_t> Pixel; + + Mat_<Pixel> image = Mat::zeros(3, sizes, CV_8UC3); + + image.forEach<Pixel>([&](Pixel& pixel, const int position[]) -> void { + pixel.x = position[0]; + pixel.y = position[1]; + pixel.z = position[2]; + }); + @endcode + */ + template<typename _Tp, typename Functor> void forEach(const Functor& operation); + /** @overload */ + template<typename _Tp, typename Functor> void forEach(const Functor& operation) const; + +#ifdef CV_CXX_MOVE_SEMANTICS + Mat(Mat&& m); + Mat& operator = (Mat&& m); +#endif + + enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; + enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + //! the matrix dimensionality, >= 2 + int dims; + //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions + int rows, cols; + //! pointer to the data + uchar* data; + + //! helper fields used in locateROI and adjustROI + const uchar* datastart; + const uchar* dataend; + const uchar* datalimit; + + //! custom allocator + MatAllocator* allocator; + //! and the standard allocator + static MatAllocator* getStdAllocator(); + static MatAllocator* getDefaultAllocator(); + static void setDefaultAllocator(MatAllocator* allocator); + + //! internal use method: updates the continuity flag + void updateContinuityFlag(); + + //! interaction with UMat + UMatData* u; + + MatSize size; + MatStep step; + +protected: + template<typename _Tp, typename Functor> void forEach_impl(const Functor& operation); +}; + + +///////////////////////////////// Mat_<_Tp> //////////////////////////////////// + +/** @brief Template matrix class derived from Mat + +@code{.cpp} + template<typename _Tp> class Mat_ : public Mat + { + public: + // ... some specific methods + // and + // no new extra fields + }; +@endcode +The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It does not have any +extra data fields. Nor this class nor Mat has any virtual methods. Thus, references or pointers to +these two classes can be freely but carefully converted one to another. For example: +@code{.cpp} + // create a 100x100 8-bit matrix + Mat M(100,100,CV_8U); + // this will be compiled fine. no any data conversion will be done. + Mat_<float>& M1 = (Mat_<float>&)M; + // the program is likely to crash at the statement below + M1(99,99) = 1.f; +@endcode +While Mat is sufficient in most cases, Mat_ can be more convenient if you use a lot of element +access operations and if you know matrix type at the compilation time. Note that +`Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do absolutely the same +and run at the same speed, but the latter is certainly shorter: +@code{.cpp} + Mat_<double> M(20,20); + for(int i = 0; i < M.rows; i++) + for(int j = 0; j < M.cols; j++) + M(i,j) = 1./(i+j+1); + Mat E, V; + eigen(M,E,V); + cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0); +@endcode +To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter: +@code{.cpp} + // allocate a 320x240 color image and fill it with green (in RGB space) + Mat_<Vec3b> img(240, 320, Vec3b(0,255,0)); + // now draw a diagonal white line + for(int i = 0; i < 100; i++) + img(i,i)=Vec3b(255,255,255); + // and now scramble the 2nd (red) channel of each pixel + for(int i = 0; i < img.rows; i++) + for(int j = 0; j < img.cols; j++) + img(i,j)[2] ^= (uchar)(i ^ j); +@endcode +Mat_ is fully compatible with C++11 range-based for loop. For example such loop +can be used to safely apply look-up table: +@code{.cpp} +void applyTable(Mat_<uchar>& I, const uchar* const table) +{ + for(auto& pixel : I) + { + pixel = table[pixel]; + } +} +@endcode + */ +template<typename _Tp> class Mat_ : public Mat +{ +public: + typedef _Tp value_type; + typedef typename DataType<_Tp>::channel_type channel_type; + typedef MatIterator_<_Tp> iterator; + typedef MatConstIterator_<_Tp> const_iterator; + + //! default constructor + Mat_(); + //! equivalent to Mat(_rows, _cols, DataType<_Tp>::type) + Mat_(int _rows, int _cols); + //! constructor that sets each matrix element to specified value + Mat_(int _rows, int _cols, const _Tp& value); + //! equivalent to Mat(_size, DataType<_Tp>::type) + explicit Mat_(Size _size); + //! constructor that sets each matrix element to specified value + Mat_(Size _size, const _Tp& value); + //! n-dim array constructor + Mat_(int _ndims, const int* _sizes); + //! n-dim array constructor that sets each matrix element to specified value + Mat_(int _ndims, const int* _sizes, const _Tp& value); + //! copy/conversion constructor. If m is of different type, it's converted + Mat_(const Mat& m); + //! copy constructor + Mat_(const Mat_& m); + //! constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type + Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP); + //! constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type + Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0); + //! selects a submatrix + Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all()); + //! selects a submatrix + Mat_(const Mat_& m, const Rect& roi); + //! selects a submatrix, n-dim version + Mat_(const Mat_& m, const Range* ranges); + //! selects a submatrix, n-dim version + Mat_(const Mat_& m, const std::vector<Range>& ranges); + //! from a matrix expression + explicit Mat_(const MatExpr& e); + //! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column + explicit Mat_(const std::vector<_Tp>& vec, bool copyData=false); + template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true); + template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true); + explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true); + explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true); + explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer); + +#ifdef CV_CXX11 + Mat_(std::initializer_list<_Tp> values); + explicit Mat_(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> values); +#endif + +#ifdef CV_CXX_STD_ARRAY + template <std::size_t _Nm> explicit Mat_(const std::array<_Tp, _Nm>& arr, bool copyData=false); +#endif + + Mat_& operator = (const Mat& m); + Mat_& operator = (const Mat_& m); + //! set all the elements to s. + Mat_& operator = (const _Tp& s); + //! assign a matrix expression + Mat_& operator = (const MatExpr& e); + + //! iterators; they are smart enough to skip gaps in the end of rows + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + //! template methods for for operation over all matrix elements. + // the operations take care of skipping gaps in the end of rows (if any) + template<typename Functor> void forEach(const Functor& operation); + template<typename Functor> void forEach(const Functor& operation) const; + + //! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type) + void create(int _rows, int _cols); + //! equivalent to Mat::create(_size, DataType<_Tp>::type) + void create(Size _size); + //! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type) + void create(int _ndims, const int* _sizes); + //! equivalent to Mat::release() + void release(); + //! cross-product + Mat_ cross(const Mat_& m) const; + //! data type conversion + template<typename T2> operator Mat_<T2>() const; + //! overridden forms of Mat::row() etc. + Mat_ row(int y) const; + Mat_ col(int x) const; + Mat_ diag(int d=0) const; + Mat_ clone() const CV_NODISCARD; + + //! overridden forms of Mat::elemSize() etc. + size_t elemSize() const; + size_t elemSize1() const; + int type() const; + int depth() const; + int channels() const; + size_t step1(int i=0) const; + //! returns step()/sizeof(_Tp) + size_t stepT(int i=0) const; + + //! overridden forms of Mat::zeros() etc. Data type is omitted, of course + static MatExpr zeros(int rows, int cols); + static MatExpr zeros(Size size); + static MatExpr zeros(int _ndims, const int* _sizes); + static MatExpr ones(int rows, int cols); + static MatExpr ones(Size size); + static MatExpr ones(int _ndims, const int* _sizes); + static MatExpr eye(int rows, int cols); + static MatExpr eye(Size size); + + //! some more overridden methods + Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright ); + Mat_ operator()( const Range& rowRange, const Range& colRange ) const; + Mat_ operator()( const Rect& roi ) const; + Mat_ operator()( const Range* ranges ) const; + Mat_ operator()(const std::vector<Range>& ranges) const; + + //! more convenient forms of row and element access operators + _Tp* operator [](int y); + const _Tp* operator [](int y) const; + + //! returns reference to the specified element + _Tp& operator ()(const int* idx); + //! returns read-only reference to the specified element + const _Tp& operator ()(const int* idx) const; + + //! returns reference to the specified element + template<int n> _Tp& operator ()(const Vec<int, n>& idx); + //! returns read-only reference to the specified element + template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const; + + //! returns reference to the specified element (1D case) + _Tp& operator ()(int idx0); + //! returns read-only reference to the specified element (1D case) + const _Tp& operator ()(int idx0) const; + //! returns reference to the specified element (2D case) + _Tp& operator ()(int row, int col); + //! returns read-only reference to the specified element (2D case) + const _Tp& operator ()(int row, int col) const; + //! returns reference to the specified element (3D case) + _Tp& operator ()(int idx0, int idx1, int idx2); + //! returns read-only reference to the specified element (3D case) + const _Tp& operator ()(int idx0, int idx1, int idx2) const; + + _Tp& operator ()(Point pt); + const _Tp& operator ()(Point pt) const; + + //! conversion to vector. + operator std::vector<_Tp>() const; + +#ifdef CV_CXX_STD_ARRAY + //! conversion to array. + template<std::size_t _Nm> operator std::array<_Tp, _Nm>() const; +#endif + + //! conversion to Vec + template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const; + //! conversion to Matx + template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const; + +#ifdef CV_CXX_MOVE_SEMANTICS + Mat_(Mat_&& m); + Mat_& operator = (Mat_&& m); + + Mat_(Mat&& m); + Mat_& operator = (Mat&& m); + + Mat_(MatExpr&& e); +#endif +}; + +typedef Mat_<uchar> Mat1b; +typedef Mat_<Vec2b> Mat2b; +typedef Mat_<Vec3b> Mat3b; +typedef Mat_<Vec4b> Mat4b; + +typedef Mat_<short> Mat1s; +typedef Mat_<Vec2s> Mat2s; +typedef Mat_<Vec3s> Mat3s; +typedef Mat_<Vec4s> Mat4s; + +typedef Mat_<ushort> Mat1w; +typedef Mat_<Vec2w> Mat2w; +typedef Mat_<Vec3w> Mat3w; +typedef Mat_<Vec4w> Mat4w; + +typedef Mat_<int> Mat1i; +typedef Mat_<Vec2i> Mat2i; +typedef Mat_<Vec3i> Mat3i; +typedef Mat_<Vec4i> Mat4i; + +typedef Mat_<float> Mat1f; +typedef Mat_<Vec2f> Mat2f; +typedef Mat_<Vec3f> Mat3f; +typedef Mat_<Vec4f> Mat4f; + +typedef Mat_<double> Mat1d; +typedef Mat_<Vec2d> Mat2d; +typedef Mat_<Vec3d> Mat3d; +typedef Mat_<Vec4d> Mat4d; + +/** @todo document */ +class CV_EXPORTS UMat +{ +public: + //! default constructor + UMat(UMatUsageFlags usageFlags = USAGE_DEFAULT); + //! constructs 2D matrix of the specified size and type + // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) + UMat(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + //! constucts 2D matrix and fills it with the specified value _s. + UMat(int rows, int cols, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(Size size, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + + //! constructs n-dimensional matrix + UMat(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(int ndims, const int* sizes, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + + //! copy constructor + UMat(const UMat& m); + + //! creates a matrix header for a part of the bigger matrix + UMat(const UMat& m, const Range& rowRange, const Range& colRange=Range::all()); + UMat(const UMat& m, const Rect& roi); + UMat(const UMat& m, const Range* ranges); + UMat(const UMat& m, const std::vector<Range>& ranges); + //! builds matrix from std::vector with or without copying the data + template<typename _Tp> explicit UMat(const std::vector<_Tp>& vec, bool copyData=false); + + //! builds matrix from cv::Vec; the data is copied by default + template<typename _Tp, int n> explicit UMat(const Vec<_Tp, n>& vec, bool copyData=true); + //! builds matrix from cv::Matx; the data is copied by default + template<typename _Tp, int m, int n> explicit UMat(const Matx<_Tp, m, n>& mtx, bool copyData=true); + //! builds matrix from a 2D point + template<typename _Tp> explicit UMat(const Point_<_Tp>& pt, bool copyData=true); + //! builds matrix from a 3D point + template<typename _Tp> explicit UMat(const Point3_<_Tp>& pt, bool copyData=true); + //! builds matrix from comma initializer + template<typename _Tp> explicit UMat(const MatCommaInitializer_<_Tp>& commaInitializer); + + //! destructor - calls release() + ~UMat(); + //! assignment operators + UMat& operator = (const UMat& m); + + Mat getMat(int flags) const; + + //! returns a new matrix header for the specified row + UMat row(int y) const; + //! returns a new matrix header for the specified column + UMat col(int x) const; + //! ... for the specified row span + UMat rowRange(int startrow, int endrow) const; + UMat rowRange(const Range& r) const; + //! ... for the specified column span + UMat colRange(int startcol, int endcol) const; + UMat colRange(const Range& r) const; + //! ... for the specified diagonal + //! (d=0 - the main diagonal, + //! >0 - a diagonal from the upper half, + //! <0 - a diagonal from the lower half) + UMat diag(int d=0) const; + //! constructs a square diagonal matrix which main diagonal is vector "d" + static UMat diag(const UMat& d); + + //! returns deep copy of the matrix, i.e. the data is copied + UMat clone() const CV_NODISCARD; + //! copies the matrix content to "m". + // It calls m.create(this->size(), this->type()). + void copyTo( OutputArray m ) const; + //! copies those matrix elements to "m" that are marked with non-zero mask elements. + void copyTo( OutputArray m, InputArray mask ) const; + //! converts matrix to another datatype with optional scaling. See cvConvertScale. + void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; + + void assignTo( UMat& m, int type=-1 ) const; + + //! sets every matrix element to s + UMat& operator = (const Scalar& s); + //! sets some of the matrix elements to s, according to the mask + UMat& setTo(InputArray value, InputArray mask=noArray()); + //! creates alternative matrix header for the same data, with different + // number of channels and/or different number of rows. see cvReshape. + UMat reshape(int cn, int rows=0) const; + UMat reshape(int cn, int newndims, const int* newsz) const; + + //! matrix transposition by means of matrix expressions + UMat t() const; + //! matrix inversion by means of matrix expressions + UMat inv(int method=DECOMP_LU) const; + //! per-element matrix multiplication by means of matrix expressions + UMat mul(InputArray m, double scale=1) const; + + //! computes dot-product + double dot(InputArray m) const; + + //! Matlab-style matrix initialization + static UMat zeros(int rows, int cols, int type); + static UMat zeros(Size size, int type); + static UMat zeros(int ndims, const int* sz, int type); + static UMat ones(int rows, int cols, int type); + static UMat ones(Size size, int type); + static UMat ones(int ndims, const int* sz, int type); + static UMat eye(int rows, int cols, int type); + static UMat eye(Size size, int type); + + //! allocates new matrix data unless the matrix already has specified size and type. + // previous data is unreferenced if needed. + void create(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(const std::vector<int>& sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + + //! increases the reference counter; use with care to avoid memleaks + void addref(); + //! decreases reference counter; + // deallocates the data when reference counter reaches 0. + void release(); + + //! deallocates the matrix data + void deallocate(); + //! internal use function; properly re-allocates _size, _step arrays + void copySize(const UMat& m); + + //! locates matrix header within a parent matrix. See below + void locateROI( Size& wholeSize, Point& ofs ) const; + //! moves/resizes the current matrix ROI inside the parent matrix. + UMat& adjustROI( int dtop, int dbottom, int dleft, int dright ); + //! extracts a rectangular sub-matrix + // (this is a generalized form of row, rowRange etc.) + UMat operator()( Range rowRange, Range colRange ) const; + UMat operator()( const Rect& roi ) const; + UMat operator()( const Range* ranges ) const; + UMat operator()(const std::vector<Range>& ranges) const; + + //! returns true iff the matrix data is continuous + // (i.e. when there are no gaps between successive rows). + // similar to CV_IS_MAT_CONT(cvmat->type) + bool isContinuous() const; + + //! returns true if the matrix is a submatrix of another matrix + bool isSubmatrix() const; + + //! returns element size in bytes, + // similar to CV_ELEM_SIZE(cvmat->type) + size_t elemSize() const; + //! returns the size of element channel in bytes. + size_t elemSize1() const; + //! returns element type, similar to CV_MAT_TYPE(cvmat->type) + int type() const; + //! returns element type, similar to CV_MAT_DEPTH(cvmat->type) + int depth() const; + //! returns element type, similar to CV_MAT_CN(cvmat->type) + int channels() const; + //! returns step/elemSize1() + size_t step1(int i=0) const; + //! returns true if matrix data is NULL + bool empty() const; + //! returns the total number of matrix elements + size_t total() const; + + //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise + int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; + +#ifdef CV_CXX_MOVE_SEMANTICS + UMat(UMat&& m); + UMat& operator = (UMat&& m); +#endif + + /*! Returns the OpenCL buffer handle on which UMat operates on. + The UMat instance should be kept alive during the use of the handle to prevent the buffer to be + returned to the OpenCV buffer pool. + */ + void* handle(int accessFlags) const; + void ndoffset(size_t* ofs) const; + + enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; + enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + //! the matrix dimensionality, >= 2 + int dims; + //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions + int rows, cols; + + //! custom allocator + MatAllocator* allocator; + UMatUsageFlags usageFlags; // usage flags for allocator + //! and the standard allocator + static MatAllocator* getStdAllocator(); + + //! internal use method: updates the continuity flag + void updateContinuityFlag(); + + // black-box container of UMat data + UMatData* u; + + // offset of the submatrix (or 0) + size_t offset; + + MatSize size; + MatStep step; + +protected: +}; + + +/////////////////////////// multi-dimensional sparse matrix ////////////////////////// + +/** @brief The class SparseMat represents multi-dimensional sparse numerical arrays. + +Such a sparse array can store elements of any type that Mat can store. *Sparse* means that only +non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its +stored elements can actually become 0. It is up to you to detect such elements and delete them +using SparseMat::erase ). The non-zero elements are stored in a hash table that grows when it is +filled so that the search time is O(1) in average (regardless of whether element is there or not). +Elements can be accessed using the following methods: +- Query operations (SparseMat::ptr and the higher-level SparseMat::ref, SparseMat::value and + SparseMat::find), for example: + @code + const int dims = 5; + int size[5] = {10, 10, 10, 10, 10}; + SparseMat sparse_mat(dims, size, CV_32F); + for(int i = 0; i < 1000; i++) + { + int idx[dims]; + for(int k = 0; k < dims; k++) + idx[k] = rand() % size[k]; + sparse_mat.ref<float>(idx) += 1.f; + } + cout << "nnz = " << sparse_mat.nzcount() << endl; + @endcode +- Sparse matrix iterators. They are similar to MatIterator but different from NAryMatIterator. + That is, the iteration loop is familiar to STL users: + @code + // prints elements of a sparse floating-point matrix + // and the sum of elements. + SparseMatConstIterator_<float> + it = sparse_mat.begin<float>(), + it_end = sparse_mat.end<float>(); + double s = 0; + int dims = sparse_mat.dims(); + for(; it != it_end; ++it) + { + // print element indices and the element value + const SparseMat::Node* n = it.node(); + printf("("); + for(int i = 0; i < dims; i++) + printf("%d%s", n->idx[i], i < dims-1 ? ", " : ")"); + printf(": %g\n", it.value<float>()); + s += *it; + } + printf("Element sum is %g\n", s); + @endcode + If you run this loop, you will notice that elements are not enumerated in a logical order + (lexicographical, and so on). They come in the same order as they are stored in the hash table + (semi-randomly). You may collect pointers to the nodes and sort them to get the proper ordering. + Note, however, that pointers to the nodes may become invalid when you add more elements to the + matrix. This may happen due to possible buffer reallocation. +- Combination of the above 2 methods when you need to process 2 or more sparse matrices + simultaneously. For example, this is how you can compute unnormalized cross-correlation of the 2 + floating-point sparse matrices: + @code + double cross_corr(const SparseMat& a, const SparseMat& b) + { + const SparseMat *_a = &a, *_b = &b; + // if b contains less elements than a, + // it is faster to iterate through b + if(_a->nzcount() > _b->nzcount()) + std::swap(_a, _b); + SparseMatConstIterator_<float> it = _a->begin<float>(), + it_end = _a->end<float>(); + double ccorr = 0; + for(; it != it_end; ++it) + { + // take the next element from the first matrix + float avalue = *it; + const Node* anode = it.node(); + // and try to find an element with the same index in the second matrix. + // since the hash value depends only on the element index, + // reuse the hash value stored in the node + float bvalue = _b->value<float>(anode->idx,&anode->hashval); + ccorr += avalue*bvalue; + } + return ccorr; + } + @endcode + */ +class CV_EXPORTS SparseMat +{ +public: + typedef SparseMatIterator iterator; + typedef SparseMatConstIterator const_iterator; + + enum { MAGIC_VAL=0x42FD0000, MAX_DIM=32, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 }; + + //! the sparse matrix header + struct CV_EXPORTS Hdr + { + Hdr(int _dims, const int* _sizes, int _type); + void clear(); + int refcount; + int dims; + int valueOffset; + size_t nodeSize; + size_t nodeCount; + size_t freeList; + std::vector<uchar> pool; + std::vector<size_t> hashtab; + int size[MAX_DIM]; + }; + + //! sparse matrix node - element of a hash table + struct CV_EXPORTS Node + { + //! hash value + size_t hashval; + //! index of the next node in the same hash table entry + size_t next; + //! index of the matrix element + int idx[MAX_DIM]; + }; + + /** @brief Various SparseMat constructors. + */ + SparseMat(); + + /** @overload + @param dims Array dimensionality. + @param _sizes Sparce matrix size on all dementions. + @param _type Sparse matrix data type. + */ + SparseMat(int dims, const int* _sizes, int _type); + + /** @overload + @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted + to sparse representation. + */ + SparseMat(const SparseMat& m); + + /** @overload + @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted + to sparse representation. + */ + explicit SparseMat(const Mat& m); + + //! the destructor + ~SparseMat(); + + //! assignment operator. This is O(1) operation, i.e. no data is copied + SparseMat& operator = (const SparseMat& m); + //! equivalent to the corresponding constructor + SparseMat& operator = (const Mat& m); + + //! creates full copy of the matrix + SparseMat clone() const CV_NODISCARD; + + //! copies all the data to the destination matrix. All the previous content of m is erased + void copyTo( SparseMat& m ) const; + //! converts sparse matrix to dense matrix. + void copyTo( Mat& m ) const; + //! multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type + void convertTo( SparseMat& m, int rtype, double alpha=1 ) const; + //! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling. + /*! + @param [out] m - output matrix; if it does not have a proper size or type before the operation, + it is reallocated + @param [in] rtype - desired output matrix type or, rather, the depth since the number of channels + are the same as the input has; if rtype is negative, the output matrix will have the + same type as the input. + @param [in] alpha - optional scale factor + @param [in] beta - optional delta added to the scaled values + */ + void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; + + // not used now + void assignTo( SparseMat& m, int type=-1 ) const; + + //! reallocates sparse matrix. + /*! + If the matrix already had the proper size and type, + it is simply cleared with clear(), otherwise, + the old matrix is released (using release()) and the new one is allocated. + */ + void create(int dims, const int* _sizes, int _type); + //! sets all the sparse matrix elements to 0, which means clearing the hash table. + void clear(); + //! manually increments the reference counter to the header. + void addref(); + // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated. + void release(); + + //! converts sparse matrix to the old-style representation; all the elements are copied. + //operator CvSparseMat*() const; + //! returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements) + size_t elemSize() const; + //! returns elemSize()/channels() + size_t elemSize1() const; + + //! returns type of sparse matrix elements + int type() const; + //! returns the depth of sparse matrix elements + int depth() const; + //! returns the number of channels + int channels() const; + + //! returns the array of sizes, or NULL if the matrix is not allocated + const int* size() const; + //! returns the size of i-th matrix dimension (or 0) + int size(int i) const; + //! returns the matrix dimensionality + int dims() const; + //! returns the number of non-zero elements (=the number of hash table nodes) + size_t nzcount() const; + + //! computes the element hash value (1D case) + size_t hash(int i0) const; + //! computes the element hash value (2D case) + size_t hash(int i0, int i1) const; + //! computes the element hash value (3D case) + size_t hash(int i0, int i1, int i2) const; + //! computes the element hash value (nD case) + size_t hash(const int* idx) const; + + //!@{ + /*! + specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case. + return pointer to the matrix element. + - if the element is there (it's non-zero), the pointer to it is returned + - if it's not there and createMissing=false, NULL pointer is returned + - if it's not there and createMissing=true, then the new element + is created and initialized with 0. Pointer to it is returned + - if the optional hashval pointer is not NULL, the element hash value is + not computed, but *hashval is taken instead. + */ + //! returns pointer to the specified element (1D case) + uchar* ptr(int i0, bool createMissing, size_t* hashval=0); + //! returns pointer to the specified element (2D case) + uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0); + //! returns pointer to the specified element (3D case) + uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0); + //! returns pointer to the specified element (nD case) + uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0); + //!@} + + //!@{ + /*! + return read-write reference to the specified sparse matrix element. + + `ref<_Tp>(i0,...[,hashval])` is equivalent to `*(_Tp*)ptr(i0,...,true[,hashval])`. + The methods always return a valid reference. + If the element did not exist, it is created and initialiazed with 0. + */ + //! returns reference to the specified element (1D case) + template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0); + //! returns reference to the specified element (2D case) + template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0); + //! returns reference to the specified element (3D case) + template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); + //! returns reference to the specified element (nD case) + template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0); + //!@} + + //!@{ + /*! + return value of the specified sparse matrix element. + + `value<_Tp>(i0,...[,hashval])` is equivalent to + @code + { const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); } + @endcode + + That is, if the element did not exist, the methods return 0. + */ + //! returns value of the specified element (1D case) + template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const; + //! returns value of the specified element (2D case) + template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const; + //! returns value of the specified element (3D case) + template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const; + //! returns value of the specified element (nD case) + template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const; + //!@} + + //!@{ + /*! + Return pointer to the specified sparse matrix element if it exists + + `find<_Tp>(i0,...[,hashval])` is equivalent to `(_const Tp*)ptr(i0,...false[,hashval])`. + + If the specified element does not exist, the methods return NULL. + */ + //! returns pointer to the specified element (1D case) + template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const; + //! returns pointer to the specified element (2D case) + template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const; + //! returns pointer to the specified element (3D case) + template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const; + //! returns pointer to the specified element (nD case) + template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const; + //!@} + + //! erases the specified element (2D case) + void erase(int i0, int i1, size_t* hashval=0); + //! erases the specified element (3D case) + void erase(int i0, int i1, int i2, size_t* hashval=0); + //! erases the specified element (nD case) + void erase(const int* idx, size_t* hashval=0); + + //!@{ + /*! + return the sparse matrix iterator pointing to the first sparse matrix element + */ + //! returns the sparse matrix iterator at the matrix beginning + SparseMatIterator begin(); + //! returns the sparse matrix iterator at the matrix beginning + template<typename _Tp> SparseMatIterator_<_Tp> begin(); + //! returns the read-only sparse matrix iterator at the matrix beginning + SparseMatConstIterator begin() const; + //! returns the read-only sparse matrix iterator at the matrix beginning + template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const; + //!@} + /*! + return the sparse matrix iterator pointing to the element following the last sparse matrix element + */ + //! returns the sparse matrix iterator at the matrix end + SparseMatIterator end(); + //! returns the read-only sparse matrix iterator at the matrix end + SparseMatConstIterator end() const; + //! returns the typed sparse matrix iterator at the matrix end + template<typename _Tp> SparseMatIterator_<_Tp> end(); + //! returns the typed read-only sparse matrix iterator at the matrix end + template<typename _Tp> SparseMatConstIterator_<_Tp> end() const; + + //! returns the value stored in the sparse martix node + template<typename _Tp> _Tp& value(Node* n); + //! returns the value stored in the sparse martix node + template<typename _Tp> const _Tp& value(const Node* n) const; + + ////////////// some internal-use methods /////////////// + Node* node(size_t nidx); + const Node* node(size_t nidx) const; + + uchar* newNode(const int* idx, size_t hashval); + void removeNode(size_t hidx, size_t nidx, size_t previdx); + void resizeHashTab(size_t newsize); + + int flags; + Hdr* hdr; +}; + + + +///////////////////////////////// SparseMat_<_Tp> //////////////////////////////////// + +/** @brief Template sparse n-dimensional array class derived from SparseMat + +SparseMat_ is a thin wrapper on top of SparseMat created in the same way as Mat_ . It simplifies +notation of some operations: +@code + int sz[] = {10, 20, 30}; + SparseMat_<double> M(3, sz); + ... + M.ref(1, 2, 3) = M(4, 5, 6) + M(7, 8, 9); +@endcode + */ +template<typename _Tp> class SparseMat_ : public SparseMat +{ +public: + typedef SparseMatIterator_<_Tp> iterator; + typedef SparseMatConstIterator_<_Tp> const_iterator; + + //! the default constructor + SparseMat_(); + //! the full constructor equivalent to SparseMat(dims, _sizes, DataType<_Tp>::type) + SparseMat_(int dims, const int* _sizes); + //! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted + SparseMat_(const SparseMat& m); + //! the copy constructor. This is O(1) operation - no data is copied + SparseMat_(const SparseMat_& m); + //! converts dense matrix to the sparse form + SparseMat_(const Mat& m); + //! converts the old-style sparse matrix to the C++ class. All the elements are copied + //SparseMat_(const CvSparseMat* m); + //! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted + SparseMat_& operator = (const SparseMat& m); + //! the assignment operator. This is O(1) operation - no data is copied + SparseMat_& operator = (const SparseMat_& m); + //! converts dense matrix to the sparse form + SparseMat_& operator = (const Mat& m); + + //! makes full copy of the matrix. All the elements are duplicated + SparseMat_ clone() const CV_NODISCARD; + //! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type) + void create(int dims, const int* _sizes); + //! converts sparse matrix to the old-style CvSparseMat. All the elements are copied + //operator CvSparseMat*() const; + + //! returns type of the matrix elements + int type() const; + //! returns depth of the matrix elements + int depth() const; + //! returns the number of channels in each matrix element + int channels() const; + + //! equivalent to SparseMat::ref<_Tp>(i0, hashval) + _Tp& ref(int i0, size_t* hashval=0); + //! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval) + _Tp& ref(int i0, int i1, size_t* hashval=0); + //! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval) + _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); + //! equivalent to SparseMat::ref<_Tp>(idx, hashval) + _Tp& ref(const int* idx, size_t* hashval=0); + + //! equivalent to SparseMat::value<_Tp>(i0, hashval) + _Tp operator()(int i0, size_t* hashval=0) const; + //! equivalent to SparseMat::value<_Tp>(i0, i1, hashval) + _Tp operator()(int i0, int i1, size_t* hashval=0) const; + //! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval) + _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const; + //! equivalent to SparseMat::value<_Tp>(idx, hashval) + _Tp operator()(const int* idx, size_t* hashval=0) const; + + //! returns sparse matrix iterator pointing to the first sparse matrix element + SparseMatIterator_<_Tp> begin(); + //! returns read-only sparse matrix iterator pointing to the first sparse matrix element + SparseMatConstIterator_<_Tp> begin() const; + //! returns sparse matrix iterator pointing to the element following the last sparse matrix element + SparseMatIterator_<_Tp> end(); + //! returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element + SparseMatConstIterator_<_Tp> end() const; +}; + + + +////////////////////////////////// MatConstIterator ////////////////////////////////// + +class CV_EXPORTS MatConstIterator +{ +public: + typedef uchar* value_type; + typedef ptrdiff_t difference_type; + typedef const uchar** pointer; + typedef uchar* reference; + + typedef std::random_access_iterator_tag iterator_category; + + //! default constructor + MatConstIterator(); + //! constructor that sets the iterator to the beginning of the matrix + MatConstIterator(const Mat* _m); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator(const Mat* _m, int _row, int _col=0); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator(const Mat* _m, Point _pt); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator(const Mat* _m, const int* _idx); + //! copy constructor + MatConstIterator(const MatConstIterator& it); + + //! copy operator + MatConstIterator& operator = (const MatConstIterator& it); + //! returns the current matrix element + const uchar* operator *() const; + //! returns the i-th matrix element, relative to the current + const uchar* operator [](ptrdiff_t i) const; + + //! shifts the iterator forward by the specified number of elements + MatConstIterator& operator += (ptrdiff_t ofs); + //! shifts the iterator backward by the specified number of elements + MatConstIterator& operator -= (ptrdiff_t ofs); + //! decrements the iterator + MatConstIterator& operator --(); + //! decrements the iterator + MatConstIterator operator --(int); + //! increments the iterator + MatConstIterator& operator ++(); + //! increments the iterator + MatConstIterator operator ++(int); + //! returns the current iterator position + Point pos() const; + //! returns the current iterator position + void pos(int* _idx) const; + + ptrdiff_t lpos() const; + void seek(ptrdiff_t ofs, bool relative = false); + void seek(const int* _idx, bool relative = false); + + const Mat* m; + size_t elemSize; + const uchar* ptr; + const uchar* sliceStart; + const uchar* sliceEnd; +}; + + + +////////////////////////////////// MatConstIterator_ ///////////////////////////////// + +/** @brief Matrix read-only iterator + */ +template<typename _Tp> +class MatConstIterator_ : public MatConstIterator +{ +public: + typedef _Tp value_type; + typedef ptrdiff_t difference_type; + typedef const _Tp* pointer; + typedef const _Tp& reference; + + typedef std::random_access_iterator_tag iterator_category; + + //! default constructor + MatConstIterator_(); + //! constructor that sets the iterator to the beginning of the matrix + MatConstIterator_(const Mat_<_Tp>* _m); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator_(const Mat_<_Tp>* _m, Point _pt); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx); + //! copy constructor + MatConstIterator_(const MatConstIterator_& it); + + //! copy operator + MatConstIterator_& operator = (const MatConstIterator_& it); + //! returns the current matrix element + const _Tp& operator *() const; + //! returns the i-th matrix element, relative to the current + const _Tp& operator [](ptrdiff_t i) const; + + //! shifts the iterator forward by the specified number of elements + MatConstIterator_& operator += (ptrdiff_t ofs); + //! shifts the iterator backward by the specified number of elements + MatConstIterator_& operator -= (ptrdiff_t ofs); + //! decrements the iterator + MatConstIterator_& operator --(); + //! decrements the iterator + MatConstIterator_ operator --(int); + //! increments the iterator + MatConstIterator_& operator ++(); + //! increments the iterator + MatConstIterator_ operator ++(int); + //! returns the current iterator position + Point pos() const; +}; + + + +//////////////////////////////////// MatIterator_ //////////////////////////////////// + +/** @brief Matrix read-write iterator +*/ +template<typename _Tp> +class MatIterator_ : public MatConstIterator_<_Tp> +{ +public: + typedef _Tp* pointer; + typedef _Tp& reference; + + typedef std::random_access_iterator_tag iterator_category; + + //! the default constructor + MatIterator_(); + //! constructor that sets the iterator to the beginning of the matrix + MatIterator_(Mat_<_Tp>* _m); + //! constructor that sets the iterator to the specified element of the matrix + MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0); + //! constructor that sets the iterator to the specified element of the matrix + MatIterator_(Mat_<_Tp>* _m, Point _pt); + //! constructor that sets the iterator to the specified element of the matrix + MatIterator_(Mat_<_Tp>* _m, const int* _idx); + //! copy constructor + MatIterator_(const MatIterator_& it); + //! copy operator + MatIterator_& operator = (const MatIterator_<_Tp>& it ); + + //! returns the current matrix element + _Tp& operator *() const; + //! returns the i-th matrix element, relative to the current + _Tp& operator [](ptrdiff_t i) const; + + //! shifts the iterator forward by the specified number of elements + MatIterator_& operator += (ptrdiff_t ofs); + //! shifts the iterator backward by the specified number of elements + MatIterator_& operator -= (ptrdiff_t ofs); + //! decrements the iterator + MatIterator_& operator --(); + //! decrements the iterator + MatIterator_ operator --(int); + //! increments the iterator + MatIterator_& operator ++(); + //! increments the iterator + MatIterator_ operator ++(int); +}; + + + +/////////////////////////////// SparseMatConstIterator /////////////////////////////// + +/** @brief Read-Only Sparse Matrix Iterator. + + Here is how to use the iterator to compute the sum of floating-point sparse matrix elements: + + \code + SparseMatConstIterator it = m.begin(), it_end = m.end(); + double s = 0; + CV_Assert( m.type() == CV_32F ); + for( ; it != it_end; ++it ) + s += it.value<float>(); + \endcode +*/ +class CV_EXPORTS SparseMatConstIterator +{ +public: + //! the default constructor + SparseMatConstIterator(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatConstIterator(const SparseMat* _m); + //! the copy constructor + SparseMatConstIterator(const SparseMatConstIterator& it); + + //! the assignment operator + SparseMatConstIterator& operator = (const SparseMatConstIterator& it); + + //! template method returning the current matrix element + template<typename _Tp> const _Tp& value() const; + //! returns the current node of the sparse matrix. it.node->idx is the current element index + const SparseMat::Node* node() const; + + //! moves iterator to the previous element + SparseMatConstIterator& operator --(); + //! moves iterator to the previous element + SparseMatConstIterator operator --(int); + //! moves iterator to the next element + SparseMatConstIterator& operator ++(); + //! moves iterator to the next element + SparseMatConstIterator operator ++(int); + + //! moves iterator to the element after the last element + void seekEnd(); + + const SparseMat* m; + size_t hashidx; + uchar* ptr; +}; + + + +////////////////////////////////// SparseMatIterator ///////////////////////////////// + +/** @brief Read-write Sparse Matrix Iterator + + The class is similar to cv::SparseMatConstIterator, + but can be used for in-place modification of the matrix elements. +*/ +class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator +{ +public: + //! the default constructor + SparseMatIterator(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatIterator(SparseMat* _m); + //! the full constructor setting the iterator to the specified sparse matrix element + SparseMatIterator(SparseMat* _m, const int* idx); + //! the copy constructor + SparseMatIterator(const SparseMatIterator& it); + + //! the assignment operator + SparseMatIterator& operator = (const SparseMatIterator& it); + //! returns read-write reference to the current sparse matrix element + template<typename _Tp> _Tp& value() const; + //! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!) + SparseMat::Node* node() const; + + //! moves iterator to the next element + SparseMatIterator& operator ++(); + //! moves iterator to the next element + SparseMatIterator operator ++(int); +}; + + + +/////////////////////////////// SparseMatConstIterator_ ////////////////////////////// + +/** @brief Template Read-Only Sparse Matrix Iterator Class. + + This is the derived from SparseMatConstIterator class that + introduces more convenient operator *() for accessing the current element. +*/ +template<typename _Tp> class SparseMatConstIterator_ : public SparseMatConstIterator +{ +public: + + typedef std::forward_iterator_tag iterator_category; + + //! the default constructor + SparseMatConstIterator_(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatConstIterator_(const SparseMat_<_Tp>* _m); + SparseMatConstIterator_(const SparseMat* _m); + //! the copy constructor + SparseMatConstIterator_(const SparseMatConstIterator_& it); + + //! the assignment operator + SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it); + //! the element access operator + const _Tp& operator *() const; + + //! moves iterator to the next element + SparseMatConstIterator_& operator ++(); + //! moves iterator to the next element + SparseMatConstIterator_ operator ++(int); +}; + + + +///////////////////////////////// SparseMatIterator_ ///////////////////////////////// + +/** @brief Template Read-Write Sparse Matrix Iterator Class. + + This is the derived from cv::SparseMatConstIterator_ class that + introduces more convenient operator *() for accessing the current element. +*/ +template<typename _Tp> class SparseMatIterator_ : public SparseMatConstIterator_<_Tp> +{ +public: + + typedef std::forward_iterator_tag iterator_category; + + //! the default constructor + SparseMatIterator_(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatIterator_(SparseMat_<_Tp>* _m); + SparseMatIterator_(SparseMat* _m); + //! the copy constructor + SparseMatIterator_(const SparseMatIterator_& it); + + //! the assignment operator + SparseMatIterator_& operator = (const SparseMatIterator_& it); + //! returns the reference to the current element + _Tp& operator *() const; + + //! moves the iterator to the next element + SparseMatIterator_& operator ++(); + //! moves the iterator to the next element + SparseMatIterator_ operator ++(int); +}; + + + +/////////////////////////////////// NAryMatIterator ////////////////////////////////// + +/** @brief n-ary multi-dimensional array iterator. + +Use the class to implement unary, binary, and, generally, n-ary element-wise operations on +multi-dimensional arrays. Some of the arguments of an n-ary function may be continuous arrays, some +may be not. It is possible to use conventional MatIterator 's for each array but incrementing all of +the iterators after each small operations may be a big overhead. In this case consider using +NAryMatIterator to iterate through several matrices simultaneously as long as they have the same +geometry (dimensionality and all the dimension sizes are the same). On each iteration `it.planes[0]`, +`it.planes[1]`,... will be the slices of the corresponding matrices. + +The example below illustrates how you can compute a normalized and threshold 3D color histogram: +@code + void computeNormalizedColorHist(const Mat& image, Mat& hist, int N, double minProb) + { + const int histSize[] = {N, N, N}; + + // make sure that the histogram has a proper size and type + hist.create(3, histSize, CV_32F); + + // and clear it + hist = Scalar(0); + + // the loop below assumes that the image + // is a 8-bit 3-channel. check it. + CV_Assert(image.type() == CV_8UC3); + MatConstIterator_<Vec3b> it = image.begin<Vec3b>(), + it_end = image.end<Vec3b>(); + for( ; it != it_end; ++it ) + { + const Vec3b& pix = *it; + hist.at<float>(pix[0]*N/256, pix[1]*N/256, pix[2]*N/256) += 1.f; + } + + minProb *= image.rows*image.cols; + + // initialize iterator (the style is different from STL). + // after initialization the iterator will contain + // the number of slices or planes the iterator will go through. + // it simultaneously increments iterators for several matrices + // supplied as a null terminated list of pointers + const Mat* arrays[] = {&hist, 0}; + Mat planes[1]; + NAryMatIterator itNAry(arrays, planes, 1); + double s = 0; + // iterate through the matrix. on each iteration + // itNAry.planes[i] (of type Mat) will be set to the current plane + // of the i-th n-dim matrix passed to the iterator constructor. + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) + { + threshold(itNAry.planes[0], itNAry.planes[0], minProb, 0, THRESH_TOZERO); + s += sum(itNAry.planes[0])[0]; + } + + s = 1./s; + itNAry = NAryMatIterator(arrays, planes, 1); + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) + itNAry.planes[0] *= s; + } +@endcode + */ +class CV_EXPORTS NAryMatIterator +{ +public: + //! the default constructor + NAryMatIterator(); + //! the full constructor taking arbitrary number of n-dim matrices + NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1); + //! the full constructor taking arbitrary number of n-dim matrices + NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1); + //! the separate iterator initialization method + void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1); + + //! proceeds to the next plane of every iterated matrix + NAryMatIterator& operator ++(); + //! proceeds to the next plane of every iterated matrix (postfix increment operator) + NAryMatIterator operator ++(int); + + //! the iterated arrays + const Mat** arrays; + //! the current planes + Mat* planes; + //! data pointers + uchar** ptrs; + //! the number of arrays + int narrays; + //! the number of hyper-planes that the iterator steps through + size_t nplanes; + //! the size of each segment (in elements) + size_t size; +protected: + int iterdepth; + size_t idx; +}; + + + +///////////////////////////////// Matrix Expressions ///////////////////////////////// + +class CV_EXPORTS MatOp +{ +public: + MatOp(); + virtual ~MatOp(); + + virtual bool elementWise(const MatExpr& expr) const; + virtual void assign(const MatExpr& expr, Mat& m, int type=-1) const = 0; + virtual void roi(const MatExpr& expr, const Range& rowRange, + const Range& colRange, MatExpr& res) const; + virtual void diag(const MatExpr& expr, int d, MatExpr& res) const; + virtual void augAssignAdd(const MatExpr& expr, Mat& m) const; + virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const; + virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const; + virtual void augAssignDivide(const MatExpr& expr, Mat& m) const; + virtual void augAssignAnd(const MatExpr& expr, Mat& m) const; + virtual void augAssignOr(const MatExpr& expr, Mat& m) const; + virtual void augAssignXor(const MatExpr& expr, Mat& m) const; + + virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; + virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const; + + virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; + virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const; + + virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const; + virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const; + + virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const; + virtual void divide(double s, const MatExpr& expr, MatExpr& res) const; + + virtual void abs(const MatExpr& expr, MatExpr& res) const; + + virtual void transpose(const MatExpr& expr, MatExpr& res) const; + virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; + virtual void invert(const MatExpr& expr, int method, MatExpr& res) const; + + virtual Size size(const MatExpr& expr) const; + virtual int type(const MatExpr& expr) const; +}; + +/** @brief Matrix expression representation +@anchor MatrixExpressions +This is a list of implemented matrix operations that can be combined in arbitrary complex +expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a +real-valued scalar ( double )): +- Addition, subtraction, negation: `A+B`, `A-B`, `A+s`, `A-s`, `s+A`, `s-A`, `-A` +- Scaling: `A*alpha` +- Per-element multiplication and division: `A.mul(B)`, `A/B`, `alpha/A` +- Matrix multiplication: `A*B` +- Transposition: `A.t()` (means A<sup>T</sup>) +- Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems: + `A.inv([method]) (~ A<sup>-1</sup>)`, `A.inv([method])*B (~ X: AX=B)` +- Comparison: `A cmpop B`, `A cmpop alpha`, `alpha cmpop A`, where *cmpop* is one of + `>`, `>=`, `==`, `!=`, `<=`, `<`. The result of comparison is an 8-bit single channel mask whose + elements are set to 255 (if the particular element or pair of elements satisfy the condition) or + 0. +- Bitwise logical operations: `A logicop B`, `A logicop s`, `s logicop A`, `~A`, where *logicop* is one of + `&`, `|`, `^`. +- Element-wise minimum and maximum: `min(A, B)`, `min(A, alpha)`, `max(A, B)`, `max(A, alpha)` +- Element-wise absolute value: `abs(A)` +- Cross-product, dot-product: `A.cross(B)`, `A.dot(B)` +- Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm, + mean, sum, countNonZero, trace, determinant, repeat, and others. +- Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated + initializers, matrix constructors and operators that extract sub-matrices (see Mat description). +- Mat_<destination_type>() constructors to cast the result to the proper type. +@note Comma-separated initializers and probably some other operations may require additional +explicit Mat() or Mat_<T>() constructor calls to resolve a possible ambiguity. + +Here are examples of matrix expressions: +@code + // compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD) + SVD svd(A); + Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t(); + + // compute the new vector of parameters in the Levenberg-Marquardt algorithm + x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err); + + // sharpen image using "unsharp mask" algorithm + Mat blurred; double sigma = 1, threshold = 5, amount = 1; + GaussianBlur(img, blurred, Size(), sigma, sigma); + Mat lowContrastMask = abs(img - blurred) < threshold; + Mat sharpened = img*(1+amount) + blurred*(-amount); + img.copyTo(sharpened, lowContrastMask); +@endcode +*/ +class CV_EXPORTS MatExpr +{ +public: + MatExpr(); + explicit MatExpr(const Mat& m); + + MatExpr(const MatOp* _op, int _flags, const Mat& _a = Mat(), const Mat& _b = Mat(), + const Mat& _c = Mat(), double _alpha = 1, double _beta = 1, const Scalar& _s = Scalar()); + + operator Mat() const; + template<typename _Tp> operator Mat_<_Tp>() const; + + Size size() const; + int type() const; + + MatExpr row(int y) const; + MatExpr col(int x) const; + MatExpr diag(int d = 0) const; + MatExpr operator()( const Range& rowRange, const Range& colRange ) const; + MatExpr operator()( const Rect& roi ) const; + + MatExpr t() const; + MatExpr inv(int method = DECOMP_LU) const; + MatExpr mul(const MatExpr& e, double scale=1) const; + MatExpr mul(const Mat& m, double scale=1) const; + + Mat cross(const Mat& m) const; + double dot(const Mat& m) const; + + const MatOp* op; + int flags; + + Mat a, b, c; + double alpha, beta; + Scalar s; +}; + +//! @} core_basic + +//! @relates cv::MatExpr +//! @{ +CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a); +CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s); +CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e); +CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2); +template<typename _Tp, int m, int n> static inline +MatExpr operator + (const Mat& a, const Matx<_Tp, m, n>& b) { return a + Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator + (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) + b; } + +CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a); +CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s); +CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e); +CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2); +template<typename _Tp, int m, int n> static inline +MatExpr operator - (const Mat& a, const Matx<_Tp, m, n>& b) { return a - Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator - (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) - b; } + +CV_EXPORTS MatExpr operator - (const Mat& m); +CV_EXPORTS MatExpr operator - (const MatExpr& e); + +CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator * (const Mat& a, double s); +CV_EXPORTS MatExpr operator * (double s, const Mat& a); +CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator * (const MatExpr& e, double s); +CV_EXPORTS MatExpr operator * (double s, const MatExpr& e); +CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2); +template<typename _Tp, int m, int n> static inline +MatExpr operator * (const Mat& a, const Matx<_Tp, m, n>& b) { return a * Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator * (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) * b; } + +CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator / (const Mat& a, double s); +CV_EXPORTS MatExpr operator / (double s, const Mat& a); +CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator / (const MatExpr& e, double s); +CV_EXPORTS MatExpr operator / (double s, const MatExpr& e); +CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2); +template<typename _Tp, int m, int n> static inline +MatExpr operator / (const Mat& a, const Matx<_Tp, m, n>& b) { return a / Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator / (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) / b; } + +CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator < (const Mat& a, double s); +CV_EXPORTS MatExpr operator < (double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator < (const Mat& a, const Matx<_Tp, m, n>& b) { return a < Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator < (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) < b; } + +CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator <= (const Mat& a, double s); +CV_EXPORTS MatExpr operator <= (double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator <= (const Mat& a, const Matx<_Tp, m, n>& b) { return a <= Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator <= (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) <= b; } + +CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator == (const Mat& a, double s); +CV_EXPORTS MatExpr operator == (double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator == (const Mat& a, const Matx<_Tp, m, n>& b) { return a == Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator == (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) == b; } + +CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator != (const Mat& a, double s); +CV_EXPORTS MatExpr operator != (double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator != (const Mat& a, const Matx<_Tp, m, n>& b) { return a != Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator != (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) != b; } + +CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator >= (const Mat& a, double s); +CV_EXPORTS MatExpr operator >= (double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator >= (const Mat& a, const Matx<_Tp, m, n>& b) { return a >= Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator >= (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) >= b; } + +CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator > (const Mat& a, double s); +CV_EXPORTS MatExpr operator > (double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator > (const Mat& a, const Matx<_Tp, m, n>& b) { return a > Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator > (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) > b; } + +CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator & (const Mat& a, const Matx<_Tp, m, n>& b) { return a & Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator & (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) & b; } + +CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator | (const Mat& a, const Matx<_Tp, m, n>& b) { return a | Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator | (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) | b; } + +CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr operator ^ (const Mat& a, const Matx<_Tp, m, n>& b) { return a ^ Mat(b); } +template<typename _Tp, int m, int n> static inline +MatExpr operator ^ (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) ^ b; } + +CV_EXPORTS MatExpr operator ~(const Mat& m); + +CV_EXPORTS MatExpr min(const Mat& a, const Mat& b); +CV_EXPORTS MatExpr min(const Mat& a, double s); +CV_EXPORTS MatExpr min(double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr min (const Mat& a, const Matx<_Tp, m, n>& b) { return min(a, Mat(b)); } +template<typename _Tp, int m, int n> static inline +MatExpr min (const Matx<_Tp, m, n>& a, const Mat& b) { return min(Mat(a), b); } + +CV_EXPORTS MatExpr max(const Mat& a, const Mat& b); +CV_EXPORTS MatExpr max(const Mat& a, double s); +CV_EXPORTS MatExpr max(double s, const Mat& a); +template<typename _Tp, int m, int n> static inline +MatExpr max (const Mat& a, const Matx<_Tp, m, n>& b) { return max(a, Mat(b)); } +template<typename _Tp, int m, int n> static inline +MatExpr max (const Matx<_Tp, m, n>& a, const Mat& b) { return max(Mat(a), b); } + +/** @brief Calculates an absolute value of each matrix element. + +abs is a meta-function that is expanded to one of absdiff or convertScaleAbs forms: +- C = abs(A-B) is equivalent to `absdiff(A, B, C)` +- C = abs(A) is equivalent to `absdiff(A, Scalar::all(0), C)` +- C = `Mat_<Vec<uchar,n> >(abs(A*alpha + beta))` is equivalent to `convertScaleAbs(A, C, alpha, +beta)` + +The output matrix has the same size and the same type as the input one except for the last case, +where C is depth=CV_8U . +@param m matrix. +@sa @ref MatrixExpressions, absdiff, convertScaleAbs + */ +CV_EXPORTS MatExpr abs(const Mat& m); +/** @overload +@param e matrix expression. +*/ +CV_EXPORTS MatExpr abs(const MatExpr& e); +//! @} relates cv::MatExpr + +} // cv + +#include "opencv2/core/mat.inl.hpp" + +#endif // OPENCV_CORE_MAT_HPP diff --git a/include/opencv2/core/mat.inl.hpp b/include/opencv2/core/mat.inl.hpp new file mode 100644 index 0000000..a2e7923 --- /dev/null +++ b/include/opencv2/core/mat.inl.hpp @@ -0,0 +1,4027 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_MATRIX_OPERATIONS_HPP +#define OPENCV_CORE_MATRIX_OPERATIONS_HPP + +#ifndef __cplusplus +# error mat.inl.hpp header must be compiled as C++ +#endif + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4127 ) +#endif + +namespace cv +{ +CV__DEBUG_NS_BEGIN + + +//! @cond IGNORED + +////////////////////////// Custom (raw) type wrapper ////////////////////////// + +template<typename _Tp> static inline +int rawType() +{ + CV_StaticAssert(sizeof(_Tp) <= CV_CN_MAX, "sizeof(_Tp) is too large"); + const int elemSize = sizeof(_Tp); + return (int)CV_MAKETYPE(CV_8U, elemSize); +} + +//////////////////////// Input/Output Arrays //////////////////////// + +inline void _InputArray::init(int _flags, const void* _obj) +{ flags = _flags; obj = (void*)_obj; } + +inline void _InputArray::init(int _flags, const void* _obj, Size _sz) +{ flags = _flags; obj = (void*)_obj; sz = _sz; } + +inline void* _InputArray::getObj() const { return obj; } +inline int _InputArray::getFlags() const { return flags; } +inline Size _InputArray::getSz() const { return sz; } + +inline _InputArray::_InputArray() { init(NONE, 0); } +inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); } +inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); } +inline _InputArray::_InputArray(const std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); } +inline _InputArray::_InputArray(const UMat& m) { init(UMAT+ACCESS_READ, &m); } +inline _InputArray::_InputArray(const std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_READ, &vec); } + +template<typename _Tp> inline +_InputArray::_InputArray(const std::vector<_Tp>& vec) +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_InputArray::_InputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); } + +template<std::size_t _Nm> inline +_InputArray::_InputArray(const std::array<Mat, _Nm>& arr) +{ init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); } +#endif + +inline +_InputArray::_InputArray(const std::vector<bool>& vec) +{ init(FIXED_TYPE + STD_BOOL_VECTOR + traits::Type<bool>::value + ACCESS_READ, &vec); } + +template<typename _Tp> inline +_InputArray::_InputArray(const std::vector<std::vector<_Tp> >& vec) +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +inline +_InputArray::_InputArray(const std::vector<std::vector<bool> >&) +{ CV_Error(Error::StsUnsupportedFormat, "std::vector<std::vector<bool> > is not supported!\n"); } + +template<typename _Tp> inline +_InputArray::_InputArray(const std::vector<Mat_<_Tp> >& vec) +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +template<typename _Tp, int m, int n> inline +_InputArray::_InputArray(const Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, &mtx, Size(n, m)); } + +template<typename _Tp> inline +_InputArray::_InputArray(const _Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); } + +template<typename _Tp> inline +_InputArray::_InputArray(const Mat_<_Tp>& m) +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_READ, &m); } + +inline _InputArray::_InputArray(const double& val) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); } + +inline _InputArray::_InputArray(const MatExpr& expr) +{ init(FIXED_TYPE + FIXED_SIZE + EXPR + ACCESS_READ, &expr); } + +inline _InputArray::_InputArray(const cuda::GpuMat& d_mat) +{ init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); } + +inline _InputArray::_InputArray(const std::vector<cuda::GpuMat>& d_mat) +{ init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_READ, &d_mat);} + +inline _InputArray::_InputArray(const ogl::Buffer& buf) +{ init(OPENGL_BUFFER + ACCESS_READ, &buf); } + +inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem) +{ init(CUDA_HOST_MEM + ACCESS_READ, &cuda_mem); } + +template<typename _Tp> inline +_InputArray _InputArray::rawIn(const std::vector<_Tp>& vec) +{ + _InputArray v; + v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_READ; + v.obj = (void*)&vec; + return v; +} + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_InputArray _InputArray::rawIn(const std::array<_Tp, _Nm>& arr) +{ + _InputArray v; + v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ; + v.obj = (void*)arr.data(); + v.sz = Size(1, _Nm); + return v; +} +#endif + +inline _InputArray::~_InputArray() {} + +inline Mat _InputArray::getMat(int i) const +{ + if( kind() == MAT && i < 0 ) + return *(const Mat*)obj; + return getMat_(i); +} + +inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; } +inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; } +inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; } +inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; } +inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; } +inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR || + kind() == _InputArray::STD_BOOL_VECTOR || + kind() == _InputArray::STD_ARRAY; } +inline bool _InputArray::isGpuMat() const { return kind() == _InputArray::CUDA_GPU_MAT; } +inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; } + +//////////////////////////////////////////////////////////////////////////////////////// + +inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); } +inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags|ACCESS_WRITE, _obj); } +inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); } +inline _OutputArray::_OutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_WRITE, &vec); } +inline _OutputArray::_OutputArray(UMat& m) { init(UMAT+ACCESS_WRITE, &m); } +inline _OutputArray::_OutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_WRITE, &vec); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(std::vector<_Tp>& vec) +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template<std::size_t _Nm> inline +_OutputArray::_OutputArray(std::array<Mat, _Nm>& arr) +{ init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } +#endif + +inline +_OutputArray::_OutputArray(std::vector<bool>&) +{ CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an output array\n"); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(std::vector<std::vector<_Tp> >& vec) +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +inline +_OutputArray::_OutputArray(std::vector<std::vector<bool> >&) +{ CV_Error(Error::StsUnsupportedFormat, "std::vector<std::vector<bool> > cannot be an output array\n"); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(std::vector<Mat_<_Tp> >& vec) +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(Mat_<_Tp>& m) +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); } + +template<typename _Tp, int m, int n> inline +_OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(_Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(const std::vector<_Tp>& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template<std::size_t _Nm> inline +_OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr) +{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } +#endif + +template<typename _Tp> inline +_OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(const std::vector<Mat_<_Tp> >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(const Mat_<_Tp>& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); } + +template<typename _Tp, int m, int n> inline +_OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); } + +template<typename _Tp> inline +_OutputArray::_OutputArray(const _Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); } + +inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat) +{ init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } + +inline _OutputArray::_OutputArray(std::vector<cuda::GpuMat>& d_mat) +{ init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_WRITE, &d_mat);} + +inline _OutputArray::_OutputArray(ogl::Buffer& buf) +{ init(OPENGL_BUFFER + ACCESS_WRITE, &buf); } + +inline _OutputArray::_OutputArray(cuda::HostMem& cuda_mem) +{ init(CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); } + +inline _OutputArray::_OutputArray(const Mat& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_WRITE, &m); } + +inline _OutputArray::_OutputArray(const std::vector<Mat>& vec) +{ init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_WRITE, &vec); } + +inline _OutputArray::_OutputArray(const UMat& m) +{ init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_WRITE, &m); } + +inline _OutputArray::_OutputArray(const std::vector<UMat>& vec) +{ init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_WRITE, &vec); } + +inline _OutputArray::_OutputArray(const cuda::GpuMat& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } + + +inline _OutputArray::_OutputArray(const ogl::Buffer& buf) +{ init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_WRITE, &buf); } + +inline _OutputArray::_OutputArray(const cuda::HostMem& cuda_mem) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); } + +template<typename _Tp> inline +_OutputArray _OutputArray::rawOut(std::vector<_Tp>& vec) +{ + _OutputArray v; + v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_WRITE; + v.obj = (void*)&vec; + return v; +} + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr) +{ + _OutputArray v; + v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE; + v.obj = (void*)arr.data(); + v.sz = Size(1, _Nm); + return v; +} +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); } +inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags|ACCESS_RW, _obj); } +inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); } +inline _InputOutputArray::_InputOutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); } +inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); } +inline _InputOutputArray::_InputOutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_RW, &vec); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec) +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template<std::size_t _Nm> inline +_InputOutputArray::_InputOutputArray(std::array<Mat, _Nm>& arr) +{ init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } +#endif + +inline _InputOutputArray::_InputOutputArray(std::vector<bool>&) +{ CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an input/output array\n"); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(std::vector<std::vector<_Tp> >& vec) +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(std::vector<Mat_<_Tp> >& vec) +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(Mat_<_Tp>& m) +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); } + +template<typename _Tp, int m, int n> inline +_InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(_Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template<std::size_t _Nm> inline +_InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr) +{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } +#endif + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(const std::vector<std::vector<_Tp> >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(const std::vector<Mat_<_Tp> >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); } + +template<typename _Tp, int m, int n> inline +_InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); } + +template<typename _Tp> inline +_InputOutputArray::_InputOutputArray(const _Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); } + +inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat) +{ init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); } + +inline _InputOutputArray::_InputOutputArray(ogl::Buffer& buf) +{ init(OPENGL_BUFFER + ACCESS_RW, &buf); } + +inline _InputOutputArray::_InputOutputArray(cuda::HostMem& cuda_mem) +{ init(CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } + +inline _InputOutputArray::_InputOutputArray(const Mat& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_RW, &m); } + +inline _InputOutputArray::_InputOutputArray(const std::vector<Mat>& vec) +{ init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_RW, &vec); } + +inline _InputOutputArray::_InputOutputArray(const UMat& m) +{ init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_RW, &m); } + +inline _InputOutputArray::_InputOutputArray(const std::vector<UMat>& vec) +{ init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_RW, &vec); } + +inline _InputOutputArray::_InputOutputArray(const cuda::GpuMat& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_RW, &d_mat); } + +inline _InputOutputArray::_InputOutputArray(const std::vector<cuda::GpuMat>& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} + +template<> inline _InputOutputArray::_InputOutputArray(std::vector<cuda::GpuMat>& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} + +inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf) +{ init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_RW, &buf); } + +inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } + +template<typename _Tp> inline +_InputOutputArray _InputOutputArray::rawInOut(std::vector<_Tp>& vec) +{ + _InputOutputArray v; + v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_RW; + v.obj = (void*)&vec; + return v; +} + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +_InputOutputArray _InputOutputArray::rawInOut(std::array<_Tp, _Nm>& arr) +{ + _InputOutputArray v; + v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW; + v.obj = (void*)arr.data(); + v.sz = Size(1, _Nm); + return v; +} +#endif + + +template<typename _Tp> static inline _InputArray rawIn(_Tp& v) { return _InputArray::rawIn(v); } +template<typename _Tp> static inline _OutputArray rawOut(_Tp& v) { return _OutputArray::rawOut(v); } +template<typename _Tp> static inline _InputOutputArray rawInOut(_Tp& v) { return _InputOutputArray::rawInOut(v); } + +CV__DEBUG_NS_END + +//////////////////////////////////////////// Mat ////////////////////////////////////////// + +inline +Mat::Mat() + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{} + +inline +Mat::Mat(int _rows, int _cols, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_rows, _cols, _type); +} + +inline +Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_rows, _cols, _type); + *this = _s; +} + +inline +Mat::Mat(Size _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create( _sz.height, _sz.width, _type ); +} + +inline +Mat::Mat(Size _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz.height, _sz.width, _type); + *this = _s; +} + +inline +Mat::Mat(int _dims, const int* _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_dims, _sz, _type); +} + +inline +Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_dims, _sz, _type); + *this = _s; +} + +inline +Mat::Mat(const std::vector<int>& _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz, _type); +} + +inline +Mat::Mat(const std::vector<int>& _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz, _type); + *this = _s; +} + +inline +Mat::Mat(const Mat& m) + : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), + datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), + u(m.u), size(&rows), step(0) +{ + if( u ) + CV_XADD(&u->refcount, 1); + if( m.dims <= 2 ) + { + step[0] = m.step[0]; step[1] = m.step[1]; + } + else + { + dims = 0; + copySize(m); + } +} + +inline +Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) + : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_rows), cols(_cols), + data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), + allocator(0), u(0), size(&rows) +{ + CV_Assert(total() == 0 || data != NULL); + + size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); + size_t minstep = cols * esz; + if( _step == AUTO_STEP ) + { + _step = minstep; + } + else + { + CV_DbgAssert( _step >= minstep ); + if (_step % esz1 != 0) + { + CV_Error(Error::BadStep, "Step must be a multiple of esz1"); + } + } + step[0] = _step; + step[1] = esz; + datalimit = datastart + _step * rows; + dataend = datalimit - _step + minstep; + updateContinuityFlag(); +} + +inline +Mat::Mat(Size _sz, int _type, void* _data, size_t _step) + : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_sz.height), cols(_sz.width), + data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), + allocator(0), u(0), size(&rows) +{ + CV_Assert(total() == 0 || data != NULL); + + size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); + size_t minstep = cols*esz; + if( _step == AUTO_STEP ) + { + _step = minstep; + } + else + { + CV_DbgAssert( _step >= minstep ); + + if (_step % esz1 != 0) + { + CV_Error(Error::BadStep, "Step must be a multiple of esz1"); + } + } + step[0] = _step; + step[1] = esz; + datalimit = datastart + _step*rows; + dataend = datalimit - _step + minstep; + updateContinuityFlag(); +} + +template<typename _Tp> inline +Mat::Mat(const std::vector<_Tp>& vec, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if(vec.empty()) + return; + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)&vec[0]; + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); +} + +#ifdef CV_CXX11 +template<typename _Tp, typename> inline +Mat::Mat(const std::initializer_list<_Tp> list) + : Mat() +{ + CV_Assert(list.size() != 0); + Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); +} + +template<typename _Tp> inline +Mat::Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list) + : Mat() +{ + size_t size_total = 1; + for(auto s : sizes) + size_total *= s; + CV_Assert(list.size() != 0); + CV_Assert(size_total == list.size()); + Mat((int)sizes.size(), (int*)sizes.begin(), traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); +} +#endif + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if(arr.empty()) + return; + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)arr.data(); + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this); +} +#endif + +template<typename _Tp, int n> inline +Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)vec.val; + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this); +} + + +template<typename _Tp, int m, int n> inline +Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = cols * sizeof(_Tp); + step[1] = sizeof(_Tp); + datastart = data = (uchar*)M.val; + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat(m, n, traits::Type<_Tp>::value, (uchar*)M.val).copyTo(*this); +} + +template<typename _Tp> inline +Mat::Mat(const Point_<_Tp>& pt, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)&pt.x; + datalimit = dataend = datastart + rows * step[0]; + } + else + { + create(2, 1, traits::Type<_Tp>::value); + ((_Tp*)data)[0] = pt.x; + ((_Tp*)data)[1] = pt.y; + } +} + +template<typename _Tp> inline +Mat::Mat(const Point3_<_Tp>& pt, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)&pt.x; + datalimit = dataend = datastart + rows * step[0]; + } + else + { + create(3, 1, traits::Type<_Tp>::value); + ((_Tp*)data)[0] = pt.x; + ((_Tp*)data)[1] = pt.y; + ((_Tp*)data)[2] = pt.z; + } +} + +template<typename _Tp> inline +Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), + datastart(0), dataend(0), allocator(0), u(0), size(&rows) +{ + *this = commaInitializer.operator Mat_<_Tp>(); +} + +inline +Mat::~Mat() +{ + release(); + if( step.p != step.buf ) + fastFree(step.p); +} + +inline +Mat& Mat::operator = (const Mat& m) +{ + if( this != &m ) + { + if( m.u ) + CV_XADD(&m.u->refcount, 1); + release(); + flags = m.flags; + if( dims <= 2 && m.dims <= 2 ) + { + dims = m.dims; + rows = m.rows; + cols = m.cols; + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + copySize(m); + data = m.data; + datastart = m.datastart; + dataend = m.dataend; + datalimit = m.datalimit; + allocator = m.allocator; + u = m.u; + } + return *this; +} + +inline +Mat Mat::row(int y) const +{ + return Mat(*this, Range(y, y + 1), Range::all()); +} + +inline +Mat Mat::col(int x) const +{ + return Mat(*this, Range::all(), Range(x, x + 1)); +} + +inline +Mat Mat::rowRange(int startrow, int endrow) const +{ + return Mat(*this, Range(startrow, endrow), Range::all()); +} + +inline +Mat Mat::rowRange(const Range& r) const +{ + return Mat(*this, r, Range::all()); +} + +inline +Mat Mat::colRange(int startcol, int endcol) const +{ + return Mat(*this, Range::all(), Range(startcol, endcol)); +} + +inline +Mat Mat::colRange(const Range& r) const +{ + return Mat(*this, Range::all(), r); +} + +inline +Mat Mat::clone() const +{ + Mat m; + copyTo(m); + return m; +} + +inline +void Mat::assignTo( Mat& m, int _type ) const +{ + if( _type < 0 ) + m = *this; + else + convertTo(m, _type); +} + +inline +void Mat::create(int _rows, int _cols, int _type) +{ + _type &= TYPE_MASK; + if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && data ) + return; + int sz[] = {_rows, _cols}; + create(2, sz, _type); +} + +inline +void Mat::create(Size _sz, int _type) +{ + create(_sz.height, _sz.width, _type); +} + +inline +void Mat::addref() +{ + if( u ) + CV_XADD(&u->refcount, 1); +} + +inline +void Mat::release() +{ + if( u && CV_XADD(&u->refcount, -1) == 1 ) + deallocate(); + u = NULL; + datastart = dataend = datalimit = data = 0; + for(int i = 0; i < dims; i++) + size.p[i] = 0; +#ifdef _DEBUG + flags = MAGIC_VAL; + dims = rows = cols = 0; + if(step.p != step.buf) + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } +#endif +} + +inline +Mat Mat::operator()( Range _rowRange, Range _colRange ) const +{ + return Mat(*this, _rowRange, _colRange); +} + +inline +Mat Mat::operator()( const Rect& roi ) const +{ + return Mat(*this, roi); +} + +inline +Mat Mat::operator()(const Range* ranges) const +{ + return Mat(*this, ranges); +} + +inline +Mat Mat::operator()(const std::vector<Range>& ranges) const +{ + return Mat(*this, ranges); +} + +inline +bool Mat::isContinuous() const +{ + return (flags & CONTINUOUS_FLAG) != 0; +} + +inline +bool Mat::isSubmatrix() const +{ + return (flags & SUBMATRIX_FLAG) != 0; +} + +inline +size_t Mat::elemSize() const +{ + size_t res = dims > 0 ? step.p[dims - 1] : 0; + CV_DbgAssert(res != 0); + return res; +} + +inline +size_t Mat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int Mat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int Mat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int Mat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t Mat::step1(int i) const +{ + return step.p[i] / elemSize1(); +} + +inline +bool Mat::empty() const +{ + return data == 0 || total() == 0 || dims == 0; +} + +inline +size_t Mat::total() const +{ + if( dims <= 2 ) + return (size_t)rows * cols; + size_t p = 1; + for( int i = 0; i < dims; i++ ) + p *= size[i]; + return p; +} + +inline +size_t Mat::total(int startDim, int endDim) const +{ + CV_Assert( 0 <= startDim && startDim <= endDim); + size_t p = 1; + int endDim_ = endDim <= dims ? endDim : dims; + for( int i = startDim; i < endDim_; i++ ) + p *= size[i]; + return p; +} + +inline +uchar* Mat::ptr(int y) +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return data + step.p[0] * y; +} + +inline +const uchar* Mat::ptr(int y) const +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return data + step.p[0] * y; +} + +template<typename _Tp> inline +_Tp* Mat::ptr(int y) +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return (_Tp*)(data + step.p[0] * y); +} + +template<typename _Tp> inline +const _Tp* Mat::ptr(int y) const +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return (const _Tp*)(data + step.p[0] * y); +} + +inline +uchar* Mat::ptr(int i0, int i1) +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return data + i0 * step.p[0] + i1 * step.p[1]; +} + +inline +const uchar* Mat::ptr(int i0, int i1) const +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return data + i0 * step.p[0] + i1 * step.p[1]; +} + +template<typename _Tp> inline +_Tp* Mat::ptr(int i0, int i1) +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1]); +} + +template<typename _Tp> inline +const _Tp* Mat::ptr(int i0, int i1) const +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1]); +} + +inline +uchar* Mat::ptr(int i0, int i1, int i2) +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]; +} + +inline +const uchar* Mat::ptr(int i0, int i1, int i2) const +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]; +} + +template<typename _Tp> inline +_Tp* Mat::ptr(int i0, int i1, int i2) +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]); +} + +template<typename _Tp> inline +const _Tp* Mat::ptr(int i0, int i1, int i2) const +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]); +} + +inline +uchar* Mat::ptr(const int* idx) +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return p; +} + +inline +const uchar* Mat::ptr(const int* idx) const +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return p; +} + +template<typename _Tp> inline +_Tp* Mat::ptr(const int* idx) +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return (_Tp*)p; +} + +template<typename _Tp> inline +const _Tp* Mat::ptr(const int* idx) const +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return (const _Tp*)p; +} + +template<typename _Tp> inline +_Tp& Mat::at(int i0, int i1) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((_Tp*)(data + step.p[0] * i0))[i1]; +} + +template<typename _Tp> inline +const _Tp& Mat::at(int i0, int i1) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((const _Tp*)(data + step.p[0] * i0))[i1]; +} + +template<typename _Tp> inline +_Tp& Mat::at(Point pt) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template<typename _Tp> inline +const _Tp& Mat::at(Point pt) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template<typename _Tp> inline +_Tp& Mat::at(int i0) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); + CV_DbgAssert(elemSize() == sizeof(_Tp)); + if( isContinuous() || size.p[0] == 1 ) + return ((_Tp*)data)[i0]; + if( size.p[1] == 1 ) + return *(_Tp*)(data + step.p[0] * i0); + int i = i0 / cols, j = i0 - i * cols; + return ((_Tp*)(data + step.p[0] * i))[j]; +} + +template<typename _Tp> inline +const _Tp& Mat::at(int i0) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); + CV_DbgAssert(elemSize() == sizeof(_Tp)); + if( isContinuous() || size.p[0] == 1 ) + return ((const _Tp*)data)[i0]; + if( size.p[1] == 1 ) + return *(const _Tp*)(data + step.p[0] * i0); + int i = i0 / cols, j = i0 - i * cols; + return ((const _Tp*)(data + step.p[0] * i))[j]; +} + +template<typename _Tp> inline +_Tp& Mat::at(int i0, int i1, int i2) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(_Tp*)ptr(i0, i1, i2); +} + +template<typename _Tp> inline +const _Tp& Mat::at(int i0, int i1, int i2) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(const _Tp*)ptr(i0, i1, i2); +} + +template<typename _Tp> inline +_Tp& Mat::at(const int* idx) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(_Tp*)ptr(idx); +} + +template<typename _Tp> inline +const _Tp& Mat::at(const int* idx) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(const _Tp*)ptr(idx); +} + +template<typename _Tp, int n> inline +_Tp& Mat::at(const Vec<int, n>& idx) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(_Tp*)ptr(idx.val); +} + +template<typename _Tp, int n> inline +const _Tp& Mat::at(const Vec<int, n>& idx) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(const _Tp*)ptr(idx.val); +} + +template<typename _Tp> inline +MatConstIterator_<_Tp> Mat::begin() const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this); +} + +template<typename _Tp> inline +MatConstIterator_<_Tp> Mat::end() const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this); + it += total(); + return it; +} + +template<typename _Tp> inline +MatIterator_<_Tp> Mat::begin() +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return MatIterator_<_Tp>((Mat_<_Tp>*)this); +} + +template<typename _Tp> inline +MatIterator_<_Tp> Mat::end() +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + MatIterator_<_Tp> it((Mat_<_Tp>*)this); + it += total(); + return it; +} + +template<typename _Tp, typename Functor> inline +void Mat::forEach(const Functor& operation) { + this->forEach_impl<_Tp>(operation); +} + +template<typename _Tp, typename Functor> inline +void Mat::forEach(const Functor& operation) const { + // call as not const + (const_cast<Mat*>(this))->forEach<_Tp>(operation); +} + +template<typename _Tp> inline +Mat::operator std::vector<_Tp>() const +{ + std::vector<_Tp> v; + copyTo(v); + return v; +} + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp, std::size_t _Nm> inline +Mat::operator std::array<_Tp, _Nm>() const +{ + std::array<_Tp, _Nm> v; + copyTo(v); + return v; +} +#endif + +template<typename _Tp, int n> inline +Mat::operator Vec<_Tp, n>() const +{ + CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) && + rows + cols - 1 == n && channels() == 1 ); + + if( isContinuous() && type() == traits::Type<_Tp>::value ) + return Vec<_Tp, n>((_Tp*)data); + Vec<_Tp, n> v; + Mat tmp(rows, cols, traits::Type<_Tp>::value, v.val); + convertTo(tmp, tmp.type()); + return v; +} + +template<typename _Tp, int m, int n> inline +Mat::operator Matx<_Tp, m, n>() const +{ + CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 ); + + if( isContinuous() && type() == traits::Type<_Tp>::value ) + return Matx<_Tp, m, n>((_Tp*)data); + Matx<_Tp, m, n> mtx; + Mat tmp(rows, cols, traits::Type<_Tp>::value, mtx.val); + convertTo(tmp, tmp.type()); + return mtx; +} + +template<typename _Tp> inline +void Mat::push_back(const _Tp& elem) +{ + if( !data ) + { + *this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone(); + return; + } + CV_Assert(traits::Type<_Tp>::value == type() && cols == 1 + /* && dims == 2 (cols == 1 implies dims == 2) */); + const uchar* tmp = dataend + step[0]; + if( !isSubmatrix() && isContinuous() && tmp <= datalimit ) + { + *(_Tp*)(data + (size.p[0]++) * step.p[0]) = elem; + dataend = tmp; + } + else + push_back_(&elem); +} + +template<typename _Tp> inline +void Mat::push_back(const Mat_<_Tp>& m) +{ + push_back((const Mat&)m); +} + +template<> inline +void Mat::push_back(const MatExpr& expr) +{ + push_back(static_cast<Mat>(expr)); +} + + +template<typename _Tp> inline +void Mat::push_back(const std::vector<_Tp>& v) +{ + push_back(Mat(v)); +} + +#ifdef CV_CXX_MOVE_SEMANTICS + +inline +Mat::Mat(Mat&& m) + : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), + datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), + u(m.u), size(&rows) +{ + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; + m.allocator = NULL; + m.u = NULL; +} + +inline +Mat& Mat::operator = (Mat&& m) +{ + if (this == &m) + return *this; + + release(); + flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; + datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; + u = m.u; + if (step.p != step.buf) // release self step/size + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; + m.allocator = NULL; + m.u = NULL; + return *this; +} + +#endif + + +///////////////////////////// MatSize //////////////////////////// + +inline +MatSize::MatSize(int* _p) + : p(_p) {} + +inline +int MatSize::dims() const +{ + return (p - 1)[0]; +} + +inline +Size MatSize::operator()() const +{ + CV_DbgAssert(dims() <= 2); + return Size(p[1], p[0]); +} + +inline +const int& MatSize::operator[](int i) const +{ + CV_DbgAssert(i < dims()); +#ifdef __OPENCV_BUILD + CV_DbgAssert(i >= 0); +#endif + return p[i]; +} + +inline +int& MatSize::operator[](int i) +{ + CV_DbgAssert(i < dims()); +#ifdef __OPENCV_BUILD + CV_DbgAssert(i >= 0); +#endif + return p[i]; +} + +inline +MatSize::operator const int*() const +{ + return p; +} + +inline +bool MatSize::operator == (const MatSize& sz) const +{ + int d = dims(); + int dsz = sz.dims(); + if( d != dsz ) + return false; + if( d == 2 ) + return p[0] == sz.p[0] && p[1] == sz.p[1]; + + for( int i = 0; i < d; i++ ) + if( p[i] != sz.p[i] ) + return false; + return true; +} + +inline +bool MatSize::operator != (const MatSize& sz) const +{ + return !(*this == sz); +} + + + +///////////////////////////// MatStep //////////////////////////// + +inline +MatStep::MatStep() +{ + p = buf; p[0] = p[1] = 0; +} + +inline +MatStep::MatStep(size_t s) +{ + p = buf; p[0] = s; p[1] = 0; +} + +inline +const size_t& MatStep::operator[](int i) const +{ + return p[i]; +} + +inline +size_t& MatStep::operator[](int i) +{ + return p[i]; +} + +inline MatStep::operator size_t() const +{ + CV_DbgAssert( p == buf ); + return buf[0]; +} + +inline MatStep& MatStep::operator = (size_t s) +{ + CV_DbgAssert( p == buf ); + buf[0] = s; + return *this; +} + + + +////////////////////////////// Mat_<_Tp> //////////////////////////// + +template<typename _Tp> inline +Mat_<_Tp>::Mat_() + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(int _rows, int _cols) + : Mat(_rows, _cols, traits::Type<_Tp>::value) +{ +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value) + : Mat(_rows, _cols, traits::Type<_Tp>::value) +{ + *this = value; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(Size _sz) + : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(Size _sz, const _Tp& value) + : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value) +{ + *this = value; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz) + : Mat(_dims, _sz, traits::Type<_Tp>::value) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s) + : Mat(_dims, _sz, traits::Type<_Tp>::value, Scalar(_s)) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz, _Tp* _data, const size_t* _steps) + : Mat(_dims, _sz, traits::Type<_Tp>::value, _data, _steps) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges) + : Mat(m, ranges) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const std::vector<Range>& ranges) + : Mat(m, ranges) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Mat& m) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + *this = m; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Mat_& m) + : Mat(m) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps) + : Mat(_rows, _cols, traits::Type<_Tp>::value, _data, steps) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Mat_& m, const Range& _rowRange, const Range& _colRange) + : Mat(m, _rowRange, _colRange) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi) + : Mat(m, roi) +{} + +template<typename _Tp> template<int n> inline +Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData) + : Mat(n / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&vec) +{ + CV_Assert(n%DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template<typename _Tp> template<int m, int n> inline +Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& M, bool copyData) + : Mat(m, n / DataType<_Tp>::channels, traits::Type<_Tp>::value, (void*)&M) +{ + CV_Assert(n % DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData) + : Mat(2 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt) +{ + CV_Assert(2 % DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData) + : Mat(3 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt) +{ + CV_Assert(3 % DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer) + : Mat(commaInitializer) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData) + : Mat(vec, copyData) +{} + +#ifdef CV_CXX11 +template<typename _Tp> inline +Mat_<_Tp>::Mat_(std::initializer_list<_Tp> list) + : Mat(list) +{} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const std::initializer_list<int> sizes, std::initializer_list<_Tp> list) + : Mat(sizes, list) +{} +#endif + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp> template<std::size_t _Nm> inline +Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData) + : Mat(arr, copyData) +{} +#endif + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) +{ + if( traits::Type<_Tp>::value == m.type() ) + { + Mat::operator = (m); + return *this; + } + if( traits::Depth<_Tp>::value == m.depth() ) + { + return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0)); + } + CV_Assert(DataType<_Tp>::channels == m.channels() || m.empty()); + m.convertTo(*this, type()); + return *this; +} + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m) +{ + Mat::operator=(m); + return *this; +} + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s) +{ + typedef typename DataType<_Tp>::vec_type VT; + Mat::operator=(Scalar((const VT&)s)); + return *this; +} + +template<typename _Tp> inline +void Mat_<_Tp>::create(int _rows, int _cols) +{ + Mat::create(_rows, _cols, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +void Mat_<_Tp>::create(Size _sz) +{ + Mat::create(_sz, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +void Mat_<_Tp>::create(int _dims, const int* _sz) +{ + Mat::create(_dims, _sz, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +void Mat_<_Tp>::release() +{ + Mat::release(); +#ifdef _DEBUG + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; +#endif +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const +{ + return Mat_<_Tp>(Mat::cross(m)); +} + +template<typename _Tp> template<typename T2> inline +Mat_<_Tp>::operator Mat_<T2>() const +{ + return Mat_<T2>(*this); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::row(int y) const +{ + return Mat_(*this, Range(y, y+1), Range::all()); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::col(int x) const +{ + return Mat_(*this, Range::all(), Range(x, x+1)); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::diag(int d) const +{ + return Mat_(Mat::diag(d)); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::clone() const +{ + return Mat_(Mat::clone()); +} + +template<typename _Tp> inline +size_t Mat_<_Tp>::elemSize() const +{ + CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) ); + return sizeof(_Tp); +} + +template<typename _Tp> inline +size_t Mat_<_Tp>::elemSize1() const +{ + CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp) / DataType<_Tp>::channels ); + return sizeof(_Tp) / DataType<_Tp>::channels; +} + +template<typename _Tp> inline +int Mat_<_Tp>::type() const +{ + CV_DbgAssert( Mat::type() == traits::Type<_Tp>::value ); + return traits::Type<_Tp>::value; +} + +template<typename _Tp> inline +int Mat_<_Tp>::depth() const +{ + CV_DbgAssert( Mat::depth() == traits::Depth<_Tp>::value ); + return traits::Depth<_Tp>::value; +} + +template<typename _Tp> inline +int Mat_<_Tp>::channels() const +{ + CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels ); + return DataType<_Tp>::channels; +} + +template<typename _Tp> inline +size_t Mat_<_Tp>::stepT(int i) const +{ + return step.p[i] / elemSize(); +} + +template<typename _Tp> inline +size_t Mat_<_Tp>::step1(int i) const +{ + return step.p[i] / elemSize1(); +} + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright ) +{ + return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::operator()( const Range& _rowRange, const Range& _colRange ) const +{ + return Mat_<_Tp>(*this, _rowRange, _colRange); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const +{ + return Mat_<_Tp>(*this, roi); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const +{ + return Mat_<_Tp>(*this, ranges); +} + +template<typename _Tp> inline +Mat_<_Tp> Mat_<_Tp>::operator()(const std::vector<Range>& ranges) const +{ + return Mat_<_Tp>(*this, ranges); +} + +template<typename _Tp> inline +_Tp* Mat_<_Tp>::operator [](int y) +{ + CV_DbgAssert( 0 <= y && y < size.p[0] ); + return (_Tp*)(data + y*step.p[0]); +} + +template<typename _Tp> inline +const _Tp* Mat_<_Tp>::operator [](int y) const +{ + CV_DbgAssert( 0 <= y && y < size.p[0] ); + return (const _Tp*)(data + y*step.p[0]); +} + +template<typename _Tp> inline +_Tp& Mat_<_Tp>::operator ()(int i0, int i1) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((_Tp*)(data + step.p[0] * i0))[i1]; +} + +template<typename _Tp> inline +const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((const _Tp*)(data + step.p[0] * i0))[i1]; +} + +template<typename _Tp> inline +_Tp& Mat_<_Tp>::operator ()(Point pt) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template<typename _Tp> inline +const _Tp& Mat_<_Tp>::operator ()(Point pt) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template<typename _Tp> inline +_Tp& Mat_<_Tp>::operator ()(const int* idx) +{ + return Mat::at<_Tp>(idx); +} + +template<typename _Tp> inline +const _Tp& Mat_<_Tp>::operator ()(const int* idx) const +{ + return Mat::at<_Tp>(idx); +} + +template<typename _Tp> template<int n> inline +_Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx) +{ + return Mat::at<_Tp>(idx); +} + +template<typename _Tp> template<int n> inline +const _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx) const +{ + return Mat::at<_Tp>(idx); +} + +template<typename _Tp> inline +_Tp& Mat_<_Tp>::operator ()(int i0) +{ + return this->at<_Tp>(i0); +} + +template<typename _Tp> inline +const _Tp& Mat_<_Tp>::operator ()(int i0) const +{ + return this->at<_Tp>(i0); +} + +template<typename _Tp> inline +_Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) +{ + return this->at<_Tp>(i0, i1, i2); +} + +template<typename _Tp> inline +const _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) const +{ + return this->at<_Tp>(i0, i1, i2); +} + +template<typename _Tp> inline +Mat_<_Tp>::operator std::vector<_Tp>() const +{ + std::vector<_Tp> v; + copyTo(v); + return v; +} + +#ifdef CV_CXX_STD_ARRAY +template<typename _Tp> template<std::size_t _Nm> inline +Mat_<_Tp>::operator std::array<_Tp, _Nm>() const +{ + std::array<_Tp, _Nm> a; + copyTo(a); + return a; +} +#endif + +template<typename _Tp> template<int n> inline +Mat_<_Tp>::operator Vec<typename DataType<_Tp>::channel_type, n>() const +{ + CV_Assert(n % DataType<_Tp>::channels == 0); + +#if defined _MSC_VER + const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround) + return pMat->operator Vec<typename DataType<_Tp>::channel_type, n>(); +#else + return this->Mat::operator Vec<typename DataType<_Tp>::channel_type, n>(); +#endif +} + +template<typename _Tp> template<int m, int n> inline +Mat_<_Tp>::operator Matx<typename DataType<_Tp>::channel_type, m, n>() const +{ + CV_Assert(n % DataType<_Tp>::channels == 0); + +#if defined _MSC_VER + const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround) + Matx<typename DataType<_Tp>::channel_type, m, n> res = pMat->operator Matx<typename DataType<_Tp>::channel_type, m, n>(); + return res; +#else + Matx<typename DataType<_Tp>::channel_type, m, n> res = this->Mat::operator Matx<typename DataType<_Tp>::channel_type, m, n>(); + return res; +#endif +} + +template<typename _Tp> inline +MatConstIterator_<_Tp> Mat_<_Tp>::begin() const +{ + return Mat::begin<_Tp>(); +} + +template<typename _Tp> inline +MatConstIterator_<_Tp> Mat_<_Tp>::end() const +{ + return Mat::end<_Tp>(); +} + +template<typename _Tp> inline +MatIterator_<_Tp> Mat_<_Tp>::begin() +{ + return Mat::begin<_Tp>(); +} + +template<typename _Tp> inline +MatIterator_<_Tp> Mat_<_Tp>::end() +{ + return Mat::end<_Tp>(); +} + +template<typename _Tp> template<typename Functor> inline +void Mat_<_Tp>::forEach(const Functor& operation) { + Mat::forEach<_Tp, Functor>(operation); +} + +template<typename _Tp> template<typename Functor> inline +void Mat_<_Tp>::forEach(const Functor& operation) const { + Mat::forEach<_Tp, Functor>(operation); +} + +#ifdef CV_CXX_MOVE_SEMANTICS + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(Mat_&& m) + : Mat(m) +{ +} + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m) +{ + Mat::operator = (std::move(m)); + return *this; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(Mat&& m) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + *this = m; +} + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m) +{ + if( traits::Type<_Tp>::value == m.type() ) + { + Mat::operator = ((Mat&&)m); + return *this; + } + if( traits::Depth<_Tp>::value == m.depth() ) + { + Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0)); + return *this; + } + CV_DbgAssert(DataType<_Tp>::channels == m.channels()); + m.convertTo(*this, type()); + return *this; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(MatExpr&& e) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + *this = Mat(e); +} + +#endif + +///////////////////////////// SparseMat ///////////////////////////// + +inline +SparseMat::SparseMat() + : flags(MAGIC_VAL), hdr(0) +{} + +inline +SparseMat::SparseMat(int _dims, const int* _sizes, int _type) + : flags(MAGIC_VAL), hdr(0) +{ + create(_dims, _sizes, _type); +} + +inline +SparseMat::SparseMat(const SparseMat& m) + : flags(m.flags), hdr(m.hdr) +{ + addref(); +} + +inline +SparseMat::~SparseMat() +{ + release(); +} + +inline +SparseMat& SparseMat::operator = (const SparseMat& m) +{ + if( this != &m ) + { + if( m.hdr ) + CV_XADD(&m.hdr->refcount, 1); + release(); + flags = m.flags; + hdr = m.hdr; + } + return *this; +} + +inline +SparseMat& SparseMat::operator = (const Mat& m) +{ + return (*this = SparseMat(m)); +} + +inline +SparseMat SparseMat::clone() const +{ + SparseMat temp; + this->copyTo(temp); + return temp; +} + +inline +void SparseMat::assignTo( SparseMat& m, int _type ) const +{ + if( _type < 0 ) + m = *this; + else + convertTo(m, _type); +} + +inline +void SparseMat::addref() +{ + if( hdr ) + CV_XADD(&hdr->refcount, 1); +} + +inline +void SparseMat::release() +{ + if( hdr && CV_XADD(&hdr->refcount, -1) == 1 ) + delete hdr; + hdr = 0; +} + +inline +size_t SparseMat::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t SparseMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int SparseMat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int SparseMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int SparseMat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +const int* SparseMat::size() const +{ + return hdr ? hdr->size : 0; +} + +inline +int SparseMat::size(int i) const +{ + if( hdr ) + { + CV_DbgAssert((unsigned)i < (unsigned)hdr->dims); + return hdr->size[i]; + } + return 0; +} + +inline +int SparseMat::dims() const +{ + return hdr ? hdr->dims : 0; +} + +inline +size_t SparseMat::nzcount() const +{ + return hdr ? hdr->nodeCount : 0; +} + +inline +size_t SparseMat::hash(int i0) const +{ + return (size_t)i0; +} + +inline +size_t SparseMat::hash(int i0, int i1) const +{ + return (size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1; +} + +inline +size_t SparseMat::hash(int i0, int i1, int i2) const +{ + return ((size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1) * HASH_SCALE + (unsigned)i2; +} + +inline +size_t SparseMat::hash(const int* idx) const +{ + size_t h = (unsigned)idx[0]; + if( !hdr ) + return 0; + int d = hdr->dims; + for(int i = 1; i < d; i++ ) + h = h * HASH_SCALE + (unsigned)idx[i]; + return h; +} + +template<typename _Tp> inline +_Tp& SparseMat::ref(int i0, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat::ref(int i0, int i1, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat::ref(const int* idx, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval); +} + +template<typename _Tp> inline +_Tp SparseMat::value(int i0, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); + return p ? *p : _Tp(); +} + +template<typename _Tp> inline +_Tp SparseMat::value(int i0, int i1, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); + return p ? *p : _Tp(); +} + +template<typename _Tp> inline +_Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); + return p ? *p : _Tp(); +} + +template<typename _Tp> inline +_Tp SparseMat::value(const int* idx, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); + return p ? *p : _Tp(); +} + +template<typename _Tp> inline +const _Tp* SparseMat::find(int i0, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); +} + +template<typename _Tp> inline +const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); +} + +template<typename _Tp> inline +const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); +} + +template<typename _Tp> inline +const _Tp* SparseMat::find(const int* idx, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat::value(Node* n) +{ + return *(_Tp*)((uchar*)n + hdr->valueOffset); +} + +template<typename _Tp> inline +const _Tp& SparseMat::value(const Node* n) const +{ + return *(const _Tp*)((const uchar*)n + hdr->valueOffset); +} + +inline +SparseMat::Node* SparseMat::node(size_t nidx) +{ + return (Node*)(void*)&hdr->pool[nidx]; +} + +inline +const SparseMat::Node* SparseMat::node(size_t nidx) const +{ + return (const Node*)(const void*)&hdr->pool[nidx]; +} + +inline +SparseMatIterator SparseMat::begin() +{ + return SparseMatIterator(this); +} + +inline +SparseMatConstIterator SparseMat::begin() const +{ + return SparseMatConstIterator(this); +} + +inline +SparseMatIterator SparseMat::end() +{ + SparseMatIterator it(this); + it.seekEnd(); + return it; +} + +inline +SparseMatConstIterator SparseMat::end() const +{ + SparseMatConstIterator it(this); + it.seekEnd(); + return it; +} + +template<typename _Tp> inline +SparseMatIterator_<_Tp> SparseMat::begin() +{ + return SparseMatIterator_<_Tp>(this); +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp> SparseMat::begin() const +{ + return SparseMatConstIterator_<_Tp>(this); +} + +template<typename _Tp> inline +SparseMatIterator_<_Tp> SparseMat::end() +{ + SparseMatIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp> SparseMat::end() const +{ + SparseMatConstIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + + + +///////////////////////////// SparseMat_ //////////////////////////// + +template<typename _Tp> inline +SparseMat_<_Tp>::SparseMat_() +{ + flags = MAGIC_VAL | traits::Type<_Tp>::value; +} + +template<typename _Tp> inline +SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes) + : SparseMat(_dims, _sizes, traits::Type<_Tp>::value) +{} + +template<typename _Tp> inline +SparseMat_<_Tp>::SparseMat_(const SparseMat& m) +{ + if( m.type() == traits::Type<_Tp>::value ) + *this = (const SparseMat_<_Tp>&)m; + else + m.convertTo(*this, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m) +{ + this->flags = m.flags; + this->hdr = m.hdr; + if( this->hdr ) + CV_XADD(&this->hdr->refcount, 1); +} + +template<typename _Tp> inline +SparseMat_<_Tp>::SparseMat_(const Mat& m) +{ + SparseMat sm(m); + *this = sm; +} + +template<typename _Tp> inline +SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m) +{ + if( this != &m ) + { + if( m.hdr ) CV_XADD(&m.hdr->refcount, 1); + release(); + flags = m.flags; + hdr = m.hdr; + } + return *this; +} + +template<typename _Tp> inline +SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m) +{ + if( m.type() == traits::Type<_Tp>::value ) + return (*this = (const SparseMat_<_Tp>&)m); + m.convertTo(*this, traits::Type<_Tp>::value); + return *this; +} + +template<typename _Tp> inline +SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const Mat& m) +{ + return (*this = SparseMat(m)); +} + +template<typename _Tp> inline +SparseMat_<_Tp> SparseMat_<_Tp>::clone() const +{ + SparseMat_<_Tp> m; + this->copyTo(m); + return m; +} + +template<typename _Tp> inline +void SparseMat_<_Tp>::create(int _dims, const int* _sizes) +{ + SparseMat::create(_dims, _sizes, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +int SparseMat_<_Tp>::type() const +{ + return traits::Type<_Tp>::value; +} + +template<typename _Tp> inline +int SparseMat_<_Tp>::depth() const +{ + return traits::Depth<_Tp>::value; +} + +template<typename _Tp> inline +int SparseMat_<_Tp>::channels() const +{ + return DataType<_Tp>::channels; +} + +template<typename _Tp> inline +_Tp& SparseMat_<_Tp>::ref(int i0, size_t* hashval) +{ + return SparseMat::ref<_Tp>(i0, hashval); +} + +template<typename _Tp> inline +_Tp SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const +{ + return SparseMat::value<_Tp>(i0, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval) +{ + return SparseMat::ref<_Tp>(i0, i1, hashval); +} + +template<typename _Tp> inline +_Tp SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const +{ + return SparseMat::value<_Tp>(i0, i1, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval) +{ + return SparseMat::ref<_Tp>(i0, i1, i2, hashval); +} + +template<typename _Tp> inline +_Tp SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const +{ + return SparseMat::value<_Tp>(i0, i1, i2, hashval); +} + +template<typename _Tp> inline +_Tp& SparseMat_<_Tp>::ref(const int* idx, size_t* hashval) +{ + return SparseMat::ref<_Tp>(idx, hashval); +} + +template<typename _Tp> inline +_Tp SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const +{ + return SparseMat::value<_Tp>(idx, hashval); +} + +template<typename _Tp> inline +SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin() +{ + return SparseMatIterator_<_Tp>(this); +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const +{ + return SparseMatConstIterator_<_Tp>(this); +} + +template<typename _Tp> inline +SparseMatIterator_<_Tp> SparseMat_<_Tp>::end() +{ + SparseMatIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const +{ + SparseMatConstIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + + + +////////////////////////// MatConstIterator ///////////////////////// + +inline +MatConstIterator::MatConstIterator() + : m(0), elemSize(0), ptr(0), sliceStart(0), sliceEnd(0) +{} + +inline +MatConstIterator::MatConstIterator(const Mat* _m) + : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) +{ + if( m && m->isContinuous() ) + { + sliceStart = m->ptr(); + sliceEnd = sliceStart + m->total()*elemSize; + } + seek((const int*)0); +} + +inline +MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col) + : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) +{ + CV_Assert(m && m->dims <= 2); + if( m->isContinuous() ) + { + sliceStart = m->ptr(); + sliceEnd = sliceStart + m->total()*elemSize; + } + int idx[] = {_row, _col}; + seek(idx); +} + +inline +MatConstIterator::MatConstIterator(const Mat* _m, Point _pt) + : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) +{ + CV_Assert(m && m->dims <= 2); + if( m->isContinuous() ) + { + sliceStart = m->ptr(); + sliceEnd = sliceStart + m->total()*elemSize; + } + int idx[] = {_pt.y, _pt.x}; + seek(idx); +} + +inline +MatConstIterator::MatConstIterator(const MatConstIterator& it) + : m(it.m), elemSize(it.elemSize), ptr(it.ptr), sliceStart(it.sliceStart), sliceEnd(it.sliceEnd) +{} + +inline +MatConstIterator& MatConstIterator::operator = (const MatConstIterator& it ) +{ + m = it.m; elemSize = it.elemSize; ptr = it.ptr; + sliceStart = it.sliceStart; sliceEnd = it.sliceEnd; + return *this; +} + +inline +const uchar* MatConstIterator::operator *() const +{ + return ptr; +} + +inline MatConstIterator& MatConstIterator::operator += (ptrdiff_t ofs) +{ + if( !m || ofs == 0 ) + return *this; + ptrdiff_t ofsb = ofs*elemSize; + ptr += ofsb; + if( ptr < sliceStart || sliceEnd <= ptr ) + { + ptr -= ofsb; + seek(ofs, true); + } + return *this; +} + +inline +MatConstIterator& MatConstIterator::operator -= (ptrdiff_t ofs) +{ + return (*this += -ofs); +} + +inline +MatConstIterator& MatConstIterator::operator --() +{ + if( m && (ptr -= elemSize) < sliceStart ) + { + ptr += elemSize; + seek(-1, true); + } + return *this; +} + +inline +MatConstIterator MatConstIterator::operator --(int) +{ + MatConstIterator b = *this; + *this += -1; + return b; +} + +inline +MatConstIterator& MatConstIterator::operator ++() +{ + if( m && (ptr += elemSize) >= sliceEnd ) + { + ptr -= elemSize; + seek(1, true); + } + return *this; +} + +inline MatConstIterator MatConstIterator::operator ++(int) +{ + MatConstIterator b = *this; + *this += 1; + return b; +} + + +static inline +bool operator == (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.m == b.m && a.ptr == b.ptr; +} + +static inline +bool operator != (const MatConstIterator& a, const MatConstIterator& b) +{ + return !(a == b); +} + +static inline +bool operator < (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr < b.ptr; +} + +static inline +bool operator > (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr > b.ptr; +} + +static inline +bool operator <= (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr <= b.ptr; +} + +static inline +bool operator >= (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr >= b.ptr; +} + +static inline +ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a) +{ + if( a.m != b.m ) + return ((size_t)(-1) >> 1); + if( a.sliceEnd == b.sliceEnd ) + return (b.ptr - a.ptr)/static_cast<ptrdiff_t>(b.elemSize); + + return b.lpos() - a.lpos(); +} + +static inline +MatConstIterator operator + (const MatConstIterator& a, ptrdiff_t ofs) +{ + MatConstIterator b = a; + return b += ofs; +} + +static inline +MatConstIterator operator + (ptrdiff_t ofs, const MatConstIterator& a) +{ + MatConstIterator b = a; + return b += ofs; +} + +static inline +MatConstIterator operator - (const MatConstIterator& a, ptrdiff_t ofs) +{ + MatConstIterator b = a; + return b += -ofs; +} + + +inline +const uchar* MatConstIterator::operator [](ptrdiff_t i) const +{ + return *(*this + i); +} + + + +///////////////////////// MatConstIterator_ ///////////////////////// + +template<typename _Tp> inline +MatConstIterator_<_Tp>::MatConstIterator_() +{} + +template<typename _Tp> inline +MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m) + : MatConstIterator(_m) +{} + +template<typename _Tp> inline +MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col) + : MatConstIterator(_m, _row, _col) +{} + +template<typename _Tp> inline +MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, Point _pt) + : MatConstIterator(_m, _pt) +{} + +template<typename _Tp> inline +MatConstIterator_<_Tp>::MatConstIterator_(const MatConstIterator_& it) + : MatConstIterator(it) +{} + +template<typename _Tp> inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it ) +{ + MatConstIterator::operator = (it); + return *this; +} + +template<typename _Tp> inline +const _Tp& MatConstIterator_<_Tp>::operator *() const +{ + return *(_Tp*)(this->ptr); +} + +template<typename _Tp> inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (ptrdiff_t ofs) +{ + MatConstIterator::operator += (ofs); + return *this; +} + +template<typename _Tp> inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (ptrdiff_t ofs) +{ + return (*this += -ofs); +} + +template<typename _Tp> inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --() +{ + MatConstIterator::operator --(); + return *this; +} + +template<typename _Tp> inline +MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int) +{ + MatConstIterator_ b = *this; + MatConstIterator::operator --(); + return b; +} + +template<typename _Tp> inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++() +{ + MatConstIterator::operator ++(); + return *this; +} + +template<typename _Tp> inline +MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int) +{ + MatConstIterator_ b = *this; + MatConstIterator::operator ++(); + return b; +} + + +template<typename _Tp> inline +Point MatConstIterator_<_Tp>::pos() const +{ + if( !m ) + return Point(); + CV_DbgAssert( m->dims <= 2 ); + if( m->isContinuous() ) + { + ptrdiff_t ofs = (const _Tp*)ptr - (const _Tp*)m->data; + int y = (int)(ofs / m->cols); + int x = (int)(ofs - (ptrdiff_t)y * m->cols); + return Point(x, y); + } + else + { + ptrdiff_t ofs = (uchar*)ptr - m->data; + int y = (int)(ofs / m->step); + int x = (int)((ofs - y * m->step)/sizeof(_Tp)); + return Point(x, y); + } +} + + +template<typename _Tp> static inline +bool operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b) +{ + return a.m == b.m && a.ptr == b.ptr; +} + +template<typename _Tp> static inline +bool operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b) +{ + return a.m != b.m || a.ptr != b.ptr; +} + +template<typename _Tp> static inline +MatConstIterator_<_Tp> operator + (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatConstIterator_<_Tp>&)t; +} + +template<typename _Tp> static inline +MatConstIterator_<_Tp> operator + (ptrdiff_t ofs, const MatConstIterator_<_Tp>& a) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatConstIterator_<_Tp>&)t; +} + +template<typename _Tp> static inline +MatConstIterator_<_Tp> operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a - ofs; + return (MatConstIterator_<_Tp>&)t; +} + +template<typename _Tp> inline +const _Tp& MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const +{ + return *(_Tp*)MatConstIterator::operator [](i); +} + + + +//////////////////////////// MatIterator_ /////////////////////////// + +template<typename _Tp> inline +MatIterator_<_Tp>::MatIterator_() + : MatConstIterator_<_Tp>() +{} + +template<typename _Tp> inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m) + : MatConstIterator_<_Tp>(_m) +{} + +template<typename _Tp> inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col) + : MatConstIterator_<_Tp>(_m, _row, _col) +{} + +template<typename _Tp> inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, Point _pt) + : MatConstIterator_<_Tp>(_m, _pt) +{} + +template<typename _Tp> inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, const int* _idx) + : MatConstIterator_<_Tp>(_m, _idx) +{} + +template<typename _Tp> inline +MatIterator_<_Tp>::MatIterator_(const MatIterator_& it) + : MatConstIterator_<_Tp>(it) +{} + +template<typename _Tp> inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it ) +{ + MatConstIterator::operator = (it); + return *this; +} + +template<typename _Tp> inline +_Tp& MatIterator_<_Tp>::operator *() const +{ + return *(_Tp*)(this->ptr); +} + +template<typename _Tp> inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (ptrdiff_t ofs) +{ + MatConstIterator::operator += (ofs); + return *this; +} + +template<typename _Tp> inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (ptrdiff_t ofs) +{ + MatConstIterator::operator += (-ofs); + return *this; +} + +template<typename _Tp> inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator --() +{ + MatConstIterator::operator --(); + return *this; +} + +template<typename _Tp> inline +MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int) +{ + MatIterator_ b = *this; + MatConstIterator::operator --(); + return b; +} + +template<typename _Tp> inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++() +{ + MatConstIterator::operator ++(); + return *this; +} + +template<typename _Tp> inline +MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int) +{ + MatIterator_ b = *this; + MatConstIterator::operator ++(); + return b; +} + +template<typename _Tp> inline +_Tp& MatIterator_<_Tp>::operator [](ptrdiff_t i) const +{ + return *(*this + i); +} + + +template<typename _Tp> static inline +bool operator == (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b) +{ + return a.m == b.m && a.ptr == b.ptr; +} + +template<typename _Tp> static inline +bool operator != (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b) +{ + return a.m != b.m || a.ptr != b.ptr; +} + +template<typename _Tp> static inline +MatIterator_<_Tp> operator + (const MatIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatIterator_<_Tp>&)t; +} + +template<typename _Tp> static inline +MatIterator_<_Tp> operator + (ptrdiff_t ofs, const MatIterator_<_Tp>& a) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatIterator_<_Tp>&)t; +} + +template<typename _Tp> static inline +MatIterator_<_Tp> operator - (const MatIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a - ofs; + return (MatIterator_<_Tp>&)t; +} + + + +/////////////////////// SparseMatConstIterator ////////////////////// + +inline +SparseMatConstIterator::SparseMatConstIterator() + : m(0), hashidx(0), ptr(0) +{} + +inline +SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it) + : m(it.m), hashidx(it.hashidx), ptr(it.ptr) +{} + +inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it) +{ + if( this != &it ) + { + m = it.m; + hashidx = it.hashidx; + ptr = it.ptr; + } + return *this; +} + +template<typename _Tp> inline +const _Tp& SparseMatConstIterator::value() const +{ + return *(const _Tp*)ptr; +} + +inline +const SparseMat::Node* SparseMatConstIterator::node() const +{ + return (ptr && m && m->hdr) ? (const SparseMat::Node*)(const void*)(ptr - m->hdr->valueOffset) : 0; +} + +inline +SparseMatConstIterator SparseMatConstIterator::operator ++(int) +{ + SparseMatConstIterator it = *this; + ++*this; + return it; +} + +inline +void SparseMatConstIterator::seekEnd() +{ + if( m && m->hdr ) + { + hashidx = m->hdr->hashtab.size(); + ptr = 0; + } +} + + +static inline +bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2) +{ + return it1.m == it2.m && it1.ptr == it2.ptr; +} + +static inline +bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2) +{ + return !(it1 == it2); +} + + + +///////////////////////// SparseMatIterator ///////////////////////// + +inline +SparseMatIterator::SparseMatIterator() +{} + +inline +SparseMatIterator::SparseMatIterator(SparseMat* _m) + : SparseMatConstIterator(_m) +{} + +inline +SparseMatIterator::SparseMatIterator(const SparseMatIterator& it) + : SparseMatConstIterator(it) +{} + +inline +SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it) +{ + (SparseMatConstIterator&)*this = it; + return *this; +} + +template<typename _Tp> inline +_Tp& SparseMatIterator::value() const +{ + return *(_Tp*)ptr; +} + +inline +SparseMat::Node* SparseMatIterator::node() const +{ + return (SparseMat::Node*)SparseMatConstIterator::node(); +} + +inline +SparseMatIterator& SparseMatIterator::operator ++() +{ + SparseMatConstIterator::operator ++(); + return *this; +} + +inline +SparseMatIterator SparseMatIterator::operator ++(int) +{ + SparseMatIterator it = *this; + ++*this; + return it; +} + + + +////////////////////// SparseMatConstIterator_ ////////////////////// + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_() +{} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m) + : SparseMatConstIterator(_m) +{} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m) + : SparseMatConstIterator(_m) +{ + CV_Assert( _m->type() == traits::Type<_Tp>::value ); +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it) + : SparseMatConstIterator(it) +{} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it) +{ + return reinterpret_cast<SparseMatConstIterator_<_Tp>&> + (*reinterpret_cast<SparseMatConstIterator*>(this) = + reinterpret_cast<const SparseMatConstIterator&>(it)); +} + +template<typename _Tp> inline +const _Tp& SparseMatConstIterator_<_Tp>::operator *() const +{ + return *(const _Tp*)this->ptr; +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator ++() +{ + SparseMatConstIterator::operator ++(); + return *this; +} + +template<typename _Tp> inline +SparseMatConstIterator_<_Tp> SparseMatConstIterator_<_Tp>::operator ++(int) +{ + SparseMatConstIterator_<_Tp> it = *this; + SparseMatConstIterator::operator ++(); + return it; +} + + + +///////////////////////// SparseMatIterator_ //////////////////////// + +template<typename _Tp> inline +SparseMatIterator_<_Tp>::SparseMatIterator_() +{} + +template<typename _Tp> inline +SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m) + : SparseMatConstIterator_<_Tp>(_m) +{} + +template<typename _Tp> inline +SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat* _m) + : SparseMatConstIterator_<_Tp>(_m) +{} + +template<typename _Tp> inline +SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it) + : SparseMatConstIterator_<_Tp>(it) +{} + +template<typename _Tp> inline +SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it) +{ + return reinterpret_cast<SparseMatIterator_<_Tp>&> + (*reinterpret_cast<SparseMatConstIterator*>(this) = + reinterpret_cast<const SparseMatConstIterator&>(it)); +} + +template<typename _Tp> inline +_Tp& SparseMatIterator_<_Tp>::operator *() const +{ + return *(_Tp*)this->ptr; +} + +template<typename _Tp> inline +SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator ++() +{ + SparseMatConstIterator::operator ++(); + return *this; +} + +template<typename _Tp> inline +SparseMatIterator_<_Tp> SparseMatIterator_<_Tp>::operator ++(int) +{ + SparseMatIterator_<_Tp> it = *this; + SparseMatConstIterator::operator ++(); + return it; +} + + + +//////////////////////// MatCommaInitializer_ /////////////////////// + +template<typename _Tp> inline +MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m) + : it(_m) +{} + +template<typename _Tp> template<typename T2> inline +MatCommaInitializer_<_Tp>& MatCommaInitializer_<_Tp>::operator , (T2 v) +{ + CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() ); + *this->it = _Tp(v); + ++this->it; + return *this; +} + +template<typename _Tp> inline +MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const +{ + CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() ); + return Mat_<_Tp>(*this->it.m); +} + + +template<typename _Tp, typename T2> static inline +MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val) +{ + MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m); + return (commaInitializer, val); +} + + + +///////////////////////// Matrix Expressions //////////////////////// + +inline +Mat& Mat::operator = (const MatExpr& e) +{ + e.op->assign(e, *this); + return *this; +} + +template<typename _Tp> inline +Mat_<_Tp>::Mat_(const MatExpr& e) +{ + e.op->assign(e, *this, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e) +{ + e.op->assign(e, *this, traits::Type<_Tp>::value); + return *this; +} + +template<typename _Tp> inline +MatExpr Mat_<_Tp>::zeros(int rows, int cols) +{ + return Mat::zeros(rows, cols, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +MatExpr Mat_<_Tp>::zeros(Size sz) +{ + return Mat::zeros(sz, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +MatExpr Mat_<_Tp>::ones(int rows, int cols) +{ + return Mat::ones(rows, cols, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +MatExpr Mat_<_Tp>::ones(Size sz) +{ + return Mat::ones(sz, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +MatExpr Mat_<_Tp>::eye(int rows, int cols) +{ + return Mat::eye(rows, cols, traits::Type<_Tp>::value); +} + +template<typename _Tp> inline +MatExpr Mat_<_Tp>::eye(Size sz) +{ + return Mat::eye(sz, traits::Type<_Tp>::value); +} + +inline +MatExpr::MatExpr() + : op(0), flags(0), a(Mat()), b(Mat()), c(Mat()), alpha(0), beta(0), s() +{} + +inline +MatExpr::MatExpr(const MatOp* _op, int _flags, const Mat& _a, const Mat& _b, + const Mat& _c, double _alpha, double _beta, const Scalar& _s) + : op(_op), flags(_flags), a(_a), b(_b), c(_c), alpha(_alpha), beta(_beta), s(_s) +{} + +inline +MatExpr::operator Mat() const +{ + Mat m; + op->assign(*this, m); + return m; +} + +template<typename _Tp> inline +MatExpr::operator Mat_<_Tp>() const +{ + Mat_<_Tp> m; + op->assign(*this, m, traits::Type<_Tp>::value); + return m; +} + + +template<typename _Tp> static inline +MatExpr min(const Mat_<_Tp>& a, const Mat_<_Tp>& b) +{ + return cv::min((const Mat&)a, (const Mat&)b); +} + +template<typename _Tp> static inline +MatExpr min(const Mat_<_Tp>& a, double s) +{ + return cv::min((const Mat&)a, s); +} + +template<typename _Tp> static inline +MatExpr min(double s, const Mat_<_Tp>& a) +{ + return cv::min((const Mat&)a, s); +} + +template<typename _Tp> static inline +MatExpr max(const Mat_<_Tp>& a, const Mat_<_Tp>& b) +{ + return cv::max((const Mat&)a, (const Mat&)b); +} + +template<typename _Tp> static inline +MatExpr max(const Mat_<_Tp>& a, double s) +{ + return cv::max((const Mat&)a, s); +} + +template<typename _Tp> static inline +MatExpr max(double s, const Mat_<_Tp>& a) +{ + return cv::max((const Mat&)a, s); +} + +template<typename _Tp> static inline +MatExpr abs(const Mat_<_Tp>& m) +{ + return cv::abs((const Mat&)m); +} + + +static inline +Mat& operator += (Mat& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, a); + return a; +} + +static inline +const Mat& operator += (const Mat& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, (Mat&)a); + return a; +} + +template<typename _Tp> static inline +Mat_<_Tp>& operator += (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, a); + return a; +} + +template<typename _Tp> static inline +const Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, (Mat&)a); + return a; +} + +static inline +Mat& operator -= (Mat& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, a); + return a; +} + +static inline +const Mat& operator -= (const Mat& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, (Mat&)a); + return a; +} + +template<typename _Tp> static inline +Mat_<_Tp>& operator -= (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, a); + return a; +} + +template<typename _Tp> static inline +const Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, (Mat&)a); + return a; +} + +static inline +Mat& operator *= (Mat& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, a); + return a; +} + +static inline +const Mat& operator *= (const Mat& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, (Mat&)a); + return a; +} + +template<typename _Tp> static inline +Mat_<_Tp>& operator *= (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, a); + return a; +} + +template<typename _Tp> static inline +const Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, (Mat&)a); + return a; +} + +static inline +Mat& operator /= (Mat& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, a); + return a; +} + +static inline +const Mat& operator /= (const Mat& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, (Mat&)a); + return a; +} + +template<typename _Tp> static inline +Mat_<_Tp>& operator /= (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, a); + return a; +} + +template<typename _Tp> static inline +const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, (Mat&)a); + return a; +} + + +//////////////////////////////// UMat //////////////////////////////// + +inline +UMat::UMat(UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{} + +inline +UMat::UMat(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_rows, _cols, _type); +} + +inline +UMat::UMat(int _rows, int _cols, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_rows, _cols, _type); + *this = _s; +} + +inline +UMat::UMat(Size _sz, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create( _sz.height, _sz.width, _type ); +} + +inline +UMat::UMat(Size _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_sz.height, _sz.width, _type); + *this = _s; +} + +inline +UMat::UMat(int _dims, const int* _sz, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_dims, _sz, _type); +} + +inline +UMat::UMat(int _dims, const int* _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_dims, _sz, _type); + *this = _s; +} + +inline +UMat::UMat(const UMat& m) +: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), + usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) +{ + addref(); + if( m.dims <= 2 ) + { + step[0] = m.step[0]; step[1] = m.step[1]; + } + else + { + dims = 0; + copySize(m); + } +} + + +template<typename _Tp> inline +UMat::UMat(const std::vector<_Tp>& vec, bool copyData) +: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), +cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) +{ + if(vec.empty()) + return; + if( !copyData ) + { + // !!!TODO!!! + CV_Error(Error::StsNotImplemented, ""); + } + else + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); +} + +inline +UMat& UMat::operator = (const UMat& m) +{ + if( this != &m ) + { + const_cast<UMat&>(m).addref(); + release(); + flags = m.flags; + if( dims <= 2 && m.dims <= 2 ) + { + dims = m.dims; + rows = m.rows; + cols = m.cols; + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + copySize(m); + allocator = m.allocator; + if (usageFlags == USAGE_DEFAULT) + usageFlags = m.usageFlags; + u = m.u; + offset = m.offset; + } + return *this; +} + +inline +UMat UMat::row(int y) const +{ + return UMat(*this, Range(y, y + 1), Range::all()); +} + +inline +UMat UMat::col(int x) const +{ + return UMat(*this, Range::all(), Range(x, x + 1)); +} + +inline +UMat UMat::rowRange(int startrow, int endrow) const +{ + return UMat(*this, Range(startrow, endrow), Range::all()); +} + +inline +UMat UMat::rowRange(const Range& r) const +{ + return UMat(*this, r, Range::all()); +} + +inline +UMat UMat::colRange(int startcol, int endcol) const +{ + return UMat(*this, Range::all(), Range(startcol, endcol)); +} + +inline +UMat UMat::colRange(const Range& r) const +{ + return UMat(*this, Range::all(), r); +} + +inline +UMat UMat::clone() const +{ + UMat m; + copyTo(m); + return m; +} + +inline +void UMat::assignTo( UMat& m, int _type ) const +{ + if( _type < 0 ) + m = *this; + else + convertTo(m, _type); +} + +inline +void UMat::create(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) +{ + _type &= TYPE_MASK; + if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && u ) + return; + int sz[] = {_rows, _cols}; + create(2, sz, _type, _usageFlags); +} + +inline +void UMat::create(Size _sz, int _type, UMatUsageFlags _usageFlags) +{ + create(_sz.height, _sz.width, _type, _usageFlags); +} + +inline +void UMat::addref() +{ + if( u ) + CV_XADD(&(u->urefcount), 1); +} + +inline void UMat::release() +{ + if( u && CV_XADD(&(u->urefcount), -1) == 1 ) + deallocate(); + for(int i = 0; i < dims; i++) + size.p[i] = 0; + u = 0; +} + +inline +UMat UMat::operator()( Range _rowRange, Range _colRange ) const +{ + return UMat(*this, _rowRange, _colRange); +} + +inline +UMat UMat::operator()( const Rect& roi ) const +{ + return UMat(*this, roi); +} + +inline +UMat UMat::operator()(const Range* ranges) const +{ + return UMat(*this, ranges); +} + +inline +UMat UMat::operator()(const std::vector<Range>& ranges) const +{ + return UMat(*this, ranges); +} + +inline +bool UMat::isContinuous() const +{ + return (flags & CONTINUOUS_FLAG) != 0; +} + +inline +bool UMat::isSubmatrix() const +{ + return (flags & SUBMATRIX_FLAG) != 0; +} + +inline +size_t UMat::elemSize() const +{ + size_t res = dims > 0 ? step.p[dims - 1] : 0; + CV_DbgAssert(res != 0); + return res; +} + +inline +size_t UMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int UMat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int UMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int UMat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t UMat::step1(int i) const +{ + return step.p[i] / elemSize1(); +} + +inline +bool UMat::empty() const +{ + return u == 0 || total() == 0 || dims == 0; +} + +inline +size_t UMat::total() const +{ + if( dims <= 2 ) + return (size_t)rows * cols; + size_t p = 1; + for( int i = 0; i < dims; i++ ) + p *= size[i]; + return p; +} + +#ifdef CV_CXX_MOVE_SEMANTICS + +inline +UMat::UMat(UMat&& m) +: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), + usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) +{ + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.allocator = NULL; + m.u = NULL; + m.offset = 0; +} + +inline +UMat& UMat::operator = (UMat&& m) +{ + if (this == &m) + return *this; + release(); + flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; + allocator = m.allocator; usageFlags = m.usageFlags; + u = m.u; + offset = m.offset; + if (step.p != step.buf) // release self step/size + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.allocator = NULL; + m.u = NULL; + m.offset = 0; + return *this; +} + +#endif + + +inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; } +inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; } +inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; } +inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; } +inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; } +inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; } + +inline void UMatData::markDeviceMemMapped(bool flag) +{ + if(flag) + flags |= DEVICE_MEM_MAPPED; + else + flags &= ~DEVICE_MEM_MAPPED; +} + +inline void UMatData::markHostCopyObsolete(bool flag) +{ + if(flag) + flags |= HOST_COPY_OBSOLETE; + else + flags &= ~HOST_COPY_OBSOLETE; +} +inline void UMatData::markDeviceCopyObsolete(bool flag) +{ + if(flag) + flags |= DEVICE_COPY_OBSOLETE; + else + flags &= ~DEVICE_COPY_OBSOLETE; +} + +//! @endcond + +} //cv + +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + +#endif diff --git a/include/opencv2/core/matx.hpp b/include/opencv2/core/matx.hpp new file mode 100644 index 0000000..d8e17e7 --- /dev/null +++ b/include/opencv2/core/matx.hpp @@ -0,0 +1,1477 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_MATX_HPP +#define OPENCV_CORE_MATX_HPP + +#ifndef __cplusplus +# error matx.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/base.hpp" +#include "opencv2/core/traits.hpp" +#include "opencv2/core/saturate.hpp" + +#ifdef CV_CXX11 +#include <initializer_list> +#endif + +namespace cv +{ + +//! @addtogroup core_basic +//! @{ + +////////////////////////////// Small Matrix /////////////////////////// + +//! @cond IGNORED +// FIXIT Remove this (especially CV_EXPORTS modifier) +struct CV_EXPORTS Matx_AddOp { Matx_AddOp() {} Matx_AddOp(const Matx_AddOp&) {} }; +struct CV_EXPORTS Matx_SubOp { Matx_SubOp() {} Matx_SubOp(const Matx_SubOp&) {} }; +struct CV_EXPORTS Matx_ScaleOp { Matx_ScaleOp() {} Matx_ScaleOp(const Matx_ScaleOp&) {} }; +struct CV_EXPORTS Matx_MulOp { Matx_MulOp() {} Matx_MulOp(const Matx_MulOp&) {} }; +struct CV_EXPORTS Matx_DivOp { Matx_DivOp() {} Matx_DivOp(const Matx_DivOp&) {} }; +struct CV_EXPORTS Matx_MatMulOp { Matx_MatMulOp() {} Matx_MatMulOp(const Matx_MatMulOp&) {} }; +struct CV_EXPORTS Matx_TOp { Matx_TOp() {} Matx_TOp(const Matx_TOp&) {} }; +//! @endcond + +/** @brief Template class for small matrices whose type and size are known at compilation time + +If you need a more flexible type, use Mat . The elements of the matrix M are accessible using the +M(i,j) notation. Most of the common matrix operations (see also @ref MatrixExpressions ) are +available. To do an operation on Matx that is not implemented, you can easily convert the matrix to +Mat and backwards: +@code{.cpp} + Matx33f m(1, 2, 3, + 4, 5, 6, + 7, 8, 9); + cout << sum(Mat(m*m.t())) << endl; +@endcode +Except of the plain constructor which takes a list of elements, Matx can be initialized from a C-array: +@code{.cpp} + float values[] = { 1, 2, 3}; + Matx31f m(values); +@endcode +In case if C++11 features are available, std::initializer_list can be also used to initialize Matx: +@code{.cpp} + Matx31f m = { 1, 2, 3}; +@endcode + */ +template<typename _Tp, int m, int n> class Matx +{ +public: + enum { + rows = m, + cols = n, + channels = rows*cols, +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = traits::Type<_Tp>::value, + type = CV_MAKETYPE(depth, channels), +#endif + shortdim = (m < n ? m : n) + }; + + typedef _Tp value_type; + typedef Matx<_Tp, m, n> mat_type; + typedef Matx<_Tp, shortdim, 1> diag_type; + + //! default constructor + Matx(); + + explicit Matx(_Tp v0); //!< 1x1 matrix + Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 1x10, 2x5 or 5x2 or 10x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, + _Tp v4, _Tp v5, _Tp v6, _Tp v7, + _Tp v8, _Tp v9, _Tp v10, _Tp v11); //!< 1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, + _Tp v4, _Tp v5, _Tp v6, _Tp v7, + _Tp v8, _Tp v9, _Tp v10, _Tp v11, + _Tp v12, _Tp v13); //!< 1x14, 2x7, 7x2 or 14x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, + _Tp v4, _Tp v5, _Tp v6, _Tp v7, + _Tp v8, _Tp v9, _Tp v10, _Tp v11, + _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix + explicit Matx(const _Tp* vals); //!< initialize from a plain array + +#ifdef CV_CXX11 + Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list +#endif + + static Matx all(_Tp alpha); + static Matx zeros(); + static Matx ones(); + static Matx eye(); + static Matx diag(const diag_type& d); + static Matx randu(_Tp a, _Tp b); + static Matx randn(_Tp a, _Tp b); + + //! dot product computed with the default precision + _Tp dot(const Matx<_Tp, m, n>& v) const; + + //! dot product computed in double-precision arithmetics + double ddot(const Matx<_Tp, m, n>& v) const; + + //! conversion to another data type + template<typename T2> operator Matx<T2, m, n>() const; + + //! change the matrix shape + template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const; + + //! extract part of the matrix + template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int base_row, int base_col) const; + + //! extract the matrix row + Matx<_Tp, 1, n> row(int i) const; + + //! extract the matrix column + Matx<_Tp, m, 1> col(int i) const; + + //! extract the matrix diagonal + diag_type diag() const; + + //! transpose the matrix + Matx<_Tp, n, m> t() const; + + //! invert the matrix + Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const; + + //! solve linear system + template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; + Vec<_Tp, n> solve(const Vec<_Tp, m>& rhs, int method) const; + + //! multiply two matrices element-wise + Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const; + + //! divide two matrices element-wise + Matx<_Tp, m, n> div(const Matx<_Tp, m, n>& a) const; + + //! element access + const _Tp& operator ()(int row, int col) const; + _Tp& operator ()(int row, int col); + + //! 1D element access + const _Tp& operator ()(int i) const; + _Tp& operator ()(int i); + + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp); + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp); + template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp); + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp); + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp); + template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp); + Matx(const Matx<_Tp, n, m>& a, Matx_TOp); + + _Tp val[m*n]; //< matrix elements +}; + +typedef Matx<float, 1, 2> Matx12f; +typedef Matx<double, 1, 2> Matx12d; +typedef Matx<float, 1, 3> Matx13f; +typedef Matx<double, 1, 3> Matx13d; +typedef Matx<float, 1, 4> Matx14f; +typedef Matx<double, 1, 4> Matx14d; +typedef Matx<float, 1, 6> Matx16f; +typedef Matx<double, 1, 6> Matx16d; + +typedef Matx<float, 2, 1> Matx21f; +typedef Matx<double, 2, 1> Matx21d; +typedef Matx<float, 3, 1> Matx31f; +typedef Matx<double, 3, 1> Matx31d; +typedef Matx<float, 4, 1> Matx41f; +typedef Matx<double, 4, 1> Matx41d; +typedef Matx<float, 6, 1> Matx61f; +typedef Matx<double, 6, 1> Matx61d; + +typedef Matx<float, 2, 2> Matx22f; +typedef Matx<double, 2, 2> Matx22d; +typedef Matx<float, 2, 3> Matx23f; +typedef Matx<double, 2, 3> Matx23d; +typedef Matx<float, 3, 2> Matx32f; +typedef Matx<double, 3, 2> Matx32d; + +typedef Matx<float, 3, 3> Matx33f; +typedef Matx<double, 3, 3> Matx33d; + +typedef Matx<float, 3, 4> Matx34f; +typedef Matx<double, 3, 4> Matx34d; +typedef Matx<float, 4, 3> Matx43f; +typedef Matx<double, 4, 3> Matx43d; + +typedef Matx<float, 4, 4> Matx44f; +typedef Matx<double, 4, 4> Matx44d; +typedef Matx<float, 6, 6> Matx66f; +typedef Matx<double, 6, 6> Matx66d; + +/*! + traits +*/ +template<typename _Tp, int m, int n> class DataType< Matx<_Tp, m, n> > +{ +public: + typedef Matx<_Tp, m, n> value_type; + typedef Matx<typename DataType<_Tp>::work_type, m, n> work_type; + typedef _Tp channel_type; + typedef value_type vec_type; + + enum { generic_type = 0, + channels = m * n, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; +}; + +namespace traits { +template<typename _Tp, int m, int n> +struct Depth< Matx<_Tp, m, n> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp, int m, int n> +struct Type< Matx<_Tp, m, n> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, n*m) }; }; +} // namespace + + +/** @brief Comma-separated Matrix Initializer +*/ +template<typename _Tp, int m, int n> class MatxCommaInitializer +{ +public: + MatxCommaInitializer(Matx<_Tp, m, n>* _mtx); + template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val); + Matx<_Tp, m, n> operator *() const; + + Matx<_Tp, m, n>* dst; + int idx; +}; + +/* + Utility methods +*/ +template<typename _Tp, int m> static double determinant(const Matx<_Tp, m, m>& a); +template<typename _Tp, int m, int n> static double trace(const Matx<_Tp, m, n>& a); +template<typename _Tp, int m, int n> static double norm(const Matx<_Tp, m, n>& M); +template<typename _Tp, int m, int n> static double norm(const Matx<_Tp, m, n>& M, int normType); + + + +/////////////////////// Vec (used as element of multi-channel images ///////////////////// + +/** @brief Template class for short numerical vectors, a partial case of Matx + +This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements) on which you +can perform basic arithmetical operations, access individual elements using [] operator etc. The +vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc., which +elements are dynamically allocated in the heap. + +The template takes 2 parameters: +@tparam _Tp element type +@tparam cn the number of elements + +In addition to the universal notation like Vec<float, 3>, you can use shorter aliases +for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec<float, 3>. + +It is possible to convert Vec\<T,2\> to/from Point_, Vec\<T,3\> to/from Point3_ , and Vec\<T,4\> +to CvScalar or Scalar_. Use operator[] to access the elements of Vec. + +All the expected vector operations are also implemented: +- v1 = v2 + v3 +- v1 = v2 - v3 +- v1 = v2 \* scale +- v1 = scale \* v2 +- v1 = -v2 +- v1 += v2 and other augmenting operations +- v1 == v2, v1 != v2 +- norm(v1) (euclidean norm) +The Vec class is commonly used to describe pixel types of multi-channel arrays. See Mat for details. +*/ +template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1> +{ +public: + typedef _Tp value_type; + enum { + channels = cn, +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = Matx<_Tp, cn, 1>::depth, + type = CV_MAKETYPE(depth, channels), +#endif + _dummy_enum_finalizer = 0 + }; + + //! default constructor + Vec(); + + Vec(_Tp v0); //!< 1-element vector constructor + Vec(_Tp v0, _Tp v1); //!< 2-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2); //!< 3-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 4-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 5-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 6-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 7-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 8-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 9-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 10-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13); //!< 14-element vector constructor + explicit Vec(const _Tp* values); + +#ifdef CV_CXX11 + Vec(std::initializer_list<_Tp>); +#endif + + Vec(const Vec<_Tp, cn>& v); + + static Vec all(_Tp alpha); + + //! per-element multiplication + Vec mul(const Vec<_Tp, cn>& v) const; + + //! conjugation (makes sense for complex numbers and quaternions) + Vec conj() const; + + /*! + cross product of the two 3D vectors. + + For other dimensionalities the exception is raised + */ + Vec cross(const Vec& v) const; + //! conversion to another data type + template<typename T2> operator Vec<T2, cn>() const; + + /*! element access */ + const _Tp& operator [](int i) const; + _Tp& operator[](int i); + const _Tp& operator ()(int i) const; + _Tp& operator ()(int i); + + Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp); + Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp); + template<typename _T2> Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp); +}; + +/** @name Shorter aliases for the most popular specializations of Vec<T,n> + @{ +*/ +typedef Vec<uchar, 2> Vec2b; +typedef Vec<uchar, 3> Vec3b; +typedef Vec<uchar, 4> Vec4b; + +typedef Vec<short, 2> Vec2s; +typedef Vec<short, 3> Vec3s; +typedef Vec<short, 4> Vec4s; + +typedef Vec<ushort, 2> Vec2w; +typedef Vec<ushort, 3> Vec3w; +typedef Vec<ushort, 4> Vec4w; + +typedef Vec<int, 2> Vec2i; +typedef Vec<int, 3> Vec3i; +typedef Vec<int, 4> Vec4i; +typedef Vec<int, 6> Vec6i; +typedef Vec<int, 8> Vec8i; + +typedef Vec<float, 2> Vec2f; +typedef Vec<float, 3> Vec3f; +typedef Vec<float, 4> Vec4f; +typedef Vec<float, 6> Vec6f; + +typedef Vec<double, 2> Vec2d; +typedef Vec<double, 3> Vec3d; +typedef Vec<double, 4> Vec4d; +typedef Vec<double, 6> Vec6d; +/** @} */ + +/*! + traits +*/ +template<typename _Tp, int cn> class DataType< Vec<_Tp, cn> > +{ +public: + typedef Vec<_Tp, cn> value_type; + typedef Vec<typename DataType<_Tp>::work_type, cn> work_type; + typedef _Tp channel_type; + typedef value_type vec_type; + + enum { generic_type = 0, + channels = cn, + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8), +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = DataType<channel_type>::depth, + type = CV_MAKETYPE(depth, channels), +#endif + _dummy_enum_finalizer = 0 + }; +}; + +namespace traits { +template<typename _Tp, int cn> +struct Depth< Vec<_Tp, cn> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp, int cn> +struct Type< Vec<_Tp, cn> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, cn) }; }; +} // namespace + + +/** @brief Comma-separated Vec Initializer +*/ +template<typename _Tp, int m> class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1> +{ +public: + VecCommaInitializer(Vec<_Tp, m>* _vec); + template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val); + Vec<_Tp, m> operator *() const; +}; + +template<typename _Tp, int cn> static Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v); + +//! @} core_basic + +//! @cond IGNORED + +///////////////////////////////////// helper classes ///////////////////////////////////// +namespace internal +{ + +template<typename _Tp, int m> struct Matx_DetOp +{ + double operator ()(const Matx<_Tp, m, m>& a) const + { + Matx<_Tp, m, m> temp = a; + double p = LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0); + if( p == 0 ) + return p; + for( int i = 0; i < m; i++ ) + p *= temp(i, i); + return p; + } +}; + +template<typename _Tp> struct Matx_DetOp<_Tp, 1> +{ + double operator ()(const Matx<_Tp, 1, 1>& a) const + { + return a(0,0); + } +}; + +template<typename _Tp> struct Matx_DetOp<_Tp, 2> +{ + double operator ()(const Matx<_Tp, 2, 2>& a) const + { + return a(0,0)*a(1,1) - a(0,1)*a(1,0); + } +}; + +template<typename _Tp> struct Matx_DetOp<_Tp, 3> +{ + double operator ()(const Matx<_Tp, 3, 3>& a) const + { + return a(0,0)*(a(1,1)*a(2,2) - a(2,1)*a(1,2)) - + a(0,1)*(a(1,0)*a(2,2) - a(2,0)*a(1,2)) + + a(0,2)*(a(1,0)*a(2,1) - a(2,0)*a(1,1)); + } +}; + +template<typename _Tp> Vec<_Tp, 2> inline conjugate(const Vec<_Tp, 2>& v) +{ + return Vec<_Tp, 2>(v[0], -v[1]); +} + +template<typename _Tp> Vec<_Tp, 4> inline conjugate(const Vec<_Tp, 4>& v) +{ + return Vec<_Tp, 4>(v[0], -v[1], -v[2], -v[3]); +} + +} // internal + + + +////////////////////////////////// Matx Implementation /////////////////////////////////// + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx() +{ + for(int i = 0; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0) +{ + val[0] = v0; + for(int i = 1; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1) +{ + CV_StaticAssert(channels >= 2, "Matx should have at least 2 elements."); + val[0] = v0; val[1] = v1; + for(int i = 2; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2) +{ + CV_StaticAssert(channels >= 3, "Matx should have at least 3 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; + for(int i = 3; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3) +{ + CV_StaticAssert(channels >= 4, "Matx should have at least 4 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + for(int i = 4; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4) +{ + CV_StaticAssert(channels >= 5, "Matx should have at least 5 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; val[4] = v4; + for(int i = 5; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5) +{ + CV_StaticAssert(channels >= 6, "Matx should have at least 6 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; + for(int i = 6; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6) +{ + CV_StaticAssert(channels >= 7, "Matx should have at least 7 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; + for(int i = 7; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7) +{ + CV_StaticAssert(channels >= 8, "Matx should have at least 8 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + for(int i = 8; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8) +{ + CV_StaticAssert(channels >= 9, "Matx should have at least 9 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; + for(int i = 9; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9) +{ + CV_StaticAssert(channels >= 10, "Matx should have at least 10 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; + for(int i = 10; i < channels; i++) val[i] = _Tp(0); +} + + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11) +{ + CV_StaticAssert(channels >= 12, "Matx should have at least 12 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; + for(int i = 12; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13) +{ + CV_StaticAssert(channels >= 14, "Matx should have at least 14 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; + val[12] = v12; val[13] = v13; + for (int i = 14; i < channels; i++) val[i] = _Tp(0); +} + + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13, _Tp v14, _Tp v15) +{ + CV_StaticAssert(channels >= 16, "Matx should have at least 16 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; + val[12] = v12; val[13] = v13; val[14] = v14; val[15] = v15; + for(int i = 16; i < channels; i++) val[i] = _Tp(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(const _Tp* values) +{ + for( int i = 0; i < channels; i++ ) val[i] = values[i]; +} + +#ifdef CV_CXX11 +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list) +{ + CV_DbgAssert(list.size() == channels); + int i = 0; + for(const auto& elem : list) + { + val[i++] = elem; + } +} +#endif + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n> Matx<_Tp, m, n>::all(_Tp alpha) +{ + Matx<_Tp, m, n> M; + for( int i = 0; i < m*n; i++ ) M.val[i] = alpha; + return M; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::zeros() +{ + return all(0); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::ones() +{ + return all(1); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::eye() +{ + Matx<_Tp,m,n> M; + for(int i = 0; i < shortdim; i++) + M(i,i) = 1; + return M; +} + +template<typename _Tp, int m, int n> inline +_Tp Matx<_Tp, m, n>::dot(const Matx<_Tp, m, n>& M) const +{ + _Tp s = 0; + for( int i = 0; i < channels; i++ ) s += val[i]*M.val[i]; + return s; +} + +template<typename _Tp, int m, int n> inline +double Matx<_Tp, m, n>::ddot(const Matx<_Tp, m, n>& M) const +{ + double s = 0; + for( int i = 0; i < channels; i++ ) s += (double)val[i]*M.val[i]; + return s; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const typename Matx<_Tp,m,n>::diag_type& d) +{ + Matx<_Tp,m,n> M; + for(int i = 0; i < shortdim; i++) + M(i,i) = d(i, 0); + return M; +} + +template<typename _Tp, int m, int n> template<typename T2> +inline Matx<_Tp, m, n>::operator Matx<T2, m, n>() const +{ + Matx<T2, m, n> M; + for( int i = 0; i < m*n; i++ ) M.val[i] = saturate_cast<T2>(val[i]); + return M; +} + +template<typename _Tp, int m, int n> template<int m1, int n1> inline +Matx<_Tp, m1, n1> Matx<_Tp, m, n>::reshape() const +{ + CV_StaticAssert(m1*n1 == m*n, "Input and destnarion matrices must have the same number of elements"); + return (const Matx<_Tp, m1, n1>&)*this; +} + +template<typename _Tp, int m, int n> +template<int m1, int n1> inline +Matx<_Tp, m1, n1> Matx<_Tp, m, n>::get_minor(int base_row, int base_col) const +{ + CV_DbgAssert(0 <= base_row && base_row+m1 <= m && 0 <= base_col && base_col+n1 <= n); + Matx<_Tp, m1, n1> s; + for( int di = 0; di < m1; di++ ) + for( int dj = 0; dj < n1; dj++ ) + s(di, dj) = (*this)(base_row+di, base_col+dj); + return s; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, 1, n> Matx<_Tp, m, n>::row(int i) const +{ + CV_DbgAssert((unsigned)i < (unsigned)m); + return Matx<_Tp, 1, n>(&val[i*n]); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, 1> Matx<_Tp, m, n>::col(int j) const +{ + CV_DbgAssert((unsigned)j < (unsigned)n); + Matx<_Tp, m, 1> v; + for( int i = 0; i < m; i++ ) + v.val[i] = val[i*n + j]; + return v; +} + +template<typename _Tp, int m, int n> inline +typename Matx<_Tp, m, n>::diag_type Matx<_Tp, m, n>::diag() const +{ + diag_type d; + for( int i = 0; i < shortdim; i++ ) + d.val[i] = val[i*n + i]; + return d; +} + +template<typename _Tp, int m, int n> inline +const _Tp& Matx<_Tp, m, n>::operator()(int row_idx, int col_idx) const +{ + CV_DbgAssert( (unsigned)row_idx < (unsigned)m && (unsigned)col_idx < (unsigned)n ); + return this->val[row_idx*n + col_idx]; +} + +template<typename _Tp, int m, int n> inline +_Tp& Matx<_Tp, m, n>::operator ()(int row_idx, int col_idx) +{ + CV_DbgAssert( (unsigned)row_idx < (unsigned)m && (unsigned)col_idx < (unsigned)n ); + return val[row_idx*n + col_idx]; +} + +template<typename _Tp, int m, int n> inline +const _Tp& Matx<_Tp, m, n>::operator ()(int i) const +{ + CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row"); + CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) ); + return val[i]; +} + +template<typename _Tp, int m, int n> inline +_Tp& Matx<_Tp, m, n>::operator ()(int i) +{ + CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row"); + CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) ); + return val[i]; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] + b.val[i]); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] - b.val[i]); +} + +template<typename _Tp, int m, int n> template<typename _T2> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] * alpha); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] * b.val[i]); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] / b.val[i]); +} + +template<typename _Tp, int m, int n> template<int l> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp) +{ + for( int i = 0; i < m; i++ ) + for( int j = 0; j < n; j++ ) + { + _Tp s = 0; + for( int k = 0; k < l; k++ ) + s += a(i, k) * b(k, j); + val[i*n + j] = s; + } +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, n, m>& a, Matx_TOp) +{ + for( int i = 0; i < m; i++ ) + for( int j = 0; j < n; j++ ) + val[i*n + j] = a(j, i); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n> Matx<_Tp, m, n>::mul(const Matx<_Tp, m, n>& a) const +{ + return Matx<_Tp, m, n>(*this, a, Matx_MulOp()); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n> Matx<_Tp, m, n>::div(const Matx<_Tp, m, n>& a) const +{ + return Matx<_Tp, m, n>(*this, a, Matx_DivOp()); +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, n, m> Matx<_Tp, m, n>::t() const +{ + return Matx<_Tp, n, m>(*this, Matx_TOp()); +} + +template<typename _Tp, int m, int n> inline +Vec<_Tp, n> Matx<_Tp, m, n>::solve(const Vec<_Tp, m>& rhs, int method) const +{ + Matx<_Tp, n, 1> x = solve((const Matx<_Tp, m, 1>&)(rhs), method); + return (Vec<_Tp, n>&)(x); +} + +template<typename _Tp, int m> static inline +double determinant(const Matx<_Tp, m, m>& a) +{ + return cv::internal::Matx_DetOp<_Tp, m>()(a); +} + +template<typename _Tp, int m, int n> static inline +double trace(const Matx<_Tp, m, n>& a) +{ + _Tp s = 0; + for( int i = 0; i < std::min(m, n); i++ ) + s += a(i,i); + return s; +} + +template<typename _Tp, int m, int n> static inline +double norm(const Matx<_Tp, m, n>& M) +{ + return std::sqrt(normL2Sqr<_Tp, double>(M.val, m*n)); +} + +template<typename _Tp, int m, int n> static inline +double norm(const Matx<_Tp, m, n>& M, int normType) +{ + switch(normType) { + case NORM_INF: + return (double)normInf<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); + case NORM_L1: + return (double)normL1<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); + case NORM_L2SQR: + return (double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); + default: + case NORM_L2: + return std::sqrt((double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n)); + } +} + + + +//////////////////////////////// matx comma initializer ////////////////////////////////// + +template<typename _Tp, typename _T2, int m, int n> static inline +MatxCommaInitializer<_Tp, m, n> operator << (const Matx<_Tp, m, n>& mtx, _T2 val) +{ + MatxCommaInitializer<_Tp, m, n> commaInitializer((Matx<_Tp, m, n>*)&mtx); + return (commaInitializer, val); +} + +template<typename _Tp, int m, int n> inline +MatxCommaInitializer<_Tp, m, n>::MatxCommaInitializer(Matx<_Tp, m, n>* _mtx) + : dst(_mtx), idx(0) +{} + +template<typename _Tp, int m, int n> template<typename _T2> inline +MatxCommaInitializer<_Tp, m, n>& MatxCommaInitializer<_Tp, m, n>::operator , (_T2 value) +{ + CV_DbgAssert( idx < m*n ); + dst->val[idx++] = saturate_cast<_Tp>(value); + return *this; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, m, n> MatxCommaInitializer<_Tp, m, n>::operator *() const +{ + CV_DbgAssert( idx == n*m ); + return *dst; +} + + + +/////////////////////////////////// Vec Implementation /////////////////////////////////// + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec() {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0) + : Matx<_Tp, cn, 1>(v0) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1) + : Matx<_Tp, cn, 1>(v0, v1) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2) + : Matx<_Tp, cn, 1>(v0, v1, v2) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(const _Tp* values) + : Matx<_Tp, cn, 1>(values) {} + +#ifdef CV_CXX11 +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list) + : Matx<_Tp, cn, 1>(list) {} +#endif + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m) + : Matx<_Tp, cn, 1>(m.val) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp op) + : Matx<_Tp, cn, 1>(a, b, op) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp op) + : Matx<_Tp, cn, 1>(a, b, op) {} + +template<typename _Tp, int cn> template<typename _T2> inline +Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp op) + : Matx<_Tp, cn, 1>(a, alpha, op) {} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn> Vec<_Tp, cn>::all(_Tp alpha) +{ + Vec v; + for( int i = 0; i < cn; i++ ) v.val[i] = alpha; + return v; +} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn> Vec<_Tp, cn>::mul(const Vec<_Tp, cn>& v) const +{ + Vec<_Tp, cn> w; + for( int i = 0; i < cn; i++ ) w.val[i] = saturate_cast<_Tp>(this->val[i]*v.val[i]); + return w; +} + +template<> inline +Vec<float, 2> Vec<float, 2>::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<> inline +Vec<double, 2> Vec<double, 2>::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<> inline +Vec<float, 4> Vec<float, 4>::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<> inline +Vec<double, 4> Vec<double, 4>::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn> Vec<_Tp, cn>::cross(const Vec<_Tp, cn>&) const +{ + CV_StaticAssert(cn == 3, "for arbitrary-size vector there is no cross-product defined"); + return Vec<_Tp, cn>(); +} + +template<> inline +Vec<float, 3> Vec<float, 3>::cross(const Vec<float, 3>& v) const +{ + return Vec<float,3>(this->val[1]*v.val[2] - this->val[2]*v.val[1], + this->val[2]*v.val[0] - this->val[0]*v.val[2], + this->val[0]*v.val[1] - this->val[1]*v.val[0]); +} + +template<> inline +Vec<double, 3> Vec<double, 3>::cross(const Vec<double, 3>& v) const +{ + return Vec<double,3>(this->val[1]*v.val[2] - this->val[2]*v.val[1], + this->val[2]*v.val[0] - this->val[0]*v.val[2], + this->val[0]*v.val[1] - this->val[1]*v.val[0]); +} + +template<typename _Tp, int cn> template<typename T2> inline +Vec<_Tp, cn>::operator Vec<T2, cn>() const +{ + Vec<T2, cn> v; + for( int i = 0; i < cn; i++ ) v.val[i] = saturate_cast<T2>(this->val[i]); + return v; +} + +template<typename _Tp, int cn> inline +const _Tp& Vec<_Tp, cn>::operator [](int i) const +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template<typename _Tp, int cn> inline +_Tp& Vec<_Tp, cn>::operator [](int i) +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template<typename _Tp, int cn> inline +const _Tp& Vec<_Tp, cn>::operator ()(int i) const +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template<typename _Tp, int cn> inline +_Tp& Vec<_Tp, cn>::operator ()(int i) +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v) +{ + double nv = norm(v); + return v * (nv ? 1./nv : 0.); +} + + + +//////////////////////////////// vec comma initializer ////////////////////////////////// + + +template<typename _Tp, typename _T2, int cn> static inline +VecCommaInitializer<_Tp, cn> operator << (const Vec<_Tp, cn>& vec, _T2 val) +{ + VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec); + return (commaInitializer, val); +} + +template<typename _Tp, int cn> inline +VecCommaInitializer<_Tp, cn>::VecCommaInitializer(Vec<_Tp, cn>* _vec) + : MatxCommaInitializer<_Tp, cn, 1>(_vec) +{} + +template<typename _Tp, int cn> template<typename _T2> inline +VecCommaInitializer<_Tp, cn>& VecCommaInitializer<_Tp, cn>::operator , (_T2 value) +{ + CV_DbgAssert( this->idx < cn ); + this->dst->val[this->idx++] = saturate_cast<_Tp>(value); + return *this; +} + +template<typename _Tp, int cn> inline +Vec<_Tp, cn> VecCommaInitializer<_Tp, cn>::operator *() const +{ + CV_DbgAssert( this->idx == cn ); + return *this->dst; +} + +//! @endcond + +///////////////////////////// Matx out-of-class operators //////////////////////////////// + +//! @relates cv::Matx +//! @{ + +template<typename _Tp1, typename _Tp2, int m, int n> static inline +Matx<_Tp1, m, n>& operator += (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); + return a; +} + +template<typename _Tp1, typename _Tp2, int m, int n> static inline +Matx<_Tp1, m, n>& operator -= (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); + return a; +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator + (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + return Matx<_Tp, m, n>(a, b, Matx_AddOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + return Matx<_Tp, m, n>(a, b, Matx_SubOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, int alpha) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); + return a; +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, float alpha) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); + return a; +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, double alpha) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); + return a; +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, int alpha) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, float alpha) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, double alpha) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator * (int alpha, const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator * (float alpha, const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator * (double alpha, const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n> static inline +Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, -1, Matx_ScaleOp()); +} + +template<typename _Tp, int m, int n, int l> static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b) +{ + return Matx<_Tp, m, n>(a, b, Matx_MatMulOp()); +} + +template<typename _Tp, int m, int n> static inline +Vec<_Tp, m> operator * (const Matx<_Tp, m, n>& a, const Vec<_Tp, n>& b) +{ + Matx<_Tp, m, 1> c(a, b, Matx_MatMulOp()); + return (const Vec<_Tp, m>&)(c); +} + +template<typename _Tp, int m, int n> static inline +bool operator == (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + for( int i = 0; i < m*n; i++ ) + if( a.val[i] != b.val[i] ) return false; + return true; +} + +template<typename _Tp, int m, int n> static inline +bool operator != (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + return !(a == b); +} + +//! @} + +////////////////////////////// Vec out-of-class operators //////////////////////////////// + +//! @relates cv::Vec +//! @{ + +template<typename _Tp1, typename _Tp2, int cn> static inline +Vec<_Tp1, cn>& operator += (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) +{ + for( int i = 0; i < cn; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); + return a; +} + +template<typename _Tp1, typename _Tp2, int cn> static inline +Vec<_Tp1, cn>& operator -= (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) +{ + for( int i = 0; i < cn; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator + (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) +{ + return Vec<_Tp, cn>(a, b, Matx_AddOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) +{ + return Vec<_Tp, cn>(a, b, Matx_SubOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, int alpha) +{ + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*alpha); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, float alpha) +{ + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*alpha); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, double alpha) +{ + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*alpha); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, int alpha) +{ + double ialpha = 1./alpha; + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*ialpha); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, float alpha) +{ + float ialpha = 1.f/alpha; + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*ialpha); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, double alpha) +{ + double ialpha = 1./alpha; + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*ialpha); + return a; +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, int alpha) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator * (int alpha, const Vec<_Tp, cn>& a) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, float alpha) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator * (float alpha, const Vec<_Tp, cn>& a) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, double alpha) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator * (double alpha, const Vec<_Tp, cn>& a) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, int alpha) +{ + return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, float alpha) +{ + return Vec<_Tp, cn>(a, 1.f/alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, double alpha) +{ + return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); +} + +template<typename _Tp, int cn> static inline +Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a) +{ + Vec<_Tp,cn> t; + for( int i = 0; i < cn; i++ ) t.val[i] = saturate_cast<_Tp>(-a.val[i]); + return t; +} + +template<typename _Tp> inline Vec<_Tp, 4> operator * (const Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) +{ + return Vec<_Tp, 4>(saturate_cast<_Tp>(v1[0]*v2[0] - v1[1]*v2[1] - v1[2]*v2[2] - v1[3]*v2[3]), + saturate_cast<_Tp>(v1[0]*v2[1] + v1[1]*v2[0] + v1[2]*v2[3] - v1[3]*v2[2]), + saturate_cast<_Tp>(v1[0]*v2[2] - v1[1]*v2[3] + v1[2]*v2[0] + v1[3]*v2[1]), + saturate_cast<_Tp>(v1[0]*v2[3] + v1[1]*v2[2] - v1[2]*v2[1] + v1[3]*v2[0])); +} + +template<typename _Tp> inline Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) +{ + v1 = v1 * v2; + return v1; +} + +//! @} + +} // cv + +#endif // OPENCV_CORE_MATX_HPP diff --git a/include/opencv2/core/neon_utils.hpp b/include/opencv2/core/neon_utils.hpp new file mode 100644 index 0000000..573ba99 --- /dev/null +++ b/include/opencv2/core/neon_utils.hpp @@ -0,0 +1,128 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HAL_NEON_UTILS_HPP +#define OPENCV_HAL_NEON_UTILS_HPP + +#include "opencv2/core/cvdef.h" + +//! @addtogroup core_utils_neon +//! @{ + +#if CV_NEON + +inline int32x2_t cv_vrnd_s32_f32(float32x2_t v) +{ + static int32x2_t v_sign = vdup_n_s32(1 << 31), + v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f)); + + int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v))); + return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition))); +} + +inline int32x4_t cv_vrndq_s32_f32(float32x4_t v) +{ + static int32x4_t v_sign = vdupq_n_s32(1 << 31), + v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); + + int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v))); + return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition))); +} + +inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v) +{ + static float32x2_t v_05 = vdup_n_f32(0.5f); + return vcvt_u32_f32(vadd_f32(v, v_05)); +} + +inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v) +{ + static float32x4_t v_05 = vdupq_n_f32(0.5f); + return vcvtq_u32_f32(vaddq_f32(v, v_05)); +} + +inline float32x4_t cv_vrecpq_f32(float32x4_t val) +{ + float32x4_t reciprocal = vrecpeq_f32(val); + reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); + reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); + return reciprocal; +} + +inline float32x2_t cv_vrecp_f32(float32x2_t val) +{ + float32x2_t reciprocal = vrecpe_f32(val); + reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); + reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); + return reciprocal; +} + +inline float32x4_t cv_vrsqrtq_f32(float32x4_t val) +{ + float32x4_t e = vrsqrteq_f32(val); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); + return e; +} + +inline float32x2_t cv_vrsqrt_f32(float32x2_t val) +{ + float32x2_t e = vrsqrte_f32(val); + e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); + e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); + return e; +} + +inline float32x4_t cv_vsqrtq_f32(float32x4_t val) +{ + return cv_vrecpq_f32(cv_vrsqrtq_f32(val)); +} + +inline float32x2_t cv_vsqrt_f32(float32x2_t val) +{ + return cv_vrecp_f32(cv_vrsqrt_f32(val)); +} + +#endif + +//! @} + +#endif // OPENCV_HAL_NEON_UTILS_HPP diff --git a/include/opencv2/core/ocl.hpp b/include/opencv2/core/ocl.hpp new file mode 100644 index 0000000..95f0fcd --- /dev/null +++ b/include/opencv2/core/ocl.hpp @@ -0,0 +1,843 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_OPENCL_HPP +#define OPENCV_OPENCL_HPP + +#include "opencv2/core.hpp" + +namespace cv { namespace ocl { + +//! @addtogroup core_opencl +//! @{ + +CV_EXPORTS_W bool haveOpenCL(); +CV_EXPORTS_W bool useOpenCL(); +CV_EXPORTS_W bool haveAmdBlas(); +CV_EXPORTS_W bool haveAmdFft(); +CV_EXPORTS_W void setUseOpenCL(bool flag); +CV_EXPORTS_W void finish(); + +CV_EXPORTS bool haveSVM(); + +class CV_EXPORTS Context; +class CV_EXPORTS_W_SIMPLE Device; +class CV_EXPORTS Kernel; +class CV_EXPORTS Program; +class CV_EXPORTS ProgramSource; +class CV_EXPORTS Queue; +class CV_EXPORTS PlatformInfo; +class CV_EXPORTS Image2D; + +class CV_EXPORTS_W_SIMPLE Device +{ +public: + CV_WRAP Device(); + explicit Device(void* d); + Device(const Device& d); + Device& operator = (const Device& d); + CV_WRAP ~Device(); + + void set(void* d); + + enum + { + TYPE_DEFAULT = (1 << 0), + TYPE_CPU = (1 << 1), + TYPE_GPU = (1 << 2), + TYPE_ACCELERATOR = (1 << 3), + TYPE_DGPU = TYPE_GPU + (1 << 16), + TYPE_IGPU = TYPE_GPU + (1 << 17), + TYPE_ALL = 0xFFFFFFFF + }; + + CV_WRAP String name() const; + CV_WRAP String extensions() const; + CV_WRAP bool isExtensionSupported(const String& extensionName) const; + CV_WRAP String version() const; + CV_WRAP String vendorName() const; + CV_WRAP String OpenCL_C_Version() const; + CV_WRAP String OpenCLVersion() const; + CV_WRAP int deviceVersionMajor() const; + CV_WRAP int deviceVersionMinor() const; + CV_WRAP String driverVersion() const; + void* ptr() const; + + CV_WRAP int type() const; + + CV_WRAP int addressBits() const; + CV_WRAP bool available() const; + CV_WRAP bool compilerAvailable() const; + CV_WRAP bool linkerAvailable() const; + + enum + { + FP_DENORM=(1 << 0), + FP_INF_NAN=(1 << 1), + FP_ROUND_TO_NEAREST=(1 << 2), + FP_ROUND_TO_ZERO=(1 << 3), + FP_ROUND_TO_INF=(1 << 4), + FP_FMA=(1 << 5), + FP_SOFT_FLOAT=(1 << 6), + FP_CORRECTLY_ROUNDED_DIVIDE_SQRT=(1 << 7) + }; + CV_WRAP int doubleFPConfig() const; + CV_WRAP int singleFPConfig() const; + CV_WRAP int halfFPConfig() const; + + CV_WRAP bool endianLittle() const; + CV_WRAP bool errorCorrectionSupport() const; + + enum + { + EXEC_KERNEL=(1 << 0), + EXEC_NATIVE_KERNEL=(1 << 1) + }; + CV_WRAP int executionCapabilities() const; + + CV_WRAP size_t globalMemCacheSize() const; + + enum + { + NO_CACHE=0, + READ_ONLY_CACHE=1, + READ_WRITE_CACHE=2 + }; + CV_WRAP int globalMemCacheType() const; + CV_WRAP int globalMemCacheLineSize() const; + CV_WRAP size_t globalMemSize() const; + + CV_WRAP size_t localMemSize() const; + enum + { + NO_LOCAL_MEM=0, + LOCAL_IS_LOCAL=1, + LOCAL_IS_GLOBAL=2 + }; + CV_WRAP int localMemType() const; + CV_WRAP bool hostUnifiedMemory() const; + + CV_WRAP bool imageSupport() const; + + CV_WRAP bool imageFromBufferSupport() const; + uint imagePitchAlignment() const; + uint imageBaseAddressAlignment() const; + + /// deprecated, use isExtensionSupported() method (probably with "cl_khr_subgroups" value) + CV_WRAP bool intelSubgroupsSupport() const; + + CV_WRAP size_t image2DMaxWidth() const; + CV_WRAP size_t image2DMaxHeight() const; + + CV_WRAP size_t image3DMaxWidth() const; + CV_WRAP size_t image3DMaxHeight() const; + CV_WRAP size_t image3DMaxDepth() const; + + CV_WRAP size_t imageMaxBufferSize() const; + CV_WRAP size_t imageMaxArraySize() const; + + enum + { + UNKNOWN_VENDOR=0, + VENDOR_AMD=1, + VENDOR_INTEL=2, + VENDOR_NVIDIA=3 + }; + CV_WRAP int vendorID() const; + // FIXIT + // dev.isAMD() doesn't work for OpenCL CPU devices from AMD OpenCL platform. + // This method should use platform name instead of vendor name. + // After fix restore code in arithm.cpp: ocl_compare() + CV_WRAP inline bool isAMD() const { return vendorID() == VENDOR_AMD; } + CV_WRAP inline bool isIntel() const { return vendorID() == VENDOR_INTEL; } + CV_WRAP inline bool isNVidia() const { return vendorID() == VENDOR_NVIDIA; } + + CV_WRAP int maxClockFrequency() const; + CV_WRAP int maxComputeUnits() const; + CV_WRAP int maxConstantArgs() const; + CV_WRAP size_t maxConstantBufferSize() const; + + CV_WRAP size_t maxMemAllocSize() const; + CV_WRAP size_t maxParameterSize() const; + + CV_WRAP int maxReadImageArgs() const; + CV_WRAP int maxWriteImageArgs() const; + CV_WRAP int maxSamplers() const; + + CV_WRAP size_t maxWorkGroupSize() const; + CV_WRAP int maxWorkItemDims() const; + void maxWorkItemSizes(size_t*) const; + + CV_WRAP int memBaseAddrAlign() const; + + CV_WRAP int nativeVectorWidthChar() const; + CV_WRAP int nativeVectorWidthShort() const; + CV_WRAP int nativeVectorWidthInt() const; + CV_WRAP int nativeVectorWidthLong() const; + CV_WRAP int nativeVectorWidthFloat() const; + CV_WRAP int nativeVectorWidthDouble() const; + CV_WRAP int nativeVectorWidthHalf() const; + + CV_WRAP int preferredVectorWidthChar() const; + CV_WRAP int preferredVectorWidthShort() const; + CV_WRAP int preferredVectorWidthInt() const; + CV_WRAP int preferredVectorWidthLong() const; + CV_WRAP int preferredVectorWidthFloat() const; + CV_WRAP int preferredVectorWidthDouble() const; + CV_WRAP int preferredVectorWidthHalf() const; + + CV_WRAP size_t printfBufferSize() const; + CV_WRAP size_t profilingTimerResolution() const; + + CV_WRAP static const Device& getDefault(); + +protected: + struct Impl; + Impl* p; +}; + + +class CV_EXPORTS Context +{ +public: + Context(); + explicit Context(int dtype); + ~Context(); + Context(const Context& c); + Context& operator = (const Context& c); + + bool create(); + bool create(int dtype); + size_t ndevices() const; + const Device& device(size_t idx) const; + Program getProg(const ProgramSource& prog, + const String& buildopt, String& errmsg); + void unloadProg(Program& prog); + + static Context& getDefault(bool initialize = true); + void* ptr() const; + + friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); + + bool useSVM() const; + void setUseSVM(bool enabled); + + struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +//protected: + Impl* p; +}; + +class CV_EXPORTS Platform +{ +public: + Platform(); + ~Platform(); + Platform(const Platform& p); + Platform& operator = (const Platform& p); + + void* ptr() const; + static Platform& getDefault(); + + friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); +protected: + struct Impl; + Impl* p; +}; + +/** @brief Attaches OpenCL context to OpenCV +@note + OpenCV will check if available OpenCL platform has platformName name, then assign context to + OpenCV and call `clRetainContext` function. The deviceID device will be used as target device and + new command queue will be created. +@param platformName name of OpenCL platform to attach, this string is used to check if platform is available to OpenCV at runtime +@param platformID ID of platform attached context was created for +@param context OpenCL context to be attached to OpenCV +@param deviceID ID of device, must be created from attached context +*/ +CV_EXPORTS void attachContext(const String& platformName, void* platformID, void* context, void* deviceID); + +/** @brief Convert OpenCL buffer to UMat +@note + OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV. Memory + content is not copied from `clBuffer` to UMat. Instead, buffer handle assigned to UMat and + `clRetainMemObject` is called. +@param cl_mem_buffer source clBuffer handle +@param step num of bytes in single row +@param rows number of rows +@param cols number of cols +@param type OpenCV type of image +@param dst destination UMat +*/ +CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int type, UMat& dst); + +/** @brief Convert OpenCL image2d_t to UMat +@note + OpenCL `image2d_t` (cl_mem_image), should be compatible with OpenCV UMat formats. Memory content + is copied from image to UMat with `clEnqueueCopyImageToBuffer` function. +@param cl_mem_image source image2d_t handle +@param dst destination UMat +*/ +CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst); + +// TODO Move to internal header +void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); + +class CV_EXPORTS Queue +{ +public: + Queue(); + explicit Queue(const Context& c, const Device& d=Device()); + ~Queue(); + Queue(const Queue& q); + Queue& operator = (const Queue& q); + + bool create(const Context& c=Context(), const Device& d=Device()); + void finish(); + void* ptr() const; + static Queue& getDefault(); + + /// @brief Returns OpenCL command queue with enable profiling mode support + const Queue& getProfilingQueue() const; + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return p; } +protected: + Impl* p; +}; + + +class CV_EXPORTS KernelArg +{ +public: + enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 }; + KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0); + KernelArg(); + + static KernelArg Local(size_t localMemSize) + { return KernelArg(LOCAL, 0, 1, 1, 0, localMemSize); } + static KernelArg PtrWriteOnly(const UMat& m) + { return KernelArg(PTR_ONLY+WRITE_ONLY, (UMat*)&m); } + static KernelArg PtrReadOnly(const UMat& m) + { return KernelArg(PTR_ONLY+READ_ONLY, (UMat*)&m); } + static KernelArg PtrReadWrite(const UMat& m) + { return KernelArg(PTR_ONLY+READ_WRITE, (UMat*)&m); } + static KernelArg ReadWrite(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_WRITE, (UMat*)&m, wscale, iwscale); } + static KernelArg ReadWriteNoSize(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_WRITE+NO_SIZE, (UMat*)&m, wscale, iwscale); } + static KernelArg ReadOnly(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_ONLY, (UMat*)&m, wscale, iwscale); } + static KernelArg WriteOnly(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(WRITE_ONLY, (UMat*)&m, wscale, iwscale); } + static KernelArg ReadOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); } + static KernelArg WriteOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(WRITE_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); } + static KernelArg Constant(const Mat& m); + template<typename _Tp> static KernelArg Constant(const _Tp* arr, size_t n) + { return KernelArg(CONSTANT, 0, 1, 1, (void*)arr, n); } + + int flags; + UMat* m; + const void* obj; + size_t sz; + int wscale, iwscale; +}; + + +class CV_EXPORTS Kernel +{ +public: + Kernel(); + Kernel(const char* kname, const Program& prog); + Kernel(const char* kname, const ProgramSource& prog, + const String& buildopts = String(), String* errmsg=0); + ~Kernel(); + Kernel(const Kernel& k); + Kernel& operator = (const Kernel& k); + + bool empty() const; + bool create(const char* kname, const Program& prog); + bool create(const char* kname, const ProgramSource& prog, + const String& buildopts, String* errmsg=0); + + int set(int i, const void* value, size_t sz); + int set(int i, const Image2D& image2D); + int set(int i, const UMat& m); + int set(int i, const KernelArg& arg); + template<typename _Tp> int set(int i, const _Tp& value) + { return set(i, &value, sizeof(value)); } + + template<typename _Tp0> + Kernel& args(const _Tp0& a0) + { + set(0, a0); return *this; + } + + template<typename _Tp0, typename _Tp1> + Kernel& args(const _Tp0& a0, const _Tp1& a1) + { + int i = set(0, a0); set(i, a1); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2) + { + int i = set(0, a0); i = set(i, a1); set(i, a2); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, + const _Tp3& a3, const _Tp4& a4) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); + i = set(i, a3); set(i, a4); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, + typename _Tp3, typename _Tp4, typename _Tp5> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, + const _Tp3& a3, const _Tp4& a4, const _Tp5& a5) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); + i = set(i, a3); i = set(i, a4); set(i, a5); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); + i = set(i, a4); i = set(i, a5); set(i, a6); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); + i = set(i, a4); i = set(i, a5); i = set(i, a6); set(i, a7); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4, + typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); + i = set(i, a5); i = set(i, a6); i = set(i, a7); set(i, a8); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4, + typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8, typename _Tp9> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); set(i, a9); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, + typename _Tp8, typename _Tp9, typename _Tp10> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9, const _Tp10& a10) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); set(i, a10); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, + typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); set(i, a11); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, + typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, + const _Tp12& a12) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); + set(i, a12); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, + typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12, + typename _Tp13> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, + const _Tp12& a12, const _Tp13& a13) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); + i = set(i, a12); set(i, a13); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, + typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12, + typename _Tp13, typename _Tp14> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, + const _Tp12& a12, const _Tp13& a13, const _Tp14& a14) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); + i = set(i, a12); i = set(i, a13); set(i, a14); return *this; + } + + template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, + typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7, + typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12, + typename _Tp13, typename _Tp14, typename _Tp15> + Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, + const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, + const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, + const _Tp12& a12, const _Tp13& a13, const _Tp14& a14, const _Tp15& a15) + { + int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); + i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); + i = set(i, a12); i = set(i, a13); i = set(i, a14); set(i, a15); return *this; + } + /** @brief Run the OpenCL kernel. + @param dims the work problem dimensions. It is the length of globalsize and localsize. It can be either 1, 2 or 3. + @param globalsize work items for each dimension. It is not the final globalsize passed to + OpenCL. Each dimension will be adjusted to the nearest integer divisible by the corresponding + value in localsize. If localsize is NULL, it will still be adjusted depending on dims. The + adjusted values are greater than or equal to the original values. + @param localsize work-group size for each dimension. + @param sync specify whether to wait for OpenCL computation to finish before return. + @param q command queue + */ + bool run(int dims, size_t globalsize[], + size_t localsize[], bool sync, const Queue& q=Queue()); + bool runTask(bool sync, const Queue& q=Queue()); + + /** @brief Similar to synchronized run() call with returning of kernel execution time + * Separate OpenCL command queue may be used (with CL_QUEUE_PROFILING_ENABLE) + * @return Execution time in nanoseconds or negative number on error + */ + int64 runProfiling(int dims, size_t globalsize[], size_t localsize[], const Queue& q=Queue()); + + size_t workGroupSize() const; + size_t preferedWorkGroupSizeMultiple() const; + bool compileWorkGroupSize(size_t wsz[]) const; + size_t localMemSize() const; + + void* ptr() const; + struct Impl; + +protected: + Impl* p; +}; + +class CV_EXPORTS Program +{ +public: + Program(); + Program(const ProgramSource& src, + const String& buildflags, String& errmsg); + Program(const Program& prog); + + Program& operator = (const Program& prog); + ~Program(); + + bool create(const ProgramSource& src, + const String& buildflags, String& errmsg); + + void* ptr() const; + + /** + * @brief Query device-specific program binary. + * + * Returns RAW OpenCL executable binary without additional attachments. + * + * @sa ProgramSource::fromBinary + * + * @param[out] binary output buffer + */ + void getBinary(std::vector<char>& binary) const; + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +protected: + Impl* p; +public: +#ifndef OPENCV_REMOVE_DEPRECATED_API + // TODO Remove this + CV_DEPRECATED bool read(const String& buf, const String& buildflags); // removed, use ProgramSource instead + CV_DEPRECATED bool write(String& buf) const; // removed, use getBinary() method instead (RAW OpenCL binary) + CV_DEPRECATED const ProgramSource& source() const; // implementation removed + CV_DEPRECATED String getPrefix() const; // deprecated, implementation replaced + CV_DEPRECATED static String getPrefix(const String& buildflags); // deprecated, implementation replaced +#endif +}; + + +class CV_EXPORTS ProgramSource +{ +public: + typedef uint64 hash_t; // deprecated + + ProgramSource(); + explicit ProgramSource(const String& module, const String& name, const String& codeStr, const String& codeHash); + explicit ProgramSource(const String& prog); // deprecated + explicit ProgramSource(const char* prog); // deprecated + ~ProgramSource(); + ProgramSource(const ProgramSource& prog); + ProgramSource& operator = (const ProgramSource& prog); + + const String& source() const; // deprecated + hash_t hash() const; // deprecated + + + /** @brief Describe OpenCL program binary. + * Do not call clCreateProgramWithBinary() and/or clBuildProgram(). + * + * Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies). + * + * This kind of binary is not portable between platforms in general - it is specific to OpenCL vendor / device / driver version. + * + * @param module name of program owner module + * @param name unique name of program (module+name is used as key for OpenCL program caching) + * @param binary buffer address. See buffer lifetime requirement in description. + * @param size buffer size + * @param buildOptions additional program-related build options passed to clBuildProgram() + * @return created ProgramSource object + */ + static ProgramSource fromBinary(const String& module, const String& name, + const unsigned char* binary, const size_t size, + const cv::String& buildOptions = cv::String()); + + /** @brief Describe OpenCL program in SPIR format. + * Do not call clCreateProgramWithBinary() and/or clBuildProgram(). + * + * Supports SPIR 1.2 by default (pass '-spir-std=X.Y' in buildOptions to override this behavior) + * + * Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies). + * + * Programs in this format are portable between OpenCL implementations with 'khr_spir' extension: + * https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_khr_spir.html + * (but they are not portable between different platforms: 32-bit / 64-bit) + * + * Note: these programs can't support vendor specific extensions, like 'cl_intel_subgroups'. + * + * @param module name of program owner module + * @param name unique name of program (module+name is used as key for OpenCL program caching) + * @param binary buffer address. See buffer lifetime requirement in description. + * @param size buffer size + * @param buildOptions additional program-related build options passed to clBuildProgram() + * (these options are added automatically: '-x spir' and '-spir-std=1.2') + * @return created ProgramSource object. + */ + static ProgramSource fromSPIR(const String& module, const String& name, + const unsigned char* binary, const size_t size, + const cv::String& buildOptions = cv::String()); + + //OpenCL 2.1+ only + //static Program fromSPIRV(const String& module, const String& name, + // const unsigned char* binary, const size_t size, + // const cv::String& buildOptions = cv::String()); + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +protected: + Impl* p; +}; + +class CV_EXPORTS PlatformInfo +{ +public: + PlatformInfo(); + explicit PlatformInfo(void* id); + ~PlatformInfo(); + + PlatformInfo(const PlatformInfo& i); + PlatformInfo& operator =(const PlatformInfo& i); + + String name() const; + String vendor() const; + String version() const; + int deviceNumber() const; + void getDevice(Device& device, int d) const; + +protected: + struct Impl; + Impl* p; +}; + +CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf); +CV_EXPORTS const char* typeToStr(int t); +CV_EXPORTS const char* memopTypeToStr(int t); +CV_EXPORTS const char* vecopTypeToStr(int t); +CV_EXPORTS const char* getOpenCLErrorString(int errorCode); +CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL); +CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info); + + +enum OclVectorStrategy +{ + // all matrices have its own vector width + OCL_VECTOR_OWN = 0, + // all matrices have maximal vector width among all matrices + // (useful for cases when matrices have different data types) + OCL_VECTOR_MAX = 1, + + // default strategy + OCL_VECTOR_DEFAULT = OCL_VECTOR_OWN +}; + +CV_EXPORTS int predictOptimalVectorWidth(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), + InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), + InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(), + OclVectorStrategy strat = OCL_VECTOR_DEFAULT); + +CV_EXPORTS int checkOptimalVectorWidth(const int *vectorWidths, + InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), + InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), + InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(), + OclVectorStrategy strat = OCL_VECTOR_DEFAULT); + +// with OCL_VECTOR_MAX strategy +CV_EXPORTS int predictOptimalVectorWidthMax(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), + InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), + InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray()); + +CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const String& name, InputArray _m); + +class CV_EXPORTS Image2D +{ +public: + Image2D(); + + /** + @param src UMat object from which to get image properties and data + @param norm flag to enable the use of normalized channel data types + @param alias flag indicating that the image should alias the src UMat. If true, changes to the + image or src will be reflected in both objects. + */ + explicit Image2D(const UMat &src, bool norm = false, bool alias = false); + Image2D(const Image2D & i); + ~Image2D(); + + Image2D & operator = (const Image2D & i); + + /** Indicates if creating an aliased image should succeed. + Depends on the underlying platform and the dimensions of the UMat. + */ + static bool canCreateAlias(const UMat &u); + + /** Indicates if the image format is supported. + */ + static bool isFormatSupported(int depth, int cn, bool norm); + + void* ptr() const; +protected: + struct Impl; + Impl* p; +}; + +class CV_EXPORTS Timer +{ +public: + Timer(const Queue& q); + ~Timer(); + void start(); + void stop(); + + uint64 durationNS() const; //< duration in nanoseconds + +protected: + struct Impl; + Impl* const p; + +private: + Timer(const Timer&); // disabled + Timer& operator=(const Timer&); // disabled +}; + +CV_EXPORTS MatAllocator* getOpenCLAllocator(); + + +#ifdef __OPENCV_BUILD +namespace internal { + +CV_EXPORTS bool isOpenCLForced(); +#define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition)) + +CV_EXPORTS bool isPerformanceCheckBypassed(); +#define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition)) + +CV_EXPORTS bool isCLBuffer(UMat& u); + +} // namespace internal +#endif + +//! @} + +}} + +#endif diff --git a/include/opencv2/core/ocl_genbase.hpp b/include/opencv2/core/ocl_genbase.hpp new file mode 100644 index 0000000..5334cf1 --- /dev/null +++ b/include/opencv2/core/ocl_genbase.hpp @@ -0,0 +1,69 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_OPENCL_GENBASE_HPP +#define OPENCV_OPENCL_GENBASE_HPP + +//! @cond IGNORED + +namespace cv { +namespace ocl { + +class ProgramSource; + +namespace internal { + +struct CV_EXPORTS ProgramEntry +{ + const char* module; + const char* name; + const char* programCode; + const char* programHash; + ProgramSource* pProgramSource; + + operator ProgramSource& () const; +}; + +} } } // namespace + +//! @endcond + +#endif diff --git a/include/opencv2/core/opencl/ocl_defs.hpp b/include/opencv2/core/opencl/ocl_defs.hpp new file mode 100644 index 0000000..605a65f --- /dev/null +++ b/include/opencv2/core/opencl/ocl_defs.hpp @@ -0,0 +1,75 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. + +#ifndef OPENCV_CORE_OPENCL_DEFS_HPP +#define OPENCV_CORE_OPENCL_DEFS_HPP + +#include "opencv2/core/utility.hpp" +#include "cvconfig.h" + +namespace cv { namespace ocl { +#ifdef HAVE_OPENCL +/// Call is similar to useOpenCL() but doesn't try to load OpenCL runtime or create OpenCL context +CV_EXPORTS bool isOpenCLActivated(); +#else +static inline bool isOpenCLActivated() { return false; } +#endif +}} // namespace + + +//#define CV_OPENCL_RUN_ASSERT + +#ifdef HAVE_OPENCL + +#ifdef CV_OPENCL_RUN_VERBOSE +#define CV_OCL_RUN_(condition, func, ...) \ + { \ + if (cv::ocl::isOpenCLActivated() && (condition) && func) \ + { \ + printf("%s: OpenCL implementation is running\n", CV_Func); \ + fflush(stdout); \ + CV_IMPL_ADD(CV_IMPL_OCL); \ + return __VA_ARGS__; \ + } \ + else \ + { \ + printf("%s: Plain implementation is running\n", CV_Func); \ + fflush(stdout); \ + } \ + } +#elif defined CV_OPENCL_RUN_ASSERT +#define CV_OCL_RUN_(condition, func, ...) \ + { \ + if (cv::ocl::isOpenCLActivated() && (condition)) \ + { \ + if(func) \ + { \ + CV_IMPL_ADD(CV_IMPL_OCL); \ + } \ + else \ + { \ + CV_Error(cv::Error::StsAssert, #func); \ + } \ + return __VA_ARGS__; \ + } \ + } +#else +#define CV_OCL_RUN_(condition, func, ...) \ + if (cv::ocl::isOpenCLActivated() && (condition) && func) \ + { \ + CV_IMPL_ADD(CV_IMPL_OCL); \ + return __VA_ARGS__; \ + } +#endif + +#else +#define CV_OCL_RUN_(condition, func, ...) +#endif + +#define CV_OCL_RUN(condition, func) CV_OCL_RUN_(condition, func) + +#endif // OPENCV_CORE_OPENCL_DEFS_HPP diff --git a/include/opencv2/core/opencl/opencl_info.hpp b/include/opencv2/core/opencl/opencl_info.hpp new file mode 100644 index 0000000..b5d3739 --- /dev/null +++ b/include/opencv2/core/opencl/opencl_info.hpp @@ -0,0 +1,198 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include <iostream> + +#include <opencv2/core.hpp> +#include <opencv2/core/ocl.hpp> + +#ifndef DUMP_CONFIG_PROPERTY +#define DUMP_CONFIG_PROPERTY(...) +#endif + +#ifndef DUMP_MESSAGE_STDOUT +#define DUMP_MESSAGE_STDOUT(...) do { std::cout << __VA_ARGS__ << std::endl; } while (false) +#endif + +namespace cv { + +namespace { +static std::string bytesToStringRepr(size_t value) +{ + size_t b = value % 1024; + value /= 1024; + + size_t kb = value % 1024; + value /= 1024; + + size_t mb = value % 1024; + value /= 1024; + + size_t gb = value; + + std::ostringstream stream; + + if (gb > 0) + stream << gb << " GB "; + if (mb > 0) + stream << mb << " MB "; + if (kb > 0) + stream << kb << " KB "; + if (b > 0) + stream << b << " B"; + + std::string s = stream.str(); + if (s[s.size() - 1] == ' ') + s = s.substr(0, s.size() - 1); + return s; +} +} // namespace + +static void dumpOpenCLInformation() +{ + using namespace cv::ocl; + + try + { + if (!haveOpenCL() || !useOpenCL()) + { + DUMP_MESSAGE_STDOUT("OpenCL is disabled"); + DUMP_CONFIG_PROPERTY("cv_ocl", "disabled"); + return; + } + + std::vector<PlatformInfo> platforms; + cv::ocl::getPlatfomsInfo(platforms); + if (platforms.size() > 0) + { + DUMP_MESSAGE_STDOUT("OpenCL Platforms: "); + for (size_t i = 0; i < platforms.size(); i++) + { + const PlatformInfo* platform = &platforms[i]; + DUMP_MESSAGE_STDOUT(" " << platform->name().c_str()); + Device current_device; + for (int j = 0; j < platform->deviceNumber(); j++) + { + platform->getDevice(current_device, j); + const char* deviceTypeStr = current_device.type() == Device::TYPE_CPU + ? ("CPU") : (current_device.type() == Device::TYPE_GPU ? current_device.hostUnifiedMemory() ? "iGPU" : "dGPU" : "unknown"); + DUMP_MESSAGE_STDOUT( " " << deviceTypeStr << ": " << current_device.name().c_str() << " (" << current_device.version().c_str() << ")"); + DUMP_CONFIG_PROPERTY( cv::format("cv_ocl_platform_%d_device_%d", (int)i, (int)j ), + cv::format("(Platform=%s)(Type=%s)(Name=%s)(Version=%s)", + platform->name().c_str(), deviceTypeStr, current_device.name().c_str(), current_device.version().c_str()) ); + } + } + } + else + { + DUMP_MESSAGE_STDOUT("OpenCL is not available"); + DUMP_CONFIG_PROPERTY("cv_ocl", "not available"); + return; + } + + const Device& device = Device::getDefault(); + if (!device.available()) + CV_Error(Error::OpenCLInitError, "OpenCL device is not available"); + + DUMP_MESSAGE_STDOUT("Current OpenCL device: "); + +#if 0 + DUMP_MESSAGE_STDOUT(" Platform = " << device.getPlatform().name()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_platformName", device.getPlatform().name()); +#endif + + const char* deviceTypeStr = device.type() == Device::TYPE_CPU + ? ("CPU") : (device.type() == Device::TYPE_GPU ? device.hostUnifiedMemory() ? "iGPU" : "dGPU" : "unknown"); + DUMP_MESSAGE_STDOUT(" Type = " << deviceTypeStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceType", deviceTypeStr); + + DUMP_MESSAGE_STDOUT(" Name = " << device.name()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceName", device.name()); + + DUMP_MESSAGE_STDOUT(" Version = " << device.version()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceVersion", device.version()); + + DUMP_MESSAGE_STDOUT(" Driver version = " << device.driverVersion()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_driverVersion", device.driverVersion()); + + DUMP_MESSAGE_STDOUT(" Address bits = " << device.addressBits()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_addressBits", device.addressBits()); + + DUMP_MESSAGE_STDOUT(" Compute units = " << device.maxComputeUnits()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_maxComputeUnits", device.maxComputeUnits()); + + DUMP_MESSAGE_STDOUT(" Max work group size = " << device.maxWorkGroupSize()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_maxWorkGroupSize", device.maxWorkGroupSize()); + + std::string localMemorySizeStr = bytesToStringRepr(device.localMemSize()); + DUMP_MESSAGE_STDOUT(" Local memory size = " << localMemorySizeStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_localMemSize", device.localMemSize()); + + std::string maxMemAllocSizeStr = bytesToStringRepr(device.maxMemAllocSize()); + DUMP_MESSAGE_STDOUT(" Max memory allocation size = " << maxMemAllocSizeStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_maxMemAllocSize", device.maxMemAllocSize()); + + const char* doubleSupportStr = device.doubleFPConfig() > 0 ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Double support = " << doubleSupportStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.doubleFPConfig() > 0); + + const char* isUnifiedMemoryStr = device.hostUnifiedMemory() ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Host unified memory = " << isUnifiedMemoryStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_hostUnifiedMemory", device.hostUnifiedMemory()); + + DUMP_MESSAGE_STDOUT(" Device extensions:"); + String extensionsStr = device.extensions(); + size_t pos = 0; + while (pos < extensionsStr.size()) + { + size_t pos2 = extensionsStr.find(' ', pos); + if (pos2 == String::npos) + pos2 = extensionsStr.size(); + if (pos2 > pos) + { + String extensionName = extensionsStr.substr(pos, pos2 - pos); + DUMP_MESSAGE_STDOUT(" " << extensionName); + } + pos = pos2 + 1; + } + DUMP_CONFIG_PROPERTY("cv_ocl_current_extensions", extensionsStr.c_str()); + + const char* haveAmdBlasStr = haveAmdBlas() ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Has AMD Blas = " << haveAmdBlasStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdBlas", haveAmdBlas()); + + const char* haveAmdFftStr = haveAmdFft() ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Has AMD Fft = " << haveAmdFftStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdFft", haveAmdFft()); + + + DUMP_MESSAGE_STDOUT(" Preferred vector width char = " << device.preferredVectorWidthChar()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthChar", device.preferredVectorWidthChar()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width short = " << device.preferredVectorWidthShort()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthShort", device.preferredVectorWidthShort()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width int = " << device.preferredVectorWidthInt()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthInt", device.preferredVectorWidthInt()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width long = " << device.preferredVectorWidthLong()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthLong", device.preferredVectorWidthLong()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width float = " << device.preferredVectorWidthFloat()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthFloat", device.preferredVectorWidthFloat()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width double = " << device.preferredVectorWidthDouble()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthDouble", device.preferredVectorWidthDouble()); + } + catch (...) + { + DUMP_MESSAGE_STDOUT("Exception. Can't dump OpenCL info"); + DUMP_MESSAGE_STDOUT("OpenCL device not available"); + DUMP_CONFIG_PROPERTY("cv_ocl", "not available"); + } +} +#undef DUMP_MESSAGE_STDOUT +#undef DUMP_CONFIG_PROPERTY + +} // namespace diff --git a/include/opencv2/core/opencl/opencl_svm.hpp b/include/opencv2/core/opencl/opencl_svm.hpp new file mode 100644 index 0000000..7453082 --- /dev/null +++ b/include/opencv2/core/opencl/opencl_svm.hpp @@ -0,0 +1,81 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OPENCL_SVM_HPP +#define OPENCV_CORE_OPENCL_SVM_HPP + +// +// Internal usage only (binary compatibility is not guaranteed) +// +#ifndef __OPENCV_BUILD +#error Internal header file +#endif + +#if defined(HAVE_OPENCL) && defined(HAVE_OPENCL_SVM) +#include "runtime/opencl_core.hpp" +#include "runtime/opencl_svm_20.hpp" +#include "runtime/opencl_svm_hsa_extension.hpp" + +namespace cv { namespace ocl { namespace svm { + +struct SVMCapabilities +{ + enum Value + { + SVM_COARSE_GRAIN_BUFFER = (1 << 0), + SVM_FINE_GRAIN_BUFFER = (1 << 1), + SVM_FINE_GRAIN_SYSTEM = (1 << 2), + SVM_ATOMICS = (1 << 3), + }; + int value_; + + SVMCapabilities(int capabilities = 0) : value_(capabilities) { } + operator int() const { return value_; } + + inline bool isNoSVMSupport() const { return value_ == 0; } + inline bool isSupportCoarseGrainBuffer() const { return (value_ & SVM_COARSE_GRAIN_BUFFER) != 0; } + inline bool isSupportFineGrainBuffer() const { return (value_ & SVM_FINE_GRAIN_BUFFER) != 0; } + inline bool isSupportFineGrainSystem() const { return (value_ & SVM_FINE_GRAIN_SYSTEM) != 0; } + inline bool isSupportAtomics() const { return (value_ & SVM_ATOMICS) != 0; } +}; + +CV_EXPORTS const SVMCapabilities getSVMCapabilitites(const ocl::Context& context); + +struct SVMFunctions +{ + clSVMAllocAMD_fn fn_clSVMAlloc; + clSVMFreeAMD_fn fn_clSVMFree; + clSetKernelArgSVMPointerAMD_fn fn_clSetKernelArgSVMPointer; + //clSetKernelExecInfoAMD_fn fn_clSetKernelExecInfo; + //clEnqueueSVMFreeAMD_fn fn_clEnqueueSVMFree; + clEnqueueSVMMemcpyAMD_fn fn_clEnqueueSVMMemcpy; + clEnqueueSVMMemFillAMD_fn fn_clEnqueueSVMMemFill; + clEnqueueSVMMapAMD_fn fn_clEnqueueSVMMap; + clEnqueueSVMUnmapAMD_fn fn_clEnqueueSVMUnmap; + + inline SVMFunctions() + : fn_clSVMAlloc(NULL), fn_clSVMFree(NULL), + fn_clSetKernelArgSVMPointer(NULL), /*fn_clSetKernelExecInfo(NULL),*/ + /*fn_clEnqueueSVMFree(NULL),*/ fn_clEnqueueSVMMemcpy(NULL), fn_clEnqueueSVMMemFill(NULL), + fn_clEnqueueSVMMap(NULL), fn_clEnqueueSVMUnmap(NULL) + { + // nothing + } + + inline bool isValid() const + { + return fn_clSVMAlloc != NULL && fn_clSVMFree && fn_clSetKernelArgSVMPointer && + /*fn_clSetKernelExecInfo && fn_clEnqueueSVMFree &&*/ fn_clEnqueueSVMMemcpy && + fn_clEnqueueSVMMemFill && fn_clEnqueueSVMMap && fn_clEnqueueSVMUnmap; + } +}; + +// We should guarantee that SVMFunctions lifetime is not less than context's lifetime +CV_EXPORTS const SVMFunctions* getSVMFunctions(const ocl::Context& context); + +CV_EXPORTS bool useSVM(UMatUsageFlags usageFlags); + +}}} //namespace cv::ocl::svm +#endif + +#endif // OPENCV_CORE_OPENCL_SVM_HPP +/* End of file. */ diff --git a/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp b/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp new file mode 100644 index 0000000..65c8493 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp @@ -0,0 +1,714 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP +#error "Invalid usage" +#endif + +// generated by parser_clamdblas.py +#define clAmdBlasAddScratchImage clAmdBlasAddScratchImage_ +#define clAmdBlasCaxpy clAmdBlasCaxpy_ +#define clAmdBlasCcopy clAmdBlasCcopy_ +#define clAmdBlasCdotc clAmdBlasCdotc_ +#define clAmdBlasCdotu clAmdBlasCdotu_ +#define clAmdBlasCgbmv clAmdBlasCgbmv_ +#define clAmdBlasCgemm clAmdBlasCgemm_ +#define clAmdBlasCgemmEx clAmdBlasCgemmEx_ +#define clAmdBlasCgemv clAmdBlasCgemv_ +#define clAmdBlasCgemvEx clAmdBlasCgemvEx_ +#define clAmdBlasCgerc clAmdBlasCgerc_ +#define clAmdBlasCgeru clAmdBlasCgeru_ +#define clAmdBlasChbmv clAmdBlasChbmv_ +#define clAmdBlasChemm clAmdBlasChemm_ +#define clAmdBlasChemv clAmdBlasChemv_ +#define clAmdBlasCher clAmdBlasCher_ +#define clAmdBlasCher2 clAmdBlasCher2_ +#define clAmdBlasCher2k clAmdBlasCher2k_ +#define clAmdBlasCherk clAmdBlasCherk_ +#define clAmdBlasChpmv clAmdBlasChpmv_ +#define clAmdBlasChpr clAmdBlasChpr_ +#define clAmdBlasChpr2 clAmdBlasChpr2_ +#define clAmdBlasCrotg clAmdBlasCrotg_ +#define clAmdBlasCscal clAmdBlasCscal_ +#define clAmdBlasCsrot clAmdBlasCsrot_ +#define clAmdBlasCsscal clAmdBlasCsscal_ +#define clAmdBlasCswap clAmdBlasCswap_ +#define clAmdBlasCsymm clAmdBlasCsymm_ +#define clAmdBlasCsyr2k clAmdBlasCsyr2k_ +#define clAmdBlasCsyr2kEx clAmdBlasCsyr2kEx_ +#define clAmdBlasCsyrk clAmdBlasCsyrk_ +#define clAmdBlasCsyrkEx clAmdBlasCsyrkEx_ +#define clAmdBlasCtbmv clAmdBlasCtbmv_ +#define clAmdBlasCtbsv clAmdBlasCtbsv_ +#define clAmdBlasCtpmv clAmdBlasCtpmv_ +#define clAmdBlasCtpsv clAmdBlasCtpsv_ +#define clAmdBlasCtrmm clAmdBlasCtrmm_ +#define clAmdBlasCtrmmEx clAmdBlasCtrmmEx_ +#define clAmdBlasCtrmv clAmdBlasCtrmv_ +#define clAmdBlasCtrsm clAmdBlasCtrsm_ +#define clAmdBlasCtrsmEx clAmdBlasCtrsmEx_ +#define clAmdBlasCtrsv clAmdBlasCtrsv_ +#define clAmdBlasDasum clAmdBlasDasum_ +#define clAmdBlasDaxpy clAmdBlasDaxpy_ +#define clAmdBlasDcopy clAmdBlasDcopy_ +#define clAmdBlasDdot clAmdBlasDdot_ +#define clAmdBlasDgbmv clAmdBlasDgbmv_ +#define clAmdBlasDgemm clAmdBlasDgemm_ +#define clAmdBlasDgemmEx clAmdBlasDgemmEx_ +#define clAmdBlasDgemv clAmdBlasDgemv_ +#define clAmdBlasDgemvEx clAmdBlasDgemvEx_ +#define clAmdBlasDger clAmdBlasDger_ +#define clAmdBlasDnrm2 clAmdBlasDnrm2_ +#define clAmdBlasDrot clAmdBlasDrot_ +#define clAmdBlasDrotg clAmdBlasDrotg_ +#define clAmdBlasDrotm clAmdBlasDrotm_ +#define clAmdBlasDrotmg clAmdBlasDrotmg_ +#define clAmdBlasDsbmv clAmdBlasDsbmv_ +#define clAmdBlasDscal clAmdBlasDscal_ +#define clAmdBlasDspmv clAmdBlasDspmv_ +#define clAmdBlasDspr clAmdBlasDspr_ +#define clAmdBlasDspr2 clAmdBlasDspr2_ +#define clAmdBlasDswap clAmdBlasDswap_ +#define clAmdBlasDsymm clAmdBlasDsymm_ +#define clAmdBlasDsymv clAmdBlasDsymv_ +#define clAmdBlasDsymvEx clAmdBlasDsymvEx_ +#define clAmdBlasDsyr clAmdBlasDsyr_ +#define clAmdBlasDsyr2 clAmdBlasDsyr2_ +#define clAmdBlasDsyr2k clAmdBlasDsyr2k_ +#define clAmdBlasDsyr2kEx clAmdBlasDsyr2kEx_ +#define clAmdBlasDsyrk clAmdBlasDsyrk_ +#define clAmdBlasDsyrkEx clAmdBlasDsyrkEx_ +#define clAmdBlasDtbmv clAmdBlasDtbmv_ +#define clAmdBlasDtbsv clAmdBlasDtbsv_ +#define clAmdBlasDtpmv clAmdBlasDtpmv_ +#define clAmdBlasDtpsv clAmdBlasDtpsv_ +#define clAmdBlasDtrmm clAmdBlasDtrmm_ +#define clAmdBlasDtrmmEx clAmdBlasDtrmmEx_ +#define clAmdBlasDtrmv clAmdBlasDtrmv_ +#define clAmdBlasDtrsm clAmdBlasDtrsm_ +#define clAmdBlasDtrsmEx clAmdBlasDtrsmEx_ +#define clAmdBlasDtrsv clAmdBlasDtrsv_ +#define clAmdBlasDzasum clAmdBlasDzasum_ +#define clAmdBlasDznrm2 clAmdBlasDznrm2_ +#define clAmdBlasGetVersion clAmdBlasGetVersion_ +#define clAmdBlasRemoveScratchImage clAmdBlasRemoveScratchImage_ +#define clAmdBlasSasum clAmdBlasSasum_ +#define clAmdBlasSaxpy clAmdBlasSaxpy_ +#define clAmdBlasScasum clAmdBlasScasum_ +#define clAmdBlasScnrm2 clAmdBlasScnrm2_ +#define clAmdBlasScopy clAmdBlasScopy_ +#define clAmdBlasSdot clAmdBlasSdot_ +#define clAmdBlasSetup clAmdBlasSetup_ +#define clAmdBlasSgbmv clAmdBlasSgbmv_ +#define clAmdBlasSgemm clAmdBlasSgemm_ +#define clAmdBlasSgemmEx clAmdBlasSgemmEx_ +#define clAmdBlasSgemv clAmdBlasSgemv_ +#define clAmdBlasSgemvEx clAmdBlasSgemvEx_ +#define clAmdBlasSger clAmdBlasSger_ +#define clAmdBlasSnrm2 clAmdBlasSnrm2_ +#define clAmdBlasSrot clAmdBlasSrot_ +#define clAmdBlasSrotg clAmdBlasSrotg_ +#define clAmdBlasSrotm clAmdBlasSrotm_ +#define clAmdBlasSrotmg clAmdBlasSrotmg_ +#define clAmdBlasSsbmv clAmdBlasSsbmv_ +#define clAmdBlasSscal clAmdBlasSscal_ +#define clAmdBlasSspmv clAmdBlasSspmv_ +#define clAmdBlasSspr clAmdBlasSspr_ +#define clAmdBlasSspr2 clAmdBlasSspr2_ +#define clAmdBlasSswap clAmdBlasSswap_ +#define clAmdBlasSsymm clAmdBlasSsymm_ +#define clAmdBlasSsymv clAmdBlasSsymv_ +#define clAmdBlasSsymvEx clAmdBlasSsymvEx_ +#define clAmdBlasSsyr clAmdBlasSsyr_ +#define clAmdBlasSsyr2 clAmdBlasSsyr2_ +#define clAmdBlasSsyr2k clAmdBlasSsyr2k_ +#define clAmdBlasSsyr2kEx clAmdBlasSsyr2kEx_ +#define clAmdBlasSsyrk clAmdBlasSsyrk_ +#define clAmdBlasSsyrkEx clAmdBlasSsyrkEx_ +#define clAmdBlasStbmv clAmdBlasStbmv_ +#define clAmdBlasStbsv clAmdBlasStbsv_ +#define clAmdBlasStpmv clAmdBlasStpmv_ +#define clAmdBlasStpsv clAmdBlasStpsv_ +#define clAmdBlasStrmm clAmdBlasStrmm_ +#define clAmdBlasStrmmEx clAmdBlasStrmmEx_ +#define clAmdBlasStrmv clAmdBlasStrmv_ +#define clAmdBlasStrsm clAmdBlasStrsm_ +#define clAmdBlasStrsmEx clAmdBlasStrsmEx_ +#define clAmdBlasStrsv clAmdBlasStrsv_ +#define clAmdBlasTeardown clAmdBlasTeardown_ +#define clAmdBlasZaxpy clAmdBlasZaxpy_ +#define clAmdBlasZcopy clAmdBlasZcopy_ +#define clAmdBlasZdotc clAmdBlasZdotc_ +#define clAmdBlasZdotu clAmdBlasZdotu_ +#define clAmdBlasZdrot clAmdBlasZdrot_ +#define clAmdBlasZdscal clAmdBlasZdscal_ +#define clAmdBlasZgbmv clAmdBlasZgbmv_ +#define clAmdBlasZgemm clAmdBlasZgemm_ +#define clAmdBlasZgemmEx clAmdBlasZgemmEx_ +#define clAmdBlasZgemv clAmdBlasZgemv_ +#define clAmdBlasZgemvEx clAmdBlasZgemvEx_ +#define clAmdBlasZgerc clAmdBlasZgerc_ +#define clAmdBlasZgeru clAmdBlasZgeru_ +#define clAmdBlasZhbmv clAmdBlasZhbmv_ +#define clAmdBlasZhemm clAmdBlasZhemm_ +#define clAmdBlasZhemv clAmdBlasZhemv_ +#define clAmdBlasZher clAmdBlasZher_ +#define clAmdBlasZher2 clAmdBlasZher2_ +#define clAmdBlasZher2k clAmdBlasZher2k_ +#define clAmdBlasZherk clAmdBlasZherk_ +#define clAmdBlasZhpmv clAmdBlasZhpmv_ +#define clAmdBlasZhpr clAmdBlasZhpr_ +#define clAmdBlasZhpr2 clAmdBlasZhpr2_ +#define clAmdBlasZrotg clAmdBlasZrotg_ +#define clAmdBlasZscal clAmdBlasZscal_ +#define clAmdBlasZswap clAmdBlasZswap_ +#define clAmdBlasZsymm clAmdBlasZsymm_ +#define clAmdBlasZsyr2k clAmdBlasZsyr2k_ +#define clAmdBlasZsyr2kEx clAmdBlasZsyr2kEx_ +#define clAmdBlasZsyrk clAmdBlasZsyrk_ +#define clAmdBlasZsyrkEx clAmdBlasZsyrkEx_ +#define clAmdBlasZtbmv clAmdBlasZtbmv_ +#define clAmdBlasZtbsv clAmdBlasZtbsv_ +#define clAmdBlasZtpmv clAmdBlasZtpmv_ +#define clAmdBlasZtpsv clAmdBlasZtpsv_ +#define clAmdBlasZtrmm clAmdBlasZtrmm_ +#define clAmdBlasZtrmmEx clAmdBlasZtrmmEx_ +#define clAmdBlasZtrmv clAmdBlasZtrmv_ +#define clAmdBlasZtrsm clAmdBlasZtrsm_ +#define clAmdBlasZtrsmEx clAmdBlasZtrsmEx_ +#define clAmdBlasZtrsv clAmdBlasZtrsv_ +#define clAmdBlasiCamax clAmdBlasiCamax_ +#define clAmdBlasiDamax clAmdBlasiDamax_ +#define clAmdBlasiSamax clAmdBlasiSamax_ +#define clAmdBlasiZamax clAmdBlasiZamax_ + +#include <clAmdBlas.h> + +// generated by parser_clamdblas.py +#undef clAmdBlasAddScratchImage +//#define clAmdBlasAddScratchImage clAmdBlasAddScratchImage_pfn +#undef clAmdBlasCaxpy +//#define clAmdBlasCaxpy clAmdBlasCaxpy_pfn +#undef clAmdBlasCcopy +//#define clAmdBlasCcopy clAmdBlasCcopy_pfn +#undef clAmdBlasCdotc +//#define clAmdBlasCdotc clAmdBlasCdotc_pfn +#undef clAmdBlasCdotu +//#define clAmdBlasCdotu clAmdBlasCdotu_pfn +#undef clAmdBlasCgbmv +//#define clAmdBlasCgbmv clAmdBlasCgbmv_pfn +#undef clAmdBlasCgemm +//#define clAmdBlasCgemm clAmdBlasCgemm_pfn +#undef clAmdBlasCgemmEx +#define clAmdBlasCgemmEx clAmdBlasCgemmEx_pfn +#undef clAmdBlasCgemv +//#define clAmdBlasCgemv clAmdBlasCgemv_pfn +#undef clAmdBlasCgemvEx +//#define clAmdBlasCgemvEx clAmdBlasCgemvEx_pfn +#undef clAmdBlasCgerc +//#define clAmdBlasCgerc clAmdBlasCgerc_pfn +#undef clAmdBlasCgeru +//#define clAmdBlasCgeru clAmdBlasCgeru_pfn +#undef clAmdBlasChbmv +//#define clAmdBlasChbmv clAmdBlasChbmv_pfn +#undef clAmdBlasChemm +//#define clAmdBlasChemm clAmdBlasChemm_pfn +#undef clAmdBlasChemv +//#define clAmdBlasChemv clAmdBlasChemv_pfn +#undef clAmdBlasCher +//#define clAmdBlasCher clAmdBlasCher_pfn +#undef clAmdBlasCher2 +//#define clAmdBlasCher2 clAmdBlasCher2_pfn +#undef clAmdBlasCher2k +//#define clAmdBlasCher2k clAmdBlasCher2k_pfn +#undef clAmdBlasCherk +//#define clAmdBlasCherk clAmdBlasCherk_pfn +#undef clAmdBlasChpmv +//#define clAmdBlasChpmv clAmdBlasChpmv_pfn +#undef clAmdBlasChpr +//#define clAmdBlasChpr clAmdBlasChpr_pfn +#undef clAmdBlasChpr2 +//#define clAmdBlasChpr2 clAmdBlasChpr2_pfn +#undef clAmdBlasCrotg +//#define clAmdBlasCrotg clAmdBlasCrotg_pfn +#undef clAmdBlasCscal +//#define clAmdBlasCscal clAmdBlasCscal_pfn +#undef clAmdBlasCsrot +//#define clAmdBlasCsrot clAmdBlasCsrot_pfn +#undef clAmdBlasCsscal +//#define clAmdBlasCsscal clAmdBlasCsscal_pfn +#undef clAmdBlasCswap +//#define clAmdBlasCswap clAmdBlasCswap_pfn +#undef clAmdBlasCsymm +//#define clAmdBlasCsymm clAmdBlasCsymm_pfn +#undef clAmdBlasCsyr2k +//#define clAmdBlasCsyr2k clAmdBlasCsyr2k_pfn +#undef clAmdBlasCsyr2kEx +//#define clAmdBlasCsyr2kEx clAmdBlasCsyr2kEx_pfn +#undef clAmdBlasCsyrk +//#define clAmdBlasCsyrk clAmdBlasCsyrk_pfn +#undef clAmdBlasCsyrkEx +//#define clAmdBlasCsyrkEx clAmdBlasCsyrkEx_pfn +#undef clAmdBlasCtbmv +//#define clAmdBlasCtbmv clAmdBlasCtbmv_pfn +#undef clAmdBlasCtbsv +//#define clAmdBlasCtbsv clAmdBlasCtbsv_pfn +#undef clAmdBlasCtpmv +//#define clAmdBlasCtpmv clAmdBlasCtpmv_pfn +#undef clAmdBlasCtpsv +//#define clAmdBlasCtpsv clAmdBlasCtpsv_pfn +#undef clAmdBlasCtrmm +//#define clAmdBlasCtrmm clAmdBlasCtrmm_pfn +#undef clAmdBlasCtrmmEx +//#define clAmdBlasCtrmmEx clAmdBlasCtrmmEx_pfn +#undef clAmdBlasCtrmv +//#define clAmdBlasCtrmv clAmdBlasCtrmv_pfn +#undef clAmdBlasCtrsm +//#define clAmdBlasCtrsm clAmdBlasCtrsm_pfn +#undef clAmdBlasCtrsmEx +//#define clAmdBlasCtrsmEx clAmdBlasCtrsmEx_pfn +#undef clAmdBlasCtrsv +//#define clAmdBlasCtrsv clAmdBlasCtrsv_pfn +#undef clAmdBlasDasum +//#define clAmdBlasDasum clAmdBlasDasum_pfn +#undef clAmdBlasDaxpy +//#define clAmdBlasDaxpy clAmdBlasDaxpy_pfn +#undef clAmdBlasDcopy +//#define clAmdBlasDcopy clAmdBlasDcopy_pfn +#undef clAmdBlasDdot +//#define clAmdBlasDdot clAmdBlasDdot_pfn +#undef clAmdBlasDgbmv +//#define clAmdBlasDgbmv clAmdBlasDgbmv_pfn +#undef clAmdBlasDgemm +//#define clAmdBlasDgemm clAmdBlasDgemm_pfn +#undef clAmdBlasDgemmEx +#define clAmdBlasDgemmEx clAmdBlasDgemmEx_pfn +#undef clAmdBlasDgemv +//#define clAmdBlasDgemv clAmdBlasDgemv_pfn +#undef clAmdBlasDgemvEx +//#define clAmdBlasDgemvEx clAmdBlasDgemvEx_pfn +#undef clAmdBlasDger +//#define clAmdBlasDger clAmdBlasDger_pfn +#undef clAmdBlasDnrm2 +//#define clAmdBlasDnrm2 clAmdBlasDnrm2_pfn +#undef clAmdBlasDrot +//#define clAmdBlasDrot clAmdBlasDrot_pfn +#undef clAmdBlasDrotg +//#define clAmdBlasDrotg clAmdBlasDrotg_pfn +#undef clAmdBlasDrotm +//#define clAmdBlasDrotm clAmdBlasDrotm_pfn +#undef clAmdBlasDrotmg +//#define clAmdBlasDrotmg clAmdBlasDrotmg_pfn +#undef clAmdBlasDsbmv +//#define clAmdBlasDsbmv clAmdBlasDsbmv_pfn +#undef clAmdBlasDscal +//#define clAmdBlasDscal clAmdBlasDscal_pfn +#undef clAmdBlasDspmv +//#define clAmdBlasDspmv clAmdBlasDspmv_pfn +#undef clAmdBlasDspr +//#define clAmdBlasDspr clAmdBlasDspr_pfn +#undef clAmdBlasDspr2 +//#define clAmdBlasDspr2 clAmdBlasDspr2_pfn +#undef clAmdBlasDswap +//#define clAmdBlasDswap clAmdBlasDswap_pfn +#undef clAmdBlasDsymm +//#define clAmdBlasDsymm clAmdBlasDsymm_pfn +#undef clAmdBlasDsymv +//#define clAmdBlasDsymv clAmdBlasDsymv_pfn +#undef clAmdBlasDsymvEx +//#define clAmdBlasDsymvEx clAmdBlasDsymvEx_pfn +#undef clAmdBlasDsyr +//#define clAmdBlasDsyr clAmdBlasDsyr_pfn +#undef clAmdBlasDsyr2 +//#define clAmdBlasDsyr2 clAmdBlasDsyr2_pfn +#undef clAmdBlasDsyr2k +//#define clAmdBlasDsyr2k clAmdBlasDsyr2k_pfn +#undef clAmdBlasDsyr2kEx +//#define clAmdBlasDsyr2kEx clAmdBlasDsyr2kEx_pfn +#undef clAmdBlasDsyrk +//#define clAmdBlasDsyrk clAmdBlasDsyrk_pfn +#undef clAmdBlasDsyrkEx +//#define clAmdBlasDsyrkEx clAmdBlasDsyrkEx_pfn +#undef clAmdBlasDtbmv +//#define clAmdBlasDtbmv clAmdBlasDtbmv_pfn +#undef clAmdBlasDtbsv +//#define clAmdBlasDtbsv clAmdBlasDtbsv_pfn +#undef clAmdBlasDtpmv +//#define clAmdBlasDtpmv clAmdBlasDtpmv_pfn +#undef clAmdBlasDtpsv +//#define clAmdBlasDtpsv clAmdBlasDtpsv_pfn +#undef clAmdBlasDtrmm +//#define clAmdBlasDtrmm clAmdBlasDtrmm_pfn +#undef clAmdBlasDtrmmEx +//#define clAmdBlasDtrmmEx clAmdBlasDtrmmEx_pfn +#undef clAmdBlasDtrmv +//#define clAmdBlasDtrmv clAmdBlasDtrmv_pfn +#undef clAmdBlasDtrsm +//#define clAmdBlasDtrsm clAmdBlasDtrsm_pfn +#undef clAmdBlasDtrsmEx +//#define clAmdBlasDtrsmEx clAmdBlasDtrsmEx_pfn +#undef clAmdBlasDtrsv +//#define clAmdBlasDtrsv clAmdBlasDtrsv_pfn +#undef clAmdBlasDzasum +//#define clAmdBlasDzasum clAmdBlasDzasum_pfn +#undef clAmdBlasDznrm2 +//#define clAmdBlasDznrm2 clAmdBlasDznrm2_pfn +#undef clAmdBlasGetVersion +//#define clAmdBlasGetVersion clAmdBlasGetVersion_pfn +#undef clAmdBlasRemoveScratchImage +//#define clAmdBlasRemoveScratchImage clAmdBlasRemoveScratchImage_pfn +#undef clAmdBlasSasum +//#define clAmdBlasSasum clAmdBlasSasum_pfn +#undef clAmdBlasSaxpy +//#define clAmdBlasSaxpy clAmdBlasSaxpy_pfn +#undef clAmdBlasScasum +//#define clAmdBlasScasum clAmdBlasScasum_pfn +#undef clAmdBlasScnrm2 +//#define clAmdBlasScnrm2 clAmdBlasScnrm2_pfn +#undef clAmdBlasScopy +//#define clAmdBlasScopy clAmdBlasScopy_pfn +#undef clAmdBlasSdot +//#define clAmdBlasSdot clAmdBlasSdot_pfn +#undef clAmdBlasSetup +#define clAmdBlasSetup clAmdBlasSetup_pfn +#undef clAmdBlasSgbmv +//#define clAmdBlasSgbmv clAmdBlasSgbmv_pfn +#undef clAmdBlasSgemm +//#define clAmdBlasSgemm clAmdBlasSgemm_pfn +#undef clAmdBlasSgemmEx +#define clAmdBlasSgemmEx clAmdBlasSgemmEx_pfn +#undef clAmdBlasSgemv +//#define clAmdBlasSgemv clAmdBlasSgemv_pfn +#undef clAmdBlasSgemvEx +//#define clAmdBlasSgemvEx clAmdBlasSgemvEx_pfn +#undef clAmdBlasSger +//#define clAmdBlasSger clAmdBlasSger_pfn +#undef clAmdBlasSnrm2 +//#define clAmdBlasSnrm2 clAmdBlasSnrm2_pfn +#undef clAmdBlasSrot +//#define clAmdBlasSrot clAmdBlasSrot_pfn +#undef clAmdBlasSrotg +//#define clAmdBlasSrotg clAmdBlasSrotg_pfn +#undef clAmdBlasSrotm +//#define clAmdBlasSrotm clAmdBlasSrotm_pfn +#undef clAmdBlasSrotmg +//#define clAmdBlasSrotmg clAmdBlasSrotmg_pfn +#undef clAmdBlasSsbmv +//#define clAmdBlasSsbmv clAmdBlasSsbmv_pfn +#undef clAmdBlasSscal +//#define clAmdBlasSscal clAmdBlasSscal_pfn +#undef clAmdBlasSspmv +//#define clAmdBlasSspmv clAmdBlasSspmv_pfn +#undef clAmdBlasSspr +//#define clAmdBlasSspr clAmdBlasSspr_pfn +#undef clAmdBlasSspr2 +//#define clAmdBlasSspr2 clAmdBlasSspr2_pfn +#undef clAmdBlasSswap +//#define clAmdBlasSswap clAmdBlasSswap_pfn +#undef clAmdBlasSsymm +//#define clAmdBlasSsymm clAmdBlasSsymm_pfn +#undef clAmdBlasSsymv +//#define clAmdBlasSsymv clAmdBlasSsymv_pfn +#undef clAmdBlasSsymvEx +//#define clAmdBlasSsymvEx clAmdBlasSsymvEx_pfn +#undef clAmdBlasSsyr +//#define clAmdBlasSsyr clAmdBlasSsyr_pfn +#undef clAmdBlasSsyr2 +//#define clAmdBlasSsyr2 clAmdBlasSsyr2_pfn +#undef clAmdBlasSsyr2k +//#define clAmdBlasSsyr2k clAmdBlasSsyr2k_pfn +#undef clAmdBlasSsyr2kEx +//#define clAmdBlasSsyr2kEx clAmdBlasSsyr2kEx_pfn +#undef clAmdBlasSsyrk +//#define clAmdBlasSsyrk clAmdBlasSsyrk_pfn +#undef clAmdBlasSsyrkEx +//#define clAmdBlasSsyrkEx clAmdBlasSsyrkEx_pfn +#undef clAmdBlasStbmv +//#define clAmdBlasStbmv clAmdBlasStbmv_pfn +#undef clAmdBlasStbsv +//#define clAmdBlasStbsv clAmdBlasStbsv_pfn +#undef clAmdBlasStpmv +//#define clAmdBlasStpmv clAmdBlasStpmv_pfn +#undef clAmdBlasStpsv +//#define clAmdBlasStpsv clAmdBlasStpsv_pfn +#undef clAmdBlasStrmm +//#define clAmdBlasStrmm clAmdBlasStrmm_pfn +#undef clAmdBlasStrmmEx +//#define clAmdBlasStrmmEx clAmdBlasStrmmEx_pfn +#undef clAmdBlasStrmv +//#define clAmdBlasStrmv clAmdBlasStrmv_pfn +#undef clAmdBlasStrsm +//#define clAmdBlasStrsm clAmdBlasStrsm_pfn +#undef clAmdBlasStrsmEx +//#define clAmdBlasStrsmEx clAmdBlasStrsmEx_pfn +#undef clAmdBlasStrsv +//#define clAmdBlasStrsv clAmdBlasStrsv_pfn +#undef clAmdBlasTeardown +#define clAmdBlasTeardown clAmdBlasTeardown_pfn +#undef clAmdBlasZaxpy +//#define clAmdBlasZaxpy clAmdBlasZaxpy_pfn +#undef clAmdBlasZcopy +//#define clAmdBlasZcopy clAmdBlasZcopy_pfn +#undef clAmdBlasZdotc +//#define clAmdBlasZdotc clAmdBlasZdotc_pfn +#undef clAmdBlasZdotu +//#define clAmdBlasZdotu clAmdBlasZdotu_pfn +#undef clAmdBlasZdrot +//#define clAmdBlasZdrot clAmdBlasZdrot_pfn +#undef clAmdBlasZdscal +//#define clAmdBlasZdscal clAmdBlasZdscal_pfn +#undef clAmdBlasZgbmv +//#define clAmdBlasZgbmv clAmdBlasZgbmv_pfn +#undef clAmdBlasZgemm +//#define clAmdBlasZgemm clAmdBlasZgemm_pfn +#undef clAmdBlasZgemmEx +#define clAmdBlasZgemmEx clAmdBlasZgemmEx_pfn +#undef clAmdBlasZgemv +//#define clAmdBlasZgemv clAmdBlasZgemv_pfn +#undef clAmdBlasZgemvEx +//#define clAmdBlasZgemvEx clAmdBlasZgemvEx_pfn +#undef clAmdBlasZgerc +//#define clAmdBlasZgerc clAmdBlasZgerc_pfn +#undef clAmdBlasZgeru +//#define clAmdBlasZgeru clAmdBlasZgeru_pfn +#undef clAmdBlasZhbmv +//#define clAmdBlasZhbmv clAmdBlasZhbmv_pfn +#undef clAmdBlasZhemm +//#define clAmdBlasZhemm clAmdBlasZhemm_pfn +#undef clAmdBlasZhemv +//#define clAmdBlasZhemv clAmdBlasZhemv_pfn +#undef clAmdBlasZher +//#define clAmdBlasZher clAmdBlasZher_pfn +#undef clAmdBlasZher2 +//#define clAmdBlasZher2 clAmdBlasZher2_pfn +#undef clAmdBlasZher2k +//#define clAmdBlasZher2k clAmdBlasZher2k_pfn +#undef clAmdBlasZherk +//#define clAmdBlasZherk clAmdBlasZherk_pfn +#undef clAmdBlasZhpmv +//#define clAmdBlasZhpmv clAmdBlasZhpmv_pfn +#undef clAmdBlasZhpr +//#define clAmdBlasZhpr clAmdBlasZhpr_pfn +#undef clAmdBlasZhpr2 +//#define clAmdBlasZhpr2 clAmdBlasZhpr2_pfn +#undef clAmdBlasZrotg +//#define clAmdBlasZrotg clAmdBlasZrotg_pfn +#undef clAmdBlasZscal +//#define clAmdBlasZscal clAmdBlasZscal_pfn +#undef clAmdBlasZswap +//#define clAmdBlasZswap clAmdBlasZswap_pfn +#undef clAmdBlasZsymm +//#define clAmdBlasZsymm clAmdBlasZsymm_pfn +#undef clAmdBlasZsyr2k +//#define clAmdBlasZsyr2k clAmdBlasZsyr2k_pfn +#undef clAmdBlasZsyr2kEx +//#define clAmdBlasZsyr2kEx clAmdBlasZsyr2kEx_pfn +#undef clAmdBlasZsyrk +//#define clAmdBlasZsyrk clAmdBlasZsyrk_pfn +#undef clAmdBlasZsyrkEx +//#define clAmdBlasZsyrkEx clAmdBlasZsyrkEx_pfn +#undef clAmdBlasZtbmv +//#define clAmdBlasZtbmv clAmdBlasZtbmv_pfn +#undef clAmdBlasZtbsv +//#define clAmdBlasZtbsv clAmdBlasZtbsv_pfn +#undef clAmdBlasZtpmv +//#define clAmdBlasZtpmv clAmdBlasZtpmv_pfn +#undef clAmdBlasZtpsv +//#define clAmdBlasZtpsv clAmdBlasZtpsv_pfn +#undef clAmdBlasZtrmm +//#define clAmdBlasZtrmm clAmdBlasZtrmm_pfn +#undef clAmdBlasZtrmmEx +//#define clAmdBlasZtrmmEx clAmdBlasZtrmmEx_pfn +#undef clAmdBlasZtrmv +//#define clAmdBlasZtrmv clAmdBlasZtrmv_pfn +#undef clAmdBlasZtrsm +//#define clAmdBlasZtrsm clAmdBlasZtrsm_pfn +#undef clAmdBlasZtrsmEx +//#define clAmdBlasZtrsmEx clAmdBlasZtrsmEx_pfn +#undef clAmdBlasZtrsv +//#define clAmdBlasZtrsv clAmdBlasZtrsv_pfn +#undef clAmdBlasiCamax +//#define clAmdBlasiCamax clAmdBlasiCamax_pfn +#undef clAmdBlasiDamax +//#define clAmdBlasiDamax clAmdBlasiDamax_pfn +#undef clAmdBlasiSamax +//#define clAmdBlasiSamax clAmdBlasiSamax_pfn +#undef clAmdBlasiZamax +//#define clAmdBlasiZamax clAmdBlasiZamax_pfn + +// generated by parser_clamdblas.py +//extern CL_RUNTIME_EXPORT cl_ulong (*clAmdBlasAddScratchImage)(cl_context context, size_t width, size_t height, clAmdBlasStatus* status); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCaxpy)(size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgerc)(clAmdBlasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgeru)(clAmdBlasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChemm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChemv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, FloatComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCherk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, float alpha, const cl_mem A, size_t offa, size_t lda, float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCscal)(size_t N, cl_float2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDaxpy)(size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDger)(clAmdBlasOrder order, size_t M, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotg)(cl_mem DA, size_t offDA, cl_mem DB, size_t offDB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotmg)(cl_mem DD1, size_t offDD1, cl_mem DD2, size_t offDD2, cl_mem DX1, size_t offDX1, const cl_mem DY1, size_t offDY1, cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymvEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDzasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDznrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasRemoveScratchImage)(cl_ulong imageID); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSaxpy)(size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSetup)(); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSger)(clAmdBlasOrder order, size_t M, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotg)(cl_mem SA, size_t offSA, cl_mem SB, size_t offSB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotmg)(cl_mem SD1, size_t offSD1, cl_mem SD2, size_t offSD2, cl_mem SX1, size_t offSX1, const cl_mem SY1, size_t offSY1, cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymvEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT void (*clAmdBlasTeardown)(); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZaxpy)(size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgerc)(clAmdBlasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgeru)(clAmdBlasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhemm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhemv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, DoubleComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZherk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, double alpha, const cl_mem A, size_t offa, size_t lda, double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZscal)(size_t N, cl_double2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiCamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiDamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiSamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiZamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); diff --git a/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp b/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp new file mode 100644 index 0000000..1457d7e --- /dev/null +++ b/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp @@ -0,0 +1,142 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP +#error "Invalid usage" +#endif + +// generated by parser_clamdfft.py +#define clAmdFftBakePlan clAmdFftBakePlan_ +#define clAmdFftCopyPlan clAmdFftCopyPlan_ +#define clAmdFftCreateDefaultPlan clAmdFftCreateDefaultPlan_ +#define clAmdFftDestroyPlan clAmdFftDestroyPlan_ +#define clAmdFftEnqueueTransform clAmdFftEnqueueTransform_ +#define clAmdFftGetLayout clAmdFftGetLayout_ +#define clAmdFftGetPlanBatchSize clAmdFftGetPlanBatchSize_ +#define clAmdFftGetPlanContext clAmdFftGetPlanContext_ +#define clAmdFftGetPlanDim clAmdFftGetPlanDim_ +#define clAmdFftGetPlanDistance clAmdFftGetPlanDistance_ +#define clAmdFftGetPlanInStride clAmdFftGetPlanInStride_ +#define clAmdFftGetPlanLength clAmdFftGetPlanLength_ +#define clAmdFftGetPlanOutStride clAmdFftGetPlanOutStride_ +#define clAmdFftGetPlanPrecision clAmdFftGetPlanPrecision_ +#define clAmdFftGetPlanScale clAmdFftGetPlanScale_ +#define clAmdFftGetPlanTransposeResult clAmdFftGetPlanTransposeResult_ +#define clAmdFftGetResultLocation clAmdFftGetResultLocation_ +#define clAmdFftGetTmpBufSize clAmdFftGetTmpBufSize_ +#define clAmdFftGetVersion clAmdFftGetVersion_ +#define clAmdFftSetLayout clAmdFftSetLayout_ +#define clAmdFftSetPlanBatchSize clAmdFftSetPlanBatchSize_ +#define clAmdFftSetPlanDim clAmdFftSetPlanDim_ +#define clAmdFftSetPlanDistance clAmdFftSetPlanDistance_ +#define clAmdFftSetPlanInStride clAmdFftSetPlanInStride_ +#define clAmdFftSetPlanLength clAmdFftSetPlanLength_ +#define clAmdFftSetPlanOutStride clAmdFftSetPlanOutStride_ +#define clAmdFftSetPlanPrecision clAmdFftSetPlanPrecision_ +#define clAmdFftSetPlanScale clAmdFftSetPlanScale_ +#define clAmdFftSetPlanTransposeResult clAmdFftSetPlanTransposeResult_ +#define clAmdFftSetResultLocation clAmdFftSetResultLocation_ +#define clAmdFftSetup clAmdFftSetup_ +#define clAmdFftTeardown clAmdFftTeardown_ + +#include <clAmdFft.h> + +// generated by parser_clamdfft.py +#undef clAmdFftBakePlan +#define clAmdFftBakePlan clAmdFftBakePlan_pfn +#undef clAmdFftCopyPlan +//#define clAmdFftCopyPlan clAmdFftCopyPlan_pfn +#undef clAmdFftCreateDefaultPlan +#define clAmdFftCreateDefaultPlan clAmdFftCreateDefaultPlan_pfn +#undef clAmdFftDestroyPlan +#define clAmdFftDestroyPlan clAmdFftDestroyPlan_pfn +#undef clAmdFftEnqueueTransform +#define clAmdFftEnqueueTransform clAmdFftEnqueueTransform_pfn +#undef clAmdFftGetLayout +//#define clAmdFftGetLayout clAmdFftGetLayout_pfn +#undef clAmdFftGetPlanBatchSize +//#define clAmdFftGetPlanBatchSize clAmdFftGetPlanBatchSize_pfn +#undef clAmdFftGetPlanContext +//#define clAmdFftGetPlanContext clAmdFftGetPlanContext_pfn +#undef clAmdFftGetPlanDim +//#define clAmdFftGetPlanDim clAmdFftGetPlanDim_pfn +#undef clAmdFftGetPlanDistance +//#define clAmdFftGetPlanDistance clAmdFftGetPlanDistance_pfn +#undef clAmdFftGetPlanInStride +//#define clAmdFftGetPlanInStride clAmdFftGetPlanInStride_pfn +#undef clAmdFftGetPlanLength +//#define clAmdFftGetPlanLength clAmdFftGetPlanLength_pfn +#undef clAmdFftGetPlanOutStride +//#define clAmdFftGetPlanOutStride clAmdFftGetPlanOutStride_pfn +#undef clAmdFftGetPlanPrecision +//#define clAmdFftGetPlanPrecision clAmdFftGetPlanPrecision_pfn +#undef clAmdFftGetPlanScale +//#define clAmdFftGetPlanScale clAmdFftGetPlanScale_pfn +#undef clAmdFftGetPlanTransposeResult +//#define clAmdFftGetPlanTransposeResult clAmdFftGetPlanTransposeResult_pfn +#undef clAmdFftGetResultLocation +//#define clAmdFftGetResultLocation clAmdFftGetResultLocation_pfn +#undef clAmdFftGetTmpBufSize +#define clAmdFftGetTmpBufSize clAmdFftGetTmpBufSize_pfn +#undef clAmdFftGetVersion +#define clAmdFftGetVersion clAmdFftGetVersion_pfn +#undef clAmdFftSetLayout +#define clAmdFftSetLayout clAmdFftSetLayout_pfn +#undef clAmdFftSetPlanBatchSize +#define clAmdFftSetPlanBatchSize clAmdFftSetPlanBatchSize_pfn +#undef clAmdFftSetPlanDim +//#define clAmdFftSetPlanDim clAmdFftSetPlanDim_pfn +#undef clAmdFftSetPlanDistance +#define clAmdFftSetPlanDistance clAmdFftSetPlanDistance_pfn +#undef clAmdFftSetPlanInStride +#define clAmdFftSetPlanInStride clAmdFftSetPlanInStride_pfn +#undef clAmdFftSetPlanLength +//#define clAmdFftSetPlanLength clAmdFftSetPlanLength_pfn +#undef clAmdFftSetPlanOutStride +#define clAmdFftSetPlanOutStride clAmdFftSetPlanOutStride_pfn +#undef clAmdFftSetPlanPrecision +#define clAmdFftSetPlanPrecision clAmdFftSetPlanPrecision_pfn +#undef clAmdFftSetPlanScale +#define clAmdFftSetPlanScale clAmdFftSetPlanScale_pfn +#undef clAmdFftSetPlanTransposeResult +//#define clAmdFftSetPlanTransposeResult clAmdFftSetPlanTransposeResult_pfn +#undef clAmdFftSetResultLocation +#define clAmdFftSetResultLocation clAmdFftSetResultLocation_pfn +#undef clAmdFftSetup +#define clAmdFftSetup clAmdFftSetup_pfn +#undef clAmdFftTeardown +#define clAmdFftTeardown clAmdFftTeardown_pfn + +// generated by parser_clamdfft.py +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftBakePlan)(clAmdFftPlanHandle plHandle, cl_uint numQueues, cl_command_queue* commQueueFFT, void (CL_CALLBACK* pfn_notify) (clAmdFftPlanHandle plHandle, void* user_data), void* user_data); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftCopyPlan)(clAmdFftPlanHandle* out_plHandle, cl_context new_context, clAmdFftPlanHandle in_plHandle); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftCreateDefaultPlan)(clAmdFftPlanHandle* plHandle, cl_context context, const clAmdFftDim dim, const size_t* clLengths); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftDestroyPlan)(clAmdFftPlanHandle* plHandle); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftEnqueueTransform)(clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_uint numQueuesAndEvents, cl_command_queue* commQueues, cl_uint numWaitEvents, const cl_event* waitEvents, cl_event* outEvents, cl_mem* inputBuffers, cl_mem* outputBuffers, cl_mem tmpBuffer); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetLayout)(const clAmdFftPlanHandle plHandle, clAmdFftLayout* iLayout, clAmdFftLayout* oLayout); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanBatchSize)(const clAmdFftPlanHandle plHandle, size_t* batchSize); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanContext)(const clAmdFftPlanHandle plHandle, cl_context* context); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanDim)(const clAmdFftPlanHandle plHandle, clAmdFftDim* dim, cl_uint* size); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanDistance)(const clAmdFftPlanHandle plHandle, size_t* iDist, size_t* oDist); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanInStride)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanLength)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clLengths); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanOutStride)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanPrecision)(const clAmdFftPlanHandle plHandle, clAmdFftPrecision* precision); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanScale)(const clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_float* scale); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanTransposeResult)(const clAmdFftPlanHandle plHandle, clAmdFftResultTransposed* transposed); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetResultLocation)(const clAmdFftPlanHandle plHandle, clAmdFftResultLocation* placeness); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetTmpBufSize)(const clAmdFftPlanHandle plHandle, size_t* buffersize); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetLayout)(clAmdFftPlanHandle plHandle, clAmdFftLayout iLayout, clAmdFftLayout oLayout); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanBatchSize)(clAmdFftPlanHandle plHandle, size_t batchSize); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanDim)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanDistance)(clAmdFftPlanHandle plHandle, size_t iDist, size_t oDist); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanInStride)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanLength)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, const size_t* clLengths); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanOutStride)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanPrecision)(clAmdFftPlanHandle plHandle, clAmdFftPrecision precision); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanScale)(clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_float scale); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanTransposeResult)(clAmdFftPlanHandle plHandle, clAmdFftResultTransposed transposed); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetResultLocation)(clAmdFftPlanHandle plHandle, clAmdFftResultLocation placeness); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetup)(const clAmdFftSetupData* setupData); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftTeardown)(); diff --git a/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp b/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp new file mode 100644 index 0000000..28618a1 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp @@ -0,0 +1,371 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP +#error "Invalid usage" +#endif + +// generated by parser_cl.py +#define clBuildProgram clBuildProgram_ +#define clCompileProgram clCompileProgram_ +#define clCreateBuffer clCreateBuffer_ +#define clCreateCommandQueue clCreateCommandQueue_ +#define clCreateContext clCreateContext_ +#define clCreateContextFromType clCreateContextFromType_ +#define clCreateImage clCreateImage_ +#define clCreateImage2D clCreateImage2D_ +#define clCreateImage3D clCreateImage3D_ +#define clCreateKernel clCreateKernel_ +#define clCreateKernelsInProgram clCreateKernelsInProgram_ +#define clCreateProgramWithBinary clCreateProgramWithBinary_ +#define clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels_ +#define clCreateProgramWithSource clCreateProgramWithSource_ +#define clCreateSampler clCreateSampler_ +#define clCreateSubBuffer clCreateSubBuffer_ +#define clCreateSubDevices clCreateSubDevices_ +#define clCreateUserEvent clCreateUserEvent_ +#define clEnqueueBarrier clEnqueueBarrier_ +#define clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList_ +#define clEnqueueCopyBuffer clEnqueueCopyBuffer_ +#define clEnqueueCopyBufferRect clEnqueueCopyBufferRect_ +#define clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage_ +#define clEnqueueCopyImage clEnqueueCopyImage_ +#define clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer_ +#define clEnqueueFillBuffer clEnqueueFillBuffer_ +#define clEnqueueFillImage clEnqueueFillImage_ +#define clEnqueueMapBuffer clEnqueueMapBuffer_ +#define clEnqueueMapImage clEnqueueMapImage_ +#define clEnqueueMarker clEnqueueMarker_ +#define clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList_ +#define clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects_ +#define clEnqueueNDRangeKernel clEnqueueNDRangeKernel_ +#define clEnqueueNativeKernel clEnqueueNativeKernel_ +#define clEnqueueReadBuffer clEnqueueReadBuffer_ +#define clEnqueueReadBufferRect clEnqueueReadBufferRect_ +#define clEnqueueReadImage clEnqueueReadImage_ +#define clEnqueueTask clEnqueueTask_ +#define clEnqueueUnmapMemObject clEnqueueUnmapMemObject_ +#define clEnqueueWaitForEvents clEnqueueWaitForEvents_ +#define clEnqueueWriteBuffer clEnqueueWriteBuffer_ +#define clEnqueueWriteBufferRect clEnqueueWriteBufferRect_ +#define clEnqueueWriteImage clEnqueueWriteImage_ +#define clFinish clFinish_ +#define clFlush clFlush_ +#define clGetCommandQueueInfo clGetCommandQueueInfo_ +#define clGetContextInfo clGetContextInfo_ +#define clGetDeviceIDs clGetDeviceIDs_ +#define clGetDeviceInfo clGetDeviceInfo_ +#define clGetEventInfo clGetEventInfo_ +#define clGetEventProfilingInfo clGetEventProfilingInfo_ +#define clGetExtensionFunctionAddress clGetExtensionFunctionAddress_ +#define clGetExtensionFunctionAddressForPlatform clGetExtensionFunctionAddressForPlatform_ +#define clGetImageInfo clGetImageInfo_ +#define clGetKernelArgInfo clGetKernelArgInfo_ +#define clGetKernelInfo clGetKernelInfo_ +#define clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo_ +#define clGetMemObjectInfo clGetMemObjectInfo_ +#define clGetPlatformIDs clGetPlatformIDs_ +#define clGetPlatformInfo clGetPlatformInfo_ +#define clGetProgramBuildInfo clGetProgramBuildInfo_ +#define clGetProgramInfo clGetProgramInfo_ +#define clGetSamplerInfo clGetSamplerInfo_ +#define clGetSupportedImageFormats clGetSupportedImageFormats_ +#define clLinkProgram clLinkProgram_ +#define clReleaseCommandQueue clReleaseCommandQueue_ +#define clReleaseContext clReleaseContext_ +#define clReleaseDevice clReleaseDevice_ +#define clReleaseEvent clReleaseEvent_ +#define clReleaseKernel clReleaseKernel_ +#define clReleaseMemObject clReleaseMemObject_ +#define clReleaseProgram clReleaseProgram_ +#define clReleaseSampler clReleaseSampler_ +#define clRetainCommandQueue clRetainCommandQueue_ +#define clRetainContext clRetainContext_ +#define clRetainDevice clRetainDevice_ +#define clRetainEvent clRetainEvent_ +#define clRetainKernel clRetainKernel_ +#define clRetainMemObject clRetainMemObject_ +#define clRetainProgram clRetainProgram_ +#define clRetainSampler clRetainSampler_ +#define clSetEventCallback clSetEventCallback_ +#define clSetKernelArg clSetKernelArg_ +#define clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback_ +#define clSetUserEventStatus clSetUserEventStatus_ +#define clUnloadCompiler clUnloadCompiler_ +#define clUnloadPlatformCompiler clUnloadPlatformCompiler_ +#define clWaitForEvents clWaitForEvents_ + +#if defined __APPLE__ +#define CL_SILENCE_DEPRECATION +#include <OpenCL/cl.h> +#else +#include <CL/cl.h> +#endif + +// generated by parser_cl.py +#undef clBuildProgram +#define clBuildProgram clBuildProgram_pfn +#undef clCompileProgram +#define clCompileProgram clCompileProgram_pfn +#undef clCreateBuffer +#define clCreateBuffer clCreateBuffer_pfn +#undef clCreateCommandQueue +#define clCreateCommandQueue clCreateCommandQueue_pfn +#undef clCreateContext +#define clCreateContext clCreateContext_pfn +#undef clCreateContextFromType +#define clCreateContextFromType clCreateContextFromType_pfn +#undef clCreateImage +#define clCreateImage clCreateImage_pfn +#undef clCreateImage2D +#define clCreateImage2D clCreateImage2D_pfn +#undef clCreateImage3D +#define clCreateImage3D clCreateImage3D_pfn +#undef clCreateKernel +#define clCreateKernel clCreateKernel_pfn +#undef clCreateKernelsInProgram +#define clCreateKernelsInProgram clCreateKernelsInProgram_pfn +#undef clCreateProgramWithBinary +#define clCreateProgramWithBinary clCreateProgramWithBinary_pfn +#undef clCreateProgramWithBuiltInKernels +#define clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels_pfn +#undef clCreateProgramWithSource +#define clCreateProgramWithSource clCreateProgramWithSource_pfn +#undef clCreateSampler +#define clCreateSampler clCreateSampler_pfn +#undef clCreateSubBuffer +#define clCreateSubBuffer clCreateSubBuffer_pfn +#undef clCreateSubDevices +#define clCreateSubDevices clCreateSubDevices_pfn +#undef clCreateUserEvent +#define clCreateUserEvent clCreateUserEvent_pfn +#undef clEnqueueBarrier +#define clEnqueueBarrier clEnqueueBarrier_pfn +#undef clEnqueueBarrierWithWaitList +#define clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList_pfn +#undef clEnqueueCopyBuffer +#define clEnqueueCopyBuffer clEnqueueCopyBuffer_pfn +#undef clEnqueueCopyBufferRect +#define clEnqueueCopyBufferRect clEnqueueCopyBufferRect_pfn +#undef clEnqueueCopyBufferToImage +#define clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage_pfn +#undef clEnqueueCopyImage +#define clEnqueueCopyImage clEnqueueCopyImage_pfn +#undef clEnqueueCopyImageToBuffer +#define clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer_pfn +#undef clEnqueueFillBuffer +#define clEnqueueFillBuffer clEnqueueFillBuffer_pfn +#undef clEnqueueFillImage +#define clEnqueueFillImage clEnqueueFillImage_pfn +#undef clEnqueueMapBuffer +#define clEnqueueMapBuffer clEnqueueMapBuffer_pfn +#undef clEnqueueMapImage +#define clEnqueueMapImage clEnqueueMapImage_pfn +#undef clEnqueueMarker +#define clEnqueueMarker clEnqueueMarker_pfn +#undef clEnqueueMarkerWithWaitList +#define clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList_pfn +#undef clEnqueueMigrateMemObjects +#define clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects_pfn +#undef clEnqueueNDRangeKernel +#define clEnqueueNDRangeKernel clEnqueueNDRangeKernel_pfn +#undef clEnqueueNativeKernel +#define clEnqueueNativeKernel clEnqueueNativeKernel_pfn +#undef clEnqueueReadBuffer +#define clEnqueueReadBuffer clEnqueueReadBuffer_pfn +#undef clEnqueueReadBufferRect +#define clEnqueueReadBufferRect clEnqueueReadBufferRect_pfn +#undef clEnqueueReadImage +#define clEnqueueReadImage clEnqueueReadImage_pfn +#undef clEnqueueTask +#define clEnqueueTask clEnqueueTask_pfn +#undef clEnqueueUnmapMemObject +#define clEnqueueUnmapMemObject clEnqueueUnmapMemObject_pfn +#undef clEnqueueWaitForEvents +#define clEnqueueWaitForEvents clEnqueueWaitForEvents_pfn +#undef clEnqueueWriteBuffer +#define clEnqueueWriteBuffer clEnqueueWriteBuffer_pfn +#undef clEnqueueWriteBufferRect +#define clEnqueueWriteBufferRect clEnqueueWriteBufferRect_pfn +#undef clEnqueueWriteImage +#define clEnqueueWriteImage clEnqueueWriteImage_pfn +#undef clFinish +#define clFinish clFinish_pfn +#undef clFlush +#define clFlush clFlush_pfn +#undef clGetCommandQueueInfo +#define clGetCommandQueueInfo clGetCommandQueueInfo_pfn +#undef clGetContextInfo +#define clGetContextInfo clGetContextInfo_pfn +#undef clGetDeviceIDs +#define clGetDeviceIDs clGetDeviceIDs_pfn +#undef clGetDeviceInfo +#define clGetDeviceInfo clGetDeviceInfo_pfn +#undef clGetEventInfo +#define clGetEventInfo clGetEventInfo_pfn +#undef clGetEventProfilingInfo +#define clGetEventProfilingInfo clGetEventProfilingInfo_pfn +#undef clGetExtensionFunctionAddress +#define clGetExtensionFunctionAddress clGetExtensionFunctionAddress_pfn +#undef clGetExtensionFunctionAddressForPlatform +#define clGetExtensionFunctionAddressForPlatform clGetExtensionFunctionAddressForPlatform_pfn +#undef clGetImageInfo +#define clGetImageInfo clGetImageInfo_pfn +#undef clGetKernelArgInfo +#define clGetKernelArgInfo clGetKernelArgInfo_pfn +#undef clGetKernelInfo +#define clGetKernelInfo clGetKernelInfo_pfn +#undef clGetKernelWorkGroupInfo +#define clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo_pfn +#undef clGetMemObjectInfo +#define clGetMemObjectInfo clGetMemObjectInfo_pfn +#undef clGetPlatformIDs +#define clGetPlatformIDs clGetPlatformIDs_pfn +#undef clGetPlatformInfo +#define clGetPlatformInfo clGetPlatformInfo_pfn +#undef clGetProgramBuildInfo +#define clGetProgramBuildInfo clGetProgramBuildInfo_pfn +#undef clGetProgramInfo +#define clGetProgramInfo clGetProgramInfo_pfn +#undef clGetSamplerInfo +#define clGetSamplerInfo clGetSamplerInfo_pfn +#undef clGetSupportedImageFormats +#define clGetSupportedImageFormats clGetSupportedImageFormats_pfn +#undef clLinkProgram +#define clLinkProgram clLinkProgram_pfn +#undef clReleaseCommandQueue +#define clReleaseCommandQueue clReleaseCommandQueue_pfn +#undef clReleaseContext +#define clReleaseContext clReleaseContext_pfn +#undef clReleaseDevice +#define clReleaseDevice clReleaseDevice_pfn +#undef clReleaseEvent +#define clReleaseEvent clReleaseEvent_pfn +#undef clReleaseKernel +#define clReleaseKernel clReleaseKernel_pfn +#undef clReleaseMemObject +#define clReleaseMemObject clReleaseMemObject_pfn +#undef clReleaseProgram +#define clReleaseProgram clReleaseProgram_pfn +#undef clReleaseSampler +#define clReleaseSampler clReleaseSampler_pfn +#undef clRetainCommandQueue +#define clRetainCommandQueue clRetainCommandQueue_pfn +#undef clRetainContext +#define clRetainContext clRetainContext_pfn +#undef clRetainDevice +#define clRetainDevice clRetainDevice_pfn +#undef clRetainEvent +#define clRetainEvent clRetainEvent_pfn +#undef clRetainKernel +#define clRetainKernel clRetainKernel_pfn +#undef clRetainMemObject +#define clRetainMemObject clRetainMemObject_pfn +#undef clRetainProgram +#define clRetainProgram clRetainProgram_pfn +#undef clRetainSampler +#define clRetainSampler clRetainSampler_pfn +#undef clSetEventCallback +#define clSetEventCallback clSetEventCallback_pfn +#undef clSetKernelArg +#define clSetKernelArg clSetKernelArg_pfn +#undef clSetMemObjectDestructorCallback +#define clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback_pfn +#undef clSetUserEventStatus +#define clSetUserEventStatus clSetUserEventStatus_pfn +#undef clUnloadCompiler +#define clUnloadCompiler clUnloadCompiler_pfn +#undef clUnloadPlatformCompiler +#define clUnloadPlatformCompiler clUnloadPlatformCompiler_pfn +#undef clWaitForEvents +#define clWaitForEvents clWaitForEvents_pfn + +// generated by parser_cl.py +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clBuildProgram)(cl_program, cl_uint, const cl_device_id*, const char*, void (CL_CALLBACK*) (cl_program, void*), void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clCompileProgram)(cl_program, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, const char**, void (CL_CALLBACK*) (cl_program, void*), void*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateBuffer)(cl_context, cl_mem_flags, size_t, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_command_queue (CL_API_CALL*clCreateCommandQueue)(cl_context, cl_device_id, cl_command_queue_properties, cl_int*); +extern CL_RUNTIME_EXPORT cl_context (CL_API_CALL*clCreateContext)(const cl_context_properties*, cl_uint, const cl_device_id*, void (CL_CALLBACK*) (const char*, const void*, size_t, void*), void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_context (CL_API_CALL*clCreateContextFromType)(const cl_context_properties*, cl_device_type, void (CL_CALLBACK*) (const char*, const void*, size_t, void*), void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateImage)(cl_context, cl_mem_flags, const cl_image_format*, const cl_image_desc*, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateImage2D)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateImage3D)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, size_t, size_t, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_kernel (CL_API_CALL*clCreateKernel)(cl_program, const char*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clCreateKernelsInProgram)(cl_program, cl_uint, cl_kernel*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clCreateProgramWithBinary)(cl_context, cl_uint, const cl_device_id*, const size_t*, const unsigned char**, cl_int*, cl_int*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clCreateProgramWithBuiltInKernels)(cl_context, cl_uint, const cl_device_id*, const char*, cl_int*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clCreateProgramWithSource)(cl_context, cl_uint, const char**, const size_t*, cl_int*); +extern CL_RUNTIME_EXPORT cl_sampler (CL_API_CALL*clCreateSampler)(cl_context, cl_bool, cl_addressing_mode, cl_filter_mode, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateSubBuffer)(cl_mem, cl_mem_flags, cl_buffer_create_type, const void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clCreateSubDevices)(cl_device_id, const cl_device_partition_property*, cl_uint, cl_device_id*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_event (CL_API_CALL*clCreateUserEvent)(cl_context, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueBarrier)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueBarrierWithWaitList)(cl_command_queue, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyBuffer)(cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyBufferRect)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyBufferToImage)(cl_command_queue, cl_mem, cl_mem, size_t, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyImage)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyImageToBuffer)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueFillBuffer)(cl_command_queue, cl_mem, const void*, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueFillImage)(cl_command_queue, cl_mem, const void*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clEnqueueMapBuffer)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event*, cl_event*, cl_int*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clEnqueueMapImage)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t*, const size_t*, size_t*, size_t*, cl_uint, const cl_event*, cl_event*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueMarker)(cl_command_queue, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueMarkerWithWaitList)(cl_command_queue, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueMigrateMemObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_mem_migration_flags, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueNDRangeKernel)(cl_command_queue, cl_kernel, cl_uint, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueNativeKernel)(cl_command_queue, void (CL_CALLBACK*) (void*), void*, size_t, cl_uint, const cl_mem*, const void**, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReadBuffer)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReadBufferRect)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReadImage)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueTask)(cl_command_queue, cl_kernel, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueUnmapMemObject)(cl_command_queue, cl_mem, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWaitForEvents)(cl_command_queue, cl_uint, const cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWriteBuffer)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWriteBufferRect)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWriteImage)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clFinish)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clFlush)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetCommandQueueInfo)(cl_command_queue, cl_command_queue_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetContextInfo)(cl_context, cl_context_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetDeviceIDs)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetDeviceInfo)(cl_device_id, cl_device_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetEventInfo)(cl_event, cl_event_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetEventProfilingInfo)(cl_event, cl_profiling_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clGetExtensionFunctionAddress)(const char*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clGetExtensionFunctionAddressForPlatform)(cl_platform_id, const char*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetImageInfo)(cl_mem, cl_image_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetKernelArgInfo)(cl_kernel, cl_uint, cl_kernel_arg_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetKernelInfo)(cl_kernel, cl_kernel_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetKernelWorkGroupInfo)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetMemObjectInfo)(cl_mem, cl_mem_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetPlatformIDs)(cl_uint, cl_platform_id*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetPlatformInfo)(cl_platform_id, cl_platform_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetProgramBuildInfo)(cl_program, cl_device_id, cl_program_build_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetProgramInfo)(cl_program, cl_program_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetSamplerInfo)(cl_sampler, cl_sampler_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetSupportedImageFormats)(cl_context, cl_mem_flags, cl_mem_object_type, cl_uint, cl_image_format*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clLinkProgram)(cl_context, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, void (CL_CALLBACK*) (cl_program, void*), void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseCommandQueue)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseContext)(cl_context); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseDevice)(cl_device_id); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseEvent)(cl_event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseKernel)(cl_kernel); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseMemObject)(cl_mem); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseProgram)(cl_program); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseSampler)(cl_sampler); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainCommandQueue)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainContext)(cl_context); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainDevice)(cl_device_id); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainEvent)(cl_event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainKernel)(cl_kernel); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainMemObject)(cl_mem); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainProgram)(cl_program); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainSampler)(cl_sampler); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetEventCallback)(cl_event, cl_int, void (CL_CALLBACK*) (cl_event, cl_int, void*), void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetKernelArg)(cl_kernel, cl_uint, size_t, const void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetMemObjectDestructorCallback)(cl_mem, void (CL_CALLBACK*) (cl_mem, void*), void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetUserEventStatus)(cl_event, cl_int); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clUnloadCompiler)(); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clUnloadPlatformCompiler)(cl_platform_id); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clWaitForEvents)(cl_uint, const cl_event*); diff --git a/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp b/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp new file mode 100644 index 0000000..216b22b --- /dev/null +++ b/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp @@ -0,0 +1,272 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP +#error "Invalid usage" +#endif + +// generated by parser_cl.py +#undef clBuildProgram +#define clBuildProgram clBuildProgram_fn +inline cl_int clBuildProgram(cl_program p0, cl_uint p1, const cl_device_id* p2, const char* p3, void (CL_CALLBACK*p4) (cl_program, void*), void* p5) { return clBuildProgram_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCompileProgram +#define clCompileProgram clCompileProgram_fn +inline cl_int clCompileProgram(cl_program p0, cl_uint p1, const cl_device_id* p2, const char* p3, cl_uint p4, const cl_program* p5, const char** p6, void (CL_CALLBACK*p7) (cl_program, void*), void* p8) { return clCompileProgram_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clCreateBuffer +#define clCreateBuffer clCreateBuffer_fn +inline cl_mem clCreateBuffer(cl_context p0, cl_mem_flags p1, size_t p2, void* p3, cl_int* p4) { return clCreateBuffer_pfn(p0, p1, p2, p3, p4); } +#undef clCreateCommandQueue +#define clCreateCommandQueue clCreateCommandQueue_fn +inline cl_command_queue clCreateCommandQueue(cl_context p0, cl_device_id p1, cl_command_queue_properties p2, cl_int* p3) { return clCreateCommandQueue_pfn(p0, p1, p2, p3); } +#undef clCreateContext +#define clCreateContext clCreateContext_fn +inline cl_context clCreateContext(const cl_context_properties* p0, cl_uint p1, const cl_device_id* p2, void (CL_CALLBACK*p3) (const char*, const void*, size_t, void*), void* p4, cl_int* p5) { return clCreateContext_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateContextFromType +#define clCreateContextFromType clCreateContextFromType_fn +inline cl_context clCreateContextFromType(const cl_context_properties* p0, cl_device_type p1, void (CL_CALLBACK*p2) (const char*, const void*, size_t, void*), void* p3, cl_int* p4) { return clCreateContextFromType_pfn(p0, p1, p2, p3, p4); } +#undef clCreateImage +#define clCreateImage clCreateImage_fn +inline cl_mem clCreateImage(cl_context p0, cl_mem_flags p1, const cl_image_format* p2, const cl_image_desc* p3, void* p4, cl_int* p5) { return clCreateImage_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateImage2D +#define clCreateImage2D clCreateImage2D_fn +inline cl_mem clCreateImage2D(cl_context p0, cl_mem_flags p1, const cl_image_format* p2, size_t p3, size_t p4, size_t p5, void* p6, cl_int* p7) { return clCreateImage2D_pfn(p0, p1, p2, p3, p4, p5, p6, p7); } +#undef clCreateImage3D +#define clCreateImage3D clCreateImage3D_fn +inline cl_mem clCreateImage3D(cl_context p0, cl_mem_flags p1, const cl_image_format* p2, size_t p3, size_t p4, size_t p5, size_t p6, size_t p7, void* p8, cl_int* p9) { return clCreateImage3D_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } +#undef clCreateKernel +#define clCreateKernel clCreateKernel_fn +inline cl_kernel clCreateKernel(cl_program p0, const char* p1, cl_int* p2) { return clCreateKernel_pfn(p0, p1, p2); } +#undef clCreateKernelsInProgram +#define clCreateKernelsInProgram clCreateKernelsInProgram_fn +inline cl_int clCreateKernelsInProgram(cl_program p0, cl_uint p1, cl_kernel* p2, cl_uint* p3) { return clCreateKernelsInProgram_pfn(p0, p1, p2, p3); } +#undef clCreateProgramWithBinary +#define clCreateProgramWithBinary clCreateProgramWithBinary_fn +inline cl_program clCreateProgramWithBinary(cl_context p0, cl_uint p1, const cl_device_id* p2, const size_t* p3, const unsigned char** p4, cl_int* p5, cl_int* p6) { return clCreateProgramWithBinary_pfn(p0, p1, p2, p3, p4, p5, p6); } +#undef clCreateProgramWithBuiltInKernels +#define clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels_fn +inline cl_program clCreateProgramWithBuiltInKernels(cl_context p0, cl_uint p1, const cl_device_id* p2, const char* p3, cl_int* p4) { return clCreateProgramWithBuiltInKernels_pfn(p0, p1, p2, p3, p4); } +#undef clCreateProgramWithSource +#define clCreateProgramWithSource clCreateProgramWithSource_fn +inline cl_program clCreateProgramWithSource(cl_context p0, cl_uint p1, const char** p2, const size_t* p3, cl_int* p4) { return clCreateProgramWithSource_pfn(p0, p1, p2, p3, p4); } +#undef clCreateSampler +#define clCreateSampler clCreateSampler_fn +inline cl_sampler clCreateSampler(cl_context p0, cl_bool p1, cl_addressing_mode p2, cl_filter_mode p3, cl_int* p4) { return clCreateSampler_pfn(p0, p1, p2, p3, p4); } +#undef clCreateSubBuffer +#define clCreateSubBuffer clCreateSubBuffer_fn +inline cl_mem clCreateSubBuffer(cl_mem p0, cl_mem_flags p1, cl_buffer_create_type p2, const void* p3, cl_int* p4) { return clCreateSubBuffer_pfn(p0, p1, p2, p3, p4); } +#undef clCreateSubDevices +#define clCreateSubDevices clCreateSubDevices_fn +inline cl_int clCreateSubDevices(cl_device_id p0, const cl_device_partition_property* p1, cl_uint p2, cl_device_id* p3, cl_uint* p4) { return clCreateSubDevices_pfn(p0, p1, p2, p3, p4); } +#undef clCreateUserEvent +#define clCreateUserEvent clCreateUserEvent_fn +inline cl_event clCreateUserEvent(cl_context p0, cl_int* p1) { return clCreateUserEvent_pfn(p0, p1); } +#undef clEnqueueBarrier +#define clEnqueueBarrier clEnqueueBarrier_fn +inline cl_int clEnqueueBarrier(cl_command_queue p0) { return clEnqueueBarrier_pfn(p0); } +#undef clEnqueueBarrierWithWaitList +#define clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList_fn +inline cl_int clEnqueueBarrierWithWaitList(cl_command_queue p0, cl_uint p1, const cl_event* p2, cl_event* p3) { return clEnqueueBarrierWithWaitList_pfn(p0, p1, p2, p3); } +#undef clEnqueueCopyBuffer +#define clEnqueueCopyBuffer clEnqueueCopyBuffer_fn +inline cl_int clEnqueueCopyBuffer(cl_command_queue p0, cl_mem p1, cl_mem p2, size_t p3, size_t p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueCopyBufferRect +#define clEnqueueCopyBufferRect clEnqueueCopyBufferRect_fn +inline cl_int clEnqueueCopyBufferRect(cl_command_queue p0, cl_mem p1, cl_mem p2, const size_t* p3, const size_t* p4, const size_t* p5, size_t p6, size_t p7, size_t p8, size_t p9, cl_uint p10, const cl_event* p11, cl_event* p12) { return clEnqueueCopyBufferRect_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); } +#undef clEnqueueCopyBufferToImage +#define clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage_fn +inline cl_int clEnqueueCopyBufferToImage(cl_command_queue p0, cl_mem p1, cl_mem p2, size_t p3, const size_t* p4, const size_t* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyBufferToImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueCopyImage +#define clEnqueueCopyImage clEnqueueCopyImage_fn +inline cl_int clEnqueueCopyImage(cl_command_queue p0, cl_mem p1, cl_mem p2, const size_t* p3, const size_t* p4, const size_t* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueCopyImageToBuffer +#define clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer_fn +inline cl_int clEnqueueCopyImageToBuffer(cl_command_queue p0, cl_mem p1, cl_mem p2, const size_t* p3, const size_t* p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyImageToBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueFillBuffer +#define clEnqueueFillBuffer clEnqueueFillBuffer_fn +inline cl_int clEnqueueFillBuffer(cl_command_queue p0, cl_mem p1, const void* p2, size_t p3, size_t p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueFillBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueFillImage +#define clEnqueueFillImage clEnqueueFillImage_fn +inline cl_int clEnqueueFillImage(cl_command_queue p0, cl_mem p1, const void* p2, const size_t* p3, const size_t* p4, cl_uint p5, const cl_event* p6, cl_event* p7) { return clEnqueueFillImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7); } +#undef clEnqueueMapBuffer +#define clEnqueueMapBuffer clEnqueueMapBuffer_fn +inline void* clEnqueueMapBuffer(cl_command_queue p0, cl_mem p1, cl_bool p2, cl_map_flags p3, size_t p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8, cl_int* p9) { return clEnqueueMapBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } +#undef clEnqueueMapImage +#define clEnqueueMapImage clEnqueueMapImage_fn +inline void* clEnqueueMapImage(cl_command_queue p0, cl_mem p1, cl_bool p2, cl_map_flags p3, const size_t* p4, const size_t* p5, size_t* p6, size_t* p7, cl_uint p8, const cl_event* p9, cl_event* p10, cl_int* p11) { return clEnqueueMapImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); } +#undef clEnqueueMarker +#define clEnqueueMarker clEnqueueMarker_fn +inline cl_int clEnqueueMarker(cl_command_queue p0, cl_event* p1) { return clEnqueueMarker_pfn(p0, p1); } +#undef clEnqueueMarkerWithWaitList +#define clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList_fn +inline cl_int clEnqueueMarkerWithWaitList(cl_command_queue p0, cl_uint p1, const cl_event* p2, cl_event* p3) { return clEnqueueMarkerWithWaitList_pfn(p0, p1, p2, p3); } +#undef clEnqueueMigrateMemObjects +#define clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects_fn +inline cl_int clEnqueueMigrateMemObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_mem_migration_flags p3, cl_uint p4, const cl_event* p5, cl_event* p6) { return clEnqueueMigrateMemObjects_pfn(p0, p1, p2, p3, p4, p5, p6); } +#undef clEnqueueNDRangeKernel +#define clEnqueueNDRangeKernel clEnqueueNDRangeKernel_fn +inline cl_int clEnqueueNDRangeKernel(cl_command_queue p0, cl_kernel p1, cl_uint p2, const size_t* p3, const size_t* p4, const size_t* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueNDRangeKernel_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueNativeKernel +#define clEnqueueNativeKernel clEnqueueNativeKernel_fn +inline cl_int clEnqueueNativeKernel(cl_command_queue p0, void (CL_CALLBACK*p1) (void*), void* p2, size_t p3, cl_uint p4, const cl_mem* p5, const void** p6, cl_uint p7, const cl_event* p8, cl_event* p9) { return clEnqueueNativeKernel_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } +#undef clEnqueueReadBuffer +#define clEnqueueReadBuffer clEnqueueReadBuffer_fn +inline cl_int clEnqueueReadBuffer(cl_command_queue p0, cl_mem p1, cl_bool p2, size_t p3, size_t p4, void* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueReadBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueReadBufferRect +#define clEnqueueReadBufferRect clEnqueueReadBufferRect_fn +inline cl_int clEnqueueReadBufferRect(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, const size_t* p5, size_t p6, size_t p7, size_t p8, size_t p9, void* p10, cl_uint p11, const cl_event* p12, cl_event* p13) { return clEnqueueReadBufferRect_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); } +#undef clEnqueueReadImage +#define clEnqueueReadImage clEnqueueReadImage_fn +inline cl_int clEnqueueReadImage(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, size_t p5, size_t p6, void* p7, cl_uint p8, const cl_event* p9, cl_event* p10) { return clEnqueueReadImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } +#undef clEnqueueTask +#define clEnqueueTask clEnqueueTask_fn +inline cl_int clEnqueueTask(cl_command_queue p0, cl_kernel p1, cl_uint p2, const cl_event* p3, cl_event* p4) { return clEnqueueTask_pfn(p0, p1, p2, p3, p4); } +#undef clEnqueueUnmapMemObject +#define clEnqueueUnmapMemObject clEnqueueUnmapMemObject_fn +inline cl_int clEnqueueUnmapMemObject(cl_command_queue p0, cl_mem p1, void* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueUnmapMemObject_pfn(p0, p1, p2, p3, p4, p5); } +#undef clEnqueueWaitForEvents +#define clEnqueueWaitForEvents clEnqueueWaitForEvents_fn +inline cl_int clEnqueueWaitForEvents(cl_command_queue p0, cl_uint p1, const cl_event* p2) { return clEnqueueWaitForEvents_pfn(p0, p1, p2); } +#undef clEnqueueWriteBuffer +#define clEnqueueWriteBuffer clEnqueueWriteBuffer_fn +inline cl_int clEnqueueWriteBuffer(cl_command_queue p0, cl_mem p1, cl_bool p2, size_t p3, size_t p4, const void* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueWriteBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueWriteBufferRect +#define clEnqueueWriteBufferRect clEnqueueWriteBufferRect_fn +inline cl_int clEnqueueWriteBufferRect(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, const size_t* p5, size_t p6, size_t p7, size_t p8, size_t p9, const void* p10, cl_uint p11, const cl_event* p12, cl_event* p13) { return clEnqueueWriteBufferRect_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); } +#undef clEnqueueWriteImage +#define clEnqueueWriteImage clEnqueueWriteImage_fn +inline cl_int clEnqueueWriteImage(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, size_t p5, size_t p6, const void* p7, cl_uint p8, const cl_event* p9, cl_event* p10) { return clEnqueueWriteImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } +#undef clFinish +#define clFinish clFinish_fn +inline cl_int clFinish(cl_command_queue p0) { return clFinish_pfn(p0); } +#undef clFlush +#define clFlush clFlush_fn +inline cl_int clFlush(cl_command_queue p0) { return clFlush_pfn(p0); } +#undef clGetCommandQueueInfo +#define clGetCommandQueueInfo clGetCommandQueueInfo_fn +inline cl_int clGetCommandQueueInfo(cl_command_queue p0, cl_command_queue_info p1, size_t p2, void* p3, size_t* p4) { return clGetCommandQueueInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetContextInfo +#define clGetContextInfo clGetContextInfo_fn +inline cl_int clGetContextInfo(cl_context p0, cl_context_info p1, size_t p2, void* p3, size_t* p4) { return clGetContextInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetDeviceIDs +#define clGetDeviceIDs clGetDeviceIDs_fn +inline cl_int clGetDeviceIDs(cl_platform_id p0, cl_device_type p1, cl_uint p2, cl_device_id* p3, cl_uint* p4) { return clGetDeviceIDs_pfn(p0, p1, p2, p3, p4); } +#undef clGetDeviceInfo +#define clGetDeviceInfo clGetDeviceInfo_fn +inline cl_int clGetDeviceInfo(cl_device_id p0, cl_device_info p1, size_t p2, void* p3, size_t* p4) { return clGetDeviceInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetEventInfo +#define clGetEventInfo clGetEventInfo_fn +inline cl_int clGetEventInfo(cl_event p0, cl_event_info p1, size_t p2, void* p3, size_t* p4) { return clGetEventInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetEventProfilingInfo +#define clGetEventProfilingInfo clGetEventProfilingInfo_fn +inline cl_int clGetEventProfilingInfo(cl_event p0, cl_profiling_info p1, size_t p2, void* p3, size_t* p4) { return clGetEventProfilingInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetExtensionFunctionAddress +#define clGetExtensionFunctionAddress clGetExtensionFunctionAddress_fn +inline void* clGetExtensionFunctionAddress(const char* p0) { return clGetExtensionFunctionAddress_pfn(p0); } +#undef clGetExtensionFunctionAddressForPlatform +#define clGetExtensionFunctionAddressForPlatform clGetExtensionFunctionAddressForPlatform_fn +inline void* clGetExtensionFunctionAddressForPlatform(cl_platform_id p0, const char* p1) { return clGetExtensionFunctionAddressForPlatform_pfn(p0, p1); } +#undef clGetImageInfo +#define clGetImageInfo clGetImageInfo_fn +inline cl_int clGetImageInfo(cl_mem p0, cl_image_info p1, size_t p2, void* p3, size_t* p4) { return clGetImageInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetKernelArgInfo +#define clGetKernelArgInfo clGetKernelArgInfo_fn +inline cl_int clGetKernelArgInfo(cl_kernel p0, cl_uint p1, cl_kernel_arg_info p2, size_t p3, void* p4, size_t* p5) { return clGetKernelArgInfo_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetKernelInfo +#define clGetKernelInfo clGetKernelInfo_fn +inline cl_int clGetKernelInfo(cl_kernel p0, cl_kernel_info p1, size_t p2, void* p3, size_t* p4) { return clGetKernelInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetKernelWorkGroupInfo +#define clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo_fn +inline cl_int clGetKernelWorkGroupInfo(cl_kernel p0, cl_device_id p1, cl_kernel_work_group_info p2, size_t p3, void* p4, size_t* p5) { return clGetKernelWorkGroupInfo_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetMemObjectInfo +#define clGetMemObjectInfo clGetMemObjectInfo_fn +inline cl_int clGetMemObjectInfo(cl_mem p0, cl_mem_info p1, size_t p2, void* p3, size_t* p4) { return clGetMemObjectInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetPlatformIDs +#define clGetPlatformIDs clGetPlatformIDs_fn +inline cl_int clGetPlatformIDs(cl_uint p0, cl_platform_id* p1, cl_uint* p2) { return clGetPlatformIDs_pfn(p0, p1, p2); } +#undef clGetPlatformInfo +#define clGetPlatformInfo clGetPlatformInfo_fn +inline cl_int clGetPlatformInfo(cl_platform_id p0, cl_platform_info p1, size_t p2, void* p3, size_t* p4) { return clGetPlatformInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetProgramBuildInfo +#define clGetProgramBuildInfo clGetProgramBuildInfo_fn +inline cl_int clGetProgramBuildInfo(cl_program p0, cl_device_id p1, cl_program_build_info p2, size_t p3, void* p4, size_t* p5) { return clGetProgramBuildInfo_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetProgramInfo +#define clGetProgramInfo clGetProgramInfo_fn +inline cl_int clGetProgramInfo(cl_program p0, cl_program_info p1, size_t p2, void* p3, size_t* p4) { return clGetProgramInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetSamplerInfo +#define clGetSamplerInfo clGetSamplerInfo_fn +inline cl_int clGetSamplerInfo(cl_sampler p0, cl_sampler_info p1, size_t p2, void* p3, size_t* p4) { return clGetSamplerInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetSupportedImageFormats +#define clGetSupportedImageFormats clGetSupportedImageFormats_fn +inline cl_int clGetSupportedImageFormats(cl_context p0, cl_mem_flags p1, cl_mem_object_type p2, cl_uint p3, cl_image_format* p4, cl_uint* p5) { return clGetSupportedImageFormats_pfn(p0, p1, p2, p3, p4, p5); } +#undef clLinkProgram +#define clLinkProgram clLinkProgram_fn +inline cl_program clLinkProgram(cl_context p0, cl_uint p1, const cl_device_id* p2, const char* p3, cl_uint p4, const cl_program* p5, void (CL_CALLBACK*p6) (cl_program, void*), void* p7, cl_int* p8) { return clLinkProgram_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clReleaseCommandQueue +#define clReleaseCommandQueue clReleaseCommandQueue_fn +inline cl_int clReleaseCommandQueue(cl_command_queue p0) { return clReleaseCommandQueue_pfn(p0); } +#undef clReleaseContext +#define clReleaseContext clReleaseContext_fn +inline cl_int clReleaseContext(cl_context p0) { return clReleaseContext_pfn(p0); } +#undef clReleaseDevice +#define clReleaseDevice clReleaseDevice_fn +inline cl_int clReleaseDevice(cl_device_id p0) { return clReleaseDevice_pfn(p0); } +#undef clReleaseEvent +#define clReleaseEvent clReleaseEvent_fn +inline cl_int clReleaseEvent(cl_event p0) { return clReleaseEvent_pfn(p0); } +#undef clReleaseKernel +#define clReleaseKernel clReleaseKernel_fn +inline cl_int clReleaseKernel(cl_kernel p0) { return clReleaseKernel_pfn(p0); } +#undef clReleaseMemObject +#define clReleaseMemObject clReleaseMemObject_fn +inline cl_int clReleaseMemObject(cl_mem p0) { return clReleaseMemObject_pfn(p0); } +#undef clReleaseProgram +#define clReleaseProgram clReleaseProgram_fn +inline cl_int clReleaseProgram(cl_program p0) { return clReleaseProgram_pfn(p0); } +#undef clReleaseSampler +#define clReleaseSampler clReleaseSampler_fn +inline cl_int clReleaseSampler(cl_sampler p0) { return clReleaseSampler_pfn(p0); } +#undef clRetainCommandQueue +#define clRetainCommandQueue clRetainCommandQueue_fn +inline cl_int clRetainCommandQueue(cl_command_queue p0) { return clRetainCommandQueue_pfn(p0); } +#undef clRetainContext +#define clRetainContext clRetainContext_fn +inline cl_int clRetainContext(cl_context p0) { return clRetainContext_pfn(p0); } +#undef clRetainDevice +#define clRetainDevice clRetainDevice_fn +inline cl_int clRetainDevice(cl_device_id p0) { return clRetainDevice_pfn(p0); } +#undef clRetainEvent +#define clRetainEvent clRetainEvent_fn +inline cl_int clRetainEvent(cl_event p0) { return clRetainEvent_pfn(p0); } +#undef clRetainKernel +#define clRetainKernel clRetainKernel_fn +inline cl_int clRetainKernel(cl_kernel p0) { return clRetainKernel_pfn(p0); } +#undef clRetainMemObject +#define clRetainMemObject clRetainMemObject_fn +inline cl_int clRetainMemObject(cl_mem p0) { return clRetainMemObject_pfn(p0); } +#undef clRetainProgram +#define clRetainProgram clRetainProgram_fn +inline cl_int clRetainProgram(cl_program p0) { return clRetainProgram_pfn(p0); } +#undef clRetainSampler +#define clRetainSampler clRetainSampler_fn +inline cl_int clRetainSampler(cl_sampler p0) { return clRetainSampler_pfn(p0); } +#undef clSetEventCallback +#define clSetEventCallback clSetEventCallback_fn +inline cl_int clSetEventCallback(cl_event p0, cl_int p1, void (CL_CALLBACK*p2) (cl_event, cl_int, void*), void* p3) { return clSetEventCallback_pfn(p0, p1, p2, p3); } +#undef clSetKernelArg +#define clSetKernelArg clSetKernelArg_fn +inline cl_int clSetKernelArg(cl_kernel p0, cl_uint p1, size_t p2, const void* p3) { return clSetKernelArg_pfn(p0, p1, p2, p3); } +#undef clSetMemObjectDestructorCallback +#define clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback_fn +inline cl_int clSetMemObjectDestructorCallback(cl_mem p0, void (CL_CALLBACK*p1) (cl_mem, void*), void* p2) { return clSetMemObjectDestructorCallback_pfn(p0, p1, p2); } +#undef clSetUserEventStatus +#define clSetUserEventStatus clSetUserEventStatus_fn +inline cl_int clSetUserEventStatus(cl_event p0, cl_int p1) { return clSetUserEventStatus_pfn(p0, p1); } +#undef clUnloadCompiler +#define clUnloadCompiler clUnloadCompiler_fn +inline cl_int clUnloadCompiler() { return clUnloadCompiler_pfn(); } +#undef clUnloadPlatformCompiler +#define clUnloadPlatformCompiler clUnloadPlatformCompiler_fn +inline cl_int clUnloadPlatformCompiler(cl_platform_id p0) { return clUnloadPlatformCompiler_pfn(p0); } +#undef clWaitForEvents +#define clWaitForEvents clWaitForEvents_fn +inline cl_int clWaitForEvents(cl_uint p0, const cl_event* p1) { return clWaitForEvents_pfn(p0, p1); } diff --git a/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp b/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp new file mode 100644 index 0000000..0b12aed --- /dev/null +++ b/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp @@ -0,0 +1,62 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP +#error "Invalid usage" +#endif + +// generated by parser_cl.py +#define clCreateFromGLBuffer clCreateFromGLBuffer_ +#define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_ +#define clCreateFromGLTexture clCreateFromGLTexture_ +#define clCreateFromGLTexture2D clCreateFromGLTexture2D_ +#define clCreateFromGLTexture3D clCreateFromGLTexture3D_ +#define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_ +#define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_ +#define clGetGLContextInfoKHR clGetGLContextInfoKHR_ +#define clGetGLObjectInfo clGetGLObjectInfo_ +#define clGetGLTextureInfo clGetGLTextureInfo_ + +#if defined __APPLE__ +#include <OpenCL/cl_gl.h> +#else +#include <CL/cl_gl.h> +#endif + +// generated by parser_cl.py +#undef clCreateFromGLBuffer +#define clCreateFromGLBuffer clCreateFromGLBuffer_pfn +#undef clCreateFromGLRenderbuffer +#define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_pfn +#undef clCreateFromGLTexture +#define clCreateFromGLTexture clCreateFromGLTexture_pfn +#undef clCreateFromGLTexture2D +#define clCreateFromGLTexture2D clCreateFromGLTexture2D_pfn +#undef clCreateFromGLTexture3D +#define clCreateFromGLTexture3D clCreateFromGLTexture3D_pfn +#undef clEnqueueAcquireGLObjects +#define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_pfn +#undef clEnqueueReleaseGLObjects +#define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_pfn +#undef clGetGLContextInfoKHR +#define clGetGLContextInfoKHR clGetGLContextInfoKHR_pfn +#undef clGetGLObjectInfo +#define clGetGLObjectInfo clGetGLObjectInfo_pfn +#undef clGetGLTextureInfo +#define clGetGLTextureInfo clGetGLTextureInfo_pfn + +#ifdef cl_khr_gl_sharing + +// generated by parser_cl.py +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLRenderbuffer)(cl_context, cl_mem_flags, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture2D)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture3D)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueAcquireGLObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReleaseGLObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLContextInfoKHR)(const cl_context_properties*, cl_gl_context_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLObjectInfo)(cl_mem, cl_gl_object_type*, cl_GLuint*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t, void*, size_t*); + +#endif // cl_khr_gl_sharing diff --git a/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp b/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp new file mode 100644 index 0000000..12f342b --- /dev/null +++ b/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp @@ -0,0 +1,42 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP +#error "Invalid usage" +#endif + +#ifdef cl_khr_gl_sharing + +// generated by parser_cl.py +#undef clCreateFromGLBuffer +#define clCreateFromGLBuffer clCreateFromGLBuffer_fn +inline cl_mem clCreateFromGLBuffer(cl_context p0, cl_mem_flags p1, cl_GLuint p2, int* p3) { return clCreateFromGLBuffer_pfn(p0, p1, p2, p3); } +#undef clCreateFromGLRenderbuffer +#define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_fn +inline cl_mem clCreateFromGLRenderbuffer(cl_context p0, cl_mem_flags p1, cl_GLuint p2, cl_int* p3) { return clCreateFromGLRenderbuffer_pfn(p0, p1, p2, p3); } +#undef clCreateFromGLTexture +#define clCreateFromGLTexture clCreateFromGLTexture_fn +inline cl_mem clCreateFromGLTexture(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateFromGLTexture2D +#define clCreateFromGLTexture2D clCreateFromGLTexture2D_fn +inline cl_mem clCreateFromGLTexture2D(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture2D_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateFromGLTexture3D +#define clCreateFromGLTexture3D clCreateFromGLTexture3D_fn +inline cl_mem clCreateFromGLTexture3D(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture3D_pfn(p0, p1, p2, p3, p4, p5); } +#undef clEnqueueAcquireGLObjects +#define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_fn +inline cl_int clEnqueueAcquireGLObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueAcquireGLObjects_pfn(p0, p1, p2, p3, p4, p5); } +#undef clEnqueueReleaseGLObjects +#define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_fn +inline cl_int clEnqueueReleaseGLObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueReleaseGLObjects_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetGLContextInfoKHR +#define clGetGLContextInfoKHR clGetGLContextInfoKHR_fn +inline cl_int clGetGLContextInfoKHR(const cl_context_properties* p0, cl_gl_context_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLContextInfoKHR_pfn(p0, p1, p2, p3, p4); } +#undef clGetGLObjectInfo +#define clGetGLObjectInfo clGetGLObjectInfo_fn +inline cl_int clGetGLObjectInfo(cl_mem p0, cl_gl_object_type* p1, cl_GLuint* p2) { return clGetGLObjectInfo_pfn(p0, p1, p2); } +#undef clGetGLTextureInfo +#define clGetGLTextureInfo clGetGLTextureInfo_fn +inline cl_int clGetGLTextureInfo(cl_mem p0, cl_gl_texture_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLTextureInfo_pfn(p0, p1, p2, p3, p4); } + +#endif // cl_khr_gl_sharing diff --git a/include/opencv2/core/opencl/runtime/opencl_clamdblas.hpp b/include/opencv2/core/opencl/runtime/opencl_clamdblas.hpp new file mode 100644 index 0000000..2ad8ac0 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_clamdblas.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP +#define OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP + +#ifdef HAVE_CLAMDBLAS + +#include "opencl_core.hpp" + +#include "autogenerated/opencl_clamdblas.hpp" + +#endif // HAVE_CLAMDBLAS + +#endif // OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_clamdfft.hpp b/include/opencv2/core/opencl/runtime/opencl_clamdfft.hpp new file mode 100644 index 0000000..a328f72 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_clamdfft.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP +#define OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP + +#ifdef HAVE_CLAMDFFT + +#include "opencl_core.hpp" + +#include "autogenerated/opencl_clamdfft.hpp" + +#endif // HAVE_CLAMDFFT + +#endif // OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_core.hpp b/include/opencv2/core/opencl/runtime/opencl_core.hpp new file mode 100644 index 0000000..0404b31 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_core.hpp @@ -0,0 +1,84 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP + +#ifdef HAVE_OPENCL + +#ifndef CL_RUNTIME_EXPORT +#if (defined(BUILD_SHARED_LIBS) || defined(OPENCV_CORE_SHARED)) && (defined _WIN32 || defined WINCE) && \ + !(defined(__OPENCV_BUILD) && defined(OPENCV_MODULE_IS_PART_OF_WORLD)) +#define CL_RUNTIME_EXPORT __declspec(dllimport) +#else +#define CL_RUNTIME_EXPORT +#endif +#endif + +#ifdef HAVE_OPENCL_SVM +#define clSVMAlloc clSVMAlloc_ +#define clSVMFree clSVMFree_ +#define clSetKernelArgSVMPointer clSetKernelArgSVMPointer_ +#define clSetKernelExecInfo clSetKernelExecInfo_ +#define clEnqueueSVMFree clEnqueueSVMFree_ +#define clEnqueueSVMMemcpy clEnqueueSVMMemcpy_ +#define clEnqueueSVMMemFill clEnqueueSVMMemFill_ +#define clEnqueueSVMMap clEnqueueSVMMap_ +#define clEnqueueSVMUnmap clEnqueueSVMUnmap_ +#endif + +#include "autogenerated/opencl_core.hpp" + +#ifndef CL_DEVICE_DOUBLE_FP_CONFIG +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#endif + +#ifndef CL_DEVICE_HALF_FP_CONFIG +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 +#endif + +#ifndef CL_VERSION_1_2 +#define CV_REQUIRE_OPENCL_1_2_ERROR CV_Error(cv::Error::OpenCLApiCallError, "OpenCV compiled without OpenCL v1.2 support, so we can't use functionality from OpenCL v1.2") +#endif + +#endif // HAVE_OPENCL + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp b/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp new file mode 100644 index 0000000..38fcae9 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP + +#include "autogenerated/opencl_core_wrappers.hpp" + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_gl.hpp b/include/opencv2/core/opencl/runtime/opencl_gl.hpp new file mode 100644 index 0000000..659c7d8 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_gl.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP + +#if defined HAVE_OPENCL && defined HAVE_OPENGL + +#include "opencl_core.hpp" + +#include "autogenerated/opencl_gl.hpp" + +#endif // defined HAVE_OPENCL && defined HAVE_OPENGL + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp b/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp new file mode 100644 index 0000000..9700004 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP + +#include "autogenerated/opencl_gl_wrappers.hpp" + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp b/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp new file mode 100644 index 0000000..9636b19 --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp @@ -0,0 +1,48 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP + +#if defined(HAVE_OPENCL_SVM) +#include "opencl_core.hpp" + +#include "opencl_svm_definitions.hpp" + +#undef clSVMAlloc +#define clSVMAlloc clSVMAlloc_pfn +#undef clSVMFree +#define clSVMFree clSVMFree_pfn +#undef clSetKernelArgSVMPointer +#define clSetKernelArgSVMPointer clSetKernelArgSVMPointer_pfn +#undef clSetKernelExecInfo +//#define clSetKernelExecInfo clSetKernelExecInfo_pfn +#undef clEnqueueSVMFree +//#define clEnqueueSVMFree clEnqueueSVMFree_pfn +#undef clEnqueueSVMMemcpy +#define clEnqueueSVMMemcpy clEnqueueSVMMemcpy_pfn +#undef clEnqueueSVMMemFill +#define clEnqueueSVMMemFill clEnqueueSVMMemFill_pfn +#undef clEnqueueSVMMap +#define clEnqueueSVMMap clEnqueueSVMMap_pfn +#undef clEnqueueSVMUnmap +#define clEnqueueSVMUnmap clEnqueueSVMUnmap_pfn + +extern CL_RUNTIME_EXPORT void* (CL_API_CALL *clSVMAlloc)(cl_context context, cl_svm_mem_flags flags, size_t size, unsigned int alignment); +extern CL_RUNTIME_EXPORT void (CL_API_CALL *clSVMFree)(cl_context context, void* svm_pointer); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clSetKernelArgSVMPointer)(cl_kernel kernel, cl_uint arg_index, const void* arg_value); +//extern CL_RUNTIME_EXPORT void* (CL_API_CALL *clSetKernelExecInfo)(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void* param_value); +//extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMFree)(cl_command_queue command_queue, cl_uint num_svm_pointers, void* svm_pointers[], +// void (CL_CALLBACK *pfn_free_func)(cl_command_queue queue, cl_uint num_svm_pointers, void* svm_pointers[], void* user_data), void* user_data, +// cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMemcpy)(cl_command_queue command_queue, cl_bool blocking_copy, void* dst_ptr, const void* src_ptr, size_t size, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMemFill)(cl_command_queue command_queue, void* svm_ptr, const void* pattern, size_t pattern_size, size_t size, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMap)(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags map_flags, void* svm_ptr, size_t size, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMUnmap)(cl_command_queue command_queue, void* svm_ptr, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); + +#endif // HAVE_OPENCL_SVM + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp b/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp new file mode 100644 index 0000000..97c927b --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp @@ -0,0 +1,42 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP + +#if defined(HAVE_OPENCL_SVM) +#if defined(CL_VERSION_2_0) + +// OpenCL 2.0 contains SVM definitions + +#else + +typedef cl_bitfield cl_device_svm_capabilities; +typedef cl_bitfield cl_svm_mem_flags; +typedef cl_uint cl_kernel_exec_info; + +// +// TODO Add real values after OpenCL 2.0 release +// + +#ifndef CL_DEVICE_SVM_CAPABILITIES +#define CL_DEVICE_SVM_CAPABILITIES 0x1053 + +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS (1 << 3) +#endif + +#ifndef CL_MEM_SVM_FINE_GRAIN_BUFFER +#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) +#endif + +#ifndef CL_MEM_SVM_ATOMICS +#define CL_MEM_SVM_ATOMICS (1 << 11) +#endif + + +#endif // CL_VERSION_2_0 +#endif // HAVE_OPENCL_SVM + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP diff --git a/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp b/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp new file mode 100644 index 0000000..497bc3d --- /dev/null +++ b/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp @@ -0,0 +1,166 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_HSA_EXTENSION_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_HSA_EXTENSION_HPP + +#if defined(HAVE_OPENCL_SVM) +#include "opencl_core.hpp" + +#ifndef CL_DEVICE_SVM_CAPABILITIES_AMD +// +// Part of the file is an extract from the cl_ext.h file from AMD APP SDK package. +// Below is the original copyright. +// +/******************************************************************************* + * Copyright (c) 2008-2013 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/******************************************* + * Shared Virtual Memory (SVM) extension + *******************************************/ +typedef cl_bitfield cl_device_svm_capabilities_amd; +typedef cl_bitfield cl_svm_mem_flags_amd; +typedef cl_uint cl_kernel_exec_info_amd; + +/* cl_device_info */ +#define CL_DEVICE_SVM_CAPABILITIES_AMD 0x1053 +#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT_AMD 0x1054 + +/* cl_device_svm_capabilities_amd */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_AMD (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_AMD (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_AMD (1 << 2) +#define CL_DEVICE_SVM_ATOMICS_AMD (1 << 3) + +/* cl_svm_mem_flags_amd */ +#define CL_MEM_SVM_FINE_GRAIN_BUFFER_AMD (1 << 10) +#define CL_MEM_SVM_ATOMICS_AMD (1 << 11) + +/* cl_mem_info */ +#define CL_MEM_USES_SVM_POINTER_AMD 0x1109 + +/* cl_kernel_exec_info_amd */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS_AMD 0x11B6 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_AMD 0x11B7 + +/* cl_command_type */ +#define CL_COMMAND_SVM_FREE_AMD 0x1209 +#define CL_COMMAND_SVM_MEMCPY_AMD 0x120A +#define CL_COMMAND_SVM_MEMFILL_AMD 0x120B +#define CL_COMMAND_SVM_MAP_AMD 0x120C +#define CL_COMMAND_SVM_UNMAP_AMD 0x120D + +typedef CL_API_ENTRY void* +(CL_API_CALL * clSVMAllocAMD_fn)( + cl_context /* context */, + cl_svm_mem_flags_amd /* flags */, + size_t /* size */, + unsigned int /* alignment */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY void +(CL_API_CALL * clSVMFreeAMD_fn)( + cl_context /* context */, + void* /* svm_pointer */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMFreeAMD_fn)( + cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void** /* svm_pointers */, + void (CL_CALLBACK *)( /*pfn_free_func*/ + cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void** /* svm_pointers */, + void* /* user_data */), + void* /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMMemcpyAMD_fn)( + cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void* /* dst_ptr */, + const void* /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMMemFillAMD_fn)( + cl_command_queue /* command_queue */, + void* /* svm_ptr */, + const void* /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMMapAMD_fn)( + cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, + void* /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMUnmapAMD_fn)( + cl_command_queue /* command_queue */, + void* /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clSetKernelArgSVMPointerAMD_fn)( + cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clSetKernelExecInfoAMD_fn)( + cl_kernel /* kernel */, + cl_kernel_exec_info_amd /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */ +) CL_EXT_SUFFIX__VERSION_1_2; + +#endif + +#endif // HAVE_OPENCL_SVM + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_HSA_EXTENSION_HPP diff --git a/include/opencv2/core/opengl.hpp b/include/opencv2/core/opengl.hpp new file mode 100644 index 0000000..a6288be --- /dev/null +++ b/include/opencv2/core/opengl.hpp @@ -0,0 +1,725 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OPENGL_HPP +#define OPENCV_CORE_OPENGL_HPP + +#ifndef __cplusplus +# error opengl.hpp header must be compiled as C++ +#endif + +#include "opencv2/core.hpp" +#include "ocl.hpp" + +namespace cv { namespace ogl { + +/** @addtogroup core_opengl +This section describes OpenGL interoperability. + +To enable OpenGL support, configure OpenCV using CMake with WITH_OPENGL=ON . Currently OpenGL is +supported only with WIN32, GTK and Qt backends on Windows and Linux (MacOS and Android are not +supported). For GTK backend gtkglext-1.0 library is required. + +To use OpenGL functionality you should first create OpenGL context (window or frame buffer). You can +do this with namedWindow function or with other OpenGL toolkit (GLUT, for example). +*/ +//! @{ + +/////////////////// OpenGL Objects /////////////////// + +/** @brief Smart pointer for OpenGL buffer object with reference counting. + +Buffer Objects are OpenGL objects that store an array of unformatted memory allocated by the OpenGL +context. These can be used to store vertex data, pixel data retrieved from images or the +framebuffer, and a variety of other things. + +ogl::Buffer has interface similar with Mat interface and represents 2D array memory. + +ogl::Buffer supports memory transfers between host and device and also can be mapped to CUDA memory. + */ +class CV_EXPORTS Buffer +{ +public: + /** @brief The target defines how you intend to use the buffer object. + */ + enum Target + { + ARRAY_BUFFER = 0x8892, //!< The buffer will be used as a source for vertex data + ELEMENT_ARRAY_BUFFER = 0x8893, //!< The buffer will be used for indices (in glDrawElements, for example) + PIXEL_PACK_BUFFER = 0x88EB, //!< The buffer will be used for reading from OpenGL textures + PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures + }; + + enum Access + { + READ_ONLY = 0x88B8, + WRITE_ONLY = 0x88B9, + READ_WRITE = 0x88BA + }; + + /** @brief The constructors. + + Creates empty ogl::Buffer object, creates ogl::Buffer object from existed buffer ( abufId + parameter), allocates memory for ogl::Buffer object or copies from host/device memory. + */ + Buffer(); + + /** @overload + @param arows Number of rows in a 2D array. + @param acols Number of columns in a 2D array. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param abufId Buffer object name. + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param abufId Buffer object name. + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false); + + /** @overload + @param arows Number of rows in a 2D array. + @param acols Number of columns in a 2D array. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ). + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + explicit Buffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @brief Allocates memory for ogl::Buffer object. + + @param arows Number of rows in a 2D array. + @param acols Number of columns in a 2D array. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @brief Decrements the reference counter and destroys the buffer object if needed. + + The function will call setAutoRelease(true) . + */ + void release(); + + /** @brief Sets auto release mode. + + The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was + bound to a window it could be released at any time (user can close a window). If object's destructor + is called after destruction of the context it will cause an error. Thus ogl::Buffer doesn't destroy + OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context). + This function can force ogl::Buffer destructor to destroy OpenGL object. + @param flag Auto release mode (if true, release will be called in object's destructor). + */ + void setAutoRelease(bool flag); + + /** @brief Copies from host/device memory to OpenGL buffer. + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ). + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload */ + void copyFrom(InputArray arr, cuda::Stream& stream, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @brief Copies from OpenGL buffer to host/device memory or another OpenGL buffer object. + + @param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , std::vector or + ogl::Buffer ). + */ + void copyTo(OutputArray arr) const; + + /** @overload */ + void copyTo(OutputArray arr, cuda::Stream& stream) const; + + /** @brief Creates a full copy of the buffer object and the underlying data. + + @param target Buffer usage for destination buffer. + @param autoRelease Auto release mode for destination buffer. + */ + Buffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const; + + /** @brief Binds OpenGL buffer to the specified buffer binding point. + + @param target Binding point. See cv::ogl::Buffer::Target . + */ + void bind(Target target) const; + + /** @brief Unbind any buffers from the specified binding point. + + @param target Binding point. See cv::ogl::Buffer::Target . + */ + static void unbind(Target target); + + /** @brief Maps OpenGL buffer to host memory. + + mapHost maps to the client's address space the entire data store of the buffer object. The data can + then be directly read and/or written relative to the returned pointer, depending on the specified + access policy. + + A mapped data store must be unmapped with ogl::Buffer::unmapHost before its buffer object is used. + + This operation can lead to memory transfers between host and device. + + Only one buffer object can be mapped at a time. + @param access Access policy, indicating whether it will be possible to read from, write to, or both + read from and write to the buffer object's mapped data store. The symbolic constant must be + ogl::Buffer::READ_ONLY , ogl::Buffer::WRITE_ONLY or ogl::Buffer::READ_WRITE . + */ + Mat mapHost(Access access); + + /** @brief Unmaps OpenGL buffer. + */ + void unmapHost(); + + //! map to device memory (blocking) + cuda::GpuMat mapDevice(); + void unmapDevice(); + + /** @brief Maps OpenGL buffer to CUDA device memory. + + This operation doesn't copy data. Several buffer objects can be mapped to CUDA memory at a time. + + A mapped data store must be unmapped with ogl::Buffer::unmapDevice before its buffer object is used. + */ + cuda::GpuMat mapDevice(cuda::Stream& stream); + + /** @brief Unmaps OpenGL buffer. + */ + void unmapDevice(cuda::Stream& stream); + + int rows() const; + int cols() const; + Size size() const; + bool empty() const; + + int type() const; + int depth() const; + int channels() const; + int elemSize() const; + int elemSize1() const; + + //! get OpenGL opject id + unsigned int bufId() const; + + class Impl; + +private: + Ptr<Impl> impl_; + int rows_; + int cols_; + int type_; +}; + +/** @brief Smart pointer for OpenGL 2D texture memory with reference counting. + */ +class CV_EXPORTS Texture2D +{ +public: + /** @brief An Image Format describes the way that the images in Textures store their data. + */ + enum Format + { + NONE = 0, + DEPTH_COMPONENT = 0x1902, //!< Depth + RGB = 0x1907, //!< Red, Green, Blue + RGBA = 0x1908 //!< Red, Green, Blue, Alpha + }; + + /** @brief The constructors. + + Creates empty ogl::Texture2D object, allocates memory for ogl::Texture2D object or copies from + host/device memory. + */ + Texture2D(); + + /** @overload */ + Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false); + + /** @overload */ + Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false); + + /** @overload + @param arows Number of rows. + @param acols Number of columns. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Texture2D(int arows, int acols, Format aformat, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Texture2D(Size asize, Format aformat, bool autoRelease = false); + + /** @overload + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ). + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + explicit Texture2D(InputArray arr, bool autoRelease = false); + + /** @brief Allocates memory for ogl::Texture2D object. + + @param arows Number of rows. + @param acols Number of columns. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(int arows, int acols, Format aformat, bool autoRelease = false); + /** @overload + @param asize 2D array size. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(Size asize, Format aformat, bool autoRelease = false); + + /** @brief Decrements the reference counter and destroys the texture object if needed. + + The function will call setAutoRelease(true) . + */ + void release(); + + /** @brief Sets auto release mode. + + @param flag Auto release mode (if true, release will be called in object's destructor). + + The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was + bound to a window it could be released at any time (user can close a window). If object's destructor + is called after destruction of the context it will cause an error. Thus ogl::Texture2D doesn't + destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL + context). This function can force ogl::Texture2D destructor to destroy OpenGL object. + */ + void setAutoRelease(bool flag); + + /** @brief Copies from host/device memory to OpenGL texture. + + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ). + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void copyFrom(InputArray arr, bool autoRelease = false); + + /** @brief Copies from OpenGL texture to host/device memory or another OpenGL texture object. + + @param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , ogl::Buffer or + ogl::Texture2D ). + @param ddepth Destination depth. + @param autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture). + */ + void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const; + + /** @brief Binds texture to current active texture unit for GL_TEXTURE_2D target. + */ + void bind() const; + + int rows() const; + int cols() const; + Size size() const; + bool empty() const; + + Format format() const; + + //! get OpenGL opject id + unsigned int texId() const; + + class Impl; + +private: + Ptr<Impl> impl_; + int rows_; + int cols_; + Format format_; +}; + +/** @brief Wrapper for OpenGL Client-Side Vertex arrays. + +ogl::Arrays stores vertex data in ogl::Buffer objects. + */ +class CV_EXPORTS Arrays +{ +public: + /** @brief Default constructor + */ + Arrays(); + + /** @brief Sets an array of vertex coordinates. + @param vertex array with vertex coordinates, can be both host and device memory. + */ + void setVertexArray(InputArray vertex); + + /** @brief Resets vertex coordinates. + */ + void resetVertexArray(); + + /** @brief Sets an array of vertex colors. + @param color array with vertex colors, can be both host and device memory. + */ + void setColorArray(InputArray color); + + /** @brief Resets vertex colors. + */ + void resetColorArray(); + + /** @brief Sets an array of vertex normals. + @param normal array with vertex normals, can be both host and device memory. + */ + void setNormalArray(InputArray normal); + + /** @brief Resets vertex normals. + */ + void resetNormalArray(); + + /** @brief Sets an array of vertex texture coordinates. + @param texCoord array with vertex texture coordinates, can be both host and device memory. + */ + void setTexCoordArray(InputArray texCoord); + + /** @brief Resets vertex texture coordinates. + */ + void resetTexCoordArray(); + + /** @brief Releases all inner buffers. + */ + void release(); + + /** @brief Sets auto release mode all inner buffers. + @param flag Auto release mode. + */ + void setAutoRelease(bool flag); + + /** @brief Binds all vertex arrays. + */ + void bind() const; + + /** @brief Returns the vertex count. + */ + int size() const; + bool empty() const; + +private: + int size_; + Buffer vertex_; + Buffer color_; + Buffer normal_; + Buffer texCoord_; +}; + +/////////////////// Render Functions /////////////////// + +//! render mode +enum RenderModes { + POINTS = 0x0000, + LINES = 0x0001, + LINE_LOOP = 0x0002, + LINE_STRIP = 0x0003, + TRIANGLES = 0x0004, + TRIANGLE_STRIP = 0x0005, + TRIANGLE_FAN = 0x0006, + QUADS = 0x0007, + QUAD_STRIP = 0x0008, + POLYGON = 0x0009 +}; + +/** @brief Render OpenGL texture or primitives. +@param tex Texture to draw. +@param wndRect Region of window, where to draw a texture (normalized coordinates). +@param texRect Region of texture to draw (normalized coordinates). + */ +CV_EXPORTS void render(const Texture2D& tex, + Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0), + Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0)); + +/** @overload +@param arr Array of privitives vertices. +@param mode Render mode. One of cv::ogl::RenderModes +@param color Color for all vertices. Will be used if arr doesn't contain color array. +*/ +CV_EXPORTS void render(const Arrays& arr, int mode = POINTS, Scalar color = Scalar::all(255)); + +/** @overload +@param arr Array of privitives vertices. +@param indices Array of vertices indices (host or device memory). +@param mode Render mode. One of cv::ogl::RenderModes +@param color Color for all vertices. Will be used if arr doesn't contain color array. +*/ +CV_EXPORTS void render(const Arrays& arr, InputArray indices, int mode = POINTS, Scalar color = Scalar::all(255)); + +/////////////////// CL-GL Interoperability Functions /////////////////// + +namespace ocl { +using namespace cv::ocl; + +// TODO static functions in the Context class +/** @brief Creates OpenCL context from GL. +@return Returns reference to OpenCL Context + */ +CV_EXPORTS Context& initializeContextFromGL(); + +} // namespace cv::ogl::ocl + +/** @brief Converts InputArray to Texture2D object. +@param src - source InputArray. +@param texture - destination Texture2D object. + */ +CV_EXPORTS void convertToGLTexture2D(InputArray src, Texture2D& texture); + +/** @brief Converts Texture2D object to OutputArray. +@param texture - source Texture2D object. +@param dst - destination OutputArray. + */ +CV_EXPORTS void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst); + +/** @brief Maps Buffer object to process on CL side (convert to UMat). + +Function creates CL buffer from GL one, and then constructs UMat that can be used +to process buffer data with OpenCV functions. Note that in current implementation +UMat constructed this way doesn't own corresponding GL buffer object, so it is +the user responsibility to close down CL/GL buffers relationships by explicitly +calling unmapGLBuffer() function. +@param buffer - source Buffer object. +@param accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE). +@return Returns UMat object + */ +CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, int accessFlags = ACCESS_READ|ACCESS_WRITE); + +/** @brief Unmaps Buffer object (releases UMat, previously mapped from Buffer). + +Function must be called explicitly by the user for each UMat previously constructed +by the call to mapGLBuffer() function. +@param u - source UMat, created by mapGLBuffer(). + */ +CV_EXPORTS void unmapGLBuffer(UMat& u); + +//! @} +}} // namespace cv::ogl + +namespace cv { namespace cuda { + +/** @brief Sets a CUDA device and initializes it for the current thread with OpenGL interoperability. + +This function should be explicitly called after OpenGL context creation and before any CUDA calls. +@param device System index of a CUDA device starting with 0. +@ingroup core_opengl + */ +CV_EXPORTS void setGlDevice(int device = 0); + +}} + +//! @cond IGNORED + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +inline +cv::ogl::Buffer::Buffer(int arows, int acols, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0) +{ + create(arows, acols, atype, target, autoRelease); +} + +inline +cv::ogl::Buffer::Buffer(Size asize, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0) +{ + create(asize, atype, target, autoRelease); +} + +inline +void cv::ogl::Buffer::create(Size asize, int atype, Target target, bool autoRelease) +{ + create(asize.height, asize.width, atype, target, autoRelease); +} + +inline +int cv::ogl::Buffer::rows() const +{ + return rows_; +} + +inline +int cv::ogl::Buffer::cols() const +{ + return cols_; +} + +inline +cv::Size cv::ogl::Buffer::size() const +{ + return Size(cols_, rows_); +} + +inline +bool cv::ogl::Buffer::empty() const +{ + return rows_ == 0 || cols_ == 0; +} + +inline +int cv::ogl::Buffer::type() const +{ + return type_; +} + +inline +int cv::ogl::Buffer::depth() const +{ + return CV_MAT_DEPTH(type_); +} + +inline +int cv::ogl::Buffer::channels() const +{ + return CV_MAT_CN(type_); +} + +inline +int cv::ogl::Buffer::elemSize() const +{ + return CV_ELEM_SIZE(type_); +} + +inline +int cv::ogl::Buffer::elemSize1() const +{ + return CV_ELEM_SIZE1(type_); +} + +/////// + +inline +cv::ogl::Texture2D::Texture2D(int arows, int acols, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE) +{ + create(arows, acols, aformat, autoRelease); +} + +inline +cv::ogl::Texture2D::Texture2D(Size asize, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE) +{ + create(asize, aformat, autoRelease); +} + +inline +void cv::ogl::Texture2D::create(Size asize, Format aformat, bool autoRelease) +{ + create(asize.height, asize.width, aformat, autoRelease); +} + +inline +int cv::ogl::Texture2D::rows() const +{ + return rows_; +} + +inline +int cv::ogl::Texture2D::cols() const +{ + return cols_; +} + +inline +cv::Size cv::ogl::Texture2D::size() const +{ + return Size(cols_, rows_); +} + +inline +bool cv::ogl::Texture2D::empty() const +{ + return rows_ == 0 || cols_ == 0; +} + +inline +cv::ogl::Texture2D::Format cv::ogl::Texture2D::format() const +{ + return format_; +} + +/////// + +inline +cv::ogl::Arrays::Arrays() : size_(0) +{ +} + +inline +int cv::ogl::Arrays::size() const +{ + return size_; +} + +inline +bool cv::ogl::Arrays::empty() const +{ + return size_ == 0; +} + +//! @endcond + +#endif /* OPENCV_CORE_OPENGL_HPP */ diff --git a/include/opencv2/core/operations.hpp b/include/opencv2/core/operations.hpp new file mode 100644 index 0000000..082fef4 --- /dev/null +++ b/include/opencv2/core/operations.hpp @@ -0,0 +1,573 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_OPERATIONS_HPP +#define OPENCV_CORE_OPERATIONS_HPP + +#ifndef __cplusplus +# error operations.hpp header must be compiled as C++ +#endif + +#include <cstdio> + +//! @cond IGNORED + +namespace cv +{ + +////////////////////////////// Matx methods depending on core API ///////////////////////////// + +namespace internal +{ + +template<typename _Tp, int m, int n> struct Matx_FastInvOp +{ + bool operator()(const Matx<_Tp, m, n>& a, Matx<_Tp, n, m>& b, int method) const + { + return invert(a, b, method) != 0; + } +}; + +template<typename _Tp, int m> struct Matx_FastInvOp<_Tp, m, m> +{ + bool operator()(const Matx<_Tp, m, m>& a, Matx<_Tp, m, m>& b, int method) const + { + if (method == DECOMP_LU || method == DECOMP_CHOLESKY) + { + Matx<_Tp, m, m> temp = a; + + // assume that b is all 0's on input => make it a unity matrix + for (int i = 0; i < m; i++) + b(i, i) = (_Tp)1; + + if (method == DECOMP_CHOLESKY) + return Cholesky(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m); + + return LU(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m) != 0; + } + else + { + return invert(a, b, method) != 0; + } + } +}; + +template<typename _Tp> struct Matx_FastInvOp<_Tp, 2, 2> +{ + bool operator()(const Matx<_Tp, 2, 2>& a, Matx<_Tp, 2, 2>& b, int /*method*/) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + b(1,1) = a(0,0)*d; + b(0,0) = a(1,1)*d; + b(0,1) = -a(0,1)*d; + b(1,0) = -a(1,0)*d; + return true; + } +}; + +template<typename _Tp> struct Matx_FastInvOp<_Tp, 3, 3> +{ + bool operator()(const Matx<_Tp, 3, 3>& a, Matx<_Tp, 3, 3>& b, int /*method*/) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + b(0,0) = (a(1,1) * a(2,2) - a(1,2) * a(2,1)) * d; + b(0,1) = (a(0,2) * a(2,1) - a(0,1) * a(2,2)) * d; + b(0,2) = (a(0,1) * a(1,2) - a(0,2) * a(1,1)) * d; + + b(1,0) = (a(1,2) * a(2,0) - a(1,0) * a(2,2)) * d; + b(1,1) = (a(0,0) * a(2,2) - a(0,2) * a(2,0)) * d; + b(1,2) = (a(0,2) * a(1,0) - a(0,0) * a(1,2)) * d; + + b(2,0) = (a(1,0) * a(2,1) - a(1,1) * a(2,0)) * d; + b(2,1) = (a(0,1) * a(2,0) - a(0,0) * a(2,1)) * d; + b(2,2) = (a(0,0) * a(1,1) - a(0,1) * a(1,0)) * d; + return true; + } +}; + + +template<typename _Tp, int m, int l, int n> struct Matx_FastSolveOp +{ + bool operator()(const Matx<_Tp, m, l>& a, const Matx<_Tp, m, n>& b, + Matx<_Tp, l, n>& x, int method) const + { + return cv::solve(a, b, x, method); + } +}; + +template<typename _Tp, int m, int n> struct Matx_FastSolveOp<_Tp, m, m, n> +{ + bool operator()(const Matx<_Tp, m, m>& a, const Matx<_Tp, m, n>& b, + Matx<_Tp, m, n>& x, int method) const + { + if (method == DECOMP_LU || method == DECOMP_CHOLESKY) + { + Matx<_Tp, m, m> temp = a; + x = b; + if( method == DECOMP_CHOLESKY ) + return Cholesky(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n); + + return LU(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n) != 0; + } + else + { + return cv::solve(a, b, x, method); + } + } +}; + +template<typename _Tp> struct Matx_FastSolveOp<_Tp, 2, 2, 1> +{ + bool operator()(const Matx<_Tp, 2, 2>& a, const Matx<_Tp, 2, 1>& b, + Matx<_Tp, 2, 1>& x, int) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + x(0) = (b(0)*a(1,1) - b(1)*a(0,1))*d; + x(1) = (b(1)*a(0,0) - b(0)*a(1,0))*d; + return true; + } +}; + +template<typename _Tp> struct Matx_FastSolveOp<_Tp, 3, 3, 1> +{ + bool operator()(const Matx<_Tp, 3, 3>& a, const Matx<_Tp, 3, 1>& b, + Matx<_Tp, 3, 1>& x, int) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + x(0) = d*(b(0)*(a(1,1)*a(2,2) - a(1,2)*a(2,1)) - + a(0,1)*(b(1)*a(2,2) - a(1,2)*b(2)) + + a(0,2)*(b(1)*a(2,1) - a(1,1)*b(2))); + + x(1) = d*(a(0,0)*(b(1)*a(2,2) - a(1,2)*b(2)) - + b(0)*(a(1,0)*a(2,2) - a(1,2)*a(2,0)) + + a(0,2)*(a(1,0)*b(2) - b(1)*a(2,0))); + + x(2) = d*(a(0,0)*(a(1,1)*b(2) - b(1)*a(2,1)) - + a(0,1)*(a(1,0)*b(2) - b(1)*a(2,0)) + + b(0)*(a(1,0)*a(2,1) - a(1,1)*a(2,0))); + return true; + } +}; + +} // internal + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::randu(_Tp a, _Tp b) +{ + Matx<_Tp,m,n> M; + cv::randu(M, Scalar(a), Scalar(b)); + return M; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b) +{ + Matx<_Tp,m,n> M; + cv::randn(M, Scalar(a), Scalar(b)); + return M; +} + +template<typename _Tp, int m, int n> inline +Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method, bool *p_is_ok /*= NULL*/) const +{ + Matx<_Tp, n, m> b; + bool ok = cv::internal::Matx_FastInvOp<_Tp, m, n>()(*this, b, method); + if (p_is_ok) *p_is_ok = ok; + return ok ? b : Matx<_Tp, n, m>::zeros(); +} + +template<typename _Tp, int m, int n> template<int l> inline +Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) const +{ + Matx<_Tp, n, l> x; + bool ok = cv::internal::Matx_FastSolveOp<_Tp, m, n, l>()(*this, rhs, x, method); + return ok ? x : Matx<_Tp, n, l>::zeros(); +} + + + +////////////////////////// Augmenting algebraic & logical operations ////////////////////////// + +#define CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \ + static inline A& operator op (A& a, const B& b) { cvop; return a; } + +#define CV_MAT_AUG_OPERATOR(op, cvop, A, B) \ + CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \ + CV_MAT_AUG_OPERATOR1(op, cvop, const A, B) + +#define CV_MAT_AUG_OPERATOR_T(op, cvop, A, B) \ + template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \ + template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B) + +#define CV_MAT_AUG_OPERATOR_TN(op, cvop, A) \ + template<typename _Tp, int m, int n> static inline A& operator op (A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } \ + template<typename _Tp, int m, int n> static inline const A& operator op (const A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } + +CV_MAT_AUG_OPERATOR (+=, cv::add(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (+=, cv::add(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat) +CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (-=, cv::subtract(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (-=, cv::subtract(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(-=, cv::subtract(a,Mat(b),a), Mat) +CV_MAT_AUG_OPERATOR_TN(-=, cv::subtract(a,Mat(b),a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat, Mat) +CV_MAT_AUG_OPERATOR_T(*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR (*=, a.convertTo(a, -1, b), Mat, double) +CV_MAT_AUG_OPERATOR_T(*=, a.convertTo(a, -1, b), Mat_<_Tp>, double) +CV_MAT_AUG_OPERATOR_TN(*=, cv::gemm(a, Mat(b), 1, Mat(), 0, a, 0), Mat) +CV_MAT_AUG_OPERATOR_TN(*=, cv::gemm(a, Mat(b), 1, Mat(), 0, a, 0), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (/=, cv::divide(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR_T(/=, cv::divide(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(/=, cv::divide(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR (/=, a.convertTo((Mat&)a, -1, 1./b), Mat, double) +CV_MAT_AUG_OPERATOR_T(/=, a.convertTo((Mat&)a, -1, 1./b), Mat_<_Tp>, double) +CV_MAT_AUG_OPERATOR_TN(/=, cv::divide(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(/=, cv::divide(a, Mat(b), a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (&=, cv::bitwise_and(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (&=, cv::bitwise_and(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(&=, cv::bitwise_and(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(&=, cv::bitwise_and(a, Mat(b), a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (|=, cv::bitwise_or(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (|=, cv::bitwise_or(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(|=, cv::bitwise_or(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(|=, cv::bitwise_or(a, Mat(b), a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (^=, cv::bitwise_xor(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (^=, cv::bitwise_xor(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(^=, cv::bitwise_xor(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(^=, cv::bitwise_xor(a, Mat(b), a), Mat_<_Tp>) + +#undef CV_MAT_AUG_OPERATOR_TN +#undef CV_MAT_AUG_OPERATOR_T +#undef CV_MAT_AUG_OPERATOR +#undef CV_MAT_AUG_OPERATOR1 + + + +///////////////////////////////////////////// SVD ///////////////////////////////////////////// + +inline SVD::SVD() {} +inline SVD::SVD( InputArray m, int flags ) { operator ()(m, flags); } +inline void SVD::solveZ( InputArray m, OutputArray _dst ) +{ + Mat mtx = m.getMat(); + SVD svd(mtx, (mtx.rows >= mtx.cols ? 0 : SVD::FULL_UV)); + _dst.create(svd.vt.cols, 1, svd.vt.type()); + Mat dst = _dst.getMat(); + svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst); +} + +template<typename _Tp, int m, int n, int nm> inline void + SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt ) +{ + CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector."); + Mat _a(a, false), _u(u, false), _w(w, false), _vt(vt, false); + SVD::compute(_a, _w, _u, _vt); + CV_Assert(_w.data == (uchar*)&w.val[0] && _u.data == (uchar*)&u.val[0] && _vt.data == (uchar*)&vt.val[0]); +} + +template<typename _Tp, int m, int n, int nm> inline void +SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w ) +{ + CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector."); + Mat _a(a, false), _w(w, false); + SVD::compute(_a, _w); + CV_Assert(_w.data == (uchar*)&w.val[0]); +} + +template<typename _Tp, int m, int n, int nm, int nb> inline void +SVD::backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u, + const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, + Matx<_Tp, n, nb>& dst ) +{ + CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector."); + Mat _u(u, false), _w(w, false), _vt(vt, false), _rhs(rhs, false), _dst(dst, false); + SVD::backSubst(_w, _u, _vt, _rhs, _dst); + CV_Assert(_dst.data == (uchar*)&dst.val[0]); +} + + + +/////////////////////////////////// Multiply-with-Carry RNG /////////////////////////////////// + +inline RNG::RNG() { state = 0xffffffff; } +inline RNG::RNG(uint64 _state) { state = _state ? _state : 0xffffffff; } + +inline RNG::operator uchar() { return (uchar)next(); } +inline RNG::operator schar() { return (schar)next(); } +inline RNG::operator ushort() { return (ushort)next(); } +inline RNG::operator short() { return (short)next(); } +inline RNG::operator int() { return (int)next(); } +inline RNG::operator unsigned() { return next(); } +inline RNG::operator float() { return next()*2.3283064365386962890625e-10f; } +inline RNG::operator double() { unsigned t = next(); return (((uint64)t << 32) | next()) * 5.4210108624275221700372640043497e-20; } + +inline unsigned RNG::operator ()(unsigned N) { return (unsigned)uniform(0,N); } +inline unsigned RNG::operator ()() { return next(); } + +inline int RNG::uniform(int a, int b) { return a == b ? a : (int)(next() % (b - a) + a); } +inline float RNG::uniform(float a, float b) { return ((float)*this)*(b - a) + a; } +inline double RNG::uniform(double a, double b) { return ((double)*this)*(b - a) + a; } + +inline bool RNG::operator ==(const RNG& other) const { return state == other.state; } + +inline unsigned RNG::next() +{ + state = (uint64)(unsigned)state* /*CV_RNG_COEFF*/ 4164903690U + (unsigned)(state >> 32); + return (unsigned)state; +} + +//! returns the next unifomly-distributed random number of the specified type +template<typename _Tp> static inline _Tp randu() +{ + return (_Tp)theRNG(); +} + +///////////////////////////////// Formatted string generation ///////////////////////////////// + +/** @brief Returns a text string formatted using the printf-like expression. + +The function acts like sprintf but forms and returns an STL string. It can be used to form an error +message in the Exception constructor. +@param fmt printf-compatible formatting specifiers. + */ +CV_EXPORTS String format( const char* fmt, ... ); + +///////////////////////////////// Formatted output of cv::Mat ///////////////////////////////// + +static inline +Ptr<Formatted> format(InputArray mtx, int fmt) +{ + return Formatter::get(fmt)->format(mtx.getMat()); +} + +static inline +int print(Ptr<Formatted> fmtd, FILE* stream = stdout) +{ + int written = 0; + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + written += fputs(str, stream); + + return written; +} + +static inline +int print(const Mat& mtx, FILE* stream = stdout) +{ + return print(Formatter::get()->format(mtx), stream); +} + +static inline +int print(const UMat& mtx, FILE* stream = stdout) +{ + return print(Formatter::get()->format(mtx.getMat(ACCESS_READ)), stream); +} + +template<typename _Tp> static inline +int print(const std::vector<Point_<_Tp> >& vec, FILE* stream = stdout) +{ + return print(Formatter::get()->format(Mat(vec)), stream); +} + +template<typename _Tp> static inline +int print(const std::vector<Point3_<_Tp> >& vec, FILE* stream = stdout) +{ + return print(Formatter::get()->format(Mat(vec)), stream); +} + +template<typename _Tp, int m, int n> static inline +int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout) +{ + return print(Formatter::get()->format(cv::Mat(matx)), stream); +} + +//! @endcond + +/****************************************************************************************\ +* Auxiliary algorithms * +\****************************************************************************************/ + +/** @brief Splits an element set into equivalency classes. + +The generic function partition implements an \f$O(N^2)\f$ algorithm for splitting a set of \f$N\f$ elements +into one or more equivalency classes, as described in +<http://en.wikipedia.org/wiki/Disjoint-set_data_structure> . The function returns the number of +equivalency classes. +@param _vec Set of elements stored as a vector. +@param labels Output vector of labels. It contains as many elements as vec. Each label labels[i] is +a 0-based cluster index of `vec[i]`. +@param predicate Equivalence predicate (pointer to a boolean function of two arguments or an +instance of the class that has the method bool operator()(const _Tp& a, const _Tp& b) ). The +predicate returns true when the elements are certainly in the same class, and returns false if they +may or may not be in the same class. +@ingroup core_cluster +*/ +template<typename _Tp, class _EqPredicate> int +partition( const std::vector<_Tp>& _vec, std::vector<int>& labels, + _EqPredicate predicate=_EqPredicate()) +{ + int i, j, N = (int)_vec.size(); + const _Tp* vec = &_vec[0]; + + const int PARENT=0; + const int RANK=1; + + std::vector<int> _nodes(N*2); + int (*nodes)[2] = (int(*)[2])&_nodes[0]; + + // The first O(N) pass: create N single-vertex trees + for(i = 0; i < N; i++) + { + nodes[i][PARENT]=-1; + nodes[i][RANK] = 0; + } + + // The main O(N^2) pass: merge connected components + for( i = 0; i < N; i++ ) + { + int root = i; + + // find root + while( nodes[root][PARENT] >= 0 ) + root = nodes[root][PARENT]; + + for( j = 0; j < N; j++ ) + { + if( i == j || !predicate(vec[i], vec[j])) + continue; + int root2 = j; + + while( nodes[root2][PARENT] >= 0 ) + root2 = nodes[root2][PARENT]; + + if( root2 != root ) + { + // unite both trees + int rank = nodes[root][RANK], rank2 = nodes[root2][RANK]; + if( rank > rank2 ) + nodes[root2][PARENT] = root; + else + { + nodes[root][PARENT] = root2; + nodes[root2][RANK] += rank == rank2; + root = root2; + } + CV_Assert( nodes[root][PARENT] < 0 ); + + int k = j, parent; + + // compress the path from node2 to root + while( (parent = nodes[k][PARENT]) >= 0 ) + { + nodes[k][PARENT] = root; + k = parent; + } + + // compress the path from node to root + k = i; + while( (parent = nodes[k][PARENT]) >= 0 ) + { + nodes[k][PARENT] = root; + k = parent; + } + } + } + } + + // Final O(N) pass: enumerate classes + labels.resize(N); + int nclasses = 0; + + for( i = 0; i < N; i++ ) + { + int root = i; + while( nodes[root][PARENT] >= 0 ) + root = nodes[root][PARENT]; + // re-use the rank as the class label + if( nodes[root][RANK] >= 0 ) + nodes[root][RANK] = ~nclasses++; + labels[i] = ~nodes[root][RANK]; + } + + return nclasses; +} + +} // cv + +#endif diff --git a/include/opencv2/core/optim.hpp b/include/opencv2/core/optim.hpp new file mode 100644 index 0000000..c4729a9 --- /dev/null +++ b/include/opencv2/core/optim.hpp @@ -0,0 +1,302 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the OpenCV Foundation 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. +// +//M*/ + +#ifndef OPENCV_OPTIM_HPP +#define OPENCV_OPTIM_HPP + +#include "opencv2/core.hpp" + +namespace cv +{ + +/** @addtogroup core_optim +The algorithms in this section minimize or maximize function value within specified constraints or +without any constraints. +@{ +*/ + +/** @brief Basic interface for all solvers + */ +class CV_EXPORTS MinProblemSolver : public Algorithm +{ +public: + /** @brief Represents function being optimized + */ + class CV_EXPORTS Function + { + public: + virtual ~Function() {} + virtual int getDims() const = 0; + virtual double getGradientEps() const; + virtual double calc(const double* x) const = 0; + virtual void getGradient(const double* x,double* grad); + }; + + /** @brief Getter for the optimized function. + + The optimized function is represented by Function interface, which requires derivatives to + implement the calc(double*) and getDim() methods to evaluate the function. + + @return Smart-pointer to an object that implements Function interface - it represents the + function that is being optimized. It can be empty, if no function was given so far. + */ + virtual Ptr<Function> getFunction() const = 0; + + /** @brief Setter for the optimized function. + + *It should be called at least once before the call to* minimize(), as default value is not usable. + + @param f The new function to optimize. + */ + virtual void setFunction(const Ptr<Function>& f) = 0; + + /** @brief Getter for the previously set terminal criteria for this algorithm. + + @return Deep copy of the terminal criteria used at the moment. + */ + virtual TermCriteria getTermCriteria() const = 0; + + /** @brief Set terminal criteria for solver. + + This method *is not necessary* to be called before the first call to minimize(), as the default + value is sensible. + + Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when + the function values at the vertices of simplex are within termcrit.epsilon range or simplex + becomes so small that it can enclosed in a box with termcrit.epsilon sides, whatever comes + first. + @param termcrit Terminal criteria to be used, represented as cv::TermCriteria structure. + */ + virtual void setTermCriteria(const TermCriteria& termcrit) = 0; + + /** @brief actually runs the algorithm and performs the minimization. + + The sole input parameter determines the centroid of the starting simplex (roughly, it tells + where to start), all the others (terminal criteria, initial step, function to be minimized) are + supposed to be set via the setters before the call to this method or the default values (not + always sensible) will be used. + + @param x The initial point, that will become a centroid of an initial simplex. After the algorithm + will terminate, it will be set to the point where the algorithm stops, the point of possible + minimum. + @return The value of a function at the point found. + */ + virtual double minimize(InputOutputArray x) = 0; +}; + +/** @brief This class is used to perform the non-linear non-constrained minimization of a function, + +defined on an `n`-dimensional Euclidean space, using the **Nelder-Mead method**, also known as +**downhill simplex method**. The basic idea about the method can be obtained from +<http://en.wikipedia.org/wiki/Nelder-Mead_method>. + +It should be noted, that this method, although deterministic, is rather a heuristic and therefore +may converge to a local minima, not necessary a global one. It is iterative optimization technique, +which at each step uses an information about the values of a function evaluated only at `n+1` +points, arranged as a *simplex* in `n`-dimensional space (hence the second name of the method). At +each step new point is chosen to evaluate function at, obtained value is compared with previous +ones and based on this information simplex changes it's shape , slowly moving to the local minimum. +Thus this method is using *only* function values to make decision, on contrary to, say, Nonlinear +Conjugate Gradient method (which is also implemented in optim). + +Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when the +function values at the vertices of simplex are within termcrit.epsilon range or simplex becomes so +small that it can enclosed in a box with termcrit.epsilon sides, whatever comes first, for some +defined by user positive integer termcrit.maxCount and positive non-integer termcrit.epsilon. + +@note DownhillSolver is a derivative of the abstract interface +cv::MinProblemSolver, which in turn is derived from the Algorithm interface and is used to +encapsulate the functionality, common to all non-linear optimization algorithms in the optim +module. + +@note term criteria should meet following condition: +@code + termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0 +@endcode + */ +class CV_EXPORTS DownhillSolver : public MinProblemSolver +{ +public: + /** @brief Returns the initial step that will be used in downhill simplex algorithm. + + @param step Initial step that will be used in algorithm. Note, that although corresponding setter + accepts column-vectors as well as row-vectors, this method will return a row-vector. + @see DownhillSolver::setInitStep + */ + virtual void getInitStep(OutputArray step) const=0; + + /** @brief Sets the initial step that will be used in downhill simplex algorithm. + + Step, together with initial point (givin in DownhillSolver::minimize) are two `n`-dimensional + vectors that are used to determine the shape of initial simplex. Roughly said, initial point + determines the position of a simplex (it will become simplex's centroid), while step determines the + spread (size in each dimension) of a simplex. To be more precise, if \f$s,x_0\in\mathbb{R}^n\f$ are + the initial step and initial point respectively, the vertices of a simplex will be: + \f$v_0:=x_0-\frac{1}{2} s\f$ and \f$v_i:=x_0+s_i\f$ for \f$i=1,2,\dots,n\f$ where \f$s_i\f$ denotes + projections of the initial step of *n*-th coordinate (the result of projection is treated to be + vector given by \f$s_i:=e_i\cdot\left<e_i\cdot s\right>\f$, where \f$e_i\f$ form canonical basis) + + @param step Initial step that will be used in algorithm. Roughly said, it determines the spread + (size in each dimension) of an initial simplex. + */ + virtual void setInitStep(InputArray step)=0; + + /** @brief This function returns the reference to the ready-to-use DownhillSolver object. + + All the parameters are optional, so this procedure can be called even without parameters at + all. In this case, the default values will be used. As default value for terminal criteria are + the only sensible ones, MinProblemSolver::setFunction() and DownhillSolver::setInitStep() + should be called upon the obtained object, if the respective parameters were not given to + create(). Otherwise, the two ways (give parameters to createDownhillSolver() or miss them out + and call the MinProblemSolver::setFunction() and DownhillSolver::setInitStep()) are absolutely + equivalent (and will drop the same errors in the same way, should invalid input be detected). + @param f Pointer to the function that will be minimized, similarly to the one you submit via + MinProblemSolver::setFunction. + @param initStep Initial step, that will be used to construct the initial simplex, similarly to the one + you submit via MinProblemSolver::setInitStep. + @param termcrit Terminal criteria to the algorithm, similarly to the one you submit via + MinProblemSolver::setTermCriteria. + */ + static Ptr<DownhillSolver> create(const Ptr<MinProblemSolver::Function>& f=Ptr<MinProblemSolver::Function>(), + InputArray initStep=Mat_<double>(1,1,0.0), + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); +}; + +/** @brief This class is used to perform the non-linear non-constrained minimization of a function +with known gradient, + +defined on an *n*-dimensional Euclidean space, using the **Nonlinear Conjugate Gradient method**. +The implementation was done based on the beautifully clear explanatory article [An Introduction to +the Conjugate Gradient Method Without the Agonizing +Pain](http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf) by Jonathan Richard +Shewchuk. The method can be seen as an adaptation of a standard Conjugate Gradient method (see, for +example <http://en.wikipedia.org/wiki/Conjugate_gradient_method>) for numerically solving the +systems of linear equations. + +It should be noted, that this method, although deterministic, is rather a heuristic method and +therefore may converge to a local minima, not necessary a global one. What is even more disastrous, +most of its behaviour is ruled by gradient, therefore it essentially cannot distinguish between +local minima and maxima. Therefore, if it starts sufficiently near to the local maximum, it may +converge to it. Another obvious restriction is that it should be possible to compute the gradient of +a function at any point, thus it is preferable to have analytic expression for gradient and +computational burden should be born by the user. + +The latter responsibility is accompilished via the getGradient method of a +MinProblemSolver::Function interface (which represents function being optimized). This method takes +point a point in *n*-dimensional space (first argument represents the array of coordinates of that +point) and comput its gradient (it should be stored in the second argument as an array). + +@note class ConjGradSolver thus does not add any new methods to the basic MinProblemSolver interface. + +@note term criteria should meet following condition: +@code + termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0 + // or + termcrit.type == TermCriteria::MAX_ITER) && termcrit.maxCount > 0 +@endcode + */ +class CV_EXPORTS ConjGradSolver : public MinProblemSolver +{ +public: + /** @brief This function returns the reference to the ready-to-use ConjGradSolver object. + + All the parameters are optional, so this procedure can be called even without parameters at + all. In this case, the default values will be used. As default value for terminal criteria are + the only sensible ones, MinProblemSolver::setFunction() should be called upon the obtained + object, if the function was not given to create(). Otherwise, the two ways (submit it to + create() or miss it out and call the MinProblemSolver::setFunction()) are absolutely equivalent + (and will drop the same errors in the same way, should invalid input be detected). + @param f Pointer to the function that will be minimized, similarly to the one you submit via + MinProblemSolver::setFunction. + @param termcrit Terminal criteria to the algorithm, similarly to the one you submit via + MinProblemSolver::setTermCriteria. + */ + static Ptr<ConjGradSolver> create(const Ptr<MinProblemSolver::Function>& f=Ptr<ConjGradSolver::Function>(), + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); +}; + +//! return codes for cv::solveLP() function +enum SolveLPResult +{ + SOLVELP_UNBOUNDED = -2, //!< problem is unbounded (target function can achieve arbitrary high values) + SOLVELP_UNFEASIBLE = -1, //!< problem is unfeasible (there are no points that satisfy all the constraints imposed) + SOLVELP_SINGLE = 0, //!< there is only one maximum for target function + SOLVELP_MULTI = 1 //!< there are multiple maxima for target function - the arbitrary one is returned +}; + +/** @brief Solve given (non-integer) linear programming problem using the Simplex Algorithm (Simplex Method). + +What we mean here by "linear programming problem" (or LP problem, for short) can be formulated as: + +\f[\mbox{Maximize } c\cdot x\\ + \mbox{Subject to:}\\ + Ax\leq b\\ + x\geq 0\f] + +Where \f$c\f$ is fixed `1`-by-`n` row-vector, \f$A\f$ is fixed `m`-by-`n` matrix, \f$b\f$ is fixed `m`-by-`1` +column vector and \f$x\f$ is an arbitrary `n`-by-`1` column vector, which satisfies the constraints. + +Simplex algorithm is one of many algorithms that are designed to handle this sort of problems +efficiently. Although it is not optimal in theoretical sense (there exist algorithms that can solve +any problem written as above in polynomial time, while simplex method degenerates to exponential +time for some special cases), it is well-studied, easy to implement and is shown to work well for +real-life purposes. + +The particular implementation is taken almost verbatim from **Introduction to Algorithms, third +edition** by T. H. Cormen, C. E. Leiserson, R. L. Rivest and Clifford Stein. In particular, the +Bland's rule <http://en.wikipedia.org/wiki/Bland%27s_rule> is used to prevent cycling. + +@param Func This row-vector corresponds to \f$c\f$ in the LP problem formulation (see above). It should +contain 32- or 64-bit floating point numbers. As a convenience, column-vector may be also submitted, +in the latter case it is understood to correspond to \f$c^T\f$. +@param Constr `m`-by-`n+1` matrix, whose rightmost column corresponds to \f$b\f$ in formulation above +and the remaining to \f$A\f$. It should contain 32- or 64-bit floating point numbers. +@param z The solution will be returned here as a column-vector - it corresponds to \f$c\f$ in the +formulation above. It will contain 64-bit floating point numbers. +@return One of cv::SolveLPResult + */ +CV_EXPORTS_W int solveLP(const Mat& Func, const Mat& Constr, Mat& z); + +//! @} + +}// cv + +#endif diff --git a/include/opencv2/core/ovx.hpp b/include/opencv2/core/ovx.hpp new file mode 100644 index 0000000..8bb7d54 --- /dev/null +++ b/include/opencv2/core/ovx.hpp @@ -0,0 +1,28 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2016, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. + +// OpenVX related definitions and declarations + +#pragma once +#ifndef OPENCV_OVX_HPP +#define OPENCV_OVX_HPP + +#include "cvdef.h" + +namespace cv +{ +/// Check if use of OpenVX is possible +CV_EXPORTS_W bool haveOpenVX(); + +/// Check if use of OpenVX is enabled +CV_EXPORTS_W bool useOpenVX(); + +/// Enable/disable use of OpenVX +CV_EXPORTS_W void setUseOpenVX(bool flag); +} // namespace cv + +#endif // OPENCV_OVX_HPP diff --git a/include/opencv2/core/persistence.hpp b/include/opencv2/core/persistence.hpp new file mode 100644 index 0000000..126393f --- /dev/null +++ b/include/opencv2/core/persistence.hpp @@ -0,0 +1,1366 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_PERSISTENCE_HPP +#define OPENCV_CORE_PERSISTENCE_HPP + +#ifndef CV_DOXYGEN +/// Define to support persistence legacy formats +#define CV__LEGACY_PERSISTENCE +#endif + +#ifndef __cplusplus +# error persistence.hpp header must be compiled as C++ +#endif + +//! @addtogroup core_c +//! @{ + +/** @brief "black box" representation of the file storage associated with a file on disk. + +Several functions that are described below take CvFileStorage\* as inputs and allow the user to +save or to load hierarchical collections that consist of scalar values, standard CXCore objects +(such as matrices, sequences, graphs), and user-defined objects. + +OpenCV can read and write data in XML (<http://www.w3c.org/XML>), YAML (<http://www.yaml.org>) or +JSON (<http://www.json.org/>) formats. Below is an example of 3x3 floating-point identity matrix A, +stored in XML and YAML files +using CXCore functions: +XML: +@code{.xml} + <?xml version="1.0"> + <opencv_storage> + <A type_id="opencv-matrix"> + <rows>3</rows> + <cols>3</cols> + <dt>f</dt> + <data>1. 0. 0. 0. 1. 0. 0. 0. 1.</data> + </A> + </opencv_storage> +@endcode +YAML: +@code{.yaml} + %YAML:1.0 + A: !!opencv-matrix + rows: 3 + cols: 3 + dt: f + data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1.] +@endcode +As it can be seen from the examples, XML uses nested tags to represent hierarchy, while YAML uses +indentation for that purpose (similar to the Python programming language). + +The same functions can read and write data in both formats; the particular format is determined by +the extension of the opened file, ".xml" for XML files, ".yml" or ".yaml" for YAML and ".json" for +JSON. + */ +typedef struct CvFileStorage CvFileStorage; +typedef struct CvFileNode CvFileNode; +typedef struct CvMat CvMat; +typedef struct CvMatND CvMatND; + +//! @} core_c + +#include "opencv2/core/types.hpp" +#include "opencv2/core/mat.hpp" + +namespace cv { + +/** @addtogroup core_xml + +XML/YAML/JSON file storages. {#xml_storage} +======================= +Writing to a file storage. +-------------------------- +You can store and then restore various OpenCV data structures to/from XML (<http://www.w3c.org/XML>), +YAML (<http://www.yaml.org>) or JSON (<http://www.json.org/>) formats. Also, it is possible to store +and load arbitrarily complex data structures, which include OpenCV data structures, as well as +primitive data types (integer and floating-point numbers and text strings) as their elements. + +Use the following procedure to write something to XML, YAML or JSON: +-# Create new FileStorage and open it for writing. It can be done with a single call to +FileStorage::FileStorage constructor that takes a filename, or you can use the default constructor +and then call FileStorage::open. Format of the file (XML, YAML or JSON) is determined from the filename +extension (".xml", ".yml"/".yaml" and ".json", respectively) +-# Write all the data you want using the streaming operator `<<`, just like in the case of STL +streams. +-# Close the file using FileStorage::release. FileStorage destructor also closes the file. + +Here is an example: +@code + #include "opencv2/opencv.hpp" + #include <time.h> + + using namespace cv; + + int main(int, char** argv) + { + FileStorage fs("test.yml", FileStorage::WRITE); + + fs << "frameCount" << 5; + time_t rawtime; time(&rawtime); + fs << "calibrationDate" << asctime(localtime(&rawtime)); + Mat cameraMatrix = (Mat_<double>(3,3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1); + Mat distCoeffs = (Mat_<double>(5,1) << 0.1, 0.01, -0.001, 0, 0); + fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs; + fs << "features" << "["; + for( int i = 0; i < 3; i++ ) + { + int x = rand() % 640; + int y = rand() % 480; + uchar lbp = rand() % 256; + + fs << "{:" << "x" << x << "y" << y << "lbp" << "[:"; + for( int j = 0; j < 8; j++ ) + fs << ((lbp >> j) & 1); + fs << "]" << "}"; + } + fs << "]"; + fs.release(); + return 0; + } +@endcode +The sample above stores to YML an integer, a text string (calibration date), 2 matrices, and a custom +structure "feature", which includes feature coordinates and LBP (local binary pattern) value. Here +is output of the sample: +@code{.yaml} +%YAML:1.0 +frameCount: 5 +calibrationDate: "Fri Jun 17 14:09:29 2011\n" +cameraMatrix: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 1000., 0., 320., 0., 1000., 240., 0., 0., 1. ] +distCoeffs: !!opencv-matrix + rows: 5 + cols: 1 + dt: d + data: [ 1.0000000000000001e-01, 1.0000000000000000e-02, + -1.0000000000000000e-03, 0., 0. ] +features: + - { x:167, y:49, lbp:[ 1, 0, 0, 1, 1, 0, 1, 1 ] } + - { x:298, y:130, lbp:[ 0, 0, 0, 1, 0, 0, 1, 1 ] } + - { x:344, y:158, lbp:[ 1, 1, 0, 0, 0, 0, 1, 0 ] } +@endcode + +As an exercise, you can replace ".yml" with ".xml" or ".json" in the sample above and see, how the +corresponding XML file will look like. + +Several things can be noted by looking at the sample code and the output: + +- The produced YAML (and XML/JSON) consists of heterogeneous collections that can be nested. There are + 2 types of collections: named collections (mappings) and unnamed collections (sequences). In mappings + each element has a name and is accessed by name. This is similar to structures and std::map in + C/C++ and dictionaries in Python. In sequences elements do not have names, they are accessed by + indices. This is similar to arrays and std::vector in C/C++ and lists, tuples in Python. + "Heterogeneous" means that elements of each single collection can have different types. + + Top-level collection in YAML/XML/JSON is a mapping. Each matrix is stored as a mapping, and the matrix + elements are stored as a sequence. Then, there is a sequence of features, where each feature is + represented a mapping, and lbp value in a nested sequence. + +- When you write to a mapping (a structure), you write element name followed by its value. When you + write to a sequence, you simply write the elements one by one. OpenCV data structures (such as + cv::Mat) are written in absolutely the same way as simple C data structures - using `<<` + operator. + +- To write a mapping, you first write the special string `{` to the storage, then write the + elements as pairs (`fs << <element_name> << <element_value>`) and then write the closing + `}`. + +- To write a sequence, you first write the special string `[`, then write the elements, then + write the closing `]`. + +- In YAML/JSON (but not XML), mappings and sequences can be written in a compact Python-like inline + form. In the sample above matrix elements, as well as each feature, including its lbp value, is + stored in such inline form. To store a mapping/sequence in a compact form, put `:` after the + opening character, e.g. use `{:` instead of `{` and `[:` instead of `[`. When the + data is written to XML, those extra `:` are ignored. + +Reading data from a file storage. +--------------------------------- +To read the previously written XML, YAML or JSON file, do the following: +-# Open the file storage using FileStorage::FileStorage constructor or FileStorage::open method. + In the current implementation the whole file is parsed and the whole representation of file + storage is built in memory as a hierarchy of file nodes (see FileNode) + +-# Read the data you are interested in. Use FileStorage::operator [], FileNode::operator [] + and/or FileNodeIterator. + +-# Close the storage using FileStorage::release. + +Here is how to read the file created by the code sample above: +@code + FileStorage fs2("test.yml", FileStorage::READ); + + // first method: use (type) operator on FileNode. + int frameCount = (int)fs2["frameCount"]; + + String date; + // second method: use FileNode::operator >> + fs2["calibrationDate"] >> date; + + Mat cameraMatrix2, distCoeffs2; + fs2["cameraMatrix"] >> cameraMatrix2; + fs2["distCoeffs"] >> distCoeffs2; + + cout << "frameCount: " << frameCount << endl + << "calibration date: " << date << endl + << "camera matrix: " << cameraMatrix2 << endl + << "distortion coeffs: " << distCoeffs2 << endl; + + FileNode features = fs2["features"]; + FileNodeIterator it = features.begin(), it_end = features.end(); + int idx = 0; + std::vector<uchar> lbpval; + + // iterate through a sequence using FileNodeIterator + for( ; it != it_end; ++it, idx++ ) + { + cout << "feature #" << idx << ": "; + cout << "x=" << (int)(*it)["x"] << ", y=" << (int)(*it)["y"] << ", lbp: ("; + // you can also easily read numerical arrays using FileNode >> std::vector operator. + (*it)["lbp"] >> lbpval; + for( int i = 0; i < (int)lbpval.size(); i++ ) + cout << " " << (int)lbpval[i]; + cout << ")" << endl; + } + fs2.release(); +@endcode + +Format specification {#format_spec} +-------------------- +`([count]{u|c|w|s|i|f|d})`... where the characters correspond to fundamental C++ types: +- `u` 8-bit unsigned number +- `c` 8-bit signed number +- `w` 16-bit unsigned number +- `s` 16-bit signed number +- `i` 32-bit signed number +- `f` single precision floating-point number +- `d` double precision floating-point number +- `r` pointer, 32 lower bits of which are written as a signed integer. The type can be used to + store structures with links between the elements. + +`count` is the optional counter of values of a given type. For example, `2if` means that each array +element is a structure of 2 integers, followed by a single-precision floating-point number. The +equivalent notations of the above specification are `iif`, `2i1f` and so forth. Other examples: `u` +means that the array consists of bytes, and `2d` means the array consists of pairs of doubles. + +@see @ref samples/cpp/filestorage.cpp +*/ + +//! @{ + +/** @example samples/cpp/filestorage.cpp +A complete example using the FileStorage interface +*/ + +////////////////////////// XML & YAML I/O ////////////////////////// + +class CV_EXPORTS FileNode; +class CV_EXPORTS FileNodeIterator; + +/** @brief XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or +reading data to/from a file. + */ +class CV_EXPORTS_W FileStorage +{ +public: + //! file storage mode + enum Mode + { + READ = 0, //!< value, open the file for reading + WRITE = 1, //!< value, open the file for writing + APPEND = 2, //!< value, open the file for appending + MEMORY = 4, //!< flag, read data from source or write data to the internal buffer (which is + //!< returned by FileStorage::release) + FORMAT_MASK = (7<<3), //!< mask for format flags + FORMAT_AUTO = 0, //!< flag, auto format + FORMAT_XML = (1<<3), //!< flag, XML format + FORMAT_YAML = (2<<3), //!< flag, YAML format + FORMAT_JSON = (3<<3), //!< flag, JSON format + + BASE64 = 64, //!< flag, write rawdata in Base64 by default. (consider using WRITE_BASE64) + WRITE_BASE64 = BASE64 | WRITE, //!< flag, enable both WRITE and BASE64 + }; + enum + { + UNDEFINED = 0, + VALUE_EXPECTED = 1, + NAME_EXPECTED = 2, + INSIDE_MAP = 4 + }; + + /** @brief The constructors. + + The full constructor opens the file. Alternatively you can use the default constructor and then + call FileStorage::open. + */ + CV_WRAP FileStorage(); + + /** @overload + @copydoc open() + */ + CV_WRAP FileStorage(const String& filename, int flags, const String& encoding=String()); + + /** @overload */ + FileStorage(CvFileStorage* fs, bool owning=true); + + //! the destructor. calls release() + virtual ~FileStorage(); + + /** @brief Opens a file. + + See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release + before opening the file. + @param filename Name of the file to open or the text string to read the data from. + Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON + respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both + FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify + the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. + You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to + FileStorage::BASE64 flag. + @param flags Mode of operation. One of FileStorage::Mode + @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and + you should use 8-bit encoding instead of it. + */ + CV_WRAP virtual bool open(const String& filename, int flags, const String& encoding=String()); + + /** @brief Checks whether the file is opened. + + @returns true if the object is associated with the current file and false otherwise. It is a + good practice to call this method after you tried to open a file. + */ + CV_WRAP virtual bool isOpened() const; + + /** @brief Closes the file and releases all the memory buffers. + + Call this method after all I/O operations with the storage are finished. + */ + CV_WRAP virtual void release(); + + /** @brief Closes the file and releases all the memory buffers. + + Call this method after all I/O operations with the storage are finished. If the storage was + opened for writing data and FileStorage::WRITE was specified + */ + CV_WRAP virtual String releaseAndGetString(); + + /** @brief Returns the first element of the top-level mapping. + @returns The first element of the top-level mapping. + */ + CV_WRAP FileNode getFirstTopLevelNode() const; + + /** @brief Returns the top-level mapping + @param streamidx Zero-based index of the stream. In most cases there is only one stream in the file. + However, YAML supports multiple streams and so there can be several. + @returns The top-level mapping. + */ + CV_WRAP FileNode root(int streamidx=0) const; + + /** @brief Returns the specified element of the top-level mapping. + @param nodename Name of the file node. + @returns Node with the given name. + */ + FileNode operator[](const String& nodename) const; + + /** @overload */ + CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; + + /** @brief Returns the obsolete C FileStorage structure. + @returns Pointer to the underlying C FileStorage structure + */ + CvFileStorage* operator *() { return fs.get(); } + + /** @overload */ + const CvFileStorage* operator *() const { return fs.get(); } + + /** @brief Writes multiple numbers. + + Writes one or more numbers of the specified format to the currently written structure. Usually it is + more convenient to use operator `<<` instead of this method. + @param fmt Specification of each array element, see @ref format_spec "format specification" + @param vec Pointer to the written array. + @param len Number of the uchar elements to write. + */ + void writeRaw( const String& fmt, const uchar* vec, size_t len ); + + /** @brief Writes the registered C structure (CvMat, CvMatND, CvSeq). + @param name Name of the written object. + @param obj Pointer to the object. + @see ocvWrite for details. + */ + void writeObj( const String& name, const void* obj ); + + /** + * @brief Simplified writing API to use with bindings. + * @param name Name of the written object + * @param val Value of the written object + */ + CV_WRAP void write(const String& name, int val); + /// @overload + CV_WRAP void write(const String& name, double val); + /// @overload + CV_WRAP void write(const String& name, const String& val); + /// @overload + CV_WRAP void write(const String& name, InputArray val); + + /** @brief Writes a comment. + + The function writes a comment into file storage. The comments are skipped when the storage is read. + @param comment The written comment, single-line or multi-line + @param append If true, the function tries to put the comment at the end of current line. + Else if the comment is multi-line, or if it does not fit at the end of the current + line, the comment starts a new line. + */ + CV_WRAP void writeComment(const String& comment, bool append = false); + + /** @brief Returns the normalized object name for the specified name of a file. + @param filename Name of a file + @returns The normalized object name. + */ + static String getDefaultObjectName(const String& filename); + + /** @brief Returns the current format. + * @returns The current format, see FileStorage::Mode + */ + CV_WRAP int getFormat() const; + + Ptr<CvFileStorage> fs; //!< the underlying C FileStorage structure + String elname; //!< the currently written element + std::vector<char> structs; //!< the stack of written structures + int state; //!< the writer state +}; + +template<> CV_EXPORTS void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const; + +/** @brief File Storage Node class. + +The node is used to store each and every element of the file storage opened for reading. When +XML/YAML file is read, it is first parsed and stored in the memory as a hierarchical collection of +nodes. Each node can be a "leaf" that is contain a single number or a string, or be a collection of +other nodes. There can be named collections (mappings) where each element has a name and it is +accessed by a name, and ordered collections (sequences) where elements do not have names but rather +accessed by index. Type of the file node can be determined using FileNode::type method. + +Note that file nodes are only used for navigating file storages opened for reading. When a file +storage is opened for writing, no data is stored in memory after it is written. + */ +class CV_EXPORTS_W_SIMPLE FileNode +{ +public: + //! type of the file storage node + enum Type + { + NONE = 0, //!< empty node + INT = 1, //!< an integer + REAL = 2, //!< floating-point number + FLOAT = REAL, //!< synonym or REAL + STR = 3, //!< text string in UTF-8 encoding + STRING = STR, //!< synonym for STR + REF = 4, //!< integer of size size_t. Typically used for storing complex dynamic structures where some elements reference the others + SEQ = 5, //!< sequence + MAP = 6, //!< mapping + TYPE_MASK = 7, + FLOW = 8, //!< compact representation of a sequence or mapping. Used only by YAML writer + USER = 16, //!< a registered object (e.g. a matrix) + EMPTY = 32, //!< empty structure (sequence or mapping) + NAMED = 64 //!< the node has a name (i.e. it is element of a mapping) + }; + /** @brief The constructors. + + These constructors are used to create a default file node, construct it from obsolete structures or + from the another file node. + */ + CV_WRAP FileNode(); + + /** @overload + @param fs Pointer to the obsolete file storage structure. + @param node File node to be used as initialization for the created file node. + */ + FileNode(const CvFileStorage* fs, const CvFileNode* node); + + /** @overload + @param node File node to be used as initialization for the created file node. + */ + FileNode(const FileNode& node); + + /** @brief Returns element of a mapping node or a sequence node. + @param nodename Name of an element in the mapping node. + @returns Returns the element with the given identifier. + */ + FileNode operator[](const String& nodename) const; + + /** @overload + @param nodename Name of an element in the mapping node. + */ + CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; + + /** @overload + @param i Index of an element in the sequence node. + */ + CV_WRAP_AS(at) FileNode operator[](int i) const; + + /** @brief Returns keys of a mapping node. + @returns Keys of a mapping node. + */ + CV_WRAP std::vector<String> keys() const; + + /** @brief Returns type of the node. + @returns Type of the node. See FileNode::Type + */ + CV_WRAP int type() const; + + //! returns true if the node is empty + CV_WRAP bool empty() const; + //! returns true if the node is a "none" object + CV_WRAP bool isNone() const; + //! returns true if the node is a sequence + CV_WRAP bool isSeq() const; + //! returns true if the node is a mapping + CV_WRAP bool isMap() const; + //! returns true if the node is an integer + CV_WRAP bool isInt() const; + //! returns true if the node is a floating-point number + CV_WRAP bool isReal() const; + //! returns true if the node is a text string + CV_WRAP bool isString() const; + //! returns true if the node has a name + CV_WRAP bool isNamed() const; + //! returns the node name or an empty string if the node is nameless + CV_WRAP String name() const; + //! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise. + CV_WRAP size_t size() const; + //! returns the node content as an integer. If the node stores floating-point number, it is rounded. + operator int() const; + //! returns the node content as float + operator float() const; + //! returns the node content as double + operator double() const; + //! returns the node content as text string + operator String() const; + operator std::string() const; + + //! returns pointer to the underlying file node + CvFileNode* operator *(); + //! returns pointer to the underlying file node + const CvFileNode* operator* () const; + + //! returns iterator pointing to the first node element + FileNodeIterator begin() const; + //! returns iterator pointing to the element following the last node element + FileNodeIterator end() const; + + /** @brief Reads node elements to the buffer with the specified format. + + Usually it is more convenient to use operator `>>` instead of this method. + @param fmt Specification of each array element. See @ref format_spec "format specification" + @param vec Pointer to the destination array. + @param len Number of elements to read. If it is greater than number of remaining elements then all + of them will be read. + */ + void readRaw( const String& fmt, uchar* vec, size_t len ) const; + + //! reads the registered object and returns pointer to it + void* readObj() const; + + //! Simplified reading API to use with bindings. + CV_WRAP double real() const; + //! Simplified reading API to use with bindings. + CV_WRAP String string() const; + //! Simplified reading API to use with bindings. + CV_WRAP Mat mat() const; + + // do not use wrapper pointer classes for better efficiency + const CvFileStorage* fs; + const CvFileNode* node; +}; + + +/** @brief used to iterate through sequences and mappings. + +A standard STL notation, with node.begin(), node.end() denoting the beginning and the end of a +sequence, stored in node. See the data reading sample in the beginning of the section. + */ +class CV_EXPORTS FileNodeIterator +{ +public: + /** @brief The constructors. + + These constructors are used to create a default iterator, set it to specific element in a file node + or construct it from another iterator. + */ + FileNodeIterator(); + + /** @overload + @param fs File storage for the iterator. + @param node File node for the iterator. + @param ofs Index of the element in the node. The created iterator will point to this element. + */ + FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0); + + /** @overload + @param it Iterator to be used as initialization for the created iterator. + */ + FileNodeIterator(const FileNodeIterator& it); + + //! returns the currently observed element + FileNode operator *() const; + //! accesses the currently observed element methods + FileNode operator ->() const; + + //! moves iterator to the next node + FileNodeIterator& operator ++ (); + //! moves iterator to the next node + FileNodeIterator operator ++ (int); + //! moves iterator to the previous node + FileNodeIterator& operator -- (); + //! moves iterator to the previous node + FileNodeIterator operator -- (int); + //! moves iterator forward by the specified offset (possibly negative) + FileNodeIterator& operator += (int ofs); + //! moves iterator backward by the specified offset (possibly negative) + FileNodeIterator& operator -= (int ofs); + + /** @brief Reads node elements to the buffer with the specified format. + + Usually it is more convenient to use operator `>>` instead of this method. + @param fmt Specification of each array element. See @ref format_spec "format specification" + @param vec Pointer to the destination array. + @param maxCount Number of elements to read. If it is greater than number of remaining elements then + all of them will be read. + */ + FileNodeIterator& readRaw( const String& fmt, uchar* vec, + size_t maxCount=(size_t)INT_MAX ); + + struct SeqReader + { + int header_size; + void* seq; /* sequence, beign read; CvSeq */ + void* block; /* current block; CvSeqBlock */ + schar* ptr; /* pointer to element be read next */ + schar* block_min; /* pointer to the beginning of block */ + schar* block_max; /* pointer to the end of block */ + int delta_index;/* = seq->first->start_index */ + schar* prev_elem; /* pointer to previous element */ + }; + + const CvFileStorage* fs; + const CvFileNode* container; + SeqReader reader; + size_t remaining; +}; + +//! @} core_xml + +/////////////////// XML & YAML I/O implementation ////////////////// + +//! @relates cv::FileStorage +//! @{ + +CV_EXPORTS void write( FileStorage& fs, const String& name, int value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, float value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, double value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, const String& value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, const Mat& value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value ); +#ifdef CV__LEGACY_PERSISTENCE +CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<KeyPoint>& value); +CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<DMatch>& value); +#endif + +CV_EXPORTS void writeScalar( FileStorage& fs, int value ); +CV_EXPORTS void writeScalar( FileStorage& fs, float value ); +CV_EXPORTS void writeScalar( FileStorage& fs, double value ); +CV_EXPORTS void writeScalar( FileStorage& fs, const String& value ); + +//! @} + +//! @relates cv::FileNode +//! @{ + +CV_EXPORTS void read(const FileNode& node, int& value, int default_value); +CV_EXPORTS void read(const FileNode& node, float& value, float default_value); +CV_EXPORTS void read(const FileNode& node, double& value, double default_value); +CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value); +CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value); +CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() ); +CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); +#ifdef CV__LEGACY_PERSISTENCE +CV_EXPORTS void read(const FileNode& node, std::vector<KeyPoint>& keypoints); +CV_EXPORTS void read(const FileNode& node, std::vector<DMatch>& matches); +#endif +CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value); +CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value); + +template<typename _Tp> static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Point_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template<typename _Tp> static inline void read(const FileNode& node, Point3_<_Tp>& value, const Point3_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 3 ? default_value : Point3_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2])); +} + +template<typename _Tp> static inline void read(const FileNode& node, Size_<_Tp>& value, const Size_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Size_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template<typename _Tp> static inline void read(const FileNode& node, Complex<_Tp>& value, const Complex<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Complex<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template<typename _Tp> static inline void read(const FileNode& node, Rect_<_Tp>& value, const Rect_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 4 ? default_value : Rect_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); +} + +template<typename _Tp, int cn> static inline void read(const FileNode& node, Vec<_Tp, cn>& value, const Vec<_Tp, cn>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]); +} + +template<typename _Tp> static inline void read(const FileNode& node, Scalar_<_Tp>& value, const Scalar_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 4 ? default_value : Scalar_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); +} + +static inline void read(const FileNode& node, Range& value, const Range& default_value) +{ + Point2i temp(value.start, value.end); const Point2i default_temp = Point2i(default_value.start, default_value.end); + read(node, temp, default_temp); + value.start = temp.x; value.end = temp.y; +} + +//! @} + +/** @brief Writes string to a file storage. +@relates cv::FileStorage + */ +CV_EXPORTS FileStorage& operator << (FileStorage& fs, const String& str); + +//! @cond IGNORED + +namespace internal +{ + class CV_EXPORTS WriteStructContext + { + public: + WriteStructContext(FileStorage& _fs, const String& name, int flags, const String& typeName = String()); + ~WriteStructContext(); + private: + FileStorage* fs; + }; + + template<typename _Tp, int numflag> class VecWriterProxy + { + public: + VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} + void operator()(const std::vector<_Tp>& vec) const + { + size_t count = vec.size(); + for (size_t i = 0; i < count; i++) + write(*fs, vec[i]); + } + private: + FileStorage* fs; + }; + + template<typename _Tp> class VecWriterProxy<_Tp, 1> + { + public: + VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} + void operator()(const std::vector<_Tp>& vec) const + { + int _fmt = traits::SafeFmt<_Tp>::fmt; + char fmt[] = { (char)((_fmt >> 8) + '1'), (char)_fmt, '\0' }; + fs->writeRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, vec.size() * sizeof(_Tp)); + } + private: + FileStorage* fs; + }; + + template<typename _Tp, int numflag> class VecReaderProxy + { + public: + VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} + void operator()(std::vector<_Tp>& vec, size_t count) const + { + count = std::min(count, it->remaining); + vec.resize(count); + for (size_t i = 0; i < count; i++, ++(*it)) + read(**it, vec[i], _Tp()); + } + private: + FileNodeIterator* it; + }; + + template<typename _Tp> class VecReaderProxy<_Tp, 1> + { + public: + VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} + void operator()(std::vector<_Tp>& vec, size_t count) const + { + size_t remaining = it->remaining; + size_t cn = DataType<_Tp>::channels; + int _fmt = traits::SafeFmt<_Tp>::fmt; + CV_Assert((_fmt >> 8) < 9); + char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' }; + CV_Assert((remaining % cn) == 0); + size_t remaining1 = remaining / cn; + count = count < remaining1 ? count : remaining1; + vec.resize(count); + it->readRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp)); + } + private: + FileNodeIterator* it; + }; + +} // internal + +//! @endcond + +//! @relates cv::FileStorage +//! @{ + +template<typename _Tp> static inline +void write(FileStorage& fs, const _Tp& value) +{ + write(fs, String(), value); +} + +template<> inline +void write( FileStorage& fs, const int& value ) +{ + writeScalar(fs, value); +} + +template<> inline +void write( FileStorage& fs, const float& value ) +{ + writeScalar(fs, value); +} + +template<> inline +void write( FileStorage& fs, const double& value ) +{ + writeScalar(fs, value); +} + +template<> inline +void write( FileStorage& fs, const String& value ) +{ + writeScalar(fs, value); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const Point_<_Tp>& pt ) +{ + write(fs, pt.x); + write(fs, pt.y); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const Point3_<_Tp>& pt ) +{ + write(fs, pt.x); + write(fs, pt.y); + write(fs, pt.z); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const Size_<_Tp>& sz ) +{ + write(fs, sz.width); + write(fs, sz.height); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const Complex<_Tp>& c ) +{ + write(fs, c.re); + write(fs, c.im); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const Rect_<_Tp>& r ) +{ + write(fs, r.x); + write(fs, r.y); + write(fs, r.width); + write(fs, r.height); +} + +template<typename _Tp, int cn> static inline +void write(FileStorage& fs, const Vec<_Tp, cn>& v ) +{ + for(int i = 0; i < cn; i++) + write(fs, v.val[i]); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const Scalar_<_Tp>& s ) +{ + write(fs, s.val[0]); + write(fs, s.val[1]); + write(fs, s.val[2]); + write(fs, s.val[3]); +} + +static inline +void write(FileStorage& fs, const Range& r ) +{ + write(fs, r.start); + write(fs, r.end); +} + +template<typename _Tp> static inline +void write( FileStorage& fs, const std::vector<_Tp>& vec ) +{ + cv::internal::VecWriterProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> w(&fs); + w(vec); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const String& name, const Point_<_Tp>& pt ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, pt); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const String& name, const Point3_<_Tp>& pt ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, pt); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const String& name, const Size_<_Tp>& sz ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, sz); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const String& name, const Complex<_Tp>& c ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, c); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const String& name, const Rect_<_Tp>& r ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, r); +} + +template<typename _Tp, int cn> static inline +void write(FileStorage& fs, const String& name, const Vec<_Tp, cn>& v ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, v); +} + +template<typename _Tp> static inline +void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, s); +} + +static inline +void write(FileStorage& fs, const String& name, const Range& r ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, r); +} + +static inline +void write(FileStorage& fs, const String& name, const KeyPoint& kpt) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, kpt.pt.x); + write(fs, kpt.pt.y); + write(fs, kpt.size); + write(fs, kpt.angle); + write(fs, kpt.response); + write(fs, kpt.octave); + write(fs, kpt.class_id); +} + +static inline +void write(FileStorage& fs, const String& name, const DMatch& m) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, m.queryIdx); + write(fs, m.trainIdx); + write(fs, m.imgIdx); + write(fs, m.distance); +} + +template<typename _Tp> static inline +void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); + write(fs, vec); +} + +template<typename _Tp> static inline +void write( FileStorage& fs, const String& name, const std::vector< std::vector<_Tp> >& vec ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ); + for(size_t i = 0; i < vec.size(); i++) + { + cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); + write(fs, vec[i]); + } +} + +#ifdef CV__LEGACY_PERSISTENCE +// This code is not needed anymore, but it is preserved here to keep source compatibility +// Implementation is similar to templates instantiations +static inline void write(FileStorage& fs, const KeyPoint& kpt) { write(fs, String(), kpt); } +static inline void write(FileStorage& fs, const DMatch& m) { write(fs, String(), m); } +static inline void write(FileStorage& fs, const std::vector<KeyPoint>& vec) +{ + cv::internal::VecWriterProxy<KeyPoint, 0> w(&fs); + w(vec); +} +static inline void write(FileStorage& fs, const std::vector<DMatch>& vec) +{ + cv::internal::VecWriterProxy<DMatch, 0> w(&fs); + w(vec); + +} +#endif + +//! @} FileStorage + +//! @relates cv::FileNode +//! @{ + +static inline +void read(const FileNode& node, bool& value, bool default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = temp != 0; +} + +static inline +void read(const FileNode& node, uchar& value, uchar default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast<uchar>(temp); +} + +static inline +void read(const FileNode& node, schar& value, schar default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast<schar>(temp); +} + +static inline +void read(const FileNode& node, ushort& value, ushort default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast<ushort>(temp); +} + +static inline +void read(const FileNode& node, short& value, short default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast<short>(temp); +} + +template<typename _Tp> static inline +void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_t)INT_MAX ) +{ + cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it); + r(vec, maxCount); +} + +template<typename _Tp> static inline +void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& default_value = std::vector<_Tp>() ) +{ + if(!node.node) + vec = default_value; + else + { + FileNodeIterator it = node.begin(); + read( it, vec ); + } +} + +static inline +void read( const FileNode& node, std::vector<KeyPoint>& vec, const std::vector<KeyPoint>& default_value ) +{ + if(!node.node) + vec = default_value; + else + read(node, vec); +} + +static inline +void read( const FileNode& node, std::vector<DMatch>& vec, const std::vector<DMatch>& default_value ) +{ + if(!node.node) + vec = default_value; + else + read(node, vec); +} + +//! @} FileNode + +//! @relates cv::FileStorage +//! @{ + +/** @brief Writes data to a file storage. + */ +template<typename _Tp> static inline +FileStorage& operator << (FileStorage& fs, const _Tp& value) +{ + if( !fs.isOpened() ) + return fs; + if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP ) + CV_Error( Error::StsError, "No element name has been given" ); + write( fs, fs.elname, value ); + if( fs.state & FileStorage::INSIDE_MAP ) + fs.state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP; + return fs; +} + +/** @brief Writes data to a file storage. + */ +static inline +FileStorage& operator << (FileStorage& fs, const char* str) +{ + return (fs << String(str)); +} + +/** @brief Writes data to a file storage. + */ +static inline +FileStorage& operator << (FileStorage& fs, char* value) +{ + return (fs << String(value)); +} + +//! @} FileStorage + +//! @relates cv::FileNodeIterator +//! @{ + +/** @brief Reads data from a file storage. + */ +template<typename _Tp> static inline +FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value) +{ + read( *it, value, _Tp()); + return ++it; +} + +/** @brief Reads data from a file storage. + */ +template<typename _Tp> static inline +FileNodeIterator& operator >> (FileNodeIterator& it, std::vector<_Tp>& vec) +{ + cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it); + r(vec, (size_t)INT_MAX); + return it; +} + +//! @} FileNodeIterator + +//! @relates cv::FileNode +//! @{ + +/** @brief Reads data from a file storage. + */ +template<typename _Tp> static inline +void operator >> (const FileNode& n, _Tp& value) +{ + read( n, value, _Tp()); +} + +/** @brief Reads data from a file storage. + */ +template<typename _Tp> static inline +void operator >> (const FileNode& n, std::vector<_Tp>& vec) +{ + FileNodeIterator it = n.begin(); + it >> vec; +} + +/** @brief Reads KeyPoint from a file storage. +*/ +//It needs special handling because it contains two types of fields, int & float. +static inline +void operator >> (const FileNode& n, KeyPoint& kpt) +{ + FileNodeIterator it = n.begin(); + it >> kpt.pt.x >> kpt.pt.y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave >> kpt.class_id; +} + +#ifdef CV__LEGACY_PERSISTENCE +static inline +void operator >> (const FileNode& n, std::vector<KeyPoint>& vec) +{ + read(n, vec); +} +static inline +void operator >> (const FileNode& n, std::vector<DMatch>& vec) +{ + read(n, vec); +} +#endif + +/** @brief Reads DMatch from a file storage. +*/ +//It needs special handling because it contains two types of fields, int & float. +static inline +void operator >> (const FileNode& n, DMatch& m) +{ + FileNodeIterator it = n.begin(); + it >> m.queryIdx >> m.trainIdx >> m.imgIdx >> m.distance; +} + +//! @} FileNode + +//! @relates cv::FileNodeIterator +//! @{ + +static inline +bool operator == (const FileNodeIterator& it1, const FileNodeIterator& it2) +{ + return it1.fs == it2.fs && it1.container == it2.container && + it1.reader.ptr == it2.reader.ptr && it1.remaining == it2.remaining; +} + +static inline +bool operator != (const FileNodeIterator& it1, const FileNodeIterator& it2) +{ + return !(it1 == it2); +} + +static inline +ptrdiff_t operator - (const FileNodeIterator& it1, const FileNodeIterator& it2) +{ + return it2.remaining - it1.remaining; +} + +static inline +bool operator < (const FileNodeIterator& it1, const FileNodeIterator& it2) +{ + return it1.remaining > it2.remaining; +} + +//! @} FileNodeIterator + +//! @cond IGNORED + +inline FileNode FileStorage::getFirstTopLevelNode() const { FileNode r = root(); FileNodeIterator it = r.begin(); return it != r.end() ? *it : FileNode(); } +inline FileNode::FileNode() : fs(0), node(0) {} +inline FileNode::FileNode(const CvFileStorage* _fs, const CvFileNode* _node) : fs(_fs), node(_node) {} +inline FileNode::FileNode(const FileNode& _node) : fs(_node.fs), node(_node.node) {} +inline bool FileNode::empty() const { return node == 0; } +inline bool FileNode::isNone() const { return type() == NONE; } +inline bool FileNode::isSeq() const { return type() == SEQ; } +inline bool FileNode::isMap() const { return type() == MAP; } +inline bool FileNode::isInt() const { return type() == INT; } +inline bool FileNode::isReal() const { return type() == REAL; } +inline bool FileNode::isString() const { return type() == STR; } +inline CvFileNode* FileNode::operator *() { return (CvFileNode*)node; } +inline const CvFileNode* FileNode::operator* () const { return node; } +inline FileNode::operator int() const { int value; read(*this, value, 0); return value; } +inline FileNode::operator float() const { float value; read(*this, value, 0.f); return value; } +inline FileNode::operator double() const { double value; read(*this, value, 0.); return value; } +inline FileNode::operator String() const { String value; read(*this, value, value); return value; } +inline double FileNode::real() const { return double(*this); } +inline String FileNode::string() const { return String(*this); } +inline Mat FileNode::mat() const { Mat value; read(*this, value, value); return value; } +inline FileNodeIterator FileNode::begin() const { return FileNodeIterator(fs, node); } +inline FileNodeIterator FileNode::end() const { return FileNodeIterator(fs, node, size()); } +inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const { begin().readRaw( fmt, vec, len ); } +inline FileNode FileNodeIterator::operator *() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } +inline FileNode FileNodeIterator::operator ->() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } +inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, *this); } + +//! @endcond + + +CV_EXPORTS void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); + +CV_EXPORTS void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); + +CV_EXPORTS void cvEndWriteRawData_Base64(::CvFileStorage * fs); + +CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); + +CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat); + +} // cv + +#endif // OPENCV_CORE_PERSISTENCE_HPP diff --git a/include/opencv2/core/ptr.inl.hpp b/include/opencv2/core/ptr.inl.hpp new file mode 100644 index 0000000..466f634 --- /dev/null +++ b/include/opencv2/core/ptr.inl.hpp @@ -0,0 +1,379 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, NVIDIA Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef OPENCV_CORE_PTR_INL_HPP +#define OPENCV_CORE_PTR_INL_HPP + +#include <algorithm> + +//! @cond IGNORED + +namespace cv { + +template<typename Y> +void DefaultDeleter<Y>::operator () (Y* p) const +{ + delete p; +} + +namespace detail +{ + +struct PtrOwner +{ + PtrOwner() : refCount(1) + {} + + void incRef() + { + CV_XADD(&refCount, 1); + } + + void decRef() + { + if (CV_XADD(&refCount, -1) == 1) deleteSelf(); + } + +protected: + /* This doesn't really need to be virtual, since PtrOwner is never deleted + directly, but it doesn't hurt and it helps avoid warnings. */ + virtual ~PtrOwner() + {} + + virtual void deleteSelf() = 0; + +private: + unsigned int refCount; + + // noncopyable + PtrOwner(const PtrOwner&); + PtrOwner& operator = (const PtrOwner&); +}; + +template<typename Y, typename D> +struct PtrOwnerImpl CV_FINAL : PtrOwner +{ + PtrOwnerImpl(Y* p, D d) : owned(p), deleter(d) + {} + + void deleteSelf() CV_OVERRIDE + { + deleter(owned); + delete this; + } + +private: + Y* owned; + D deleter; +}; + + +} + +template<typename T> +Ptr<T>::Ptr() : owner(NULL), stored(NULL) +{} + +template<typename T> +template<typename Y> +Ptr<T>::Ptr(Y* p) + : owner(p + ? new detail::PtrOwnerImpl<Y, DefaultDeleter<Y> >(p, DefaultDeleter<Y>()) + : NULL), + stored(p) +{} + +template<typename T> +template<typename Y, typename D> +Ptr<T>::Ptr(Y* p, D d) + : owner(p + ? new detail::PtrOwnerImpl<Y, D>(p, d) + : NULL), + stored(p) +{} + +template<typename T> +Ptr<T>::Ptr(const Ptr& o) : owner(o.owner), stored(o.stored) +{ + if (owner) owner->incRef(); +} + +template<typename T> +template<typename Y> +Ptr<T>::Ptr(const Ptr<Y>& o) : owner(o.owner), stored(o.stored) +{ + if (owner) owner->incRef(); +} + +template<typename T> +template<typename Y> +Ptr<T>::Ptr(const Ptr<Y>& o, T* p) : owner(o.owner), stored(p) +{ + if (owner) owner->incRef(); +} + +template<typename T> +Ptr<T>::~Ptr() +{ + release(); +} + +template<typename T> +Ptr<T>& Ptr<T>::operator = (const Ptr<T>& o) +{ + Ptr(o).swap(*this); + return *this; +} + +template<typename T> +template<typename Y> +Ptr<T>& Ptr<T>::operator = (const Ptr<Y>& o) +{ + Ptr(o).swap(*this); + return *this; +} + +template<typename T> +void Ptr<T>::release() +{ + if (owner) owner->decRef(); + owner = NULL; + stored = NULL; +} + +template<typename T> +template<typename Y> +void Ptr<T>::reset(Y* p) +{ + Ptr(p).swap(*this); +} + +template<typename T> +template<typename Y, typename D> +void Ptr<T>::reset(Y* p, D d) +{ + Ptr(p, d).swap(*this); +} + +template<typename T> +void Ptr<T>::swap(Ptr<T>& o) +{ + std::swap(owner, o.owner); + std::swap(stored, o.stored); +} + +template<typename T> +T* Ptr<T>::get() const +{ + return stored; +} + +template<typename T> +typename detail::RefOrVoid<T>::type Ptr<T>::operator * () const +{ + return *stored; +} + +template<typename T> +T* Ptr<T>::operator -> () const +{ + return stored; +} + +template<typename T> +Ptr<T>::operator T* () const +{ + return stored; +} + + +template<typename T> +bool Ptr<T>::empty() const +{ + return !stored; +} + +template<typename T> +template<typename Y> +Ptr<Y> Ptr<T>::staticCast() const +{ + return Ptr<Y>(*this, static_cast<Y*>(stored)); +} + +template<typename T> +template<typename Y> +Ptr<Y> Ptr<T>::constCast() const +{ + return Ptr<Y>(*this, const_cast<Y*>(stored)); +} + +template<typename T> +template<typename Y> +Ptr<Y> Ptr<T>::dynamicCast() const +{ + return Ptr<Y>(*this, dynamic_cast<Y*>(stored)); +} + +#ifdef CV_CXX_MOVE_SEMANTICS + +template<typename T> +Ptr<T>::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored) +{ + o.owner = NULL; + o.stored = NULL; +} + +template<typename T> +Ptr<T>& Ptr<T>::operator = (Ptr<T>&& o) +{ + if (this == &o) + return *this; + + release(); + owner = o.owner; + stored = o.stored; + o.owner = NULL; + o.stored = NULL; + return *this; +} + +#endif + + +template<typename T> +void swap(Ptr<T>& ptr1, Ptr<T>& ptr2){ + ptr1.swap(ptr2); +} + +template<typename T> +bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2) +{ + return ptr1.get() == ptr2.get(); +} + +template<typename T> +bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2) +{ + return ptr1.get() != ptr2.get(); +} + +template<typename T> +Ptr<T> makePtr() +{ + return Ptr<T>(new T()); +} + +template<typename T, typename A1> +Ptr<T> makePtr(const A1& a1) +{ + return Ptr<T>(new T(a1)); +} + +template<typename T, typename A1, typename A2> +Ptr<T> makePtr(const A1& a1, const A2& a2) +{ + return Ptr<T>(new T(a1, a2)); +} + +template<typename T, typename A1, typename A2, typename A3> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3) +{ + return Ptr<T>(new T(a1, a2, a3)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4) +{ + return Ptr<T>(new T(a1, a2, a3, a4)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10, typename A11> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); +} + +template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10, typename A11, typename A12> +Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11, const A12& a12) +{ + return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); +} +} // namespace cv + +//! @endcond + +#endif // OPENCV_CORE_PTR_INL_HPP diff --git a/include/opencv2/core/saturate.hpp b/include/opencv2/core/saturate.hpp new file mode 100644 index 0000000..118599f --- /dev/null +++ b/include/opencv2/core/saturate.hpp @@ -0,0 +1,165 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2014, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_SATURATE_HPP +#define OPENCV_CORE_SATURATE_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/fast_math.hpp" + +namespace cv +{ + +//! @addtogroup core_utils +//! @{ + +/////////////// saturate_cast (used in image & signal processing) /////////////////// + +/** @brief Template function for accurate conversion from one primitive type to another. + + The function saturate_cast resembles the standard C++ cast operations, such as static_cast\<T\>() + and others. It perform an efficient and accurate conversion from one primitive type to another + (see the introduction chapter). saturate in the name means that when the input value v is out of the + range of the target type, the result is not formed just by taking low bits of the input, but instead + the value is clipped. For example: + @code + uchar a = saturate_cast<uchar>(-100); // a = 0 (UCHAR_MIN) + short b = saturate_cast<short>(33333.33333); // b = 32767 (SHRT_MAX) + @endcode + Such clipping is done when the target type is unsigned char , signed char , unsigned short or + signed short . For 32-bit integers, no clipping is done. + + When the parameter is a floating-point value and the target type is an integer (8-, 16- or 32-bit), + the floating-point value is first rounded to the nearest integer and then clipped if needed (when + the target type is 8- or 16-bit). + + This operation is used in the simplest or most complex image processing functions in OpenCV. + + @param v Function parameter. + @sa add, subtract, multiply, divide, Mat::convertTo + */ +template<typename _Tp> static inline _Tp saturate_cast(uchar v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(schar v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(ushort v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(short v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(unsigned v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(int v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(float v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(double v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(int64 v) { return _Tp(v); } +/** @overload */ +template<typename _Tp> static inline _Tp saturate_cast(uint64 v) { return _Tp(v); } + +template<> inline uchar saturate_cast<uchar>(schar v) { return (uchar)std::max((int)v, 0); } +template<> inline uchar saturate_cast<uchar>(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); } +template<> inline uchar saturate_cast<uchar>(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } +template<> inline uchar saturate_cast<uchar>(short v) { return saturate_cast<uchar>((int)v); } +template<> inline uchar saturate_cast<uchar>(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); } +template<> inline uchar saturate_cast<uchar>(float v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); } +template<> inline uchar saturate_cast<uchar>(double v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); } +template<> inline uchar saturate_cast<uchar>(int64 v) { return (uchar)((uint64)v <= (uint64)UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } +template<> inline uchar saturate_cast<uchar>(uint64 v) { return (uchar)std::min(v, (uint64)UCHAR_MAX); } + +template<> inline schar saturate_cast<schar>(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); } +template<> inline schar saturate_cast<schar>(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); } +template<> inline schar saturate_cast<schar>(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } +template<> inline schar saturate_cast<schar>(short v) { return saturate_cast<schar>((int)v); } +template<> inline schar saturate_cast<schar>(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); } +template<> inline schar saturate_cast<schar>(float v) { int iv = cvRound(v); return saturate_cast<schar>(iv); } +template<> inline schar saturate_cast<schar>(double v) { int iv = cvRound(v); return saturate_cast<schar>(iv); } +template<> inline schar saturate_cast<schar>(int64 v) { return (schar)((uint64)((int64)v-SCHAR_MIN) <= (uint64)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } +template<> inline schar saturate_cast<schar>(uint64 v) { return (schar)std::min(v, (uint64)SCHAR_MAX); } + +template<> inline ushort saturate_cast<ushort>(schar v) { return (ushort)std::max((int)v, 0); } +template<> inline ushort saturate_cast<ushort>(short v) { return (ushort)std::max((int)v, 0); } +template<> inline ushort saturate_cast<ushort>(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } +template<> inline ushort saturate_cast<ushort>(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); } +template<> inline ushort saturate_cast<ushort>(float v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); } +template<> inline ushort saturate_cast<ushort>(double v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); } +template<> inline ushort saturate_cast<ushort>(int64 v) { return (ushort)((uint64)v <= (uint64)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } +template<> inline ushort saturate_cast<ushort>(uint64 v) { return (ushort)std::min(v, (uint64)USHRT_MAX); } + +template<> inline short saturate_cast<short>(ushort v) { return (short)std::min((int)v, SHRT_MAX); } +template<> inline short saturate_cast<short>(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } +template<> inline short saturate_cast<short>(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); } +template<> inline short saturate_cast<short>(float v) { int iv = cvRound(v); return saturate_cast<short>(iv); } +template<> inline short saturate_cast<short>(double v) { int iv = cvRound(v); return saturate_cast<short>(iv); } +template<> inline short saturate_cast<short>(int64 v) { return (short)((uint64)((int64)v - SHRT_MIN) <= (uint64)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } +template<> inline short saturate_cast<short>(uint64 v) { return (short)std::min(v, (uint64)SHRT_MAX); } + +template<> inline int saturate_cast<int>(unsigned v) { return (int)std::min(v, (unsigned)INT_MAX); } +template<> inline int saturate_cast<int>(int64 v) { return (int)((uint64)(v - INT_MIN) <= (uint64)UINT_MAX ? v : v > 0 ? INT_MAX : INT_MIN); } +template<> inline int saturate_cast<int>(uint64 v) { return (int)std::min(v, (uint64)INT_MAX); } +template<> inline int saturate_cast<int>(float v) { return cvRound(v); } +template<> inline int saturate_cast<int>(double v) { return cvRound(v); } + +template<> inline unsigned saturate_cast<unsigned>(schar v) { return (unsigned)std::max(v, (schar)0); } +template<> inline unsigned saturate_cast<unsigned>(short v) { return (unsigned)std::max(v, (short)0); } +template<> inline unsigned saturate_cast<unsigned>(int v) { return (unsigned)std::max(v, (int)0); } +template<> inline unsigned saturate_cast<unsigned>(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); } +template<> inline unsigned saturate_cast<unsigned>(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); } +// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. +template<> inline unsigned saturate_cast<unsigned>(float v) { return static_cast<unsigned>(cvRound(v)); } +template<> inline unsigned saturate_cast<unsigned>(double v) { return static_cast<unsigned>(cvRound(v)); } + +template<> inline uint64 saturate_cast<uint64>(schar v) { return (uint64)std::max(v, (schar)0); } +template<> inline uint64 saturate_cast<uint64>(short v) { return (uint64)std::max(v, (short)0); } +template<> inline uint64 saturate_cast<uint64>(int v) { return (uint64)std::max(v, (int)0); } +template<> inline uint64 saturate_cast<uint64>(int64 v) { return (uint64)std::max(v, (int64)0); } + +template<> inline int64 saturate_cast<int64>(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); } + +//! @} + +} // cv + +#endif // OPENCV_CORE_SATURATE_HPP diff --git a/include/opencv2/core/softfloat.hpp b/include/opencv2/core/softfloat.hpp new file mode 100644 index 0000000..5470980 --- /dev/null +++ b/include/opencv2/core/softfloat.hpp @@ -0,0 +1,514 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This file is based on files from package issued with the following license: + +/*============================================================================ + +This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3c, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions, and the following disclaimer. + + 2. 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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 THE REGENTS 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. + +=============================================================================*/ + +#pragma once +#ifndef softfloat_h +#define softfloat_h 1 + +#include "cvdef.h" + +namespace cv +{ + +/** @addtogroup core_utils_softfloat + + [SoftFloat](http://www.jhauser.us/arithmetic/SoftFloat.html) is a software implementation + of floating-point calculations according to IEEE 754 standard. + All calculations are done in integers, that's why they are machine-independent and bit-exact. + This library can be useful in accuracy-critical parts like look-up tables generation, tests, etc. + OpenCV contains a subset of SoftFloat partially rewritten to C++. + + ### Types + + There are two basic types: @ref softfloat and @ref softdouble. + These types are binary compatible with float and double types respectively + and support conversions to/from them. + Other types from original SoftFloat library like fp16 or fp128 were thrown away + as well as quiet/signaling NaN support, on-the-fly rounding mode switch + and exception flags (though exceptions can be implemented in the future). + + ### Operations + + Both types support the following: + - Construction from signed and unsigned 32-bit and 64 integers, + float/double or raw binary representation + - Conversions between each other, to float or double and to int + using @ref cvRound, @ref cvTrunc, @ref cvFloor, @ref cvCeil or a bunch of + saturate_cast functions + - Add, subtract, multiply, divide, remainder, square root, FMA with absolute precision + - Comparison operations + - Explicit sign, exponent and significand manipulation through get/set methods, + number state indicators (isInf, isNan, isSubnormal) + - Type-specific constants like eps, minimum/maximum value, best pi approximation, etc. + - min(), max(), abs(), exp(), log() and pow() functions + +*/ +//! @{ + +struct softfloat; +struct softdouble; + +struct CV_EXPORTS softfloat +{ +public: + /** @brief Default constructor */ + softfloat() { v = 0; } + /** @brief Copy constructor */ + softfloat( const softfloat& c) { v = c.v; } + /** @brief Assign constructor */ + softfloat& operator=( const softfloat& c ) + { + if(&c != this) v = c.v; + return *this; + } + /** @brief Construct from raw + + Builds new value from raw binary representation + */ + static const softfloat fromRaw( const uint32_t a ) { softfloat x; x.v = a; return x; } + + /** @brief Construct from integer */ + explicit softfloat( const uint32_t ); + explicit softfloat( const uint64_t ); + explicit softfloat( const int32_t ); + explicit softfloat( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softfloat( const int a ) { *this = softfloat(static_cast<int32_t>(a)); } +#endif + + /** @brief Construct from float */ + explicit softfloat( const float a ) { Cv32suf s; s.f = a; v = s.u; } + + /** @brief Type casts */ + operator softdouble() const; + operator float() const { Cv32suf s; s.u = v; return s.f; } + + /** @brief Basic arithmetics */ + softfloat operator + (const softfloat&) const; + softfloat operator - (const softfloat&) const; + softfloat operator * (const softfloat&) const; + softfloat operator / (const softfloat&) const; + softfloat operator - () const { softfloat x; x.v = v ^ (1U << 31); return x; } + + /** @brief Remainder operator + + A quote from original SoftFloat manual: + + > The IEEE Standard remainder operation computes the value + > a - n * b, where n is the integer closest to a / b. + > If a / b is exactly halfway between two integers, n is the even integer + > closest to a / b. The IEEE Standard’s remainder operation is always exact and so requires no rounding. + > Depending on the relative magnitudes of the operands, the remainder functions + > can take considerably longer to execute than the other SoftFloat functions. + > This is an inherent characteristic of the remainder operation itself and is not a flaw + > in the SoftFloat implementation. + */ + softfloat operator % (const softfloat&) const; + + softfloat& operator += (const softfloat& a) { *this = *this + a; return *this; } + softfloat& operator -= (const softfloat& a) { *this = *this - a; return *this; } + softfloat& operator *= (const softfloat& a) { *this = *this * a; return *this; } + softfloat& operator /= (const softfloat& a) { *this = *this / a; return *this; } + softfloat& operator %= (const softfloat& a) { *this = *this % a; return *this; } + + /** @brief Comparison operations + + - Any operation with NaN produces false + + The only exception is when x is NaN: x != y for any y. + - Positive and negative zeros are equal + */ + bool operator == ( const softfloat& ) const; + bool operator != ( const softfloat& ) const; + bool operator > ( const softfloat& ) const; + bool operator >= ( const softfloat& ) const; + bool operator < ( const softfloat& ) const; + bool operator <= ( const softfloat& ) const; + + /** @brief NaN state indicator */ + inline bool isNaN() const { return (v & 0x7fffffff) > 0x7f800000; } + /** @brief Inf state indicator */ + inline bool isInf() const { return (v & 0x7fffffff) == 0x7f800000; } + /** @brief Subnormal number indicator */ + inline bool isSubnormal() const { return ((v >> 23) & 0xFF) == 0; } + + /** @brief Get sign bit */ + inline bool getSign() const { return (v >> 31) != 0; } + /** @brief Construct a copy with new sign bit */ + inline softfloat setSign(bool sign) const { softfloat x; x.v = (v & ((1U << 31) - 1)) | ((uint32_t)sign << 31); return x; } + /** @brief Get 0-based exponent */ + inline int getExp() const { return ((v >> 23) & 0xFF) - 127; } + /** @brief Construct a copy with new 0-based exponent */ + inline softfloat setExp(int e) const { softfloat x; x.v = (v & 0x807fffff) | (((e + 127) & 0xFF) << 23 ); return x; } + + /** @brief Get a fraction part + + Returns a number 1 <= x < 2 with the same significand + */ + inline softfloat getFrac() const + { + uint_fast32_t vv = (v & 0x007fffff) | (127 << 23); + return softfloat::fromRaw(vv); + } + /** @brief Construct a copy with provided significand + + Constructs a copy of a number with significand taken from parameter + */ + inline softfloat setFrac(const softfloat& s) const + { + softfloat x; + x.v = (v & 0xff800000) | (s.v & 0x007fffff); + return x; + } + + /** @brief Zero constant */ + static softfloat zero() { return softfloat::fromRaw( 0 ); } + /** @brief Positive infinity constant */ + static softfloat inf() { return softfloat::fromRaw( 0xFF << 23 ); } + /** @brief Default NaN constant */ + static softfloat nan() { return softfloat::fromRaw( 0x7fffffff ); } + /** @brief One constant */ + static softfloat one() { return softfloat::fromRaw( 127 << 23 ); } + /** @brief Smallest normalized value */ + static softfloat min() { return softfloat::fromRaw( 0x01 << 23 ); } + /** @brief Difference between 1 and next representable value */ + static softfloat eps() { return softfloat::fromRaw( (127 - 23) << 23 ); } + /** @brief Biggest finite value */ + static softfloat max() { return softfloat::fromRaw( (0xFF << 23) - 1 ); } + /** @brief Correct pi approximation */ + static softfloat pi() { return softfloat::fromRaw( 0x40490fdb ); } + + uint32_t v; +}; + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ + +struct CV_EXPORTS softdouble +{ +public: + /** @brief Default constructor */ + softdouble() : v(0) { } + /** @brief Copy constructor */ + softdouble( const softdouble& c) { v = c.v; } + /** @brief Assign constructor */ + softdouble& operator=( const softdouble& c ) + { + if(&c != this) v = c.v; + return *this; + } + /** @brief Construct from raw + + Builds new value from raw binary representation + */ + static softdouble fromRaw( const uint64_t a ) { softdouble x; x.v = a; return x; } + + /** @brief Construct from integer */ + explicit softdouble( const uint32_t ); + explicit softdouble( const uint64_t ); + explicit softdouble( const int32_t ); + explicit softdouble( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softdouble( const int a ) { *this = softdouble(static_cast<int32_t>(a)); } +#endif + + /** @brief Construct from double */ + explicit softdouble( const double a ) { Cv64suf s; s.f = a; v = s.u; } + + /** @brief Type casts */ + operator softfloat() const; + operator double() const { Cv64suf s; s.u = v; return s.f; } + + /** @brief Basic arithmetics */ + softdouble operator + (const softdouble&) const; + softdouble operator - (const softdouble&) const; + softdouble operator * (const softdouble&) const; + softdouble operator / (const softdouble&) const; + softdouble operator - () const { softdouble x; x.v = v ^ (1ULL << 63); return x; } + + /** @brief Remainder operator + + A quote from original SoftFloat manual: + + > The IEEE Standard remainder operation computes the value + > a - n * b, where n is the integer closest to a / b. + > If a / b is exactly halfway between two integers, n is the even integer + > closest to a / b. The IEEE Standard’s remainder operation is always exact and so requires no rounding. + > Depending on the relative magnitudes of the operands, the remainder functions + > can take considerably longer to execute than the other SoftFloat functions. + > This is an inherent characteristic of the remainder operation itself and is not a flaw + > in the SoftFloat implementation. + */ + softdouble operator % (const softdouble&) const; + + softdouble& operator += (const softdouble& a) { *this = *this + a; return *this; } + softdouble& operator -= (const softdouble& a) { *this = *this - a; return *this; } + softdouble& operator *= (const softdouble& a) { *this = *this * a; return *this; } + softdouble& operator /= (const softdouble& a) { *this = *this / a; return *this; } + softdouble& operator %= (const softdouble& a) { *this = *this % a; return *this; } + + /** @brief Comparison operations + + - Any operation with NaN produces false + + The only exception is when x is NaN: x != y for any y. + - Positive and negative zeros are equal + */ + bool operator == ( const softdouble& ) const; + bool operator != ( const softdouble& ) const; + bool operator > ( const softdouble& ) const; + bool operator >= ( const softdouble& ) const; + bool operator < ( const softdouble& ) const; + bool operator <= ( const softdouble& ) const; + + /** @brief NaN state indicator */ + inline bool isNaN() const { return (v & 0x7fffffffffffffff) > 0x7ff0000000000000; } + /** @brief Inf state indicator */ + inline bool isInf() const { return (v & 0x7fffffffffffffff) == 0x7ff0000000000000; } + /** @brief Subnormal number indicator */ + inline bool isSubnormal() const { return ((v >> 52) & 0x7FF) == 0; } + + /** @brief Get sign bit */ + inline bool getSign() const { return (v >> 63) != 0; } + /** @brief Construct a copy with new sign bit */ + softdouble setSign(bool sign) const { softdouble x; x.v = (v & ((1ULL << 63) - 1)) | ((uint_fast64_t)(sign) << 63); return x; } + /** @brief Get 0-based exponent */ + inline int getExp() const { return ((v >> 52) & 0x7FF) - 1023; } + /** @brief Construct a copy with new 0-based exponent */ + inline softdouble setExp(int e) const + { + softdouble x; + x.v = (v & 0x800FFFFFFFFFFFFF) | ((uint_fast64_t)((e + 1023) & 0x7FF) << 52); + return x; + } + + /** @brief Get a fraction part + + Returns a number 1 <= x < 2 with the same significand + */ + inline softdouble getFrac() const + { + uint_fast64_t vv = (v & 0x000FFFFFFFFFFFFF) | ((uint_fast64_t)(1023) << 52); + return softdouble::fromRaw(vv); + } + /** @brief Construct a copy with provided significand + + Constructs a copy of a number with significand taken from parameter + */ + inline softdouble setFrac(const softdouble& s) const + { + softdouble x; + x.v = (v & 0xFFF0000000000000) | (s.v & 0x000FFFFFFFFFFFFF); + return x; + } + + /** @brief Zero constant */ + static softdouble zero() { return softdouble::fromRaw( 0 ); } + /** @brief Positive infinity constant */ + static softdouble inf() { return softdouble::fromRaw( (uint_fast64_t)(0x7FF) << 52 ); } + /** @brief Default NaN constant */ + static softdouble nan() { return softdouble::fromRaw( CV_BIG_INT(0x7FFFFFFFFFFFFFFF) ); } + /** @brief One constant */ + static softdouble one() { return softdouble::fromRaw( (uint_fast64_t)( 1023) << 52 ); } + /** @brief Smallest normalized value */ + static softdouble min() { return softdouble::fromRaw( (uint_fast64_t)( 0x01) << 52 ); } + /** @brief Difference between 1 and next representable value */ + static softdouble eps() { return softdouble::fromRaw( (uint_fast64_t)( 1023 - 52 ) << 52 ); } + /** @brief Biggest finite value */ + static softdouble max() { return softdouble::fromRaw( ((uint_fast64_t)(0x7FF) << 52) - 1 ); } + /** @brief Correct pi approximation */ + static softdouble pi() { return softdouble::fromRaw( CV_BIG_INT(0x400921FB54442D18) ); } + + uint64_t v; +}; + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ + +/** @brief Fused Multiplication and Addition + +Computes (a*b)+c with single rounding +*/ +CV_EXPORTS softfloat mulAdd( const softfloat& a, const softfloat& b, const softfloat & c); +CV_EXPORTS softdouble mulAdd( const softdouble& a, const softdouble& b, const softdouble& c); + +/** @brief Square root */ +CV_EXPORTS softfloat sqrt( const softfloat& a ); +CV_EXPORTS softdouble sqrt( const softdouble& a ); +} + +/*---------------------------------------------------------------------------- +| Ported from OpenCV and added for usability +*----------------------------------------------------------------------------*/ + +/** @brief Truncates number to integer with minimum magnitude */ +CV_EXPORTS int cvTrunc(const cv::softfloat& a); +CV_EXPORTS int cvTrunc(const cv::softdouble& a); + +/** @brief Rounds a number to nearest even integer */ +CV_EXPORTS int cvRound(const cv::softfloat& a); +CV_EXPORTS int cvRound(const cv::softdouble& a); + +/** @brief Rounds a number to nearest even long long integer */ +CV_EXPORTS int64_t cvRound64(const cv::softdouble& a); + +/** @brief Rounds a number down to integer */ +CV_EXPORTS int cvFloor(const cv::softfloat& a); +CV_EXPORTS int cvFloor(const cv::softdouble& a); + +/** @brief Rounds number up to integer */ +CV_EXPORTS int cvCeil(const cv::softfloat& a); +CV_EXPORTS int cvCeil(const cv::softdouble& a); + +namespace cv +{ +/** @brief Saturate casts */ +template<typename _Tp> static inline _Tp saturate_cast(softfloat a) { return _Tp(a); } +template<typename _Tp> static inline _Tp saturate_cast(softdouble a) { return _Tp(a); } + +template<> inline uchar saturate_cast<uchar>(softfloat a) { return (uchar)std::max(std::min(cvRound(a), (int)UCHAR_MAX), 0); } +template<> inline uchar saturate_cast<uchar>(softdouble a) { return (uchar)std::max(std::min(cvRound(a), (int)UCHAR_MAX), 0); } + +template<> inline schar saturate_cast<schar>(softfloat a) { return (schar)std::min(std::max(cvRound(a), (int)SCHAR_MIN), (int)SCHAR_MAX); } +template<> inline schar saturate_cast<schar>(softdouble a) { return (schar)std::min(std::max(cvRound(a), (int)SCHAR_MIN), (int)SCHAR_MAX); } + +template<> inline ushort saturate_cast<ushort>(softfloat a) { return (ushort)std::max(std::min(cvRound(a), (int)USHRT_MAX), 0); } +template<> inline ushort saturate_cast<ushort>(softdouble a) { return (ushort)std::max(std::min(cvRound(a), (int)USHRT_MAX), 0); } + +template<> inline short saturate_cast<short>(softfloat a) { return (short)std::min(std::max(cvRound(a), (int)SHRT_MIN), (int)SHRT_MAX); } +template<> inline short saturate_cast<short>(softdouble a) { return (short)std::min(std::max(cvRound(a), (int)SHRT_MIN), (int)SHRT_MAX); } + +template<> inline int saturate_cast<int>(softfloat a) { return cvRound(a); } +template<> inline int saturate_cast<int>(softdouble a) { return cvRound(a); } + +template<> inline int64_t saturate_cast<int64_t>(softfloat a) { return cvRound(a); } +template<> inline int64_t saturate_cast<int64_t>(softdouble a) { return cvRound64(a); } + +/** @brief Saturate cast to unsigned integer and unsigned long long integer +We intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. +*/ +template<> inline unsigned saturate_cast<unsigned>(softfloat a) { return cvRound(a); } +template<> inline unsigned saturate_cast<unsigned>(softdouble a) { return cvRound(a); } + +template<> inline uint64_t saturate_cast<uint64_t>(softfloat a) { return cvRound(a); } +template<> inline uint64_t saturate_cast<uint64_t>(softdouble a) { return cvRound64(a); } + +/** @brief Min and Max functions */ +inline softfloat min(const softfloat& a, const softfloat& b) { return (a > b) ? b : a; } +inline softdouble min(const softdouble& a, const softdouble& b) { return (a > b) ? b : a; } + +inline softfloat max(const softfloat& a, const softfloat& b) { return (a > b) ? a : b; } +inline softdouble max(const softdouble& a, const softdouble& b) { return (a > b) ? a : b; } + +/** @brief Absolute value */ +inline softfloat abs( softfloat a) { softfloat x; x.v = a.v & ((1U << 31) - 1); return x; } +inline softdouble abs( softdouble a) { softdouble x; x.v = a.v & ((1ULL << 63) - 1); return x; } + +/** @brief Exponent + +Special cases: +- exp(NaN) is NaN +- exp(-Inf) == 0 +- exp(+Inf) == +Inf +*/ +CV_EXPORTS softfloat exp( const softfloat& a); +CV_EXPORTS softdouble exp( const softdouble& a); + +/** @brief Natural logarithm + +Special cases: +- log(NaN), log(x < 0) are NaN +- log(0) == -Inf +*/ +CV_EXPORTS softfloat log( const softfloat& a ); +CV_EXPORTS softdouble log( const softdouble& a ); + +/** @brief Raising to the power + +Special cases: +- x**NaN is NaN for any x +- ( |x| == 1 )**Inf is NaN +- ( |x| > 1 )**+Inf or ( |x| < 1 )**-Inf is +Inf +- ( |x| > 1 )**-Inf or ( |x| < 1 )**+Inf is 0 +- x ** 0 == 1 for any x +- x ** 1 == 1 for any x +- NaN ** y is NaN for any other y +- Inf**(y < 0) == 0 +- Inf ** y is +Inf for any other y +- (x < 0)**y is NaN for any other y if x can't be correctly rounded to integer +- 0 ** 0 == 1 +- 0 ** (y < 0) is +Inf +- 0 ** (y > 0) is 0 +*/ +CV_EXPORTS softfloat pow( const softfloat& a, const softfloat& b); +CV_EXPORTS softdouble pow( const softdouble& a, const softdouble& b); + +/** @brief Cube root + +Special cases: +- cbrt(NaN) is NaN +- cbrt(+/-Inf) is +/-Inf +*/ +CV_EXPORTS softfloat cbrt( const softfloat& a ); + +/** @brief Sine + +Special cases: +- sin(Inf) or sin(NaN) is NaN +- sin(x) == x when sin(x) is close to zero +*/ +CV_EXPORTS softdouble sin( const softdouble& a ); + +/** @brief Cosine + * +Special cases: +- cos(Inf) or cos(NaN) is NaN +- cos(x) == +/- 1 when cos(x) is close to +/- 1 +*/ +CV_EXPORTS softdouble cos( const softdouble& a ); + +} + +//! @} + +#endif diff --git a/include/opencv2/core/sse_utils.hpp b/include/opencv2/core/sse_utils.hpp new file mode 100644 index 0000000..0906583 --- /dev/null +++ b/include/opencv2/core/sse_utils.hpp @@ -0,0 +1,652 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_SSE_UTILS_HPP +#define OPENCV_CORE_SSE_UTILS_HPP + +#ifndef __cplusplus +# error sse_utils.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" + +//! @addtogroup core_utils_sse +//! @{ + +#if CV_SSE2 + +inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_g0); + __m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_g0); + __m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_g1); + __m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_g1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk3); + __m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk3); + + __m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk3); + __m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk3); + + __m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk2); + __m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk2); + __m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk3); + __m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk3); + + v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk2); + v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk2); + v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk3); + v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk3); +} + +inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_g1); + __m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_g1); + __m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_b0); + __m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_b0); + __m128i layer1_chunk4 = _mm_unpacklo_epi8(v_g0, v_b1); + __m128i layer1_chunk5 = _mm_unpackhi_epi8(v_g0, v_b1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk4 = _mm_unpacklo_epi8(layer1_chunk2, layer1_chunk5); + __m128i layer2_chunk5 = _mm_unpackhi_epi8(layer1_chunk2, layer1_chunk5); + + __m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk4 = _mm_unpacklo_epi8(layer2_chunk2, layer2_chunk5); + __m128i layer3_chunk5 = _mm_unpackhi_epi8(layer2_chunk2, layer2_chunk5); + + __m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk3); + __m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk3); + __m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk4); + __m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk4); + __m128i layer4_chunk4 = _mm_unpacklo_epi8(layer3_chunk2, layer3_chunk5); + __m128i layer4_chunk5 = _mm_unpackhi_epi8(layer3_chunk2, layer3_chunk5); + + v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk3); + v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk3); + v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk4); + v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk4); + v_b0 = _mm_unpacklo_epi8(layer4_chunk2, layer4_chunk5); + v_b1 = _mm_unpackhi_epi8(layer4_chunk2, layer4_chunk5); +} + +inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_b0); + __m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_b0); + __m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_b1); + __m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_b1); + __m128i layer1_chunk4 = _mm_unpacklo_epi8(v_g0, v_a0); + __m128i layer1_chunk5 = _mm_unpackhi_epi8(v_g0, v_a0); + __m128i layer1_chunk6 = _mm_unpacklo_epi8(v_g1, v_a1); + __m128i layer1_chunk7 = _mm_unpackhi_epi8(v_g1, v_a1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk4 = _mm_unpacklo_epi8(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk5 = _mm_unpackhi_epi8(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk6 = _mm_unpacklo_epi8(layer1_chunk3, layer1_chunk7); + __m128i layer2_chunk7 = _mm_unpackhi_epi8(layer1_chunk3, layer1_chunk7); + + __m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk4 = _mm_unpacklo_epi8(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk5 = _mm_unpackhi_epi8(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk6 = _mm_unpacklo_epi8(layer2_chunk3, layer2_chunk7); + __m128i layer3_chunk7 = _mm_unpackhi_epi8(layer2_chunk3, layer2_chunk7); + + __m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk4); + __m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk4); + __m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk5); + __m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk5); + __m128i layer4_chunk4 = _mm_unpacklo_epi8(layer3_chunk2, layer3_chunk6); + __m128i layer4_chunk5 = _mm_unpackhi_epi8(layer3_chunk2, layer3_chunk6); + __m128i layer4_chunk6 = _mm_unpacklo_epi8(layer3_chunk3, layer3_chunk7); + __m128i layer4_chunk7 = _mm_unpackhi_epi8(layer3_chunk3, layer3_chunk7); + + v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk4); + v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk4); + v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk5); + v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk5); + v_b0 = _mm_unpacklo_epi8(layer4_chunk2, layer4_chunk6); + v_b1 = _mm_unpackhi_epi8(layer4_chunk2, layer4_chunk6); + v_a0 = _mm_unpacklo_epi8(layer4_chunk3, layer4_chunk7); + v_a1 = _mm_unpackhi_epi8(layer4_chunk3, layer4_chunk7); +} + +inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i v_mask = _mm_set1_epi16(0x00ff); + + __m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer4_chunk2 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8)); + __m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer4_chunk3 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8)); + + __m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask)); + __m128i layer3_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8)); + __m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8)); + + __m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8)); + __m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8)); + + __m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8)); + __m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8)); + + v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8)); + v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_g1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8)); +} + +inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i v_mask = _mm_set1_epi16(0x00ff); + + __m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer4_chunk3 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8)); + __m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer4_chunk4 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8)); + __m128i layer4_chunk2 = _mm_packus_epi16(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer4_chunk5 = _mm_packus_epi16(_mm_srli_epi16(v_b0, 8), _mm_srli_epi16(v_b1, 8)); + + __m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8)); + __m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8)); + __m128i layer3_chunk2 = _mm_packus_epi16(_mm_and_si128(layer4_chunk4, v_mask), _mm_and_si128(layer4_chunk5, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk4, 8), _mm_srli_epi16(layer4_chunk5, 8)); + + __m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8)); + __m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8)); + __m128i layer2_chunk2 = _mm_packus_epi16(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk4, 8), _mm_srli_epi16(layer3_chunk5, 8)); + + __m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8)); + __m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8)); + __m128i layer1_chunk2 = _mm_packus_epi16(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk4, 8), _mm_srli_epi16(layer2_chunk5, 8)); + + v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8)); + v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8)); + v_g0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_b1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk4, 8), _mm_srli_epi16(layer1_chunk5, 8)); +} + +inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i v_mask = _mm_set1_epi16(0x00ff); + + __m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer4_chunk4 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8)); + __m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer4_chunk5 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8)); + __m128i layer4_chunk2 = _mm_packus_epi16(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer4_chunk6 = _mm_packus_epi16(_mm_srli_epi16(v_b0, 8), _mm_srli_epi16(v_b1, 8)); + __m128i layer4_chunk3 = _mm_packus_epi16(_mm_and_si128(v_a0, v_mask), _mm_and_si128(v_a1, v_mask)); + __m128i layer4_chunk7 = _mm_packus_epi16(_mm_srli_epi16(v_a0, 8), _mm_srli_epi16(v_a1, 8)); + + __m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8)); + __m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8)); + __m128i layer3_chunk2 = _mm_packus_epi16(_mm_and_si128(layer4_chunk4, v_mask), _mm_and_si128(layer4_chunk5, v_mask)); + __m128i layer3_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk4, 8), _mm_srli_epi16(layer4_chunk5, 8)); + __m128i layer3_chunk3 = _mm_packus_epi16(_mm_and_si128(layer4_chunk6, v_mask), _mm_and_si128(layer4_chunk7, v_mask)); + __m128i layer3_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk6, 8), _mm_srli_epi16(layer4_chunk7, 8)); + + __m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8)); + __m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8)); + __m128i layer2_chunk2 = _mm_packus_epi16(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk4, 8), _mm_srli_epi16(layer3_chunk5, 8)); + __m128i layer2_chunk3 = _mm_packus_epi16(_mm_and_si128(layer3_chunk6, v_mask), _mm_and_si128(layer3_chunk7, v_mask)); + __m128i layer2_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk6, 8), _mm_srli_epi16(layer3_chunk7, 8)); + + __m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8)); + __m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8)); + __m128i layer1_chunk2 = _mm_packus_epi16(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk4, 8), _mm_srli_epi16(layer2_chunk5, 8)); + __m128i layer1_chunk3 = _mm_packus_epi16(_mm_and_si128(layer2_chunk6, v_mask), _mm_and_si128(layer2_chunk7, v_mask)); + __m128i layer1_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk6, 8), _mm_srli_epi16(layer2_chunk7, 8)); + + v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_b0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8)); + v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8)); + v_g0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_a0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk4, 8), _mm_srli_epi16(layer1_chunk5, 8)); + v_g1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk6, v_mask), _mm_and_si128(layer1_chunk7, v_mask)); + v_a1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk6, 8), _mm_srli_epi16(layer1_chunk7, 8)); +} + +inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_g0); + __m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_g0); + __m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_g1); + __m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_g1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk3); + __m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk3); + + __m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk3); + __m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk3); + + v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk2); + v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk2); + v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk3); + v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk3); +} + +inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_g1); + __m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_g1); + __m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_b0); + __m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_b0); + __m128i layer1_chunk4 = _mm_unpacklo_epi16(v_g0, v_b1); + __m128i layer1_chunk5 = _mm_unpackhi_epi16(v_g0, v_b1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk4 = _mm_unpacklo_epi16(layer1_chunk2, layer1_chunk5); + __m128i layer2_chunk5 = _mm_unpackhi_epi16(layer1_chunk2, layer1_chunk5); + + __m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk4 = _mm_unpacklo_epi16(layer2_chunk2, layer2_chunk5); + __m128i layer3_chunk5 = _mm_unpackhi_epi16(layer2_chunk2, layer2_chunk5); + + v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk3); + v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk3); + v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk4); + v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk4); + v_b0 = _mm_unpacklo_epi16(layer3_chunk2, layer3_chunk5); + v_b1 = _mm_unpackhi_epi16(layer3_chunk2, layer3_chunk5); +} + +inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_b0); + __m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_b0); + __m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_b1); + __m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_b1); + __m128i layer1_chunk4 = _mm_unpacklo_epi16(v_g0, v_a0); + __m128i layer1_chunk5 = _mm_unpackhi_epi16(v_g0, v_a0); + __m128i layer1_chunk6 = _mm_unpacklo_epi16(v_g1, v_a1); + __m128i layer1_chunk7 = _mm_unpackhi_epi16(v_g1, v_a1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk4 = _mm_unpacklo_epi16(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk5 = _mm_unpackhi_epi16(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk6 = _mm_unpacklo_epi16(layer1_chunk3, layer1_chunk7); + __m128i layer2_chunk7 = _mm_unpackhi_epi16(layer1_chunk3, layer1_chunk7); + + __m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk4 = _mm_unpacklo_epi16(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk5 = _mm_unpackhi_epi16(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk6 = _mm_unpacklo_epi16(layer2_chunk3, layer2_chunk7); + __m128i layer3_chunk7 = _mm_unpackhi_epi16(layer2_chunk3, layer2_chunk7); + + v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk4); + v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk4); + v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk5); + v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk5); + v_b0 = _mm_unpacklo_epi16(layer3_chunk2, layer3_chunk6); + v_b1 = _mm_unpackhi_epi16(layer3_chunk2, layer3_chunk6); + v_a0 = _mm_unpacklo_epi16(layer3_chunk3, layer3_chunk7); + v_a1 = _mm_unpackhi_epi16(layer3_chunk3, layer3_chunk7); +} + +#if CV_SSE4_1 + +inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i v_mask = _mm_set1_epi32(0x0000ffff); + + __m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer3_chunk2 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16)); + __m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16)); + + __m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk2 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16)); + __m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16)); + + __m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk2 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16)); + __m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16)); + + v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16)); + v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_g1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16)); +} + +inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i v_mask = _mm_set1_epi32(0x0000ffff); + + __m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16)); + __m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16)); + __m128i layer3_chunk2 = _mm_packus_epi32(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi32(_mm_srli_epi32(v_b0, 16), _mm_srli_epi32(v_b1, 16)); + + __m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16)); + __m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16)); + __m128i layer2_chunk2 = _mm_packus_epi32(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk4, 16), _mm_srli_epi32(layer3_chunk5, 16)); + + __m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16)); + __m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16)); + __m128i layer1_chunk2 = _mm_packus_epi32(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk4, 16), _mm_srli_epi32(layer2_chunk5, 16)); + + v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16)); + v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16)); + v_g0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_b1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk4, 16), _mm_srli_epi32(layer1_chunk5, 16)); +} + +inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i v_mask = _mm_set1_epi32(0x0000ffff); + + __m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16)); + __m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16)); + __m128i layer3_chunk2 = _mm_packus_epi32(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer3_chunk6 = _mm_packus_epi32(_mm_srli_epi32(v_b0, 16), _mm_srli_epi32(v_b1, 16)); + __m128i layer3_chunk3 = _mm_packus_epi32(_mm_and_si128(v_a0, v_mask), _mm_and_si128(v_a1, v_mask)); + __m128i layer3_chunk7 = _mm_packus_epi32(_mm_srli_epi32(v_a0, 16), _mm_srli_epi32(v_a1, 16)); + + __m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16)); + __m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16)); + __m128i layer2_chunk2 = _mm_packus_epi32(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk6 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk4, 16), _mm_srli_epi32(layer3_chunk5, 16)); + __m128i layer2_chunk3 = _mm_packus_epi32(_mm_and_si128(layer3_chunk6, v_mask), _mm_and_si128(layer3_chunk7, v_mask)); + __m128i layer2_chunk7 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk6, 16), _mm_srli_epi32(layer3_chunk7, 16)); + + __m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16)); + __m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16)); + __m128i layer1_chunk2 = _mm_packus_epi32(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk6 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk4, 16), _mm_srli_epi32(layer2_chunk5, 16)); + __m128i layer1_chunk3 = _mm_packus_epi32(_mm_and_si128(layer2_chunk6, v_mask), _mm_and_si128(layer2_chunk7, v_mask)); + __m128i layer1_chunk7 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk6, 16), _mm_srli_epi32(layer2_chunk7, 16)); + + v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_b0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16)); + v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16)); + v_g0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_a0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk4, 16), _mm_srli_epi32(layer1_chunk5, 16)); + v_g1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk6, v_mask), _mm_and_si128(layer1_chunk7, v_mask)); + v_a1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk6, 16), _mm_srli_epi32(layer1_chunk7, 16)); +} + +#endif // CV_SSE4_1 + +inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1) +{ + __m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_g0); + __m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_g0); + __m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_g1); + __m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_g1); + + __m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk2); + __m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk2); + __m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk3); + __m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk3); + + v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk2); + v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk2); + v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk3); + v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk3); +} + +inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, + __m128 & v_g1, __m128 & v_b0, __m128 & v_b1) +{ + __m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_g1); + __m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_g1); + __m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_b0); + __m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_b0); + __m128 layer1_chunk4 = _mm_unpacklo_ps(v_g0, v_b1); + __m128 layer1_chunk5 = _mm_unpackhi_ps(v_g0, v_b1); + + __m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk3); + __m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk3); + __m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk4); + __m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk4); + __m128 layer2_chunk4 = _mm_unpacklo_ps(layer1_chunk2, layer1_chunk5); + __m128 layer2_chunk5 = _mm_unpackhi_ps(layer1_chunk2, layer1_chunk5); + + v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk3); + v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk3); + v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk4); + v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk4); + v_b0 = _mm_unpacklo_ps(layer2_chunk2, layer2_chunk5); + v_b1 = _mm_unpackhi_ps(layer2_chunk2, layer2_chunk5); +} + +inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1, + __m128 & v_b0, __m128 & v_b1, __m128 & v_a0, __m128 & v_a1) +{ + __m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_b0); + __m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_b0); + __m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_b1); + __m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_b1); + __m128 layer1_chunk4 = _mm_unpacklo_ps(v_g0, v_a0); + __m128 layer1_chunk5 = _mm_unpackhi_ps(v_g0, v_a0); + __m128 layer1_chunk6 = _mm_unpacklo_ps(v_g1, v_a1); + __m128 layer1_chunk7 = _mm_unpackhi_ps(v_g1, v_a1); + + __m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk4); + __m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk4); + __m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk5); + __m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk5); + __m128 layer2_chunk4 = _mm_unpacklo_ps(layer1_chunk2, layer1_chunk6); + __m128 layer2_chunk5 = _mm_unpackhi_ps(layer1_chunk2, layer1_chunk6); + __m128 layer2_chunk6 = _mm_unpacklo_ps(layer1_chunk3, layer1_chunk7); + __m128 layer2_chunk7 = _mm_unpackhi_ps(layer1_chunk3, layer1_chunk7); + + v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk4); + v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk4); + v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk5); + v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk5); + v_b0 = _mm_unpacklo_ps(layer2_chunk2, layer2_chunk6); + v_b1 = _mm_unpackhi_ps(layer2_chunk2, layer2_chunk6); + v_a0 = _mm_unpacklo_ps(layer2_chunk3, layer2_chunk7); + v_a1 = _mm_unpackhi_ps(layer2_chunk3, layer2_chunk7); +} + +inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1) +{ + enum { mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1) }; + + __m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo); + __m128 layer2_chunk2 = _mm_shuffle_ps(v_r0, v_r1, mask_hi); + __m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo); + __m128 layer2_chunk3 = _mm_shuffle_ps(v_g0, v_g1, mask_hi); + + __m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo); + __m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi); + __m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo); + __m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi); + + v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo); + v_g0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi); + v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo); + v_g1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi); +} + +inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, + __m128 & v_g1, __m128 & v_b0, __m128 & v_b1) +{ + enum { mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1) }; + + __m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo); + __m128 layer2_chunk3 = _mm_shuffle_ps(v_r0, v_r1, mask_hi); + __m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo); + __m128 layer2_chunk4 = _mm_shuffle_ps(v_g0, v_g1, mask_hi); + __m128 layer2_chunk2 = _mm_shuffle_ps(v_b0, v_b1, mask_lo); + __m128 layer2_chunk5 = _mm_shuffle_ps(v_b0, v_b1, mask_hi); + + __m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo); + __m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi); + __m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo); + __m128 layer1_chunk4 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi); + __m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_lo); + __m128 layer1_chunk5 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_hi); + + v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo); + v_g1 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi); + v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo); + v_b0 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi); + v_g0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_lo); + v_b1 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_hi); +} + +inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1, + __m128 & v_b0, __m128 & v_b1, __m128 & v_a0, __m128 & v_a1) +{ + enum { mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1) }; + + __m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo); + __m128 layer2_chunk4 = _mm_shuffle_ps(v_r0, v_r1, mask_hi); + __m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo); + __m128 layer2_chunk5 = _mm_shuffle_ps(v_g0, v_g1, mask_hi); + __m128 layer2_chunk2 = _mm_shuffle_ps(v_b0, v_b1, mask_lo); + __m128 layer2_chunk6 = _mm_shuffle_ps(v_b0, v_b1, mask_hi); + __m128 layer2_chunk3 = _mm_shuffle_ps(v_a0, v_a1, mask_lo); + __m128 layer2_chunk7 = _mm_shuffle_ps(v_a0, v_a1, mask_hi); + + __m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo); + __m128 layer1_chunk4 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi); + __m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo); + __m128 layer1_chunk5 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi); + __m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_lo); + __m128 layer1_chunk6 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_hi); + __m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk6, layer2_chunk7, mask_lo); + __m128 layer1_chunk7 = _mm_shuffle_ps(layer2_chunk6, layer2_chunk7, mask_hi); + + v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo); + v_b0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi); + v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo); + v_b1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi); + v_g0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_lo); + v_a0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_hi); + v_g1 = _mm_shuffle_ps(layer1_chunk6, layer1_chunk7, mask_lo); + v_a1 = _mm_shuffle_ps(layer1_chunk6, layer1_chunk7, mask_hi); +} + +#endif // CV_SSE2 + +//! @} + +#endif //OPENCV_CORE_SSE_UTILS_HPP diff --git a/include/opencv2/core/traits.hpp b/include/opencv2/core/traits.hpp new file mode 100644 index 0000000..6cb10f4 --- /dev/null +++ b/include/opencv2/core/traits.hpp @@ -0,0 +1,397 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_TRAITS_HPP +#define OPENCV_CORE_TRAITS_HPP + +#include "opencv2/core/cvdef.h" + +namespace cv +{ + +//#define OPENCV_TRAITS_ENABLE_DEPRECATED + +//! @addtogroup core_basic +//! @{ + +/** @brief Template "trait" class for OpenCV primitive data types. + +@note Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth + +A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed +short, int, float, double, or a tuple of values of one of these types, where all the values in the +tuple have the same type. Any primitive type from the list can be defined by an identifier in the +form CV_\<bit-depth\>{U|S|F}C(\<number_of_channels\>), for example: uchar \~ CV_8UC1, 3-element +floating-point tuple \~ CV_32FC3, and so on. A universal OpenCV structure that is able to store a +single instance of such a primitive data type is Vec. Multiple instances of such a type can be +stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to +store Vec instances. + +The DataType class is basically used to provide a description of such primitive data types without +adding any fields or methods to the corresponding classes (and it is actually impossible to add +anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not +DataType itself that is used but its specialized versions, such as: +@code + template<> class DataType<uchar> + { + typedef uchar value_type; + typedef int work_type; + typedef uchar channel_type; + enum { channel_type = CV_8U, channels = 1, fmt='u', type = CV_8U }; + }; + ... + template<typename _Tp> DataType<std::complex<_Tp> > + { + typedef std::complex<_Tp> value_type; + typedef std::complex<_Tp> work_type; + typedef _Tp channel_type; + // DataDepth is another helper trait class + enum { depth = DataDepth<_Tp>::value, channels=2, + fmt=(channels-1)*256+DataDepth<_Tp>::fmt, + type=CV_MAKETYPE(depth, channels) }; + }; + ... +@endcode +The main purpose of this class is to convert compilation-time type information to an +OpenCV-compatible data type identifier, for example: +@code + // allocates a 30x40 floating-point matrix + Mat A(30, 40, DataType<float>::type); + + Mat B = Mat_<std::complex<double> >(3, 3); + // the statement below will print 6, 2 , that is depth == CV_64F, channels == 2 + cout << B.depth() << ", " << B.channels() << endl; +@endcode +So, such traits are used to tell OpenCV which data type you are working with, even if such a type is +not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV +defines the proper specialized template class DataType\<complex\<_Tp\> \> . This mechanism is also +useful (and used in OpenCV this way) for generic algorithms implementations. + +@note Default values were dropped to stop confusing developers about using of unsupported types (see #7599) +*/ +template<typename _Tp> class DataType +{ +public: +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + typedef _Tp value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 1, + depth = -1, + channels = 1, + fmt = 0, + type = CV_MAKETYPE(depth, channels) + }; +#endif +}; + +template<> class DataType<bool> +{ +public: + typedef bool value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8U, + channels = 1, + fmt = (int)'u', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<uchar> +{ +public: + typedef uchar value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8U, + channels = 1, + fmt = (int)'u', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<schar> +{ +public: + typedef schar value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8S, + channels = 1, + fmt = (int)'c', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<char> +{ +public: + typedef schar value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8S, + channels = 1, + fmt = (int)'c', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<ushort> +{ +public: + typedef ushort value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_16U, + channels = 1, + fmt = (int)'w', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<short> +{ +public: + typedef short value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_16S, + channels = 1, + fmt = (int)'s', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<int> +{ +public: + typedef int value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_32S, + channels = 1, + fmt = (int)'i', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<float> +{ +public: + typedef float value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_32F, + channels = 1, + fmt = (int)'f', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType<double> +{ +public: + typedef double value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_64F, + channels = 1, + fmt = (int)'d', + type = CV_MAKETYPE(depth, channels) + }; +}; + + +/** @brief A helper class for cv::DataType + +The class is specialized for each fundamental numerical data type supported by OpenCV. It provides +DataDepth<T>::value constant. +*/ +template<typename _Tp> class DataDepth +{ +public: + enum + { + value = DataType<_Tp>::depth, + fmt = DataType<_Tp>::fmt + }; +}; + + +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + +template<int _depth> class TypeDepth +{ +#ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS + enum { depth = CV_USRTYPE1 }; + typedef void value_type; +#endif +}; + +template<> class TypeDepth<CV_8U> +{ + enum { depth = CV_8U }; + typedef uchar value_type; +}; + +template<> class TypeDepth<CV_8S> +{ + enum { depth = CV_8S }; + typedef schar value_type; +}; + +template<> class TypeDepth<CV_16U> +{ + enum { depth = CV_16U }; + typedef ushort value_type; +}; + +template<> class TypeDepth<CV_16S> +{ + enum { depth = CV_16S }; + typedef short value_type; +}; + +template<> class TypeDepth<CV_32S> +{ + enum { depth = CV_32S }; + typedef int value_type; +}; + +template<> class TypeDepth<CV_32F> +{ + enum { depth = CV_32F }; + typedef float value_type; +}; + +template<> class TypeDepth<CV_64F> +{ + enum { depth = CV_64F }; + typedef double value_type; +}; + +#endif + +//! @} + +namespace traits { + +namespace internal { +#define CV_CREATE_MEMBER_CHECK(X) \ +template<typename T> class CheckMember_##X { \ + struct Fallback { int X; }; \ + struct Derived : T, Fallback { }; \ + template<typename U, U> struct Check; \ + typedef char CV_NO[1]; \ + typedef char CV_YES[2]; \ + template<typename U> static CV_NO & func(Check<int Fallback::*, &U::X> *); \ + template<typename U> static CV_YES & func(...); \ +public: \ + typedef CheckMember_##X type; \ + enum { value = sizeof(func<Derived>(0)) == sizeof(CV_YES) }; \ +}; + +CV_CREATE_MEMBER_CHECK(fmt) +CV_CREATE_MEMBER_CHECK(type) + +} // namespace internal + + +template<typename T> +struct Depth +{ enum { value = DataType<T>::depth }; }; + +template<typename T> +struct Type +{ enum { value = DataType<T>::type }; }; + +/** Similar to traits::Type<T> but has value = -1 in case of unknown type (instead of compiler error) */ +template<typename T, bool available = internal::CheckMember_type< DataType<T> >::value > +struct SafeType {}; + +template<typename T> +struct SafeType<T, false> +{ enum { value = -1 }; }; + +template<typename T> +struct SafeType<T, true> +{ enum { value = Type<T>::value }; }; + + +template<typename T, bool available = internal::CheckMember_fmt< DataType<T> >::value > +struct SafeFmt {}; + +template<typename T> +struct SafeFmt<T, false> +{ enum { fmt = 0 }; }; + +template<typename T> +struct SafeFmt<T, true> +{ enum { fmt = DataType<T>::fmt }; }; + + +} // namespace + +} // cv + +#endif // OPENCV_CORE_TRAITS_HPP diff --git a/include/opencv2/core/types.hpp b/include/opencv2/core/types.hpp new file mode 100644 index 0000000..ef9ab59 --- /dev/null +++ b/include/opencv2/core/types.hpp @@ -0,0 +1,2391 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_TYPES_HPP +#define OPENCV_CORE_TYPES_HPP + +#ifndef __cplusplus +# error types.hpp header must be compiled as C++ +#endif + +#include <climits> +#include <cfloat> +#include <vector> +#include <limits> + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/matx.hpp" + +namespace cv +{ + +//! @addtogroup core_basic +//! @{ + +//////////////////////////////// Complex ////////////////////////////// + +/** @brief A complex number class. + + The template class is similar and compatible with std::complex, however it provides slightly + more convenient access to the real and imaginary parts using through the simple field access, as opposite + to std::complex::real() and std::complex::imag(). +*/ +template<typename _Tp> class Complex +{ +public: + + //! default constructor + Complex(); + Complex( _Tp _re, _Tp _im = 0 ); + + //! conversion to another data type + template<typename T2> operator Complex<T2>() const; + //! conjugation + Complex conj() const; + + _Tp re, im; //< the real and the imaginary parts +}; + +typedef Complex<float> Complexf; +typedef Complex<double> Complexd; + +template<typename _Tp> class DataType< Complex<_Tp> > +{ +public: + typedef Complex<_Tp> value_type; + typedef value_type work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<typename _Tp> +struct Depth< Complex<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp> +struct Type< Complex<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace + + +//////////////////////////////// Point_ //////////////////////////////// + +/** @brief Template class for 2D points specified by its coordinates `x` and `y`. + +An instance of the class is interchangeable with C structures, CvPoint and CvPoint2D32f . There is +also a cast operator to convert point coordinates to the specified type. The conversion from +floating-point coordinates to integer coordinates is done by rounding. Commonly, the conversion +uses this operation for each of the coordinates. Besides the class members listed in the +declaration above, the following operations on points are implemented: +@code + pt1 = pt2 + pt3; + pt1 = pt2 - pt3; + pt1 = pt2 * a; + pt1 = a * pt2; + pt1 = pt2 / a; + pt1 += pt2; + pt1 -= pt2; + pt1 *= a; + pt1 /= a; + double value = norm(pt); // L2 norm + pt1 == pt2; + pt1 != pt2; +@endcode +For your convenience, the following type aliases are defined: +@code + typedef Point_<int> Point2i; + typedef Point2i Point; + typedef Point_<float> Point2f; + typedef Point_<double> Point2d; +@endcode +Example: +@code + Point2f a(0.3f, 0.f), b(0.f, 0.4f); + Point pt = (a + b)*10.f; + cout << pt.x << ", " << pt.y << endl; +@endcode +*/ +template<typename _Tp> class Point_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Point_(); + Point_(_Tp _x, _Tp _y); + Point_(const Point_& pt); + Point_(const Size_<_Tp>& sz); + Point_(const Vec<_Tp, 2>& v); + + Point_& operator = (const Point_& pt); + //! conversion to another data type + template<typename _Tp2> operator Point_<_Tp2>() const; + + //! conversion to the old-style C structures + operator Vec<_Tp, 2>() const; + + //! dot product + _Tp dot(const Point_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point_& pt) const; + //! cross-product + double cross(const Point_& pt) const; + //! checks whether the point is inside the specified rectangle + bool inside(const Rect_<_Tp>& r) const; + _Tp x; //!< x coordinate of the point + _Tp y; //!< y coordinate of the point +}; + +typedef Point_<int> Point2i; +typedef Point_<int64> Point2l; +typedef Point_<float> Point2f; +typedef Point_<double> Point2d; +typedef Point2i Point; + +template<typename _Tp> class DataType< Point_<_Tp> > +{ +public: + typedef Point_<_Tp> value_type; + typedef Point_<typename DataType<_Tp>::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<typename _Tp> +struct Depth< Point_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp> +struct Type< Point_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace + + +//////////////////////////////// Point3_ //////////////////////////////// + +/** @brief Template class for 3D points specified by its coordinates `x`, `y` and `z`. + +An instance of the class is interchangeable with the C structure CvPoint2D32f . Similarly to +Point_ , the coordinates of 3D points can be converted to another type. The vector arithmetic and +comparison operations are also supported. + +The following Point3_\<\> aliases are available: +@code + typedef Point3_<int> Point3i; + typedef Point3_<float> Point3f; + typedef Point3_<double> Point3d; +@endcode +@see cv::Point3i, cv::Point3f and cv::Point3d +*/ +template<typename _Tp> class Point3_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Point3_(); + Point3_(_Tp _x, _Tp _y, _Tp _z); + Point3_(const Point3_& pt); + explicit Point3_(const Point_<_Tp>& pt); + Point3_(const Vec<_Tp, 3>& v); + + Point3_& operator = (const Point3_& pt); + //! conversion to another data type + template<typename _Tp2> operator Point3_<_Tp2>() const; + //! conversion to cv::Vec<> +#if OPENCV_ABI_COMPATIBILITY > 300 + template<typename _Tp2> operator Vec<_Tp2, 3>() const; +#else + operator Vec<_Tp, 3>() const; +#endif + + //! dot product + _Tp dot(const Point3_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point3_& pt) const; + //! cross product of the 2 3D points + Point3_ cross(const Point3_& pt) const; + _Tp x; //!< x coordinate of the 3D point + _Tp y; //!< y coordinate of the 3D point + _Tp z; //!< z coordinate of the 3D point +}; + +typedef Point3_<int> Point3i; +typedef Point3_<float> Point3f; +typedef Point3_<double> Point3d; + +template<typename _Tp> class DataType< Point3_<_Tp> > +{ +public: + typedef Point3_<_Tp> value_type; + typedef Point3_<typename DataType<_Tp>::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 3, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<typename _Tp> +struct Depth< Point3_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp> +struct Type< Point3_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 3) }; }; +} // namespace + +//////////////////////////////// Size_ //////////////////////////////// + +/** @brief Template class for specifying the size of an image or rectangle. + +The class includes two members called width and height. The structure can be converted to and from +the old OpenCV structures CvSize and CvSize2D32f . The same set of arithmetic and comparison +operations as for Point_ is available. + +OpenCV defines the following Size_\<\> aliases: +@code + typedef Size_<int> Size2i; + typedef Size2i Size; + typedef Size_<float> Size2f; +@endcode +*/ +template<typename _Tp> class Size_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Size_(); + Size_(_Tp _width, _Tp _height); + Size_(const Size_& sz); + Size_(const Point_<_Tp>& pt); + + Size_& operator = (const Size_& sz); + //! the area (width*height) + _Tp area() const; + //! true if empty + bool empty() const; + + //! conversion of another data type. + template<typename _Tp2> operator Size_<_Tp2>() const; + + _Tp width; //!< the width + _Tp height; //!< the height +}; + +typedef Size_<int> Size2i; +typedef Size_<int64> Size2l; +typedef Size_<float> Size2f; +typedef Size_<double> Size2d; +typedef Size2i Size; + +template<typename _Tp> class DataType< Size_<_Tp> > +{ +public: + typedef Size_<_Tp> value_type; + typedef Size_<typename DataType<_Tp>::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<typename _Tp> +struct Depth< Size_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp> +struct Type< Size_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace + +//////////////////////////////// Rect_ //////////////////////////////// + +/** @brief Template class for 2D rectangles + +described by the following parameters: +- Coordinates of the top-left corner. This is a default interpretation of Rect_::x and Rect_::y + in OpenCV. Though, in your algorithms you may count x and y from the bottom-left corner. +- Rectangle width and height. + +OpenCV typically assumes that the top and left boundary of the rectangle are inclusive, while the +right and bottom boundaries are not. For example, the method Rect_::contains returns true if + +\f[x \leq pt.x < x+width, + y \leq pt.y < y+height\f] + +Virtually every loop over an image ROI in OpenCV (where ROI is specified by Rect_\<int\> ) is +implemented as: +@code + for(int y = roi.y; y < roi.y + roi.height; y++) + for(int x = roi.x; x < roi.x + roi.width; x++) + { + // ... + } +@endcode +In addition to the class members, the following operations on rectangles are implemented: +- \f$\texttt{rect} = \texttt{rect} \pm \texttt{point}\f$ (shifting a rectangle by a certain offset) +- \f$\texttt{rect} = \texttt{rect} \pm \texttt{size}\f$ (expanding or shrinking a rectangle by a + certain amount) +- rect += point, rect -= point, rect += size, rect -= size (augmenting operations) +- rect = rect1 & rect2 (rectangle intersection) +- rect = rect1 | rect2 (minimum area rectangle containing rect1 and rect2 ) +- rect &= rect1, rect |= rect1 (and the corresponding augmenting operations) +- rect == rect1, rect != rect1 (rectangle comparison) + +This is an example how the partial ordering on rectangles can be established (rect1 \f$\subseteq\f$ +rect2): +@code + template<typename _Tp> inline bool + operator <= (const Rect_<_Tp>& r1, const Rect_<_Tp>& r2) + { + return (r1 & r2) == r1; + } +@endcode +For your convenience, the Rect_\<\> alias is available: cv::Rect +*/ +template<typename _Tp> class Rect_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Rect_(); + Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); + Rect_(const Rect_& r); + Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); + Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); + + Rect_& operator = ( const Rect_& r ); + //! the top-left corner + Point_<_Tp> tl() const; + //! the bottom-right corner + Point_<_Tp> br() const; + + //! size (width, height) of the rectangle + Size_<_Tp> size() const; + //! area (width*height) of the rectangle + _Tp area() const; + //! true if empty + bool empty() const; + + //! conversion to another data type + template<typename _Tp2> operator Rect_<_Tp2>() const; + + //! checks whether the rectangle contains the point + bool contains(const Point_<_Tp>& pt) const; + + _Tp x; //!< x coordinate of the top-left corner + _Tp y; //!< y coordinate of the top-left corner + _Tp width; //!< width of the rectangle + _Tp height; //!< height of the rectangle +}; + +typedef Rect_<int> Rect2i; +typedef Rect_<float> Rect2f; +typedef Rect_<double> Rect2d; +typedef Rect2i Rect; + +template<typename _Tp> class DataType< Rect_<_Tp> > +{ +public: + typedef Rect_<_Tp> value_type; + typedef Rect_<typename DataType<_Tp>::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 4, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<typename _Tp> +struct Depth< Rect_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp> +struct Type< Rect_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; }; +} // namespace + +///////////////////////////// RotatedRect ///////////////////////////// + +/** @brief The class represents rotated (i.e. not up-right) rectangles on a plane. + +Each rectangle is specified by the center point (mass center), length of each side (represented by +#Size2f structure) and the rotation angle in degrees. + +The sample below demonstrates how to use RotatedRect: +@snippet snippets/core_various.cpp RotatedRect_demo +![image](pics/rotatedrect.png) + +@sa CamShift, fitEllipse, minAreaRect, CvBox2D +*/ +class CV_EXPORTS RotatedRect +{ +public: + //! default constructor + RotatedRect(); + /** full constructor + @param center The rectangle mass center. + @param size Width and height of the rectangle. + @param angle The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., + the rectangle becomes an up-right rectangle. + */ + RotatedRect(const Point2f& center, const Size2f& size, float angle); + /** + Any 3 end points of the RotatedRect. They must be given in order (either clockwise or + anticlockwise). + */ + RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3); + + /** returns 4 vertices of the rectangle + @param pts The points array for storing rectangle vertices. The order is bottomLeft, topLeft, topRight, bottomRight. + */ + void points(Point2f pts[]) const; + //! returns the minimal up-right integer rectangle containing the rotated rectangle + Rect boundingRect() const; + //! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images + Rect_<float> boundingRect2f() const; + //! returns the rectangle mass center + Point2f center; + //! returns width and height of the rectangle + Size2f size; + //! returns the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle. + float angle; +}; + +template<> class DataType< RotatedRect > +{ +public: + typedef RotatedRect value_type; + typedef value_type work_type; + typedef float channel_type; + + enum { generic_type = 0, + channels = (int)sizeof(value_type)/sizeof(channel_type), // 5 + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<> +struct Depth< RotatedRect > { enum { value = Depth<float>::value }; }; +template<> +struct Type< RotatedRect > { enum { value = CV_MAKETYPE(Depth<float>::value, (int)sizeof(RotatedRect)/sizeof(float)) }; }; +} // namespace + + +//////////////////////////////// Range ///////////////////////////////// + +/** @brief Template class specifying a continuous subsequence (slice) of a sequence. + +The class is used to specify a row or a column span in a matrix ( Mat ) and for many other purposes. +Range(a,b) is basically the same as a:b in Matlab or a..b in Python. As in Python, start is an +inclusive left boundary of the range and end is an exclusive right boundary of the range. Such a +half-opened interval is usually denoted as \f$[start,end)\f$ . + +The static method Range::all() returns a special variable that means "the whole sequence" or "the +whole range", just like " : " in Matlab or " ... " in Python. All the methods and functions in +OpenCV that take Range support this special Range::all() value. But, of course, in case of your own +custom processing, you will probably have to check and handle it explicitly: +@code + void my_function(..., const Range& r, ....) + { + if(r == Range::all()) { + // process all the data + } + else { + // process [r.start, r.end) + } + } +@endcode +*/ +class CV_EXPORTS Range +{ +public: + Range(); + Range(int _start, int _end); + int size() const; + bool empty() const; + static Range all(); + + int start, end; +}; + +template<> class DataType<Range> +{ +public: + typedef Range value_type; + typedef value_type work_type; + typedef int channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<> +struct Depth< Range > { enum { value = Depth<int>::value }; }; +template<> +struct Type< Range > { enum { value = CV_MAKETYPE(Depth<int>::value, 2) }; }; +} // namespace + + +//////////////////////////////// Scalar_ /////////////////////////////// + +/** @brief Template class for a 4-element vector derived from Vec. + +Being derived from Vec\<_Tp, 4\> , Scalar\_ and Scalar can be used just as typical 4-element +vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in +OpenCV to pass pixel values. +*/ +template<typename _Tp> class Scalar_ : public Vec<_Tp, 4> +{ +public: + //! default constructor + Scalar_(); + Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0); + Scalar_(_Tp v0); + + template<typename _Tp2, int cn> + Scalar_(const Vec<_Tp2, cn>& v); + + //! returns a scalar with all elements set to v0 + static Scalar_<_Tp> all(_Tp v0); + + //! conversion to another data type + template<typename T2> operator Scalar_<T2>() const; + + //! per-element product + Scalar_<_Tp> mul(const Scalar_<_Tp>& a, double scale=1 ) const; + + //! returns (v0, -v1, -v2, -v3) + Scalar_<_Tp> conj() const; + + //! returns true iff v1 == v2 == v3 == 0 + bool isReal() const; +}; + +typedef Scalar_<double> Scalar; + +template<typename _Tp> class DataType< Scalar_<_Tp> > +{ +public: + typedef Scalar_<_Tp> value_type; + typedef Scalar_<typename DataType<_Tp>::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 4, + fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<typename _Tp> +struct Depth< Scalar_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template<typename _Tp> +struct Type< Scalar_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; }; +} // namespace + + +/////////////////////////////// KeyPoint //////////////////////////////// + +/** @brief Data structure for salient point detectors. + +The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint +detectors, such as Harris corner detector, #FAST, %StarDetector, %SURF, %SIFT etc. + +The keypoint is characterized by the 2D position, scale (proportional to the diameter of the +neighborhood that needs to be taken into account), orientation and some other parameters. The +keypoint neighborhood is then analyzed by another algorithm that builds a descriptor (usually +represented as a feature vector). The keypoints representing the same object in different images +can then be matched using %KDTree or another method. +*/ +class CV_EXPORTS_W_SIMPLE KeyPoint +{ +public: + //! the default constructor + CV_WRAP KeyPoint(); + /** + @param _pt x & y coordinates of the keypoint + @param _size keypoint diameter + @param _angle keypoint orientation + @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param _octave pyramid octave in which the keypoint has been detected + @param _class_id object id + */ + KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + /** + @param x x-coordinate of the keypoint + @param y y-coordinate of the keypoint + @param _size keypoint diameter + @param _angle keypoint orientation + @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param _octave pyramid octave in which the keypoint has been detected + @param _class_id object id + */ + CV_WRAP KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + + size_t hash() const; + + /** + This method converts vector of keypoints to vector of points or the reverse, where each keypoint is + assigned the same size and the same orientation. + + @param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB + @param points2f Array of (x,y) coordinates of each keypoint + @param keypointIndexes Array of indexes of keypoints to be converted to points. (Acts like a mask to + convert only specified keypoints) + */ + CV_WRAP static void convert(const std::vector<KeyPoint>& keypoints, + CV_OUT std::vector<Point2f>& points2f, + const std::vector<int>& keypointIndexes=std::vector<int>()); + /** @overload + @param points2f Array of (x,y) coordinates of each keypoint + @param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB + @param size keypoint diameter + @param response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param octave pyramid octave in which the keypoint has been detected + @param class_id object id + */ + CV_WRAP static void convert(const std::vector<Point2f>& points2f, + CV_OUT std::vector<KeyPoint>& keypoints, + float size=1, float response=1, int octave=0, int class_id=-1); + + /** + This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint + regions' intersection and area of keypoint regions' union (considering keypoint region as circle). + If they don't overlap, we get zero. If they coincide at same location with same size, we get 1. + @param kp1 First keypoint + @param kp2 Second keypoint + */ + CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2); + + CV_PROP_RW Point2f pt; //!< coordinates of the keypoints + CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood + CV_PROP_RW float angle; //!< computed orientation of the keypoint (-1 if not applicable); + //!< it's in [0,360) degrees and measured relative to + //!< image coordinate system, ie in clockwise. + CV_PROP_RW float response; //!< the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling + CV_PROP_RW int octave; //!< octave (pyramid layer) from which the keypoint has been extracted + CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to) +}; + +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED +template<> class DataType<KeyPoint> +{ +public: + typedef KeyPoint value_type; + typedef float work_type; + typedef float channel_type; + + enum { generic_type = 0, + depth = DataType<channel_type>::depth, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 7 + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) + }; + + typedef Vec<channel_type, channels> vec_type; +}; +#endif + + +//////////////////////////////// DMatch ///////////////////////////////// + +/** @brief Class for matching keypoint descriptors + +query descriptor index, train descriptor index, train image index, and distance between +descriptors. +*/ +class CV_EXPORTS_W_SIMPLE DMatch +{ +public: + CV_WRAP DMatch(); + CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance); + CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance); + + CV_PROP_RW int queryIdx; //!< query descriptor index + CV_PROP_RW int trainIdx; //!< train descriptor index + CV_PROP_RW int imgIdx; //!< train image index + + CV_PROP_RW float distance; + + // less is better + bool operator<(const DMatch &m) const; +}; + +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED +template<> class DataType<DMatch> +{ +public: + typedef DMatch value_type; + typedef int work_type; + typedef int channel_type; + + enum { generic_type = 0, + depth = DataType<channel_type>::depth, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 4 + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) + }; + + typedef Vec<channel_type, channels> vec_type; +}; +#endif + + +///////////////////////////// TermCriteria ////////////////////////////// + +/** @brief The class defining termination criteria for iterative algorithms. + +You can initialize it by default constructor and then override any parameters, or the structure may +be fully initialized using the advanced variant of the constructor. +*/ +class CV_EXPORTS TermCriteria +{ +public: + /** + Criteria type, can be one of: COUNT, EPS or COUNT + EPS + */ + enum Type + { + COUNT=1, //!< the maximum number of iterations or elements to compute + MAX_ITER=COUNT, //!< ditto + EPS=2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops + }; + + //! default constructor + TermCriteria(); + /** + @param type The type of termination criteria, one of TermCriteria::Type + @param maxCount The maximum number of iterations or elements to compute. + @param epsilon The desired accuracy or change in parameters at which the iterative algorithm stops. + */ + TermCriteria(int type, int maxCount, double epsilon); + + inline bool isValid() const + { + const bool isCount = (type & COUNT) && maxCount > 0; + const bool isEps = (type & EPS) && !cvIsNaN(epsilon); + return isCount || isEps; + } + + int type; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS + int maxCount; //!< the maximum number of iterations/elements + double epsilon; //!< the desired accuracy +}; + + +//! @} core_basic + +///////////////////////// raster image moments ////////////////////////// + +//! @addtogroup imgproc_shape +//! @{ + +/** @brief struct returned by cv::moments + +The spatial moments \f$\texttt{Moments::m}_{ji}\f$ are computed as: + +\f[\texttt{m} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot x^j \cdot y^i \right )\f] + +The central moments \f$\texttt{Moments::mu}_{ji}\f$ are computed as: + +\f[\texttt{mu} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot (x - \bar{x} )^j \cdot (y - \bar{y} )^i \right )\f] + +where \f$(\bar{x}, \bar{y})\f$ is the mass center: + +\f[\bar{x} = \frac{\texttt{m}_{10}}{\texttt{m}_{00}} , \; \bar{y} = \frac{\texttt{m}_{01}}{\texttt{m}_{00}}\f] + +The normalized central moments \f$\texttt{Moments::nu}_{ij}\f$ are computed as: + +\f[\texttt{nu} _{ji}= \frac{\texttt{mu}_{ji}}{\texttt{m}_{00}^{(i+j)/2+1}} .\f] + +@note +\f$\texttt{mu}_{00}=\texttt{m}_{00}\f$, \f$\texttt{nu}_{00}=1\f$ +\f$\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0\f$ , hence the values are not +stored. + +The moments of a contour are defined in the same way but computed using the Green's formula (see +<http://en.wikipedia.org/wiki/Green_theorem>). So, due to a limited raster resolution, the moments +computed for a contour are slightly different from the moments computed for the same rasterized +contour. + +@note +Since the contour moments are computed using Green formula, you may get seemingly odd results for +contours with self-intersections, e.g. a zero area (m00) for butterfly-shaped contours. + */ +class CV_EXPORTS_W_MAP Moments +{ +public: + //! the default constructor + Moments(); + //! the full constructor + Moments(double m00, double m10, double m01, double m20, double m11, + double m02, double m30, double m21, double m12, double m03 ); + ////! the conversion from CvMoments + //Moments( const CvMoments& moments ); + ////! the conversion to CvMoments + //operator CvMoments() const; + + //! @name spatial moments + //! @{ + CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; + //! @} + + //! @name central moments + //! @{ + CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03; + //! @} + + //! @name central normalized moments + //! @{ + CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03; + //! @} +}; + +template<> class DataType<Moments> +{ +public: + typedef Moments value_type; + typedef double work_type; + typedef double channel_type; + + enum { generic_type = 0, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24 + fmt = DataType<channel_type>::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType<channel_type>::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec<channel_type, channels> vec_type; +}; + +namespace traits { +template<> +struct Depth< Moments > { enum { value = Depth<double>::value }; }; +template<> +struct Type< Moments > { enum { value = CV_MAKETYPE(Depth<double>::value, (int)(sizeof(Moments)/sizeof(double))) }; }; +} // namespace + +//! @} imgproc_shape + +//! @cond IGNORED + +///////////////////////////////////////////////////////////////////////// +///////////////////////////// Implementation //////////////////////////// +///////////////////////////////////////////////////////////////////////// + +//////////////////////////////// Complex //////////////////////////////// + +template<typename _Tp> inline +Complex<_Tp>::Complex() + : re(0), im(0) {} + +template<typename _Tp> inline +Complex<_Tp>::Complex( _Tp _re, _Tp _im ) + : re(_re), im(_im) {} + +template<typename _Tp> template<typename T2> inline +Complex<_Tp>::operator Complex<T2>() const +{ + return Complex<T2>(saturate_cast<T2>(re), saturate_cast<T2>(im)); +} + +template<typename _Tp> inline +Complex<_Tp> Complex<_Tp>::conj() const +{ + return Complex<_Tp>(re, -im); +} + + +template<typename _Tp> static inline +bool operator == (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return a.re == b.re && a.im == b.im; +} + +template<typename _Tp> static inline +bool operator != (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return a.re != b.re || a.im != b.im; +} + +template<typename _Tp> static inline +Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return Complex<_Tp>( a.re + b.re, a.im + b.im ); +} + +template<typename _Tp> static inline +Complex<_Tp>& operator += (Complex<_Tp>& a, const Complex<_Tp>& b) +{ + a.re += b.re; a.im += b.im; + return a; +} + +template<typename _Tp> static inline +Complex<_Tp> operator - (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return Complex<_Tp>( a.re - b.re, a.im - b.im ); +} + +template<typename _Tp> static inline +Complex<_Tp>& operator -= (Complex<_Tp>& a, const Complex<_Tp>& b) +{ + a.re -= b.re; a.im -= b.im; + return a; +} + +template<typename _Tp> static inline +Complex<_Tp> operator - (const Complex<_Tp>& a) +{ + return Complex<_Tp>(-a.re, -a.im); +} + +template<typename _Tp> static inline +Complex<_Tp> operator * (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return Complex<_Tp>( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re ); +} + +template<typename _Tp> static inline +Complex<_Tp> operator * (const Complex<_Tp>& a, _Tp b) +{ + return Complex<_Tp>( a.re*b, a.im*b ); +} + +template<typename _Tp> static inline +Complex<_Tp> operator * (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>( a.re*b, a.im*b ); +} + +template<typename _Tp> static inline +Complex<_Tp> operator + (const Complex<_Tp>& a, _Tp b) +{ + return Complex<_Tp>( a.re + b, a.im ); +} + +template<typename _Tp> static inline +Complex<_Tp> operator - (const Complex<_Tp>& a, _Tp b) +{ return Complex<_Tp>( a.re - b, a.im ); } + +template<typename _Tp> static inline +Complex<_Tp> operator + (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>( a.re + b, a.im ); +} + +template<typename _Tp> static inline +Complex<_Tp> operator - (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>( b - a.re, -a.im ); +} + +template<typename _Tp> static inline +Complex<_Tp>& operator += (Complex<_Tp>& a, _Tp b) +{ + a.re += b; return a; +} + +template<typename _Tp> static inline +Complex<_Tp>& operator -= (Complex<_Tp>& a, _Tp b) +{ + a.re -= b; return a; +} + +template<typename _Tp> static inline +Complex<_Tp>& operator *= (Complex<_Tp>& a, _Tp b) +{ + a.re *= b; a.im *= b; return a; +} + +template<typename _Tp> static inline +double abs(const Complex<_Tp>& a) +{ + return std::sqrt( (double)a.re*a.re + (double)a.im*a.im); +} + +template<typename _Tp> static inline +Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + double t = 1./((double)b.re*b.re + (double)b.im*b.im); + return Complex<_Tp>( (_Tp)((a.re*b.re + a.im*b.im)*t), + (_Tp)((-a.re*b.im + a.im*b.re)*t) ); +} + +template<typename _Tp> static inline +Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b) +{ + a = a / b; + return a; +} + +template<typename _Tp> static inline +Complex<_Tp> operator / (const Complex<_Tp>& a, _Tp b) +{ + _Tp t = (_Tp)1/b; + return Complex<_Tp>( a.re*t, a.im*t ); +} + +template<typename _Tp> static inline +Complex<_Tp> operator / (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>(b)/a; +} + +template<typename _Tp> static inline +Complex<_Tp> operator /= (const Complex<_Tp>& a, _Tp b) +{ + _Tp t = (_Tp)1/b; + a.re *= t; a.im *= t; return a; +} + + + +//////////////////////////////// 2D Point /////////////////////////////// + +template<typename _Tp> inline +Point_<_Tp>::Point_() + : x(0), y(0) {} + +template<typename _Tp> inline +Point_<_Tp>::Point_(_Tp _x, _Tp _y) + : x(_x), y(_y) {} + +template<typename _Tp> inline +Point_<_Tp>::Point_(const Point_& pt) + : x(pt.x), y(pt.y) {} + +template<typename _Tp> inline +Point_<_Tp>::Point_(const Size_<_Tp>& sz) + : x(sz.width), y(sz.height) {} + +template<typename _Tp> inline +Point_<_Tp>::Point_(const Vec<_Tp,2>& v) + : x(v[0]), y(v[1]) {} + +template<typename _Tp> inline +Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt) +{ + x = pt.x; y = pt.y; + return *this; +} + +template<typename _Tp> template<typename _Tp2> inline +Point_<_Tp>::operator Point_<_Tp2>() const +{ + return Point_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y)); +} + +template<typename _Tp> inline +Point_<_Tp>::operator Vec<_Tp, 2>() const +{ + return Vec<_Tp, 2>(x, y); +} + +template<typename _Tp> inline +_Tp Point_<_Tp>::dot(const Point_& pt) const +{ + return saturate_cast<_Tp>(x*pt.x + y*pt.y); +} + +template<typename _Tp> inline +double Point_<_Tp>::ddot(const Point_& pt) const +{ + return (double)x*pt.x + (double)y*pt.y; +} + +template<typename _Tp> inline +double Point_<_Tp>::cross(const Point_& pt) const +{ + return (double)x*pt.y - (double)y*pt.x; +} + +template<typename _Tp> inline bool +Point_<_Tp>::inside( const Rect_<_Tp>& r ) const +{ + return r.contains(*this); +} + + +template<typename _Tp> static inline +Point_<_Tp>& operator += (Point_<_Tp>& a, const Point_<_Tp>& b) +{ + a.x += b.x; + a.y += b.y; + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator -= (Point_<_Tp>& a, const Point_<_Tp>& b) +{ + a.x -= b.x; + a.y -= b.y; + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator *= (Point_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator *= (Point_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator *= (Point_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template<typename _Tp> static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template<typename _Tp> static inline +double norm(const Point_<_Tp>& pt) +{ + return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y); +} + +template<typename _Tp> static inline +bool operator == (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return a.x == b.x && a.y == b.y; +} + +template<typename _Tp> static inline +bool operator != (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return a.x != b.x || a.y != b.y; +} + +template<typename _Tp> static inline +Point_<_Tp> operator + (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator - (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator - (const Point_<_Tp>& a) +{ + return Point_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (const Point_<_Tp>& a, int b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (int a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (const Point_<_Tp>& a, float b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (float a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (const Point_<_Tp>& a, double b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (double a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); +} + +template<typename _Tp> static inline +Point_<_Tp> operator * (const Matx<_Tp, 2, 2>& a, const Point_<_Tp>& b) +{ + Matx<_Tp, 2, 1> tmp = a * Vec<_Tp,2>(b.x, b.y); + return Point_<_Tp>(tmp.val[0], tmp.val[1]); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b) +{ + Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, 1); + return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); +} + +template<typename _Tp> static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, int b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template<typename _Tp> static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, float b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template<typename _Tp> static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, double b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + + +template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<int>& pt); +template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<int64>& pt); +template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<float>& pt); +template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<double>& pt); + +template<> inline int normL2Sqr<int>(const Point_<int>& pt) { return pt.dot(pt); } +template<> inline int64 normL2Sqr<int64>(const Point_<int64>& pt) { return pt.dot(pt); } +template<> inline float normL2Sqr<float>(const Point_<float>& pt) { return pt.dot(pt); } +template<> inline double normL2Sqr<double>(const Point_<int>& pt) { return pt.dot(pt); } + +template<> inline double normL2Sqr<double>(const Point_<float>& pt) { return pt.ddot(pt); } +template<> inline double normL2Sqr<double>(const Point_<double>& pt) { return pt.ddot(pt); } + + + +//////////////////////////////// 3D Point /////////////////////////////// + +template<typename _Tp> inline +Point3_<_Tp>::Point3_() + : x(0), y(0), z(0) {} + +template<typename _Tp> inline +Point3_<_Tp>::Point3_(_Tp _x, _Tp _y, _Tp _z) + : x(_x), y(_y), z(_z) {} + +template<typename _Tp> inline +Point3_<_Tp>::Point3_(const Point3_& pt) + : x(pt.x), y(pt.y), z(pt.z) {} + +template<typename _Tp> inline +Point3_<_Tp>::Point3_(const Point_<_Tp>& pt) + : x(pt.x), y(pt.y), z(_Tp()) {} + +template<typename _Tp> inline +Point3_<_Tp>::Point3_(const Vec<_Tp, 3>& v) + : x(v[0]), y(v[1]), z(v[2]) {} + +template<typename _Tp> template<typename _Tp2> inline +Point3_<_Tp>::operator Point3_<_Tp2>() const +{ + return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z)); +} + +#if OPENCV_ABI_COMPATIBILITY > 300 +template<typename _Tp> template<typename _Tp2> inline +Point3_<_Tp>::operator Vec<_Tp2, 3>() const +{ + return Vec<_Tp2, 3>(x, y, z); +} +#else +template<typename _Tp> inline +Point3_<_Tp>::operator Vec<_Tp, 3>() const +{ + return Vec<_Tp, 3>(x, y, z); +} +#endif + +template<typename _Tp> inline +Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt) +{ + x = pt.x; y = pt.y; z = pt.z; + return *this; +} + +template<typename _Tp> inline +_Tp Point3_<_Tp>::dot(const Point3_& pt) const +{ + return saturate_cast<_Tp>(x*pt.x + y*pt.y + z*pt.z); +} + +template<typename _Tp> inline +double Point3_<_Tp>::ddot(const Point3_& pt) const +{ + return (double)x*pt.x + (double)y*pt.y + (double)z*pt.z; +} + +template<typename _Tp> inline +Point3_<_Tp> Point3_<_Tp>::cross(const Point3_<_Tp>& pt) const +{ + return Point3_<_Tp>(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x); +} + + +template<typename _Tp> static inline +Point3_<_Tp>& operator += (Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator -= (Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator *= (Point3_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + a.z = saturate_cast<_Tp>(a.z * b); + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator *= (Point3_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + a.z = saturate_cast<_Tp>(a.z * b); + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator *= (Point3_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + a.z = saturate_cast<_Tp>(a.z * b); + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template<typename _Tp> static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template<typename _Tp> static inline +double norm(const Point3_<_Tp>& pt) +{ + return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y + (double)pt.z*pt.z); +} + +template<typename _Tp> static inline +bool operator == (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return a.x == b.x && a.y == b.y && a.z == b.z; +} + +template<typename _Tp> static inline +bool operator != (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return a.x != b.x || a.y != b.y || a.z != b.z; +} + +template<typename _Tp> static inline +Point3_<_Tp> operator + (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y), saturate_cast<_Tp>(a.z + b.z)); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator - (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y), saturate_cast<_Tp>(a.z - b.z)); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator - (const Point3_<_Tp>& a) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y), saturate_cast<_Tp>(-a.z) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (const Point3_<_Tp>& a, int b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b), saturate_cast<_Tp>(a.z*b) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (int a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (const Point3_<_Tp>& a, float b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (float a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (const Point3_<_Tp>& a, double b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (double a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) ); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point3_<_Tp>& b) +{ + Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, b.z); + return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); +} + +template<typename _Tp> static inline +Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b) +{ + return a * Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1); +} + +template<typename _Tp> static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, int b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template<typename _Tp> static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, float b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template<typename _Tp> static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, double b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + + + +////////////////////////////////// Size ///////////////////////////////// + +template<typename _Tp> inline +Size_<_Tp>::Size_() + : width(0), height(0) {} + +template<typename _Tp> inline +Size_<_Tp>::Size_(_Tp _width, _Tp _height) + : width(_width), height(_height) {} + +template<typename _Tp> inline +Size_<_Tp>::Size_(const Size_& sz) + : width(sz.width), height(sz.height) {} + +template<typename _Tp> inline +Size_<_Tp>::Size_(const Point_<_Tp>& pt) + : width(pt.x), height(pt.y) {} + +template<typename _Tp> template<typename _Tp2> inline +Size_<_Tp>::operator Size_<_Tp2>() const +{ + return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height)); +} + +template<typename _Tp> inline +Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz) +{ + width = sz.width; height = sz.height; + return *this; +} + +template<typename _Tp> inline +_Tp Size_<_Tp>::area() const +{ + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; +} + +template<typename _Tp> inline +bool Size_<_Tp>::empty() const +{ + return width <= 0 || height <= 0; +} + + +template<typename _Tp> static inline +Size_<_Tp>& operator *= (Size_<_Tp>& a, _Tp b) +{ + a.width *= b; + a.height *= b; + return a; +} + +template<typename _Tp> static inline +Size_<_Tp> operator * (const Size_<_Tp>& a, _Tp b) +{ + Size_<_Tp> tmp(a); + tmp *= b; + return tmp; +} + +template<typename _Tp> static inline +Size_<_Tp>& operator /= (Size_<_Tp>& a, _Tp b) +{ + a.width /= b; + a.height /= b; + return a; +} + +template<typename _Tp> static inline +Size_<_Tp> operator / (const Size_<_Tp>& a, _Tp b) +{ + Size_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template<typename _Tp> static inline +Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b) +{ + a.width += b.width; + a.height += b.height; + return a; +} + +template<typename _Tp> static inline +Size_<_Tp> operator + (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + Size_<_Tp> tmp(a); + tmp += b; + return tmp; +} + +template<typename _Tp> static inline +Size_<_Tp>& operator -= (Size_<_Tp>& a, const Size_<_Tp>& b) +{ + a.width -= b.width; + a.height -= b.height; + return a; +} + +template<typename _Tp> static inline +Size_<_Tp> operator - (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + Size_<_Tp> tmp(a); + tmp -= b; + return tmp; +} + +template<typename _Tp> static inline +bool operator == (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + return a.width == b.width && a.height == b.height; +} + +template<typename _Tp> static inline +bool operator != (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + return !(a == b); +} + + + +////////////////////////////////// Rect ///////////////////////////////// + +template<typename _Tp> inline +Rect_<_Tp>::Rect_() + : x(0), y(0), width(0), height(0) {} + +template<typename _Tp> inline +Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height) + : x(_x), y(_y), width(_width), height(_height) {} + +template<typename _Tp> inline +Rect_<_Tp>::Rect_(const Rect_<_Tp>& r) + : x(r.x), y(r.y), width(r.width), height(r.height) {} + +template<typename _Tp> inline +Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz) + : x(org.x), y(org.y), width(sz.width), height(sz.height) {} + +template<typename _Tp> inline +Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2) +{ + x = std::min(pt1.x, pt2.x); + y = std::min(pt1.y, pt2.y); + width = std::max(pt1.x, pt2.x) - x; + height = std::max(pt1.y, pt2.y) - y; +} + +template<typename _Tp> inline +Rect_<_Tp>& Rect_<_Tp>::operator = ( const Rect_<_Tp>& r ) +{ + x = r.x; + y = r.y; + width = r.width; + height = r.height; + return *this; +} + +template<typename _Tp> inline +Point_<_Tp> Rect_<_Tp>::tl() const +{ + return Point_<_Tp>(x,y); +} + +template<typename _Tp> inline +Point_<_Tp> Rect_<_Tp>::br() const +{ + return Point_<_Tp>(x + width, y + height); +} + +template<typename _Tp> inline +Size_<_Tp> Rect_<_Tp>::size() const +{ + return Size_<_Tp>(width, height); +} + +template<typename _Tp> inline +_Tp Rect_<_Tp>::area() const +{ + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; +} + +template<typename _Tp> inline +bool Rect_<_Tp>::empty() const +{ + return width <= 0 || height <= 0; +} + +template<typename _Tp> template<typename _Tp2> inline +Rect_<_Tp>::operator Rect_<_Tp2>() const +{ + return Rect_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height)); +} + +template<typename _Tp> inline +bool Rect_<_Tp>::contains(const Point_<_Tp>& pt) const +{ + return x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height; +} + + +template<typename _Tp> static inline +Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Point_<_Tp>& b ) +{ + a.x += b.x; + a.y += b.y; + return a; +} + +template<typename _Tp> static inline +Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Point_<_Tp>& b ) +{ + a.x -= b.x; + a.y -= b.y; + return a; +} + +template<typename _Tp> static inline +Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Size_<_Tp>& b ) +{ + a.width += b.width; + a.height += b.height; + return a; +} + +template<typename _Tp> static inline +Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Size_<_Tp>& b ) +{ + const _Tp width = a.width - b.width; + const _Tp height = a.height - b.height; + CV_DbgAssert(width >= 0 && height >= 0); + a.width = width; + a.height = height; + return a; +} + +template<typename _Tp> static inline +Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b ) +{ + _Tp x1 = std::max(a.x, b.x); + _Tp y1 = std::max(a.y, b.y); + a.width = std::min(a.x + a.width, b.x + b.width) - x1; + a.height = std::min(a.y + a.height, b.y + b.height) - y1; + a.x = x1; + a.y = y1; + if( a.width <= 0 || a.height <= 0 ) + a = Rect(); + return a; +} + +template<typename _Tp> static inline +Rect_<_Tp>& operator |= ( Rect_<_Tp>& a, const Rect_<_Tp>& b ) +{ + if (a.empty()) { + a = b; + } + else if (!b.empty()) { + _Tp x1 = std::min(a.x, b.x); + _Tp y1 = std::min(a.y, b.y); + a.width = std::max(a.x + a.width, b.x + b.width) - x1; + a.height = std::max(a.y + a.height, b.y + b.height) - y1; + a.x = x1; + a.y = y1; + } + return a; +} + +template<typename _Tp> static inline +bool operator == (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; +} + +template<typename _Tp> static inline +bool operator != (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height; +} + +template<typename _Tp> static inline +Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Point_<_Tp>& b) +{ + return Rect_<_Tp>( a.x + b.x, a.y + b.y, a.width, a.height ); +} + +template<typename _Tp> static inline +Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Point_<_Tp>& b) +{ + return Rect_<_Tp>( a.x - b.x, a.y - b.y, a.width, a.height ); +} + +template<typename _Tp> static inline +Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Size_<_Tp>& b) +{ + return Rect_<_Tp>( a.x, a.y, a.width + b.width, a.height + b.height ); +} + +template<typename _Tp> static inline +Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Size_<_Tp>& b) +{ + const _Tp width = a.width - b.width; + const _Tp height = a.height - b.height; + CV_DbgAssert(width >= 0 && height >= 0); + return Rect_<_Tp>( a.x, a.y, width, height ); +} + +template<typename _Tp> static inline +Rect_<_Tp> operator & (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + Rect_<_Tp> c = a; + return c &= b; +} + +template<typename _Tp> static inline +Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + Rect_<_Tp> c = a; + return c |= b; +} + +/** + * @brief measure dissimilarity between two sample sets + * + * computes the complement of the Jaccard Index as described in <https://en.wikipedia.org/wiki/Jaccard_index>. + * For rectangles this reduces to computing the intersection over the union. + */ +template<typename _Tp> static inline +double jaccardDistance(const Rect_<_Tp>& a, const Rect_<_Tp>& b) { + _Tp Aa = a.area(); + _Tp Ab = b.area(); + + if ((Aa + Ab) <= std::numeric_limits<_Tp>::epsilon()) { + // jaccard_index = 1 -> distance = 0 + return 0.0; + } + + double Aab = (a & b).area(); + // distance = 1 - jaccard_index + return 1.0 - Aab / (Aa + Ab - Aab); +} + +////////////////////////////// RotatedRect ////////////////////////////// + +inline +RotatedRect::RotatedRect() + : center(), size(), angle(0) {} + +inline +RotatedRect::RotatedRect(const Point2f& _center, const Size2f& _size, float _angle) + : center(_center), size(_size), angle(_angle) {} + + + +///////////////////////////////// Range ///////////////////////////////// + +inline +Range::Range() + : start(0), end(0) {} + +inline +Range::Range(int _start, int _end) + : start(_start), end(_end) {} + +inline +int Range::size() const +{ + return end - start; +} + +inline +bool Range::empty() const +{ + return start == end; +} + +inline +Range Range::all() +{ + return Range(INT_MIN, INT_MAX); +} + + +static inline +bool operator == (const Range& r1, const Range& r2) +{ + return r1.start == r2.start && r1.end == r2.end; +} + +static inline +bool operator != (const Range& r1, const Range& r2) +{ + return !(r1 == r2); +} + +static inline +bool operator !(const Range& r) +{ + return r.start == r.end; +} + +static inline +Range operator & (const Range& r1, const Range& r2) +{ + Range r(std::max(r1.start, r2.start), std::min(r1.end, r2.end)); + r.end = std::max(r.end, r.start); + return r; +} + +static inline +Range& operator &= (Range& r1, const Range& r2) +{ + r1 = r1 & r2; + return r1; +} + +static inline +Range operator + (const Range& r1, int delta) +{ + return Range(r1.start + delta, r1.end + delta); +} + +static inline +Range operator + (int delta, const Range& r1) +{ + return Range(r1.start + delta, r1.end + delta); +} + +static inline +Range operator - (const Range& r1, int delta) +{ + return r1 + (-delta); +} + + + +///////////////////////////////// Scalar //////////////////////////////// + +template<typename _Tp> inline +Scalar_<_Tp>::Scalar_() +{ + this->val[0] = this->val[1] = this->val[2] = this->val[3] = 0; +} + +template<typename _Tp> inline +Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3) +{ + this->val[0] = v0; + this->val[1] = v1; + this->val[2] = v2; + this->val[3] = v3; +} + +template<typename _Tp> template<typename _Tp2, int cn> inline +Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v) +{ + int i; + for( i = 0; i < (cn < 4 ? cn : 4); i++ ) + this->val[i] = cv::saturate_cast<_Tp>(v.val[i]); + for( ; i < 4; i++ ) + this->val[i] = 0; +} + +template<typename _Tp> inline +Scalar_<_Tp>::Scalar_(_Tp v0) +{ + this->val[0] = v0; + this->val[1] = this->val[2] = this->val[3] = 0; +} + +template<typename _Tp> inline +Scalar_<_Tp> Scalar_<_Tp>::all(_Tp v0) +{ + return Scalar_<_Tp>(v0, v0, v0, v0); +} + + +template<typename _Tp> inline +Scalar_<_Tp> Scalar_<_Tp>::mul(const Scalar_<_Tp>& a, double scale ) const +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(this->val[0] * a.val[0] * scale), + saturate_cast<_Tp>(this->val[1] * a.val[1] * scale), + saturate_cast<_Tp>(this->val[2] * a.val[2] * scale), + saturate_cast<_Tp>(this->val[3] * a.val[3] * scale)); +} + +template<typename _Tp> inline +Scalar_<_Tp> Scalar_<_Tp>::conj() const +{ + return Scalar_<_Tp>(saturate_cast<_Tp>( this->val[0]), + saturate_cast<_Tp>(-this->val[1]), + saturate_cast<_Tp>(-this->val[2]), + saturate_cast<_Tp>(-this->val[3])); +} + +template<typename _Tp> inline +bool Scalar_<_Tp>::isReal() const +{ + return this->val[1] == 0 && this->val[2] == 0 && this->val[3] == 0; +} + + +template<typename _Tp> template<typename T2> inline +Scalar_<_Tp>::operator Scalar_<T2>() const +{ + return Scalar_<T2>(saturate_cast<T2>(this->val[0]), + saturate_cast<T2>(this->val[1]), + saturate_cast<T2>(this->val[2]), + saturate_cast<T2>(this->val[3])); +} + + +template<typename _Tp> static inline +Scalar_<_Tp>& operator += (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a.val[0] += b.val[0]; + a.val[1] += b.val[1]; + a.val[2] += b.val[2]; + a.val[3] += b.val[3]; + return a; +} + +template<typename _Tp> static inline +Scalar_<_Tp>& operator -= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a.val[0] -= b.val[0]; + a.val[1] -= b.val[1]; + a.val[2] -= b.val[2]; + a.val[3] -= b.val[3]; + return a; +} + +template<typename _Tp> static inline +Scalar_<_Tp>& operator *= ( Scalar_<_Tp>& a, _Tp v ) +{ + a.val[0] *= v; + a.val[1] *= v; + a.val[2] *= v; + a.val[3] *= v; + return a; +} + +template<typename _Tp> static inline +bool operator == ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b ) +{ + return a.val[0] == b.val[0] && a.val[1] == b.val[1] && + a.val[2] == b.val[2] && a.val[3] == b.val[3]; +} + +template<typename _Tp> static inline +bool operator != ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b ) +{ + return a.val[0] != b.val[0] || a.val[1] != b.val[1] || + a.val[2] != b.val[2] || a.val[3] != b.val[3]; +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator + (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return Scalar_<_Tp>(a.val[0] + b.val[0], + a.val[1] + b.val[1], + a.val[2] + b.val[2], + a.val[3] + b.val[3]); +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator - (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(a.val[0] - b.val[0]), + saturate_cast<_Tp>(a.val[1] - b.val[1]), + saturate_cast<_Tp>(a.val[2] - b.val[2]), + saturate_cast<_Tp>(a.val[3] - b.val[3])); +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, _Tp alpha) +{ + return Scalar_<_Tp>(a.val[0] * alpha, + a.val[1] * alpha, + a.val[2] * alpha, + a.val[3] * alpha); +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator * (_Tp alpha, const Scalar_<_Tp>& a) +{ + return a*alpha; +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator - (const Scalar_<_Tp>& a) +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(-a.val[0]), + saturate_cast<_Tp>(-a.val[1]), + saturate_cast<_Tp>(-a.val[2]), + saturate_cast<_Tp>(-a.val[3])); +} + + +template<typename _Tp> static inline +Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3]), + saturate_cast<_Tp>(a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2]), + saturate_cast<_Tp>(a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]), + saturate_cast<_Tp>(a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0])); +} + +template<typename _Tp> static inline +Scalar_<_Tp>& operator *= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a = a * b; + return a; +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, _Tp alpha) +{ + return Scalar_<_Tp>(a.val[0] / alpha, + a.val[1] / alpha, + a.val[2] / alpha, + a.val[3] / alpha); +} + +template<typename _Tp> static inline +Scalar_<float> operator / (const Scalar_<float>& a, float alpha) +{ + float s = 1 / alpha; + return Scalar_<float>(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s); +} + +template<typename _Tp> static inline +Scalar_<double> operator / (const Scalar_<double>& a, double alpha) +{ + double s = 1 / alpha; + return Scalar_<double>(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s); +} + +template<typename _Tp> static inline +Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, _Tp alpha) +{ + a = a / alpha; + return a; +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator / (_Tp a, const Scalar_<_Tp>& b) +{ + _Tp s = a / (b[0]*b[0] + b[1]*b[1] + b[2]*b[2] + b[3]*b[3]); + return b.conj() * s; +} + +template<typename _Tp> static inline +Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return a * ((_Tp)1 / b); +} + +template<typename _Tp> static inline +Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a = a / b; + return a; +} + +template<typename _Tp> static inline +Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b) +{ + Matx<double, 4, 1> c((Matx<double, 4, 4>)a, b, Matx_MatMulOp()); + return reinterpret_cast<const Scalar&>(c); +} + +template<> inline +Scalar operator * (const Matx<double, 4, 4>& a, const Scalar& b) +{ + Matx<double, 4, 1> c(a, b, Matx_MatMulOp()); + return reinterpret_cast<const Scalar&>(c); +} + + + +//////////////////////////////// KeyPoint /////////////////////////////// + +inline +KeyPoint::KeyPoint() + : pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {} + +inline +KeyPoint::KeyPoint(Point2f _pt, float _size, float _angle, float _response, int _octave, int _class_id) + : pt(_pt), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} + +inline +KeyPoint::KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id) + : pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} + + + +///////////////////////////////// DMatch //////////////////////////////// + +inline +DMatch::DMatch() + : queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(FLT_MAX) {} + +inline +DMatch::DMatch(int _queryIdx, int _trainIdx, float _distance) + : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {} + +inline +DMatch::DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) + : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {} + +inline +bool DMatch::operator < (const DMatch &m) const +{ + return distance < m.distance; +} + + + +////////////////////////////// TermCriteria ///////////////////////////// + +inline +TermCriteria::TermCriteria() + : type(0), maxCount(0), epsilon(0) {} + +inline +TermCriteria::TermCriteria(int _type, int _maxCount, double _epsilon) + : type(_type), maxCount(_maxCount), epsilon(_epsilon) {} + +//! @endcond + +} // cv + +#endif //OPENCV_CORE_TYPES_HPP diff --git a/include/opencv2/core/types_c.h b/include/opencv2/core/types_c.h new file mode 100644 index 0000000..5f63eb8 --- /dev/null +++ b/include/opencv2/core/types_c.h @@ -0,0 +1,2139 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_TYPES_H +#define OPENCV_CORE_TYPES_H + +#if !defined(__OPENCV_BUILD) && !defined(CV__DISABLE_C_API_CTORS) +#define CV__ENABLE_C_API_CTORS // enable C API ctors (must be removed) +#endif + +//#define CV__VALIDATE_UNUNITIALIZED_VARS 1 // C++11 & GCC only + +#ifdef __cplusplus + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#define CV_STRUCT_INITIALIZER {0,} +#else +#if defined(__GNUC__) && __GNUC__ == 4 // GCC 4.x warns on "= {}" initialization, fixed in GCC 5.0 +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif +#define CV_STRUCT_INITIALIZER {} +#endif + +#else +#define CV_STRUCT_INITIALIZER {0} +#endif + + +#ifdef HAVE_IPL +# ifndef __IPL_H__ +# if defined _WIN32 +# include <ipl.h> +# else +# include <ipl/ipl.h> +# endif +# endif +#elif defined __IPL_H__ +# define HAVE_IPL +#endif + +#include "opencv2/core/cvdef.h" + +#ifndef SKIP_INCLUDES +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <float.h> +#endif // SKIP_INCLUDES + +#if defined _WIN32 +# define CV_CDECL __cdecl +# define CV_STDCALL __stdcall +#else +# define CV_CDECL +# define CV_STDCALL +#endif + +#ifndef CV_DEFAULT +# ifdef __cplusplus +# define CV_DEFAULT(val) = val +# else +# define CV_DEFAULT(val) +# endif +#endif + +#ifndef CV_EXTERN_C_FUNCPTR +# ifdef __cplusplus +# define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; } +# else +# define CV_EXTERN_C_FUNCPTR(x) typedef x +# endif +#endif + +#ifndef CVAPI +# define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL +#endif + +#ifndef CV_IMPL +# define CV_IMPL CV_EXTERN_C +#endif + +#ifdef __cplusplus +# include "opencv2/core.hpp" +#endif + +/** @addtogroup core_c + @{ +*/ + +/** @brief This is the "metatype" used *only* as a function parameter. + +It denotes that the function accepts arrays of multiple types, such as IplImage*, CvMat* or even +CvSeq* sometimes. The particular array type is determined at runtime by analyzing the first 4 +bytes of the header. In C++ interface the role of CvArr is played by InputArray and OutputArray. + */ +typedef void CvArr; + +typedef int CVStatus; + +/** @see cv::Error::Code */ +enum { + CV_StsOk= 0, /**< everything is ok */ + CV_StsBackTrace= -1, /**< pseudo error for back trace */ + CV_StsError= -2, /**< unknown /unspecified error */ + CV_StsInternal= -3, /**< internal error (bad state) */ + CV_StsNoMem= -4, /**< insufficient memory */ + CV_StsBadArg= -5, /**< function arg/param is bad */ + CV_StsBadFunc= -6, /**< unsupported function */ + CV_StsNoConv= -7, /**< iter. didn't converge */ + CV_StsAutoTrace= -8, /**< tracing */ + CV_HeaderIsNull= -9, /**< image header is NULL */ + CV_BadImageSize= -10, /**< image size is invalid */ + CV_BadOffset= -11, /**< offset is invalid */ + CV_BadDataPtr= -12, /**/ + CV_BadStep= -13, /**< image step is wrong, this may happen for a non-continuous matrix */ + CV_BadModelOrChSeq= -14, /**/ + CV_BadNumChannels= -15, /**< bad number of channels, for example, some functions accept only single channel matrices */ + CV_BadNumChannel1U= -16, /**/ + CV_BadDepth= -17, /**< input image depth is not supported by the function */ + CV_BadAlphaChannel= -18, /**/ + CV_BadOrder= -19, /**< number of dimensions is out of range */ + CV_BadOrigin= -20, /**< incorrect input origin */ + CV_BadAlign= -21, /**< incorrect input align */ + CV_BadCallBack= -22, /**/ + CV_BadTileSize= -23, /**/ + CV_BadCOI= -24, /**< input COI is not supported */ + CV_BadROISize= -25, /**< incorrect input roi */ + CV_MaskIsTiled= -26, /**/ + CV_StsNullPtr= -27, /**< null pointer */ + CV_StsVecLengthErr= -28, /**< incorrect vector length */ + CV_StsFilterStructContentErr= -29, /**< incorrect filter structure content */ + CV_StsKernelStructContentErr= -30, /**< incorrect transform kernel content */ + CV_StsFilterOffsetErr= -31, /**< incorrect filter offset value */ + CV_StsBadSize= -201, /**< the input/output structure size is incorrect */ + CV_StsDivByZero= -202, /**< division by zero */ + CV_StsInplaceNotSupported= -203, /**< in-place operation is not supported */ + CV_StsObjectNotFound= -204, /**< request can't be completed */ + CV_StsUnmatchedFormats= -205, /**< formats of input/output arrays differ */ + CV_StsBadFlag= -206, /**< flag is wrong or not supported */ + CV_StsBadPoint= -207, /**< bad CvPoint */ + CV_StsBadMask= -208, /**< bad format of mask (neither 8uC1 nor 8sC1)*/ + CV_StsUnmatchedSizes= -209, /**< sizes of input/output structures do not match */ + CV_StsUnsupportedFormat= -210, /**< the data format/type is not supported by the function*/ + CV_StsOutOfRange= -211, /**< some of parameters are out of range */ + CV_StsParseError= -212, /**< invalid syntax/structure of the parsed file */ + CV_StsNotImplemented= -213, /**< the requested function/feature is not implemented */ + CV_StsBadMemBlock= -214, /**< an allocated block has been corrupted */ + CV_StsAssert= -215, /**< assertion failed */ + CV_GpuNotSupported= -216, /**< no CUDA support */ + CV_GpuApiCallError= -217, /**< GPU API call error */ + CV_OpenGlNotSupported= -218, /**< no OpenGL support */ + CV_OpenGlApiCallError= -219, /**< OpenGL API call error */ + CV_OpenCLApiCallError= -220, /**< OpenCL API call error */ + CV_OpenCLDoubleNotSupported= -221, + CV_OpenCLInitError= -222, /**< OpenCL initialization error */ + CV_OpenCLNoAMDBlasFft= -223 +}; + +/****************************************************************************************\ +* Common macros and inline functions * +\****************************************************************************************/ + +#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) + +/** min & max without jumps */ +#define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))) + +#define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))) + +/** absolute value without jumps */ +#ifndef __cplusplus +# define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) +#else +# define CV_IABS(a) abs(a) +#endif +#define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) +#define CV_SIGN(a) CV_CMP((a),0) + +#define cvInvSqrt(value) ((float)(1./sqrt(value))) +#define cvSqrt(value) ((float)sqrt(value)) + + +/*************** Random number generation *******************/ + +typedef uint64 CvRNG; + +#define CV_RNG_COEFF 4164903690U + +/** @brief Initializes a random number generator state. + +The function initializes a random number generator and returns the state. The pointer to the state +can be then passed to the cvRandInt, cvRandReal and cvRandArr functions. In the current +implementation a multiply-with-carry generator is used. +@param seed 64-bit value used to initiate a random sequence +@sa the C++ class RNG replaced CvRNG. + */ +CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1)) +{ + CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1; + return rng; +} + +/** @brief Returns a 32-bit unsigned integer and updates RNG. + +The function returns a uniformly-distributed random 32-bit unsigned integer and updates the RNG +state. It is similar to the rand() function from the C runtime library, except that OpenCV functions +always generates a 32-bit random number, regardless of the platform. +@param rng CvRNG state initialized by cvRNG. + */ +CV_INLINE unsigned cvRandInt( CvRNG* rng ) +{ + uint64 temp = *rng; + temp = (uint64)(unsigned)temp*CV_RNG_COEFF + (temp >> 32); + *rng = temp; + return (unsigned)temp; +} + +/** @brief Returns a floating-point random number and updates RNG. + +The function returns a uniformly-distributed random floating-point number between 0 and 1 (1 is not +included). +@param rng RNG state initialized by cvRNG + */ +CV_INLINE double cvRandReal( CvRNG* rng ) +{ + return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */; +} + +/****************************************************************************************\ +* Image type (IplImage) * +\****************************************************************************************/ + +#ifndef HAVE_IPL + +/* + * The following definitions (until #endif) + * is an extract from IPL headers. + * Copyright (c) 1995 Intel Corporation. + */ +#define IPL_DEPTH_SIGN 0x80000000 + +#define IPL_DEPTH_1U 1 +#define IPL_DEPTH_8U 8 +#define IPL_DEPTH_16U 16 +#define IPL_DEPTH_32F 32 + +#define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8) +#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16) +#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32) + +#define IPL_DATA_ORDER_PIXEL 0 +#define IPL_DATA_ORDER_PLANE 1 + +#define IPL_ORIGIN_TL 0 +#define IPL_ORIGIN_BL 1 + +#define IPL_ALIGN_4BYTES 4 +#define IPL_ALIGN_8BYTES 8 +#define IPL_ALIGN_16BYTES 16 +#define IPL_ALIGN_32BYTES 32 + +#define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES +#define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES + +#define IPL_BORDER_CONSTANT 0 +#define IPL_BORDER_REPLICATE 1 +#define IPL_BORDER_REFLECT 2 +#define IPL_BORDER_WRAP 3 + +#ifdef __cplusplus +typedef struct _IplImage IplImage; +CV_EXPORTS _IplImage cvIplImage(const cv::Mat& m); +#endif + +/** The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV +only supports a subset of possible IplImage formats, as outlined in the parameter list above. + +In addition to the above restrictions, OpenCV handles ROIs differently. OpenCV functions require +that the image size or ROI size of all source and destination images match exactly. On the other +hand, the Intel Image Processing Library processes the area of intersection between the source and +destination images (or ROIs), allowing them to vary independently. +*/ +typedef struct +_IplImage +{ + int nSize; /**< sizeof(IplImage) */ + int ID; /**< version (=0)*/ + int nChannels; /**< Most of OpenCV functions support 1,2,3 or 4 channels */ + int alphaChannel; /**< Ignored by OpenCV */ + int depth; /**< Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, + IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */ + char colorModel[4]; /**< Ignored by OpenCV */ + char channelSeq[4]; /**< ditto */ + int dataOrder; /**< 0 - interleaved color channels, 1 - separate color channels. + cvCreateImage can only create interleaved images */ + int origin; /**< 0 - top-left origin, + 1 - bottom-left origin (Windows bitmaps style). */ + int align; /**< Alignment of image rows (4 or 8). + OpenCV ignores it and uses widthStep instead. */ + int width; /**< Image width in pixels. */ + int height; /**< Image height in pixels. */ + struct _IplROI *roi; /**< Image ROI. If NULL, the whole image is selected. */ + struct _IplImage *maskROI; /**< Must be NULL. */ + void *imageId; /**< " " */ + struct _IplTileInfo *tileInfo; /**< " " */ + int imageSize; /**< Image data size in bytes + (==image->height*image->widthStep + in case of interleaved data)*/ + char *imageData; /**< Pointer to aligned image data. */ + int widthStep; /**< Size of aligned image row in bytes. */ + int BorderMode[4]; /**< Ignored by OpenCV. */ + int BorderConst[4]; /**< Ditto. */ + char *imageDataOrigin; /**< Pointer to very origin of image data + (not necessarily aligned) - + needed for correct deallocation */ + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + _IplImage() {} + _IplImage(const cv::Mat& m) { *this = cvIplImage(m); } +#endif +} +IplImage; + +CV_INLINE IplImage cvIplImage() +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + IplImage self = CV_STRUCT_INITIALIZER; self.nSize = sizeof(IplImage); return self; +#else + return _IplImage(); +#endif +} + +typedef struct _IplTileInfo IplTileInfo; + +typedef struct _IplROI +{ + int coi; /**< 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ + int xOffset; + int yOffset; + int width; + int height; +} +IplROI; + +typedef struct _IplConvKernel +{ + int nCols; + int nRows; + int anchorX; + int anchorY; + int *values; + int nShiftR; +} +IplConvKernel; + +typedef struct _IplConvKernelFP +{ + int nCols; + int nRows; + int anchorX; + int anchorY; + float *values; +} +IplConvKernelFP; + +#define IPL_IMAGE_HEADER 1 +#define IPL_IMAGE_DATA 2 +#define IPL_IMAGE_ROI 4 + +#endif/*HAVE_IPL*/ + +/** extra border mode */ +#define IPL_BORDER_REFLECT_101 4 +#define IPL_BORDER_TRANSPARENT 5 + +#define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage)) +#define CV_TYPE_NAME_IMAGE "opencv-image" + +#define CV_IS_IMAGE_HDR(img) \ + ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage)) + +#define CV_IS_IMAGE(img) \ + (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL) + +/** for storing double-precision + floating point data in IplImage's */ +#define IPL_DEPTH_64F 64 + +/** get reference to pixel at (col,row), + for multi-channel images (col) should be multiplied by number of channels */ +#define CV_IMAGE_ELEM( image, elemtype, row, col ) \ + (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)]) + +/****************************************************************************************\ +* Matrix type (CvMat) * +\****************************************************************************************/ + +#define CV_AUTO_STEP 0x7fffffff +#define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff ) + +#define CV_MAGIC_MASK 0xFFFF0000 +#define CV_MAT_MAGIC_VAL 0x42420000 +#define CV_TYPE_NAME_MAT "opencv-matrix" + +#ifdef __cplusplus +typedef struct CvMat CvMat; +CV_INLINE CvMat cvMat(const cv::Mat& m); +#endif + +/** Matrix elements are stored row by row. Element (i, j) (i - 0-based row index, j - 0-based column +index) of a matrix can be retrieved or modified using CV_MAT_ELEM macro: + + uchar pixval = CV_MAT_ELEM(grayimg, uchar, i, j) + CV_MAT_ELEM(cameraMatrix, float, 0, 2) = image.width*0.5f; + +To access multiple-channel matrices, you can use +CV_MAT_ELEM(matrix, type, i, j\*nchannels + channel_idx). + +@deprecated CvMat is now obsolete; consider using Mat instead. + */ +typedef struct CvMat +{ + int type; + int step; + + /* for internal use only */ + int* refcount; + int hdr_refcount; + + union + { + uchar* ptr; + short* s; + int* i; + float* fl; + double* db; + } data; + +#ifdef __cplusplus + union + { + int rows; + int height; + }; + + union + { + int cols; + int width; + }; +#else + int rows; + int cols; +#endif + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvMat() {} + CvMat(const cv::Mat& m) { *this = cvMat(m); } +#endif +} +CvMat; + + +#define CV_IS_MAT_HDR(mat) \ + ((mat) != NULL && \ + (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ + ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0) + +#define CV_IS_MAT_HDR_Z(mat) \ + ((mat) != NULL && \ + (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ + ((const CvMat*)(mat))->cols >= 0 && ((const CvMat*)(mat))->rows >= 0) + +#define CV_IS_MAT(mat) \ + (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL) + +#define CV_IS_MASK_ARR(mat) \ + (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0) + +#define CV_ARE_TYPES_EQ(mat1, mat2) \ + ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0) + +#define CV_ARE_CNS_EQ(mat1, mat2) \ + ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0) + +#define CV_ARE_DEPTHS_EQ(mat1, mat2) \ + ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0) + +#define CV_ARE_SIZES_EQ(mat1, mat2) \ + ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols) + +#define CV_IS_MAT_CONST(mat) \ + (((mat)->rows|(mat)->cols) == 1) + +#define IPL2CV_DEPTH(depth) \ + ((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \ + (CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \ + (((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15) + +/** Inline constructor. No data is allocated internally!!! + * (Use together with cvCreateData, or use cvCreateMat instead to + * get a matrix with allocated data): + */ +CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL)) +{ + CvMat m; + + assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F ); + type = CV_MAT_TYPE(type); + m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type; + m.cols = cols; + m.rows = rows; + m.step = m.cols*CV_ELEM_SIZE(type); + m.data.ptr = (uchar*)data; + m.refcount = NULL; + m.hdr_refcount = 0; + + return m; +} + +#ifdef __cplusplus + +CV_INLINE CvMat cvMat(const cv::Mat& m) +{ + CvMat self; + CV_DbgAssert(m.dims <= 2); + self = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data); + self.step = (int)m.step[0]; + self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG); + return self; +} +CV_INLINE CvMat cvMat() +{ +#if !defined(CV__ENABLE_C_API_CTORS) + CvMat self = CV_STRUCT_INITIALIZER; return self; +#else + return CvMat(); +#endif +} +CV_INLINE CvMat cvMat(const CvMat& m) +{ +#if !defined(CV__ENABLE_C_API_CTORS) + CvMat self = CV_STRUCT_INITIALIZER; memcpy(&self, &m, sizeof(self)); return self; +#else + return CvMat(m); +#endif +} + +#endif // __cplusplus + + +#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \ + (assert( (unsigned)(row) < (unsigned)(mat).rows && \ + (unsigned)(col) < (unsigned)(mat).cols ), \ + (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col)) + +#define CV_MAT_ELEM_PTR( mat, row, col ) \ + CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) ) + +#define CV_MAT_ELEM( mat, elemtype, row, col ) \ + (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype))) + +/** @brief Returns the particular element of single-channel floating-point matrix. + +The function is a fast replacement for cvGetReal2D in the case of single-channel floating-point +matrices. It is faster because it is inline, it does fewer checks for array type and array element +type, and it checks for the row and column ranges only in debug mode. +@param mat Input matrix +@param row The zero-based index of row +@param col The zero-based index of column + */ +CV_INLINE double cvmGet( const CvMat* mat, int row, int col ) +{ + int type; + + type = CV_MAT_TYPE(mat->type); + assert( (unsigned)row < (unsigned)mat->rows && + (unsigned)col < (unsigned)mat->cols ); + + if( type == CV_32FC1 ) + return ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col]; + else + { + assert( type == CV_64FC1 ); + return ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col]; + } +} + +/** @brief Sets a specific element of a single-channel floating-point matrix. + +The function is a fast replacement for cvSetReal2D in the case of single-channel floating-point +matrices. It is faster because it is inline, it does fewer checks for array type and array element +type, and it checks for the row and column ranges only in debug mode. +@param mat The matrix +@param row The zero-based index of row +@param col The zero-based index of column +@param value The new value of the matrix element + */ +CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value ) +{ + int type; + type = CV_MAT_TYPE(mat->type); + assert( (unsigned)row < (unsigned)mat->rows && + (unsigned)col < (unsigned)mat->cols ); + + if( type == CV_32FC1 ) + ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value; + else + { + assert( type == CV_64FC1 ); + ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = value; + } +} + + +CV_INLINE int cvIplDepth( int type ) +{ + int depth = CV_MAT_DEPTH(type); + return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S || + depth == CV_32S ? IPL_DEPTH_SIGN : 0); +} + + +/****************************************************************************************\ +* Multi-dimensional dense array (CvMatND) * +\****************************************************************************************/ + +#define CV_MATND_MAGIC_VAL 0x42430000 +#define CV_TYPE_NAME_MATND "opencv-nd-matrix" + +#define CV_MAX_DIM 32 + +#ifdef __cplusplus +typedef struct CvMatND CvMatND; +CV_EXPORTS CvMatND cvMatND(const cv::Mat& m); +#endif + +/** + @deprecated consider using cv::Mat instead + */ +typedef struct +CvMatND +{ + int type; + int dims; + + int* refcount; + int hdr_refcount; + + union + { + uchar* ptr; + float* fl; + double* db; + int* i; + short* s; + } data; + + struct + { + int size; + int step; + } + dim[CV_MAX_DIM]; + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvMatND() {} + CvMatND(const cv::Mat& m) { *this = cvMatND(m); } +#endif +} +CvMatND; + + +CV_INLINE CvMatND cvMatND() +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvMatND self = CV_STRUCT_INITIALIZER; return self; +#else + return CvMatND(); +#endif +} + +#define CV_IS_MATND_HDR(mat) \ + ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL) + +#define CV_IS_MATND(mat) \ + (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL) + + +/****************************************************************************************\ +* Multi-dimensional sparse array (CvSparseMat) * +\****************************************************************************************/ + +#define CV_SPARSE_MAT_MAGIC_VAL 0x42440000 +#define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix" + +struct CvSet; + +typedef struct CvSparseMat +{ + int type; + int dims; + int* refcount; + int hdr_refcount; + + struct CvSet* heap; + void** hashtable; + int hashsize; + int valoffset; + int idxoffset; + int size[CV_MAX_DIM]; + +#ifdef __cplusplus + CV_EXPORTS void copyToSparseMat(cv::SparseMat& m) const; +#endif +} +CvSparseMat; + +#ifdef __cplusplus +CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m); +#endif + +#define CV_IS_SPARSE_MAT_HDR(mat) \ + ((mat) != NULL && \ + (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL) + +#define CV_IS_SPARSE_MAT(mat) \ + CV_IS_SPARSE_MAT_HDR(mat) + +/**************** iteration through a sparse array *****************/ + +typedef struct CvSparseNode +{ + unsigned hashval; + struct CvSparseNode* next; +} +CvSparseNode; + +typedef struct CvSparseMatIterator +{ + CvSparseMat* mat; + CvSparseNode* node; + int curidx; +} +CvSparseMatIterator; + +#define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset)) +#define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset)) + +/****************************************************************************************\ +* Histogram * +\****************************************************************************************/ + +typedef int CvHistType; + +#define CV_HIST_MAGIC_VAL 0x42450000 +#define CV_HIST_UNIFORM_FLAG (1 << 10) + +/** indicates whether bin ranges are set already or not */ +#define CV_HIST_RANGES_FLAG (1 << 11) + +#define CV_HIST_ARRAY 0 +#define CV_HIST_SPARSE 1 +#define CV_HIST_TREE CV_HIST_SPARSE + +/** should be used as a parameter only, + it turns to CV_HIST_UNIFORM_FLAG of hist->type */ +#define CV_HIST_UNIFORM 1 + +typedef struct CvHistogram +{ + int type; + CvArr* bins; + float thresh[CV_MAX_DIM][2]; /**< For uniform histograms. */ + float** thresh2; /**< For non-uniform histograms. */ + CvMatND mat; /**< Embedded matrix header for array histograms. */ +} +CvHistogram; + +#define CV_IS_HIST( hist ) \ + ((hist) != NULL && \ + (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \ + (hist)->bins != NULL) + +#define CV_IS_UNIFORM_HIST( hist ) \ + (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0) + +#define CV_IS_SPARSE_HIST( hist ) \ + CV_IS_SPARSE_MAT((hist)->bins) + +#define CV_HIST_HAS_RANGES( hist ) \ + (((hist)->type & CV_HIST_RANGES_FLAG) != 0) + +/****************************************************************************************\ +* Other supplementary data type definitions * +\****************************************************************************************/ + +/*************************************** CvRect *****************************************/ +/** @sa Rect_ */ +typedef struct CvRect +{ + int x; + int y; + int width; + int height; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvRect() __attribute__(( warning("Non-initialized variable") )) {}; + template<typename _Tp> CvRect(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 4); + x = y = width = height = 0; + if (list.size() == 4) + { + x = list.begin()[0]; y = list.begin()[1]; width = list.begin()[2]; height = list.begin()[3]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {} + template<typename _Tp> + CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast<int>(r.x)), y(cv::saturate_cast<int>(r.y)), width(cv::saturate_cast<int>(r.width)), height(cv::saturate_cast<int>(r.height)) {} +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); } +#endif +} +CvRect; + +/** constructs CvRect structure. */ +CV_INLINE CvRect cvRect( int x, int y, int width, int height ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvRect r = {x, y, width, height}; +#else + CvRect r(x, y , width, height); +#endif + return r; +} +#ifdef __cplusplus +CV_INLINE CvRect cvRect(const cv::Rect& rc) { return cvRect(rc.x, rc.y, rc.width, rc.height); } +#endif + +CV_INLINE IplROI cvRectToROI( CvRect rect, int coi ) +{ + IplROI roi; + roi.xOffset = rect.x; + roi.yOffset = rect.y; + roi.width = rect.width; + roi.height = rect.height; + roi.coi = coi; + + return roi; +} + + +CV_INLINE CvRect cvROIToRect( IplROI roi ) +{ + return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height ); +} + +/*********************************** CvTermCriteria *************************************/ + +#define CV_TERMCRIT_ITER 1 +#define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER +#define CV_TERMCRIT_EPS 2 + +/** @sa TermCriteria + */ +typedef struct CvTermCriteria +{ + int type; /**< may be combination of + CV_TERMCRIT_ITER + CV_TERMCRIT_EPS */ + int max_iter; + double epsilon; +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvTermCriteria(int _type = 0, int _iter = 0, double _eps = 0) : type(_type), max_iter(_iter), epsilon(_eps) {} + CvTermCriteria(const cv::TermCriteria& t) : type(t.type), max_iter(t.maxCount), epsilon(t.epsilon) {} +#endif +#ifdef __cplusplus + operator cv::TermCriteria() const { return cv::TermCriteria(type, max_iter, epsilon); } +#endif +} +CvTermCriteria; + +CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvTermCriteria t = { type, max_iter, (float)epsilon}; +#else + CvTermCriteria t(type, max_iter, epsilon); +#endif + return t; +} +#ifdef __cplusplus +CV_INLINE CvTermCriteria cvTermCriteria(const cv::TermCriteria& t) { return cvTermCriteria(t.type, t.maxCount, t.epsilon); } +#endif + + +/******************************* CvPoint and variants ***********************************/ + +typedef struct CvPoint +{ + int x; + int y; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvPoint(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + x = y = 0; + if (list.size() == 2) + { + x = list.begin()[0]; y = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {} + template<typename _Tp> + CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {} +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } +#endif +} +CvPoint; + +/** constructs CvPoint structure. */ +CV_INLINE CvPoint cvPoint( int x, int y ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint p = {x, y}; +#else + CvPoint p(x, y); +#endif + return p; +} +#ifdef __cplusplus +CV_INLINE CvPoint cvPoint(const cv::Point& pt) { return cvPoint(pt.x, pt.y); } +#endif + +typedef struct CvPoint2D32f +{ + float x; + float y; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint2D32f() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvPoint2D32f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + x = y = 0; + if (list.size() == 2) + { + x = list.begin()[0]; y = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {} + template<typename _Tp> + CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {} +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } +#endif +} +CvPoint2D32f; + +/** constructs CvPoint2D32f structure. */ +CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint2D32f p = { (float)x, (float)y }; +#else + CvPoint2D32f p((float)x, (float)y); +#endif + return p; +} + +#ifdef __cplusplus +template<typename _Tp> +CvPoint2D32f cvPoint2D32f(const cv::Point_<_Tp>& pt) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint2D32f p = { (float)pt.x, (float)pt.y }; +#else + CvPoint2D32f p((float)pt.x, (float)pt.y); +#endif + return p; +} +#endif + +/** converts CvPoint to CvPoint2D32f. */ +CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point ) +{ + return cvPoint2D32f( (float)point.x, (float)point.y ); +} + +/** converts CvPoint2D32f to CvPoint. */ +CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint ipt = { cvRound(point.x), cvRound(point.y) }; +#else + CvPoint ipt(cvRound(point.x), cvRound(point.y)); +#endif + return ipt; +} + + +typedef struct CvPoint3D32f +{ + float x; + float y; + float z; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint3D32f() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvPoint3D32f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 3); + x = y = z = 0; + if (list.size() == 3) + { + x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {} + template<typename _Tp> + CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {} +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Point3_<_Tp>() const { return cv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); } +#endif +} +CvPoint3D32f; + +/** constructs CvPoint3D32f structure. */ +CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint3D32f p = { (float)x, (float)y, (float)z }; +#else + CvPoint3D32f p((float)x, (float)y, (float)z); +#endif + return p; +} + +#ifdef __cplusplus +template<typename _Tp> +CvPoint3D32f cvPoint3D32f(const cv::Point3_<_Tp>& pt) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint3D32f p = { (float)pt.x, (float)pt.y, (float)pt.z }; +#else + CvPoint3D32f p((float)pt.x, (float)pt.y, (float)pt.z); +#endif + return p; +} +#endif + + +typedef struct CvPoint2D64f +{ + double x; + double y; +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint2D64f() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvPoint2D64f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + x = y = 0; + if (list.size() == 2) + { + x = list.begin()[0]; y = list.begin()[1]; + } + }; +#endif +} +CvPoint2D64f; + +/** constructs CvPoint2D64f structure.*/ +CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y ) +{ + CvPoint2D64f p = { x, y }; + return p; +} + + +typedef struct CvPoint3D64f +{ + double x; + double y; + double z; +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint3D64f() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvPoint3D64f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 3); + x = y = z = 0; + if (list.size() == 3) + { + x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2]; + } + }; +#endif +} +CvPoint3D64f; + +/** constructs CvPoint3D64f structure. */ +CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z ) +{ + CvPoint3D64f p = { x, y, z }; + return p; +} + + +/******************************** CvSize's & CvBox **************************************/ + +typedef struct CvSize +{ + int width; + int height; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvSize() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvSize(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + width = 0; height = 0; + if (list.size() == 2) + { + width = list.begin()[0]; height = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvSize(int w = 0, int h = 0): width(w), height(h) {} + template<typename _Tp> + CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<int>(sz.width)), height(cv::saturate_cast<int>(sz.height)) {} +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } +#endif +} +CvSize; + +/** constructs CvSize structure. */ +CV_INLINE CvSize cvSize( int width, int height ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize s = { width, height }; +#else + CvSize s(width, height); +#endif + return s; +} + +#ifdef __cplusplus +CV_INLINE CvSize cvSize(const cv::Size& sz) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize s = { sz.width, sz.height }; +#else + CvSize s(sz.width, sz.height); +#endif + return s; +} +#endif + +typedef struct CvSize2D32f +{ + float width; + float height; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvSize2D32f() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvSize2D32f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + width = 0; height = 0; + if (list.size() == 2) + { + width = list.begin()[0]; height = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {} + template<typename _Tp> + CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<float>(sz.width)), height(cv::saturate_cast<float>(sz.height)) {} +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } +#endif +} +CvSize2D32f; + +/** constructs CvSize2D32f structure. */ +CV_INLINE CvSize2D32f cvSize2D32f( double width, double height ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize2D32f s = { (float)width, (float)height }; +#else + CvSize2D32f s((float)width, (float)height); +#endif + return s; +} +#ifdef __cplusplus +template<typename _Tp> +CvSize2D32f cvSize2D32f(const cv::Size_<_Tp>& sz) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize2D32f s = { (float)sz.width, (float)sz.height }; +#else + CvSize2D32f s((float)sz.width, (float)sz.height); +#endif + return s; +} +#endif + +/** @sa RotatedRect + */ +typedef struct CvBox2D +{ + CvPoint2D32f center; /**< Center of the box. */ + CvSize2D32f size; /**< Box width and length. */ + float angle; /**< Angle between the horizontal axis */ + /**< and the first side (i.e. length) in degrees */ + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) : center(c), size(s), angle(a) {} + CvBox2D(const cv::RotatedRect& rr) : center(rr.center), size(rr.size), angle(rr.angle) {} +#endif +#ifdef __cplusplus + operator cv::RotatedRect() const { return cv::RotatedRect(center, size, angle); } +#endif +} +CvBox2D; + + +#ifdef __cplusplus +CV_INLINE CvBox2D cvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) +{ + CvBox2D self; + self.center = c; + self.size = s; + self.angle = a; + return self; +} +CV_INLINE CvBox2D cvBox2D(const cv::RotatedRect& rr) +{ + CvBox2D self; + self.center = cvPoint2D32f(rr.center); + self.size = cvSize2D32f(rr.size); + self.angle = rr.angle; + return self; +} +#endif + + +/** Line iterator state: */ +typedef struct CvLineIterator +{ + /** Pointer to the current point: */ + uchar* ptr; + + /* Bresenham algorithm state: */ + int err; + int plus_delta; + int minus_delta; + int plus_step; + int minus_step; +} +CvLineIterator; + + + +/************************************* CvSlice ******************************************/ +#define CV_WHOLE_SEQ_END_INDEX 0x3fffffff +#define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX) + +typedef struct CvSlice +{ + int start_index, end_index; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvSlice() __attribute__(( warning("Non-initialized variable") )) {} + template<typename _Tp> CvSlice(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + start_index = end_index = 0; + if (list.size() == 2) + { + start_index = list.begin()[0]; end_index = list.begin()[1]; + } + }; +#endif +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) && !defined(__CUDACC__) + CvSlice(int start = 0, int end = 0) : start_index(start), end_index(end) {} + CvSlice(const cv::Range& r) { *this = (r.start != INT_MIN && r.end != INT_MAX) ? CvSlice(r.start, r.end) : CvSlice(0, CV_WHOLE_SEQ_END_INDEX); } + operator cv::Range() const { return (start_index == 0 && end_index == CV_WHOLE_SEQ_END_INDEX ) ? cv::Range::all() : cv::Range(start_index, end_index); } +#endif +} +CvSlice; + +CV_INLINE CvSlice cvSlice( int start, int end ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) && !defined(__CUDACC__)) + CvSlice slice = { start, end }; +#else + CvSlice slice(start, end); +#endif + return slice; +} + +#if defined(__cplusplus) +CV_INLINE CvSlice cvSlice(const cv::Range& r) +{ + CvSlice slice = (r.start != INT_MIN && r.end != INT_MAX) ? cvSlice(r.start, r.end) : cvSlice(0, CV_WHOLE_SEQ_END_INDEX); + return slice; +} +#endif + + +/************************************* CvScalar *****************************************/ +/** @sa Scalar_ + */ +typedef struct CvScalar +{ + double val[4]; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvScalar() __attribute__(( warning("Non-initialized variable") )) {} + CvScalar(const std::initializer_list<double> list) + { + CV_Assert(list.size() == 0 || list.size() == 4); + val[0] = val[1] = val[2] = val[3] = 0; + if (list.size() == 4) + { + val[0] = list.begin()[0]; val[1] = list.begin()[1]; val[2] = list.begin()[2]; val[3] = list.begin()[3]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvScalar() {} + CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; } + template<typename _Tp> + CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; } + template<typename _Tp, int cn> + CvScalar(const cv::Vec<_Tp, cn>& v) + { + int i; + for( i = 0; i < (cn < 4 ? cn : 4); i++ ) val[i] = v.val[i]; + for( ; i < 4; i++ ) val[i] = 0; + } +#endif +#ifdef __cplusplus + template<typename _Tp> + operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); } +#endif +} +CvScalar; + +CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), + double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = val0; scalar.val[1] = val1; + scalar.val[2] = val2; scalar.val[3] = val3; + return scalar; +} + +#ifdef __cplusplus +CV_INLINE CvScalar cvScalar() +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; + return scalar; +} +CV_INLINE CvScalar cvScalar(const cv::Scalar& s) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = s.val[0]; + scalar.val[1] = s.val[1]; + scalar.val[2] = s.val[2]; + scalar.val[3] = s.val[3]; + return scalar; +} +#endif + +CV_INLINE CvScalar cvRealScalar( double val0 ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = val0; + scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; + return scalar; +} + +CV_INLINE CvScalar cvScalarAll( double val0123 ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = val0123; + scalar.val[1] = val0123; + scalar.val[2] = val0123; + scalar.val[3] = val0123; + return scalar; +} + +/****************************************************************************************\ +* Dynamic Data structures * +\****************************************************************************************/ + +/******************************** Memory storage ****************************************/ + +typedef struct CvMemBlock +{ + struct CvMemBlock* prev; + struct CvMemBlock* next; +} +CvMemBlock; + +#define CV_STORAGE_MAGIC_VAL 0x42890000 + +typedef struct CvMemStorage +{ + int signature; + CvMemBlock* bottom; /**< First allocated block. */ + CvMemBlock* top; /**< Current memory block - top of the stack. */ + struct CvMemStorage* parent; /**< We get new blocks from parent as needed. */ + int block_size; /**< Block size. */ + int free_space; /**< Remaining free space in current block. */ +} +CvMemStorage; + +#define CV_IS_STORAGE(storage) \ + ((storage) != NULL && \ + (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL) + + +typedef struct CvMemStoragePos +{ + CvMemBlock* top; + int free_space; +} +CvMemStoragePos; + + +/*********************************** Sequence *******************************************/ + +typedef struct CvSeqBlock +{ + struct CvSeqBlock* prev; /**< Previous sequence block. */ + struct CvSeqBlock* next; /**< Next sequence block. */ + int start_index; /**< Index of the first element in the block + */ + /**< sequence->first->start_index. */ + int count; /**< Number of elements in the block. */ + schar* data; /**< Pointer to the first element of the block. */ +} +CvSeqBlock; + + +#define CV_TREE_NODE_FIELDS(node_type) \ + int flags; /**< Miscellaneous flags. */ \ + int header_size; /**< Size of sequence header. */ \ + struct node_type* h_prev; /**< Previous sequence. */ \ + struct node_type* h_next; /**< Next sequence. */ \ + struct node_type* v_prev; /**< 2nd previous sequence. */ \ + struct node_type* v_next /**< 2nd next sequence. */ + +/** + Read/Write sequence. + Elements can be dynamically inserted to or deleted from the sequence. +*/ +#define CV_SEQUENCE_FIELDS() \ + CV_TREE_NODE_FIELDS(CvSeq); \ + int total; /**< Total number of elements. */ \ + int elem_size; /**< Size of sequence element in bytes. */ \ + schar* block_max; /**< Maximal bound of the last block. */ \ + schar* ptr; /**< Current write pointer. */ \ + int delta_elems; /**< Grow seq this many at a time. */ \ + CvMemStorage* storage; /**< Where the seq is stored. */ \ + CvSeqBlock* free_blocks; /**< Free blocks list. */ \ + CvSeqBlock* first; /**< Pointer to the first sequence block. */ + +typedef struct CvSeq +{ + CV_SEQUENCE_FIELDS() +} +CvSeq; + +#define CV_TYPE_NAME_SEQ "opencv-sequence" +#define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree" + +/*************************************** Set ********************************************/ +/** @brief Set + Order is not preserved. There can be gaps between sequence elements. + After the element has been inserted it stays in the same place all the time. + The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists. +*/ +#define CV_SET_ELEM_FIELDS(elem_type) \ + int flags; \ + struct elem_type* next_free; + +typedef struct CvSetElem +{ + CV_SET_ELEM_FIELDS(CvSetElem) +} +CvSetElem; + +#define CV_SET_FIELDS() \ + CV_SEQUENCE_FIELDS() \ + CvSetElem* free_elems; \ + int active_count; + +typedef struct CvSet +{ + CV_SET_FIELDS() +} +CvSet; + + +#define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1) +#define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1)) + +/** Checks whether the element pointed by ptr belongs to a set or not */ +#define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0) + +/************************************* Graph ********************************************/ + +/** @name Graph + +We represent a graph as a set of vertices. Vertices contain their adjacency lists (more exactly, +pointers to first incoming or outcoming edge (or 0 if isolated vertex)). Edges are stored in +another set. There is a singly-linked list of incoming/outcoming edges for each vertex. + +Each edge consists of: + +- Two pointers to the starting and ending vertices (vtx[0] and vtx[1] respectively). + + A graph may be oriented or not. In the latter case, edges between vertex i to vertex j are not +distinguished during search operations. + +- Two pointers to next edges for the starting and ending vertices, where next[0] points to the +next edge in the vtx[0] adjacency list and next[1] points to the next edge in the vtx[1] +adjacency list. + +@see CvGraphEdge, CvGraphVtx, CvGraphVtx2D, CvGraph +@{ +*/ +#define CV_GRAPH_EDGE_FIELDS() \ + int flags; \ + float weight; \ + struct CvGraphEdge* next[2]; \ + struct CvGraphVtx* vtx[2]; + + +#define CV_GRAPH_VERTEX_FIELDS() \ + int flags; \ + struct CvGraphEdge* first; + + +typedef struct CvGraphEdge +{ + CV_GRAPH_EDGE_FIELDS() +} +CvGraphEdge; + +typedef struct CvGraphVtx +{ + CV_GRAPH_VERTEX_FIELDS() +} +CvGraphVtx; + +typedef struct CvGraphVtx2D +{ + CV_GRAPH_VERTEX_FIELDS() + CvPoint2D32f* ptr; +} +CvGraphVtx2D; + +/** + Graph is "derived" from the set (this is set a of vertices) + and includes another set (edges) +*/ +#define CV_GRAPH_FIELDS() \ + CV_SET_FIELDS() \ + CvSet* edges; + +typedef struct CvGraph +{ + CV_GRAPH_FIELDS() +} +CvGraph; + +#define CV_TYPE_NAME_GRAPH "opencv-graph" + +/** @} */ + +/*********************************** Chain/Contour *************************************/ + +typedef struct CvChain +{ + CV_SEQUENCE_FIELDS() + CvPoint origin; +} +CvChain; + +#define CV_CONTOUR_FIELDS() \ + CV_SEQUENCE_FIELDS() \ + CvRect rect; \ + int color; \ + int reserved[3]; + +typedef struct CvContour +{ + CV_CONTOUR_FIELDS() +} +CvContour; + +typedef CvContour CvPoint2DSeq; + +/****************************************************************************************\ +* Sequence types * +\****************************************************************************************/ + +#define CV_SEQ_MAGIC_VAL 0x42990000 + +#define CV_IS_SEQ(seq) \ + ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL) + +#define CV_SET_MAGIC_VAL 0x42980000 +#define CV_IS_SET(set) \ + ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL) + +#define CV_SEQ_ELTYPE_BITS 12 +#define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1) + +#define CV_SEQ_ELTYPE_POINT CV_32SC2 /**< (x,y) */ +#define CV_SEQ_ELTYPE_CODE CV_8UC1 /**< freeman code: 0..7 */ +#define CV_SEQ_ELTYPE_GENERIC 0 +#define CV_SEQ_ELTYPE_PTR CV_USRTYPE1 +#define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /**< &(x,y) */ +#define CV_SEQ_ELTYPE_INDEX CV_32SC1 /**< #(x,y) */ +#define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /**< &next_o, &next_d, &vtx_o, &vtx_d */ +#define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /**< first_edge, &(x,y) */ +#define CV_SEQ_ELTYPE_TRIAN_ATR 0 /**< vertex of the binary tree */ +#define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /**< connected component */ +#define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /**< (x,y,z) */ + +#define CV_SEQ_KIND_BITS 2 +#define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS) + +/** types of sequences */ +#define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS) +#define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS) +#define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS) + +/** types of sparse sequences (sets) */ +#define CV_SEQ_KIND_GRAPH (1 << CV_SEQ_ELTYPE_BITS) +#define CV_SEQ_KIND_SUBDIV2D (2 << CV_SEQ_ELTYPE_BITS) + +#define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS) + +/** flags for curves */ +#define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT) +#define CV_SEQ_FLAG_SIMPLE (0 << CV_SEQ_FLAG_SHIFT) +#define CV_SEQ_FLAG_CONVEX (0 << CV_SEQ_FLAG_SHIFT) +#define CV_SEQ_FLAG_HOLE (2 << CV_SEQ_FLAG_SHIFT) + +/** flags for graphs */ +#define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT) + +#define CV_GRAPH CV_SEQ_KIND_GRAPH +#define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED) + +/** point sets */ +#define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT) +#define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D) +#define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT) +#define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE ) +#define CV_SEQ_CONTOUR CV_SEQ_POLYGON +#define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON ) + +/** chain-coded curves */ +#define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE) +#define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN) + +/** binary tree for the contour */ +#define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR) + +/** sequence of the connected components */ +#define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP) + +/** sequence of the integer numbers */ +#define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX) + +#define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK) +#define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK ) + +/** flag checking */ +#define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \ + (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC)) + +#define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE) +#define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0) +#define CV_IS_SEQ_CONVEX( seq ) 0 +#define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0) +#define CV_IS_SEQ_SIMPLE( seq ) 1 + +/** type checking macros */ +#define CV_IS_SEQ_POINT_SET( seq ) \ + ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2)) + +#define CV_IS_SEQ_POINT_SUBSET( seq ) \ + (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT) + +#define CV_IS_SEQ_POLYLINE( seq ) \ + (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq)) + +#define CV_IS_SEQ_POLYGON( seq ) \ + (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq)) + +#define CV_IS_SEQ_CHAIN( seq ) \ + (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1) + +#define CV_IS_SEQ_CONTOUR( seq ) \ + (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq))) + +#define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \ + (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq )) + +#define CV_IS_SEQ_POLYGON_TREE( seq ) \ + (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \ + CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE ) + +#define CV_IS_GRAPH( seq ) \ + (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH) + +#define CV_IS_GRAPH_ORIENTED( seq ) \ + (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0) + +#define CV_IS_SUBDIV2D( seq ) \ + (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D) + +/****************************************************************************************/ +/* Sequence writer & reader */ +/****************************************************************************************/ + +#define CV_SEQ_WRITER_FIELDS() \ + int header_size; \ + CvSeq* seq; /**< the sequence written */ \ + CvSeqBlock* block; /**< current block */ \ + schar* ptr; /**< pointer to free space */ \ + schar* block_min; /**< pointer to the beginning of block*/\ + schar* block_max; /**< pointer to the end of block */ + +typedef struct CvSeqWriter +{ + CV_SEQ_WRITER_FIELDS() +} +CvSeqWriter; + + +#define CV_SEQ_READER_FIELDS() \ + int header_size; \ + CvSeq* seq; /**< sequence, beign read */ \ + CvSeqBlock* block; /**< current block */ \ + schar* ptr; /**< pointer to element be read next */ \ + schar* block_min; /**< pointer to the beginning of block */\ + schar* block_max; /**< pointer to the end of block */ \ + int delta_index;/**< = seq->first->start_index */ \ + schar* prev_elem; /**< pointer to previous element */ + +typedef struct CvSeqReader +{ + CV_SEQ_READER_FIELDS() +} +CvSeqReader; + +/****************************************************************************************/ +/* Operations on sequences */ +/****************************************************************************************/ + +#define CV_SEQ_ELEM( seq, elem_type, index ) \ +/** assert gives some guarantee that <seq> parameter is valid */ \ +( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \ + (seq)->elem_size == sizeof(elem_type)), \ + (elem_type*)((seq)->first && (unsigned)index < \ + (unsigned)((seq)->first->count) ? \ + (seq)->first->data + (index) * sizeof(elem_type) : \ + cvGetSeqElem( (CvSeq*)(seq), (index) ))) +#define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) ) + +/** Add element to sequence: */ +#define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \ +{ \ + if( (writer).ptr >= (writer).block_max ) \ + { \ + cvCreateSeqBlock( &writer); \ + } \ + memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\ + (writer).ptr += (writer).seq->elem_size; \ +} + +#define CV_WRITE_SEQ_ELEM( elem, writer ) \ +{ \ + assert( (writer).seq->elem_size == sizeof(elem)); \ + if( (writer).ptr >= (writer).block_max ) \ + { \ + cvCreateSeqBlock( &writer); \ + } \ + assert( (writer).ptr <= (writer).block_max - sizeof(elem));\ + memcpy((writer).ptr, &(elem), sizeof(elem)); \ + (writer).ptr += sizeof(elem); \ +} + + +/** Move reader position forward: */ +#define CV_NEXT_SEQ_ELEM( elem_size, reader ) \ +{ \ + if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \ + { \ + cvChangeSeqBlock( &(reader), 1 ); \ + } \ +} + + +/** Move reader position backward: */ +#define CV_PREV_SEQ_ELEM( elem_size, reader ) \ +{ \ + if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \ + { \ + cvChangeSeqBlock( &(reader), -1 ); \ + } \ +} + +/** Read element and move read position forward: */ +#define CV_READ_SEQ_ELEM( elem, reader ) \ +{ \ + assert( (reader).seq->elem_size == sizeof(elem)); \ + memcpy( &(elem), (reader).ptr, sizeof((elem))); \ + CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \ +} + +/** Read element and move read position backward: */ +#define CV_REV_READ_SEQ_ELEM( elem, reader ) \ +{ \ + assert( (reader).seq->elem_size == sizeof(elem)); \ + memcpy(&(elem), (reader).ptr, sizeof((elem))); \ + CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \ +} + + +#define CV_READ_CHAIN_POINT( _pt, reader ) \ +{ \ + (_pt) = (reader).pt; \ + if( (reader).ptr ) \ + { \ + CV_READ_SEQ_ELEM( (reader).code, (reader)); \ + assert( ((reader).code & ~7) == 0 ); \ + (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \ + (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \ + } \ +} + +#define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr))) +#define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem))) + +#define CV_READ_EDGE( pt1, pt2, reader ) \ +{ \ + assert( sizeof(pt1) == sizeof(CvPoint) && \ + sizeof(pt2) == sizeof(CvPoint) && \ + reader.seq->elem_size == sizeof(CvPoint)); \ + (pt1) = CV_PREV_POINT( reader ); \ + (pt2) = CV_CURRENT_POINT( reader ); \ + (reader).prev_elem = (reader).ptr; \ + CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \ +} + +/************ Graph macros ************/ + +/** Return next graph edge for given vertex: */ +#define CV_NEXT_GRAPH_EDGE( edge, vertex ) \ + (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \ + (edge)->next[(edge)->vtx[1] == (vertex)]) + + + +/****************************************************************************************\ +* Data structures for persistence (a.k.a serialization) functionality * +\****************************************************************************************/ + +/** "black box" file storage */ +typedef struct CvFileStorage CvFileStorage; + +/** Storage flags: */ +#define CV_STORAGE_READ 0 +#define CV_STORAGE_WRITE 1 +#define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE +#define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE +#define CV_STORAGE_APPEND 2 +#define CV_STORAGE_MEMORY 4 +#define CV_STORAGE_FORMAT_MASK (7<<3) +#define CV_STORAGE_FORMAT_AUTO 0 +#define CV_STORAGE_FORMAT_XML 8 +#define CV_STORAGE_FORMAT_YAML 16 +#define CV_STORAGE_FORMAT_JSON 24 +#define CV_STORAGE_BASE64 64 +#define CV_STORAGE_WRITE_BASE64 (CV_STORAGE_BASE64 | CV_STORAGE_WRITE) + +/** @brief List of attributes. : + +In the current implementation, attributes are used to pass extra parameters when writing user +objects (see cvWrite). XML attributes inside tags are not supported, aside from the object type +specification (type_id attribute). +@see cvAttrList, cvAttrValue + */ +typedef struct CvAttrList +{ + const char** attr; /**< NULL-terminated array of (attribute_name,attribute_value) pairs. */ + struct CvAttrList* next; /**< Pointer to next chunk of the attributes list. */ +} +CvAttrList; + +/** initializes CvAttrList structure */ +CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL), + CvAttrList* next CV_DEFAULT(NULL) ) +{ + CvAttrList l; + l.attr = attr; + l.next = next; + + return l; +} + +struct CvTypeInfo; + +#define CV_NODE_NONE 0 +#define CV_NODE_INT 1 +#define CV_NODE_INTEGER CV_NODE_INT +#define CV_NODE_REAL 2 +#define CV_NODE_FLOAT CV_NODE_REAL +#define CV_NODE_STR 3 +#define CV_NODE_STRING CV_NODE_STR +#define CV_NODE_REF 4 /**< not used */ +#define CV_NODE_SEQ 5 +#define CV_NODE_MAP 6 +#define CV_NODE_TYPE_MASK 7 + +#define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK) + +/** file node flags */ +#define CV_NODE_FLOW 8 /**<Used only for writing structures in YAML format. */ +#define CV_NODE_USER 16 +#define CV_NODE_EMPTY 32 +#define CV_NODE_NAMED 64 + +#define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT) +#define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL) +#define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING) +#define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ) +#define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP) +#define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ) +#define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0) +#define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0) +#define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0) +#define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0) + +#define CV_NODE_SEQ_SIMPLE 256 +#define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0) + +typedef struct CvString +{ + int len; + char* ptr; +} +CvString; + +/** All the keys (names) of elements in the read file storage + are stored in the hash to speed up the lookup operations: */ +typedef struct CvStringHashNode +{ + unsigned hashval; + CvString str; + struct CvStringHashNode* next; +} +CvStringHashNode; + +typedef struct CvGenericHash CvFileNodeHash; + +/** Basic element of the file storage - scalar or collection: */ +typedef struct CvFileNode +{ + int tag; + struct CvTypeInfo* info; /**< type information + (only for user-defined object, for others it is 0) */ + union + { + double f; /**< scalar floating-point number */ + int i; /**< scalar integer number */ + CvString str; /**< text string */ + CvSeq* seq; /**< sequence (ordered collection of file nodes) */ + CvFileNodeHash* map; /**< map (collection of named file nodes) */ + } data; +} +CvFileNode; + +#ifdef __cplusplus +extern "C" { +#endif +typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr ); +typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr ); +typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node ); +typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name, + const void* struct_ptr, CvAttrList attributes ); +typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr ); +#ifdef __cplusplus +} +#endif + +/** @brief Type information + +The structure contains information about one of the standard or user-defined types. Instances of the +type may or may not contain a pointer to the corresponding CvTypeInfo structure. In any case, there +is a way to find the type info structure for a given object using the cvTypeOf function. +Alternatively, type info can be found by type name using cvFindType, which is used when an object +is read from file storage. The user can register a new type with cvRegisterType that adds the type +information structure into the beginning of the type list. Thus, it is possible to create +specialized types from generic standard types and override the basic methods. + */ +typedef struct CvTypeInfo +{ + int flags; /**< not used */ + int header_size; /**< sizeof(CvTypeInfo) */ + struct CvTypeInfo* prev; /**< previous registered type in the list */ + struct CvTypeInfo* next; /**< next registered type in the list */ + const char* type_name; /**< type name, written to file storage */ + CvIsInstanceFunc is_instance; /**< checks if the passed object belongs to the type */ + CvReleaseFunc release; /**< releases object (memory etc.) */ + CvReadFunc read; /**< reads object from file storage */ + CvWriteFunc write; /**< writes object to file storage */ + CvCloneFunc clone; /**< creates a copy of the object */ +} +CvTypeInfo; + + +/**** System data types ******/ + +typedef struct CvPluginFuncInfo +{ + void** func_addr; + void* default_func_addr; + const char* func_names; + int search_modules; + int loaded_from; +} +CvPluginFuncInfo; + +typedef struct CvModuleInfo +{ + struct CvModuleInfo* next; + const char* name; + const char* version; + CvPluginFuncInfo* func_tab; +} +CvModuleInfo; + +/** @} */ + +#endif /*OPENCV_CORE_TYPES_H*/ + +/* End of file. */ diff --git a/include/opencv2/core/utility.hpp b/include/opencv2/core/utility.hpp new file mode 100644 index 0000000..7a7158f --- /dev/null +++ b/include/opencv2/core/utility.hpp @@ -0,0 +1,1358 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_CORE_UTILITY_H +#define OPENCV_CORE_UTILITY_H + +#ifndef __cplusplus +# error utility.hpp header must be compiled as C++ +#endif + +#if defined(check) +# warning Detected Apple 'check' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif + +#include "opencv2/core.hpp" +#include <ostream> + +#ifdef CV_CXX11 +#include <functional> +#endif + +namespace cv +{ + +#ifdef CV_COLLECT_IMPL_DATA +CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays +CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays +// Get stored implementation flags and functions names arrays +// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function +CV_EXPORTS int getImpl(std::vector<int> &impl, std::vector<String> &funName); + +CV_EXPORTS bool useCollection(); // return implementation collection state +CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state + +#define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation +#define CV_IMPL_OCL 0x02 // OpenCL implementation +#define CV_IMPL_IPP 0x04 // IPP implementation +#define CV_IMPL_MT 0x10 // multithreaded implementation + +#define CV_IMPL_ADD(impl) \ + if(cv::useCollection()) \ + { \ + cv::addImpl(impl, CV_Func); \ + } +#else +#define CV_IMPL_ADD(impl) +#endif + +//! @addtogroup core_utils +//! @{ + +/** @brief Automatically Allocated Buffer Class + + The class is used for temporary buffers in functions and methods. + If a temporary buffer is usually small (a few K's of memory), + but its size depends on the parameters, it makes sense to create a small + fixed-size array on stack and use it if it's large enough. If the required buffer size + is larger than the fixed size, another buffer of sufficient size is allocated dynamically + and released after the processing. Therefore, in typical cases, when the buffer size is small, + there is no overhead associated with malloc()/free(). + At the same time, there is no limit on the size of processed data. + + This is what AutoBuffer does. The template takes 2 parameters - type of the buffer elements and + the number of stack-allocated elements. Here is how the class is used: + + \code + void my_func(const cv::Mat& m) + { + cv::AutoBuffer<float> buf(1000); // create automatic buffer containing 1000 floats + + buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used, + // otherwise the buffer of "m.rows" floats will be allocated + // dynamically and deallocated in cv::AutoBuffer destructor + ... + } + \endcode +*/ +template<typename _Tp, size_t fixed_size = 1024/sizeof(_Tp)+8> class AutoBuffer +{ +public: + typedef _Tp value_type; + + //! the default constructor + AutoBuffer(); + //! constructor taking the real buffer size + explicit AutoBuffer(size_t _size); + + //! the copy constructor + AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf); + //! the assignment operator + AutoBuffer<_Tp, fixed_size>& operator = (const AutoBuffer<_Tp, fixed_size>& buf); + + //! destructor. calls deallocate() + ~AutoBuffer(); + + //! allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used + void allocate(size_t _size); + //! deallocates the buffer if it was dynamically allocated + void deallocate(); + //! resizes the buffer and preserves the content + void resize(size_t _size); + //! returns the current buffer size + size_t size() const; + //! returns pointer to the real buffer, stack-allocated or heap-allocated + inline _Tp* data() { return ptr; } + //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated + inline const _Tp* data() const { return ptr; } + +#if !defined(OPENCV_DISABLE_DEPRECATED_COMPATIBILITY) // use to .data() calls instead + //! returns pointer to the real buffer, stack-allocated or heap-allocated + operator _Tp* () { return ptr; } + //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated + operator const _Tp* () const { return ptr; } +#else + //! returns a reference to the element at specified location. No bounds checking is performed in Release builds. + inline _Tp& operator[] (size_t i) { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; } + //! returns a reference to the element at specified location. No bounds checking is performed in Release builds. + inline const _Tp& operator[] (size_t i) const { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; } +#endif + +protected: + //! pointer to the real buffer, can point to buf if the buffer is small enough + _Tp* ptr; + //! size of the real buffer + size_t sz; + //! pre-allocated buffer. At least 1 element to confirm C++ standard requirements + _Tp buf[(fixed_size > 0) ? fixed_size : 1]; +}; + +/** @brief Sets/resets the break-on-error mode. + +When the break-on-error mode is set, the default error handler issues a hardware exception, which +can make debugging more convenient. + +\return the previous state + */ +CV_EXPORTS bool setBreakOnError(bool flag); + +extern "C" typedef int (*ErrorCallback)( int status, const char* func_name, + const char* err_msg, const char* file_name, + int line, void* userdata ); + + +/** @brief Sets the new error handler and the optional user data. + + The function sets the new error handler, called from cv::error(). + + \param errCallback the new error handler. If NULL, the default error handler is used. + \param userdata the optional user data pointer, passed to the callback. + \param prevUserdata the optional output parameter where the previous user data pointer is stored + + \return the previous error handler +*/ +CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdata=0, void** prevUserdata=0); + +CV_EXPORTS String tempfile( const char* suffix = 0); +CV_EXPORTS void glob(String pattern, std::vector<String>& result, bool recursive = false); + +/** @brief OpenCV will try to set the number of threads for the next parallel region. + +If threads == 0, OpenCV will disable threading optimizations and run all it's functions +sequentially. Passing threads \< 0 will reset threads number to system default. This function must +be called outside of parallel region. + +OpenCV will try to run its functions with specified threads number, but some behaviour differs from +framework: +- `TBB` - User-defined parallel constructions will run with the same threads number, if + another is not specified. If later on user creates his own scheduler, OpenCV will use it. +- `OpenMP` - No special defined behaviour. +- `Concurrency` - If threads == 1, OpenCV will disable threading optimizations and run its + functions sequentially. +- `GCD` - Supports only values \<= 0. +- `C=` - No special defined behaviour. +@param nthreads Number of threads used by OpenCV. +@sa getNumThreads, getThreadNum + */ +CV_EXPORTS_W void setNumThreads(int nthreads); + +/** @brief Returns the number of threads used by OpenCV for parallel regions. + +Always returns 1 if OpenCV is built without threading support. + +The exact meaning of return value depends on the threading framework used by OpenCV library: +- `TBB` - The number of threads, that OpenCV will try to use for parallel regions. If there is + any tbb::thread_scheduler_init in user code conflicting with OpenCV, then function returns + default number of threads used by TBB library. +- `OpenMP` - An upper bound on the number of threads that could be used to form a new team. +- `Concurrency` - The number of threads, that OpenCV will try to use for parallel regions. +- `GCD` - Unsupported; returns the GCD thread pool limit (512) for compatibility. +- `C=` - The number of threads, that OpenCV will try to use for parallel regions, if before + called setNumThreads with threads \> 0, otherwise returns the number of logical CPUs, + available for the process. +@sa setNumThreads, getThreadNum + */ +CV_EXPORTS_W int getNumThreads(); + +/** @brief Returns the index of the currently executed thread within the current parallel region. Always +returns 0 if called outside of parallel region. + +@deprecated Current implementation doesn't corresponding to this documentation. + +The exact meaning of the return value depends on the threading framework used by OpenCV library: +- `TBB` - Unsupported with current 4.1 TBB release. Maybe will be supported in future. +- `OpenMP` - The thread number, within the current team, of the calling thread. +- `Concurrency` - An ID for the virtual processor that the current context is executing on (0 + for master thread and unique number for others, but not necessary 1,2,3,...). +- `GCD` - System calling thread's ID. Never returns 0 inside parallel region. +- `C=` - The index of the current parallel task. +@sa setNumThreads, getNumThreads + */ +CV_EXPORTS_W int getThreadNum(); + +/** @brief Returns full configuration time cmake output. + +Returned value is raw cmake output including version control system revision, compiler version, +compiler flags, enabled modules and third party libraries, etc. Output format depends on target +architecture. + */ +CV_EXPORTS_W const String& getBuildInformation(); + +/** @brief Returns library version string + +For example "3.4.1-dev". + +@sa getMajorVersion, getMinorVersion, getRevisionVersion +*/ +CV_EXPORTS_W String getVersionString(); + +/** @brief Returns major library version */ +CV_EXPORTS_W int getVersionMajor(); + +/** @brief Returns minor library version */ +CV_EXPORTS_W int getVersionMinor(); + +/** @brief Returns revision field of the library version */ +CV_EXPORTS_W int getVersionRevision(); + +/** @brief Returns the number of ticks. + +The function returns the number of ticks after the certain event (for example, when the machine was +turned on). It can be used to initialize RNG or to measure a function execution time by reading the +tick count before and after the function call. +@sa getTickFrequency, TickMeter + */ +CV_EXPORTS_W int64 getTickCount(); + +/** @brief Returns the number of ticks per second. + +The function returns the number of ticks per second. That is, the following code computes the +execution time in seconds: +@code + double t = (double)getTickCount(); + // do something ... + t = ((double)getTickCount() - t)/getTickFrequency(); +@endcode +@sa getTickCount, TickMeter + */ +CV_EXPORTS_W double getTickFrequency(); + +/** @brief a Class to measure passing time. + +The class computes passing time by counting the number of ticks per second. That is, the following code computes the +execution time in seconds: +@code +TickMeter tm; +tm.start(); +// do something ... +tm.stop(); +std::cout << tm.getTimeSec(); +@endcode + +It is also possible to compute the average time over multiple runs: +@code +TickMeter tm; +for (int i = 0; i < 100; i++) +{ + tm.start(); + // do something ... + tm.stop(); +} +double average_time = tm.getTimeSec() / tm.getCounter(); +std::cout << "Average time in second per iteration is: " << average_time << std::endl; +@endcode +@sa getTickCount, getTickFrequency +*/ + +class CV_EXPORTS_W TickMeter +{ +public: + //! the default constructor + CV_WRAP TickMeter() + { + reset(); + } + + /** + starts counting ticks. + */ + CV_WRAP void start() + { + startTime = cv::getTickCount(); + } + + /** + stops counting ticks. + */ + CV_WRAP void stop() + { + int64 time = cv::getTickCount(); + if (startTime == 0) + return; + ++counter; + sumTime += (time - startTime); + startTime = 0; + } + + /** + returns counted ticks. + */ + CV_WRAP int64 getTimeTicks() const + { + return sumTime; + } + + /** + returns passed time in microseconds. + */ + CV_WRAP double getTimeMicro() const + { + return getTimeMilli()*1e3; + } + + /** + returns passed time in milliseconds. + */ + CV_WRAP double getTimeMilli() const + { + return getTimeSec()*1e3; + } + + /** + returns passed time in seconds. + */ + CV_WRAP double getTimeSec() const + { + return (double)getTimeTicks() / getTickFrequency(); + } + + /** + returns internal counter value. + */ + CV_WRAP int64 getCounter() const + { + return counter; + } + + /** + resets internal values. + */ + CV_WRAP void reset() + { + startTime = 0; + sumTime = 0; + counter = 0; + } + +private: + int64 counter; + int64 sumTime; + int64 startTime; +}; + +/** @brief output operator +@code +TickMeter tm; +tm.start(); +// do something ... +tm.stop(); +std::cout << tm; +@endcode +*/ + +static inline +std::ostream& operator << (std::ostream& out, const TickMeter& tm) +{ + return out << tm.getTimeSec() << "sec"; +} + +/** @brief Returns the number of CPU ticks. + +The function returns the current number of CPU ticks on some architectures (such as x86, x64, +PowerPC). On other platforms the function is equivalent to getTickCount. It can also be used for +very accurate time measurements, as well as for RNG initialization. Note that in case of multi-CPU +systems a thread, from which getCPUTickCount is called, can be suspended and resumed at another CPU +with its own counter. So, theoretically (and practically) the subsequent calls to the function do +not necessary return the monotonously increasing values. Also, since a modern CPU varies the CPU +frequency depending on the load, the number of CPU clocks spent in some code cannot be directly +converted to time units. Therefore, getTickCount is generally a preferable solution for measuring +execution time. + */ +CV_EXPORTS_W int64 getCPUTickCount(); + +/** @brief Returns true if the specified feature is supported by the host hardware. + +The function returns true if the host hardware supports the specified feature. When user calls +setUseOptimized(false), the subsequent calls to checkHardwareSupport() will return false until +setUseOptimized(true) is called. This way user can dynamically switch on and off the optimized code +in OpenCV. +@param feature The feature of interest, one of cv::CpuFeatures + */ +CV_EXPORTS_W bool checkHardwareSupport(int feature); + +/** @brief Returns feature name by ID + +Returns empty string if feature is not defined +*/ +CV_EXPORTS_W String getHardwareFeatureName(int feature); + +/** @brief Returns list of CPU features enabled during compilation. + +Returned value is a string containing space separated list of CPU features with following markers: + +- no markers - baseline features +- prefix `*` - features enabled in dispatcher +- suffix `?` - features enabled but not available in HW + +Example: `SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?` +*/ +CV_EXPORTS std::string getCPUFeaturesLine(); + +/** @brief Returns the number of logical CPUs available for the process. + */ +CV_EXPORTS_W int getNumberOfCPUs(); + + +/** @brief Aligns a pointer to the specified number of bytes. + +The function returns the aligned pointer of the same type as the input pointer: +\f[\texttt{(_Tp*)(((size_t)ptr + n-1) & -n)}\f] +@param ptr Aligned pointer. +@param n Alignment size that must be a power of two. + */ +template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp)) +{ + CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2 + return (_Tp*)(((size_t)ptr + n-1) & -n); +} + +/** @brief Aligns a buffer size to the specified number of bytes. + +The function returns the minimum number that is greater than or equal to sz and is divisible by n : +\f[\texttt{(sz + n-1) & -n}\f] +@param sz Buffer size to align. +@param n Alignment size that must be a power of two. + */ +static inline size_t alignSize(size_t sz, int n) +{ + CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2 + return (sz + n-1) & -n; +} + +/** @brief Integer division with result round up. + +Use this function instead of `ceil((float)a / b)` expressions. + +@sa alignSize +*/ +static inline int divUp(int a, unsigned int b) +{ + CV_DbgAssert(a >= 0); + return (a + b - 1) / b; +} +/** @overload */ +static inline size_t divUp(size_t a, unsigned int b) +{ + return (a + b - 1) / b; +} + +/** @brief Round first value up to the nearest multiple of second value. + +Use this function instead of `ceil((float)a / b) * b` expressions. + +@sa divUp +*/ +static inline int roundUp(int a, unsigned int b) +{ + CV_DbgAssert(a >= 0); + return a + b - 1 - (a + b -1) % b; +} +/** @overload */ +static inline size_t roundUp(size_t a, unsigned int b) +{ + return a + b - 1 - (a + b - 1) % b; +} + +/** @brief Enables or disables the optimized code. + +The function can be used to dynamically turn on and off optimized dispatched code (code that uses SSE4.2, AVX/AVX2, +and other instructions on the platforms that support it). It sets a global flag that is further +checked by OpenCV functions. Since the flag is not checked in the inner OpenCV loops, it is only +safe to call the function on the very top level in your application where you can be sure that no +other OpenCV function is currently executed. + +By default, the optimized code is enabled unless you disable it in CMake. The current status can be +retrieved using useOptimized. +@param onoff The boolean flag specifying whether the optimized code should be used (onoff=true) +or not (onoff=false). + */ +CV_EXPORTS_W void setUseOptimized(bool onoff); + +/** @brief Returns the status of optimized code usage. + +The function returns true if the optimized code is enabled. Otherwise, it returns false. + */ +CV_EXPORTS_W bool useOptimized(); + +static inline size_t getElemSize(int type) { return (size_t)CV_ELEM_SIZE(type); } + +/////////////////////////////// Parallel Primitives ////////////////////////////////// + +/** @brief Base class for parallel data processors +*/ +class CV_EXPORTS ParallelLoopBody +{ +public: + virtual ~ParallelLoopBody(); + virtual void operator() (const Range& range) const = 0; +}; + +/** @brief Parallel data processor +*/ +CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.); + +#ifdef CV_CXX11 +class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody +{ +private: + std::function<void(const Range&)> m_functor; +public: + ParallelLoopBodyLambdaWrapper(std::function<void(const Range&)> functor) : + m_functor(functor) + { } + + virtual void operator() (const cv::Range& range) const CV_OVERRIDE + { + m_functor(range); + } +}; + +inline void parallel_for_(const Range& range, std::function<void(const Range&)> functor, double nstripes=-1.) +{ + parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes); +} +#endif + +/////////////////////////////// forEach method of cv::Mat //////////////////////////// +template<typename _Tp, typename Functor> inline +void Mat::forEach_impl(const Functor& operation) { + if (false) { + operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast<int*>(0)); + // If your compiler fails in this line. + // Please check that your functor signature is + // (_Tp&, const int*) <- multi-dimensional + // or (_Tp&, void*) <- in case you don't need current idx. + } + + CV_Assert(this->total() / this->size[this->dims - 1] <= INT_MAX); + const int LINES = static_cast<int>(this->total() / this->size[this->dims - 1]); + + class PixelOperationWrapper :public ParallelLoopBody + { + public: + PixelOperationWrapper(Mat_<_Tp>* const frame, const Functor& _operation) + : mat(frame), op(_operation) {} + virtual ~PixelOperationWrapper(){} + // ! Overloaded virtual operator + // convert range call to row call. + virtual void operator()(const Range &range) const CV_OVERRIDE + { + const int DIMS = mat->dims; + const int COLS = mat->size[DIMS - 1]; + if (DIMS <= 2) { + for (int row = range.start; row < range.end; ++row) { + this->rowCall2(row, COLS); + } + } else { + std::vector<int> idx(DIMS); /// idx is modified in this->rowCall + idx[DIMS - 2] = range.start - 1; + + for (int line_num = range.start; line_num < range.end; ++line_num) { + idx[DIMS - 2]++; + for (int i = DIMS - 2; i >= 0; --i) { + if (idx[i] >= mat->size[i]) { + idx[i - 1] += idx[i] / mat->size[i]; + idx[i] %= mat->size[i]; + continue; // carry-over; + } + else { + break; + } + } + this->rowCall(&idx[0], COLS, DIMS); + } + } + } + private: + Mat_<_Tp>* const mat; + const Functor op; + // ! Call operator for each elements in this row. + inline void rowCall(int* const idx, const int COLS, const int DIMS) const { + int &col = idx[DIMS - 1]; + col = 0; + _Tp* pixel = &(mat->template at<_Tp>(idx)); + + while (col < COLS) { + op(*pixel, const_cast<const int*>(idx)); + pixel++; col++; + } + col = 0; + } + // ! Call operator for each elements in this row. 2d mat special version. + inline void rowCall2(const int row, const int COLS) const { + union Index{ + int body[2]; + operator const int*() const { + return reinterpret_cast<const int*>(this); + } + int& operator[](const int i) { + return body[i]; + } + } idx = {{row, 0}}; + // Special union is needed to avoid + // "error: array subscript is above array bounds [-Werror=array-bounds]" + // when call the functor `op` such that access idx[3]. + + _Tp* pixel = &(mat->template at<_Tp>(idx)); + const _Tp* const pixel_end = pixel + COLS; + while(pixel < pixel_end) { + op(*pixel++, static_cast<const int*>(idx)); + idx[1]++; + } + } + PixelOperationWrapper& operator=(const PixelOperationWrapper &) { + CV_Assert(false); + // We can not remove this implementation because Visual Studio warning C4822. + return *this; + } + }; + + parallel_for_(cv::Range(0, LINES), PixelOperationWrapper(reinterpret_cast<Mat_<_Tp>*>(this), operation)); +} + +/////////////////////////// Synchronization Primitives /////////////////////////////// + +class CV_EXPORTS Mutex +{ +public: + Mutex(); + ~Mutex(); + Mutex(const Mutex& m); + Mutex& operator = (const Mutex& m); + + void lock(); + bool trylock(); + void unlock(); + + struct Impl; +protected: + Impl* impl; +}; + +class CV_EXPORTS AutoLock +{ +public: + AutoLock(Mutex& m) : mutex(&m) { mutex->lock(); } + ~AutoLock() { mutex->unlock(); } +protected: + Mutex* mutex; +private: + AutoLock(const AutoLock&); + AutoLock& operator = (const AutoLock&); +}; + +// TLS interface +class CV_EXPORTS TLSDataContainer +{ +protected: + TLSDataContainer(); + virtual ~TLSDataContainer(); + + void gatherData(std::vector<void*> &data) const; +#if OPENCV_ABI_COMPATIBILITY > 300 + void* getData() const; + void release(); + +private: +#else + void release(); + +public: + void* getData() const; +#endif + virtual void* createDataInstance() const = 0; + virtual void deleteDataInstance(void* pData) const = 0; + + int key_; + +public: + void cleanup(); //! Release created TLS data container objects. It is similar to release() call, but it keeps TLS container valid. +}; + +// Main TLS data class +template <typename T> +class TLSData : protected TLSDataContainer +{ +public: + inline TLSData() {} + inline ~TLSData() { release(); } // Release key and delete associated data + inline T* get() const { return (T*)getData(); } // Get data associated with key + inline T& getRef() const { T* ptr = (T*)getData(); CV_Assert(ptr); return *ptr; } // Get data associated with key + + // Get data from all threads + inline void gather(std::vector<T*> &data) const + { + std::vector<void*> &dataVoid = reinterpret_cast<std::vector<void*>&>(data); + gatherData(dataVoid); + } + + inline void cleanup() { TLSDataContainer::cleanup(); } + +private: + virtual void* createDataInstance() const CV_OVERRIDE {return new T;} // Wrapper to allocate data by template + virtual void deleteDataInstance(void* pData) const CV_OVERRIDE {delete (T*)pData;} // Wrapper to release data by template + + // Disable TLS copy operations + TLSData(TLSData &) {} + TLSData& operator =(const TLSData &) {return *this;} +}; + +/** @brief Designed for command line parsing + +The sample below demonstrates how to use CommandLineParser: +@code + CommandLineParser parser(argc, argv, keys); + parser.about("Application name v1.0.0"); + + if (parser.has("help")) + { + parser.printMessage(); + return 0; + } + + int N = parser.get<int>("N"); + double fps = parser.get<double>("fps"); + String path = parser.get<String>("path"); + + use_time_stamp = parser.has("timestamp"); + + String img1 = parser.get<String>(0); + String img2 = parser.get<String>(1); + + int repeat = parser.get<int>(2); + + if (!parser.check()) + { + parser.printErrors(); + return 0; + } +@endcode + +### Keys syntax + +The keys parameter is a string containing several blocks, each one is enclosed in curly braces and +describes one argument. Each argument contains three parts separated by the `|` symbol: + +-# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the `@` symbol) +-# default value will be used if the argument was not provided (can be empty) +-# help message (can be empty) + +For example: + +@code{.cpp} + const String keys = + "{help h usage ? | | print this message }" + "{@image1 | | image1 for compare }" + "{@image2 |<none>| image2 for compare }" + "{@repeat |1 | number }" + "{path |. | path to file }" + "{fps | -1.0 | fps for output video }" + "{N count |100 | count of objects }" + "{ts timestamp | | use time stamp }" + ; +} +@endcode + +Note that there are no default values for `help` and `timestamp` so we can check their presence using the `has()` method. +Arguments with default values are considered to be always present. Use the `get()` method in these cases to check their +actual value instead. + +String keys like `get<String>("@image1")` return the empty string `""` by default - even with an empty default value. +Use the special `<none>` default value to enforce that the returned string must not be empty. (like in `get<String>("@image2")`) + +### Usage + +For the described keys: + +@code{.sh} + # Good call (3 positional parameters: image1, image2 and repeat; N is 200, ts is true) + $ ./app -N=200 1.png 2.jpg 19 -ts + + # Bad call + $ ./app -fps=aaa + ERRORS: + Parameter 'fps': can not convert: [aaa] to [double] +@endcode + */ +class CV_EXPORTS CommandLineParser +{ +public: + + /** @brief Constructor + + Initializes command line parser object + + @param argc number of command line arguments (from main()) + @param argv array of command line arguments (from main()) + @param keys string describing acceptable command line parameters (see class description for syntax) + */ + CommandLineParser(int argc, const char* const argv[], const String& keys); + + /** @brief Copy constructor */ + CommandLineParser(const CommandLineParser& parser); + + /** @brief Assignment operator */ + CommandLineParser& operator = (const CommandLineParser& parser); + + /** @brief Destructor */ + ~CommandLineParser(); + + /** @brief Returns application path + + This method returns the path to the executable from the command line (`argv[0]`). + + For example, if the application has been started with such a command: + @code{.sh} + $ ./bin/my-executable + @endcode + this method will return `./bin`. + */ + String getPathToApplication() const; + + /** @brief Access arguments by name + + Returns argument converted to selected type. If the argument is not known or can not be + converted to selected type, the error flag is set (can be checked with @ref check). + + For example, define: + @code{.cpp} + String keys = "{N count||}"; + @endcode + + Call: + @code{.sh} + $ ./my-app -N=20 + # or + $ ./my-app --count=20 + @endcode + + Access: + @code{.cpp} + int N = parser.get<int>("N"); + @endcode + + @param name name of the argument + @param space_delete remove spaces from the left and right of the string + @tparam T the argument will be converted to this type if possible + + @note You can access positional arguments by their `@`-prefixed name: + @code{.cpp} + parser.get<String>("@image"); + @endcode + */ + template <typename T> + T get(const String& name, bool space_delete = true) const + { + T val = T(); + getByName(name, space_delete, ParamType<T>::type, (void*)&val); + return val; + } + + /** @brief Access positional arguments by index + + Returns argument converted to selected type. Indexes are counted from zero. + + For example, define: + @code{.cpp} + String keys = "{@arg1||}{@arg2||}" + @endcode + + Call: + @code{.sh} + ./my-app abc qwe + @endcode + + Access arguments: + @code{.cpp} + String val_1 = parser.get<String>(0); // returns "abc", arg1 + String val_2 = parser.get<String>(1); // returns "qwe", arg2 + @endcode + + @param index index of the argument + @param space_delete remove spaces from the left and right of the string + @tparam T the argument will be converted to this type if possible + */ + template <typename T> + T get(int index, bool space_delete = true) const + { + T val = T(); + getByIndex(index, space_delete, ParamType<T>::type, (void*)&val); + return val; + } + + /** @brief Check if field was provided in the command line + + @param name argument name to check + */ + bool has(const String& name) const; + + /** @brief Check for parsing errors + + Returns false if error occurred while accessing the parameters (bad conversion, missing arguments, + etc.). Call @ref printErrors to print error messages list. + */ + bool check() const; + + /** @brief Set the about message + + The about message will be shown when @ref printMessage is called, right before arguments table. + */ + void about(const String& message); + + /** @brief Print help message + + This method will print standard help message containing the about message and arguments description. + + @sa about + */ + void printMessage() const; + + /** @brief Print list of errors occurred + + @sa check + */ + void printErrors() const; + +protected: + void getByName(const String& name, bool space_delete, int type, void* dst) const; + void getByIndex(int index, bool space_delete, int type, void* dst) const; + + struct Impl; + Impl* impl; +}; + +//! @} core_utils + +//! @cond IGNORED + +/////////////////////////////// AutoBuffer implementation //////////////////////////////////////// + +template<typename _Tp, size_t fixed_size> inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer() +{ + ptr = buf; + sz = fixed_size; +} + +template<typename _Tp, size_t fixed_size> inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size) +{ + ptr = buf; + sz = fixed_size; + allocate(_size); +} + +template<typename _Tp, size_t fixed_size> inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf ) +{ + ptr = buf; + sz = fixed_size; + allocate(abuf.size()); + for( size_t i = 0; i < sz; i++ ) + ptr[i] = abuf.ptr[i]; +} + +template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>& +AutoBuffer<_Tp, fixed_size>::operator = (const AutoBuffer<_Tp, fixed_size>& abuf) +{ + if( this != &abuf ) + { + deallocate(); + allocate(abuf.size()); + for( size_t i = 0; i < sz; i++ ) + ptr[i] = abuf.ptr[i]; + } + return *this; +} + +template<typename _Tp, size_t fixed_size> inline +AutoBuffer<_Tp, fixed_size>::~AutoBuffer() +{ deallocate(); } + +template<typename _Tp, size_t fixed_size> inline void +AutoBuffer<_Tp, fixed_size>::allocate(size_t _size) +{ + if(_size <= sz) + { + sz = _size; + return; + } + deallocate(); + sz = _size; + if(_size > fixed_size) + { + ptr = new _Tp[_size]; + } +} + +template<typename _Tp, size_t fixed_size> inline void +AutoBuffer<_Tp, fixed_size>::deallocate() +{ + if( ptr != buf ) + { + delete[] ptr; + ptr = buf; + sz = fixed_size; + } +} + +template<typename _Tp, size_t fixed_size> inline void +AutoBuffer<_Tp, fixed_size>::resize(size_t _size) +{ + if(_size <= sz) + { + sz = _size; + return; + } + size_t i, prevsize = sz, minsize = MIN(prevsize, _size); + _Tp* prevptr = ptr; + + ptr = _size > fixed_size ? new _Tp[_size] : buf; + sz = _size; + + if( ptr != prevptr ) + for( i = 0; i < minsize; i++ ) + ptr[i] = prevptr[i]; + for( i = prevsize; i < _size; i++ ) + ptr[i] = _Tp(); + + if( prevptr != buf ) + delete[] prevptr; +} + +template<typename _Tp, size_t fixed_size> inline size_t +AutoBuffer<_Tp, fixed_size>::size() const +{ return sz; } + +template<> inline std::string CommandLineParser::get<std::string>(int index, bool space_delete) const +{ + return get<String>(index, space_delete); +} +template<> inline std::string CommandLineParser::get<std::string>(const String& name, bool space_delete) const +{ + return get<String>(name, space_delete); +} + +//! @endcond + + +// Basic Node class for tree building +template<class OBJECT> +class CV_EXPORTS Node +{ +public: + Node() + { + m_pParent = 0; + } + Node(OBJECT& payload) : m_payload(payload) + { + m_pParent = 0; + } + ~Node() + { + removeChilds(); + if (m_pParent) + { + int idx = m_pParent->findChild(this); + if (idx >= 0) + m_pParent->m_childs.erase(m_pParent->m_childs.begin() + idx); + } + } + + Node<OBJECT>* findChild(OBJECT& payload) const + { + for(size_t i = 0; i < this->m_childs.size(); i++) + { + if(this->m_childs[i]->m_payload == payload) + return this->m_childs[i]; + } + return NULL; + } + + int findChild(Node<OBJECT> *pNode) const + { + for (size_t i = 0; i < this->m_childs.size(); i++) + { + if(this->m_childs[i] == pNode) + return (int)i; + } + return -1; + } + + void addChild(Node<OBJECT> *pNode) + { + if(!pNode) + return; + + CV_Assert(pNode->m_pParent == 0); + pNode->m_pParent = this; + this->m_childs.push_back(pNode); + } + + void removeChilds() + { + for(size_t i = 0; i < m_childs.size(); i++) + { + m_childs[i]->m_pParent = 0; // avoid excessive parent vector trimming + delete m_childs[i]; + } + m_childs.clear(); + } + + int getDepth() + { + int count = 0; + Node *pParent = m_pParent; + while(pParent) count++, pParent = pParent->m_pParent; + return count; + } + +public: + OBJECT m_payload; + Node<OBJECT>* m_pParent; + std::vector<Node<OBJECT>*> m_childs; +}; + +// Instrumentation external interface +namespace instr +{ + +#if !defined OPENCV_ABI_CHECK + +enum TYPE +{ + TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function + TYPE_MARKER, // Information marker + TYPE_WRAPPER, // Wrapper function for implementation + TYPE_FUN, // Simple function call +}; + +enum IMPL +{ + IMPL_PLAIN = 0, + IMPL_IPP, + IMPL_OPENCL, +}; + +struct NodeDataTls +{ + NodeDataTls() + { + m_ticksTotal = 0; + } + uint64 m_ticksTotal; +}; + +class CV_EXPORTS NodeData +{ +public: + NodeData(const char* funName = 0, const char* fileName = NULL, int lineNum = 0, void* retAddress = NULL, bool alwaysExpand = false, cv::instr::TYPE instrType = TYPE_GENERAL, cv::instr::IMPL implType = IMPL_PLAIN); + NodeData(NodeData &ref); + ~NodeData(); + NodeData& operator=(const NodeData&); + + cv::String m_funName; + cv::instr::TYPE m_instrType; + cv::instr::IMPL m_implType; + const char* m_fileName; + int m_lineNum; + void* m_retAddress; + bool m_alwaysExpand; + bool m_funError; + + volatile int m_counter; + volatile uint64 m_ticksTotal; + TLSData<NodeDataTls> m_tls; + int m_threads; + + // No synchronization + double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; } + double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; } +}; +bool operator==(const NodeData& lhs, const NodeData& rhs); + +typedef Node<NodeData> InstrNode; + +CV_EXPORTS InstrNode* getTrace(); + +#endif // !defined OPENCV_ABI_CHECK + + +CV_EXPORTS bool useInstrumentation(); +CV_EXPORTS void setUseInstrumentation(bool flag); +CV_EXPORTS void resetTrace(); + +enum FLAGS +{ + FLAGS_NONE = 0, + FLAGS_MAPPING = 0x01, + FLAGS_EXPAND_SAME_NAMES = 0x02, +}; + +CV_EXPORTS void setFlags(FLAGS modeFlags); +static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); } +CV_EXPORTS FLAGS getFlags(); + +} // namespace instr + + +namespace samples { + +//! @addtogroup core_utils_samples +// This section describes utility functions for OpenCV samples. +// +// @note Implementation of these utilities is not thread-safe. +// +//! @{ + +/** @brief Try to find requested data file + +Search directories: + +1. Directories passed via `addSamplesDataSearchPath()` +2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable +3. OPENCV_SAMPLES_DATA_PATH environment variable + If parameter value is not empty and nothing is found then stop searching. +4. Detects build/install path based on: + a. current working directory (CWD) + b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage) +5. Scan `<source>/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree. +6. Scan `<install>/share/OpenCV` directory if install directory is detected. + +@see cv::utils::findDataFile + +@param relative_path Relative path to data file +@param required Specify "file not found" handling. + If true, function prints information message and raises cv::Exception. + If false, function returns empty result +@param silentMode Disables messages +@return Returns path (absolute or relative to the current directory) or empty string if file is not found +*/ +CV_EXPORTS_W cv::String findFile(const cv::String& relative_path, bool required = true, bool silentMode = false); + +CV_EXPORTS_W cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode = false); + +inline cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode) +{ + cv::String res = findFile(relative_path, false, silentMode); + if (res.empty()) + return relative_path; + return res; +} + +/** @brief Override search data path by adding new search location + +Use this only to override default behavior +Passed paths are used in LIFO order. + +@param path Path to used samples data +*/ +CV_EXPORTS_W void addSamplesDataSearchPath(const cv::String& path); + +/** @brief Append samples search data sub directory + +General usage is to add OpenCV modules name (`<opencv_contrib>/modules/<name>/samples/data` -> `<name>/samples/data` + `modules/<name>/samples/data`). +Passed subdirectories are used in LIFO order. + +@param subdir samples data sub directory +*/ +CV_EXPORTS_W void addSamplesDataSearchSubDirectory(const cv::String& subdir); + +//! @} +} // namespace samples + +namespace utils { + +CV_EXPORTS int getThreadID(); + +} // namespace + +} //namespace cv + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/core/core_c.h" +#endif + +#endif //OPENCV_CORE_UTILITY_H diff --git a/include/opencv2/core/utils/filesystem.hpp b/include/opencv2/core/utils/filesystem.hpp new file mode 100644 index 0000000..00b0dd1 --- /dev/null +++ b/include/opencv2/core/utils/filesystem.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_UTILS_FILESYSTEM_HPP +#define OPENCV_UTILS_FILESYSTEM_HPP + +namespace cv { namespace utils { namespace fs { + + +CV_EXPORTS bool exists(const cv::String& path); +CV_EXPORTS bool isDirectory(const cv::String& path); + +CV_EXPORTS void remove_all(const cv::String& path); + + +CV_EXPORTS cv::String getcwd(); + +/** @brief Converts path p to a canonical absolute path + * Symlinks are processed if there is support for them on running platform. + * + * @param path input path. Target file/directory should exist. + */ +CV_EXPORTS cv::String canonical(const cv::String& path); + +/** Join path components */ +CV_EXPORTS cv::String join(const cv::String& base, const cv::String& path); + +/** + * Generate a list of all files that match the globbing pattern. + * + * Result entries are prefixed by base directory path. + * + * @param directory base directory + * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results + * @param[out] result result of globing. + * @param recursive scan nested directories too + * @param includeDirectories include directories into results list + */ +CV_EXPORTS void glob(const cv::String& directory, const cv::String& pattern, + CV_OUT std::vector<cv::String>& result, + bool recursive = false, bool includeDirectories = false); + +/** + * Generate a list of all files that match the globbing pattern. + * + * @param directory base directory + * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results + * @param[out] result globbing result with relative paths from base directory + * @param recursive scan nested directories too + * @param includeDirectories include directories into results list + */ +CV_EXPORTS void glob_relative(const cv::String& directory, const cv::String& pattern, + CV_OUT std::vector<cv::String>& result, + bool recursive = false, bool includeDirectories = false); + + +CV_EXPORTS bool createDirectory(const cv::String& path); +CV_EXPORTS bool createDirectories(const cv::String& path); + +#ifdef __OPENCV_BUILD +// TODO +//CV_EXPORTS cv::String getTempDirectory(); + +/** + * @brief Returns directory to store OpenCV cache files + * Create sub-directory in common OpenCV cache directory if it doesn't exist. + * @param sub_directory_name name of sub-directory. NULL or "" value asks to return root cache directory. + * @param configuration_name optional name of configuration parameter name which overrides default behavior. + * @return Path to cache directory. Returns empty string if cache directories support is not available. Returns "disabled" if cache disabled by user. + */ +CV_EXPORTS cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name = NULL); + +#endif + +}}} // namespace + +#endif // OPENCV_UTILS_FILESYSTEM_HPP diff --git a/include/opencv2/core/utils/logger.defines.hpp b/include/opencv2/core/utils/logger.defines.hpp new file mode 100644 index 0000000..b2dfc41 --- /dev/null +++ b/include/opencv2/core/utils/logger.defines.hpp @@ -0,0 +1,22 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_LOGGER_DEFINES_HPP +#define OPENCV_LOGGER_DEFINES_HPP + +//! @addtogroup core_logging +//! @{ + +// Supported logging levels and their semantic +#define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogLevel() call +#define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error) +#define CV_LOG_LEVEL_ERROR 2 //!< Error message +#define CV_LOG_LEVEL_WARN 3 //!< Warning message +#define CV_LOG_LEVEL_INFO 4 //!< Info message +#define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build. +#define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. + +//! @} + +#endif // OPENCV_LOGGER_DEFINES_HPP diff --git a/include/opencv2/core/utils/logger.hpp b/include/opencv2/core/utils/logger.hpp new file mode 100644 index 0000000..47094f9 --- /dev/null +++ b/include/opencv2/core/utils/logger.hpp @@ -0,0 +1,87 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_LOGGER_HPP +#define OPENCV_LOGGER_HPP + +#include <iostream> +#include <sstream> +#include <limits.h> // INT_MAX + +#include "logger.defines.hpp" + +//! @addtogroup core_logging +// This section describes OpenCV logging utilities. +// +//! @{ + +namespace cv { +namespace utils { +namespace logging { + +//! Supported logging levels and their semantic +enum LogLevel { + LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call + LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error) + LOG_LEVEL_ERROR = 2, //!< Error message + LOG_LEVEL_WARNING = 3, //!< Warning message + LOG_LEVEL_INFO = 4, //!< Info message + LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build. + LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. +#ifndef CV_DOXYGEN + ENUM_LOG_LEVEL_FORCE_INT = INT_MAX +#endif +}; + +/** Set global logging level +@return previous logging level +*/ +CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel); +/** Get global logging level */ +CV_EXPORTS LogLevel getLogLevel(); + +namespace internal { +/** Write log message */ +CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); +} // namespace + +/** + * \def CV_LOG_STRIP_LEVEL + * + * Define CV_LOG_STRIP_LEVEL=CV_LOG_LEVEL_[DEBUG|INFO|WARN|ERROR|FATAL|DISABLED] to compile out anything at that and before that logging level + */ +#ifndef CV_LOG_STRIP_LEVEL +# if defined NDEBUG +# define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG +# else +# define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE +# endif +#endif + + +#define CV_LOG_FATAL(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_FATAL) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_FATAL, ss.str().c_str()); break; } +#define CV_LOG_ERROR(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_ERROR) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_ERROR, ss.str().c_str()); break; } +#define CV_LOG_WARNING(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_WARNING) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_WARNING, ss.str().c_str()); break; } +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO +#define CV_LOG_INFO(tag, ...) +#else +#define CV_LOG_INFO(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_INFO) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_INFO, ss.str().c_str()); break; } +#endif +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG +#define CV_LOG_DEBUG(tag, ...) +#else +#define CV_LOG_DEBUG(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_DEBUG) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_DEBUG, ss.str().c_str()); break; } +#endif +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE +#define CV_LOG_VERBOSE(tag, v, ...) +#else +#define CV_LOG_VERBOSE(tag, v, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_VERBOSE) break; std::stringstream ss; ss << "[VERB" << v << ":" << cv::utils::getThreadID() << "] " << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_VERBOSE, ss.str().c_str()); break; } +#endif + + +}}} // namespace + +//! @} + +#endif // OPENCV_LOGGER_HPP diff --git a/include/opencv2/core/utils/trace.hpp b/include/opencv2/core/utils/trace.hpp new file mode 100644 index 0000000..858e973 --- /dev/null +++ b/include/opencv2/core/utils/trace.hpp @@ -0,0 +1,254 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_TRACE_HPP +#define OPENCV_TRACE_HPP + +#include <opencv2/core/cvdef.h> + +//! @addtogroup core_logging +// This section describes OpenCV tracing utilities. +// +//! @{ + +namespace cv { +namespace utils { +namespace trace { + +//! Macro to trace function +#define CV_TRACE_FUNCTION() + +#define CV_TRACE_FUNCTION_SKIP_NESTED() + +//! Trace code scope. +//! @note Dynamic names are not supported in this macro (on stack or heap). Use string literals here only, like "initialize". +#define CV_TRACE_REGION(name_as_static_string_literal) +//! mark completed of the current opened region and create new one +//! @note Dynamic names are not supported in this macro (on stack or heap). Use string literals here only, like "step1". +#define CV_TRACE_REGION_NEXT(name_as_static_string_literal) + +//! Macro to trace argument value +#define CV_TRACE_ARG(arg_id) + +//! Macro to trace argument value (expanded version) +#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value) + +//! @cond IGNORED +#define CV_TRACE_NS cv::utils::trace + +#if !defined(OPENCV_DISABLE_TRACE) && defined(__EMSCRIPTEN__) +#define OPENCV_DISABLE_TRACE 1 +#endif + +namespace details { + +#ifndef __OPENCV_TRACE +# if defined __OPENCV_BUILD && !defined __OPENCV_TESTS && !defined __OPENCV_APPS +# define __OPENCV_TRACE 1 +# else +# define __OPENCV_TRACE 0 +# endif +#endif + +#ifndef CV_TRACE_FILENAME +# define CV_TRACE_FILENAME __FILE__ +#endif + +#ifndef CV__TRACE_FUNCTION +# if defined _MSC_VER +# define CV__TRACE_FUNCTION __FUNCSIG__ +# elif defined __GNUC__ +# define CV__TRACE_FUNCTION __PRETTY_FUNCTION__ +# else +# define CV__TRACE_FUNCTION "<unknown>" +# endif +#endif + +//! Thread-local instance (usually allocated on stack) +class CV_EXPORTS Region +{ +public: + struct LocationExtraData; + struct LocationStaticStorage + { + LocationExtraData** ppExtra; //< implementation specific data + const char* name; //< region name (function name or other custom name) + const char* filename; //< source code filename + int line; //< source code line + int flags; //< flags (implementation code path: Plain, IPP, OpenCL) + }; + + Region(const LocationStaticStorage& location); + inline ~Region() + { + if (implFlags != 0) + destroy(); + CV_DbgAssert(implFlags == 0); + CV_DbgAssert(pImpl == NULL); + } + + class Impl; + Impl* pImpl; // NULL if current region is not active + int implFlags; // see RegionFlag, 0 if region is ignored + + bool isActive() const { return pImpl != NULL; } + + void destroy(); +private: + Region(const Region&); // disabled + Region& operator= (const Region&); // disabled +}; + +//! Specify region flags +enum RegionLocationFlag { + REGION_FLAG_FUNCTION = (1 << 0), //< region is function (=1) / nested named region (=0) + REGION_FLAG_APP_CODE = (1 << 1), //< region is Application code (=1) / OpenCV library code (=0) + REGION_FLAG_SKIP_NESTED = (1 << 2), //< avoid processing of nested regions + + REGION_FLAG_IMPL_IPP = (1 << 16), //< region is part of IPP code path + REGION_FLAG_IMPL_OPENCL = (2 << 16), //< region is part of OpenCL code path + REGION_FLAG_IMPL_OPENVX = (3 << 16), //< region is part of OpenVX code path + + REGION_FLAG_IMPL_MASK = (15 << 16), + + REGION_FLAG_REGION_FORCE = (1 << 30), + REGION_FLAG_REGION_NEXT = (1 << 31), //< close previous region (see #CV_TRACE_REGION_NEXT macro) + + ENUM_REGION_FLAG_FORCE_INT = INT_MAX +}; + +struct CV_EXPORTS TraceArg { +public: + struct ExtraData; + ExtraData** ppExtra; + const char* name; + int flags; +}; +/** @brief Add meta information to current region (function) + * See CV_TRACE_ARG macro + * @param arg argument information structure (global static cache) + * @param value argument value (can by dynamic string literal in case of string, static allocation is not required) + */ +CV_EXPORTS void traceArg(const TraceArg& arg, const char* value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, int value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, int64 value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, double value); + +#define CV__TRACE_LOCATION_VARNAME(loc_id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_trace_location_, loc_id), __LINE__) +#define CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_trace_location_extra_, loc_id) , __LINE__) + +#define CV__TRACE_DEFINE_LOCATION_(loc_id, name, flags) \ + static CV_TRACE_NS::details::Region::LocationExtraData* CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id) = 0; \ + static const CV_TRACE_NS::details::Region::LocationStaticStorage \ + CV__TRACE_LOCATION_VARNAME(loc_id) = { &(CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id)), name, CV_TRACE_FILENAME, __LINE__, flags}; + +#define CV__TRACE_DEFINE_LOCATION_FN(name, flags) CV__TRACE_DEFINE_LOCATION_(fn, name, ((flags) | CV_TRACE_NS::details::REGION_FLAG_FUNCTION)) + + +#define CV__TRACE_OPENCV_FUNCTION() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, 0); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_OPENCV_FUNCTION_NAME(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, 0); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION_NAME(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + + +#define CV__TRACE_OPENCV_FUNCTION_SKIP_NESTED() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_OPENCV_FUNCTION_NAME_SKIP_NESTED(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION_SKIP_NESTED() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED | CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + + +#define CV__TRACE_REGION_(name_as_static_string_literal, flags) \ + CV__TRACE_DEFINE_LOCATION_(region, name_as_static_string_literal, flags); \ + CV_TRACE_NS::details::Region CVAUX_CONCAT(__region_, __LINE__)(CV__TRACE_LOCATION_VARNAME(region)); + +#define CV__TRACE_REGION(name_as_static_string_literal) CV__TRACE_REGION_(name_as_static_string_literal, 0) +#define CV__TRACE_REGION_NEXT(name_as_static_string_literal) CV__TRACE_REGION_(name_as_static_string_literal, CV_TRACE_NS::details::REGION_FLAG_REGION_NEXT) + +#define CV__TRACE_ARG_VARNAME(arg_id) CVAUX_CONCAT(__cv_trace_arg_ ## arg_id, __LINE__) +#define CV__TRACE_ARG_EXTRA_VARNAME(arg_id) CVAUX_CONCAT(__cv_trace_arg_extra_ ## arg_id, __LINE__) + +#define CV__TRACE_DEFINE_ARG_(arg_id, name, flags) \ + static CV_TRACE_NS::details::TraceArg::ExtraData* CV__TRACE_ARG_EXTRA_VARNAME(arg_id) = 0; \ + static const CV_TRACE_NS::details::TraceArg \ + CV__TRACE_ARG_VARNAME(arg_id) = { &(CV__TRACE_ARG_EXTRA_VARNAME(arg_id)), name, flags }; + +#define CV__TRACE_ARG_VALUE(arg_id, arg_name, value) \ + CV__TRACE_DEFINE_ARG_(arg_id, arg_name, 0); \ + CV_TRACE_NS::details::traceArg((CV__TRACE_ARG_VARNAME(arg_id)), value); + +#define CV__TRACE_ARG(arg_id) CV_TRACE_ARG_VALUE(arg_id, #arg_id, (arg_id)) + +} // namespace + +#ifndef OPENCV_DISABLE_TRACE +#undef CV_TRACE_FUNCTION +#undef CV_TRACE_FUNCTION_SKIP_NESTED +#if __OPENCV_TRACE +#define CV_TRACE_FUNCTION CV__TRACE_OPENCV_FUNCTION +#define CV_TRACE_FUNCTION_SKIP_NESTED CV__TRACE_OPENCV_FUNCTION_SKIP_NESTED +#else +#define CV_TRACE_FUNCTION CV__TRACE_APP_FUNCTION +#define CV_TRACE_FUNCTION_SKIP_NESTED CV__TRACE_APP_FUNCTION_SKIP_NESTED +#endif + +#undef CV_TRACE_REGION +#define CV_TRACE_REGION CV__TRACE_REGION + +#undef CV_TRACE_REGION_NEXT +#define CV_TRACE_REGION_NEXT CV__TRACE_REGION_NEXT + +#undef CV_TRACE_ARG_VALUE +#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value) \ + if (__region_fn.isActive()) \ + { \ + CV__TRACE_ARG_VALUE(arg_id, arg_name, value); \ + } + +#undef CV_TRACE_ARG +#define CV_TRACE_ARG CV__TRACE_ARG + +#endif // OPENCV_DISABLE_TRACE + +#ifdef OPENCV_TRACE_VERBOSE +#define CV_TRACE_FUNCTION_VERBOSE CV_TRACE_FUNCTION +#define CV_TRACE_REGION_VERBOSE CV_TRACE_REGION +#define CV_TRACE_REGION_NEXT_VERBOSE CV_TRACE_REGION_NEXT +#define CV_TRACE_ARG_VALUE_VERBOSE CV_TRACE_ARG_VALUE +#define CV_TRACE_ARG_VERBOSE CV_TRACE_ARG +#else +#define CV_TRACE_FUNCTION_VERBOSE(...) +#define CV_TRACE_REGION_VERBOSE(...) +#define CV_TRACE_REGION_NEXT_VERBOSE(...) +#define CV_TRACE_ARG_VALUE_VERBOSE(...) +#define CV_TRACE_ARG_VERBOSE(...) +#endif + +//! @endcond + +}}} // namespace + +//! @} + +#endif // OPENCV_TRACE_HPP diff --git a/include/opencv2/core/va_intel.hpp b/include/opencv2/core/va_intel.hpp new file mode 100644 index 0000000..f665470 --- /dev/null +++ b/include/opencv2/core/va_intel.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2015, Itseez, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. + +#ifndef OPENCV_CORE_VA_INTEL_HPP +#define OPENCV_CORE_VA_INTEL_HPP + +#ifndef __cplusplus +# error va_intel.hpp header must be compiled as C++ +#endif + +#include "opencv2/core.hpp" +#include "ocl.hpp" + +#if defined(HAVE_VA) +# include "va/va.h" +#else // HAVE_VA +# if !defined(_VA_H_) + typedef void* VADisplay; + typedef unsigned int VASurfaceID; +# endif // !_VA_H_ +#endif // HAVE_VA + +namespace cv { namespace va_intel { + +/** @addtogroup core_va_intel +This section describes Intel VA-API/OpenCL (CL-VA) interoperability. + +To enable CL-VA interoperability support, configure OpenCV using CMake with WITH_VA_INTEL=ON . Currently VA-API is +supported on Linux only. You should also install Intel Media Server Studio (MSS) to use this feature. You may +have to specify the path(s) to MSS components for cmake in environment variables: + +- VA_INTEL_IOCL_ROOT for Intel OpenCL (default is "/opt/intel/opencl"). + +To use CL-VA interoperability you should first create VADisplay (libva), and then call initializeContextFromVA() +function to create OpenCL context and set up interoperability. +*/ +//! @{ + +/////////////////// CL-VA Interoperability Functions /////////////////// + +namespace ocl { +using namespace cv::ocl; + +// TODO static functions in the Context class +/** @brief Creates OpenCL context from VA. +@param display - VADisplay for which CL interop should be established. +@param tryInterop - try to set up for interoperability, if true; set up for use slow copy if false. +@return Returns reference to OpenCL Context + */ +CV_EXPORTS Context& initializeContextFromVA(VADisplay display, bool tryInterop = true); + +} // namespace cv::va_intel::ocl + +/** @brief Converts InputArray to VASurfaceID object. +@param display - VADisplay object. +@param src - source InputArray. +@param surface - destination VASurfaceID object. +@param size - size of image represented by VASurfaceID object. + */ +CV_EXPORTS void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface, Size size); + +/** @brief Converts VASurfaceID object to OutputArray. +@param display - VADisplay object. +@param surface - source VASurfaceID object. +@param size - size of image represented by VASurfaceID object. +@param dst - destination OutputArray. + */ +CV_EXPORTS void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, OutputArray dst); + +//! @} + +}} // namespace cv::va_intel + +#endif /* OPENCV_CORE_VA_INTEL_HPP */ diff --git a/include/opencv2/core/version.hpp b/include/opencv2/core/version.hpp new file mode 100644 index 0000000..fe6df95 --- /dev/null +++ b/include/opencv2/core/version.hpp @@ -0,0 +1,26 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_VERSION_HPP +#define OPENCV_VERSION_HPP + +#define CV_VERSION_MAJOR 3 +#define CV_VERSION_MINOR 4 +#define CV_VERSION_REVISION 6 +#define CV_VERSION_STATUS "" + +#define CVAUX_STR_EXP(__A) #__A +#define CVAUX_STR(__A) CVAUX_STR_EXP(__A) + +#define CVAUX_STRW_EXP(__A) L ## #__A +#define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A) + +#define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS + +/* old style version constants*/ +#define CV_MAJOR_VERSION CV_VERSION_MAJOR +#define CV_MINOR_VERSION CV_VERSION_MINOR +#define CV_SUBMINOR_VERSION CV_VERSION_REVISION + +#endif // OPENCV_VERSION_HPP diff --git a/include/opencv2/core/vsx_utils.hpp b/include/opencv2/core/vsx_utils.hpp new file mode 100644 index 0000000..6e2baea --- /dev/null +++ b/include/opencv2/core/vsx_utils.hpp @@ -0,0 +1,1013 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_VSX_UTILS_HPP +#define OPENCV_HAL_VSX_UTILS_HPP + +#include "opencv2/core/cvdef.h" + +#ifndef SKIP_INCLUDES +# include <assert.h> +#endif + +//! @addtogroup core_utils_vsx +//! @{ +#if CV_VSX + +#define __VSX_S16__(c, v) (c){v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v} +#define __VSX_S8__(c, v) (c){v, v, v, v, v, v, v, v} +#define __VSX_S4__(c, v) (c){v, v, v, v} +#define __VSX_S2__(c, v) (c){v, v} + +typedef __vector unsigned char vec_uchar16; +#define vec_uchar16_set(...) (vec_uchar16){__VA_ARGS__} +#define vec_uchar16_sp(c) (__VSX_S16__(vec_uchar16, (unsigned char)c)) +#define vec_uchar16_c(v) ((vec_uchar16)(v)) +#define vec_uchar16_z vec_uchar16_sp(0) + +typedef __vector signed char vec_char16; +#define vec_char16_set(...) (vec_char16){__VA_ARGS__} +#define vec_char16_sp(c) (__VSX_S16__(vec_char16, (signed char)c)) +#define vec_char16_c(v) ((vec_char16)(v)) +#define vec_char16_z vec_char16_sp(0) + +typedef __vector unsigned short vec_ushort8; +#define vec_ushort8_set(...) (vec_ushort8){__VA_ARGS__} +#define vec_ushort8_sp(c) (__VSX_S8__(vec_ushort8, (unsigned short)c)) +#define vec_ushort8_c(v) ((vec_ushort8)(v)) +#define vec_ushort8_z vec_ushort8_sp(0) + +typedef __vector signed short vec_short8; +#define vec_short8_set(...) (vec_short8){__VA_ARGS__} +#define vec_short8_sp(c) (__VSX_S8__(vec_short8, (signed short)c)) +#define vec_short8_c(v) ((vec_short8)(v)) +#define vec_short8_z vec_short8_sp(0) + +typedef __vector unsigned int vec_uint4; +#define vec_uint4_set(...) (vec_uint4){__VA_ARGS__} +#define vec_uint4_sp(c) (__VSX_S4__(vec_uint4, (unsigned int)c)) +#define vec_uint4_c(v) ((vec_uint4)(v)) +#define vec_uint4_z vec_uint4_sp(0) + +typedef __vector signed int vec_int4; +#define vec_int4_set(...) (vec_int4){__VA_ARGS__} +#define vec_int4_sp(c) (__VSX_S4__(vec_int4, (signed int)c)) +#define vec_int4_c(v) ((vec_int4)(v)) +#define vec_int4_z vec_int4_sp(0) + +typedef __vector float vec_float4; +#define vec_float4_set(...) (vec_float4){__VA_ARGS__} +#define vec_float4_sp(c) (__VSX_S4__(vec_float4, c)) +#define vec_float4_c(v) ((vec_float4)(v)) +#define vec_float4_z vec_float4_sp(0) + +typedef __vector unsigned long long vec_udword2; +#define vec_udword2_set(...) (vec_udword2){__VA_ARGS__} +#define vec_udword2_sp(c) (__VSX_S2__(vec_udword2, (unsigned long long)c)) +#define vec_udword2_c(v) ((vec_udword2)(v)) +#define vec_udword2_z vec_udword2_sp(0) + +typedef __vector signed long long vec_dword2; +#define vec_dword2_set(...) (vec_dword2){__VA_ARGS__} +#define vec_dword2_sp(c) (__VSX_S2__(vec_dword2, (signed long long)c)) +#define vec_dword2_c(v) ((vec_dword2)(v)) +#define vec_dword2_z vec_dword2_sp(0) + +typedef __vector double vec_double2; +#define vec_double2_set(...) (vec_double2){__VA_ARGS__} +#define vec_double2_c(v) ((vec_double2)(v)) +#define vec_double2_sp(c) (__VSX_S2__(vec_double2, c)) +#define vec_double2_z vec_double2_sp(0) + +#define vec_bchar16 __vector __bool char +#define vec_bchar16_set(...) (vec_bchar16){__VA_ARGS__} +#define vec_bchar16_c(v) ((vec_bchar16)(v)) + +#define vec_bshort8 __vector __bool short +#define vec_bshort8_set(...) (vec_bshort8){__VA_ARGS__} +#define vec_bshort8_c(v) ((vec_bshort8)(v)) + +#define vec_bint4 __vector __bool int +#define vec_bint4_set(...) (vec_bint4){__VA_ARGS__} +#define vec_bint4_c(v) ((vec_bint4)(v)) + +#define vec_bdword2 __vector __bool long long +#define vec_bdword2_set(...) (vec_bdword2){__VA_ARGS__} +#define vec_bdword2_c(v) ((vec_bdword2)(v)) + +#define VSX_FINLINE(tp) extern inline tp __attribute__((always_inline)) + +#define VSX_REDIRECT_1RG(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fn2(a); } + +#define VSX_REDIRECT_2RG(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a, const rg& b) { return fn2(a, b); } + +/* + * GCC VSX compatibility +**/ +#if defined(__GNUG__) && !defined(__clang__) + +// inline asm helper +#define VSX_IMPL_1RG(rt, rto, rg, rgo, opc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ rt rs; __asm__ __volatile__(#opc" %x0,%x1" : "="#rto (rs) : #rgo (a)); return rs; } + +#define VSX_IMPL_1VRG(rt, rg, opc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ rt rs; __asm__ __volatile__(#opc" %0,%1" : "=v" (rs) : "v" (a)); return rs; } + +#define VSX_IMPL_2VRG_F(rt, rg, fopc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a, const rg& b) \ +{ rt rs; __asm__ __volatile__(fopc : "=v" (rs) : "v" (a), "v" (b)); return rs; } + +#define VSX_IMPL_2VRG(rt, rg, opc, fnm) VSX_IMPL_2VRG_F(rt, rg, #opc" %0,%1,%2", fnm) + +#if __GNUG__ < 7 +// up to GCC 6 vec_mul only supports precisions and llong +# ifdef vec_mul +# undef vec_mul +# endif +/* + * there's no a direct instruction for supporting 8-bit, 16-bit multiplication in ISA 2.07, + * XLC Implement it by using instruction "multiply even", "multiply odd" and "permute" +**/ +# define VSX_IMPL_MULH(Tvec, cperm) \ + VSX_FINLINE(Tvec) vec_mul(const Tvec& a, const Tvec& b) \ + { \ + static const vec_uchar16 ev_od = {cperm}; \ + return vec_perm((Tvec)vec_mule(a, b), (Tvec)vec_mulo(a, b), ev_od); \ + } + #define VSX_IMPL_MULH_P16 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30 + VSX_IMPL_MULH(vec_char16, VSX_IMPL_MULH_P16) + VSX_IMPL_MULH(vec_uchar16, VSX_IMPL_MULH_P16) + #define VSX_IMPL_MULH_P8 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29 + VSX_IMPL_MULH(vec_short8, VSX_IMPL_MULH_P8) + VSX_IMPL_MULH(vec_ushort8, VSX_IMPL_MULH_P8) + // vmuluwm can be used for unsigned or signed integers, that's what they said + VSX_IMPL_2VRG(vec_int4, vec_int4, vmuluwm, vec_mul) + VSX_IMPL_2VRG(vec_uint4, vec_uint4, vmuluwm, vec_mul) + // redirect to GCC builtin vec_mul, since it already supports precisions and llong + VSX_REDIRECT_2RG(vec_float4, vec_float4, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mul, __builtin_vec_mul) +#endif // __GNUG__ < 7 + +#if __GNUG__ < 6 +/* + * Instruction "compare greater than or equal" in ISA 2.07 only supports single + * and double precision. + * In XLC and new versions of GCC implement integers by using instruction "greater than" and NOR. +**/ +# ifdef vec_cmpge +# undef vec_cmpge +# endif +# ifdef vec_cmple +# undef vec_cmple +# endif +# define vec_cmple(a, b) vec_cmpge(b, a) +# define VSX_IMPL_CMPGE(rt, rg, opc, fnm) \ + VSX_IMPL_2VRG_F(rt, rg, #opc" %0,%2,%1\n\t xxlnor %x0,%x0,%x0", fnm) + + VSX_IMPL_CMPGE(vec_bchar16, vec_char16, vcmpgtsb, vec_cmpge) + VSX_IMPL_CMPGE(vec_bchar16, vec_uchar16, vcmpgtub, vec_cmpge) + VSX_IMPL_CMPGE(vec_bshort8, vec_short8, vcmpgtsh, vec_cmpge) + VSX_IMPL_CMPGE(vec_bshort8, vec_ushort8, vcmpgtuh, vec_cmpge) + VSX_IMPL_CMPGE(vec_bint4, vec_int4, vcmpgtsw, vec_cmpge) + VSX_IMPL_CMPGE(vec_bint4, vec_uint4, vcmpgtuw, vec_cmpge) + VSX_IMPL_CMPGE(vec_bdword2, vec_dword2, vcmpgtsd, vec_cmpge) + VSX_IMPL_CMPGE(vec_bdword2, vec_udword2, vcmpgtud, vec_cmpge) + +// redirect to GCC builtin cmpge, since it already supports precisions + VSX_REDIRECT_2RG(vec_bint4, vec_float4, vec_cmpge, __builtin_vec_cmpge) + VSX_REDIRECT_2RG(vec_bdword2, vec_double2, vec_cmpge, __builtin_vec_cmpge) + +// up to gcc5 vec_nor doesn't support bool long long +# undef vec_nor + template<typename T> + VSX_REDIRECT_2RG(T, T, vec_nor, __builtin_vec_nor) + + VSX_FINLINE(vec_bdword2) vec_nor(const vec_bdword2& a, const vec_bdword2& b) + { return vec_bdword2_c(__builtin_vec_nor(vec_dword2_c(a), vec_dword2_c(b))); } + +// vec_packs doesn't support double words in gcc4 and old versions of gcc5 +# undef vec_packs + VSX_REDIRECT_2RG(vec_char16, vec_short8, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_uchar16, vec_ushort8, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_short8, vec_int4, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_ushort8, vec_uint4, vec_packs, __builtin_vec_packs) + + VSX_IMPL_2VRG_F(vec_int4, vec_dword2, "vpksdss %0,%2,%1", vec_packs) + VSX_IMPL_2VRG_F(vec_uint4, vec_udword2, "vpkudus %0,%2,%1", vec_packs) +#endif // __GNUG__ < 6 + +#if __GNUG__ < 5 +// vec_xxpermdi in gcc4 missing little-endian supports just like clang +# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ (((c) & 1) << 1 | (c) >> 1))) +#else +# define vec_permi vec_xxpermdi +#endif // __GNUG__ < 5 + +// shift left double by word immediate +#ifndef vec_sldw +# define vec_sldw __builtin_vsx_xxsldwi +#endif + +// vector population count +VSX_IMPL_1VRG(vec_uchar16, vec_uchar16, vpopcntb, vec_popcntu) +VSX_IMPL_1VRG(vec_uchar16, vec_char16, vpopcntb, vec_popcntu) +VSX_IMPL_1VRG(vec_ushort8, vec_ushort8, vpopcnth, vec_popcntu) +VSX_IMPL_1VRG(vec_ushort8, vec_short8, vpopcnth, vec_popcntu) +VSX_IMPL_1VRG(vec_uint4, vec_uint4, vpopcntw, vec_popcntu) +VSX_IMPL_1VRG(vec_uint4, vec_int4, vpopcntw, vec_popcntu) +VSX_IMPL_1VRG(vec_udword2, vec_udword2, vpopcntd, vec_popcntu) +VSX_IMPL_1VRG(vec_udword2, vec_dword2, vpopcntd, vec_popcntu) + +// converts between single and double-precision +VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp) +VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp) + +// converts word and doubleword to double-precision +#ifdef vec_ctd +# undef vec_ctd +#endif +VSX_IMPL_1RG(vec_double2, wd, vec_int4, wa, xvcvsxwdp, vec_ctdo) +VSX_IMPL_1RG(vec_double2, wd, vec_uint4, wa, xvcvuxwdp, vec_ctdo) +VSX_IMPL_1RG(vec_double2, wd, vec_dword2, wi, xvcvsxddp, vec_ctd) +VSX_IMPL_1RG(vec_double2, wd, vec_udword2, wi, xvcvuxddp, vec_ctd) + +// converts word and doubleword to single-precision +#undef vec_ctf +VSX_IMPL_1RG(vec_float4, wf, vec_int4, wa, xvcvsxwsp, vec_ctf) +VSX_IMPL_1RG(vec_float4, wf, vec_uint4, wa, xvcvuxwsp, vec_ctf) +VSX_IMPL_1RG(vec_float4, wf, vec_dword2, wi, xvcvsxdsp, vec_ctfo) +VSX_IMPL_1RG(vec_float4, wf, vec_udword2, wi, xvcvuxdsp, vec_ctfo) + +// converts single and double precision to signed word +#undef vec_cts +VSX_IMPL_1RG(vec_int4, wa, vec_double2, wd, xvcvdpsxws, vec_ctso) +VSX_IMPL_1RG(vec_int4, wa, vec_float4, wf, xvcvspsxws, vec_cts) + +// converts single and double precision to unsigned word +#undef vec_ctu +VSX_IMPL_1RG(vec_uint4, wa, vec_double2, wd, xvcvdpuxws, vec_ctuo) +VSX_IMPL_1RG(vec_uint4, wa, vec_float4, wf, xvcvspuxws, vec_ctu) + +// converts single and double precision to signed doubleword +#ifdef vec_ctsl +# undef vec_ctsl +#endif +VSX_IMPL_1RG(vec_dword2, wi, vec_double2, wd, xvcvdpsxds, vec_ctsl) +VSX_IMPL_1RG(vec_dword2, wi, vec_float4, wf, xvcvspsxds, vec_ctslo) + +// converts single and double precision to unsigned doubleword +#ifdef vec_ctul +# undef vec_ctul +#endif +VSX_IMPL_1RG(vec_udword2, wi, vec_double2, wd, xvcvdpuxds, vec_ctul) +VSX_IMPL_1RG(vec_udword2, wi, vec_float4, wf, xvcvspuxds, vec_ctulo) + +// just in case if GCC doesn't define it +#ifndef vec_xl +# define vec_xl vec_vsx_ld +# define vec_xst vec_vsx_st +#endif + +#endif // GCC VSX compatibility + +/* + * CLANG VSX compatibility +**/ +#if defined(__clang__) && !defined(__IBMCPP__) + +/* + * CLANG doesn't support %x<n> in the inline asm template which fixes register number + * when using any of the register constraints wa, wd, wf + * + * For more explanation checkout PowerPC and IBM RS6000 in https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html + * Also there's already an open bug https://bugs.llvm.org/show_bug.cgi?id=31837 + * + * So we're not able to use inline asm and only use built-in functions that CLANG supports + * and use __builtin_convertvector if clang missng any of vector conversions built-in functions + * + * todo: clang asm template bug is fixed, need to reconsider the current workarounds. +*/ + +// convert vector helper +#define VSX_IMPL_CONVERT(rt, rg, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) { return __builtin_convertvector(a, rt); } + +#if __clang_major__ < 5 +// implement vec_permi in a dirty way +# define VSX_IMPL_CLANG_4_PERMI(Tvec) \ + VSX_FINLINE(Tvec) vec_permi(const Tvec& a, const Tvec& b, unsigned const char c) \ + { \ + switch (c) \ + { \ + case 0: \ + return vec_mergeh(a, b); \ + case 1: \ + return vec_mergel(vec_mergeh(a, a), b); \ + case 2: \ + return vec_mergeh(vec_mergel(a, a), b); \ + default: \ + return vec_mergel(a, b); \ + } \ + } + VSX_IMPL_CLANG_4_PERMI(vec_udword2) + VSX_IMPL_CLANG_4_PERMI(vec_dword2) + VSX_IMPL_CLANG_4_PERMI(vec_double2) + +// vec_xxsldwi is missing in clang 4 +# define vec_xxsldwi(a, b, c) vec_sld(a, b, (c) * 4) +#else +// vec_xxpermdi is missing little-endian supports in clang 4 just like gcc4 +# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ (((c) & 1) << 1 | (c) >> 1))) +#endif // __clang_major__ < 5 + +// shift left double by word immediate +#ifndef vec_sldw +# define vec_sldw vec_xxsldwi +#endif + +// Implement vec_rsqrt since clang only supports vec_rsqrte +#ifndef vec_rsqrt + VSX_FINLINE(vec_float4) vec_rsqrt(const vec_float4& a) + { return vec_div(vec_float4_sp(1), vec_sqrt(a)); } + + VSX_FINLINE(vec_double2) vec_rsqrt(const vec_double2& a) + { return vec_div(vec_double2_sp(1), vec_sqrt(a)); } +#endif + +// vec_promote missing support for doubleword +VSX_FINLINE(vec_dword2) vec_promote(long long a, int b) +{ + vec_dword2 ret = vec_dword2_z; + ret[b & 1] = a; + return ret; +} + +VSX_FINLINE(vec_udword2) vec_promote(unsigned long long a, int b) +{ + vec_udword2 ret = vec_udword2_z; + ret[b & 1] = a; + return ret; +} + +// vec_popcnt should return unsigned but clang has different thought just like gcc in vec_vpopcnt +#define VSX_IMPL_POPCNTU(Tvec, Tvec2, ucast) \ +VSX_FINLINE(Tvec) vec_popcntu(const Tvec2& a) \ +{ return ucast(vec_popcnt(a)); } +VSX_IMPL_POPCNTU(vec_uchar16, vec_char16, vec_uchar16_c); +VSX_IMPL_POPCNTU(vec_ushort8, vec_short8, vec_ushort8_c); +VSX_IMPL_POPCNTU(vec_uint4, vec_int4, vec_uint4_c); +// redirect unsigned types +VSX_REDIRECT_1RG(vec_uchar16, vec_uchar16, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_ushort8, vec_ushort8, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_uint4, vec_uint4, vec_popcntu, vec_popcnt) + +// converts between single and double precision +VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp) +VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp) + +// converts word and doubleword to double-precision +#ifdef vec_ctd +# undef vec_ctd +#endif +VSX_REDIRECT_1RG(vec_double2, vec_int4, vec_ctdo, __builtin_vsx_xvcvsxwdp) +VSX_REDIRECT_1RG(vec_double2, vec_uint4, vec_ctdo, __builtin_vsx_xvcvuxwdp) + +VSX_IMPL_CONVERT(vec_double2, vec_dword2, vec_ctd) +VSX_IMPL_CONVERT(vec_double2, vec_udword2, vec_ctd) + +// converts word and doubleword to single-precision +#if __clang_major__ > 4 +# undef vec_ctf +#endif +VSX_IMPL_CONVERT(vec_float4, vec_int4, vec_ctf) +VSX_IMPL_CONVERT(vec_float4, vec_uint4, vec_ctf) +VSX_REDIRECT_1RG(vec_float4, vec_dword2, vec_ctfo, __builtin_vsx_xvcvsxdsp) +VSX_REDIRECT_1RG(vec_float4, vec_udword2, vec_ctfo, __builtin_vsx_xvcvuxdsp) + +// converts single and double precision to signed word +#if __clang_major__ > 4 +# undef vec_cts +#endif +VSX_REDIRECT_1RG(vec_int4, vec_double2, vec_ctso, __builtin_vsx_xvcvdpsxws) +VSX_IMPL_CONVERT(vec_int4, vec_float4, vec_cts) + +// converts single and double precision to unsigned word +#if __clang_major__ > 4 +# undef vec_ctu +#endif +VSX_REDIRECT_1RG(vec_uint4, vec_double2, vec_ctuo, __builtin_vsx_xvcvdpuxws) +VSX_IMPL_CONVERT(vec_uint4, vec_float4, vec_ctu) + +// converts single and double precision to signed doubleword +#ifdef vec_ctsl +# undef vec_ctsl +#endif +VSX_IMPL_CONVERT(vec_dword2, vec_double2, vec_ctsl) +// __builtin_convertvector unable to convert, xvcvspsxds is missing on it +VSX_FINLINE(vec_dword2) vec_ctslo(const vec_float4& a) +{ return vec_ctsl(vec_cvfo(a)); } + +// converts single and double precision to unsigned doubleword +#ifdef vec_ctul +# undef vec_ctul +#endif +VSX_IMPL_CONVERT(vec_udword2, vec_double2, vec_ctul) +// __builtin_convertvector unable to convert, xvcvspuxds is missing on it +VSX_FINLINE(vec_udword2) vec_ctulo(const vec_float4& a) +{ return vec_ctul(vec_cvfo(a)); } + +#endif // CLANG VSX compatibility + +/* + * Common GCC, CLANG compatibility +**/ +#if defined(__GNUG__) && !defined(__IBMCPP__) + +#ifdef vec_cvf +# undef vec_cvf +#endif + +#define VSX_IMPL_CONV_EVEN_4_2(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ return fn2(vec_sldw(a, a, 1)); } + +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_float4, vec_cvf, vec_cvfo) +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_int4, vec_ctd, vec_ctdo) +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_uint4, vec_ctd, vec_ctdo) + +VSX_IMPL_CONV_EVEN_4_2(vec_dword2, vec_float4, vec_ctsl, vec_ctslo) +VSX_IMPL_CONV_EVEN_4_2(vec_udword2, vec_float4, vec_ctul, vec_ctulo) + +#define VSX_IMPL_CONV_EVEN_2_4(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ \ + rt v4 = fn2(a); \ + return vec_sldw(v4, v4, 3); \ +} + +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_double2, vec_cvf, vec_cvfo) +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_dword2, vec_ctf, vec_ctfo) +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_udword2, vec_ctf, vec_ctfo) + +VSX_IMPL_CONV_EVEN_2_4(vec_int4, vec_double2, vec_cts, vec_ctso) +VSX_IMPL_CONV_EVEN_2_4(vec_uint4, vec_double2, vec_ctu, vec_ctuo) + +// Only for Eigen! +/* + * changing behavior of conversion intrinsics for gcc has effect on Eigen + * so we redfine old behavior again only on gcc, clang +*/ +#if !defined(__clang__) || __clang_major__ > 4 + // ignoring second arg since Eigen only truncates toward zero +# define VSX_IMPL_CONV_2VARIANT(rt, rg, fnm, fn2) \ + VSX_FINLINE(rt) fnm(const rg& a, int only_truncate) \ + { \ + assert(only_truncate == 0); \ + CV_UNUSED(only_truncate); \ + return fn2(a); \ + } + VSX_IMPL_CONV_2VARIANT(vec_int4, vec_float4, vec_cts, vec_cts) + VSX_IMPL_CONV_2VARIANT(vec_float4, vec_int4, vec_ctf, vec_ctf) + // define vec_cts for converting double precision to signed doubleword + // which isn't combitable with xlc but its okay since Eigen only use it for gcc + VSX_IMPL_CONV_2VARIANT(vec_dword2, vec_double2, vec_cts, vec_ctsl) +#endif // Eigen + +#endif // Common GCC, CLANG compatibility + +/* + * XLC VSX compatibility +**/ +#if defined(__IBMCPP__) + +// vector population count +#define vec_popcntu vec_popcnt + +// overload and redirect with setting second arg to zero +// since we only support conversions without the second arg +#define VSX_IMPL_OVERLOAD_Z2(rt, rg, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fnm(a, 0); } + +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_int4, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_uint4, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_dword2, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_udword2, vec_ctd) + +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_int4, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_uint4, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_dword2, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_udword2, vec_ctf) + +VSX_IMPL_OVERLOAD_Z2(vec_int4, vec_double2, vec_cts) +VSX_IMPL_OVERLOAD_Z2(vec_int4, vec_float4, vec_cts) + +VSX_IMPL_OVERLOAD_Z2(vec_uint4, vec_double2, vec_ctu) +VSX_IMPL_OVERLOAD_Z2(vec_uint4, vec_float4, vec_ctu) + +VSX_IMPL_OVERLOAD_Z2(vec_dword2, vec_double2, vec_ctsl) +VSX_IMPL_OVERLOAD_Z2(vec_dword2, vec_float4, vec_ctsl) + +VSX_IMPL_OVERLOAD_Z2(vec_udword2, vec_double2, vec_ctul) +VSX_IMPL_OVERLOAD_Z2(vec_udword2, vec_float4, vec_ctul) + +// fixme: implement conversions of odd-numbered elements in a dirty way +// since xlc doesn't support VSX registers operand in inline asm. +#define VSX_IMPL_CONV_ODD_4_2(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fn2(vec_sldw(a, a, 3)); } + +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_float4, vec_cvfo, vec_cvf) +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_int4, vec_ctdo, vec_ctd) +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_uint4, vec_ctdo, vec_ctd) + +VSX_IMPL_CONV_ODD_4_2(vec_dword2, vec_float4, vec_ctslo, vec_ctsl) +VSX_IMPL_CONV_ODD_4_2(vec_udword2, vec_float4, vec_ctulo, vec_ctul) + +#define VSX_IMPL_CONV_ODD_2_4(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ \ + rt v4 = fn2(a); \ + return vec_sldw(v4, v4, 1); \ +} + +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_double2, vec_cvfo, vec_cvf) +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_dword2, vec_ctfo, vec_ctf) +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_udword2, vec_ctfo, vec_ctf) + +VSX_IMPL_CONV_ODD_2_4(vec_int4, vec_double2, vec_ctso, vec_cts) +VSX_IMPL_CONV_ODD_2_4(vec_uint4, vec_double2, vec_ctuo, vec_ctu) + +#endif // XLC VSX compatibility + +// ignore GCC warning that caused by -Wunused-but-set-variable in rare cases +#if defined(__GNUG__) && !defined(__clang__) +# define VSX_UNUSED(Tvec) Tvec __attribute__((__unused__)) +#else // CLANG, XLC +# define VSX_UNUSED(Tvec) Tvec +#endif + +// gcc can find his way in casting log int and XLC, CLANG ambiguous +#if defined(__clang__) || defined(__IBMCPP__) + VSX_FINLINE(vec_udword2) vec_splats(uint64 v) + { return vec_splats((unsigned long long) v); } + + VSX_FINLINE(vec_dword2) vec_splats(int64 v) + { return vec_splats((long long) v); } + + VSX_FINLINE(vec_udword2) vec_promote(uint64 a, int b) + { return vec_promote((unsigned long long) a, b); } + + VSX_FINLINE(vec_dword2) vec_promote(int64 a, int b) + { return vec_promote((long long) a, b); } +#endif + +/* + * implement vsx_ld(offset, pointer), vsx_st(vector, offset, pointer) + * load and set using offset depend on the pointer type + * + * implement vsx_ldf(offset, pointer), vsx_stf(vector, offset, pointer) + * load and set using offset depend on fixed bytes size + * + * Note: In clang vec_xl and vec_xst fails to load unaligned addresses + * so we are using vec_vsx_ld, vec_vsx_st instead +*/ + +#if defined(__clang__) && !defined(__IBMCPP__) +# define vsx_ldf vec_vsx_ld +# define vsx_stf vec_vsx_st +#else // GCC , XLC +# define vsx_ldf vec_xl +# define vsx_stf vec_xst +#endif + +#define VSX_OFFSET(o, p) ((o) * sizeof(*(p))) +#define vsx_ld(o, p) vsx_ldf(VSX_OFFSET(o, p), p) +#define vsx_st(v, o, p) vsx_stf(v, VSX_OFFSET(o, p), p) + +/* + * implement vsx_ld2(offset, pointer), vsx_st2(vector, offset, pointer) to load and store double words + * In GCC vec_xl and vec_xst it maps to vec_vsx_ld, vec_vsx_st which doesn't support long long + * and in CLANG we are using vec_vsx_ld, vec_vsx_st because vec_xl, vec_xst fails to load unaligned addresses + * + * In XLC vec_xl and vec_xst fail to cast int64(long int) to long long +*/ +#if (defined(__GNUG__) || defined(__clang__)) && !defined(__IBMCPP__) + VSX_FINLINE(vec_udword2) vsx_ld2(long o, const uint64* p) + { return vec_udword2_c(vsx_ldf(VSX_OFFSET(o, p), (unsigned int*)p)); } + + VSX_FINLINE(vec_dword2) vsx_ld2(long o, const int64* p) + { return vec_dword2_c(vsx_ldf(VSX_OFFSET(o, p), (int*)p)); } + + VSX_FINLINE(void) vsx_st2(const vec_udword2& vec, long o, uint64* p) + { vsx_stf(vec_uint4_c(vec), VSX_OFFSET(o, p), (unsigned int*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_dword2& vec, long o, int64* p) + { vsx_stf(vec_int4_c(vec), VSX_OFFSET(o, p), (int*)p); } +#else // XLC + VSX_FINLINE(vec_udword2) vsx_ld2(long o, const uint64* p) + { return vsx_ldf(VSX_OFFSET(o, p), (unsigned long long*)p); } + + VSX_FINLINE(vec_dword2) vsx_ld2(long o, const int64* p) + { return vsx_ldf(VSX_OFFSET(o, p), (long long*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_udword2& vec, long o, uint64* p) + { vsx_stf(vec, VSX_OFFSET(o, p), (unsigned long long*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_dword2& vec, long o, int64* p) + { vsx_stf(vec, VSX_OFFSET(o, p), (long long*)p); } +#endif + +// Store lower 8 byte +#define vec_st_l8(v, p) *((uint64*)(p)) = vec_extract(vec_udword2_c(v), 0) + +// Store higher 8 byte +#define vec_st_h8(v, p) *((uint64*)(p)) = vec_extract(vec_udword2_c(v), 1) + +// Load 64-bits of integer data to lower part +#define VSX_IMPL_LOAD_L8(Tvec, Tp) \ +VSX_FINLINE(Tvec) vec_ld_l8(const Tp *p) \ +{ return ((Tvec)vec_promote(*((uint64*)p), 0)); } + +VSX_IMPL_LOAD_L8(vec_uchar16, uchar) +VSX_IMPL_LOAD_L8(vec_char16, schar) +VSX_IMPL_LOAD_L8(vec_ushort8, ushort) +VSX_IMPL_LOAD_L8(vec_short8, short) +VSX_IMPL_LOAD_L8(vec_uint4, uint) +VSX_IMPL_LOAD_L8(vec_int4, int) +VSX_IMPL_LOAD_L8(vec_float4, float) +VSX_IMPL_LOAD_L8(vec_udword2, uint64) +VSX_IMPL_LOAD_L8(vec_dword2, int64) +VSX_IMPL_LOAD_L8(vec_double2, double) + +// logical not +#define vec_not(a) vec_nor(a, a) + +// power9 yaya +// not equal +#ifndef vec_cmpne +# define vec_cmpne(a, b) vec_not(vec_cmpeq(a, b)) +#endif + +// absolute difference +#ifndef vec_absd +# define vec_absd(a, b) vec_sub(vec_max(a, b), vec_min(a, b)) +#endif + +/* + * Implement vec_unpacklu and vec_unpackhu + * since vec_unpackl, vec_unpackh only support signed integers +**/ +#define VSX_IMPL_UNPACKU(rt, rg, zero) \ +VSX_FINLINE(rt) vec_unpacklu(const rg& a) \ +{ return (rt)(vec_mergel(a, zero)); } \ +VSX_FINLINE(rt) vec_unpackhu(const rg& a) \ +{ return (rt)(vec_mergeh(a, zero)); } + +VSX_IMPL_UNPACKU(vec_ushort8, vec_uchar16, vec_uchar16_z) +VSX_IMPL_UNPACKU(vec_uint4, vec_ushort8, vec_ushort8_z) +VSX_IMPL_UNPACKU(vec_udword2, vec_uint4, vec_uint4_z) + +/* + * Implement vec_mergesqe and vec_mergesqo + * Merges the sequence values of even and odd elements of two vectors +*/ +#define VSX_IMPL_PERM(rt, fnm, ...) \ +VSX_FINLINE(rt) fnm(const rt& a, const rt& b) \ +{ static const vec_uchar16 perm = {__VA_ARGS__}; return vec_perm(a, b, perm); } + +// 16 +#define perm16_mergesqe 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 +#define perm16_mergesqo 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 +VSX_IMPL_PERM(vec_uchar16, vec_mergesqe, perm16_mergesqe) +VSX_IMPL_PERM(vec_uchar16, vec_mergesqo, perm16_mergesqo) +VSX_IMPL_PERM(vec_char16, vec_mergesqe, perm16_mergesqe) +VSX_IMPL_PERM(vec_char16, vec_mergesqo, perm16_mergesqo) +// 8 +#define perm8_mergesqe 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 +#define perm8_mergesqo 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 +VSX_IMPL_PERM(vec_ushort8, vec_mergesqe, perm8_mergesqe) +VSX_IMPL_PERM(vec_ushort8, vec_mergesqo, perm8_mergesqo) +VSX_IMPL_PERM(vec_short8, vec_mergesqe, perm8_mergesqe) +VSX_IMPL_PERM(vec_short8, vec_mergesqo, perm8_mergesqo) +// 4 +#define perm4_mergesqe 0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27 +#define perm4_mergesqo 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31 +VSX_IMPL_PERM(vec_uint4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_uint4, vec_mergesqo, perm4_mergesqo) +VSX_IMPL_PERM(vec_int4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_int4, vec_mergesqo, perm4_mergesqo) +VSX_IMPL_PERM(vec_float4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_float4, vec_mergesqo, perm4_mergesqo) +// 2 +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqo, vec_mergel) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqo, vec_mergel) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqo, vec_mergel) + +/* + * Implement vec_mergesqh and vec_mergesql + * Merges the sequence most and least significant halves of two vectors +*/ +#define VSX_IMPL_MERGESQHL(Tvec) \ +VSX_FINLINE(Tvec) vec_mergesqh(const Tvec& a, const Tvec& b) \ +{ return (Tvec)vec_mergeh(vec_udword2_c(a), vec_udword2_c(b)); } \ +VSX_FINLINE(Tvec) vec_mergesql(const Tvec& a, const Tvec& b) \ +{ return (Tvec)vec_mergel(vec_udword2_c(a), vec_udword2_c(b)); } +VSX_IMPL_MERGESQHL(vec_uchar16) +VSX_IMPL_MERGESQHL(vec_char16) +VSX_IMPL_MERGESQHL(vec_ushort8) +VSX_IMPL_MERGESQHL(vec_short8) +VSX_IMPL_MERGESQHL(vec_uint4) +VSX_IMPL_MERGESQHL(vec_int4) +VSX_IMPL_MERGESQHL(vec_float4) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesql, vec_mergel) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesql, vec_mergel) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesql, vec_mergel) + + +// 2 and 4 channels interleave for all types except 2 lanes +#define VSX_IMPL_ST_INTERLEAVE(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, Tp* ptr) \ +{ \ + vsx_stf(vec_mergeh(a, b), 0, ptr); \ + vsx_stf(vec_mergel(a, b), 16, ptr); \ +} \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, const Tvec& d, Tp* ptr) \ +{ \ + Tvec ac = vec_mergeh(a, c); \ + Tvec bd = vec_mergeh(b, d); \ + vsx_stf(vec_mergeh(ac, bd), 0, ptr); \ + vsx_stf(vec_mergel(ac, bd), 16, ptr); \ + ac = vec_mergel(a, c); \ + bd = vec_mergel(b, d); \ + vsx_stf(vec_mergeh(ac, bd), 32, ptr); \ + vsx_stf(vec_mergel(ac, bd), 48, ptr); \ +} +VSX_IMPL_ST_INTERLEAVE(uchar, vec_uchar16) +VSX_IMPL_ST_INTERLEAVE(schar, vec_char16) +VSX_IMPL_ST_INTERLEAVE(ushort, vec_ushort8) +VSX_IMPL_ST_INTERLEAVE(short, vec_short8) +VSX_IMPL_ST_INTERLEAVE(uint, vec_uint4) +VSX_IMPL_ST_INTERLEAVE(int, vec_int4) +VSX_IMPL_ST_INTERLEAVE(float, vec_float4) + +// 2 and 4 channels deinterleave for 16 lanes +#define VSX_IMPL_ST_DINTERLEAVE_8(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(16, ptr); \ + a = vec_mergesqe(v0, v1); \ + b = vec_mergesqo(v0, v1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(16, ptr); \ + Tvec v2 = vsx_ld(32, ptr); \ + Tvec v3 = vsx_ld(48, ptr); \ + Tvec m0 = vec_mergesqe(v0, v1); \ + Tvec m1 = vec_mergesqe(v2, v3); \ + a = vec_mergesqe(m0, m1); \ + c = vec_mergesqo(m0, m1); \ + m0 = vec_mergesqo(v0, v1); \ + m1 = vec_mergesqo(v2, v3); \ + b = vec_mergesqe(m0, m1); \ + d = vec_mergesqo(m0, m1); \ +} +VSX_IMPL_ST_DINTERLEAVE_8(uchar, vec_uchar16) +VSX_IMPL_ST_DINTERLEAVE_8(schar, vec_char16) + +// 2 and 4 channels deinterleave for 8 lanes +#define VSX_IMPL_ST_DINTERLEAVE_16(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(8, ptr); \ + a = vec_mergesqe(v0, v1); \ + b = vec_mergesqo(v0, v1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(8, ptr); \ + Tvec m0 = vec_mergeh(v0, v1); \ + Tvec m1 = vec_mergel(v0, v1); \ + Tvec ab0 = vec_mergeh(m0, m1); \ + Tvec cd0 = vec_mergel(m0, m1); \ + v0 = vsx_ld(16, ptr); \ + v1 = vsx_ld(24, ptr); \ + m0 = vec_mergeh(v0, v1); \ + m1 = vec_mergel(v0, v1); \ + Tvec ab1 = vec_mergeh(m0, m1); \ + Tvec cd1 = vec_mergel(m0, m1); \ + a = vec_mergesqh(ab0, ab1); \ + b = vec_mergesql(ab0, ab1); \ + c = vec_mergesqh(cd0, cd1); \ + d = vec_mergesql(cd0, cd1); \ +} +VSX_IMPL_ST_DINTERLEAVE_16(ushort, vec_ushort8) +VSX_IMPL_ST_DINTERLEAVE_16(short, vec_short8) + +// 2 and 4 channels deinterleave for 4 lanes +#define VSX_IMPL_ST_DINTERLEAVE_32(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + a = vsx_ld(0, ptr); \ + b = vsx_ld(4, ptr); \ + Tvec m0 = vec_mergeh(a, b); \ + Tvec m1 = vec_mergel(a, b); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(4, ptr); \ + Tvec v2 = vsx_ld(8, ptr); \ + Tvec v3 = vsx_ld(12, ptr); \ + Tvec m0 = vec_mergeh(v0, v2); \ + Tvec m1 = vec_mergeh(v1, v3); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ + m0 = vec_mergel(v0, v2); \ + m1 = vec_mergel(v1, v3); \ + c = vec_mergeh(m0, m1); \ + d = vec_mergel(m0, m1); \ +} +VSX_IMPL_ST_DINTERLEAVE_32(uint, vec_uint4) +VSX_IMPL_ST_DINTERLEAVE_32(int, vec_int4) +VSX_IMPL_ST_DINTERLEAVE_32(float, vec_float4) + +// 2 and 4 channels interleave and deinterleave for 2 lanes +#define VSX_IMPL_ST_D_INTERLEAVE_64(Tp, Tvec, ld_func, st_func) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_mergel(a, b), 2, ptr); \ +} \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, const Tvec& d, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_mergeh(c, d), 2, ptr); \ + st_func(vec_mergel(a, b), 4, ptr); \ + st_func(vec_mergel(c, d), 6, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec m0 = ld_func(0, ptr); \ + Tvec m1 = ld_func(2, ptr); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = ld_func(0, ptr); \ + Tvec v1 = ld_func(2, ptr); \ + Tvec v2 = ld_func(4, ptr); \ + Tvec v3 = ld_func(6, ptr); \ + a = vec_mergeh(v0, v2); \ + b = vec_mergel(v0, v2); \ + c = vec_mergeh(v1, v3); \ + d = vec_mergel(v1, v3); \ +} +VSX_IMPL_ST_D_INTERLEAVE_64(int64, vec_dword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_D_INTERLEAVE_64(uint64, vec_udword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_D_INTERLEAVE_64(double, vec_double2, vsx_ld, vsx_st) + +/* 3 channels */ +#define VSX_IMPL_ST_INTERLEAVE_3CH_16(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + static const vec_uchar16 a12 = {0, 16, 0, 1, 17, 0, 2, 18, 0, 3, 19, 0, 4, 20, 0, 5}; \ + static const vec_uchar16 a123 = {0, 1, 16, 3, 4, 17, 6, 7, 18, 9, 10, 19, 12, 13, 20, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, a12), c, a123), 0, ptr); \ + static const vec_uchar16 b12 = {21, 0, 6, 22, 0, 7, 23, 0, 8, 24, 0, 9, 25, 0, 10, 26}; \ + static const vec_uchar16 b123 = {0, 21, 2, 3, 22, 5, 6, 23, 8, 9, 24, 11, 12, 25, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, b12), c, b123), 16, ptr); \ + static const vec_uchar16 c12 = {0, 11, 27, 0, 12, 28, 0, 13, 29, 0, 14, 30, 0, 15, 31, 0}; \ + static const vec_uchar16 c123 = {26, 1, 2, 27, 4, 5, 28, 7, 8, 29, 10, 11, 30, 13, 14, 31}; \ + vsx_st(vec_perm(vec_perm(a, b, c12), c, c123), 32, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(16, ptr); \ + Tvec v3 = vsx_ld(32, ptr); \ + static const vec_uchar16 a12_perm = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 a123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 17, 20, 23, 26, 29}; \ + a = vec_perm(vec_perm(v1, v2, a12_perm), v3, a123_perm); \ + static const vec_uchar16 b12_perm = {1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 b123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 18, 21, 24, 27, 30}; \ + b = vec_perm(vec_perm(v1, v2, b12_perm), v3, b123_perm); \ + static const vec_uchar16 c12_perm = {2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 c123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 19, 22, 25, 28, 31}; \ + c = vec_perm(vec_perm(v1, v2, c12_perm), v3, c123_perm); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_16(uchar, vec_uchar16) +VSX_IMPL_ST_INTERLEAVE_3CH_16(schar, vec_char16) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_8(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + static const vec_uchar16 a12 = {0, 1, 16, 17, 0, 0, 2, 3, 18, 19, 0, 0, 4, 5, 20, 21}; \ + static const vec_uchar16 a123 = {0, 1, 2, 3, 16, 17, 6, 7, 8, 9, 18, 19, 12, 13, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, a12), c, a123), 0, ptr); \ + static const vec_uchar16 b12 = {0, 0, 6, 7, 22, 23, 0, 0, 8, 9, 24, 25, 0, 0, 10, 11}; \ + static const vec_uchar16 b123 = {20, 21, 2, 3, 4, 5, 22, 23, 8, 9, 10, 11, 24, 25, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, b12), c, b123), 8, ptr); \ + static const vec_uchar16 c12 = {26, 27, 0, 0, 12, 13, 28, 29, 0, 0, 14, 15, 30, 31, 0, 0}; \ + static const vec_uchar16 c123 = {0, 1, 26, 27, 4, 5, 6, 7, 28, 29, 10, 11, 12, 13, 30, 31}; \ + vsx_st(vec_perm(vec_perm(a, b, c12), c, c123), 16, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(8, ptr); \ + Tvec v3 = vsx_ld(16, ptr); \ + static const vec_uchar16 a12_perm = {0, 1, 6, 7, 12, 13, 18, 19, 24, 25, 30, 31, 0, 0, 0, 0}; \ + static const vec_uchar16 a123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 26, 27}; \ + a = vec_perm(vec_perm(v1, v2, a12_perm), v3, a123_perm); \ + static const vec_uchar16 b12_perm = {2, 3, 8, 9, 14, 15, 20, 21, 26, 27, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 b123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 22, 23, 28, 29}; \ + b = vec_perm(vec_perm(v1, v2, b12_perm), v3, b123_perm); \ + static const vec_uchar16 c12_perm = {4, 5, 10, 11, 16, 17, 22, 23, 28, 29, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 c123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 19, 24, 25, 30, 31}; \ + c = vec_perm(vec_perm(v1, v2, c12_perm), v3, c123_perm); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_8(ushort, vec_ushort8) +VSX_IMPL_ST_INTERLEAVE_3CH_8(short, vec_short8) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_4(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + Tvec hbc = vec_mergeh(b, c); \ + static const vec_uchar16 ahbc = {0, 1, 2, 3, 16, 17, 18, 19, 20, 21, 22, 23, 4, 5, 6, 7}; \ + vsx_st(vec_perm(a, hbc, ahbc), 0, ptr); \ + Tvec lab = vec_mergel(a, b); \ + vsx_st(vec_sld(lab, hbc, 8), 4, ptr); \ + static const vec_uchar16 clab = {8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31, 12, 13, 14, 15};\ + vsx_st(vec_perm(c, lab, clab), 8, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(4, ptr); \ + Tvec v3 = vsx_ld(8, ptr); \ + static const vec_uchar16 flp = {0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19, 28, 29, 30, 31}; \ + a = vec_perm(v1, vec_sld(v3, v2, 8), flp); \ + static const vec_uchar16 flp2 = {28, 29, 30, 31, 0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19}; \ + b = vec_perm(v2, vec_sld(v1, v3, 8), flp2); \ + c = vec_perm(vec_sld(v2, v1, 8), v3, flp); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_4(uint, vec_uint4) +VSX_IMPL_ST_INTERLEAVE_3CH_4(int, vec_int4) +VSX_IMPL_ST_INTERLEAVE_3CH_4(float, vec_float4) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_2(Tp, Tvec, ld_func, st_func) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_permi(c, a, 1), 2, ptr); \ + st_func(vec_mergel(b, c), 4, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, \ + Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = ld_func(0, ptr); \ + Tvec v2 = ld_func(2, ptr); \ + Tvec v3 = ld_func(4, ptr); \ + a = vec_permi(v1, v2, 1); \ + b = vec_permi(v1, v3, 2); \ + c = vec_permi(v2, v3, 1); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_2(int64, vec_dword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_INTERLEAVE_3CH_2(uint64, vec_udword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_INTERLEAVE_3CH_2(double, vec_double2, vsx_ld, vsx_st) + +#endif // CV_VSX + +//! @} + +#endif // OPENCV_HAL_VSX_UTILS_HPP diff --git a/include/opencv2/core/wimage.hpp b/include/opencv2/core/wimage.hpp new file mode 100644 index 0000000..c7b6efa --- /dev/null +++ b/include/opencv2/core/wimage.hpp @@ -0,0 +1,603 @@ +/*M////////////////////////////////////////////////////////////////////////////// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2008, Google, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation or contributors may not 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 the Intel Corporation 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. +///////////////////////////////////////////////////////////////////////////////// +//M*/ + +#ifndef OPENCV_CORE_WIMAGE_HPP +#define OPENCV_CORE_WIMAGE_HPP + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus + +namespace cv { + +//! @addtogroup core +//! @{ + +template <typename T> class WImage; +template <typename T> class WImageBuffer; +template <typename T> class WImageView; + +template<typename T, int C> class WImageC; +template<typename T, int C> class WImageBufferC; +template<typename T, int C> class WImageViewC; + +// Commonly used typedefs. +typedef WImage<uchar> WImage_b; +typedef WImageView<uchar> WImageView_b; +typedef WImageBuffer<uchar> WImageBuffer_b; + +typedef WImageC<uchar, 1> WImage1_b; +typedef WImageViewC<uchar, 1> WImageView1_b; +typedef WImageBufferC<uchar, 1> WImageBuffer1_b; + +typedef WImageC<uchar, 3> WImage3_b; +typedef WImageViewC<uchar, 3> WImageView3_b; +typedef WImageBufferC<uchar, 3> WImageBuffer3_b; + +typedef WImage<float> WImage_f; +typedef WImageView<float> WImageView_f; +typedef WImageBuffer<float> WImageBuffer_f; + +typedef WImageC<float, 1> WImage1_f; +typedef WImageViewC<float, 1> WImageView1_f; +typedef WImageBufferC<float, 1> WImageBuffer1_f; + +typedef WImageC<float, 3> WImage3_f; +typedef WImageViewC<float, 3> WImageView3_f; +typedef WImageBufferC<float, 3> WImageBuffer3_f; + +// There isn't a standard for signed and unsigned short so be more +// explicit in the typename for these cases. +typedef WImage<short> WImage_16s; +typedef WImageView<short> WImageView_16s; +typedef WImageBuffer<short> WImageBuffer_16s; + +typedef WImageC<short, 1> WImage1_16s; +typedef WImageViewC<short, 1> WImageView1_16s; +typedef WImageBufferC<short, 1> WImageBuffer1_16s; + +typedef WImageC<short, 3> WImage3_16s; +typedef WImageViewC<short, 3> WImageView3_16s; +typedef WImageBufferC<short, 3> WImageBuffer3_16s; + +typedef WImage<ushort> WImage_16u; +typedef WImageView<ushort> WImageView_16u; +typedef WImageBuffer<ushort> WImageBuffer_16u; + +typedef WImageC<ushort, 1> WImage1_16u; +typedef WImageViewC<ushort, 1> WImageView1_16u; +typedef WImageBufferC<ushort, 1> WImageBuffer1_16u; + +typedef WImageC<ushort, 3> WImage3_16u; +typedef WImageViewC<ushort, 3> WImageView3_16u; +typedef WImageBufferC<ushort, 3> WImageBuffer3_16u; + +/** @brief Image class which provides a thin layer around an IplImage. + +The goals of the class design are: + + -# All the data has explicit ownership to avoid memory leaks + -# No hidden allocations or copies for performance. + -# Easy access to OpenCV methods (which will access IPP if available) + -# Can easily treat external data as an image + -# Easy to create images which are subsets of other images + -# Fast pixel access which can take advantage of number of channels if known at compile time. + +The WImage class is the image class which provides the data accessors. The 'W' comes from the fact +that it is also a wrapper around the popular but inconvenient IplImage class. A WImage can be +constructed either using a WImageBuffer class which allocates and frees the data, or using a +WImageView class which constructs a subimage or a view into external data. The view class does no +memory management. Each class actually has two versions, one when the number of channels is known +at compile time and one when it isn't. Using the one with the number of channels specified can +provide some compile time optimizations by using the fact that the number of channels is a +constant. + +We use the convention (c,r) to refer to column c and row r with (0,0) being the upper left corner. +This is similar to standard Euclidean coordinates with the first coordinate varying in the +horizontal direction and the second coordinate varying in the vertical direction. Thus (c,r) is +usually in the domain [0, width) X [0, height) + +Example usage: +@code +WImageBuffer3_b im(5,7); // Make a 5X7 3 channel image of type uchar +WImageView3_b sub_im(im, 2,2, 3,3); // 3X3 submatrix +vector<float> vec(10, 3.0f); +WImageView1_f user_im(&vec[0], 2, 5); // 2X5 image w/ supplied data + +im.SetZero(); // same as cvSetZero(im.Ipl()) +*im(2, 3) = 15; // Modify the element at column 2, row 3 +MySetRand(&sub_im); + +// Copy the second row into the first. This can be done with no memory +// allocation and will use SSE if IPP is available. +int w = im.Width(); +im.View(0,0, w,1).CopyFrom(im.View(0,1, w,1)); + +// Doesn't care about source of data since using WImage +void MySetRand(WImage_b* im) { // Works with any number of channels +for (int r = 0; r < im->Height(); ++r) { + float* row = im->Row(r); + for (int c = 0; c < im->Width(); ++c) { + for (int ch = 0; ch < im->Channels(); ++ch, ++row) { + *row = uchar(rand() & 255); + } + } +} +} +@endcode + +Functions that are not part of the basic image allocation, viewing, and access should come from +OpenCV, except some useful functions that are not part of OpenCV can be found in wimage_util.h +*/ +template<typename T> +class WImage +{ +public: + typedef T BaseType; + + // WImage is an abstract class with no other virtual methods so make the + // destructor virtual. + virtual ~WImage() = 0; + + // Accessors + IplImage* Ipl() {return image_; } + const IplImage* Ipl() const {return image_; } + T* ImageData() { return reinterpret_cast<T*>(image_->imageData); } + const T* ImageData() const { + return reinterpret_cast<const T*>(image_->imageData); + } + + int Width() const {return image_->width; } + int Height() const {return image_->height; } + + // WidthStep is the number of bytes to go to the pixel with the next y coord + int WidthStep() const {return image_->widthStep; } + + int Channels() const {return image_->nChannels; } + int ChannelSize() const {return sizeof(T); } // number of bytes per channel + + // Number of bytes per pixel + int PixelSize() const {return Channels() * ChannelSize(); } + + // Return depth type (e.g. IPL_DEPTH_8U, IPL_DEPTH_32F) which is the number + // of bits per channel and with the signed bit set. + // This is known at compile time using specializations. + int Depth() const; + + inline const T* Row(int r) const { + return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep); + } + + inline T* Row(int r) { + return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep); + } + + // Pixel accessors which returns a pointer to the start of the channel + inline T* operator() (int c, int r) { + return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep) + + c*Channels(); + } + + inline const T* operator() (int c, int r) const { + return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep) + + c*Channels(); + } + + // Copy the contents from another image which is just a convenience to cvCopy + void CopyFrom(const WImage<T>& src) { cvCopy(src.Ipl(), image_); } + + // Set contents to zero which is just a convenient to cvSetZero + void SetZero() { cvSetZero(image_); } + + // Construct a view into a region of this image + WImageView<T> View(int c, int r, int width, int height); + +protected: + // Disallow copy and assignment + WImage(const WImage&); + void operator=(const WImage&); + + explicit WImage(IplImage* img) : image_(img) { + assert(!img || img->depth == Depth()); + } + + void SetIpl(IplImage* image) { + assert(!image || image->depth == Depth()); + image_ = image; + } + + IplImage* image_; +}; + + +/** Image class when both the pixel type and number of channels +are known at compile time. This wrapper will speed up some of the operations +like accessing individual pixels using the () operator. +*/ +template<typename T, int C> +class WImageC : public WImage<T> +{ +public: + typedef typename WImage<T>::BaseType BaseType; + enum { kChannels = C }; + + explicit WImageC(IplImage* img) : WImage<T>(img) { + assert(!img || img->nChannels == Channels()); + } + + // Construct a view into a region of this image + WImageViewC<T, C> View(int c, int r, int width, int height); + + // Copy the contents from another image which is just a convenience to cvCopy + void CopyFrom(const WImageC<T, C>& src) { + cvCopy(src.Ipl(), WImage<T>::image_); + } + + // WImageC is an abstract class with no other virtual methods so make the + // destructor virtual. + virtual ~WImageC() = 0; + + int Channels() const {return C; } + +protected: + // Disallow copy and assignment + WImageC(const WImageC&); + void operator=(const WImageC&); + + void SetIpl(IplImage* image) { + assert(!image || image->depth == WImage<T>::Depth()); + WImage<T>::SetIpl(image); + } +}; + +/** Image class which owns the data, so it can be allocated and is always +freed. It cannot be copied but can be explicitly cloned. +*/ +template<typename T> +class WImageBuffer : public WImage<T> +{ +public: + typedef typename WImage<T>::BaseType BaseType; + + // Default constructor which creates an object that can be + WImageBuffer() : WImage<T>(0) {} + + WImageBuffer(int width, int height, int nchannels) : WImage<T>(0) { + Allocate(width, height, nchannels); + } + + // Constructor which takes ownership of a given IplImage so releases + // the image on destruction. + explicit WImageBuffer(IplImage* img) : WImage<T>(img) {} + + // Allocate an image. Does nothing if current size is the same as + // the new size. + void Allocate(int width, int height, int nchannels); + + // Set the data to point to an image, releasing the old data + void SetIpl(IplImage* img) { + ReleaseImage(); + WImage<T>::SetIpl(img); + } + + // Clone an image which reallocates the image if of a different dimension. + void CloneFrom(const WImage<T>& src) { + Allocate(src.Width(), src.Height(), src.Channels()); + CopyFrom(src); + } + + ~WImageBuffer() { + ReleaseImage(); + } + + // Release the image if it isn't null. + void ReleaseImage() { + if (WImage<T>::image_) { + IplImage* image = WImage<T>::image_; + cvReleaseImage(&image); + WImage<T>::SetIpl(0); + } + } + + bool IsNull() const {return WImage<T>::image_ == NULL; } + +private: + // Disallow copy and assignment + WImageBuffer(const WImageBuffer&); + void operator=(const WImageBuffer&); +}; + +/** Like a WImageBuffer class but when the number of channels is known at compile time. +*/ +template<typename T, int C> +class WImageBufferC : public WImageC<T, C> +{ +public: + typedef typename WImage<T>::BaseType BaseType; + enum { kChannels = C }; + + // Default constructor which creates an object that can be + WImageBufferC() : WImageC<T, C>(0) {} + + WImageBufferC(int width, int height) : WImageC<T, C>(0) { + Allocate(width, height); + } + + // Constructor which takes ownership of a given IplImage so releases + // the image on destruction. + explicit WImageBufferC(IplImage* img) : WImageC<T, C>(img) {} + + // Allocate an image. Does nothing if current size is the same as + // the new size. + void Allocate(int width, int height); + + // Set the data to point to an image, releasing the old data + void SetIpl(IplImage* img) { + ReleaseImage(); + WImageC<T, C>::SetIpl(img); + } + + // Clone an image which reallocates the image if of a different dimension. + void CloneFrom(const WImageC<T, C>& src) { + Allocate(src.Width(), src.Height()); + CopyFrom(src); + } + + ~WImageBufferC() { + ReleaseImage(); + } + + // Release the image if it isn't null. + void ReleaseImage() { + if (WImage<T>::image_) { + IplImage* image = WImage<T>::image_; + cvReleaseImage(&image); + WImageC<T, C>::SetIpl(0); + } + } + + bool IsNull() const {return WImage<T>::image_ == NULL; } + +private: + // Disallow copy and assignment + WImageBufferC(const WImageBufferC&); + void operator=(const WImageBufferC&); +}; + +/** View into an image class which allows treating a subimage as an image or treating external data +as an image +*/ +template<typename T> class WImageView : public WImage<T> +{ +public: + typedef typename WImage<T>::BaseType BaseType; + + // Construct a subimage. No checks are done that the subimage lies + // completely inside the original image. + WImageView(WImage<T>* img, int c, int r, int width, int height); + + // Refer to external data. + // If not given width_step assumed to be same as width. + WImageView(T* data, int width, int height, int channels, int width_step = -1); + + // Refer to external data. This does NOT take ownership + // of the supplied IplImage. + WImageView(IplImage* img) : WImage<T>(img) {} + + // Copy constructor + WImageView(const WImage<T>& img) : WImage<T>(0) { + header_ = *(img.Ipl()); + WImage<T>::SetIpl(&header_); + } + + WImageView& operator=(const WImage<T>& img) { + header_ = *(img.Ipl()); + WImage<T>::SetIpl(&header_); + return *this; + } + +protected: + IplImage header_; +}; + + +template<typename T, int C> +class WImageViewC : public WImageC<T, C> +{ +public: + typedef typename WImage<T>::BaseType BaseType; + enum { kChannels = C }; + + // Default constructor needed for vectors of views. + WImageViewC(); + + virtual ~WImageViewC() {} + + // Construct a subimage. No checks are done that the subimage lies + // completely inside the original image. + WImageViewC(WImageC<T, C>* img, + int c, int r, int width, int height); + + // Refer to external data + WImageViewC(T* data, int width, int height, int width_step = -1); + + // Refer to external data. This does NOT take ownership + // of the supplied IplImage. + WImageViewC(IplImage* img) : WImageC<T, C>(img) {} + + // Copy constructor which does a shallow copy to allow multiple views + // of same data. gcc-4.1.1 gets confused if both versions of + // the constructor and assignment operator are not provided. + WImageViewC(const WImageC<T, C>& img) : WImageC<T, C>(0) { + header_ = *(img.Ipl()); + WImageC<T, C>::SetIpl(&header_); + } + WImageViewC(const WImageViewC<T, C>& img) : WImageC<T, C>(0) { + header_ = *(img.Ipl()); + WImageC<T, C>::SetIpl(&header_); + } + + WImageViewC& operator=(const WImageC<T, C>& img) { + header_ = *(img.Ipl()); + WImageC<T, C>::SetIpl(&header_); + return *this; + } + WImageViewC& operator=(const WImageViewC<T, C>& img) { + header_ = *(img.Ipl()); + WImageC<T, C>::SetIpl(&header_); + return *this; + } + +protected: + IplImage header_; +}; + + +// Specializations for depth +template<> +inline int WImage<uchar>::Depth() const {return IPL_DEPTH_8U; } +template<> +inline int WImage<signed char>::Depth() const {return IPL_DEPTH_8S; } +template<> +inline int WImage<short>::Depth() const {return IPL_DEPTH_16S; } +template<> +inline int WImage<ushort>::Depth() const {return IPL_DEPTH_16U; } +template<> +inline int WImage<int>::Depth() const {return IPL_DEPTH_32S; } +template<> +inline int WImage<float>::Depth() const {return IPL_DEPTH_32F; } +template<> +inline int WImage<double>::Depth() const {return IPL_DEPTH_64F; } + +template<typename T> inline WImage<T>::~WImage() {} +template<typename T, int C> inline WImageC<T, C>::~WImageC() {} + +template<typename T> +inline void WImageBuffer<T>::Allocate(int width, int height, int nchannels) +{ + if (IsNull() || WImage<T>::Width() != width || + WImage<T>::Height() != height || WImage<T>::Channels() != nchannels) { + ReleaseImage(); + WImage<T>::image_ = cvCreateImage(cvSize(width, height), + WImage<T>::Depth(), nchannels); + } +} + +template<typename T, int C> +inline void WImageBufferC<T, C>::Allocate(int width, int height) +{ + if (IsNull() || WImage<T>::Width() != width || WImage<T>::Height() != height) { + ReleaseImage(); + WImageC<T, C>::SetIpl(cvCreateImage(cvSize(width, height),WImage<T>::Depth(), C)); + } +} + +template<typename T> +WImageView<T>::WImageView(WImage<T>* img, int c, int r, int width, int height) + : WImage<T>(0) +{ + header_ = *(img->Ipl()); + header_.imageData = reinterpret_cast<char*>((*img)(c, r)); + header_.width = width; + header_.height = height; + WImage<T>::SetIpl(&header_); +} + +template<typename T> +WImageView<T>::WImageView(T* data, int width, int height, int nchannels, int width_step) + : WImage<T>(0) +{ + cvInitImageHeader(&header_, cvSize(width, height), WImage<T>::Depth(), nchannels); + header_.imageData = reinterpret_cast<char*>(data); + if (width_step > 0) { + header_.widthStep = width_step; + } + WImage<T>::SetIpl(&header_); +} + +template<typename T, int C> +WImageViewC<T, C>::WImageViewC(WImageC<T, C>* img, int c, int r, int width, int height) + : WImageC<T, C>(0) +{ + header_ = *(img->Ipl()); + header_.imageData = reinterpret_cast<char*>((*img)(c, r)); + header_.width = width; + header_.height = height; + WImageC<T, C>::SetIpl(&header_); +} + +template<typename T, int C> +WImageViewC<T, C>::WImageViewC() : WImageC<T, C>(0) { + cvInitImageHeader(&header_, cvSize(0, 0), WImage<T>::Depth(), C); + header_.imageData = reinterpret_cast<char*>(0); + WImageC<T, C>::SetIpl(&header_); +} + +template<typename T, int C> +WImageViewC<T, C>::WImageViewC(T* data, int width, int height, int width_step) + : WImageC<T, C>(0) +{ + cvInitImageHeader(&header_, cvSize(width, height), WImage<T>::Depth(), C); + header_.imageData = reinterpret_cast<char*>(data); + if (width_step > 0) { + header_.widthStep = width_step; + } + WImageC<T, C>::SetIpl(&header_); +} + +// Construct a view into a region of an image +template<typename T> +WImageView<T> WImage<T>::View(int c, int r, int width, int height) { + return WImageView<T>(this, c, r, width, height); +} + +template<typename T, int C> +WImageViewC<T, C> WImageC<T, C>::View(int c, int r, int width, int height) { + return WImageViewC<T, C>(this, c, r, width, height); +} + +//! @} core + +} // end of namespace + +#endif // __cplusplus + +#endif diff --git a/include/opencv2/core_detect.hpp b/include/opencv2/core_detect.hpp new file mode 100644 index 0000000..46a5017 --- /dev/null +++ b/include/opencv2/core_detect.hpp @@ -0,0 +1,149 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#ifndef _OPENCV_DNN_OBJDETECT_CORE_DETECT_HPP_ +#define _OPENCV_DNN_OBJDETECT_CORE_DETECT_HPP_ + +#include <vector> +#include <memory> + +#include <opencv2/highgui.hpp> +#include <opencv2/imgproc.hpp> + +/** @defgroup dnn_objdetect DNN used for object detection +*/ + +namespace cv +{ +namespace dnn_objdetect +{ + + //! @addtogroup dnn_objdetect + //! @{ + + /** @brief Structure to hold the details pertaining to a single bounding box + */ + typedef struct + { + int xmin, xmax; + int ymin, ymax; + size_t class_idx; + std::string label_name; + double class_prob; + } object; + + + /** @brief A class to post process model predictions + */ + class CV_EXPORTS InferBbox + { + public: + /** @brief Default constructer + @param _delta_bbox Blob containing relative coordinates of bounding boxes + @param _class_scores Blob containing the probability values of each class + @param _conf_scores Blob containing the confidence scores + */ + InferBbox(Mat _delta_bbox, Mat _class_scores, Mat _conf_scores); + + /** @brief Filters the bounding boxes. + */ + void filter(double thresh = 0.8); + + /** @brief Vector which holds the final detections of the model + */ + std::vector<object> detections; + + protected: + /** @brief Transform relative coordinates from ConvDet to bounding box coordinates + @param bboxes Vector to hold the predicted bounding boxes + */ + void transform_bboxes(std::vector<std::vector<double> > *bboxes); + + /** @brief Computes final probability values of each bounding box + @param final_probs Vector to hold the probability values + */ + void final_probability_dist(std::vector<std::vector<double> > *final_probs); + + /** @brief Transform bounding boxes from [x, y, h, w] to [xmin, ymin, xmax, ymax] + @param pre Vector conatining initial co-ordinates + @param post Vector containing the transformed co-ordinates + */ + void transform_bboxes_inv(std::vector<std::vector<double> > *pre, + std::vector<std::vector<double> > *post); + + /** @brief Ensures that the bounding box values are within image boundaries + @param min_max_boxes Vector containing bounding boxes of the form [xmin, ymin, xmax, ymax] + */ + void assert_predictions(std::vector<std::vector<double> > *min_max_boxes); + + /** @brief Filter top `n` predictions + @param probs Final probability values of bounding boxes + @param boxes Predicted bounding box co-ordinates + @param top_n_boxes Contains bounding box co-ordinates of top `n` boxes + @param top_n_idxs Containes class indices of top `n` bounding boxes + @param top_n_probs Contains probability values of top `n` bounding boxes + */ + void filter_top_n(std::vector<std::vector<double> > *probs, + std::vector<std::vector<double> > *boxes, + std::vector<std::vector<double> > &top_n_boxes, + std::vector<size_t> &top_n_idxs, + std::vector<double> &top_n_probs); + + /** @brief Wrapper to apply Non-Maximal Supression + @param top_n_boxes Contains bounding box co-ordinates of top `n` boxes + @param top_n_idxs Containes class indices of top `n` bounding boxes + @param top_n_probs Contains probability values of top `n` bounding boxes + */ + void nms_wrapper(std::vector<std::vector<double> > &top_n_boxes, + std::vector<size_t> &top_n_idxs, + std::vector<double> &top_n_probs); + + /** @brief Applies Non-Maximal Supression + @param boxes Bounding box co-ordinates belonging to one class + @param probs Probability values of boxes belonging to one class + */ + std::vector<bool> non_maximal_suppression(std::vector<std::vector<double> > + *boxes, std::vector<double> *probs); + + /** @brief Computes intersection over union of bounding boxes + @param boxes Vector of bounding box co-ordinates + @param base_box Base box wrt which IOU is calculated + @param iou Vector to store IOU values + */ + void intersection_over_union(std::vector<std::vector<double> > *boxes, + std::vector<double> *base_box, std::vector<double> *iou); + + static inline bool comparator (std::pair<double, size_t> l1, + std::pair<double, size_t> l2) + { + return l1.first > l2.first; + } + + private: + Mat delta_bbox; + Mat class_scores; + Mat conf_scores; + + unsigned int image_width; + unsigned int image_height; + + unsigned int W, H; + std::vector<std::vector<double> > anchors_values; + std::vector<std::pair<double, double> > anchor_center; + std::vector<std::pair<double, double> > anchor_shapes; + + std::vector<std::string> label_map; + + unsigned int num_classes; + unsigned int anchors_per_grid; + size_t anchors; + double intersection_thresh; + double nms_intersection_thresh; + size_t n_top_detections; + double epsilon; + }; + + //! @} +} // namespace dnn_objdetect +} // namespace cv +#endif diff --git a/include/opencv2/cvconfig.h b/include/opencv2/cvconfig.h new file mode 100644 index 0000000..4597d39 --- /dev/null +++ b/include/opencv2/cvconfig.h @@ -0,0 +1,251 @@ +#ifndef OPENCV_CVCONFIG_H_INCLUDED +#define OPENCV_CVCONFIG_H_INCLUDED + +/* OpenCV compiled as static or dynamic libs */ +#define BUILD_SHARED_LIBS + +/* OpenCV intrinsics optimized code */ +#define CV_ENABLE_INTRINSICS + +/* OpenCV additional optimized code */ +/* #undef CV_DISABLE_OPTIMIZATION */ + +/* Compile for 'real' NVIDIA GPU architectures */ +#define CUDA_ARCH_BIN "" + +/* Create PTX or BIN for 1.0 compute capability */ +/* #undef CUDA_ARCH_BIN_OR_PTX_10 */ + +/* NVIDIA GPU features are used */ +#define CUDA_ARCH_FEATURES "" + +/* Compile for 'virtual' NVIDIA PTX architectures */ +#define CUDA_ARCH_PTX "" + +/* AVFoundation video libraries */ +/* #undef HAVE_AVFOUNDATION */ + +/* V4L capturing support */ +/* #undef HAVE_CAMV4L */ + +/* V4L2 capturing support */ +/* #undef HAVE_CAMV4L2 */ + +/* Carbon windowing environment */ +/* #undef HAVE_CARBON */ + +/* AMD's Basic Linear Algebra Subprograms Library*/ +/* #undef HAVE_CLAMDBLAS */ + +/* AMD's OpenCL Fast Fourier Transform Library*/ +/* #undef HAVE_CLAMDFFT */ + +/* Clp support */ +/* #undef HAVE_CLP */ + +/* Cocoa API */ +/* #undef HAVE_COCOA */ + +/* C= */ +/* #undef HAVE_CSTRIPES */ + +/* NVIDIA CUDA Basic Linear Algebra Subprograms (BLAS) API*/ +/* #undef HAVE_CUBLAS */ + +/* NVIDIA CUDA Runtime API*/ +/* #undef HAVE_CUDA */ + +/* NVIDIA CUDA Fast Fourier Transform (FFT) API*/ +/* #undef HAVE_CUFFT */ + +/* IEEE1394 capturing support */ +/* #undef HAVE_DC1394 */ + +/* IEEE1394 capturing support - libdc1394 v2.x */ +/* #undef HAVE_DC1394_2 */ + +/* DirectX */ +/* #undef HAVE_DIRECTX */ +/* #undef HAVE_DIRECTX_NV12 */ +/* #undef HAVE_D3D11 */ +/* #undef HAVE_D3D10 */ +/* #undef HAVE_D3D9 */ + +/* DirectShow Video Capture library */ +/* #undef HAVE_DSHOW */ + +/* Eigen Matrix & Linear Algebra Library */ +#define HAVE_EIGEN + +/* FFMpeg video library */ +/* #undef HAVE_FFMPEG */ + +/* Geospatial Data Abstraction Library */ +/* #undef HAVE_GDAL */ + +/* GStreamer multimedia framework */ +/* #undef HAVE_GSTREAMER */ + +/* GTK+ 2.0 Thread support */ +/* #undef HAVE_GTHREAD */ + +/* GTK+ 2.x toolkit */ +/* #undef HAVE_GTK */ + +/* Halide support */ +/* #undef HAVE_HALIDE */ + +/* Define to 1 if you have the <inttypes.h> header file. */ +/* #undef HAVE_INTTYPES_H */ + +/* Intel Perceptual Computing SDK library */ +/* #undef HAVE_INTELPERC */ + +/* Intel Integrated Performance Primitives */ +/* #undef HAVE_IPP */ +/* #undef HAVE_IPP_ICV */ +/* #undef HAVE_IPP_IW */ +/* #undef HAVE_IPP_IW_LL */ + +/* JPEG-2000 codec */ +/* #undef HAVE_JASPER */ + +/* IJG JPEG codec */ +#define HAVE_JPEG + +/* libpng/png.h needs to be included */ +/* #undef HAVE_LIBPNG_PNG_H */ + +/* GDCM DICOM codec */ +/* #undef HAVE_GDCM */ + +/* V4L/V4L2 capturing support via libv4l */ +/* #undef HAVE_LIBV4L */ + +/* Microsoft Media Foundation Capture library */ +/* #undef HAVE_MSMF */ + +/* NVIDIA Video Decoding API*/ +/* #undef HAVE_NVCUVID */ + +/* NVIDIA Video Encoding API*/ +/* #undef HAVE_NVCUVENC */ + +/* OpenCL Support */ +/* #undef HAVE_OPENCL */ +/* #undef HAVE_OPENCL_STATIC */ +/* #undef HAVE_OPENCL_SVM */ + +/* NVIDIA OpenCL D3D Extensions support */ +/* #undef HAVE_OPENCL_D3D11_NV */ + +/* OpenEXR codec */ +/* #undef HAVE_OPENEXR */ + +/* OpenGL support*/ +/* #undef HAVE_OPENGL */ + +/* OpenNI library */ +/* #undef HAVE_OPENNI */ + +/* OpenNI library */ +/* #undef HAVE_OPENNI2 */ + +/* PNG codec */ +#define HAVE_PNG + +/* Posix threads (pthreads) */ +#define HAVE_PTHREAD + +/* parallel_for with pthreads */ +#define HAVE_PTHREADS_PF + +/* Qt support */ +/* #undef HAVE_QT */ + +/* Qt OpenGL support */ +/* #undef HAVE_QT_OPENGL */ + +/* QuickTime video libraries */ +/* #undef HAVE_QUICKTIME */ + +/* QTKit video libraries */ +/* #undef HAVE_QTKIT */ + +/* Intel Threading Building Blocks */ +/* #undef HAVE_TBB */ + +/* TIFF codec */ +/* #undef HAVE_TIFF */ + +/* Unicap video capture library */ +/* #undef HAVE_UNICAP */ + +/* Video for Windows support */ +/* #undef HAVE_VFW */ + +/* V4L2 capturing support in videoio.h */ +/* #undef HAVE_VIDEOIO */ + +/* Win32 UI */ +/* #undef HAVE_WIN32UI */ + +/* XIMEA camera support */ +/* #undef HAVE_XIMEA */ + +/* Xine video library */ +/* #undef HAVE_XINE */ + +/* Define if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* gPhoto2 library */ +/* #undef HAVE_GPHOTO2 */ + +/* VA library (libva) */ +/* #undef HAVE_VA */ + +/* Intel VA-API/OpenCL */ +/* #undef HAVE_VA_INTEL */ + +/* Intel Media SDK */ +/* #undef HAVE_MFX */ + +/* Lapack */ +/* #undef HAVE_LAPACK */ + +/* Library was compiled with functions instrumentation */ +/* #undef ENABLE_INSTRUMENTATION */ + +/* OpenVX */ +/* #undef HAVE_OPENVX */ + +#if defined(HAVE_XINE) || \ + defined(HAVE_GSTREAMER) || \ + defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ + defined(HAVE_AVFOUNDATION) || \ + /*defined(HAVE_OPENNI) || too specialized */ \ + defined(HAVE_FFMPEG) || \ + defined(HAVE_MSMF) +#define HAVE_VIDEO_INPUT +#endif + +#if /*defined(HAVE_XINE) || */\ + defined(HAVE_GSTREAMER) || \ + defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ + defined(HAVE_AVFOUNDATION) || \ + defined(HAVE_FFMPEG) || \ + defined(HAVE_MSMF) +#define HAVE_VIDEO_OUTPUT +#endif + +/* OpenCV trace utilities */ +#define OPENCV_TRACE + +/* Library QR-code decoding */ +#define HAVE_QUIRC + +#endif // OPENCV_CVCONFIG_H_INCLUDED diff --git a/include/opencv2/datasets/ar_hmdb.hpp b/include/opencv2/datasets/ar_hmdb.hpp new file mode 100644 index 0000000..fa257ad --- /dev/null +++ b/include/opencv2/datasets/ar_hmdb.hpp @@ -0,0 +1,80 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_AR_HMDB_HPP +#define OPENCV_DATASETS_AR_HMDB_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ar +//! @{ + +struct AR_hmdbObj : public Object +{ + int id; + std::string name; + std::string videoName; +}; + +class CV_EXPORTS AR_hmdb : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<AR_hmdb> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/ar_sports.hpp b/include/opencv2/datasets/ar_sports.hpp new file mode 100644 index 0000000..cb24e38 --- /dev/null +++ b/include/opencv2/datasets/ar_sports.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_AR_SPORTS_HPP +#define OPENCV_DATASETS_AR_SPORTS_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ar +//! @{ + +struct AR_sportsObj : public Object +{ + std::string videoUrl; + std::vector<int> labels; +}; + +class CV_EXPORTS AR_sports : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<AR_sports> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/dataset.hpp b/include/opencv2/datasets/dataset.hpp new file mode 100644 index 0000000..f62da15 --- /dev/null +++ b/include/opencv2/datasets/dataset.hpp @@ -0,0 +1,545 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_DATASET_HPP +#define OPENCV_DATASETS_DATASET_HPP + +#include <string> +#include <vector> + +#include <opencv2/core.hpp> + +/** @defgroup datasets Framework for working with different datasets + +The datasets module includes classes for working with different datasets: load data, evaluate +different algorithms on them, contains benchmarks, etc. + +It is planned to have: + +- basic: loading code for all datasets to help start work with them. +- next stage: quick benchmarks for all datasets to show how to solve them using OpenCV and +implement evaluation code. +- finally: implement on OpenCV state-of-the-art algorithms, which solve these tasks. + +@{ +@defgroup datasets_ar Action Recognition + +### HMDB: A Large Human Motion Database + +Implements loading dataset: + +"HMDB: A Large Human Motion Database": <http://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database/> + +Usage: +-# From link above download dataset files: `hmdb51_org.rar` & `test_train_splits.rar`. +-# Unpack them. Unpack all archives from directory: `hmdb51_org/` and remove them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_ar_hmdb -p=/home/user/path_to_unpacked_folders/ +~~~ + +#### Benchmark + +For this dataset was implemented benchmark with accuracy: 0.107407 (using precomputed HOG/HOF +"STIP" features from site, averaging for 3 splits) + +To run this benchmark execute: +~~~ +./opencv/build/bin/example_datasets_ar_hmdb_benchmark -p=/home/user/path_to_unpacked_folders/ +~~~ + +@note +Precomputed features should be unpacked in the same folder: `/home/user/path_to_unpacked_folders/hmdb51_org_stips/`. +Also unpack all archives from directory: `hmdb51_org_stips/` and remove them. + +### Sports-1M %Dataset + +Implements loading dataset: + +"Sports-1M Dataset": <http://cs.stanford.edu/people/karpathy/deepvideo/> + +Usage: +-# From link above download dataset files (`git clone https://code.google.com/p/sports-1m-dataset/`). +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_ar_sports -p=/home/user/path_to_downloaded_folders/ +~~~ + +@defgroup datasets_fr Face Recognition + +### Adience + +Implements loading dataset: + +"Adience": <http://www.openu.ac.il/home/hassner/Adience/data.html> + +Usage: +-# From link above download any dataset file: `faces.tar.gz\aligned.tar.gz` and files with splits: +`fold_0_data.txt-fold_4_data.txt`, `fold_frontal_0_data.txt-fold_frontal_4_data.txt`. (For +face recognition task another splits should be created) +-# Unpack dataset file to some folder and place split files into the same folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_fr_adience -p=/home/user/path_to_created_folder/ +~~~ + +### Labeled Faces in the Wild + +Implements loading dataset: + +"Labeled Faces in the Wild": <http://vis-www.cs.umass.edu/lfw/> + +Usage: +-# From link above download any dataset file: +`lfw.tgz\lfwa.tar.gz\lfw-deepfunneled.tgz\lfw-funneled.tgz` and files with pairs: 10 test +splits: `pairs.txt` and developer train split: `pairsDevTrain.txt`. +-# Unpack dataset file and place `pairs.txt` and `pairsDevTrain.txt` in created folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/ +~~~ + +#### Benchmark + +For this dataset was implemented benchmark with accuracy: 0.623833 +- 0.005223 (train split: +`pairsDevTrain.txt`, dataset: lfwa) + +To run this benchmark execute: +~~~ +./opencv/build/bin/example_datasets_fr_lfw_benchmark -p=/home/user/path_to_unpacked_folder/lfw2/ +~~~ + +@defgroup datasets_gr Gesture Recognition + +### ChaLearn Looking at People + +Implements loading dataset: + +"ChaLearn Looking at People": <http://gesture.chalearn.org/> + +Usage +-# Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": +`Train1.zip`-`Train5.zip`, `Validation1.zip`-`Validation3.zip` (Register on site: www.codalab.org and +accept the terms and conditions of competition: +<https://www.codalab.org/competitions/991#learn_the_details> There are three mirrors for +downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" +works). +-# Unpack train archives `Train1.zip`-`Train5.zip` to folder `Train/`, validation archives +`Validation1.zip`-`Validation3.zip` to folder `Validation/` +-# Unpack all archives in `Train/` & `Validation/` in the folders with the same names, for example: +`Sample0001.zip` to `Sample0001/` +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_gr_chalearn -p=/home/user/path_to_unpacked_folders/ +~~~ + +### Sheffield Kinect Gesture Dataset + +Implements loading dataset: + +"Sheffield Kinect Gesture Dataset": <http://lshao.staff.shef.ac.uk/data/SheffieldKinectGesture.htm> + +Usage: +-# From link above download dataset files: `subject1_dep.7z`-`subject6_dep.7z`, `subject1_rgb.7z`-`subject6_rgb.7z`. +-# Unpack them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_gr_skig -p=/home/user/path_to_unpacked_folders/ +~~~ + +@defgroup datasets_hpe Human Pose Estimation + +### HumanEva Dataset + +Implements loading dataset: + +"HumanEva Dataset": <http://humaneva.is.tue.mpg.de> + +Usage: +-# From link above download dataset files for `HumanEva-I` (tar) & `HumanEva-II`. +-# Unpack them to `HumanEva_1` & `HumanEva_2` accordingly. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_hpe_humaneva -p=/home/user/path_to_unpacked_folders/ +~~~ + +### PARSE Dataset + +Implements loading dataset: + +"PARSE Dataset": <http://www.ics.uci.edu/~dramanan/papers/parse/> + +Usage: +-# From link above download dataset file: `people.zip`. +-# Unpack it. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_hpe_parse -p=/home/user/path_to_unpacked_folder/people_all/ +~~~ + +@defgroup datasets_ir Image Registration + +### Affine Covariant Regions Datasets + +Implements loading dataset: + +"Affine Covariant Regions Datasets": <http://www.robots.ox.ac.uk/~vgg/data/data-aff.html> + +Usage: +-# From link above download dataset files: +`bark\bikes\boat\graf\leuven\trees\ubc\wall.tar.gz`. +-# Unpack them. +-# To load data, for example, for "bark", run: +``` +./opencv/build/bin/example_datasets_ir_affine -p=/home/user/path_to_unpacked_folder/bark/ +``` + +### Robot Data Set + +Implements loading dataset: + +"Robot Data Set, Point Feature Data Set – 2010": <http://roboimagedata.compute.dtu.dk/?page_id=24> + +Usage: +-# From link above download dataset files: `SET001_6.tar.gz`-`SET055_60.tar.gz` +-# Unpack them to one folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_ir_robot -p=/home/user/path_to_unpacked_folder/ +~~~ + +@defgroup datasets_is Image Segmentation + +### The Berkeley Segmentation Dataset and Benchmark + +Implements loading dataset: + +"The Berkeley Segmentation Dataset and Benchmark": <https://www.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/> + +Usage: +-# From link above download dataset files: `BSDS300-human.tgz` & `BSDS300-images.tgz`. +-# Unpack them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_is_bsds -p=/home/user/path_to_unpacked_folder/BSDS300/ +~~~ + +### Weizmann Segmentation Evaluation Database + +Implements loading dataset: + +"Weizmann Segmentation Evaluation Database": <http://www.wisdom.weizmann.ac.il/~vision/Seg_Evaluation_DB/> + +Usage: +-# From link above download dataset files: `Weizmann_Seg_DB_1obj.ZIP` & `Weizmann_Seg_DB_2obj.ZIP`. +-# Unpack them. +-# To load data, for example, for `1 object` dataset, run: +~~~ +./opencv/build/bin/example_datasets_is_weizmann -p=/home/user/path_to_unpacked_folder/1obj/ +~~~ + +@defgroup datasets_msm Multiview Stereo Matching + +### EPFL Multi-View Stereo + +Implements loading dataset: + +"EPFL Multi-View Stereo": <http://cvlab.epfl.ch/data/strechamvs> + +Usage: +-# From link above download dataset files: +`castle_dense\castle_dense_large\castle_entry\fountain\herzjesu_dense\herzjesu_dense_large_bounding\cameras\images\p.tar.gz`. +-# Unpack them in separate folder for each object. For example, for "fountain", in folder `fountain/` : +`fountain_dense_bounding.tar.gz -> bounding/`, +`fountain_dense_cameras.tar.gz -> camera/`, +`fountain_dense_images.tar.gz -> png/`, +`fountain_dense_p.tar.gz -> P/` +-# To load data, for example, for "fountain", run: +~~~ +./opencv/build/bin/example_datasets_msm_epfl -p=/home/user/path_to_unpacked_folder/fountain/ +~~~ + +### Stereo – Middlebury Computer Vision + +Implements loading dataset: + +"Stereo – Middlebury Computer Vision": <http://vision.middlebury.edu/mview/> + +Usage: +-# From link above download dataset files: +`dino\dinoRing\dinoSparseRing\temple\templeRing\templeSparseRing.zip` +-# Unpack them. +-# To load data, for example "temple" dataset, run: +~~~ +./opencv/build/bin/example_datasets_msm_middlebury -p=/home/user/path_to_unpacked_folder/temple/ +~~~ + +@defgroup datasets_or Object Recognition + +### ImageNet + +Implements loading dataset: "ImageNet": <http://www.image-net.org/> + +Usage: +-# From link above download dataset files: +`ILSVRC2010_images_train.tar\ILSVRC2010_images_test.tar\ILSVRC2010_images_val.tar` & devkit: +`ILSVRC2010_devkit-1.0.tar.gz` (Implemented loading of 2010 dataset as only this dataset has ground +truth for test data, but structure for ILSVRC2014 is similar) +-# Unpack them to: `some_folder/train/`, `some_folder/test/`, `some_folder/val` & +`some_folder/ILSVRC2010_validation_ground_truth.txt`, +`some_folder/ILSVRC2010_test_ground_truth.txt`. +-# Create file with labels: `some_folder/labels.txt`, for example, using python script below (each +file's row format: `synset,labelID,description`. For example: "n07751451,18,plum"). +-# Unpack all tar files in train. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_or_imagenet -p=/home/user/some_folder/ +~~~ + +Python script to parse `meta.mat`: +~~~{py} + import scipy.io + meta_mat = scipy.io.loadmat("devkit-1.0/data/meta.mat") + + labels_dic = dict((m[0][1][0], m[0][0][0][0]-1) for m in meta_mat['synsets'] + label_names_dic = dict((m[0][1][0], m[0][2][0]) for m in meta_mat['synsets'] + + for label in labels_dic.keys(): + print "{0},{1},{2}".format(label, labels_dic[label], label_names_dic[label]) +~~~ + +### MNIST + +Implements loading dataset: + +"MNIST": <http://yann.lecun.com/exdb/mnist/> + +Usage: +-# From link above download dataset files: +`t10k-images-idx3-ubyte.gz`, `t10k-labels-idx1-ubyte.gz`, `train-images-idx3-ubyte.gz`, `train-labels-idx1-ubyte.gz`. +-# Unpack them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_or_mnist -p=/home/user/path_to_unpacked_files/ +~~~ + +### SUN Database + +Implements loading dataset: + +"SUN Database, Scene Recognition Benchmark. SUN397": <http://vision.cs.princeton.edu/projects/2010/SUN/> + +Usage: +-# From link above download dataset file: `SUN397.tar` & file with splits: `Partitions.zip` +-# Unpack `SUN397.tar` into folder: `SUN397/` & `Partitions.zip` into folder: `SUN397/Partitions/` +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_or_sun -p=/home/user/path_to_unpacked_files/SUN397/ +~~~ + +@defgroup datasets_pd Pedestrian Detection + +### Caltech Pedestrian Detection Benchmark + +Implements loading dataset: + +"Caltech Pedestrian Detection Benchmark": <http://www.vision.caltech.edu/Image_Datasets/CaltechPedestrians/> + +@note First version of Caltech Pedestrian dataset loading. Code to unpack all frames from seq files +commented as their number is huge! So currently load only meta information without data. Also +ground truth isn't processed, as need to convert it from mat files first. + +Usage: +-# From link above download dataset files: `set00.tar`-`set10.tar`. +-# Unpack them to separate folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_pd_caltech -p=/home/user/path_to_unpacked_folders/ +~~~ + +@defgroup datasets_slam SLAM + +### KITTI Vision Benchmark + +Implements loading dataset: + +"KITTI Vision Benchmark": <http://www.cvlibs.net/datasets/kitti/eval_odometry.php> + +Usage: +-# From link above download "Odometry" dataset files: +`data_odometry_gray\data_odometry_color\data_odometry_velodyne\data_odometry_poses\data_odometry_calib.zip`. +-# Unpack `data_odometry_poses.zip`, it creates folder `dataset/poses/`. After that unpack +`data_odometry_gray.zip`, `data_odometry_color.zip`, `data_odometry_velodyne.zip`. Folder +`dataset/sequences/` will be created with folders `00/..21/`. Each of these folders will contain: +`image_0/`, `image_1/`, `image_2/`, `image_3/`, `velodyne/` and files `calib.txt` & `times.txt`. +These two last files will be replaced after unpacking `data_odometry_calib.zip` at the end. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_slam_kitti -p=/home/user/path_to_unpacked_folder/dataset/ +~~~ + +### TUMindoor Dataset + +Implements loading dataset: + +"TUMindoor Dataset": <http://www.navvis.lmt.ei.tum.de/dataset/> + +Usage: +-# From link above download dataset files: `dslr\info\ladybug\pointcloud.tar.bz2` for each dataset: +`11-11-28 (1st floor)\11-12-13 (1st floor N1)\11-12-17a (4th floor)\11-12-17b (3rd floor)\11-12-17c (Ground I)\11-12-18a (Ground II)\11-12-18b (2nd floor)` +-# Unpack them in separate folder for each dataset. +`dslr.tar.bz2 -> dslr/`, +`info.tar.bz2 -> info/`, +`ladybug.tar.bz2 -> ladybug/`, +`pointcloud.tar.bz2 -> pointcloud/`. +-# To load each dataset run: +~~~ +./opencv/build/bin/example_datasets_slam_tumindoor -p=/home/user/path_to_unpacked_folders/ +~~~ + +@defgroup datasets_tr Text Recognition + +### The Chars74K Dataset + +Implements loading dataset: + +"The Chars74K Dataset": <http://www.ee.surrey.ac.uk/CVSSP/demos/chars74k/> + +Usage: +-# From link above download dataset files: +`EnglishFnt\EnglishHnd\EnglishImg\KannadaHnd\KannadaImg.tgz`, `ListsTXT.tgz`. +-# Unpack them. +-# Move `.m` files from folder `ListsTXT/` to appropriate folder. For example, +`English/list_English_Img.m` for `EnglishImg.tgz`. +-# To load data, for example "EnglishImg", run: +~~~ +./opencv/build/bin/example_datasets_tr_chars -p=/home/user/path_to_unpacked_folder/English/ +~~~ + +### The Street View Text Dataset + +Implements loading dataset: + +"The Street View Text Dataset": <http://vision.ucsd.edu/~kai/svt/> + +Usage: +-# From link above download dataset file: `svt.zip`. +-# Unpack it. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_tr_svt -p=/home/user/path_to_unpacked_folder/svt/svt1/ +~~~ + +#### Benchmark + +For this dataset was implemented benchmark with accuracy (mean f1): 0.217 + +To run benchmark execute: +~~~ +./opencv/build/bin/example_datasets_tr_svt_benchmark -p=/home/user/path_to_unpacked_folders/svt/svt1/ +~~~ + +@defgroup datasets_track Tracking + +### VOT 2015 Database + +Implements loading dataset: + +"VOT 2015 dataset comprises 60 short sequences showing various objects in challenging backgrounds. +The sequences were chosen from a large pool of sequences including the ALOV dataset, OTB2 dataset, +non-tracking datasets, Computer Vision Online, Professor Bob Fisher's Image Database, Videezy, +Center for Research in Computer Vision, University of Central Florida, USA, NYU Center for Genomics +and Systems Biology, Data Wrangling, Open Access Directory and Learning and Recognition in Vision +Group, INRIA, France. The VOT sequence selection protocol was applied to obtain a representative +set of challenging sequences.": <http://box.vicos.si/vot/vot2015.zip> + +Usage: +-# From link above download dataset file: `vot2015.zip` +-# Unpack `vot2015.zip` into folder: `VOT2015/` +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_track_vot -p=/home/user/path_to_unpacked_files/VOT2015/ +~~~ +@} + +*/ + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets +//! @{ + +struct Object +{ +}; + +class CV_EXPORTS Dataset +{ +public: + Dataset() {} + virtual ~Dataset() {} + + virtual void load(const std::string &path) = 0; + + std::vector< Ptr<Object> >& getTrain(int splitNum = 0); + std::vector< Ptr<Object> >& getTest(int splitNum = 0); + std::vector< Ptr<Object> >& getValidation(int splitNum = 0); + + int getNumSplits() const; + +protected: + std::vector< std::vector< Ptr<Object> > > train; + std::vector< std::vector< Ptr<Object> > > test; + std::vector< std::vector< Ptr<Object> > > validation; + +private: + std::vector< Ptr<Object> > empty; +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/fr_adience.hpp b/include/opencv2/datasets/fr_adience.hpp new file mode 100644 index 0000000..2df5d8d --- /dev/null +++ b/include/opencv2/datasets/fr_adience.hpp @@ -0,0 +1,98 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_FR_ADIENCE_HPP +#define OPENCV_DATASETS_FR_ADIENCE_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_fr +//! @{ + +enum genderType +{ + male = 0, + female, + none +}; + +struct FR_adienceObj : public Object +{ + std::string user_id; + std::string original_image; + int face_id; + std::string age; + genderType gender; + int x; + int y; + int dx; + int dy; + int tilt_ang; + int fiducial_yaw_angle; + int fiducial_score; +}; + +class CV_EXPORTS FR_adience : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<FR_adience> create(); + + std::vector<std::string> paths; +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/fr_lfw.hpp b/include/opencv2/datasets/fr_lfw.hpp new file mode 100644 index 0000000..16d6315 --- /dev/null +++ b/include/opencv2/datasets/fr_lfw.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_FR_LFW_HPP +#define OPENCV_DATASETS_FR_LFW_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_fr +//! @{ + +struct FR_lfwObj : public Object +{ + std::string image1, image2; + bool same; +}; + +class CV_EXPORTS FR_lfw : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<FR_lfw> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/gr_chalearn.hpp b/include/opencv2/datasets/gr_chalearn.hpp new file mode 100644 index 0000000..6a5c764 --- /dev/null +++ b/include/opencv2/datasets/gr_chalearn.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_GR_CHALEARN_HPP +#define OPENCV_DATASETS_GR_CHALEARN_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_gr +//! @{ + +struct groundTruth +{ + int gestureID, initialFrame, lastFrame; +}; + +struct join +{ + double Wx, Wy, Wz, Rx, Ry, Rz, Rw, Px, Py; +}; + +struct skeleton +{ + join s[20]; +}; + +struct GR_chalearnObj : public Object +{ + std::string name, nameColor, nameDepth, nameUser; + int numFrames, fps, depth; + std::vector<groundTruth> groundTruths; + std::vector<skeleton> skeletons; +}; + +class CV_EXPORTS GR_chalearn : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<GR_chalearn> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/gr_skig.hpp b/include/opencv2/datasets/gr_skig.hpp new file mode 100644 index 0000000..35bc6f4 --- /dev/null +++ b/include/opencv2/datasets/gr_skig.hpp @@ -0,0 +1,118 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_GR_SKIG_HPP +#define OPENCV_DATASETS_GR_SKIG_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_gr +//! @{ + +enum actionType +{ + circle = 1, + triangle, + updown, + rightleft, + wave, + z, + cross, + comehere, + turnaround, + pat +}; + +enum poseType +{ + fist = 1, + index, + flat +}; + +enum illuminationType +{ + light = 1, + dark +}; + +enum backgroundType +{ + woodenBoard = 1, + whitePaper, + paperWithCharacters +}; + +struct GR_skigObj : public Object +{ + std::string rgb; + std::string dep; + char person; // 1..6 + backgroundType background; + illuminationType illumination; + poseType pose; + actionType type; +}; + +class CV_EXPORTS GR_skig : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<GR_skig> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/hpe_humaneva.hpp b/include/opencv2/datasets/hpe_humaneva.hpp new file mode 100644 index 0000000..2eba8cf --- /dev/null +++ b/include/opencv2/datasets/hpe_humaneva.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_HPE_HUMANEVA_HPP +#define OPENCV_DATASETS_HPE_HUMANEVA_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_hpe +//! @{ + +struct HPE_humanevaObj : public Object +{ + char person; // 1..4 + std::string action; + int type1; + std::string type2; + Matx13d ofs; + std::string fileName; + std::vector<std::string> imageNames; // for HumanEva_II +}; + +enum datasetType +{ + humaneva_1 = 1, + humaneva_2 +}; + +class CV_EXPORTS HPE_humaneva : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<HPE_humaneva> create(int num=humaneva_1); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/hpe_parse.hpp b/include/opencv2/datasets/hpe_parse.hpp new file mode 100644 index 0000000..42294df --- /dev/null +++ b/include/opencv2/datasets/hpe_parse.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_HPE_PARSE_HPP +#define OPENCV_DATASETS_HPE_PARSE_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_hpe +//! @{ + +struct HPE_parseObj : public Object +{ + std::string name; +}; + +class CV_EXPORTS HPE_parse : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<HPE_parse> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/ir_affine.hpp b/include/opencv2/datasets/ir_affine.hpp new file mode 100644 index 0000000..7cc0c09 --- /dev/null +++ b/include/opencv2/datasets/ir_affine.hpp @@ -0,0 +1,80 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_IR_AFFINE_HPP +#define OPENCV_DATASETS_IR_AFFINE_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> +#include <opencv2/core/matx.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ir +//! @{ + +struct IR_affineObj : public Object +{ + std::string imageName; + Matx33d mat; +}; + +class CV_EXPORTS IR_affine : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<IR_affine> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/ir_robot.hpp b/include/opencv2/datasets/ir_robot.hpp new file mode 100644 index 0000000..446e3be --- /dev/null +++ b/include/opencv2/datasets/ir_robot.hpp @@ -0,0 +1,89 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_IR_ROBOT_HPP +#define OPENCV_DATASETS_IR_ROBOT_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ir +//! @{ + +// calibration matrix from calibrationFile.mat +// 2.8290e+03 0.0000e+00 8.0279e+02 +// 0.0000e+00 2.8285e+03 6.1618e+02 +// 0.0000e+00 0.0000e+00 1.0000e+00 + +struct cameraPos +{ + std::vector<std::string> images; +}; + +struct IR_robotObj : public Object +{ + std::string name; + std::vector<cameraPos> pos; +}; + +class CV_EXPORTS IR_robot : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<IR_robot> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/is_bsds.hpp b/include/opencv2/datasets/is_bsds.hpp new file mode 100644 index 0000000..b4a3e65 --- /dev/null +++ b/include/opencv2/datasets/is_bsds.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_IS_BSDS_HPP +#define OPENCV_DATASETS_IS_BSDS_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_is +//! @{ + +struct IS_bsdsObj : public Object +{ + std::string name; +}; + +class CV_EXPORTS IS_bsds : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<IS_bsds> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/is_weizmann.hpp b/include/opencv2/datasets/is_weizmann.hpp new file mode 100644 index 0000000..4f61578 --- /dev/null +++ b/include/opencv2/datasets/is_weizmann.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_IS_WEIZMANN_HPP +#define OPENCV_DATASETS_IS_WEIZMANN_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_is +//! @{ + +struct IS_weizmannObj : public Object +{ + std::string imageName; + std::string srcBw; + std::string srcColor; + std::string humanSeg; // TODO: read human segmented +}; + +class CV_EXPORTS IS_weizmann : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<IS_weizmann> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/msm_epfl.hpp b/include/opencv2/datasets/msm_epfl.hpp new file mode 100644 index 0000000..54aebde --- /dev/null +++ b/include/opencv2/datasets/msm_epfl.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_MSM_EPFL_HPP +#define OPENCV_DATASETS_MSM_EPFL_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_msm +//! @{ + +struct cameraParam +{ + Matx33d mat1; + double mat2[3]; + Matx33d mat3; + double mat4[3]; + int imageWidth, imageHeight; +}; + +struct MSM_epflObj : public Object +{ + std::string imageName; + Matx23d bounding; + Matx34d p; + cameraParam camera; +}; + +class CV_EXPORTS MSM_epfl : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<MSM_epfl> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/msm_middlebury.hpp b/include/opencv2/datasets/msm_middlebury.hpp new file mode 100644 index 0000000..9b883e5 --- /dev/null +++ b/include/opencv2/datasets/msm_middlebury.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_MSM_MIDDLEBURY_HPP +#define OPENCV_DATASETS_MSM_MIDDLEBURY_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_msm +//! @{ + +struct MSM_middleburyObj : public Object +{ + std::string imageName; + Matx33d k; + Matx33d r; + double t[3]; +}; + +class CV_EXPORTS MSM_middlebury : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<MSM_middlebury> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/or_imagenet.hpp b/include/opencv2/datasets/or_imagenet.hpp new file mode 100644 index 0000000..079165b --- /dev/null +++ b/include/opencv2/datasets/or_imagenet.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_OR_IMAGENET_HPP +#define OPENCV_DATASETS_OR_IMAGENET_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ + +struct OR_imagenetObj : public Object +{ + int id; + std::string image; +}; + +class CV_EXPORTS OR_imagenet : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<OR_imagenet> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/or_mnist.hpp b/include/opencv2/datasets/or_mnist.hpp new file mode 100644 index 0000000..ac4d838 --- /dev/null +++ b/include/opencv2/datasets/or_mnist.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_OR_MNIST_HPP +#define OPENCV_DATASETS_OR_MNIST_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ + +struct OR_mnistObj : public Object +{ + char label; // 0..9 + Mat image; // [28][28] +}; + +class CV_EXPORTS OR_mnist : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<OR_mnist> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/or_pascal.hpp b/include/opencv2/datasets/or_pascal.hpp new file mode 100644 index 0000000..c5f27af --- /dev/null +++ b/include/opencv2/datasets/or_pascal.hpp @@ -0,0 +1,102 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_VOC_PASCAL_HPP +#define OPENCV_DATASETS_VOC_PASCAL_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ +struct PascalPart: public Object +{ + std::string name; + int xmin; + int ymin; + int xmax; + int ymax; +}; + +struct PascalObj: public PascalPart +{ + std::string pose; + bool truncated; + bool difficult; + bool occluded; + + std::vector<PascalPart> parts; +}; + +struct OR_pascalObj : public Object +{ + std::string filename; + + int width; + int height; + int depth; + + std::vector<PascalObj> objects; +}; + +class CV_EXPORTS OR_pascal : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<OR_pascal> create(); +}; + +//! @} + +}// namespace dataset +}// namespace cv + +#endif diff --git a/include/opencv2/datasets/or_sun.hpp b/include/opencv2/datasets/or_sun.hpp new file mode 100644 index 0000000..7d3d887 --- /dev/null +++ b/include/opencv2/datasets/or_sun.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_OR_SUN_HPP +#define OPENCV_DATASETS_OR_SUN_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ + +struct OR_sunObj : public Object +{ + int label; + std::string name; +}; + +class CV_EXPORTS OR_sun : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<OR_sun> create(); + + std::vector<std::string> paths; +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/pd_caltech.hpp b/include/opencv2/datasets/pd_caltech.hpp new file mode 100644 index 0000000..c8545e2 --- /dev/null +++ b/include/opencv2/datasets/pd_caltech.hpp @@ -0,0 +1,89 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_PD_CALTECH_HPP +#define OPENCV_DATASETS_PD_CALTECH_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_pd +//! @{ + +struct PD_caltechObj : public Object +{ + //double groundTrue[][]; + //Mat image; + std::string name; + std::vector< std::string > imageNames; +}; + +// +// first version of Caltech Pedestrian dataset loading +// code to unpack all frames from seq files commented as their number is huge +// so currently load only meta information without data +// +// also ground truth isn't processed, as need to convert it from mat files first +// + +class CV_EXPORTS PD_caltech : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<PD_caltech> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/pd_inria.hpp b/include/opencv2/datasets/pd_inria.hpp new file mode 100644 index 0000000..9e1d30b --- /dev/null +++ b/include/opencv2/datasets/pd_inria.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_PD_INRIA_HPP +#define OPENCV_DATASETS_PD_INRIA_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_pd +//! @{ + +enum sampleType +{ + POS = 0, + NEG = 1 +}; + +struct PD_inriaObj : public Object +{ + // image file name + std::string filename; + + // positive or negative + sampleType sType; + + // image size + int width; + int height; + int depth; + + // bounding boxes + std::vector< Rect > bndboxes; +}; + +class CV_EXPORTS PD_inria : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<PD_inria> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/slam_kitti.hpp b/include/opencv2/datasets/slam_kitti.hpp new file mode 100644 index 0000000..a004b95 --- /dev/null +++ b/include/opencv2/datasets/slam_kitti.hpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_SLAM_KITTI_HPP +#define OPENCV_DATASETS_SLAM_KITTI_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_slam +//! @{ + +struct pose +{ + double elem[12]; +}; + +struct SLAM_kittiObj : public Object +{ + std::string name; + std::vector<std::string> images[4]; + std::vector<std::string> velodyne; + std::vector<double> times, p[4]; + std::vector<pose> posesArray; +}; + +class CV_EXPORTS SLAM_kitti : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<SLAM_kitti> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/slam_tumindoor.hpp b/include/opencv2/datasets/slam_tumindoor.hpp new file mode 100644 index 0000000..eca07ad --- /dev/null +++ b/include/opencv2/datasets/slam_tumindoor.hpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_SLAM_TUMINDOOR_HPP +#define OPENCV_DATASETS_SLAM_TUMINDOOR_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_slam +//! @{ + +enum imageType +{ + LEFT = 0, + RIGHT, + LADYBUG +}; + +struct SLAM_tumindoorObj : public Object +{ + std::string name; + Matx44d transformMat; + imageType type; +}; + +class CV_EXPORTS SLAM_tumindoor : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<SLAM_tumindoor> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/tr_chars.hpp b/include/opencv2/datasets/tr_chars.hpp new file mode 100644 index 0000000..69aab83 --- /dev/null +++ b/include/opencv2/datasets/tr_chars.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_TR_CHARS_HPP +#define OPENCV_DATASETS_TR_CHARS_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_tr +//! @{ + +struct TR_charsObj : public Object +{ + std::string imgName; + int label; +}; + +class CV_EXPORTS TR_chars : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<TR_chars> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/tr_icdar.hpp b/include/opencv2/datasets/tr_icdar.hpp new file mode 100644 index 0000000..3b43d69 --- /dev/null +++ b/include/opencv2/datasets/tr_icdar.hpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_TR_ICDAR_HPP +#define OPENCV_DATASETS_TR_ICDAR_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_tr +//! @{ + +struct word +{ + std::string value; + int height, width, x, y; +}; + +struct TR_icdarObj : public Object +{ + std::string fileName; + std::vector<std::string> lex100; + std::vector<std::string> lexFull; + std::vector<word> words; +}; + +class CV_EXPORTS TR_icdar : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<TR_icdar> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/tr_svt.hpp b/include/opencv2/datasets/tr_svt.hpp new file mode 100644 index 0000000..7b94180 --- /dev/null +++ b/include/opencv2/datasets/tr_svt.hpp @@ -0,0 +1,86 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_TR_SVT_HPP +#define OPENCV_DATASETS_TR_SVT_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_tr +//! @{ + +struct tag +{ + std::string value; + int height, width, x, y; +}; + +struct TR_svtObj : public Object +{ + std::string fileName; + std::vector<std::string> lex; + std::vector<tag> tags; +}; + +class CV_EXPORTS TR_svt : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr<TR_svt> create(); +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/track_alov.hpp b/include/opencv2/datasets/track_alov.hpp new file mode 100644 index 0000000..a3c5da0 --- /dev/null +++ b/include/opencv2/datasets/track_alov.hpp @@ -0,0 +1,107 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_TRACK_ALOV_HPP +#define OPENCV_DATASETS_TRACK_ALOV_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" +#include "opencv2/datasets/util.hpp" + +using namespace std; + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_track +//! @{ + +struct TRACK_alovObj : public Object +{ + int id; + std::string imagePath; + vector <Point2f> gtbb; +}; + +const string sectionNames[] = { "01-Light", "02-SurfaceCover", "03-Specularity", "04-Transparency", "05-Shape", "06-MotionSmoothness", "07-MotionCoherence", +"08-Clutter", "09-Confusion", "10-LowContrast", "11-Occlusion", "12-MovingCamera", "13-ZoomingCamera", "14-LongDuration" }; + +const int sectionSizes[] = { 33, 15, 18, 20, 24, 22, 12, 15, 37, 23, 34, 22, 29, 10 }; + +class CV_EXPORTS TRACK_alov : public Dataset +{ +public: + static Ptr<TRACK_alov> create(); + + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + //Load only frames with annotations (~every 5-th frame) + virtual void loadAnnotatedOnly(const std::string &path) = 0; + + virtual int getDatasetsNum() = 0; + + virtual int getDatasetLength(int id) = 0; + + virtual bool initDataset(int id) = 0; + + virtual bool getNextFrame(Mat &frame) = 0; + virtual vector <Point2f> getNextGT() = 0; + + //Get frame/GT by datasetID (1..N) frameID (1..K) + virtual bool getFrame(Mat &frame, int datasetID, int frameID) = 0; + virtual vector <Point2f> getGT(int datasetID, int frameID) = 0; + +protected: + vector <vector <Ptr<TRACK_alovObj> > > data; + int activeDatasetID; + int frameCounter; +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/track_vot.hpp b/include/opencv2/datasets/track_vot.hpp new file mode 100644 index 0000000..a5a9c6f --- /dev/null +++ b/include/opencv2/datasets/track_vot.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_TRACK_VOT_HPP +#define OPENCV_DATASETS_TRACK_VOT_HPP + +#include <string> +#include <vector> + +#include "opencv2/datasets/dataset.hpp" +#include "opencv2/datasets/util.hpp" + +using namespace std; + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_track +//! @{ + +struct TRACK_votObj : public Object +{ + int id; + std::string imagePath; + vector <Point2d> gtbb; +}; + +class CV_EXPORTS TRACK_vot : public Dataset +{ +public: + static Ptr<TRACK_vot> create(); + + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + virtual int getDatasetsNum() = 0; + + virtual int getDatasetLength(int id) = 0; + + virtual bool initDataset(int id) = 0; + + virtual bool getNextFrame(Mat &frame) = 0; + + virtual vector <Point2d> getGT() = 0; + +protected: + vector <vector <Ptr<TRACK_votObj> > > data; + int activeDatasetID; + int frameCounter; +}; + +//! @} + +} +} + +#endif diff --git a/include/opencv2/datasets/util.hpp b/include/opencv2/datasets/util.hpp new file mode 100644 index 0000000..316de3a --- /dev/null +++ b/include/opencv2/datasets/util.hpp @@ -0,0 +1,74 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +//M*/ + +#ifndef OPENCV_DATASETS_UTIL_HPP +#define OPENCV_DATASETS_UTIL_HPP + +#include <string> +#include <vector> + +#include <cstdio> +#include <cstdlib> // atoi, atof + +#include <fstream> + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets +//! @{ + +void CV_EXPORTS split(const std::string &s, std::vector<std::string> &elems, char delim); + +void CV_EXPORTS createDirectory(const std::string &path); + +void CV_EXPORTS getDirList(const std::string &dirName, std::vector<std::string> &fileNames); + +//! @} + +} +} + +#endif diff --git a/include/opencv2/dnn.hpp b/include/opencv2/dnn.hpp new file mode 100644 index 0000000..97f2fe3 --- /dev/null +++ b/include/opencv2/dnn.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_DNN_HPP +#define OPENCV_DNN_HPP + +// This is an umbrella header to include into you project. +// We are free to change headers layout in dnn subfolder, so please include +// this header for future compatibility + + +/** @defgroup dnn Deep Neural Network module + @{ + This module contains: + - API for new layers creation, layers are building bricks of neural networks; + - set of built-in most-useful Layers; + - API to construct and modify comprehensive neural networks from layers; + - functionality for loading serialized networks models from different frameworks. + + Functionality of this module is designed only for forward pass computations (i.e. network testing). + A network training is in principle not supported. + @} +*/ +/** @example samples/dnn/classification.cpp +Check @ref tutorial_dnn_googlenet "the corresponding tutorial" for more details +*/ +/** @example samples/dnn/colorization.cpp +*/ +/** @example samples/dnn/object_detection.cpp +Check @ref tutorial_dnn_yolo "the corresponding tutorial" for more details +*/ +/** @example samples/dnn/openpose.cpp +*/ +/** @example samples/dnn/segmentation.cpp +*/ +/** @example samples/dnn/text_detection.cpp +*/ +#include <opencv2/dnn/dnn.hpp> + +#endif /* OPENCV_DNN_HPP */ diff --git a/include/opencv2/dnn/all_layers.hpp b/include/opencv2/dnn/all_layers.hpp new file mode 100644 index 0000000..c6fe6d0 --- /dev/null +++ b/include/opencv2/dnn/all_layers.hpp @@ -0,0 +1,634 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_ALL_LAYERS_HPP +#define OPENCV_DNN_DNN_ALL_LAYERS_HPP +#include <opencv2/dnn.hpp> + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ + +/** @defgroup dnnLayerList Partial List of Implemented Layers + @{ + This subsection of dnn module contains information about built-in layers and their descriptions. + + Classes listed here, in fact, provides C++ API for creating instances of built-in layers. + In addition to this way of layers instantiation, there is a more common factory API (see @ref dnnLayerFactory), it allows to create layers dynamically (by name) and register new ones. + You can use both API, but factory API is less convenient for native C++ programming and basically designed for use inside importers (see @ref readNetFromCaffe(), @ref readNetFromTorch(), @ref readNetFromTensorflow()). + + Built-in layers partially reproduce functionality of corresponding Caffe and Torch7 layers. + In particular, the following layers and Caffe importer were tested to reproduce <a href="http://caffe.berkeleyvision.org/tutorial/layers.html">Caffe</a> functionality: + - Convolution + - Deconvolution + - Pooling + - InnerProduct + - TanH, ReLU, Sigmoid, BNLL, Power, AbsVal + - Softmax + - Reshape, Flatten, Slice, Split + - LRN + - MVN + - Dropout (since it does nothing on forward pass -)) +*/ + + class CV_EXPORTS BlankLayer : public Layer + { + public: + static Ptr<Layer> create(const LayerParams ¶ms); + }; + + /** + * Constant layer produces the same data blob at an every forward pass. + */ + class CV_EXPORTS ConstLayer : public Layer + { + public: + static Ptr<Layer> create(const LayerParams ¶ms); + }; + + //! LSTM recurrent layer + class CV_EXPORTS LSTMLayer : public Layer + { + public: + /** Creates instance of LSTM layer */ + static Ptr<LSTMLayer> create(const LayerParams& params); + + /** @deprecated Use LayerParams::blobs instead. + @brief Set trained weights for LSTM layer. + + LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights. + + Let @f$x_t@f$ be current input, @f$h_t@f$ be current output, @f$c_t@f$ be current state. + Than current output and current cell state is computed as follows: + @f{eqnarray*}{ + h_t &= o_t \odot tanh(c_t), \\ + c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \\ + @f} + where @f$\odot@f$ is per-element multiply operation and @f$i_t, f_t, o_t, g_t@f$ is internal gates that are computed using learned wights. + + Gates are computed as follows: + @f{eqnarray*}{ + i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \\ + f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \\ + o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \\ + g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \\ + @f} + where @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices: + @f$W_{x?} \in R^{N_h \times N_x}@f$, @f$W_{h?} \in R^{N_h \times N_h}@f$, @f$b_? \in R^{N_h}@f$. + + For simplicity and performance purposes we use @f$ W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] @f$ + (i.e. @f$W_x@f$ is vertical concatenation of @f$ W_{x?} @f$), @f$ W_x \in R^{4N_h \times N_x} @f$. + The same for @f$ W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} @f$ + and for @f$ b = [b_i; b_f, b_o, b_g]@f$, @f$b \in R^{4N_h} @f$. + + @param Wh is matrix defining how previous output is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_h @f$) + @param Wx is matrix defining how current input is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_x @f$) + @param b is bias vector (i.e. according to above mentioned notation is @f$ b @f$) + */ + CV_DEPRECATED virtual void setWeights(const Mat &Wh, const Mat &Wx, const Mat &b) = 0; + + /** @brief Specifies shape of output blob which will be [[`T`], `N`] + @p outTailShape. + * @details If this parameter is empty or unset then @p outTailShape = [`Wh`.size(0)] will be used, + * where `Wh` is parameter from setWeights(). + */ + virtual void setOutShape(const MatShape &outTailShape = MatShape()) = 0; + + /** @deprecated Use flag `produce_cell_output` in LayerParams. + * @brief Specifies either interpret first dimension of input blob as timestamp dimenion either as sample. + * + * If flag is set to true then shape of input blob will be interpreted as [`T`, `N`, `[data dims]`] where `T` specifies number of timestamps, `N` is number of independent streams. + * In this case each forward() call will iterate through `T` timestamps and update layer's state `T` times. + * + * If flag is set to false then shape of input blob will be interpreted as [`N`, `[data dims]`]. + * In this case each forward() call will make one iteration and produce one timestamp with shape [`N`, `[out dims]`]. + */ + CV_DEPRECATED virtual void setUseTimstampsDim(bool use = true) = 0; + + /** @deprecated Use flag `use_timestamp_dim` in LayerParams. + * @brief If this flag is set to true then layer will produce @f$ c_t @f$ as second output. + * @details Shape of the second output is the same as first output. + */ + CV_DEPRECATED virtual void setProduceCellOutput(bool produce = false) = 0; + + /* In common case it use single input with @f$x_t@f$ values to compute output(s) @f$h_t@f$ (and @f$c_t@f$). + * @param input should contain packed values @f$x_t@f$ + * @param output contains computed outputs: @f$h_t@f$ (and @f$c_t@f$ if setProduceCellOutput() flag was set to true). + * + * If setUseTimstampsDim() is set to true then @p input[0] should has at least two dimensions with the following shape: [`T`, `N`, `[data dims]`], + * where `T` specifies number of timestamps, `N` is number of independent streams (i.e. @f$ x_{t_0 + t}^{stream} @f$ is stored inside @p input[0][t, stream, ...]). + * + * If setUseTimstampsDim() is set to false then @p input[0] should contain single timestamp, its shape should has form [`N`, `[data dims]`] with at least one dimension. + * (i.e. @f$ x_{t}^{stream} @f$ is stored inside @p input[0][stream, ...]). + */ + + int inputNameToIndex(String inputName) CV_OVERRIDE; + int outputNameToIndex(const String& outputName) CV_OVERRIDE; + }; + + /** @brief Classical recurrent layer + + Accepts two inputs @f$x_t@f$ and @f$h_{t-1}@f$ and compute two outputs @f$o_t@f$ and @f$h_t@f$. + + - input: should contain packed input @f$x_t@f$. + - output: should contain output @f$o_t@f$ (and @f$h_t@f$ if setProduceHiddenOutput() is set to true). + + input[0] should have shape [`T`, `N`, `data_dims`] where `T` and `N` is number of timestamps and number of independent samples of @f$x_t@f$ respectively. + + output[0] will have shape [`T`, `N`, @f$N_o@f$], where @f$N_o@f$ is number of rows in @f$ W_{xo} @f$ matrix. + + If setProduceHiddenOutput() is set to true then @p output[1] will contain a Mat with shape [`T`, `N`, @f$N_h@f$], where @f$N_h@f$ is number of rows in @f$ W_{hh} @f$ matrix. + */ + class CV_EXPORTS RNNLayer : public Layer + { + public: + /** Creates instance of RNNLayer */ + static Ptr<RNNLayer> create(const LayerParams& params); + + /** Setups learned weights. + + Recurrent-layer behavior on each step is defined by current input @f$ x_t @f$, previous state @f$ h_t @f$ and learned weights as follows: + @f{eqnarray*}{ + h_t &= tanh&(W_{hh} h_{t-1} + W_{xh} x_t + b_h), \\ + o_t &= tanh&(W_{ho} h_t + b_o), + @f} + + @param Wxh is @f$ W_{xh} @f$ matrix + @param bh is @f$ b_{h} @f$ vector + @param Whh is @f$ W_{hh} @f$ matrix + @param Who is @f$ W_{xo} @f$ matrix + @param bo is @f$ b_{o} @f$ vector + */ + virtual void setWeights(const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo) = 0; + + /** @brief If this flag is set to true then layer will produce @f$ h_t @f$ as second output. + * @details Shape of the second output is the same as first output. + */ + virtual void setProduceHiddenOutput(bool produce = false) = 0; + + }; + + class CV_EXPORTS BaseConvolutionLayer : public Layer + { + public: + Size kernel, stride, pad, dilation, adjustPad; + String padMode; + int numOutput; + }; + + class CV_EXPORTS ConvolutionLayer : public BaseConvolutionLayer + { + public: + static Ptr<BaseConvolutionLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer + { + public: + static Ptr<BaseConvolutionLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS LRNLayer : public Layer + { + public: + int type; + + int size; + float alpha, beta, bias; + bool normBySize; + + static Ptr<LRNLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS PoolingLayer : public Layer + { + public: + int type; + Size kernel, stride; + int pad_l, pad_t, pad_r, pad_b; + CV_DEPRECATED_EXTERNAL Size pad; + bool globalPooling; + bool computeMaxIdx; + String padMode; + bool ceilMode; + // If true for average pooling with padding, divide an every output region + // by a whole kernel area. Otherwise exclude zero padded values and divide + // by number of real values. + bool avePoolPaddedArea; + // ROIPooling parameters. + Size pooledSize; + float spatialScale; + // PSROIPooling parameters. + int psRoiOutChannels; + + static Ptr<PoolingLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS SoftmaxLayer : public Layer + { + public: + bool logSoftMax; + + static Ptr<SoftmaxLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS InnerProductLayer : public Layer + { + public: + int axis; + static Ptr<InnerProductLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS MVNLayer : public Layer + { + public: + float eps; + bool normVariance, acrossChannels; + + static Ptr<MVNLayer> create(const LayerParams& params); + }; + + /* Reshaping */ + + class CV_EXPORTS ReshapeLayer : public Layer + { + public: + MatShape newShapeDesc; + Range newShapeRange; + + static Ptr<ReshapeLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS FlattenLayer : public Layer + { + public: + static Ptr<FlattenLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ConcatLayer : public Layer + { + public: + int axis; + /** + * @brief Add zero padding in case of concatenation of blobs with different + * spatial sizes. + * + * Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat + */ + bool padding; + + static Ptr<ConcatLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SplitLayer : public Layer + { + public: + int outputsCount; //!< Number of copies that will be produced (is ignored when negative). + + static Ptr<SplitLayer> create(const LayerParams ¶ms); + }; + + /** + * Slice layer has several modes: + * 1. Caffe mode + * @param[in] axis Axis of split operation + * @param[in] slice_point Array of split points + * + * Number of output blobs equals to number of split points plus one. The + * first blob is a slice on input from 0 to @p slice_point[0] - 1 by @p axis, + * the second output blob is a slice of input from @p slice_point[0] to + * @p slice_point[1] - 1 by @p axis and the last output blob is a slice of + * input from @p slice_point[-1] up to the end of @p axis size. + * + * 2. TensorFlow mode + * @param begin Vector of start indices + * @param size Vector of sizes + * + * More convenient numpy-like slice. One and only output blob + * is a slice `input[begin[0]:begin[0]+size[0], begin[1]:begin[1]+size[1], ...]` + * + * 3. Torch mode + * @param axis Axis of split operation + * + * Split input blob on the equal parts by @p axis. + */ + class CV_EXPORTS SliceLayer : public Layer + { + public: + /** + * @brief Vector of slice ranges. + * + * The first dimension equals number of output blobs. + * Inner vector has slice ranges for the first number of input dimensions. + */ + std::vector<std::vector<Range> > sliceRanges; + int axis; + + static Ptr<SliceLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS PermuteLayer : public Layer + { + public: + static Ptr<PermuteLayer> create(const LayerParams& params); + }; + + /** + * Permute channels of 4-dimensional input blob. + * @param group Number of groups to split input channels and pick in turns + * into output blob. + * + * \f[ groupSize = \frac{number\ of\ channels}{group} \f] + * \f[ output(n, c, h, w) = input(n, groupSize \times (c \% group) + \lfloor \frac{c}{group} \rfloor, h, w) \f] + * Read more at https://arxiv.org/pdf/1707.01083.pdf + */ + class CV_EXPORTS ShuffleChannelLayer : public Layer + { + public: + static Ptr<Layer> create(const LayerParams& params); + + int group; + }; + + /** + * @brief Adds extra values for specific axes. + * @param paddings Vector of paddings in format + * @code + * [ pad_before, pad_after, // [0]th dimension + * pad_before, pad_after, // [1]st dimension + * ... + * pad_before, pad_after ] // [n]th dimension + * @endcode + * that represents number of padded values at every dimension + * starting from the first one. The rest of dimensions won't + * be padded. + * @param value Value to be padded. Defaults to zero. + * @param type Padding type: 'constant', 'reflect' + * @param input_dims Torch's parameter. If @p input_dims is not equal to the + * actual input dimensionality then the `[0]th` dimension + * is considered as a batch dimension and @p paddings are shifted + * to a one dimension. Defaults to `-1` that means padding + * corresponding to @p paddings. + */ + class CV_EXPORTS PaddingLayer : public Layer + { + public: + static Ptr<PaddingLayer> create(const LayerParams& params); + }; + + /* Activations */ + class CV_EXPORTS ActivationLayer : public Layer + { + public: + virtual void forwardSlice(const float* src, float* dst, int len, + size_t outPlaneSize, int cn0, int cn1) const = 0; + }; + + class CV_EXPORTS ReLULayer : public ActivationLayer + { + public: + float negativeSlope; + + static Ptr<ReLULayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ReLU6Layer : public ActivationLayer + { + public: + float minValue, maxValue; + + static Ptr<ReLU6Layer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ChannelsPReLULayer : public ActivationLayer + { + public: + static Ptr<Layer> create(const LayerParams& params); + }; + + class CV_EXPORTS ELULayer : public ActivationLayer + { + public: + static Ptr<ELULayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS TanHLayer : public ActivationLayer + { + public: + static Ptr<TanHLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SigmoidLayer : public ActivationLayer + { + public: + static Ptr<SigmoidLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS BNLLLayer : public ActivationLayer + { + public: + static Ptr<BNLLLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS AbsLayer : public ActivationLayer + { + public: + static Ptr<AbsLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS PowerLayer : public ActivationLayer + { + public: + float power, scale, shift; + + static Ptr<PowerLayer> create(const LayerParams ¶ms); + }; + + /* Layers used in semantic segmentation */ + + class CV_EXPORTS CropLayer : public Layer + { + public: + int startAxis; + std::vector<int> offset; + + static Ptr<CropLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS EltwiseLayer : public Layer + { + public: + static Ptr<EltwiseLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS BatchNormLayer : public ActivationLayer + { + public: + bool hasWeights, hasBias; + float epsilon; + + static Ptr<BatchNormLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS MaxUnpoolLayer : public Layer + { + public: + Size poolKernel; + Size poolPad; + Size poolStride; + + static Ptr<MaxUnpoolLayer> create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ScaleLayer : public Layer + { + public: + bool hasBias; + int axis; + + static Ptr<ScaleLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS ShiftLayer : public Layer + { + public: + static Ptr<Layer> create(const LayerParams& params); + }; + + class CV_EXPORTS PriorBoxLayer : public Layer + { + public: + static Ptr<PriorBoxLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS ReorgLayer : public Layer + { + public: + static Ptr<ReorgLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS RegionLayer : public Layer + { + public: + static Ptr<RegionLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS DetectionOutputLayer : public Layer + { + public: + static Ptr<DetectionOutputLayer> create(const LayerParams& params); + }; + + /** + * @brief \f$ L_p \f$ - normalization layer. + * @param p Normalization factor. The most common `p = 1` for \f$ L_1 \f$ - + * normalization or `p = 2` for \f$ L_2 \f$ - normalization or a custom one. + * @param eps Parameter \f$ \epsilon \f$ to prevent a division by zero. + * @param across_spatial If true, normalize an input across all non-batch dimensions. + * Otherwise normalize an every channel separately. + * + * Across spatial: + * @f[ + * norm = \sqrt[p]{\epsilon + \sum_{x, y, c} |src(x, y, c)|^p } \\ + * dst(x, y, c) = \frac{ src(x, y, c) }{norm} + * @f] + * + * Channel wise normalization: + * @f[ + * norm(c) = \sqrt[p]{\epsilon + \sum_{x, y} |src(x, y, c)|^p } \\ + * dst(x, y, c) = \frac{ src(x, y, c) }{norm(c)} + * @f] + * + * Where `x, y` - spatial coordinates, `c` - channel. + * + * An every sample in the batch is normalized separately. Optionally, + * output is scaled by the trained parameters. + */ + class CV_EXPORTS NormalizeBBoxLayer : public Layer + { + public: + float pnorm, epsilon; + CV_DEPRECATED_EXTERNAL bool acrossSpatial; + + static Ptr<NormalizeBBoxLayer> create(const LayerParams& params); + }; + + /** + * @brief Resize input 4-dimensional blob by nearest neighbor or bilinear strategy. + * + * Layer is used to support TensorFlow's resize_nearest_neighbor and resize_bilinear ops. + */ + class CV_EXPORTS ResizeLayer : public Layer + { + public: + static Ptr<ResizeLayer> create(const LayerParams& params); + }; + + /** + * @brief Bilinear resize layer from https://github.com/cdmh/deeplab-public + * + * It differs from @ref ResizeLayer in output shape and resize scales computations. + */ + class CV_EXPORTS InterpLayer : public Layer + { + public: + static Ptr<Layer> create(const LayerParams& params); + }; + + class CV_EXPORTS ProposalLayer : public Layer + { + public: + static Ptr<ProposalLayer> create(const LayerParams& params); + }; + + class CV_EXPORTS CropAndResizeLayer : public Layer + { + public: + static Ptr<Layer> create(const LayerParams& params); + }; + +//! @} +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} +#endif diff --git a/include/opencv2/dnn/dict.hpp b/include/opencv2/dnn/dict.hpp new file mode 100644 index 0000000..60c2aa5 --- /dev/null +++ b/include/opencv2/dnn/dict.hpp @@ -0,0 +1,160 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#include <opencv2/core.hpp> +#include <map> +#include <ostream> + +#include <opencv2/dnn/dnn.hpp> + +#ifndef OPENCV_DNN_DNN_DICT_HPP +#define OPENCV_DNN_DNN_DICT_HPP + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ + +/** @brief This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64. + * @todo Maybe int64 is useless because double type exactly stores at least 2^52 integers. + */ +struct CV_EXPORTS_W DictValue +{ + DictValue(const DictValue &r); + DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar + DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar + CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar + DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = p; } //!< Constructs integer scalar + CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar + CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar + DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload + + template<typename TypeIter> + static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array + template<typename TypeIter> + static DictValue arrayReal(TypeIter begin, int size); //!< Constructs floating point array + template<typename TypeIter> + static DictValue arrayString(TypeIter begin, int size); //!< Constructs array of strings + + template<typename T> + T get(int idx = -1) const; //!< Tries to convert array element with specified index to requested type and returns its. + + int size() const; + + CV_WRAP bool isInt() const; + CV_WRAP bool isString() const; + CV_WRAP bool isReal() const; + + CV_WRAP int getIntValue(int idx = -1) const; + CV_WRAP double getRealValue(int idx = -1) const; + CV_WRAP String getStringValue(int idx = -1) const; + + DictValue &operator=(const DictValue &r); + + friend std::ostream &operator<<(std::ostream &stream, const DictValue &dictv); + + ~DictValue(); + +private: + + int type; + + union + { + AutoBuffer<int64, 1> *pi; + AutoBuffer<double, 1> *pd; + AutoBuffer<String, 1> *ps; + void *pv; + }; + + DictValue(int _type, void *_p) : type(_type), pv(_p) {} + void release(); +}; + +/** @brief This class implements name-value dictionary, values are instances of DictValue. */ +class CV_EXPORTS Dict +{ + typedef std::map<String, DictValue> _Dict; + _Dict dict; + +public: + + //! Checks a presence of the @p key in the dictionary. + bool has(const String &key) const; + + //! If the @p key in the dictionary then returns pointer to its value, else returns NULL. + DictValue *ptr(const String &key); + + /** @overload */ + const DictValue *ptr(const String &key) const; + + //! If the @p key in the dictionary then returns its value, else an error will be generated. + const DictValue &get(const String &key) const; + + /** @overload */ + template <typename T> + T get(const String &key) const; + + //! If the @p key in the dictionary then returns its value, else returns @p defaultValue. + template <typename T> + T get(const String &key, const T &defaultValue) const; + + //! Sets new @p value for the @p key, or adds new key-value pair into the dictionary. + template<typename T> + const T &set(const String &key, const T &value); + + //! Erase @p key from the dictionary. + void erase(const String &key); + + friend std::ostream &operator<<(std::ostream &stream, const Dict &dict); + + std::map<String, DictValue>::const_iterator begin() const; + + std::map<String, DictValue>::const_iterator end() const; +}; + +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} + +#endif diff --git a/include/opencv2/dnn/dnn.hpp b/include/opencv2/dnn/dnn.hpp new file mode 100644 index 0000000..144fc11 --- /dev/null +++ b/include/opencv2/dnn/dnn.hpp @@ -0,0 +1,973 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_HPP +#define OPENCV_DNN_DNN_HPP + +#include <vector> +#include <opencv2/core.hpp> + +#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS +#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v11 { +#define CV__DNN_EXPERIMENTAL_NS_END } +namespace cv { namespace dnn { namespace experimental_dnn_34_v11 { } using namespace experimental_dnn_34_v11; }} +#else +#define CV__DNN_EXPERIMENTAL_NS_BEGIN +#define CV__DNN_EXPERIMENTAL_NS_END +#endif + +#include <opencv2/dnn/dict.hpp> + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ + + typedef std::vector<int> MatShape; + + /** + * @brief Enum of computation backends supported by layers. + * @see Net::setPreferableBackend + */ + enum Backend + { + //! DNN_BACKEND_DEFAULT equals to DNN_BACKEND_INFERENCE_ENGINE if + //! OpenCV is built with Intel's Inference Engine library or + //! DNN_BACKEND_OPENCV otherwise. + DNN_BACKEND_DEFAULT, + DNN_BACKEND_HALIDE, + DNN_BACKEND_INFERENCE_ENGINE, + DNN_BACKEND_OPENCV + }; + + /** + * @brief Enum of target devices for computations. + * @see Net::setPreferableTarget + */ + enum Target + { + DNN_TARGET_CPU, + DNN_TARGET_OPENCL, + DNN_TARGET_OPENCL_FP16, + DNN_TARGET_MYRIAD, + //! FPGA device with CPU fallbacks using Inference Engine's Heterogeneous plugin. + DNN_TARGET_FPGA + }; + + CV_EXPORTS std::vector< std::pair<Backend, Target> > getAvailableBackends(); + CV_EXPORTS std::vector<Target> getAvailableTargets(Backend be); + + /** @brief This class provides all data needed to initialize layer. + * + * It includes dictionary with scalar params (which can be read by using Dict interface), + * blob params #blobs and optional meta information: #name and #type of layer instance. + */ + class CV_EXPORTS LayerParams : public Dict + { + public: + //TODO: Add ability to name blob params + std::vector<Mat> blobs; //!< List of learned parameters stored as blobs. + + String name; //!< Name of the layer instance (optional, can be used internal purposes). + String type; //!< Type name which was used for creating layer by layer factory (optional). + }; + + /** + * @brief Derivatives of this class encapsulates functions of certain backends. + */ + class BackendNode + { + public: + BackendNode(int backendId); + + virtual ~BackendNode(); //!< Virtual destructor to make polymorphism. + + int backendId; //!< Backend identifier. + }; + + /** + * @brief Derivatives of this class wraps cv::Mat for different backends and targets. + */ + class BackendWrapper + { + public: + BackendWrapper(int backendId, int targetId); + + /** + * @brief Wrap cv::Mat for specific backend and target. + * @param[in] targetId Target identifier. + * @param[in] m cv::Mat for wrapping. + * + * Make CPU->GPU data transfer if it's require for the target. + */ + BackendWrapper(int targetId, const cv::Mat& m); + + /** + * @brief Make wrapper for reused cv::Mat. + * @param[in] base Wrapper of cv::Mat that will be reused. + * @param[in] shape Specific shape. + * + * Initialize wrapper from another one. It'll wrap the same host CPU + * memory and mustn't allocate memory on device(i.e. GPU). It might + * has different shape. Use in case of CPU memory reusing for reuse + * associated memory on device too. + */ + BackendWrapper(const Ptr<BackendWrapper>& base, const MatShape& shape); + + virtual ~BackendWrapper(); //!< Virtual destructor to make polymorphism. + + /** + * @brief Transfer data to CPU host memory. + */ + virtual void copyToHost() = 0; + + /** + * @brief Indicate that an actual data is on CPU. + */ + virtual void setHostDirty() = 0; + + int backendId; //!< Backend identifier. + int targetId; //!< Target identifier. + }; + + class CV_EXPORTS ActivationLayer; + + /** @brief This interface class allows to build new Layers - are building blocks of networks. + * + * Each class, derived from Layer, must implement allocate() methods to declare own outputs and forward() to compute outputs. + * Also before using the new layer into networks you must register your layer by using one of @ref dnnLayerFactory "LayerFactory" macros. + */ + class CV_EXPORTS_W Layer : public Algorithm + { + public: + + //! List of learned parameters must be stored here to allow read them by using Net::getParam(). + CV_PROP_RW std::vector<Mat> blobs; + + /** @brief Computes and sets internal parameters according to inputs, outputs and blobs. + * @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead + * @param[in] input vector of already allocated input blobs + * @param[out] output vector of already allocated output blobs + * + * If this method is called after network has allocated all memory for input and output blobs + * and before inferencing. + */ + CV_DEPRECATED_EXTERNAL + virtual void finalize(const std::vector<Mat*> &input, std::vector<Mat> &output); + + /** @brief Computes and sets internal parameters according to inputs, outputs and blobs. + * @param[in] inputs vector of already allocated input blobs + * @param[out] outputs vector of already allocated output blobs + * + * If this method is called after network has allocated all memory for input and output blobs + * and before inferencing. + */ + CV_WRAP virtual void finalize(InputArrayOfArrays inputs, OutputArrayOfArrays outputs); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @deprecated Use Layer::forward(InputArrayOfArrays, OutputArrayOfArrays, OutputArrayOfArrays) instead + * @param[in] input the input blobs. + * @param[out] output allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + CV_DEPRECATED_EXTERNAL + virtual void forward(std::vector<Mat*> &input, std::vector<Mat> &output, std::vector<Mat> &internals); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] inputs the input blobs. + * @param[out] outputs allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + virtual void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] inputs the input blobs. + * @param[out] outputs allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + void forward_fallback(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals); + + /** @brief + * @overload + * @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead + */ + CV_DEPRECATED_EXTERNAL + void finalize(const std::vector<Mat> &inputs, CV_OUT std::vector<Mat> &outputs); + + /** @brief + * @overload + * @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead + */ + CV_DEPRECATED std::vector<Mat> finalize(const std::vector<Mat> &inputs); + + /** @brief Allocates layer and computes output. + * @deprecated This method will be removed in the future release. + */ + CV_DEPRECATED CV_WRAP void run(const std::vector<Mat> &inputs, CV_OUT std::vector<Mat> &outputs, + CV_IN_OUT std::vector<Mat> &internals); + + /** @brief Returns index of input blob into the input array. + * @param inputName label of input blob + * + * Each layer input and output can be labeled to easily identify them using "%<layer_name%>[.output_name]" notation. + * This method maps label of input blob to its index into input vector. + */ + virtual int inputNameToIndex(String inputName); + /** @brief Returns index of output blob in output array. + * @see inputNameToIndex() + */ + CV_WRAP virtual int outputNameToIndex(const String& outputName); + + /** + * @brief Ask layer if it support specific backend for doing computations. + * @param[in] backendId computation backend identifier. + * @see Backend + */ + virtual bool supportBackend(int backendId); + + /** + * @brief Returns Halide backend node. + * @param[in] inputs Input Halide buffers. + * @see BackendNode, BackendWrapper + * + * Input buffers should be exactly the same that will be used in forward invocations. + * Despite we can use Halide::ImageParam based on input shape only, + * it helps prevent some memory management issues (if something wrong, + * Halide tests will be failed). + */ + virtual Ptr<BackendNode> initHalide(const std::vector<Ptr<BackendWrapper> > &inputs); + + virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> > &inputs); + + /** + * @brief Automatic Halide scheduling based on layer hyper-parameters. + * @param[in] node Backend node with Halide functions. + * @param[in] inputs Blobs that will be used in forward invocations. + * @param[in] outputs Blobs that will be used in forward invocations. + * @param[in] targetId Target identifier + * @see BackendNode, Target + * + * Layer don't use own Halide::Func members because we can have applied + * layers fusing. In this way the fused function should be scheduled. + */ + virtual void applyHalideScheduler(Ptr<BackendNode>& node, + const std::vector<Mat*> &inputs, + const std::vector<Mat> &outputs, + int targetId) const; + + /** + * @brief Implement layers fusing. + * @param[in] node Backend node of bottom layer. + * @see BackendNode + * + * Actual for graph-based backends. If layer attached successfully, + * returns non-empty cv::Ptr to node of the same backend. + * Fuse only over the last function. + */ + virtual Ptr<BackendNode> tryAttach(const Ptr<BackendNode>& node); + + /** + * @brief Tries to attach to the layer the subsequent activation layer, i.e. do the layer fusion in a partial case. + * @param[in] layer The subsequent activation layer. + * + * Returns true if the activation layer has been attached successfully. + */ + virtual bool setActivation(const Ptr<ActivationLayer>& layer); + + /** + * @brief Try to fuse current layer with a next one + * @param[in] top Next layer to be fused. + * @returns True if fusion was performed. + */ + virtual bool tryFuse(Ptr<Layer>& top); + + /** + * @brief Returns parameters of layers with channel-wise multiplication and addition. + * @param[out] scale Channel-wise multipliers. Total number of values should + * be equal to number of channels. + * @param[out] shift Channel-wise offsets. Total number of values should + * be equal to number of channels. + * + * Some layers can fuse their transformations with further layers. + * In example, convolution + batch normalization. This way base layer + * use weights from layer after it. Fused layer is skipped. + * By default, @p scale and @p shift are empty that means layer has no + * element-wise multiplications or additions. + */ + virtual void getScaleShift(Mat& scale, Mat& shift) const; + + /** + * @brief "Deattaches" all the layers, attached to particular layer. + */ + virtual void unsetAttached(); + + virtual bool getMemoryShapes(const std::vector<MatShape> &inputs, + const int requiredOutputs, + std::vector<MatShape> &outputs, + std::vector<MatShape> &internals) const; + virtual int64 getFLOPS(const std::vector<MatShape> &inputs, + const std::vector<MatShape> &outputs) const {CV_UNUSED(inputs); CV_UNUSED(outputs); return 0;} + + CV_PROP String name; //!< Name of the layer instance, can be used for logging or other internal purposes. + CV_PROP String type; //!< Type name which was used for creating layer by layer factory. + CV_PROP int preferableTarget; //!< prefer target for layer forwarding + + Layer(); + explicit Layer(const LayerParams ¶ms); //!< Initializes only #name, #type and #blobs fields. + void setParamsFrom(const LayerParams ¶ms); //!< Initializes only #name, #type and #blobs fields. + virtual ~Layer(); + }; + + /** @brief This class allows to create and manipulate comprehensive artificial neural networks. + * + * Neural network is presented as directed acyclic graph (DAG), where vertices are Layer instances, + * and edges specify relationships between layers inputs and outputs. + * + * Each network layer has unique integer id and unique string name inside its network. + * LayerId can store either layer name or layer id. + * + * This class supports reference counting of its instances, i. e. copies point to the same instance. + */ + class CV_EXPORTS_W_SIMPLE Net + { + public: + + CV_WRAP Net(); //!< Default constructor. + CV_WRAP ~Net(); //!< Destructor frees the net only if there aren't references to the net anymore. + + /** @brief Create a network from Intel's Model Optimizer intermediate representation. + * @param[in] xml XML configuration file with network's topology. + * @param[in] bin Binary file with trained weights. + * Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine + * backend. + */ + CV_WRAP static Net readFromModelOptimizer(const String& xml, const String& bin); + + /** Returns true if there are no layers in the network. */ + CV_WRAP bool empty() const; + + /** @brief Adds new layer to the net. + * @param name unique name of the adding layer. + * @param type typename of the adding layer (type must be registered in LayerRegister). + * @param params parameters which will be used to initialize the creating layer. + * @returns unique identifier of created layer, or -1 if a failure will happen. + */ + int addLayer(const String &name, const String &type, LayerParams ¶ms); + /** @brief Adds new layer and connects its first input to the first output of previously added layer. + * @see addLayer() + */ + int addLayerToPrev(const String &name, const String &type, LayerParams ¶ms); + + /** @brief Converts string name of the layer to the integer identifier. + * @returns id of the layer, or -1 if the layer wasn't found. + */ + CV_WRAP int getLayerId(const String &layer); + + CV_WRAP std::vector<String> getLayerNames() const; + + /** @brief Container for strings and integers. */ + typedef DictValue LayerId; + + /** @brief Returns pointer to layer with specified id or name which the network use. */ + CV_WRAP Ptr<Layer> getLayer(LayerId layerId); + + /** @brief Returns pointers to input layers of specific layer. */ + std::vector<Ptr<Layer> > getLayerInputs(LayerId layerId); // FIXIT: CV_WRAP + + /** @brief Connects output of the first layer to input of the second layer. + * @param outPin descriptor of the first layer output. + * @param inpPin descriptor of the second layer input. + * + * Descriptors have the following template <DFN><layer_name>[.input_number]</DFN>: + * - the first part of the template <DFN>layer_name</DFN> is sting name of the added layer. + * If this part is empty then the network input pseudo layer will be used; + * - the second optional part of the template <DFN>input_number</DFN> + * is either number of the layer input, either label one. + * If this part is omitted then the first layer input will be used. + * + * @see setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex() + */ + CV_WRAP void connect(String outPin, String inpPin); + + /** @brief Connects #@p outNum output of the first layer to #@p inNum input of the second layer. + * @param outLayerId identifier of the first layer + * @param outNum number of the first layer output + * @param inpLayerId identifier of the second layer + * @param inpNum number of the second layer input + */ + void connect(int outLayerId, int outNum, int inpLayerId, int inpNum); + + /** @brief Sets outputs names of the network input pseudo layer. + * + * Each net always has special own the network input pseudo layer with id=0. + * This layer stores the user blobs only and don't make any computations. + * In fact, this layer provides the only way to pass user data into the network. + * As any other layer, this layer can label its outputs and this function provides an easy way to do this. + */ + CV_WRAP void setInputsNames(const std::vector<String> &inputBlobNames); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputName name for layer which output is needed to get + * @return blob for first output of specified layer. + * @details By default runs forward pass for the whole network. + */ + CV_WRAP Mat forward(const String& outputName = String()); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputBlobs contains all output blobs for specified layer. + * @param outputName name for layer which output is needed to get + * @details If @p outputName is empty, runs forward pass for the whole network. + */ + CV_WRAP void forward(OutputArrayOfArrays outputBlobs, const String& outputName = String()); + + /** @brief Runs forward pass to compute outputs of layers listed in @p outBlobNames. + * @param outputBlobs contains blobs for first outputs of specified layers. + * @param outBlobNames names for layers which outputs are needed to get + */ + CV_WRAP void forward(OutputArrayOfArrays outputBlobs, + const std::vector<String>& outBlobNames); + + /** @brief Runs forward pass to compute outputs of layers listed in @p outBlobNames. + * @param outputBlobs contains all output blobs for each layer specified in @p outBlobNames. + * @param outBlobNames names for layers which outputs are needed to get + */ + CV_WRAP_AS(forwardAndRetrieve) void forward(CV_OUT std::vector<std::vector<Mat> >& outputBlobs, + const std::vector<String>& outBlobNames); + + /** + * @brief Compile Halide layers. + * @param[in] scheduler Path to YAML file with scheduling directives. + * @see setPreferableBackend + * + * Schedule layers that support Halide backend. Then compile them for + * specific target. For layers that not represented in scheduling file + * or if no manual scheduling used at all, automatic scheduling will be applied. + */ + CV_WRAP void setHalideScheduler(const String& scheduler); + + /** + * @brief Ask network to use specific computation backend where it supported. + * @param[in] backendId backend identifier. + * @see Backend + * + * If OpenCV is compiled with Intel's Inference Engine library, DNN_BACKEND_DEFAULT + * means DNN_BACKEND_INFERENCE_ENGINE. Otherwise it equals to DNN_BACKEND_OPENCV. + */ + CV_WRAP void setPreferableBackend(int backendId); + + /** + * @brief Ask network to make computations on specific target device. + * @param[in] targetId target identifier. + * @see Target + * + * List of supported combinations backend / target: + * | | DNN_BACKEND_OPENCV | DNN_BACKEND_INFERENCE_ENGINE | DNN_BACKEND_HALIDE | + * |------------------------|--------------------|------------------------------|--------------------| + * | DNN_TARGET_CPU | + | + | + | + * | DNN_TARGET_OPENCL | + | + | + | + * | DNN_TARGET_OPENCL_FP16 | + | + | | + * | DNN_TARGET_MYRIAD | | + | | + * | DNN_TARGET_FPGA | | + | | + */ + CV_WRAP void setPreferableTarget(int targetId); + + /** @brief Sets the new input value for the network + * @param blob A new blob. Should have CV_32F or CV_8U depth. + * @param name A name of input layer. + * @param scalefactor An optional normalization scale. + * @param mean An optional mean subtraction values. + * @see connect(String, String) to know format of the descriptor. + * + * If scale or mean values are specified, a final input blob is computed + * as: + * \f[input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\f] + */ + CV_WRAP void setInput(InputArray blob, const String& name = "", + double scalefactor = 1.0, const Scalar& mean = Scalar()); + + /** @brief Sets the new value for the learned param of the layer. + * @param layer name or id of the layer. + * @param numParam index of the layer parameter in the Layer::blobs array. + * @param blob the new value. + * @see Layer::blobs + * @note If shape of the new blob differs from the previous shape, + * then the following forward pass may fail. + */ + CV_WRAP void setParam(LayerId layer, int numParam, const Mat &blob); + + /** @brief Returns parameter blob of the layer. + * @param layer name or id of the layer. + * @param numParam index of the layer parameter in the Layer::blobs array. + * @see Layer::blobs + */ + CV_WRAP Mat getParam(LayerId layer, int numParam = 0); + + /** @brief Returns indexes of layers with unconnected outputs. + */ + CV_WRAP std::vector<int> getUnconnectedOutLayers() const; + + /** @brief Returns names of layers with unconnected outputs. + */ + CV_WRAP std::vector<String> getUnconnectedOutLayersNames() const; + + /** @brief Returns input and output shapes for all layers in loaded model; + * preliminary inferencing isn't necessary. + * @param netInputShapes shapes for all input blobs in net input layer. + * @param layersIds output parameter for layer IDs. + * @param inLayersShapes output parameter for input layers shapes; + * order is the same as in layersIds + * @param outLayersShapes output parameter for output layers shapes; + * order is the same as in layersIds + */ + CV_WRAP void getLayersShapes(const std::vector<MatShape>& netInputShapes, + CV_OUT std::vector<int>& layersIds, + CV_OUT std::vector<std::vector<MatShape> >& inLayersShapes, + CV_OUT std::vector<std::vector<MatShape> >& outLayersShapes) const; + + /** @overload */ + CV_WRAP void getLayersShapes(const MatShape& netInputShape, + CV_OUT std::vector<int>& layersIds, + CV_OUT std::vector<std::vector<MatShape> >& inLayersShapes, + CV_OUT std::vector<std::vector<MatShape> >& outLayersShapes) const; + + /** @brief Returns input and output shapes for layer with specified + * id in loaded model; preliminary inferencing isn't necessary. + * @param netInputShape shape input blob in net input layer. + * @param layerId id for layer. + * @param inLayerShapes output parameter for input layers shapes; + * order is the same as in layersIds + * @param outLayerShapes output parameter for output layers shapes; + * order is the same as in layersIds + */ + void getLayerShapes(const MatShape& netInputShape, + const int layerId, + CV_OUT std::vector<MatShape>& inLayerShapes, + CV_OUT std::vector<MatShape>& outLayerShapes) const; // FIXIT: CV_WRAP + + /** @overload */ + void getLayerShapes(const std::vector<MatShape>& netInputShapes, + const int layerId, + CV_OUT std::vector<MatShape>& inLayerShapes, + CV_OUT std::vector<MatShape>& outLayerShapes) const; // FIXIT: CV_WRAP + + /** @brief Computes FLOP for whole loaded model with specified input shapes. + * @param netInputShapes vector of shapes for all net inputs. + * @returns computed FLOP. + */ + CV_WRAP int64 getFLOPS(const std::vector<MatShape>& netInputShapes) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const MatShape& netInputShape) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const int layerId, + const std::vector<MatShape>& netInputShapes) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const int layerId, + const MatShape& netInputShape) const; + + /** @brief Returns list of types for layer used in model. + * @param layersTypes output parameter for returning types. + */ + CV_WRAP void getLayerTypes(CV_OUT std::vector<String>& layersTypes) const; + + /** @brief Returns count of layers of specified type. + * @param layerType type. + * @returns count of layers + */ + CV_WRAP int getLayersCount(const String& layerType) const; + + /** @brief Computes bytes number which are required to store + * all weights and intermediate blobs for model. + * @param netInputShapes vector of shapes for all net inputs. + * @param weights output parameter to store resulting bytes for weights. + * @param blobs output parameter to store resulting bytes for intermediate blobs. + */ + void getMemoryConsumption(const std::vector<MatShape>& netInputShapes, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; // FIXIT: CV_WRAP + /** @overload */ + CV_WRAP void getMemoryConsumption(const MatShape& netInputShape, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + /** @overload */ + CV_WRAP void getMemoryConsumption(const int layerId, + const std::vector<MatShape>& netInputShapes, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + /** @overload */ + CV_WRAP void getMemoryConsumption(const int layerId, + const MatShape& netInputShape, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + + /** @brief Computes bytes number which are required to store + * all weights and intermediate blobs for each layer. + * @param netInputShapes vector of shapes for all net inputs. + * @param layerIds output vector to save layer IDs. + * @param weights output parameter to store resulting bytes for weights. + * @param blobs output parameter to store resulting bytes for intermediate blobs. + */ + void getMemoryConsumption(const std::vector<MatShape>& netInputShapes, + CV_OUT std::vector<int>& layerIds, + CV_OUT std::vector<size_t>& weights, + CV_OUT std::vector<size_t>& blobs) const; // FIXIT: CV_WRAP + /** @overload */ + void getMemoryConsumption(const MatShape& netInputShape, + CV_OUT std::vector<int>& layerIds, + CV_OUT std::vector<size_t>& weights, + CV_OUT std::vector<size_t>& blobs) const; // FIXIT: CV_WRAP + + /** @brief Enables or disables layer fusion in the network. + * @param fusion true to enable the fusion, false to disable. The fusion is enabled by default. + */ + CV_WRAP void enableFusion(bool fusion); + + /** @brief Returns overall time for inference and timings (in ticks) for layers. + * Indexes in returned vector correspond to layers ids. Some layers can be fused with others, + * in this case zero ticks count will be return for that skipped layers. + * @param timings vector for tick timings for all layers. + * @return overall ticks for model inference. + */ + CV_WRAP int64 getPerfProfile(CV_OUT std::vector<double>& timings); + + private: + struct Impl; + Ptr<Impl> impl; + }; + + /** @brief Reads a network model stored in <a href="https://pjreddie.com/darknet/">Darknet</a> model files. + * @param cfgFile path to the .cfg file with text description of the network architecture. + * @param darknetModel path to the .weights file with learned network. + * @returns Network object that ready to do forward, throw an exception in failure cases. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromDarknet(const String &cfgFile, const String &darknetModel = String()); + + /** @brief Reads a network model stored in <a href="https://pjreddie.com/darknet/">Darknet</a> model files. + * @param bufferCfg A buffer contains a content of .cfg file with text description of the network architecture. + * @param bufferModel A buffer contains a content of .weights file with learned network. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromDarknet(const std::vector<uchar>& bufferCfg, + const std::vector<uchar>& bufferModel = std::vector<uchar>()); + + /** @brief Reads a network model stored in <a href="https://pjreddie.com/darknet/">Darknet</a> model files. + * @param bufferCfg A buffer contains a content of .cfg file with text description of the network architecture. + * @param lenCfg Number of bytes to read from bufferCfg + * @param bufferModel A buffer contains a content of .weights file with learned network. + * @param lenModel Number of bytes to read from bufferModel + * @returns Net object. + */ + CV_EXPORTS Net readNetFromDarknet(const char *bufferCfg, size_t lenCfg, + const char *bufferModel = NULL, size_t lenModel = 0); + + /** @brief Reads a network model stored in <a href="http://caffe.berkeleyvision.org">Caffe</a> framework's format. + * @param prototxt path to the .prototxt file with text description of the network architecture. + * @param caffeModel path to the .caffemodel file with learned network. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromCaffe(const String &prototxt, const String &caffeModel = String()); + + /** @brief Reads a network model stored in Caffe model in memory. + * @param bufferProto buffer containing the content of the .prototxt file + * @param bufferModel buffer containing the content of the .caffemodel file + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromCaffe(const std::vector<uchar>& bufferProto, + const std::vector<uchar>& bufferModel = std::vector<uchar>()); + + /** @brief Reads a network model stored in Caffe model in memory. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param bufferProto buffer containing the content of the .prototxt file + * @param lenProto length of bufferProto + * @param bufferModel buffer containing the content of the .caffemodel file + * @param lenModel length of bufferModel + * @returns Net object. + */ + CV_EXPORTS Net readNetFromCaffe(const char *bufferProto, size_t lenProto, + const char *bufferModel = NULL, size_t lenModel = 0); + + /** @brief Reads a network model stored in <a href="https://www.tensorflow.org/">TensorFlow</a> framework's format. + * @param model path to the .pb file with binary protobuf description of the network architecture + * @param config path to the .pbtxt file that contains text graph definition in protobuf format. + * Resulting Net object is built by text graph using weights from a binary one that + * let us make it more flexible. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromTensorflow(const String &model, const String &config = String()); + + /** @brief Reads a network model stored in <a href="https://www.tensorflow.org/">TensorFlow</a> framework's format. + * @param bufferModel buffer containing the content of the pb file + * @param bufferConfig buffer containing the content of the pbtxt file + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromTensorflow(const std::vector<uchar>& bufferModel, + const std::vector<uchar>& bufferConfig = std::vector<uchar>()); + + /** @brief Reads a network model stored in <a href="https://www.tensorflow.org/">TensorFlow</a> framework's format. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param bufferModel buffer containing the content of the pb file + * @param lenModel length of bufferModel + * @param bufferConfig buffer containing the content of the pbtxt file + * @param lenConfig length of bufferConfig + */ + CV_EXPORTS Net readNetFromTensorflow(const char *bufferModel, size_t lenModel, + const char *bufferConfig = NULL, size_t lenConfig = 0); + + /** + * @brief Reads a network model stored in <a href="http://torch.ch">Torch7</a> framework's format. + * @param model path to the file, dumped from Torch by using torch.save() function. + * @param isBinary specifies whether the network was serialized in ascii mode or binary. + * @param evaluate specifies testing phase of network. If true, it's similar to evaluate() method in Torch. + * @returns Net object. + * + * @note Ascii mode of Torch serializer is more preferable, because binary mode extensively use `long` type of C language, + * which has various bit-length on different systems. + * + * The loading file must contain serialized <a href="https://github.com/torch/nn/blob/master/doc/module.md">nn.Module</a> object + * with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors. + * + * List of supported layers (i.e. object instances derived from Torch nn.Module class): + * - nn.Sequential + * - nn.Parallel + * - nn.Concat + * - nn.Linear + * - nn.SpatialConvolution + * - nn.SpatialMaxPooling, nn.SpatialAveragePooling + * - nn.ReLU, nn.TanH, nn.Sigmoid + * - nn.Reshape + * - nn.SoftMax, nn.LogSoftMax + * + * Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported. + */ + CV_EXPORTS_W Net readNetFromTorch(const String &model, bool isBinary = true, bool evaluate = true); + + /** + * @brief Read deep learning network represented in one of the supported formats. + * @param[in] model Binary file contains trained weights. The following file + * extensions are expected for models from different frameworks: + * * `*.caffemodel` (Caffe, http://caffe.berkeleyvision.org/) + * * `*.pb` (TensorFlow, https://www.tensorflow.org/) + * * `*.t7` | `*.net` (Torch, http://torch.ch/) + * * `*.weights` (Darknet, https://pjreddie.com/darknet/) + * * `*.bin` (DLDT, https://software.intel.com/openvino-toolkit) + * @param[in] config Text file contains network configuration. It could be a + * file with the following extensions: + * * `*.prototxt` (Caffe, http://caffe.berkeleyvision.org/) + * * `*.pbtxt` (TensorFlow, https://www.tensorflow.org/) + * * `*.cfg` (Darknet, https://pjreddie.com/darknet/) + * * `*.xml` (DLDT, https://software.intel.com/openvino-toolkit) + * @param[in] framework Explicit framework name tag to determine a format. + * @returns Net object. + * + * This function automatically detects an origin framework of trained model + * and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow, + * @ref readNetFromTorch or @ref readNetFromDarknet. An order of @p model and @p config + * arguments does not matter. + */ + CV_EXPORTS_W Net readNet(const String& model, const String& config = "", const String& framework = ""); + + /** + * @brief Read deep learning network represented in one of the supported formats. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param[in] framework Name of origin framework. + * @param[in] bufferModel A buffer with a content of binary file with weights + * @param[in] bufferConfig A buffer with a content of text file contains network configuration. + * @returns Net object. + */ + CV_EXPORTS_W Net readNet(const String& framework, const std::vector<uchar>& bufferModel, + const std::vector<uchar>& bufferConfig = std::vector<uchar>()); + + /** @brief Loads blob which was serialized as torch.Tensor object of Torch7 framework. + * @warning This function has the same limitations as readNetFromTorch(). + */ + CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true); + + /** @brief Load a network from Intel's Model Optimizer intermediate representation. + * @param[in] xml XML configuration file with network's topology. + * @param[in] bin Binary file with trained weights. + * @returns Net object. + * Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine + * backend. + */ + CV_EXPORTS_W Net readNetFromModelOptimizer(const String &xml, const String &bin); + + /** @brief Reads a network model <a href="https://onnx.ai/">ONNX</a>. + * @param onnxFile path to the .onnx file with text description of the network architecture. + * @returns Network object that ready to do forward, throw an exception in failure cases. + */ + CV_EXPORTS_W Net readNetFromONNX(const String &onnxFile); + + /** @brief Creates blob from .pb file. + * @param path to the .pb file with input tensor. + * @returns Mat. + */ + CV_EXPORTS_W Mat readTensorFromONNX(const String& path); + + /** @brief Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, + * subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels. + * @param image input image (with 1-, 3- or 4-channels). + * @param size spatial size for output image + * @param mean scalar with mean values which are subtracted from channels. Values are intended + * to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. + * @param scalefactor multiplier for @p image values. + * @param swapRB flag which indicates that swap first and last channels + * in 3-channel image is necessary. + * @param crop flag which indicates whether image will be cropped after resize or not + * @param ddepth Depth of output blob. Choose CV_32F or CV_8U. + * @details if @p crop is true, input image is resized so one side after resize is equal to corresponding + * dimension in @p size and another one is equal or larger. Then, crop from the center is performed. + * If @p crop is false, direct resize without cropping and preserving aspect ratio is performed. + * @returns 4-dimensional Mat with NCHW dimensions order. + */ + CV_EXPORTS_W Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size& size = Size(), + const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false, + int ddepth=CV_32F); + + /** @brief Creates 4-dimensional blob from image. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + */ + CV_EXPORTS void blobFromImage(InputArray image, OutputArray blob, double scalefactor=1.0, + const Size& size = Size(), const Scalar& mean = Scalar(), + bool swapRB=false, bool crop=false, int ddepth=CV_32F); + + + /** @brief Creates 4-dimensional blob from series of images. Optionally resizes and + * crops @p images from center, subtract @p mean values, scales values by @p scalefactor, + * swap Blue and Red channels. + * @param images input images (all with 1-, 3- or 4-channels). + * @param size spatial size for output image + * @param mean scalar with mean values which are subtracted from channels. Values are intended + * to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. + * @param scalefactor multiplier for @p images values. + * @param swapRB flag which indicates that swap first and last channels + * in 3-channel image is necessary. + * @param crop flag which indicates whether image will be cropped after resize or not + * @param ddepth Depth of output blob. Choose CV_32F or CV_8U. + * @details if @p crop is true, input image is resized so one side after resize is equal to corresponding + * dimension in @p size and another one is equal or larger. Then, crop from the center is performed. + * If @p crop is false, direct resize without cropping and preserving aspect ratio is performed. + * @returns 4-dimensional Mat with NCHW dimensions order. + */ + CV_EXPORTS_W Mat blobFromImages(InputArrayOfArrays images, double scalefactor=1.0, + Size size = Size(), const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false, + int ddepth=CV_32F); + + /** @brief Creates 4-dimensional blob from series of images. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + */ + CV_EXPORTS void blobFromImages(InputArrayOfArrays images, OutputArray blob, + double scalefactor=1.0, Size size = Size(), + const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false, + int ddepth=CV_32F); + + /** @brief Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure + * (std::vector<cv::Mat>). + * @param[in] blob_ 4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from + * which you would like to extract the images. + * @param[out] images_ array of 2D Mat containing the images extracted from the blob in floating point precision + * (CV_32F). They are non normalized neither mean added. The number of returned images equals the first dimension + * of the blob (batch size). Every image has a number of channels equals to the second dimension of the blob (depth). + */ + CV_EXPORTS_W void imagesFromBlob(const cv::Mat& blob_, OutputArrayOfArrays images_); + + /** @brief Convert all weights of Caffe network to half precision floating point. + * @param src Path to origin model from Caffe framework contains single + * precision floating point weights (usually has `.caffemodel` extension). + * @param dst Path to destination model with updated weights. + * @param layersTypes Set of layers types which parameters will be converted. + * By default, converts only Convolutional and Fully-Connected layers' + * weights. + * + * @note Shrinked model has no origin float32 weights so it can't be used + * in origin Caffe framework anymore. However the structure of data + * is taken from NVidia's Caffe fork: https://github.com/NVIDIA/caffe. + * So the resulting model may be used there. + */ + CV_EXPORTS_W void shrinkCaffeModel(const String& src, const String& dst, + const std::vector<String>& layersTypes = std::vector<String>()); + + /** @brief Create a text representation for a binary network stored in protocol buffer format. + * @param[in] model A path to binary network. + * @param[in] output A path to output text file to be created. + * + * @note To reduce output file size, trained weights are not included. + */ + CV_EXPORTS_W void writeTextGraph(const String& model, const String& output); + + /** @brief Performs non maximum suppression given boxes and corresponding scores. + + * @param bboxes a set of bounding boxes to apply NMS. + * @param scores a set of corresponding confidences. + * @param score_threshold a threshold used to filter boxes by score. + * @param nms_threshold a threshold used in non maximum suppression. + * @param indices the kept indices of bboxes after NMS. + * @param eta a coefficient in adaptive threshold formula: \f$nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\f$. + * @param top_k if `>0`, keep at most @p top_k picked indices. + */ + CV_EXPORTS_W void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector<int>& indices, + const float eta = 1.f, const int top_k = 0); + + CV_EXPORTS_W void NMSBoxes(const std::vector<Rect2d>& bboxes, const std::vector<float>& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector<int>& indices, + const float eta = 1.f, const int top_k = 0); + + CV_EXPORTS_AS(NMSBoxesRotated) void NMSBoxes(const std::vector<RotatedRect>& bboxes, const std::vector<float>& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector<int>& indices, + const float eta = 1.f, const int top_k = 0); + +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} + +#include <opencv2/dnn/layer.hpp> +#include <opencv2/dnn/dnn.inl.hpp> + +/// @deprecated Include this header directly from application. Automatic inclusion will be removed +#include <opencv2/dnn/utils/inference_engine.hpp> + +#endif /* OPENCV_DNN_DNN_HPP */ diff --git a/include/opencv2/dnn/dnn.inl.hpp b/include/opencv2/dnn/dnn.inl.hpp new file mode 100644 index 0000000..17d4c20 --- /dev/null +++ b/include/opencv2/dnn/dnn.inl.hpp @@ -0,0 +1,395 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_INL_HPP +#define OPENCV_DNN_DNN_INL_HPP + +#include <opencv2/dnn.hpp> + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + +template<typename TypeIter> +DictValue DictValue::arrayInt(TypeIter begin, int size) +{ + DictValue res(Param::INT, new AutoBuffer<int64, 1>(size)); + for (int j = 0; j < size; begin++, j++) + (*res.pi)[j] = *begin; + return res; +} + +template<typename TypeIter> +DictValue DictValue::arrayReal(TypeIter begin, int size) +{ + DictValue res(Param::REAL, new AutoBuffer<double, 1>(size)); + for (int j = 0; j < size; begin++, j++) + (*res.pd)[j] = *begin; + return res; +} + +template<typename TypeIter> +DictValue DictValue::arrayString(TypeIter begin, int size) +{ + DictValue res(Param::STRING, new AutoBuffer<String, 1>(size)); + for (int j = 0; j < size; begin++, j++) + (*res.ps)[j] = *begin; + return res; +} + +template<> +inline DictValue DictValue::get<DictValue>(int idx) const +{ + CV_Assert(idx == -1); + return *this; +} + +template<> +inline int64 DictValue::get<int64>(int idx) const +{ + CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size())); + idx = (idx == -1) ? 0 : idx; + + if (type == Param::INT) + { + return (*pi)[idx]; + } + else if (type == Param::REAL) + { + double doubleValue = (*pd)[idx]; + + double fracpart, intpart; + fracpart = std::modf(doubleValue, &intpart); + CV_Assert(fracpart == 0.0); + + return (int64)doubleValue; + } + else if (type == Param::STRING) + { + return std::atoi((*ps)[idx].c_str()); + } + else + { + CV_Assert(isInt() || isReal() || isString()); + return 0; + } +} + +template<> +inline int DictValue::get<int>(int idx) const +{ + return (int)get<int64>(idx); +} + +inline int DictValue::getIntValue(int idx) const +{ + return (int)get<int64>(idx); +} + +template<> +inline unsigned DictValue::get<unsigned>(int idx) const +{ + return (unsigned)get<int64>(idx); +} + +template<> +inline bool DictValue::get<bool>(int idx) const +{ + return (get<int64>(idx) != 0); +} + +template<> +inline double DictValue::get<double>(int idx) const +{ + CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size())); + idx = (idx == -1) ? 0 : idx; + + if (type == Param::REAL) + { + return (*pd)[idx]; + } + else if (type == Param::INT) + { + return (double)(*pi)[idx]; + } + else if (type == Param::STRING) + { + return std::atof((*ps)[idx].c_str()); + } + else + { + CV_Assert(isReal() || isInt() || isString()); + return 0; + } +} + +inline double DictValue::getRealValue(int idx) const +{ + return get<double>(idx); +} + +template<> +inline float DictValue::get<float>(int idx) const +{ + return (float)get<double>(idx); +} + +template<> +inline String DictValue::get<String>(int idx) const +{ + CV_Assert(isString()); + CV_Assert((idx == -1 && ps->size() == 1) || (idx >= 0 && idx < (int)ps->size())); + return (*ps)[(idx == -1) ? 0 : idx]; +} + + +inline String DictValue::getStringValue(int idx) const +{ + return get<String>(idx); +} + +inline void DictValue::release() +{ + switch (type) + { + case Param::INT: + delete pi; + break; + case Param::STRING: + delete ps; + break; + case Param::REAL: + delete pd; + break; + } +} + +inline DictValue::~DictValue() +{ + release(); +} + +inline DictValue & DictValue::operator=(const DictValue &r) +{ + if (&r == this) + return *this; + + if (r.type == Param::INT) + { + AutoBuffer<int64, 1> *tmp = new AutoBuffer<int64, 1>(*r.pi); + release(); + pi = tmp; + } + else if (r.type == Param::STRING) + { + AutoBuffer<String, 1> *tmp = new AutoBuffer<String, 1>(*r.ps); + release(); + ps = tmp; + } + else if (r.type == Param::REAL) + { + AutoBuffer<double, 1> *tmp = new AutoBuffer<double, 1>(*r.pd); + release(); + pd = tmp; + } + + type = r.type; + + return *this; +} + +inline DictValue::DictValue(const DictValue &r) +{ + type = r.type; + + if (r.type == Param::INT) + pi = new AutoBuffer<int64, 1>(*r.pi); + else if (r.type == Param::STRING) + ps = new AutoBuffer<String, 1>(*r.ps); + else if (r.type == Param::REAL) + pd = new AutoBuffer<double, 1>(*r.pd); +} + +inline bool DictValue::isString() const +{ + return (type == Param::STRING); +} + +inline bool DictValue::isInt() const +{ + return (type == Param::INT); +} + +inline bool DictValue::isReal() const +{ + return (type == Param::REAL || type == Param::INT); +} + +inline int DictValue::size() const +{ + switch (type) + { + case Param::INT: + return (int)pi->size(); + case Param::STRING: + return (int)ps->size(); + case Param::REAL: + return (int)pd->size(); + } +#ifdef __OPENCV_BUILD + CV_Error(Error::StsInternal, ""); +#else + CV_ErrorNoReturn(Error::StsInternal, ""); +#endif +} + +inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv) +{ + int i; + + if (dictv.isInt()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << dictv.get<int64>(i) << ", "; + stream << dictv.get<int64>(i); + } + else if (dictv.isReal()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << dictv.get<double>(i) << ", "; + stream << dictv.get<double>(i); + } + else if (dictv.isString()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << "\"" << dictv.get<String>(i) << "\", "; + stream << dictv.get<String>(i); + } + + return stream; +} + +///////////////////////////////////////////////////////////////// + +inline bool Dict::has(const String &key) const +{ + return dict.count(key) != 0; +} + +inline DictValue *Dict::ptr(const String &key) +{ + _Dict::iterator i = dict.find(key); + return (i == dict.end()) ? NULL : &i->second; +} + +inline const DictValue *Dict::ptr(const String &key) const +{ + _Dict::const_iterator i = dict.find(key); + return (i == dict.end()) ? NULL : &i->second; +} + +inline const DictValue &Dict::get(const String &key) const +{ + _Dict::const_iterator i = dict.find(key); + if (i == dict.end()) + CV_Error(Error::StsObjectNotFound, "Required argument \"" + key + "\" not found into dictionary"); + return i->second; +} + +template <typename T> +inline T Dict::get(const String &key) const +{ + return this->get(key).get<T>(); +} + +template <typename T> +inline T Dict::get(const String &key, const T &defaultValue) const +{ + _Dict::const_iterator i = dict.find(key); + + if (i != dict.end()) + return i->second.get<T>(); + else + return defaultValue; +} + +template<typename T> +inline const T &Dict::set(const String &key, const T &value) +{ + _Dict::iterator i = dict.find(key); + + if (i != dict.end()) + i->second = DictValue(value); + else + dict.insert(std::make_pair(key, DictValue(value))); + + return value; +} + +inline void Dict::erase(const String &key) +{ + dict.erase(key); +} + +inline std::ostream &operator<<(std::ostream &stream, const Dict &dict) +{ + Dict::_Dict::const_iterator it; + for (it = dict.dict.begin(); it != dict.dict.end(); it++) + stream << it->first << " : " << it->second << "\n"; + + return stream; +} + +inline std::map<String, DictValue>::const_iterator Dict::begin() const +{ + return dict.begin(); +} + +inline std::map<String, DictValue>::const_iterator Dict::end() const +{ + return dict.end(); +} + +CV__DNN_EXPERIMENTAL_NS_END +} +} + +#endif diff --git a/include/opencv2/dnn/layer.details.hpp b/include/opencv2/dnn/layer.details.hpp new file mode 100644 index 0000000..619514e --- /dev/null +++ b/include/opencv2/dnn/layer.details.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +#ifndef OPENCV_DNN_LAYER_DETAILS_HPP +#define OPENCV_DNN_LAYER_DETAILS_HPP + +#include <opencv2/dnn/layer.hpp> + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + +/** @brief Registers layer constructor in runtime. +* @param type string, containing type name of the layer. +* @param constructorFunc pointer to the function of type LayerRegister::Constructor, which creates the layer. +* @details This macros must be placed inside the function code. +*/ +#define CV_DNN_REGISTER_LAYER_FUNC(type, constructorFunc) \ + cv::dnn::LayerFactory::registerLayer(#type, constructorFunc); + +/** @brief Registers layer class in runtime. + * @param type string, containing type name of the layer. + * @param class C++ class, derived from Layer. + * @details This macros must be placed inside the function code. + */ +#define CV_DNN_REGISTER_LAYER_CLASS(type, class) \ + cv::dnn::LayerFactory::registerLayer(#type, cv::dnn::details::_layerDynamicRegisterer<class>); + +/** @brief Registers layer constructor on module load time. +* @param type string, containing type name of the layer. +* @param constructorFunc pointer to the function of type LayerRegister::Constructor, which creates the layer. +* @details This macros must be placed outside the function code. +*/ +#define CV_DNN_REGISTER_LAYER_FUNC_STATIC(type, constructorFunc) \ +static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, constructorFunc); + +/** @brief Registers layer class on module load time. + * @param type string, containing type name of the layer. + * @param class C++ class, derived from Layer. + * @details This macros must be placed outside the function code. + */ +#define CV_DNN_REGISTER_LAYER_CLASS_STATIC(type, class) \ +Ptr<Layer> __LayerStaticRegisterer_func_##type(LayerParams ¶ms) \ + { return Ptr<Layer>(new class(params)); } \ +static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, __LayerStaticRegisterer_func_##type); + +namespace details { + +template<typename LayerClass> +Ptr<Layer> _layerDynamicRegisterer(LayerParams ¶ms) +{ + return Ptr<Layer>(LayerClass::create(params)); +} + +//allows automatically register created layer on module load time +class _LayerStaticRegisterer +{ + String type; +public: + + _LayerStaticRegisterer(const String &layerType, LayerFactory::Constructor layerConstructor) + { + this->type = layerType; + LayerFactory::registerLayer(layerType, layerConstructor); + } + + ~_LayerStaticRegisterer() + { + LayerFactory::unregisterLayer(type); + } +}; + +} // namespace +CV__DNN_EXPERIMENTAL_NS_END +}} // namespace + +#endif diff --git a/include/opencv2/dnn/layer.hpp b/include/opencv2/dnn/layer.hpp new file mode 100644 index 0000000..c4712b8 --- /dev/null +++ b/include/opencv2/dnn/layer.hpp @@ -0,0 +1,85 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_DNN_LAYER_HPP +#define OPENCV_DNN_LAYER_HPP +#include <opencv2/dnn.hpp> + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ +//! +//! @defgroup dnnLayerFactory Utilities for New Layers Registration +//! @{ + +/** @brief %Layer factory allows to create instances of registered layers. */ +class CV_EXPORTS LayerFactory +{ +public: + + //! Each Layer class must provide this function to the factory + typedef Ptr<Layer>(*Constructor)(LayerParams ¶ms); + + //! Registers the layer class with typename @p type and specified @p constructor. Thread-safe. + static void registerLayer(const String &type, Constructor constructor); + + //! Unregisters registered layer with specified type name. Thread-safe. + static void unregisterLayer(const String &type); + + /** @brief Creates instance of registered layer. + * @param type type name of creating layer. + * @param params parameters which will be used for layer initialization. + * @note Thread-safe. + */ + static Ptr<Layer> createLayerInstance(const String &type, LayerParams& params); + +private: + LayerFactory(); +}; + +//! @} +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} +#endif diff --git a/include/opencv2/dnn/shape_utils.hpp b/include/opencv2/dnn/shape_utils.hpp new file mode 100644 index 0000000..b0ed3af --- /dev/null +++ b/include/opencv2/dnn/shape_utils.hpp @@ -0,0 +1,219 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_SHAPE_UTILS_HPP +#define OPENCV_DNN_DNN_SHAPE_UTILS_HPP + +#include <opencv2/dnn/dnn.hpp> +#include <opencv2/core/types_c.h> // CV_MAX_DIM +#include <iostream> +#include <ostream> +#include <sstream> + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + +//Slicing + +struct _Range : public cv::Range +{ + _Range(const Range &r) : cv::Range(r) {} + _Range(int start_, int size_ = 1) : cv::Range(start_, start_ + size_) {} +}; + +static inline Mat slice(const Mat &m, const _Range &r0) +{ + Range ranges[CV_MAX_DIM]; + for (int i = 1; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1) +{ + CV_Assert(m.dims >= 2); + Range ranges[CV_MAX_DIM]; + for (int i = 2; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2) +{ + CV_Assert(m.dims >= 3); + Range ranges[CV_MAX_DIM]; + for (int i = 3; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + ranges[2] = r2; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2, const _Range &r3) +{ + CV_Assert(m.dims >= 4); + Range ranges[CV_MAX_DIM]; + for (int i = 4; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + ranges[2] = r2; + ranges[3] = r3; + return m(&ranges[0]); +} + +static inline Mat getPlane(const Mat &m, int n, int cn) +{ + CV_Assert(m.dims > 2); + int sz[CV_MAX_DIM]; + for(int i = 2; i < m.dims; i++) + { + sz[i-2] = m.size.p[i]; + } + return Mat(m.dims - 2, sz, m.type(), (void*)m.ptr<float>(n, cn)); +} + +static inline MatShape shape(const int* dims, const int n) +{ + MatShape shape; + shape.assign(dims, dims + n); + return shape; +} + +static inline MatShape shape(const Mat& mat) +{ + return shape(mat.size.p, mat.dims); +} + +static inline MatShape shape(const MatSize& sz) +{ + return shape(sz.p, sz.dims()); +} + +static inline MatShape shape(const UMat& mat) +{ + return shape(mat.size.p, mat.dims); +} + +namespace {inline bool is_neg(int i) { return i < 0; }} + +static inline MatShape shape(int a0, int a1=-1, int a2=-1, int a3=-1) +{ + int dims[] = {a0, a1, a2, a3}; + MatShape s = shape(dims, 4); + s.erase(std::remove_if(s.begin(), s.end(), is_neg), s.end()); + return s; +} + +static inline int total(const MatShape& shape, int start = -1, int end = -1) +{ + if (start == -1) start = 0; + if (end == -1) end = (int)shape.size(); + + if (shape.empty()) + return 0; + + int elems = 1; + CV_Assert(start <= (int)shape.size() && end <= (int)shape.size() && + start <= end); + for(int i = start; i < end; i++) + { + elems *= shape[i]; + } + return elems; +} + +static inline MatShape concat(const MatShape& a, const MatShape& b) +{ + MatShape c = a; + c.insert(c.end(), b.begin(), b.end()); + + return c; +} + +static inline std::string toString(const MatShape& shape, const String& name = "") +{ + std::ostringstream ss; + if (!name.empty()) + ss << name << ' '; + ss << '['; + for(size_t i = 0, n = shape.size(); i < n; ++i) + ss << ' ' << shape[i]; + ss << " ]"; + return ss.str(); +} +static inline void print(const MatShape& shape, const String& name = "") +{ + std::cout << toString(shape, name) << std::endl; +} +static inline std::ostream& operator<<(std::ostream &out, const MatShape& shape) +{ + out << toString(shape); + return out; +} + +inline int clamp(int ax, int dims) +{ + return ax < 0 ? ax + dims : ax; +} + +inline int clamp(int ax, const MatShape& shape) +{ + return clamp(ax, (int)shape.size()); +} + +inline Range clamp(const Range& r, int axisSize) +{ + Range clamped(std::max(r.start, 0), + r.end > 0 ? std::min(r.end, axisSize) : axisSize + r.end + 1); + CV_Assert_N(clamped.start < clamped.end, clamped.end <= axisSize); + return clamped; +} + +CV__DNN_EXPERIMENTAL_NS_END +} +} +#endif diff --git a/include/opencv2/dnn/utils/inference_engine.hpp b/include/opencv2/dnn/utils/inference_engine.hpp new file mode 100644 index 0000000..0211096 --- /dev/null +++ b/include/opencv2/dnn/utils/inference_engine.hpp @@ -0,0 +1,43 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. + +#ifndef OPENCV_DNN_UTILS_INF_ENGINE_HPP +#define OPENCV_DNN_UTILS_INF_ENGINE_HPP + +#include "../dnn.hpp" + +namespace cv { namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + + +/** @brief Release a Myriad device (binded by OpenCV). + * + * Single Myriad device cannot be shared across multiple processes which uses + * Inference Engine's Myriad plugin. + */ +CV_EXPORTS_W void resetMyriadDevice(); + + +/* Values for 'OPENCV_DNN_IE_VPU_TYPE' parameter */ +#define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_UNSPECIFIED "" +/// Intel(R) Movidius(TM) Neural Compute Stick, NCS (USB 03e7:2150), Myriad2 (https://software.intel.com/en-us/movidius-ncs) +#define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2 "Myriad2" +/// Intel(R) Neural Compute Stick 2, NCS2 (USB 03e7:2485), MyriadX (https://software.intel.com/ru-ru/neural-compute-stick) +#define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X "MyriadX" + + +/** @brief Returns Inference Engine VPU type. + * + * See values of `CV_DNN_INFERENCE_ENGINE_VPU_TYPE_*` macros. + */ +CV_EXPORTS_W cv::String getInferenceEngineVPUType(); + + +CV__DNN_EXPERIMENTAL_NS_END +}} // namespace + +#endif // OPENCV_DNN_UTILS_INF_ENGINE_HPP diff --git a/include/opencv2/dpm.hpp b/include/opencv2/dpm.hpp new file mode 100644 index 0000000..ab604ab --- /dev/null +++ b/include/opencv2/dpm.hpp @@ -0,0 +1,153 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Itseez Inc 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. +// +// Implementation authors: +// Jiaolong Xu - jiaolongxu@gmail.com +// Evgeniy Kozinov - evgeniy.kozinov@gmail.com +// Valentina Kustikova - valentina.kustikova@gmail.com +// Nikolai Zolotykh - Nikolai.Zolotykh@gmail.com +// Iosif Meyerov - meerov@vmk.unn.ru +// Alexey Polovinkin - polovinkin.alexey@gmail.com +// +//M*/ + +#ifndef __OPENCV_LATENTSVM_HPP__ +#define __OPENCV_LATENTSVM_HPP__ + +#include "opencv2/core.hpp" + +#include <map> +#include <vector> +#include <string> + +/** @defgroup dpm Deformable Part-based Models + +Discriminatively Trained Part Based Models for Object Detection +--------------------------------------------------------------- + +The object detector described below has been initially proposed by P.F. Felzenszwalb in +@cite Felzenszwalb2010a . It is based on a Dalal-Triggs detector that uses a single filter on histogram +of oriented gradients (HOG) features to represent an object category. This detector uses a sliding +window approach, where a filter is applied at all positions and scales of an image. The first +innovation is enriching the Dalal-Triggs model using a star-structured part-based model defined by a +"root" filter (analogous to the Dalal-Triggs filter) plus a set of parts filters and associated +deformation models. The score of one of star models at a particular position and scale within an +image is the score of the root filter at the given location plus the sum over parts of the maximum, +over placements of that part, of the part filter score on its location minus a deformation cost +easuring the deviation of the part from its ideal location relative to the root. Both root and part +filter scores are defined by the dot product between a filter (a set of weights) and a subwindow of +a feature pyramid computed from the input image. Another improvement is a representation of the +class of models by a mixture of star models. The score of a mixture model at a particular position +and scale is the maximum over components, of the score of that component model at the given +location. + +The detector was dramatically speeded-up with cascade algorithm proposed by P.F. Felzenszwalb in +@cite Felzenszwalb2010b . The algorithm prunes partial hypotheses using thresholds on their scores.The +basic idea of the algorithm is to use a hierarchy of models defined by an ordering of the original +model's parts. For a model with (n+1) parts, including the root, a sequence of (n+1) models is +obtained. The i-th model in this sequence is defined by the first i parts from the original model. +Using this hierarchy, low scoring hypotheses can be pruned after looking at the best configuration +of a subset of the parts. Hypotheses that score high under a weak model are evaluated further using +a richer model. + +In OpenCV there is an C++ implementation of DPM cascade detector. + +*/ + +namespace cv +{ + +namespace dpm +{ + +//! @addtogroup dpm +//! @{ + +/** @brief This is a C++ abstract class, it provides external user API to work with DPM. + */ +class CV_EXPORTS_W DPMDetector +{ +public: + + struct CV_EXPORTS_W ObjectDetection + { + ObjectDetection(); + ObjectDetection( const Rect& rect, float score, int classID=-1 ); + Rect rect; + float score; + int classID; + }; + + virtual bool isEmpty() const = 0; + + /** @brief Find rectangular regions in the given image that are likely to contain objects of loaded classes + (models) and corresponding confidence levels. + @param image An image. + @param objects The detections: rectangulars, scores and class IDs. + */ + virtual void detect(cv::Mat &image, CV_OUT std::vector<ObjectDetection> &objects) = 0; + + /** @brief Return the class (model) names that were passed in constructor or method load or extracted from + models filenames in those methods. + */ + virtual std::vector<std::string> const& getClassNames() const = 0; + + /** @brief Return a count of loaded models (classes). + */ + virtual size_t getClassCount() const = 0; + + /** @brief Load the trained models from given .xml files and return cv::Ptr\<DPMDetector\>. + @param filenames A set of filenames storing the trained detectors (models). Each file contains one + model. See examples of such files here `/opencv_extra/testdata/cv/dpm/VOC2007_Cascade/`. + @param classNames A set of trained models names. If it's empty then the name of each model will be + constructed from the name of file containing the model. E.g. the model stored in + "/home/user/cat.xml" will get the name "cat". + */ + static cv::Ptr<DPMDetector> create(std::vector<std::string> const &filenames, + std::vector<std::string> const &classNames = std::vector<std::string>()); + + virtual ~DPMDetector(){} +}; + +//! @} + +} // namespace dpm +} // namespace cv + +#endif diff --git a/include/opencv2/face.hpp b/include/opencv2/face.hpp new file mode 100644 index 0000000..890f5b6 --- /dev/null +++ b/include/opencv2/face.hpp @@ -0,0 +1,384 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_FACE_HPP__ +#define __OPENCV_FACE_HPP__ + +/** +@defgroup face Face Analysis + +- @ref face_changelog +- @ref tutorial_face_main + +*/ + +#include "opencv2/core.hpp" +#include "face/predict_collector.hpp" +#include <map> + +namespace cv { namespace face { + +//! @addtogroup face +//! @{ + +/** @brief Abstract base class for all face recognition models + +All face recognition models in OpenCV are derived from the abstract base class FaceRecognizer, which +provides a unified access to all face recongition algorithms in OpenCV. + +### Description + +I'll go a bit more into detail explaining FaceRecognizer, because it doesn't look like a powerful +interface at first sight. But: Every FaceRecognizer is an Algorithm, so you can easily get/set all +model internals (if allowed by the implementation). Algorithm is a relatively new OpenCV concept, +which is available since the 2.4 release. I suggest you take a look at its description. + +Algorithm provides the following features for all derived classes: + +- So called "virtual constructor". That is, each Algorithm derivative is registered at program + start and you can get the list of registered algorithms and create instance of a particular + algorithm by its name (see Algorithm::create). If you plan to add your own algorithms, it is + good practice to add a unique prefix to your algorithms to distinguish them from other + algorithms. +- Setting/Retrieving algorithm parameters by name. If you used video capturing functionality from + OpenCV highgui module, you are probably familar with cv::cvSetCaptureProperty, +ocvcvGetCaptureProperty, VideoCapture::set and VideoCapture::get. Algorithm provides similar + method where instead of integer id's you specify the parameter names as text Strings. See + Algorithm::set and Algorithm::get for details. +- Reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store + all its parameters and then read them back. There is no need to re-implement it each time. + +Moreover every FaceRecognizer supports the: + +- **Training** of a FaceRecognizer with FaceRecognizer::train on a given set of images (your face + database!). +- **Prediction** of a given sample image, that means a face. The image is given as a Mat. +- **Loading/Saving** the model state from/to a given XML or YAML. +- **Setting/Getting labels info**, that is stored as a string. String labels info is useful for + keeping names of the recognized people. + +@note When using the FaceRecognizer interface in combination with Python, please stick to Python 2. +Some underlying scripts like create_csv will not work in other versions, like Python 3. Setting the +Thresholds +++++++++++++++++++++++ + +Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common +scenario in face recognition is to tell, whether a face belongs to the training dataset or if it is +unknown. You might wonder, why there's no public API in FaceRecognizer to set the threshold for the +prediction, but rest assured: It's supported. It just means there's no generic way in an abstract +class to provide an interface for setting/getting the thresholds of *every possible* FaceRecognizer +algorithm. The appropriate place to set the thresholds is in the constructor of the specific +FaceRecognizer and since every FaceRecognizer is a Algorithm (see above), you can get/set the +thresholds at runtime! + +Here is an example of setting a threshold for the Eigenfaces method, when creating the model: + +@code +// Let's say we want to keep 10 Eigenfaces and have a threshold value of 10.0 +int num_components = 10; +double threshold = 10.0; +// Then if you want to have a cv::FaceRecognizer with a confidence threshold, +// create the concrete implementation with the appropiate parameters: +Ptr<FaceRecognizer> model = EigenFaceRecognizer::create(num_components, threshold); +@endcode + +Sometimes it's impossible to train the model, just to experiment with threshold values. Thanks to +Algorithm it's possible to set internal model thresholds during runtime. Let's see how we would +set/get the prediction for the Eigenface model, we've created above: + +@code +// The following line reads the threshold from the Eigenfaces model: +double current_threshold = model->getDouble("threshold"); +// And this line sets the threshold to 0.0: +model->set("threshold", 0.0); +@endcode + +If you've set the threshold to 0.0 as we did above, then: + +@code +// +Mat img = imread("person1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE); +// Get a prediction from the model. Note: We've set a threshold of 0.0 above, +// since the distance is almost always larger than 0.0, you'll get -1 as +// label, which indicates, this face is unknown +int predicted_label = model->predict(img); +// ... +@endcode + +is going to yield -1 as predicted label, which states this face is unknown. + +### Getting the name of a FaceRecognizer + +Since every FaceRecognizer is a Algorithm, you can use Algorithm::name to get the name of a +FaceRecognizer: + +@code +// Create a FaceRecognizer: +Ptr<FaceRecognizer> model = EigenFaceRecognizer::create(); +// And here's how to get its name: +String name = model->name(); +@endcode + + */ +class CV_EXPORTS_W FaceRecognizer : public Algorithm +{ +public: + /** @brief Trains a FaceRecognizer with given data and associated labels. + + @param src The training images, that means the faces you want to learn. The data has to be + given as a vector\<Mat\>. + @param labels The labels corresponding to the images have to be given either as a vector\<int\> + or a + + The following source code snippet shows you how to learn a Fisherfaces model on a given set of + images. The images are read with imread and pushed into a std::vector\<Mat\>. The labels of each + image are stored within a std::vector\<int\> (you could also use a Mat of type CV_32SC1). Think of + the label as the subject (the person) this image belongs to, so same subjects (persons) should have + the same label. For the available FaceRecognizer you don't have to pay any attention to the order of + the labels, just make sure same persons have the same label: + + @code + // holds images and labels + vector<Mat> images; + vector<int> labels; + // images for first person + images.push_back(imread("person0/0.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); + images.push_back(imread("person0/1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); + images.push_back(imread("person0/2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); + // images for second person + images.push_back(imread("person1/0.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); + images.push_back(imread("person1/1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); + images.push_back(imread("person1/2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); + @endcode + + Now that you have read some images, we can create a new FaceRecognizer. In this example I'll create + a Fisherfaces model and decide to keep all of the possible Fisherfaces: + + @code + // Create a new Fisherfaces model and retain all available Fisherfaces, + // this is the most common usage of this specific FaceRecognizer: + // + Ptr<FaceRecognizer> model = FisherFaceRecognizer::create(); + @endcode + + And finally train it on the given dataset (the face images and labels): + + @code + // This is the common interface to train all of the available cv::FaceRecognizer + // implementations: + // + model->train(images, labels); + @endcode + */ + CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; + + /** @brief Updates a FaceRecognizer with given data and associated labels. + + @param src The training images, that means the faces you want to learn. The data has to be given + as a vector\<Mat\>. + @param labels The labels corresponding to the images have to be given either as a vector\<int\> or + a + + This method updates a (probably trained) FaceRecognizer, but only if the algorithm supports it. The + Local Binary Patterns Histograms (LBPH) recognizer (see createLBPHFaceRecognizer) can be updated. + For the Eigenfaces and Fisherfaces method, this is algorithmically not possible and you have to + re-estimate the model with FaceRecognizer::train. In any case, a call to train empties the existing + model and learns a new model, while update does not delete any model data. + + @code + // Create a new LBPH model (it can be updated) and use the default parameters, + // this is the most common usage of this specific FaceRecognizer: + // + Ptr<FaceRecognizer> model = LBPHFaceRecognizer::create(); + // This is the common interface to train all of the available cv::FaceRecognizer + // implementations: + // + model->train(images, labels); + // Some containers to hold new image: + vector<Mat> newImages; + vector<int> newLabels; + // You should add some images to the containers: + // + // ... + // + // Now updating the model is as easy as calling: + model->update(newImages,newLabels); + // This will preserve the old model data and extend the existing model + // with the new features extracted from newImages! + @endcode + + Calling update on an Eigenfaces model (see EigenFaceRecognizer::create), which doesn't support + updating, will throw an error similar to: + + @code + OpenCV Error: The function/feature is not implemented (This FaceRecognizer (FaceRecognizer.Eigenfaces) does not support updating, you have to use FaceRecognizer::train to update it.) in update, file /home/philipp/git/opencv/modules/contrib/src/facerec.cpp, line 305 + terminate called after throwing an instance of 'cv::Exception' + @endcode + + @note The FaceRecognizer does not store your training images, because this would be very + memory intense and it's not the responsibility of te FaceRecognizer to do so. The caller is + responsible for maintaining the dataset, he want to work with. + */ + CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); + + /** @overload */ + CV_WRAP_AS(predict_label) int predict(InputArray src) const; + + + /** @brief Predicts a label and associated confidence (e.g. distance) for a given input image. + + @param src Sample image to get a prediction from. + @param label The predicted label for the given image. + @param confidence Associated confidence (e.g. distance) for the predicted label. + + The suffix const means that prediction does not affect the internal model state, so the method can + be safely called from within different threads. + + The following example shows how to get a prediction from a trained model: + + @code + using namespace cv; + // Do your initialization here (create the cv::FaceRecognizer model) ... + // ... + // Read in a sample image: + Mat img = imread("person1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE); + // And get a prediction from the cv::FaceRecognizer: + int predicted = model->predict(img); + @endcode + + Or to get a prediction and the associated confidence (e.g. distance): + + @code + using namespace cv; + // Do your initialization here (create the cv::FaceRecognizer model) ... + // ... + Mat img = imread("person1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE); + // Some variables for the predicted label and associated confidence (e.g. distance): + int predicted_label = -1; + double predicted_confidence = 0.0; + // Get the prediction and associated confidence from the model + model->predict(img, predicted_label, predicted_confidence); + @endcode + */ + CV_WRAP void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const; + + + /** @brief - if implemented - send all result of prediction to collector that can be used for somehow custom result handling + @param src Sample image to get a prediction from. + @param collector User-defined collector object that accepts all results + + To implement this method u just have to do same internal cycle as in predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) but + not try to get "best@ result, just resend it to caller side with given collector + */ + CV_WRAP_AS(predict_collect) virtual void predict(InputArray src, Ptr<PredictCollector> collector) const = 0; + + /** @brief Saves a FaceRecognizer and its model state. + + Saves this model to a given filename, either as XML or YAML. + @param filename The filename to store this FaceRecognizer to (either XML/YAML). + + Every FaceRecognizer overwrites FaceRecognizer::save(FileStorage& fs) to save the internal model + state. FaceRecognizer::save(const String& filename) saves the state of a model to the given + filename. + + The suffix const means that prediction does not affect the internal model state, so the method can + be safely called from within different threads. + */ + CV_WRAP virtual void write(const String& filename) const; + + /** @brief Loads a FaceRecognizer and its model state. + + Loads a persisted model and state from a given XML or YAML file . Every FaceRecognizer has to + overwrite FaceRecognizer::load(FileStorage& fs) to enable loading the model state. + FaceRecognizer::load(FileStorage& fs) in turn gets called by + FaceRecognizer::load(const String& filename), to ease saving a model. + */ + CV_WRAP virtual void read(const String& filename); + + /** @overload + Saves this model to a given FileStorage. + @param fs The FileStorage to store this FaceRecognizer to. + */ + virtual void write(FileStorage& fs) const CV_OVERRIDE = 0; + + /** @overload */ + virtual void read(const FileNode& fn) CV_OVERRIDE = 0; + + /** @overload */ + virtual bool empty() const CV_OVERRIDE = 0; + + /** @brief Sets string info for the specified model's label. + + The string info is replaced by the provided value if it was set before for the specified label. + */ + CV_WRAP virtual void setLabelInfo(int label, const String& strInfo); + + /** @brief Gets string information by label. + + If an unknown label id is provided or there is no label information associated with the specified + label id the method returns an empty string. + */ + CV_WRAP virtual String getLabelInfo(int label) const; + + /** @brief Gets vector of labels by string. + + The function searches for the labels containing the specified sub-string in the associated string + info. + */ + CV_WRAP virtual std::vector<int> getLabelsByString(const String& str) const; + /** @brief threshold parameter accessor - required for default BestMinDist collector */ + virtual double getThreshold() const = 0; + /** @brief Sets threshold of model */ + virtual void setThreshold(double val) = 0; +protected: + // Stored pairs "label id - string info" + std::map<int, String> _labelsInfo; +}; + +//! @} + +}} + +#include "opencv2/face/facerec.hpp" +#include "opencv2/face/facemark.hpp" +#include "opencv2/face/facemark_train.hpp" +#include "opencv2/face/facemarkLBF.hpp" +#include "opencv2/face/facemarkAAM.hpp" +#include "opencv2/face/face_alignment.hpp" +#include "opencv2/face/mace.hpp" + +#endif // __OPENCV_FACE_HPP__ diff --git a/include/opencv2/face/bif.hpp b/include/opencv2/face/bif.hpp new file mode 100644 index 0000000..d4f0ec5 --- /dev/null +++ b/include/opencv2/face/bif.hpp @@ -0,0 +1,83 @@ +/* +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) + +Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +Copyright (C) 2015, OpenCV Foundation, all rights reserved. +Copyright (C) 2015, Itseez Inc., all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_BIF_HPP__ +#define __OPENCV_BIF_HPP__ + +#include "opencv2/core.hpp" + +namespace cv { +namespace face { + +/** Implementation of bio-inspired features (BIF) from the paper: + * Guo, Guodong, et al. "Human age estimation using bio-inspired features." + * Computer Vision and Pattern Recognition, 2009. CVPR 2009. + */ +class CV_EXPORTS_W BIF : public Algorithm { +public: + /** @returns The number of filter bands used for computing BIF. */ + CV_WRAP virtual int getNumBands() const = 0; + + /** @returns The number of image rotations. */ + CV_WRAP virtual int getNumRotations() const = 0; + + /** Computes features sby input image. + * @param image Input image (CV_32FC1). + * @param features Feature vector (CV_32FC1). + */ + CV_WRAP virtual void compute(InputArray image, + OutputArray features) const = 0; + + /** + * @param num_bands The number of filter bands (<=8) used for computing BIF. + * @param num_rotations The number of image rotations for computing BIF. + * @returns Object for computing BIF. + */ + CV_WRAP static Ptr<BIF> create(int num_bands = 8, int num_rotations = 12); +}; + +} // namespace cv +} // namespace face + +#endif // #ifndef __OPENCV_FACEREC_HPP__ diff --git a/include/opencv2/face/face_alignment.hpp b/include/opencv2/face/face_alignment.hpp new file mode 100644 index 0000000..612bce1 --- /dev/null +++ b/include/opencv2/face/face_alignment.hpp @@ -0,0 +1,60 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#ifndef __OPENCV_FACE_ALIGNMENT_HPP__ +#define __OPENCV_FACE_ALIGNMENT_HPP__ + +#include "opencv2/face/facemark_train.hpp" + +namespace cv{ +namespace face{ +class CV_EXPORTS_W FacemarkKazemi : public Facemark +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + /// cascade_depth This stores the deapth of cascade used for training. + unsigned long cascade_depth; + /// tree_depth This stores the max height of the regression tree built. + unsigned long tree_depth; + /// num_trees_per_cascade_level This stores number of trees fit per cascade level. + unsigned long num_trees_per_cascade_level; + /// learning_rate stores the learning rate in gradient boosting, also reffered as shrinkage. + float learning_rate; + /// oversampling_amount stores number of initialisations used to create training samples. + unsigned long oversampling_amount; + /// num_test_coordinates stores number of test coordinates. + unsigned long num_test_coordinates; + /// lambda stores a value to calculate probability of closeness of two coordinates. + float lambda; + /// num_test_splits stores number of random test splits generated. + unsigned long num_test_splits; + /// configfile stores the name of the file containing the values of training parameters + String configfile; + }; + static Ptr<FacemarkKazemi> create(const FacemarkKazemi::Params ¶meters = FacemarkKazemi::Params()); + virtual ~FacemarkKazemi(); + + /** @brief This function is used to train the model using gradient boosting to get a cascade of regressors + *which can then be used to predict shape. + *@param images A vector of type cv::Mat which stores the images which are used in training samples. + *@param landmarks A vector of vectors of type cv::Point2f which stores the landmarks detected in a particular image. + *@param scale A size of type cv::Size to which all images and landmarks have to be scaled to. + *@param configfile A variable of type std::string which stores the name of the file storing parameters for training the model. + *@param modelFilename A variable of type std::string which stores the name of the trained model file that has to be saved. + *@returns A boolean value. The function returns true if the model is trained properly or false if it is not trained. + */ + virtual bool training(std::vector<Mat>& images, std::vector< std::vector<Point2f> >& landmarks,std::string configfile,Size scale,std::string modelFilename = "face_landmarks.dat")=0; + + /// set the custom face detector + virtual bool setFaceDetector(bool(*f)(InputArray , OutputArray, void*), void* userData)=0; + /// get faces using the custom detector + virtual bool getFaces(InputArray image, OutputArray faces)=0; +}; + +}} // namespace +#endif diff --git a/include/opencv2/face/facemark.hpp b/include/opencv2/face/facemark.hpp new file mode 100644 index 0000000..70849bc --- /dev/null +++ b/include/opencv2/face/facemark.hpp @@ -0,0 +1,95 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +/* +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACELANDMARK_HPP__ +#define __OPENCV_FACELANDMARK_HPP__ + +/** +@defgroup face Face Analysis +- @ref tutorial_table_of_content_facemark +- The Facemark API +*/ + +#include "opencv2/core.hpp" +#include <vector> + + +namespace cv { +namespace face { + + +/** @brief Abstract base class for all facemark models + +To utilize this API in your program, please take a look at the @ref tutorial_table_of_content_facemark +### Description + +Facemark is a base class which provides universal access to any specific facemark algorithm. +Therefore, the users should declare a desired algorithm before they can use it in their application. + +Here is an example on how to declare a facemark algorithm: +@code +// Using Facemark in your code: +Ptr<Facemark> facemark = createFacemarkLBF(); +@endcode + +The typical pipeline for facemark detection is as follows: +- Load the trained model using Facemark::loadModel. +- Perform the fitting on an image via Facemark::fit. +*/ +class CV_EXPORTS_W Facemark : public virtual Algorithm +{ +public: + + /** @brief A function to load the trained model before the fitting process. + @param model A string represent the filename of a trained model. + + <B>Example of usage</B> + @code + facemark->loadModel("../data/lbf.model"); + @endcode + */ + CV_WRAP virtual void loadModel( String model ) = 0; + // virtual void saveModel(String fs)=0; + + /** @brief Detect facial landmarks from an image. + @param image Input image. + @param faces Output of the function which represent region of interest of the detected faces. + Each face is stored in cv::Rect container. + @param landmarks The detected landmark points for each faces. + + <B>Example of usage</B> + @code + Mat image = imread("image.jpg"); + std::vector<Rect> faces; + std::vector<std::vector<Point2f> > landmarks; + facemark->fit(image, faces, landmarks); + @endcode + */ + CV_WRAP virtual bool fit( InputArray image, + InputArray faces, + OutputArrayOfArrays landmarks ) = 0; +}; /* Facemark*/ + + +//! construct an AAM facemark detector +CV_EXPORTS_W Ptr<Facemark> createFacemarkAAM(); + +//! construct an LBF facemark detector +CV_EXPORTS_W Ptr<Facemark> createFacemarkLBF(); + +//! construct a Kazemi facemark detector +CV_EXPORTS_W Ptr<Facemark> createFacemarkKazemi(); + + +} // face +} // cv + +#endif //__OPENCV_FACELANDMARK_HPP__ diff --git a/include/opencv2/face/facemarkAAM.hpp b/include/opencv2/face/facemarkAAM.hpp new file mode 100644 index 0000000..6f96e4a --- /dev/null +++ b/include/opencv2/face/facemarkAAM.hpp @@ -0,0 +1,162 @@ +/* +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) +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. +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. + +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACEMARK_AAM_HPP__ +#define __OPENCV_FACEMARK_AAM_HPP__ + +#include "opencv2/face/facemark_train.hpp" +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + +class CV_EXPORTS_W FacemarkAAM : public FacemarkTrain +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + + /** + * \brief Read parameters from file, currently unused + */ + void read(const FileNode& /*fn*/); + + /** + * \brief Read parameters from file, currently unused + */ + void write(FileStorage& /*fs*/) const; + + std::string model_filename; + int m; + int n; + int n_iter; + bool verbose; + bool save_model; + int max_m, max_n, texture_max_m; + std::vector<float>scales; + }; + + /** + * \brief Optional parameter for fitting process. + */ + struct CV_EXPORTS Config + { + Config( Mat rot = Mat::eye(2,2,CV_32F), + Point2f trans = Point2f(0.0f, 0.0f), + float scaling = 1.0f, + int scale_id=0 + ); + + Mat R; + Point2f t; + float scale; + int model_scale_idx; + + }; + + /** + * \brief Data container for the facemark::getData function + */ + struct CV_EXPORTS Data + { + std::vector<Point2f> s0; + }; + + /** + * \brief The model of AAM Algorithm + */ + struct CV_EXPORTS Model + { + std::vector<float>scales; + //!< defines the scales considered to build the model + + /*warping*/ + std::vector<Vec3i> triangles; + //!< each element contains 3 values, represent index of facemarks that construct one triangle (obtained using delaunay triangulation) + + struct Texture{ + int max_m; //!< unused delete + Rect resolution; + //!< resolution of the current scale + Mat A; + //!< gray values from all face region in the dataset, projected in PCA space + Mat A0; + //!< average of gray values from all face region in the dataset + Mat AA; + //!< gray values from all erorded face region in the dataset, projected in PCA space + Mat AA0; + //!< average of gray values from all erorded face region in the dataset + + std::vector<std::vector<Point> > textureIdx; + //!< index for warping of each delaunay triangle region constructed by 3 facemarks + std::vector<Point2f> base_shape; + //!< basic shape, normalized to be fit in an image with current detection resolution + std::vector<int> ind1; + //!< index of pixels for mapping process to obtains the grays values of face region + std::vector<int> ind2; + //!< index of pixels for mapping process to obtains the grays values of eroded face region + }; + std::vector<Texture> textures; + //!< a container to holds the texture data for each scale of fitting + + /*shape*/ + std::vector<Point2f> s0; + //!< the basic shape obtained from training dataset + Mat S,Q; + //!< the encoded shapes from training data + + }; + + //! overload with additional Config structures + virtual bool fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &runtime_params ) = 0; + + + //! initializer + static Ptr<FacemarkAAM> create(const FacemarkAAM::Params ¶meters = FacemarkAAM::Params() ); + virtual ~FacemarkAAM() {} + +}; /* AAM */ + +//! @} + +} /* namespace face */ +} /* namespace cv */ +#endif diff --git a/include/opencv2/face/facemarkLBF.hpp b/include/opencv2/face/facemarkLBF.hpp new file mode 100644 index 0000000..7f4cd32 --- /dev/null +++ b/include/opencv2/face/facemarkLBF.hpp @@ -0,0 +1,120 @@ +/* +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) +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. +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. + +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACEMARK_LBF_HPP__ +#define __OPENCV_FACEMARK_LBF_HPP__ + +#include "opencv2/face/facemark_train.hpp" + +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + +class CV_EXPORTS_W FacemarkLBF : public FacemarkTrain +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + + double shape_offset; + //!< offset for the loaded face landmark points + String cascade_face; + //!< filename of the face detector model + bool verbose; + //!< show the training print-out + + int n_landmarks; + //!< number of landmark points + int initShape_n; + //!< multiplier for augment the training data + + int stages_n; + //!< number of refinement stages + int tree_n; + //!< number of tree in the model for each landmark point refinement + int tree_depth; + //!< the depth of decision tree, defines the size of feature + double bagging_overlap; + //!< overlap ratio for training the LBF feature + + std::string model_filename; + //!< filename where the trained model will be saved + bool save_model; //!< flag to save the trained model or not + unsigned int seed; //!< seed for shuffling the training data + + std::vector<int> feats_m; + std::vector<double> radius_m; + std::vector<int> pupils[2]; + //!< index of facemark points on pupils of left and right eye + + Rect detectROI; + + void read(const FileNode& /*fn*/); + void write(FileStorage& /*fs*/) const; + + }; + + class BBox { + public: + BBox(); + ~BBox(); + BBox(double x, double y, double w, double h); + + Mat project(const Mat &shape) const; + Mat reproject(const Mat &shape) const; + + double x, y; + double x_center, y_center; + double x_scale, y_scale; + double width, height; + }; + + static Ptr<FacemarkLBF> create(const FacemarkLBF::Params ¶meters = FacemarkLBF::Params() ); + virtual ~FacemarkLBF(){}; +}; /* LBF */ + +//! @} + +} /* namespace face */ +}/* namespace cv */ + +#endif diff --git a/include/opencv2/face/facemark_train.hpp b/include/opencv2/face/facemark_train.hpp new file mode 100644 index 0000000..33ecb94 --- /dev/null +++ b/include/opencv2/face/facemark_train.hpp @@ -0,0 +1,392 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +/* +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACELANDMARKTRAIN_HPP__ +#define __OPENCV_FACELANDMARKTRAIN_HPP__ + +/** +@defgroup face Face Analysis +- @ref tutorial_table_of_content_facemark +- The Facemark API +*/ + +#include "opencv2/face/facemark.hpp" +#include "opencv2/objdetect.hpp" +#include <vector> +#include <string> + + +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + +typedef bool(*FN_FaceDetector)(InputArray, OutputArray, void* userData); + +struct CParams{ + String cascade; //!< the face detector + double scaleFactor; //!< Parameter specifying how much the image size is reduced at each image scale. + int minNeighbors; //!< Parameter specifying how many neighbors each candidate rectangle should have to retain it. + Size minSize; //!< Minimum possible object size. + Size maxSize; //!< Maximum possible object size. + + CV_EXPORTS CParams( + String cascade_model, + double sf = 1.1, + int minN = 3, + Size minSz = Size(30, 30), + Size maxSz = Size() + ); + + CascadeClassifier face_cascade; +}; + +/** @brief Default face detector +This function is mainly utilized by the implementation of a Facemark Algorithm. +End users are advised to use function Facemark::getFaces which can be manually defined +and circumvented to the algorithm by Facemark::setFaceDetector. + +@param image The input image to be processed. +@param faces Output of the function which represent region of interest of the detected faces. +Each face is stored in cv::Rect container. +@param params detector parameters + +<B>Example of usage</B> +@code +std::vector<cv::Rect> faces; +CParams params("haarcascade_frontalface_alt.xml"); +cv::face::getFaces(frame, faces, ¶ms); +for(int j=0;j<faces.size();j++){ + cv::rectangle(frame, faces[j], cv::Scalar(255,0,255)); +} +cv::imshow("detection", frame); +@endcode +*/ +CV_EXPORTS bool getFaces(InputArray image, OutputArray faces, CParams* params); + +CV_EXPORTS_W bool getFacesHAAR(InputArray image, OutputArray faces, const String& face_cascade_name); + +/** @brief A utility to load list of paths to training image and annotation file. +@param imageList The specified file contains paths to the training images. +@param annotationList The specified file contains paths to the training annotations. +@param images The loaded paths of training images. +@param annotations The loaded paths of annotation files. + +Example of usage: +@code +String imageFiles = "images_path.txt"; +String ptsFiles = "annotations_path.txt"; +std::vector<String> images_train; +std::vector<String> landmarks_train; +loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train); +@endcode +*/ +CV_EXPORTS_W bool loadDatasetList(String imageList, + String annotationList, + std::vector<String> & images, + std::vector<String> & annotations); + +/** @brief A utility to load facial landmark dataset from a single file. + +@param filename The filename of a file that contains the dataset information. +Each line contains the filename of an image followed by +pairs of x and y values of facial landmarks points separated by a space. +Example +@code +/home/user/ibug/image_003_1.jpg 336.820955 240.864510 334.238298 260.922709 335.266918 ... +/home/user/ibug/image_005_1.jpg 376.158428 230.845712 376.736984 254.924635 383.265403 ... +@endcode +@param images A vector where each element represent the filename of image in the dataset. +Images are not loaded by default to save the memory. +@param facePoints The loaded landmark points for all training data. +@param delim Delimiter between each element, the default value is a whitespace. +@param offset An offset value to adjust the loaded points. + +<B>Example of usage</B> +@code +cv::String imageFiles = "../data/images_train.txt"; +cv::String ptsFiles = "../data/points_train.txt"; +std::vector<String> images; +std::vector<std::vector<Point2f> > facePoints; +loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f); +@endcode +*/ +CV_EXPORTS_W bool loadTrainingData( String filename , std::vector<String> & images, + OutputArray facePoints, + char delim = ' ', float offset = 0.0f); + +/** @brief A utility to load facial landmark information from the dataset. + +@param imageList A file contains the list of image filenames in the training dataset. +@param groundTruth A file contains the list of filenames +where the landmarks points information are stored. +The content in each file should follow the standard format (see face::loadFacePoints). +@param images A vector where each element represent the filename of image in the dataset. +Images are not loaded by default to save the memory. +@param facePoints The loaded landmark points for all training data. +@param offset An offset value to adjust the loaded points. + +<B>Example of usage</B> +@code +cv::String imageFiles = "../data/images_train.txt"; +cv::String ptsFiles = "../data/points_train.txt"; +std::vector<String> images; +std::vector<std::vector<Point2f> > facePoints; +loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f); +@endcode + +example of content in the images_train.txt +@code +/home/user/ibug/image_003_1.jpg +/home/user/ibug/image_004_1.jpg +/home/user/ibug/image_005_1.jpg +/home/user/ibug/image_006.jpg +@endcode + +example of content in the points_train.txt +@code +/home/user/ibug/image_003_1.pts +/home/user/ibug/image_004_1.pts +/home/user/ibug/image_005_1.pts +/home/user/ibug/image_006.pts +@endcode +*/ +CV_EXPORTS_W bool loadTrainingData( String imageList, String groundTruth, + std::vector<String> & images, + OutputArray facePoints, + float offset = 0.0f); + +/** @brief This function extracts the data for training from .txt files which contains the corresponding image name and landmarks. +*The first file in each file should give the path of the image whose +*landmarks are being described in the file. Then in the subsequent +*lines there should be coordinates of the landmarks in the image +*i.e each line should be of the form x,y +*where x represents the x coordinate of the landmark and y represents +*the y coordinate of the landmark. +* +*For reference you can see the files as provided in the +*<a href="http://www.ifp.illinois.edu/~vuongle2/helen/">HELEN dataset</a> +* +* @param filename A vector of type cv::String containing name of the .txt files. +* @param trainlandmarks A vector of type cv::Point2f that would store shape or landmarks of all images. +* @param trainimages A vector of type cv::String which stores the name of images whose landmarks are tracked +* @returns A boolean value. It returns true when it reads the data successfully and false otherwise +*/ +CV_EXPORTS_W bool loadTrainingData(std::vector<String> filename,std::vector< std::vector<Point2f> > + &trainlandmarks,std::vector<String> & trainimages); + +/** @brief A utility to load facial landmark information from a given file. + +@param filename The filename of file contains the facial landmarks data. +@param points The loaded facial landmark points. +@param offset An offset value to adjust the loaded points. + +<B>Example of usage</B> +@code +std::vector<Point2f> points; +face::loadFacePoints("filename.txt", points, 0.0f); +@endcode + +The annotation file should follow the default format which is +@code +version: 1 +n_points: 68 +{ +212.716603 499.771793 +230.232816 566.290071 +... +} +@endcode +where n_points is the number of points considered +and each point is represented as its position in x and y. +*/ +CV_EXPORTS_W bool loadFacePoints( String filename, OutputArray points, + float offset = 0.0f); + +/** @brief Utility to draw the detected facial landmark points + +@param image The input image to be processed. +@param points Contains the data of points which will be drawn. +@param color The color of points in BGR format represented by cv::Scalar. + +<B>Example of usage</B> +@code +std::vector<Rect> faces; +std::vector<std::vector<Point2f> > landmarks; +facemark->getFaces(img, faces); +facemark->fit(img, faces, landmarks); +for(int j=0;j<rects.size();j++){ + face::drawFacemarks(frame, landmarks[j], Scalar(0,0,255)); +} +@endcode +*/ +CV_EXPORTS_W void drawFacemarks( InputOutputArray image, InputArray points, + Scalar color = Scalar(255,0,0)); + +/** @brief Abstract base class for trainable facemark models + +To utilize this API in your program, please take a look at the @ref tutorial_table_of_content_facemark +### Description + +The AAM and LBF facemark models in OpenCV are derived from the abstract base class FacemarkTrain, which +provides a unified access to those facemark algorithms in OpenCV. + +Here is an example on how to declare facemark algorithm: +@code +// Using Facemark in your code: +Ptr<Facemark> facemark = FacemarkLBF::create(); +@endcode + + +The typical pipeline for facemark detection is listed as follows: +- (Non-mandatory) Set a user defined face detection using FacemarkTrain::setFaceDetector. + The facemark algorithms are desgined to fit the facial points into a face. + Therefore, the face information should be provided to the facemark algorithm. + Some algorithms might provides a default face recognition function. + However, the users might prefer to use their own face detector to obtains the best possible detection result. +- (Non-mandatory) Training the model for a specific algorithm using FacemarkTrain::training. + In this case, the model should be automatically saved by the algorithm. + If the user already have a trained model, then this part can be omitted. +- Load the trained model using Facemark::loadModel. +- Perform the fitting via the Facemark::fit. +*/ +class CV_EXPORTS_W FacemarkTrain : public Facemark +{ +public: + /** @brief Add one training sample to the trainer. + + @param image Input image. + @param landmarks The ground-truth of facial landmarks points corresponds to the image. + + <B>Example of usage</B> + @code + String imageFiles = "../data/images_train.txt"; + String ptsFiles = "../data/points_train.txt"; + std::vector<String> images_train; + std::vector<String> landmarks_train; + + // load the list of dataset: image paths and landmark file paths + loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train); + + Mat image; + std::vector<Point2f> facial_points; + for(size_t i=0;i<images_train.size();i++){ + image = imread(images_train[i].c_str()); + loadFacePoints(landmarks_train[i],facial_points); + facemark->addTrainingSample(image, facial_points); + } + @endcode + + The contents in the training files should follows the standard format. + Here are examples for the contents in these files. + example of content in the images_train.txt + @code + /home/user/ibug/image_003_1.jpg + /home/user/ibug/image_004_1.jpg + /home/user/ibug/image_005_1.jpg + /home/user/ibug/image_006.jpg + @endcode + + example of content in the points_train.txt + @code + /home/user/ibug/image_003_1.pts + /home/user/ibug/image_004_1.pts + /home/user/ibug/image_005_1.pts + /home/user/ibug/image_006.pts + @endcode + + */ + virtual bool addTrainingSample(InputArray image, InputArray landmarks)=0; + + /** @brief Trains a Facemark algorithm using the given dataset. + Before the training process, training samples should be added to the trainer + using face::addTrainingSample function. + + @param parameters Optional extra parameters (algorithm dependent). + + <B>Example of usage</B> + @code + FacemarkLBF::Params params; + params.model_filename = "ibug68.model"; // filename to save the trained model + Ptr<Facemark> facemark = FacemarkLBF::create(params); + + // add training samples (see Facemark::addTrainingSample) + + facemark->training(); + @endcode + */ + + virtual void training(void* parameters=0)=0; + + /** @brief Set a user defined face detector for the Facemark algorithm. + @param detector The user defined face detector function + @param userData Detector parameters + + <B>Example of usage</B> + @code + MyDetectorParameters detectorParameters(...); + facemark->setFaceDetector(myDetector, &detectorParameters); + @endcode + + Example of a user defined face detector + @code + bool myDetector( InputArray image, OutputArray faces, void* userData) + { + MyDetectorParameters* params = (MyDetectorParameters*)userData; + // -------- do something -------- + } + @endcode + + TODO Lifetime of detector parameters is uncontrolled. Rework interface design to "Ptr<FaceDetector>". + */ + virtual bool setFaceDetector(FN_FaceDetector detector, void* userData = 0)=0; + + /** @brief Detect faces from a given image using default or user defined face detector. + Some Algorithm might not provide a default face detector. + + @param image Input image. + @param faces Output of the function which represent region of interest of the detected faces. Each face is stored in cv::Rect container. + + <B>Example of usage</B> + @code + std::vector<cv::Rect> faces; + facemark->getFaces(img, faces); + for(int j=0;j<faces.size();j++){ + cv::rectangle(img, faces[j], cv::Scalar(255,0,255)); + } + @endcode + */ + virtual bool getFaces(InputArray image, OutputArray faces)=0; + + /** @brief Get data from an algorithm + + @param items The obtained data, algorithm dependent. + + <B>Example of usage</B> + @code + Ptr<FacemarkAAM> facemark = FacemarkAAM::create(); + facemark->loadModel("AAM.yml"); + + FacemarkAAM::Data data; + facemark->getData(&data); + std::vector<Point2f> s0 = data.s0; + + cout<<s0<<endl; + @endcode + */ + virtual bool getData(void * items=0)=0; // FIXIT +}; /* Facemark*/ + +//! @} +} /* namespace face */ +} /* namespace cv */ +#endif //__OPENCV_FACELANDMARKTRAIN_HPP__ diff --git a/include/opencv2/face/facerec.hpp b/include/opencv2/face/facerec.hpp new file mode 100644 index 0000000..83c0701 --- /dev/null +++ b/include/opencv2/face/facerec.hpp @@ -0,0 +1,191 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (c) 2011,2012. Philipp Wagner <bytefish[at]gmx[dot]de>. +// Third party copyrights are property of their respective owners. + +#ifndef __OPENCV_FACEREC_HPP__ +#define __OPENCV_FACEREC_HPP__ + +#include "opencv2/face.hpp" +#include "opencv2/core.hpp" + +namespace cv { namespace face { + +//! @addtogroup face +//! @{ + +// base for two classes +class CV_EXPORTS_W BasicFaceRecognizer : public FaceRecognizer +{ +public: + /** @see setNumComponents */ + CV_WRAP int getNumComponents() const; + /** @copybrief getNumComponents @see getNumComponents */ + CV_WRAP void setNumComponents(int val); + /** @see setThreshold */ + CV_WRAP double getThreshold() const CV_OVERRIDE; + /** @copybrief getThreshold @see getThreshold */ + CV_WRAP void setThreshold(double val) CV_OVERRIDE; + CV_WRAP std::vector<cv::Mat> getProjections() const; + CV_WRAP cv::Mat getLabels() const; + CV_WRAP cv::Mat getEigenValues() const; + CV_WRAP cv::Mat getEigenVectors() const; + CV_WRAP cv::Mat getMean() const; + + virtual void read(const FileNode& fn) CV_OVERRIDE; + virtual void write(FileStorage& fs) const CV_OVERRIDE; + virtual bool empty() const CV_OVERRIDE; + + using FaceRecognizer::read; + using FaceRecognizer::write; + +protected: + int _num_components; + double _threshold; + std::vector<Mat> _projections; + Mat _labels; + Mat _eigenvectors; + Mat _eigenvalues; + Mat _mean; +}; + +class CV_EXPORTS_W EigenFaceRecognizer : public BasicFaceRecognizer +{ +public: + /** + @param num_components The number of components (read: Eigenfaces) kept for this Principal + Component Analysis. As a hint: There's no rule how many components (read: Eigenfaces) should be + kept for good reconstruction capabilities. It is based on your input data, so experiment with the + number. Keeping 80 components should almost always be sufficient. + @param threshold The threshold applied in the prediction. + + ### Notes: + + - Training and prediction must be done on grayscale images, use cvtColor to convert between the + color spaces. + - **THE EIGENFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL + SIZE.** (caps-lock, because I got so many mails asking for this). You have to make sure your + input data has the correct shape, else a meaningful exception is thrown. Use resize to resize + the images. + - This model does not support updating. + + ### Model internal data: + + - num_components see EigenFaceRecognizer::create. + - threshold see EigenFaceRecognizer::create. + - eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending). + - eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their + eigenvalue). + - mean The sample mean calculated from the training data. + - projections The projections of the training data. + - labels The threshold applied in the prediction. If the distance to the nearest neighbor is + larger than the threshold, this method returns -1. + */ + CV_WRAP static Ptr<EigenFaceRecognizer> create(int num_components = 0, double threshold = DBL_MAX); +}; + +class CV_EXPORTS_W FisherFaceRecognizer : public BasicFaceRecognizer +{ +public: + /** + @param num_components The number of components (read: Fisherfaces) kept for this Linear + Discriminant Analysis with the Fisherfaces criterion. It's useful to keep all components, that + means the number of your classes c (read: subjects, persons you want to recognize). If you leave + this at the default (0) or set it to a value less-equal 0 or greater (c-1), it will be set to the + correct number (c-1) automatically. + @param threshold The threshold applied in the prediction. If the distance to the nearest neighbor + is larger than the threshold, this method returns -1. + + ### Notes: + + - Training and prediction must be done on grayscale images, use cvtColor to convert between the + color spaces. + - **THE FISHERFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL + SIZE.** (caps-lock, because I got so many mails asking for this). You have to make sure your + input data has the correct shape, else a meaningful exception is thrown. Use resize to resize + the images. + - This model does not support updating. + + ### Model internal data: + + - num_components see FisherFaceRecognizer::create. + - threshold see FisherFaceRecognizer::create. + - eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending). + - eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their + eigenvalue). + - mean The sample mean calculated from the training data. + - projections The projections of the training data. + - labels The labels corresponding to the projections. + */ + CV_WRAP static Ptr<FisherFaceRecognizer> create(int num_components = 0, double threshold = DBL_MAX); +}; + + +class CV_EXPORTS_W LBPHFaceRecognizer : public FaceRecognizer +{ +public: + /** @see setGridX */ + CV_WRAP virtual int getGridX() const = 0; + /** @copybrief getGridX @see getGridX */ + CV_WRAP virtual void setGridX(int val) = 0; + /** @see setGridY */ + CV_WRAP virtual int getGridY() const = 0; + /** @copybrief getGridY @see getGridY */ + CV_WRAP virtual void setGridY(int val) = 0; + /** @see setRadius */ + CV_WRAP virtual int getRadius() const = 0; + /** @copybrief getRadius @see getRadius */ + CV_WRAP virtual void setRadius(int val) = 0; + /** @see setNeighbors */ + CV_WRAP virtual int getNeighbors() const = 0; + /** @copybrief getNeighbors @see getNeighbors */ + CV_WRAP virtual void setNeighbors(int val) = 0; + /** @see setThreshold */ + CV_WRAP virtual double getThreshold() const CV_OVERRIDE = 0; + /** @copybrief getThreshold @see getThreshold */ + CV_WRAP virtual void setThreshold(double val) CV_OVERRIDE = 0; + CV_WRAP virtual std::vector<cv::Mat> getHistograms() const = 0; + CV_WRAP virtual cv::Mat getLabels() const = 0; + + /** + @param radius The radius used for building the Circular Local Binary Pattern. The greater the + radius, the smoother the image but more spatial information you can get. + @param neighbors The number of sample points to build a Circular Local Binary Pattern from. An + appropriate value is to use `8` sample points. Keep in mind: the more sample points you include, + the higher the computational cost. + @param grid_x The number of cells in the horizontal direction, 8 is a common value used in + publications. The more cells, the finer the grid, the higher the dimensionality of the resulting + feature vector. + @param grid_y The number of cells in the vertical direction, 8 is a common value used in + publications. The more cells, the finer the grid, the higher the dimensionality of the resulting + feature vector. + @param threshold The threshold applied in the prediction. If the distance to the nearest neighbor + is larger than the threshold, this method returns -1. + + ### Notes: + + - The Circular Local Binary Patterns (used in training and prediction) expect the data given as + grayscale images, use cvtColor to convert between the color spaces. + - This model supports updating. + + ### Model internal data: + + - radius see LBPHFaceRecognizer::create. + - neighbors see LBPHFaceRecognizer::create. + - grid_x see LLBPHFaceRecognizer::create. + - grid_y see LBPHFaceRecognizer::create. + - threshold see LBPHFaceRecognizer::create. + - histograms Local Binary Patterns Histograms calculated from the given training data (empty if + none was given). + - labels Labels corresponding to the calculated Local Binary Patterns Histograms. + */ + CV_WRAP static Ptr<LBPHFaceRecognizer> create(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8, double threshold = DBL_MAX); +}; + +//! @} + +}} //namespace cv::face + +#endif //__OPENCV_FACEREC_HPP__ diff --git a/include/opencv2/face/mace.hpp b/include/opencv2/face/mace.hpp new file mode 100644 index 0000000..ba3ec86 --- /dev/null +++ b/include/opencv2/face/mace.hpp @@ -0,0 +1,114 @@ +// This file is part of the OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __mace_h_onboard__ +#define __mace_h_onboard__ + +#include "opencv2/core.hpp" + + +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + + +/** +@brief Minimum Average Correlation Energy Filter + useful for authentication with (cancellable) biometrical features. + (does not need many positives to train (10-50), and no negatives at all, also robust to noise/salting) + + see also: @cite Savvides04 + + this implementation is largely based on: https://code.google.com/archive/p/pam-face-authentication (GSOC 2009) + + use it like: + @code + + Ptr<face::MACE> mace = face::MACE::create(64); + + vector<Mat> pos_images = ... + mace->train(pos_images); + + Mat query = ... + bool same = mace->same(query); + + @endcode + + you can also use two-factor authentication, with an additional passphrase: + + @code + String owners_passphrase = "ilikehotdogs"; + Ptr<face::MACE> mace = face::MACE::create(64); + mace->salt(owners_passphrase); + vector<Mat> pos_images = ... + mace->train(pos_images); + + // now, users have to give a valid passphrase, along with the image: + Mat query = ... + cout << "enter passphrase: "; + string pass; + getline(cin, pass); + mace->salt(pass); + bool same = mace->same(query); + @endcode + + save/load your model: + @code + Ptr<face::MACE> mace = face::MACE::create(64); + mace->train(pos_images); + mace->save("my_mace.xml"); + + // later: + Ptr<MACE> reloaded = MACE::load("my_mace.xml"); + reloaded->same(some_image); + @endcode + +*/ + +class CV_EXPORTS_W MACE : public cv::Algorithm +{ +public: + /** + @brief optionally encrypt images with random convolution + @param passphrase a crc64 random seed will get generated from this + */ + CV_WRAP virtual void salt(const cv::String &passphrase) = 0; + + /** + @brief train it on positive features + compute the mace filter: `h = D(-1) * X * (X(+) * D(-1) * X)(-1) * C` + also calculate a minimal threshold for this class, the smallest self-similarity from the train images + @param images a vector<Mat> with the train images + */ + CV_WRAP virtual void train(cv::InputArrayOfArrays images) = 0; + + /** + @brief correlate query img and threshold to min class value + @param query a Mat with query image + */ + CV_WRAP virtual bool same(cv::InputArray query) const = 0; + + + /** + @brief constructor + @param filename build a new MACE instance from a pre-serialized FileStorage + @param objname (optional) top-level node in the FileStorage + */ + CV_WRAP static cv::Ptr<MACE> load(const String &filename, const String &objname=String()); + + /** + @brief constructor + @param IMGSIZE images will get resized to this (should be an even number) + */ + CV_WRAP static cv::Ptr<MACE> create(int IMGSIZE=64); +}; + +//! @} + +}/* namespace face */ +}/* namespace cv */ + +#endif // __mace_h_onboard__ diff --git a/include/opencv2/face/predict_collector.hpp b/include/opencv2/face/predict_collector.hpp new file mode 100644 index 0000000..dba3c7e --- /dev/null +++ b/include/opencv2/face/predict_collector.hpp @@ -0,0 +1,127 @@ +/* +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) + +Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +Copyright (C) 2015, OpenCV Foundation, all rights reserved. +Copyright (C) 2015, Itseez Inc., all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_PREDICT_COLLECTOR_HPP__ +#define __OPENCV_PREDICT_COLLECTOR_HPP__ + +#include <vector> +#include <map> +#include <utility> +#include <cfloat> + +#include "opencv2/core/base.hpp" + +namespace cv { +namespace face { +//! @addtogroup face +//! @{ +/** @brief Abstract base class for all strategies of prediction result handling +*/ +class CV_EXPORTS_W PredictCollector +{ +public: + virtual ~PredictCollector() {} + + /** @brief Interface method called by face recognizer before results processing + @param size total size of prediction evaluation that recognizer could perform + */ + virtual void init(size_t size) { CV_UNUSED(size); } + + /** @brief Interface method called by face recognizer for each result + @param label current prediction label + @param dist current prediction distance (confidence) + */ + virtual bool collect(int label, double dist) = 0; +}; + +/** @brief Default predict collector + +Trace minimal distance with treshhold checking (that is default behavior for most predict logic) +*/ +class CV_EXPORTS_W StandardCollector : public PredictCollector +{ +public: + struct PredictResult + { + int label; + double distance; + PredictResult(int label_ = -1, double distance_ = DBL_MAX) : label(label_), distance(distance_) {} + }; +protected: + double threshold; + PredictResult minRes; + std::vector<PredictResult> data; +public: + /** @brief Constructor + @param threshold_ set threshold + */ + StandardCollector(double threshold_ = DBL_MAX); + /** @brief overloaded interface method */ + void init(size_t size) CV_OVERRIDE; + /** @brief overloaded interface method */ + bool collect(int label, double dist) CV_OVERRIDE; + /** @brief Returns label with minimal distance */ + CV_WRAP int getMinLabel() const; + /** @brief Returns minimal distance value */ + CV_WRAP double getMinDist() const; + /** @brief Return results as vector + @param sorted If set, results will be sorted by distance + Each values is a pair of label and distance. + */ + CV_WRAP std::vector< std::pair<int, double> > getResults(bool sorted = false) const; + /** @brief Return results as map + Labels are keys, values are minimal distances + */ + std::map<int, double> getResultsMap() const; + /** @brief Static constructor + @param threshold set threshold + */ + CV_WRAP static Ptr<StandardCollector> create(double threshold = DBL_MAX); +}; + +//! @} +} +} + +#endif diff --git a/include/opencv2/features2d.hpp b/include/opencv2/features2d.hpp new file mode 100644 index 0000000..ee81ebe --- /dev/null +++ b/include/opencv2/features2d.hpp @@ -0,0 +1,1428 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_FEATURES_2D_HPP +#define OPENCV_FEATURES_2D_HPP + +#include "opencv2/opencv_modules.hpp" +#include "opencv2/core.hpp" + +#ifdef HAVE_OPENCV_FLANN +#include "opencv2/flann/miniflann.hpp" +#endif + +/** + @defgroup features2d 2D Features Framework + @{ + @defgroup features2d_main Feature Detection and Description + @defgroup features2d_match Descriptor Matchers + +Matchers of keypoint descriptors in OpenCV have wrappers with a common interface that enables you to +easily switch between different algorithms solving the same problem. This section is devoted to +matching descriptors that are represented as vectors in a multidimensional space. All objects that +implement vector descriptor matchers inherit the DescriptorMatcher interface. + +@note + - An example explaining keypoint matching can be found at + opencv_source_code/samples/cpp/descriptor_extractor_matcher.cpp + - An example on descriptor matching evaluation can be found at + opencv_source_code/samples/cpp/detector_descriptor_matcher_evaluation.cpp + - An example on one to many image matching can be found at + opencv_source_code/samples/cpp/matching_to_many_images.cpp + + @defgroup features2d_draw Drawing Function of Keypoints and Matches + @defgroup features2d_category Object Categorization + +This section describes approaches based on local 2D features and used to categorize objects. + +@note + - A complete Bag-Of-Words sample can be found at + opencv_source_code/samples/cpp/bagofwords_classification.cpp + - (Python) An example using the features2D framework to perform object categorization can be + found at opencv_source_code/samples/python/find_obj.py + + @} + */ + +namespace cv +{ + +//! @addtogroup features2d +//! @{ + +// //! writes vector of keypoints to the file storage +// CV_EXPORTS void write(FileStorage& fs, const String& name, const std::vector<KeyPoint>& keypoints); +// //! reads vector of keypoints from the specified file storage node +// CV_EXPORTS void read(const FileNode& node, CV_OUT std::vector<KeyPoint>& keypoints); + +/** @brief A class filters a vector of keypoints. + + Because now it is difficult to provide a convenient interface for all usage scenarios of the + keypoints filter class, it has only several needed by now static methods. + */ +class CV_EXPORTS KeyPointsFilter +{ +public: + KeyPointsFilter(){} + + /* + * Remove keypoints within borderPixels of an image edge. + */ + static void runByImageBorder( std::vector<KeyPoint>& keypoints, Size imageSize, int borderSize ); + /* + * Remove keypoints of sizes out of range. + */ + static void runByKeypointSize( std::vector<KeyPoint>& keypoints, float minSize, + float maxSize=FLT_MAX ); + /* + * Remove keypoints from some image by mask for pixels of this image. + */ + static void runByPixelsMask( std::vector<KeyPoint>& keypoints, const Mat& mask ); + /* + * Remove duplicated keypoints. + */ + static void removeDuplicated( std::vector<KeyPoint>& keypoints ); + /* + * Remove duplicated keypoints and sort the remaining keypoints + */ + static void removeDuplicatedSorted( std::vector<KeyPoint>& keypoints ); + + /* + * Retain the specified number of the best keypoints (according to the response) + */ + static void retainBest( std::vector<KeyPoint>& keypoints, int npoints ); +}; + + +/************************************ Base Classes ************************************/ + +/** @brief Abstract base class for 2D image feature detectors and descriptor extractors +*/ +#ifdef __EMSCRIPTEN__ +class CV_EXPORTS_W Feature2D : public Algorithm +#else +class CV_EXPORTS_W Feature2D : public virtual Algorithm +#endif +{ +public: + virtual ~Feature2D(); + + /** @brief Detects keypoints in an image (first variant) or image set (second variant). + + @param image Image. + @param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set + of keypoints detected in images[i] . + @param mask Mask specifying where to look for keypoints (optional). It must be a 8-bit integer + matrix with non-zero values in the region of interest. + */ + CV_WRAP virtual void detect( InputArray image, + CV_OUT std::vector<KeyPoint>& keypoints, + InputArray mask=noArray() ); + + /** @overload + @param images Image set. + @param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set + of keypoints detected in images[i] . + @param masks Masks for each input image specifying where to look for keypoints (optional). + masks[i] is a mask for images[i]. + */ + CV_WRAP virtual void detect( InputArrayOfArrays images, + CV_OUT std::vector<std::vector<KeyPoint> >& keypoints, + InputArrayOfArrays masks=noArray() ); + + /** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set + (second variant). + + @param image Image. + @param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be + computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint + with several dominant orientations (for each orientation). + @param descriptors Computed descriptors. In the second variant of the method descriptors[i] are + descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the + descriptor for keypoint j-th keypoint. + */ + CV_WRAP virtual void compute( InputArray image, + CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints, + OutputArray descriptors ); + + /** @overload + + @param images Image set. + @param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be + computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint + with several dominant orientations (for each orientation). + @param descriptors Computed descriptors. In the second variant of the method descriptors[i] are + descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the + descriptor for keypoint j-th keypoint. + */ + CV_WRAP virtual void compute( InputArrayOfArrays images, + CV_OUT CV_IN_OUT std::vector<std::vector<KeyPoint> >& keypoints, + OutputArrayOfArrays descriptors ); + + /** Detects keypoints and computes the descriptors */ + CV_WRAP virtual void detectAndCompute( InputArray image, InputArray mask, + CV_OUT std::vector<KeyPoint>& keypoints, + OutputArray descriptors, + bool useProvidedKeypoints=false ); + + CV_WRAP virtual int descriptorSize() const; + CV_WRAP virtual int descriptorType() const; + CV_WRAP virtual int defaultNorm() const; + + CV_WRAP void write( const String& fileName ) const; + + CV_WRAP void read( const String& fileName ); + + virtual void write( FileStorage&) const CV_OVERRIDE; + + // see corresponding cv::Algorithm method + CV_WRAP virtual void read( const FileNode&) CV_OVERRIDE; + + //! Return true if detector object is empty + CV_WRAP virtual bool empty() const CV_OVERRIDE; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; + + // see corresponding cv::Algorithm method + CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) const { Algorithm::write(fs, name); } +}; + +/** Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch +between different algorithms solving the same problem. All objects that implement keypoint detectors +inherit the FeatureDetector interface. */ +typedef Feature2D FeatureDetector; + +/** Extractors of keypoint descriptors in OpenCV have wrappers with a common interface that enables you +to easily switch between different algorithms solving the same problem. This section is devoted to +computing descriptors represented as vectors in a multidimensional space. All objects that implement +the vector descriptor extractors inherit the DescriptorExtractor interface. + */ +typedef Feature2D DescriptorExtractor; + +//! @addtogroup features2d_main +//! @{ + +/** @brief Class implementing the BRISK keypoint detector and descriptor extractor, described in @cite LCS11 . + */ +class CV_EXPORTS_W BRISK : public Feature2D +{ +public: + /** @brief The BRISK constructor + + @param thresh AGAST detection threshold score. + @param octaves detection octaves. Use 0 to do single scale. + @param patternScale apply this scale to the pattern used for sampling the neighbourhood of a + keypoint. + */ + CV_WRAP static Ptr<BRISK> create(int thresh=30, int octaves=3, float patternScale=1.0f); + + /** @brief The BRISK constructor for a custom pattern + + @param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for + keypoint scale 1). + @param numberList defines the number of sampling points on the sampling circle. Must be the same + size as radiusList.. + @param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint + scale 1). + @param dMin threshold for the long pairings used for orientation determination (in pixels for + keypoint scale 1). + @param indexChange index remapping of the bits. */ + CV_WRAP static Ptr<BRISK> create(const std::vector<float> &radiusList, const std::vector<int> &numberList, + float dMax=5.85f, float dMin=8.2f, const std::vector<int>& indexChange=std::vector<int>()); + + /** @brief The BRISK constructor for a custom pattern, detection threshold and octaves + + @param thresh AGAST detection threshold score. + @param octaves detection octaves. Use 0 to do single scale. + @param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for + keypoint scale 1). + @param numberList defines the number of sampling points on the sampling circle. Must be the same + size as radiusList.. + @param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint + scale 1). + @param dMin threshold for the long pairings used for orientation determination (in pixels for + keypoint scale 1). + @param indexChange index remapping of the bits. */ + CV_WRAP static Ptr<BRISK> create(int thresh, int octaves, const std::vector<float> &radiusList, + const std::vector<int> &numberList, float dMax=5.85f, float dMin=8.2f, + const std::vector<int>& indexChange=std::vector<int>()); + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Class implementing the ORB (*oriented BRIEF*) keypoint detector and descriptor extractor + +described in @cite RRKB11 . The algorithm uses FAST in pyramids to detect stable keypoints, selects +the strongest features using FAST or Harris response, finds their orientation using first-order +moments and computes the descriptors using BRIEF (where the coordinates of random point pairs (or +k-tuples) are rotated according to the measured orientation). + */ +class CV_EXPORTS_W ORB : public Feature2D +{ +public: + enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; + + /** @brief The ORB constructor + + @param nfeatures The maximum number of features to retain. + @param scaleFactor Pyramid decimation ratio, greater than 1. scaleFactor==2 means the classical + pyramid, where each next level has 4x less pixels than the previous, but such a big scale factor + will degrade feature matching scores dramatically. On the other hand, too close to 1 scale factor + will mean that to cover certain scale range you will need more pyramid levels and so the speed + will suffer. + @param nlevels The number of pyramid levels. The smallest level will have linear size equal to + input_image_linear_size/pow(scaleFactor, nlevels - firstLevel). + @param edgeThreshold This is size of the border where the features are not detected. It should + roughly match the patchSize parameter. + @param firstLevel The level of pyramid to put source image to. Previous layers are filled + with upscaled source image. + @param WTA_K The number of points that produce each element of the oriented BRIEF descriptor. The + default value 2 means the BRIEF where we take a random point pair and compare their brightnesses, + so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3 + random points (of course, those point coordinates are random, but they are generated from the + pre-defined seed, so each element of BRIEF descriptor is computed deterministically from the pixel + rectangle), find point of maximum brightness and output index of the winner (0, 1 or 2). Such + output will occupy 2 bits, and therefore it will need a special variant of Hamming distance, + denoted as NORM_HAMMING2 (2 bits per bin). When WTA_K=4, we take 4 random points to compute each + bin (that will also occupy 2 bits with possible values 0, 1, 2 or 3). + @param scoreType The default HARRIS_SCORE means that Harris algorithm is used to rank features + (the score is written to KeyPoint::score and is used to retain best nfeatures features); + FAST_SCORE is alternative value of the parameter that produces slightly less stable keypoints, + but it is a little faster to compute. + @param patchSize size of the patch used by the oriented BRIEF descriptor. Of course, on smaller + pyramid layers the perceived image area covered by a feature will be larger. + @param fastThreshold + */ + CV_WRAP static Ptr<ORB> create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, + int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20); + + CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; + CV_WRAP virtual int getMaxFeatures() const = 0; + + CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0; + CV_WRAP virtual double getScaleFactor() const = 0; + + CV_WRAP virtual void setNLevels(int nlevels) = 0; + CV_WRAP virtual int getNLevels() const = 0; + + CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0; + CV_WRAP virtual int getEdgeThreshold() const = 0; + + CV_WRAP virtual void setFirstLevel(int firstLevel) = 0; + CV_WRAP virtual int getFirstLevel() const = 0; + + CV_WRAP virtual void setWTA_K(int wta_k) = 0; + CV_WRAP virtual int getWTA_K() const = 0; + + CV_WRAP virtual void setScoreType(int scoreType) = 0; + CV_WRAP virtual int getScoreType() const = 0; + + CV_WRAP virtual void setPatchSize(int patchSize) = 0; + CV_WRAP virtual int getPatchSize() const = 0; + + CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0; + CV_WRAP virtual int getFastThreshold() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Maximally stable extremal region extractor + +The class encapsulates all the parameters of the %MSER extraction algorithm (see [wiki +article](http://en.wikipedia.org/wiki/Maximally_stable_extremal_regions)). + +- there are two different implementation of %MSER: one for grey image, one for color image + +- the grey image algorithm is taken from: @cite nister2008linear ; the paper claims to be faster +than union-find method; it actually get 1.5~2m/s on my centrino L7200 1.2GHz laptop. + +- the color image algorithm is taken from: @cite forssen2007maximally ; it should be much slower +than grey image method ( 3~4 times ); the chi_table.h file is taken directly from paper's source +code which is distributed under GPL. + +- (Python) A complete example showing the use of the %MSER detector can be found at samples/python/mser.py +*/ +class CV_EXPORTS_W MSER : public Feature2D +{ +public: + /** @brief Full consturctor for %MSER detector + + @param _delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$ + @param _min_area prune the area which smaller than minArea + @param _max_area prune the area which bigger than maxArea + @param _max_variation prune the area have similar size to its children + @param _min_diversity for color image, trace back to cut off mser with diversity less than min_diversity + @param _max_evolution for color image, the evolution steps + @param _area_threshold for color image, the area threshold to cause re-initialize + @param _min_margin for color image, ignore too small margin + @param _edge_blur_size for color image, the aperture size for edge blur + */ + CV_WRAP static Ptr<MSER> create( int _delta=5, int _min_area=60, int _max_area=14400, + double _max_variation=0.25, double _min_diversity=.2, + int _max_evolution=200, double _area_threshold=1.01, + double _min_margin=0.003, int _edge_blur_size=5 ); + + /** @brief Detect %MSER regions + + @param image input image (8UC1, 8UC3 or 8UC4, must be greater or equal than 3x3) + @param msers resulting list of point sets + @param bboxes resulting bounding boxes + */ + CV_WRAP virtual void detectRegions( InputArray image, + CV_OUT std::vector<std::vector<Point> >& msers, + CV_OUT std::vector<Rect>& bboxes ) = 0; + + CV_WRAP virtual void setDelta(int delta) = 0; + CV_WRAP virtual int getDelta() const = 0; + + CV_WRAP virtual void setMinArea(int minArea) = 0; + CV_WRAP virtual int getMinArea() const = 0; + + CV_WRAP virtual void setMaxArea(int maxArea) = 0; + CV_WRAP virtual int getMaxArea() const = 0; + + CV_WRAP virtual void setPass2Only(bool f) = 0; + CV_WRAP virtual bool getPass2Only() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @overload */ +CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints, + int threshold, bool nonmaxSuppression=true ); + +/** @brief Detects corners using the FAST algorithm + +@param image grayscale image where keypoints (corners) are detected. +@param keypoints keypoints detected on the image. +@param threshold threshold on difference between intensity of the central pixel and pixels of a +circle around this pixel. +@param nonmaxSuppression if true, non-maximum suppression is applied to detected corners +(keypoints). +@param type one of the three neighborhoods as defined in the paper: +FastFeatureDetector::TYPE_9_16, FastFeatureDetector::TYPE_7_12, +FastFeatureDetector::TYPE_5_8 + +Detects corners using the FAST algorithm by @cite Rosten06 . + +@note In Python API, types are given as cv2.FAST_FEATURE_DETECTOR_TYPE_5_8, +cv2.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv2.FAST_FEATURE_DETECTOR_TYPE_9_16. For corner +detection, use cv2.FAST.detect() method. + */ +CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints, + int threshold, bool nonmaxSuppression, int type ); + +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Wrapping class for feature detection using the FAST method. : + */ +class CV_EXPORTS_W FastFeatureDetector : public Feature2D +{ +public: + enum + { + TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2, + THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002, + }; + + CV_WRAP static Ptr<FastFeatureDetector> create( int threshold=10, + bool nonmaxSuppression=true, + int type=FastFeatureDetector::TYPE_9_16 ); + + CV_WRAP virtual void setThreshold(int threshold) = 0; + CV_WRAP virtual int getThreshold() const = 0; + + CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; + CV_WRAP virtual bool getNonmaxSuppression() const = 0; + + CV_WRAP virtual void setType(int type) = 0; + CV_WRAP virtual int getType() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @overload */ +CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints, + int threshold, bool nonmaxSuppression=true ); + +/** @brief Detects corners using the AGAST algorithm + +@param image grayscale image where keypoints (corners) are detected. +@param keypoints keypoints detected on the image. +@param threshold threshold on difference between intensity of the central pixel and pixels of a +circle around this pixel. +@param nonmaxSuppression if true, non-maximum suppression is applied to detected corners +(keypoints). +@param type one of the four neighborhoods as defined in the paper: +AgastFeatureDetector::AGAST_5_8, AgastFeatureDetector::AGAST_7_12d, +AgastFeatureDetector::AGAST_7_12s, AgastFeatureDetector::OAST_9_16 + +For non-Intel platforms, there is a tree optimised variant of AGAST with same numerical results. +The 32-bit binary tree tables were generated automatically from original code using perl script. +The perl script and examples of tree generation are placed in features2d/doc folder. +Detects corners using the AGAST algorithm by @cite mair2010_agast . + + */ +CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints, + int threshold, bool nonmaxSuppression, int type ); +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Wrapping class for feature detection using the AGAST method. : + */ +class CV_EXPORTS_W AgastFeatureDetector : public Feature2D +{ +public: + enum + { + AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3, + THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001, + }; + + CV_WRAP static Ptr<AgastFeatureDetector> create( int threshold=10, + bool nonmaxSuppression=true, + int type=AgastFeatureDetector::OAST_9_16 ); + + CV_WRAP virtual void setThreshold(int threshold) = 0; + CV_WRAP virtual int getThreshold() const = 0; + + CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; + CV_WRAP virtual bool getNonmaxSuppression() const = 0; + + CV_WRAP virtual void setType(int type) = 0; + CV_WRAP virtual int getType() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. : + */ +class CV_EXPORTS_W GFTTDetector : public Feature2D +{ +public: + CV_WRAP static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1, + int blockSize=3, bool useHarrisDetector=false, double k=0.04 ); + CV_WRAP static Ptr<GFTTDetector> create( int maxCorners, double qualityLevel, double minDistance, + int blockSize, int gradiantSize, bool useHarrisDetector=false, double k=0.04 ); + CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; + CV_WRAP virtual int getMaxFeatures() const = 0; + + CV_WRAP virtual void setQualityLevel(double qlevel) = 0; + CV_WRAP virtual double getQualityLevel() const = 0; + + CV_WRAP virtual void setMinDistance(double minDistance) = 0; + CV_WRAP virtual double getMinDistance() const = 0; + + CV_WRAP virtual void setBlockSize(int blockSize) = 0; + CV_WRAP virtual int getBlockSize() const = 0; + + CV_WRAP virtual void setHarrisDetector(bool val) = 0; + CV_WRAP virtual bool getHarrisDetector() const = 0; + + CV_WRAP virtual void setK(double k) = 0; + CV_WRAP virtual double getK() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Class for extracting blobs from an image. : + +The class implements a simple algorithm for extracting blobs from an image: + +1. Convert the source image to binary images by applying thresholding with several thresholds from + minThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep between + neighboring thresholds. +2. Extract connected components from every binary image by findContours and calculate their + centers. +3. Group centers from several binary images by their coordinates. Close centers form one group that + corresponds to one blob, which is controlled by the minDistBetweenBlobs parameter. +4. From the groups, estimate final centers of blobs and their radiuses and return as locations and + sizes of keypoints. + +This class performs several filtrations of returned blobs. You should set filterBy\* to true/false +to turn on/off corresponding filtration. Available filtrations: + +- **By color**. This filter compares the intensity of a binary image at the center of a blob to +blobColor. If they differ, the blob is filtered out. Use blobColor = 0 to extract dark blobs +and blobColor = 255 to extract light blobs. +- **By area**. Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive). +- **By circularity**. Extracted blobs have circularity +(\f$\frac{4*\pi*Area}{perimeter * perimeter}\f$) between minCircularity (inclusive) and +maxCircularity (exclusive). +- **By ratio of the minimum inertia to maximum inertia**. Extracted blobs have this ratio +between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive). +- **By convexity**. Extracted blobs have convexity (area / area of blob convex hull) between +minConvexity (inclusive) and maxConvexity (exclusive). + +Default values of parameters are tuned to extract dark circular blobs. + */ +class CV_EXPORTS_W SimpleBlobDetector : public Feature2D +{ +public: + struct CV_EXPORTS_W_SIMPLE Params + { + CV_WRAP Params(); + CV_PROP_RW float thresholdStep; + CV_PROP_RW float minThreshold; + CV_PROP_RW float maxThreshold; + CV_PROP_RW size_t minRepeatability; + CV_PROP_RW float minDistBetweenBlobs; + + CV_PROP_RW bool filterByColor; + CV_PROP_RW uchar blobColor; + + CV_PROP_RW bool filterByArea; + CV_PROP_RW float minArea, maxArea; + + CV_PROP_RW bool filterByCircularity; + CV_PROP_RW float minCircularity, maxCircularity; + + CV_PROP_RW bool filterByInertia; + CV_PROP_RW float minInertiaRatio, maxInertiaRatio; + + CV_PROP_RW bool filterByConvexity; + CV_PROP_RW float minConvexity, maxConvexity; + + void read( const FileNode& fn ); + void write( FileStorage& fs ) const; + }; + + CV_WRAP static Ptr<SimpleBlobDetector> + create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params()); + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Class implementing the KAZE keypoint detector and descriptor extractor, described in @cite ABD12 . + +@note AKAZE descriptor can only be used with KAZE or AKAZE keypoints .. [ABD12] KAZE Features. Pablo +F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on Computer Vision +(ECCV), Fiorenze, Italy, October 2012. +*/ +class CV_EXPORTS_W KAZE : public Feature2D +{ +public: + enum + { + DIFF_PM_G1 = 0, + DIFF_PM_G2 = 1, + DIFF_WEICKERT = 2, + DIFF_CHARBONNIER = 3 + }; + + /** @brief The KAZE constructor + + @param extended Set to enable extraction of extended (128-byte) descriptor. + @param upright Set to enable use of upright descriptors (non rotation-invariant). + @param threshold Detector response threshold to accept point + @param nOctaves Maximum octave evolution of the image + @param nOctaveLayers Default number of sublevels per scale level + @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or + DIFF_CHARBONNIER + */ + CV_WRAP static Ptr<KAZE> create(bool extended=false, bool upright=false, + float threshold = 0.001f, + int nOctaves = 4, int nOctaveLayers = 4, + int diffusivity = KAZE::DIFF_PM_G2); + + CV_WRAP virtual void setExtended(bool extended) = 0; + CV_WRAP virtual bool getExtended() const = 0; + + CV_WRAP virtual void setUpright(bool upright) = 0; + CV_WRAP virtual bool getUpright() const = 0; + + CV_WRAP virtual void setThreshold(double threshold) = 0; + CV_WRAP virtual double getThreshold() const = 0; + + CV_WRAP virtual void setNOctaves(int octaves) = 0; + CV_WRAP virtual int getNOctaves() const = 0; + + CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; + CV_WRAP virtual int getNOctaveLayers() const = 0; + + CV_WRAP virtual void setDiffusivity(int diff) = 0; + CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Class implementing the AKAZE keypoint detector and descriptor extractor, described in @cite ANB13. + +@details AKAZE descriptors can only be used with KAZE or AKAZE keypoints. This class is thread-safe. + +@note When you need descriptors use Feature2D::detectAndCompute, which +provides better performance. When using Feature2D::detect followed by +Feature2D::compute scale space pyramid is computed twice. + +@note AKAZE implements T-API. When image is passed as UMat some parts of the algorithm +will use OpenCL. + +@note [ANB13] Fast Explicit Diffusion for Accelerated Features in Nonlinear +Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien Bartoli. In +British Machine Vision Conference (BMVC), Bristol, UK, September 2013. + +*/ +class CV_EXPORTS_W AKAZE : public Feature2D +{ +public: + // AKAZE descriptor type + enum + { + DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation + DESCRIPTOR_KAZE = 3, + DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation + DESCRIPTOR_MLDB = 5 + }; + + /** @brief The AKAZE constructor + + @param descriptor_type Type of the extracted descriptor: DESCRIPTOR_KAZE, + DESCRIPTOR_KAZE_UPRIGHT, DESCRIPTOR_MLDB or DESCRIPTOR_MLDB_UPRIGHT. + @param descriptor_size Size of the descriptor in bits. 0 -\> Full size + @param descriptor_channels Number of channels in the descriptor (1, 2, 3) + @param threshold Detector response threshold to accept point + @param nOctaves Maximum octave evolution of the image + @param nOctaveLayers Default number of sublevels per scale level + @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or + DIFF_CHARBONNIER + */ + CV_WRAP static Ptr<AKAZE> create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB, + int descriptor_size = 0, int descriptor_channels = 3, + float threshold = 0.001f, int nOctaves = 4, + int nOctaveLayers = 4, int diffusivity = KAZE::DIFF_PM_G2); + + CV_WRAP virtual void setDescriptorType(int dtype) = 0; + CV_WRAP virtual int getDescriptorType() const = 0; + + CV_WRAP virtual void setDescriptorSize(int dsize) = 0; + CV_WRAP virtual int getDescriptorSize() const = 0; + + CV_WRAP virtual void setDescriptorChannels(int dch) = 0; + CV_WRAP virtual int getDescriptorChannels() const = 0; + + CV_WRAP virtual void setThreshold(double threshold) = 0; + CV_WRAP virtual double getThreshold() const = 0; + + CV_WRAP virtual void setNOctaves(int octaves) = 0; + CV_WRAP virtual int getNOctaves() const = 0; + + CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; + CV_WRAP virtual int getNOctaveLayers() const = 0; + + CV_WRAP virtual void setDiffusivity(int diff) = 0; + CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +//! @} features2d_main + +/****************************************************************************************\ +* Distance * +\****************************************************************************************/ + +template<typename T> +struct CV_EXPORTS Accumulator +{ + typedef T Type; +}; + +template<> struct Accumulator<unsigned char> { typedef float Type; }; +template<> struct Accumulator<unsigned short> { typedef float Type; }; +template<> struct Accumulator<char> { typedef float Type; }; +template<> struct Accumulator<short> { typedef float Type; }; + +/* + * Squared Euclidean distance functor + */ +template<class T> +struct CV_EXPORTS SL2 +{ + enum { normType = NORM_L2SQR }; + typedef T ValueType; + typedef typename Accumulator<T>::Type ResultType; + + ResultType operator()( const T* a, const T* b, int size ) const + { + return normL2Sqr<ValueType, ResultType>(a, b, size); + } +}; + +/* + * Euclidean distance functor + */ +template<class T> +struct L2 +{ + enum { normType = NORM_L2 }; + typedef T ValueType; + typedef typename Accumulator<T>::Type ResultType; + + ResultType operator()( const T* a, const T* b, int size ) const + { + return (ResultType)std::sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size)); + } +}; + +/* + * Manhattan distance (city block distance) functor + */ +template<class T> +struct L1 +{ + enum { normType = NORM_L1 }; + typedef T ValueType; + typedef typename Accumulator<T>::Type ResultType; + + ResultType operator()( const T* a, const T* b, int size ) const + { + return normL1<ValueType, ResultType>(a, b, size); + } +}; + +/****************************************************************************************\ +* DescriptorMatcher * +\****************************************************************************************/ + +//! @addtogroup features2d_match +//! @{ + +/** @brief Abstract base class for matching keypoint descriptors. + +It has two groups of match methods: for matching descriptors of an image with another image or with +an image set. + */ +class CV_EXPORTS_W DescriptorMatcher : public Algorithm +{ +public: + enum + { + FLANNBASED = 1, + BRUTEFORCE = 2, + BRUTEFORCE_L1 = 3, + BRUTEFORCE_HAMMING = 4, + BRUTEFORCE_HAMMINGLUT = 5, + BRUTEFORCE_SL2 = 6 + }; + virtual ~DescriptorMatcher(); + + /** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor + collection. + + If the collection is not empty, the new descriptors are added to existing train descriptors. + + @param descriptors Descriptors to add. Each descriptors[i] is a set of descriptors from the same + train image. + */ + CV_WRAP virtual void add( InputArrayOfArrays descriptors ); + + /** @brief Returns a constant link to the train descriptor collection trainDescCollection . + */ + CV_WRAP const std::vector<Mat>& getTrainDescriptors() const; + + /** @brief Clears the train descriptor collections. + */ + CV_WRAP virtual void clear() CV_OVERRIDE; + + /** @brief Returns true if there are no train descriptors in the both collections. + */ + CV_WRAP virtual bool empty() const CV_OVERRIDE; + + /** @brief Returns true if the descriptor matcher supports masking permissible matches. + */ + CV_WRAP virtual bool isMaskSupported() const = 0; + + /** @brief Trains a descriptor matcher + + Trains a descriptor matcher (for example, the flann index). In all methods to match, the method + train() is run every time before matching. Some descriptor matchers (for example, BruteForceMatcher) + have an empty implementation of this method. Other matchers really train their inner structures (for + example, FlannBasedMatcher trains flann::Index ). + */ + CV_WRAP virtual void train(); + + /** @brief Finds the best match for each descriptor from a query set. + + @param queryDescriptors Query set of descriptors. + @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors + collection stored in the class object. + @param matches Matches. If a query descriptor is masked out in mask , no match is added for this + descriptor. So, matches size may be smaller than the query descriptors count. + @param mask Mask specifying permissible matches between an input query and train matrices of + descriptors. + + In the first variant of this method, the train descriptors are passed as an input argument. In the + second variant of the method, train descriptors collection that was set by DescriptorMatcher::add is + used. Optional mask (or masks) can be passed to specify which query and training descriptors can be + matched. Namely, queryDescriptors[i] can be matched with trainDescriptors[j] only if + mask.at\<uchar\>(i,j) is non-zero. + */ + CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector<DMatch>& matches, InputArray mask=noArray() ) const; + + /** @brief Finds the k best matches for each descriptor from a query set. + + @param queryDescriptors Query set of descriptors. + @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors + collection stored in the class object. + @param mask Mask specifying permissible matches between an input query and train matrices of + descriptors. + @param matches Matches. Each matches[i] is k or less matches for the same query descriptor. + @param k Count of best matches found per each query descriptor or less if a query descriptor has + less than k possible matches in total. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + + These extended variants of DescriptorMatcher::match methods find several best matches for each query + descriptor. The matches are returned in the distance increasing order. See DescriptorMatcher::match + for the details about query and train descriptors. + */ + CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector<std::vector<DMatch> >& matches, int k, + InputArray mask=noArray(), bool compactResult=false ) const; + + /** @brief For each query descriptor, finds the training descriptors not farther than the specified distance. + + @param queryDescriptors Query set of descriptors. + @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors + collection stored in the class object. + @param matches Found matches. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + @param maxDistance Threshold for the distance between matched descriptors. Distance means here + metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured + in Pixels)! + @param mask Mask specifying permissible matches between an input query and train matrices of + descriptors. + + For each query descriptor, the methods find such training descriptors that the distance between the + query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are + returned in the distance increasing order. + */ + CV_WRAP void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance, + InputArray mask=noArray(), bool compactResult=false ) const; + + /** @overload + @param queryDescriptors Query set of descriptors. + @param matches Matches. If a query descriptor is masked out in mask , no match is added for this + descriptor. So, matches size may be smaller than the query descriptors count. + @param masks Set of masks. Each masks[i] specifies permissible matches between the input query + descriptors and stored train descriptors from the i-th image trainDescCollection[i]. + */ + CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector<DMatch>& matches, + InputArrayOfArrays masks=noArray() ); + /** @overload + @param queryDescriptors Query set of descriptors. + @param matches Matches. Each matches[i] is k or less matches for the same query descriptor. + @param k Count of best matches found per each query descriptor or less if a query descriptor has + less than k possible matches in total. + @param masks Set of masks. Each masks[i] specifies permissible matches between the input query + descriptors and stored train descriptors from the i-th image trainDescCollection[i]. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + */ + CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ); + /** @overload + @param queryDescriptors Query set of descriptors. + @param matches Found matches. + @param maxDistance Threshold for the distance between matched descriptors. Distance means here + metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured + in Pixels)! + @param masks Set of masks. Each masks[i] specifies permissible matches between the input query + descriptors and stored train descriptors from the i-th image trainDescCollection[i]. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + */ + CV_WRAP void radiusMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ); + + + CV_WRAP void write( const String& fileName ) const + { + FileStorage fs(fileName, FileStorage::WRITE); + write(fs); + } + + CV_WRAP void read( const String& fileName ) + { + FileStorage fs(fileName, FileStorage::READ); + read(fs.root()); + } + // Reads matcher object from a file node + // see corresponding cv::Algorithm method + CV_WRAP virtual void read( const FileNode& ) CV_OVERRIDE; + // Writes matcher object to a file storage + virtual void write( FileStorage& ) const CV_OVERRIDE; + + /** @brief Clones the matcher. + + @param emptyTrainData If emptyTrainData is false, the method creates a deep copy of the object, + that is, copies both parameters and train data. If emptyTrainData is true, the method creates an + object copy with the current parameters but with empty train data. + */ + CV_WRAP virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const = 0; + + /** @brief Creates a descriptor matcher of a given type with the default parameters (using default + constructor). + + @param descriptorMatcherType Descriptor matcher type. Now the following matcher types are + supported: + - `BruteForce` (it uses L2 ) + - `BruteForce-L1` + - `BruteForce-Hamming` + - `BruteForce-Hamming(2)` + - `FlannBased` + */ + CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType ); + + CV_WRAP static Ptr<DescriptorMatcher> create( int matcherType ); + + + // see corresponding cv::Algorithm method + CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) const { Algorithm::write(fs, name); } + +protected: + /** + * Class to work with descriptors from several images as with one merged matrix. + * It is used e.g. in FlannBasedMatcher. + */ + class CV_EXPORTS DescriptorCollection + { + public: + DescriptorCollection(); + DescriptorCollection( const DescriptorCollection& collection ); + virtual ~DescriptorCollection(); + + // Vector of matrices "descriptors" will be merged to one matrix "mergedDescriptors" here. + void set( const std::vector<Mat>& descriptors ); + virtual void clear(); + + const Mat& getDescriptors() const; + const Mat getDescriptor( int imgIdx, int localDescIdx ) const; + const Mat getDescriptor( int globalDescIdx ) const; + void getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const; + + int size() const; + + protected: + Mat mergedDescriptors; + std::vector<int> startIdxs; + }; + + //! In fact the matching is implemented only by the following two methods. These methods suppose + //! that the class object has been trained already. Public match methods call these methods + //! after calling train(). + virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0; + virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0; + + static bool isPossibleMatch( InputArray mask, int queryIdx, int trainIdx ); + static bool isMaskedOut( InputArrayOfArrays masks, int queryIdx ); + + static Mat clone_op( Mat m ) { return m.clone(); } + void checkMasks( InputArrayOfArrays masks, int queryDescriptorsCount ) const; + + //! Collection of descriptors from train images. + std::vector<Mat> trainDescCollection; + std::vector<UMat> utrainDescCollection; +}; + +/** @brief Brute-force descriptor matcher. + +For each descriptor in the first set, this matcher finds the closest descriptor in the second set +by trying each one. This descriptor matcher supports masking permissible matches of descriptor +sets. + */ +class CV_EXPORTS_W BFMatcher : public DescriptorMatcher +{ +public: + /** @brief Brute-force matcher constructor (obsolete). Please use BFMatcher.create() + * + * + */ + CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false ); + + virtual ~BFMatcher() {} + + virtual bool isMaskSupported() const CV_OVERRIDE { return true; } + + /** @brief Brute-force matcher create method. + @param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are + preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and + BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor + description). + @param crossCheck If it is false, this is will be default BFMatcher behaviour when it finds the k + nearest neighbors for each query descriptor. If crossCheck==true, then the knnMatch() method with + k=1 will only return pairs (i,j) such that for i-th query descriptor the j-th descriptor in the + matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent + pairs. Such technique usually produces best results with minimal number of outliers when there are + enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper. + */ + CV_WRAP static Ptr<BFMatcher> create( int normType=NORM_L2, bool crossCheck=false ) ; + + virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const CV_OVERRIDE; +protected: + virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + + int normType; + bool crossCheck; +}; + +#if defined(HAVE_OPENCV_FLANN) || defined(CV_DOXYGEN) + +/** @brief Flann-based descriptor matcher. + +This matcher trains cv::flann::Index on a train descriptor collection and calls its nearest search +methods to find the best matches. So, this matcher may be faster when matching a large train +collection than the brute force matcher. FlannBasedMatcher does not support masking permissible +matches of descriptor sets because flann::Index does not support this. : + */ +class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher +{ +public: + CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(), + const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() ); + + virtual void add( InputArrayOfArrays descriptors ) CV_OVERRIDE; + virtual void clear() CV_OVERRIDE; + + // Reads matcher object from a file node + virtual void read( const FileNode& ) CV_OVERRIDE; + // Writes matcher object to a file storage + virtual void write( FileStorage& ) const CV_OVERRIDE; + + virtual void train() CV_OVERRIDE; + virtual bool isMaskSupported() const CV_OVERRIDE; + + CV_WRAP static Ptr<FlannBasedMatcher> create(); + + virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const CV_OVERRIDE; +protected: + static void convertToDMatches( const DescriptorCollection& descriptors, + const Mat& indices, const Mat& distances, + std::vector<std::vector<DMatch> >& matches ); + + virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + + Ptr<flann::IndexParams> indexParams; + Ptr<flann::SearchParams> searchParams; + Ptr<flann::Index> flannIndex; + + DescriptorCollection mergedDescriptors; + int addedDescCount; +}; + +#endif + +//! @} features2d_match + +/****************************************************************************************\ +* Drawing functions * +\****************************************************************************************/ + +//! @addtogroup features2d_draw +//! @{ + +struct CV_EXPORTS DrawMatchesFlags +{ + enum{ DEFAULT = 0, //!< Output image matrix will be created (Mat::create), + //!< i.e. existing memory of output image may be reused. + //!< Two source image, matches and single keypoints will be drawn. + //!< For each keypoint only the center point will be drawn (without + //!< the circle around keypoint with keypoint size and orientation). + DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create). + //!< Matches will be drawn on existing content of output image. + NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn. + DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and + //!< orientation will be drawn. + }; +}; + +/** @brief Draws keypoints. + +@param image Source image. +@param keypoints Keypoints from the source image. +@param outImage Output image. Its content depends on the flags value defining what is drawn in the +output image. See possible flags bit values below. +@param color Color of keypoints. +@param flags Flags setting drawing features. Possible flags bit values are defined by +DrawMatchesFlags. See details above in drawMatches . + +@note +For Python API, flags are modified as cv2.DRAW_MATCHES_FLAGS_DEFAULT, +cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS, cv2.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG, +cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS + */ +CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage, + const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT ); + +/** @brief Draws the found matches of keypoints from two images. + +@param img1 First source image. +@param keypoints1 Keypoints from the first source image. +@param img2 Second source image. +@param keypoints2 Keypoints from the second source image. +@param matches1to2 Matches from the first image to the second one, which means that keypoints1[i] +has a corresponding point in keypoints2[matches[i]] . +@param outImg Output image. Its content depends on the flags value defining what is drawn in the +output image. See possible flags bit values below. +@param matchColor Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1) +, the color is generated randomly. +@param singlePointColor Color of single keypoints (circles), which means that keypoints do not +have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly. +@param matchesMask Mask determining which matches are drawn. If the mask is empty, all matches are +drawn. +@param flags Flags setting drawing features. Possible flags bit values are defined by +DrawMatchesFlags. + +This function draws matches of keypoints from two images in the output image. Match is a line +connecting two keypoints (circles). See cv::DrawMatchesFlags. + */ +CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1, + InputArray img2, const std::vector<KeyPoint>& keypoints2, + const std::vector<DMatch>& matches1to2, InputOutputArray outImg, + const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), + const std::vector<char>& matchesMask=std::vector<char>(), int flags=DrawMatchesFlags::DEFAULT ); + +/** @overload */ +CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1, + InputArray img2, const std::vector<KeyPoint>& keypoints2, + const std::vector<std::vector<DMatch> >& matches1to2, InputOutputArray outImg, + const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), + const std::vector<std::vector<char> >& matchesMask=std::vector<std::vector<char> >(), int flags=DrawMatchesFlags::DEFAULT ); + +//! @} features2d_draw + +/****************************************************************************************\ +* Functions to evaluate the feature detectors and [generic] descriptor extractors * +\****************************************************************************************/ + +CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2, + std::vector<KeyPoint>* keypoints1, std::vector<KeyPoint>* keypoints2, + float& repeatability, int& correspCount, + const Ptr<FeatureDetector>& fdetector=Ptr<FeatureDetector>() ); + +CV_EXPORTS void computeRecallPrecisionCurve( const std::vector<std::vector<DMatch> >& matches1to2, + const std::vector<std::vector<uchar> >& correctMatches1to2Mask, + std::vector<Point2f>& recallPrecisionCurve ); + +CV_EXPORTS float getRecall( const std::vector<Point2f>& recallPrecisionCurve, float l_precision ); +CV_EXPORTS int getNearestPoint( const std::vector<Point2f>& recallPrecisionCurve, float l_precision ); + +/****************************************************************************************\ +* Bag of visual words * +\****************************************************************************************/ + +//! @addtogroup features2d_category +//! @{ + +/** @brief Abstract base class for training the *bag of visual words* vocabulary from a set of descriptors. + +For details, see, for example, *Visual Categorization with Bags of Keypoints* by Gabriella Csurka, +Christopher R. Dance, Lixin Fan, Jutta Willamowski, Cedric Bray, 2004. : + */ +class CV_EXPORTS_W BOWTrainer +{ +public: + BOWTrainer(); + virtual ~BOWTrainer(); + + /** @brief Adds descriptors to a training set. + + @param descriptors Descriptors to add to a training set. Each row of the descriptors matrix is a + descriptor. + + The training set is clustered using clustermethod to construct the vocabulary. + */ + CV_WRAP void add( const Mat& descriptors ); + + /** @brief Returns a training set of descriptors. + */ + CV_WRAP const std::vector<Mat>& getDescriptors() const; + + /** @brief Returns the count of all descriptors stored in the training set. + */ + CV_WRAP int descriptorsCount() const; + + CV_WRAP virtual void clear(); + + /** @overload */ + CV_WRAP virtual Mat cluster() const = 0; + + /** @brief Clusters train descriptors. + + @param descriptors Descriptors to cluster. Each row of the descriptors matrix is a descriptor. + Descriptors are not added to the inner train descriptor set. + + The vocabulary consists of cluster centers. So, this method returns the vocabulary. In the first + variant of the method, train descriptors stored in the object are clustered. In the second variant, + input descriptors are clustered. + */ + CV_WRAP virtual Mat cluster( const Mat& descriptors ) const = 0; + +protected: + std::vector<Mat> descriptors; + int size; +}; + +/** @brief kmeans -based class to train visual vocabulary using the *bag of visual words* approach. : + */ +class CV_EXPORTS_W BOWKMeansTrainer : public BOWTrainer +{ +public: + /** @brief The constructor. + + @see cv::kmeans + */ + CV_WRAP BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(), + int attempts=3, int flags=KMEANS_PP_CENTERS ); + virtual ~BOWKMeansTrainer(); + + // Returns trained vocabulary (i.e. cluster centers). + CV_WRAP virtual Mat cluster() const CV_OVERRIDE; + CV_WRAP virtual Mat cluster( const Mat& descriptors ) const CV_OVERRIDE; + +protected: + + int clusterCount; + TermCriteria termcrit; + int attempts; + int flags; +}; + +/** @brief Class to compute an image descriptor using the *bag of visual words*. + +Such a computation consists of the following steps: + +1. Compute descriptors for a given image and its keypoints set. +2. Find the nearest visual words from the vocabulary for each keypoint descriptor. +3. Compute the bag-of-words image descriptor as is a normalized histogram of vocabulary words +encountered in the image. The i-th bin of the histogram is a frequency of i-th word of the +vocabulary in the given image. + */ +class CV_EXPORTS_W BOWImgDescriptorExtractor +{ +public: + /** @brief The constructor. + + @param dextractor Descriptor extractor that is used to compute descriptors for an input image and + its keypoints. + @param dmatcher Descriptor matcher that is used to find the nearest word of the trained vocabulary + for each keypoint descriptor of the image. + */ + CV_WRAP BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor, + const Ptr<DescriptorMatcher>& dmatcher ); + /** @overload */ + BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher ); + virtual ~BOWImgDescriptorExtractor(); + + /** @brief Sets a visual vocabulary. + + @param vocabulary Vocabulary (can be trained using the inheritor of BOWTrainer ). Each row of the + vocabulary is a visual word (cluster center). + */ + CV_WRAP void setVocabulary( const Mat& vocabulary ); + + /** @brief Returns the set vocabulary. + */ + CV_WRAP const Mat& getVocabulary() const; + + /** @brief Computes an image descriptor using the set visual vocabulary. + + @param image Image, for which the descriptor is computed. + @param keypoints Keypoints detected in the input image. + @param imgDescriptor Computed output image descriptor. + @param pointIdxsOfClusters Indices of keypoints that belong to the cluster. This means that + pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary) + returned if it is non-zero. + @param descriptors Descriptors of the image keypoints that are returned if they are non-zero. + */ + void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray imgDescriptor, + std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 ); + /** @overload + @param keypointDescriptors Computed descriptors to match with vocabulary. + @param imgDescriptor Computed output image descriptor. + @param pointIdxsOfClusters Indices of keypoints that belong to the cluster. This means that + pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary) + returned if it is non-zero. + */ + void compute( InputArray keypointDescriptors, OutputArray imgDescriptor, + std::vector<std::vector<int> >* pointIdxsOfClusters=0 ); + // compute() is not constant because DescriptorMatcher::match is not constant + + CV_WRAP_AS(compute) void compute2( const Mat& image, std::vector<KeyPoint>& keypoints, CV_OUT Mat& imgDescriptor ) + { compute(image,keypoints,imgDescriptor); } + + /** @brief Returns an image descriptor size if the vocabulary is set. Otherwise, it returns 0. + */ + CV_WRAP int descriptorSize() const; + + /** @brief Returns an image descriptor type. + */ + CV_WRAP int descriptorType() const; + +protected: + Mat vocabulary; + Ptr<DescriptorExtractor> dextractor; + Ptr<DescriptorMatcher> dmatcher; +}; + +//! @} features2d_category + +//! @} features2d + +} /* namespace cv */ + +#endif diff --git a/include/opencv2/features2d/features2d.hpp b/include/opencv2/features2d/features2d.hpp new file mode 100644 index 0000000..e81df0a --- /dev/null +++ b/include/opencv2/features2d/features2d.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/features2d.hpp" diff --git a/include/opencv2/features2d/hal/interface.h b/include/opencv2/features2d/hal/interface.h new file mode 100644 index 0000000..bcc6577 --- /dev/null +++ b/include/opencv2/features2d/hal/interface.h @@ -0,0 +1,33 @@ +#ifndef OPENCV_FEATURE2D_HAL_INTERFACE_H +#define OPENCV_FEATURE2D_HAL_INTERFACE_H + +#include "opencv2/core/cvdef.h" +//! @addtogroup featrure2d_hal_interface +//! @{ + +//! @name Fast feature detector types +//! @sa cv::FastFeatureDetector +//! @{ +#define CV_HAL_TYPE_5_8 0 +#define CV_HAL_TYPE_7_12 1 +#define CV_HAL_TYPE_9_16 2 +//! @} + +//! @name Key point +//! @sa cv::KeyPoint +//! @{ +struct CV_EXPORTS cvhalKeyPoint +{ + float x; + float y; + float size; + float angle; + float response; + int octave; + int class_id; +}; +//! @} + +//! @} + +#endif diff --git a/include/opencv2/flann.hpp b/include/opencv2/flann.hpp new file mode 100644 index 0000000..fec3d06 --- /dev/null +++ b/include/opencv2/flann.hpp @@ -0,0 +1,594 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_FLANN_HPP +#define OPENCV_FLANN_HPP + +#include "opencv2/core.hpp" +#include "opencv2/flann/miniflann.hpp" +#include "opencv2/flann/flann_base.hpp" + +/** +@defgroup flann Clustering and Search in Multi-Dimensional Spaces + +This section documents OpenCV's interface to the FLANN library. FLANN (Fast Library for Approximate +Nearest Neighbors) is a library that contains a collection of algorithms optimized for fast nearest +neighbor search in large datasets and for high dimensional features. More information about FLANN +can be found in @cite Muja2009 . +*/ + +namespace cvflann +{ + CV_EXPORTS flann_distance_t flann_distance_type(); + CV_DEPRECATED CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order); +} + + +namespace cv +{ +namespace flann +{ + + +//! @addtogroup flann +//! @{ + +template <typename T> struct CvType {}; +template <> struct CvType<unsigned char> { static int type() { return CV_8U; } }; +template <> struct CvType<char> { static int type() { return CV_8S; } }; +template <> struct CvType<unsigned short> { static int type() { return CV_16U; } }; +template <> struct CvType<short> { static int type() { return CV_16S; } }; +template <> struct CvType<int> { static int type() { return CV_32S; } }; +template <> struct CvType<float> { static int type() { return CV_32F; } }; +template <> struct CvType<double> { static int type() { return CV_64F; } }; + + +// bring the flann parameters into this namespace +using ::cvflann::get_param; +using ::cvflann::print_params; + +// bring the flann distances into this namespace +using ::cvflann::L2_Simple; +using ::cvflann::L2; +using ::cvflann::L1; +using ::cvflann::MinkowskiDistance; +using ::cvflann::MaxDistance; +using ::cvflann::HammingLUT; +using ::cvflann::Hamming; +using ::cvflann::Hamming2; +using ::cvflann::HistIntersectionDistance; +using ::cvflann::HellingerDistance; +using ::cvflann::ChiSquareDistance; +using ::cvflann::KL_Divergence; + + +/** @brief The FLANN nearest neighbor index class. This class is templated with the type of elements for which +the index is built. + +`Distance` functor specifies the metric to be used to calculate the distance between two points. +There are several `Distance` functors that are readily available: + +@link cvflann::L2_Simple cv::flann::L2_Simple @endlink- Squared Euclidean distance functor. +This is the simpler, unrolled version. This is preferable for very low dimensionality data (eg 3D points) + +@link cvflann::L2 cv::flann::L2 @endlink- Squared Euclidean distance functor, optimized version. + +@link cvflann::L1 cv::flann::L1 @endlink - Manhattan distance functor, optimized version. + +@link cvflann::MinkowskiDistance cv::flann::MinkowskiDistance @endlink - The Minkowsky distance functor. +This is highly optimised with loop unrolling. +The computation of squared root at the end is omitted for efficiency. + +@link cvflann::MaxDistance cv::flann::MaxDistance @endlink - The max distance functor. It computes the +maximum distance between two vectors. This distance is not a valid kdtree distance, it's not +dimensionwise additive. + +@link cvflann::HammingLUT cv::flann::HammingLUT @endlink - %Hamming distance functor. It counts the bit +differences between two strings using a lookup table implementation. + +@link cvflann::Hamming cv::flann::Hamming @endlink - %Hamming distance functor. Population count is +performed using library calls, if available. Lookup table implementation is used as a fallback. + +@link cvflann::Hamming2 cv::flann::Hamming2 @endlink- %Hamming distance functor. Population count is +implemented in 12 arithmetic operations (one of which is multiplication). + +@link cvflann::HistIntersectionDistance cv::flann::HistIntersectionDistance @endlink - The histogram +intersection distance functor. + +@link cvflann::HellingerDistance cv::flann::HellingerDistance @endlink - The Hellinger distance functor. + +@link cvflann::ChiSquareDistance cv::flann::ChiSquareDistance @endlink - The chi-square distance functor. + +@link cvflann::KL_Divergence cv::flann::KL_Divergence @endlink - The Kullback-Leibler divergence functor. + +Although the provided implementations cover a vast range of cases, it is also possible to use +a custom implementation. The distance functor is a class whose `operator()` computes the distance +between two features. If the distance is also a kd-tree compatible distance, it should also provide an +`accum_dist()` method that computes the distance between individual feature dimensions. + +In addition to `operator()` and `accum_dist()`, a distance functor should also define the +`ElementType` and the `ResultType` as the types of the elements it operates on and the type of the +result it computes. If a distance functor can be used as a kd-tree distance (meaning that the full +distance between a pair of features can be accumulated from the partial distances between the +individual dimensions) a typedef `is_kdtree_distance` should be present inside the distance functor. +If the distance is not a kd-tree distance, but it's a distance in a vector space (the individual +dimensions of the elements it operates on can be accessed independently) a typedef +`is_vector_space_distance` should be defined inside the functor. If neither typedef is defined, the +distance is assumed to be a metric distance and will only be used with indexes operating on +generic metric distances. + */ +template <typename Distance> +class GenericIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + /** @brief Constructs a nearest neighbor search index for a given dataset. + + @param features Matrix of containing the features(points) to index. The size of the matrix is + num_features x feature_dimensionality and the data type of the elements in the matrix must + coincide with the type of the index. + @param params Structure containing the index parameters. The type of index that will be + constructed depends on the type of this parameter. See the description. + @param distance + + The method constructs a fast search structure from a set of features using the specified algorithm + with specified parameters, as defined by params. params is a reference to one of the following class + IndexParams descendants: + + - **LinearIndexParams** When passing an object of this type, the index will perform a linear, + brute-force search. : + @code + struct LinearIndexParams : public IndexParams + { + }; + @endcode + - **KDTreeIndexParams** When passing an object of this type the index constructed will consist of + a set of randomized kd-trees which will be searched in parallel. : + @code + struct KDTreeIndexParams : public IndexParams + { + KDTreeIndexParams( int trees = 4 ); + }; + @endcode + - **KMeansIndexParams** When passing an object of this type the index constructed will be a + hierarchical k-means tree. : + @code + struct KMeansIndexParams : public IndexParams + { + KMeansIndexParams( + int branching = 32, + int iterations = 11, + flann_centers_init_t centers_init = CENTERS_RANDOM, + float cb_index = 0.2 ); + }; + @endcode + - **CompositeIndexParams** When using a parameters object of this type the index created + combines the randomized kd-trees and the hierarchical k-means tree. : + @code + struct CompositeIndexParams : public IndexParams + { + CompositeIndexParams( + int trees = 4, + int branching = 32, + int iterations = 11, + flann_centers_init_t centers_init = CENTERS_RANDOM, + float cb_index = 0.2 ); + }; + @endcode + - **LshIndexParams** When using a parameters object of this type the index created uses + multi-probe LSH (by Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search + by Qin Lv, William Josephson, Zhe Wang, Moses Charikar, Kai Li., Proceedings of the 33rd + International Conference on Very Large Data Bases (VLDB). Vienna, Austria. September 2007) : + @code + struct LshIndexParams : public IndexParams + { + LshIndexParams( + unsigned int table_number, + unsigned int key_size, + unsigned int multi_probe_level ); + }; + @endcode + - **AutotunedIndexParams** When passing an object of this type the index created is + automatically tuned to offer the best performance, by choosing the optimal index type + (randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. : + @code + struct AutotunedIndexParams : public IndexParams + { + AutotunedIndexParams( + float target_precision = 0.9, + float build_weight = 0.01, + float memory_weight = 0, + float sample_fraction = 0.1 ); + }; + @endcode + - **SavedIndexParams** This object type is used for loading a previously saved index from the + disk. : + @code + struct SavedIndexParams : public IndexParams + { + SavedIndexParams( String filename ); + }; + @endcode + */ + GenericIndex(const Mat& features, const ::cvflann::IndexParams& params, Distance distance = Distance()); + + ~GenericIndex(); + + /** @brief Performs a K-nearest neighbor search for a given query point using the index. + + @param query The query point + @param indices Vector that will contain the indices of the K-nearest neighbors found. It must have + at least knn size. + @param dists Vector that will contain the distances to the K-nearest neighbors found. It must have + at least knn size. + @param knn Number of nearest neighbors to search for. + @param params SearchParams + */ + void knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, + std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params); + void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params); + + /** @brief Performs a radius nearest neighbor search for a given query point using the index. + + @param query The query point. + @param indices Vector that will contain the indices of the nearest neighbors found. + @param dists Vector that will contain the distances to the nearest neighbors found. It has the same + number of elements as indices. + @param radius The search radius. + @param params SearchParams + + This function returns the number of nearest neighbors found. + */ + int radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, + std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params); + int radiusSearch(const Mat& query, Mat& indices, Mat& dists, + DistanceType radius, const ::cvflann::SearchParams& params); + + void save(String filename) { nnIndex->save(filename); } + + int veclen() const { return nnIndex->veclen(); } + + int size() const { return nnIndex->size(); } + + ::cvflann::IndexParams getParameters() { return nnIndex->getParameters(); } + + CV_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() { return nnIndex->getIndexParameters(); } + +private: + ::cvflann::Index<Distance>* nnIndex; +}; + +//! @cond IGNORED + +#define FLANN_DISTANCE_CHECK \ + if ( ::cvflann::flann_distance_type() != cvflann::FLANN_DIST_L2) { \ + printf("[WARNING] You are using cv::flann::Index (or cv::flann::GenericIndex) and have also changed "\ + "the distance using cvflann::set_distance_type. This is no longer working as expected "\ + "(cv::flann::Index always uses L2). You should create the index templated on the distance, "\ + "for example for L1 distance use: GenericIndex< L1<float> > \n"); \ + } + + +template <typename Distance> +GenericIndex<Distance>::GenericIndex(const Mat& dataset, const ::cvflann::IndexParams& params, Distance distance) +{ + CV_Assert(dataset.type() == CvType<ElementType>::type()); + CV_Assert(dataset.isContinuous()); + ::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols); + + nnIndex = new ::cvflann::Index<Distance>(m_dataset, params, distance); + + FLANN_DISTANCE_CHECK + + nnIndex->buildIndex(); +} + +template <typename Distance> +GenericIndex<Distance>::~GenericIndex() +{ + delete nnIndex; +} + +template <typename Distance> +void GenericIndex<Distance>::knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& searchParams) +{ + ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size()); + + FLANN_DISTANCE_CHECK + + nnIndex->knnSearch(m_query,m_indices,m_dists,knn,searchParams); +} + + +template <typename Distance> +void GenericIndex<Distance>::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams) +{ + CV_Assert(queries.type() == CvType<ElementType>::type()); + CV_Assert(queries.isContinuous()); + ::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType<DistanceType>::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols); + + FLANN_DISTANCE_CHECK + + nnIndex->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); +} + +template <typename Distance> +int GenericIndex<Distance>::radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) +{ + ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size()); + + FLANN_DISTANCE_CHECK + + return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); +} + +template <typename Distance> +int GenericIndex<Distance>::radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) +{ + CV_Assert(query.type() == CvType<ElementType>::type()); + CV_Assert(query.isContinuous()); + ::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType<DistanceType>::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols); + + FLANN_DISTANCE_CHECK + + return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); +} + +//! @endcond + +/** + * @deprecated Use GenericIndex class instead + */ +template <typename T> +class Index_ +{ +public: + typedef typename L2<T>::ElementType ElementType; + typedef typename L2<T>::ResultType DistanceType; + + CV_DEPRECATED Index_(const Mat& dataset, const ::cvflann::IndexParams& params) + { + printf("[WARNING] The cv::flann::Index_<T> class is deperecated, use cv::flann::GenericIndex<Distance> instead\n"); + + CV_Assert(dataset.type() == CvType<ElementType>::type()); + CV_Assert(dataset.isContinuous()); + ::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols); + + if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) { + nnIndex_L1 = NULL; + nnIndex_L2 = new ::cvflann::Index< L2<ElementType> >(m_dataset, params); + } + else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) { + nnIndex_L1 = new ::cvflann::Index< L1<ElementType> >(m_dataset, params); + nnIndex_L2 = NULL; + } + else { + printf("[ERROR] cv::flann::Index_<T> only provides backwards compatibility for the L1 and L2 distances. " + "For other distance types you must use cv::flann::GenericIndex<Distance>\n"); + CV_Assert(0); + } + if (nnIndex_L1) nnIndex_L1->buildIndex(); + if (nnIndex_L2) nnIndex_L2->buildIndex(); + } + CV_DEPRECATED ~Index_() + { + if (nnIndex_L1) delete nnIndex_L1; + if (nnIndex_L2) delete nnIndex_L2; + } + + CV_DEPRECATED void knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& searchParams) + { + ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size()); + + if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams); + if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams); + } + CV_DEPRECATED void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams) + { + CV_Assert(queries.type() == CvType<ElementType>::type()); + CV_Assert(queries.isContinuous()); + ::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType<DistanceType>::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols); + + if (nnIndex_L1) nnIndex_L1->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); + if (nnIndex_L2) nnIndex_L2->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); + } + + CV_DEPRECATED int radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) + { + ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size()); + + if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + } + + CV_DEPRECATED int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) + { + CV_Assert(query.type() == CvType<ElementType>::type()); + CV_Assert(query.isContinuous()); + ::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType<DistanceType>::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols); + + if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + } + + CV_DEPRECATED void save(String filename) + { + if (nnIndex_L1) nnIndex_L1->save(filename); + if (nnIndex_L2) nnIndex_L2->save(filename); + } + + CV_DEPRECATED int veclen() const + { + if (nnIndex_L1) return nnIndex_L1->veclen(); + if (nnIndex_L2) return nnIndex_L2->veclen(); + } + + CV_DEPRECATED int size() const + { + if (nnIndex_L1) return nnIndex_L1->size(); + if (nnIndex_L2) return nnIndex_L2->size(); + } + + CV_DEPRECATED ::cvflann::IndexParams getParameters() + { + if (nnIndex_L1) return nnIndex_L1->getParameters(); + if (nnIndex_L2) return nnIndex_L2->getParameters(); + + } + + CV_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() + { + if (nnIndex_L1) return nnIndex_L1->getIndexParameters(); + if (nnIndex_L2) return nnIndex_L2->getIndexParameters(); + } + +private: + // providing backwards compatibility for L2 and L1 distances (most common) + ::cvflann::Index< L2<ElementType> >* nnIndex_L2; + ::cvflann::Index< L1<ElementType> >* nnIndex_L1; +}; + + +/** @brief Clusters features using hierarchical k-means algorithm. + +@param features The points to be clustered. The matrix must have elements of type +Distance::ElementType. +@param centers The centers of the clusters obtained. The matrix must have type +Distance::ResultType. The number of rows in this matrix represents the number of clusters desired, +however, because of the way the cut in the hierarchical tree is chosen, the number of clusters +computed will be the highest number of the form (branching-1)\*k+1 that's lower than the number of +clusters desired, where branching is the tree's branching factor (see description of the +KMeansIndexParams). +@param params Parameters used in the construction of the hierarchical k-means tree. +@param d Distance to be used for clustering. + +The method clusters the given feature vectors by constructing a hierarchical k-means tree and +choosing a cut in the tree that minimizes the cluster's variance. It returns the number of clusters +found. + */ +template <typename Distance> +int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params, + Distance d = Distance()) +{ + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + CV_Assert(features.type() == CvType<ElementType>::type()); + CV_Assert(features.isContinuous()); + ::cvflann::Matrix<ElementType> m_features((ElementType*)features.ptr<ElementType>(0), features.rows, features.cols); + + CV_Assert(centers.type() == CvType<DistanceType>::type()); + CV_Assert(centers.isContinuous()); + ::cvflann::Matrix<DistanceType> m_centers((DistanceType*)centers.ptr<DistanceType>(0), centers.rows, centers.cols); + + return ::cvflann::hierarchicalClustering<Distance>(m_features, m_centers, params, d); +} + +/** @deprecated +*/ +template <typename ELEM_TYPE, typename DIST_TYPE> +CV_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params) +{ + printf("[WARNING] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> is deprecated, use " + "cv::flann::hierarchicalClustering<Distance> instead\n"); + + if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) { + return hierarchicalClustering< L2<ELEM_TYPE> >(features, centers, params); + } + else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) { + return hierarchicalClustering< L1<ELEM_TYPE> >(features, centers, params); + } + else { + printf("[ERROR] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> only provides backwards " + "compatibility for the L1 and L2 distances. " + "For other distance types you must use cv::flann::hierarchicalClustering<Distance>\n"); + CV_Assert(0); + } +} + +//! @} flann + +} } // namespace cv::flann + +#endif diff --git a/include/opencv2/flann/all_indices.h b/include/opencv2/flann/all_indices.h new file mode 100644 index 0000000..ff53fd8 --- /dev/null +++ b/include/opencv2/flann/all_indices.h @@ -0,0 +1,155 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_ALL_INDICES_H_ +#define OPENCV_FLANN_ALL_INDICES_H_ + +#include "general.h" + +#include "nn_index.h" +#include "kdtree_index.h" +#include "kdtree_single_index.h" +#include "kmeans_index.h" +#include "composite_index.h" +#include "linear_index.h" +#include "hierarchical_clustering_index.h" +#include "lsh_index.h" +#include "autotuned_index.h" + + +namespace cvflann +{ + +template<typename KDTreeCapability, typename VectorSpace, typename Distance> +struct index_creator +{ + static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) + { + flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm"); + + NNIndex<Distance>* nnIndex; + switch (index_type) { + case FLANN_INDEX_LINEAR: + nnIndex = new LinearIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_KDTREE_SINGLE: + nnIndex = new KDTreeSingleIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_KDTREE: + nnIndex = new KDTreeIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_KMEANS: + nnIndex = new KMeansIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_COMPOSITE: + nnIndex = new CompositeIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_AUTOTUNED: + nnIndex = new AutotunedIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_HIERARCHICAL: + nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_LSH: + nnIndex = new LshIndex<Distance>(dataset, params, distance); + break; + default: + throw FLANNException("Unknown index type"); + } + + return nnIndex; + } +}; + +template<typename VectorSpace, typename Distance> +struct index_creator<False,VectorSpace,Distance> +{ + static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) + { + flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm"); + + NNIndex<Distance>* nnIndex; + switch (index_type) { + case FLANN_INDEX_LINEAR: + nnIndex = new LinearIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_KMEANS: + nnIndex = new KMeansIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_HIERARCHICAL: + nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_LSH: + nnIndex = new LshIndex<Distance>(dataset, params, distance); + break; + default: + throw FLANNException("Unknown index type"); + } + + return nnIndex; + } +}; + +template<typename Distance> +struct index_creator<False,False,Distance> +{ + static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) + { + flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm"); + + NNIndex<Distance>* nnIndex; + switch (index_type) { + case FLANN_INDEX_LINEAR: + nnIndex = new LinearIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_HIERARCHICAL: + nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance); + break; + case FLANN_INDEX_LSH: + nnIndex = new LshIndex<Distance>(dataset, params, distance); + break; + default: + throw FLANNException("Unknown index type"); + } + + return nnIndex; + } +}; + +template<typename Distance> +NNIndex<Distance>* create_index_by_type(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) +{ + return index_creator<typename Distance::is_kdtree_distance, + typename Distance::is_vector_space_distance, + Distance>::create(dataset, params,distance); +} + +} + +#endif /* OPENCV_FLANN_ALL_INDICES_H_ */ diff --git a/include/opencv2/flann/allocator.h b/include/opencv2/flann/allocator.h new file mode 100644 index 0000000..f347f88 --- /dev/null +++ b/include/opencv2/flann/allocator.h @@ -0,0 +1,192 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_ALLOCATOR_H_ +#define OPENCV_FLANN_ALLOCATOR_H_ + +#include <stdlib.h> +#include <stdio.h> + + +namespace cvflann +{ + +/** + * Allocates (using C's malloc) a generic type T. + * + * Params: + * count = number of instances to allocate. + * Returns: pointer (of type T*) to memory buffer + */ +template <typename T> +T* allocate(size_t count = 1) +{ + T* mem = (T*) ::malloc(sizeof(T)*count); + return mem; +} + + +/** + * Pooled storage allocator + * + * The following routines allow for the efficient allocation of storage in + * small chunks from a specified pool. Rather than allowing each structure + * to be freed individually, an entire pool of storage is freed at once. + * This method has two advantages over just using malloc() and free(). First, + * it is far more efficient for allocating small objects, as there is + * no overhead for remembering all the information needed to free each + * object or consolidating fragmented memory. Second, the decision about + * how long to keep an object is made at the time of allocation, and there + * is no need to track down all the objects to free them. + * + */ + +const size_t WORDSIZE=16; +const size_t BLOCKSIZE=8192; + +class PooledAllocator +{ + /* We maintain memory alignment to word boundaries by requiring that all + allocations be in multiples of the machine wordsize. */ + /* Size of machine word in bytes. Must be power of 2. */ + /* Minimum number of bytes requested at a time from the system. Must be multiple of WORDSIZE. */ + + + int remaining; /* Number of bytes left in current block of storage. */ + void* base; /* Pointer to base of current block of storage. */ + void* loc; /* Current location in block to next allocate memory. */ + int blocksize; + + +public: + int usedMemory; + int wastedMemory; + + /** + Default constructor. Initializes a new pool. + */ + PooledAllocator(int blockSize = BLOCKSIZE) + { + blocksize = blockSize; + remaining = 0; + base = NULL; + loc = NULL; + + usedMemory = 0; + wastedMemory = 0; + } + + /** + * Destructor. Frees all the memory allocated in this pool. + */ + ~PooledAllocator() + { + void* prev; + + while (base != NULL) { + prev = *((void**) base); /* Get pointer to prev block. */ + ::free(base); + base = prev; + } + } + + /** + * Returns a pointer to a piece of new memory of the given size in bytes + * allocated from the pool. + */ + void* allocateMemory(int size) + { + int blockSize; + + /* Round size up to a multiple of wordsize. The following expression + only works for WORDSIZE that is a power of 2, by masking last bits of + incremented size to zero. + */ + size = (size + (WORDSIZE - 1)) & ~(WORDSIZE - 1); + + /* Check whether a new block must be allocated. Note that the first word + of a block is reserved for a pointer to the previous block. + */ + if (size > remaining) { + + wastedMemory += remaining; + + /* Allocate new storage. */ + blockSize = (size + sizeof(void*) + (WORDSIZE-1) > BLOCKSIZE) ? + size + sizeof(void*) + (WORDSIZE-1) : BLOCKSIZE; + + // use the standard C malloc to allocate memory + void* m = ::malloc(blockSize); + if (!m) { + fprintf(stderr,"Failed to allocate memory.\n"); + return NULL; + } + + /* Fill first word of new block with pointer to previous block. */ + ((void**) m)[0] = base; + base = m; + + int shift = 0; + //int shift = (WORDSIZE - ( (((size_t)m) + sizeof(void*)) & (WORDSIZE-1))) & (WORDSIZE-1); + + remaining = blockSize - sizeof(void*) - shift; + loc = ((char*)m + sizeof(void*) + shift); + } + void* rloc = loc; + loc = (char*)loc + size; + remaining -= size; + + usedMemory += size; + + return rloc; + } + + /** + * Allocates (using this pool) a generic type T. + * + * Params: + * count = number of instances to allocate. + * Returns: pointer (of type T*) to memory buffer + */ + template <typename T> + T* allocate(size_t count = 1) + { + T* mem = (T*) this->allocateMemory((int)(sizeof(T)*count)); + return mem; + } + +private: + PooledAllocator(const PooledAllocator &); // copy disabled + PooledAllocator& operator=(const PooledAllocator &); // assign disabled +}; + +} + +#endif //OPENCV_FLANN_ALLOCATOR_H_ diff --git a/include/opencv2/flann/any.h b/include/opencv2/flann/any.h new file mode 100644 index 0000000..5b57aa3 --- /dev/null +++ b/include/opencv2/flann/any.h @@ -0,0 +1,330 @@ +#ifndef OPENCV_FLANN_ANY_H_ +#define OPENCV_FLANN_ANY_H_ +/* + * (C) Copyright Christopher Diggins 2005-2011 + * (C) Copyright Pablo Aguilar 2005 + * (C) Copyright Kevlin Henney 2001 + * + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt + * + * Adapted for FLANN by Marius Muja + */ + +#include "defines.h" +#include <stdexcept> +#include <ostream> +#include <typeinfo> + +namespace cvflann +{ + +namespace anyimpl +{ + +struct bad_any_cast +{ +}; + +struct empty_any +{ +}; + +inline std::ostream& operator <<(std::ostream& out, const empty_any&) +{ + out << "[empty_any]"; + return out; +} + +struct base_any_policy +{ + virtual void static_delete(void** x) = 0; + virtual void copy_from_value(void const* src, void** dest) = 0; + virtual void clone(void* const* src, void** dest) = 0; + virtual void move(void* const* src, void** dest) = 0; + virtual void* get_value(void** src) = 0; + virtual const void* get_value(void* const * src) = 0; + virtual ::size_t get_size() = 0; + virtual const std::type_info& type() = 0; + virtual void print(std::ostream& out, void* const* src) = 0; + virtual ~base_any_policy() {} +}; + +template<typename T> +struct typed_base_any_policy : base_any_policy +{ + virtual ::size_t get_size() CV_OVERRIDE { return sizeof(T); } + virtual const std::type_info& type() CV_OVERRIDE { return typeid(T); } + +}; + +template<typename T> +struct small_any_policy CV_FINAL : typed_base_any_policy<T> +{ + virtual void static_delete(void**) CV_OVERRIDE { } + virtual void copy_from_value(void const* src, void** dest) CV_OVERRIDE + { + new (dest) T(* reinterpret_cast<T const*>(src)); + } + virtual void clone(void* const* src, void** dest) CV_OVERRIDE { *dest = *src; } + virtual void move(void* const* src, void** dest) CV_OVERRIDE { *dest = *src; } + virtual void* get_value(void** src) CV_OVERRIDE { return reinterpret_cast<void*>(src); } + virtual const void* get_value(void* const * src) CV_OVERRIDE { return reinterpret_cast<const void*>(src); } + virtual void print(std::ostream& out, void* const* src) CV_OVERRIDE { out << *reinterpret_cast<T const*>(src); } +}; + +template<typename T> +struct big_any_policy CV_FINAL : typed_base_any_policy<T> +{ + virtual void static_delete(void** x) CV_OVERRIDE + { + if (* x) delete (* reinterpret_cast<T**>(x)); + *x = NULL; + } + virtual void copy_from_value(void const* src, void** dest) CV_OVERRIDE + { + *dest = new T(*reinterpret_cast<T const*>(src)); + } + virtual void clone(void* const* src, void** dest) CV_OVERRIDE + { + *dest = new T(**reinterpret_cast<T* const*>(src)); + } + virtual void move(void* const* src, void** dest) CV_OVERRIDE + { + (*reinterpret_cast<T**>(dest))->~T(); + **reinterpret_cast<T**>(dest) = **reinterpret_cast<T* const*>(src); + } + virtual void* get_value(void** src) CV_OVERRIDE { return *src; } + virtual const void* get_value(void* const * src) CV_OVERRIDE { return *src; } + virtual void print(std::ostream& out, void* const* src) CV_OVERRIDE { out << *reinterpret_cast<T const*>(*src); } +}; + +template<> inline void big_any_policy<flann_centers_init_t>::print(std::ostream& out, void* const* src) +{ + out << int(*reinterpret_cast<flann_centers_init_t const*>(*src)); +} + +template<> inline void big_any_policy<flann_algorithm_t>::print(std::ostream& out, void* const* src) +{ + out << int(*reinterpret_cast<flann_algorithm_t const*>(*src)); +} + +template<> inline void big_any_policy<cv::String>::print(std::ostream& out, void* const* src) +{ + out << (*reinterpret_cast<cv::String const*>(*src)).c_str(); +} + +template<typename T> +struct choose_policy +{ + typedef big_any_policy<T> type; +}; + +template<typename T> +struct choose_policy<T*> +{ + typedef small_any_policy<T*> type; +}; + +struct any; + +/// Choosing the policy for an any type is illegal, but should never happen. +/// This is designed to throw a compiler error. +template<> +struct choose_policy<any> +{ + typedef void type; +}; + +/// Specializations for small types. +#define SMALL_POLICY(TYPE) \ + template<> \ + struct choose_policy<TYPE> { typedef small_any_policy<TYPE> type; \ + } + +SMALL_POLICY(signed char); +SMALL_POLICY(unsigned char); +SMALL_POLICY(signed short); +SMALL_POLICY(unsigned short); +SMALL_POLICY(signed int); +SMALL_POLICY(unsigned int); +SMALL_POLICY(signed long); +SMALL_POLICY(unsigned long); +SMALL_POLICY(float); +SMALL_POLICY(bool); + +#undef SMALL_POLICY + +template <typename T> +class SinglePolicy +{ + SinglePolicy(); + SinglePolicy(const SinglePolicy& other); + SinglePolicy& operator=(const SinglePolicy& other); + +public: + static base_any_policy* get_policy(); + +private: + static typename choose_policy<T>::type policy; +}; + +template <typename T> +typename choose_policy<T>::type SinglePolicy<T>::policy; + +/// This function will return a different policy for each type. +template <typename T> +inline base_any_policy* SinglePolicy<T>::get_policy() { return &policy; } + +} // namespace anyimpl + +struct any +{ +private: + // fields + anyimpl::base_any_policy* policy; + void* object; + +public: + /// Initializing constructor. + template <typename T> + any(const T& x) + : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL) + { + assign(x); + } + + /// Empty constructor. + any() + : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL) + { } + + /// Special initializing constructor for string literals. + any(const char* x) + : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL) + { + assign(x); + } + + /// Copy constructor. + any(const any& x) + : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL) + { + assign(x); + } + + /// Destructor. + ~any() + { + policy->static_delete(&object); + } + + /// Assignment function from another any. + any& assign(const any& x) + { + reset(); + policy = x.policy; + policy->clone(&x.object, &object); + return *this; + } + + /// Assignment function. + template <typename T> + any& assign(const T& x) + { + reset(); + policy = anyimpl::SinglePolicy<T>::get_policy(); + policy->copy_from_value(&x, &object); + return *this; + } + + /// Assignment operator. + template<typename T> + any& operator=(const T& x) + { + return assign(x); + } + + /// Assignment operator. Template-based version above doesn't work as expected. We need regular assignment operator here. + any& operator=(const any& x) + { + return assign(x); + } + + /// Assignment operator, specialed for literal strings. + /// They have types like const char [6] which don't work as expected. + any& operator=(const char* x) + { + return assign(x); + } + + /// Utility functions + any& swap(any& x) + { + std::swap(policy, x.policy); + std::swap(object, x.object); + return *this; + } + + /// Cast operator. You can only cast to the original type. + template<typename T> + T& cast() + { + if (policy->type() != typeid(T)) throw anyimpl::bad_any_cast(); + T* r = reinterpret_cast<T*>(policy->get_value(&object)); + return *r; + } + + /// Cast operator. You can only cast to the original type. + template<typename T> + const T& cast() const + { + if (policy->type() != typeid(T)) throw anyimpl::bad_any_cast(); + const T* r = reinterpret_cast<const T*>(policy->get_value(&object)); + return *r; + } + + /// Returns true if the any contains no value. + bool empty() const + { + return policy->type() == typeid(anyimpl::empty_any); + } + + /// Frees any allocated memory, and sets the value to NULL. + void reset() + { + policy->static_delete(&object); + policy = anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy(); + } + + /// Returns true if the two types are the same. + bool compatible(const any& x) const + { + return policy->type() == x.policy->type(); + } + + /// Returns if the type is compatible with the policy + template<typename T> + bool has_type() + { + return policy->type() == typeid(T); + } + + const std::type_info& type() const + { + return policy->type(); + } + + friend std::ostream& operator <<(std::ostream& out, const any& any_val); +}; + +inline std::ostream& operator <<(std::ostream& out, const any& any_val) +{ + any_val.policy->print(out,&any_val.object); + return out; +} + +} + +#endif // OPENCV_FLANN_ANY_H_ diff --git a/include/opencv2/flann/autotuned_index.h b/include/opencv2/flann/autotuned_index.h new file mode 100644 index 0000000..2fbc6c9 --- /dev/null +++ b/include/opencv2/flann/autotuned_index.h @@ -0,0 +1,591 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ +#ifndef OPENCV_FLANN_AUTOTUNED_INDEX_H_ +#define OPENCV_FLANN_AUTOTUNED_INDEX_H_ + +#include <sstream> + +#include "general.h" +#include "nn_index.h" +#include "ground_truth.h" +#include "index_testing.h" +#include "sampling.h" +#include "kdtree_index.h" +#include "kdtree_single_index.h" +#include "kmeans_index.h" +#include "composite_index.h" +#include "linear_index.h" +#include "logger.h" + +namespace cvflann +{ + +template<typename Distance> +NNIndex<Distance>* create_index_by_type(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance); + + +struct AutotunedIndexParams : public IndexParams +{ + AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01, float memory_weight = 0, float sample_fraction = 0.1) + { + (*this)["algorithm"] = FLANN_INDEX_AUTOTUNED; + // precision desired (used for autotuning, -1 otherwise) + (*this)["target_precision"] = target_precision; + // build tree time weighting factor + (*this)["build_weight"] = build_weight; + // index memory weighting factor + (*this)["memory_weight"] = memory_weight; + // what fraction of the dataset to use for autotuning + (*this)["sample_fraction"] = sample_fraction; + } +}; + + +template <typename Distance> +class AutotunedIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + AutotunedIndex(const Matrix<ElementType>& inputData, const IndexParams& params = AutotunedIndexParams(), Distance d = Distance()) : + dataset_(inputData), distance_(d) + { + target_precision_ = get_param(params, "target_precision",0.8f); + build_weight_ = get_param(params,"build_weight", 0.01f); + memory_weight_ = get_param(params, "memory_weight", 0.0f); + sample_fraction_ = get_param(params,"sample_fraction", 0.1f); + bestIndex_ = NULL; + speedup_ = 0; + } + + AutotunedIndex(const AutotunedIndex&); + AutotunedIndex& operator=(const AutotunedIndex&); + + virtual ~AutotunedIndex() + { + if (bestIndex_ != NULL) { + delete bestIndex_; + bestIndex_ = NULL; + } + } + + /** + * Method responsible with building the index. + */ + virtual void buildIndex() CV_OVERRIDE + { + std::ostringstream stream; + bestParams_ = estimateBuildParams(); + print_params(bestParams_, stream); + Logger::info("----------------------------------------------------\n"); + Logger::info("Autotuned parameters:\n"); + Logger::info("%s", stream.str().c_str()); + Logger::info("----------------------------------------------------\n"); + + bestIndex_ = create_index_by_type(dataset_, bestParams_, distance_); + bestIndex_->buildIndex(); + speedup_ = estimateSearchParams(bestSearchParams_); + stream.str(std::string()); + print_params(bestSearchParams_, stream); + Logger::info("----------------------------------------------------\n"); + Logger::info("Search parameters:\n"); + Logger::info("%s", stream.str().c_str()); + Logger::info("----------------------------------------------------\n"); + } + + /** + * Saves the index to a stream + */ + virtual void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, (int)bestIndex_->getType()); + bestIndex_->saveIndex(stream); + save_value(stream, get_param<int>(bestSearchParams_, "checks")); + } + + /** + * Loads the index from a stream + */ + virtual void loadIndex(FILE* stream) CV_OVERRIDE + { + int index_type; + + load_value(stream, index_type); + IndexParams params; + params["algorithm"] = (flann_algorithm_t)index_type; + bestIndex_ = create_index_by_type<Distance>(dataset_, params, distance_); + bestIndex_->loadIndex(stream); + int checks; + load_value(stream, checks); + bestSearchParams_["checks"] = checks; + } + + /** + * Method that searches for nearest-neighbors + */ + virtual void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + int checks = get_param<int>(searchParams,"checks",FLANN_CHECKS_AUTOTUNED); + if (checks == FLANN_CHECKS_AUTOTUNED) { + bestIndex_->findNeighbors(result, vec, bestSearchParams_); + } + else { + bestIndex_->findNeighbors(result, vec, searchParams); + } + } + + + IndexParams getParameters() const CV_OVERRIDE + { + return bestIndex_->getParameters(); + } + + SearchParams getSearchParameters() const + { + return bestSearchParams_; + } + + float getSpeedup() const + { + return speedup_; + } + + + /** + * Number of features in this index. + */ + virtual size_t size() const CV_OVERRIDE + { + return bestIndex_->size(); + } + + /** + * The length of each vector in this index. + */ + virtual size_t veclen() const CV_OVERRIDE + { + return bestIndex_->veclen(); + } + + /** + * The amount of memory (in bytes) this index uses. + */ + virtual int usedMemory() const CV_OVERRIDE + { + return bestIndex_->usedMemory(); + } + + /** + * Algorithm name + */ + virtual flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_AUTOTUNED; + } + +private: + + struct CostData + { + float searchTimeCost; + float buildTimeCost; + float memoryCost; + float totalCost; + IndexParams params; + }; + + void evaluate_kmeans(CostData& cost) + { + StartStopTimer t; + int checks; + const int nn = 1; + + Logger::info("KMeansTree using params: max_iterations=%d, branching=%d\n", + get_param<int>(cost.params,"iterations"), + get_param<int>(cost.params,"branching")); + KMeansIndex<Distance> kmeans(sampledDataset_, cost.params, distance_); + // measure index build time + t.start(); + kmeans.buildIndex(); + t.stop(); + float buildTime = (float)t.value; + + // measure search time + float searchTime = test_index_precision(kmeans, sampledDataset_, testDataset_, gt_matches_, target_precision_, checks, distance_, nn); + + float datasetMemory = float(sampledDataset_.rows * sampledDataset_.cols * sizeof(float)); + cost.memoryCost = (kmeans.usedMemory() + datasetMemory) / datasetMemory; + cost.searchTimeCost = searchTime; + cost.buildTimeCost = buildTime; + Logger::info("KMeansTree buildTime=%g, searchTime=%g, build_weight=%g\n", buildTime, searchTime, build_weight_); + } + + + void evaluate_kdtree(CostData& cost) + { + StartStopTimer t; + int checks; + const int nn = 1; + + Logger::info("KDTree using params: trees=%d\n", get_param<int>(cost.params,"trees")); + KDTreeIndex<Distance> kdtree(sampledDataset_, cost.params, distance_); + + t.start(); + kdtree.buildIndex(); + t.stop(); + float buildTime = (float)t.value; + + //measure search time + float searchTime = test_index_precision(kdtree, sampledDataset_, testDataset_, gt_matches_, target_precision_, checks, distance_, nn); + + float datasetMemory = float(sampledDataset_.rows * sampledDataset_.cols * sizeof(float)); + cost.memoryCost = (kdtree.usedMemory() + datasetMemory) / datasetMemory; + cost.searchTimeCost = searchTime; + cost.buildTimeCost = buildTime; + Logger::info("KDTree buildTime=%g, searchTime=%g\n", buildTime, searchTime); + } + + + // struct KMeansSimpleDownhillFunctor { + // + // Autotune& autotuner; + // KMeansSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {} + // + // float operator()(int* params) { + // + // float maxFloat = numeric_limits<float>::max(); + // + // if (params[0]<2) return maxFloat; + // if (params[1]<0) return maxFloat; + // + // CostData c; + // c.params["algorithm"] = KMEANS; + // c.params["centers-init"] = CENTERS_RANDOM; + // c.params["branching"] = params[0]; + // c.params["max-iterations"] = params[1]; + // + // autotuner.evaluate_kmeans(c); + // + // return c.timeCost; + // + // } + // }; + // + // struct KDTreeSimpleDownhillFunctor { + // + // Autotune& autotuner; + // KDTreeSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {} + // + // float operator()(int* params) { + // float maxFloat = numeric_limits<float>::max(); + // + // if (params[0]<1) return maxFloat; + // + // CostData c; + // c.params["algorithm"] = KDTREE; + // c.params["trees"] = params[0]; + // + // autotuner.evaluate_kdtree(c); + // + // return c.timeCost; + // + // } + // }; + + + + void optimizeKMeans(std::vector<CostData>& costs) + { + Logger::info("KMEANS, Step 1: Exploring parameter space\n"); + + // explore kmeans parameters space using combinations of the parameters below + int maxIterations[] = { 1, 5, 10, 15 }; + int branchingFactors[] = { 16, 32, 64, 128, 256 }; + + int kmeansParamSpaceSize = FLANN_ARRAY_LEN(maxIterations) * FLANN_ARRAY_LEN(branchingFactors); + costs.reserve(costs.size() + kmeansParamSpaceSize); + + // evaluate kmeans for all parameter combinations + for (size_t i = 0; i < FLANN_ARRAY_LEN(maxIterations); ++i) { + for (size_t j = 0; j < FLANN_ARRAY_LEN(branchingFactors); ++j) { + CostData cost; + cost.params["algorithm"] = FLANN_INDEX_KMEANS; + cost.params["centers_init"] = FLANN_CENTERS_RANDOM; + cost.params["iterations"] = maxIterations[i]; + cost.params["branching"] = branchingFactors[j]; + + evaluate_kmeans(cost); + costs.push_back(cost); + } + } + + // Logger::info("KMEANS, Step 2: simplex-downhill optimization\n"); + // + // const int n = 2; + // // choose initial simplex points as the best parameters so far + // int kmeansNMPoints[n*(n+1)]; + // float kmeansVals[n+1]; + // for (int i=0;i<n+1;++i) { + // kmeansNMPoints[i*n] = (int)kmeansCosts[i].params["branching"]; + // kmeansNMPoints[i*n+1] = (int)kmeansCosts[i].params["max-iterations"]; + // kmeansVals[i] = kmeansCosts[i].timeCost; + // } + // KMeansSimpleDownhillFunctor kmeans_cost_func(*this); + // // run optimization + // optimizeSimplexDownhill(kmeansNMPoints,n,kmeans_cost_func,kmeansVals); + // // store results + // for (int i=0;i<n+1;++i) { + // kmeansCosts[i].params["branching"] = kmeansNMPoints[i*2]; + // kmeansCosts[i].params["max-iterations"] = kmeansNMPoints[i*2+1]; + // kmeansCosts[i].timeCost = kmeansVals[i]; + // } + } + + + void optimizeKDTree(std::vector<CostData>& costs) + { + Logger::info("KD-TREE, Step 1: Exploring parameter space\n"); + + // explore kd-tree parameters space using the parameters below + int testTrees[] = { 1, 4, 8, 16, 32 }; + + // evaluate kdtree for all parameter combinations + for (size_t i = 0; i < FLANN_ARRAY_LEN(testTrees); ++i) { + CostData cost; + cost.params["algorithm"] = FLANN_INDEX_KDTREE; + cost.params["trees"] = testTrees[i]; + + evaluate_kdtree(cost); + costs.push_back(cost); + } + + // Logger::info("KD-TREE, Step 2: simplex-downhill optimization\n"); + // + // const int n = 1; + // // choose initial simplex points as the best parameters so far + // int kdtreeNMPoints[n*(n+1)]; + // float kdtreeVals[n+1]; + // for (int i=0;i<n+1;++i) { + // kdtreeNMPoints[i] = (int)kdtreeCosts[i].params["trees"]; + // kdtreeVals[i] = kdtreeCosts[i].timeCost; + // } + // KDTreeSimpleDownhillFunctor kdtree_cost_func(*this); + // // run optimization + // optimizeSimplexDownhill(kdtreeNMPoints,n,kdtree_cost_func,kdtreeVals); + // // store results + // for (int i=0;i<n+1;++i) { + // kdtreeCosts[i].params["trees"] = kdtreeNMPoints[i]; + // kdtreeCosts[i].timeCost = kdtreeVals[i]; + // } + } + + /** + * Chooses the best nearest-neighbor algorithm and estimates the optimal + * parameters to use when building the index (for a given precision). + * Returns a dictionary with the optimal parameters. + */ + IndexParams estimateBuildParams() + { + std::vector<CostData> costs; + + int sampleSize = int(sample_fraction_ * dataset_.rows); + int testSampleSize = std::min(sampleSize / 10, 1000); + + Logger::info("Entering autotuning, dataset size: %d, sampleSize: %d, testSampleSize: %d, target precision: %g\n", dataset_.rows, sampleSize, testSampleSize, target_precision_); + + // For a very small dataset, it makes no sense to build any fancy index, just + // use linear search + if (testSampleSize < 10) { + Logger::info("Choosing linear, dataset too small\n"); + return LinearIndexParams(); + } + + // We use a fraction of the original dataset to speedup the autotune algorithm + sampledDataset_ = random_sample(dataset_, sampleSize); + // We use a cross-validation approach, first we sample a testset from the dataset + testDataset_ = random_sample(sampledDataset_, testSampleSize, true); + + // We compute the ground truth using linear search + Logger::info("Computing ground truth... \n"); + gt_matches_ = Matrix<int>(new int[testDataset_.rows], testDataset_.rows, 1); + StartStopTimer t; + t.start(); + compute_ground_truth<Distance>(sampledDataset_, testDataset_, gt_matches_, 0, distance_); + t.stop(); + + CostData linear_cost; + linear_cost.searchTimeCost = (float)t.value; + linear_cost.buildTimeCost = 0; + linear_cost.memoryCost = 0; + linear_cost.params["algorithm"] = FLANN_INDEX_LINEAR; + + costs.push_back(linear_cost); + + // Start parameter autotune process + Logger::info("Autotuning parameters...\n"); + + optimizeKMeans(costs); + optimizeKDTree(costs); + + float bestTimeCost = costs[0].searchTimeCost; + for (size_t i = 0; i < costs.size(); ++i) { + float timeCost = costs[i].buildTimeCost * build_weight_ + costs[i].searchTimeCost; + if (timeCost < bestTimeCost) { + bestTimeCost = timeCost; + } + } + + float bestCost = costs[0].searchTimeCost / bestTimeCost; + IndexParams bestParams = costs[0].params; + if (bestTimeCost > 0) { + for (size_t i = 0; i < costs.size(); ++i) { + float crtCost = (costs[i].buildTimeCost * build_weight_ + costs[i].searchTimeCost) / bestTimeCost + + memory_weight_ * costs[i].memoryCost; + if (crtCost < bestCost) { + bestCost = crtCost; + bestParams = costs[i].params; + } + } + } + + delete[] gt_matches_.data; + delete[] testDataset_.data; + delete[] sampledDataset_.data; + + return bestParams; + } + + + + /** + * Estimates the search time parameters needed to get the desired precision. + * Precondition: the index is built + * Postcondition: the searchParams will have the optimum params set, also the speedup obtained over linear search. + */ + float estimateSearchParams(SearchParams& searchParams) + { + const int nn = 1; + const size_t SAMPLE_COUNT = 1000; + + assert(bestIndex_ != NULL); // must have a valid index + + float speedup = 0; + + int samples = (int)std::min(dataset_.rows / 10, SAMPLE_COUNT); + if (samples > 0) { + Matrix<ElementType> testDataset = random_sample(dataset_, samples); + + Logger::info("Computing ground truth\n"); + + // we need to compute the ground truth first + Matrix<int> gt_matches(new int[testDataset.rows], testDataset.rows, 1); + StartStopTimer t; + t.start(); + compute_ground_truth<Distance>(dataset_, testDataset, gt_matches, 1, distance_); + t.stop(); + float linear = (float)t.value; + + int checks; + Logger::info("Estimating number of checks\n"); + + float searchTime; + float cb_index; + if (bestIndex_->getType() == FLANN_INDEX_KMEANS) { + Logger::info("KMeans algorithm, estimating cluster border factor\n"); + KMeansIndex<Distance>* kmeans = (KMeansIndex<Distance>*)bestIndex_; + float bestSearchTime = -1; + float best_cb_index = -1; + int best_checks = -1; + for (cb_index = 0; cb_index < 1.1f; cb_index += 0.2f) { + kmeans->set_cb_index(cb_index); + searchTime = test_index_precision(*kmeans, dataset_, testDataset, gt_matches, target_precision_, checks, distance_, nn, 1); + if ((searchTime < bestSearchTime) || (bestSearchTime == -1)) { + bestSearchTime = searchTime; + best_cb_index = cb_index; + best_checks = checks; + } + } + searchTime = bestSearchTime; + cb_index = best_cb_index; + checks = best_checks; + + kmeans->set_cb_index(best_cb_index); + Logger::info("Optimum cb_index: %g\n", cb_index); + bestParams_["cb_index"] = cb_index; + } + else { + searchTime = test_index_precision(*bestIndex_, dataset_, testDataset, gt_matches, target_precision_, checks, distance_, nn, 1); + } + + Logger::info("Required number of checks: %d \n", checks); + searchParams["checks"] = checks; + + speedup = linear / searchTime; + + delete[] gt_matches.data; + delete[] testDataset.data; + } + + return speedup; + } + +private: + NNIndex<Distance>* bestIndex_; + + IndexParams bestParams_; + SearchParams bestSearchParams_; + + Matrix<ElementType> sampledDataset_; + Matrix<ElementType> testDataset_; + Matrix<int> gt_matches_; + + float speedup_; + + /** + * The dataset used by this index + */ + const Matrix<ElementType> dataset_; + + /** + * Index parameters + */ + float target_precision_; + float build_weight_; + float memory_weight_; + float sample_fraction_; + + Distance distance_; + + +}; +} + +#endif /* OPENCV_FLANN_AUTOTUNED_INDEX_H_ */ diff --git a/include/opencv2/flann/composite_index.h b/include/opencv2/flann/composite_index.h new file mode 100644 index 0000000..5e12a17 --- /dev/null +++ b/include/opencv2/flann/composite_index.h @@ -0,0 +1,194 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_COMPOSITE_INDEX_H_ +#define OPENCV_FLANN_COMPOSITE_INDEX_H_ + +#include "general.h" +#include "nn_index.h" +#include "kdtree_index.h" +#include "kmeans_index.h" + +namespace cvflann +{ + +/** + * Index parameters for the CompositeIndex. + */ +struct CompositeIndexParams : public IndexParams +{ + CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 ) + { + (*this)["algorithm"] = FLANN_INDEX_KMEANS; + // number of randomized trees to use (for kdtree) + (*this)["trees"] = trees; + // branching factor + (*this)["branching"] = branching; + // max iterations to perform in one kmeans clustering (kmeans tree) + (*this)["iterations"] = iterations; + // algorithm used for picking the initial cluster centers for kmeans tree + (*this)["centers_init"] = centers_init; + // cluster boundary index. Used when searching the kmeans tree + (*this)["cb_index"] = cb_index; + } +}; + + +/** + * This index builds a kd-tree index and a k-means index and performs nearest + * neighbour search both indexes. This gives a slight boost in search performance + * as some of the neighbours that are missed by one index are found by the other. + */ +template <typename Distance> +class CompositeIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + /** + * Index constructor + * @param inputData dataset containing the points to index + * @param params Index parameters + * @param d Distance functor + * @return + */ + CompositeIndex(const Matrix<ElementType>& inputData, const IndexParams& params = CompositeIndexParams(), + Distance d = Distance()) : index_params_(params) + { + kdtree_index_ = new KDTreeIndex<Distance>(inputData, params, d); + kmeans_index_ = new KMeansIndex<Distance>(inputData, params, d); + + } + + CompositeIndex(const CompositeIndex&); + CompositeIndex& operator=(const CompositeIndex&); + + virtual ~CompositeIndex() + { + delete kdtree_index_; + delete kmeans_index_; + } + + /** + * @return The index type + */ + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_COMPOSITE; + } + + /** + * @return Size of the index + */ + size_t size() const CV_OVERRIDE + { + return kdtree_index_->size(); + } + + /** + * \returns The dimensionality of the features in this index. + */ + size_t veclen() const CV_OVERRIDE + { + return kdtree_index_->veclen(); + } + + /** + * \returns The amount of memory (in bytes) used by the index. + */ + int usedMemory() const CV_OVERRIDE + { + return kmeans_index_->usedMemory() + kdtree_index_->usedMemory(); + } + + /** + * \brief Builds the index + */ + void buildIndex() CV_OVERRIDE + { + Logger::info("Building kmeans tree...\n"); + kmeans_index_->buildIndex(); + Logger::info("Building kdtree tree...\n"); + kdtree_index_->buildIndex(); + } + + /** + * \brief Saves the index to a stream + * \param stream The stream to save the index to + */ + void saveIndex(FILE* stream) CV_OVERRIDE + { + kmeans_index_->saveIndex(stream); + kdtree_index_->saveIndex(stream); + } + + /** + * \brief Loads the index from a stream + * \param stream The stream from which the index is loaded + */ + void loadIndex(FILE* stream) CV_OVERRIDE + { + kmeans_index_->loadIndex(stream); + kdtree_index_->loadIndex(stream); + } + + /** + * \returns The index parameters + */ + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + /** + * \brief Method that searches for nearest-neighbours + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + kmeans_index_->findNeighbors(result, vec, searchParams); + kdtree_index_->findNeighbors(result, vec, searchParams); + } + +private: + /** The k-means index */ + KMeansIndex<Distance>* kmeans_index_; + + /** The kd-tree index */ + KDTreeIndex<Distance>* kdtree_index_; + + /** The index parameters */ + const IndexParams index_params_; +}; + +} + +#endif //OPENCV_FLANN_COMPOSITE_INDEX_H_ diff --git a/include/opencv2/flann/config.h b/include/opencv2/flann/config.h new file mode 100644 index 0000000..56832fd --- /dev/null +++ b/include/opencv2/flann/config.h @@ -0,0 +1,38 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_CONFIG_H_ +#define OPENCV_FLANN_CONFIG_H_ + +#ifdef FLANN_VERSION_ +#undef FLANN_VERSION_ +#endif +#define FLANN_VERSION_ "1.6.10" + +#endif /* OPENCV_FLANN_CONFIG_H_ */ diff --git a/include/opencv2/flann/defines.h b/include/opencv2/flann/defines.h new file mode 100644 index 0000000..6fd53c2 --- /dev/null +++ b/include/opencv2/flann/defines.h @@ -0,0 +1,164 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_DEFINES_H_ +#define OPENCV_FLANN_DEFINES_H_ + +#include "config.h" + +#ifdef FLANN_EXPORT +#undef FLANN_EXPORT +#endif +#ifdef _WIN32 +/* win32 dll export/import directives */ + #ifdef FLANN_EXPORTS + #define FLANN_EXPORT __declspec(dllexport) + #elif defined(FLANN_STATIC) + #define FLANN_EXPORT + #else + #define FLANN_EXPORT __declspec(dllimport) + #endif +#else +/* unix needs nothing */ + #define FLANN_EXPORT +#endif + + +#undef FLANN_PLATFORM_32_BIT +#undef FLANN_PLATFORM_64_BIT +#if defined __amd64__ || defined __x86_64__ || defined _WIN64 || defined _M_X64 +#define FLANN_PLATFORM_64_BIT +#else +#define FLANN_PLATFORM_32_BIT +#endif + + +#undef FLANN_ARRAY_LEN +#define FLANN_ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) + +namespace cvflann { + +/* Nearest neighbour index algorithms */ +enum flann_algorithm_t +{ + FLANN_INDEX_LINEAR = 0, + FLANN_INDEX_KDTREE = 1, + FLANN_INDEX_KMEANS = 2, + FLANN_INDEX_COMPOSITE = 3, + FLANN_INDEX_KDTREE_SINGLE = 4, + FLANN_INDEX_HIERARCHICAL = 5, + FLANN_INDEX_LSH = 6, + FLANN_INDEX_SAVED = 254, + FLANN_INDEX_AUTOTUNED = 255, + + // deprecated constants, should use the FLANN_INDEX_* ones instead + LINEAR = 0, + KDTREE = 1, + KMEANS = 2, + COMPOSITE = 3, + KDTREE_SINGLE = 4, + SAVED = 254, + AUTOTUNED = 255 +}; + + + +enum flann_centers_init_t +{ + FLANN_CENTERS_RANDOM = 0, + FLANN_CENTERS_GONZALES = 1, + FLANN_CENTERS_KMEANSPP = 2, + FLANN_CENTERS_GROUPWISE = 3, + + // deprecated constants, should use the FLANN_CENTERS_* ones instead + CENTERS_RANDOM = 0, + CENTERS_GONZALES = 1, + CENTERS_KMEANSPP = 2 +}; + +enum flann_log_level_t +{ + FLANN_LOG_NONE = 0, + FLANN_LOG_FATAL = 1, + FLANN_LOG_ERROR = 2, + FLANN_LOG_WARN = 3, + FLANN_LOG_INFO = 4 +}; + +enum flann_distance_t +{ + FLANN_DIST_EUCLIDEAN = 1, + FLANN_DIST_L2 = 1, + FLANN_DIST_MANHATTAN = 2, + FLANN_DIST_L1 = 2, + FLANN_DIST_MINKOWSKI = 3, + FLANN_DIST_MAX = 4, + FLANN_DIST_HIST_INTERSECT = 5, + FLANN_DIST_HELLINGER = 6, + FLANN_DIST_CHI_SQUARE = 7, + FLANN_DIST_CS = 7, + FLANN_DIST_KULLBACK_LEIBLER = 8, + FLANN_DIST_KL = 8, + FLANN_DIST_HAMMING = 9, + + // deprecated constants, should use the FLANN_DIST_* ones instead + EUCLIDEAN = 1, + MANHATTAN = 2, + MINKOWSKI = 3, + MAX_DIST = 4, + HIST_INTERSECT = 5, + HELLINGER = 6, + CS = 7, + KL = 8, + KULLBACK_LEIBLER = 8 +}; + +enum flann_datatype_t +{ + FLANN_INT8 = 0, + FLANN_INT16 = 1, + FLANN_INT32 = 2, + FLANN_INT64 = 3, + FLANN_UINT8 = 4, + FLANN_UINT16 = 5, + FLANN_UINT32 = 6, + FLANN_UINT64 = 7, + FLANN_FLOAT32 = 8, + FLANN_FLOAT64 = 9 +}; + +enum +{ + FLANN_CHECKS_UNLIMITED = -1, + FLANN_CHECKS_AUTOTUNED = -2 +}; + +} + +#endif /* OPENCV_FLANN_DEFINES_H_ */ diff --git a/include/opencv2/flann/dist.h b/include/opencv2/flann/dist.h new file mode 100644 index 0000000..2bb4fc9 --- /dev/null +++ b/include/opencv2/flann/dist.h @@ -0,0 +1,904 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_DIST_H_ +#define OPENCV_FLANN_DIST_H_ + +#include <cmath> +#include <cstdlib> +#include <string.h> +#ifdef _MSC_VER +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +#include <stdint.h> +#endif + +#include "defines.h" + +#if defined _WIN32 && defined(_M_ARM) +# include <Intrin.h> +#endif + +#if defined(__ARM_NEON__) && !defined(__CUDACC__) +# include "arm_neon.h" +#endif + +namespace cvflann +{ + +template<typename T> +inline T abs(T x) { return (x<0) ? -x : x; } + +template<> +inline int abs<int>(int x) { return ::abs(x); } + +template<> +inline float abs<float>(float x) { return fabsf(x); } + +template<> +inline double abs<double>(double x) { return fabs(x); } + +template<typename T> +struct Accumulator { typedef T Type; }; +template<> +struct Accumulator<unsigned char> { typedef float Type; }; +template<> +struct Accumulator<unsigned short> { typedef float Type; }; +template<> +struct Accumulator<unsigned int> { typedef float Type; }; +template<> +struct Accumulator<char> { typedef float Type; }; +template<> +struct Accumulator<short> { typedef float Type; }; +template<> +struct Accumulator<int> { typedef float Type; }; + +#undef True +#undef False + +class True +{ +}; + +class False +{ +}; + + +/** + * Squared Euclidean distance functor. + * + * This is the simpler, unrolled version. This is preferable for + * very low dimensionality data (eg 3D points) + */ +template<class T> +struct L2_Simple +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { + ResultType result = ResultType(); + ResultType diff; + for(size_t i = 0; i < size; ++i ) { + diff = *a++ - *b++; + result += diff*diff; + } + return result; + } + + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return (a-b)*(a-b); + } +}; + + + +/** + * Squared Euclidean distance functor, optimized version + */ +template<class T> +struct L2 +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the squared Euclidean distance between two vectors. + * + * This is highly optimised, with loop unrolling, as it is one + * of the most expensive inner loops. + * + * The computation of squared root at the end is omitted for + * efficiency. + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = (ResultType)(a[0] - b[0]); + diff1 = (ResultType)(a[1] - b[1]); + diff2 = (ResultType)(a[2] - b[2]); + diff3 = (ResultType)(a[3] - b[3]); + result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3; + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = (ResultType)(*a++ - *b++); + result += diff0 * diff0; + } + return result; + } + + /** + * Partial euclidean distance, using just one dimension. This is used by the + * kd-tree when computing partial distances while traversing the tree. + * + * Squared root is omitted for efficiency. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return (a-b)*(a-b); + } +}; + + +/* + * Manhattan distance functor, optimized version + */ +template<class T> +struct L1 +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the Manhattan (L_1) distance between two vectors. + * + * This is highly optimised, with loop unrolling, as it is one + * of the most expensive inner loops. + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = (ResultType)abs(a[0] - b[0]); + diff1 = (ResultType)abs(a[1] - b[1]); + diff2 = (ResultType)abs(a[2] - b[2]); + diff3 = (ResultType)abs(a[3] - b[3]); + result += diff0 + diff1 + diff2 + diff3; + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = (ResultType)abs(*a++ - *b++); + result += diff0; + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return abs(a-b); + } +}; + + + +template<class T> +struct MinkowskiDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + int order; + + MinkowskiDistance(int order_) : order(order_) {} + + /** + * Compute the Minkowsky (L_p) distance between two vectors. + * + * This is highly optimised, with loop unrolling, as it is one + * of the most expensive inner loops. + * + * The computation of squared root at the end is omitted for + * efficiency. + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = (ResultType)abs(a[0] - b[0]); + diff1 = (ResultType)abs(a[1] - b[1]); + diff2 = (ResultType)abs(a[2] - b[2]); + diff3 = (ResultType)abs(a[3] - b[3]); + result += pow(diff0,order) + pow(diff1,order) + pow(diff2,order) + pow(diff3,order); + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = (ResultType)abs(*a++ - *b++); + result += pow(diff0,order); + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return pow(static_cast<ResultType>(abs(a-b)),order); + } +}; + + + +template<class T> +struct MaxDistance +{ + typedef False is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the max distance (L_infinity) between two vectors. + * + * This distance is not a valid kdtree distance, it's not dimensionwise additive. + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = abs(a[0] - b[0]); + diff1 = abs(a[1] - b[1]); + diff2 = abs(a[2] - b[2]); + diff3 = abs(a[3] - b[3]); + if (diff0>result) {result = diff0; } + if (diff1>result) {result = diff1; } + if (diff2>result) {result = diff2; } + if (diff3>result) {result = diff3; } + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = abs(*a++ - *b++); + result = (diff0>result) ? diff0 : result; + } + return result; + } + + /* This distance functor is not dimension-wise additive, which + * makes it an invalid kd-tree distance, not implementing the accum_dist method */ + +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** + * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor + * bit count of A exclusive XOR'ed with B + */ +struct HammingLUT +{ + typedef False is_kdtree_distance; + typedef False is_vector_space_distance; + + typedef unsigned char ElementType; + typedef int ResultType; + + /** this will count the bits in a ^ b + */ + ResultType operator()(const unsigned char* a, const unsigned char* b, size_t size) const + { + static const uchar popCountTable[] = + { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 + }; + ResultType result = 0; + for (size_t i = 0; i < size; i++) { + result += popCountTable[a[i] ^ b[i]]; + } + return result; + } +}; + +/** + * Hamming distance functor (pop count between two binary vectors, i.e. xor them and count the number of bits set) + * That code was taken from brief.cpp in OpenCV + */ +template<class T> +struct Hamming +{ + typedef False is_kdtree_distance; + typedef False is_vector_space_distance; + + + typedef T ElementType; + typedef int ResultType; + + template<typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { + ResultType result = 0; +#if defined(__ARM_NEON__) && !defined(__CUDACC__) + { + uint32x4_t bits = vmovq_n_u32(0); + for (size_t i = 0; i < size; i += 16) { + uint8x16_t A_vec = vld1q_u8 (a + i); + uint8x16_t B_vec = vld1q_u8 (b + i); + uint8x16_t AxorB = veorq_u8 (A_vec, B_vec); + uint8x16_t bitsSet = vcntq_u8 (AxorB); + uint16x8_t bitSet8 = vpaddlq_u8 (bitsSet); + uint32x4_t bitSet4 = vpaddlq_u16 (bitSet8); + bits = vaddq_u32(bits, bitSet4); + } + uint64x2_t bitSet2 = vpaddlq_u32 (bits); + result = vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),0); + result += vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),2); + } +#elif __GNUC__ + { + //for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll) + typedef unsigned long long pop_t; + const size_t modulo = size % sizeof(pop_t); + const pop_t* a2 = reinterpret_cast<const pop_t*> (a); + const pop_t* b2 = reinterpret_cast<const pop_t*> (b); + const pop_t* a2_end = a2 + (size / sizeof(pop_t)); + + for (; a2 != a2_end; ++a2, ++b2) result += __builtin_popcountll((*a2) ^ (*b2)); + + if (modulo) { + //in the case where size is not dividable by sizeof(size_t) + //need to mask off the bits at the end + pop_t a_final = 0, b_final = 0; + memcpy(&a_final, a2, modulo); + memcpy(&b_final, b2, modulo); + result += __builtin_popcountll(a_final ^ b_final); + } + } +#else // NO NEON and NOT GNUC + HammingLUT lut; + result = lut(reinterpret_cast<const unsigned char*> (a), + reinterpret_cast<const unsigned char*> (b), size); +#endif + return result; + } +}; + +template<typename T> +struct Hamming2 +{ + typedef False is_kdtree_distance; + typedef False is_vector_space_distance; + + typedef T ElementType; + typedef int ResultType; + + /** This is popcount_3() from: + * http://en.wikipedia.org/wiki/Hamming_weight */ + unsigned int popcnt32(uint32_t n) const + { + n -= ((n >> 1) & 0x55555555); + n = (n & 0x33333333) + ((n >> 2) & 0x33333333); + return (((n + (n >> 4))& 0xF0F0F0F)* 0x1010101) >> 24; + } + +#ifdef FLANN_PLATFORM_64_BIT + unsigned int popcnt64(uint64_t n) const + { + n -= ((n >> 1) & 0x5555555555555555); + n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333); + return (((n + (n >> 4))& 0x0f0f0f0f0f0f0f0f)* 0x0101010101010101) >> 56; + } +#endif + + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { +#ifdef FLANN_PLATFORM_64_BIT + const uint64_t* pa = reinterpret_cast<const uint64_t*>(a); + const uint64_t* pb = reinterpret_cast<const uint64_t*>(b); + ResultType result = 0; + size /= (sizeof(uint64_t)/sizeof(unsigned char)); + for(size_t i = 0; i < size; ++i ) { + result += popcnt64(*pa ^ *pb); + ++pa; + ++pb; + } +#else + const uint32_t* pa = reinterpret_cast<const uint32_t*>(a); + const uint32_t* pb = reinterpret_cast<const uint32_t*>(b); + ResultType result = 0; + size /= (sizeof(uint32_t)/sizeof(unsigned char)); + for(size_t i = 0; i < size; ++i ) { + result += popcnt32(*pa ^ *pb); + ++pa; + ++pb; + } +#endif + return result; + } +}; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template<class T> +struct HistIntersectionDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the histogram intersection distance + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType min0, min1, min2, min3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + min0 = (ResultType)(a[0] < b[0] ? a[0] : b[0]); + min1 = (ResultType)(a[1] < b[1] ? a[1] : b[1]); + min2 = (ResultType)(a[2] < b[2] ? a[2] : b[2]); + min3 = (ResultType)(a[3] < b[3] ? a[3] : b[3]); + result += min0 + min1 + min2 + min3; + a += 4; + b += 4; + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + min0 = (ResultType)(*a < *b ? *a : *b); + result += min0; + ++a; + ++b; + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return a<b ? a : b; + } +}; + + + +template<class T> +struct HellingerDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the Hellinger distance + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = sqrt(static_cast<ResultType>(a[0])) - sqrt(static_cast<ResultType>(b[0])); + diff1 = sqrt(static_cast<ResultType>(a[1])) - sqrt(static_cast<ResultType>(b[1])); + diff2 = sqrt(static_cast<ResultType>(a[2])) - sqrt(static_cast<ResultType>(b[2])); + diff3 = sqrt(static_cast<ResultType>(a[3])) - sqrt(static_cast<ResultType>(b[3])); + result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3; + a += 4; + b += 4; + } + while (a < last) { + diff0 = sqrt(static_cast<ResultType>(*a++)) - sqrt(static_cast<ResultType>(*b++)); + result += diff0 * diff0; + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + ResultType diff = sqrt(static_cast<ResultType>(a)) - sqrt(static_cast<ResultType>(b)); + return diff * diff; + } +}; + + +template<class T> +struct ChiSquareDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the chi-square distance + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType sum, diff; + Iterator1 last = a + size; + + while (a < last) { + sum = (ResultType)(*a + *b); + if (sum>0) { + diff = (ResultType)(*a - *b); + result += diff*diff/sum; + } + ++a; + ++b; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + ResultType result = ResultType(); + ResultType sum, diff; + + sum = (ResultType)(a+b); + if (sum>0) { + diff = (ResultType)(a-b); + result = diff*diff/sum; + } + return result; + } +}; + + +template<class T> +struct KL_Divergence +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator<T>::Type ResultType; + + /** + * Compute the Kullback-Leibler divergence + */ + template <typename Iterator1, typename Iterator2> + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + Iterator1 last = a + size; + + while (a < last) { + if (* b != 0) { + ResultType ratio = (ResultType)(*a / *b); + if (ratio>0) { + result += *a * log(ratio); + } + } + ++a; + ++b; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template <typename U, typename V> + inline ResultType accum_dist(const U& a, const V& b, int) const + { + ResultType result = ResultType(); + if( *b != 0 ) { + ResultType ratio = (ResultType)(a / b); + if (ratio>0) { + result = a * log(ratio); + } + } + return result; + } +}; + + + +/* + * This is a "zero iterator". It basically behaves like a zero filled + * array to all algorithms that use arrays as iterators (STL style). + * It's useful when there's a need to compute the distance between feature + * and origin it and allows for better compiler optimisation than using a + * zero-filled array. + */ +template <typename T> +struct ZeroIterator +{ + + T operator*() + { + return 0; + } + + T operator[](int) + { + return 0; + } + + const ZeroIterator<T>& operator ++() + { + return *this; + } + + ZeroIterator<T> operator ++(int) + { + return *this; + } + + ZeroIterator<T>& operator+=(int) + { + return *this; + } + +}; + + +/* + * Depending on processed distances, some of them are already squared (e.g. L2) + * and some are not (e.g.Hamming). In KMeans++ for instance we want to be sure + * we are working on ^2 distances, thus following templates to ensure that. + */ +template <typename Distance, typename ElementType> +struct squareDistance +{ + typedef typename Distance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist*dist; } +}; + + +template <typename ElementType> +struct squareDistance<L2_Simple<ElementType>, ElementType> +{ + typedef typename L2_Simple<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template <typename ElementType> +struct squareDistance<L2<ElementType>, ElementType> +{ + typedef typename L2<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template <typename ElementType> +struct squareDistance<MinkowskiDistance<ElementType>, ElementType> +{ + typedef typename MinkowskiDistance<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template <typename ElementType> +struct squareDistance<HellingerDistance<ElementType>, ElementType> +{ + typedef typename HellingerDistance<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template <typename ElementType> +struct squareDistance<ChiSquareDistance<ElementType>, ElementType> +{ + typedef typename ChiSquareDistance<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template <typename Distance> +typename Distance::ResultType ensureSquareDistance( typename Distance::ResultType dist ) +{ + typedef typename Distance::ElementType ElementType; + + squareDistance<Distance, ElementType> dummy; + return dummy( dist ); +} + + +/* + * ...and a template to ensure the user that he will process the normal distance, + * and not squared distance, without losing processing time calling sqrt(ensureSquareDistance) + * that will result in doing actually sqrt(dist*dist) for L1 distance for instance. + */ +template <typename Distance, typename ElementType> +struct simpleDistance +{ + typedef typename Distance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template <typename ElementType> +struct simpleDistance<L2_Simple<ElementType>, ElementType> +{ + typedef typename L2_Simple<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + +template <typename ElementType> +struct simpleDistance<L2<ElementType>, ElementType> +{ + typedef typename L2<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + + +template <typename ElementType> +struct simpleDistance<MinkowskiDistance<ElementType>, ElementType> +{ + typedef typename MinkowskiDistance<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + +template <typename ElementType> +struct simpleDistance<HellingerDistance<ElementType>, ElementType> +{ + typedef typename HellingerDistance<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + +template <typename ElementType> +struct simpleDistance<ChiSquareDistance<ElementType>, ElementType> +{ + typedef typename ChiSquareDistance<ElementType>::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + + +template <typename Distance> +typename Distance::ResultType ensureSimpleDistance( typename Distance::ResultType dist ) +{ + typedef typename Distance::ElementType ElementType; + + simpleDistance<Distance, ElementType> dummy; + return dummy( dist ); +} + +} + +#endif //OPENCV_FLANN_DIST_H_ diff --git a/include/opencv2/flann/dummy.h b/include/opencv2/flann/dummy.h new file mode 100644 index 0000000..d6837e5 --- /dev/null +++ b/include/opencv2/flann/dummy.h @@ -0,0 +1,13 @@ + +#ifndef OPENCV_FLANN_DUMMY_H_ +#define OPENCV_FLANN_DUMMY_H_ + +namespace cvflann +{ + +CV_DEPRECATED inline void dummyfunc() {} + +} + + +#endif /* OPENCV_FLANN_DUMMY_H_ */ diff --git a/include/opencv2/flann/dynamic_bitset.h b/include/opencv2/flann/dynamic_bitset.h new file mode 100644 index 0000000..923b658 --- /dev/null +++ b/include/opencv2/flann/dynamic_bitset.h @@ -0,0 +1,159 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +/*********************************************************************** + * Author: Vincent Rabaud + *************************************************************************/ + +#ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_ +#define OPENCV_FLANN_DYNAMIC_BITSET_H_ + +#ifndef FLANN_USE_BOOST +# define FLANN_USE_BOOST 0 +#endif +//#define FLANN_USE_BOOST 1 +#if FLANN_USE_BOOST +#include <boost/dynamic_bitset.hpp> +typedef boost::dynamic_bitset<> DynamicBitset; +#else + +#include <limits.h> + +#include "dist.h" + +namespace cvflann { + +/** Class re-implementing the boost version of it + * This helps not depending on boost, it also does not do the bound checks + * and has a way to reset a block for speed + */ +class DynamicBitset +{ +public: + /** default constructor + */ + DynamicBitset() : size_(0) + { + } + + /** only constructor we use in our code + * @param sz the size of the bitset (in bits) + */ + DynamicBitset(size_t sz) + { + resize(sz); + reset(); + } + + /** Sets all the bits to 0 + */ + void clear() + { + std::fill(bitset_.begin(), bitset_.end(), 0); + } + + /** @brief checks if the bitset is empty + * @return true if the bitset is empty + */ + bool empty() const + { + return bitset_.empty(); + } + + /** set all the bits to 0 + */ + void reset() + { + std::fill(bitset_.begin(), bitset_.end(), 0); + } + + /** @brief set one bit to 0 + * @param index + */ + void reset(size_t index) + { + bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_)); + } + + /** @brief sets a specific bit to 0, and more bits too + * This function is useful when resetting a given set of bits so that the + * whole bitset ends up being 0: if that's the case, we don't care about setting + * other bits to 0 + * @param index + */ + void reset_block(size_t index) + { + bitset_[index / cell_bit_size_] = 0; + } + + /** resize the bitset so that it contains at least sz bits + * @param sz + */ + void resize(size_t sz) + { + size_ = sz; + bitset_.resize(sz / cell_bit_size_ + 1); + } + + /** set a bit to true + * @param index the index of the bit to set to 1 + */ + void set(size_t index) + { + bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_); + } + + /** gives the number of contained bits + */ + size_t size() const + { + return size_; + } + + /** check if a bit is set + * @param index the index of the bit to check + * @return true if the bit is set + */ + bool test(size_t index) const + { + return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0; + } + +private: + std::vector<size_t> bitset_; + size_t size_; + static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t); +}; + +} // namespace cvflann + +#endif + +#endif // OPENCV_FLANN_DYNAMIC_BITSET_H_ diff --git a/include/opencv2/flann/flann.hpp b/include/opencv2/flann/flann.hpp new file mode 100644 index 0000000..227683f --- /dev/null +++ b/include/opencv2/flann/flann.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/flann.hpp" diff --git a/include/opencv2/flann/flann_base.hpp b/include/opencv2/flann/flann_base.hpp new file mode 100644 index 0000000..0ffb857 --- /dev/null +++ b/include/opencv2/flann/flann_base.hpp @@ -0,0 +1,295 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_BASE_HPP_ +#define OPENCV_FLANN_BASE_HPP_ + +#include <vector> +#include <cassert> +#include <cstdio> + +#include "general.h" +#include "matrix.h" +#include "params.h" +#include "saving.h" + +#include "all_indices.h" + +namespace cvflann +{ + +/** + * Sets the log level used for all flann functions + * @param level Verbosity level + */ +inline void log_verbosity(int level) +{ + if (level >= 0) { + Logger::setLevel(level); + } +} + +/** + * (Deprecated) Index parameters for creating a saved index. + */ +struct SavedIndexParams : public IndexParams +{ + SavedIndexParams(cv::String filename) + { + (* this)["algorithm"] = FLANN_INDEX_SAVED; + (*this)["filename"] = filename; + } +}; + + +template<typename Distance> +NNIndex<Distance>* load_saved_index(const Matrix<typename Distance::ElementType>& dataset, const cv::String& filename, Distance distance) +{ + typedef typename Distance::ElementType ElementType; + + FILE* fin = fopen(filename.c_str(), "rb"); + if (fin == NULL) { + return NULL; + } + IndexHeader header = load_header(fin); + if (header.data_type != Datatype<ElementType>::type()) { + fclose(fin); + throw FLANNException("Datatype of saved index is different than of the one to be created."); + } + if ((size_t(header.rows) != dataset.rows)||(size_t(header.cols) != dataset.cols)) { + fclose(fin); + throw FLANNException("The index saved belongs to a different dataset"); + } + + IndexParams params; + params["algorithm"] = header.index_type; + NNIndex<Distance>* nnIndex = create_index_by_type<Distance>(dataset, params, distance); + nnIndex->loadIndex(fin); + fclose(fin); + + return nnIndex; +} + + +template<typename Distance> +class Index : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + Index(const Matrix<ElementType>& features, const IndexParams& params, Distance distance = Distance() ) + : index_params_(params) + { + flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,"algorithm"); + loaded_ = false; + + if (index_type == FLANN_INDEX_SAVED) { + nnIndex_ = load_saved_index<Distance>(features, get_param<cv::String>(params,"filename"), distance); + loaded_ = true; + } + else { + nnIndex_ = create_index_by_type<Distance>(features, params, distance); + } + } + + ~Index() + { + delete nnIndex_; + } + + /** + * Builds the index. + */ + void buildIndex() CV_OVERRIDE + { + if (!loaded_) { + nnIndex_->buildIndex(); + } + } + + void save(cv::String filename) + { + FILE* fout = fopen(filename.c_str(), "wb"); + if (fout == NULL) { + throw FLANNException("Cannot open file"); + } + save_header(fout, *nnIndex_); + saveIndex(fout); + fclose(fout); + } + + /** + * \brief Saves the index to a stream + * \param stream The stream to save the index to + */ + virtual void saveIndex(FILE* stream) CV_OVERRIDE + { + nnIndex_->saveIndex(stream); + } + + /** + * \brief Loads the index from a stream + * \param stream The stream from which the index is loaded + */ + virtual void loadIndex(FILE* stream) CV_OVERRIDE + { + nnIndex_->loadIndex(stream); + } + + /** + * \returns number of features in this index. + */ + size_t veclen() const CV_OVERRIDE + { + return nnIndex_->veclen(); + } + + /** + * \returns The dimensionality of the features in this index. + */ + size_t size() const CV_OVERRIDE + { + return nnIndex_->size(); + } + + /** + * \returns The index type (kdtree, kmeans,...) + */ + flann_algorithm_t getType() const CV_OVERRIDE + { + return nnIndex_->getType(); + } + + /** + * \returns The amount of memory (in bytes) used by the index. + */ + virtual int usedMemory() const CV_OVERRIDE + { + return nnIndex_->usedMemory(); + } + + + /** + * \returns The index parameters + */ + IndexParams getParameters() const CV_OVERRIDE + { + return nnIndex_->getParameters(); + } + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE + { + nnIndex_->knnSearch(queries, indices, dists, knn, params); + } + + /** + * \brief Perform radius search + * \param[in] query The query point + * \param[out] indices The indinces of the neighbors found within the given radius + * \param[out] dists The distances to the nearest neighbors found + * \param[in] radius The radius used for search + * \param[in] params Search parameters + * \returns Number of neighbors found + */ + int radiusSearch(const Matrix<ElementType>& query, Matrix<int>& indices, Matrix<DistanceType>& dists, float radius, const SearchParams& params) CV_OVERRIDE + { + return nnIndex_->radiusSearch(query, indices, dists, radius, params); + } + + /** + * \brief Method that searches for nearest-neighbours + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + nnIndex_->findNeighbors(result, vec, searchParams); + } + + /** + * \brief Returns actual index + */ + CV_DEPRECATED NNIndex<Distance>* getIndex() + { + return nnIndex_; + } + + /** + * \brief Returns index parameters. + * \deprecated use getParameters() instead. + */ + CV_DEPRECATED const IndexParams* getIndexParameters() + { + return &index_params_; + } + +private: + /** Pointer to actual index class */ + NNIndex<Distance>* nnIndex_; + /** Indices if the index was loaded from a file */ + bool loaded_; + /** Parameters passed to the index */ + IndexParams index_params_; + + Index(const Index &); // copy disabled + Index& operator=(const Index &); // assign disabled +}; + +/** + * Performs a hierarchical clustering of the points passed as argument and then takes a cut in the + * the clustering tree to return a flat clustering. + * @param[in] points Points to be clustered + * @param centers The computed cluster centres. Matrix should be preallocated and centers.rows is the + * number of clusters requested. + * @param params Clustering parameters (The same as for cvflann::KMeansIndex) + * @param d Distance to be used for clustering (eg: cvflann::L2) + * @return number of clusters computed (can be different than clusters.rows and is the highest number + * of the form (branching-1)*K+1 smaller than clusters.rows). + */ +template <typename Distance> +int hierarchicalClustering(const Matrix<typename Distance::ElementType>& points, Matrix<typename Distance::ResultType>& centers, + const KMeansIndexParams& params, Distance d = Distance()) +{ + KMeansIndex<Distance> kmeans(points, params, d); + kmeans.buildIndex(); + + int clusterNum = kmeans.getClusterCenters(centers); + return clusterNum; +} + +} +#endif /* OPENCV_FLANN_BASE_HPP_ */ diff --git a/include/opencv2/flann/general.h b/include/opencv2/flann/general.h new file mode 100644 index 0000000..9d5402a --- /dev/null +++ b/include/opencv2/flann/general.h @@ -0,0 +1,50 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_GENERAL_H_ +#define OPENCV_FLANN_GENERAL_H_ + +#include "opencv2/core.hpp" + +namespace cvflann +{ + +class FLANNException : public cv::Exception +{ +public: + FLANNException(const char* message) : cv::Exception(0, message, "", __FILE__, __LINE__) { } + + FLANNException(const cv::String& message) : cv::Exception(0, message, "", __FILE__, __LINE__) { } +}; + +} + + +#endif /* OPENCV_FLANN_GENERAL_H_ */ diff --git a/include/opencv2/flann/ground_truth.h b/include/opencv2/flann/ground_truth.h new file mode 100644 index 0000000..fd8f3ae --- /dev/null +++ b/include/opencv2/flann/ground_truth.h @@ -0,0 +1,94 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_GROUND_TRUTH_H_ +#define OPENCV_FLANN_GROUND_TRUTH_H_ + +#include "dist.h" +#include "matrix.h" + + +namespace cvflann +{ + +template <typename Distance> +void find_nearest(const Matrix<typename Distance::ElementType>& dataset, typename Distance::ElementType* query, int* matches, int nn, + int skip = 0, Distance distance = Distance()) +{ + typedef typename Distance::ResultType DistanceType; + int n = nn + skip; + + std::vector<int> match(n); + std::vector<DistanceType> dists(n); + + dists[0] = distance(dataset[0], query, dataset.cols); + match[0] = 0; + int dcnt = 1; + + for (size_t i=1; i<dataset.rows; ++i) { + DistanceType tmp = distance(dataset[i], query, dataset.cols); + + if (dcnt<n) { + match[dcnt] = (int)i; + dists[dcnt++] = tmp; + } + else if (tmp < dists[dcnt-1]) { + dists[dcnt-1] = tmp; + match[dcnt-1] = (int)i; + } + + int j = dcnt-1; + // bubble up + while (j>=1 && dists[j]<dists[j-1]) { + std::swap(dists[j],dists[j-1]); + std::swap(match[j],match[j-1]); + j--; + } + } + + for (int i=0; i<nn; ++i) { + matches[i] = match[i+skip]; + } +} + + +template <typename Distance> +void compute_ground_truth(const Matrix<typename Distance::ElementType>& dataset, const Matrix<typename Distance::ElementType>& testset, Matrix<int>& matches, + int skip=0, Distance d = Distance()) +{ + for (size_t i=0; i<testset.rows; ++i) { + find_nearest<Distance>(dataset, testset[i], matches[i], (int)matches.cols, skip, d); + } +} + + +} + +#endif //OPENCV_FLANN_GROUND_TRUTH_H_ diff --git a/include/opencv2/flann/hdf5.h b/include/opencv2/flann/hdf5.h new file mode 100644 index 0000000..80d23b9 --- /dev/null +++ b/include/opencv2/flann/hdf5.h @@ -0,0 +1,231 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_HDF5_H_ +#define OPENCV_FLANN_HDF5_H_ + +#include <hdf5.h> + +#include "matrix.h" + + +namespace cvflann +{ + +namespace +{ + +template<typename T> +hid_t get_hdf5_type() +{ + throw FLANNException("Unsupported type for IO operations"); +} + +template<> +hid_t get_hdf5_type<char>() { return H5T_NATIVE_CHAR; } +template<> +hid_t get_hdf5_type<unsigned char>() { return H5T_NATIVE_UCHAR; } +template<> +hid_t get_hdf5_type<short int>() { return H5T_NATIVE_SHORT; } +template<> +hid_t get_hdf5_type<unsigned short int>() { return H5T_NATIVE_USHORT; } +template<> +hid_t get_hdf5_type<int>() { return H5T_NATIVE_INT; } +template<> +hid_t get_hdf5_type<unsigned int>() { return H5T_NATIVE_UINT; } +template<> +hid_t get_hdf5_type<long>() { return H5T_NATIVE_LONG; } +template<> +hid_t get_hdf5_type<unsigned long>() { return H5T_NATIVE_ULONG; } +template<> +hid_t get_hdf5_type<float>() { return H5T_NATIVE_FLOAT; } +template<> +hid_t get_hdf5_type<double>() { return H5T_NATIVE_DOUBLE; } +} + + +#define CHECK_ERROR(x,y) if ((x)<0) throw FLANNException((y)); + +template<typename T> +void save_to_file(const cvflann::Matrix<T>& dataset, const String& filename, const String& name) +{ + +#if H5Eset_auto_vers == 2 + H5Eset_auto( H5E_DEFAULT, NULL, NULL ); +#else + H5Eset_auto( NULL, NULL ); +#endif + + herr_t status; + hid_t file_id; + file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + if (file_id < 0) { + file_id = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); + } + CHECK_ERROR(file_id,"Error creating hdf5 file."); + + hsize_t dimsf[2]; // dataset dimensions + dimsf[0] = dataset.rows; + dimsf[1] = dataset.cols; + + hid_t space_id = H5Screate_simple(2, dimsf, NULL); + hid_t memspace_id = H5Screate_simple(2, dimsf, NULL); + + hid_t dataset_id; +#if H5Dcreate_vers == 2 + dataset_id = H5Dcreate2(file_id, name.c_str(), get_hdf5_type<T>(), space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); +#else + dataset_id = H5Dcreate(file_id, name.c_str(), get_hdf5_type<T>(), space_id, H5P_DEFAULT); +#endif + + if (dataset_id<0) { +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + } + CHECK_ERROR(dataset_id,"Error creating or opening dataset in file."); + + status = H5Dwrite(dataset_id, get_hdf5_type<T>(), memspace_id, space_id, H5P_DEFAULT, dataset.data ); + CHECK_ERROR(status, "Error writing to dataset"); + + H5Sclose(memspace_id); + H5Sclose(space_id); + H5Dclose(dataset_id); + H5Fclose(file_id); + +} + + +template<typename T> +void load_from_file(cvflann::Matrix<T>& dataset, const String& filename, const String& name) +{ + herr_t status; + hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + CHECK_ERROR(file_id,"Error opening hdf5 file."); + + hid_t dataset_id; +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + CHECK_ERROR(dataset_id,"Error opening dataset in file."); + + hid_t space_id = H5Dget_space(dataset_id); + + hsize_t dims_out[2]; + H5Sget_simple_extent_dims(space_id, dims_out, NULL); + + dataset = cvflann::Matrix<T>(new T[dims_out[0]*dims_out[1]], dims_out[0], dims_out[1]); + + status = H5Dread(dataset_id, get_hdf5_type<T>(), H5S_ALL, H5S_ALL, H5P_DEFAULT, dataset[0]); + CHECK_ERROR(status, "Error reading dataset"); + + H5Sclose(space_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} + + +#ifdef HAVE_MPI + +namespace mpi +{ +/** + * Loads a the hyperslice corresponding to this processor from a hdf5 file. + * @param flann_dataset Dataset where the data is loaded + * @param filename HDF5 file name + * @param name Name of dataset inside file + */ +template<typename T> +void load_from_file(cvflann::Matrix<T>& dataset, const String& filename, const String& name) +{ + MPI_Comm comm = MPI_COMM_WORLD; + MPI_Info info = MPI_INFO_NULL; + + int mpi_size, mpi_rank; + MPI_Comm_size(comm, &mpi_size); + MPI_Comm_rank(comm, &mpi_rank); + + herr_t status; + + hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_mpio(plist_id, comm, info); + hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, plist_id); + CHECK_ERROR(file_id,"Error opening hdf5 file."); + H5Pclose(plist_id); + hid_t dataset_id; +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + CHECK_ERROR(dataset_id,"Error opening dataset in file."); + + hid_t space_id = H5Dget_space(dataset_id); + hsize_t dims[2]; + H5Sget_simple_extent_dims(space_id, dims, NULL); + + hsize_t count[2]; + hsize_t offset[2]; + + hsize_t item_cnt = dims[0]/mpi_size+(dims[0]%mpi_size==0 ? 0 : 1); + hsize_t cnt = (mpi_rank<mpi_size-1 ? item_cnt : dims[0]-item_cnt*(mpi_size-1)); + + count[0] = cnt; + count[1] = dims[1]; + offset[0] = mpi_rank*item_cnt; + offset[1] = 0; + + hid_t memspace_id = H5Screate_simple(2,count,NULL); + + H5Sselect_hyperslab(space_id, H5S_SELECT_SET, offset, NULL, count, NULL); + + dataset.rows = count[0]; + dataset.cols = count[1]; + dataset.data = new T[dataset.rows*dataset.cols]; + + plist_id = H5Pcreate(H5P_DATASET_XFER); + H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE); + status = H5Dread(dataset_id, get_hdf5_type<T>(), memspace_id, space_id, plist_id, dataset.data); + CHECK_ERROR(status, "Error reading dataset"); + + H5Pclose(plist_id); + H5Sclose(space_id); + H5Sclose(memspace_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} +} +#endif // HAVE_MPI +} // namespace cvflann::mpi + +#endif /* OPENCV_FLANN_HDF5_H_ */ diff --git a/include/opencv2/flann/heap.h b/include/opencv2/flann/heap.h new file mode 100644 index 0000000..92a6ea6 --- /dev/null +++ b/include/opencv2/flann/heap.h @@ -0,0 +1,165 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_HEAP_H_ +#define OPENCV_FLANN_HEAP_H_ + +#include <algorithm> +#include <vector> + +namespace cvflann +{ + +/** + * Priority Queue Implementation + * + * The priority queue is implemented with a heap. A heap is a complete + * (full) binary tree in which each parent is less than both of its + * children, but the order of the children is unspecified. + */ +template <typename T> +class Heap +{ + + /** + * Storage array for the heap. + * Type T must be comparable. + */ + std::vector<T> heap; + int length; + + /** + * Number of element in the heap + */ + int count; + + + +public: + /** + * Constructor. + * + * Params: + * sz = heap size + */ + + Heap(int sz) + { + length = sz; + heap.reserve(length); + count = 0; + } + + /** + * + * Returns: heap size + */ + int size() + { + return count; + } + + /** + * Tests if the heap is empty + * + * Returns: true is heap empty, false otherwise + */ + bool empty() + { + return size()==0; + } + + /** + * Clears the heap. + */ + void clear() + { + heap.clear(); + count = 0; + } + + struct CompareT + { + bool operator()(const T& t_1, const T& t_2) const + { + return t_2 < t_1; + } + }; + + /** + * Insert a new element in the heap. + * + * We select the next empty leaf node, and then keep moving any larger + * parents down until the right location is found to store this element. + * + * Params: + * value = the new element to be inserted in the heap + */ + void insert(T value) + { + /* If heap is full, then return without adding this element. */ + if (count == length) { + return; + } + + heap.push_back(value); + static CompareT compareT; + std::push_heap(heap.begin(), heap.end(), compareT); + ++count; + } + + + + /** + * Returns the node of minimum value from the heap (top of the heap). + * + * Params: + * value = out parameter used to return the min element + * Returns: false if heap empty + */ + bool popMin(T& value) + { + if (count == 0) { + return false; + } + + value = heap[0]; + static CompareT compareT; + std::pop_heap(heap.begin(), heap.end(), compareT); + heap.pop_back(); + --count; + + return true; /* Return old last node. */ + } +}; + +} + +#endif //OPENCV_FLANN_HEAP_H_ diff --git a/include/opencv2/flann/hierarchical_clustering_index.h b/include/opencv2/flann/hierarchical_clustering_index.h new file mode 100644 index 0000000..2a947da --- /dev/null +++ b/include/opencv2/flann/hierarchical_clustering_index.h @@ -0,0 +1,848 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ +#define OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ + +#include <algorithm> +#include <map> +#include <cassert> +#include <limits> +#include <cmath> + +#include "general.h" +#include "nn_index.h" +#include "dist.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + + +namespace cvflann +{ + +struct HierarchicalClusteringIndexParams : public IndexParams +{ + HierarchicalClusteringIndexParams(int branching = 32, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, + int trees = 4, int leaf_size = 100) + { + (*this)["algorithm"] = FLANN_INDEX_HIERARCHICAL; + // The branching factor used in the hierarchical clustering + (*this)["branching"] = branching; + // Algorithm used for picking the initial cluster centers + (*this)["centers_init"] = centers_init; + // number of parallel trees to build + (*this)["trees"] = trees; + // maximum leaf size + (*this)["leaf_size"] = leaf_size; + } +}; + + +/** + * Hierarchical index + * + * Contains a tree constructed through a hierarchical clustering + * and other information for indexing a set of points for nearest-neighbour matching. + */ +template <typename Distance> +class HierarchicalClusteringIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + +private: + + + typedef void (HierarchicalClusteringIndex::* centersAlgFunction)(int, int*, int, int*, int&); + + /** + * The function used for choosing the cluster centers. + */ + centersAlgFunction chooseCenters; + + + + /** + * Chooses the initial centers in the k-means clustering in a random manner. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * indices_length = length of indices vector + * + */ + void chooseCentersRandom(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + UniqueRandom r(indices_length); + + int index; + for (index=0; index<k; ++index) { + bool duplicate = true; + int rnd; + while (duplicate) { + duplicate = false; + rnd = r.next(); + if (rnd<0) { + centers_length = index; + return; + } + + centers[index] = dsindices[rnd]; + + for (int j=0; j<index; ++j) { + DistanceType sq = distance(dataset[centers[index]], dataset[centers[j]], dataset.cols); + if (sq<1e-16) { + duplicate = true; + } + } + } + } + + centers_length = index; + } + + + /** + * Chooses the initial centers in the k-means using Gonzales' algorithm + * so that the centers are spaced apart from each other. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void chooseCentersGonzales(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + int n = indices_length; + + int rnd = rand_int(n); + assert(rnd >=0 && rnd < n); + + centers[0] = dsindices[rnd]; + + int index; + for (index=1; index<k; ++index) { + + int best_index = -1; + DistanceType best_val = 0; + for (int j=0; j<n; ++j) { + DistanceType dist = distance(dataset[centers[0]],dataset[dsindices[j]],dataset.cols); + for (int i=1; i<index; ++i) { + DistanceType tmp_dist = distance(dataset[centers[i]],dataset[dsindices[j]],dataset.cols); + if (tmp_dist<dist) { + dist = tmp_dist; + } + } + if (dist>best_val) { + best_val = dist; + best_index = j; + } + } + if (best_index!=-1) { + centers[index] = dsindices[best_index]; + } + else { + break; + } + } + centers_length = index; + } + + + /** + * Chooses the initial centers in the k-means using the algorithm + * proposed in the KMeans++ paper: + * Arthur, David; Vassilvitskii, Sergei - k-means++: The Advantages of Careful Seeding + * + * Implementation of this function was converted from the one provided in Arthur's code. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void chooseCentersKMeanspp(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + int n = indices_length; + + double currentPot = 0; + DistanceType* closestDistSq = new DistanceType[n]; + + // Choose one random center and set the closestDistSq values + int index = rand_int(n); + assert(index >=0 && index < n); + centers[0] = dsindices[index]; + + // Computing distance^2 will have the advantage of even higher probability further to pick new centers + // far from previous centers (and this complies to "k-means++: the advantages of careful seeding" article) + for (int i = 0; i < n; i++) { + closestDistSq[i] = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + closestDistSq[i] = ensureSquareDistance<Distance>( closestDistSq[i] ); + currentPot += closestDistSq[i]; + } + + + const int numLocalTries = 1; + + // Choose each center + int centerCount; + for (centerCount = 1; centerCount < k; centerCount++) { + + // Repeat several trials + double bestNewPot = -1; + int bestNewIndex = 0; + for (int localTrial = 0; localTrial < numLocalTries; localTrial++) { + + // Choose our center - have to be slightly careful to return a valid answer even accounting + // for possible rounding errors + double randVal = rand_double(currentPot); + for (index = 0; index < n-1; index++) { + if (randVal <= closestDistSq[index]) break; + else randVal -= closestDistSq[index]; + } + + // Compute the new potential + double newPot = 0; + for (int i = 0; i < n; i++) { + DistanceType dist = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + newPot += std::min( ensureSquareDistance<Distance>(dist), closestDistSq[i] ); + } + + // Store the best result + if ((bestNewPot < 0)||(newPot < bestNewPot)) { + bestNewPot = newPot; + bestNewIndex = index; + } + } + + // Add the appropriate center + centers[centerCount] = dsindices[bestNewIndex]; + currentPot = bestNewPot; + for (int i = 0; i < n; i++) { + DistanceType dist = distance(dataset[dsindices[i]], dataset[dsindices[bestNewIndex]], dataset.cols); + closestDistSq[i] = std::min( ensureSquareDistance<Distance>(dist), closestDistSq[i] ); + } + } + + centers_length = centerCount; + + delete[] closestDistSq; + } + + + /** + * Chooses the initial centers in a way inspired by Gonzales (by Pierre-Emmanuel Viel): + * select the first point of the list as a candidate, then parse the points list. If another + * point is further than current candidate from the other centers, test if it is a good center + * of a local aggregation. If it is, replace current candidate by this point. And so on... + * + * Used with KMeansIndex that computes centers coordinates by averaging positions of clusters points, + * this doesn't make a real difference with previous methods. But used with HierarchicalClusteringIndex + * class that pick centers among existing points instead of computing the barycenters, there is a real + * improvement. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void GroupWiseCenterChooser(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + const float kSpeedUpFactor = 1.3f; + + int n = indices_length; + + DistanceType* closestDistSq = new DistanceType[n]; + + // Choose one random center and set the closestDistSq values + int index = rand_int(n); + assert(index >=0 && index < n); + centers[0] = dsindices[index]; + + for (int i = 0; i < n; i++) { + closestDistSq[i] = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + } + + + // Choose each center + int centerCount; + for (centerCount = 1; centerCount < k; centerCount++) { + + // Repeat several trials + double bestNewPot = -1; + int bestNewIndex = 0; + DistanceType furthest = 0; + for (index = 0; index < n; index++) { + + // We will test only the potential of the points further than current candidate + if( closestDistSq[index] > kSpeedUpFactor * (float)furthest ) { + + // Compute the new potential + double newPot = 0; + for (int i = 0; i < n; i++) { + newPot += std::min( distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols) + , closestDistSq[i] ); + } + + // Store the best result + if ((bestNewPot < 0)||(newPot <= bestNewPot)) { + bestNewPot = newPot; + bestNewIndex = index; + furthest = closestDistSq[index]; + } + } + } + + // Add the appropriate center + centers[centerCount] = dsindices[bestNewIndex]; + for (int i = 0; i < n; i++) { + closestDistSq[i] = std::min( distance(dataset[dsindices[i]], dataset[dsindices[bestNewIndex]], dataset.cols) + , closestDistSq[i] ); + } + } + + centers_length = centerCount; + + delete[] closestDistSq; + } + + +public: + + + /** + * Index constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the hierarchical k-means algorithm + */ + HierarchicalClusteringIndex(const Matrix<ElementType>& inputData, const IndexParams& index_params = HierarchicalClusteringIndexParams(), + Distance d = Distance()) + : dataset(inputData), params(index_params), root(NULL), indices(NULL), distance(d) + { + memoryCounter = 0; + + size_ = dataset.rows; + veclen_ = dataset.cols; + + branching_ = get_param(params,"branching",32); + centers_init_ = get_param(params,"centers_init", FLANN_CENTERS_RANDOM); + trees_ = get_param(params,"trees",4); + leaf_size_ = get_param(params,"leaf_size",100); + + if (centers_init_==FLANN_CENTERS_RANDOM) { + chooseCenters = &HierarchicalClusteringIndex::chooseCentersRandom; + } + else if (centers_init_==FLANN_CENTERS_GONZALES) { + chooseCenters = &HierarchicalClusteringIndex::chooseCentersGonzales; + } + else if (centers_init_==FLANN_CENTERS_KMEANSPP) { + chooseCenters = &HierarchicalClusteringIndex::chooseCentersKMeanspp; + } + else if (centers_init_==FLANN_CENTERS_GROUPWISE) { + chooseCenters = &HierarchicalClusteringIndex::GroupWiseCenterChooser; + } + else { + throw FLANNException("Unknown algorithm for choosing initial centers."); + } + + trees_ = get_param(params,"trees",4); + root = new NodePtr[trees_]; + indices = new int*[trees_]; + + for (int i=0; i<trees_; ++i) { + root[i] = NULL; + indices[i] = NULL; + } + } + + HierarchicalClusteringIndex(const HierarchicalClusteringIndex&); + HierarchicalClusteringIndex& operator=(const HierarchicalClusteringIndex&); + + /** + * Index destructor. + * + * Release the memory used by the index. + */ + virtual ~HierarchicalClusteringIndex() + { + free_elements(); + + if (root!=NULL) { + delete[] root; + } + + if (indices!=NULL) { + delete[] indices; + } + } + + + /** + * Release the inner elements of indices[] + */ + void free_elements() + { + if (indices!=NULL) { + for(int i=0; i<trees_; ++i) { + if (indices[i]!=NULL) { + delete[] indices[i]; + indices[i] = NULL; + } + } + } + } + + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return size_; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return veclen_; + } + + + /** + * Computes the inde memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return pool.usedMemory+pool.wastedMemory+memoryCounter; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + if (branching_<2) { + throw FLANNException("Branching factor must be at least 2"); + } + + free_elements(); + + for (int i=0; i<trees_; ++i) { + indices[i] = new int[size_]; + for (size_t j=0; j<size_; ++j) { + indices[i][j] = (int)j; + } + root[i] = pool.allocate<Node>(); + computeClustering(root[i], indices[i], (int)size_, branching_,0); + } + } + + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_HIERARCHICAL; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, branching_); + save_value(stream, trees_); + save_value(stream, centers_init_); + save_value(stream, leaf_size_); + save_value(stream, memoryCounter); + for (int i=0; i<trees_; ++i) { + save_value(stream, *indices[i], size_); + save_tree(stream, root[i], i); + } + + } + + + void loadIndex(FILE* stream) CV_OVERRIDE + { + free_elements(); + + if (root!=NULL) { + delete[] root; + } + + if (indices!=NULL) { + delete[] indices; + } + + load_value(stream, branching_); + load_value(stream, trees_); + load_value(stream, centers_init_); + load_value(stream, leaf_size_); + load_value(stream, memoryCounter); + + indices = new int*[trees_]; + root = new NodePtr[trees_]; + for (int i=0; i<trees_; ++i) { + indices[i] = new int[size_]; + load_value(stream, *indices[i], size_); + load_tree(stream, root[i], i); + } + + params["algorithm"] = getType(); + params["branching"] = branching_; + params["trees"] = trees_; + params["centers_init"] = centers_init_; + params["leaf_size"] = leaf_size_; + } + + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * searchParams = parameters that influence the search algorithm (checks) + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + + int maxChecks = get_param(searchParams,"checks",32); + + // Priority queue storing intermediate branches in the best-bin-first search + Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_); + + std::vector<bool> checked(size_,false); + int checks = 0; + for (int i=0; i<trees_; ++i) { + findNN(root[i], result, vec, checks, maxChecks, heap, checked); + } + + BranchSt branch; + while (heap->popMin(branch) && (checks<maxChecks || !result.full())) { + NodePtr node = branch.node; + findNN(node, result, vec, checks, maxChecks, heap, checked); + } + assert(result.full()); + + delete heap; + + } + + IndexParams getParameters() const CV_OVERRIDE + { + return params; + } + + +private: + + /** + * Struture representing a node in the hierarchical k-means tree. + */ + struct Node + { + /** + * The cluster center index + */ + int pivot; + /** + * The cluster size (number of points in the cluster) + */ + int size; + /** + * Child nodes (only for non-terminal nodes) + */ + Node** childs; + /** + * Node points (only for terminal nodes) + */ + int* indices; + /** + * Level + */ + int level; + }; + typedef Node* NodePtr; + + + + /** + * Alias definition for a nicer syntax. + */ + typedef BranchStruct<NodePtr, DistanceType> BranchSt; + + + + void save_tree(FILE* stream, NodePtr node, int num) + { + save_value(stream, *node); + if (node->childs==NULL) { + int indices_offset = (int)(node->indices - indices[num]); + save_value(stream, indices_offset); + } + else { + for(int i=0; i<branching_; ++i) { + save_tree(stream, node->childs[i], num); + } + } + } + + + void load_tree(FILE* stream, NodePtr& node, int num) + { + node = pool.allocate<Node>(); + load_value(stream, *node); + if (node->childs==NULL) { + int indices_offset; + load_value(stream, indices_offset); + node->indices = indices[num] + indices_offset; + } + else { + node->childs = pool.allocate<NodePtr>(branching_); + for(int i=0; i<branching_; ++i) { + load_tree(stream, node->childs[i], num); + } + } + } + + + + + void computeLabels(int* dsindices, int indices_length, int* centers, int centers_length, int* labels, DistanceType& cost) + { + cost = 0; + for (int i=0; i<indices_length; ++i) { + ElementType* point = dataset[dsindices[i]]; + DistanceType dist = distance(point, dataset[centers[0]], veclen_); + labels[i] = 0; + for (int j=1; j<centers_length; ++j) { + DistanceType new_dist = distance(point, dataset[centers[j]], veclen_); + if (dist>new_dist) { + labels[i] = j; + dist = new_dist; + } + } + cost += dist; + } + } + + /** + * The method responsible with actually doing the recursive hierarchical + * clustering + * + * Params: + * node = the node to cluster + * indices = indices of the points belonging to the current node + * branching = the branching factor to use in the clustering + * + * TODO: for 1-sized clusters don't store a cluster center (it's the same as the single cluster point) + */ + void computeClustering(NodePtr node, int* dsindices, int indices_length, int branching, int level) + { + node->size = indices_length; + node->level = level; + + if (indices_length < leaf_size_) { // leaf node + node->indices = dsindices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + std::vector<int> centers(branching); + std::vector<int> labels(indices_length); + + int centers_length; + (this->*chooseCenters)(branching, dsindices, indices_length, ¢ers[0], centers_length); + + if (centers_length<branching) { + node->indices = dsindices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + + // assign points to clusters + DistanceType cost; + computeLabels(dsindices, indices_length, ¢ers[0], centers_length, &labels[0], cost); + + node->childs = pool.allocate<NodePtr>(branching); + int start = 0; + int end = start; + for (int i=0; i<branching; ++i) { + for (int j=0; j<indices_length; ++j) { + if (labels[j]==i) { + std::swap(dsindices[j],dsindices[end]); + std::swap(labels[j],labels[end]); + end++; + } + } + + node->childs[i] = pool.allocate<Node>(); + node->childs[i]->pivot = centers[i]; + node->childs[i]->indices = NULL; + computeClustering(node->childs[i],dsindices+start, end-start, branching, level+1); + start=end; + } + } + + + + /** + * Performs one descent in the hierarchical k-means tree. The branches not + * visited are stored in a priority queue. + * + * Params: + * node = node to explore + * result = container for the k-nearest neighbors found + * vec = query points + * checks = how many points in the dataset have been checked so far + * maxChecks = maximum dataset points to checks + */ + + + void findNN(NodePtr node, ResultSet<DistanceType>& result, const ElementType* vec, int& checks, int maxChecks, + Heap<BranchSt>* heap, std::vector<bool>& checked) + { + if (node->childs==NULL) { + if (checks>=maxChecks) { + if (result.full()) return; + } + for (int i=0; i<node->size; ++i) { + int index = node->indices[i]; + if (!checked[index]) { + DistanceType dist = distance(dataset[index], vec, veclen_); + result.addPoint(dist, index); + checked[index] = true; + ++checks; + } + } + } + else { + DistanceType* domain_distances = new DistanceType[branching_]; + int best_index = 0; + domain_distances[best_index] = distance(vec, dataset[node->childs[best_index]->pivot], veclen_); + for (int i=1; i<branching_; ++i) { + domain_distances[i] = distance(vec, dataset[node->childs[i]->pivot], veclen_); + if (domain_distances[i]<domain_distances[best_index]) { + best_index = i; + } + } + for (int i=0; i<branching_; ++i) { + if (i!=best_index) { + heap->insert(BranchSt(node->childs[i],domain_distances[i])); + } + } + delete[] domain_distances; + findNN(node->childs[best_index],result,vec, checks, maxChecks, heap, checked); + } + } + +private: + + + /** + * The dataset used by this index + */ + const Matrix<ElementType> dataset; + + /** + * Parameters used by this index + */ + IndexParams params; + + + /** + * Number of features in the dataset. + */ + size_t size_; + + /** + * Length of each feature. + */ + size_t veclen_; + + /** + * The root node in the tree. + */ + NodePtr* root; + + /** + * Array of indices to vectors in the dataset. + */ + int** indices; + + + /** + * The distance + */ + Distance distance; + + /** + * Pooled memory allocator. + * + * Using a pooled memory allocator is more efficient + * than allocating memory directly when there is a large + * number small of memory allocations. + */ + PooledAllocator pool; + + /** + * Memory occupied by the index. + */ + int memoryCounter; + + /** index parameters */ + int branching_; + int trees_; + flann_centers_init_t centers_init_; + int leaf_size_; + + +}; + +} + +#endif /* OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ */ diff --git a/include/opencv2/flann/index_testing.h b/include/opencv2/flann/index_testing.h new file mode 100644 index 0000000..d764004 --- /dev/null +++ b/include/opencv2/flann/index_testing.h @@ -0,0 +1,318 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_INDEX_TESTING_H_ +#define OPENCV_FLANN_INDEX_TESTING_H_ + +#include <cstring> +#include <cassert> +#include <cmath> + +#include "matrix.h" +#include "nn_index.h" +#include "result_set.h" +#include "logger.h" +#include "timer.h" + + +namespace cvflann +{ + +inline int countCorrectMatches(int* neighbors, int* groundTruth, int n) +{ + int count = 0; + for (int i=0; i<n; ++i) { + for (int k=0; k<n; ++k) { + if (neighbors[i]==groundTruth[k]) { + count++; + break; + } + } + } + return count; +} + + +template <typename Distance> +typename Distance::ResultType computeDistanceRaport(const Matrix<typename Distance::ElementType>& inputData, typename Distance::ElementType* target, + int* neighbors, int* groundTruth, int veclen, int n, const Distance& distance) +{ + typedef typename Distance::ResultType DistanceType; + + DistanceType ret = 0; + for (int i=0; i<n; ++i) { + DistanceType den = distance(inputData[groundTruth[i]], target, veclen); + DistanceType num = distance(inputData[neighbors[i]], target, veclen); + + if ((den==0)&&(num==0)) { + ret += 1; + } + else { + ret += num/den; + } + } + + return ret; +} + +template <typename Distance> +float search_with_ground_truth(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData, + const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches, int nn, int checks, + float& time, typename Distance::ResultType& dist, const Distance& distance, int skipMatches) +{ + typedef typename Distance::ResultType DistanceType; + + if (matches.cols<size_t(nn)) { + Logger::info("matches.cols=%d, nn=%d\n",matches.cols,nn); + + throw FLANNException("Ground truth is not computed for as many neighbors as requested"); + } + + KNNResultSet<DistanceType> resultSet(nn+skipMatches); + SearchParams searchParams(checks); + + std::vector<int> indices(nn+skipMatches); + std::vector<DistanceType> dists(nn+skipMatches); + int* neighbors = &indices[skipMatches]; + + int correct = 0; + DistanceType distR = 0; + StartStopTimer t; + int repeats = 0; + while (t.value<0.2) { + repeats++; + t.start(); + correct = 0; + distR = 0; + for (size_t i = 0; i < testData.rows; i++) { + resultSet.init(&indices[0], &dists[0]); + index.findNeighbors(resultSet, testData[i], searchParams); + + correct += countCorrectMatches(neighbors,matches[i], nn); + distR += computeDistanceRaport<Distance>(inputData, testData[i], neighbors, matches[i], (int)testData.cols, nn, distance); + } + t.stop(); + } + time = float(t.value/repeats); + + float precicion = (float)correct/(nn*testData.rows); + + dist = distR/(testData.rows*nn); + + Logger::info("%8d %10.4g %10.5g %10.5g %10.5g\n", + checks, precicion, time, 1000.0 * time / testData.rows, dist); + + return precicion; +} + + +template <typename Distance> +float test_index_checks(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData, + const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches, + int checks, float& precision, const Distance& distance, int nn = 1, int skipMatches = 0) +{ + typedef typename Distance::ResultType DistanceType; + + Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + Logger::info("---------------------------------------------------------\n"); + + float time = 0; + DistanceType dist = 0; + precision = search_with_ground_truth(index, inputData, testData, matches, nn, checks, time, dist, distance, skipMatches); + + return time; +} + +template <typename Distance> +float test_index_precision(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData, + const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches, + float precision, int& checks, const Distance& distance, int nn = 1, int skipMatches = 0) +{ + typedef typename Distance::ResultType DistanceType; + const float SEARCH_EPS = 0.001f; + + Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + Logger::info("---------------------------------------------------------\n"); + + int c2 = 1; + float p2; + int c1 = 1; + //float p1; + float time; + DistanceType dist; + + p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches); + + if (p2>precision) { + Logger::info("Got as close as I can\n"); + checks = c2; + return time; + } + + while (p2<precision) { + c1 = c2; + //p1 = p2; + c2 *=2; + p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches); + } + + int cx; + float realPrecision; + if (fabs(p2-precision)>SEARCH_EPS) { + Logger::info("Start linear estimation\n"); + // after we got to values in the vecinity of the desired precision + // use linear approximation get a better estimation + + cx = (c1+c2)/2; + realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches); + while (fabs(realPrecision-precision)>SEARCH_EPS) { + + if (realPrecision<precision) { + c1 = cx; + } + else { + c2 = cx; + } + cx = (c1+c2)/2; + if (cx==c1) { + Logger::info("Got as close as I can\n"); + break; + } + realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches); + } + + c2 = cx; + p2 = realPrecision; + + } + else { + Logger::info("No need for linear estimation\n"); + cx = c2; + realPrecision = p2; + } + + checks = cx; + return time; +} + + +template <typename Distance> +void test_index_precisions(NNIndex<Distance>& index, const Matrix<typename Distance::ElementType>& inputData, + const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches, + float* precisions, int precisions_length, const Distance& distance, int nn = 1, int skipMatches = 0, float maxTime = 0) +{ + typedef typename Distance::ResultType DistanceType; + + const float SEARCH_EPS = 0.001; + + // make sure precisions array is sorted + std::sort(precisions, precisions+precisions_length); + + int pindex = 0; + float precision = precisions[pindex]; + + Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + Logger::info("---------------------------------------------------------\n"); + + int c2 = 1; + float p2; + + int c1 = 1; + float p1; + + float time; + DistanceType dist; + + p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches); + + // if precision for 1 run down the tree is already + // better then some of the requested precisions, then + // skip those + while (precisions[pindex]<p2 && pindex<precisions_length) { + pindex++; + } + + if (pindex==precisions_length) { + Logger::info("Got as close as I can\n"); + return; + } + + for (int i=pindex; i<precisions_length; ++i) { + + precision = precisions[i]; + while (p2<precision) { + c1 = c2; + p1 = p2; + c2 *=2; + p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches); + if ((maxTime> 0)&&(time > maxTime)&&(p2<precision)) return; + } + + int cx; + float realPrecision; + if (fabs(p2-precision)>SEARCH_EPS) { + Logger::info("Start linear estimation\n"); + // after we got to values in the vecinity of the desired precision + // use linear approximation get a better estimation + + cx = (c1+c2)/2; + realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches); + while (fabs(realPrecision-precision)>SEARCH_EPS) { + + if (realPrecision<precision) { + c1 = cx; + } + else { + c2 = cx; + } + cx = (c1+c2)/2; + if (cx==c1) { + Logger::info("Got as close as I can\n"); + break; + } + realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches); + } + + c2 = cx; + p2 = realPrecision; + + } + else { + Logger::info("No need for linear estimation\n"); + cx = c2; + realPrecision = p2; + } + + } +} + +} + +#endif //OPENCV_FLANN_INDEX_TESTING_H_ diff --git a/include/opencv2/flann/kdtree_index.h b/include/opencv2/flann/kdtree_index.h new file mode 100644 index 0000000..c233515 --- /dev/null +++ b/include/opencv2/flann/kdtree_index.h @@ -0,0 +1,626 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_KDTREE_INDEX_H_ +#define OPENCV_FLANN_KDTREE_INDEX_H_ + +#include <algorithm> +#include <map> +#include <cassert> +#include <cstring> + +#include "general.h" +#include "nn_index.h" +#include "dynamic_bitset.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + + +namespace cvflann +{ + +struct KDTreeIndexParams : public IndexParams +{ + KDTreeIndexParams(int trees = 4) + { + (*this)["algorithm"] = FLANN_INDEX_KDTREE; + (*this)["trees"] = trees; + } +}; + + +/** + * Randomized kd-tree index + * + * Contains the k-d trees and other information for indexing a set of points + * for nearest-neighbor matching. + */ +template <typename Distance> +class KDTreeIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + /** + * KDTree constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the kdtree algorithm + */ + KDTreeIndex(const Matrix<ElementType>& inputData, const IndexParams& params = KDTreeIndexParams(), + Distance d = Distance() ) : + dataset_(inputData), index_params_(params), distance_(d) + { + size_ = dataset_.rows; + veclen_ = dataset_.cols; + + trees_ = get_param(index_params_,"trees",4); + tree_roots_ = new NodePtr[trees_]; + + // Create a permutable array of indices to the input vectors. + vind_.resize(size_); + for (size_t i = 0; i < size_; ++i) { + vind_[i] = int(i); + } + + mean_ = new DistanceType[veclen_]; + var_ = new DistanceType[veclen_]; + } + + + KDTreeIndex(const KDTreeIndex&); + KDTreeIndex& operator=(const KDTreeIndex&); + + /** + * Standard destructor + */ + ~KDTreeIndex() + { + if (tree_roots_!=NULL) { + delete[] tree_roots_; + } + delete[] mean_; + delete[] var_; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + /* Construct the randomized trees. */ + for (int i = 0; i < trees_; i++) { + /* Randomize the order of vectors to allow for unbiased sampling. */ +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(vind_); +#else + std::random_shuffle(vind_.begin(), vind_.end()); +#endif + + tree_roots_[i] = divideTree(&vind_[0], int(size_) ); + } + } + + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_KDTREE; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, trees_); + for (int i=0; i<trees_; ++i) { + save_tree(stream, tree_roots_[i]); + } + } + + + + void loadIndex(FILE* stream) CV_OVERRIDE + { + load_value(stream, trees_); + if (tree_roots_!=NULL) { + delete[] tree_roots_; + } + tree_roots_ = new NodePtr[trees_]; + for (int i=0; i<trees_; ++i) { + load_tree(stream,tree_roots_[i]); + } + + index_params_["algorithm"] = getType(); + index_params_["trees"] = tree_roots_; + } + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return size_; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return veclen_; + } + + /** + * Computes the inde memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return int(pool_.usedMemory+pool_.wastedMemory+dataset_.rows*sizeof(int)); // pool memory and vind array memory + } + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * maxCheck = the maximum number of restarts (in a best-bin-first manner) + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + int maxChecks = get_param(searchParams,"checks", 32); + float epsError = 1+get_param(searchParams,"eps",0.0f); + + if (maxChecks==FLANN_CHECKS_UNLIMITED) { + getExactNeighbors(result, vec, epsError); + } + else { + getNeighbors(result, vec, maxChecks, epsError); + } + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + +private: + + + /*--------------------- Internal Data Structures --------------------------*/ + struct Node + { + /** + * Dimension used for subdivision. + */ + int divfeat; + /** + * The values used for subdivision. + */ + DistanceType divval; + /** + * The child nodes. + */ + Node* child1, * child2; + }; + typedef Node* NodePtr; + typedef BranchStruct<NodePtr, DistanceType> BranchSt; + typedef BranchSt* Branch; + + + + void save_tree(FILE* stream, NodePtr tree) + { + save_value(stream, *tree); + if (tree->child1!=NULL) { + save_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + save_tree(stream, tree->child2); + } + } + + + void load_tree(FILE* stream, NodePtr& tree) + { + tree = pool_.allocate<Node>(); + load_value(stream, *tree); + if (tree->child1!=NULL) { + load_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + load_tree(stream, tree->child2); + } + } + + + /** + * Create a tree node that subdivides the list of vecs from vind[first] + * to vind[last]. The routine is called recursively on each sublist. + * Place a pointer to this new tree node in the location pTree. + * + * Params: pTree = the new node to create + * first = index of the first vector + * last = index of the last vector + */ + NodePtr divideTree(int* ind, int count) + { + NodePtr node = pool_.allocate<Node>(); // allocate memory + + /* If too few exemplars remain, then make this a leaf node. */ + if ( count == 1) { + node->child1 = node->child2 = NULL; /* Mark as leaf node. */ + node->divfeat = *ind; /* Store index of this vec. */ + } + else { + int idx; + int cutfeat; + DistanceType cutval; + meanSplit(ind, count, idx, cutfeat, cutval); + + node->divfeat = cutfeat; + node->divval = cutval; + node->child1 = divideTree(ind, idx); + node->child2 = divideTree(ind+idx, count-idx); + } + + return node; + } + + + /** + * Choose which feature to use in order to subdivide this set of vectors. + * Make a random choice among those with the highest variance, and use + * its variance as the threshold value. + */ + void meanSplit(int* ind, int count, int& index, int& cutfeat, DistanceType& cutval) + { + memset(mean_,0,veclen_*sizeof(DistanceType)); + memset(var_,0,veclen_*sizeof(DistanceType)); + + /* Compute mean values. Only the first SAMPLE_MEAN values need to be + sampled to get a good estimate. + */ + int cnt = std::min((int)SAMPLE_MEAN+1, count); + for (int j = 0; j < cnt; ++j) { + ElementType* v = dataset_[ind[j]]; + for (size_t k=0; k<veclen_; ++k) { + mean_[k] += v[k]; + } + } + for (size_t k=0; k<veclen_; ++k) { + mean_[k] /= cnt; + } + + /* Compute variances (no need to divide by count). */ + for (int j = 0; j < cnt; ++j) { + ElementType* v = dataset_[ind[j]]; + for (size_t k=0; k<veclen_; ++k) { + DistanceType dist = v[k] - mean_[k]; + var_[k] += dist * dist; + } + } + /* Select one of the highest variance indices at random. */ + cutfeat = selectDivision(var_); + cutval = mean_[cutfeat]; + + int lim1, lim2; + planeSplit(ind, count, cutfeat, cutval, lim1, lim2); + + if (lim1>count/2) index = lim1; + else if (lim2<count/2) index = lim2; + else index = count/2; + + /* If either list is empty, it means that all remaining features + * are identical. Split in the middle to maintain a balanced tree. + */ + if ((lim1==count)||(lim2==0)) index = count/2; + } + + + /** + * Select the top RAND_DIM largest values from v and return the index of + * one of these selected at random. + */ + int selectDivision(DistanceType* v) + { + int num = 0; + size_t topind[RAND_DIM]; + + /* Create a list of the indices of the top RAND_DIM values. */ + for (size_t i = 0; i < veclen_; ++i) { + if ((num < RAND_DIM)||(v[i] > v[topind[num-1]])) { + /* Put this element at end of topind. */ + if (num < RAND_DIM) { + topind[num++] = i; /* Add to list. */ + } + else { + topind[num-1] = i; /* Replace last element. */ + } + /* Bubble end value down to right location by repeated swapping. */ + int j = num - 1; + while (j > 0 && v[topind[j]] > v[topind[j-1]]) { + std::swap(topind[j], topind[j-1]); + --j; + } + } + } + /* Select a random integer in range [0,num-1], and return that index. */ + int rnd = rand_int(num); + return (int)topind[rnd]; + } + + + /** + * Subdivide the list of points by a plane perpendicular on axe corresponding + * to the 'cutfeat' dimension at 'cutval' position. + * + * On return: + * dataset[ind[0..lim1-1]][cutfeat]<cutval + * dataset[ind[lim1..lim2-1]][cutfeat]==cutval + * dataset[ind[lim2..count]][cutfeat]>cutval + */ + void planeSplit(int* ind, int count, int cutfeat, DistanceType cutval, int& lim1, int& lim2) + { + /* Move vector indices for left subtree to front of list. */ + int left = 0; + int right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]<cutval) ++left; + while (left<=right && dataset_[ind[right]][cutfeat]>=cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + lim1 = left; + right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]<=cutval) ++left; + while (left<=right && dataset_[ind[right]][cutfeat]>cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + lim2 = left; + } + + /** + * Performs an exact nearest neighbor search. The exact search performs a full + * traversal of the tree. + */ + void getExactNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, float epsError) + { + // checkID -= 1; /* Set a different unique ID for each search. */ + + if (trees_ > 1) { + fprintf(stderr,"It doesn't make any sense to use more than one tree for exact search"); + } + if (trees_>0) { + searchLevelExact(result, vec, tree_roots_[0], 0.0, epsError); + } + assert(result.full()); + } + + /** + * Performs the approximate nearest-neighbor search. The search is approximate + * because the tree traversal is abandoned after a given number of descends in + * the tree. + */ + void getNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, int maxCheck, float epsError) + { + int i; + BranchSt branch; + + int checkCount = 0; + Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_); + DynamicBitset checked(size_); + + /* Search once through each tree down to root. */ + for (i = 0; i < trees_; ++i) { + searchLevel(result, vec, tree_roots_[i], 0, checkCount, maxCheck, epsError, heap, checked); + } + + /* Keep searching other branches from heap until finished. */ + while ( heap->popMin(branch) && (checkCount < maxCheck || !result.full() )) { + searchLevel(result, vec, branch.node, branch.mindist, checkCount, maxCheck, epsError, heap, checked); + } + + delete heap; + + assert(result.full()); + } + + + /** + * Search starting from a given node of the tree. Based on any mismatches at + * higher levels, all exemplars below this level must have a distance of + * at least "mindistsq". + */ + void searchLevel(ResultSet<DistanceType>& result_set, const ElementType* vec, NodePtr node, DistanceType mindist, int& checkCount, int maxCheck, + float epsError, Heap<BranchSt>* heap, DynamicBitset& checked) + { + if (result_set.worstDist()<mindist) { + // printf("Ignoring branch, too far\n"); + return; + } + + /* If this is a leaf node, then do check and return. */ + if ((node->child1 == NULL)&&(node->child2 == NULL)) { + /* Do not check same node more than once when searching multiple trees. + Once a vector is checked, we set its location in vind to the + current checkID. + */ + int index = node->divfeat; + if ( checked.test(index) || ((checkCount>=maxCheck)&& result_set.full()) ) return; + checked.set(index); + checkCount++; + + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result_set.addPoint(dist,index); + + return; + } + + /* Which child branch should be taken first? */ + ElementType val = vec[node->divfeat]; + DistanceType diff = val - node->divval; + NodePtr bestChild = (diff < 0) ? node->child1 : node->child2; + NodePtr otherChild = (diff < 0) ? node->child2 : node->child1; + + /* Create a branch record for the branch not taken. Add distance + of this feature boundary (we don't attempt to correct for any + use of this feature in a parent node, which is unlikely to + happen and would have only a small effect). Don't bother + adding more branches to heap after halfway point, as cost of + adding exceeds their value. + */ + + DistanceType new_distsq = mindist + distance_.accum_dist(val, node->divval, node->divfeat); + // if (2 * checkCount < maxCheck || !result.full()) { + if ((new_distsq*epsError < result_set.worstDist())|| !result_set.full()) { + heap->insert( BranchSt(otherChild, new_distsq) ); + } + + /* Call recursively to search next level down. */ + searchLevel(result_set, vec, bestChild, mindist, checkCount, maxCheck, epsError, heap, checked); + } + + /** + * Performs an exact search in the tree starting from a node. + */ + void searchLevelExact(ResultSet<DistanceType>& result_set, const ElementType* vec, const NodePtr node, DistanceType mindist, const float epsError) + { + /* If this is a leaf node, then do check and return. */ + if ((node->child1 == NULL)&&(node->child2 == NULL)) { + int index = node->divfeat; + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result_set.addPoint(dist,index); + return; + } + + /* Which child branch should be taken first? */ + ElementType val = vec[node->divfeat]; + DistanceType diff = val - node->divval; + NodePtr bestChild = (diff < 0) ? node->child1 : node->child2; + NodePtr otherChild = (diff < 0) ? node->child2 : node->child1; + + /* Create a branch record for the branch not taken. Add distance + of this feature boundary (we don't attempt to correct for any + use of this feature in a parent node, which is unlikely to + happen and would have only a small effect). Don't bother + adding more branches to heap after halfway point, as cost of + adding exceeds their value. + */ + + DistanceType new_distsq = mindist + distance_.accum_dist(val, node->divval, node->divfeat); + + /* Call recursively to search next level down. */ + searchLevelExact(result_set, vec, bestChild, mindist, epsError); + + if (new_distsq*epsError<=result_set.worstDist()) { + searchLevelExact(result_set, vec, otherChild, new_distsq, epsError); + } + } + + +private: + + enum + { + /** + * To improve efficiency, only SAMPLE_MEAN random values are used to + * compute the mean and variance at each level when building a tree. + * A value of 100 seems to perform as well as using all values. + */ + SAMPLE_MEAN = 100, + /** + * Top random dimensions to consider + * + * When creating random trees, the dimension on which to subdivide is + * selected at random from among the top RAND_DIM dimensions with the + * highest variance. A value of 5 works well. + */ + RAND_DIM=5 + }; + + + /** + * Number of randomized trees that are used + */ + int trees_; + + /** + * Array of indices to vectors in the dataset. + */ + std::vector<int> vind_; + + /** + * The dataset used by this index + */ + const Matrix<ElementType> dataset_; + + IndexParams index_params_; + + size_t size_; + size_t veclen_; + + + DistanceType* mean_; + DistanceType* var_; + + + /** + * Array of k-d trees used to find neighbours. + */ + NodePtr* tree_roots_; + + /** + * Pooled memory allocator. + * + * Using a pooled memory allocator is more efficient + * than allocating memory directly when there is a large + * number small of memory allocations. + */ + PooledAllocator pool_; + + Distance distance_; + + +}; // class KDTreeForest + +} + +#endif //OPENCV_FLANN_KDTREE_INDEX_H_ diff --git a/include/opencv2/flann/kdtree_single_index.h b/include/opencv2/flann/kdtree_single_index.h new file mode 100644 index 0000000..22a28d0 --- /dev/null +++ b/include/opencv2/flann/kdtree_single_index.h @@ -0,0 +1,635 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ +#define OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ + +#include <algorithm> +#include <map> +#include <cassert> +#include <cstring> + +#include "general.h" +#include "nn_index.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + +namespace cvflann +{ + +struct KDTreeSingleIndexParams : public IndexParams +{ + KDTreeSingleIndexParams(int leaf_max_size = 10, bool reorder = true, int dim = -1) + { + (*this)["algorithm"] = FLANN_INDEX_KDTREE_SINGLE; + (*this)["leaf_max_size"] = leaf_max_size; + (*this)["reorder"] = reorder; + (*this)["dim"] = dim; + } +}; + + +/** + * Randomized kd-tree index + * + * Contains the k-d trees and other information for indexing a set of points + * for nearest-neighbor matching. + */ +template <typename Distance> +class KDTreeSingleIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + /** + * KDTree constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the kdtree algorithm + */ + KDTreeSingleIndex(const Matrix<ElementType>& inputData, const IndexParams& params = KDTreeSingleIndexParams(), + Distance d = Distance() ) : + dataset_(inputData), index_params_(params), distance_(d) + { + size_ = dataset_.rows; + dim_ = dataset_.cols; + root_node_ = 0; + int dim_param = get_param(params,"dim",-1); + if (dim_param>0) dim_ = dim_param; + leaf_max_size_ = get_param(params,"leaf_max_size",10); + reorder_ = get_param(params,"reorder",true); + + // Create a permutable array of indices to the input vectors. + vind_.resize(size_); + for (size_t i = 0; i < size_; i++) { + vind_[i] = (int)i; + } + } + + KDTreeSingleIndex(const KDTreeSingleIndex&); + KDTreeSingleIndex& operator=(const KDTreeSingleIndex&); + + /** + * Standard destructor + */ + ~KDTreeSingleIndex() + { + if (reorder_) delete[] data_.data; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + computeBoundingBox(root_bbox_); + root_node_ = divideTree(0, (int)size_, root_bbox_ ); // construct the tree + + if (reorder_) { + delete[] data_.data; + data_ = cvflann::Matrix<ElementType>(new ElementType[size_*dim_], size_, dim_); + for (size_t i=0; i<size_; ++i) { + for (size_t j=0; j<dim_; ++j) { + data_[i][j] = dataset_[vind_[i]][j]; + } + } + } + else { + data_ = dataset_; + } + } + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_KDTREE_SINGLE; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, size_); + save_value(stream, dim_); + save_value(stream, root_bbox_); + save_value(stream, reorder_); + save_value(stream, leaf_max_size_); + save_value(stream, vind_); + if (reorder_) { + save_value(stream, data_); + } + save_tree(stream, root_node_); + } + + + void loadIndex(FILE* stream) CV_OVERRIDE + { + load_value(stream, size_); + load_value(stream, dim_); + load_value(stream, root_bbox_); + load_value(stream, reorder_); + load_value(stream, leaf_max_size_); + load_value(stream, vind_); + if (reorder_) { + load_value(stream, data_); + } + else { + data_ = dataset_; + } + load_tree(stream, root_node_); + + + index_params_["algorithm"] = getType(); + index_params_["leaf_max_size"] = leaf_max_size_; + index_params_["reorder"] = reorder_; + } + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return size_; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return dim_; + } + + /** + * Computes the inde memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return (int)(pool_.usedMemory+pool_.wastedMemory+dataset_.rows*sizeof(int)); // pool memory and vind array memory + } + + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE + { + assert(queries.cols == veclen()); + assert(indices.rows >= queries.rows); + assert(dists.rows >= queries.rows); + assert(int(indices.cols) >= knn); + assert(int(dists.cols) >= knn); + + KNNSimpleResultSet<DistanceType> resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.init(indices[i], dists[i]); + findNeighbors(resultSet, queries[i], params); + } + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * maxCheck = the maximum number of restarts (in a best-bin-first manner) + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + float epsError = 1+get_param(searchParams,"eps",0.0f); + + std::vector<DistanceType> dists(dim_,0); + DistanceType distsq = computeInitialDistances(vec, dists); + searchLevel(result, vec, root_node_, distsq, dists, epsError); + } + +private: + + + /*--------------------- Internal Data Structures --------------------------*/ + struct Node + { + /** + * Indices of points in leaf node + */ + int left, right; + /** + * Dimension used for subdivision. + */ + int divfeat; + /** + * The values used for subdivision. + */ + DistanceType divlow, divhigh; + /** + * The child nodes. + */ + Node* child1, * child2; + }; + typedef Node* NodePtr; + + + struct Interval + { + DistanceType low, high; + }; + + typedef std::vector<Interval> BoundingBox; + + typedef BranchStruct<NodePtr, DistanceType> BranchSt; + typedef BranchSt* Branch; + + + + + void save_tree(FILE* stream, NodePtr tree) + { + save_value(stream, *tree); + if (tree->child1!=NULL) { + save_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + save_tree(stream, tree->child2); + } + } + + + void load_tree(FILE* stream, NodePtr& tree) + { + tree = pool_.allocate<Node>(); + load_value(stream, *tree); + if (tree->child1!=NULL) { + load_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + load_tree(stream, tree->child2); + } + } + + + void computeBoundingBox(BoundingBox& bbox) + { + bbox.resize(dim_); + for (size_t i=0; i<dim_; ++i) { + bbox[i].low = (DistanceType)dataset_[0][i]; + bbox[i].high = (DistanceType)dataset_[0][i]; + } + for (size_t k=1; k<dataset_.rows; ++k) { + for (size_t i=0; i<dim_; ++i) { + if (dataset_[k][i]<bbox[i].low) bbox[i].low = (DistanceType)dataset_[k][i]; + if (dataset_[k][i]>bbox[i].high) bbox[i].high = (DistanceType)dataset_[k][i]; + } + } + } + + + /** + * Create a tree node that subdivides the list of vecs from vind[first] + * to vind[last]. The routine is called recursively on each sublist. + * Place a pointer to this new tree node in the location pTree. + * + * Params: pTree = the new node to create + * first = index of the first vector + * last = index of the last vector + */ + NodePtr divideTree(int left, int right, BoundingBox& bbox) + { + NodePtr node = pool_.allocate<Node>(); // allocate memory + + /* If too few exemplars remain, then make this a leaf node. */ + if ( (right-left) <= leaf_max_size_) { + node->child1 = node->child2 = NULL; /* Mark as leaf node. */ + node->left = left; + node->right = right; + + // compute bounding-box of leaf points + for (size_t i=0; i<dim_; ++i) { + bbox[i].low = (DistanceType)dataset_[vind_[left]][i]; + bbox[i].high = (DistanceType)dataset_[vind_[left]][i]; + } + for (int k=left+1; k<right; ++k) { + for (size_t i=0; i<dim_; ++i) { + if (bbox[i].low>dataset_[vind_[k]][i]) bbox[i].low=(DistanceType)dataset_[vind_[k]][i]; + if (bbox[i].high<dataset_[vind_[k]][i]) bbox[i].high=(DistanceType)dataset_[vind_[k]][i]; + } + } + } + else { + int idx; + int cutfeat; + DistanceType cutval; + middleSplit_(&vind_[0]+left, right-left, idx, cutfeat, cutval, bbox); + + node->divfeat = cutfeat; + + BoundingBox left_bbox(bbox); + left_bbox[cutfeat].high = cutval; + node->child1 = divideTree(left, left+idx, left_bbox); + + BoundingBox right_bbox(bbox); + right_bbox[cutfeat].low = cutval; + node->child2 = divideTree(left+idx, right, right_bbox); + + node->divlow = left_bbox[cutfeat].high; + node->divhigh = right_bbox[cutfeat].low; + + for (size_t i=0; i<dim_; ++i) { + bbox[i].low = std::min(left_bbox[i].low, right_bbox[i].low); + bbox[i].high = std::max(left_bbox[i].high, right_bbox[i].high); + } + } + + return node; + } + + void computeMinMax(int* ind, int count, int dim, ElementType& min_elem, ElementType& max_elem) + { + min_elem = dataset_[ind[0]][dim]; + max_elem = dataset_[ind[0]][dim]; + for (int i=1; i<count; ++i) { + ElementType val = dataset_[ind[i]][dim]; + if (val<min_elem) min_elem = val; + if (val>max_elem) max_elem = val; + } + } + + void middleSplit(int* ind, int count, int& index, int& cutfeat, DistanceType& cutval, const BoundingBox& bbox) + { + // find the largest span from the approximate bounding box + ElementType max_span = bbox[0].high-bbox[0].low; + cutfeat = 0; + cutval = (bbox[0].high+bbox[0].low)/2; + for (size_t i=1; i<dim_; ++i) { + ElementType span = bbox[i].high-bbox[i].low; + if (span>max_span) { + max_span = span; + cutfeat = i; + cutval = (bbox[i].high+bbox[i].low)/2; + } + } + + // compute exact span on the found dimension + ElementType min_elem, max_elem; + computeMinMax(ind, count, cutfeat, min_elem, max_elem); + cutval = (min_elem+max_elem)/2; + max_span = max_elem - min_elem; + + // check if a dimension of a largest span exists + size_t k = cutfeat; + for (size_t i=0; i<dim_; ++i) { + if (i==k) continue; + ElementType span = bbox[i].high-bbox[i].low; + if (span>max_span) { + computeMinMax(ind, count, i, min_elem, max_elem); + span = max_elem - min_elem; + if (span>max_span) { + max_span = span; + cutfeat = i; + cutval = (min_elem+max_elem)/2; + } + } + } + int lim1, lim2; + planeSplit(ind, count, cutfeat, cutval, lim1, lim2); + + if (lim1>count/2) index = lim1; + else if (lim2<count/2) index = lim2; + else index = count/2; + } + + + void middleSplit_(int* ind, int count, int& index, int& cutfeat, DistanceType& cutval, const BoundingBox& bbox) + { + const float EPS=0.00001f; + DistanceType max_span = bbox[0].high-bbox[0].low; + for (size_t i=1; i<dim_; ++i) { + DistanceType span = bbox[i].high-bbox[i].low; + if (span>max_span) { + max_span = span; + } + } + DistanceType max_spread = -1; + cutfeat = 0; + for (size_t i=0; i<dim_; ++i) { + DistanceType span = bbox[i].high-bbox[i].low; + if (span>(DistanceType)((1-EPS)*max_span)) { + ElementType min_elem, max_elem; + computeMinMax(ind, count, cutfeat, min_elem, max_elem); + DistanceType spread = (DistanceType)(max_elem-min_elem); + if (spread>max_spread) { + cutfeat = (int)i; + max_spread = spread; + } + } + } + // split in the middle + DistanceType split_val = (bbox[cutfeat].low+bbox[cutfeat].high)/2; + ElementType min_elem, max_elem; + computeMinMax(ind, count, cutfeat, min_elem, max_elem); + + if (split_val<min_elem) cutval = (DistanceType)min_elem; + else if (split_val>max_elem) cutval = (DistanceType)max_elem; + else cutval = split_val; + + int lim1, lim2; + planeSplit(ind, count, cutfeat, cutval, lim1, lim2); + + if (lim1>count/2) index = lim1; + else if (lim2<count/2) index = lim2; + else index = count/2; + } + + + /** + * Subdivide the list of points by a plane perpendicular on axe corresponding + * to the 'cutfeat' dimension at 'cutval' position. + * + * On return: + * dataset[ind[0..lim1-1]][cutfeat]<cutval + * dataset[ind[lim1..lim2-1]][cutfeat]==cutval + * dataset[ind[lim2..count]][cutfeat]>cutval + */ + void planeSplit(int* ind, int count, int cutfeat, DistanceType cutval, int& lim1, int& lim2) + { + /* Move vector indices for left subtree to front of list. */ + int left = 0; + int right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]<cutval) ++left; + while (left<=right && dataset_[ind[right]][cutfeat]>=cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + /* If either list is empty, it means that all remaining features + * are identical. Split in the middle to maintain a balanced tree. + */ + lim1 = left; + right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]<=cutval) ++left; + while (left<=right && dataset_[ind[right]][cutfeat]>cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + lim2 = left; + } + + DistanceType computeInitialDistances(const ElementType* vec, std::vector<DistanceType>& dists) + { + DistanceType distsq = 0.0; + + for (size_t i = 0; i < dim_; ++i) { + if (vec[i] < root_bbox_[i].low) { + dists[i] = distance_.accum_dist(vec[i], root_bbox_[i].low, (int)i); + distsq += dists[i]; + } + if (vec[i] > root_bbox_[i].high) { + dists[i] = distance_.accum_dist(vec[i], root_bbox_[i].high, (int)i); + distsq += dists[i]; + } + } + + return distsq; + } + + /** + * Performs an exact search in the tree starting from a node. + */ + void searchLevel(ResultSet<DistanceType>& result_set, const ElementType* vec, const NodePtr node, DistanceType mindistsq, + std::vector<DistanceType>& dists, const float epsError) + { + /* If this is a leaf node, then do check and return. */ + if ((node->child1 == NULL)&&(node->child2 == NULL)) { + DistanceType worst_dist = result_set.worstDist(); + for (int i=node->left; i<node->right; ++i) { + int index = reorder_ ? i : vind_[i]; + DistanceType dist = distance_(vec, data_[index], dim_, worst_dist); + if (dist<worst_dist) { + result_set.addPoint(dist,vind_[i]); + } + } + return; + } + + /* Which child branch should be taken first? */ + int idx = node->divfeat; + ElementType val = vec[idx]; + DistanceType diff1 = val - node->divlow; + DistanceType diff2 = val - node->divhigh; + + NodePtr bestChild; + NodePtr otherChild; + DistanceType cut_dist; + if ((diff1+diff2)<0) { + bestChild = node->child1; + otherChild = node->child2; + cut_dist = distance_.accum_dist(val, node->divhigh, idx); + } + else { + bestChild = node->child2; + otherChild = node->child1; + cut_dist = distance_.accum_dist( val, node->divlow, idx); + } + + /* Call recursively to search next level down. */ + searchLevel(result_set, vec, bestChild, mindistsq, dists, epsError); + + DistanceType dst = dists[idx]; + mindistsq = mindistsq + cut_dist - dst; + dists[idx] = cut_dist; + if (mindistsq*epsError<=result_set.worstDist()) { + searchLevel(result_set, vec, otherChild, mindistsq, dists, epsError); + } + dists[idx] = dst; + } + +private: + + /** + * The dataset used by this index + */ + const Matrix<ElementType> dataset_; + + IndexParams index_params_; + + int leaf_max_size_; + bool reorder_; + + + /** + * Array of indices to vectors in the dataset. + */ + std::vector<int> vind_; + + Matrix<ElementType> data_; + + size_t size_; + size_t dim_; + + /** + * Array of k-d trees used to find neighbours. + */ + NodePtr root_node_; + + BoundingBox root_bbox_; + + /** + * Pooled memory allocator. + * + * Using a pooled memory allocator is more efficient + * than allocating memory directly when there is a large + * number small of memory allocations. + */ + PooledAllocator pool_; + + Distance distance_; +}; // class KDTree + +} + +#endif //OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ diff --git a/include/opencv2/flann/kmeans_index.h b/include/opencv2/flann/kmeans_index.h new file mode 100644 index 0000000..fe91ddd --- /dev/null +++ b/include/opencv2/flann/kmeans_index.h @@ -0,0 +1,1172 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_KMEANS_INDEX_H_ +#define OPENCV_FLANN_KMEANS_INDEX_H_ + +#include <algorithm> +#include <map> +#include <cassert> +#include <limits> +#include <cmath> + +#include "general.h" +#include "nn_index.h" +#include "dist.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" +#include "logger.h" + + +namespace cvflann +{ + +struct KMeansIndexParams : public IndexParams +{ + KMeansIndexParams(int branching = 32, int iterations = 11, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 ) + { + (*this)["algorithm"] = FLANN_INDEX_KMEANS; + // branching factor + (*this)["branching"] = branching; + // max iterations to perform in one kmeans clustering (kmeans tree) + (*this)["iterations"] = iterations; + // algorithm used for picking the initial cluster centers for kmeans tree + (*this)["centers_init"] = centers_init; + // cluster boundary index. Used when searching the kmeans tree + (*this)["cb_index"] = cb_index; + } +}; + + +/** + * Hierarchical kmeans index + * + * Contains a tree constructed through a hierarchical kmeans clustering + * and other information for indexing a set of points for nearest-neighbour matching. + */ +template <typename Distance> +class KMeansIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + + typedef void (KMeansIndex::* centersAlgFunction)(int, int*, int, int*, int&); + + /** + * The function used for choosing the cluster centers. + */ + centersAlgFunction chooseCenters; + + + + /** + * Chooses the initial centers in the k-means clustering in a random manner. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * indices_length = length of indices vector + * + */ + void chooseCentersRandom(int k, int* indices, int indices_length, int* centers, int& centers_length) + { + UniqueRandom r(indices_length); + + int index; + for (index=0; index<k; ++index) { + bool duplicate = true; + int rnd; + while (duplicate) { + duplicate = false; + rnd = r.next(); + if (rnd<0) { + centers_length = index; + return; + } + + centers[index] = indices[rnd]; + + for (int j=0; j<index; ++j) { + DistanceType sq = distance_(dataset_[centers[index]], dataset_[centers[j]], dataset_.cols); + if (sq<1e-16) { + duplicate = true; + } + } + } + } + + centers_length = index; + } + + + /** + * Chooses the initial centers in the k-means using Gonzales' algorithm + * so that the centers are spaced apart from each other. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void chooseCentersGonzales(int k, int* indices, int indices_length, int* centers, int& centers_length) + { + int n = indices_length; + + int rnd = rand_int(n); + assert(rnd >=0 && rnd < n); + + centers[0] = indices[rnd]; + + int index; + for (index=1; index<k; ++index) { + + int best_index = -1; + DistanceType best_val = 0; + for (int j=0; j<n; ++j) { + DistanceType dist = distance_(dataset_[centers[0]],dataset_[indices[j]],dataset_.cols); + for (int i=1; i<index; ++i) { + DistanceType tmp_dist = distance_(dataset_[centers[i]],dataset_[indices[j]],dataset_.cols); + if (tmp_dist<dist) { + dist = tmp_dist; + } + } + if (dist>best_val) { + best_val = dist; + best_index = j; + } + } + if (best_index!=-1) { + centers[index] = indices[best_index]; + } + else { + break; + } + } + centers_length = index; + } + + + /** + * Chooses the initial centers in the k-means using the algorithm + * proposed in the KMeans++ paper: + * Arthur, David; Vassilvitskii, Sergei - k-means++: The Advantages of Careful Seeding + * + * Implementation of this function was converted from the one provided in Arthur's code. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void chooseCentersKMeanspp(int k, int* indices, int indices_length, int* centers, int& centers_length) + { + int n = indices_length; + + double currentPot = 0; + DistanceType* closestDistSq = new DistanceType[n]; + + // Choose one random center and set the closestDistSq values + int index = rand_int(n); + assert(index >=0 && index < n); + centers[0] = indices[index]; + + for (int i = 0; i < n; i++) { + closestDistSq[i] = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols); + closestDistSq[i] = ensureSquareDistance<Distance>( closestDistSq[i] ); + currentPot += closestDistSq[i]; + } + + + const int numLocalTries = 1; + + // Choose each center + int centerCount; + for (centerCount = 1; centerCount < k; centerCount++) { + + // Repeat several trials + double bestNewPot = -1; + int bestNewIndex = -1; + for (int localTrial = 0; localTrial < numLocalTries; localTrial++) { + + // Choose our center - have to be slightly careful to return a valid answer even accounting + // for possible rounding errors + double randVal = rand_double(currentPot); + for (index = 0; index < n-1; index++) { + if (randVal <= closestDistSq[index]) break; + else randVal -= closestDistSq[index]; + } + + // Compute the new potential + double newPot = 0; + for (int i = 0; i < n; i++) { + DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols); + newPot += std::min( ensureSquareDistance<Distance>(dist), closestDistSq[i] ); + } + + // Store the best result + if ((bestNewPot < 0)||(newPot < bestNewPot)) { + bestNewPot = newPot; + bestNewIndex = index; + } + } + + // Add the appropriate center + centers[centerCount] = indices[bestNewIndex]; + currentPot = bestNewPot; + for (int i = 0; i < n; i++) { + DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[bestNewIndex]], dataset_.cols); + closestDistSq[i] = std::min( ensureSquareDistance<Distance>(dist), closestDistSq[i] ); + } + } + + centers_length = centerCount; + + delete[] closestDistSq; + } + + + +public: + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_KMEANS; + } + + class KMeansDistanceComputer : public cv::ParallelLoopBody + { + public: + KMeansDistanceComputer(Distance _distance, const Matrix<ElementType>& _dataset, + const int _branching, const int* _indices, const Matrix<double>& _dcenters, const size_t _veclen, + std::vector<int> &_new_centroids, std::vector<DistanceType> &_sq_dists) + : distance(_distance) + , dataset(_dataset) + , branching(_branching) + , indices(_indices) + , dcenters(_dcenters) + , veclen(_veclen) + , new_centroids(_new_centroids) + , sq_dists(_sq_dists) + { + } + + void operator()(const cv::Range& range) const CV_OVERRIDE + { + const int begin = range.start; + const int end = range.end; + + for( int i = begin; i<end; ++i) + { + DistanceType sq_dist(distance(dataset[indices[i]], dcenters[0], veclen)); + int new_centroid(0); + for (int j=1; j<branching; ++j) { + DistanceType new_sq_dist = distance(dataset[indices[i]], dcenters[j], veclen); + if (sq_dist>new_sq_dist) { + new_centroid = j; + sq_dist = new_sq_dist; + } + } + sq_dists[i] = sq_dist; + new_centroids[i] = new_centroid; + } + } + + private: + Distance distance; + const Matrix<ElementType>& dataset; + const int branching; + const int* indices; + const Matrix<double>& dcenters; + const size_t veclen; + std::vector<int> &new_centroids; + std::vector<DistanceType> &sq_dists; + KMeansDistanceComputer& operator=( const KMeansDistanceComputer & ) { return *this; } + }; + + /** + * Index constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the hierarchical k-means algorithm + */ + KMeansIndex(const Matrix<ElementType>& inputData, const IndexParams& params = KMeansIndexParams(), + Distance d = Distance()) + : dataset_(inputData), index_params_(params), root_(NULL), indices_(NULL), distance_(d) + { + memoryCounter_ = 0; + + size_ = dataset_.rows; + veclen_ = dataset_.cols; + + branching_ = get_param(params,"branching",32); + iterations_ = get_param(params,"iterations",11); + if (iterations_<0) { + iterations_ = (std::numeric_limits<int>::max)(); + } + centers_init_ = get_param(params,"centers_init",FLANN_CENTERS_RANDOM); + + if (centers_init_==FLANN_CENTERS_RANDOM) { + chooseCenters = &KMeansIndex::chooseCentersRandom; + } + else if (centers_init_==FLANN_CENTERS_GONZALES) { + chooseCenters = &KMeansIndex::chooseCentersGonzales; + } + else if (centers_init_==FLANN_CENTERS_KMEANSPP) { + chooseCenters = &KMeansIndex::chooseCentersKMeanspp; + } + else { + throw FLANNException("Unknown algorithm for choosing initial centers."); + } + cb_index_ = 0.4f; + + } + + + KMeansIndex(const KMeansIndex&); + KMeansIndex& operator=(const KMeansIndex&); + + + /** + * Index destructor. + * + * Release the memory used by the index. + */ + virtual ~KMeansIndex() + { + if (root_ != NULL) { + free_centers(root_); + } + if (indices_!=NULL) { + delete[] indices_; + } + } + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return size_; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return veclen_; + } + + + void set_cb_index( float index) + { + cb_index_ = index; + } + + /** + * Computes the inde memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return pool_.usedMemory+pool_.wastedMemory+memoryCounter_; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + if (branching_<2) { + throw FLANNException("Branching factor must be at least 2"); + } + + indices_ = new int[size_]; + for (size_t i=0; i<size_; ++i) { + indices_[i] = int(i); + } + + root_ = pool_.allocate<KMeansNode>(); + std::memset(root_, 0, sizeof(KMeansNode)); + + computeNodeStatistics(root_, indices_, (int)size_); + computeClustering(root_, indices_, (int)size_, branching_,0); + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, branching_); + save_value(stream, iterations_); + save_value(stream, memoryCounter_); + save_value(stream, cb_index_); + save_value(stream, *indices_, (int)size_); + + save_tree(stream, root_); + } + + + void loadIndex(FILE* stream) CV_OVERRIDE + { + load_value(stream, branching_); + load_value(stream, iterations_); + load_value(stream, memoryCounter_); + load_value(stream, cb_index_); + if (indices_!=NULL) { + delete[] indices_; + } + indices_ = new int[size_]; + load_value(stream, *indices_, size_); + + if (root_!=NULL) { + free_centers(root_); + } + load_tree(stream, root_); + + index_params_["algorithm"] = getType(); + index_params_["branching"] = branching_; + index_params_["iterations"] = iterations_; + index_params_["centers_init"] = centers_init_; + index_params_["cb_index"] = cb_index_; + + } + + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * searchParams = parameters that influence the search algorithm (checks, cb_index) + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + + int maxChecks = get_param(searchParams,"checks",32); + + if (maxChecks==FLANN_CHECKS_UNLIMITED) { + findExactNN(root_, result, vec); + } + else { + // Priority queue storing intermediate branches in the best-bin-first search + Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_); + + int checks = 0; + findNN(root_, result, vec, checks, maxChecks, heap); + + BranchSt branch; + while (heap->popMin(branch) && (checks<maxChecks || !result.full())) { + KMeansNodePtr node = branch.node; + findNN(node, result, vec, checks, maxChecks, heap); + } + assert(result.full()); + + delete heap; + } + + } + + /** + * Clustering function that takes a cut in the hierarchical k-means + * tree and return the clusters centers of that clustering. + * Params: + * numClusters = number of clusters to have in the clustering computed + * Returns: number of cluster centers + */ + int getClusterCenters(Matrix<DistanceType>& centers) + { + int numClusters = centers.rows; + if (numClusters<1) { + throw FLANNException("Number of clusters must be at least 1"); + } + + DistanceType variance; + KMeansNodePtr* clusters = new KMeansNodePtr[numClusters]; + + int clusterCount = getMinVarianceClusters(root_, clusters, numClusters, variance); + + Logger::info("Clusters requested: %d, returning %d\n",numClusters, clusterCount); + + for (int i=0; i<clusterCount; ++i) { + DistanceType* center = clusters[i]->pivot; + for (size_t j=0; j<veclen_; ++j) { + centers[i][j] = center[j]; + } + } + delete[] clusters; + + return clusterCount; + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + +private: + /** + * Struture representing a node in the hierarchical k-means tree. + */ + struct KMeansNode + { + /** + * The cluster center. + */ + DistanceType* pivot; + /** + * The cluster radius. + */ + DistanceType radius; + /** + * The cluster mean radius. + */ + DistanceType mean_radius; + /** + * The cluster variance. + */ + DistanceType variance; + /** + * The cluster size (number of points in the cluster) + */ + int size; + /** + * Child nodes (only for non-terminal nodes) + */ + KMeansNode** childs; + /** + * Node points (only for terminal nodes) + */ + int* indices; + /** + * Level + */ + int level; + }; + typedef KMeansNode* KMeansNodePtr; + + /** + * Alias definition for a nicer syntax. + */ + typedef BranchStruct<KMeansNodePtr, DistanceType> BranchSt; + + + + + void save_tree(FILE* stream, KMeansNodePtr node) + { + save_value(stream, *node); + save_value(stream, *(node->pivot), (int)veclen_); + if (node->childs==NULL) { + int indices_offset = (int)(node->indices - indices_); + save_value(stream, indices_offset); + } + else { + for(int i=0; i<branching_; ++i) { + save_tree(stream, node->childs[i]); + } + } + } + + + void load_tree(FILE* stream, KMeansNodePtr& node) + { + node = pool_.allocate<KMeansNode>(); + load_value(stream, *node); + node->pivot = new DistanceType[veclen_]; + load_value(stream, *(node->pivot), (int)veclen_); + if (node->childs==NULL) { + int indices_offset; + load_value(stream, indices_offset); + node->indices = indices_ + indices_offset; + } + else { + node->childs = pool_.allocate<KMeansNodePtr>(branching_); + for(int i=0; i<branching_; ++i) { + load_tree(stream, node->childs[i]); + } + } + } + + + /** + * Helper function + */ + void free_centers(KMeansNodePtr node) + { + delete[] node->pivot; + if (node->childs!=NULL) { + for (int k=0; k<branching_; ++k) { + free_centers(node->childs[k]); + } + } + } + + /** + * Computes the statistics of a node (mean, radius, variance). + * + * Params: + * node = the node to use + * indices = the indices of the points belonging to the node + */ + void computeNodeStatistics(KMeansNodePtr node, int* indices, int indices_length) + { + + DistanceType radius = 0; + DistanceType variance = 0; + DistanceType* mean = new DistanceType[veclen_]; + memoryCounter_ += int(veclen_*sizeof(DistanceType)); + + memset(mean,0,veclen_*sizeof(DistanceType)); + + for (size_t i=0; i<size_; ++i) { + ElementType* vec = dataset_[indices[i]]; + for (size_t j=0; j<veclen_; ++j) { + mean[j] += vec[j]; + } + variance += distance_(vec, ZeroIterator<ElementType>(), veclen_); + } + for (size_t j=0; j<veclen_; ++j) { + mean[j] /= size_; + } + variance /= size_; + variance -= distance_(mean, ZeroIterator<ElementType>(), veclen_); + + DistanceType tmp = 0; + for (int i=0; i<indices_length; ++i) { + tmp = distance_(mean, dataset_[indices[i]], veclen_); + if (tmp>radius) { + radius = tmp; + } + } + + node->variance = variance; + node->radius = radius; + node->pivot = mean; + } + + + /** + * The method responsible with actually doing the recursive hierarchical + * clustering + * + * Params: + * node = the node to cluster + * indices = indices of the points belonging to the current node + * branching = the branching factor to use in the clustering + * + * TODO: for 1-sized clusters don't store a cluster center (it's the same as the single cluster point) + */ + void computeClustering(KMeansNodePtr node, int* indices, int indices_length, int branching, int level) + { + node->size = indices_length; + node->level = level; + + if (indices_length < branching) { + node->indices = indices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + cv::AutoBuffer<int> centers_idx_buf(branching); + int* centers_idx = centers_idx_buf.data(); + int centers_length; + (this->*chooseCenters)(branching, indices, indices_length, centers_idx, centers_length); + + if (centers_length<branching) { + node->indices = indices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + + cv::AutoBuffer<double> dcenters_buf(branching*veclen_); + Matrix<double> dcenters(dcenters_buf.data(), branching, veclen_); + for (int i=0; i<centers_length; ++i) { + ElementType* vec = dataset_[centers_idx[i]]; + for (size_t k=0; k<veclen_; ++k) { + dcenters[i][k] = double(vec[k]); + } + } + + std::vector<DistanceType> radiuses(branching); + cv::AutoBuffer<int> count_buf(branching); + int* count = count_buf.data(); + for (int i=0; i<branching; ++i) { + radiuses[i] = 0; + count[i] = 0; + } + + // assign points to clusters + cv::AutoBuffer<int> belongs_to_buf(indices_length); + int* belongs_to = belongs_to_buf.data(); + for (int i=0; i<indices_length; ++i) { + + DistanceType sq_dist = distance_(dataset_[indices[i]], dcenters[0], veclen_); + belongs_to[i] = 0; + for (int j=1; j<branching; ++j) { + DistanceType new_sq_dist = distance_(dataset_[indices[i]], dcenters[j], veclen_); + if (sq_dist>new_sq_dist) { + belongs_to[i] = j; + sq_dist = new_sq_dist; + } + } + if (sq_dist>radiuses[belongs_to[i]]) { + radiuses[belongs_to[i]] = sq_dist; + } + count[belongs_to[i]]++; + } + + bool converged = false; + int iteration = 0; + while (!converged && iteration<iterations_) { + converged = true; + iteration++; + + // compute the new cluster centers + for (int i=0; i<branching; ++i) { + memset(dcenters[i],0,sizeof(double)*veclen_); + radiuses[i] = 0; + } + for (int i=0; i<indices_length; ++i) { + ElementType* vec = dataset_[indices[i]]; + double* center = dcenters[belongs_to[i]]; + for (size_t k=0; k<veclen_; ++k) { + center[k] += vec[k]; + } + } + for (int i=0; i<branching; ++i) { + int cnt = count[i]; + for (size_t k=0; k<veclen_; ++k) { + dcenters[i][k] /= cnt; + } + } + + std::vector<int> new_centroids(indices_length); + std::vector<DistanceType> sq_dists(indices_length); + + // reassign points to clusters + KMeansDistanceComputer invoker(distance_, dataset_, branching, indices, dcenters, veclen_, new_centroids, sq_dists); + parallel_for_(cv::Range(0, (int)indices_length), invoker); + + for (int i=0; i < (int)indices_length; ++i) { + DistanceType sq_dist(sq_dists[i]); + int new_centroid(new_centroids[i]); + if (sq_dist > radiuses[new_centroid]) { + radiuses[new_centroid] = sq_dist; + } + if (new_centroid != belongs_to[i]) { + count[belongs_to[i]]--; + count[new_centroid]++; + belongs_to[i] = new_centroid; + converged = false; + } + } + + for (int i=0; i<branching; ++i) { + // if one cluster converges to an empty cluster, + // move an element into that cluster + if (count[i]==0) { + int j = (i+1)%branching; + while (count[j]<=1) { + j = (j+1)%branching; + } + + for (int k=0; k<indices_length; ++k) { + if (belongs_to[k]==j) { + // for cluster j, we move the furthest element from the center to the empty cluster i + if ( distance_(dataset_[indices[k]], dcenters[j], veclen_) == radiuses[j] ) { + belongs_to[k] = i; + count[j]--; + count[i]++; + break; + } + } + } + converged = false; + } + } + + } + + DistanceType** centers = new DistanceType*[branching]; + + for (int i=0; i<branching; ++i) { + centers[i] = new DistanceType[veclen_]; + memoryCounter_ += (int)(veclen_*sizeof(DistanceType)); + for (size_t k=0; k<veclen_; ++k) { + centers[i][k] = (DistanceType)dcenters[i][k]; + } + } + + + // compute kmeans clustering for each of the resulting clusters + node->childs = pool_.allocate<KMeansNodePtr>(branching); + int start = 0; + int end = start; + for (int c=0; c<branching; ++c) { + int s = count[c]; + + DistanceType variance = 0; + DistanceType mean_radius =0; + for (int i=0; i<indices_length; ++i) { + if (belongs_to[i]==c) { + DistanceType d = distance_(dataset_[indices[i]], ZeroIterator<ElementType>(), veclen_); + variance += d; + mean_radius += sqrt(d); + std::swap(indices[i],indices[end]); + std::swap(belongs_to[i],belongs_to[end]); + end++; + } + } + variance /= s; + mean_radius /= s; + variance -= distance_(centers[c], ZeroIterator<ElementType>(), veclen_); + + node->childs[c] = pool_.allocate<KMeansNode>(); + std::memset(node->childs[c], 0, sizeof(KMeansNode)); + node->childs[c]->radius = radiuses[c]; + node->childs[c]->pivot = centers[c]; + node->childs[c]->variance = variance; + node->childs[c]->mean_radius = mean_radius; + computeClustering(node->childs[c],indices+start, end-start, branching, level+1); + start=end; + } + + delete[] centers; + } + + + + /** + * Performs one descent in the hierarchical k-means tree. The branches not + * visited are stored in a priority queue. + * + * Params: + * node = node to explore + * result = container for the k-nearest neighbors found + * vec = query points + * checks = how many points in the dataset have been checked so far + * maxChecks = maximum dataset points to checks + */ + + + void findNN(KMeansNodePtr node, ResultSet<DistanceType>& result, const ElementType* vec, int& checks, int maxChecks, + Heap<BranchSt>* heap) + { + // Ignore those clusters that are too far away + { + DistanceType bsq = distance_(vec, node->pivot, veclen_); + DistanceType rsq = node->radius; + DistanceType wsq = result.worstDist(); + + DistanceType val = bsq-rsq-wsq; + DistanceType val2 = val*val-4*rsq*wsq; + + //if (val>0) { + if ((val>0)&&(val2>0)) { + return; + } + } + + if (node->childs==NULL) { + if (checks>=maxChecks) { + if (result.full()) return; + } + checks += node->size; + for (int i=0; i<node->size; ++i) { + int index = node->indices[i]; + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result.addPoint(dist, index); + } + } + else { + DistanceType* domain_distances = new DistanceType[branching_]; + int closest_center = exploreNodeBranches(node, vec, domain_distances, heap); + delete[] domain_distances; + findNN(node->childs[closest_center],result,vec, checks, maxChecks, heap); + } + } + + /** + * Helper function that computes the nearest childs of a node to a given query point. + * Params: + * node = the node + * q = the query point + * distances = array with the distances to each child node. + * Returns: + */ + int exploreNodeBranches(KMeansNodePtr node, const ElementType* q, DistanceType* domain_distances, Heap<BranchSt>* heap) + { + + int best_index = 0; + domain_distances[best_index] = distance_(q, node->childs[best_index]->pivot, veclen_); + for (int i=1; i<branching_; ++i) { + domain_distances[i] = distance_(q, node->childs[i]->pivot, veclen_); + if (domain_distances[i]<domain_distances[best_index]) { + best_index = i; + } + } + + // float* best_center = node->childs[best_index]->pivot; + for (int i=0; i<branching_; ++i) { + if (i != best_index) { + domain_distances[i] -= cb_index_*node->childs[i]->variance; + + // float dist_to_border = getDistanceToBorder(node.childs[i].pivot,best_center,q); + // if (domain_distances[i]<dist_to_border) { + // domain_distances[i] = dist_to_border; + // } + heap->insert(BranchSt(node->childs[i],domain_distances[i])); + } + } + + return best_index; + } + + + /** + * Function the performs exact nearest neighbor search by traversing the entire tree. + */ + void findExactNN(KMeansNodePtr node, ResultSet<DistanceType>& result, const ElementType* vec) + { + // Ignore those clusters that are too far away + { + DistanceType bsq = distance_(vec, node->pivot, veclen_); + DistanceType rsq = node->radius; + DistanceType wsq = result.worstDist(); + + DistanceType val = bsq-rsq-wsq; + DistanceType val2 = val*val-4*rsq*wsq; + + // if (val>0) { + if ((val>0)&&(val2>0)) { + return; + } + } + + + if (node->childs==NULL) { + for (int i=0; i<node->size; ++i) { + int index = node->indices[i]; + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result.addPoint(dist, index); + } + } + else { + int* sort_indices = new int[branching_]; + + getCenterOrdering(node, vec, sort_indices); + + for (int i=0; i<branching_; ++i) { + findExactNN(node->childs[sort_indices[i]],result,vec); + } + + delete[] sort_indices; + } + } + + + /** + * Helper function. + * + * I computes the order in which to traverse the child nodes of a particular node. + */ + void getCenterOrdering(KMeansNodePtr node, const ElementType* q, int* sort_indices) + { + DistanceType* domain_distances = new DistanceType[branching_]; + for (int i=0; i<branching_; ++i) { + DistanceType dist = distance_(q, node->childs[i]->pivot, veclen_); + + int j=0; + while (domain_distances[j]<dist && j<i) j++; + for (int k=i; k>j; --k) { + domain_distances[k] = domain_distances[k-1]; + sort_indices[k] = sort_indices[k-1]; + } + domain_distances[j] = dist; + sort_indices[j] = i; + } + delete[] domain_distances; + } + + /** + * Method that computes the squared distance from the query point q + * from inside region with center c to the border between this + * region and the region with center p + */ + DistanceType getDistanceToBorder(DistanceType* p, DistanceType* c, DistanceType* q) + { + DistanceType sum = 0; + DistanceType sum2 = 0; + + for (int i=0; i<veclen_; ++i) { + DistanceType t = c[i]-p[i]; + sum += t*(q[i]-(c[i]+p[i])/2); + sum2 += t*t; + } + + return sum*sum/sum2; + } + + + /** + * Helper function the descends in the hierarchical k-means tree by splitting those clusters that minimize + * the overall variance of the clustering. + * Params: + * root = root node + * clusters = array with clusters centers (return value) + * varianceValue = variance of the clustering (return value) + * Returns: + */ + int getMinVarianceClusters(KMeansNodePtr root, KMeansNodePtr* clusters, int clusters_length, DistanceType& varianceValue) + { + int clusterCount = 1; + clusters[0] = root; + + DistanceType meanVariance = root->variance*root->size; + + while (clusterCount<clusters_length) { + DistanceType minVariance = (std::numeric_limits<DistanceType>::max)(); + int splitIndex = -1; + + for (int i=0; i<clusterCount; ++i) { + if (clusters[i]->childs != NULL) { + + DistanceType variance = meanVariance - clusters[i]->variance*clusters[i]->size; + + for (int j=0; j<branching_; ++j) { + variance += clusters[i]->childs[j]->variance*clusters[i]->childs[j]->size; + } + if (variance<minVariance) { + minVariance = variance; + splitIndex = i; + } + } + } + + if (splitIndex==-1) break; + if ( (branching_+clusterCount-1) > clusters_length) break; + + meanVariance = minVariance; + + // split node + KMeansNodePtr toSplit = clusters[splitIndex]; + clusters[splitIndex] = toSplit->childs[0]; + for (int i=1; i<branching_; ++i) { + clusters[clusterCount++] = toSplit->childs[i]; + } + } + + varianceValue = meanVariance/root->size; + return clusterCount; + } + +private: + /** The branching factor used in the hierarchical k-means clustering */ + int branching_; + + /** Maximum number of iterations to use when performing k-means clustering */ + int iterations_; + + /** Algorithm for choosing the cluster centers */ + flann_centers_init_t centers_init_; + + /** + * Cluster border index. This is used in the tree search phase when determining + * the closest cluster to explore next. A zero value takes into account only + * the cluster centres, a value greater then zero also take into account the size + * of the cluster. + */ + float cb_index_; + + /** + * The dataset used by this index + */ + const Matrix<ElementType> dataset_; + + /** Index parameters */ + IndexParams index_params_; + + /** + * Number of features in the dataset. + */ + size_t size_; + + /** + * Length of each feature. + */ + size_t veclen_; + + /** + * The root node in the tree. + */ + KMeansNodePtr root_; + + /** + * Array of indices to vectors in the dataset. + */ + int* indices_; + + /** + * The distance + */ + Distance distance_; + + /** + * Pooled memory allocator. + */ + PooledAllocator pool_; + + /** + * Memory occupied by the index. + */ + int memoryCounter_; +}; + +} + +#endif //OPENCV_FLANN_KMEANS_INDEX_H_ diff --git a/include/opencv2/flann/linear_index.h b/include/opencv2/flann/linear_index.h new file mode 100644 index 0000000..ca3f44d --- /dev/null +++ b/include/opencv2/flann/linear_index.h @@ -0,0 +1,132 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_LINEAR_INDEX_H_ +#define OPENCV_FLANN_LINEAR_INDEX_H_ + +#include "general.h" +#include "nn_index.h" + +namespace cvflann +{ + +struct LinearIndexParams : public IndexParams +{ + LinearIndexParams() + { + (* this)["algorithm"] = FLANN_INDEX_LINEAR; + } +}; + +template <typename Distance> +class LinearIndex : public NNIndex<Distance> +{ +public: + + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + LinearIndex(const Matrix<ElementType>& inputData, const IndexParams& params = LinearIndexParams(), + Distance d = Distance()) : + dataset_(inputData), index_params_(params), distance_(d) + { + } + + LinearIndex(const LinearIndex&); + LinearIndex& operator=(const LinearIndex&); + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_LINEAR; + } + + + size_t size() const CV_OVERRIDE + { + return dataset_.rows; + } + + size_t veclen() const CV_OVERRIDE + { + return dataset_.cols; + } + + + int usedMemory() const CV_OVERRIDE + { + return 0; + } + + void buildIndex() CV_OVERRIDE + { + /* nothing to do here for linear search */ + } + + void saveIndex(FILE*) CV_OVERRIDE + { + /* nothing to do here for linear search */ + } + + + void loadIndex(FILE*) CV_OVERRIDE + { + /* nothing to do here for linear search */ + + index_params_["algorithm"] = getType(); + } + + void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/) CV_OVERRIDE + { + ElementType* data = dataset_.data; + for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) { + DistanceType dist = distance_(data, vec, dataset_.cols); + resultSet.addPoint(dist, (int)i); + } + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + +private: + /** The dataset */ + const Matrix<ElementType> dataset_; + /** Index parameters */ + IndexParams index_params_; + /** Index distance */ + Distance distance_; + +}; + +} + +#endif // OPENCV_FLANN_LINEAR_INDEX_H_ diff --git a/include/opencv2/flann/logger.h b/include/opencv2/flann/logger.h new file mode 100644 index 0000000..32618db --- /dev/null +++ b/include/opencv2/flann/logger.h @@ -0,0 +1,135 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_LOGGER_H +#define OPENCV_FLANN_LOGGER_H + +#include <stdio.h> +#include <stdarg.h> + +#include "defines.h" + + +namespace cvflann +{ + +class Logger +{ + Logger() : stream(stdout), logLevel(FLANN_LOG_WARN) {} + + ~Logger() + { + if ((stream!=NULL)&&(stream!=stdout)) { + fclose(stream); + } + } + + static Logger& instance() + { + static Logger logger; + return logger; + } + + void _setDestination(const char* name) + { + if (name==NULL) { + stream = stdout; + } + else { +#ifdef _MSC_VER + if (fopen_s(&stream, name, "w") != 0) + stream = NULL; +#else + stream = fopen(name,"w"); +#endif + if (stream == NULL) { + stream = stdout; + } + } + } + + int _log(int level, const char* fmt, va_list arglist) + { + if (level > logLevel ) return -1; + int ret = vfprintf(stream, fmt, arglist); + return ret; + } + +public: + /** + * Sets the logging level. All messages with lower priority will be ignored. + * @param level Logging level + */ + static void setLevel(int level) { instance().logLevel = level; } + + /** + * Sets the logging destination + * @param name Filename or NULL for console + */ + static void setDestination(const char* name) { instance()._setDestination(name); } + + /** + * Print log message + * @param level Log level + * @param fmt Message format + * @return + */ + static int log(int level, const char* fmt, ...) + { + va_list arglist; + va_start(arglist, fmt); + int ret = instance()._log(level,fmt,arglist); + va_end(arglist); + return ret; + } + +#define LOG_METHOD(NAME,LEVEL) \ + static int NAME(const char* fmt, ...) \ + { \ + va_list ap; \ + va_start(ap, fmt); \ + int ret = instance()._log(LEVEL, fmt, ap); \ + va_end(ap); \ + return ret; \ + } + + LOG_METHOD(fatal, FLANN_LOG_FATAL) + LOG_METHOD(error, FLANN_LOG_ERROR) + LOG_METHOD(warn, FLANN_LOG_WARN) + LOG_METHOD(info, FLANN_LOG_INFO) + +private: + FILE* stream; + int logLevel; +}; + +} + +#endif //OPENCV_FLANN_LOGGER_H diff --git a/include/opencv2/flann/lsh_index.h b/include/opencv2/flann/lsh_index.h new file mode 100644 index 0000000..42afe89 --- /dev/null +++ b/include/opencv2/flann/lsh_index.h @@ -0,0 +1,392 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +/*********************************************************************** + * Author: Vincent Rabaud + *************************************************************************/ + +#ifndef OPENCV_FLANN_LSH_INDEX_H_ +#define OPENCV_FLANN_LSH_INDEX_H_ + +#include <algorithm> +#include <cassert> +#include <cstring> +#include <map> +#include <vector> + +#include "general.h" +#include "nn_index.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "lsh_table.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + +namespace cvflann +{ + +struct LshIndexParams : public IndexParams +{ + LshIndexParams(unsigned int table_number = 12, unsigned int key_size = 20, unsigned int multi_probe_level = 2) + { + (* this)["algorithm"] = FLANN_INDEX_LSH; + // The number of hash tables to use + (*this)["table_number"] = table_number; + // The length of the key in the hash tables + (*this)["key_size"] = key_size; + // Number of levels to use in multi-probe (0 for standard LSH) + (*this)["multi_probe_level"] = multi_probe_level; + } +}; + +/** + * Randomized kd-tree index + * + * Contains the k-d trees and other information for indexing a set of points + * for nearest-neighbor matching. + */ +template<typename Distance> +class LshIndex : public NNIndex<Distance> +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + /** Constructor + * @param input_data dataset with the input features + * @param params parameters passed to the LSH algorithm + * @param d the distance used + */ + LshIndex(const Matrix<ElementType>& input_data, const IndexParams& params = LshIndexParams(), + Distance d = Distance()) : + dataset_(input_data), index_params_(params), distance_(d) + { + // cv::flann::IndexParams sets integer params as 'int', so it is used with get_param + // in place of 'unsigned int' + table_number_ = (unsigned int)get_param<int>(index_params_,"table_number",12); + key_size_ = (unsigned int)get_param<int>(index_params_,"key_size",20); + multi_probe_level_ = (unsigned int)get_param<int>(index_params_,"multi_probe_level",2); + + feature_size_ = (unsigned)dataset_.cols; + fill_xor_mask(0, key_size_, multi_probe_level_, xor_masks_); + } + + + LshIndex(const LshIndex&); + LshIndex& operator=(const LshIndex&); + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + tables_.resize(table_number_); + for (unsigned int i = 0; i < table_number_; ++i) { + lsh::LshTable<ElementType>& table = tables_[i]; + table = lsh::LshTable<ElementType>(feature_size_, key_size_); + + // Add the features to the table + table.add(dataset_); + } + } + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_LSH; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream,table_number_); + save_value(stream,key_size_); + save_value(stream,multi_probe_level_); + save_value(stream, dataset_); + } + + void loadIndex(FILE* stream) CV_OVERRIDE + { + load_value(stream, table_number_); + load_value(stream, key_size_); + load_value(stream, multi_probe_level_); + load_value(stream, dataset_); + // Building the index is so fast we can afford not storing it + buildIndex(); + + index_params_["algorithm"] = getType(); + index_params_["table_number"] = table_number_; + index_params_["key_size"] = key_size_; + index_params_["multi_probe_level"] = multi_probe_level_; + } + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return dataset_.rows; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return feature_size_; + } + + /** + * Computes the index memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return (int)(dataset_.rows * sizeof(int)); + } + + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + virtual void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE + { + assert(queries.cols == veclen()); + assert(indices.rows >= queries.rows); + assert(dists.rows >= queries.rows); + assert(int(indices.cols) >= knn); + assert(int(dists.cols) >= knn); + + + KNNUniqueResultSet<DistanceType> resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.clear(); + std::fill_n(indices[i], knn, -1); + std::fill_n(dists[i], knn, std::numeric_limits<DistanceType>::max()); + findNeighbors(resultSet, queries[i], params); + if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices[i], dists[i], knn); + else resultSet.copy(indices[i], dists[i], knn); + } + } + + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * maxCheck = the maximum number of restarts (in a best-bin-first manner) + */ + void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& /*searchParams*/) CV_OVERRIDE + { + getNeighbors(vec, result); + } + +private: + /** Defines the comparator on score and index + */ + typedef std::pair<float, unsigned int> ScoreIndexPair; + struct SortScoreIndexPairOnSecond + { + bool operator()(const ScoreIndexPair& left, const ScoreIndexPair& right) const + { + return left.second < right.second; + } + }; + + /** Fills the different xor masks to use when getting the neighbors in multi-probe LSH + * @param key the key we build neighbors from + * @param lowest_index the lowest index of the bit set + * @param level the multi-probe level we are at + * @param xor_masks all the xor mask + */ + void fill_xor_mask(lsh::BucketKey key, int lowest_index, unsigned int level, + std::vector<lsh::BucketKey>& xor_masks) + { + xor_masks.push_back(key); + if (level == 0) return; + for (int index = lowest_index - 1; index >= 0; --index) { + // Create a new key + lsh::BucketKey new_key = key | (1 << index); + fill_xor_mask(new_key, index, level - 1, xor_masks); + } + } + + /** Performs the approximate nearest-neighbor search. + * @param vec the feature to analyze + * @param do_radius flag indicating if we check the radius too + * @param radius the radius if it is a radius search + * @param do_k flag indicating if we limit the number of nn + * @param k_nn the number of nearest neighbors + * @param checked_average used for debugging + */ + void getNeighbors(const ElementType* vec, bool /*do_radius*/, float radius, bool do_k, unsigned int k_nn, + float& /*checked_average*/) + { + static std::vector<ScoreIndexPair> score_index_heap; + + if (do_k) { + unsigned int worst_score = std::numeric_limits<unsigned int>::max(); + typename std::vector<lsh::LshTable<ElementType> >::const_iterator table = tables_.begin(); + typename std::vector<lsh::LshTable<ElementType> >::const_iterator table_end = tables_.end(); + for (; table != table_end; ++table) { + size_t key = table->getKey(vec); + std::vector<lsh::BucketKey>::const_iterator xor_mask = xor_masks_.begin(); + std::vector<lsh::BucketKey>::const_iterator xor_mask_end = xor_masks_.end(); + for (; xor_mask != xor_mask_end; ++xor_mask) { + size_t sub_key = key ^ (*xor_mask); + const lsh::Bucket* bucket = table->getBucketFromKey(sub_key); + if (bucket == 0) continue; + + // Go over each descriptor index + std::vector<lsh::FeatureIndex>::const_iterator training_index = bucket->begin(); + std::vector<lsh::FeatureIndex>::const_iterator last_training_index = bucket->end(); + DistanceType hamming_distance; + + // Process the rest of the candidates + for (; training_index < last_training_index; ++training_index) { + hamming_distance = distance_(vec, dataset_[*training_index], dataset_.cols); + + if (hamming_distance < worst_score) { + // Insert the new element + score_index_heap.push_back(ScoreIndexPair(hamming_distance, training_index)); + std::push_heap(score_index_heap.begin(), score_index_heap.end()); + + if (score_index_heap.size() > (unsigned int)k_nn) { + // Remove the highest distance value as we have too many elements + std::pop_heap(score_index_heap.begin(), score_index_heap.end()); + score_index_heap.pop_back(); + // Keep track of the worst score + worst_score = score_index_heap.front().first; + } + } + } + } + } + } + else { + typename std::vector<lsh::LshTable<ElementType> >::const_iterator table = tables_.begin(); + typename std::vector<lsh::LshTable<ElementType> >::const_iterator table_end = tables_.end(); + for (; table != table_end; ++table) { + size_t key = table->getKey(vec); + std::vector<lsh::BucketKey>::const_iterator xor_mask = xor_masks_.begin(); + std::vector<lsh::BucketKey>::const_iterator xor_mask_end = xor_masks_.end(); + for (; xor_mask != xor_mask_end; ++xor_mask) { + size_t sub_key = key ^ (*xor_mask); + const lsh::Bucket* bucket = table->getBucketFromKey(sub_key); + if (bucket == 0) continue; + + // Go over each descriptor index + std::vector<lsh::FeatureIndex>::const_iterator training_index = bucket->begin(); + std::vector<lsh::FeatureIndex>::const_iterator last_training_index = bucket->end(); + DistanceType hamming_distance; + + // Process the rest of the candidates + for (; training_index < last_training_index; ++training_index) { + // Compute the Hamming distance + hamming_distance = distance_(vec, dataset_[*training_index], dataset_.cols); + if (hamming_distance < radius) score_index_heap.push_back(ScoreIndexPair(hamming_distance, training_index)); + } + } + } + } + } + + /** Performs the approximate nearest-neighbor search. + * This is a slower version than the above as it uses the ResultSet + * @param vec the feature to analyze + */ + void getNeighbors(const ElementType* vec, ResultSet<DistanceType>& result) + { + typename std::vector<lsh::LshTable<ElementType> >::const_iterator table = tables_.begin(); + typename std::vector<lsh::LshTable<ElementType> >::const_iterator table_end = tables_.end(); + for (; table != table_end; ++table) { + size_t key = table->getKey(vec); + std::vector<lsh::BucketKey>::const_iterator xor_mask = xor_masks_.begin(); + std::vector<lsh::BucketKey>::const_iterator xor_mask_end = xor_masks_.end(); + for (; xor_mask != xor_mask_end; ++xor_mask) { + size_t sub_key = key ^ (*xor_mask); + const lsh::Bucket* bucket = table->getBucketFromKey((lsh::BucketKey)sub_key); + if (bucket == 0) continue; + + // Go over each descriptor index + std::vector<lsh::FeatureIndex>::const_iterator training_index = bucket->begin(); + std::vector<lsh::FeatureIndex>::const_iterator last_training_index = bucket->end(); + DistanceType hamming_distance; + + // Process the rest of the candidates + for (; training_index < last_training_index; ++training_index) { + // Compute the Hamming distance + hamming_distance = distance_(vec, dataset_[*training_index], (int)dataset_.cols); + result.addPoint(hamming_distance, *training_index); + } + } + } + } + + /** The different hash tables */ + std::vector<lsh::LshTable<ElementType> > tables_; + + /** The data the LSH tables where built from */ + Matrix<ElementType> dataset_; + + /** The size of the features (as ElementType[]) */ + unsigned int feature_size_; + + IndexParams index_params_; + + /** table number */ + unsigned int table_number_; + /** key size */ + unsigned int key_size_; + /** How far should we look for neighbors in multi-probe LSH */ + unsigned int multi_probe_level_; + + /** The XOR masks to apply to a key to get the neighboring buckets */ + std::vector<lsh::BucketKey> xor_masks_; + + Distance distance_; +}; +} + +#endif //OPENCV_FLANN_LSH_INDEX_H_ diff --git a/include/opencv2/flann/lsh_table.h b/include/opencv2/flann/lsh_table.h new file mode 100644 index 0000000..b07a9d5 --- /dev/null +++ b/include/opencv2/flann/lsh_table.h @@ -0,0 +1,513 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +/*********************************************************************** + * Author: Vincent Rabaud + *************************************************************************/ + +#ifndef OPENCV_FLANN_LSH_TABLE_H_ +#define OPENCV_FLANN_LSH_TABLE_H_ + +#include <algorithm> +#include <iostream> +#include <iomanip> +#include <limits.h> +// TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +# define USE_UNORDERED_MAP 1 +#else +# define USE_UNORDERED_MAP 0 +#endif +#if USE_UNORDERED_MAP +#include <unordered_map> +#else +#include <map> +#endif +#include <math.h> +#include <stddef.h> + +#include "dynamic_bitset.h" +#include "matrix.h" + +namespace cvflann +{ + +namespace lsh +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** What is stored in an LSH bucket + */ +typedef uint32_t FeatureIndex; +/** The id from which we can get a bucket back in an LSH table + */ +typedef unsigned int BucketKey; + +/** A bucket in an LSH table + */ +typedef std::vector<FeatureIndex> Bucket; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** POD for stats about an LSH table + */ +struct LshStats +{ + std::vector<unsigned int> bucket_sizes_; + size_t n_buckets_; + size_t bucket_size_mean_; + size_t bucket_size_median_; + size_t bucket_size_min_; + size_t bucket_size_max_; + size_t bucket_size_std_dev; + /** Each contained vector contains three value: beginning/end for interval, number of elements in the bin + */ + std::vector<std::vector<unsigned int> > size_histogram_; +}; + +/** Overload the << operator for LshStats + * @param out the streams + * @param stats the stats to display + * @return the streams + */ +inline std::ostream& operator <<(std::ostream& out, const LshStats& stats) +{ + int w = 20; + out << "Lsh Table Stats:\n" << std::setw(w) << std::setiosflags(std::ios::right) << "N buckets : " + << stats.n_buckets_ << "\n" << std::setw(w) << std::setiosflags(std::ios::right) << "mean size : " + << std::setiosflags(std::ios::left) << stats.bucket_size_mean_ << "\n" << std::setw(w) + << std::setiosflags(std::ios::right) << "median size : " << stats.bucket_size_median_ << "\n" << std::setw(w) + << std::setiosflags(std::ios::right) << "min size : " << std::setiosflags(std::ios::left) + << stats.bucket_size_min_ << "\n" << std::setw(w) << std::setiosflags(std::ios::right) << "max size : " + << std::setiosflags(std::ios::left) << stats.bucket_size_max_; + + // Display the histogram + out << std::endl << std::setw(w) << std::setiosflags(std::ios::right) << "histogram : " + << std::setiosflags(std::ios::left); + for (std::vector<std::vector<unsigned int> >::const_iterator iterator = stats.size_histogram_.begin(), end = + stats.size_histogram_.end(); iterator != end; ++iterator) out << (*iterator)[0] << "-" << (*iterator)[1] << ": " << (*iterator)[2] << ", "; + + return out; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Lsh hash table. As its key is a sub-feature, and as usually + * the size of it is pretty small, we keep it as a continuous memory array. + * The value is an index in the corpus of features (we keep it as an unsigned + * int for pure memory reasons, it could be a size_t) + */ +template<typename ElementType> +class LshTable +{ +public: + /** A container of all the feature indices. Optimized for space + */ +#if USE_UNORDERED_MAP + typedef std::unordered_map<BucketKey, Bucket> BucketsSpace; +#else + typedef std::map<BucketKey, Bucket> BucketsSpace; +#endif + + /** A container of all the feature indices. Optimized for speed + */ + typedef std::vector<Bucket> BucketsSpeed; + + /** Default constructor + */ + LshTable() + { + key_size_ = 0; + feature_size_ = 0; + speed_level_ = kArray; + } + + /** Default constructor + * Create the mask and allocate the memory + * @param feature_size is the size of the feature (considered as a ElementType[]) + * @param key_size is the number of bits that are turned on in the feature + */ + LshTable(unsigned int feature_size, unsigned int key_size) + { + feature_size_ = feature_size; + CV_UNUSED(key_size); + std::cerr << "LSH is not implemented for that type" << std::endl; + assert(0); + } + + /** Add a feature to the table + * @param value the value to store for that feature + * @param feature the feature itself + */ + void add(unsigned int value, const ElementType* feature) + { + // Add the value to the corresponding bucket + BucketKey key = (lsh::BucketKey)getKey(feature); + + switch (speed_level_) { + case kArray: + // That means we get the buckets from an array + buckets_speed_[key].push_back(value); + break; + case kBitsetHash: + // That means we can check the bitset for the presence of a key + key_bitset_.set(key); + buckets_space_[key].push_back(value); + break; + case kHash: + { + // That means we have to check for the hash table for the presence of a key + buckets_space_[key].push_back(value); + break; + } + } + } + + /** Add a set of features to the table + * @param dataset the values to store + */ + void add(Matrix<ElementType> dataset) + { +#if USE_UNORDERED_MAP + buckets_space_.rehash((buckets_space_.size() + dataset.rows) * 1.2); +#endif + // Add the features to the table + for (unsigned int i = 0; i < dataset.rows; ++i) add(i, dataset[i]); + // Now that the table is full, optimize it for speed/space + optimize(); + } + + /** Get a bucket given the key + * @param key + * @return + */ + inline const Bucket* getBucketFromKey(BucketKey key) const + { + // Generate other buckets + switch (speed_level_) { + case kArray: + // That means we get the buckets from an array + return &buckets_speed_[key]; + break; + case kBitsetHash: + // That means we can check the bitset for the presence of a key + if (key_bitset_.test(key)) return &buckets_space_.find(key)->second; + else return 0; + break; + case kHash: + { + // That means we have to check for the hash table for the presence of a key + BucketsSpace::const_iterator bucket_it, bucket_end = buckets_space_.end(); + bucket_it = buckets_space_.find(key); + // Stop here if that bucket does not exist + if (bucket_it == bucket_end) return 0; + else return &bucket_it->second; + break; + } + } + return 0; + } + + /** Compute the sub-signature of a feature + */ + size_t getKey(const ElementType* /*feature*/) const + { + std::cerr << "LSH is not implemented for that type" << std::endl; + assert(0); + return 1; + } + + /** Get statistics about the table + * @return + */ + LshStats getStats() const; + +private: + /** defines the speed fo the implementation + * kArray uses a vector for storing data + * kBitsetHash uses a hash map but checks for the validity of a key with a bitset + * kHash uses a hash map only + */ + enum SpeedLevel + { + kArray, kBitsetHash, kHash + }; + + /** Initialize some variables + */ + void initialize(size_t key_size) + { + const size_t key_size_lower_bound = 1; + //a value (size_t(1) << key_size) must fit the size_t type so key_size has to be strictly less than size of size_t + const size_t key_size_upper_bound = (std::min)(sizeof(BucketKey) * CHAR_BIT + 1, sizeof(size_t) * CHAR_BIT); + if (key_size < key_size_lower_bound || key_size >= key_size_upper_bound) + { + CV_Error(cv::Error::StsBadArg, cv::format("Invalid key_size (=%d). Valid values for your system are %d <= key_size < %d.", (int)key_size, (int)key_size_lower_bound, (int)key_size_upper_bound)); + } + + speed_level_ = kHash; + key_size_ = (unsigned)key_size; + } + + /** Optimize the table for speed/space + */ + void optimize() + { + // If we are already using the fast storage, no need to do anything + if (speed_level_ == kArray) return; + + // Use an array if it will be more than half full + if (buckets_space_.size() > ((size_t(1) << key_size_) / 2)) { + speed_level_ = kArray; + // Fill the array version of it + buckets_speed_.resize(size_t(1) << key_size_); + for (BucketsSpace::const_iterator key_bucket = buckets_space_.begin(); key_bucket != buckets_space_.end(); ++key_bucket) buckets_speed_[key_bucket->first] = key_bucket->second; + + // Empty the hash table + buckets_space_.clear(); + return; + } + + // If the bitset is going to use less than 10% of the RAM of the hash map (at least 1 size_t for the key and two + // for the vector) or less than 512MB (key_size_ <= 30) + if (((std::max(buckets_space_.size(), buckets_speed_.size()) * CHAR_BIT * 3 * sizeof(BucketKey)) / 10 + >= (size_t(1) << key_size_)) || (key_size_ <= 32)) { + speed_level_ = kBitsetHash; + key_bitset_.resize(size_t(1) << key_size_); + key_bitset_.reset(); + // Try with the BucketsSpace + for (BucketsSpace::const_iterator key_bucket = buckets_space_.begin(); key_bucket != buckets_space_.end(); ++key_bucket) key_bitset_.set(key_bucket->first); + } + else { + speed_level_ = kHash; + key_bitset_.clear(); + } + } + + /** The vector of all the buckets if they are held for speed + */ + BucketsSpeed buckets_speed_; + + /** The hash table of all the buckets in case we cannot use the speed version + */ + BucketsSpace buckets_space_; + + /** What is used to store the data */ + SpeedLevel speed_level_; + + /** If the subkey is small enough, it will keep track of which subkeys are set through that bitset + * That is just a speedup so that we don't look in the hash table (which can be mush slower that checking a bitset) + */ + DynamicBitset key_bitset_; + + /** The size of the sub-signature in bits + */ + unsigned int key_size_; + + unsigned int feature_size_; + + // Members only used for the unsigned char specialization + /** The mask to apply to a feature to get the hash key + * Only used in the unsigned char case + */ + std::vector<size_t> mask_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Specialization for unsigned char + +template<> +inline LshTable<unsigned char>::LshTable(unsigned int feature_size, unsigned int subsignature_size) +{ + feature_size_ = feature_size; + initialize(subsignature_size); + // Allocate the mask + mask_ = std::vector<size_t>((feature_size * sizeof(char) + sizeof(size_t) - 1) / sizeof(size_t), 0); + + // A bit brutal but fast to code + std::vector<int> indices(feature_size * CHAR_BIT); + for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = (int)i; +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(indices); +#else + std::random_shuffle(indices.begin(), indices.end()); +#endif + + // Generate a random set of order of subsignature_size_ bits + for (unsigned int i = 0; i < key_size_; ++i) { + size_t index = indices[i]; + + // Set that bit in the mask + size_t divisor = CHAR_BIT * sizeof(size_t); + size_t idx = index / divisor; //pick the right size_t index + mask_[idx] |= size_t(1) << (index % divisor); //use modulo to find the bit offset + } + + // Set to 1 if you want to display the mask for debug +#if 0 + { + size_t bcount = 0; + BOOST_FOREACH(size_t mask_block, mask_){ + out << std::setw(sizeof(size_t) * CHAR_BIT / 4) << std::setfill('0') << std::hex << mask_block + << std::endl; + bcount += __builtin_popcountll(mask_block); + } + out << "bit count : " << std::dec << bcount << std::endl; + out << "mask size : " << mask_.size() << std::endl; + return out; + } +#endif +} + +/** Return the Subsignature of a feature + * @param feature the feature to analyze + */ +template<> +inline size_t LshTable<unsigned char>::getKey(const unsigned char* feature) const +{ + // no need to check if T is dividable by sizeof(size_t) like in the Hamming + // distance computation as we have a mask + // FIXIT: This is bad assumption, because we reading tail bytes after of the allocated features buffer + const size_t* feature_block_ptr = reinterpret_cast<const size_t*> ((const void*)feature); + + // Figure out the subsignature of the feature + // Given the feature ABCDEF, and the mask 001011, the output will be + // 000CEF + size_t subsignature = 0; + size_t bit_index = 1; + + for (unsigned i = 0; i < feature_size_; i += sizeof(size_t)) { + // get the mask and signature blocks + size_t feature_block; + if (i <= feature_size_ - sizeof(size_t)) + { + feature_block = *feature_block_ptr; + } + else + { + size_t tmp = 0; + memcpy(&tmp, feature_block_ptr, feature_size_ - i); // preserve bytes order + feature_block = tmp; + } + size_t mask_block = mask_[i / sizeof(size_t)]; + while (mask_block) { + // Get the lowest set bit in the mask block + size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block); + // Add it to the current subsignature if necessary + subsignature += (feature_block & lowest_bit) ? bit_index : 0; + // Reset the bit in the mask block + mask_block ^= lowest_bit; + // increment the bit index for the subsignature + bit_index <<= 1; + } + // Check the next feature block + ++feature_block_ptr; + } + return subsignature; +} + +template<> +inline LshStats LshTable<unsigned char>::getStats() const +{ + LshStats stats; + stats.bucket_size_mean_ = 0; + if ((buckets_speed_.empty()) && (buckets_space_.empty())) { + stats.n_buckets_ = 0; + stats.bucket_size_median_ = 0; + stats.bucket_size_min_ = 0; + stats.bucket_size_max_ = 0; + return stats; + } + + if (!buckets_speed_.empty()) { + for (BucketsSpeed::const_iterator pbucket = buckets_speed_.begin(); pbucket != buckets_speed_.end(); ++pbucket) { + stats.bucket_sizes_.push_back((lsh::FeatureIndex)pbucket->size()); + stats.bucket_size_mean_ += pbucket->size(); + } + stats.bucket_size_mean_ /= buckets_speed_.size(); + stats.n_buckets_ = buckets_speed_.size(); + } + else { + for (BucketsSpace::const_iterator x = buckets_space_.begin(); x != buckets_space_.end(); ++x) { + stats.bucket_sizes_.push_back((lsh::FeatureIndex)x->second.size()); + stats.bucket_size_mean_ += x->second.size(); + } + stats.bucket_size_mean_ /= buckets_space_.size(); + stats.n_buckets_ = buckets_space_.size(); + } + + std::sort(stats.bucket_sizes_.begin(), stats.bucket_sizes_.end()); + + // BOOST_FOREACH(int size, stats.bucket_sizes_) + // std::cout << size << " "; + // std::cout << std::endl; + stats.bucket_size_median_ = stats.bucket_sizes_[stats.bucket_sizes_.size() / 2]; + stats.bucket_size_min_ = stats.bucket_sizes_.front(); + stats.bucket_size_max_ = stats.bucket_sizes_.back(); + + // TODO compute mean and std + /*float mean, stddev; + stats.bucket_size_mean_ = mean; + stats.bucket_size_std_dev = stddev;*/ + + // Include a histogram of the buckets + unsigned int bin_start = 0; + unsigned int bin_end = 20; + bool is_new_bin = true; + for (std::vector<unsigned int>::iterator iterator = stats.bucket_sizes_.begin(), end = stats.bucket_sizes_.end(); iterator + != end; ) + if (*iterator < bin_end) { + if (is_new_bin) { + stats.size_histogram_.push_back(std::vector<unsigned int>(3, 0)); + stats.size_histogram_.back()[0] = bin_start; + stats.size_histogram_.back()[1] = bin_end - 1; + is_new_bin = false; + } + ++stats.size_histogram_.back()[2]; + ++iterator; + } + else { + bin_start += 20; + bin_end += 20; + is_new_bin = true; + } + + return stats; +} + +// End the two namespaces +} +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif /* OPENCV_FLANN_LSH_TABLE_H_ */ diff --git a/include/opencv2/flann/matrix.h b/include/opencv2/flann/matrix.h new file mode 100644 index 0000000..f6092d1 --- /dev/null +++ b/include/opencv2/flann/matrix.h @@ -0,0 +1,116 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_DATASET_H_ +#define OPENCV_FLANN_DATASET_H_ + +#include <stdio.h> + +#include "general.h" + +namespace cvflann +{ + +/** + * Class that implements a simple rectangular matrix stored in a memory buffer and + * provides convenient matrix-like access using the [] operators. + */ +template <typename T> +class Matrix +{ +public: + typedef T type; + + size_t rows; + size_t cols; + size_t stride; + T* data; + + Matrix() : rows(0), cols(0), stride(0), data(NULL) + { + } + + Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) : + rows(rows_), cols(cols_), stride(stride_), data(data_) + { + if (stride==0) stride = cols; + } + + /** + * Convenience function for deallocating the storage data. + */ + CV_DEPRECATED void free() + { + fprintf(stderr, "The cvflann::Matrix<T>::free() method is deprecated " + "and it does not do any memory deallocation any more. You are" + "responsible for deallocating the matrix memory (by doing" + "'delete[] matrix.data' for example)"); + } + + /** + * Operator that return a (pointer to a) row of the data. + */ + T* operator[](size_t index) const + { + return data+index*stride; + } +}; + + +class UntypedMatrix +{ +public: + size_t rows; + size_t cols; + void* data; + flann_datatype_t type; + + UntypedMatrix(void* data_, long rows_, long cols_) : + rows(rows_), cols(cols_), data(data_) + { + } + + ~UntypedMatrix() + { + } + + + template<typename T> + Matrix<T> as() + { + return Matrix<T>((T*)data, rows, cols); + } +}; + + + +} + +#endif //OPENCV_FLANN_DATASET_H_ diff --git a/include/opencv2/flann/miniflann.hpp b/include/opencv2/flann/miniflann.hpp new file mode 100644 index 0000000..bda2ed4 --- /dev/null +++ b/include/opencv2/flann/miniflann.hpp @@ -0,0 +1,162 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_MINIFLANN_HPP +#define OPENCV_MINIFLANN_HPP + +#include "opencv2/core.hpp" +#include "opencv2/flann/defines.h" + +namespace cv +{ + +namespace flann +{ + +struct CV_EXPORTS IndexParams +{ + IndexParams(); + ~IndexParams(); + + String getString(const String& key, const String& defaultVal=String()) const; + int getInt(const String& key, int defaultVal=-1) const; + double getDouble(const String& key, double defaultVal=-1) const; + + void setString(const String& key, const String& value); + void setInt(const String& key, int value); + void setDouble(const String& key, double value); + void setFloat(const String& key, float value); + void setBool(const String& key, bool value); + void setAlgorithm(int value); + + void getAll(std::vector<String>& names, + std::vector<int>& types, + std::vector<String>& strValues, + std::vector<double>& numValues) const; + + void* params; + +private: + IndexParams(const IndexParams &); // copy disabled + IndexParams& operator=(const IndexParams &); // assign disabled +}; + +struct CV_EXPORTS KDTreeIndexParams : public IndexParams +{ + KDTreeIndexParams(int trees=4); +}; + +struct CV_EXPORTS LinearIndexParams : public IndexParams +{ + LinearIndexParams(); +}; + +struct CV_EXPORTS CompositeIndexParams : public IndexParams +{ + CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, + cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2f ); +}; + +struct CV_EXPORTS AutotunedIndexParams : public IndexParams +{ + AutotunedIndexParams(float target_precision = 0.8f, float build_weight = 0.01f, + float memory_weight = 0, float sample_fraction = 0.1f); +}; + +struct CV_EXPORTS HierarchicalClusteringIndexParams : public IndexParams +{ + HierarchicalClusteringIndexParams(int branching = 32, + cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, int trees = 4, int leaf_size = 100 ); +}; + +struct CV_EXPORTS KMeansIndexParams : public IndexParams +{ + KMeansIndexParams(int branching = 32, int iterations = 11, + cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2f ); +}; + +struct CV_EXPORTS LshIndexParams : public IndexParams +{ + LshIndexParams(int table_number, int key_size, int multi_probe_level); +}; + +struct CV_EXPORTS SavedIndexParams : public IndexParams +{ + SavedIndexParams(const String& filename); +}; + +struct CV_EXPORTS SearchParams : public IndexParams +{ + SearchParams( int checks = 32, float eps = 0, bool sorted = true ); +}; + +class CV_EXPORTS_W Index +{ +public: + CV_WRAP Index(); + CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); + virtual ~Index(); + + CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); + CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices, + OutputArray dists, int knn, const SearchParams& params=SearchParams()); + + CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices, + OutputArray dists, double radius, int maxResults, + const SearchParams& params=SearchParams()); + + CV_WRAP virtual void save(const String& filename) const; + CV_WRAP virtual bool load(InputArray features, const String& filename); + CV_WRAP virtual void release(); + CV_WRAP cvflann::flann_distance_t getDistance() const; + CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const; + +protected: + cvflann::flann_distance_t distType; + cvflann::flann_algorithm_t algo; + int featureType; + void* index; +}; + +} } // namespace cv::flann + +#endif diff --git a/include/opencv2/flann/nn_index.h b/include/opencv2/flann/nn_index.h new file mode 100644 index 0000000..381d4bc --- /dev/null +++ b/include/opencv2/flann/nn_index.h @@ -0,0 +1,177 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_NNINDEX_H +#define OPENCV_FLANN_NNINDEX_H + +#include "general.h" +#include "matrix.h" +#include "result_set.h" +#include "params.h" + +namespace cvflann +{ + +/** + * Nearest-neighbour index base class + */ +template <typename Distance> +class NNIndex +{ + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + +public: + + virtual ~NNIndex() {} + + /** + * \brief Builds the index + */ + virtual void buildIndex() = 0; + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + virtual void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) + { + assert(queries.cols == veclen()); + assert(indices.rows >= queries.rows); + assert(dists.rows >= queries.rows); + assert(int(indices.cols) >= knn); + assert(int(dists.cols) >= knn); + +#if 0 + KNNResultSet<DistanceType> resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.init(indices[i], dists[i]); + findNeighbors(resultSet, queries[i], params); + } +#else + KNNUniqueResultSet<DistanceType> resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.clear(); + findNeighbors(resultSet, queries[i], params); + if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices[i], dists[i], knn); + else resultSet.copy(indices[i], dists[i], knn); + } +#endif + } + + /** + * \brief Perform radius search + * \param[in] query The query point + * \param[out] indices The indinces of the neighbors found within the given radius + * \param[out] dists The distances to the nearest neighbors found + * \param[in] radius The radius used for search + * \param[in] params Search parameters + * \returns Number of neighbors found + */ + virtual int radiusSearch(const Matrix<ElementType>& query, Matrix<int>& indices, Matrix<DistanceType>& dists, float radius, const SearchParams& params) + { + if (query.rows != 1) { + fprintf(stderr, "I can only search one feature at a time for range search\n"); + return -1; + } + assert(query.cols == veclen()); + assert(indices.cols == dists.cols); + + int n = 0; + int* indices_ptr = NULL; + DistanceType* dists_ptr = NULL; + if (indices.cols > 0) { + n = (int)indices.cols; + indices_ptr = indices[0]; + dists_ptr = dists[0]; + } + + RadiusUniqueResultSet<DistanceType> resultSet((DistanceType)radius); + resultSet.clear(); + findNeighbors(resultSet, query[0], params); + if (n>0) { + if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices_ptr, dists_ptr, n); + else resultSet.copy(indices_ptr, dists_ptr, n); + } + + return (int)resultSet.size(); + } + + /** + * \brief Saves the index to a stream + * \param stream The stream to save the index to + */ + virtual void saveIndex(FILE* stream) = 0; + + /** + * \brief Loads the index from a stream + * \param stream The stream from which the index is loaded + */ + virtual void loadIndex(FILE* stream) = 0; + + /** + * \returns number of features in this index. + */ + virtual size_t size() const = 0; + + /** + * \returns The dimensionality of the features in this index. + */ + virtual size_t veclen() const = 0; + + /** + * \returns The amount of memory (in bytes) used by the index. + */ + virtual int usedMemory() const = 0; + + /** + * \returns The index type (kdtree, kmeans,...) + */ + virtual flann_algorithm_t getType() const = 0; + + /** + * \returns The index parameters + */ + virtual IndexParams getParameters() const = 0; + + + /** + * \brief Method that searches for nearest-neighbours + */ + virtual void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) = 0; +}; + +} + +#endif //OPENCV_FLANN_NNINDEX_H diff --git a/include/opencv2/flann/object_factory.h b/include/opencv2/flann/object_factory.h new file mode 100644 index 0000000..7f971c5 --- /dev/null +++ b/include/opencv2/flann/object_factory.h @@ -0,0 +1,91 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_OBJECT_FACTORY_H_ +#define OPENCV_FLANN_OBJECT_FACTORY_H_ + +#include <map> + +namespace cvflann +{ + +class CreatorNotFound +{ +}; + +template<typename BaseClass, + typename UniqueIdType, + typename ObjectCreator = BaseClass* (*)()> +class ObjectFactory +{ + typedef ObjectFactory<BaseClass,UniqueIdType,ObjectCreator> ThisClass; + typedef std::map<UniqueIdType, ObjectCreator> ObjectRegistry; + + // singleton class, private constructor + ObjectFactory() {} + +public: + + bool subscribe(UniqueIdType id, ObjectCreator creator) + { + if (object_registry.find(id) != object_registry.end()) return false; + + object_registry[id] = creator; + return true; + } + + bool unregister(UniqueIdType id) + { + return object_registry.erase(id) == 1; + } + + ObjectCreator create(UniqueIdType id) + { + typename ObjectRegistry::const_iterator iter = object_registry.find(id); + + if (iter == object_registry.end()) { + throw CreatorNotFound(); + } + + return iter->second; + } + + static ThisClass& instance() + { + static ThisClass the_factory; + return the_factory; + } +private: + ObjectRegistry object_registry; +}; + +} + +#endif /* OPENCV_FLANN_OBJECT_FACTORY_H_ */ diff --git a/include/opencv2/flann/params.h b/include/opencv2/flann/params.h new file mode 100644 index 0000000..95ef4cd --- /dev/null +++ b/include/opencv2/flann/params.h @@ -0,0 +1,99 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_PARAMS_H_ +#define OPENCV_FLANN_PARAMS_H_ + +#include "any.h" +#include "general.h" +#include <iostream> +#include <map> + + +namespace cvflann +{ + +typedef std::map<cv::String, any> IndexParams; + +struct SearchParams : public IndexParams +{ + SearchParams(int checks = 32, float eps = 0, bool sorted = true ) + { + // how many leafs to visit when searching for neighbours (-1 for unlimited) + (*this)["checks"] = checks; + // search for eps-approximate neighbours (default: 0) + (*this)["eps"] = eps; + // only for radius search, require neighbours sorted by distance (default: true) + (*this)["sorted"] = sorted; + } +}; + + +template<typename T> +T get_param(const IndexParams& params, cv::String name, const T& default_value) +{ + IndexParams::const_iterator it = params.find(name); + if (it != params.end()) { + return it->second.cast<T>(); + } + else { + return default_value; + } +} + +template<typename T> +T get_param(const IndexParams& params, cv::String name) +{ + IndexParams::const_iterator it = params.find(name); + if (it != params.end()) { + return it->second.cast<T>(); + } + else { + throw FLANNException(cv::String("Missing parameter '")+name+cv::String("' in the parameters given")); + } +} + +inline void print_params(const IndexParams& params, std::ostream& stream) +{ + IndexParams::const_iterator it; + + for(it=params.begin(); it!=params.end(); ++it) { + stream << it->first << " : " << it->second << std::endl; + } +} + +inline void print_params(const IndexParams& params) +{ + print_params(params, std::cout); +} + +} + + +#endif /* OPENCV_FLANN_PARAMS_H_ */ diff --git a/include/opencv2/flann/random.h b/include/opencv2/flann/random.h new file mode 100644 index 0000000..d678474 --- /dev/null +++ b/include/opencv2/flann/random.h @@ -0,0 +1,155 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_RANDOM_H +#define OPENCV_FLANN_RANDOM_H + +#include <algorithm> +#include <cstdlib> +#include <vector> + +#include "general.h" + +namespace cvflann +{ + +inline int rand() +{ +#ifndef OPENCV_FLANN_USE_STD_RAND +# if INT_MAX == RAND_MAX + int v = cv::theRNG().next() & INT_MAX; +# else + int v = cv::theRNG().uniform(0, RAND_MAX + 1); +# endif +#else + int v = std::rand(); +#endif // OPENCV_FLANN_USE_STD_RAND + return v; +} + +/** + * Seeds the random number generator + * @param seed Random seed + */ +inline void seed_random(unsigned int seed) +{ +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::theRNG() = cv::RNG(seed); +#else + std::srand(seed); +#endif +} + +/* + * Generates a random double value. + */ +/** + * Generates a random double value. + * @param high Upper limit + * @param low Lower limit + * @return Random double value + */ +inline double rand_double(double high = 1.0, double low = 0) +{ + return low + ((high-low) * (rand() / (RAND_MAX + 1.0))); +} + +/** + * Generates a random integer value. + * @param high Upper limit + * @param low Lower limit + * @return Random integer value + */ +inline int rand_int(int high = RAND_MAX, int low = 0) +{ + return low + (int) ( double(high-low) * (rand() / (RAND_MAX + 1.0))); +} + +/** + * Random number generator that returns a distinct number from + * the [0,n) interval each time. + */ +class UniqueRandom +{ + std::vector<int> vals_; + int size_; + int counter_; + +public: + /** + * Constructor. + * @param n Size of the interval from which to generate + * @return + */ + UniqueRandom(int n) + { + init(n); + } + + /** + * Initializes the number generator. + * @param n the size of the interval from which to generate random numbers. + */ + void init(int n) + { + // create and initialize an array of size n + vals_.resize(n); + size_ = n; + for (int i = 0; i < size_; ++i) vals_[i] = i; + + // shuffle the elements in the array +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(vals_); +#else + std::random_shuffle(vals_.begin(), vals_.end()); +#endif + + counter_ = 0; + } + + /** + * Return a distinct random integer in greater or equal to 0 and less + * than 'n' on each call. It should be called maximum 'n' times. + * Returns: a random integer + */ + int next() + { + if (counter_ == size_) { + return -1; + } + else { + return vals_[counter_++]; + } + } +}; + +} + +#endif //OPENCV_FLANN_RANDOM_H diff --git a/include/opencv2/flann/result_set.h b/include/opencv2/flann/result_set.h new file mode 100644 index 0000000..5c69ac2 --- /dev/null +++ b/include/opencv2/flann/result_set.h @@ -0,0 +1,543 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_RESULTSET_H +#define OPENCV_FLANN_RESULTSET_H + +#include <algorithm> +#include <cstring> +#include <iostream> +#include <limits> +#include <set> +#include <vector> + +namespace cvflann +{ + +/* This record represents a branch point when finding neighbors in + the tree. It contains a record of the minimum distance to the query + point, as well as the node at which the search resumes. + */ + +template <typename T, typename DistanceType> +struct BranchStruct +{ + T node; /* Tree node at which search resumes */ + DistanceType mindist; /* Minimum distance to query for all nodes below. */ + + BranchStruct() {} + BranchStruct(const T& aNode, DistanceType dist) : node(aNode), mindist(dist) {} + + bool operator<(const BranchStruct<T, DistanceType>& rhs) const + { + return mindist<rhs.mindist; + } +}; + + +template <typename DistanceType> +class ResultSet +{ +public: + virtual ~ResultSet() {} + + virtual bool full() const = 0; + + virtual void addPoint(DistanceType dist, int index) = 0; + + virtual DistanceType worstDist() const = 0; + +}; + +/** + * KNNSimpleResultSet does not ensure that the element it holds are unique. + * Is used in those cases where the nearest neighbour algorithm used does not + * attempt to insert the same element multiple times. + */ +template <typename DistanceType> +class KNNSimpleResultSet : public ResultSet<DistanceType> +{ + int* indices; + DistanceType* dists; + int capacity; + int count; + DistanceType worst_distance_; + +public: + KNNSimpleResultSet(int capacity_) : capacity(capacity_), count(0) + { + } + + void init(int* indices_, DistanceType* dists_) + { + indices = indices_; + dists = dists_; + count = 0; + worst_distance_ = (std::numeric_limits<DistanceType>::max)(); + dists[capacity-1] = worst_distance_; + } + + size_t size() const + { + return count; + } + + bool full() const CV_OVERRIDE + { + return count == capacity; + } + + + void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + if (dist >= worst_distance_) return; + int i; + for (i=count; i>0; --i) { +#ifdef FLANN_FIRST_MATCH + if ( (dists[i-1]>dist) || ((dist==dists[i-1])&&(indices[i-1]>index)) ) +#else + if (dists[i-1]>dist) +#endif + { + if (i<capacity) { + dists[i] = dists[i-1]; + indices[i] = indices[i-1]; + } + } + else break; + } + if (count < capacity) ++count; + dists[i] = dist; + indices[i] = index; + worst_distance_ = dists[capacity-1]; + } + + DistanceType worstDist() const CV_OVERRIDE + { + return worst_distance_; + } +}; + +/** + * K-Nearest neighbour result set. Ensures that the elements inserted are unique + */ +template <typename DistanceType> +class KNNResultSet : public ResultSet<DistanceType> +{ + int* indices; + DistanceType* dists; + int capacity; + int count; + DistanceType worst_distance_; + +public: + KNNResultSet(int capacity_) : capacity(capacity_), count(0) + { + } + + void init(int* indices_, DistanceType* dists_) + { + indices = indices_; + dists = dists_; + count = 0; + worst_distance_ = (std::numeric_limits<DistanceType>::max)(); + dists[capacity-1] = worst_distance_; + } + + size_t size() const + { + return count; + } + + bool full() const CV_OVERRIDE + { + return count == capacity; + } + + + void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + if (dist >= worst_distance_) return; + int i; + for (i = count; i > 0; --i) { +#ifdef FLANN_FIRST_MATCH + if ( (dists[i-1]<=dist) && ((dist!=dists[i-1])||(indices[i-1]<=index)) ) +#else + if (dists[i-1]<=dist) +#endif + { + // Check for duplicate indices + int j = i - 1; + while ((j >= 0) && (dists[j] == dist)) { + if (indices[j] == index) { + return; + } + --j; + } + break; + } + } + + if (count < capacity) ++count; + for (int j = count-1; j > i; --j) { + dists[j] = dists[j-1]; + indices[j] = indices[j-1]; + } + dists[i] = dist; + indices[i] = index; + worst_distance_ = dists[capacity-1]; + } + + DistanceType worstDist() const CV_OVERRIDE + { + return worst_distance_; + } +}; + + +/** + * A result-set class used when performing a radius based search. + */ +template <typename DistanceType> +class RadiusResultSet : public ResultSet<DistanceType> +{ + DistanceType radius; + int* indices; + DistanceType* dists; + size_t capacity; + size_t count; + +public: + RadiusResultSet(DistanceType radius_, int* indices_, DistanceType* dists_, int capacity_) : + radius(radius_), indices(indices_), dists(dists_), capacity(capacity_) + { + init(); + } + + ~RadiusResultSet() + { + } + + void init() + { + count = 0; + } + + size_t size() const + { + return count; + } + + bool full() const + { + return true; + } + + void addPoint(DistanceType dist, int index) + { + if (dist<radius) { + if ((capacity>0)&&(count < capacity)) { + dists[count] = dist; + indices[count] = index; + } + count++; + } + } + + DistanceType worstDist() const + { + return radius; + } + +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the k NN neighbors + * Faster than KNNResultSet as it uses a binary heap and does not maintain two arrays + */ +template<typename DistanceType> +class UniqueResultSet : public ResultSet<DistanceType> +{ +public: + struct DistIndex + { + DistIndex(DistanceType dist, unsigned int index) : + dist_(dist), index_(index) + { + } + bool operator<(const DistIndex dist_index) const + { + return (dist_ < dist_index.dist_) || ((dist_ == dist_index.dist_) && index_ < dist_index.index_); + } + DistanceType dist_; + unsigned int index_; + }; + + /** Default cosntructor */ + UniqueResultSet() : + is_full_(false), worst_distance_(std::numeric_limits<DistanceType>::max()) + { + } + + /** Check the status of the set + * @return true if we have k NN + */ + inline bool full() const CV_OVERRIDE + { + return is_full_; + } + + /** Remove all elements in the set + */ + virtual void clear() = 0; + + /** Copy the set to two C arrays + * @param indices pointer to a C array of indices + * @param dist pointer to a C array of distances + * @param n_neighbors the number of neighbors to copy + */ + virtual void copy(int* indices, DistanceType* dist, int n_neighbors = -1) const + { + if (n_neighbors < 0) { + for (typename std::set<DistIndex>::const_iterator dist_index = dist_indices_.begin(), dist_index_end = + dist_indices_.end(); dist_index != dist_index_end; ++dist_index, ++indices, ++dist) { + *indices = dist_index->index_; + *dist = dist_index->dist_; + } + } + else { + int i = 0; + for (typename std::set<DistIndex>::const_iterator dist_index = dist_indices_.begin(), dist_index_end = + dist_indices_.end(); (dist_index != dist_index_end) && (i < n_neighbors); ++dist_index, ++indices, ++dist, ++i) { + *indices = dist_index->index_; + *dist = dist_index->dist_; + } + } + } + + /** Copy the set to two C arrays but sort it according to the distance first + * @param indices pointer to a C array of indices + * @param dist pointer to a C array of distances + * @param n_neighbors the number of neighbors to copy + */ + virtual void sortAndCopy(int* indices, DistanceType* dist, int n_neighbors = -1) const + { + copy(indices, dist, n_neighbors); + } + + /** The number of neighbors in the set + * @return + */ + size_t size() const + { + return dist_indices_.size(); + } + + /** The distance of the furthest neighbor + * If we don't have enough neighbors, it returns the max possible value + * @return + */ + inline DistanceType worstDist() const CV_OVERRIDE + { + return worst_distance_; + } +protected: + /** Flag to say if the set is full */ + bool is_full_; + + /** The worst distance found so far */ + DistanceType worst_distance_; + + /** The best candidates so far */ + std::set<DistIndex> dist_indices_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the k NN neighbors + * Faster than KNNResultSet as it uses a binary heap and does not maintain two arrays + */ +template<typename DistanceType> +class KNNUniqueResultSet : public UniqueResultSet<DistanceType> +{ +public: + /** Constructor + * @param capacity the number of neighbors to store at max + */ + KNNUniqueResultSet(unsigned int capacity) : capacity_(capacity) + { + this->is_full_ = false; + this->clear(); + } + + /** Add a possible candidate to the best neighbors + * @param dist distance for that neighbor + * @param index index of that neighbor + */ + inline void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + // Don't do anything if we are worse than the worst + if (dist >= worst_distance_) return; + dist_indices_.insert(DistIndex(dist, index)); + + if (is_full_) { + if (dist_indices_.size() > capacity_) { + dist_indices_.erase(*dist_indices_.rbegin()); + worst_distance_ = dist_indices_.rbegin()->dist_; + } + } + else if (dist_indices_.size() == capacity_) { + is_full_ = true; + worst_distance_ = dist_indices_.rbegin()->dist_; + } + } + + /** Remove all elements in the set + */ + void clear() CV_OVERRIDE + { + dist_indices_.clear(); + worst_distance_ = std::numeric_limits<DistanceType>::max(); + is_full_ = false; + } + +protected: + typedef typename UniqueResultSet<DistanceType>::DistIndex DistIndex; + using UniqueResultSet<DistanceType>::is_full_; + using UniqueResultSet<DistanceType>::worst_distance_; + using UniqueResultSet<DistanceType>::dist_indices_; + + /** The number of neighbors to keep */ + unsigned int capacity_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the radius nearest neighbors + * It is more accurate than RadiusResult as it is not limited in the number of neighbors + */ +template<typename DistanceType> +class RadiusUniqueResultSet : public UniqueResultSet<DistanceType> +{ +public: + /** Constructor + * @param radius the maximum distance of a neighbor + */ + RadiusUniqueResultSet(DistanceType radius) : + radius_(radius) + { + is_full_ = true; + } + + /** Add a possible candidate to the best neighbors + * @param dist distance for that neighbor + * @param index index of that neighbor + */ + void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + if (dist <= radius_) dist_indices_.insert(DistIndex(dist, index)); + } + + /** Remove all elements in the set + */ + inline void clear() CV_OVERRIDE + { + dist_indices_.clear(); + } + + + /** Check the status of the set + * @return alwys false + */ + inline bool full() const CV_OVERRIDE + { + return true; + } + + /** The distance of the furthest neighbor + * If we don't have enough neighbors, it returns the max possible value + * @return + */ + inline DistanceType worstDist() const CV_OVERRIDE + { + return radius_; + } +private: + typedef typename UniqueResultSet<DistanceType>::DistIndex DistIndex; + using UniqueResultSet<DistanceType>::dist_indices_; + using UniqueResultSet<DistanceType>::is_full_; + + /** The furthest distance a neighbor can be */ + DistanceType radius_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the k NN neighbors within a radius distance + */ +template<typename DistanceType> +class KNNRadiusUniqueResultSet : public KNNUniqueResultSet<DistanceType> +{ +public: + /** Constructor + * @param capacity the number of neighbors to store at max + * @param radius the maximum distance of a neighbor + */ + KNNRadiusUniqueResultSet(unsigned int capacity, DistanceType radius) + { + this->capacity_ = capacity; + this->radius_ = radius; + this->dist_indices_.reserve(capacity_); + this->clear(); + } + + /** Remove all elements in the set + */ + void clear() + { + dist_indices_.clear(); + worst_distance_ = radius_; + is_full_ = false; + } +private: + using KNNUniqueResultSet<DistanceType>::dist_indices_; + using KNNUniqueResultSet<DistanceType>::is_full_; + using KNNUniqueResultSet<DistanceType>::worst_distance_; + + /** The maximum number of neighbors to consider */ + unsigned int capacity_; + + /** The maximum distance of a neighbor */ + DistanceType radius_; +}; +} + +#endif //OPENCV_FLANN_RESULTSET_H diff --git a/include/opencv2/flann/sampling.h b/include/opencv2/flann/sampling.h new file mode 100644 index 0000000..396f177 --- /dev/null +++ b/include/opencv2/flann/sampling.h @@ -0,0 +1,81 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_SAMPLING_H_ +#define OPENCV_FLANN_SAMPLING_H_ + +#include "matrix.h" +#include "random.h" + +namespace cvflann +{ + +template<typename T> +Matrix<T> random_sample(Matrix<T>& srcMatrix, long size, bool remove = false) +{ + Matrix<T> newSet(new T[size * srcMatrix.cols], size,srcMatrix.cols); + + T* src,* dest; + for (long i=0; i<size; ++i) { + long r = rand_int((int)(srcMatrix.rows-i)); + dest = newSet[i]; + src = srcMatrix[r]; + std::copy(src, src+srcMatrix.cols, dest); + if (remove) { + src = srcMatrix[srcMatrix.rows-i-1]; + dest = srcMatrix[r]; + std::copy(src, src+srcMatrix.cols, dest); + } + } + if (remove) { + srcMatrix.rows -= size; + } + return newSet; +} + +template<typename T> +Matrix<T> random_sample(const Matrix<T>& srcMatrix, size_t size) +{ + UniqueRandom rand((int)srcMatrix.rows); + Matrix<T> newSet(new T[size * srcMatrix.cols], size,srcMatrix.cols); + + T* src,* dest; + for (size_t i=0; i<size; ++i) { + long r = rand.next(); + dest = newSet[i]; + src = srcMatrix[r]; + std::copy(src, src+srcMatrix.cols, dest); + } + return newSet; +} + +} // namespace + + +#endif /* OPENCV_FLANN_SAMPLING_H_ */ diff --git a/include/opencv2/flann/saving.h b/include/opencv2/flann/saving.h new file mode 100644 index 0000000..7e3bea5 --- /dev/null +++ b/include/opencv2/flann/saving.h @@ -0,0 +1,187 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE NNIndexGOODS 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_SAVING_H_ +#define OPENCV_FLANN_SAVING_H_ + +#include <cstring> +#include <vector> + +#include "general.h" +#include "nn_index.h" + +#ifdef FLANN_SIGNATURE_ +#undef FLANN_SIGNATURE_ +#endif +#define FLANN_SIGNATURE_ "FLANN_INDEX" + +namespace cvflann +{ + +template <typename T> +struct Datatype {}; +template<> +struct Datatype<char> { static flann_datatype_t type() { return FLANN_INT8; } }; +template<> +struct Datatype<short> { static flann_datatype_t type() { return FLANN_INT16; } }; +template<> +struct Datatype<int> { static flann_datatype_t type() { return FLANN_INT32; } }; +template<> +struct Datatype<unsigned char> { static flann_datatype_t type() { return FLANN_UINT8; } }; +template<> +struct Datatype<unsigned short> { static flann_datatype_t type() { return FLANN_UINT16; } }; +template<> +struct Datatype<unsigned int> { static flann_datatype_t type() { return FLANN_UINT32; } }; +template<> +struct Datatype<float> { static flann_datatype_t type() { return FLANN_FLOAT32; } }; +template<> +struct Datatype<double> { static flann_datatype_t type() { return FLANN_FLOAT64; } }; + + +/** + * Structure representing the index header. + */ +struct IndexHeader +{ + char signature[16]; + char version[16]; + flann_datatype_t data_type; + flann_algorithm_t index_type; + size_t rows; + size_t cols; +}; + +/** + * Saves index header to stream + * + * @param stream - Stream to save to + * @param index - The index to save + */ +template<typename Distance> +void save_header(FILE* stream, const NNIndex<Distance>& index) +{ + IndexHeader header; + memset(header.signature, 0, sizeof(header.signature)); + strcpy(header.signature, FLANN_SIGNATURE_); + memset(header.version, 0, sizeof(header.version)); + strcpy(header.version, FLANN_VERSION_); + header.data_type = Datatype<typename Distance::ElementType>::type(); + header.index_type = index.getType(); + header.rows = index.size(); + header.cols = index.veclen(); + + std::fwrite(&header, sizeof(header),1,stream); +} + + +/** + * + * @param stream - Stream to load from + * @return Index header + */ +inline IndexHeader load_header(FILE* stream) +{ + IndexHeader header; + size_t read_size = fread(&header,sizeof(header),1,stream); + + if (read_size!=(size_t)1) { + throw FLANNException("Invalid index file, cannot read"); + } + + if (strcmp(header.signature,FLANN_SIGNATURE_)!=0) { + throw FLANNException("Invalid index file, wrong signature"); + } + + return header; + +} + + +template<typename T> +void save_value(FILE* stream, const T& value, size_t count = 1) +{ + fwrite(&value, sizeof(value),count, stream); +} + +template<typename T> +void save_value(FILE* stream, const cvflann::Matrix<T>& value) +{ + fwrite(&value, sizeof(value),1, stream); + fwrite(value.data, sizeof(T),value.rows*value.cols, stream); +} + +template<typename T> +void save_value(FILE* stream, const std::vector<T>& value) +{ + size_t size = value.size(); + fwrite(&size, sizeof(size_t), 1, stream); + fwrite(&value[0], sizeof(T), size, stream); +} + +template<typename T> +void load_value(FILE* stream, T& value, size_t count = 1) +{ + size_t read_cnt = fread(&value, sizeof(value), count, stream); + if (read_cnt != count) { + throw FLANNException("Cannot read from file"); + } +} + +template<typename T> +void load_value(FILE* stream, cvflann::Matrix<T>& value) +{ + size_t read_cnt = fread(&value, sizeof(value), 1, stream); + if (read_cnt != 1) { + throw FLANNException("Cannot read from file"); + } + value.data = new T[value.rows*value.cols]; + read_cnt = fread(value.data, sizeof(T), value.rows*value.cols, stream); + if (read_cnt != (size_t)(value.rows*value.cols)) { + throw FLANNException("Cannot read from file"); + } +} + + +template<typename T> +void load_value(FILE* stream, std::vector<T>& value) +{ + size_t size; + size_t read_cnt = fread(&size, sizeof(size_t), 1, stream); + if (read_cnt!=1) { + throw FLANNException("Cannot read from file"); + } + value.resize(size); + read_cnt = fread(&value[0], sizeof(T), size, stream); + if (read_cnt != size) { + throw FLANNException("Cannot read from file"); + } +} + +} + +#endif /* OPENCV_FLANN_SAVING_H_ */ diff --git a/include/opencv2/flann/simplex_downhill.h b/include/opencv2/flann/simplex_downhill.h new file mode 100644 index 0000000..145901a --- /dev/null +++ b/include/opencv2/flann/simplex_downhill.h @@ -0,0 +1,186 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ +#define OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ + +namespace cvflann +{ + +/** + Adds val to array vals (and point to array points) and keeping the arrays sorted by vals. + */ +template <typename T> +void addValue(int pos, float val, float* vals, T* point, T* points, int n) +{ + vals[pos] = val; + for (int i=0; i<n; ++i) { + points[pos*n+i] = point[i]; + } + + // bubble down + int j=pos; + while (j>0 && vals[j]<vals[j-1]) { + swap(vals[j],vals[j-1]); + for (int i=0; i<n; ++i) { + swap(points[j*n+i],points[(j-1)*n+i]); + } + --j; + } +} + + +/** + Simplex downhill optimization function. + Preconditions: points is a 2D mattrix of size (n+1) x n + func is the cost function taking n an array of n params and returning float + vals is the cost function in the n+1 simplex points, if NULL it will be computed + + Postcondition: returns optimum value and points[0..n] are the optimum parameters + */ +template <typename T, typename F> +float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL ) +{ + const int MAX_ITERATIONS = 10; + + assert(n>0); + + T* p_o = new T[n]; + T* p_r = new T[n]; + T* p_e = new T[n]; + + int alpha = 1; + + int iterations = 0; + + bool ownVals = false; + if (vals == NULL) { + ownVals = true; + vals = new float[n+1]; + for (int i=0; i<n+1; ++i) { + float val = func(points+i*n); + addValue(i, val, vals, points+i*n, points, n); + } + } + int nn = n*n; + + while (true) { + + if (iterations++ > MAX_ITERATIONS) break; + + // compute average of simplex points (except the highest point) + for (int j=0; j<n; ++j) { + p_o[j] = 0; + for (int i=0; i<n; ++i) { + p_o[i] += points[j*n+i]; + } + } + for (int i=0; i<n; ++i) { + p_o[i] /= n; + } + + bool converged = true; + for (int i=0; i<n; ++i) { + if (p_o[i] != points[nn+i]) { + converged = false; + } + } + if (converged) break; + + // trying a reflection + for (int i=0; i<n; ++i) { + p_r[i] = p_o[i] + alpha*(p_o[i]-points[nn+i]); + } + float val_r = func(p_r); + + if ((val_r>=vals[0])&&(val_r<vals[n])) { + // reflection between second highest and lowest + // add it to the simplex + Logger::info("Choosing reflection\n"); + addValue(n, val_r,vals, p_r, points, n); + continue; + } + + if (val_r<vals[0]) { + // value is smaller than smalest in simplex + + // expand some more to see if it drops further + for (int i=0; i<n; ++i) { + p_e[i] = 2*p_r[i]-p_o[i]; + } + float val_e = func(p_e); + + if (val_e<val_r) { + Logger::info("Choosing reflection and expansion\n"); + addValue(n, val_e,vals,p_e,points,n); + } + else { + Logger::info("Choosing reflection\n"); + addValue(n, val_r,vals,p_r,points,n); + } + continue; + } + if (val_r>=vals[n]) { + for (int i=0; i<n; ++i) { + p_e[i] = (p_o[i]+points[nn+i])/2; + } + float val_e = func(p_e); + + if (val_e<vals[n]) { + Logger::info("Choosing contraction\n"); + addValue(n,val_e,vals,p_e,points,n); + continue; + } + } + { + Logger::info("Full contraction\n"); + for (int j=1; j<=n; ++j) { + for (int i=0; i<n; ++i) { + points[j*n+i] = (points[j*n+i]+points[i])/2; + } + float val = func(points+j*n); + addValue(j,val,vals,points+j*n,points,n); + } + } + } + + float bestVal = vals[0]; + + delete[] p_r; + delete[] p_o; + delete[] p_e; + if (ownVals) delete[] vals; + + return bestVal; +} + +} + +#endif //OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ diff --git a/include/opencv2/flann/timer.h b/include/opencv2/flann/timer.h new file mode 100644 index 0000000..f771a34 --- /dev/null +++ b/include/opencv2/flann/timer.h @@ -0,0 +1,94 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. + *************************************************************************/ + +#ifndef OPENCV_FLANN_TIMER_H +#define OPENCV_FLANN_TIMER_H + +#include <time.h> +#include "opencv2/core.hpp" +#include "opencv2/core/utility.hpp" + +namespace cvflann +{ + +/** + * A start-stop timer class. + * + * Can be used to time portions of code. + */ +class StartStopTimer +{ + int64 startTime; + +public: + /** + * Value of the timer. + */ + double value; + + + /** + * Constructor. + */ + StartStopTimer() + { + reset(); + } + + /** + * Starts the timer. + */ + void start() + { + startTime = cv::getTickCount(); + } + + /** + * Stops the timer and updates timer value. + */ + void stop() + { + int64 stopTime = cv::getTickCount(); + value += ( (double)stopTime - startTime) / cv::getTickFrequency(); + } + + /** + * Resets the timer value to 0. + */ + void reset() + { + value = 0; + } + +}; + +} + +#endif // FLANN_TIMER_H diff --git a/include/opencv2/fuzzy.hpp b/include/opencv2/fuzzy.hpp new file mode 100644 index 0000000..d660cc3 --- /dev/null +++ b/include/opencv2/fuzzy.hpp @@ -0,0 +1,71 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_FUZZY_H__ +#define __OPENCV_FUZZY_H__ + +#include "opencv2/fuzzy/types.hpp" +#include "opencv2/fuzzy/fuzzy_F0_math.hpp" +#include "opencv2/fuzzy/fuzzy_F1_math.hpp" +#include "opencv2/fuzzy/fuzzy_image.hpp" + +/** +@defgroup fuzzy Image processing based on fuzzy mathematics + +Namespace for all functions is `ft`. The module brings implementation of the last image processing algorithms based on fuzzy mathematics. Method are named based on the pattern `FT`_degree_dimension`_`method. + + @{ + @defgroup f0_math Math with F0-transform support + +Fuzzy transform (\f$F^0\f$-transform) of the 0th degree transforms whole image to a matrix of its components. These components are used in latter computation where each of them represents average color of certain subarea. + + @defgroup f1_math Math with F1-transform support + +Fuzzy transform (\f$F^1\f$-transform) of the 1th degree transforms whole image to a matrix of its components. Each component is polynomial of the 1th degree carrying information about average color and average gradient of certain subarea. + + @defgroup f_image Fuzzy image processing + +Image proceesing based on fuzzy mathematics namely F-transform. + @} + +*/ + +#endif // __OPENCV_FUZZY_H__ diff --git a/include/opencv2/fuzzy/fuzzy_F0_math.hpp b/include/opencv2/fuzzy/fuzzy_F0_math.hpp new file mode 100644 index 0000000..7beeb9b --- /dev/null +++ b/include/opencv2/fuzzy/fuzzy_F0_math.hpp @@ -0,0 +1,121 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_FUZZY_F0_MATH_H__ +#define __OPENCV_FUZZY_F0_MATH_H__ + +#include "opencv2/fuzzy/types.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ + +namespace ft +{ + //! @addtogroup f0_math + //! @{ + + /** @brief Computes components of the array using direct \f$F^0\f$-transform. + @param matrix Input array. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param components Output 32-bit float array for the components. + @param mask Mask can be used for unwanted area marking. + + The function computes components using predefined kernel and mask. + */ + CV_EXPORTS_W void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask = noArray()); + + /** @brief Computes inverse \f$F^0\f$-transfrom. + @param components Input 32-bit float single channel array for the components. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param width Width of the output array. + @param height Height of the output array. + + Computation of inverse F-transform. + */ + CV_EXPORTS_W void FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); + + /** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once. + @param matrix Input matrix. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param mask Mask used for unwanted area marking. + + This function computes F-transfrom and inverse F-transfotm in one step. It is fully sufficient and optimized for `cv::Mat`. + */ + CV_EXPORTS_W void FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray()); + + /** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once and return state. + @param matrix Input matrix. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param mask Mask used for unwanted area marking. + @param maskOutput Mask after one iteration. + @param firstStop If **true** function returns -1 when first problem appears. In case of `false` the process is completed and summation of all problems returned. + + This function computes iteration of F-transfrom and inverse F-transfotm and handle image and mask change. The function is used in `ft::inpaint` function. + */ + CV_EXPORTS_W int FT02D_iteration(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask, OutputArray maskOutput, bool firstStop); + + /** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function. + @param matrix Input 3 channels matrix. + @param radius Radius of the `ft::LINEAR` basic function. + @param output Output array. + + This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~10 times faster than `ft::FT02D_process` method. + */ + CV_EXPORTS_W void FT02D_FL_process(InputArray matrix, const int radius, OutputArray output); + + /** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function. + @param matrix Input 3 channels matrix. + @param radius Radius of the `ft::LINEAR` basic function. + @param output Output array. + + This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~9 times faster then `ft::FT02D_process` method and more accurate than `ft::FT02D_FL_process` method. + */ + CV_EXPORTS_W void FT02D_FL_process_float(InputArray matrix, const int radius, OutputArray output); + + //! @} +} +} + +#endif // __OPENCV_FUZZY_F0_MATH_H__ diff --git a/include/opencv2/fuzzy/fuzzy_F1_math.hpp b/include/opencv2/fuzzy/fuzzy_F1_math.hpp new file mode 100644 index 0000000..3320e67 --- /dev/null +++ b/include/opencv2/fuzzy/fuzzy_F1_math.hpp @@ -0,0 +1,124 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_FUZZY_F1_MATH_H__ +#define __OPENCV_FUZZY_F1_MATH_H__ + +#include "opencv2/fuzzy/types.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ + +namespace ft +{ + //! @addtogroup f1_math + //! @{ + + /** @brief Computes components of the array using direct \f$F^1\f$-transform. + @param matrix Input array. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param components Output 32-bit float array for the components. + + The function computes linear components using predefined kernel. + */ + CV_EXPORTS_W void FT12D_components(InputArray matrix, InputArray kernel, OutputArray components); + + /** @brief Computes elements of \f$F^1\f$-transform components. + @param matrix Input array. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param c00 Elements represent average color. + @param c10 Elements represent average vertical gradient. + @param c01 Elements represent average horizontal gradient. + @param components Output 32-bit float array for the components. + @param mask Mask can be used for unwanted area marking. + + The function computes components and its elements using predefined kernel and mask. + */ + CV_EXPORTS_W void FT12D_polynomial(InputArray matrix, InputArray kernel, OutputArray c00, OutputArray c10, OutputArray c01, OutputArray components, InputArray mask = noArray()); + + /** @brief Creates vertical matrix for \f$F^1\f$-transform computation. + @param radius Radius of the basic function. + @param matrix The vertical matrix. + @param chn Number of channels. + + The function creates helper vertical matrix for \f$F^1\f$-transfrom processing. It is used for gradient computation. + */ + CV_EXPORTS_W void FT12D_createPolynomMatrixVertical(int radius, OutputArray matrix, const int chn); + + /** @brief Creates horizontal matrix for \f$F^1\f$-transform computation. + @param radius Radius of the basic function. + @param matrix The horizontal matrix. + @param chn Number of channels. + + The function creates helper horizontal matrix for \f$F^1\f$-transfrom processing. It is used for gradient computation. + */ + CV_EXPORTS_W void FT12D_createPolynomMatrixHorizontal(int radius, OutputArray matrix, const int chn); + + /** @brief Computes \f$F^1\f$-transfrom and inverse \f$F^1\f$-transfrom at once. + @param matrix Input matrix. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param mask Mask used for unwanted area marking. + + This function computes \f$F^1\f$-transfrom and inverse \f$F^1\f$-transfotm in one step. It is fully sufficient and optimized for `cv::Mat`. + + @note + F-transform technique of first degreee is described in paper @cite Vlas:FT. + */ + CV_EXPORTS_W void FT12D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray()); + + /** @brief Computes inverse \f$F^1\f$-transfrom. + @param components Input 32-bit float single channel array for the components. + @param kernel Kernel used for processing. The same kernel as for components computation must be used. + @param output Output 32-bit float array. + @param width Width of the output array. + @param height Height of the output array. + + Computation of inverse \f$F^1\f$-transform. + */ + CV_EXPORTS_W void FT12D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); + + //! @} +} +} + +#endif // __OPENCV_FUZZY_F1_MATH_H__ diff --git a/include/opencv2/fuzzy/fuzzy_image.hpp b/include/opencv2/fuzzy/fuzzy_image.hpp new file mode 100644 index 0000000..9c9eeff --- /dev/null +++ b/include/opencv2/fuzzy/fuzzy_image.hpp @@ -0,0 +1,109 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_FUZZY_IMAGE_H__ +#define __OPENCV_FUZZY_IMAGE_H__ + +#include "types.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ + +namespace ft +{ + //! @addtogroup f_image + //! @{ + + /** @brief Creates kernel from basic functions. + @param A Basic function used in axis **x**. + @param B Basic function used in axis **y**. + @param kernel Final 32-bit kernel derived from **A** and **B**. + @param chn Number of kernel channels. + + The function creates kernel usable for latter fuzzy image processing. + */ + CV_EXPORTS_AS(createKernel1) void createKernel(InputArray A, InputArray B, OutputArray kernel, const int chn); + + /** @brief Creates kernel from general functions. + @param function Function type could be one of the following: + - **LINEAR** Linear basic function. + @param radius Radius of the basic function. + @param kernel Final 32-bit kernel. + @param chn Number of kernel channels. + + The function creates kernel from predefined functions. + */ + CV_EXPORTS_W void createKernel(int function, int radius, OutputArray kernel, const int chn); + + /** @brief Image inpainting + @param image Input image. + @param mask Mask used for unwanted area marking. + @param output Output 32-bit image. + @param radius Radius of the basic function. + @param function Function type could be one of the following: + - `ft::LINEAR` Linear basic function. + @param algorithm Algorithm could be one of the following: + - `ft::ONE_STEP` One step algorithm. + - `ft::MULTI_STEP` This algorithm automaticaly increases radius of the basic function. + - `ft::ITERATIVE` Iterative algorithm running in more steps using partial computations. + + This function provides inpainting technique based on the fuzzy mathematic. + + @note + The algorithms are described in paper @cite Perf:rec. + */ + CV_EXPORTS_W void inpaint(InputArray image, InputArray mask, OutputArray output, int radius, int function, int algorithm); + + /** @brief Image filtering + @param image Input image. + @param kernel Final 32-bit kernel. + @param output Output 32-bit image. + + Filtering of the input image by means of F-transform. + */ + CV_EXPORTS_W void filter(InputArray image, InputArray kernel, OutputArray output); + + //! @} +} +} + +#endif // __OPENCV_FUZZY_IMAGE_H__ diff --git a/include/opencv2/fuzzy/types.hpp b/include/opencv2/fuzzy/types.hpp new file mode 100644 index 0000000..22e0a01 --- /dev/null +++ b/include/opencv2/fuzzy/types.hpp @@ -0,0 +1,70 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_FUZZY_TYPES_H__ +#define __OPENCV_FUZZY_TYPES_H__ + +namespace cv +{ + +namespace ft +{ + //! @addtogroup fuzzy + //! @{ + + enum + { + LINEAR = 1, //!< linear (triangular) shape + SINUS = 2 //!< sinusoidal shape + }; + + enum + { + ONE_STEP = 1, //!< processing in one step + MULTI_STEP = 2, //!< processing in multiple step + ITERATIVE = 3 //!< processing in several iterations + }; + + //! @} +} +} + +#endif // __OPENCV_FUZZY_TYPES_H__ diff --git a/include/opencv2/hfs.hpp b/include/opencv2/hfs.hpp new file mode 100644 index 0000000..2d84412 --- /dev/null +++ b/include/opencv2/hfs.hpp @@ -0,0 +1,153 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "opencv2/core.hpp" + +namespace cv { namespace hfs { + +/** @defgroup hfs Hierarchical Feature Selection for Efficient Image Segmentation + +The opencv hfs module contains an efficient algorithm to segment an image. +This module is implemented based on the paper Hierarchical Feature Selection for Efficient +Image Segmentation, ECCV 2016. The original project was developed by +Yun Liu(https://github.com/yun-liu/hfs). + + +Introduction to Hierarchical Feature Selection +---------------------------------------------- + + +This algorithm is executed in 3 stages: + +In the first stage, the algorithm uses SLIC (simple linear iterative clustering) algorithm +to obtain the superpixel of the input image. + +In the second stage, the algorithm view each superpixel as a node in the graph. +It will calculate a feature vector for each edge of the graph. It then calculates a weight +for each edge based on the feature vector and trained SVM parameters. After obtaining +weight for each edge, it will exploit EGB (Efficient Graph-based Image Segmentation) +algorithm to merge some nodes in the graph thus obtaining a coarser segmentation +After these operations, a post process will be executed to merge regions that are smaller +then a specific number of pixels into their nearby region. + +In the third stage, the algorithm exploits the similar mechanism to further merge +the small regions obtained in the second stage into even coarser segmentation. + +After these three stages, we can obtain the final segmentation of the image. +For further details about the algorithm, please refer to the original paper: +Hierarchical Feature Selection for Efficient Image Segmentation, ECCV 2016 + +*/ + +//! @addtogroup hfs +//! @{ +class CV_EXPORTS_W HfsSegment : public Algorithm { +public: + +/** @brief: set and get the parameter segEgbThresholdI. +* This parameter is used in the second stage mentioned above. +* It is a constant used to threshold weights of the edge when merging +* adjacent nodes when applying EGB algorithm. The segmentation result +* tends to have more regions remained if this value is large and vice versa. +*/ +CV_WRAP virtual void setSegEgbThresholdI(float c) = 0; +CV_WRAP virtual float getSegEgbThresholdI() = 0; + + +/** @brief: set and get the parameter minRegionSizeI. +* This parameter is used in the second stage +* mentioned above. After the EGB segmentation, regions that have fewer +* pixels then this parameter will be merged into it's adjacent region. +*/ +CV_WRAP virtual void setMinRegionSizeI(int n) = 0; +CV_WRAP virtual int getMinRegionSizeI() = 0; + + +/** @brief: set and get the parameter segEgbThresholdII. +* This parameter is used in the third stage +* mentioned above. It serves the same purpose as segEgbThresholdI. +* The segmentation result tends to have more regions remained if +* this value is large and vice versa. +*/ +CV_WRAP virtual void setSegEgbThresholdII(float c) = 0; +CV_WRAP virtual float getSegEgbThresholdII() = 0; + + +/** @brief: set and get the parameter minRegionSizeII. +* This parameter is used in the third stage +* mentioned above. It serves the same purpose as minRegionSizeI +*/ +CV_WRAP virtual void setMinRegionSizeII(int n) = 0; +CV_WRAP virtual int getMinRegionSizeII() = 0; + + +/** @brief: set and get the parameter spatialWeight. +* This parameter is used in the first stage +* mentioned above(the SLIC stage). It describes how important is the role +* of position when calculating the distance between each pixel and it's +* center. The exact formula to calculate the distance is +* \f$colorDistance + spatialWeight \times spatialDistance\f$. +* The segmentation result tends to have more local consistency +* if this value is larger. +*/ +CV_WRAP virtual void setSpatialWeight(float w) = 0; +CV_WRAP virtual float getSpatialWeight() = 0; + + +/** @brief: set and get the parameter slicSpixelSize. +* This parameter is used in the first stage mentioned +* above(the SLIC stage). It describes the size of each +* superpixel when initializing SLIC. Every superpixel +* approximately has \f$slicSpixelSize \times slicSpixelSize\f$ +* pixels in the begining. +*/ +CV_WRAP virtual void setSlicSpixelSize(int n) = 0; +CV_WRAP virtual int getSlicSpixelSize() = 0; + + +/** @brief: set and get the parameter numSlicIter. +* This parameter is used in the first stage. It +* describes how many iteration to perform when executing SLIC. +*/ +CV_WRAP virtual void setNumSlicIter(int n) = 0; +CV_WRAP virtual int getNumSlicIter() = 0; + +/** @brief do segmentation gpu +* @param src: the input image +* @param ifDraw: if draw the image in the returned Mat. if this parameter is false, +* then the content of the returned Mat is a matrix of index, describing the region +* each pixel belongs to. And it's data type is CV_16U. If this parameter is true, +* then the returned Mat is a segmented picture, and color of each region is the +* average color of all pixels in that region. And it's data type is the same as +* the input image +*/ +CV_WRAP virtual Mat performSegmentGpu(InputArray src, bool ifDraw = true) = 0; + +/** @brief do segmentation with cpu +* This method is only implemented for reference. +* It is highly NOT recommanded to use it. +*/ +CV_WRAP virtual Mat performSegmentCpu(InputArray src, bool ifDraw = true) = 0; + +/** @brief: create a hfs object +* @param height: the height of the input image +* @param width: the width of the input image +* @param segEgbThresholdI: parameter segEgbThresholdI +* @param minRegionSizeI: parameter minRegionSizeI +* @param segEgbThresholdII: parameter segEgbThresholdII +* @param minRegionSizeII: parameter minRegionSizeII +* @param spatialWeight: parameter spatialWeight +* @param slicSpixelSize: parameter slicSpixelSize +* @param numSlicIter: parameter numSlicIter +*/ +CV_WRAP static Ptr<HfsSegment> create(int height, int width, + float segEgbThresholdI = 0.08f, int minRegionSizeI = 100, + float segEgbThresholdII = 0.28f, int minRegionSizeII = 200, + float spatialWeight = 0.6f, int slicSpixelSize = 8, int numSlicIter = 5); + +}; + +//! @} + +}} // namespace cv { namespace hfs { diff --git a/include/opencv2/highgui.hpp b/include/opencv2/highgui.hpp new file mode 100644 index 0000000..994a1d1 --- /dev/null +++ b/include/opencv2/highgui.hpp @@ -0,0 +1,845 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HIGHGUI_HPP +#define OPENCV_HIGHGUI_HPP + +#include "opencv2/core.hpp" +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio.hpp" +#endif + +/** +@defgroup highgui High-level GUI + +While OpenCV was designed for use in full-scale applications and can be used within functionally +rich UI frameworks (such as Qt\*, WinForms\*, or Cocoa\*) or without any UI at all, sometimes there +it is required to try functionality quickly and visualize the results. This is what the HighGUI +module has been designed for. + +It provides easy interface to: + +- Create and manipulate windows that can display images and "remember" their content (no need to + handle repaint events from OS). +- Add trackbars to the windows, handle simple mouse events as well as keyboard commands. + +@{ + @defgroup highgui_opengl OpenGL support + @defgroup highgui_qt Qt New Functions + + ![image](pics/qtgui.png) + + This figure explains new functionality implemented with Qt\* GUI. The new GUI provides a statusbar, + a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it. + If you cannot see the control panel, press Ctrl+P or right-click any Qt window and select **Display + properties window**. + + - To attach a trackbar, the window name parameter must be NULL. + + - To attach a buttonbar, a button must be created. If the last bar attached to the control panel + is a buttonbar, the new button is added to the right of the last button. If the last bar + attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is + created. Then, a new button is attached to it. + + See below the example used to generate the figure: + @code + int main(int argc, char *argv[]) + { + + int value = 50; + int value2 = 0; + + + namedWindow("main1",WINDOW_NORMAL); + namedWindow("main2",WINDOW_AUTOSIZE | CV_GUI_NORMAL); + createTrackbar( "track1", "main1", &value, 255, NULL); + + String nameb1 = "button1"; + String nameb2 = "button2"; + + createButton(nameb1,callbackButton,&nameb1,QT_CHECKBOX,1); + createButton(nameb2,callbackButton,NULL,QT_CHECKBOX,0); + createTrackbar( "track2", NULL, &value2, 255, NULL); + createButton("button5",callbackButton1,NULL,QT_RADIOBOX,0); + createButton("button6",callbackButton2,NULL,QT_RADIOBOX,1); + + setMouseCallback( "main2",on_mouse,NULL ); + + Mat img1 = imread("files/flower.jpg"); + VideoCapture video; + video.open("files/hockey.avi"); + + Mat img2,img3; + + while( waitKey(33) != 27 ) + { + img1.convertTo(img2,-1,1,value); + video >> img3; + + imshow("main1",img2); + imshow("main2",img3); + } + + destroyAllWindows(); + + return 0; + } + @endcode + + + @defgroup highgui_winrt WinRT support + + This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control, + and a slider panel. Slider panel holds trackbars attached to it. + + Sliders are attached below the image control. Every new slider is added below the previous one. + + See below the example used to generate the figure: + @code + void sample_app::MainPage::ShowWindow() + { + static cv::String windowName("sample"); + cv::winrt_initContainer(this->cvContainer); + cv::namedWindow(windowName); // not required + + cv::Mat image = cv::imread("Assets/sample.jpg"); + cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4); + cv::cvtColor(image, converted, COLOR_BGR2BGRA); + cv::imshow(windowName, converted); // this will create window if it hasn't been created before + + int state = 42; + cv::TrackbarCallback callback = [](int pos, void* userdata) + { + if (pos == 0) { + cv::destroyWindow(windowName); + } + }; + cv::TrackbarCallback callbackTwin = [](int pos, void* userdata) + { + if (pos >= 70) { + cv::destroyAllWindows(); + } + }; + cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback); + cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin); + } + @endcode + + @defgroup highgui_c C API +@} +*/ + +///////////////////////// graphical user interface ////////////////////////// +namespace cv +{ + +//! @addtogroup highgui +//! @{ + +//! Flags for cv::namedWindow +enum WindowFlags { + WINDOW_NORMAL = 0x00000000, //!< the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size. + WINDOW_AUTOSIZE = 0x00000001, //!< the user cannot resize the window, the size is constrainted by the image displayed. + WINDOW_OPENGL = 0x00001000, //!< window with opengl support. + + WINDOW_FULLSCREEN = 1, //!< change the window to fullscreen. + WINDOW_FREERATIO = 0x00000100, //!< the image expends as much as it can (no ratio constraint). + WINDOW_KEEPRATIO = 0x00000000, //!< the ratio of the image is respected. + WINDOW_GUI_EXPANDED=0x00000000, //!< status bar and tool bar + WINDOW_GUI_NORMAL = 0x00000010, //!< old fashious way + }; + +//! Flags for cv::setWindowProperty / cv::getWindowProperty +enum WindowPropertyFlags { + WND_PROP_FULLSCREEN = 0, //!< fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN). + WND_PROP_AUTOSIZE = 1, //!< autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE). + WND_PROP_ASPECT_RATIO = 2, //!< window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). + WND_PROP_OPENGL = 3, //!< opengl support. + WND_PROP_VISIBLE = 4 //!< checks whether the window exists and is visible + }; + +//! Mouse Events see cv::MouseCallback +enum MouseEventTypes { + EVENT_MOUSEMOVE = 0, //!< indicates that the mouse pointer has moved over the window. + EVENT_LBUTTONDOWN = 1, //!< indicates that the left mouse button is pressed. + EVENT_RBUTTONDOWN = 2, //!< indicates that the right mouse button is pressed. + EVENT_MBUTTONDOWN = 3, //!< indicates that the middle mouse button is pressed. + EVENT_LBUTTONUP = 4, //!< indicates that left mouse button is released. + EVENT_RBUTTONUP = 5, //!< indicates that right mouse button is released. + EVENT_MBUTTONUP = 6, //!< indicates that middle mouse button is released. + EVENT_LBUTTONDBLCLK = 7, //!< indicates that left mouse button is double clicked. + EVENT_RBUTTONDBLCLK = 8, //!< indicates that right mouse button is double clicked. + EVENT_MBUTTONDBLCLK = 9, //!< indicates that middle mouse button is double clicked. + EVENT_MOUSEWHEEL = 10,//!< positive and negative values mean forward and backward scrolling, respectively. + EVENT_MOUSEHWHEEL = 11 //!< positive and negative values mean right and left scrolling, respectively. + }; + +//! Mouse Event Flags see cv::MouseCallback +enum MouseEventFlags { + EVENT_FLAG_LBUTTON = 1, //!< indicates that the left mouse button is down. + EVENT_FLAG_RBUTTON = 2, //!< indicates that the right mouse button is down. + EVENT_FLAG_MBUTTON = 4, //!< indicates that the middle mouse button is down. + EVENT_FLAG_CTRLKEY = 8, //!< indicates that CTRL Key is pressed. + EVENT_FLAG_SHIFTKEY = 16,//!< indicates that SHIFT Key is pressed. + EVENT_FLAG_ALTKEY = 32 //!< indicates that ALT Key is pressed. + }; + +//! Qt font weight +enum QtFontWeights { + QT_FONT_LIGHT = 25, //!< Weight of 25 + QT_FONT_NORMAL = 50, //!< Weight of 50 + QT_FONT_DEMIBOLD = 63, //!< Weight of 63 + QT_FONT_BOLD = 75, //!< Weight of 75 + QT_FONT_BLACK = 87 //!< Weight of 87 + }; + +//! Qt font style +enum QtFontStyles { + QT_STYLE_NORMAL = 0, //!< Normal font. + QT_STYLE_ITALIC = 1, //!< Italic font. + QT_STYLE_OBLIQUE = 2 //!< Oblique font. + }; + +//! Qt "button" type +enum QtButtonTypes { + QT_PUSH_BUTTON = 0, //!< Push button. + QT_CHECKBOX = 1, //!< Checkbox button. + QT_RADIOBOX = 2, //!< Radiobox button. + QT_NEW_BUTTONBAR = 1024 //!< Button should create a new buttonbar + }; + +/** @brief Callback function for mouse events. see cv::setMouseCallback +@param event one of the cv::MouseEventTypes constants. +@param x The x-coordinate of the mouse event. +@param y The y-coordinate of the mouse event. +@param flags one of the cv::MouseEventFlags constants. +@param userdata The optional parameter. + */ +typedef void (*MouseCallback)(int event, int x, int y, int flags, void* userdata); + +/** @brief Callback function for Trackbar see cv::createTrackbar +@param pos current position of the specified trackbar. +@param userdata The optional parameter. + */ +typedef void (*TrackbarCallback)(int pos, void* userdata); + +/** @brief Callback function defined to be called every frame. See cv::setOpenGlDrawCallback +@param userdata The optional parameter. + */ +typedef void (*OpenGlDrawCallback)(void* userdata); + +/** @brief Callback function for a button created by cv::createButton +@param state current state of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. +@param userdata The optional parameter. + */ +typedef void (*ButtonCallback)(int state, void* userdata); + +/** @brief Creates a window. + +The function namedWindow creates a window that can be used as a placeholder for images and +trackbars. Created windows are referred to by their names. + +If a window with the same name already exists, the function does nothing. + +You can call cv::destroyWindow or cv::destroyAllWindows to close the window and de-allocate any associated +memory usage. For a simple program, you do not really have to call these functions because all the +resources and windows of the application are closed automatically by the operating system upon exit. + +@note + +Qt backend supports additional flags: + - **WINDOW_NORMAL or WINDOW_AUTOSIZE:** WINDOW_NORMAL enables you to resize the + window, whereas WINDOW_AUTOSIZE adjusts automatically the window size to fit the + displayed image (see imshow ), and you cannot change the window size manually. + - **WINDOW_FREERATIO or WINDOW_KEEPRATIO:** WINDOW_FREERATIO adjusts the image + with no respect to its ratio, whereas WINDOW_KEEPRATIO keeps the image ratio. + - **WINDOW_GUI_NORMAL or WINDOW_GUI_EXPANDED:** WINDOW_GUI_NORMAL is the old way to draw the window + without statusbar and toolbar, whereas WINDOW_GUI_EXPANDED is a new enhanced GUI. +By default, flags == WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | WINDOW_GUI_EXPANDED + +@param winname Name of the window in the window caption that may be used as a window identifier. +@param flags Flags of the window. The supported flags are: (cv::WindowFlags) + */ +CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE); + +/** @brief Destroys the specified window. + +The function destroyWindow destroys the window with the given name. + +@param winname Name of the window to be destroyed. + */ +CV_EXPORTS_W void destroyWindow(const String& winname); + +/** @brief Destroys all of the HighGUI windows. + +The function destroyAllWindows destroys all of the opened HighGUI windows. + */ +CV_EXPORTS_W void destroyAllWindows(); + +CV_EXPORTS_W int startWindowThread(); + +/** @brief Similar to #waitKey, but returns full key code. + +@note + +Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc + +*/ +CV_EXPORTS_W int waitKeyEx(int delay = 0); + +/** @brief Waits for a pressed key. + +The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay +milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the +function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is +running on your computer at that time. It returns the code of the pressed key or -1 if no key was +pressed before the specified time had elapsed. + +@note + +This function is the only method in HighGUI that can fetch and handle events, so it needs to be +called periodically for normal event processing unless HighGUI is used within an environment that +takes care of event processing. + +@note + +The function only works if there is at least one HighGUI window created and the window is active. +If there are several HighGUI windows, any of them can be active. + +@param delay Delay in milliseconds. 0 is the special value that means "forever". + */ +CV_EXPORTS_W int waitKey(int delay = 0); + +/** @brief Displays an image in the specified window. + +The function imshow displays an image in the specified window. If the window was created with the +cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution. +Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth: + +- If the image is 8-bit unsigned, it is displayed as is. +- If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the + value range [0,255\*256] is mapped to [0,255]. +- If the image is 32-bit or 64-bit floating-point, the pixel values are multiplied by 255. That is, the + value range [0,1] is mapped to [0,255]. + +If window was created with OpenGL support, cv::imshow also support ogl::Buffer , ogl::Texture2D and +cuda::GpuMat as input. + +If the window was not created before this function, it is assumed creating a window with cv::WINDOW_AUTOSIZE. + +If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow. + +@note This function should be followed by cv::waitKey function which displays the image for specified +milliseconds. Otherwise, it won't display the image. For example, **waitKey(0)** will display the window +infinitely until any keypress (it is suitable for image display). **waitKey(25)** will display a frame +for 25 ms, after which display will be automatically closed. (If you put it in a loop to read +videos, it will display the video frame-by-frame) + +@note + +[__Windows Backend Only__] Pressing Ctrl+C will copy the image to the clipboard. + +[__Windows Backend Only__] Pressing Ctrl+S will show a dialog to save the image. + +@param winname Name of the window. +@param mat Image to be shown. + */ +CV_EXPORTS_W void imshow(const String& winname, InputArray mat); + +/** @brief Resizes window to the specified size + +@note + +- The specified window size is for the image area. Toolbars are not counted. +- Only windows created without cv::WINDOW_AUTOSIZE flag can be resized. + +@param winname Window name. +@param width The new window width. +@param height The new window height. + */ +CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height); + +/** @overload +@param winname Window name. +@param size The new window size. +*/ +CV_EXPORTS_W void resizeWindow(const String& winname, const cv::Size& size); + +/** @brief Moves window to the specified position + +@param winname Name of the window. +@param x The new x-coordinate of the window. +@param y The new y-coordinate of the window. + */ +CV_EXPORTS_W void moveWindow(const String& winname, int x, int y); + +/** @brief Changes parameters of a window dynamically. + +The function setWindowProperty enables changing properties of a window. + +@param winname Name of the window. +@param prop_id Window property to edit. The supported operation flags are: (cv::WindowPropertyFlags) +@param prop_value New value of the window property. The supported flags are: (cv::WindowFlags) + */ +CV_EXPORTS_W void setWindowProperty(const String& winname, int prop_id, double prop_value); + +/** @brief Updates window title +@param winname Name of the window. +@param title New title. +*/ +CV_EXPORTS_W void setWindowTitle(const String& winname, const String& title); + +/** @brief Provides parameters of a window. + +The function getWindowProperty returns properties of a window. + +@param winname Name of the window. +@param prop_id Window property to retrieve. The following operation flags are available: (cv::WindowPropertyFlags) + +@sa setWindowProperty + */ +CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id); + +/** @brief Provides rectangle of image in the window. + +The function getWindowImageRect returns the client screen coordinates, width and height of the image rendering area. + +@param winname Name of the window. + +@sa resizeWindow moveWindow + */ +CV_EXPORTS_W Rect getWindowImageRect(const String& winname); + +/** @example samples/cpp/create_mask.cpp +This program demonstrates using mouse events and how to make and use a mask image (black and white) . +*/ +/** @brief Sets mouse handler for the specified window + +@param winname Name of the window. +@param onMouse Callback function for mouse events. See OpenCV samples on how to specify and use the callback. +@param userdata The optional parameter passed to the callback. + */ +CV_EXPORTS void setMouseCallback(const String& winname, MouseCallback onMouse, void* userdata = 0); + +/** @brief Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and +cv::EVENT_MOUSEHWHEEL. + +For regular mice with a scroll-wheel, delta will be a multiple of 120. The value 120 corresponds to +a one notch rotation of the wheel or the threshold for action to be taken and one such action should +occur for each delta. Some high-precision mice with higher-resolution freely-rotating wheels may +generate smaller values. + +For cv::EVENT_MOUSEWHEEL positive and negative values mean forward and backward scrolling, +respectively. For cv::EVENT_MOUSEHWHEEL, where available, positive and negative values mean right and +left scrolling, respectively. + +With the C API, the macro CV_GET_WHEEL_DELTA(flags) can be used alternatively. + +@note + +Mouse-wheel events are currently supported only on Windows. + +@param flags The mouse callback flags parameter. + */ +CV_EXPORTS int getMouseWheelDelta(int flags); + +/** @brief Selects ROI on the given image. +Function creates a window and allows user to select a ROI using mouse. +Controls: use `space` or `enter` to finish selection, use key `c` to cancel selection (function will return the zero cv::Rect). + +@param windowName name of the window where selection process will be shown. +@param img image to select a ROI. +@param showCrosshair if true crosshair of selection rectangle will be shown. +@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of +selection rectangle will correspont to the initial mouse position. +@return selected ROI or empty rect if selection canceled. + +@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). +After finish of work an empty callback will be set for the used window. + */ +CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false); + +/** @overload + */ +CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false); + +/** @brief Selects ROIs on the given image. +Function creates a window and allows user to select a ROIs using mouse. +Controls: use `space` or `enter` to finish current selection and start a new one, +use `esc` to terminate multiple ROI selection process. + +@param windowName name of the window where selection process will be shown. +@param img image to select a ROI. +@param boundingBoxes selected ROIs. +@param showCrosshair if true crosshair of selection rectangle will be shown. +@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of +selection rectangle will correspont to the initial mouse position. + +@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). +After finish of work an empty callback will be set for the used window. + */ +CV_EXPORTS_W void selectROIs(const String& windowName, InputArray img, + CV_OUT std::vector<Rect>& boundingBoxes, bool showCrosshair = true, bool fromCenter = false); + +/** @brief Creates a trackbar and attaches it to the specified window. + +The function createTrackbar creates a trackbar (a slider or range control) with the specified name +and range, assigns a variable value to be a position synchronized with the trackbar and specifies +the callback function onChange to be called on the trackbar position change. The created trackbar is +displayed in the specified window winname. + +@note + +[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar should be attached to the +control panel. + +Clicking the label of each trackbar enables editing the trackbar values manually. + +@param trackbarname Name of the created trackbar. +@param winname Name of the window that will be used as a parent of the created trackbar. +@param value Optional pointer to an integer variable whose value reflects the position of the +slider. Upon creation, the slider position is defined by this variable. +@param count Maximal position of the slider. The minimal position is always 0. +@param onChange Pointer to the function to be called every time the slider changes position. This +function should be prototyped as void Foo(int,void\*); , where the first parameter is the trackbar +position and the second parameter is the user data (see the next parameter). If the callback is +the NULL pointer, no callbacks are called, but only value is updated. +@param userdata User data that is passed as is to the callback. It can be used to handle trackbar +events without using global variables. + */ +CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname, + int* value, int count, + TrackbarCallback onChange = 0, + void* userdata = 0); + +/** @brief Returns the trackbar position. + +The function returns the current position of the specified trackbar. + +@note + +[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of the trackbar. + */ +CV_EXPORTS_W int getTrackbarPos(const String& trackbarname, const String& winname); + +/** @brief Sets the trackbar position. + +The function sets the position of the specified trackbar in the specified window. + +@note + +[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of trackbar. +@param pos New position. + */ +CV_EXPORTS_W void setTrackbarPos(const String& trackbarname, const String& winname, int pos); + +/** @brief Sets the trackbar maximum position. + +The function sets the maximum position of the specified trackbar in the specified window. + +@note + +[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of trackbar. +@param maxval New maximum position. + */ +CV_EXPORTS_W void setTrackbarMax(const String& trackbarname, const String& winname, int maxval); + +/** @brief Sets the trackbar minimum position. + +The function sets the minimum position of the specified trackbar in the specified window. + +@note + +[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of trackbar. +@param minval New minimum position. + */ +CV_EXPORTS_W void setTrackbarMin(const String& trackbarname, const String& winname, int minval); + +//! @addtogroup highgui_opengl OpenGL support +//! @{ + +/** @brief Displays OpenGL 2D texture in the specified window. + +@param winname Name of the window. +@param tex OpenGL 2D texture data. + */ +CV_EXPORTS void imshow(const String& winname, const ogl::Texture2D& tex); + +/** @brief Sets a callback function to be called to draw on top of displayed image. + +The function setOpenGlDrawCallback can be used to draw 3D data on the window. See the example of +callback function below: +@code + void on_opengl(void* param) + { + glLoadIdentity(); + + glTranslated(0.0, 0.0, -1.0); + + glRotatef( 55, 1, 0, 0 ); + glRotatef( 45, 0, 1, 0 ); + glRotatef( 0, 0, 0, 1 ); + + static const int coords[6][4][3] = { + { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, + { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, + { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, + { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, + { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, + { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } + }; + + for (int i = 0; i < 6; ++i) { + glColor3ub( i*20, 100+i*10, i*42 ); + glBegin(GL_QUADS); + for (int j = 0; j < 4; ++j) { + glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]); + } + glEnd(); + } + } +@endcode + +@param winname Name of the window. +@param onOpenGlDraw Pointer to the function to be called every frame. This function should be +prototyped as void Foo(void\*) . +@param userdata Pointer passed to the callback function.(__Optional__) + */ +CV_EXPORTS void setOpenGlDrawCallback(const String& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0); + +/** @brief Sets the specified window as current OpenGL context. + +@param winname Name of the window. + */ +CV_EXPORTS void setOpenGlContext(const String& winname); + +/** @brief Force window to redraw its context and call draw callback ( See cv::setOpenGlDrawCallback ). + +@param winname Name of the window. + */ +CV_EXPORTS void updateWindow(const String& winname); + +//! @} highgui_opengl + +//! @addtogroup highgui_qt +//! @{ + +/** @brief QtFont available only for Qt. See cv::fontQt + */ +struct QtFont +{ + const char* nameFont; //!< Name of the font + Scalar color; //!< Color of the font. Scalar(blue_component, green_component, red_component[, alpha_component]) + int font_face; //!< See cv::QtFontStyles + const int* ascii; //!< font data and metrics + const int* greek; + const int* cyrillic; + float hscale, vscale; + float shear; //!< slope coefficient: 0 - normal, >0 - italic + int thickness; //!< See cv::QtFontWeights + float dx; //!< horizontal interval between letters + int line_type; //!< PointSize +}; + +/** @brief Creates the font to draw a text on an image. + +The function fontQt creates a cv::QtFont object. This cv::QtFont is not compatible with putText . + +A basic usage of this function is the following: : +@code + QtFont font = fontQt("Times"); + addText( img1, "Hello World !", Point(50,50), font); +@endcode + +@param nameFont Name of the font. The name should match the name of a system font (such as +*Times*). If the font is not found, a default one is used. +@param pointSize Size of the font. If not specified, equal zero or negative, the point size of the +font is set to a system-dependent default value. Generally, this is 12 points. +@param color Color of the font in BGRA where A = 255 is fully transparent. Use the macro CV_RGB +for simplicity. +@param weight Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control. +@param style Font style. Available operation flags are : cv::QtFontStyles +@param spacing Spacing between characters. It can be negative or positive. + */ +CV_EXPORTS QtFont fontQt(const String& nameFont, int pointSize = -1, + Scalar color = Scalar::all(0), int weight = QT_FONT_NORMAL, + int style = QT_STYLE_NORMAL, int spacing = 0); + +/** @brief Draws a text on the image. + +The function addText draws *text* on the image *img* using a specific font *font* (see example cv::fontQt +) + +@param img 8-bit 3-channel image where the text should be drawn. +@param text Text to write on an image. +@param org Point(x,y) where the text should start on an image. +@param font Font to use to draw a text. + */ +CV_EXPORTS void addText( const Mat& img, const String& text, Point org, const QtFont& font); + +/** @brief Draws a text on the image. + +@param img 8-bit 3-channel image where the text should be drawn. +@param text Text to write on an image. +@param org Point(x,y) where the text should start on an image. +@param nameFont Name of the font. The name should match the name of a system font (such as +*Times*). If the font is not found, a default one is used. +@param pointSize Size of the font. If not specified, equal zero or negative, the point size of the +font is set to a system-dependent default value. Generally, this is 12 points. +@param color Color of the font in BGRA where A = 255 is fully transparent. +@param weight Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control. +@param style Font style. Available operation flags are : cv::QtFontStyles +@param spacing Spacing between characters. It can be negative or positive. + */ +CV_EXPORTS_W void addText(const Mat& img, const String& text, Point org, const String& nameFont, int pointSize = -1, Scalar color = Scalar::all(0), + int weight = QT_FONT_NORMAL, int style = QT_STYLE_NORMAL, int spacing = 0); + +/** @brief Displays a text on a window image as an overlay for a specified duration. + +The function displayOverlay displays useful information/tips on top of the window for a certain +amount of time *delayms*. The function does not modify the image, displayed in the window, that is, +after the specified delay the original content of the window is restored. + +@param winname Name of the window. +@param text Overlay text to write on a window image. +@param delayms The period (in milliseconds), during which the overlay text is displayed. If this +function is called before the previous overlay text timed out, the timer is restarted and the text +is updated. If this value is zero, the text never disappears. + */ +CV_EXPORTS_W void displayOverlay(const String& winname, const String& text, int delayms = 0); + +/** @brief Displays a text on the window statusbar during the specified period of time. + +The function displayStatusBar displays useful information/tips on top of the window for a certain +amount of time *delayms* . This information is displayed on the window statusbar (the window must be +created with the CV_GUI_EXPANDED flags). + +@param winname Name of the window. +@param text Text to write on the window statusbar. +@param delayms Duration (in milliseconds) to display the text. If this function is called before +the previous text timed out, the timer is restarted and the text is updated. If this value is +zero, the text never disappears. + */ +CV_EXPORTS_W void displayStatusBar(const String& winname, const String& text, int delayms = 0); + +/** @brief Saves parameters of the specified window. + +The function saveWindowParameters saves size, location, flags, trackbars value, zoom and panning +location of the window windowName. + +@param windowName Name of the window. + */ +CV_EXPORTS void saveWindowParameters(const String& windowName); + +/** @brief Loads parameters of the specified window. + +The function loadWindowParameters loads size, location, flags, trackbars value, zoom and panning +location of the window windowName. + +@param windowName Name of the window. + */ +CV_EXPORTS void loadWindowParameters(const String& windowName); + +CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); + +CV_EXPORTS void stopLoop(); + +/** @brief Attaches a button to the control panel. + +The function createButton attaches a button to the control panel. Each button is added to a +buttonbar to the right of the last button. A new buttonbar is created if nothing was attached to the +control panel before, or if the last element attached to the control panel was a trackbar or if the +QT_NEW_BUTTONBAR flag is added to the type. + +See below various examples of the cv::createButton function call: : +@code + createButton(NULL,callbackButton);//create a push button "button 0", that will call callbackButton. + createButton("button2",callbackButton,NULL,QT_CHECKBOX,0); + createButton("button3",callbackButton,&value); + createButton("button5",callbackButton1,NULL,QT_RADIOBOX); + createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON,1); + createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON|QT_NEW_BUTTONBAR);// create a push button in a new row +@endcode + +@param bar_name Name of the button. +@param on_change Pointer to the function to be called every time the button changes its state. +This function should be prototyped as void Foo(int state,\*void); . *state* is the current state +of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. +@param userdata Pointer passed to the callback function. +@param type Optional type of the button. Available types are: (cv::QtButtonTypes) +@param initial_button_state Default state of the button. Use for checkbox and radiobox. Its +value could be 0 or 1. (__Optional__) +*/ +CV_EXPORTS int createButton( const String& bar_name, ButtonCallback on_change, + void* userdata = 0, int type = QT_PUSH_BUTTON, + bool initial_button_state = false); + +//! @} highgui_qt + +//! @} highgui + +} // cv + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/highgui/highgui_c.h" +#endif + +#endif diff --git a/include/opencv2/highgui/highgui.hpp b/include/opencv2/highgui/highgui.hpp new file mode 100644 index 0000000..160c9cf --- /dev/null +++ b/include/opencv2/highgui/highgui.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/highgui.hpp" diff --git a/include/opencv2/highgui/highgui_c.h b/include/opencv2/highgui/highgui_c.h new file mode 100644 index 0000000..3541313 --- /dev/null +++ b/include/opencv2/highgui/highgui_c.h @@ -0,0 +1,262 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HIGHGUI_H +#define OPENCV_HIGHGUI_H + +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs/imgcodecs_c.h" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio/videoio_c.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** @addtogroup highgui_c + @{ + */ + +/****************************************************************************************\ +* Basic GUI functions * +\****************************************************************************************/ +//YV +//-----------New for Qt +/* For font */ +enum { CV_FONT_LIGHT = 25,//QFont::Light, + CV_FONT_NORMAL = 50,//QFont::Normal, + CV_FONT_DEMIBOLD = 63,//QFont::DemiBold, + CV_FONT_BOLD = 75,//QFont::Bold, + CV_FONT_BLACK = 87 //QFont::Black +}; + +enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal, + CV_STYLE_ITALIC = 1,//QFont::StyleItalic, + CV_STYLE_OBLIQUE = 2 //QFont::StyleOblique +}; +/* ---------*/ + +//for color cvScalar(blue_component, green_component, red_component[, alpha_component]) +//and alpha= 0 <-> 0xFF (not transparent <-> transparent) +CVAPI(CvFont) cvFontQt(const char* nameFont, int pointSize CV_DEFAULT(-1), CvScalar color CV_DEFAULT(cvScalarAll(0)), int weight CV_DEFAULT(CV_FONT_NORMAL), int style CV_DEFAULT(CV_STYLE_NORMAL), int spacing CV_DEFAULT(0)); + +CVAPI(void) cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont *arg2); + +CVAPI(void) cvDisplayOverlay(const char* name, const char* text, int delayms CV_DEFAULT(0)); +CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms CV_DEFAULT(0)); + +CVAPI(void) cvSaveWindowParameters(const char* name); +CVAPI(void) cvLoadWindowParameters(const char* name); +CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); +CVAPI(void) cvStopLoop( void ); + +typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata); +enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1, CV_RADIOBOX = 2}; +CVAPI(int) cvCreateButton( const char* button_name CV_DEFAULT(NULL),CvButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL) , int button_type CV_DEFAULT(CV_PUSH_BUTTON), int initial_button_state CV_DEFAULT(0)); +//---------------------- + + +/* this function is used to set some external parameters in case of X Window */ +CVAPI(int) cvInitSystem( int argc, char** argv ); + +CVAPI(int) cvStartWindowThread( void ); + +// --------- YV --------- +enum +{ + //These 3 flags are used by cvSet/GetWindowProperty + CV_WND_PROP_FULLSCREEN = 0, //to change/get window's fullscreen property + CV_WND_PROP_AUTOSIZE = 1, //to change/get window's autosize property + CV_WND_PROP_ASPECTRATIO= 2, //to change/get window's aspectratio property + CV_WND_PROP_OPENGL = 3, //to change/get window's opengl support + CV_WND_PROP_VISIBLE = 4, + + //These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty + CV_WINDOW_NORMAL = 0x00000000, //the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size + CV_WINDOW_AUTOSIZE = 0x00000001, //the user cannot resize the window, the size is constrainted by the image displayed + CV_WINDOW_OPENGL = 0x00001000, //window with opengl support + + //Those flags are only for Qt + CV_GUI_EXPANDED = 0x00000000, //status bar and tool bar + CV_GUI_NORMAL = 0x00000010, //old fashious way + + //These 3 flags are used by cvNamedWindow and cvSet/GetWindowProperty + CV_WINDOW_FULLSCREEN = 1,//change the window to fullscreen + CV_WINDOW_FREERATIO = 0x00000100,//the image expends as much as it can (no ratio constraint) + CV_WINDOW_KEEPRATIO = 0x00000000//the ration image is respected. +}; + +/* create window */ +CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) ); + +/* Set and Get Property of the window */ +CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value); +CVAPI(double) cvGetWindowProperty(const char* name, int prop_id); + +#ifdef __cplusplus // FIXIT remove in OpenCV 4.0 +/* Get window image rectangle coordinates, width and height */ +CVAPI(cv::Rect)cvGetWindowImageRect(const char* name); +#endif + +/* display image within window (highgui windows remember their content) */ +CVAPI(void) cvShowImage( const char* name, const CvArr* image ); + +/* resize/move window */ +CVAPI(void) cvResizeWindow( const char* name, int width, int height ); +CVAPI(void) cvMoveWindow( const char* name, int x, int y ); + + +/* destroy window and all the trackers associated with it */ +CVAPI(void) cvDestroyWindow( const char* name ); + +CVAPI(void) cvDestroyAllWindows(void); + +/* get native window handle (HWND in case of Win32 and Widget in case of X Window) */ +CVAPI(void*) cvGetWindowHandle( const char* name ); + +/* get name of highgui window given its native handle */ +CVAPI(const char*) cvGetWindowName( void* window_handle ); + + +typedef void (CV_CDECL *CvTrackbarCallback)(int pos); + +/* create trackbar and display it on top of given window, set callback */ +CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name, + int* value, int count, CvTrackbarCallback on_change CV_DEFAULT(NULL)); + +typedef void (CV_CDECL *CvTrackbarCallback2)(int pos, void* userdata); + +CVAPI(int) cvCreateTrackbar2( const char* trackbar_name, const char* window_name, + int* value, int count, CvTrackbarCallback2 on_change, + void* userdata CV_DEFAULT(0)); + +/* retrieve or set trackbar position */ +CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name ); +CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos ); +CVAPI(void) cvSetTrackbarMax(const char* trackbar_name, const char* window_name, int maxval); +CVAPI(void) cvSetTrackbarMin(const char* trackbar_name, const char* window_name, int minval); + +enum +{ + CV_EVENT_MOUSEMOVE =0, + CV_EVENT_LBUTTONDOWN =1, + CV_EVENT_RBUTTONDOWN =2, + CV_EVENT_MBUTTONDOWN =3, + CV_EVENT_LBUTTONUP =4, + CV_EVENT_RBUTTONUP =5, + CV_EVENT_MBUTTONUP =6, + CV_EVENT_LBUTTONDBLCLK =7, + CV_EVENT_RBUTTONDBLCLK =8, + CV_EVENT_MBUTTONDBLCLK =9, + CV_EVENT_MOUSEWHEEL =10, + CV_EVENT_MOUSEHWHEEL =11 +}; + +enum +{ + CV_EVENT_FLAG_LBUTTON =1, + CV_EVENT_FLAG_RBUTTON =2, + CV_EVENT_FLAG_MBUTTON =4, + CV_EVENT_FLAG_CTRLKEY =8, + CV_EVENT_FLAG_SHIFTKEY =16, + CV_EVENT_FLAG_ALTKEY =32 +}; + + +#define CV_GET_WHEEL_DELTA(flags) ((short)((flags >> 16) & 0xffff)) // upper 16 bits + +typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param); + +/* assign callback for mouse events */ +CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse, + void* param CV_DEFAULT(NULL)); + +/* wait for key event infinitely (delay<=0) or for "delay" milliseconds */ +CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0)); + +// OpenGL support + +typedef void (CV_CDECL *CvOpenGlDrawCallback)(void* userdata); +CVAPI(void) cvSetOpenGlDrawCallback(const char* window_name, CvOpenGlDrawCallback callback, void* userdata CV_DEFAULT(NULL)); + +CVAPI(void) cvSetOpenGlContext(const char* window_name); +CVAPI(void) cvUpdateWindow(const char* window_name); + + +/****************************************************************************************\ + +* Obsolete functions/synonyms * +\****************************************************************************************/ + +#define cvAddSearchPath(path) +#define cvvInitSystem cvInitSystem +#define cvvNamedWindow cvNamedWindow +#define cvvShowImage cvShowImage +#define cvvResizeWindow cvResizeWindow +#define cvvDestroyWindow cvDestroyWindow +#define cvvCreateTrackbar cvCreateTrackbar +#define cvvAddSearchPath cvAddSearchPath +#define cvvWaitKey(name) cvWaitKey(0) +#define cvvWaitKeyEx(name,delay) cvWaitKey(delay) +#define HG_AUTOSIZE CV_WINDOW_AUTOSIZE +#define set_preprocess_func cvSetPreprocessFuncWin32 +#define set_postprocess_func cvSetPostprocessFuncWin32 + +#if defined _WIN32 + +CVAPI(void) cvSetPreprocessFuncWin32_(const void* callback); +CVAPI(void) cvSetPostprocessFuncWin32_(const void* callback); +#define cvSetPreprocessFuncWin32(callback) cvSetPreprocessFuncWin32_((const void*)(callback)) +#define cvSetPostprocessFuncWin32(callback) cvSetPostprocessFuncWin32_((const void*)(callback)) + +#endif + +/** @} highgui_c */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/opencv2/img_hash.hpp b/include/opencv2/img_hash.hpp new file mode 100644 index 0000000..5e7a928 --- /dev/null +++ b/include/opencv2/img_hash.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMG_HASH_H +#define OPENCV_IMG_HASH_H + +#include "opencv2/img_hash/average_hash.hpp" +#include "opencv2/img_hash/block_mean_hash.hpp" +#include "opencv2/img_hash/color_moment_hash.hpp" +#include "opencv2/img_hash/marr_hildreth_hash.hpp" +#include "opencv2/img_hash/phash.hpp" +#include "opencv2/img_hash/radial_variance_hash.hpp" + +/** +@defgroup img_hash The module brings implementations of different image hashing algorithms. + +Provide algorithms to extract the hash of images and fast way to figure out most similar images in +huge data set. + +Namespace for all functions is cv::img_hash. + +### Supported Algorithms + +- Average hash (also called Different hash) +- PHash (also called Perceptual hash) +- Marr Hildreth Hash +- Radial Variance Hash +- Block Mean Hash (modes 0 and 1) +- Color Moment Hash (this is the one and only hash algorithm resist to rotation attack(-90~90 degree)) + +You can study more about image hashing from following paper and websites: + +- "Implementation and benchmarking of perceptual image hash functions" @cite zauner2010implementation +- "Looks Like It" @cite lookslikeit + +### Code Example + +@include samples/hash_samples.cpp + +### Performance under different attacks + +![Performance chart](img_hash/doc/attack_performance.JPG) + +### Speed comparison with PHash library (100 images from ukbench) + +![Hash Computation chart](img_hash/doc/hash_computation_chart.JPG) +![Hash comparison chart](img_hash/doc/hash_comparison_chart.JPG) + +As you can see, hash computation speed of img_hash module outperform [PHash library](http://www.phash.org/) a lot. + +PS : I do not list out the comparison of Average hash, PHash and Color Moment hash, because I cannot +find them in PHash. + +### Motivation + +Collects useful image hash algorithms into opencv, so we do not need to rewrite them by ourselves +again and again or rely on another 3rd party library(ex : PHash library). BOVW or correlation +matching are good and robust, but they are very slow compare with image hash, if you need to deal +with large scale CBIR(content based image retrieval) problem, image hash is a more reasonable +solution. + +### More info + +You can learn more about img_hash modules from following links, these links show you how to find +similar image from ukbench dataset, provide thorough benchmark of different attacks(contrast, blur, +noise(gaussion,pepper and salt), jpeg compression, watermark, resize). + +* [Introduction to image hash module of opencv](http://qtandopencv.blogspot.my/2016/06/introduction-to-image-hash-module-of.html) +* [Speed up image hashing of opencv(img_hash) and introduce color moment hash](http://qtandopencv.blogspot.my/2016/06/speed-up-image-hashing-of-opencvimghash.html) + +### Contributors + +Tham Ngap Wei, thamngapwei@gmail.com + +*/ + +#endif // OPENCV_IMG_HASH_H diff --git a/include/opencv2/img_hash/average_hash.hpp b/include/opencv2/img_hash/average_hash.hpp new file mode 100644 index 0000000..1204441 --- /dev/null +++ b/include/opencv2/img_hash/average_hash.hpp @@ -0,0 +1,39 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_AVERAGE_HASH_HPP +#define OPENCV_AVERAGE_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief Computes average hash value of the input image + +This is a fast image hashing algorithm, but only work on simple case. For more details, please +refer to @cite lookslikeit +*/ +class CV_EXPORTS_W AverageHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr<AverageHash> create(); +protected: + AverageHash() {} +}; + +/** @brief Calculates img_hash::AverageHash in one call +@param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. +@param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U +*/ +CV_EXPORTS_W void averageHash(cv::InputArray inputArr, cv::OutputArray outputArr); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_AVERAGE_HASH_HPP diff --git a/include/opencv2/img_hash/block_mean_hash.hpp b/include/opencv2/img_hash/block_mean_hash.hpp new file mode 100644 index 0000000..65d0a03 --- /dev/null +++ b/include/opencv2/img_hash/block_mean_hash.hpp @@ -0,0 +1,52 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_BLOCK_MEAN_HASH_HPP +#define OPENCV_BLOCK_MEAN_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +enum BlockMeanHashMode +{ + BLOCK_MEAN_HASH_MODE_0 = 0, //!< use fewer block and generate 16*16/8 uchar hash value + BLOCK_MEAN_HASH_MODE_1 = 1, //!< use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value +}; + +/** @brief Image hash based on block mean. + +See @cite zauner2010implementation for details. +*/ +class CV_EXPORTS_W BlockMeanHash : public ImgHashBase +{ +public: + /** @brief Create BlockMeanHash object + @param mode + */ + CV_WRAP void setMode(int mode); + CV_WRAP std::vector<double> getMean() const; + CV_WRAP static Ptr<BlockMeanHash> create(int mode = BLOCK_MEAN_HASH_MODE_0); +protected: + BlockMeanHash() {} +}; + +/** @brief Computes block mean hash of the input image + @param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. + @param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U + @param mode +*/ +CV_EXPORTS_W void blockMeanHash(cv::InputArray inputArr, + cv::OutputArray outputArr, + int mode = BLOCK_MEAN_HASH_MODE_0); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_BLOCK_MEAN_HASH_HPP diff --git a/include/opencv2/img_hash/color_moment_hash.hpp b/include/opencv2/img_hash/color_moment_hash.hpp new file mode 100644 index 0000000..d0a820b --- /dev/null +++ b/include/opencv2/img_hash/color_moment_hash.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_COLOR_MOMENT_HASH_HPP +#define OPENCV_COLOR_MOMENT_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief Image hash based on color moments. + +See @cite tang2012perceptual for details. +*/ +class CV_EXPORTS_W ColorMomentHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr<ColorMomentHash> create(); +protected: + ColorMomentHash() {} +}; + +/** @brief Computes color moment hash of the input, the algorithm + is come from the paper "Perceptual Hashing for Color Images + Using Invariant Moments" + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3 or CV_8UC1. + @param outputArr 42 hash values with type CV_64F(double) + */ +CV_EXPORTS_W void colorMomentHash(cv::InputArray inputArr, cv::OutputArray outputArr); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_COLOR_MOMENT_HASH_HPP diff --git a/include/opencv2/img_hash/img_hash_base.hpp b/include/opencv2/img_hash/img_hash_base.hpp new file mode 100644 index 0000000..f0cc451 --- /dev/null +++ b/include/opencv2/img_hash/img_hash_base.hpp @@ -0,0 +1,46 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMG_HASH_BASE_HPP +#define OPENCV_IMG_HASH_BASE_HPP + +#include "opencv2/core.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief The base class for image hash algorithms + */ +class CV_EXPORTS_W ImgHashBase : public Algorithm +{ +public: + class ImgHashImpl; + + ~ImgHashBase(); + /** @brief Computes hash of the input image + @param inputArr input image want to compute hash value + @param outputArr hash of the image + */ + CV_WRAP void compute(cv::InputArray inputArr, cv::OutputArray outputArr); + /** @brief Compare the hash value between inOne and inTwo + @param hashOne Hash value one + @param hashTwo Hash value two + @return value indicate similarity between inOne and inTwo, the meaning + of the value vary from algorithms to algorithms + */ + CV_WRAP double compare(cv::InputArray hashOne, cv::InputArray hashTwo) const; +protected: + ImgHashBase(); +protected: + Ptr<ImgHashImpl> pImpl; +}; + +//! @} + +} } // cv::img_hash:: + +#endif // OPENCV_IMG_HASH_BASE_HPP diff --git a/include/opencv2/img_hash/marr_hildreth_hash.hpp b/include/opencv2/img_hash/marr_hildreth_hash.hpp new file mode 100644 index 0000000..a9b04f9 --- /dev/null +++ b/include/opencv2/img_hash/marr_hildreth_hash.hpp @@ -0,0 +1,64 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_MARR_HILDRETH_HASH_HPP +#define OPENCV_MARR_HILDRETH_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief Marr-Hildreth Operator Based Hash, slowest but more discriminative. + +See @cite zauner2010implementation for details. +*/ +class CV_EXPORTS_W MarrHildrethHash : public ImgHashBase +{ +public: + /** + * @brief self explain + */ + CV_WRAP float getAlpha() const; + + /** + * @brief self explain + */ + CV_WRAP float getScale() const; + + /** @brief Set Mh kernel parameters + @param alpha int scale factor for marr wavelet (default=2). + @param scale int level of scale factor (default = 1) + */ + CV_WRAP void setKernelParam(float alpha, float scale); + + /** + @param alpha int scale factor for marr wavelet (default=2). + @param scale int level of scale factor (default = 1) + */ + CV_WRAP static Ptr<MarrHildrethHash> create(float alpha = 2.0f, float scale = 1.0f); +protected: + MarrHildrethHash() {} +}; + +/** @brief Computes average hash value of the input image + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3, CV_8UC1. + @param outputArr Hash value of input, it will contain 16 hex + decimal number, return type is CV_8U + @param alpha int scale factor for marr wavelet (default=2). + @param scale int level of scale factor (default = 1) +*/ +CV_EXPORTS_W void marrHildrethHash(cv::InputArray inputArr, + cv::OutputArray outputArr, + float alpha = 2.0f, float scale = 1.0f); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_MARR_HILDRETH_HASH_HPP diff --git a/include/opencv2/img_hash/phash.hpp b/include/opencv2/img_hash/phash.hpp new file mode 100644 index 0000000..d57cd6f --- /dev/null +++ b/include/opencv2/img_hash/phash.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_PHASH_HPP +#define OPENCV_PHASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief pHash + +Slower than average_hash, but tolerant of minor modifications + +This algorithm can combat more variation than averageHash, for more details please refer to @cite lookslikeit +*/ +class CV_EXPORTS_W PHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr<PHash> create(); +protected: + PHash() {} +}; + +/** @brief Computes pHash value of the input image + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3, CV_8UC1. + @param outputArr Hash value of input, it will contain 8 uchar value +*/ +CV_EXPORTS_W void pHash(cv::InputArray inputArr, cv::OutputArray outputArr); + +//! @} + +} } // cv::img_hash:: + +#endif // OPENCV_PHASH_HPP diff --git a/include/opencv2/img_hash/radial_variance_hash.hpp b/include/opencv2/img_hash/radial_variance_hash.hpp new file mode 100644 index 0000000..455f285 --- /dev/null +++ b/include/opencv2/img_hash/radial_variance_hash.hpp @@ -0,0 +1,58 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_RADIAL_VARIANCE_HASH_HPP +#define OPENCV_RADIAL_VARIANCE_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + + +/** @brief Image hash based on Radon transform. + +See @cite tang2012perceptual for details. +*/ +class CV_EXPORTS_W RadialVarianceHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr<RadialVarianceHash> create(double sigma = 1, int numOfAngleLine = 180); + + CV_WRAP int getNumOfAngleLine() const; + CV_WRAP double getSigma() const; + + CV_WRAP void setNumOfAngleLine(int value); + CV_WRAP void setSigma(double value); + + // internals + std::vector<double> getFeatures(); + cv::Mat getHash(); + Mat getPixPerLine(Mat const &input); + Mat getProjection(); +protected: + RadialVarianceHash() {} +}; + +/** @brief Computes radial variance hash of the input image + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3, CV_8UC1. + @param outputArr Hash value of input + @param sigma Gaussian kernel standard deviation + @param numOfAngleLine The number of angles to consider + */ +CV_EXPORTS_W void radialVarianceHash(cv::InputArray inputArr, + cv::OutputArray outputArr, + double sigma = 1, + int numOfAngleLine = 180); + + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_RADIAL_VARIANCE_HASH_HPP diff --git a/include/opencv2/imgcodecs.hpp b/include/opencv2/imgcodecs.hpp new file mode 100644 index 0000000..ab75990 --- /dev/null +++ b/include/opencv2/imgcodecs.hpp @@ -0,0 +1,260 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_IMGCODECS_HPP +#define OPENCV_IMGCODECS_HPP + +#include "opencv2/core.hpp" + +/** + @defgroup imgcodecs Image file reading and writing + @{ + @defgroup imgcodecs_c C API + @defgroup imgcodecs_ios iOS glue + @} +*/ + +//////////////////////////////// image codec //////////////////////////////// +namespace cv +{ + +//! @addtogroup imgcodecs +//! @{ + +//! Imread flags +enum ImreadModes { + IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). + IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion). + IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image. + IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. + IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format. + IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image. + IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2. + IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. + IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4. + IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. + IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8. + IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. + IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag. + }; + +//! Imwrite flags +enum ImwriteFlags { + IMWRITE_JPEG_QUALITY = 1, //!< For JPEG, it can be a quality from 0 to 100 (the higher is the better). Default value is 95. + IMWRITE_JPEG_PROGRESSIVE = 2, //!< Enable JPEG features, 0 or 1, default is False. + IMWRITE_JPEG_OPTIMIZE = 3, //!< Enable JPEG features, 0 or 1, default is False. + IMWRITE_JPEG_RST_INTERVAL = 4, //!< JPEG restart interval, 0 - 65535, default is 0 - no restart. + IMWRITE_JPEG_LUMA_QUALITY = 5, //!< Separate luma quality level, 0 - 100, default is 0 - don't use. + IMWRITE_JPEG_CHROMA_QUALITY = 6, //!< Separate chroma quality level, 0 - 100, default is 0 - don't use. + IMWRITE_PNG_COMPRESSION = 16, //!< For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. If specified, strategy is changed to IMWRITE_PNG_STRATEGY_DEFAULT (Z_DEFAULT_STRATEGY). Default value is 1 (best speed setting). + IMWRITE_PNG_STRATEGY = 17, //!< One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_RLE. + IMWRITE_PNG_BILEVEL = 18, //!< Binary level PNG, 0 or 1, default is 0. + IMWRITE_PXM_BINARY = 32, //!< For PPM, PGM, or PBM, it can be a binary format flag, 0 or 1. Default value is 1. + IMWRITE_EXR_TYPE = (3 << 4) + 0, /* 48 */ //!< override EXR storage type (FLOAT (FP32) is default) + IMWRITE_WEBP_QUALITY = 64, //!< For WEBP, it can be a quality from 1 to 100 (the higher is the better). By default (without any parameter) and for quality above 100 the lossless compression is used. + IMWRITE_PAM_TUPLETYPE = 128,//!< For PAM, sets the TUPLETYPE field to the corresponding string value that is defined for the format + IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values. + IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI. + IMWRITE_TIFF_YDPI = 258, //!< For TIFF, use to specify the Y direction DPI. + IMWRITE_TIFF_COMPRESSION = 259 //!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default. + }; + +enum ImwriteEXRTypeFlags { + /*IMWRITE_EXR_TYPE_UNIT = 0, //!< not supported */ + IMWRITE_EXR_TYPE_HALF = 1, //!< store as HALF (FP16) + IMWRITE_EXR_TYPE_FLOAT = 2 //!< store as FP32 (default) + }; + +//! Imwrite PNG specific flags used to tune the compression algorithm. +/** These flags will be modify the way of PNG image compression and will be passed to the underlying zlib processing stage. + +- The effect of IMWRITE_PNG_STRATEGY_FILTERED is to force more Huffman coding and less string matching; it is somewhat intermediate between IMWRITE_PNG_STRATEGY_DEFAULT and IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY. +- IMWRITE_PNG_STRATEGY_RLE is designed to be almost as fast as IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY, but give better compression for PNG image data. +- The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately. +- IMWRITE_PNG_STRATEGY_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. +*/ +enum ImwritePNGFlags { + IMWRITE_PNG_STRATEGY_DEFAULT = 0, //!< Use this value for normal data. + IMWRITE_PNG_STRATEGY_FILTERED = 1, //!< Use this value for data produced by a filter (or predictor).Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. + IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2, //!< Use this value to force Huffman encoding only (no string match). + IMWRITE_PNG_STRATEGY_RLE = 3, //!< Use this value to limit match distances to one (run-length encoding). + IMWRITE_PNG_STRATEGY_FIXED = 4 //!< Using this value prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. + }; + +//! Imwrite PAM specific tupletype flags used to define the 'TUPETYPE' field of a PAM file. +enum ImwritePAMFlags { + IMWRITE_PAM_FORMAT_NULL = 0, + IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + IMWRITE_PAM_FORMAT_RGB = 4, + IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, + }; + +/** @brief Loads an image from a file. + +@anchor imread + +The function imread loads an image from the specified file and returns it. If the image cannot be +read (because of missing file, improper permissions, unsupported or invalid format), the function +returns an empty matrix ( Mat::data==NULL ). + +Currently, the following file formats are supported: + +- Windows bitmaps - \*.bmp, \*.dib (always supported) +- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section) +- JPEG 2000 files - \*.jp2 (see the *Note* section) +- Portable Network Graphics - \*.png (see the *Note* section) +- WebP - \*.webp (see the *Note* section) +- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) +- Sun rasters - \*.sr, \*.ras (always supported) +- TIFF files - \*.tiff, \*.tif (see the *Note* section) +- OpenEXR Image files - \*.exr (see the *Note* section) +- Radiance HDR - \*.hdr, \*.pic (always supported) +- Raster and Vector geospatial data supported by GDAL (see the *Note* section) + +@note +- The function determines the type of an image by the content, not by the file extension. +- In the case of color images, the decoded images will have the channels stored in **B G R** order. +- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. + Results may differ to the output of cvtColor() +- On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, + libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, + and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware + that currently these native image loaders give images with different pixel values because of + the color management embedded into MacOSX. +- On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for + codecs supplied with an OS image. Install the relevant packages (do not forget the development + files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn + on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. +- In the case you set *WITH_GDAL* flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image, + then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting + the following formats: [Raster](http://www.gdal.org/formats_list.html), + [Vector](http://www.gdal.org/ogr_formats.html). +- If EXIF information are embedded in the image file, the EXIF orientation will be taken into account + and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed. +- By default number of pixels must be less than 2^30. Limit can be set using system + variable OPENCV_IO_MAX_IMAGE_PIXELS + +@param filename Name of file to be loaded. +@param flags Flag that can take values of cv::ImreadModes +*/ +CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR ); + +/** @brief Loads a multi-page image from a file. + +The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. +@param filename Name of file to be loaded. +@param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. +@param mats A vector of Mat objects holding each page, if more than one. +@sa cv::imread +*/ +CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector<Mat>& mats, int flags = IMREAD_ANYCOLOR); + +/** @brief Saves an image to a specified file. + +The function imwrite saves the image to the specified file. The image format is chosen based on the +filename extension (see cv::imread for the list of extensions). In general, only 8-bit +single-channel or 3-channel (with 'BGR' channel order) images +can be saved using this function, with these exceptions: + +- 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats +- 32-bit float (CV_32F) images can be saved in TIFF, OpenEXR, and Radiance HDR formats; 3-channel +(CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding (4 bytes per pixel) +- PNG images with an alpha channel can be saved using this function. To do this, create +8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels +should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). + +If the format, depth or channel order is different, use +Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O +functions to save the image to XML or YAML format. + +The sample below shows how to create a BGRA image and save it to a PNG file. It also demonstrates how to set custom +compression parameters: +@include snippets/imgcodecs_imwrite.cpp +@param filename Name of the file. +@param img Image to be saved. +@param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags +*/ +CV_EXPORTS_W bool imwrite( const String& filename, InputArray img, + const std::vector<int>& params = std::vector<int>()); + +/** @brief Reads an image from a buffer in memory. + +The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or +contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). + +See cv::imread for the list of supported formats and flags description. + +@note In the case of color images, the decoded images will have the channels stored in **B G R** order. +@param buf Input array or vector of bytes. +@param flags The same flags as in cv::imread, see cv::ImreadModes. +*/ +CV_EXPORTS_W Mat imdecode( InputArray buf, int flags ); + +/** @overload +@param buf +@param flags +@param dst The optional output placeholder for the decoded matrix. It can save the image +reallocations when the function is called repeatedly for images of the same size. +*/ +CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst); + +/** @brief Encodes an image into a memory buffer. + +The function imencode compresses the image and stores it in the memory buffer that is resized to fit the +result. See cv::imwrite for the list of supported formats and flags description. + +@param ext File extension that defines the output format. +@param img Image to be written. +@param buf Output buffer resized to fit the compressed image. +@param params Format-specific parameters. See cv::imwrite and cv::ImwriteFlags. +*/ +CV_EXPORTS_W bool imencode( const String& ext, InputArray img, + CV_OUT std::vector<uchar>& buf, + const std::vector<int>& params = std::vector<int>()); + +//! @} imgcodecs + +} // cv + +#endif //OPENCV_IMGCODECS_HPP diff --git a/include/opencv2/imgcodecs/imgcodecs.hpp b/include/opencv2/imgcodecs/imgcodecs.hpp new file mode 100644 index 0000000..a3cd232 --- /dev/null +++ b/include/opencv2/imgcodecs/imgcodecs.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/imgcodecs.hpp" diff --git a/include/opencv2/imgcodecs/imgcodecs_c.h b/include/opencv2/imgcodecs/imgcodecs_c.h new file mode 100644 index 0000000..c36dac3 --- /dev/null +++ b/include/opencv2/imgcodecs/imgcodecs_c.h @@ -0,0 +1,149 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_IMGCODECS_H +#define OPENCV_IMGCODECS_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** @addtogroup imgcodecs_c + @{ + */ + +enum +{ +/* 8bit, color or not */ + CV_LOAD_IMAGE_UNCHANGED =-1, +/* 8bit, gray */ + CV_LOAD_IMAGE_GRAYSCALE =0, +/* ?, color */ + CV_LOAD_IMAGE_COLOR =1, +/* any depth, ? */ + CV_LOAD_IMAGE_ANYDEPTH =2, +/* ?, any color */ + CV_LOAD_IMAGE_ANYCOLOR =4, +/* ?, no rotate */ + CV_LOAD_IMAGE_IGNORE_ORIENTATION =128 +}; + +/* load image from file + iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED + overrides the other flags + using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED + unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit +*/ +CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); +CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); + +enum +{ + CV_IMWRITE_JPEG_QUALITY =1, + CV_IMWRITE_JPEG_PROGRESSIVE =2, + CV_IMWRITE_JPEG_OPTIMIZE =3, + CV_IMWRITE_JPEG_RST_INTERVAL =4, + CV_IMWRITE_JPEG_LUMA_QUALITY =5, + CV_IMWRITE_JPEG_CHROMA_QUALITY =6, + CV_IMWRITE_PNG_COMPRESSION =16, + CV_IMWRITE_PNG_STRATEGY =17, + CV_IMWRITE_PNG_BILEVEL =18, + CV_IMWRITE_PNG_STRATEGY_DEFAULT =0, + CV_IMWRITE_PNG_STRATEGY_FILTERED =1, + CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2, + CV_IMWRITE_PNG_STRATEGY_RLE =3, + CV_IMWRITE_PNG_STRATEGY_FIXED =4, + CV_IMWRITE_PXM_BINARY =32, + CV_IMWRITE_EXR_TYPE = 48, + CV_IMWRITE_WEBP_QUALITY =64, + CV_IMWRITE_PAM_TUPLETYPE = 128, + CV_IMWRITE_PAM_FORMAT_NULL = 0, + CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + CV_IMWRITE_PAM_FORMAT_RGB = 4, + CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, +}; + + + +/* save image to file */ +CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, + const int* params CV_DEFAULT(0) ); + +/* decode image stored in the buffer */ +CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); +CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); + +/* encode image and store the result as a byte vector (single-row 8uC1 matrix) */ +CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image, + const int* params CV_DEFAULT(0) ); + +enum +{ + CV_CVTIMG_FLIP =1, + CV_CVTIMG_SWAP_RB =2 +}; + +/* utility function: convert one image to another with optional vertical flip */ +CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0)); + +CVAPI(int) cvHaveImageReader(const char* filename); +CVAPI(int) cvHaveImageWriter(const char* filename); + + +/****************************************************************************************\ +* Obsolete functions/synonyms * +\****************************************************************************************/ + +#define cvvLoadImage(name) cvLoadImage((name),1) +#define cvvSaveImage cvSaveImage +#define cvvConvertImage cvConvertImage + +/** @} imgcodecs_c */ + +#ifdef __cplusplus +} +#endif + +#endif // OPENCV_IMGCODECS_H diff --git a/include/opencv2/imgcodecs/ios.h b/include/opencv2/imgcodecs/ios.h new file mode 100644 index 0000000..a90c6d3 --- /dev/null +++ b/include/opencv2/imgcodecs/ios.h @@ -0,0 +1,57 @@ + +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#import <UIKit/UIKit.h> +#import <Accelerate/Accelerate.h> +#import <AVFoundation/AVFoundation.h> +#import <ImageIO/ImageIO.h> +#include "opencv2/core/core.hpp" + +//! @addtogroup imgcodecs_ios +//! @{ + +CV_EXPORTS UIImage* MatToUIImage(const cv::Mat& image); +CV_EXPORTS void UIImageToMat(const UIImage* image, + cv::Mat& m, bool alphaExist = false); + +//! @} diff --git a/include/opencv2/imgproc.hpp b/include/opencv2/imgproc.hpp new file mode 100644 index 0000000..ab7d0e6 --- /dev/null +++ b/include/opencv2/imgproc.hpp @@ -0,0 +1,4922 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_IMGPROC_HPP +#define OPENCV_IMGPROC_HPP + +#include "opencv2/core.hpp" + +/** + @defgroup imgproc Image Processing + +This module includes image-processing functions. + + @{ + @defgroup imgproc_filter Image Filtering + +Functions and classes described in this section are used to perform various linear or non-linear +filtering operations on 2D images (represented as Mat's). It means that for each pixel location +\f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to +compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of +morphological operations, it is the minimum or maximum values, and so on. The computed response is +stored in the destination image at the same location \f$(x,y)\f$. It means that the output image +will be of the same size as the input image. Normally, the functions support multi-channel arrays, +in which case every channel is processed independently. Therefore, the output image will also have +the same number of channels as the input one. + +Another common feature of the functions and classes described in this section is that, unlike +simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For +example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when +processing the left-most pixels in each row, you need pixels to the left of them, that is, outside +of the image. You can let these pixels be the same as the left-most image pixels ("replicated +border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant +border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method. +For details, see #BorderTypes + +@anchor filter_depths +### Depth combinations +Input depth (src.depth()) | Output depth (ddepth) +--------------------------|---------------------- +CV_8U | -1/CV_16S/CV_32F/CV_64F +CV_16U/CV_16S | -1/CV_32F/CV_64F +CV_32F | -1/CV_32F/CV_64F +CV_64F | -1/CV_64F + +@note when ddepth=-1, the output image will have the same depth as the source. + + @defgroup imgproc_transform Geometric Image Transformations + +The functions in this section perform various geometrical transformations of 2D images. They do not +change the image content but deform the pixel grid and map this deformed grid to the destination +image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from +destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the +functions compute coordinates of the corresponding "donor" pixel in the source image and copy the +pixel value: + +\f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f] + +In case when you specify the forward mapping \f$\left<g_x, g_y\right>: \texttt{src} \rightarrow +\texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping +\f$\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula. + +The actual implementations of the geometrical transformations, from the most generic remap and to +the simplest and the fastest resize, need to solve two main problems with the above formula: + +- Extrapolation of non-existing pixels. Similarly to the filtering functions described in the +previous section, for some \f$(x,y)\f$, either one of \f$f_x(x,y)\f$, or \f$f_y(x,y)\f$, or both +of them may fall outside of the image. In this case, an extrapolation method needs to be used. +OpenCV provides the same selection of extrapolation methods as in the filtering functions. In +addition, it provides the method #BORDER_TRANSPARENT. This means that the corresponding pixels in +the destination image will not be modified at all. + +- Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point +numbers. This means that \f$\left<f_x, f_y\right>\f$ can be either an affine or perspective +transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional +coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the +nearest integer coordinates and the corresponding pixel can be used. This is called a +nearest-neighbor interpolation. However, a better result can be achieved by using more +sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) , +where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y), +f_y(x,y))\f$, and then the value of the polynomial at \f$(f_x(x,y), f_y(x,y))\f$ is taken as the +interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See +resize for details. + +@note The geometrical transformations do not work with `CV_8S` or `CV_32S` images. + + @defgroup imgproc_misc Miscellaneous Image Transformations + @defgroup imgproc_draw Drawing Functions + +Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be +rendered with antialiasing (implemented only for 8-bit images for now). All the functions include +the parameter color that uses an RGB value (that may be constructed with the Scalar constructor ) +for color images and brightness for grayscale images. For color images, the channel ordering is +normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a +color using the Scalar constructor, it should look like: + +\f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f] + +If you are using your own image rendering and I/O functions, you can use any channel ordering. The +drawing functions process each channel independently and do not depend on the channel order or even +on the used color space. The whole image can be converted from BGR to RGB or to a different color +space using cvtColor . + +If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, +many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means +that the coordinates can be passed as fixed-point numbers encoded as integers. The number of +fractional bits is specified by the shift parameter and the real point coordinates are calculated as +\f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is +especially effective when rendering antialiased shapes. + +@note The functions do not support alpha-transparency when the target image is 4-channel. In this +case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint +semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main +image. + + @defgroup imgproc_color_conversions Color Space Conversions + @defgroup imgproc_colormap ColorMaps in OpenCV + +The human perception isn't built for observing fine changes in grayscale images. Human eyes are more +sensitive to observing changes between colors, so you often need to recolor your grayscale images to +get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your +computer vision application. + +In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample +code reads the path to an image from command line, applies a Jet colormap on it and shows the +result: + +@include snippets/imgproc_applyColorMap.cpp + +@see #ColormapTypes + + @defgroup imgproc_subdiv2d Planar Subdivision + +The Subdiv2D class described in this section is used to perform various planar subdivision on +a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles +using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram. +In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi +diagram with red lines. + +![Delaunay triangulation (black) and Voronoi (red)](pics/delaunay_voronoi.png) + +The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast +location of points on the plane, building special graphs (such as NNG,RNG), and so forth. + + @defgroup imgproc_hist Histograms + @defgroup imgproc_shape Structural Analysis and Shape Descriptors + @defgroup imgproc_motion Motion Analysis and Object Tracking + @defgroup imgproc_feature Feature Detection + @defgroup imgproc_object Object Detection + @defgroup imgproc_c C API + @defgroup imgproc_hal Hardware Acceleration Layer + @{ + @defgroup imgproc_hal_functions Functions + @defgroup imgproc_hal_interface Interface + @} + @} +*/ + +namespace cv +{ + +/** @addtogroup imgproc +@{ +*/ + +//! @addtogroup imgproc_filter +//! @{ + +//! type of morphological operation +enum MorphTypes{ + MORPH_ERODE = 0, //!< see #erode + MORPH_DILATE = 1, //!< see #dilate + MORPH_OPEN = 2, //!< an opening operation + //!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f] + MORPH_CLOSE = 3, //!< a closing operation + //!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f] + MORPH_GRADIENT = 4, //!< a morphological gradient + //!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f] + MORPH_TOPHAT = 5, //!< "top hat" + //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f] + MORPH_BLACKHAT = 6, //!< "black hat" + //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f] + MORPH_HITMISS = 7 //!< "hit or miss" + //!< .- Only supported for CV_8UC1 binary images. A tutorial can be found in the documentation +}; + +//! shape of the structuring element +enum MorphShapes { + MORPH_RECT = 0, //!< a rectangular structuring element: \f[E_{ij}=1\f] + MORPH_CROSS = 1, //!< a cross-shaped structuring element: + //!< \f[E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f] + MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed + //!< into the rectangle Rect(0, 0, esize.width, 0.esize.height) +}; + +//! @} imgproc_filter + +//! @addtogroup imgproc_transform +//! @{ + +//! interpolation algorithm +enum InterpolationFlags{ + /** nearest neighbor interpolation */ + INTER_NEAREST = 0, + /** bilinear interpolation */ + INTER_LINEAR = 1, + /** bicubic interpolation */ + INTER_CUBIC = 2, + /** resampling using pixel area relation. It may be a preferred method for image decimation, as + it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST + method. */ + INTER_AREA = 3, + /** Lanczos interpolation over 8x8 neighborhood */ + INTER_LANCZOS4 = 4, + /** Bit exact bilinear interpolation */ + INTER_LINEAR_EXACT = 5, + /** mask for interpolation codes */ + INTER_MAX = 7, + /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the + source image, they are set to zero */ + WARP_FILL_OUTLIERS = 8, + /** flag, inverse transformation + + For example, #linearPolar or #logPolar transforms: + - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$ + - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$ + */ + WARP_INVERSE_MAP = 16 +}; + +/** \brief Specify the polar mapping mode +@sa warpPolar +*/ +enum WarpPolarMode +{ + WARP_POLAR_LINEAR = 0, ///< Remaps an image to/from polar space. + WARP_POLAR_LOG = 256 ///< Remaps an image to/from semilog-polar space. +}; + +enum InterpolationMasks { + INTER_BITS = 5, + INTER_BITS2 = INTER_BITS * 2, + INTER_TAB_SIZE = 1 << INTER_BITS, + INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE + }; + +//! @} imgproc_transform + +//! @addtogroup imgproc_misc +//! @{ + +//! Distance types for Distance Transform and M-estimators +//! @see distanceTransform, fitLine +enum DistanceTypes { + DIST_USER = -1, //!< User defined distance + DIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2| + DIST_L2 = 2, //!< the simple euclidean distance + DIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|) + DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) + DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 + DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 + DIST_HUBER = 7 //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 +}; + +//! Mask size for distance transform +enum DistanceTransformMasks { + DIST_MASK_3 = 3, //!< mask=3 + DIST_MASK_5 = 5, //!< mask=5 + DIST_MASK_PRECISE = 0 //!< +}; + +//! type of the threshold operation +//! ![threshold types](pics/threshold.png) +enum ThresholdTypes { + THRESH_BINARY = 0, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] + THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f] + THRESH_TRUNC = 2, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] + THRESH_TOZERO = 3, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] + THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] + THRESH_MASK = 7, + THRESH_OTSU = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value + THRESH_TRIANGLE = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value +}; + +//! adaptive threshold algorithm +//! @see adaptiveThreshold +enum AdaptiveThresholdTypes { + /** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times + \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */ + ADAPTIVE_THRESH_MEAN_C = 0, + /** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian + window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ + minus C . The default sigma (standard deviation) is used for the specified blockSize . See + #getGaussianKernel*/ + ADAPTIVE_THRESH_GAUSSIAN_C = 1 +}; + +//! cv::undistort mode +enum UndistortTypes { + PROJ_SPHERICAL_ORTHO = 0, + PROJ_SPHERICAL_EQRECT = 1 + }; + +//! class of the pixel in GrabCut algorithm +enum GrabCutClasses { + GC_BGD = 0, //!< an obvious background pixels + GC_FGD = 1, //!< an obvious foreground (object) pixel + GC_PR_BGD = 2, //!< a possible background pixel + GC_PR_FGD = 3 //!< a possible foreground pixel +}; + +//! GrabCut algorithm flags +enum GrabCutModes { + /** The function initializes the state and the mask using the provided rectangle. After that it + runs iterCount iterations of the algorithm. */ + GC_INIT_WITH_RECT = 0, + /** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT + and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are + automatically initialized with GC_BGD .*/ + GC_INIT_WITH_MASK = 1, + /** The value means that the algorithm should just resume. */ + GC_EVAL = 2, + /** The value means that the algorithm should just run the grabCut algorithm (a single iteration) with the fixed model */ + GC_EVAL_FREEZE_MODEL = 3 +}; + +//! distanceTransform algorithm flags +enum DistanceTransformLabelTypes { + /** each connected component of zeros in src (as well as all the non-zero pixels closest to the + connected component) will be assigned the same label */ + DIST_LABEL_CCOMP = 0, + /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */ + DIST_LABEL_PIXEL = 1 +}; + +//! floodfill algorithm flags +enum FloodFillFlags { + /** If set, the difference between the current pixel and seed pixel is considered. Otherwise, + the difference between neighbor pixels is considered (that is, the range is floating). */ + FLOODFILL_FIXED_RANGE = 1 << 16, + /** If set, the function does not change the image ( newVal is ignored), and only fills the + mask with the value specified in bits 8-16 of flags as described above. This option only make + sense in function variants that have the mask parameter. */ + FLOODFILL_MASK_ONLY = 1 << 17 +}; + +//! @} imgproc_misc + +//! @addtogroup imgproc_shape +//! @{ + +//! connected components algorithm output formats +enum ConnectedComponentsTypes { + CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding + //!< box in the horizontal direction. + CC_STAT_TOP = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding + //!< box in the vertical direction. + CC_STAT_WIDTH = 2, //!< The horizontal size of the bounding box + CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box + CC_STAT_AREA = 4, //!< The total area (in pixels) of the connected component + CC_STAT_MAX = 5 +}; + +//! connected components algorithm +enum ConnectedComponentsAlgorithmsTypes { + CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity +}; + +//! mode of the contour retrieval algorithm +enum RetrievalModes { + /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for + all the contours. */ + RETR_EXTERNAL = 0, + /** retrieves all of the contours without establishing any hierarchical relationships. */ + RETR_LIST = 1, + /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top + level, there are external boundaries of the components. At the second level, there are + boundaries of the holes. If there is another contour inside a hole of a connected component, it + is still put at the top level. */ + RETR_CCOMP = 2, + /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/ + RETR_TREE = 3, + RETR_FLOODFILL = 4 //!< +}; + +//! the contour approximation algorithm +enum ContourApproximationModes { + /** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and + (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is, + max(abs(x1-x2),abs(y2-y1))==1. */ + CHAIN_APPROX_NONE = 1, + /** compresses horizontal, vertical, and diagonal segments and leaves only their end points. + For example, an up-right rectangular contour is encoded with 4 points. */ + CHAIN_APPROX_SIMPLE = 2, + /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */ + CHAIN_APPROX_TC89_L1 = 3, + /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */ + CHAIN_APPROX_TC89_KCOS = 4 +}; + +/** @brief Shape matching methods + +\f$A\f$ denotes object1,\f$B\f$ denotes object2 + +\f$\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\f$ + +and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively. +*/ +enum ShapeMatchModes { + CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f] + CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f] + CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f] +}; + +//! @} imgproc_shape + +//! @addtogroup imgproc_feature +//! @{ + +//! Variants of a Hough transform +enum HoughModes { + + /** classical or standard Hough transform. Every line is represented by two floating-point + numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line, + and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must + be (the created sequence will be) of CV_32FC2 type */ + HOUGH_STANDARD = 0, + /** probabilistic Hough transform (more efficient in case if the picture contains a few long + linear segments). It returns line segments rather than the whole line. Each segment is + represented by starting and ending points, and the matrix must be (the created sequence will + be) of the CV_32SC4 type. */ + HOUGH_PROBABILISTIC = 1, + /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as + HOUGH_STANDARD. */ + HOUGH_MULTI_SCALE = 2, + HOUGH_GRADIENT = 3 //!< basically *21HT*, described in @cite Yuen90 +}; + +//! Variants of Line Segment %Detector +enum LineSegmentDetectorModes { + LSD_REFINE_NONE = 0, //!< No refinement applied + LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations. + LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are + //!< refined through increase of precision, decrement in size, etc. +}; + +//! @} imgproc_feature + +/** Histogram comparison methods + @ingroup imgproc_hist +*/ +enum HistCompMethods { + /** Correlation + \f[d(H_1,H_2) = \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}\f] + where + \f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f] + and \f$N\f$ is a total number of histogram bins. */ + HISTCMP_CORREL = 0, + /** Chi-Square + \f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */ + HISTCMP_CHISQR = 1, + /** Intersection + \f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] */ + HISTCMP_INTERSECT = 2, + /** Bhattacharyya distance + (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.) + \f[d(H_1,H_2) = \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}\f] */ + HISTCMP_BHATTACHARYYA = 3, + HISTCMP_HELLINGER = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA + /** Alternative Chi-Square + \f[d(H_1,H_2) = 2 * \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)+H_2(I)}\f] + This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */ + HISTCMP_CHISQR_ALT = 4, + /** Kullback-Leibler divergence + \f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */ + HISTCMP_KL_DIV = 5 +}; + +/** the color conversion codes +@see @ref imgproc_color_conversions +@ingroup imgproc_color_conversions + */ +enum ColorConversionCodes { + COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image + COLOR_RGB2RGBA = COLOR_BGR2BGRA, + + COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image + COLOR_RGBA2RGB = COLOR_BGRA2BGR, + + COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel) + COLOR_RGB2BGRA = COLOR_BGR2RGBA, + + COLOR_RGBA2BGR = 3, + COLOR_BGRA2RGB = COLOR_RGBA2BGR, + + COLOR_BGR2RGB = 4, + COLOR_RGB2BGR = COLOR_BGR2RGB, + + COLOR_BGRA2RGBA = 5, + COLOR_RGBA2BGRA = COLOR_BGRA2RGBA, + + COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions" + COLOR_RGB2GRAY = 7, + COLOR_GRAY2BGR = 8, + COLOR_GRAY2RGB = COLOR_GRAY2BGR, + COLOR_GRAY2BGRA = 9, + COLOR_GRAY2RGBA = COLOR_GRAY2BGRA, + COLOR_BGRA2GRAY = 10, + COLOR_RGBA2GRAY = 11, + + COLOR_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images) + COLOR_RGB2BGR565 = 13, + COLOR_BGR5652BGR = 14, + COLOR_BGR5652RGB = 15, + COLOR_BGRA2BGR565 = 16, + COLOR_RGBA2BGR565 = 17, + COLOR_BGR5652BGRA = 18, + COLOR_BGR5652RGBA = 19, + + COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images) + COLOR_BGR5652GRAY = 21, + + COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images) + COLOR_RGB2BGR555 = 23, + COLOR_BGR5552BGR = 24, + COLOR_BGR5552RGB = 25, + COLOR_BGRA2BGR555 = 26, + COLOR_RGBA2BGR555 = 27, + COLOR_BGR5552BGRA = 28, + COLOR_BGR5552RGBA = 29, + + COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images) + COLOR_BGR5552GRAY = 31, + + COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions" + COLOR_RGB2XYZ = 33, + COLOR_XYZ2BGR = 34, + COLOR_XYZ2RGB = 35, + + COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions" + COLOR_RGB2YCrCb = 37, + COLOR_YCrCb2BGR = 38, + COLOR_YCrCb2RGB = 39, + + COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions" + COLOR_RGB2HSV = 41, + + COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions" + COLOR_RGB2Lab = 45, + + COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions" + COLOR_RGB2Luv = 51, + COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions" + COLOR_RGB2HLS = 53, + + COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR + COLOR_HSV2RGB = 55, + + COLOR_Lab2BGR = 56, + COLOR_Lab2RGB = 57, + COLOR_Luv2BGR = 58, + COLOR_Luv2RGB = 59, + COLOR_HLS2BGR = 60, + COLOR_HLS2RGB = 61, + + COLOR_BGR2HSV_FULL = 66, + COLOR_RGB2HSV_FULL = 67, + COLOR_BGR2HLS_FULL = 68, + COLOR_RGB2HLS_FULL = 69, + + COLOR_HSV2BGR_FULL = 70, + COLOR_HSV2RGB_FULL = 71, + COLOR_HLS2BGR_FULL = 72, + COLOR_HLS2RGB_FULL = 73, + + COLOR_LBGR2Lab = 74, + COLOR_LRGB2Lab = 75, + COLOR_LBGR2Luv = 76, + COLOR_LRGB2Luv = 77, + + COLOR_Lab2LBGR = 78, + COLOR_Lab2LRGB = 79, + COLOR_Luv2LBGR = 80, + COLOR_Luv2LRGB = 81, + + COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV + COLOR_RGB2YUV = 83, + COLOR_YUV2BGR = 84, + COLOR_YUV2RGB = 85, + + //! YUV 4:2:0 family to RGB + COLOR_YUV2RGB_NV12 = 90, + COLOR_YUV2BGR_NV12 = 91, + COLOR_YUV2RGB_NV21 = 92, + COLOR_YUV2BGR_NV21 = 93, + COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21, + COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21, + + COLOR_YUV2RGBA_NV12 = 94, + COLOR_YUV2BGRA_NV12 = 95, + COLOR_YUV2RGBA_NV21 = 96, + COLOR_YUV2BGRA_NV21 = 97, + COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21, + COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21, + + COLOR_YUV2RGB_YV12 = 98, + COLOR_YUV2BGR_YV12 = 99, + COLOR_YUV2RGB_IYUV = 100, + COLOR_YUV2BGR_IYUV = 101, + COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV, + COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV, + COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12, + COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12, + + COLOR_YUV2RGBA_YV12 = 102, + COLOR_YUV2BGRA_YV12 = 103, + COLOR_YUV2RGBA_IYUV = 104, + COLOR_YUV2BGRA_IYUV = 105, + COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV, + COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV, + COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12, + COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12, + + COLOR_YUV2GRAY_420 = 106, + COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420, + COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420, + COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420, + + //! YUV 4:2:2 family to RGB + COLOR_YUV2RGB_UYVY = 107, + COLOR_YUV2BGR_UYVY = 108, + //COLOR_YUV2RGB_VYUY = 109, + //COLOR_YUV2BGR_VYUY = 110, + COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY, + COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY, + COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY, + COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY, + + COLOR_YUV2RGBA_UYVY = 111, + COLOR_YUV2BGRA_UYVY = 112, + //COLOR_YUV2RGBA_VYUY = 113, + //COLOR_YUV2BGRA_VYUY = 114, + COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY, + COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY, + COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY, + COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY, + + COLOR_YUV2RGB_YUY2 = 115, + COLOR_YUV2BGR_YUY2 = 116, + COLOR_YUV2RGB_YVYU = 117, + COLOR_YUV2BGR_YVYU = 118, + COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2, + COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2, + COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2, + COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2, + + COLOR_YUV2RGBA_YUY2 = 119, + COLOR_YUV2BGRA_YUY2 = 120, + COLOR_YUV2RGBA_YVYU = 121, + COLOR_YUV2BGRA_YVYU = 122, + COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2, + COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2, + COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2, + COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2, + + COLOR_YUV2GRAY_UYVY = 123, + COLOR_YUV2GRAY_YUY2 = 124, + //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY, + COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY, + COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY, + COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2, + COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2, + COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2, + + //! alpha premultiplication + COLOR_RGBA2mRGBA = 125, + COLOR_mRGBA2RGBA = 126, + + //! RGB to YUV 4:2:0 family + COLOR_RGB2YUV_I420 = 127, + COLOR_BGR2YUV_I420 = 128, + COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420, + COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420, + + COLOR_RGBA2YUV_I420 = 129, + COLOR_BGRA2YUV_I420 = 130, + COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420, + COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420, + COLOR_RGB2YUV_YV12 = 131, + COLOR_BGR2YUV_YV12 = 132, + COLOR_RGBA2YUV_YV12 = 133, + COLOR_BGRA2YUV_YV12 = 134, + + //! Demosaicing + COLOR_BayerBG2BGR = 46, + COLOR_BayerGB2BGR = 47, + COLOR_BayerRG2BGR = 48, + COLOR_BayerGR2BGR = 49, + + COLOR_BayerBG2RGB = COLOR_BayerRG2BGR, + COLOR_BayerGB2RGB = COLOR_BayerGR2BGR, + COLOR_BayerRG2RGB = COLOR_BayerBG2BGR, + COLOR_BayerGR2RGB = COLOR_BayerGB2BGR, + + COLOR_BayerBG2GRAY = 86, + COLOR_BayerGB2GRAY = 87, + COLOR_BayerRG2GRAY = 88, + COLOR_BayerGR2GRAY = 89, + + //! Demosaicing using Variable Number of Gradients + COLOR_BayerBG2BGR_VNG = 62, + COLOR_BayerGB2BGR_VNG = 63, + COLOR_BayerRG2BGR_VNG = 64, + COLOR_BayerGR2BGR_VNG = 65, + + COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG, + COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG, + COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG, + COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG, + + //! Edge-Aware Demosaicing + COLOR_BayerBG2BGR_EA = 135, + COLOR_BayerGB2BGR_EA = 136, + COLOR_BayerRG2BGR_EA = 137, + COLOR_BayerGR2BGR_EA = 138, + + COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA, + COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA, + COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA, + COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA, + + //! Demosaicing with alpha channel + COLOR_BayerBG2BGRA = 139, + COLOR_BayerGB2BGRA = 140, + COLOR_BayerRG2BGRA = 141, + COLOR_BayerGR2BGRA = 142, + + COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA, + COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA, + COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA, + COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA, + + COLOR_COLORCVT_MAX = 143 +}; + +//! @addtogroup imgproc_shape +//! @{ + +//! types of intersection between rectangles +enum RectanglesIntersectTypes { + INTERSECT_NONE = 0, //!< No intersection + INTERSECT_PARTIAL = 1, //!< There is a partial intersection + INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other +}; + +/** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform +*/ +class CV_EXPORTS GeneralizedHough : public Algorithm +{ +public: + //! set template to search + virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0; + virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0; + + //! find template on image + virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0; + virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0; + + //! Canny low threshold. + virtual void setCannyLowThresh(int cannyLowThresh) = 0; + virtual int getCannyLowThresh() const = 0; + + //! Canny high threshold. + virtual void setCannyHighThresh(int cannyHighThresh) = 0; + virtual int getCannyHighThresh() const = 0; + + //! Minimum distance between the centers of the detected objects. + virtual void setMinDist(double minDist) = 0; + virtual double getMinDist() const = 0; + + //! Inverse ratio of the accumulator resolution to the image resolution. + virtual void setDp(double dp) = 0; + virtual double getDp() const = 0; + + //! Maximal size of inner buffers. + virtual void setMaxBufferSize(int maxBufferSize) = 0; + virtual int getMaxBufferSize() const = 0; +}; + +/** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform + +Detects position only without translation and rotation @cite Ballard1981 . +*/ +class CV_EXPORTS GeneralizedHoughBallard : public GeneralizedHough +{ +public: + //! R-Table levels. + virtual void setLevels(int levels) = 0; + virtual int getLevels() const = 0; + + //! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected. + virtual void setVotesThreshold(int votesThreshold) = 0; + virtual int getVotesThreshold() const = 0; +}; + +/** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform + +Detects position, translation and rotation @cite Guil1999 . +*/ +class CV_EXPORTS GeneralizedHoughGuil : public GeneralizedHough +{ +public: + //! Angle difference in degrees between two points in feature. + virtual void setXi(double xi) = 0; + virtual double getXi() const = 0; + + //! Feature table levels. + virtual void setLevels(int levels) = 0; + virtual int getLevels() const = 0; + + //! Maximal difference between angles that treated as equal. + virtual void setAngleEpsilon(double angleEpsilon) = 0; + virtual double getAngleEpsilon() const = 0; + + //! Minimal rotation angle to detect in degrees. + virtual void setMinAngle(double minAngle) = 0; + virtual double getMinAngle() const = 0; + + //! Maximal rotation angle to detect in degrees. + virtual void setMaxAngle(double maxAngle) = 0; + virtual double getMaxAngle() const = 0; + + //! Angle step in degrees. + virtual void setAngleStep(double angleStep) = 0; + virtual double getAngleStep() const = 0; + + //! Angle votes threshold. + virtual void setAngleThresh(int angleThresh) = 0; + virtual int getAngleThresh() const = 0; + + //! Minimal scale to detect. + virtual void setMinScale(double minScale) = 0; + virtual double getMinScale() const = 0; + + //! Maximal scale to detect. + virtual void setMaxScale(double maxScale) = 0; + virtual double getMaxScale() const = 0; + + //! Scale step. + virtual void setScaleStep(double scaleStep) = 0; + virtual double getScaleStep() const = 0; + + //! Scale votes threshold. + virtual void setScaleThresh(int scaleThresh) = 0; + virtual int getScaleThresh() const = 0; + + //! Position votes threshold. + virtual void setPosThresh(int posThresh) = 0; + virtual int getPosThresh() const = 0; +}; + +//! @} imgproc_shape + +//! @addtogroup imgproc_hist +//! @{ + +/** @brief Base class for Contrast Limited Adaptive Histogram Equalization. +*/ +class CV_EXPORTS_W CLAHE : public Algorithm +{ +public: + /** @brief Equalizes the histogram of a grayscale image using Contrast Limited Adaptive Histogram Equalization. + + @param src Source image of type CV_8UC1 or CV_16UC1. + @param dst Destination image. + */ + CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0; + + /** @brief Sets threshold for contrast limiting. + + @param clipLimit threshold value. + */ + CV_WRAP virtual void setClipLimit(double clipLimit) = 0; + + //! Returns threshold value for contrast limiting. + CV_WRAP virtual double getClipLimit() const = 0; + + /** @brief Sets size of grid for histogram equalization. Input image will be divided into + equally sized rectangular tiles. + + @param tileGridSize defines the number of tiles in row and column. + */ + CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0; + + //!@brief Returns Size defines the number of tiles in row and column. + CV_WRAP virtual Size getTilesGridSize() const = 0; + + CV_WRAP virtual void collectGarbage() = 0; +}; + +//! @} imgproc_hist + +//! @addtogroup imgproc_subdiv2d +//! @{ + +class CV_EXPORTS_W Subdiv2D +{ +public: + /** Subdiv2D point location cases */ + enum { PTLOC_ERROR = -2, //!< Point location error + PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect + PTLOC_INSIDE = 0, //!< Point inside some facet + PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices + PTLOC_ON_EDGE = 2 //!< Point on some edge + }; + + /** Subdiv2D edge type navigation (see: getEdge()) */ + enum { NEXT_AROUND_ORG = 0x00, + NEXT_AROUND_DST = 0x22, + PREV_AROUND_ORG = 0x11, + PREV_AROUND_DST = 0x33, + NEXT_AROUND_LEFT = 0x13, + NEXT_AROUND_RIGHT = 0x31, + PREV_AROUND_LEFT = 0x20, + PREV_AROUND_RIGHT = 0x02 + }; + + /** creates an empty Subdiv2D object. + To create a new empty Delaunay subdivision you need to use the #initDelaunay function. + */ + CV_WRAP Subdiv2D(); + + /** @overload + + @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision. + + The function creates an empty Delaunay subdivision where 2D points can be added using the function + insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime + error is raised. + */ + CV_WRAP Subdiv2D(Rect rect); + + /** @brief Creates a new empty Delaunay subdivision + + @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision. + + */ + CV_WRAP void initDelaunay(Rect rect); + + /** @brief Insert a single point into a Delaunay triangulation. + + @param pt Point to insert. + + The function inserts a single point into a subdivision and modifies the subdivision topology + appropriately. If a point with the same coordinates exists already, no new point is added. + @returns the ID of the point. + + @note If the point is outside of the triangulation specified rect a runtime error is raised. + */ + CV_WRAP int insert(Point2f pt); + + /** @brief Insert multiple points into a Delaunay triangulation. + + @param ptvec Points to insert. + + The function inserts a vector of points into a subdivision and modifies the subdivision topology + appropriately. + */ + CV_WRAP void insert(const std::vector<Point2f>& ptvec); + + /** @brief Returns the location of a point within a Delaunay triangulation. + + @param pt Point to locate. + @param edge Output edge that the point belongs to or is located to the right of it. + @param vertex Optional output vertex the input point coincides with. + + The function locates the input point within the subdivision and gives one of the triangle edges + or vertices. + + @returns an integer which specify one of the following five cases for point location: + - The point falls into some facet. The function returns #PTLOC_INSIDE and edge will contain one of + edges of the facet. + - The point falls onto the edge. The function returns #PTLOC_ON_EDGE and edge will contain this edge. + - The point coincides with one of the subdivision vertices. The function returns #PTLOC_VERTEX and + vertex will contain a pointer to the vertex. + - The point is outside the subdivision reference rectangle. The function returns #PTLOC_OUTSIDE_RECT + and no pointers are filled. + - One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error + processing mode is selected, #PTLOC_ERROR is returned. + */ + CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex); + + /** @brief Finds the subdivision vertex closest to the given point. + + @param pt Input point. + @param nearestPt Output subdivision vertex point. + + The function is another function that locates the input point within the subdivision. It finds the + subdivision vertex that is the closest to the input point. It is not necessarily one of vertices + of the facet containing the input point, though the facet (located using locate() ) is used as a + starting point. + + @returns vertex ID. + */ + CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0); + + /** @brief Returns a list of all edges. + + @param edgeList Output vector. + + The function gives each edge as a 4 numbers vector, where each two are one of the edge + vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3]. + */ + CV_WRAP void getEdgeList(CV_OUT std::vector<Vec4f>& edgeList) const; + + /** @brief Returns a list of the leading edge ID connected to each triangle. + + @param leadingEdgeList Output vector. + + The function gives one edge ID for each triangle. + */ + CV_WRAP void getLeadingEdgeList(CV_OUT std::vector<int>& leadingEdgeList) const; + + /** @brief Returns a list of all triangles. + + @param triangleList Output vector. + + The function gives each triangle as a 6 numbers vector, where each two are one of the triangle + vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5]. + */ + CV_WRAP void getTriangleList(CV_OUT std::vector<Vec6f>& triangleList) const; + + /** @brief Returns a list of all Voroni facets. + + @param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector. + @param facetList Output vector of the Voroni facets. + @param facetCenters Output vector of the Voroni facets center points. + + */ + CV_WRAP void getVoronoiFacetList(const std::vector<int>& idx, CV_OUT std::vector<std::vector<Point2f> >& facetList, + CV_OUT std::vector<Point2f>& facetCenters); + + /** @brief Returns vertex location from vertex ID. + + @param vertex vertex ID. + @param firstEdge Optional. The first edge ID which is connected to the vertex. + @returns vertex (x,y) + + */ + CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const; + + /** @brief Returns one of the edges related to the given edge. + + @param edge Subdivision edge ID. + @param nextEdgeType Parameter specifying which of the related edges to return. + The following values are possible: + - NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge) + - NEXT_AROUND_DST next around the edge vertex ( eDnext ) + - PREV_AROUND_ORG previous around the edge origin (reversed eRnext ) + - PREV_AROUND_DST previous around the edge destination (reversed eLnext ) + - NEXT_AROUND_LEFT next around the left facet ( eLnext ) + - NEXT_AROUND_RIGHT next around the right facet ( eRnext ) + - PREV_AROUND_LEFT previous around the left facet (reversed eOnext ) + - PREV_AROUND_RIGHT previous around the right facet (reversed eDnext ) + + ![sample output](pics/quadedge.png) + + @returns edge ID related to the input edge. + */ + CV_WRAP int getEdge( int edge, int nextEdgeType ) const; + + /** @brief Returns next edge around the edge origin. + + @param edge Subdivision edge ID. + + @returns an integer which is next edge ID around the edge origin: eOnext on the + picture above if e is the input edge). + */ + CV_WRAP int nextEdge(int edge) const; + + /** @brief Returns another edge of the same quad-edge. + + @param edge Subdivision edge ID. + @param rotate Parameter specifying which of the edges of the same quad-edge as the input + one to return. The following values are possible: + - 0 - the input edge ( e on the picture below if e is the input edge) + - 1 - the rotated edge ( eRot ) + - 2 - the reversed edge (reversed e (in green)) + - 3 - the reversed rotated edge (reversed eRot (in green)) + + @returns one of the edges ID of the same quad-edge as the input edge. + */ + CV_WRAP int rotateEdge(int edge, int rotate) const; + CV_WRAP int symEdge(int edge) const; + + /** @brief Returns the edge origin. + + @param edge Subdivision edge ID. + @param orgpt Output vertex location. + + @returns vertex ID. + */ + CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const; + + /** @brief Returns the edge destination. + + @param edge Subdivision edge ID. + @param dstpt Output vertex location. + + @returns vertex ID. + */ + CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const; + +protected: + int newEdge(); + void deleteEdge(int edge); + int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0); + void deletePoint(int vtx); + void setEdgePoints( int edge, int orgPt, int dstPt ); + void splice( int edgeA, int edgeB ); + int connectEdges( int edgeA, int edgeB ); + void swapEdges( int edge ); + int isRightOf(Point2f pt, int edge) const; + void calcVoronoi(); + void clearVoronoi(); + void checkSubdiv() const; + + struct CV_EXPORTS Vertex + { + Vertex(); + Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0); + bool isvirtual() const; + bool isfree() const; + + int firstEdge; + int type; + Point2f pt; + }; + + struct CV_EXPORTS QuadEdge + { + QuadEdge(); + QuadEdge(int edgeidx); + bool isfree() const; + + int next[4]; + int pt[4]; + }; + + //! All of the vertices + std::vector<Vertex> vtx; + //! All of the edges + std::vector<QuadEdge> qedges; + int freeQEdge; + int freePoint; + bool validGeometry; + + int recentEdge; + //! Top left corner of the bounding rect + Point2f topLeft; + //! Bottom right corner of the bounding rect + Point2f bottomRight; +}; + +//! @} imgproc_subdiv2d + +//! @addtogroup imgproc_feature +//! @{ + +/** @brief Line segment detector class + +following the algorithm described at @cite Rafael12 . + +@note Implementation has been removed due original code license conflict + +*/ +class CV_EXPORTS_W LineSegmentDetector : public Algorithm +{ +public: + + /** @brief Finds lines in the input image. + + This is the output of the default parameters of the algorithm on the above shown image. + + ![image](pics/building_lsd.png) + + @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: + `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);` + @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where + Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly + oriented depending on the gradient. + @param width Vector of widths of the regions, where the lines are found. E.g. Width of line. + @param prec Vector of precisions with which the lines are found. + @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The + bigger the value, logarithmically better the detection. + - -1 corresponds to 10 mean false alarms + - 0 corresponds to 1 mean false alarm + - 1 corresponds to 0.1 mean false alarms + This vector will be calculated only when the objects type is #LSD_REFINE_ADV. + */ + CV_WRAP virtual void detect(InputArray _image, OutputArray _lines, + OutputArray width = noArray(), OutputArray prec = noArray(), + OutputArray nfa = noArray()) = 0; + + /** @brief Draws the line segments on a given image. + @param _image The image, where the lines will be drawn. Should be bigger or equal to the image, + where the lines were found. + @param lines A vector of the lines that needed to be drawn. + */ + CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; + + /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels. + + @param size The size of the image, where lines1 and lines2 were found. + @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color. + @param lines2 The second group of lines. They visualized in red color. + @param _image Optional image, where the lines will be drawn. The image should be color(3-channel) + in order for lines1 and lines2 to be drawn in the above mentioned colors. + */ + CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; + + virtual ~LineSegmentDetector() { } +}; + +/** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it. + +The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want +to edit those, as to tailor it for their own application. + +@param _refine The way found lines will be refined, see #LineSegmentDetectorModes +@param _scale The scale of the image that will be used to find the lines. Range (0..1]. +@param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. +@param _quant Bound to the quantization error on the gradient norm. +@param _ang_th Gradient angle tolerance in degrees. +@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement +is chosen. +@param _density_th Minimal density of aligned region points in the enclosing rectangle. +@param _n_bins Number of bins in pseudo-ordering of gradient modulus. + +@note Implementation has been removed due original code license conflict + */ +CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector( + int _refine = LSD_REFINE_STD, double _scale = 0.8, + double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, + double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); + +//! @} imgproc_feature + +//! @addtogroup imgproc_filter +//! @{ + +/** @brief Returns Gaussian filter coefficients. + +The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter +coefficients: + +\f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f] + +where \f$i=0..\texttt{ksize}-1\f$ and \f$\alpha\f$ is the scale factor chosen so that \f$\sum_i G_i=1\f$. + +Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize +smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly. +You may also use the higher-level GaussianBlur. +@param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive. +@param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as +`sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`. +@param ktype Type of filter coefficients. It can be CV_32F or CV_64F . +@sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur + */ +CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F ); + +/** @brief Returns filter coefficients for computing spatial image derivatives. + +The function computes and returns the filter coefficients for spatial image derivatives. When +`ksize=CV_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see #Scharr). Otherwise, Sobel +kernels are generated (see #Sobel). The filters are normally passed to #sepFilter2D or to + +@param kx Output matrix of row filter coefficients. It has the type ktype . +@param ky Output matrix of column filter coefficients. It has the type ktype . +@param dx Derivative order in respect of x. +@param dy Derivative order in respect of y. +@param ksize Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7. +@param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not. +Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are +going to filter floating-point images, you are likely to use the normalized kernels. But if you +compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve +all the fractional bits, you may want to set normalize=false . +@param ktype Type of filter coefficients. It can be CV_32f or CV_64F . + */ +CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky, + int dx, int dy, int ksize, + bool normalize = false, int ktype = CV_32F ); + +/** @brief Returns Gabor filter coefficients. + +For more details about gabor filter equations and parameters, see: [Gabor +Filter](http://en.wikipedia.org/wiki/Gabor_filter). + +@param ksize Size of the filter returned. +@param sigma Standard deviation of the gaussian envelope. +@param theta Orientation of the normal to the parallel stripes of a Gabor function. +@param lambd Wavelength of the sinusoidal factor. +@param gamma Spatial aspect ratio. +@param psi Phase offset. +@param ktype Type of filter coefficients. It can be CV_32F or CV_64F . + */ +CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd, + double gamma, double psi = CV_PI*0.5, int ktype = CV_64F ); + +//! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation. +static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); } + +/** @brief Returns a structuring element of the specified size and shape for morphological operations. + +The function constructs and returns the structuring element that can be further passed to #erode, +#dilate or #morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as +the structuring element. + +@param shape Element shape that could be one of #MorphShapes +@param ksize Size of the structuring element. +@param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the +anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor +position. In other cases the anchor just regulates how much the result of the morphological +operation is shifted. + */ +CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1)); + +/** @example samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp +Sample code for simple filters +![Sample screenshot](Smoothing_Tutorial_Result_Median_Filter.jpg) +Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details + */ + +/** @brief Blurs an image using the median filter. + +The function smoothes an image using the median filter with the \f$\texttt{ksize} \times +\texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently. +In-place operation is supported. + +@note The median filter uses #BORDER_REPLICATE internally to cope with border pixels, see #BorderTypes + +@param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be +CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U. +@param dst destination array of the same size and type as src. +@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ... +@sa bilateralFilter, blur, boxFilter, GaussianBlur + */ +CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize ); + +/** @brief Blurs an image using a Gaussian filter. + +The function convolves the source image with the specified Gaussian kernel. In-place filtering is +supported. + +@param src input image; the image can have any number of channels, which are processed +independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be +positive and odd. Or, they can be zero's and then they are computed from sigma. +@param sigmaX Gaussian kernel standard deviation in X direction. +@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be +equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, +respectively (see #getGaussianKernel for details); to fully control the result regardless of +possible future modifications of all this semantics, it is recommended to specify all of ksize, +sigmaX, and sigmaY. +@param borderType pixel extrapolation method, see #BorderTypes + +@sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur + */ +CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize, + double sigmaX, double sigmaY = 0, + int borderType = BORDER_DEFAULT ); + +/** @brief Applies the bilateral filter to an image. + +The function applies bilateral filtering to the input image, as described in +http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html +bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is +very slow compared to most filters. + +_Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\< +10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very +strong effect, making the image look "cartoonish". + +_Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time +applications, and perhaps d=9 for offline applications that need heavy noise filtering. + +This filter does not work inplace. +@param src Source 8-bit or floating-point, 1-channel or 3-channel image. +@param dst Destination image of the same size and type as src . +@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, +it is computed from sigmaSpace. +@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that +farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting +in larger areas of semi-equal color. +@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that +farther pixels will influence each other as long as their colors are close enough (see sigmaColor +). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is +proportional to sigmaSpace. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes + */ +CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d, + double sigmaColor, double sigmaSpace, + int borderType = BORDER_DEFAULT ); + +/** @brief Blurs an image using the box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f] + +where + +\f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f] + +Unnormalized box filter is useful for computing various integral characteristics over each pixel +neighborhood, such as covariance matrices of image derivatives (used in dense optical flow +algorithms, and so on). If you need to compute pixel sums over variable-size windows, use #integral. + +@param src input image. +@param dst output image of the same size and type as src. +@param ddepth the output image depth (-1 to use src.depth()). +@param ksize blurring kernel size. +@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel +center. +@param normalize flag, specifying whether the kernel is normalized by its area or not. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@sa blur, bilateralFilter, GaussianBlur, medianBlur, integral + */ +CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth, + Size ksize, Point anchor = Point(-1,-1), + bool normalize = true, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter. + +For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring +pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$. + +The unnormalized square box filter can be useful in computing local image statistics such as the the local +variance and standard deviation around the neighborhood of a pixel. + +@param src input image +@param dst output image of the same size and type as _src +@param ddepth the output image depth (-1 to use src.depth()) +@param ksize kernel size +@param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel +center. +@param normalize flag, specifying whether the kernel is to be normalized by it's area or not. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@sa boxFilter +*/ +CV_EXPORTS_W void sqrBoxFilter( InputArray src, OutputArray dst, int ddepth, + Size ksize, Point anchor = Point(-1, -1), + bool normalize = true, + int borderType = BORDER_DEFAULT ); + +/** @brief Blurs an image using the normalized box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f] + +The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(), +anchor, true, borderType)`. + +@param src input image; it can have any number of channels, which are processed independently, but +the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param ksize blurring kernel size. +@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel +center. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@sa boxFilter, bilateralFilter, GaussianBlur, medianBlur + */ +CV_EXPORTS_W void blur( InputArray src, OutputArray dst, + Size ksize, Point anchor = Point(-1,-1), + int borderType = BORDER_DEFAULT ); + +/** @brief Convolves an image with the kernel. + +The function applies an arbitrary linear filter to an image. In-place operation is supported. When +the aperture is partially outside the image, the function interpolates outlier pixel values +according to the specified border mode. + +The function does actually compute correlation, not the convolution: + +\f[\texttt{dst} (x,y) = \sum _{ \stackrel{0\leq x' < \texttt{kernel.cols},}{0\leq y' < \texttt{kernel.rows}} } \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f] + +That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip +the kernel using #flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows - +anchor.y - 1)`. + +The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or +larger) and the direct algorithm for small kernels. + +@param src input image. +@param dst output image of the same size and the same number of channels as src. +@param ddepth desired depth of the destination image, see @ref filter_depths "combinations" +@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point +matrix; if you want to apply different kernels to different channels, split the image into +separate color planes using split and process them individually. +@param anchor anchor of the kernel that indicates the relative position of a filtered point within +the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor +is at the kernel center. +@param delta optional value added to the filtered pixels before storing them in dst. +@param borderType pixel extrapolation method, see #BorderTypes +@sa sepFilter2D, dft, matchTemplate + */ +CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth, + InputArray kernel, Point anchor = Point(-1,-1), + double delta = 0, int borderType = BORDER_DEFAULT ); + +/** @brief Applies a separable linear filter to an image. + +The function applies a separable linear filter to the image. That is, first, every row of src is +filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D +kernel kernelY. The final result shifted by delta is stored in dst . + +@param src Source image. +@param dst Destination image of the same size and the same number of channels as src . +@param ddepth Destination image depth, see @ref filter_depths "combinations" +@param kernelX Coefficients for filtering each row. +@param kernelY Coefficients for filtering each column. +@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor +is at the kernel center. +@param delta Value added to the filtered results before storing them. +@param borderType Pixel extrapolation method, see #BorderTypes +@sa filter2D, Sobel, GaussianBlur, boxFilter, blur + */ +CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth, + InputArray kernelX, InputArray kernelY, + Point anchor = Point(-1,-1), + double delta = 0, int borderType = BORDER_DEFAULT ); + +/** @example samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp +Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector +![Sample screenshot](Sobel_Derivatives_Tutorial_Result.jpg) +Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details +*/ + +/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. + +In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to +calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ +kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first +or the second x- or y- derivatives. + +There is also the special value `ksize = #CV_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is + +\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] + +for the x-derivative, or transposed for the y-derivative. + +The function calculates an image derivative by convolving the image with the appropriate kernel: + +\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] + +The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less +resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) +or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first +case corresponds to a kernel of: + +\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] + +The second case corresponds to a kernel of: + +\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] + +@param src input image. +@param dst output image of the same size and the same number of channels as src . +@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of + 8-bit input images it will result in truncated derivatives. +@param dx order of the derivative x. +@param dy order of the derivative y. +@param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see #getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see #BorderTypes +@sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar + */ +CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth, + int dx, int dy, int ksize = 3, + double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates the first order image derivative in both x and y using a Sobel operator + +Equivalent to calling: + +@code +Sobel( src, dx, CV_16SC1, 1, 0, 3 ); +Sobel( src, dy, CV_16SC1, 0, 1, 3 ); +@endcode + +@param src input image. +@param dx output image with first-order derivative in x. +@param dy output image with first-order derivative in y. +@param ksize size of Sobel kernel. It must be 3. +@param borderType pixel extrapolation method, see #BorderTypes + +@sa Sobel + */ + +CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx, + OutputArray dy, int ksize = 3, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates the first x- or y- image derivative using Scharr operator. + +The function computes the first x- or y- spatial image derivative using the Scharr operator. The +call + +\f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f] + +is equivalent to + +\f[\texttt{Sobel(src, dst, ddepth, dx, dy, CV_SCHARR, scale, delta, borderType)} .\f] + +@param src input image. +@param dst output image of the same size and the same number of channels as src. +@param ddepth output image depth, see @ref filter_depths "combinations" +@param dx order of the derivative x. +@param dy order of the derivative y. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see #getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see #BorderTypes +@sa cartToPolar + */ +CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth, + int dx, int dy, double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT ); + +/** @example samples/cpp/laplace.cpp +An example using Laplace transformations for edge detection +*/ + +/** @brief Calculates the Laplacian of an image. + +The function calculates the Laplacian of the source image by adding up the second x and y +derivatives calculated using the Sobel operator: + +\f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f] + +This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image +with the following \f$3 \times 3\f$ aperture: + +\f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f] + +@param src Source image. +@param dst Destination image of the same size and the same number of channels as src . +@param ddepth Desired depth of the destination image. +@param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for +details. The size must be positive and odd. +@param scale Optional scale factor for the computed Laplacian values. By default, no scaling is +applied. See #getDerivKernels for details. +@param delta Optional delta value that is added to the results prior to storing them in dst . +@param borderType Pixel extrapolation method, see #BorderTypes +@sa Sobel, Scharr + */ +CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth, + int ksize = 1, double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT ); + +//! @} imgproc_filter + +//! @addtogroup imgproc_feature +//! @{ + +/** @example samples/cpp/edge.cpp +This program demonstrates usage of the Canny edge detector + +Check @ref tutorial_canny_detector "the corresponding tutorial" for more details +*/ + +/** @brief Finds edges in an image using the Canny algorithm @cite Canny86 . + +The function finds edges in the input image and marks them in the output map edges using the +Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The +largest value is used to find initial segments of strong edges. See +<http://en.wikipedia.org/wiki/Canny_edge_detector> + +@param image 8-bit input image. +@param edges output edge map; single channels 8-bit image, which has the same size as image . +@param threshold1 first threshold for the hysteresis procedure. +@param threshold2 second threshold for the hysteresis procedure. +@param apertureSize aperture size for the Sobel operator. +@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm +\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( +L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( +L2gradient=false ). + */ +CV_EXPORTS_W void Canny( InputArray image, OutputArray edges, + double threshold1, double threshold2, + int apertureSize = 3, bool L2gradient = false ); + +/** \overload + +Finds edges in an image using the Canny algorithm with custom image gradient. + +@param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3). +@param dy 16-bit y derivative of input image (same type as dx). +@param edges output edge map; single channels 8-bit image, which has the same size as image . +@param threshold1 first threshold for the hysteresis procedure. +@param threshold2 second threshold for the hysteresis procedure. +@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm +\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( +L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( +L2gradient=false ). + */ +CV_EXPORTS_W void Canny( InputArray dx, InputArray dy, + OutputArray edges, + double threshold1, double threshold2, + bool L2gradient = false ); + +/** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection. + +The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal +eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms +of the formulae in the cornerEigenValsAndVecs description. + +@param src Input single-channel 8-bit or floating-point image. +@param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as +src . +@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ). +@param ksize Aperture parameter for the Sobel operator. +@param borderType Pixel extrapolation method. See #BorderTypes. + */ +CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst, + int blockSize, int ksize = 3, + int borderType = BORDER_DEFAULT ); + +/** @brief Harris corner detector. + +The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and +cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance +matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it +computes the following characteristic: + +\f[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f] + +Corners in the image can be found as the local maxima of this response map. + +@param src Input single-channel 8-bit or floating-point image. +@param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same +size as src . +@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ). +@param ksize Aperture parameter for the Sobel operator. +@param k Harris detector free parameter. See the formula above. +@param borderType Pixel extrapolation method. See #BorderTypes. + */ +CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize, + int ksize, double k, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection. + +For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize +neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as: + +\f[M = \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 & \sum _{S(p)}dI/dx dI/dy \\ \sum _{S(p)}dI/dx dI/dy & \sum _{S(p)}(dI/dy)^2 \end{bmatrix}\f] + +where the derivatives are computed using the Sobel operator. + +After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as +\f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where + +- \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$ +- \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$ +- \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$ + +The output of the function can be used for robust edge or corner detection. + +@param src Input single-channel 8-bit or floating-point image. +@param dst Image to store the results. It has the same size as src and the type CV_32FC(6) . +@param blockSize Neighborhood size (see details below). +@param ksize Aperture parameter for the Sobel operator. +@param borderType Pixel extrapolation method. See #BorderTypes. + +@sa cornerMinEigenVal, cornerHarris, preCornerDetect + */ +CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst, + int blockSize, int ksize, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates a feature map for corner detection. + +The function calculates the complex spatial derivative-based function of the source image + +\f[\texttt{dst} = (D_x \texttt{src} )^2 \cdot D_{yy} \texttt{src} + (D_y \texttt{src} )^2 \cdot D_{xx} \texttt{src} - 2 D_x \texttt{src} \cdot D_y \texttt{src} \cdot D_{xy} \texttt{src}\f] + +where \f$D_x\f$,\f$D_y\f$ are the first image derivatives, \f$D_{xx}\f$,\f$D_{yy}\f$ are the second image +derivatives, and \f$D_{xy}\f$ is the mixed derivative. + +The corners can be found as local maximums of the functions, as shown below: +@code + Mat corners, dilated_corners; + preCornerDetect(image, corners, 3); + // dilation with 3x3 rectangular structuring element + dilate(corners, dilated_corners, Mat(), 1); + Mat corner_mask = corners == dilated_corners; +@endcode + +@param src Source single-channel 8-bit of floating-point image. +@param dst Output image that has the type CV_32F and the same size as src . +@param ksize %Aperture size of the Sobel . +@param borderType Pixel extrapolation method. See #BorderTypes. + */ +CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize, + int borderType = BORDER_DEFAULT ); + +/** @brief Refines the corner locations. + +The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as +shown on the figure below. + +![image](pics/cornersubpix.png) + +Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$ +to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$ +subject to image and measurement noise. Consider the expression: + +\f[\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)\f] + +where \f${DI_{p_i}}\f$ is an image gradient at one of the points \f$p_i\f$ in a neighborhood of \f$q\f$ . The +value of \f$q\f$ is to be found so that \f$\epsilon_i\f$ is minimized. A system of equations may be set up +with \f$\epsilon_i\f$ set to zero: + +\f[\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) \cdot q - \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)\f] + +where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first +gradient term \f$G\f$ and the second gradient term \f$b\f$ gives: + +\f[q = G^{-1} \cdot b\f] + +The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates +until the center stays within a set threshold. + +@param image Input single-channel, 8-bit or float image. +@param corners Initial coordinates of the input corners and refined coordinates provided for +output. +@param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) , +then a \f$(5*2+1) \times (5*2+1) = 11 \times 11\f$ search window is used. +@param zeroZone Half of the size of the dead region in the middle of the search zone over which +the summation in the formula below is not done. It is used sometimes to avoid possible +singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such +a size. +@param criteria Criteria for termination of the iterative process of corner refinement. That is, +the process of corner position refinement stops either after criteria.maxCount iterations or when +the corner position moves by less than criteria.epsilon on some iteration. + */ +CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners, + Size winSize, Size zeroZone, + TermCriteria criteria ); + +/** @brief Determines strong corners on an image. + +The function finds the most prominent corners in the image or in the specified image region, as +described in @cite Shi94 + +- Function calculates the corner quality measure at every source image pixel using the + #cornerMinEigenVal or #cornerHarris . +- Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are + retained). +- The corners with the minimal eigenvalue less than + \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected. +- The remaining corners are sorted by the quality measure in the descending order. +- Function throws away each corner for which there is a stronger corner at a distance less than + maxDistance. + +The function can be used to initialize a point-based tracker of an object. + +@note If the function is called with different values A and B of the parameter qualityLevel , and +A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector +with qualityLevel=B . + +@param image Input 8-bit or floating-point 32-bit, single-channel image. +@param corners Output vector of detected corners. +@param maxCorners Maximum number of corners to return. If there are more corners than are found, +the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set +and all detected corners are returned. +@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The +parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue +(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the +quality measure less than the product are rejected. For example, if the best corner has the +quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure +less than 15 are rejected. +@param minDistance Minimum possible Euclidean distance between the returned corners. +@param mask Optional region of interest. If the image is not empty (it needs to have the type +CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected. +@param blockSize Size of an average block for computing a derivative covariation matrix over each +pixel neighborhood. See cornerEigenValsAndVecs . +@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris) +or #cornerMinEigenVal. +@param k Free parameter of the Harris detector. + +@sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform, + */ + +CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, + int maxCorners, double qualityLevel, double minDistance, + InputArray mask = noArray(), int blockSize = 3, + bool useHarrisDetector = false, double k = 0.04 ); + +CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, + int maxCorners, double qualityLevel, double minDistance, + InputArray mask, int blockSize, + int gradientSize, bool useHarrisDetector = false, + double k = 0.04 ); +/** @example samples/cpp/tutorial_code/ImgTrans/houghlines.cpp +An example using the Hough line detector +![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg) +*/ + +/** @brief Finds lines in a binary image using the standard Hough transform. + +The function implements the standard or standard multi-scale Hough transform algorithm for line +detection. See <http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm> for a good explanation of Hough +transform. + +@param image 8-bit, single-channel binary source image. The image may be modified by the function. +@param lines Output vector of lines. Each line is represented by a 2 or 3 element vector +\f$(\rho, \theta)\f$ or \f$(\rho, \theta, \textrm{votes})\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of +the image). \f$\theta\f$ is the line rotation angle in radians ( +\f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ). +\f$\textrm{votes}\f$ is the value of accumulator. +@param rho Distance resolution of the accumulator in pixels. +@param theta Angle resolution of the accumulator in radians. +@param threshold Accumulator threshold parameter. Only those lines are returned that get enough +votes ( \f$>\texttt{threshold}\f$ ). +@param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho . +The coarse accumulator distance resolution is rho and the accurate accumulator resolution is +rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these +parameters should be positive. +@param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta. +@param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines. +Must fall between 0 and max_theta. +@param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines. +Must fall between min_theta and CV_PI. + */ +CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines, + double rho, double theta, int threshold, + double srn = 0, double stn = 0, + double min_theta = 0, double max_theta = CV_PI ); + +/** @brief Finds line segments in a binary image using the probabilistic Hough transform. + +The function implements the probabilistic Hough transform algorithm for line detection, described +in @cite Matas00 + +See the line detection example below: +@include snippets/imgproc_HoughLinesP.cpp +This is a sample picture the function parameters have been tuned for: + +![image](pics/building.jpg) + +And this is the output of the above program in case of the probabilistic Hough transform: + +![image](pics/houghp.png) + +@param image 8-bit, single-channel binary source image. The image may be modified by the function. +@param lines Output vector of lines. Each line is represented by a 4-element vector +\f$(x_1, y_1, x_2, y_2)\f$ , where \f$(x_1,y_1)\f$ and \f$(x_2, y_2)\f$ are the ending points of each detected +line segment. +@param rho Distance resolution of the accumulator in pixels. +@param theta Angle resolution of the accumulator in radians. +@param threshold Accumulator threshold parameter. Only those lines are returned that get enough +votes ( \f$>\texttt{threshold}\f$ ). +@param minLineLength Minimum line length. Line segments shorter than that are rejected. +@param maxLineGap Maximum allowed gap between points on the same line to link them. + +@sa LineSegmentDetector + */ +CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines, + double rho, double theta, int threshold, + double minLineLength = 0, double maxLineGap = 0 ); + +/** @brief Finds lines in a set of points using the standard Hough transform. + +The function finds lines in a set of points using a modification of the Hough transform. +@include snippets/imgproc_HoughLinesPointSet.cpp +@param _point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. +@param _lines Output vector of found lines. Each vector is encoded as a vector<Vec3d> \f$(votes, rho, theta)\f$. +The larger the value of 'votes', the higher the reliability of the Hough line. +@param lines_max Max count of hough lines. +@param threshold Accumulator threshold parameter. Only those lines are returned that get enough +votes ( \f$>\texttt{threshold}\f$ ) +@param min_rho Minimum Distance value of the accumulator in pixels. +@param max_rho Maximum Distance value of the accumulator in pixels. +@param rho_step Distance resolution of the accumulator in pixels. +@param min_theta Minimum angle value of the accumulator in radians. +@param max_theta Maximum angle value of the accumulator in radians. +@param theta_step Angle resolution of the accumulator in radians. + */ +CV_EXPORTS_W void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, int threshold, + double min_rho, double max_rho, double rho_step, + double min_theta, double max_theta, double theta_step ); + +/** @example samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp +An example using the Hough circle detector +*/ + +/** @brief Finds circles in a grayscale image using the Hough transform. + +The function finds circles in a grayscale image using a modification of the Hough transform. + +Example: : +@include snippets/imgproc_HoughLinesCircles.cpp + +@note Usually the function detects the centers of circles well. However, it may fail to find correct +radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if +you know it. Or, you may set maxRadius to a negative number to return centers only without radius +search, and find the correct radius using an additional procedure. + +@param image 8-bit, single-channel, grayscale input image. +@param circles Output vector of found circles. Each vector is encoded as 3 or 4 element +floating-point vector \f$(x, y, radius)\f$ or \f$(x, y, radius, votes)\f$ . +@param method Detection method, see #HoughModes. Currently, the only implemented method is #HOUGH_GRADIENT +@param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if +dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has +half as big width and height. +@param minDist Minimum distance between the centers of the detected circles. If the parameter is +too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is +too large, some circles may be missed. +@param param1 First method-specific parameter. In case of #HOUGH_GRADIENT , it is the higher +threshold of the two passed to the Canny edge detector (the lower one is twice smaller). +@param param2 Second method-specific parameter. In case of #HOUGH_GRADIENT , it is the +accumulator threshold for the circle centers at the detection stage. The smaller it is, the more +false circles may be detected. Circles, corresponding to the larger accumulator values, will be +returned first. +@param minRadius Minimum circle radius. +@param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, returns +centers without finding the radius. + +@sa fitEllipse, minEnclosingCircle + */ +CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles, + int method, double dp, double minDist, + double param1 = 100, double param2 = 100, + int minRadius = 0, int maxRadius = 0 ); + +//! @} imgproc_feature + +//! @addtogroup imgproc_filter +//! @{ + +/** @example samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp +Advanced morphology Transformations sample code +![Sample screenshot](Morphology_2_Tutorial_Result.jpg) +Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details +*/ + +/** @brief Erodes an image by using a specific structuring element. + +The function erodes the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the minimum is taken: + +\f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In +case of multi-channel images, each channel is processed independently. + +@param src input image; the number of channels can be arbitrary, but the depth should be one of +CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular +structuring element is used. Kernel can be created using #getStructuringElement. +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times erosion is applied. +@param borderType pixel extrapolation method, see #BorderTypes +@param borderValue border value in case of a constant border +@sa dilate, morphologyEx, getStructuringElement + */ +CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, + Point anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue() ); + +/** @example samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp +Erosion and Dilation sample code +![Sample Screenshot-Erosion](Morphology_1_Tutorial_Erosion_Result.jpg)![Sample Screenshot-Dilation](Morphology_1_Tutorial_Dilation_Result.jpg) +Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details +*/ + +/** @brief Dilates an image by using a specific structuring element. + +The function dilates the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the maximum is taken: +\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In +case of multi-channel images, each channel is processed independently. + +@param src input image; the number of channels can be arbitrary, but the depth should be one of +CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular +structuring element is used. Kernel can be created using #getStructuringElement +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times dilation is applied. +@param borderType pixel extrapolation method, see #BorderTypes +@param borderValue border value in case of a constant border +@sa erode, morphologyEx, getStructuringElement + */ +CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel, + Point anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue() ); + +/** @brief Performs advanced morphological transformations. + +The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as +basic operations. + +Any of the operations can be done in-place. In case of multi-channel images, each channel is +processed independently. + +@param src Source image. The number of channels can be arbitrary. The depth should be one of +CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst Destination image of the same size and type as source image. +@param op Type of a morphological operation, see #MorphTypes +@param kernel Structuring element. It can be created using #getStructuringElement. +@param anchor Anchor position with the kernel. Negative values mean that the anchor is at the +kernel center. +@param iterations Number of times erosion and dilation are applied. +@param borderType Pixel extrapolation method, see #BorderTypes +@param borderValue Border value in case of a constant border. The default value has a special +meaning. +@sa dilate, erode, getStructuringElement +@note The number of iterations is the number of times erosion or dilatation operation will be applied. +For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply +successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate). + */ +CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst, + int op, InputArray kernel, + Point anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue() ); + +//! @} imgproc_filter + +//! @addtogroup imgproc_transform +//! @{ + +/** @brief Resizes an image. + +The function resize resizes the image src down to or up to the specified size. Note that the +initial dst type or size are not taken into account. Instead, the size and type are derived from +the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst, +you may call the function as follows: +@code + // explicitly specify dsize=dst.size(); fx and fy will be computed from that. + resize(src, dst, dst.size(), 0, 0, interpolation); +@endcode +If you want to decimate the image by factor of 2 in each direction, you can call the function this +way: +@code + // specify fx and fy and let the function compute the destination image size. + resize(src, dst, Size(), 0.5, 0.5, interpolation); +@endcode +To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to +enlarge an image, it will generally look best with c#INTER_CUBIC (slow) or #INTER_LINEAR +(faster but still looks OK). + +@param src input image. +@param dst output image; it has the size dsize (when it is non-zero) or the size computed from +src.size(), fx, and fy; the type of dst is the same as of src. +@param dsize output image size; if it equals zero, it is computed as: + \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f] + Either dsize or both fx and fy must be non-zero. +@param fx scale factor along the horizontal axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.width/src.cols}\f] +@param fy scale factor along the vertical axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.height/src.rows}\f] +@param interpolation interpolation method, see #InterpolationFlags + +@sa warpAffine, warpPerspective, remap + */ +CV_EXPORTS_W void resize( InputArray src, OutputArray dst, + Size dsize, double fx = 0, double fy = 0, + int interpolation = INTER_LINEAR ); + +/** @brief Applies an affine transformation to an image. + +The function warpAffine transforms the source image using the specified matrix: + +\f[\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})\f] + +when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted +with #invertAffineTransform and then put in the formula above instead of M. The function cannot +operate in-place. + +@param src input image. +@param dst output image that has the size dsize and the same type as src . +@param M \f$2\times 3\f$ transformation matrix. +@param dsize size of the output image. +@param flags combination of interpolation methods (see #InterpolationFlags) and the optional +flag #WARP_INVERSE_MAP that means that M is the inverse transformation ( +\f$\texttt{dst}\rightarrow\texttt{src}\f$ ). +@param borderMode pixel extrapolation method (see #BorderTypes); when +borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to +the "outliers" in the source image are not modified by the function. +@param borderValue value used in case of a constant border; by default, it is 0. + +@sa warpPerspective, resize, remap, getRectSubPix, transform + */ +CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst, + InputArray M, Size dsize, + int flags = INTER_LINEAR, + int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @example samples/cpp/warpPerspective_demo.cpp +An example program shows using cv::findHomography and cv::warpPerspective for image warping +*/ + +/** @brief Applies a perspective transformation to an image. + +The function warpPerspective transforms the source image using the specified matrix: + +\f[\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} , + \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f] + +when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert +and then put in the formula above instead of M. The function cannot operate in-place. + +@param src input image. +@param dst output image that has the size dsize and the same type as src . +@param M \f$3\times 3\f$ transformation matrix. +@param dsize size of the output image. +@param flags combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the +optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation ( +\f$\texttt{dst}\rightarrow\texttt{src}\f$ ). +@param borderMode pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE). +@param borderValue value used in case of a constant border; by default, it equals 0. + +@sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform + */ +CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst, + InputArray M, Size dsize, + int flags = INTER_LINEAR, + int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @brief Applies a generic geometrical transformation to an image. + +The function remap transforms the source image using the specified map: + +\f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f] + +where values of pixels with non-integer coordinates are computed using one of available +interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps +in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in +\f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to +convert from floating to fixed-point representations of a map is that they can yield much faster +(\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x), +cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients. + +This function cannot operate in-place. + +@param src Source image. +@param dst Destination image. It has the same size as map1 and the same type as src . +@param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 , +CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point +representation to fixed-point for speed. +@param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map +if map1 is (x,y) points), respectively. +@param interpolation Interpolation method (see #InterpolationFlags). The method #INTER_AREA is +not supported by this function. +@param borderMode Pixel extrapolation method (see #BorderTypes). When +borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image that +corresponds to the "outliers" in the source image are not modified by the function. +@param borderValue Value used in case of a constant border. By default, it is 0. +@note +Due to current implementation limitations the size of an input and output images should be less than 32767x32767. + */ +CV_EXPORTS_W void remap( InputArray src, OutputArray dst, + InputArray map1, InputArray map2, + int interpolation, int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @brief Converts image transformation maps from one representation to another. + +The function converts a pair of maps for remap from one representation to another. The following +options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are +supported: + +- \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the +most frequently used conversion operation, in which the original floating-point maps (see remap ) +are converted to a more compact and much faster fixed-point representation. The first output array +contains the rounded coordinates and the second array (created only when nninterpolation=false ) +contains indices in the interpolation tables. + +- \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but +the original maps are stored in one 2-channel matrix. + +- Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same +as the originals. + +@param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 . +@param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix), +respectively. +@param dstmap1 The first output map that has the type dstmap1type and the same size as src . +@param dstmap2 The second output map. +@param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or +CV_32FC2 . +@param nninterpolation Flag indicating whether the fixed-point maps are used for the +nearest-neighbor or for a more complex interpolation. + +@sa remap, undistort, initUndistortRectifyMap + */ +CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2, + OutputArray dstmap1, OutputArray dstmap2, + int dstmap1type, bool nninterpolation = false ); + +/** @brief Calculates an affine matrix of 2D rotation. + +The function calculates the following matrix: + +\f[\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} + (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}\f] + +where + +\f[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f] + +The transformation maps the rotation center to itself. If this is not the target, adjust the shift. + +@param center Center of the rotation in the source image. +@param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the +coordinate origin is assumed to be the top-left corner). +@param scale Isotropic scale factor. + +@sa getAffineTransform, warpAffine, transform + */ +CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale ); + +//! returns 3x3 perspective transformation for the corresponding 4 point pairs. +CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] ); + +/** @brief Calculates an affine transform from three pairs of the corresponding points. + +The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that: + +\f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] + +where + +\f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f] + +@param src Coordinates of triangle vertices in the source image. +@param dst Coordinates of the corresponding triangle vertices in the destination image. + +@sa warpAffine, transform + */ +CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] ); + +/** @brief Inverts an affine transformation. + +The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M: + +\f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f] + +The result is also a \f$2 \times 3\f$ matrix of the same type as M. + +@param M Original affine transformation. +@param iM Output reverse affine transformation. + */ +CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM ); + +/** @brief Calculates a perspective transform from four pairs of the corresponding points. + +The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that: + +\f[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] + +where + +\f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f] + +@param src Coordinates of quadrangle vertices in the source image. +@param dst Coordinates of the corresponding quadrangle vertices in the destination image. + +@sa findHomography, warpPerspective, perspectiveTransform + */ +CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst ); + +CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst ); + +/** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy. + +The function getRectSubPix extracts pixels from src: + +\f[patch(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f] + +where the values of the pixels at non-integer coordinates are retrieved using bilinear +interpolation. Every channel of multi-channel images is processed independently. Also +the image should be a single channel or three channel image. While the center of the +rectangle must be inside the image, parts of the rectangle may be outside. + +@param image Source image. +@param patchSize Size of the extracted patch. +@param center Floating point coordinates of the center of the extracted rectangle within the +source image. The center must be inside the image. +@param patch Extracted patch that has the size patchSize and the same number of channels as src . +@param patchType Depth of the extracted pixels. By default, they have the same depth as src . + +@sa warpAffine, warpPerspective + */ +CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize, + Point2f center, OutputArray patch, int patchType = -1 ); + +/** @example samples/cpp/polar_transforms.cpp +An example using the cv::linearPolar and cv::logPolar operations +*/ + +/** @brief Remaps an image to semilog-polar coordinates space. + +@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags+WARP_POLAR_LOG); + +@internal +Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image d)"): +\f[\begin{array}{l} + dst( \rho , \phi ) = src(x,y) \\ + dst.size() \leftarrow src.size() +\end{array}\f] + +where +\f[\begin{array}{l} + I = (dx,dy) = (x - center.x,y - center.y) \\ + \rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\ + \phi = Kangle \cdot \texttt{angle} (I) \\ +\end{array}\f] + +and +\f[\begin{array}{l} + M = src.cols / log_e(maxRadius) \\ + Kangle = src.rows / 2\Pi \\ +\end{array}\f] + +The function emulates the human "foveal" vision and can be used for fast scale and +rotation-invariant template matching, for object tracking and so forth. +@param src Source image +@param dst Destination image. It will have same size and type as src. +@param center The transformation center; where the output precision is maximal +@param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too. +@param flags A combination of interpolation methods, see #InterpolationFlags + +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. + +@sa cv::linearPolar +@endinternal +*/ +CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst, + Point2f center, double M, int flags ); + +/** @brief Remaps an image to polar coordinates space. + +@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags) + +@internal +Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image c)"): +\f[\begin{array}{l} + dst( \rho , \phi ) = src(x,y) \\ + dst.size() \leftarrow src.size() +\end{array}\f] + +where +\f[\begin{array}{l} + I = (dx,dy) = (x - center.x,y - center.y) \\ + \rho = Kmag \cdot \texttt{magnitude} (I) ,\\ + \phi = angle \cdot \texttt{angle} (I) +\end{array}\f] + +and +\f[\begin{array}{l} + Kx = src.cols / maxRadius \\ + Ky = src.rows / 2\Pi +\end{array}\f] + + +@param src Source image +@param dst Destination image. It will have same size and type as src. +@param center The transformation center; +@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too. +@param flags A combination of interpolation methods, see #InterpolationFlags + +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. + +@sa cv::logPolar +@endinternal +*/ +CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst, + Point2f center, double maxRadius, int flags ); + + +/** \brief Remaps an image to polar or semilog-polar coordinates space + +@anchor polar_remaps_reference_image +![Polar remaps reference](pics/polar_remap_doc.png) + +Transform the source image using the following transformation: +\f[ +dst(\rho , \phi ) = src(x,y) +\f] + +where +\f[ +\begin{array}{l} +\vec{I} = (x - center.x, \;y - center.y) \\ +\phi = Kangle \cdot \texttt{angle} (\vec{I}) \\ +\rho = \left\{\begin{matrix} +Klin \cdot \texttt{magnitude} (\vec{I}) & default \\ +Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\ +\end{matrix}\right. +\end{array} +\f] + +and +\f[ +\begin{array}{l} +Kangle = dsize.height / 2\Pi \\ +Klin = dsize.width / maxRadius \\ +Klog = dsize.width / log_e(maxRadius) \\ +\end{array} +\f] + + +\par Linear vs semilog mapping + +Polar mapping can be linear or semi-log. Add one of #WarpPolarMode to `flags` to specify the polar mapping mode. + +Linear is the default mode. + +The semilog mapping emulates the human "foveal" vision that permit very high acuity on the line of sight (central vision) +in contrast to peripheral vision where acuity is minor. + +\par Option on `dsize`: + +- if both values in `dsize <=0 ` (default), +the destination image will have (almost) same area of source bounding circle: +\f[\begin{array}{l} +dsize.area \leftarrow (maxRadius^2 \cdot \Pi) \\ +dsize.width = \texttt{cvRound}(maxRadius) \\ +dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\ +\end{array}\f] + + +- if only `dsize.height <= 0`, +the destination image area will be proportional to the bounding circle area but scaled by `Kx * Kx`: +\f[\begin{array}{l} +dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\ +\end{array} +\f] + +- if both values in `dsize > 0 `, +the destination image will have the given size therefore the area of the bounding circle will be scaled to `dsize`. + + +\par Reverse mapping + +You can get reverse mapping adding #WARP_INVERSE_MAP to `flags` +\snippet polar_transforms.cpp InverseMap + +In addiction, to calculate the original coordinate from a polar mapped coordinate \f$(rho, phi)->(x, y)\f$: +\snippet polar_transforms.cpp InverseCoordinate + +@param src Source image. +@param dst Destination image. It will have same type as src. +@param dsize The destination image size (see description for valid options). +@param center The transformation center. +@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too. +@param flags A combination of interpolation methods, #InterpolationFlags + #WarpPolarMode. + - Add #WARP_POLAR_LINEAR to select linear polar mapping (default) + - Add #WARP_POLAR_LOG to select semilog polar mapping + - Add #WARP_INVERSE_MAP for reverse mapping. +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. +- This function uses #remap. Due to current implementation limitations the size of an input and output images should be less than 32767x32767. + +@sa cv::remap +*/ +CV_EXPORTS_W void warpPolar(InputArray src, OutputArray dst, Size dsize, + Point2f center, double maxRadius, int flags); + + +//! @} imgproc_transform + +//! @addtogroup imgproc_misc +//! @{ + +/** @overload */ +CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 ); + +/** @overload */ +CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum, + OutputArray sqsum, int sdepth = -1, int sqdepth = -1 ); + +/** @brief Calculates the integral of an image. + +The function calculates one or more integral images for the source image as follows: + +\f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f] + +\f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f] + +\f[\texttt{tilted} (X,Y) = \sum _{y<Y,abs(x-X+1) \leq Y-y-1} \texttt{image} (x,y)\f] + +Using these integral images, you can calculate sum, mean, and standard deviation over a specific +up-right or rotated rectangular region of the image in a constant time, for example: + +\f[\sum _{x_1 \leq x < x_2, \, y_1 \leq y < y_2} \texttt{image} (x,y) = \texttt{sum} (x_2,y_2)- \texttt{sum} (x_1,y_2)- \texttt{sum} (x_2,y_1)+ \texttt{sum} (x_1,y_1)\f] + +It makes possible to do a fast blurring or fast block correlation with a variable window size, for +example. In case of multi-channel images, sums for each channel are accumulated independently. + +As a practical example, the next figure shows the calculation of the integral of a straight +rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the +original image are shown, as well as the relative pixels in the integral images sum and tilted . + +![integral calculation example](pics/integral.png) + +@param src input image as \f$W \times H\f$, 8-bit or floating-point (32f or 64f). +@param sum integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f). +@param sqsum integral image for squared pixel values; it is \f$(W+1)\times (H+1)\f$, double-precision +floating-point (64f) array. +@param tilted integral for the image rotated by 45 degrees; it is \f$(W+1)\times (H+1)\f$ array with +the same data type as sum. +@param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or +CV_64F. +@param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F. + */ +CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum, + OutputArray sqsum, OutputArray tilted, + int sdepth = -1, int sqdepth = -1 ); + +//! @} imgproc_misc + +//! @addtogroup imgproc_motion +//! @{ + +/** @brief Adds an image to the accumulator image. + +The function adds src or some of its elements to dst : + +\f[\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f] + +The function supports multi-channel images. Each channel is processed independently. + +The function cv::accumulate can be used, for example, to collect statistics of a scene background +viewed by a still camera and for the further foreground-background segmentation. + +@param src Input image of type CV_8UC(n), CV_16UC(n), CV_32FC(n) or CV_64FC(n), where n is a positive integer. +@param dst %Accumulator image with the same number of channels as input image, and a depth of CV_32F or CV_64F. +@param mask Optional operation mask. + +@sa accumulateSquare, accumulateProduct, accumulateWeighted + */ +CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst, + InputArray mask = noArray() ); + +/** @brief Adds the square of a source image to the accumulator image. + +The function adds the input image src or its selected region, raised to a power of 2, to the +accumulator dst : + +\f[\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src} (x,y)^2 \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f] + +The function supports multi-channel images. Each channel is processed independently. + +@param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point. +@param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit +floating-point. +@param mask Optional operation mask. + +@sa accumulateSquare, accumulateProduct, accumulateWeighted + */ +CV_EXPORTS_W void accumulateSquare( InputArray src, InputOutputArray dst, + InputArray mask = noArray() ); + +/** @brief Adds the per-element product of two input images to the accumulator image. + +The function adds the product of two images or their selected regions to the accumulator dst : + +\f[\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src1} (x,y) \cdot \texttt{src2} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f] + +The function supports multi-channel images. Each channel is processed independently. + +@param src1 First input image, 1- or 3-channel, 8-bit or 32-bit floating point. +@param src2 Second input image of the same type and the same size as src1 . +@param dst %Accumulator image with the same number of channels as input images, 32-bit or 64-bit +floating-point. +@param mask Optional operation mask. + +@sa accumulate, accumulateSquare, accumulateWeighted + */ +CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2, + InputOutputArray dst, InputArray mask=noArray() ); + +/** @brief Updates a running average. + +The function calculates the weighted sum of the input image src and the accumulator dst so that dst +becomes a running average of a frame sequence: + +\f[\texttt{dst} (x,y) \leftarrow (1- \texttt{alpha} ) \cdot \texttt{dst} (x,y) + \texttt{alpha} \cdot \texttt{src} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f] + +That is, alpha regulates the update speed (how fast the accumulator "forgets" about earlier images). +The function supports multi-channel images. Each channel is processed independently. + +@param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point. +@param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit +floating-point. +@param alpha Weight of the input image. +@param mask Optional operation mask. + +@sa accumulate, accumulateSquare, accumulateProduct + */ +CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst, + double alpha, InputArray mask = noArray() ); + +/** @brief The function is used to detect translational shifts that occur between two images. + +The operation takes advantage of the Fourier shift theorem for detecting the translational shift in +the frequency domain. It can be used for fast image registration as well as motion estimation. For +more information please see <http://en.wikipedia.org/wiki/Phase_correlation> + +Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed +with getOptimalDFTSize. + +The function performs the following equations: +- First it applies a Hanning window (see <http://en.wikipedia.org/wiki/Hann_function>) to each +image to remove possible edge effects. This window is cached until the array size changes to speed +up processing time. +- Next it computes the forward DFTs of each source array: +\f[\mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}\f] +where \f$\mathcal{F}\f$ is the forward DFT. +- It then computes the cross-power spectrum of each frequency domain array: +\f[R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}\f] +- Next the cross-correlation is converted back into the time domain via the inverse DFT: +\f[r = \mathcal{F}^{-1}\{R\}\f] +- Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to +achieve sub-pixel accuracy. +\f[(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}\f] +- If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5 +centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single +peak) and will be smaller when there are multiple peaks. + +@param src1 Source floating point array (CV_32FC1 or CV_64FC1) +@param src2 Source floating point array (CV_32FC1 or CV_64FC1) +@param window Floating point array with windowing coefficients to reduce edge effects (optional). +@param response Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional). +@returns detected phase shift (sub-pixel) between the two arrays. + +@sa dft, getOptimalDFTSize, idft, mulSpectrums createHanningWindow + */ +CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, + InputArray window = noArray(), CV_OUT double* response = 0); + +/** @brief This function computes a Hanning window coefficients in two dimensions. + +See (http://en.wikipedia.org/wiki/Hann_function) and (http://en.wikipedia.org/wiki/Window_function) +for more information. + +An example is shown below: +@code + // create hanning window of size 100x100 and type CV_32F + Mat hann; + createHanningWindow(hann, Size(100, 100), CV_32F); +@endcode +@param dst Destination array to place Hann coefficients in +@param winSize The window size specifications (both width and height must be > 1) +@param type Created array type + */ +CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); + +//! @} imgproc_motion + +//! @addtogroup imgproc_misc +//! @{ + +/** @brief Applies a fixed-level threshold to each array element. + +The function applies fixed-level thresholding to a multiple-channel array. The function is typically +used to get a bi-level (binary) image out of a grayscale image ( #compare could be also used for +this purpose) or for removing a noise, that is, filtering out pixels with too small or too large +values. There are several types of thresholding supported by the function. They are determined by +type parameter. + +Also, the special values #THRESH_OTSU or #THRESH_TRIANGLE may be combined with one of the +above values. In these cases, the function determines the optimal threshold value using the Otsu's +or Triangle algorithm and uses it instead of the specified thresh. + +@note Currently, the Otsu's and Triangle methods are implemented only for 8-bit single-channel images. + +@param src input array (multiple-channel, 8-bit or 32-bit floating point). +@param dst output array of the same size and type and the same number of channels as src. +@param thresh threshold value. +@param maxval maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding +types. +@param type thresholding type (see #ThresholdTypes). +@return the computed threshold value if Otsu's or Triangle methods used. + +@sa adaptiveThreshold, findContours, compare, min, max + */ +CV_EXPORTS_W double threshold( InputArray src, OutputArray dst, + double thresh, double maxval, int type ); + + +/** @brief Applies an adaptive threshold to an array. + +The function transforms a grayscale image to a binary image according to the formulae: +- **THRESH_BINARY** + \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f] +- **THRESH_BINARY_INV** + \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f] +where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter). + +The function can process the image in-place. + +@param src Source 8-bit single-channel image. +@param dst Destination image of the same size and the same type as src. +@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied +@param adaptiveMethod Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes. +The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries. +@param thresholdType Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV, +see #ThresholdTypes. +@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the +pixel: 3, 5, 7, and so on. +@param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it +is positive but may be zero or negative as well. + +@sa threshold, blur, GaussianBlur + */ +CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst, + double maxValue, int adaptiveMethod, + int thresholdType, int blockSize, double C ); + +//! @} imgproc_misc + +//! @addtogroup imgproc_filter +//! @{ + +/** @example samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp +An example using pyrDown and pyrUp functions +*/ + +/** @brief Blurs an image and downsamples it. + +By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in +any case, the following conditions should be satisfied: + +\f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f] + +The function performs the downsampling step of the Gaussian pyramid construction. First, it +convolves the source image with the kernel: + +\f[\frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f] + +Then, it downsamples the image by rejecting even rows and columns. + +@param src input image. +@param dst output image; it has the specified size and the same type as src. +@param dstsize size of the output image. +@param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported) + */ +CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst, + const Size& dstsize = Size(), int borderType = BORDER_DEFAULT ); + +/** @brief Upsamples an image and then blurs it. + +By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any +case, the following conditions should be satisfied: + +\f[\begin{array}{l} | \texttt{dstsize.width} -src.cols*2| \leq ( \texttt{dstsize.width} \mod 2) \\ | \texttt{dstsize.height} -src.rows*2| \leq ( \texttt{dstsize.height} \mod 2) \end{array}\f] + +The function performs the upsampling step of the Gaussian pyramid construction, though it can +actually be used to construct the Laplacian pyramid. First, it upsamples the source image by +injecting even zero rows and columns and then convolves the result with the same kernel as in +pyrDown multiplied by 4. + +@param src input image. +@param dst output image. It has the specified size and the same type as src . +@param dstsize size of the output image. +@param borderType Pixel extrapolation method, see #BorderTypes (only #BORDER_DEFAULT is supported) + */ +CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst, + const Size& dstsize = Size(), int borderType = BORDER_DEFAULT ); + +/** @brief Constructs the Gaussian pyramid for an image. + +The function constructs a vector of images and builds the Gaussian pyramid by recursively applying +pyrDown to the previously built pyramid layers, starting from `dst[0]==src`. + +@param src Source image. Check pyrDown for the list of supported types. +@param dst Destination vector of maxlevel+1 images of the same type as src. dst[0] will be the +same as src. dst[1] is the next pyramid layer, a smoothed and down-sized src, and so on. +@param maxlevel 0-based index of the last (the smallest) pyramid layer. It must be non-negative. +@param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported) + */ +CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst, + int maxlevel, int borderType = BORDER_DEFAULT ); + +//! @} imgproc_filter + +//! @addtogroup imgproc_transform +//! @{ + +/** @brief Transforms an image to compensate for lens distortion. + +The function transforms an image to compensate radial and tangential lens distortion. + +The function is simply a combination of #initUndistortRectifyMap (with unity R ) and #remap +(with bilinear interpolation). See the former function for details of the transformation being +performed. + +Those pixels in the destination image, for which there is no correspondent pixels in the source +image, are filled with zeros (black color). + +A particular subset of the source image that will be visible in the corrected image can be regulated +by newCameraMatrix. You can use #getOptimalNewCameraMatrix to compute the appropriate +newCameraMatrix depending on your requirements. + +The camera matrix and the distortion parameters can be determined using #calibrateCamera. If +the resolution of images is different from the resolution used at the calibration stage, \f$f_x, +f_y, c_x\f$ and \f$c_y\f$ need to be scaled accordingly, while the distortion coefficients remain +the same. + +@param src Input (distorted) image. +@param dst Output (corrected) image that has the same size and type as src . +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as +cameraMatrix but you may additionally scale and shift the result by using a different matrix. + */ +CV_EXPORTS_W void undistort( InputArray src, OutputArray dst, + InputArray cameraMatrix, + InputArray distCoeffs, + InputArray newCameraMatrix = noArray() ); + +/** @brief Computes the undistortion and rectification transformation map. + +The function computes the joint undistortion and rectification transformation and represents the +result in the form of maps for remap. The undistorted image looks like original, as if it is +captured with a camera using the camera matrix =newCameraMatrix and zero distortion. In case of a +monocular camera, newCameraMatrix is usually equal to cameraMatrix, or it can be computed by +#getOptimalNewCameraMatrix for a better control over scaling. In case of a stereo camera, +newCameraMatrix is normally set to P1 or P2 computed by #stereoRectify . + +Also, this new camera is oriented differently in the coordinate space, according to R. That, for +example, helps to align two heads of a stereo camera so that the epipolar lines on both images +become horizontal and have the same y- coordinate (in case of a horizontally aligned stereo camera). + +The function actually builds the maps for the inverse mapping algorithm that is used by remap. That +is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function +computes the corresponding coordinates in the source image (that is, in the original image from +camera). The following process is applied: +\f[ +\begin{array}{l} +x \leftarrow (u - {c'}_x)/{f'}_x \\ +y \leftarrow (v - {c'}_y)/{f'}_y \\ +{[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\ +x' \leftarrow X/W \\ +y' \leftarrow Y/W \\ +r^2 \leftarrow x'^2 + y'^2 \\ +x'' \leftarrow x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} ++ 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\\ +y'' \leftarrow y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} ++ p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ +s\vecthree{x'''}{y'''}{1} = +\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} +{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} +{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ +map_x(u,v) \leftarrow x''' f_x + c_x \\ +map_y(u,v) \leftarrow y''' f_y + c_y +\end{array} +\f] +where \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +are the distortion coefficients. + +In case of a stereo camera, this function is called twice: once for each camera head, after +stereoRectify, which in its turn is called after #stereoCalibrate. But if the stereo camera +was not calibrated, it is still possible to compute the rectification transformations directly from +the fundamental matrix using #stereoRectifyUncalibrated. For each camera, the function computes +homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D +space. R can be computed from H as +\f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f] +where cameraMatrix can be chosen arbitrarily. + +@param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 , +computed by #stereoRectify can be passed here. If the matrix is empty, the identity transformation +is assumed. In cvInitUndistortMap R assumed to be an identity matrix. +@param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. +@param size Undistorted image size. +@param m1type Type of the first output map that can be CV_32FC1, CV_32FC2 or CV_16SC2, see #convertMaps +@param map1 The first output map. +@param map2 The second output map. + */ +CV_EXPORTS_W void initUndistortRectifyMap( InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray newCameraMatrix, + Size size, int m1type, OutputArray map1, OutputArray map2 ); + +//! initializes maps for #remap for wide-angle +CV_EXPORTS_W float initWideAngleProjMap( InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, int destImageWidth, + int m1type, OutputArray map1, OutputArray map2, + int projType = PROJ_SPHERICAL_EQRECT, double alpha = 0); + +/** @brief Returns the default new camera matrix. + +The function returns the camera matrix that is either an exact copy of the input cameraMatrix (when +centerPrinicipalPoint=false ), or the modified one (when centerPrincipalPoint=true). + +In the latter case, the new camera matrix will be: + +\f[\begin{bmatrix} f_x && 0 && ( \texttt{imgSize.width} -1)*0.5 \\ 0 && f_y && ( \texttt{imgSize.height} -1)*0.5 \\ 0 && 0 && 1 \end{bmatrix} ,\f] + +where \f$f_x\f$ and \f$f_y\f$ are \f$(0,0)\f$ and \f$(1,1)\f$ elements of cameraMatrix, respectively. + +By default, the undistortion functions in OpenCV (see #initUndistortRectifyMap, #undistort) do not +move the principal point. However, when you work with stereo, it is important to move the principal +points in both views to the same y-coordinate (which is required by most of stereo correspondence +algorithms), and may be to the same x-coordinate too. So, you can form the new camera matrix for +each view where the principal points are located at the center. + +@param cameraMatrix Input camera matrix. +@param imgsize Camera view image size in pixels. +@param centerPrincipalPoint Location of the principal point in the new camera matrix. The +parameter indicates whether this location should be at the image center or not. + */ +CV_EXPORTS_W Mat getDefaultNewCameraMatrix( InputArray cameraMatrix, Size imgsize = Size(), + bool centerPrincipalPoint = false ); + +/** @brief Computes the ideal point coordinates from the observed point coordinates. + +The function is similar to #undistort and #initUndistortRectifyMap but it operates on a +sparse set of points instead of a raster image. Also the function performs a reverse transformation +to projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a +planar object, it does, up to a translation vector, if the proper R is specified. + +For each observed point coordinate \f$(u, v)\f$ the function computes: +\f[ +\begin{array}{l} +x^{"} \leftarrow (u - c_x)/f_x \\ +y^{"} \leftarrow (v - c_y)/f_y \\ +(x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ +{[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ +x \leftarrow X/W \\ +y \leftarrow Y/W \\ +\text{only performed if P is specified:} \\ +u' \leftarrow x {f'}_x + {c'}_x \\ +v' \leftarrow y {f'}_y + {c'}_y +\end{array} +\f] + +where *undistort* is an approximate iterative algorithm that estimates the normalized original +point coordinates out of the normalized distorted point coordinates ("normalized" means that the +coordinates do not depend on the camera matrix). + +The function can be used for both a stereo camera head or a monocular camera (when R is empty). + +@param src Observed point coordinates, 1xN or Nx1 2-channel (CV_32FC2 or CV_64FC2). +@param dst Output ideal point coordinates after undistortion and reverse perspective +transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates. +@param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by +#stereoRectify can be passed here. If the matrix is empty, the identity transformation is used. +@param P New camera matrix (3x3) or new projection matrix (3x4) \f$\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\f$. P1 or P2 computed by +#stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used. + */ +CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R = noArray(), InputArray P = noArray()); +/** @overload + @note Default version of #undistortPoints does 5 iterations to compute undistorted points. + + */ +CV_EXPORTS_AS(undistortPointsIter) void undistortPoints( InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray P, TermCriteria criteria); + +//! @} imgproc_transform + +//! @addtogroup imgproc_hist +//! @{ + +/** @example samples/cpp/demhist.cpp +An example for creating histograms of an image +*/ + +/** @brief Calculates a histogram of a set of arrays. + +The function cv::calcHist calculates the histogram of one or more arrays. The elements of a tuple used +to increment a histogram bin are taken from the corresponding input arrays at the same location. The +sample below shows how to compute a 2D Hue-Saturation histogram for a color image. : +@include snippets/imgproc_calcHist.cpp + +@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same +size. Each of them can have an arbitrary number of channels. +@param nimages Number of source images. +@param channels List of the dims channels used to compute the histogram. The first array channels +are numerated from 0 to images[0].channels()-1 , the second array channels are counted from +images[0].channels() to images[0].channels() + images[1].channels()-1, and so on. +@param mask Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size +as images[i] . The non-zero mask elements mark the array elements counted in the histogram. +@param hist Output histogram, which is a dense or sparse dims -dimensional array. +@param dims Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS +(equal to 32 in the current OpenCV version). +@param histSize Array of histogram sizes in each dimension. +@param ranges Array of the dims arrays of the histogram bin boundaries in each dimension. When the +histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower +(inclusive) boundary \f$L_0\f$ of the 0-th histogram bin and the upper (exclusive) boundary +\f$U_{\texttt{histSize}[i]-1}\f$ for the last histogram bin histSize[i]-1 . That is, in case of a +uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform ( +uniform=false ), then each of ranges[i] contains histSize[i]+1 elements: +\f$L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}\f$ +. The array elements, that are not between \f$L_0\f$ and \f$U_{\texttt{histSize[i]}-1}\f$ , are not +counted in the histogram. +@param uniform Flag indicating whether the histogram is uniform or not (see above). +@param accumulate Accumulation flag. If it is set, the histogram is not cleared in the beginning +when it is allocated. This feature enables you to compute a single histogram from several sets of +arrays, or to update the histogram in time. +*/ +CV_EXPORTS void calcHist( const Mat* images, int nimages, + const int* channels, InputArray mask, + OutputArray hist, int dims, const int* histSize, + const float** ranges, bool uniform = true, bool accumulate = false ); + +/** @overload + +this variant uses %SparseMat for output +*/ +CV_EXPORTS void calcHist( const Mat* images, int nimages, + const int* channels, InputArray mask, + SparseMat& hist, int dims, + const int* histSize, const float** ranges, + bool uniform = true, bool accumulate = false ); + +/** @overload */ +CV_EXPORTS_W void calcHist( InputArrayOfArrays images, + const std::vector<int>& channels, + InputArray mask, OutputArray hist, + const std::vector<int>& histSize, + const std::vector<float>& ranges, + bool accumulate = false ); + +/** @brief Calculates the back projection of a histogram. + +The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to +#calcHist , at each location (x, y) the function collects the values from the selected channels +in the input images and finds the corresponding histogram bin. But instead of incrementing it, the +function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of +statistics, the function computes probability of each element value in respect with the empirical +probability distribution represented by the histogram. See how, for example, you can find and track +a bright-colored object in a scene: + +- Before tracking, show the object to the camera so that it covers almost the whole frame. +Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant +colors in the object. + +- When tracking, calculate a back projection of a hue plane of each input video frame using that +pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make +sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels. + +- Find connected components in the resulting picture and choose, for example, the largest +component. + +This is an approximate algorithm of the CamShift color object tracker. + +@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same +size. Each of them can have an arbitrary number of channels. +@param nimages Number of source images. +@param channels The list of channels used to compute the back projection. The number of channels +must match the histogram dimensionality. The first array channels are numerated from 0 to +images[0].channels()-1 , the second array channels are counted from images[0].channels() to +images[0].channels() + images[1].channels()-1, and so on. +@param hist Input histogram that can be dense or sparse. +@param backProject Destination back projection array that is a single-channel array of the same +size and depth as images[0] . +@param ranges Array of arrays of the histogram bin boundaries in each dimension. See #calcHist . +@param scale Optional scale factor for the output back projection. +@param uniform Flag indicating whether the histogram is uniform or not (see above). + +@sa calcHist, compareHist + */ +CV_EXPORTS void calcBackProject( const Mat* images, int nimages, + const int* channels, InputArray hist, + OutputArray backProject, const float** ranges, + double scale = 1, bool uniform = true ); + +/** @overload */ +CV_EXPORTS void calcBackProject( const Mat* images, int nimages, + const int* channels, const SparseMat& hist, + OutputArray backProject, const float** ranges, + double scale = 1, bool uniform = true ); + +/** @overload */ +CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector<int>& channels, + InputArray hist, OutputArray dst, + const std::vector<float>& ranges, + double scale ); + +/** @brief Compares two histograms. + +The function cv::compareHist compares two dense or two sparse histograms using the specified method. + +The function returns \f$d(H_1, H_2)\f$ . + +While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable +for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling +problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms +or more general sparse configurations of weighted points, consider using the #EMD function. + +@param H1 First compared histogram. +@param H2 Second compared histogram of the same size as H1 . +@param method Comparison method, see #HistCompMethods + */ +CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method ); + +/** @overload */ +CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method ); + +/** @brief Equalizes the histogram of a grayscale image. + +The function equalizes the histogram of the input image using the following algorithm: + +- Calculate the histogram \f$H\f$ for src . +- Normalize the histogram so that the sum of histogram bins is 255. +- Compute the integral of the histogram: +\f[H'_i = \sum _{0 \le j < i} H(j)\f] +- Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$ + +The algorithm normalizes the brightness and increases the contrast of the image. + +@param src Source 8-bit single channel image. +@param dst Destination image of the same size and type as src . + */ +CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst ); + +/** @brief Creates a smart pointer to a cv::CLAHE class and initializes it. + +@param clipLimit Threshold for contrast limiting. +@param tileGridSize Size of grid for histogram equalization. Input image will be divided into +equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column. + */ +CV_EXPORTS_W Ptr<CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); + +/** @brief Computes the "minimal work" distance between two weighted point configurations. + +The function computes the earth mover distance and/or a lower boundary of the distance between the +two weighted point configurations. One of the applications described in @cite RubnerSept98, +@cite Rubner2000 is multi-dimensional histogram comparison for image retrieval. EMD is a transportation +problem that is solved using some modification of a simplex algorithm, thus the complexity is +exponential in the worst case, though, on average it is much faster. In the case of a real metric +the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used +to determine roughly whether the two signatures are far enough so that they cannot relate to the +same object. + +@param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix. +Each row stores the point weight followed by the point coordinates. The matrix is allowed to have +a single column (weights only) if the user-defined cost matrix is used. The weights must be +non-negative and have at least one non-zero value. +@param signature2 Second signature of the same format as signature1 , though the number of rows +may be different. The total weights may be different. In this case an extra "dummy" point is added +to either signature1 or signature2. The weights must be non-negative and have at least one non-zero +value. +@param distType Used metric. See #DistanceTypes. +@param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix +is used, lower boundary lowerBound cannot be calculated because it needs a metric function. +@param lowerBound Optional input/output parameter: lower boundary of a distance between the two +signatures that is a distance between mass centers. The lower boundary may not be calculated if +the user-defined cost matrix is used, the total weights of point configurations are not equal, or +if the signatures consist of weights only (the signature matrices have a single column). You +**must** initialize \*lowerBound . If the calculated distance between mass centers is greater or +equal to \*lowerBound (it means that the signatures are far enough), the function does not +calculate EMD. In any case \*lowerBound is set to the calculated distance between mass centers on +return. Thus, if you want to calculate both distance between mass centers and EMD, \*lowerBound +should be set to 0. +@param flow Resultant \f$\texttt{size1} \times \texttt{size2}\f$ flow matrix: \f$\texttt{flow}_{i,j}\f$ is +a flow from \f$i\f$ -th point of signature1 to \f$j\f$ -th point of signature2 . + */ +CV_EXPORTS float EMD( InputArray signature1, InputArray signature2, + int distType, InputArray cost=noArray(), + float* lowerBound = 0, OutputArray flow = noArray() ); + +CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature2, + int distType, InputArray cost=noArray(), + CV_IN_OUT Ptr<float> lowerBound = Ptr<float>(), OutputArray flow = noArray() ); + +//! @} imgproc_hist + +/** @example samples/cpp/watershed.cpp +An example using the watershed algorithm +*/ + +/** @brief Performs a marker-based image segmentation using the watershed algorithm. + +The function implements one of the variants of watershed, non-parametric marker-based segmentation +algorithm, described in @cite Meyer92 . + +Before passing the image to the function, you have to roughly outline the desired regions in the +image markers with positive (\>0) indices. So, every region is represented as one or more connected +components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary +mask using #findContours and #drawContours (see the watershed.cpp demo). The markers are "seeds" of +the future image regions. All the other pixels in markers , whose relation to the outlined regions +is not known and should be defined by the algorithm, should be set to 0's. In the function output, +each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the +regions. + +@note Any two neighbor connected components are not necessarily separated by a watershed boundary +(-1's pixels); for example, they can touch each other in the initial marker image passed to the +function. + +@param image Input 8-bit 3-channel image. +@param markers Input/output 32-bit single-channel image (map) of markers. It should have the same +size as image . + +@sa findContours + +@ingroup imgproc_misc + */ +CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers ); + +//! @addtogroup imgproc_filter +//! @{ + +/** @brief Performs initial step of meanshift segmentation of an image. + +The function implements the filtering stage of meanshift segmentation, that is, the output of the +function is the filtered "posterized" image with color gradients and fine-grain texture flattened. +At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes +meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is +considered: + +\f[(x,y): X- \texttt{sp} \le x \le X+ \texttt{sp} , Y- \texttt{sp} \le y \le Y+ \texttt{sp} , ||(R,G,B)-(r,g,b)|| \le \texttt{sr}\f] + +where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively +(though, the algorithm does not depend on the color space used, so any 3-component color space can +be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector +(R',G',B') are found and they act as the neighborhood center on the next iteration: + +\f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f] + +After the iterations over, the color components of the initial pixel (that is, the pixel from where +the iterations started) are set to the final value (average color at the last iteration): + +\f[I(X,Y) <- (R*,G*,B*)\f] + +When maxLevel \> 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is +run on the smallest layer first. After that, the results are propagated to the larger layer and the +iterations are run again only on those pixels where the layer colors differ by more than sr from the +lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the +results will be actually different from the ones obtained by running the meanshift procedure on the +whole original image (i.e. when maxLevel==0). + +@param src The source 8-bit, 3-channel image. +@param dst The destination image of the same format and the same size as the source. +@param sp The spatial window radius. +@param sr The color window radius. +@param maxLevel Maximum level of the pyramid for the segmentation. +@param termcrit Termination criteria: when to stop meanshift iterations. + */ +CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, + double sp, double sr, int maxLevel = 1, + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) ); + +//! @} + +//! @addtogroup imgproc_misc +//! @{ + +/** @example samples/cpp/grabcut.cpp +An example using the GrabCut algorithm +![Sample Screenshot](grabcut_output1.jpg) +*/ + +/** @brief Runs the GrabCut algorithm. + +The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut). + +@param img Input 8-bit 3-channel image. +@param mask Input/output 8-bit single-channel mask. The mask is initialized by the function when +mode is set to #GC_INIT_WITH_RECT. Its elements may have one of the #GrabCutClasses. +@param rect ROI containing a segmented object. The pixels outside of the ROI are marked as +"obvious background". The parameter is only used when mode==#GC_INIT_WITH_RECT . +@param bgdModel Temporary array for the background model. Do not modify it while you are +processing the same image. +@param fgdModel Temporary arrays for the foreground model. Do not modify it while you are +processing the same image. +@param iterCount Number of iterations the algorithm should make before returning the result. Note +that the result can be refined with further calls with mode==#GC_INIT_WITH_MASK or +mode==GC_EVAL . +@param mode Operation mode that could be one of the #GrabCutModes + */ +CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect, + InputOutputArray bgdModel, InputOutputArray fgdModel, + int iterCount, int mode = GC_EVAL ); + +/** @example samples/cpp/distrans.cpp +An example on using the distance transform +*/ + +/** @brief Calculates the distance to the closest zero pixel for each pixel of the source image. + +The function cv::distanceTransform calculates the approximate or precise distance from every binary +image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero. + +When maskSize == #DIST_MASK_PRECISE and distanceType == #DIST_L2 , the function runs the +algorithm described in @cite Felzenszwalb04 . This algorithm is parallelized with the TBB library. + +In other cases, the algorithm @cite Borgefors86 is used. This means that for a pixel the function +finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical, +diagonal, or knight's move (the latest is available for a \f$5\times 5\f$ mask). The overall +distance is calculated as a sum of these basic distances. Since the distance function should be +symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all +the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the +same cost (denoted as `c`). For the #DIST_C and #DIST_L1 types, the distance is calculated +precisely, whereas for #DIST_L2 (Euclidean distance) the distance can be calculated only with a +relative error (a \f$5\times 5\f$ mask gives more accurate results). For `a`,`b`, and `c`, OpenCV +uses the values suggested in the original paper: +- DIST_L1: `a = 1, b = 2` +- DIST_L2: + - `3 x 3`: `a=0.955, b=1.3693` + - `5 x 5`: `a=1, b=1.4, c=2.1969` +- DIST_C: `a = 1, b = 1` + +Typically, for a fast, coarse distance estimation #DIST_L2, a \f$3\times 3\f$ mask is used. For a +more accurate distance estimation #DIST_L2, a \f$5\times 5\f$ mask or the precise algorithm is used. +Note that both the precise and the approximate algorithms are linear on the number of pixels. + +This variant of the function does not only compute the minimum distance for each pixel \f$(x, y)\f$ +but also identifies the nearest connected component consisting of zero pixels +(labelType==#DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==#DIST_LABEL_PIXEL). Index of the +component/pixel is stored in `labels(x, y)`. When labelType==#DIST_LABEL_CCOMP, the function +automatically finds connected components of zero pixels in the input image and marks them with +distinct labels. When labelType==#DIST_LABEL_CCOMP, the function scans through the input image and +marks all the zero pixels with distinct labels. + +In this mode, the complexity is still linear. That is, the function provides a very fast way to +compute the Voronoi diagram for a binary image. Currently, the second variant can use only the +approximate distance transform algorithm, i.e. maskSize=#DIST_MASK_PRECISE is not supported +yet. + +@param src 8-bit, single-channel (binary) source image. +@param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, +single-channel image of the same size as src. +@param labels Output 2D array of labels (the discrete Voronoi diagram). It has the type +CV_32SC1 and the same size as src. +@param distanceType Type of distance, see #DistanceTypes +@param maskSize Size of the distance transform mask, see #DistanceTransformMasks. +#DIST_MASK_PRECISE is not supported by this variant. In case of the #DIST_L1 or #DIST_C distance type, +the parameter is forced to 3 because a \f$3\times 3\f$ mask gives the same result as \f$5\times +5\f$ or any larger aperture. +@param labelType Type of the label array to build, see #DistanceTransformLabelTypes. + */ +CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst, + OutputArray labels, int distanceType, int maskSize, + int labelType = DIST_LABEL_CCOMP ); + +/** @overload +@param src 8-bit, single-channel (binary) source image. +@param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, +single-channel image of the same size as src . +@param distanceType Type of distance, see #DistanceTypes +@param maskSize Size of the distance transform mask, see #DistanceTransformMasks. In case of the +#DIST_L1 or #DIST_C distance type, the parameter is forced to 3 because a \f$3\times 3\f$ mask gives +the same result as \f$5\times 5\f$ or any larger aperture. +@param dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for +the first variant of the function and distanceType == #DIST_L1. +*/ +CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst, + int distanceType, int maskSize, int dstType=CV_32F); + +/** @example samples/cpp/ffilldemo.cpp +An example using the FloodFill technique +*/ + +/** @overload + +variant without `mask` parameter +*/ +CV_EXPORTS int floodFill( InputOutputArray image, + Point seedPoint, Scalar newVal, CV_OUT Rect* rect = 0, + Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), + int flags = 4 ); + +/** @brief Fills a connected component with the given color. + +The function cv::floodFill fills a connected component starting from the seed point with the specified +color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The +pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if: + +- in case of a grayscale image and floating range +\f[\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} (x',y')+ \texttt{upDiff}\f] + + +- in case of a grayscale image and fixed range +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)+ \texttt{upDiff}\f] + + +- in case of a color image and floating range +\f[\texttt{src} (x',y')_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} (x',y')_r+ \texttt{upDiff} _r,\f] +\f[\texttt{src} (x',y')_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} (x',y')_g+ \texttt{upDiff} _g\f] +and +\f[\texttt{src} (x',y')_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} (x',y')_b+ \texttt{upDiff} _b\f] + + +- in case of a color image and fixed range +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r+ \texttt{upDiff} _r,\f] +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g+ \texttt{upDiff} _g\f] +and +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b+ \texttt{upDiff} _b\f] + + +where \f$src(x',y')\f$ is the value of one of pixel neighbors that is already known to belong to the +component. That is, to be added to the connected component, a color/brightness of the pixel should +be close enough to: +- Color/brightness of one of its neighbors that already belong to the connected component in case +of a floating range. +- Color/brightness of the seed point in case of a fixed range. + +Use these functions to either mark a connected component with the specified color in-place, or build +a mask and then extract the contour, or copy the region to another image, and so on. + +@param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the +function unless the #FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See +the details below. +@param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels +taller than image. Since this is both an input and output parameter, you must take responsibility +of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, +an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the +mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags +as described below. Additionally, the function fills the border of the mask with ones to simplify +internal processing. It is therefore possible to use the same mask in multiple calls to the function +to make sure the filled areas do not overlap. +@param seedPoint Starting point. +@param newVal New value of the repainted domain pixels. +@param loDiff Maximal lower brightness/color difference between the currently observed pixel and +one of its neighbors belonging to the component, or a seed pixel being added to the component. +@param upDiff Maximal upper brightness/color difference between the currently observed pixel and +one of its neighbors belonging to the component, or a seed pixel being added to the component. +@param rect Optional output parameter set by the function to the minimum bounding rectangle of the +repainted domain. +@param flags Operation flags. The first 8 bits contain a connectivity value. The default value of +4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A +connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) +will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill +the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest +neighbours and fill the mask with a value of 255. The following additional options occupy higher +bits and therefore may be further combined with the connectivity and mask fill values using +bit-wise or (|), see #FloodFillFlags. + +@note Since the mask is larger than the filled image, a pixel \f$(x, y)\f$ in image corresponds to the +pixel \f$(x+1, y+1)\f$ in the mask . + +@sa findContours + */ +CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask, + Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0, + Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), + int flags = 4 ); + +//! Performs linear blending of two images: +//! \f[ \texttt{dst}(i,j) = \texttt{weights1}(i,j)*\texttt{src1}(i,j) + \texttt{weights2}(i,j)*\texttt{src2}(i,j) \f] +//! @param src1 It has a type of CV_8UC(n) or CV_32FC(n), where n is a positive integer. +//! @param src2 It has the same type and size as src1. +//! @param weights1 It has a type of CV_32FC1 and the same size with src1. +//! @param weights2 It has a type of CV_32FC1 and the same size with src1. +//! @param dst It is created if it does not have the same size and type with src1. +CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst); + +//! @} imgproc_misc + +//! @addtogroup imgproc_color_conversions +//! @{ + +/** @brief Converts an image from one color space to another. + +The function converts an input image from one color space to another. In case of a transformation +to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note +that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the +bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue +component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and +sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on. + +The conventional ranges for R, G, and B channel values are: +- 0 to 255 for CV_8U images +- 0 to 65535 for CV_16U images +- 0 to 1 for CV_32F images + +In case of linear transformations, the range does not matter. But in case of a non-linear +transformation, an input RGB image should be normalized to the proper value range to get the correct +results, for example, for RGB \f$\rightarrow\f$ L\*u\*v\* transformation. For example, if you have a +32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will +have the 0..255 value range instead of 0..1 assumed by the function. So, before calling #cvtColor , +you need first to scale the image down: +@code + img *= 1./255; + cvtColor(img, img, COLOR_BGR2Luv); +@endcode +If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many +applications, this will not be noticeable but it is recommended to use 32-bit images in applications +that need the full range of colors or that convert an image before an operation and then convert +back. + +If conversion adds the alpha channel, its value will set to the maximum of corresponding channel +range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F. + +@param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision +floating-point. +@param dst output image of the same size and depth as src. +@param code color space conversion code (see #ColorConversionCodes). +@param dstCn number of channels in the destination image; if the parameter is 0, the number of the +channels is derived automatically from src and code. + +@see @ref imgproc_color_conversions + */ +CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 ); + +/** @brief Converts an image from one color space to another where the source image is +stored in two planes. + +This function only supports YUV420 to RGB conversion as of now. + +@param src1: 8-bit image (#CV_8U) of the Y plane. +@param src2: image containing interleaved U/V plane. +@param dst: output image. +@param code: Specifies the type of conversion. It can take any of the following values: +- #COLOR_YUV2BGR_NV12 +- #COLOR_YUV2RGB_NV12 +- #COLOR_YUV2BGRA_NV12 +- #COLOR_YUV2RGBA_NV12 +- #COLOR_YUV2BGR_NV21 +- #COLOR_YUV2RGB_NV21 +- #COLOR_YUV2BGRA_NV21 +- #COLOR_YUV2RGBA_NV21 +*/ +CV_EXPORTS_W void cvtColorTwoPlane( InputArray src1, InputArray src2, OutputArray dst, int code ); + +/** @brief main function for all demosaicing processes + +@param src input image: 8-bit unsigned or 16-bit unsigned. +@param dst output image of the same size and depth as src. +@param code Color space conversion code (see the description below). +@param dstCn number of channels in the destination image; if the parameter is 0, the number of the +channels is derived automatically from src and code. + +The function can do the following transformations: + +- Demosaicing using bilinear interpolation + + #COLOR_BayerBG2BGR , #COLOR_BayerGB2BGR , #COLOR_BayerRG2BGR , #COLOR_BayerGR2BGR + + #COLOR_BayerBG2GRAY , #COLOR_BayerGB2GRAY , #COLOR_BayerRG2GRAY , #COLOR_BayerGR2GRAY + +- Demosaicing using Variable Number of Gradients. + + #COLOR_BayerBG2BGR_VNG , #COLOR_BayerGB2BGR_VNG , #COLOR_BayerRG2BGR_VNG , #COLOR_BayerGR2BGR_VNG + +- Edge-Aware Demosaicing. + + #COLOR_BayerBG2BGR_EA , #COLOR_BayerGB2BGR_EA , #COLOR_BayerRG2BGR_EA , #COLOR_BayerGR2BGR_EA + +- Demosaicing with alpha channel + + #COLOR_BayerBG2BGRA , #COLOR_BayerGB2BGRA , #COLOR_BayerRG2BGRA , #COLOR_BayerGR2BGRA + +@sa cvtColor +*/ +CV_EXPORTS_W void demosaicing(InputArray src, OutputArray dst, int code, int dstCn = 0); + +//! @} imgproc_color_conversions + +//! @addtogroup imgproc_shape +//! @{ + +/** @brief Calculates all of the moments up to the third order of a polygon or rasterized shape. + +The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The +results are returned in the structure cv::Moments. + +@param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array ( +\f$1 \times N\f$ or \f$N \times 1\f$ ) of 2D points (Point or Point2f ). +@param binaryImage If it is true, all non-zero image pixels are treated as 1's. The parameter is +used for images only. +@returns moments. + +@note Only applicable to contour moments calculations from Python bindings: Note that the numpy +type for the input array should be either np.int32 or np.float32. + +@sa contourArea, arcLength + */ +CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false ); + +/** @brief Calculates seven Hu invariants. + +The function calculates seven Hu invariants (introduced in @cite Hu62; see also +<http://en.wikipedia.org/wiki/Image_moment>) defined as: + +\f[\begin{array}{l} hu[0]= \eta _{20}+ \eta _{02} \\ hu[1]=( \eta _{20}- \eta _{02})^{2}+4 \eta _{11}^{2} \\ hu[2]=( \eta _{30}-3 \eta _{12})^{2}+ (3 \eta _{21}- \eta _{03})^{2} \\ hu[3]=( \eta _{30}+ \eta _{12})^{2}+ ( \eta _{21}+ \eta _{03})^{2} \\ hu[4]=( \eta _{30}-3 \eta _{12})( \eta _{30}+ \eta _{12})[( \eta _{30}+ \eta _{12})^{2}-3( \eta _{21}+ \eta _{03})^{2}]+(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ hu[5]=( \eta _{20}- \eta _{02})[( \eta _{30}+ \eta _{12})^{2}- ( \eta _{21}+ \eta _{03})^{2}]+4 \eta _{11}( \eta _{30}+ \eta _{12})( \eta _{21}+ \eta _{03}) \\ hu[6]=(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]-( \eta _{30}-3 \eta _{12})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ \end{array}\f] + +where \f$\eta_{ji}\f$ stands for \f$\texttt{Moments::nu}_{ji}\f$ . + +These values are proved to be invariants to the image scale, rotation, and reflection except the +seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of +infinite image resolution. In case of raster images, the computed Hu invariants for the original and +transformed images are a bit different. + +@param moments Input moments computed with moments . +@param hu Output Hu invariants. + +@sa matchShapes + */ +CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] ); + +/** @overload */ +CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu ); + +//! @} imgproc_shape + +//! @addtogroup imgproc_object +//! @{ + +//! type of the template matching operation +enum TemplateMatchModes { + TM_SQDIFF = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f] + TM_SQDIFF_NORMED = 1, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] + TM_CCORR = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f] + TM_CCORR_NORMED = 3, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] + TM_CCOEFF = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f] + //!< where + //!< \f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f] + TM_CCOEFF_NORMED = 5 //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f] +}; + +/** @example samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp +An example using Template Matching algorithm +*/ + +/** @brief Compares a template against overlapped image regions. + +The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against +templ using the specified method and stores the comparison results in result . Here are the formulae +for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation +is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$ + +After the function finishes the comparison, the best matches can be found as global minimums (when +#TM_SQDIFF was used) or maximums (when #TM_CCORR or #TM_CCOEFF was used) using the +#minMaxLoc function. In case of a color image, template summation in the numerator and each sum in +the denominator is done over all of the channels and separate mean values are used for each channel. +That is, the function can take a color template and a color image. The result will still be a +single-channel image, which is easier to analyze. + +@param image Image where the search is running. It must be 8-bit or 32-bit floating-point. +@param templ Searched template. It must be not greater than the source image and have the same +data type. +@param result Map of comparison results. It must be single-channel 32-bit floating-point. If image +is \f$W \times H\f$ and templ is \f$w \times h\f$ , then result is \f$(W-w+1) \times (H-h+1)\f$ . +@param method Parameter specifying the comparison method, see #TemplateMatchModes +@param mask Mask of searched template. It must have the same datatype and size with templ. It is +not set by default. Currently, only the #TM_SQDIFF and #TM_CCORR_NORMED methods are supported. + */ +CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, + OutputArray result, int method, InputArray mask = noArray() ); + +//! @} + +//! @addtogroup imgproc_shape +//! @{ + +/** @example samples/cpp/connected_components.cpp +This program demonstrates connected components and use of the trackbar +*/ + +/** @brief computes the connected components labeled image of boolean image + +image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 +represents the background label. ltype specifies the output label image type, an important +consideration based on the total number of labels or alternatively the total number of pixels in +the source image. ccltype specifies the connected components labeling algorithm to use, currently +Grana (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes +for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. +This function uses parallel version of both Grana and Wu's algorithms if at least one allowed +parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs. + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +@param ccltype connected components algorithm type (see the #ConnectedComponentsAlgorithmsTypes). +*/ +CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels, + int connectivity, int ltype, int ccltype); + + +/** @overload + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +*/ +CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels, + int connectivity = 8, int ltype = CV_32S); + + +/** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label + +image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 +represents the background label. ltype specifies the output label image type, an important +consideration based on the total number of labels or alternatively the total number of pixels in +the source image. ccltype specifies the connected components labeling algorithm to use, currently +Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes +for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. +This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed +parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs. + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param stats statistics output for each label, including the background label, see below for +available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +#ConnectedComponentsTypes. The data type is CV_32S. +@param centroids centroid output for each label, including the background label. Centroids are +accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +@param ccltype connected components algorithm type (see #ConnectedComponentsAlgorithmsTypes). +*/ +CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels, + OutputArray stats, OutputArray centroids, + int connectivity, int ltype, int ccltype); + +/** @overload +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param stats statistics output for each label, including the background label, see below for +available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +#ConnectedComponentsTypes. The data type is CV_32S. +@param centroids centroid output for each label, including the background label. Centroids are +accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +*/ +CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labels, + OutputArray stats, OutputArray centroids, + int connectivity = 8, int ltype = CV_32S); + + +/** @brief Finds contours in a binary image. + +The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours +are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the +OpenCV sample directory. +@note Since opencv 3.2 source image is not modified by this function. + +@param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero +pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold , +#adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one. +If mode equals to #RETR_CCOMP or #RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1). +@param contours Detected contours. Each contour is stored as a vector of points (e.g. +std::vector<std::vector<cv::Point> >). +@param hierarchy Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has +as many elements as the number of contours. For each i-th contour contours[i], the elements +hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices +in contours of the next and previous contours at the same hierarchical level, the first child +contour and the parent contour, respectively. If for the contour i there are no next, previous, +parent, or nested contours, the corresponding elements of hierarchy[i] will be negative. +@param mode Contour retrieval mode, see #RetrievalModes +@param method Contour approximation method, see #ContourApproximationModes +@param offset Optional offset by which every contour point is shifted. This is useful if the +contours are extracted from the image ROI and then they should be analyzed in the whole image +context. + */ +CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours, + OutputArray hierarchy, int mode, + int method, Point offset = Point()); + +/** @overload */ +CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours, + int mode, int method, Point offset = Point()); + +/** @example samples/cpp/squares.cpp +A program using pyramid scaling, Canny, contours and contour simplification to find +squares in a list of images (pic1-6.png). Returns sequence of squares detected on the image. +*/ + +/** @example samples/tapi/squares.cpp +A program using pyramid scaling, Canny, contours and contour simplification to find +squares in the input image. +*/ + +/** @brief Approximates a polygonal curve(s) with the specified precision. + +The function cv::approxPolyDP approximates a curve or a polygon with another curve/polygon with less +vertices so that the distance between them is less or equal to the specified precision. It uses the +Douglas-Peucker algorithm <http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm> + +@param curve Input vector of a 2D point stored in std::vector or Mat +@param approxCurve Result of the approximation. The type should match the type of the input curve. +@param epsilon Parameter specifying the approximation accuracy. This is the maximum distance +between the original curve and its approximation. +@param closed If true, the approximated curve is closed (its first and last vertices are +connected). Otherwise, it is not closed. + */ +CV_EXPORTS_W void approxPolyDP( InputArray curve, + OutputArray approxCurve, + double epsilon, bool closed ); + +/** @brief Calculates a contour perimeter or a curve length. + +The function computes a curve length or a closed contour perimeter. + +@param curve Input vector of 2D points, stored in std::vector or Mat. +@param closed Flag indicating whether the curve is closed or not. + */ +CV_EXPORTS_W double arcLength( InputArray curve, bool closed ); + +/** @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image. + +The function calculates and returns the minimal up-right bounding rectangle for the specified point set or +non-zero pixels of gray-scale image. + +@param array Input gray-scale image or 2D point set, stored in std::vector or Mat. + */ +CV_EXPORTS_W Rect boundingRect( InputArray array ); + +/** @brief Calculates a contour area. + +The function computes a contour area. Similarly to moments , the area is computed using the Green +formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using +#drawContours or #fillPoly , can be different. Also, the function will most certainly give a wrong +results for contours with self-intersections. + +Example: +@code + vector<Point> contour; + contour.push_back(Point2f(0, 0)); + contour.push_back(Point2f(10, 0)); + contour.push_back(Point2f(10, 10)); + contour.push_back(Point2f(5, 4)); + + double area0 = contourArea(contour); + vector<Point> approx; + approxPolyDP(contour, approx, 5, true); + double area1 = contourArea(approx); + + cout << "area0 =" << area0 << endl << + "area1 =" << area1 << endl << + "approx poly vertices" << approx.size() << endl; +@endcode +@param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat. +@param oriented Oriented area flag. If it is true, the function returns a signed area value, +depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can +determine orientation of a contour by taking the sign of an area. By default, the parameter is +false, which means that the absolute value is returned. + */ +CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false ); + +/** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set. + +The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a +specified point set. Developer should keep in mind that the returned RotatedRect can contain negative +indices when data is close to the containing Mat element boundary. + +@param points Input vector of 2D points, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect minAreaRect( InputArray points ); + +/** @brief Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle. + +The function finds the four vertices of a rotated rectangle. This function is useful to draw the +rectangle. In C++, instead of using this function, you can directly use RotatedRect::points method. Please +visit the @ref tutorial_bounding_rotated_ellipses "tutorial on Creating Bounding rotated boxes and ellipses for contours" for more information. + +@param box The input rotated rectangle. It may be the output of +@param points The output array of four vertices of rectangles. + */ +CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points); + +/** @brief Finds a circle of the minimum area enclosing a 2D point set. + +The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. + +@param points Input vector of 2D points, stored in std::vector\<\> or Mat +@param center Output center of the circle. +@param radius Output radius of the circle. + */ +CV_EXPORTS_W void minEnclosingCircle( InputArray points, + CV_OUT Point2f& center, CV_OUT float& radius ); + +/** @example samples/cpp/minarea.cpp +*/ + +/** @brief Finds a triangle of minimum area enclosing a 2D point set and returns its area. + +The function finds a triangle of minimum area enclosing the given set of 2D points and returns its +area. The output for a given 2D point set is shown in the image below. 2D points are depicted in +*red* and the enclosing triangle in *yellow*. + +![Sample output of the minimum enclosing triangle function](pics/minenclosingtriangle.png) + +The implementation of the algorithm is based on O'Rourke's @cite ORourke86 and Klee and Laskowski's +@cite KleeLaskowski85 papers. O'Rourke provides a \f$\theta(n)\f$ algorithm for finding the minimal +enclosing triangle of a 2D convex polygon with n vertices. Since the #minEnclosingTriangle function +takes a 2D point set as input an additional preprocessing step of computing the convex hull of the +2D point set is required. The complexity of the #convexHull function is \f$O(n log(n))\f$ which is higher +than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log(n))\f$. + +@param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat +@param triangle Output vector of three 2D points defining the vertices of the triangle. The depth +of the OutputArray must be CV_32F. + */ +CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle ); + +/** @brief Compares two shapes. + +The function compares two shapes. All three implemented methods use the Hu invariants (see #HuMoments) + +@param contour1 First contour or grayscale image. +@param contour2 Second contour or grayscale image. +@param method Comparison method, see #ShapeMatchModes +@param parameter Method-specific parameter (not supported now). + */ +CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2, + int method, double parameter ); + +/** @example samples/cpp/convexhull.cpp +An example using the convexHull functionality +*/ + +/** @brief Finds the convex hull of a point set. + +The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82 +that has *O(N logN)* complexity in the current implementation. + +@param points Input 2D point set, stored in std::vector or Mat. +@param hull Output convex hull. It is either an integer vector of indices or vector of points. In +the first case, the hull elements are 0-based indices of the convex hull points in the original +array (since the set of convex hull points is a subset of the original point set). In the second +case, hull elements are the convex hull points themselves. +@param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise. +Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing +to the right, and its Y axis pointing upwards. +@param returnPoints Operation flag. In case of a matrix, when the flag is true, the function +returns convex hull points. Otherwise, it returns indices of the convex hull points. When the +output array is std::vector, the flag is ignored, and the output depends on the type of the +vector: std::vector\<int\> implies returnPoints=false, std::vector\<Point\> implies +returnPoints=true. + +@note `points` and `hull` should be different arrays, inplace processing isn't supported. + +Check @ref tutorial_hull "the corresponding tutorial" for more details. + +useful links: + +https://www.learnopencv.com/convex-hull-using-opencv-in-python-and-c/ + */ +CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull, + bool clockwise = false, bool returnPoints = true ); + +/** @brief Finds the convexity defects of a contour. + +The figure below displays convexity defects of a hand contour: + +![image](pics/defects.png) + +@param contour Input contour. +@param convexhull Convex hull obtained using convexHull that should contain indices of the contour +points that make the hull. +@param convexityDefects The output vector of convexity defects. In C++ and the new Python/Java +interface each convexity defect is represented as 4-element integer vector (a.k.a. #Vec4i): +(start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices +in the original contour of the convexity defect beginning, end and the farthest point, and +fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the +farthest contour point and the hull. That is, to get the floating-point value of the depth will be +fixpt_depth/256.0. + */ +CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects ); + +/** @brief Tests a contour convexity. + +The function tests whether the input contour is convex or not. The contour must be simple, that is, +without self-intersections. Otherwise, the function output is undefined. + +@param contour Input vector of 2D points, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W bool isContourConvex( InputArray contour ); + +//! finds intersection of two convex polygons +CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2, + OutputArray _p12, bool handleNested = true ); + +/** @example samples/cpp/fitellipse.cpp +An example using the fitEllipse technique +*/ + +/** @brief Fits an ellipse around a set of 2D points. + +The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of +all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by @cite Fitzgibbon95 +is used. Developer should keep in mind that it is possible that the returned +ellipse/rotatedRect data contains negative indices, due to the data points being close to the +border of the containing Mat element. + +@param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipse( InputArray points ); + +/** @brief Fits an ellipse around a set of 2D points. + + The function calculates the ellipse that fits a set of 2D points. + It returns the rotated rectangle in which the ellipse is inscribed. + The Approximate Mean Square (AMS) proposed by @cite Taubin1991 is used. + + For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$, + which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$. + However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$, + the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines, + quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. + If the fit is found to be a parabolic or hyperbolic function then the standard #fitEllipse method is used. + The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves + by imposing the condition that \f$ A^T ( D_x^T D_x + D_y^T D_y) A = 1 \f$ where + the matrices \f$ Dx \f$ and \f$ Dy \f$ are the partial derivatives of the design matrix \f$ D \f$ with + respect to x and y. The matrices are formed row by row applying the following to + each of the points in the set: + \f{align*}{ + D(i,:)&=\left\{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right\} & + D_x(i,:)&=\left\{2 x_i,y_i,0,1,0,0\right\} & + D_y(i,:)&=\left\{0,x_i,2 y_i,0,1,0\right\} + \f} + The AMS method minimizes the cost function + \f{equation*}{ + \epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T } + \f} + + The minimum cost is found by solving the generalized eigenvalue problem. + + \f{equation*}{ + D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A + \f} + + @param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipseAMS( InputArray points ); + + +/** @brief Fits an ellipse around a set of 2D points. + + The function calculates the ellipse that fits a set of 2D points. + It returns the rotated rectangle in which the ellipse is inscribed. + The Direct least square (Direct) method by @cite Fitzgibbon1999 is used. + + For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$, + which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$. + However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$, + the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines, + quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. + The Direct method confines the fit to ellipses by ensuring that \f$ 4 A_{xx} A_{yy}- A_{xy}^2 > 0 \f$. + The condition imposed is that \f$ 4 A_{xx} A_{yy}- A_{xy}^2=1 \f$ which satisfies the inequality + and as the coefficients can be arbitrarily scaled is not overly restrictive. + + \f{equation*}{ + \epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix} + 0 & 0 & 2 & 0 & 0 & 0 \\ + 0 & -1 & 0 & 0 & 0 & 0 \\ + 2 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 + \end{matrix} \right) + \f} + + The minimum cost is found by solving the generalized eigenvalue problem. + + \f{equation*}{ + D^T D A = \lambda \left( C\right) A + \f} + + The system produces only one positive eigenvalue \f$ \lambda\f$ which is chosen as the solution + with its eigenvector \f$\mathbf{u}\f$. These are used to find the coefficients + + \f{equation*}{ + A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u} + \f} + The scaling factor guarantees that \f$A^T C A =1\f$. + + @param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipseDirect( InputArray points ); + +/** @brief Fits a line to a 2D or 3D point set. + +The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where +\f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance function, one +of the following: +- DIST_L2 +\f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f] +- DIST_L1 +\f[\rho (r) = r\f] +- DIST_L12 +\f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f] +- DIST_FAIR +\f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f] +- DIST_WELSCH +\f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f] +- DIST_HUBER +\f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f] + +The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique +that iteratively fits the line using the weighted least-squares algorithm. After each iteration the +weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ . + +@param points Input vector of 2D or 3D points, stored in std::vector\<\> or Mat. +@param line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements +(like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and +(x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like +Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line +and (x0, y0, z0) is a point on the line. +@param distType Distance used by the M-estimator, see #DistanceTypes +@param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value +is chosen. +@param reps Sufficient accuracy for the radius (distance between the coordinate origin and the line). +@param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps. + */ +CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType, + double param, double reps, double aeps ); + +/** @brief Performs a point-in-contour test. + +The function determines whether the point is inside a contour, outside, or lies on an edge (or +coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge) +value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively. +Otherwise, the return value is a signed distance between the point and the nearest contour edge. + +See below a sample output of the function where each image pixel is tested against the contour: + +![sample output](pics/pointpolygon.png) + +@param contour Input contour. +@param pt Point tested against the contour. +@param measureDist If true, the function estimates the signed distance from the point to the +nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not. + */ +CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist ); + +/** @brief Finds out if there is any intersection between two rotated rectangles. + +If there is then the vertices of the intersecting region are returned as well. + +Below are some examples of intersection configurations. The hatched pattern indicates the +intersecting region and the red vertices are returned by the function. + +![intersection examples](pics/intersection.png) + +@param rect1 First rectangle +@param rect2 Second rectangle +@param intersectingRegion The output array of the vertices of the intersecting region. It returns +at most 8 vertices. Stored as std::vector\<cv::Point2f\> or cv::Mat as Mx1 of type CV_32FC2. +@returns One of #RectanglesIntersectTypes + */ +CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ); + +/** @brief Creates a smart pointer to a cv::GeneralizedHoughBallard class and initializes it. +*/ +CV_EXPORTS Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard(); + +/** @brief Creates a smart pointer to a cv::GeneralizedHoughGuil class and initializes it. +*/ +CV_EXPORTS Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil(); + +//! @} imgproc_shape + +//! @addtogroup imgproc_colormap +//! @{ + +//! GNU Octave/MATLAB equivalent colormaps +enum ColormapTypes +{ + COLORMAP_AUTUMN = 0, //!< ![autumn](pics/colormaps/colorscale_autumn.jpg) + COLORMAP_BONE = 1, //!< ![bone](pics/colormaps/colorscale_bone.jpg) + COLORMAP_JET = 2, //!< ![jet](pics/colormaps/colorscale_jet.jpg) + COLORMAP_WINTER = 3, //!< ![winter](pics/colormaps/colorscale_winter.jpg) + COLORMAP_RAINBOW = 4, //!< ![rainbow](pics/colormaps/colorscale_rainbow.jpg) + COLORMAP_OCEAN = 5, //!< ![ocean](pics/colormaps/colorscale_ocean.jpg) + COLORMAP_SUMMER = 6, //!< ![summer](pics/colormaps/colorscale_summer.jpg) + COLORMAP_SPRING = 7, //!< ![spring](pics/colormaps/colorscale_spring.jpg) + COLORMAP_COOL = 8, //!< ![cool](pics/colormaps/colorscale_cool.jpg) + COLORMAP_HSV = 9, //!< ![HSV](pics/colormaps/colorscale_hsv.jpg) + COLORMAP_PINK = 10, //!< ![pink](pics/colormaps/colorscale_pink.jpg) + COLORMAP_HOT = 11, //!< ![hot](pics/colormaps/colorscale_hot.jpg) + COLORMAP_PARULA = 12, //!< ![parula](pics/colormaps/colorscale_parula.jpg) + COLORMAP_MAGMA = 13, //!< ![magma](pics/colormaps/colorscale_magma.jpg) + COLORMAP_INFERNO = 14, //!< ![inferno](pics/colormaps/colorscale_inferno.jpg) + COLORMAP_PLASMA = 15, //!< ![plasma](pics/colormaps/colorscale_plasma.jpg) + COLORMAP_VIRIDIS = 16, //!< ![viridis](pics/colormaps/colorscale_viridis.jpg) + COLORMAP_CIVIDIS = 17, //!< ![cividis](pics/colormaps/colorscale_cividis.jpg) + COLORMAP_TWILIGHT = 18, //!< ![twilight](pics/colormaps/colorscale_twilight.jpg) + COLORMAP_TWILIGHT_SHIFTED = 19 //!< ![twilight shifted](pics/colormaps/colorscale_twilight_shifted.jpg) +}; + +/** @example samples/cpp/falsecolor.cpp +An example using applyColorMap function +*/ + +/** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image. + +@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. +@param dst The result is the colormapped source image. Note: Mat::create is called on dst. +@param colormap The colormap to apply, see #ColormapTypes +*/ +CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); + +/** @brief Applies a user colormap on a given image. + +@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. +@param dst The result is the colormapped source image. Note: Mat::create is called on dst. +@param userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 256 +*/ +CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray userColor); + +//! @} imgproc_colormap + +//! @addtogroup imgproc_draw +//! @{ + + +/** OpenCV color channel order is BGR[A] */ +#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0) + +/** @brief Draws a line segment connecting two points. + +The function line draws the line segment between pt1 and pt2 points in the image. The line is +clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected +or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased +lines are drawn using Gaussian filtering. + +@param img Image. +@param pt1 First point of the line segment. +@param pt2 Second point of the line segment. +@param color Line color. +@param thickness Line thickness. +@param lineType Type of the line. See #LineTypes. +@param shift Number of fractional bits in the point coordinates. + */ +CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, + int thickness = 1, int lineType = LINE_8, int shift = 0); + +/** @brief Draws a arrow segment pointing from the first point to the second one. + +The function cv::arrowedLine draws an arrow between pt1 and pt2 points in the image. See also #line. + +@param img Image. +@param pt1 The point the arrow starts from. +@param pt2 The point the arrow points to. +@param color Line color. +@param thickness Line thickness. +@param line_type Type of the line. See #LineTypes +@param shift Number of fractional bits in the point coordinates. +@param tipLength The length of the arrow tip in relation to the arrow length + */ +CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, + int thickness=1, int line_type=8, int shift=0, double tipLength=0.1); + +/** @brief Draws a simple, thick, or filled up-right rectangle. + +The function cv::rectangle draws a rectangle outline or a filled rectangle whose two opposite corners +are pt1 and pt2. + +@param img Image. +@param pt1 Vertex of the rectangle. +@param pt2 Vertex of the rectangle opposite to pt1 . +@param color Rectangle color or brightness (grayscale image). +@param thickness Thickness of lines that make up the rectangle. Negative values, like #FILLED, +mean that the function has to draw a filled rectangle. +@param lineType Type of the line. See #LineTypes +@param shift Number of fractional bits in the point coordinates. + */ +CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @overload + +use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and +r.br()-Point(1,1)` are opposite corners +*/ +CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_2.cpp +An example using drawing functions +*/ + +/** @brief Draws a circle. + +The function cv::circle draws a simple or filled circle with a given center and radius. +@param img Image where the circle is drawn. +@param center Center of the circle. +@param radius Radius of the circle. +@param color Circle color. +@param thickness Thickness of the circle outline, if positive. Negative values, like #FILLED, +mean that a filled circle is to be drawn. +@param lineType Type of the circle boundary. See #LineTypes +@param shift Number of fractional bits in the coordinates of the center and in the radius value. + */ +CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @brief Draws a simple or thick elliptic arc or fills an ellipse sector. + +The function cv::ellipse with more parameters draws an ellipse outline, a filled ellipse, an elliptic +arc, or a filled ellipse sector. The drawing code uses general parametric form. +A piecewise-linear curve is used to approximate the elliptic arc +boundary. If you need more control of the ellipse rendering, you can retrieve the curve using +#ellipse2Poly and then render it with #polylines or fill it with #fillPoly. If you use the first +variant of the function and want to draw the whole ellipse, not an arc, pass `startAngle=0` and +`endAngle=360`. If `startAngle` is greater than `endAngle`, they are swapped. The figure below explains +the meaning of the parameters to draw the blue arc. + +![Parameters of Elliptic Arc](pics/ellipse.svg) + +@param img Image. +@param center Center of the ellipse. +@param axes Half of the size of the ellipse main axes. +@param angle Ellipse rotation angle in degrees. +@param startAngle Starting angle of the elliptic arc in degrees. +@param endAngle Ending angle of the elliptic arc in degrees. +@param color Ellipse color. +@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that +a filled ellipse sector is to be drawn. +@param lineType Type of the ellipse boundary. See #LineTypes +@param shift Number of fractional bits in the coordinates of the center and values of axes. + */ +CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes, + double angle, double startAngle, double endAngle, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @overload +@param img Image. +@param box Alternative ellipse representation via RotatedRect. This means that the function draws +an ellipse inscribed in the rotated rectangle. +@param color Ellipse color. +@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that +a filled ellipse sector is to be drawn. +@param lineType Type of the ellipse boundary. See #LineTypes +*/ +CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Scalar& color, + int thickness = 1, int lineType = LINE_8); + +/* ----------------------------------------------------------------------------------------- */ +/* ADDING A SET OF PREDEFINED MARKERS WHICH COULD BE USED TO HIGHLIGHT POSITIONS IN AN IMAGE */ +/* ----------------------------------------------------------------------------------------- */ + +//! Possible set of marker types used for the cv::drawMarker function +enum MarkerTypes +{ + MARKER_CROSS = 0, //!< A crosshair marker shape + MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape + MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross + MARKER_DIAMOND = 3, //!< A diamond marker shape + MARKER_SQUARE = 4, //!< A square marker shape + MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape + MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape +}; + +/** @brief Draws a marker on a predefined position in an image. + +The function cv::drawMarker draws a marker on a given position in the image. For the moment several +marker types are supported, see #MarkerTypes for more information. + +@param img Image. +@param position The point where the crosshair is positioned. +@param color Line color. +@param markerType The specific type of marker you want to use, see #MarkerTypes +@param thickness Line thickness. +@param line_type Type of the line, See #LineTypes +@param markerSize The length of the marker axis [default = 20 pixels] + */ +CV_EXPORTS_W void drawMarker(CV_IN_OUT Mat& img, Point position, const Scalar& color, + int markerType = MARKER_CROSS, int markerSize=20, int thickness=1, + int line_type=8); + +/* ----------------------------------------------------------------------------------------- */ +/* END OF MARKER SECTION */ +/* ----------------------------------------------------------------------------------------- */ + +/** @overload */ +CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts, + const Scalar& color, int lineType = LINE_8, + int shift = 0); + +/** @brief Fills a convex polygon. + +The function cv::fillConvexPoly draws a filled convex polygon. This function is much faster than the +function #fillPoly . It can fill not only convex polygons but any monotonic polygon without +self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line) +twice at the most (though, its top-most and/or the bottom edge could be horizontal). + +@param img Image. +@param points Polygon vertices. +@param color Polygon color. +@param lineType Type of the polygon boundaries. See #LineTypes +@param shift Number of fractional bits in the vertex coordinates. + */ +CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points, + const Scalar& color, int lineType = LINE_8, + int shift = 0); + +/** @overload */ +CV_EXPORTS void fillPoly(Mat& img, const Point** pts, + const int* npts, int ncontours, + const Scalar& color, int lineType = LINE_8, int shift = 0, + Point offset = Point() ); + +/** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_1.cpp +An example using drawing functions +Check @ref tutorial_random_generator_and_text "the corresponding tutorial" for more details +*/ + +/** @brief Fills the area bounded by one or more polygons. + +The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill +complex areas, for example, areas with holes, contours with self-intersections (some of their +parts), and so forth. + +@param img Image. +@param pts Array of polygons where each polygon is represented as an array of points. +@param color Polygon color. +@param lineType Type of the polygon boundaries. See #LineTypes +@param shift Number of fractional bits in the vertex coordinates. +@param offset Optional offset of all points of the contours. + */ +CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts, + const Scalar& color, int lineType = LINE_8, int shift = 0, + Point offset = Point() ); + +/** @overload */ +CV_EXPORTS void polylines(Mat& img, const Point* const* pts, const int* npts, + int ncontours, bool isClosed, const Scalar& color, + int thickness = 1, int lineType = LINE_8, int shift = 0 ); + +/** @brief Draws several polygonal curves. + +@param img Image. +@param pts Array of polygonal curves. +@param isClosed Flag indicating whether the drawn polylines are closed or not. If they are closed, +the function draws a line from the last vertex of each curve to its first vertex. +@param color Polyline color. +@param thickness Thickness of the polyline edges. +@param lineType Type of the line segments. See #LineTypes +@param shift Number of fractional bits in the vertex coordinates. + +The function cv::polylines draws one or more polygonal curves. + */ +CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts, + bool isClosed, const Scalar& color, + int thickness = 1, int lineType = LINE_8, int shift = 0 ); + +/** @example samples/cpp/contours2.cpp +An example program illustrates the use of cv::findContours and cv::drawContours +\image html WindowsQtContoursOutput.png "Screenshot of the program" +*/ + +/** @example samples/cpp/segment_objects.cpp +An example using drawContours to clean up a background segmentation result +*/ + +/** @brief Draws contours outlines or filled contours. + +The function draws contour outlines in the image if \f$\texttt{thickness} \ge 0\f$ or fills the area +bounded by the contours if \f$\texttt{thickness}<0\f$ . The example below shows how to retrieve +connected components from the binary image and label them: : +@include snippets/imgproc_drawContours.cpp + +@param image Destination image. +@param contours All the input contours. Each contour is stored as a point vector. +@param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn. +@param color Color of the contours. +@param thickness Thickness of lines the contours are drawn with. If it is negative (for example, +thickness=#FILLED ), the contour interiors are drawn. +@param lineType Line connectivity. See #LineTypes +@param hierarchy Optional information about hierarchy. It is only needed if you want to draw only +some of the contours (see maxLevel ). +@param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn. +If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function +draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This +parameter is only taken into account when there is hierarchy available. +@param offset Optional contour shift parameter. Shift all the drawn contours by the specified +\f$\texttt{offset}=(dx,dy)\f$ . +@note When thickness=#FILLED, the function is designed to handle connected components with holes correctly +even when no hierarchy date is provided. This is done by analyzing all the outlines together +using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved +contours. In order to solve this problem, you need to call #drawContours separately for each sub-group +of contours, or iterate over the collection using contourIdx parameter. + */ +CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours, + int contourIdx, const Scalar& color, + int thickness = 1, int lineType = LINE_8, + InputArray hierarchy = noArray(), + int maxLevel = INT_MAX, Point offset = Point() ); + +/** @brief Clips the line against the image rectangle. + +The function cv::clipLine calculates a part of the line segment that is entirely within the specified +rectangle. it returns false if the line segment is completely outside the rectangle. Otherwise, +it returns true . +@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . +@param pt1 First line point. +@param pt2 Second line point. + */ +CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2); + +/** @overload +@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . +@param pt1 First line point. +@param pt2 Second line point. +*/ +CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2); + +/** @overload +@param imgRect Image rectangle. +@param pt1 First line point. +@param pt2 Second line point. +*/ +CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2); + +/** @brief Approximates an elliptic arc with a polyline. + +The function ellipse2Poly computes the vertices of a polyline that approximates the specified +elliptic arc. It is used by #ellipse. If `arcStart` is greater than `arcEnd`, they are swapped. + +@param center Center of the arc. +@param axes Half of the size of the ellipse main axes. See #ellipse for details. +@param angle Rotation angle of the ellipse in degrees. See #ellipse for details. +@param arcStart Starting angle of the elliptic arc in degrees. +@param arcEnd Ending angle of the elliptic arc in degrees. +@param delta Angle between the subsequent polyline vertices. It defines the approximation +accuracy. +@param pts Output vector of polyline vertices. + */ +CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, + int arcStart, int arcEnd, int delta, + CV_OUT std::vector<Point>& pts ); + +/** @overload +@param center Center of the arc. +@param axes Half of the size of the ellipse main axes. See #ellipse for details. +@param angle Rotation angle of the ellipse in degrees. See #ellipse for details. +@param arcStart Starting angle of the elliptic arc in degrees. +@param arcEnd Ending angle of the elliptic arc in degrees. +@param delta Angle between the subsequent polyline vertices. It defines the approximation accuracy. +@param pts Output vector of polyline vertices. +*/ +CV_EXPORTS void ellipse2Poly(Point2d center, Size2d axes, int angle, + int arcStart, int arcEnd, int delta, + CV_OUT std::vector<Point2d>& pts); + +/** @brief Draws a text string. + +The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered +using the specified font are replaced by question marks. See #getTextSize for a text rendering code +example. + +@param img Image. +@param text Text string to be drawn. +@param org Bottom-left corner of the text string in the image. +@param fontFace Font type, see #HersheyFonts. +@param fontScale Font scale factor that is multiplied by the font-specific base size. +@param color Text color. +@param thickness Thickness of the lines used to draw a text. +@param lineType Line type. See #LineTypes +@param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, +it is at the top-left corner. + */ +CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org, + int fontFace, double fontScale, Scalar color, + int thickness = 1, int lineType = LINE_8, + bool bottomLeftOrigin = false ); + +/** @brief Calculates the width and height of a text string. + +The function cv::getTextSize calculates and returns the size of a box that contains the specified text. +That is, the following code renders some text, the tight box surrounding it, and the baseline: : +@code + String text = "Funny text inside the box"; + int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; + double fontScale = 2; + int thickness = 3; + + Mat img(600, 800, CV_8UC3, Scalar::all(0)); + + int baseline=0; + Size textSize = getTextSize(text, fontFace, + fontScale, thickness, &baseline); + baseline += thickness; + + // center the text + Point textOrg((img.cols - textSize.width)/2, + (img.rows + textSize.height)/2); + + // draw the box + rectangle(img, textOrg + Point(0, baseline), + textOrg + Point(textSize.width, -textSize.height), + Scalar(0,0,255)); + // ... and the baseline first + line(img, textOrg + Point(0, thickness), + textOrg + Point(textSize.width, thickness), + Scalar(0, 0, 255)); + + // then put the text itself + putText(img, text, textOrg, fontFace, fontScale, + Scalar::all(255), thickness, 8); +@endcode + +@param text Input text string. +@param fontFace Font to use, see #HersheyFonts. +@param fontScale Font scale factor that is multiplied by the font-specific base size. +@param thickness Thickness of lines used to render the text. See #putText for details. +@param[out] baseLine y-coordinate of the baseline relative to the bottom-most text +point. +@return The size of a box that contains the specified text. + +@see putText + */ +CV_EXPORTS_W Size getTextSize(const String& text, int fontFace, + double fontScale, int thickness, + CV_OUT int* baseLine); + + +/** @brief Calculates the font-specific size to use to achieve a given height in pixels. + +@param fontFace Font to use, see cv::HersheyFonts. +@param pixelHeight Pixel height to compute the fontScale for +@param thickness Thickness of lines used to render the text.See putText for details. +@return The fontSize to use for cv::putText + +@see cv::putText +*/ +CV_EXPORTS_W double getFontScaleFromHeight(const int fontFace, + const int pixelHeight, + const int thickness = 1); + +/** @brief Line iterator + +The class is used to iterate over all the pixels on the raster line +segment connecting two specified points. + +The class LineIterator is used to get each pixel of a raster line. It +can be treated as versatile implementation of the Bresenham algorithm +where you can stop at each pixel and do some extra processing, for +example, grab pixel values along the line or draw a line with an effect +(for example, with XOR operation). + +The number of pixels along the line is stored in LineIterator::count. +The method LineIterator::pos returns the current position in the image: + +@code{.cpp} +// grabs pixels along the line (pt1, pt2) +// from 8-bit 3-channel image to the buffer +LineIterator it(img, pt1, pt2, 8); +LineIterator it2 = it; +vector<Vec3b> buf(it.count); + +for(int i = 0; i < it.count; i++, ++it) + buf[i] = *(const Vec3b*)*it; + +// alternative way of iterating through the line +for(int i = 0; i < it2.count; i++, ++it2) +{ + Vec3b val = img.at<Vec3b>(it2.pos()); + CV_Assert(buf[i] == val); +} +@endcode +*/ +class CV_EXPORTS LineIterator +{ +public: + /** @brief initializes the iterator + + creates iterators for the line connecting pt1 and pt2 + the line will be clipped on the image boundaries + the line is 8-connected or 4-connected + If leftToRight=true, then the iteration is always done + from the left-most point to the right most, + not to depend on the ordering of pt1 and pt2 parameters + */ + LineIterator( const Mat& img, Point pt1, Point pt2, + int connectivity = 8, bool leftToRight = false ); + /** @brief returns pointer to the current pixel + */ + uchar* operator *(); + /** @brief prefix increment operator (++it). shifts iterator to the next pixel + */ + LineIterator& operator ++(); + /** @brief postfix increment operator (it++). shifts iterator to the next pixel + */ + LineIterator operator ++(int); + /** @brief returns coordinates of the current pixel + */ + Point pos() const; + + uchar* ptr; + const uchar* ptr0; + int step, elemSize; + int err, count; + int minusDelta, plusDelta; + int minusStep, plusStep; +}; + +//! @cond IGNORED + +// === LineIterator implementation === + +inline +uchar* LineIterator::operator *() +{ + return ptr; +} + +inline +LineIterator& LineIterator::operator ++() +{ + int mask = err < 0 ? -1 : 0; + err += minusDelta + (plusDelta & mask); + ptr += minusStep + (plusStep & mask); + return *this; +} + +inline +LineIterator LineIterator::operator ++(int) +{ + LineIterator it = *this; + ++(*this); + return it; +} + +inline +Point LineIterator::pos() const +{ + Point p; + p.y = (int)((ptr - ptr0)/step); + p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize); + return p; +} + +//! @endcond + +//! @} imgproc_draw + +//! @} imgproc + +} // cv + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/imgproc/imgproc_c.h" +#endif + +#endif diff --git a/include/opencv2/imgproc/detail/distortion_model.hpp b/include/opencv2/imgproc/detail/distortion_model.hpp new file mode 100644 index 0000000..a9c3dde --- /dev/null +++ b/include/opencv2/imgproc/detail/distortion_model.hpp @@ -0,0 +1,123 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP +#define OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP + +//! @cond IGNORED + +namespace cv { namespace detail { +/** +Computes the matrix for the projection onto a tilted image sensor +\param tauX angular parameter rotation around x-axis +\param tauY angular parameter rotation around y-axis +\param matTilt if not NULL returns the matrix +\f[ +\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} +{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} +{0}{0}{1} R(\tau_x, \tau_y) +\f] +where +\f[ +R(\tau_x, \tau_y) = +\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)} +\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} = +\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)} +{0}{\cos(\tau_x)}{\sin(\tau_x)} +{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}. +\f] +\param dMatTiltdTauX if not NULL it returns the derivative of matTilt with +respect to \f$\tau_x\f$. +\param dMatTiltdTauY if not NULL it returns the derivative of matTilt with +respect to \f$\tau_y\f$. +\param invMatTilt if not NULL it returns the inverse of matTilt +**/ +template <typename FLOAT> +void computeTiltProjectionMatrix(FLOAT tauX, + FLOAT tauY, + Matx<FLOAT, 3, 3>* matTilt = 0, + Matx<FLOAT, 3, 3>* dMatTiltdTauX = 0, + Matx<FLOAT, 3, 3>* dMatTiltdTauY = 0, + Matx<FLOAT, 3, 3>* invMatTilt = 0) +{ + FLOAT cTauX = cos(tauX); + FLOAT sTauX = sin(tauX); + FLOAT cTauY = cos(tauY); + FLOAT sTauY = sin(tauY); + Matx<FLOAT, 3, 3> matRotX = Matx<FLOAT, 3, 3>(1,0,0,0,cTauX,sTauX,0,-sTauX,cTauX); + Matx<FLOAT, 3, 3> matRotY = Matx<FLOAT, 3, 3>(cTauY,0,-sTauY,0,1,0,sTauY,0,cTauY); + Matx<FLOAT, 3, 3> matRotXY = matRotY * matRotX; + Matx<FLOAT, 3, 3> matProjZ = Matx<FLOAT, 3, 3>(matRotXY(2,2),0,-matRotXY(0,2),0,matRotXY(2,2),-matRotXY(1,2),0,0,1); + if (matTilt) + { + // Matrix for trapezoidal distortion of tilted image sensor + *matTilt = matProjZ * matRotXY; + } + if (dMatTiltdTauX) + { + // Derivative with respect to tauX + Matx<FLOAT, 3, 3> dMatRotXYdTauX = matRotY * Matx<FLOAT, 3, 3>(0,0,0,0,-sTauX,cTauX,0,-cTauX,-sTauX); + Matx<FLOAT, 3, 3> dMatProjZdTauX = Matx<FLOAT, 3, 3>(dMatRotXYdTauX(2,2),0,-dMatRotXYdTauX(0,2), + 0,dMatRotXYdTauX(2,2),-dMatRotXYdTauX(1,2),0,0,0); + *dMatTiltdTauX = (matProjZ * dMatRotXYdTauX) + (dMatProjZdTauX * matRotXY); + } + if (dMatTiltdTauY) + { + // Derivative with respect to tauY + Matx<FLOAT, 3, 3> dMatRotXYdTauY = Matx<FLOAT, 3, 3>(-sTauY,0,-cTauY,0,0,0,cTauY,0,-sTauY) * matRotX; + Matx<FLOAT, 3, 3> dMatProjZdTauY = Matx<FLOAT, 3, 3>(dMatRotXYdTauY(2,2),0,-dMatRotXYdTauY(0,2), + 0,dMatRotXYdTauY(2,2),-dMatRotXYdTauY(1,2),0,0,0); + *dMatTiltdTauY = (matProjZ * dMatRotXYdTauY) + (dMatProjZdTauY * matRotXY); + } + if (invMatTilt) + { + FLOAT inv = 1./matRotXY(2,2); + Matx<FLOAT, 3, 3> invMatProjZ = Matx<FLOAT, 3, 3>(inv,0,inv*matRotXY(0,2),0,inv,inv*matRotXY(1,2),0,0,1); + *invMatTilt = matRotXY.t()*invMatProjZ; + } +} +}} // namespace detail, cv + + +//! @endcond + +#endif // OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP diff --git a/include/opencv2/imgproc/hal/hal.hpp b/include/opencv2/imgproc/hal/hal.hpp new file mode 100644 index 0000000..a435fd6 --- /dev/null +++ b/include/opencv2/imgproc/hal/hal.hpp @@ -0,0 +1,241 @@ +#ifndef CV_IMGPROC_HAL_HPP +#define CV_IMGPROC_HAL_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/hal/interface.h" + +namespace cv { namespace hal { + +//! @addtogroup imgproc_hal_functions +//! @{ + +//--------------------------- +//! @cond IGNORED + +struct CV_EXPORTS Filter2D +{ + CV_DEPRECATED static Ptr<hal::Filter2D> create(uchar * , size_t , int , + int , int , + int , int , + int , int , + int , double , + int , int , + bool , bool ); + virtual void apply(uchar * , size_t , + uchar * , size_t , + int , int , + int , int , + int , int ) = 0; + virtual ~Filter2D() {} +}; + +struct CV_EXPORTS SepFilter2D +{ + CV_DEPRECATED static Ptr<hal::SepFilter2D> create(int , int , int , + uchar * , int , + uchar * , int , + int , int , + double , int ); + virtual void apply(uchar * , size_t , + uchar * , size_t , + int , int , + int , int , + int , int ) = 0; + virtual ~SepFilter2D() {} +}; + + +struct CV_EXPORTS Morph +{ + CV_DEPRECATED static Ptr<hal::Morph> create(int , int , int , int , int , + int , uchar * , size_t , + int , int , + int , int , + int , const double *, + int , bool , bool ); + virtual void apply(uchar * , size_t , uchar * , size_t , int , int , + int , int , int , int , + int , int , int , int ) = 0; + virtual ~Morph() {} +}; + +//! @endcond +//--------------------------- + +CV_EXPORTS void filter2D(int stype, int dtype, int kernel_type, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int full_width, int full_height, + int offset_x, int offset_y, + uchar * kernel_data, size_t kernel_step, + int kernel_width, int kernel_height, + int anchor_x, int anchor_y, + double delta, int borderType, + bool isSubmatrix); + +CV_EXPORTS void sepFilter2D(int stype, int dtype, int ktype, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int full_width, int full_height, + int offset_x, int offset_y, + uchar * kernelx_data, int kernelx_len, + uchar * kernely_data, int kernely_len, + int anchor_x, int anchor_y, + double delta, int borderType); + +CV_EXPORTS void morph(int op, int src_type, int dst_type, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int roi_width, int roi_height, int roi_x, int roi_y, + int roi_width2, int roi_height2, int roi_x2, int roi_y2, + int kernel_type, uchar * kernel_data, size_t kernel_step, + int kernel_width, int kernel_height, int anchor_x, int anchor_y, + int borderType, const double borderValue[4], + int iterations, bool isSubmatrix); + + +CV_EXPORTS void resize(int src_type, + const uchar * src_data, size_t src_step, int src_width, int src_height, + uchar * dst_data, size_t dst_step, int dst_width, int dst_height, + double inv_scale_x, double inv_scale_y, int interpolation); + +CV_EXPORTS void warpAffine(int src_type, + const uchar * src_data, size_t src_step, int src_width, int src_height, + uchar * dst_data, size_t dst_step, int dst_width, int dst_height, + const double M[6], int interpolation, int borderType, const double borderValue[4]); + +CV_EXPORTS void warpPerspectve(int src_type, + const uchar * src_data, size_t src_step, int src_width, int src_height, + uchar * dst_data, size_t dst_step, int dst_width, int dst_height, + const double M[9], int interpolation, int borderType, const double borderValue[4]); + +CV_EXPORTS void cvtBGRtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, int dcn, bool swapBlue); + +CV_EXPORTS void cvtBGRtoBGR5x5(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int greenBits); + +CV_EXPORTS void cvtBGR5x5toBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int dcn, bool swapBlue, int greenBits); + +CV_EXPORTS void cvtBGRtoGray(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue); + +CV_EXPORTS void cvtGraytoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn); + +CV_EXPORTS void cvtBGR5x5toGray(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int greenBits); + +CV_EXPORTS void cvtGraytoBGR5x5(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int greenBits); +CV_EXPORTS void cvtBGRtoYUV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isCbCr); + +CV_EXPORTS void cvtYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isCbCr); + +CV_EXPORTS void cvtBGRtoXYZ(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue); + +CV_EXPORTS void cvtXYZtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue); + +CV_EXPORTS void cvtBGRtoHSV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isFullRange, bool isHSV); + +CV_EXPORTS void cvtHSVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isFullRange, bool isHSV); + +CV_EXPORTS void cvtBGRtoLab(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isLab, bool srgb); + +CV_EXPORTS void cvtLabtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isLab, bool srgb); + +CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +//! Separate Y and UV planes +CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * y_data, const uchar * uv_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtThreePlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtBGRtoThreePlaneYUV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int uIdx); + +//! Separate Y and UV planes +CV_EXPORTS void cvtBGRtoTwoPlaneYUV(const uchar * src_data, size_t src_step, + uchar * y_data, uchar * uv_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int dcn, bool swapBlue, int uIdx, int ycn); + +CV_EXPORTS void cvtRGBAtoMultipliedRGBA(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height); + +CV_EXPORTS void cvtMultipliedRGBAtoRGBA(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height); + +CV_EXPORTS void integral(int depth, int sdepth, int sqdepth, + const uchar* src, size_t srcstep, + uchar* sum, size_t sumstep, + uchar* sqsum, size_t sqsumstep, + uchar* tilted, size_t tstep, + int width, int height, int cn); + +//! @} + +}} + +#endif // CV_IMGPROC_HAL_HPP diff --git a/include/opencv2/imgproc/hal/interface.h b/include/opencv2/imgproc/hal/interface.h new file mode 100644 index 0000000..f8dbcfe --- /dev/null +++ b/include/opencv2/imgproc/hal/interface.h @@ -0,0 +1,46 @@ +#ifndef OPENCV_IMGPROC_HAL_INTERFACE_H +#define OPENCV_IMGPROC_HAL_INTERFACE_H + +//! @addtogroup imgproc_hal_interface +//! @{ + +//! @name Interpolation modes +//! @sa cv::InterpolationFlags +//! @{ +#define CV_HAL_INTER_NEAREST 0 +#define CV_HAL_INTER_LINEAR 1 +#define CV_HAL_INTER_CUBIC 2 +#define CV_HAL_INTER_AREA 3 +#define CV_HAL_INTER_LANCZOS4 4 +//! @} + +//! @name Morphology operations +//! @sa cv::MorphTypes +//! @{ +#define CV_HAL_MORPH_ERODE 0 +#define CV_HAL_MORPH_DILATE 1 +//! @} + +//! @name Threshold types +//! @sa cv::ThresholdTypes +//! @{ +#define CV_HAL_THRESH_BINARY 0 +#define CV_HAL_THRESH_BINARY_INV 1 +#define CV_HAL_THRESH_TRUNC 2 +#define CV_HAL_THRESH_TOZERO 3 +#define CV_HAL_THRESH_TOZERO_INV 4 +#define CV_HAL_THRESH_MASK 7 +#define CV_HAL_THRESH_OTSU 8 +#define CV_HAL_THRESH_TRIANGLE 16 +//! @} + +//! @name Adaptive threshold algorithm +//! @sa cv::AdaptiveThresholdTypes +//! @{ +#define CV_HAL_ADAPTIVE_THRESH_MEAN_C 0 +#define CV_HAL_ADAPTIVE_THRESH_GAUSSIAN_C 1 +//! @} + +//! @} + +#endif diff --git a/include/opencv2/imgproc/imgproc.hpp b/include/opencv2/imgproc/imgproc.hpp new file mode 100644 index 0000000..4175bd0 --- /dev/null +++ b/include/opencv2/imgproc/imgproc.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/imgproc.hpp" diff --git a/include/opencv2/imgproc/imgproc_c.h b/include/opencv2/imgproc/imgproc_c.h new file mode 100644 index 0000000..cec0f36 --- /dev/null +++ b/include/opencv2/imgproc/imgproc_c.h @@ -0,0 +1,1210 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_IMGPROC_IMGPROC_C_H +#define OPENCV_IMGPROC_IMGPROC_C_H + +#include "opencv2/imgproc/types_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup imgproc_c +@{ +*/ + +/*********************** Background statistics accumulation *****************************/ + +/** @brief Adds image to accumulator +@see cv::accumulate +*/ +CVAPI(void) cvAcc( const CvArr* image, CvArr* sum, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Adds squared image to accumulator +@see cv::accumulateSquare +*/ +CVAPI(void) cvSquareAcc( const CvArr* image, CvArr* sqsum, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Adds a product of two images to accumulator +@see cv::accumulateProduct +*/ +CVAPI(void) cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha +@see cv::accumulateWeighted +*/ +CVAPI(void) cvRunningAvg( const CvArr* image, CvArr* acc, double alpha, + const CvArr* mask CV_DEFAULT(NULL) ); + +/****************************************************************************************\ +* Image Processing * +\****************************************************************************************/ + +/** Copies source 2D array inside of the larger destination array and + makes a border of the specified type (IPL_BORDER_*) around the copied area. */ +CVAPI(void) cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, + int bordertype, CvScalar value CV_DEFAULT(cvScalarAll(0))); + +/** @brief Smooths the image in one of several ways. + +@param src The source image +@param dst The destination image +@param smoothtype Type of the smoothing, see SmoothMethod_c +@param size1 The first parameter of the smoothing operation, the aperture width. Must be a +positive odd number (1, 3, 5, ...) +@param size2 The second parameter of the smoothing operation, the aperture height. Ignored by +CV_MEDIAN and CV_BILATERAL methods. In the case of simple scaled/non-scaled and Gaussian blur if +size2 is zero, it is set to size1. Otherwise it must be a positive odd number. +@param sigma1 In the case of a Gaussian parameter this parameter may specify Gaussian \f$\sigma\f$ +(standard deviation). If it is zero, it is calculated from the kernel size: +\f[\sigma = 0.3 (n/2 - 1) + 0.8 \quad \text{where} \quad n= \begin{array}{l l} \mbox{\texttt{size1} for horizontal kernel} \\ \mbox{\texttt{size2} for vertical kernel} \end{array}\f] +Using standard sigma for small kernels ( \f$3\times 3\f$ to \f$7\times 7\f$ ) gives better speed. If +sigma1 is not zero, while size1 and size2 are zeros, the kernel size is calculated from the +sigma (to provide accurate enough operation). +@param sigma2 additional parameter for bilateral filtering + +@see cv::GaussianBlur, cv::blur, cv::medianBlur, cv::bilateralFilter. + */ +CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst, + int smoothtype CV_DEFAULT(CV_GAUSSIAN), + int size1 CV_DEFAULT(3), + int size2 CV_DEFAULT(0), + double sigma1 CV_DEFAULT(0), + double sigma2 CV_DEFAULT(0)); + +/** @brief Convolves an image with the kernel. + +@param src input image. +@param dst output image of the same size and the same number of channels as src. +@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point +matrix; if you want to apply different kernels to different channels, split the image into +separate color planes using split and process them individually. +@param anchor anchor of the kernel that indicates the relative position of a filtered point within +the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor +is at the kernel center. + +@see cv::filter2D + */ +CVAPI(void) cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel, + CvPoint anchor CV_DEFAULT(cvPoint(-1,-1))); + +/** @brief Finds integral image: SUM(X,Y) = sum(x<X,y<Y)I(x,y) +@see cv::integral +*/ +CVAPI(void) cvIntegral( const CvArr* image, CvArr* sum, + CvArr* sqsum CV_DEFAULT(NULL), + CvArr* tilted_sum CV_DEFAULT(NULL)); + +/** @brief Smoothes the input image with gaussian kernel and then down-samples it. + + dst_width = floor(src_width/2)[+1], + dst_height = floor(src_height/2)[+1] + @see cv::pyrDown +*/ +CVAPI(void) cvPyrDown( const CvArr* src, CvArr* dst, + int filter CV_DEFAULT(CV_GAUSSIAN_5x5) ); + +/** @brief Up-samples image and smoothes the result with gaussian kernel. + + dst_width = src_width*2, + dst_height = src_height*2 + @see cv::pyrUp +*/ +CVAPI(void) cvPyrUp( const CvArr* src, CvArr* dst, + int filter CV_DEFAULT(CV_GAUSSIAN_5x5) ); + +/** @brief Builds pyramid for an image +@see buildPyramid +*/ +CVAPI(CvMat**) cvCreatePyramid( const CvArr* img, int extra_layers, double rate, + const CvSize* layer_sizes CV_DEFAULT(0), + CvArr* bufarr CV_DEFAULT(0), + int calc CV_DEFAULT(1), + int filter CV_DEFAULT(CV_GAUSSIAN_5x5) ); + +/** @brief Releases pyramid */ +CVAPI(void) cvReleasePyramid( CvMat*** pyramid, int extra_layers ); + + +/** @brief Filters image using meanshift algorithm +@see cv::pyrMeanShiftFiltering +*/ +CVAPI(void) cvPyrMeanShiftFiltering( const CvArr* src, CvArr* dst, + double sp, double sr, int max_level CV_DEFAULT(1), + CvTermCriteria termcrit CV_DEFAULT(cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,5,1))); + +/** @brief Segments image using seed "markers" +@see cv::watershed +*/ +CVAPI(void) cvWatershed( const CvArr* image, CvArr* markers ); + +/** @brief Calculates an image derivative using generalized Sobel + + (aperture_size = 1,3,5,7) or Scharr (aperture_size = -1) operator. + Scharr can be used only for the first dx or dy derivative +@see cv::Sobel +*/ +CVAPI(void) cvSobel( const CvArr* src, CvArr* dst, + int xorder, int yorder, + int aperture_size CV_DEFAULT(3)); + +/** @brief Calculates the image Laplacian: (d2/dx + d2/dy)I +@see cv::Laplacian +*/ +CVAPI(void) cvLaplace( const CvArr* src, CvArr* dst, + int aperture_size CV_DEFAULT(3) ); + +/** @brief Converts input array pixels from one color space to another +@see cv::cvtColor +*/ +CVAPI(void) cvCvtColor( const CvArr* src, CvArr* dst, int code ); + + +/** @brief Resizes image (input array is resized to fit the destination array) +@see cv::resize +*/ +CVAPI(void) cvResize( const CvArr* src, CvArr* dst, + int interpolation CV_DEFAULT( CV_INTER_LINEAR )); + +/** @brief Warps image with affine transform +@note ::cvGetQuadrangleSubPix is similar to ::cvWarpAffine, but the outliers are extrapolated using +replication border mode. +@see cv::warpAffine +*/ +CVAPI(void) cvWarpAffine( const CvArr* src, CvArr* dst, const CvMat* map_matrix, + int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), + CvScalar fillval CV_DEFAULT(cvScalarAll(0)) ); + +/** @brief Computes affine transform matrix for mapping src[i] to dst[i] (i=0,1,2) +@see cv::getAffineTransform +*/ +CVAPI(CvMat*) cvGetAffineTransform( const CvPoint2D32f * src, + const CvPoint2D32f * dst, + CvMat * map_matrix ); + +/** @brief Computes rotation_matrix matrix +@see cv::getRotationMatrix2D +*/ +CVAPI(CvMat*) cv2DRotationMatrix( CvPoint2D32f center, double angle, + double scale, CvMat* map_matrix ); + +/** @brief Warps image with perspective (projective) transform +@see cv::warpPerspective +*/ +CVAPI(void) cvWarpPerspective( const CvArr* src, CvArr* dst, const CvMat* map_matrix, + int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), + CvScalar fillval CV_DEFAULT(cvScalarAll(0)) ); + +/** @brief Computes perspective transform matrix for mapping src[i] to dst[i] (i=0,1,2,3) +@see cv::getPerspectiveTransform +*/ +CVAPI(CvMat*) cvGetPerspectiveTransform( const CvPoint2D32f* src, + const CvPoint2D32f* dst, + CvMat* map_matrix ); + +/** @brief Performs generic geometric transformation using the specified coordinate maps +@see cv::remap +*/ +CVAPI(void) cvRemap( const CvArr* src, CvArr* dst, + const CvArr* mapx, const CvArr* mapy, + int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), + CvScalar fillval CV_DEFAULT(cvScalarAll(0)) ); + +/** @brief Converts mapx & mapy from floating-point to integer formats for cvRemap +@see cv::convertMaps +*/ +CVAPI(void) cvConvertMaps( const CvArr* mapx, const CvArr* mapy, + CvArr* mapxy, CvArr* mapalpha ); + +/** @brief Performs forward or inverse log-polar image transform +@see cv::warpPolar +*/ +CVAPI(void) cvLogPolar( const CvArr* src, CvArr* dst, + CvPoint2D32f center, double M, + int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS)); + +/** Performs forward or inverse linear-polar image transform +@see cv::warpPolar +*/ +CVAPI(void) cvLinearPolar( const CvArr* src, CvArr* dst, + CvPoint2D32f center, double maxRadius, + int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS)); + +/** @brief Transforms the input image to compensate lens distortion +@see cv::undistort +*/ +CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst, + const CvMat* camera_matrix, + const CvMat* distortion_coeffs, + const CvMat* new_camera_matrix CV_DEFAULT(0) ); + +/** @brief Computes transformation map from intrinsic camera parameters + that can used by cvRemap +*/ +CVAPI(void) cvInitUndistortMap( const CvMat* camera_matrix, + const CvMat* distortion_coeffs, + CvArr* mapx, CvArr* mapy ); + +/** @brief Computes undistortion+rectification map for a head of stereo camera +@see cv::initUndistortRectifyMap +*/ +CVAPI(void) cvInitUndistortRectifyMap( const CvMat* camera_matrix, + const CvMat* dist_coeffs, + const CvMat *R, const CvMat* new_camera_matrix, + CvArr* mapx, CvArr* mapy ); + +/** @brief Computes the original (undistorted) feature coordinates + from the observed (distorted) coordinates +@see cv::undistortPoints +*/ +CVAPI(void) cvUndistortPoints( const CvMat* src, CvMat* dst, + const CvMat* camera_matrix, + const CvMat* dist_coeffs, + const CvMat* R CV_DEFAULT(0), + const CvMat* P CV_DEFAULT(0)); + +/** @brief Returns a structuring element of the specified size and shape for morphological operations. + +@note the created structuring element IplConvKernel\* element must be released in the end using +`cvReleaseStructuringElement(&element)`. + +@param cols Width of the structuring element +@param rows Height of the structuring element +@param anchor_x x-coordinate of the anchor +@param anchor_y y-coordinate of the anchor +@param shape element shape that could be one of the cv::MorphShapes_c +@param values integer array of cols*rows elements that specifies the custom shape of the +structuring element, when shape=CV_SHAPE_CUSTOM. + +@see cv::getStructuringElement + */ + CVAPI(IplConvKernel*) cvCreateStructuringElementEx( + int cols, int rows, int anchor_x, int anchor_y, + int shape, int* values CV_DEFAULT(NULL) ); + +/** @brief releases structuring element +@see cvCreateStructuringElementEx +*/ +CVAPI(void) cvReleaseStructuringElement( IplConvKernel** element ); + +/** @brief erodes input image (applies minimum filter) one or more times. + If element pointer is NULL, 3x3 rectangular element is used +@see cv::erode +*/ +CVAPI(void) cvErode( const CvArr* src, CvArr* dst, + IplConvKernel* element CV_DEFAULT(NULL), + int iterations CV_DEFAULT(1) ); + +/** @brief dilates input image (applies maximum filter) one or more times. + + If element pointer is NULL, 3x3 rectangular element is used +@see cv::dilate +*/ +CVAPI(void) cvDilate( const CvArr* src, CvArr* dst, + IplConvKernel* element CV_DEFAULT(NULL), + int iterations CV_DEFAULT(1) ); + +/** @brief Performs complex morphological transformation +@see cv::morphologyEx +*/ +CVAPI(void) cvMorphologyEx( const CvArr* src, CvArr* dst, + CvArr* temp, IplConvKernel* element, + int operation, int iterations CV_DEFAULT(1) ); + +/** @brief Calculates all spatial and central moments up to the 3rd order +@see cv::moments +*/ +CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0)); + +/** @brief Retrieve spatial moments */ +CVAPI(double) cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order ); +/** @brief Retrieve central moments */ +CVAPI(double) cvGetCentralMoment( CvMoments* moments, int x_order, int y_order ); +/** @brief Retrieve normalized central moments */ +CVAPI(double) cvGetNormalizedCentralMoment( CvMoments* moments, + int x_order, int y_order ); + +/** @brief Calculates 7 Hu's invariants from precalculated spatial and central moments +@see cv::HuMoments +*/ +CVAPI(void) cvGetHuMoments( CvMoments* moments, CvHuMoments* hu_moments ); + +/*********************************** data sampling **************************************/ + +/** @brief Fetches pixels that belong to the specified line segment and stores them to the buffer. + + Returns the number of retrieved points. +@see cv::LineSegmentDetector +*/ +CVAPI(int) cvSampleLine( const CvArr* image, CvPoint pt1, CvPoint pt2, void* buffer, + int connectivity CV_DEFAULT(8)); + +/** @brief Retrieves the rectangular image region with specified center from the input array. + + dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2). + Values of pixels with fractional coordinates are retrieved using bilinear interpolation +@see cv::getRectSubPix +*/ +CVAPI(void) cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center ); + + +/** @brief Retrieves quadrangle from the input array. + + matrixarr = ( a11 a12 | b1 ) dst(x,y) <- src(A[x y]' + b) + ( a21 a22 | b2 ) (bilinear interpolation is used to retrieve pixels + with fractional coordinates) +@see cvWarpAffine +*/ +CVAPI(void) cvGetQuadrangleSubPix( const CvArr* src, CvArr* dst, + const CvMat* map_matrix ); + +/** @brief Measures similarity between template and overlapped windows in the source image + and fills the resultant image with the measurements +@see cv::matchTemplate +*/ +CVAPI(void) cvMatchTemplate( const CvArr* image, const CvArr* templ, + CvArr* result, int method ); + +/** @brief Computes earth mover distance between + two weighted point sets (called signatures) +@see cv::EMD +*/ +CVAPI(float) cvCalcEMD2( const CvArr* signature1, + const CvArr* signature2, + int distance_type, + CvDistanceFunction distance_func CV_DEFAULT(NULL), + const CvArr* cost_matrix CV_DEFAULT(NULL), + CvArr* flow CV_DEFAULT(NULL), + float* lower_bound CV_DEFAULT(NULL), + void* userdata CV_DEFAULT(NULL)); + +/****************************************************************************************\ +* Contours retrieving * +\****************************************************************************************/ + +/** @brief Retrieves outer and optionally inner boundaries of white (non-zero) connected + components in the black (zero) background +@see cv::findContours, cvStartFindContours, cvFindNextContour, cvSubstituteContour, cvEndFindContours +*/ +CVAPI(int) cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour, + int header_size CV_DEFAULT(sizeof(CvContour)), + int mode CV_DEFAULT(CV_RETR_LIST), + int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), + CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/** @brief Initializes contour retrieving process. + + Calls cvStartFindContours. + Calls cvFindNextContour until null pointer is returned + or some other condition becomes true. + Calls cvEndFindContours at the end. +@see cvFindContours +*/ +CVAPI(CvContourScanner) cvStartFindContours( CvArr* image, CvMemStorage* storage, + int header_size CV_DEFAULT(sizeof(CvContour)), + int mode CV_DEFAULT(CV_RETR_LIST), + int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), + CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/** @brief Retrieves next contour +@see cvFindContours +*/ +CVAPI(CvSeq*) cvFindNextContour( CvContourScanner scanner ); + + +/** @brief Substitutes the last retrieved contour with the new one + + (if the substitutor is null, the last retrieved contour is removed from the tree) +@see cvFindContours +*/ +CVAPI(void) cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour ); + + +/** @brief Releases contour scanner and returns pointer to the first outer contour +@see cvFindContours +*/ +CVAPI(CvSeq*) cvEndFindContours( CvContourScanner* scanner ); + +/** @brief Approximates Freeman chain(s) with a polygonal curve. + +This is a standalone contour approximation routine, not represented in the new interface. When +cvFindContours retrieves contours as Freeman chains, it calls the function to get approximated +contours, represented as polygons. + +@param src_seq Pointer to the approximated Freeman chain that can refer to other chains. +@param storage Storage location for the resulting polylines. +@param method Approximation method (see the description of the function :ocvFindContours ). +@param parameter Method parameter (not used now). +@param minimal_perimeter Approximates only those contours whose perimeters are not less than +minimal_perimeter . Other chains are removed from the resulting structure. +@param recursive Recursion flag. If it is non-zero, the function approximates all chains that can +be obtained from chain by using the h_next or v_next links. Otherwise, the single input chain is +approximated. +@see cvStartReadChainPoints, cvReadChainPoint + */ +CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, + int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), + double parameter CV_DEFAULT(0), + int minimal_perimeter CV_DEFAULT(0), + int recursive CV_DEFAULT(0)); + +/** @brief Initializes Freeman chain reader. + + The reader is used to iteratively get coordinates of all the chain points. + If the Freeman codes should be read as is, a simple sequence reader should be used +@see cvApproxChains +*/ +CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader ); + +/** @brief Retrieves the next chain point +@see cvApproxChains +*/ +CVAPI(CvPoint) cvReadChainPoint( CvChainPtReader* reader ); + + +/****************************************************************************************\ +* Contour Processing and Shape Analysis * +\****************************************************************************************/ + +/** @brief Approximates a single polygonal curve (contour) or + a tree of polygonal curves (contours) +@see cv::approxPolyDP +*/ +CVAPI(CvSeq*) cvApproxPoly( const void* src_seq, + int header_size, CvMemStorage* storage, + int method, double eps, + int recursive CV_DEFAULT(0)); + +/** @brief Calculates perimeter of a contour or length of a part of contour +@see cv::arcLength +*/ +CVAPI(double) cvArcLength( const void* curve, + CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ), + int is_closed CV_DEFAULT(-1)); + +/** same as cvArcLength for closed contour +*/ +CV_INLINE double cvContourPerimeter( const void* contour ) +{ + return cvArcLength( contour, CV_WHOLE_SEQ, 1 ); +} + + +/** @brief Calculates contour bounding rectangle (update=1) or + just retrieves pre-calculated rectangle (update=0) +@see cv::boundingRect +*/ +CVAPI(CvRect) cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) ); + +/** @brief Calculates area of a contour or contour segment +@see cv::contourArea +*/ +CVAPI(double) cvContourArea( const CvArr* contour, + CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ), + int oriented CV_DEFAULT(0)); + +/** @brief Finds minimum area rotated rectangle bounding a set of points +@see cv::minAreaRect +*/ +CVAPI(CvBox2D) cvMinAreaRect2( const CvArr* points, + CvMemStorage* storage CV_DEFAULT(NULL)); + +/** @brief Finds minimum enclosing circle for a set of points +@see cv::minEnclosingCircle +*/ +CVAPI(int) cvMinEnclosingCircle( const CvArr* points, + CvPoint2D32f* center, float* radius ); + +/** @brief Compares two contours by matching their moments +@see cv::matchShapes +*/ +CVAPI(double) cvMatchShapes( const void* object1, const void* object2, + int method, double parameter CV_DEFAULT(0)); + +/** @brief Calculates exact convex hull of 2d point set +@see cv::convexHull +*/ +CVAPI(CvSeq*) cvConvexHull2( const CvArr* input, + void* hull_storage CV_DEFAULT(NULL), + int orientation CV_DEFAULT(CV_CLOCKWISE), + int return_points CV_DEFAULT(0)); + +/** @brief Checks whether the contour is convex or not (returns 1 if convex, 0 if not) +@see cv::isContourConvex +*/ +CVAPI(int) cvCheckContourConvexity( const CvArr* contour ); + + +/** @brief Finds convexity defects for the contour +@see cv::convexityDefects +*/ +CVAPI(CvSeq*) cvConvexityDefects( const CvArr* contour, const CvArr* convexhull, + CvMemStorage* storage CV_DEFAULT(NULL)); + +/** @brief Fits ellipse into a set of 2d points +@see cv::fitEllipse +*/ +CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points ); + +/** @brief Finds minimum rectangle containing two given rectangles */ +CVAPI(CvRect) cvMaxRect( const CvRect* rect1, const CvRect* rect2 ); + +/** @brief Finds coordinates of the box vertices */ +CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] ); + +/** @brief Initializes sequence header for a matrix (column or row vector) of points + + a wrapper for cvMakeSeqHeaderForArray (it does not initialize bounding rectangle!!!) */ +CVAPI(CvSeq*) cvPointSeqFromMat( int seq_kind, const CvArr* mat, + CvContour* contour_header, + CvSeqBlock* block ); + +/** @brief Checks whether the point is inside polygon, outside, on an edge (at a vertex). + + Returns positive, negative or zero value, correspondingly. + Optionally, measures a signed distance between + the point and the nearest polygon edge (measure_dist=1) +@see cv::pointPolygonTest +*/ +CVAPI(double) cvPointPolygonTest( const CvArr* contour, + CvPoint2D32f pt, int measure_dist ); + +/****************************************************************************************\ +* Histogram functions * +\****************************************************************************************/ + +/** @brief Creates a histogram. + +The function creates a histogram of the specified size and returns a pointer to the created +histogram. If the array ranges is 0, the histogram bin ranges must be specified later via the +function cvSetHistBinRanges. Though cvCalcHist and cvCalcBackProject may process 8-bit images +without setting bin ranges, they assume they are equally spaced in 0 to 255 bins. + +@param dims Number of histogram dimensions. +@param sizes Array of the histogram dimension sizes. +@param type Histogram representation format. CV_HIST_ARRAY means that the histogram data is +represented as a multi-dimensional dense array CvMatND. CV_HIST_SPARSE means that histogram data +is represented as a multi-dimensional sparse array CvSparseMat. +@param ranges Array of ranges for the histogram bins. Its meaning depends on the uniform parameter +value. The ranges are used when the histogram is calculated or backprojected to determine which +histogram bin corresponds to which value/tuple of values from the input image(s). +@param uniform Uniformity flag. If not zero, the histogram has evenly spaced bins and for every +\f$0<=i<cDims\f$ ranges[i] is an array of two numbers: lower and upper boundaries for the i-th +histogram dimension. The whole range [lower,upper] is then split into dims[i] equal parts to +determine the i-th input tuple value ranges for every histogram bin. And if uniform=0 , then the +i-th element of the ranges array contains dims[i]+1 elements: \f$\texttt{lower}_0, +\texttt{upper}_0, \texttt{lower}_1, \texttt{upper}_1 = \texttt{lower}_2, +... +\texttt{upper}_{dims[i]-1}\f$ where \f$\texttt{lower}_j\f$ and \f$\texttt{upper}_j\f$ are lower +and upper boundaries of the i-th input tuple value for the j-th bin, respectively. In either +case, the input values that are beyond the specified range for a histogram bin are not counted +by cvCalcHist and filled with 0 by cvCalcBackProject. + */ +CVAPI(CvHistogram*) cvCreateHist( int dims, int* sizes, int type, + float** ranges CV_DEFAULT(NULL), + int uniform CV_DEFAULT(1)); + +/** @brief Sets the bounds of the histogram bins. + +This is a standalone function for setting bin ranges in the histogram. For a more detailed +description of the parameters ranges and uniform, see the :ocvCalcHist function that can initialize +the ranges as well. Ranges for the histogram bins must be set before the histogram is calculated or +the backproject of the histogram is calculated. + +@param hist Histogram. +@param ranges Array of bin ranges arrays. See :ocvCreateHist for details. +@param uniform Uniformity flag. See :ocvCreateHist for details. + */ +CVAPI(void) cvSetHistBinRanges( CvHistogram* hist, float** ranges, + int uniform CV_DEFAULT(1)); + +/** @brief Makes a histogram out of an array. + +The function initializes the histogram, whose header and bins are allocated by the user. +cvReleaseHist does not need to be called afterwards. Only dense histograms can be initialized this +way. The function returns hist. + +@param dims Number of the histogram dimensions. +@param sizes Array of the histogram dimension sizes. +@param hist Histogram header initialized by the function. +@param data Array used to store histogram bins. +@param ranges Histogram bin ranges. See cvCreateHist for details. +@param uniform Uniformity flag. See cvCreateHist for details. + */ +CVAPI(CvHistogram*) cvMakeHistHeaderForArray( + int dims, int* sizes, CvHistogram* hist, + float* data, float** ranges CV_DEFAULT(NULL), + int uniform CV_DEFAULT(1)); + +/** @brief Releases the histogram. + +The function releases the histogram (header and the data). The pointer to the histogram is cleared +by the function. If \*hist pointer is already NULL, the function does nothing. + +@param hist Double pointer to the released histogram. + */ +CVAPI(void) cvReleaseHist( CvHistogram** hist ); + +/** @brief Clears the histogram. + +The function sets all of the histogram bins to 0 in case of a dense histogram and removes all +histogram bins in case of a sparse array. + +@param hist Histogram. + */ +CVAPI(void) cvClearHist( CvHistogram* hist ); + +/** @brief Finds the minimum and maximum histogram bins. + +The function finds the minimum and maximum histogram bins and their positions. All of output +arguments are optional. Among several extremas with the same value the ones with the minimum index +(in the lexicographical order) are returned. In case of several maximums or minimums, the earliest +in the lexicographical order (extrema locations) is returned. + +@param hist Histogram. +@param min_value Pointer to the minimum value of the histogram. +@param max_value Pointer to the maximum value of the histogram. +@param min_idx Pointer to the array of coordinates for the minimum. +@param max_idx Pointer to the array of coordinates for the maximum. + */ +CVAPI(void) cvGetMinMaxHistValue( const CvHistogram* hist, + float* min_value, float* max_value, + int* min_idx CV_DEFAULT(NULL), + int* max_idx CV_DEFAULT(NULL)); + + +/** @brief Normalizes the histogram. + +The function normalizes the histogram bins by scaling them so that the sum of the bins becomes equal +to factor. + +@param hist Pointer to the histogram. +@param factor Normalization factor. + */ +CVAPI(void) cvNormalizeHist( CvHistogram* hist, double factor ); + + +/** @brief Thresholds the histogram. + +The function clears histogram bins that are below the specified threshold. + +@param hist Pointer to the histogram. +@param threshold Threshold level. + */ +CVAPI(void) cvThreshHist( CvHistogram* hist, double threshold ); + + +/** Compares two histogram */ +CVAPI(double) cvCompareHist( const CvHistogram* hist1, + const CvHistogram* hist2, + int method); + +/** @brief Copies a histogram. + +The function makes a copy of the histogram. If the second histogram pointer \*dst is NULL, a new +histogram of the same size as src is created. Otherwise, both histograms must have equal types and +sizes. Then the function copies the bin values of the source histogram to the destination histogram +and sets the same bin value ranges as in src. + +@param src Source histogram. +@param dst Pointer to the destination histogram. + */ +CVAPI(void) cvCopyHist( const CvHistogram* src, CvHistogram** dst ); + + +/** @brief Calculates bayesian probabilistic histograms + (each or src and dst is an array of _number_ histograms */ +CVAPI(void) cvCalcBayesianProb( CvHistogram** src, int number, + CvHistogram** dst); + +/** @brief Calculates array histogram +@see cv::calcHist +*/ +CVAPI(void) cvCalcArrHist( CvArr** arr, CvHistogram* hist, + int accumulate CV_DEFAULT(0), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @overload */ +CV_INLINE void cvCalcHist( IplImage** image, CvHistogram* hist, + int accumulate CV_DEFAULT(0), + const CvArr* mask CV_DEFAULT(NULL) ) +{ + cvCalcArrHist( (CvArr**)image, hist, accumulate, mask ); +} + +/** @brief Calculates back project +@see cvCalcBackProject, cv::calcBackProject +*/ +CVAPI(void) cvCalcArrBackProject( CvArr** image, CvArr* dst, + const CvHistogram* hist ); + +#define cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist) + + +/** @brief Locates a template within an image by using a histogram comparison. + +The function calculates the back projection by comparing histograms of the source image patches with +the given histogram. The function is similar to matchTemplate, but instead of comparing the raster +patch with all its possible positions within the search window, the function CalcBackProjectPatch +compares histograms. See the algorithm diagram below: + +![image](pics/backprojectpatch.png) + +@param image Source images (though, you may pass CvMat\*\* as well). +@param dst Destination image. +@param range +@param hist Histogram. +@param method Comparison method passed to cvCompareHist (see the function description). +@param factor Normalization factor for histograms that affects the normalization scale of the +destination image. Pass 1 if not sure. + +@see cvCalcBackProjectPatch + */ +CVAPI(void) cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range, + CvHistogram* hist, int method, + double factor ); + +#define cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \ + cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor ) + + +/** @brief Divides one histogram by another. + +The function calculates the object probability density from two histograms as: + +\f[\texttt{disthist} (I)= \forkthree{0}{if \(\texttt{hist1}(I)=0\)}{\texttt{scale}}{if \(\texttt{hist1}(I) \ne 0\) and \(\texttt{hist2}(I) > \texttt{hist1}(I)\)}{\frac{\texttt{hist2}(I) \cdot \texttt{scale}}{\texttt{hist1}(I)}}{if \(\texttt{hist1}(I) \ne 0\) and \(\texttt{hist2}(I) \le \texttt{hist1}(I)\)}\f] + +@param hist1 First histogram (the divisor). +@param hist2 Second histogram. +@param dst_hist Destination histogram. +@param scale Scale factor for the destination histogram. + */ +CVAPI(void) cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2, + CvHistogram* dst_hist, double scale CV_DEFAULT(255) ); + +/** @brief equalizes histogram of 8-bit single-channel image +@see cv::equalizeHist +*/ +CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst ); + + +/** @brief Applies distance transform to binary image +@see cv::distanceTransform +*/ +CVAPI(void) cvDistTransform( const CvArr* src, CvArr* dst, + int distance_type CV_DEFAULT(CV_DIST_L2), + int mask_size CV_DEFAULT(3), + const float* mask CV_DEFAULT(NULL), + CvArr* labels CV_DEFAULT(NULL), + int labelType CV_DEFAULT(CV_DIST_LABEL_CCOMP)); + + +/** @brief Applies fixed-level threshold to grayscale image. + + This is a basic operation applied before retrieving contours +@see cv::threshold +*/ +CVAPI(double) cvThreshold( const CvArr* src, CvArr* dst, + double threshold, double max_value, + int threshold_type ); + +/** @brief Applies adaptive threshold to grayscale image. + + The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and + CV_ADAPTIVE_THRESH_GAUSSIAN_C are: + neighborhood size (3, 5, 7 etc.), + and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) +@see cv::adaptiveThreshold +*/ +CVAPI(void) cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value, + int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C), + int threshold_type CV_DEFAULT(CV_THRESH_BINARY), + int block_size CV_DEFAULT(3), + double param1 CV_DEFAULT(5)); + +/** @brief Fills the connected component until the color difference gets large enough +@see cv::floodFill +*/ +CVAPI(void) cvFloodFill( CvArr* image, CvPoint seed_point, + CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)), + CvScalar up_diff CV_DEFAULT(cvScalarAll(0)), + CvConnectedComp* comp CV_DEFAULT(NULL), + int flags CV_DEFAULT(4), + CvArr* mask CV_DEFAULT(NULL)); + +/****************************************************************************************\ +* Feature detection * +\****************************************************************************************/ + +/** @brief Runs canny edge detector +@see cv::Canny +*/ +CVAPI(void) cvCanny( const CvArr* image, CvArr* edges, double threshold1, + double threshold2, int aperture_size CV_DEFAULT(3) ); + +/** @brief Calculates constraint image for corner detection + + Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy. + Applying threshold to the result gives coordinates of corners +@see cv::preCornerDetect +*/ +CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners, + int aperture_size CV_DEFAULT(3) ); + +/** @brief Calculates eigen values and vectors of 2x2 + gradient covariation matrix at every image pixel +@see cv::cornerEigenValsAndVecs +*/ +CVAPI(void) cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv, + int block_size, int aperture_size CV_DEFAULT(3) ); + +/** @brief Calculates minimal eigenvalue for 2x2 gradient covariation matrix at + every image pixel +@see cv::cornerMinEigenVal +*/ +CVAPI(void) cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, + int block_size, int aperture_size CV_DEFAULT(3) ); + +/** @brief Harris corner detector: + + Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel +@see cv::cornerHarris +*/ +CVAPI(void) cvCornerHarris( const CvArr* image, CvArr* harris_response, + int block_size, int aperture_size CV_DEFAULT(3), + double k CV_DEFAULT(0.04) ); + +/** @brief Adjust corner position using some sort of gradient search +@see cv::cornerSubPix +*/ +CVAPI(void) cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners, + int count, CvSize win, CvSize zero_zone, + CvTermCriteria criteria ); + +/** @brief Finds a sparse set of points within the selected region + that seem to be easy to track +@see cv::goodFeaturesToTrack +*/ +CVAPI(void) cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, + CvArr* temp_image, CvPoint2D32f* corners, + int* corner_count, double quality_level, + double min_distance, + const CvArr* mask CV_DEFAULT(NULL), + int block_size CV_DEFAULT(3), + int use_harris CV_DEFAULT(0), + double k CV_DEFAULT(0.04) ); + +/** @brief Finds lines on binary image using one of several methods. + + line_storage is either memory storage or 1 x _max number of lines_ CvMat, its + number of columns is changed by the function. + method is one of CV_HOUGH_*; + rho, theta and threshold are used for each of those methods; + param1 ~ line length, param2 ~ line gap - for probabilistic, + param1 ~ srn, param2 ~ stn - for multi-scale +@see cv::HoughLines +*/ +CVAPI(CvSeq*) cvHoughLines2( CvArr* image, void* line_storage, int method, + double rho, double theta, int threshold, + double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0), + double min_theta CV_DEFAULT(0), double max_theta CV_DEFAULT(CV_PI)); + +/** @brief Finds circles in the image +@see cv::HoughCircles +*/ +CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage, + int method, double dp, double min_dist, + double param1 CV_DEFAULT(100), + double param2 CV_DEFAULT(100), + int min_radius CV_DEFAULT(0), + int max_radius CV_DEFAULT(0)); + +/** @brief Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) +@see cv::fitLine +*/ +CVAPI(void) cvFitLine( const CvArr* points, int dist_type, double param, + double reps, double aeps, float* line ); + +/****************************************************************************************\ +* Drawing * +\****************************************************************************************/ + +/****************************************************************************************\ +* Drawing functions work with images/matrices of arbitrary type. * +* For color images the channel order is BGR[A] * +* Antialiasing is supported only for 8-bit image now. * +* All the functions include parameter color that means rgb value (that may be * +* constructed with CV_RGB macro) for color images and brightness * +* for grayscale images. * +* If a drawn figure is partially or completely outside of the image, it is clipped.* +\****************************************************************************************/ + +#define CV_FILLED -1 + +#define CV_AA 16 + +/** @brief Draws 4-connected, 8-connected or antialiased line segment connecting two points +@see cv::line +*/ +CVAPI(void) cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); + +/** @brief Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2) + + if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn +@see cv::rectangle +*/ +CVAPI(void) cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), + int shift CV_DEFAULT(0)); + +/** @brief Draws a rectangle specified by a CvRect structure +@see cv::rectangle +*/ +CVAPI(void) cvRectangleR( CvArr* img, CvRect r, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), + int shift CV_DEFAULT(0)); + + +/** @brief Draws a circle with specified center and radius. + + Thickness works in the same way as with cvRectangle +@see cv::circle +*/ +CVAPI(void) cvCircle( CvArr* img, CvPoint center, int radius, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +/** @brief Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector + + depending on _thickness_, _start_angle_ and _end_angle_ parameters. The resultant figure + is rotated by _angle_. All the angles are in degrees +@see cv::ellipse +*/ +CVAPI(void) cvEllipse( CvArr* img, CvPoint center, CvSize axes, + double angle, double start_angle, double end_angle, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +CV_INLINE void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color, + int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ) +{ + CvSize axes = cvSize( + cvRound(box.size.width*0.5), + cvRound(box.size.height*0.5) + ); + + cvEllipse( img, cvPointFrom32f( box.center ), axes, box.angle, + 0, 360, color, thickness, line_type, shift ); +} + +/** @brief Fills convex or monotonous polygon. +@see cv::fillConvexPoly +*/ +CVAPI(void) cvFillConvexPoly( CvArr* img, const CvPoint* pts, int npts, CvScalar color, + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +/** @brief Fills an area bounded by one or more arbitrary polygons +@see cv::fillPoly +*/ +CVAPI(void) cvFillPoly( CvArr* img, CvPoint** pts, const int* npts, + int contours, CvScalar color, + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); + +/** @brief Draws one or more polygonal curves +@see cv::polylines +*/ +CVAPI(void) cvPolyLine( CvArr* img, CvPoint** pts, const int* npts, int contours, + int is_closed, CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); + +#define cvDrawRect cvRectangle +#define cvDrawLine cvLine +#define cvDrawCircle cvCircle +#define cvDrawEllipse cvEllipse +#define cvDrawPolyLine cvPolyLine + +/** @brief Clips the line segment connecting *pt1 and *pt2 + by the rectangular window + + (0<=x<img_size.width, 0<=y<img_size.height). +@see cv::clipLine +*/ +CVAPI(int) cvClipLine( CvSize img_size, CvPoint* pt1, CvPoint* pt2 ); + +/** @brief Initializes line iterator. + +Initially, line_iterator->ptr will point to pt1 (or pt2, see left_to_right description) location in +the image. Returns the number of pixels on the line between the ending points. +@see cv::LineIterator +*/ +CVAPI(int) cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2, + CvLineIterator* line_iterator, + int connectivity CV_DEFAULT(8), + int left_to_right CV_DEFAULT(0)); + +#define CV_NEXT_LINE_POINT( line_iterator ) \ +{ \ + int _line_iterator_mask = (line_iterator).err < 0 ? -1 : 0; \ + (line_iterator).err += (line_iterator).minus_delta + \ + ((line_iterator).plus_delta & _line_iterator_mask); \ + (line_iterator).ptr += (line_iterator).minus_step + \ + ((line_iterator).plus_step & _line_iterator_mask); \ +} + + +#define CV_FONT_HERSHEY_SIMPLEX 0 +#define CV_FONT_HERSHEY_PLAIN 1 +#define CV_FONT_HERSHEY_DUPLEX 2 +#define CV_FONT_HERSHEY_COMPLEX 3 +#define CV_FONT_HERSHEY_TRIPLEX 4 +#define CV_FONT_HERSHEY_COMPLEX_SMALL 5 +#define CV_FONT_HERSHEY_SCRIPT_SIMPLEX 6 +#define CV_FONT_HERSHEY_SCRIPT_COMPLEX 7 + +#define CV_FONT_ITALIC 16 + +#define CV_FONT_VECTOR0 CV_FONT_HERSHEY_SIMPLEX + + +/** Font structure */ +typedef struct CvFont +{ + const char* nameFont; //Qt:nameFont + CvScalar color; //Qt:ColorFont -> cvScalar(blue_component, green_component, red_component[, alpha_component]) + int font_face; //Qt: bool italic /** =CV_FONT_* */ + const int* ascii; //!< font data and metrics + const int* greek; + const int* cyrillic; + float hscale, vscale; + float shear; //!< slope coefficient: 0 - normal, >0 - italic + int thickness; //!< Qt: weight /** letters thickness */ + float dx; //!< horizontal interval between letters + int line_type; //!< Qt: PointSize +} +CvFont; + +/** @brief Initializes font structure (OpenCV 1.x API). + +The function initializes the font structure that can be passed to text rendering functions. + +@param font Pointer to the font structure initialized by the function +@param font_face Font name identifier. See cv::HersheyFonts and corresponding old CV_* identifiers. +@param hscale Horizontal scale. If equal to 1.0f , the characters have the original width +depending on the font type. If equal to 0.5f , the characters are of half the original width. +@param vscale Vertical scale. If equal to 1.0f , the characters have the original height depending +on the font type. If equal to 0.5f , the characters are of half the original height. +@param shear Approximate tangent of the character slope relative to the vertical line. A zero +value means a non-italic font, 1.0f means about a 45 degree slope, etc. +@param thickness Thickness of the text strokes +@param line_type Type of the strokes, see line description + +@sa cvPutText + */ +CVAPI(void) cvInitFont( CvFont* font, int font_face, + double hscale, double vscale, + double shear CV_DEFAULT(0), + int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8)); + +CV_INLINE CvFont cvFont( double scale, int thickness CV_DEFAULT(1) ) +{ + CvFont font; + cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, scale, scale, 0, thickness, CV_AA ); + return font; +} + +/** @brief Renders text stroke with specified font and color at specified location. + CvFont should be initialized with cvInitFont +@see cvInitFont, cvGetTextSize, cvFont, cv::putText +*/ +CVAPI(void) cvPutText( CvArr* img, const char* text, CvPoint org, + const CvFont* font, CvScalar color ); + +/** @brief Calculates bounding box of text stroke (useful for alignment) +@see cv::getTextSize +*/ +CVAPI(void) cvGetTextSize( const char* text_string, const CvFont* font, + CvSize* text_size, int* baseline ); + +/** @brief Unpacks color value + +if arrtype is CV_8UC?, _color_ is treated as packed color value, otherwise the first channels +(depending on arrtype) of destination scalar are set to the same value = _color_ +*/ +CVAPI(CvScalar) cvColorToScalar( double packed_color, int arrtype ); + +/** @brief Returns the polygon points which make up the given ellipse. + +The ellipse is define by the box of size 'axes' rotated 'angle' around the 'center'. A partial +sweep of the ellipse arc can be done by spcifying arc_start and arc_end to be something other than +0 and 360, respectively. The input array 'pts' must be large enough to hold the result. The total +number of points stored into 'pts' is returned by this function. +@see cv::ellipse2Poly +*/ +CVAPI(int) cvEllipse2Poly( CvPoint center, CvSize axes, + int angle, int arc_start, int arc_end, CvPoint * pts, int delta ); + +/** @brief Draws contour outlines or filled interiors on the image +@see cv::drawContours +*/ +CVAPI(void) cvDrawContours( CvArr *img, CvSeq* contour, + CvScalar external_color, CvScalar hole_color, + int max_level, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), + CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/opencv2/imgproc/types_c.h b/include/opencv2/imgproc/types_c.h new file mode 100644 index 0000000..d3e55f5 --- /dev/null +++ b/include/opencv2/imgproc/types_c.h @@ -0,0 +1,659 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_IMGPROC_TYPES_C_H +#define OPENCV_IMGPROC_TYPES_C_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup imgproc_c + @{ +*/ + +/** Connected component structure */ +typedef struct CvConnectedComp +{ + double area; /**<area of the connected component */ + CvScalar value; /**<average color of the connected component */ + CvRect rect; /**<ROI of the component */ + CvSeq* contour; /**<optional component boundary + (the contour might have child contours corresponding to the holes)*/ +} +CvConnectedComp; + +/** Image smooth methods */ +enum SmoothMethod_c +{ + /** linear convolution with \f$\texttt{size1}\times\texttt{size2}\f$ box kernel (all 1's). If + you want to smooth different pixels with different-size box kernels, you can use the integral + image that is computed using integral */ + CV_BLUR_NO_SCALE =0, + /** linear convolution with \f$\texttt{size1}\times\texttt{size2}\f$ box kernel (all + 1's) with subsequent scaling by \f$1/(\texttt{size1}\cdot\texttt{size2})\f$ */ + CV_BLUR =1, + /** linear convolution with a \f$\texttt{size1}\times\texttt{size2}\f$ Gaussian kernel */ + CV_GAUSSIAN =2, + /** median filter with a \f$\texttt{size1}\times\texttt{size1}\f$ square aperture */ + CV_MEDIAN =3, + /** bilateral filter with a \f$\texttt{size1}\times\texttt{size1}\f$ square aperture, color + sigma= sigma1 and spatial sigma= sigma2. If size1=0, the aperture square side is set to + cvRound(sigma2\*1.5)\*2+1. See cv::bilateralFilter */ + CV_BILATERAL =4 +}; + +/** Filters used in pyramid decomposition */ +enum +{ + CV_GAUSSIAN_5x5 = 7 +}; + +/** Special filters */ +enum +{ + CV_SCHARR =-1, + CV_MAX_SOBEL_KSIZE =7 +}; + +/** Constants for color conversion */ +enum +{ + CV_BGR2BGRA =0, + CV_RGB2RGBA =CV_BGR2BGRA, + + CV_BGRA2BGR =1, + CV_RGBA2RGB =CV_BGRA2BGR, + + CV_BGR2RGBA =2, + CV_RGB2BGRA =CV_BGR2RGBA, + + CV_RGBA2BGR =3, + CV_BGRA2RGB =CV_RGBA2BGR, + + CV_BGR2RGB =4, + CV_RGB2BGR =CV_BGR2RGB, + + CV_BGRA2RGBA =5, + CV_RGBA2BGRA =CV_BGRA2RGBA, + + CV_BGR2GRAY =6, + CV_RGB2GRAY =7, + CV_GRAY2BGR =8, + CV_GRAY2RGB =CV_GRAY2BGR, + CV_GRAY2BGRA =9, + CV_GRAY2RGBA =CV_GRAY2BGRA, + CV_BGRA2GRAY =10, + CV_RGBA2GRAY =11, + + CV_BGR2BGR565 =12, + CV_RGB2BGR565 =13, + CV_BGR5652BGR =14, + CV_BGR5652RGB =15, + CV_BGRA2BGR565 =16, + CV_RGBA2BGR565 =17, + CV_BGR5652BGRA =18, + CV_BGR5652RGBA =19, + + CV_GRAY2BGR565 =20, + CV_BGR5652GRAY =21, + + CV_BGR2BGR555 =22, + CV_RGB2BGR555 =23, + CV_BGR5552BGR =24, + CV_BGR5552RGB =25, + CV_BGRA2BGR555 =26, + CV_RGBA2BGR555 =27, + CV_BGR5552BGRA =28, + CV_BGR5552RGBA =29, + + CV_GRAY2BGR555 =30, + CV_BGR5552GRAY =31, + + CV_BGR2XYZ =32, + CV_RGB2XYZ =33, + CV_XYZ2BGR =34, + CV_XYZ2RGB =35, + + CV_BGR2YCrCb =36, + CV_RGB2YCrCb =37, + CV_YCrCb2BGR =38, + CV_YCrCb2RGB =39, + + CV_BGR2HSV =40, + CV_RGB2HSV =41, + + CV_BGR2Lab =44, + CV_RGB2Lab =45, + + CV_BayerBG2BGR =46, + CV_BayerGB2BGR =47, + CV_BayerRG2BGR =48, + CV_BayerGR2BGR =49, + + CV_BayerBG2RGB =CV_BayerRG2BGR, + CV_BayerGB2RGB =CV_BayerGR2BGR, + CV_BayerRG2RGB =CV_BayerBG2BGR, + CV_BayerGR2RGB =CV_BayerGB2BGR, + + CV_BGR2Luv =50, + CV_RGB2Luv =51, + CV_BGR2HLS =52, + CV_RGB2HLS =53, + + CV_HSV2BGR =54, + CV_HSV2RGB =55, + + CV_Lab2BGR =56, + CV_Lab2RGB =57, + CV_Luv2BGR =58, + CV_Luv2RGB =59, + CV_HLS2BGR =60, + CV_HLS2RGB =61, + + CV_BayerBG2BGR_VNG =62, + CV_BayerGB2BGR_VNG =63, + CV_BayerRG2BGR_VNG =64, + CV_BayerGR2BGR_VNG =65, + + CV_BayerBG2RGB_VNG =CV_BayerRG2BGR_VNG, + CV_BayerGB2RGB_VNG =CV_BayerGR2BGR_VNG, + CV_BayerRG2RGB_VNG =CV_BayerBG2BGR_VNG, + CV_BayerGR2RGB_VNG =CV_BayerGB2BGR_VNG, + + CV_BGR2HSV_FULL = 66, + CV_RGB2HSV_FULL = 67, + CV_BGR2HLS_FULL = 68, + CV_RGB2HLS_FULL = 69, + + CV_HSV2BGR_FULL = 70, + CV_HSV2RGB_FULL = 71, + CV_HLS2BGR_FULL = 72, + CV_HLS2RGB_FULL = 73, + + CV_LBGR2Lab = 74, + CV_LRGB2Lab = 75, + CV_LBGR2Luv = 76, + CV_LRGB2Luv = 77, + + CV_Lab2LBGR = 78, + CV_Lab2LRGB = 79, + CV_Luv2LBGR = 80, + CV_Luv2LRGB = 81, + + CV_BGR2YUV = 82, + CV_RGB2YUV = 83, + CV_YUV2BGR = 84, + CV_YUV2RGB = 85, + + CV_BayerBG2GRAY = 86, + CV_BayerGB2GRAY = 87, + CV_BayerRG2GRAY = 88, + CV_BayerGR2GRAY = 89, + + //YUV 4:2:0 formats family + CV_YUV2RGB_NV12 = 90, + CV_YUV2BGR_NV12 = 91, + CV_YUV2RGB_NV21 = 92, + CV_YUV2BGR_NV21 = 93, + CV_YUV420sp2RGB = CV_YUV2RGB_NV21, + CV_YUV420sp2BGR = CV_YUV2BGR_NV21, + + CV_YUV2RGBA_NV12 = 94, + CV_YUV2BGRA_NV12 = 95, + CV_YUV2RGBA_NV21 = 96, + CV_YUV2BGRA_NV21 = 97, + CV_YUV420sp2RGBA = CV_YUV2RGBA_NV21, + CV_YUV420sp2BGRA = CV_YUV2BGRA_NV21, + + CV_YUV2RGB_YV12 = 98, + CV_YUV2BGR_YV12 = 99, + CV_YUV2RGB_IYUV = 100, + CV_YUV2BGR_IYUV = 101, + CV_YUV2RGB_I420 = CV_YUV2RGB_IYUV, + CV_YUV2BGR_I420 = CV_YUV2BGR_IYUV, + CV_YUV420p2RGB = CV_YUV2RGB_YV12, + CV_YUV420p2BGR = CV_YUV2BGR_YV12, + + CV_YUV2RGBA_YV12 = 102, + CV_YUV2BGRA_YV12 = 103, + CV_YUV2RGBA_IYUV = 104, + CV_YUV2BGRA_IYUV = 105, + CV_YUV2RGBA_I420 = CV_YUV2RGBA_IYUV, + CV_YUV2BGRA_I420 = CV_YUV2BGRA_IYUV, + CV_YUV420p2RGBA = CV_YUV2RGBA_YV12, + CV_YUV420p2BGRA = CV_YUV2BGRA_YV12, + + CV_YUV2GRAY_420 = 106, + CV_YUV2GRAY_NV21 = CV_YUV2GRAY_420, + CV_YUV2GRAY_NV12 = CV_YUV2GRAY_420, + CV_YUV2GRAY_YV12 = CV_YUV2GRAY_420, + CV_YUV2GRAY_IYUV = CV_YUV2GRAY_420, + CV_YUV2GRAY_I420 = CV_YUV2GRAY_420, + CV_YUV420sp2GRAY = CV_YUV2GRAY_420, + CV_YUV420p2GRAY = CV_YUV2GRAY_420, + + //YUV 4:2:2 formats family + CV_YUV2RGB_UYVY = 107, + CV_YUV2BGR_UYVY = 108, + //CV_YUV2RGB_VYUY = 109, + //CV_YUV2BGR_VYUY = 110, + CV_YUV2RGB_Y422 = CV_YUV2RGB_UYVY, + CV_YUV2BGR_Y422 = CV_YUV2BGR_UYVY, + CV_YUV2RGB_UYNV = CV_YUV2RGB_UYVY, + CV_YUV2BGR_UYNV = CV_YUV2BGR_UYVY, + + CV_YUV2RGBA_UYVY = 111, + CV_YUV2BGRA_UYVY = 112, + //CV_YUV2RGBA_VYUY = 113, + //CV_YUV2BGRA_VYUY = 114, + CV_YUV2RGBA_Y422 = CV_YUV2RGBA_UYVY, + CV_YUV2BGRA_Y422 = CV_YUV2BGRA_UYVY, + CV_YUV2RGBA_UYNV = CV_YUV2RGBA_UYVY, + CV_YUV2BGRA_UYNV = CV_YUV2BGRA_UYVY, + + CV_YUV2RGB_YUY2 = 115, + CV_YUV2BGR_YUY2 = 116, + CV_YUV2RGB_YVYU = 117, + CV_YUV2BGR_YVYU = 118, + CV_YUV2RGB_YUYV = CV_YUV2RGB_YUY2, + CV_YUV2BGR_YUYV = CV_YUV2BGR_YUY2, + CV_YUV2RGB_YUNV = CV_YUV2RGB_YUY2, + CV_YUV2BGR_YUNV = CV_YUV2BGR_YUY2, + + CV_YUV2RGBA_YUY2 = 119, + CV_YUV2BGRA_YUY2 = 120, + CV_YUV2RGBA_YVYU = 121, + CV_YUV2BGRA_YVYU = 122, + CV_YUV2RGBA_YUYV = CV_YUV2RGBA_YUY2, + CV_YUV2BGRA_YUYV = CV_YUV2BGRA_YUY2, + CV_YUV2RGBA_YUNV = CV_YUV2RGBA_YUY2, + CV_YUV2BGRA_YUNV = CV_YUV2BGRA_YUY2, + + CV_YUV2GRAY_UYVY = 123, + CV_YUV2GRAY_YUY2 = 124, + //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY, + CV_YUV2GRAY_Y422 = CV_YUV2GRAY_UYVY, + CV_YUV2GRAY_UYNV = CV_YUV2GRAY_UYVY, + CV_YUV2GRAY_YVYU = CV_YUV2GRAY_YUY2, + CV_YUV2GRAY_YUYV = CV_YUV2GRAY_YUY2, + CV_YUV2GRAY_YUNV = CV_YUV2GRAY_YUY2, + + // alpha premultiplication + CV_RGBA2mRGBA = 125, + CV_mRGBA2RGBA = 126, + + CV_RGB2YUV_I420 = 127, + CV_BGR2YUV_I420 = 128, + CV_RGB2YUV_IYUV = CV_RGB2YUV_I420, + CV_BGR2YUV_IYUV = CV_BGR2YUV_I420, + + CV_RGBA2YUV_I420 = 129, + CV_BGRA2YUV_I420 = 130, + CV_RGBA2YUV_IYUV = CV_RGBA2YUV_I420, + CV_BGRA2YUV_IYUV = CV_BGRA2YUV_I420, + CV_RGB2YUV_YV12 = 131, + CV_BGR2YUV_YV12 = 132, + CV_RGBA2YUV_YV12 = 133, + CV_BGRA2YUV_YV12 = 134, + + // Edge-Aware Demosaicing + CV_BayerBG2BGR_EA = 135, + CV_BayerGB2BGR_EA = 136, + CV_BayerRG2BGR_EA = 137, + CV_BayerGR2BGR_EA = 138, + + CV_BayerBG2RGB_EA = CV_BayerRG2BGR_EA, + CV_BayerGB2RGB_EA = CV_BayerGR2BGR_EA, + CV_BayerRG2RGB_EA = CV_BayerBG2BGR_EA, + CV_BayerGR2RGB_EA = CV_BayerGB2BGR_EA, + + CV_BayerBG2BGRA =139, + CV_BayerGB2BGRA =140, + CV_BayerRG2BGRA =141, + CV_BayerGR2BGRA =142, + + CV_BayerBG2RGBA =CV_BayerRG2BGRA, + CV_BayerGB2RGBA =CV_BayerGR2BGRA, + CV_BayerRG2RGBA =CV_BayerBG2BGRA, + CV_BayerGR2RGBA =CV_BayerGB2BGRA, + + CV_COLORCVT_MAX = 143 +}; + + +/** Sub-pixel interpolation methods */ +enum +{ + CV_INTER_NN =0, + CV_INTER_LINEAR =1, + CV_INTER_CUBIC =2, + CV_INTER_AREA =3, + CV_INTER_LANCZOS4 =4 +}; + +/** ... and other image warping flags */ +enum +{ + CV_WARP_FILL_OUTLIERS =8, + CV_WARP_INVERSE_MAP =16 +}; + +/** Shapes of a structuring element for morphological operations +@see cv::MorphShapes, cv::getStructuringElement +*/ +enum MorphShapes_c +{ + CV_SHAPE_RECT =0, + CV_SHAPE_CROSS =1, + CV_SHAPE_ELLIPSE =2, + CV_SHAPE_CUSTOM =100 //!< custom structuring element +}; + +/** Morphological operations */ +enum +{ + CV_MOP_ERODE =0, + CV_MOP_DILATE =1, + CV_MOP_OPEN =2, + CV_MOP_CLOSE =3, + CV_MOP_GRADIENT =4, + CV_MOP_TOPHAT =5, + CV_MOP_BLACKHAT =6 +}; + +/** Spatial and central moments */ +typedef struct CvMoments +{ + double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /**< spatial moments */ + double mu20, mu11, mu02, mu30, mu21, mu12, mu03; /**< central moments */ + double inv_sqrt_m00; /**< m00 != 0 ? 1/sqrt(m00) : 0 */ + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvMoments(){} + CvMoments(const cv::Moments& m) + { + m00 = m.m00; m10 = m.m10; m01 = m.m01; + m20 = m.m20; m11 = m.m11; m02 = m.m02; + m30 = m.m30; m21 = m.m21; m12 = m.m12; m03 = m.m03; + mu20 = m.mu20; mu11 = m.mu11; mu02 = m.mu02; + mu30 = m.mu30; mu21 = m.mu21; mu12 = m.mu12; mu03 = m.mu03; + double am00 = std::abs(m.m00); + inv_sqrt_m00 = am00 > DBL_EPSILON ? 1./std::sqrt(am00) : 0; + } + operator cv::Moments() const + { + return cv::Moments(m00, m10, m01, m20, m11, m02, m30, m21, m12, m03); + } +#endif +} +CvMoments; + +#ifdef __cplusplus +} // extern "C" + +CV_INLINE CvMoments cvMoments() +{ +#if !defined(CV__ENABLE_C_API_CTORS) + CvMoments self = CV_STRUCT_INITIALIZER; return self; +#else + return CvMoments(); +#endif +} + +CV_INLINE CvMoments cvMoments(const cv::Moments& m) +{ +#if !defined(CV__ENABLE_C_API_CTORS) + double am00 = std::abs(m.m00); + CvMoments self = { + m.m00, m.m10, m.m01, m.m20, m.m11, m.m02, m.m30, m.m21, m.m12, m.m03, + m.mu20, m.mu11, m.mu02, m.mu30, m.mu21, m.mu12, m.mu03, + am00 > DBL_EPSILON ? 1./std::sqrt(am00) : 0 + }; + return self; +#else + return CvMoments(m); +#endif +} + +extern "C" { +#endif // __cplusplus + +/** Hu invariants */ +typedef struct CvHuMoments +{ + double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /**< Hu invariants */ +} +CvHuMoments; + +/** Template matching methods */ +enum +{ + CV_TM_SQDIFF =0, + CV_TM_SQDIFF_NORMED =1, + CV_TM_CCORR =2, + CV_TM_CCORR_NORMED =3, + CV_TM_CCOEFF =4, + CV_TM_CCOEFF_NORMED =5 +}; + +typedef float (CV_CDECL * CvDistanceFunction)( const float* a, const float* b, void* user_param ); + +/** Contour retrieval modes */ +enum +{ + CV_RETR_EXTERNAL=0, + CV_RETR_LIST=1, + CV_RETR_CCOMP=2, + CV_RETR_TREE=3, + CV_RETR_FLOODFILL=4 +}; + +/** Contour approximation methods */ +enum +{ + CV_CHAIN_CODE=0, + CV_CHAIN_APPROX_NONE=1, + CV_CHAIN_APPROX_SIMPLE=2, + CV_CHAIN_APPROX_TC89_L1=3, + CV_CHAIN_APPROX_TC89_KCOS=4, + CV_LINK_RUNS=5 +}; + +/* +Internal structure that is used for sequential retrieving contours from the image. +It supports both hierarchical and plane variants of Suzuki algorithm. +*/ +typedef struct _CvContourScanner* CvContourScanner; + +/** Freeman chain reader state */ +typedef struct CvChainPtReader +{ + CV_SEQ_READER_FIELDS() + char code; + CvPoint pt; + schar deltas[8][2]; +} +CvChainPtReader; + +/** initializes 8-element array for fast access to 3x3 neighborhood of a pixel */ +#define CV_INIT_3X3_DELTAS( deltas, step, nch ) \ + ((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \ + (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \ + (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \ + (deltas)[6] = (step), (deltas)[7] = (step) + (nch)) + + +/** Contour approximation algorithms */ +enum +{ + CV_POLY_APPROX_DP = 0 +}; + +/** Shape matching methods */ +enum +{ + CV_CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f] + CV_CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f] + CV_CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f] +}; + +/** Shape orientation */ +enum +{ + CV_CLOCKWISE =1, + CV_COUNTER_CLOCKWISE =2 +}; + + +/** Convexity defect */ +typedef struct CvConvexityDefect +{ + CvPoint* start; /**< point of the contour where the defect begins */ + CvPoint* end; /**< point of the contour where the defect ends */ + CvPoint* depth_point; /**< the farthest from the convex hull point within the defect */ + float depth; /**< distance between the farthest point and the convex hull */ +} CvConvexityDefect; + + +/** Histogram comparison methods */ +enum +{ + CV_COMP_CORREL =0, + CV_COMP_CHISQR =1, + CV_COMP_INTERSECT =2, + CV_COMP_BHATTACHARYYA =3, + CV_COMP_HELLINGER =CV_COMP_BHATTACHARYYA, + CV_COMP_CHISQR_ALT =4, + CV_COMP_KL_DIV =5 +}; + +/** Mask size for distance transform */ +enum +{ + CV_DIST_MASK_3 =3, + CV_DIST_MASK_5 =5, + CV_DIST_MASK_PRECISE =0 +}; + +/** Content of output label array: connected components or pixels */ +enum +{ + CV_DIST_LABEL_CCOMP = 0, + CV_DIST_LABEL_PIXEL = 1 +}; + +/** Distance types for Distance Transform and M-estimators */ +enum +{ + CV_DIST_USER =-1, /**< User defined distance */ + CV_DIST_L1 =1, /**< distance = |x1-x2| + |y1-y2| */ + CV_DIST_L2 =2, /**< the simple euclidean distance */ + CV_DIST_C =3, /**< distance = max(|x1-x2|,|y1-y2|) */ + CV_DIST_L12 =4, /**< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */ + CV_DIST_FAIR =5, /**< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */ + CV_DIST_WELSCH =6, /**< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */ + CV_DIST_HUBER =7 /**< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */ +}; + + +/** Threshold types */ +enum +{ + CV_THRESH_BINARY =0, /**< value = value > threshold ? max_value : 0 */ + CV_THRESH_BINARY_INV =1, /**< value = value > threshold ? 0 : max_value */ + CV_THRESH_TRUNC =2, /**< value = value > threshold ? threshold : value */ + CV_THRESH_TOZERO =3, /**< value = value > threshold ? value : 0 */ + CV_THRESH_TOZERO_INV =4, /**< value = value > threshold ? 0 : value */ + CV_THRESH_MASK =7, + CV_THRESH_OTSU =8, /**< use Otsu algorithm to choose the optimal threshold value; + combine the flag with one of the above CV_THRESH_* values */ + CV_THRESH_TRIANGLE =16 /**< use Triangle algorithm to choose the optimal threshold value; + combine the flag with one of the above CV_THRESH_* values, but not + with CV_THRESH_OTSU */ +}; + +/** Adaptive threshold methods */ +enum +{ + CV_ADAPTIVE_THRESH_MEAN_C =0, + CV_ADAPTIVE_THRESH_GAUSSIAN_C =1 +}; + +/** FloodFill flags */ +enum +{ + CV_FLOODFILL_FIXED_RANGE =(1 << 16), + CV_FLOODFILL_MASK_ONLY =(1 << 17) +}; + + +/** Canny edge detector flags */ +enum +{ + CV_CANNY_L2_GRADIENT =(1 << 31) +}; + +/** Variants of a Hough transform */ +enum +{ + CV_HOUGH_STANDARD =0, + CV_HOUGH_PROBABILISTIC =1, + CV_HOUGH_MULTI_SCALE =2, + CV_HOUGH_GRADIENT =3 +}; + + +/* Fast search data structures */ +struct CvFeatureTree; +struct CvLSH; +struct CvLSHOperations; + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/opencv2/line_descriptor.hpp b/include/opencv2/line_descriptor.hpp new file mode 100644 index 0000000..cb2969f --- /dev/null +++ b/include/opencv2/line_descriptor.hpp @@ -0,0 +1,119 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_LINE_DESCRIPTOR_HPP__ +#define __OPENCV_LINE_DESCRIPTOR_HPP__ + +#include "opencv2/line_descriptor/descriptor.hpp" + +/** @defgroup line_descriptor Binary descriptors for lines extracted from an image + +Introduction +------------ + +One of the most challenging activities in computer vision is the extraction of useful information +from a given image. Such information, usually comes in the form of points that preserve some kind of +property (for instance, they are scale-invariant) and are actually representative of input image. + +The goal of this module is seeking a new kind of representative information inside an image and +providing the functionalities for its extraction and representation. In particular, differently from +previous methods for detection of relevant elements inside an image, lines are extracted in place of +points; a new class is defined ad hoc to summarize a line's properties, for reuse and plotting +purposes. + +Computation of binary descriptors +--------------------------------- + +To obtatin a binary descriptor representing a certain line detected from a certain octave of an +image, we first compute a non-binary descriptor as described in @cite LBD . Such algorithm works on +lines extracted using EDLine detector, as explained in @cite EDL . Given a line, we consider a +rectangular region centered at it and called *line support region (LSR)*. Such region is divided +into a set of bands \f$\{B_1, B_2, ..., B_m\}\f$, whose length equals the one of line. + +If we indicate with \f$\bf{d}_L\f$ the direction of line, the orthogonal and clockwise direction to line +\f$\bf{d}_{\perp}\f$ can be determined; these two directions, are used to construct a reference frame +centered in the middle point of line. The gradients of pixels \f$\bf{g'}\f$ inside LSR can be projected +to the newly determined frame, obtaining their local equivalent +\f$\bf{g'} = (\bf{g}^T \cdot \bf{d}_{\perp}, \bf{g}^T \cdot \bf{d}_L)^T \triangleq (\bf{g'}_{d_{\perp}}, \bf{g'}_{d_L})^T\f$. + +Later on, a Gaussian function is applied to all LSR's pixels along \f$\bf{d}_\perp\f$ direction; first, +we assign a global weighting coefficient \f$f_g(i) = (1/\sqrt{2\pi}\sigma_g)e^{-d^2_i/2\sigma^2_g}\f$ to +*i*-th row in LSR, where \f$d_i\f$ is the distance of *i*-th row from the center row in LSR, +\f$\sigma_g = 0.5(m \cdot w - 1)\f$ and \f$w\f$ is the width of bands (the same for every band). Secondly, +considering a band \f$B_j\f$ and its neighbor bands \f$B_{j-1}, B_{j+1}\f$, we assign a local weighting +\f$F_l(k) = (1/\sqrt{2\pi}\sigma_l)e^{-d'^2_k/2\sigma_l^2}\f$, where \f$d'_k\f$ is the distance of *k*-th +row from the center row in \f$B_j\f$ and \f$\sigma_l = w\f$. Using the global and local weights, we obtain, +at the same time, the reduction of role played by gradients far from line and of boundary effect, +respectively. + +Each band \f$B_j\f$ in LSR has an associated *band descriptor(BD)* which is computed considering +previous and next band (top and bottom bands are ignored when computing descriptor for first and +last band). Once each band has been assignen its BD, the LBD descriptor of line is simply given by + +\f[LBD = (BD_1^T, BD_2^T, ... , BD^T_m)^T.\f] + +To compute a band descriptor \f$B_j\f$, each *k*-th row in it is considered and the gradients in such +row are accumulated: + +\f[\begin{matrix} \bf{V1}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}>0}\bf{g}'_{d_\perp}, & \bf{V2}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}<0} -\bf{g}'_{d_\perp}, \\ \bf{V3}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}>0}\bf{g}'_{d_L}, & \bf{V4}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}<0} -\bf{g}'_{d_L}\end{matrix}.\f] + +with \f$\lambda = f_g(k)f_l(k)\f$. + +By stacking previous results, we obtain the *band description matrix (BDM)* + +\f[BDM_j = \left(\begin{matrix} \bf{V1}_j^1 & \bf{V1}_j^2 & \ldots & \bf{V1}_j^n \\ \bf{V2}_j^1 & \bf{V2}_j^2 & \ldots & \bf{V2}_j^n \\ \bf{V3}_j^1 & \bf{V3}_j^2 & \ldots & \bf{V3}_j^n \\ \bf{V4}_j^1 & \bf{V4}_j^2 & \ldots & \bf{V4}_j^n \end{matrix} \right) \in \mathbb{R}^{4\times n},\f] + +with \f$n\f$ the number of rows in band \f$B_j\f$: + +\f[n = \begin{cases} 2w, & j = 1||m; \\ 3w, & \mbox{else}. \end{cases}\f] + +Each \f$BD_j\f$ can be obtained using the standard deviation vector \f$S_j\f$ and mean vector \f$M_j\f$ of +\f$BDM_J\f$. Thus, finally: + +\f[LBD = (M_1^T, S_1^T, M_2^T, S_2^T, \ldots, M_m^T, S_m^T)^T \in \mathbb{R}^{8m}\f] + +Once the LBD has been obtained, it must be converted into a binary form. For such purpose, we +consider 32 possible pairs of BD inside it; each couple of BD is compared bit by bit and comparison +generates an 8 bit string. Concatenating 32 comparison strings, we get the 256-bit final binary +representation of a single LBD. +*/ + +#endif diff --git a/include/opencv2/line_descriptor/descriptor.hpp b/include/opencv2/line_descriptor/descriptor.hpp new file mode 100644 index 0000000..e4b6c33 --- /dev/null +++ b/include/opencv2/line_descriptor/descriptor.hpp @@ -0,0 +1,1205 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2014, Biagio Montesano, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_DESCRIPTOR_HPP__ +#define __OPENCV_DESCRIPTOR_HPP__ + +#include <map> +#include <vector> +#include <list> + +#if defined _MSC_VER && _MSC_VER <= 1700 +#include <stdint.h> +#else +#include <inttypes.h> +#endif + +#include <stdio.h> +#include <iostream> + +#include "opencv2/core/utility.hpp" +#include <opencv2/imgproc.hpp> +#include "opencv2/core.hpp" + +/* define data types */ +typedef uint64_t UINT64; +typedef uint32_t UINT32; +typedef uint16_t UINT16; +typedef uint8_t UINT8; + +/* define constants */ +#define UINT64_1 ((UINT64)0x01) +#define UINT32_1 ((UINT32)0x01) + +namespace cv +{ +namespace line_descriptor +{ + +//! @addtogroup line_descriptor +//! @{ + +/** @brief A class to represent a line + +As aformentioned, it is been necessary to design a class that fully stores the information needed to +characterize completely a line and plot it on image it was extracted from, when required. + +*KeyLine* class has been created for such goal; it is mainly inspired to Feature2d's KeyPoint class, +since KeyLine shares some of *KeyPoint*'s fields, even if a part of them assumes a different +meaning, when speaking about lines. In particular: + +- the *class_id* field is used to gather lines extracted from different octaves which refer to + same line inside original image (such lines and the one they represent in original image share + the same *class_id* value) +- the *angle* field represents line's slope with respect to (positive) X axis +- the *pt* field represents line's midpoint +- the *response* field is computed as the ratio between the line's length and maximum between + image's width and height +- the *size* field is the area of the smallest rectangle containing line + +Apart from fields inspired to KeyPoint class, KeyLines stores information about extremes of line in +original image and in octave it was extracted from, about line's length and number of pixels it +covers. + */ +struct CV_EXPORTS_W_SIMPLE KeyLine +{ + public: + /** orientation of the line */ + CV_PROP_RW float angle; + + /** object ID, that can be used to cluster keylines by the line they represent */ + CV_PROP_RW int class_id; + + /** octave (pyramid layer), from which the keyline has been extracted */ + CV_PROP_RW int octave; + + /** coordinates of the middlepoint */ + CV_PROP_RW Point2f pt; + + /** the response, by which the strongest keylines have been selected. + It's represented by the ratio between line's length and maximum between + image's width and height */ + CV_PROP_RW float response; + + /** minimum area containing line */ + CV_PROP_RW float size; + + /** lines's extremes in original image */ + CV_PROP_RW float startPointX; + CV_PROP_RW float startPointY; + CV_PROP_RW float endPointX; + CV_PROP_RW float endPointY; + + /** line's extremes in image it was extracted from */ + CV_PROP_RW float sPointInOctaveX; + CV_PROP_RW float sPointInOctaveY; + CV_PROP_RW float ePointInOctaveX; + CV_PROP_RW float ePointInOctaveY; + + /** the length of line */ + CV_PROP_RW float lineLength; + + /** number of pixels covered by the line */ + CV_PROP_RW int numOfPixels; + + /** Returns the start point of the line in the original image */ + CV_WRAP Point2f getStartPoint() const + { + return Point2f(startPointX, startPointY); + } + + /** Returns the end point of the line in the original image */ + CV_WRAP Point2f getEndPoint() const + { + return Point2f(endPointX, endPointY); + } + + /** Returns the start point of the line in the octave it was extracted from */ + CV_WRAP Point2f getStartPointInOctave() const + { + return Point2f(sPointInOctaveX, sPointInOctaveY); + } + + /** Returns the end point of the line in the octave it was extracted from */ + CV_WRAP Point2f getEndPointInOctave() const + { + return Point2f(ePointInOctaveX, ePointInOctaveY); + } + + /** constructor */ + CV_WRAP KeyLine() + { + } +}; + +/** @brief Class implements both functionalities for detection of lines and computation of their +binary descriptor. + +Class' interface is mainly based on the ones of classical detectors and extractors, such as +Feature2d's @ref features2d_main and @ref features2d_match. Retrieved information about lines is +stored in line_descriptor::KeyLine objects. + */ +class CV_EXPORTS_W BinaryDescriptor : public Algorithm +{ + + public: + /** @brief List of BinaryDescriptor parameters: + */ + struct CV_EXPORTS Params + { + /*CV_WRAP*/ + Params(); + + /** the number of image octaves (default = 1) */ + + int numOfOctave_; + + /** the width of band; (default: 7) */ + + int widthOfBand_; + + /** image's reduction ratio in construction of Gaussian pyramids */ + int reductionRatio; + + int ksize_; + + /** read parameters from a FileNode object and store them (struct function) */ + void read( const FileNode& fn ); + + /** store parameters to a FileStorage object (struct function) */ + void write( FileStorage& fs ) const; + + }; + + /** @brief Constructor + + @param parameters configuration parameters BinaryDescriptor::Params + + If no argument is provided, constructor sets default values (see comments in the code snippet in + previous section). Default values are strongly reccomended. + */ + BinaryDescriptor( const BinaryDescriptor::Params ¶meters = BinaryDescriptor::Params() ); + + /** @brief Create a BinaryDescriptor object with default parameters (or with the ones provided) + and return a smart pointer to it + */ + CV_WRAP static Ptr<BinaryDescriptor> createBinaryDescriptor(); + static Ptr<BinaryDescriptor> createBinaryDescriptor( Params parameters ); + + /** destructor */ + ~BinaryDescriptor(); + + /** @brief Get current number of octaves + */ + CV_WRAP int getNumOfOctaves(); + /** @brief Set number of octaves + @param octaves number of octaves + */ + CV_WRAP void setNumOfOctaves( int octaves ); + /** @brief Get current width of bands + */ + CV_WRAP int getWidthOfBand(); + /** @brief Set width of bands + @param width width of bands + */ + CV_WRAP void setWidthOfBand( int width ); + /** @brief Get current reduction ratio (used in Gaussian pyramids) + */ + CV_WRAP int getReductionRatio(); + /** @brief Set reduction ratio (used in Gaussian pyramids) + @param rRatio reduction ratio + */ + CV_WRAP void setReductionRatio( int rRatio ); + + /** @brief Read parameters from a FileNode object and store them + + @param fn source FileNode file + */ + virtual void read( const cv::FileNode& fn ) CV_OVERRIDE; + + /** @brief Store parameters to a FileStorage object + + @param fs output FileStorage file + */ + virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE; + + /** @brief Requires line detection + + @param image input image + @param keypoints vector that will store extracted lines for one or more images + @param mask mask matrix to detect only KeyLines of interest + */ + CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, const Mat& mask = Mat() ); + + /** @overload + + @param images input images + @param keylines set of vectors that will store extracted lines for one or more images + @param masks vector of mask matrices to detect only KeyLines of interest from each input image + */ + void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, const std::vector<Mat>& masks = + std::vector<Mat>() ) const; + + /** @brief Requires descriptors computation + + @param image input image + @param keylines vector containing lines for which descriptors must be computed + @param descriptors + @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) + */ + CV_WRAP void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr = false ) const; + + /** @overload + + @param images input images + @param keylines set of vectors containing lines for which descriptors must be computed + @param descriptors + @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) + */ + void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors, bool returnFloatDescr = + false ) const; + + /** @brief Return descriptor size + */ + int descriptorSize() const; + + /** @brief Return data type + */ + int descriptorType() const; + + /** returns norm mode */ + /*CV_WRAP*/ + int defaultNorm() const; + + /** @brief Define operator '()' to perform detection of KeyLines and computation of descriptors in a row. + + @param image input image + @param mask mask matrix to select which lines in KeyLines must be accepted among the ones + extracted (used when *keylines* is not empty) + @param keylines vector that contains input lines (when filled, the detection part will be skipped + and input lines will be passed as input to the algorithm computing descriptors) + @param descriptors matrix that will store final descriptors + @param useProvidedKeyLines flag (when set to true, detection phase will be skipped and only + computation of descriptors will be executed, using lines provided in *keylines*) + @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) + */ + virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector<KeyLine>& keylines, OutputArray descriptors, + bool useProvidedKeyLines = false, bool returnFloatDescr = false ) const; + + protected: + /** implementation of line detection */ + virtual void detectImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, const Mat& mask = Mat() ) const; + + /** implementation of descriptors' computation */ + virtual void computeImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, Mat& descriptors, bool returnFloatDescr, + bool useDetectionData ) const; + + private: + /** struct to represent lines extracted from an octave */ + struct OctaveLine + { + unsigned int octaveCount; //the octave which this line is detected + unsigned int lineIDInOctave; //the line ID in that octave image + unsigned int lineIDInScaleLineVec; //the line ID in Scale line vector + float lineLength; //the length of line in original image scale + }; + + // A 2D line (normal equation parameters). + struct SingleLine + { + //note: rho and theta are based on coordinate origin, i.e. the top-left corner of image + double rho; //unit: pixel length + double theta; //unit: rad + double linePointX; // = rho * cos(theta); + double linePointY; // = rho * sin(theta); + //for EndPoints, the coordinate origin is the top-left corner of image. + double startPointX; + double startPointY; + double endPointX; + double endPointY; + //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis. + double direction; + //mean gradient magnitude + double gradientMagnitude; + //mean gray value of pixels in dark side of line + double darkSideGrayValue; + //mean gray value of pixels in light side of line + double lightSideGrayValue; + //the length of line + double lineLength; + //the width of line; + double width; + //number of pixels + int numOfPixels; + //the decriptor of line + std::vector<double> descriptor; + }; + + // Specifies a vector of lines. + typedef std::vector<SingleLine> Lines_list; + + struct OctaveSingleLine + { + /*endPoints, the coordinate origin is the top-left corner of the original image. + *startPointX = sPointInOctaveX * (factor)^octaveCount; */ + float startPointX; + float startPointY; + float endPointX; + float endPointY; + //endPoints, the coordinate origin is the top-left corner of the octave image. + float sPointInOctaveX; + float sPointInOctaveY; + float ePointInOctaveX; + float ePointInOctaveY; + //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis. + float direction; + //the summation of gradient magnitudes of pixels on lines + float salience; + //the length of line + float lineLength; + //number of pixels + unsigned int numOfPixels; + //the octave which this line is detected + unsigned int octaveCount; + //the decriptor of line + std::vector<float> descriptor; + + OctaveSingleLine() : startPointX(0), startPointY(0), endPointX(0), endPointY(0), + sPointInOctaveX(0), sPointInOctaveY(0), ePointInOctaveX(0), ePointInOctaveY(0), + direction(0), salience(0), lineLength(0), numOfPixels(0), octaveCount(0), + descriptor(std::vector<float>()) + {} + }; + + struct Pixel + { + unsigned int x; //X coordinate + unsigned int y; //Y coordinate + }; + struct EdgeChains + { + std::vector<unsigned int> xCors; //all the x coordinates of edge points + std::vector<unsigned int> yCors; //all the y coordinates of edge points + std::vector<unsigned int> sId; //the start index of each edge in the coordinate arrays + unsigned int numOfEdges; //the number of edges whose length are larger than minLineLen; numOfEdges < sId.size; + }; + + struct LineChains + { + std::vector<unsigned int> xCors; //all the x coordinates of line points + std::vector<unsigned int> yCors; //all the y coordinates of line points + std::vector<unsigned int> sId; //the start index of each line in the coordinate arrays + unsigned int numOfLines; //the number of lines whose length are larger than minLineLen; numOfLines < sId.size; + }; + + typedef std::list<Pixel> PixelChain; //each edge is a pixel chain + + struct CV_EXPORTS_W_SIMPLE EDLineParam + { + CV_PROP_RW int ksize; + CV_PROP_RW float sigma; + CV_PROP_RW float gradientThreshold; + CV_PROP_RW float anchorThreshold; + CV_PROP_RW int scanIntervals; + CV_PROP_RW int minLineLen; + CV_PROP_RW double lineFitErrThreshold; + }; + + #define RELATIVE_ERROR_FACTOR 100.0 + #define MLN10 2.30258509299404568402 + #define log_gamma(x) ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x)) + + /** This class is used to detect lines from input image. + * First, edges are extracted from input image following the method presented in Cihan Topal and + * Cuneyt Akinlar's paper:"Edge Drawing: A Heuristic Approach to Robust Real-Time Edge Detection", 2010. + * Then, lines are extracted from the edge image following the method presented in Cuneyt Akinlar and + * Cihan Topal's paper:"EDLines: A real-time line segment detector with a false detection control", 2011 + * PS: The linking step of edge detection has a little bit difference with the Edge drawing algorithm + * described in the paper. The edge chain doesn't stop when the pixel direction is changed. + */ + class CV_EXPORTS_W EDLineDetector + { + public: + CV_WRAP EDLineDetector(); + CV_WRAP_AS(EDLineDetectorWithParams) EDLineDetector( EDLineParam param ); + ~EDLineDetector(); + + /** @brief Creates an EDLineDetector object, using smart pointers. + */ + CV_WRAP static Ptr<EDLineDetector> createEDLineDetector(); + + + CV_WRAP_AS(createEDLineDetectorWithParams) static Ptr<EDLineDetector> createEDLineDetector(EDLineParam params); + /*extract edges from image + *image: In, gray image; + *edges: Out, store the edges, each edge is a pixel chain + *return -1: error happen + */ + int EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains ); + + /*extract lines from image + *image: In, gray image; + *lines: Out, store the extracted lines, + *return -1: error happen + */ + int EDline( cv::Mat &image, LineChains &lines ); + + /** extract line from image, and store them */ + CV_WRAP int EDline( cv::Mat &image ); + + cv::Mat dxImg_; //store the dxImg; + + cv::Mat dyImg_; //store the dyImg; + + cv::Mat gImgWO_; //store the gradient image without threshold; + + LineChains lines_; //store the detected line chains; + + //store the line Equation coefficients, vec3=[w1,w2,w3] for line w1*x + w2*y + w3=0; + std::vector<std::vector<double> > lineEquations_; + + //store the line endpoints, [x1,y1,x2,y3] + std::vector<std::vector<float> > lineEndpoints_; + + //store the line direction + std::vector<float> lineDirection_; + + //store the line salience, which is the summation of gradients of pixels on line + std::vector<float> lineSalience_; + + // image sizes + unsigned int imageWidth; + unsigned int imageHeight; + + /*The threshold of line fit error; + *If lineFitErr is large than this threshold, then + *the pixel chain is not accepted as a single line segment.*/ + double lineFitErrThreshold_; + + /*the threshold of pixel gradient magnitude. + *Only those pixel whose gradient magnitude are larger than this threshold will be + *taken as possible edge points. Default value is 36*/ + short gradienThreshold_; + + /*If the pixel's gradient value is bigger than both of its neighbors by a + *certain threshold (ANCHOR_THRESHOLD), the pixel is marked to be an anchor. + *Default value is 8*/ + unsigned char anchorThreshold_; + + /*anchor testing can be performed at different scan intervals, i.e., + *every row/column, every second row/column etc. + *Default value is 2*/ + unsigned int scanIntervals_; + + int minLineLen_; //minimal acceptable line length + + private: + void InitEDLine_(); + + /*For an input edge chain, find the best fit line, the default chain length is minLineLen_ + *xCors: In, pointer to the X coordinates of pixel chain; + *yCors: In, pointer to the Y coordinates of pixel chain; + *offsetS:In, start index of this chain in vector; + *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical); + *return: line fit error; -1:error happens; + */ + double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, std::vector<double> &lineEquation ); + + /*For an input pixel chain, find the best fit line. Only do the update based on new points. + *For A*x=v, Least square estimation of x = Inv(A^T * A) * (A^T * v); + *If some new observations are added, i.e, [A; A'] * x = [v; v'], + *then x' = Inv(A^T * A + (A')^T * A') * (A^T * v + (A')^T * v'); + *xCors: In, pointer to the X coordinates of pixel chain; + *yCors: In, pointer to the Y coordinates of pixel chain; + *offsetS:In, start index of this chain in vector; + *newOffsetS: In, start index of extended part; + *offsetE:In, end index of this chain in vector; + *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical); + *return: line fit error; -1:error happens; + */ + double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int newOffsetS, unsigned int offsetE, + std::vector<double> &lineEquation ); + + /** Validate line based on the Helmholtz principle, which basically states that + * for a structure to be perceptually meaningful, the expectation of this structure + * by chance must be very low. + */ + bool LineValidation_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int offsetE, std::vector<double> &lineEquation, + float &direction ); + + bool bValidate_; //flag to decide whether line will be validated + + int ksize_; //the size of Gaussian kernel: ksize X ksize, default value is 5. + + float sigma_; //the sigma of Gaussian kernal, default value is 1.0. + + /*For example, there two edges in the image: + *edge1 = [(7,4), (8,5), (9,6),| (10,7)|, (11, 8), (12,9)] and + *edge2 = [(14,9), (15,10), (16,11), (17,12),| (18, 13)|, (19,14)] ; then we store them as following: + *pFirstPartEdgeX_ = [10, 11, 12, 18, 19];//store the first part of each edge[from middle to end] + *pFirstPartEdgeY_ = [7, 8, 9, 13, 14]; + *pFirstPartEdgeS_ = [0,3,5];// the index of start point of first part of each edge + *pSecondPartEdgeX_ = [10, 9, 8, 7, 18, 17, 16, 15, 14];//store the second part of each edge[from middle to front] + *pSecondPartEdgeY_ = [7, 6, 5, 4, 13, 12, 11, 10, 9];//anchor points(10, 7) and (18, 13) are stored again + *pSecondPartEdgeS_ = [0, 4, 9];// the index of start point of second part of each edge + *This type of storage order is because of the order of edge detection process. + *For each edge, start from one anchor point, first go right, then go left or first go down, then go up*/ + + //store the X coordinates of the first part of the pixels for chains + unsigned int *pFirstPartEdgeX_; + + //store the Y coordinates of the first part of the pixels for chains + unsigned int *pFirstPartEdgeY_; + + //store the start index of every edge chain in the first part arrays + unsigned int *pFirstPartEdgeS_; + + //store the X coordinates of the second part of the pixels for chains + unsigned int *pSecondPartEdgeX_; + + //store the Y coordinates of the second part of the pixels for chains + unsigned int *pSecondPartEdgeY_; + + //store the start index of every edge chain in the second part arrays + unsigned int *pSecondPartEdgeS_; + + //store the X coordinates of anchors + unsigned int *pAnchorX_; + + //store the Y coordinates of anchors + unsigned int *pAnchorY_; + + //edges + cv::Mat edgeImage_; + + cv::Mat gImg_; //store the gradient image; + + cv::Mat dirImg_; //store the direction image + + double logNT_; + + cv::Mat_<float> ATA; //the previous matrix of A^T * A; + + cv::Mat_<float> ATV; //the previous vector of A^T * V; + + cv::Mat_<float> fitMatT; //the matrix used in line fit function; + + cv::Mat_<float> fitVec; //the vector used in line fit function; + + cv::Mat_<float> tempMatLineFit; //the matrix used in line fit function; + + cv::Mat_<float> tempVecLineFit; //the vector used in line fit function; + +}; + + // Specifies a vector of lines. +typedef std::vector<OctaveSingleLine> LinesVec; + +// each element in ScaleLines is a vector of lines +// which corresponds the same line detected in different octave images. +typedef std::vector<LinesVec> ScaleLines; + +/* compute Gaussian pyramids */ +void computeGaussianPyramid( const Mat& image, const int numOctaves ); + +/* compute Sobel's derivatives */ +void computeSobel( const Mat& image, const int numOctaves ); + +/* conversion of an LBD descriptor to its binary representation */ +unsigned char binaryConversion( float* f1, float* f2 ); + +/* compute LBD descriptors using EDLine extractor */ +int computeLBD( ScaleLines &keyLines, bool useDetectionData = false ); + +/* gathers lines in groups using EDLine extractor. + Each group contains the same line, detected in different octaves */ +int OctaveKeyLines( cv::Mat& image, ScaleLines &keyLines ); + +/* the local gaussian coefficient applied to the orthogonal line direction within each band */ +std::vector<double> gaussCoefL_; + +/* the global gaussian coefficient applied to each row within line support region */ +std::vector<double> gaussCoefG_; + +/* descriptor parameters */ +Params params; + +/* vector of sizes of downsampled and blurred images */ +std::vector<cv::Size> images_sizes; + +/*For each octave of image, we define an EDLineDetector, because we can get gradient images (dxImg, dyImg, gImg) + *from the EDLineDetector class without extra computation cost. Another reason is that, if we use + *a single EDLineDetector to detect lines in different octave of images, then we need to allocate and release + *memory for gradient images (dxImg, dyImg, gImg) repeatedly for their varying size*/ +std::vector<Ptr<EDLineDetector> > edLineVec_; + +/* Sobel's derivatives */ +std::vector<cv::Mat> dxImg_vector, dyImg_vector; + +/* Gaussian pyramid */ +std::vector<cv::Mat> octaveImages; + +}; + +/** +Lines extraction methodology +---------------------------- + +The lines extraction methodology described in the following is mainly based on @cite EDL . The +extraction starts with a Gaussian pyramid generated from an original image, downsampled N-1 times, +blurred N times, to obtain N layers (one for each octave), with layer 0 corresponding to input +image. Then, from each layer (octave) in the pyramid, lines are extracted using LSD algorithm. + +Differently from EDLine lines extractor used in original article, LSD furnishes information only +about lines extremes; thus, additional information regarding slope and equation of line are computed +via analytic methods. The number of pixels is obtained using *LineIterator*. Extracted lines are +returned in the form of KeyLine objects, but since extraction is based on a method different from +the one used in *BinaryDescriptor* class, data associated to a line's extremes in original image and +in octave it was extracted from, coincide. KeyLine's field *class_id* is used as an index to +indicate the order of extraction of a line inside a single octave. +*/ +struct CV_EXPORTS_W_SIMPLE LSDParam +{ + CV_PROP_RW double scale ; + CV_PROP_RW double sigma_scale; + CV_PROP_RW double quant; + CV_PROP_RW double ang_th; + CV_PROP_RW double log_eps; + CV_PROP_RW double density_th ; + CV_PROP_RW int n_bins ; + + +CV_WRAP LSDParam():scale(0.8), + sigma_scale(0.6), + quant(2.0), + ang_th(22.5), + log_eps(0), + density_th(0.7), + n_bins(1024){} + +}; + +class CV_EXPORTS_W LSDDetector : public Algorithm +{ +public: + +/* constructor */ +CV_WRAP LSDDetector() : params() +{ +} +; + +CV_WRAP_AS(LSDDetectorWithParams) LSDDetector(LSDParam _params) : params(_params) +{ +} +; + +/** @brief Creates ad LSDDetector object, using smart pointers. + */ +CV_WRAP static Ptr<LSDDetector> createLSDDetector(); + + +CV_WRAP_AS(createLSDDetectorWithParams) static Ptr<LSDDetector> createLSDDetector(LSDParam params); + + +/** @brief Detect lines inside an image. + +@param image input image +@param keypoints vector that will store extracted lines for one or more images +@param scale scale factor used in pyramids generation +@param numOctaves number of octaves inside pyramid +@param mask mask matrix to detect only KeyLines of interest + */ +CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale, int numOctaves, const Mat& mask = Mat() ); + +/** @overload +@param images input images +@param keylines set of vectors that will store extracted lines for one or more images +@param scale scale factor used in pyramids generation +@param numOctaves number of octaves inside pyramid +@param masks vector of mask matrices to detect only KeyLines of interest from each input image +*/ +CV_WRAP void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves, +const std::vector<Mat>& masks = std::vector<Mat>() ) const; + +private: +/* compute Gaussian pyramid of input image */ +void computeGaussianPyramid( const Mat& image, int numOctaves, int scale ); + +/* implementation of line detection */ +void detectImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, int numOctaves, int scale, const Mat& mask ) const; + +/* matrices for Gaussian pyramids */ +std::vector<cv::Mat> gaussianPyrs; + +/* parameters */ +LSDParam params; +}; + +/** @brief furnishes all functionalities for querying a dataset provided by user or internal to +class (that user must, anyway, populate) on the model of @ref features2d_match + + +Once descriptors have been extracted from an image (both they represent lines and points), it +becomes interesting to be able to match a descriptor with another one extracted from a different +image and representing the same line or point, seen from a differente perspective or on a different +scale. In reaching such goal, the main headache is designing an efficient search algorithm to +associate a query descriptor to one extracted from a dataset. In the following, a matching modality +based on *Multi-Index Hashing (MiHashing)* will be described. + +Multi-Index Hashing +------------------- + +The theory described in this section is based on @cite MIH . Given a dataset populated with binary +codes, each code is indexed *m* times into *m* different hash tables, according to *m* substrings it +has been divided into. Thus, given a query code, all the entries close to it at least in one +substring are returned by search as *neighbor candidates*. Returned entries are then checked for +validity by verifying that their full codes are not distant (in Hamming space) more than *r* bits +from query code. In details, each binary code **h** composed of *b* bits is divided into *m* +disjoint substrings \f$\mathbf{h}^{(1)}, ..., \mathbf{h}^{(m)}\f$, each with length +\f$\lfloor b/m \rfloor\f$ or \f$\lceil b/m \rceil\f$ bits. Formally, when two codes **h** and **g** differ +by at the most *r* bits, in at the least one of their *m* substrings they differ by at the most +\f$\lfloor r/m \rfloor\f$ bits. In particular, when \f$||\mathbf{h}-\mathbf{g}||_H \le r\f$ (where \f$||.||_H\f$ +is the Hamming norm), there must exist a substring *k* (with \f$1 \le k \le m\f$) such that + +\f[||\mathbf{h}^{(k)} - \mathbf{g}^{(k)}||_H \le \left\lfloor \frac{r}{m} \right\rfloor .\f] + +That means that if Hamming distance between each of the *m* substring is strictly greater than +\f$\lfloor r/m \rfloor\f$, then \f$||\mathbf{h}-\mathbf{g}||_H\f$ must be larger that *r* and that is a +contradiction. If the codes in dataset are divided into *m* substrings, then *m* tables will be +built. Given a query **q** with substrings \f$\{\mathbf{q}^{(i)}\}^m_{i=1}\f$, *i*-th hash table is +searched for entries distant at the most \f$\lfloor r/m \rfloor\f$ from \f$\mathbf{q}^{(i)}\f$ and a set of +candidates \f$\mathcal{N}_i(\mathbf{q})\f$ is obtained. The union of sets +\f$\mathcal{N}(\mathbf{q}) = \bigcup_i \mathcal{N}_i(\mathbf{q})\f$ is a superset of the *r*-neighbors +of **q**. Then, last step of algorithm is computing the Hamming distance between **q** and each +element in \f$\mathcal{N}(\mathbf{q})\f$, deleting the codes that are distant more that *r* from **q**. +*/ +class CV_EXPORTS_W BinaryDescriptorMatcher : public Algorithm +{ + +public: +/** @brief For every input query descriptor, retrieve the best matching one from a dataset provided from user +or from the one internal to class + +@param queryDescriptors query descriptors +@param trainDescriptors dataset of descriptors furnished by user +@param matches vector to host retrieved matches +@param mask mask to select which input descriptors must be matched to one in dataset + */ +CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector<DMatch>& matches, const Mat& mask = Mat() ) const; + +/** @overload +@param queryDescriptors query descriptors +@param matches vector to host retrieved matches +@param masks vector of masks to select which input descriptors must be matched to one in dataset +(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in +dataset relative to *i*-th image) +*/ +CV_WRAP_AS(matchQuery) void match( const Mat& queryDescriptors, CV_OUT std::vector<DMatch>& matches, const std::vector<Mat>& masks = std::vector<Mat>() ); + +/** @brief For every input query descriptor, retrieve the best *k* matching ones from a dataset provided from +user or from the one internal to class + +@param queryDescriptors query descriptors +@param trainDescriptors dataset of descriptors furnished by user +@param matches vector to host retrieved matches +@param k number of the closest descriptors to be returned for every input query +@param mask mask to select which input descriptors must be matched to ones in dataset +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) + */ +CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k, const Mat& mask = Mat(), +bool compactResult = false ) const; + +/** @overload +@param queryDescriptors query descriptors +@param matches vector to host retrieved matches +@param k number of the closest descriptors to be returned for every input query +@param masks vector of masks to select which input descriptors must be matched to ones in dataset +(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in +dataset relative to *i*-th image) +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) +*/ +CV_WRAP_AS(knnMatchQuery) void knnMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const std::vector<Mat>& masks = std::vector<Mat>(), +bool compactResult = false ); + +/** @brief For every input query descriptor, retrieve, from a dataset provided from user or from the one +internal to class, all the descriptors that are not further than *maxDist* from input query + +@param queryDescriptors query descriptors +@param trainDescriptors dataset of descriptors furnished by user +@param matches vector to host retrieved matches +@param maxDistance search radius +@param mask mask to select which input descriptors must be matched to ones in dataset +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) + */ +void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, +const Mat& mask = Mat(), bool compactResult = false ) const; + +/** @overload +@param queryDescriptors query descriptors +@param matches vector to host retrieved matches +@param maxDistance search radius +@param masks vector of masks to select which input descriptors must be matched to ones in dataset +(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in +dataset relative to *i*-th image) +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) +*/ +void radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, const std::vector<Mat>& masks = +std::vector<Mat>(), +bool compactResult = false ); + +/** @brief Store locally new descriptors to be inserted in dataset, without updating dataset. + +@param descriptors matrices containing descriptors to be inserted into dataset + +@note Each matrix *i* in **descriptors** should contain descriptors relative to lines extracted from +*i*-th image. + */ +void add( const std::vector<Mat>& descriptors ); + +/** @brief Update dataset by inserting into it all descriptors that were stored locally by *add* function. + +@note Every time this function is invoked, current dataset is deleted and locally stored descriptors +are inserted into dataset. The locally stored copy of just inserted descriptors is then removed. + */ +void train(); + +/** @brief Create a BinaryDescriptorMatcher object and return a smart pointer to it. + */ +static Ptr<BinaryDescriptorMatcher> createBinaryDescriptorMatcher(); + +/** @brief Clear dataset and internal data + */ +void clear() CV_OVERRIDE; + +/** @brief Constructor. + +The BinaryDescriptorMatcher constructed is able to store and manage 256-bits long entries. + */ +CV_WRAP BinaryDescriptorMatcher(); + +/** destructor */ +~BinaryDescriptorMatcher() +{ +} + +private: +class BucketGroup +{ + +public: +/** constructor */ +BucketGroup(bool needAllocateGroup = true); + +/** destructor */ +~BucketGroup(); + +/** insert data into the bucket */ +void insert( int subindex, UINT32 data ); + +/** perform a query to the bucket */ +UINT32* query( int subindex, int *size ); + +/** utility functions */ +void insert_value( std::vector<uint32_t>& vec, int index, UINT32 data ); +void push_value( std::vector<uint32_t>& vec, UINT32 Data ); + +/** data fields */ +UINT32 empty; +std::vector<uint32_t> group; + + +}; + +class SparseHashtable +{ + +private: + +/** Maximum bits per key before folding the table */ +static const int MAX_B; + +/** Bins (each bin is an Array object for duplicates of the same key) */ +std::vector<BucketGroup> table; + +public: + +/** constructor */ +SparseHashtable(); + +/** destructor */ +~SparseHashtable(); + +/** initializer */ +int init( int _b ); + +/** insert data */ +void insert( UINT64 index, UINT32 data ); + +/** query data */ +UINT32* query( UINT64 index, int* size ); + +/** Bits per index */ +int b; + +/** Number of bins */ +UINT64 size; + +}; + +/** class defining a sequence of bits */ +class bitarray +{ + +public: +/** pointer to bits sequence and sequence's length */ +UINT32 *arr; +UINT32 length; + +/** constructor setting default values */ +bitarray() +{ +arr = NULL; +length = 0; +} + +/** constructor setting sequence's length */ +bitarray( UINT64 _bits ) +{ +arr = NULL; +init( _bits ); +} + +/** initializer of private fields */ +void init( UINT64 _bits ) +{ +if( arr ) +delete[] arr; +length = (UINT32) ceil( _bits / 32.00 ); +arr = new UINT32[length]; +erase(); +} + +/** destructor */ +~bitarray() +{ +if( arr ) +delete[] arr; +} + +inline void flip( UINT64 index ) +{ +arr[index >> 5] ^= ( (UINT32) 0x01 ) << ( index % 32 ); +} + +inline void set( UINT64 index ) +{ +arr[index >> 5] |= ( (UINT32) 0x01 ) << ( index % 32 ); +} + +inline UINT8 get( UINT64 index ) +{ +return ( arr[index >> 5] & ( ( (UINT32) 0x01 ) << ( index % 32 ) ) ) != 0; +} + +/** reserve menory for an UINT32 */ +inline void erase() +{ +memset( arr, 0, sizeof(UINT32) * length ); +} + +}; + +class Mihasher +{ + +public: +/** Bits per code */ +int B; + +/** B/8 */ +int B_over_8; + +/** Bits per chunk (must be less than 64) */ +int b; + +/** Number of chunks */ +int m; + +/** Number of chunks with b bits (have 1 bit more than others) */ +int mplus; + +/** Maximum hamming search radius (we use B/2 by default) */ +int D; + +/** Maximum hamming search radius per substring */ +int d; + +/** Maximum results to return */ +int K; + +/** Number of codes */ +UINT64 N; + +/** Table of original full-length codes */ +cv::Mat codes; + +/** Counter for eliminating duplicate results (it is not thread safe) */ +Ptr<bitarray> counter; + +/** Array of m hashtables */ +std::vector<SparseHashtable> H; + +/** Volume of a b-bit Hamming ball with radius s (for s = 0 to d) */ +std::vector<UINT32> xornum; + +/** Used within generation of binary codes at a certain Hamming distance */ +int power[100]; + +/** constructor */ +Mihasher(); + +/** desctructor */ +~Mihasher(); + +/** constructor 2 */ +Mihasher( int B, int m ); + +/** K setter */ +void setK( int K ); + +/** populate tables */ +void populate( cv::Mat & codes, UINT32 N, int dim1codes ); + +/** execute a batch query */ +void batchquery( UINT32 * results, UINT32 *numres/*, qstat *stats*/, const cv::Mat & q, UINT32 numq, int dim1queries ); + +private: + +/** execute a single query */ +void query( UINT32 * results, UINT32* numres/*, qstat *stats*/, UINT8 *q, UINT64 * chunks, UINT32 * res ); +}; + +/** retrieve Hamming distances */ +void checkKDistances( UINT32 * numres, int k, std::vector<int>& k_distances, int row, int string_length ) const; + +/** matrix to store new descriptors */ +Mat descriptorsMat; + +/** map storing where each bunch of descriptors benins in DS */ +std::map<int, int> indexesMap; + +/** internal MiHaser representing dataset */ +Ptr<Mihasher> dataset; + +/** index from which next added descriptors' bunch must begin */ +int nextAddedIndex; + +/** number of images whose descriptors are stored in DS */ +int numImages; + +/** number of descriptors in dataset */ +int descrInDS; + +}; + +/* -------------------------------------------------------------------------------------------- + UTILITY FUNCTIONS + -------------------------------------------------------------------------------------------- */ + +/** struct for drawing options */ +struct CV_EXPORTS_W_SIMPLE DrawLinesMatchesFlags +{ +CV_PROP_RW enum +{ +DEFAULT = 0, //!< Output image matrix will be created (Mat::create), + //!< i.e. existing memory of output image may be reused. + //!< Two source images, matches, and single keylines + //!< will be drawn. +DRAW_OVER_OUTIMG = 1,//!< Output image matrix will not be +//!< created (using Mat::create). Matches will be drawn +//!< on existing content of output image. +NOT_DRAW_SINGLE_LINES = 2//!< Single keylines will not be drawn. +}; +}; + +/** @brief Draws the found matches of keylines from two images. + +@param img1 first image +@param keylines1 keylines extracted from first image +@param img2 second image +@param keylines2 keylines extracted from second image +@param matches1to2 vector of matches +@param outImg output matrix to draw on +@param matchColor drawing color for matches (chosen randomly in case of default value) +@param singleLineColor drawing color for keylines (chosen randomly in case of default value) +@param matchesMask mask to indicate which matches must be drawn +@param flags drawing flags, see DrawLinesMatchesFlags + +@note If both *matchColor* and *singleLineColor* are set to their default values, function draws +matched lines and line connecting them with same color + */ +CV_EXPORTS_W void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2, + const std::vector<DMatch>& matches1to2, CV_OUT Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ), + const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector<char>& matchesMask = std::vector<char>(), + int flags = DrawLinesMatchesFlags::DEFAULT ); + +/** @brief Draws keylines. + +@param image input image +@param keylines keylines to be drawn +@param outImage output image to draw on +@param color color of lines to be drawn (if set to defaul value, color is chosen randomly) +@param flags drawing flags + */ +CV_EXPORTS_W void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, CV_OUT Mat& outImage, const Scalar& color = Scalar::all( -1 ), + int flags = DrawLinesMatchesFlags::DEFAULT ); + +//! @} + +} +} + +#endif diff --git a/include/opencv2/ml.hpp b/include/opencv2/ml.hpp new file mode 100644 index 0000000..5348206 --- /dev/null +++ b/include/opencv2/ml.hpp @@ -0,0 +1,1972 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_ML_HPP +#define OPENCV_ML_HPP + +#ifdef __cplusplus +# include "opencv2/core.hpp" +#endif + +#ifdef __cplusplus + +#include <float.h> +#include <map> +#include <iostream> + +/** + @defgroup ml Machine Learning + + The Machine Learning Library (MLL) is a set of classes and functions for statistical + classification, regression, and clustering of data. + + Most of the classification and regression algorithms are implemented as C++ classes. As the + algorithms have different sets of features (like an ability to handle missing measurements or + categorical input variables), there is a little common ground between the classes. This common + ground is defined by the class cv::ml::StatModel that all the other ML classes are derived from. + + See detailed overview here: @ref ml_intro. + */ + +namespace cv +{ + +namespace ml +{ + +//! @addtogroup ml +//! @{ + +/** @brief Variable types */ +enum VariableTypes +{ + VAR_NUMERICAL =0, //!< same as VAR_ORDERED + VAR_ORDERED =0, //!< ordered variables + VAR_CATEGORICAL =1 //!< categorical variables +}; + +/** @brief %Error types */ +enum ErrorTypes +{ + TEST_ERROR = 0, + TRAIN_ERROR = 1 +}; + +/** @brief Sample types */ +enum SampleTypes +{ + ROW_SAMPLE = 0, //!< each training sample is a row of samples + COL_SAMPLE = 1 //!< each training sample occupies a column of samples +}; + +/** @brief The structure represents the logarithmic grid range of statmodel parameters. + +It is used for optimizing statmodel accuracy by varying model parameters, the accuracy estimate +being computed by cross-validation. + */ +class CV_EXPORTS_W ParamGrid +{ +public: + /** @brief Default constructor */ + ParamGrid(); + /** @brief Constructor with parameters */ + ParamGrid(double _minVal, double _maxVal, double _logStep); + + CV_PROP_RW double minVal; //!< Minimum value of the statmodel parameter. Default value is 0. + CV_PROP_RW double maxVal; //!< Maximum value of the statmodel parameter. Default value is 0. + /** @brief Logarithmic step for iterating the statmodel parameter. + + The grid determines the following iteration sequence of the statmodel parameter values: + \f[(minVal, minVal*step, minVal*{step}^2, \dots, minVal*{logStep}^n),\f] + where \f$n\f$ is the maximal index satisfying + \f[\texttt{minVal} * \texttt{logStep} ^n < \texttt{maxVal}\f] + The grid is logarithmic, so logStep must always be greater than 1. Default value is 1. + */ + CV_PROP_RW double logStep; + + /** @brief Creates a ParamGrid Ptr that can be given to the %SVM::trainAuto method + + @param minVal minimum value of the parameter grid + @param maxVal maximum value of the parameter grid + @param logstep Logarithmic step for iterating the statmodel parameter + */ + CV_WRAP static Ptr<ParamGrid> create(double minVal=0., double maxVal=0., double logstep=1.); +}; + +/** @brief Class encapsulating training data. + +Please note that the class only specifies the interface of training data, but not implementation. +All the statistical model classes in _ml_ module accepts Ptr\<TrainData\> as parameter. In other +words, you can create your own class derived from TrainData and pass smart pointer to the instance +of this class into StatModel::train. + +@sa @ref ml_intro_data + */ +class CV_EXPORTS_W TrainData +{ +public: + static inline float missingValue() { return FLT_MAX; } + virtual ~TrainData(); + + CV_WRAP virtual int getLayout() const = 0; + CV_WRAP virtual int getNTrainSamples() const = 0; + CV_WRAP virtual int getNTestSamples() const = 0; + CV_WRAP virtual int getNSamples() const = 0; + CV_WRAP virtual int getNVars() const = 0; + CV_WRAP virtual int getNAllVars() const = 0; + + CV_WRAP virtual void getSample(InputArray varIdx, int sidx, float* buf) const = 0; + CV_WRAP virtual Mat getSamples() const = 0; + CV_WRAP virtual Mat getMissing() const = 0; + + /** @brief Returns matrix of train samples + + @param layout The requested layout. If it's different from the initial one, the matrix is + transposed. See ml::SampleTypes. + @param compressSamples if true, the function returns only the training samples (specified by + sampleIdx) + @param compressVars if true, the function returns the shorter training samples, containing only + the active variables. + + In current implementation the function tries to avoid physical data copying and returns the + matrix stored inside TrainData (unless the transposition or compression is needed). + */ + CV_WRAP virtual Mat getTrainSamples(int layout=ROW_SAMPLE, + bool compressSamples=true, + bool compressVars=true) const = 0; + + /** @brief Returns the vector of responses + + The function returns ordered or the original categorical responses. Usually it's used in + regression algorithms. + */ + CV_WRAP virtual Mat getTrainResponses() const = 0; + + /** @brief Returns the vector of normalized categorical responses + + The function returns vector of responses. Each response is integer from `0` to `<number of + classes>-1`. The actual label value can be retrieved then from the class label vector, see + TrainData::getClassLabels. + */ + CV_WRAP virtual Mat getTrainNormCatResponses() const = 0; + CV_WRAP virtual Mat getTestResponses() const = 0; + CV_WRAP virtual Mat getTestNormCatResponses() const = 0; + CV_WRAP virtual Mat getResponses() const = 0; + CV_WRAP virtual Mat getNormCatResponses() const = 0; + CV_WRAP virtual Mat getSampleWeights() const = 0; + CV_WRAP virtual Mat getTrainSampleWeights() const = 0; + CV_WRAP virtual Mat getTestSampleWeights() const = 0; + CV_WRAP virtual Mat getVarIdx() const = 0; + CV_WRAP virtual Mat getVarType() const = 0; + CV_WRAP Mat getVarSymbolFlags() const; + CV_WRAP virtual int getResponseType() const = 0; + CV_WRAP virtual Mat getTrainSampleIdx() const = 0; + CV_WRAP virtual Mat getTestSampleIdx() const = 0; + CV_WRAP virtual void getValues(int vi, InputArray sidx, float* values) const = 0; + virtual void getNormCatValues(int vi, InputArray sidx, int* values) const = 0; + CV_WRAP virtual Mat getDefaultSubstValues() const = 0; + + CV_WRAP virtual int getCatCount(int vi) const = 0; + + /** @brief Returns the vector of class labels + + The function returns vector of unique labels occurred in the responses. + */ + CV_WRAP virtual Mat getClassLabels() const = 0; + + CV_WRAP virtual Mat getCatOfs() const = 0; + CV_WRAP virtual Mat getCatMap() const = 0; + + /** @brief Splits the training data into the training and test parts + @sa TrainData::setTrainTestSplitRatio + */ + CV_WRAP virtual void setTrainTestSplit(int count, bool shuffle=true) = 0; + + /** @brief Splits the training data into the training and test parts + + The function selects a subset of specified relative size and then returns it as the training + set. If the function is not called, all the data is used for training. Please, note that for + each of TrainData::getTrain\* there is corresponding TrainData::getTest\*, so that the test + subset can be retrieved and processed as well. + @sa TrainData::setTrainTestSplit + */ + CV_WRAP virtual void setTrainTestSplitRatio(double ratio, bool shuffle=true) = 0; + CV_WRAP virtual void shuffleTrainTest() = 0; + + /** @brief Returns matrix of test samples */ + CV_WRAP Mat getTestSamples() const; + + /** @brief Returns vector of symbolic names captured in loadFromCSV() */ + CV_WRAP void getNames(std::vector<String>& names) const; + + /** @brief Extract from 1D vector elements specified by passed indexes. + @param vec input vector (supported types: CV_32S, CV_32F, CV_64F) + @param idx 1D index vector + */ + static CV_WRAP Mat getSubVector(const Mat& vec, const Mat& idx); + + /** @brief Extract from matrix rows/cols specified by passed indexes. + @param matrix input matrix (supported types: CV_32S, CV_32F, CV_64F) + @param idx 1D index vector + @param layout specifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES) + */ + static CV_WRAP Mat getSubMatrix(const Mat& matrix, const Mat& idx, int layout); + + /** @brief Reads the dataset from a .csv file and returns the ready-to-use training data. + + @param filename The input file name + @param headerLineCount The number of lines in the beginning to skip; besides the header, the + function also skips empty lines and lines staring with `#` + @param responseStartIdx Index of the first output variable. If -1, the function considers the + last variable as the response + @param responseEndIdx Index of the last output variable + 1. If -1, then there is single + response variable at responseStartIdx. + @param varTypeSpec The optional text string that specifies the variables' types. It has the + format `ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]`. That is, variables from `n1 to n2` + (inclusive range), `n3`, `n4 to n5` ... are considered ordered and `n6`, `n7 to n8` ... are + considered as categorical. The range `[n1..n2] + [n3] + [n4..n5] + ... + [n6] + [n7..n8]` + should cover all the variables. If varTypeSpec is not specified, then algorithm uses the + following rules: + - all input variables are considered ordered by default. If some column contains has non- + numerical values, e.g. 'apple', 'pear', 'apple', 'apple', 'mango', the corresponding + variable is considered categorical. + - if there are several output variables, they are all considered as ordered. Error is + reported when non-numerical values are used. + - if there is a single output variable, then if its values are non-numerical or are all + integers, then it's considered categorical. Otherwise, it's considered ordered. + @param delimiter The character used to separate values in each line. + @param missch The character used to specify missing measurements. It should not be a digit. + Although it's a non-numerical value, it surely does not affect the decision of whether the + variable ordered or categorical. + @note If the dataset only contains input variables and no responses, use responseStartIdx = -2 + and responseEndIdx = 0. The output variables vector will just contain zeros. + */ + static Ptr<TrainData> loadFromCSV(const String& filename, + int headerLineCount, + int responseStartIdx=-1, + int responseEndIdx=-1, + const String& varTypeSpec=String(), + char delimiter=',', + char missch='?'); + + /** @brief Creates training data from in-memory arrays. + + @param samples matrix of samples. It should have CV_32F type. + @param layout see ml::SampleTypes. + @param responses matrix of responses. If the responses are scalar, they should be stored as a + single row or as a single column. The matrix should have type CV_32F or CV_32S (in the + former case the responses are considered as ordered by default; in the latter case - as + categorical) + @param varIdx vector specifying which variables to use for training. It can be an integer vector + (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of + active variables. + @param sampleIdx vector specifying which samples to use for training. It can be an integer + vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask + of training samples. + @param sampleWeights optional vector with weights for each sample. It should have CV_32F type. + @param varType optional vector of type CV_8U and size `<number_of_variables_in_samples> + + <number_of_variables_in_responses>`, containing types of each input and output variable. See + ml::VariableTypes. + */ + CV_WRAP static Ptr<TrainData> create(InputArray samples, int layout, InputArray responses, + InputArray varIdx=noArray(), InputArray sampleIdx=noArray(), + InputArray sampleWeights=noArray(), InputArray varType=noArray()); +}; + +/** @brief Base class for statistical models in OpenCV ML. + */ +class CV_EXPORTS_W StatModel : public Algorithm +{ +public: + /** Predict options */ + enum Flags { + UPDATE_MODEL = 1, + RAW_OUTPUT=1, //!< makes the method return the raw results (the sum), not the class label + COMPRESSED_INPUT=2, + PREPROCESSED_INPUT=4 + }; + + /** @brief Returns the number of variables in training samples */ + CV_WRAP virtual int getVarCount() const = 0; + + CV_WRAP virtual bool empty() const CV_OVERRIDE; + + /** @brief Returns true if the model is trained */ + CV_WRAP virtual bool isTrained() const = 0; + /** @brief Returns true if the model is classifier */ + CV_WRAP virtual bool isClassifier() const = 0; + + /** @brief Trains the statistical model + + @param trainData training data that can be loaded from file using TrainData::loadFromCSV or + created with TrainData::create. + @param flags optional flags, depending on the model. Some of the models can be updated with the + new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP). + */ + CV_WRAP virtual bool train( const Ptr<TrainData>& trainData, int flags=0 ); + + /** @brief Trains the statistical model + + @param samples training samples + @param layout See ml::SampleTypes. + @param responses vector of responses associated with the training samples. + */ + CV_WRAP virtual bool train( InputArray samples, int layout, InputArray responses ); + + /** @brief Computes error on the training or test dataset + + @param data the training data + @param test if true, the error is computed over the test subset of the data, otherwise it's + computed over the training subset of the data. Please note that if you loaded a completely + different dataset to evaluate already trained classifier, you will probably want not to set + the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so + that the error is computed for the whole new set. Yes, this sounds a bit confusing. + @param resp the optional output responses. + + The method uses StatModel::predict to compute the error. For regression models the error is + computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%). + */ + CV_WRAP virtual float calcError( const Ptr<TrainData>& data, bool test, OutputArray resp ) const; + + /** @brief Predicts response(s) for the provided sample(s) + + @param samples The input samples, floating-point matrix + @param results The optional output matrix of results. + @param flags The optional flags, model-dependent. See cv::ml::StatModel::Flags. + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const = 0; + + /** @brief Create and train model with default parameters + + The class must implement static `create()` method with no parameters or with all default parameter values + */ + template<typename _Tp> static Ptr<_Tp> train(const Ptr<TrainData>& data, int flags=0) + { + Ptr<_Tp> model = _Tp::create(); + return !model.empty() && model->train(data, flags) ? model : Ptr<_Tp>(); + } +}; + +/****************************************************************************************\ +* Normal Bayes Classifier * +\****************************************************************************************/ + +/** @brief Bayes classifier for normally distributed data. + +@sa @ref ml_intro_bayes + */ +class CV_EXPORTS_W NormalBayesClassifier : public StatModel +{ +public: + /** @brief Predicts the response for sample(s). + + The method estimates the most probable classes for input vectors. Input vectors (one or more) + are stored as rows of the matrix inputs. In case of multiple input vectors, there should be one + output vector outputs. The predicted class for a single input vector is returned by the method. + The vector outputProbs contains the output probabilities corresponding to each element of + result. + */ + CV_WRAP virtual float predictProb( InputArray inputs, OutputArray outputs, + OutputArray outputProbs, int flags=0 ) const = 0; + + /** Creates empty model + Use StatModel::train to train the model after creation. */ + CV_WRAP static Ptr<NormalBayesClassifier> create(); + + /** @brief Loads and creates a serialized NormalBayesClassifier from a file + * + * Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk. + * Load the NormalBayesClassifier from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized NormalBayesClassifier + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<NormalBayesClassifier> load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* K-Nearest Neighbour Classifier * +\****************************************************************************************/ + +/** @brief The class implements K-Nearest Neighbors model + +@sa @ref ml_intro_knn + */ +class CV_EXPORTS_W KNearest : public StatModel +{ +public: + + /** Default number of neighbors to use in predict method. */ + /** @see setDefaultK */ + CV_WRAP virtual int getDefaultK() const = 0; + /** @copybrief getDefaultK @see getDefaultK */ + CV_WRAP virtual void setDefaultK(int val) = 0; + + /** Whether classification or regression model should be trained. */ + /** @see setIsClassifier */ + CV_WRAP virtual bool getIsClassifier() const = 0; + /** @copybrief getIsClassifier @see getIsClassifier */ + CV_WRAP virtual void setIsClassifier(bool val) = 0; + + /** Parameter for KDTree implementation. */ + /** @see setEmax */ + CV_WRAP virtual int getEmax() const = 0; + /** @copybrief getEmax @see getEmax */ + CV_WRAP virtual void setEmax(int val) = 0; + + /** %Algorithm type, one of KNearest::Types. */ + /** @see setAlgorithmType */ + CV_WRAP virtual int getAlgorithmType() const = 0; + /** @copybrief getAlgorithmType @see getAlgorithmType */ + CV_WRAP virtual void setAlgorithmType(int val) = 0; + + /** @brief Finds the neighbors and predicts responses for input vectors. + + @param samples Input samples stored by rows. It is a single-precision floating-point matrix of + `<number_of_samples> * k` size. + @param k Number of used nearest neighbors. Should be greater than 1. + @param results Vector with results of prediction (regression or classification) for each input + sample. It is a single-precision floating-point vector with `<number_of_samples>` elements. + @param neighborResponses Optional output values for corresponding neighbors. It is a single- + precision floating-point matrix of `<number_of_samples> * k` size. + @param dist Optional output distances from the input vectors to the corresponding neighbors. It + is a single-precision floating-point matrix of `<number_of_samples> * k` size. + + For each input vector (a row of the matrix samples), the method finds the k nearest neighbors. + In case of regression, the predicted result is a mean value of the particular vector's neighbor + responses. In case of classification, the class is determined by voting. + + For each input vector, the neighbors are sorted by their distances to the vector. + + In case of C++ interface you can use output pointers to empty matrices and the function will + allocate memory itself. + + If only a single input vector is passed, all output matrices are optional and the predicted + value is returned by the method. + + The function is parallelized with the TBB library. + */ + CV_WRAP virtual float findNearest( InputArray samples, int k, + OutputArray results, + OutputArray neighborResponses=noArray(), + OutputArray dist=noArray() ) const = 0; + + /** @brief Implementations of KNearest algorithm + */ + enum Types + { + BRUTE_FORCE=1, + KDTREE=2 + }; + + /** @brief Creates the empty model + + The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method. + */ + CV_WRAP static Ptr<KNearest> create(); +}; + +/****************************************************************************************\ +* Support Vector Machines * +\****************************************************************************************/ + +/** @brief Support Vector Machines. + +@sa @ref ml_intro_svm + */ +class CV_EXPORTS_W SVM : public StatModel +{ +public: + + class CV_EXPORTS Kernel : public Algorithm + { + public: + virtual int getType() const = 0; + virtual void calc( int vcount, int n, const float* vecs, const float* another, float* results ) = 0; + }; + + /** Type of a %SVM formulation. + See SVM::Types. Default value is SVM::C_SVC. */ + /** @see setType */ + CV_WRAP virtual int getType() const = 0; + /** @copybrief getType @see getType */ + CV_WRAP virtual void setType(int val) = 0; + + /** Parameter \f$\gamma\f$ of a kernel function. + For SVM::POLY, SVM::RBF, SVM::SIGMOID or SVM::CHI2. Default value is 1. */ + /** @see setGamma */ + CV_WRAP virtual double getGamma() const = 0; + /** @copybrief getGamma @see getGamma */ + CV_WRAP virtual void setGamma(double val) = 0; + + /** Parameter _coef0_ of a kernel function. + For SVM::POLY or SVM::SIGMOID. Default value is 0.*/ + /** @see setCoef0 */ + CV_WRAP virtual double getCoef0() const = 0; + /** @copybrief getCoef0 @see getCoef0 */ + CV_WRAP virtual void setCoef0(double val) = 0; + + /** Parameter _degree_ of a kernel function. + For SVM::POLY. Default value is 0. */ + /** @see setDegree */ + CV_WRAP virtual double getDegree() const = 0; + /** @copybrief getDegree @see getDegree */ + CV_WRAP virtual void setDegree(double val) = 0; + + /** Parameter _C_ of a %SVM optimization problem. + For SVM::C_SVC, SVM::EPS_SVR or SVM::NU_SVR. Default value is 0. */ + /** @see setC */ + CV_WRAP virtual double getC() const = 0; + /** @copybrief getC @see getC */ + CV_WRAP virtual void setC(double val) = 0; + + /** Parameter \f$\nu\f$ of a %SVM optimization problem. + For SVM::NU_SVC, SVM::ONE_CLASS or SVM::NU_SVR. Default value is 0. */ + /** @see setNu */ + CV_WRAP virtual double getNu() const = 0; + /** @copybrief getNu @see getNu */ + CV_WRAP virtual void setNu(double val) = 0; + + /** Parameter \f$\epsilon\f$ of a %SVM optimization problem. + For SVM::EPS_SVR. Default value is 0. */ + /** @see setP */ + CV_WRAP virtual double getP() const = 0; + /** @copybrief getP @see getP */ + CV_WRAP virtual void setP(double val) = 0; + + /** Optional weights in the SVM::C_SVC problem, assigned to particular classes. + They are multiplied by _C_ so the parameter _C_ of class _i_ becomes `classWeights(i) * C`. Thus + these weights affect the misclassification penalty for different classes. The larger weight, + the larger penalty on misclassification of data from the corresponding class. Default value is + empty Mat. */ + /** @see setClassWeights */ + CV_WRAP virtual cv::Mat getClassWeights() const = 0; + /** @copybrief getClassWeights @see getClassWeights */ + CV_WRAP virtual void setClassWeights(const cv::Mat &val) = 0; + + /** Termination criteria of the iterative %SVM training procedure which solves a partial + case of constrained quadratic optimization problem. + You can specify tolerance and/or the maximum number of iterations. Default value is + `TermCriteria( TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, FLT_EPSILON )`; */ + /** @see setTermCriteria */ + CV_WRAP virtual cv::TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const cv::TermCriteria &val) = 0; + + /** Type of a %SVM kernel. + See SVM::KernelTypes. Default value is SVM::RBF. */ + CV_WRAP virtual int getKernelType() const = 0; + + /** Initialize with one of predefined kernels. + See SVM::KernelTypes. */ + CV_WRAP virtual void setKernel(int kernelType) = 0; + + /** Initialize with custom kernel. + See SVM::Kernel class for implementation details */ + virtual void setCustomKernel(const Ptr<Kernel> &_kernel) = 0; + + //! %SVM type + enum Types { + /** C-Support Vector Classification. n-class classification (n \f$\geq\f$ 2), allows + imperfect separation of classes with penalty multiplier C for outliers. */ + C_SVC=100, + /** \f$\nu\f$-Support Vector Classification. n-class classification with possible + imperfect separation. Parameter \f$\nu\f$ (in the range 0..1, the larger the value, the smoother + the decision boundary) is used instead of C. */ + NU_SVC=101, + /** Distribution Estimation (One-class %SVM). All the training data are from + the same class, %SVM builds a boundary that separates the class from the rest of the feature + space. */ + ONE_CLASS=102, + /** \f$\epsilon\f$-Support Vector Regression. The distance between feature vectors + from the training set and the fitting hyper-plane must be less than p. For outliers the + penalty multiplier C is used. */ + EPS_SVR=103, + /** \f$\nu\f$-Support Vector Regression. \f$\nu\f$ is used instead of p. + See @cite LibSVM for details. */ + NU_SVR=104 + }; + + /** @brief %SVM kernel type + + A comparison of different kernels on the following 2D test case with four classes. Four + SVM::C_SVC SVMs have been trained (one against rest) with auto_train. Evaluation on three + different kernels (SVM::CHI2, SVM::INTER, SVM::RBF). The color depicts the class with max score. + Bright means max-score \> 0, dark means max-score \< 0. + ![image](pics/SVM_Comparison.png) + */ + enum KernelTypes { + /** Returned by SVM::getKernelType in case when custom kernel has been set */ + CUSTOM=-1, + /** Linear kernel. No mapping is done, linear discrimination (or regression) is + done in the original feature space. It is the fastest option. \f$K(x_i, x_j) = x_i^T x_j\f$. */ + LINEAR=0, + /** Polynomial kernel: + \f$K(x_i, x_j) = (\gamma x_i^T x_j + coef0)^{degree}, \gamma > 0\f$. */ + POLY=1, + /** Radial basis function (RBF), a good choice in most cases. + \f$K(x_i, x_j) = e^{-\gamma ||x_i - x_j||^2}, \gamma > 0\f$. */ + RBF=2, + /** Sigmoid kernel: \f$K(x_i, x_j) = \tanh(\gamma x_i^T x_j + coef0)\f$. */ + SIGMOID=3, + /** Exponential Chi2 kernel, similar to the RBF kernel: + \f$K(x_i, x_j) = e^{-\gamma \chi^2(x_i,x_j)}, \chi^2(x_i,x_j) = (x_i-x_j)^2/(x_i+x_j), \gamma > 0\f$. */ + CHI2=4, + /** Histogram intersection kernel. A fast kernel. \f$K(x_i, x_j) = min(x_i,x_j)\f$. */ + INTER=5 + }; + + //! %SVM params type + enum ParamTypes { + C=0, + GAMMA=1, + P=2, + NU=3, + COEF=4, + DEGREE=5 + }; + + /** @brief Trains an %SVM with optimal parameters. + + @param data the training data that can be constructed using TrainData::create or + TrainData::loadFromCSV. + @param kFold Cross-validation parameter. The training set is divided into kFold subsets. One + subset is used to test the model, the others form the train set. So, the %SVM algorithm is + executed kFold times. + @param Cgrid grid for C + @param gammaGrid grid for gamma + @param pGrid grid for p + @param nuGrid grid for nu + @param coeffGrid grid for coeff + @param degreeGrid grid for degree + @param balanced If true and the problem is 2-class classification then the method creates more + balanced cross-validation subsets that is proportions between classes in subsets are close + to such proportion in the whole train dataset. + + The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, + nu, coef0, degree. Parameters are considered optimal when the cross-validation + estimate of the test set error is minimal. + + If there is no need to optimize a parameter, the corresponding grid step should be set to any + value less than or equal to 1. For example, to avoid optimization in gamma, set `gammaGrid.step + = 0`, `gammaGrid.minVal`, `gamma_grid.maxVal` as arbitrary numbers. In this case, the value + `Gamma` is taken for gamma. + + And, finally, if the optimization in a parameter is required but the corresponding grid is + unknown, you may call the function SVM::getDefaultGrid. To generate a grid, for example, for + gamma, call `SVM::getDefaultGrid(SVM::GAMMA)`. + + This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the + regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and + the usual %SVM with parameters specified in params is executed. + */ + virtual bool trainAuto( const Ptr<TrainData>& data, int kFold = 10, + ParamGrid Cgrid = getDefaultGrid(C), + ParamGrid gammaGrid = getDefaultGrid(GAMMA), + ParamGrid pGrid = getDefaultGrid(P), + ParamGrid nuGrid = getDefaultGrid(NU), + ParamGrid coeffGrid = getDefaultGrid(COEF), + ParamGrid degreeGrid = getDefaultGrid(DEGREE), + bool balanced=false) = 0; + + /** @brief Trains an %SVM with optimal parameters + + @param samples training samples + @param layout See ml::SampleTypes. + @param responses vector of responses associated with the training samples. + @param kFold Cross-validation parameter. The training set is divided into kFold subsets. One + subset is used to test the model, the others form the train set. So, the %SVM algorithm is + @param Cgrid grid for C + @param gammaGrid grid for gamma + @param pGrid grid for p + @param nuGrid grid for nu + @param coeffGrid grid for coeff + @param degreeGrid grid for degree + @param balanced If true and the problem is 2-class classification then the method creates more + balanced cross-validation subsets that is proportions between classes in subsets are close + to such proportion in the whole train dataset. + + The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, + nu, coef0, degree. Parameters are considered optimal when the cross-validation + estimate of the test set error is minimal. + + This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only + offers rudimentary parameter options. + + This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the + regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and + the usual %SVM with parameters specified in params is executed. + */ + CV_WRAP bool trainAuto(InputArray samples, + int layout, + InputArray responses, + int kFold = 10, + Ptr<ParamGrid> Cgrid = SVM::getDefaultGridPtr(SVM::C), + Ptr<ParamGrid> gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), + Ptr<ParamGrid> pGrid = SVM::getDefaultGridPtr(SVM::P), + Ptr<ParamGrid> nuGrid = SVM::getDefaultGridPtr(SVM::NU), + Ptr<ParamGrid> coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), + Ptr<ParamGrid> degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), + bool balanced=false); + + /** @brief Retrieves all the support vectors + + The method returns all the support vectors as a floating-point matrix, where support vectors are + stored as matrix rows. + */ + CV_WRAP virtual Mat getSupportVectors() const = 0; + + /** @brief Retrieves all the uncompressed support vectors of a linear %SVM + + The method returns all the uncompressed support vectors of a linear %SVM that the compressed + support vector, used for prediction, was derived from. They are returned in a floating-point + matrix, where the support vectors are stored as matrix rows. + */ + CV_WRAP Mat getUncompressedSupportVectors() const; + + /** @brief Retrieves the decision function + + @param i the index of the decision function. If the problem solved is regression, 1-class or + 2-class classification, then there will be just one decision function and the index should + always be 0. Otherwise, in the case of N-class classification, there will be \f$N(N-1)/2\f$ + decision functions. + @param alpha the optional output vector for weights, corresponding to different support vectors. + In the case of linear %SVM all the alpha's will be 1's. + @param svidx the optional output vector of indices of support vectors within the matrix of + support vectors (which can be retrieved by SVM::getSupportVectors). In the case of linear + %SVM each decision function consists of a single "compressed" support vector. + + The method returns rho parameter of the decision function, a scalar subtracted from the weighted + sum of kernel responses. + */ + CV_WRAP virtual double getDecisionFunction(int i, OutputArray alpha, OutputArray svidx) const = 0; + + /** @brief Generates a grid for %SVM parameters. + + @param param_id %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is + generated for the parameter with this ID. + + The function generates a grid for the specified parameter of the %SVM algorithm. The grid may be + passed to the function SVM::trainAuto. + */ + static ParamGrid getDefaultGrid( int param_id ); + + /** @brief Generates a grid for %SVM parameters. + + @param param_id %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is + generated for the parameter with this ID. + + The function generates a grid pointer for the specified parameter of the %SVM algorithm. + The grid may be passed to the function SVM::trainAuto. + */ + CV_WRAP static Ptr<ParamGrid> getDefaultGridPtr( int param_id ); + + /** Creates empty model. + Use StatModel::train to train the model. Since %SVM has several parameters, you may want to + find the best parameters for your problem, it can be done with SVM::trainAuto. */ + CV_WRAP static Ptr<SVM> create(); + + /** @brief Loads and creates a serialized svm from a file + * + * Use SVM::save to serialize and store an SVM to disk. + * Load the SVM from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized svm + */ + CV_WRAP static Ptr<SVM> load(const String& filepath); +}; + +/****************************************************************************************\ +* Expectation - Maximization * +\****************************************************************************************/ + +/** @brief The class implements the Expectation Maximization algorithm. + +@sa @ref ml_intro_em + */ +class CV_EXPORTS_W EM : public StatModel +{ +public: + //! Type of covariation matrices + enum Types { + /** A scaled identity matrix \f$\mu_k * I\f$. There is the only + parameter \f$\mu_k\f$ to be estimated for each matrix. The option may be used in special cases, + when the constraint is relevant, or as a first step in the optimization (for example in case + when the data is preprocessed with PCA). The results of such preliminary estimation may be + passed again to the optimization procedure, this time with + covMatType=EM::COV_MAT_DIAGONAL. */ + COV_MAT_SPHERICAL=0, + /** A diagonal matrix with positive diagonal elements. The number of + free parameters is d for each matrix. This is most commonly used option yielding good + estimation results. */ + COV_MAT_DIAGONAL=1, + /** A symmetric positively defined matrix. The number of free + parameters in each matrix is about \f$d^2/2\f$. It is not recommended to use this option, unless + there is pretty accurate initial estimation of the parameters and/or a huge number of + training samples. */ + COV_MAT_GENERIC=2, + COV_MAT_DEFAULT=COV_MAT_DIAGONAL + }; + + //! Default parameters + enum {DEFAULT_NCLUSTERS=5, DEFAULT_MAX_ITERS=100}; + + //! The initial step + enum {START_E_STEP=1, START_M_STEP=2, START_AUTO_STEP=0}; + + /** The number of mixture components in the Gaussian mixture model. + Default value of the parameter is EM::DEFAULT_NCLUSTERS=5. Some of %EM implementation could + determine the optimal number of mixtures within a specified value range, but that is not the + case in ML yet. */ + /** @see setClustersNumber */ + CV_WRAP virtual int getClustersNumber() const = 0; + /** @copybrief getClustersNumber @see getClustersNumber */ + CV_WRAP virtual void setClustersNumber(int val) = 0; + + /** Constraint on covariance matrices which defines type of matrices. + See EM::Types. */ + /** @see setCovarianceMatrixType */ + CV_WRAP virtual int getCovarianceMatrixType() const = 0; + /** @copybrief getCovarianceMatrixType @see getCovarianceMatrixType */ + CV_WRAP virtual void setCovarianceMatrixType(int val) = 0; + + /** The termination criteria of the %EM algorithm. + The %EM algorithm can be terminated by the number of iterations termCrit.maxCount (number of + M-steps) or when relative change of likelihood logarithm is less than termCrit.epsilon. Default + maximum number of iterations is EM::DEFAULT_MAX_ITERS=100. */ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const TermCriteria &val) = 0; + + /** @brief Returns weights of the mixtures + + Returns vector with the number of elements equal to the number of mixtures. + */ + CV_WRAP virtual Mat getWeights() const = 0; + /** @brief Returns the cluster centers (means of the Gaussian mixture) + + Returns matrix with the number of rows equal to the number of mixtures and number of columns + equal to the space dimensionality. + */ + CV_WRAP virtual Mat getMeans() const = 0; + /** @brief Returns covariation matrices + + Returns vector of covariation matrices. Number of matrices is the number of gaussian mixtures, + each matrix is a square floating-point matrix NxN, where N is the space dimensionality. + */ + CV_WRAP virtual void getCovs(CV_OUT std::vector<Mat>& covs) const = 0; + + /** @brief Returns posterior probabilities for the provided samples + + @param samples The input samples, floating-point matrix + @param results The optional output \f$ nSamples \times nClusters\f$ matrix of results. It contains + posterior probabilities for each sample from the input + @param flags This parameter will be ignored + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const CV_OVERRIDE = 0; + + /** @brief Returns a likelihood logarithm value and an index of the most probable mixture component + for the given sample. + + @param sample A sample for classification. It should be a one-channel matrix of + \f$1 \times dims\f$ or \f$dims \times 1\f$ size. + @param probs Optional output matrix that contains posterior probabilities of each component + given the sample. It has \f$1 \times nclusters\f$ size and CV_64FC1 type. + + The method returns a two-element double vector. Zero element is a likelihood logarithm value for + the sample. First element is an index of the most probable mixture component for the given + sample. + */ + CV_WRAP virtual Vec2d predict2(InputArray sample, OutputArray probs) const = 0; + + /** @brief Estimate the Gaussian mixture parameters from a samples set. + + This variation starts with Expectation step. Initial values of the model parameters will be + estimated by the k-means algorithm. + + Unlike many of the ML models, %EM is an unsupervised learning algorithm and it does not take + responses (class labels or function values) as input. Instead, it computes the *Maximum + Likelihood Estimate* of the Gaussian mixture parameters from an input sample set, stores all the + parameters inside the structure: \f$p_{i,k}\f$ in probs, \f$a_k\f$ in means , \f$S_k\f$ in + covs[k], \f$\pi_k\f$ in weights , and optionally computes the output "class label" for each + sample: \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most + probable mixture component for each sample). + + The trained model can be used further for prediction, just like any other classifier. The + trained model is similar to the NormalBayesClassifier. + + @param samples Samples from which the Gaussian mixture model will be estimated. It should be a + one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type + it will be converted to the inner matrix of such type for the further computing. + @param logLikelihoods The optional output matrix that contains a likelihood logarithm value for + each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. + @param labels The optional output "class label" for each sample: + \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable + mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. + @param probs The optional output matrix that contains posterior probabilities of each Gaussian + mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and + CV_64FC1 type. + */ + CV_WRAP virtual bool trainEM(InputArray samples, + OutputArray logLikelihoods=noArray(), + OutputArray labels=noArray(), + OutputArray probs=noArray()) = 0; + + /** @brief Estimate the Gaussian mixture parameters from a samples set. + + This variation starts with Expectation step. You need to provide initial means \f$a_k\f$ of + mixture components. Optionally you can pass initial weights \f$\pi_k\f$ and covariance matrices + \f$S_k\f$ of mixture components. + + @param samples Samples from which the Gaussian mixture model will be estimated. It should be a + one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type + it will be converted to the inner matrix of such type for the further computing. + @param means0 Initial means \f$a_k\f$ of mixture components. It is a one-channel matrix of + \f$nclusters \times dims\f$ size. If the matrix does not have CV_64F type it will be + converted to the inner matrix of such type for the further computing. + @param covs0 The vector of initial covariance matrices \f$S_k\f$ of mixture components. Each of + covariance matrices is a one-channel matrix of \f$dims \times dims\f$ size. If the matrices + do not have CV_64F type they will be converted to the inner matrices of such type for the + further computing. + @param weights0 Initial weights \f$\pi_k\f$ of mixture components. It should be a one-channel + floating-point matrix with \f$1 \times nclusters\f$ or \f$nclusters \times 1\f$ size. + @param logLikelihoods The optional output matrix that contains a likelihood logarithm value for + each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. + @param labels The optional output "class label" for each sample: + \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable + mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. + @param probs The optional output matrix that contains posterior probabilities of each Gaussian + mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and + CV_64FC1 type. + */ + CV_WRAP virtual bool trainE(InputArray samples, InputArray means0, + InputArray covs0=noArray(), + InputArray weights0=noArray(), + OutputArray logLikelihoods=noArray(), + OutputArray labels=noArray(), + OutputArray probs=noArray()) = 0; + + /** @brief Estimate the Gaussian mixture parameters from a samples set. + + This variation starts with Maximization step. You need to provide initial probabilities + \f$p_{i,k}\f$ to use this option. + + @param samples Samples from which the Gaussian mixture model will be estimated. It should be a + one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type + it will be converted to the inner matrix of such type for the further computing. + @param probs0 + @param logLikelihoods The optional output matrix that contains a likelihood logarithm value for + each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. + @param labels The optional output "class label" for each sample: + \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable + mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. + @param probs The optional output matrix that contains posterior probabilities of each Gaussian + mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and + CV_64FC1 type. + */ + CV_WRAP virtual bool trainM(InputArray samples, InputArray probs0, + OutputArray logLikelihoods=noArray(), + OutputArray labels=noArray(), + OutputArray probs=noArray()) = 0; + + /** Creates empty %EM model. + The model should be trained then using StatModel::train(traindata, flags) method. Alternatively, you + can use one of the EM::train\* methods or load it from file using Algorithm::load\<EM\>(filename). + */ + CV_WRAP static Ptr<EM> create(); + + /** @brief Loads and creates a serialized EM from a file + * + * Use EM::save to serialize and store an EM to disk. + * Load the EM from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized EM + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<EM> load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Decision Tree * +\****************************************************************************************/ + +/** @brief The class represents a single decision tree or a collection of decision trees. + +The current public interface of the class allows user to train only a single decision tree, however +the class is capable of storing multiple decision trees and using them for prediction (by summing +responses or using a voting schemes), and the derived from DTrees classes (such as RTrees and Boost) +use this capability to implement decision tree ensembles. + +@sa @ref ml_intro_trees +*/ +class CV_EXPORTS_W DTrees : public StatModel +{ +public: + /** Predict options */ + enum Flags { PREDICT_AUTO=0, PREDICT_SUM=(1<<8), PREDICT_MAX_VOTE=(2<<8), PREDICT_MASK=(3<<8) }; + + /** Cluster possible values of a categorical variable into K\<=maxCategories clusters to + find a suboptimal split. + If a discrete variable, on which the training procedure tries to make a split, takes more than + maxCategories values, the precise best subset estimation may take a very long time because the + algorithm is exponential. Instead, many decision trees engines (including our implementation) + try to find sub-optimal split in this case by clustering all the samples into maxCategories + clusters that is some categories are merged together. The clustering is applied only in n \> + 2-class classification problems for categorical variables with N \> max_categories possible + values. In case of regression and 2-class classification the optimal split can be found + efficiently without employing clustering, thus the parameter is not used in these cases. + Default value is 10.*/ + /** @see setMaxCategories */ + CV_WRAP virtual int getMaxCategories() const = 0; + /** @copybrief getMaxCategories @see getMaxCategories */ + CV_WRAP virtual void setMaxCategories(int val) = 0; + + /** The maximum possible depth of the tree. + That is the training algorithms attempts to split a node while its depth is less than maxDepth. + The root node has zero depth. The actual depth may be smaller if the other termination criteria + are met (see the outline of the training procedure @ref ml_intro_trees "here"), and/or if the + tree is pruned. Default value is INT_MAX.*/ + /** @see setMaxDepth */ + CV_WRAP virtual int getMaxDepth() const = 0; + /** @copybrief getMaxDepth @see getMaxDepth */ + CV_WRAP virtual void setMaxDepth(int val) = 0; + + /** If the number of samples in a node is less than this parameter then the node will not be split. + + Default value is 10.*/ + /** @see setMinSampleCount */ + CV_WRAP virtual int getMinSampleCount() const = 0; + /** @copybrief getMinSampleCount @see getMinSampleCount */ + CV_WRAP virtual void setMinSampleCount(int val) = 0; + + /** If CVFolds \> 1 then algorithms prunes the built decision tree using K-fold + cross-validation procedure where K is equal to CVFolds. + Default value is 10.*/ + /** @see setCVFolds */ + CV_WRAP virtual int getCVFolds() const = 0; + /** @copybrief getCVFolds @see getCVFolds */ + CV_WRAP virtual void setCVFolds(int val) = 0; + + /** If true then surrogate splits will be built. + These splits allow to work with missing data and compute variable importance correctly. + Default value is false. + @note currently it's not implemented.*/ + /** @see setUseSurrogates */ + CV_WRAP virtual bool getUseSurrogates() const = 0; + /** @copybrief getUseSurrogates @see getUseSurrogates */ + CV_WRAP virtual void setUseSurrogates(bool val) = 0; + + /** If true then a pruning will be harsher. + This will make a tree more compact and more resistant to the training data noise but a bit less + accurate. Default value is true.*/ + /** @see setUse1SERule */ + CV_WRAP virtual bool getUse1SERule() const = 0; + /** @copybrief getUse1SERule @see getUse1SERule */ + CV_WRAP virtual void setUse1SERule(bool val) = 0; + + /** If true then pruned branches are physically removed from the tree. + Otherwise they are retained and it is possible to get results from the original unpruned (or + pruned less aggressively) tree. Default value is true.*/ + /** @see setTruncatePrunedTree */ + CV_WRAP virtual bool getTruncatePrunedTree() const = 0; + /** @copybrief getTruncatePrunedTree @see getTruncatePrunedTree */ + CV_WRAP virtual void setTruncatePrunedTree(bool val) = 0; + + /** Termination criteria for regression trees. + If all absolute differences between an estimated value in a node and values of train samples + in this node are less than this parameter then the node will not be split further. Default + value is 0.01f*/ + /** @see setRegressionAccuracy */ + CV_WRAP virtual float getRegressionAccuracy() const = 0; + /** @copybrief getRegressionAccuracy @see getRegressionAccuracy */ + CV_WRAP virtual void setRegressionAccuracy(float val) = 0; + + /** @brief The array of a priori class probabilities, sorted by the class label value. + + The parameter can be used to tune the decision tree preferences toward a certain class. For + example, if you want to detect some rare anomaly occurrence, the training base will likely + contain much more normal cases than anomalies, so a very good classification performance + will be achieved just by considering every case as normal. To avoid this, the priors can be + specified, where the anomaly probability is artificially increased (up to 0.5 or even + greater), so the weight of the misclassified anomalies becomes much bigger, and the tree is + adjusted properly. + + You can also think about this parameter as weights of prediction categories which determine + relative weights that you give to misclassification. That is, if the weight of the first + category is 1 and the weight of the second category is 10, then each mistake in predicting + the second category is equivalent to making 10 mistakes in predicting the first category. + Default value is empty Mat.*/ + /** @see setPriors */ + CV_WRAP virtual cv::Mat getPriors() const = 0; + /** @copybrief getPriors @see getPriors */ + CV_WRAP virtual void setPriors(const cv::Mat &val) = 0; + + /** @brief The class represents a decision tree node. + */ + class CV_EXPORTS Node + { + public: + Node(); + double value; //!< Value at the node: a class label in case of classification or estimated + //!< function value in case of regression. + int classIdx; //!< Class index normalized to 0..class_count-1 range and assigned to the + //!< node. It is used internally in classification trees and tree ensembles. + int parent; //!< Index of the parent node + int left; //!< Index of the left child node + int right; //!< Index of right child node + int defaultDir; //!< Default direction where to go (-1: left or +1: right). It helps in the + //!< case of missing values. + int split; //!< Index of the first split + }; + + /** @brief The class represents split in a decision tree. + */ + class CV_EXPORTS Split + { + public: + Split(); + int varIdx; //!< Index of variable on which the split is created. + bool inversed; //!< If true, then the inverse split rule is used (i.e. left and right + //!< branches are exchanged in the rule expressions below). + float quality; //!< The split quality, a positive number. It is used to choose the best split. + int next; //!< Index of the next split in the list of splits for the node + float c; /**< The threshold value in case of split on an ordered variable. + The rule is: + @code{.none} + if var_value < c + then next_node <- left + else next_node <- right + @endcode */ + int subsetOfs; /**< Offset of the bitset used by the split on a categorical variable. + The rule is: + @code{.none} + if bitset[var_value] == 1 + then next_node <- left + else next_node <- right + @endcode */ + }; + + /** @brief Returns indices of root nodes + */ + virtual const std::vector<int>& getRoots() const = 0; + /** @brief Returns all the nodes + + all the node indices are indices in the returned vector + */ + virtual const std::vector<Node>& getNodes() const = 0; + /** @brief Returns all the splits + + all the split indices are indices in the returned vector + */ + virtual const std::vector<Split>& getSplits() const = 0; + /** @brief Returns all the bitsets for categorical splits + + Split::subsetOfs is an offset in the returned vector + */ + virtual const std::vector<int>& getSubsets() const = 0; + + /** @brief Creates the empty model + + The static method creates empty decision tree with the specified parameters. It should be then + trained using train method (see StatModel::train). Alternatively, you can load the model from + file using Algorithm::load\<DTrees\>(filename). + */ + CV_WRAP static Ptr<DTrees> create(); + + /** @brief Loads and creates a serialized DTrees from a file + * + * Use DTree::save to serialize and store an DTree to disk. + * Load the DTree from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized DTree + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<DTrees> load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Random Trees Classifier * +\****************************************************************************************/ + +/** @brief The class implements the random forest predictor. + +@sa @ref ml_intro_rtrees + */ +class CV_EXPORTS_W RTrees : public DTrees +{ +public: + + /** If true then variable importance will be calculated and then it can be retrieved by RTrees::getVarImportance. + Default value is false.*/ + /** @see setCalculateVarImportance */ + CV_WRAP virtual bool getCalculateVarImportance() const = 0; + /** @copybrief getCalculateVarImportance @see getCalculateVarImportance */ + CV_WRAP virtual void setCalculateVarImportance(bool val) = 0; + + /** The size of the randomly selected subset of features at each tree node and that are used + to find the best split(s). + If you set it to 0 then the size will be set to the square root of the total number of + features. Default value is 0.*/ + /** @see setActiveVarCount */ + CV_WRAP virtual int getActiveVarCount() const = 0; + /** @copybrief getActiveVarCount @see getActiveVarCount */ + CV_WRAP virtual void setActiveVarCount(int val) = 0; + + /** The termination criteria that specifies when the training algorithm stops. + Either when the specified number of trees is trained and added to the ensemble or when + sufficient accuracy (measured as OOB error) is achieved. Typically the more trees you have the + better the accuracy. However, the improvement in accuracy generally diminishes and asymptotes + pass a certain number of trees. Also to keep in mind, the number of tree increases the + prediction time linearly. Default value is TermCriteria(TermCriteria::MAX_ITERS + + TermCriteria::EPS, 50, 0.1)*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const TermCriteria &val) = 0; + + /** Returns the variable importance array. + The method returns the variable importance vector, computed at the training stage when + CalculateVarImportance is set to true. If this flag was set to false, the empty matrix is + returned. + */ + CV_WRAP virtual Mat getVarImportance() const = 0; + + /** Returns the result of each individual tree in the forest. + In case the model is a regression problem, the method will return each of the trees' + results for each of the sample cases. If the model is a classifier, it will return + a Mat with samples + 1 rows, where the first row gives the class number and the + following rows return the votes each class had for each sample. + @param samples Array containing the samples for which votes will be calculated. + @param results Array where the result of the calculation will be written. + @param flags Flags for defining the type of RTrees. + */ + CV_WRAP void getVotes(InputArray samples, OutputArray results, int flags) const; + + /** Creates the empty model. + Use StatModel::train to train the model, StatModel::train to create and train the model, + Algorithm::load to load the pre-trained model. + */ + CV_WRAP static Ptr<RTrees> create(); + + /** @brief Loads and creates a serialized RTree from a file + * + * Use RTree::save to serialize and store an RTree to disk. + * Load the RTree from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized RTree + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<RTrees> load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Boosted tree classifier * +\****************************************************************************************/ + +/** @brief Boosted tree classifier derived from DTrees + +@sa @ref ml_intro_boost + */ +class CV_EXPORTS_W Boost : public DTrees +{ +public: + /** Type of the boosting algorithm. + See Boost::Types. Default value is Boost::REAL. */ + /** @see setBoostType */ + CV_WRAP virtual int getBoostType() const = 0; + /** @copybrief getBoostType @see getBoostType */ + CV_WRAP virtual void setBoostType(int val) = 0; + + /** The number of weak classifiers. + Default value is 100. */ + /** @see setWeakCount */ + CV_WRAP virtual int getWeakCount() const = 0; + /** @copybrief getWeakCount @see getWeakCount */ + CV_WRAP virtual void setWeakCount(int val) = 0; + + /** A threshold between 0 and 1 used to save computational time. + Samples with summary weight \f$\leq 1 - weight_trim_rate\f$ do not participate in the *next* + iteration of training. Set this parameter to 0 to turn off this functionality. Default value is 0.95.*/ + /** @see setWeightTrimRate */ + CV_WRAP virtual double getWeightTrimRate() const = 0; + /** @copybrief getWeightTrimRate @see getWeightTrimRate */ + CV_WRAP virtual void setWeightTrimRate(double val) = 0; + + /** Boosting type. + Gentle AdaBoost and Real AdaBoost are often the preferable choices. */ + enum Types { + DISCRETE=0, //!< Discrete AdaBoost. + REAL=1, //!< Real AdaBoost. It is a technique that utilizes confidence-rated predictions + //!< and works well with categorical data. + LOGIT=2, //!< LogitBoost. It can produce good regression fits. + GENTLE=3 //!< Gentle AdaBoost. It puts less weight on outlier data points and for that + //!<reason is often good with regression data. + }; + + /** Creates the empty model. + Use StatModel::train to train the model, Algorithm::load\<Boost\>(filename) to load the pre-trained model. */ + CV_WRAP static Ptr<Boost> create(); + + /** @brief Loads and creates a serialized Boost from a file + * + * Use Boost::save to serialize and store an RTree to disk. + * Load the Boost from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized Boost + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<Boost> load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Gradient Boosted Trees * +\****************************************************************************************/ + +/*class CV_EXPORTS_W GBTrees : public DTrees +{ +public: + struct CV_EXPORTS_W_MAP Params : public DTrees::Params + { + CV_PROP_RW int weakCount; + CV_PROP_RW int lossFunctionType; + CV_PROP_RW float subsamplePortion; + CV_PROP_RW float shrinkage; + + Params(); + Params( int lossFunctionType, int weakCount, float shrinkage, + float subsamplePortion, int maxDepth, bool useSurrogates ); + }; + + enum {SQUARED_LOSS=0, ABSOLUTE_LOSS, HUBER_LOSS=3, DEVIANCE_LOSS}; + + virtual void setK(int k) = 0; + + virtual float predictSerial( InputArray samples, + OutputArray weakResponses, int flags) const = 0; + + static Ptr<GBTrees> create(const Params& p); +};*/ + +/****************************************************************************************\ +* Artificial Neural Networks (ANN) * +\****************************************************************************************/ + +/////////////////////////////////// Multi-Layer Perceptrons ////////////////////////////// + +/** @brief Artificial Neural Networks - Multi-Layer Perceptrons. + +Unlike many other models in ML that are constructed and trained at once, in the MLP model these +steps are separated. First, a network with the specified topology is created using the non-default +constructor or the method ANN_MLP::create. All the weights are set to zeros. Then, the network is +trained using a set of input and output vectors. The training procedure can be repeated more than +once, that is, the weights can be adjusted based on the new training data. + +Additional flags for StatModel::train are available: ANN_MLP::TrainFlags. + +@sa @ref ml_intro_ann + */ +class CV_EXPORTS_W ANN_MLP : public StatModel +{ +public: + /** Available training methods */ + enum TrainingMethods { + BACKPROP=0, //!< The back-propagation algorithm. + RPROP = 1, //!< The RPROP algorithm. See @cite RPROP93 for details. + ANNEAL = 2 //!< The simulated annealing algorithm. See @cite Kirkpatrick83 for details. + }; + + /** Sets training method and common parameters. + @param method Default value is ANN_MLP::RPROP. See ANN_MLP::TrainingMethods. + @param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP and to initialT for ANN_MLP::ANNEAL. + @param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP and to finalT for ANN_MLP::ANNEAL. + */ + CV_WRAP virtual void setTrainMethod(int method, double param1 = 0, double param2 = 0) = 0; + + /** Returns current training method */ + CV_WRAP virtual int getTrainMethod() const = 0; + + /** Initialize the activation function for each neuron. + Currently the default and the only fully supported activation function is ANN_MLP::SIGMOID_SYM. + @param type The type of activation function. See ANN_MLP::ActivationFunctions. + @param param1 The first parameter of the activation function, \f$\alpha\f$. Default value is 0. + @param param2 The second parameter of the activation function, \f$\beta\f$. Default value is 0. + */ + CV_WRAP virtual void setActivationFunction(int type, double param1 = 0, double param2 = 0) = 0; + + /** Integer vector specifying the number of neurons in each layer including the input and output layers. + The very first element specifies the number of elements in the input layer. + The last element - number of elements in the output layer. Default value is empty Mat. + @sa getLayerSizes */ + CV_WRAP virtual void setLayerSizes(InputArray _layer_sizes) = 0; + + /** Integer vector specifying the number of neurons in each layer including the input and output layers. + The very first element specifies the number of elements in the input layer. + The last element - number of elements in the output layer. + @sa setLayerSizes */ + CV_WRAP virtual cv::Mat getLayerSizes() const = 0; + + /** Termination criteria of the training algorithm. + You can specify the maximum number of iterations (maxCount) and/or how much the error could + change between the iterations to make the algorithm continue (epsilon). Default value is + TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, 0.01).*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(TermCriteria val) = 0; + + /** BPROP: Strength of the weight gradient term. + The recommended value is about 0.1. Default value is 0.1.*/ + /** @see setBackpropWeightScale */ + CV_WRAP virtual double getBackpropWeightScale() const = 0; + /** @copybrief getBackpropWeightScale @see getBackpropWeightScale */ + CV_WRAP virtual void setBackpropWeightScale(double val) = 0; + + /** BPROP: Strength of the momentum term (the difference between weights on the 2 previous iterations). + This parameter provides some inertia to smooth the random fluctuations of the weights. It can + vary from 0 (the feature is disabled) to 1 and beyond. The value 0.1 or so is good enough. + Default value is 0.1.*/ + /** @see setBackpropMomentumScale */ + CV_WRAP virtual double getBackpropMomentumScale() const = 0; + /** @copybrief getBackpropMomentumScale @see getBackpropMomentumScale */ + CV_WRAP virtual void setBackpropMomentumScale(double val) = 0; + + /** RPROP: Initial value \f$\Delta_0\f$ of update-values \f$\Delta_{ij}\f$. + Default value is 0.1.*/ + /** @see setRpropDW0 */ + CV_WRAP virtual double getRpropDW0() const = 0; + /** @copybrief getRpropDW0 @see getRpropDW0 */ + CV_WRAP virtual void setRpropDW0(double val) = 0; + + /** RPROP: Increase factor \f$\eta^+\f$. + It must be \>1. Default value is 1.2.*/ + /** @see setRpropDWPlus */ + CV_WRAP virtual double getRpropDWPlus() const = 0; + /** @copybrief getRpropDWPlus @see getRpropDWPlus */ + CV_WRAP virtual void setRpropDWPlus(double val) = 0; + + /** RPROP: Decrease factor \f$\eta^-\f$. + It must be \<1. Default value is 0.5.*/ + /** @see setRpropDWMinus */ + CV_WRAP virtual double getRpropDWMinus() const = 0; + /** @copybrief getRpropDWMinus @see getRpropDWMinus */ + CV_WRAP virtual void setRpropDWMinus(double val) = 0; + + /** RPROP: Update-values lower limit \f$\Delta_{min}\f$. + It must be positive. Default value is FLT_EPSILON.*/ + /** @see setRpropDWMin */ + CV_WRAP virtual double getRpropDWMin() const = 0; + /** @copybrief getRpropDWMin @see getRpropDWMin */ + CV_WRAP virtual void setRpropDWMin(double val) = 0; + + /** RPROP: Update-values upper limit \f$\Delta_{max}\f$. + It must be \>1. Default value is 50.*/ + /** @see setRpropDWMax */ + CV_WRAP virtual double getRpropDWMax() const = 0; + /** @copybrief getRpropDWMax @see getRpropDWMax */ + CV_WRAP virtual void setRpropDWMax(double val) = 0; + + /** ANNEAL: Update initial temperature. + It must be \>=0. Default value is 10.*/ + /** @see setAnnealInitialT */ + CV_WRAP double getAnnealInitialT() const; + /** @copybrief getAnnealInitialT @see getAnnealInitialT */ + CV_WRAP void setAnnealInitialT(double val); + + /** ANNEAL: Update final temperature. + It must be \>=0 and less than initialT. Default value is 0.1.*/ + /** @see setAnnealFinalT */ + CV_WRAP double getAnnealFinalT() const; + /** @copybrief getAnnealFinalT @see getAnnealFinalT */ + CV_WRAP void setAnnealFinalT(double val); + + /** ANNEAL: Update cooling ratio. + It must be \>0 and less than 1. Default value is 0.95.*/ + /** @see setAnnealCoolingRatio */ + CV_WRAP double getAnnealCoolingRatio() const; + /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ + CV_WRAP void setAnnealCoolingRatio(double val); + + /** ANNEAL: Update iteration per step. + It must be \>0 . Default value is 10.*/ + /** @see setAnnealItePerStep */ + CV_WRAP int getAnnealItePerStep() const; + /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ + CV_WRAP void setAnnealItePerStep(int val); + + /** @brief Set/initialize anneal RNG */ + void setAnnealEnergyRNG(const RNG& rng); + + /** possible activation functions */ + enum ActivationFunctions { + /** Identity function: \f$f(x)=x\f$ */ + IDENTITY = 0, + /** Symmetrical sigmoid: \f$f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x})\f$ + @note + If you are using the default sigmoid activation function with the default parameter values + fparam1=0 and fparam2=0 then the function used is y = 1.7159\*tanh(2/3 \* x), so the output + will range from [-1.7159, 1.7159], instead of [0,1].*/ + SIGMOID_SYM = 1, + /** Gaussian function: \f$f(x)=\beta e^{-\alpha x*x}\f$ */ + GAUSSIAN = 2, + /** ReLU function: \f$f(x)=max(0,x)\f$ */ + RELU = 3, + /** Leaky ReLU function: for x>0 \f$f(x)=x \f$ and x<=0 \f$f(x)=\alpha x \f$*/ + LEAKYRELU= 4 + }; + + /** Train options */ + enum TrainFlags { + /** Update the network weights, rather than compute them from scratch. In the latter case + the weights are initialized using the Nguyen-Widrow algorithm. */ + UPDATE_WEIGHTS = 1, + /** Do not normalize the input vectors. If this flag is not set, the training algorithm + normalizes each input feature independently, shifting its mean value to 0 and making the + standard deviation equal to 1. If the network is assumed to be updated frequently, the new + training data could be much different from original one. In this case, you should take care + of proper normalization. */ + NO_INPUT_SCALE = 2, + /** Do not normalize the output vectors. If the flag is not set, the training algorithm + normalizes each output feature independently, by transforming it to the certain range + depending on the used activation function. */ + NO_OUTPUT_SCALE = 4 + }; + + CV_WRAP virtual Mat getWeights(int layerIdx) const = 0; + + /** @brief Creates empty model + + Use StatModel::train to train the model, Algorithm::load\<ANN_MLP\>(filename) to load the pre-trained model. + Note that the train method has optional flags: ANN_MLP::TrainFlags. + */ + CV_WRAP static Ptr<ANN_MLP> create(); + + /** @brief Loads and creates a serialized ANN from a file + * + * Use ANN::save to serialize and store an ANN to disk. + * Load the ANN from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized ANN + */ + CV_WRAP static Ptr<ANN_MLP> load(const String& filepath); + +}; + +/****************************************************************************************\ +* Logistic Regression * +\****************************************************************************************/ + +/** @brief Implements Logistic Regression classifier. + +@sa @ref ml_intro_lr + */ +class CV_EXPORTS_W LogisticRegression : public StatModel +{ +public: + + /** Learning rate. */ + /** @see setLearningRate */ + CV_WRAP virtual double getLearningRate() const = 0; + /** @copybrief getLearningRate @see getLearningRate */ + CV_WRAP virtual void setLearningRate(double val) = 0; + + /** Number of iterations. */ + /** @see setIterations */ + CV_WRAP virtual int getIterations() const = 0; + /** @copybrief getIterations @see getIterations */ + CV_WRAP virtual void setIterations(int val) = 0; + + /** Kind of regularization to be applied. See LogisticRegression::RegKinds. */ + /** @see setRegularization */ + CV_WRAP virtual int getRegularization() const = 0; + /** @copybrief getRegularization @see getRegularization */ + CV_WRAP virtual void setRegularization(int val) = 0; + + /** Kind of training method used. See LogisticRegression::Methods. */ + /** @see setTrainMethod */ + CV_WRAP virtual int getTrainMethod() const = 0; + /** @copybrief getTrainMethod @see getTrainMethod */ + CV_WRAP virtual void setTrainMethod(int val) = 0; + + /** Specifies the number of training samples taken in each step of Mini-Batch Gradient + Descent. Will only be used if using LogisticRegression::MINI_BATCH training algorithm. It + has to take values less than the total number of training samples. */ + /** @see setMiniBatchSize */ + CV_WRAP virtual int getMiniBatchSize() const = 0; + /** @copybrief getMiniBatchSize @see getMiniBatchSize */ + CV_WRAP virtual void setMiniBatchSize(int val) = 0; + + /** Termination criteria of the algorithm. */ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(TermCriteria val) = 0; + + //! Regularization kinds + enum RegKinds { + REG_DISABLE = -1, //!< Regularization disabled + REG_L1 = 0, //!< %L1 norm + REG_L2 = 1 //!< %L2 norm + }; + + //! Training methods + enum Methods { + BATCH = 0, + MINI_BATCH = 1 //!< Set MiniBatchSize to a positive integer when using this method. + }; + + /** @brief Predicts responses for input samples and returns a float type. + + @param samples The input data for the prediction algorithm. Matrix [m x n], where each row + contains variables (features) of one object being classified. Should have data type CV_32F. + @param results Predicted labels as a column matrix of type CV_32S. + @param flags Not used. + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const CV_OVERRIDE = 0; + + /** @brief This function returns the trained parameters arranged across rows. + + For a two class classifcation problem, it returns a row matrix. It returns learnt parameters of + the Logistic Regression as a matrix of type CV_32F. + */ + CV_WRAP virtual Mat get_learnt_thetas() const = 0; + + /** @brief Creates empty model. + + Creates Logistic Regression model with parameters given. + */ + CV_WRAP static Ptr<LogisticRegression> create(); + + /** @brief Loads and creates a serialized LogisticRegression from a file + * + * Use LogisticRegression::save to serialize and store an LogisticRegression to disk. + * Load the LogisticRegression from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized LogisticRegression + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<LogisticRegression> load(const String& filepath , const String& nodeName = String()); +}; + + +/****************************************************************************************\ +* Stochastic Gradient Descent SVM Classifier * +\****************************************************************************************/ + +/*! +@brief Stochastic Gradient Descent SVM classifier + +SVMSGD provides a fast and easy-to-use implementation of the SVM classifier using the Stochastic Gradient Descent approach, +as presented in @cite bottou2010large. + +The classifier has following parameters: +- model type, +- margin type, +- margin regularization (\f$\lambda\f$), +- initial step size (\f$\gamma_0\f$), +- step decreasing power (\f$c\f$), +- and termination criteria. + +The model type may have one of the following values: \ref SGD and \ref ASGD. + +- \ref SGD is the classic version of SVMSGD classifier: every next step is calculated by the formula + \f[w_{t+1} = w_t - \gamma(t) \frac{dQ_i}{dw} |_{w = w_t}\f] + where + - \f$w_t\f$ is the weights vector for decision function at step \f$t\f$, + - \f$\gamma(t)\f$ is the step size of model parameters at the iteration \f$t\f$, it is decreased on each step by the formula + \f$\gamma(t) = \gamma_0 (1 + \lambda \gamma_0 t) ^ {-c}\f$ + - \f$Q_i\f$ is the target functional from SVM task for sample with number \f$i\f$, this sample is chosen stochastically on each step of the algorithm. + +- \ref ASGD is Average Stochastic Gradient Descent SVM Classifier. ASGD classifier averages weights vector on each step of algorithm by the formula +\f$\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\f$ + +The recommended model type is ASGD (following @cite bottou2010large). + +The margin type may have one of the following values: \ref SOFT_MARGIN or \ref HARD_MARGIN. + +- You should use \ref HARD_MARGIN type, if you have linearly separable sets. +- You should use \ref SOFT_MARGIN type, if you have non-linearly separable sets or sets with outliers. +- In the general case (if you know nothing about linear separability of your sets), use SOFT_MARGIN. + +The other parameters may be described as follows: +- Margin regularization parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers + (the less the parameter, the less probability that an outlier will be ignored). + Recommended value for SGD model is 0.0001, for ASGD model is 0.00001. + +- Initial step size parameter is the initial value for the step size \f$\gamma(t)\f$. + You will have to find the best initial step for your problem. + +- Step decreasing power is the power parameter for \f$\gamma(t)\f$ decreasing by the formula, mentioned above. + Recommended value for SGD model is 1, for ASGD model is 0.75. + +- Termination criteria can be TermCriteria::COUNT, TermCriteria::EPS or TermCriteria::COUNT + TermCriteria::EPS. + You will have to find the best termination criteria for your problem. + +Note that the parameters margin regularization, initial step size, and step decreasing power should be positive. + +To use SVMSGD algorithm do as follows: + +- first, create the SVMSGD object. The algoorithm will set optimal parameters by default, but you can set your own parameters via functions setSvmsgdType(), + setMarginType(), setMarginRegularization(), setInitialStepSize(), and setStepDecreasingPower(). + +- then the SVM model can be trained using the train features and the correspondent labels by the method train(). + +- after that, the label of a new feature vector can be predicted using the method predict(). + +@code +// Create empty object +cv::Ptr<SVMSGD> svmsgd = SVMSGD::create(); + +// Train the Stochastic Gradient Descent SVM +svmsgd->train(trainData); + +// Predict labels for the new samples +svmsgd->predict(samples, responses); +@endcode + +*/ + +class CV_EXPORTS_W SVMSGD : public cv::ml::StatModel +{ +public: + + /** SVMSGD type. + ASGD is often the preferable choice. */ + enum SvmsgdType + { + SGD, //!< Stochastic Gradient Descent + ASGD //!< Average Stochastic Gradient Descent + }; + + /** Margin type.*/ + enum MarginType + { + SOFT_MARGIN, //!< General case, suits to the case of non-linearly separable sets, allows outliers. + HARD_MARGIN //!< More accurate for the case of linearly separable sets. + }; + + /** + * @return the weights of the trained model (decision function f(x) = weights * x + shift). + */ + CV_WRAP virtual Mat getWeights() = 0; + + /** + * @return the shift of the trained model (decision function f(x) = weights * x + shift). + */ + CV_WRAP virtual float getShift() = 0; + + /** @brief Creates empty model. + * Use StatModel::train to train the model. Since %SVMSGD has several parameters, you may want to + * find the best parameters for your problem or use setOptimalParameters() to set some default parameters. + */ + CV_WRAP static Ptr<SVMSGD> create(); + + /** @brief Loads and creates a serialized SVMSGD from a file + * + * Use SVMSGD::save to serialize and store an SVMSGD to disk. + * Load the SVMSGD from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized SVMSGD + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr<SVMSGD> load(const String& filepath , const String& nodeName = String()); + + /** @brief Function sets optimal parameters values for chosen SVM SGD model. + * @param svmsgdType is the type of SVMSGD classifier. + * @param marginType is the type of margin constraint. + */ + CV_WRAP virtual void setOptimalParameters(int svmsgdType = SVMSGD::ASGD, int marginType = SVMSGD::SOFT_MARGIN) = 0; + + /** @brief %Algorithm type, one of SVMSGD::SvmsgdType. */ + /** @see setSvmsgdType */ + CV_WRAP virtual int getSvmsgdType() const = 0; + /** @copybrief getSvmsgdType @see getSvmsgdType */ + CV_WRAP virtual void setSvmsgdType(int svmsgdType) = 0; + + /** @brief %Margin type, one of SVMSGD::MarginType. */ + /** @see setMarginType */ + CV_WRAP virtual int getMarginType() const = 0; + /** @copybrief getMarginType @see getMarginType */ + CV_WRAP virtual void setMarginType(int marginType) = 0; + + /** @brief Parameter marginRegularization of a %SVMSGD optimization problem. */ + /** @see setMarginRegularization */ + CV_WRAP virtual float getMarginRegularization() const = 0; + /** @copybrief getMarginRegularization @see getMarginRegularization */ + CV_WRAP virtual void setMarginRegularization(float marginRegularization) = 0; + + /** @brief Parameter initialStepSize of a %SVMSGD optimization problem. */ + /** @see setInitialStepSize */ + CV_WRAP virtual float getInitialStepSize() const = 0; + /** @copybrief getInitialStepSize @see getInitialStepSize */ + CV_WRAP virtual void setInitialStepSize(float InitialStepSize) = 0; + + /** @brief Parameter stepDecreasingPower of a %SVMSGD optimization problem. */ + /** @see setStepDecreasingPower */ + CV_WRAP virtual float getStepDecreasingPower() const = 0; + /** @copybrief getStepDecreasingPower @see getStepDecreasingPower */ + CV_WRAP virtual void setStepDecreasingPower(float stepDecreasingPower) = 0; + + /** @brief Termination criteria of the training algorithm. + You can specify the maximum number of iterations (maxCount) and/or how much the error could + change between the iterations to make the algorithm continue (epsilon).*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const cv::TermCriteria &val) = 0; +}; + + +/****************************************************************************************\ +* Auxiliary functions declarations * +\****************************************************************************************/ + +/** @brief Generates _sample_ from multivariate normal distribution + +@param mean an average row vector +@param cov symmetric covariation matrix +@param nsamples returned samples count +@param samples returned samples array +*/ +CV_EXPORTS void randMVNormal( InputArray mean, InputArray cov, int nsamples, OutputArray samples); + +/** @brief Creates test set */ +CV_EXPORTS void createConcentricSpheresTestSet( int nsamples, int nfeatures, int nclasses, + OutputArray samples, OutputArray responses); + +/** @brief Artificial Neural Networks - Multi-Layer Perceptrons. + +@sa @ref ml_intro_ann +*/ +class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP +{ +public: + /** @see setAnnealInitialT */ + CV_WRAP virtual double getAnnealInitialT() const = 0; + /** @copybrief getAnnealInitialT @see getAnnealInitialT */ + CV_WRAP virtual void setAnnealInitialT(double val) = 0; + + /** ANNEAL: Update final temperature. + It must be \>=0 and less than initialT. Default value is 0.1.*/ + /** @see setAnnealFinalT */ + CV_WRAP virtual double getAnnealFinalT() const = 0; + /** @copybrief getAnnealFinalT @see getAnnealFinalT */ + CV_WRAP virtual void setAnnealFinalT(double val) = 0; + + /** ANNEAL: Update cooling ratio. + It must be \>0 and less than 1. Default value is 0.95.*/ + /** @see setAnnealCoolingRatio */ + CV_WRAP virtual double getAnnealCoolingRatio() const = 0; + /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ + CV_WRAP virtual void setAnnealCoolingRatio(double val) = 0; + + /** ANNEAL: Update iteration per step. + It must be \>0 . Default value is 10.*/ + /** @see setAnnealItePerStep */ + CV_WRAP virtual int getAnnealItePerStep() const = 0; + /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ + CV_WRAP virtual void setAnnealItePerStep(int val) = 0; + + /** @brief Set/initialize anneal RNG */ + virtual void setAnnealEnergyRNG(const RNG& rng) = 0; +}; + + +/****************************************************************************************\ +* Simulated annealing solver * +\****************************************************************************************/ + +#ifdef CV_DOXYGEN +/** @brief This class declares example interface for system state used in simulated annealing optimization algorithm. + +@note This class is not defined in C++ code and can't be use directly - you need your own implementation with the same methods. +*/ +struct SimulatedAnnealingSolverSystem +{ + /** Give energy value for a state of system.*/ + double energy() const; + /** Function which change the state of system (random perturbation).*/ + void changeState(); + /** Function to reverse to the previous state. Can be called once only after changeState(). */ + void reverseState(); +}; +#endif // CV_DOXYGEN + +/** @brief The class implements simulated annealing for optimization. + +@cite Kirkpatrick83 for details + +@param solverSystem optimization system (see SimulatedAnnealingSolverSystem) +@param initialTemperature initial temperature +@param finalTemperature final temperature +@param coolingRatio temperature step multiplies +@param iterationsPerStep number of iterations per temperature changing step +@param lastTemperature optional output for last used temperature +@param rngEnergy specify custom random numbers generator (cv::theRNG() by default) +*/ +template<class SimulatedAnnealingSolverSystem> +int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem, + double initialTemperature, double finalTemperature, double coolingRatio, + size_t iterationsPerStep, + CV_OUT double* lastTemperature = NULL, + cv::RNG& rngEnergy = cv::theRNG() +); + +//! @} ml + +} +} + +#include <opencv2/ml/ml.inl.hpp> + +#endif // __cplusplus +#endif // OPENCV_ML_HPP + +/* End of file. */ diff --git a/include/opencv2/ml/ml.hpp b/include/opencv2/ml/ml.hpp new file mode 100644 index 0000000..f6f9cd8 --- /dev/null +++ b/include/opencv2/ml/ml.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/ml.hpp" diff --git a/include/opencv2/ml/ml.inl.hpp b/include/opencv2/ml/ml.inl.hpp new file mode 100644 index 0000000..dc9c783 --- /dev/null +++ b/include/opencv2/ml/ml.inl.hpp @@ -0,0 +1,60 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_ML_INL_HPP +#define OPENCV_ML_INL_HPP + +namespace cv { namespace ml { + +// declared in ml.hpp +template<class SimulatedAnnealingSolverSystem> +int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem, + double initialTemperature, double finalTemperature, double coolingRatio, + size_t iterationsPerStep, + CV_OUT double* lastTemperature, + cv::RNG& rngEnergy +) +{ + CV_Assert(finalTemperature > 0); + CV_Assert(initialTemperature > finalTemperature); + CV_Assert(iterationsPerStep > 0); + CV_Assert(coolingRatio < 1.0f); + double Ti = initialTemperature; + double previousEnergy = solverSystem.energy(); + int exchange = 0; + while (Ti > finalTemperature) + { + for (size_t i = 0; i < iterationsPerStep; i++) + { + solverSystem.changeState(); + double newEnergy = solverSystem.energy(); + if (newEnergy < previousEnergy) + { + previousEnergy = newEnergy; + exchange++; + } + else + { + double r = rngEnergy.uniform(0.0, 1.0); + if (r < std::exp(-(newEnergy - previousEnergy) / Ti)) + { + previousEnergy = newEnergy; + exchange++; + } + else + { + solverSystem.reverseState(); + } + } + } + Ti *= coolingRatio; + } + if (lastTemperature) + *lastTemperature = Ti; + return exchange; +} + +}} //namespace + +#endif // OPENCV_ML_INL_HPP diff --git a/include/opencv2/objdetect.hpp b/include/opencv2/objdetect.hpp new file mode 100644 index 0000000..cc9c4e1 --- /dev/null +++ b/include/opencv2/objdetect.hpp @@ -0,0 +1,743 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OBJDETECT_HPP +#define OPENCV_OBJDETECT_HPP + +#include "opencv2/core.hpp" + +/** +@defgroup objdetect Object Detection + +Haar Feature-based Cascade Classifier for Object Detection +---------------------------------------------------------- + +The object detector described below has been initially proposed by Paul Viola @cite Viola01 and +improved by Rainer Lienhart @cite Lienhart02 . + +First, a classifier (namely a *cascade of boosted classifiers working with haar-like features*) is +trained with a few hundred sample views of a particular object (i.e., a face or a car), called +positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary +images of the same size. + +After a classifier is trained, it can be applied to a region of interest (of the same size as used +during the training) in an input image. The classifier outputs a "1" if the region is likely to show +the object (i.e., face/car), and "0" otherwise. To search for the object in the whole image one can +move the search window across the image and check every location using the classifier. The +classifier is designed so that it can be easily "resized" in order to be able to find the objects of +interest at different sizes, which is more efficient than resizing the image itself. So, to find an +object of an unknown size in the image the scan procedure should be done several times at different +scales. + +The word "cascade" in the classifier name means that the resultant classifier consists of several +simpler classifiers (*stages*) that are applied subsequently to a region of interest until at some +stage the candidate is rejected or all the stages are passed. The word "boosted" means that the +classifiers at every stage of the cascade are complex themselves and they are built out of basic +classifiers using one of four different boosting techniques (weighted voting). Currently Discrete +Adaboost, Real Adaboost, Gentle Adaboost and Logitboost are supported. The basic classifiers are +decision-tree classifiers with at least 2 leaves. Haar-like features are the input to the basic +classifiers, and are calculated as described below. The current algorithm uses the following +Haar-like features: + +![image](pics/haarfeatures.png) + +The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within +the region of interest and the scale (this scale is not the same as the scale used at the detection +stage, though these two scales are multiplied). For example, in the case of the third line feature +(2c) the response is calculated as the difference between the sum of image pixels under the +rectangle covering the whole feature (including the two white stripes and the black stripe in the +middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to +compensate for the differences in the size of areas. The sums of pixel values over a rectangular +regions are calculated rapidly using integral images (see below and the integral description). + +To see the object detector at work, have a look at the facedetect demo: +<https://github.com/opencv/opencv/tree/3.4/samples/cpp/dbt_face_detection.cpp> + +The following reference is for the detection part only. There is a separate application called +opencv_traincascade that can train a cascade of boosted classifiers from a set of samples. + +@note In the new C++ interface it is also possible to use LBP (local binary pattern) features in +addition to Haar-like features. .. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection +using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at +<http://research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_CVPR2001.pdf> + +@{ + @defgroup objdetect_c C API +@} + */ + +typedef struct CvHaarClassifierCascade CvHaarClassifierCascade; + +namespace cv +{ + +//! @addtogroup objdetect +//! @{ + +///////////////////////////// Object Detection //////////////////////////// + +//! class for grouping object candidates, detected by Cascade Classifier, HOG etc. +//! instance of the class is to be passed to cv::partition (see cxoperations.hpp) +class CV_EXPORTS SimilarRects +{ +public: + SimilarRects(double _eps) : eps(_eps) {} + inline bool operator()(const Rect& r1, const Rect& r2) const + { + double delta = eps * ((std::min)(r1.width, r2.width) + (std::min)(r1.height, r2.height)) * 0.5; + return std::abs(r1.x - r2.x) <= delta && + std::abs(r1.y - r2.y) <= delta && + std::abs(r1.x + r1.width - r2.x - r2.width) <= delta && + std::abs(r1.y + r1.height - r2.y - r2.height) <= delta; + } + double eps; +}; + +/** @brief Groups the object candidate rectangles. + +@param rectList Input/output vector of rectangles. Output vector includes retained and grouped +rectangles. (The Python list is not modified in place.) +@param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a +group of rectangles to retain it. +@param eps Relative difference between sides of the rectangles to merge them into a group. + +The function is a wrapper for the generic function partition . It clusters all the input rectangles +using the rectangle equivalence criteria that combines rectangles with similar sizes and similar +locations. The similarity is defined by eps. When eps=0 , no clustering is done at all. If +\f$\texttt{eps}\rightarrow +\inf\f$ , all the rectangles are put in one cluster. Then, the small +clusters containing less than or equal to groupThreshold rectangles are rejected. In each other +cluster, the average rectangle is computed and put into the output rectangle list. + */ +CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, double eps = 0.2); +/** @overload */ +CV_EXPORTS_W void groupRectangles(CV_IN_OUT std::vector<Rect>& rectList, CV_OUT std::vector<int>& weights, + int groupThreshold, double eps = 0.2); +/** @overload */ +CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, + double eps, std::vector<int>* weights, std::vector<double>* levelWeights ); +/** @overload */ +CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, std::vector<int>& rejectLevels, + std::vector<double>& levelWeights, int groupThreshold, double eps = 0.2); +/** @overload */ +CV_EXPORTS void groupRectangles_meanshift(std::vector<Rect>& rectList, std::vector<double>& foundWeights, + std::vector<double>& foundScales, + double detectThreshold = 0.0, Size winDetSize = Size(64, 128)); + +template<> CV_EXPORTS void DefaultDeleter<CvHaarClassifierCascade>::operator ()(CvHaarClassifierCascade* obj) const; + +enum { CASCADE_DO_CANNY_PRUNING = 1, + CASCADE_SCALE_IMAGE = 2, + CASCADE_FIND_BIGGEST_OBJECT = 4, + CASCADE_DO_ROUGH_SEARCH = 8 + }; + +class CV_EXPORTS_W BaseCascadeClassifier : public Algorithm +{ +public: + virtual ~BaseCascadeClassifier(); + virtual bool empty() const CV_OVERRIDE = 0; + virtual bool load( const String& filename ) = 0; + virtual void detectMultiScale( InputArray image, + CV_OUT std::vector<Rect>& objects, + double scaleFactor, + int minNeighbors, int flags, + Size minSize, Size maxSize ) = 0; + + virtual void detectMultiScale( InputArray image, + CV_OUT std::vector<Rect>& objects, + CV_OUT std::vector<int>& numDetections, + double scaleFactor, + int minNeighbors, int flags, + Size minSize, Size maxSize ) = 0; + + virtual void detectMultiScale( InputArray image, + CV_OUT std::vector<Rect>& objects, + CV_OUT std::vector<int>& rejectLevels, + CV_OUT std::vector<double>& levelWeights, + double scaleFactor, + int minNeighbors, int flags, + Size minSize, Size maxSize, + bool outputRejectLevels ) = 0; + + virtual bool isOldFormatCascade() const = 0; + virtual Size getOriginalWindowSize() const = 0; + virtual int getFeatureType() const = 0; + virtual void* getOldCascade() = 0; + + class CV_EXPORTS MaskGenerator + { + public: + virtual ~MaskGenerator() {} + virtual Mat generateMask(const Mat& src)=0; + virtual void initializeMask(const Mat& /*src*/) { } + }; + virtual void setMaskGenerator(const Ptr<MaskGenerator>& maskGenerator) = 0; + virtual Ptr<MaskGenerator> getMaskGenerator() = 0; +}; + +/** @example samples/cpp/facedetect.cpp +This program demonstrates usage of the Cascade classifier class +\image html Cascade_Classifier_Tutorial_Result_Haar.jpg "Sample screenshot" width=321 height=254 +*/ +/** @brief Cascade classifier class for object detection. + */ +class CV_EXPORTS_W CascadeClassifier +{ +public: + CV_WRAP CascadeClassifier(); + /** @brief Loads a classifier from a file. + + @param filename Name of the file from which the classifier is loaded. + */ + CV_WRAP CascadeClassifier(const String& filename); + ~CascadeClassifier(); + /** @brief Checks whether the classifier has been loaded. + */ + CV_WRAP bool empty() const; + /** @brief Loads a classifier from a file. + + @param filename Name of the file from which the classifier is loaded. The file may contain an old + HAAR classifier trained by the haartraining application or a new cascade classifier trained by the + traincascade application. + */ + CV_WRAP bool load( const String& filename ); + /** @brief Reads a classifier from a FileStorage node. + + @note The file may contain a new cascade classifier (trained traincascade application) only. + */ + CV_WRAP bool read( const FileNode& node ); + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + + @param image Matrix of the type CV_8U containing an image where objects are detected. + @param objects Vector of rectangles where each rectangle contains the detected object, the + rectangles may be partially outside the original image. + @param scaleFactor Parameter specifying how much the image size is reduced at each image scale. + @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have + to retain it. + @param flags Parameter with the same meaning for an old cascade as in the function + cvHaarDetectObjects. It is not used for a new cascade. + @param minSize Minimum possible object size. Objects smaller than that are ignored. + @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. + + The function is parallelized with the TBB library. + + @note + - (Python) A face detection example using cascade classifiers can be found at + opencv_source_code/samples/python/facedetect.py + */ + CV_WRAP void detectMultiScale( InputArray image, + CV_OUT std::vector<Rect>& objects, + double scaleFactor = 1.1, + int minNeighbors = 3, int flags = 0, + Size minSize = Size(), + Size maxSize = Size() ); + + /** @overload + @param image Matrix of the type CV_8U containing an image where objects are detected. + @param objects Vector of rectangles where each rectangle contains the detected object, the + rectangles may be partially outside the original image. + @param numDetections Vector of detection numbers for the corresponding objects. An object's number + of detections is the number of neighboring positively classified rectangles that were joined + together to form the object. + @param scaleFactor Parameter specifying how much the image size is reduced at each image scale. + @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have + to retain it. + @param flags Parameter with the same meaning for an old cascade as in the function + cvHaarDetectObjects. It is not used for a new cascade. + @param minSize Minimum possible object size. Objects smaller than that are ignored. + @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. + */ + CV_WRAP_AS(detectMultiScale2) void detectMultiScale( InputArray image, + CV_OUT std::vector<Rect>& objects, + CV_OUT std::vector<int>& numDetections, + double scaleFactor=1.1, + int minNeighbors=3, int flags=0, + Size minSize=Size(), + Size maxSize=Size() ); + + /** @overload + This function allows you to retrieve the final stage decision certainty of classification. + For this, one needs to set `outputRejectLevels` on true and provide the `rejectLevels` and `levelWeights` parameter. + For each resulting detection, `levelWeights` will then contain the certainty of classification at the final stage. + This value can then be used to separate strong from weaker classifications. + + A code sample on how to use it efficiently can be found below: + @code + Mat img; + vector<double> weights; + vector<int> levels; + vector<Rect> detections; + CascadeClassifier model("/path/to/your/model.xml"); + model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); + cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; + @endcode + */ + CV_WRAP_AS(detectMultiScale3) void detectMultiScale( InputArray image, + CV_OUT std::vector<Rect>& objects, + CV_OUT std::vector<int>& rejectLevels, + CV_OUT std::vector<double>& levelWeights, + double scaleFactor = 1.1, + int minNeighbors = 3, int flags = 0, + Size minSize = Size(), + Size maxSize = Size(), + bool outputRejectLevels = false ); + + CV_WRAP bool isOldFormatCascade() const; + CV_WRAP Size getOriginalWindowSize() const; + CV_WRAP int getFeatureType() const; + void* getOldCascade(); + + CV_WRAP static bool convert(const String& oldcascade, const String& newcascade); + + void setMaskGenerator(const Ptr<BaseCascadeClassifier::MaskGenerator>& maskGenerator); + Ptr<BaseCascadeClassifier::MaskGenerator> getMaskGenerator(); + + Ptr<BaseCascadeClassifier> cc; +}; + +CV_EXPORTS Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator(); + +//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// + +//! struct for detection region of interest (ROI) +struct DetectionROI +{ + //! scale(size) of the bounding box + double scale; + //! set of requested locations to be evaluated + std::vector<cv::Point> locations; + //! vector that will contain confidence values for each location + std::vector<double> confidences; +}; + +/**@brief Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector. + +the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs @cite Dalal2005 . + +useful links: + +https://hal.inria.fr/inria-00548512/document/ + +https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients + +https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor + +http://www.learnopencv.com/histogram-of-oriented-gradients + +http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial + + */ +struct CV_EXPORTS_W HOGDescriptor +{ +public: + enum { L2Hys = 0 //!< Default histogramNormType + }; + enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value. + }; + /**@brief Creates the HOG descriptor and detector with default params. + + aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9, 1 ) + */ + CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), + cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), + histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true), + free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false) + {} + + /** @overload + @param _winSize sets winSize with given value. + @param _blockSize sets blockSize with given value. + @param _blockStride sets blockStride with given value. + @param _cellSize sets cellSize with given value. + @param _nbins sets nbins with given value. + @param _derivAperture sets derivAperture with given value. + @param _winSigma sets winSigma with given value. + @param _histogramNormType sets histogramNormType with given value. + @param _L2HysThreshold sets L2HysThreshold with given value. + @param _gammaCorrection sets gammaCorrection with given value. + @param _nlevels sets nlevels with given value. + @param _signedGradient sets signedGradient with given value. + */ + CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, + Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, + int _histogramNormType=HOGDescriptor::L2Hys, + double _L2HysThreshold=0.2, bool _gammaCorrection=false, + int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false) + : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize), + nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma), + histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold), + gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient) + {} + + /** @overload + @param filename the file name containing HOGDescriptor properties and coefficients of the trained classifier + */ + CV_WRAP HOGDescriptor(const String& filename) + { + load(filename); + } + + /** @overload + @param d the HOGDescriptor which cloned to create a new one. + */ + HOGDescriptor(const HOGDescriptor& d) + { + d.copyTo(*this); + } + + /**@brief Default destructor. + */ + virtual ~HOGDescriptor() {} + + /**@brief Returns the number of coefficients required for the classification. + */ + CV_WRAP size_t getDescriptorSize() const; + + /** @brief Checks if detector size equal to descriptor size. + */ + CV_WRAP bool checkDetectorSize() const; + + /** @brief Returns winSigma value + */ + CV_WRAP double getWinSigma() const; + + /**@example samples/cpp/peopledetect.cpp + */ + /**@brief Sets coefficients for the linear SVM classifier. + @param _svmdetector coefficients for the linear SVM classifier. + */ + CV_WRAP virtual void setSVMDetector(InputArray _svmdetector); + + /** @brief Reads HOGDescriptor parameters from a file node. + @param fn File node + */ + virtual bool read(FileNode& fn); + + /** @brief Stores HOGDescriptor parameters in a file storage. + @param fs File storage + @param objname Object name + */ + virtual void write(FileStorage& fs, const String& objname) const; + + /** @brief loads coefficients for the linear SVM classifier from a file + @param filename Name of the file to read. + @param objname The optional name of the node to read (if empty, the first top-level node will be used). + */ + CV_WRAP virtual bool load(const String& filename, const String& objname = String()); + + /** @brief saves coefficients for the linear SVM classifier to a file + @param filename File name + @param objname Object name + */ + CV_WRAP virtual void save(const String& filename, const String& objname = String()) const; + + /** @brief clones the HOGDescriptor + @param c cloned HOGDescriptor + */ + virtual void copyTo(HOGDescriptor& c) const; + + /**@example samples/cpp/train_HOG.cpp + */ + /** @brief Computes HOG descriptors of given image. + @param img Matrix of the type CV_8U containing an image where HOG features will be calculated. + @param descriptors Matrix of the type CV_32F + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param locations Vector of Point + */ + CV_WRAP virtual void compute(InputArray img, + CV_OUT std::vector<float>& descriptors, + Size winStride = Size(), Size padding = Size(), + const std::vector<Point>& locations = std::vector<Point>()) const; + + /** @brief Performs object detection without a multi-scale window. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. + @param weights Vector that will contain confidence values for each detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param searchLocations Vector of Point includes set of requested locations to be evaluated. + */ + CV_WRAP virtual void detect(const Mat& img, CV_OUT std::vector<Point>& foundLocations, + CV_OUT std::vector<double>& weights, + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), + const std::vector<Point>& searchLocations = std::vector<Point>()) const; + + /** @brief Performs object detection without a multi-scale window. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param searchLocations Vector of Point includes locations to search. + */ + virtual void detect(const Mat& img, CV_OUT std::vector<Point>& foundLocations, + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), + const std::vector<Point>& searchLocations=std::vector<Point>()) const; + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param foundWeights Vector that will contain confidence values for each detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param scale Coefficient of the detection window increase. + @param finalThreshold Final threshold + @param useMeanshiftGrouping indicates grouping algorithm + */ + CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations, + CV_OUT std::vector<double>& foundWeights, double hitThreshold = 0, + Size winStride = Size(), Size padding = Size(), double scale = 1.05, + double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const; + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param scale Coefficient of the detection window increase. + @param finalThreshold Final threshold + @param useMeanshiftGrouping indicates grouping algorithm + */ + virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations, + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), double scale = 1.05, + double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const; + + /** @brief Computes gradients and quantized gradient orientations. + @param img Matrix contains the image to be computed + @param grad Matrix of type CV_32FC2 contains computed gradients + @param angleOfs Matrix of type CV_8UC2 contains quantized gradient orientations + @param paddingTL Padding from top-left + @param paddingBR Padding from bottom-right + */ + CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs, + Size paddingTL = Size(), Size paddingBR = Size()) const; + + /** @brief Returns coefficients of the classifier trained for people detection (for 64x128 windows). + */ + CV_WRAP static std::vector<float> getDefaultPeopleDetector(); + + /**@example samples/tapi/hog.cpp + */ + /** @brief Returns coefficients of the classifier trained for people detection (for 48x96 windows). + */ + CV_WRAP static std::vector<float> getDaimlerPeopleDetector(); + + //! Detection window size. Align to block size and block stride. Default value is Size(64,128). + CV_PROP Size winSize; + + //! Block size in pixels. Align to cell size. Default value is Size(16,16). + CV_PROP Size blockSize; + + //! Block stride. It must be a multiple of cell size. Default value is Size(8,8). + CV_PROP Size blockStride; + + //! Cell size. Default value is Size(8,8). + CV_PROP Size cellSize; + + //! Number of bins used in the calculation of histogram of gradients. Default value is 9. + CV_PROP int nbins; + + //! not documented + CV_PROP int derivAperture; + + //! Gaussian smoothing window parameter. + CV_PROP double winSigma; + + //! histogramNormType + CV_PROP int histogramNormType; + + //! L2-Hys normalization method shrinkage. + CV_PROP double L2HysThreshold; + + //! Flag to specify whether the gamma correction preprocessing is required or not. + CV_PROP bool gammaCorrection; + + //! coefficients for the linear SVM classifier. + CV_PROP std::vector<float> svmDetector; + + //! coefficients for the linear SVM classifier used when OpenCL is enabled + UMat oclSvmDetector; + + //! not documented + float free_coef; + + //! Maximum number of detection window increases. Default value is 64 + CV_PROP int nlevels; + + //! Indicates signed gradient will be used or not + CV_PROP bool signedGradient; + + /** @brief evaluate specified ROI and return confidence value for each location + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param locations Vector of Point + @param foundLocations Vector of Point where each Point is detected object's top-left point. + @param confidences confidences + @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually + it is 0 and should be specified in the detector coefficients (as the last free coefficient). But if + the free coefficient is omitted (which is allowed), you can specify it manually here + @param winStride winStride + @param padding padding + */ + virtual void detectROI(const cv::Mat& img, const std::vector<cv::Point> &locations, + CV_OUT std::vector<cv::Point>& foundLocations, CV_OUT std::vector<double>& confidences, + double hitThreshold = 0, cv::Size winStride = Size(), + cv::Size padding = Size()) const; + + /** @brief evaluate specified ROI and return confidence value for each location in multiple scales + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param locations Vector of DetectionROI + @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified + in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. + */ + virtual void detectMultiScaleROI(const cv::Mat& img, + CV_OUT std::vector<cv::Rect>& foundLocations, + std::vector<DetectionROI>& locations, + double hitThreshold = 0, + int groupThreshold = 0) const; + + /** @brief read/parse Dalal's alt model file + @param modelfile Path of Dalal's alt model file. + */ + void readALTModel(String modelfile); + + /** @brief Groups the object candidate rectangles. + @param rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.) + @param weights Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.) + @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. + @param eps Relative difference between sides of the rectangles to merge them into a group. + */ + void groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const; +}; + +class CV_EXPORTS_W QRCodeDetector +{ +public: + CV_WRAP QRCodeDetector(); + ~QRCodeDetector(); + + /** @brief sets the epsilon used during the horizontal scan of QR code stop marker detection. + @param epsX Epsilon neighborhood, which allows you to determine the horizontal pattern + of the scheme 1:1:3:1:1 according to QR code standard. + */ + CV_WRAP void setEpsX(double epsX); + /** @brief sets the epsilon used during the vertical scan of QR code stop marker detection. + @param epsY Epsilon neighborhood, which allows you to determine the vertical pattern + of the scheme 1:1:3:1:1 according to QR code standard. + */ + CV_WRAP void setEpsY(double epsY); + + /** @brief Detects QR code in image and returns the quadrangle containing the code. + @param img grayscale or color (BGR) image containing (or not) QR code. + @param points Output vector of vertices of the minimum-area quadrangle containing the code. + */ + CV_WRAP bool detect(InputArray img, OutputArray points) const; + + /** @brief Decodes QR code in image once it's found by the detect() method. + Returns UTF8-encoded output string or empty string if the code cannot be decoded. + + @param img grayscale or color (BGR) image containing QR code. + @param points Quadrangle vertices found by detect() method (or some other algorithm). + @param straight_qrcode The optional output image containing rectified and binarized QR code + */ + CV_WRAP cv::String decode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray()); + + /** @brief Both detects and decodes QR code + + @param img grayscale or color (BGR) image containing QR code. + @param points opiotnal output array of vertices of the found QR code quadrangle. Will be empty if not found. + @param straight_qrcode The optional output image containing rectified and binarized QR code + */ + CV_WRAP cv::String detectAndDecode(InputArray img, OutputArray points=noArray(), + OutputArray straight_qrcode = noArray()); +protected: + struct Impl; + Ptr<Impl> p; +}; + +/** @brief Detect QR code in image and return minimum area of quadrangle that describes QR code. + @param in Matrix of the type CV_8UC1 containing an image where QR code are detected. + @param points Output vector of vertices of a quadrangle of minimal area that describes QR code. + @param eps_x Epsilon neighborhood, which allows you to determine the horizontal pattern of the scheme 1:1:3:1:1 according to QR code standard. + @param eps_y Epsilon neighborhood, which allows you to determine the vertical pattern of the scheme 1:1:3:1:1 according to QR code standard. + */ +CV_EXPORTS bool detectQRCode(InputArray in, std::vector<Point> &points, double eps_x = 0.2, double eps_y = 0.1); + +/** @brief Decode QR code in image and return text that is encrypted in QR code. + @param in Matrix of the type CV_8UC1 containing an image where QR code are detected. + @param points Input vector of vertices of a quadrangle of minimal area that describes QR code. + @param decoded_info String information that is encrypted in QR code. + @param straight_qrcode Matrix of the type CV_8UC1 containing an binary straight QR code. + */ +CV_EXPORTS bool decodeQRCode(InputArray in, InputArray points, std::string &decoded_info, OutputArray straight_qrcode = noArray()); + +//! @} objdetect +} + +#include "opencv2/objdetect/detection_based_tracker.hpp" + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/objdetect/objdetect_c.h" +#endif + +#endif diff --git a/include/opencv2/objdetect/detection_based_tracker.hpp b/include/opencv2/objdetect/detection_based_tracker.hpp new file mode 100644 index 0000000..07dd587 --- /dev/null +++ b/include/opencv2/objdetect/detection_based_tracker.hpp @@ -0,0 +1,227 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OBJDETECT_DBT_HPP +#define OPENCV_OBJDETECT_DBT_HPP + +#include <opencv2/core.hpp> + +// After this condition removal update blacklist for bindings: modules/python/common.cmake +#if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(__ANDROID__) || \ + defined(CV_CXX11) + +#include <vector> + +namespace cv +{ + +//! @addtogroup objdetect +//! @{ + +class CV_EXPORTS DetectionBasedTracker +{ + public: + struct CV_EXPORTS Parameters + { + int maxTrackLifetime; + int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0 + + Parameters(); + }; + + class IDetector + { + public: + IDetector(): + minObjSize(96, 96), + maxObjSize(INT_MAX, INT_MAX), + minNeighbours(2), + scaleFactor(1.1f) + {} + + virtual void detect(const cv::Mat& image, std::vector<cv::Rect>& objects) = 0; + + void setMinObjectSize(const cv::Size& min) + { + minObjSize = min; + } + void setMaxObjectSize(const cv::Size& max) + { + maxObjSize = max; + } + cv::Size getMinObjectSize() const + { + return minObjSize; + } + cv::Size getMaxObjectSize() const + { + return maxObjSize; + } + float getScaleFactor() + { + return scaleFactor; + } + void setScaleFactor(float value) + { + scaleFactor = value; + } + int getMinNeighbours() + { + return minNeighbours; + } + void setMinNeighbours(int value) + { + minNeighbours = value; + } + virtual ~IDetector() {} + + protected: + cv::Size minObjSize; + cv::Size maxObjSize; + int minNeighbours; + float scaleFactor; + }; + + DetectionBasedTracker(cv::Ptr<IDetector> mainDetector, cv::Ptr<IDetector> trackingDetector, const Parameters& params); + virtual ~DetectionBasedTracker(); + + virtual bool run(); + virtual void stop(); + virtual void resetTracking(); + + virtual void process(const cv::Mat& imageGray); + + bool setParameters(const Parameters& params); + const Parameters& getParameters() const; + + + typedef std::pair<cv::Rect, int> Object; + virtual void getObjects(std::vector<cv::Rect>& result) const; + virtual void getObjects(std::vector<Object>& result) const; + + enum ObjectStatus + { + DETECTED_NOT_SHOWN_YET, + DETECTED, + DETECTED_TEMPORARY_LOST, + WRONG_OBJECT + }; + struct ExtObject + { + int id; + cv::Rect location; + ObjectStatus status; + ExtObject(int _id, cv::Rect _location, ObjectStatus _status) + :id(_id), location(_location), status(_status) + { + } + }; + virtual void getObjects(std::vector<ExtObject>& result) const; + + + virtual int addObject(const cv::Rect& location); //returns id of the new object + + protected: + class SeparateDetectionWork; + cv::Ptr<SeparateDetectionWork> separateDetectionWork; + friend void* workcycleObjectDetectorFunction(void* p); + + struct InnerParameters + { + int numLastPositionsToTrack; + int numStepsToWaitBeforeFirstShow; + int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown; + int numStepsToShowWithoutDetecting; + + float coeffTrackingWindowSize; + float coeffObjectSizeToTrack; + float coeffObjectSpeedUsingInPrediction; + + InnerParameters(); + }; + Parameters parameters; + InnerParameters innerParameters; + + struct TrackedObject + { + typedef std::vector<cv::Rect> PositionsVector; + + PositionsVector lastPositions; + + int numDetectedFrames; + int numFramesNotDetected; + int id; + + TrackedObject(const cv::Rect& rect):numDetectedFrames(1), numFramesNotDetected(0) + { + lastPositions.push_back(rect); + id=getNextId(); + }; + + static int getNextId() + { + static int _id=0; + return _id++; + } + }; + + int numTrackedSteps; + std::vector<TrackedObject> trackedObjects; + + std::vector<float> weightsPositionsSmoothing; + std::vector<float> weightsSizesSmoothing; + + cv::Ptr<IDetector> cascadeForTracking; + + void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects); + cv::Rect calcTrackedObjectPositionToShow(int i) const; + cv::Rect calcTrackedObjectPositionToShow(int i, ObjectStatus& status) const; + void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions); +}; + +//! @} objdetect + +} //end of cv namespace +#endif + +#endif diff --git a/include/opencv2/objdetect/objdetect.hpp b/include/opencv2/objdetect/objdetect.hpp new file mode 100644 index 0000000..3ee284f --- /dev/null +++ b/include/opencv2/objdetect/objdetect.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/objdetect.hpp" diff --git a/include/opencv2/objdetect/objdetect_c.h b/include/opencv2/objdetect/objdetect_c.h new file mode 100644 index 0000000..67dc2f4 --- /dev/null +++ b/include/opencv2/objdetect/objdetect_c.h @@ -0,0 +1,166 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OBJDETECT_C_H +#define OPENCV_OBJDETECT_C_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +#include <deque> +#include <vector> + +extern "C" { +#endif + +/** @addtogroup objdetect_c + @{ + */ + +/****************************************************************************************\ +* Haar-like Object Detection functions * +\****************************************************************************************/ + +#define CV_HAAR_MAGIC_VAL 0x42500000 +#define CV_TYPE_NAME_HAAR "opencv-haar-classifier" + +#define CV_IS_HAAR_CLASSIFIER( haar ) \ + ((haar) != NULL && \ + (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL) + +#define CV_HAAR_FEATURE_MAX 3 +#define CV_HAAR_STAGE_MAX 1000 + +typedef struct CvHaarFeature +{ + int tilted; + struct + { + CvRect r; + float weight; + } rect[CV_HAAR_FEATURE_MAX]; +} CvHaarFeature; + +typedef struct CvHaarClassifier +{ + int count; + CvHaarFeature* haar_feature; + float* threshold; + int* left; + int* right; + float* alpha; +} CvHaarClassifier; + +typedef struct CvHaarStageClassifier +{ + int count; + float threshold; + CvHaarClassifier* classifier; + + int next; + int child; + int parent; +} CvHaarStageClassifier; + +typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade; + +typedef struct CvHaarClassifierCascade +{ + int flags; + int count; + CvSize orig_window_size; + CvSize real_window_size; + double scale; + CvHaarStageClassifier* stage_classifier; + CvHidHaarClassifierCascade* hid_cascade; +} CvHaarClassifierCascade; + +typedef struct CvAvgComp +{ + CvRect rect; + int neighbors; +} CvAvgComp; + +/* Loads haar classifier cascade from a directory. + It is obsolete: convert your cascade to xml and use cvLoad instead */ +CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade( + const char* directory, CvSize orig_window_size); + +CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade ); + +#define CV_HAAR_DO_CANNY_PRUNING 1 +#define CV_HAAR_SCALE_IMAGE 2 +#define CV_HAAR_FIND_BIGGEST_OBJECT 4 +#define CV_HAAR_DO_ROUGH_SEARCH 8 + +CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image, + CvHaarClassifierCascade* cascade, CvMemStorage* storage, + double scale_factor CV_DEFAULT(1.1), + int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), + CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0))); + +/* sets images for haar classifier cascade */ +CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade, + const CvArr* sum, const CvArr* sqsum, + const CvArr* tilted_sum, double scale ); + +/* runs the cascade on the specified window */ +CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade, + CvPoint pt, int start_stage CV_DEFAULT(0)); + +/** @} objdetect_c */ + +#ifdef __cplusplus +} + +CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image, + CvHaarClassifierCascade* cascade, CvMemStorage* storage, + std::vector<int>& rejectLevels, std::vector<double>& levelWeightds, + double scale_factor = 1.1, + int min_neighbors = 3, int flags = 0, + CvSize min_size = cvSize(0, 0), CvSize max_size = cvSize(0, 0), + bool outputRejectLevels = false ); + +#endif + +#endif /* OPENCV_OBJDETECT_C_H */ diff --git a/include/opencv2/opencv.hpp b/include/opencv2/opencv.hpp new file mode 100644 index 0000000..4048158 --- /dev/null +++ b/include/opencv2/opencv.hpp @@ -0,0 +1,139 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_ALL_HPP +#define OPENCV_ALL_HPP + +// File that defines what modules where included during the build of OpenCV +// These are purely the defines of the correct HAVE_OPENCV_modulename values +#include "opencv2/opencv_modules.hpp" + +// Then the list of defines is checked to include the correct headers +// Core library is always included --> without no OpenCV functionality available +#include "opencv2/core.hpp" + +// Then the optional modules are checked +#ifdef HAVE_OPENCV_CALIB3D +#include "opencv2/calib3d.hpp" +#endif +#ifdef HAVE_OPENCV_FEATURES2D +#include "opencv2/features2d.hpp" +#endif +#ifdef HAVE_OPENCV_DNN +#include "opencv2/dnn.hpp" +#endif +#ifdef HAVE_OPENCV_FLANN +#include "opencv2/flann.hpp" +#endif +#ifdef HAVE_OPENCV_HIGHGUI +#include "opencv2/highgui.hpp" +#endif +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_IMGPROC +#include "opencv2/imgproc.hpp" +#endif +#ifdef HAVE_OPENCV_ML +#include "opencv2/ml.hpp" +#endif +#ifdef HAVE_OPENCV_OBJDETECT +#include "opencv2/objdetect.hpp" +#endif +#ifdef HAVE_OPENCV_PHOTO +#include "opencv2/photo.hpp" +#endif +#ifdef HAVE_OPENCV_SHAPE +#include "opencv2/shape.hpp" +#endif +#ifdef HAVE_OPENCV_STITCHING +#include "opencv2/stitching.hpp" +#endif +#ifdef HAVE_OPENCV_SUPERRES +#include "opencv2/superres.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEO +#include "opencv2/video.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOSTAB +#include "opencv2/videostab.hpp" +#endif +#ifdef HAVE_OPENCV_VIZ +#include "opencv2/viz.hpp" +#endif + +// Finally CUDA specific entries are checked and added +#ifdef HAVE_OPENCV_CUDAARITHM +#include "opencv2/cudaarithm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDABGSEGM +#include "opencv2/cudabgsegm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDACODEC +#include "opencv2/cudacodec.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFEATURES2D +#include "opencv2/cudafeatures2d.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFILTERS +#include "opencv2/cudafilters.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAIMGPROC +#include "opencv2/cudaimgproc.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOBJDETECT +#include "opencv2/cudaobjdetect.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOPTFLOW +#include "opencv2/cudaoptflow.hpp" +#endif +#ifdef HAVE_OPENCV_CUDASTEREO +#include "opencv2/cudastereo.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAWARPING +#include "opencv2/cudawarping.hpp" +#endif + +#endif diff --git a/include/opencv2/opencv_modules.hpp b/include/opencv2/opencv_modules.hpp new file mode 100644 index 0000000..7182f9b --- /dev/null +++ b/include/opencv2/opencv_modules.hpp @@ -0,0 +1,57 @@ +/* + * ** File generated automatically, do not modify ** + * + * This file defines the list of modules available in current build configuration + * + * +*/ + +// This definition means that OpenCV is built with enabled non-free code. +// For example, patented algorithms for non-profit/non-commercial use only. +/* #undef OPENCV_ENABLE_NONFREE */ + +#define HAVE_OPENCV_ARUCO +#define HAVE_OPENCV_BGSEGM +#define HAVE_OPENCV_BIOINSPIRED +#define HAVE_OPENCV_CALIB3D +#define HAVE_OPENCV_CCALIB +#define HAVE_OPENCV_CORE +#define HAVE_OPENCV_DATASETS +#define HAVE_OPENCV_DNN +#define HAVE_OPENCV_DNN_OBJDETECT +#define HAVE_OPENCV_DPM +#define HAVE_OPENCV_FACE +#define HAVE_OPENCV_FEATURES2D +#define HAVE_OPENCV_FLANN +#define HAVE_OPENCV_FUZZY +#define HAVE_OPENCV_HFS +#define HAVE_OPENCV_HIGHGUI +#define HAVE_OPENCV_IMG_HASH +#define HAVE_OPENCV_IMGCODECS +#define HAVE_OPENCV_IMGPROC +#define HAVE_OPENCV_LINE_DESCRIPTOR +#define HAVE_OPENCV_ML +#define HAVE_OPENCV_OBJDETECT +#define HAVE_OPENCV_OPTFLOW +#define HAVE_OPENCV_PHASE_UNWRAPPING +#define HAVE_OPENCV_PHOTO +#define HAVE_OPENCV_PLOT +#define HAVE_OPENCV_REG +#define HAVE_OPENCV_RGBD +#define HAVE_OPENCV_SALIENCY +#define HAVE_OPENCV_SHAPE +#define HAVE_OPENCV_STEREO +#define HAVE_OPENCV_STITCHING +#define HAVE_OPENCV_STRUCTURED_LIGHT +#define HAVE_OPENCV_SUPERRES +#define HAVE_OPENCV_SURFACE_MATCHING +#define HAVE_OPENCV_TEXT +#define HAVE_OPENCV_TRACKING +#define HAVE_OPENCV_VIDEO +#define HAVE_OPENCV_VIDEOIO +#define HAVE_OPENCV_VIDEOSTAB +#define HAVE_OPENCV_XIMGPROC +#define HAVE_OPENCV_XOBJDETECT +#define HAVE_OPENCV_XPHOTO + + diff --git a/include/opencv2/optflow.hpp b/include/opencv2/optflow.hpp new file mode 100644 index 0000000..e68d5b7 --- /dev/null +++ b/include/opencv2/optflow.hpp @@ -0,0 +1,364 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_OPTFLOW_HPP__ +#define __OPENCV_OPTFLOW_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/video.hpp" + +/** +@defgroup optflow Optical Flow Algorithms + +Dense optical flow algorithms compute motion for each point: + +- cv::optflow::calcOpticalFlowSF +- cv::optflow::createOptFlow_DeepFlow + +Motion templates is alternative technique for detecting motion and computing its direction. +See samples/motempl.py. + +- cv::motempl::updateMotionHistory +- cv::motempl::calcMotionGradient +- cv::motempl::calcGlobalOrientation +- cv::motempl::segmentMotion + +Functions reading and writing .flo files in "Middlebury" format, see: <http://vision.middlebury.edu/flow/code/flow-code/README.txt> + +- cv::optflow::readOpticalFlow +- cv::optflow::writeOpticalFlow + + */ + +#include "opencv2/optflow/pcaflow.hpp" +#include "opencv2/optflow/sparse_matching_gpc.hpp" + +namespace cv +{ +namespace optflow +{ + +//! @addtogroup optflow +//! @{ + +/** @overload */ +CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, + int layers, int averaging_block_size, int max_flow); + +/** @brief Calculate an optical flow using "SimpleFlow" algorithm. + +@param from First 8-bit 3-channel image. +@param to Second 8-bit 3-channel image of the same size as prev +@param flow computed flow image that has the same size as prev and type CV_32FC2 +@param layers Number of layers +@param averaging_block_size Size of block through which we sum up when calculate cost function +for pixel +@param max_flow maximal flow that we search at each level +@param sigma_dist vector smooth spatial sigma parameter +@param sigma_color vector smooth color sigma parameter +@param postprocess_window window size for postprocess cross bilateral filter +@param sigma_dist_fix spatial sigma for postprocess cross bilateralf filter +@param sigma_color_fix color sigma for postprocess cross bilateral filter +@param occ_thr threshold for detecting occlusions +@param upscale_averaging_radius window size for bilateral upscale operation +@param upscale_sigma_dist spatial sigma for bilateral upscale operation +@param upscale_sigma_color color sigma for bilateral upscale operation +@param speed_up_thr threshold to detect point with irregular flow - where flow should be +recalculated after upscale + +See @cite Tao2012 . And site of project - <http://graphics.berkeley.edu/papers/Tao-SAN-2012-05/>. + +@note + - An example using the simpleFlow algorithm can be found at samples/simpleflow_demo.cpp + */ +CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, int layers, + int averaging_block_size, int max_flow, + double sigma_dist, double sigma_color, int postprocess_window, + double sigma_dist_fix, double sigma_color_fix, double occ_thr, + int upscale_averaging_radius, double upscale_sigma_dist, + double upscale_sigma_color, double speed_up_thr ); + +/** @brief Fast dense optical flow based on PyrLK sparse matches interpolation. + +@param from first 8-bit 3-channel or 1-channel image. +@param to second 8-bit 3-channel or 1-channel image of the same size as from +@param flow computed flow image that has the same size as from and CV_32FC2 type +@param grid_step stride used in sparse match computation. Lower values usually + result in higher quality but slow down the algorithm. +@param k number of nearest-neighbor matches considered, when fitting a locally affine + model. Lower values can make the algorithm noticeably faster at the cost of + some quality degradation. +@param sigma parameter defining how fast the weights decrease in the locally-weighted affine + fitting. Higher values can help preserve fine details, lower values can help to get rid + of the noise in the output flow. +@param use_post_proc defines whether the ximgproc::fastGlobalSmootherFilter() is used + for post-processing after interpolation +@param fgs_lambda see the respective parameter of the ximgproc::fastGlobalSmootherFilter() +@param fgs_sigma see the respective parameter of the ximgproc::fastGlobalSmootherFilter() + */ +CV_EXPORTS_W void calcOpticalFlowSparseToDense ( InputArray from, InputArray to, OutputArray flow, + int grid_step = 8, int k = 128, float sigma = 0.05f, + bool use_post_proc = true, float fgs_lambda = 500.0f, + float fgs_sigma = 1.5f ); + +/** @brief Read a .flo file + +@param path Path to the file to be loaded + +The function readOpticalFlow loads a flow field from a file and returns it as a single matrix. +Resulting Mat has a type CV_32FC2 - floating-point, 2-channel. First channel corresponds to the +flow in the horizontal direction (u), second - vertical (v). + */ +CV_EXPORTS_W Mat readOpticalFlow( const String& path ); +/** @brief Write a .flo to disk + +@param path Path to the file to be written +@param flow Flow field to be stored + +The function stores a flow field in a file, returns true on success, false otherwise. +The flow field must be a 2-channel, floating-point matrix (CV_32FC2). First channel corresponds +to the flow in the horizontal direction (u), second - vertical (v). + */ +CV_EXPORTS_W bool writeOpticalFlow( const String& path, InputArray flow ); + +/** @brief Variational optical flow refinement + +This class implements variational refinement of the input flow field, i.e. +it uses input flow to initialize the minimization of the following functional: +\f$E(U) = \int_{\Omega} \delta \Psi(E_I) + \gamma \Psi(E_G) + \alpha \Psi(E_S) \f$, +where \f$E_I,E_G,E_S\f$ are color constancy, gradient constancy and smoothness terms +respectively. \f$\Psi(s^2)=\sqrt{s^2+\epsilon^2}\f$ is a robust penalizer to limit the +influence of outliers. A complete formulation and a description of the minimization +procedure can be found in @cite Brox2004 +*/ +class CV_EXPORTS_W VariationalRefinement : public DenseOpticalFlow +{ +public: + /** @brief @ref calc function overload to handle separate horizontal (u) and vertical (v) flow components + (to avoid extra splits/merges) */ + CV_WRAP virtual void calcUV(InputArray I0, InputArray I1, InputOutputArray flow_u, InputOutputArray flow_v) = 0; + + /** @brief Number of outer (fixed-point) iterations in the minimization procedure. + @see setFixedPointIterations */ + CV_WRAP virtual int getFixedPointIterations() const = 0; + /** @copybrief getFixedPointIterations @see getFixedPointIterations */ + CV_WRAP virtual void setFixedPointIterations(int val) = 0; + + /** @brief Number of inner successive over-relaxation (SOR) iterations + in the minimization procedure to solve the respective linear system. + @see setSorIterations */ + CV_WRAP virtual int getSorIterations() const = 0; + /** @copybrief getSorIterations @see getSorIterations */ + CV_WRAP virtual void setSorIterations(int val) = 0; + + /** @brief Relaxation factor in SOR + @see setOmega */ + CV_WRAP virtual float getOmega() const = 0; + /** @copybrief getOmega @see getOmega */ + CV_WRAP virtual void setOmega(float val) = 0; + + /** @brief Weight of the smoothness term + @see setAlpha */ + CV_WRAP virtual float getAlpha() const = 0; + /** @copybrief getAlpha @see getAlpha */ + CV_WRAP virtual void setAlpha(float val) = 0; + + /** @brief Weight of the color constancy term + @see setDelta */ + CV_WRAP virtual float getDelta() const = 0; + /** @copybrief getDelta @see getDelta */ + CV_WRAP virtual void setDelta(float val) = 0; + + /** @brief Weight of the gradient constancy term + @see setGamma */ + CV_WRAP virtual float getGamma() const = 0; + /** @copybrief getGamma @see getGamma */ + CV_WRAP virtual void setGamma(float val) = 0; +}; + +/** @brief Creates an instance of VariationalRefinement +*/ +CV_EXPORTS_W Ptr<VariationalRefinement> createVariationalFlowRefinement(); + +/** @brief DeepFlow optical flow algorithm implementation. + +The class implements the DeepFlow optical flow algorithm described in @cite Weinzaepfel2013 . See +also <http://lear.inrialpes.fr/src/deepmatching/> . +Parameters - class fields - that may be modified after creating a class instance: +- member float alpha +Smoothness assumption weight +- member float delta +Color constancy assumption weight +- member float gamma +Gradient constancy weight +- member float sigma +Gaussian smoothing parameter +- member int minSize +Minimal dimension of an image in the pyramid (next, smaller images in the pyramid are generated +until one of the dimensions reaches this size) +- member float downscaleFactor +Scaling factor in the image pyramid (must be \< 1) +- member int fixedPointIterations +How many iterations on each level of the pyramid +- member int sorIterations +Iterations of Succesive Over-Relaxation (solver) +- member float omega +Relaxation factor in SOR + */ +CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_DeepFlow(); + +//! Additional interface to the SimpleFlow algorithm - calcOpticalFlowSF() +CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_SimpleFlow(); + +//! Additional interface to the Farneback's algorithm - calcOpticalFlowFarneback() +CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_Farneback(); + +//! Additional interface to the SparseToDenseFlow algorithm - calcOpticalFlowSparseToDense() +CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_SparseToDense(); + +/** @brief DIS optical flow algorithm. + +This class implements the Dense Inverse Search (DIS) optical flow algorithm. More +details about the algorithm can be found at @cite Kroeger2016 . Includes three presets with preselected +parameters to provide reasonable trade-off between speed and quality. However, even the slowest preset is +still relatively fast, use DeepFlow if you need better quality and don't care about speed. + +This implementation includes several additional features compared to the algorithm described in the paper, +including spatial propagation of flow vectors (@ref getUseSpatialPropagation), as well as an option to +utilize an initial flow approximation passed to @ref calc (which is, essentially, temporal propagation, +if the previous frame's flow field is passed). +*/ +class CV_EXPORTS_W DISOpticalFlow : public DenseOpticalFlow +{ +public: + enum + { + PRESET_ULTRAFAST = 0, + PRESET_FAST = 1, + PRESET_MEDIUM = 2 + }; + + /** @brief Finest level of the Gaussian pyramid on which the flow is computed (zero level + corresponds to the original image resolution). The final flow is obtained by bilinear upscaling. + @see setFinestScale */ + CV_WRAP virtual int getFinestScale() const = 0; + /** @copybrief getFinestScale @see getFinestScale */ + CV_WRAP virtual void setFinestScale(int val) = 0; + + /** @brief Size of an image patch for matching (in pixels). Normally, default 8x8 patches work well + enough in most cases. + @see setPatchSize */ + CV_WRAP virtual int getPatchSize() const = 0; + /** @copybrief getPatchSize @see getPatchSize */ + CV_WRAP virtual void setPatchSize(int val) = 0; + + /** @brief Stride between neighbor patches. Must be less than patch size. Lower values correspond + to higher flow quality. + @see setPatchStride */ + CV_WRAP virtual int getPatchStride() const = 0; + /** @copybrief getPatchStride @see getPatchStride */ + CV_WRAP virtual void setPatchStride(int val) = 0; + + /** @brief Maximum number of gradient descent iterations in the patch inverse search stage. Higher values + may improve quality in some cases. + @see setGradientDescentIterations */ + CV_WRAP virtual int getGradientDescentIterations() const = 0; + /** @copybrief getGradientDescentIterations @see getGradientDescentIterations */ + CV_WRAP virtual void setGradientDescentIterations(int val) = 0; + + /** @brief Number of fixed point iterations of variational refinement per scale. Set to zero to + disable variational refinement completely. Higher values will typically result in more smooth and + high-quality flow. + @see setGradientDescentIterations */ + CV_WRAP virtual int getVariationalRefinementIterations() const = 0; + /** @copybrief getGradientDescentIterations @see getGradientDescentIterations */ + CV_WRAP virtual void setVariationalRefinementIterations(int val) = 0; + + /** @brief Weight of the smoothness term + @see setVariationalRefinementAlpha */ + CV_WRAP virtual float getVariationalRefinementAlpha() const = 0; + /** @copybrief getVariationalRefinementAlpha @see getVariationalRefinementAlpha */ + CV_WRAP virtual void setVariationalRefinementAlpha(float val) = 0; + + /** @brief Weight of the color constancy term + @see setVariationalRefinementDelta */ + CV_WRAP virtual float getVariationalRefinementDelta() const = 0; + /** @copybrief getVariationalRefinementDelta @see getVariationalRefinementDelta */ + CV_WRAP virtual void setVariationalRefinementDelta(float val) = 0; + + /** @brief Weight of the gradient constancy term + @see setVariationalRefinementGamma */ + CV_WRAP virtual float getVariationalRefinementGamma() const = 0; + /** @copybrief getVariationalRefinementGamma @see getVariationalRefinementGamma */ + CV_WRAP virtual void setVariationalRefinementGamma(float val) = 0; + + + /** @brief Whether to use mean-normalization of patches when computing patch distance. It is turned on + by default as it typically provides a noticeable quality boost because of increased robustness to + illumination variations. Turn it off if you are certain that your sequence doesn't contain any changes + in illumination. + @see setUseMeanNormalization */ + CV_WRAP virtual bool getUseMeanNormalization() const = 0; + /** @copybrief getUseMeanNormalization @see getUseMeanNormalization */ + CV_WRAP virtual void setUseMeanNormalization(bool val) = 0; + + /** @brief Whether to use spatial propagation of good optical flow vectors. This option is turned on by + default, as it tends to work better on average and can sometimes help recover from major errors + introduced by the coarse-to-fine scheme employed by the DIS optical flow algorithm. Turning this + option off can make the output flow field a bit smoother, however. + @see setUseSpatialPropagation */ + CV_WRAP virtual bool getUseSpatialPropagation() const = 0; + /** @copybrief getUseSpatialPropagation @see getUseSpatialPropagation */ + CV_WRAP virtual void setUseSpatialPropagation(bool val) = 0; +}; + +/** @brief Creates an instance of DISOpticalFlow + +@param preset one of PRESET_ULTRAFAST, PRESET_FAST and PRESET_MEDIUM +*/ +CV_EXPORTS_W Ptr<DISOpticalFlow> createOptFlow_DIS(int preset = DISOpticalFlow::PRESET_FAST); + +//! @} + +} //optflow +} + +#include "opencv2/optflow/motempl.hpp" + +#endif diff --git a/include/opencv2/optflow/motempl.hpp b/include/opencv2/optflow/motempl.hpp new file mode 100644 index 0000000..aeea9e8 --- /dev/null +++ b/include/opencv2/optflow/motempl.hpp @@ -0,0 +1,147 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_OPTFLOW_MOTEMPL_HPP__ +#define __OPENCV_OPTFLOW_MOTEMPL_HPP__ + +#include "opencv2/core.hpp" + +namespace cv +{ +namespace motempl +{ + +//! @addtogroup optflow +//! @{ + +/** @brief Updates the motion history image by a moving silhouette. + +@param silhouette Silhouette mask that has non-zero pixels where the motion occurs. +@param mhi Motion history image that is updated by the function (single-channel, 32-bit +floating-point). +@param timestamp Current time in milliseconds or other units. +@param duration Maximal duration of the motion track in the same units as timestamp . + +The function updates the motion history image as follows: + +\f[\texttt{mhi} (x,y)= \forkthree{\texttt{timestamp}}{if \(\texttt{silhouette}(x,y) \ne 0\)}{0}{if \(\texttt{silhouette}(x,y) = 0\) and \(\texttt{mhi} < (\texttt{timestamp} - \texttt{duration})\)}{\texttt{mhi}(x,y)}{otherwise}\f] + +That is, MHI pixels where the motion occurs are set to the current timestamp , while the pixels +where the motion happened last time a long time ago are cleared. + +The function, together with calcMotionGradient and calcGlobalOrientation , implements a motion +templates technique described in @cite Davis97 and @cite Bradski00 . + */ +CV_EXPORTS_W void updateMotionHistory( InputArray silhouette, InputOutputArray mhi, + double timestamp, double duration ); + +/** @brief Calculates a gradient orientation of a motion history image. + +@param mhi Motion history single-channel floating-point image. +@param mask Output mask image that has the type CV_8UC1 and the same size as mhi . Its non-zero +elements mark pixels where the motion gradient data is correct. +@param orientation Output motion gradient orientation image that has the same type and the same +size as mhi . Each pixel of the image is a motion orientation, from 0 to 360 degrees. +@param delta1 Minimal (or maximal) allowed difference between mhi values within a pixel +neighborhood. +@param delta2 Maximal (or minimal) allowed difference between mhi values within a pixel +neighborhood. That is, the function finds the minimum ( \f$m(x,y)\f$ ) and maximum ( \f$M(x,y)\f$ ) mhi +values over \f$3 \times 3\f$ neighborhood of each pixel and marks the motion orientation at \f$(x, y)\f$ +as valid only if +\f[\min ( \texttt{delta1} , \texttt{delta2} ) \le M(x,y)-m(x,y) \le \max ( \texttt{delta1} , \texttt{delta2} ).\f] +@param apertureSize Aperture size of the Sobel operator. + +The function calculates a gradient orientation at each pixel \f$(x, y)\f$ as: + +\f[\texttt{orientation} (x,y)= \arctan{\frac{d\texttt{mhi}/dy}{d\texttt{mhi}/dx}}\f] + +In fact, fastAtan2 and phase are used so that the computed angle is measured in degrees and covers +the full range 0..360. Also, the mask is filled to indicate pixels where the computed angle is +valid. + +@note + - (Python) An example on how to perform a motion template technique can be found at + opencv_source_code/samples/python2/motempl.py + */ +CV_EXPORTS_W void calcMotionGradient( InputArray mhi, OutputArray mask, OutputArray orientation, + double delta1, double delta2, int apertureSize = 3 ); + +/** @brief Calculates a global motion orientation in a selected region. + +@param orientation Motion gradient orientation image calculated by the function calcMotionGradient +@param mask Mask image. It may be a conjunction of a valid gradient mask, also calculated by +calcMotionGradient , and the mask of a region whose direction needs to be calculated. +@param mhi Motion history image calculated by updateMotionHistory . +@param timestamp Timestamp passed to updateMotionHistory . +@param duration Maximum duration of a motion track in milliseconds, passed to updateMotionHistory + +The function calculates an average motion direction in the selected region and returns the angle +between 0 degrees and 360 degrees. The average direction is computed from the weighted orientation +histogram, where a recent motion has a larger weight and the motion occurred in the past has a +smaller weight, as recorded in mhi . + */ +CV_EXPORTS_W double calcGlobalOrientation( InputArray orientation, InputArray mask, InputArray mhi, + double timestamp, double duration ); + +/** @brief Splits a motion history image into a few parts corresponding to separate independent motions (for +example, left hand, right hand). + +@param mhi Motion history image. +@param segmask Image where the found mask should be stored, single-channel, 32-bit floating-point. +@param boundingRects Vector containing ROIs of motion connected components. +@param timestamp Current time in milliseconds or other units. +@param segThresh Segmentation threshold that is recommended to be equal to the interval between +motion history "steps" or greater. + +The function finds all of the motion segments and marks them in segmask with individual values +(1,2,...). It also computes a vector with ROIs of motion connected components. After that the motion +direction for every component can be calculated with calcGlobalOrientation using the extracted mask +of the particular component. + */ +CV_EXPORTS_W void segmentMotion( InputArray mhi, OutputArray segmask, + CV_OUT std::vector<Rect>& boundingRects, + double timestamp, double segThresh ); + + +//! @} + +} +} + +#endif diff --git a/include/opencv2/optflow/pcaflow.hpp b/include/opencv2/optflow/pcaflow.hpp new file mode 100644 index 0000000..78946f6 --- /dev/null +++ b/include/opencv2/optflow/pcaflow.hpp @@ -0,0 +1,149 @@ +/* +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) + +Copyright (C) 2016, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +/** + * @file pcaflow.hpp + * @author Vladislav Samsonov <vvladxx@gmail.com> + * @brief Implementation of the PCAFlow algorithm from the following paper: + * http://files.is.tue.mpg.de/black/papers/cvpr2015_pcaflow.pdf + * + * @cite Wulff:CVPR:2015 + * + * There are some key differences which distinguish this algorithm from the original PCAFlow (see paper): + * - Discrete Cosine Transform basis is used instead of basis extracted with PCA. + * Reasoning: DCT basis has comparable performance and it doesn't require additional storage space. + * Also, this decision helps to avoid overloading the algorithm with a lot of external input. + * - Usage of built-in OpenCV feature tracking instead of libviso. +*/ + +#ifndef __OPENCV_OPTFLOW_PCAFLOW_HPP__ +#define __OPENCV_OPTFLOW_PCAFLOW_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/video.hpp" + +namespace cv +{ +namespace optflow +{ + +//! @addtogroup optflow +//! @{ + +/** @brief + * This class can be used for imposing a learned prior on the resulting optical flow. + * Solution will be regularized according to this prior. + * You need to generate appropriate prior file with "learn_prior.py" script beforehand. + */ +class CV_EXPORTS_W PCAPrior +{ +private: + Mat L1; + Mat L2; + Mat c1; + Mat c2; + +public: + PCAPrior( const char *pathToPrior ); + + int getPadding() const { return L1.size().height; } + + int getBasisSize() const { return L1.size().width; } + + void fillConstraints( float *A1, float *A2, float *b1, float *b2 ) const; +}; + +/** @brief PCAFlow algorithm. + */ +class CV_EXPORTS_W OpticalFlowPCAFlow : public DenseOpticalFlow +{ +protected: + const Ptr<const PCAPrior> prior; + const Size basisSize; + const float sparseRate; // (0 .. 0.1) + const float retainedCornersFraction; // [0 .. 1] + const float occlusionsThreshold; + const float dampingFactor; + const float claheClip; + bool useOpenCL; + +public: + /** @brief Creates an instance of PCAFlow algorithm. + * @param _prior Learned prior or no prior (default). @see cv::optflow::PCAPrior + * @param _basisSize Number of basis vectors. + * @param _sparseRate Controls density of sparse matches. + * @param _retainedCornersFraction Retained corners fraction. + * @param _occlusionsThreshold Occlusion threshold. + * @param _dampingFactor Regularization term for solving least-squares. It is not related to the prior regularization. + * @param _claheClip Clip parameter for CLAHE. + */ + OpticalFlowPCAFlow( Ptr<const PCAPrior> _prior = Ptr<const PCAPrior>(), const Size _basisSize = Size( 18, 14 ), + float _sparseRate = 0.024, float _retainedCornersFraction = 0.2, + float _occlusionsThreshold = 0.0003, float _dampingFactor = 0.00002, float _claheClip = 14 ); + + void calc( InputArray I0, InputArray I1, InputOutputArray flow ) CV_OVERRIDE; + void collectGarbage() CV_OVERRIDE; + +private: + void findSparseFeatures( UMat &from, UMat &to, std::vector<Point2f> &features, + std::vector<Point2f> &predictedFeatures ) const; + + void removeOcclusions( UMat &from, UMat &to, std::vector<Point2f> &features, + std::vector<Point2f> &predictedFeatures ) const; + + void getSystem( OutputArray AOut, OutputArray b1Out, OutputArray b2Out, const std::vector<Point2f> &features, + const std::vector<Point2f> &predictedFeatures, const Size size ); + + void getSystem( OutputArray A1Out, OutputArray A2Out, OutputArray b1Out, OutputArray b2Out, + const std::vector<Point2f> &features, const std::vector<Point2f> &predictedFeatures, + const Size size ); + + OpticalFlowPCAFlow& operator=( const OpticalFlowPCAFlow& ); // make it non-assignable +}; + +/** @brief Creates an instance of PCAFlow +*/ +CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_PCAFlow(); + +//! @} + +} +} + +#endif diff --git a/include/opencv2/optflow/sparse_matching_gpc.hpp b/include/opencv2/optflow/sparse_matching_gpc.hpp new file mode 100644 index 0000000..9458ffb --- /dev/null +++ b/include/opencv2/optflow/sparse_matching_gpc.hpp @@ -0,0 +1,379 @@ +/* +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) + +Copyright (C) 2016, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +/** + * @file sparse_matching_gpc.hpp + * @author Vladislav Samsonov <vvladxx@gmail.com> + * @brief Implementation of the Global Patch Collider. + * + * Implementation of the Global Patch Collider algorithm from the following paper: + * http://research.microsoft.com/en-us/um/people/pkohli/papers/wfrik_cvpr2016.pdf + * + * @cite Wang_2016_CVPR + */ + +#ifndef __OPENCV_OPTFLOW_SPARSE_MATCHING_GPC_HPP__ +#define __OPENCV_OPTFLOW_SPARSE_MATCHING_GPC_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" + +namespace cv +{ +namespace optflow +{ + +//! @addtogroup optflow +//! @{ + +struct CV_EXPORTS_W GPCPatchDescriptor +{ + static const unsigned nFeatures = 18; //!< number of features in a patch descriptor + Vec< double, nFeatures > feature; + + double dot( const Vec< double, nFeatures > &coef ) const; + + void markAsSeparated() { feature[0] = std::numeric_limits< double >::quiet_NaN(); } + + bool isSeparated() const { return cvIsNaN( feature[0] ) != 0; } +}; + +struct CV_EXPORTS_W GPCPatchSample +{ + GPCPatchDescriptor ref; + GPCPatchDescriptor pos; + GPCPatchDescriptor neg; + + void getDirections( bool &refdir, bool &posdir, bool &negdir, const Vec< double, GPCPatchDescriptor::nFeatures > &coef, double rhs ) const; +}; + +typedef std::vector< GPCPatchSample > GPCSamplesVector; + +/** @brief Descriptor types for the Global Patch Collider. + */ +enum GPCDescType +{ + GPC_DESCRIPTOR_DCT = 0, //!< Better quality but slow + GPC_DESCRIPTOR_WHT //!< Worse quality but much faster +}; + +/** @brief Class encapsulating training samples. + */ +class CV_EXPORTS_W GPCTrainingSamples +{ +private: + GPCSamplesVector samples; + int descriptorType; + +public: + /** @brief This function can be used to extract samples from a pair of images and a ground truth flow. + * Sizes of all the provided vectors must be equal. + */ + static Ptr< GPCTrainingSamples > create( const std::vector< String > &imagesFrom, const std::vector< String > &imagesTo, + const std::vector< String > >, int descriptorType ); + + static Ptr< GPCTrainingSamples > create( InputArrayOfArrays imagesFrom, InputArrayOfArrays imagesTo, InputArrayOfArrays gt, + int descriptorType ); + + size_t size() const { return samples.size(); } + + int type() const { return descriptorType; } + + operator GPCSamplesVector &() { return samples; } +}; + +/** @brief Class encapsulating training parameters. + */ +struct GPCTrainingParams +{ + unsigned maxTreeDepth; //!< Maximum tree depth to stop partitioning. + int minNumberOfSamples; //!< Minimum number of samples in the node to stop partitioning. + int descriptorType; //!< Type of descriptors to use. + bool printProgress; //!< Print progress to stdout. + + GPCTrainingParams( unsigned _maxTreeDepth = 20, int _minNumberOfSamples = 3, GPCDescType _descriptorType = GPC_DESCRIPTOR_DCT, + bool _printProgress = true ) + : maxTreeDepth( _maxTreeDepth ), minNumberOfSamples( _minNumberOfSamples ), descriptorType( _descriptorType ), + printProgress( _printProgress ) + { + CV_Assert( check() ); + } + + GPCTrainingParams( const GPCTrainingParams ¶ms ) + : maxTreeDepth( params.maxTreeDepth ), minNumberOfSamples( params.minNumberOfSamples ), descriptorType( params.descriptorType ), + printProgress( params.printProgress ) + { + CV_Assert( check() ); + } + + bool check() const { return maxTreeDepth > 1 && minNumberOfSamples > 1; } +}; + +/** @brief Class encapsulating matching parameters. + */ +struct GPCMatchingParams +{ + bool useOpenCL; //!< Whether to use OpenCL to speed up the matching. + + GPCMatchingParams( bool _useOpenCL = false ) : useOpenCL( _useOpenCL ) {} + + GPCMatchingParams( const GPCMatchingParams ¶ms ) : useOpenCL( params.useOpenCL ) {} +}; + +/** @brief Class for individual tree. + */ +class CV_EXPORTS_W GPCTree : public Algorithm +{ +public: + struct Node + { + Vec< double, GPCPatchDescriptor::nFeatures > coef; //!< Hyperplane coefficients + double rhs; //!< Bias term of the hyperplane + unsigned left; + unsigned right; + + bool operator==( const Node &n ) const { return coef == n.coef && rhs == n.rhs && left == n.left && right == n.right; } + }; + +private: + typedef GPCSamplesVector::iterator SIter; + + std::vector< Node > nodes; + GPCTrainingParams params; + + bool trainNode( size_t nodeId, SIter begin, SIter end, unsigned depth ); + +public: + void train( GPCTrainingSamples &samples, const GPCTrainingParams params = GPCTrainingParams() ); + + void write( FileStorage &fs ) const CV_OVERRIDE; + + void read( const FileNode &fn ) CV_OVERRIDE; + + unsigned findLeafForPatch( const GPCPatchDescriptor &descr ) const; + + static Ptr< GPCTree > create() { return makePtr< GPCTree >(); } + + bool operator==( const GPCTree &t ) const { return nodes == t.nodes; } + + int getDescriptorType() const { return params.descriptorType; } +}; + +template < int T > class GPCForest : public Algorithm +{ +private: + struct Trail + { + unsigned leaf[T]; //!< Inside which leaf of the tree 0..T the patch fell? + Point2i coord; //!< Patch coordinates. + + bool operator==( const Trail &trail ) const { return memcmp( leaf, trail.leaf, sizeof( leaf ) ) == 0; } + + bool operator<( const Trail &trail ) const + { + for ( int i = 0; i < T - 1; ++i ) + if ( leaf[i] != trail.leaf[i] ) + return leaf[i] < trail.leaf[i]; + return leaf[T - 1] < trail.leaf[T - 1]; + } + }; + + class ParallelTrailsFilling : public ParallelLoopBody + { + private: + const GPCForest *forest; + const std::vector< GPCPatchDescriptor > *descr; + std::vector< Trail > *trails; + + ParallelTrailsFilling &operator=( const ParallelTrailsFilling & ); + + public: + ParallelTrailsFilling( const GPCForest *_forest, const std::vector< GPCPatchDescriptor > *_descr, std::vector< Trail > *_trails ) + : forest( _forest ), descr( _descr ), trails( _trails ){}; + + void operator()( const Range &range ) const CV_OVERRIDE + { + for ( int t = range.start; t < range.end; ++t ) + for ( size_t i = 0; i < descr->size(); ++i ) + trails->at( i ).leaf[t] = forest->tree[t].findLeafForPatch( descr->at( i ) ); + } + }; + + GPCTree tree[T]; + +public: + /** @brief Train the forest using one sample set for every tree. + * Please, consider using the next method instead of this one for better quality. + */ + void train( GPCTrainingSamples &samples, const GPCTrainingParams params = GPCTrainingParams() ) + { + for ( int i = 0; i < T; ++i ) + tree[i].train( samples, params ); + } + + /** @brief Train the forest using individual samples for each tree. + * It is generally better to use this instead of the first method. + */ + void train( const std::vector< String > &imagesFrom, const std::vector< String > &imagesTo, const std::vector< String > >, + const GPCTrainingParams params = GPCTrainingParams() ) + { + for ( int i = 0; i < T; ++i ) + { + Ptr< GPCTrainingSamples > samples = + GPCTrainingSamples::create( imagesFrom, imagesTo, gt, params.descriptorType ); // Create training set for the tree + tree[i].train( *samples, params ); + } + } + + void train( InputArrayOfArrays imagesFrom, InputArrayOfArrays imagesTo, InputArrayOfArrays gt, + const GPCTrainingParams params = GPCTrainingParams() ) + { + for ( int i = 0; i < T; ++i ) + { + Ptr< GPCTrainingSamples > samples = + GPCTrainingSamples::create( imagesFrom, imagesTo, gt, params.descriptorType ); // Create training set for the tree + tree[i].train( *samples, params ); + } + } + + void write( FileStorage &fs ) const CV_OVERRIDE + { + fs << "ntrees" << T << "trees" + << "["; + for ( int i = 0; i < T; ++i ) + { + fs << "{"; + tree[i].write( fs ); + fs << "}"; + } + fs << "]"; + } + + void read( const FileNode &fn ) CV_OVERRIDE + { + CV_Assert( T <= (int)fn["ntrees"] ); + FileNodeIterator it = fn["trees"].begin(); + for ( int i = 0; i < T; ++i, ++it ) + tree[i].read( *it ); + } + + /** @brief Find correspondences between two images. + * @param[in] imgFrom First image in a sequence. + * @param[in] imgTo Second image in a sequence. + * @param[out] corr Output vector with pairs of corresponding points. + * @param[in] params Additional matching parameters for fine-tuning. + */ + void findCorrespondences( InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, + const GPCMatchingParams params = GPCMatchingParams() ) const; + + static Ptr< GPCForest > create() { return makePtr< GPCForest >(); } +}; + +class CV_EXPORTS_W GPCDetails +{ +public: + static void dropOutliers( std::vector< std::pair< Point2i, Point2i > > &corr ); + + static void getAllDescriptorsForImage( const Mat *imgCh, std::vector< GPCPatchDescriptor > &descr, const GPCMatchingParams &mp, + int type ); + + static void getCoordinatesFromIndex( size_t index, Size sz, int &x, int &y ); +}; + +template < int T > +void GPCForest< T >::findCorrespondences( InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, + const GPCMatchingParams params ) const +{ + CV_Assert( imgFrom.channels() == 3 ); + CV_Assert( imgTo.channels() == 3 ); + + Mat from, to; + imgFrom.getMat().convertTo( from, CV_32FC3 ); + imgTo.getMat().convertTo( to, CV_32FC3 ); + cvtColor( from, from, COLOR_BGR2YCrCb ); + cvtColor( to, to, COLOR_BGR2YCrCb ); + + Mat fromCh[3], toCh[3]; + split( from, fromCh ); + split( to, toCh ); + + std::vector< GPCPatchDescriptor > descr; + GPCDetails::getAllDescriptorsForImage( fromCh, descr, params, tree[0].getDescriptorType() ); + std::vector< Trail > trailsFrom( descr.size() ), trailsTo( descr.size() ); + + for ( size_t i = 0; i < descr.size(); ++i ) + GPCDetails::getCoordinatesFromIndex( i, from.size(), trailsFrom[i].coord.x, trailsFrom[i].coord.y ); + parallel_for_( Range( 0, T ), ParallelTrailsFilling( this, &descr, &trailsFrom ) ); + + descr.clear(); + GPCDetails::getAllDescriptorsForImage( toCh, descr, params, tree[0].getDescriptorType() ); + + for ( size_t i = 0; i < descr.size(); ++i ) + GPCDetails::getCoordinatesFromIndex( i, to.size(), trailsTo[i].coord.x, trailsTo[i].coord.y ); + parallel_for_( Range( 0, T ), ParallelTrailsFilling( this, &descr, &trailsTo ) ); + + std::sort( trailsFrom.begin(), trailsFrom.end() ); + std::sort( trailsTo.begin(), trailsTo.end() ); + + for ( size_t i = 0; i < trailsFrom.size(); ++i ) + { + bool uniq = true; + while ( i + 1 < trailsFrom.size() && trailsFrom[i] == trailsFrom[i + 1] ) + ++i, uniq = false; + if ( uniq ) + { + typename std::vector< Trail >::const_iterator lb = std::lower_bound( trailsTo.begin(), trailsTo.end(), trailsFrom[i] ); + if ( lb != trailsTo.end() && *lb == trailsFrom[i] && ( ( lb + 1 ) == trailsTo.end() || !( *lb == *( lb + 1 ) ) ) ) + corr.push_back( std::make_pair( trailsFrom[i].coord, lb->coord ) ); + } + } + + GPCDetails::dropOutliers( corr ); +} + +//! @} + +} // namespace optflow + +CV_EXPORTS void write( FileStorage &fs, const String &name, const optflow::GPCTree::Node &node ); + +CV_EXPORTS void read( const FileNode &fn, optflow::GPCTree::Node &node, optflow::GPCTree::Node ); +} // namespace cv + +#endif diff --git a/include/opencv2/phase_unwrapping.hpp b/include/opencv2/phase_unwrapping.hpp new file mode 100644 index 0000000..0e15e71 --- /dev/null +++ b/include/opencv2/phase_unwrapping.hpp @@ -0,0 +1,61 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#include "opencv2/phase_unwrapping/phase_unwrapping.hpp" +#include "opencv2/phase_unwrapping/histogramphaseunwrapping.hpp" + +/** @defgroup phase_unwrapping Phase Unwrapping API + +Two-dimensional phase unwrapping is found in different applications like terrain elevation estimation +in synthetic aperture radar (SAR), field mapping in magnetic resonance imaging or as a way of finding +corresponding pixels in structured light reconstruction with sinusoidal patterns. + +Given a phase map, wrapped between [-pi; pi], phase unwrapping aims at finding the "true" phase map +by adding the right number of 2*pi to each pixel. + +The problem is straightforward for perfect wrapped phase map, but real data are usually not noise-free. +Among the different algorithms that were developed, quality-guided phase unwrapping methods are fast +and efficient. They follow a path that unwraps high quality pixels first, +avoiding error propagation from the start. + +In this module, a quality-guided phase unwrapping is implemented following the approach described in @cite histogramUnwrapping . + +*/ \ No newline at end of file diff --git a/include/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp b/include/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp new file mode 100644 index 0000000..e75d889 --- /dev/null +++ b/include/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp @@ -0,0 +1,107 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_HISTOGRAM_PHASE_UNWRAPPING_HPP__ +#define __OPENCV_HISTOGRAM_PHASE_UNWRAPPING_HPP__ + +#include "opencv2/core.hpp" +#include <opencv2/imgproc.hpp> +#include "opencv2/phase_unwrapping/phase_unwrapping.hpp" + +namespace cv { +namespace phase_unwrapping { +//! @addtogroup phase_unwrapping +//! @{ + + /** @brief Class implementing two-dimensional phase unwrapping based on @cite histogramUnwrapping + * This algorithm belongs to the quality-guided phase unwrapping methods. + * First, it computes a reliability map from second differences between a pixel and its eight neighbours. + * Reliability values lie between 0 and 16*pi*pi. Then, this reliability map is used to compute + * the reliabilities of "edges". An edge is an entity defined by two pixels that are connected + * horizontally or vertically. Its reliability is found by adding the the reliabilities of the + * two pixels connected through it. Edges are sorted in a histogram based on their reliability values. + * This histogram is then used to unwrap pixels, starting from the highest quality pixel. + + * The wrapped phase map and the unwrapped result are stored in CV_32FC1 Mat. + */ +class CV_EXPORTS_W HistogramPhaseUnwrapping : public PhaseUnwrapping +{ + +public: + /** + * @brief Parameters of phaseUnwrapping constructor. + + * @param width Phase map width. + * @param height Phase map height. + * @param histThresh Bins in the histogram are not of equal size. Default value is 3*pi*pi. The one before "histThresh" value are smaller. + * @param nbrOfSmallBins Number of bins between 0 and "histThresh". Default value is 10. + * @param nbrOfLargeBins Number of bins between "histThresh" and 32*pi*pi (highest edge reliability value). Default value is 5. + */ + struct CV_EXPORTS Params + { + Params(); + int width; + int height; + float histThresh; + int nbrOfSmallBins; + int nbrOfLargeBins; + }; + /** + * @brief Constructor + + * @param parameters HistogramPhaseUnwrapping parameters HistogramPhaseUnwrapping::Params: width,height of the phase map and histogram characteristics. + */ + static Ptr<HistogramPhaseUnwrapping> create( const HistogramPhaseUnwrapping::Params ¶meters = + HistogramPhaseUnwrapping::Params() ); + + /** + * @brief Get the reliability map computed from the wrapped phase map. + + * @param reliabilityMap Image where the reliability map is stored. + */ + CV_WRAP + virtual void getInverseReliabilityMap( OutputArray reliabilityMap ) = 0; +}; + +//! @} +} +} +#endif \ No newline at end of file diff --git a/include/opencv2/phase_unwrapping/phase_unwrapping.hpp b/include/opencv2/phase_unwrapping/phase_unwrapping.hpp new file mode 100644 index 0000000..5b5cb51 --- /dev/null +++ b/include/opencv2/phase_unwrapping/phase_unwrapping.hpp @@ -0,0 +1,74 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_PHASE_UNWRAPPING_HPP__ +#define __OPENCV_PHASE_UNWRAPPING_HPP__ + +#include "opencv2/core.hpp" + +namespace cv { +namespace phase_unwrapping { +//! @addtogroup phase_unwrapping +//! @{ + + /** + @brief Abstract base class for phase unwrapping. + */ +class CV_EXPORTS_W PhaseUnwrapping : public virtual Algorithm +{ +public: + /** + * @brief Unwraps a 2D phase map. + + * @param wrappedPhaseMap The wrapped phase map that needs to be unwrapped. + * @param unwrappedPhaseMap The unwrapped phase map. + * @param shadowMask Optional parameter used when some pixels do not hold any phase information in the wrapped phase map. + */ + CV_WRAP + virtual void unwrapPhaseMap( InputArray wrappedPhaseMap, OutputArray unwrappedPhaseMap, + InputArray shadowMask = noArray() ) = 0; + +}; + +//! @} +} +} +#endif \ No newline at end of file diff --git a/include/opencv2/photo.hpp b/include/opencv2/photo.hpp new file mode 100644 index 0000000..8b0652a --- /dev/null +++ b/include/opencv2/photo.hpp @@ -0,0 +1,860 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_PHOTO_HPP +#define OPENCV_PHOTO_HPP + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" + +/** +@defgroup photo Computational Photography + +This module includes photo processing algorithms +@{ + @defgroup photo_inpaint Inpainting + @defgroup photo_denoise Denoising + @defgroup photo_hdr HDR imaging + +This section describes high dynamic range imaging algorithms namely tonemapping, exposure alignment, +camera calibration with multiple exposures and exposure fusion. + + @defgroup photo_decolor Contrast Preserving Decolorization + +Useful links: + +http://www.cse.cuhk.edu.hk/leojia/projects/color2gray/index.html + + @defgroup photo_clone Seamless Cloning + +Useful links: + +https://www.learnopencv.com/seamless-cloning-using-opencv-python-cpp + + @defgroup photo_render Non-Photorealistic Rendering + +Useful links: + +http://www.inf.ufrgs.br/~eslgastal/DomainTransform + +https://www.learnopencv.com/non-photorealistic-rendering-using-opencv-python-c/ +@} + */ + +namespace cv +{ + +//! @addtogroup photo +//! @{ + +//! @addtogroup photo_inpaint +//! @{ +//! the inpainting algorithm +enum +{ + INPAINT_NS = 0, //!< Use Navier-Stokes based method + INPAINT_TELEA = 1 //!< Use the algorithm proposed by Alexandru Telea @cite Telea04 +}; + +/** @brief Restores the selected region in an image using the region neighborhood. + +@param src Input 8-bit, 16-bit unsigned or 32-bit float 1-channel or 8-bit 3-channel image. +@param inpaintMask Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that +needs to be inpainted. +@param dst Output image with the same size and type as src . +@param inpaintRadius Radius of a circular neighborhood of each point inpainted that is considered +by the algorithm. +@param flags Inpainting method that could be cv::INPAINT_NS or cv::INPAINT_TELEA + +The function reconstructs the selected image area from the pixel near the area boundary. The +function may be used to remove dust and scratches from a scanned photo, or to remove undesirable +objects from still images or video. See <http://en.wikipedia.org/wiki/Inpainting> for more details. + +@note + - An example using the inpainting technique can be found at + opencv_source_code/samples/cpp/inpaint.cpp + - (Python) An example using the inpainting technique can be found at + opencv_source_code/samples/python/inpaint.py + */ +CV_EXPORTS_W void inpaint( InputArray src, InputArray inpaintMask, + OutputArray dst, double inpaintRadius, int flags ); + +//! @} photo_inpaint + +//! @addtogroup photo_denoise +//! @{ + +/** @brief Perform image denoising using Non-local Means Denoising algorithm +<http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/> with several computational +optimizations. Noise expected to be a gaussian white noise + +@param src Input 8-bit 1-channel, 2-channel, 3-channel or 4-channel image. +@param dst Output image with the same size and type as src . +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength. Big h value perfectly removes noise but also +removes image details, smaller h value preserves details but also preserves some noise + +This function expected to be applied to grayscale images. For colored images look at +fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored +image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting +image to CIELAB colorspace and then separately denoise L and AB components with different h +parameter. + */ +CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, float h = 3, + int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Perform image denoising using Non-local Means Denoising algorithm +<http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/> with several computational +optimizations. Noise expected to be a gaussian white noise + +@param src Input 8-bit or 16-bit (only with NORM_L1) 1-channel, +2-channel, 3-channel or 4-channel image. +@param dst Output image with the same size and type as src . +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Array of parameters regulating filter strength, either one +parameter applied to all channels or one per channel in dst. Big h value +perfectly removes noise but also removes image details, smaller h +value preserves details but also preserves some noise +@param normType Type of norm used for weight calculation. Can be either NORM_L2 or NORM_L1 + +This function expected to be applied to grayscale images. For colored images look at +fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored +image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting +image to CIELAB colorspace and then separately denoise L and AB components with different h +parameter. + */ +CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, + const std::vector<float>& h, + int templateWindowSize = 7, int searchWindowSize = 21, + int normType = NORM_L2); + +/** @brief Modification of fastNlMeansDenoising function for colored images + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src . +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength for luminance component. Bigger h value perfectly +removes noise but also removes image details, smaller h value preserves details but also preserves +some noise +@param hColor The same as h but for color components. For most images value equals 10 +will be enough to remove colored noise and do not distort colors + +The function converts image to CIELAB colorspace and then separately denoise L and AB components +with given h parameters using fastNlMeansDenoising function. + */ +CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst, + float h = 3, float hColor = 3, + int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Modification of fastNlMeansDenoising function for images sequence where consecutive images have been +captured in small period of time. For example video. This version of the function is for grayscale +images or for manual manipulation with colorspaces. For more details see +<http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394> + +@param srcImgs Input 8-bit 1-channel, 2-channel, 3-channel or +4-channel images sequence. All images should have the same type and +size. +@param imgToDenoiseIndex Target image to denoise index in srcImgs sequence +@param temporalWindowSize Number of surrounding images to use for target image denoising. Should +be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to +imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise +srcImgs[imgToDenoiseIndex] image. +@param dst Output image with the same size and type as srcImgs images. +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength. Bigger h value +perfectly removes noise but also removes image details, smaller h +value preserves details but also preserves some noise + */ +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst, + int imgToDenoiseIndex, int temporalWindowSize, + float h = 3, int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Modification of fastNlMeansDenoising function for images sequence where consecutive images have been +captured in small period of time. For example video. This version of the function is for grayscale +images or for manual manipulation with colorspaces. For more details see +<http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394> + +@param srcImgs Input 8-bit or 16-bit (only with NORM_L1) 1-channel, +2-channel, 3-channel or 4-channel images sequence. All images should +have the same type and size. +@param imgToDenoiseIndex Target image to denoise index in srcImgs sequence +@param temporalWindowSize Number of surrounding images to use for target image denoising. Should +be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to +imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise +srcImgs[imgToDenoiseIndex] image. +@param dst Output image with the same size and type as srcImgs images. +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Array of parameters regulating filter strength, either one +parameter applied to all channels or one per channel in dst. Big h value +perfectly removes noise but also removes image details, smaller h +value preserves details but also preserves some noise +@param normType Type of norm used for weight calculation. Can be either NORM_L2 or NORM_L1 + */ +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst, + int imgToDenoiseIndex, int temporalWindowSize, + const std::vector<float>& h, + int templateWindowSize = 7, int searchWindowSize = 21, + int normType = NORM_L2); + +/** @brief Modification of fastNlMeansDenoisingMulti function for colored images sequences + +@param srcImgs Input 8-bit 3-channel images sequence. All images should have the same type and +size. +@param imgToDenoiseIndex Target image to denoise index in srcImgs sequence +@param temporalWindowSize Number of surrounding images to use for target image denoising. Should +be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to +imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise +srcImgs[imgToDenoiseIndex] image. +@param dst Output image with the same size and type as srcImgs images. +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength for luminance component. Bigger h value perfectly +removes noise but also removes image details, smaller h value preserves details but also preserves +some noise. +@param hColor The same as h but for color components. + +The function converts images to CIELAB colorspace and then separately denoise L and AB components +with given h parameters using fastNlMeansDenoisingMulti function. + */ +CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst, + int imgToDenoiseIndex, int temporalWindowSize, + float h = 3, float hColor = 3, + int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Primal-dual algorithm is an algorithm for solving special types of variational problems (that is, +finding a function to minimize some functional). As the image denoising, in particular, may be seen +as the variational problem, primal-dual algorithm then can be used to perform denoising and this is +exactly what is implemented. + +It should be noted, that this implementation was taken from the July 2013 blog entry +@cite MA13 , which also contained (slightly more general) ready-to-use source code on Python. +Subsequently, that code was rewritten on C++ with the usage of openCV by Vadim Pisarevsky at the end +of July 2013 and finally it was slightly adapted by later authors. + +Although the thorough discussion and justification of the algorithm involved may be found in +@cite ChambolleEtAl, it might make sense to skim over it here, following @cite MA13 . To begin +with, we consider the 1-byte gray-level images as the functions from the rectangular domain of +pixels (it may be seen as set +\f$\left\{(x,y)\in\mathbb{N}\times\mathbb{N}\mid 1\leq x\leq n,\;1\leq y\leq m\right\}\f$ for some +\f$m,\;n\in\mathbb{N}\f$) into \f$\{0,1,\dots,255\}\f$. We shall denote the noised images as \f$f_i\f$ and with +this view, given some image \f$x\f$ of the same size, we may measure how bad it is by the formula + +\f[\left\|\left\|\nabla x\right\|\right\| + \lambda\sum_i\left\|\left\|x-f_i\right\|\right\|\f] + +\f$\|\|\cdot\|\|\f$ here denotes \f$L_2\f$-norm and as you see, the first addend states that we want our +image to be smooth (ideally, having zero gradient, thus being constant) and the second states that +we want our result to be close to the observations we've got. If we treat \f$x\f$ as a function, this is +exactly the functional what we seek to minimize and here the Primal-Dual algorithm comes into play. + +@param observations This array should contain one or more noised versions of the image that is to +be restored. +@param result Here the denoised image will be stored. There is no need to do pre-allocation of +storage space, as it will be automatically allocated, if necessary. +@param lambda Corresponds to \f$\lambda\f$ in the formulas above. As it is enlarged, the smooth +(blurred) images are treated more favorably than detailed (but maybe more noised) ones. Roughly +speaking, as it becomes smaller, the result will be more blur but more sever outliers will be +removed. +@param niters Number of iterations that the algorithm will run. Of course, as more iterations as +better, but it is hard to quantitatively refine this statement, so just use the default and +increase it if the results are poor. + */ +CV_EXPORTS_W void denoise_TVL1(const std::vector<Mat>& observations,Mat& result, double lambda=1.0, int niters=30); + +//! @} photo_denoise + +//! @addtogroup photo_hdr +//! @{ + +enum { LDR_SIZE = 256 }; + +/** @brief Base class for tonemapping algorithms - tools that are used to map HDR image to 8-bit range. + */ +class CV_EXPORTS_W Tonemap : public Algorithm +{ +public: + /** @brief Tonemaps image + + @param src source image - CV_32FC3 Mat (float 32 bits 3 channels) + @param dst destination image - CV_32FC3 Mat with values in [0, 1] range + */ + CV_WRAP virtual void process(InputArray src, OutputArray dst) = 0; + + CV_WRAP virtual float getGamma() const = 0; + CV_WRAP virtual void setGamma(float gamma) = 0; +}; + +/** @brief Creates simple linear mapper with gamma correction + +@param gamma positive value for gamma correction. Gamma value of 1.0 implies no correction, gamma +equal to 2.2f is suitable for most displays. +Generally gamma \> 1 brightens the image and gamma \< 1 darkens it. + */ +CV_EXPORTS_W Ptr<Tonemap> createTonemap(float gamma = 1.0f); + +/** @brief Adaptive logarithmic mapping is a fast global tonemapping algorithm that scales the image in +logarithmic domain. + +Since it's a global operator the same function is applied to all the pixels, it is controlled by the +bias parameter. + +Optional saturation enhancement is possible as described in @cite FL02 . + +For more information see @cite DM03 . + */ +class CV_EXPORTS_W TonemapDrago : public Tonemap +{ +public: + + CV_WRAP virtual float getSaturation() const = 0; + CV_WRAP virtual void setSaturation(float saturation) = 0; + + CV_WRAP virtual float getBias() const = 0; + CV_WRAP virtual void setBias(float bias) = 0; +}; + +/** @brief Creates TonemapDrago object + +@param gamma gamma value for gamma correction. See createTonemap +@param saturation positive saturation enhancement value. 1.0 preserves saturation, values greater +than 1 increase saturation and values less than 1 decrease it. +@param bias value for bias function in [0, 1] range. Values from 0.7 to 0.9 usually give best +results, default value is 0.85. + */ +CV_EXPORTS_W Ptr<TonemapDrago> createTonemapDrago(float gamma = 1.0f, float saturation = 1.0f, float bias = 0.85f); + + +/** @brief This is a global tonemapping operator that models human visual system. + +Mapping function is controlled by adaptation parameter, that is computed using light adaptation and +color adaptation. + +For more information see @cite RD05 . + */ +class CV_EXPORTS_W TonemapReinhard : public Tonemap +{ +public: + CV_WRAP virtual float getIntensity() const = 0; + CV_WRAP virtual void setIntensity(float intensity) = 0; + + CV_WRAP virtual float getLightAdaptation() const = 0; + CV_WRAP virtual void setLightAdaptation(float light_adapt) = 0; + + CV_WRAP virtual float getColorAdaptation() const = 0; + CV_WRAP virtual void setColorAdaptation(float color_adapt) = 0; +}; + +/** @brief Creates TonemapReinhard object + +@param gamma gamma value for gamma correction. See createTonemap +@param intensity result intensity in [-8, 8] range. Greater intensity produces brighter results. +@param light_adapt light adaptation in [0, 1] range. If 1 adaptation is based only on pixel +value, if 0 it's global, otherwise it's a weighted mean of this two cases. +@param color_adapt chromatic adaptation in [0, 1] range. If 1 channels are treated independently, +if 0 adaptation level is the same for each channel. + */ +CV_EXPORTS_W Ptr<TonemapReinhard> +createTonemapReinhard(float gamma = 1.0f, float intensity = 0.0f, float light_adapt = 1.0f, float color_adapt = 0.0f); + +/** @brief This algorithm transforms image to contrast using gradients on all levels of gaussian pyramid, +transforms contrast values to HVS response and scales the response. After this the image is +reconstructed from new contrast values. + +For more information see @cite MM06 . + */ +class CV_EXPORTS_W TonemapMantiuk : public Tonemap +{ +public: + CV_WRAP virtual float getScale() const = 0; + CV_WRAP virtual void setScale(float scale) = 0; + + CV_WRAP virtual float getSaturation() const = 0; + CV_WRAP virtual void setSaturation(float saturation) = 0; +}; + +/** @brief Creates TonemapMantiuk object + +@param gamma gamma value for gamma correction. See createTonemap +@param scale contrast scale factor. HVS response is multiplied by this parameter, thus compressing +dynamic range. Values from 0.6 to 0.9 produce best results. +@param saturation saturation enhancement value. See createTonemapDrago + */ +CV_EXPORTS_W Ptr<TonemapMantiuk> +createTonemapMantiuk(float gamma = 1.0f, float scale = 0.7f, float saturation = 1.0f); + +/** @brief The base class for algorithms that align images of the same scene with different exposures + */ +class CV_EXPORTS_W AlignExposures : public Algorithm +{ +public: + /** @brief Aligns images + + @param src vector of input images + @param dst vector of aligned images + @param times vector of exposure time values for each image + @param response 256x1 matrix with inverse camera response function for each pixel value, it should + have the same number of channels as images. + */ + CV_WRAP virtual void process(InputArrayOfArrays src, std::vector<Mat>& dst, + InputArray times, InputArray response) = 0; +}; + +/** @brief This algorithm converts images to median threshold bitmaps (1 for pixels brighter than median +luminance and 0 otherwise) and than aligns the resulting bitmaps using bit operations. + +It is invariant to exposure, so exposure values and camera response are not necessary. + +In this implementation new image regions are filled with zeros. + +For more information see @cite GW03 . + */ +class CV_EXPORTS_W AlignMTB : public AlignExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, std::vector<Mat>& dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + + /** @brief Short version of process, that doesn't take extra arguments. + + @param src vector of input images + @param dst vector of aligned images + */ + CV_WRAP virtual void process(InputArrayOfArrays src, std::vector<Mat>& dst) = 0; + + /** @brief Calculates shift between two images, i. e. how to shift the second image to correspond it with the + first. + + @param img0 first image + @param img1 second image + */ + CV_WRAP virtual Point calculateShift(InputArray img0, InputArray img1) = 0; + /** @brief Helper function, that shift Mat filling new regions with zeros. + + @param src input image + @param dst result image + @param shift shift value + */ + CV_WRAP virtual void shiftMat(InputArray src, OutputArray dst, const Point shift) = 0; + /** @brief Computes median threshold and exclude bitmaps of given image. + + @param img input image + @param tb median threshold bitmap + @param eb exclude bitmap + */ + CV_WRAP virtual void computeBitmaps(InputArray img, OutputArray tb, OutputArray eb) = 0; + + CV_WRAP virtual int getMaxBits() const = 0; + CV_WRAP virtual void setMaxBits(int max_bits) = 0; + + CV_WRAP virtual int getExcludeRange() const = 0; + CV_WRAP virtual void setExcludeRange(int exclude_range) = 0; + + CV_WRAP virtual bool getCut() const = 0; + CV_WRAP virtual void setCut(bool value) = 0; +}; + +/** @brief Creates AlignMTB object + +@param max_bits logarithm to the base 2 of maximal shift in each dimension. Values of 5 and 6 are +usually good enough (31 and 63 pixels shift respectively). +@param exclude_range range for exclusion bitmap that is constructed to suppress noise around the +median value. +@param cut if true cuts images, otherwise fills the new regions with zeros. + */ +CV_EXPORTS_W Ptr<AlignMTB> createAlignMTB(int max_bits = 6, int exclude_range = 4, bool cut = true); + +/** @brief The base class for camera response calibration algorithms. + */ +class CV_EXPORTS_W CalibrateCRF : public Algorithm +{ +public: + /** @brief Recovers inverse camera response. + + @param src vector of input images + @param dst 256x1 matrix with inverse camera response function + @param times vector of exposure time values for each image + */ + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0; +}; + +/** @brief Inverse camera response function is extracted for each brightness value by minimizing an objective +function as linear system. Objective function is constructed using pixel values on the same position +in all images, extra term is added to make the result smoother. + +For more information see @cite DM97 . + */ +class CV_EXPORTS_W CalibrateDebevec : public CalibrateCRF +{ +public: + CV_WRAP virtual float getLambda() const = 0; + CV_WRAP virtual void setLambda(float lambda) = 0; + + CV_WRAP virtual int getSamples() const = 0; + CV_WRAP virtual void setSamples(int samples) = 0; + + CV_WRAP virtual bool getRandom() const = 0; + CV_WRAP virtual void setRandom(bool random) = 0; +}; + +/** @brief Creates CalibrateDebevec object + +@param samples number of pixel locations to use +@param lambda smoothness term weight. Greater values produce smoother results, but can alter the +response. +@param random if true sample pixel locations are chosen at random, otherwise they form a +rectangular grid. + */ +CV_EXPORTS_W Ptr<CalibrateDebevec> createCalibrateDebevec(int samples = 70, float lambda = 10.0f, bool random = false); + +/** @brief Inverse camera response function is extracted for each brightness value by minimizing an objective +function as linear system. This algorithm uses all image pixels. + +For more information see @cite RB99 . + */ +class CV_EXPORTS_W CalibrateRobertson : public CalibrateCRF +{ +public: + CV_WRAP virtual int getMaxIter() const = 0; + CV_WRAP virtual void setMaxIter(int max_iter) = 0; + + CV_WRAP virtual float getThreshold() const = 0; + CV_WRAP virtual void setThreshold(float threshold) = 0; + + CV_WRAP virtual Mat getRadiance() const = 0; +}; + +/** @brief Creates CalibrateRobertson object + +@param max_iter maximal number of Gauss-Seidel solver iterations. +@param threshold target difference between results of two successive steps of the minimization. + */ +CV_EXPORTS_W Ptr<CalibrateRobertson> createCalibrateRobertson(int max_iter = 30, float threshold = 0.01f); + +/** @brief The base class algorithms that can merge exposure sequence to a single image. + */ +class CV_EXPORTS_W MergeExposures : public Algorithm +{ +public: + /** @brief Merges images. + + @param src vector of input images + @param dst result image + @param times vector of exposure time values for each image + @param response 256x1 matrix with inverse camera response function for each pixel value, it should + have the same number of channels as images. + */ + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) = 0; +}; + +/** @brief The resulting HDR image is calculated as weighted average of the exposures considering exposure +values and camera response. + +For more information see @cite DM97 . + */ +class CV_EXPORTS_W MergeDebevec : public MergeExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0; +}; + +/** @brief Creates MergeDebevec object + */ +CV_EXPORTS_W Ptr<MergeDebevec> createMergeDebevec(); + +/** @brief Pixels are weighted using contrast, saturation and well-exposedness measures, than images are +combined using laplacian pyramids. + +The resulting image weight is constructed as weighted average of contrast, saturation and +well-exposedness measures. + +The resulting image doesn't require tonemapping and can be converted to 8-bit image by multiplying +by 255, but it's recommended to apply gamma correction and/or linear tonemapping. + +For more information see @cite MK07 . + */ +class CV_EXPORTS_W MergeMertens : public MergeExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + /** @brief Short version of process, that doesn't take extra arguments. + + @param src vector of input images + @param dst result image + */ + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst) = 0; + + CV_WRAP virtual float getContrastWeight() const = 0; + CV_WRAP virtual void setContrastWeight(float contrast_weiht) = 0; + + CV_WRAP virtual float getSaturationWeight() const = 0; + CV_WRAP virtual void setSaturationWeight(float saturation_weight) = 0; + + CV_WRAP virtual float getExposureWeight() const = 0; + CV_WRAP virtual void setExposureWeight(float exposure_weight) = 0; +}; + +/** @brief Creates MergeMertens object + +@param contrast_weight contrast measure weight. See MergeMertens. +@param saturation_weight saturation measure weight +@param exposure_weight well-exposedness measure weight + */ +CV_EXPORTS_W Ptr<MergeMertens> +createMergeMertens(float contrast_weight = 1.0f, float saturation_weight = 1.0f, float exposure_weight = 0.0f); + +/** @brief The resulting HDR image is calculated as weighted average of the exposures considering exposure +values and camera response. + +For more information see @cite RB99 . + */ +class CV_EXPORTS_W MergeRobertson : public MergeExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0; +}; + +/** @brief Creates MergeRobertson object + */ +CV_EXPORTS_W Ptr<MergeRobertson> createMergeRobertson(); + +//! @} photo_hdr + +//! @addtogroup photo_decolor +//! @{ + +/** @brief Transforms a color image to a grayscale image. It is a basic tool in digital printing, stylized +black-and-white photograph rendering, and in many single channel image processing applications +@cite CL12 . + +@param src Input 8-bit 3-channel image. +@param grayscale Output 8-bit 1-channel image. +@param color_boost Output 8-bit 3-channel image. + +This function is to be applied on color images. + */ +CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost); + +//! @} photo_decolor + +//! @addtogroup photo_clone +//! @{ + + +//! seamlessClone algorithm flags +enum +{ + /** The power of the method is fully expressed when inserting objects with complex outlines into a new background*/ + NORMAL_CLONE = 1, + /** The classic method, color-based selection and alpha masking might be time consuming and often leaves an undesirable + halo. Seamless cloning, even averaged with the original image, is not effective. Mixed seamless cloning based on a loose selection proves effective.*/ + MIXED_CLONE = 2, + /** Monochrome transfer allows the user to easily replace certain features of one object by alternative features.*/ + MONOCHROME_TRANSFER = 3}; + + +/** @example samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp +An example using seamlessClone function +*/ +/** @brief Image editing tasks concern either global changes (color/intensity corrections, filters, +deformations) or local changes concerned to a selection. Here we are interested in achieving local +changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless +manner. The extent of the changes ranges from slight distortions to complete replacement by novel +content @cite PM03 . + +@param src Input 8-bit 3-channel image. +@param dst Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param p Point in dst image where object is placed. +@param blend Output image with the same size and type as dst. +@param flags Cloning method that could be cv::NORMAL_CLONE, cv::MIXED_CLONE or cv::MONOCHROME_TRANSFER + */ +CV_EXPORTS_W void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p, + OutputArray blend, int flags); + +/** @brief Given an original color image, two differently colored versions of this image can be mixed +seamlessly. + +@param src Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param dst Output image with the same size and type as src . +@param red_mul R-channel multiply factor. +@param green_mul G-channel multiply factor. +@param blue_mul B-channel multiply factor. + +Multiplication factor is between .5 to 2.5. + */ +CV_EXPORTS_W void colorChange(InputArray src, InputArray mask, OutputArray dst, float red_mul = 1.0f, + float green_mul = 1.0f, float blue_mul = 1.0f); + +/** @brief Applying an appropriate non-linear transformation to the gradient field inside the selection and +then integrating back with a Poisson solver, modifies locally the apparent illumination of an image. + +@param src Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param dst Output image with the same size and type as src. +@param alpha Value ranges between 0-2. +@param beta Value ranges between 0-2. + +This is useful to highlight under-exposed foreground objects or to reduce specular reflections. + */ +CV_EXPORTS_W void illuminationChange(InputArray src, InputArray mask, OutputArray dst, + float alpha = 0.2f, float beta = 0.4f); + +/** @brief By retaining only the gradients at edge locations, before integrating with the Poisson solver, one +washes out the texture of the selected region, giving its contents a flat aspect. Here Canny Edge %Detector is used. + +@param src Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param dst Output image with the same size and type as src. +@param low_threshold %Range from 0 to 100. +@param high_threshold Value \> 100. +@param kernel_size The size of the Sobel kernel to be used. + +@note +The algorithm assumes that the color of the source image is close to that of the destination. This +assumption means that when the colors don't match, the source image color gets tinted toward the +color of the destination image. + */ +CV_EXPORTS_W void textureFlattening(InputArray src, InputArray mask, OutputArray dst, + float low_threshold = 30, float high_threshold = 45, + int kernel_size = 3); + +//! @} photo_clone + +//! @addtogroup photo_render +//! @{ + +//! Edge preserving filters +enum +{ + RECURS_FILTER = 1, //!< Recursive Filtering + NORMCONV_FILTER = 2 //!< Normalized Convolution Filtering +}; + +/** @brief Filtering is the fundamental operation in image and video processing. Edge-preserving smoothing +filters are used in many different applications @cite EM11 . + +@param src Input 8-bit 3-channel image. +@param dst Output 8-bit 3-channel image. +@param flags Edge preserving filters: cv::RECURS_FILTER or cv::NORMCONV_FILTER +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. + */ +CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1, + float sigma_s = 60, float sigma_r = 0.4f); + +/** @brief This filter enhances the details of a particular image. + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src. +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. + */ +CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10, + float sigma_r = 0.15f); + +/** @example samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp +An example using non-photorealistic line drawing functions +*/ +/** @brief Pencil-like non-photorealistic line drawing + +@param src Input 8-bit 3-channel image. +@param dst1 Output 8-bit 1-channel image. +@param dst2 Output image with the same size and type as src. +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. +@param shade_factor %Range between 0 to 0.1. + */ +CV_EXPORTS_W void pencilSketch(InputArray src, OutputArray dst1, OutputArray dst2, + float sigma_s = 60, float sigma_r = 0.07f, float shade_factor = 0.02f); + +/** @brief Stylization aims to produce digital imagery with a wide variety of effects not focused on +photorealism. Edge-aware filters are ideal for stylization, as they can abstract regions of low +contrast while preserving, or enhancing, high-contrast features. + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src. +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. + */ +CV_EXPORTS_W void stylization(InputArray src, OutputArray dst, float sigma_s = 60, + float sigma_r = 0.45f); + +//! @} photo_render + +//! @} photo + +} // cv + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/photo/photo_c.h" +#endif + +#endif diff --git a/include/opencv2/photo/cuda.hpp b/include/opencv2/photo/cuda.hpp new file mode 100644 index 0000000..a2f3816 --- /dev/null +++ b/include/opencv2/photo/cuda.hpp @@ -0,0 +1,132 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_PHOTO_CUDA_HPP +#define OPENCV_PHOTO_CUDA_HPP + +#include "opencv2/core/cuda.hpp" + +namespace cv { namespace cuda { + +//! @addtogroup photo_denoise +//! @{ + +/** @brief Performs pure non local means denoising without any simplification, and thus it is not fast. + +@param src Source image. Supports only CV_8UC1, CV_8UC2 and CV_8UC3. +@param dst Destination image. +@param h Filter sigma regulating filter strength for color. +@param search_window Size of search window. +@param block_size Size of block used for computing weights. +@param borderMode Border type. See borderInterpolate for details. BORDER_REFLECT101 , +BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now. +@param stream Stream for the asynchronous version. + +@sa + fastNlMeansDenoising + */ +CV_EXPORTS void nonLocalMeans(InputArray src, OutputArray dst, + float h, + int search_window = 21, + int block_size = 7, + int borderMode = BORDER_DEFAULT, + Stream& stream = Stream::Null()); + +/** @brief Perform image denoising using Non-local Means Denoising algorithm +<http://www.ipol.im/pub/algo/bcm_non_local_means_denoising> with several computational +optimizations. Noise expected to be a gaussian white noise + +@param src Input 8-bit 1-channel, 2-channel or 3-channel image. +@param dst Output image with the same size and type as src . +@param h Parameter regulating filter strength. Big h value perfectly removes noise but also +removes image details, smaller h value preserves details but also preserves some noise +@param search_window Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater search_window - greater +denoising time. Recommended value 21 pixels +@param block_size Size in pixels of the template patch that is used to compute weights. Should be +odd. Recommended value 7 pixels +@param stream Stream for the asynchronous invocations. + +This function expected to be applied to grayscale images. For colored images look at +FastNonLocalMeansDenoising::labMethod. + +@sa + fastNlMeansDenoising + */ +CV_EXPORTS void fastNlMeansDenoising(InputArray src, OutputArray dst, + float h, + int search_window = 21, + int block_size = 7, + Stream& stream = Stream::Null()); + +/** @brief Modification of fastNlMeansDenoising function for colored images + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src . +@param h_luminance Parameter regulating filter strength. Big h value perfectly removes noise but +also removes image details, smaller h value preserves details but also preserves some noise +@param photo_render float The same as h but for color components. For most images value equals 10 will be +enough to remove colored noise and do not distort colors +@param search_window Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater search_window - greater +denoising time. Recommended value 21 pixels +@param block_size Size in pixels of the template patch that is used to compute weights. Should be +odd. Recommended value 7 pixels +@param stream Stream for the asynchronous invocations. + +The function converts image to CIELAB colorspace and then separately denoise L and AB components +with given h parameters using FastNonLocalMeansDenoising::simpleMethod function. + +@sa + fastNlMeansDenoisingColored + */ +CV_EXPORTS void fastNlMeansDenoisingColored(InputArray src, OutputArray dst, + float h_luminance, float photo_render, + int search_window = 21, + int block_size = 7, + Stream& stream = Stream::Null()); + +//! @} photo + +}} // namespace cv { namespace cuda { + +#endif /* OPENCV_PHOTO_CUDA_HPP */ diff --git a/include/opencv2/photo/photo.hpp b/include/opencv2/photo/photo.hpp new file mode 100644 index 0000000..8af5e9f --- /dev/null +++ b/include/opencv2/photo/photo.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/photo.hpp" diff --git a/include/opencv2/photo/photo_c.h b/include/opencv2/photo/photo_c.h new file mode 100644 index 0000000..cd623c1 --- /dev/null +++ b/include/opencv2/photo/photo_c.h @@ -0,0 +1,74 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_PHOTO_C_H +#define OPENCV_PHOTO_C_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup photo_c + @{ + */ + +/* Inpainting algorithms */ +enum InpaintingModes +{ + CV_INPAINT_NS =0, + CV_INPAINT_TELEA =1 +}; + + +/* Inpaints the selected region in the image */ +CVAPI(void) cvInpaint( const CvArr* src, const CvArr* inpaint_mask, + CvArr* dst, double inpaintRange, int flags ); + +/** @} */ + +#ifdef __cplusplus +} //extern "C" +#endif + +#endif //OPENCV_PHOTO_C_H diff --git a/include/opencv2/plot.hpp b/include/opencv2/plot.hpp new file mode 100644 index 0000000..06a12a1 --- /dev/null +++ b/include/opencv2/plot.hpp @@ -0,0 +1,120 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ +//################################################################################ +// +// Created by Nuno Moutinho +// +//################################################################################ + +#ifndef _OPENCV_PLOT_H_ +#define _OPENCV_PLOT_H_ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +/** +@defgroup plot Plot function for Mat data +*/ + +namespace cv +{ + namespace plot + { + //! @addtogroup plot + //! @{ + + class CV_EXPORTS_W Plot2d : public Algorithm + { + public: + + CV_WRAP virtual void setMinX(double _plotMinX) = 0; + CV_WRAP virtual void setMinY(double _plotMinY) = 0; + CV_WRAP virtual void setMaxX(double _plotMaxX) = 0; + CV_WRAP virtual void setMaxY(double _plotMaxY) = 0; + CV_WRAP virtual void setPlotLineWidth(int _plotLineWidth) = 0; + /** + * @brief Switches data visualization mode + * + * @param _needPlotLine if true then neighbour plot points will be connected by lines. + * In other case data will be plotted as a set of standalone points. + */ + CV_WRAP virtual void setNeedPlotLine(bool _needPlotLine) = 0; + CV_WRAP virtual void setPlotLineColor(Scalar _plotLineColor) = 0; + CV_WRAP virtual void setPlotBackgroundColor(Scalar _plotBackgroundColor) = 0; + CV_WRAP virtual void setPlotAxisColor(Scalar _plotAxisColor) = 0; + CV_WRAP virtual void setPlotGridColor(Scalar _plotGridColor) = 0; + CV_WRAP virtual void setPlotTextColor(Scalar _plotTextColor) = 0; + CV_WRAP virtual void setPlotSize(int _plotSizeWidth, int _plotSizeHeight) = 0; + CV_WRAP virtual void setShowGrid(bool needShowGrid) = 0; + CV_WRAP virtual void setShowText(bool needShowText) = 0; + CV_WRAP virtual void setGridLinesNumber(int gridLinesNumber) = 0; + CV_WRAP virtual void setInvertOrientation(bool _invertOrientation) = 0; + /** + * @brief Sets the index of a point which coordinates will be printed on the top left corner of the plot (if ShowText flag is true). + * + * @param pointIdx index of the required point in data array. + */ + CV_WRAP virtual void setPointIdxToPrint(int pointIdx) = 0; + CV_WRAP virtual void render(OutputArray _plotResult) = 0; + + /** + * @brief Creates Plot2d object + * + * @param data \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. \f$X\f$ values + * will be equal to indexes of correspondind elements in data matrix. + */ + CV_WRAP static Ptr<Plot2d> create(InputArray data); + + /** + * @brief Creates Plot2d object + * + * @param dataX \f$1xN\f$ or \f$Nx1\f$ matrix \f$X\f$ values of points to plot. + * @param dataY \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. + */ + CV_WRAP static Ptr<Plot2d> create(InputArray dataX, InputArray dataY); + }; + //! @} + } +} + +#endif +#endif diff --git a/include/opencv2/reg/map.hpp b/include/opencv2/reg/map.hpp new file mode 100644 index 0000000..a885a28 --- /dev/null +++ b/include/opencv2/reg/map.hpp @@ -0,0 +1,175 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAP_H_ +#define MAP_H_ + +#include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar) + +/** @defgroup reg Image Registration + +The Registration module implements parametric image registration. The implemented method is direct +alignment, that is, it uses directly the pixel values for calculating the registration between a +pair of images, as opposed to feature-based registration. The implementation follows essentially the +corresponding part of @cite Szeliski06 . + +Feature based methods have some advantages over pixel based methods when we are trying to register +pictures that have been shoot under different lighting conditions or exposition times, or when the +images overlap only partially. On the other hand, the main advantage of pixel-based methods when +compared to feature based methods is their better precision for some pictures (those shoot under +similar lighting conditions and that have a significative overlap), due to the fact that we are +using all the information available in the image, which allows us to achieve subpixel accuracy. This +is particularly important for certain applications like multi-frame denoising or super-resolution. + +In fact, pixel and feature registration methods can complement each other: an application could +first obtain a coarse registration using features and then refine the registration using a pixel +based method on the overlapping area of the images. The code developed allows this use case. + +The module implements classes derived from the abstract classes cv::reg::Map or cv::reg::Mapper. The +former models a coordinate transformation between two reference frames, while the later encapsulates +a way of invoking a method that calculates a Map between two images. Although the objective has been +to implement pixel based methods, the module can be extended to support other methods that can +calculate transformations between images (feature methods, optical flow, etc.). + +Each class derived from Map implements a motion model, as follows: + +- MapShift: Models a simple translation +- MapAffine: Models an affine transformation +- MapProjec: Models a projective transformation + +MapProject can also be used to model affine motion or translations, but some operations on it are +more costly, and that is the reason for defining the other two classes. + +The classes derived from Mapper are + +- MapperGradShift: Gradient based alignment for calculating translations. It produces a MapShift + (two parameters that correspond to the shift vector). +- MapperGradEuclid: Gradient based alignment for euclidean motions, that is, rotations and + translations. It calculates three parameters (angle and shift vector), although the result is + stored in a MapAffine object for convenience. +- MapperGradSimilar: Gradient based alignment for calculating similarities, which adds scaling to + the euclidean motion. It calculates four parameters (two for the anti-symmetric matrix and two + for the shift vector), although the result is stored in a MapAffine object for better + convenience. +- MapperGradAffine: Gradient based alignment for an affine motion model. The number of parameters + is six and the result is stored in a MapAffine object. +- MapperGradProj: Gradient based alignment for calculating projective transformations. The number + of parameters is eight and the result is stored in a MapProject object. +- MapperPyramid: It implements hyerarchical motion estimation using a Gaussian pyramid. Its + constructor accepts as argument any other object that implements the Mapper interface, and it is + that mapper the one called by MapperPyramid for each scale of the pyramid. + +If the motion between the images is not very small, the normal way of using these classes is to +create a MapperGrad\* object and use it as input to create a MapperPyramid, which in turn is called +to perform the calculation. However, if the motion between the images is small enough, we can use +directly the MapperGrad\* classes. Another possibility is to use first a feature based method to +perform a coarse registration and then do a refinement through MapperPyramid or directly a +MapperGrad\* object. The "calculate" method of the mappers accepts an initial estimation of the +motion as input. + +When deciding which MapperGrad to use we must take into account that mappers with more parameters +can handle more complex motions, but involve more calculations and are therefore slower. Also, if we +are confident on the motion model that is followed by the sequence, increasing the number of +parameters beyond what we need will decrease the accuracy: it is better to use the least number of +degrees of freedom that we can. + +In the module tests there are examples that show how to register a pair of images using any of the +implemented mappers. +*/ + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/** @brief Base class for modelling a Map between two images. + +The class is only used to define the common interface for any possible map. + */ +class CV_EXPORTS_W Map +{ +public: + /*! + * Virtual destructor + */ + virtual ~Map(); + + /*! + * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T^{-1}(x)), as we + * have to apply the inverse transformation to the points to move them to were the values + * of img2 are. + * \param[in] img1 Original image + * \param[out] img2 Warped image + */ + CV_WRAP virtual void warp(InputArray img1, OutputArray img2) const; + + /*! + * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T(x)), so in fact + * this is the inverse warping as we are taking the value of img1 with the forward + * transformation of the points. + * \param[in] img1 Original image + * \param[out] img2 Warped image + */ + CV_WRAP virtual void inverseWarp(InputArray img1, OutputArray img2) const = 0; + + /*! + * Calculates the inverse map + * \return Inverse map + */ + CV_WRAP virtual cv::Ptr<Map> inverseMap() const = 0; + + /*! + * Changes the map composing the current transformation with the one provided in the call. + * The order is first the current transformation, then the input argument. + * \param[in] map Transformation to compose with. + */ + CV_WRAP virtual void compose(cv::Ptr<Map> map) = 0; + + /*! + * Scales the map by a given factor as if the coordinates system is expanded/compressed + * by that factor. + * \param[in] factor Expansion if bigger than one, compression if smaller than one + */ + CV_WRAP virtual void scale(double factor) = 0; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAP_H_ diff --git a/include/opencv2/reg/mapaffine.hpp b/include/opencv2/reg/mapaffine.hpp new file mode 100644 index 0000000..52ab8d6 --- /dev/null +++ b/include/opencv2/reg/mapaffine.hpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPAFFINE_H_ +#define MAPAFFINE_H_ + +#include "map.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Defines an affine transformation + */ +class CV_EXPORTS_W MapAffine : public Map +{ +public: + /*! + * Default constructor builds an identity map + */ + CV_WRAP MapAffine(); + + /*! + * Constructor providing explicit values + * \param[in] linTr Linear part of the affine transformation + * \param[in] shift Displacement part of the affine transformation + */ + CV_WRAP MapAffine(InputArray linTr, InputArray shift); + + /*! + * Destructor + */ + ~MapAffine(); + + CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> inverseMap() const CV_OVERRIDE; + + CV_WRAP void compose(cv::Ptr<Map> map) CV_OVERRIDE; + + CV_WRAP void scale(double factor) CV_OVERRIDE; + + /*! + * Return linear part of the affine transformation + * \return Linear part of the affine transformation + */ + const cv::Matx<double, 2, 2>& getLinTr() const { + return linTr_; + } + + CV_WRAP void getLinTr(OutputArray linTr) const { + Mat(linTr_).copyTo(linTr); + } + + /*! + * Return displacement part of the affine transformation + * \return Displacement part of the affine transformation + */ + const cv::Vec<double, 2>& getShift() const { + return shift_; + } + + CV_WRAP void getShift(OutputArray shift) const { + Mat(shift_).copyTo(shift); + } + +private: + cv::Matx<double, 2, 2> linTr_; + cv::Vec<double, 2> shift_; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPAFFINE_H_ diff --git a/include/opencv2/reg/mapper.hpp b/include/opencv2/reg/mapper.hpp new file mode 100644 index 0000000..2c2862d --- /dev/null +++ b/include/opencv2/reg/mapper.hpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPER_H_ +#define MAPPER_H_ + +#include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar) +#include "map.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/** @brief Base class for modelling an algorithm for calculating a map + +The class is only used to define the common interface for any possible mapping algorithm. + */ +class CV_EXPORTS_W Mapper +{ +public: + virtual ~Mapper(void) {} + + /* + * Calculate mapping between two images + * \param[in] img1 Reference image + * \param[in] img2 Warped image + * \param[in] If present, it is an initial rough estimation that the mapper will try to refine. + * \return Map from img1 to img2, stored in a smart pointer. + */ + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0; + + /* + * Returns a map compatible with the Mapper class + * \return Pointer to identity Map + */ + CV_WRAP virtual cv::Ptr<Map> getMap() const = 0; + +protected: + /* + * Calculates gradient and difference between images + * \param[in] img1 Image one + * \param[in] img2 Image two + * \param[out] Ix Gradient x-coordinate + * \param[out] Iy Gradient y-coordinate + * \param[out] It Difference of images + */ + void gradient(const cv::Mat& img1, const cv::Mat& img2, + cv::Mat& Ix, cv::Mat& Iy, cv::Mat& It) const; + + /* + * Fills matrices with pixel coordinates of an image + * \param[in] img Image + * \param[out] grid_r Row (y-coordinate) + * \param[out] grid_c Column (x-coordinate) + */ + void grid(const Mat& img, Mat& grid_r, Mat& grid_c) const; + + /* + * Per-element square of a matrix + * \param[in] mat1 Input matrix + * \return mat1[i,j]^2 + */ + cv::Mat sqr(const cv::Mat& mat1) const + { + cv::Mat res; + res.create(mat1.size(), mat1.type()); + res = mat1.mul(mat1); + return res; + } +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPER_H_ + diff --git a/include/opencv2/reg/mappergradaffine.hpp b/include/opencv2/reg/mappergradaffine.hpp new file mode 100644 index 0000000..49b0bc7 --- /dev/null +++ b/include/opencv2/reg/mappergradaffine.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPERGRADAFFINE_H_ +#define MAPPERGRADAFFINE_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Mapper for affine motion + */ +class CV_EXPORTS_W MapperGradAffine: public Mapper +{ +public: + CV_WRAP MapperGradAffine(); + ~MapperGradAffine(void); + + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADAFFINE_H_ diff --git a/include/opencv2/reg/mappergradeuclid.hpp b/include/opencv2/reg/mappergradeuclid.hpp new file mode 100644 index 0000000..4f6c5c8 --- /dev/null +++ b/include/opencv2/reg/mappergradeuclid.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPERGRADEUCLID_H_ +#define MAPPERGRADEUCLID_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Mapper for euclidean motion: rotation plus shift + */ +class CV_EXPORTS_W MapperGradEuclid: public Mapper +{ +public: + CV_WRAP MapperGradEuclid(); + ~MapperGradEuclid(); + + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADEUCLID_H_ diff --git a/include/opencv2/reg/mappergradproj.hpp b/include/opencv2/reg/mappergradproj.hpp new file mode 100644 index 0000000..1e01c71 --- /dev/null +++ b/include/opencv2/reg/mappergradproj.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPERGRADPROJ_H_ +#define MAPPERGRADPROJ_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Gradient mapper for a projective transformation + */ +class CV_EXPORTS_W MapperGradProj: public Mapper +{ +public: + CV_WRAP MapperGradProj(); + ~MapperGradProj(); + + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADPROJ_H_ diff --git a/include/opencv2/reg/mappergradshift.hpp b/include/opencv2/reg/mappergradshift.hpp new file mode 100644 index 0000000..cd812d9 --- /dev/null +++ b/include/opencv2/reg/mappergradshift.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPERGRADSHIFT_H_ +#define MAPPERGRADSHIFT_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Gradient mapper for a translation + */ +class CV_EXPORTS_W MapperGradShift: public Mapper +{ +public: + CV_WRAP MapperGradShift(); + virtual ~MapperGradShift(); + + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADSHIFT_H_ diff --git a/include/opencv2/reg/mappergradsimilar.hpp b/include/opencv2/reg/mappergradsimilar.hpp new file mode 100644 index 0000000..07d64d9 --- /dev/null +++ b/include/opencv2/reg/mappergradsimilar.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPERGRADSIMILAR_H_ +#define MAPPERGRADSIMILAR_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Calculates a similarity transformation between to images (scale, rotation, and shift) + */ +class CV_EXPORTS_W MapperGradSimilar: public Mapper +{ +public: + CV_WRAP MapperGradSimilar(); + ~MapperGradSimilar(); + + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADSIMILAR_H_ diff --git a/include/opencv2/reg/mapperpyramid.hpp b/include/opencv2/reg/mapperpyramid.hpp new file mode 100644 index 0000000..6106f49 --- /dev/null +++ b/include/opencv2/reg/mapperpyramid.hpp @@ -0,0 +1,105 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPERPYRAMID_H_ +#define MAPPERPYRAMID_H_ + +#include "mapper.hpp" +#include "mapaffine.hpp" +#include "mapprojec.hpp" +#include "mapshift.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Calculates a map using a gaussian pyramid + */ +class CV_EXPORTS_W MapperPyramid: public Mapper +{ +public: + /* + * Constructor + * \param[in] baseMapper Base mapper used for the refinements + */ + CV_WRAP MapperPyramid(Ptr<Mapper> baseMapper); + + CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> getMap() const CV_OVERRIDE; + + CV_PROP_RW int numLev_; /*!< Number of levels of the pyramid */ + CV_PROP_RW int numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */ + +private: + MapperPyramid& operator=(const MapperPyramid&); + const Mapper& baseMapper_; /*!< Mapper used in inner level */ +}; + +/*! + * Converts a pointer to a Map returned by MapperPyramid::calculate into the specified Map pointer type + */ +class CV_EXPORTS_W MapTypeCaster +{ +public: + CV_WRAP static Ptr<MapAffine> toAffine(Ptr<Map> sourceMap) + { + MapAffine& affineMap = dynamic_cast<MapAffine&>(*sourceMap); + return Ptr<MapAffine>(new MapAffine(affineMap)); + } + + CV_WRAP static Ptr<MapShift> toShift(Ptr<Map> sourceMap) + { + MapShift& shiftMap = dynamic_cast<MapShift&>(*sourceMap); + return Ptr<MapShift>(new MapShift(shiftMap)); + } + + CV_WRAP static Ptr<MapProjec> toProjec(Ptr<Map> sourceMap) + { + MapProjec& projecMap = dynamic_cast<MapProjec&>(*sourceMap); + return Ptr<MapProjec>(new MapProjec(projecMap)); + } +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERPYRAMID_H_ diff --git a/include/opencv2/reg/mapprojec.hpp b/include/opencv2/reg/mapprojec.hpp new file mode 100644 index 0000000..6d1e565 --- /dev/null +++ b/include/opencv2/reg/mapprojec.hpp @@ -0,0 +1,109 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPPROJEC_H_ +#define MAPPROJEC_H_ + +#include "map.hpp" + + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Defines an transformation that consists on a projective transformation + */ +class CV_EXPORTS_W MapProjec : public Map +{ +public: + /*! + * Default constructor builds an identity map + */ + CV_WRAP MapProjec(); + + /*! + * Constructor providing explicit values + * \param[in] projTr Projective transformation + */ + CV_WRAP MapProjec(InputArray projTr); + + /*! + * Destructor + */ + ~MapProjec(); + + CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> inverseMap() const CV_OVERRIDE; + + CV_WRAP void compose(cv::Ptr<Map> map) CV_OVERRIDE; + + CV_WRAP void scale(double factor) CV_OVERRIDE; + + /*! + * Returns projection matrix + * \return Projection matrix + */ + const cv::Matx<double, 3, 3>& getProjTr() const { + return projTr_; + } + + CV_WRAP void getProjTr(OutputArray projTr) const { + Mat(projTr_).copyTo(projTr); + } + + /*! + * Normalizes object's homography + */ + CV_WRAP void normalize() { + double z = 1./projTr_(2, 2); + for(size_t v_i = 0; v_i < sizeof(projTr_.val)/sizeof(projTr_.val[0]); ++v_i) + projTr_.val[v_i] *= z; + } + +private: + cv::Matx<double, 3, 3> projTr_; /*< Projection matrix */ +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPROJEC_H_ diff --git a/include/opencv2/reg/mapshift.hpp b/include/opencv2/reg/mapshift.hpp new file mode 100644 index 0000000..ada9545 --- /dev/null +++ b/include/opencv2/reg/mapshift.hpp @@ -0,0 +1,101 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the 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. +// +//M*/ + +#ifndef MAPSHIFT_H_ +#define MAPSHIFT_H_ + +#include "map.hpp" + + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Defines an transformation that consists on a simple displacement + */ +class CV_EXPORTS_W MapShift : public Map +{ +public: + /*! + * Default constructor builds an identity map + */ + CV_WRAP MapShift(); + + /*! + * Constructor providing explicit values + * \param[in] shift Displacement + */ + + CV_WRAP MapShift(InputArray shift); + + /*! + * Destructor + */ + ~MapShift(); + + CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; + + CV_WRAP cv::Ptr<Map> inverseMap() const CV_OVERRIDE; + + CV_WRAP void compose(cv::Ptr<Map> map) CV_OVERRIDE; + + CV_WRAP void scale(double factor) CV_OVERRIDE; + + /*! + * Return displacement + * \return Displacement + */ + const cv::Vec<double, 2>& getShift() const { + return shift_; + } + + CV_WRAP void getShift(OutputArray shift) const { + Mat(shift_).copyTo(shift); + } + +private: + cv::Vec<double, 2> shift_; /*< Displacement */ +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPSHIFT_H_ diff --git a/include/opencv2/rgbd.hpp b/include/opencv2/rgbd.hpp new file mode 100644 index 0000000..a7d1127 --- /dev/null +++ b/include/opencv2/rgbd.hpp @@ -0,0 +1,1075 @@ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2009, Willow Garage, Inc. + * All rights reserved. + * + * 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 name of Willow Garage, Inc. nor the names of its + * 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 THE + * COPYRIGHT OWNER 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. + * + */ + +#ifndef __OPENCV_RGBD_HPP__ +#define __OPENCV_RGBD_HPP__ + +#ifdef __cplusplus + +#include <opencv2/core.hpp> +#include <limits> + +/** @defgroup rgbd RGB-Depth Processing +*/ + +namespace cv +{ +namespace rgbd +{ + +//! @addtogroup rgbd +//! @{ + + /** Checks if the value is a valid depth. For CV_16U or CV_16S, the convention is to be invalid if it is + * a limit. For a float/double, we just check if it is a NaN + * @param depth the depth to check for validity + */ + CV_EXPORTS + inline bool + isValidDepth(const float & depth) + { + return !cvIsNaN(depth); + } + CV_EXPORTS + inline bool + isValidDepth(const double & depth) + { + return !cvIsNaN(depth); + } + CV_EXPORTS + inline bool + isValidDepth(const short int & depth) + { + return (depth != std::numeric_limits<short int>::min()) && (depth != std::numeric_limits<short int>::max()); + } + CV_EXPORTS + inline bool + isValidDepth(const unsigned short int & depth) + { + return (depth != std::numeric_limits<unsigned short int>::min()) + && (depth != std::numeric_limits<unsigned short int>::max()); + } + CV_EXPORTS + inline bool + isValidDepth(const int & depth) + { + return (depth != std::numeric_limits<int>::min()) && (depth != std::numeric_limits<int>::max()); + } + CV_EXPORTS + inline bool + isValidDepth(const unsigned int & depth) + { + return (depth != std::numeric_limits<unsigned int>::min()) && (depth != std::numeric_limits<unsigned int>::max()); + } + + /** Object that can compute the normals in an image. + * It is an object as it can cache data for speed efficiency + * The implemented methods are either: + * - FALS (the fastest) and SRI from + * ``Fast and Accurate Computation of Surface Normals from Range Images`` + * by H. Badino, D. Huber, Y. Park and T. Kanade + * - the normals with bilateral filtering on a depth image from + * ``Gradient Response Maps for Real-Time Detection of Texture-Less Objects`` + * by S. Hinterstoisser, C. Cagniart, S. Ilic, P. Sturm, N. Navab, P. Fua, and V. Lepetit + */ + class CV_EXPORTS_W RgbdNormals: public Algorithm + { + public: + enum RGBD_NORMALS_METHOD + { + RGBD_NORMALS_METHOD_FALS = 0, + RGBD_NORMALS_METHOD_LINEMOD = 1, + RGBD_NORMALS_METHOD_SRI = 2 + }; + + RgbdNormals() + : + rows_(0), + cols_(0), + depth_(0), + K_(Mat()), + window_size_(0), + method_(RGBD_NORMALS_METHOD_FALS), + rgbd_normals_impl_(0) + { + } + + /** Constructor + * @param rows the number of rows of the depth image normals will be computed on + * @param cols the number of cols of the depth image normals will be computed on + * @param depth the depth of the normals (only CV_32F or CV_64F) + * @param K the calibration matrix to use + * @param window_size the window size to compute the normals: can only be 1,3,5 or 7 + * @param method one of the methods to use: RGBD_NORMALS_METHOD_SRI, RGBD_NORMALS_METHOD_FALS + */ + RgbdNormals(int rows, int cols, int depth, InputArray K, int window_size = 5, int method = + RgbdNormals::RGBD_NORMALS_METHOD_FALS); + + ~RgbdNormals(); + + CV_WRAP static Ptr<RgbdNormals> create(int rows, int cols, int depth, InputArray K, int window_size = 5, int method = + RgbdNormals::RGBD_NORMALS_METHOD_FALS); + + /** Given a set of 3d points in a depth image, compute the normals at each point. + * @param points a rows x cols x 3 matrix of CV_32F/CV64F or a rows x cols x 1 CV_U16S + * @param normals a rows x cols x 3 matrix + */ + CV_WRAP_AS(apply) void + operator()(InputArray points, OutputArray normals) const; + + /** Initializes some data that is cached for later computation + * If that function is not called, it will be called the first time normals are computed + */ + CV_WRAP void + initialize() const; + + CV_WRAP int getRows() const + { + return rows_; + } + CV_WRAP void setRows(int val) + { + rows_ = val; + } + CV_WRAP int getCols() const + { + return cols_; + } + CV_WRAP void setCols(int val) + { + cols_ = val; + } + CV_WRAP int getWindowSize() const + { + return window_size_; + } + CV_WRAP void setWindowSize(int val) + { + window_size_ = val; + } + CV_WRAP int getDepth() const + { + return depth_; + } + CV_WRAP void setDepth(int val) + { + depth_ = val; + } + CV_WRAP cv::Mat getK() const + { + return K_; + } + CV_WRAP void setK(const cv::Mat &val) + { + K_ = val; + } + CV_WRAP int getMethod() const + { + return method_; + } + CV_WRAP void setMethod(int val) + { + method_ = val; + } + + protected: + void + initialize_normals_impl(int rows, int cols, int depth, const Mat & K, int window_size, int method) const; + + int rows_, cols_, depth_; + Mat K_; + int window_size_; + int method_; + mutable void* rgbd_normals_impl_; + }; + + /** Object that can clean a noisy depth image + */ + class CV_EXPORTS_W DepthCleaner: public Algorithm + { + public: + /** NIL method is from + * ``Modeling Kinect Sensor Noise for Improved 3d Reconstruction and Tracking`` + * by C. Nguyen, S. Izadi, D. Lovel + */ + enum DEPTH_CLEANER_METHOD + { + DEPTH_CLEANER_NIL + }; + + DepthCleaner() + : + depth_(0), + window_size_(0), + method_(DEPTH_CLEANER_NIL), + depth_cleaner_impl_(0) + { + } + + /** Constructor + * @param depth the depth of the normals (only CV_32F or CV_64F) + * @param window_size the window size to compute the normals: can only be 1,3,5 or 7 + * @param method one of the methods to use: RGBD_NORMALS_METHOD_SRI, RGBD_NORMALS_METHOD_FALS + */ + DepthCleaner(int depth, int window_size = 5, int method = DepthCleaner::DEPTH_CLEANER_NIL); + + ~DepthCleaner(); + + CV_WRAP static Ptr<DepthCleaner> create(int depth, int window_size = 5, int method = DepthCleaner::DEPTH_CLEANER_NIL); + + /** Given a set of 3d points in a depth image, compute the normals at each point. + * @param points a rows x cols x 3 matrix of CV_32F/CV64F or a rows x cols x 1 CV_U16S + * @param depth a rows x cols matrix of the cleaned up depth + */ + CV_WRAP_AS(apply) void + operator()(InputArray points, OutputArray depth) const; + + /** Initializes some data that is cached for later computation + * If that function is not called, it will be called the first time normals are computed + */ + CV_WRAP void + initialize() const; + + CV_WRAP int getWindowSize() const + { + return window_size_; + } + CV_WRAP void setWindowSize(int val) + { + window_size_ = val; + } + CV_WRAP int getDepth() const + { + return depth_; + } + CV_WRAP void setDepth(int val) + { + depth_ = val; + } + CV_WRAP int getMethod() const + { + return method_; + } + CV_WRAP void setMethod(int val) + { + method_ = val; + } + + protected: + void + initialize_cleaner_impl() const; + + int depth_; + int window_size_; + int method_; + mutable void* depth_cleaner_impl_; + }; + + + /** Registers depth data to an external camera + * Registration is performed by creating a depth cloud, transforming the cloud by + * the rigid body transformation between the cameras, and then projecting the + * transformed points into the RGB camera. + * + * uv_rgb = K_rgb * [R | t] * z * inv(K_ir) * uv_ir + * + * Currently does not check for negative depth values. + * + * @param unregisteredCameraMatrix the camera matrix of the depth camera + * @param registeredCameraMatrix the camera matrix of the external camera + * @param registeredDistCoeffs the distortion coefficients of the external camera + * @param Rt the rigid body transform between the cameras. Transforms points from depth camera frame to external camera frame. + * @param unregisteredDepth the input depth data + * @param outputImagePlaneSize the image plane dimensions of the external camera (width, height) + * @param registeredDepth the result of transforming the depth into the external camera + * @param depthDilation whether or not the depth is dilated to avoid holes and occlusion errors (optional) + */ + CV_EXPORTS_W + void + registerDepth(InputArray unregisteredCameraMatrix, InputArray registeredCameraMatrix, InputArray registeredDistCoeffs, + InputArray Rt, InputArray unregisteredDepth, const Size& outputImagePlaneSize, + OutputArray registeredDepth, bool depthDilation=false); + + /** + * @param depth the depth image + * @param in_K + * @param in_points the list of xy coordinates + * @param points3d the resulting 3d points + */ + CV_EXPORTS_W + void + depthTo3dSparse(InputArray depth, InputArray in_K, InputArray in_points, OutputArray points3d); + + /** Converts a depth image to an organized set of 3d points. + * The coordinate system is x pointing left, y down and z away from the camera + * @param depth the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters + * (as done with the Microsoft Kinect), otherwise, if given as CV_32F or CV_64F, it is assumed in meters) + * @param K The calibration matrix + * @param points3d the resulting 3d points. They are of depth the same as `depth` if it is CV_32F or CV_64F, and the + * depth of `K` if `depth` is of depth CV_U + * @param mask the mask of the points to consider (can be empty) + */ + CV_EXPORTS_W + void + depthTo3d(InputArray depth, InputArray K, OutputArray points3d, InputArray mask = noArray()); + + /** If the input image is of type CV_16UC1 (like the Kinect one), the image is converted to floats, divided + * by 1000 to get a depth in meters, and the values 0 are converted to std::numeric_limits<float>::quiet_NaN() + * Otherwise, the image is simply converted to floats + * @param in the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters + * (as done with the Microsoft Kinect), it is assumed in meters) + * @param depth the desired output depth (floats or double) + * @param out The rescaled float depth image + */ + CV_EXPORTS_W + void + rescaleDepth(InputArray in, int depth, OutputArray out); + + /** Object that can compute planes in an image + */ + class CV_EXPORTS_W RgbdPlane: public Algorithm + { + public: + enum RGBD_PLANE_METHOD + { + RGBD_PLANE_METHOD_DEFAULT + }; + + RgbdPlane(int method = RgbdPlane::RGBD_PLANE_METHOD_DEFAULT) + : + method_(method), + block_size_(40), + min_size_(block_size_*block_size_), + threshold_(0.01), + sensor_error_a_(0), + sensor_error_b_(0), + sensor_error_c_(0) + { + } + + /** Find The planes in a depth image + * @param points3d the 3d points organized like the depth image: rows x cols with 3 channels + * @param normals the normals for every point in the depth image + * @param mask An image where each pixel is labeled with the plane it belongs to + * and 255 if it does not belong to any plane + * @param plane_coefficients the coefficients of the corresponding planes (a,b,c,d) such that ax+by+cz+d=0, norm(a,b,c)=1 + * and c < 0 (so that the normal points towards the camera) + */ + CV_WRAP_AS(apply) void + operator()(InputArray points3d, InputArray normals, OutputArray mask, + OutputArray plane_coefficients); + + /** Find The planes in a depth image but without doing a normal check, which is faster but less accurate + * @param points3d the 3d points organized like the depth image: rows x cols with 3 channels + * @param mask An image where each pixel is labeled with the plane it belongs to + * and 255 if it does not belong to any plane + * @param plane_coefficients the coefficients of the corresponding planes (a,b,c,d) such that ax+by+cz+d=0 + */ + CV_WRAP_AS(apply) void + operator()(InputArray points3d, OutputArray mask, OutputArray plane_coefficients); + + CV_WRAP int getBlockSize() const + { + return block_size_; + } + CV_WRAP void setBlockSize(int val) + { + block_size_ = val; + } + CV_WRAP int getMinSize() const + { + return min_size_; + } + CV_WRAP void setMinSize(int val) + { + min_size_ = val; + } + CV_WRAP int getMethod() const + { + return method_; + } + CV_WRAP void setMethod(int val) + { + method_ = val; + } + CV_WRAP double getThreshold() const + { + return threshold_; + } + CV_WRAP void setThreshold(double val) + { + threshold_ = val; + } + CV_WRAP double getSensorErrorA() const + { + return sensor_error_a_; + } + CV_WRAP void setSensorErrorA(double val) + { + sensor_error_a_ = val; + } + CV_WRAP double getSensorErrorB() const + { + return sensor_error_b_; + } + CV_WRAP void setSensorErrorB(double val) + { + sensor_error_b_ = val; + } + CV_WRAP double getSensorErrorC() const + { + return sensor_error_c_; + } + CV_WRAP void setSensorErrorC(double val) + { + sensor_error_c_ = val; + } + + private: + /** The method to use to compute the planes */ + int method_; + /** The size of the blocks to look at for a stable MSE */ + int block_size_; + /** The minimum size of a cluster to be considered a plane */ + int min_size_; + /** How far a point can be from a plane to belong to it (in meters) */ + double threshold_; + /** coefficient of the sensor error with respect to the. All 0 by default but you want a=0.0075 for a Kinect */ + double sensor_error_a_, sensor_error_b_, sensor_error_c_; + }; + + /** Object that contains a frame data. + */ + struct CV_EXPORTS_W RgbdFrame + { + RgbdFrame(); + RgbdFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + virtual ~RgbdFrame(); + + CV_WRAP static Ptr<RgbdFrame> create(const Mat& image=Mat(), const Mat& depth=Mat(), const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + + CV_WRAP virtual void + release(); + + CV_PROP int ID; + CV_PROP Mat image; + CV_PROP Mat depth; + CV_PROP Mat mask; + CV_PROP Mat normals; + }; + + /** Object that contains a frame data that is possibly needed for the Odometry. + * It's used for the efficiency (to pass precomputed/cached data of the frame that participates + * in the Odometry processing several times). + */ + struct CV_EXPORTS_W OdometryFrame : public RgbdFrame + { + /** These constants are used to set a type of cache which has to be prepared depending on the frame role: + * srcFrame or dstFrame (see compute method of the Odometry class). For the srcFrame and dstFrame different cache data may be required, + * some part of a cache may be common for both frame roles. + * @param CACHE_SRC The cache data for the srcFrame will be prepared. + * @param CACHE_DST The cache data for the dstFrame will be prepared. + * @param CACHE_ALL The cache data for both srcFrame and dstFrame roles will be computed. + */ + enum + { + CACHE_SRC = 1, CACHE_DST = 2, CACHE_ALL = CACHE_SRC + CACHE_DST + }; + + OdometryFrame(); + OdometryFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + + CV_WRAP static Ptr<OdometryFrame> create(const Mat& image=Mat(), const Mat& depth=Mat(), const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + + CV_WRAP virtual void + release() CV_OVERRIDE; + + CV_WRAP void + releasePyramids(); + + CV_PROP std::vector<Mat> pyramidImage; + CV_PROP std::vector<Mat> pyramidDepth; + CV_PROP std::vector<Mat> pyramidMask; + + CV_PROP std::vector<Mat> pyramidCloud; + + CV_PROP std::vector<Mat> pyramid_dI_dx; + CV_PROP std::vector<Mat> pyramid_dI_dy; + CV_PROP std::vector<Mat> pyramidTexturedMask; + + CV_PROP std::vector<Mat> pyramidNormals; + CV_PROP std::vector<Mat> pyramidNormalsMask; + }; + + /** Base class for computation of odometry. + */ + class CV_EXPORTS_W Odometry: public Algorithm + { + public: + + /** A class of transformation*/ + enum + { + ROTATION = 1, TRANSLATION = 2, RIGID_BODY_MOTION = 4 + }; + + CV_WRAP static inline float + DEFAULT_MIN_DEPTH() + { + return 0.f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_DEPTH() + { + return 4.f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_DEPTH_DIFF() + { + return 0.07f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_POINTS_PART() + { + return 0.07f; // in [0, 1] + } + CV_WRAP static inline float + DEFAULT_MAX_TRANSLATION() + { + return 0.15f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_ROTATION() + { + return 15; // in degrees + } + + /** Method to compute a transformation from the source frame to the destination one. + * Some odometry algorithms do not used some data of frames (eg. ICP does not use images). + * In such case corresponding arguments can be set as empty Mat. + * The method returns true if all internal computions were possible (e.g. there were enough correspondences, + * system of equations has a solution, etc) and resulting transformation satisfies some test if it's provided + * by the Odometry inheritor implementation (e.g. thresholds for maximum translation and rotation). + * @param srcImage Image data of the source frame (CV_8UC1) + * @param srcDepth Depth data of the source frame (CV_32FC1, in meters) + * @param srcMask Mask that sets which pixels have to be used from the source frame (CV_8UC1) + * @param dstImage Image data of the destination frame (CV_8UC1) + * @param dstDepth Depth data of the destination frame (CV_32FC1, in meters) + * @param dstMask Mask that sets which pixels have to be used from the destination frame (CV_8UC1) + * @param Rt Resulting transformation from the source frame to the destination one (rigid body motion): + dst_p = Rt * src_p, where dst_p is a homogeneous point in the destination frame and src_p is + homogeneous point in the source frame, + Rt is 4x4 matrix of CV_64FC1 type. + * @param initRt Initial transformation from the source frame to the destination one (optional) + */ + CV_WRAP bool + compute(const Mat& srcImage, const Mat& srcDepth, const Mat& srcMask, const Mat& dstImage, const Mat& dstDepth, + const Mat& dstMask, OutputArray Rt, const Mat& initRt = Mat()) const; + + /** One more method to compute a transformation from the source frame to the destination one. + * It is designed to save on computing the frame data (image pyramids, normals, etc.). + */ + CV_WRAP_AS(compute2) bool + compute(Ptr<OdometryFrame>& srcFrame, Ptr<OdometryFrame>& dstFrame, OutputArray Rt, const Mat& initRt = Mat()) const; + + /** Prepare a cache for the frame. The function checks the precomputed/passed data (throws the error if this data + * does not satisfy) and computes all remaining cache data needed for the frame. Returned size is a resolution + * of the prepared frame. + * @param frame The odometry which will process the frame. + * @param cacheType The cache type: CACHE_SRC, CACHE_DST or CACHE_ALL. + */ + CV_WRAP virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const; + + CV_WRAP static Ptr<Odometry> create(const String & odometryType); + + /** @see setCameraMatrix */ + CV_WRAP virtual cv::Mat getCameraMatrix() const = 0; + /** @copybrief getCameraMatrix @see getCameraMatrix */ + CV_WRAP virtual void setCameraMatrix(const cv::Mat &val) = 0; + /** @see setTransformType */ + CV_WRAP virtual int getTransformType() const = 0; + /** @copybrief getTransformType @see getTransformType */ + CV_WRAP virtual void setTransformType(int val) = 0; + + protected: + virtual void + checkParams() const = 0; + + virtual bool + computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, OutputArray Rt, + const Mat& initRt) const = 0; + }; + + /** Odometry based on the paper "Real-Time Visual Odometry from Dense RGB-D Images", + * F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011. + */ + class CV_EXPORTS_W RgbdOdometry: public Odometry + { + public: + RgbdOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param minDepth Pixels with depth less than minDepth will not be used (in meters) + * @param maxDepth Pixels with depth larger than maxDepth will not be used (in meters) + * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff (in meters) + * @param iterCounts Count of iterations on each pyramid level. + * @param minGradientMagnitudes For each pyramid level the pixels will be filtered out + * if they have gradient magnitude less than minGradientMagnitudes[level]. + * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart + * @param transformType Class of transformation + */ + RgbdOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), const std::vector<int>& iterCounts = std::vector<int>(), + const std::vector<float>& minGradientMagnitudes = std::vector<float>(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP static Ptr<RgbdOdometry> create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), const std::vector<int>& iterCounts = std::vector<int>(), + const std::vector<float>& minGradientMagnitudes = std::vector<float>(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMinDepth() const + { + return minDepth; + } + CV_WRAP void setMinDepth(double val) + { + minDepth = val; + } + CV_WRAP double getMaxDepth() const + { + return maxDepth; + } + CV_WRAP void setMaxDepth(double val) + { + maxDepth = val; + } + CV_WRAP double getMaxDepthDiff() const + { + return maxDepthDiff; + } + CV_WRAP void setMaxDepthDiff(double val) + { + maxDepthDiff = val; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP cv::Mat getMinGradientMagnitudes() const + { + return minGradientMagnitudes; + } + CV_WRAP void setMinGradientMagnitudes(const cv::Mat &val) + { + minGradientMagnitudes = val; + } + CV_WRAP double getMaxPointsPart() const + { + return maxPointsPart; + } + CV_WRAP void setMaxPointsPart(double val) + { + maxPointsPart = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return transformType; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + transformType = val; + } + CV_WRAP double getMaxTranslation() const + { + return maxTranslation; + } + CV_WRAP void setMaxTranslation(double val) + { + maxTranslation = val; + } + CV_WRAP double getMaxRotation() const + { + return maxRotation; + } + CV_WRAP void setMaxRotation(double val) + { + maxRotation = val; + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + /*float*/ + double minDepth, maxDepth, maxDepthDiff; + /*vector<int>*/ + Mat iterCounts; + /*vector<float>*/ + Mat minGradientMagnitudes; + double maxPointsPart; + + Mat cameraMatrix; + int transformType; + + double maxTranslation, maxRotation; + }; + + /** Odometry based on the paper "KinectFusion: Real-Time Dense Surface Mapping and Tracking", + * Richard A. Newcombe, Andrew Fitzgibbon, at al, SIGGRAPH, 2011. + */ + class CV_EXPORTS_W ICPOdometry: public Odometry + { + public: + ICPOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param minDepth Pixels with depth less than minDepth will not be used + * @param maxDepth Pixels with depth larger than maxDepth will not be used + * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff + * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart + * @param iterCounts Count of iterations on each pyramid level. + * @param transformType Class of trasformation + */ + ICPOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector<int>& iterCounts = std::vector<int>(), int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP static Ptr<ICPOdometry> create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector<int>& iterCounts = std::vector<int>(), int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMinDepth() const + { + return minDepth; + } + CV_WRAP void setMinDepth(double val) + { + minDepth = val; + } + CV_WRAP double getMaxDepth() const + { + return maxDepth; + } + CV_WRAP void setMaxDepth(double val) + { + maxDepth = val; + } + CV_WRAP double getMaxDepthDiff() const + { + return maxDepthDiff; + } + CV_WRAP void setMaxDepthDiff(double val) + { + maxDepthDiff = val; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP double getMaxPointsPart() const + { + return maxPointsPart; + } + CV_WRAP void setMaxPointsPart(double val) + { + maxPointsPart = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return transformType; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + transformType = val; + } + CV_WRAP double getMaxTranslation() const + { + return maxTranslation; + } + CV_WRAP void setMaxTranslation(double val) + { + maxTranslation = val; + } + CV_WRAP double getMaxRotation() const + { + return maxRotation; + } + CV_WRAP void setMaxRotation(double val) + { + maxRotation = val; + } + CV_WRAP Ptr<RgbdNormals> getNormalsComputer() const + { + return normalsComputer; + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + /*float*/ + double minDepth, maxDepth, maxDepthDiff; + /*float*/ + double maxPointsPart; + /*vector<int>*/ + Mat iterCounts; + + Mat cameraMatrix; + int transformType; + + double maxTranslation, maxRotation; + + mutable Ptr<RgbdNormals> normalsComputer; + }; + + /** Odometry that merges RgbdOdometry and ICPOdometry by minimize sum of their energy functions. + */ + + class CV_EXPORTS_W RgbdICPOdometry: public Odometry + { + public: + RgbdICPOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param minDepth Pixels with depth less than minDepth will not be used + * @param maxDepth Pixels with depth larger than maxDepth will not be used + * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff + * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart + * @param iterCounts Count of iterations on each pyramid level. + * @param minGradientMagnitudes For each pyramid level the pixels will be filtered out + * if they have gradient magnitude less than minGradientMagnitudes[level]. + * @param transformType Class of trasformation + */ + RgbdICPOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector<int>& iterCounts = std::vector<int>(), + const std::vector<float>& minGradientMagnitudes = std::vector<float>(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP static Ptr<RgbdICPOdometry> create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector<int>& iterCounts = std::vector<int>(), + const std::vector<float>& minGradientMagnitudes = std::vector<float>(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMinDepth() const + { + return minDepth; + } + CV_WRAP void setMinDepth(double val) + { + minDepth = val; + } + CV_WRAP double getMaxDepth() const + { + return maxDepth; + } + CV_WRAP void setMaxDepth(double val) + { + maxDepth = val; + } + CV_WRAP double getMaxDepthDiff() const + { + return maxDepthDiff; + } + CV_WRAP void setMaxDepthDiff(double val) + { + maxDepthDiff = val; + } + CV_WRAP double getMaxPointsPart() const + { + return maxPointsPart; + } + CV_WRAP void setMaxPointsPart(double val) + { + maxPointsPart = val; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP cv::Mat getMinGradientMagnitudes() const + { + return minGradientMagnitudes; + } + CV_WRAP void setMinGradientMagnitudes(const cv::Mat &val) + { + minGradientMagnitudes = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return transformType; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + transformType = val; + } + CV_WRAP double getMaxTranslation() const + { + return maxTranslation; + } + CV_WRAP void setMaxTranslation(double val) + { + maxTranslation = val; + } + CV_WRAP double getMaxRotation() const + { + return maxRotation; + } + CV_WRAP void setMaxRotation(double val) + { + maxRotation = val; + } + CV_WRAP Ptr<RgbdNormals> getNormalsComputer() const + { + return normalsComputer; + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + /*float*/ + double minDepth, maxDepth, maxDepthDiff; + /*float*/ + double maxPointsPart; + /*vector<int>*/ + Mat iterCounts; + /*vector<float>*/ + Mat minGradientMagnitudes; + + Mat cameraMatrix; + int transformType; + + double maxTranslation, maxRotation; + + mutable Ptr<RgbdNormals> normalsComputer; + }; + + /** Warp the image: compute 3d points from the depth, transform them using given transformation, + * then project color point cloud to an image plane. + * This function can be used to visualize results of the Odometry algorithm. + * @param image The image (of CV_8UC1 or CV_8UC3 type) + * @param depth The depth (of type used in depthTo3d fuction) + * @param mask The mask of used pixels (of CV_8UC1), it can be empty + * @param Rt The transformation that will be applied to the 3d points computed from the depth + * @param cameraMatrix Camera matrix + * @param distCoeff Distortion coefficients + * @param warpedImage The warped image. + * @param warpedDepth The warped depth. + * @param warpedMask The warped mask. + */ + CV_EXPORTS_W + void + warpFrame(const Mat& image, const Mat& depth, const Mat& mask, const Mat& Rt, const Mat& cameraMatrix, + const Mat& distCoeff, OutputArray warpedImage, OutputArray warpedDepth = noArray(), OutputArray warpedMask = noArray()); + +// TODO Depth interpolation +// Curvature +// Get rescaleDepth return dubles if asked for + +//! @} + +} /* namespace rgbd */ +} /* namespace cv */ + +#include "opencv2/rgbd/linemod.hpp" + +#endif /* __cplusplus */ +#endif + +/* End of file. */ + diff --git a/include/opencv2/rgbd/linemod.hpp b/include/opencv2/rgbd/linemod.hpp new file mode 100644 index 0000000..95eed96 --- /dev/null +++ b/include/opencv2/rgbd/linemod.hpp @@ -0,0 +1,463 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_OBJDETECT_LINEMOD_HPP__ +#define __OPENCV_OBJDETECT_LINEMOD_HPP__ + +#include "opencv2/core.hpp" +#include <map> + +/****************************************************************************************\ +* LINE-MOD * +\****************************************************************************************/ + +namespace cv { +namespace linemod { + +//! @addtogroup rgbd +//! @{ + +/** + * \brief Discriminant feature described by its location and label. + */ +struct CV_EXPORTS_W_SIMPLE Feature +{ + CV_PROP_RW int x; ///< x offset + CV_PROP_RW int y; ///< y offset + CV_PROP_RW int label; ///< Quantization + + CV_WRAP Feature() : x(0), y(0), label(0) {} + CV_WRAP Feature(int x, int y, int label); + + void read(const FileNode& fn); + void write(FileStorage& fs) const; +}; + +inline Feature::Feature(int _x, int _y, int _label) : x(_x), y(_y), label(_label) {} + +struct CV_EXPORTS_W_SIMPLE Template +{ + CV_PROP int width; + CV_PROP int height; + CV_PROP int pyramid_level; + CV_PROP std::vector<Feature> features; + + void read(const FileNode& fn); + void write(FileStorage& fs) const; +}; + +/** + * \brief Represents a modality operating over an image pyramid. + */ +class CV_EXPORTS_W QuantizedPyramid +{ +public: + // Virtual destructor + virtual ~QuantizedPyramid() {} + + /** + * \brief Compute quantized image at current pyramid level for online detection. + * + * \param[out] dst The destination 8-bit image. For each pixel at most one bit is set, + * representing its classification. + */ + CV_WRAP virtual void quantize(CV_OUT Mat& dst) const =0; + + /** + * \brief Extract most discriminant features at current pyramid level to form a new template. + * + * \param[out] templ The new template. + */ + CV_WRAP virtual bool extractTemplate(CV_OUT Template& templ) const =0; + + /** + * \brief Go to the next pyramid level. + * + * \todo Allow pyramid scale factor other than 2 + */ + CV_WRAP virtual void pyrDown() =0; + +protected: + /// Candidate feature with a score + struct Candidate + { + Candidate(int x, int y, int label, float score); + + /// Sort candidates with high score to the front + bool operator<(const Candidate& rhs) const + { + return score > rhs.score; + } + + Feature f; + float score; + }; + + /** + * \brief Choose candidate features so that they are not bunched together. + * + * \param[in] candidates Candidate features sorted by score. + * \param[out] features Destination vector of selected features. + * \param[in] num_features Number of candidates to select. + * \param[in] distance Hint for desired distance between features. + */ + static void selectScatteredFeatures(const std::vector<Candidate>& candidates, + std::vector<Feature>& features, + size_t num_features, float distance); +}; + +inline QuantizedPyramid::Candidate::Candidate(int x, int y, int label, float _score) : f(x, y, label), score(_score) {} + +/** + * \brief Interface for modalities that plug into the LINE template matching representation. + * + * \todo Max response, to allow optimization of summing (255/MAX) features as uint8 + */ +class CV_EXPORTS_W Modality +{ +public: + // Virtual destructor + virtual ~Modality() {} + + /** + * \brief Form a quantized image pyramid from a source image. + * + * \param[in] src The source image. Type depends on the modality. + * \param[in] mask Optional mask. If not empty, unmasked pixels are set to zero + * in quantized image and cannot be extracted as features. + */ + CV_WRAP Ptr<QuantizedPyramid> process(const Mat& src, + const Mat& mask = Mat()) const + { + return processImpl(src, mask); + } + + CV_WRAP virtual String name() const =0; + + CV_WRAP virtual void read(const FileNode& fn) =0; + virtual void write(FileStorage& fs) const =0; + + /** + * \brief Create modality by name. + * + * The following modality types are supported: + * - "ColorGradient" + * - "DepthNormal" + */ + CV_WRAP static Ptr<Modality> create(const String& modality_type); + + /** + * \brief Load a modality from file. + */ + CV_WRAP static Ptr<Modality> create(const FileNode& fn); + +protected: + // Indirection is because process() has a default parameter. + virtual Ptr<QuantizedPyramid> processImpl(const Mat& src, + const Mat& mask) const =0; +}; + +/** + * \brief Modality that computes quantized gradient orientations from a color image. + */ +class CV_EXPORTS_W ColorGradient : public Modality +{ +public: + /** + * \brief Default constructor. Uses reasonable default parameter values. + */ + ColorGradient(); + + /** + * \brief Constructor. + * + * \param weak_threshold When quantizing, discard gradients with magnitude less than this. + * \param num_features How many features a template must contain. + * \param strong_threshold Consider as candidate features only gradients whose norms are + * larger than this. + */ + ColorGradient(float weak_threshold, size_t num_features, float strong_threshold); + + CV_WRAP static Ptr<ColorGradient> create(float weak_threshold, size_t num_features, float strong_threshold); + + virtual String name() const CV_OVERRIDE; + + virtual void read(const FileNode& fn) CV_OVERRIDE; + virtual void write(FileStorage& fs) const CV_OVERRIDE; + + CV_PROP float weak_threshold; + CV_PROP size_t num_features; + CV_PROP float strong_threshold; + +protected: + virtual Ptr<QuantizedPyramid> processImpl(const Mat& src, + const Mat& mask) const CV_OVERRIDE; +}; + +/** + * \brief Modality that computes quantized surface normals from a dense depth map. + */ +class CV_EXPORTS_W DepthNormal : public Modality +{ +public: + /** + * \brief Default constructor. Uses reasonable default parameter values. + */ + DepthNormal(); + + /** + * \brief Constructor. + * + * \param distance_threshold Ignore pixels beyond this distance. + * \param difference_threshold When computing normals, ignore contributions of pixels whose + * depth difference with the central pixel is above this threshold. + * \param num_features How many features a template must contain. + * \param extract_threshold Consider as candidate feature only if there are no differing + * orientations within a distance of extract_threshold. + */ + DepthNormal(int distance_threshold, int difference_threshold, size_t num_features, + int extract_threshold); + + CV_WRAP static Ptr<DepthNormal> create(int distance_threshold, int difference_threshold, + size_t num_features, int extract_threshold); + + virtual String name() const CV_OVERRIDE; + + virtual void read(const FileNode& fn) CV_OVERRIDE; + virtual void write(FileStorage& fs) const CV_OVERRIDE; + + CV_PROP int distance_threshold; + CV_PROP int difference_threshold; + CV_PROP size_t num_features; + CV_PROP int extract_threshold; + +protected: + virtual Ptr<QuantizedPyramid> processImpl(const Mat& src, + const Mat& mask) const CV_OVERRIDE; +}; + +/** + * \brief Debug function to colormap a quantized image for viewing. + */ +CV_EXPORTS_W void colormap(const Mat& quantized, CV_OUT Mat& dst); + +/** + * \brief Represents a successful template match. + */ +struct CV_EXPORTS_W_SIMPLE Match +{ + CV_WRAP Match() + { + } + + CV_WRAP Match(int x, int y, float similarity, const String& class_id, int template_id); + + /// Sort matches with high similarity to the front + bool operator<(const Match& rhs) const + { + // Secondarily sort on template_id for the sake of duplicate removal + if (similarity != rhs.similarity) + return similarity > rhs.similarity; + else + return template_id < rhs.template_id; + } + + bool operator==(const Match& rhs) const + { + return x == rhs.x && y == rhs.y && similarity == rhs.similarity && class_id == rhs.class_id; + } + + CV_PROP_RW int x; + CV_PROP_RW int y; + CV_PROP_RW float similarity; + CV_PROP_RW String class_id; + CV_PROP_RW int template_id; +}; + +inline +Match::Match(int _x, int _y, float _similarity, const String& _class_id, int _template_id) + : x(_x), y(_y), similarity(_similarity), class_id(_class_id), template_id(_template_id) +{} + +/** + * \brief Object detector using the LINE template matching algorithm with any set of + * modalities. + */ +class CV_EXPORTS_W Detector +{ +public: + /** + * \brief Empty constructor, initialize with read(). + */ + CV_WRAP Detector(); + + /** + * \brief Constructor. + * + * \param modalities Modalities to use (color gradients, depth normals, ...). + * \param T_pyramid Value of the sampling step T at each pyramid level. The + * number of pyramid levels is T_pyramid.size(). + */ + CV_WRAP Detector(const std::vector< Ptr<Modality> >& modalities, const std::vector<int>& T_pyramid); + + /** + * \brief Detect objects by template matching. + * + * Matches globally at the lowest pyramid level, then refines locally stepping up the pyramid. + * + * \param sources Source images, one for each modality. + * \param threshold Similarity threshold, a percentage between 0 and 100. + * \param[out] matches Template matches, sorted by similarity score. + * \param class_ids If non-empty, only search for the desired object classes. + * \param[out] quantized_images Optionally return vector<Mat> of quantized images. + * \param masks The masks for consideration during matching. The masks should be CV_8UC1 + * where 255 represents a valid pixel. If non-empty, the vector must be + * the same size as sources. Each element must be + * empty or the same size as its corresponding source. + */ + CV_WRAP void match(const std::vector<Mat>& sources, float threshold, CV_OUT std::vector<Match>& matches, + const std::vector<String>& class_ids = std::vector<String>(), + OutputArrayOfArrays quantized_images = noArray(), + const std::vector<Mat>& masks = std::vector<Mat>()) const; + + /** + * \brief Add new object template. + * + * \param sources Source images, one for each modality. + * \param class_id Object class ID. + * \param object_mask Mask separating object from background. + * \param[out] bounding_box Optionally return bounding box of the extracted features. + * + * \return Template ID, or -1 if failed to extract a valid template. + */ + CV_WRAP int addTemplate(const std::vector<Mat>& sources, const String& class_id, + const Mat& object_mask, CV_OUT Rect* bounding_box = NULL); + + /** + * \brief Add a new object template computed by external means. + */ + CV_WRAP int addSyntheticTemplate(const std::vector<Template>& templates, const String& class_id); + + /** + * \brief Get the modalities used by this detector. + * + * You are not permitted to add/remove modalities, but you may dynamic_cast them to + * tweak parameters. + */ + CV_WRAP const std::vector< Ptr<Modality> >& getModalities() const { return modalities; } + + /** + * \brief Get sampling step T at pyramid_level. + */ + CV_WRAP int getT(int pyramid_level) const { return T_at_level[pyramid_level]; } + + /** + * \brief Get number of pyramid levels used by this detector. + */ + CV_WRAP int pyramidLevels() const { return pyramid_levels; } + + /** + * \brief Get the template pyramid identified by template_id. + * + * For example, with 2 modalities (Gradient, Normal) and two pyramid levels + * (L0, L1), the order is (GradientL0, NormalL0, GradientL1, NormalL1). + */ + CV_WRAP const std::vector<Template>& getTemplates(const String& class_id, int template_id) const; + + CV_WRAP int numTemplates() const; + CV_WRAP int numTemplates(const String& class_id) const; + CV_WRAP int numClasses() const { return static_cast<int>(class_templates.size()); } + + CV_WRAP std::vector<String> classIds() const; + + CV_WRAP void read(const FileNode& fn); + void write(FileStorage& fs) const; + + String readClass(const FileNode& fn, const String &class_id_override = ""); + void writeClass(const String& class_id, FileStorage& fs) const; + + CV_WRAP void readClasses(const std::vector<String>& class_ids, + const String& format = "templates_%s.yml.gz"); + CV_WRAP void writeClasses(const String& format = "templates_%s.yml.gz") const; + +protected: + std::vector< Ptr<Modality> > modalities; + int pyramid_levels; + std::vector<int> T_at_level; + + typedef std::vector<Template> TemplatePyramid; + typedef std::map<String, std::vector<TemplatePyramid> > TemplatesMap; + TemplatesMap class_templates; + + typedef std::vector<Mat> LinearMemories; + // Indexed as [pyramid level][modality][quantized label] + typedef std::vector< std::vector<LinearMemories> > LinearMemoryPyramid; + + void matchClass(const LinearMemoryPyramid& lm_pyramid, + const std::vector<Size>& sizes, + float threshold, std::vector<Match>& matches, + const String& class_id, + const std::vector<TemplatePyramid>& template_pyramids) const; +}; + +/** + * \brief Factory function for detector using LINE algorithm with color gradients. + * + * Default parameter settings suitable for VGA images. + */ +CV_EXPORTS_W Ptr<linemod::Detector> getDefaultLINE(); + +/** + * \brief Factory function for detector using LINE-MOD algorithm with color gradients + * and depth normals. + * + * Default parameter settings suitable for VGA images. + */ +CV_EXPORTS_W Ptr<linemod::Detector> getDefaultLINEMOD(); + +//! @} + +} // namespace linemod +} // namespace cv + +#endif // __OPENCV_OBJDETECT_LINEMOD_HPP__ diff --git a/include/opencv2/saliency.hpp b/include/opencv2/saliency.hpp new file mode 100644 index 0000000..56bfe8a --- /dev/null +++ b/include/opencv2/saliency.hpp @@ -0,0 +1,83 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2014, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_SALIENCY_HPP__ +#define __OPENCV_SALIENCY_HPP__ + +#include "opencv2/saliency/saliencyBaseClasses.hpp" +#include "opencv2/saliency/saliencySpecializedClasses.hpp" + +/** @defgroup saliency Saliency API + +Many computer vision applications may benefit from understanding where humans focus given a scene. +Other than cognitively understanding the way human perceive images and scenes, finding salient +regions and objects in the images helps various tasks such as speeding up object detection, object +recognition, object tracking and content-aware image editing. + +About the saliency, there is a rich literature but the development is very fragmented. The principal +purpose of this API is to give a unique interface, a unique framework for use and plug sever +saliency algorithms, also with very different nature and methodology, but they share the same +purpose, organizing algorithms into three main categories: + +**Static Saliency**: algorithms belonging to this category, exploit different image features that +allow to detect salient objects in a non dynamic scenarios. + +**Motion Saliency**: algorithms belonging to this category, are particularly focused to detect +salient objects over time (hence also over frame), then there is a temporal component sealing +cosider that allows to detect "moving" objects as salient, meaning therefore also the more general +sense of detection the changes in the scene. + +**Objectness**: Objectness is usually represented as a value which reflects how likely an image +window covers an object of any category. Algorithms belonging to this category, avoid making +decisions early on, by proposing a small number of category-independent proposals, that are expected +to cover all objects in an image. Being able to perceive objects before identifying them is closely +related to bottom up visual attention (saliency). + +![Saliency diagram](pics/saliency.png) + +To see how API works, try tracker demo: +<https://github.com/fpuja/opencv_contrib/blob/saliencyModuleDevelop/modules/saliency/samples/computeSaliency.cpp> + +@note This API has been designed with PlantUML. If you modify this API please change UML. + +*/ + +#endif //__OPENCV_SALIENCY_HPP__ diff --git a/include/opencv2/saliency/saliencyBaseClasses.hpp b/include/opencv2/saliency/saliencyBaseClasses.hpp new file mode 100644 index 0000000..06fb4e2 --- /dev/null +++ b/include/opencv2/saliency/saliencyBaseClasses.hpp @@ -0,0 +1,133 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2014, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_SALIENCY_BASE_CLASSES_HPP__ +#define __OPENCV_SALIENCY_BASE_CLASSES_HPP__ + +#include "opencv2/core.hpp" +#include <opencv2/core/persistence.hpp> +#include "opencv2/imgproc.hpp" +#include <iostream> +#include <sstream> +#include <complex> + +namespace cv +{ +namespace saliency +{ + +//! @addtogroup saliency +//! @{ + +/************************************ Saliency Base Class ************************************/ + +class CV_EXPORTS_W Saliency : public virtual Algorithm +{ + public: + /** + * \brief Destructor + */ + virtual ~Saliency(); + + /** + * \brief Compute the saliency + * \param image The image. + * \param saliencyMap The computed saliency map. + * \return true if the saliency map is computed, false otherwise + */ + CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap ); + + protected: + + virtual bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) = 0; + String className; +}; + +/************************************ Static Saliency Base Class ************************************/ +class CV_EXPORTS_W StaticSaliency : public virtual Saliency +{ + public: + + /** @brief This function perform a binary map of given saliency map. This is obtained in this + way: + + In a first step, to improve the definition of interest areas and facilitate identification of + targets, a segmentation by clustering is performed, using *K-means algorithm*. Then, to gain a + binary representation of clustered saliency map, since values of the map can vary according to + the characteristics of frame under analysis, it is not convenient to use a fixed threshold. So, + *Otsu's algorithm* is used, which assumes that the image to be thresholded contains two classes + of pixels or bi-modal histograms (e.g. foreground and back-ground pixels); later on, the + algorithm calculates the optimal threshold separating those two classes, so that their + intra-class variance is minimal. + + @param _saliencyMap the saliency map obtained through one of the specialized algorithms + @param _binaryMap the binary map + */ + CV_WRAP bool computeBinaryMap( InputArray _saliencyMap, OutputArray _binaryMap ); + protected: + virtual bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) CV_OVERRIDE = 0; + +}; + +/************************************ Motion Saliency Base Class ************************************/ +class CV_EXPORTS_W MotionSaliency : public virtual Saliency +{ + + protected: + virtual bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) CV_OVERRIDE = 0; + +}; + +/************************************ Objectness Base Class ************************************/ +class CV_EXPORTS_W Objectness : public virtual Saliency +{ + + protected: + virtual bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) CV_OVERRIDE = 0; + +}; + +//! @} + +} /* namespace saliency */ +} /* namespace cv */ + +#endif diff --git a/include/opencv2/saliency/saliencySpecializedClasses.hpp b/include/opencv2/saliency/saliencySpecializedClasses.hpp new file mode 100644 index 0000000..c3149bf --- /dev/null +++ b/include/opencv2/saliency/saliencySpecializedClasses.hpp @@ -0,0 +1,513 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2014, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_SALIENCY_SPECIALIZED_CLASSES_HPP__ +#define __OPENCV_SALIENCY_SPECIALIZED_CLASSES_HPP__ + +#include <cstdio> +#include <string> +#include <iostream> +#include <stdint.h> +#include "saliencyBaseClasses.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ +namespace saliency +{ + +//! @addtogroup saliency +//! @{ + +/************************************ Specific Static Saliency Specialized Classes ************************************/ + +/** @brief the Spectral Residual approach from @cite SR + +Starting from the principle of natural image statistics, this method simulate the behavior of +pre-attentive visual search. The algorithm analyze the log spectrum of each image and obtain the +spectral residual. Then transform the spectral residual to spatial domain to obtain the saliency +map, which suggests the positions of proto-objects. + */ +class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency +{ +public: + + StaticSaliencySpectralResidual(); + virtual ~StaticSaliencySpectralResidual(); + + CV_WRAP static Ptr<StaticSaliencySpectralResidual> create() + { + return makePtr<StaticSaliencySpectralResidual>(); + } + + CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap ) + { + if( image.empty() ) + return false; + + return computeSaliencyImpl( image, saliencyMap ); + } + + CV_WRAP void read( const FileNode& fn ) CV_OVERRIDE; + void write( FileStorage& fs ) const CV_OVERRIDE; + + CV_WRAP int getImageWidth() const + { + return resImWidth; + } + CV_WRAP inline void setImageWidth(int val) + { + resImWidth = val; + } + CV_WRAP int getImageHeight() const + { + return resImHeight; + } + CV_WRAP void setImageHeight(int val) + { + resImHeight = val; + } + +protected: + bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) CV_OVERRIDE; + CV_PROP_RW int resImWidth; + CV_PROP_RW int resImHeight; + +}; + + +/** @brief the Fine Grained Saliency approach from @cite FGS + +This method calculates saliency based on center-surround differences. +High resolution saliency maps are generated in real time by using integral images. + */ +class CV_EXPORTS_W StaticSaliencyFineGrained : public StaticSaliency +{ +public: + + StaticSaliencyFineGrained(); + + CV_WRAP static Ptr<StaticSaliencyFineGrained> create() + { + return makePtr<StaticSaliencyFineGrained>(); + } + + CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap ) + { + if( image.empty() ) + return false; + + return computeSaliencyImpl( image, saliencyMap ); + } + virtual ~StaticSaliencyFineGrained(); + +protected: + bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) CV_OVERRIDE; + +private: + void calcIntensityChannel(Mat src, Mat dst); + void copyImage(Mat src, Mat dst); + void getIntensityScaled(Mat integralImage, Mat gray, Mat saliencyOn, Mat saliencyOff, int neighborhood); + float getMean(Mat srcArg, Point2i PixArg, int neighbourhood, int centerVal); + void mixScales(Mat *saliencyOn, Mat intensityOn, Mat *saliencyOff, Mat intensityOff, const int numScales); + void mixOnOff(Mat intensityOn, Mat intensityOff, Mat intensity); + void getIntensity(Mat srcArg, Mat dstArg, Mat dstOnArg, Mat dstOffArg, bool generateOnOff); +}; + + + + +/************************************ Specific Motion Saliency Specialized Classes ************************************/ + +/*! + * A Fast Self-tuning Background Subtraction Algorithm. + * + * This background subtraction algorithm is inspired to the work of B. Wang and P. Dudek [2] + * [2] B. Wang and P. Dudek "A Fast Self-tuning Background Subtraction Algorithm", in proc of IEEE Workshop on Change Detection, 2014 + * + */ +/** @brief the Fast Self-tuning Background Subtraction Algorithm from @cite BinWangApr2014 + */ +class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency +{ +public: + MotionSaliencyBinWangApr2014(); + virtual ~MotionSaliencyBinWangApr2014(); + + CV_WRAP static Ptr<MotionSaliencyBinWangApr2014> create() + { + return makePtr<MotionSaliencyBinWangApr2014>(); + } + + CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap ) + { + if( image.empty() ) + return false; + + return computeSaliencyImpl( image, saliencyMap ); + } + + /** @brief This is a utility function that allows to set the correct size (taken from the input image) in the + corresponding variables that will be used to size the data structures of the algorithm. + @param W width of input image + @param H height of input image + */ + CV_WRAP void setImagesize( int W, int H ); + /** @brief This function allows the correct initialization of all data structures that will be used by the + algorithm. + */ + CV_WRAP bool init(); + + CV_WRAP int getImageWidth() const + { + return imageWidth; + } + CV_WRAP inline void setImageWidth(int val) + { + imageWidth = val; + } + CV_WRAP int getImageHeight() const + { + return imageHeight; + } + CV_WRAP void setImageHeight(int val) + { + imageHeight = val; + } + +protected: + /** @brief Performs all the operations and calls all internal functions necessary for the accomplishment of the + Fast Self-tuning Background Subtraction Algorithm algorithm. + @param image input image. According to the needs of this specialized algorithm, the param image is a + single *Mat*. + @param saliencyMap Saliency Map. Is a binarized map that, in accordance with the nature of the algorithm, highlights the moving objects or areas of change in the scene. + The saliency map is given by a single *Mat* (one for each frame of an hypothetical video + stream). + */ + bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ) CV_OVERRIDE; + +private: + + // classification (and adaptation) functions + bool fullResolutionDetection( const Mat& image, Mat& highResBFMask ); + bool lowResolutionDetection( const Mat& image, Mat& lowResBFMask ); + + // Background model maintenance functions + bool templateOrdering(); + bool templateReplacement( const Mat& finalBFMask, const Mat& image ); + + // Decision threshold adaptation and Activity control function + bool activityControl(const Mat& current_noisePixelsMask); + bool decisionThresholdAdaptation(); + + // changing structure + std::vector<Ptr<Mat> > backgroundModel;// The vector represents the background template T0---TK of reference paper. + // Matrices are two-channel matrix. In the first layer there are the B (background value) + // for each pixel. In the second layer, there are the C (efficacy) value for each pixel + Mat potentialBackground;// Two channel Matrix. For each pixel, in the first level there are the Ba value (potential background value) + // and in the secon level there are the Ca value, the counter for each potential value. + Mat epslonPixelsValue;// epslon threshold + + Mat activityPixelsValue;// Activity level of each pixel + + //vector<Mat> noisePixelMask; // We define a ‘noise-pixel’ as a pixel that has been classified as a foreground pixel during the full resolution + Mat noisePixelMask;// We define a ‘noise-pixel’ as a pixel that has been classified as a foreground pixel during the full resolution + //detection process,however, after the low resolution detection, it has become a + // background pixel. The matrix is two-channel matrix. In the first layer there is the mask ( the identified noise-pixels are set to 1 while other pixels are 0) + // for each pixel. In the second layer, there is the value of activity level A for each pixel. + + //fixed parameter + bool activityControlFlag; + bool neighborhoodCheck; + int N_DS;// Number of template to be downsampled and used in lowResolutionDetection function + CV_PROP_RW int imageWidth;// Width of input image + CV_PROP_RW int imageHeight;//Height of input image + int K;// Number of background model template + int N;// NxN is the size of the block for downsampling in the lowlowResolutionDetection + float alpha;// Learning rate + int L0, L1;// Upper-bound values for C0 and C1 (efficacy of the first two template (matrices) of backgroundModel + int thetaL;// T0, T1 swap threshold + int thetaA;// Potential background value threshold + int gamma;// Parameter that controls the time that the newly updated long-term background value will remain in the + // long-term template, regardless of any subsequent background changes. A relatively large (eg gamma=3) will + //restrain the generation of ghosts. + + uchar Ainc;// Activity Incrementation; + int Bmax;// Upper-bound value for pixel activity + int Bth;// Max activity threshold + int Binc, Bdec;// Threshold for pixel-level decision threshold (epslon) adaptation + float deltaINC, deltaDEC;// Increment-decrement value for epslon adaptation + int epslonMIN, epslonMAX;// Range values for epslon threshold + +}; + +/************************************ Specific Objectness Specialized Classes ************************************/ + +/** + * \brief Objectness algorithms based on [3] + * [3] Cheng, Ming-Ming, et al. "BING: Binarized normed gradients for objectness estimation at 300fps." IEEE CVPR. 2014. + */ + +/** @brief the Binarized normed gradients algorithm from @cite BING + */ +class CV_EXPORTS_W ObjectnessBING : public Objectness +{ +public: + + ObjectnessBING(); + virtual ~ObjectnessBING(); + + CV_WRAP static Ptr<ObjectnessBING> create() + { + return makePtr<ObjectnessBING>(); + } + + CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap ) + { + if( image.empty() ) + return false; + + return computeSaliencyImpl( image, saliencyMap ); + } + + CV_WRAP void read(); + CV_WRAP void write() const; + + /** @brief Return the list of the rectangles' objectness value, + + in the same order as the *vector\<Vec4i\> objectnessBoundingBox* returned by the algorithm (in + computeSaliencyImpl function). The bigger value these scores are, it is more likely to be an + object window. + */ + CV_WRAP std::vector<float> getobjectnessValues(); + + /** @brief This is a utility function that allows to set the correct path from which the algorithm will load + the trained model. + @param trainingPath trained model path + */ + CV_WRAP void setTrainingPath( const String& trainingPath ); + + /** @brief This is a utility function that allows to set an arbitrary path in which the algorithm will save the + optional results + + (ie writing on file the total number and the list of rectangles returned by objectess, one for + each row). + @param resultsDir results' folder path + */ + CV_WRAP void setBBResDir( const String& resultsDir ); + + CV_WRAP double getBase() const + { + return _base; + } + CV_WRAP inline void setBase(double val) + { + _base = val; + } + CV_WRAP int getNSS() const + { + return _NSS; + } + CV_WRAP void setNSS(int val) + { + _NSS = val; + } + CV_WRAP int getW() const + { + return _W; + } + CV_WRAP void setW(int val) + { + _W = val; + } + +protected: + /** @brief Performs all the operations and calls all internal functions necessary for the + accomplishment of the Binarized normed gradients algorithm. + + @param image input image. According to the needs of this specialized algorithm, the param image is a + single *Mat* + @param objectnessBoundingBox objectness Bounding Box vector. According to the result given by this + specialized algorithm, the objectnessBoundingBox is a *vector\<Vec4i\>*. Each bounding box is + represented by a *Vec4i* for (minX, minY, maxX, maxY). + */ + bool computeSaliencyImpl( InputArray image, OutputArray objectnessBoundingBox ) CV_OVERRIDE; + +private: + + class FilterTIG + { + public: + void update( Mat &w ); + + // For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map + Mat matchTemplate( const Mat &mag1u ); + + float dot( int64_t tig1, int64_t tig2, int64_t tig4, int64_t tig8 ); + void reconstruct( Mat &w );// For illustration purpose + + private: + static const int NUM_COMP = 2;// Number of components + static const int D = 64;// Dimension of TIG + int64_t _bTIGs[NUM_COMP];// Binary TIG features + float _coeffs1[NUM_COMP];// Coefficients of binary TIG features + + // For efficiently deals with different bits in CV_8U gradient map + float _coeffs2[NUM_COMP], _coeffs4[NUM_COMP], _coeffs8[NUM_COMP]; + }; + + template<typename VT, typename ST> + struct ValStructVec + { + ValStructVec(); + int size() const; + void clear(); + void reserve( int resSz ); + void pushBack( const VT& val, const ST& structVal ); + const VT& operator ()( int i ) const; + const ST& operator []( int i ) const; + VT& operator ()( int i ); + ST& operator []( int i ); + + void sort( bool descendOrder = true ); + const std::vector<ST> &getSortedStructVal(); + std::vector<std::pair<VT, int> > getvalIdxes(); + void append( const ValStructVec<VT, ST> &newVals, int startV = 0 ); + + std::vector<ST> structVals; // struct values + int sz;// size of the value struct vector + std::vector<std::pair<VT, int> > valIdxes;// Indexes after sort + bool smaller() + { + return true; + } + std::vector<ST> sortedStructVals; + }; + + enum + { + MAXBGR, + HSV, + G + }; + + double _base, _logBase; // base for window size quantization + int _W;// As described in the paper: #Size, Size(_W, _H) of feature window. + int _NSS;// Size for non-maximal suppress + int _maxT, _minT, _numT;// The minimal and maximal dimensions of the template + + int _Clr;// + static const char* _clrName[3]; + +// Names and paths to read model and to store results + std::string _modelName, _bbResDir, _trainingPath, _resultsDir; + + std::vector<int> _svmSzIdxs;// Indexes of active size. It's equal to _svmFilters.size() and _svmReW1f.rows + Mat _svmFilter;// Filters learned at stage I, each is a _H by _W CV_32F matrix + FilterTIG _tigF;// TIG filter + Mat _svmReW1f;// Re-weight parameters learned at stage II. + +// List of the rectangles' objectness value, in the same order as +// the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function) + std::vector<float> objectnessValues; + +private: +// functions + + inline static float LoG( float x, float y, float delta ) + { + float d = - ( x * x + y * y ) / ( 2 * delta * delta ); + return -1.0f / ( (float) ( CV_PI ) * pow( delta, 4 ) ) * ( 1 + d ) * exp( d ); + } // Laplacian of Gaussian + +// Read matrix from binary file + static bool matRead( const std::string& filename, Mat& M ); + + void setColorSpace( int clr = MAXBGR ); + +// Load trained model. + int loadTrainedModel();// Return -1, 0, or 1 if partial, none, or all loaded + +// Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY). +// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII(). +// Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio) + void getObjBndBoxes( Mat &img3u, ValStructVec<float, Vec4i> &valBoxes, int numDetPerSize = 120 ); + void getObjBndBoxesForSingleImage( Mat img, ValStructVec<float, Vec4i> &boxes, int numDetPerSize ); + + bool filtersLoaded() + { + int n = (int) _svmSzIdxs.size(); + return n > 0 && _svmReW1f.size() == Size( 2, n ) && _svmFilter.size() == Size( _W, _W ); + } + void predictBBoxSI( Mat &mag3u, ValStructVec<float, Vec4i> &valBoxes, std::vector<int> &sz, int NUM_WIN_PSZ = 100, bool fast = true ); + void predictBBoxSII( ValStructVec<float, Vec4i> &valBoxes, const std::vector<int> &sz ); + +// Calculate the image gradient: center option as in VLFeat + void gradientMag( Mat &imgBGR3u, Mat &mag1u ); + + static void gradientRGB( Mat &bgr3u, Mat &mag1u ); + static void gradientGray( Mat &bgr3u, Mat &mag1u ); + static void gradientHSV( Mat &bgr3u, Mat &mag1u ); + static void gradientXY( Mat &x1i, Mat &y1i, Mat &mag1u ); + + static inline int bgrMaxDist( const Vec3b &u, const Vec3b &v ) + { + int b = abs( u[0] - v[0] ), g = abs( u[1] - v[1] ), r = abs( u[2] - v[2] ); + b = max( b, g ); + return max( b, r ); + } + static inline int vecDist3b( const Vec3b &u, const Vec3b &v ) + { + return abs( u[0] - v[0] ) + abs( u[1] - v[1] ) + abs( u[2] - v[2] ); + } + +//Non-maximal suppress + static void nonMaxSup( Mat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true ); + +}; + +//! @} + +} +/* namespace saliency */ +} /* namespace cv */ + +#endif diff --git a/include/opencv2/shape.hpp b/include/opencv2/shape.hpp new file mode 100644 index 0000000..f302b6b --- /dev/null +++ b/include/opencv2/shape.hpp @@ -0,0 +1,57 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_SHAPE_HPP +#define OPENCV_SHAPE_HPP + +#include "opencv2/shape/emdL1.hpp" +#include "opencv2/shape/shape_transformer.hpp" +#include "opencv2/shape/hist_cost.hpp" +#include "opencv2/shape/shape_distance.hpp" + +/** + @defgroup shape Shape Distance and Matching + */ + +#endif + +/* End of file. */ diff --git a/include/opencv2/shape/emdL1.hpp b/include/opencv2/shape/emdL1.hpp new file mode 100644 index 0000000..a15d68c --- /dev/null +++ b/include/opencv2/shape/emdL1.hpp @@ -0,0 +1,72 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_EMD_L1_HPP +#define OPENCV_EMD_L1_HPP + +#include "opencv2/core.hpp" + +namespace cv +{ +/****************************************************************************************\ +* EMDL1 Function * +\****************************************************************************************/ + +//! @addtogroup shape +//! @{ + +/** @brief Computes the "minimal work" distance between two weighted point configurations base on the papers +"EMD-L1: An efficient and Robust Algorithm for comparing histogram-based descriptors", by Haibin +Ling and Kazunori Okuda; and "The Earth Mover's Distance is the Mallows Distance: Some Insights from +Statistics", by Elizaveta Levina and Peter Bickel. + +@param signature1 First signature, a single column floating-point matrix. Each row is the value of +the histogram in each bin. +@param signature2 Second signature of the same format and size as signature1. + */ +CV_EXPORTS float EMDL1(InputArray signature1, InputArray signature2); + +//! @} + +}//namespace cv + +#endif diff --git a/include/opencv2/shape/hist_cost.hpp b/include/opencv2/shape/hist_cost.hpp new file mode 100644 index 0000000..21d0d68 --- /dev/null +++ b/include/opencv2/shape/hist_cost.hpp @@ -0,0 +1,111 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_HIST_COST_HPP +#define OPENCV_HIST_COST_HPP + +#include "opencv2/imgproc.hpp" + +namespace cv +{ + +//! @addtogroup shape +//! @{ + +/** @brief Abstract base class for histogram cost algorithms. + */ +class CV_EXPORTS_W HistogramCostExtractor : public Algorithm +{ +public: + CV_WRAP virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix) = 0; + + CV_WRAP virtual void setNDummies(int nDummies) = 0; + CV_WRAP virtual int getNDummies() const = 0; + + CV_WRAP virtual void setDefaultCost(float defaultCost) = 0; + CV_WRAP virtual float getDefaultCost() const = 0; +}; + +/** @brief A norm based cost extraction. : + */ +class CV_EXPORTS_W NormHistogramCostExtractor : public HistogramCostExtractor +{ +public: + CV_WRAP virtual void setNormFlag(int flag) = 0; + CV_WRAP virtual int getNormFlag() const = 0; +}; + +CV_EXPORTS_W Ptr<HistogramCostExtractor> + createNormHistogramCostExtractor(int flag=DIST_L2, int nDummies=25, float defaultCost=0.2f); + +/** @brief An EMD based cost extraction. : + */ +class CV_EXPORTS_W EMDHistogramCostExtractor : public HistogramCostExtractor +{ +public: + CV_WRAP virtual void setNormFlag(int flag) = 0; + CV_WRAP virtual int getNormFlag() const = 0; +}; + +CV_EXPORTS_W Ptr<HistogramCostExtractor> + createEMDHistogramCostExtractor(int flag=DIST_L2, int nDummies=25, float defaultCost=0.2f); + +/** @brief An Chi based cost extraction. : + */ +class CV_EXPORTS_W ChiHistogramCostExtractor : public HistogramCostExtractor +{}; + +CV_EXPORTS_W Ptr<HistogramCostExtractor> createChiHistogramCostExtractor(int nDummies=25, float defaultCost=0.2f); + +/** @brief An EMD-L1 based cost extraction. : + */ +class CV_EXPORTS_W EMDL1HistogramCostExtractor : public HistogramCostExtractor +{}; + +CV_EXPORTS_W Ptr<HistogramCostExtractor> + createEMDL1HistogramCostExtractor(int nDummies=25, float defaultCost=0.2f); + +//! @} + +} // cv +#endif diff --git a/include/opencv2/shape/shape.hpp b/include/opencv2/shape/shape.hpp new file mode 100644 index 0000000..5c4da3c --- /dev/null +++ b/include/opencv2/shape/shape.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/shape.hpp" diff --git a/include/opencv2/shape/shape_distance.hpp b/include/opencv2/shape/shape_distance.hpp new file mode 100644 index 0000000..725b56a --- /dev/null +++ b/include/opencv2/shape/shape_distance.hpp @@ -0,0 +1,227 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_SHAPE_SHAPE_DISTANCE_HPP +#define OPENCV_SHAPE_SHAPE_DISTANCE_HPP +#include "opencv2/core.hpp" +#include "opencv2/shape/hist_cost.hpp" +#include "opencv2/shape/shape_transformer.hpp" + +namespace cv +{ + +//! @addtogroup shape +//! @{ + +/** @example samples/cpp/shape_example.cpp +An example using shape distance algorithm +*/ +/** @brief Abstract base class for shape distance algorithms. + */ +class CV_EXPORTS_W ShapeDistanceExtractor : public Algorithm +{ +public: + /** @brief Compute the shape distance between two shapes defined by its contours. + + @param contour1 Contour defining first shape. + @param contour2 Contour defining second shape. + */ + CV_WRAP virtual float computeDistance(InputArray contour1, InputArray contour2) = 0; +}; + +/***********************************************************************************/ +/***********************************************************************************/ +/***********************************************************************************/ +/** @brief Implementation of the Shape Context descriptor and matching algorithm + +proposed by Belongie et al. in "Shape Matching and Object Recognition Using Shape Contexts" (PAMI +2002). This implementation is packaged in a generic scheme, in order to allow you the +implementation of the common variations of the original pipeline. +*/ +class CV_EXPORTS_W ShapeContextDistanceExtractor : public ShapeDistanceExtractor +{ +public: + /** @brief Establish the number of angular bins for the Shape Context Descriptor used in the shape matching + pipeline. + + @param nAngularBins The number of angular bins in the shape context descriptor. + */ + CV_WRAP virtual void setAngularBins(int nAngularBins) = 0; + CV_WRAP virtual int getAngularBins() const = 0; + + /** @brief Establish the number of radial bins for the Shape Context Descriptor used in the shape matching + pipeline. + + @param nRadialBins The number of radial bins in the shape context descriptor. + */ + CV_WRAP virtual void setRadialBins(int nRadialBins) = 0; + CV_WRAP virtual int getRadialBins() const = 0; + + /** @brief Set the inner radius of the shape context descriptor. + + @param innerRadius The value of the inner radius. + */ + CV_WRAP virtual void setInnerRadius(float innerRadius) = 0; + CV_WRAP virtual float getInnerRadius() const = 0; + + /** @brief Set the outer radius of the shape context descriptor. + + @param outerRadius The value of the outer radius. + */ + CV_WRAP virtual void setOuterRadius(float outerRadius) = 0; + CV_WRAP virtual float getOuterRadius() const = 0; + + CV_WRAP virtual void setRotationInvariant(bool rotationInvariant) = 0; + CV_WRAP virtual bool getRotationInvariant() const = 0; + + /** @brief Set the weight of the shape context distance in the final value of the shape distance. The shape + context distance between two shapes is defined as the symmetric sum of shape context matching costs + over best matching points. The final value of the shape distance is a user-defined linear + combination of the shape context distance, an image appearance distance, and a bending energy. + + @param shapeContextWeight The weight of the shape context distance in the final distance value. + */ + CV_WRAP virtual void setShapeContextWeight(float shapeContextWeight) = 0; + CV_WRAP virtual float getShapeContextWeight() const = 0; + + /** @brief Set the weight of the Image Appearance cost in the final value of the shape distance. The image + appearance cost is defined as the sum of squared brightness differences in Gaussian windows around + corresponding image points. The final value of the shape distance is a user-defined linear + combination of the shape context distance, an image appearance distance, and a bending energy. If + this value is set to a number different from 0, is mandatory to set the images that correspond to + each shape. + + @param imageAppearanceWeight The weight of the appearance cost in the final distance value. + */ + CV_WRAP virtual void setImageAppearanceWeight(float imageAppearanceWeight) = 0; + CV_WRAP virtual float getImageAppearanceWeight() const = 0; + + /** @brief Set the weight of the Bending Energy in the final value of the shape distance. The bending energy + definition depends on what transformation is being used to align the shapes. The final value of the + shape distance is a user-defined linear combination of the shape context distance, an image + appearance distance, and a bending energy. + + @param bendingEnergyWeight The weight of the Bending Energy in the final distance value. + */ + CV_WRAP virtual void setBendingEnergyWeight(float bendingEnergyWeight) = 0; + CV_WRAP virtual float getBendingEnergyWeight() const = 0; + + /** @brief Set the images that correspond to each shape. This images are used in the calculation of the Image + Appearance cost. + + @param image1 Image corresponding to the shape defined by contours1. + @param image2 Image corresponding to the shape defined by contours2. + */ + CV_WRAP virtual void setImages(InputArray image1, InputArray image2) = 0; + CV_WRAP virtual void getImages(OutputArray image1, OutputArray image2) const = 0; + + CV_WRAP virtual void setIterations(int iterations) = 0; + CV_WRAP virtual int getIterations() const = 0; + + /** @brief Set the algorithm used for building the shape context descriptor cost matrix. + + @param comparer Smart pointer to a HistogramCostExtractor, an algorithm that defines the cost + matrix between descriptors. + */ + CV_WRAP virtual void setCostExtractor(Ptr<HistogramCostExtractor> comparer) = 0; + CV_WRAP virtual Ptr<HistogramCostExtractor> getCostExtractor() const = 0; + + /** @brief Set the value of the standard deviation for the Gaussian window for the image appearance cost. + + @param sigma Standard Deviation. + */ + CV_WRAP virtual void setStdDev(float sigma) = 0; + CV_WRAP virtual float getStdDev() const = 0; + + /** @brief Set the algorithm used for aligning the shapes. + + @param transformer Smart pointer to a ShapeTransformer, an algorithm that defines the aligning + transformation. + */ + CV_WRAP virtual void setTransformAlgorithm(Ptr<ShapeTransformer> transformer) = 0; + CV_WRAP virtual Ptr<ShapeTransformer> getTransformAlgorithm() const = 0; +}; + +/* Complete constructor */ +CV_EXPORTS_W Ptr<ShapeContextDistanceExtractor> + createShapeContextDistanceExtractor(int nAngularBins=12, int nRadialBins=4, + float innerRadius=0.2f, float outerRadius=2, int iterations=3, + const Ptr<HistogramCostExtractor> &comparer = createChiHistogramCostExtractor(), + const Ptr<ShapeTransformer> &transformer = createThinPlateSplineShapeTransformer()); + +/***********************************************************************************/ +/***********************************************************************************/ +/***********************************************************************************/ +/** @brief A simple Hausdorff distance measure between shapes defined by contours + +according to the paper "Comparing Images using the Hausdorff distance." by D.P. Huttenlocher, G.A. +Klanderman, and W.J. Rucklidge. (PAMI 1993). : + */ +class CV_EXPORTS_W HausdorffDistanceExtractor : public ShapeDistanceExtractor +{ +public: + /** @brief Set the norm used to compute the Hausdorff value between two shapes. It can be L1 or L2 norm. + + @param distanceFlag Flag indicating which norm is used to compute the Hausdorff distance + (NORM_L1, NORM_L2). + */ + CV_WRAP virtual void setDistanceFlag(int distanceFlag) = 0; + CV_WRAP virtual int getDistanceFlag() const = 0; + + /** @brief This method sets the rank proportion (or fractional value) that establish the Kth ranked value of + the partial Hausdorff distance. Experimentally had been shown that 0.6 is a good value to compare + shapes. + + @param rankProportion fractional value (between 0 and 1). + */ + CV_WRAP virtual void setRankProportion(float rankProportion) = 0; + CV_WRAP virtual float getRankProportion() const = 0; +}; + +/* Constructor */ +CV_EXPORTS_W Ptr<HausdorffDistanceExtractor> createHausdorffDistanceExtractor(int distanceFlag=cv::NORM_L2, float rankProp=0.6f); + +//! @} + +} // cv +#endif diff --git a/include/opencv2/shape/shape_transformer.hpp b/include/opencv2/shape/shape_transformer.hpp new file mode 100644 index 0000000..3c3ce20 --- /dev/null +++ b/include/opencv2/shape/shape_transformer.hpp @@ -0,0 +1,132 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_SHAPE_SHAPE_TRANSFORM_HPP +#define OPENCV_SHAPE_SHAPE_TRANSFORM_HPP +#include <vector> +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" + +namespace cv +{ + +//! @addtogroup shape +//! @{ + +/** @brief Abstract base class for shape transformation algorithms. + */ +class CV_EXPORTS_W ShapeTransformer : public Algorithm +{ +public: + /** @brief Estimate the transformation parameters of the current transformer algorithm, based on point matches. + + @param transformingShape Contour defining first shape. + @param targetShape Contour defining second shape (Target). + @param matches Standard vector of Matches between points. + */ + CV_WRAP virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, + std::vector<DMatch>& matches) = 0; + + /** @brief Apply a transformation, given a pre-estimated transformation parameters. + + @param input Contour (set of points) to apply the transformation. + @param output Output contour. + */ + CV_WRAP virtual float applyTransformation(InputArray input, OutputArray output=noArray()) = 0; + + /** @brief Apply a transformation, given a pre-estimated transformation parameters, to an Image. + + @param transformingImage Input image. + @param output Output image. + @param flags Image interpolation method. + @param borderMode border style. + @param borderValue border value. + */ + CV_WRAP virtual void warpImage(InputArray transformingImage, OutputArray output, + int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, + const Scalar& borderValue=Scalar()) const = 0; +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +/** @brief Definition of the transformation + +occupied in the paper "Principal Warps: Thin-Plate Splines and Decomposition of Deformations", by +F.L. Bookstein (PAMI 1989). : + */ +class CV_EXPORTS_W ThinPlateSplineShapeTransformer : public ShapeTransformer +{ +public: + /** @brief Set the regularization parameter for relaxing the exact interpolation requirements of the TPS + algorithm. + + @param beta value of the regularization parameter. + */ + CV_WRAP virtual void setRegularizationParameter(double beta) = 0; + CV_WRAP virtual double getRegularizationParameter() const = 0; +}; + +/** Complete constructor */ +CV_EXPORTS_W Ptr<ThinPlateSplineShapeTransformer> + createThinPlateSplineShapeTransformer(double regularizationParameter=0); + +/***********************************************************************************/ +/***********************************************************************************/ + +/** @brief Wrapper class for the OpenCV Affine Transformation algorithm. : + */ +class CV_EXPORTS_W AffineTransformer : public ShapeTransformer +{ +public: + CV_WRAP virtual void setFullAffine(bool fullAffine) = 0; + CV_WRAP virtual bool getFullAffine() const = 0; +}; + +/** Complete constructor */ +CV_EXPORTS_W Ptr<AffineTransformer> createAffineTransformer(bool fullAffine); + +//! @} + +} // cv +#endif diff --git a/include/opencv2/stereo.hpp b/include/opencv2/stereo.hpp new file mode 100644 index 0000000..fc22938 --- /dev/null +++ b/include/opencv2/stereo.hpp @@ -0,0 +1,280 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_STEREO_HPP__ +#define __OPENCV_STEREO_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/core/affine.hpp" +#include "opencv2/stereo/descriptor.hpp" +#include "opencv2/stereo/matching.hpp" + +/** +@defgroup stereo Stereo Correspondance Algorithms + +*/ + +namespace cv +{ + namespace stereo + { + //! @addtogroup stereo + //! @{ + // void correctMatches( InputArray F, InputArray points1, InputArray points2, + // OutputArray newPoints1, OutputArray newPoints2 ); + /** @brief Filters off small noise blobs (speckles) in the disparity map + @param img The input 16-bit signed disparity image + @param newVal The disparity value used to paint-off the speckles + @param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not + affected by the algorithm + @param maxDiff Maximum difference between neighbor disparity pixels to put them into the same + blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point + disparity map, where disparity values are multiplied by 16, this scale factor should be taken into + account when specifying this parameter value. + @param buf The optional temporary buffer to avoid memory allocation within the function. + */ + /** @brief The base class for stereo correspondence algorithms. + */ + class StereoMatcher : public Algorithm + { + public: + enum { DISP_SHIFT = 4, + DISP_SCALE = (1 << DISP_SHIFT) + }; + + /** @brief Computes disparity map for the specified stereo pair + + @param left Left 8-bit single-channel image. + @param right Right image of the same size and the same type as the left one. + @param disparity Output disparity map. It has the same size as the input images. Some algorithms, + like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value + has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map. + */ + virtual void compute( InputArray left, InputArray right, + OutputArray disparity ) = 0; + + virtual int getMinDisparity() const = 0; + virtual void setMinDisparity(int minDisparity) = 0; + + virtual int getNumDisparities() const = 0; + virtual void setNumDisparities(int numDisparities) = 0; + + virtual int getBlockSize() const = 0; + virtual void setBlockSize(int blockSize) = 0; + + virtual int getSpeckleWindowSize() const = 0; + virtual void setSpeckleWindowSize(int speckleWindowSize) = 0; + + virtual int getSpeckleRange() const = 0; + virtual void setSpeckleRange(int speckleRange) = 0; + + virtual int getDisp12MaxDiff() const = 0; + virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0; + + }; + //!speckle removal algorithms. These algorithms have the purpose of removing small regions + enum { + CV_SPECKLE_REMOVAL_ALGORITHM, CV_SPECKLE_REMOVAL_AVG_ALGORITHM + }; + //!subpixel interpolationm methods for disparities. + enum{ + CV_QUADRATIC_INTERPOLATION, CV_SIMETRICV_INTERPOLATION + }; + /** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and + contributed to OpenCV by K. Konolige. + */ + class StereoBinaryBM : public StereoMatcher + { + public: + enum { PREFILTER_NORMALIZED_RESPONSE = 0, + PREFILTER_XSOBEL = 1 + }; + + virtual int getPreFilterType() const = 0; + virtual void setPreFilterType(int preFilterType) = 0; + + virtual int getPreFilterSize() const = 0; + virtual void setPreFilterSize(int preFilterSize) = 0; + + virtual int getPreFilterCap() const = 0; + virtual void setPreFilterCap(int preFilterCap) = 0; + + virtual int getTextureThreshold() const = 0; + virtual void setTextureThreshold(int textureThreshold) = 0; + + virtual int getUniquenessRatio() const = 0; + virtual void setUniquenessRatio(int uniquenessRatio) = 0; + + virtual int getSmallerBlockSize() const = 0; + virtual void setSmallerBlockSize(int blockSize) = 0; + + virtual int getScalleFactor() const = 0 ; + virtual void setScalleFactor(int factor) = 0; + + virtual int getSpekleRemovalTechnique() const = 0 ; + virtual void setSpekleRemovalTechnique(int factor) = 0; + + virtual bool getUsePrefilter() const = 0 ; + virtual void setUsePrefilter(bool factor) = 0; + + virtual int getBinaryKernelType() const = 0; + virtual void setBinaryKernelType(int value) = 0; + + virtual int getAgregationWindowSize() const = 0; + virtual void setAgregationWindowSize(int value) = 0; + /** @brief Creates StereoBM object + + @param numDisparities the disparity search range. For each pixel algorithm will find the best + disparity from 0 (default minimum disparity) to numDisparities. The search range can then be + shifted by changing the minimum disparity. + @param blockSize the linear size of the blocks compared by the algorithm. The size should be odd + (as the block is centered at the current pixel). Larger block size implies smoother, though less + accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher + chance for algorithm to find a wrong correspondence. + + The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for + a specific stereo pair. + */ + CV_EXPORTS static Ptr< cv::stereo::StereoBinaryBM > create(int numDisparities = 0, int blockSize = 9); + }; + + /** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original + one as follows: + + - By default, the algorithm is single-pass, which means that you consider only 5 directions + instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the + algorithm but beware that it may consume a lot of memory. + - The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the + blocks to single pixels. + - Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi + sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well. + - Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for + example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness + check, quadratic interpolation and speckle filtering). + + @note + - (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found + at opencv_source_code/samples/python2/stereo_match.py + */ + class StereoBinarySGBM : public StereoMatcher + { + public: + enum + { + MODE_SGBM = 0, + MODE_HH = 1 + }; + + virtual int getPreFilterCap() const = 0; + virtual void setPreFilterCap(int preFilterCap) = 0; + + virtual int getUniquenessRatio() const = 0; + virtual void setUniquenessRatio(int uniquenessRatio) = 0; + + virtual int getP1() const = 0; + virtual void setP1(int P1) = 0; + + virtual int getP2() const = 0; + virtual void setP2(int P2) = 0; + + virtual int getMode() const = 0; + virtual void setMode(int mode) = 0; + + virtual int getSpekleRemovalTechnique() const = 0 ; + virtual void setSpekleRemovalTechnique(int factor) = 0; + + virtual int getBinaryKernelType() const = 0; + virtual void setBinaryKernelType(int value) = 0; + + virtual int getSubPixelInterpolationMethod() const = 0; + virtual void setSubPixelInterpolationMethod(int value) = 0; + + /** @brief Creates StereoSGBM object + + @param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes + rectification algorithms can shift images, so this parameter needs to be adjusted accordingly. + @param numDisparities Maximum disparity minus minimum disparity. The value is always greater than + zero. In the current implementation, this parameter must be divisible by 16. + @param blockSize Matched block size. It must be an odd number \>=1 . Normally, it should be + somewhere in the 3..11 range. + @param P1 The first parameter controlling the disparity smoothness.This parameter is used for the case of slanted surfaces (not fronto parallel). + @param P2 The second parameter controlling the disparity smoothness.This parameter is used for "solving" the depth discontinuities problem. + The larger the values are, the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1 + between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor + pixels. The algorithm requires P2 \> P1 . See stereo_match.cpp sample where some reasonably good + P1 and P2 values are shown (like 8\*number_of_image_channels\*SADWindowSize\*SADWindowSize and + 32\*number_of_image_channels\*SADWindowSize\*SADWindowSize , respectively). + @param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right + disparity check. Set it to a non-positive value to disable the check. + @param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first + computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval. + The result values are passed to the Birchfield-Tomasi pixel cost function. + @param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function + value should "win" the second best value to consider the found match correct. Normally, a value + within the 5-15 range is good enough. + @param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles + and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the + 50-200 range. + @param speckleRange Maximum disparity variation within each connected component. If you do speckle + filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. + Normally, 1 or 2 is good enough. + @param mode Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming + algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and + huge for HD-size pictures. By default, it is set to false . + + The first constructor initializes StereoSGBM with all the default parameters. So, you only have to + set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter + to a custom value. + */ + CV_EXPORTS static Ptr<cv::stereo::StereoBinarySGBM> create(int minDisparity, int numDisparities, int blockSize, + int P1 = 100, int P2 = 1000, int disp12MaxDiff = 1, + int preFilterCap = 0, int uniquenessRatio = 5, + int speckleWindowSize = 400, int speckleRange = 200, + int mode = StereoBinarySGBM::MODE_SGBM); + }; + //! @} + }//stereo +} // cv + +#endif diff --git a/include/opencv2/stereo/descriptor.hpp b/include/opencv2/stereo/descriptor.hpp new file mode 100644 index 0000000..397fd31 --- /dev/null +++ b/include/opencv2/stereo/descriptor.hpp @@ -0,0 +1,452 @@ +//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) +// +//Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +//Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +//Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +//Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +//Copyright (C) 2015, OpenCV Foundation, all rights reserved. +//Copyright (C) 2015, Itseez Inc., all rights reserved. +//Third party copyrights are property of their respective owners. +// +//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. + +/*****************************************************************************************************************\ +* The interface contains the main descriptors that will be implemented in the descriptor class * +\*****************************************************************************************************************/ + +#include <stdint.h> +#ifndef _OPENCV_DESCRIPTOR_HPP_ +#define _OPENCV_DESCRIPTOR_HPP_ +#ifdef __cplusplus + +namespace cv +{ + namespace stereo + { + //types of supported kernels + enum { + CV_DENSE_CENSUS, CV_SPARSE_CENSUS, + CV_CS_CENSUS, CV_MODIFIED_CS_CENSUS, CV_MODIFIED_CENSUS_TRANSFORM, + CV_MEAN_VARIATION, CV_STAR_KERNEL + }; + //!Mean Variation is a robust kernel that compares a pixel + //!not just with the center but also with the mean of the window + template<int num_images> + struct MVKernel + { + uint8_t *image[num_images]; + int *integralImage[num_images]; + int stop; + MVKernel(){} + MVKernel(uint8_t **images, int **integral) + { + for(int i = 0; i < num_images; i++) + { + image[i] = images[i]; + integralImage[i] = integral[i]; + } + stop = num_images; + } + void operator()(int rrWidth,int w2, int rWidth, int jj, int j, int c[num_images]) const + { + CV_UNUSED(w2); + for (int i = 0; i < stop; i++) + { + if (image[i][rrWidth + jj] > image[i][rWidth + j]) + { + c[i] = c[i] + 1; + } + c[i] = c[i] << 1; + if (integralImage[i][rrWidth + jj] > image[i][rWidth + j]) + { + c[i] = c[i] + 1; + } + c[i] = c[i] << 1; + } + } + }; + //!Compares pixels from a patch giving high weights to pixels in which + //!the intensity is higher. The other pixels receive a lower weight + template <int num_images> + struct MCTKernel + { + uint8_t *image[num_images]; + int t,imageStop; + MCTKernel(){} + MCTKernel(uint8_t ** images, int threshold) + { + for(int i = 0; i < num_images; i++) + { + image[i] = images[i]; + } + imageStop = num_images; + t = threshold; + } + void operator()(int rrWidth,int w2, int rWidth, int jj, int j, int c[num_images]) const + { + CV_UNUSED(w2); + for(int i = 0; i < imageStop; i++) + { + if (image[i][rrWidth + jj] > image[i][rWidth + j] - t) + { + c[i] = c[i] << 1; + c[i] = c[i] + 1; + c[i] = c[i] << 1; + c[i] = c[i] + 1; + } + else if (image[i][rWidth + j] - t < image[i][rrWidth + jj] && image[i][rWidth + j] + t >= image[i][rrWidth + jj]) + { + c[i] = c[i] << 2; + c[i] = c[i] + 1; + } + else + { + c[i] <<= 2; + } + } + } + }; + //!A madified cs census that compares a pixel with the imediat neightbour starting + //!from the center + template<int num_images> + struct ModifiedCsCensus + { + uint8_t *image[num_images]; + int n2; + int imageStop; + ModifiedCsCensus(){} + ModifiedCsCensus(uint8_t **images, int ker) + { + for(int i = 0; i < num_images; i++) + image[i] = images[i]; + imageStop = num_images; + n2 = ker; + } + void operator()(int rrWidth,int w2, int rWidth, int jj, int j, int c[num_images]) const + { + CV_UNUSED(j); + CV_UNUSED(rWidth); + for(int i = 0; i < imageStop; i++) + { + if (image[i][(rrWidth + jj)] > image[i][(w2 + (jj + n2))]) + { + c[i] = c[i] + 1; + } + c[i] = c[i] * 2; + } + } + }; + //!A kernel in which a pixel is compared with the center of the window + template<int num_images> + struct CensusKernel + { + uint8_t *image[num_images]; + int imageStop; + CensusKernel(){} + CensusKernel(uint8_t **images) + { + for(int i = 0; i < num_images; i++) + image[i] = images[i]; + imageStop = num_images; + } + void operator()(int rrWidth,int w2, int rWidth, int jj, int j, int c[num_images]) const + { + CV_UNUSED(w2); + for(int i = 0; i < imageStop; i++) + { + ////compare a pixel with the center from the kernel + if (image[i][rrWidth + jj] > image[i][rWidth + j]) + { + c[i] += 1; + } + c[i] <<= 1; + } + } + }; + //template clas which efficiently combines the descriptors + template <int step_start, int step_end, int step_inc,int nr_img, typename Kernel> + class CombinedDescriptor:public ParallelLoopBody + { + private: + int width, height,n2; + int stride_; + int *dst[nr_img]; + Kernel kernel_; + int n2_stop; + public: + CombinedDescriptor(int w, int h,int stride, int k2, int **distance, Kernel kernel,int k2Stop) + { + width = w; + height = h; + n2 = k2; + stride_ = stride; + for(int i = 0; i < nr_img; i++) + dst[i] = distance[i]; + kernel_ = kernel; + n2_stop = k2Stop; + } + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end ; i++) + { + int rWidth = i * stride_; + for (int j = n2 + 2; j <= width - n2 - 2; j++) + { + int c[nr_img]; + memset(c,0,nr_img); + for(int step = step_start; step <= step_end; step += step_inc) + { + for (int ii = - n2; ii <= + n2_stop; ii += step) + { + int rrWidth = (ii + i) * stride_; + int rrWidthC = (ii + i + n2) * stride_; + for (int jj = j - n2; jj <= j + n2; jj += step) + { + if (ii != i || jj != j) + { + kernel_(rrWidth,rrWidthC, rWidth, jj, j,c); + } + } + } + } + for(int l = 0; l < nr_img; l++) + dst[l][rWidth + j] = c[l]; + } + } + } + }; + //!calculate the mean of every windowSizexWindwoSize block from the integral Image + //!this is a preprocessing for MV kernel + class MeanKernelIntegralImage : public ParallelLoopBody + { + private: + int *img; + int windowSize,width; + float scalling; + int *c; + public: + MeanKernelIntegralImage(const cv::Mat &image, int window,float scale, int *cost): + img((int *)image.data),windowSize(window) ,width(image.cols) ,scalling(scale) , c(cost){}; + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end; i++) + { + int iw = i * width; + for (int j = windowSize + 1; j <= width - windowSize - 1; j++) + { + c[iw + j] = (int)((img[(i + windowSize - 1) * width + j + windowSize - 1] + img[(i - windowSize - 1) * width + j - windowSize - 1] + - img[(i + windowSize) * width + j - windowSize] - img[(i - windowSize) * width + j + windowSize]) * scalling); + } + } + } + }; + //!implementation for the star kernel descriptor + template<int num_images> + class StarKernelCensus:public ParallelLoopBody + { + private: + uint8_t *image[num_images]; + int *dst[num_images]; + int n2, width, height, im_num,stride_; + public: + StarKernelCensus(const cv::Mat *img, int k2, int **distance) + { + for(int i = 0; i < num_images; i++) + { + image[i] = img[i].data; + dst[i] = distance[i]; + } + n2 = k2; + width = img[0].cols; + height = img[0].rows; + im_num = num_images; + stride_ = (int)img[0].step; + } + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end ; i++) + { + int rWidth = i * stride_; + for (int j = n2; j <= width - n2; j++) + { + for(int d = 0 ; d < im_num; d++) + { + int c = 0; + for(int step = 4; step > 0; step--) + { + for (int ii = i - step; ii <= i + step; ii += step) + { + int rrWidth = ii * stride_; + for (int jj = j - step; jj <= j + step; jj += step) + { + if (image[d][rrWidth + jj] > image[d][rWidth + j]) + { + c = c + 1; + } + c = c * 2; + } + } + } + for (int ii = -1; ii <= +1; ii++) + { + int rrWidth = (ii + i) * stride_; + if (i == -1) + { + if (ii + i != i) + { + if (image[d][rrWidth + j] > image[d][rWidth + j]) + { + c = c + 1; + } + c = c * 2; + } + } + else if (i == 0) + { + for (int j2 = -1; j2 <= 1; j2 += 2) + { + if (ii + i != i) + { + if (image[d][rrWidth + j + j2] > image[d][rWidth + j]) + { + c = c + 1; + } + c = c * 2; + } + } + } + else + { + if (ii + i != i) + { + if (image[d][rrWidth + j] > image[d][rWidth + j]) + { + c = c + 1; + } + c = c * 2; + } + } + } + dst[d][rWidth + j] = c; + } + } + } + } + }; + //!paralel implementation of the center symetric census + template <int num_images> + class SymetricCensus:public ParallelLoopBody + { + private: + uint8_t *image[num_images]; + int *dst[num_images]; + int n2, width, height, im_num,stride_; + public: + SymetricCensus(const cv::Mat *img, int k2, int **distance) + { + for(int i = 0; i < num_images; i++) + { + image[i] = img[i].data; + dst[i] = distance[i]; + } + n2 = k2; + width = img[0].cols; + height = img[0].rows; + im_num = num_images; + stride_ = (int)img[0].step; + } + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end ; i++) + { + int distV = i*stride_; + for (int j = n2; j <= width - n2; j++) + { + for(int d = 0; d < im_num; d++) + { + int c = 0; + //the classic center symetric census which compares the curent pixel with its symetric not its center. + for (int ii = -n2; ii <= 0; ii++) + { + int rrWidth = (ii + i) * stride_; + for (int jj = -n2; jj <= +n2; jj++) + { + if (image[d][(rrWidth + (jj + j))] > image[d][((ii * (-1) + i) * width + (-1 * jj) + j)]) + { + c = c + 1; + } + c = c * 2; + if(ii == 0 && jj < 0) + { + if (image[d][(i * width + (jj + j))] > image[d][(i * width + (-1 * jj) + j)]) + { + c = c + 1; + } + c = c * 2; + } + } + } + dst[d][(distV + j)] = c; + } + } + } + } + }; + /** + Two variations of census applied on input images + Implementation of a census transform which is taking into account just the some pixels from the census kernel thus allowing for larger block sizes + **/ + //void applyCensusOnImages(const cv::Mat &im1,const cv::Mat &im2, int kernelSize, cv::Mat &dist, cv::Mat &dist2, const int type); + CV_EXPORTS void censusTransform(const cv::Mat &image1, const cv::Mat &image2, int kernelSize, cv::Mat &dist1, cv::Mat &dist2, const int type); + //single image census transform + CV_EXPORTS void censusTransform(const cv::Mat &image1, int kernelSize, cv::Mat &dist1, const int type); + /** + STANDARD_MCT - Modified census which is memorizing for each pixel 2 bits and includes a tolerance to the pixel comparison + MCT_MEAN_VARIATION - Implementation of a modified census transform which is also taking into account the variation to the mean of the window not just the center pixel + **/ + CV_EXPORTS void modifiedCensusTransform(const cv::Mat &img1, const cv::Mat &img2, int kernelSize, cv::Mat &dist1,cv::Mat &dist2, const int type, int t = 0 , const cv::Mat &IntegralImage1 = cv::Mat::zeros(100,100,CV_8UC1), const cv::Mat &IntegralImage2 = cv::Mat::zeros(100,100,CV_8UC1)); + //single version of modified census transform descriptor + CV_EXPORTS void modifiedCensusTransform(const cv::Mat &img1, int kernelSize, cv::Mat &dist, const int type, int t = 0 ,const cv::Mat &IntegralImage = cv::Mat::zeros(100,100,CV_8UC1)); + /**The classical center symetric census + A modified version of cs census which is comparing a pixel with its correspondent after the center + **/ + CV_EXPORTS void symetricCensusTransform(const cv::Mat &img1, const cv::Mat &img2, int kernelSize, cv::Mat &dist1, cv::Mat &dist2, const int type); + //single version of census transform + CV_EXPORTS void symetricCensusTransform(const cv::Mat &img1, int kernelSize, cv::Mat &dist1, const int type); + //in a 9x9 kernel only certain positions are choosen + CV_EXPORTS void starCensusTransform(const cv::Mat &img1, const cv::Mat &img2, int kernelSize, cv::Mat &dist1,cv::Mat &dist2); + //single image version of star kernel + CV_EXPORTS void starCensusTransform(const cv::Mat &img1, int kernelSize, cv::Mat &dist); + //integral image computation used in the Mean Variation Census Transform + void imageMeanKernelSize(const cv::Mat &img, int windowSize, cv::Mat &c); + } +} +#endif +#endif +/*End of file*/ diff --git a/include/opencv2/stereo/matching.hpp b/include/opencv2/stereo/matching.hpp new file mode 100644 index 0000000..361eb18 --- /dev/null +++ b/include/opencv2/stereo/matching.hpp @@ -0,0 +1,621 @@ +//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) +// +//Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +//Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +//Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +//Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +//Copyright (C) 2015, OpenCV Foundation, all rights reserved. +//Copyright (C) 2015, Itseez Inc., all rights reserved. +//Third party copyrights are property of their respective owners. +// +//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. + +/*****************************************************************************************************************\ +* The interface contains the main methods for computing the matching between the left and right images * +* * +\******************************************************************************************************************/ +#ifndef _OPENCV_MATCHING_HPP_ +#define _OPENCV_MATCHING_HPP_ + +#include <stdint.h> +#include "opencv2/core.hpp" + +namespace cv +{ + namespace stereo + { + class Matching + { + private: + //!The maximum disparity + int maxDisparity; + //!the factor by which we are multiplying the disparity + int scallingFactor; + //!the confidence to which a min disparity found is good or not + double confidenceCheck; + //!the LUT used in case SSE is not available + int hamLut[65537]; + //!function used for getting the minimum disparity from the cost volume" + static int minim(short *c, int iwpj, int widthDisp,const double confidence, const int search_region) + { + double mini, mini2, mini3; + mini = mini2 = mini3 = DBL_MAX; + int index = 0; + int iw = iwpj; + int widthDisp2; + widthDisp2 = widthDisp; + widthDisp -= 1; + for (int i = 0; i <= widthDisp; i++) + { + if (c[(iw + i * search_region) * widthDisp2 + i] < mini) + { + mini3 = mini2; + mini2 = mini; + mini = c[(iw + i * search_region) * widthDisp2 + i]; + index = i; + } + else if (c[(iw + i * search_region) * widthDisp2 + i] < mini2) + { + mini3 = mini2; + mini2 = c[(iw + i * search_region) * widthDisp2 + i]; + } + else if (c[(iw + i * search_region) * widthDisp2 + i] < mini3) + { + mini3 = c[(iw + i * search_region) * widthDisp2 + i]; + } + } + if(mini != 0) + { + if (mini3 / mini <= confidence) + return index; + } + return -1; + } + //!Interpolate in order to obtain better results + //!function for refining the disparity at sub pixel using simetric v + static double symetricVInterpolation(short *c, int iwjp, int widthDisp, int winDisp,const int search_region) + { + if (winDisp == 0 || winDisp == widthDisp - 1) + return winDisp; + double m2m1, m3m1, m3, m2, m1; + m2 = c[(iwjp + (winDisp - 1) * search_region) * widthDisp + winDisp - 1]; + m3 = c[(iwjp + (winDisp + 1) * search_region)* widthDisp + winDisp + 1]; + m1 = c[(iwjp + winDisp * search_region) * widthDisp + winDisp]; + m2m1 = m2 - m1; + m3m1 = m3 - m1; + if (m2m1 == 0 || m3m1 == 0) return winDisp; + double p; + p = 0; + if (m2 > m3) + { + p = (0.5 - 0.25 * ((m3m1 * m3m1) / (m2m1 * m2m1) + (m3m1 / m2m1))); + } + else + { + p = -1 * (0.5 - 0.25 * ((m2m1 * m2m1) / (m3m1 * m3m1) + (m2m1 / m3m1))); + } + if (p >= -0.5 && p <= 0.5) + p = winDisp + p; + return p; + } + //!a pre processing function that generates the Hamming LUT in case the algorithm will ever be used on platform where SSE is not available + void hammingLut() + { + for (int i = 0; i <= 65536; i++) + { + int dist = 0; + int j = i; + //we number the bits from our number + while (j) + { + dist = dist + 1; + j = j & (j - 1); + } + hamLut[i] = dist; + } + } + //!the class used in computing the hamming distance + class hammingDistance : public ParallelLoopBody + { + private: + int *left, *right; + short *c; + int v,kernelSize, width; + int MASK; + int *hammLut; + public : + hammingDistance(const Mat &leftImage, const Mat &rightImage, short *cost, int maxDisp, int kerSize, int *hammingLUT): + left((int *)leftImage.data), right((int *)rightImage.data), c(cost), v(maxDisp),kernelSize(kerSize),width(leftImage.cols), MASK(65535), hammLut(hammingLUT){} + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end ; i++) + { + int iw = i * width; + for (int j = kernelSize; j < width - kernelSize; j++) + { + int j2; + int xorul; + int iwj; + iwj = iw + j; + for (int d = 0; d <= v; d++) + { + j2 = (0 > j - d) ? (0) : (j - d); + xorul = left[(iwj)] ^ right[(iw + j2)]; +#if CV_POPCNT + if (checkHardwareSupport(CV_CPU_POPCNT)) + { + c[(iwj)* (v + 1) + d] = (short)_mm_popcnt_u32(xorul); + } + else +#endif + { + c[(iwj)* (v + 1) + d] = (short)(hammLut[xorul & MASK] + hammLut[(xorul >> 16) & MASK]); + } + } + } + } + } + }; + //!cost aggregation + class agregateCost:public ParallelLoopBody + { + private: + int win; + short *c, *parSum; + int maxDisp,width, height; + public: + agregateCost(const Mat &partialSums, int windowSize, int maxDispa, Mat &cost) + { + win = windowSize / 2; + c = (short *)cost.data; + maxDisp = maxDispa; + width = cost.cols / ( maxDisp + 1) - 1; + height = cost.rows - 1; + parSum = (short *)partialSums.data; + } + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end; i++) + { + int iwi = (i - 1) * width; + for (int j = win + 1; j <= width - win - 1; j++) + { + int w1 = ((i + win + 1) * width + j + win) * (maxDisp + 1); + int w2 = ((i - win) * width + j - win - 1) * (maxDisp + 1); + int w3 = ((i + win + 1) * width + j - win - 1) * (maxDisp + 1); + int w4 = ((i - win) * width + j + win) * (maxDisp + 1); + int w = (iwi + j - 1) * (maxDisp + 1); + for (int d = 0; d <= maxDisp; d++) + { + c[w + d] = parSum[w1 + d] + parSum[w2 + d] + - parSum[w3 + d] - parSum[w4 + d]; + } + } + } + } + }; + //!class that is responsable for generating the disparity map + class makeMap:public ParallelLoopBody + { + private: + //enum used to notify wether we are searching on the vertical ie (lr) or diagonal (rl) + enum {CV_VERTICAL_SEARCH, CV_DIAGONAL_SEARCH}; + int width,disparity,scallingFact,th; + double confCheck; + uint8_t *map; + short *c; + public: + makeMap(const Mat &costVolume, int threshold, int maxDisp, double confidence,int scale, Mat &mapFinal) + { + c = (short *)costVolume.data; + map = mapFinal.data; + disparity = maxDisp; + width = costVolume.cols / ( disparity + 1) - 1; + th = threshold; + scallingFact = scale; + confCheck = confidence; + } + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int i = r.start; i <= r.end ; i++) + { + int lr; + int v = -1; + double p1, p2; + int iw = i * width; + for (int j = 0; j < width; j++) + { + lr = Matching:: minim(c, iw + j, disparity + 1, confCheck,CV_VERTICAL_SEARCH); + if (lr != -1) + { + v = Matching::minim(c, iw + j - lr, disparity + 1, confCheck,CV_DIAGONAL_SEARCH); + if (v != -1) + { + p1 = Matching::symetricVInterpolation(c, iw + j - lr, disparity + 1, v,CV_DIAGONAL_SEARCH); + p2 = Matching::symetricVInterpolation(c, iw + j, disparity + 1, lr,CV_VERTICAL_SEARCH); + if (abs(p1 - p2) <= th) + map[iw + j] = (uint8_t)((p2)* scallingFact); + else + { + map[iw + j] = 0; + } + } + else + { + if (width - j <= disparity) + { + p2 = Matching::symetricVInterpolation(c, iw + j, disparity + 1, lr,CV_VERTICAL_SEARCH); + map[iw + j] = (uint8_t)(p2* scallingFact); + } + } + } + else + { + map[iw + j] = 0; + } + } + } + } + }; + //!median 1x9 paralelized filter + template <typename T> + class Median1x9:public ParallelLoopBody + { + private: + T *original; + T *filtered; + int height, width; + public: + Median1x9(const Mat &originalImage, Mat &filteredImage) + { + original = (T *)originalImage.data; + filtered = (T *)filteredImage.data; + height = originalImage.rows; + width = originalImage.cols; + } + void operator()(const cv::Range &r) const CV_OVERRIDE { + for (int m = r.start; m <= r.end; m++) + { + for (int n = 4; n < width - 4; ++n) + { + int k = 0; + T window[9]; + for (int i = n - 4; i <= n + 4; ++i) + window[k++] = original[m * width + i]; + for (int j = 0; j < 5; ++j) + { + int min = j; + for (int l = j + 1; l < 9; ++l) + if (window[l] < window[min]) + min = l; + const T temp = window[j]; + window[j] = window[min]; + window[min] = temp; + } + filtered[m * width + n] = window[4]; + } + } + } + }; + //!median 9x1 paralelized filter + template <typename T> + class Median9x1:public ParallelLoopBody + { + private: + T *original; + T *filtered; + int height, width; + public: + Median9x1(const Mat &originalImage, Mat &filteredImage) + { + original = (T *)originalImage.data; + filtered = (T *)filteredImage.data; + height = originalImage.rows; + width = originalImage.cols; + } + void operator()(const Range &r) const CV_OVERRIDE { + for (int n = r.start; n <= r.end; ++n) + { + for (int m = 4; m < height - 4; ++m) + { + int k = 0; + T window[9]; + for (int i = m - 4; i <= m + 4; ++i) + window[k++] = original[i * width + n]; + for (int j = 0; j < 5; j++) + { + int min = j; + for (int l = j + 1; l < 9; ++l) + if (window[l] < window[min]) + min = l; + const T temp = window[j]; + window[j] = window[min]; + window[min] = temp; + } + filtered[m * width + n] = window[4]; + } + } + } + }; + protected: + //arrays used in the region removal + Mat_<int> speckleY; + Mat_<int> speckleX; + Mat_<int> puss; + //int *specklePointX; + //int *specklePointY; + //long long *pus; + //!method for setting the maximum disparity + void setMaxDisparity(int val) + { + CV_Assert(val > 10); + this->maxDisparity = val; + } + //!method for getting the disparity + int getMaxDisparity() + { + return this->maxDisparity; + } + //! a number by which the disparity will be multiplied for better display + void setScallingFactor(int val) + { + CV_Assert(val > 0); + this->scallingFactor = val; + } + //!method for getting the scalling factor + int getScallingFactor() + { + return scallingFactor; + } + //!setter for the confidence check + void setConfidence(double val) + { + CV_Assert(val >= 1); + this->confidenceCheck = val; + } + //getter for confidence check + double getConfidence() + { + return confidenceCheck; + } + //! Hamming distance computation method + //! leftImage and rightImage are the two transformed images + //! the cost is the resulted cost volume and kernel Size is the size of the matching window + void hammingDistanceBlockMatching(const Mat &leftImage, const Mat &rightImage, Mat &cost, const int kernelSize= 9) + { + CV_Assert(leftImage.cols == rightImage.cols); + CV_Assert(leftImage.rows == rightImage.rows); + CV_Assert(kernelSize % 2 != 0); + CV_Assert(cost.rows == leftImage.rows); + CV_Assert(cost.cols / (maxDisparity + 1) == leftImage.cols); + short *c = (short *)cost.data; + memset(c, 0, sizeof(c[0]) * leftImage.cols * leftImage.rows * (maxDisparity + 1)); + parallel_for_(cv::Range(kernelSize / 2,leftImage.rows - kernelSize / 2), hammingDistance(leftImage,rightImage,(short *)cost.data,maxDisparity,kernelSize / 2,hamLut)); + } + //preprocessing the cost volume in order to get it ready for aggregation + void costGathering(const Mat &hammingDistanceCost, Mat &cost) + { + CV_Assert(hammingDistanceCost.type() == CV_16S); + CV_Assert(cost.type() == CV_16S); + int maxDisp = maxDisparity; + int width = cost.cols / ( maxDisp + 1) - 1; + int height = cost.rows - 1; + short *c = (short *)cost.data; + short *ham = (short *)hammingDistanceCost.data; + memset(c, 0, sizeof(c[0]) * (width + 1) * (height + 1) * (maxDisp + 1)); + for (int i = 1; i <= height; i++) + { + int iw = i * width; + int iwi = (i - 1) * width; + for (int j = 1; j <= width; j++) + { + int iwj = (iw + j) * (maxDisp + 1); + int iwjmu = (iw + j - 1) * (maxDisp + 1); + int iwijmu = (iwi + j - 1) * (maxDisp + 1); + for (int d = 0; d <= maxDisp; d++) + { + c[iwj + d] = ham[iwijmu + d] + c[iwjmu + d]; + } + } + } + for (int i = 1; i <= height; i++) + { + for (int j = 1; j <= width; j++) + { + int iwj = (i * width + j) * (maxDisp + 1); + int iwjmu = ((i - 1) * width + j) * (maxDisp + 1); + for (int d = 0; d <= maxDisp; d++) + { + c[iwj + d] += c[iwjmu + d]; + } + } + } + } + //!The aggregation on the cost volume + void blockAgregation(const Mat &partialSums, int windowSize, Mat &cost) + { + CV_Assert(windowSize % 2 != 0); + CV_Assert(partialSums.rows == cost.rows); + CV_Assert(partialSums.cols == cost.cols); + int win = windowSize / 2; + short *c = (short *)cost.data; + int maxDisp = maxDisparity; + int width = cost.cols / ( maxDisp + 1) - 1; + int height = cost.rows - 1; + memset(c, 0, sizeof(c[0]) * width * height * (maxDisp + 1)); + parallel_for_(cv::Range(win + 1,height - win - 1), agregateCost(partialSums,windowSize,maxDisp,cost)); + } + //!remove small regions that have an area smaller than t, we fill the region with the average of the good pixels around it + template <typename T> + void smallRegionRemoval(const Mat ¤tMap, int t, Mat &out) + { + CV_Assert(currentMap.cols == out.cols); + CV_Assert(currentMap.rows == out.rows); + CV_Assert(t >= 0); + CV_Assert(!puss.empty()); + int *specklePointX = (int *)speckleX.data; + int *specklePointY = (int *)speckleY.data; + puss.setTo(Scalar::all(0)); + T *map = (T *)currentMap.data; + T *outputMap = (T *)out.data; + int height = currentMap.rows; + int width = currentMap.cols; + T k = 1; + int st, dr; + int di[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, + dj[] = { -1, 0, 1, 1, 1, 0, -1, -1 }; + int speckle_size = 0; + st = 0; + dr = 0; + for (int i = 1; i < height - 1; i++) + { + int iw = i * width; + for (int j = 1; j < width - 1; j++) + { + if (map[iw + j] != 0) + { + outputMap[iw + j] = map[iw + j]; + } + else if (map[iw + j] == 0) + { + T nr = 1; + T avg = 0; + speckle_size = dr; + specklePointX[dr] = i; + specklePointY[dr] = j; + puss(i, j) = 1; + dr++; + map[iw + j] = k; + while (st < dr) + { + int ii = specklePointX[st]; + int jj = specklePointY[st]; + //going on 8 directions + for (int d = 0; d < 8; d++) + {//if insisde + if (ii + di[d] >= 0 && ii + di[d] < height && jj + dj[d] >= 0 && jj + dj[d] < width && + puss(ii + di[d], jj + dj[d]) == 0) + { + T val = map[(ii + di[d]) * width + jj + dj[d]]; + if (val == 0) + { + map[(ii + di[d]) * width + jj + dj[d]] = k; + specklePointX[dr] = (ii + di[d]); + specklePointY[dr] = (jj + dj[d]); + dr++; + puss(ii + di[d], jj + dj[d]) = 1; + }//this means that my point is a good point to be used in computing the final filling value + else if (val >= 1 && val < 250) + { + avg += val; + nr++; + } + } + } + st++; + }//if hole size is smaller than a specified threshold we fill the respective hole with the average of the good neighbours + if (st - speckle_size <= t) + { + T fillValue = (T)(avg / nr); + while (speckle_size < st) + { + int ii = specklePointX[speckle_size]; + int jj = specklePointY[speckle_size]; + outputMap[ii * width + jj] = fillValue; + speckle_size++; + } + } + } + } + } + } + //!Method responsible for generating the disparity map + //!function for generating disparity maps at sub pixel level + /* costVolume - represents the cost volume + * width, height - represent the width and height of the iage + *disparity - represents the maximum disparity + *map - is the disparity map that will result + *th - is the LR threshold + */ + void dispartyMapFormation(const Mat &costVolume, Mat &mapFinal, int th) + { + uint8_t *map = mapFinal.data; + int disparity = maxDisparity; + int width = costVolume.cols / ( disparity + 1) - 1; + int height = costVolume.rows - 1; + memset(map, 0, sizeof(map[0]) * width * height); + parallel_for_(Range(0,height - 1), makeMap(costVolume,th,disparity,confidenceCheck,scallingFactor,mapFinal)); + } + public: + //!a median filter of 1x9 and 9x1 + //!1x9 median filter + template<typename T> + void Median1x9Filter(const Mat &originalImage, Mat &filteredImage) + { + CV_Assert(originalImage.rows == filteredImage.rows); + CV_Assert(originalImage.cols == filteredImage.cols); + parallel_for_(Range(1,originalImage.rows - 2), Median1x9<T>(originalImage,filteredImage)); + } + //!9x1 median filter + template<typename T> + void Median9x1Filter(const Mat &originalImage, Mat &filteredImage) + { + CV_Assert(originalImage.cols == filteredImage.cols); + CV_Assert(originalImage.cols == filteredImage.cols); + parallel_for_(Range(1,originalImage.cols - 2), Median9x1<T>(originalImage,filteredImage)); + } + //!constructor for the matching class + //!maxDisp - represents the maximum disparity + Matching(void) + { + hammingLut(); + } + ~Matching(void) + { + } + //constructor for the matching class + //maxDisp - represents the maximum disparity + //confidence - represents the confidence check + Matching(int maxDisp, int scalling = 4, int confidence = 6) + { + //set the maximum disparity + setMaxDisparity(maxDisp); + //set scalling factor + setScallingFactor(scalling); + //set the value for the confidence + setConfidence(confidence); + //generate the hamming lut in case SSE is not available + hammingLut(); + } + }; + } +} +#endif +/*End of file*/ diff --git a/include/opencv2/stereo/stereo.hpp b/include/opencv2/stereo/stereo.hpp new file mode 100644 index 0000000..bab7c41 --- /dev/null +++ b/include/opencv2/stereo/stereo.hpp @@ -0,0 +1,49 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/stereo.hpp" + diff --git a/include/opencv2/stitching.hpp b/include/opencv2/stitching.hpp new file mode 100644 index 0000000..07e1b5f --- /dev/null +++ b/include/opencv2/stitching.hpp @@ -0,0 +1,329 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_STITCHER_HPP +#define OPENCV_STITCHING_STITCHER_HPP + +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/stitching/warpers.hpp" +#include "opencv2/stitching/detail/matchers.hpp" +#include "opencv2/stitching/detail/motion_estimators.hpp" +#include "opencv2/stitching/detail/exposure_compensate.hpp" +#include "opencv2/stitching/detail/seam_finders.hpp" +#include "opencv2/stitching/detail/blenders.hpp" +#include "opencv2/stitching/detail/camera.hpp" + + +#if defined(Status) +# warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers. +#endif + + +/** +@defgroup stitching Images stitching + +This figure illustrates the stitching module pipeline implemented in the Stitcher class. Using that +class it's possible to configure/remove some steps, i.e. adjust the stitching pipeline according to +the particular needs. All building blocks from the pipeline are available in the detail namespace, +one can combine and use them separately. + +The implemented stitching pipeline is very similar to the one proposed in @cite BL07 . + +![stitching pipeline](StitchingPipeline.jpg) + +Camera models +------------- + +There are currently 2 camera models implemented in stitching pipeline. + +- _Homography model_ expecting perspective transformations between images + implemented in @ref cv::detail::BestOf2NearestMatcher cv::detail::HomographyBasedEstimator + cv::detail::BundleAdjusterReproj cv::detail::BundleAdjusterRay +- _Affine model_ expecting affine transformation with 6 DOF or 4 DOF implemented in + @ref cv::detail::AffineBestOf2NearestMatcher cv::detail::AffineBasedEstimator + cv::detail::BundleAdjusterAffine cv::detail::BundleAdjusterAffinePartial cv::AffineWarper + +Homography model is useful for creating photo panoramas captured by camera, +while affine-based model can be used to stitch scans and object captured by +specialized devices. Use @ref cv::Stitcher::create to get preconfigured pipeline for one +of those models. + +@note +Certain detailed settings of @ref cv::Stitcher might not make sense. Especially +you should not mix classes implementing affine model and classes implementing +Homography model, as they work with different transformations. + +@{ + @defgroup stitching_match Features Finding and Images Matching + @defgroup stitching_rotation Rotation Estimation + @defgroup stitching_autocalib Autocalibration + @defgroup stitching_warp Images Warping + @defgroup stitching_seam Seam Estimation + @defgroup stitching_exposure Exposure Compensation + @defgroup stitching_blend Image Blenders +@} + */ + +namespace cv { + +//! @addtogroup stitching +//! @{ + +/** @example samples/cpp/stitching.cpp +A basic example on image stitching +*/ + +/** @example samples/cpp/stitching_detailed.cpp +A detailed example on image stitching +*/ + +/** @brief High level image stitcher. + +It's possible to use this class without being aware of the entire stitching pipeline. However, to +be able to achieve higher stitching stability and quality of the final images at least being +familiar with the theory is recommended. + +@note + - A basic example on image stitching can be found at + opencv_source_code/samples/cpp/stitching.cpp + - A detailed example on image stitching can be found at + opencv_source_code/samples/cpp/stitching_detailed.cpp + */ +class CV_EXPORTS_W Stitcher +{ +public: + enum { ORIG_RESOL = -1 }; + enum Status + { + OK = 0, + ERR_NEED_MORE_IMGS = 1, + ERR_HOMOGRAPHY_EST_FAIL = 2, + ERR_CAMERA_PARAMS_ADJUST_FAIL = 3 + }; + enum Mode + { + /** Mode for creating photo panoramas. Expects images under perspective + transformation and projects resulting pano to sphere. + + @sa detail::BestOf2NearestMatcher SphericalWarper + */ + PANORAMA = 0, + /** Mode for composing scans. Expects images under affine transformation does + not compensate exposure by default. + + @sa detail::AffineBestOf2NearestMatcher AffineWarper + */ + SCANS = 1, + + }; + + // Stitcher() {} + /** @brief Creates a stitcher with the default parameters. + + @param try_use_gpu Flag indicating whether GPU should be used whenever it's possible. + @return Stitcher class instance. + */ + static Stitcher createDefault(bool try_use_gpu = false); + /** @brief Creates a Stitcher configured in one of the stitching modes. + + @param mode Scenario for stitcher operation. This is usually determined by source of images + to stitch and their transformation. Default parameters will be chosen for operation in given + scenario. + @param try_use_gpu Flag indicating whether GPU should be used whenever it's possible. + @return Stitcher class instance. + */ + static Ptr<Stitcher> create(Mode mode = PANORAMA, bool try_use_gpu = false); + + CV_WRAP double registrationResol() const { return registr_resol_; } + CV_WRAP void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; } + + CV_WRAP double seamEstimationResol() const { return seam_est_resol_; } + CV_WRAP void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; } + + CV_WRAP double compositingResol() const { return compose_resol_; } + CV_WRAP void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; } + + CV_WRAP double panoConfidenceThresh() const { return conf_thresh_; } + CV_WRAP void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; } + + CV_WRAP bool waveCorrection() const { return do_wave_correct_; } + CV_WRAP void setWaveCorrection(bool flag) { do_wave_correct_ = flag; } + + detail::WaveCorrectKind waveCorrectKind() const { return wave_correct_kind_; } + void setWaveCorrectKind(detail::WaveCorrectKind kind) { wave_correct_kind_ = kind; } + + Ptr<detail::FeaturesFinder> featuresFinder() { return features_finder_; } + const Ptr<detail::FeaturesFinder> featuresFinder() const { return features_finder_; } + void setFeaturesFinder(Ptr<detail::FeaturesFinder> features_finder) + { features_finder_ = features_finder; } + + Ptr<detail::FeaturesMatcher> featuresMatcher() { return features_matcher_; } + const Ptr<detail::FeaturesMatcher> featuresMatcher() const { return features_matcher_; } + void setFeaturesMatcher(Ptr<detail::FeaturesMatcher> features_matcher) + { features_matcher_ = features_matcher; } + + const cv::UMat& matchingMask() const { return matching_mask_; } + void setMatchingMask(const cv::UMat &mask) + { + CV_Assert(mask.type() == CV_8U && mask.cols == mask.rows); + matching_mask_ = mask.clone(); + } + + Ptr<detail::BundleAdjusterBase> bundleAdjuster() { return bundle_adjuster_; } + const Ptr<detail::BundleAdjusterBase> bundleAdjuster() const { return bundle_adjuster_; } + void setBundleAdjuster(Ptr<detail::BundleAdjusterBase> bundle_adjuster) + { bundle_adjuster_ = bundle_adjuster; } + + /* TODO OpenCV ABI 4.x + Ptr<detail::Estimator> estimator() { return estimator_; } + const Ptr<detail::Estimator> estimator() const { return estimator_; } + void setEstimator(Ptr<detail::Estimator> estimator) + { estimator_ = estimator; } + */ + + Ptr<WarperCreator> warper() { return warper_; } + const Ptr<WarperCreator> warper() const { return warper_; } + void setWarper(Ptr<WarperCreator> creator) { warper_ = creator; } + + Ptr<detail::ExposureCompensator> exposureCompensator() { return exposure_comp_; } + const Ptr<detail::ExposureCompensator> exposureCompensator() const { return exposure_comp_; } + void setExposureCompensator(Ptr<detail::ExposureCompensator> exposure_comp) + { exposure_comp_ = exposure_comp; } + + Ptr<detail::SeamFinder> seamFinder() { return seam_finder_; } + const Ptr<detail::SeamFinder> seamFinder() const { return seam_finder_; } + void setSeamFinder(Ptr<detail::SeamFinder> seam_finder) { seam_finder_ = seam_finder; } + + Ptr<detail::Blender> blender() { return blender_; } + const Ptr<detail::Blender> blender() const { return blender_; } + void setBlender(Ptr<detail::Blender> b) { blender_ = b; } + + /** @overload */ + CV_WRAP Status estimateTransform(InputArrayOfArrays images); + /** @brief These functions try to match the given images and to estimate rotations of each camera. + + @note Use the functions only if you're aware of the stitching pipeline, otherwise use + Stitcher::stitch. + + @param images Input images. + @param rois Region of interest rectangles. + @return Status code. + */ + Status estimateTransform(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois); + + /** @overload */ + CV_WRAP Status composePanorama(OutputArray pano); + /** @brief These functions try to compose the given images (or images stored internally from the other function + calls) into the final pano under the assumption that the image transformations were estimated + before. + + @note Use the functions only if you're aware of the stitching pipeline, otherwise use + Stitcher::stitch. + + @param images Input images. + @param pano Final pano. + @return Status code. + */ + Status composePanorama(InputArrayOfArrays images, OutputArray pano); + + /** @overload */ + CV_WRAP Status stitch(InputArrayOfArrays images, OutputArray pano); + /** @brief These functions try to stitch the given images. + + @param images Input images. + @param rois Region of interest rectangles. + @param pano Final pano. + @return Status code. + */ + Status stitch(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois, OutputArray pano); + + std::vector<int> component() const { return indices_; } + std::vector<detail::CameraParams> cameras() const { return cameras_; } + CV_WRAP double workScale() const { return work_scale_; } + +private: + //Stitcher() {} + + Status matchImages(); + Status estimateCameraParams(); + + double registr_resol_; + double seam_est_resol_; + double compose_resol_; + double conf_thresh_; + Ptr<detail::FeaturesFinder> features_finder_; + Ptr<detail::FeaturesMatcher> features_matcher_; + cv::UMat matching_mask_; + Ptr<detail::BundleAdjusterBase> bundle_adjuster_; + /* TODO OpenCV ABI 4.x + Ptr<detail::Estimator> estimator_; + */ + bool do_wave_correct_; + detail::WaveCorrectKind wave_correct_kind_; + Ptr<WarperCreator> warper_; + Ptr<detail::ExposureCompensator> exposure_comp_; + Ptr<detail::SeamFinder> seam_finder_; + Ptr<detail::Blender> blender_; + + std::vector<cv::UMat> imgs_; + std::vector<std::vector<cv::Rect> > rois_; + std::vector<cv::Size> full_img_sizes_; + std::vector<detail::ImageFeatures> features_; + std::vector<detail::MatchesInfo> pairwise_matches_; + std::vector<cv::UMat> seam_est_imgs_; + std::vector<int> indices_; + std::vector<detail::CameraParams> cameras_; + double work_scale_; + double seam_scale_; + double seam_work_aspect_; + double warped_image_scale_; +}; + +CV_EXPORTS_W Ptr<Stitcher> createStitcher(bool try_use_gpu = false); +CV_EXPORTS_W Ptr<Stitcher> createStitcherScans(bool try_use_gpu = false); + +//! @} stitching + +} // namespace cv + +#endif // OPENCV_STITCHING_STITCHER_HPP diff --git a/include/opencv2/stitching/detail/autocalib.hpp b/include/opencv2/stitching/detail/autocalib.hpp new file mode 100644 index 0000000..19705e2 --- /dev/null +++ b/include/opencv2/stitching/detail/autocalib.hpp @@ -0,0 +1,86 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_AUTOCALIB_HPP +#define OPENCV_STITCHING_AUTOCALIB_HPP + +#include "opencv2/core.hpp" +#include "matchers.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching_autocalib +//! @{ + +/** @brief Tries to estimate focal lengths from the given homography under the assumption that the camera +undergoes rotations around its centre only. + +@param H Homography. +@param f0 Estimated focal length along X axis. +@param f1 Estimated focal length along Y axis. +@param f0_ok True, if f0 was estimated successfully, false otherwise. +@param f1_ok True, if f1 was estimated successfully, false otherwise. + +See "Construction of Panoramic Image Mosaics with Global and Local Alignment" +by Heung-Yeung Shum and Richard Szeliski. + */ +void CV_EXPORTS focalsFromHomography(const Mat &H, double &f0, double &f1, bool &f0_ok, bool &f1_ok); + +/** @brief Estimates focal lengths for each given camera. + +@param features Features of images. +@param pairwise_matches Matches between all image pairs. +@param focals Estimated focal lengths for each camera. + */ +void CV_EXPORTS estimateFocal(const std::vector<ImageFeatures> &features, + const std::vector<MatchesInfo> &pairwise_matches, + std::vector<double> &focals); + +bool CV_EXPORTS calibrateRotatingCamera(const std::vector<Mat> &Hs, Mat &K); + +//! @} stitching_autocalib + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_AUTOCALIB_HPP diff --git a/include/opencv2/stitching/detail/blenders.hpp b/include/opencv2/stitching/detail/blenders.hpp new file mode 100644 index 0000000..542f1e4 --- /dev/null +++ b/include/opencv2/stitching/detail/blenders.hpp @@ -0,0 +1,184 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_BLENDERS_HPP +#define OPENCV_STITCHING_BLENDERS_HPP + +#if defined(NO) +# warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif + +#include "opencv2/core.hpp" +#include "opencv2/core/cuda.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching_blend +//! @{ + +/** @brief Base class for all blenders. + +Simple blender which puts one image over another +*/ +class CV_EXPORTS Blender +{ +public: + virtual ~Blender() {} + + enum { NO, FEATHER, MULTI_BAND }; + static Ptr<Blender> createDefault(int type, bool try_gpu = false); + + /** @brief Prepares the blender for blending. + + @param corners Source images top-left corners + @param sizes Source image sizes + */ + void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes); + /** @overload */ + virtual void prepare(Rect dst_roi); + /** @brief Processes the image. + + @param img Source image + @param mask Source image mask + @param tl Source image top-left corners + */ + virtual void feed(InputArray img, InputArray mask, Point tl); + /** @brief Blends and returns the final pano. + + @param dst Final pano + @param dst_mask Final pano mask + */ + virtual void blend(InputOutputArray dst, InputOutputArray dst_mask); + +protected: + UMat dst_, dst_mask_; + Rect dst_roi_; +}; + +/** @brief Simple blender which mixes images at its borders. + */ +class CV_EXPORTS FeatherBlender : public Blender +{ +public: + FeatherBlender(float sharpness = 0.02f); + + float sharpness() const { return sharpness_; } + void setSharpness(float val) { sharpness_ = val; } + + void prepare(Rect dst_roi) CV_OVERRIDE; + void feed(InputArray img, InputArray mask, Point tl) CV_OVERRIDE; + void blend(InputOutputArray dst, InputOutputArray dst_mask) CV_OVERRIDE; + + //! Creates weight maps for fixed set of source images by their masks and top-left corners. + //! Final image can be obtained by simple weighting of the source images. + Rect createWeightMaps(const std::vector<UMat> &masks, const std::vector<Point> &corners, + std::vector<UMat> &weight_maps); + +private: + float sharpness_; + UMat weight_map_; + UMat dst_weight_map_; +}; + +inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); } + +/** @brief Blender which uses multi-band blending algorithm (see @cite BA83). + */ +class CV_EXPORTS MultiBandBlender : public Blender +{ +public: + MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F); + + int numBands() const { return actual_num_bands_; } + void setNumBands(int val) { actual_num_bands_ = val; } + + void prepare(Rect dst_roi) CV_OVERRIDE; + void feed(InputArray img, InputArray mask, Point tl) CV_OVERRIDE; + void blend(InputOutputArray dst, InputOutputArray dst_mask) CV_OVERRIDE; + +private: + int actual_num_bands_, num_bands_; + std::vector<UMat> dst_pyr_laplace_; + std::vector<UMat> dst_band_weights_; + Rect dst_roi_final_; + bool can_use_gpu_; + int weight_type_; //CV_32F or CV_16S +#if defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAWARPING) + std::vector<cuda::GpuMat> gpu_dst_pyr_laplace_; + std::vector<cuda::GpuMat> gpu_dst_band_weights_; + std::vector<Point> gpu_tl_points_; + std::vector<cuda::GpuMat> gpu_imgs_with_border_; + std::vector<std::vector<cuda::GpuMat> > gpu_weight_pyr_gauss_vec_; + std::vector<std::vector<cuda::GpuMat> > gpu_src_pyr_laplace_vec_; + std::vector<std::vector<cuda::GpuMat> > gpu_ups_; + cuda::GpuMat gpu_dst_mask_; + cuda::GpuMat gpu_mask_; + cuda::GpuMat gpu_img_; + cuda::GpuMat gpu_weight_map_; + cuda::GpuMat gpu_add_mask_; + int gpu_feed_idx_; + bool gpu_initialized_; +#endif +}; + + +////////////////////////////////////////////////////////////////////////////// +// Auxiliary functions + +void CV_EXPORTS normalizeUsingWeightMap(InputArray weight, InputOutputArray src); + +void CV_EXPORTS createWeightMap(InputArray mask, float sharpness, InputOutputArray weight); + +void CV_EXPORTS createLaplacePyr(InputArray img, int num_levels, std::vector<UMat>& pyr); +void CV_EXPORTS createLaplacePyrGpu(InputArray img, int num_levels, std::vector<UMat>& pyr); + +// Restores source image +void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<UMat>& pyr); +void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<UMat>& pyr); + +//! @} + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_BLENDERS_HPP diff --git a/include/opencv2/stitching/detail/camera.hpp b/include/opencv2/stitching/detail/camera.hpp new file mode 100644 index 0000000..07c6b5b --- /dev/null +++ b/include/opencv2/stitching/detail/camera.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_CAMERA_HPP +#define OPENCV_STITCHING_CAMERA_HPP + +#include "opencv2/core.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching +//! @{ + +/** @brief Describes camera parameters. + +@note Translation is assumed to be zero during the whole stitching pipeline. : + */ +struct CV_EXPORTS CameraParams +{ + CameraParams(); + CameraParams(const CameraParams& other); + CameraParams& operator =(const CameraParams& other); + Mat K() const; + + double focal; // Focal length + double aspect; // Aspect ratio + double ppx; // Principal point X + double ppy; // Principal point Y + Mat R; // Rotation + Mat t; // Translation +}; + +//! @} + +} // namespace detail +} // namespace cv + +#endif // #ifndef OPENCV_STITCHING_CAMERA_HPP diff --git a/include/opencv2/stitching/detail/exposure_compensate.hpp b/include/opencv2/stitching/detail/exposure_compensate.hpp new file mode 100644 index 0000000..6c99407 --- /dev/null +++ b/include/opencv2/stitching/detail/exposure_compensate.hpp @@ -0,0 +1,136 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP +#define OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP + +#if defined(NO) +# warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif + +#include "opencv2/core.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching_exposure +//! @{ + +/** @brief Base class for all exposure compensators. + */ +class CV_EXPORTS ExposureCompensator +{ +public: + virtual ~ExposureCompensator() {} + + enum { NO, GAIN, GAIN_BLOCKS }; + static Ptr<ExposureCompensator> createDefault(int type); + + /** + @param corners Source image top-left corners + @param images Source images + @param masks Image masks to update (second value in pair specifies the value which should be used + to detect where image is) + */ + void feed(const std::vector<Point> &corners, const std::vector<UMat> &images, + const std::vector<UMat> &masks); + /** @overload */ + virtual void feed(const std::vector<Point> &corners, const std::vector<UMat> &images, + const std::vector<std::pair<UMat,uchar> > &masks) = 0; + /** @brief Compensate exposure in the specified image. + + @param index Image index + @param corner Image top-left corner + @param image Image to process + @param mask Image mask + */ + virtual void apply(int index, Point corner, InputOutputArray image, InputArray mask) = 0; +}; + +/** @brief Stub exposure compensator which does nothing. + */ +class CV_EXPORTS NoExposureCompensator : public ExposureCompensator +{ +public: + void feed(const std::vector<Point> &/*corners*/, const std::vector<UMat> &/*images*/, + const std::vector<std::pair<UMat,uchar> > &/*masks*/) CV_OVERRIDE { } + void apply(int /*index*/, Point /*corner*/, InputOutputArray /*image*/, InputArray /*mask*/) CV_OVERRIDE { } +}; + +/** @brief Exposure compensator which tries to remove exposure related artifacts by adjusting image +intensities, see @cite BL07 and @cite WJ10 for details. + */ +class CV_EXPORTS GainCompensator : public ExposureCompensator +{ +public: + void feed(const std::vector<Point> &corners, const std::vector<UMat> &images, + const std::vector<std::pair<UMat,uchar> > &masks) CV_OVERRIDE; + void apply(int index, Point corner, InputOutputArray image, InputArray mask) CV_OVERRIDE; + std::vector<double> gains() const; + +private: + Mat_<double> gains_; +}; + +/** @brief Exposure compensator which tries to remove exposure related artifacts by adjusting image block +intensities, see @cite UES01 for details. + */ +class CV_EXPORTS BlocksGainCompensator : public ExposureCompensator +{ +public: + BlocksGainCompensator(int bl_width = 32, int bl_height = 32) + : bl_width_(bl_width), bl_height_(bl_height) {} + void feed(const std::vector<Point> &corners, const std::vector<UMat> &images, + const std::vector<std::pair<UMat,uchar> > &masks) CV_OVERRIDE; + void apply(int index, Point corner, InputOutputArray image, InputArray mask) CV_OVERRIDE; + +private: + int bl_width_, bl_height_; + std::vector<UMat> gain_maps_; +}; + +//! @} + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP diff --git a/include/opencv2/stitching/detail/matchers.hpp b/include/opencv2/stitching/detail/matchers.hpp new file mode 100644 index 0000000..25c0f2a --- /dev/null +++ b/include/opencv2/stitching/detail/matchers.hpp @@ -0,0 +1,370 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_MATCHERS_HPP +#define OPENCV_STITCHING_MATCHERS_HPP + +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" + +#include "opencv2/opencv_modules.hpp" + +#ifdef HAVE_OPENCV_XFEATURES2D +# include "opencv2/xfeatures2d/cuda.hpp" +#endif + +namespace cv { +namespace detail { + +//! @addtogroup stitching_match +//! @{ + +/** @brief Structure containing image keypoints and descriptors. */ +struct CV_EXPORTS ImageFeatures +{ + int img_idx; + Size img_size; + std::vector<KeyPoint> keypoints; + UMat descriptors; +}; + +/** @brief Feature finders base class */ +class CV_EXPORTS FeaturesFinder +{ +public: + virtual ~FeaturesFinder() {} + /** @overload */ + void operator ()(InputArray image, ImageFeatures &features); + /** @brief Finds features in the given image. + + @param image Source image + @param features Found features + @param rois Regions of interest + + @sa detail::ImageFeatures, Rect_ + */ + void operator ()(InputArray image, ImageFeatures &features, const std::vector<cv::Rect> &rois); + /** @brief Finds features in the given images in parallel. + + @param images Source images + @param features Found features for each image + @param rois Regions of interest for each image + + @sa detail::ImageFeatures, Rect_ + */ + void operator ()(InputArrayOfArrays images, std::vector<ImageFeatures> &features, + const std::vector<std::vector<cv::Rect> > &rois); + /** @overload */ + void operator ()(InputArrayOfArrays images, std::vector<ImageFeatures> &features); + /** @brief Frees unused memory allocated before if there is any. */ + virtual void collectGarbage() {} + + /* TODO OpenCV ABI 4.x + reimplement this as public method similar to FeaturesMatcher and remove private function hack + @return True, if it's possible to use the same finder instance in parallel, false otherwise + bool isThreadSafe() const { return is_thread_safe_; } + */ + +protected: + /** @brief This method must implement features finding logic in order to make the wrappers + detail::FeaturesFinder::operator()_ work. + + @param image Source image + @param features Found features + + @sa detail::ImageFeatures */ + virtual void find(InputArray image, ImageFeatures &features) = 0; + /** @brief uses dynamic_cast to determine thread-safety + @return True, if it's possible to use the same finder instance in parallel, false otherwise + */ + bool isThreadSafe() const; +}; + +/** @brief SURF features finder. + +@sa detail::FeaturesFinder, SURF +*/ +class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder +{ +public: + SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4, + int num_octaves_descr = /*4*/3, int num_layers_descr = /*2*/4); + +private: + void find(InputArray image, ImageFeatures &features) CV_OVERRIDE; + + Ptr<FeatureDetector> detector_; + Ptr<DescriptorExtractor> extractor_; + Ptr<Feature2D> surf; +}; + + +/** @brief SIFT features finder. + +@sa detail::FeaturesFinder, SIFT +*/ +class CV_EXPORTS SiftFeaturesFinder : public FeaturesFinder +{ +public: + SiftFeaturesFinder(); + +private: + void find(InputArray image, ImageFeatures &features) CV_OVERRIDE; + Ptr<Feature2D> sift; +}; + +/** @brief ORB features finder. : + +@sa detail::FeaturesFinder, ORB +*/ +class CV_EXPORTS OrbFeaturesFinder : public FeaturesFinder +{ +public: + OrbFeaturesFinder(Size _grid_size = Size(3,1), int nfeatures=1500, float scaleFactor=1.3f, int nlevels=5); + +private: + void find(InputArray image, ImageFeatures &features) CV_OVERRIDE; + + Ptr<ORB> orb; + Size grid_size; +}; + +/** @brief AKAZE features finder. : + +@sa detail::FeaturesFinder, AKAZE +*/ +class CV_EXPORTS AKAZEFeaturesFinder : public detail::FeaturesFinder +{ +public: + AKAZEFeaturesFinder(int descriptor_type = AKAZE::DESCRIPTOR_MLDB, + int descriptor_size = 0, + int descriptor_channels = 3, + float threshold = 0.001f, + int nOctaves = 4, + int nOctaveLayers = 4, + int diffusivity = KAZE::DIFF_PM_G2); + +private: + void find(InputArray image, ImageFeatures &features) CV_OVERRIDE; + + Ptr<AKAZE> akaze; +}; + +#ifdef HAVE_OPENCV_XFEATURES2D +class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder +{ +public: + SurfFeaturesFinderGpu(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4, + int num_octaves_descr = 4, int num_layers_descr = 2); + + void collectGarbage() CV_OVERRIDE; + +private: + void find(InputArray image, ImageFeatures &features) CV_OVERRIDE; + + cuda::GpuMat image_; + cuda::GpuMat gray_image_; + cuda::SURF_CUDA surf_; + cuda::GpuMat keypoints_; + cuda::GpuMat descriptors_; + int num_octaves_, num_layers_; + int num_octaves_descr_, num_layers_descr_; +}; +#endif + +/** @brief Structure containing information about matches between two images. + +It's assumed that there is a transformation between those images. Transformation may be +homography or affine transformation based on selected matcher. + +@sa detail::FeaturesMatcher +*/ +struct CV_EXPORTS MatchesInfo +{ + MatchesInfo(); + MatchesInfo(const MatchesInfo &other); + MatchesInfo& operator =(const MatchesInfo &other); + + int src_img_idx, dst_img_idx; //!< Images indices (optional) + std::vector<DMatch> matches; + std::vector<uchar> inliers_mask; //!< Geometrically consistent matches mask + int num_inliers; //!< Number of geometrically consistent matches + Mat H; //!< Estimated transformation + double confidence; //!< Confidence two images are from the same panorama +}; + +/** @brief Feature matchers base class. */ +class CV_EXPORTS FeaturesMatcher +{ +public: + virtual ~FeaturesMatcher() {} + + /** @overload + @param features1 First image features + @param features2 Second image features + @param matches_info Found matches + */ + void operator ()(const ImageFeatures &features1, const ImageFeatures &features2, + MatchesInfo& matches_info) { match(features1, features2, matches_info); } + + /** @brief Performs images matching. + + @param features Features of the source images + @param pairwise_matches Found pairwise matches + @param mask Mask indicating which image pairs must be matched + + The function is parallelized with the TBB library. + + @sa detail::MatchesInfo + */ + void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches, + const cv::UMat &mask = cv::UMat()); + + /** @return True, if it's possible to use the same matcher instance in parallel, false otherwise + */ + bool isThreadSafe() const { return is_thread_safe_; } + + /** @brief Frees unused memory allocated before if there is any. + */ + virtual void collectGarbage() {} + +protected: + FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {} + + /** @brief This method must implement matching logic in order to make the wrappers + detail::FeaturesMatcher::operator()_ work. + + @param features1 first image features + @param features2 second image features + @param matches_info found matches + */ + virtual void match(const ImageFeatures &features1, const ImageFeatures &features2, + MatchesInfo& matches_info) = 0; + + bool is_thread_safe_; +}; + +/** @brief Features matcher which finds two best matches for each feature and leaves the best one only if the +ratio between descriptor distances is greater than the threshold match_conf + +@sa detail::FeaturesMatcher + */ +class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher +{ +public: + /** @brief Constructs a "best of 2 nearest" matcher. + + @param try_use_gpu Should try to use GPU or not + @param match_conf Match distances ration threshold + @param num_matches_thresh1 Minimum number of matches required for the 2D projective transform + estimation used in the inliers classification step + @param num_matches_thresh2 Minimum number of matches required for the 2D projective transform + re-estimation on inliers + */ + BestOf2NearestMatcher(bool try_use_gpu = false, float match_conf = 0.3f, int num_matches_thresh1 = 6, + int num_matches_thresh2 = 6); + + void collectGarbage() CV_OVERRIDE; + +protected: + void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info) CV_OVERRIDE; + + int num_matches_thresh1_; + int num_matches_thresh2_; + Ptr<FeaturesMatcher> impl_; +}; + +class CV_EXPORTS BestOf2NearestRangeMatcher : public BestOf2NearestMatcher +{ +public: + BestOf2NearestRangeMatcher(int range_width = 5, bool try_use_gpu = false, float match_conf = 0.3f, + int num_matches_thresh1 = 6, int num_matches_thresh2 = 6); + + void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches, + const cv::UMat &mask = cv::UMat()); + + +protected: + int range_width_; +}; + +/** @brief Features matcher similar to cv::detail::BestOf2NearestMatcher which +finds two best matches for each feature and leaves the best one only if the +ratio between descriptor distances is greater than the threshold match_conf. + +Unlike cv::detail::BestOf2NearestMatcher this matcher uses affine +transformation (affine trasformation estimate will be placed in matches_info). + +@sa cv::detail::FeaturesMatcher cv::detail::BestOf2NearestMatcher + */ +class CV_EXPORTS AffineBestOf2NearestMatcher : public BestOf2NearestMatcher +{ +public: + /** @brief Constructs a "best of 2 nearest" matcher that expects affine trasformation + between images + + @param full_affine whether to use full affine transformation with 6 degress of freedom or reduced + transformation with 4 degrees of freedom using only rotation, translation and uniform scaling + @param try_use_gpu Should try to use GPU or not + @param match_conf Match distances ration threshold + @param num_matches_thresh1 Minimum number of matches required for the 2D affine transform + estimation used in the inliers classification step + + @sa cv::estimateAffine2D cv::estimateAffinePartial2D + */ + AffineBestOf2NearestMatcher(bool full_affine = false, bool try_use_gpu = false, + float match_conf = 0.3f, int num_matches_thresh1 = 6) : + BestOf2NearestMatcher(try_use_gpu, match_conf, num_matches_thresh1, num_matches_thresh1), + full_affine_(full_affine) {} + +protected: + void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info) CV_OVERRIDE; + + bool full_affine_; +}; + +//! @} stitching_match + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_MATCHERS_HPP diff --git a/include/opencv2/stitching/detail/motion_estimators.hpp b/include/opencv2/stitching/detail/motion_estimators.hpp new file mode 100644 index 0000000..40f12c3 --- /dev/null +++ b/include/opencv2/stitching/detail/motion_estimators.hpp @@ -0,0 +1,359 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_MOTION_ESTIMATORS_HPP +#define OPENCV_STITCHING_MOTION_ESTIMATORS_HPP + +#include "opencv2/core.hpp" +#include "matchers.hpp" +#include "util.hpp" +#include "camera.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching_rotation +//! @{ + +/** @brief Rotation estimator base class. + +It takes features of all images, pairwise matches between all images and estimates rotations of all +cameras. + +@note The coordinate system origin is implementation-dependent, but you can always normalize the +rotations in respect to the first camera, for instance. : + */ +class CV_EXPORTS Estimator +{ +public: + virtual ~Estimator() {} + + /** @brief Estimates camera parameters. + + @param features Features of images + @param pairwise_matches Pairwise matches of images + @param cameras Estimated camera parameters + @return True in case of success, false otherwise + */ + bool operator ()(const std::vector<ImageFeatures> &features, + const std::vector<MatchesInfo> &pairwise_matches, + std::vector<CameraParams> &cameras) + { return estimate(features, pairwise_matches, cameras); } + +protected: + /** @brief This method must implement camera parameters estimation logic in order to make the wrapper + detail::Estimator::operator()_ work. + + @param features Features of images + @param pairwise_matches Pairwise matches of images + @param cameras Estimated camera parameters + @return True in case of success, false otherwise + */ + virtual bool estimate(const std::vector<ImageFeatures> &features, + const std::vector<MatchesInfo> &pairwise_matches, + std::vector<CameraParams> &cameras) = 0; +}; + +/** @brief Homography based rotation estimator. + */ +class CV_EXPORTS HomographyBasedEstimator : public Estimator +{ +public: + HomographyBasedEstimator(bool is_focals_estimated = false) + : is_focals_estimated_(is_focals_estimated) {} + +private: + virtual bool estimate(const std::vector<ImageFeatures> &features, + const std::vector<MatchesInfo> &pairwise_matches, + std::vector<CameraParams> &cameras) CV_OVERRIDE; + + bool is_focals_estimated_; +}; + +/** @brief Affine transformation based estimator. + +This estimator uses pairwise transformations estimated by matcher to estimate +final transformation for each camera. + +@sa cv::detail::HomographyBasedEstimator + */ +class CV_EXPORTS AffineBasedEstimator : public Estimator +{ +private: + virtual bool estimate(const std::vector<ImageFeatures> &features, + const std::vector<MatchesInfo> &pairwise_matches, + std::vector<CameraParams> &cameras) CV_OVERRIDE; +}; + +/** @brief Base class for all camera parameters refinement methods. + */ +class CV_EXPORTS BundleAdjusterBase : public Estimator +{ +public: + const Mat refinementMask() const { return refinement_mask_.clone(); } + void setRefinementMask(const Mat &mask) + { + CV_Assert(mask.type() == CV_8U && mask.size() == Size(3, 3)); + refinement_mask_ = mask.clone(); + } + + double confThresh() const { return conf_thresh_; } + void setConfThresh(double conf_thresh) { conf_thresh_ = conf_thresh; } + + TermCriteria termCriteria() { return term_criteria_; } + void setTermCriteria(const TermCriteria& term_criteria) { term_criteria_ = term_criteria; } + +protected: + /** @brief Construct a bundle adjuster base instance. + + @param num_params_per_cam Number of parameters per camera + @param num_errs_per_measurement Number of error terms (components) per match + */ + BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement) + : num_images_(0), total_num_matches_(0), + num_params_per_cam_(num_params_per_cam), + num_errs_per_measurement_(num_errs_per_measurement), + features_(0), pairwise_matches_(0), conf_thresh_(0) + { + setRefinementMask(Mat::ones(3, 3, CV_8U)); + setConfThresh(1.); + setTermCriteria(TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 1000, DBL_EPSILON)); + } + + // Runs bundle adjustment + virtual bool estimate(const std::vector<ImageFeatures> &features, + const std::vector<MatchesInfo> &pairwise_matches, + std::vector<CameraParams> &cameras) CV_OVERRIDE; + + /** @brief Sets initial camera parameter to refine. + + @param cameras Camera parameters + */ + virtual void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) = 0; + /** @brief Gets the refined camera parameters. + + @param cameras Refined camera parameters + */ + virtual void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const = 0; + /** @brief Calculates error vector. + + @param err Error column-vector of length total_num_matches \* num_errs_per_measurement + */ + virtual void calcError(Mat &err) = 0; + /** @brief Calculates the cost function jacobian. + + @param jac Jacobian matrix of dimensions + (total_num_matches \* num_errs_per_measurement) x (num_images \* num_params_per_cam) + */ + virtual void calcJacobian(Mat &jac) = 0; + + // 3x3 8U mask, where 0 means don't refine respective parameter, != 0 means refine + Mat refinement_mask_; + + int num_images_; + int total_num_matches_; + + int num_params_per_cam_; + int num_errs_per_measurement_; + + const ImageFeatures *features_; + const MatchesInfo *pairwise_matches_; + + // Threshold to filter out poorly matched image pairs + double conf_thresh_; + + //Levenberg-Marquardt algorithm termination criteria + TermCriteria term_criteria_; + + // Camera parameters matrix (CV_64F) + Mat cam_params_; + + // Connected images pairs + std::vector<std::pair<int,int> > edges_; +}; + + +/** @brief Stub bundle adjuster that does nothing. + */ +class CV_EXPORTS NoBundleAdjuster : public BundleAdjusterBase +{ +public: + NoBundleAdjuster() : BundleAdjusterBase(0, 0) {} + +private: + bool estimate(const std::vector<ImageFeatures> &, const std::vector<MatchesInfo> &, + std::vector<CameraParams> &) CV_OVERRIDE + { + return true; + } + void setUpInitialCameraParams(const std::vector<CameraParams> &) CV_OVERRIDE {} + void obtainRefinedCameraParams(std::vector<CameraParams> &) const CV_OVERRIDE {} + void calcError(Mat &) CV_OVERRIDE {} + void calcJacobian(Mat &) CV_OVERRIDE {} +}; + + +/** @brief Implementation of the camera parameters refinement algorithm which minimizes sum of the reprojection +error squares + +It can estimate focal length, aspect ratio, principal point. +You can affect only on them via the refinement mask. + */ +class CV_EXPORTS BundleAdjusterReproj : public BundleAdjusterBase +{ +public: + BundleAdjusterReproj() : BundleAdjusterBase(7, 2) {} + +private: + void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) CV_OVERRIDE; + void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const CV_OVERRIDE; + void calcError(Mat &err) CV_OVERRIDE; + void calcJacobian(Mat &jac) CV_OVERRIDE; + + Mat err1_, err2_; +}; + + +/** @brief Implementation of the camera parameters refinement algorithm which minimizes sum of the distances +between the rays passing through the camera center and a feature. : + +It can estimate focal length. It ignores the refinement mask for now. + */ +class CV_EXPORTS BundleAdjusterRay : public BundleAdjusterBase +{ +public: + BundleAdjusterRay() : BundleAdjusterBase(4, 3) {} + +private: + void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) CV_OVERRIDE; + void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const CV_OVERRIDE; + void calcError(Mat &err) CV_OVERRIDE; + void calcJacobian(Mat &jac) CV_OVERRIDE; + + Mat err1_, err2_; +}; + + +/** @brief Bundle adjuster that expects affine transformation +represented in homogeneous coordinates in R for each camera param. Implements +camera parameters refinement algorithm which minimizes sum of the reprojection +error squares + +It estimates all transformation parameters. Refinement mask is ignored. + +@sa AffineBasedEstimator AffineBestOf2NearestMatcher BundleAdjusterAffinePartial + */ +class CV_EXPORTS BundleAdjusterAffine : public BundleAdjusterBase +{ +public: + BundleAdjusterAffine() : BundleAdjusterBase(6, 2) {} + +private: + void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) CV_OVERRIDE; + void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const CV_OVERRIDE; + void calcError(Mat &err) CV_OVERRIDE; + void calcJacobian(Mat &jac) CV_OVERRIDE; + + Mat err1_, err2_; +}; + + +/** @brief Bundle adjuster that expects affine transformation with 4 DOF +represented in homogeneous coordinates in R for each camera param. Implements +camera parameters refinement algorithm which minimizes sum of the reprojection +error squares + +It estimates all transformation parameters. Refinement mask is ignored. + +@sa AffineBasedEstimator AffineBestOf2NearestMatcher BundleAdjusterAffine + */ +class CV_EXPORTS BundleAdjusterAffinePartial : public BundleAdjusterBase +{ +public: + BundleAdjusterAffinePartial() : BundleAdjusterBase(4, 2) {} + +private: + void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) CV_OVERRIDE; + void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const CV_OVERRIDE; + void calcError(Mat &err) CV_OVERRIDE; + void calcJacobian(Mat &jac) CV_OVERRIDE; + + Mat err1_, err2_; +}; + + +enum WaveCorrectKind +{ + WAVE_CORRECT_HORIZ, + WAVE_CORRECT_VERT +}; + +/** @brief Tries to make panorama more horizontal (or vertical). + +@param rmats Camera rotation matrices. +@param kind Correction kind, see detail::WaveCorrectKind. + */ +void CV_EXPORTS waveCorrect(std::vector<Mat> &rmats, WaveCorrectKind kind); + + +////////////////////////////////////////////////////////////////////////////// +// Auxiliary functions + +// Returns matches graph representation in DOT language +String CV_EXPORTS matchesGraphAsString(std::vector<String> &pathes, std::vector<MatchesInfo> &pairwise_matches, + float conf_threshold); + +std::vector<int> CV_EXPORTS leaveBiggestComponent( + std::vector<ImageFeatures> &features, + std::vector<MatchesInfo> &pairwise_matches, + float conf_threshold); + +void CV_EXPORTS findMaxSpanningTree( + int num_images, const std::vector<MatchesInfo> &pairwise_matches, + Graph &span_tree, std::vector<int> ¢ers); + +//! @} stitching_rotation + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_MOTION_ESTIMATORS_HPP diff --git a/include/opencv2/stitching/detail/seam_finders.hpp b/include/opencv2/stitching/detail/seam_finders.hpp new file mode 100644 index 0000000..904f0ec --- /dev/null +++ b/include/opencv2/stitching/detail/seam_finders.hpp @@ -0,0 +1,285 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_SEAM_FINDERS_HPP +#define OPENCV_STITCHING_SEAM_FINDERS_HPP + +#include <set> +#include "opencv2/core.hpp" +#include "opencv2/opencv_modules.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching_seam +//! @{ + +/** @brief Base class for a seam estimator. + */ +class CV_EXPORTS SeamFinder +{ +public: + virtual ~SeamFinder() {} + /** @brief Estimates seams. + + @param src Source images + @param corners Source image top-left corners + @param masks Source image masks to update + */ + virtual void find(const std::vector<UMat> &src, const std::vector<Point> &corners, + std::vector<UMat> &masks) = 0; +}; + +/** @brief Stub seam estimator which does nothing. + */ +class CV_EXPORTS NoSeamFinder : public SeamFinder +{ +public: + void find(const std::vector<UMat>&, const std::vector<Point>&, std::vector<UMat>&) CV_OVERRIDE {} +}; + +/** @brief Base class for all pairwise seam estimators. + */ +class CV_EXPORTS PairwiseSeamFinder : public SeamFinder +{ +public: + virtual void find(const std::vector<UMat> &src, const std::vector<Point> &corners, + std::vector<UMat> &masks) CV_OVERRIDE; + +protected: + void run(); + /** @brief Resolves masks intersection of two specified images in the given ROI. + + @param first First image index + @param second Second image index + @param roi Region of interest + */ + virtual void findInPair(size_t first, size_t second, Rect roi) = 0; + + std::vector<UMat> images_; + std::vector<Size> sizes_; + std::vector<Point> corners_; + std::vector<UMat> masks_; +}; + +/** @brief Voronoi diagram-based seam estimator. + */ +class CV_EXPORTS VoronoiSeamFinder : public PairwiseSeamFinder +{ +public: + virtual void find(const std::vector<UMat> &src, const std::vector<Point> &corners, + std::vector<UMat> &masks) CV_OVERRIDE; + virtual void find(const std::vector<Size> &size, const std::vector<Point> &corners, + std::vector<UMat> &masks); +private: + void findInPair(size_t first, size_t second, Rect roi) CV_OVERRIDE; +}; + + +class CV_EXPORTS DpSeamFinder : public SeamFinder +{ +public: + enum CostFunction { COLOR, COLOR_GRAD }; + + DpSeamFinder(CostFunction costFunc = COLOR); + + CostFunction costFunction() const { return costFunc_; } + void setCostFunction(CostFunction val) { costFunc_ = val; } + + virtual void find(const std::vector<UMat> &src, const std::vector<Point> &corners, + std::vector<UMat> &masks) CV_OVERRIDE; + +private: + enum ComponentState + { + FIRST = 1, SECOND = 2, INTERS = 4, + INTERS_FIRST = INTERS | FIRST, + INTERS_SECOND = INTERS | SECOND + }; + + class ImagePairLess + { + public: + ImagePairLess(const std::vector<Mat> &images, const std::vector<Point> &corners) + : src_(&images[0]), corners_(&corners[0]) {} + + bool operator() (const std::pair<size_t, size_t> &l, const std::pair<size_t, size_t> &r) const + { + Point c1 = corners_[l.first] + Point(src_[l.first].cols / 2, src_[l.first].rows / 2); + Point c2 = corners_[l.second] + Point(src_[l.second].cols / 2, src_[l.second].rows / 2); + int d1 = (c1 - c2).dot(c1 - c2); + + c1 = corners_[r.first] + Point(src_[r.first].cols / 2, src_[r.first].rows / 2); + c2 = corners_[r.second] + Point(src_[r.second].cols / 2, src_[r.second].rows / 2); + int d2 = (c1 - c2).dot(c1 - c2); + + return d1 < d2; + } + + private: + const Mat *src_; + const Point *corners_; + }; + + class ClosePoints + { + public: + ClosePoints(int minDist) : minDist_(minDist) {} + + bool operator() (const Point &p1, const Point &p2) const + { + int dist2 = (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y); + return dist2 < minDist_ * minDist_; + } + + private: + int minDist_; + }; + + void process( + const Mat &image1, const Mat &image2, Point tl1, Point tl2, Mat &mask1, Mat &mask2); + + void findComponents(); + + void findEdges(); + + void resolveConflicts( + const Mat &image1, const Mat &image2, Point tl1, Point tl2, Mat &mask1, Mat &mask2); + + void computeGradients(const Mat &image1, const Mat &image2); + + bool hasOnlyOneNeighbor(int comp); + + bool closeToContour(int y, int x, const Mat_<uchar> &contourMask); + + bool getSeamTips(int comp1, int comp2, Point &p1, Point &p2); + + void computeCosts( + const Mat &image1, const Mat &image2, Point tl1, Point tl2, + int comp, Mat_<float> &costV, Mat_<float> &costH); + + bool estimateSeam( + const Mat &image1, const Mat &image2, Point tl1, Point tl2, int comp, + Point p1, Point p2, std::vector<Point> &seam, bool &isHorizontal); + + void updateLabelsUsingSeam( + int comp1, int comp2, const std::vector<Point> &seam, bool isHorizontalSeam); + + CostFunction costFunc_; + + // processing images pair data + Point unionTl_, unionBr_; + Size unionSize_; + Mat_<uchar> mask1_, mask2_; + Mat_<uchar> contour1mask_, contour2mask_; + Mat_<float> gradx1_, grady1_; + Mat_<float> gradx2_, grady2_; + + // components data + int ncomps_; + Mat_<int> labels_; + std::vector<ComponentState> states_; + std::vector<Point> tls_, brs_; + std::vector<std::vector<Point> > contours_; + std::set<std::pair<int, int> > edges_; +}; + +/** @brief Base class for all minimum graph-cut-based seam estimators. + */ +class CV_EXPORTS GraphCutSeamFinderBase +{ +public: + enum CostType { COST_COLOR, COST_COLOR_GRAD }; +}; + +/** @brief Minimum graph cut-based seam estimator. See details in @cite V03 . + */ +class CV_EXPORTS GraphCutSeamFinder : public GraphCutSeamFinderBase, public SeamFinder +{ +public: + GraphCutSeamFinder(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f, + float bad_region_penalty = 1000.f); + + ~GraphCutSeamFinder(); + + void find(const std::vector<UMat> &src, const std::vector<Point> &corners, + std::vector<UMat> &masks) CV_OVERRIDE; + +private: + // To avoid GCGraph dependency + class Impl; + Ptr<PairwiseSeamFinder> impl_; +}; + + +#ifdef HAVE_OPENCV_CUDALEGACY +class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder +{ +public: + GraphCutSeamFinderGpu(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f, + float bad_region_penalty = 1000.f) + : cost_type_(cost_type), terminal_cost_(terminal_cost), + bad_region_penalty_(bad_region_penalty) {} + + void find(const std::vector<cv::UMat> &src, const std::vector<cv::Point> &corners, + std::vector<cv::UMat> &masks) CV_OVERRIDE; + void findInPair(size_t first, size_t second, Rect roi) CV_OVERRIDE; + +private: + void setGraphWeightsColor(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &mask1, const cv::Mat &mask2, + cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom); + void setGraphWeightsColorGrad(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &dx1, const cv::Mat &dx2, + const cv::Mat &dy1, const cv::Mat &dy2, const cv::Mat &mask1, const cv::Mat &mask2, + cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom); + std::vector<Mat> dx_, dy_; + int cost_type_; + float terminal_cost_; + float bad_region_penalty_; +}; +#endif + +//! @} + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_SEAM_FINDERS_HPP diff --git a/include/opencv2/stitching/detail/timelapsers.hpp b/include/opencv2/stitching/detail/timelapsers.hpp new file mode 100644 index 0000000..74d797e --- /dev/null +++ b/include/opencv2/stitching/detail/timelapsers.hpp @@ -0,0 +1,91 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + + +#ifndef OPENCV_STITCHING_TIMELAPSERS_HPP +#define OPENCV_STITCHING_TIMELAPSERS_HPP + +#include "opencv2/core.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching +//! @{ + +// Base Timelapser class, takes a sequence of images, applies appropriate shift, stores result in dst_. + +class CV_EXPORTS Timelapser +{ +public: + + enum {AS_IS, CROP}; + + virtual ~Timelapser() {} + + static Ptr<Timelapser> createDefault(int type); + + virtual void initialize(const std::vector<Point> &corners, const std::vector<Size> &sizes); + virtual void process(InputArray img, InputArray mask, Point tl); + virtual const UMat& getDst() {return dst_;} + +protected: + + virtual bool test_point(Point pt); + + UMat dst_; + Rect dst_roi_; +}; + + +class CV_EXPORTS TimelapserCrop : public Timelapser +{ +public: + virtual void initialize(const std::vector<Point> &corners, const std::vector<Size> &sizes) CV_OVERRIDE; +}; + +//! @} + +} // namespace detail +} // namespace cv + +#endif // OPENCV_STITCHING_TIMELAPSERS_HPP diff --git a/include/opencv2/stitching/detail/util.hpp b/include/opencv2/stitching/detail/util.hpp new file mode 100644 index 0000000..78301b8 --- /dev/null +++ b/include/opencv2/stitching/detail/util.hpp @@ -0,0 +1,121 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_UTIL_HPP +#define OPENCV_STITCHING_UTIL_HPP + +#include <list> +#include "opencv2/core.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching +//! @{ + +class CV_EXPORTS DisjointSets +{ +public: + DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); } + + void createOneElemSets(int elem_count); + int findSetByElem(int elem); + int mergeSets(int set1, int set2); + + std::vector<int> parent; + std::vector<int> size; + +private: + std::vector<int> rank_; +}; + + +struct CV_EXPORTS GraphEdge +{ + GraphEdge(int from, int to, float weight); + bool operator <(const GraphEdge& other) const { return weight < other.weight; } + bool operator >(const GraphEdge& other) const { return weight > other.weight; } + + int from, to; + float weight; +}; + +inline GraphEdge::GraphEdge(int _from, int _to, float _weight) : from(_from), to(_to), weight(_weight) {} + + +class CV_EXPORTS Graph +{ +public: + Graph(int num_vertices = 0) { create(num_vertices); } + void create(int num_vertices) { edges_.assign(num_vertices, std::list<GraphEdge>()); } + int numVertices() const { return static_cast<int>(edges_.size()); } + void addEdge(int from, int to, float weight); + template <typename B> B forEach(B body) const; + template <typename B> B walkBreadthFirst(int from, B body) const; + +private: + std::vector< std::list<GraphEdge> > edges_; +}; + + +////////////////////////////////////////////////////////////////////////////// +// Auxiliary functions + +CV_EXPORTS bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi); +CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<UMat> &images); +CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes); +CV_EXPORTS Rect resultRoiIntersection(const std::vector<Point> &corners, const std::vector<Size> &sizes); +CV_EXPORTS Point resultTl(const std::vector<Point> &corners); + +// Returns random 'count' element subset of the {0,1,...,size-1} set +CV_EXPORTS void selectRandomSubset(int count, int size, std::vector<int> &subset); + +CV_EXPORTS int& stitchingLogLevel(); + +//! @} + +} // namespace detail +} // namespace cv + +#include "util_inl.hpp" + +#endif // OPENCV_STITCHING_UTIL_HPP diff --git a/include/opencv2/stitching/detail/util_inl.hpp b/include/opencv2/stitching/detail/util_inl.hpp new file mode 100644 index 0000000..dafab8b --- /dev/null +++ b/include/opencv2/stitching/detail/util_inl.hpp @@ -0,0 +1,131 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_UTIL_INL_HPP +#define OPENCV_STITCHING_UTIL_INL_HPP + +#include <queue> +#include "opencv2/core.hpp" +#include "util.hpp" // Make your IDE see declarations + +//! @cond IGNORED + +namespace cv { +namespace detail { + +template <typename B> +B Graph::forEach(B body) const +{ + for (int i = 0; i < numVertices(); ++i) + { + std::list<GraphEdge>::const_iterator edge = edges_[i].begin(); + for (; edge != edges_[i].end(); ++edge) + body(*edge); + } + return body; +} + + +template <typename B> +B Graph::walkBreadthFirst(int from, B body) const +{ + std::vector<bool> was(numVertices(), false); + std::queue<int> vertices; + + was[from] = true; + vertices.push(from); + + while (!vertices.empty()) + { + int vertex = vertices.front(); + vertices.pop(); + + std::list<GraphEdge>::const_iterator edge = edges_[vertex].begin(); + for (; edge != edges_[vertex].end(); ++edge) + { + if (!was[edge->to]) + { + body(*edge); + was[edge->to] = true; + vertices.push(edge->to); + } + } + } + + return body; +} + + +////////////////////////////////////////////////////////////////////////////// +// Some auxiliary math functions + +static inline +float normL2(const Point3f& a) +{ + return a.x * a.x + a.y * a.y + a.z * a.z; +} + + +static inline +float normL2(const Point3f& a, const Point3f& b) +{ + return normL2(a - b); +} + + +static inline +double normL2sq(const Mat &r) +{ + return r.dot(r); +} + + +static inline int sqr(int x) { return x * x; } +static inline float sqr(float x) { return x * x; } +static inline double sqr(double x) { return x * x; } + +} // namespace detail +} // namespace cv + +//! @endcond + +#endif // OPENCV_STITCHING_UTIL_INL_HPP diff --git a/include/opencv2/stitching/detail/warpers.hpp b/include/opencv2/stitching/detail/warpers.hpp new file mode 100644 index 0000000..1b05651 --- /dev/null +++ b/include/opencv2/stitching/detail/warpers.hpp @@ -0,0 +1,616 @@ + /*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_WARPERS_HPP +#define OPENCV_STITCHING_WARPERS_HPP + +#include "opencv2/core.hpp" +#include "opencv2/core/cuda.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/opencv_modules.hpp" + +namespace cv { +namespace detail { + +//! @addtogroup stitching_warp +//! @{ + +/** @brief Rotation-only model image warper interface. + */ +class CV_EXPORTS RotationWarper +{ +public: + virtual ~RotationWarper() {} + + /** @brief Projects the image point. + + @param pt Source point + @param K Camera intrinsic parameters + @param R Camera rotation matrix + @return Projected point + */ + virtual Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) = 0; + + /** @brief Builds the projection maps according to the given camera data. + + @param src_size Source image size + @param K Camera intrinsic parameters + @param R Camera rotation matrix + @param xmap Projection map for the x axis + @param ymap Projection map for the y axis + @return Projected image minimum bounding box + */ + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) = 0; + + /** @brief Projects the image. + + @param src Source image + @param K Camera intrinsic parameters + @param R Camera rotation matrix + @param interp_mode Interpolation mode + @param border_mode Border extrapolation mode + @param dst Projected image + @return Project image top-left corner + */ + virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) = 0; + + /** @brief Projects the image backward. + + @param src Projected image + @param K Camera intrinsic parameters + @param R Camera rotation matrix + @param interp_mode Interpolation mode + @param border_mode Border extrapolation mode + @param dst_size Backward-projected image size + @param dst Backward-projected image + */ + virtual void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + Size dst_size, OutputArray dst) = 0; + + /** + @param src_size Source image bounding box + @param K Camera intrinsic parameters + @param R Camera rotation matrix + @return Projected image minimum bounding box + */ + virtual Rect warpRoi(Size src_size, InputArray K, InputArray R) = 0; + + virtual float getScale() const { return 1.f; } + virtual void setScale(float) {} +}; + +/** @brief Base class for warping logic implementation. + */ +struct CV_EXPORTS ProjectorBase +{ + void setCameraParams(InputArray K = Mat::eye(3, 3, CV_32F), + InputArray R = Mat::eye(3, 3, CV_32F), + InputArray T = Mat::zeros(3, 1, CV_32F)); + + float scale; + float k[9]; + float rinv[9]; + float r_kinv[9]; + float k_rinv[9]; + float t[3]; +}; + +/** @brief Base class for rotation-based warper using a detail::ProjectorBase_ derived class. + */ +template <class P> +class CV_EXPORTS_TEMPLATE RotationWarperBase : public RotationWarper +{ +public: + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE; + + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE; + + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) CV_OVERRIDE; + + void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + Size dst_size, OutputArray dst) CV_OVERRIDE; + + Rect warpRoi(Size src_size, InputArray K, InputArray R) CV_OVERRIDE; + + float getScale() const CV_OVERRIDE{ return projector_.scale; } + void setScale(float val) CV_OVERRIDE { projector_.scale = val; } + +protected: + + // Detects ROI of the destination image. It's correct for any projection. + virtual void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br); + + // Detects ROI of the destination image by walking over image border. + // Correctness for any projection isn't guaranteed. + void detectResultRoiByBorder(Size src_size, Point &dst_tl, Point &dst_br); + + P projector_; +}; + + +struct CV_EXPORTS PlaneProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + +/** @brief Warper that maps an image onto the z = 1 plane. + */ +class CV_EXPORTS PlaneWarper : public RotationWarperBase<PlaneProjector> +{ +public: + /** @brief Construct an instance of the plane warper class. + + @param scale Projected image scale multiplier + */ + PlaneWarper(float scale = 1.f) { projector_.scale = scale; } + + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE; + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T); + + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap); + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE; + + Point warp(InputArray src, InputArray K, InputArray R, + int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE; + virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + OutputArray dst); + + Rect warpRoi(Size src_size, InputArray K, InputArray R) CV_OVERRIDE; + Rect warpRoi(Size src_size, InputArray K, InputArray R, InputArray T); + +protected: + void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE; +}; + + +/** @brief Affine warper that uses rotations and translations + + Uses affine transformation in homogeneous coordinates to represent both rotation and + translation in camera rotation matrix. + */ +class CV_EXPORTS AffineWarper : public PlaneWarper +{ +public: + /** @brief Construct an instance of the affine warper class. + + @param scale Projected image scale multiplier + */ + AffineWarper(float scale = 1.f) : PlaneWarper(scale) {} + + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE; + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE; + Point warp(InputArray src, InputArray K, InputArray R, + int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE; + Rect warpRoi(Size src_size, InputArray K, InputArray R) CV_OVERRIDE; + +protected: + /** @brief Extracts rotation and translation matrices from matrix H representing + affine transformation in homogeneous coordinates + */ + void getRTfromHomogeneous(InputArray H, Mat &R, Mat &T); +}; + + +struct CV_EXPORTS SphericalProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +/** @brief Warper that maps an image onto the unit sphere located at the origin. + + Projects image onto unit sphere with origin at (0, 0, 0) and radius scale, measured in pixels. + A 360 panorama would therefore have a resulting width of 2 * scale * PI pixels. + Poles are located at (0, -1, 0) and (0, 1, 0) points. +*/ +class CV_EXPORTS SphericalWarper : public RotationWarperBase<SphericalProjector> +{ +public: + /** @brief Construct an instance of the spherical warper class. + + @param scale Radius of the projected sphere, in pixels. An image spanning the + whole sphere will have a width of 2 * scale * PI pixels. + */ + SphericalWarper(float scale) { projector_.scale = scale; } + + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE; + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE; +protected: + void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE; +}; + + +struct CV_EXPORTS CylindricalProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +/** @brief Warper that maps an image onto the x\*x + z\*z = 1 cylinder. + */ +class CV_EXPORTS CylindricalWarper : public RotationWarperBase<CylindricalProjector> +{ +public: + /** @brief Construct an instance of the cylindrical warper class. + + @param scale Projected image scale multiplier + */ + CylindricalWarper(float scale) { projector_.scale = scale; } + + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE; + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE; +protected: + void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE + { + RotationWarperBase<CylindricalProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br); + } +}; + + +struct CV_EXPORTS FisheyeProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS FisheyeWarper : public RotationWarperBase<FisheyeProjector> +{ +public: + FisheyeWarper(float scale) { projector_.scale = scale; } +}; + + +struct CV_EXPORTS StereographicProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS StereographicWarper : public RotationWarperBase<StereographicProjector> +{ +public: + StereographicWarper(float scale) { projector_.scale = scale; } +}; + + +struct CV_EXPORTS CompressedRectilinearProjector : ProjectorBase +{ + float a, b; + + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS CompressedRectilinearWarper : public RotationWarperBase<CompressedRectilinearProjector> +{ +public: + CompressedRectilinearWarper(float scale, float A = 1, float B = 1) + { + projector_.a = A; + projector_.b = B; + projector_.scale = scale; + } +}; + + +struct CV_EXPORTS CompressedRectilinearPortraitProjector : ProjectorBase +{ + float a, b; + + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS CompressedRectilinearPortraitWarper : public RotationWarperBase<CompressedRectilinearPortraitProjector> +{ +public: + CompressedRectilinearPortraitWarper(float scale, float A = 1, float B = 1) + { + projector_.a = A; + projector_.b = B; + projector_.scale = scale; + } +}; + + +struct CV_EXPORTS PaniniProjector : ProjectorBase +{ + float a, b; + + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS PaniniWarper : public RotationWarperBase<PaniniProjector> +{ +public: + PaniniWarper(float scale, float A = 1, float B = 1) + { + projector_.a = A; + projector_.b = B; + projector_.scale = scale; + } +}; + + +struct CV_EXPORTS PaniniPortraitProjector : ProjectorBase +{ + float a, b; + + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS PaniniPortraitWarper : public RotationWarperBase<PaniniPortraitProjector> +{ +public: + PaniniPortraitWarper(float scale, float A = 1, float B = 1) + { + projector_.a = A; + projector_.b = B; + projector_.scale = scale; + } + +}; + + +struct CV_EXPORTS MercatorProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS MercatorWarper : public RotationWarperBase<MercatorProjector> +{ +public: + MercatorWarper(float scale) { projector_.scale = scale; } +}; + + +struct CV_EXPORTS TransverseMercatorProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS TransverseMercatorWarper : public RotationWarperBase<TransverseMercatorProjector> +{ +public: + TransverseMercatorWarper(float scale) { projector_.scale = scale; } +}; + + +class CV_EXPORTS PlaneWarperGpu : public PlaneWarper +{ +public: + PlaneWarperGpu(float scale = 1.f) : PlaneWarper(scale) {} + + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE + { + Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_); + d_xmap_.download(xmap); + d_ymap_.download(ymap); + return result; + } + + Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap) CV_OVERRIDE + { + Rect result = buildMaps(src_size, K, R, T, d_xmap_, d_ymap_); + d_xmap_.download(xmap); + d_ymap_.download(ymap); + return result; + } + + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) CV_OVERRIDE + { + d_src_.upload(src); + Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_); + d_dst_.download(dst); + return result; + } + + Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + OutputArray dst) CV_OVERRIDE + { + d_src_.upload(src); + Point result = warp(d_src_, K, R, T, interp_mode, border_mode, d_dst_); + d_dst_.download(dst); + return result; + } + + Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap); + + Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, cuda::GpuMat & xmap, cuda::GpuMat & ymap); + + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst); + + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + cuda::GpuMat & dst); + +private: + cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; +}; + + +class CV_EXPORTS SphericalWarperGpu : public SphericalWarper +{ +public: + SphericalWarperGpu(float scale) : SphericalWarper(scale) {} + + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE + { + Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_); + d_xmap_.download(xmap); + d_ymap_.download(ymap); + return result; + } + + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) CV_OVERRIDE + { + d_src_.upload(src); + Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_); + d_dst_.download(dst); + return result; + } + + Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap); + + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst); + +private: + cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; +}; + + +class CV_EXPORTS CylindricalWarperGpu : public CylindricalWarper +{ +public: + CylindricalWarperGpu(float scale) : CylindricalWarper(scale) {} + + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE + { + Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_); + d_xmap_.download(xmap); + d_ymap_.download(ymap); + return result; + } + + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) CV_OVERRIDE + { + d_src_.upload(src); + Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_); + d_dst_.download(dst); + return result; + } + + Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap); + + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst); + +private: + cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; +}; + + +struct CV_EXPORTS SphericalPortraitProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +// Projects image onto unit sphere with origin at (0, 0, 0). +// Poles are located NOT at (0, -1, 0) and (0, 1, 0) points, BUT at (1, 0, 0) and (-1, 0, 0) points. +class CV_EXPORTS SphericalPortraitWarper : public RotationWarperBase<SphericalPortraitProjector> +{ +public: + SphericalPortraitWarper(float scale) { projector_.scale = scale; } + +protected: + void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE; +}; + +struct CV_EXPORTS CylindricalPortraitProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS CylindricalPortraitWarper : public RotationWarperBase<CylindricalPortraitProjector> +{ +public: + CylindricalPortraitWarper(float scale) { projector_.scale = scale; } + +protected: + void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE + { + RotationWarperBase<CylindricalPortraitProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br); + } +}; + +struct CV_EXPORTS PlanePortraitProjector : ProjectorBase +{ + void mapForward(float x, float y, float &u, float &v); + void mapBackward(float u, float v, float &x, float &y); +}; + + +class CV_EXPORTS PlanePortraitWarper : public RotationWarperBase<PlanePortraitProjector> +{ +public: + PlanePortraitWarper(float scale) { projector_.scale = scale; } + +protected: + void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE + { + RotationWarperBase<PlanePortraitProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br); + } +}; + +//! @} stitching_warp + +} // namespace detail +} // namespace cv + +#include "warpers_inl.hpp" + +#endif // OPENCV_STITCHING_WARPERS_HPP diff --git a/include/opencv2/stitching/detail/warpers_inl.hpp b/include/opencv2/stitching/detail/warpers_inl.hpp new file mode 100644 index 0000000..f4a19d9 --- /dev/null +++ b/include/opencv2/stitching/detail/warpers_inl.hpp @@ -0,0 +1,774 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_WARPERS_INL_HPP +#define OPENCV_STITCHING_WARPERS_INL_HPP + +#include "opencv2/core.hpp" +#include "warpers.hpp" // Make your IDE see declarations +#include <limits> + +//! @cond IGNORED + +namespace cv { +namespace detail { + +template <class P> +Point2f RotationWarperBase<P>::warpPoint(const Point2f &pt, InputArray K, InputArray R) +{ + projector_.setCameraParams(K, R); + Point2f uv; + projector_.mapForward(pt.x, pt.y, uv.x, uv.y); + return uv; +} + + +template <class P> +Rect RotationWarperBase<P>::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray _xmap, OutputArray _ymap) +{ + projector_.setCameraParams(K, R); + + Point dst_tl, dst_br; + detectResultRoi(src_size, dst_tl, dst_br); + + _xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + _ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + + Mat xmap = _xmap.getMat(), ymap = _ymap.getMat(); + + float x, y; + for (int v = dst_tl.y; v <= dst_br.y; ++v) + { + for (int u = dst_tl.x; u <= dst_br.x; ++u) + { + projector_.mapBackward(static_cast<float>(u), static_cast<float>(v), x, y); + xmap.at<float>(v - dst_tl.y, u - dst_tl.x) = x; + ymap.at<float>(v - dst_tl.y, u - dst_tl.x) = y; + } + } + + return Rect(dst_tl, dst_br); +} + + +template <class P> +Point RotationWarperBase<P>::warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) +{ + UMat xmap, ymap; + Rect dst_roi = buildMaps(src.size(), K, R, xmap, ymap); + + dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); + remap(src, dst, xmap, ymap, interp_mode, border_mode); + + return dst_roi.tl(); +} + + +template <class P> +void RotationWarperBase<P>::warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + Size dst_size, OutputArray dst) +{ + projector_.setCameraParams(K, R); + + Point src_tl, src_br; + detectResultRoi(dst_size, src_tl, src_br); + + Size size = src.size(); + CV_Assert(src_br.x - src_tl.x + 1 == size.width && src_br.y - src_tl.y + 1 == size.height); + + Mat xmap(dst_size, CV_32F); + Mat ymap(dst_size, CV_32F); + + float u, v; + for (int y = 0; y < dst_size.height; ++y) + { + for (int x = 0; x < dst_size.width; ++x) + { + projector_.mapForward(static_cast<float>(x), static_cast<float>(y), u, v); + xmap.at<float>(y, x) = u - src_tl.x; + ymap.at<float>(y, x) = v - src_tl.y; + } + } + + dst.create(dst_size, src.type()); + remap(src, dst, xmap, ymap, interp_mode, border_mode); +} + + +template <class P> +Rect RotationWarperBase<P>::warpRoi(Size src_size, InputArray K, InputArray R) +{ + projector_.setCameraParams(K, R); + + Point dst_tl, dst_br; + detectResultRoi(src_size, dst_tl, dst_br); + + return Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)); +} + + +template <class P> +void RotationWarperBase<P>::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) +{ + float tl_uf = (std::numeric_limits<float>::max)(); + float tl_vf = (std::numeric_limits<float>::max)(); + float br_uf = -(std::numeric_limits<float>::max)(); + float br_vf = -(std::numeric_limits<float>::max)(); + + float u, v; + for (int y = 0; y < src_size.height; ++y) + { + for (int x = 0; x < src_size.width; ++x) + { + projector_.mapForward(static_cast<float>(x), static_cast<float>(y), u, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); + } + } + + dst_tl.x = static_cast<int>(tl_uf); + dst_tl.y = static_cast<int>(tl_vf); + dst_br.x = static_cast<int>(br_uf); + dst_br.y = static_cast<int>(br_vf); +} + + +template <class P> +void RotationWarperBase<P>::detectResultRoiByBorder(Size src_size, Point &dst_tl, Point &dst_br) +{ + float tl_uf = (std::numeric_limits<float>::max)(); + float tl_vf = (std::numeric_limits<float>::max)(); + float br_uf = -(std::numeric_limits<float>::max)(); + float br_vf = -(std::numeric_limits<float>::max)(); + + float u, v; + for (float x = 0; x < src_size.width; ++x) + { + projector_.mapForward(static_cast<float>(x), 0, u, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); + + projector_.mapForward(static_cast<float>(x), static_cast<float>(src_size.height - 1), u, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); + } + for (int y = 0; y < src_size.height; ++y) + { + projector_.mapForward(0, static_cast<float>(y), u, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); + + projector_.mapForward(static_cast<float>(src_size.width - 1), static_cast<float>(y), u, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); + } + + dst_tl.x = static_cast<int>(tl_uf); + dst_tl.y = static_cast<int>(tl_vf); + dst_br.x = static_cast<int>(br_uf); + dst_br.y = static_cast<int>(br_vf); +} + + +inline +void PlaneProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + x_ = t[0] + x_ / z_ * (1 - t[2]); + y_ = t[1] + y_ / z_ * (1 - t[2]); + + u = scale * x_; + v = scale * y_; +} + + +inline +void PlaneProjector::mapBackward(float u, float v, float &x, float &y) +{ + u = u / scale - t[0]; + v = v / scale - t[1]; + + float z; + x = k_rinv[0] * u + k_rinv[1] * v + k_rinv[2] * (1 - t[2]); + y = k_rinv[3] * u + k_rinv[4] * v + k_rinv[5] * (1 - t[2]); + z = k_rinv[6] * u + k_rinv[7] * v + k_rinv[8] * (1 - t[2]); + + x /= z; + y /= z; +} + + +inline +void SphericalProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + u = scale * atan2f(x_, z_); + float w = y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_); + v = scale * (static_cast<float>(CV_PI) - acosf(w == w ? w : 0)); +} + + +inline +void SphericalProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float sinv = sinf(static_cast<float>(CV_PI) - v); + float x_ = sinv * sinf(u); + float y_ = cosf(static_cast<float>(CV_PI) - v); + float z_ = sinv * cosf(u); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + + +inline +void CylindricalProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + u = scale * atan2f(x_, z_); + v = scale * y_ / sqrtf(x_ * x_ + z_ * z_); +} + + +inline +void CylindricalProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float x_ = sinf(u); + float y_ = v; + float z_ = cosf(u); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void FisheyeProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = (float)CV_PI - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + u = scale * v_ * cosf(u_); + v = scale * v_ * sinf(u_); +} + +inline +void FisheyeProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float u_ = atan2f(v, u); + float v_ = sqrtf(u*u + v*v); + + float sinv = sinf((float)CV_PI - v_); + float x_ = sinv * sinf(u_); + float y_ = cosf((float)CV_PI - v_); + float z_ = sinv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void StereographicProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = (float)CV_PI - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + float r = sinf(v_) / (1 - cosf(v_)); + + u = scale * r * cos(u_); + v = scale * r * sin(u_); +} + +inline +void StereographicProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float u_ = atan2f(v, u); + float r = sqrtf(u*u + v*v); + float v_ = 2 * atanf(1.f / r); + + float sinv = sinf((float)CV_PI - v_); + float x_ = sinv * sinf(u_); + float y_ = cosf((float)CV_PI - v_); + float z_ = sinv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void CompressedRectilinearProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + u = scale * a * tanf(u_ / a); + v = scale * b * tanf(v_) / cosf(u_); +} + +inline +void CompressedRectilinearProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float aatg = a * atanf(u / a); + float u_ = aatg; + float v_ = atanf(v * cosf(aatg) / b); + + float cosv = cosf(v_); + float x_ = cosv * sinf(u_); + float y_ = sinf(v_); + float z_ = cosv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void CompressedRectilinearPortraitProjector::mapForward(float x, float y, float &u, float &v) +{ + float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float x_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + u = - scale * a * tanf(u_ / a); + v = scale * b * tanf(v_) / cosf(u_); +} + +inline +void CompressedRectilinearPortraitProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= - scale; + v /= scale; + + float aatg = a * atanf(u / a); + float u_ = aatg; + float v_ = atanf(v * cosf( aatg ) / b); + + float cosv = cosf(v_); + float y_ = cosv * sinf(u_); + float x_ = sinf(v_); + float z_ = cosv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void PaniniProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + float tg = a * tanf(u_ / a); + u = scale * tg; + + float sinu = sinf(u_); + if ( fabs(sinu) < 1E-7 ) + v = scale * b * tanf(v_); + else + v = scale * b * tg * tanf(v_) / sinu; +} + +inline +void PaniniProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float lamda = a * atanf(u / a); + float u_ = lamda; + + float v_; + if ( fabs(lamda) > 1E-7) + v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda / a))); + else + v_ = atanf(v / b); + + float cosv = cosf(v_); + float x_ = cosv * sinf(u_); + float y_ = sinf(v_); + float z_ = cosv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void PaniniPortraitProjector::mapForward(float x, float y, float &u, float &v) +{ + float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float x_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + float tg = a * tanf(u_ / a); + u = - scale * tg; + + float sinu = sinf( u_ ); + if ( fabs(sinu) < 1E-7 ) + v = scale * b * tanf(v_); + else + v = scale * b * tg * tanf(v_) / sinu; +} + +inline +void PaniniPortraitProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= - scale; + v /= scale; + + float lamda = a * atanf(u / a); + float u_ = lamda; + + float v_; + if ( fabs(lamda) > 1E-7) + v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda/a))); + else + v_ = atanf(v / b); + + float cosv = cosf(v_); + float y_ = cosv * sinf(u_); + float x_ = sinf(v_); + float z_ = cosv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void MercatorProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + u = scale * u_; + v = scale * logf( tanf( (float)(CV_PI/4) + v_/2 ) ); +} + +inline +void MercatorProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float v_ = atanf( sinhf(v) ); + float u_ = u; + + float cosv = cosf(v_); + float x_ = cosv * sinf(u_); + float y_ = sinf(v_); + float z_ = cosv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void TransverseMercatorProjector::mapForward(float x, float y, float &u, float &v) +{ + float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float u_ = atan2f(x_, z_); + float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)); + + float B = cosf(v_) * sinf(u_); + + u = scale / 2 * logf( (1+B) / (1-B) ); + v = scale * atan2f(tanf(v_), cosf(u_)); +} + +inline +void TransverseMercatorProjector::mapBackward(float u, float v, float &x, float &y) +{ + u /= scale; + v /= scale; + + float v_ = asinf( sinf(v) / coshf(u) ); + float u_ = atan2f( sinhf(u), cos(v) ); + + float cosv = cosf(v_); + float x_ = cosv * sinf(u_); + float y_ = sinf(v_); + float z_ = cosv * cosf(u_); + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void SphericalPortraitProjector::mapForward(float x, float y, float &u0, float &v0) +{ + float x0_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y0_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float x_ = y0_; + float y_ = x0_; + float u, v; + + u = scale * atan2f(x_, z_); + v = scale * (static_cast<float>(CV_PI) - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_))); + + u0 = -u;//v; + v0 = v;//u; +} + + +inline +void SphericalPortraitProjector::mapBackward(float u0, float v0, float &x, float &y) +{ + float u, v; + u = -u0;//v0; + v = v0;//u0; + + u /= scale; + v /= scale; + + float sinv = sinf(static_cast<float>(CV_PI) - v); + float x0_ = sinv * sinf(u); + float y0_ = cosf(static_cast<float>(CV_PI) - v); + float z_ = sinv * cosf(u); + + float x_ = y0_; + float y_ = x0_; + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void CylindricalPortraitProjector::mapForward(float x, float y, float &u0, float &v0) +{ + float x0_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y0_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float x_ = y0_; + float y_ = x0_; + float u, v; + + u = scale * atan2f(x_, z_); + v = scale * y_ / sqrtf(x_ * x_ + z_ * z_); + + u0 = -u;//v; + v0 = v;//u; +} + + +inline +void CylindricalPortraitProjector::mapBackward(float u0, float v0, float &x, float &y) +{ + float u, v; + u = -u0;//v0; + v = v0;//u0; + + u /= scale; + v /= scale; + + float x0_ = sinf(u); + float y0_ = v; + float z_ = cosf(u); + + float x_ = y0_; + float y_ = x0_; + + float z; + x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_; + y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_; + z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_; + + if (z > 0) { x /= z; y /= z; } + else x = y = -1; +} + +inline +void PlanePortraitProjector::mapForward(float x, float y, float &u0, float &v0) +{ + float x0_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2]; + float y0_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5]; + float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8]; + + float x_ = y0_; + float y_ = x0_; + + x_ = t[0] + x_ / z_ * (1 - t[2]); + y_ = t[1] + y_ / z_ * (1 - t[2]); + + float u,v; + u = scale * x_; + v = scale * y_; + + u0 = -u; + v0 = v; +} + + +inline +void PlanePortraitProjector::mapBackward(float u0, float v0, float &x, float &y) +{ + float u, v; + u = -u0; + v = v0; + + u = u / scale - t[0]; + v = v / scale - t[1]; + + float z; + x = k_rinv[0] * v + k_rinv[1] * u + k_rinv[2] * (1 - t[2]); + y = k_rinv[3] * v + k_rinv[4] * u + k_rinv[5] * (1 - t[2]); + z = k_rinv[6] * v + k_rinv[7] * u + k_rinv[8] * (1 - t[2]); + + x /= z; + y /= z; +} + + +} // namespace detail +} // namespace cv + +//! @endcond + +#endif // OPENCV_STITCHING_WARPERS_INL_HPP diff --git a/include/opencv2/stitching/warpers.hpp b/include/opencv2/stitching/warpers.hpp new file mode 100644 index 0000000..cf7699c --- /dev/null +++ b/include/opencv2/stitching/warpers.hpp @@ -0,0 +1,192 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_STITCHING_WARPER_CREATORS_HPP +#define OPENCV_STITCHING_WARPER_CREATORS_HPP + +#include "opencv2/stitching/detail/warpers.hpp" + +namespace cv { + +//! @addtogroup stitching_warp +//! @{ + +/** @brief Image warper factories base class. + */ +class WarperCreator +{ +public: + virtual ~WarperCreator() {} + virtual Ptr<detail::RotationWarper> create(float scale) const = 0; +}; + +/** @brief Plane warper factory class. + @sa detail::PlaneWarper + */ +class PlaneWarper : public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PlaneWarper>(scale); } +}; + +/** @brief Affine warper factory class. + @sa detail::AffineWarper + */ +class AffineWarper : public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::AffineWarper>(scale); } +}; + +/** @brief Cylindrical warper factory class. +@sa detail::CylindricalWarper +*/ +class CylindricalWarper: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CylindricalWarper>(scale); } +}; + +/** @brief Spherical warper factory class */ +class SphericalWarper: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::SphericalWarper>(scale); } +}; + +class FisheyeWarper : public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::FisheyeWarper>(scale); } +}; + +class StereographicWarper: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::StereographicWarper>(scale); } +}; + +class CompressedRectilinearWarper: public WarperCreator +{ + float a, b; +public: + CompressedRectilinearWarper(float A = 1, float B = 1) + { + a = A; b = B; + } + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CompressedRectilinearWarper>(scale, a, b); } +}; + +class CompressedRectilinearPortraitWarper: public WarperCreator +{ + float a, b; +public: + CompressedRectilinearPortraitWarper(float A = 1, float B = 1) + { + a = A; b = B; + } + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CompressedRectilinearPortraitWarper>(scale, a, b); } +}; + +class PaniniWarper: public WarperCreator +{ + float a, b; +public: + PaniniWarper(float A = 1, float B = 1) + { + a = A; b = B; + } + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PaniniWarper>(scale, a, b); } +}; + +class PaniniPortraitWarper: public WarperCreator +{ + float a, b; +public: + PaniniPortraitWarper(float A = 1, float B = 1) + { + a = A; b = B; + } + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PaniniPortraitWarper>(scale, a, b); } +}; + +class MercatorWarper: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::MercatorWarper>(scale); } +}; + +class TransverseMercatorWarper: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::TransverseMercatorWarper>(scale); } +}; + + + +#ifdef HAVE_OPENCV_CUDAWARPING +class PlaneWarperGpu: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PlaneWarperGpu>(scale); } +}; + + +class CylindricalWarperGpu: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CylindricalWarperGpu>(scale); } +}; + + +class SphericalWarperGpu: public WarperCreator +{ +public: + Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::SphericalWarperGpu>(scale); } +}; +#endif + +//! @} stitching_warp + +} // namespace cv + +#endif // OPENCV_STITCHING_WARPER_CREATORS_HPP diff --git a/include/opencv2/structured_light.hpp b/include/opencv2/structured_light.hpp new file mode 100644 index 0000000..4508d89 --- /dev/null +++ b/include/opencv2/structured_light.hpp @@ -0,0 +1,68 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +/*#ifdef __OPENCV_BUILD + #error this is a compatibility header which should not be used inside the OpenCV library + #endif*/ + +#include "opencv2/structured_light/structured_light.hpp" +#include "opencv2/structured_light/graycodepattern.hpp" +#include "opencv2/structured_light/sinusoidalpattern.hpp" + +/** @defgroup structured_light Structured Light API + + Structured light is considered one of the most effective techniques to acquire 3D models. + This technique is based on projecting a light pattern and capturing the illuminated scene + from one or more points of view. Since the pattern is coded, correspondences between image + points and points of the projected pattern can be quickly found and 3D information easily + retrieved. + + One of the most commonly exploited coding strategies is based on trmatime-multiplexing. In this + case, a set of patterns are successively projected onto the measuring surface. + The codeword for a given pixel is usually formed by the sequence of illuminance values for that + pixel across the projected patterns. Thus, the codification is called temporal because the bits + of the codewords are multiplexed in time @cite pattern . + + In this module a time-multiplexing coding strategy based on Gray encoding is implemented following the + (stereo) approach described in 3DUNDERWORLD algorithm @cite UNDERWORLD . + For more details, see @ref tutorial_structured_light. + + */ \ No newline at end of file diff --git a/include/opencv2/structured_light/graycodepattern.hpp b/include/opencv2/structured_light/graycodepattern.hpp new file mode 100644 index 0000000..f1d6331 --- /dev/null +++ b/include/opencv2/structured_light/graycodepattern.hpp @@ -0,0 +1,149 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_GRAY_CODE_PATTERN_HPP__ +#define __OPENCV_GRAY_CODE_PATTERN_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/structured_light/structured_light.hpp" + +namespace cv { +namespace structured_light { +//! @addtogroup structured_light +//! @{ + +/** @brief Class implementing the Gray-code pattern, based on @cite UNDERWORLD. + * + * The generation of the pattern images is performed with Gray encoding using the traditional white and black colors. + * + * The information about the two image axes x, y is encoded separately into two different pattern sequences. + * A projector P with resolution (P_res_x, P_res_y) will result in Ncols = log 2 (P_res_x) encoded pattern images representing the columns, and + * in Nrows = log 2 (P_res_y) encoded pattern images representing the rows. + * For example a projector with resolution 1024x768 will result in Ncols = 10 and Nrows = 10. + + * However, the generated pattern sequence consists of both regular color and color-inverted images: inverted pattern images are images + * with the same structure as the original but with inverted colors. + * This provides an effective method for easily determining the intensity value of each pixel when it is lit (highest value) and + * when it is not lit (lowest value). So for a a projector with resolution 1024x768, the number of pattern images will be Ncols * 2 + Nrows * 2 = 40. + * + */ +class CV_EXPORTS_W GrayCodePattern : public StructuredLightPattern +{ + public: + + /** @brief Parameters of StructuredLightPattern constructor. + * @param width Projector's width. Default value is 1024. + * @param height Projector's height. Default value is 768. + */ + struct CV_EXPORTS Params + { + Params(); + int width; + int height; + }; + + /** @brief Constructor + @param parameters GrayCodePattern parameters GrayCodePattern::Params: the width and the height of the projector. + */ + static Ptr<GrayCodePattern> create( const GrayCodePattern::Params ¶meters = GrayCodePattern::Params() ); + + // alias for scripting + CV_WRAP + static Ptr<GrayCodePattern> create( int width, int height ); + + /** @brief Get the number of pattern images needed for the graycode pattern. + * + * @return The number of pattern images needed for the graycode pattern. + * + */ + CV_WRAP + virtual size_t getNumberOfPatternImages() const = 0; + + /** @brief Sets the value for white threshold, needed for decoding. + * + * White threshold is a number between 0-255 that represents the minimum brightness difference required for valid pixels, between the graycode pattern and its inverse images; used in getProjPixel method. + * + * @param value The desired white threshold value. + * + */ + CV_WRAP + virtual void setWhiteThreshold( size_t value ) = 0; + + /** @brief Sets the value for black threshold, needed for decoding (shadowsmasks computation). + * + * Black threshold is a number between 0-255 that represents the minimum brightness difference required for valid pixels, between the fully illuminated (white) and the not illuminated images (black); used in computeShadowMasks method. + * + * @param value The desired black threshold value. + * + */ + CV_WRAP + virtual void setBlackThreshold( size_t value ) = 0; + + /** @brief Generates the all-black and all-white images needed for shadowMasks computation. + * + * To identify shadow regions, the regions of two images where the pixels are not lit by projector's light and thus where there is not coded information, + * the 3DUNDERWORLD algorithm computes a shadow mask for the two cameras views, starting from a white and a black images captured by each camera. + * This method generates these two additional images to project. + * + * @param blackImage The generated all-black CV_8U image, at projector's resolution. + * @param whiteImage The generated all-white CV_8U image, at projector's resolution. + */ + CV_WRAP + virtual void getImagesForShadowMasks( InputOutputArray blackImage, InputOutputArray whiteImage ) const = 0; + + /** @brief For a (x,y) pixel of a camera returns the corresponding projector pixel. + * + * The function decodes each pixel in the pattern images acquired by a camera into their corresponding decimal numbers representing the projector's column and row, + * providing a mapping between camera's and projector's pixel. + * + * @param patternImages The pattern images acquired by the camera, stored in a grayscale vector < Mat >. + * @param x x coordinate of the image pixel. + * @param y y coordinate of the image pixel. + * @param projPix Projector's pixel corresponding to the camera's pixel: projPix.x and projPix.y are the image coordinates of the projector's pixel corresponding to the pixel being decoded in a camera. + */ + CV_WRAP + virtual bool getProjPixel( InputArrayOfArrays patternImages, int x, int y, CV_OUT Point &projPix ) const = 0; +}; + +//! @} +} +} +#endif diff --git a/include/opencv2/structured_light/sinusoidalpattern.hpp b/include/opencv2/structured_light/sinusoidalpattern.hpp new file mode 100644 index 0000000..0942552 --- /dev/null +++ b/include/opencv2/structured_light/sinusoidalpattern.hpp @@ -0,0 +1,151 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_SINUSOIDAL_PATTERN_HPP__ +#define __OPENCV_SINUSOIDAL_PATTERN_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/structured_light/structured_light.hpp" +#include <opencv2/phase_unwrapping.hpp> +#include <opencv2/calib3d.hpp> + +namespace cv { +namespace structured_light { +//! @addtogroup structured_light +//! @{ + + //! Type of sinusoidal pattern profilometry methods. +enum{ + FTP = 0, + PSP = 1, + FAPS = 2 + }; +/** + * @brief Class implementing Fourier transform profilometry (FTP) , phase-shifting profilometry (PSP) + * and Fourier-assisted phase-shifting profilometry (FAPS) based on @cite faps. + + * This class generates sinusoidal patterns that can be used with FTP, PSP and FAPS. +*/ +class CV_EXPORTS_W SinusoidalPattern : public StructuredLightPattern +{ +public: + /** + * @brief Parameters of SinusoidalPattern constructor + * @param width Projector's width. + * @param height Projector's height. + * @param nbrOfPeriods Number of period along the patterns direction. + * @param shiftValue Phase shift between two consecutive patterns. + * @param methodId Allow to choose between FTP, PSP and FAPS. + * @param nbrOfPixelsBetweenMarkers Number of pixels between two consecutive markers on the same row. + * @param setMarkers Allow to set markers on the patterns. + * @param markersLocation vector used to store markers location on the patterns. + */ + struct CV_EXPORTS_W Params + { + CV_WRAP Params(); + CV_PROP_RW int width; + CV_PROP_RW int height; + CV_PROP_RW int nbrOfPeriods; + CV_PROP_RW float shiftValue; + CV_PROP_RW int methodId; + CV_PROP_RW int nbrOfPixelsBetweenMarkers; + CV_PROP_RW bool horizontal; + CV_PROP_RW bool setMarkers; + std::vector<Point2f> markersLocation; + }; + /** + * @brief Constructor. + * @param parameters SinusoidalPattern parameters SinusoidalPattern::Params: width, height of the projector and patterns parameters. + * + */ + CV_WRAP static Ptr<SinusoidalPattern> create( Ptr<SinusoidalPattern::Params> parameters = + makePtr<SinusoidalPattern::Params>() ); + /** + * @brief Compute a wrapped phase map from sinusoidal patterns. + * @param patternImages Input data to compute the wrapped phase map. + * @param wrappedPhaseMap Wrapped phase map obtained through one of the three methods. + * @param shadowMask Mask used to discard shadow regions. + * @param fundamental Fundamental matrix used to compute epipolar lines and ease the matching step. + */ + CV_WRAP + virtual void computePhaseMap( InputArrayOfArrays patternImages, + OutputArray wrappedPhaseMap, + OutputArray shadowMask = noArray(), + InputArray fundamental = noArray()) = 0; + /** + * @brief Unwrap the wrapped phase map to remove phase ambiguities. + * @param wrappedPhaseMap The wrapped phase map computed from the pattern. + * @param unwrappedPhaseMap The unwrapped phase map used to find correspondences between the two devices. + * @param camSize Resolution of the camera. + * @param shadowMask Mask used to discard shadow regions. + */ + CV_WRAP + virtual void unwrapPhaseMap( InputArrayOfArrays wrappedPhaseMap, + OutputArray unwrappedPhaseMap, + cv::Size camSize, + InputArray shadowMask = noArray() ) = 0; + /** + * @brief Find correspondences between the two devices thanks to unwrapped phase maps. + * @param projUnwrappedPhaseMap Projector's unwrapped phase map. + * @param camUnwrappedPhaseMap Camera's unwrapped phase map. + * @param matches Images used to display correspondences map. + */ + CV_WRAP + virtual void findProCamMatches( InputArray projUnwrappedPhaseMap, InputArray camUnwrappedPhaseMap, + OutputArrayOfArrays matches ) = 0; + + /** + * @brief compute the data modulation term. + * @param patternImages captured images with projected patterns. + * @param dataModulationTerm Mat where the data modulation term is saved. + * @param shadowMask Mask used to discard shadow regions. + */ + CV_WRAP + virtual void computeDataModulationTerm( InputArrayOfArrays patternImages, + OutputArray dataModulationTerm, + InputArray shadowMask ) = 0; + +}; +//! @} +} +} +#endif diff --git a/include/opencv2/structured_light/structured_light.hpp b/include/opencv2/structured_light/structured_light.hpp new file mode 100644 index 0000000..4d4b6fa --- /dev/null +++ b/include/opencv2/structured_light/structured_light.hpp @@ -0,0 +1,91 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_STRUCTURED_LIGHT_HPP__ +#define __OPENCV_STRUCTURED_LIGHT_HPP__ + +#include "opencv2/core.hpp" + +namespace cv { +namespace structured_light { +//! @addtogroup structured_light +//! @{ + +//! Type of the decoding algorithm +// other algorithms can be implemented +enum +{ + DECODE_3D_UNDERWORLD = 0 //!< Kyriakos Herakleous, Charalambos Poullis. "3DUNDERWORLD-SLS: An Open-Source Structured-Light Scanning System for Rapid Geometry Acquisition", arXiv preprint arXiv:1406.6595 (2014). +}; + +/** @brief Abstract base class for generating and decoding structured light patterns. + */ +class CV_EXPORTS_W StructuredLightPattern : public virtual Algorithm +{ + public: + /** @brief Generates the structured light pattern to project. + + @param patternImages The generated pattern: a vector<Mat>, in which each image is a CV_8U Mat at projector's resolution. + */ + CV_WRAP + virtual bool generate( OutputArrayOfArrays patternImages ) = 0; + + /** @brief Decodes the structured light pattern, generating a disparity map + + @param patternImages The acquired pattern images to decode (vector<vector<Mat>>), loaded as grayscale and previously rectified. + @param disparityMap The decoding result: a CV_64F Mat at image resolution, storing the computed disparity map. + @param blackImages The all-black images needed for shadowMasks computation. + @param whiteImages The all-white images needed for shadowMasks computation. + @param flags Flags setting decoding algorithms. Default: DECODE_3D_UNDERWORLD. + @note All the images must be at the same resolution. + */ + CV_WRAP + virtual bool decode( const std::vector< std::vector<Mat> >& patternImages, OutputArray disparityMap, + InputArrayOfArrays blackImages = noArray(), + InputArrayOfArrays whiteImages = noArray(), + int flags = DECODE_3D_UNDERWORLD ) const = 0; +}; + +//! @} + +} +} +#endif diff --git a/include/opencv2/superres.hpp b/include/opencv2/superres.hpp new file mode 100644 index 0000000..16c11ac --- /dev/null +++ b/include/opencv2/superres.hpp @@ -0,0 +1,207 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_SUPERRES_HPP +#define OPENCV_SUPERRES_HPP + +#include "opencv2/core.hpp" +#include "opencv2/superres/optical_flow.hpp" + +/** + @defgroup superres Super Resolution + +The Super Resolution module contains a set of functions and classes that can be used to solve the +problem of resolution enhancement. There are a few methods implemented, most of them are described in +the papers @cite Farsiu03 and @cite Mitzel09 . + + */ + +namespace cv +{ + namespace superres + { + +//! @addtogroup superres +//! @{ + + class CV_EXPORTS FrameSource + { + public: + virtual ~FrameSource(); + + virtual void nextFrame(OutputArray frame) = 0; + virtual void reset() = 0; + }; + + CV_EXPORTS Ptr<FrameSource> createFrameSource_Empty(); + + CV_EXPORTS Ptr<FrameSource> createFrameSource_Video(const String& fileName); + CV_EXPORTS Ptr<FrameSource> createFrameSource_Video_CUDA(const String& fileName); + + CV_EXPORTS Ptr<FrameSource> createFrameSource_Camera(int deviceId = 0); + + /** @brief Base class for Super Resolution algorithms. + + The class is only used to define the common interface for the whole family of Super Resolution + algorithms. + */ + class CV_EXPORTS SuperResolution : public cv::Algorithm, public FrameSource + { + public: + /** @brief Set input frame source for Super Resolution algorithm. + + @param frameSource Input frame source + */ + void setInput(const Ptr<FrameSource>& frameSource); + + /** @brief Process next frame from input and return output result. + + @param frame Output result + */ + void nextFrame(OutputArray frame) CV_OVERRIDE; + void reset() CV_OVERRIDE; + + /** @brief Clear all inner buffers. + */ + virtual void collectGarbage(); + + //! @brief Scale factor + /** @see setScale */ + virtual int getScale() const = 0; + /** @copybrief getScale @see getScale */ + virtual void setScale(int val) = 0; + + //! @brief Iterations count + /** @see setIterations */ + virtual int getIterations() const = 0; + /** @copybrief getIterations @see getIterations */ + virtual void setIterations(int val) = 0; + + //! @brief Asymptotic value of steepest descent method + /** @see setTau */ + virtual double getTau() const = 0; + /** @copybrief getTau @see getTau */ + virtual void setTau(double val) = 0; + + //! @brief Weight parameter to balance data term and smoothness term + /** @see setLabmda */ + virtual double getLabmda() const = 0; + /** @copybrief getLabmda @see getLabmda */ + virtual void setLabmda(double val) = 0; + + //! @brief Parameter of spacial distribution in Bilateral-TV + /** @see setAlpha */ + virtual double getAlpha() const = 0; + /** @copybrief getAlpha @see getAlpha */ + virtual void setAlpha(double val) = 0; + + //! @brief Kernel size of Bilateral-TV filter + /** @see setKernelSize */ + virtual int getKernelSize() const = 0; + /** @copybrief getKernelSize @see getKernelSize */ + virtual void setKernelSize(int val) = 0; + + //! @brief Gaussian blur kernel size + /** @see setBlurKernelSize */ + virtual int getBlurKernelSize() const = 0; + /** @copybrief getBlurKernelSize @see getBlurKernelSize */ + virtual void setBlurKernelSize(int val) = 0; + + //! @brief Gaussian blur sigma + /** @see setBlurSigma */ + virtual double getBlurSigma() const = 0; + /** @copybrief getBlurSigma @see getBlurSigma */ + virtual void setBlurSigma(double val) = 0; + + //! @brief Radius of the temporal search area + /** @see setTemporalAreaRadius */ + virtual int getTemporalAreaRadius() const = 0; + /** @copybrief getTemporalAreaRadius @see getTemporalAreaRadius */ + virtual void setTemporalAreaRadius(int val) = 0; + + //! @brief Dense optical flow algorithm + /** @see setOpticalFlow */ + virtual Ptr<cv::superres::DenseOpticalFlowExt> getOpticalFlow() const = 0; + /** @copybrief getOpticalFlow @see getOpticalFlow */ + virtual void setOpticalFlow(const Ptr<cv::superres::DenseOpticalFlowExt> &val) = 0; + + protected: + SuperResolution(); + + virtual void initImpl(Ptr<FrameSource>& frameSource) = 0; + virtual void processImpl(Ptr<FrameSource>& frameSource, OutputArray output) = 0; + + bool isUmat_; + + private: + Ptr<FrameSource> frameSource_; + bool firstCall_; + }; + + /** @brief Create Bilateral TV-L1 Super Resolution. + + This class implements Super Resolution algorithm described in the papers @cite Farsiu03 and + @cite Mitzel09 . + + Here are important members of the class that control the algorithm, which you can set after + constructing the class instance: + + - **int scale** Scale factor. + - **int iterations** Iteration count. + - **double tau** Asymptotic value of steepest descent method. + - **double lambda** Weight parameter to balance data term and smoothness term. + - **double alpha** Parameter of spacial distribution in Bilateral-TV. + - **int btvKernelSize** Kernel size of Bilateral-TV filter. + - **int blurKernelSize** Gaussian blur kernel size. + - **double blurSigma** Gaussian blur sigma. + - **int temporalAreaRadius** Radius of the temporal search area. + - **Ptr\<DenseOpticalFlowExt\> opticalFlow** Dense optical flow algorithm. + */ + CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1(); + CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1_CUDA(); + +//! @} superres + + } +} + +#endif // OPENCV_SUPERRES_HPP diff --git a/include/opencv2/superres/optical_flow.hpp b/include/opencv2/superres/optical_flow.hpp new file mode 100644 index 0000000..07e7ca9 --- /dev/null +++ b/include/opencv2/superres/optical_flow.hpp @@ -0,0 +1,203 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_SUPERRES_OPTICAL_FLOW_HPP +#define OPENCV_SUPERRES_OPTICAL_FLOW_HPP + +#include "opencv2/core.hpp" + +namespace cv +{ + namespace superres + { + +//! @addtogroup superres +//! @{ + + class CV_EXPORTS DenseOpticalFlowExt : public cv::Algorithm + { + public: + virtual void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2 = noArray()) = 0; + virtual void collectGarbage() = 0; + }; + + + class CV_EXPORTS FarnebackOpticalFlow : public virtual DenseOpticalFlowExt + { + public: + /** @see setPyrScale */ + virtual double getPyrScale() const = 0; + /** @copybrief getPyrScale @see getPyrScale */ + virtual void setPyrScale(double val) = 0; + /** @see setLevelsNumber */ + virtual int getLevelsNumber() const = 0; + /** @copybrief getLevelsNumber @see getLevelsNumber */ + virtual void setLevelsNumber(int val) = 0; + /** @see setWindowSize */ + virtual int getWindowSize() const = 0; + /** @copybrief getWindowSize @see getWindowSize */ + virtual void setWindowSize(int val) = 0; + /** @see setIterations */ + virtual int getIterations() const = 0; + /** @copybrief getIterations @see getIterations */ + virtual void setIterations(int val) = 0; + /** @see setPolyN */ + virtual int getPolyN() const = 0; + /** @copybrief getPolyN @see getPolyN */ + virtual void setPolyN(int val) = 0; + /** @see setPolySigma */ + virtual double getPolySigma() const = 0; + /** @copybrief getPolySigma @see getPolySigma */ + virtual void setPolySigma(double val) = 0; + /** @see setFlags */ + virtual int getFlags() const = 0; + /** @copybrief getFlags @see getFlags */ + virtual void setFlags(int val) = 0; + }; + CV_EXPORTS Ptr<FarnebackOpticalFlow> createOptFlow_Farneback(); + CV_EXPORTS Ptr<FarnebackOpticalFlow> createOptFlow_Farneback_CUDA(); + + +// CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_Simple(); + + + class CV_EXPORTS DualTVL1OpticalFlow : public virtual DenseOpticalFlowExt + { + public: + /** @see setTau */ + virtual double getTau() const = 0; + /** @copybrief getTau @see getTau */ + virtual void setTau(double val) = 0; + /** @see setLambda */ + virtual double getLambda() const = 0; + /** @copybrief getLambda @see getLambda */ + virtual void setLambda(double val) = 0; + /** @see setTheta */ + virtual double getTheta() const = 0; + /** @copybrief getTheta @see getTheta */ + virtual void setTheta(double val) = 0; + /** @see setScalesNumber */ + virtual int getScalesNumber() const = 0; + /** @copybrief getScalesNumber @see getScalesNumber */ + virtual void setScalesNumber(int val) = 0; + /** @see setWarpingsNumber */ + virtual int getWarpingsNumber() const = 0; + /** @copybrief getWarpingsNumber @see getWarpingsNumber */ + virtual void setWarpingsNumber(int val) = 0; + /** @see setEpsilon */ + virtual double getEpsilon() const = 0; + /** @copybrief getEpsilon @see getEpsilon */ + virtual void setEpsilon(double val) = 0; + /** @see setIterations */ + virtual int getIterations() const = 0; + /** @copybrief getIterations @see getIterations */ + virtual void setIterations(int val) = 0; + /** @see setUseInitialFlow */ + virtual bool getUseInitialFlow() const = 0; + /** @copybrief getUseInitialFlow @see getUseInitialFlow */ + virtual void setUseInitialFlow(bool val) = 0; + }; + CV_EXPORTS Ptr<DualTVL1OpticalFlow> createOptFlow_DualTVL1(); + CV_EXPORTS Ptr<DualTVL1OpticalFlow> createOptFlow_DualTVL1_CUDA(); + + + class CV_EXPORTS BroxOpticalFlow : public virtual DenseOpticalFlowExt + { + public: + //! @brief Flow smoothness + /** @see setAlpha */ + virtual double getAlpha() const = 0; + /** @copybrief getAlpha @see getAlpha */ + virtual void setAlpha(double val) = 0; + //! @brief Gradient constancy importance + /** @see setGamma */ + virtual double getGamma() const = 0; + /** @copybrief getGamma @see getGamma */ + virtual void setGamma(double val) = 0; + //! @brief Pyramid scale factor + /** @see setScaleFactor */ + virtual double getScaleFactor() const = 0; + /** @copybrief getScaleFactor @see getScaleFactor */ + virtual void setScaleFactor(double val) = 0; + //! @brief Number of lagged non-linearity iterations (inner loop) + /** @see setInnerIterations */ + virtual int getInnerIterations() const = 0; + /** @copybrief getInnerIterations @see getInnerIterations */ + virtual void setInnerIterations(int val) = 0; + //! @brief Number of warping iterations (number of pyramid levels) + /** @see setOuterIterations */ + virtual int getOuterIterations() const = 0; + /** @copybrief getOuterIterations @see getOuterIterations */ + virtual void setOuterIterations(int val) = 0; + //! @brief Number of linear system solver iterations + /** @see setSolverIterations */ + virtual int getSolverIterations() const = 0; + /** @copybrief getSolverIterations @see getSolverIterations */ + virtual void setSolverIterations(int val) = 0; + }; + CV_EXPORTS Ptr<BroxOpticalFlow> createOptFlow_Brox_CUDA(); + + + class PyrLKOpticalFlow : public virtual DenseOpticalFlowExt + { + public: + /** @see setWindowSize */ + virtual int getWindowSize() const = 0; + /** @copybrief getWindowSize @see getWindowSize */ + virtual void setWindowSize(int val) = 0; + /** @see setMaxLevel */ + virtual int getMaxLevel() const = 0; + /** @copybrief getMaxLevel @see getMaxLevel */ + virtual void setMaxLevel(int val) = 0; + /** @see setIterations */ + virtual int getIterations() const = 0; + /** @copybrief getIterations @see getIterations */ + virtual void setIterations(int val) = 0; + }; + CV_EXPORTS Ptr<PyrLKOpticalFlow> createOptFlow_PyrLK_CUDA(); + +//! @} + + } +} + +#endif // OPENCV_SUPERRES_OPTICAL_FLOW_HPP diff --git a/include/opencv2/surface_matching.hpp b/include/opencv2/surface_matching.hpp new file mode 100644 index 0000000..6cf5f9d --- /dev/null +++ b/include/opencv2/surface_matching.hpp @@ -0,0 +1,402 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +#ifndef __OPENCV_SURFACE_MATCHING_HPP__ +#define __OPENCV_SURFACE_MATCHING_HPP__ + +#include "surface_matching/ppf_match_3d.hpp" +#include "surface_matching/icp.hpp" + +/** @defgroup surface_matching Surface Matching + +Note about the License and Patents +----------------------------------- + +The following patents have been issued for methods embodied in this +software: "Recognition and pose determination of 3D objects in 3D scenes +using geometric point pair descriptors and the generalized Hough +Transform", Bertram Heinrich Drost, Markus Ulrich, EP Patent 2385483 +(Nov. 21, 2012), assignee: MVTec Software GmbH, 81675 Muenchen +(Germany); "Recognition and pose determination of 3D objects in 3D +scenes", Bertram Heinrich Drost, Markus Ulrich, US Patent 8830229 (Sept. +9, 2014), assignee: MVTec Software GmbH, 81675 Muenchen (Germany). +Further patents are pending. For further details, contact MVTec Software +GmbH (info@mvtec.com). + +Note that restrictions imposed by these patents (and possibly others) +exist independently of and may be in conflict with the freedoms granted +in this license, which refers to copyright of the program, not patents +for any methods that it implements. Both copyright and patent law must +be obeyed to legally use and redistribute this program and it is not the +purpose of this license to induce you to infringe any patents or other +property right claims or to contest validity of any such claims. If you +redistribute or use the program, then this license merely protects you +from committing copyright infringement. It does not protect you from +committing patent infringement. So, before you do anything with this +program, make sure that you have permission to do so not merely in terms +of copyright, but also in terms of patent law. + +Please note that this license is not to be understood as a guarantee +either. If you use the program according to this license, but in +conflict with patent law, it does not mean that the licensor will refund +you for any losses that you incur if you are sued for your patent +infringement. + + +Introduction to Surface Matching +-------------------------------- + +Cameras and similar devices with the capability of sensation of 3D structure are becoming more +common. Thus, using depth and intensity information for matching 3D objects (or parts) are of +crucial importance for computer vision. Applications range from industrial control to guiding +everyday actions for visually impaired people. The task in recognition and pose estimation in range +images aims to identify and localize a queried 3D free-form object by matching it to the acquired +database. + +From an industrial perspective, enabling robots to automatically locate and pick up randomly placed +and oriented objects from a bin is an important challenge in factory automation, replacing tedious +and heavy manual labor. A system should be able to recognize and locate objects with a predefined +shape and estimate the position with the precision necessary for a gripping robot to pick it up. +This is where vision guided robotics takes the stage. Similar tools are also capable of guiding +robots (and even people) through unstructured environments, leading to automated navigation. These +properties make 3D matching from point clouds a ubiquitous necessity. Within this context, I will +now describe the OpenCV implementation of a 3D object recognition and pose estimation algorithm +using 3D features. + +Surface Matching Algorithm Through 3D Features +---------------------------------------------- + +The state of the algorithms in order to achieve the task 3D matching is heavily based on +@cite drost2010, which is one of the first and main practical methods presented in this area. The +approach is composed of extracting 3D feature points randomly from depth images or generic point +clouds, indexing them and later in runtime querying them efficiently. Only the 3D structure is +considered, and a trivial hash table is used for feature queries. + +While being fully aware that utilization of the nice CAD model structure in order to achieve a smart +point sampling, I will be leaving that aside now in order to respect the generalizability of the +methods (Typically for such algorithms training on a CAD model is not needed, and a point cloud +would be sufficient). Below is the outline of the entire algorithm: + +![Outline of the Algorithm](img/outline.jpg) + +As explained, the algorithm relies on the extraction and indexing of point pair features, which are +defined as follows: + +\f[\bf{{F}}(\bf{{m1}}, \bf{{m2}}) = (||\bf{{d}}||_2, <(\bf{{n1}},\bf{{d}}), <(\bf{{n2}},\bf{{d}}), <(\bf{{n1}},\bf{{n2}}))\f] + +where \f$\bf{{m1}}\f$ and \f$\bf{{m2}}\f$ are feature two selected points on the model (or scene), +\f$\bf{{d}}\f$ is the difference vector, \f$\bf{{n1}}\f$ and \f$\bf{{n2}}\f$ are the normals at \f$\bf{{m1}}\f$ and +\f$\bf{m2}\f$. During the training stage, this vector is quantized, indexed. In the test stage, same +features are extracted from the scene and compared to the database. With a few tricks like +separation of the rotational components, the pose estimation part can also be made efficient (check +the reference for more details). A Hough-like voting and clustering is employed to estimate the +object pose. To cluster the poses, the raw pose hypotheses are sorted in decreasing order of the +number of votes. From the highest vote, a new cluster is created. If the next pose hypothesis is +close to one of the existing clusters, the hypothesis is added to the cluster and the cluster center +is updated as the average of the pose hypotheses within the cluster. If the next hypothesis is not +close to any of the clusters, it creates a new cluster. The proximity testing is done with fixed +thresholds in translation and rotation. Distance computation and averaging for translation are +performed in the 3D Euclidean space, while those for rotation are performed using quaternion +representation. After clustering, the clusters are sorted in decreasing order of the total number of +votes which determines confidence of the estimated poses. + +This pose is further refined using \f$ICP\f$ in order to obtain the final pose. + +PPF presented above depends largely on robust computation of angles between 3D vectors. Even though +not reported in the paper, the naive way of doing this (\f$\theta = cos^{-1}({\bf{a}}\cdot{\bf{b}})\f$ +remains numerically unstable. A better way to do this is then use inverse tangents, like: + +\f[<(\bf{n1},\bf{n2})=tan^{-1}(||{\bf{n1} \wedge \bf{n2}}||_2, \bf{n1} \cdot \bf{n2})\f] + +Rough Computation of Object Pose Given PPF +------------------------------------------ + +Let me summarize the following notation: + +- \f$p^i_m\f$: \f$i^{th}\f$ point of the model (\f$p^j_m\f$ accordingly) +- \f$n^i_m\f$: Normal of the \f$i^{th}\f$ point of the model (\f$n^j_m\f$ accordingly) +- \f$p^i_s\f$: \f$i^{th}\f$ point of the scene (\f$p^j_s\f$ accordingly) +- \f$n^i_s\f$: Normal of the \f$i^{th}\f$ point of the scene (\f$n^j_s\f$ accordingly) +- \f$T_{m\rightarrow g}\f$: The transformation required to translate \f$p^i_m\f$ to the origin and rotate + its normal \f$n^i_m\f$ onto the \f$x\f$-axis. +- \f$R_{m\rightarrow g}\f$: Rotational component of \f$T_{m\rightarrow g}\f$. +- \f$t_{m\rightarrow g}\f$: Translational component of \f$T_{m\rightarrow g}\f$. +- \f$(p^i_m)^{'}\f$: \f$i^{th}\f$ point of the model transformed by \f$T_{m\rightarrow g}\f$. (\f$(p^j_m)^{'}\f$ + accordingly). +- \f${\bf{R_{m\rightarrow g}}}\f$: Axis angle representation of rotation \f$R_{m\rightarrow g}\f$. +- \f$\theta_{m\rightarrow g}\f$: The angular component of the axis angle representation + \f${\bf{R_{m\rightarrow g}}}\f$. + +The transformation in a point pair feature is computed by first finding the transformation +\f$T_{m\rightarrow g}\f$ from the first point, and applying the same transformation to the second one. +Transforming each point, together with the normal, to the ground plane leaves us with an angle to +find out, during a comparison with a new point pair. + +We could now simply start writing + +\f[(p^i_m)^{'} = T_{m\rightarrow g} p^i_m\f] + +where + +\f[T_{m\rightarrow g} = -t_{m\rightarrow g}R_{m\rightarrow g}\f] + +Note that this is nothing but a stacked transformation. The translational component +\f$t_{m\rightarrow g}\f$ reads + +\f[t_{m\rightarrow g} = -R_{m\rightarrow g}p^i_m\f] + +and the rotational being + +\f[\theta_{m\rightarrow g} = \cos^{-1}(n^i_m \cdot {\bf{x}})\\ + {\bf{R_{m\rightarrow g}}} = n^i_m \wedge {\bf{x}}\f] + +in axis angle format. Note that bold refers to the vector form. After this transformation, the +feature vectors of the model are registered onto the ground plane X and the angle with respect to +\f$x=0\f$ is called \f$\alpha_m\f$. Similarly, for the scene, it is called \f$\alpha_s\f$. + +### Hough-like Voting Scheme + +As shown in the outline, PPF (point pair features) are extracted from the model, quantized, stored +in the hashtable and indexed, during the training stage. During the runtime however, the similar +operation is perfomed on the input scene with the exception that this time a similarity lookup over +the hashtable is performed, instead of an insertion. This lookup also allows us to compute a +transformation to the ground plane for the scene pairs. After this point, computing the rotational +component of the pose reduces to computation of the difference \f$\alpha=\alpha_m-\alpha_s\f$. This +component carries the cue about the object pose. A Hough-like voting scheme is performed over the +local model coordinate vector and \f$\alpha\f$. The highest poses achieved for every scene point lets us +recover the object pose. + +### Source Code for PPF Matching + +~~~{cpp} +// pc is the loaded point cloud of the model +// (Nx6) and pcTest is a loaded point cloud of +// the scene (Mx6) +ppf_match_3d::PPF3DDetector detector(0.03, 0.05); +detector.trainModel(pc); +vector<Pose3DPtr> results; +detector.match(pcTest, results, 1.0/10.0, 0.05); +cout << "Poses: " << endl; +// print the poses +for (size_t i=0; i<results.size(); i++) +{ + Pose3DPtr pose = results[i]; + cout << "Pose Result " << i << endl; + pose->printPose(); +} +~~~ + +Pose Registration via ICP +------------------------- + +The matching process terminates with the attainment of the pose. However, due to the multiple +matching points, erroneous hypothesis, pose averaging and etc. such pose is very open to noise and +many times is far from being perfect. Although the visual results obtained in that stage are +pleasing, the quantitative evaluation shows \f$~10\f$ degrees variation (error), which is an acceptable +level of matching. Many times, the requirement might be set well beyond this margin and it is +desired to refine the computed pose. + +Furthermore, in typical RGBD scenes and point clouds, 3D structure can capture only less than half +of the model due to the visibility in the scene. Therefore, a robust pose refinement algorithm, +which can register occluded and partially visible shapes quickly and correctly is not an unrealistic +wish. + +At this point, a trivial option would be to use the well known iterative closest point algorithm . +However, utilization of the basic ICP leads to slow convergence, bad registration, outlier +sensitivity and failure to register partial shapes. Thus, it is definitely not suited to the +problem. For this reason, many variants have been proposed . Different variants contribute to +different stages of the pose estimation process. + +ICP is composed of \f$6\f$ stages and the improvements I propose for each stage is summarized below. + +### Sampling + +To improve convergence speed and computation time, it is common to use less points than the model +actually has. However, sampling the correct points to register is an issue in itself. The naive way +would be to sample uniformly and hope to get a reasonable subset. More smarter ways try to identify +the critical points, which are found to highly contribute to the registration process. Gelfand et. +al. exploit the covariance matrix in order to constrain the eigenspace, so that a set of points +which affect both translation and rotation are used. This is a clever way of subsampling, which I +will optionally be using in the implementation. + +### Correspondence Search + +As the name implies, this step is actually the assignment of the points in the data and the model in +a closest point fashion. Correct assignments will lead to a correct pose, where wrong assignments +strongly degrade the result. In general, KD-trees are used in the search of nearest neighbors, to +increase the speed. However this is not an optimality guarantee and many times causes wrong points +to be matched. Luckily the assignments are corrected over iterations. + +To overcome some of the limitations, Picky ICP @cite pickyicp and BC-ICP (ICP using bi-unique +correspondences) are two well-known methods. Picky ICP first finds the correspondences in the +old-fashioned way and then among the resulting corresponding pairs, if more than one scene point +\f$p_i\f$ is assigned to the same model point \f$m_j\f$, it selects \f$p_i\f$ that corresponds to the minimum +distance. BC-ICP on the other hand, allows multiple correspondences first and then resolves the +assignments by establishing bi-unique correspondences. It also defines a novel no-correspondence +outlier, which intrinsically eases the process of identifying outliers. + +For reference, both methods are used. Because P-ICP is a bit faster, with not-so-significant +performance drawback, it will be the method of choice in refinment of correspondences. + +### Weighting of Pairs + +In my implementation, I currently do not use a weighting scheme. But the common approaches involve +*normal compatibility* (\f$w_i=n^1_i\cdot n^2_j\f$) or assigning lower weights to point pairs with +greater distances (\f$w=1-\frac{||dist(m_i,s_i)||_2}{dist_{max}}\f$). + +### Rejection of Pairs + +The rejections are done using a dynamic thresholding based on a robust estimate of the standard +deviation. In other words, in each iteration, I find the MAD estimate of the Std. Dev. I denote this +as \f$mad_i\f$. I reject the pairs with distances \f$d_i>\tau mad_i\f$. Here \f$\tau\f$ is the threshold of +rejection and by default set to \f$3\f$. The weighting is applied prior to Picky refinement, explained +in the previous stage. + +### Error Metric + +As described in , a linearization of point to plane as in @cite koklimlow error metric is used. This +both speeds up the registration process and improves convergence. + +### Minimization + +Even though many non-linear optimizers (such as Levenberg Mardquardt) are proposed, due to the +linearization in the previous step, pose estimation reduces to solving a linear system of equations. +This is what I do exactly using cv::solve with DECOMP_SVD option. + +### ICP Algorithm + +Having described the steps above, here I summarize the layout of the ICP algorithm. + +#### Efficient ICP Through Point Cloud Pyramids + +While the up-to-now-proposed variants deal well with some outliers and bad initializations, they +require significant number of iterations. Yet, multi-resolution scheme can help reducing the number +of iterations by allowing the registration to start from a coarse level and propagate to the lower +and finer levels. Such approach both improves the performances and enhances the runtime. + +The search is done through multiple levels, in a hierarchical fashion. The registration starts with +a very coarse set of samples of the model. Iteratively, the points are densified and sought. After +each iteration the previously estimated pose is used as an initial pose and refined with the ICP. + +#### Visual Results + +##### Results on Synthetic Data + +In all of the results, the pose is initiated by PPF and the rest is left as: +\f$[\theta_x, \theta_y, \theta_z, t_x, t_y, t_z]=[0]\f$ + +### Source Code for Pose Refinement Using ICP + +~~~{cpp} +ICP icp(200, 0.001f, 2.5f, 8); +// Using the previously declared pc and pcTest +// This will perform registration for every pose +// contained in results +icp.registerModelToScene(pc, pcTest, results); + +// results now contain the refined poses +~~~ + +Results +------- + +This section is dedicated to the results of surface matching (point-pair-feature matching and a +following ICP refinement): + +![Several matches of a single frog model using ppf + icp](img/gsoc_forg_matches.jpg) + +Matches of different models for Mian dataset is presented below: + +![Matches of different models for Mian dataset](img/snapshot27.jpg) + +You might checkout the video on [youTube here](http://www.youtube.com/watch?v=uFnqLFznuZU). + +A Complete Sample +----------------- + +### Parameter Tuning + +Surface matching module treats its parameters relative to the model diameter (diameter of the axis +parallel bounding box), whenever it can. This makes the parameters independent from the model size. +This is why, both model and scene cloud were subsampled such that all points have a minimum distance +of \f$RelativeSamplingStep*DimensionRange\f$, where \f$DimensionRange\f$ is the distance along a given +dimension. All three dimensions are sampled in similar manner. For example, if +\f$RelativeSamplingStep\f$ is set to 0.05 and the diameter of model is 1m (1000mm), the points sampled +from the object's surface will be approximately 50 mm apart. From another point of view, if the +sampling RelativeSamplingStep is set to 0.05, at most \f$20x20x20 = 8000\f$ model points are generated +(depending on how the model fills in the volume). Consequently this results in at most 8000x8000 +pairs. In practice, because the models are not uniformly distributed over a rectangular prism, much +less points are to be expected. Decreasing this value, results in more model points and thus a more +accurate representation. However, note that number of point pair features to be computed is now +quadratically increased as the complexity is O(N\^2). This is especially a concern for 32 bit +systems, where large models can easily overshoot the available memory. Typically, values in the +range of 0.025 - 0.05 seem adequate for most of the applications, where the default value is 0.03. +(Note that there is a difference in this paremeter with the one presented in @cite drost2010 . In +@cite drost2010 a uniform cuboid is used for quantization and model diameter is used for reference of +sampling. In my implementation, the cuboid is a rectangular prism, and each dimension is quantized +independently. I do not take reference from the diameter but along the individual dimensions. + +It would very wise to remove the outliers from the model and prepare an ideal model initially. This +is because, the outliers directly affect the relative computations and degrade the matching +accuracy. + +During runtime stage, the scene is again sampled by \f$RelativeSamplingStep\f$, as described above. +However this time, only a portion of the scene points are used as reference. This portion is +controlled by the parameter \f$RelativeSceneSampleStep\f$, where +\f$SceneSampleStep = (int)(1.0/RelativeSceneSampleStep)\f$. In other words, if the +\f$RelativeSceneSampleStep = 1.0/5.0\f$, the subsampled scene will once again be uniformly sampled to +1/5 of the number of points. Maximum value of this parameter is 1 and increasing this parameter also +increases the stability, but decreases the speed. Again, because of the initial scene-independent +relative sampling, fine tuning this parameter is not a big concern. This would only be an issue when +the model shape occupies a volume uniformly, or when the model shape is condensed in a tiny place +within the quantization volume (e.g. The octree representation would have too much empty cells). + +\f$RelativeDistanceStep\f$ acts as a step of discretization over the hash table. The point pair features +are quantized to be mapped to the buckets of the hashtable. This discretization involves a +multiplication and a casting to the integer. Adjusting RelativeDistanceStep in theory controls the +collision rate. Note that, more collisions on the hashtable results in less accurate estimations. +Reducing this parameter increases the affect of quantization but starts to assign non-similar point +pairs to the same bins. Increasing it however, wanes the ability to group the similar pairs. +Generally, because during the sampling stage, the training model points are selected uniformly with +a distance controlled by RelativeSamplingStep, RelativeDistanceStep is expected to equate to this +value. Yet again, values in the range of 0.025-0.05 are sensible. This time however, when the model +is dense, it is not advised to decrease this value. For noisy scenes, the value can be increased to +improve the robustness of the matching against noisy points. + +*/ + +#endif diff --git a/include/opencv2/surface_matching/icp.hpp b/include/opencv2/surface_matching/icp.hpp new file mode 100644 index 0000000..123120a --- /dev/null +++ b/include/opencv2/surface_matching/icp.hpp @@ -0,0 +1,170 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. + +/** + * @file + * + * @brief Implementation of ICP (Iterative Closest Point) Algorithm + * @author Tolga Birdal <tbirdal AT gmail.com> + */ + +#ifndef __OPENCV_SURFACE_MATCHING_ICP_HPP__ +#define __OPENCV_SURFACE_MATCHING_ICP_HPP__ + +#include <opencv2/core.hpp> + +#include "pose_3d.hpp" +#include <vector> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +/** +* @brief This class implements a very efficient and robust variant of the iterative closest point (ICP) algorithm. +* The task is to register a 3D model (or point cloud) against a set of noisy target data. The variants are put together +* by myself after certain tests. The task is to be able to match partial, noisy point clouds in cluttered scenes, quickly. +* You will find that my emphasis is on the performance, while retaining the accuracy. +* This implementation is based on Tolga Birdal's MATLAB implementation in here: +* http://www.mathworks.com/matlabcentral/fileexchange/47152-icp-registration-using-efficient-variants-and-multi-resolution-scheme +* The main contributions come from: +* 1. Picky ICP: +* http://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2003/Zinsser03-ARI.pdf +* 2. Efficient variants of the ICP Algorithm: +* http://docs.happycoders.org/orgadoc/graphics/imaging/fasticp_paper.pdf +* 3. Geometrically Stable Sampling for the ICP Algorithm: https://graphics.stanford.edu/papers/stabicp/stabicp.pdf +* 4. Multi-resolution registration: +* http://www.cvl.iis.u-tokyo.ac.jp/~oishi/Papers/Alignment/Jost_MultiResolutionICP_3DIM03.pdf +* 5. Linearization of Point-to-Plane metric by Kok Lim Low: +* https://www.comp.nus.edu.sg/~lowkl/publications/lowk_point-to-plane_icp_techrep.pdf +*/ +class CV_EXPORTS_W ICP +{ +public: + + CV_WRAP enum + { + ICP_SAMPLING_TYPE_UNIFORM = 0, + ICP_SAMPLING_TYPE_GELFAND = 1 + }; + + CV_WRAP ICP() + { + m_tolerance = 0.005f; + m_rejectionScale = 2.5f; + m_maxIterations = 250; + m_numLevels = 6; + m_sampleType = ICP_SAMPLING_TYPE_UNIFORM; + m_numNeighborsCorr = 1; + } + + virtual ~ICP() { } + + /** + * \brief ICP constructor with default arguments. + * @param [in] iterations + * @param [in] tolerence Controls the accuracy of registration at each iteration of ICP. + * @param [in] rejectionScale Robust outlier rejection is applied for robustness. This value + actually corresponds to the standard deviation coefficient. Points with + rejectionScale * &sigma are ignored during registration. + * @param [in] numLevels Number of pyramid levels to proceed. Deep pyramids increase speed but + decrease accuracy. Too coarse pyramids might have computational overhead on top of the + inaccurate registrtaion. This parameter should be chosen to optimize a balance. Typical + values range from 4 to 10. + * @param [in] sampleType Currently this parameter is ignored and only uniform sampling is + applied. Leave it as 0. + * @param [in] numMaxCorr Currently this parameter is ignored and only PickyICP is applied. Leave it as 1. + */ + CV_WRAP ICP(const int iterations, const float tolerence = 0.05f, const float rejectionScale = 2.5f, const int numLevels = 6, const int sampleType = ICP::ICP_SAMPLING_TYPE_UNIFORM, const int numMaxCorr = 1) + { + m_tolerance = tolerence; + m_numNeighborsCorr = numMaxCorr; + m_rejectionScale = rejectionScale; + m_maxIterations = iterations; + m_numLevels = numLevels; + m_sampleType = sampleType; + } + + /** + * \brief Perform registration + * + * @param [in] srcPC The input point cloud for the model. Expected to have the normals (Nx6). Currently, + * CV_32F is the only supported data type. + * @param [in] dstPC The input point cloud for the scene. It is assumed that the model is registered on the scene. Scene remains static. Expected to have the normals (Nx6). Currently, CV_32F is the only supported data type. + * @param [out] residual The output registration error. + * @param [out] pose Transformation between srcPC and dstPC. + * \return On successful termination, the function returns 0. + * + * \details It is assumed that the model is registered on the scene. Scene remains static, while the model transforms. The output poses transform the models onto the scene. Because of the point to plane minimization, the scene is expected to have the normals available. Expected to have the normals (Nx6). + */ + CV_WRAP int registerModelToScene(const Mat& srcPC, const Mat& dstPC, CV_OUT double& residual, CV_OUT Matx44d& pose); + + /** + * \brief Perform registration with multiple initial poses + * + * @param [in] srcPC The input point cloud for the model. Expected to have the normals (Nx6). Currently, + * CV_32F is the only supported data type. + * @param [in] dstPC The input point cloud for the scene. Currently, CV_32F is the only supported data type. + * @param [in,out] poses Input poses to start with but also list output of poses. + * \return On successful termination, the function returns 0. + * + * \details It is assumed that the model is registered on the scene. Scene remains static, while the model transforms. The output poses transform the models onto the scene. Because of the point to plane minimization, the scene is expected to have the normals available. Expected to have the normals (Nx6). + */ + int registerModelToScene(const Mat& srcPC, const Mat& dstPC, std::vector<Pose3DPtr>& poses); + +private: + float m_tolerance; + int m_maxIterations; + float m_rejectionScale; + int m_numNeighborsCorr; + int m_numLevels; + int m_sampleType; + +}; + +//! @} + +} // namespace ppf_match_3d + +} // namespace cv + +#endif diff --git a/include/opencv2/surface_matching/pose_3d.hpp b/include/opencv2/surface_matching/pose_3d.hpp new file mode 100644 index 0000000..82984bf --- /dev/null +++ b/include/opencv2/surface_matching/pose_3d.hpp @@ -0,0 +1,188 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + +#ifndef __OPENCV_SURFACE_MATCHING_POSE3D_HPP__ +#define __OPENCV_SURFACE_MATCHING_POSE3D_HPP__ + +#include "opencv2/core/cvstd.hpp" // cv::Ptr +#include <vector> +#include <string> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +class Pose3D; +typedef Ptr<Pose3D> Pose3DPtr; + +class PoseCluster3D; +typedef Ptr<PoseCluster3D> PoseCluster3DPtr; + +/** +* @brief Class, allowing the storage of a pose. The data structure stores both +* the quaternions and the matrix forms. It supports IO functionality together with +* various helper methods to work with poses +* +*/ +class CV_EXPORTS Pose3D +{ +public: + Pose3D() + { + alpha=0; + modelIndex=0; + numVotes=0; + residual = 0; + + pose = Matx44d::all(0); + } + + Pose3D(double Alpha, size_t ModelIndex=0, size_t NumVotes=0) + { + alpha = Alpha; + modelIndex = ModelIndex; + numVotes = NumVotes; + residual=0; + + pose = Matx44d::all(0); + } + + /** + * \brief Updates the pose with the new one + * \param [in] NewPose New pose to overwrite + */ + void updatePose(Matx44d& NewPose); + + /** + * \brief Updates the pose with the new one + */ + void updatePose(Matx33d& NewR, Vec3d& NewT); + + /** + * \brief Updates the pose with the new one, but this time using quaternions to represent rotation + */ + void updatePoseQuat(Vec4d& Q, Vec3d& NewT); + + /** + * \brief Left multiplies the existing pose in order to update the transformation + * \param [in] IncrementalPose New pose to apply + */ + void appendPose(Matx44d& IncrementalPose); + void printPose(); + + Pose3DPtr clone(); + + int writePose(FILE* f); + int readPose(FILE* f); + int writePose(const std::string& FileName); + int readPose(const std::string& FileName); + + virtual ~Pose3D() {} + + double alpha, residual; + size_t modelIndex, numVotes; + Matx44d pose; + double angle; + Vec3d t; + Vec4d q; +}; + +/** +* @brief When multiple poses (see Pose3D) are grouped together (contribute to the same transformation) +* pose clusters occur. This class is a general container for such groups of poses. It is possible to store, +* load and perform IO on these poses. +*/ +class CV_EXPORTS_W PoseCluster3D +{ +public: + PoseCluster3D() + { + numVotes=0; + id=0; + } + + PoseCluster3D(Pose3DPtr newPose) + { + poseList.clear(); + poseList.push_back(newPose); + numVotes=newPose->numVotes; + id=0; + } + + PoseCluster3D(Pose3DPtr newPose, int newId) + { + poseList.push_back(newPose); + this->numVotes = newPose->numVotes; + this->id = newId; + } + + virtual ~PoseCluster3D() + {} + + /** + * \brief Adds a new pose to the cluster. The pose should be "close" to the mean poses + * in order to preserve the consistency + * \param [in] newPose Pose to add to the cluster + */ + void addPose(Pose3DPtr newPose); + + int writePoseCluster(FILE* f); + int readPoseCluster(FILE* f); + int writePoseCluster(const std::string& FileName); + int readPoseCluster(const std::string& FileName); + + std::vector<Pose3DPtr> poseList; + size_t numVotes; + int id; +}; + +//! @} + +} // namespace ppf_match_3d +} // namespace cv + +#endif + diff --git a/include/opencv2/surface_matching/ppf_helpers.hpp b/include/opencv2/surface_matching/ppf_helpers.hpp new file mode 100644 index 0000000..7b4de88 --- /dev/null +++ b/include/opencv2/surface_matching/ppf_helpers.hpp @@ -0,0 +1,153 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + +#ifndef __OPENCV_SURFACE_MATCHING_HELPERS_HPP__ +#define __OPENCV_SURFACE_MATCHING_HELPERS_HPP__ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +/** + * @brief Load a PLY file + * @param [in] fileName The PLY model to read + * @param [in] withNormals Flag wheather the input PLY contains normal information, + * and whether it should be loaded or not + * @return Returns the matrix on successfull load + */ +CV_EXPORTS_W Mat loadPLYSimple(const char* fileName, int withNormals = 0); + +/** + * @brief Write a point cloud to PLY file + * @param [in] PC Input point cloud + * @param [in] fileName The PLY model file to write +*/ +CV_EXPORTS_W void writePLY(Mat PC, const char* fileName); + +/** +* @brief Used for debbuging pruposes, writes a point cloud to a PLY file with the tip +* of the normal vectors as visible red points +* @param [in] PC Input point cloud +* @param [in] fileName The PLY model file to write +*/ +CV_EXPORTS_W void writePLYVisibleNormals(Mat PC, const char* fileName); + +Mat samplePCUniform(Mat PC, int sampleStep); +Mat samplePCUniformInd(Mat PC, int sampleStep, std::vector<int>& indices); + +/** + * Sample a point cloud using uniform steps + * @param [in] pc Input point cloud + * @param [in] xrange X components (min and max) of the bounding box of the model + * @param [in] yrange Y components (min and max) of the bounding box of the model + * @param [in] zrange Z components (min and max) of the bounding box of the model + * @param [in] sample_step_relative The point cloud is sampled such that all points + * have a certain minimum distance. This minimum distance is determined relatively using + * the parameter sample_step_relative. + * @param [in] weightByCenter The contribution of the quantized data points can be weighted + * by the distance to the origin. This parameter enables/disables the use of weighting. + * @return Sampled point cloud +*/ +CV_EXPORTS_W Mat samplePCByQuantization(Mat pc, Vec2f& xrange, Vec2f& yrange, Vec2f& zrange, float sample_step_relative, int weightByCenter=0); + +void computeBboxStd(Mat pc, Vec2f& xRange, Vec2f& yRange, Vec2f& zRange); + +void* indexPCFlann(Mat pc); +void destroyFlann(void* flannIndex); +void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances); +void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances, const int numNeighbors); + +Mat normalizePCCoeff(Mat pc, float scale, float* Cx, float* Cy, float* Cz, float* MinVal, float* MaxVal); +Mat transPCCoeff(Mat pc, float scale, float Cx, float Cy, float Cz, float MinVal, float MaxVal); + +/** + * Transforms the point cloud with a given a homogeneous 4x4 pose matrix (in double precision) + * @param [in] pc Input point cloud (CV_32F family). Point clouds with 3 or 6 elements per + * row are expected. In the case where the normals are provided, they are also rotated to be + * compatible with the entire transformation + * @param [in] Pose 4x4 pose matrix, but linearized in row-major form. + * @return Transformed point cloud +*/ +CV_EXPORTS_W Mat transformPCPose(Mat pc, const Matx44d& Pose); + +/** + * Generate a random 4x4 pose matrix + * @param [out] Pose The random pose +*/ +CV_EXPORTS_W void getRandomPose(Matx44d& Pose); + +/** + * Adds a uniform noise in the given scale to the input point cloud + * @param [in] pc Input point cloud (CV_32F family). + * @param [in] scale Input scale of the noise. The larger the scale, the more noisy the output +*/ +CV_EXPORTS_W Mat addNoisePC(Mat pc, double scale); + +/** + * @brief Compute the normals of an arbitrary point cloud + * computeNormalsPC3d uses a plane fitting approach to smoothly compute + * local normals. Normals are obtained through the eigenvector of the covariance + * matrix, corresponding to the smallest eigen value. + * If PCNormals is provided to be an Nx6 matrix, then no new allocation + * is made, instead the existing memory is overwritten. + * @param [in] PC Input point cloud to compute the normals for. + * @param [out] PCNormals Output point cloud + * @param [in] NumNeighbors Number of neighbors to take into account in a local region + * @param [in] FlipViewpoint Should normals be flipped to a viewing direction? + * @param [in] viewpoint + * @return Returns 0 on success + */ +CV_EXPORTS_W int computeNormalsPC3d(const Mat& PC, CV_OUT Mat& PCNormals, const int NumNeighbors, const bool FlipViewpoint, const Vec3f& viewpoint); + +//! @} + +} // namespace ppf_match_3d +} // namespace cv + +#endif diff --git a/include/opencv2/surface_matching/ppf_match_3d.hpp b/include/opencv2/surface_matching/ppf_match_3d.hpp new file mode 100644 index 0000000..8e68610 --- /dev/null +++ b/include/opencv2/surface_matching/ppf_match_3d.hpp @@ -0,0 +1,179 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// + +/** +** ppf_match_3d : Interfaces for matching 3d surfaces in 3d scenes. This module implements the algorithm from Bertram Drost and Slobodan Ilic. +** Use: Read a 3D model, load a 3D scene and match the model to the scene +** +** +** Creation - 2014 +** Author: Tolga Birdal (tbirdal@gmail.com) +** +** Refer to the following research paper for more information: +** B. Drost, Markus Ulrich, N. Navab, S. Ilic +Model Globally, Match Locally: Efficient and Robust 3D Object Recognition +IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR), San Francisco, California (USA), June 2010. +***/ + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + + +#ifndef __OPENCV_SURFACE_MATCHING_PPF_MATCH_3D_HPP__ +#define __OPENCV_SURFACE_MATCHING_PPF_MATCH_3D_HPP__ + +#include <opencv2/core.hpp> + +#include <vector> +#include "pose_3d.hpp" +#include "t_hash_int.hpp" + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +/** + * @brief Struct, holding a node in the hashtable + */ +typedef struct THash +{ + int id; + int i, ppfInd; +} THash; + +/** + * @brief Class, allowing the load and matching 3D models. + * Typical Use: + * @code + * // Train a model + * ppf_match_3d::PPF3DDetector detector(0.05, 0.05); + * detector.trainModel(pc); + * // Search the model in a given scene + * vector<Pose3DPtr> results; + * detector.match(pcTest, results, 1.0/5.0,0.05); + * @endcode + */ +class CV_EXPORTS_W PPF3DDetector +{ +public: + + /** + * \brief Empty constructor. Sets default arguments + */ + PPF3DDetector(); + + /** + * Constructor with arguments + * @param [in] relativeSamplingStep Sampling distance relative to the object's diameter. Models are first sampled uniformly in order to improve efficiency. Decreasing this value leads to a denser model, and a more accurate pose estimation but the larger the model, the slower the training. Increasing the value leads to a less accurate pose computation but a smaller model and faster model generation and matching. Beware of the memory consumption when using small values. + * @param [in] relativeDistanceStep The discretization distance of the point pair distance relative to the model's diameter. This value has a direct impact on the hashtable. Using small values would lead to too fine discretization, and thus ambiguity in the bins of hashtable. Too large values would lead to no discrimination over the feature vectors and different point pair features would be assigned to the same bin. This argument defaults to the value of RelativeSamplingStep. For noisy scenes, the value can be increased to improve the robustness of the matching against noisy points. + * @param [in] numAngles Set the discretization of the point pair orientation as the number of subdivisions of the angle. This value is the equivalent of RelativeDistanceStep for the orientations. Increasing the value increases the precision of the matching but decreases the robustness against incorrect normal directions. Decreasing the value decreases the precision of the matching but increases the robustness against incorrect normal directions. For very noisy scenes where the normal directions can not be computed accurately, the value can be set to 25 or 20. + */ + PPF3DDetector(const double relativeSamplingStep, const double relativeDistanceStep=0.05, const double numAngles=30); + + virtual ~PPF3DDetector(); + + /** + * Set the parameters for the search + * @param [in] positionThreshold Position threshold controlling the similarity of translations. Depends on the units of calibration/model. + * @param [in] rotationThreshold Position threshold controlling the similarity of rotations. This parameter can be perceived as a threshold over the difference of angles + * @param [in] useWeightedClustering The algorithm by default clusters the poses without weighting. A non-zero value would indicate that the pose clustering should take into account the number of votes as the weights and perform a weighted averaging instead of a simple one. + */ + void setSearchParams(const double positionThreshold=-1, const double rotationThreshold=-1, const bool useWeightedClustering=false); + + /** + * \brief Trains a new model. + * + * @param [in] Model The input point cloud with normals (Nx6) + * + * \details Uses the parameters set in the constructor to downsample and learn a new model. When the model is learnt, the instance gets ready for calling "match". + */ + void trainModel(const Mat& Model); + + /** + * \brief Matches a trained model across a provided scene. + * + * @param [in] scene Point cloud for the scene + * @param [out] results List of output poses + * @param [in] relativeSceneSampleStep The ratio of scene points to be used for the matching after sampling with relativeSceneDistance. For example, if this value is set to 1.0/5.0, every 5th point from the scene is used for pose estimation. This parameter allows an easy trade-off between speed and accuracy of the matching. Increasing the value leads to less points being used and in turn to a faster but less accurate pose computation. Decreasing the value has the inverse effect. + * @param [in] relativeSceneDistance Set the distance threshold relative to the diameter of the model. This parameter is equivalent to relativeSamplingStep in the training stage. This parameter acts like a prior sampling with the relativeSceneSampleStep parameter. + */ + void match(const Mat& scene, std::vector<Pose3DPtr> &results, const double relativeSceneSampleStep=1.0/5.0, const double relativeSceneDistance=0.03); + + void read(const FileNode& fn); + void write(FileStorage& fs) const; + +protected: + + double angle_step, angle_step_radians, distance_step; + double sampling_step_relative, angle_step_relative, distance_step_relative; + Mat sampled_pc, ppf; + int num_ref_points; + hashtable_int* hash_table; + THash* hash_nodes; + + double position_threshold, rotation_threshold; + bool use_weighted_avg; + + int scene_sample_step; + + void clearTrainingModels(); + +private: + void computePPFFeatures(const Vec3d& p1, const Vec3d& n1, + const Vec3d& p2, const Vec3d& n2, + Vec4d& f); + + bool matchPose(const Pose3D& sourcePose, const Pose3D& targetPose); + + void clusterPoses(std::vector<Pose3DPtr>& poseList, int numPoses, std::vector<Pose3DPtr> &finalPoses); + + bool trained; +}; + +//! @} + +} // namespace ppf_match_3d + +} // namespace cv +#endif diff --git a/include/opencv2/surface_matching/t_hash_int.hpp b/include/opencv2/surface_matching/t_hash_int.hpp new file mode 100644 index 0000000..4e9b5bb --- /dev/null +++ b/include/opencv2/surface_matching/t_hash_int.hpp @@ -0,0 +1,113 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + +#ifndef __OPENCV_SURFACE_MATCHING_T_HASH_INT_HPP__ +#define __OPENCV_SURFACE_MATCHING_T_HASH_INT_HPP__ + +#include <stdio.h> +#include <stdlib.h> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +typedef uint KeyType; + +typedef struct hashnode_i +{ + KeyType key; + void *data; + struct hashnode_i *next; +} hashnode_i ; + +typedef struct HSHTBL_i +{ + size_t size; + struct hashnode_i **nodes; + size_t (*hashfunc)(uint); +} hashtable_int; + + +/** @brief Round up to the next highest power of 2 + +from http://www-graphics.stanford.edu/~seander/bithacks.html +*/ +inline static uint next_power_of_two(uint value) +{ + + --value; + value |= value >> 1; + value |= value >> 2; + value |= value >> 4; + value |= value >> 8; + value |= value >> 16; + ++value; + + return value; +} + +hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(uint)); +void hashtableDestroy(hashtable_int *hashtbl); +int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data); +int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data); +int hashtableRemove(hashtable_int *hashtbl, KeyType key); +void *hashtableGet(hashtable_int *hashtbl, KeyType key); +hashnode_i* hashtableGetBucketHashed(hashtable_int *hashtbl, KeyType key); +int hashtableResize(hashtable_int *hashtbl, size_t size); +hashtable_int *hashtable_int_clone(hashtable_int *hashtbl); +hashtable_int *hashtableRead(FILE* f); +int hashtableWrite(const hashtable_int * hashtbl, const size_t dataSize, FILE* f); +void hashtablePrint(hashtable_int *hashtbl); + +//! @} + +} // namespace ppf_match_3d + +} // namespace cv +#endif + + diff --git a/include/opencv2/text.hpp b/include/opencv2/text.hpp new file mode 100644 index 0000000..c06c889 --- /dev/null +++ b/include/opencv2/text.hpp @@ -0,0 +1,102 @@ +/* +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. +*/ + +#ifndef __OPENCV_TEXT_HPP__ +#define __OPENCV_TEXT_HPP__ + +#include "opencv2/text/erfilter.hpp" +#include "opencv2/text/ocr.hpp" +#include "opencv2/text/textDetector.hpp" + +/** @defgroup text Scene Text Detection and Recognition + +The opencv_text module provides different algorithms for text detection and recognition in natural +scene images. + + @{ + @defgroup text_detect Scene Text Detection + +Class-specific Extremal Regions for Scene Text Detection +-------------------------------------------------------- + +The scene text detection algorithm described below has been initially proposed by Lukás Neumann & +Jiri Matas @cite Neumann11. The main idea behind Class-specific Extremal Regions is similar to the MSER +in that suitable Extremal Regions (ERs) are selected from the whole component tree of the image. +However, this technique differs from MSER in that selection of suitable ERs is done by a sequential +classifier trained for character detection, i.e. dropping the stability requirement of MSERs and +selecting class-specific (not necessarily stable) regions. + +The component tree of an image is constructed by thresholding by an increasing value step-by-step +from 0 to 255 and then linking the obtained connected components from successive levels in a +hierarchy by their inclusion relation: + +![image](pics/component_tree.png) + +The component tree may contain a huge number of regions even for a very simple image as shown in +the previous image. This number can easily reach the order of 1 x 10\^6 regions for an average 1 +Megapixel image. In order to efficiently select suitable regions among all the ERs the algorithm +make use of a sequential classifier with two differentiated stages. + +In the first stage incrementally computable descriptors (area, perimeter, bounding box, and Euler's +number) are computed (in O(1)) for each region r and used as features for a classifier which +estimates the class-conditional probability p(r|character). Only the ERs which correspond to local +maximum of the probability p(r|character) are selected (if their probability is above a global limit +p_min and the difference between local maximum and local minimum is greater than a delta_min +value). + +In the second stage, the ERs that passed the first stage are classified into character and +non-character classes using more informative but also more computationally expensive features. (Hole +area ratio, convex hull ratio, and the number of outer boundary inflexion points). + +This ER filtering process is done in different single-channel projections of the input image in +order to increase the character localization recall. + +After the ER filtering is done on each input channel, character candidates must be grouped in +high-level text blocks (i.e. words, text lines, paragraphs, ...). The opencv_text module implements +two different grouping algorithms: the Exhaustive Search algorithm proposed in @cite Neumann12 for +grouping horizontally aligned text, and the method proposed by Lluis Gomez and Dimosthenis Karatzas +in @cite Gomez13 @cite Gomez14 for grouping arbitrary oriented text (see erGrouping). + +To see the text detector at work, have a look at the textdetection demo: +<https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/textdetection.cpp> + + @defgroup text_recognize Scene Text Recognition + @} +*/ + +#endif diff --git a/include/opencv2/text/erfilter.hpp b/include/opencv2/text/erfilter.hpp new file mode 100644 index 0000000..d83beb0 --- /dev/null +++ b/include/opencv2/text/erfilter.hpp @@ -0,0 +1,373 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_TEXT_ERFILTER_HPP__ +#define __OPENCV_TEXT_ERFILTER_HPP__ + +#include "opencv2/core.hpp" +#include <vector> +#include <deque> +#include <string> + +namespace cv +{ +namespace text +{ + +//! @addtogroup text_detect +//! @{ + +/** @brief The ERStat structure represents a class-specific Extremal Region (ER). + +An ER is a 4-connected set of pixels with all its grey-level values smaller than the values in its +outer boundary. A class-specific ER is selected (using a classifier) from all the ER's in the +component tree of the image. : + */ +struct CV_EXPORTS ERStat +{ +public: + //! Constructor + explicit ERStat(int level = 256, int pixel = 0, int x = 0, int y = 0); + //! Destructor + ~ERStat() { } + + //! seed point and the threshold (max grey-level value) + int pixel; + int level; + + //! incrementally computable features + int area; + int perimeter; + int euler; //!< Euler's number + Rect rect; + double raw_moments[2]; //!< order 1 raw moments to derive the centroid + double central_moments[3]; //!< order 2 central moments to construct the covariance matrix + Ptr<std::deque<int> > crossings;//!< horizontal crossings + float med_crossings; //!< median of the crossings at three different height levels + + //! 2nd stage features + float hole_area_ratio; + float convex_hull_ratio; + float num_inflexion_points; + + // TODO Other features can be added (average color, standard deviation, and such) + + + // TODO shall we include the pixel list whenever available (i.e. after 2nd stage) ? + std::vector<int> *pixels; + + //! probability that the ER belongs to the class we are looking for + double probability; + + //! pointers preserving the tree structure of the component tree + ERStat* parent; + ERStat* child; + ERStat* next; + ERStat* prev; + + //! whenever the regions is a local maxima of the probability + bool local_maxima; + ERStat* max_probability_ancestor; + ERStat* min_probability_ancestor; +}; + +/** @brief Base class for 1st and 2nd stages of Neumann and Matas scene text detection algorithm @cite Neumann12. : + +Extracts the component tree (if needed) and filter the extremal regions (ER's) by using a given classifier. + */ +class CV_EXPORTS_W ERFilter : public Algorithm +{ +public: + + /** @brief Callback with the classifier is made a class. + + By doing it we hide SVM, Boost etc. Developers can provide their own classifiers to the + ERFilter algorithm. + */ + class CV_EXPORTS_W Callback + { + public: + virtual ~Callback() { } + /** @brief The classifier must return probability measure for the region. + + @param stat : The region to be classified + */ + virtual double eval(const ERStat& stat) = 0; //const = 0; //TODO why cannot use const = 0 here? + }; + + /** @brief The key method of ERFilter algorithm. + + Takes image on input and returns the selected regions in a vector of ERStat only distinctive + ERs which correspond to characters are selected by a sequential classifier + + @param image Single channel image CV_8UC1 + + @param regions Output for the 1st stage and Input/Output for the 2nd. The selected Extremal Regions + are stored here. + + Extracts the component tree (if needed) and filter the extremal regions (ER's) by using a given + classifier. + */ + virtual void run( InputArray image, std::vector<ERStat>& regions ) = 0; + + + //! set/get methods to set the algorithm properties, + virtual void setCallback(const Ptr<ERFilter::Callback>& cb) = 0; + virtual void setThresholdDelta(int thresholdDelta) = 0; + virtual void setMinArea(float minArea) = 0; + virtual void setMaxArea(float maxArea) = 0; + virtual void setMinProbability(float minProbability) = 0; + virtual void setMinProbabilityDiff(float minProbabilityDiff) = 0; + virtual void setNonMaxSuppression(bool nonMaxSuppression) = 0; + virtual int getNumRejected() const = 0; +}; + + + +/** @brief Create an Extremal Region Filter for the 1st stage classifier of N&M algorithm @cite Neumann12. + +@param cb : Callback with the classifier. Default classifier can be implicitly load with function +loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml +@param thresholdDelta : Threshold step in subsequent thresholds when extracting the component tree +@param minArea : The minimum area (% of image size) allowed for retreived ER's +@param maxArea : The maximum area (% of image size) allowed for retreived ER's +@param minProbability : The minimum probability P(er|character) allowed for retreived ER's +@param nonMaxSuppression : Whenever non-maximum suppression is done over the branch probabilities +@param minProbabilityDiff : The minimum probability difference between local maxima and local minima ERs + +The component tree of the image is extracted by a threshold increased step by step from 0 to 255, +incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of +horizontal crossings) are computed for each ER and used as features for a classifier which estimates +the class-conditional probability P(er|character). The value of P(er|character) is tracked using the +inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of +the probability P(er|character) are selected (if the local maximum of the probability is above a +global limit pmin and the difference between local maximum and local minimum is greater than +minProbabilityDiff). + */ +CV_EXPORTS_W Ptr<ERFilter> createERFilterNM1(const Ptr<ERFilter::Callback>& cb, + int thresholdDelta = 1, float minArea = (float)0.00025, + float maxArea = (float)0.13, float minProbability = (float)0.4, + bool nonMaxSuppression = true, + float minProbabilityDiff = (float)0.1); + +/** @brief Create an Extremal Region Filter for the 2nd stage classifier of N&M algorithm @cite Neumann12. + +@param cb : Callback with the classifier. Default classifier can be implicitly load with function +loadClassifierNM2, e.g. from file in samples/cpp/trained_classifierNM2.xml +@param minProbability : The minimum probability P(er|character) allowed for retreived ER's + +In the second stage, the ERs that passed the first stage are classified into character and +non-character classes using more informative but also more computationally expensive features. The +classifier uses all the features calculated in the first stage and the following additional +features: hole area ratio, convex hull ratio, and number of outer inflexion points. + */ +CV_EXPORTS_W Ptr<ERFilter> createERFilterNM2(const Ptr<ERFilter::Callback>& cb, + float minProbability = (float)0.3); + +/** @brief Reads an Extremal Region Filter for the 1st stage classifier of N&M algorithm + from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml + +@overload + */ +CV_EXPORTS_W Ptr<ERFilter> createERFilterNM1(const String& filename, + int thresholdDelta = 1, float minArea = (float)0.00025, + float maxArea = (float)0.13, float minProbability = (float)0.4, + bool nonMaxSuppression = true, + float minProbabilityDiff = (float)0.1); + +/** @brief Reads an Extremal Region Filter for the 2nd stage classifier of N&M algorithm + from the provided path e.g. /path/to/cpp/trained_classifierNM2.xml + +@overload + */ +CV_EXPORTS_W Ptr<ERFilter> createERFilterNM2(const String& filename, + float minProbability = (float)0.3); + +/** @brief Allow to implicitly load the default classifier when creating an ERFilter object. + +@param filename The XML or YAML file with the classifier model (e.g. trained_classifierNM1.xml) + +returns a pointer to ERFilter::Callback. + */ +CV_EXPORTS_W Ptr<ERFilter::Callback> loadClassifierNM1(const String& filename); + +/** @brief Allow to implicitly load the default classifier when creating an ERFilter object. + +@param filename The XML or YAML file with the classifier model (e.g. trained_classifierNM2.xml) + +returns a pointer to ERFilter::Callback. + */ +CV_EXPORTS_W Ptr<ERFilter::Callback> loadClassifierNM2(const String& filename); + + +//! computeNMChannels operation modes +enum { ERFILTER_NM_RGBLGrad, + ERFILTER_NM_IHSGrad + }; + +/** @brief Compute the different channels to be processed independently in the N&M algorithm @cite Neumann12. + +@param _src Source image. Must be RGB CV_8UC3. + +@param _channels Output vector\<Mat\> where computed channels are stored. + +@param _mode Mode of operation. Currently the only available options are: +**ERFILTER_NM_RGBLGrad** (used by default) and **ERFILTER_NM_IHSGrad**. + +In N&M algorithm, the combination of intensity (I), hue (H), saturation (S), and gradient magnitude +channels (Grad) are used in order to obtain high localization recall. This implementation also +provides an alternative combination of red (R), green (G), blue (B), lightness (L), and gradient +magnitude (Grad). + */ +CV_EXPORTS_W void computeNMChannels(InputArray _src, CV_OUT OutputArrayOfArrays _channels, int _mode = ERFILTER_NM_RGBLGrad); + + + +//! text::erGrouping operation modes +enum erGrouping_Modes { + + /** Exhaustive Search algorithm proposed in @cite Neumann11 for grouping horizontally aligned text. + The algorithm models a verification function for all the possible ER sequences. The + verification fuction for ER pairs consists in a set of threshold-based pairwise rules which + compare measurements of two regions (height ratio, centroid angle, and region distance). The + verification function for ER triplets creates a word text line estimate using Least + Median-Squares fitting for a given triplet and then verifies that the estimate is valid (based + on thresholds created during training). Verification functions for sequences larger than 3 are + approximated by verifying that the text line parameters of all (sub)sequences of length 3 are + consistent. + */ + ERGROUPING_ORIENTATION_HORIZ, + /** Text grouping method proposed in @cite Gomez13 @cite Gomez14 for grouping arbitrary oriented text. Regions + are agglomerated by Single Linkage Clustering in a weighted feature space that combines proximity + (x,y coordinates) and similarity measures (color, size, gradient magnitude, stroke width, etc.). + SLC provides a dendrogram where each node represents a text group hypothesis. Then the algorithm + finds the branches corresponding to text groups by traversing this dendrogram with a stopping rule + that combines the output of a rotation invariant text group classifier and a probabilistic measure + for hierarchical clustering validity assessment. + */ + ERGROUPING_ORIENTATION_ANY +}; + +/** @brief Find groups of Extremal Regions that are organized as text blocks. + +@param img Original RGB or Greyscale image from wich the regions were extracted. + +@param channels Vector of single channel images CV_8UC1 from wich the regions were extracted. + +@param regions Vector of ER's retrieved from the ERFilter algorithm from each channel. + +@param groups The output of the algorithm is stored in this parameter as set of lists of indexes to +provided regions. + +@param groups_rects The output of the algorithm are stored in this parameter as list of rectangles. + +@param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ, +ERGROUPING_ORIENTATION_ANY. + +@param filename The XML or YAML file with the classifier model (e.g. +samples/trained_classifier_erGrouping.xml). Only to use when grouping method is +ERGROUPING_ORIENTATION_ANY. + +@param minProbablity The minimum probability for accepting a group. Only to use when grouping +method is ERGROUPING_ORIENTATION_ANY. + */ +CV_EXPORTS void erGrouping(InputArray img, InputArrayOfArrays channels, + std::vector<std::vector<ERStat> > ®ions, + std::vector<std::vector<Vec2i> > &groups, + std::vector<Rect> &groups_rects, + int method = ERGROUPING_ORIENTATION_HORIZ, + const std::string& filename = std::string(), + float minProbablity = 0.5); + +CV_EXPORTS_W void erGrouping(InputArray image, InputArray channel, + std::vector<std::vector<Point> > regions, + CV_OUT std::vector<Rect> &groups_rects, + int method = ERGROUPING_ORIENTATION_HORIZ, + const String& filename = String(), + float minProbablity = (float)0.5); + +/** @brief Converts MSER contours (vector\<Point\>) to ERStat regions. + +@param image Source image CV_8UC1 from which the MSERs where extracted. + +@param contours Input vector with all the contours (vector\<Point\>). + +@param regions Output where the ERStat regions are stored. + +It takes as input the contours provided by the OpenCV MSER feature detector and returns as output +two vectors of ERStats. This is because MSER() output contains both MSER+ and MSER- regions in a +single vector\<Point\>, the function separates them in two different vectors (this is as if the +ERStats where extracted from two different channels). + +An example of MSERsToERStats in use can be found in the text detection webcam_demo: +<https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/webcam_demo.cpp> + */ +CV_EXPORTS void MSERsToERStats(InputArray image, std::vector<std::vector<Point> > &contours, + std::vector<std::vector<ERStat> > ®ions); + +// Utility funtion for scripting +CV_EXPORTS_W void detectRegions(InputArray image, const Ptr<ERFilter>& er_filter1, const Ptr<ERFilter>& er_filter2, CV_OUT std::vector< std::vector<Point> >& regions); + + +/** @brief Extracts text regions from image. + +@param image Source image where text blocks needs to be extracted from. Should be CV_8UC3 (color). +@param er_filter1 Extremal Region Filter for the 1st stage classifier of N&M algorithm @cite Neumann12 +@param er_filter2 Extremal Region Filter for the 2nd stage classifier of N&M algorithm @cite Neumann12 +@param groups_rects Output list of rectangle blocks with text +@param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ, ERGROUPING_ORIENTATION_ANY. +@param filename The XML or YAML file with the classifier model (e.g. samples/trained_classifier_erGrouping.xml). Only to use when grouping method is ERGROUPING_ORIENTATION_ANY. +@param minProbability The minimum probability for accepting a group. Only to use when grouping method is ERGROUPING_ORIENTATION_ANY. + + + */ +CV_EXPORTS_W void detectRegions(InputArray image, const Ptr<ERFilter>& er_filter1, const Ptr<ERFilter>& er_filter2, CV_OUT std::vector<Rect> &groups_rects, + int method = ERGROUPING_ORIENTATION_HORIZ, + const String& filename = String(), + float minProbability = (float)0.5); + +//! @} + +} +} +#endif // _OPENCV_TEXT_ERFILTER_HPP_ diff --git a/include/opencv2/text/ocr.hpp b/include/opencv2/text/ocr.hpp new file mode 100644 index 0000000..b70b30a --- /dev/null +++ b/include/opencv2/text/ocr.hpp @@ -0,0 +1,603 @@ +/*M////////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_TEXT_OCR_HPP__ +#define __OPENCV_TEXT_OCR_HPP__ + +#include <opencv2/core.hpp> + +#include <vector> +#include <string> + +namespace cv +{ +namespace text +{ + +//! @addtogroup text_recognize +//! @{ + +enum +{ + OCR_LEVEL_WORD, + OCR_LEVEL_TEXTLINE +}; + +//! Tesseract.PageSegMode Enumeration +enum page_seg_mode +{ + PSM_OSD_ONLY, + PSM_AUTO_OSD, + PSM_AUTO_ONLY, + PSM_AUTO, + PSM_SINGLE_COLUMN, + PSM_SINGLE_BLOCK_VERT_TEXT, + PSM_SINGLE_BLOCK, + PSM_SINGLE_LINE, + PSM_SINGLE_WORD, + PSM_CIRCLE_WORD, + PSM_SINGLE_CHAR +}; + +//! Tesseract.OcrEngineMode Enumeration +enum ocr_engine_mode +{ + OEM_TESSERACT_ONLY, + OEM_CUBE_ONLY, + OEM_TESSERACT_CUBE_COMBINED, + OEM_DEFAULT +}; + +//base class BaseOCR declares a common API that would be used in a typical text recognition scenario +class CV_EXPORTS_W BaseOCR +{ +public: + virtual ~BaseOCR() {}; + virtual void run(Mat& image, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) = 0; + virtual void run(Mat& image, Mat& mask, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) = 0; +}; + +/** @brief OCRTesseract class provides an interface with the tesseract-ocr API (v3.02.02) in C++. + +Notice that it is compiled only when tesseract-ocr is correctly installed. + +@note + - (C++) An example of OCRTesseract recognition combined with scene text detection can be found + at the end_to_end_recognition demo: + <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/end_to_end_recognition.cpp> + - (C++) Another example of OCRTesseract recognition combined with scene text detection can be + found at the webcam_demo: + <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/webcam_demo.cpp> + */ +class CV_EXPORTS_W OCRTesseract : public BaseOCR +{ +public: + /** @brief Recognize text using the tesseract-ocr API. + + Takes image on input and returns recognized text in the output_text parameter. Optionally + provides also the Rects for individual text elements found (e.g. words), and the list of those + text elements with their confidence values. + + @param image Input image CV_8UC1 or CV_8UC3 + @param output_text Output text of the tesseract-ocr. + @param component_rects If provided the method will output a list of Rects for the individual + text elements found (e.g. words or text lines). + @param component_texts If provided the method will output a list of text strings for the + recognition of individual text elements found (e.g. words or text lines). + @param component_confidences If provided the method will output a list of confidence values + for the recognition of individual text elements found (e.g. words or text lines). + @param component_level OCR_LEVEL_WORD (by default), or OCR_LEVEL_TEXTLINE. + */ + virtual void run(Mat& image, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) CV_OVERRIDE; + + virtual void run(Mat& image, Mat& mask, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) CV_OVERRIDE; + + // aliases for scripting + CV_WRAP String run(InputArray image, int min_confidence, int component_level=0); + + CV_WRAP String run(InputArray image, InputArray mask, int min_confidence, int component_level=0); + + CV_WRAP virtual void setWhiteList(const String& char_whitelist) = 0; + + + /** @brief Creates an instance of the OCRTesseract class. Initializes Tesseract. + + @param datapath the name of the parent directory of tessdata ended with "/", or NULL to use the + system's default directory. + @param language an ISO 639-3 code or NULL will default to "eng". + @param char_whitelist specifies the list of characters used for recognition. NULL defaults to + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". + @param oem tesseract-ocr offers different OCR Engine Modes (OEM), by default + tesseract::OEM_DEFAULT is used. See the tesseract-ocr API documentation for other possible + values. + @param psmode tesseract-ocr offers different Page Segmentation Modes (PSM) tesseract::PSM_AUTO + (fully automatic layout analysis) is used. See the tesseract-ocr API documentation for other + possible values. + */ + CV_WRAP static Ptr<OCRTesseract> create(const char* datapath=NULL, const char* language=NULL, + const char* char_whitelist=NULL, int oem=OEM_DEFAULT, int psmode=PSM_AUTO); +}; + + +/* OCR HMM Decoder */ + +enum decoder_mode +{ + OCR_DECODER_VITERBI = 0 // Other algorithms may be added +}; + +/* OCR classifier type*/ +enum classifier_type +{ + OCR_KNN_CLASSIFIER = 0, + OCR_CNN_CLASSIFIER = 1 +}; + +/** @brief OCRHMMDecoder class provides an interface for OCR using Hidden Markov Models. + +@note + - (C++) An example on using OCRHMMDecoder recognition combined with scene text detection can + be found at the webcam_demo sample: + <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/webcam_demo.cpp> + */ +class CV_EXPORTS_W OCRHMMDecoder : public BaseOCR +{ +public: + + /** @brief Callback with the character classifier is made a class. + + This way it hides the feature extractor and the classifier itself, so developers can write + their own OCR code. + + The default character classifier and feature extractor can be loaded using the utility function + loadOCRHMMClassifierNM and KNN model provided in + <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/OCRHMM_knn_model_data.xml.gz>. + */ + class CV_EXPORTS_W ClassifierCallback + { + public: + virtual ~ClassifierCallback() { } + /** @brief The character classifier must return a (ranked list of) class(es) id('s) + + @param image Input image CV_8UC1 or CV_8UC3 with a single letter. + @param out_class The classifier returns the character class categorical label, or list of + class labels, to which the input image corresponds. + @param out_confidence The classifier returns the probability of the input image + corresponding to each classes in out_class. + */ + virtual void eval( InputArray image, std::vector<int>& out_class, std::vector<double>& out_confidence); + }; + +public: + /** @brief Recognize text using HMM. + + Takes binary image on input and returns recognized text in the output_text parameter. Optionally + provides also the Rects for individual text elements found (e.g. words), and the list of those + text elements with their confidence values. + + @param image Input binary image CV_8UC1 with a single text line (or word). + + @param output_text Output text. Most likely character sequence found by the HMM decoder. + + @param component_rects If provided the method will output a list of Rects for the individual + text elements found (e.g. words). + + @param component_texts If provided the method will output a list of text strings for the + recognition of individual text elements found (e.g. words). + + @param component_confidences If provided the method will output a list of confidence values + for the recognition of individual text elements found (e.g. words). + + @param component_level Only OCR_LEVEL_WORD is supported. + */ + virtual void run(Mat& image, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) CV_OVERRIDE; + + /** @brief Recognize text using HMM. + + Takes an image and a mask (where each connected component corresponds to a segmented character) + on input and returns recognized text in the output_text parameter. Optionally + provides also the Rects for individual text elements found (e.g. words), and the list of those + text elements with their confidence values. + + @param image Input image CV_8UC1 or CV_8UC3 with a single text line (or word). + @param mask Input binary image CV_8UC1 same size as input image. Each connected component in mask corresponds to a segmented character in the input image. + + @param output_text Output text. Most likely character sequence found by the HMM decoder. + + @param component_rects If provided the method will output a list of Rects for the individual + text elements found (e.g. words). + + @param component_texts If provided the method will output a list of text strings for the + recognition of individual text elements found (e.g. words). + + @param component_confidences If provided the method will output a list of confidence values + for the recognition of individual text elements found (e.g. words). + + @param component_level Only OCR_LEVEL_WORD is supported. + */ + virtual void run(Mat& image, Mat& mask, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) CV_OVERRIDE; + + // aliases for scripting + CV_WRAP String run(InputArray image, int min_confidence, int component_level=0); + + CV_WRAP String run(InputArray image, InputArray mask, int min_confidence, int component_level=0); + + /** @brief Creates an instance of the OCRHMMDecoder class. Initializes HMMDecoder. + + @param classifier The character classifier with built in feature extractor. + + @param vocabulary The language vocabulary (chars when ascii english text). vocabulary.size() + must be equal to the number of classes of the classifier. + + @param transition_probabilities_table Table with transition probabilities between character + pairs. cols == rows == vocabulary.size(). + + @param emission_probabilities_table Table with observation emission probabilities. cols == + rows == vocabulary.size(). + + @param mode HMM Decoding algorithm. Only OCR_DECODER_VITERBI is available for the moment + (<http://en.wikipedia.org/wiki/Viterbi_algorithm>). + */ + static Ptr<OCRHMMDecoder> create(const Ptr<OCRHMMDecoder::ClassifierCallback> classifier,// The character classifier with built in feature extractor + const std::string& vocabulary, // The language vocabulary (chars when ASCII English text) + // size() must be equal to the number of classes + InputArray transition_probabilities_table, // Table with transition probabilities between character pairs + // cols == rows == vocabulary.size() + InputArray emission_probabilities_table, // Table with observation emission probabilities + // cols == rows == vocabulary.size() + decoder_mode mode = OCR_DECODER_VITERBI); // HMM Decoding algorithm (only Viterbi for the moment) + + CV_WRAP static Ptr<OCRHMMDecoder> create(const Ptr<OCRHMMDecoder::ClassifierCallback> classifier,// The character classifier with built in feature extractor + const String& vocabulary, // The language vocabulary (chars when ASCII English text) + // size() must be equal to the number of classes + InputArray transition_probabilities_table, // Table with transition probabilities between character pairs + // cols == rows == vocabulary.size() + InputArray emission_probabilities_table, // Table with observation emission probabilities + // cols == rows == vocabulary.size() + int mode = OCR_DECODER_VITERBI); // HMM Decoding algorithm (only Viterbi for the moment) + + /** @brief Creates an instance of the OCRHMMDecoder class. Loads and initializes HMMDecoder from the specified path + + @overload + */ + CV_WRAP static Ptr<OCRHMMDecoder> create(const String& filename, + + const String& vocabulary, // The language vocabulary (chars when ASCII English text) + // size() must be equal to the number of classes + InputArray transition_probabilities_table, // Table with transition probabilities between character pairs + // cols == rows == vocabulary.size() + InputArray emission_probabilities_table, // Table with observation emission probabilities + // cols == rows == vocabulary.size() + int mode = OCR_DECODER_VITERBI, // HMM Decoding algorithm (only Viterbi for the moment) + + int classifier = OCR_KNN_CLASSIFIER); // The character classifier type +protected: + + Ptr<OCRHMMDecoder::ClassifierCallback> classifier; + std::string vocabulary; + Mat transition_p; + Mat emission_p; + decoder_mode mode; +}; + +/** @brief Allow to implicitly load the default character classifier when creating an OCRHMMDecoder object. + +@param filename The XML or YAML file with the classifier model (e.g. OCRHMM_knn_model_data.xml) + +The KNN default classifier is based in the scene text recognition method proposed by Lukás Neumann & +Jiri Matas in [Neumann11b]. Basically, the region (contour) in the input image is normalized to a +fixed size, while retaining the centroid and aspect ratio, in order to extract a feature vector +based on gradient orientations along the chain-code of its perimeter. Then, the region is classified +using a KNN model trained with synthetic data of rendered characters with different standard font +types. + +@deprecated loadOCRHMMClassifier instead + */ + +CV_EXPORTS_W Ptr<OCRHMMDecoder::ClassifierCallback> loadOCRHMMClassifierNM(const String& filename); + +/** @brief Allow to implicitly load the default character classifier when creating an OCRHMMDecoder object. + +@param filename The XML or YAML file with the classifier model (e.g. OCRBeamSearch_CNN_model_data.xml.gz) + +The CNN default classifier is based in the scene text recognition method proposed by Adam Coates & +Andrew NG in [Coates11a]. The character classifier consists in a Single Layer Convolutional Neural Network and +a linear classifier. It is applied to the input image in a sliding window fashion, providing a set of recognitions +at each window location. + +@deprecated use loadOCRHMMClassifier instead + */ +CV_EXPORTS_W Ptr<OCRHMMDecoder::ClassifierCallback> loadOCRHMMClassifierCNN(const String& filename); + +/** @brief Allow to implicitly load the default character classifier when creating an OCRHMMDecoder object. + + @param filename The XML or YAML file with the classifier model (e.g. OCRBeamSearch_CNN_model_data.xml.gz) + + @param classifier Can be one of classifier_type enum values. + + */ +CV_EXPORTS_W Ptr<OCRHMMDecoder::ClassifierCallback> loadOCRHMMClassifier(const String& filename, int classifier); +//! @} + +/** @brief Utility function to create a tailored language model transitions table from a given list of words (lexicon). + * + * @param vocabulary The language vocabulary (chars when ASCII English text). + * + * @param lexicon The list of words that are expected to be found in a particular image. + * + * @param transition_probabilities_table Output table with transition probabilities between character pairs. cols == rows == vocabulary.size(). + * + * The function calculate frequency statistics of character pairs from the given lexicon and fills the output transition_probabilities_table with them. The transition_probabilities_table can be used as input in the OCRHMMDecoder::create() and OCRBeamSearchDecoder::create() methods. + * @note + * - (C++) An alternative would be to load the default generic language transition table provided in the text module samples folder (created from ispell 42869 english words list) : + * <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/OCRHMM_transitions_table.xml> + **/ +CV_EXPORTS void createOCRHMMTransitionsTable(std::string& vocabulary, std::vector<std::string>& lexicon, OutputArray transition_probabilities_table); + +CV_EXPORTS_W Mat createOCRHMMTransitionsTable(const String& vocabulary, std::vector<cv::String>& lexicon); + + +/* OCR BeamSearch Decoder */ + +/** @brief OCRBeamSearchDecoder class provides an interface for OCR using Beam Search algorithm. + +@note + - (C++) An example on using OCRBeamSearchDecoder recognition combined with scene text detection can + be found at the demo sample: + <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/word_recognition.cpp> + */ +class CV_EXPORTS_W OCRBeamSearchDecoder : public BaseOCR +{ +public: + + /** @brief Callback with the character classifier is made a class. + + This way it hides the feature extractor and the classifier itself, so developers can write + their own OCR code. + + The default character classifier and feature extractor can be loaded using the utility funtion + loadOCRBeamSearchClassifierCNN with all its parameters provided in + <https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/OCRBeamSearch_CNN_model_data.xml.gz>. + */ + class CV_EXPORTS_W ClassifierCallback + { + public: + virtual ~ClassifierCallback() { } + /** @brief The character classifier must return a (ranked list of) class(es) id('s) + + @param image Input image CV_8UC1 or CV_8UC3 with a single letter. + @param recognition_probabilities For each of the N characters found the classifier returns a list with + class probabilities for each class. + @param oversegmentation The classifier returns a list of N+1 character locations' x-coordinates, + including 0 as start-sequence location. + */ + virtual void eval( InputArray image, std::vector< std::vector<double> >& recognition_probabilities, std::vector<int>& oversegmentation ); + + int getWindowSize() {return 0;} + int getStepSize() {return 0;} + }; + +public: + /** @brief Recognize text using Beam Search. + + Takes image on input and returns recognized text in the output_text parameter. Optionally + provides also the Rects for individual text elements found (e.g. words), and the list of those + text elements with their confidence values. + + @param image Input binary image CV_8UC1 with a single text line (or word). + + @param output_text Output text. Most likely character sequence found by the HMM decoder. + + @param component_rects If provided the method will output a list of Rects for the individual + text elements found (e.g. words). + + @param component_texts If provided the method will output a list of text strings for the + recognition of individual text elements found (e.g. words). + + @param component_confidences If provided the method will output a list of confidence values + for the recognition of individual text elements found (e.g. words). + + @param component_level Only OCR_LEVEL_WORD is supported. + */ + virtual void run(Mat& image, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) CV_OVERRIDE; + + virtual void run(Mat& image, Mat& mask, std::string& output_text, std::vector<Rect>* component_rects=NULL, + std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL, + int component_level=0) CV_OVERRIDE; + + // aliases for scripting + CV_WRAP String run(InputArray image, int min_confidence, int component_level=0); + + CV_WRAP String run(InputArray image, InputArray mask, int min_confidence, int component_level=0); + + /** @brief Creates an instance of the OCRBeamSearchDecoder class. Initializes HMMDecoder. + + @param classifier The character classifier with built in feature extractor. + + @param vocabulary The language vocabulary (chars when ASCII English text). vocabulary.size() + must be equal to the number of classes of the classifier. + + @param transition_probabilities_table Table with transition probabilities between character + pairs. cols == rows == vocabulary.size(). + + @param emission_probabilities_table Table with observation emission probabilities. cols == + rows == vocabulary.size(). + + @param mode HMM Decoding algorithm. Only OCR_DECODER_VITERBI is available for the moment + (<http://en.wikipedia.org/wiki/Viterbi_algorithm>). + + @param beam_size Size of the beam in Beam Search algorithm. + */ + static Ptr<OCRBeamSearchDecoder> create(const Ptr<OCRBeamSearchDecoder::ClassifierCallback> classifier,// The character classifier with built in feature extractor + const std::string& vocabulary, // The language vocabulary (chars when ASCII English text) + // size() must be equal to the number of classes + InputArray transition_probabilities_table, // Table with transition probabilities between character pairs + // cols == rows == vocabulary.size() + InputArray emission_probabilities_table, // Table with observation emission probabilities + // cols == rows == vocabulary.size() + decoder_mode mode = OCR_DECODER_VITERBI, // HMM Decoding algorithm (only Viterbi for the moment) + int beam_size = 500); // Size of the beam in Beam Search algorithm + + CV_WRAP static Ptr<OCRBeamSearchDecoder> create(const Ptr<OCRBeamSearchDecoder::ClassifierCallback> classifier, // The character classifier with built in feature extractor + const String& vocabulary, // The language vocabulary (chars when ASCII English text) + // size() must be equal to the number of classes + InputArray transition_probabilities_table, // Table with transition probabilities between character pairs + // cols == rows == vocabulary.size() + InputArray emission_probabilities_table, // Table with observation emission probabilities + // cols == rows == vocabulary.size() + int mode = OCR_DECODER_VITERBI, // HMM Decoding algorithm (only Viterbi for the moment) + int beam_size = 500); // Size of the beam in Beam Search algorithm + + /** @brief Creates an instance of the OCRBeamSearchDecoder class. Initializes HMMDecoder from the specified path. + + @overload + + */ + CV_WRAP static Ptr<OCRBeamSearchDecoder> create(const String& filename, // The character classifier file + const String& vocabulary, // The language vocabulary (chars when ASCII English text) + // size() must be equal to the number of classes + InputArray transition_probabilities_table, // Table with transition probabilities between character pairs + // cols == rows == vocabulary.size() + InputArray emission_probabilities_table, // Table with observation emission probabilities + // cols == rows == vocabulary.size() + int mode = OCR_DECODER_VITERBI, // HMM Decoding algorithm (only Viterbi for the moment) + int beam_size = 500); +protected: + + Ptr<OCRBeamSearchDecoder::ClassifierCallback> classifier; + std::string vocabulary; + Mat transition_p; + Mat emission_p; + decoder_mode mode; + int beam_size; +}; + +/** @brief Allow to implicitly load the default character classifier when creating an OCRBeamSearchDecoder object. + +@param filename The XML or YAML file with the classifier model (e.g. OCRBeamSearch_CNN_model_data.xml.gz) + +The CNN default classifier is based in the scene text recognition method proposed by Adam Coates & +Andrew NG in [Coates11a]. The character classifier consists in a Single Layer Convolutional Neural Network and +a linear classifier. It is applied to the input image in a sliding window fashion, providing a set of recognitions +at each window location. + */ + +CV_EXPORTS_W Ptr<OCRBeamSearchDecoder::ClassifierCallback> loadOCRBeamSearchClassifierCNN(const String& filename); + + +/** @brief OCRHolisticWordRecognizer class provides the functionallity of segmented wordspotting. + * Given a predefined vocabulary , a DictNet is employed to select the most probable + * word given an input image. + * + * DictNet is described in detail in: + * Max Jaderberg et al.: Reading Text in the Wild with Convolutional Neural Networks, IJCV 2015 + * http://arxiv.org/abs/1412.1842 + */ +class CV_EXPORTS OCRHolisticWordRecognizer : public BaseOCR +{ +public: + virtual void run(Mat& image, + std::string& output_text, + std::vector<Rect>* component_rects = NULL, + std::vector<std::string>* component_texts = NULL, + std::vector<float>* component_confidences = NULL, + int component_level = OCR_LEVEL_WORD) CV_OVERRIDE = 0; + + /** @brief Recognize text using a segmentation based word-spotting/classifier cnn. + + Takes image on input and returns recognized text in the output_text parameter. Optionally + provides also the Rects for individual text elements found (e.g. words), and the list of those + text elements with their confidence values. + + @param image Input image CV_8UC1 or CV_8UC3 + + @param mask is totally ignored and is only available for compatibillity reasons + + @param output_text Output text of the the word spoting, always one that exists in the dictionary. + + @param component_rects Not applicable for word spotting can be be NULL if not, a single elemnt will + be put in the vector. + + @param component_texts Not applicable for word spotting can be be NULL if not, a single elemnt will + be put in the vector. + + @param component_confidences Not applicable for word spotting can be be NULL if not, a single elemnt will + be put in the vector. + + @param component_level must be OCR_LEVEL_WORD. + */ + virtual void run(Mat& image, + Mat& mask, + std::string& output_text, + std::vector<Rect>* component_rects = NULL, + std::vector<std::string>* component_texts = NULL, + std::vector<float>* component_confidences = NULL, + int component_level = OCR_LEVEL_WORD) CV_OVERRIDE = 0; + + /** @brief Creates an instance of the OCRHolisticWordRecognizer class. + */ + static Ptr<OCRHolisticWordRecognizer> create(const std::string &archFilename, + const std::string &weightsFilename, + const std::string &wordsFilename); +}; + +//! @} + +}} // cv::text:: + + +#endif // _OPENCV_TEXT_OCR_HPP_ diff --git a/include/opencv2/text/textDetector.hpp b/include/opencv2/text/textDetector.hpp new file mode 100644 index 0000000..da65337 --- /dev/null +++ b/include/opencv2/text/textDetector.hpp @@ -0,0 +1,73 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __OPENCV_TEXT_TEXTDETECTOR_HPP__ +#define __OPENCV_TEXT_TEXTDETECTOR_HPP__ + +#include "ocr.hpp" + +namespace cv +{ +namespace text +{ + +//! @addtogroup text_detect +//! @{ + +/** @brief An abstract class providing interface for text detection algorithms + */ +class CV_EXPORTS_W TextDetector +{ +public: + /** + @brief Method that provides a quick and simple interface to detect text inside an image + + @param inputImage an image to process + @param Bbox a vector of Rect that will store the detected word bounding box + @param confidence a vector of float that will be updated with the confidence the classifier has for the selected bounding box + */ + CV_WRAP virtual void detect(InputArray inputImage, CV_OUT std::vector<Rect>& Bbox, CV_OUT std::vector<float>& confidence) = 0; + virtual ~TextDetector() {} +}; + +/** @brief TextDetectorCNN class provides the functionallity of text bounding box detection. + This class is representing to find bounding boxes of text words given an input image. + This class uses OpenCV dnn module to load pre-trained model described in @cite LiaoSBWL17. + The original repository with the modified SSD Caffe version: https://github.com/MhLiao/TextBoxes. + Model can be downloaded from [DropBox](https://www.dropbox.com/s/g8pjzv2de9gty8g/TextBoxes_icdar13.caffemodel?dl=0). + Modified .prototxt file with the model description can be found in `opencv_contrib/modules/text/samples/textbox.prototxt`. + */ +class CV_EXPORTS_W TextDetectorCNN : public TextDetector +{ +public: + /** + @overload + + @param inputImage an image expected to be a CV_U8C3 of any size + @param Bbox a vector of Rect that will store the detected word bounding box + @param confidence a vector of float that will be updated with the confidence the classifier has for the selected bounding box + */ + CV_WRAP virtual void detect(InputArray inputImage, CV_OUT std::vector<Rect>& Bbox, CV_OUT std::vector<float>& confidence) CV_OVERRIDE = 0; + + /** @brief Creates an instance of the TextDetectorCNN class using the provided parameters. + + @param modelArchFilename the relative or absolute path to the prototxt file describing the classifiers architecture. + @param modelWeightsFilename the relative or absolute path to the file containing the pretrained weights of the model in caffe-binary form. + @param detectionSizes a list of sizes for multiscale detection. The values`[(300,300),(700,500),(700,300),(700,700),(1600,1600)]` are + recommended in @cite LiaoSBWL17 to achieve the best quality. + */ + static Ptr<TextDetectorCNN> create(const String& modelArchFilename, const String& modelWeightsFilename, + std::vector<Size> detectionSizes); + /** + @overload + */ + CV_WRAP static Ptr<TextDetectorCNN> create(const String& modelArchFilename, const String& modelWeightsFilename); +}; + +//! @} +}//namespace text +}//namespace cv + + +#endif // _OPENCV_TEXT_OCR_HPP_ diff --git a/include/opencv2/tracking.hpp b/include/opencv2/tracking.hpp new file mode 100644 index 0000000..e1c44ab --- /dev/null +++ b/include/opencv2/tracking.hpp @@ -0,0 +1,284 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_TRACKING_HPP__ +#define __OPENCV_TRACKING_HPP__ + +#include "opencv2/core/cvdef.h" + +/** @defgroup tracking Tracking API + +Long-term optical tracking API +------------------------------ + +Long-term optical tracking is an important issue for many computer vision applications in +real world scenario. The development in this area is very fragmented and this API is an unique +interface useful for plug several algorithms and compare them. This work is partially based on +@cite AAM and @cite AMVOT . + +These algorithms start from a bounding box of the target and with their internal representation they +avoid the drift during the tracking. These long-term trackers are able to evaluate online the +quality of the location of the target in the new frame, without ground truth. + +There are three main components: the TrackerSampler, the TrackerFeatureSet and the TrackerModel. The +first component is the object that computes the patches over the frame based on the last target +location. The TrackerFeatureSet is the class that manages the Features, is possible plug many kind +of these (HAAR, HOG, LBP, Feature2D, etc). The last component is the internal representation of the +target, it is the appearence model. It stores all state candidates and compute the trajectory (the +most likely target states). The class TrackerTargetState represents a possible state of the target. +The TrackerSampler and the TrackerFeatureSet are the visual representation of the target, instead +the TrackerModel is the statistical model. + +A recent benchmark between these algorithms can be found in @cite OOT + +Creating Your Own %Tracker +-------------------- + +If you want to create a new tracker, here's what you have to do. First, decide on the name of the class +for the tracker (to meet the existing style, we suggest something with prefix "tracker", e.g. +trackerMIL, trackerBoosting) -- we shall refer to this choice as to "classname" in subsequent. + +- Declare your tracker in modules/tracking/include/opencv2/tracking/tracker.hpp. Your tracker should inherit from + Tracker (please, see the example below). You should declare the specialized Param structure, + where you probably will want to put the data, needed to initialize your tracker. You should + get something similar to : +@code + class CV_EXPORTS_W TrackerMIL : public Tracker + { + public: + struct CV_EXPORTS Params + { + Params(); + //parameters for sampler + float samplerInitInRadius; // radius for gathering positive instances during init + int samplerInitMaxNegNum; // # negative samples to use during init + float samplerSearchWinSize; // size of search window + float samplerTrackInRadius; // radius for gathering positive instances during tracking + int samplerTrackMaxPosNum; // # positive samples to use during tracking + int samplerTrackMaxNegNum; // # negative samples to use during tracking + int featureSetNumFeatures; // #features + + void read( const FileNode& fn ); + void write( FileStorage& fs ) const; + }; +@endcode + of course, you can also add any additional methods of your choice. It should be pointed out, + however, that it is not expected to have a constructor declared, as creation should be done via + the corresponding create() method. +- Finally, you should implement the function with signature : +@code + Ptr<classname> classname::create(const classname::Params ¶meters){ + ... + } +@endcode + That function can (and probably will) return a pointer to some derived class of "classname", + which will probably have a real constructor. + +Every tracker has three component TrackerSampler, TrackerFeatureSet and TrackerModel. The first two +are instantiated from Tracker base class, instead the last component is abstract, so you must +implement your TrackerModel. + +### TrackerSampler + +TrackerSampler is already instantiated, but you should define the sampling algorithm and add the +classes (or single class) to TrackerSampler. You can choose one of the ready implementation as +TrackerSamplerCSC or you can implement your sampling method, in this case the class must inherit +TrackerSamplerAlgorithm. Fill the samplingImpl method that writes the result in "sample" output +argument. + +Example of creating specialized TrackerSamplerAlgorithm TrackerSamplerCSC : : +@code + class CV_EXPORTS_W TrackerSamplerCSC : public TrackerSamplerAlgorithm + { + public: + TrackerSamplerCSC( const TrackerSamplerCSC::Params ¶meters = TrackerSamplerCSC::Params() ); + ~TrackerSamplerCSC(); + ... + + protected: + bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ); + ... + + }; +@endcode + +Example of adding TrackerSamplerAlgorithm to TrackerSampler : : +@code + //sampler is the TrackerSampler + Ptr<TrackerSamplerAlgorithm> CSCSampler = new TrackerSamplerCSC( CSCparameters ); + if( !sampler->addTrackerSamplerAlgorithm( CSCSampler ) ) + return false; + + //or add CSC sampler with default parameters + //sampler->addTrackerSamplerAlgorithm( "CSC" ); +@endcode +@sa + TrackerSamplerCSC, TrackerSamplerAlgorithm + +### TrackerFeatureSet + +TrackerFeatureSet is already instantiated (as first) , but you should define what kinds of features +you'll use in your tracker. You can use multiple feature types, so you can add a ready +implementation as TrackerFeatureHAAR in your TrackerFeatureSet or develop your own implementation. +In this case, in the computeImpl method put the code that extract the features and in the selection +method optionally put the code for the refinement and selection of the features. + +Example of creating specialized TrackerFeature TrackerFeatureHAAR : : +@code + class CV_EXPORTS_W TrackerFeatureHAAR : public TrackerFeature + { + public: + TrackerFeatureHAAR( const TrackerFeatureHAAR::Params ¶meters = TrackerFeatureHAAR::Params() ); + ~TrackerFeatureHAAR(); + void selection( Mat& response, int npoints ); + ... + + protected: + bool computeImpl( const std::vector<Mat>& images, Mat& response ); + ... + + }; +@endcode +Example of adding TrackerFeature to TrackerFeatureSet : : +@code + //featureSet is the TrackerFeatureSet + Ptr<TrackerFeature> trackerFeature = new TrackerFeatureHAAR( HAARparameters ); + featureSet->addTrackerFeature( trackerFeature ); +@endcode +@sa + TrackerFeatureHAAR, TrackerFeatureSet + +### TrackerModel + +TrackerModel is abstract, so in your implementation you must develop your TrackerModel that inherit +from TrackerModel. Fill the method for the estimation of the state "modelEstimationImpl", that +estimates the most likely target location, see @cite AAM table I (ME) for further information. Fill +"modelUpdateImpl" in order to update the model, see @cite AAM table I (MU). In this class you can use +the :cConfidenceMap and :cTrajectory to storing the model. The first represents the model on the all +possible candidate states and the second represents the list of all estimated states. + +Example of creating specialized TrackerModel TrackerMILModel : : +@code + class TrackerMILModel : public TrackerModel + { + public: + TrackerMILModel( const Rect& boundingBox ); + ~TrackerMILModel(); + ... + + protected: + void modelEstimationImpl( const std::vector<Mat>& responses ); + void modelUpdateImpl(); + ... + + }; +@endcode +And add it in your Tracker : : +@code + bool TrackerMIL::initImpl( const Mat& image, const Rect2d& boundingBox ) + { + ... + //model is the general TrackerModel field of the general Tracker + model = new TrackerMILModel( boundingBox ); + ... + } +@endcode +In the last step you should define the TrackerStateEstimator based on your implementation or you can +use one of ready class as TrackerStateEstimatorMILBoosting. It represent the statistical part of the +model that estimates the most likely target state. + +Example of creating specialized TrackerStateEstimator TrackerStateEstimatorMILBoosting : : +@code + class CV_EXPORTS_W TrackerStateEstimatorMILBoosting : public TrackerStateEstimator + { + class TrackerMILTargetState : public TrackerTargetState + { + ... + }; + + public: + TrackerStateEstimatorMILBoosting( int nFeatures = 250 ); + ~TrackerStateEstimatorMILBoosting(); + ... + + protected: + Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ); + void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ); + ... + + }; +@endcode +And add it in your TrackerModel : : +@code + //model is the TrackerModel of your Tracker + Ptr<TrackerStateEstimatorMILBoosting> stateEstimator = new TrackerStateEstimatorMILBoosting( params.featureSetNumFeatures ); + model->setTrackerStateEstimator( stateEstimator ); +@endcode +@sa + TrackerModel, TrackerStateEstimatorMILBoosting, TrackerTargetState + +During this step, you should define your TrackerTargetState based on your implementation. +TrackerTargetState base class has only the bounding box (upper-left position, width and height), you +can enrich it adding scale factor, target rotation, etc. + +Example of creating specialized TrackerTargetState TrackerMILTargetState : : +@code + class TrackerMILTargetState : public TrackerTargetState + { + public: + TrackerMILTargetState( const Point2f& position, int targetWidth, int targetHeight, bool foreground, const Mat& features ); + ~TrackerMILTargetState(); + ... + + private: + bool isTarget; + Mat targetFeatures; + ... + + }; +@endcode + +*/ + +#include <opencv2/tracking/tracker.hpp> +#include <opencv2/tracking/tldDataset.hpp> + +#endif //__OPENCV_TRACKING_HPP__ diff --git a/include/opencv2/tracking/feature.hpp b/include/opencv2/tracking/feature.hpp new file mode 100644 index 0000000..710a370 --- /dev/null +++ b/include/opencv2/tracking/feature.hpp @@ -0,0 +1,415 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_FEATURE_HPP__ +#define __OPENCV_FEATURE_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include <iostream> +#include <string> +#include <time.h> + +/* + * TODO This implementation is based on apps/traincascade/ + * TODO Changed CvHaarEvaluator based on ADABOOSTING implementation (Grabner et al.) + */ + +namespace cv +{ + +//! @addtogroup tracking +//! @{ + +#define FEATURES "features" + +#define CC_FEATURES FEATURES +#define CC_FEATURE_PARAMS "featureParams" +#define CC_MAX_CAT_COUNT "maxCatCount" +#define CC_FEATURE_SIZE "featSize" +#define CC_NUM_FEATURES "numFeat" +#define CC_ISINTEGRAL "isIntegral" +#define CC_RECTS "rects" +#define CC_TILTED "tilted" +#define CC_RECT "rect" + +#define LBPF_NAME "lbpFeatureParams" +#define HOGF_NAME "HOGFeatureParams" +#define HFP_NAME "haarFeatureParams" + +#define CV_HAAR_FEATURE_MAX 3 +#define N_BINS 9 +#define N_CELLS 4 + +#define CV_SUM_OFFSETS( p0, p1, p2, p3, rect, step ) \ + /* (x, y) */ \ + (p0) = (rect).x + (step) * (rect).y; \ + /* (x + w, y) */ \ + (p1) = (rect).x + (rect).width + (step) * (rect).y; \ + /* (x + w, y) */ \ + (p2) = (rect).x + (step) * ((rect).y + (rect).height); \ + /* (x + w, y + h) */ \ + (p3) = (rect).x + (rect).width + (step) * ((rect).y + (rect).height); + +#define CV_TILTED_OFFSETS( p0, p1, p2, p3, rect, step ) \ + /* (x, y) */ \ + (p0) = (rect).x + (step) * (rect).y; \ + /* (x - h, y + h) */ \ + (p1) = (rect).x - (rect).height + (step) * ((rect).y + (rect).height);\ + /* (x + w, y + w) */ \ + (p2) = (rect).x + (rect).width + (step) * ((rect).y + (rect).width); \ + /* (x + w - h, y + w + h) */ \ + (p3) = (rect).x + (rect).width - (rect).height \ + + (step) * ((rect).y + (rect).width + (rect).height); + +float calcNormFactor( const Mat& sum, const Mat& sqSum ); + +template<class Feature> +void _writeFeatures( const std::vector<Feature> features, FileStorage &fs, const Mat& featureMap ) +{ + fs << FEATURES << "["; + const Mat_<int>& featureMap_ = (const Mat_<int>&) featureMap; + for ( int fi = 0; fi < featureMap.cols; fi++ ) + if( featureMap_( 0, fi ) >= 0 ) + { + fs << "{"; + features[fi].write( fs ); + fs << "}"; + } + fs << "]"; +} + +class CvParams +{ + public: + CvParams(); + virtual ~CvParams() + { + } + // from|to file + virtual void write( FileStorage &fs ) const = 0; + virtual bool read( const FileNode &node ) = 0; + // from|to screen + virtual void printDefaults() const; + virtual void printAttrs() const; + virtual bool scanAttr( const std::string prmName, const std::string val ); + std::string name; +}; + +class CvFeatureParams : public CvParams +{ + public: + enum + { + HAAR = 0, + LBP = 1, + HOG = 2 + }; + CvFeatureParams(); + virtual void init( const CvFeatureParams& fp ); + virtual void write( FileStorage &fs ) const CV_OVERRIDE; + virtual bool read( const FileNode &node ) CV_OVERRIDE; + static Ptr<CvFeatureParams> create( int featureType ); + int maxCatCount; // 0 in case of numerical features + int featSize; // 1 in case of simple features (HAAR, LBP) and N_BINS(9)*N_CELLS(4) in case of Dalal's HOG features + int numFeatures; +}; + +class CvFeatureEvaluator +{ + public: + virtual ~CvFeatureEvaluator() + { + } + virtual void init( const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize ); + virtual void setImage( const Mat& img, uchar clsLabel, int idx ); + virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const = 0; + virtual float operator()( int featureIdx, int sampleIdx ) = 0; + static Ptr<CvFeatureEvaluator> create( int type ); + + int getNumFeatures() const + { + return numFeatures; + } + int getMaxCatCount() const + { + return featureParams->maxCatCount; + } + int getFeatureSize() const + { + return featureParams->featSize; + } + const Mat& getCls() const + { + return cls; + } + float getCls( int si ) const + { + return cls.at<float>( si, 0 ); + } + protected: + virtual void generateFeatures() = 0; + + int npos, nneg; + int numFeatures; + Size winSize; + CvFeatureParams *featureParams; + Mat cls; +}; + +class CvHaarFeatureParams : public CvFeatureParams +{ + public: + + CvHaarFeatureParams(); + + virtual void init( const CvFeatureParams& fp ) CV_OVERRIDE; + virtual void write( FileStorage &fs ) const CV_OVERRIDE; + virtual bool read( const FileNode &node ) CV_OVERRIDE; + + virtual void printDefaults() const CV_OVERRIDE; + virtual void printAttrs() const CV_OVERRIDE; + virtual bool scanAttr( const std::string prm, const std::string val ) CV_OVERRIDE; + + bool isIntegral; +}; + +class CvHaarEvaluator : public CvFeatureEvaluator +{ + public: + + class FeatureHaar + { + + public: + + FeatureHaar( Size patchSize ); + bool eval( const Mat& image, Rect ROI, float* result ) const; + int getNumAreas(); + const std::vector<float>& getWeights() const; + const std::vector<Rect>& getAreas() const; + void write( FileStorage ) const + { + } + ; + float getInitMean() const; + float getInitSigma() const; + + private: + int m_type; + int m_numAreas; + std::vector<float> m_weights; + float m_initMean; + float m_initSigma; + void generateRandomFeature( Size imageSize ); + float getSum( const Mat& image, Rect imgROI ) const; + std::vector<Rect> m_areas; // areas within the patch over which to compute the feature + cv::Size m_initSize; // size of the patch used during training + cv::Size m_curSize; // size of the patches currently under investigation + float m_scaleFactorHeight; // scaling factor in vertical direction + float m_scaleFactorWidth; // scaling factor in horizontal direction + std::vector<Rect> m_scaleAreas; // areas after scaling + std::vector<float> m_scaleWeights; // weights after scaling + + }; + + virtual void init( const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize ) CV_OVERRIDE; + virtual void setImage( const Mat& img, uchar clsLabel = 0, int idx = 1 ) CV_OVERRIDE; + virtual float operator()( int featureIdx, int sampleIdx ) CV_OVERRIDE; + virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const CV_OVERRIDE; + void writeFeature( FileStorage &fs ) const; // for old file format + const std::vector<CvHaarEvaluator::FeatureHaar>& getFeatures() const; + inline CvHaarEvaluator::FeatureHaar& getFeatures( int idx ) + { + return features[idx]; + } + void setWinSize( Size patchSize ); + Size setWinSize() const; + virtual void generateFeatures() CV_OVERRIDE; + + /** + * TODO new method + * \brief Overload the original generateFeatures in order to limit the number of the features + * @param numFeatures Number of the features + */ + + virtual void generateFeatures( int numFeatures ); + + protected: + bool isIntegral; + + /* TODO Added from MIL implementation */ + Mat _ii_img; + void compute_integral( const cv::Mat & img, std::vector<cv::Mat_<float> > & ii_imgs ) + { + Mat ii_img; + integral( img, ii_img, CV_32F ); + split( ii_img, ii_imgs ); + } + + std::vector<FeatureHaar> features; + Mat sum; /* sum images (each row represents image) */ +}; + +struct CvHOGFeatureParams : public CvFeatureParams +{ + CvHOGFeatureParams(); +}; + +class CvHOGEvaluator : public CvFeatureEvaluator +{ + public: + virtual ~CvHOGEvaluator() + { + } + virtual void init( const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize ) CV_OVERRIDE; + virtual void setImage( const Mat& img, uchar clsLabel, int idx ) CV_OVERRIDE; + virtual float operator()( int varIdx, int sampleIdx ) CV_OVERRIDE; + virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const CV_OVERRIDE; + protected: + virtual void generateFeatures() CV_OVERRIDE; + virtual void integralHistogram( const Mat &img, std::vector<Mat> &histogram, Mat &norm, int nbins ) const; + class Feature + { + public: + Feature(); + Feature( int offset, int x, int y, int cellW, int cellH ); + float calc( const std::vector<Mat> &_hists, const Mat &_normSum, size_t y, int featComponent ) const; + void write( FileStorage &fs ) const; + void write( FileStorage &fs, int varIdx ) const; + + Rect rect[N_CELLS]; //cells + + struct + { + int p0, p1, p2, p3; + } fastRect[N_CELLS]; + }; + std::vector<Feature> features; + + Mat normSum; //for nomalization calculation (L1 or L2) + std::vector<Mat> hist; +}; + +inline float CvHOGEvaluator::operator()( int varIdx, int sampleIdx ) +{ + int featureIdx = varIdx / ( N_BINS * N_CELLS ); + int componentIdx = varIdx % ( N_BINS * N_CELLS ); + //return features[featureIdx].calc( hist, sampleIdx, componentIdx); + return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx ); +} + +inline float CvHOGEvaluator::Feature::calc( const std::vector<Mat>& _hists, const Mat& _normSum, size_t y, int featComponent ) const +{ + float normFactor; + float res; + + int binIdx = featComponent % N_BINS; + int cellIdx = featComponent / N_BINS; + + const float *phist = _hists[binIdx].ptr<float>( (int) y ); + res = phist[fastRect[cellIdx].p0] - phist[fastRect[cellIdx].p1] - phist[fastRect[cellIdx].p2] + phist[fastRect[cellIdx].p3]; + + const float *pnormSum = _normSum.ptr<float>( (int) y ); + normFactor = (float) ( pnormSum[fastRect[0].p0] - pnormSum[fastRect[1].p1] - pnormSum[fastRect[2].p2] + pnormSum[fastRect[3].p3] ); + res = ( res > 0.001f ) ? ( res / ( normFactor + 0.001f ) ) : 0.f; //for cutting negative values, which apper due to floating precision + + return res; +} + +struct CvLBPFeatureParams : CvFeatureParams +{ + CvLBPFeatureParams(); + +}; + +class CvLBPEvaluator : public CvFeatureEvaluator +{ + public: + virtual ~CvLBPEvaluator() CV_OVERRIDE + { + } + virtual void init( const CvFeatureParams *_featureParams, int _maxSampleCount, Size _winSize ) CV_OVERRIDE; + virtual void setImage( const Mat& img, uchar clsLabel, int idx ) CV_OVERRIDE; + virtual float operator()( int featureIdx, int sampleIdx ) CV_OVERRIDE + { + return (float) features[featureIdx].calc( sum, sampleIdx ); + } + virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const CV_OVERRIDE; + protected: + virtual void generateFeatures() CV_OVERRIDE; + + class Feature + { + public: + Feature(); + Feature( int offset, int x, int y, int _block_w, int _block_h ); + uchar calc( const Mat& _sum, size_t y ) const; + void write( FileStorage &fs ) const; + + Rect rect; + int p[16]; + }; + std::vector<Feature> features; + + Mat sum; +}; + +inline uchar CvLBPEvaluator::Feature::calc( const Mat &_sum, size_t y ) const +{ + const int* psum = _sum.ptr<int>( (int) y ); + int cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]]; + + return (uchar) ( ( psum[p[0]] - psum[p[1]] - psum[p[4]] + psum[p[5]] >= cval ? 128 : 0 ) | // 0 + ( psum[p[1]] - psum[p[2]] - psum[p[5]] + psum[p[6]] >= cval ? 64 : 0 ) | // 1 + ( psum[p[2]] - psum[p[3]] - psum[p[6]] + psum[p[7]] >= cval ? 32 : 0 ) | // 2 + ( psum[p[6]] - psum[p[7]] - psum[p[10]] + psum[p[11]] >= cval ? 16 : 0 ) | // 5 + ( psum[p[10]] - psum[p[11]] - psum[p[14]] + psum[p[15]] >= cval ? 8 : 0 ) | // 8 + ( psum[p[9]] - psum[p[10]] - psum[p[13]] + psum[p[14]] >= cval ? 4 : 0 ) | // 7 + ( psum[p[8]] - psum[p[9]] - psum[p[12]] + psum[p[13]] >= cval ? 2 : 0 ) | // 6 + ( psum[p[4]] - psum[p[5]] - psum[p[8]] + psum[p[9]] >= cval ? 1 : 0 ) ); // 3 +} + +//! @} + +} /* namespace cv */ + +#endif diff --git a/include/opencv2/tracking/kalman_filters.hpp b/include/opencv2/tracking/kalman_filters.hpp new file mode 100644 index 0000000..7a89c87 --- /dev/null +++ b/include/opencv2/tracking/kalman_filters.hpp @@ -0,0 +1,228 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_TRACKING_KALMAN_HPP_ +#define __OPENCV_TRACKING_KALMAN_HPP_ + +#include "opencv2/core.hpp" +#include <limits> + +namespace cv +{ +namespace tracking +{ + +/** @brief The interface for Unscented Kalman filter and Augmented Unscented Kalman filter. +*/ +class CV_EXPORTS UnscentedKalmanFilter +{ +public: + + virtual ~UnscentedKalmanFilter(){} + + /** The function performs prediction step of the algorithm + * @param control - the current control vector, + * @return the predicted estimate of the state. + */ + virtual Mat predict( InputArray control = noArray() ) = 0; + + /** The function performs correction step of the algorithm + * @param measurement - the current measurement vector, + * @return the corrected estimate of the state. + */ + virtual Mat correct( InputArray measurement ) = 0; + + /** + * @return the process noise cross-covariance matrix. + */ + virtual Mat getProcessNoiseCov() const = 0; + + /** + * @return the measurement noise cross-covariance matrix. + */ + virtual Mat getMeasurementNoiseCov() const = 0; + + /** + * @return the error cross-covariance matrix. + */ + virtual Mat getErrorCov() const = 0; + + /** + * @return the current estimate of the state. + */ + virtual Mat getState() const = 0; +}; + +/** @brief Model of dynamical system for Unscented Kalman filter. +* The interface for dynamical system model. It contains functions for computing the next state and the measurement. +* It must be inherited for using UKF. +*/ +class CV_EXPORTS UkfSystemModel +{ +public: + + virtual ~UkfSystemModel(){} + + /** The function for computing the next state from the previous state + * @param x_k - previous state vector, + * @param u_k - control vector, + * @param v_k - noise vector, + * @param x_kplus1 - next state vector. + */ + virtual void stateConversionFunction( const Mat& x_k, const Mat& u_k, const Mat& v_k, Mat& x_kplus1 ) = 0; + /** The function for computing the measurement from the state + * @param x_k - state vector, + * @param n_k - noise vector, + * @param z_k - measurement vector. + */ + virtual void measurementFunction( const Mat& x_k, const Mat& n_k, Mat& z_k ) = 0; +}; + + +/** @brief Unscented Kalman filter parameters. +* The class for initialization parameters of Unscented Kalman filter +*/ +class CV_EXPORTS UnscentedKalmanFilterParams +{ +public: + + int DP; //!< Dimensionality of the state vector. + int MP; //!< Dimensionality of the measurement vector. + int CP; //!< Dimensionality of the control vector. + int dataType; //!< Type of elements of vectors and matrices, default is CV_64F. + + Mat stateInit; //!< Initial state, DP x 1, default is zero. + Mat errorCovInit; //!< State estimate cross-covariance matrix, DP x DP, default is identity. + + Mat processNoiseCov; //!< Process noise cross-covariance matrix, DP x DP. + Mat measurementNoiseCov; //!< Measurement noise cross-covariance matrix, MP x MP. + + // Parameters of algorithm + double alpha; //!< Default is 1e-3. + double k; //!< Default is 0. + double beta; //!< Default is 2.0. + + //Dynamical system model + Ptr<UkfSystemModel> model; //!< Object of the class containing functions for computing the next state and the measurement. + + /** The constructors. + */ + UnscentedKalmanFilterParams(){} + + /** + * @param dp - dimensionality of the state vector, + * @param mp - dimensionality of the measurement vector, + * @param cp - dimensionality of the control vector, + * @param processNoiseCovDiag - value of elements on main diagonal process noise cross-covariance matrix, + * @param measurementNoiseCovDiag - value of elements on main diagonal measurement noise cross-covariance matrix, + * @param dynamicalSystem - ptr to object of the class containing functions for computing the next state and the measurement, + * @param type - type of the created matrices that should be CV_32F or CV_64F. + */ + UnscentedKalmanFilterParams( int dp, int mp, int cp, double processNoiseCovDiag, double measurementNoiseCovDiag, + Ptr<UkfSystemModel> dynamicalSystem, int type = CV_64F ); + + /** The function for initialization of Unscented Kalman filter + * @param dp - dimensionality of the state vector, + * @param mp - dimensionality of the measurement vector, + * @param cp - dimensionality of the control vector, + * @param processNoiseCovDiag - value of elements on main diagonal process noise cross-covariance matrix, + * @param measurementNoiseCovDiag - value of elements on main diagonal measurement noise cross-covariance matrix, + * @param dynamicalSystem - ptr to object of the class containing functions for computing the next state and the measurement, + * @param type - type of the created matrices that should be CV_32F or CV_64F. + */ + void init( int dp, int mp, int cp, double processNoiseCovDiag, double measurementNoiseCovDiag, + Ptr<UkfSystemModel> dynamicalSystem, int type = CV_64F ); +}; + +/** @brief Augmented Unscented Kalman filter parameters. +* The class for initialization parameters of Augmented Unscented Kalman filter +*/ +class CV_EXPORTS AugmentedUnscentedKalmanFilterParams: public UnscentedKalmanFilterParams +{ +public: + + AugmentedUnscentedKalmanFilterParams(){} + + /** + * @param dp - dimensionality of the state vector, + * @param mp - dimensionality of the measurement vector, + * @param cp - dimensionality of the control vector, + * @param processNoiseCovDiag - value of elements on main diagonal process noise cross-covariance matrix, + * @param measurementNoiseCovDiag - value of elements on main diagonal measurement noise cross-covariance matrix, + * @param dynamicalSystem - ptr to object of the class containing functions for computing the next state and the measurement, + * @param type - type of the created matrices that should be CV_32F or CV_64F. + */ + AugmentedUnscentedKalmanFilterParams( int dp, int mp, int cp, double processNoiseCovDiag, double measurementNoiseCovDiag, + Ptr<UkfSystemModel> dynamicalSystem, int type = CV_64F ); + + /** The function for initialization of Augmented Unscented Kalman filter + * @param dp - dimensionality of the state vector, + * @param mp - dimensionality of the measurement vector, + * @param cp - dimensionality of the control vector, + * @param processNoiseCovDiag - value of elements on main diagonal process noise cross-covariance matrix, + * @param measurementNoiseCovDiag - value of elements on main diagonal measurement noise cross-covariance matrix, + * @param dynamicalSystem - object of the class containing functions for computing the next state and the measurement, + * @param type - type of the created matrices that should be CV_32F or CV_64F. + */ + void init( int dp, int mp, int cp, double processNoiseCovDiag, double measurementNoiseCovDiag, + Ptr<UkfSystemModel> dynamicalSystem, int type = CV_64F ); +}; + +/** @brief Unscented Kalman Filter factory method + +* The class implements an Unscented Kalman filter <https://en.wikipedia.org/wiki/Kalman_filter#Unscented_Kalman_filter>. +* @param params - an object of the UnscentedKalmanFilterParams class containing UKF parameters. +* @return pointer to the object of the UnscentedKalmanFilterImpl class implementing UnscentedKalmanFilter. +*/ +CV_EXPORTS Ptr<UnscentedKalmanFilter> createUnscentedKalmanFilter( const UnscentedKalmanFilterParams ¶ms ); +/** @brief Augmented Unscented Kalman Filter factory method + +* The class implements an Augmented Unscented Kalman filter http://becs.aalto.fi/en/research/bayes/ekfukf/documentation.pdf, page 31-33. +* AUKF is more accurate than UKF but its computational complexity is larger. +* @param params - an object of the AugmentedUnscentedKalmanFilterParams class containing AUKF parameters. +* @return pointer to the object of the AugmentedUnscentedKalmanFilterImpl class implementing UnscentedKalmanFilter. +*/ +CV_EXPORTS Ptr<UnscentedKalmanFilter> createAugmentedUnscentedKalmanFilter( const AugmentedUnscentedKalmanFilterParams ¶ms ); + +} // tracking +} // cv + +#endif diff --git a/include/opencv2/tracking/onlineBoosting.hpp b/include/opencv2/tracking/onlineBoosting.hpp new file mode 100644 index 0000000..982bc20 --- /dev/null +++ b/include/opencv2/tracking/onlineBoosting.hpp @@ -0,0 +1,288 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_ONLINEBOOSTING_HPP__ +#define __OPENCV_ONLINEBOOSTING_HPP__ + +#include "opencv2/core.hpp" + +namespace cv +{ + +//! @addtogroup tracking +//! @{ + +//TODO based on the original implementation +//http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml + +class BaseClassifier; +class WeakClassifierHaarFeature; +class EstimatedGaussDistribution; +class ClassifierThreshold; +class Detector; + +class StrongClassifierDirectSelection +{ + public: + + StrongClassifierDirectSelection( int numBaseClf, int numWeakClf, Size patchSz, const Rect& sampleROI, bool useFeatureEx = false, int iterationInit = + 0 ); + virtual ~StrongClassifierDirectSelection(); + + void initBaseClassifier(); + + bool update( const Mat& image, int target, float importance = 1.0 ); + float eval( const Mat& response ); + std::vector<int> getSelectedWeakClassifier(); + float classifySmooth( const std::vector<Mat>& images, const Rect& sampleROI, int& idx ); + int getNumBaseClassifier(); + Size getPatchSize() const; + Rect getROI() const; + bool getUseFeatureExchange() const; + int getReplacedClassifier() const; + + void replaceWeakClassifier( int idx ); + int getSwappedClassifier() const; + private: + + //StrongClassifier + int numBaseClassifier; + int numAllWeakClassifier; + int numWeakClassifier; + int iterInit; + BaseClassifier** baseClassifier; + std::vector<float> alpha; + cv::Size patchSize; + + bool useFeatureExchange; + + //StrongClassifierDirectSelection + std::vector<bool> m_errorMask; + std::vector<float> m_errors; + std::vector<float> m_sumErrors; + + Detector* detector; + Rect ROI; + + int replacedClassifier; + int swappedClassifier; +}; + +class BaseClassifier +{ + public: + + BaseClassifier( int numWeakClassifier, int iterationInit ); + BaseClassifier( int numWeakClassifier, int iterationInit, WeakClassifierHaarFeature** weakCls ); + + WeakClassifierHaarFeature** getReferenceWeakClassifier() + { + return weakClassifier; + } + ; + void trainClassifier( const Mat& image, int target, float importance, std::vector<bool>& errorMask ); + int selectBestClassifier( std::vector<bool>& errorMask, float importance, std::vector<float> & errors ); + int computeReplaceWeakestClassifier( const std::vector<float> & errors ); + void replaceClassifierStatistic( int sourceIndex, int targetIndex ); + int getIdxOfNewWeakClassifier() + { + return m_idxOfNewWeakClassifier; + } + ; + int eval( const Mat& image ); + virtual ~BaseClassifier(); + float getError( int curWeakClassifier ); + void getErrors( float* errors ); + int getSelectedClassifier() const; + void replaceWeakClassifier( int index ); + + protected: + + void generateRandomClassifier(); + WeakClassifierHaarFeature** weakClassifier; + bool m_referenceWeakClassifier; + int m_numWeakClassifier; + int m_selectedClassifier; + int m_idxOfNewWeakClassifier; + std::vector<float> m_wCorrect; + std::vector<float> m_wWrong; + int m_iterationInit; + +}; + +class EstimatedGaussDistribution +{ + public: + + EstimatedGaussDistribution(); + EstimatedGaussDistribution( float P_mean, float R_mean, float P_sigma, float R_sigma ); + virtual ~EstimatedGaussDistribution(); + void update( float value ); //, float timeConstant = -1.0); + float getMean(); + float getSigma(); + void setValues( float mean, float sigma ); + + private: + + float m_mean; + float m_sigma; + float m_P_mean; + float m_P_sigma; + float m_R_mean; + float m_R_sigma; +}; + +class WeakClassifierHaarFeature +{ + + public: + + WeakClassifierHaarFeature(); + virtual ~WeakClassifierHaarFeature(); + + bool update( float value, int target ); + int eval( float value ); + + private: + + float sigma; + float mean; + ClassifierThreshold* m_classifier; + + void getInitialDistribution( EstimatedGaussDistribution *distribution ); + void generateRandomClassifier( EstimatedGaussDistribution* m_posSamples, EstimatedGaussDistribution* m_negSamples ); + +}; + +class Detector +{ + public: + + Detector( StrongClassifierDirectSelection* classifier ); + virtual + ~Detector( void ); + + void + classifySmooth( const std::vector<Mat>& image, float minMargin = 0 ); + + int + getNumDetections(); + float + getConfidence( int patchIdx ); + float + getConfidenceOfDetection( int detectionIdx ); + + float getConfidenceOfBestDetection() + { + return m_maxConfidence; + } + ; + int + getPatchIdxOfBestDetection(); + + int + getPatchIdxOfDetection( int detectionIdx ); + + const std::vector<int> & + getIdxDetections() const + { + return m_idxDetections; + } + ; + const std::vector<float> & + getConfidences() const + { + return m_confidences; + } + ; + + const cv::Mat & + getConfImageDisplay() const + { + return m_confImageDisplay; + } + + private: + + void + prepareConfidencesMemory( int numPatches ); + void + prepareDetectionsMemory( int numDetections ); + + StrongClassifierDirectSelection* m_classifier; + std::vector<float> m_confidences; + int m_sizeConfidences; + int m_numDetections; + std::vector<int> m_idxDetections; + int m_sizeDetections; + int m_idxBestDetection; + float m_maxConfidence; + cv::Mat_<float> m_confMatrix; + cv::Mat_<float> m_confMatrixSmooth; + cv::Mat_<unsigned char> m_confImageDisplay; +}; + +class ClassifierThreshold +{ + public: + + ClassifierThreshold( EstimatedGaussDistribution* posSamples, EstimatedGaussDistribution* negSamples ); + virtual ~ClassifierThreshold(); + + void update( float value, int target ); + int eval( float value ); + + void* getDistribution( int target ); + + private: + + EstimatedGaussDistribution* m_posSamples; + EstimatedGaussDistribution* m_negSamples; + + float m_threshold; + int m_parity; +}; + +//! @} + +} /* namespace cv */ + +#endif diff --git a/include/opencv2/tracking/onlineMIL.hpp b/include/opencv2/tracking/onlineMIL.hpp new file mode 100644 index 0000000..78e1372 --- /dev/null +++ b/include/opencv2/tracking/onlineMIL.hpp @@ -0,0 +1,118 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_ONLINEMIL_HPP__ +#define __OPENCV_ONLINEMIL_HPP__ + +#include "opencv2/core.hpp" +#include <limits> + +namespace cv +{ + +//! @addtogroup tracking +//! @{ + +//TODO based on the original implementation +//http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml + +class ClfOnlineStump; + +class CV_EXPORTS ClfMilBoost +{ + public: + struct CV_EXPORTS Params + { + Params(); + int _numSel; + int _numFeat; + float _lRate; + }; + + ClfMilBoost(); + ~ClfMilBoost(); + void init( const ClfMilBoost::Params ¶meters = ClfMilBoost::Params() ); + void update( const Mat& posx, const Mat& negx ); + std::vector<float> classify( const Mat& x, bool logR = true ); + + inline float sigmoid( float x ) + { + return 1.0f / ( 1.0f + exp( -x ) ); + } + + private: + uint _numsamples; + ClfMilBoost::Params _myParams; + std::vector<int> _selectors; + std::vector<ClfOnlineStump*> _weakclf; + uint _counter; + +}; + +class ClfOnlineStump +{ + public: + float _mu0, _mu1, _sig0, _sig1; + float _q; + int _s; + float _log_n1, _log_n0; + float _e1, _e0; + float _lRate; + + ClfOnlineStump(); + ClfOnlineStump( int ind ); + void init(); + void update( const Mat& posx, const Mat& negx, const cv::Mat_<float> & posw = cv::Mat_<float>(), const cv::Mat_<float> & negw = cv::Mat_<float>() ); + bool classify( const Mat& x, int i ); + float classifyF( const Mat& x, int i ); + std::vector<float> classifySetF( const Mat& x ); + + private: + bool _trained; + int _ind; + +}; + +//! @} + +} /* namespace cv */ + +#endif diff --git a/include/opencv2/tracking/tldDataset.hpp b/include/opencv2/tracking/tldDataset.hpp new file mode 100644 index 0000000..a874255 --- /dev/null +++ b/include/opencv2/tracking/tldDataset.hpp @@ -0,0 +1,56 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_TLD_DATASET +#define OPENCV_TLD_DATASET + +#include "opencv2/core.hpp" + +namespace cv +{ + namespace tld + { + CV_EXPORTS cv::Rect2d tld_InitDataset(int videoInd, const char* rootPath = "TLD_dataset", int datasetInd = 0); + CV_EXPORTS cv::String tld_getNextDatasetFrame(); + } +} + +#endif diff --git a/include/opencv2/tracking/tracker.hpp b/include/opencv2/tracking/tracker.hpp new file mode 100644 index 0000000..3b880d9 --- /dev/null +++ b/include/opencv2/tracking/tracker.hpp @@ -0,0 +1,1546 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifndef __OPENCV_TRACKER_HPP__ +#define __OPENCV_TRACKER_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/imgproc/types_c.h" +#include "feature.hpp" +#include "onlineMIL.hpp" +#include "onlineBoosting.hpp" + +/* + * Partially based on: + * ==================================================================================================================== + * - [AAM] S. Salti, A. Cavallaro, L. Di Stefano, Adaptive Appearance Modeling for Video Tracking: Survey and Evaluation + * - [AMVOT] X. Li, W. Hu, C. Shen, Z. Zhang, A. Dick, A. van den Hengel, A Survey of Appearance Models in Visual Object Tracking + * + * This Tracking API has been designed with PlantUML. If you modify this API please change UML files under modules/tracking/doc/uml + * + */ + +namespace cv +{ + +//! @addtogroup tracking +//! @{ + +/************************************ TrackerFeature Base Classes ************************************/ + +/** @brief Abstract base class for TrackerFeature that represents the feature. + */ +class CV_EXPORTS TrackerFeature +{ + public: + virtual ~TrackerFeature(); + + /** @brief Compute the features in the images collection + @param images The images + @param response The output response + */ + void compute( const std::vector<Mat>& images, Mat& response ); + + /** @brief Create TrackerFeature by tracker feature type + @param trackerFeatureType The TrackerFeature name + + The modes available now: + + - "HAAR" -- Haar Feature-based + + The modes that will be available soon: + + - "HOG" -- Histogram of Oriented Gradients features + - "LBP" -- Local Binary Pattern features + - "FEATURE2D" -- All types of Feature2D + */ + static Ptr<TrackerFeature> create( const String& trackerFeatureType ); + + /** @brief Identify most effective features + @param response Collection of response for the specific TrackerFeature + @param npoints Max number of features + + @note This method modifies the response parameter + */ + virtual void selection( Mat& response, int npoints ) = 0; + + /** @brief Get the name of the specific TrackerFeature + */ + String getClassName() const; + + protected: + + virtual bool computeImpl( const std::vector<Mat>& images, Mat& response ) = 0; + + String className; +}; + +/** @brief Class that manages the extraction and selection of features + +@cite AAM Feature Extraction and Feature Set Refinement (Feature Processing and Feature Selection). +See table I and section III C @cite AMVOT Appearance modelling -\> Visual representation (Table II, +section 3.1 - 3.2) + +TrackerFeatureSet is an aggregation of TrackerFeature + +@sa + TrackerFeature + + */ +class CV_EXPORTS TrackerFeatureSet +{ + public: + + TrackerFeatureSet(); + + ~TrackerFeatureSet(); + + /** @brief Extract features from the images collection + @param images The input images + */ + void extraction( const std::vector<Mat>& images ); + + /** @brief Identify most effective features for all feature types (optional) + */ + void selection(); + + /** @brief Remove outliers for all feature types (optional) + */ + void removeOutliers(); + + /** @brief Add TrackerFeature in the collection. Return true if TrackerFeature is added, false otherwise + @param trackerFeatureType The TrackerFeature name + + The modes available now: + + - "HAAR" -- Haar Feature-based + + The modes that will be available soon: + + - "HOG" -- Histogram of Oriented Gradients features + - "LBP" -- Local Binary Pattern features + - "FEATURE2D" -- All types of Feature2D + + Example TrackerFeatureSet::addTrackerFeature : : + @code + //sample usage: + + Ptr<TrackerFeature> trackerFeature = new TrackerFeatureHAAR( HAARparameters ); + featureSet->addTrackerFeature( trackerFeature ); + + //or add CSC sampler with default parameters + //featureSet->addTrackerFeature( "HAAR" ); + @endcode + @note If you use the second method, you must initialize the TrackerFeature + */ + bool addTrackerFeature( String trackerFeatureType ); + + /** @overload + @param feature The TrackerFeature class + */ + bool addTrackerFeature( Ptr<TrackerFeature>& feature ); + + /** @brief Get the TrackerFeature collection (TrackerFeature name, TrackerFeature pointer) + */ + const std::vector<std::pair<String, Ptr<TrackerFeature> > >& getTrackerFeature() const; + + /** @brief Get the responses + + @note Be sure to call extraction before getResponses Example TrackerFeatureSet::getResponses : : + */ + const std::vector<Mat>& getResponses() const; + + private: + + void clearResponses(); + bool blockAddTrackerFeature; + + std::vector<std::pair<String, Ptr<TrackerFeature> > > features; //list of features + std::vector<Mat> responses; //list of response after compute + +}; + +/************************************ TrackerSampler Base Classes ************************************/ + +/** @brief Abstract base class for TrackerSamplerAlgorithm that represents the algorithm for the specific +sampler. + */ +class CV_EXPORTS TrackerSamplerAlgorithm +{ + public: + /** + * \brief Destructor + */ + virtual ~TrackerSamplerAlgorithm(); + + /** @brief Create TrackerSamplerAlgorithm by tracker sampler type. + @param trackerSamplerType The trackerSamplerType name + + The modes available now: + + - "CSC" -- Current State Center + - "CS" -- Current State + */ + static Ptr<TrackerSamplerAlgorithm> create( const String& trackerSamplerType ); + + /** @brief Computes the regions starting from a position in an image. + + Return true if samples are computed, false otherwise + + @param image The current frame + @param boundingBox The bounding box from which regions can be calculated + + @param sample The computed samples @cite AAM Fig. 1 variable Sk + */ + bool sampling( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ); + + /** @brief Get the name of the specific TrackerSamplerAlgorithm + */ + String getClassName() const; + + protected: + String className; + + virtual bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ) = 0; +}; + +/** + * \brief Class that manages the sampler in order to select regions for the update the model of the tracker + * [AAM] Sampling e Labeling. See table I and section III B + */ + +/** @brief Class that manages the sampler in order to select regions for the update the model of the tracker + +@cite AAM Sampling e Labeling. See table I and section III B + +TrackerSampler is an aggregation of TrackerSamplerAlgorithm +@sa + TrackerSamplerAlgorithm + */ +class CV_EXPORTS TrackerSampler +{ + public: + + /** + * \brief Constructor + */ + TrackerSampler(); + + /** + * \brief Destructor + */ + ~TrackerSampler(); + + /** @brief Computes the regions starting from a position in an image + @param image The current frame + @param boundingBox The bounding box from which regions can be calculated + */ + void sampling( const Mat& image, Rect boundingBox ); + + /** @brief Return the collection of the TrackerSamplerAlgorithm + */ + const std::vector<std::pair<String, Ptr<TrackerSamplerAlgorithm> > >& getSamplers() const; + + /** @brief Return the samples from all TrackerSamplerAlgorithm, @cite AAM Fig. 1 variable Sk + */ + const std::vector<Mat>& getSamples() const; + + /** @brief Add TrackerSamplerAlgorithm in the collection. Return true if sampler is added, false otherwise + @param trackerSamplerAlgorithmType The TrackerSamplerAlgorithm name + + The modes available now: + - "CSC" -- Current State Center + - "CS" -- Current State + - "PF" -- Particle Filtering + + Example TrackerSamplerAlgorithm::addTrackerSamplerAlgorithm : : + @code + TrackerSamplerCSC::Params CSCparameters; + Ptr<TrackerSamplerAlgorithm> CSCSampler = new TrackerSamplerCSC( CSCparameters ); + + if( !sampler->addTrackerSamplerAlgorithm( CSCSampler ) ) + return false; + + //or add CSC sampler with default parameters + //sampler->addTrackerSamplerAlgorithm( "CSC" ); + @endcode + @note If you use the second method, you must initialize the TrackerSamplerAlgorithm + */ + bool addTrackerSamplerAlgorithm( String trackerSamplerAlgorithmType ); + + /** @overload + @param sampler The TrackerSamplerAlgorithm + */ + bool addTrackerSamplerAlgorithm( Ptr<TrackerSamplerAlgorithm>& sampler ); + + private: + std::vector<std::pair<String, Ptr<TrackerSamplerAlgorithm> > > samplers; + std::vector<Mat> samples; + bool blockAddTrackerSampler; + + void clearSamples(); +}; + +/************************************ TrackerModel Base Classes ************************************/ + +/** @brief Abstract base class for TrackerTargetState that represents a possible state of the target. + +See @cite AAM \f$\hat{x}^{i}_{k}\f$ all the states candidates. + +Inherits this class with your Target state, In own implementation you can add scale variation, +width, height, orientation, etc. + */ +class CV_EXPORTS TrackerTargetState +{ + public: + virtual ~TrackerTargetState() + { + } + ; + /** + * \brief Get the position + * \return The position + */ + Point2f getTargetPosition() const; + + /** + * \brief Set the position + * \param position The position + */ + void setTargetPosition( const Point2f& position ); + /** + * \brief Get the width of the target + * \return The width of the target + */ + int getTargetWidth() const; + + /** + * \brief Set the width of the target + * \param width The width of the target + */ + void setTargetWidth( int width ); + /** + * \brief Get the height of the target + * \return The height of the target + */ + int getTargetHeight() const; + + /** + * \brief Set the height of the target + * \param height The height of the target + */ + void setTargetHeight( int height ); + + protected: + Point2f targetPosition; + int targetWidth; + int targetHeight; + +}; + +/** @brief Represents the model of the target at frame \f$k\f$ (all states and scores) + +See @cite AAM The set of the pair \f$\langle \hat{x}^{i}_{k}, C^{i}_{k} \rangle\f$ +@sa TrackerTargetState + */ +typedef std::vector<std::pair<Ptr<TrackerTargetState>, float> > ConfidenceMap; + +/** @brief Represents the estimate states for all frames + +@cite AAM \f$x_{k}\f$ is the trajectory of the target up to time \f$k\f$ + +@sa TrackerTargetState + */ +typedef std::vector<Ptr<TrackerTargetState> > Trajectory; + +/** @brief Abstract base class for TrackerStateEstimator that estimates the most likely target state. + +See @cite AAM State estimator + +See @cite AMVOT Statistical modeling (Fig. 3), Table III (generative) - IV (discriminative) - V (hybrid) + */ +class CV_EXPORTS TrackerStateEstimator +{ + public: + virtual ~TrackerStateEstimator(); + + /** @brief Estimate the most likely target state, return the estimated state + @param confidenceMaps The overall appearance model as a list of :cConfidenceMap + */ + Ptr<TrackerTargetState> estimate( const std::vector<ConfidenceMap>& confidenceMaps ); + + /** @brief Update the ConfidenceMap with the scores + @param confidenceMaps The overall appearance model as a list of :cConfidenceMap + */ + void update( std::vector<ConfidenceMap>& confidenceMaps ); + + /** @brief Create TrackerStateEstimator by tracker state estimator type + @param trackeStateEstimatorType The TrackerStateEstimator name + + The modes available now: + + - "BOOSTING" -- Boosting-based discriminative appearance models. See @cite AMVOT section 4.4 + + The modes available soon: + + - "SVM" -- SVM-based discriminative appearance models. See @cite AMVOT section 4.5 + */ + static Ptr<TrackerStateEstimator> create( const String& trackeStateEstimatorType ); + + /** @brief Get the name of the specific TrackerStateEstimator + */ + String getClassName() const; + + protected: + + virtual Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ) = 0; + virtual void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ) = 0; + String className; +}; + +/** @brief Abstract class that represents the model of the target. It must be instantiated by specialized +tracker + +See @cite AAM Ak + +Inherits this with your TrackerModel + */ +class CV_EXPORTS TrackerModel +{ + public: + + /** + * \brief Constructor + */ + TrackerModel(); + + /** + * \brief Destructor + */ + virtual ~TrackerModel(); + + /** @brief Set TrackerEstimator, return true if the tracker state estimator is added, false otherwise + @param trackerStateEstimator The TrackerStateEstimator + @note You can add only one TrackerStateEstimator + */ + bool setTrackerStateEstimator( Ptr<TrackerStateEstimator> trackerStateEstimator ); + + /** @brief Estimate the most likely target location + + @cite AAM ME, Model Estimation table I + @param responses Features extracted from TrackerFeatureSet + */ + void modelEstimation( const std::vector<Mat>& responses ); + + /** @brief Update the model + + @cite AAM MU, Model Update table I + */ + void modelUpdate(); + + /** @brief Run the TrackerStateEstimator, return true if is possible to estimate a new state, false otherwise + */ + bool runStateEstimator(); + + /** @brief Set the current TrackerTargetState in the Trajectory + @param lastTargetState The current TrackerTargetState + */ + void setLastTargetState( const Ptr<TrackerTargetState>& lastTargetState ); + + /** @brief Get the last TrackerTargetState from Trajectory + */ + Ptr<TrackerTargetState> getLastTargetState() const; + + /** @brief Get the list of the ConfidenceMap + */ + const std::vector<ConfidenceMap>& getConfidenceMaps() const; + + /** @brief Get the last ConfidenceMap for the current frame + */ + const ConfidenceMap& getLastConfidenceMap() const; + + /** @brief Get the TrackerStateEstimator + */ + Ptr<TrackerStateEstimator> getTrackerStateEstimator() const; + + private: + + void clearCurrentConfidenceMap(); + + protected: + std::vector<ConfidenceMap> confidenceMaps; + Ptr<TrackerStateEstimator> stateEstimator; + ConfidenceMap currentConfidenceMap; + Trajectory trajectory; + int maxCMLength; + + virtual void modelEstimationImpl( const std::vector<Mat>& responses ) = 0; + virtual void modelUpdateImpl() = 0; + +}; + +/************************************ Tracker Base Class ************************************/ + +/** @brief Base abstract class for the long-term tracker: + */ +class CV_EXPORTS_W Tracker : public virtual Algorithm +{ + public: + + virtual ~Tracker() CV_OVERRIDE; + + /** @brief Initialize the tracker with a known bounding box that surrounded the target + @param image The initial frame + @param boundingBox The initial bounding box + + @return True if initialization went succesfully, false otherwise + */ + CV_WRAP bool init( InputArray image, const Rect2d& boundingBox ); + + /** @brief Update the tracker, find the new most likely bounding box for the target + @param image The current frame + @param boundingBox The bounding box that represent the new target location, if true was returned, not + modified otherwise + + @return True means that target was located and false means that tracker cannot locate target in + current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed + missing from the frame (say, out of sight) + */ + CV_WRAP bool update( InputArray image, CV_OUT Rect2d& boundingBox ); + + virtual void read( const FileNode& fn ) CV_OVERRIDE = 0; + virtual void write( FileStorage& fs ) const CV_OVERRIDE = 0; + + protected: + + virtual bool initImpl( const Mat& image, const Rect2d& boundingBox ) = 0; + virtual bool updateImpl( const Mat& image, Rect2d& boundingBox ) = 0; + + bool isInit; + + Ptr<TrackerFeatureSet> featureSet; + Ptr<TrackerSampler> sampler; + Ptr<TrackerModel> model; +}; + + +/************************************ Specific TrackerStateEstimator Classes ************************************/ + +/** @brief TrackerStateEstimator based on Boosting + */ +class CV_EXPORTS TrackerStateEstimatorMILBoosting : public TrackerStateEstimator +{ + public: + + /** + * Implementation of the target state for TrackerStateEstimatorMILBoosting + */ + class TrackerMILTargetState : public TrackerTargetState + { + + public: + /** + * \brief Constructor + * \param position Top left corner of the bounding box + * \param width Width of the bounding box + * \param height Height of the bounding box + * \param foreground label for target or background + * \param features features extracted + */ + TrackerMILTargetState( const Point2f& position, int width, int height, bool foreground, const Mat& features ); + + /** + * \brief Destructor + */ + ~TrackerMILTargetState() + { + } + ; + + /** @brief Set label: true for target foreground, false for background + @param foreground Label for background/foreground + */ + void setTargetFg( bool foreground ); + /** @brief Set the features extracted from TrackerFeatureSet + @param features The features extracted + */ + void setFeatures( const Mat& features ); + /** @brief Get the label. Return true for target foreground, false for background + */ + bool isTargetFg() const; + /** @brief Get the features extracted + */ + Mat getFeatures() const; + + private: + bool isTarget; + Mat targetFeatures; + }; + + /** @brief Constructor + @param nFeatures Number of features for each sample + */ + TrackerStateEstimatorMILBoosting( int nFeatures = 250 ); + ~TrackerStateEstimatorMILBoosting(); + + /** @brief Set the current confidenceMap + @param confidenceMap The current :cConfidenceMap + */ + void setCurrentConfidenceMap( ConfidenceMap& confidenceMap ); + + protected: + Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ) CV_OVERRIDE; + void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ) CV_OVERRIDE; + + private: + uint max_idx( const std::vector<float> &v ); + void prepareData( const ConfidenceMap& confidenceMap, Mat& positive, Mat& negative ); + + ClfMilBoost boostMILModel; + bool trained; + int numFeatures; + + ConfidenceMap currentConfidenceMap; +}; + +/** @brief TrackerStateEstimatorAdaBoosting based on ADA-Boosting + */ +class CV_EXPORTS TrackerStateEstimatorAdaBoosting : public TrackerStateEstimator +{ + public: + /** @brief Implementation of the target state for TrackerAdaBoostingTargetState + */ + class TrackerAdaBoostingTargetState : public TrackerTargetState + { + + public: + /** + * \brief Constructor + * \param position Top left corner of the bounding box + * \param width Width of the bounding box + * \param height Height of the bounding box + * \param foreground label for target or background + * \param responses list of features + */ + TrackerAdaBoostingTargetState( const Point2f& position, int width, int height, bool foreground, const Mat& responses ); + + /** + * \brief Destructor + */ + ~TrackerAdaBoostingTargetState() + { + } + ; + + /** @brief Set the features extracted from TrackerFeatureSet + @param responses The features extracted + */ + void setTargetResponses( const Mat& responses ); + /** @brief Set label: true for target foreground, false for background + @param foreground Label for background/foreground + */ + void setTargetFg( bool foreground ); + /** @brief Get the features extracted + */ + Mat getTargetResponses() const; + /** @brief Get the label. Return true for target foreground, false for background + */ + bool isTargetFg() const; + + private: + bool isTarget; + Mat targetResponses; + + }; + + /** @brief Constructor + @param numClassifer Number of base classifiers + @param initIterations Number of iterations in the initialization + @param nFeatures Number of features/weak classifiers + @param patchSize tracking rect + @param ROI initial ROI + */ + TrackerStateEstimatorAdaBoosting( int numClassifer, int initIterations, int nFeatures, Size patchSize, const Rect& ROI ); + + /** + * \brief Destructor + */ + ~TrackerStateEstimatorAdaBoosting(); + + /** @brief Get the sampling ROI + */ + Rect getSampleROI() const; + + /** @brief Set the sampling ROI + @param ROI the sampling ROI + */ + void setSampleROI( const Rect& ROI ); + + /** @brief Set the current confidenceMap + @param confidenceMap The current :cConfidenceMap + */ + void setCurrentConfidenceMap( ConfidenceMap& confidenceMap ); + + /** @brief Get the list of the selected weak classifiers for the classification step + */ + std::vector<int> computeSelectedWeakClassifier(); + + /** @brief Get the list of the weak classifiers that should be replaced + */ + std::vector<int> computeReplacedClassifier(); + + /** @brief Get the list of the weak classifiers that replace those to be replaced + */ + std::vector<int> computeSwappedClassifier(); + + protected: + Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ) CV_OVERRIDE; + void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ) CV_OVERRIDE; + + Ptr<StrongClassifierDirectSelection> boostClassifier; + + private: + int numBaseClassifier; + int iterationInit; + int numFeatures; + bool trained; + Size initPatchSize; + Rect sampleROI; + std::vector<int> replacedClassifier; + std::vector<int> swappedClassifier; + + ConfidenceMap currentConfidenceMap; +}; + +/** + * \brief TrackerStateEstimator based on SVM + */ +class CV_EXPORTS TrackerStateEstimatorSVM : public TrackerStateEstimator +{ + public: + TrackerStateEstimatorSVM(); + ~TrackerStateEstimatorSVM(); + + protected: + Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ) CV_OVERRIDE; + void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ) CV_OVERRIDE; +}; + +/************************************ Specific TrackerSamplerAlgorithm Classes ************************************/ + +/** @brief TrackerSampler based on CSC (current state centered), used by MIL algorithm TrackerMIL + */ +class CV_EXPORTS TrackerSamplerCSC : public TrackerSamplerAlgorithm +{ + public: + enum + { + MODE_INIT_POS = 1, //!< mode for init positive samples + MODE_INIT_NEG = 2, //!< mode for init negative samples + MODE_TRACK_POS = 3, //!< mode for update positive samples + MODE_TRACK_NEG = 4, //!< mode for update negative samples + MODE_DETECT = 5 //!< mode for detect samples + }; + + struct CV_EXPORTS Params + { + Params(); + float initInRad; //!< radius for gathering positive instances during init + float trackInPosRad; //!< radius for gathering positive instances during tracking + float searchWinSize; //!< size of search window + int initMaxNegNum; //!< # negative samples to use during init + int trackMaxPosNum; //!< # positive samples to use during training + int trackMaxNegNum; //!< # negative samples to use during training + }; + + /** @brief Constructor + @param parameters TrackerSamplerCSC parameters TrackerSamplerCSC::Params + */ + TrackerSamplerCSC( const TrackerSamplerCSC::Params ¶meters = TrackerSamplerCSC::Params() ); + + /** @brief Set the sampling mode of TrackerSamplerCSC + @param samplingMode The sampling mode + + The modes are: + + - "MODE_INIT_POS = 1" -- for the positive sampling in initialization step + - "MODE_INIT_NEG = 2" -- for the negative sampling in initialization step + - "MODE_TRACK_POS = 3" -- for the positive sampling in update step + - "MODE_TRACK_NEG = 4" -- for the negative sampling in update step + - "MODE_DETECT = 5" -- for the sampling in detection step + */ + void setMode( int samplingMode ); + + ~TrackerSamplerCSC(); + + protected: + + bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ) CV_OVERRIDE; + + private: + + Params params; + int mode; + RNG rng; + + std::vector<Mat> sampleImage( const Mat& img, int x, int y, int w, int h, float inrad, float outrad = 0, int maxnum = 1000000 ); +}; + +/** @brief TrackerSampler based on CS (current state), used by algorithm TrackerBoosting + */ +class CV_EXPORTS TrackerSamplerCS : public TrackerSamplerAlgorithm +{ + public: + enum + { + MODE_POSITIVE = 1, //!< mode for positive samples + MODE_NEGATIVE = 2, //!< mode for negative samples + MODE_CLASSIFY = 3 //!< mode for classify samples + }; + + struct CV_EXPORTS Params + { + Params(); + float overlap; //!<overlapping for the search windows + float searchFactor; //!<search region parameter + }; + /** @brief Constructor + @param parameters TrackerSamplerCS parameters TrackerSamplerCS::Params + */ + TrackerSamplerCS( const TrackerSamplerCS::Params ¶meters = TrackerSamplerCS::Params() ); + + /** @brief Set the sampling mode of TrackerSamplerCS + @param samplingMode The sampling mode + + The modes are: + + - "MODE_POSITIVE = 1" -- for the positive sampling + - "MODE_NEGATIVE = 2" -- for the negative sampling + - "MODE_CLASSIFY = 3" -- for the sampling in classification step + */ + void setMode( int samplingMode ); + + ~TrackerSamplerCS(); + + bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ) CV_OVERRIDE; + Rect getROI() const; + private: + Rect getTrackingROI( float searchFactor ); + Rect RectMultiply( const Rect & rect, float f ); + std::vector<Mat> patchesRegularScan( const Mat& image, Rect trackingROI, Size patchSize ); + void setCheckedROI( Rect imageROI ); + + Params params; + int mode; + Rect trackedPatch; + Rect validROI; + Rect ROI; + +}; + +/** @brief This sampler is based on particle filtering. + +In principle, it can be thought of as performing some sort of optimization (and indeed, this +tracker uses opencv's optim module), where tracker seeks to find the rectangle in given frame, +which is the most *"similar"* to the initial rectangle (the one, given through the constructor). + +The optimization performed is stochastic and somehow resembles genetic algorithms, where on each new +image received (submitted via TrackerSamplerPF::sampling()) we start with the region bounded by +boundingBox, then generate several "perturbed" boxes, take the ones most similar to the original. +This selection round is repeated several times. At the end, we hope that only the most promising box +remaining, and these are combined to produce the subrectangle of image, which is put as a sole +element in array sample. + +It should be noted, that the definition of "similarity" between two rectangles is based on comparing +their histograms. As experiments show, tracker is *not* very succesfull if target is assumed to +strongly change its dimensions. + */ +class CV_EXPORTS TrackerSamplerPF : public TrackerSamplerAlgorithm +{ +public: + /** @brief This structure contains all the parameters that can be varied during the course of sampling + algorithm. Below is the structure exposed, together with its members briefly explained with + reference to the above discussion on algorithm's working. + */ + struct CV_EXPORTS Params + { + Params(); + int iterationNum; //!< number of selection rounds + int particlesNum; //!< number of "perturbed" boxes on each round + double alpha; //!< with each new round we exponentially decrease the amount of "perturbing" we allow (like in simulated annealing) + //!< and this very alpha controls how fast annealing happens, ie. how fast perturbing decreases + Mat_<double> std; //!< initial values for perturbing (1-by-4 array, as each rectangle is given by 4 values -- coordinates of opposite vertices, + //!< hence we have 4 values to perturb) + }; + /** @brief Constructor + @param chosenRect Initial rectangle, that is supposed to contain target we'd like to track. + @param parameters + */ + TrackerSamplerPF(const Mat& chosenRect,const TrackerSamplerPF::Params ¶meters = TrackerSamplerPF::Params()); +protected: + bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ) CV_OVERRIDE; +private: + Params params; + Ptr<MinProblemSolver> _solver; + Ptr<MinProblemSolver::Function> _function; +}; + +/************************************ Specific TrackerFeature Classes ************************************/ + +/** + * \brief TrackerFeature based on Feature2D + */ +class CV_EXPORTS TrackerFeatureFeature2d : public TrackerFeature +{ + public: + + /** + * \brief Constructor + * \param detectorType string of FeatureDetector + * \param descriptorType string of DescriptorExtractor + */ + TrackerFeatureFeature2d( String detectorType, String descriptorType ); + + ~TrackerFeatureFeature2d() CV_OVERRIDE; + + void selection( Mat& response, int npoints ) CV_OVERRIDE; + + protected: + + bool computeImpl( const std::vector<Mat>& images, Mat& response ) CV_OVERRIDE; + + private: + + std::vector<KeyPoint> keypoints; +}; + +/** + * \brief TrackerFeature based on HOG + */ +class CV_EXPORTS TrackerFeatureHOG : public TrackerFeature +{ + public: + + TrackerFeatureHOG(); + + ~TrackerFeatureHOG() CV_OVERRIDE; + + void selection( Mat& response, int npoints ) CV_OVERRIDE; + + protected: + + bool computeImpl( const std::vector<Mat>& images, Mat& response ) CV_OVERRIDE; + +}; + +/** @brief TrackerFeature based on HAAR features, used by TrackerMIL and many others algorithms +@note HAAR features implementation is copied from apps/traincascade and modified according to MIL + */ +class CV_EXPORTS TrackerFeatureHAAR : public TrackerFeature +{ + public: + struct CV_EXPORTS Params + { + Params(); + int numFeatures; //!< # of rects + Size rectSize; //!< rect size + bool isIntegral; //!< true if input images are integral, false otherwise + }; + + /** @brief Constructor + @param parameters TrackerFeatureHAAR parameters TrackerFeatureHAAR::Params + */ + TrackerFeatureHAAR( const TrackerFeatureHAAR::Params ¶meters = TrackerFeatureHAAR::Params() ); + + ~TrackerFeatureHAAR() CV_OVERRIDE; + + /** @brief Compute the features only for the selected indices in the images collection + @param selFeatures indices of selected features + @param images The images + @param response Collection of response for the specific TrackerFeature + */ + bool extractSelected( const std::vector<int> selFeatures, const std::vector<Mat>& images, Mat& response ); + + /** @brief Identify most effective features + @param response Collection of response for the specific TrackerFeature + @param npoints Max number of features + + @note This method modifies the response parameter + */ + void selection( Mat& response, int npoints ) CV_OVERRIDE; + + /** @brief Swap the feature in position source with the feature in position target + @param source The source position + @param target The target position + */ + bool swapFeature( int source, int target ); + + /** @brief Swap the feature in position id with the feature input + @param id The position + @param feature The feature + */ + bool swapFeature( int id, CvHaarEvaluator::FeatureHaar& feature ); + + /** @brief Get the feature in position id + @param id The position + */ + CvHaarEvaluator::FeatureHaar& getFeatureAt( int id ); + + protected: + bool computeImpl( const std::vector<Mat>& images, Mat& response ) CV_OVERRIDE; + + private: + + Params params; + Ptr<CvHaarEvaluator> featureEvaluator; +}; + +/** + * \brief TrackerFeature based on LBP + */ +class CV_EXPORTS TrackerFeatureLBP : public TrackerFeature +{ + public: + + TrackerFeatureLBP(); + + ~TrackerFeatureLBP(); + + void selection( Mat& response, int npoints ) CV_OVERRIDE; + + protected: + + bool computeImpl( const std::vector<Mat>& images, Mat& response ) CV_OVERRIDE; + +}; + +/************************************ Specific Tracker Classes ************************************/ + +/** @brief The MIL algorithm trains a classifier in an online manner to separate the object from the +background. + +Multiple Instance Learning avoids the drift problem for a robust tracking. The implementation is +based on @cite MIL . + +Original code can be found here <http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml> + */ +class CV_EXPORTS_W TrackerMIL : public Tracker +{ + public: + struct CV_EXPORTS Params + { + Params(); + //parameters for sampler + float samplerInitInRadius; //!< radius for gathering positive instances during init + int samplerInitMaxNegNum; //!< # negative samples to use during init + float samplerSearchWinSize; //!< size of search window + float samplerTrackInRadius; //!< radius for gathering positive instances during tracking + int samplerTrackMaxPosNum; //!< # positive samples to use during tracking + int samplerTrackMaxNegNum; //!< # negative samples to use during tracking + int featureSetNumFeatures; //!< # features + + void read( const FileNode& fn ); + void write( FileStorage& fs ) const; + }; + + /** @brief Constructor + @param parameters MIL parameters TrackerMIL::Params + */ + static Ptr<TrackerMIL> create(const TrackerMIL::Params ¶meters); + + CV_WRAP static Ptr<TrackerMIL> create(); + + virtual ~TrackerMIL() CV_OVERRIDE {} +}; + +/** @brief the Boosting tracker + +This is a real-time object tracking based on a novel on-line version of the AdaBoost algorithm. +The classifier uses the surrounding background as negative examples in update step to avoid the +drifting problem. The implementation is based on @cite OLB . + */ +class CV_EXPORTS_W TrackerBoosting : public Tracker +{ + public: + struct CV_EXPORTS Params + { + Params(); + int numClassifiers; //!<the number of classifiers to use in a OnlineBoosting algorithm + float samplerOverlap; //!<search region parameters to use in a OnlineBoosting algorithm + float samplerSearchFactor; //!< search region parameters to use in a OnlineBoosting algorithm + int iterationInit; //!<the initial iterations + int featureSetNumFeatures; //!< # features + /** + * \brief Read parameters from a file + */ + void read( const FileNode& fn ); + + /** + * \brief Write parameters to a file + */ + void write( FileStorage& fs ) const; + }; + + /** @brief Constructor + @param parameters BOOSTING parameters TrackerBoosting::Params + */ + static Ptr<TrackerBoosting> create(const TrackerBoosting::Params ¶meters); + + CV_WRAP static Ptr<TrackerBoosting> create(); + + virtual ~TrackerBoosting() CV_OVERRIDE {} +}; + +/** @brief the Median Flow tracker + +Implementation of a paper @cite MedianFlow . + +The tracker is suitable for very smooth and predictable movements when object is visible throughout +the whole sequence. It's quite and accurate for this type of problems (in particular, it was shown +by authors to outperform MIL). During the implementation period the code at +<http://www.aonsquared.co.uk/node/5>, the courtesy of the author Arthur Amarra, was used for the +reference purpose. + */ +class CV_EXPORTS_W TrackerMedianFlow : public Tracker +{ + public: + struct CV_EXPORTS Params + { + Params(); //!<default constructor + //!<note that the default values of parameters are recommended for most of use cases + int pointsInGrid; //!<square root of number of keypoints used; increase it to trade + //!<accurateness for speed + cv::Size winSize; //!<window size parameter for Lucas-Kanade optical flow + int maxLevel; //!<maximal pyramid level number for Lucas-Kanade optical flow + TermCriteria termCriteria; //!<termination criteria for Lucas-Kanade optical flow + cv::Size winSizeNCC; //!<window size around a point for normalized cross-correlation check + double maxMedianLengthOfDisplacementDifference; //!<criterion for loosing the tracked object + + void read( const FileNode& /*fn*/ ); + void write( FileStorage& /*fs*/ ) const; + }; + + /** @brief Constructor + @param parameters Median Flow parameters TrackerMedianFlow::Params + */ + static Ptr<TrackerMedianFlow> create(const TrackerMedianFlow::Params ¶meters); + + CV_WRAP static Ptr<TrackerMedianFlow> create(); + + virtual ~TrackerMedianFlow() CV_OVERRIDE {} +}; + +/** @brief the TLD (Tracking, learning and detection) tracker + +TLD is a novel tracking framework that explicitly decomposes the long-term tracking task into +tracking, learning and detection. + +The tracker follows the object from frame to frame. The detector localizes all appearances that +have been observed so far and corrects the tracker if necessary. The learning estimates detector's +errors and updates it to avoid these errors in the future. The implementation is based on @cite TLD . + +The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking component in this +implementation, following authors. The tracker is supposed to be able to handle rapid motions, partial +occlusions, object absence etc. + */ +class CV_EXPORTS_W TrackerTLD : public Tracker +{ + public: + struct CV_EXPORTS Params + { + Params(); + void read( const FileNode& /*fn*/ ); + void write( FileStorage& /*fs*/ ) const; + }; + + /** @brief Constructor + @param parameters TLD parameters TrackerTLD::Params + */ + static Ptr<TrackerTLD> create(const TrackerTLD::Params ¶meters); + + CV_WRAP static Ptr<TrackerTLD> create(); + + virtual ~TrackerTLD() CV_OVERRIDE {} +}; + +/** @brief the KCF (Kernelized Correlation Filter) tracker + + * KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed. + * This tracking method is an implementation of @cite KCF_ECCV which is extended to KCF with color-names features (@cite KCF_CN). + * The original paper of KCF is available at <http://www.robots.ox.ac.uk/~joao/publications/henriques_tpami2015.pdf> + * as well as the matlab implementation. For more information about KCF with color-names features, please refer to + * <http://www.cvl.isy.liu.se/research/objrec/visualtracking/colvistrack/index.html>. + */ +class CV_EXPORTS_W TrackerKCF : public Tracker +{ +public: + /** + * \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names + * The modes available now: + - "GRAY" -- Use grayscale values as the feature + - "CN" -- Color-names feature + */ + enum MODE { + GRAY = (1 << 0), + CN = (1 << 1), + CUSTOM = (1 << 2) + }; + + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + + /** + * \brief Read parameters from a file + */ + void read(const FileNode& /*fn*/); + + /** + * \brief Write parameters to a file + */ + void write(FileStorage& /*fs*/) const; + + float detect_thresh; //!< detection confidence threshold + float sigma; //!< gaussian kernel bandwidth + float lambda; //!< regularization + float interp_factor; //!< linear interpolation factor for adaptation + float output_sigma_factor; //!< spatial bandwidth (proportional to target) + float pca_learning_rate; //!< compression learning rate + bool resize; //!< activate the resize feature to improve the processing speed + bool split_coeff; //!< split the training coefficients into two matrices + bool wrap_kernel; //!< wrap around the kernel values + bool compress_feature; //!< activate the pca method to compress the features + int max_patch_size; //!< threshold for the ROI size + int compressed_size; //!< feature size after compression + int desc_pca; //!< compressed descriptors of TrackerKCF::MODE + int desc_npca; //!< non-compressed descriptors of TrackerKCF::MODE + }; + + virtual void setFeatureExtractor(void(*)(const Mat, const Rect, Mat&), bool pca_func = false) = 0; + + /** @brief Constructor + @param parameters KCF parameters TrackerKCF::Params + */ + static Ptr<TrackerKCF> create(const TrackerKCF::Params ¶meters); + + CV_WRAP static Ptr<TrackerKCF> create(); + + virtual ~TrackerKCF() CV_OVERRIDE {} +}; + +/** @brief the GOTURN (Generic Object Tracking Using Regression Networks) tracker + + * GOTURN (@cite GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers, + * GOTURN is much faster due to offline training without online fine-tuning nature. + * GOTURN tracker addresses the problem of single target tracking: given a bounding box label of an object in the first frame of the video, + * we track that object through the rest of the video. NOTE: Current method of GOTURN does not handle occlusions; however, it is fairly + * robust to viewpoint changes, lighting changes, and deformations. + * Inputs of GOTURN are two RGB patches representing Target and Search patches resized to 227x227. + * Outputs of GOTURN are predicted bounding box coordinates, relative to Search patch coordinate system, in format X1,Y1,X2,Y2. + * Original paper is here: <http://davheld.github.io/GOTURN/GOTURN.pdf> + * As long as original authors implementation: <https://github.com/davheld/GOTURN#train-the-tracker> + * Implementation of training algorithm is placed in separately here due to 3d-party dependencies: + * <https://github.com/Auron-X/GOTURN_Training_Toolkit> + * GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository. +*/ +class CV_EXPORTS_W TrackerGOTURN : public Tracker +{ +public: + struct CV_EXPORTS Params + { + Params(); + void read(const FileNode& /*fn*/); + void write(FileStorage& /*fs*/) const; + }; + + /** @brief Constructor + @param parameters GOTURN parameters TrackerGOTURN::Params + */ + static Ptr<TrackerGOTURN> create(const TrackerGOTURN::Params ¶meters); + + CV_WRAP static Ptr<TrackerGOTURN> create(); + + virtual ~TrackerGOTURN() CV_OVERRIDE {} +}; + +/** @brief the MOSSE (Minimum Output Sum of Squared %Error) tracker + +The implementation is based on @cite MOSSE Visual Object Tracking using Adaptive Correlation Filters +@note this tracker works with grayscale images, if passed bgr ones, they will get converted internally. +*/ + +class CV_EXPORTS_W TrackerMOSSE : public Tracker +{ + public: + /** @brief Constructor + */ + CV_WRAP static Ptr<TrackerMOSSE> create(); + + virtual ~TrackerMOSSE() CV_OVERRIDE {} +}; + + +/************************************ MultiTracker Class ---By Laksono Kurnianggoro---) ************************************/ +/** @brief This class is used to track multiple objects using the specified tracker algorithm. + +* The %MultiTracker is naive implementation of multiple object tracking. +* It process the tracked objects independently without any optimization accross the tracked objects. +*/ +class CV_EXPORTS_W MultiTracker : public Algorithm +{ +public: + + /** + * \brief Constructor. + */ + CV_WRAP MultiTracker(); + + /** + * \brief Destructor + */ + ~MultiTracker() CV_OVERRIDE; + + /** + * \brief Add a new object to be tracked. + * + * @param newTracker tracking algorithm to be used + * @param image input image + * @param boundingBox a rectangle represents ROI of the tracked object + */ + CV_WRAP bool add(Ptr<Tracker> newTracker, InputArray image, const Rect2d& boundingBox); + + /** + * \brief Add a set of objects to be tracked. + * @param newTrackers list of tracking algorithms to be used + * @param image input image + * @param boundingBox list of the tracked objects + */ + bool add(std::vector<Ptr<Tracker> > newTrackers, InputArray image, std::vector<Rect2d> boundingBox); + + /** + * \brief Update the current tracking status. + * The result will be saved in the internal storage. + * @param image input image + */ + bool update(InputArray image); + + /** + * \brief Update the current tracking status. + * @param image input image + * @param boundingBox the tracking result, represent a list of ROIs of the tracked objects. + */ + CV_WRAP bool update(InputArray image, CV_OUT std::vector<Rect2d> & boundingBox); + + /** + * \brief Returns a reference to a storage for the tracked objects, each object corresponds to one tracker algorithm + */ + CV_WRAP const std::vector<Rect2d>& getObjects() const; + + /** + * \brief Returns a pointer to a new instance of MultiTracker + */ + CV_WRAP static Ptr<MultiTracker> create(); + +protected: + //!< storage for the tracker algorithms. + std::vector< Ptr<Tracker> > trackerList; + + //!< storage for the tracked objects, each object corresponds to one tracker algorithm. + std::vector<Rect2d> objects; +}; + +/************************************ Multi-Tracker Classes ---By Tyan Vladimir---************************************/ + +/** @brief Base abstract class for the long-term Multi Object Trackers: + +@sa Tracker, MultiTrackerTLD +*/ +class CV_EXPORTS MultiTracker_Alt +{ +public: + /** @brief Constructor for Multitracker + */ + MultiTracker_Alt() + { + targetNum = 0; + } + + /** @brief Add a new target to a tracking-list and initialize the tracker with a known bounding box that surrounded the target + @param image The initial frame + @param boundingBox The initial bounding box of target + @param tracker_algorithm Multi-tracker algorithm + + @return True if new target initialization went succesfully, false otherwise + */ + bool addTarget(InputArray image, const Rect2d& boundingBox, Ptr<Tracker> tracker_algorithm); + + /** @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets + @param image The current frame + + @return True means that all targets were located and false means that tracker couldn't locate one of the targets in + current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed + missing from the frame (say, out of sight) + */ + bool update(InputArray image); + + /** @brief Current number of targets in tracking-list + */ + int targetNum; + + /** @brief Trackers list for Multi-Object-Tracker + */ + std::vector <Ptr<Tracker> > trackers; + + /** @brief Bounding Boxes list for Multi-Object-Tracker + */ + std::vector <Rect2d> boundingBoxes; + /** @brief List of randomly generated colors for bounding boxes display + */ + std::vector<Scalar> colors; +}; + +/** @brief Multi Object %Tracker for TLD. + +TLD is a novel tracking framework that explicitly decomposes +the long-term tracking task into tracking, learning and detection. + +The tracker follows the object from frame to frame. The detector localizes all appearances that +have been observed so far and corrects the tracker if necessary. The learning estimates detector's +errors and updates it to avoid these errors in the future. The implementation is based on @cite TLD . + +The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking component in this +implementation, following authors. The tracker is supposed to be able to handle rapid motions, partial +occlusions, object absence etc. + +@sa Tracker, MultiTracker, TrackerTLD +*/ +class CV_EXPORTS MultiTrackerTLD : public MultiTracker_Alt +{ +public: + /** @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets by + optimized update method using some techniques to speedup calculations specifically for MO TLD. The only limitation + is that all target bounding boxes should have approximately same aspect ratios. Speed boost is around 20% + + @param image The current frame. + + @return True means that all targets were located and false means that tracker couldn't locate one of the targets in + current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed + missing from the frame (say, out of sight) + */ + bool update_opt(InputArray image); +}; + +/*********************************** CSRT ************************************/ +/** @brief the CSRT tracker + +The implementation is based on @cite Lukezic_IJCV2018 Discriminative Correlation Filter with Channel and Spatial Reliability +*/ +class CV_EXPORTS_W TrackerCSRT : public Tracker +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + + /** + * \brief Read parameters from a file + */ + void read(const FileNode& /*fn*/); + + /** + * \brief Write parameters to a file + */ + void write(cv::FileStorage& fs) const; + + bool use_hog; + bool use_color_names; + bool use_gray; + bool use_rgb; + bool use_channel_weights; + bool use_segmentation; + + std::string window_function; //!< Window function: "hann", "cheb", "kaiser" + float kaiser_alpha; + float cheb_attenuation; + + float template_size; + float gsl_sigma; + float hog_orientations; + float hog_clip; + float padding; + float filter_lr; + float weights_lr; + int num_hog_channels_used; + int admm_iterations; + int histogram_bins; + float histogram_lr; + int background_ratio; + int number_of_scales; + float scale_sigma_factor; + float scale_model_max_area; + float scale_lr; + float scale_step; + + float psr_threshold; //!< we lost the target, if the psr is lower than this. + }; + + /** @brief Constructor + @param parameters CSRT parameters TrackerCSRT::Params + */ + static Ptr<TrackerCSRT> create(const TrackerCSRT::Params ¶meters); + + CV_WRAP static Ptr<TrackerCSRT> create(); + + virtual void setInitialMask(const Mat mask) = 0; + + virtual ~TrackerCSRT() CV_OVERRIDE {} +}; + +//! @} +} /* namespace cv */ + +#endif diff --git a/include/opencv2/tracking/tracking.hpp b/include/opencv2/tracking/tracking.hpp new file mode 100644 index 0000000..eb098e2 --- /dev/null +++ b/include/opencv2/tracking/tracking.hpp @@ -0,0 +1,46 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // 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 + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's 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. + // + // * The name of the copyright holders may not 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 the Intel Corporation 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. + // + //M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/tracking.hpp" diff --git a/include/opencv2/video.hpp b/include/opencv2/video.hpp new file mode 100644 index 0000000..aa644a9 --- /dev/null +++ b/include/opencv2/video.hpp @@ -0,0 +1,63 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEO_HPP +#define OPENCV_VIDEO_HPP + +/** + @defgroup video Video Analysis + @{ + @defgroup video_motion Motion Analysis + @defgroup video_track Object Tracking + @defgroup video_c C API + @} +*/ + +#include "opencv2/video/tracking.hpp" +#include "opencv2/video/background_segm.hpp" + +#ifndef DISABLE_OPENCV_24_COMPATIBILITY +#include "opencv2/video/tracking_c.h" +#endif + +#endif //OPENCV_VIDEO_HPP diff --git a/include/opencv2/video/background_segm.hpp b/include/opencv2/video/background_segm.hpp new file mode 100644 index 0000000..e1dfa15 --- /dev/null +++ b/include/opencv2/video/background_segm.hpp @@ -0,0 +1,317 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_BACKGROUND_SEGM_HPP +#define OPENCV_BACKGROUND_SEGM_HPP + +#include "opencv2/core.hpp" + +namespace cv +{ + +//! @addtogroup video_motion +//! @{ + +/** @brief Base class for background/foreground segmentation. : + +The class is only used to define the common interface for the whole family of background/foreground +segmentation algorithms. + */ +class CV_EXPORTS_W BackgroundSubtractor : public Algorithm +{ +public: + /** @brief Computes a foreground mask. + + @param image Next video frame. + @param fgmask The output foreground mask as an 8-bit binary image. + @param learningRate The value between 0 and 1 that indicates how fast the background model is + learnt. Negative parameter value makes the algorithm to use some automatically chosen learning + rate. 0 means that the background model is not updated at all, 1 means that the background model + is completely reinitialized from the last frame. + */ + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) = 0; + + /** @brief Computes a background image. + + @param backgroundImage The output background image. + + @note Sometimes the background image can be very blurry, as it contain the average background + statistics. + */ + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const = 0; +}; + + +/** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm. + +The class implements the Gaussian mixture model background subtraction described in @cite Zivkovic2004 +and @cite Zivkovic2006 . + */ +class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor +{ +public: + /** @brief Returns the number of last frames that affect the background model + */ + CV_WRAP virtual int getHistory() const = 0; + /** @brief Sets the number of last frames that affect the background model + */ + CV_WRAP virtual void setHistory(int history) = 0; + + /** @brief Returns the number of gaussian components in the background model + */ + CV_WRAP virtual int getNMixtures() const = 0; + /** @brief Sets the number of gaussian components in the background model. + + The model needs to be reinitalized to reserve memory. + */ + CV_WRAP virtual void setNMixtures(int nmixtures) = 0;//needs reinitialization! + + /** @brief Returns the "background ratio" parameter of the algorithm + + If a foreground pixel keeps semi-constant value for about backgroundRatio\*history frames, it's + considered background and added to the model as a center of a new component. It corresponds to TB + parameter in the paper. + */ + CV_WRAP virtual double getBackgroundRatio() const = 0; + /** @brief Sets the "background ratio" parameter of the algorithm + */ + CV_WRAP virtual void setBackgroundRatio(double ratio) = 0; + + /** @brief Returns the variance threshold for the pixel-model match + + The main threshold on the squared Mahalanobis distance to decide if the sample is well described by + the background model or not. Related to Cthr from the paper. + */ + CV_WRAP virtual double getVarThreshold() const = 0; + /** @brief Sets the variance threshold for the pixel-model match + */ + CV_WRAP virtual void setVarThreshold(double varThreshold) = 0; + + /** @brief Returns the variance threshold for the pixel-model match used for new mixture component generation + + Threshold for the squared Mahalanobis distance that helps decide when a sample is close to the + existing components (corresponds to Tg in the paper). If a pixel is not close to any component, it + is considered foreground or added as a new component. 3 sigma =\> Tg=3\*3=9 is default. A smaller Tg + value generates more components. A higher Tg value may result in a small number of components but + they can grow too large. + */ + CV_WRAP virtual double getVarThresholdGen() const = 0; + /** @brief Sets the variance threshold for the pixel-model match used for new mixture component generation + */ + CV_WRAP virtual void setVarThresholdGen(double varThresholdGen) = 0; + + /** @brief Returns the initial variance of each gaussian component + */ + CV_WRAP virtual double getVarInit() const = 0; + /** @brief Sets the initial variance of each gaussian component + */ + CV_WRAP virtual void setVarInit(double varInit) = 0; + + CV_WRAP virtual double getVarMin() const = 0; + CV_WRAP virtual void setVarMin(double varMin) = 0; + + CV_WRAP virtual double getVarMax() const = 0; + CV_WRAP virtual void setVarMax(double varMax) = 0; + + /** @brief Returns the complexity reduction threshold + + This parameter defines the number of samples needed to accept to prove the component exists. CT=0.05 + is a default value for all the samples. By setting CT=0 you get an algorithm very similar to the + standard Stauffer&Grimson algorithm. + */ + CV_WRAP virtual double getComplexityReductionThreshold() const = 0; + /** @brief Sets the complexity reduction threshold + */ + CV_WRAP virtual void setComplexityReductionThreshold(double ct) = 0; + + /** @brief Returns the shadow detection flag + + If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorMOG2 for + details. + */ + CV_WRAP virtual bool getDetectShadows() const = 0; + /** @brief Enables or disables shadow detection + */ + CV_WRAP virtual void setDetectShadows(bool detectShadows) = 0; + + /** @brief Returns the shadow value + + Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0 + in the mask always means background, 255 means foreground. + */ + CV_WRAP virtual int getShadowValue() const = 0; + /** @brief Sets the shadow value + */ + CV_WRAP virtual void setShadowValue(int value) = 0; + + /** @brief Returns the shadow threshold + + A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in + the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel + is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara, + *Detecting Moving Shadows...*, IEEE PAMI,2003. + */ + CV_WRAP virtual double getShadowThreshold() const = 0; + /** @brief Sets the shadow threshold + */ + CV_WRAP virtual void setShadowThreshold(double threshold) = 0; + + /** @brief Computes a foreground mask. + + @param image Next video frame. Floating point frame will be used without scaling and should be in range \f$[0,255]\f$. + @param fgmask The output foreground mask as an 8-bit binary image. + @param learningRate The value between 0 and 1 that indicates how fast the background model is + learnt. Negative parameter value makes the algorithm to use some automatically chosen learning + rate. 0 means that the background model is not updated at all, 1 means that the background model + is completely reinitialized from the last frame. + */ + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; +}; + +/** @brief Creates MOG2 Background Subtractor + +@param history Length of the history. +@param varThreshold Threshold on the squared Mahalanobis distance between the pixel and the model +to decide whether a pixel is well described by the background model. This parameter does not +affect the background update. +@param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the +speed a bit, so if you do not need this feature, set the parameter to false. + */ +CV_EXPORTS_W Ptr<BackgroundSubtractorMOG2> + createBackgroundSubtractorMOG2(int history=500, double varThreshold=16, + bool detectShadows=true); + +/** @brief K-nearest neighbours - based Background/Foreground Segmentation Algorithm. + +The class implements the K-nearest neighbours background subtraction described in @cite Zivkovic2006 . +Very efficient if number of foreground pixels is low. + */ +class CV_EXPORTS_W BackgroundSubtractorKNN : public BackgroundSubtractor +{ +public: + /** @brief Returns the number of last frames that affect the background model + */ + CV_WRAP virtual int getHistory() const = 0; + /** @brief Sets the number of last frames that affect the background model + */ + CV_WRAP virtual void setHistory(int history) = 0; + + /** @brief Returns the number of data samples in the background model + */ + CV_WRAP virtual int getNSamples() const = 0; + /** @brief Sets the number of data samples in the background model. + + The model needs to be reinitalized to reserve memory. + */ + CV_WRAP virtual void setNSamples(int _nN) = 0;//needs reinitialization! + + /** @brief Returns the threshold on the squared distance between the pixel and the sample + + The threshold on the squared distance between the pixel and the sample to decide whether a pixel is + close to a data sample. + */ + CV_WRAP virtual double getDist2Threshold() const = 0; + /** @brief Sets the threshold on the squared distance + */ + CV_WRAP virtual void setDist2Threshold(double _dist2Threshold) = 0; + + /** @brief Returns the number of neighbours, the k in the kNN. + + K is the number of samples that need to be within dist2Threshold in order to decide that that + pixel is matching the kNN background model. + */ + CV_WRAP virtual int getkNNSamples() const = 0; + /** @brief Sets the k in the kNN. How many nearest neighbours need to match. + */ + CV_WRAP virtual void setkNNSamples(int _nkNN) = 0; + + /** @brief Returns the shadow detection flag + + If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorKNN for + details. + */ + CV_WRAP virtual bool getDetectShadows() const = 0; + /** @brief Enables or disables shadow detection + */ + CV_WRAP virtual void setDetectShadows(bool detectShadows) = 0; + + /** @brief Returns the shadow value + + Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0 + in the mask always means background, 255 means foreground. + */ + CV_WRAP virtual int getShadowValue() const = 0; + /** @brief Sets the shadow value + */ + CV_WRAP virtual void setShadowValue(int value) = 0; + + /** @brief Returns the shadow threshold + + A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in + the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel + is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara, + *Detecting Moving Shadows...*, IEEE PAMI,2003. + */ + CV_WRAP virtual double getShadowThreshold() const = 0; + /** @brief Sets the shadow threshold + */ + CV_WRAP virtual void setShadowThreshold(double threshold) = 0; +}; + +/** @brief Creates KNN Background Subtractor + +@param history Length of the history. +@param dist2Threshold Threshold on the squared distance between the pixel and the sample to decide +whether a pixel is close to that sample. This parameter does not affect the background update. +@param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the +speed a bit, so if you do not need this feature, set the parameter to false. + */ +CV_EXPORTS_W Ptr<BackgroundSubtractorKNN> + createBackgroundSubtractorKNN(int history=500, double dist2Threshold=400.0, + bool detectShadows=true); + +//! @} video_motion + +} // cv + +#endif diff --git a/include/opencv2/video/tracking.hpp b/include/opencv2/video/tracking.hpp new file mode 100644 index 0000000..e8566fa --- /dev/null +++ b/include/opencv2/video/tracking.hpp @@ -0,0 +1,654 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_TRACKING_HPP +#define OPENCV_TRACKING_HPP + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" + +namespace cv +{ + +//! @addtogroup video_track +//! @{ + +enum { OPTFLOW_USE_INITIAL_FLOW = 4, + OPTFLOW_LK_GET_MIN_EIGENVALS = 8, + OPTFLOW_FARNEBACK_GAUSSIAN = 256 + }; + +/** @brief Finds an object center, size, and orientation. + +@param probImage Back projection of the object histogram. See calcBackProject. +@param window Initial search window. +@param criteria Stop criteria for the underlying meanShift. +returns +(in old interfaces) Number of iterations CAMSHIFT took to converge +The function implements the CAMSHIFT object tracking algorithm @cite Bradski98 . First, it finds an +object center using meanShift and then adjusts the window size and finds the optimal rotation. The +function returns the rotated rectangle structure that includes the object position, size, and +orientation. The next position of the search window can be obtained with RotatedRect::boundingRect() + +See the OpenCV sample camshiftdemo.c that tracks colored objects. + +@note +- (Python) A sample explaining the camshift tracking algorithm can be found at + opencv_source_code/samples/python/camshift.py + */ +CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window, + TermCriteria criteria ); +/** @example samples/cpp/camshiftdemo.cpp +An example using the mean-shift tracking algorithm +*/ + +/** @brief Finds an object on a back projection image. + +@param probImage Back projection of the object histogram. See calcBackProject for details. +@param window Initial search window. +@param criteria Stop criteria for the iterative search algorithm. +returns +: Number of iterations CAMSHIFT took to converge. +The function implements the iterative object search algorithm. It takes the input back projection of +an object and the initial position. The mass center in window of the back projection image is +computed and the search window center shifts to the mass center. The procedure is repeated until the +specified number of iterations criteria.maxCount is done or until the window center shifts by less +than criteria.epsilon. The algorithm is used inside CamShift and, unlike CamShift , the search +window size or orientation do not change during the search. You can simply pass the output of +calcBackProject to this function. But better results can be obtained if you pre-filter the back +projection and remove the noise. For example, you can do this by retrieving connected components +with findContours , throwing away contours with small area ( contourArea ), and rendering the +remaining contours with drawContours. + + */ +CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); + +/** @brief Constructs the image pyramid which can be passed to calcOpticalFlowPyrLK. + +@param img 8-bit input image. +@param pyramid output pyramid. +@param winSize window size of optical flow algorithm. Must be not less than winSize argument of +calcOpticalFlowPyrLK. It is needed to calculate required padding for pyramid levels. +@param maxLevel 0-based maximal pyramid level number. +@param withDerivatives set to precompute gradients for the every pyramid level. If pyramid is +constructed without the gradients then calcOpticalFlowPyrLK will calculate them internally. +@param pyrBorder the border mode for pyramid layers. +@param derivBorder the border mode for gradients. +@param tryReuseInputImage put ROI of input image into the pyramid if possible. You can pass false +to force data copying. +@return number of levels in constructed pyramid. Can be less than maxLevel. + */ +CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays pyramid, + Size winSize, int maxLevel, bool withDerivatives = true, + int pyrBorder = BORDER_REFLECT_101, + int derivBorder = BORDER_CONSTANT, + bool tryReuseInputImage = true ); + +/** @example samples/cpp/lkdemo.cpp +An example using the Lucas-Kanade optical flow algorithm +*/ + +/** @brief Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with +pyramids. + +@param prevImg first 8-bit input image or pyramid constructed by buildOpticalFlowPyramid. +@param nextImg second input image or pyramid of the same size and the same type as prevImg. +@param prevPts vector of 2D points for which the flow needs to be found; point coordinates must be +single-precision floating-point numbers. +@param nextPts output vector of 2D points (with single-precision floating-point coordinates) +containing the calculated new positions of input features in the second image; when +OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input. +@param status output status vector (of unsigned chars); each element of the vector is set to 1 if +the flow for the corresponding features has been found, otherwise, it is set to 0. +@param err output vector of errors; each element of the vector is set to an error for the +corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't +found then the error is not defined (use the status parameter to find such cases). +@param winSize size of the search window at each pyramid level. +@param maxLevel 0-based maximal pyramid level number; if set to 0, pyramids are not used (single +level), if set to 1, two levels are used, and so on; if pyramids are passed to input then +algorithm will use as many levels as pyramids have but no more than maxLevel. +@param criteria parameter, specifying the termination criteria of the iterative search algorithm +(after the specified maximum number of iterations criteria.maxCount or when the search window +moves by less than criteria.epsilon. +@param flags operation flags: + - **OPTFLOW_USE_INITIAL_FLOW** uses initial estimations, stored in nextPts; if the flag is + not set, then prevPts is copied to nextPts and is considered the initial estimate. + - **OPTFLOW_LK_GET_MIN_EIGENVALS** use minimum eigen values as an error measure (see + minEigThreshold description); if the flag is not set, then L1 distance between patches + around the original and a moved point, divided by number of pixels in a window, is used as a + error measure. +@param minEigThreshold the algorithm calculates the minimum eigen value of a 2x2 normal matrix of +optical flow equations (this matrix is called a spatial gradient matrix in @cite Bouguet00), divided +by number of pixels in a window; if this value is less than minEigThreshold, then a corresponding +feature is filtered out and its flow is not processed, so it allows to remove bad points and get a +performance boost. + +The function implements a sparse iterative version of the Lucas-Kanade optical flow in pyramids. See +@cite Bouguet00 . The function is parallelized with the TBB library. + +@note + +- An example using the Lucas-Kanade optical flow algorithm can be found at + opencv_source_code/samples/cpp/lkdemo.cpp +- (Python) An example using the Lucas-Kanade optical flow algorithm can be found at + opencv_source_code/samples/python/lk_track.py +- (Python) An example using the Lucas-Kanade tracker for homography matching can be found at + opencv_source_code/samples/python/lk_homography.py + */ +CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg, + InputArray prevPts, InputOutputArray nextPts, + OutputArray status, OutputArray err, + Size winSize = Size(21,21), int maxLevel = 3, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), + int flags = 0, double minEigThreshold = 1e-4 ); + +/** @brief Computes a dense optical flow using the Gunnar Farneback's algorithm. + +@param prev first 8-bit single-channel input image. +@param next second input image of the same size and the same type as prev. +@param flow computed flow image that has the same size as prev and type CV_32FC2. +@param pyr_scale parameter, specifying the image scale (\<1) to build pyramids for each image; +pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous +one. +@param levels number of pyramid layers including the initial image; levels=1 means that no extra +layers are created and only the original images are used. +@param winsize averaging window size; larger values increase the algorithm robustness to image +noise and give more chances for fast motion detection, but yield more blurred motion field. +@param iterations number of iterations the algorithm does at each pyramid level. +@param poly_n size of the pixel neighborhood used to find polynomial expansion in each pixel; +larger values mean that the image will be approximated with smoother surfaces, yielding more +robust algorithm and more blurred motion field, typically poly_n =5 or 7. +@param poly_sigma standard deviation of the Gaussian that is used to smooth derivatives used as a +basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a +good value would be poly_sigma=1.5. +@param flags operation flags that can be a combination of the following: + - **OPTFLOW_USE_INITIAL_FLOW** uses the input flow as an initial flow approximation. + - **OPTFLOW_FARNEBACK_GAUSSIAN** uses the Gaussian \f$\texttt{winsize}\times\texttt{winsize}\f$ + filter instead of a box filter of the same size for optical flow estimation; usually, this + option gives z more accurate flow than with a box filter, at the cost of lower speed; + normally, winsize for a Gaussian window should be set to a larger value to achieve the same + level of robustness. + +The function finds an optical flow for each prev pixel using the @cite Farneback2003 algorithm so that + +\f[\texttt{prev} (y,x) \sim \texttt{next} ( y + \texttt{flow} (y,x)[1], x + \texttt{flow} (y,x)[0])\f] + +@note + +- An example using the optical flow algorithm described by Gunnar Farneback can be found at + opencv_source_code/samples/cpp/fback.cpp +- (Python) An example using the optical flow algorithm described by Gunnar Farneback can be + found at opencv_source_code/samples/python/opt_flow.py + */ +CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, InputOutputArray flow, + double pyr_scale, int levels, int winsize, + int iterations, int poly_n, double poly_sigma, + int flags ); + +/** @brief Computes an optimal affine transformation between two 2D point sets. + +@param src First input 2D point set stored in std::vector or Mat, or an image stored in Mat. +@param dst Second input 2D point set of the same size and the same type as A, or another image. +@param fullAffine If true, the function finds an optimal affine transformation with no additional +restrictions (6 degrees of freedom). Otherwise, the class of transformations to choose from is +limited to combinations of translation, rotation, and uniform scaling (4 degrees of freedom). + +The function finds an optimal affine transform *[A|b]* (a 2 x 3 floating-point matrix) that +approximates best the affine transformation between: + +* Two point sets +* Two raster images. In this case, the function first finds some features in the src image and + finds the corresponding features in dst image. After that, the problem is reduced to the first + case. +In case of point sets, the problem is formulated as follows: you need to find a 2x2 matrix *A* and +2x1 vector *b* so that: + +\f[[A^*|b^*] = arg \min _{[A|b]} \sum _i \| \texttt{dst}[i] - A { \texttt{src}[i]}^T - b \| ^2\f] +where src[i] and dst[i] are the i-th points in src and dst, respectively +\f$[A|b]\f$ can be either arbitrary (when fullAffine=true ) or have a form of +\f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ -a_{12} & a_{11} & b_2 \end{bmatrix}\f] +when fullAffine=false. + +@sa +estimateAffine2D, estimateAffinePartial2D, getAffineTransform, getPerspectiveTransform, findHomography + */ +CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine); +CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine, int ransacMaxIters, double ransacGoodRatio, + int ransacSize0); + + +enum +{ + MOTION_TRANSLATION = 0, + MOTION_EUCLIDEAN = 1, + MOTION_AFFINE = 2, + MOTION_HOMOGRAPHY = 3 +}; + +/** @brief Computes the Enhanced Correlation Coefficient value between two images @cite EP08 . + +@param templateImage single-channel template image; CV_8U or CV_32F array. +@param inputImage single-channel input image to be warped to provide an image similar to + templateImage, same type as templateImage. +@param inputMask An optional mask to indicate valid values of inputImage. + +@sa +findTransformECC + */ + +CV_EXPORTS_W double computeECC(InputArray templateImage, InputArray inputImage, InputArray inputMask = noArray()); + +/** @example samples/cpp/image_alignment.cpp +An example using the image alignment ECC algorithm +*/ + +/** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08 . + +@param templateImage single-channel template image; CV_8U or CV_32F array. +@param inputImage single-channel input image which should be warped with the final warpMatrix in +order to provide an image similar to templateImage, same type as templateImage. +@param warpMatrix floating-point \f$2\times 3\f$ or \f$3\times 3\f$ mapping matrix (warp). +@param motionType parameter, specifying the type of motion: + - **MOTION_TRANSLATION** sets a translational motion model; warpMatrix is \f$2\times 3\f$ with + the first \f$2\times 2\f$ part being the unity matrix and the rest two parameters being + estimated. + - **MOTION_EUCLIDEAN** sets a Euclidean (rigid) transformation as motion model; three + parameters are estimated; warpMatrix is \f$2\times 3\f$. + - **MOTION_AFFINE** sets an affine motion model (DEFAULT); six parameters are estimated; + warpMatrix is \f$2\times 3\f$. + - **MOTION_HOMOGRAPHY** sets a homography as a motion model; eight parameters are + estimated;\`warpMatrix\` is \f$3\times 3\f$. +@param criteria parameter, specifying the termination criteria of the ECC algorithm; +criteria.epsilon defines the threshold of the increment in the correlation coefficient between two +iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). +Default values are shown in the declaration above. +@param inputMask An optional mask to indicate valid values of inputImage. +@param gaussFiltSize An optional value indicating size of gaussian blur filter; (DEFAULT: 5) + +The function estimates the optimum transformation (warpMatrix) with respect to ECC criterion +(@cite EP08), that is + +\f[\texttt{warpMatrix} = \texttt{warpMatrix} = \arg\max_{W} \texttt{ECC}(\texttt{templateImage}(x,y),\texttt{inputImage}(x',y'))\f] + +where + +\f[\begin{bmatrix} x' \\ y' \end{bmatrix} = W \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\f] + +(the equation holds with homogeneous coordinates for homography). It returns the final enhanced +correlation coefficient, that is the correlation coefficient between the template image and the +final warped input image. When a \f$3\times 3\f$ matrix is given with motionType =0, 1 or 2, the third +row is ignored. + +Unlike findHomography and estimateRigidTransform, the function findTransformECC implements an +area-based alignment that builds on intensity similarities. In essence, the function updates the +initial transformation that roughly aligns the images. If this information is missing, the identity +warp (unity matrix) is used as an initialization. Note that if images undergo strong +displacements/rotations, an initial transformation that roughly aligns the images is necessary +(e.g., a simple euclidean/similarity transform that allows for the images showing the same image +content approximately). Use inverse warping in the second image to take an image close to the first +one, i.e. use the flag WARP_INVERSE_MAP with warpAffine or warpPerspective. See also the OpenCV +sample image_alignment.cpp that demonstrates the use of the function. Note that the function throws +an exception if algorithm does not converges. + +@sa +computeECC, estimateAffine2D, estimateAffinePartial2D, findHomography + */ +CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray inputImage, + InputOutputArray warpMatrix, int motionType, + TermCriteria criteria, + InputArray inputMask, int gaussFiltSize); + +/** @overload */ +CV_EXPORTS +double findTransformECC(InputArray templateImage, InputArray inputImage, + InputOutputArray warpMatrix, int motionType = MOTION_AFFINE, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), + InputArray inputMask = noArray()); + +/** @example samples/cpp/kalman.cpp +An example using the standard Kalman filter +*/ + +/** @brief Kalman filter class. + +The class implements a standard Kalman filter <http://en.wikipedia.org/wiki/Kalman_filter>, +@cite Welch95 . However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get +an extended Kalman filter functionality. +@note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released +with cvReleaseKalman(&kalmanFilter) + */ +class CV_EXPORTS_W KalmanFilter +{ +public: + CV_WRAP KalmanFilter(); + /** @overload + @param dynamParams Dimensionality of the state. + @param measureParams Dimensionality of the measurement. + @param controlParams Dimensionality of the control vector. + @param type Type of the created matrices that should be CV_32F or CV_64F. + */ + CV_WRAP KalmanFilter( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); + + /** @brief Re-initializes Kalman filter. The previous content is destroyed. + + @param dynamParams Dimensionality of the state. + @param measureParams Dimensionality of the measurement. + @param controlParams Dimensionality of the control vector. + @param type Type of the created matrices that should be CV_32F or CV_64F. + */ + void init( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); + + /** @brief Computes a predicted state. + + @param control The optional input control + */ + CV_WRAP const Mat& predict( const Mat& control = Mat() ); + + /** @brief Updates the predicted state from the measurement. + + @param measurement The measured system parameters + */ + CV_WRAP const Mat& correct( const Mat& measurement ); + + CV_PROP_RW Mat statePre; //!< predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k) + CV_PROP_RW Mat statePost; //!< corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) + CV_PROP_RW Mat transitionMatrix; //!< state transition matrix (A) + CV_PROP_RW Mat controlMatrix; //!< control matrix (B) (not used if there is no control) + CV_PROP_RW Mat measurementMatrix; //!< measurement matrix (H) + CV_PROP_RW Mat processNoiseCov; //!< process noise covariance matrix (Q) + CV_PROP_RW Mat measurementNoiseCov;//!< measurement noise covariance matrix (R) + CV_PROP_RW Mat errorCovPre; //!< priori error estimate covariance matrix (P'(k)): P'(k)=A*P(k-1)*At + Q)*/ + CV_PROP_RW Mat gain; //!< Kalman gain matrix (K(k)): K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R) + CV_PROP_RW Mat errorCovPost; //!< posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k) + + // temporary matrices + Mat temp1; + Mat temp2; + Mat temp3; + Mat temp4; + Mat temp5; +}; + + +class CV_EXPORTS_W DenseOpticalFlow : public Algorithm +{ +public: + /** @brief Calculates an optical flow. + + @param I0 first 8-bit single-channel input image. + @param I1 second input image of the same size and the same type as prev. + @param flow computed flow image that has the same size as prev and type CV_32FC2. + */ + CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; + /** @brief Releases all inner buffers. + */ + CV_WRAP virtual void collectGarbage() = 0; +}; + +/** @brief Base interface for sparse optical flow algorithms. + */ +class CV_EXPORTS_W SparseOpticalFlow : public Algorithm +{ +public: + /** @brief Calculates a sparse optical flow. + + @param prevImg First input image. + @param nextImg Second input image of the same size and the same type as prevImg. + @param prevPts Vector of 2D points for which the flow needs to be found. + @param nextPts Output vector of 2D points containing the calculated new positions of input features in the second image. + @param status Output status vector. Each element of the vector is set to 1 if the + flow for the corresponding features has been found. Otherwise, it is set to 0. + @param err Optional output vector that contains error response for each point (inverse confidence). + */ + CV_WRAP virtual void calc(InputArray prevImg, InputArray nextImg, + InputArray prevPts, InputOutputArray nextPts, + OutputArray status, + OutputArray err = cv::noArray()) = 0; +}; + +/** @brief "Dual TV L1" Optical Flow Algorithm. + +The class implements the "Dual TV L1" optical flow algorithm described in @cite Zach2007 and +@cite Javier2012 . +Here are important members of the class that control the algorithm, which you can set after +constructing the class instance: + +- member double tau + Time step of the numerical scheme. + +- member double lambda + Weight parameter for the data term, attachment parameter. This is the most relevant + parameter, which determines the smoothness of the output. The smaller this parameter is, + the smoother the solutions we obtain. It depends on the range of motions of the images, so + its value should be adapted to each image sequence. + +- member double theta + Weight parameter for (u - v)\^2, tightness parameter. It serves as a link between the + attachment and the regularization terms. In theory, it should have a small value in order + to maintain both parts in correspondence. The method is stable for a large range of values + of this parameter. + +- member int nscales + Number of scales used to create the pyramid of images. + +- member int warps + Number of warpings per scale. Represents the number of times that I1(x+u0) and grad( + I1(x+u0) ) are computed per scale. This is a parameter that assures the stability of the + method. It also affects the running time, so it is a compromise between speed and + accuracy. + +- member double epsilon + Stopping criterion threshold used in the numerical scheme, which is a trade-off between + precision and running time. A small value will yield more accurate solutions at the + expense of a slower convergence. + +- member int iterations + Stopping criterion iterations number used in the numerical scheme. + +C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". +Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". +*/ +class CV_EXPORTS_W DualTVL1OpticalFlow : public DenseOpticalFlow +{ +public: + //! @brief Time step of the numerical scheme + /** @see setTau */ + CV_WRAP virtual double getTau() const = 0; + /** @copybrief getTau @see getTau */ + CV_WRAP virtual void setTau(double val) = 0; + //! @brief Weight parameter for the data term, attachment parameter + /** @see setLambda */ + CV_WRAP virtual double getLambda() const = 0; + /** @copybrief getLambda @see getLambda */ + CV_WRAP virtual void setLambda(double val) = 0; + //! @brief Weight parameter for (u - v)^2, tightness parameter + /** @see setTheta */ + CV_WRAP virtual double getTheta() const = 0; + /** @copybrief getTheta @see getTheta */ + CV_WRAP virtual void setTheta(double val) = 0; + //! @brief coefficient for additional illumination variation term + /** @see setGamma */ + CV_WRAP virtual double getGamma() const = 0; + /** @copybrief getGamma @see getGamma */ + CV_WRAP virtual void setGamma(double val) = 0; + //! @brief Number of scales used to create the pyramid of images + /** @see setScalesNumber */ + CV_WRAP virtual int getScalesNumber() const = 0; + /** @copybrief getScalesNumber @see getScalesNumber */ + CV_WRAP virtual void setScalesNumber(int val) = 0; + //! @brief Number of warpings per scale + /** @see setWarpingsNumber */ + CV_WRAP virtual int getWarpingsNumber() const = 0; + /** @copybrief getWarpingsNumber @see getWarpingsNumber */ + CV_WRAP virtual void setWarpingsNumber(int val) = 0; + //! @brief Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time + /** @see setEpsilon */ + CV_WRAP virtual double getEpsilon() const = 0; + /** @copybrief getEpsilon @see getEpsilon */ + CV_WRAP virtual void setEpsilon(double val) = 0; + //! @brief Inner iterations (between outlier filtering) used in the numerical scheme + /** @see setInnerIterations */ + CV_WRAP virtual int getInnerIterations() const = 0; + /** @copybrief getInnerIterations @see getInnerIterations */ + CV_WRAP virtual void setInnerIterations(int val) = 0; + //! @brief Outer iterations (number of inner loops) used in the numerical scheme + /** @see setOuterIterations */ + CV_WRAP virtual int getOuterIterations() const = 0; + /** @copybrief getOuterIterations @see getOuterIterations */ + CV_WRAP virtual void setOuterIterations(int val) = 0; + //! @brief Use initial flow + /** @see setUseInitialFlow */ + CV_WRAP virtual bool getUseInitialFlow() const = 0; + /** @copybrief getUseInitialFlow @see getUseInitialFlow */ + CV_WRAP virtual void setUseInitialFlow(bool val) = 0; + //! @brief Step between scales (<1) + /** @see setScaleStep */ + CV_WRAP virtual double getScaleStep() const = 0; + /** @copybrief getScaleStep @see getScaleStep */ + CV_WRAP virtual void setScaleStep(double val) = 0; + //! @brief Median filter kernel size (1 = no filter) (3 or 5) + /** @see setMedianFiltering */ + CV_WRAP virtual int getMedianFiltering() const = 0; + /** @copybrief getMedianFiltering @see getMedianFiltering */ + CV_WRAP virtual void setMedianFiltering(int val) = 0; + + /** @brief Creates instance of cv::DualTVL1OpticalFlow*/ + CV_WRAP static Ptr<DualTVL1OpticalFlow> create( + double tau = 0.25, + double lambda = 0.15, + double theta = 0.3, + int nscales = 5, + int warps = 5, + double epsilon = 0.01, + int innnerIterations = 30, + int outerIterations = 10, + double scaleStep = 0.8, + double gamma = 0.0, + int medianFiltering = 5, + bool useInitialFlow = false); +}; + +/** @brief Creates instance of cv::DenseOpticalFlow +*/ +CV_EXPORTS_W Ptr<DualTVL1OpticalFlow> createOptFlow_DualTVL1(); + +/** @brief Class computing a dense optical flow using the Gunnar Farneback's algorithm. + */ +class CV_EXPORTS_W FarnebackOpticalFlow : public DenseOpticalFlow +{ +public: + CV_WRAP virtual int getNumLevels() const = 0; + CV_WRAP virtual void setNumLevels(int numLevels) = 0; + + CV_WRAP virtual double getPyrScale() const = 0; + CV_WRAP virtual void setPyrScale(double pyrScale) = 0; + + CV_WRAP virtual bool getFastPyramids() const = 0; + CV_WRAP virtual void setFastPyramids(bool fastPyramids) = 0; + + CV_WRAP virtual int getWinSize() const = 0; + CV_WRAP virtual void setWinSize(int winSize) = 0; + + CV_WRAP virtual int getNumIters() const = 0; + CV_WRAP virtual void setNumIters(int numIters) = 0; + + CV_WRAP virtual int getPolyN() const = 0; + CV_WRAP virtual void setPolyN(int polyN) = 0; + + CV_WRAP virtual double getPolySigma() const = 0; + CV_WRAP virtual void setPolySigma(double polySigma) = 0; + + CV_WRAP virtual int getFlags() const = 0; + CV_WRAP virtual void setFlags(int flags) = 0; + + CV_WRAP static Ptr<FarnebackOpticalFlow> create( + int numLevels = 5, + double pyrScale = 0.5, + bool fastPyramids = false, + int winSize = 13, + int numIters = 10, + int polyN = 5, + double polySigma = 1.1, + int flags = 0); +}; + + +/** @brief Class used for calculating a sparse optical flow. + +The class can calculate an optical flow for a sparse feature set using the +iterative Lucas-Kanade method with pyramids. + +@sa calcOpticalFlowPyrLK + +*/ +class CV_EXPORTS_W SparsePyrLKOpticalFlow : public SparseOpticalFlow +{ +public: + CV_WRAP virtual Size getWinSize() const = 0; + CV_WRAP virtual void setWinSize(Size winSize) = 0; + + CV_WRAP virtual int getMaxLevel() const = 0; + CV_WRAP virtual void setMaxLevel(int maxLevel) = 0; + + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + CV_WRAP virtual void setTermCriteria(TermCriteria& crit) = 0; + + CV_WRAP virtual int getFlags() const = 0; + CV_WRAP virtual void setFlags(int flags) = 0; + + CV_WRAP virtual double getMinEigThreshold() const = 0; + CV_WRAP virtual void setMinEigThreshold(double minEigThreshold) = 0; + + CV_WRAP static Ptr<SparsePyrLKOpticalFlow> create( + Size winSize = Size(21, 21), + int maxLevel = 3, TermCriteria crit = + TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), + int flags = 0, + double minEigThreshold = 1e-4); +}; + +//! @} video_track + +} // cv + +#endif diff --git a/include/opencv2/video/tracking_c.h b/include/opencv2/video/tracking_c.h new file mode 100644 index 0000000..3e32fbd --- /dev/null +++ b/include/opencv2/video/tracking_c.h @@ -0,0 +1,232 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_TRACKING_C_H +#define OPENCV_TRACKING_C_H + +#include "opencv2/imgproc/types_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup video_c + @{ +*/ + +/****************************************************************************************\ +* Motion Analysis * +\****************************************************************************************/ + +/************************************ optical flow ***************************************/ + +#define CV_LKFLOW_PYR_A_READY 1 +#define CV_LKFLOW_PYR_B_READY 2 +#define CV_LKFLOW_INITIAL_GUESSES 4 +#define CV_LKFLOW_GET_MIN_EIGENVALS 8 + +/* It is Lucas & Kanade method, modified to use pyramids. + Also it does several iterations to get optical flow for + every point at every pyramid level. + Calculates optical flow between two images for certain set of points (i.e. + it is a "sparse" optical flow, which is opposite to the previous 3 methods) */ +CVAPI(void) cvCalcOpticalFlowPyrLK( const CvArr* prev, const CvArr* curr, + CvArr* prev_pyr, CvArr* curr_pyr, + const CvPoint2D32f* prev_features, + CvPoint2D32f* curr_features, + int count, + CvSize win_size, + int level, + char* status, + float* track_error, + CvTermCriteria criteria, + int flags ); + + +/* Modification of a previous sparse optical flow algorithm to calculate + affine flow */ +CVAPI(void) cvCalcAffineFlowPyrLK( const CvArr* prev, const CvArr* curr, + CvArr* prev_pyr, CvArr* curr_pyr, + const CvPoint2D32f* prev_features, + CvPoint2D32f* curr_features, + float* matrices, int count, + CvSize win_size, int level, + char* status, float* track_error, + CvTermCriteria criteria, int flags ); + +/* Estimate rigid transformation between 2 images or 2 point sets */ +CVAPI(int) cvEstimateRigidTransform( const CvArr* A, const CvArr* B, + CvMat* M, int full_affine ); + +/* Estimate optical flow for each pixel using the two-frame G. Farneback algorithm */ +CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next, + CvArr* flow, double pyr_scale, int levels, + int winsize, int iterations, int poly_n, + double poly_sigma, int flags ); + +/********************************* motion templates *************************************/ + +/****************************************************************************************\ +* All the motion template functions work only with single channel images. * +* Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S * +* Motion history image must have depth IPL_DEPTH_32F, * +* Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, * +* Motion orientation image - IPL_DEPTH_32F * +* Segmentation mask - IPL_DEPTH_32F * +* All the angles are in degrees, all the times are in milliseconds * +\****************************************************************************************/ + +/* Updates motion history image given motion silhouette */ +CVAPI(void) cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi, + double timestamp, double duration ); + +/* Calculates gradient of the motion history image and fills + a mask indicating where the gradient is valid */ +CVAPI(void) cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation, + double delta1, double delta2, + int aperture_size CV_DEFAULT(3)); + +/* Calculates average motion direction within a selected motion region + (region can be selected by setting ROIs and/or by composing a valid gradient mask + with the region mask) */ +CVAPI(double) cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask, + const CvArr* mhi, double timestamp, + double duration ); + +/* Splits a motion history image into a few parts corresponding to separate independent motions + (e.g. left hand, right hand) */ +CVAPI(CvSeq*) cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask, + CvMemStorage* storage, + double timestamp, double seg_thresh ); + +/****************************************************************************************\ +* Tracking * +\****************************************************************************************/ + +/* Implements CAMSHIFT algorithm - determines object position, size and orientation + from the object histogram back project (extension of meanshift) */ +CVAPI(int) cvCamShift( const CvArr* prob_image, CvRect window, + CvTermCriteria criteria, CvConnectedComp* comp, + CvBox2D* box CV_DEFAULT(NULL) ); + +/* Implements MeanShift algorithm - determines object position + from the object histogram back project */ +CVAPI(int) cvMeanShift( const CvArr* prob_image, CvRect window, + CvTermCriteria criteria, CvConnectedComp* comp ); + +/* +standard Kalman filter (in G. Welch' and G. Bishop's notation): + + x(k)=A*x(k-1)+B*u(k)+w(k) p(w)~N(0,Q) + z(k)=H*x(k)+v(k), p(v)~N(0,R) +*/ +typedef struct CvKalman +{ + int MP; /* number of measurement vector dimensions */ + int DP; /* number of state vector dimensions */ + int CP; /* number of control vector dimensions */ + + /* backward compatibility fields */ +#if 1 + float* PosterState; /* =state_pre->data.fl */ + float* PriorState; /* =state_post->data.fl */ + float* DynamMatr; /* =transition_matrix->data.fl */ + float* MeasurementMatr; /* =measurement_matrix->data.fl */ + float* MNCovariance; /* =measurement_noise_cov->data.fl */ + float* PNCovariance; /* =process_noise_cov->data.fl */ + float* KalmGainMatr; /* =gain->data.fl */ + float* PriorErrorCovariance;/* =error_cov_pre->data.fl */ + float* PosterErrorCovariance;/* =error_cov_post->data.fl */ + float* Temp1; /* temp1->data.fl */ + float* Temp2; /* temp2->data.fl */ +#endif + + CvMat* state_pre; /* predicted state (x'(k)): + x(k)=A*x(k-1)+B*u(k) */ + CvMat* state_post; /* corrected state (x(k)): + x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */ + CvMat* transition_matrix; /* state transition matrix (A) */ + CvMat* control_matrix; /* control matrix (B) + (it is not used if there is no control)*/ + CvMat* measurement_matrix; /* measurement matrix (H) */ + CvMat* process_noise_cov; /* process noise covariance matrix (Q) */ + CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */ + CvMat* error_cov_pre; /* priori error estimate covariance matrix (P'(k)): + P'(k)=A*P(k-1)*At + Q)*/ + CvMat* gain; /* Kalman gain matrix (K(k)): + K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/ + CvMat* error_cov_post; /* posteriori error estimate covariance matrix (P(k)): + P(k)=(I-K(k)*H)*P'(k) */ + CvMat* temp1; /* temporary matrices */ + CvMat* temp2; + CvMat* temp3; + CvMat* temp4; + CvMat* temp5; +} CvKalman; + +/* Creates Kalman filter and sets A, B, Q, R and state to some initial values */ +CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params, + int control_params CV_DEFAULT(0)); + +/* Releases Kalman filter state */ +CVAPI(void) cvReleaseKalman( CvKalman** kalman); + +/* Updates Kalman filter by time (predicts future state of the system) */ +CVAPI(const CvMat*) cvKalmanPredict( CvKalman* kalman, + const CvMat* control CV_DEFAULT(NULL)); + +/* Updates Kalman filter by measurement + (corrects state of the system and internal matrices) */ +CVAPI(const CvMat*) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement ); + +#define cvKalmanUpdateByTime cvKalmanPredict +#define cvKalmanUpdateByMeasurement cvKalmanCorrect + +/** @} video_c */ + +#ifdef __cplusplus +} // extern "C" +#endif + + +#endif // OPENCV_TRACKING_C_H diff --git a/include/opencv2/video/video.hpp b/include/opencv2/video/video.hpp new file mode 100644 index 0000000..8267b85 --- /dev/null +++ b/include/opencv2/video/video.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/video.hpp" diff --git a/include/opencv2/videoio.hpp b/include/opencv2/videoio.hpp new file mode 100644 index 0000000..cc639d6 --- /dev/null +++ b/include/opencv2/videoio.hpp @@ -0,0 +1,992 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOIO_HPP +#define OPENCV_VIDEOIO_HPP + +#include "opencv2/core.hpp" + +/** + @defgroup videoio Video I/O + + @brief Read and write video or images sequence with OpenCV + + ### See also: + - @ref videoio_overview + - Tutorials: @ref tutorial_table_of_content_videoio + @{ + @defgroup videoio_flags_base Flags for video I/O + @defgroup videoio_flags_others Additional flags for video I/O API backends + @defgroup videoio_c C API for video I/O + @defgroup videoio_ios iOS glue for video I/O + @defgroup videoio_winrt WinRT glue for video I/O + @defgroup videoio_registry Query I/O API backends registry + @} +*/ + +////////////////////////////////// video io ///////////////////////////////// + +typedef struct CvCapture CvCapture; +typedef struct CvVideoWriter CvVideoWriter; + +namespace cv +{ + +//! @addtogroup videoio +//! @{ + +//! @addtogroup videoio_flags_base +//! @{ + + +/** @brief %VideoCapture API backends identifier. + +Select preferred API for a capture object. +To be used in the VideoCapture::VideoCapture() constructor or VideoCapture::open() + +@note Backends are available only if they have been built with your OpenCV binaries. +See @ref videoio_overview for more information. +*/ +enum VideoCaptureAPIs { + CAP_ANY = 0, //!< Auto detect == 0 + CAP_VFW = 200, //!< Video For Windows (platform native) + CAP_V4L = 200, //!< V4L/V4L2 capturing support via libv4l + CAP_V4L2 = CAP_V4L, //!< Same as CAP_V4L + CAP_FIREWIRE = 300, //!< IEEE 1394 drivers + CAP_FIREWARE = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_IEEE1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_DC1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_CMU1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_QT = 500, //!< QuickTime + CAP_UNICAP = 600, //!< Unicap drivers + CAP_DSHOW = 700, //!< DirectShow (via videoInput) + CAP_PVAPI = 800, //!< PvAPI, Prosilica GigE SDK + CAP_OPENNI = 900, //!< OpenNI (for Kinect) + CAP_OPENNI_ASUS = 910, //!< OpenNI (for Asus Xtion) + CAP_ANDROID = 1000, //!< Android - not used + CAP_XIAPI = 1100, //!< XIMEA Camera API + CAP_AVFOUNDATION = 1200, //!< AVFoundation framework for iOS (OS X Lion will have the same API) + CAP_GIGANETIX = 1300, //!< Smartek Giganetix GigEVisionSDK + CAP_MSMF = 1400, //!< Microsoft Media Foundation (via videoInput) + CAP_WINRT = 1410, //!< Microsoft Windows Runtime using Media Foundation + CAP_INTELPERC = 1500, //!< Intel Perceptual Computing SDK + CAP_OPENNI2 = 1600, //!< OpenNI2 (for Kinect) + CAP_OPENNI2_ASUS = 1610, //!< OpenNI2 (for Asus Xtion and Occipital Structure sensors) + CAP_GPHOTO2 = 1700, //!< gPhoto2 connection + CAP_GSTREAMER = 1800, //!< GStreamer + CAP_FFMPEG = 1900, //!< Open and record video file or stream using the FFMPEG library + CAP_IMAGES = 2000, //!< OpenCV Image Sequence (e.g. img_%02d.jpg) + CAP_ARAVIS = 2100, //!< Aravis SDK + CAP_OPENCV_MJPEG = 2200, //!< Built-in OpenCV MotionJPEG codec + CAP_INTEL_MFX = 2300, //!< Intel MediaSDK + CAP_XINE = 2400, //!< XINE engine (Linux) + }; + +/** @brief %VideoCapture generic properties identifier. + + Reading / writing properties involves many layers. Some unexpected result might happens along this chain. + Effective behaviour depends from device hardware, driver and API Backend. + @sa videoio_flags_others, VideoCapture::get(), VideoCapture::set() +*/ +enum VideoCaptureProperties { + CAP_PROP_POS_MSEC =0, //!< Current position of the video file in milliseconds. + CAP_PROP_POS_FRAMES =1, //!< 0-based index of the frame to be decoded/captured next. + CAP_PROP_POS_AVI_RATIO =2, //!< Relative position of the video file: 0=start of the film, 1=end of the film. + CAP_PROP_FRAME_WIDTH =3, //!< Width of the frames in the video stream. + CAP_PROP_FRAME_HEIGHT =4, //!< Height of the frames in the video stream. + CAP_PROP_FPS =5, //!< Frame rate. + CAP_PROP_FOURCC =6, //!< 4-character code of codec. see VideoWriter::fourcc . + CAP_PROP_FRAME_COUNT =7, //!< Number of frames in the video file. + CAP_PROP_FORMAT =8, //!< Format of the %Mat objects returned by VideoCapture::retrieve(). + CAP_PROP_MODE =9, //!< Backend-specific value indicating the current capture mode. + CAP_PROP_BRIGHTNESS =10, //!< Brightness of the image (only for those cameras that support). + CAP_PROP_CONTRAST =11, //!< Contrast of the image (only for cameras). + CAP_PROP_SATURATION =12, //!< Saturation of the image (only for cameras). + CAP_PROP_HUE =13, //!< Hue of the image (only for cameras). + CAP_PROP_GAIN =14, //!< Gain of the image (only for those cameras that support). + CAP_PROP_EXPOSURE =15, //!< Exposure (only for those cameras that support). + CAP_PROP_CONVERT_RGB =16, //!< Boolean flags indicating whether images should be converted to RGB. + CAP_PROP_WHITE_BALANCE_BLUE_U =17, //!< Currently unsupported. + CAP_PROP_RECTIFICATION =18, //!< Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently). + CAP_PROP_MONOCHROME =19, + CAP_PROP_SHARPNESS =20, + CAP_PROP_AUTO_EXPOSURE =21, //!< DC1394: exposure control done by camera, user can adjust reference level using this feature. + CAP_PROP_GAMMA =22, + CAP_PROP_TEMPERATURE =23, + CAP_PROP_TRIGGER =24, + CAP_PROP_TRIGGER_DELAY =25, + CAP_PROP_WHITE_BALANCE_RED_V =26, + CAP_PROP_ZOOM =27, + CAP_PROP_FOCUS =28, + CAP_PROP_GUID =29, + CAP_PROP_ISO_SPEED =30, + CAP_PROP_BACKLIGHT =32, + CAP_PROP_PAN =33, + CAP_PROP_TILT =34, + CAP_PROP_ROLL =35, + CAP_PROP_IRIS =36, + CAP_PROP_SETTINGS =37, //!< Pop up video/camera filter dialog (note: only supported by DSHOW backend currently. The property value is ignored) + CAP_PROP_BUFFERSIZE =38, + CAP_PROP_AUTOFOCUS =39, + CAP_PROP_SAR_NUM =40, //!< Sample aspect ratio: num/den (num) + CAP_PROP_SAR_DEN =41, //!< Sample aspect ratio: num/den (den) + CAP_PROP_BACKEND =42, //!< Current backend (enum VideoCaptureAPIs). Read-only property + CAP_PROP_CHANNEL =43, //!< Video input or Channel Number (only for those cameras that support) + CAP_PROP_AUTO_WB =44, //!< enable/ disable auto white-balance + CAP_PROP_WB_TEMPERATURE=45, //!< white-balance color temperature +#ifndef CV_DOXYGEN + CV__CAP_PROP_LATEST +#endif + }; + + +/** @brief Generic camera output modes identifier. +@note Currently, these are supported through the libv4l backend only. +*/ +enum VideoCaptureModes { + CAP_MODE_BGR = 0, //!< BGR24 (default) + CAP_MODE_RGB = 1, //!< RGB24 + CAP_MODE_GRAY = 2, //!< Y8 + CAP_MODE_YUYV = 3 //!< YUYV + }; + +/** @brief %VideoWriter generic properties identifier. + @sa VideoWriter::get(), VideoWriter::set() +*/ +enum VideoWriterProperties { + VIDEOWRITER_PROP_QUALITY = 1, //!< Current quality (0..100%) of the encoded videostream. Can be adjusted dynamically in some codecs. + VIDEOWRITER_PROP_FRAMEBYTES = 2, //!< (Read-only): Size of just encoded video frame. Note that the encoding order may be different from representation order. + VIDEOWRITER_PROP_NSTRIPES = 3 //!< Number of stripes for parallel encoding. -1 for auto detection. +}; + +//! @} videoio_flags_base + +//! @addtogroup videoio_flags_others +//! @{ + +/** @name IEEE 1394 drivers + @{ +*/ + +/** @brief Modes of the IEEE 1394 controlling registers +(can be: auto, manual, auto single push, absolute Latter allowed with any other mode) +every feature can have only one mode turned on at a time +*/ +enum { CAP_PROP_DC1394_OFF = -4, //!< turn the feature off (not controlled manually nor automatically). + CAP_PROP_DC1394_MODE_MANUAL = -3, //!< set automatically when a value of the feature is set by the user. + CAP_PROP_DC1394_MODE_AUTO = -2, + CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1, + CAP_PROP_DC1394_MAX = 31 + }; + +//! @} IEEE 1394 drivers + +/** @name OpenNI (for Kinect) + @{ +*/ + +//! OpenNI map generators +enum { CAP_OPENNI_DEPTH_GENERATOR = 1 << 31, + CAP_OPENNI_IMAGE_GENERATOR = 1 << 30, + CAP_OPENNI_IR_GENERATOR = 1 << 29, + CAP_OPENNI_GENERATORS_MASK = CAP_OPENNI_DEPTH_GENERATOR + CAP_OPENNI_IMAGE_GENERATOR + CAP_OPENNI_IR_GENERATOR + }; + +//! Properties of cameras available through OpenNI backend +enum { CAP_PROP_OPENNI_OUTPUT_MODE = 100, + CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, //!< In mm + CAP_PROP_OPENNI_BASELINE = 102, //!< In mm + CAP_PROP_OPENNI_FOCAL_LENGTH = 103, //!< In pixels + CAP_PROP_OPENNI_REGISTRATION = 104, //!< Flag that synchronizes the remapping depth map to image map + //!< by changing depth generator's view point (if the flag is "on") or + //!< sets this view point to its normal one (if the flag is "off"). + CAP_PROP_OPENNI_REGISTRATION_ON = CAP_PROP_OPENNI_REGISTRATION, + CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105, + CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106, + CAP_PROP_OPENNI_CIRCLE_BUFFER = 107, + CAP_PROP_OPENNI_MAX_TIME_DURATION = 108, + CAP_PROP_OPENNI_GENERATOR_PRESENT = 109, + CAP_PROP_OPENNI2_SYNC = 110, + CAP_PROP_OPENNI2_MIRROR = 111 + }; + +//! OpenNI shortcuts +enum { CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, + CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_OUTPUT_MODE, + CAP_OPENNI_DEPTH_GENERATOR_PRESENT = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, + CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_BASELINE, + CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_FOCAL_LENGTH, + CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_REGISTRATION, + CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, + CAP_OPENNI_IR_GENERATOR_PRESENT = CAP_OPENNI_IR_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, + }; + +//! OpenNI data given from depth generator +enum { CAP_OPENNI_DEPTH_MAP = 0, //!< Depth values in mm (CV_16UC1) + CAP_OPENNI_POINT_CLOUD_MAP = 1, //!< XYZ in meters (CV_32FC3) + CAP_OPENNI_DISPARITY_MAP = 2, //!< Disparity in pixels (CV_8UC1) + CAP_OPENNI_DISPARITY_MAP_32F = 3, //!< Disparity in pixels (CV_32FC1) + CAP_OPENNI_VALID_DEPTH_MASK = 4, //!< CV_8UC1 + + CAP_OPENNI_BGR_IMAGE = 5, //!< Data given from RGB image generator + CAP_OPENNI_GRAY_IMAGE = 6, //!< Data given from RGB image generator + + CAP_OPENNI_IR_IMAGE = 7 //!< Data given from IR image generator + }; + +//! Supported output modes of OpenNI image generator +enum { CAP_OPENNI_VGA_30HZ = 0, + CAP_OPENNI_SXGA_15HZ = 1, + CAP_OPENNI_SXGA_30HZ = 2, + CAP_OPENNI_QVGA_30HZ = 3, + CAP_OPENNI_QVGA_60HZ = 4 + }; + +//! @} OpenNI + +/** @name GStreamer + @{ +*/ + +enum { CAP_PROP_GSTREAMER_QUEUE_LENGTH = 200 //!< Default is 1 + }; + +//! @} GStreamer + +/** @name PvAPI, Prosilica GigE SDK + @{ +*/ + +//! PVAPI +enum { CAP_PROP_PVAPI_MULTICASTIP = 300, //!< IP for enable multicast master mode. 0 for disable multicast. + CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301, //!< FrameStartTriggerMode: Determines how a frame is initiated. + CAP_PROP_PVAPI_DECIMATIONHORIZONTAL = 302, //!< Horizontal sub-sampling of the image. + CAP_PROP_PVAPI_DECIMATIONVERTICAL = 303, //!< Vertical sub-sampling of the image. + CAP_PROP_PVAPI_BINNINGX = 304, //!< Horizontal binning factor. + CAP_PROP_PVAPI_BINNINGY = 305, //!< Vertical binning factor. + CAP_PROP_PVAPI_PIXELFORMAT = 306 //!< Pixel format. + }; + +//! PVAPI: FrameStartTriggerMode +enum { CAP_PVAPI_FSTRIGMODE_FREERUN = 0, //!< Freerun + CAP_PVAPI_FSTRIGMODE_SYNCIN1 = 1, //!< SyncIn1 + CAP_PVAPI_FSTRIGMODE_SYNCIN2 = 2, //!< SyncIn2 + CAP_PVAPI_FSTRIGMODE_FIXEDRATE = 3, //!< FixedRate + CAP_PVAPI_FSTRIGMODE_SOFTWARE = 4 //!< Software + }; + +//! PVAPI: DecimationHorizontal, DecimationVertical +enum { CAP_PVAPI_DECIMATION_OFF = 1, //!< Off + CAP_PVAPI_DECIMATION_2OUTOF4 = 2, //!< 2 out of 4 decimation + CAP_PVAPI_DECIMATION_2OUTOF8 = 4, //!< 2 out of 8 decimation + CAP_PVAPI_DECIMATION_2OUTOF16 = 8 //!< 2 out of 16 decimation + }; + +//! PVAPI: PixelFormat +enum { CAP_PVAPI_PIXELFORMAT_MONO8 = 1, //!< Mono8 + CAP_PVAPI_PIXELFORMAT_MONO16 = 2, //!< Mono16 + CAP_PVAPI_PIXELFORMAT_BAYER8 = 3, //!< Bayer8 + CAP_PVAPI_PIXELFORMAT_BAYER16 = 4, //!< Bayer16 + CAP_PVAPI_PIXELFORMAT_RGB24 = 5, //!< Rgb24 + CAP_PVAPI_PIXELFORMAT_BGR24 = 6, //!< Bgr24 + CAP_PVAPI_PIXELFORMAT_RGBA32 = 7, //!< Rgba32 + CAP_PVAPI_PIXELFORMAT_BGRA32 = 8, //!< Bgra32 + }; + +//! @} PvAPI + +/** @name XIMEA Camera API + @{ +*/ + +//! Properties of cameras available through XIMEA SDK backend +enum { CAP_PROP_XI_DOWNSAMPLING = 400, //!< Change image resolution by binning or skipping. + CAP_PROP_XI_DATA_FORMAT = 401, //!< Output data format. + CAP_PROP_XI_OFFSET_X = 402, //!< Horizontal offset from the origin to the area of interest (in pixels). + CAP_PROP_XI_OFFSET_Y = 403, //!< Vertical offset from the origin to the area of interest (in pixels). + CAP_PROP_XI_TRG_SOURCE = 404, //!< Defines source of trigger. + CAP_PROP_XI_TRG_SOFTWARE = 405, //!< Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE. + CAP_PROP_XI_GPI_SELECTOR = 406, //!< Selects general purpose input. + CAP_PROP_XI_GPI_MODE = 407, //!< Set general purpose input mode. + CAP_PROP_XI_GPI_LEVEL = 408, //!< Get general purpose level. + CAP_PROP_XI_GPO_SELECTOR = 409, //!< Selects general purpose output. + CAP_PROP_XI_GPO_MODE = 410, //!< Set general purpose output mode. + CAP_PROP_XI_LED_SELECTOR = 411, //!< Selects camera signalling LED. + CAP_PROP_XI_LED_MODE = 412, //!< Define camera signalling LED functionality. + CAP_PROP_XI_MANUAL_WB = 413, //!< Calculates White Balance(must be called during acquisition). + CAP_PROP_XI_AUTO_WB = 414, //!< Automatic white balance. + CAP_PROP_XI_AEAG = 415, //!< Automatic exposure/gain. + CAP_PROP_XI_EXP_PRIORITY = 416, //!< Exposure priority (0.5 - exposure 50%, gain 50%). + CAP_PROP_XI_AE_MAX_LIMIT = 417, //!< Maximum limit of exposure in AEAG procedure. + CAP_PROP_XI_AG_MAX_LIMIT = 418, //!< Maximum limit of gain in AEAG procedure. + CAP_PROP_XI_AEAG_LEVEL = 419, //!< Average intensity of output signal AEAG should achieve(in %). + CAP_PROP_XI_TIMEOUT = 420, //!< Image capture timeout in milliseconds. + CAP_PROP_XI_EXPOSURE = 421, //!< Exposure time in microseconds. + CAP_PROP_XI_EXPOSURE_BURST_COUNT = 422, //!< Sets the number of times of exposure in one frame. + CAP_PROP_XI_GAIN_SELECTOR = 423, //!< Gain selector for parameter Gain allows to select different type of gains. + CAP_PROP_XI_GAIN = 424, //!< Gain in dB. + CAP_PROP_XI_DOWNSAMPLING_TYPE = 426, //!< Change image downsampling type. + CAP_PROP_XI_BINNING_SELECTOR = 427, //!< Binning engine selector. + CAP_PROP_XI_BINNING_VERTICAL = 428, //!< Vertical Binning - number of vertical photo-sensitive cells to combine together. + CAP_PROP_XI_BINNING_HORIZONTAL = 429, //!< Horizontal Binning - number of horizontal photo-sensitive cells to combine together. + CAP_PROP_XI_BINNING_PATTERN = 430, //!< Binning pattern type. + CAP_PROP_XI_DECIMATION_SELECTOR = 431, //!< Decimation engine selector. + CAP_PROP_XI_DECIMATION_VERTICAL = 432, //!< Vertical Decimation - vertical sub-sampling of the image - reduces the vertical resolution of the image by the specified vertical decimation factor. + CAP_PROP_XI_DECIMATION_HORIZONTAL = 433, //!< Horizontal Decimation - horizontal sub-sampling of the image - reduces the horizontal resolution of the image by the specified vertical decimation factor. + CAP_PROP_XI_DECIMATION_PATTERN = 434, //!< Decimation pattern type. + CAP_PROP_XI_TEST_PATTERN_GENERATOR_SELECTOR = 587, //!< Selects which test pattern generator is controlled by the TestPattern feature. + CAP_PROP_XI_TEST_PATTERN = 588, //!< Selects which test pattern type is generated by the selected generator. + CAP_PROP_XI_IMAGE_DATA_FORMAT = 435, //!< Output data format. + CAP_PROP_XI_SHUTTER_TYPE = 436, //!< Change sensor shutter type(CMOS sensor). + CAP_PROP_XI_SENSOR_TAPS = 437, //!< Number of taps. + CAP_PROP_XI_AEAG_ROI_OFFSET_X = 439, //!< Automatic exposure/gain ROI offset X. + CAP_PROP_XI_AEAG_ROI_OFFSET_Y = 440, //!< Automatic exposure/gain ROI offset Y. + CAP_PROP_XI_AEAG_ROI_WIDTH = 441, //!< Automatic exposure/gain ROI Width. + CAP_PROP_XI_AEAG_ROI_HEIGHT = 442, //!< Automatic exposure/gain ROI Height. + CAP_PROP_XI_BPC = 445, //!< Correction of bad pixels. + CAP_PROP_XI_WB_KR = 448, //!< White balance red coefficient. + CAP_PROP_XI_WB_KG = 449, //!< White balance green coefficient. + CAP_PROP_XI_WB_KB = 450, //!< White balance blue coefficient. + CAP_PROP_XI_WIDTH = 451, //!< Width of the Image provided by the device (in pixels). + CAP_PROP_XI_HEIGHT = 452, //!< Height of the Image provided by the device (in pixels). + CAP_PROP_XI_REGION_SELECTOR = 589, //!< Selects Region in Multiple ROI which parameters are set by width, height, ... ,region mode. + CAP_PROP_XI_REGION_MODE = 595, //!< Activates/deactivates Region selected by Region Selector. + CAP_PROP_XI_LIMIT_BANDWIDTH = 459, //!< Set/get bandwidth(datarate)(in Megabits). + CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, //!< Sensor output data bit depth. + CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, //!< Device output data bit depth. + CAP_PROP_XI_IMAGE_DATA_BIT_DEPTH = 462, //!< bitdepth of data returned by function xiGetImage. + CAP_PROP_XI_OUTPUT_DATA_PACKING = 463, //!< Device output data packing (or grouping) enabled. Packing could be enabled if output_data_bit_depth > 8 and packing capability is available. + CAP_PROP_XI_OUTPUT_DATA_PACKING_TYPE = 464, //!< Data packing type. Some cameras supports only specific packing type. + CAP_PROP_XI_IS_COOLED = 465, //!< Returns 1 for cameras that support cooling. + CAP_PROP_XI_COOLING = 466, //!< Start camera cooling. + CAP_PROP_XI_TARGET_TEMP = 467, //!< Set sensor target temperature for cooling. + CAP_PROP_XI_CHIP_TEMP = 468, //!< Camera sensor temperature. + CAP_PROP_XI_HOUS_TEMP = 469, //!< Camera housing temperature. + CAP_PROP_XI_HOUS_BACK_SIDE_TEMP = 590, //!< Camera housing back side temperature. + CAP_PROP_XI_SENSOR_BOARD_TEMP = 596, //!< Camera sensor board temperature. + CAP_PROP_XI_CMS = 470, //!< Mode of color management system. + CAP_PROP_XI_APPLY_CMS = 471, //!< Enable applying of CMS profiles to xiGetImage (see XI_PRM_INPUT_CMS_PROFILE, XI_PRM_OUTPUT_CMS_PROFILE). + CAP_PROP_XI_IMAGE_IS_COLOR = 474, //!< Returns 1 for color cameras. + CAP_PROP_XI_COLOR_FILTER_ARRAY = 475, //!< Returns color filter array type of RAW data. + CAP_PROP_XI_GAMMAY = 476, //!< Luminosity gamma. + CAP_PROP_XI_GAMMAC = 477, //!< Chromaticity gamma. + CAP_PROP_XI_SHARPNESS = 478, //!< Sharpness Strength. + CAP_PROP_XI_CC_MATRIX_00 = 479, //!< Color Correction Matrix element [0][0]. + CAP_PROP_XI_CC_MATRIX_01 = 480, //!< Color Correction Matrix element [0][1]. + CAP_PROP_XI_CC_MATRIX_02 = 481, //!< Color Correction Matrix element [0][2]. + CAP_PROP_XI_CC_MATRIX_03 = 482, //!< Color Correction Matrix element [0][3]. + CAP_PROP_XI_CC_MATRIX_10 = 483, //!< Color Correction Matrix element [1][0]. + CAP_PROP_XI_CC_MATRIX_11 = 484, //!< Color Correction Matrix element [1][1]. + CAP_PROP_XI_CC_MATRIX_12 = 485, //!< Color Correction Matrix element [1][2]. + CAP_PROP_XI_CC_MATRIX_13 = 486, //!< Color Correction Matrix element [1][3]. + CAP_PROP_XI_CC_MATRIX_20 = 487, //!< Color Correction Matrix element [2][0]. + CAP_PROP_XI_CC_MATRIX_21 = 488, //!< Color Correction Matrix element [2][1]. + CAP_PROP_XI_CC_MATRIX_22 = 489, //!< Color Correction Matrix element [2][2]. + CAP_PROP_XI_CC_MATRIX_23 = 490, //!< Color Correction Matrix element [2][3]. + CAP_PROP_XI_CC_MATRIX_30 = 491, //!< Color Correction Matrix element [3][0]. + CAP_PROP_XI_CC_MATRIX_31 = 492, //!< Color Correction Matrix element [3][1]. + CAP_PROP_XI_CC_MATRIX_32 = 493, //!< Color Correction Matrix element [3][2]. + CAP_PROP_XI_CC_MATRIX_33 = 494, //!< Color Correction Matrix element [3][3]. + CAP_PROP_XI_DEFAULT_CC_MATRIX = 495, //!< Set default Color Correction Matrix. + CAP_PROP_XI_TRG_SELECTOR = 498, //!< Selects the type of trigger. + CAP_PROP_XI_ACQ_FRAME_BURST_COUNT = 499, //!< Sets number of frames acquired by burst. This burst is used only if trigger is set to FrameBurstStart. + CAP_PROP_XI_DEBOUNCE_EN = 507, //!< Enable/Disable debounce to selected GPI. + CAP_PROP_XI_DEBOUNCE_T0 = 508, //!< Debounce time (x * 10us). + CAP_PROP_XI_DEBOUNCE_T1 = 509, //!< Debounce time (x * 10us). + CAP_PROP_XI_DEBOUNCE_POL = 510, //!< Debounce polarity (pol = 1 t0 - falling edge, t1 - rising edge). + CAP_PROP_XI_LENS_MODE = 511, //!< Status of lens control interface. This shall be set to XI_ON before any Lens operations. + CAP_PROP_XI_LENS_APERTURE_VALUE = 512, //!< Current lens aperture value in stops. Examples: 2.8, 4, 5.6, 8, 11. + CAP_PROP_XI_LENS_FOCUS_MOVEMENT_VALUE = 513, //!< Lens current focus movement value to be used by XI_PRM_LENS_FOCUS_MOVE in motor steps. + CAP_PROP_XI_LENS_FOCUS_MOVE = 514, //!< Moves lens focus motor by steps set in XI_PRM_LENS_FOCUS_MOVEMENT_VALUE. + CAP_PROP_XI_LENS_FOCUS_DISTANCE = 515, //!< Lens focus distance in cm. + CAP_PROP_XI_LENS_FOCAL_LENGTH = 516, //!< Lens focal distance in mm. + CAP_PROP_XI_LENS_FEATURE_SELECTOR = 517, //!< Selects the current feature which is accessible by XI_PRM_LENS_FEATURE. + CAP_PROP_XI_LENS_FEATURE = 518, //!< Allows access to lens feature value currently selected by XI_PRM_LENS_FEATURE_SELECTOR. + CAP_PROP_XI_DEVICE_MODEL_ID = 521, //!< Returns device model id. + CAP_PROP_XI_DEVICE_SN = 522, //!< Returns device serial number. + CAP_PROP_XI_IMAGE_DATA_FORMAT_RGB32_ALPHA = 529, //!< The alpha channel of RGB32 output image format. + CAP_PROP_XI_IMAGE_PAYLOAD_SIZE = 530, //!< Buffer size in bytes sufficient for output image returned by xiGetImage. + CAP_PROP_XI_TRANSPORT_PIXEL_FORMAT = 531, //!< Current format of pixels on transport layer. + CAP_PROP_XI_SENSOR_CLOCK_FREQ_HZ = 532, //!< Sensor clock frequency in Hz. + CAP_PROP_XI_SENSOR_CLOCK_FREQ_INDEX = 533, //!< Sensor clock frequency index. Sensor with selected frequencies have possibility to set the frequency only by this index. + CAP_PROP_XI_SENSOR_OUTPUT_CHANNEL_COUNT = 534, //!< Number of output channels from sensor used for data transfer. + CAP_PROP_XI_FRAMERATE = 535, //!< Define framerate in Hz. + CAP_PROP_XI_COUNTER_SELECTOR = 536, //!< Select counter. + CAP_PROP_XI_COUNTER_VALUE = 537, //!< Counter status. + CAP_PROP_XI_ACQ_TIMING_MODE = 538, //!< Type of sensor frames timing. + CAP_PROP_XI_AVAILABLE_BANDWIDTH = 539, //!< Calculate and returns available interface bandwidth(int Megabits). + CAP_PROP_XI_BUFFER_POLICY = 540, //!< Data move policy. + CAP_PROP_XI_LUT_EN = 541, //!< Activates LUT. + CAP_PROP_XI_LUT_INDEX = 542, //!< Control the index (offset) of the coefficient to access in the LUT. + CAP_PROP_XI_LUT_VALUE = 543, //!< Value at entry LUTIndex of the LUT. + CAP_PROP_XI_TRG_DELAY = 544, //!< Specifies the delay in microseconds (us) to apply after the trigger reception before activating it. + CAP_PROP_XI_TS_RST_MODE = 545, //!< Defines how time stamp reset engine will be armed. + CAP_PROP_XI_TS_RST_SOURCE = 546, //!< Defines which source will be used for timestamp reset. Writing this parameter will trigger settings of engine (arming). + CAP_PROP_XI_IS_DEVICE_EXIST = 547, //!< Returns 1 if camera connected and works properly. + CAP_PROP_XI_ACQ_BUFFER_SIZE = 548, //!< Acquisition buffer size in buffer_size_unit. Default bytes. + CAP_PROP_XI_ACQ_BUFFER_SIZE_UNIT = 549, //!< Acquisition buffer size unit in bytes. Default 1. E.g. Value 1024 means that buffer_size is in KiBytes. + CAP_PROP_XI_ACQ_TRANSPORT_BUFFER_SIZE = 550, //!< Acquisition transport buffer size in bytes. + CAP_PROP_XI_BUFFERS_QUEUE_SIZE = 551, //!< Queue of field/frame buffers. + CAP_PROP_XI_ACQ_TRANSPORT_BUFFER_COMMIT = 552, //!< Number of buffers to commit to low level. + CAP_PROP_XI_RECENT_FRAME = 553, //!< GetImage returns most recent frame. + CAP_PROP_XI_DEVICE_RESET = 554, //!< Resets the camera to default state. + CAP_PROP_XI_COLUMN_FPN_CORRECTION = 555, //!< Correction of column FPN. + CAP_PROP_XI_ROW_FPN_CORRECTION = 591, //!< Correction of row FPN. + CAP_PROP_XI_SENSOR_MODE = 558, //!< Current sensor mode. Allows to select sensor mode by one integer. Setting of this parameter affects: image dimensions and downsampling. + CAP_PROP_XI_HDR = 559, //!< Enable High Dynamic Range feature. + CAP_PROP_XI_HDR_KNEEPOINT_COUNT = 560, //!< The number of kneepoints in the PWLR. + CAP_PROP_XI_HDR_T1 = 561, //!< Position of first kneepoint(in % of XI_PRM_EXPOSURE). + CAP_PROP_XI_HDR_T2 = 562, //!< Position of second kneepoint (in % of XI_PRM_EXPOSURE). + CAP_PROP_XI_KNEEPOINT1 = 563, //!< Value of first kneepoint (% of sensor saturation). + CAP_PROP_XI_KNEEPOINT2 = 564, //!< Value of second kneepoint (% of sensor saturation). + CAP_PROP_XI_IMAGE_BLACK_LEVEL = 565, //!< Last image black level counts. Can be used for Offline processing to recall it. + CAP_PROP_XI_HW_REVISION = 571, //!< Returns hardware revision number. + CAP_PROP_XI_DEBUG_LEVEL = 572, //!< Set debug level. + CAP_PROP_XI_AUTO_BANDWIDTH_CALCULATION = 573, //!< Automatic bandwidth calculation. + CAP_PROP_XI_FFS_FILE_ID = 594, //!< File number. + CAP_PROP_XI_FFS_FILE_SIZE = 580, //!< Size of file. + CAP_PROP_XI_FREE_FFS_SIZE = 581, //!< Size of free camera FFS. + CAP_PROP_XI_USED_FFS_SIZE = 582, //!< Size of used camera FFS. + CAP_PROP_XI_FFS_ACCESS_KEY = 583, //!< Setting of key enables file operations on some cameras. + CAP_PROP_XI_SENSOR_FEATURE_SELECTOR = 585, //!< Selects the current feature which is accessible by XI_PRM_SENSOR_FEATURE_VALUE. + CAP_PROP_XI_SENSOR_FEATURE_VALUE = 586, //!< Allows access to sensor feature value currently selected by XI_PRM_SENSOR_FEATURE_SELECTOR. + }; + +//! @} XIMEA + +/** @name AVFoundation framework for iOS + OS X Lion will have the same API + @{ +*/ + +//! Properties of cameras available through AVFOUNDATION backend +enum { CAP_PROP_IOS_DEVICE_FOCUS = 9001, + CAP_PROP_IOS_DEVICE_EXPOSURE = 9002, + CAP_PROP_IOS_DEVICE_FLASH = 9003, + CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004, + CAP_PROP_IOS_DEVICE_TORCH = 9005 + }; + +/** @name Smartek Giganetix GigEVisionSDK + @{ +*/ + +//! Properties of cameras available through Smartek Giganetix Ethernet Vision backend +/* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */ +enum { CAP_PROP_GIGA_FRAME_OFFSET_X = 10001, + CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002, + CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003, + CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004, + CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005, + CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006 + }; + +//! @} Smartek + +/** @name Intel Perceptual Computing SDK + @{ +*/ +enum { CAP_PROP_INTELPERC_PROFILE_COUNT = 11001, + CAP_PROP_INTELPERC_PROFILE_IDX = 11002, + CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003, + CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004, + CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005, + CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006, + CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007 + }; + +//! Intel Perceptual Streams +enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29, + CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28, + CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR + }; + +enum { CAP_INTELPERC_DEPTH_MAP = 0, //!< Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth. + CAP_INTELPERC_UVDEPTH_MAP = 1, //!< Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates. + CAP_INTELPERC_IR_MAP = 2, //!< Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam. + CAP_INTELPERC_IMAGE = 3 + }; + +//! @} Intel Perceptual + +/** @name gPhoto2 connection + @{ +*/ + +/** @brief gPhoto2 properties + +If `propertyId` is less than 0 then work on widget with that __additive inversed__ camera setting ID +Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE. +@see CvCaptureCAM_GPHOTO2 for more info +*/ +enum { CAP_PROP_GPHOTO2_PREVIEW = 17001, //!< Capture only preview from liveview mode. + CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, //!< Readonly, returns (const char *). + CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, //!< Trigger, only by set. Reload camera settings. + CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, //!< Reload all settings on set. + CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, //!< Collect messages with details. + CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, //!< Readonly, returns (const char *). + CAP_PROP_SPEED = 17007, //!< Exposure speed. Can be readonly, depends on camera program. + CAP_PROP_APERTURE = 17008, //!< Aperture. Can be readonly, depends on camera program. + CAP_PROP_EXPOSUREPROGRAM = 17009, //!< Camera exposure program. + CAP_PROP_VIEWFINDER = 17010 //!< Enter liveview mode. + }; + +//! @} gPhoto2 + + +/** @name Images backend + @{ +*/ + +/** @brief Images backend properties + +*/ +enum { CAP_PROP_IMAGES_BASE = 18000, + CAP_PROP_IMAGES_LAST = 19000 // excluding + }; + +//! @} Images + +//! @} videoio_flags_others + + +class IVideoCapture; + +/** @brief Class for video capturing from video files, image sequences or cameras. + +The class provides C++ API for capturing video from cameras or for reading video files and image sequences. + +Here is how the class can be used: +@include samples/cpp/videocapture_basic.cpp + +@note In @ref videoio_c "C API" the black-box structure `CvCapture` is used instead of %VideoCapture. +@note +- (C++) A basic sample on using the %VideoCapture interface can be found at + `OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp` +- (Python) A basic sample on using the %VideoCapture interface can be found at + `OPENCV_SOURCE_CODE/samples/python/video.py` +- (Python) A multi threaded video processing sample can be found at + `OPENCV_SOURCE_CODE/samples/python/video_threaded.py` +- (Python) %VideoCapture sample showcasing some features of the Video4Linux2 backend + `OPENCV_SOURCE_CODE/samples/python/video_v4l2.py` + */ +class CV_EXPORTS_W VideoCapture +{ +public: + /** @brief Default constructor + @note In @ref videoio_c "C API", when you finished working with video, release CvCapture structure with + cvReleaseCapture(), or use Ptr\<CvCapture\> that calls cvReleaseCapture() automatically in the + destructor. + */ + CV_WRAP VideoCapture(); + + /** @overload + @brief Open video file or a capturing device or a IP video stream for video capturing + + Same as VideoCapture(const String& filename, int apiPreference) but using default Capture API backends + */ + CV_WRAP VideoCapture(const String& filename); + + /** @overload + @brief Open video file or a capturing device or a IP video stream for video capturing with API Preference + + @param filename it can be: + - name of video file (eg. `video.avi`) + - or image sequence (eg. `img_%02d.jpg`, which will read samples like `img_00.jpg, img_01.jpg, img_02.jpg, ...`) + - or URL of video stream (eg. `protocol://host:port/script_name?script_params|auth`). + Note that each video stream or IP camera feed has its own URL scheme. Please refer to the + documentation of source stream to know the right URL. + @param apiPreference preferred Capture API backends to use. Can be used to enforce a specific reader + implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. + @sa The list of supported API backends cv::VideoCaptureAPIs + */ + CV_WRAP VideoCapture(const String& filename, int apiPreference); + + /** @overload + @brief Open a camera for video capturing + + @param index camera_id + domain_offset (CAP_*) id of the video capturing device to open. To open default camera using default backend just pass 0. + Use a `domain_offset` to enforce a specific reader implementation if multiple are available like cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. + e.g. to open Camera 1 using the MS Media Foundation API use `index = 1 + cv::CAP_MSMF` + + @sa The list of supported API backends cv::VideoCaptureAPIs + */ + CV_WRAP VideoCapture(int index); + + /** @overload + @brief Opens a camera for video capturing + + @param index id of the video capturing device to open. To open default camera using default backend just pass 0. + (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY) + @param apiPreference preferred Capture API backends to use. Can be used to enforce a specific reader + implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L2. + + @sa The list of supported API backends cv::VideoCaptureAPIs + */ + CV_WRAP VideoCapture(int index, int apiPreference); + + /** @brief Default destructor + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + virtual ~VideoCapture(); + + /** @brief Open video file or a capturing device or a IP video stream for video capturing + + @overload + + Parameters are same as the constructor VideoCapture(const String& filename) + @return `true` if the file has been successfully opened + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + CV_WRAP virtual bool open(const String& filename); + + /** @brief Open a camera for video capturing + + @overload + + Parameters are same as the constructor VideoCapture(int index) + @return `true` if the camera has been successfully opened. + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + CV_WRAP virtual bool open(int index); + + /** @brief Open a camera for video capturing + + @overload + + Parameters are similar as the constructor VideoCapture(int index),except it takes an additional argument apiPreference. + Definitely, is same as open(int index) where `index=cameraNum + apiPreference` + @return `true` if the camera has been successfully opened. + */ + CV_WRAP bool open(int cameraNum, int apiPreference); + + /** @brief Returns true if video capturing has been initialized already. + + If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns + true. + */ + CV_WRAP virtual bool isOpened() const; + + /** @brief Closes video file or capturing device. + + The method is automatically called by subsequent VideoCapture::open and by VideoCapture + destructor. + + The C function also deallocates memory and clears \*capture pointer. + */ + CV_WRAP virtual void release(); + + /** @brief Grabs the next frame from video file or capturing device. + + @return `true` (non-zero) in the case of success. + + The method/function grabs the next frame from video file or camera and returns true (non-zero) in + the case of success. + + The primary use of the function is in multi-camera environments, especially when the cameras do not + have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that + call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way + the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames + from different cameras will be closer in time. + + Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the + correct way of retrieving data from it is to call VideoCapture::grab() first and then call + VideoCapture::retrieve() one or more times with different values of the channel parameter. + + @ref tutorial_kinect_openni + */ + CV_WRAP virtual bool grab(); + + /** @brief Decodes and returns the grabbed video frame. + + @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty. + @param flag it could be a frame index or a driver specific flag + @return `false` if no frames has been grabbed + + The method decodes and returns the just grabbed frame. If no frames has been grabbed + (camera has been disconnected, or there are no more frames in video file), the method returns false + and the function returns an empty image (with %cv::Mat, test it with Mat::empty()). + + @sa read() + + @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video + capturing structure. It is not allowed to modify or release the image! You can copy the frame using + cvCloneImage and then do whatever you want with the copy. + */ + CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0); + + /** @brief Stream operator to read the next video frame. + @sa read() + */ + virtual VideoCapture& operator >> (CV_OUT Mat& image); + + /** @overload + @sa read() + */ + virtual VideoCapture& operator >> (CV_OUT UMat& image); + + /** @brief Grabs, decodes and returns the next video frame. + + @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty. + @return `false` if no frames has been grabbed + + The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the + most convenient method for reading video files or capturing data from decode and returns the just + grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more + frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()). + + @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video + capturing structure. It is not allowed to modify or release the image! You can copy the frame using + cvCloneImage and then do whatever you want with the copy. + */ + CV_WRAP virtual bool read(OutputArray image); + + /** @brief Sets a property in the VideoCapture. + + @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) + or one from @ref videoio_flags_others + @param value Value of the property. + @return `true` if the property is supported by backend used by the VideoCapture instance. + @note Even if it returns `true` this doesn't ensure that the property + value has been accepted by the capture device. See note in VideoCapture::get() + */ + CV_WRAP virtual bool set(int propId, double value); + + /** @brief Returns the specified VideoCapture property + + @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) + or one from @ref videoio_flags_others + @return Value for the specified property. Value 0 is returned when querying a property that is + not supported by the backend used by the VideoCapture instance. + + @note Reading / writing properties involves many layers. Some unexpected result might happens + along this chain. + @code {.txt} + `VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware` + @endcode + The returned value might be different from what really used by the device or it could be encoded + using device dependent rules (eg. steps or percentage). Effective behaviour depends from device + driver and API Backend + + */ + CV_WRAP virtual double get(int propId) const; + + /** @brief Open video file or a capturing device or a IP video stream for video capturing with API Preference + + @overload + + Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference) + @return `true` if the file has been successfully opened + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + CV_WRAP virtual bool open(const String& filename, int apiPreference); + + /** @brief Returns used backend API name + + @note Stream should be opened. + */ + CV_WRAP String getBackendName() const; + +protected: + Ptr<CvCapture> cap; + Ptr<IVideoCapture> icap; +}; + +class IVideoWriter; + +/** @example samples/cpp/tutorial_code/videoio/video-write/video-write.cpp +Check @ref tutorial_video_write "the corresponding tutorial" for more details +*/ + +/** @example samples/cpp/videowriter_basic.cpp +An example using VideoCapture and VideoWriter class +*/ + +/** @brief Video writer class. + +The class provides C++ API for writing video files or image sequences. +*/ +class CV_EXPORTS_W VideoWriter +{ +public: + /** @brief Default constructors + + The constructors/functions initialize video writers. + - On Linux FFMPEG is used to write videos; + - On Windows FFMPEG or VFW is used; + - On MacOSX QTKit is used. + */ + CV_WRAP VideoWriter(); + + /** @overload + @param filename Name of the output video file. + @param fourcc 4-character code of codec used to compress the frames. For example, + VideoWriter::fourcc('P','I','M','1') is a MPEG-1 codec, VideoWriter::fourcc('M','J','P','G') is a + motion-jpeg codec etc. List of codes can be obtained at [Video Codecs by + FOURCC](http://www.fourcc.org/codecs.php) page. FFMPEG backend with MP4 container natively uses + other values as fourcc code: see [ObjectType](http://www.mp4ra.org/codecs.html), + so you may receive a warning message from OpenCV about fourcc code conversion. + @param fps Framerate of the created video stream. + @param frameSize Size of the video frames. + @param isColor If it is not zero, the encoder will expect and encode color frames, otherwise it + will work with grayscale frames (the flag is currently supported on Windows only). + + @b Tips: + - With some backends `fourcc=-1` pops up the codec selection dialog from the system. + - To save image sequence use a proper filename (eg. `img_%02d.jpg`) and `fourcc=0` + OR `fps=0`. Use uncompressed image format (eg. `img_%02d.BMP`) to save raw frames. + - Most codecs are lossy. If you want lossless video file you need to use a lossless codecs + (eg. FFMPEG FFV1, Huffman HFYU, Lagarith LAGS, etc...) + - If FFMPEG is enabled, using `codec=0; fps=0;` you can create an uncompressed (raw) video file. + */ + CV_WRAP VideoWriter(const String& filename, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @overload + The `apiPreference` parameter allows to specify API backends to use. Can be used to enforce a specific reader implementation + if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_GSTREAMER. + */ + CV_WRAP VideoWriter(const String& filename, int apiPreference, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @brief Default destructor + + The method first calls VideoWriter::release to close the already opened file. + */ + virtual ~VideoWriter(); + + /** @brief Initializes or reinitializes video writer. + + The method opens video writer. Parameters are the same as in the constructor + VideoWriter::VideoWriter. + @return `true` if video writer has been successfully initialized + + The method first calls VideoWriter::release to close the already opened file. + */ + CV_WRAP virtual bool open(const String& filename, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @overload + */ + CV_WRAP bool open(const String& filename, int apiPreference, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @brief Returns true if video writer has been successfully initialized. + */ + CV_WRAP virtual bool isOpened() const; + + /** @brief Closes the video writer. + + The method is automatically called by subsequent VideoWriter::open and by the VideoWriter + destructor. + */ + CV_WRAP virtual void release(); + + /** @brief Stream operator to write the next video frame. + @sa write + */ + virtual VideoWriter& operator << (const Mat& image); + + /** @brief Writes the next video frame + + @param image The written frame. In general, color images are expected in BGR format. + + The function/method writes the specified image to video file. It must have the same size as has + been specified when opening the video writer. + */ + CV_WRAP virtual void write(const Mat& image); + + /** @brief Sets a property in the VideoWriter. + + @param propId Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) + or one of @ref videoio_flags_others + + @param value Value of the property. + @return `true` if the property is supported by the backend used by the VideoWriter instance. + */ + CV_WRAP virtual bool set(int propId, double value); + + /** @brief Returns the specified VideoWriter property + + @param propId Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) + or one of @ref videoio_flags_others + + @return Value for the specified property. Value 0 is returned when querying a property that is + not supported by the backend used by the VideoWriter instance. + */ + CV_WRAP virtual double get(int propId) const; + + /** @brief Concatenates 4 chars to a fourcc code + + @return a fourcc code + + This static method constructs the fourcc code of the codec to be used in the constructor + VideoWriter::VideoWriter or VideoWriter::open. + */ + CV_WRAP static int fourcc(char c1, char c2, char c3, char c4); + + /** @brief Returns used backend API name + + @note Stream should be opened. + */ + CV_WRAP String getBackendName() const; + +protected: + Ptr<CvVideoWriter> writer; + Ptr<IVideoWriter> iwriter; + + static Ptr<IVideoWriter> create(const String& filename, int fourcc, double fps, + Size frameSize, bool isColor = true); +}; + +template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const; +template<> CV_EXPORTS void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const; + +//! @} videoio + +} // cv + +#endif //OPENCV_VIDEOIO_HPP diff --git a/include/opencv2/videoio/cap_ios.h b/include/opencv2/videoio/cap_ios.h new file mode 100644 index 0000000..207ad46 --- /dev/null +++ b/include/opencv2/videoio/cap_ios.h @@ -0,0 +1,150 @@ +/* For iOS video I/O + * by Eduard Feicho on 29/07/12 + * Copyright 2012. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 THE AUTHOR 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. + * + */ + +#import <UIKit/UIKit.h> +#import <Accelerate/Accelerate.h> +#import <AVFoundation/AVFoundation.h> +#import <ImageIO/ImageIO.h> +#include "opencv2/core.hpp" + +//! @addtogroup videoio_ios +//! @{ + +/////////////////////////////////////// CvAbstractCamera ///////////////////////////////////// + +@class CvAbstractCamera; + +CV_EXPORTS @interface CvAbstractCamera : NSObject +{ + UIDeviceOrientation currentDeviceOrientation; + + BOOL cameraAvailable; +} + +@property (nonatomic, strong) AVCaptureSession* captureSession; +@property (nonatomic, strong) AVCaptureConnection* videoCaptureConnection; + +@property (nonatomic, readonly) BOOL running; +@property (nonatomic, readonly) BOOL captureSessionLoaded; + +@property (nonatomic, assign) int defaultFPS; +@property (nonatomic, readonly) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer; +@property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition; +@property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation; +@property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer; +@property (nonatomic, strong) NSString *const defaultAVCaptureSessionPreset; + +@property (nonatomic, assign) int imageWidth; +@property (nonatomic, assign) int imageHeight; + +@property (nonatomic, strong) UIView* parentView; + +- CV_UNUSED(start); +- CV_UNUSED(stop); +- CV_UNUSED(switchCameras); + +- (id)initWithParentView:(UIView*)parent; + +- CV_UNUSED(createCaptureOutput); +- CV_UNUSED(createVideoPreviewLayer); +- CV_UNUSED(updateOrientation); + +- CV_UNUSED(lockFocus); +- CV_UNUSED(unlockFocus); +- CV_UNUSED(lockExposure); +- CV_UNUSED(unlockExposure); +- CV_UNUSED(lockBalance); +- CV_UNUSED(unlockBalance); + +@end + +///////////////////////////////// CvVideoCamera /////////////////////////////////////////// + +@class CvVideoCamera; + +CV_EXPORTS @protocol CvVideoCameraDelegate <NSObject> + +#ifdef __cplusplus +// delegate method for processing image frames +- (void)processImage:(cv::Mat&)image; +#endif + +@end + +CV_EXPORTS @interface CvVideoCamera : CvAbstractCamera<AVCaptureVideoDataOutputSampleBufferDelegate> +{ + AVCaptureVideoDataOutput *videoDataOutput; + + dispatch_queue_t videoDataOutputQueue; + CALayer *customPreviewLayer; + + CMTime lastSampleTime; + +} + +@property (nonatomic, weak) id<CvVideoCameraDelegate> delegate; +@property (nonatomic, assign) BOOL grayscaleMode; + +@property (nonatomic, assign) BOOL recordVideo; +@property (nonatomic, assign) BOOL rotateVideo; +@property (nonatomic, strong) AVAssetWriterInput* recordAssetWriterInput; +@property (nonatomic, strong) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; +@property (nonatomic, strong) AVAssetWriter* recordAssetWriter; + +- (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; +- CV_UNUSED(layoutPreviewLayer); +- CV_UNUSED(saveVideo); +- (NSURL *)videoFileURL; +- (NSString *)videoFileString; + + +@end + +///////////////////////////////// CvPhotoCamera /////////////////////////////////////////// + +@class CvPhotoCamera; + +CV_EXPORTS @protocol CvPhotoCameraDelegate <NSObject> + +- (void)photoCamera:(CvPhotoCamera*)photoCamera capturedImage:(UIImage *)image; +- (void)photoCameraCancel:(CvPhotoCamera*)photoCamera; + +@end + +CV_EXPORTS @interface CvPhotoCamera : CvAbstractCamera +{ + AVCaptureStillImageOutput *stillImageOutput; +} + +@property (nonatomic, weak) id<CvPhotoCameraDelegate> delegate; + +- CV_UNUSED(takePicture); + +@end + +//! @} videoio_ios diff --git a/include/opencv2/videoio/registry.hpp b/include/opencv2/videoio/registry.hpp new file mode 100644 index 0000000..7404c68 --- /dev/null +++ b/include/opencv2/videoio/registry.hpp @@ -0,0 +1,44 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_VIDEOIO_REGISTRY_HPP +#define OPENCV_VIDEOIO_REGISTRY_HPP + +#include <opencv2/videoio.hpp> + +namespace cv { namespace videoio_registry { +/** @addtogroup videoio_registry +This section contains API description how to query/configure available Video I/O backends. + +Runtime configuration options: +- enable debug mode: `OPENCV_VIDEOIO_DEBUG=1` +- change backend priority: `OPENCV_VIDEOIO_PRIORITY_<backend>=9999` +- disable backend: `OPENCV_VIDEOIO_PRIORITY_<backend>=0` +- specify list of backends with high priority (>100000): `OPENCV_VIDEOIO_PRIORITY_LIST=FFMPEG,GSTREAMER` + +@{ + */ + + +/** @brief Returns backend API name or "unknown" +@param api backend ID (#VideoCaptureAPIs) +*/ +CV_EXPORTS_W cv::String getBackendName(VideoCaptureAPIs api); + +/** @brief Returns list of all builtin backends */ +CV_EXPORTS_W std::vector<VideoCaptureAPIs> getBackends(); + +/** @brief Returns list of available backends which works via `cv::VideoCapture(int index)` */ +CV_EXPORTS_W std::vector<VideoCaptureAPIs> getCameraBackends(); + +/** @brief Returns list of available backends which works via `cv::VideoCapture(filename)` */ +CV_EXPORTS_W std::vector<VideoCaptureAPIs> getStreamBackends(); + +/** @brief Returns list of available backends which works via `cv::VideoWriter()` */ +CV_EXPORTS_W std::vector<VideoCaptureAPIs> getWriterBackends(); + +//! @} +}} // namespace + +#endif // OPENCV_VIDEOIO_REGISTRY_HPP diff --git a/include/opencv2/videoio/videoio.hpp b/include/opencv2/videoio/videoio.hpp new file mode 100644 index 0000000..ec84cf7 --- /dev/null +++ b/include/opencv2/videoio/videoio.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/videoio.hpp" diff --git a/include/opencv2/videoio/videoio_c.h b/include/opencv2/videoio/videoio_c.h new file mode 100644 index 0000000..32f6ec7 --- /dev/null +++ b/include/opencv2/videoio/videoio_c.h @@ -0,0 +1,587 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOIO_H +#define OPENCV_VIDEOIO_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + @addtogroup videoio_c + @{ +*/ + +/****************************************************************************************\ +* Working with Video Files and Cameras * +\****************************************************************************************/ + +/** @brief "black box" capture structure + +In C++ use cv::VideoCapture +*/ +typedef struct CvCapture CvCapture; + +/** @brief start capturing frames from video file +*/ +CVAPI(CvCapture*) cvCreateFileCapture( const char* filename ); + +/** @brief start capturing frames from video file. allows specifying a preferred API to use +*/ +CVAPI(CvCapture*) cvCreateFileCaptureWithPreference( const char* filename , int apiPreference); + +enum +{ + CV_CAP_ANY =0, // autodetect + + CV_CAP_MIL =100, // MIL proprietary drivers + + CV_CAP_VFW =200, // platform native + CV_CAP_V4L =200, + CV_CAP_V4L2 =200, + + CV_CAP_FIREWARE =300, // IEEE 1394 drivers + CV_CAP_FIREWIRE =300, + CV_CAP_IEEE1394 =300, + CV_CAP_DC1394 =300, + CV_CAP_CMU1394 =300, + + CV_CAP_STEREO =400, // TYZX proprietary drivers + CV_CAP_TYZX =400, + CV_TYZX_LEFT =400, + CV_TYZX_RIGHT =401, + CV_TYZX_COLOR =402, + CV_TYZX_Z =403, + + CV_CAP_QT =500, // QuickTime + + CV_CAP_UNICAP =600, // Unicap drivers + + CV_CAP_DSHOW =700, // DirectShow (via videoInput) + CV_CAP_MSMF =1400, // Microsoft Media Foundation (via videoInput) + + CV_CAP_PVAPI =800, // PvAPI, Prosilica GigE SDK + + CV_CAP_OPENNI =900, // OpenNI (for Kinect) + CV_CAP_OPENNI_ASUS =910, // OpenNI (for Asus Xtion) + + CV_CAP_ANDROID =1000, // Android - not used + CV_CAP_ANDROID_BACK =CV_CAP_ANDROID+99, // Android back camera - not used + CV_CAP_ANDROID_FRONT =CV_CAP_ANDROID+98, // Android front camera - not used + + CV_CAP_XIAPI =1100, // XIMEA Camera API + + CV_CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API) + + CV_CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK + + CV_CAP_INTELPERC = 1500, // Intel Perceptual Computing + + CV_CAP_OPENNI2 = 1600, // OpenNI2 (for Kinect) + CV_CAP_GPHOTO2 = 1700, + CV_CAP_GSTREAMER = 1800, // GStreamer + CV_CAP_FFMPEG = 1900, // FFMPEG + CV_CAP_IMAGES = 2000, // OpenCV Image Sequence (e.g. img_%02d.jpg) + + CV_CAP_ARAVIS = 2100 // Aravis GigE SDK +}; + +/** @brief start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) +*/ +CVAPI(CvCapture*) cvCreateCameraCapture( int index ); + +/** @brief grab a frame, return 1 on success, 0 on fail. + + this function is thought to be fast +*/ +CVAPI(int) cvGrabFrame( CvCapture* capture ); + +/** @brief get the frame grabbed with cvGrabFrame(..) + + This function may apply some frame processing like + frame decompression, flipping etc. + @warning !!!DO NOT RELEASE or MODIFY the retrieved frame!!! +*/ +CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture, int streamIdx CV_DEFAULT(0) ); + +/** @brief Just a combination of cvGrabFrame and cvRetrieveFrame + + @warning !!!DO NOT RELEASE or MODIFY the retrieved frame!!! +*/ +CVAPI(IplImage*) cvQueryFrame( CvCapture* capture ); + +/** @brief stop capturing/reading and free resources +*/ +CVAPI(void) cvReleaseCapture( CvCapture** capture ); + +enum +{ + // modes of the controlling registers (can be: auto, manual, auto single push, absolute Latter allowed with any other mode) + // every feature can have only one mode turned on at a time + CV_CAP_PROP_DC1394_OFF = -4, //turn the feature off (not controlled manually nor automatically) + CV_CAP_PROP_DC1394_MODE_MANUAL = -3, //set automatically when a value of the feature is set by the user + CV_CAP_PROP_DC1394_MODE_AUTO = -2, + CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1, + CV_CAP_PROP_POS_MSEC =0, + CV_CAP_PROP_POS_FRAMES =1, + CV_CAP_PROP_POS_AVI_RATIO =2, + CV_CAP_PROP_FRAME_WIDTH =3, + CV_CAP_PROP_FRAME_HEIGHT =4, + CV_CAP_PROP_FPS =5, + CV_CAP_PROP_FOURCC =6, + CV_CAP_PROP_FRAME_COUNT =7, + CV_CAP_PROP_FORMAT =8, + CV_CAP_PROP_MODE =9, + CV_CAP_PROP_BRIGHTNESS =10, + CV_CAP_PROP_CONTRAST =11, + CV_CAP_PROP_SATURATION =12, + CV_CAP_PROP_HUE =13, + CV_CAP_PROP_GAIN =14, + CV_CAP_PROP_EXPOSURE =15, + CV_CAP_PROP_CONVERT_RGB =16, + CV_CAP_PROP_WHITE_BALANCE_BLUE_U =17, + CV_CAP_PROP_RECTIFICATION =18, + CV_CAP_PROP_MONOCHROME =19, + CV_CAP_PROP_SHARPNESS =20, + CV_CAP_PROP_AUTO_EXPOSURE =21, // exposure control done by camera, + // user can adjust reference level + // using this feature + CV_CAP_PROP_GAMMA =22, + CV_CAP_PROP_TEMPERATURE =23, + CV_CAP_PROP_TRIGGER =24, + CV_CAP_PROP_TRIGGER_DELAY =25, + CV_CAP_PROP_WHITE_BALANCE_RED_V =26, + CV_CAP_PROP_ZOOM =27, + CV_CAP_PROP_FOCUS =28, + CV_CAP_PROP_GUID =29, + CV_CAP_PROP_ISO_SPEED =30, + CV_CAP_PROP_MAX_DC1394 =31, + CV_CAP_PROP_BACKLIGHT =32, + CV_CAP_PROP_PAN =33, + CV_CAP_PROP_TILT =34, + CV_CAP_PROP_ROLL =35, + CV_CAP_PROP_IRIS =36, + CV_CAP_PROP_SETTINGS =37, + CV_CAP_PROP_BUFFERSIZE =38, + CV_CAP_PROP_AUTOFOCUS =39, + CV_CAP_PROP_SAR_NUM =40, + CV_CAP_PROP_SAR_DEN =41, + + CV_CAP_PROP_AUTOGRAB =1024, // property for videoio class CvCapture_Android only + CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING=1025, // readonly, tricky property, returns cpnst char* indeed + CV_CAP_PROP_PREVIEW_FORMAT=1026, // readonly, tricky property, returns cpnst char* indeed + + // OpenNI map generators + CV_CAP_OPENNI_DEPTH_GENERATOR = 1 << 31, + CV_CAP_OPENNI_IMAGE_GENERATOR = 1 << 30, + CV_CAP_OPENNI_IR_GENERATOR = 1 << 29, + CV_CAP_OPENNI_GENERATORS_MASK = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_OPENNI_IR_GENERATOR, + + // Properties of cameras available through OpenNI interfaces + CV_CAP_PROP_OPENNI_OUTPUT_MODE = 100, + CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm + CV_CAP_PROP_OPENNI_BASELINE = 102, // in mm + CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels + CV_CAP_PROP_OPENNI_REGISTRATION = 104, // flag + CV_CAP_PROP_OPENNI_REGISTRATION_ON = CV_CAP_PROP_OPENNI_REGISTRATION, // flag that synchronizes the remapping depth map to image map + // by changing depth generator's view point (if the flag is "on") or + // sets this view point to its normal one (if the flag is "off"). + CV_CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105, + CV_CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106, + CV_CAP_PROP_OPENNI_CIRCLE_BUFFER = 107, + CV_CAP_PROP_OPENNI_MAX_TIME_DURATION = 108, + + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT = 109, + CV_CAP_PROP_OPENNI2_SYNC = 110, + CV_CAP_PROP_OPENNI2_MIRROR = 111, + + CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT, + CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE, + CV_CAP_OPENNI_DEPTH_GENERATOR_PRESENT = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT, + CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE, + CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH, + CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_REGISTRATION, + CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, + CV_CAP_OPENNI_IR_GENERATOR_PRESENT = CV_CAP_OPENNI_IR_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT, + + // Properties of cameras available through GStreamer interface + CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1 + + // PVAPI + CV_CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast + CV_CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301, // FrameStartTriggerMode: Determines how a frame is initiated + CV_CAP_PROP_PVAPI_DECIMATIONHORIZONTAL = 302, // Horizontal sub-sampling of the image + CV_CAP_PROP_PVAPI_DECIMATIONVERTICAL = 303, // Vertical sub-sampling of the image + CV_CAP_PROP_PVAPI_BINNINGX = 304, // Horizontal binning factor + CV_CAP_PROP_PVAPI_BINNINGY = 305, // Vertical binning factor + CV_CAP_PROP_PVAPI_PIXELFORMAT = 306, // Pixel format + + // Properties of cameras available through XIMEA SDK interface + CV_CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping. + CV_CAP_PROP_XI_DATA_FORMAT = 401, // Output data format. + CV_CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels). + CV_CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels). + CV_CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger. + CV_CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE. + CV_CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input + CV_CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode + CV_CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level + CV_CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output + CV_CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode + CV_CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED + CV_CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality + CV_CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition) + CV_CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance + CV_CAP_PROP_XI_AEAG = 415, // Automatic exposure/gain + CV_CAP_PROP_XI_EXP_PRIORITY = 416, // Exposure priority (0.5 - exposure 50%, gain 50%). + CV_CAP_PROP_XI_AE_MAX_LIMIT = 417, // Maximum limit of exposure in AEAG procedure + CV_CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure + CV_CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %) + CV_CAP_PROP_XI_TIMEOUT = 420, // Image capture timeout in milliseconds + CV_CAP_PROP_XI_EXPOSURE = 421, // Exposure time in microseconds + CV_CAP_PROP_XI_EXPOSURE_BURST_COUNT = 422, // Sets the number of times of exposure in one frame. + CV_CAP_PROP_XI_GAIN_SELECTOR = 423, // Gain selector for parameter Gain allows to select different type of gains. + CV_CAP_PROP_XI_GAIN = 424, // Gain in dB + CV_CAP_PROP_XI_DOWNSAMPLING_TYPE = 426, // Change image downsampling type. + CV_CAP_PROP_XI_BINNING_SELECTOR = 427, // Binning engine selector. + CV_CAP_PROP_XI_BINNING_VERTICAL = 428, // Vertical Binning - number of vertical photo-sensitive cells to combine together. + CV_CAP_PROP_XI_BINNING_HORIZONTAL = 429, // Horizontal Binning - number of horizontal photo-sensitive cells to combine together. + CV_CAP_PROP_XI_BINNING_PATTERN = 430, // Binning pattern type. + CV_CAP_PROP_XI_DECIMATION_SELECTOR = 431, // Decimation engine selector. + CV_CAP_PROP_XI_DECIMATION_VERTICAL = 432, // Vertical Decimation - vertical sub-sampling of the image - reduces the vertical resolution of the image by the specified vertical decimation factor. + CV_CAP_PROP_XI_DECIMATION_HORIZONTAL = 433, // Horizontal Decimation - horizontal sub-sampling of the image - reduces the horizontal resolution of the image by the specified vertical decimation factor. + CV_CAP_PROP_XI_DECIMATION_PATTERN = 434, // Decimation pattern type. + CV_CAP_PROP_XI_TEST_PATTERN_GENERATOR_SELECTOR = 587, // Selects which test pattern generator is controlled by the TestPattern feature. + CV_CAP_PROP_XI_TEST_PATTERN = 588, // Selects which test pattern type is generated by the selected generator. + CV_CAP_PROP_XI_IMAGE_DATA_FORMAT = 435, // Output data format. + CV_CAP_PROP_XI_SHUTTER_TYPE = 436, // Change sensor shutter type(CMOS sensor). + CV_CAP_PROP_XI_SENSOR_TAPS = 437, // Number of taps + CV_CAP_PROP_XI_AEAG_ROI_OFFSET_X = 439, // Automatic exposure/gain ROI offset X + CV_CAP_PROP_XI_AEAG_ROI_OFFSET_Y = 440, // Automatic exposure/gain ROI offset Y + CV_CAP_PROP_XI_AEAG_ROI_WIDTH = 441, // Automatic exposure/gain ROI Width + CV_CAP_PROP_XI_AEAG_ROI_HEIGHT = 442, // Automatic exposure/gain ROI Height + CV_CAP_PROP_XI_BPC = 445, // Correction of bad pixels + CV_CAP_PROP_XI_WB_KR = 448, // White balance red coefficient + CV_CAP_PROP_XI_WB_KG = 449, // White balance green coefficient + CV_CAP_PROP_XI_WB_KB = 450, // White balance blue coefficient + CV_CAP_PROP_XI_WIDTH = 451, // Width of the Image provided by the device (in pixels). + CV_CAP_PROP_XI_HEIGHT = 452, // Height of the Image provided by the device (in pixels). + CV_CAP_PROP_XI_REGION_SELECTOR = 589, // Selects Region in Multiple ROI which parameters are set by width, height, ... ,region mode + CV_CAP_PROP_XI_REGION_MODE = 595, // Activates/deactivates Region selected by Region Selector + CV_CAP_PROP_XI_LIMIT_BANDWIDTH = 459, // Set/get bandwidth(datarate)(in Megabits) + CV_CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, // Sensor output data bit depth. + CV_CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, // Device output data bit depth. + CV_CAP_PROP_XI_IMAGE_DATA_BIT_DEPTH = 462, // bitdepth of data returned by function xiGetImage + CV_CAP_PROP_XI_OUTPUT_DATA_PACKING = 463, // Device output data packing (or grouping) enabled. Packing could be enabled if output_data_bit_depth > 8 and packing capability is available. + CV_CAP_PROP_XI_OUTPUT_DATA_PACKING_TYPE = 464, // Data packing type. Some cameras supports only specific packing type. + CV_CAP_PROP_XI_IS_COOLED = 465, // Returns 1 for cameras that support cooling. + CV_CAP_PROP_XI_COOLING = 466, // Start camera cooling. + CV_CAP_PROP_XI_TARGET_TEMP = 467, // Set sensor target temperature for cooling. + CV_CAP_PROP_XI_CHIP_TEMP = 468, // Camera sensor temperature + CV_CAP_PROP_XI_HOUS_TEMP = 469, // Camera housing tepmerature + CV_CAP_PROP_XI_HOUS_BACK_SIDE_TEMP = 590, // Camera housing back side tepmerature + CV_CAP_PROP_XI_SENSOR_BOARD_TEMP = 596, // Camera sensor board temperature + CV_CAP_PROP_XI_CMS = 470, // Mode of color management system. + CV_CAP_PROP_XI_APPLY_CMS = 471, // Enable applying of CMS profiles to xiGetImage (see XI_PRM_INPUT_CMS_PROFILE, XI_PRM_OUTPUT_CMS_PROFILE). + CV_CAP_PROP_XI_IMAGE_IS_COLOR = 474, // Returns 1 for color cameras. + CV_CAP_PROP_XI_COLOR_FILTER_ARRAY = 475, // Returns color filter array type of RAW data. + CV_CAP_PROP_XI_GAMMAY = 476, // Luminosity gamma + CV_CAP_PROP_XI_GAMMAC = 477, // Chromaticity gamma + CV_CAP_PROP_XI_SHARPNESS = 478, // Sharpness Strength + CV_CAP_PROP_XI_CC_MATRIX_00 = 479, // Color Correction Matrix element [0][0] + CV_CAP_PROP_XI_CC_MATRIX_01 = 480, // Color Correction Matrix element [0][1] + CV_CAP_PROP_XI_CC_MATRIX_02 = 481, // Color Correction Matrix element [0][2] + CV_CAP_PROP_XI_CC_MATRIX_03 = 482, // Color Correction Matrix element [0][3] + CV_CAP_PROP_XI_CC_MATRIX_10 = 483, // Color Correction Matrix element [1][0] + CV_CAP_PROP_XI_CC_MATRIX_11 = 484, // Color Correction Matrix element [1][1] + CV_CAP_PROP_XI_CC_MATRIX_12 = 485, // Color Correction Matrix element [1][2] + CV_CAP_PROP_XI_CC_MATRIX_13 = 486, // Color Correction Matrix element [1][3] + CV_CAP_PROP_XI_CC_MATRIX_20 = 487, // Color Correction Matrix element [2][0] + CV_CAP_PROP_XI_CC_MATRIX_21 = 488, // Color Correction Matrix element [2][1] + CV_CAP_PROP_XI_CC_MATRIX_22 = 489, // Color Correction Matrix element [2][2] + CV_CAP_PROP_XI_CC_MATRIX_23 = 490, // Color Correction Matrix element [2][3] + CV_CAP_PROP_XI_CC_MATRIX_30 = 491, // Color Correction Matrix element [3][0] + CV_CAP_PROP_XI_CC_MATRIX_31 = 492, // Color Correction Matrix element [3][1] + CV_CAP_PROP_XI_CC_MATRIX_32 = 493, // Color Correction Matrix element [3][2] + CV_CAP_PROP_XI_CC_MATRIX_33 = 494, // Color Correction Matrix element [3][3] + CV_CAP_PROP_XI_DEFAULT_CC_MATRIX = 495, // Set default Color Correction Matrix + CV_CAP_PROP_XI_TRG_SELECTOR = 498, // Selects the type of trigger. + CV_CAP_PROP_XI_ACQ_FRAME_BURST_COUNT = 499, // Sets number of frames acquired by burst. This burst is used only if trigger is set to FrameBurstStart + CV_CAP_PROP_XI_DEBOUNCE_EN = 507, // Enable/Disable debounce to selected GPI + CV_CAP_PROP_XI_DEBOUNCE_T0 = 508, // Debounce time (x * 10us) + CV_CAP_PROP_XI_DEBOUNCE_T1 = 509, // Debounce time (x * 10us) + CV_CAP_PROP_XI_DEBOUNCE_POL = 510, // Debounce polarity (pol = 1 t0 - falling edge, t1 - rising edge) + CV_CAP_PROP_XI_LENS_MODE = 511, // Status of lens control interface. This shall be set to XI_ON before any Lens operations. + CV_CAP_PROP_XI_LENS_APERTURE_VALUE = 512, // Current lens aperture value in stops. Examples: 2.8, 4, 5.6, 8, 11 + CV_CAP_PROP_XI_LENS_FOCUS_MOVEMENT_VALUE = 513, // Lens current focus movement value to be used by XI_PRM_LENS_FOCUS_MOVE in motor steps. + CV_CAP_PROP_XI_LENS_FOCUS_MOVE = 514, // Moves lens focus motor by steps set in XI_PRM_LENS_FOCUS_MOVEMENT_VALUE. + CV_CAP_PROP_XI_LENS_FOCUS_DISTANCE = 515, // Lens focus distance in cm. + CV_CAP_PROP_XI_LENS_FOCAL_LENGTH = 516, // Lens focal distance in mm. + CV_CAP_PROP_XI_LENS_FEATURE_SELECTOR = 517, // Selects the current feature which is accessible by XI_PRM_LENS_FEATURE. + CV_CAP_PROP_XI_LENS_FEATURE = 518, // Allows access to lens feature value currently selected by XI_PRM_LENS_FEATURE_SELECTOR. + CV_CAP_PROP_XI_DEVICE_MODEL_ID = 521, // Return device model id + CV_CAP_PROP_XI_DEVICE_SN = 522, // Return device serial number + CV_CAP_PROP_XI_IMAGE_DATA_FORMAT_RGB32_ALPHA = 529, // The alpha channel of RGB32 output image format. + CV_CAP_PROP_XI_IMAGE_PAYLOAD_SIZE = 530, // Buffer size in bytes sufficient for output image returned by xiGetImage + CV_CAP_PROP_XI_TRANSPORT_PIXEL_FORMAT = 531, // Current format of pixels on transport layer. + CV_CAP_PROP_XI_SENSOR_CLOCK_FREQ_HZ = 532, // Sensor clock frequency in Hz. + CV_CAP_PROP_XI_SENSOR_CLOCK_FREQ_INDEX = 533, // Sensor clock frequency index. Sensor with selected frequencies have possibility to set the frequency only by this index. + CV_CAP_PROP_XI_SENSOR_OUTPUT_CHANNEL_COUNT = 534, // Number of output channels from sensor used for data transfer. + CV_CAP_PROP_XI_FRAMERATE = 535, // Define framerate in Hz + CV_CAP_PROP_XI_COUNTER_SELECTOR = 536, // Select counter + CV_CAP_PROP_XI_COUNTER_VALUE = 537, // Counter status + CV_CAP_PROP_XI_ACQ_TIMING_MODE = 538, // Type of sensor frames timing. + CV_CAP_PROP_XI_AVAILABLE_BANDWIDTH = 539, // Calculate and return available interface bandwidth(int Megabits) + CV_CAP_PROP_XI_BUFFER_POLICY = 540, // Data move policy + CV_CAP_PROP_XI_LUT_EN = 541, // Activates LUT. + CV_CAP_PROP_XI_LUT_INDEX = 542, // Control the index (offset) of the coefficient to access in the LUT. + CV_CAP_PROP_XI_LUT_VALUE = 543, // Value at entry LUTIndex of the LUT + CV_CAP_PROP_XI_TRG_DELAY = 544, // Specifies the delay in microseconds (us) to apply after the trigger reception before activating it. + CV_CAP_PROP_XI_TS_RST_MODE = 545, // Defines how time stamp reset engine will be armed + CV_CAP_PROP_XI_TS_RST_SOURCE = 546, // Defines which source will be used for timestamp reset. Writing this parameter will trigger settings of engine (arming) + CV_CAP_PROP_XI_IS_DEVICE_EXIST = 547, // Returns 1 if camera connected and works properly. + CV_CAP_PROP_XI_ACQ_BUFFER_SIZE = 548, // Acquisition buffer size in buffer_size_unit. Default bytes. + CV_CAP_PROP_XI_ACQ_BUFFER_SIZE_UNIT = 549, // Acquisition buffer size unit in bytes. Default 1. E.g. Value 1024 means that buffer_size is in KiBytes + CV_CAP_PROP_XI_ACQ_TRANSPORT_BUFFER_SIZE = 550, // Acquisition transport buffer size in bytes + CV_CAP_PROP_XI_BUFFERS_QUEUE_SIZE = 551, // Queue of field/frame buffers + CV_CAP_PROP_XI_ACQ_TRANSPORT_BUFFER_COMMIT = 552, // Number of buffers to commit to low level + CV_CAP_PROP_XI_RECENT_FRAME = 553, // GetImage returns most recent frame + CV_CAP_PROP_XI_DEVICE_RESET = 554, // Resets the camera to default state. + CV_CAP_PROP_XI_COLUMN_FPN_CORRECTION = 555, // Correction of column FPN + CV_CAP_PROP_XI_ROW_FPN_CORRECTION = 591, // Correction of row FPN + CV_CAP_PROP_XI_SENSOR_MODE = 558, // Current sensor mode. Allows to select sensor mode by one integer. Setting of this parameter affects: image dimensions and downsampling. + CV_CAP_PROP_XI_HDR = 559, // Enable High Dynamic Range feature. + CV_CAP_PROP_XI_HDR_KNEEPOINT_COUNT = 560, // The number of kneepoints in the PWLR. + CV_CAP_PROP_XI_HDR_T1 = 561, // position of first kneepoint(in % of XI_PRM_EXPOSURE) + CV_CAP_PROP_XI_HDR_T2 = 562, // position of second kneepoint (in % of XI_PRM_EXPOSURE) + CV_CAP_PROP_XI_KNEEPOINT1 = 563, // value of first kneepoint (% of sensor saturation) + CV_CAP_PROP_XI_KNEEPOINT2 = 564, // value of second kneepoint (% of sensor saturation) + CV_CAP_PROP_XI_IMAGE_BLACK_LEVEL = 565, // Last image black level counts. Can be used for Offline processing to recall it. + CV_CAP_PROP_XI_HW_REVISION = 571, // Returns hardware revision number. + CV_CAP_PROP_XI_DEBUG_LEVEL = 572, // Set debug level + CV_CAP_PROP_XI_AUTO_BANDWIDTH_CALCULATION = 573, // Automatic bandwidth calculation, + CV_CAP_PROP_XI_FFS_FILE_ID = 594, // File number. + CV_CAP_PROP_XI_FFS_FILE_SIZE = 580, // Size of file. + CV_CAP_PROP_XI_FREE_FFS_SIZE = 581, // Size of free camera FFS. + CV_CAP_PROP_XI_USED_FFS_SIZE = 582, // Size of used camera FFS. + CV_CAP_PROP_XI_FFS_ACCESS_KEY = 583, // Setting of key enables file operations on some cameras. + CV_CAP_PROP_XI_SENSOR_FEATURE_SELECTOR = 585, // Selects the current feature which is accessible by XI_PRM_SENSOR_FEATURE_VALUE. + CV_CAP_PROP_XI_SENSOR_FEATURE_VALUE = 586, // Allows access to sensor feature value currently selected by XI_PRM_SENSOR_FEATURE_SELECTOR. + + + // Properties for Android cameras + CV_CAP_PROP_ANDROID_FLASH_MODE = 8001, + CV_CAP_PROP_ANDROID_FOCUS_MODE = 8002, + CV_CAP_PROP_ANDROID_WHITE_BALANCE = 8003, + CV_CAP_PROP_ANDROID_ANTIBANDING = 8004, + CV_CAP_PROP_ANDROID_FOCAL_LENGTH = 8005, + CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_NEAR = 8006, + CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_OPTIMAL = 8007, + CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR = 8008, + CV_CAP_PROP_ANDROID_EXPOSE_LOCK = 8009, + CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK = 8010, + + // Properties of cameras available through AVFOUNDATION interface + CV_CAP_PROP_IOS_DEVICE_FOCUS = 9001, + CV_CAP_PROP_IOS_DEVICE_EXPOSURE = 9002, + CV_CAP_PROP_IOS_DEVICE_FLASH = 9003, + CV_CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004, + CV_CAP_PROP_IOS_DEVICE_TORCH = 9005, + + // Properties of cameras available through Smartek Giganetix Ethernet Vision interface + /* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */ + CV_CAP_PROP_GIGA_FRAME_OFFSET_X = 10001, + CV_CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002, + CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003, + CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004, + CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005, + CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006, + + CV_CAP_PROP_INTELPERC_PROFILE_COUNT = 11001, + CV_CAP_PROP_INTELPERC_PROFILE_IDX = 11002, + CV_CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003, + CV_CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004, + CV_CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005, + CV_CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006, + CV_CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007, + + // Intel PerC streams + CV_CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29, + CV_CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28, + CV_CAP_INTELPERC_GENERATORS_MASK = CV_CAP_INTELPERC_DEPTH_GENERATOR + CV_CAP_INTELPERC_IMAGE_GENERATOR +}; + +// Generic camera output modes. +// Currently, these are supported through the libv4l interface only. +enum +{ + CV_CAP_MODE_BGR = 0, // BGR24 (default) + CV_CAP_MODE_RGB = 1, // RGB24 + CV_CAP_MODE_GRAY = 2, // Y8 + CV_CAP_MODE_YUYV = 3 // YUYV +}; + +enum +{ + // Data given from depth generator. + CV_CAP_OPENNI_DEPTH_MAP = 0, // Depth values in mm (CV_16UC1) + CV_CAP_OPENNI_POINT_CLOUD_MAP = 1, // XYZ in meters (CV_32FC3) + CV_CAP_OPENNI_DISPARITY_MAP = 2, // Disparity in pixels (CV_8UC1) + CV_CAP_OPENNI_DISPARITY_MAP_32F = 3, // Disparity in pixels (CV_32FC1) + CV_CAP_OPENNI_VALID_DEPTH_MASK = 4, // CV_8UC1 + + // Data given from RGB image generator. + CV_CAP_OPENNI_BGR_IMAGE = 5, + CV_CAP_OPENNI_GRAY_IMAGE = 6, + + // Data given from IR image generator. + CV_CAP_OPENNI_IR_IMAGE = 7 +}; + +// Supported output modes of OpenNI image generator +enum +{ + CV_CAP_OPENNI_VGA_30HZ = 0, + CV_CAP_OPENNI_SXGA_15HZ = 1, + CV_CAP_OPENNI_SXGA_30HZ = 2, + CV_CAP_OPENNI_QVGA_30HZ = 3, + CV_CAP_OPENNI_QVGA_60HZ = 4 +}; + +enum +{ + CV_CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth. + CV_CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates. + CV_CAP_INTELPERC_IR_MAP = 2, // Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam. + CV_CAP_INTELPERC_IMAGE = 3 +}; + +// gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID +// Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE. +// @see CvCaptureCAM_GPHOTO2 for more info +enum +{ + CV_CAP_PROP_GPHOTO2_PREVIEW = 17001, // Capture only preview from liveview mode. + CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, // Readonly, returns (const char *). + CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, // Trigger, only by set. Reload camera settings. + CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, // Reload all settings on set. + CV_CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, // Collect messages with details. + CV_CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, // Readonly, returns (const char *). + CV_CAP_PROP_SPEED = 17007, // Exposure speed. Can be readonly, depends on camera program. + CV_CAP_PROP_APERTURE = 17008, // Aperture. Can be readonly, depends on camera program. + CV_CAP_PROP_EXPOSUREPROGRAM = 17009, // Camera exposure program. + CV_CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode. +}; + +/** @brief retrieve capture properties +*/ +CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id ); +/** @brief set capture properties +*/ +CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value ); + +/** @brief Return the type of the capturer (eg, ::CV_CAP_VFW, ::CV_CAP_UNICAP) + +It is unknown if created with ::CV_CAP_ANY +*/ +CVAPI(int) cvGetCaptureDomain( CvCapture* capture); + +/** @brief "black box" video file writer structure + +In C++ use cv::VideoWriter +*/ +typedef struct CvVideoWriter CvVideoWriter; + +//! Macro to construct the fourcc code of the codec. Same as CV_FOURCC() +#define CV_FOURCC_MACRO(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24)) + +/** @brief Constructs the fourcc code of the codec function + +Simply call it with 4 chars fourcc code like `CV_FOURCC('I', 'Y', 'U', 'V')` + +List of codes can be obtained at [Video Codecs by FOURCC](http://www.fourcc.org/codecs.php) page. +FFMPEG backend with MP4 container natively uses other values as fourcc code: +see [ObjectType](http://www.mp4ra.org/codecs.html). +*/ +CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4) +{ + return CV_FOURCC_MACRO(c1, c2, c3, c4); +} + +//! (Windows only) Open Codec Selection Dialog +#define CV_FOURCC_PROMPT -1 +//! (Linux only) Use default codec for specified filename +#define CV_FOURCC_DEFAULT CV_FOURCC('I', 'Y', 'U', 'V') + +/** @brief initialize video file writer +*/ +CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc, + double fps, CvSize frame_size, + int is_color CV_DEFAULT(1)); + +/** @brief write frame to video file +*/ +CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image ); + +/** @brief close video file writer +*/ +CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer ); + +// *************************************************************************************** +//! @name Obsolete functions/synonyms +//! @{ +#define cvCaptureFromCAM cvCreateCameraCapture //!< @deprecated use cvCreateCameraCapture() instead +#define cvCaptureFromFile cvCreateFileCapture //!< @deprecated use cvCreateFileCapture() instead +#define cvCaptureFromAVI cvCaptureFromFile //!< @deprecated use cvCreateFileCapture() instead +#define cvCreateAVIWriter cvCreateVideoWriter //!< @deprecated use cvCreateVideoWriter() instead +#define cvWriteToAVI cvWriteFrame //!< @deprecated use cvWriteFrame() instead +//! @} Obsolete... + +//! @} videoio_c + +#ifdef __cplusplus +} +#endif + +#endif //OPENCV_VIDEOIO_H diff --git a/include/opencv2/videostab.hpp b/include/opencv2/videostab.hpp new file mode 100644 index 0000000..ca3f5ad --- /dev/null +++ b/include/opencv2/videostab.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_HPP +#define OPENCV_VIDEOSTAB_HPP + +/** + @defgroup videostab Video Stabilization + +The video stabilization module contains a set of functions and classes that can be used to solve the +problem of video stabilization. There are a few methods implemented, most of them are described in +the papers @cite OF06 and @cite G11 . However, there are some extensions and deviations from the original +paper methods. + +### References + + 1. "Full-Frame Video Stabilization with Motion Inpainting" + Yasuyuki Matsushita, Eyal Ofek, Weina Ge, Xiaoou Tang, Senior Member, and Heung-Yeung Shum + 2. "Auto-Directed Video Stabilization with Robust L1 Optimal Camera Paths" + Matthias Grundmann, Vivek Kwatra, Irfan Essa + + @{ + @defgroup videostab_motion Global Motion Estimation + +The video stabilization module contains a set of functions and classes for global motion estimation +between point clouds or between images. In the last case features are extracted and matched +internally. For the sake of convenience the motion estimation functions are wrapped into classes. +Both the functions and the classes are available. + + @defgroup videostab_marching Fast Marching Method + +The Fast Marching Method @cite Telea04 is used in of the video stabilization routines to do motion and +color inpainting. The method is implemented is a flexible way and it's made public for other users. + + @} + +*/ + +#include "opencv2/videostab/stabilizer.hpp" +#include "opencv2/videostab/ring_buffer.hpp" + +#endif diff --git a/include/opencv2/videostab/deblurring.hpp b/include/opencv2/videostab/deblurring.hpp new file mode 100644 index 0000000..c665640 --- /dev/null +++ b/include/opencv2/videostab/deblurring.hpp @@ -0,0 +1,116 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_DEBLURRING_HPP +#define OPENCV_VIDEOSTAB_DEBLURRING_HPP + +#include <vector> +#include "opencv2/core.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +CV_EXPORTS float calcBlurriness(const Mat &frame); + +class CV_EXPORTS DeblurerBase +{ +public: + DeblurerBase() : radius_(0), frames_(0), motions_(0), blurrinessRates_(0) {} + + virtual ~DeblurerBase() {} + + virtual void setRadius(int val) { radius_ = val; } + virtual int radius() const { return radius_; } + + virtual void deblur(int idx, Mat &frame) = 0; + + + // data from stabilizer + + virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; } + virtual const std::vector<Mat>& frames() const { return *frames_; } + + virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; } + virtual const std::vector<Mat>& motions() const { return *motions_; } + + virtual void setBlurrinessRates(const std::vector<float> &val) { blurrinessRates_ = &val; } + virtual const std::vector<float>& blurrinessRates() const { return *blurrinessRates_; } + +protected: + int radius_; + const std::vector<Mat> *frames_; + const std::vector<Mat> *motions_; + const std::vector<float> *blurrinessRates_; +}; + +class CV_EXPORTS NullDeblurer : public DeblurerBase +{ +public: + virtual void deblur(int /*idx*/, Mat &/*frame*/) CV_OVERRIDE {} +}; + +class CV_EXPORTS WeightingDeblurer : public DeblurerBase +{ +public: + WeightingDeblurer(); + + void setSensitivity(float val) { sensitivity_ = val; } + float sensitivity() const { return sensitivity_; } + + virtual void deblur(int idx, Mat &frame) CV_OVERRIDE; + +private: + float sensitivity_; + Mat_<float> bSum_, gSum_, rSum_, wSum_; +}; + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/fast_marching.hpp b/include/opencv2/videostab/fast_marching.hpp new file mode 100644 index 0000000..43f8e4a --- /dev/null +++ b/include/opencv2/videostab/fast_marching.hpp @@ -0,0 +1,121 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_FAST_MARCHING_HPP +#define OPENCV_VIDEOSTAB_FAST_MARCHING_HPP + +#include <cmath> +#include <queue> +#include <algorithm> +#include "opencv2/core.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab_marching +//! @{ + +/** @brief Describes the Fast Marching Method implementation. + + See http://iwi.eldoc.ub.rug.nl/FILES/root/2004/JGraphToolsTelea/2004JGraphToolsTelea.pdf + */ +class CV_EXPORTS FastMarchingMethod +{ +public: + FastMarchingMethod() : inf_(1e6f), size_(0) {} + + /** @brief Template method that runs the Fast Marching Method. + + @param mask Image mask. 0 value indicates that the pixel value must be inpainted, 255 indicates + that the pixel value is known, other values aren't acceptable. + @param inpaint Inpainting functor that overloads void operator ()(int x, int y). + @return Inpainting functor. + */ + template <typename Inpaint> + Inpaint run(const Mat &mask, Inpaint inpaint); + + /** + @return Distance map that's created during working of the method. + */ + Mat distanceMap() const { return dist_; } + +private: + enum { INSIDE = 0, BAND = 1, KNOWN = 255 }; + + struct DXY + { + float dist; + int x, y; + + DXY() : dist(0), x(0), y(0) {} + DXY(float _dist, int _x, int _y) : dist(_dist), x(_x), y(_y) {} + bool operator <(const DXY &dxy) const { return dist < dxy.dist; } + }; + + float solve(int x1, int y1, int x2, int y2) const; + int& indexOf(const DXY &dxy) { return index_(dxy.y, dxy.x); } + + void heapUp(int idx); + void heapDown(int idx); + void heapAdd(const DXY &dxy); + void heapRemoveMin(); + + float inf_; + + cv::Mat_<uchar> flag_; // flag map + cv::Mat_<float> dist_; // distance map + + cv::Mat_<int> index_; // index of point in the narrow band + std::vector<DXY> narrowBand_; // narrow band heap + int size_; // narrow band size +}; + +//! @} + +} // namespace videostab +} // namespace cv + +#include "fast_marching_inl.hpp" + +#endif diff --git a/include/opencv2/videostab/fast_marching_inl.hpp b/include/opencv2/videostab/fast_marching_inl.hpp new file mode 100644 index 0000000..fdd488a --- /dev/null +++ b/include/opencv2/videostab/fast_marching_inl.hpp @@ -0,0 +1,165 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP +#define OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP + +#include "opencv2/videostab/fast_marching.hpp" + +namespace cv +{ +namespace videostab +{ + +template <typename Inpaint> +Inpaint FastMarchingMethod::run(const cv::Mat &mask, Inpaint inpaint) +{ + using namespace cv; + + CV_Assert(mask.type() == CV_8U); + + static const int lut[4][2] = {{-1,0}, {0,-1}, {1,0}, {0,1}}; + + mask.copyTo(flag_); + flag_.create(mask.size()); + dist_.create(mask.size()); + index_.create(mask.size()); + narrowBand_.clear(); + size_ = 0; + + // init + for (int y = 0; y < flag_.rows; ++y) + { + for (int x = 0; x < flag_.cols; ++x) + { + if (flag_(y,x) == KNOWN) + dist_(y,x) = 0.f; + else + { + int n = 0; + int nunknown = 0; + + for (int i = 0; i < 4; ++i) + { + int xn = x + lut[i][0]; + int yn = y + lut[i][1]; + + if (xn >= 0 && xn < flag_.cols && yn >= 0 && yn < flag_.rows) + { + n++; + if (flag_(yn,xn) != KNOWN) + nunknown++; + } + } + + if (n>0 && nunknown == n) + { + dist_(y,x) = inf_; + flag_(y,x) = INSIDE; + } + else + { + dist_(y,x) = 0.f; + flag_(y,x) = BAND; + inpaint(x, y); + + narrowBand_.push_back(DXY(0.f,x,y)); + index_(y,x) = size_++; + } + } + } + } + + // make heap + for (int i = size_/2-1; i >= 0; --i) + heapDown(i); + + // main cycle + while (size_ > 0) + { + int x = narrowBand_[0].x; + int y = narrowBand_[0].y; + heapRemoveMin(); + + flag_(y,x) = KNOWN; + for (int n = 0; n < 4; ++n) + { + int xn = x + lut[n][0]; + int yn = y + lut[n][1]; + + if (xn >= 0 && xn < flag_.cols && yn >= 0 && yn < flag_.rows && flag_(yn,xn) != KNOWN) + { + dist_(yn,xn) = std::min(std::min(solve(xn-1, yn, xn, yn-1), solve(xn+1, yn, xn, yn-1)), + std::min(solve(xn-1, yn, xn, yn+1), solve(xn+1, yn, xn, yn+1))); + + if (flag_(yn,xn) == INSIDE) + { + flag_(yn,xn) = BAND; + inpaint(xn, yn); + heapAdd(DXY(dist_(yn,xn),xn,yn)); + } + else + { + int i = index_(yn,xn); + if (dist_(yn,xn) < narrowBand_[i].dist) + { + narrowBand_[i].dist = dist_(yn,xn); + heapUp(i); + } + // works better if it's commented out + /*else if (dist(yn,xn) > narrowBand[i].dist) + { + narrowBand[i].dist = dist(yn,xn); + heapDown(i); + }*/ + } + } + } + } + + return inpaint; +} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/frame_source.hpp b/include/opencv2/videostab/frame_source.hpp new file mode 100644 index 0000000..171c637 --- /dev/null +++ b/include/opencv2/videostab/frame_source.hpp @@ -0,0 +1,94 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP +#define OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP + +#include <vector> +#include "opencv2/core.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS IFrameSource +{ +public: + virtual ~IFrameSource() {} + virtual void reset() = 0; + virtual Mat nextFrame() = 0; +}; + +class CV_EXPORTS NullFrameSource : public IFrameSource +{ +public: + virtual void reset() CV_OVERRIDE {} + virtual Mat nextFrame() CV_OVERRIDE { return Mat(); } +}; + +class CV_EXPORTS VideoFileSource : public IFrameSource +{ +public: + VideoFileSource(const String &path, bool volatileFrame = false); + + virtual void reset() CV_OVERRIDE; + virtual Mat nextFrame() CV_OVERRIDE; + + int width(); + int height(); + int count(); + double fps(); + +private: + Ptr<IFrameSource> impl; +}; + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/global_motion.hpp b/include/opencv2/videostab/global_motion.hpp new file mode 100644 index 0000000..fedca2c --- /dev/null +++ b/include/opencv2/videostab/global_motion.hpp @@ -0,0 +1,300 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP +#define OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP + +#include <vector> +#include <fstream> +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/opencv_modules.hpp" +#include "opencv2/videostab/optical_flow.hpp" +#include "opencv2/videostab/motion_core.hpp" +#include "opencv2/videostab/outlier_rejection.hpp" + +#ifdef HAVE_OPENCV_CUDAIMGPROC +# include "opencv2/cudaimgproc.hpp" +#endif + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab_motion +//! @{ + +/** @brief Estimates best global motion between two 2D point clouds in the least-squares sense. + +@note Works in-place and changes input point arrays. + +@param points0 Source set of 2D points (32F). +@param points1 Destination set of 2D points (32F). +@param model Motion model (up to MM_AFFINE). +@param rmse Final root-mean-square error. +@return 3x3 2D transformation matrix (32F). + */ +CV_EXPORTS Mat estimateGlobalMotionLeastSquares( + InputOutputArray points0, InputOutputArray points1, int model = MM_AFFINE, + float *rmse = 0); + +/** @brief Estimates best global motion between two 2D point clouds robustly (using RANSAC method). + +@param points0 Source set of 2D points (32F). +@param points1 Destination set of 2D points (32F). +@param model Motion model. See cv::videostab::MotionModel. +@param params RANSAC method parameters. See videostab::RansacParams. +@param rmse Final root-mean-square error. +@param ninliers Final number of inliers. + */ +CV_EXPORTS Mat estimateGlobalMotionRansac( + InputArray points0, InputArray points1, int model = MM_AFFINE, + const RansacParams ¶ms = RansacParams::default2dMotion(MM_AFFINE), + float *rmse = 0, int *ninliers = 0); + +/** @brief Base class for all global motion estimation methods. + */ +class CV_EXPORTS MotionEstimatorBase +{ +public: + virtual ~MotionEstimatorBase() {} + + /** @brief Sets motion model. + + @param val Motion model. See cv::videostab::MotionModel. + */ + virtual void setMotionModel(MotionModel val) { motionModel_ = val; } + + /** + @return Motion model. See cv::videostab::MotionModel. + */ + virtual MotionModel motionModel() const { return motionModel_; } + + /** @brief Estimates global motion between two 2D point clouds. + + @param points0 Source set of 2D points (32F). + @param points1 Destination set of 2D points (32F). + @param ok Indicates whether motion was estimated successfully. + @return 3x3 2D transformation matrix (32F). + */ + virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0) = 0; + +protected: + MotionEstimatorBase(MotionModel model) { setMotionModel(model); } + +private: + MotionModel motionModel_; +}; + +/** @brief Describes a robust RANSAC-based global 2D motion estimation method which minimizes L2 error. + */ +class CV_EXPORTS MotionEstimatorRansacL2 : public MotionEstimatorBase +{ +public: + MotionEstimatorRansacL2(MotionModel model = MM_AFFINE); + + void setRansacParams(const RansacParams &val) { ransacParams_ = val; } + RansacParams ransacParams() const { return ransacParams_; } + + void setMinInlierRatio(float val) { minInlierRatio_ = val; } + float minInlierRatio() const { return minInlierRatio_; } + + virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0) CV_OVERRIDE; + +private: + RansacParams ransacParams_; + float minInlierRatio_; +}; + +/** @brief Describes a global 2D motion estimation method which minimizes L1 error. + +@note To be able to use this method you must build OpenCV with CLP library support. : + */ +class CV_EXPORTS MotionEstimatorL1 : public MotionEstimatorBase +{ +public: + MotionEstimatorL1(MotionModel model = MM_AFFINE); + + virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0) CV_OVERRIDE; + +private: + std::vector<double> obj_, collb_, colub_; + std::vector<double> elems_, rowlb_, rowub_; + std::vector<int> rows_, cols_; + + void set(int row, int col, double coef) + { + rows_.push_back(row); + cols_.push_back(col); + elems_.push_back(coef); + } +}; + +/** @brief Base class for global 2D motion estimation methods which take frames as input. + */ +class CV_EXPORTS ImageMotionEstimatorBase +{ +public: + virtual ~ImageMotionEstimatorBase() {} + + virtual void setMotionModel(MotionModel val) { motionModel_ = val; } + virtual MotionModel motionModel() const { return motionModel_; } + + virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) = 0; + +protected: + ImageMotionEstimatorBase(MotionModel model) { setMotionModel(model); } + +private: + MotionModel motionModel_; +}; + +class CV_EXPORTS FromFileMotionReader : public ImageMotionEstimatorBase +{ +public: + FromFileMotionReader(const String &path); + + virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) CV_OVERRIDE; + +private: + std::ifstream file_; +}; + +class CV_EXPORTS ToFileMotionWriter : public ImageMotionEstimatorBase +{ +public: + ToFileMotionWriter(const String &path, Ptr<ImageMotionEstimatorBase> estimator); + + virtual void setMotionModel(MotionModel val) CV_OVERRIDE { motionEstimator_->setMotionModel(val); } + virtual MotionModel motionModel() const CV_OVERRIDE { return motionEstimator_->motionModel(); } + + virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) CV_OVERRIDE; + +private: + std::ofstream file_; + Ptr<ImageMotionEstimatorBase> motionEstimator_; +}; + +/** @brief Describes a global 2D motion estimation method which uses keypoints detection and optical flow for +matching. + */ +class CV_EXPORTS KeypointBasedMotionEstimator : public ImageMotionEstimatorBase +{ +public: + KeypointBasedMotionEstimator(Ptr<MotionEstimatorBase> estimator); + + virtual void setMotionModel(MotionModel val) CV_OVERRIDE { motionEstimator_->setMotionModel(val); } + virtual MotionModel motionModel() const CV_OVERRIDE { return motionEstimator_->motionModel(); } + + void setDetector(Ptr<FeatureDetector> val) { detector_ = val; } + Ptr<FeatureDetector> detector() const { return detector_; } + + void setOpticalFlowEstimator(Ptr<ISparseOptFlowEstimator> val) { optFlowEstimator_ = val; } + Ptr<ISparseOptFlowEstimator> opticalFlowEstimator() const { return optFlowEstimator_; } + + void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; } + Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; } + + virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) CV_OVERRIDE; + Mat estimate(InputArray frame0, InputArray frame1, bool *ok = 0); + +private: + Ptr<MotionEstimatorBase> motionEstimator_; + Ptr<FeatureDetector> detector_; + Ptr<ISparseOptFlowEstimator> optFlowEstimator_; + Ptr<IOutlierRejector> outlierRejector_; + + std::vector<uchar> status_; + std::vector<KeyPoint> keypointsPrev_; + std::vector<Point2f> pointsPrev_, points_; + std::vector<Point2f> pointsPrevGood_, pointsGood_; +}; + +#if defined(HAVE_OPENCV_CUDAIMGPROC) && defined(HAVE_OPENCV_CUDAOPTFLOW) + +class CV_EXPORTS KeypointBasedMotionEstimatorGpu : public ImageMotionEstimatorBase +{ +public: + KeypointBasedMotionEstimatorGpu(Ptr<MotionEstimatorBase> estimator); + + virtual void setMotionModel(MotionModel val) CV_OVERRIDE { motionEstimator_->setMotionModel(val); } + virtual MotionModel motionModel() const CV_OVERRIDE { return motionEstimator_->motionModel(); } + + void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; } + Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; } + + virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) CV_OVERRIDE; + Mat estimate(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, bool *ok = 0); + +private: + Ptr<MotionEstimatorBase> motionEstimator_; + Ptr<cuda::CornersDetector> detector_; + SparsePyrLkOptFlowEstimatorGpu optFlowEstimator_; + Ptr<IOutlierRejector> outlierRejector_; + + cuda::GpuMat frame0_, grayFrame0_, frame1_; + cuda::GpuMat pointsPrev_, points_; + cuda::GpuMat status_; + + Mat hostPointsPrev_, hostPoints_; + std::vector<Point2f> hostPointsPrevTmp_, hostPointsTmp_; + std::vector<uchar> rejectionStatus_; +}; + +#endif // defined(HAVE_OPENCV_CUDAIMGPROC) && defined(HAVE_OPENCV_CUDAOPTFLOW) + +/** @brief Computes motion between two frames assuming that all the intermediate motions are known. + +@param from Source frame index. +@param to Destination frame index. +@param motions Pair-wise motions. motions[i] denotes motion from the frame i to the frame i+1 +@return Motion from the Source frame to the Destination frame. + */ +CV_EXPORTS Mat getMotion(int from, int to, const std::vector<Mat> &motions); + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/inpainting.hpp b/include/opencv2/videostab/inpainting.hpp new file mode 100644 index 0000000..9c123f0 --- /dev/null +++ b/include/opencv2/videostab/inpainting.hpp @@ -0,0 +1,212 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_INPAINTINT_HPP +#define OPENCV_VIDEOSTAB_INPAINTINT_HPP + +#include <vector> +#include "opencv2/core.hpp" +#include "opencv2/videostab/optical_flow.hpp" +#include "opencv2/videostab/fast_marching.hpp" +#include "opencv2/videostab/global_motion.hpp" +#include "opencv2/photo.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS InpainterBase +{ +public: + InpainterBase() + : radius_(0), motionModel_(MM_UNKNOWN), frames_(0), motions_(0), + stabilizedFrames_(0), stabilizationMotions_(0) {} + + virtual ~InpainterBase() {} + + virtual void setRadius(int val) { radius_ = val; } + virtual int radius() const { return radius_; } + + virtual void setMotionModel(MotionModel val) { motionModel_ = val; } + virtual MotionModel motionModel() const { return motionModel_; } + + virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0; + + + // data from stabilizer + + virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; } + virtual const std::vector<Mat>& frames() const { return *frames_; } + + virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; } + virtual const std::vector<Mat>& motions() const { return *motions_; } + + virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; } + virtual const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; } + + virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; } + virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; } + +protected: + int radius_; + MotionModel motionModel_; + const std::vector<Mat> *frames_; + const std::vector<Mat> *motions_; + const std::vector<Mat> *stabilizedFrames_; + const std::vector<Mat> *stabilizationMotions_; +}; + +class CV_EXPORTS NullInpainter : public InpainterBase +{ +public: + virtual void inpaint(int /*idx*/, Mat &/*frame*/, Mat &/*mask*/) CV_OVERRIDE {} +}; + +class CV_EXPORTS InpaintingPipeline : public InpainterBase +{ +public: + void pushBack(Ptr<InpainterBase> inpainter) { inpainters_.push_back(inpainter); } + bool empty() const { return inpainters_.empty(); } + + virtual void setRadius(int val) CV_OVERRIDE; + virtual void setMotionModel(MotionModel val) CV_OVERRIDE; + virtual void setFrames(const std::vector<Mat> &val) CV_OVERRIDE; + virtual void setMotions(const std::vector<Mat> &val) CV_OVERRIDE; + virtual void setStabilizedFrames(const std::vector<Mat> &val) CV_OVERRIDE; + virtual void setStabilizationMotions(const std::vector<Mat> &val) CV_OVERRIDE; + + virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE; + +private: + std::vector<Ptr<InpainterBase> > inpainters_; +}; + +class CV_EXPORTS ConsistentMosaicInpainter : public InpainterBase +{ +public: + ConsistentMosaicInpainter(); + + void setStdevThresh(float val) { stdevThresh_ = val; } + float stdevThresh() const { return stdevThresh_; } + + virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE; + +private: + float stdevThresh_; +}; + +class CV_EXPORTS MotionInpainter : public InpainterBase +{ +public: + MotionInpainter(); + + void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; } + Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; } + + void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; } + float flowErrorThreshold() const { return flowErrorThreshold_; } + + void setDistThreshold(float val) { distThresh_ = val; } + float distThresh() const { return distThresh_; } + + void setBorderMode(int val) { borderMode_ = val; } + int borderMode() const { return borderMode_; } + + virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE; + +private: + FastMarchingMethod fmm_; + Ptr<IDenseOptFlowEstimator> optFlowEstimator_; + float flowErrorThreshold_; + float distThresh_; + int borderMode_; + + Mat frame1_, transformedFrame1_; + Mat_<uchar> grayFrame_, transformedGrayFrame1_; + Mat_<uchar> mask1_, transformedMask1_; + Mat_<float> flowX_, flowY_, flowErrors_; + Mat_<uchar> flowMask_; +}; + +class CV_EXPORTS ColorAverageInpainter : public InpainterBase +{ +public: + virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE; + +private: + FastMarchingMethod fmm_; +}; + +class CV_EXPORTS ColorInpainter : public InpainterBase +{ +public: + ColorInpainter(int method = INPAINT_TELEA, double radius = 2.); + + virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE; + +private: + int method_; + double radius_; + Mat invMask_; +}; + +inline ColorInpainter::ColorInpainter(int _method, double _radius) + : method_(_method), radius_(_radius) {} + +CV_EXPORTS void calcFlowMask( + const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError, + const Mat &mask0, const Mat &mask1, Mat &flowMask); + +CV_EXPORTS void completeFrameAccordingToFlow( + const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1, + float distThresh, Mat& frame0, Mat &mask0); + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/log.hpp b/include/opencv2/videostab/log.hpp new file mode 100644 index 0000000..73e7049 --- /dev/null +++ b/include/opencv2/videostab/log.hpp @@ -0,0 +1,80 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_LOG_HPP +#define OPENCV_VIDEOSTAB_LOG_HPP + +#include "opencv2/core.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS ILog +{ +public: + virtual ~ILog() {} + virtual void print(const char *format, ...) = 0; +}; + +class CV_EXPORTS NullLog : public ILog +{ +public: + virtual void print(const char * /*format*/, ...) CV_OVERRIDE {} +}; + +class CV_EXPORTS LogToStdout : public ILog +{ +public: + virtual void print(const char *format, ...) CV_OVERRIDE; +}; + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/motion_core.hpp b/include/opencv2/videostab/motion_core.hpp new file mode 100644 index 0000000..4525cc7 --- /dev/null +++ b/include/opencv2/videostab/motion_core.hpp @@ -0,0 +1,129 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_MOTION_CORE_HPP +#define OPENCV_VIDEOSTAB_MOTION_CORE_HPP + +#include <cmath> +#include "opencv2/core.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab_motion +//! @{ + +/** @brief Describes motion model between two point clouds. + */ +enum MotionModel +{ + MM_TRANSLATION = 0, + MM_TRANSLATION_AND_SCALE = 1, + MM_ROTATION = 2, + MM_RIGID = 3, + MM_SIMILARITY = 4, + MM_AFFINE = 5, + MM_HOMOGRAPHY = 6, + MM_UNKNOWN = 7 +}; + +/** @brief Describes RANSAC method parameters. + */ +struct CV_EXPORTS RansacParams +{ + int size; //!< subset size + float thresh; //!< max error to classify as inlier + float eps; //!< max outliers ratio + float prob; //!< probability of success + + RansacParams() : size(0), thresh(0), eps(0), prob(0) {} + /** @brief Constructor + @param size Subset size. + @param thresh Maximum re-projection error value to classify as inlier. + @param eps Maximum ratio of incorrect correspondences. + @param prob Required success probability. + */ + RansacParams(int size, float thresh, float eps, float prob); + + /** + @return Number of iterations that'll be performed by RANSAC method. + */ + int niters() const + { + return static_cast<int>( + std::ceil(std::log(1 - prob) / std::log(1 - std::pow(1 - eps, size)))); + } + + /** + @param model Motion model. See cv::videostab::MotionModel. + @return Default RANSAC method parameters for the given motion model. + */ + static RansacParams default2dMotion(MotionModel model) + { + CV_Assert(model < MM_UNKNOWN); + if (model == MM_TRANSLATION) + return RansacParams(1, 0.5f, 0.5f, 0.99f); + if (model == MM_TRANSLATION_AND_SCALE) + return RansacParams(2, 0.5f, 0.5f, 0.99f); + if (model == MM_ROTATION) + return RansacParams(1, 0.5f, 0.5f, 0.99f); + if (model == MM_RIGID) + return RansacParams(2, 0.5f, 0.5f, 0.99f); + if (model == MM_SIMILARITY) + return RansacParams(2, 0.5f, 0.5f, 0.99f); + if (model == MM_AFFINE) + return RansacParams(3, 0.5f, 0.5f, 0.99f); + return RansacParams(4, 0.5f, 0.5f, 0.99f); + } +}; + +inline RansacParams::RansacParams(int _size, float _thresh, float _eps, float _prob) + : size(_size), thresh(_thresh), eps(_eps), prob(_prob) {} + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/motion_stabilizing.hpp b/include/opencv2/videostab/motion_stabilizing.hpp new file mode 100644 index 0000000..c50095b --- /dev/null +++ b/include/opencv2/videostab/motion_stabilizing.hpp @@ -0,0 +1,174 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP +#define OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP + +#include <vector> +#include <utility> +#include "opencv2/core.hpp" +#include "opencv2/videostab/global_motion.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab_motion +//! @{ + +class CV_EXPORTS IMotionStabilizer +{ +public: + virtual ~IMotionStabilizer() {} + + //! assumes that [0, size-1) is in or equals to [range.first, range.second) + virtual void stabilize( + int size, const std::vector<Mat> &motions, std::pair<int,int> range, + Mat *stabilizationMotions) = 0; +}; + +class CV_EXPORTS MotionStabilizationPipeline : public IMotionStabilizer +{ +public: + void pushBack(Ptr<IMotionStabilizer> stabilizer) { stabilizers_.push_back(stabilizer); } + bool empty() const { return stabilizers_.empty(); } + + virtual void stabilize( + int size, const std::vector<Mat> &motions, std::pair<int,int> range, + Mat *stabilizationMotions) CV_OVERRIDE; + +private: + std::vector<Ptr<IMotionStabilizer> > stabilizers_; +}; + +class CV_EXPORTS MotionFilterBase : public IMotionStabilizer +{ +public: + virtual ~MotionFilterBase() {} + + virtual Mat stabilize( + int idx, const std::vector<Mat> &motions, std::pair<int,int> range) = 0; + + virtual void stabilize( + int size, const std::vector<Mat> &motions, std::pair<int,int> range, + Mat *stabilizationMotions) CV_OVERRIDE; +}; + +class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase +{ +public: + GaussianMotionFilter(int radius = 15, float stdev = -1.f); + + void setParams(int radius, float stdev = -1.f); + int radius() const { return radius_; } + float stdev() const { return stdev_; } + + virtual Mat stabilize( + int idx, const std::vector<Mat> &motions, std::pair<int,int> range) CV_OVERRIDE; + +private: + int radius_; + float stdev_; + std::vector<float> weight_; +}; + +inline GaussianMotionFilter::GaussianMotionFilter(int _radius, float _stdev) { setParams(_radius, _stdev); } + +class CV_EXPORTS LpMotionStabilizer : public IMotionStabilizer +{ +public: + LpMotionStabilizer(MotionModel model = MM_SIMILARITY); + + void setMotionModel(MotionModel val) { model_ = val; } + MotionModel motionModel() const { return model_; } + + void setFrameSize(Size val) { frameSize_ = val; } + Size frameSize() const { return frameSize_; } + + void setTrimRatio(float val) { trimRatio_ = val; } + float trimRatio() const { return trimRatio_; } + + void setWeight1(float val) { w1_ = val; } + float weight1() const { return w1_; } + + void setWeight2(float val) { w2_ = val; } + float weight2() const { return w2_; } + + void setWeight3(float val) { w3_ = val; } + float weight3() const { return w3_; } + + void setWeight4(float val) { w4_ = val; } + float weight4() const { return w4_; } + + virtual void stabilize( + int size, const std::vector<Mat> &motions, std::pair<int,int> range, + Mat *stabilizationMotions) CV_OVERRIDE; + +private: + MotionModel model_; + Size frameSize_; + float trimRatio_; + float w1_, w2_, w3_, w4_; + + std::vector<double> obj_, collb_, colub_; + std::vector<int> rows_, cols_; + std::vector<double> elems_, rowlb_, rowub_; + + void set(int row, int col, double coef) + { + rows_.push_back(row); + cols_.push_back(col); + elems_.push_back(coef); + } +}; + +CV_EXPORTS Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio); + +CV_EXPORTS float estimateOptimalTrimRatio(const Mat &M, Size size); + +//! @} + +} // namespace videostab +} // namespace + +#endif diff --git a/include/opencv2/videostab/optical_flow.hpp b/include/opencv2/videostab/optical_flow.hpp new file mode 100644 index 0000000..5e06941 --- /dev/null +++ b/include/opencv2/videostab/optical_flow.hpp @@ -0,0 +1,150 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP +#define OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP + +#include "opencv2/core.hpp" +#include "opencv2/opencv_modules.hpp" + +#ifdef HAVE_OPENCV_CUDAOPTFLOW + #include "opencv2/cudaoptflow.hpp" +#endif + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS ISparseOptFlowEstimator +{ +public: + virtual ~ISparseOptFlowEstimator() {} + virtual void run( + InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1, + OutputArray status, OutputArray errors) = 0; +}; + +class CV_EXPORTS IDenseOptFlowEstimator +{ +public: + virtual ~IDenseOptFlowEstimator() {} + virtual void run( + InputArray frame0, InputArray frame1, InputOutputArray flowX, InputOutputArray flowY, + OutputArray errors) = 0; +}; + +class CV_EXPORTS PyrLkOptFlowEstimatorBase +{ +public: + PyrLkOptFlowEstimatorBase() { setWinSize(Size(21, 21)); setMaxLevel(3); } + + virtual void setWinSize(Size val) { winSize_ = val; } + virtual Size winSize() const { return winSize_; } + + virtual void setMaxLevel(int val) { maxLevel_ = val; } + virtual int maxLevel() const { return maxLevel_; } + virtual ~PyrLkOptFlowEstimatorBase() {} + +protected: + Size winSize_; + int maxLevel_; +}; + +class CV_EXPORTS SparsePyrLkOptFlowEstimator + : public PyrLkOptFlowEstimatorBase, public ISparseOptFlowEstimator +{ +public: + virtual void run( + InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1, + OutputArray status, OutputArray errors) CV_OVERRIDE; +}; + +#ifdef HAVE_OPENCV_CUDAOPTFLOW + +class CV_EXPORTS SparsePyrLkOptFlowEstimatorGpu + : public PyrLkOptFlowEstimatorBase, public ISparseOptFlowEstimator +{ +public: + SparsePyrLkOptFlowEstimatorGpu(); + + virtual void run( + InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1, + OutputArray status, OutputArray errors) CV_OVERRIDE; + + void run(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1, + cuda::GpuMat &status, cuda::GpuMat &errors); + + void run(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1, + cuda::GpuMat &status); + +private: + Ptr<cuda::SparsePyrLKOpticalFlow> optFlowEstimator_; + cuda::GpuMat frame0_, frame1_, points0_, points1_, status_, errors_; +}; + +class CV_EXPORTS DensePyrLkOptFlowEstimatorGpu + : public PyrLkOptFlowEstimatorBase, public IDenseOptFlowEstimator +{ +public: + DensePyrLkOptFlowEstimatorGpu(); + + virtual void run( + InputArray frame0, InputArray frame1, InputOutputArray flowX, InputOutputArray flowY, + OutputArray errors) CV_OVERRIDE; + +private: + Ptr<cuda::DensePyrLKOpticalFlow> optFlowEstimator_; + cuda::GpuMat frame0_, frame1_, flowX_, flowY_, errors_; +}; + +#endif + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/outlier_rejection.hpp b/include/opencv2/videostab/outlier_rejection.hpp new file mode 100644 index 0000000..1d29896 --- /dev/null +++ b/include/opencv2/videostab/outlier_rejection.hpp @@ -0,0 +1,101 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP +#define OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP + +#include <vector> +#include "opencv2/core.hpp" +#include "opencv2/videostab/motion_core.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS IOutlierRejector +{ +public: + virtual ~IOutlierRejector() {} + + virtual void process( + Size frameSize, InputArray points0, InputArray points1, OutputArray mask) = 0; +}; + +class CV_EXPORTS NullOutlierRejector : public IOutlierRejector +{ +public: + virtual void process( + Size frameSize, InputArray points0, InputArray points1, OutputArray mask) CV_OVERRIDE; +}; + +class CV_EXPORTS TranslationBasedLocalOutlierRejector : public IOutlierRejector +{ +public: + TranslationBasedLocalOutlierRejector(); + + void setCellSize(Size val) { cellSize_ = val; } + Size cellSize() const { return cellSize_; } + + void setRansacParams(RansacParams val) { ransacParams_ = val; } + RansacParams ransacParams() const { return ransacParams_; } + + virtual void process( + Size frameSize, InputArray points0, InputArray points1, OutputArray mask) CV_OVERRIDE; + +private: + Size cellSize_; + RansacParams ransacParams_; + + typedef std::vector<int> Cell; + std::vector<Cell> grid_; +}; + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/ring_buffer.hpp b/include/opencv2/videostab/ring_buffer.hpp new file mode 100644 index 0000000..55d5244 --- /dev/null +++ b/include/opencv2/videostab/ring_buffer.hpp @@ -0,0 +1,72 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_RING_BUFFER_HPP +#define OPENCV_VIDEOSTAB_RING_BUFFER_HPP + +#include <vector> +#include "opencv2/imgproc.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +template <typename T> inline T& at(int idx, std::vector<T> &items) +{ + return items[cv::borderInterpolate(idx, static_cast<int>(items.size()), cv::BORDER_WRAP)]; +} + +template <typename T> inline const T& at(int idx, const std::vector<T> &items) +{ + return items[cv::borderInterpolate(idx, static_cast<int>(items.size()), cv::BORDER_WRAP)]; +} + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/stabilizer.hpp b/include/opencv2/videostab/stabilizer.hpp new file mode 100644 index 0000000..634a0aa --- /dev/null +++ b/include/opencv2/videostab/stabilizer.hpp @@ -0,0 +1,200 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_STABILIZER_HPP +#define OPENCV_VIDEOSTAB_STABILIZER_HPP + +#include <vector> +#include <ctime> +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/videostab/global_motion.hpp" +#include "opencv2/videostab/motion_stabilizing.hpp" +#include "opencv2/videostab/frame_source.hpp" +#include "opencv2/videostab/log.hpp" +#include "opencv2/videostab/inpainting.hpp" +#include "opencv2/videostab/deblurring.hpp" +#include "opencv2/videostab/wobble_suppression.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS StabilizerBase +{ +public: + virtual ~StabilizerBase() {} + + void setLog(Ptr<ILog> ilog) { log_ = ilog; } + Ptr<ILog> log() const { return log_; } + + void setRadius(int val) { radius_ = val; } + int radius() const { return radius_; } + + void setFrameSource(Ptr<IFrameSource> val) { frameSource_ = val; } + Ptr<IFrameSource> frameSource() const { return frameSource_; } + + void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; } + Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; } + + void setDeblurer(Ptr<DeblurerBase> val) { deblurer_ = val; } + Ptr<DeblurerBase> deblurrer() const { return deblurer_; } + + void setTrimRatio(float val) { trimRatio_ = val; } + float trimRatio() const { return trimRatio_; } + + void setCorrectionForInclusion(bool val) { doCorrectionForInclusion_ = val; } + bool doCorrectionForInclusion() const { return doCorrectionForInclusion_; } + + void setBorderMode(int val) { borderMode_ = val; } + int borderMode() const { return borderMode_; } + + void setInpainter(Ptr<InpainterBase> val) { inpainter_ = val; } + Ptr<InpainterBase> inpainter() const { return inpainter_; } + +protected: + StabilizerBase(); + + void reset(); + Mat nextStabilizedFrame(); + bool doOneIteration(); + virtual void setUp(const Mat &firstFrame); + virtual Mat estimateMotion() = 0; + virtual Mat estimateStabilizationMotion() = 0; + void stabilizeFrame(); + virtual Mat postProcessFrame(const Mat &frame); + void logProcessingTime(); + + Ptr<ILog> log_; + Ptr<IFrameSource> frameSource_; + Ptr<ImageMotionEstimatorBase> motionEstimator_; + Ptr<DeblurerBase> deblurer_; + Ptr<InpainterBase> inpainter_; + int radius_; + float trimRatio_; + bool doCorrectionForInclusion_; + int borderMode_; + + Size frameSize_; + Mat frameMask_; + int curPos_; + int curStabilizedPos_; + bool doDeblurring_; + Mat preProcessedFrame_; + bool doInpainting_; + Mat inpaintingMask_; + Mat finalFrame_; + std::vector<Mat> frames_; + std::vector<Mat> motions_; // motions_[i] is the motion from i-th to i+1-th frame + std::vector<float> blurrinessRates_; + std::vector<Mat> stabilizedFrames_; + std::vector<Mat> stabilizedMasks_; + std::vector<Mat> stabilizationMotions_; + clock_t processingStartTime_; +}; + +class CV_EXPORTS OnePassStabilizer : public StabilizerBase, public IFrameSource +{ +public: + OnePassStabilizer(); + + void setMotionFilter(Ptr<MotionFilterBase> val) { motionFilter_ = val; } + Ptr<MotionFilterBase> motionFilter() const { return motionFilter_; } + + virtual void reset() CV_OVERRIDE; + virtual Mat nextFrame() CV_OVERRIDE { return nextStabilizedFrame(); } + +protected: + virtual void setUp(const Mat &firstFrame) CV_OVERRIDE; + virtual Mat estimateMotion() CV_OVERRIDE; + virtual Mat estimateStabilizationMotion() CV_OVERRIDE; + virtual Mat postProcessFrame(const Mat &frame) CV_OVERRIDE; + + Ptr<MotionFilterBase> motionFilter_; +}; + +class CV_EXPORTS TwoPassStabilizer : public StabilizerBase, public IFrameSource +{ +public: + TwoPassStabilizer(); + + void setMotionStabilizer(Ptr<IMotionStabilizer> val) { motionStabilizer_ = val; } + Ptr<IMotionStabilizer> motionStabilizer() const { return motionStabilizer_; } + + void setWobbleSuppressor(Ptr<WobbleSuppressorBase> val) { wobbleSuppressor_ = val; } + Ptr<WobbleSuppressorBase> wobbleSuppressor() const { return wobbleSuppressor_; } + + void setEstimateTrimRatio(bool val) { mustEstTrimRatio_ = val; } + bool mustEstimateTrimaRatio() const { return mustEstTrimRatio_; } + + virtual void reset() CV_OVERRIDE; + virtual Mat nextFrame() CV_OVERRIDE; + +protected: + void runPrePassIfNecessary(); + + virtual void setUp(const Mat &firstFrame) CV_OVERRIDE; + virtual Mat estimateMotion() CV_OVERRIDE; + virtual Mat estimateStabilizationMotion() CV_OVERRIDE; + virtual Mat postProcessFrame(const Mat &frame) CV_OVERRIDE; + + Ptr<IMotionStabilizer> motionStabilizer_; + Ptr<WobbleSuppressorBase> wobbleSuppressor_; + bool mustEstTrimRatio_; + + int frameCount_; + bool isPrePassDone_; + bool doWobbleSuppression_; + std::vector<Mat> motions2_; + Mat suppressedFrame_; +}; + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/videostab/wobble_suppression.hpp b/include/opencv2/videostab/wobble_suppression.hpp new file mode 100644 index 0000000..d60ae6d --- /dev/null +++ b/include/opencv2/videostab/wobble_suppression.hpp @@ -0,0 +1,140 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP +#define OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP + +#include <vector> +#include "opencv2/core.hpp" +#include "opencv2/core/cuda.hpp" +#include "opencv2/videostab/global_motion.hpp" +#include "opencv2/videostab/log.hpp" + +namespace cv +{ +namespace videostab +{ + +//! @addtogroup videostab +//! @{ + +class CV_EXPORTS WobbleSuppressorBase +{ +public: + WobbleSuppressorBase(); + + virtual ~WobbleSuppressorBase() {} + + void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; } + Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; } + + virtual void suppress(int idx, const Mat &frame, Mat &result) = 0; + + + // data from stabilizer + + virtual void setFrameCount(int val) { frameCount_ = val; } + virtual int frameCount() const { return frameCount_; } + + virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; } + virtual const std::vector<Mat>& motions() const { return *motions_; } + + virtual void setMotions2(const std::vector<Mat> &val) { motions2_ = &val; } + virtual const std::vector<Mat>& motions2() const { return *motions2_; } + + virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; } + virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; } + +protected: + Ptr<ImageMotionEstimatorBase> motionEstimator_; + int frameCount_; + const std::vector<Mat> *motions_; + const std::vector<Mat> *motions2_; + const std::vector<Mat> *stabilizationMotions_; +}; + +class CV_EXPORTS NullWobbleSuppressor : public WobbleSuppressorBase +{ +public: + virtual void suppress(int idx, const Mat &frame, Mat &result) CV_OVERRIDE; +}; + +class CV_EXPORTS MoreAccurateMotionWobbleSuppressorBase : public WobbleSuppressorBase +{ +public: + virtual void setPeriod(int val) { period_ = val; } + virtual int period() const { return period_; } + +protected: + MoreAccurateMotionWobbleSuppressorBase() { setPeriod(30); } + + int period_; +}; + +class CV_EXPORTS MoreAccurateMotionWobbleSuppressor : public MoreAccurateMotionWobbleSuppressorBase +{ +public: + virtual void suppress(int idx, const Mat &frame, Mat &result) CV_OVERRIDE; + +private: + Mat_<float> mapx_, mapy_; +}; + +#if defined(HAVE_OPENCV_CUDAWARPING) +class CV_EXPORTS MoreAccurateMotionWobbleSuppressorGpu : public MoreAccurateMotionWobbleSuppressorBase +{ +public: + void suppress(int idx, const cuda::GpuMat &frame, cuda::GpuMat &result); + virtual void suppress(int idx, const Mat &frame, Mat &result) CV_OVERRIDE; + +private: + cuda::GpuMat frameDevice_, resultDevice_; + cuda::GpuMat mapx_, mapy_; +}; +#endif + +//! @} + +} // namespace videostab +} // namespace cv + +#endif diff --git a/include/opencv2/ximgproc.hpp b/include/opencv2/ximgproc.hpp new file mode 100644 index 0000000..2853dca --- /dev/null +++ b/include/opencv2/ximgproc.hpp @@ -0,0 +1,177 @@ +/* + * 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. + */ + +#ifndef __OPENCV_XIMGPROC_HPP__ +#define __OPENCV_XIMGPROC_HPP__ + +#include "ximgproc/edge_filter.hpp" +#include "ximgproc/disparity_filter.hpp" +#include "ximgproc/sparse_match_interpolator.hpp" +#include "ximgproc/structured_edge_detection.hpp" +#include "ximgproc/edgeboxes.hpp" +#include "ximgproc/seeds.hpp" +#include "ximgproc/segmentation.hpp" +#include "ximgproc/fast_hough_transform.hpp" +#include "ximgproc/estimated_covariance.hpp" +#include "ximgproc/weighted_median_filter.hpp" +#include "ximgproc/slic.hpp" +#include "ximgproc/lsc.hpp" +#include "ximgproc/paillou_filter.hpp" +#include "ximgproc/fast_line_detector.hpp" +#include "ximgproc/deriche_filter.hpp" +#include "ximgproc/peilin.hpp" +#include "ximgproc/fourier_descriptors.hpp" +#include "ximgproc/ridgefilter.hpp" +#include "ximgproc/brightedges.hpp" + + +/** @defgroup ximgproc Extended Image Processing + @{ + @defgroup ximgproc_edge Structured forests for fast edge detection + +This module contains implementations of modern structured edge detection algorithms, +i.e. algorithms which somehow takes into account pixel affinities in natural images. + + @defgroup ximgproc_edgeboxes EdgeBoxes + + @defgroup ximgproc_filters Filters + + @defgroup ximgproc_superpixel Superpixels + + @defgroup ximgproc_segmentation Image segmentation + + @defgroup ximgproc_fast_line_detector Fast line detector + + @defgroup ximgproc_fourier Fourier descriptors + @} +*/ + +namespace cv +{ +namespace ximgproc +{ + +enum ThinningTypes{ + THINNING_ZHANGSUEN = 0, // Thinning technique of Zhang-Suen + THINNING_GUOHALL = 1 // Thinning technique of Guo-Hall +}; + +/** +* @brief Specifies the binarization method to use in cv::ximgproc::niBlackThreshold +*/ +enum LocalBinarizationMethods{ + BINARIZATION_NIBLACK = 0, //!< Classic Niblack binarization. See @cite Niblack1985 . + BINARIZATION_SAUVOLA = 1, //!< Sauvola's technique. See @cite Sauvola1997 . + BINARIZATION_WOLF = 2, //!< Wolf's technique. See @cite Wolf2004 . + BINARIZATION_NICK = 3 //!< NICK technique. See @cite Khurshid2009 . +}; + +//! @addtogroup ximgproc +//! @{ + +/** @brief Performs thresholding on input images using Niblack's technique or some of the +popular variations it inspired. + +The function transforms a grayscale image to a binary image according to the formulae: +- **THRESH_BINARY** + \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f] +- **THRESH_BINARY_INV** + \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f] +where \f$T(x,y)\f$ is a threshold calculated individually for each pixel. + +The threshold value \f$T(x, y)\f$ is determined based on the binarization method chosen. For +classic Niblack, it is the mean minus \f$ k \f$ times standard deviation of +\f$\texttt{blockSize} \times\texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$. + +The function can't process the image in-place. + +@param _src Source 8-bit single-channel image. +@param _dst Destination image of the same size and the same type as src. +@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied, +used with the THRESH_BINARY and THRESH_BINARY_INV thresholding types. +@param type Thresholding type, see cv::ThresholdTypes. +@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value +for the pixel: 3, 5, 7, and so on. +@param k The user-adjustable parameter used by Niblack and inspired techniques. For Niblack, this is +normally a value between 0 and 1 that is multiplied with the standard deviation and subtracted from +the mean. +@param binarizationMethod Binarization method to use. By default, Niblack's technique is used. +Other techniques can be specified, see cv::ximgproc::LocalBinarizationMethods. + +@sa threshold, adaptiveThreshold + */ +CV_EXPORTS_W void niBlackThreshold( InputArray _src, OutputArray _dst, + double maxValue, int type, + int blockSize, double k, int binarizationMethod = BINARIZATION_NIBLACK ); + +/** @brief Applies a binary blob thinning operation, to achieve a skeletization of the input image. + +The function transforms a binary blob image into a skeletized form using the technique of Zhang-Suen. + +@param src Source 8-bit single-channel image, containing binary blobs, with blobs having 255 pixel values. +@param dst Destination image of the same size and the same type as src. The function can work in-place. +@param thinningType Value that defines which thinning algorithm should be used. See cv::ximgproc::ThinningTypes + */ +CV_EXPORTS_W void thinning( InputArray src, OutputArray dst, int thinningType = THINNING_ZHANGSUEN); + +/** @brief Performs anisotropic diffusian on an image. + + The function applies Perona-Malik anisotropic diffusion to an image. This is the solution to the partial differential equation: + + \f[{\frac {\partial I}{\partial t}}={\mathrm {div}}\left(c(x,y,t)\nabla I\right)=\nabla c\cdot \nabla I+c(x,y,t)\Delta I\f] + + Suggested functions for c(x,y,t) are: + + \f[c\left(\|\nabla I\|\right)=e^{{-\left(\|\nabla I\|/K\right)^{2}}}\f] + + or + + \f[ c\left(\|\nabla I\|\right)={\frac {1}{1+\left({\frac {\|\nabla I\|}{K}}\right)^{2}}} \f] + + @param src Source image with 3 channels. + @param dst Destination image of the same size and the same number of channels as src . + @param alpha The amount of time to step forward by on each iteration (normally, it's between 0 and 1). + @param K sensitivity to the edges + @param niters The number of iterations +*/ +CV_EXPORTS_W void anisotropicDiffusion(InputArray src, OutputArray dst, float alpha, float K, int niters ); + +//! @} + +} +} + +#endif // __OPENCV_XIMGPROC_HPP__ diff --git a/include/opencv2/ximgproc/brightedges.hpp b/include/opencv2/ximgproc/brightedges.hpp new file mode 100644 index 0000000..fa30911 --- /dev/null +++ b/include/opencv2/ximgproc/brightedges.hpp @@ -0,0 +1,50 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2017, IBM Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// @Authors +// Marc Fiammante marc.fiammante@fr.ibm.com +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of OpenCV Foundation or contributors may not 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 the OpenCV Foundation 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. +// +//M*/ +#include "opencv2/core.hpp" +namespace cv +{ + namespace ximgproc { + CV_EXPORTS_W void BrightEdges(Mat &_original, Mat &_edgeview, int contrast = 1, int shortrange = 3, int longrange = 9); + } +} \ No newline at end of file diff --git a/include/opencv2/ximgproc/deriche_filter.hpp b/include/opencv2/ximgproc/deriche_filter.hpp new file mode 100644 index 0000000..26d3b67 --- /dev/null +++ b/include/opencv2/ximgproc/deriche_filter.hpp @@ -0,0 +1,77 @@ +/* + * 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. + */ + +#ifndef __OPENCV_DERICHEFILTER_HPP__ +#define __OPENCV_DERICHEFILTER_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv { +namespace ximgproc { + +//! @addtogroup ximgproc_filters +//! @{ + +/** +* @brief Applies Y Deriche filter to an image. +* +* For more details about this implementation, please see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.476.5736&rep=rep1&type=pdf +* +* @param op Source 8-bit or 16bit image, 1-channel or 3-channel image. +* @param dst result CV_32FC image with same number of channel than _op. +* @param alpha double see paper +* @param omega double see paper +* +*/ +CV_EXPORTS_W void GradientDericheY(InputArray op, OutputArray dst, double alpha,double omega); +/** +* @brief Applies X Deriche filter to an image. +* +* For more details about this implementation, please see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.476.5736&rep=rep1&type=pdf +* +* @param op Source 8-bit or 16bit image, 1-channel or 3-channel image. +* @param dst result CV_32FC image with same number of channel than _op. +* @param alpha double see paper +* @param omega double see paper +* +*/ +CV_EXPORTS_W void GradientDericheX(InputArray op, OutputArray dst, double alpha,double omega); + +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/disparity_filter.hpp b/include/opencv2/ximgproc/disparity_filter.hpp new file mode 100644 index 0000000..b738436 --- /dev/null +++ b/include/opencv2/ximgproc/disparity_filter.hpp @@ -0,0 +1,210 @@ +/* + * 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. + */ + +#ifndef __OPENCV_DISPARITYFILTER_HPP__ +#define __OPENCV_DISPARITYFILTER_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> +#include <opencv2/calib3d.hpp> + +namespace cv { +namespace ximgproc { + +//! @addtogroup ximgproc_filters +//! @{ + +/** @brief Main interface for all disparity map filters. + */ +class CV_EXPORTS_W DisparityFilter : public Algorithm +{ +public: + + /** @brief Apply filtering to the disparity map. + + @param disparity_map_left disparity map of the left view, 1 channel, CV_16S type. Implicitly assumes that disparity + values are scaled by 16 (one-pixel disparity corresponds to the value of 16 in the disparity map). Disparity map + can have any resolution, it will be automatically resized to fit left_view resolution. + + @param left_view left view of the original stereo-pair to guide the filtering process, 8-bit single-channel + or three-channel image. + + @param filtered_disparity_map output disparity map. + + @param disparity_map_right optional argument, some implementations might also use the disparity map + of the right view to compute confidence maps, for instance. + + @param ROI region of the disparity map to filter. Optional, usually it should be set automatically. + + @param right_view optional argument, some implementations might also use the right view of the original + stereo-pair. + */ + CV_WRAP virtual void filter(InputArray disparity_map_left, InputArray left_view, OutputArray filtered_disparity_map, InputArray disparity_map_right = Mat(), Rect ROI = Rect(), InputArray right_view = Mat()) = 0; +}; + +/** @brief Disparity map filter based on Weighted Least Squares filter (in form of Fast Global Smoother that +is a lot faster than traditional Weighted Least Squares filter implementations) and optional use of +left-right-consistency-based confidence to refine the results in half-occlusions and uniform areas. + */ +class CV_EXPORTS_W DisparityWLSFilter : public DisparityFilter +{ +public: + /** filter parameters */ + + /** @brief Lambda is a parameter defining the amount of regularization during filtering. Larger values force + filtered disparity map edges to adhere more to source image edges. Typical value is 8000. + */ + CV_WRAP virtual double getLambda() = 0; + /** @see getLambda */ + CV_WRAP virtual void setLambda(double _lambda) = 0; + /** @brief SigmaColor is a parameter defining how sensitive the filtering process is to source image edges. + Large values can lead to disparity leakage through low-contrast edges. Small values can make the filter too + sensitive to noise and textures in the source image. Typical values range from 0.8 to 2.0. + */ + CV_WRAP virtual double getSigmaColor() = 0; + /** @see getSigmaColor */ + CV_WRAP virtual void setSigmaColor(double _sigma_color) = 0; + + /** confidence-related parameters */ + + /** @brief LRCthresh is a threshold of disparity difference used in left-right-consistency check during + confidence map computation. The default value of 24 (1.5 pixels) is virtually always good enough. + */ + CV_WRAP virtual int getLRCthresh() = 0; + /** @see getLRCthresh */ + CV_WRAP virtual void setLRCthresh(int _LRC_thresh) = 0; + /** @brief DepthDiscontinuityRadius is a parameter used in confidence computation. It defines the size of + low-confidence regions around depth discontinuities. + */ + CV_WRAP virtual int getDepthDiscontinuityRadius() = 0; + /** @see getDepthDiscontinuityRadius */ + CV_WRAP virtual void setDepthDiscontinuityRadius(int _disc_radius) = 0; + /** @brief Get the confidence map that was used in the last filter call. It is a CV_32F one-channel image + with values ranging from 0.0 (totally untrusted regions of the raw disparity map) to 255.0 (regions containing + correct disparity values with a high degree of confidence). + */ + CV_WRAP virtual Mat getConfidenceMap() = 0; + /** @brief Get the ROI used in the last filter call + */ + CV_WRAP virtual Rect getROI() = 0; +}; + +/** @brief Convenience factory method that creates an instance of DisparityWLSFilter and sets up all the relevant +filter parameters automatically based on the matcher instance. Currently supports only StereoBM and StereoSGBM. + +@param matcher_left stereo matcher instance that will be used with the filter +*/ +CV_EXPORTS_W +Ptr<DisparityWLSFilter> createDisparityWLSFilter(Ptr<StereoMatcher> matcher_left); + +/** @brief Convenience method to set up the matcher for computing the right-view disparity map +that is required in case of filtering with confidence. + +@param matcher_left main stereo matcher instance that will be used with the filter +*/ +CV_EXPORTS_W +Ptr<StereoMatcher> createRightMatcher(Ptr<StereoMatcher> matcher_left); + +/** @brief More generic factory method, create instance of DisparityWLSFilter and execute basic +initialization routines. When using this method you will need to set-up the ROI, matchers and +other parameters by yourself. + +@param use_confidence filtering with confidence requires two disparity maps (for the left and right views) and is +approximately two times slower. However, quality is typically significantly better. +*/ +CV_EXPORTS_W +Ptr<DisparityWLSFilter> createDisparityWLSFilterGeneric(bool use_confidence); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Function for reading ground truth disparity maps. Supports basic Middlebury +and MPI-Sintel formats. Note that the resulting disparity map is scaled by 16. + +@param src_path path to the image, containing ground-truth disparity map + +@param dst output disparity map, CV_16S depth + +@result returns zero if successfully read the ground truth + */ +CV_EXPORTS +int readGT(String src_path,OutputArray dst); + +/** @brief Function for computing mean square error for disparity maps + +@param GT ground truth disparity map + +@param src disparity map to evaluate + +@param ROI region of interest + +@result returns mean square error between GT and src + */ +CV_EXPORTS +double computeMSE(InputArray GT, InputArray src, Rect ROI); + +/** @brief Function for computing the percent of "bad" pixels in the disparity map +(pixels where error is higher than a specified threshold) + +@param GT ground truth disparity map + +@param src disparity map to evaluate + +@param ROI region of interest + +@param thresh threshold used to determine "bad" pixels + +@result returns mean square error between GT and src + */ +CV_EXPORTS +double computeBadPixelPercent(InputArray GT, InputArray src, Rect ROI, int thresh=24/*1.5 pixels*/); + +/** @brief Function for creating a disparity map visualization (clamped CV_8U image) + +@param src input disparity map (CV_16S depth) + +@param dst output visualization + +@param scale disparity map will be multiplied by this value for visualization + */ +CV_EXPORTS +void getDisparityVis(InputArray src,OutputArray dst,double scale=1.0); + +//! @} +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/edge_filter.hpp b/include/opencv2/ximgproc/edge_filter.hpp new file mode 100644 index 0000000..8388d1a --- /dev/null +++ b/include/opencv2/ximgproc/edge_filter.hpp @@ -0,0 +1,527 @@ +/* + * 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. + */ + +#ifndef __OPENCV_EDGEFILTER_HPP__ +#define __OPENCV_EDGEFILTER_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_filters +//! @{ + +enum EdgeAwareFiltersList +{ + DTF_NC, + DTF_IC, + DTF_RF, + + GUIDED_FILTER, + AM_FILTER +}; + + +/** @brief Interface for realizations of Domain Transform filter. + +For more details about this filter see @cite Gastal11 . + */ +class CV_EXPORTS_W DTFilter : public Algorithm +{ +public: + + /** @brief Produce domain transform filtering operation on source image. + + @param src filtering image with unsigned 8-bit or floating-point 32-bit depth and up to 4 channels. + + @param dst destination image. + + @param dDepth optional depth of the output image. dDepth can be set to -1, which will be equivalent + to src.depth(). + */ + CV_WRAP virtual void filter(InputArray src, OutputArray dst, int dDepth = -1) = 0; +}; + +/** @brief Factory method, create instance of DTFilter and produce initialization routines. + +@param guide guided image (used to build transformed distance, which describes edge structure of +guided image). + +@param sigmaSpatial \f${\sigma}_H\f$ parameter in the original article, it's similar to the sigma in the +coordinate space into bilateralFilter. + +@param sigmaColor \f${\sigma}_r\f$ parameter in the original article, it's similar to the sigma in the +color space into bilateralFilter. + +@param mode one form three modes DTF_NC, DTF_RF and DTF_IC which corresponds to three modes for +filtering 2D signals in the article. + +@param numIters optional number of iterations used for filtering, 3 is quite enough. + +For more details about Domain Transform filter parameters, see the original article @cite Gastal11 and +[Domain Transform filter homepage](http://www.inf.ufrgs.br/~eslgastal/DomainTransform/). + */ +CV_EXPORTS_W +Ptr<DTFilter> createDTFilter(InputArray guide, double sigmaSpatial, double sigmaColor, int mode = DTF_NC, int numIters = 3); + +/** @brief Simple one-line Domain Transform filter call. If you have multiple images to filter with the same +guided image then use DTFilter interface to avoid extra computations on initialization stage. + +@param guide guided image (also called as joint image) with unsigned 8-bit or floating-point 32-bit +depth and up to 4 channels. +@param src filtering image with unsigned 8-bit or floating-point 32-bit depth and up to 4 channels. +@param dst +@param sigmaSpatial \f${\sigma}_H\f$ parameter in the original article, it's similar to the sigma in the +coordinate space into bilateralFilter. +@param sigmaColor \f${\sigma}_r\f$ parameter in the original article, it's similar to the sigma in the +color space into bilateralFilter. +@param mode one form three modes DTF_NC, DTF_RF and DTF_IC which corresponds to three modes for +filtering 2D signals in the article. +@param numIters optional number of iterations used for filtering, 3 is quite enough. +@sa bilateralFilter, guidedFilter, amFilter + */ +CV_EXPORTS_W +void dtFilter(InputArray guide, InputArray src, OutputArray dst, double sigmaSpatial, double sigmaColor, int mode = DTF_NC, int numIters = 3); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Interface for realizations of Guided Filter. + +For more details about this filter see @cite Kaiming10 . + */ +class CV_EXPORTS_W GuidedFilter : public Algorithm +{ +public: + + /** @brief Apply Guided Filter to the filtering image. + + @param src filtering image with any numbers of channels. + + @param dst output image. + + @param dDepth optional depth of the output image. dDepth can be set to -1, which will be equivalent + to src.depth(). + */ + CV_WRAP virtual void filter(InputArray src, OutputArray dst, int dDepth = -1) = 0; +}; + +/** @brief Factory method, create instance of GuidedFilter and produce initialization routines. + +@param guide guided image (or array of images) with up to 3 channels, if it have more then 3 +channels then only first 3 channels will be used. + +@param radius radius of Guided Filter. + +@param eps regularization term of Guided Filter. \f${eps}^2\f$ is similar to the sigma in the color +space into bilateralFilter. + +For more details about Guided Filter parameters, see the original article @cite Kaiming10 . + */ +CV_EXPORTS_W Ptr<GuidedFilter> createGuidedFilter(InputArray guide, int radius, double eps); + +/** @brief Simple one-line Guided Filter call. + +If you have multiple images to filter with the same guided image then use GuidedFilter interface to +avoid extra computations on initialization stage. + +@param guide guided image (or array of images) with up to 3 channels, if it have more then 3 +channels then only first 3 channels will be used. + +@param src filtering image with any numbers of channels. + +@param dst output image. + +@param radius radius of Guided Filter. + +@param eps regularization term of Guided Filter. \f${eps}^2\f$ is similar to the sigma in the color +space into bilateralFilter. + +@param dDepth optional depth of the output image. + +@sa bilateralFilter, dtFilter, amFilter */ +CV_EXPORTS_W void guidedFilter(InputArray guide, InputArray src, OutputArray dst, int radius, double eps, int dDepth = -1); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Interface for Adaptive Manifold Filter realizations. + +For more details about this filter see @cite Gastal12 and References_. + +Below listed optional parameters which may be set up with Algorithm::set function. +- member double sigma_s = 16.0 +Spatial standard deviation. +- member double sigma_r = 0.2 +Color space standard deviation. +- member int tree_height = -1 +Height of the manifold tree (default = -1 : automatically computed). +- member int num_pca_iterations = 1 +Number of iterations to computed the eigenvector. +- member bool adjust_outliers = false +Specify adjust outliers using Eq. 9 or not. +- member bool use_RNG = true +Specify use random number generator to compute eigenvector or not. + */ +class CV_EXPORTS_W AdaptiveManifoldFilter : public Algorithm +{ +public: + /** @brief Apply high-dimensional filtering using adaptive manifolds. + + @param src filtering image with any numbers of channels. + + @param dst output image. + + @param joint optional joint (also called as guided) image with any numbers of channels. + */ + CV_WRAP virtual void filter(InputArray src, OutputArray dst, InputArray joint = noArray()) = 0; + + CV_WRAP virtual void collectGarbage() = 0; + + CV_WRAP static Ptr<AdaptiveManifoldFilter> create(); + + /** @see setSigmaS */ + virtual double getSigmaS() const = 0; + /** @copybrief getSigmaS @see getSigmaS */ + virtual void setSigmaS(double val) = 0; + /** @see setSigmaR */ + virtual double getSigmaR() const = 0; + /** @copybrief getSigmaR @see getSigmaR */ + virtual void setSigmaR(double val) = 0; + /** @see setTreeHeight */ + virtual int getTreeHeight() const = 0; + /** @copybrief getTreeHeight @see getTreeHeight */ + virtual void setTreeHeight(int val) = 0; + /** @see setPCAIterations */ + virtual int getPCAIterations() const = 0; + /** @copybrief getPCAIterations @see getPCAIterations */ + virtual void setPCAIterations(int val) = 0; + /** @see setAdjustOutliers */ + virtual bool getAdjustOutliers() const = 0; + /** @copybrief getAdjustOutliers @see getAdjustOutliers */ + virtual void setAdjustOutliers(bool val) = 0; + /** @see setUseRNG */ + virtual bool getUseRNG() const = 0; + /** @copybrief getUseRNG @see getUseRNG */ + virtual void setUseRNG(bool val) = 0; +}; + +/** @brief Factory method, create instance of AdaptiveManifoldFilter and produce some initialization routines. + +@param sigma_s spatial standard deviation. + +@param sigma_r color space standard deviation, it is similar to the sigma in the color space into +bilateralFilter. + +@param adjust_outliers optional, specify perform outliers adjust operation or not, (Eq. 9) in the +original paper. + +For more details about Adaptive Manifold Filter parameters, see the original article @cite Gastal12 . + +@note Joint images with CV_8U and CV_16U depth converted to images with CV_32F depth and [0; 1] +color range before processing. Hence color space sigma sigma_r must be in [0; 1] range, unlike same +sigmas in bilateralFilter and dtFilter functions. +*/ +CV_EXPORTS_W Ptr<AdaptiveManifoldFilter> createAMFilter(double sigma_s, double sigma_r, bool adjust_outliers = false); + +/** @brief Simple one-line Adaptive Manifold Filter call. + +@param joint joint (also called as guided) image or array of images with any numbers of channels. + +@param src filtering image with any numbers of channels. + +@param dst output image. + +@param sigma_s spatial standard deviation. + +@param sigma_r color space standard deviation, it is similar to the sigma in the color space into +bilateralFilter. + +@param adjust_outliers optional, specify perform outliers adjust operation or not, (Eq. 9) in the +original paper. + +@note Joint images with CV_8U and CV_16U depth converted to images with CV_32F depth and [0; 1] +color range before processing. Hence color space sigma sigma_r must be in [0; 1] range, unlike same +sigmas in bilateralFilter and dtFilter functions. @sa bilateralFilter, dtFilter, guidedFilter +*/ +CV_EXPORTS_W void amFilter(InputArray joint, InputArray src, OutputArray dst, double sigma_s, double sigma_r, bool adjust_outliers = false); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Applies the joint bilateral filter to an image. + +@param joint Joint 8-bit or floating-point, 1-channel or 3-channel image. + +@param src Source 8-bit or floating-point, 1-channel or 3-channel image with the same depth as joint +image. + +@param dst Destination image of the same size and type as src . + +@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, +it is computed from sigmaSpace . + +@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that +farther colors within the pixel neighborhood (see sigmaSpace ) will be mixed together, resulting in +larger areas of semi-equal color. + +@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that +farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). +When d\>0 , it specifies the neighborhood size regardless of sigmaSpace . Otherwise, d is +proportional to sigmaSpace . + +@param borderType + +@note bilateralFilter and jointBilateralFilter use L1 norm to compute difference between colors. + +@sa bilateralFilter, amFilter +*/ +CV_EXPORTS_W +void jointBilateralFilter(InputArray joint, InputArray src, OutputArray dst, int d, double sigmaColor, double sigmaSpace, int borderType = BORDER_DEFAULT); + +/** @brief Applies the bilateral texture filter to an image. It performs structure-preserving texture filter. +For more details about this filter see @cite Cho2014. + +@param src Source image whose depth is 8-bit UINT or 32-bit FLOAT + +@param dst Destination image of the same size and type as src. + +@param fr Radius of kernel to be used for filtering. It should be positive integer + +@param numIter Number of iterations of algorithm, It should be positive integer + +@param sigmaAlpha Controls the sharpness of the weight transition from edges to smooth/texture regions, where +a bigger value means sharper transition. When the value is negative, it is automatically calculated. + +@param sigmaAvg Range blur parameter for texture blurring. Larger value makes result to be more blurred. When the +value is negative, it is automatically calculated as described in the paper. + +@sa rollingGuidanceFilter, bilateralFilter +*/ +CV_EXPORTS_W +void bilateralTextureFilter(InputArray src, OutputArray dst, int fr = 3, int numIter = 1, double sigmaAlpha = -1., double sigmaAvg = -1.); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Applies the rolling guidance filter to an image. + +For more details, please see @cite zhang2014rolling + +@param src Source 8-bit or floating-point, 1-channel or 3-channel image. + +@param dst Destination image of the same size and type as src. + +@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, +it is computed from sigmaSpace . + +@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that +farther colors within the pixel neighborhood (see sigmaSpace ) will be mixed together, resulting in +larger areas of semi-equal color. + +@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that +farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). +When d\>0 , it specifies the neighborhood size regardless of sigmaSpace . Otherwise, d is +proportional to sigmaSpace . + +@param numOfIter Number of iterations of joint edge-preserving filtering applied on the source image. + +@param borderType + +@note rollingGuidanceFilter uses jointBilateralFilter as the edge-preserving filter. + +@sa jointBilateralFilter, bilateralFilter, amFilter +*/ +CV_EXPORTS_W +void rollingGuidanceFilter(InputArray src, OutputArray dst, int d = -1, double sigmaColor = 25, double sigmaSpace = 3, int numOfIter = 4, int borderType = BORDER_DEFAULT); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Interface for implementations of Fast Bilateral Solver. + +For more details about this solver see @cite BarronPoole2016 . +*/ +class CV_EXPORTS_W FastBilateralSolverFilter : public Algorithm +{ +public: + /** @brief Apply smoothing operation to the source image. + + @param src source image for filtering with unsigned 8-bit or signed 16-bit or floating-point 32-bit depth and up to 3 channels. + + @param confidence confidence image with unsigned 8-bit or floating-point 32-bit confidence and 1 channel. + + @param dst destination image. + + @note Confidence images with CV_8U depth are expected to in [0, 255] and CV_32F in [0, 1] range. + */ + CV_WRAP virtual void filter(InputArray src, InputArray confidence, OutputArray dst) = 0; +}; + +/** @brief Factory method, create instance of FastBilateralSolverFilter and execute the initialization routines. + +@param guide image serving as guide for filtering. It should have 8-bit depth and either 1 or 3 channels. + +@param sigma_spatial parameter, that is similar to spatial space sigma (bandwidth) in bilateralFilter. + +@param sigma_luma parameter, that is similar to luma space sigma (bandwidth) in bilateralFilter. + +@param sigma_chroma parameter, that is similar to chroma space sigma (bandwidth) in bilateralFilter. + +@param lambda smoothness strength parameter for solver. + +@param num_iter number of iterations used for solver, 25 is usually enough. + +@param max_tol convergence tolerance used for solver. + +For more details about the Fast Bilateral Solver parameters, see the original paper @cite BarronPoole2016. + +*/ +CV_EXPORTS_W Ptr<FastBilateralSolverFilter> createFastBilateralSolverFilter(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda = 128.0, int num_iter = 25, double max_tol = 1e-5); + + +/** @brief Simple one-line Fast Bilateral Solver filter call. If you have multiple images to filter with the same +guide then use FastBilateralSolverFilter interface to avoid extra computations. + +@param guide image serving as guide for filtering. It should have 8-bit depth and either 1 or 3 channels. + +@param src source image for filtering with unsigned 8-bit or signed 16-bit or floating-point 32-bit depth and up to 4 channels. + +@param confidence confidence image with unsigned 8-bit or floating-point 32-bit confidence and 1 channel. + +@param dst destination image. + +@param sigma_spatial parameter, that is similar to spatial space sigma (bandwidth) in bilateralFilter. + +@param sigma_luma parameter, that is similar to luma space sigma (bandwidth) in bilateralFilter. + +@param sigma_chroma parameter, that is similar to chroma space sigma (bandwidth) in bilateralFilter. + +@param lambda smoothness strength parameter for solver. + +@param num_iter number of iterations used for solver, 25 is usually enough. + +@param max_tol convergence tolerance used for solver. + +For more details about the Fast Bilateral Solver parameters, see the original paper @cite BarronPoole2016. + +@note Confidence images with CV_8U depth are expected to in [0, 255] and CV_32F in [0, 1] range. +*/ +CV_EXPORTS_W void fastBilateralSolverFilter(InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial = 8, double sigma_luma = 8, double sigma_chroma = 8, double lambda = 128.0, int num_iter = 25, double max_tol = 1e-5); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/** @brief Interface for implementations of Fast Global Smoother filter. + +For more details about this filter see @cite Min2014 and @cite Farbman2008 . +*/ +class CV_EXPORTS_W FastGlobalSmootherFilter : public Algorithm +{ +public: + /** @brief Apply smoothing operation to the source image. + + @param src source image for filtering with unsigned 8-bit or signed 16-bit or floating-point 32-bit depth and up to 4 channels. + + @param dst destination image. + */ + CV_WRAP virtual void filter(InputArray src, OutputArray dst) = 0; +}; + +/** @brief Factory method, create instance of FastGlobalSmootherFilter and execute the initialization routines. + +@param guide image serving as guide for filtering. It should have 8-bit depth and either 1 or 3 channels. + +@param lambda parameter defining the amount of regularization + +@param sigma_color parameter, that is similar to color space sigma in bilateralFilter. + +@param lambda_attenuation internal parameter, defining how much lambda decreases after each iteration. Normally, +it should be 0.25. Setting it to 1.0 may lead to streaking artifacts. + +@param num_iter number of iterations used for filtering, 3 is usually enough. + +For more details about Fast Global Smoother parameters, see the original paper @cite Min2014. However, please note that +there are several differences. Lambda attenuation described in the paper is implemented a bit differently so do not +expect the results to be identical to those from the paper; sigma_color values from the paper should be multiplied by 255.0 to +achieve the same effect. Also, in case of image filtering where source and guide image are the same, authors +propose to dynamically update the guide image after each iteration. To maximize the performance this feature +was not implemented here. +*/ +CV_EXPORTS_W Ptr<FastGlobalSmootherFilter> createFastGlobalSmootherFilter(InputArray guide, double lambda, double sigma_color, double lambda_attenuation=0.25, int num_iter=3); + +/** @brief Simple one-line Fast Global Smoother filter call. If you have multiple images to filter with the same +guide then use FastGlobalSmootherFilter interface to avoid extra computations. + +@param guide image serving as guide for filtering. It should have 8-bit depth and either 1 or 3 channels. + +@param src source image for filtering with unsigned 8-bit or signed 16-bit or floating-point 32-bit depth and up to 4 channels. + +@param dst destination image. + +@param lambda parameter defining the amount of regularization + +@param sigma_color parameter, that is similar to color space sigma in bilateralFilter. + +@param lambda_attenuation internal parameter, defining how much lambda decreases after each iteration. Normally, +it should be 0.25. Setting it to 1.0 may lead to streaking artifacts. + +@param num_iter number of iterations used for filtering, 3 is usually enough. +*/ +CV_EXPORTS_W void fastGlobalSmootherFilter(InputArray guide, InputArray src, OutputArray dst, double lambda, double sigma_color, double lambda_attenuation=0.25, int num_iter=3); + +/** @brief Global image smoothing via L0 gradient minimization. + +@param src source image for filtering with unsigned 8-bit or signed 16-bit or floating-point depth. + +@param dst destination image. + +@param lambda parameter defining the smooth term weight. + +@param kappa parameter defining the increasing factor of the weight of the gradient data term. + +For more details about L0 Smoother, see the original paper @cite xu2011image. +*/ +CV_EXPORTS_W void l0Smooth(InputArray src, OutputArray dst, double lambda = 0.02, double kappa = 2.0); +//! @} +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/edgeboxes.hpp b/include/opencv2/ximgproc/edgeboxes.hpp new file mode 100644 index 0000000..b413b80 --- /dev/null +++ b/include/opencv2/ximgproc/edgeboxes.hpp @@ -0,0 +1,200 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_EDGEBOXES_HPP__ +#define __OPENCV_EDGEBOXES_HPP__ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_edgeboxes +//! @{ + +// bounding box data structures +typedef struct +{ + int x, y, w, h; + float score; +} Box; + +typedef std::vector<Box> Boxes; + +/** @brief Class implementing EdgeBoxes algorithm from @cite ZitnickECCV14edgeBoxes : + */ +class CV_EXPORTS_W EdgeBoxes : public Algorithm +{ + +public: + + /** @brief Returns array containing proposal boxes. + + @param edge_map edge image. + @param orientation_map orientation map. + @param boxes proposal boxes. + */ + CV_WRAP virtual void getBoundingBoxes(InputArray edge_map, InputArray orientation_map, CV_OUT std::vector<Rect> &boxes) = 0; + + /** @brief Returns the step size of sliding window search. + */ + CV_WRAP virtual float getAlpha() const = 0; + /** @brief Sets the step size of sliding window search. + */ + CV_WRAP virtual void setAlpha(float value) = 0; + + /** @brief Returns the nms threshold for object proposals. + */ + CV_WRAP virtual float getBeta() const = 0; + /** @brief Sets the nms threshold for object proposals. + */ + CV_WRAP virtual void setBeta(float value) = 0; + + /** @brief Returns adaptation rate for nms threshold. + */ + CV_WRAP virtual float getEta() const = 0; + /** @brief Sets the adaptation rate for nms threshold. + */ + CV_WRAP virtual void setEta(float value) = 0; + + /** @brief Returns the min score of boxes to detect. + */ + CV_WRAP virtual float getMinScore() const = 0; + /** @brief Sets the min score of boxes to detect. + */ + CV_WRAP virtual void setMinScore(float value) = 0; + + /** @brief Returns the max number of boxes to detect. + */ + CV_WRAP virtual int getMaxBoxes() const = 0; + /** @brief Sets max number of boxes to detect. + */ + CV_WRAP virtual void setMaxBoxes(int value) = 0; + + /** @brief Returns the edge min magnitude. + */ + CV_WRAP virtual float getEdgeMinMag() const = 0; + /** @brief Sets the edge min magnitude. + */ + CV_WRAP virtual void setEdgeMinMag(float value) = 0; + + /** @brief Returns the edge merge threshold. + */ + CV_WRAP virtual float getEdgeMergeThr() const = 0; + /** @brief Sets the edge merge threshold. + */ + CV_WRAP virtual void setEdgeMergeThr(float value) = 0; + + /** @brief Returns the cluster min magnitude. + */ + CV_WRAP virtual float getClusterMinMag() const = 0; + /** @brief Sets the cluster min magnitude. + */ + CV_WRAP virtual void setClusterMinMag(float value) = 0; + + /** @brief Returns the max aspect ratio of boxes. + */ + CV_WRAP virtual float getMaxAspectRatio() const = 0; + /** @brief Sets the max aspect ratio of boxes. + */ + CV_WRAP virtual void setMaxAspectRatio(float value) = 0; + + /** @brief Returns the minimum area of boxes. + */ + CV_WRAP virtual float getMinBoxArea() const = 0; + /** @brief Sets the minimum area of boxes. + */ + CV_WRAP virtual void setMinBoxArea(float value) = 0; + + /** @brief Returns the affinity sensitivity. + */ + CV_WRAP virtual float getGamma() const = 0; + /** @brief Sets the affinity sensitivity + */ + CV_WRAP virtual void setGamma(float value) = 0; + + /** @brief Returns the scale sensitivity. + */ + CV_WRAP virtual float getKappa() const = 0; + /** @brief Sets the scale sensitivity. + */ + CV_WRAP virtual void setKappa(float value) = 0; + +}; + +/** @brief Creates a Edgeboxes + +@param alpha step size of sliding window search. +@param beta nms threshold for object proposals. +@param eta adaptation rate for nms threshold. +@param minScore min score of boxes to detect. +@param maxBoxes max number of boxes to detect. +@param edgeMinMag edge min magnitude. Increase to trade off accuracy for speed. +@param edgeMergeThr edge merge threshold. Increase to trade off accuracy for speed. +@param clusterMinMag cluster min magnitude. Increase to trade off accuracy for speed. +@param maxAspectRatio max aspect ratio of boxes. +@param minBoxArea minimum area of boxes. +@param gamma affinity sensitivity. +@param kappa scale sensitivity. +*/ +CV_EXPORTS_W Ptr<EdgeBoxes> +createEdgeBoxes(float alpha=0.65f, + float beta=0.75f, + float eta=1, + float minScore=0.01f, + int maxBoxes=10000, + float edgeMinMag=0.1f, + float edgeMergeThr=0.5f, + float clusterMinMag=0.5f, + float maxAspectRatio=3, + float minBoxArea=1000, + float gamma=2, + float kappa=1.5f); + +//! @} + +} +} + +#endif /* __OPENCV_EDGEBOXES_HPP__ */ diff --git a/include/opencv2/ximgproc/estimated_covariance.hpp b/include/opencv2/ximgproc/estimated_covariance.hpp new file mode 100644 index 0000000..e4f5ddf --- /dev/null +++ b/include/opencv2/ximgproc/estimated_covariance.hpp @@ -0,0 +1,82 @@ +/* +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) + +Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +Copyright (C) 2015, OpenCV Foundation, all rights reserved. +Copyright (C) 2015, Itseez Inc., all rights reserved. +Third party copyrights are property of their respective owners. + +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. + +Algorithmic details of this algorithm can be found at: + * O. Green, Y. Birk, "A Computationally Efficient Algorithm for the 2D Covariance Method", ACM/IEEE International Conference on High Performance Computing, Networking, Storage and Analysis, Denver, Colorado, 2013 +A previous and less efficient version of the algorithm can be found: + * O. Green, L. David, A. Galperin, Y. Birk, "Efficient parallel computation of the estimated covariance matrix", arXiv, 2013 + + +*/ +#ifndef __OPENCV_ESTIMATECOVARIANCE_HPP__ +#define __OPENCV_ESTIMATECOVARIANCE_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +/** @brief Computes the estimated covariance matrix of an image using the sliding +window forumlation. + +@param src The source image. Input image must be of a complex type. +@param dst The destination estimated covariance matrix. Output matrix will be size (windowRows*windowCols, windowRows*windowCols). +@param windowRows The number of rows in the window. +@param windowCols The number of cols in the window. +The window size parameters control the accuracy of the estimation. +The sliding window moves over the entire image from the top-left corner +to the bottom right corner. Each location of the window represents a sample. +If the window is the size of the image, then this gives the exact covariance matrix. +For all other cases, the sizes of the window will impact the number of samples +and the number of elements in the estimated covariance matrix. +*/ + +CV_EXPORTS_W void covarianceEstimation(InputArray src, OutputArray dst, int windowRows, int windowCols); + +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/fast_hough_transform.hpp b/include/opencv2/ximgproc/fast_hough_transform.hpp new file mode 100644 index 0000000..adfbf54 --- /dev/null +++ b/include/opencv2/ximgproc/fast_hough_transform.hpp @@ -0,0 +1,164 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, Smart Engines Ltd, all rights reserved. +// Copyright (C) 2015, Institute for Information Transmission Problems of the Russian Academy of Sciences (Kharkevich Institute), all rights reserved. +// Copyright (C) 2015, Dmitry Nikolaev, Simon Karpenko, Michail Aliev, Elena Kuznetsova, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_FAST_HOUGH_TRANSFORM_HPP__ +#define __OPENCV_FAST_HOUGH_TRANSFORM_HPP__ +#ifdef __cplusplus + +#include "opencv2/core.hpp" + + +namespace cv { namespace ximgproc { + +/** +* @brief Specifies the part of Hough space to calculate +* @details The enum specifies the part of Hough space to calculate. Each +* member specifies primarily direction of lines (horizontal or vertical) +* and the direction of angle changes. +* Direction of angle changes is from multiples of 90 to odd multiples of 45. +* The image considered to be written top-down and left-to-right. +* Angles are started from vertical line and go clockwise. +* Separate quarters and halves are written in orientation they should be in +* full Hough space. +*/ +enum AngleRangeOption +{ + ARO_0_45 = 0, //< Vertical primarily direction and clockwise angle changes + ARO_45_90 = 1, //< Horizontal primarily direction and counterclockwise angle changes + ARO_90_135 = 2, //< Horizontal primarily direction and clockwise angle changes + ARO_315_0 = 3, //< Vertical primarily direction and counterclockwise angle changes + ARO_315_45 = 4, //< Vertical primarily direction + ARO_45_135 = 5, //< Horizontal primarily direction + ARO_315_135 = 6, //< Full set of directions + ARO_CTR_HOR = 7, //< 90 +/- atan(0.5), interval approximately from 64.5 to 116.5 degrees. + //< It is used for calculating Fast Hough Transform for images skewed by atan(0.5). + ARO_CTR_VER = 8 //< +/- atan(0.5), interval approximately from 333.5(-26.5) to 26.5 degrees + //< It is used for calculating Fast Hough Transform for images skewed by atan(0.5). +}; + +/** + * @brief Specifies binary operations. + * @details The enum specifies binary operations, that is such ones which involve + * two operands. Formally, a binary operation @f$ f @f$ on a set @f$ S @f$ + * is a binary relation that maps elements of the Cartesian product + * @f$ S \times S @f$ to @f$ S @f$: +* @f[ f: S \times S \to S @f] + * @ingroup MinUtils_MathOper + */ +enum HoughOp +{ + FHT_MIN = 0, //< Binary minimum operation. The constant specifies the binary minimum operation + //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = \min(x, y) @f] + FHT_MAX = 1, //< Binary maximum operation. The constant specifies the binary maximum operation + //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = \max(x, y) @f] + FHT_ADD = 2, //< Binary addition operation. The constant specifies the binary addition operation + //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = x + y @f] + FHT_AVE = 3 //< Binary average operation. The constant specifies the binary average operation + //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = \frac{x + y}{2} @f] +}; + +/** +* @brief Specifies to do or not to do skewing of Hough transform image +* @details The enum specifies to do or not to do skewing of Hough transform image +* so it would be no cycling in Hough transform image through borders of image. +*/ +enum HoughDeskewOption +{ + HDO_RAW = 0, //< Use raw cyclic image + HDO_DESKEW = 1 //< Prepare deskewed image +}; + +/** + * @brief Specifies the degree of rules validation. + * @details The enum specifies the degree of rules validation. This can be used, + * for example, to choose a proper way of input arguments validation. + */ +typedef enum { + RO_STRICT = 0x00, ///< Validate each rule in a proper way. + RO_IGNORE_BORDERS = 0x01, ///< Skip validations of image borders. +} RulesOption; + +/** +* @brief Calculates 2D Fast Hough transform of an image. +* @param dst The destination image, result of transformation. +* @param src The source (input) image. +* @param dstMatDepth The depth of destination image +* @param op The operation to be applied, see cv::HoughOp +* @param angleRange The part of Hough space to calculate, see cv::AngleRangeOption +* @param makeSkew Specifies to do or not to do image skewing, see cv::HoughDeskewOption +* +* The function calculates the fast Hough transform for full, half or quarter +* range of angles. +*/ +CV_EXPORTS_W void FastHoughTransform( InputArray src, + OutputArray dst, + int dstMatDepth, + int angleRange = ARO_315_135, + int op = FHT_ADD, + int makeSkew = HDO_DESKEW ); + +/** +* @brief Calculates coordinates of line segment corresponded by point in Hough space. +* @param houghPoint Point in Hough space. +* @param srcImgInfo The source (input) image of Hough transform. +* @param angleRange The part of Hough space where point is situated, see cv::AngleRangeOption +* @param makeSkew Specifies to do or not to do image skewing, see cv::HoughDeskewOption +* @param rules Specifies strictness of line segment calculating, see cv::RulesOption +* @retval [Vec4i] Coordinates of line segment corresponded by point in Hough space. +* @remarks If rules parameter set to RO_STRICT + then returned line cut along the border of source image. +* @remarks If rules parameter set to RO_WEAK then in case of point, which belongs + the incorrect part of Hough image, returned line will not intersect source image. +* +* The function calculates coordinates of line segment corresponded by point in Hough space. +*/ +CV_EXPORTS_W Vec4i HoughPoint2Line(const Point &houghPoint, + InputArray srcImgInfo, + int angleRange = ARO_315_135, + int makeSkew = HDO_DESKEW, + int rules = RO_IGNORE_BORDERS ); + +} }// namespace cv::ximgproc + +#endif //__cplusplus +#endif //__OPENCV_FAST_HOUGH_TRANSFORM_HPP__ diff --git a/include/opencv2/ximgproc/fast_line_detector.hpp b/include/opencv2/ximgproc/fast_line_detector.hpp new file mode 100644 index 0000000..1df5558 --- /dev/null +++ b/include/opencv2/ximgproc/fast_line_detector.hpp @@ -0,0 +1,81 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __OPENCV_FAST_LINE_DETECTOR_HPP__ +#define __OPENCV_FAST_LINE_DETECTOR_HPP__ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_fast_line_detector +//! @{ + +/** @brief Class implementing the FLD (Fast Line Detector) algorithm described +in @cite Lee14 . +*/ + +//! @include samples/fld_lines.cpp + +class CV_EXPORTS_W FastLineDetector : public Algorithm +{ +public: + /** @example fld_lines.cpp + An example using the FastLineDetector + */ + /** @brief Finds lines in the input image. + This is the output of the default parameters of the algorithm on the above + shown image. + + ![image](pics/corridor_fld.jpg) + + @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be + selected, use: `fld_ptr-\>detect(image(roi), lines, ...); + lines += Scalar(roi.x, roi.y, roi.x, roi.y);` + @param _lines A vector of Vec4f elements specifying the beginning + and ending point of a line. Where Vec4f is (x1, y1, x2, y2), point + 1 is the start, point 2 - end. Returned lines are directed so that the + brighter side is on their left. + */ + CV_WRAP virtual void detect(InputArray _image, OutputArray _lines) = 0; + + /** @brief Draws the line segments on a given image. + @param _image The image, where the lines will be drawn. Should be bigger + or equal to the image, where the lines were found. + @param lines A vector of the lines that needed to be drawn. + @param draw_arrow If true, arrow heads will be drawn. + */ + CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines, + bool draw_arrow = false) = 0; + + virtual ~FastLineDetector() { } +}; + +/** @brief Creates a smart pointer to a FastLineDetector object and initializes it + +@param _length_threshold 10 - Segment shorter than this will be discarded +@param _distance_threshold 1.41421356 - A point placed from a hypothesis line + segment farther than this will be + regarded as an outlier +@param _canny_th1 50 - First threshold for + hysteresis procedure in Canny() +@param _canny_th2 50 - Second threshold for + hysteresis procedure in Canny() +@param _canny_aperture_size 3 - Aperturesize for the sobel + operator in Canny() +@param _do_merge false - If true, incremental merging of segments + will be perfomred +*/ +CV_EXPORTS_W Ptr<FastLineDetector> createFastLineDetector( + int _length_threshold = 10, float _distance_threshold = 1.414213562f, + double _canny_th1 = 50.0, double _canny_th2 = 50.0, int _canny_aperture_size = 3, + bool _do_merge = false); + +//! @} ximgproc_fast_line_detector +} +} +#endif diff --git a/include/opencv2/ximgproc/fourier_descriptors.hpp b/include/opencv2/ximgproc/fourier_descriptors.hpp new file mode 100644 index 0000000..969a33d --- /dev/null +++ b/include/opencv2/ximgproc/fourier_descriptors.hpp @@ -0,0 +1,119 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __OPENCV_FOURIERDESCRIPTORS_HPP__ +#define __OPENCV_FOURIERDESCRIPTORS_HPP__ + +#include <opencv2/core.hpp> + +namespace cv { +namespace ximgproc { + + //! @addtogroup ximgproc_fourier + //! @{ + + /** @brief Class for ContourFitting algorithms. + ContourFitting match two contours \f$ z_a \f$ and \f$ z_b \f$ minimizing distance + \f[ d(z_a,z_b)=\sum (a_n - s b_n e^{j(n \alpha +\phi )})^2 \f] where \f$ a_n \f$ and \f$ b_n \f$ are Fourier descriptors of \f$ z_a \f$ and \f$ z_b \f$ and s is a scaling factor and \f$ \phi \f$ is angle rotation and \f$ \alpha \f$ is starting point factor adjustement + */ + class CV_EXPORTS_W ContourFitting : public Algorithm + { + int ctrSize; + int fdSize; + std::vector<std::complex<double> > b; + std::vector<std::complex<double> > a; + std::vector<double> frequence; + std::vector<double> rho, psi; + void frequencyInit(); + void fAlpha(double x, double &fn, double &df); + double distance(std::complex<double> r, double alpha); + double newtonRaphson(double x1, double x2); + public: + /** @brief Fit two closed curves using fourier descriptors. More details in @cite PersoonFu1977 and @cite BergerRaghunathan1998 + + * @param ctr number of Fourier descriptors equal to number of contour points after resampling. + * @param fd Contour defining second shape (Target). + */ + ContourFitting(int ctr=1024,int fd=16):ctrSize(ctr),fdSize(fd){}; + /** @brief Fit two closed curves using fourier descriptors. More details in @cite PersoonFu1977 and @cite BergerRaghunathan1998 + + @param src Contour defining first shape. + @param dst Contour defining second shape (Target). + @param alphaPhiST : \f$ \alpha \f$=alphaPhiST(0,0), \f$ \phi \f$=alphaPhiST(0,1) (in radian), s=alphaPhiST(0,2), Tx=alphaPhiST(0,3), Ty=alphaPhiST(0,4) rotation center + @param dist distance between src and dst after matching. + @param fdContour false then src and dst are contours and true src and dst are fourier descriptors. + */ + void estimateTransformation(InputArray src, InputArray dst, OutputArray alphaPhiST, double *dist = 0, bool fdContour = false); + /** @brief Fit two closed curves using fourier descriptors. More details in @cite PersoonFu1977 and @cite BergerRaghunathan1998 + + @param src Contour defining first shape. + @param dst Contour defining second shape (Target). + @param alphaPhiST : \f$ \alpha \f$=alphaPhiST(0,0), \f$ \phi \f$=alphaPhiST(0,1) (in radian), s=alphaPhiST(0,2), Tx=alphaPhiST(0,3), Ty=alphaPhiST(0,4) rotation center + @param dist distance between src and dst after matching. + @param fdContour false then src and dst are contours and true src and dst are fourier descriptors. + */ + CV_WRAP void estimateTransformation(InputArray src, InputArray dst, OutputArray alphaPhiST, CV_OUT double &dist , bool fdContour = false); + /** @brief set number of Fourier descriptors used in estimateTransformation + + @param n number of Fourier descriptors equal to number of contour points after resampling. + */ + CV_WRAP void setCtrSize(int n); + /** @brief set number of Fourier descriptors when estimateTransformation used vector<Point> + + @param n number of fourier descriptors used for optimal curve matching. + */ + CV_WRAP void setFDSize(int n); + /** + @returns number of fourier descriptors + */ + CV_WRAP int getCtrSize() { return ctrSize; }; + /** + @returns number of fourier descriptors used for optimal curve matching + */ + CV_WRAP int getFDSize() { return fdSize; }; + }; + /** + * @brief Fourier descriptors for planed closed curves + * + * For more details about this implementation, please see @cite PersoonFu1977 + * + * @param src contour type vector<Point> , vector<Point2f> or vector<Point2d> + * @param dst Mat of type CV_64FC2 and nbElt rows A VERIFIER + * @param nbElt number of rows in dst or getOptimalDFTSize rows if nbElt=-1 + * @param nbFD number of FD return in dst dst = [FD(1...nbFD/2) FD(nbFD/2-nbElt+1...:nbElt)] + * + */ + CV_EXPORTS_W void fourierDescriptor(InputArray src, OutputArray dst, int nbElt=-1,int nbFD=-1); + /** + * @brief transform a contour + * + * @param src contour or Fourier Descriptors if fd is true + * @param t transform Mat given by estimateTransformation + * @param dst Mat of type CV_64FC2 and nbElt rows + * @param fdContour true src are Fourier Descriptors. fdContour false src is a contour + * + */ + CV_EXPORTS_W void transformFD(InputArray src, InputArray t,OutputArray dst, bool fdContour=true); + /** + * @brief Contour sampling . + * + * @param src contour type vector<Point> , vector<Point2f> or vector<Point2d> + * @param out Mat of type CV_64FC2 and nbElt rows + * @param nbElt number of points in out contour + * + */ + CV_EXPORTS_W void contourSampling(InputArray src, OutputArray out, int nbElt); + + /** + * @brief create ContourFitting algorithm object + * + * @param ctr number of Fourier descriptors equal to number of contour points after resampling. + * @param fd Contour defining second shape (Target). + */ + CV_EXPORTS_W Ptr<ContourFitting> createContourFitting(int ctr = 1024, int fd = 16); + + //! @} ximgproc_fourier +} +} +#endif diff --git a/include/opencv2/ximgproc/lsc.hpp b/include/opencv2/ximgproc/lsc.hpp new file mode 100644 index 0000000..e6f5bae --- /dev/null +++ b/include/opencv2/ximgproc/lsc.hpp @@ -0,0 +1,157 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2014, 2015 + * Zhengqin Li <li-zq12 at mails dot tsinghua dot edu dot cn> + * Jiansheng Chen <jschenthu at mail dot tsinghua dot edu dot cn> + * Tsinghua University + * + * 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 name of the copyright holders nor the names of its + * 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 THE + * COPYRIGHT OWNER 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. + *********************************************************************/ + +/* + + "Superpixel Segmentation using Linear Spectral Clustering" + Zhengqin Li, Jiansheng Chen, IEEE Conference on Computer Vision and Pattern + Recognition (CVPR), Jun. 2015 + + OpenCV port by: Cristian Balint <cristian dot balint at gmail dot com> + */ + +#ifndef __OPENCV_LSC_HPP__ +#define __OPENCV_LSC_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_superpixel +//! @{ + +/** @brief Class implementing the LSC (Linear Spectral Clustering) superpixels +algorithm described in @cite LiCVPR2015LSC. + +LSC (Linear Spectral Clustering) produces compact and uniform superpixels with low +computational costs. Basically, a normalized cuts formulation of the superpixel +segmentation is adopted based on a similarity metric that measures the color +similarity and space proximity between image pixels. LSC is of linear computational +complexity and high memory efficiency and is able to preserve global properties of images + + */ + +class CV_EXPORTS_W SuperpixelLSC : public Algorithm +{ +public: + + /** @brief Calculates the actual amount of superpixels on a given segmentation computed + and stored in SuperpixelLSC object. + */ + CV_WRAP virtual int getNumberOfSuperpixels() const = 0; + + /** @brief Calculates the superpixel segmentation on a given image with the initialized + parameters in the SuperpixelLSC object. + + This function can be called again without the need of initializing the algorithm with + createSuperpixelLSC(). This save the computational cost of allocating memory for all the + structures of the algorithm. + + @param num_iterations Number of iterations. Higher number improves the result. + + The function computes the superpixels segmentation of an image with the parameters initialized + with the function createSuperpixelLSC(). The algorithms starts from a grid of superpixels and + then refines the boundaries by proposing updates of edges boundaries. + + */ + CV_WRAP virtual void iterate( int num_iterations = 10 ) = 0; + + /** @brief Returns the segmentation labeling of the image. + + Each label represents a superpixel, and each pixel is assigned to one superpixel label. + + @param labels_out Return: A CV_32SC1 integer array containing the labels of the superpixel + segmentation. The labels are in the range [0, getNumberOfSuperpixels()]. + + The function returns an image with the labels of the superpixel segmentation. The labels are in + the range [0, getNumberOfSuperpixels()]. + */ + CV_WRAP virtual void getLabels( OutputArray labels_out ) const = 0; + + /** @brief Returns the mask of the superpixel segmentation stored in SuperpixelLSC object. + + @param image Return: CV_8U1 image mask where -1 indicates that the pixel is a superpixel border, + and 0 otherwise. + + @param thick_line If false, the border is only one pixel wide, otherwise all pixels at the border + are masked. + + The function return the boundaries of the superpixel segmentation. + */ + CV_WRAP virtual void getLabelContourMask( OutputArray image, bool thick_line = true ) const = 0; + + /** @brief Enforce label connectivity. + + @param min_element_size The minimum element size in percents that should be absorbed into a bigger + superpixel. Given resulted average superpixel size valid value should be in 0-100 range, 25 means + that less then a quarter sized superpixel should be absorbed, this is default. + + The function merge component that is too small, assigning the previously found adjacent label + to this component. Calling this function may change the final number of superpixels. + */ + CV_WRAP virtual void enforceLabelConnectivity( int min_element_size = 20 ) = 0; + + +}; + +/** @brief Class implementing the LSC (Linear Spectral Clustering) superpixels + +@param image Image to segment +@param region_size Chooses an average superpixel size measured in pixels +@param ratio Chooses the enforcement of superpixel compactness factor of superpixel + +The function initializes a SuperpixelLSC object for the input image. It sets the parameters of +superpixel algorithm, which are: region_size and ruler. It preallocate some buffers for future +computing iterations over the given image. An example of LSC is ilustrated in the following picture. +For enanched results it is recommended for color images to preprocess image with little gaussian blur +with a small 3 x 3 kernel and additional conversion into CieLAB color space. + +![image](pics/superpixels_lsc.png) + + */ + + CV_EXPORTS_W Ptr<SuperpixelLSC> createSuperpixelLSC( InputArray image, int region_size = 10, float ratio = 0.075f ); + +//! @} + +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/paillou_filter.hpp b/include/opencv2/ximgproc/paillou_filter.hpp new file mode 100644 index 0000000..03754a1 --- /dev/null +++ b/include/opencv2/ximgproc/paillou_filter.hpp @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#ifndef __OPENCV_PAILLOUFILTER_HPP__ +#define __OPENCV_PAILLOUFILTER_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv { +namespace ximgproc { + +//! @addtogroup ximgproc_filters +//! @{ + +/** +* @brief Applies Paillou filter to an image. +* +* For more details about this implementation, please see @cite paillou1997detecting +* +* @param op Source CV_8U(S) or CV_16U(S), 1-channel or 3-channels image. +* @param _dst result CV_32F image with same number of channel than op. +* @param omega double see paper +* @param alpha double see paper +* +* @sa GradientPaillouX, GradientPaillouY +*/ +CV_EXPORTS void GradientPaillouY(InputArray op, OutputArray _dst, double alpha, double omega); +CV_EXPORTS void GradientPaillouX(InputArray op, OutputArray _dst, double alpha, double omega); + +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/peilin.hpp b/include/opencv2/ximgproc/peilin.hpp new file mode 100644 index 0000000..1b224aa --- /dev/null +++ b/include/opencv2/ximgproc/peilin.hpp @@ -0,0 +1,32 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __OPENCV_PEILIN_HPP__ +#define __OPENCV_PEILIN_HPP__ + +#include <opencv2/core.hpp> + +namespace cv { namespace ximgproc { + + //! @addtogroup ximgproc + //! @{ + + /** + * @brief Calculates an affine transformation that normalize given image using Pei&Lin Normalization. + * + * Assume given image \f$I=T(\bar{I})\f$ where \f$\bar{I}\f$ is a normalized image and \f$T\f$ is an affine transformation distorting this image by translation, rotation, scaling and skew. + * The function returns an affine transformation matrix corresponding to the transformation \f$T^{-1}\f$ described in [PeiLin95]. + * For more details about this implementation, please see + * [PeiLin95] Soo-Chang Pei and Chao-Nan Lin. Image normalization for pattern recognition. Image and Vision Computing, Vol. 13, N.10, pp. 711-723, 1995. + * + * @param I Given transformed image. + * @return Transformation matrix corresponding to inversed image transformation + */ + CV_EXPORTS Matx23d PeiLinNormalization ( InputArray I ); + /** @overload */ + CV_EXPORTS_W void PeiLinNormalization ( InputArray I, OutputArray T ); + +}} // namespace + +#endif diff --git a/include/opencv2/ximgproc/ridgefilter.hpp b/include/opencv2/ximgproc/ridgefilter.hpp new file mode 100644 index 0000000..185202b --- /dev/null +++ b/include/opencv2/ximgproc/ridgefilter.hpp @@ -0,0 +1,53 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +/* +Ridge Detection Filter. +OpenCV port by : Kushal Vyas (@kushalvyas), Venkatesh Vijaykumar(@venkateshvijaykumar) +Adapted from Niki Estner's explaination of RidgeFilter. +*/ + +#ifndef __OPENCV_XIMGPROC_RIDGEFILTER_HPP__ +#define __OPENCV_XIMGPROC_RIDGEFILTER_HPP__ + +#include <opencv2/core.hpp> + +namespace cv { namespace ximgproc { + +//! @addtogroup ximgproc_filters +//! @{ + +/** @brief Applies Ridge Detection Filter to an input image. +Implements Ridge detection similar to the one in [Mathematica](http://reference.wolfram.com/language/ref/RidgeFilter.html) +using the eigen values from the Hessian Matrix of the input image using Sobel Derivatives. +Additional refinement can be done using Skeletonization and Binarization. Adapted from @cite segleafvein and @cite M_RF + +*/ +class CV_EXPORTS_W RidgeDetectionFilter : public Algorithm +{ +public: + /** + @brief Create pointer to the Ridge detection filter. + @param ddepth Specifies output image depth. Defualt is CV_32FC1 + @param dx Order of derivative x, default is 1 + @param dy Order of derivative y, default is 1 + @param ksize Sobel kernel size , default is 3 + @param out_dtype Converted format for output, default is CV_8UC1 + @param scale Optional scale value for derivative values, default is 1 + @param delta Optional bias added to output, default is 0 + @param borderType Pixel extrapolation method, default is BORDER_DEFAULT + @see Sobel, threshold, getStructuringElement, morphologyEx.( for additional refinement) + */ + CV_WRAP static Ptr<RidgeDetectionFilter> create(int ddepth = CV_32FC1, int dx=1, int dy=1, int ksize = 3, int out_dtype=CV_8UC1, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT); + /** + @brief Apply Ridge detection filter on input image. + @param _img InputArray as supported by Sobel. img can be 1-Channel or 3-Channels. + @param out OutputAray of structure as RidgeDetectionFilter::ddepth. Output image with ridges. + */ + CV_WRAP virtual void getRidgeFilteredImage(InputArray _img, OutputArray out) = 0; +}; + +//! @} +}} // namespace +#endif diff --git a/include/opencv2/ximgproc/seeds.hpp b/include/opencv2/ximgproc/seeds.hpp new file mode 100644 index 0000000..4db8b8f --- /dev/null +++ b/include/opencv2/ximgproc/seeds.hpp @@ -0,0 +1,183 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2014, Beat Kueng (beat-kueng@gmx.net), Lukas Vogel, Morten Lysgaard +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_SEEDS_HPP__ +#define __OPENCV_SEEDS_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_superpixel +//! @{ + +/** @brief Class implementing the SEEDS (Superpixels Extracted via Energy-Driven Sampling) superpixels +algorithm described in @cite VBRV14 . + +The algorithm uses an efficient hill-climbing algorithm to optimize the superpixels' energy +function that is based on color histograms and a boundary term, which is optional. The energy +function encourages superpixels to be of the same color, and if the boundary term is activated, the +superpixels have smooth boundaries and are of similar shape. In practice it starts from a regular +grid of superpixels and moves the pixels or blocks of pixels at the boundaries to refine the +solution. The algorithm runs in real-time using a single CPU. + */ +class CV_EXPORTS_W SuperpixelSEEDS : public Algorithm +{ +public: + + /** @brief Calculates the superpixel segmentation on a given image stored in SuperpixelSEEDS object. + + The function computes the superpixels segmentation of an image with the parameters initialized + with the function createSuperpixelSEEDS(). + */ + CV_WRAP virtual int getNumberOfSuperpixels() = 0; + + /** @brief Calculates the superpixel segmentation on a given image with the initialized + parameters in the SuperpixelSEEDS object. + + This function can be called again for other images without the need of initializing the + algorithm with createSuperpixelSEEDS(). This save the computational cost of allocating memory + for all the structures of the algorithm. + + @param img Input image. Supported formats: CV_8U, CV_16U, CV_32F. Image size & number of + channels must match with the initialized image size & channels with the function + createSuperpixelSEEDS(). It should be in HSV or Lab color space. Lab is a bit better, but also + slower. + + @param num_iterations Number of pixel level iterations. Higher number improves the result. + + The function computes the superpixels segmentation of an image with the parameters initialized + with the function createSuperpixelSEEDS(). The algorithms starts from a grid of superpixels and + then refines the boundaries by proposing updates of blocks of pixels that lie at the boundaries + from large to smaller size, finalizing with proposing pixel updates. An illustrative example + can be seen below. + + ![image](pics/superpixels_blocks2.png) + */ + CV_WRAP virtual void iterate(InputArray img, int num_iterations=4) = 0; + + /** @brief Returns the segmentation labeling of the image. + + Each label represents a superpixel, and each pixel is assigned to one superpixel label. + + @param labels_out Return: A CV_32UC1 integer array containing the labels of the superpixel + segmentation. The labels are in the range [0, getNumberOfSuperpixels()]. + + The function returns an image with ssthe labels of the superpixel segmentation. The labels are in + the range [0, getNumberOfSuperpixels()]. + */ + CV_WRAP virtual void getLabels(OutputArray labels_out) = 0; + + /** @brief Returns the mask of the superpixel segmentation stored in SuperpixelSEEDS object. + + @param image Return: CV_8UC1 image mask where -1 indicates that the pixel is a superpixel border, + and 0 otherwise. + + @param thick_line If false, the border is only one pixel wide, otherwise all pixels at the border + are masked. + + The function return the boundaries of the superpixel segmentation. + + @note + - (Python) A demo on how to generate superpixels in images from the webcam can be found at + opencv_source_code/samples/python2/seeds.py + - (cpp) A demo on how to generate superpixels in images from the webcam can be found at + opencv_source_code/modules/ximgproc/samples/seeds.cpp. By adding a file image as a command + line argument, the static image will be used instead of the webcam. + - It will show a window with the video from the webcam with the superpixel boundaries marked + in red (see below). Use Space to switch between different output modes. At the top of the + window there are 4 sliders, from which the user can change on-the-fly the number of + superpixels, the number of block levels, the strength of the boundary prior term to modify + the shape, and the number of iterations at pixel level. This is useful to play with the + parameters and set them to the user convenience. In the console the frame-rate of the + algorithm is indicated. + + ![image](pics/superpixels_demo.png) + */ + CV_WRAP virtual void getLabelContourMask(OutputArray image, bool thick_line = false) = 0; + + virtual ~SuperpixelSEEDS() {} +}; + +/** @brief Initializes a SuperpixelSEEDS object. + +@param image_width Image width. +@param image_height Image height. +@param image_channels Number of channels of the image. +@param num_superpixels Desired number of superpixels. Note that the actual number may be smaller +due to restrictions (depending on the image size and num_levels). Use getNumberOfSuperpixels() to +get the actual number. +@param num_levels Number of block levels. The more levels, the more accurate is the segmentation, +but needs more memory and CPU time. +@param prior enable 3x3 shape smoothing term if \>0. A larger value leads to smoother shapes. prior +must be in the range [0, 5]. +@param histogram_bins Number of histogram bins. +@param double_step If true, iterate each block level twice for higher accuracy. + +The function initializes a SuperpixelSEEDS object for the input image. It stores the parameters of +the image: image_width, image_height and image_channels. It also sets the parameters of the SEEDS +superpixel algorithm, which are: num_superpixels, num_levels, use_prior, histogram_bins and +double_step. + +The number of levels in num_levels defines the amount of block levels that the algorithm use in the +optimization. The initialization is a grid, in which the superpixels are equally distributed through +the width and the height of the image. The larger blocks correspond to the superpixel size, and the +levels with smaller blocks are formed by dividing the larger blocks into 2 x 2 blocks of pixels, +recursively until the smaller block level. An example of initialization of 4 block levels is +illustrated in the following figure. + +![image](pics/superpixels_blocks.png) + */ +CV_EXPORTS_W Ptr<SuperpixelSEEDS> createSuperpixelSEEDS( + int image_width, int image_height, int image_channels, + int num_superpixels, int num_levels, int prior = 2, + int histogram_bins=5, bool double_step = false); + +//! @} + +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/segmentation.hpp b/include/opencv2/ximgproc/segmentation.hpp new file mode 100644 index 0000000..19d032b --- /dev/null +++ b/include/opencv2/ximgproc/segmentation.hpp @@ -0,0 +1,252 @@ +/* +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) +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. +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. +*/ + +#ifndef __OPENCV_XIMGPROC_SEGMENTATION_HPP__ +#define __OPENCV_XIMGPROC_SEGMENTATION_HPP__ + +#include <opencv2/core.hpp> + +namespace cv { + namespace ximgproc { + namespace segmentation { + //! @addtogroup ximgproc_segmentation + //! @{ + + /** @brief Graph Based Segmentation Algorithm. + The class implements the algorithm described in @cite PFF2004 . + */ + class CV_EXPORTS_W GraphSegmentation : public Algorithm { + public: + /** @brief Segment an image and store output in dst + @param src The input image. Any number of channel (1 (Eg: Gray), 3 (Eg: RGB), 4 (Eg: RGB-D)) can be provided + @param dst The output segmentation. It's a CV_32SC1 Mat with the same number of cols and rows as input image, with an unique, sequential, id for each pixel. + */ + CV_WRAP virtual void processImage(InputArray src, OutputArray dst) = 0; + + CV_WRAP virtual void setSigma(double sigma) = 0; + CV_WRAP virtual double getSigma() = 0; + + CV_WRAP virtual void setK(float k) = 0; + CV_WRAP virtual float getK() = 0; + + CV_WRAP virtual void setMinSize(int min_size) = 0; + CV_WRAP virtual int getMinSize() = 0; + }; + + /** @brief Creates a graph based segmentor + @param sigma The sigma parameter, used to smooth image + @param k The k parameter of the algorythm + @param min_size The minimum size of segments + */ + CV_EXPORTS_W Ptr<GraphSegmentation> createGraphSegmentation(double sigma=0.5, float k=300, int min_size=100); + + /** @brief Strategie for the selective search segmentation algorithm + The class implements a generic stragery for the algorithm described in @cite uijlings2013selective. + */ + class CV_EXPORTS_W SelectiveSearchSegmentationStrategy : public Algorithm { + public: + /** @brief Set a initial image, with a segementation. + @param img The input image. Any number of channel can be provided + @param regions A segementation of the image. The parameter must be the same size of img. + @param sizes The sizes of different regions + @param image_id If not set to -1, try to cache pre-computations. If the same set og (img, regions, size) is used, the image_id need to be the same. + */ + CV_WRAP virtual void setImage(InputArray img, InputArray regions, InputArray sizes, int image_id = -1) = 0; + + /** @brief Return the score between two regions (between 0 and 1) + @param r1 The first region + @param r2 The second region + */ + CV_WRAP virtual float get(int r1, int r2) = 0; + + /** @brief Inform the strategy that two regions will be merged + @param r1 The first region + @param r2 The second region + */ + CV_WRAP virtual void merge(int r1, int r2) = 0; + }; + + /** @brief Color-based strategy for the selective search segmentation algorithm + The class is implemented from the algorithm described in @cite uijlings2013selective. + */ + class CV_EXPORTS_W SelectiveSearchSegmentationStrategyColor : public SelectiveSearchSegmentationStrategy { + }; + + /** @brief Create a new color-based strategy */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyColor> createSelectiveSearchSegmentationStrategyColor(); + + /** @brief Size-based strategy for the selective search segmentation algorithm + The class is implemented from the algorithm described in @cite uijlings2013selective. + */ + class CV_EXPORTS_W SelectiveSearchSegmentationStrategySize : public SelectiveSearchSegmentationStrategy { + }; + + /** @brief Create a new size-based strategy */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategySize> createSelectiveSearchSegmentationStrategySize(); + + /** @brief Texture-based strategy for the selective search segmentation algorithm + The class is implemented from the algorithm described in @cite uijlings2013selective. + */ + class CV_EXPORTS_W SelectiveSearchSegmentationStrategyTexture : public SelectiveSearchSegmentationStrategy { + }; + + /** @brief Create a new size-based strategy */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyTexture> createSelectiveSearchSegmentationStrategyTexture(); + + /** @brief Fill-based strategy for the selective search segmentation algorithm + The class is implemented from the algorithm described in @cite uijlings2013selective. + */ + class CV_EXPORTS_W SelectiveSearchSegmentationStrategyFill : public SelectiveSearchSegmentationStrategy { + }; + + /** @brief Create a new fill-based strategy */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyFill> createSelectiveSearchSegmentationStrategyFill(); + + /** @brief Regroup multiple strategies for the selective search segmentation algorithm + */ + class CV_EXPORTS_W SelectiveSearchSegmentationStrategyMultiple : public SelectiveSearchSegmentationStrategy { + public: + + /** @brief Add a new sub-strategy + @param g The strategy + @param weight The weight of the strategy + */ + CV_WRAP virtual void addStrategy(Ptr<SelectiveSearchSegmentationStrategy> g, float weight) = 0; + /** @brief Remove all sub-strategies + */ + CV_WRAP virtual void clearStrategies() = 0; + }; + + /** @brief Create a new multiple strategy */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(); + + /** @brief Create a new multiple strategy and set one subtrategy + @param s1 The first strategy + */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1); + + /** @brief Create a new multiple strategy and set two subtrategies, with equal weights + @param s1 The first strategy + @param s2 The second strategy + */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1, Ptr<SelectiveSearchSegmentationStrategy> s2); + + + /** @brief Create a new multiple strategy and set three subtrategies, with equal weights + @param s1 The first strategy + @param s2 The second strategy + @param s3 The third strategy + */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1, Ptr<SelectiveSearchSegmentationStrategy> s2, Ptr<SelectiveSearchSegmentationStrategy> s3); + + /** @brief Create a new multiple strategy and set four subtrategies, with equal weights + @param s1 The first strategy + @param s2 The second strategy + @param s3 The third strategy + @param s4 The forth strategy + */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1, Ptr<SelectiveSearchSegmentationStrategy> s2, Ptr<SelectiveSearchSegmentationStrategy> s3, Ptr<SelectiveSearchSegmentationStrategy> s4); + + /** @brief Selective search segmentation algorithm + The class implements the algorithm described in @cite uijlings2013selective. + */ + class CV_EXPORTS_W SelectiveSearchSegmentation : public Algorithm { + public: + + /** @brief Set a image used by switch* functions to initialize the class + @param img The image + */ + CV_WRAP virtual void setBaseImage(InputArray img) = 0; + + /** @brief Initialize the class with the 'Single stragegy' parameters describled in @cite uijlings2013selective. + @param k The k parameter for the graph segmentation + @param sigma The sigma parameter for the graph segmentation + */ + CV_WRAP virtual void switchToSingleStrategy(int k = 200, float sigma = 0.8f) = 0; + + /** @brief Initialize the class with the 'Selective search fast' parameters describled in @cite uijlings2013selective. + @param base_k The k parameter for the first graph segmentation + @param inc_k The increment of the k parameter for all graph segmentations + @param sigma The sigma parameter for the graph segmentation + */ + CV_WRAP virtual void switchToSelectiveSearchFast(int base_k = 150, int inc_k = 150, float sigma = 0.8f) = 0; + + /** @brief Initialize the class with the 'Selective search fast' parameters describled in @cite uijlings2013selective. + @param base_k The k parameter for the first graph segmentation + @param inc_k The increment of the k parameter for all graph segmentations + @param sigma The sigma parameter for the graph segmentation + */ + CV_WRAP virtual void switchToSelectiveSearchQuality(int base_k = 150, int inc_k = 150, float sigma = 0.8f) = 0; + + /** @brief Add a new image in the list of images to process. + @param img The image + */ + CV_WRAP virtual void addImage(InputArray img) = 0; + + /** @brief Clear the list of images to process + */ + CV_WRAP virtual void clearImages() = 0; + + /** @brief Add a new graph segmentation in the list of graph segementations to process. + @param g The graph segmentation + */ + CV_WRAP virtual void addGraphSegmentation(Ptr<GraphSegmentation> g) = 0; + + /** @brief Clear the list of graph segmentations to process; + */ + CV_WRAP virtual void clearGraphSegmentations() = 0; + + /** @brief Add a new strategy in the list of strategy to process. + @param s The strategy + */ + CV_WRAP virtual void addStrategy(Ptr<SelectiveSearchSegmentationStrategy> s) = 0; + + /** @brief Clear the list of strategy to process; + */ + CV_WRAP virtual void clearStrategies() = 0; + + /** @brief Based on all images, graph segmentations and stragies, computes all possible rects and return them + @param rects The list of rects. The first ones are more relevents than the lasts ones. + */ + CV_WRAP virtual void process(CV_OUT std::vector<Rect>& rects) = 0; + }; + + /** @brief Create a new SelectiveSearchSegmentation class. + */ + CV_EXPORTS_W Ptr<SelectiveSearchSegmentation> createSelectiveSearchSegmentation(); + + //! @} + + } + } +} + +#endif diff --git a/include/opencv2/ximgproc/slic.hpp b/include/opencv2/ximgproc/slic.hpp new file mode 100644 index 0000000..f9f125c --- /dev/null +++ b/include/opencv2/ximgproc/slic.hpp @@ -0,0 +1,169 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2013 + * Radhakrishna Achanta + * email : Radhakrishna [dot] Achanta [at] epfl [dot] ch + * web : http://ivrl.epfl.ch/people/achanta + * + * 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 name of the copyright holders nor the names of its + * 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 THE + * COPYRIGHT OWNER 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. + *********************************************************************/ + +/* + "SLIC Superpixels Compared to State-of-the-art Superpixel Methods" + Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, + and Sabine Susstrunk, IEEE TPAMI, Volume 34, Issue 11, Pages 2274-2282, + November 2012. + + "SLIC Superpixels" Radhakrishna Achanta, Appu Shaji, Kevin Smith, + Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk, EPFL Technical + Report no. 149300, June 2010. + + OpenCV port by: Cristian Balint <cristian dot balint at gmail dot com> + */ + +#ifndef __OPENCV_SLIC_HPP__ +#define __OPENCV_SLIC_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_superpixel +//! @{ + + enum SLIC { SLIC = 100, SLICO = 101, MSLIC = 102 }; + typedef enum SLIC SLICType; + +/** @brief Class implementing the SLIC (Simple Linear Iterative Clustering) superpixels +algorithm described in @cite Achanta2012. + +SLIC (Simple Linear Iterative Clustering) clusters pixels using pixel channels and image plane space +to efficiently generate compact, nearly uniform superpixels. The simplicity of approach makes it +extremely easy to use a lone parameter specifies the number of superpixels and the efficiency of +the algorithm makes it very practical. +Several optimizations are available for SLIC class: +SLICO stands for "Zero parameter SLIC" and it is an optimization of baseline SLIC descibed in @cite Achanta2012. +MSLIC stands for "Manifold SLIC" and it is an optimization of baseline SLIC described in @cite Liu_2017_IEEE. + */ + +class CV_EXPORTS_W SuperpixelSLIC : public Algorithm +{ +public: + + /** @brief Calculates the actual amount of superpixels on a given segmentation computed + and stored in SuperpixelSLIC object. + */ + CV_WRAP virtual int getNumberOfSuperpixels() const = 0; + + /** @brief Calculates the superpixel segmentation on a given image with the initialized + parameters in the SuperpixelSLIC object. + + This function can be called again without the need of initializing the algorithm with + createSuperpixelSLIC(). This save the computational cost of allocating memory for all the + structures of the algorithm. + + @param num_iterations Number of iterations. Higher number improves the result. + + The function computes the superpixels segmentation of an image with the parameters initialized + with the function createSuperpixelSLIC(). The algorithms starts from a grid of superpixels and + then refines the boundaries by proposing updates of edges boundaries. + + */ + CV_WRAP virtual void iterate( int num_iterations = 10 ) = 0; + + /** @brief Returns the segmentation labeling of the image. + + Each label represents a superpixel, and each pixel is assigned to one superpixel label. + + @param labels_out Return: A CV_32SC1 integer array containing the labels of the superpixel + segmentation. The labels are in the range [0, getNumberOfSuperpixels()]. + + The function returns an image with the labels of the superpixel segmentation. The labels are in + the range [0, getNumberOfSuperpixels()]. + */ + CV_WRAP virtual void getLabels( OutputArray labels_out ) const = 0; + + /** @brief Returns the mask of the superpixel segmentation stored in SuperpixelSLIC object. + + @param image Return: CV_8U1 image mask where -1 indicates that the pixel is a superpixel border, + and 0 otherwise. + + @param thick_line If false, the border is only one pixel wide, otherwise all pixels at the border + are masked. + + The function return the boundaries of the superpixel segmentation. + */ + CV_WRAP virtual void getLabelContourMask( OutputArray image, bool thick_line = true ) const = 0; + + /** @brief Enforce label connectivity. + + @param min_element_size The minimum element size in percents that should be absorbed into a bigger + superpixel. Given resulted average superpixel size valid value should be in 0-100 range, 25 means + that less then a quarter sized superpixel should be absorbed, this is default. + + The function merge component that is too small, assigning the previously found adjacent label + to this component. Calling this function may change the final number of superpixels. + */ + CV_WRAP virtual void enforceLabelConnectivity( int min_element_size = 25 ) = 0; + + +}; + +/** @brief Initialize a SuperpixelSLIC object + +@param image Image to segment +@param algorithm Chooses the algorithm variant to use: +SLIC segments image using a desired region_size, and in addition SLICO will optimize using adaptive compactness factor, +while MSLIC will optimize using manifold methods resulting in more content-sensitive superpixels. +@param region_size Chooses an average superpixel size measured in pixels +@param ruler Chooses the enforcement of superpixel smoothness factor of superpixel + +The function initializes a SuperpixelSLIC object for the input image. It sets the parameters of choosed +superpixel algorithm, which are: region_size and ruler. It preallocate some buffers for future +computing iterations over the given image. For enanched results it is recommended for color images to +preprocess image with little gaussian blur using a small 3 x 3 kernel and additional conversion into +CieLAB color space. An example of SLIC versus SLICO and MSLIC is ilustrated in the following picture. + +![image](pics/superpixels_slic.png) + + */ + + CV_EXPORTS_W Ptr<SuperpixelSLIC> createSuperpixelSLIC( InputArray image, int algorithm = SLICO, + int region_size = 10, float ruler = 10.0f ); + +//! @} + +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/sparse_match_interpolator.hpp b/include/opencv2/ximgproc/sparse_match_interpolator.hpp new file mode 100644 index 0000000..fffcfd6 --- /dev/null +++ b/include/opencv2/ximgproc/sparse_match_interpolator.hpp @@ -0,0 +1,132 @@ +/* + * 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. + */ + +#ifndef __OPENCV_SPARSEMATCHINTERPOLATOR_HPP__ +#define __OPENCV_SPARSEMATCHINTERPOLATOR_HPP__ +#ifdef __cplusplus + +#include <opencv2/core.hpp> + +namespace cv { +namespace ximgproc { + +//! @addtogroup ximgproc_filters +//! @{ + +/** @brief Main interface for all filters, that take sparse matches as an +input and produce a dense per-pixel matching (optical flow) as an output. + */ +class CV_EXPORTS_W SparseMatchInterpolator : public Algorithm +{ +public: + /** @brief Interpolate input sparse matches. + + @param from_image first of the two matched images, 8-bit single-channel or three-channel. + + @param from_points points of the from_image for which there are correspondences in the + to_image (Point2f vector, size shouldn't exceed 32767) + + @param to_image second of the two matched images, 8-bit single-channel or three-channel. + + @param to_points points in the to_image corresponding to from_points + (Point2f vector, size shouldn't exceed 32767) + + @param dense_flow output dense matching (two-channel CV_32F image) + */ + CV_WRAP virtual void interpolate(InputArray from_image, InputArray from_points, + InputArray to_image , InputArray to_points, + OutputArray dense_flow) = 0; +}; + +/** @brief Sparse match interpolation algorithm based on modified locally-weighted affine +estimator from @cite Revaud2015 and Fast Global Smoother as post-processing filter. + */ +class CV_EXPORTS_W EdgeAwareInterpolator : public SparseMatchInterpolator +{ +public: + /** @brief K is a number of nearest-neighbor matches considered, when fitting a locally affine + model. Usually it should be around 128. However, lower values would make the interpolation + noticeably faster. + */ + CV_WRAP virtual void setK(int _k) = 0; + /** @see setK */ + CV_WRAP virtual int getK() = 0; + + /** @brief Sigma is a parameter defining how fast the weights decrease in the locally-weighted affine + fitting. Higher values can help preserve fine details, lower values can help to get rid of noise in the + output flow. + */ + CV_WRAP virtual void setSigma(float _sigma) = 0; + /** @see setSigma */ + CV_WRAP virtual float getSigma() = 0; + + /** @brief Lambda is a parameter defining the weight of the edge-aware term in geodesic distance, + should be in the range of 0 to 1000. + */ + CV_WRAP virtual void setLambda(float _lambda) = 0; + /** @see setLambda */ + CV_WRAP virtual float getLambda() = 0; + + /** @brief Sets whether the fastGlobalSmootherFilter() post-processing is employed. It is turned on by + default. + */ + CV_WRAP virtual void setUsePostProcessing(bool _use_post_proc) = 0; + /** @see setUsePostProcessing */ + CV_WRAP virtual bool getUsePostProcessing() = 0; + + /** @brief Sets the respective fastGlobalSmootherFilter() parameter. + */ + CV_WRAP virtual void setFGSLambda(float _lambda) = 0; + /** @see setFGSLambda */ + CV_WRAP virtual float getFGSLambda() = 0; + + /** @see setFGSLambda */ + CV_WRAP virtual void setFGSSigma(float _sigma) = 0; + /** @see setFGSLambda */ + CV_WRAP virtual float getFGSSigma() = 0; +}; + +/** @brief Factory method that creates an instance of the +EdgeAwareInterpolator. +*/ +CV_EXPORTS_W +Ptr<EdgeAwareInterpolator> createEdgeAwareInterpolator(); + +//! @} +} +} +#endif +#endif diff --git a/include/opencv2/ximgproc/structured_edge_detection.hpp b/include/opencv2/ximgproc/structured_edge_detection.hpp new file mode 100644 index 0000000..b0eb777 --- /dev/null +++ b/include/opencv2/ximgproc/structured_edge_detection.hpp @@ -0,0 +1,148 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_STRUCTURED_EDGE_DETECTION_HPP__ +#define __OPENCV_STRUCTURED_EDGE_DETECTION_HPP__ +#ifdef __cplusplus + +/** @file +@date Jun 17, 2014 +@author Yury Gitman + */ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ximgproc +{ + +//! @addtogroup ximgproc_edge +//! @{ + +/*! + Helper class for training part of [P. Dollar and C. L. Zitnick. Structured Forests for Fast Edge Detection, 2013]. + */ +class CV_EXPORTS_W RFFeatureGetter : public Algorithm +{ +public: + + /*! + * This functions extracts feature channels from src. + * Than StructureEdgeDetection uses this feature space + * to detect edges. + * + * \param src : source image to extract features + * \param features : output n-channel floating point feature matrix. + * + * \param gnrmRad : __rf.options.gradientNormalizationRadius + * \param gsmthRad : __rf.options.gradientSmoothingRadius + * \param shrink : __rf.options.shrinkNumber + * \param outNum : __rf.options.numberOfOutputChannels + * \param gradNum : __rf.options.numberOfGradientOrientations + */ + CV_WRAP virtual void getFeatures(const Mat &src, Mat &features, + const int gnrmRad, + const int gsmthRad, + const int shrink, + const int outNum, + const int gradNum) const = 0; +}; + +CV_EXPORTS_W Ptr<RFFeatureGetter> createRFFeatureGetter(); + + + +/** @brief Class implementing edge detection algorithm from @cite Dollar2013 : + */ +class CV_EXPORTS_W StructuredEdgeDetection : public Algorithm +{ +public: + + /** @brief The function detects edges in src and draw them to dst. + + The algorithm underlies this function is much more robust to texture presence, than common + approaches, e.g. Sobel + @param _src source image (RGB, float, in [0;1]) to detect edges + @param _dst destination image (grayscale, float, in [0;1]) where edges are drawn + @sa Sobel, Canny + */ + CV_WRAP virtual void detectEdges(cv::InputArray _src, cv::OutputArray _dst) const = 0; + + /** @brief The function computes orientation from edge image. + + @param _src edge image. + @param _dst orientation image. + */ + CV_WRAP virtual void computeOrientation(cv::InputArray _src, cv::OutputArray _dst) const = 0; + + + /** @brief The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction. + + @param edge_image edge image from detectEdges function. + @param orientation_image orientation image from computeOrientation function. + @param _dst suppressed image (grayscale, float, in [0;1]) + @param r radius for NMS suppression. + @param s radius for boundary suppression. + @param m multiplier for conservative suppression. + @param isParallel enables/disables parallel computing. + */ + CV_WRAP virtual void edgesNms(cv::InputArray edge_image, cv::InputArray orientation_image, cv::OutputArray _dst, int r = 2, int s = 0, float m = 1, bool isParallel = true) const = 0; +}; + +/*! +* The only constructor +* +* \param model : name of the file where the model is stored +* \param howToGetFeatures : optional object inheriting from RFFeatureGetter. +* You need it only if you would like to train your +* own forest, pass NULL otherwise +*/ +CV_EXPORTS_W Ptr<StructuredEdgeDetection> createStructuredEdgeDetection(const String &model, + Ptr<const RFFeatureGetter> howToGetFeatures = Ptr<RFFeatureGetter>()); + +//! @} + +} +} +#endif +#endif /* __OPENCV_STRUCTURED_EDGE_DETECTION_HPP__ */ diff --git a/include/opencv2/ximgproc/weighted_median_filter.hpp b/include/opencv2/ximgproc/weighted_median_filter.hpp new file mode 100644 index 0000000..d3da29e --- /dev/null +++ b/include/opencv2/ximgproc/weighted_median_filter.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2015, The Chinese University of Hong Kong, all rights reserved. +// +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_WEIGHTED_MEDIAN_FILTER_HPP__ +#define __OPENCV_WEIGHTED_MEDIAN_FILTER_HPP__ +#ifdef __cplusplus + +/** +* @file +* @date Sept 9, 2015 +* @author Zhou Chao +*/ + +#include <opencv2/core.hpp> +#include <string> + +namespace cv +{ +namespace ximgproc +{ + +/** +* @brief Specifies weight types of weighted median filter. +*/ +enum WMFWeightType +{ + WMF_EXP = 1 , //!< \f$exp(-|I1-I2|^2/(2*sigma^2))\f$ + WMF_IV1 = 1 << 1, //!< \f$(|I1-I2|+sigma)^-1\f$ + WMF_IV2 = 1 << 2, //!< \f$(|I1-I2|^2+sigma^2)^-1\f$ + WMF_COS = 1 << 3, //!< \f$dot(I1,I2)/(|I1|*|I2|)\f$ + WMF_JAC = 1 << 4, //!< \f$(min(r1,r2)+min(g1,g2)+min(b1,b2))/(max(r1,r2)+max(g1,g2)+max(b1,b2))\f$ + WMF_OFF = 1 << 5 //!< unweighted +}; + +/** +* @brief Applies weighted median filter to an image. +* +* For more details about this implementation, please see @cite zhang2014100+ +* +* @param joint Joint 8-bit, 1-channel or 3-channel image. +* @param src Source 8-bit or floating-point, 1-channel or 3-channel image. +* @param dst Destination image. +* @param r Radius of filtering kernel, should be a positive integer. +* @param sigma Filter range standard deviation for the joint image. +* @param weightType weightType The type of weight definition, see WMFWeightType +* @param mask A 0-1 mask that has the same size with I. This mask is used to ignore the effect of some pixels. If the pixel value on mask is 0, +* the pixel will be ignored when maintaining the joint-histogram. This is useful for applications like optical flow occlusion handling. +* +* @sa medianBlur, jointBilateralFilter +*/ +CV_EXPORTS_W void weightedMedianFilter(InputArray joint, InputArray src, OutputArray dst, + int r, double sigma = 25.5, int weightType = WMF_EXP, InputArray mask = noArray()); +} +} + +#endif +#endif diff --git a/include/opencv2/xobjdetect.hpp b/include/opencv2/xobjdetect.hpp new file mode 100644 index 0000000..13dde11 --- /dev/null +++ b/include/opencv2/xobjdetect.hpp @@ -0,0 +1,104 @@ +/* + +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) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +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. + +*/ + +#ifndef __OPENCV_XOBJDETECT_XOBJDETECT_HPP__ +#define __OPENCV_XOBJDETECT_XOBJDETECT_HPP__ + +#include <opencv2/core.hpp> +#include <vector> +#include <string> + +/** @defgroup xobjdetect Extended object detection +*/ +namespace cv +{ +namespace xobjdetect +{ +//! @addtogroup xobjdetect +//! @{ + + +/** @brief WaldBoost detector +*/ +class CV_EXPORTS WBDetector { +public: + /** @brief Read detector from FileNode. + @param node FileNode for input + */ + virtual void read(const FileNode &node) = 0; + + /** @brief Write detector to FileStorage. + @param fs FileStorage for output + */ + virtual void write(FileStorage &fs) const = 0; + + /** @brief Train WaldBoost detector + @param pos_samples Path to directory with cropped positive samples + @param neg_imgs Path to directory with negative (background) images + */ + virtual void train( + const std::string& pos_samples, + const std::string& neg_imgs) = 0; + + /** @brief Detect objects on image using WaldBoost detector + @param img Input image for detection + @param bboxes Bounding boxes coordinates output vector + @param confidences Confidence values for bounding boxes output vector + */ + virtual void detect( + const Mat& img, + std::vector<Rect> &bboxes, + std::vector<double> &confidences) = 0; + + /** @brief Create instance of WBDetector + */ + static Ptr<WBDetector> create(); + + virtual ~WBDetector(){} +}; + + +//! @} + +} /* namespace xobjdetect */ +} /* namespace cv */ + +#endif /* __OPENCV_XOBJDETECT_XOBJDETECT_HPP__ */ diff --git a/include/opencv2/xphoto.hpp b/include/opencv2/xphoto.hpp new file mode 100644 index 0000000..14d5d53 --- /dev/null +++ b/include/opencv2/xphoto.hpp @@ -0,0 +1,55 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_XPHOTO_HPP__ +#define __OPENCV_XPHOTO_HPP__ + +/** @defgroup xphoto Additional photo processing algorithms +*/ + +#include "xphoto/inpainting.hpp" +#include "xphoto/white_balance.hpp" +#include "xphoto/dct_image_denoising.hpp" +#include "xphoto/bm3d_image_denoising.hpp" +#include "xphoto/tonemap.hpp" + +#endif diff --git a/include/opencv2/xphoto/bm3d_image_denoising.hpp b/include/opencv2/xphoto/bm3d_image_denoising.hpp new file mode 100644 index 0000000..5873f4c --- /dev/null +++ b/include/opencv2/xphoto/bm3d_image_denoising.hpp @@ -0,0 +1,186 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_BM3D_IMAGE_DENOISING_HPP__ +#define __OPENCV_BM3D_IMAGE_DENOISING_HPP__ + +/** @file +@date Jul 19, 2016 +@author Bartek Pawlik +*/ + +#include <opencv2/core.hpp> + +namespace cv +{ + namespace xphoto + { + //! @addtogroup xphoto + //! @{ + + //! BM3D transform types + enum TransformTypes + { + /** Un-normalized Haar transform */ + HAAR = 0 + }; + + //! BM3D algorithm steps + enum Bm3dSteps + { + /** Execute all steps of the algorithm */ + BM3D_STEPALL = 0, + /** Execute only first step of the algorithm */ + BM3D_STEP1 = 1, + /** Execute only second step of the algorithm */ + BM3D_STEP2 = 2 + }; + + /** @brief Performs image denoising using the Block-Matching and 3D-filtering algorithm + <http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf> with several computational + optimizations. Noise expected to be a gaussian white noise. + + @param src Input 8-bit or 16-bit 1-channel image. + @param dstStep1 Output image of the first step of BM3D with the same size and type as src. + @param dstStep2 Output image of the second step of BM3D with the same size and type as src. + @param h Parameter regulating filter strength. Big h value perfectly removes noise but also + removes image details, smaller h value preserves details but also preserves some noise. + @param templateWindowSize Size in pixels of the template patch that is used for block-matching. + Should be power of 2. + @param searchWindowSize Size in pixels of the window that is used to perform block-matching. + Affect performance linearly: greater searchWindowsSize - greater denoising time. + Must be larger than templateWindowSize. + @param blockMatchingStep1 Block matching threshold for the first step of BM3D (hard thresholding), + i.e. maximum distance for which two blocks are considered similar. + Value expressed in euclidean distance. + @param blockMatchingStep2 Block matching threshold for the second step of BM3D (Wiener filtering), + i.e. maximum distance for which two blocks are considered similar. + Value expressed in euclidean distance. + @param groupSize Maximum size of the 3D group for collaborative filtering. + @param slidingStep Sliding step to process every next reference block. + @param beta Kaiser window parameter that affects the sidelobe attenuation of the transform of the + window. Kaiser window is used in order to reduce border effects. To prevent usage of the window, + set beta to zero. + @param normType Norm used to calculate distance between blocks. L2 is slower than L1 + but yields more accurate results. + @param step Step of BM3D to be executed. Possible variants are: step 1, step 2, both steps. + @param transformType Type of the orthogonal transform used in collaborative filtering step. + Currently only Haar transform is supported. + + This function expected to be applied to grayscale images. Advanced usage of this function + can be manual denoising of colored image in different colorspaces. + + @sa + fastNlMeansDenoising + */ + CV_EXPORTS_W void bm3dDenoising( + InputArray src, + InputOutputArray dstStep1, + OutputArray dstStep2, + float h = 1, + int templateWindowSize = 4, + int searchWindowSize = 16, + int blockMatchingStep1 = 2500, + int blockMatchingStep2 = 400, + int groupSize = 8, + int slidingStep = 1, + float beta = 2.0f, + int normType = cv::NORM_L2, + int step = cv::xphoto::BM3D_STEPALL, + int transformType = cv::xphoto::HAAR); + + /** @brief Performs image denoising using the Block-Matching and 3D-filtering algorithm + <http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf> with several computational + optimizations. Noise expected to be a gaussian white noise. + + @param src Input 8-bit or 16-bit 1-channel image. + @param dst Output image with the same size and type as src. + @param h Parameter regulating filter strength. Big h value perfectly removes noise but also + removes image details, smaller h value preserves details but also preserves some noise. + @param templateWindowSize Size in pixels of the template patch that is used for block-matching. + Should be power of 2. + @param searchWindowSize Size in pixels of the window that is used to perform block-matching. + Affect performance linearly: greater searchWindowsSize - greater denoising time. + Must be larger than templateWindowSize. + @param blockMatchingStep1 Block matching threshold for the first step of BM3D (hard thresholding), + i.e. maximum distance for which two blocks are considered similar. + Value expressed in euclidean distance. + @param blockMatchingStep2 Block matching threshold for the second step of BM3D (Wiener filtering), + i.e. maximum distance for which two blocks are considered similar. + Value expressed in euclidean distance. + @param groupSize Maximum size of the 3D group for collaborative filtering. + @param slidingStep Sliding step to process every next reference block. + @param beta Kaiser window parameter that affects the sidelobe attenuation of the transform of the + window. Kaiser window is used in order to reduce border effects. To prevent usage of the window, + set beta to zero. + @param normType Norm used to calculate distance between blocks. L2 is slower than L1 + but yields more accurate results. + @param step Step of BM3D to be executed. Allowed are only BM3D_STEP1 and BM3D_STEPALL. + BM3D_STEP2 is not allowed as it requires basic estimate to be present. + @param transformType Type of the orthogonal transform used in collaborative filtering step. + Currently only Haar transform is supported. + + This function expected to be applied to grayscale images. Advanced usage of this function + can be manual denoising of colored image in different colorspaces. + + @sa + fastNlMeansDenoising + */ + CV_EXPORTS_W void bm3dDenoising( + InputArray src, + OutputArray dst, + float h = 1, + int templateWindowSize = 4, + int searchWindowSize = 16, + int blockMatchingStep1 = 2500, + int blockMatchingStep2 = 400, + int groupSize = 8, + int slidingStep = 1, + float beta = 2.0f, + int normType = cv::NORM_L2, + int step = cv::xphoto::BM3D_STEPALL, + int transformType = cv::xphoto::HAAR); + //! @} + } +} + +#endif // __OPENCV_BM3D_IMAGE_DENOISING_HPP__ diff --git a/include/opencv2/xphoto/dct_image_denoising.hpp b/include/opencv2/xphoto/dct_image_denoising.hpp new file mode 100644 index 0000000..bfb77fe --- /dev/null +++ b/include/opencv2/xphoto/dct_image_denoising.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_DCT_IMAGE_DENOISING_HPP__ +#define __OPENCV_DCT_IMAGE_DENOISING_HPP__ + +/** @file +@date Jun 26, 2014 +@author Yury Gitman +*/ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace xphoto +{ + +//! @addtogroup xphoto +//! @{ + + /** @brief The function implements simple dct-based denoising + + <http://www.ipol.im/pub/art/2011/ys-dct/>. + @param src source image + @param dst destination image + @param sigma expected noise standard deviation + @param psize size of block side where dct is computed + + @sa + fastNlMeansDenoising + */ + CV_EXPORTS_W void dctDenoising(const Mat &src, Mat &dst, const double sigma, const int psize = 16); + +//! @} + +} +} + +#endif // __OPENCV_DCT_IMAGE_DENOISING_HPP__ diff --git a/include/opencv2/xphoto/inpainting.hpp b/include/opencv2/xphoto/inpainting.hpp new file mode 100644 index 0000000..9c40e8c --- /dev/null +++ b/include/opencv2/xphoto/inpainting.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_INPAINTING_HPP__ +#define __OPENCV_INPAINTING_HPP__ + +/** @file +@date Jul 22, 2014 +@author Yury Gitman +*/ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace xphoto +{ + +//! @addtogroup xphoto +//! @{ + + //! various inpainting algorithms + enum InpaintTypes + { + /** This algorithm searches for dominant correspondences (transformations) of + image patches and tries to seamlessly fill-in the area to be inpainted using this + transformations */ + INPAINT_SHIFTMAP = 0 + }; + + /** @brief The function implements different single-image inpainting algorithms. + + See the original paper @cite He2012 for details. + + @param src source image, it could be of any type and any number of channels from 1 to 4. In case of + 3- and 4-channels images the function expect them in CIELab colorspace or similar one, where first + color component shows intensity, while second and third shows colors. Nonetheless you can try any + colorspaces. + @param mask mask (CV_8UC1), where non-zero pixels indicate valid image area, while zero pixels + indicate area to be inpainted + @param dst destination image + @param algorithmType see xphoto::InpaintTypes + */ + CV_EXPORTS_W void inpaint(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType); + +//! @} + +} +} + +#endif // __OPENCV_INPAINTING_HPP__ diff --git a/include/opencv2/xphoto/tonemap.hpp b/include/opencv2/xphoto/tonemap.hpp new file mode 100644 index 0000000..8d977d6 --- /dev/null +++ b/include/opencv2/xphoto/tonemap.hpp @@ -0,0 +1,56 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_XPHOTO_TONEMAP_HPP +#define OPENCV_XPHOTO_TONEMAP_HPP + +#include "opencv2/photo.hpp" + +namespace cv { namespace xphoto { + +//! @addtogroup xphoto +//! @{ + +/** @brief This algorithm decomposes image into two layers: base layer and detail layer using bilateral filter +and compresses contrast of the base layer thus preserving all the details. + +This implementation uses regular bilateral filter from OpenCV. + +Saturation enhancement is possible as in cv::TonemapDrago. + +For more information see @cite DD02 . + */ +class CV_EXPORTS_W TonemapDurand : public Tonemap +{ +public: + + CV_WRAP virtual float getSaturation() const = 0; + CV_WRAP virtual void setSaturation(float saturation) = 0; + + CV_WRAP virtual float getContrast() const = 0; + CV_WRAP virtual void setContrast(float contrast) = 0; + + CV_WRAP virtual float getSigmaSpace() const = 0; + CV_WRAP virtual void setSigmaSpace(float sigma_space) = 0; + + CV_WRAP virtual float getSigmaColor() const = 0; + CV_WRAP virtual void setSigmaColor(float sigma_color) = 0; +}; + +/** @brief Creates TonemapDurand object + +You need to set the OPENCV_ENABLE_NONFREE option in cmake to use those. Use them at your own risk. + +@param gamma gamma value for gamma correction. See createTonemap +@param contrast resulting contrast on logarithmic scale, i. e. log(max / min), where max and min +are maximum and minimum luminance values of the resulting image. +@param saturation saturation enhancement value. See createTonemapDrago +@param sigma_space bilateral filter sigma in color space +@param sigma_color bilateral filter sigma in coordinate space + */ +CV_EXPORTS_W Ptr<TonemapDurand> +createTonemapDurand(float gamma = 1.0f, float contrast = 4.0f, float saturation = 1.0f, float sigma_space = 2.0f, float sigma_color = 2.0f); + +}} // namespace +#endif // OPENCV_XPHOTO_TONEMAP_HPP diff --git a/include/opencv2/xphoto/white_balance.hpp b/include/opencv2/xphoto/white_balance.hpp new file mode 100644 index 0000000..1767f1f --- /dev/null +++ b/include/opencv2/xphoto/white_balance.hpp @@ -0,0 +1,230 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef __OPENCV_SIMPLE_COLOR_BALANCE_HPP__ +#define __OPENCV_SIMPLE_COLOR_BALANCE_HPP__ + +/** @file +@date Jun 26, 2014 +@author Yury Gitman +*/ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace xphoto +{ + +//! @addtogroup xphoto +//! @{ + +/** @brief The base class for auto white balance algorithms. + */ +class CV_EXPORTS_W WhiteBalancer : public Algorithm +{ + public: + /** @brief Applies white balancing to the input image + + @param src Input image + @param dst White balancing result + @sa cvtColor, equalizeHist + */ + CV_WRAP virtual void balanceWhite(InputArray src, OutputArray dst) = 0; +}; + +/** @brief A simple white balance algorithm that works by independently stretching + each of the input image channels to the specified range. For increased robustness + it ignores the top and bottom \f$p\%\f$ of pixel values. + */ +class CV_EXPORTS_W SimpleWB : public WhiteBalancer +{ + public: + /** @brief Input image range minimum value + @see setInputMin */ + CV_WRAP virtual float getInputMin() const = 0; + /** @copybrief getInputMin @see getInputMin */ + CV_WRAP virtual void setInputMin(float val) = 0; + + /** @brief Input image range maximum value + @see setInputMax */ + CV_WRAP virtual float getInputMax() const = 0; + /** @copybrief getInputMax @see getInputMax */ + CV_WRAP virtual void setInputMax(float val) = 0; + + /** @brief Output image range minimum value + @see setOutputMin */ + CV_WRAP virtual float getOutputMin() const = 0; + /** @copybrief getOutputMin @see getOutputMin */ + CV_WRAP virtual void setOutputMin(float val) = 0; + + /** @brief Output image range maximum value + @see setOutputMax */ + CV_WRAP virtual float getOutputMax() const = 0; + /** @copybrief getOutputMax @see getOutputMax */ + CV_WRAP virtual void setOutputMax(float val) = 0; + + /** @brief Percent of top/bottom values to ignore + @see setP */ + CV_WRAP virtual float getP() const = 0; + /** @copybrief getP @see getP */ + CV_WRAP virtual void setP(float val) = 0; +}; + +/** @brief Creates an instance of SimpleWB + */ +CV_EXPORTS_W Ptr<SimpleWB> createSimpleWB(); + +/** @brief Gray-world white balance algorithm + +This algorithm scales the values of pixels based on a +gray-world assumption which states that the average of all channels +should result in a gray image. + +It adds a modification which thresholds pixels based on their +saturation value and only uses pixels below the provided threshold in +finding average pixel values. + +Saturation is calculated using the following for a 3-channel RGB image per +pixel I and is in the range [0, 1]: + +\f[ \texttt{Saturation} [I] = \frac{\textrm{max}(R,G,B) - \textrm{min}(R,G,B) +}{\textrm{max}(R,G,B)} \f] + +A threshold of 1 means that all pixels are used to white-balance, while a +threshold of 0 means no pixels are used. Lower thresholds are useful in +white-balancing saturated images. + +Currently supports images of type @ref CV_8UC3 and @ref CV_16UC3. + */ +class CV_EXPORTS_W GrayworldWB : public WhiteBalancer +{ + public: + /** @brief Maximum saturation for a pixel to be included in the + gray-world assumption + @see setSaturationThreshold */ + CV_WRAP virtual float getSaturationThreshold() const = 0; + /** @copybrief getSaturationThreshold @see getSaturationThreshold */ + CV_WRAP virtual void setSaturationThreshold(float val) = 0; +}; + +/** @brief Creates an instance of GrayworldWB + */ +CV_EXPORTS_W Ptr<GrayworldWB> createGrayworldWB(); + +/** @brief More sophisticated learning-based automatic white balance algorithm. + +As @ref GrayworldWB, this algorithm works by applying different gains to the input +image channels, but their computation is a bit more involved compared to the +simple gray-world assumption. More details about the algorithm can be found in +@cite Cheng2015 . + +To mask out saturated pixels this function uses only pixels that satisfy the +following condition: + +\f[ \frac{\textrm{max}(R,G,B)}{\texttt{range_max_val}} < \texttt{saturation_thresh} \f] + +Currently supports images of type @ref CV_8UC3 and @ref CV_16UC3. + */ +class CV_EXPORTS_W LearningBasedWB : public WhiteBalancer +{ + public: + /** @brief Implements the feature extraction part of the algorithm. + + In accordance with @cite Cheng2015 , computes the following features for the input image: + 1. Chromaticity of an average (R,G,B) tuple + 2. Chromaticity of the brightest (R,G,B) tuple (while ignoring saturated pixels) + 3. Chromaticity of the dominant (R,G,B) tuple (the one that has the highest value in the RGB histogram) + 4. Mode of the chromaticity palette, that is constructed by taking 300 most common colors according to + the RGB histogram and projecting them on the chromaticity plane. Mode is the most high-density point + of the palette, which is computed by a straightforward fixed-bandwidth kernel density estimator with + a Epanechnikov kernel function. + + @param src Input three-channel image (BGR color space is assumed). + @param dst An array of four (r,g) chromaticity tuples corresponding to the features listed above. + */ + CV_WRAP virtual void extractSimpleFeatures(InputArray src, OutputArray dst) = 0; + + /** @brief Maximum possible value of the input image (e.g. 255 for 8 bit images, + 4095 for 12 bit images) + @see setRangeMaxVal */ + CV_WRAP virtual int getRangeMaxVal() const = 0; + /** @copybrief getRangeMaxVal @see getRangeMaxVal */ + CV_WRAP virtual void setRangeMaxVal(int val) = 0; + + /** @brief Threshold that is used to determine saturated pixels, i.e. pixels where at least one of the + channels exceeds \f$\texttt{saturation_threshold}\times\texttt{range_max_val}\f$ are ignored. + @see setSaturationThreshold */ + CV_WRAP virtual float getSaturationThreshold() const = 0; + /** @copybrief getSaturationThreshold @see getSaturationThreshold */ + CV_WRAP virtual void setSaturationThreshold(float val) = 0; + + /** @brief Defines the size of one dimension of a three-dimensional RGB histogram that is used internally + by the algorithm. It often makes sense to increase the number of bins for images with higher bit depth + (e.g. 256 bins for a 12 bit image). + @see setHistBinNum */ + CV_WRAP virtual int getHistBinNum() const = 0; + /** @copybrief getHistBinNum @see getHistBinNum */ + CV_WRAP virtual void setHistBinNum(int val) = 0; +}; + +/** @brief Creates an instance of LearningBasedWB + +@param path_to_model Path to a .yml file with the model. If not specified, the default model is used + */ +CV_EXPORTS_W Ptr<LearningBasedWB> createLearningBasedWB(const String& path_to_model = String()); + +/** @brief Implements an efficient fixed-point approximation for applying channel gains, which is + the last step of multiple white balance algorithms. + +@param src Input three-channel image in the BGR color space (either CV_8UC3 or CV_16UC3) +@param dst Output image of the same size and type as src. +@param gainB gain for the B channel +@param gainG gain for the G channel +@param gainR gain for the R channel +*/ +CV_EXPORTS_W void applyChannelGains(InputArray src, OutputArray dst, float gainB, float gainG, float gainR); +//! @} +} +} + +#endif // __OPENCV_SIMPLE_COLOR_BALANCE_HPP__ diff --git a/include/zbar/Decoder.h b/include/zbar/Decoder.h new file mode 100644 index 0000000..3e65d5e --- /dev/null +++ b/include/zbar/Decoder.h @@ -0,0 +1,193 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_DECODER_H_ +#define _ZBAR_DECODER_H_ + +/// @file +/// Decoder C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Decoder.h" +#endif + +#include <string> + +namespace zbar { + +/// low-level bar width stream decoder interface. +/// identifies symbols and extracts encoded data + +class Decoder { + public: + + /// Decoder result handler. + /// applications should subtype this and pass an instance to + /// set_handler() to implement result processing + class Handler { + public: + virtual ~Handler() { } + + /// invoked by the Decoder as decode results become available. + virtual void decode_callback(Decoder &decoder) = 0; + }; + + /// constructor. + Decoder () + : _handler(NULL) + { + _decoder = zbar_decoder_create(); + } + + ~Decoder () + { + zbar_decoder_destroy(_decoder); + } + + /// clear all decoder state. + /// see zbar_decoder_reset() + void reset () + { + zbar_decoder_reset(_decoder); + } + + /// mark start of a new scan pass. + /// see zbar_decoder_new_scan() + void new_scan () + { + zbar_decoder_new_scan(_decoder); + } + + /// process next bar/space width from input stream. + /// see zbar_decode_width() + zbar_symbol_type_t decode_width (unsigned width) + { + return(zbar_decode_width(_decoder, width)); + } + + /// process next bar/space width from input stream. + /// see zbar_decode_width() + Decoder& operator<< (unsigned width) + { + zbar_decode_width(_decoder, width); + return(*this); + } + + /// retrieve color of @em next element passed to Decoder. + /// see zbar_decoder_get_color() + zbar_color_t get_color () const + { + return(zbar_decoder_get_color(_decoder)); + } + + /// retrieve last decoded symbol type. + /// see zbar_decoder_get_type() + zbar_symbol_type_t get_type () const + { + return(zbar_decoder_get_type(_decoder)); + } + + /// retrieve string name of last decoded symbol type. + /// see zbar_get_symbol_name() + const char *get_symbol_name () const + { + return(zbar_get_symbol_name(zbar_decoder_get_type(_decoder))); + } + + /// retrieve string name for last decode addon. + /// see zbar_get_addon_name() + const char *get_addon_name () const + { + return(zbar_get_addon_name(zbar_decoder_get_type(_decoder))); + } + + /// retrieve last decoded data in ASCII format as a char array. + /// see zbar_decoder_get_data() + const char *get_data_chars() const + { + return(zbar_decoder_get_data(_decoder)); + } + + /// retrieve last decoded data as a std::string. + /// see zbar_decoder_get_data() + const std::string get_data_string() const + { + return(std::string(zbar_decoder_get_data(_decoder), + zbar_decoder_get_data_length(_decoder))); + } + + /// retrieve last decoded data as a std::string. + /// see zbar_decoder_get_data() + const std::string get_data() const + { + return(get_data_string()); + } + + /// retrieve length of decoded binary data. + /// see zbar_decoder_get_data_length() + int get_data_length() const + { + return(zbar_decoder_get_data_length(_decoder)); + } + + /// setup callback to handle result data. + void set_handler (Handler &handler) + { + _handler = &handler; + zbar_decoder_set_handler(_decoder, _cb); + zbar_decoder_set_userdata(_decoder, this); + } + + /// set config for indicated symbology (0 for all) to specified value. + /// @see zbar_decoder_set_config() + /// @since 0.4 + int set_config (zbar_symbol_type_t symbology, + zbar_config_t config, + int value) + { + return(zbar_decoder_set_config(_decoder, symbology, config, value)); + } + + /// set config parsed from configuration string. + /// @see zbar_decoder_parse_config() + /// @since 0.4 + int set_config (std::string cfgstr) + { + return(zbar_decoder_parse_config(_decoder, cfgstr.c_str())); + } + + private: + friend class Scanner; + zbar_decoder_t *_decoder; + Handler *_handler; + + static void _cb (zbar_decoder_t *cdcode) + { + Decoder *dcode = (Decoder*)zbar_decoder_get_userdata(cdcode); + if(dcode && dcode->_handler) + dcode->_handler->decode_callback(*dcode); + } +}; + +} + +#endif diff --git a/include/zbar/Exception.h b/include/zbar/Exception.h new file mode 100644 index 0000000..236622f --- /dev/null +++ b/include/zbar/Exception.h @@ -0,0 +1,187 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_EXCEPTION_H_ +#define _ZBAR_EXCEPTION_H_ + +/// @file +/// C++ Exception definitions + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Exception.h" +#endif + +#include <exception> +#include <new> + +namespace zbar { + +/// base class for exceptions defined by this API. +class Exception : public std::exception { + +public: + /// create exception from C library error + Exception (const void *obj = NULL) + : std::exception(), + _obj(obj) + { } + + ~Exception () throw() { } + + /// retrieve error message + virtual const char* what () const throw() + { + if(!_obj) + return("zbar library unspecified generic error"); + return(_zbar_error_string(_obj, 0)); + } + +private: + const void *_obj; +}; + +/// internal library error. +class InternalError : public Exception { +public: + /// create exception from C library error + InternalError (const void *obj) + : Exception(obj) + { } +}; + +/// unsupported request. +class UnsupportedError : public Exception { +public: + /// create exception from C library error + UnsupportedError (const void *obj) + : Exception(obj) + { } +}; + +/// invalid request. +class InvalidError : public Exception { +public: + /// create exception from C library error + InvalidError (const void *obj) + : Exception(obj) + { } +}; + +/// failed system call. +class SystemError : public Exception { +public: + /// create exception from C library error + SystemError (const void *obj) + : Exception(obj) + { } +}; + +/// locking error. +class LockingError : public Exception { +public: + /// create exception from C library error + LockingError (const void *obj) + : Exception(obj) + { } +}; + +/// all resources busy. +class BusyError : public Exception { +public: + /// create exception from C library error + BusyError (const void *obj) + : Exception(obj) + { } +}; + +/// X11 display error. +class XDisplayError : public Exception { +public: + /// create exception from C library error + XDisplayError (const void *obj) + : Exception(obj) + { } +}; + +/// X11 protocol error. +class XProtoError : public Exception { +public: + /// create exception from C library error + XProtoError (const void *obj) + : Exception(obj) + { } +}; + +/// output window is closed. +class ClosedError : public Exception { +public: + /// create exception from C library error + ClosedError (const void *obj) + : Exception(obj) + { } +}; + +/// image format error +class FormatError : public Exception { + // FIXME needs c equivalent + + virtual const char* what () const throw() + { + // FIXME what format? + return("unsupported format"); + } +}; + +/// @internal + +/// extract error information and create exception. +static inline std::exception throw_exception (const void *obj) +{ + switch(_zbar_get_error_code(obj)) { + case ZBAR_ERR_NOMEM: + throw std::bad_alloc(); + case ZBAR_ERR_INTERNAL: + throw InternalError(obj); + case ZBAR_ERR_UNSUPPORTED: + throw UnsupportedError(obj); + case ZBAR_ERR_INVALID: + throw InvalidError(obj); + case ZBAR_ERR_SYSTEM: + throw SystemError(obj); + case ZBAR_ERR_LOCKING: + throw LockingError(obj); + case ZBAR_ERR_BUSY: + throw BusyError(obj); + case ZBAR_ERR_XDISPLAY: + throw XDisplayError(obj); + case ZBAR_ERR_XPROTO: + throw XProtoError(obj); + case ZBAR_ERR_CLOSED: + throw ClosedError(obj); + default: + throw Exception(obj); + } +} + +} + +#endif diff --git a/include/zbar/Image.h b/include/zbar/Image.h new file mode 100644 index 0000000..e1d9644 --- /dev/null +++ b/include/zbar/Image.h @@ -0,0 +1,290 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_IMAGE_H_ +#define _ZBAR_IMAGE_H_ + +/// @file +/// Image C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Image.h" +#endif + +#include <assert.h> +#include <iterator> +#include "Symbol.h" +#include "Exception.h" + +namespace zbar { + +class Video; + +/// stores image data samples along with associated format and size +/// metadata + +class Image { +public: + + /// general Image result handler. + /// applications should subtype this and pass an instance to + /// eg. ImageScanner::set_handler() to implement result processing + class Handler { + public: + virtual ~Handler() { } + + /// invoked by library when Image should be processed + virtual void image_callback(Image &image) = 0; + + /// cast this handler to the C handler + operator zbar_image_data_handler_t* () const + { + return(_cb); + } + + private: + static void _cb (zbar_image_t *zimg, + const void *userdata) + { + if(userdata) { + Image *image = (Image*)zbar_image_get_userdata(zimg); + ((Handler*)userdata)->image_callback(*image); + } + } + }; + + class SymbolIterator : public zbar::SymbolIterator { + public: + /// default constructor. + SymbolIterator () + : zbar::SymbolIterator() + { } + + /// constructor. + SymbolIterator (const SymbolSet &syms) + : zbar::SymbolIterator(syms) + { } + + /// copy constructor. + SymbolIterator (const SymbolIterator& iter) + : zbar::SymbolIterator(iter) + { } + }; + + /// constructor. + /// create a new Image with the specified parameters + Image (unsigned width = 0, + unsigned height = 0, + const std::string& format = "", + const void *data = NULL, + unsigned long length = 0) + : _img(zbar_image_create()) + { + zbar_image_set_userdata(_img, this); + if(width && height) + set_size(width, height); + if(format.length()) + set_format(format); + if(data && length) + set_data(data, length); + } + + ~Image () + { + zbar_image_ref(_img, -1); + } + + /// cast to C image object + operator const zbar_image_t* () const + { + return(_img); + } + + /// cast to C image object + operator zbar_image_t* () + { + return(_img); + } + + /// retrieve the image format. + /// see zbar_image_get_format() + unsigned long get_format () const + { + return(zbar_image_get_format(_img)); + } + + /// specify the fourcc image format code for image sample data. + /// see zbar_image_set_format() + void set_format (unsigned long format) + { + zbar_image_set_format(_img, format); + } + + /// specify the fourcc image format code for image sample data. + /// see zbar_image_set_format() + void set_format (const std::string& format) + { + if(format.length() != 4) + throw FormatError(); + unsigned long fourcc = ((format[0] & 0xff) | + ((format[1] & 0xff) << 8) | + ((format[2] & 0xff) << 16) | + ((format[3] & 0xff) << 24)); + zbar_image_set_format(_img, fourcc); + } + + /// retrieve a "sequence" (page/frame) number associated with this + /// image. + /// see zbar_image_get_sequence() + /// @since 0.6 + unsigned get_sequence () const + { + return(zbar_image_get_sequence(_img)); + } + + /// associate a "sequence" (page/frame) number with this image. + /// see zbar_image_set_sequence() + /// @since 0.6 + void set_sequence (unsigned sequence_num) + { + zbar_image_set_sequence(_img, sequence_num); + } + + /// retrieve the width of the image. + /// see zbar_image_get_width() + unsigned get_width () const + { + return(zbar_image_get_width(_img)); + } + + /// retrieve the height of the image. + /// see zbar_image_get_height() + unsigned get_height () const + { + return(zbar_image_get_height(_img)); + } + + /// specify the pixel size of the image. + /// see zbar_image_set_size() + void set_size (unsigned width, + unsigned height) + { + zbar_image_set_size(_img, width, height); + } + + /// return the image sample data. + /// see zbar_image_get_data() + const void *get_data () const + { + return(zbar_image_get_data(_img)); + } + + /// return the size of the image sample data. + /// see zbar_image_get_data_length() + /// @since 0.6 + unsigned long get_data_length () const + { + return(zbar_image_get_data_length(_img)); + } + + /// specify image sample data. + /// see zbar_image_set_data() + void set_data (const void *data, + unsigned long length) + { + zbar_image_set_data(_img, data, length, _cleanup); + } + + /// image format conversion. + /// see zbar_image_convert() + Image convert (unsigned long format) const + { + zbar_image_t *img = zbar_image_convert(_img, format); + if(img) + return(Image(img)); + throw FormatError(); + } + + /// image format conversion with crop/pad. + /// see zbar_image_convert_resize() + /// @since 0.4 + Image convert (unsigned long format, + unsigned width, + unsigned height) const + { + zbar_image_t *img = + zbar_image_convert_resize(_img, format, width, height); + if(img) + return(Image(img)); + throw FormatError(); + } + + const SymbolSet get_symbols () const { + return(SymbolSet(zbar_image_get_symbols(_img))); + } + + void set_symbols (const SymbolSet &syms) { + zbar_image_set_symbols(_img, syms); + } + + /// create a new SymbolIterator over decoded results. + SymbolIterator symbol_begin () const { + return(SymbolIterator(get_symbols())); + } + + /// return a SymbolIterator suitable for ending iteration. + SymbolIterator symbol_end () const { + return(SymbolIterator()); + } + +protected: + + friend class Video; + + /// constructor. + /// @internal + /// create a new Image from a zbar_image_t C object + Image (zbar_image_t *src, + int refs = 0) + : _img(src) + { + if(refs) + zbar_image_ref(_img, refs); + zbar_image_set_userdata(_img, this); + } + + /// default data cleanup (noop) + /// @internal + static void _cleanup (zbar_image_t *img) + { + // by default nothing is cleaned + assert(img); + assert(zbar_image_get_userdata(img)); + } + +private: + zbar_image_t *_img; +}; + +} + +#endif diff --git a/include/zbar/ImageScanner.h b/include/zbar/ImageScanner.h new file mode 100644 index 0000000..bda8433 --- /dev/null +++ b/include/zbar/ImageScanner.h @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_IMAGE_SCANNER_H_ +#define _ZBAR_IMAGE_SCANNER_H_ + +/// @file +/// Image Scanner C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/ImageScanner.h" +#endif + +#include "Image.h" + +namespace zbar { + +/// mid-level image scanner interface. +/// reads barcodes from a 2-D Image + +class ImageScanner { +public: + /// constructor. + ImageScanner (zbar_image_scanner_t *scanner = NULL) + { + if(scanner) + _scanner = scanner; + else + _scanner = zbar_image_scanner_create(); + } + + ~ImageScanner () + { + zbar_image_scanner_destroy(_scanner); + } + + /// cast to C image_scanner object + operator zbar_image_scanner_t* () const + { + return(_scanner); + } + + /// setup result handler callback. + void set_handler (Image::Handler &handler) + { + zbar_image_scanner_set_data_handler(_scanner, handler, &handler); + } + + /// set config for indicated symbology (0 for all) to specified value. + /// @see zbar_image_scanner_set_config() + /// @since 0.4 + int set_config (zbar_symbol_type_t symbology, + zbar_config_t config, + int value) + { + return(zbar_image_scanner_set_config(_scanner, symbology, + config, value)); + } + + /// set config parsed from configuration string. + /// @see zbar_image_scanner_parse_config() + /// @since 0.4 + int set_config (std::string cfgstr) + { + return(zbar_image_scanner_parse_config(_scanner, cfgstr.c_str())); + } + + /// enable or disable the inter-image result cache. + /// see zbar_image_scanner_enable_cache() + void enable_cache (bool enable = true) + { + zbar_image_scanner_enable_cache(_scanner, enable); + } + + /// remove previous results from scanner and image. + /// @see zbar_image_scanner_recycle_image() + /// @since 0.10 + void recycle_image (Image &image) + { + zbar_image_scanner_recycle_image(_scanner, image); + } + + /// retrieve decode results for last scanned image. + /// @see zbar_image_scanner_get_results() + /// @since 0.10 + const SymbolSet get_results () const { + return(SymbolSet(zbar_image_scanner_get_results(_scanner))); + } + + /// scan for symbols in provided image. + /// see zbar_scan_image() + int scan (Image& image) + { + return(zbar_scan_image(_scanner, image)); + } + + /// scan for symbols in provided image. + /// see zbar_scan_image() + ImageScanner& operator<< (Image& image) + { + scan(image); + return(*this); + } + +private: + zbar_image_scanner_t *_scanner; +}; + +} + +#endif diff --git a/include/zbar/Processor.h b/include/zbar/Processor.h new file mode 100644 index 0000000..51b0e1c --- /dev/null +++ b/include/zbar/Processor.h @@ -0,0 +1,223 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_PROCESSOR_H_ +#define _ZBAR_PROCESSOR_H_ + +/// @file +/// Processor C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Processor.h" +#endif + +#include "Exception.h" +#include "Image.h" + +namespace zbar { + +/// high-level self-contained image processor. +/// processes video and images for barcodes, optionally displaying +/// images to a library owned output window + +class Processor { + public: + /// value to pass for no timeout. + static const int FOREVER = -1; + + /// constructor. + Processor (bool threaded = true, + const char *video_device = "", + bool enable_display = true) + { + _processor = zbar_processor_create(threaded); + if(!_processor) + throw std::bad_alloc(); + init(video_device, enable_display); + } + + ~Processor () + { + zbar_processor_destroy(_processor); + } + + /// cast to C processor object. + operator zbar_processor_t* () + { + return(_processor); + } + + /// opens a video input device and/or prepares to display output. + /// see zbar_processor_init() + void init (const char *video_device = "", + bool enable_display = true) + { + if(zbar_processor_init(_processor, video_device, enable_display)) + throw_exception(_processor); + } + + /// setup result handler callback. + /// see zbar_processor_set_data_handler() + void set_handler (Image::Handler& handler) + { + zbar_processor_set_data_handler(_processor, handler, &handler); + } + + /// set config for indicated symbology (0 for all) to specified value. + /// @see zbar_processor_set_config() + /// @since 0.4 + int set_config (zbar_symbol_type_t symbology, + zbar_config_t config, + int value) + { + return(zbar_processor_set_config(_processor, symbology, + config, value)); + } + + /// set config parsed from configuration string. + /// @see zbar_processor_parse_config() + /// @since 0.4 + int set_config (std::string cfgstr) + { + return(zbar_processor_parse_config(_processor, cfgstr.c_str())); + } + + /// retrieve the current state of the ouput window. + /// see zbar_processor_is_visible() + bool is_visible () + { + int rc = zbar_processor_is_visible(_processor); + if(rc < 0) + throw_exception(_processor); + return(rc != 0); + } + + /// show or hide the display window owned by the library. + /// see zbar_processor_set_visible() + void set_visible (bool visible = true) + { + if(zbar_processor_set_visible(_processor, visible) < 0) + throw_exception(_processor); + } + + /// control the processor in free running video mode. + /// see zbar_processor_set_active() + void set_active (bool active = true) + { + if(zbar_processor_set_active(_processor, active) < 0) + throw_exception(_processor); + } + + /// retrieve decode results for last scanned image. + /// @see zbar_processor_get_results() + /// @since 0.10 + const SymbolSet get_results () const { + return(SymbolSet(zbar_processor_get_results(_processor))); + } + + /// wait for input to the display window from the user. + /// see zbar_processor_user_wait() + int user_wait (int timeout = FOREVER) + { + int rc = zbar_processor_user_wait(_processor, timeout); + if(rc < 0) + throw_exception(_processor); + return(rc); + } + + /// process from the video stream until a result is available. + /// see zbar_process_one() + void process_one (int timeout = FOREVER) + { + if(zbar_process_one(_processor, timeout) < 0) + throw_exception(_processor); + } + + /// process the provided image for barcodes. + /// see zbar_process_image() + void process_image (Image& image) + { + if(zbar_process_image(_processor, image) < 0) + throw_exception(_processor); + } + + /// process the provided image for barcodes. + /// see zbar_process_image() + Processor& operator<< (Image& image) + { + process_image(image); + return(*this); + } + + /// force specific input and output formats for debug/testing. + /// see zbar_processor_force_format() + void force_format (unsigned long input_format, + unsigned long output_format) + { + if(zbar_processor_force_format(_processor, input_format, + output_format)) + throw_exception(_processor); + } + + /// force specific input and output formats for debug/testing. + /// see zbar_processor_force_format() + void force_format (std::string& input_format, + std::string& output_format) + { + unsigned long ifourcc = *(unsigned long*)input_format.c_str(); + unsigned long ofourcc = *(unsigned long*)output_format.c_str(); + if(zbar_processor_force_format(_processor, ifourcc, ofourcc)) + throw_exception(_processor); + } + + /// request a preferred size for the video image from the device. + /// see zbar_processor_request_size() + /// @since 0.6 + void request_size (int width, int height) + { + zbar_processor_request_size(_processor, width, height); + } + + /// request a preferred driver interface version for debug/testing. + /// see zbar_processor_request_interface() + /// @since 0.6 + void request_interface (int version) + { + zbar_processor_request_interface(_processor, version); + } + + /// request a preferred I/O mode for debug/testing. + /// see zbar_processor_request_iomode() + /// @since 0.7 + void request_iomode (int iomode) + { + if(zbar_processor_request_iomode(_processor, iomode)) + throw_exception(_processor); + } + + private: + zbar_processor_t *_processor; +}; + +} + +#endif diff --git a/include/zbar/Scanner.h b/include/zbar/Scanner.h new file mode 100644 index 0000000..8c9a756 --- /dev/null +++ b/include/zbar/Scanner.h @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_SCANNER_H_ +#define _ZBAR_SCANNER_H_ + +/// @file +/// Scanner C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Scanner.h" +#endif + +#include <stdio.h> + +namespace zbar { + +/// low-level linear intensity sample stream scanner interface. +/// identifies "bar" edges and measures width between them. +/// optionally passes to bar width Decoder + +class Scanner { + public: + + /// constructor. + /// @param decoder reference to a Decoder instance which will + /// be passed scan results automatically + Scanner (Decoder& decoder) + { + _scanner = zbar_scanner_create(decoder._decoder); + } + + /// constructor. + /// @param decoder pointer to a Decoder instance which will + /// be passed scan results automatically + Scanner (Decoder* decoder = NULL) + { + zbar_decoder_t *zdcode = NULL; + if(decoder) + zdcode = decoder->_decoder; + _scanner = zbar_scanner_create(zdcode); + } + + ~Scanner () + { + zbar_scanner_destroy(_scanner); + } + + /// clear all scanner state. + /// see zbar_scanner_reset() + void reset () + { + zbar_scanner_reset(_scanner); + } + + /// mark start of a new scan pass. + /// see zbar_scanner_new_scan() + zbar_symbol_type_t new_scan () + { + _type = zbar_scanner_new_scan(_scanner); + return(_type); + } + + /// flush scanner pipeline. + /// see zbar_scanner_flush() + zbar_symbol_type_t flush () + { + _type = zbar_scanner_flush(_scanner); + return(_type); + } + + /// process next sample intensity value. + /// see zbar_scan_y() + zbar_symbol_type_t scan_y (int y) + { + _type = zbar_scan_y(_scanner, y); + return(_type); + } + + /// process next sample intensity value. + /// see zbar_scan_y() + Scanner& operator<< (int y) + { + _type = zbar_scan_y(_scanner, y); + return(*this); + } + + /// process next sample from RGB (or BGR) triple. + /// see zbar_scan_rgb24() + zbar_symbol_type_t scan_rgb24 (unsigned char *rgb) + { + _type = zbar_scan_rgb24(_scanner, rgb); + return(_type); + } + + /// process next sample from RGB (or BGR) triple. + /// see zbar_scan_rgb24() + Scanner& operator<< (unsigned char *rgb) + { + _type = zbar_scan_rgb24(_scanner, rgb); + return(*this); + } + + /// retrieve last scanned width. + /// see zbar_scanner_get_width() + unsigned get_width () const + { + return(zbar_scanner_get_width(_scanner)); + } + + /// retrieve last scanned color. + /// see zbar_scanner_get_color() + zbar_color_t get_color () const + { + return(zbar_scanner_get_color(_scanner)); + } + + /// retrieve last scan result. + zbar_symbol_type_t get_type () const + { + return(_type); + } + + /// cast to C scanner + operator zbar_scanner_t* () const + { + return(_scanner); + } + + /// retrieve C scanner + const zbar_scanner_t *get_c_scanner () const + { + return(_scanner); + } + + private: + zbar_scanner_t *_scanner; + zbar_symbol_type_t _type; +}; + +} + +#endif diff --git a/include/zbar/Symbol.h b/include/zbar/Symbol.h new file mode 100644 index 0000000..b47732a --- /dev/null +++ b/include/zbar/Symbol.h @@ -0,0 +1,451 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_SYMBOL_H_ +#define _ZBAR_SYMBOL_H_ + +/// @file +/// Symbol C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Symbol.h" +#endif + +#include <stdlib.h> +#include <string> +#include <ostream> +#include <assert.h> + +namespace zbar { + +class SymbolIterator; + +/// container for decoded result symbols associated with an image +/// or a composite symbol. + +class SymbolSet { +public: + /// constructor. + SymbolSet (const zbar_symbol_set_t *syms = NULL) + : _syms(syms) + { + ref(); + } + + /// copy constructor. + SymbolSet (const SymbolSet& syms) + : _syms(syms._syms) + { + ref(); + } + + /// destructor. + ~SymbolSet () + { + ref(-1); + } + + /// manipulate reference count. + void ref (int delta = 1) const + { + if(_syms) + zbar_symbol_set_ref((zbar_symbol_set_t*)_syms, delta); + } + + /// cast to C symbol set. + operator const zbar_symbol_set_t* () const + { + return(_syms); + } + + int get_size () + { + return((_syms) ? zbar_symbol_set_get_size(_syms) : 0); + } + + /// create a new SymbolIterator over decoded results. + SymbolIterator symbol_begin() const; + + /// return a SymbolIterator suitable for ending iteration. + const SymbolIterator symbol_end() const; + +private: + const zbar_symbol_set_t *_syms; +}; + +/// decoded barcode symbol result object. stores type, data, and +/// image location of decoded symbol + +class Symbol { +public: + + /// image pixel location (x, y) coordinate tuple. + class Point { + public: + int x; ///< x-coordinate. + int y; ///< y-coordinate. + + Point () { } + + Point(int x, int y) + : x(x), y(y) + { } + + /// copy constructor. + Point (const Point& pt) + { + x = pt.x; + y = pt.y; + } + }; + + /// iteration over Point objects in a symbol location polygon. + class PointIterator + : public std::iterator<std::input_iterator_tag, Point> { + + public: + /// constructor. + PointIterator (const Symbol *sym = NULL, + int index = 0) + : _sym(sym), + _index(index) + { + sym->ref(1); + if(!sym || + (unsigned)_index >= zbar_symbol_get_loc_size(*_sym)) + _index = -1; + } + + /// constructor. + PointIterator (const PointIterator& iter) + : _sym(iter._sym), + _index(iter._index) + { + _sym->ref(); + } + + /// destructor. + ~PointIterator () + { + _sym->ref(-1); + } + + /// advance iterator to next Point. + PointIterator& operator++ () + { + unsigned int i = ++_index; + if(i >= zbar_symbol_get_loc_size(*_sym)) + _index = -1; + return(*this); + } + + /// retrieve currently referenced Point. + const Point operator* () const + { + assert(_index >= 0); + return(Point(zbar_symbol_get_loc_x(*_sym, _index), + zbar_symbol_get_loc_y(*_sym, _index))); + } + + /// test if two iterators refer to the same Point in the same + /// Symbol. + bool operator== (const PointIterator& iter) const + { + return(_index == iter._index && + ((_index < 0) || _sym == iter._sym)); + } + + /// test if two iterators refer to the same Point in the same + /// Symbol. + bool operator!= (const PointIterator& iter) const + { + return(!(*this == iter)); + } + + private: + const Symbol *_sym; + int _index; + }; + + /// constructor. + Symbol (const zbar_symbol_t *sym = NULL) + : _xmlbuf(NULL), + _xmllen(0) + { + init(sym); + ref(); + } + + /// copy constructor. + Symbol (const Symbol& sym) + : _sym(sym._sym), + _type(sym._type), + _data(sym._data), + _xmlbuf(NULL), + _xmllen(0) + { + ref(); + } + + /// destructor. + ~Symbol () { + if(_xmlbuf) + free(_xmlbuf); + ref(-1); + } + + void ref (int delta = 1) const + { + if(_sym) + zbar_symbol_ref((zbar_symbol_t*)_sym, delta); + } + + /// cast to C symbol. + operator const zbar_symbol_t* () const + { + return(_sym); + } + + /// test if two Symbol objects refer to the same C symbol. + bool operator== (const Symbol& sym) const + { + return(_sym == sym._sym); + } + + /// test if two Symbol objects refer to the same C symbol. + bool operator!= (const Symbol& sym) const + { + return(!(*this == sym)); + } + + /// retrieve type of decoded symbol. + zbar_symbol_type_t get_type () const + { + return(_type); + } + + /// retrieve the string name of the symbol type. + const std::string get_type_name () const + { + return(zbar_get_symbol_name(_type)); + } + + /// retrieve the string name for any addon. + const std::string get_addon_name () const + { + return(zbar_get_addon_name(_type)); + } + + /// retrieve data decoded from symbol. + const std::string get_data () const + { + return(_data); + } + + /// retrieve length of binary data + unsigned get_data_length () const + { + return((_sym) ? zbar_symbol_get_data_length(_sym) : 0); + } + + /// retrieve inter-frame coherency count. + /// see zbar_symbol_get_count() + /// @since 1.5 + int get_count () const + { + return((_sym) ? zbar_symbol_get_count(_sym) : -1); + } + + SymbolSet get_components () const + { + return(SymbolSet((_sym) ? zbar_symbol_get_components(_sym) : NULL)); + } + + /// create a new PointIterator at the start of the location + /// polygon. + PointIterator point_begin() const + { + return(PointIterator(this)); + } + + /// return a PointIterator suitable for ending iteration. + const PointIterator point_end() const + { + return(PointIterator()); + } + + /// see zbar_symbol_get_loc_size(). + int get_location_size () const + { + return((_sym) ? zbar_symbol_get_loc_size(_sym) : 0); + } + + /// see zbar_symbol_get_loc_x(). + int get_location_x (unsigned index) const + { + return((_sym) ? zbar_symbol_get_loc_x(_sym, index) : -1); + } + + /// see zbar_symbol_get_loc_y(). + int get_location_y (unsigned index) const + { + return((_sym) ? zbar_symbol_get_loc_y(_sym, index) : -1); + } + + /// see zbar_symbol_xml(). + const std::string xml () const + { + if(!_sym) + return(""); + return(zbar_symbol_xml(_sym, (char**)&_xmlbuf, (unsigned*)&_xmllen)); + } + +protected: + + friend class SymbolIterator; + + /// (re)initialize Symbol from C symbol object. + void init (const zbar_symbol_t *sym = NULL) + { + _sym = sym; + if(sym) { + _type = zbar_symbol_get_type(sym); + _data = std::string(zbar_symbol_get_data(sym), + zbar_symbol_get_data_length(sym)); + } + else { + _type = ZBAR_NONE; + _data = ""; + } + } + +private: + const zbar_symbol_t *_sym; + zbar_symbol_type_t _type; + std::string _data; + char *_xmlbuf; + unsigned _xmllen; +}; + +/// iteration over Symbol result objects in a scanned Image or SymbolSet. +class SymbolIterator + : public std::iterator<std::input_iterator_tag, Symbol> { + +public: + /// default constructor. + SymbolIterator () + { } + + /// constructor. + SymbolIterator (const SymbolSet &syms) + : _syms(syms) + { + const zbar_symbol_set_t *zsyms = _syms; + if(zsyms) + _sym.init(zbar_symbol_set_first_symbol(zsyms)); + } + + /// copy constructor. + SymbolIterator (const SymbolIterator& iter) + : _syms(iter._syms) + { + const zbar_symbol_set_t *zsyms = _syms; + if(zsyms) + _sym.init(zbar_symbol_set_first_symbol(zsyms)); + } + + ~SymbolIterator () + { + _sym.init(); + } + + /// advance iterator to next Symbol. + SymbolIterator& operator++ () + { + const zbar_symbol_t *zsym = _sym; + if(zsym) + _sym.init(zbar_symbol_next(zsym)); + else { + const zbar_symbol_set_t *zsyms = _syms; + if(zsyms) + _sym.init(zbar_symbol_set_first_symbol(zsyms)); + } + return(*this); + } + + /// retrieve currently referenced Symbol. + const Symbol operator* () const + { + return(_sym); + } + + /// access currently referenced Symbol. + const Symbol* operator-> () const + { + return(&_sym); + } + + /// test if two iterators refer to the same Symbol + bool operator== (const SymbolIterator& iter) const + { + // it is enough to test the symbols, as they belong + // to only one set (also simplifies invalid case) + return(_sym == iter._sym); + } + + /// test if two iterators refer to the same Symbol + bool operator!= (const SymbolIterator& iter) const + { + return(!(*this == iter)); + } + + const SymbolIterator end () const { + return(SymbolIterator()); + } + +private: + SymbolSet _syms; + Symbol _sym; +}; + +inline SymbolIterator SymbolSet::symbol_begin () const { + return(SymbolIterator(*this)); +} + +inline const SymbolIterator SymbolSet::symbol_end () const { + return(SymbolIterator()); +} + +/// @relates Symbol +/// stream the string representation of a Symbol. +static inline std::ostream& operator<< (std::ostream& out, + const Symbol& sym) +{ + out << sym.get_type_name() + << sym.get_addon_name() + << ":" << sym.get_data(); + return(out); +} + +} + +#endif diff --git a/include/zbar/Video.h b/include/zbar/Video.h new file mode 100644 index 0000000..2787d86 --- /dev/null +++ b/include/zbar/Video.h @@ -0,0 +1,170 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_VIDEO_H_ +#define _ZBAR_VIDEO_H_ + +/// @file +/// Video Input C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Video.h" +#endif + +#include "Image.h" + +namespace zbar { + +/// mid-level video source abstraction. +/// captures images from a video device + +class Video { +public: + /// constructor. + Video (zbar_video_t *video = NULL) + { + if(video) + _video = video; + else + _video = zbar_video_create(); + } + + /// constructor. + Video (std::string& device) + { + _video = zbar_video_create(); + open(device); + } + + ~Video () + { + zbar_video_destroy(_video); + } + + /// cast to C video object. + operator zbar_video_t* () const + { + return(_video); + } + + /// open and probe a video device. + void open (std::string& device) + { + if(zbar_video_open(_video, device.c_str())) + throw_exception(_video); + } + + /// close video device if open. + void close () + { + if(zbar_video_open(_video, NULL)) + throw_exception(_video); + } + + /// initialize video using a specific format for debug. + /// see zbar_video_init() + void init (unsigned long fourcc) + { + if(zbar_video_init(_video, fourcc)) + throw_exception(_video); + } + + /// initialize video using a specific format for debug. + /// see zbar_video_init() + void init (std::string& format) + { + unsigned int fourcc = *(unsigned int*)format.c_str(); + if(zbar_video_init(_video, fourcc)) + throw_exception(_video); + } + + /// retrieve file descriptor associated with open *nix video device. + /// see zbar_video_get_fd() + int get_fd () + { + return(zbar_video_get_fd(_video)); + } + + /// retrieve current output image width. + /// see zbar_video_get_width() + int get_width () + { + return(zbar_video_get_width(_video)); + } + + /// retrieve current output image height. + /// see zbar_video_get_height() + int get_height () + { + return(zbar_video_get_height(_video)); + } + + /// start/stop video capture. + /// see zbar_video_enable() + void enable (bool enable = true) + { + if(zbar_video_enable(_video, enable)) + throw_exception(_video); + } + + /// retrieve next captured image. + /// see zbar_video_next_image() + Image next_image () + { + zbar_image_t *img = zbar_video_next_image(_video); + if(!img) + throw_exception(_video); + return(Image(img)); + } + + /// request a preferred size for the video image from the device. + /// see zbar_video_request_size() + /// @since 0.6 + void request_size (int width, int height) + { + zbar_video_request_size(_video, width, height); + } + + /// request a preferred driver interface version for debug/testing. + /// see zbar_video_request_interface() + /// @since 0.6 + void request_interface (int version) + { + zbar_video_request_interface(_video, version); + } + + /// request a preferred I/O mode for debug/testing. + /// see zbar_video_request_iomode() + /// @since 0.7 + void request_iomode (int iomode) + { + if(zbar_video_request_iomode(_video, iomode)) + throw_exception(_video); + } + +private: + zbar_video_t *_video; +}; + +} + +#endif diff --git a/include/zbar/Window.h b/include/zbar/Window.h new file mode 100644 index 0000000..c91a405 --- /dev/null +++ b/include/zbar/Window.h @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------ +// Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> +// +// This file is part of the ZBar Bar Code Reader. +// +// The ZBar Bar Code Reader is free software; you can redistribute it +// and/or modify it under the terms of the GNU Lesser Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// The ZBar Bar Code Reader 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 Lesser Public License for more details. +// +// You should have received a copy of the GNU Lesser Public License +// along with the ZBar Bar Code Reader; if not, write to the Free +// Software Foundation, Inc., 51 Franklin St, Fifth Floor, +// Boston, MA 02110-1301 USA +// +// http://sourceforge.net/projects/zbar +//------------------------------------------------------------------------ +#ifndef _ZBAR_WINDOW_H_ +#define _ZBAR_WINDOW_H_ + +/// @file +/// Output Window C++ wrapper + +#ifndef _ZBAR_H_ +# error "include zbar.h in your application, **not** zbar/Window.h" +#endif + +#include "Image.h" + +namespace zbar { + +/// mid-level output window abstraction. +/// displays images to user-specified platform specific output window + +class Window { +public: + /// constructor. + Window (zbar_window_t *window = NULL) + { + if(window) + _window = window; + else + _window = zbar_window_create(); + } + + /// constructor. + Window (void *x11_display_w32_hwnd, + unsigned long x11_drawable) + { + _window = zbar_window_create(); + attach(x11_display_w32_hwnd, x11_drawable); + } + + ~Window () + { + zbar_window_destroy(_window); + } + + /// cast to C window object. + operator zbar_window_t* () const + { + return(_window); + } + + /// associate reader with an existing platform window. + /// see zbar_window_attach() + void attach (void *x11_display_w32_hwnd, + unsigned long x11_drawable = 0) + { + if(zbar_window_attach(_window, + x11_display_w32_hwnd, x11_drawable) < 0) + throw_exception(_window); + } + + /// control content level of the reader overlay. + /// see zbar_window_set_overlay() + void set_overlay (int level) + { + zbar_window_set_overlay(_window, level); + } + + /// retrieve current content level of reader overlay. + /// see zbar_window_get_overlay() + + /// draw a new image into the output window. + /// see zbar_window_draw() + void draw (Image& image) + { + if(zbar_window_draw(_window, image) < 0) + throw_exception(_window); + } + + /// clear the image from the output window. + /// see zbar_window_draw() + void clear () + { + if(zbar_window_draw(_window, NULL) < 0) + throw_exception(_window); + } + + /// redraw the last image. + /// zbar_window_redraw() + void redraw () + { + if(zbar_window_redraw(_window) < 0) + throw_exception(_window); + } + + /// resize the image window. + /// zbar_window_resize() + void resize (unsigned width, unsigned height) + { + if(zbar_window_resize(_window, width, height) < 0) + throw_exception(_window); + } + +private: + zbar_window_t *_window; +}; + +/// select a compatible format between video input and output window. +/// see zbar_negotiate_format() +static inline void negotiate_format (Video& video, Window& window) +{ + if(zbar_negotiate_format(video, window) < 0) + throw_exception(video); +} + +} + +#endif diff --git a/include/zbar/zbar.h b/include/zbar/zbar.h new file mode 100644 index 0000000..66281c1 --- /dev/null +++ b/include/zbar/zbar.h @@ -0,0 +1,1587 @@ +/*------------------------------------------------------------------------ + * Copyright 2007-2010 (c) Jeff Brown <spadix@users.sourceforge.net> + * + * This file is part of the ZBar Bar Code Reader. + * + * The ZBar Bar Code Reader is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * The ZBar Bar Code Reader 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with the ZBar Bar Code Reader; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * http://sourceforge.net/projects/zbar + *------------------------------------------------------------------------*/ +#ifndef _ZBAR_H_ +#define _ZBAR_H_ + +#include <stdint.h> + +/** @file + * ZBar Barcode Reader C API definition + */ + +/** @mainpage + * + * interface to the barcode reader is available at several levels. + * most applications will want to use the high-level interfaces: + * + * @section high-level High-Level Interfaces + * + * these interfaces wrap all library functionality into an easy-to-use + * package for a specific toolkit: + * - the "GTK+ 2.x widget" may be used with GTK GUI applications. a + * Python wrapper is included for PyGtk + * - the @ref zbar::QZBar "Qt4 widget" may be used with Qt GUI + * applications + * - the Processor interface (in @ref c-processor "C" or @ref + * zbar::Processor "C++") adds a scanning window to an application + * with no GUI. + * + * @section mid-level Intermediate Interfaces + * + * building blocks used to construct high-level interfaces: + * - the ImageScanner (in @ref c-imagescanner "C" or @ref + * zbar::ImageScanner "C++") looks for barcodes in a library defined + * image object + * - the Window abstraction (in @ref c-window "C" or @ref + * zbar::Window "C++") sinks library images, displaying them on the + * platform display + * - the Video abstraction (in @ref c-video "C" or @ref zbar::Video + * "C++") sources library images from a video device + * + * @section low-level Low-Level Interfaces + * + * direct interaction with barcode scanning and decoding: + * - the Scanner (in @ref c-scanner "C" or @ref zbar::Scanner "C++") + * looks for barcodes in a linear intensity sample stream + * - the Decoder (in @ref c-decoder "C" or @ref zbar::Decoder "C++") + * extracts barcodes from a stream of bar and space widths + */ + +#ifdef __cplusplus + +/** C++ namespace for library interfaces */ +namespace zbar +{ +extern "C" { +#endif + +/** @name Global library interfaces */ +/*@{*/ + +/** "color" of element: bar or space. */ +typedef enum zbar_color_e +{ + ZBAR_SPACE = 0, /**< light area or space between bars */ + ZBAR_BAR = 1, /**< dark area or colored bar segment */ +} zbar_color_t; + +/** decoded symbol type. */ +typedef enum zbar_symbol_type_e +{ + ZBAR_NONE = 0, /**< no symbol decoded */ + ZBAR_PARTIAL = 1, /**< intermediate status */ + ZBAR_EAN2 = 2, /**< GS1 2-digit add-on */ + ZBAR_EAN5 = 5, /**< GS1 5-digit add-on */ + ZBAR_EAN8 = 8, /**< EAN-8 */ + ZBAR_UPCE = 9, /**< UPC-E */ + ZBAR_ISBN10 = 10, /**< ISBN-10 (from EAN-13). @since 0.4 */ + ZBAR_UPCA = 12, /**< UPC-A */ + ZBAR_EAN13 = 13, /**< EAN-13 */ + ZBAR_ISBN13 = 14, /**< ISBN-13 (from EAN-13). @since 0.4 */ + ZBAR_COMPOSITE = 15, /**< EAN/UPC composite */ + ZBAR_I25 = 25, /**< Interleaved 2 of 5. @since 0.4 */ + ZBAR_DATABAR = 34, /**< GS1 DataBar (RSS). @since 0.11 */ + ZBAR_DATABAR_EXP = 35, /**< GS1 DataBar Expanded. @since 0.11 */ + ZBAR_CODABAR = 38, /**< Codabar. @since 0.11 */ + ZBAR_CODE39 = 39, /**< Code 39. @since 0.4 */ + ZBAR_PDF417 = 57, /**< PDF417. @since 0.6 */ + ZBAR_QRCODE = 64, /**< QR Code. @since 0.10 */ + ZBAR_SQCODE = 80, /**< SQ Code. @since 0.20.1 */ + ZBAR_CODE93 = 93, /**< Code 93. @since 0.11 */ + ZBAR_CODE128 = 128, /**< Code 128 */ + + /* + * Please see _zbar_get_symbol_hash() if adding + * anything after 128 + */ + + /** mask for base symbol type. + * @deprecated in 0.11, remove this from existing code + */ + ZBAR_SYMBOL = 0x00ff, + /** 2-digit add-on flag. + * @deprecated in 0.11, a ::ZBAR_EAN2 component is used for + * 2-digit GS1 add-ons + */ + ZBAR_ADDON2 = 0x0200, + /** 5-digit add-on flag. + * @deprecated in 0.11, a ::ZBAR_EAN5 component is used for + * 5-digit GS1 add-ons + */ + ZBAR_ADDON5 = 0x0500, + /** add-on flag mask. + * @deprecated in 0.11, GS1 add-ons are represented using composite + * symbols of type ::ZBAR_COMPOSITE; add-on components use ::ZBAR_EAN2 + * or ::ZBAR_EAN5 + */ + ZBAR_ADDON = 0x0700, +} zbar_symbol_type_t; + +/** decoded symbol coarse orientation. + * @since 0.11 + */ +typedef enum zbar_orientation_e +{ + ZBAR_ORIENT_UNKNOWN = -1, /**< unable to determine orientation */ + ZBAR_ORIENT_UP, /**< upright, read left to right */ + ZBAR_ORIENT_RIGHT, /**< sideways, read top to bottom */ + ZBAR_ORIENT_DOWN, /**< upside-down, read right to left */ + ZBAR_ORIENT_LEFT, /**< sideways, read bottom to top */ +} zbar_orientation_t; + +/** error codes. */ +typedef enum zbar_error_e +{ + ZBAR_OK = 0, /**< no error */ + ZBAR_ERR_NOMEM, /**< out of memory */ + ZBAR_ERR_INTERNAL, /**< internal library error */ + ZBAR_ERR_UNSUPPORTED, /**< unsupported request */ + ZBAR_ERR_INVALID, /**< invalid request */ + ZBAR_ERR_SYSTEM, /**< system error */ + ZBAR_ERR_LOCKING, /**< locking error */ + ZBAR_ERR_BUSY, /**< all resources busy */ + ZBAR_ERR_XDISPLAY, /**< X11 display error */ + ZBAR_ERR_XPROTO, /**< X11 protocol error */ + ZBAR_ERR_CLOSED, /**< output window is closed */ + ZBAR_ERR_WINAPI, /**< windows system error */ + ZBAR_ERR_NUM /**< number of error codes */ +} zbar_error_t; + +/** decoder configuration options. + * @since 0.4 + */ +typedef enum zbar_config_e +{ + ZBAR_CFG_ENABLE = 0, /**< enable symbology/feature */ + ZBAR_CFG_ADD_CHECK, /**< enable check digit when optional */ + ZBAR_CFG_EMIT_CHECK, /**< return check digit when present */ + ZBAR_CFG_ASCII, /**< enable full ASCII character set */ + ZBAR_CFG_BINARY, /**< don't convert binary data to text */ + ZBAR_CFG_NUM, /**< number of boolean decoder configs */ + + ZBAR_CFG_MIN_LEN = 0x20, /**< minimum data length for valid decode */ + ZBAR_CFG_MAX_LEN, /**< maximum data length for valid decode */ + + ZBAR_CFG_UNCERTAINTY = 0x40, /**< required video consistency frames */ + + ZBAR_CFG_POSITION = 0x80, /**< enable scanner to collect position data */ + ZBAR_CFG_TEST_INVERTED, /**< if fails to decode, test inverted */ + + ZBAR_CFG_X_DENSITY = 0x100, /**< image scanner vertical scan density */ + ZBAR_CFG_Y_DENSITY, /**< image scanner horizontal scan density */ +} zbar_config_t; + +/** decoder symbology modifier flags. + * @since 0.11 + */ +typedef enum zbar_modifier_e +{ + /** barcode tagged as GS1 (EAN.UCC) reserved + * (eg, FNC1 before first data character). + * data may be parsed as a sequence of GS1 AIs + */ + ZBAR_MOD_GS1 = 0, + + /** barcode tagged as AIM reserved + * (eg, FNC1 after first character or digit pair) + */ + ZBAR_MOD_AIM, + + /** number of modifiers */ + ZBAR_MOD_NUM, +} zbar_modifier_t; + +typedef enum video_control_type_e +{ + VIDEO_CNTL_INTEGER = 1, + VIDEO_CNTL_MENU, + VIDEO_CNTL_BUTTON, + VIDEO_CNTL_INTEGER64, + VIDEO_CNTL_STRING, + VIDEO_CNTL_BOOLEAN, +} video_control_type_t; + +/** store video control menu + * @param name name of the menu item + * @param val integer value associated with the item + */ +typedef struct video_control_menu_s { + char *name; + int64_t value; +} video_control_menu_t; + +/** store video controls + * @param name name of the control + * @param group name of the control group/class + * @param type type of the control + * @param min minimum value of control (if control is integer) + * @param max maximum value of control (if control is integer) + * @param def default value of control (if control is integer) + * @param step increment steps (if control is integer) + * @param menu menu array + * @param menu_size menu size + * @since 0.20 + */ +typedef struct video_controls_s { + char *name; + char *group; + video_control_type_t type; + + int64_t min, max, def; + uint64_t step; + + unsigned int menu_size; + video_control_menu_t *menu; + + void *next; + + // video drivers may add extra private data in the end of this struct +} video_controls_t; + +/** store a video resolution + * @param width width of the video window + * @param height length of the video window + * @param max_fps maximum streaming speed, in frames per second + * @since 0.22 + */ +struct video_resolution_s { + unsigned int width, height; + float max_fps; +}; + +/** retrieve runtime library version information. + * @param major set to the running major version (unless NULL) + * @param minor set to the running minor version (unless NULL) + * @returns 0 + */ +extern int zbar_version(unsigned *major, unsigned *minor, unsigned *patch); + +/** set global library debug level. + * @param verbosity desired debug level. higher values create more spew + */ +extern void zbar_set_verbosity(int verbosity); + +/** increase global library debug level. + * eg, for -vvvv + */ +extern void zbar_increase_verbosity(void); + +/** retrieve string name for symbol encoding. + * @param sym symbol type encoding + * @returns the static string name for the specified symbol type, + * or "UNKNOWN" if the encoding is not recognized + */ +extern const char *zbar_get_symbol_name(zbar_symbol_type_t sym); + +/** retrieve string name for addon encoding. + * @param sym symbol type encoding + * @returns static string name for any addon, or the empty string + * if no addons were decoded + * @deprecated in 0.11 + */ +extern const char *zbar_get_addon_name(zbar_symbol_type_t sym); + +/** retrieve string name for configuration setting. + * @param config setting to name + * @returns static string name for config, + * or the empty string if value is not a known config + */ +extern const char *zbar_get_config_name(zbar_config_t config); + +/** retrieve string name for modifier. + * @param modifier flag to name + * @returns static string name for modifier, + * or the empty string if the value is not a known flag + */ +extern const char *zbar_get_modifier_name(zbar_modifier_t modifier); + +/** retrieve string name for orientation. + * @param orientation orientation encoding + * @returns the static string name for the specified orientation, + * or "UNKNOWN" if the orientation is not recognized + * @since 0.11 + */ +extern const char *zbar_get_orientation_name(zbar_orientation_t orientation); + +/** parse a configuration string of the form "[symbology.]config[=value]". + * the config must match one of the recognized names. + * the symbology, if present, must match one of the recognized names. + * if symbology is unspecified, it will be set to 0. + * if value is unspecified it will be set to 1. + * @returns 0 if the config is parsed successfully, 1 otherwise + * @since 0.4 + */ +extern int zbar_parse_config(const char *config_string, + zbar_symbol_type_t *symbology, + zbar_config_t *config, int *value); + +/** consistently compute fourcc values across architectures + * (adapted from v4l2 specification) + * @since 0.11 + */ +#define zbar_fourcc(a, b, c, d) \ + ((unsigned long)(a) | ((unsigned long)(b) << 8) | \ + ((unsigned long)(c) << 16) | ((unsigned long)(d) << 24)) + +/** parse a fourcc string into its encoded integer value. + * @since 0.11 + */ +static inline unsigned long zbar_fourcc_parse(const char *format) +{ + unsigned long fourcc = 0; + if (format) { + int i; + for (i = 0; i < 4 && format[i]; i++) + fourcc |= ((unsigned long)format[i]) << (i * 8); + } + return (fourcc); +} + +/** @internal type unsafe error API (don't use) */ +extern int _zbar_error_spew(const void *object, int verbosity); +extern const char *_zbar_error_string(const void *object, int verbosity); +extern zbar_error_t _zbar_get_error_code(const void *object); + +/*@}*/ + +struct zbar_symbol_s; +typedef struct zbar_symbol_s zbar_symbol_t; + +struct zbar_symbol_set_s; +typedef struct zbar_symbol_set_s zbar_symbol_set_t; + +/*------------------------------------------------------------*/ +/** @name Symbol interface + * decoded barcode symbol result object. stores type, data, and image + * location of decoded symbol. all memory is owned by the library + */ +/*@{*/ + +/** @typedef zbar_symbol_t + * opaque decoded symbol object. + */ + +/** symbol reference count manipulation. + * increment the reference count when you store a new reference to the + * symbol. decrement when the reference is no longer used. do not + * refer to the symbol once the count is decremented and the + * containing image has been recycled or destroyed. + * @note the containing image holds a reference to the symbol, so you + * only need to use this if you keep a symbol after the image has been + * destroyed or reused. + * @since 0.9 + */ +extern void zbar_symbol_ref(const zbar_symbol_t *symbol, int refs); + +/** retrieve type of decoded symbol. + * @returns the symbol type + */ +extern zbar_symbol_type_t zbar_symbol_get_type(const zbar_symbol_t *symbol); + +/** retrieve symbology boolean config settings. + * @returns a bitmask indicating which configs were set for the detected + * symbology during decoding. + * @since 0.11 + */ +extern unsigned int zbar_symbol_get_configs(const zbar_symbol_t *symbol); + +/** retrieve symbology modifier flag settings. + * @returns a bitmask indicating which characteristics were detected + * during decoding. + * @since 0.11 + */ +extern unsigned int zbar_symbol_get_modifiers(const zbar_symbol_t *symbol); + +/** retrieve data decoded from symbol. + * @returns the data string + */ +extern const char *zbar_symbol_get_data(const zbar_symbol_t *symbol); + +/** retrieve length of binary data. + * @returns the length of the decoded data + */ +extern unsigned int zbar_symbol_get_data_length(const zbar_symbol_t *symbol); + +/** retrieve a symbol confidence metric. + * @returns an unscaled, relative quantity: larger values are better + * than smaller values, where "large" and "small" are application + * dependent. + * @note expect the exact definition of this quantity to change as the + * metric is refined. currently, only the ordered relationship + * between two values is defined and will remain stable in the future + * @since 0.9 + */ +extern int zbar_symbol_get_quality(const zbar_symbol_t *symbol); + +/** retrieve current cache count. when the cache is enabled for the + * image_scanner this provides inter-frame reliability and redundancy + * information for video streams. + * @returns < 0 if symbol is still uncertain. + * @returns 0 if symbol is newly verified. + * @returns > 0 for duplicate symbols + */ +extern int zbar_symbol_get_count(const zbar_symbol_t *symbol); + +/** retrieve the number of points in the location polygon. the + * location polygon defines the image area that the symbol was + * extracted from. + * @returns the number of points in the location polygon + * @note this is currently not a polygon, but the scan locations + * where the symbol was decoded + */ +extern unsigned zbar_symbol_get_loc_size(const zbar_symbol_t *symbol); + +/** retrieve location polygon x-coordinates. + * points are specified by 0-based index. + * @returns the x-coordinate for a point in the location polygon. + * @returns -1 if index is out of range + */ +extern int zbar_symbol_get_loc_x(const zbar_symbol_t *symbol, unsigned index); + +/** retrieve location polygon y-coordinates. + * points are specified by 0-based index. + * @returns the y-coordinate for a point in the location polygon. + * @returns -1 if index is out of range + */ +extern int zbar_symbol_get_loc_y(const zbar_symbol_t *symbol, unsigned index); + +/** retrieve general orientation of decoded symbol. + * @returns a coarse, axis-aligned indication of symbol orientation or + * ::ZBAR_ORIENT_UNKNOWN if unknown + * @since 0.11 + */ +extern zbar_orientation_t +zbar_symbol_get_orientation(const zbar_symbol_t *symbol); + +/** iterate the set to which this symbol belongs (there can be only one). + * @returns the next symbol in the set, or + * @returns NULL when no more results are available + */ +extern const zbar_symbol_t *zbar_symbol_next(const zbar_symbol_t *symbol); + +/** retrieve components of a composite result. + * @returns the symbol set containing the components + * @returns NULL if the symbol is already a physical symbol + * @since 0.10 + */ +extern const zbar_symbol_set_t * +zbar_symbol_get_components(const zbar_symbol_t *symbol); + +/** iterate components of a composite result. + * @returns the first physical component symbol of a composite result + * @returns NULL if the symbol is already a physical symbol + * @since 0.10 + */ +extern const zbar_symbol_t * +zbar_symbol_first_component(const zbar_symbol_t *symbol); + +/** print XML symbol element representation to user result buffer. + * @see http://zbar.sourceforge.net/2008/barcode.xsd for the schema. + * @param symbol is the symbol to print + * @param buffer is the inout result pointer, it will be reallocated + * with a larger size if necessary. + * @param buflen is inout length of the result buffer. + * @returns the buffer pointer + * @since 0.6 + */ +extern char *zbar_symbol_xml(const zbar_symbol_t *symbol, char **buffer, + unsigned *buflen); + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Symbol Set interface + * container for decoded result symbols associated with an image + * or a composite symbol. + * @since 0.10 + */ +/*@{*/ + +/** @typedef zbar_symbol_set_t + * opaque symbol iterator object. + * @since 0.10 + */ + +/** reference count manipulation. + * increment the reference count when you store a new reference. + * decrement when the reference is no longer used. do not refer to + * the object any longer once references have been released. + * @since 0.10 + */ +extern void zbar_symbol_set_ref(const zbar_symbol_set_t *symbols, int refs); + +/** retrieve set size. + * @returns the number of symbols in the set. + * @since 0.10 + */ +extern int zbar_symbol_set_get_size(const zbar_symbol_set_t *symbols); + +/** set iterator. + * @returns the first decoded symbol result in a set + * @returns NULL if the set is empty + * @since 0.10 + */ +extern const zbar_symbol_t * +zbar_symbol_set_first_symbol(const zbar_symbol_set_t *symbols); + +/** raw result iterator. + * @returns the first decoded symbol result in a set, *before* filtering + * @returns NULL if the set is empty + * @since 0.11 + */ +extern const zbar_symbol_t * +zbar_symbol_set_first_unfiltered(const zbar_symbol_set_t *symbols); + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Image interface + * stores image data samples along with associated format and size + * metadata + */ +/*@{*/ + +struct zbar_image_s; +/** + * zbar_image_t: opaque image object. + */ +typedef struct zbar_image_s zbar_image_t; + +/** cleanup handler callback function. + * called to free sample data when an image is destroyed. + */ +typedef void(zbar_image_cleanup_handler_t)(zbar_image_t *image); + +/** data handler callback function. + * called when decoded symbol results are available for an image + */ +typedef void(zbar_image_data_handler_t)(zbar_image_t *image, + const void *userdata); + +/** new image constructor. + * @returns a new image object with uninitialized data and format. + * this image should be destroyed (using zbar_image_destroy()) as + * soon as the application is finished with it + */ +extern zbar_image_t *zbar_image_create(void); + +/** image destructor. all images created by or returned to the + * application should be destroyed using this function. when an image + * is destroyed, the associated data cleanup handler will be invoked + * if available + * @note make no assumptions about the image or the data buffer. + * they may not be destroyed/cleaned immediately if the library + * is still using them. if necessary, use the cleanup handler hook + * to keep track of image data buffers + */ +extern void zbar_image_destroy(zbar_image_t *image); + +/** image reference count manipulation. + * increment the reference count when you store a new reference to the + * image. decrement when the reference is no longer used. do not + * refer to the image any longer once the count is decremented. + * zbar_image_ref(image, -1) is the same as zbar_image_destroy(image) + * @since 0.5 + */ +extern void zbar_image_ref(zbar_image_t *image, int refs); + +/** image format conversion. refer to the documentation for supported + * image formats + * @returns a @em new image with the sample data from the original image + * converted to the requested format. the original image is + * unaffected. + * @note the converted image size may be rounded (up) due to format + * constraints + */ +extern zbar_image_t *zbar_image_convert(const zbar_image_t *image, + unsigned long format); + +/** image format conversion with crop/pad. + * if the requested size is larger than the image, the last row/column + * are duplicated to cover the difference. if the requested size is + * smaller than the image, the extra rows/columns are dropped from the + * right/bottom. + * @returns a @em new image with the sample data from the original + * image converted to the requested format and size. + * @note the image is @em not scaled + * @see zbar_image_convert() + * @since 0.4 + */ +extern zbar_image_t *zbar_image_convert_resize(const zbar_image_t *image, + unsigned long format, + unsigned width, unsigned height); + +/** retrieve the image format. + * @returns the fourcc describing the format of the image sample data + */ +extern unsigned long zbar_image_get_format(const zbar_image_t *image); + +/** retrieve a "sequence" (page/frame) number associated with this image. + * @since 0.6 + */ +extern unsigned zbar_image_get_sequence(const zbar_image_t *image); + +/** retrieve the width of the image. + * @returns the width in sample columns + */ +extern unsigned zbar_image_get_width(const zbar_image_t *image); + +/** retrieve the height of the image. + * @returns the height in sample rows + */ +extern unsigned zbar_image_get_height(const zbar_image_t *image); + +/** retrieve both dimensions of the image. + * fills in the width and height in samples + */ +extern void zbar_image_get_size(const zbar_image_t *image, unsigned *width, + unsigned *height); + +/** retrieve the crop rectangle. + * fills in the image coordinates of the upper left corner and size + * of an axis-aligned rectangular area of the image that will be scanned. + * defaults to the full image + * @since 0.11 + */ +extern void zbar_image_get_crop(const zbar_image_t *image, unsigned *x, + unsigned *y, unsigned *width, unsigned *height); + +/** return the image sample data. the returned data buffer is only + * valid until zbar_image_destroy() is called + */ +extern const void *zbar_image_get_data(const zbar_image_t *image); + +/** return the size of image data. + * @since 0.6 + */ +extern unsigned long zbar_image_get_data_length(const zbar_image_t *img); + +/** retrieve the decoded results. + * @returns the (possibly empty) set of decoded symbols + * @returns NULL if the image has not been scanned + * @since 0.10 + */ +extern const zbar_symbol_set_t * +zbar_image_get_symbols(const zbar_image_t *image); + +/** associate the specified symbol set with the image, replacing any + * existing results. use NULL to release the current results from the + * image. + * @see zbar_image_scanner_recycle_image() + * @since 0.10 + */ +extern void zbar_image_set_symbols(zbar_image_t *image, + const zbar_symbol_set_t *symbols); + +/** image_scanner decode result iterator. + * @returns the first decoded symbol result for an image + * or NULL if no results are available + */ +extern const zbar_symbol_t *zbar_image_first_symbol(const zbar_image_t *image); + +/** specify the fourcc image format code for image sample data. + * refer to the documentation for supported formats. + * @note this does not convert the data! + * (see zbar_image_convert() for that) + */ +extern void zbar_image_set_format(zbar_image_t *image, unsigned long format); + +/** associate a "sequence" (page/frame) number with this image. + * @since 0.6 + */ +extern void zbar_image_set_sequence(zbar_image_t *image, unsigned sequence_num); + +/** specify the pixel size of the image. + * @note this also resets the crop rectangle to the full image + * (0, 0, width, height) + * @note this does not affect the data! + */ +extern void zbar_image_set_size(zbar_image_t *image, unsigned width, + unsigned height); + +/** specify a rectangular region of the image to scan. + * the rectangle will be clipped to the image boundaries. + * defaults to the full image specified by zbar_image_set_size() + */ +extern void zbar_image_set_crop(zbar_image_t *image, unsigned x, unsigned y, + unsigned width, unsigned height); + +/** specify image sample data. when image data is no longer needed by + * the library the specific data cleanup handler will be called + * (unless NULL) + * @note application image data will not be modified by the library + */ +extern void zbar_image_set_data(zbar_image_t *image, const void *data, + unsigned long data_byte_length, + zbar_image_cleanup_handler_t *cleanup_hndlr); + +/** built-in cleanup handler. + * passes the image data buffer to free() + */ +extern void zbar_image_free_data(zbar_image_t *image); + +/** associate user specified data value with an image. + * @since 0.5 + */ +extern void zbar_image_set_userdata(zbar_image_t *image, void *userdata); + +/** return user specified data value associated with the image. + * @since 0.5 + */ +extern void *zbar_image_get_userdata(const zbar_image_t *image); + +/** dump raw image data to a file for debug. + * the data will be prefixed with a 16 byte header consisting of: + * - 4 bytes uint = 0x676d697a ("zimg") + * - 4 bytes format fourcc + * - 2 bytes width + * - 2 bytes height + * - 4 bytes size of following image data in bytes + * this header can be dumped w/eg: + * @verbatim + od -Ax -tx1z -N16 -w4 [file] +@endverbatim + * for some formats the image can be displayed/converted using + * ImageMagick, eg: + * @verbatim + display -size 640x480+16 [-depth ?] [-sampling-factor ?x?] \ + {GRAY,RGB,UYVY,YUV}:[file] +@endverbatim + * + * @param image the image object to dump + * @param filebase base filename, appended with ".XXXX.zimg" where + * XXXX is the format fourcc + * @returns 0 on success or a system error code on failure + */ +extern int zbar_image_write(const zbar_image_t *image, const char *filebase); + +/** read back an image in the format written by zbar_image_write() + * @note TBD + */ +extern zbar_image_t *zbar_image_read(char *filename); + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Processor interface + * @anchor c-processor + * high-level self-contained image processor. + * processes video and images for barcodes, optionally displaying + * images to a library owned output window + */ +/*@{*/ + +struct zbar_processor_s; +/** opaque standalone processor object. */ +typedef struct zbar_processor_s zbar_processor_t; + +/** constructor. + * if threaded is set and threading is available the processor + * will spawn threads where appropriate to avoid blocking and + * improve responsiveness + */ +extern zbar_processor_t *zbar_processor_create(int threaded); + +/** destructor. cleans up all resources associated with the processor + */ +extern void zbar_processor_destroy(zbar_processor_t *processor); + +/** (re)initialization. + * opens a video input device and/or prepares to display output + */ +extern int zbar_processor_init(zbar_processor_t *processor, + const char *video_device, int enable_display); + +/** request a preferred size for the video image from the device. + * the request may be adjusted or completely ignored by the driver. + * @note must be called before zbar_processor_init() + * @since 0.6 + */ +extern int zbar_processor_request_size(zbar_processor_t *processor, + unsigned width, unsigned height); + +/** request a preferred video driver interface version for + * debug/testing. + * @note must be called before zbar_processor_init() + * @since 0.6 + */ +extern int zbar_processor_request_interface(zbar_processor_t *processor, + int version); + +/** request a preferred video I/O mode for debug/testing. You will + * get errors if the driver does not support the specified mode. + * @verbatim + 0 = auto-detect + 1 = force I/O using read() + 2 = force memory mapped I/O using mmap() + 3 = force USERPTR I/O (v4l2 only) +@endverbatim + * @note must be called before zbar_processor_init() + * @since 0.7 + */ +extern int zbar_processor_request_iomode(zbar_processor_t *video, int iomode); + +/** force specific input and output formats for debug/testing. + * @note must be called before zbar_processor_init() + */ +extern int zbar_processor_force_format(zbar_processor_t *processor, + unsigned long input_format, + unsigned long output_format); + +/** setup result handler callback. + * the specified function will be called by the processor whenever + * new results are available from the video stream or a static image. + * pass a NULL value to disable callbacks. + * @param processor the object on which to set the handler. + * @param handler the function to call when new results are available. + * @param userdata is set as with zbar_processor_set_userdata(). + * @returns the previously registered handler + */ +extern zbar_image_data_handler_t * +zbar_processor_set_data_handler(zbar_processor_t *processor, + zbar_image_data_handler_t *handler, + const void *userdata); + +/** associate user specified data value with the processor. + * @since 0.6 + */ +extern void zbar_processor_set_userdata(zbar_processor_t *processor, + void *userdata); + +/** return user specified data value associated with the processor. + * @since 0.6 + */ +extern void *zbar_processor_get_userdata(const zbar_processor_t *processor); + +/** set config for indicated symbology (0 for all) to specified value. + * @returns 0 for success, non-0 for failure (config does not apply to + * specified symbology, or value out of range) + * @see zbar_decoder_set_config() + * @since 0.4 + */ +extern int zbar_processor_set_config(zbar_processor_t *processor, + zbar_symbol_type_t symbology, + zbar_config_t config, int value); + +/** set video control value + * @returns 0 for success, non-0 for failure + * @since 0.20 + * @see zbar_video_set_control() + */ +extern int zbar_processor_set_control(zbar_processor_t *processor, + const char *control_name, int value); + +/** get video control value + * @returns 0 for success, non-0 for failure + * @since 0.20 + * @see zbar_video_get_control() + */ +extern int zbar_processor_get_control(zbar_processor_t *processor, + const char *control_name, int *value); + +/** parse configuration string using zbar_parse_config() + * and apply to processor using zbar_processor_set_config(). + * @returns 0 for success, non-0 for failure + * @see zbar_parse_config() + * @see zbar_processor_set_config() + * @since 0.4 + */ +static inline int zbar_processor_parse_config(zbar_processor_t *processor, + const char *config_string) +{ + zbar_symbol_type_t sym; + zbar_config_t cfg; + int val; + return (zbar_parse_config(config_string, &sym, &cfg, &val) || + zbar_processor_set_config(processor, sym, cfg, val)); +} + +/** retrieve the current state of the output window. + * @returns 1 if the output window is currently displayed, 0 if not. + * @returns -1 if an error occurs + */ +extern int zbar_processor_is_visible(zbar_processor_t *processor); + +/** show or hide the display window owned by the library. + * the size will be adjusted to the input size + */ +extern int zbar_processor_set_visible(zbar_processor_t *processor, int visible); + +/** control the processor in free running video mode. + * only works if video input is initialized. if threading is in use, + * scanning will occur in the background, otherwise this is only + * useful wrapping calls to zbar_processor_user_wait(). if the + * library output window is visible, video display will be enabled. + */ +extern int zbar_processor_set_active(zbar_processor_t *processor, int active); + +/** retrieve decode results for last scanned image/frame. + * @returns the symbol set result container or NULL if no results are + * available + * @note the returned symbol set has its reference count incremented; + * ensure that the count is decremented after use + * @since 0.10 + */ +extern const zbar_symbol_set_t * +zbar_processor_get_results(const zbar_processor_t *processor); + +/** wait for input to the display window from the user + * (via mouse or keyboard). + * @returns >0 when input is received, 0 if timeout ms expired + * with no input or -1 in case of an error + */ +extern int zbar_processor_user_wait(zbar_processor_t *processor, int timeout); + +/** process from the video stream until a result is available, + * or the timeout (in milliseconds) expires. + * specify a timeout of -1 to scan indefinitely + * (zbar_processor_set_active() may still be used to abort the scan + * from another thread). + * if the library window is visible, video display will be enabled. + * @note that multiple results may still be returned (despite the + * name). + * @returns >0 if symbols were successfully decoded, + * 0 if no symbols were found (ie, the timeout expired) + * or -1 if an error occurs + */ +extern int zbar_process_one(zbar_processor_t *processor, int timeout); + +/** process the provided image for barcodes. + * if the library window is visible, the image will be displayed. + * @returns >0 if symbols were successfully decoded, + * 0 if no symbols were found or -1 if an error occurs + */ +extern int zbar_process_image(zbar_processor_t *processor, zbar_image_t *image); + +/** enable dbus IPC API. + * @returns 0 successful + */ +int zbar_processor_request_dbus(zbar_processor_t *proc, int req_dbus_enabled); + +/** display detail for last processor error to stderr. + * @returns a non-zero value suitable for passing to exit() + */ +static inline int zbar_processor_error_spew(const zbar_processor_t *processor, + int verbosity) +{ + return (_zbar_error_spew(processor, verbosity)); +} + +/** retrieve the detail string for the last processor error. */ +static inline const char * +zbar_processor_error_string(const zbar_processor_t *processor, int verbosity) +{ + return (_zbar_error_string(processor, verbosity)); +} + +/** retrieve the type code for the last processor error. */ +static inline zbar_error_t +zbar_processor_get_error_code(const zbar_processor_t *processor) +{ + return (_zbar_get_error_code(processor)); +} + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Video interface + * @anchor c-video + * mid-level video source abstraction. + * captures images from a video device + */ +/*@{*/ + +struct zbar_video_s; +/** opaque video object. */ +typedef struct zbar_video_s zbar_video_t; + +/** constructor. */ +extern zbar_video_t *zbar_video_create(void); + +/** destructor. */ +extern void zbar_video_destroy(zbar_video_t *video); + +/** open and probe a video device. + * the device specified by platform specific unique name + * (v4l device node path in *nix eg "/dev/video", + * DirectShow DevicePath property in windows). + * @returns 0 if successful or -1 if an error occurs + */ +extern int zbar_video_open(zbar_video_t *video, const char *device); + +/** retrieve file descriptor associated with open *nix video device + * useful for using select()/poll() to tell when new images are + * available (NB v4l2 only!!). + * @returns the file descriptor or -1 if the video device is not open + * or the driver only supports v4l1 + */ +extern int zbar_video_get_fd(const zbar_video_t *video); + +/** request a preferred size for the video image from the device. + * the request may be adjusted or completely ignored by the driver. + * @returns 0 if successful or -1 if the video device is already + * initialized + * @since 0.6 + */ +extern int zbar_video_request_size(zbar_video_t *video, unsigned width, + unsigned height); + +/** request a preferred driver interface version for debug/testing. + * @note must be called before zbar_video_open() + * @since 0.6 + */ +extern int zbar_video_request_interface(zbar_video_t *video, int version); + +/** request a preferred I/O mode for debug/testing. You will get + * errors if the driver does not support the specified mode. + * @verbatim + 0 = auto-detect + 1 = force I/O using read() + 2 = force memory mapped I/O using mmap() + 3 = force USERPTR I/O (v4l2 only) +@endverbatim + * @note must be called before zbar_video_open() + * @since 0.7 + */ +extern int zbar_video_request_iomode(zbar_video_t *video, int iomode); + +/** retrieve current output image width. + * @returns the width or 0 if the video device is not open + */ +extern int zbar_video_get_width(const zbar_video_t *video); + +/** retrieve current output image height. + * @returns the height or 0 if the video device is not open + */ +extern int zbar_video_get_height(const zbar_video_t *video); + +/** initialize video using a specific format for debug. + * use zbar_negotiate_format() to automatically select and initialize + * the best available format + */ +extern int zbar_video_init(zbar_video_t *video, unsigned long format); + +/** start/stop video capture. + * all buffered images are retired when capture is disabled. + * @returns 0 if successful or -1 if an error occurs + */ +extern int zbar_video_enable(zbar_video_t *video, int enable); + +/** retrieve next captured image. blocks until an image is available. + * @returns NULL if video is not enabled or an error occurs + */ +extern zbar_image_t *zbar_video_next_image(zbar_video_t *video); + +/** set video control value (integer). + * @returns 0 for success, non-0 for failure + * @since 0.20 + * @see zbar_processor_set_control() + */ +extern int zbar_video_set_control(zbar_video_t *video, const char *control_name, + int value); + +/** get video control value (integer). + * @returns 0 for success, non-0 for failure + * @since 0.20 + * @see zbar_processor_get_control() + */ +extern int zbar_video_get_control(zbar_video_t *video, const char *control_name, + int *value); + +/** get available controls from video source + * @returns 0 for success, non-0 for failure + * @since 0.20 + */ +extern struct video_controls_s * +zbar_video_get_controls(const zbar_video_t *video, int index); + +/** get available video resolutions from video source + * @returns 0 for success, non-0 for failure + * @since 0.22 + */ +extern struct video_resolution_s * +zbar_video_get_resolutions(const zbar_video_t *vdo, int index); + +/** display detail for last video error to stderr. + * @returns a non-zero value suitable for passing to exit() + */ +static inline int zbar_video_error_spew(const zbar_video_t *video, + int verbosity) +{ + return (_zbar_error_spew(video, verbosity)); +} + +/** retrieve the detail string for the last video error. */ +static inline const char *zbar_video_error_string(const zbar_video_t *video, + int verbosity) +{ + return (_zbar_error_string(video, verbosity)); +} + +/** retrieve the type code for the last video error. */ +static inline zbar_error_t zbar_video_get_error_code(const zbar_video_t *video) +{ + return (_zbar_get_error_code(video)); +} + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Window interface + * @anchor c-window + * mid-level output window abstraction. + * displays images to user-specified platform specific output window + */ +/*@{*/ + +struct zbar_window_s; +/** opaque window object. */ +typedef struct zbar_window_s zbar_window_t; + +/** constructor. */ +extern zbar_window_t *zbar_window_create(void); + +/** destructor. */ +extern void zbar_window_destroy(zbar_window_t *window); + +/** associate reader with an existing platform window. + * This can be any "Drawable" for X Windows or a "HWND" for windows. + * input images will be scaled into the output window. + * pass NULL to detach from the resource, further input will be + * ignored + */ +extern int zbar_window_attach(zbar_window_t *window, void *x11_display_w32_hwnd, + unsigned long x11_drawable); + +/** control content level of the reader overlay. + * the overlay displays graphical data for informational or debug + * purposes. higher values increase the level of annotation (possibly + * decreasing performance). @verbatim + 0 = disable overlay + 1 = outline decoded symbols (default) + 2 = also track and display input frame rate +@endverbatim + */ +extern void zbar_window_set_overlay(zbar_window_t *window, int level); + +/** retrieve current content level of reader overlay. + * @see zbar_window_set_overlay() + * @since 0.10 + */ +extern int zbar_window_get_overlay(const zbar_window_t *window); + +/** draw a new image into the output window. */ +extern int zbar_window_draw(zbar_window_t *window, zbar_image_t *image); + +/** redraw the last image (exposure handler). */ +extern int zbar_window_redraw(zbar_window_t *window); + +/** resize the image window (reconfigure handler). + * this does @em not update the contents of the window + * @since 0.3, changed in 0.4 to not redraw window + */ +extern int zbar_window_resize(zbar_window_t *window, unsigned width, + unsigned height); + +/** display detail for last window error to stderr. + * @returns a non-zero value suitable for passing to exit() + */ +static inline int zbar_window_error_spew(const zbar_window_t *window, + int verbosity) +{ + return (_zbar_error_spew(window, verbosity)); +} + +/** retrieve the detail string for the last window error. */ +static inline const char *zbar_window_error_string(const zbar_window_t *window, + int verbosity) +{ + return (_zbar_error_string(window, verbosity)); +} + +/** retrieve the type code for the last window error. */ +static inline zbar_error_t +zbar_window_get_error_code(const zbar_window_t *window) +{ + return (_zbar_get_error_code(window)); +} + +/** select a compatible format between video input and output window. + * the selection algorithm attempts to use a format shared by + * video input and window output which is also most useful for + * barcode scanning. if a format conversion is necessary, it will + * heuristically attempt to minimize the cost of the conversion + */ +extern int zbar_negotiate_format(zbar_video_t *video, zbar_window_t *window); + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Image Scanner interface + * @anchor c-imagescanner + * mid-level image scanner interface. + * reads barcodes from 2-D images + */ +/*@{*/ + +struct zbar_image_scanner_s; +/** opaque image scanner object. */ +typedef struct zbar_image_scanner_s zbar_image_scanner_t; + +/** constructor. */ +extern zbar_image_scanner_t *zbar_image_scanner_create(void); + +/** destructor. */ +extern void zbar_image_scanner_destroy(zbar_image_scanner_t *scanner); + +/** setup result handler callback. + * the specified function will be called by the scanner whenever + * new results are available from a decoded image. + * pass a NULL value to disable callbacks. + * @returns the previously registered handler + */ +extern zbar_image_data_handler_t * +zbar_image_scanner_set_data_handler(zbar_image_scanner_t *scanner, + zbar_image_data_handler_t *handler, + const void *userdata); + +/** request sending decoded codes via D-Bus + * @see zbar_processor_parse_config() + * @since 0.21 + */ +extern int zbar_image_scanner_request_dbus(zbar_image_scanner_t *scanner, + int req_dbus_enabled); + +/** set config for indicated symbology (0 for all) to specified value. + * @returns 0 for success, non-0 for failure (config does not apply to + * specified symbology, or value out of range) + * @see zbar_decoder_set_config() + * @since 0.4 + */ +extern int zbar_image_scanner_set_config(zbar_image_scanner_t *scanner, + zbar_symbol_type_t symbology, + zbar_config_t config, int value); + +/** get config for indicated symbology + * @returns 0 for success, non-0 for failure (config does not apply to + * specified symbology, or value out of range). On success, *value is filled. + * @since 0.22 + */ +extern int zbar_image_scanner_get_config(zbar_image_scanner_t *scanner, + zbar_symbol_type_t symbology, + zbar_config_t config, int *value); + +/** parse configuration string using zbar_parse_config() + * and apply to image scanner using zbar_image_scanner_set_config(). + * @returns 0 for success, non-0 for failure + * @see zbar_parse_config() + * @see zbar_image_scanner_set_config() + * @since 0.4 + */ +static inline int zbar_image_scanner_parse_config(zbar_image_scanner_t *scanner, + const char *config_string) +{ + zbar_symbol_type_t sym; + zbar_config_t cfg; + int val; + return (zbar_parse_config(config_string, &sym, &cfg, &val) || + zbar_image_scanner_set_config(scanner, sym, cfg, val)); +} + +/** enable or disable the inter-image result cache (default disabled). + * mostly useful for scanning video frames, the cache filters + * duplicate results from consecutive images, while adding some + * consistency checking and hysteresis to the results. + * this interface also clears the cache + */ +extern void zbar_image_scanner_enable_cache(zbar_image_scanner_t *scanner, + int enable); + +/** remove any previously decoded results from the image scanner and the + * specified image. somewhat more efficient version of + * zbar_image_set_symbols(image, NULL) which may retain memory for + * subsequent decodes + * @since 0.10 + */ +extern void zbar_image_scanner_recycle_image(zbar_image_scanner_t *scanner, + zbar_image_t *image); + +/** retrieve decode results for last scanned image. + * @returns the symbol set result container or NULL if no results are + * available + * @note the symbol set does not have its reference count adjusted; + * ensure that the count is incremented if the results may be kept + * after the next image is scanned + * @since 0.10 + */ +extern const zbar_symbol_set_t * +zbar_image_scanner_get_results(const zbar_image_scanner_t *scanner); + +/** scan for symbols in provided image. The image format must be + * "Y800" or "GRAY". + * @returns >0 if symbols were successfully decoded from the image, + * 0 if no symbols were found or -1 if an error occurs + * @see zbar_image_convert() + * @since 0.9 - changed to only accept grayscale images + */ +extern int zbar_scan_image(zbar_image_scanner_t *scanner, zbar_image_t *image); + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Decoder interface + * @anchor c-decoder + * low-level bar width stream decoder interface. + * identifies symbols and extracts encoded data + */ +/*@{*/ + +struct zbar_decoder_s; +/** opaque decoder object. */ +typedef struct zbar_decoder_s zbar_decoder_t; + +/** decoder data handler callback function. + * called by decoder when new data has just been decoded + */ +typedef void(zbar_decoder_handler_t)(zbar_decoder_t *decoder); + +/** constructor. */ +extern zbar_decoder_t *zbar_decoder_create(void); + +/** destructor. */ +extern void zbar_decoder_destroy(zbar_decoder_t *decoder); + +/** set config for indicated symbology (0 for all) to specified value. + * @returns 0 for success, non-0 for failure (config does not apply to + * specified symbology, or value out of range) + * @since 0.4 + */ +extern int zbar_decoder_set_config(zbar_decoder_t *decoder, + zbar_symbol_type_t symbology, + zbar_config_t config, int value); + +/** get config for indicated symbology + * @returns 0 for success, non-0 for failure (config does not apply to + * specified symbology, or value out of range). On success, *value is filled. + * @since 0.22 + */ +extern int zbar_decoder_get_config(zbar_decoder_t *decoder, + zbar_symbol_type_t symbology, + zbar_config_t config, int *value); + +/** parse configuration string using zbar_parse_config() + * and apply to decoder using zbar_decoder_set_config(). + * @returns 0 for success, non-0 for failure + * @see zbar_parse_config() + * @see zbar_decoder_set_config() + * @since 0.4 + */ +static inline int zbar_decoder_parse_config(zbar_decoder_t *decoder, + const char *config_string) +{ + zbar_symbol_type_t sym; + zbar_config_t cfg; + int val; + return (zbar_parse_config(config_string, &sym, &cfg, &val) || + zbar_decoder_set_config(decoder, sym, cfg, val)); +} + +/** retrieve symbology boolean config settings. + * @returns a bitmask indicating which configs are currently set for the + * specified symbology. + * @since 0.11 + */ +extern unsigned int zbar_decoder_get_configs(const zbar_decoder_t *decoder, + zbar_symbol_type_t symbology); + +/** clear all decoder state. + * any partial symbols are flushed + */ +extern void zbar_decoder_reset(zbar_decoder_t *decoder); + +/** mark start of a new scan pass. + * clears any intra-symbol state and resets color to ::ZBAR_SPACE. + * any partially decoded symbol state is retained + */ +extern void zbar_decoder_new_scan(zbar_decoder_t *decoder); + +/** process next bar/space width from input stream. + * the width is in arbitrary relative units. first value of a scan + * is ::ZBAR_SPACE width, alternating from there. + * @returns appropriate symbol type if width completes + * decode of a symbol (data is available for retrieval) + * @returns ::ZBAR_PARTIAL as a hint if part of a symbol was decoded + * @returns ::ZBAR_NONE (0) if no new symbol data is available + */ +extern zbar_symbol_type_t zbar_decode_width(zbar_decoder_t *decoder, + unsigned width); + +/** retrieve color of @em next element passed to + * zbar_decode_width(). */ +extern zbar_color_t zbar_decoder_get_color(const zbar_decoder_t *decoder); + +/** retrieve last decoded data. + * @returns the data string or NULL if no new data available. + * the returned data buffer is owned by library, contents are only + * valid between non-0 return from zbar_decode_width and next library + * call + */ +extern const char *zbar_decoder_get_data(const zbar_decoder_t *decoder); + +/** retrieve length of binary data. + * @returns the length of the decoded data or 0 if no new data + * available. + */ +extern unsigned int zbar_decoder_get_data_length(const zbar_decoder_t *decoder); + +/** retrieve last decoded symbol type. + * @returns the type or ::ZBAR_NONE if no new data available + */ +extern zbar_symbol_type_t zbar_decoder_get_type(const zbar_decoder_t *decoder); + +/** retrieve modifier flags for the last decoded symbol. + * @returns a bitmask indicating which characteristics were detected + * during decoding. + * @since 0.11 + */ +extern unsigned int zbar_decoder_get_modifiers(const zbar_decoder_t *decoder); + +/** retrieve last decode direction. + * @returns 1 for forward and -1 for reverse + * @returns 0 if the decode direction is unknown or does not apply + * @since 0.11 + */ +extern int zbar_decoder_get_direction(const zbar_decoder_t *decoder); + +/** setup data handler callback. + * the registered function will be called by the decoder + * just before zbar_decode_width() returns a non-zero value. + * pass a NULL value to disable callbacks. + * @returns the previously registered handler + */ +extern zbar_decoder_handler_t * +zbar_decoder_set_handler(zbar_decoder_t *decoder, + zbar_decoder_handler_t *handler); + +/** associate user specified data value with the decoder. */ +extern void zbar_decoder_set_userdata(zbar_decoder_t *decoder, void *userdata); + +/** return user specified data value associated with the decoder. */ +extern void *zbar_decoder_get_userdata(const zbar_decoder_t *decoder); + +/*@}*/ + +/*------------------------------------------------------------*/ +/** @name Scanner interface + * @anchor c-scanner + * low-level linear intensity sample stream scanner interface. + * identifies "bar" edges and measures width between them. + * optionally passes to bar width decoder + */ +/*@{*/ + +struct zbar_scanner_s; +/** opaque scanner object. */ +typedef struct zbar_scanner_s zbar_scanner_t; + +/** constructor. + * if decoder is non-NULL it will be attached to scanner + * and called automatically at each new edge + * current color is initialized to ::ZBAR_SPACE + * (so an initial BAR->SPACE transition may be discarded) + */ +extern zbar_scanner_t *zbar_scanner_create(zbar_decoder_t *decoder); + +/** destructor. */ +extern void zbar_scanner_destroy(zbar_scanner_t *scanner); + +/** clear all scanner state. + * also resets an associated decoder + */ +extern zbar_symbol_type_t zbar_scanner_reset(zbar_scanner_t *scanner); + +/** mark start of a new scan pass. resets color to ::ZBAR_SPACE. + * also updates an associated decoder. + * @returns any decode results flushed from the pipeline + * @note when not using callback handlers, the return value should + * be checked the same as zbar_scan_y() + * @note call zbar_scanner_flush() at least twice before calling this + * method to ensure no decode results are lost + */ +extern zbar_symbol_type_t zbar_scanner_new_scan(zbar_scanner_t *scanner); + +/** flush scanner processing pipeline. + * forces current scanner position to be a scan boundary. + * call multiple times (max 3) to completely flush decoder. + * @returns any decode/scan results flushed from the pipeline + * @note when not using callback handlers, the return value should + * be checked the same as zbar_scan_y() + * @since 0.9 + */ +extern zbar_symbol_type_t zbar_scanner_flush(zbar_scanner_t *scanner); + +/** process next sample intensity value. + * intensity (y) is in arbitrary relative units. + * @returns result of zbar_decode_width() if a decoder is attached, + * otherwise @returns (::ZBAR_PARTIAL) when new edge is detected + * or 0 (::ZBAR_NONE) if no new edge is detected + */ +extern zbar_symbol_type_t zbar_scan_y(zbar_scanner_t *scanner, int y); + +/** process next sample from RGB (or BGR) triple. */ +static inline zbar_symbol_type_t zbar_scan_rgb24(zbar_scanner_t *scanner, + unsigned char *rgb) +{ + return (zbar_scan_y(scanner, rgb[0] + rgb[1] + rgb[2])); +} + +/** retrieve last scanned width. */ +extern unsigned zbar_scanner_get_width(const zbar_scanner_t *scanner); + +/** retrieve sample position of last edge. + * @since 0.10 + */ +extern unsigned zbar_scanner_get_edge(const zbar_scanner_t *scn, + unsigned offset, int prec); + +/** retrieve last scanned color. */ +extern zbar_color_t zbar_scanner_get_color(const zbar_scanner_t *scanner); + +/*@}*/ + +#ifdef __cplusplus +} +} + +#include "zbar/Decoder.h" +#include "zbar/Exception.h" +#include "zbar/Image.h" +#include "zbar/ImageScanner.h" +#include "zbar/Processor.h" +#include "zbar/Scanner.h" +#include "zbar/Symbol.h" +#include "zbar/Video.h" +#include "zbar/Window.h" +#endif + +#endif diff --git a/include/zlog.h b/include/zlog.h new file mode 100644 index 0000000..9642e08 --- /dev/null +++ b/include/zlog.h @@ -0,0 +1,279 @@ +/* + * This file is part of the zlog Library. + * + * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com> + * + * Licensed under the LGPL v2.1, see the file COPYING in base directory. + */ + +#ifndef __zlog_h +#define __zlog_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdarg.h> /* for va_list */ +#include <stdio.h> /* for size_t */ + +# if defined __GNUC__ +# define ZLOG_CHECK_PRINTF(m,n) __attribute__((format(printf,m,n))) +# else +# define ZLOG_CHECK_PRINTF(m,n) +# endif + +typedef struct zlog_category_s zlog_category_t; + +int zlog_init(const char *config); +int zlog_reload(const char *config); +void zlog_fini(void); + +void zlog_profile(void); + +zlog_category_t *zlog_get_category(const char *cname); +int zlog_level_enabled(zlog_category_t *category, const int level); + +int zlog_put_mdc(const char *key, const char *value); +char *zlog_get_mdc(const char *key); +void zlog_remove_mdc(const char *key); +void zlog_clean_mdc(void); + +int zlog_level_switch(zlog_category_t * category, int level); +int zlog_level_enabled(zlog_category_t * category, int level); + +void zlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, ...) ZLOG_CHECK_PRINTF(8,9); +void vzlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, va_list args); +void hzlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const void *buf, size_t buflen); + +int dzlog_init(const char *confpath, const char *cname); +int dzlog_set_category(const char *cname); + +void dzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, ...) ZLOG_CHECK_PRINTF(7,8); +void vdzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, va_list args); +void hdzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const void *buf, size_t buflen); + +typedef struct zlog_msg_s { + char *buf; + size_t len; + char *path; +} zlog_msg_t; + +typedef int (*zlog_record_fn)(zlog_msg_t *msg); +int zlog_set_record(const char *rname, zlog_record_fn record); + +const char *zlog_version(void); + +/******* useful macros, can be redefined at user's h file **********/ + +typedef enum { + ZLOG_LEVEL_DEBUG = 20, + ZLOG_LEVEL_INFO = 40, + ZLOG_LEVEL_NOTICE = 60, + ZLOG_LEVEL_WARN = 80, + ZLOG_LEVEL_ERROR = 100, + ZLOG_LEVEL_FATAL = 120 +} zlog_level; + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L +# if defined __GNUC__ && __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "<unknown>" +# endif +#endif + +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +/* zlog macros */ +#define zlog_fatal(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, __VA_ARGS__) +#define zlog_error(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, __VA_ARGS__) +#define zlog_warn(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, __VA_ARGS__) +#define zlog_notice(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, __VA_ARGS__) +#define zlog_info(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, __VA_ARGS__) +#define zlog_debug(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, __VA_ARGS__) +/* dzlog macros */ +#define dzlog_fatal(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, __VA_ARGS__) +#define dzlog_error(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, __VA_ARGS__) +#define dzlog_warn(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, __VA_ARGS__) +#define dzlog_notice(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, __VA_ARGS__) +#define dzlog_info(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, __VA_ARGS__) +#define dzlog_debug(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, __VA_ARGS__) +#elif defined __GNUC__ +/* zlog macros */ +#define zlog_fatal(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, ##args) +#define zlog_error(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, ##args) +#define zlog_warn(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, ##args) +#define zlog_notice(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, ##args) +#define zlog_info(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, ##args) +#define zlog_debug(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, ##args) +/* dzlog macros */ +#define dzlog_fatal(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, ##args) +#define dzlog_error(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, ##args) +#define dzlog_warn(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, ##args) +#define dzlog_notice(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, ##args) +#define dzlog_info(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, ##args) +#define dzlog_debug(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, ##args) +#endif + +/* vzlog macros */ +#define vzlog_fatal(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, args) +#define vzlog_error(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, args) +#define vzlog_warn(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, args) +#define vzlog_notice(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, args) +#define vzlog_info(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, args) +#define vzlog_debug(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, args) + +/* hzlog macros */ +#define hzlog_fatal(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, buf, buf_len) +#define hzlog_error(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, buf, buf_len) +#define hzlog_warn(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, buf, buf_len) +#define hzlog_notice(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, buf, buf_len) +#define hzlog_info(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, buf, buf_len) +#define hzlog_debug(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, buf, buf_len) + + +/* vdzlog macros */ +#define vdzlog_fatal(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, args) +#define vdzlog_error(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, args) +#define vdzlog_warn(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, args) +#define vdzlog_notice(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, args) +#define vdzlog_info(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, args) +#define vdzlog_debug(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, args) + +/* hdzlog macros */ +#define hdzlog_fatal(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, buf, buf_len) +#define hdzlog_error(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, buf, buf_len) +#define hdzlog_warn(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, buf, buf_len) +#define hdzlog_notice(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, buf, buf_len) +#define hdzlog_info(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, buf, buf_len) +#define hdzlog_debug(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, buf, buf_len) + +/* enabled macros */ +#define zlog_fatal_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_FATAL) +#define zlog_error_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_ERROR) +#define zlog_warn_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_WARN) +#define zlog_notice_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_NOTICE) +#define zlog_info_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_INFO) +#define zlog_debug_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_DEBUG) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib_data_process.so b/lib_data_process.so new file mode 100644 index 0000000..71dd4a6 Binary files /dev/null and b/lib_data_process.so differ diff --git a/libavcodec.a b/libavcodec.a new file mode 100644 index 0000000..ca97e59 Binary files /dev/null and b/libavcodec.a differ diff --git a/libavdevice.a b/libavdevice.a new file mode 100644 index 0000000..35d09ae Binary files /dev/null and b/libavdevice.a differ diff --git a/libavformat.a b/libavformat.a new file mode 100644 index 0000000..a28b902 Binary files /dev/null and b/libavformat.a differ diff --git a/libavutil.a b/libavutil.a new file mode 100644 index 0000000..678e086 Binary files /dev/null and b/libavutil.a differ diff --git a/libcavalry_mem.so b/libcavalry_mem.so new file mode 100644 index 0000000..f637fa7 Binary files /dev/null and b/libcavalry_mem.so differ diff --git a/libcoldname_.a b/libcoldname_.a new file mode 100644 index 0000000..5fe73bd Binary files /dev/null and b/libcoldname_.a differ diff --git a/libcrypto.a b/libcrypto.a new file mode 100644 index 0000000..d56968e Binary files /dev/null and b/libcrypto.a differ diff --git a/libcrypto.so.1.0.0 b/libcrypto.so.1.0.0 new file mode 100644 index 0000000..8fac68e Binary files /dev/null and b/libcrypto.so.1.0.0 differ diff --git a/libcurl.a b/libcurl.a new file mode 100644 index 0000000..e59a4a3 Binary files /dev/null and b/libcurl.a differ diff --git a/libcurl.so.4.5.0 b/libcurl.so.4.5.0 new file mode 100644 index 0000000..8a4e7d0 Binary files /dev/null and b/libcurl.so.4.5.0 differ diff --git a/libdarknet.a b/libdarknet.a new file mode 100644 index 0000000..6b6f748 Binary files /dev/null and b/libdarknet.a differ diff --git a/libfreetype.so b/libfreetype.so new file mode 100644 index 0000000..09dc9b4 Binary files /dev/null and b/libfreetype.so differ diff --git a/libidn2.so.0.3.5 b/libidn2.so.0.3.5 new file mode 100644 index 0000000..1a35bb4 Binary files /dev/null and b/libidn2.so.0.3.5 differ diff --git a/libjpeg.a b/libjpeg.a new file mode 100644 index 0000000..8e0dc9a Binary files /dev/null and b/libjpeg.a differ diff --git a/libjpeg.so.8.1.2 b/libjpeg.so.8.1.2 new file mode 100644 index 0000000..7d42bbf Binary files /dev/null and b/libjpeg.so.8.1.2 differ diff --git a/libnghttp2.so.14.13.3 b/libnghttp2.so.14.13.3 new file mode 100644 index 0000000..59bdb4f Binary files /dev/null and b/libnghttp2.so.14.13.3 differ diff --git a/libnnctrl.so b/libnnctrl.so new file mode 100644 index 0000000..dca524e Binary files /dev/null and b/libnnctrl.so differ diff --git a/libopencv_core.a b/libopencv_core.a new file mode 100644 index 0000000..59ef880 Binary files /dev/null and b/libopencv_core.a differ diff --git a/libopencv_core.so.3.4.6 b/libopencv_core.so.3.4.6 new file mode 100644 index 0000000..b4b969d Binary files /dev/null and b/libopencv_core.so.3.4.6 differ diff --git a/libopencv_img_hash.a b/libopencv_img_hash.a new file mode 100644 index 0000000..4e55ec2 Binary files /dev/null and b/libopencv_img_hash.a differ diff --git a/libopencv_img_hash.so.3.4 b/libopencv_img_hash.so.3.4 new file mode 100644 index 0000000..bc3d56d Binary files /dev/null and b/libopencv_img_hash.so.3.4 differ diff --git a/libopencv_img_hash.so.3.4.6 b/libopencv_img_hash.so.3.4.6 new file mode 100644 index 0000000..bc3d56d Binary files /dev/null and b/libopencv_img_hash.so.3.4.6 differ diff --git a/libopencv_imgcodecs.a b/libopencv_imgcodecs.a new file mode 100644 index 0000000..12bddab Binary files /dev/null and b/libopencv_imgcodecs.a differ diff --git a/libopencv_imgcodecs.so.3.4.6 b/libopencv_imgcodecs.so.3.4.6 new file mode 100644 index 0000000..58587d8 Binary files /dev/null and b/libopencv_imgcodecs.so.3.4.6 differ diff --git a/libopencv_imgproc.a b/libopencv_imgproc.a new file mode 100644 index 0000000..755ee32 Binary files /dev/null and b/libopencv_imgproc.a differ diff --git a/libopencv_imgproc.so.3.4.6 b/libopencv_imgproc.so.3.4.6 new file mode 100644 index 0000000..10160a4 Binary files /dev/null and b/libopencv_imgproc.so.3.4.6 differ diff --git a/libopencv_ts.a b/libopencv_ts.a new file mode 100644 index 0000000..f308a96 Binary files /dev/null and b/libopencv_ts.a differ diff --git a/libopencv_video.a b/libopencv_video.a new file mode 100644 index 0000000..ed9aaac Binary files /dev/null and b/libopencv_video.a differ diff --git a/libopencv_video.so.3.4 b/libopencv_video.so.3.4 new file mode 100644 index 0000000..a228723 Binary files /dev/null and b/libopencv_video.so.3.4 differ diff --git a/libopencv_video.so.3.4.6 b/libopencv_video.so.3.4.6 new file mode 100644 index 0000000..a228723 Binary files /dev/null and b/libopencv_video.so.3.4.6 differ diff --git a/libpng16.a b/libpng16.a new file mode 100644 index 0000000..944ee47 Binary files /dev/null and b/libpng16.a differ diff --git a/libpng16.so.16.27.0 b/libpng16.so.16.27.0 new file mode 100644 index 0000000..9583cb8 Binary files /dev/null and b/libpng16.so.16.27.0 differ diff --git a/libsmartfb.so b/libsmartfb.so new file mode 100644 index 0000000..6ab8698 Binary files /dev/null and b/libsmartfb.so differ diff --git a/libsqlite3.so b/libsqlite3.so new file mode 100644 index 0000000..fb6ec10 Binary files /dev/null and b/libsqlite3.so differ diff --git a/libssh2.so.1.0.1 b/libssh2.so.1.0.1 new file mode 100644 index 0000000..45e1d9b Binary files /dev/null and b/libssh2.so.1.0.1 differ diff --git a/libssl.a b/libssl.a new file mode 100644 index 0000000..0f21b9b Binary files /dev/null and b/libssl.a differ diff --git a/libssl.so.1.0.0 b/libssl.so.1.0.0 new file mode 100644 index 0000000..8923906 Binary files /dev/null and b/libssl.so.1.0.0 differ diff --git a/libswscale.a b/libswscale.a new file mode 100644 index 0000000..61152db Binary files /dev/null and b/libswscale.a differ diff --git a/libunistring.so.2.1.0 b/libunistring.so.2.1.0 new file mode 100644 index 0000000..9f8d0a0 Binary files /dev/null and b/libunistring.so.2.1.0 differ diff --git a/libvproc.so b/libvproc.so new file mode 100644 index 0000000..49112a8 Binary files /dev/null and b/libvproc.so differ diff --git a/libz.a b/libz.a new file mode 100644 index 0000000..3fbc6a9 Binary files /dev/null and b/libz.a differ diff --git a/libz.so.1.3.1 b/libz.so.1.3.1 new file mode 100644 index 0000000..18e1674 Binary files /dev/null and b/libz.so.1.3.1 differ diff --git a/libzbar.so b/libzbar.so new file mode 100644 index 0000000..53b08d6 Binary files /dev/null and b/libzbar.so differ diff --git a/libzbar.so.0 b/libzbar.so.0 new file mode 100644 index 0000000..53b08d6 Binary files /dev/null and b/libzbar.so.0 differ diff --git a/libzbar.so.0.2.0 b/libzbar.so.0.2.0 new file mode 100644 index 0000000..53b08d6 Binary files /dev/null and b/libzbar.so.0.2.0 differ diff --git a/libzlog.a b/libzlog.a new file mode 100644 index 0000000..a454b1c Binary files /dev/null and b/libzlog.a differ diff --git a/libzlog_linux.a b/libzlog_linux.a new file mode 100644 index 0000000..9e351d1 Binary files /dev/null and b/libzlog_linux.a differ diff --git a/obj/ColorDetector.o b/obj/ColorDetector.o new file mode 100644 index 0000000..10152a5 Binary files /dev/null and b/obj/ColorDetector.o differ diff --git a/obj/activation_layer.o b/obj/activation_layer.o new file mode 100644 index 0000000..5cad8c9 Binary files /dev/null and b/obj/activation_layer.o differ diff --git a/obj/activations.o b/obj/activations.o new file mode 100644 index 0000000..05095f9 Binary files /dev/null and b/obj/activations.o differ diff --git a/obj/alm_queue.o b/obj/alm_queue.o new file mode 100644 index 0000000..a398e4d Binary files /dev/null and b/obj/alm_queue.o differ diff --git a/obj/amba_bbox_utils.o b/obj/amba_bbox_utils.o new file mode 100644 index 0000000..d9faa62 Binary files /dev/null and b/obj/amba_bbox_utils.o differ diff --git a/obj/amba_ssd_detection_out.o b/obj/amba_ssd_detection_out.o new file mode 100644 index 0000000..bdc6785 Binary files /dev/null and b/obj/amba_ssd_detection_out.o differ diff --git a/obj/amba_yolov3_out.o b/obj/amba_yolov3_out.o new file mode 100644 index 0000000..25e9e6f Binary files /dev/null and b/obj/amba_yolov3_out.o differ diff --git a/obj/anpr_rule.o b/obj/anpr_rule.o new file mode 100644 index 0000000..9fbaf86 Binary files /dev/null and b/obj/anpr_rule.o differ diff --git a/obj/art.o b/obj/art.o new file mode 100644 index 0000000..e3ad115 Binary files /dev/null and b/obj/art.o differ diff --git a/obj/avgpool_layer.o b/obj/avgpool_layer.o new file mode 100644 index 0000000..421ef9e Binary files /dev/null and b/obj/avgpool_layer.o differ diff --git a/obj/barcode.o b/obj/barcode.o new file mode 100644 index 0000000..7372916 Binary files /dev/null and b/obj/barcode.o differ diff --git a/obj/base64.o b/obj/base64.o new file mode 100644 index 0000000..e27b50c Binary files /dev/null and b/obj/base64.o differ diff --git a/obj/batchnorm_layer.o b/obj/batchnorm_layer.o new file mode 100644 index 0000000..8b1a94d Binary files /dev/null and b/obj/batchnorm_layer.o differ diff --git a/obj/blas.o b/obj/blas.o new file mode 100644 index 0000000..bed6ba1 Binary files /dev/null and b/obj/blas.o differ diff --git a/obj/block_to_send.o b/obj/block_to_send.o new file mode 100644 index 0000000..40d39c9 Binary files /dev/null and b/obj/block_to_send.o differ diff --git a/obj/box.o b/obj/box.o new file mode 100644 index 0000000..7746321 Binary files /dev/null and b/obj/box.o differ diff --git a/obj/cJSON.o b/obj/cJSON.o new file mode 100644 index 0000000..e853f04 Binary files /dev/null and b/obj/cJSON.o differ diff --git a/obj/cgicmd.o b/obj/cgicmd.o new file mode 100644 index 0000000..d5fc47c Binary files /dev/null and b/obj/cgicmd.o differ diff --git a/obj/col2im.o b/obj/col2im.o new file mode 100644 index 0000000..fad09be Binary files /dev/null and b/obj/col2im.o differ diff --git a/obj/cold_zone.o b/obj/cold_zone.o new file mode 100644 index 0000000..7298be7 Binary files /dev/null and b/obj/cold_zone.o differ diff --git a/obj/connected_layer.o b/obj/connected_layer.o new file mode 100644 index 0000000..b154cfc Binary files /dev/null and b/obj/connected_layer.o differ diff --git a/obj/convolutional_layer.o b/obj/convolutional_layer.o new file mode 100644 index 0000000..a803608 Binary files /dev/null and b/obj/convolutional_layer.o differ diff --git a/obj/cost_layer.o b/obj/cost_layer.o new file mode 100644 index 0000000..bc133cb Binary files /dev/null and b/obj/cost_layer.o differ diff --git a/obj/crnn_layer.o b/obj/crnn_layer.o new file mode 100644 index 0000000..5c2d342 Binary files /dev/null and b/obj/crnn_layer.o differ diff --git a/obj/crop_layer.o b/obj/crop_layer.o new file mode 100644 index 0000000..f33b71f Binary files /dev/null and b/obj/crop_layer.o differ diff --git a/obj/cryptionPlus.o b/obj/cryptionPlus.o new file mode 100644 index 0000000..34c073c Binary files /dev/null and b/obj/cryptionPlus.o differ diff --git a/obj/cuda.o b/obj/cuda.o new file mode 100644 index 0000000..2ca2d0a Binary files /dev/null and b/obj/cuda.o differ diff --git a/obj/cv_point_transform.o b/obj/cv_point_transform.o new file mode 100644 index 0000000..9b803c1 Binary files /dev/null and b/obj/cv_point_transform.o differ diff --git a/obj/darknet.o b/obj/darknet.o new file mode 100644 index 0000000..0ac042d Binary files /dev/null and b/obj/darknet.o differ diff --git a/obj/data.o b/obj/data.o new file mode 100644 index 0000000..9630b33 Binary files /dev/null and b/obj/data.o differ diff --git a/obj/dbscan.o b/obj/dbscan.o new file mode 100644 index 0000000..50cc0ea Binary files /dev/null and b/obj/dbscan.o differ diff --git a/obj/deconvolutional_layer.o b/obj/deconvolutional_layer.o new file mode 100644 index 0000000..a937ff6 Binary files /dev/null and b/obj/deconvolutional_layer.o differ diff --git a/obj/decrypt.o b/obj/decrypt.o new file mode 100644 index 0000000..4dd3269 Binary files /dev/null and b/obj/decrypt.o differ diff --git a/obj/demo.o b/obj/demo.o new file mode 100644 index 0000000..e42a298 Binary files /dev/null and b/obj/demo.o differ diff --git a/obj/detection_layer.o b/obj/detection_layer.o new file mode 100644 index 0000000..aeacb3e Binary files /dev/null and b/obj/detection_layer.o differ diff --git a/obj/detector.o b/obj/detector.o new file mode 100644 index 0000000..a33bdd9 Binary files /dev/null and b/obj/detector.o differ diff --git a/obj/dropout_layer.o b/obj/dropout_layer.o new file mode 100644 index 0000000..5663676 Binary files /dev/null and b/obj/dropout_layer.o differ diff --git a/obj/encrypt.o b/obj/encrypt.o new file mode 100644 index 0000000..3be1594 Binary files /dev/null and b/obj/encrypt.o differ diff --git a/obj/exif.o b/obj/exif.o new file mode 100644 index 0000000..58f5054 Binary files /dev/null and b/obj/exif.o differ diff --git a/obj/fflpr_plate_db.o b/obj/fflpr_plate_db.o new file mode 100644 index 0000000..a475dac Binary files /dev/null and b/obj/fflpr_plate_db.o differ diff --git a/obj/fork_pipe_lib.o b/obj/fork_pipe_lib.o new file mode 100644 index 0000000..9a754c2 Binary files /dev/null and b/obj/fork_pipe_lib.o differ diff --git a/obj/gemm.o b/obj/gemm.o new file mode 100644 index 0000000..8624fe3 Binary files /dev/null and b/obj/gemm.o differ diff --git a/obj/gettest.o b/obj/gettest.o new file mode 100644 index 0000000..eaeae79 Binary files /dev/null and b/obj/gettest.o differ diff --git a/obj/gru_layer.o b/obj/gru_layer.o new file mode 100644 index 0000000..aa8fe3e Binary files /dev/null and b/obj/gru_layer.o differ diff --git a/obj/im2col.o b/obj/im2col.o new file mode 100644 index 0000000..040a31f Binary files /dev/null and b/obj/im2col.o differ diff --git a/obj/image.o b/obj/image.o new file mode 100644 index 0000000..c0a6f10 Binary files /dev/null and b/obj/image.o differ diff --git a/obj/image_opencv.o b/obj/image_opencv.o new file mode 100644 index 0000000..b0ecd28 Binary files /dev/null and b/obj/image_opencv.o differ diff --git a/obj/iniReader.o b/obj/iniReader.o new file mode 100644 index 0000000..4c3a28f Binary files /dev/null and b/obj/iniReader.o differ diff --git a/obj/intLib.o b/obj/intLib.o new file mode 100644 index 0000000..455547e Binary files /dev/null and b/obj/intLib.o differ diff --git a/obj/ir_control.o b/obj/ir_control.o new file mode 100644 index 0000000..9ef1461 Binary files /dev/null and b/obj/ir_control.o differ diff --git a/obj/iseg_layer.o b/obj/iseg_layer.o new file mode 100644 index 0000000..a8f385e Binary files /dev/null and b/obj/iseg_layer.o differ diff --git a/obj/ivs.o b/obj/ivs.o new file mode 100644 index 0000000..ff9b27f Binary files /dev/null and b/obj/ivs.o differ diff --git a/obj/ivs_detection.o b/obj/ivs_detection.o new file mode 100644 index 0000000..9a3a651 Binary files /dev/null and b/obj/ivs_detection.o differ diff --git a/obj/k_means.o b/obj/k_means.o new file mode 100644 index 0000000..00b6e2c Binary files /dev/null and b/obj/k_means.o differ diff --git a/obj/l2norm_layer.o b/obj/l2norm_layer.o new file mode 100644 index 0000000..a6f1bf3 Binary files /dev/null and b/obj/l2norm_layer.o differ diff --git a/obj/layer.o b/obj/layer.o new file mode 100644 index 0000000..01188dc Binary files /dev/null and b/obj/layer.o differ diff --git a/obj/levenshtein.o b/obj/levenshtein.o new file mode 100644 index 0000000..e2fd179 Binary files /dev/null and b/obj/levenshtein.o differ diff --git a/obj/levenshtein_sqlite.o b/obj/levenshtein_sqlite.o new file mode 100644 index 0000000..c914636 Binary files /dev/null and b/obj/levenshtein_sqlite.o differ diff --git a/obj/lib_data_process.o b/obj/lib_data_process.o new file mode 100644 index 0000000..2b86956 Binary files /dev/null and b/obj/lib_data_process.o differ diff --git a/obj/list.o b/obj/list.o new file mode 100644 index 0000000..939cf2b Binary files /dev/null and b/obj/list.o differ diff --git a/obj/local_layer.o b/obj/local_layer.o new file mode 100644 index 0000000..ab5ca78 Binary files /dev/null and b/obj/local_layer.o differ diff --git a/obj/logistic_layer.o b/obj/logistic_layer.o new file mode 100644 index 0000000..ff94ba2 Binary files /dev/null and b/obj/logistic_layer.o differ diff --git a/obj/lstm_layer.o b/obj/lstm_layer.o new file mode 100644 index 0000000..45ef7c8 Binary files /dev/null and b/obj/lstm_layer.o differ diff --git a/obj/matrix.o b/obj/matrix.o new file mode 100644 index 0000000..4d62781 Binary files /dev/null and b/obj/matrix.o differ diff --git a/obj/maxpool_layer.o b/obj/maxpool_layer.o new file mode 100644 index 0000000..265b821 Binary files /dev/null and b/obj/maxpool_layer.o differ diff --git a/obj/md5.o b/obj/md5.o new file mode 100644 index 0000000..d248e35 Binary files /dev/null and b/obj/md5.o differ diff --git a/obj/md5_f.o b/obj/md5_f.o new file mode 100644 index 0000000..5a49134 Binary files /dev/null and b/obj/md5_f.o differ diff --git a/obj/net_curl.o b/obj/net_curl.o new file mode 100644 index 0000000..e2cc50d Binary files /dev/null and b/obj/net_curl.o differ diff --git a/obj/network.o b/obj/network.o new file mode 100644 index 0000000..7b0a32b Binary files /dev/null and b/obj/network.o differ diff --git a/obj/normalization_layer.o b/obj/normalization_layer.o new file mode 100644 index 0000000..619cc9c Binary files /dev/null and b/obj/normalization_layer.o differ diff --git a/obj/nweb.o b/obj/nweb.o new file mode 100644 index 0000000..8595f22 Binary files /dev/null and b/obj/nweb.o differ diff --git a/obj/onvif_data.o b/obj/onvif_data.o new file mode 100644 index 0000000..7463e2b Binary files /dev/null and b/obj/onvif_data.o differ diff --git a/obj/option_list.o b/obj/option_list.o new file mode 100644 index 0000000..83f397e Binary files /dev/null and b/obj/option_list.o differ diff --git a/obj/parking_method.o b/obj/parking_method.o new file mode 100644 index 0000000..9ee37c2 Binary files /dev/null and b/obj/parking_method.o differ diff --git a/obj/parser.o b/obj/parser.o new file mode 100644 index 0000000..fb0c354 Binary files /dev/null and b/obj/parser.o differ diff --git a/obj/pns.o b/obj/pns.o new file mode 100644 index 0000000..8650620 Binary files /dev/null and b/obj/pns.o differ diff --git a/obj/ptz.o b/obj/ptz.o new file mode 100644 index 0000000..cb8c618 Binary files /dev/null and b/obj/ptz.o differ diff --git a/obj/pythonR.o b/obj/pythonR.o new file mode 100644 index 0000000..4b5cc01 Binary files /dev/null and b/obj/pythonR.o differ diff --git a/obj/region_layer.o b/obj/region_layer.o new file mode 100644 index 0000000..b297765 Binary files /dev/null and b/obj/region_layer.o differ diff --git a/obj/reorg_layer.o b/obj/reorg_layer.o new file mode 100644 index 0000000..9b55ff6 Binary files /dev/null and b/obj/reorg_layer.o differ diff --git a/obj/rnn_layer.o b/obj/rnn_layer.o new file mode 100644 index 0000000..26dad07 Binary files /dev/null and b/obj/rnn_layer.o differ diff --git a/obj/route_layer.o b/obj/route_layer.o new file mode 100644 index 0000000..4ad5a73 Binary files /dev/null and b/obj/route_layer.o differ diff --git a/obj/send_osd_data.o b/obj/send_osd_data.o new file mode 100644 index 0000000..10b0d9f Binary files /dev/null and b/obj/send_osd_data.o differ diff --git a/obj/sha1.o b/obj/sha1.o new file mode 100644 index 0000000..dfe5972 Binary files /dev/null and b/obj/sha1.o differ diff --git a/obj/shortcut_layer.o b/obj/shortcut_layer.o new file mode 100644 index 0000000..b670f1d Binary files /dev/null and b/obj/shortcut_layer.o differ diff --git a/obj/signal_test.o b/obj/signal_test.o new file mode 100644 index 0000000..ea18881 Binary files /dev/null and b/obj/signal_test.o differ diff --git a/obj/softmax_layer.o b/obj/softmax_layer.o new file mode 100644 index 0000000..f14b6a8 Binary files /dev/null and b/obj/softmax_layer.o differ diff --git a/obj/sqlite_db.o b/obj/sqlite_db.o new file mode 100644 index 0000000..7feb829 Binary files /dev/null and b/obj/sqlite_db.o differ diff --git a/obj/strptime_c.o b/obj/strptime_c.o new file mode 100644 index 0000000..562049b Binary files /dev/null and b/obj/strptime_c.o differ diff --git a/obj/structures.o b/obj/structures.o new file mode 100644 index 0000000..5f4527a Binary files /dev/null and b/obj/structures.o differ diff --git a/obj/test_nnctrl_live.o b/obj/test_nnctrl_live.o new file mode 100644 index 0000000..8bbd6f4 Binary files /dev/null and b/obj/test_nnctrl_live.o differ diff --git a/obj/test_yuv_rgb.o b/obj/test_yuv_rgb.o new file mode 100644 index 0000000..648a031 Binary files /dev/null and b/obj/test_yuv_rgb.o differ diff --git a/obj/tree.o b/obj/tree.o new file mode 100644 index 0000000..7157162 Binary files /dev/null and b/obj/tree.o differ diff --git a/obj/upsample_layer.o b/obj/upsample_layer.o new file mode 100644 index 0000000..2389b0e Binary files /dev/null and b/obj/upsample_layer.o differ diff --git a/obj/url_encode.o b/obj/url_encode.o new file mode 100644 index 0000000..e420595 Binary files /dev/null and b/obj/url_encode.o differ diff --git a/obj/utility.o b/obj/utility.o new file mode 100644 index 0000000..a169813 Binary files /dev/null and b/obj/utility.o differ diff --git a/obj/utils.o b/obj/utils.o new file mode 100644 index 0000000..8c7fb6a Binary files /dev/null and b/obj/utils.o differ diff --git a/obj/websocket.o b/obj/websocket.o new file mode 100644 index 0000000..ed3cf59 Binary files /dev/null and b/obj/websocket.o differ diff --git a/obj/yolo_layer.o b/obj/yolo_layer.o new file mode 100644 index 0000000..b1f6f2e Binary files /dev/null and b/obj/yolo_layer.o differ diff --git a/obj/yuv_rgb.o b/obj/yuv_rgb.o new file mode 100644 index 0000000..f77e5eb Binary files /dev/null and b/obj/yuv_rgb.o differ diff --git a/osd_server_yolov3 b/osd_server_yolov3 new file mode 100644 index 0000000..cb09907 Binary files /dev/null and b/osd_server_yolov3 differ diff --git a/predictions.jpg b/predictions.jpg new file mode 100644 index 0000000..0ee103d Binary files /dev/null and b/predictions.jpg differ diff --git a/python/darknet.py b/python/darknet.py new file mode 100644 index 0000000..88d84cd --- /dev/null +++ b/python/darknet.py @@ -0,0 +1,156 @@ +from ctypes import * +import math +import random + +def sample(probs): + s = sum(probs) + probs = [a/s for a in probs] + r = random.uniform(0, 1) + for i in range(len(probs)): + r = r - probs[i] + if r <= 0: + return i + return len(probs)-1 + +def c_array(ctype, values): + arr = (ctype*len(values))() + arr[:] = values + return arr + +class BOX(Structure): + _fields_ = [("x", c_float), + ("y", c_float), + ("w", c_float), + ("h", c_float)] + +class DETECTION(Structure): + _fields_ = [("bbox", BOX), + ("classes", c_int), + ("prob", POINTER(c_float)), + ("mask", POINTER(c_float)), + ("objectness", c_float), + ("sort_class", c_int)] + + +class IMAGE(Structure): + _fields_ = [("w", c_int), + ("h", c_int), + ("c", c_int), + ("data", POINTER(c_float))] + +class METADATA(Structure): + _fields_ = [("classes", c_int), + ("names", POINTER(c_char_p))] + + + +#lib = CDLL("/home/pjreddie/documents/darknet/libdarknet.so", RTLD_GLOBAL) +lib = CDLL("libdarknet.so", RTLD_GLOBAL) +lib.network_width.argtypes = [c_void_p] +lib.network_width.restype = c_int +lib.network_height.argtypes = [c_void_p] +lib.network_height.restype = c_int + +predict = lib.network_predict +predict.argtypes = [c_void_p, POINTER(c_float)] +predict.restype = POINTER(c_float) + +set_gpu = lib.cuda_set_device +set_gpu.argtypes = [c_int] + +make_image = lib.make_image +make_image.argtypes = [c_int, c_int, c_int] +make_image.restype = IMAGE + +get_network_boxes = lib.get_network_boxes +get_network_boxes.argtypes = [c_void_p, c_int, c_int, c_float, c_float, POINTER(c_int), c_int, POINTER(c_int)] +get_network_boxes.restype = POINTER(DETECTION) + +make_network_boxes = lib.make_network_boxes +make_network_boxes.argtypes = [c_void_p] +make_network_boxes.restype = POINTER(DETECTION) + +free_detections = lib.free_detections +free_detections.argtypes = [POINTER(DETECTION), c_int] + +free_ptrs = lib.free_ptrs +free_ptrs.argtypes = [POINTER(c_void_p), c_int] + +network_predict = lib.network_predict +network_predict.argtypes = [c_void_p, POINTER(c_float)] + +reset_rnn = lib.reset_rnn +reset_rnn.argtypes = [c_void_p] + +load_net = lib.load_network +load_net.argtypes = [c_char_p, c_char_p, c_int] +load_net.restype = c_void_p + +do_nms_obj = lib.do_nms_obj +do_nms_obj.argtypes = [POINTER(DETECTION), c_int, c_int, c_float] + +do_nms_sort = lib.do_nms_sort +do_nms_sort.argtypes = [POINTER(DETECTION), c_int, c_int, c_float] + +free_image = lib.free_image +free_image.argtypes = [IMAGE] + +letterbox_image = lib.letterbox_image +letterbox_image.argtypes = [IMAGE, c_int, c_int] +letterbox_image.restype = IMAGE + +load_meta = lib.get_metadata +lib.get_metadata.argtypes = [c_char_p] +lib.get_metadata.restype = METADATA + +load_image = lib.load_image_color +load_image.argtypes = [c_char_p, c_int, c_int] +load_image.restype = IMAGE + +rgbgr_image = lib.rgbgr_image +rgbgr_image.argtypes = [IMAGE] + +predict_image = lib.network_predict_image +predict_image.argtypes = [c_void_p, IMAGE] +predict_image.restype = POINTER(c_float) + +def classify(net, meta, im): + out = predict_image(net, im) + res = [] + for i in range(meta.classes): + res.append((meta.names[i], out[i])) + res = sorted(res, key=lambda x: -x[1]) + return res + +def detect(net, meta, image, thresh=.5, hier_thresh=.5, nms=.45): + im = load_image(image, 0, 0) + num = c_int(0) + pnum = pointer(num) + predict_image(net, im) + dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum) + num = pnum[0] + if (nms): do_nms_obj(dets, num, meta.classes, nms); + + res = [] + for j in range(num): + for i in range(meta.classes): + if dets[j].prob[i] > 0: + b = dets[j].bbox + res.append((meta.names[i], dets[j].prob[i], (b.x, b.y, b.w, b.h))) + res = sorted(res, key=lambda x: -x[1]) + free_image(im) + free_detections(dets, num) + return res + +if __name__ == "__main__": + #net = load_net("cfg/densenet201.cfg", "/home/pjreddie/trained/densenet201.weights", 0) + #im = load_image("data/wolf.jpg", 0, 0) + #meta = load_meta("cfg/imagenet1k.data") + #r = classify(net, meta, im) + #print r[:10] + net = load_net("cfg/tiny-yolo.cfg", "tiny-yolo.weights", 0) + meta = load_meta("cfg/coco.data") + r = detect(net, meta, "data/dog.jpg") + print r + + diff --git a/python/proverbot.py b/python/proverbot.py new file mode 100644 index 0000000..095aae8 --- /dev/null +++ b/python/proverbot.py @@ -0,0 +1,37 @@ +from darknet import * + +def predict_tactic(net, s): + prob = 0 + d = c_array(c_float, [0.0]*256) + tac = '' + if not len(s): + s = '\n' + for c in s[:-1]: + d[ord(c)] = 1 + pred = predict(net, d) + d[ord(c)] = 0 + c = s[-1] + while 1: + d[ord(c)] = 1 + pred = predict(net, d) + d[ord(c)] = 0 + pred = [pred[i] for i in range(256)] + ind = sample(pred) + c = chr(ind) + prob += math.log(pred[ind]) + if len(tac) and tac[-1] == '.': + break + tac = tac + c + return (tac, prob) + +def predict_tactics(net, s, n): + tacs = [] + for i in range(n): + reset_rnn(net) + tacs.append(predict_tactic(net, s)) + tacs = sorted(tacs, key=lambda x: -x[1]) + return tacs + +net = load_net("cfg/coq.test.cfg", "/home/pjreddie/backup/coq.backup", 0) +t = predict_tactics(net, "+++++\n", 10) +print t diff --git a/script/jquery-3.4.1.min.js b/script/jquery-3.4.1.min.js new file mode 100644 index 0000000..eb1d01d --- /dev/null +++ b/script/jquery-3.4.1.min.js @@ -0,0 +1,2 @@ +/*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */ +!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],E=C.document,r=Object.getPrototypeOf,s=t.slice,g=t.concat,u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.4.1",k=function(e,t){return new k.fn.init(e,t)},p=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;function d(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0<t&&t-1 in e)}k.fn=k.prototype={jquery:f,constructor:k,length:0,toArray:function(){return s.call(this)},get:function(e){return null==e?s.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=k.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return k.each(this,e)},map:function(n){return this.pushStack(k.map(this,function(e,t){return n.call(e,t,e)}))},slice:function(){return this.pushStack(s.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(0<=n&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:u,sort:t.sort,splice:t.splice},k.extend=k.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||m(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)r=e[t],"__proto__"!==t&&a!==r&&(l&&r&&(k.isPlainObject(r)||(i=Array.isArray(r)))?(n=a[t],o=i&&!Array.isArray(n)?[]:i||k.isPlainObject(n)?n:{},i=!1,a[t]=k.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},k.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==o.call(e))&&(!(t=r(e))||"function"==typeof(n=v.call(t,"constructor")&&t.constructor)&&a.call(n)===l)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e,t){b(e,{nonce:t&&t.nonce})},each:function(e,t){var n,r=0;if(d(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},trim:function(e){return null==e?"":(e+"").replace(p,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(d(Object(e))?k.merge(n,"string"==typeof e?[e]:e):u.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:i.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r=[],i=0,o=e.length,a=!n;i<o;i++)!t(e[i],i)!==a&&r.push(e[i]);return r},map:function(e,t,n){var r,i,o=0,a=[];if(d(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&a.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&a.push(i);return g.apply([],a)},guid:1,support:y}),"function"==typeof Symbol&&(k.fn[Symbol.iterator]=t[Symbol.iterator]),k.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){n["[object "+t+"]"]=t.toLowerCase()});var h=function(n){var e,d,b,o,i,h,f,g,w,u,l,T,C,a,E,v,s,c,y,k="sizzle"+1*new Date,m=n.document,S=0,r=0,p=ue(),x=ue(),N=ue(),A=ue(),D=function(e,t){return e===t&&(l=!0),0},j={}.hasOwnProperty,t=[],q=t.pop,L=t.push,H=t.push,O=t.slice,P=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},R="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",I="(?:\\\\.|[\\w-]|[^\0-\\xa0])+",W="\\["+M+"*("+I+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+I+"))|)"+M+"*\\]",$=":("+I+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+W+")*)|.*)\\)|)",F=new RegExp(M+"+","g"),B=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),_=new RegExp("^"+M+"*,"+M+"*"),z=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp($),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+$),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),ne=function(e,t,n){var r="0x"+t-65536;return r!=r||n?t:r<0?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(m.childNodes),m.childNodes),t[m.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&((e?e.ownerDocument||e:m)!==C&&T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!A[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&U.test(t)){(s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=k),o=(l=h(t)).length;while(o--)l[o]="#"+s+" "+xe(l[o]);c=l.join(","),f=ee.test(t)&&ye(e.parentNode)||e}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){A(t,!0)}finally{s===k&&e.removeAttribute("id")}}}return g(t.replace(B,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[k]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:m;return r!==C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),m!==C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=k,!C.getElementsByName||!C.getElementsByName(k).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){a.appendChild(e).innerHTML="<a id='"+k+"'></a><select id='"+k+"-\r\\' msallowcapture=''><option selected=''></option></select>",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+k+"-]").length||v.push("~="),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+k+"+*").length||v.push(".#.+[+~]")}),ce(function(e){e.innerHTML="<a href='' disabled='disabled'></a><select disabled='disabled'><option/></select>";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",$)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e===C||e.ownerDocument===m&&y(m,e)?-1:t===C||t.ownerDocument===m&&y(m,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e===C?-1:t===C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]===m?-1:s[r]===m?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if((e.ownerDocument||e)!==C&&T(e),d.matchesSelector&&E&&!A[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){A(t,!0)}return 0<se(t,C,null,[e]).length},se.contains=function(e,t){return(e.ownerDocument||e)!==C&&T(e),y(e,t)},se.attr=function(e,t){(e.ownerDocument||e)!==C&&T(e);var n=b.attrHandle[t.toLowerCase()],r=n&&j.call(b.attrHandle,t.toLowerCase())?n(e,t,!E):void 0;return void 0!==r?r:d.attributes||!E?e.getAttribute(t):(r=e.getAttributeNode(t))&&r.specified?r.value:null},se.escape=function(e){return(e+"").replace(re,ie)},se.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},se.uniqueSort=function(e){var t,n=[],r=0,i=0;if(l=!d.detectDuplicates,u=!d.sortStable&&e.slice(0),e.sort(D),l){while(t=e[i++])t===e[i]&&(r=n.push(i));while(r--)e.splice(n[r],1)}return u=null,e},o=se.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else while(t=e[r++])n+=o(t);return n},(b=se.selectors={cacheLength:50,createPseudo:le,match:G,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=p[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&p(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1<t.indexOf(i):"$="===r?i&&t.slice(-i.length)===i:"~="===r?-1<(" "+t.replace(F," ")+" ").indexOf(i):"|="===r&&(t===i||t.slice(0,i.length+1)===i+"-"))}},CHILD:function(h,e,t,g,v){var y="nth"!==h.slice(0,3),m="last"!==h.slice(-4),x="of-type"===e;return 1===g&&0===v?function(e){return!!e.parentNode}:function(e,t,n){var r,i,o,a,s,u,l=y!==m?"nextSibling":"previousSibling",c=e.parentNode,f=x&&e.nodeName.toLowerCase(),p=!n&&!x,d=!1;if(c){if(y){while(l){a=e;while(a=a[l])if(x?a.nodeName.toLowerCase()===f:1===a.nodeType)return!1;u=l="only"===h&&!u&&"nextSibling"}return!0}if(u=[m?c.firstChild:c.lastChild],m&&p){d=(s=(r=(i=(o=(a=c)[k]||(a[k]={}))[a.uniqueID]||(o[a.uniqueID]={}))[h]||[])[0]===S&&r[1])&&r[2],a=s&&c.childNodes[s];while(a=++s&&a&&a[l]||(d=s=0)||u.pop())if(1===a.nodeType&&++d&&a===e){i[h]=[S,s,d];break}}else if(p&&(d=s=(r=(i=(o=(a=e)[k]||(a[k]={}))[a.uniqueID]||(o[a.uniqueID]={}))[h]||[])[0]===S&&r[1]),!1===d)while(a=++s&&a&&a[l]||(d=s=0)||u.pop())if((x?a.nodeName.toLowerCase()===f:1===a.nodeType)&&++d&&(p&&((i=(o=a[k]||(a[k]={}))[a.uniqueID]||(o[a.uniqueID]={}))[h]=[S,d]),a===e))break;return(d-=v)===g||d%g==0&&0<=d/g}}},PSEUDO:function(e,o){var t,a=b.pseudos[e]||b.setFilters[e.toLowerCase()]||se.error("unsupported pseudo: "+e);return a[k]?a(o):1<a.length?(t=[e,e,"",o],b.setFilters.hasOwnProperty(e.toLowerCase())?le(function(e,t){var n,r=a(e,o),i=r.length;while(i--)e[n=P(e,r[i])]=!(t[n]=r[i])}):function(e){return a(e,0,t)}):a}},pseudos:{not:le(function(e){var r=[],i=[],s=f(e.replace(B,"$1"));return s[k]?le(function(e,t,n,r){var i,o=s(e,null,r,[]),a=e.length;while(a--)(i=o[a])&&(e[a]=!(t[a]=i))}):function(e,t,n){return r[0]=e,s(r,null,n,i),r[0]=null,!i.pop()}}),has:le(function(t){return function(e){return 0<se(t,e).length}}),contains:le(function(t){return t=t.replace(te,ne),function(e){return-1<(e.textContent||o(e)).indexOf(t)}}),lang:le(function(n){return V.test(n||"")||se.error("unsupported lang: "+n),n=n.replace(te,ne).toLowerCase(),function(e){var t;do{if(t=E?e.lang:e.getAttribute("xml:lang")||e.getAttribute("lang"))return(t=t.toLowerCase())===n||0===t.indexOf(n+"-")}while((e=e.parentNode)&&1===e.nodeType);return!1}}),target:function(e){var t=n.location&&n.location.hash;return t&&t.slice(1)===e.id},root:function(e){return e===a},focus:function(e){return e===C.activeElement&&(!C.hasFocus||C.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:ge(!1),disabled:ge(!0),checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!b.pseudos.empty(e)},header:function(e){return J.test(e.nodeName)},input:function(e){return Q.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:ve(function(){return[0]}),last:ve(function(e,t){return[t-1]}),eq:ve(function(e,t,n){return[n<0?n+t:n]}),even:ve(function(e,t){for(var n=0;n<t;n+=2)e.push(n);return e}),odd:ve(function(e,t){for(var n=1;n<t;n+=2)e.push(n);return e}),lt:ve(function(e,t,n){for(var r=n<0?n+t:t<n?t:n;0<=--r;)e.push(r);return e}),gt:ve(function(e,t,n){for(var r=n<0?n+t:n;++r<t;)e.push(r);return e})}}).pseudos.nth=b.pseudos.eq,{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})b.pseudos[e]=de(e);for(e in{submit:!0,reset:!0})b.pseudos[e]=he(e);function me(){}function xe(e){for(var t=0,n=e.length,r="";t<n;t++)r+=e[t].value;return r}function be(s,e,t){var u=e.dir,l=e.next,c=l||u,f=t&&"parentNode"===c,p=r++;return e.first?function(e,t,n){while(e=e[u])if(1===e.nodeType||f)return s(e,t,n);return!1}:function(e,t,n){var r,i,o,a=[S,p];if(n){while(e=e[u])if((1===e.nodeType||f)&&s(e,t,n))return!0}else while(e=e[u])if(1===e.nodeType||f)if(i=(o=e[k]||(e[k]={}))[e.uniqueID]||(o[e.uniqueID]={}),l&&l===e.nodeName.toLowerCase())e=e[u]||e;else{if((r=i[c])&&r[0]===S&&r[1]===p)return a[2]=r[2];if((i[c]=a)[2]=s(e,t,n))return!0}return!1}}function we(i){return 1<i.length?function(e,t,n){var r=i.length;while(r--)if(!i[r](e,t,n))return!1;return!0}:i[0]}function Te(e,t,n,r,i){for(var o,a=[],s=0,u=e.length,l=null!=t;s<u;s++)(o=e[s])&&(n&&!n(o,r,i)||(a.push(o),l&&t.push(s)));return a}function Ce(d,h,g,v,y,e){return v&&!v[k]&&(v=Ce(v)),y&&!y[k]&&(y=Ce(y,e)),le(function(e,t,n,r){var i,o,a,s=[],u=[],l=t.length,c=e||function(e,t,n){for(var r=0,i=t.length;r<i;r++)se(e,t[r],n);return n}(h||"*",n.nodeType?[n]:n,[]),f=!d||!e&&h?c:Te(c,s,d,n,r),p=g?y||(e?d:l||v)?[]:t:f;if(g&&g(f,p,n,r),v){i=Te(p,u),v(i,[],n,r),o=i.length;while(o--)(a=i[o])&&(p[u[o]]=!(f[u[o]]=a))}if(e){if(y||d){if(y){i=[],o=p.length;while(o--)(a=p[o])&&i.push(f[o]=a);y(null,p=[],i,r)}o=p.length;while(o--)(a=p[o])&&-1<(i=y?P(e,a):s[o])&&(e[i]=!(t[i]=a))}}else p=Te(p===t?p.splice(l,p.length):p),y?y(null,t,p,r):H.apply(t,p)})}function Ee(e){for(var i,t,n,r=e.length,o=b.relative[e[0].type],a=o||b.relative[" "],s=o?1:0,u=be(function(e){return e===i},a,!0),l=be(function(e){return-1<P(i,e)},a,!0),c=[function(e,t,n){var r=!o&&(n||t!==w)||((i=t).nodeType?u(e,t,n):l(e,t,n));return i=null,r}];s<r;s++)if(t=b.relative[e[s].type])c=[be(we(c),t)];else{if((t=b.filter[e[s].type].apply(null,e[s].matches))[k]){for(n=++s;n<r;n++)if(b.relative[e[n].type])break;return Ce(1<s&&we(c),1<s&&xe(e.slice(0,s-1).concat({value:" "===e[s-2].type?"*":""})).replace(B,"$1"),t,s<n&&Ee(e.slice(s,n)),n<r&&Ee(e=e.slice(n)),n<r&&xe(e))}c.push(t)}return we(c)}return me.prototype=b.filters=b.pseudos,b.setFilters=new me,h=se.tokenize=function(e,t){var n,r,i,o,a,s,u,l=x[e+" "];if(l)return t?0:l.slice(0);a=e,s=[],u=b.preFilter;while(a){for(o in n&&!(r=_.exec(a))||(r&&(a=a.slice(r[0].length)||a),s.push(i=[])),n=!1,(r=z.exec(a))&&(n=r.shift(),i.push({value:n,type:r[0].replace(B," ")}),a=a.slice(n.length)),b.filter)!(r=G[o].exec(a))||u[o]&&!(r=u[o](r))||(n=r.shift(),i.push({value:n,type:o,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?se.error(e):x(e,s).slice(0)},f=se.compile=function(e,t){var n,v,y,m,x,r,i=[],o=[],a=N[e+" "];if(!a){t||(t=h(e)),n=t.length;while(n--)(a=Ee(t[n]))[k]?i.push(a):o.push(a);(a=N(e,(v=o,m=0<(y=i).length,x=0<v.length,r=function(e,t,n,r,i){var o,a,s,u=0,l="0",c=e&&[],f=[],p=w,d=e||x&&b.find.TAG("*",i),h=S+=null==p?1:Math.random()||.1,g=d.length;for(i&&(w=t===C||t||i);l!==g&&null!=(o=d[l]);l++){if(x&&o){a=0,t||o.ownerDocument===C||(T(o),n=!E);while(s=v[a++])if(s(o,t||C,n)){r.push(o);break}i&&(S=h)}m&&((o=!s&&o)&&u--,e&&c.push(o))}if(u+=l,m&&l!==u){a=0;while(s=y[a++])s(c,f,t,n);if(e){if(0<u)while(l--)c[l]||f[l]||(f[l]=q.call(r));f=Te(f)}H.apply(r,f),i&&!e&&0<f.length&&1<u+y.length&&se.uniqueSort(r)}return i&&(S=h,w=p),c},m?le(r):r))).selector=e}return a},g=se.select=function(e,t,n,r){var i,o,a,s,u,l="function"==typeof e&&e,c=!r&&h(e=l.selector||e);if(n=n||[],1===c.length){if(2<(o=c[0]=c[0].slice(0)).length&&"ID"===(a=o[0]).type&&9===t.nodeType&&E&&b.relative[o[1].type]){if(!(t=(b.find.ID(a.matches[0].replace(te,ne),t)||[])[0]))return n;l&&(t=t.parentNode),e=e.slice(o.shift().value.length)}i=G.needsContext.test(e)?0:o.length;while(i--){if(a=o[i],b.relative[s=a.type])break;if((u=b.find[s])&&(r=u(a.matches[0].replace(te,ne),ee.test(o[0].type)&&ye(t.parentNode)||t))){if(o.splice(i,1),!(e=r.length&&xe(o)))return H.apply(n,r),n;break}}}return(l||f(e,c))(r,t,!E,n,!t||ee.test(e)&&ye(t.parentNode)||t),n},d.sortStable=k.split("").sort(D).join("")===k,d.detectDuplicates=!!l,T(),d.sortDetached=ce(function(e){return 1&e.compareDocumentPosition(C.createElement("fieldset"))}),ce(function(e){return e.innerHTML="<a href='#'></a>","#"===e.firstChild.getAttribute("href")})||fe("type|href|height|width",function(e,t,n){if(!n)return e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),d.attributes&&ce(function(e){return e.innerHTML="<input/>",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||fe("value",function(e,t,n){if(!n&&"input"===e.nodeName.toLowerCase())return e.defaultValue}),ce(function(e){return null==e.getAttribute("disabled")})||fe(R,function(e,t,n){var r;if(!n)return!0===e[t]?t.toLowerCase():(r=e.getAttributeNode(t))&&r.specified?r.value:null}),se}(C);k.find=h,k.expr=h.selectors,k.expr[":"]=k.expr.pseudos,k.uniqueSort=k.unique=h.uniqueSort,k.text=h.getText,k.isXMLDoc=h.isXML,k.contains=h.contains,k.escapeSelector=h.escape;var T=function(e,t,n){var r=[],i=void 0!==n;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&k(e).is(n))break;r.push(e)}return r},S=function(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n},N=k.expr.match.needsContext;function A(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}var D=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,n,r){return m(n)?k.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?k.grep(e,function(e){return e===n!==r}):"string"!=typeof n?k.grep(e,function(e){return-1<i.call(n,e)!==r}):k.filter(n,e,r)}k.filter=function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?k.find.matchesSelector(r,e)?[r]:[]:k.find.matches(e,k.grep(t,function(e){return 1===e.nodeType}))},k.fn.extend({find:function(e){var t,n,r=this.length,i=this;if("string"!=typeof e)return this.pushStack(k(e).filter(function(){for(t=0;t<r;t++)if(k.contains(i[t],this))return!0}));for(n=this.pushStack([]),t=0;t<r;t++)k.find(e,i[t],n);return 1<r?k.uniqueSort(n):n},filter:function(e){return this.pushStack(j(this,e||[],!1))},not:function(e){return this.pushStack(j(this,e||[],!0))},is:function(e){return!!j(this,"string"==typeof e&&N.test(e)?k(e):e||[],!1).length}});var q,L=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/;(k.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||q,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:L.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof k?t[0]:t,k.merge(this,k.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),D.test(r[1])&&k.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(k):k.makeArray(e,this)}).prototype=k.fn,q=k(E);var H=/^(?:parents|prev(?:Until|All))/,O={children:!0,contents:!0,next:!0,prev:!0};function P(e,t){while((e=e[t])&&1!==e.nodeType);return e}k.fn.extend({has:function(e){var t=k(e,this),n=t.length;return this.filter(function(){for(var e=0;e<n;e++)if(k.contains(this,t[e]))return!0})},closest:function(e,t){var n,r=0,i=this.length,o=[],a="string"!=typeof e&&k(e);if(!N.test(e))for(;r<i;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(n.nodeType<11&&(a?-1<a.index(n):1===n.nodeType&&k.find.matchesSelector(n,e))){o.push(n);break}return this.pushStack(1<o.length?k.uniqueSort(o):o)},index:function(e){return e?"string"==typeof e?i.call(k(e),this[0]):i.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(k.uniqueSort(k.merge(this.get(),k(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),k.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return T(e,"parentNode")},parentsUntil:function(e,t,n){return T(e,"parentNode",n)},next:function(e){return P(e,"nextSibling")},prev:function(e){return P(e,"previousSibling")},nextAll:function(e){return T(e,"nextSibling")},prevAll:function(e){return T(e,"previousSibling")},nextUntil:function(e,t,n){return T(e,"nextSibling",n)},prevUntil:function(e,t,n){return T(e,"previousSibling",n)},siblings:function(e){return S((e.parentNode||{}).firstChild,e)},children:function(e){return S(e.firstChild)},contents:function(e){return"undefined"!=typeof e.contentDocument?e.contentDocument:(A(e,"template")&&(e=e.content||e),k.merge([],e.childNodes))}},function(r,i){k.fn[r]=function(e,t){var n=k.map(this,i,e);return"Until"!==r.slice(-5)&&(t=e),t&&"string"==typeof t&&(n=k.filter(t,n)),1<this.length&&(O[r]||k.uniqueSort(n),H.test(r)&&n.reverse()),this.pushStack(n)}});var R=/[^\x20\t\r\n\f]+/g;function M(e){return e}function I(e){throw e}function W(e,t,n,r){var i;try{e&&m(i=e.promise)?i.call(e).done(t).fail(n):e&&m(i=e.then)?i.call(e,t,n):t.apply(void 0,[e].slice(r))}catch(e){n.apply(void 0,[e])}}k.Callbacks=function(r){var e,n;r="string"==typeof r?(e=r,n={},k.each(e.match(R)||[],function(e,t){n[t]=!0}),n):k.extend({},r);var i,t,o,a,s=[],u=[],l=-1,c=function(){for(a=a||r.once,o=i=!0;u.length;l=-1){t=u.shift();while(++l<s.length)!1===s[l].apply(t[0],t[1])&&r.stopOnFalse&&(l=s.length,t=!1)}r.memory||(t=!1),i=!1,a&&(s=t?[]:"")},f={add:function(){return s&&(t&&!i&&(l=s.length-1,u.push(t)),function n(e){k.each(e,function(e,t){m(t)?r.unique&&f.has(t)||s.push(t):t&&t.length&&"string"!==w(t)&&n(t)})}(arguments),t&&!i&&c()),this},remove:function(){return k.each(arguments,function(e,t){var n;while(-1<(n=k.inArray(t,s,n)))s.splice(n,1),n<=l&&l--}),this},has:function(e){return e?-1<k.inArray(e,s):0<s.length},empty:function(){return s&&(s=[]),this},disable:function(){return a=u=[],s=t="",this},disabled:function(){return!s},lock:function(){return a=u=[],t||i||(s=t=""),this},locked:function(){return!!a},fireWith:function(e,t){return a||(t=[e,(t=t||[]).slice?t.slice():t],u.push(t),i||c()),this},fire:function(){return f.fireWith(this,arguments),this},fired:function(){return!!o}};return f},k.extend({Deferred:function(e){var o=[["notify","progress",k.Callbacks("memory"),k.Callbacks("memory"),2],["resolve","done",k.Callbacks("once memory"),k.Callbacks("once memory"),0,"resolved"],["reject","fail",k.Callbacks("once memory"),k.Callbacks("once memory"),1,"rejected"]],i="pending",a={state:function(){return i},always:function(){return s.done(arguments).fail(arguments),this},"catch":function(e){return a.then(null,e)},pipe:function(){var i=arguments;return k.Deferred(function(r){k.each(o,function(e,t){var n=m(i[t[4]])&&i[t[4]];s[t[1]](function(){var e=n&&n.apply(this,arguments);e&&m(e.promise)?e.promise().progress(r.notify).done(r.resolve).fail(r.reject):r[t[0]+"With"](this,n?[e]:arguments)})}),i=null}).promise()},then:function(t,n,r){var u=0;function l(i,o,a,s){return function(){var n=this,r=arguments,e=function(){var e,t;if(!(i<u)){if((e=a.apply(n,r))===o.promise())throw new TypeError("Thenable self-resolution");t=e&&("object"==typeof e||"function"==typeof e)&&e.then,m(t)?s?t.call(e,l(u,o,M,s),l(u,o,I,s)):(u++,t.call(e,l(u,o,M,s),l(u,o,I,s),l(u,o,M,o.notifyWith))):(a!==M&&(n=void 0,r=[e]),(s||o.resolveWith)(n,r))}},t=s?e:function(){try{e()}catch(e){k.Deferred.exceptionHook&&k.Deferred.exceptionHook(e,t.stackTrace),u<=i+1&&(a!==I&&(n=void 0,r=[e]),o.rejectWith(n,r))}};i?t():(k.Deferred.getStackHook&&(t.stackTrace=k.Deferred.getStackHook()),C.setTimeout(t))}}return k.Deferred(function(e){o[0][3].add(l(0,e,m(r)?r:M,e.notifyWith)),o[1][3].add(l(0,e,m(t)?t:M)),o[2][3].add(l(0,e,m(n)?n:I))}).promise()},promise:function(e){return null!=e?k.extend(e,a):a}},s={};return k.each(o,function(e,t){var n=t[2],r=t[5];a[t[1]]=n.add,r&&n.add(function(){i=r},o[3-e][2].disable,o[3-e][3].disable,o[0][2].lock,o[0][3].lock),n.add(t[3].fire),s[t[0]]=function(){return s[t[0]+"With"](this===s?void 0:this,arguments),this},s[t[0]+"With"]=n.fireWith}),a.promise(s),e&&e.call(s,s),s},when:function(e){var n=arguments.length,t=n,r=Array(t),i=s.call(arguments),o=k.Deferred(),a=function(t){return function(e){r[t]=this,i[t]=1<arguments.length?s.call(arguments):e,--n||o.resolveWith(r,i)}};if(n<=1&&(W(e,o.done(a(t)).resolve,o.reject,!n),"pending"===o.state()||m(i[t]&&i[t].then)))return o.then();while(t--)W(i[t],a(t),o.reject);return o.promise()}});var $=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;k.Deferred.exceptionHook=function(e,t){C.console&&C.console.warn&&e&&$.test(e.name)&&C.console.warn("jQuery.Deferred exception: "+e.message,e.stack,t)},k.readyException=function(e){C.setTimeout(function(){throw e})};var F=k.Deferred();function B(){E.removeEventListener("DOMContentLoaded",B),C.removeEventListener("load",B),k.ready()}k.fn.ready=function(e){return F.then(e)["catch"](function(e){k.readyException(e)}),this},k.extend({isReady:!1,readyWait:1,ready:function(e){(!0===e?--k.readyWait:k.isReady)||(k.isReady=!0)!==e&&0<--k.readyWait||F.resolveWith(E,[k])}}),k.ready.then=F.then,"complete"===E.readyState||"loading"!==E.readyState&&!E.documentElement.doScroll?C.setTimeout(k.ready):(E.addEventListener("DOMContentLoaded",B),C.addEventListener("load",B));var _=function(e,t,n,r,i,o,a){var s=0,u=e.length,l=null==n;if("object"===w(n))for(s in i=!0,n)_(e,t,s,n[s],!0,o,a);else if(void 0!==r&&(i=!0,m(r)||(a=!0),l&&(a?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(k(e),n)})),t))for(;s<u;s++)t(e[s],n,a?r:r.call(e[s],s,t(e[s],n)));return i?e:l?t.call(e):u?t(e[0],n):o},z=/^-ms-/,U=/-([a-z])/g;function X(e,t){return t.toUpperCase()}function V(e){return e.replace(z,"ms-").replace(U,X)}var G=function(e){return 1===e.nodeType||9===e.nodeType||!+e.nodeType};function Y(){this.expando=k.expando+Y.uid++}Y.uid=1,Y.prototype={cache:function(e){var t=e[this.expando];return t||(t={},G(e)&&(e.nodeType?e[this.expando]=t:Object.defineProperty(e,this.expando,{value:t,configurable:!0}))),t},set:function(e,t,n){var r,i=this.cache(e);if("string"==typeof t)i[V(t)]=n;else for(r in t)i[V(r)]=t[r];return i},get:function(e,t){return void 0===t?this.cache(e):e[this.expando]&&e[this.expando][V(t)]},access:function(e,t,n){return void 0===t||t&&"string"==typeof t&&void 0===n?this.get(e,t):(this.set(e,t,n),void 0!==n?n:t)},remove:function(e,t){var n,r=e[this.expando];if(void 0!==r){if(void 0!==t){n=(t=Array.isArray(t)?t.map(V):(t=V(t))in r?[t]:t.match(R)||[]).length;while(n--)delete r[t[n]]}(void 0===t||k.isEmptyObject(r))&&(e.nodeType?e[this.expando]=void 0:delete e[this.expando])}},hasData:function(e){var t=e[this.expando];return void 0!==t&&!k.isEmptyObject(t)}};var Q=new Y,J=new Y,K=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,Z=/[A-Z]/g;function ee(e,t,n){var r,i;if(void 0===n&&1===e.nodeType)if(r="data-"+t.replace(Z,"-$&").toLowerCase(),"string"==typeof(n=e.getAttribute(r))){try{n="true"===(i=n)||"false"!==i&&("null"===i?null:i===+i+""?+i:K.test(i)?JSON.parse(i):i)}catch(e){}J.set(e,t,n)}else n=void 0;return n}k.extend({hasData:function(e){return J.hasData(e)||Q.hasData(e)},data:function(e,t,n){return J.access(e,t,n)},removeData:function(e,t){J.remove(e,t)},_data:function(e,t,n){return Q.access(e,t,n)},_removeData:function(e,t){Q.remove(e,t)}}),k.fn.extend({data:function(n,e){var t,r,i,o=this[0],a=o&&o.attributes;if(void 0===n){if(this.length&&(i=J.get(o),1===o.nodeType&&!Q.get(o,"hasDataAttrs"))){t=a.length;while(t--)a[t]&&0===(r=a[t].name).indexOf("data-")&&(r=V(r.slice(5)),ee(o,r,i[r]));Q.set(o,"hasDataAttrs",!0)}return i}return"object"==typeof n?this.each(function(){J.set(this,n)}):_(this,function(e){var t;if(o&&void 0===e)return void 0!==(t=J.get(o,n))?t:void 0!==(t=ee(o,n))?t:void 0;this.each(function(){J.set(this,n,e)})},null,e,1<arguments.length,null,!0)},removeData:function(e){return this.each(function(){J.remove(this,e)})}}),k.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=Q.get(e,t),n&&(!r||Array.isArray(n)?r=Q.access(e,t,k.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=k.queue(e,t),r=n.length,i=n.shift(),o=k._queueHooks(e,t);"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,function(){k.dequeue(e,t)},o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return Q.get(e,n)||Q.access(e,n,{empty:k.Callbacks("once memory").add(function(){Q.remove(e,[t+"queue",n])})})}}),k.fn.extend({queue:function(t,n){var e=2;return"string"!=typeof t&&(n=t,t="fx",e--),arguments.length<e?k.queue(this[0],t):void 0===n?this:this.each(function(){var e=k.queue(this,t,n);k._queueHooks(this,t),"fx"===t&&"inprogress"!==e[0]&&k.dequeue(this,t)})},dequeue:function(e){return this.each(function(){k.dequeue(this,e)})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=k.Deferred(),o=this,a=this.length,s=function(){--r||i.resolveWith(o,[o])};"string"!=typeof e&&(t=e,e=void 0),e=e||"fx";while(a--)(n=Q.get(o[a],e+"queueHooks"))&&n.empty&&(r++,n.empty.add(s));return s(),i.promise(t)}});var te=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,ne=new RegExp("^(?:([+-])=|)("+te+")([a-z%]*)$","i"),re=["Top","Right","Bottom","Left"],ie=E.documentElement,oe=function(e){return k.contains(e.ownerDocument,e)},ae={composed:!0};ie.getRootNode&&(oe=function(e){return k.contains(e.ownerDocument,e)||e.getRootNode(ae)===e.ownerDocument});var se=function(e,t){return"none"===(e=t||e).style.display||""===e.style.display&&oe(e)&&"none"===k.css(e,"display")},ue=function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];for(o in i=n.apply(e,r||[]),t)e.style[o]=a[o];return i};function le(e,t,n,r){var i,o,a=20,s=r?function(){return r.cur()}:function(){return k.css(e,t,"")},u=s(),l=n&&n[3]||(k.cssNumber[t]?"":"px"),c=e.nodeType&&(k.cssNumber[t]||"px"!==l&&+u)&&ne.exec(k.css(e,t));if(c&&c[3]!==l){u/=2,l=l||c[3],c=+u||1;while(a--)k.style(e,t,c+l),(1-o)*(1-(o=s()/u||.5))<=0&&(a=0),c/=o;c*=2,k.style(e,t,c+l),n=n||[]}return n&&(c=+c||+u||0,i=n[1]?c+(n[1]+1)*n[2]:+n[2],r&&(r.unit=l,r.start=c,r.end=i)),i}var ce={};function fe(e,t){for(var n,r,i,o,a,s,u,l=[],c=0,f=e.length;c<f;c++)(r=e[c]).style&&(n=r.style.display,t?("none"===n&&(l[c]=Q.get(r,"display")||null,l[c]||(r.style.display="")),""===r.style.display&&se(r)&&(l[c]=(u=a=o=void 0,a=(i=r).ownerDocument,s=i.nodeName,(u=ce[s])||(o=a.body.appendChild(a.createElement(s)),u=k.css(o,"display"),o.parentNode.removeChild(o),"none"===u&&(u="block"),ce[s]=u)))):"none"!==n&&(l[c]="none",Q.set(r,"display",n)));for(c=0;c<f;c++)null!=l[c]&&(e[c].style.display=l[c]);return e}k.fn.extend({show:function(){return fe(this,!0)},hide:function(){return fe(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){se(this)?k(this).show():k(this).hide()})}});var pe=/^(?:checkbox|radio)$/i,de=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i,ge={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?k.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;n<r;n++)Q.set(e[n],"globalEval",!t||Q.get(t[n],"globalEval"))}ge.optgroup=ge.option,ge.tbody=ge.tfoot=ge.colgroup=ge.caption=ge.thead,ge.th=ge.td;var me,xe,be=/<|&#?\w+;/;function we(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d<h;d++)if((o=e[d])||0===o)if("object"===w(o))k.merge(p,o.nodeType?[o]:o);else if(be.test(o)){a=a||f.appendChild(t.createElement("div")),s=(de.exec(o)||["",""])[1].toLowerCase(),u=ge[s]||ge._default,a.innerHTML=u[1]+k.htmlPrefilter(o)+u[2],c=u[0];while(c--)a=a.lastChild;k.merge(p,a.childNodes),(a=f.firstChild).textContent=""}else p.push(t.createTextNode(o));f.textContent="",d=0;while(o=p[d++])if(r&&-1<k.inArray(o,r))i&&i.push(o);else if(l=oe(o),a=ve(f.appendChild(o),"script"),l&&ye(a),n){c=0;while(o=a[c++])he.test(o.type||"")&&n.push(o)}return f}me=E.createDocumentFragment().appendChild(E.createElement("div")),(xe=E.createElement("input")).setAttribute("type","radio"),xe.setAttribute("checked","checked"),xe.setAttribute("name","t"),me.appendChild(xe),y.checkClone=me.cloneNode(!0).cloneNode(!0).lastChild.checked,me.innerHTML="<textarea>x</textarea>",y.noCloneChecked=!!me.cloneNode(!0).lastChild.defaultValue;var Te=/^key/,Ce=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Ee=/^([^.]*)(?:\.(.+)|)/;function ke(){return!0}function Se(){return!1}function Ne(e,t){return e===function(){try{return E.activeElement}catch(e){}}()==("focus"===t)}function Ae(e,t,n,r,i,o){var a,s;if("object"==typeof t){for(s in"string"!=typeof n&&(r=r||n,n=void 0),t)Ae(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=Se;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return k().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=k.guid++)),e.each(function(){k.event.add(this,t,i,r,n)})}function De(e,i,o){o?(Q.set(e,i,!1),k.event.add(e,i,{namespace:!1,handler:function(e){var t,n,r=Q.get(this,i);if(1&e.isTrigger&&this[i]){if(r.length)(k.event.special[i]||{}).delegateType&&e.stopPropagation();else if(r=s.call(arguments),Q.set(this,i,r),t=o(this,i),this[i](),r!==(n=Q.get(this,i))||t?Q.set(this,i,!1):n={},r!==n)return e.stopImmediatePropagation(),e.preventDefault(),n.value}else r.length&&(Q.set(this,i,{value:k.event.trigger(k.extend(r[0],k.Event.prototype),r.slice(1),this)}),e.stopImmediatePropagation())}})):void 0===Q.get(e,i)&&k.event.add(e,i,ke)}k.event={global:{},add:function(t,e,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Q.get(t);if(v){n.handler&&(n=(o=n).handler,i=o.selector),i&&k.find.matchesSelector(ie,i),n.guid||(n.guid=k.guid++),(u=v.events)||(u=v.events={}),(a=v.handle)||(a=v.handle=function(e){return"undefined"!=typeof k&&k.event.triggered!==e.type?k.event.dispatch.apply(t,arguments):void 0}),l=(e=(e||"").match(R)||[""]).length;while(l--)d=g=(s=Ee.exec(e[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=k.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=k.event.special[d]||{},c=k.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&k.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(t,r,h,a)||t.addEventListener&&t.addEventListener(d,a)),f.add&&(f.add.call(t,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),k.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Q.hasData(e)&&Q.get(e);if(v&&(u=v.events)){l=(t=(t||"").match(R)||[""]).length;while(l--)if(d=g=(s=Ee.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d){f=k.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,v.handle)||k.removeEvent(e,d,v.handle),delete u[d])}else for(d in u)k.event.remove(e,d+t[l],n,r,!0);k.isEmptyObject(u)&&Q.remove(e,"handle events")}},dispatch:function(e){var t,n,r,i,o,a,s=k.event.fix(e),u=new Array(arguments.length),l=(Q.get(this,"events")||{})[s.type]||[],c=k.event.special[s.type]||{};for(u[0]=s,t=1;t<arguments.length;t++)u[t]=arguments[t];if(s.delegateTarget=this,!c.preDispatch||!1!==c.preDispatch.call(this,s)){a=k.event.handlers.call(this,s,l),t=0;while((i=a[t++])&&!s.isPropagationStopped()){s.currentTarget=i.elem,n=0;while((o=i.handlers[n++])&&!s.isImmediatePropagationStopped())s.rnamespace&&!1!==o.namespace&&!s.rnamespace.test(o.namespace)||(s.handleObj=o,s.data=o.data,void 0!==(r=((k.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,u))&&!1===(s.result=r)&&(s.preventDefault(),s.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,s),s.result}},handlers:function(e,t){var n,r,i,o,a,s=[],u=t.delegateCount,l=e.target;if(u&&l.nodeType&&!("click"===e.type&&1<=e.button))for(;l!==this;l=l.parentNode||this)if(1===l.nodeType&&("click"!==e.type||!0!==l.disabled)){for(o=[],a={},n=0;n<u;n++)void 0===a[i=(r=t[n]).selector+" "]&&(a[i]=r.needsContext?-1<k(i,this).index(l):k.find(i,this,null,[l]).length),a[i]&&o.push(r);o.length&&s.push({elem:l,handlers:o})}return l=this,u<t.length&&s.push({elem:l,handlers:t.slice(u)}),s},addProp:function(t,e){Object.defineProperty(k.Event.prototype,t,{enumerable:!0,configurable:!0,get:m(e)?function(){if(this.originalEvent)return e(this.originalEvent)}:function(){if(this.originalEvent)return this.originalEvent[t]},set:function(e){Object.defineProperty(this,t,{enumerable:!0,configurable:!0,writable:!0,value:e})}})},fix:function(e){return e[k.expando]?e:new k.Event(e)},special:{load:{noBubble:!0},click:{setup:function(e){var t=this||e;return pe.test(t.type)&&t.click&&A(t,"input")&&De(t,"click",ke),!1},trigger:function(e){var t=this||e;return pe.test(t.type)&&t.click&&A(t,"input")&&De(t,"click"),!0},_default:function(e){var t=e.target;return pe.test(t.type)&&t.click&&A(t,"input")&&Q.get(t,"click")||A(t,"a")}},beforeunload:{postDispatch:function(e){void 0!==e.result&&e.originalEvent&&(e.originalEvent.returnValue=e.result)}}}},k.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n)},k.Event=function(e,t){if(!(this instanceof k.Event))return new k.Event(e,t);e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||void 0===e.defaultPrevented&&!1===e.returnValue?ke:Se,this.target=e.target&&3===e.target.nodeType?e.target.parentNode:e.target,this.currentTarget=e.currentTarget,this.relatedTarget=e.relatedTarget):this.type=e,t&&k.extend(this,t),this.timeStamp=e&&e.timeStamp||Date.now(),this[k.expando]=!0},k.Event.prototype={constructor:k.Event,isDefaultPrevented:Se,isPropagationStopped:Se,isImmediatePropagationStopped:Se,isSimulated:!1,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=ke,e&&!this.isSimulated&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=ke,e&&!this.isSimulated&&e.stopPropagation()},stopImmediatePropagation:function(){var e=this.originalEvent;this.isImmediatePropagationStopped=ke,e&&!this.isSimulated&&e.stopImmediatePropagation(),this.stopPropagation()}},k.each({altKey:!0,bubbles:!0,cancelable:!0,changedTouches:!0,ctrlKey:!0,detail:!0,eventPhase:!0,metaKey:!0,pageX:!0,pageY:!0,shiftKey:!0,view:!0,"char":!0,code:!0,charCode:!0,key:!0,keyCode:!0,button:!0,buttons:!0,clientX:!0,clientY:!0,offsetX:!0,offsetY:!0,pointerId:!0,pointerType:!0,screenX:!0,screenY:!0,targetTouches:!0,toElement:!0,touches:!0,which:function(e){var t=e.button;return null==e.which&&Te.test(e.type)?null!=e.charCode?e.charCode:e.keyCode:!e.which&&void 0!==t&&Ce.test(e.type)?1&t?1:2&t?3:4&t?2:0:e.which}},k.event.addProp),k.each({focus:"focusin",blur:"focusout"},function(e,t){k.event.special[e]={setup:function(){return De(this,e,Ne),!1},trigger:function(){return De(this,e),!0},delegateType:t}}),k.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(e,i){k.event.special[e]={delegateType:i,bindType:i,handle:function(e){var t,n=e.relatedTarget,r=e.handleObj;return n&&(n===this||k.contains(this,n))||(e.type=r.origType,t=r.handler.apply(this,arguments),e.type=i),t}}}),k.fn.extend({on:function(e,t,n,r){return Ae(this,e,t,n,r)},one:function(e,t,n,r){return Ae(this,e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,k(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return!1!==t&&"function"!=typeof t||(n=t,t=void 0),!1===n&&(n=Se),this.each(function(){k.event.remove(this,e,n,t)})}});var je=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,qe=/<script|<style|<link/i,Le=/checked\s*(?:[^=]|=\s*.checked.)/i,He=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;function Oe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&k(e).children("tbody")[0]||e}function Pe(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function Re(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Me(e,t){var n,r,i,o,a,s,u,l;if(1===t.nodeType){if(Q.hasData(e)&&(o=Q.access(e),a=Q.set(t,o),l=o.events))for(i in delete a.handle,a.events={},l)for(n=0,r=l[i].length;n<r;n++)k.event.add(t,i,l[i][n]);J.hasData(e)&&(s=J.access(e),u=k.extend({},s),J.set(t,u))}}function Ie(n,r,i,o){r=g.apply([],r);var e,t,a,s,u,l,c=0,f=n.length,p=f-1,d=r[0],h=m(d);if(h||1<f&&"string"==typeof d&&!y.checkClone&&Le.test(d))return n.each(function(e){var t=n.eq(e);h&&(r[0]=d.call(this,e,t.html())),Ie(t,r,i,o)});if(f&&(t=(e=we(r,n[0].ownerDocument,!1,n,o)).firstChild,1===e.childNodes.length&&(e=t),t||o)){for(s=(a=k.map(ve(e,"script"),Pe)).length;c<f;c++)u=e,c!==p&&(u=k.clone(u,!0,!0),s&&k.merge(a,ve(u,"script"))),i.call(n[c],u,c);if(s)for(l=a[a.length-1].ownerDocument,k.map(a,Re),c=0;c<s;c++)u=a[c],he.test(u.type||"")&&!Q.access(u,"globalEval")&&k.contains(l,u)&&(u.src&&"module"!==(u.type||"").toLowerCase()?k._evalUrl&&!u.noModule&&k._evalUrl(u.src,{nonce:u.nonce||u.getAttribute("nonce")}):b(u.textContent.replace(He,""),u,l))}return n}function We(e,t,n){for(var r,i=t?k.filter(t,e):e,o=0;null!=(r=i[o]);o++)n||1!==r.nodeType||k.cleanData(ve(r)),r.parentNode&&(n&&oe(r)&&ye(ve(r,"script")),r.parentNode.removeChild(r));return e}k.extend({htmlPrefilter:function(e){return e.replace(je,"<$1></$2>")},clone:function(e,t,n){var r,i,o,a,s,u,l,c=e.cloneNode(!0),f=oe(e);if(!(y.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||k.isXMLDoc(e)))for(a=ve(c),r=0,i=(o=ve(e)).length;r<i;r++)s=o[r],u=a[r],void 0,"input"===(l=u.nodeName.toLowerCase())&&pe.test(s.type)?u.checked=s.checked:"input"!==l&&"textarea"!==l||(u.defaultValue=s.defaultValue);if(t)if(n)for(o=o||ve(e),a=a||ve(c),r=0,i=o.length;r<i;r++)Me(o[r],a[r]);else Me(e,c);return 0<(a=ve(c,"script")).length&&ye(a,!f&&ve(e,"script")),c},cleanData:function(e){for(var t,n,r,i=k.event.special,o=0;void 0!==(n=e[o]);o++)if(G(n)){if(t=n[Q.expando]){if(t.events)for(r in t.events)i[r]?k.event.remove(n,r):k.removeEvent(n,r,t.handle);n[Q.expando]=void 0}n[J.expando]&&(n[J.expando]=void 0)}}}),k.fn.extend({detach:function(e){return We(this,e,!0)},remove:function(e){return We(this,e)},text:function(e){return _(this,function(e){return void 0===e?k.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=e)})},null,e,arguments.length)},append:function(){return Ie(this,arguments,function(e){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||Oe(this,e).appendChild(e)})},prepend:function(){return Ie(this,arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Oe(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return Ie(this,arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return Ie(this,arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},empty:function(){for(var e,t=0;null!=(e=this[t]);t++)1===e.nodeType&&(k.cleanData(ve(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null!=e&&e,t=null==t?e:t,this.map(function(){return k.clone(this,e,t)})},html:function(e){return _(this,function(e){var t=this[0]||{},n=0,r=this.length;if(void 0===e&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!qe.test(e)&&!ge[(de.exec(e)||["",""])[1].toLowerCase()]){e=k.htmlPrefilter(e);try{for(;n<r;n++)1===(t=this[n]||{}).nodeType&&(k.cleanData(ve(t,!1)),t.innerHTML=e);t=0}catch(e){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var n=[];return Ie(this,arguments,function(e){var t=this.parentNode;k.inArray(this,n)<0&&(k.cleanData(ve(this)),t&&t.replaceChild(e,this))},n)}}),k.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,a){k.fn[e]=function(e){for(var t,n=[],r=k(e),i=r.length-1,o=0;o<=i;o++)t=o===i?this:this.clone(!0),k(r[o])[a](t),u.apply(n,t.get());return this.pushStack(n)}});var $e=new RegExp("^("+te+")(?!px)[a-z%]+$","i"),Fe=function(e){var t=e.ownerDocument.defaultView;return t&&t.opener||(t=C),t.getComputedStyle(e)},Be=new RegExp(re.join("|"),"i");function _e(e,t,n){var r,i,o,a,s=e.style;return(n=n||Fe(e))&&(""!==(a=n.getPropertyValue(t)||n[t])||oe(e)||(a=k.style(e,t)),!y.pixelBoxStyles()&&$e.test(a)&&Be.test(t)&&(r=s.width,i=s.minWidth,o=s.maxWidth,s.minWidth=s.maxWidth=s.width=a,a=n.width,s.width=r,s.minWidth=i,s.maxWidth=o)),void 0!==a?a+"":a}function ze(e,t){return{get:function(){if(!e())return(this.get=t).apply(this,arguments);delete this.get}}}!function(){function e(){if(u){s.style.cssText="position:absolute;left:-11111px;width:60px;margin-top:1px;padding:0;border:0",u.style.cssText="position:relative;display:block;box-sizing:border-box;overflow:scroll;margin:auto;border:1px;padding:1px;width:60%;top:1%",ie.appendChild(s).appendChild(u);var e=C.getComputedStyle(u);n="1%"!==e.top,a=12===t(e.marginLeft),u.style.right="60%",o=36===t(e.right),r=36===t(e.width),u.style.position="absolute",i=12===t(u.offsetWidth/3),ie.removeChild(s),u=null}}function t(e){return Math.round(parseFloat(e))}var n,r,i,o,a,s=E.createElement("div"),u=E.createElement("div");u.style&&(u.style.backgroundClip="content-box",u.cloneNode(!0).style.backgroundClip="",y.clearCloneStyle="content-box"===u.style.backgroundClip,k.extend(y,{boxSizingReliable:function(){return e(),r},pixelBoxStyles:function(){return e(),o},pixelPosition:function(){return e(),n},reliableMarginLeft:function(){return e(),a},scrollboxSize:function(){return e(),i}}))}();var Ue=["Webkit","Moz","ms"],Xe=E.createElement("div").style,Ve={};function Ge(e){var t=k.cssProps[e]||Ve[e];return t||(e in Xe?e:Ve[e]=function(e){var t=e[0].toUpperCase()+e.slice(1),n=Ue.length;while(n--)if((e=Ue[n]+t)in Xe)return e}(e)||e)}var Ye=/^(none|table(?!-c[ea]).+)/,Qe=/^--/,Je={position:"absolute",visibility:"hidden",display:"block"},Ke={letterSpacing:"0",fontWeight:"400"};function Ze(e,t,n){var r=ne.exec(t);return r?Math.max(0,r[2]-(n||0))+(r[3]||"px"):t}function et(e,t,n,r,i,o){var a="width"===t?1:0,s=0,u=0;if(n===(r?"border":"content"))return 0;for(;a<4;a+=2)"margin"===n&&(u+=k.css(e,n+re[a],!0,i)),r?("content"===n&&(u-=k.css(e,"padding"+re[a],!0,i)),"margin"!==n&&(u-=k.css(e,"border"+re[a]+"Width",!0,i))):(u+=k.css(e,"padding"+re[a],!0,i),"padding"!==n?u+=k.css(e,"border"+re[a]+"Width",!0,i):s+=k.css(e,"border"+re[a]+"Width",!0,i));return!r&&0<=o&&(u+=Math.max(0,Math.ceil(e["offset"+t[0].toUpperCase()+t.slice(1)]-o-u-s-.5))||0),u}function tt(e,t,n){var r=Fe(e),i=(!y.boxSizingReliable()||n)&&"border-box"===k.css(e,"boxSizing",!1,r),o=i,a=_e(e,t,r),s="offset"+t[0].toUpperCase()+t.slice(1);if($e.test(a)){if(!n)return a;a="auto"}return(!y.boxSizingReliable()&&i||"auto"===a||!parseFloat(a)&&"inline"===k.css(e,"display",!1,r))&&e.getClientRects().length&&(i="border-box"===k.css(e,"boxSizing",!1,r),(o=s in e)&&(a=e[s])),(a=parseFloat(a)||0)+et(e,t,n||(i?"border":"content"),o,r,a)+"px"}function nt(e,t,n,r,i){return new nt.prototype.init(e,t,n,r,i)}k.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=_e(e,"opacity");return""===n?"1":n}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,gridArea:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnStart:!0,gridRow:!0,gridRowEnd:!0,gridRowStart:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,a,s=V(t),u=Qe.test(t),l=e.style;if(u||(t=Ge(s)),a=k.cssHooks[t]||k.cssHooks[s],void 0===n)return a&&"get"in a&&void 0!==(i=a.get(e,!1,r))?i:l[t];"string"===(o=typeof n)&&(i=ne.exec(n))&&i[1]&&(n=le(e,t,i),o="number"),null!=n&&n==n&&("number"!==o||u||(n+=i&&i[3]||(k.cssNumber[s]?"":"px")),y.clearCloneStyle||""!==n||0!==t.indexOf("background")||(l[t]="inherit"),a&&"set"in a&&void 0===(n=a.set(e,n,r))||(u?l.setProperty(t,n):l[t]=n))}},css:function(e,t,n,r){var i,o,a,s=V(t);return Qe.test(t)||(t=Ge(s)),(a=k.cssHooks[t]||k.cssHooks[s])&&"get"in a&&(i=a.get(e,!0,n)),void 0===i&&(i=_e(e,t,r)),"normal"===i&&t in Ke&&(i=Ke[t]),""===n||n?(o=parseFloat(i),!0===n||isFinite(o)?o||0:i):i}}),k.each(["height","width"],function(e,u){k.cssHooks[u]={get:function(e,t,n){if(t)return!Ye.test(k.css(e,"display"))||e.getClientRects().length&&e.getBoundingClientRect().width?tt(e,u,n):ue(e,Je,function(){return tt(e,u,n)})},set:function(e,t,n){var r,i=Fe(e),o=!y.scrollboxSize()&&"absolute"===i.position,a=(o||n)&&"border-box"===k.css(e,"boxSizing",!1,i),s=n?et(e,u,n,a,i):0;return a&&o&&(s-=Math.ceil(e["offset"+u[0].toUpperCase()+u.slice(1)]-parseFloat(i[u])-et(e,u,"border",!1,i)-.5)),s&&(r=ne.exec(t))&&"px"!==(r[3]||"px")&&(e.style[u]=t,t=k.css(e,u)),Ze(0,t,s)}}}),k.cssHooks.marginLeft=ze(y.reliableMarginLeft,function(e,t){if(t)return(parseFloat(_e(e,"marginLeft"))||e.getBoundingClientRect().left-ue(e,{marginLeft:0},function(){return e.getBoundingClientRect().left}))+"px"}),k.each({margin:"",padding:"",border:"Width"},function(i,o){k.cssHooks[i+o]={expand:function(e){for(var t=0,n={},r="string"==typeof e?e.split(" "):[e];t<4;t++)n[i+re[t]+o]=r[t]||r[t-2]||r[0];return n}},"margin"!==i&&(k.cssHooks[i+o].set=Ze)}),k.fn.extend({css:function(e,t){return _(this,function(e,t,n){var r,i,o={},a=0;if(Array.isArray(t)){for(r=Fe(e),i=t.length;a<i;a++)o[t[a]]=k.css(e,t[a],!1,r);return o}return void 0!==n?k.style(e,t,n):k.css(e,t)},e,t,1<arguments.length)}}),((k.Tween=nt).prototype={constructor:nt,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||k.easing._default,this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(k.cssNumber[n]?"":"px")},cur:function(){var e=nt.propHooks[this.prop];return e&&e.get?e.get(this):nt.propHooks._default.get(this)},run:function(e){var t,n=nt.propHooks[this.prop];return this.options.duration?this.pos=t=k.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):this.pos=t=e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):nt.propHooks._default.set(this),this}}).init.prototype=nt.prototype,(nt.propHooks={_default:{get:function(e){var t;return 1!==e.elem.nodeType||null!=e.elem[e.prop]&&null==e.elem.style[e.prop]?e.elem[e.prop]:(t=k.css(e.elem,e.prop,""))&&"auto"!==t?t:0},set:function(e){k.fx.step[e.prop]?k.fx.step[e.prop](e):1!==e.elem.nodeType||!k.cssHooks[e.prop]&&null==e.elem.style[Ge(e.prop)]?e.elem[e.prop]=e.now:k.style(e.elem,e.prop,e.now+e.unit)}}}).scrollTop=nt.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},k.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2},_default:"swing"},k.fx=nt.prototype.init,k.fx.step={};var rt,it,ot,at,st=/^(?:toggle|show|hide)$/,ut=/queueHooks$/;function lt(){it&&(!1===E.hidden&&C.requestAnimationFrame?C.requestAnimationFrame(lt):C.setTimeout(lt,k.fx.interval),k.fx.tick())}function ct(){return C.setTimeout(function(){rt=void 0}),rt=Date.now()}function ft(e,t){var n,r=0,i={height:e};for(t=t?1:0;r<4;r+=2-t)i["margin"+(n=re[r])]=i["padding"+n]=e;return t&&(i.opacity=i.width=e),i}function pt(e,t,n){for(var r,i=(dt.tweeners[t]||[]).concat(dt.tweeners["*"]),o=0,a=i.length;o<a;o++)if(r=i[o].call(n,t,e))return r}function dt(o,e,t){var n,a,r=0,i=dt.prefilters.length,s=k.Deferred().always(function(){delete u.elem}),u=function(){if(a)return!1;for(var e=rt||ct(),t=Math.max(0,l.startTime+l.duration-e),n=1-(t/l.duration||0),r=0,i=l.tweens.length;r<i;r++)l.tweens[r].run(n);return s.notifyWith(o,[l,n,t]),n<1&&i?t:(i||s.notifyWith(o,[l,1,0]),s.resolveWith(o,[l]),!1)},l=s.promise({elem:o,props:k.extend({},e),opts:k.extend(!0,{specialEasing:{},easing:k.easing._default},t),originalProperties:e,originalOptions:t,startTime:rt||ct(),duration:t.duration,tweens:[],createTween:function(e,t){var n=k.Tween(o,l.opts,e,t,l.opts.specialEasing[e]||l.opts.easing);return l.tweens.push(n),n},stop:function(e){var t=0,n=e?l.tweens.length:0;if(a)return this;for(a=!0;t<n;t++)l.tweens[t].run(1);return e?(s.notifyWith(o,[l,1,0]),s.resolveWith(o,[l,e])):s.rejectWith(o,[l,e]),this}}),c=l.props;for(!function(e,t){var n,r,i,o,a;for(n in e)if(i=t[r=V(n)],o=e[n],Array.isArray(o)&&(i=o[1],o=e[n]=o[0]),n!==r&&(e[r]=o,delete e[n]),(a=k.cssHooks[r])&&"expand"in a)for(n in o=a.expand(o),delete e[r],o)n in e||(e[n]=o[n],t[n]=i);else t[r]=i}(c,l.opts.specialEasing);r<i;r++)if(n=dt.prefilters[r].call(l,o,c,l.opts))return m(n.stop)&&(k._queueHooks(l.elem,l.opts.queue).stop=n.stop.bind(n)),n;return k.map(c,pt,l),m(l.opts.start)&&l.opts.start.call(o,l),l.progress(l.opts.progress).done(l.opts.done,l.opts.complete).fail(l.opts.fail).always(l.opts.always),k.fx.timer(k.extend(u,{elem:o,anim:l,queue:l.opts.queue})),l}k.Animation=k.extend(dt,{tweeners:{"*":[function(e,t){var n=this.createTween(e,t);return le(n.elem,e,ne.exec(t),n),n}]},tweener:function(e,t){m(e)?(t=e,e=["*"]):e=e.match(R);for(var n,r=0,i=e.length;r<i;r++)n=e[r],dt.tweeners[n]=dt.tweeners[n]||[],dt.tweeners[n].unshift(t)},prefilters:[function(e,t,n){var r,i,o,a,s,u,l,c,f="width"in t||"height"in t,p=this,d={},h=e.style,g=e.nodeType&&se(e),v=Q.get(e,"fxshow");for(r in n.queue||(null==(a=k._queueHooks(e,"fx")).unqueued&&(a.unqueued=0,s=a.empty.fire,a.empty.fire=function(){a.unqueued||s()}),a.unqueued++,p.always(function(){p.always(function(){a.unqueued--,k.queue(e,"fx").length||a.empty.fire()})})),t)if(i=t[r],st.test(i)){if(delete t[r],o=o||"toggle"===i,i===(g?"hide":"show")){if("show"!==i||!v||void 0===v[r])continue;g=!0}d[r]=v&&v[r]||k.style(e,r)}if((u=!k.isEmptyObject(t))||!k.isEmptyObject(d))for(r in f&&1===e.nodeType&&(n.overflow=[h.overflow,h.overflowX,h.overflowY],null==(l=v&&v.display)&&(l=Q.get(e,"display")),"none"===(c=k.css(e,"display"))&&(l?c=l:(fe([e],!0),l=e.style.display||l,c=k.css(e,"display"),fe([e]))),("inline"===c||"inline-block"===c&&null!=l)&&"none"===k.css(e,"float")&&(u||(p.done(function(){h.display=l}),null==l&&(c=h.display,l="none"===c?"":c)),h.display="inline-block")),n.overflow&&(h.overflow="hidden",p.always(function(){h.overflow=n.overflow[0],h.overflowX=n.overflow[1],h.overflowY=n.overflow[2]})),u=!1,d)u||(v?"hidden"in v&&(g=v.hidden):v=Q.access(e,"fxshow",{display:l}),o&&(v.hidden=!g),g&&fe([e],!0),p.done(function(){for(r in g||fe([e]),Q.remove(e,"fxshow"),d)k.style(e,r,d[r])})),u=pt(g?v[r]:0,r,p),r in v||(v[r]=u.start,g&&(u.end=u.start,u.start=0))}],prefilter:function(e,t){t?dt.prefilters.unshift(e):dt.prefilters.push(e)}}),k.speed=function(e,t,n){var r=e&&"object"==typeof e?k.extend({},e):{complete:n||!n&&t||m(e)&&e,duration:e,easing:n&&t||t&&!m(t)&&t};return k.fx.off?r.duration=0:"number"!=typeof r.duration&&(r.duration in k.fx.speeds?r.duration=k.fx.speeds[r.duration]:r.duration=k.fx.speeds._default),null!=r.queue&&!0!==r.queue||(r.queue="fx"),r.old=r.complete,r.complete=function(){m(r.old)&&r.old.call(this),r.queue&&k.dequeue(this,r.queue)},r},k.fn.extend({fadeTo:function(e,t,n,r){return this.filter(se).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(t,e,n,r){var i=k.isEmptyObject(t),o=k.speed(e,n,r),a=function(){var e=dt(this,k.extend({},t),o);(i||Q.get(this,"finish"))&&e.stop(!0)};return a.finish=a,i||!1===o.queue?this.each(a):this.queue(o.queue,a)},stop:function(i,e,o){var a=function(e){var t=e.stop;delete e.stop,t(o)};return"string"!=typeof i&&(o=e,e=i,i=void 0),e&&!1!==i&&this.queue(i||"fx",[]),this.each(function(){var e=!0,t=null!=i&&i+"queueHooks",n=k.timers,r=Q.get(this);if(t)r[t]&&r[t].stop&&a(r[t]);else for(t in r)r[t]&&r[t].stop&&ut.test(t)&&a(r[t]);for(t=n.length;t--;)n[t].elem!==this||null!=i&&n[t].queue!==i||(n[t].anim.stop(o),e=!1,n.splice(t,1));!e&&o||k.dequeue(this,i)})},finish:function(a){return!1!==a&&(a=a||"fx"),this.each(function(){var e,t=Q.get(this),n=t[a+"queue"],r=t[a+"queueHooks"],i=k.timers,o=n?n.length:0;for(t.finish=!0,k.queue(this,a,[]),r&&r.stop&&r.stop.call(this,!0),e=i.length;e--;)i[e].elem===this&&i[e].queue===a&&(i[e].anim.stop(!0),i.splice(e,1));for(e=0;e<o;e++)n[e]&&n[e].finish&&n[e].finish.call(this);delete t.finish})}}),k.each(["toggle","show","hide"],function(e,r){var i=k.fn[r];k.fn[r]=function(e,t,n){return null==e||"boolean"==typeof e?i.apply(this,arguments):this.animate(ft(r,!0),e,t,n)}}),k.each({slideDown:ft("show"),slideUp:ft("hide"),slideToggle:ft("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,r){k.fn[e]=function(e,t,n){return this.animate(r,e,t,n)}}),k.timers=[],k.fx.tick=function(){var e,t=0,n=k.timers;for(rt=Date.now();t<n.length;t++)(e=n[t])()||n[t]!==e||n.splice(t--,1);n.length||k.fx.stop(),rt=void 0},k.fx.timer=function(e){k.timers.push(e),k.fx.start()},k.fx.interval=13,k.fx.start=function(){it||(it=!0,lt())},k.fx.stop=function(){it=null},k.fx.speeds={slow:600,fast:200,_default:400},k.fn.delay=function(r,e){return r=k.fx&&k.fx.speeds[r]||r,e=e||"fx",this.queue(e,function(e,t){var n=C.setTimeout(e,r);t.stop=function(){C.clearTimeout(n)}})},ot=E.createElement("input"),at=E.createElement("select").appendChild(E.createElement("option")),ot.type="checkbox",y.checkOn=""!==ot.value,y.optSelected=at.selected,(ot=E.createElement("input")).value="t",ot.type="radio",y.radioValue="t"===ot.value;var ht,gt=k.expr.attrHandle;k.fn.extend({attr:function(e,t){return _(this,k.attr,e,t,1<arguments.length)},removeAttr:function(e){return this.each(function(){k.removeAttr(this,e)})}}),k.extend({attr:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return"undefined"==typeof e.getAttribute?k.prop(e,t,n):(1===o&&k.isXMLDoc(e)||(i=k.attrHooks[t.toLowerCase()]||(k.expr.match.bool.test(t)?ht:void 0)),void 0!==n?null===n?void k.removeAttr(e,t):i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:(e.setAttribute(t,n+""),n):i&&"get"in i&&null!==(r=i.get(e,t))?r:null==(r=k.find.attr(e,t))?void 0:r)},attrHooks:{type:{set:function(e,t){if(!y.radioValue&&"radio"===t&&A(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},removeAttr:function(e,t){var n,r=0,i=t&&t.match(R);if(i&&1===e.nodeType)while(n=i[r++])e.removeAttribute(n)}}),ht={set:function(e,t,n){return!1===t?k.removeAttr(e,n):e.setAttribute(n,n),n}},k.each(k.expr.match.bool.source.match(/\w+/g),function(e,t){var a=gt[t]||k.find.attr;gt[t]=function(e,t,n){var r,i,o=t.toLowerCase();return n||(i=gt[o],gt[o]=r,r=null!=a(e,t,n)?o:null,gt[o]=i),r}});var vt=/^(?:input|select|textarea|button)$/i,yt=/^(?:a|area)$/i;function mt(e){return(e.match(R)||[]).join(" ")}function xt(e){return e.getAttribute&&e.getAttribute("class")||""}function bt(e){return Array.isArray(e)?e:"string"==typeof e&&e.match(R)||[]}k.fn.extend({prop:function(e,t){return _(this,k.prop,e,t,1<arguments.length)},removeProp:function(e){return this.each(function(){delete this[k.propFix[e]||e]})}}),k.extend({prop:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return 1===o&&k.isXMLDoc(e)||(t=k.propFix[t]||t,i=k.propHooks[t]),void 0!==n?i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){var t=k.find.attr(e,"tabindex");return t?parseInt(t,10):vt.test(e.nodeName)||yt.test(e.nodeName)&&e.href?0:-1}}},propFix:{"for":"htmlFor","class":"className"}}),y.optSelected||(k.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null},set:function(e){var t=e.parentNode;t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex)}}),k.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){k.propFix[this.toLowerCase()]=this}),k.fn.extend({addClass:function(t){var e,n,r,i,o,a,s,u=0;if(m(t))return this.each(function(e){k(this).addClass(t.call(this,e,xt(this)))});if((e=bt(t)).length)while(n=this[u++])if(i=xt(n),r=1===n.nodeType&&" "+mt(i)+" "){a=0;while(o=e[a++])r.indexOf(" "+o+" ")<0&&(r+=o+" ");i!==(s=mt(r))&&n.setAttribute("class",s)}return this},removeClass:function(t){var e,n,r,i,o,a,s,u=0;if(m(t))return this.each(function(e){k(this).removeClass(t.call(this,e,xt(this)))});if(!arguments.length)return this.attr("class","");if((e=bt(t)).length)while(n=this[u++])if(i=xt(n),r=1===n.nodeType&&" "+mt(i)+" "){a=0;while(o=e[a++])while(-1<r.indexOf(" "+o+" "))r=r.replace(" "+o+" "," ");i!==(s=mt(r))&&n.setAttribute("class",s)}return this},toggleClass:function(i,t){var o=typeof i,a="string"===o||Array.isArray(i);return"boolean"==typeof t&&a?t?this.addClass(i):this.removeClass(i):m(i)?this.each(function(e){k(this).toggleClass(i.call(this,e,xt(this),t),t)}):this.each(function(){var e,t,n,r;if(a){t=0,n=k(this),r=bt(i);while(e=r[t++])n.hasClass(e)?n.removeClass(e):n.addClass(e)}else void 0!==i&&"boolean"!==o||((e=xt(this))&&Q.set(this,"__className__",e),this.setAttribute&&this.setAttribute("class",e||!1===i?"":Q.get(this,"__className__")||""))})},hasClass:function(e){var t,n,r=0;t=" "+e+" ";while(n=this[r++])if(1===n.nodeType&&-1<(" "+mt(xt(n))+" ").indexOf(t))return!0;return!1}});var wt=/\r/g;k.fn.extend({val:function(n){var r,e,i,t=this[0];return arguments.length?(i=m(n),this.each(function(e){var t;1===this.nodeType&&(null==(t=i?n.call(this,e,k(this).val()):n)?t="":"number"==typeof t?t+="":Array.isArray(t)&&(t=k.map(t,function(e){return null==e?"":e+""})),(r=k.valHooks[this.type]||k.valHooks[this.nodeName.toLowerCase()])&&"set"in r&&void 0!==r.set(this,t,"value")||(this.value=t))})):t?(r=k.valHooks[t.type]||k.valHooks[t.nodeName.toLowerCase()])&&"get"in r&&void 0!==(e=r.get(t,"value"))?e:"string"==typeof(e=t.value)?e.replace(wt,""):null==e?"":e:void 0}}),k.extend({valHooks:{option:{get:function(e){var t=k.find.attr(e,"value");return null!=t?t:mt(k.text(e))}},select:{get:function(e){var t,n,r,i=e.options,o=e.selectedIndex,a="select-one"===e.type,s=a?null:[],u=a?o+1:i.length;for(r=o<0?u:a?o:0;r<u;r++)if(((n=i[r]).selected||r===o)&&!n.disabled&&(!n.parentNode.disabled||!A(n.parentNode,"optgroup"))){if(t=k(n).val(),a)return t;s.push(t)}return s},set:function(e,t){var n,r,i=e.options,o=k.makeArray(t),a=i.length;while(a--)((r=i[a]).selected=-1<k.inArray(k.valHooks.option.get(r),o))&&(n=!0);return n||(e.selectedIndex=-1),o}}}}),k.each(["radio","checkbox"],function(){k.valHooks[this]={set:function(e,t){if(Array.isArray(t))return e.checked=-1<k.inArray(k(e).val(),t)}},y.checkOn||(k.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})}),y.focusin="onfocusin"in C;var Tt=/^(?:focusinfocus|focusoutblur)$/,Ct=function(e){e.stopPropagation()};k.extend(k.event,{trigger:function(e,t,n,r){var i,o,a,s,u,l,c,f,p=[n||E],d=v.call(e,"type")?e.type:e,h=v.call(e,"namespace")?e.namespace.split("."):[];if(o=f=a=n=n||E,3!==n.nodeType&&8!==n.nodeType&&!Tt.test(d+k.event.triggered)&&(-1<d.indexOf(".")&&(d=(h=d.split(".")).shift(),h.sort()),u=d.indexOf(":")<0&&"on"+d,(e=e[k.expando]?e:new k.Event(d,"object"==typeof e&&e)).isTrigger=r?2:3,e.namespace=h.join("."),e.rnamespace=e.namespace?new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,e.result=void 0,e.target||(e.target=n),t=null==t?[e]:k.makeArray(t,[e]),c=k.event.special[d]||{},r||!c.trigger||!1!==c.trigger.apply(n,t))){if(!r&&!c.noBubble&&!x(n)){for(s=c.delegateType||d,Tt.test(s+d)||(o=o.parentNode);o;o=o.parentNode)p.push(o),a=o;a===(n.ownerDocument||E)&&p.push(a.defaultView||a.parentWindow||C)}i=0;while((o=p[i++])&&!e.isPropagationStopped())f=o,e.type=1<i?s:c.bindType||d,(l=(Q.get(o,"events")||{})[e.type]&&Q.get(o,"handle"))&&l.apply(o,t),(l=u&&o[u])&&l.apply&&G(o)&&(e.result=l.apply(o,t),!1===e.result&&e.preventDefault());return e.type=d,r||e.isDefaultPrevented()||c._default&&!1!==c._default.apply(p.pop(),t)||!G(n)||u&&m(n[d])&&!x(n)&&((a=n[u])&&(n[u]=null),k.event.triggered=d,e.isPropagationStopped()&&f.addEventListener(d,Ct),n[d](),e.isPropagationStopped()&&f.removeEventListener(d,Ct),k.event.triggered=void 0,a&&(n[u]=a)),e.result}},simulate:function(e,t,n){var r=k.extend(new k.Event,n,{type:e,isSimulated:!0});k.event.trigger(r,null,t)}}),k.fn.extend({trigger:function(e,t){return this.each(function(){k.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];if(n)return k.event.trigger(e,t,n,!0)}}),y.focusin||k.each({focus:"focusin",blur:"focusout"},function(n,r){var i=function(e){k.event.simulate(r,e.target,k.event.fix(e))};k.event.special[r]={setup:function(){var e=this.ownerDocument||this,t=Q.access(e,r);t||e.addEventListener(n,i,!0),Q.access(e,r,(t||0)+1)},teardown:function(){var e=this.ownerDocument||this,t=Q.access(e,r)-1;t?Q.access(e,r,t):(e.removeEventListener(n,i,!0),Q.remove(e,r))}}});var Et=C.location,kt=Date.now(),St=/\?/;k.parseXML=function(e){var t;if(!e||"string"!=typeof e)return null;try{t=(new C.DOMParser).parseFromString(e,"text/xml")}catch(e){t=void 0}return t&&!t.getElementsByTagName("parsererror").length||k.error("Invalid XML: "+e),t};var Nt=/\[\]$/,At=/\r?\n/g,Dt=/^(?:submit|button|image|reset|file)$/i,jt=/^(?:input|select|textarea|keygen)/i;function qt(n,e,r,i){var t;if(Array.isArray(e))k.each(e,function(e,t){r||Nt.test(n)?i(n,t):qt(n+"["+("object"==typeof t&&null!=t?e:"")+"]",t,r,i)});else if(r||"object"!==w(e))i(n,e);else for(t in e)qt(n+"["+t+"]",e[t],r,i)}k.param=function(e,t){var n,r=[],i=function(e,t){var n=m(t)?t():t;r[r.length]=encodeURIComponent(e)+"="+encodeURIComponent(null==n?"":n)};if(null==e)return"";if(Array.isArray(e)||e.jquery&&!k.isPlainObject(e))k.each(e,function(){i(this.name,this.value)});else for(n in e)qt(n,e[n],t,i);return r.join("&")},k.fn.extend({serialize:function(){return k.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var e=k.prop(this,"elements");return e?k.makeArray(e):this}).filter(function(){var e=this.type;return this.name&&!k(this).is(":disabled")&&jt.test(this.nodeName)&&!Dt.test(e)&&(this.checked||!pe.test(e))}).map(function(e,t){var n=k(this).val();return null==n?null:Array.isArray(n)?k.map(n,function(e){return{name:t.name,value:e.replace(At,"\r\n")}}):{name:t.name,value:n.replace(At,"\r\n")}}).get()}});var Lt=/%20/g,Ht=/#.*$/,Ot=/([?&])_=[^&]*/,Pt=/^(.*?):[ \t]*([^\r\n]*)$/gm,Rt=/^(?:GET|HEAD)$/,Mt=/^\/\//,It={},Wt={},$t="*/".concat("*"),Ft=E.createElement("a");function Bt(o){return function(e,t){"string"!=typeof e&&(t=e,e="*");var n,r=0,i=e.toLowerCase().match(R)||[];if(m(t))while(n=i[r++])"+"===n[0]?(n=n.slice(1)||"*",(o[n]=o[n]||[]).unshift(t)):(o[n]=o[n]||[]).push(t)}}function _t(t,i,o,a){var s={},u=t===Wt;function l(e){var r;return s[e]=!0,k.each(t[e]||[],function(e,t){var n=t(i,o,a);return"string"!=typeof n||u||s[n]?u?!(r=n):void 0:(i.dataTypes.unshift(n),l(n),!1)}),r}return l(i.dataTypes[0])||!s["*"]&&l("*")}function zt(e,t){var n,r,i=k.ajaxSettings.flatOptions||{};for(n in t)void 0!==t[n]&&((i[n]?e:r||(r={}))[n]=t[n]);return r&&k.extend(!0,e,r),e}Ft.href=Et.href,k.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:Et.href,type:"GET",isLocal:/^(?:about|app|app-storage|.+-extension|file|res|widget):$/.test(Et.protocol),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":$t,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/\bxml\b/,html:/\bhtml/,json:/\bjson\b/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":JSON.parse,"text xml":k.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?zt(zt(e,k.ajaxSettings),t):zt(k.ajaxSettings,e)},ajaxPrefilter:Bt(It),ajaxTransport:Bt(Wt),ajax:function(e,t){"object"==typeof e&&(t=e,e=void 0),t=t||{};var c,f,p,n,d,r,h,g,i,o,v=k.ajaxSetup({},t),y=v.context||v,m=v.context&&(y.nodeType||y.jquery)?k(y):k.event,x=k.Deferred(),b=k.Callbacks("once memory"),w=v.statusCode||{},a={},s={},u="canceled",T={readyState:0,getResponseHeader:function(e){var t;if(h){if(!n){n={};while(t=Pt.exec(p))n[t[1].toLowerCase()+" "]=(n[t[1].toLowerCase()+" "]||[]).concat(t[2])}t=n[e.toLowerCase()+" "]}return null==t?null:t.join(", ")},getAllResponseHeaders:function(){return h?p:null},setRequestHeader:function(e,t){return null==h&&(e=s[e.toLowerCase()]=s[e.toLowerCase()]||e,a[e]=t),this},overrideMimeType:function(e){return null==h&&(v.mimeType=e),this},statusCode:function(e){var t;if(e)if(h)T.always(e[T.status]);else for(t in e)w[t]=[w[t],e[t]];return this},abort:function(e){var t=e||u;return c&&c.abort(t),l(0,t),this}};if(x.promise(T),v.url=((e||v.url||Et.href)+"").replace(Mt,Et.protocol+"//"),v.type=t.method||t.type||v.method||v.type,v.dataTypes=(v.dataType||"*").toLowerCase().match(R)||[""],null==v.crossDomain){r=E.createElement("a");try{r.href=v.url,r.href=r.href,v.crossDomain=Ft.protocol+"//"+Ft.host!=r.protocol+"//"+r.host}catch(e){v.crossDomain=!0}}if(v.data&&v.processData&&"string"!=typeof v.data&&(v.data=k.param(v.data,v.traditional)),_t(It,v,t,T),h)return T;for(i in(g=k.event&&v.global)&&0==k.active++&&k.event.trigger("ajaxStart"),v.type=v.type.toUpperCase(),v.hasContent=!Rt.test(v.type),f=v.url.replace(Ht,""),v.hasContent?v.data&&v.processData&&0===(v.contentType||"").indexOf("application/x-www-form-urlencoded")&&(v.data=v.data.replace(Lt,"+")):(o=v.url.slice(f.length),v.data&&(v.processData||"string"==typeof v.data)&&(f+=(St.test(f)?"&":"?")+v.data,delete v.data),!1===v.cache&&(f=f.replace(Ot,"$1"),o=(St.test(f)?"&":"?")+"_="+kt+++o),v.url=f+o),v.ifModified&&(k.lastModified[f]&&T.setRequestHeader("If-Modified-Since",k.lastModified[f]),k.etag[f]&&T.setRequestHeader("If-None-Match",k.etag[f])),(v.data&&v.hasContent&&!1!==v.contentType||t.contentType)&&T.setRequestHeader("Content-Type",v.contentType),T.setRequestHeader("Accept",v.dataTypes[0]&&v.accepts[v.dataTypes[0]]?v.accepts[v.dataTypes[0]]+("*"!==v.dataTypes[0]?", "+$t+"; q=0.01":""):v.accepts["*"]),v.headers)T.setRequestHeader(i,v.headers[i]);if(v.beforeSend&&(!1===v.beforeSend.call(y,T,v)||h))return T.abort();if(u="abort",b.add(v.complete),T.done(v.success),T.fail(v.error),c=_t(Wt,v,t,T)){if(T.readyState=1,g&&m.trigger("ajaxSend",[T,v]),h)return T;v.async&&0<v.timeout&&(d=C.setTimeout(function(){T.abort("timeout")},v.timeout));try{h=!1,c.send(a,l)}catch(e){if(h)throw e;l(-1,e)}}else l(-1,"No Transport");function l(e,t,n,r){var i,o,a,s,u,l=t;h||(h=!0,d&&C.clearTimeout(d),c=void 0,p=r||"",T.readyState=0<e?4:0,i=200<=e&&e<300||304===e,n&&(s=function(e,t,n){var r,i,o,a,s=e.contents,u=e.dataTypes;while("*"===u[0])u.shift(),void 0===r&&(r=e.mimeType||t.getResponseHeader("Content-Type"));if(r)for(i in s)if(s[i]&&s[i].test(r)){u.unshift(i);break}if(u[0]in n)o=u[0];else{for(i in n){if(!u[0]||e.converters[i+" "+u[0]]){o=i;break}a||(a=i)}o=o||a}if(o)return o!==u[0]&&u.unshift(o),n[o]}(v,T,n)),s=function(e,t,n,r){var i,o,a,s,u,l={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)l[a.toLowerCase()]=e.converters[a];o=c.shift();while(o)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!u&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),u=o,o=c.shift())if("*"===o)o=u;else if("*"!==u&&u!==o){if(!(a=l[u+" "+o]||l["* "+o]))for(i in l)if((s=i.split(" "))[1]===o&&(a=l[u+" "+s[0]]||l["* "+s[0]])){!0===a?a=l[i]:!0!==l[i]&&(o=s[0],c.unshift(s[1]));break}if(!0!==a)if(a&&e["throws"])t=a(t);else try{t=a(t)}catch(e){return{state:"parsererror",error:a?e:"No conversion from "+u+" to "+o}}}return{state:"success",data:t}}(v,s,T,i),i?(v.ifModified&&((u=T.getResponseHeader("Last-Modified"))&&(k.lastModified[f]=u),(u=T.getResponseHeader("etag"))&&(k.etag[f]=u)),204===e||"HEAD"===v.type?l="nocontent":304===e?l="notmodified":(l=s.state,o=s.data,i=!(a=s.error))):(a=l,!e&&l||(l="error",e<0&&(e=0))),T.status=e,T.statusText=(t||l)+"",i?x.resolveWith(y,[o,l,T]):x.rejectWith(y,[T,l,a]),T.statusCode(w),w=void 0,g&&m.trigger(i?"ajaxSuccess":"ajaxError",[T,v,i?o:a]),b.fireWith(y,[T,l]),g&&(m.trigger("ajaxComplete",[T,v]),--k.active||k.event.trigger("ajaxStop")))}return T},getJSON:function(e,t,n){return k.get(e,t,n,"json")},getScript:function(e,t){return k.get(e,void 0,t,"script")}}),k.each(["get","post"],function(e,i){k[i]=function(e,t,n,r){return m(t)&&(r=r||n,n=t,t=void 0),k.ajax(k.extend({url:e,type:i,dataType:r,data:t,success:n},k.isPlainObject(e)&&e))}}),k._evalUrl=function(e,t){return k.ajax({url:e,type:"GET",dataType:"script",cache:!0,async:!1,global:!1,converters:{"text script":function(){}},dataFilter:function(e){k.globalEval(e,t)}})},k.fn.extend({wrapAll:function(e){var t;return this[0]&&(m(e)&&(e=e.call(this[0])),t=k(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this},wrapInner:function(n){return m(n)?this.each(function(e){k(this).wrapInner(n.call(this,e))}):this.each(function(){var e=k(this),t=e.contents();t.length?t.wrapAll(n):e.append(n)})},wrap:function(t){var n=m(t);return this.each(function(e){k(this).wrapAll(n?t.call(this,e):t)})},unwrap:function(e){return this.parent(e).not("body").each(function(){k(this).replaceWith(this.childNodes)}),this}}),k.expr.pseudos.hidden=function(e){return!k.expr.pseudos.visible(e)},k.expr.pseudos.visible=function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)},k.ajaxSettings.xhr=function(){try{return new C.XMLHttpRequest}catch(e){}};var Ut={0:200,1223:204},Xt=k.ajaxSettings.xhr();y.cors=!!Xt&&"withCredentials"in Xt,y.ajax=Xt=!!Xt,k.ajaxTransport(function(i){var o,a;if(y.cors||Xt&&!i.crossDomain)return{send:function(e,t){var n,r=i.xhr();if(r.open(i.type,i.url,i.async,i.username,i.password),i.xhrFields)for(n in i.xhrFields)r[n]=i.xhrFields[n];for(n in i.mimeType&&r.overrideMimeType&&r.overrideMimeType(i.mimeType),i.crossDomain||e["X-Requested-With"]||(e["X-Requested-With"]="XMLHttpRequest"),e)r.setRequestHeader(n,e[n]);o=function(e){return function(){o&&(o=a=r.onload=r.onerror=r.onabort=r.ontimeout=r.onreadystatechange=null,"abort"===e?r.abort():"error"===e?"number"!=typeof r.status?t(0,"error"):t(r.status,r.statusText):t(Ut[r.status]||r.status,r.statusText,"text"!==(r.responseType||"text")||"string"!=typeof r.responseText?{binary:r.response}:{text:r.responseText},r.getAllResponseHeaders()))}},r.onload=o(),a=r.onerror=r.ontimeout=o("error"),void 0!==r.onabort?r.onabort=a:r.onreadystatechange=function(){4===r.readyState&&C.setTimeout(function(){o&&a()})},o=o("abort");try{r.send(i.hasContent&&i.data||null)}catch(e){if(o)throw e}},abort:function(){o&&o()}}}),k.ajaxPrefilter(function(e){e.crossDomain&&(e.contents.script=!1)}),k.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/\b(?:java|ecma)script\b/},converters:{"text script":function(e){return k.globalEval(e),e}}}),k.ajaxPrefilter("script",function(e){void 0===e.cache&&(e.cache=!1),e.crossDomain&&(e.type="GET")}),k.ajaxTransport("script",function(n){var r,i;if(n.crossDomain||n.scriptAttrs)return{send:function(e,t){r=k("<script>").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Vt,Gt=[],Yt=/(=)\?(?=&|$)|\?\?/;k.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Gt.pop()||k.expando+"_"+kt++;return this[e]=!0,e}}),k.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Yt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Yt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Yt,"$1"+r):!1!==e.jsonp&&(e.url+=(St.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||k.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?k(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Gt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Vt=E.implementation.createHTMLDocument("").body).innerHTML="<form></form><form></form>",2===Vt.childNodes.length),k.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=D.exec(e))?[t.createElement(i[1])]:(i=we([e],t,o),o&&o.length&&k(o).remove(),k.merge([],i.childNodes)));var r,i,o},k.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1<s&&(r=mt(e.slice(s)),e=e.slice(0,s)),m(t)?(n=t,t=void 0):t&&"object"==typeof t&&(i="POST"),0<a.length&&k.ajax({url:e,type:i||"GET",dataType:"html",data:t}).done(function(e){o=arguments,a.html(r?k("<div>").append(k.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},k.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){k.fn[t]=function(e){return this.on(t,e)}}),k.expr.pseudos.animated=function(t){return k.grep(k.timers,function(e){return t===e.elem}).length},k.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=k.css(e,"position"),c=k(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=k.css(e,"top"),u=k.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,k.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):c.css(f)}},k.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){k.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===k.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===k.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=k(e).offset()).top+=k.css(e,"borderTopWidth",!0),i.left+=k.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-k.css(r,"marginTop",!0),left:t.left-i.left-k.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===k.css(e,"position"))e=e.offsetParent;return e||ie})}}),k.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;k.fn[t]=function(e){return _(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),k.each(["top","left"],function(e,n){k.cssHooks[n]=ze(y.pixelPosition,function(e,t){if(t)return t=_e(e,n),$e.test(t)?k(e).position()[n]+"px":t})}),k.each({Height:"height",Width:"width"},function(a,s){k.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){k.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return _(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?k.css(e,t,i):k.style(e,t,n,i)},s,n?e:void 0,n)}})}),k.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){k.fn[n]=function(e,t){return 0<arguments.length?this.on(n,null,e,t):this.trigger(n)}}),k.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),k.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}}),k.proxy=function(e,t){var n,r,i;if("string"==typeof t&&(n=e[t],t=e,e=n),m(e))return r=s.call(arguments,2),(i=function(){return e.apply(t||this,r.concat(s.call(arguments)))}).guid=e.guid=e.guid||k.guid++,i},k.holdReady=function(e){e?k.readyWait++:k.ready(!0)},k.isArray=Array.isArray,k.parseJSON=JSON.parse,k.nodeName=A,k.isFunction=m,k.isWindow=x,k.camelCase=V,k.type=w,k.now=Date.now,k.isNumeric=function(e){var t=k.type(e);return("number"===t||"string"===t)&&!isNaN(e-parseFloat(e))},"function"==typeof define&&define.amd&&define("jquery",[],function(){return k});var Qt=C.jQuery,Jt=C.$;return k.noConflict=function(e){return C.$===k&&(C.$=Jt),e&&C.jQuery===k&&(C.jQuery=Qt),k},e||(C.jQuery=C.$=k),k}); \ No newline at end of file diff --git a/script/js_3.5.1.js b/script/js_3.5.1.js new file mode 100644 index 0000000..015256d --- /dev/null +++ b/script/js_3.5.1.js @@ -0,0 +1,2 @@ +/*! jQuery v3.5.1 | (c) JS Foundation and other contributors | jquery.org/license */ +!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},E=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.5.1",S=function(e,t){return new S.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0<t&&t-1 in e)}S.fn=S.prototype={jquery:f,constructor:S,length:0,toArray:function(){return s.call(this)},get:function(e){return null==e?s.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=S.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return S.each(this,e)},map:function(n){return this.pushStack(S.map(this,function(e,t){return n.call(e,t,e)}))},slice:function(){return this.pushStack(s.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},even:function(){return this.pushStack(S.grep(this,function(e,t){return(t+1)%2}))},odd:function(){return this.pushStack(S.grep(this,function(e,t){return t%2}))},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(0<=n&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:u,sort:t.sort,splice:t.splice},S.extend=S.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||m(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)r=e[t],"__proto__"!==t&&a!==r&&(l&&r&&(S.isPlainObject(r)||(i=Array.isArray(r)))?(n=a[t],o=i&&!Array.isArray(n)?[]:i||S.isPlainObject(n)?n:{},i=!1,a[t]=S.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},S.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==o.call(e))&&(!(t=r(e))||"function"==typeof(n=v.call(t,"constructor")&&t.constructor)&&a.call(n)===l)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e,t,n){b(e,{nonce:t&&t.nonce},n)},each:function(e,t){var n,r=0;if(p(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},makeArray:function(e,t){var n=t||[];return null!=e&&(p(Object(e))?S.merge(n,"string"==typeof e?[e]:e):u.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:i.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r=[],i=0,o=e.length,a=!n;i<o;i++)!t(e[i],i)!==a&&r.push(e[i]);return r},map:function(e,t,n){var r,i,o=0,a=[];if(p(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&a.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&a.push(i);return g(a)},guid:1,support:y}),"function"==typeof Symbol&&(S.fn[Symbol.iterator]=t[Symbol.iterator]),S.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){n["[object "+t+"]"]=t.toLowerCase()});var d=function(n){var e,d,b,o,i,h,f,g,w,u,l,T,C,a,E,v,s,c,y,S="sizzle"+1*new Date,p=n.document,k=0,r=0,m=ue(),x=ue(),A=ue(),N=ue(),D=function(e,t){return e===t&&(l=!0),0},j={}.hasOwnProperty,t=[],q=t.pop,L=t.push,H=t.push,O=t.slice,P=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},R="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",I="(?:\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\[^\\r\\n\\f]|[\\w-]|[^\0-\\x7f])+",W="\\["+M+"*("+I+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+I+"))|)"+M+"*\\]",F=":("+I+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+W+")*)|.*)\\)|)",B=new RegExp(M+"+","g"),$=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),_=new RegExp("^"+M+"*,"+M+"*"),z=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp(F),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+F),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\([^\\r\\n\\f])","g"),ne=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(p.childNodes),p.childNodes),t[p.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!N[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&(U.test(t)||z.test(t))){(f=ee.test(t)&&ye(e.parentNode)||e)===e&&d.scope||((s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=S)),o=(l=h(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+xe(l[o]);c=l.join(",")}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){N(t,!0)}finally{s===S&&e.removeAttribute("id")}}}return g(t.replace($,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[S]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:p;return r!=C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),p!=C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.scope=ce(function(e){return a.appendChild(e).appendChild(C.createElement("div")),"undefined"!=typeof e.querySelectorAll&&!e.querySelectorAll(":scope fieldset div").length}),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=S,!C.getElementsByName||!C.getElementsByName(S).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){var t;a.appendChild(e).innerHTML="<a id='"+S+"'></a><select id='"+S+"-\r\\' msallowcapture=''><option selected=''></option></select>",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+S+"-]").length||v.push("~="),(t=C.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||v.push("\\["+M+"*name"+M+"*="+M+"*(?:''|\"\")"),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+S+"+*").length||v.push(".#.+[+~]"),e.querySelectorAll("\\\f"),v.push("[\\r\\n\\f]")}),ce(function(e){e.innerHTML="<a href='' disabled='disabled'></a><select disabled='disabled'><option/></select>";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",F)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e==C||e.ownerDocument==p&&y(p,e)?-1:t==C||t.ownerDocument==p&&y(p,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e==C?-1:t==C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]==p?-1:s[r]==p?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if(T(e),d.matchesSelector&&E&&!N[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){N(t,!0)}return 0<se(t,C,null,[e]).length},se.contains=function(e,t){return(e.ownerDocument||e)!=C&&T(e),y(e,t)},se.attr=function(e,t){(e.ownerDocument||e)!=C&&T(e);var n=b.attrHandle[t.toLowerCase()],r=n&&j.call(b.attrHandle,t.toLowerCase())?n(e,t,!E):void 0;return void 0!==r?r:d.attributes||!E?e.getAttribute(t):(r=e.getAttributeNode(t))&&r.specified?r.value:null},se.escape=function(e){return(e+"").replace(re,ie)},se.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},se.uniqueSort=function(e){var t,n=[],r=0,i=0;if(l=!d.detectDuplicates,u=!d.sortStable&&e.slice(0),e.sort(D),l){while(t=e[i++])t===e[i]&&(r=n.push(i));while(r--)e.splice(n[r],1)}return u=null,e},o=se.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else while(t=e[r++])n+=o(t);return n},(b=se.selectors={cacheLength:50,createPseudo:le,match:G,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=m[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&m(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1<t.indexOf(i):"$="===r?i&&t.slice(-i.length)===i:"~="===r?-1<(" "+t.replace(B," ")+" ").indexOf(i):"|="===r&&(t===i||t.slice(0,i.length+1)===i+"-"))}},CHILD:function(h,e,t,g,v){var y="nth"!==h.slice(0,3),m="last"!==h.slice(-4),x="of-type"===e;return 1===g&&0===v?function(e){return!!e.parentNode}:function(e,t,n){var r,i,o,a,s,u,l=y!==m?"nextSibling":"previousSibling",c=e.parentNode,f=x&&e.nodeName.toLowerCase(),p=!n&&!x,d=!1;if(c){if(y){while(l){a=e;while(a=a[l])if(x?a.nodeName.toLowerCase()===f:1===a.nodeType)return!1;u=l="only"===h&&!u&&"nextSibling"}return!0}if(u=[m?c.firstChild:c.lastChild],m&&p){d=(s=(r=(i=(o=(a=c)[S]||(a[S]={}))[a.uniqueID]||(o[a.uniqueID]={}))[h]||[])[0]===k&&r[1])&&r[2],a=s&&c.childNodes[s];while(a=++s&&a&&a[l]||(d=s=0)||u.pop())if(1===a.nodeType&&++d&&a===e){i[h]=[k,s,d];break}}else if(p&&(d=s=(r=(i=(o=(a=e)[S]||(a[S]={}))[a.uniqueID]||(o[a.uniqueID]={}))[h]||[])[0]===k&&r[1]),!1===d)while(a=++s&&a&&a[l]||(d=s=0)||u.pop())if((x?a.nodeName.toLowerCase()===f:1===a.nodeType)&&++d&&(p&&((i=(o=a[S]||(a[S]={}))[a.uniqueID]||(o[a.uniqueID]={}))[h]=[k,d]),a===e))break;return(d-=v)===g||d%g==0&&0<=d/g}}},PSEUDO:function(e,o){var t,a=b.pseudos[e]||b.setFilters[e.toLowerCase()]||se.error("unsupported pseudo: "+e);return a[S]?a(o):1<a.length?(t=[e,e,"",o],b.setFilters.hasOwnProperty(e.toLowerCase())?le(function(e,t){var n,r=a(e,o),i=r.length;while(i--)e[n=P(e,r[i])]=!(t[n]=r[i])}):function(e){return a(e,0,t)}):a}},pseudos:{not:le(function(e){var r=[],i=[],s=f(e.replace($,"$1"));return s[S]?le(function(e,t,n,r){var i,o=s(e,null,r,[]),a=e.length;while(a--)(i=o[a])&&(e[a]=!(t[a]=i))}):function(e,t,n){return r[0]=e,s(r,null,n,i),r[0]=null,!i.pop()}}),has:le(function(t){return function(e){return 0<se(t,e).length}}),contains:le(function(t){return t=t.replace(te,ne),function(e){return-1<(e.textContent||o(e)).indexOf(t)}}),lang:le(function(n){return V.test(n||"")||se.error("unsupported lang: "+n),n=n.replace(te,ne).toLowerCase(),function(e){var t;do{if(t=E?e.lang:e.getAttribute("xml:lang")||e.getAttribute("lang"))return(t=t.toLowerCase())===n||0===t.indexOf(n+"-")}while((e=e.parentNode)&&1===e.nodeType);return!1}}),target:function(e){var t=n.location&&n.location.hash;return t&&t.slice(1)===e.id},root:function(e){return e===a},focus:function(e){return e===C.activeElement&&(!C.hasFocus||C.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:ge(!1),disabled:ge(!0),checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!b.pseudos.empty(e)},header:function(e){return J.test(e.nodeName)},input:function(e){return Q.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:ve(function(){return[0]}),last:ve(function(e,t){return[t-1]}),eq:ve(function(e,t,n){return[n<0?n+t:n]}),even:ve(function(e,t){for(var n=0;n<t;n+=2)e.push(n);return e}),odd:ve(function(e,t){for(var n=1;n<t;n+=2)e.push(n);return e}),lt:ve(function(e,t,n){for(var r=n<0?n+t:t<n?t:n;0<=--r;)e.push(r);return e}),gt:ve(function(e,t,n){for(var r=n<0?n+t:n;++r<t;)e.push(r);return e})}}).pseudos.nth=b.pseudos.eq,{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})b.pseudos[e]=de(e);for(e in{submit:!0,reset:!0})b.pseudos[e]=he(e);function me(){}function xe(e){for(var t=0,n=e.length,r="";t<n;t++)r+=e[t].value;return r}function be(s,e,t){var u=e.dir,l=e.next,c=l||u,f=t&&"parentNode"===c,p=r++;return e.first?function(e,t,n){while(e=e[u])if(1===e.nodeType||f)return s(e,t,n);return!1}:function(e,t,n){var r,i,o,a=[k,p];if(n){while(e=e[u])if((1===e.nodeType||f)&&s(e,t,n))return!0}else while(e=e[u])if(1===e.nodeType||f)if(i=(o=e[S]||(e[S]={}))[e.uniqueID]||(o[e.uniqueID]={}),l&&l===e.nodeName.toLowerCase())e=e[u]||e;else{if((r=i[c])&&r[0]===k&&r[1]===p)return a[2]=r[2];if((i[c]=a)[2]=s(e,t,n))return!0}return!1}}function we(i){return 1<i.length?function(e,t,n){var r=i.length;while(r--)if(!i[r](e,t,n))return!1;return!0}:i[0]}function Te(e,t,n,r,i){for(var o,a=[],s=0,u=e.length,l=null!=t;s<u;s++)(o=e[s])&&(n&&!n(o,r,i)||(a.push(o),l&&t.push(s)));return a}function Ce(d,h,g,v,y,e){return v&&!v[S]&&(v=Ce(v)),y&&!y[S]&&(y=Ce(y,e)),le(function(e,t,n,r){var i,o,a,s=[],u=[],l=t.length,c=e||function(e,t,n){for(var r=0,i=t.length;r<i;r++)se(e,t[r],n);return n}(h||"*",n.nodeType?[n]:n,[]),f=!d||!e&&h?c:Te(c,s,d,n,r),p=g?y||(e?d:l||v)?[]:t:f;if(g&&g(f,p,n,r),v){i=Te(p,u),v(i,[],n,r),o=i.length;while(o--)(a=i[o])&&(p[u[o]]=!(f[u[o]]=a))}if(e){if(y||d){if(y){i=[],o=p.length;while(o--)(a=p[o])&&i.push(f[o]=a);y(null,p=[],i,r)}o=p.length;while(o--)(a=p[o])&&-1<(i=y?P(e,a):s[o])&&(e[i]=!(t[i]=a))}}else p=Te(p===t?p.splice(l,p.length):p),y?y(null,t,p,r):H.apply(t,p)})}function Ee(e){for(var i,t,n,r=e.length,o=b.relative[e[0].type],a=o||b.relative[" "],s=o?1:0,u=be(function(e){return e===i},a,!0),l=be(function(e){return-1<P(i,e)},a,!0),c=[function(e,t,n){var r=!o&&(n||t!==w)||((i=t).nodeType?u(e,t,n):l(e,t,n));return i=null,r}];s<r;s++)if(t=b.relative[e[s].type])c=[be(we(c),t)];else{if((t=b.filter[e[s].type].apply(null,e[s].matches))[S]){for(n=++s;n<r;n++)if(b.relative[e[n].type])break;return Ce(1<s&&we(c),1<s&&xe(e.slice(0,s-1).concat({value:" "===e[s-2].type?"*":""})).replace($,"$1"),t,s<n&&Ee(e.slice(s,n)),n<r&&Ee(e=e.slice(n)),n<r&&xe(e))}c.push(t)}return we(c)}return me.prototype=b.filters=b.pseudos,b.setFilters=new me,h=se.tokenize=function(e,t){var n,r,i,o,a,s,u,l=x[e+" "];if(l)return t?0:l.slice(0);a=e,s=[],u=b.preFilter;while(a){for(o in n&&!(r=_.exec(a))||(r&&(a=a.slice(r[0].length)||a),s.push(i=[])),n=!1,(r=z.exec(a))&&(n=r.shift(),i.push({value:n,type:r[0].replace($," ")}),a=a.slice(n.length)),b.filter)!(r=G[o].exec(a))||u[o]&&!(r=u[o](r))||(n=r.shift(),i.push({value:n,type:o,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?se.error(e):x(e,s).slice(0)},f=se.compile=function(e,t){var n,v,y,m,x,r,i=[],o=[],a=A[e+" "];if(!a){t||(t=h(e)),n=t.length;while(n--)(a=Ee(t[n]))[S]?i.push(a):o.push(a);(a=A(e,(v=o,m=0<(y=i).length,x=0<v.length,r=function(e,t,n,r,i){var o,a,s,u=0,l="0",c=e&&[],f=[],p=w,d=e||x&&b.find.TAG("*",i),h=k+=null==p?1:Math.random()||.1,g=d.length;for(i&&(w=t==C||t||i);l!==g&&null!=(o=d[l]);l++){if(x&&o){a=0,t||o.ownerDocument==C||(T(o),n=!E);while(s=v[a++])if(s(o,t||C,n)){r.push(o);break}i&&(k=h)}m&&((o=!s&&o)&&u--,e&&c.push(o))}if(u+=l,m&&l!==u){a=0;while(s=y[a++])s(c,f,t,n);if(e){if(0<u)while(l--)c[l]||f[l]||(f[l]=q.call(r));f=Te(f)}H.apply(r,f),i&&!e&&0<f.length&&1<u+y.length&&se.uniqueSort(r)}return i&&(k=h,w=p),c},m?le(r):r))).selector=e}return a},g=se.select=function(e,t,n,r){var i,o,a,s,u,l="function"==typeof e&&e,c=!r&&h(e=l.selector||e);if(n=n||[],1===c.length){if(2<(o=c[0]=c[0].slice(0)).length&&"ID"===(a=o[0]).type&&9===t.nodeType&&E&&b.relative[o[1].type]){if(!(t=(b.find.ID(a.matches[0].replace(te,ne),t)||[])[0]))return n;l&&(t=t.parentNode),e=e.slice(o.shift().value.length)}i=G.needsContext.test(e)?0:o.length;while(i--){if(a=o[i],b.relative[s=a.type])break;if((u=b.find[s])&&(r=u(a.matches[0].replace(te,ne),ee.test(o[0].type)&&ye(t.parentNode)||t))){if(o.splice(i,1),!(e=r.length&&xe(o)))return H.apply(n,r),n;break}}}return(l||f(e,c))(r,t,!E,n,!t||ee.test(e)&&ye(t.parentNode)||t),n},d.sortStable=S.split("").sort(D).join("")===S,d.detectDuplicates=!!l,T(),d.sortDetached=ce(function(e){return 1&e.compareDocumentPosition(C.createElement("fieldset"))}),ce(function(e){return e.innerHTML="<a href='#'></a>","#"===e.firstChild.getAttribute("href")})||fe("type|href|height|width",function(e,t,n){if(!n)return e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),d.attributes&&ce(function(e){return e.innerHTML="<input/>",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||fe("value",function(e,t,n){if(!n&&"input"===e.nodeName.toLowerCase())return e.defaultValue}),ce(function(e){return null==e.getAttribute("disabled")})||fe(R,function(e,t,n){var r;if(!n)return!0===e[t]?t.toLowerCase():(r=e.getAttributeNode(t))&&r.specified?r.value:null}),se}(C);S.find=d,S.expr=d.selectors,S.expr[":"]=S.expr.pseudos,S.uniqueSort=S.unique=d.uniqueSort,S.text=d.getText,S.isXMLDoc=d.isXML,S.contains=d.contains,S.escapeSelector=d.escape;var h=function(e,t,n){var r=[],i=void 0!==n;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&S(e).is(n))break;r.push(e)}return r},T=function(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n},k=S.expr.match.needsContext;function A(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}var N=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?S.grep(e,function(e){return e===n!==r}):"string"!=typeof n?S.grep(e,function(e){return-1<i.call(n,e)!==r}):S.filter(n,e,r)}S.filter=function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?S.find.matchesSelector(r,e)?[r]:[]:S.find.matches(e,S.grep(t,function(e){return 1===e.nodeType}))},S.fn.extend({find:function(e){var t,n,r=this.length,i=this;if("string"!=typeof e)return this.pushStack(S(e).filter(function(){for(t=0;t<r;t++)if(S.contains(i[t],this))return!0}));for(n=this.pushStack([]),t=0;t<r;t++)S.find(e,i[t],n);return 1<r?S.uniqueSort(n):n},filter:function(e){return this.pushStack(D(this,e||[],!1))},not:function(e){return this.pushStack(D(this,e||[],!0))},is:function(e){return!!D(this,"string"==typeof e&&k.test(e)?S(e):e||[],!1).length}});var j,q=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/;(S.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||j,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:q.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof S?t[0]:t,S.merge(this,S.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),N.test(r[1])&&S.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(S):S.makeArray(e,this)}).prototype=S.fn,j=S(E);var L=/^(?:parents|prev(?:Until|All))/,H={children:!0,contents:!0,next:!0,prev:!0};function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}S.fn.extend({has:function(e){var t=S(e,this),n=t.length;return this.filter(function(){for(var e=0;e<n;e++)if(S.contains(this,t[e]))return!0})},closest:function(e,t){var n,r=0,i=this.length,o=[],a="string"!=typeof e&&S(e);if(!k.test(e))for(;r<i;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(n.nodeType<11&&(a?-1<a.index(n):1===n.nodeType&&S.find.matchesSelector(n,e))){o.push(n);break}return this.pushStack(1<o.length?S.uniqueSort(o):o)},index:function(e){return e?"string"==typeof e?i.call(S(e),this[0]):i.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(S.uniqueSort(S.merge(this.get(),S(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),S.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return h(e,"parentNode")},parentsUntil:function(e,t,n){return h(e,"parentNode",n)},next:function(e){return O(e,"nextSibling")},prev:function(e){return O(e,"previousSibling")},nextAll:function(e){return h(e,"nextSibling")},prevAll:function(e){return h(e,"previousSibling")},nextUntil:function(e,t,n){return h(e,"nextSibling",n)},prevUntil:function(e,t,n){return h(e,"previousSibling",n)},siblings:function(e){return T((e.parentNode||{}).firstChild,e)},children:function(e){return T(e.firstChild)},contents:function(e){return null!=e.contentDocument&&r(e.contentDocument)?e.contentDocument:(A(e,"template")&&(e=e.content||e),S.merge([],e.childNodes))}},function(r,i){S.fn[r]=function(e,t){var n=S.map(this,i,e);return"Until"!==r.slice(-5)&&(t=e),t&&"string"==typeof t&&(n=S.filter(t,n)),1<this.length&&(H[r]||S.uniqueSort(n),L.test(r)&&n.reverse()),this.pushStack(n)}});var P=/[^\x20\t\r\n\f]+/g;function R(e){return e}function M(e){throw e}function I(e,t,n,r){var i;try{e&&m(i=e.promise)?i.call(e).done(t).fail(n):e&&m(i=e.then)?i.call(e,t,n):t.apply(void 0,[e].slice(r))}catch(e){n.apply(void 0,[e])}}S.Callbacks=function(r){var e,n;r="string"==typeof r?(e=r,n={},S.each(e.match(P)||[],function(e,t){n[t]=!0}),n):S.extend({},r);var i,t,o,a,s=[],u=[],l=-1,c=function(){for(a=a||r.once,o=i=!0;u.length;l=-1){t=u.shift();while(++l<s.length)!1===s[l].apply(t[0],t[1])&&r.stopOnFalse&&(l=s.length,t=!1)}r.memory||(t=!1),i=!1,a&&(s=t?[]:"")},f={add:function(){return s&&(t&&!i&&(l=s.length-1,u.push(t)),function n(e){S.each(e,function(e,t){m(t)?r.unique&&f.has(t)||s.push(t):t&&t.length&&"string"!==w(t)&&n(t)})}(arguments),t&&!i&&c()),this},remove:function(){return S.each(arguments,function(e,t){var n;while(-1<(n=S.inArray(t,s,n)))s.splice(n,1),n<=l&&l--}),this},has:function(e){return e?-1<S.inArray(e,s):0<s.length},empty:function(){return s&&(s=[]),this},disable:function(){return a=u=[],s=t="",this},disabled:function(){return!s},lock:function(){return a=u=[],t||i||(s=t=""),this},locked:function(){return!!a},fireWith:function(e,t){return a||(t=[e,(t=t||[]).slice?t.slice():t],u.push(t),i||c()),this},fire:function(){return f.fireWith(this,arguments),this},fired:function(){return!!o}};return f},S.extend({Deferred:function(e){var o=[["notify","progress",S.Callbacks("memory"),S.Callbacks("memory"),2],["resolve","done",S.Callbacks("once memory"),S.Callbacks("once memory"),0,"resolved"],["reject","fail",S.Callbacks("once memory"),S.Callbacks("once memory"),1,"rejected"]],i="pending",a={state:function(){return i},always:function(){return s.done(arguments).fail(arguments),this},"catch":function(e){return a.then(null,e)},pipe:function(){var i=arguments;return S.Deferred(function(r){S.each(o,function(e,t){var n=m(i[t[4]])&&i[t[4]];s[t[1]](function(){var e=n&&n.apply(this,arguments);e&&m(e.promise)?e.promise().progress(r.notify).done(r.resolve).fail(r.reject):r[t[0]+"With"](this,n?[e]:arguments)})}),i=null}).promise()},then:function(t,n,r){var u=0;function l(i,o,a,s){return function(){var n=this,r=arguments,e=function(){var e,t;if(!(i<u)){if((e=a.apply(n,r))===o.promise())throw new TypeError("Thenable self-resolution");t=e&&("object"==typeof e||"function"==typeof e)&&e.then,m(t)?s?t.call(e,l(u,o,R,s),l(u,o,M,s)):(u++,t.call(e,l(u,o,R,s),l(u,o,M,s),l(u,o,R,o.notifyWith))):(a!==R&&(n=void 0,r=[e]),(s||o.resolveWith)(n,r))}},t=s?e:function(){try{e()}catch(e){S.Deferred.exceptionHook&&S.Deferred.exceptionHook(e,t.stackTrace),u<=i+1&&(a!==M&&(n=void 0,r=[e]),o.rejectWith(n,r))}};i?t():(S.Deferred.getStackHook&&(t.stackTrace=S.Deferred.getStackHook()),C.setTimeout(t))}}return S.Deferred(function(e){o[0][3].add(l(0,e,m(r)?r:R,e.notifyWith)),o[1][3].add(l(0,e,m(t)?t:R)),o[2][3].add(l(0,e,m(n)?n:M))}).promise()},promise:function(e){return null!=e?S.extend(e,a):a}},s={};return S.each(o,function(e,t){var n=t[2],r=t[5];a[t[1]]=n.add,r&&n.add(function(){i=r},o[3-e][2].disable,o[3-e][3].disable,o[0][2].lock,o[0][3].lock),n.add(t[3].fire),s[t[0]]=function(){return s[t[0]+"With"](this===s?void 0:this,arguments),this},s[t[0]+"With"]=n.fireWith}),a.promise(s),e&&e.call(s,s),s},when:function(e){var n=arguments.length,t=n,r=Array(t),i=s.call(arguments),o=S.Deferred(),a=function(t){return function(e){r[t]=this,i[t]=1<arguments.length?s.call(arguments):e,--n||o.resolveWith(r,i)}};if(n<=1&&(I(e,o.done(a(t)).resolve,o.reject,!n),"pending"===o.state()||m(i[t]&&i[t].then)))return o.then();while(t--)I(i[t],a(t),o.reject);return o.promise()}});var W=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;S.Deferred.exceptionHook=function(e,t){C.console&&C.console.warn&&e&&W.test(e.name)&&C.console.warn("jQuery.Deferred exception: "+e.message,e.stack,t)},S.readyException=function(e){C.setTimeout(function(){throw e})};var F=S.Deferred();function B(){E.removeEventListener("DOMContentLoaded",B),C.removeEventListener("load",B),S.ready()}S.fn.ready=function(e){return F.then(e)["catch"](function(e){S.readyException(e)}),this},S.extend({isReady:!1,readyWait:1,ready:function(e){(!0===e?--S.readyWait:S.isReady)||(S.isReady=!0)!==e&&0<--S.readyWait||F.resolveWith(E,[S])}}),S.ready.then=F.then,"complete"===E.readyState||"loading"!==E.readyState&&!E.documentElement.doScroll?C.setTimeout(S.ready):(E.addEventListener("DOMContentLoaded",B),C.addEventListener("load",B));var $=function(e,t,n,r,i,o,a){var s=0,u=e.length,l=null==n;if("object"===w(n))for(s in i=!0,n)$(e,t,s,n[s],!0,o,a);else if(void 0!==r&&(i=!0,m(r)||(a=!0),l&&(a?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(S(e),n)})),t))for(;s<u;s++)t(e[s],n,a?r:r.call(e[s],s,t(e[s],n)));return i?e:l?t.call(e):u?t(e[0],n):o},_=/^-ms-/,z=/-([a-z])/g;function U(e,t){return t.toUpperCase()}function X(e){return e.replace(_,"ms-").replace(z,U)}var V=function(e){return 1===e.nodeType||9===e.nodeType||!+e.nodeType};function G(){this.expando=S.expando+G.uid++}G.uid=1,G.prototype={cache:function(e){var t=e[this.expando];return t||(t={},V(e)&&(e.nodeType?e[this.expando]=t:Object.defineProperty(e,this.expando,{value:t,configurable:!0}))),t},set:function(e,t,n){var r,i=this.cache(e);if("string"==typeof t)i[X(t)]=n;else for(r in t)i[X(r)]=t[r];return i},get:function(e,t){return void 0===t?this.cache(e):e[this.expando]&&e[this.expando][X(t)]},access:function(e,t,n){return void 0===t||t&&"string"==typeof t&&void 0===n?this.get(e,t):(this.set(e,t,n),void 0!==n?n:t)},remove:function(e,t){var n,r=e[this.expando];if(void 0!==r){if(void 0!==t){n=(t=Array.isArray(t)?t.map(X):(t=X(t))in r?[t]:t.match(P)||[]).length;while(n--)delete r[t[n]]}(void 0===t||S.isEmptyObject(r))&&(e.nodeType?e[this.expando]=void 0:delete e[this.expando])}},hasData:function(e){var t=e[this.expando];return void 0!==t&&!S.isEmptyObject(t)}};var Y=new G,Q=new G,J=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,K=/[A-Z]/g;function Z(e,t,n){var r,i;if(void 0===n&&1===e.nodeType)if(r="data-"+t.replace(K,"-$&").toLowerCase(),"string"==typeof(n=e.getAttribute(r))){try{n="true"===(i=n)||"false"!==i&&("null"===i?null:i===+i+""?+i:J.test(i)?JSON.parse(i):i)}catch(e){}Q.set(e,t,n)}else n=void 0;return n}S.extend({hasData:function(e){return Q.hasData(e)||Y.hasData(e)},data:function(e,t,n){return Q.access(e,t,n)},removeData:function(e,t){Q.remove(e,t)},_data:function(e,t,n){return Y.access(e,t,n)},_removeData:function(e,t){Y.remove(e,t)}}),S.fn.extend({data:function(n,e){var t,r,i,o=this[0],a=o&&o.attributes;if(void 0===n){if(this.length&&(i=Q.get(o),1===o.nodeType&&!Y.get(o,"hasDataAttrs"))){t=a.length;while(t--)a[t]&&0===(r=a[t].name).indexOf("data-")&&(r=X(r.slice(5)),Z(o,r,i[r]));Y.set(o,"hasDataAttrs",!0)}return i}return"object"==typeof n?this.each(function(){Q.set(this,n)}):$(this,function(e){var t;if(o&&void 0===e)return void 0!==(t=Q.get(o,n))?t:void 0!==(t=Z(o,n))?t:void 0;this.each(function(){Q.set(this,n,e)})},null,e,1<arguments.length,null,!0)},removeData:function(e){return this.each(function(){Q.remove(this,e)})}}),S.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=Y.get(e,t),n&&(!r||Array.isArray(n)?r=Y.access(e,t,S.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=S.queue(e,t),r=n.length,i=n.shift(),o=S._queueHooks(e,t);"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,function(){S.dequeue(e,t)},o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return Y.get(e,n)||Y.access(e,n,{empty:S.Callbacks("once memory").add(function(){Y.remove(e,[t+"queue",n])})})}}),S.fn.extend({queue:function(t,n){var e=2;return"string"!=typeof t&&(n=t,t="fx",e--),arguments.length<e?S.queue(this[0],t):void 0===n?this:this.each(function(){var e=S.queue(this,t,n);S._queueHooks(this,t),"fx"===t&&"inprogress"!==e[0]&&S.dequeue(this,t)})},dequeue:function(e){return this.each(function(){S.dequeue(this,e)})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=S.Deferred(),o=this,a=this.length,s=function(){--r||i.resolveWith(o,[o])};"string"!=typeof e&&(t=e,e=void 0),e=e||"fx";while(a--)(n=Y.get(o[a],e+"queueHooks"))&&n.empty&&(r++,n.empty.add(s));return s(),i.promise(t)}});var ee=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,te=new RegExp("^(?:([+-])=|)("+ee+")([a-z%]*)$","i"),ne=["Top","Right","Bottom","Left"],re=E.documentElement,ie=function(e){return S.contains(e.ownerDocument,e)},oe={composed:!0};re.getRootNode&&(ie=function(e){return S.contains(e.ownerDocument,e)||e.getRootNode(oe)===e.ownerDocument});var ae=function(e,t){return"none"===(e=t||e).style.display||""===e.style.display&&ie(e)&&"none"===S.css(e,"display")};function se(e,t,n,r){var i,o,a=20,s=r?function(){return r.cur()}:function(){return S.css(e,t,"")},u=s(),l=n&&n[3]||(S.cssNumber[t]?"":"px"),c=e.nodeType&&(S.cssNumber[t]||"px"!==l&&+u)&&te.exec(S.css(e,t));if(c&&c[3]!==l){u/=2,l=l||c[3],c=+u||1;while(a--)S.style(e,t,c+l),(1-o)*(1-(o=s()/u||.5))<=0&&(a=0),c/=o;c*=2,S.style(e,t,c+l),n=n||[]}return n&&(c=+c||+u||0,i=n[1]?c+(n[1]+1)*n[2]:+n[2],r&&(r.unit=l,r.start=c,r.end=i)),i}var ue={};function le(e,t){for(var n,r,i,o,a,s,u,l=[],c=0,f=e.length;c<f;c++)(r=e[c]).style&&(n=r.style.display,t?("none"===n&&(l[c]=Y.get(r,"display")||null,l[c]||(r.style.display="")),""===r.style.display&&ae(r)&&(l[c]=(u=a=o=void 0,a=(i=r).ownerDocument,s=i.nodeName,(u=ue[s])||(o=a.body.appendChild(a.createElement(s)),u=S.css(o,"display"),o.parentNode.removeChild(o),"none"===u&&(u="block"),ue[s]=u)))):"none"!==n&&(l[c]="none",Y.set(r,"display",n)));for(c=0;c<f;c++)null!=l[c]&&(e[c].style.display=l[c]);return e}S.fn.extend({show:function(){return le(this,!0)},hide:function(){return le(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){ae(this)?S(this).show():S(this).hide()})}});var ce,fe,pe=/^(?:checkbox|radio)$/i,de=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i;ce=E.createDocumentFragment().appendChild(E.createElement("div")),(fe=E.createElement("input")).setAttribute("type","radio"),fe.setAttribute("checked","checked"),fe.setAttribute("name","t"),ce.appendChild(fe),y.checkClone=ce.cloneNode(!0).cloneNode(!0).lastChild.checked,ce.innerHTML="<textarea>x</textarea>",y.noCloneChecked=!!ce.cloneNode(!0).lastChild.defaultValue,ce.innerHTML="<option></option>",y.option=!!ce.lastChild;var ge={thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?S.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;n<r;n++)Y.set(e[n],"globalEval",!t||Y.get(t[n],"globalEval"))}ge.tbody=ge.tfoot=ge.colgroup=ge.caption=ge.thead,ge.th=ge.td,y.option||(ge.optgroup=ge.option=[1,"<select multiple='multiple'>","</select>"]);var me=/<|&#?\w+;/;function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d<h;d++)if((o=e[d])||0===o)if("object"===w(o))S.merge(p,o.nodeType?[o]:o);else if(me.test(o)){a=a||f.appendChild(t.createElement("div")),s=(de.exec(o)||["",""])[1].toLowerCase(),u=ge[s]||ge._default,a.innerHTML=u[1]+S.htmlPrefilter(o)+u[2],c=u[0];while(c--)a=a.lastChild;S.merge(p,a.childNodes),(a=f.firstChild).textContent=""}else p.push(t.createTextNode(o));f.textContent="",d=0;while(o=p[d++])if(r&&-1<S.inArray(o,r))i&&i.push(o);else if(l=ie(o),a=ve(f.appendChild(o),"script"),l&&ye(a),n){c=0;while(o=a[c++])he.test(o.type||"")&&n.push(o)}return f}var be=/^key/,we=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Te=/^([^.]*)(?:\.(.+)|)/;function Ce(){return!0}function Ee(){return!1}function Se(e,t){return e===function(){try{return E.activeElement}catch(e){}}()==("focus"===t)}function ke(e,t,n,r,i,o){var a,s;if("object"==typeof t){for(s in"string"!=typeof n&&(r=r||n,n=void 0),t)ke(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=Ee;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return S().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=S.guid++)),e.each(function(){S.event.add(this,t,i,r,n)})}function Ae(e,i,o){o?(Y.set(e,i,!1),S.event.add(e,i,{namespace:!1,handler:function(e){var t,n,r=Y.get(this,i);if(1&e.isTrigger&&this[i]){if(r.length)(S.event.special[i]||{}).delegateType&&e.stopPropagation();else if(r=s.call(arguments),Y.set(this,i,r),t=o(this,i),this[i](),r!==(n=Y.get(this,i))||t?Y.set(this,i,!1):n={},r!==n)return e.stopImmediatePropagation(),e.preventDefault(),n.value}else r.length&&(Y.set(this,i,{value:S.event.trigger(S.extend(r[0],S.Event.prototype),r.slice(1),this)}),e.stopImmediatePropagation())}})):void 0===Y.get(e,i)&&S.event.add(e,i,Ce)}S.event={global:{},add:function(t,e,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Y.get(t);if(V(t)){n.handler&&(n=(o=n).handler,i=o.selector),i&&S.find.matchesSelector(re,i),n.guid||(n.guid=S.guid++),(u=v.events)||(u=v.events=Object.create(null)),(a=v.handle)||(a=v.handle=function(e){return"undefined"!=typeof S&&S.event.triggered!==e.type?S.event.dispatch.apply(t,arguments):void 0}),l=(e=(e||"").match(P)||[""]).length;while(l--)d=g=(s=Te.exec(e[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=S.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=S.event.special[d]||{},c=S.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&S.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(t,r,h,a)||t.addEventListener&&t.addEventListener(d,a)),f.add&&(f.add.call(t,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),S.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Y.hasData(e)&&Y.get(e);if(v&&(u=v.events)){l=(t=(t||"").match(P)||[""]).length;while(l--)if(d=g=(s=Te.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d){f=S.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,v.handle)||S.removeEvent(e,d,v.handle),delete u[d])}else for(d in u)S.event.remove(e,d+t[l],n,r,!0);S.isEmptyObject(u)&&Y.remove(e,"handle events")}},dispatch:function(e){var t,n,r,i,o,a,s=new Array(arguments.length),u=S.event.fix(e),l=(Y.get(this,"events")||Object.create(null))[u.type]||[],c=S.event.special[u.type]||{};for(s[0]=u,t=1;t<arguments.length;t++)s[t]=arguments[t];if(u.delegateTarget=this,!c.preDispatch||!1!==c.preDispatch.call(this,u)){a=S.event.handlers.call(this,u,l),t=0;while((i=a[t++])&&!u.isPropagationStopped()){u.currentTarget=i.elem,n=0;while((o=i.handlers[n++])&&!u.isImmediatePropagationStopped())u.rnamespace&&!1!==o.namespace&&!u.rnamespace.test(o.namespace)||(u.handleObj=o,u.data=o.data,void 0!==(r=((S.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,s))&&!1===(u.result=r)&&(u.preventDefault(),u.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,u),u.result}},handlers:function(e,t){var n,r,i,o,a,s=[],u=t.delegateCount,l=e.target;if(u&&l.nodeType&&!("click"===e.type&&1<=e.button))for(;l!==this;l=l.parentNode||this)if(1===l.nodeType&&("click"!==e.type||!0!==l.disabled)){for(o=[],a={},n=0;n<u;n++)void 0===a[i=(r=t[n]).selector+" "]&&(a[i]=r.needsContext?-1<S(i,this).index(l):S.find(i,this,null,[l]).length),a[i]&&o.push(r);o.length&&s.push({elem:l,handlers:o})}return l=this,u<t.length&&s.push({elem:l,handlers:t.slice(u)}),s},addProp:function(t,e){Object.defineProperty(S.Event.prototype,t,{enumerable:!0,configurable:!0,get:m(e)?function(){if(this.originalEvent)return e(this.originalEvent)}:function(){if(this.originalEvent)return this.originalEvent[t]},set:function(e){Object.defineProperty(this,t,{enumerable:!0,configurable:!0,writable:!0,value:e})}})},fix:function(e){return e[S.expando]?e:new S.Event(e)},special:{load:{noBubble:!0},click:{setup:function(e){var t=this||e;return pe.test(t.type)&&t.click&&A(t,"input")&&Ae(t,"click",Ce),!1},trigger:function(e){var t=this||e;return pe.test(t.type)&&t.click&&A(t,"input")&&Ae(t,"click"),!0},_default:function(e){var t=e.target;return pe.test(t.type)&&t.click&&A(t,"input")&&Y.get(t,"click")||A(t,"a")}},beforeunload:{postDispatch:function(e){void 0!==e.result&&e.originalEvent&&(e.originalEvent.returnValue=e.result)}}}},S.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n)},S.Event=function(e,t){if(!(this instanceof S.Event))return new S.Event(e,t);e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||void 0===e.defaultPrevented&&!1===e.returnValue?Ce:Ee,this.target=e.target&&3===e.target.nodeType?e.target.parentNode:e.target,this.currentTarget=e.currentTarget,this.relatedTarget=e.relatedTarget):this.type=e,t&&S.extend(this,t),this.timeStamp=e&&e.timeStamp||Date.now(),this[S.expando]=!0},S.Event.prototype={constructor:S.Event,isDefaultPrevented:Ee,isPropagationStopped:Ee,isImmediatePropagationStopped:Ee,isSimulated:!1,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=Ce,e&&!this.isSimulated&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=Ce,e&&!this.isSimulated&&e.stopPropagation()},stopImmediatePropagation:function(){var e=this.originalEvent;this.isImmediatePropagationStopped=Ce,e&&!this.isSimulated&&e.stopImmediatePropagation(),this.stopPropagation()}},S.each({altKey:!0,bubbles:!0,cancelable:!0,changedTouches:!0,ctrlKey:!0,detail:!0,eventPhase:!0,metaKey:!0,pageX:!0,pageY:!0,shiftKey:!0,view:!0,"char":!0,code:!0,charCode:!0,key:!0,keyCode:!0,button:!0,buttons:!0,clientX:!0,clientY:!0,offsetX:!0,offsetY:!0,pointerId:!0,pointerType:!0,screenX:!0,screenY:!0,targetTouches:!0,toElement:!0,touches:!0,which:function(e){var t=e.button;return null==e.which&&be.test(e.type)?null!=e.charCode?e.charCode:e.keyCode:!e.which&&void 0!==t&&we.test(e.type)?1&t?1:2&t?3:4&t?2:0:e.which}},S.event.addProp),S.each({focus:"focusin",blur:"focusout"},function(e,t){S.event.special[e]={setup:function(){return Ae(this,e,Se),!1},trigger:function(){return Ae(this,e),!0},delegateType:t}}),S.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(e,i){S.event.special[e]={delegateType:i,bindType:i,handle:function(e){var t,n=e.relatedTarget,r=e.handleObj;return n&&(n===this||S.contains(this,n))||(e.type=r.origType,t=r.handler.apply(this,arguments),e.type=i),t}}}),S.fn.extend({on:function(e,t,n,r){return ke(this,e,t,n,r)},one:function(e,t,n,r){return ke(this,e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,S(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return!1!==t&&"function"!=typeof t||(n=t,t=void 0),!1===n&&(n=Ee),this.each(function(){S.event.remove(this,e,n,t)})}});var Ne=/<script|<style|<link/i,De=/checked\s*(?:[^=]|=\s*.checked.)/i,je=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&S(e).children("tbody")[0]||e}function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=Y.get(e).events))for(i in Y.remove(t,"handle events"),s)for(n=0,r=s[i].length;n<r;n++)S.event.add(t,i,s[i][n]);Q.hasData(e)&&(o=Q.access(e),a=S.extend({},o),Q.set(t,a))}}function Pe(n,r,i,o){r=g(r);var e,t,a,s,u,l,c=0,f=n.length,p=f-1,d=r[0],h=m(d);if(h||1<f&&"string"==typeof d&&!y.checkClone&&De.test(d))return n.each(function(e){var t=n.eq(e);h&&(r[0]=d.call(this,e,t.html())),Pe(t,r,i,o)});if(f&&(t=(e=xe(r,n[0].ownerDocument,!1,n,o)).firstChild,1===e.childNodes.length&&(e=t),t||o)){for(s=(a=S.map(ve(e,"script"),Le)).length;c<f;c++)u=e,c!==p&&(u=S.clone(u,!0,!0),s&&S.merge(a,ve(u,"script"))),i.call(n[c],u,c);if(s)for(l=a[a.length-1].ownerDocument,S.map(a,He),c=0;c<s;c++)u=a[c],he.test(u.type||"")&&!Y.access(u,"globalEval")&&S.contains(l,u)&&(u.src&&"module"!==(u.type||"").toLowerCase()?S._evalUrl&&!u.noModule&&S._evalUrl(u.src,{nonce:u.nonce||u.getAttribute("nonce")},l):b(u.textContent.replace(je,""),u,l))}return n}function Re(e,t,n){for(var r,i=t?S.filter(t,e):e,o=0;null!=(r=i[o]);o++)n||1!==r.nodeType||S.cleanData(ve(r)),r.parentNode&&(n&&ie(r)&&ye(ve(r,"script")),r.parentNode.removeChild(r));return e}S.extend({htmlPrefilter:function(e){return e},clone:function(e,t,n){var r,i,o,a,s,u,l,c=e.cloneNode(!0),f=ie(e);if(!(y.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||S.isXMLDoc(e)))for(a=ve(c),r=0,i=(o=ve(e)).length;r<i;r++)s=o[r],u=a[r],void 0,"input"===(l=u.nodeName.toLowerCase())&&pe.test(s.type)?u.checked=s.checked:"input"!==l&&"textarea"!==l||(u.defaultValue=s.defaultValue);if(t)if(n)for(o=o||ve(e),a=a||ve(c),r=0,i=o.length;r<i;r++)Oe(o[r],a[r]);else Oe(e,c);return 0<(a=ve(c,"script")).length&&ye(a,!f&&ve(e,"script")),c},cleanData:function(e){for(var t,n,r,i=S.event.special,o=0;void 0!==(n=e[o]);o++)if(V(n)){if(t=n[Y.expando]){if(t.events)for(r in t.events)i[r]?S.event.remove(n,r):S.removeEvent(n,r,t.handle);n[Y.expando]=void 0}n[Q.expando]&&(n[Q.expando]=void 0)}}}),S.fn.extend({detach:function(e){return Re(this,e,!0)},remove:function(e){return Re(this,e)},text:function(e){return $(this,function(e){return void 0===e?S.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=e)})},null,e,arguments.length)},append:function(){return Pe(this,arguments,function(e){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||qe(this,e).appendChild(e)})},prepend:function(){return Pe(this,arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=qe(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return Pe(this,arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return Pe(this,arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},empty:function(){for(var e,t=0;null!=(e=this[t]);t++)1===e.nodeType&&(S.cleanData(ve(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null!=e&&e,t=null==t?e:t,this.map(function(){return S.clone(this,e,t)})},html:function(e){return $(this,function(e){var t=this[0]||{},n=0,r=this.length;if(void 0===e&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!Ne.test(e)&&!ge[(de.exec(e)||["",""])[1].toLowerCase()]){e=S.htmlPrefilter(e);try{for(;n<r;n++)1===(t=this[n]||{}).nodeType&&(S.cleanData(ve(t,!1)),t.innerHTML=e);t=0}catch(e){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var n=[];return Pe(this,arguments,function(e){var t=this.parentNode;S.inArray(this,n)<0&&(S.cleanData(ve(this)),t&&t.replaceChild(e,this))},n)}}),S.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,a){S.fn[e]=function(e){for(var t,n=[],r=S(e),i=r.length-1,o=0;o<=i;o++)t=o===i?this:this.clone(!0),S(r[o])[a](t),u.apply(n,t.get());return this.pushStack(n)}});var Me=new RegExp("^("+ee+")(?!px)[a-z%]+$","i"),Ie=function(e){var t=e.ownerDocument.defaultView;return t&&t.opener||(t=C),t.getComputedStyle(e)},We=function(e,t,n){var r,i,o={};for(i in t)o[i]=e.style[i],e.style[i]=t[i];for(i in r=n.call(e),t)e.style[i]=o[i];return r},Fe=new RegExp(ne.join("|"),"i");function Be(e,t,n){var r,i,o,a,s=e.style;return(n=n||Ie(e))&&(""!==(a=n.getPropertyValue(t)||n[t])||ie(e)||(a=S.style(e,t)),!y.pixelBoxStyles()&&Me.test(a)&&Fe.test(t)&&(r=s.width,i=s.minWidth,o=s.maxWidth,s.minWidth=s.maxWidth=s.width=a,a=n.width,s.width=r,s.minWidth=i,s.maxWidth=o)),void 0!==a?a+"":a}function $e(e,t){return{get:function(){if(!e())return(this.get=t).apply(this,arguments);delete this.get}}}!function(){function e(){if(l){u.style.cssText="position:absolute;left:-11111px;width:60px;margin-top:1px;padding:0;border:0",l.style.cssText="position:relative;display:block;box-sizing:border-box;overflow:scroll;margin:auto;border:1px;padding:1px;width:60%;top:1%",re.appendChild(u).appendChild(l);var e=C.getComputedStyle(l);n="1%"!==e.top,s=12===t(e.marginLeft),l.style.right="60%",o=36===t(e.right),r=36===t(e.width),l.style.position="absolute",i=12===t(l.offsetWidth/3),re.removeChild(u),l=null}}function t(e){return Math.round(parseFloat(e))}var n,r,i,o,a,s,u=E.createElement("div"),l=E.createElement("div");l.style&&(l.style.backgroundClip="content-box",l.cloneNode(!0).style.backgroundClip="",y.clearCloneStyle="content-box"===l.style.backgroundClip,S.extend(y,{boxSizingReliable:function(){return e(),r},pixelBoxStyles:function(){return e(),o},pixelPosition:function(){return e(),n},reliableMarginLeft:function(){return e(),s},scrollboxSize:function(){return e(),i},reliableTrDimensions:function(){var e,t,n,r;return null==a&&(e=E.createElement("table"),t=E.createElement("tr"),n=E.createElement("div"),e.style.cssText="position:absolute;left:-11111px",t.style.height="1px",n.style.height="9px",re.appendChild(e).appendChild(t).appendChild(n),r=C.getComputedStyle(t),a=3<parseInt(r.height),re.removeChild(e)),a}}))}();var _e=["Webkit","Moz","ms"],ze=E.createElement("div").style,Ue={};function Xe(e){var t=S.cssProps[e]||Ue[e];return t||(e in ze?e:Ue[e]=function(e){var t=e[0].toUpperCase()+e.slice(1),n=_e.length;while(n--)if((e=_e[n]+t)in ze)return e}(e)||e)}var Ve=/^(none|table(?!-c[ea]).+)/,Ge=/^--/,Ye={position:"absolute",visibility:"hidden",display:"block"},Qe={letterSpacing:"0",fontWeight:"400"};function Je(e,t,n){var r=te.exec(t);return r?Math.max(0,r[2]-(n||0))+(r[3]||"px"):t}function Ke(e,t,n,r,i,o){var a="width"===t?1:0,s=0,u=0;if(n===(r?"border":"content"))return 0;for(;a<4;a+=2)"margin"===n&&(u+=S.css(e,n+ne[a],!0,i)),r?("content"===n&&(u-=S.css(e,"padding"+ne[a],!0,i)),"margin"!==n&&(u-=S.css(e,"border"+ne[a]+"Width",!0,i))):(u+=S.css(e,"padding"+ne[a],!0,i),"padding"!==n?u+=S.css(e,"border"+ne[a]+"Width",!0,i):s+=S.css(e,"border"+ne[a]+"Width",!0,i));return!r&&0<=o&&(u+=Math.max(0,Math.ceil(e["offset"+t[0].toUpperCase()+t.slice(1)]-o-u-s-.5))||0),u}function Ze(e,t,n){var r=Ie(e),i=(!y.boxSizingReliable()||n)&&"border-box"===S.css(e,"boxSizing",!1,r),o=i,a=Be(e,t,r),s="offset"+t[0].toUpperCase()+t.slice(1);if(Me.test(a)){if(!n)return a;a="auto"}return(!y.boxSizingReliable()&&i||!y.reliableTrDimensions()&&A(e,"tr")||"auto"===a||!parseFloat(a)&&"inline"===S.css(e,"display",!1,r))&&e.getClientRects().length&&(i="border-box"===S.css(e,"boxSizing",!1,r),(o=s in e)&&(a=e[s])),(a=parseFloat(a)||0)+Ke(e,t,n||(i?"border":"content"),o,r,a)+"px"}function et(e,t,n,r,i){return new et.prototype.init(e,t,n,r,i)}S.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Be(e,"opacity");return""===n?"1":n}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,gridArea:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnStart:!0,gridRow:!0,gridRowEnd:!0,gridRowStart:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,a,s=X(t),u=Ge.test(t),l=e.style;if(u||(t=Xe(s)),a=S.cssHooks[t]||S.cssHooks[s],void 0===n)return a&&"get"in a&&void 0!==(i=a.get(e,!1,r))?i:l[t];"string"===(o=typeof n)&&(i=te.exec(n))&&i[1]&&(n=se(e,t,i),o="number"),null!=n&&n==n&&("number"!==o||u||(n+=i&&i[3]||(S.cssNumber[s]?"":"px")),y.clearCloneStyle||""!==n||0!==t.indexOf("background")||(l[t]="inherit"),a&&"set"in a&&void 0===(n=a.set(e,n,r))||(u?l.setProperty(t,n):l[t]=n))}},css:function(e,t,n,r){var i,o,a,s=X(t);return Ge.test(t)||(t=Xe(s)),(a=S.cssHooks[t]||S.cssHooks[s])&&"get"in a&&(i=a.get(e,!0,n)),void 0===i&&(i=Be(e,t,r)),"normal"===i&&t in Qe&&(i=Qe[t]),""===n||n?(o=parseFloat(i),!0===n||isFinite(o)?o||0:i):i}}),S.each(["height","width"],function(e,u){S.cssHooks[u]={get:function(e,t,n){if(t)return!Ve.test(S.css(e,"display"))||e.getClientRects().length&&e.getBoundingClientRect().width?Ze(e,u,n):We(e,Ye,function(){return Ze(e,u,n)})},set:function(e,t,n){var r,i=Ie(e),o=!y.scrollboxSize()&&"absolute"===i.position,a=(o||n)&&"border-box"===S.css(e,"boxSizing",!1,i),s=n?Ke(e,u,n,a,i):0;return a&&o&&(s-=Math.ceil(e["offset"+u[0].toUpperCase()+u.slice(1)]-parseFloat(i[u])-Ke(e,u,"border",!1,i)-.5)),s&&(r=te.exec(t))&&"px"!==(r[3]||"px")&&(e.style[u]=t,t=S.css(e,u)),Je(0,t,s)}}}),S.cssHooks.marginLeft=$e(y.reliableMarginLeft,function(e,t){if(t)return(parseFloat(Be(e,"marginLeft"))||e.getBoundingClientRect().left-We(e,{marginLeft:0},function(){return e.getBoundingClientRect().left}))+"px"}),S.each({margin:"",padding:"",border:"Width"},function(i,o){S.cssHooks[i+o]={expand:function(e){for(var t=0,n={},r="string"==typeof e?e.split(" "):[e];t<4;t++)n[i+ne[t]+o]=r[t]||r[t-2]||r[0];return n}},"margin"!==i&&(S.cssHooks[i+o].set=Je)}),S.fn.extend({css:function(e,t){return $(this,function(e,t,n){var r,i,o={},a=0;if(Array.isArray(t)){for(r=Ie(e),i=t.length;a<i;a++)o[t[a]]=S.css(e,t[a],!1,r);return o}return void 0!==n?S.style(e,t,n):S.css(e,t)},e,t,1<arguments.length)}}),((S.Tween=et).prototype={constructor:et,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||S.easing._default,this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(S.cssNumber[n]?"":"px")},cur:function(){var e=et.propHooks[this.prop];return e&&e.get?e.get(this):et.propHooks._default.get(this)},run:function(e){var t,n=et.propHooks[this.prop];return this.options.duration?this.pos=t=S.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):this.pos=t=e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):et.propHooks._default.set(this),this}}).init.prototype=et.prototype,(et.propHooks={_default:{get:function(e){var t;return 1!==e.elem.nodeType||null!=e.elem[e.prop]&&null==e.elem.style[e.prop]?e.elem[e.prop]:(t=S.css(e.elem,e.prop,""))&&"auto"!==t?t:0},set:function(e){S.fx.step[e.prop]?S.fx.step[e.prop](e):1!==e.elem.nodeType||!S.cssHooks[e.prop]&&null==e.elem.style[Xe(e.prop)]?e.elem[e.prop]=e.now:S.style(e.elem,e.prop,e.now+e.unit)}}}).scrollTop=et.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},S.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2},_default:"swing"},S.fx=et.prototype.init,S.fx.step={};var tt,nt,rt,it,ot=/^(?:toggle|show|hide)$/,at=/queueHooks$/;function st(){nt&&(!1===E.hidden&&C.requestAnimationFrame?C.requestAnimationFrame(st):C.setTimeout(st,S.fx.interval),S.fx.tick())}function ut(){return C.setTimeout(function(){tt=void 0}),tt=Date.now()}function lt(e,t){var n,r=0,i={height:e};for(t=t?1:0;r<4;r+=2-t)i["margin"+(n=ne[r])]=i["padding"+n]=e;return t&&(i.opacity=i.width=e),i}function ct(e,t,n){for(var r,i=(ft.tweeners[t]||[]).concat(ft.tweeners["*"]),o=0,a=i.length;o<a;o++)if(r=i[o].call(n,t,e))return r}function ft(o,e,t){var n,a,r=0,i=ft.prefilters.length,s=S.Deferred().always(function(){delete u.elem}),u=function(){if(a)return!1;for(var e=tt||ut(),t=Math.max(0,l.startTime+l.duration-e),n=1-(t/l.duration||0),r=0,i=l.tweens.length;r<i;r++)l.tweens[r].run(n);return s.notifyWith(o,[l,n,t]),n<1&&i?t:(i||s.notifyWith(o,[l,1,0]),s.resolveWith(o,[l]),!1)},l=s.promise({elem:o,props:S.extend({},e),opts:S.extend(!0,{specialEasing:{},easing:S.easing._default},t),originalProperties:e,originalOptions:t,startTime:tt||ut(),duration:t.duration,tweens:[],createTween:function(e,t){var n=S.Tween(o,l.opts,e,t,l.opts.specialEasing[e]||l.opts.easing);return l.tweens.push(n),n},stop:function(e){var t=0,n=e?l.tweens.length:0;if(a)return this;for(a=!0;t<n;t++)l.tweens[t].run(1);return e?(s.notifyWith(o,[l,1,0]),s.resolveWith(o,[l,e])):s.rejectWith(o,[l,e]),this}}),c=l.props;for(!function(e,t){var n,r,i,o,a;for(n in e)if(i=t[r=X(n)],o=e[n],Array.isArray(o)&&(i=o[1],o=e[n]=o[0]),n!==r&&(e[r]=o,delete e[n]),(a=S.cssHooks[r])&&"expand"in a)for(n in o=a.expand(o),delete e[r],o)n in e||(e[n]=o[n],t[n]=i);else t[r]=i}(c,l.opts.specialEasing);r<i;r++)if(n=ft.prefilters[r].call(l,o,c,l.opts))return m(n.stop)&&(S._queueHooks(l.elem,l.opts.queue).stop=n.stop.bind(n)),n;return S.map(c,ct,l),m(l.opts.start)&&l.opts.start.call(o,l),l.progress(l.opts.progress).done(l.opts.done,l.opts.complete).fail(l.opts.fail).always(l.opts.always),S.fx.timer(S.extend(u,{elem:o,anim:l,queue:l.opts.queue})),l}S.Animation=S.extend(ft,{tweeners:{"*":[function(e,t){var n=this.createTween(e,t);return se(n.elem,e,te.exec(t),n),n}]},tweener:function(e,t){m(e)?(t=e,e=["*"]):e=e.match(P);for(var n,r=0,i=e.length;r<i;r++)n=e[r],ft.tweeners[n]=ft.tweeners[n]||[],ft.tweeners[n].unshift(t)},prefilters:[function(e,t,n){var r,i,o,a,s,u,l,c,f="width"in t||"height"in t,p=this,d={},h=e.style,g=e.nodeType&&ae(e),v=Y.get(e,"fxshow");for(r in n.queue||(null==(a=S._queueHooks(e,"fx")).unqueued&&(a.unqueued=0,s=a.empty.fire,a.empty.fire=function(){a.unqueued||s()}),a.unqueued++,p.always(function(){p.always(function(){a.unqueued--,S.queue(e,"fx").length||a.empty.fire()})})),t)if(i=t[r],ot.test(i)){if(delete t[r],o=o||"toggle"===i,i===(g?"hide":"show")){if("show"!==i||!v||void 0===v[r])continue;g=!0}d[r]=v&&v[r]||S.style(e,r)}if((u=!S.isEmptyObject(t))||!S.isEmptyObject(d))for(r in f&&1===e.nodeType&&(n.overflow=[h.overflow,h.overflowX,h.overflowY],null==(l=v&&v.display)&&(l=Y.get(e,"display")),"none"===(c=S.css(e,"display"))&&(l?c=l:(le([e],!0),l=e.style.display||l,c=S.css(e,"display"),le([e]))),("inline"===c||"inline-block"===c&&null!=l)&&"none"===S.css(e,"float")&&(u||(p.done(function(){h.display=l}),null==l&&(c=h.display,l="none"===c?"":c)),h.display="inline-block")),n.overflow&&(h.overflow="hidden",p.always(function(){h.overflow=n.overflow[0],h.overflowX=n.overflow[1],h.overflowY=n.overflow[2]})),u=!1,d)u||(v?"hidden"in v&&(g=v.hidden):v=Y.access(e,"fxshow",{display:l}),o&&(v.hidden=!g),g&&le([e],!0),p.done(function(){for(r in g||le([e]),Y.remove(e,"fxshow"),d)S.style(e,r,d[r])})),u=ct(g?v[r]:0,r,p),r in v||(v[r]=u.start,g&&(u.end=u.start,u.start=0))}],prefilter:function(e,t){t?ft.prefilters.unshift(e):ft.prefilters.push(e)}}),S.speed=function(e,t,n){var r=e&&"object"==typeof e?S.extend({},e):{complete:n||!n&&t||m(e)&&e,duration:e,easing:n&&t||t&&!m(t)&&t};return S.fx.off?r.duration=0:"number"!=typeof r.duration&&(r.duration in S.fx.speeds?r.duration=S.fx.speeds[r.duration]:r.duration=S.fx.speeds._default),null!=r.queue&&!0!==r.queue||(r.queue="fx"),r.old=r.complete,r.complete=function(){m(r.old)&&r.old.call(this),r.queue&&S.dequeue(this,r.queue)},r},S.fn.extend({fadeTo:function(e,t,n,r){return this.filter(ae).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(t,e,n,r){var i=S.isEmptyObject(t),o=S.speed(e,n,r),a=function(){var e=ft(this,S.extend({},t),o);(i||Y.get(this,"finish"))&&e.stop(!0)};return a.finish=a,i||!1===o.queue?this.each(a):this.queue(o.queue,a)},stop:function(i,e,o){var a=function(e){var t=e.stop;delete e.stop,t(o)};return"string"!=typeof i&&(o=e,e=i,i=void 0),e&&this.queue(i||"fx",[]),this.each(function(){var e=!0,t=null!=i&&i+"queueHooks",n=S.timers,r=Y.get(this);if(t)r[t]&&r[t].stop&&a(r[t]);else for(t in r)r[t]&&r[t].stop&&at.test(t)&&a(r[t]);for(t=n.length;t--;)n[t].elem!==this||null!=i&&n[t].queue!==i||(n[t].anim.stop(o),e=!1,n.splice(t,1));!e&&o||S.dequeue(this,i)})},finish:function(a){return!1!==a&&(a=a||"fx"),this.each(function(){var e,t=Y.get(this),n=t[a+"queue"],r=t[a+"queueHooks"],i=S.timers,o=n?n.length:0;for(t.finish=!0,S.queue(this,a,[]),r&&r.stop&&r.stop.call(this,!0),e=i.length;e--;)i[e].elem===this&&i[e].queue===a&&(i[e].anim.stop(!0),i.splice(e,1));for(e=0;e<o;e++)n[e]&&n[e].finish&&n[e].finish.call(this);delete t.finish})}}),S.each(["toggle","show","hide"],function(e,r){var i=S.fn[r];S.fn[r]=function(e,t,n){return null==e||"boolean"==typeof e?i.apply(this,arguments):this.animate(lt(r,!0),e,t,n)}}),S.each({slideDown:lt("show"),slideUp:lt("hide"),slideToggle:lt("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,r){S.fn[e]=function(e,t,n){return this.animate(r,e,t,n)}}),S.timers=[],S.fx.tick=function(){var e,t=0,n=S.timers;for(tt=Date.now();t<n.length;t++)(e=n[t])()||n[t]!==e||n.splice(t--,1);n.length||S.fx.stop(),tt=void 0},S.fx.timer=function(e){S.timers.push(e),S.fx.start()},S.fx.interval=13,S.fx.start=function(){nt||(nt=!0,st())},S.fx.stop=function(){nt=null},S.fx.speeds={slow:600,fast:200,_default:400},S.fn.delay=function(r,e){return r=S.fx&&S.fx.speeds[r]||r,e=e||"fx",this.queue(e,function(e,t){var n=C.setTimeout(e,r);t.stop=function(){C.clearTimeout(n)}})},rt=E.createElement("input"),it=E.createElement("select").appendChild(E.createElement("option")),rt.type="checkbox",y.checkOn=""!==rt.value,y.optSelected=it.selected,(rt=E.createElement("input")).value="t",rt.type="radio",y.radioValue="t"===rt.value;var pt,dt=S.expr.attrHandle;S.fn.extend({attr:function(e,t){return $(this,S.attr,e,t,1<arguments.length)},removeAttr:function(e){return this.each(function(){S.removeAttr(this,e)})}}),S.extend({attr:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return"undefined"==typeof e.getAttribute?S.prop(e,t,n):(1===o&&S.isXMLDoc(e)||(i=S.attrHooks[t.toLowerCase()]||(S.expr.match.bool.test(t)?pt:void 0)),void 0!==n?null===n?void S.removeAttr(e,t):i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:(e.setAttribute(t,n+""),n):i&&"get"in i&&null!==(r=i.get(e,t))?r:null==(r=S.find.attr(e,t))?void 0:r)},attrHooks:{type:{set:function(e,t){if(!y.radioValue&&"radio"===t&&A(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},removeAttr:function(e,t){var n,r=0,i=t&&t.match(P);if(i&&1===e.nodeType)while(n=i[r++])e.removeAttribute(n)}}),pt={set:function(e,t,n){return!1===t?S.removeAttr(e,n):e.setAttribute(n,n),n}},S.each(S.expr.match.bool.source.match(/\w+/g),function(e,t){var a=dt[t]||S.find.attr;dt[t]=function(e,t,n){var r,i,o=t.toLowerCase();return n||(i=dt[o],dt[o]=r,r=null!=a(e,t,n)?o:null,dt[o]=i),r}});var ht=/^(?:input|select|textarea|button)$/i,gt=/^(?:a|area)$/i;function vt(e){return(e.match(P)||[]).join(" ")}function yt(e){return e.getAttribute&&e.getAttribute("class")||""}function mt(e){return Array.isArray(e)?e:"string"==typeof e&&e.match(P)||[]}S.fn.extend({prop:function(e,t){return $(this,S.prop,e,t,1<arguments.length)},removeProp:function(e){return this.each(function(){delete this[S.propFix[e]||e]})}}),S.extend({prop:function(e,t,n){var r,i,o=e.nodeType;if(3!==o&&8!==o&&2!==o)return 1===o&&S.isXMLDoc(e)||(t=S.propFix[t]||t,i=S.propHooks[t]),void 0!==n?i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){var t=S.find.attr(e,"tabindex");return t?parseInt(t,10):ht.test(e.nodeName)||gt.test(e.nodeName)&&e.href?0:-1}}},propFix:{"for":"htmlFor","class":"className"}}),y.optSelected||(S.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null},set:function(e){var t=e.parentNode;t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex)}}),S.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){S.propFix[this.toLowerCase()]=this}),S.fn.extend({addClass:function(t){var e,n,r,i,o,a,s,u=0;if(m(t))return this.each(function(e){S(this).addClass(t.call(this,e,yt(this)))});if((e=mt(t)).length)while(n=this[u++])if(i=yt(n),r=1===n.nodeType&&" "+vt(i)+" "){a=0;while(o=e[a++])r.indexOf(" "+o+" ")<0&&(r+=o+" ");i!==(s=vt(r))&&n.setAttribute("class",s)}return this},removeClass:function(t){var e,n,r,i,o,a,s,u=0;if(m(t))return this.each(function(e){S(this).removeClass(t.call(this,e,yt(this)))});if(!arguments.length)return this.attr("class","");if((e=mt(t)).length)while(n=this[u++])if(i=yt(n),r=1===n.nodeType&&" "+vt(i)+" "){a=0;while(o=e[a++])while(-1<r.indexOf(" "+o+" "))r=r.replace(" "+o+" "," ");i!==(s=vt(r))&&n.setAttribute("class",s)}return this},toggleClass:function(i,t){var o=typeof i,a="string"===o||Array.isArray(i);return"boolean"==typeof t&&a?t?this.addClass(i):this.removeClass(i):m(i)?this.each(function(e){S(this).toggleClass(i.call(this,e,yt(this),t),t)}):this.each(function(){var e,t,n,r;if(a){t=0,n=S(this),r=mt(i);while(e=r[t++])n.hasClass(e)?n.removeClass(e):n.addClass(e)}else void 0!==i&&"boolean"!==o||((e=yt(this))&&Y.set(this,"__className__",e),this.setAttribute&&this.setAttribute("class",e||!1===i?"":Y.get(this,"__className__")||""))})},hasClass:function(e){var t,n,r=0;t=" "+e+" ";while(n=this[r++])if(1===n.nodeType&&-1<(" "+vt(yt(n))+" ").indexOf(t))return!0;return!1}});var xt=/\r/g;S.fn.extend({val:function(n){var r,e,i,t=this[0];return arguments.length?(i=m(n),this.each(function(e){var t;1===this.nodeType&&(null==(t=i?n.call(this,e,S(this).val()):n)?t="":"number"==typeof t?t+="":Array.isArray(t)&&(t=S.map(t,function(e){return null==e?"":e+""})),(r=S.valHooks[this.type]||S.valHooks[this.nodeName.toLowerCase()])&&"set"in r&&void 0!==r.set(this,t,"value")||(this.value=t))})):t?(r=S.valHooks[t.type]||S.valHooks[t.nodeName.toLowerCase()])&&"get"in r&&void 0!==(e=r.get(t,"value"))?e:"string"==typeof(e=t.value)?e.replace(xt,""):null==e?"":e:void 0}}),S.extend({valHooks:{option:{get:function(e){var t=S.find.attr(e,"value");return null!=t?t:vt(S.text(e))}},select:{get:function(e){var t,n,r,i=e.options,o=e.selectedIndex,a="select-one"===e.type,s=a?null:[],u=a?o+1:i.length;for(r=o<0?u:a?o:0;r<u;r++)if(((n=i[r]).selected||r===o)&&!n.disabled&&(!n.parentNode.disabled||!A(n.parentNode,"optgroup"))){if(t=S(n).val(),a)return t;s.push(t)}return s},set:function(e,t){var n,r,i=e.options,o=S.makeArray(t),a=i.length;while(a--)((r=i[a]).selected=-1<S.inArray(S.valHooks.option.get(r),o))&&(n=!0);return n||(e.selectedIndex=-1),o}}}}),S.each(["radio","checkbox"],function(){S.valHooks[this]={set:function(e,t){if(Array.isArray(t))return e.checked=-1<S.inArray(S(e).val(),t)}},y.checkOn||(S.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})}),y.focusin="onfocusin"in C;var bt=/^(?:focusinfocus|focusoutblur)$/,wt=function(e){e.stopPropagation()};S.extend(S.event,{trigger:function(e,t,n,r){var i,o,a,s,u,l,c,f,p=[n||E],d=v.call(e,"type")?e.type:e,h=v.call(e,"namespace")?e.namespace.split("."):[];if(o=f=a=n=n||E,3!==n.nodeType&&8!==n.nodeType&&!bt.test(d+S.event.triggered)&&(-1<d.indexOf(".")&&(d=(h=d.split(".")).shift(),h.sort()),u=d.indexOf(":")<0&&"on"+d,(e=e[S.expando]?e:new S.Event(d,"object"==typeof e&&e)).isTrigger=r?2:3,e.namespace=h.join("."),e.rnamespace=e.namespace?new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,e.result=void 0,e.target||(e.target=n),t=null==t?[e]:S.makeArray(t,[e]),c=S.event.special[d]||{},r||!c.trigger||!1!==c.trigger.apply(n,t))){if(!r&&!c.noBubble&&!x(n)){for(s=c.delegateType||d,bt.test(s+d)||(o=o.parentNode);o;o=o.parentNode)p.push(o),a=o;a===(n.ownerDocument||E)&&p.push(a.defaultView||a.parentWindow||C)}i=0;while((o=p[i++])&&!e.isPropagationStopped())f=o,e.type=1<i?s:c.bindType||d,(l=(Y.get(o,"events")||Object.create(null))[e.type]&&Y.get(o,"handle"))&&l.apply(o,t),(l=u&&o[u])&&l.apply&&V(o)&&(e.result=l.apply(o,t),!1===e.result&&e.preventDefault());return e.type=d,r||e.isDefaultPrevented()||c._default&&!1!==c._default.apply(p.pop(),t)||!V(n)||u&&m(n[d])&&!x(n)&&((a=n[u])&&(n[u]=null),S.event.triggered=d,e.isPropagationStopped()&&f.addEventListener(d,wt),n[d](),e.isPropagationStopped()&&f.removeEventListener(d,wt),S.event.triggered=void 0,a&&(n[u]=a)),e.result}},simulate:function(e,t,n){var r=S.extend(new S.Event,n,{type:e,isSimulated:!0});S.event.trigger(r,null,t)}}),S.fn.extend({trigger:function(e,t){return this.each(function(){S.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];if(n)return S.event.trigger(e,t,n,!0)}}),y.focusin||S.each({focus:"focusin",blur:"focusout"},function(n,r){var i=function(e){S.event.simulate(r,e.target,S.event.fix(e))};S.event.special[r]={setup:function(){var e=this.ownerDocument||this.document||this,t=Y.access(e,r);t||e.addEventListener(n,i,!0),Y.access(e,r,(t||0)+1)},teardown:function(){var e=this.ownerDocument||this.document||this,t=Y.access(e,r)-1;t?Y.access(e,r,t):(e.removeEventListener(n,i,!0),Y.remove(e,r))}}});var Tt=C.location,Ct={guid:Date.now()},Et=/\?/;S.parseXML=function(e){var t;if(!e||"string"!=typeof e)return null;try{t=(new C.DOMParser).parseFromString(e,"text/xml")}catch(e){t=void 0}return t&&!t.getElementsByTagName("parsererror").length||S.error("Invalid XML: "+e),t};var St=/\[\]$/,kt=/\r?\n/g,At=/^(?:submit|button|image|reset|file)$/i,Nt=/^(?:input|select|textarea|keygen)/i;function Dt(n,e,r,i){var t;if(Array.isArray(e))S.each(e,function(e,t){r||St.test(n)?i(n,t):Dt(n+"["+("object"==typeof t&&null!=t?e:"")+"]",t,r,i)});else if(r||"object"!==w(e))i(n,e);else for(t in e)Dt(n+"["+t+"]",e[t],r,i)}S.param=function(e,t){var n,r=[],i=function(e,t){var n=m(t)?t():t;r[r.length]=encodeURIComponent(e)+"="+encodeURIComponent(null==n?"":n)};if(null==e)return"";if(Array.isArray(e)||e.jquery&&!S.isPlainObject(e))S.each(e,function(){i(this.name,this.value)});else for(n in e)Dt(n,e[n],t,i);return r.join("&")},S.fn.extend({serialize:function(){return S.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var e=S.prop(this,"elements");return e?S.makeArray(e):this}).filter(function(){var e=this.type;return this.name&&!S(this).is(":disabled")&&Nt.test(this.nodeName)&&!At.test(e)&&(this.checked||!pe.test(e))}).map(function(e,t){var n=S(this).val();return null==n?null:Array.isArray(n)?S.map(n,function(e){return{name:t.name,value:e.replace(kt,"\r\n")}}):{name:t.name,value:n.replace(kt,"\r\n")}}).get()}});var jt=/%20/g,qt=/#.*$/,Lt=/([?&])_=[^&]*/,Ht=/^(.*?):[ \t]*([^\r\n]*)$/gm,Ot=/^(?:GET|HEAD)$/,Pt=/^\/\//,Rt={},Mt={},It="*/".concat("*"),Wt=E.createElement("a");function Ft(o){return function(e,t){"string"!=typeof e&&(t=e,e="*");var n,r=0,i=e.toLowerCase().match(P)||[];if(m(t))while(n=i[r++])"+"===n[0]?(n=n.slice(1)||"*",(o[n]=o[n]||[]).unshift(t)):(o[n]=o[n]||[]).push(t)}}function Bt(t,i,o,a){var s={},u=t===Mt;function l(e){var r;return s[e]=!0,S.each(t[e]||[],function(e,t){var n=t(i,o,a);return"string"!=typeof n||u||s[n]?u?!(r=n):void 0:(i.dataTypes.unshift(n),l(n),!1)}),r}return l(i.dataTypes[0])||!s["*"]&&l("*")}function $t(e,t){var n,r,i=S.ajaxSettings.flatOptions||{};for(n in t)void 0!==t[n]&&((i[n]?e:r||(r={}))[n]=t[n]);return r&&S.extend(!0,e,r),e}Wt.href=Tt.href,S.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:Tt.href,type:"GET",isLocal:/^(?:about|app|app-storage|.+-extension|file|res|widget):$/.test(Tt.protocol),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":It,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/\bxml\b/,html:/\bhtml/,json:/\bjson\b/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":JSON.parse,"text xml":S.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?$t($t(e,S.ajaxSettings),t):$t(S.ajaxSettings,e)},ajaxPrefilter:Ft(Rt),ajaxTransport:Ft(Mt),ajax:function(e,t){"object"==typeof e&&(t=e,e=void 0),t=t||{};var c,f,p,n,d,r,h,g,i,o,v=S.ajaxSetup({},t),y=v.context||v,m=v.context&&(y.nodeType||y.jquery)?S(y):S.event,x=S.Deferred(),b=S.Callbacks("once memory"),w=v.statusCode||{},a={},s={},u="canceled",T={readyState:0,getResponseHeader:function(e){var t;if(h){if(!n){n={};while(t=Ht.exec(p))n[t[1].toLowerCase()+" "]=(n[t[1].toLowerCase()+" "]||[]).concat(t[2])}t=n[e.toLowerCase()+" "]}return null==t?null:t.join(", ")},getAllResponseHeaders:function(){return h?p:null},setRequestHeader:function(e,t){return null==h&&(e=s[e.toLowerCase()]=s[e.toLowerCase()]||e,a[e]=t),this},overrideMimeType:function(e){return null==h&&(v.mimeType=e),this},statusCode:function(e){var t;if(e)if(h)T.always(e[T.status]);else for(t in e)w[t]=[w[t],e[t]];return this},abort:function(e){var t=e||u;return c&&c.abort(t),l(0,t),this}};if(x.promise(T),v.url=((e||v.url||Tt.href)+"").replace(Pt,Tt.protocol+"//"),v.type=t.method||t.type||v.method||v.type,v.dataTypes=(v.dataType||"*").toLowerCase().match(P)||[""],null==v.crossDomain){r=E.createElement("a");try{r.href=v.url,r.href=r.href,v.crossDomain=Wt.protocol+"//"+Wt.host!=r.protocol+"//"+r.host}catch(e){v.crossDomain=!0}}if(v.data&&v.processData&&"string"!=typeof v.data&&(v.data=S.param(v.data,v.traditional)),Bt(Rt,v,t,T),h)return T;for(i in(g=S.event&&v.global)&&0==S.active++&&S.event.trigger("ajaxStart"),v.type=v.type.toUpperCase(),v.hasContent=!Ot.test(v.type),f=v.url.replace(qt,""),v.hasContent?v.data&&v.processData&&0===(v.contentType||"").indexOf("application/x-www-form-urlencoded")&&(v.data=v.data.replace(jt,"+")):(o=v.url.slice(f.length),v.data&&(v.processData||"string"==typeof v.data)&&(f+=(Et.test(f)?"&":"?")+v.data,delete v.data),!1===v.cache&&(f=f.replace(Lt,"$1"),o=(Et.test(f)?"&":"?")+"_="+Ct.guid+++o),v.url=f+o),v.ifModified&&(S.lastModified[f]&&T.setRequestHeader("If-Modified-Since",S.lastModified[f]),S.etag[f]&&T.setRequestHeader("If-None-Match",S.etag[f])),(v.data&&v.hasContent&&!1!==v.contentType||t.contentType)&&T.setRequestHeader("Content-Type",v.contentType),T.setRequestHeader("Accept",v.dataTypes[0]&&v.accepts[v.dataTypes[0]]?v.accepts[v.dataTypes[0]]+("*"!==v.dataTypes[0]?", "+It+"; q=0.01":""):v.accepts["*"]),v.headers)T.setRequestHeader(i,v.headers[i]);if(v.beforeSend&&(!1===v.beforeSend.call(y,T,v)||h))return T.abort();if(u="abort",b.add(v.complete),T.done(v.success),T.fail(v.error),c=Bt(Mt,v,t,T)){if(T.readyState=1,g&&m.trigger("ajaxSend",[T,v]),h)return T;v.async&&0<v.timeout&&(d=C.setTimeout(function(){T.abort("timeout")},v.timeout));try{h=!1,c.send(a,l)}catch(e){if(h)throw e;l(-1,e)}}else l(-1,"No Transport");function l(e,t,n,r){var i,o,a,s,u,l=t;h||(h=!0,d&&C.clearTimeout(d),c=void 0,p=r||"",T.readyState=0<e?4:0,i=200<=e&&e<300||304===e,n&&(s=function(e,t,n){var r,i,o,a,s=e.contents,u=e.dataTypes;while("*"===u[0])u.shift(),void 0===r&&(r=e.mimeType||t.getResponseHeader("Content-Type"));if(r)for(i in s)if(s[i]&&s[i].test(r)){u.unshift(i);break}if(u[0]in n)o=u[0];else{for(i in n){if(!u[0]||e.converters[i+" "+u[0]]){o=i;break}a||(a=i)}o=o||a}if(o)return o!==u[0]&&u.unshift(o),n[o]}(v,T,n)),!i&&-1<S.inArray("script",v.dataTypes)&&(v.converters["text script"]=function(){}),s=function(e,t,n,r){var i,o,a,s,u,l={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)l[a.toLowerCase()]=e.converters[a];o=c.shift();while(o)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!u&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),u=o,o=c.shift())if("*"===o)o=u;else if("*"!==u&&u!==o){if(!(a=l[u+" "+o]||l["* "+o]))for(i in l)if((s=i.split(" "))[1]===o&&(a=l[u+" "+s[0]]||l["* "+s[0]])){!0===a?a=l[i]:!0!==l[i]&&(o=s[0],c.unshift(s[1]));break}if(!0!==a)if(a&&e["throws"])t=a(t);else try{t=a(t)}catch(e){return{state:"parsererror",error:a?e:"No conversion from "+u+" to "+o}}}return{state:"success",data:t}}(v,s,T,i),i?(v.ifModified&&((u=T.getResponseHeader("Last-Modified"))&&(S.lastModified[f]=u),(u=T.getResponseHeader("etag"))&&(S.etag[f]=u)),204===e||"HEAD"===v.type?l="nocontent":304===e?l="notmodified":(l=s.state,o=s.data,i=!(a=s.error))):(a=l,!e&&l||(l="error",e<0&&(e=0))),T.status=e,T.statusText=(t||l)+"",i?x.resolveWith(y,[o,l,T]):x.rejectWith(y,[T,l,a]),T.statusCode(w),w=void 0,g&&m.trigger(i?"ajaxSuccess":"ajaxError",[T,v,i?o:a]),b.fireWith(y,[T,l]),g&&(m.trigger("ajaxComplete",[T,v]),--S.active||S.event.trigger("ajaxStop")))}return T},getJSON:function(e,t,n){return S.get(e,t,n,"json")},getScript:function(e,t){return S.get(e,void 0,t,"script")}}),S.each(["get","post"],function(e,i){S[i]=function(e,t,n,r){return m(t)&&(r=r||n,n=t,t=void 0),S.ajax(S.extend({url:e,type:i,dataType:r,data:t,success:n},S.isPlainObject(e)&&e))}}),S.ajaxPrefilter(function(e){var t;for(t in e.headers)"content-type"===t.toLowerCase()&&(e.contentType=e.headers[t]||"")}),S._evalUrl=function(e,t,n){return S.ajax({url:e,type:"GET",dataType:"script",cache:!0,async:!1,global:!1,converters:{"text script":function(){}},dataFilter:function(e){S.globalEval(e,t,n)}})},S.fn.extend({wrapAll:function(e){var t;return this[0]&&(m(e)&&(e=e.call(this[0])),t=S(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this},wrapInner:function(n){return m(n)?this.each(function(e){S(this).wrapInner(n.call(this,e))}):this.each(function(){var e=S(this),t=e.contents();t.length?t.wrapAll(n):e.append(n)})},wrap:function(t){var n=m(t);return this.each(function(e){S(this).wrapAll(n?t.call(this,e):t)})},unwrap:function(e){return this.parent(e).not("body").each(function(){S(this).replaceWith(this.childNodes)}),this}}),S.expr.pseudos.hidden=function(e){return!S.expr.pseudos.visible(e)},S.expr.pseudos.visible=function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)},S.ajaxSettings.xhr=function(){try{return new C.XMLHttpRequest}catch(e){}};var _t={0:200,1223:204},zt=S.ajaxSettings.xhr();y.cors=!!zt&&"withCredentials"in zt,y.ajax=zt=!!zt,S.ajaxTransport(function(i){var o,a;if(y.cors||zt&&!i.crossDomain)return{send:function(e,t){var n,r=i.xhr();if(r.open(i.type,i.url,i.async,i.username,i.password),i.xhrFields)for(n in i.xhrFields)r[n]=i.xhrFields[n];for(n in i.mimeType&&r.overrideMimeType&&r.overrideMimeType(i.mimeType),i.crossDomain||e["X-Requested-With"]||(e["X-Requested-With"]="XMLHttpRequest"),e)r.setRequestHeader(n,e[n]);o=function(e){return function(){o&&(o=a=r.onload=r.onerror=r.onabort=r.ontimeout=r.onreadystatechange=null,"abort"===e?r.abort():"error"===e?"number"!=typeof r.status?t(0,"error"):t(r.status,r.statusText):t(_t[r.status]||r.status,r.statusText,"text"!==(r.responseType||"text")||"string"!=typeof r.responseText?{binary:r.response}:{text:r.responseText},r.getAllResponseHeaders()))}},r.onload=o(),a=r.onerror=r.ontimeout=o("error"),void 0!==r.onabort?r.onabort=a:r.onreadystatechange=function(){4===r.readyState&&C.setTimeout(function(){o&&a()})},o=o("abort");try{r.send(i.hasContent&&i.data||null)}catch(e){if(o)throw e}},abort:function(){o&&o()}}}),S.ajaxPrefilter(function(e){e.crossDomain&&(e.contents.script=!1)}),S.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/\b(?:java|ecma)script\b/},converters:{"text script":function(e){return S.globalEval(e),e}}}),S.ajaxPrefilter("script",function(e){void 0===e.cache&&(e.cache=!1),e.crossDomain&&(e.type="GET")}),S.ajaxTransport("script",function(n){var r,i;if(n.crossDomain||n.scriptAttrs)return{send:function(e,t){r=S("<script>").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Ut,Xt=[],Vt=/(=)\?(?=&|$)|\?\?/;S.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Xt.pop()||S.expando+"_"+Ct.guid++;return this[e]=!0,e}}),S.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Vt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Vt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Vt,"$1"+r):!1!==e.jsonp&&(e.url+=(Et.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||S.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?S(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Xt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Ut=E.implementation.createHTMLDocument("").body).innerHTML="<form></form><form></form>",2===Ut.childNodes.length),S.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=N.exec(e))?[t.createElement(i[1])]:(i=xe([e],t,o),o&&o.length&&S(o).remove(),S.merge([],i.childNodes)));var r,i,o},S.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1<s&&(r=vt(e.slice(s)),e=e.slice(0,s)),m(t)?(n=t,t=void 0):t&&"object"==typeof t&&(i="POST"),0<a.length&&S.ajax({url:e,type:i||"GET",dataType:"html",data:t}).done(function(e){o=arguments,a.html(r?S("<div>").append(S.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},S.expr.pseudos.animated=function(t){return S.grep(S.timers,function(e){return t===e.elem}).length},S.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=S.css(e,"position"),c=S(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=S.css(e,"top"),u=S.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,S.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):("number"==typeof f.top&&(f.top+="px"),"number"==typeof f.left&&(f.left+="px"),c.css(f))}},S.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){S.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===S.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===S.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=S(e).offset()).top+=S.css(e,"borderTopWidth",!0),i.left+=S.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-S.css(r,"marginTop",!0),left:t.left-i.left-S.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===S.css(e,"position"))e=e.offsetParent;return e||re})}}),S.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;S.fn[t]=function(e){return $(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),S.each(["top","left"],function(e,n){S.cssHooks[n]=$e(y.pixelPosition,function(e,t){if(t)return t=Be(e,n),Me.test(t)?S(e).position()[n]+"px":t})}),S.each({Height:"height",Width:"width"},function(a,s){S.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){S.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return $(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?S.css(e,t,i):S.style(e,t,n,i)},s,n?e:void 0,n)}})}),S.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){S.fn[t]=function(e){return this.on(t,e)}}),S.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),S.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){S.fn[n]=function(e,t){return 0<arguments.length?this.on(n,null,e,t):this.trigger(n)}});var Gt=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;S.proxy=function(e,t){var n,r,i;if("string"==typeof t&&(n=e[t],t=e,e=n),m(e))return r=s.call(arguments,2),(i=function(){return e.apply(t||this,r.concat(s.call(arguments)))}).guid=e.guid=e.guid||S.guid++,i},S.holdReady=function(e){e?S.readyWait++:S.ready(!0)},S.isArray=Array.isArray,S.parseJSON=JSON.parse,S.nodeName=A,S.isFunction=m,S.isWindow=x,S.camelCase=X,S.type=w,S.now=Date.now,S.isNumeric=function(e){var t=S.type(e);return("number"===t||"string"===t)&&!isNaN(e-parseFloat(e))},S.trim=function(e){return null==e?"":(e+"").replace(Gt,"")},"function"==typeof define&&define.amd&&define("jquery",[],function(){return S});var Yt=C.jQuery,Qt=C.$;return S.noConflict=function(e){return C.$===S&&(C.$=Qt),e&&C.jQuery===S&&(C.jQuery=Yt),S},"undefined"==typeof e&&(C.jQuery=C.$=S),S}); \ No newline at end of file diff --git a/scripts/dice_label.sh b/scripts/dice_label.sh new file mode 100644 index 0000000..f19f8a4 --- /dev/null +++ b/scripts/dice_label.sh @@ -0,0 +1,20 @@ +mkdir -p images +mkdir -p images/orig +mkdir -p images/train +mkdir -p images/val + +ffmpeg -i Face1.mp4 images/orig/face1_%6d.jpg +ffmpeg -i Face2.mp4 images/orig/face2_%6d.jpg +ffmpeg -i Face3.mp4 images/orig/face3_%6d.jpg +ffmpeg -i Face4.mp4 images/orig/face4_%6d.jpg +ffmpeg -i Face5.mp4 images/orig/face5_%6d.jpg +ffmpeg -i Face6.mp4 images/orig/face6_%6d.jpg + +mogrify -resize 100x100^ -gravity center -crop 100x100+0+0 +repage images/orig/* + +ls images/orig/* | shuf | head -n 1000 | xargs mv -t images/val +mv images/orig/* images/train + +find `pwd`/images/train > dice.train.list -name \*.jpg +find `pwd`/images/val > dice.val.list -name \*.jpg + diff --git a/scripts/gen_tactic.sh b/scripts/gen_tactic.sh new file mode 100644 index 0000000..ffa30d2 --- /dev/null +++ b/scripts/gen_tactic.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Usage: +# wget http://pjreddie.com/media/files/peek.weights +# scripts/gen_tactic.sh < data/goal.txt +./darknet rnn generatetactic cfg/gru.cfg peek.weights 2>/dev/null diff --git a/scripts/get_coco_dataset.sh b/scripts/get_coco_dataset.sh new file mode 100644 index 0000000..2846301 --- /dev/null +++ b/scripts/get_coco_dataset.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Clone COCO API +git clone https://github.com/pdollar/coco +cd coco + +mkdir images +cd images + +# Download Images +wget -c https://pjreddie.com/media/files/train2014.zip +wget -c https://pjreddie.com/media/files/val2014.zip + +# Unzip +unzip -q train2014.zip +unzip -q val2014.zip + +cd .. + +# Download COCO Metadata +wget -c https://pjreddie.com/media/files/instances_train-val2014.zip +wget -c https://pjreddie.com/media/files/coco/5k.part +wget -c https://pjreddie.com/media/files/coco/trainvalno5k.part +wget -c https://pjreddie.com/media/files/coco/labels.tgz +tar xzf labels.tgz +unzip -q instances_train-val2014.zip + +# Set Up Image Lists +paste <(awk "{print \"$PWD\"}" <5k.part) 5k.part | tr -d '\t' > 5k.txt +paste <(awk "{print \"$PWD\"}" <trainvalno5k.part) trainvalno5k.part | tr -d '\t' > trainvalno5k.txt + diff --git a/scripts/imagenet_label.sh b/scripts/imagenet_label.sh new file mode 100644 index 0000000..01e4306 --- /dev/null +++ b/scripts/imagenet_label.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +mkdir -p labelled +wd=`pwd` + +for f in val/*.xml; +do +label=`grep -m1 "<name>" $f | grep -oP '<name>\K[^<]*'` +im=`echo $f | sed 's/val/imgs/; s/xml/JPEG/'` +out=`echo $im | sed 's/JPEG/'${label}'.JPEG/; s/imgs/labelled/'` +ln -s ${wd}/$im ${wd}/$out +done + +find ${wd}/labelled -name \*.JPEG > inet.val.list + diff --git a/scripts/voc_label.py b/scripts/voc_label.py new file mode 100644 index 0000000..679fc36 --- /dev/null +++ b/scripts/voc_label.py @@ -0,0 +1,59 @@ +import xml.etree.ElementTree as ET +import pickle +import os +from os import listdir, getcwd +from os.path import join + +sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')] + +classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"] + + +def convert(size, box): + dw = 1./(size[0]) + dh = 1./(size[1]) + x = (box[0] + box[1])/2.0 - 1 + y = (box[2] + box[3])/2.0 - 1 + w = box[1] - box[0] + h = box[3] - box[2] + x = x*dw + w = w*dw + y = y*dh + h = h*dh + return (x,y,w,h) + +def convert_annotation(year, image_id): + in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id)) + out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w') + tree=ET.parse(in_file) + root = tree.getroot() + size = root.find('size') + w = int(size.find('width').text) + h = int(size.find('height').text) + + for obj in root.iter('object'): + difficult = obj.find('difficult').text + cls = obj.find('name').text + if cls not in classes or int(difficult)==1: + continue + cls_id = classes.index(cls) + xmlbox = obj.find('bndbox') + b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text)) + bb = convert((w,h), b) + out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') + +wd = getcwd() + +for year, image_set in sets: + if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)): + os.makedirs('VOCdevkit/VOC%s/labels/'%(year)) + image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split() + list_file = open('%s_%s.txt'%(year, image_set), 'w') + for image_id in image_ids: + list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id)) + convert_annotation(year, image_id) + list_file.close() + +os.system("cat 2007_train.txt 2007_val.txt 2012_train.txt 2012_val.txt > train.txt") +os.system("cat 2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt > train.all.txt") + diff --git a/srbc/config.json b/srbc/config.json new file mode 100644 index 0000000..cab2b90 --- /dev/null +++ b/srbc/config.json @@ -0,0 +1,467 @@ +{ + "ai_server": { + "ip": "127.0.0.1", + "http_port": "8592", + "video_port": "8591" + }, + "view_setting": { + "camera01": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_Human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "0", + "confidence3": "80", + "confidence4": "80", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "car,bus,truck", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 141, + "y1": 257, + "x2": 635, + "y2": 255, + "x3": 729, + "y3": 411, + "x4": 10, + "y4": 409 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + } + }, + "system_setting": { + "AI dataset": "", + "dataset category": "Traffic", + "snapshot folder": "D:\\", + "language": "English", + "enable log": "No", + "auto reconnect": "No", + "enable watchdog": "No", + "enable watchdog UI": "No", + "cpu usage limit": "80", + "display OSD": "Yes", + "display dash": "No", + "display properties": "Yes", + "display tracking ID": "Yes", + "overlap thresh": 70, + "confidence thresh": 0, + "cnn type": "CUDA", + "cnn device1": "GPU", + "cnn device2": "GPU", + "cnn device3": "GPU", + "cnn device4": "GPU", + "cnn device5": "GPU", + "cnn device6": "GPU", + "cnn device7": "GPU", + "cnn device8": "GPU" + }, + "about_box": { + "dataset version": "", + "software version": "1.0.5.79", + "system id": "04-D9-F5-BA-4A-CC", + "NIC name": "AӺ", + "unlocking key": "vO41GPyfGu/VhX5VYvmmYk1w+jmPit/Z3AI2GyNf2dE/jcR9lMwkYDUtfR0uemV9Ko/RkhW6IJ9xr+YtjQyu3MbyAFtD5J94iVTHdrCPS78=" + } +} diff --git a/srbc/config_b.json b/srbc/config_b.json new file mode 100644 index 0000000..d75e5aa --- /dev/null +++ b/srbc/config_b.json @@ -0,0 +1,2117 @@ +{ + "ai_server": { + "ip": "127.0.0.1", + "http_port": "8592", + "video_port": "8591" + }, + "view_setting": { + "camera01": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_Human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "0", + "confidence3": "80", + "confidence4": "80", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "car,bus,truck", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 141, + "y1": 257, + "x2": 635, + "y2": 255, + "x3": 729, + "y3": 411, + "x4": 10, + "y4": 409 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera02": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera03": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera04": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera05": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera06": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera07": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera08": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera09": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera10": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera11": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera12": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera13": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera14": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera15": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera16": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + } + }, + "system_setting": { + "AI dataset": "", + "dataset category": "Traffic", + "snapshot folder": "D:\\", + "language": "English", + "enable log": "No", + "auto reconnect": "No", + "enable watchdog": "No", + "enable watchdog UI": "No", + "cpu usage limit": "80", + "display OSD": "Yes", + "display dash": "No", + "display properties": "Yes", + "display tracking ID": "Yes", + "overlap thresh": 70, + "confidence thresh": 0, + "cnn type": "CUDA", + "cnn device1": "GPU", + "cnn device2": "GPU", + "cnn device3": "GPU", + "cnn device4": "GPU", + "cnn device5": "GPU", + "cnn device6": "GPU", + "cnn device7": "GPU", + "cnn device8": "GPU" + }, + "about_box": { + "dataset version": "", + "software version": "1.0.5.79", + "system id": "04-D9-F5-BA-4A-CC", + "NIC name": "AӺ", + "unlocking key": "vO41GPyfGu/VhX5VYvmmYk1w+jmPit/Z3AI2GyNf2dE/jcR9lMwkYDUtfR0uemV9Ko/RkhW6IJ9xr+YtjQyu3MbyAFtD5J94iVTHdrCPS78=" + } +} diff --git a/srbc/config_bak.json b/srbc/config_bak.json new file mode 100644 index 0000000..cab2b90 --- /dev/null +++ b/srbc/config_bak.json @@ -0,0 +1,467 @@ +{ + "ai_server": { + "ip": "127.0.0.1", + "http_port": "8592", + "video_port": "8591" + }, + "view_setting": { + "camera01": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_Human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "0", + "confidence3": "80", + "confidence4": "80", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "car,bus,truck", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 141, + "y1": 257, + "x2": 635, + "y2": 255, + "x3": 729, + "y3": 411, + "x4": 10, + "y4": 409 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + } + }, + "system_setting": { + "AI dataset": "", + "dataset category": "Traffic", + "snapshot folder": "D:\\", + "language": "English", + "enable log": "No", + "auto reconnect": "No", + "enable watchdog": "No", + "enable watchdog UI": "No", + "cpu usage limit": "80", + "display OSD": "Yes", + "display dash": "No", + "display properties": "Yes", + "display tracking ID": "Yes", + "overlap thresh": 70, + "confidence thresh": 0, + "cnn type": "CUDA", + "cnn device1": "GPU", + "cnn device2": "GPU", + "cnn device3": "GPU", + "cnn device4": "GPU", + "cnn device5": "GPU", + "cnn device6": "GPU", + "cnn device7": "GPU", + "cnn device8": "GPU" + }, + "about_box": { + "dataset version": "", + "software version": "1.0.5.79", + "system id": "04-D9-F5-BA-4A-CC", + "NIC name": "AӺ", + "unlocking key": "vO41GPyfGu/VhX5VYvmmYk1w+jmPit/Z3AI2GyNf2dE/jcR9lMwkYDUtfR0uemV9Ko/RkhW6IJ9xr+YtjQyu3MbyAFtD5J94iVTHdrCPS78=" + } +} diff --git a/srbc/config_bak_b.json b/srbc/config_bak_b.json new file mode 100644 index 0000000..d75e5aa --- /dev/null +++ b/srbc/config_bak_b.json @@ -0,0 +1,2117 @@ +{ + "ai_server": { + "ip": "127.0.0.1", + "http_port": "8592", + "video_port": "8591" + }, + "view_setting": { + "camera01": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_Human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "0", + "confidence3": "80", + "confidence4": "80", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "car,bus,truck", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 141, + "y1": 257, + "x2": 635, + "y2": 255, + "x3": 729, + "y3": 411, + "x4": 10, + "y4": 409 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera02": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera03": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera04": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera05": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera06": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera07": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera08": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera09": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera10": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera11": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera12": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera13": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera14": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera15": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera16": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + } + }, + "system_setting": { + "AI dataset": "", + "dataset category": "Traffic", + "snapshot folder": "D:\\", + "language": "English", + "enable log": "No", + "auto reconnect": "No", + "enable watchdog": "No", + "enable watchdog UI": "No", + "cpu usage limit": "80", + "display OSD": "Yes", + "display dash": "No", + "display properties": "Yes", + "display tracking ID": "Yes", + "overlap thresh": 70, + "confidence thresh": 0, + "cnn type": "CUDA", + "cnn device1": "GPU", + "cnn device2": "GPU", + "cnn device3": "GPU", + "cnn device4": "GPU", + "cnn device5": "GPU", + "cnn device6": "GPU", + "cnn device7": "GPU", + "cnn device8": "GPU" + }, + "about_box": { + "dataset version": "", + "software version": "1.0.5.79", + "system id": "04-D9-F5-BA-4A-CC", + "NIC name": "AӺ", + "unlocking key": "vO41GPyfGu/VhX5VYvmmYk1w+jmPit/Z3AI2GyNf2dE/jcR9lMwkYDUtfR0uemV9Ko/RkhW6IJ9xr+YtjQyu3MbyAFtD5J94iVTHdrCPS78=" + } +} diff --git a/src/ColorDetector.cpp b/src/ColorDetector.cpp new file mode 100644 index 0000000..d6fd57d --- /dev/null +++ b/src/ColorDetector.cpp @@ -0,0 +1,643 @@ + +#include "ColorDetector.hpp" +#include "ColorDetectorC.h" +#include "utility.h" + +using namespace cv; +using namespace std; + +//extern pthread_mutex_t mutex_color_detect; + +ColorRange ColorCategory[COLOR_CATEGORY_NUM] = +{ + { 1, "Red", 0, 10, 70, 255, 86, 200 }, + { 1, "Red", 156, 180, 70, 255, 86, 200 }, + { 3, "Yellow", 11, 34, 70, 255, 86, 200 }, + //{ 3, "Yellow", 11, 34, 43, 255, 56, 200 }, + { 4, "Green", 35, 99, 43, 255, 86, 200 }, + //{ "blue", 100, 124, 43, 255, 46, 255 }, + //{ "purple", 125, 155, 43, 255, 46, 255 } }; + { 5, "Blue", 100, 124, 70, 255, 86, 200 }, + { 7, "Purple", 125, 155, 70, 255, 86, 200 }, + { 8, "Black", 0, 180, 0, 255, 0, 75 }, + { 9, "White", 0, 180, 0, 70, 200, 255 }, + //{ 9, "White", 0, 180, 0, 43, 205, 255 }, + { 11, "Darkgray", 0, 180, 0, 70, 76, 128 }, + { 10, "Silver", 0, 180, 0, 70, 129, 200 } +}; + + +void InRangeColorSummary(IplImage rgbImage, ColorArray colorCountArray[]) +{ + IplImage* hsvImg = cvCreateImage(cvSize(rgbImage.width, rgbImage.height), rgbImage.depth, rgbImage.nChannels); //cvGetSize will cause exception, more C API will not support. + if (rgbImage.width <= 0 || rgbImage.height <= 0) + return; + cvCvtColor(&rgbImage, hsvImg, CV_BGR2HSV); + IplImage* h_img = cvCreateImage(cvSize(rgbImage.width, rgbImage.height), rgbImage.depth, 1); + IplImage* s_img = cvCreateImage(cvSize(rgbImage.width, rgbImage.height), rgbImage.depth, 1); + IplImage* v_img = cvCreateImage(cvSize(rgbImage.width, rgbImage.height), rgbImage.depth, 1); + + cvSplit(hsvImg, h_img, s_img, v_img, NULL); + + //printf("\n***********h_img->height:%d,h_img->width:%d\n", h_img->height, h_img->width); + + for (int i = h_img->height*4/10; i < h_img->height*6/10; i += HSVIMAGE_ROWS) + { + for (int j = h_img->width*4/10; j < h_img->width*6/10; j += HSVIMAGE_COLS) //scan every pixels + { + for (int k = 0; k < COLOR_CATEGORY_NUM; k++) + { + + if( (cvGetReal2D(h_img, i, j) >= ColorCategory[k].h_min && cvGetReal2D(h_img, i, j) <= ColorCategory[k].h_max) && + (cvGetReal2D(s_img, i, j) >= ColorCategory[k].s_min && cvGetReal2D(s_img, i, j) <= ColorCategory[k].s_max) && + (cvGetReal2D(v_img, i, j) >= ColorCategory[k].v_min && cvGetReal2D(v_img, i, j) <= ColorCategory[k].v_max)) + { + colorCountArray[k].colorCount++; + break; + } + } + } + } + + for (int k = 0; k < COLOR_CATEGORY_NUM; k++) + { + colorCountArray[k].colorCategoryidx = k; + } + + cvReleaseImage(&hsvImg); + cvReleaseImage(&h_img); + cvReleaseImage(&s_img); + cvReleaseImage(&v_img); +} + +bool sort_color_count(ColorArray a, ColorArray b) +{ + return (a.colorCount > b.colorCount) ? true : false; +} + +int SaveRawRGBToChar(char *output_image, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, int __element_interleaved__) // For normal type +{ + Mat tempImg_snaphd; + char* img_buf_snap_hd = NULL; + + //printf("\nTTTTTTTT:1\n"); + img_buf_snap_hd = new char[__width__ * __height__ * 3]; // RGB 3 channels + //printf("\nTTTTTTTT:2\n"); + if (__element_interleaved__ == 0) + { + int i = 0, j = 0; + for (i = 0; i < __height__; i++) + { + for (j = 0; j < __width__; j++) + { + + // Using the array transposition. + img_buf_snap_hd[i * __width__ * 3 + j * 3] = __input_rgb_array__[i * __pitch__ + j + __pitch__ * __height__ * 2]; // Blue + img_buf_snap_hd[i * __width__ * 3 + j * 3 + 1] = __input_rgb_array__[i * __pitch__ + j + __pitch__ * __height__]; // Green + img_buf_snap_hd[i * __width__ * 3 + j * 3 + 2] = __input_rgb_array__[i * __pitch__ + j]; // Red + //printf("img_buf_snap_hd(%d, %d)=(%d, %d, %d)\n", i, j, img_buf_snap_hd[i * __width__ * 3 + j * 3], img_buf_snap_hd[i * __width__ * 3 + j * 3 + 1], img_buf_snap_hd[i * __width__ * 3 + j * 3 + 2]); + } + } + + tempImg_snaphd = Mat(__height__, __width__, CV_8UC3, img_buf_snap_hd); // Directly assign the array to the source of the Mat. + } + else + { + tempImg_snaphd = Mat(__height__, __pitch__, CV_8UC3, __input_rgb_array__); + } + //printf("\nTTTTTTTT:3\n"); + vector<uchar> data_encode; + imencode(".jpeg", tempImg_snaphd, data_encode); + + string str_encode(data_encode.begin(),data_encode.end()); + + int length = (int)str_encode.length(); + + memcpy(output_image, str_encode.c_str(), length); + + vector<uchar>().swap(data_encode); + delete(img_buf_snap_hd); + tempImg_snaphd.release(); + //printf("\nTTTTTTTT:4\n"); + return length; +} + +//static int Table_fv1_color[256] = { -180, -179, -177, -176, -174, -173, -172, -170, -169, -167, -166, -165, -163, -162, -160, -159, -158, -156, -155, -153, -152, -151, -149, -148, -146, -145, -144, -142, -141, -139, -138, -137, -135, -134, -132, -131, -130, -128, -127, -125, -124, -123, -121, -120, -118, -117, -115, -114, -113, -111, -110, -108, -107, -106, -104, -103, -101, -100, -99, -97, -96, -94, -93, -92, -90, -89, -87, -86, -85, -83, -82, -80, -79, -78, -76, -75, -73, -72, -71, -69, -68, -66, -65, -64,-62, -61, -59, -58, -57, -55, -54, -52, -51, -50, -48, -47, -45, -44, -43, -41, -40, -38, -37, -36, -34, -33, -31, -30, -29, -27, -26, -24, -23, -22, -20, -19, -17, -16, -15, -13, -12, -10, -9, -8, -6, -5, -3, -2, 0, 1, 2, 4, 5, 7, 8, 9, 11, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25, 26, 28, 29, 30, 32, 33, 35, 36, 37, 39, 40, 42, 43, 44, 46, 47, 49, 50, 51, 53, 54, 56, 57, 58, 60, 61, 63, 64, 65, 67, 68, 70, 71, 72, 74, 75, 77, 78, 79, 81, 82, 84, 85, 86, 88, 89, 91, 92, 93, 95, 96, 98, 99, 100, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 124, 126, 127, 129, 130, 131, 133, 134, 136, 137, 138, 140, 141, 143, 144, 145, 147, 148, 150, 151, 152, 154, 155, 157, 158, 159, 161, 162, 164, 165, 166, 168, 169, 171, 172, 173, 175, 176, 178 }; +//static int Table_fv2_color[256] = { -92, -91, -91, -90, -89, -88, -88, -87, -86, -86, -85, -84, -83, -83, -82, -81, -81, -80, -79, -78, -78, -77, -76, -76, -75, -74, -73, -73, -72, -71, -71, -70, -69, -68, -68, -67, -66, -66, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55, -54, -53, -53, -52, -51, -51, -50, -49, -48, -48, -47, -46, -46, -45, -44, -43, -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, -33, -32, -31, -31, -30, -29, -28, -28, -27, -26, -26, -25, -24, -23, -23, -22, -21, -21, -20, -19, -18, -18, -17, -16, -16, -15, -14, -13, -13, -12, -11, -11, -10, -9, -8, -8, -7, -6, -6, -5, -4, -3, -3, -2, -1, 0, 0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 22, 23, 24, 25, 25, 26, 27, 27, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 37, 38, 39, 40, 40, 41, 42, 42, 43, 44, 45, 45, 46, 47, 47, 48, 49, 50, 50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 62, 63, 64, 65, 65, 66, 67, 67, 68, 69, 70, 70, 71, 72, 72, 73, 74, 75, 75, 76, 77, 77, 78, 79, 80, 80, 81, 82, 82, 83, 84, 85, 85, 86, 87, 87, 88, 89, 90, 90 }; +//static int Table_fu1_color[256] = { -44, -44, -44, -43, -43, -43, -42, -42, -42, -41, -41, -41, -40, -40, -40, -39, -39, -39, -38, -38, -38, -37, -37, -37, -36, -36, -36, -35, -35, -35, -34, -34, -33, -33, -33, -32, -32, -32, -31, -31, -31, -30, -30, -30, -29, -29, -29, -28, -28, -28, -27, -27, -27, -26, -26, -26, -25, -25, -25, -24, -24, -24, -23, -23, -22, -22, -22, -21, -21, -21, -20, -20, -20, -19, -19, -19, -18, -18, -18, -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -11, -11, -11, -10, -10, -10, -9, -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -6, -5, -5, -5, -4, -4, -4, -3, -3, -3, -2, -2, -2, -1, -1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, 43, 43 }; +//static int Table_fu2_color[256] = { -227, -226, -224, -222, -220, -219, -217, -215, -213, -212, -210, -208, -206, -204, -203, -201, -199, -197, -196, -194, -192, -190, -188, -187, -185, -183, -181, -180, -178, -176, -174, -173, -171, -169, -167, -165, -164, -162, -160, -158, -157, -155, -153, -151, -149, -148, -146, -144, -142, -141, -139, -137, -135, -134, -132, -130, -128, -126, -125, -123, -121, -119, -118, -116, -114, -112, -110, -109, -107, -105, -103, -102, -100, -98, -96, -94, -93, -91, -89, -87, -86, -84, -82, -80, -79, -77, -75, -73, -71, -70, -68, -66, -64, -63, -61, -59, -57, -55, -54, -52, -50, -48, -47, -45, -43, -41, -40, -38, -36, -34, -32, -31, -29, -27, -25, -24, -22, -20, -18, -16, -15, -13, -11, -9, -8, -6, -4, -2, 0, 1, 3, 5, 7, 8, 10, 12, 14, 15, 17, 19, 21, 23, 24, 26, 28, 30, 31, 33, 35, 37, 39, 40, 42, 44, 46, 47, 49, 51, 53, 54, 56, 58, 60, 62, 63, 65, 67, 69, 70, 72, 74, 76, 78, 79, 81, 83, 85, 86, 88, 90, 92, 93, 95, 97, 99, 101, 102, 104, 106, 108, 109, 111, 113, 115, 117, 118, 120, 122, 124, 125, 127, 129, 131, 133, 134, 136, 138, 140, 141, 143, 145, 147, 148, 150, 152, 154, 156, 157, 159, 161, 163, 164, 166, 168, 170, 172, 173, 175, 177, 179, 180, 182, 184, 186, 187, 189, 191, 193, 195, 196, 198, 200, 202, 203, 205, 207, 209, 211, 212, 214, 216, 218, 219, 221, 223, 225 }; + + +void SaveRawYUVToRGB_JPG(char *read_filename,char* __image_name__, int __size__,int __width__, int __height__) // For normal type +{ + unsigned char DecryptData[1280 * 720 * 3 / 2] = { 0 }; + + FILE *ptr; + ptr = fopen(read_filename, "rb"); // r for read, b for binary + if (ptr) { + fread(DecryptData, sizeof(DecryptData), 1, ptr); // read 10 bytes to our buffer + } + if (ptr) { + fclose(ptr); + ptr = NULL; + } + + + Mat cv_img; + Mat cv_yuv(__height__+ __height__/2, __width__,CV_8UC1, DecryptData); + //cv_img = Mat(__height__, __width__,CV_8UC3); + cvtColor(cv_yuv, cv_img,COLOR_YUV2RGB_NV21); + + imwrite(__image_name__, cv_img); + cv_img.release(); + cv_yuv.release(); + + //vector<uchar> vector_uchar(DecryptData, DecryptData + __width__ * __height__ * 3 / 2); + //img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + + + //vector_uchar.clear(); + //vector<uchar>().swap(vector_uchar); + //img_decode.release(); + + + + + /* + Mat img = imread(read_filename); + Mat img_color; + printf("\n-------channel:%d\n",img.channels()); + + + + cvtColor(img, img_color, CV_YUV2RGB_NV12); + printf("\n-------channel img_color:%d\n", img_color.channels()); + imwrite(__image_name__, img_color); + + img_color.release(); + img.release();*/ + + //const int width = 1280; + //const int height = 800; + /* + fstream file_in; + file_in.open(read_filename, ios::binary); + filebuf *p_filebuf = file_in.rdbuf(); + size_t size = p_filebuf->pubseekoff(0, ios::end, ios::in); + p_filebuf->pubseekpos(0, ios::in); + + char *buf_src = new char[size]; + p_filebuf->sgetn(buf_src, size); + + Mat mat_src = Mat(__height__*1.5, __width__, CV_8UC1, buf_src); + Mat mat_dst = Mat(__height__, __width__, CV_8UC3); + + cvtColor(mat_src, mat_dst, cv::COLOR_YUV2BGR_NV21); + imwrite(__image_name__, mat_dst); + + file_in.close(); + delete[]buf_src; + + mat_src.release(); + mat_dst.release();*/ + + + +#if 0 + Mat tempImg; + + char* img_buf = new char[__width__ * __height__ * 3]; // RGB 3 channels + + long len_image = __width__ * __height__; + char * yData = __input_yuv_array__; + char * vData = __input_yuv_array__ + len_image; + char * uData = __input_yuv_array__ + len_image; + + int i = 0, j = 0; + + int bgr_pixel[3]; + int yIdx, uIdx, vIdx, idx; + int rdif, invgdif, bdif; + + for (i = 0; i < __height__; i++) + { + for (j = 0; j < __width__; j++) + { + //yIdx = i * __width__ + j; + //uIdx = (i / 2) * (__width__ / 2) + (j / 2); + //vIdx = uIdx + 1; + //printf("\n------------%d,%d,%d\n", yData[yIdx], vData[vIdx], uData[uIdx]); + + + yIdx = i * __width__ + j; + vIdx = (i / 2) * (__width__ / 2) + (j / 2); + uIdx = vIdx; + + rdif = Table_fv1_color[vData[vIdx]]; + invgdif = Table_fu1_color[uData[uIdx]] + Table_fv2_color[vData[vIdx]]; + bdif = Table_fu2_color[uData[uIdx]]; + + bgr_pixel[0] = yData[yIdx] + bdif; + bgr_pixel[1] = yData[yIdx] - invgdif; + bgr_pixel[2] = yData[yIdx] + rdif; + + //printf("\n------------%d,%d,%d\n", bgr_pixel[0], bgr_pixel[1], bgr_pixel[2]); + + for (int k = 0; k < 3; k++) { + idx = (i*__width__ + j) * 3 + k; + if (bgr_pixel[k] >= 0 && bgr_pixel[k] <= 255) { + img_buf[idx] = bgr_pixel[k]; + } + else { + img_buf[idx] = (bgr_pixel[k] < 0) ? 0 : 255; + } + } + + // Using the array transposition. + //img_buf[i * __width__ * 3 + j * 3] = __input_yuv_array__[i * __pitch__ + j + __pitch__ * __height__ * 2]; // Blue + //img_buf[i * __width__ * 3 + j * 3 + 1] = __input_yuv_array__[i * __pitch__ + j + __pitch__ * __height__]; // Green + //img_buf[i * __width__ * 3 + j * 3 + 2] = __input_yuv_array__[i * __width__ + j]; // Red + //printf("img_buf(%d, %d)=(%d, %d, %d)\n", i, j, img_buf[i * __width__ * 3 + j * 3], img_buf[i * __width__ * 3 + j * 3 + 1], img_buf[i * __width__ * 3 + j * 3 + 2]); + } + } + + tempImg = Mat(__height__, __width__, CV_8UC3, img_buf); // Directly assign the array to the source of the Mat. + + imwrite(__image_name__, tempImg); + delete(img_buf); + tempImg.release(); + + /* + Mat yuvImg; + Mat rgbImg(__height__, __width__,CV_8UC3); + + yuvImg.create(__height__*3/2, __width__,CV_8UC1); + memcpy(yuvImg.data, __input_yuv_array__, __size__); + + cvtColor(yuvImg, rgbImg, COLOR_YUV2RGB_I420); + imwrite(__image_name__,rgbImg); + + rgbImg.release(); + yuvImg.release(); + */ + +#endif +} + +void SaveRawRGBToJPG(char* __image_name__, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, int __element_interleaved__) // For normal type +{ + Mat tempImg; + //clock_t cputime0 = clock(); + char* img_buf = new char[__width__ * __height__ * 3]; // RGB 3 channels + + if (__element_interleaved__ == 0) + { + //tempImg = Mat(cvSize(__width__, __height__), CV_8UC3); + + int i = 0, j = 0; + for (i = 0; i < __height__; i++) + { + for (j = 0; j < __width__; j++) + { + // Using the structure. (Deprecated) + /*try + { + Vec3b& color = tempImg.at<Vec3b>(i, j); // Get the reference of the pixel + color[2] = __input_rgb_array__[i * __pitch__ + j]; // Red + color[1] = __input_rgb_array__[i * __pitch__ + j + __pitch__ * __height__]; // Green + color[0] = __input_rgb_array__[i * __pitch__ + j + __pitch__ * __height__ * 2]; // Blue + //printf("RGB(%d, %d)=(%d, %d, %d)\n", i, j, color[2], color[1], color[0]); + } + catch (Exception& reason) + { + printf("Exception reason: %s\n", reason.what()); + }*/ + + // Using the array transposition. + img_buf[i * __width__ * 3 + j * 3] = __input_rgb_array__[i * __pitch__ + j + __pitch__ * __height__ * 2]; // Blue + img_buf[i * __width__ * 3 + j * 3 + 1] = __input_rgb_array__[i * __pitch__ + j + __pitch__ * __height__]; // Green + img_buf[i * __width__ * 3 + j * 3 + 2] = __input_rgb_array__[i * __pitch__ + j]; // Red + //printf("img_buf(%d, %d)=(%d, %d, %d)\n", i, j, img_buf[i * __width__ * 3 + j * 3], img_buf[i * __width__ * 3 + j * 3 + 1], img_buf[i * __width__ * 3 + j * 3 + 2]); + } + } + + tempImg = Mat(__height__, __width__, CV_8UC3, img_buf); // Directly assign the array to the source of the Mat. + } + else + { + tempImg = Mat(__height__, __pitch__, CV_8UC3, __input_rgb_array__); + } + + //printf("[SaveRawRGBToJPG] imwrite disabled.\n"); + imwrite(__image_name__, tempImg); + //clock_t cputime1 = clock(); + //printf("[SaveRawRGBToJPG] Save raw RGB to Mat: %lf seconds (%d/%d clocks).\n", ((float)(cputime1-cputime0)/(float)CLOCKS_PER_SEC), (int)(cputime1-cputime0), (int)CLOCKS_PER_SEC); + delete(img_buf); + + //printf("[SaveRawRGBToJPG] Save raw RGB to Mat: %lf seconds (%d/%d clocks).\n", ((float)(cputime1 - cputime0) / (float)CLOCKS_PER_SEC), (int)cputime0, (int)cputime1); + //printf("[SaveRawRGBToJPG] Save raw RGB to Mat: %lf seconds (%d/%d clocks).\n", ((float)(cputime1 - cputime0) / (float)CLOCKS_PER_SEC), (int)(cputime1 - cputime0), (int)CLOCKS_PER_SEC); + tempImg.release(); +} + +int AssignObjectColorForAmba(detection_pos* current_detection_info, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, ColorDetectionType color_detection_type, int __element_interleaved__) +{ + + //pthread_mutex_lock(&mutex_color_detect); + + //printf("\n------------------[Assign Object Color For Amba]----------------------start\n"); + + int i_object_width = __width__; + int i_object_pitch = __pitch__; + int i_object_height = __height__; + + if (IsANPRCategory(current_detection_info->engine_type) && current_detection_info->obj_type == _PLATE) + { + ColorCategory[8].color_id = 7; + ColorCategory[9].color_id = 7; + ColorCategory[6].color_id = 7; + } + + + //printf("\ni_object_height: %d\n", i_object_height); + //printf("\ni_object_width: %d\n", i_object_width);*/ + + + Mat tempImg; + //clock_t cputime0 = clock(); + char* img_buf = new char[i_object_width * i_object_height * 3]; // RGB 3 channels + + if (__element_interleaved__ == 0) + { + //tempImg = Mat(cvSize(i_object_width, i_object_height), CV_8UC3); + + int i = 0, j = 0; + for (i = 0; i < i_object_height; i++) + { + for (j = 0; j < i_object_width; j++) + { + try + { + /*Vec3b& color = tempImg.at<Vec3b>(i, j); // Get the reference of the pixel + color[2] = __input_rgb_array__[i * i_object_pitch + j]; // Red + color[1] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height]; // Green + color[0] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height * 2]; // Blue*/ + //tempImg.at<Vec3b>(j, i) = color; // Write back if not using the reference. + //printf("RGB(%d, %d)=(%d, %d, %d)\n", j, i, color[2], color[1], color[0]); + + // Using the array transposition. + img_buf[i * i_object_width * 3 + j * 3] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height * 2]; // Blue + img_buf[i * i_object_width * 3 + j * 3 + 1] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height]; // Green + img_buf[i * i_object_width * 3 + j * 3 + 2] = __input_rgb_array__[i * i_object_pitch + j]; // Red + //printf("img_buf(%d, %d)=(%d, %d, %d)\n", i, j, img_buf[i * i_object_width * 3 + j * 3], img_buf[i * i_object_width * 3 + j * 3 + 1], img_buf[i * i_object_width * 3 + j * 3 + 2]); + } + catch (Exception& reason) + { + printf("Exception reason: %s\n", reason.what()); + } + } + } + + tempImg = Mat(i_object_height, i_object_width, CV_8UC3, img_buf); // Directly assign the array to the source of the Mat. + } + else + { + i_object_width = __width__; + i_object_pitch = __pitch__; + i_object_height = __height__; + tempImg = Mat(i_object_height, i_object_pitch, CV_8UC3, __input_rgb_array__); + + } + + IplImage Ipl_tempImg = IplImage(tempImg); + + //clock_t cputime1 = clock(); + //printf("[AssignObjectColorForAmba] Transform RGB array to Mat in %lf seconds (%d/%d clocks).\n", ((float)(cputime1-cputime0)/(float)CLOCKS_PER_SEC), (int)(cputime1-cputime0), (int)CLOCKS_PER_SEC); + + /*if (color_detection_type == _DEFAULT_COLOR) + { + if (current_detection_info->engine_type & FEATURE_TRAF_DET) + color_detection_type = _TRAFFIC_COLOR; + else if (IsANPRCategory(current_detection_info->engine_type) && current_detection_info->obj_type == _PLATE) + color_detection_type = _PLATE_COLOR; + else + color_detection_type = _NORMAL_COLOR; + }*/ + + ColorArray ColorCountArray[COLOR_CATEGORY_NUM] = { 0 }; + InRangeColorSummary(Ipl_tempImg, ColorCountArray); // Color statistic + tempImg.release(); + delete(img_buf); + + ColorCountArray[1].colorCount += ColorCountArray[0].colorCount; // Combine the count of the red1 and the red2 + ColorCountArray[0].colorCount = 0; // count of red1 + + if (color_detection_type == _PLATE_COLOR) + { + // count silver,darkgray,black to white. + ColorCountArray[7].colorCount += ColorCountArray[6].colorCount; + ColorCountArray[6].colorCount = 0; + ColorCountArray[7].colorCount += ColorCountArray[8].colorCount; + ColorCountArray[8].colorCount = 0; + ColorCountArray[7].colorCount += ColorCountArray[9].colorCount; + ColorCountArray[9].colorCount = 0; + } + sort(ColorCountArray, ColorCountArray + COLOR_CATEGORY_NUM, sort_color_count); + + if (ColorCountArray[0].colorCount < 3) + { + memset(current_detection_info->color, 0x00, sizeof(current_detection_info->color)); + current_detection_info->color_id = 0; + //pthread_mutex_unlock(&mutex_color_detect); + return 0; + } + + if (!IsHumanPose(current_detection_info->engine_type)) // If it's not the engine of the human pose. + { + if (color_detection_type == _NORMAL_COLOR) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[0].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[0].colorCategoryidx].color_id; + } + else if (color_detection_type == _TRAFFIC_COLOR) + { + //printf("\nBBBBAA(%s):ColorCount0:%f\n", ColorCategory[ColorCountArray[0].colorCategoryidx].color, (float)ColorCountArray[0].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount1:%f\n", ColorCategory[ColorCountArray[1].colorCategoryidx].color, (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount2:%f\n", ColorCategory[ColorCountArray[2].colorCategoryidx].color, (float)ColorCountArray[2].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount3:%f\n", ColorCategory[ColorCountArray[3].colorCategoryidx].color, (float)ColorCountArray[3].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount4:%f\n", ColorCategory[ColorCountArray[4].colorCategoryidx].color, (float)ColorCountArray[4].colorCount / (i_object_width * i_object_height)); + + if (strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "White") == 0 || + strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "Darkgray") == 0 || + strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "Silver") == 0 || + strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "Black") == 0) + { + //printf("\nBBBBAA(%s):ColorCount0:%f\n", ColorCategory[ColorCountArray[0].colorCategoryidx].color, (float)ColorCountArray[0].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount1:%f\n", ColorCategory[ColorCountArray[1].colorCategoryidx].color, (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount2:%f\n", ColorCategory[ColorCountArray[2].colorCategoryidx].color, (float)ColorCountArray[2].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount3:%f\n", ColorCategory[ColorCountArray[3].colorCategoryidx].color, (float)ColorCountArray[3].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA(%s):ColorCount4:%f\n", ColorCategory[ColorCountArray[4].colorCategoryidx].color, (float)ColorCountArray[4].colorCount / (i_object_width * i_object_height)); + + float control_color = 0; + float control_vice_color = 0; + + if (strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "White") == 0 || + strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "Darkgray") == 0 || + strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "Silver") == 0) { + control_color = 0.025; + control_vice_color = 0.01; + } + else if (strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "Black") == 0) { + control_color = 0.035; + control_vice_color = 0.006; + } + + if ((float)ColorCountArray[0].colorCount / (i_object_width * i_object_height) > control_color) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[0].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[0].colorCategoryidx].color_id; + } + else + { + //printf("\nAAAA:ColorCount:%f\n", (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + if ((float)ColorCountArray[1].colorCount / (i_object_width * i_object_height) > control_vice_color) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[1].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[1].colorCategoryidx].color_id; + } + else { + //strcpy(current_detection_info->color, "White"); + current_detection_info->color_id = 0; + } + } + } + else + { + //printf("\nBBBB(%s):ColorCount0:%f\n", ColorCategory[ColorCountArray[0].colorCategoryidx].color, (float)ColorCountArray[0].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBB(%s):ColorCount1:%f\n", ColorCategory[ColorCountArray[1].colorCategoryidx].color, (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBB(%s):ColorCount2:%f\n", ColorCategory[ColorCountArray[2].colorCategoryidx].color, (float)ColorCountArray[2].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBB(%s):ColorCount3:%f\n", ColorCategory[ColorCountArray[3].colorCategoryidx].color, (float)ColorCountArray[3].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBB(%s):ColorCount4:%f\n", ColorCategory[ColorCountArray[4].colorCategoryidx].color, (float)ColorCountArray[4].colorCount / (i_object_width * i_object_height)); + + + if ((float)ColorCountArray[0].colorCount / (i_object_width * i_object_height) > 0.025) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[0].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[0].colorCategoryidx].color_id; + } + else { + //strcpy(current_detection_info->color, "White"); + if ((float)ColorCountArray[1].colorCount / (i_object_width * i_object_height) > 0.01) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[1].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[1].colorCategoryidx].color_id; + } + else { + //strcpy(current_detection_info->color, "White"); + current_detection_info->color_id = 0; + } + } + } + } + else if (color_detection_type == _PLATE_COLOR) + { + if (strcmp(ColorCategory[ColorCountArray[0].colorCategoryidx].color, "White") == 0) + { + //printf("\nBBBBAA:ColorCount0:%f\n", (float)ColorCountArray[0].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBBAA:ColorCount1:%f\n", (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + if ((float)ColorCountArray[0].colorCount / (i_object_width * i_object_height) > 0.025) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[0].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[0].colorCategoryidx].color_id; + } + else + { + //printf("\nAAAA:ColorCount:%f\n", (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + if ((float)ColorCountArray[1].colorCount / (i_object_width * i_object_height) > 0.01) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[1].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[1].colorCategoryidx].color_id; + } + else { + //strcpy(current_detection_info->color, "White"); + current_detection_info->color_id = 0; + } + } + } + else + { + //printf("\nBBBB:ColorCount0:%f\n", (float)ColorCountArray[0].colorCount / (i_object_width * i_object_height)); + //printf("\nBBBB:ColorCount1:%f\n", (float)ColorCountArray[1].colorCount / (i_object_width * i_object_height)); + if ((float)ColorCountArray[0].colorCount / (i_object_width * i_object_height) > 0.025) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[0].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[0].colorCategoryidx].color_id; + } + else { + //strcpy(current_detection_info->color, "White"); + if ((float)ColorCountArray[1].colorCount / (i_object_width * i_object_height) > 0.01) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[1].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[1].colorCategoryidx].color_id; + } + else { + //strcpy(current_detection_info->color, "White"); + current_detection_info->color_id = 0; + } + } + } + + //printf("[AssignObjectColorForAmba] current_detection_info->color = %s\n", current_detection_info->color); + } + else if (color_detection_type == _TRAFFIC_LIGHT_COLOR) + { + int nFindTrafficLight = 0; + for (int i = 0; i < COLOR_CATEGORY_NUM; i++) + { + if (strcmp(ColorCategory[ColorCountArray[i].colorCategoryidx].color, "Red") == 0 || strcmp(ColorCategory[ColorCountArray[i].colorCategoryidx].color, "Green") == 0) + { + if ((float)ColorCountArray[i].colorCount / (i_object_width * i_object_height) > 0.051 / (4 * 4)) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[i].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[i].colorCategoryidx].color_id; + nFindTrafficLight = 1; + break; + } + } + } + + if (!nFindTrafficLight) + { + strcpy(current_detection_info->color, ColorCategory[ColorCountArray[0].colorCategoryidx].color); + current_detection_info->color_id = ColorCategory[ColorCountArray[0].colorCategoryidx].color_id; + } + } + else + { + memset(current_detection_info->color, 0x00, sizeof(current_detection_info->color)); + current_detection_info->color_id = 0; + } + } + + /* + //color_id 9 white + for (int i = 0; i < COLOR_CATEGORY_NUM; i++) { + if (current_detection_info->color_id == ColorCategory[i].color_id && ColorCategory[i].color_id != 7 ) { + printf("\n[AssignObjectColorForAmba]-------current plate color for color table exclude the white one------\n"); + printf("color: %s\n", ColorCategory[i].color); + printf("h_max: %d\n", ColorCategory[i].h_max); + printf("h_min: %d\n", ColorCategory[i].h_min); + printf("s_max: %d\n", ColorCategory[i].s_max); + printf("s_min: %d\n", ColorCategory[i].s_min); + printf("v_max: %d\n", ColorCategory[i].v_max); + printf("v_min: %d\n", ColorCategory[i].v_min); + printf("\n[AssignObjectColorForAmba]----------------------------------------------------------------------\n"); + } + } + */ + //pthread_mutex_unlock(&mutex_color_detect); + + //printf("\n------------------[Assign Object Color For Amba]----------------------end\n"); + + return current_detection_info->color_id; +} + diff --git a/src/ColorDetector.hpp b/src/ColorDetector.hpp new file mode 100644 index 0000000..bd49456 --- /dev/null +++ b/src/ColorDetector.hpp @@ -0,0 +1,29 @@ +#if 1 +#pragma once +#ifndef COLORDETECTOR_H_ +#define COLORDETECTOR_H_ + +//#include "nweb.h" +#include <opencv2/opencv.hpp> +#include <queue> +#include <string> +#include "utility.h" + +using namespace std; + +typedef struct t_color_node { + cv::Mat mean; // The mean of this node + cv::Mat cov; + uchar classid; // The class ID + + t_color_node *left; + t_color_node *right; +} t_color_node; + + +void InRangeColorSummary(IplImage rgbImage, ColorArray colorCountArray[]); +bool sort_color_count(ColorArray a, ColorArray b); + +#endif /* COLORDETECTOR_H_ */ + +#endif \ No newline at end of file diff --git a/src/ColorDetectorC.h b/src/ColorDetectorC.h new file mode 100644 index 0000000..a4a5d8b --- /dev/null +++ b/src/ColorDetectorC.h @@ -0,0 +1,31 @@ +#if 1 +#pragma once +#ifndef COLORDETECTORC_H_ +#define COLORDETECTORC_H_ + +//#include "nweb.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "utility.h" +#include <time.h> + +//extern void InRangeColorSummary(IplImage rgbImage, ColorArray colorCountArray[]); +//extern void AssignObjectColor(detection_pos* pNext, IplImage* im, ColorDetectionType color_detection_type); + +int AssignObjectColorForAmba(detection_pos* current_detection_info, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, ColorDetectionType color_detection_type, int __element_interleaved__); + +int SaveRawRGBToChar(char* output_image, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, int __element_interleaved__); +void SaveRawRGBToJPG(char* __image_name__, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, int __element_interleaved__); +void SaveRawYUVToRGB_JPG(char *read_filename,char* __image_name__, int __size__, int __width__, int __height__); + +#ifdef __cplusplus +} +#endif + +#endif /* COLORDETECTOR_H_ */ +#endif diff --git a/src/activation_kernels.cu b/src/activation_kernels.cu new file mode 100644 index 0000000..4dc5804 --- /dev/null +++ b/src/activation_kernels.cu @@ -0,0 +1,206 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "activations.h" +#include "cuda.h" +} + + +__device__ float lhtan_activate_kernel(float x) +{ + if(x < 0) return .001f*x; + if(x > 1) return .001f*(x-1.f) + 1.f; + return x; +} +__device__ float lhtan_gradient_kernel(float x) +{ + if(x > 0 && x < 1) return 1; + return .001; +} + +__device__ float hardtan_activate_kernel(float x) +{ + if (x < -1) return -1; + if (x > 1) return 1; + return x; +} +__device__ float linear_activate_kernel(float x){return x;} +__device__ float logistic_activate_kernel(float x){return 1.f/(1.f + expf(-x));} +__device__ float loggy_activate_kernel(float x){return 2.f/(1.f + expf(-x)) - 1;} +__device__ float relu_activate_kernel(float x){return x*(x>0);} +__device__ float elu_activate_kernel(float x){return (x >= 0)*x + (x < 0)*(expf(x)-1);} +__device__ float selu_activate_kernel(float x){return (x >= 0)*1.0507f*x + (x < 0)*1.0507f*1.6732f*(expf(x)-1);} +__device__ float relie_activate_kernel(float x){return (x>0) ? x : .01f*x;} +__device__ float ramp_activate_kernel(float x){return x*(x>0)+.1f*x;} +__device__ float leaky_activate_kernel(float x){return (x>0) ? x : .1f*x;} +__device__ float tanh_activate_kernel(float x){return (2.f/(1 + expf(-2*x)) - 1);} +__device__ float plse_activate_kernel(float x) +{ + if(x < -4) return .01f * (x + 4); + if(x > 4) return .01f * (x - 4) + 1; + return .125f*x + .5f; +} +__device__ float stair_activate_kernel(float x) +{ + int n = floorf(x); + if (n%2 == 0) return floorf(x/2); + else return (x - n) + floorf(x/2); +} + + +__device__ float hardtan_gradient_kernel(float x) +{ + if (x > -1 && x < 1) return 1; + return 0; +} +__device__ float linear_gradient_kernel(float x){return 1;} +__device__ float logistic_gradient_kernel(float x){return (1-x)*x;} +__device__ float loggy_gradient_kernel(float x) +{ + float y = (x+1)/2; + return 2*(1-y)*y; +} +__device__ float relu_gradient_kernel(float x){return (x>0);} +__device__ float elu_gradient_kernel(float x){return (x >= 0) + (x < 0)*(x + 1);} +__device__ float selu_gradient_kernel(float x){return (x >= 0)*1.0507 + (x < 0)*(x + 1.0507*1.6732);} +__device__ float relie_gradient_kernel(float x){return (x>0) ? 1 : .01f;} +__device__ float ramp_gradient_kernel(float x){return (x>0)+.1f;} +__device__ float leaky_gradient_kernel(float x){return (x>0) ? 1 : .1f;} +__device__ float tanh_gradient_kernel(float x){return 1-x*x;} +__device__ float plse_gradient_kernel(float x){return (x < 0 || x > 1) ? .01f : .125f;} +__device__ float stair_gradient_kernel(float x) +{ + if (floorf(x) == x) return 0; + return 1; +} + +__device__ float activate_kernel(float x, ACTIVATION a) +{ + switch(a){ + case LINEAR: + return linear_activate_kernel(x); + case LOGISTIC: + return logistic_activate_kernel(x); + case LOGGY: + return loggy_activate_kernel(x); + case RELU: + return relu_activate_kernel(x); + case ELU: + return elu_activate_kernel(x); + case SELU: + return selu_activate_kernel(x); + case RELIE: + return relie_activate_kernel(x); + case RAMP: + return ramp_activate_kernel(x); + case LEAKY: + return leaky_activate_kernel(x); + case TANH: + return tanh_activate_kernel(x); + case PLSE: + return plse_activate_kernel(x); + case STAIR: + return stair_activate_kernel(x); + case HARDTAN: + return hardtan_activate_kernel(x); + case LHTAN: + return lhtan_activate_kernel(x); + } + return 0; +} + +__device__ float gradient_kernel(float x, ACTIVATION a) +{ + switch(a){ + case LINEAR: + return linear_gradient_kernel(x); + case LOGISTIC: + return logistic_gradient_kernel(x); + case LOGGY: + return loggy_gradient_kernel(x); + case RELU: + return relu_gradient_kernel(x); + case ELU: + return elu_gradient_kernel(x); + case SELU: + return selu_gradient_kernel(x); + case RELIE: + return relie_gradient_kernel(x); + case RAMP: + return ramp_gradient_kernel(x); + case LEAKY: + return leaky_gradient_kernel(x); + case TANH: + return tanh_gradient_kernel(x); + case PLSE: + return plse_gradient_kernel(x); + case STAIR: + return stair_gradient_kernel(x); + case HARDTAN: + return hardtan_gradient_kernel(x); + case LHTAN: + return lhtan_gradient_kernel(x); + } + return 0; +} + +__global__ void binary_gradient_array_kernel(float *x, float *dy, int n, int s, BINARY_ACTIVATION a, float *dx) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + int i = id % s; + int b = id / s; + float x1 = x[b*s + i]; + float x2 = x[b*s + s/2 + i]; + if(id < n) { + float de = dy[id]; + dx[b*s + i] = x2*de; + dx[b*s + s/2 + i] = x1*de; + } +} + +extern "C" void binary_gradient_array_gpu(float *x, float *dx, int n, int size, BINARY_ACTIVATION a, float *y) +{ + binary_gradient_array_kernel<<<cuda_gridsize(n/2), BLOCK>>>(x, dx, n/2, size, a, y); + check_error(cudaPeekAtLastError()); +} +__global__ void binary_activate_array_kernel(float *x, int n, int s, BINARY_ACTIVATION a, float *y) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + int i = id % s; + int b = id / s; + float x1 = x[b*s + i]; + float x2 = x[b*s + s/2 + i]; + if(id < n) y[id] = x1*x2; +} + +extern "C" void binary_activate_array_gpu(float *x, int n, int size, BINARY_ACTIVATION a, float *y) +{ + binary_activate_array_kernel<<<cuda_gridsize(n/2), BLOCK>>>(x, n/2, size, a, y); + check_error(cudaPeekAtLastError()); +} + +__global__ void activate_array_kernel(float *x, int n, ACTIVATION a) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n) x[i] = activate_kernel(x[i], a); +} + +__global__ void gradient_array_kernel(float *x, int n, ACTIVATION a, float *delta) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n) delta[i] *= gradient_kernel(x[i], a); +} + +extern "C" void activate_array_gpu(float *x, int n, ACTIVATION a) +{ + activate_array_kernel<<<cuda_gridsize(n), BLOCK>>>(x, n, a); + check_error(cudaPeekAtLastError()); +} + +extern "C" void gradient_array_gpu(float *x, int n, ACTIVATION a, float *delta) +{ + gradient_array_kernel<<<cuda_gridsize(n), BLOCK>>>(x, n, a, delta); + check_error(cudaPeekAtLastError()); +} diff --git a/src/activation_layer.c b/src/activation_layer.c new file mode 100644 index 0000000..b4ba953 --- /dev/null +++ b/src/activation_layer.c @@ -0,0 +1,63 @@ +#include "activation_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +layer make_activation_layer(int batch, int inputs, ACTIVATION activation) +{ + layer l = {0}; + l.type = ACTIVE; + + l.inputs = inputs; + l.outputs = inputs; + l.batch=batch; + + l.output = calloc(batch*inputs, sizeof(float*)); + l.delta = calloc(batch*inputs, sizeof(float*)); + + l.forward = forward_activation_layer; + l.backward = backward_activation_layer; +#ifdef GPU + l.forward_gpu = forward_activation_layer_gpu; + l.backward_gpu = backward_activation_layer_gpu; + + l.output_gpu = cuda_make_array(l.output, inputs*batch); + l.delta_gpu = cuda_make_array(l.delta, inputs*batch); +#endif + l.activation = activation; + fprintf(stderr, "Activation Layer: %d inputs\n", inputs); + return l; +} + +void forward_activation_layer(layer l, network net) +{ + copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); + activate_array(l.output, l.outputs*l.batch, l.activation); +} + +void backward_activation_layer(layer l, network net) +{ + gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); + copy_cpu(l.outputs*l.batch, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void forward_activation_layer_gpu(layer l, network net) +{ + copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1); + activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation); +} + +void backward_activation_layer_gpu(layer l, network net) +{ + gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); + copy_gpu(l.outputs*l.batch, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif diff --git a/src/activation_layer.h b/src/activation_layer.h new file mode 100644 index 0000000..97c9df4 --- /dev/null +++ b/src/activation_layer.h @@ -0,0 +1,21 @@ + +#pragma once +#ifndef ACTIVATION_LAYER_H +#define ACTIVATION_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "layer.h" +#include "network.h" + +layer make_activation_layer(int batch, int inputs, ACTIVATION activation); + +void forward_activation_layer(layer l, network net); +void backward_activation_layer(layer l, network net); + +#ifdef GPU +void forward_activation_layer_gpu(layer l, network net); +void backward_activation_layer_gpu(layer l, network net); +#endif + +#endif + diff --git a/src/activations.c b/src/activations.c new file mode 100644 index 0000000..da1a17a --- /dev/null +++ b/src/activations.c @@ -0,0 +1,150 @@ +#include "activations.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char *get_activation_string(ACTIVATION a) +{ + switch(a){ + case LOGISTIC: + return "logistic"; + case LOGGY: + return "loggy"; + case RELU: + return "relu"; + case ELU: + return "elu"; + case SELU: + return "selu"; + case RELIE: + return "relie"; + case RAMP: + return "ramp"; + case LINEAR: + return "linear"; + case TANH: + return "tanh"; + case PLSE: + return "plse"; + case LEAKY: + return "leaky"; + case STAIR: + return "stair"; + case HARDTAN: + return "hardtan"; + case LHTAN: + return "lhtan"; + default: + break; + } + return "relu"; +} + +ACTIVATION get_activation(char *s) +{ + if (strcmp(s, "logistic")==0) return LOGISTIC; + if (strcmp(s, "loggy")==0) return LOGGY; + if (strcmp(s, "relu")==0) return RELU; + if (strcmp(s, "elu")==0) return ELU; + if (strcmp(s, "selu")==0) return SELU; + if (strcmp(s, "relie")==0) return RELIE; + if (strcmp(s, "plse")==0) return PLSE; + if (strcmp(s, "hardtan")==0) return HARDTAN; + if (strcmp(s, "lhtan")==0) return LHTAN; + if (strcmp(s, "linear")==0) return LINEAR; + if (strcmp(s, "ramp")==0) return RAMP; + if (strcmp(s, "leaky")==0) return LEAKY; + if (strcmp(s, "tanh")==0) return TANH; + if (strcmp(s, "stair")==0) return STAIR; + fprintf(stderr, "Couldn't find activation function %s, going with ReLU\n", s); + return RELU; +} + +float activate(float x, ACTIVATION a) +{ + switch(a){ + case LINEAR: + return linear_activate(x); + case LOGISTIC: + return logistic_activate(x); + case LOGGY: + return loggy_activate(x); + case RELU: + return relu_activate(x); + case ELU: + return elu_activate(x); + case SELU: + return selu_activate(x); + case RELIE: + return relie_activate(x); + case RAMP: + return ramp_activate(x); + case LEAKY: + return leaky_activate(x); + case TANH: + return tanh_activate(x); + case PLSE: + return plse_activate(x); + case STAIR: + return stair_activate(x); + case HARDTAN: + return hardtan_activate(x); + case LHTAN: + return lhtan_activate(x); + } + return 0; +} + +void activate_array(float *x, const int n, const ACTIVATION a) +{ + int i; + for(i = 0; i < n; ++i){ + x[i] = activate(x[i], a); + } +} + +float gradient(float x, ACTIVATION a) +{ + switch(a){ + case LINEAR: + return linear_gradient(x); + case LOGISTIC: + return logistic_gradient(x); + case LOGGY: + return loggy_gradient(x); + case RELU: + return relu_gradient(x); + case ELU: + return elu_gradient(x); + case SELU: + return selu_gradient(x); + case RELIE: + return relie_gradient(x); + case RAMP: + return ramp_gradient(x); + case LEAKY: + return leaky_gradient(x); + case TANH: + return tanh_gradient(x); + case PLSE: + return plse_gradient(x); + case STAIR: + return stair_gradient(x); + case HARDTAN: + return hardtan_gradient(x); + case LHTAN: + return lhtan_gradient(x); + } + return 0; +} + +void gradient_array(const float *x, const int n, const ACTIVATION a, float *delta) +{ + int i; + for(i = 0; i < n; ++i){ + delta[i] *= gradient(x[i], a); + } +} + diff --git a/src/activations.h b/src/activations.h new file mode 100644 index 0000000..901f2fa --- /dev/null +++ b/src/activations.h @@ -0,0 +1,93 @@ + +#pragma once +#ifndef ACTIVATIONS_H +#define ACTIVATIONS_H +#include "define_inc.h" +#include "cuda.h" +#include "math.h" + +typedef enum { + LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN, SELU +} ACTIVATION; + +ACTIVATION get_activation(char *s); + +char *get_activation_string(ACTIVATION a); +float activate(float x, ACTIVATION a); +float gradient(float x, ACTIVATION a); +void gradient_array(const float *x, const int n, const ACTIVATION a, float *delta); +void activate_array(float *x, const int n, const ACTIVATION a); +#ifdef GPU +void activate_array_gpu(float *x, int n, ACTIVATION a); +void gradient_array_gpu(float *x, int n, ACTIVATION a, float *delta); +#endif + +static inline float stair_activate(float x) +{ + int n = floor(x); + if (n%2 == 0) return floor(x/2.); + else return (x - n) + floor(x/2.); +} +static inline float hardtan_activate(float x) +{ + if (x < -1) return -1; + if (x > 1) return 1; + return x; +} +static inline float linear_activate(float x){return x;} +static inline float logistic_activate(float x){return 1./(1. + exp(-x));} +static inline float loggy_activate(float x){return 2./(1. + exp(-x)) - 1;} +static inline float relu_activate(float x){return x*(x>0);} +static inline float elu_activate(float x){return (x >= 0)*x + (x < 0)*(exp(x)-1);} +static inline float selu_activate(float x){return (x >= 0)*1.0507*x + (x < 0)*1.0507*1.6732*(exp(x)-1);} +static inline float relie_activate(float x){return (x>0) ? x : .01*x;} +static inline float ramp_activate(float x){return x*(x>0)+.1*x;} +static inline float leaky_activate(float x){return (x>0) ? x : .1*x;} +static inline float tanh_activate(float x){return (exp(2*x)-1)/(exp(2*x)+1);} +static inline float plse_activate(float x) +{ + if(x < -4) return .01 * (x + 4); + if(x > 4) return .01 * (x - 4) + 1; + return .125*x + .5; +} + +static inline float lhtan_activate(float x) +{ + if(x < 0) return .001*x; + if(x > 1) return .001*(x-1) + 1; + return x; +} +static inline float lhtan_gradient(float x) +{ + if(x > 0 && x < 1) return 1; + return .001; +} + +static inline float hardtan_gradient(float x) +{ + if (x > -1 && x < 1) return 1; + return 0; +} +static inline float linear_gradient(float x){return 1;} +static inline float logistic_gradient(float x){return (1-x)*x;} +static inline float loggy_gradient(float x) +{ + float y = (x+1.)/2.; + return 2*(1-y)*y; +} +static inline float stair_gradient(float x) +{ + if (floor(x) == x) return 0; + return 1; +} +static inline float relu_gradient(float x){return (x>0);} +static inline float elu_gradient(float x){return (x >= 0) + (x < 0)*(x + 1);} +static inline float selu_gradient(float x){return (x >= 0)*1.0507 + (x < 0)*(x + 1.0507*1.6732);} +static inline float relie_gradient(float x){return (x>0) ? 1 : .01;} +static inline float ramp_gradient(float x){return (x>0)+.1;} +static inline float leaky_gradient(float x){return (x>0) ? 1 : .1;} +static inline float tanh_gradient(float x){return 1-x*x;} +static inline float plse_gradient(float x){return (x < 0 || x > 1) ? .01 : .125;} + +#endif + diff --git a/src/alm_queue.cpp b/src/alm_queue.cpp new file mode 100644 index 0000000..cc2f1d3 --- /dev/null +++ b/src/alm_queue.cpp @@ -0,0 +1,56 @@ + +#include "alm_queue.h" +#include <stdio.h> +#include <stdlib.h> +#include <deque> + + +using namespace std; + + +static std::deque <ALMQueueInfo> ALMQueue[MAX_CLIENT_SOCKET]; + + +void ALMQueuePush(ALMQueueInfo q_info, int idx) +{ + ALMQueue[idx].push_back(q_info); +} + +ALMQueueInfo ALMQueueFront(int idx) +{ + return ALMQueue[idx].front(); +} + +void ALMQueuePop(int idx) +{ + /*ALMQueueInfo alm_q_info = ALMQueueFront(idx); + if (alm_q_info.pszContent != NULL) + { + free(alm_q_info.pszContent); + alm_q_info.pszContent = NULL; + }*/ + ALMQueue[idx].pop_front(); + if (ALMQueueSize(idx) == 0) { + ALMQueue[idx].shrink_to_fit(); + } +} + +int ALMQueueSize(int idx) +{ + return ALMQueue[idx].size(); +} + +int ALMQueueIsEmpty(int idx) +{ + return ALMQueueSize(idx) <= 0 ? 1 : 0; +} + +void ALMQueueClear(int idx) +{ + + while (!ALMQueueIsEmpty(idx)) + { + ALMQueuePop(idx); + } + //ALMQueue[idx].clear();//wMŤFAA +} diff --git a/src/alm_queue.h b/src/alm_queue.h new file mode 100644 index 0000000..9e3be68 --- /dev/null +++ b/src/alm_queue.h @@ -0,0 +1,34 @@ +#pragma once +#ifndef ALM_QUEUE_H +#define ALM_QUEUE_H + +#include <stdio.h> +#include "setting.h" +#include "define_inc.h" + +#ifdef __cplusplus +extern "C" { +#endif + + #define ALMBUFSIZE BUFSIZE_V3 + + typedef struct { + char pszContent[ALMBUFSIZE]; + //char websocket_content[ALMBUFSIZE]; + //char szContent[ALMBUFSIZE]; + int nSize; + int infoType; + } ALMQueueInfo; + + void ALMQueuePush(ALMQueueInfo q_info, int idx); + ALMQueueInfo ALMQueueFront(int idx); + void ALMQueuePop(int idx); + int ALMQueueSize(int idx); + int ALMQueueIsEmpty(int idx); + void ALMQueueClear(int idx); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/amba_bbox_utils.c b/src/amba_bbox_utils.c new file mode 100644 index 0000000..a2045e5 --- /dev/null +++ b/src/amba_bbox_utils.c @@ -0,0 +1,192 @@ +/******************************************************************************* + * amba_bbox_utils.c + * + * History: + * 2018/09/29 - [Hao Qian] created + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#include "lib_data_process_priv.h" +#include "amba_bbox_utils.h" +#include <stdlib.h> +#include "utils.h" +#include <math.h> +/********************************************** +Function: get_bbox_size +Description: Calculate bounding box area +Input: +bbox +Output: +bbox size +**********************************************/ +float get_bbox_size(dproc_bbox_param_t *bbox) +{ + float size = 0; + float bbox_w = bbox->x_max - bbox->x_min; + float bbox_h = bbox->y_max - bbox->y_min; + + if (bbox_w > 0 && bbox_h > 0) { + size = bbox_w * bbox_h; + + //DPRINT(L_DEBUG, "get_bbox_size: bbox min = (%f, %f), max = (%f, %f), size = %f\n", + // bbox->x_min, bbox->y_min, bbox->x_max, bbox->y_max, size); + } + + return size; +} + +/********************************************** +Function: get_intersect_bbox +Description: Calculate bounding box area +Input: +bbox1, bbox2 +Output: +int_bbox +**********************************************/ +void get_intersect_bbox(dproc_bbox_param_t *bbox1, dproc_bbox_param_t *bbox2, dproc_bbox_param_t *int_bbox) +{ + if (bbox2->x_min > bbox1->x_max || bbox2->x_max < bbox1->x_min || + bbox2->y_min > bbox1->y_max || bbox2->y_max < bbox1->y_min) { + /* no intersection*/ + int_bbox->x_min = 0; + int_bbox->y_min = 0; + int_bbox->x_max = 0; + int_bbox->y_max = 0; + } else { + /* calculate intersection box */ + int_bbox->x_min = fmax(bbox1->x_min, bbox2->x_min); + int_bbox->y_min = fmax(bbox1->y_min, bbox2->y_min); + int_bbox->x_max = fmin(bbox1->x_max, bbox2->x_max); + int_bbox->y_max = fmin(bbox1->y_max, bbox2->y_max); + } + + //DPRINT(L_DEBUG, "get_intersect_bbox: bbox1 min = (%f, %f), max = (%f, %f)\n", + // bbox1->x_min, bbox1->y_min, bbox1->x_max, bbox1->y_max); + //DPRINT(L_DEBUG, "get_intersect_bbox: bbox2 min = (%f, %f), max = (%f, %f)\n", + // bbox2->x_min, bbox2->y_min, bbox2->x_max, bbox2->y_max); + //DPRINT(L_DEBUG, "get_intersect_bbox: int_bbox min = (%f, %f), max = (%f, %f)\n", + // int_bbox->x_min, int_bbox->y_min, int_bbox->x_max, int_bbox->y_max); + + return; +} + +/********************************************** +Function: jaccard_overlap +Description: Calculate jaccard overlap of two bounding boxes +Input: +bbox1, bbox2 +Output: +overlap value +**********************************************/ +float jaccard_overlap(dproc_bbox_param_t *bbox1, dproc_bbox_param_t *bbox2) +{ + dproc_bbox_param_t int_bbox; + float int_bbox_size; + float bbox1_size = 0, bbox2_size = 0; + float overlap = 0; + + get_intersect_bbox(bbox1, bbox2, &int_bbox); + + int_bbox_size = get_bbox_size(&int_bbox); + + if (int_bbox_size > 0) { + bbox1_size = get_bbox_size(bbox1); + bbox2_size = get_bbox_size(bbox2); + overlap = int_bbox_size / (bbox1_size + bbox2_size - int_bbox_size); + } + + //DPRINT(L_DEBUG, "jaccard_overlap: bbox1_size = %f, bbox2_size = %f, int_bbox_size = %f, overlap = %f\n", + // bbox1_size, bbox2_size, int_bbox_size, overlap); + + return overlap; +} + +/********************************************** +Function: clip_bbox +Description: clip bbox parameters to [0.0 1.0] +Input: +bbox +Output: +clipped bbox +**********************************************/ +void clip_bbox(dproc_bbox_param_t *bbox) +{ + bbox->x_min = clip3(0, 1, bbox->x_min); + bbox->y_min = clip3(0, 1, bbox->y_min); + bbox->x_max = clip3(0, 1, bbox->x_max); + bbox->y_max = clip3(0, 1, bbox->y_max); + + return; +} + +/********************************************** +Function: scale_bbox +Description: scale bbox parameters +Input: +bbox +Output: +scaled bbox +**********************************************/ +void scale_bbox(dproc_bbox_param_t *bbox, int scale_w, int scale_h) +{ + //clip_bbox(bbox); + + bbox->x_min = round(bbox->x_min * scale_w); + bbox->y_min = round(bbox->y_min * scale_h); + bbox->x_max = round(bbox->x_max * scale_w); + bbox->y_max = round(bbox->y_max * scale_h); + + return; +} + +/********************************************** +Function: swap_bbox +Description: swap x and y in bbox for TF as it is y, x +Input: +bbox +Output: +scaled bbox +**********************************************/ +void swap_bbox(dproc_bbox_param_t *bbox) +{ + float tmp; + + tmp = bbox->x_min; + bbox->x_min = bbox->y_min; + bbox->y_min = tmp; + + tmp = bbox->x_max; + bbox->x_max = bbox->y_max; + bbox->y_max = tmp; + + return; +} + diff --git a/src/amba_bbox_utils.h b/src/amba_bbox_utils.h new file mode 100644 index 0000000..269c704 --- /dev/null +++ b/src/amba_bbox_utils.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * amba_bbox_utils.h + * + * History: + * 2018/09/29 - [Hao Qian] created + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ +#pragma once +#ifndef _BBOX_UTILS_H_ +#define _BBOX_UTILS_H_ +#include "define_inc.h" + +/* bbox util functions */ +float get_bbox_size(dproc_bbox_param_t *bbox); +void get_intersect_bbox(dproc_bbox_param_t *bbox1, dproc_bbox_param_t *bbox2, dproc_bbox_param_t *int_bbox); +float jaccard_overlap(dproc_bbox_param_t *bbox1, dproc_bbox_param_t *bbox2); + +void clip_bbox(dproc_bbox_param_t *bbox); +void scale_bbox(dproc_bbox_param_t *bbox, int scale_w, int scale_h); +void swap_bbox(dproc_bbox_param_t *bbox); + +#endif diff --git a/src/amba_ssd_detection_out.c b/src/amba_ssd_detection_out.c new file mode 100644 index 0000000..bbe6137 --- /dev/null +++ b/src/amba_ssd_detection_out.c @@ -0,0 +1,599 @@ +/******************************************************************************* + * amba_ssd_detection_out.c + * + * History: + * 2018/09/29 - [Hao Qian] created + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#include "lib_data_process_priv.h" +#include "amba_ssd_detection_out.h" +#include <sys/time.h> +#include <stdlib.h> +#include <math.h> + +#define true 1 +#define false 1 + +/********************************************** +Function: sort_ssd_result_by_score +Description: sort ssd result array (bubble sort) in place in descending order +Input: +array, size +Output: +sorted array +**********************************************/ +static void sort_ssd_result_by_score(dproc_ssd_detection_output_result_t* array, int size) +{ + int step, i;; + dproc_ssd_detection_output_result_t tmp; + + /* begin sort */ + for (step = 0; step < (size - 1); step++) { + for(i = 0; i < (size - step - 1); i++) { + if(array[i].score < array[i+1].score) { /* To sort in ascending order, change < to > */ + tmp = array[i]; + array[i] = array[i+1]; + array[i+1] = tmp; + } + } + } + + return; +} + +/********************************************** +Function: ssd_bboxes_decode +Description: decode bounding box +Input: +mbox_priorbox +mbox_loc +num_all_boxes +Output: +bboxes +**********************************************/ +static void ssd_bboxes_decode(float *mbox_priorbox, float *mbox_loc, int num_all_boxes, + dproc_bbox_param_t *bboxes, ssd_tf_scale_factors_t *tf_scale_factors) +{ + dproc_bbox_param_t* mbox = (dproc_bbox_param_t*)mbox_loc; + dproc_bbox_param_t* priorbox = (dproc_bbox_param_t*)mbox_priorbox; + dproc_bbox_param_t* priorbox_var = (dproc_bbox_param_t*)(&priorbox[num_all_boxes]); + float prior_center_x, prior_center_y, prior_w, prior_h; + float center_x, center_y, w, h; + + //DPRINT(L_DEBUG, "ssd_bboxes_decode enter\n"); + + for (int i = 0; i < num_all_boxes; i++) { + prior_center_x = (priorbox[i].x_min + priorbox[i].x_max) / 2; + prior_center_y = (priorbox[i].y_min + priorbox[i].y_max) / 2; + prior_w = (priorbox[i].x_max - priorbox[i].x_min); + prior_h = (priorbox[i].y_max - priorbox[i].y_min); + + if ((tf_scale_factors->center_x_scale == 0) || (tf_scale_factors->center_y_scale == 0) + || (tf_scale_factors->width_scale == 0) || (tf_scale_factors->height_scale == 0)) { + /* Caffe Model */ + center_x = mbox[i].x_min * priorbox_var[i].x_min * prior_w + prior_center_x; + center_y = mbox[i].y_min * priorbox_var[i].y_min * prior_h + prior_center_y; + w = prior_w * exp(mbox[i].x_max * priorbox_var[i].x_max); + h = prior_h * exp(mbox[i].y_max * priorbox_var[i].y_max); + } else { + /* TF model */ + center_x = mbox[i].x_min * prior_w / tf_scale_factors->center_x_scale + prior_center_x; + center_y = mbox[i].y_min * prior_h / tf_scale_factors->center_y_scale + prior_center_y; + w = prior_w * exp(mbox[i].x_max / tf_scale_factors->width_scale); + h = prior_h * exp(mbox[i].y_max / tf_scale_factors->height_scale); + } + + bboxes[i].x_min = center_x - w / 2; + bboxes[i].y_min = center_y - h / 2; + bboxes[i].x_max = center_x + w / 2; + bboxes[i].y_max = center_y + h / 2; + bboxes[i].x_min = (bboxes[i].x_min < 0.0f) ? 0.0f : ((bboxes[i].x_min > 1.0f) ? 1.0f : bboxes[i].x_min); + bboxes[i].y_min = (bboxes[i].y_min < 0.0f) ? 0.0f : ((bboxes[i].y_min > 1.0f) ? 1.0f : bboxes[i].y_min); + bboxes[i].x_max = (bboxes[i].x_max < 0.0f) ? 0.0f : ((bboxes[i].x_max > 1.0f) ? 1.0f : bboxes[i].x_max); + bboxes[i].y_max = (bboxes[i].y_max < 0.0f) ? 0.0f : ((bboxes[i].y_max > 1.0f) ? 1.0f : bboxes[i].y_max); + + //DPRINT(L_DEBUG, "bbox %d: min = (%f, %f), max = (%f, %f)\n", + // i, bboxes[i].x_min, bboxes[i].y_min, bboxes[i].x_max, bboxes[i].y_max); + } + + //DPRINT(L_DEBUG, "ssd_bboxes_decode exit: total box num %d\n", num_all_boxes); + + return; +} + +/********************************************** +Function: filter_bboxes +Input: +mbox_conf_flatten +class # +bboxes +num_all_bboxes +config +Output: +num_bboxes +ssd_info +**********************************************/ +static int filter_bboxes(float *mbox_conf, int class, dproc_bbox_param_t *bboxes, + int num_all_bboxes, dproc_ssd_detection_output_config_t *config, + dproc_ssd_detection_output_result_t *ssd_info) +{ + int num_bboxes = 0; + int i; + + //DPRINT(L_DEBUG, "filter_bboxes enter: num all bboxes: %d\n", num_all_bboxes); + + /* For performance, instead of: + 1. sort all boxes base on their scores, then + 2. filter out lower than conf_threshold entries + Do + 1. filter out lower than conf_threshold entries, then + 2. sort remaining boxes + */ + + /* step 1: filter */ + for (i = 0; i < num_all_bboxes; i++) { + if (mbox_conf[class + i*config->num_classes] >= config->conf_threshold) { + ssd_info[num_bboxes].label = class; + ssd_info[num_bboxes].score = mbox_conf[class + i*config->num_classes]; + ssd_info[num_bboxes].bbox = bboxes[i]; + num_bboxes++; + } + } + + /* step 2: sort */ + if (num_bboxes) { + sort_ssd_result_by_score(ssd_info, num_bboxes); + } + + //DPRINT(L_DEBUG, "filter_bboxes exit: num bboxes filtered %d\n", num_bboxes); + + return num_bboxes; +} + +/********************************************** +Function: nms +Input: +ssd class results +number of filtered bbox +nms threshold +Output: +ssd_result for kept bbox +bboxes_kept_num +**********************************************/ +static int nms(dproc_ssd_detection_output_result_t *ssd_class, int num_bboxes, + int nms_top_k, float th_nms, dproc_ssd_detection_output_result_t *ssd_result, + uint8_t *bboxes_kept_idx_array) +{ + int bbox_idx, ancr_idx; + int bboxes_kept_num = 0; + uint8_t keep_bbox; + float overlap; + int i; + dproc_bbox_param_t box_ancr, box_curr; + + //DPRINT(L_DEBUG, "nms enter: num bboxes: %d\n", num_bboxes); + + if (num_bboxes > nms_top_k) { + num_bboxes = nms_top_k; + } + + if (num_bboxes > 0) { + for (bbox_idx = 0; bbox_idx < num_bboxes; bbox_idx++) { + //DPRINT(L_DEBUG, "Incoming bbox %d, (%f, %f), (%f, %f)\n", + // bbox_idx, ssd_class[bbox_idx].bbox.x_min, ssd_class[bbox_idx].bbox.y_min, + // ssd_class[bbox_idx].bbox.x_max, ssd_class[bbox_idx].bbox.y_max); + keep_bbox = true; + + for (i = 0; i < bboxes_kept_num; i++) { + if (keep_bbox) { + ancr_idx = bboxes_kept_idx_array[i]; + box_ancr = ssd_class[ancr_idx].bbox; + box_curr = ssd_class[bbox_idx].bbox; + overlap = jaccard_overlap(&box_curr, &box_ancr); + if (overlap <= th_nms) { + keep_bbox = true; + } + else { + keep_bbox = false; + } + + //DPRINT(L_DEBUG, "box_curr (%f, %f), (%f, %f)\n", + // box_curr.x_min, box_curr.y_min, box_curr.x_max, box_curr.y_max); + //DPRINT(L_DEBUG, "box_ancr (%f, %f), (%f, %f)\n", + // box_ancr.x_min, box_ancr.y_min, box_ancr.x_max, box_ancr.y_max); + //DPRINT(L_DEBUG, "th_nms %f, overlap %f\n", th_nms, overlap); + } else { + break; + } + } + if (keep_bbox) { + bboxes_kept_idx_array[bboxes_kept_num] = bbox_idx; + ssd_result[bboxes_kept_num] = ssd_class[bbox_idx]; + + bboxes_kept_num++; + } + } + } + + //DPRINT(L_DEBUG, "nms exit: kept bboxes: %d\n", bboxes_kept_num); + + return bboxes_kept_num; +} + +/********************************************** +Function: keep_top_k +Input: +ssd results +ssd_result_num +keep_top_k_objs +Output: +sorted ssd_result +top_k ssd_result_num +**********************************************/ +static int keep_top_k(dproc_ssd_detection_output_result_t *ssd_result, int ssd_result_num, + int keep_top_k_objs) +{ + int result_num = ssd_result_num; + + //DPRINT(L_DEBUG, "keep_top_k enter: ssd_result_num %d\n", ssd_result_num); + + sort_ssd_result_by_score(ssd_result, ssd_result_num); + + if ((keep_top_k_objs > -1) && (ssd_result_num > keep_top_k_objs)) { + result_num = keep_top_k_objs; + } + + //DPRINT(L_DEBUG, "keep_top_k exit: final detected num %d\n", result_num); + + return result_num; +} + +/********************************************** +Function: detected_bboxes +Input: +mbox_conf_flatten +bboxes +config +Output: +ssd_result + +# processing per class to make sure we can get the same result as SSD's ones +# step a: filter out the boxes if score under the th_conf +# step b: SSD's NMS +# after all classes finished step a & b +# step c: keep keep_top_k_objects in one image for all +**********************************************/ + + +static int detected_bboxes(float *mbox_conf_flatten, dproc_bbox_param_t *bboxes, + int num_all_bboxes, dproc_ssd_detection_output_config_t *config, + dproc_ssd_detection_output_result_t *ssd_result, dproc_ssd_class_dbg_info_t *dbg_info, + dproc_ssd_detection_output_result_t *ssd_class, uint8_t *bboxes_kept_idx_array) +{ + int num_bboxes; + int ssd_result_num = 0; + int num_bboxes_post_nms; + + //DPRINT(L_DEBUG, "detected_bboxes enter\n"); + config->conf_threshold = fmax(0, config->conf_threshold); + //DPRINT(L_DEBUG, "ssd confidence threshold %f\n", config->conf_threshold); + + for (int class = 0; class < config->num_classes; class++) { + //DPRINT(L_DEBUG, "#################################################\n"); + //DPRINT(L_DEBUG, "SSD for class %d\n", class); + + /* clear ssd result to 0 first for class */ + memset(ssd_class, 0, num_all_bboxes * sizeof(dproc_ssd_detection_output_result_t)); + if (class != config->background_label_id) { + /* step a: filter out the boxes if score under the th_conf */ + num_bboxes = filter_bboxes(mbox_conf_flatten, class, bboxes, num_all_bboxes, config, ssd_class); + + /* step b: NMS */ + memset(bboxes_kept_idx_array, 0, config->nms_top_k * sizeof(uint8_t)); + num_bboxes_post_nms = nms(ssd_class, num_bboxes, config->nms_top_k, + config->nms_threshold, &ssd_result[ssd_result_num], + bboxes_kept_idx_array); + ssd_result_num += num_bboxes_post_nms; + + if (dbg_info != NULL) { + dbg_info[class].num_bboxes_above_threshold = num_bboxes; + dbg_info[class].num_bboxes_post_nms = num_bboxes_post_nms; + } + } else { + //DPRINT(L_DEBUG, "detected_bboxes: background class [%d] not handled\n", class); + } + } + + //DPRINT(L_DEBUG, "#################################################\n"); + + /* step c: keep keep_top_k_objects */ + ssd_result_num = keep_top_k(ssd_result, ssd_result_num, config->keep_top_k); + + //DPRINT(L_DEBUG, "detected_bboxes exit\n"); + + return ssd_result_num; +} + +static int check_detection_output_config(dproc_ssd_detection_output_config_t *config) +{ + int ret = 0; + + do { + if (config == NULL) { + printf("Please define dproc parameters!\n"); + ret = -1; + break; + } + + if (config->share_location != 1) { + printf("share_location only can be 1!\n"); + ret = -1; + break; + } + + if (config->code_type != AMBA_BBOX_CENTER_SIZE) { + printf("code_type only can be AMBA_BBOX_CENTER_SIZE!\n"); + ret = -1; + break; + } + + if (config->background_label_id >= config->num_classes) { + printf("background_label_id should be in range of (0~%d)!\n", (config->num_classes - 1)); + ret = -1; + break; + } + + if (config->mbox_loc_num_elements == 0) { + printf("mbox_loc_num_elements should not be 0!\n"); + ret = -1; + break; + } + + if (config->num_all_bboxes != (config->mbox_loc_num_elements >> 2)) { + printf("num_all_bboxes should be 1/4 * mbox_loc_num_elements!\n"); + ret = -1; + break; + } + + if (config->conf_threshold < 0 ) { + printf("conf_threshold cannot smaller than 0!\n"); + ret = -1; + break; + } + } while(0); + + return ret; +} + +int amba_ssd_detection_output_init(dproc_ssd_detection_output_t *ssd_detection_output, + dproc_ssd_detection_output_config_t *config) +{ + int ret = 0; + dproc_ssd_detection_output_config_t *amba_ssd_config = NULL; + dproc_bbox_param_t *bboxes = NULL; + dproc_ssd_detection_output_result_t *ssd_class = NULL; + uint8_t *bboxes_kept_idx_array = NULL; + uint32_t num_all_bboxes = 0, nms_top_k = 0; + + do { + if (config == NULL) { + printf("dproc ssd coniguration is NULL!\n"); + ret = -1; + break; + } + + if (ssd_detection_output == NULL) { + printf("Invalid ssd_detection_output!\n"); + ret = -1; + break; + } + + config->share_location = 1; + config->code_type = AMBA_BBOX_CENTER_SIZE; + if (check_detection_output_config(config) < 0) { + ret = -1; + break; + } + + num_all_bboxes = config->num_all_bboxes; + bboxes = malloc(num_all_bboxes * sizeof(dproc_bbox_param_t)); + if (bboxes == NULL) { + printf("failed to malloc bboxes\n"); + ret = -1; + break; + } + memset(bboxes, 0, num_all_bboxes * sizeof(dproc_bbox_param_t)); + + ssd_class = malloc(num_all_bboxes * sizeof(dproc_ssd_detection_output_result_t)); + if (ssd_class == NULL) { + printf("failed to malloc ssd_class\n"); + ret = -1; + break; + } + memset(ssd_class, 0, num_all_bboxes * sizeof(dproc_ssd_detection_output_result_t)); + printf("malloc ssd_class\n"); + + nms_top_k = config->nms_top_k; + bboxes_kept_idx_array = malloc(nms_top_k * sizeof(uint8_t)); + if (bboxes_kept_idx_array == NULL) { + printf("failed to malloc bboxes_kept_idx_array\n"); + ret = -1; + break; + } + memset(bboxes_kept_idx_array, 0, nms_top_k * sizeof(uint8_t)); + printf("malloc bboxes_kept_idx_array\n"); + + memset(ssd_detection_output, 0, sizeof(dproc_ssd_detection_output_t)); + amba_ssd_config = &(ssd_detection_output->config); + memcpy(amba_ssd_config, config, sizeof(dproc_ssd_detection_output_config_t)); + + ssd_detection_output->bboxes = bboxes; + ssd_detection_output->ssd_class = ssd_class; + ssd_detection_output->bboxes_kept_idx_array = bboxes_kept_idx_array; + + ssd_detection_output->max_objects = num_all_bboxes * config->num_classes; + ret = ssd_detection_output->max_objects; + } while(0); + + if (ret < 0) { + if (bboxes != NULL) { + free(bboxes); + bboxes = NULL; + } + if (ssd_class != NULL) { + free(ssd_class); + ssd_class = NULL; + } + if (bboxes_kept_idx_array != NULL) { + free(bboxes_kept_idx_array); + bboxes_kept_idx_array = NULL; + } + } + + return ret; +} + +int amba_ssd_detection_output_run(dproc_ssd_detection_output_t *ssd_detection_output, + dproc_run_ssd_detection_output_param_t *amba_ssd_param, + dproc_ssd_detection_output_result_t *amba_ssd_result, dproc_ssd_class_dbg_info_t *p_dbg_info) +{ + int ret = 0; + int i = 0; + int ssd_det_num = 0; + dproc_ssd_detection_output_config_t *ssd_detection_output_config = NULL; + dproc_bbox_param_t *bboxes = NULL; + dproc_ssd_detection_output_result_t *ssd_class = NULL; + uint8_t *bboxes_kept_idx_array = NULL; + float *mbox_priorbox = NULL; + uint8_t *mbox_loc_virt_addr = NULL; + uint8_t *mbox_conf_flatten_virt_addr = NULL; + uint32_t unnormalized = 0; + uint32_t num_all_bboxes = 0; + ssd_tf_scale_factors_t *scale_factors = NULL; + + do { + if (ssd_detection_output == NULL) { + printf("Invalid ssd_detection_output!\n"); + ret = -1; + break; + } + + if (amba_ssd_result == NULL) { + printf("Invalid dproc_ssd_detection_output_result_t!\n"); + ret = -1; + break; + } + + if (amba_ssd_param == NULL) { + printf("Invalid dproc_run_ssd_detection_output_param_t!\n"); + ret = -1; + break; + } + + if ((amba_ssd_param->mbox_loc == NULL) + || (amba_ssd_param->mbox_conf_flatten == NULL) + || (amba_ssd_param->mbox_priorbox == NULL)) { + printf("Invalid pointer for detection output's input!\n"); + ret = -1; + break; + } else { + mbox_priorbox = amba_ssd_param->mbox_priorbox; + mbox_loc_virt_addr = amba_ssd_param->mbox_loc; + mbox_conf_flatten_virt_addr = amba_ssd_param->mbox_conf_flatten; + } + + ssd_detection_output_config = &(ssd_detection_output->config); + unnormalized = ssd_detection_output_config->unnormalized; + num_all_bboxes = ssd_detection_output_config->num_all_bboxes; + + scale_factors = &(ssd_detection_output_config->scale_factors); + bboxes = ssd_detection_output->bboxes; + ssd_bboxes_decode(mbox_priorbox, (float *)mbox_loc_virt_addr, num_all_bboxes, + bboxes, scale_factors); + + ssd_class = ssd_detection_output->ssd_class; + bboxes_kept_idx_array = ssd_detection_output->bboxes_kept_idx_array; + ssd_det_num = detected_bboxes((float *)mbox_conf_flatten_virt_addr, bboxes, num_all_bboxes, + ssd_detection_output_config, amba_ssd_result, p_dbg_info, ssd_class, bboxes_kept_idx_array); + + /* Swap for TF */ + if ((scale_factors->center_x_scale != 0) && (scale_factors->center_y_scale != 0) + && (scale_factors->width_scale != 0) && (scale_factors->height_scale !=0)) { + for (i = 0; i < ssd_det_num; i++) { + swap_bbox(&amba_ssd_result[i].bbox); + } + } + + /* scale normalized bbox to real bbox */ + if (unnormalized) { + for (i = 0; i < ssd_det_num; i++) { + scale_bbox(&amba_ssd_result[i].bbox, ssd_detection_output_config->img_width, + ssd_detection_output_config->img_height); + } + + } + + ret = ssd_det_num; + } while(0); + + return ret; +} + +int amba_ssd_detection_output_deinit(dproc_ssd_detection_output_t *ssd_detection_output) +{ + int ret = 0; + + do { + if (ssd_detection_output == NULL) { + printf("Invalid ssd_detection_output!\n"); + ret = -1; + break; + } + + if (ssd_detection_output->bboxes != NULL) { + free(ssd_detection_output->bboxes); + ssd_detection_output->bboxes = NULL; + } + if (ssd_detection_output->ssd_class != NULL) { + free(ssd_detection_output->ssd_class); + ssd_detection_output->ssd_class = NULL; + } + if (ssd_detection_output->bboxes_kept_idx_array != NULL) { + free(ssd_detection_output->bboxes_kept_idx_array); + ssd_detection_output->bboxes_kept_idx_array = NULL; + } + + memset(ssd_detection_output, 0, sizeof(dproc_ssd_detection_output_t)); + } while(0); + + return ret; +} diff --git a/src/amba_ssd_detection_out.h b/src/amba_ssd_detection_out.h new file mode 100644 index 0000000..99c308b --- /dev/null +++ b/src/amba_ssd_detection_out.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * amba_ssd_detection_out.h + * + * History: + * 2018/09/29 - [Hao Qian] created + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ +#pragma once +#ifndef _AMBA_SSD_H_ +#define _AMBA_SSD_H_ +#include "define_inc.h" +#include "lib_data_process_priv.h" +#include "amba_bbox_utils.h" +#include "utils.h" + +int amba_ssd_detection_output_init(dproc_ssd_detection_output_t *ssd_detection_output, + dproc_ssd_detection_output_config_t *config); +int amba_ssd_detection_output_run(dproc_ssd_detection_output_t *ssd_detection_output, + dproc_run_ssd_detection_output_param_t *amba_ssd_param, + dproc_ssd_detection_output_result_t *amba_ssd_result, dproc_ssd_class_dbg_info_t *p_dbg_info); +int amba_ssd_detection_output_deinit(dproc_ssd_detection_output_t *ssd_detection_output); + +#endif diff --git a/src/amba_yolov3_out.c b/src/amba_yolov3_out.c new file mode 100644 index 0000000..a048c88 --- /dev/null +++ b/src/amba_yolov3_out.c @@ -0,0 +1,459 @@ +/******************************************************************************* + * amba_yolov3_out.c + * + * History: + * 2019/12/09 - [Hao Qian] created + * + * Copyright (c) 2019 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ + +#include "lib_data_process_priv.h" +#include "amba_yolov3_out.h" +#include "test_nnctrl_live.h" +#include <sys/time.h> +#include <math.h> + +float linear_approaching_to_sigmoid(float x) +{ + if (x > 0.8) { + if (x > 5.0) + return 1.0 + 2.0; + else if (x > 4.6) + return 0.25*x - 0.25 + 1; + else if (x > 1.4) + return 0.031*x + 0.756 + 0.8; + else + return 0.2*x + 0.52 + 0.5; + } + else if (x < -0.8) { + if (x < -5.0) + return 0.0 - 2.0; + else if (x < -4.6) + //return -0.3; + return 0.25*x + 1.25 - 1.0; + else if (x < -1.4) //-1.4 -1.2 + //return -0.1; + return 0.031*x + 0.243 - 0.3; + else + //return 0.1; + return 0.183*x + 0.456 - 0.1; + } + else { + return x * 0.231 + 0.495 + 0.2; + } +} + +float sigmoid(float x) +{ + float result = 0.0; + result = (float)(1. / (1. + exp(-x))); + return result; +} + +// When o is 0, 1, 2, 3, 4, it means X_min, Y_min, X_max, Y_max, Confidence +static inline int idx(uint32_t total_cls, int x, int y, int z, int h, int p, int o) +{ + return ((z * (total_cls + 5) + (o)) * h * p + y * p + x); +} + +static void yolov3_layer(float *df, dproc_yolov3_output_config_t *yolov3_output_config, + uint16_t layer_height, uint16_t layer_width, uint16_t layer_pitch, + uint32_t anchors_offset, dproc_yolov3_output_result_t *objects, + uint32_t *object_num, float *anchors) +{ + int z, y, x, c, C; + float objectness, max; + float rx, ry, rw, rh; + int num = *object_num; + float threshold = yolov3_output_config->conf_threshold; + uint32_t total_cls = yolov3_output_config->num_classes; + uint16_t img_height = yolov3_output_config->img_height; + uint16_t img_width = yolov3_output_config->img_width; + + for (y = 0; y < layer_height; y++) { + for (x = 0; x < layer_width; x++) { + for (z = 0; z < 3; z++) { + objectness = linear_approaching_to_sigmoid((float)df[idx(total_cls, x, y, z, layer_height, layer_pitch, 4)]); + if (objectness <= threshold) { + continue; + } + + max = -1e10; + C = 0; + for (c = 0; c < total_cls; c++) { + if (df[idx(total_cls, x, y, z, layer_height, layer_pitch, 5 + c)] >= max) { + max = df[idx(total_cls, x, y, z, layer_height, layer_pitch, 5 + c)]; + C = c; + } + } + + max = linear_approaching_to_sigmoid(max); + if (max <= threshold) { + continue; + } + + objectness *= max; + if (objectness <= threshold) { + continue; + } + + /* get_yolo_box */ + rx = (x + sigmoid(df[idx(total_cls, x, y, z, layer_height, layer_pitch, 0)])) / layer_width; + ry = (y + sigmoid(df[idx(total_cls, x, y, z, layer_height, layer_pitch, 1)])) / layer_height; + rw = (exp(df[idx(total_cls, x, y, z, layer_height, layer_pitch, 2)]) * anchors[2 * (z + anchors_offset) + 0]) / img_width; + rh = (exp(df[idx(total_cls, x, y, z, layer_height, layer_pitch, 3)]) * anchors[2 * (z + anchors_offset) + 1]) / img_height; + + rx -= rw / 2; + ry -= rh / 2; + rx = (rx < 0.0f) ? 0.0f : ((rx > 1.0f) ? 1.0f : rx); + ry = (ry < 0.0f) ? 0.0f : ((ry > 1.0f) ? 1.0f : ry); + + objects[num].bbox.x_min = rx; + objects[num].bbox.y_min = ry; + objects[num].bbox.x_max = + (rx + rw) < 0.0f ? 0.0f : (((rx + rw) > 1.0f) ? 1.0f : (rx + rw)); + objects[num].bbox.y_max = + (ry + rh) < 0.0f ? 0.0f : (((ry + rh) > 1.0f) ? 1.0f : (ry + rh)); + objects[num].label= C; + if (objectness > 1.0) + objectness = 1.0; + objects[num].score = objectness; + objects[num].valid = 1; + num++; + } + } + } + + *object_num = num; +} + +static void nms(dproc_yolov3_output_result_t *objects, uint32_t object_num, + float nms_threshold) +{ + int k, i, n, merge; + float left, right, low, high, a1, a2, sa; + dproc_yolov3_output_result_t *ob1, *ob2; + dproc_bbox_param_t *ob1_bbox, *ob2_bbox; + + do { + merge = 0; + + for (i = 0, ob1 = objects; i < object_num; i++, ob1++) { + if (!objects[i].valid) { + continue; + } + ob1_bbox = &(ob1->bbox); + + a1 = (ob1_bbox->x_max - ob1_bbox->x_min) * (ob1_bbox->y_max - ob1_bbox->y_min); + n = 0; + + for (k = 0, ob2 = objects; k < object_num; k++, ob2++) { + ob2_bbox = &(ob2->bbox); + if (k == i || !objects[k].valid || ob2->label != ob1->label) { + continue; + } + // calculate common ROI sa + left = ob1_bbox->x_min; + low = ob1_bbox->y_min; + right = ob1_bbox->x_max; + high = ob1_bbox->y_max; + + if (ob2_bbox->x_min > left) { + left = ob2_bbox->x_min; + } + if (ob2_bbox->x_max < right) { + right = ob2_bbox->x_max; + } + if (ob2_bbox->y_min > low) { + low = ob2_bbox->y_min; + } + if (ob2_bbox->y_max < high) { + high = ob2_bbox->y_max; + } + + if (left >= right || low >= high) { + continue; + } + + a2 = (ob2_bbox->x_max - ob2_bbox->x_min) * (ob2_bbox->y_max - ob2_bbox->y_min); + sa = (right - left) * (high - low); + + if (sa >= nms_threshold * a1 || sa >= nms_threshold * a2) + { + if (ob2->score <= ob1->score) { + objects[k].valid = 0; + } else { + n++; + } + + merge++; + } + } + + if (n) { + objects[i].valid = 0; + continue; + } + } + } while (merge); +} + +static int check_yolov3_output_config(dproc_yolov3_output_config_t *config) +{ + int ret = 0; + + do { + if (config->anchors == NULL) { + printf("anchors is empty!\n"); + ret = -1; + break; + } + + if (config->conf_threshold < 0 ) { + printf("conf_threshold cannot smaller than 0!\n"); + ret = -1; + break; + } + + if (config->nms_threshold < 0 ) { + printf("nms_threshold cannot smaller than 0!\n"); + ret = -1; + break; + } + + if (config->num_classes > MAX_CLASS_NUM) { + printf("num_classes cannot larger than 1000!\n"); + ret = -1; + break; + } + } while(0); + + return ret; +} + +int amba_yolov3_output_init(dproc_yolov3_output_t *yolov3_output, + dproc_yolov3_output_config_t *config) +{ + int ret = 0, i = 0; + uint32_t num_anchor_bboxes = 0, ratio = 0, max_objects = 0; + dproc_yolov3_output_config_t *amba_yolov3_config = NULL; + + do { + if (config == NULL) { + printf("dproc yolov3 coniguration is NULL!\n"); + ret = -1; + break; + } + + if (yolov3_output == NULL) { + printf("Invalid yolov3_output!\n"); + ret = -1; + break; + } + + if (check_yolov3_output_config(config) < 0) { + ret = -1; + break; + } + + memset(&(yolov3_output->config), 0, sizeof(dproc_yolov3_output_config_t)); + amba_yolov3_config = &(yolov3_output->config); + memcpy(amba_yolov3_config, config, sizeof(dproc_yolov3_output_config_t)); + //DPRINT(L_DEBUG, "WxH %dx%d, num_classes %d, conf_threshold %f, nms_threshold %f, tiny %d, unnormalized %d\n", + // amba_yolov3_config->img_width, amba_yolov3_config->img_height, + // amba_yolov3_config->num_classes, amba_yolov3_config->conf_threshold, + // amba_yolov3_config->nms_threshold, amba_yolov3_config->tiny_enable, + // amba_yolov3_config->unnormalized); + + // Tiny Yolov3 only has 2 feature maps, but full Yolov3 has 2 feature maps + if (config->tiny_enable) { + num_anchor_bboxes = TINY_YOLOV3_ANCHOR_NUM; + yolov3_output->feature_map_num = AMBA_YOLOV3_FEATURE_MAP_8; + yolov3_output->anchors_start_offset = 3; + } else { + num_anchor_bboxes = YOLOV3_ANCHOR_NUM; + yolov3_output->feature_map_num = AMBA_YOLOV3_FEATURE_NUM; + yolov3_output->anchors_start_offset = 6; + } + //DPRINT(L_DEBUG, "num_anchor_bboxes %d, feature_map_num %d, anchors_start_offset %d\n", + // num_anchor_bboxes, yolov3_output->feature_map_num, yolov3_output->anchors_start_offset); + + amba_yolov3_config->anchors = (float *)malloc(num_anchor_bboxes * sizeof(float)); + if (amba_yolov3_config->anchors == NULL) { + printf("failed to malloc anchor bboxes\n"); + ret = -1; + break; + } + memcpy((uint8_t *)(amba_yolov3_config->anchors), (uint8_t *)(config->anchors), num_anchor_bboxes * sizeof(float)); + //DPRINT(L_DEBUG, "anchors:"); + //for (i = 0; i < (num_anchor_bboxes - 1); i ++) { + // DPRINT(L_DEBUG, "%f, ", amba_yolov3_config->anchors[i]); + //} + //DPRINT(L_DEBUG, "%f\n", amba_yolov3_config->anchors[i]); + + for (i = 0; i < yolov3_output->feature_map_num; i++) { + ratio = 32 >> i; + yolov3_output->feature_map_width[i] = config->img_width / ratio; + yolov3_output->feature_map_height[i] = config->img_height / ratio; + yolov3_output->feature_map_pitch[i] = + config->padding_disable ? yolov3_output->feature_map_width[i] : + ((ROUND_UP_32(sizeof(float) * yolov3_output->feature_map_width[i])) / sizeof(float)); + max_objects += yolov3_output->feature_map_height[i] * yolov3_output->feature_map_width[i]; + //DPRINT(L_DEBUG, "Ratio %d feature_map_width %d, feature_map_height %d, feature_map_pitch %d\n", + // ratio, yolov3_output->feature_map_width[i], + // yolov3_output->feature_map_height[i], yolov3_output->feature_map_pitch[i]); + } + yolov3_output->max_objects = max_objects * 3; + ret = yolov3_output->max_objects; + //DPRINT(L_DEBUG, "max_objects %d\n", ret); + } while(0); + + if (ret < 0) { + if (amba_yolov3_config->anchors != NULL) { + free(amba_yolov3_config->anchors); + amba_yolov3_config->anchors = NULL; + } + } + + return ret; +} + +int comp(const void *a, const void *b) { + return (*(dproc_yolov3_output_result_t *)a).score < (*(dproc_yolov3_output_result_t *)b).score ? 1 : -1; +} + +int amba_yolov3_output_run(dproc_yolov3_output_t *yolov3_output, + dproc_run_yolov3_output_param_t *amba_yolov3_param, + dproc_yolov3_output_result_t *amba_yolov3_result, float nms_threshold) +{ + int ret = 0, i = 0; + uint32_t unnormalized = 0, object_num = 0, anchors_start_offset = 0; + dproc_yolov3_output_config_t *yolov3_output_config = NULL; + float *feature_map[AMBA_YOLOV3_FEATURE_NUM]; + dproc_yolov3_output_result_t *objects = NULL; + + do { + if (yolov3_output == NULL) { + printf("Invalid yolov3_output!\n"); + ret = -1; + break; + } + + if (amba_yolov3_result == NULL) { + printf("Invalid dproc_yolov3_output_result_t!\n"); + ret = -1; + break; + } + + if (amba_yolov3_param == NULL) { + printf("Invalid dproc_run_yolov3_output_param_t!\n"); + ret = -1; + break; + } + + for (i = 0; i < yolov3_output->feature_map_num; i++) { + if (amba_yolov3_param->feature_map[i] == NULL) { + printf("Invalid pointer for yolov3's feature map[%d]!\n", i); + break; + } + + feature_map[i] = amba_yolov3_param->feature_map[i]; + } + if (i != yolov3_output->feature_map_num) { + ret = -1; + break; + } + + yolov3_output_config = &(yolov3_output->config); + objects = amba_yolov3_result; + + // get all the objects from feature maps + //printf("\n-------feature_map_num:%d\n", yolov3_output->feature_map_num); + for (i = 0; i < yolov3_output->feature_map_num; i++) { + anchors_start_offset = yolov3_output->anchors_start_offset - i * 3; + + yolov3_layer(feature_map[i], yolov3_output_config, + yolov3_output->feature_map_height[i], + yolov3_output->feature_map_width[i], + yolov3_output->feature_map_pitch[i], + anchors_start_offset, objects, &object_num, yolov3_output_config->anchors); + + //printf("\nwidth:%d,height:%d\n", yolov3_output->feature_map_width[i], yolov3_output->feature_map_height[i]); + + //DPRINT(L_DEBUG, "feature map %d: object_num %d\n", i, object_num); + } + + + //printf("\n-------------object_num:%d\n", object_num); + // get valid objects with nms + qsort(objects, object_num, sizeof(dproc_yolov3_output_result_t), comp); + //nms(objects, object_num, yolov3_output_config->nms_threshold); + nms(objects, object_num, get_nms_thres(nms_threshold)); + + /* scale normalized bbox to real bbox */ + unnormalized = yolov3_output_config->unnormalized; + if (unnormalized) { + for (i = 0; i < object_num; i++) { + if (!objects[i].valid) { + continue; + } + + scale_bbox(&amba_yolov3_result[i].bbox, yolov3_output_config->img_width, + yolov3_output_config->img_height); + } + } + + ret = object_num; + } while(0); + + return ret; +} + +int amba_yolov3_output_deinit(dproc_yolov3_output_t *yolov3_output) +{ + int ret = 0; + + do { + if (yolov3_output == NULL) { + printf("Invalid yolov3_output!\n"); + ret = -1; + break; + } + + if (yolov3_output->config.anchors != NULL) { + free(yolov3_output->config.anchors); + yolov3_output->config.anchors = NULL; + } + + memset(yolov3_output, 0, sizeof(dproc_yolov3_output_t)); + } while(0); + + return ret; +} diff --git a/src/amba_yolov3_out.h b/src/amba_yolov3_out.h new file mode 100644 index 0000000..14cb86d --- /dev/null +++ b/src/amba_yolov3_out.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * amba_yolov3_out.h + * + * History: + * 2019/12/09 - [Hao Qian] created + * + * Copyright (c) 2019 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * +******************************************************************************/ +#pragma once +#ifndef _AMBA_YOLOV3_H_ +#define _AMBA_YOLOV3_H_ +#include "define_inc.h" +#include "lib_data_process_priv.h" +#include "amba_bbox_utils.h" +#include "utils.h" +#include <math.h> + +#define LOGACT(x) (1.0f / (1.0f + exp(-x))) + +float linear_approaching_to_sigmoid(float x); + +int amba_yolov3_output_init(dproc_yolov3_output_t *yolov3_output, + dproc_yolov3_output_config_t *config); +int amba_yolov3_output_run(dproc_yolov3_output_t *yolov3_output, + dproc_run_yolov3_output_param_t *amba_yolov3_param, + dproc_yolov3_output_result_t *amba_yolov3_result, float nms_threshold); +int amba_yolov3_output_deinit(dproc_yolov3_output_t *yolov3_output); + +#endif diff --git a/src/anpr_rule.c b/src/anpr_rule.c new file mode 100644 index 0000000..9fb3a96 --- /dev/null +++ b/src/anpr_rule.c @@ -0,0 +1,449 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "utility.h" +#include "anpr_rule.h" +#include "k_means.h" + +//int plate_number_count; +//detection_sub_properties mea_sub_properties[10]; +KmeansPoint mea_label_points[30] = { 0 }; +int g_far_idx = 0; + +void farthest_point(detection_pos* pNext) +{ + int ISubLabelNumber = 0; + int total_dis[10] = { 0 }; + + + ISubLabelNumber = pNext->plate_number_count; + + for (int i = 0; i < ISubLabelNumber; i++) + { + total_dis[i] = 0; + g_far_idx = 0; + for (int j = 0; j < ISubLabelNumber; j++) + { + if (i != j) + { + total_dis[i] += abs(mea_label_points[i].x - mea_label_points[j].x); + } + } + //printf("%d, total dis = %d \n", i, total_dis[i]); + + if (total_dis[i] > total_dis[g_far_idx]) + { + g_far_idx = i; + } + } + + //printf("far_idx = %d \n", g_far_idx); +} + +void label_cluster(detection_pos* pNext) +{ + int ISubLabelNumber = 0; + + ISubLabelNumber = pNext->plate_number_count; + + if (ISubLabelNumber > 0) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + mea_label_points[i].x = (int)pNext->mea_sub_properties[i].box_x; + mea_label_points[i].w = (int)pNext->mea_sub_properties[i].box_w; + //printf("%d, x= %d \n", i, mea_label_points[i].x); + } + + mea_plate_kmeans(mea_label_points, ISubLabelNumber); + } +} + +void rule_sharjah(detection_pos* pNext) +{ + //int iPlate_len = 0; + int ISubLabelNumber = 0; + int iRow_1_num = 0; + int iRow_2_num = 0; + int iFirstNum = -1; + + + + //printf("In rule sharjah, first char = %s\n", &(pNext->properties.plate[0])); + + //iPlate_len = strlen(pNext->properties.plate); + ISubLabelNumber = pNext->plate_number_count; + + if (strlen(pNext->mea_sub_properties[0].name) > 0) + { + iFirstNum = atoi(pNext->mea_sub_properties[0].name); + //printf("recoder name = %s, %d \n", pNext->mea_sub_properties[0].name, iFirstNum); + } + + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 1) + iRow_1_num++; + else if (pNext->mea_sub_properties[i].number_row == 2) + iRow_2_num++; + + mea_label_points->x = (int)pNext->mea_sub_properties[i].box_x; + } + + //printf("row1 = %d, row2 = %d \n", iRow_1_num, iRow_2_num); + //printf("iFirstNum = %d \n", iFirstNum); + + if (iRow_2_num > 0) + { + if (iFirstNum >= 1 && + iFirstNum <= 5) + { + insert_string(pNext->properties.plate, " ", 1); + //printf("MEA plate Sharjah = %s \n\n", pNext->properties.plate); + } + else + { + //printf("MEA plate Sharjah, first number illigal = %s \n\n", pNext->properties.plate); + pNext->confidence = 0.0; + } + } + else if (iRow_1_num > 0 && iRow_2_num == 0) + { + //mea_plate_kmeans(KmeansPoint *label_points, int point_num); + mea_plate_kmeans(mea_label_points, ISubLabelNumber); + } + + + + //else if (pNext->mea_sub_properties[0].number_row == 1) { + //(PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; + + //} + +} + +void check_rule(detection_pos* pNext) +{ + int iCluster0_num = 0; + int iCluster1_num = 0; + int iRow_1_num = 0; + int iRow_2_num = 0; + int ISubLabelNumber = pNext->plate_number_count; + + //int type_num; + //int lablel_num; + + char temp_plate[10] = { 0 }; + + //printf("bef plate = %s, %s, %s \n", pNext->properties.plate, pNext->properties.country, pNext->properties.area); + // 000000, MEA, Sharjah + + if (ISubLabelNumber > 0) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 1) + iRow_1_num++; + else if (pNext->mea_sub_properties[i].number_row == 2) + iRow_2_num++; + } + + if (iRow_1_num > 0 && iRow_2_num > 0) + { + //printf("in case a \n"); + //printf("case a row1: %d, row2: %d \n", iRow_1_num, iRow_2_num); + + + if (iRow_1_num < iRow_2_num) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 1) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + + strcat(temp_plate, " "); + + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 2) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + } + else if (iRow_1_num > iRow_2_num) + { + if (iRow_1_num == 2 && + pNext->mea_sub_properties[2].iIsDigit == 1 + ) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 1) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + + strcat(temp_plate, " "); + + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 2) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + } + else + { + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 2) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + + strcat(temp_plate, " "); + + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 1) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + } + } + else if (iRow_1_num == iRow_2_num) + { + if (iRow_1_num == 2 && iRow_2_num == 2) + { + //if (pNext->mea_sub_properties[0].iIsDigit == 1 && pNext->mea_sub_properties[1].iIsDigit == 1) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 1) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + + strcat(temp_plate, " "); + + for (int i = 0; i < ISubLabelNumber; i++) + { + if (pNext->mea_sub_properties[i].number_row == 2) + strcat(temp_plate, pNext->mea_sub_properties[i].name); + } + + } + } + else if (iRow_1_num == 1 && iRow_2_num == 1) + { + printf("in case a \n"); + if (pNext->mea_sub_properties[0].iIsDigit == 1 && pNext->mea_sub_properties[1].iIsAlpha == 1) + { + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[0].name); + } + else if (pNext->mea_sub_properties[0].iIsAlpha == 1 && pNext->mea_sub_properties[1].iIsDigit == 1) + { + strcat(temp_plate, pNext->mea_sub_properties[0].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[1].name); + } + } + else + pNext->confidence = 0; + } + } + else if ((iRow_1_num > 0 && iRow_2_num == 0) || + (iRow_1_num == 0 && iRow_2_num > 0) ) + { + //printf("in case b \n"); + label_cluster(pNext); + + for (int i = 0; i < ISubLabelNumber; i++) + { + if (mea_label_points[i].cluster_idx == 0) + iCluster0_num++; + else if (mea_label_points[i].cluster_idx == 1) + iCluster1_num++; + } + + if (ISubLabelNumber == 2) + { + if (pNext->mea_sub_properties[0].iIsAlpha == 1 && + pNext->mea_sub_properties[1].iIsDigit == 1) + { + //Case: B2 + strcat(temp_plate, pNext->mea_sub_properties[0].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + } + else if (pNext->mea_sub_properties[0].iIsDigit == 1 && + pNext->mea_sub_properties[1].iIsAlpha == 1 + ) + { + //Case: 2B + { + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[0].name); + } + + //Case: 8888 + } + else if ((iCluster0_num == 1 && iCluster1_num == 1) && + (pNext->mea_sub_properties[0].iIsDigit == 1 && pNext->mea_sub_properties[1].iIsDigit == 1)) + { + //Case: 22 + strcat(temp_plate, pNext->mea_sub_properties[0].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[1].name); + } + else + pNext->confidence = 0; + } + else if ((iCluster0_num == iCluster1_num) && + iCluster0_num > 2 + ) + { + farthest_point(pNext); + if (g_far_idx == 0 && + pNext->mea_sub_properties[0].iIsAlpha == 1) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + strcat(temp_plate, pNext->mea_sub_properties[i].name); + if (i == 0) + strcat(temp_plate, " "); + } + } + else + { + pNext->confidence = 0; + } + } + else if ((iCluster0_num == iCluster1_num) && + iCluster0_num == 2) + { + if (pNext->mea_sub_properties[0].iIsAlpha == 1 && + pNext->mea_sub_properties[1].iIsAlpha == 1) + { + //Case: AA 00 + strcat(temp_plate, pNext->mea_sub_properties[0].name); + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[2].name); + strcat(temp_plate, pNext->mea_sub_properties[3].name); + + } + else if (pNext->mea_sub_properties[0].iIsDigit == 1 && + pNext->mea_sub_properties[1].iIsDigit == 1 + ) + { + //Case: 20 88 + { + strcat(temp_plate, pNext->mea_sub_properties[0].name); + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[2].name); + strcat(temp_plate, pNext->mea_sub_properties[3].name); + } + + //Case: 8888 + } + } + else if ((iCluster0_num < iCluster1_num) && + iCluster0_num == 2) + { + if (pNext->mea_sub_properties[0].iIsAlpha == 1 && + pNext->mea_sub_properties[1].iIsAlpha == 1) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + strcat(temp_plate, pNext->mea_sub_properties[i].name); + if (i == 1) + strcat(temp_plate, " "); + } + } + else if (pNext->mea_sub_properties[0].iIsDigit == 1 && + pNext->mea_sub_properties[1].iIsDigit == 1) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + strcat(temp_plate, pNext->mea_sub_properties[i].name); + if (i == 1) + strcat(temp_plate, " "); + } + } + else if (pNext->mea_sub_properties[0].iIsAlpha == 1 && + pNext->mea_sub_properties[1].iIsDigit == 1) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + strcat(temp_plate, pNext->mea_sub_properties[i].name); + if (i == 0) + strcat(temp_plate, " "); + } + } + } + else if ((iCluster0_num < iCluster1_num) && + iCluster0_num == 1) + { + for (int i = 0; i < ISubLabelNumber; i++) + { + strcat(temp_plate, pNext->mea_sub_properties[i].name); + if (i == 0) + strcat(temp_plate, " "); + } + } + else if ((iCluster1_num < iCluster0_num) && + iCluster0_num == 2) + { + if (pNext->mea_sub_properties[0].iIsAlpha == 1 && + pNext->mea_sub_properties[1].iIsAlpha == 1) + { + strcat(temp_plate, pNext->mea_sub_properties[0].name); + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[2].name); + } + else if (pNext->mea_sub_properties[0].iIsDigit == 1 && + pNext->mea_sub_properties[1].iIsDigit == 1) + { + strcat(temp_plate, pNext->mea_sub_properties[0].name); + strcat(temp_plate, pNext->mea_sub_properties[1].name); + + strcat(temp_plate, " "); + + strcat(temp_plate, pNext->mea_sub_properties[2].name); + } + else + pNext->confidence = 0; + } + } + } + else + pNext->confidence = 0; + + //printf("aft parset plate = %s, confidence = %f \n", temp_plate, pNext->confidence); + + if (pNext->confidence != 0) + sprintf(pNext->properties.plate, "%s", temp_plate); + + //if (strcmp("Sharjah", pNext->properties.area) == 0) { + // rule_sharjah(pNext); + //} +} \ No newline at end of file diff --git a/src/anpr_rule.h b/src/anpr_rule.h new file mode 100644 index 0000000..f74a6fd --- /dev/null +++ b/src/anpr_rule.h @@ -0,0 +1,8 @@ +#pragma once +#ifndef ANPR_RULE_API +#define ANPR_RULE_API +#include "utility.h" + +void check_rule(detection_pos* pNext); + +#endif \ No newline at end of file diff --git a/src/art.c b/src/art.c new file mode 100644 index 0000000..5d62550 --- /dev/null +++ b/src/art.c @@ -0,0 +1,61 @@ +#include "darknet.h" +#include "utils.h" +#include "blas.h" + +#include <sys/time.h> + +void demo_art(char *cfgfile, char *weightfile, int cam_index) +{ +#ifdef OPENCV + network *net = load_network(cfgfile, weightfile, 0); + set_batch_network(net, 1); + + srand(2222222); + + void * cap = open_video_stream(0, cam_index, 0,0,0); + + char *window = "ArtJudgementBot9000!!!"; + if(!cap) error("Couldn't connect to webcam.\n"); + int i; + int idx[] = {37, 401, 434}; + int n = sizeof(idx)/sizeof(idx[0]); + + while(1){ + image in = get_image_from_stream(cap); + image in_s = resize_image(in, net->w, net->h); + + float *p = network_predict(net, in_s.data); + + printf("\033[2J"); + printf("\033[1;1H"); + + float score = 0; + for(i = 0; i < n; ++i){ + float s = p[idx[i]]; + if (s > score) score = s; + } + score = score; + printf("I APPRECIATE THIS ARTWORK: %10.7f%%\n", score*100); + printf("["); + int upper = 30; + for(i = 0; i < upper; ++i){ + printf("%c", ((i+.5) < score*upper) ? 219 : ' '); + } + printf("]\n"); + + show_image(in, window, 1); + free_image(in_s); + free_image(in); + } +#endif +} + + +void run_art(int argc, char **argv) +{ + int cam_index = find_int_arg(argc, argv, "-c", 0); + char *cfg = argv[2]; + char *weights = argv[3]; + demo_art(cfg, weights, cam_index); +} + diff --git a/src/auto_tchar.h b/src/auto_tchar.h new file mode 100644 index 0000000..4e49dd1 --- /dev/null +++ b/src/auto_tchar.h @@ -0,0 +1,499 @@ + +#pragma once +#ifndef __AUTO_TCHAR_H_INCLUDED +#define __AUTO_TCHAR_H_INCLUDED +#include "define_inc.h" +#define __MSVCRT_VERSION__ 0x0000 +// __AUTO_TCHAR_H_USESYS: check if support <tchar.h> +#undef __AUTO_TCHAR_H_USESYS +#if defined(_MSC_VER) // MSVC. + #define __AUTO_TCHAR_H_USESYS +#elif defined(__BORLANDC__) // BCB. + #define __AUTO_TCHAR_H_USESYS +#elif defined(_WIN32)||defined(_WIN64)||defined(__MINGW32__)||defined(__MINGW64__)||defined(__CYGWIN__) + // if Windows plate <tchar.h>. + #define __AUTO_TCHAR_H_USESYS +#else + // other, not support <tchar.h>. +#endif // __AUTO_TCHAR_H_USESYS + + +#ifdef __AUTO_TCHAR_H_USESYS +// tchar.h . + #include <tchar.h> + // + #if defined(__BORLANDC__) && !defined(_TCHAR_DEFINED) + typedef _TCHAR TCHAR, *PTCHAR; + typedef _TCHAR TBYTE, *PTBYTE; + #define _TCHAR_DEFINED + #endif // #if defined(__BORLANDC__) && !defined(_TCHAR_DEFINED) +#else +// + +#ifndef _TCHAR_H_ +#define _TCHAR_H_ + +///* All the headers include this file. */ +//#include <_mingw.h> + +/* + * NOTE: This tests _UNICODE, which is different from the UNICODE define + * used to differentiate Win32 API calls. + */ +#ifdef _UNICODE + +/* + * Include <wchar.h> for wchar_t and WEOF if _UNICODE. + */ +#include <wchar.h> + +/* + * Use TCHAR instead of char or wchar_t. It will be appropriately translated + * if _UNICODE is correctly defined (or not). + */ +#ifndef _TCHAR_DEFINED +#ifndef RC_INVOKED +typedef wchar_t TCHAR; +typedef wchar_t _TCHAR; +#endif /* Not RC_INVOKED */ +#define _TCHAR_DEFINED +#endif + +/* + * Use _TEOF instead of EOF or WEOF. It will be appropriately translated if + * _UNICODE is correctly defined (or not). + */ +#define _TEOF WEOF + +/* + * __TEXT is a private macro whose specific use is to force the expansion of a + * macro passed as an argument to the macros _T or _TEXT. DO NOT use this + * macro within your programs. It's name and function could change without + * notice. + */ +#define __TEXT(q) L##q + +/* for porting from other Windows compilers */ +#if 0 /* no wide startup module */ +#define _tmain wmain +#define _tWinMain wWinMain +#define _tenviron _wenviron +#define __targv __wargv +#endif + +/* + * Unicode functions + */ +#define _tprintf wprintf +#define _ftprintf fwprintf +#define _stprintf swprintf +#define _sntprintf _snwprintf +#define _vtprintf vwprintf +#define _vftprintf vfwprintf +#define _vstprintf vswprintf +#define _vsntprintf _vsnwprintf +#define _vsctprintf _vscwprintf +#define _tscanf wscanf +#define _ftscanf fwscanf +#define _stscanf swscanf +#define _fgettc fgetwc +#define _fgettchar _fgetwchar +#define _fgetts fgetws +#define _fputtc fputwc +#define _fputtchar _fputwchar +#define _fputts fputws +#define _gettc getwc +#define _getts _getws +#define _puttc putwc +#define _puttchar putwchar +#define _putts _putws +#define _ungettc ungetwc +#define _tcstod wcstod +#define _tcstol wcstol +#define _tcstoul wcstoul +#define _itot _itow +#define _ltot _ltow +#define _ultot _ultow +#define _ttoi _wtoi +#define _ttol _wtol +#define _tcscat wcscat +#define _tcschr wcschr +#define _tcscmp wcscmp +#define _tcscpy wcscpy +#define _tcscspn wcscspn +#define _tcslen wcslen +#define _tcsncat wcsncat +#define _tcsncmp wcsncmp +#define _tcsncpy wcsncpy +#define _tcspbrk wcspbrk +#define _tcsrchr wcsrchr +#define _tcsspn wcsspn +#define _tcsstr wcsstr +#define _tcstok wcstok +#define _tcsdup _wcsdup +#define _tcsicmp _wcsicmp +#define _tcsnicmp _wcsnicmp +#define _tcsnset _wcsnset +#define _tcsrev _wcsrev +#define _tcsset _wcsset +#define _tcslwr _wcslwr +#define _tcsupr _wcsupr +#define _tcsxfrm wcsxfrm +#define _tcscoll wcscoll +#define _tcsicoll _wcsicoll +#define _istalpha iswalpha +#define _istupper iswupper +#define _istlower iswlower +#define _istdigit iswdigit +#define _istxdigit iswxdigit +#define _istspace iswspace +#define _istpunct iswpunct +#define _istalnum iswalnum +#define _istprint iswprint +#define _istgraph iswgraph +#define _istcntrl iswcntrl +#define _istascii iswascii +#define _totupper towupper +#define _totlower towlower +#define _tcsftime wcsftime +/* Macro functions */ +#define _tcsdec _wcsdec +#define _tcsinc _wcsinc +#define _tcsnbcnt _wcsncnt +#define _tcsnccnt _wcsncnt +#define _tcsnextc _wcsnextc +#define _tcsninc _wcsninc +#define _tcsspnp _wcsspnp +#define _wcsdec(_wcs1, _wcs2) ((_wcs1)>=(_wcs2) ? NULL : (_wcs2)-1) +#define _wcsinc(_wcs) ((_wcs)+1) +#define _wcsnextc(_wcs) ((unsigned int) *(_wcs)) +#define _wcsninc(_wcs, _inc) (((_wcs)+(_inc))) +#define _wcsncnt(_wcs, _cnt) ((wcslen(_wcs)>_cnt) ? _count : wcslen(_wcs)) +#define _wcsspnp(_wcs1, _wcs2) ((*((_wcs1)+wcsspn(_wcs1,_wcs2))) ? ((_wcs1)+wcsspn(_wcs1,_wcs2)) : NULL) + +#if 1 /* defined __MSVCRT__ */ +/* + * These wide functions not in crtdll.dll. + * Define macros anyway so that _wfoo rather than _tfoo is undefined + */ +#define _ttoi64 _wtoi64 +#define _i64tot _i64tow +#define _ui64tot _ui64tow +#define _tasctime _wasctime +#define _tctime _wctime +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tctime32 _wctime32 +#define _tctime64 _wctime64 +#endif /* __MSVCRT_VERSION__ >= 0x0800 */ +#define _tstrdate _wstrdate +#define _tstrtime _wstrtime +#define _tutime _wutime +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tutime64 _wutime64 +#define _tutime32 _wutime32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#define _tcsnccoll _wcsncoll +#define _tcsncoll _wcsncoll +#define _tcsncicoll _wcsnicoll +#define _tcsnicoll _wcsnicoll +#define _taccess _waccess +#define _tchmod _wchmod +#define _tcreat _wcreat +#define _tfindfirst _wfindfirst +#define _tfindnext _wfindnext +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tfindfirst64 _wfindfirst64 +#define _tfindfirst32 _wfindfirst32 +#define _tfindnext64 _wfindnext64 +#define _tfindnext32 _wfindnext32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#define _tfdopen _wfdopen +#define _tfopen _wfopen +#define _tfreopen _wfreopen +#define _tfsopen _wfsopen +#define _tgetenv _wgetenv +#define _tputenv _wputenv +#define _tsearchenv _wsearchenv +#define _tsystem _wsystem +#define _tmakepath _wmakepath +#define _tsplitpath _wsplitpath +#define _tfullpath _wfullpath +#define _tmktemp _wmktemp +#define _topen _wopen +#define _tremove _wremove +#define _trename _wrename +#define _tsopen _wsopen +#define _tsetlocale _wsetlocale +#define _tunlink _wunlink +#define _tfinddata_t _wfinddata_t +#define _tfindfirsti64 _wfindfirsti64 +#define _tfindnexti64 _wfindnexti64 +#define _tfinddatai64_t _wfinddatai64_t +#if __MSVCRT_VERSION__ >= 0x0601 +#define _tfinddata64_t _wfinddata64_t +#endif +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tfinddata32_t _wfinddata32_t +#define _tfinddata32i64_t _wfinddata32i64_t +#define _tfinddata64i32_t _wfinddata64i32_t +#define _tfindfirst32i64 _wfindfirst32i64 +#define _tfindfirst64i32 _wfindfirst64i32 +#define _tfindnext32i64 _wfindnext32i64 +#define _tfindnext64i32 _wfindnext64i32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#define _tchdir _wchdir +#define _tgetcwd _wgetcwd +#define _tgetdcwd _wgetdcwd +#define _tmkdir _wmkdir +#define _trmdir _wrmdir +#define _tstat _wstat +#define _tstati64 _wstati64 +#define _tstat64 _wstat64 +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tstat32 _wstat32 +#define _tstat32i64 _wstat32i64 +#define _tstat64i32 _wstat64i32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#endif /* __MSVCRT__ */ + +/* dirent structures and functions */ +#define _tdirent _wdirent +#define _TDIR _WDIR +#define _topendir _wopendir +#define _tclosedir _wclosedir +#define _treaddir _wreaddir +#define _trewinddir _wrewinddir +#define _ttelldir _wtelldir +#define _tseekdir _wseekdir + +#else /* Not _UNICODE */ + +/* + * TCHAR, the type you should use instead of char. + */ +#ifndef _TCHAR_DEFINED +#ifndef RC_INVOKED +typedef char TCHAR; +typedef char _TCHAR; +#endif +#define _TCHAR_DEFINED +#endif + +/* + * _TEOF, the constant you should use instead of EOF. + */ +#define _TEOF EOF + +/* + * __TEXT is a private macro whose specific use is to force the expansion of a + * macro passed as an argument to the macros _T or _TEXT. DO NOT use this + * macro within your programs. It's name and function could change without + * notice. + */ +#define __TEXT(q) q + +/* for porting from other Windows compilers */ +#define _tmain main +#define _tWinMain WinMain +#define _tenviron _environ +#define __targv __argv + +/* + * Non-unicode (standard) functions + */ + +#define _tprintf printf +#define _ftprintf fprintf +#define _stprintf sprintf +#define _sntprintf _snprintf +#define _vtprintf vprintf +#define _vftprintf vfprintf +#define _vstprintf vsprintf +#define _vsntprintf _vsnprintf +#define _vsctprintf _vscprintf +#define _tscanf scanf +#define _ftscanf fscanf +#define _stscanf sscanf +#define _fgettc fgetc +#define _fgettchar _fgetchar +#define _fgetts fgets +#define _fputtc fputc +#define _fputtchar _fputchar +#define _fputts fputs +#define _tfdopen _fdopen +#define _tfopen fopen +#define _tfreopen freopen +#define _tfsopen _fsopen +#define _tgetenv getenv +#define _tputenv _putenv +#define _tsearchenv _searchenv +#define _tsystem system +#define _tmakepath _makepath +#define _tsplitpath _splitpath +#define _tfullpath _fullpath +#define _gettc getc +#define _getts gets +#define _puttc putc +#define _puttchar putchar +#define _putts puts +#define _ungettc ungetc +#define _tcstod strtod +#define _tcstol strtol +#define _tcstoul strtoul +#define _itot _itoa +#define _ltot _ltoa +#define _ultot _ultoa +#define _ttoi atoi +#define _ttol atol +#define _tcscat strcat +#define _tcschr strchr +#define _tcscmp strcmp +#define _tcscpy strcpy +#define _tcscspn strcspn +#define _tcslen strlen +#define _tcsncat strncat +#define _tcsncmp strncmp +#define _tcsncpy strncpy +#define _tcspbrk strpbrk +#define _tcsrchr strrchr +#define _tcsspn strspn +#define _tcsstr strstr +#define _tcstok strtok +#define _tcsdup _strdup +#define _tcsicmp _stricmp +#define _tcsnicmp _strnicmp +#define _tcsnset _strnset +#define _tcsrev _strrev +#define _tcsset _strset +#define _tcslwr _strlwr +#define _tcsupr _strupr +#define _tcsxfrm strxfrm +#define _tcscoll strcoll +#define _tcsicoll _stricoll +#define _istalpha isalpha +#define _istupper isupper +#define _istlower islower +#define _istdigit isdigit +#define _istxdigit isxdigit +#define _istspace isspace +#define _istpunct ispunct +#define _istalnum isalnum +#define _istprint isprint +#define _istgraph isgraph +#define _istcntrl iscntrl +#define _istascii isascii +#define _totupper toupper +#define _totlower tolower +#define _tasctime asctime +#define _tctime ctime +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tctime32 _ctime32 +#define _tctime64 _ctime64 +#endif /* __MSVCRT_VERSION__ >= 0x0800 */ +#define _tstrdate _strdate +#define _tstrtime _strtime +#define _tutime _utime +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tutime64 _utime64 +#define _tutime32 _utime32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#define _tcsftime strftime +/* Macro functions */ +#define _tcsdec _strdec +#define _tcsinc _strinc +#define _tcsnbcnt _strncnt +#define _tcsnccnt _strncnt +#define _tcsnextc _strnextc +#define _tcsninc _strninc +#define _tcsspnp _strspnp +#define _strdec(_str1, _str2) ((_str1)>=(_str2) ? NULL : (_str2)-1) +#define _strinc(_str) ((_str)+1) +#define _strnextc(_str) ((unsigned int) *(_str)) +#define _strninc(_str, _inc) (((_str)+(_inc))) +#define _strncnt(_str, _cnt) ((strlen(_str)>_cnt) ? _count : strlen(_str)) +#define _strspnp(_str1, _str2) ((*((_str1)+strspn(_str1,_str2))) ? ((_str1)+strspn(_str1,_str2)) : NULL) + +#define _tchmod _chmod +#define _tcreat _creat +#define _tfindfirst _findfirst +#define _tfindnext _findnext +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tfindfirst64 _findfirst64 +#define _tfindfirst32 _findfirst32 +#define _tfindnext64 _findnext64 +#define _tfindnext32 _findnext32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#define _tmktemp _mktemp +#define _topen _open +#define _taccess _access +#define _tremove remove +#define _trename rename +#define _tsopen _sopen +#define _tsetlocale setlocale +#define _tunlink _unlink +#define _tfinddata_t _finddata_t +#define _tchdir _chdir +#define _tgetcwd _getcwd +#define _tgetdcwd _getdcwd +#define _tmkdir _mkdir +#define _trmdir _rmdir +#define _tstat _stat + +#if 1 /* defined __MSVCRT__ */ +/* Not in crtdll.dll. Define macros anyway? */ +#define _ttoi64 _atoi64 +#define _i64tot _i64toa +#define _ui64tot _ui64toa +#define _tcsnccoll _strncoll +#define _tcsncoll _strncoll +#define _tcsncicoll _strnicoll +#define _tcsnicoll _strnicoll +#define _tfindfirsti64 _findfirsti64 +#define _tfindnexti64 _findnexti64 +#define _tfinddatai64_t _finddatai64_t +#if __MSVCRT_VERSION__ >= 0x0601 +#define _tfinddata64_t _finddata64_t +#endif +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tfinddata32_t _finddata32_t +#define _tfinddata32i64_t _finddata32i64_t +#define _tfinddata64i32_t _finddata64i32_t +#define _tfindfirst32i64 _findfirst32i64 +#define _tfindfirst64i32 _findfirst64i32 +#define _tfindnext32i64 _findnext32i64 +#define _tfindnext64i32 _findnext64i32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#define _tstati64 _stati64 +#define _tstat64 _stat64 +#if __MSVCRT_VERSION__ >= 0x0800 +#define _tstat32 _stat32 +#define _tstat32i64 _stat32i64 +#define _tstat64i32 _stat64i32 +#endif /* __MSVCRT_VERSION__ > 0x0800 */ +#endif /* __MSVCRT__ */ + +/* dirent structures and functions */ +#define _tdirent dirent +#define _TDIR DIR +#define _topendir opendir +#define _tclosedir closedir +#define _treaddir readdir +#define _trewinddir rewinddir +#define _ttelldir telldir +#define _tseekdir seekdir + +#endif /* Not _UNICODE */ + +/* + * UNICODE a constant string when _UNICODE is defined else returns the string + * unmodified. Also defined in w32api/winnt.h. + */ +#define _TEXT(x) __TEXT(x) +#define _T(x) __TEXT(x) + +#endif /* Not _TCHAR_H_ */ + + +#endif // #ifdef __AUTO_TCHAR_H_USESYS + +#endif // #ifndef __AUTO_TCHAR_H_INCLUDED \ No newline at end of file diff --git a/src/avgpool_layer.c b/src/avgpool_layer.c new file mode 100644 index 0000000..83034db --- /dev/null +++ b/src/avgpool_layer.c @@ -0,0 +1,71 @@ +#include "avgpool_layer.h" +#include "cuda.h" +#include <stdio.h> + +avgpool_layer make_avgpool_layer(int batch, int w, int h, int c) +{ + fprintf(stderr, "avg %4d x%4d x%4d -> %4d\n", w, h, c, c); + avgpool_layer l = {0}; + l.type = AVGPOOL; + l.batch = batch; + l.h = h; + l.w = w; + l.c = c; + l.out_w = 1; + l.out_h = 1; + l.out_c = c; + l.outputs = l.out_c; + l.inputs = h*w*c; + int output_size = l.outputs * batch; + l.output = calloc(output_size, sizeof(float)); + l.delta = calloc(output_size, sizeof(float)); + l.forward = forward_avgpool_layer; + l.backward = backward_avgpool_layer; + #ifdef GPU + l.forward_gpu = forward_avgpool_layer_gpu; + l.backward_gpu = backward_avgpool_layer_gpu; + l.output_gpu = cuda_make_array(l.output, output_size); + l.delta_gpu = cuda_make_array(l.delta, output_size); + #endif + return l; +} + +void resize_avgpool_layer(avgpool_layer *l, int w, int h) +{ + l->w = w; + l->h = h; + l->inputs = h*w*l->c; +} + +void forward_avgpool_layer(const avgpool_layer l, network net) +{ + int b,i,k; + + for(b = 0; b < l.batch; ++b){ + for(k = 0; k < l.c; ++k){ + int out_index = k + b*l.c; + l.output[out_index] = 0; + for(i = 0; i < l.h*l.w; ++i){ + int in_index = i + l.h*l.w*(k + b*l.c); + l.output[out_index] += net.input[in_index]; + } + l.output[out_index] /= l.h*l.w; + } + } +} + +void backward_avgpool_layer(const avgpool_layer l, network net) +{ + int b,i,k; + + for(b = 0; b < l.batch; ++b){ + for(k = 0; k < l.c; ++k){ + int out_index = k + b*l.c; + for(i = 0; i < l.h*l.w; ++i){ + int in_index = i + l.h*l.w*(k + b*l.c); + net.delta[in_index] += l.delta[out_index] / (l.h*l.w); + } + } + } +} + diff --git a/src/avgpool_layer.h b/src/avgpool_layer.h new file mode 100644 index 0000000..ce9cd7a --- /dev/null +++ b/src/avgpool_layer.h @@ -0,0 +1,25 @@ + +#pragma once +#ifndef AVGPOOL_LAYER_H +#define AVGPOOL_LAYER_H +#include "define_inc.h" +#include "image.h" +#include "cuda.h" +#include "layer.h" +#include "network.h" + +typedef layer avgpool_layer; + +image get_avgpool_image(avgpool_layer l); +avgpool_layer make_avgpool_layer(int batch, int w, int h, int c); +void resize_avgpool_layer(avgpool_layer *l, int w, int h); +void forward_avgpool_layer(const avgpool_layer l, network net); +void backward_avgpool_layer(const avgpool_layer l, network net); + +#ifdef GPU +void forward_avgpool_layer_gpu(avgpool_layer l, network net); +void backward_avgpool_layer_gpu(avgpool_layer l, network net); +#endif + +#endif + diff --git a/src/avgpool_layer_kernels.cu b/src/avgpool_layer_kernels.cu new file mode 100644 index 0000000..a7eca3a --- /dev/null +++ b/src/avgpool_layer_kernels.cu @@ -0,0 +1,61 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "avgpool_layer.h" +#include "cuda.h" +} + +__global__ void forward_avgpool_layer_kernel(int n, int w, int h, int c, float *input, float *output) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= n) return; + + int k = id % c; + id /= c; + int b = id; + + int i; + int out_index = (k + c*b); + output[out_index] = 0; + for(i = 0; i < w*h; ++i){ + int in_index = i + h*w*(k + b*c); + output[out_index] += input[in_index]; + } + output[out_index] /= w*h; +} + +__global__ void backward_avgpool_layer_kernel(int n, int w, int h, int c, float *in_delta, float *out_delta) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= n) return; + + int k = id % c; + id /= c; + int b = id; + + int i; + int out_index = (k + c*b); + for(i = 0; i < w*h; ++i){ + int in_index = i + h*w*(k + b*c); + in_delta[in_index] += out_delta[out_index] / (w*h); + } +} + +extern "C" void forward_avgpool_layer_gpu(avgpool_layer layer, network net) +{ + size_t n = layer.c*layer.batch; + + forward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK>>>(n, layer.w, layer.h, layer.c, net.input_gpu, layer.output_gpu); + check_error(cudaPeekAtLastError()); +} + +extern "C" void backward_avgpool_layer_gpu(avgpool_layer layer, network net) +{ + size_t n = layer.c*layer.batch; + + backward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK>>>(n, layer.w, layer.h, layer.c, net.delta_gpu, layer.delta_gpu); + check_error(cudaPeekAtLastError()); +} + diff --git a/src/barcode.cpp b/src/barcode.cpp new file mode 100644 index 0000000..e974f49 --- /dev/null +++ b/src/barcode.cpp @@ -0,0 +1,384 @@ + +#include "opencv2/opencv.hpp" +#include "opencv2/objdetect.hpp" +#include <opencv2/imgcodecs.hpp> +#include <opencv2/highgui/highgui.hpp> +#include <opencv2/imgproc/imgproc.hpp> +#include <chrono> // ]tɶ禡w + +#include <iostream> +#include <cstdint> +#include <stdio.h> +#include <zbar/zbar.h> +#include "barcode.h" +#include "vproc.h" + +using namespace cv; +using namespace zbar; +using namespace std; +using namespace std::chrono; + +/* + ZBAR_NONE, // no symbol decoded + ZBAR_PARTIAL, // intermediate status + ZBAR_EAN8,// EAN-8. + ZBAR_UPCE, //UPC-E. + ZBAR_ISBN10, //ISBN-10 (from EAN-13). + ZBAR_UPCA, //UPC-A. + ZBAR_EAN13, //EAN-13. + ZBAR_ISBN13, // ISBN-13 (from EAN-13). + ZBAR_I25,// Interleaved 2 of 5. + ZBAR_CODE39, // Code 39. + ZBAR_PDF417, // PDF417. + ZBAR_QRCODE, // QR Code. + ZBAR_CODE128, // Code 128. + ZBAR_SYMBOL, //mask for base symbol type + ZBAR_ADDON2, //2-digit add-on flag + ZBAR_ADDON5, //5-digit add-on flag + ZBAR_ADDON //add-on flag mask +*/ + +/*string generateTimestamp() { + auto now = system_clock::now(); + time_t now_c = system_clock::to_time_t(now); + + ostringstream oss; + oss << put_time(localtime(&now_c), "%Y%m%d%H%M%S"); + + return oss.str(); +}*/ + +void readQRCode(const unsigned char* imageData, int imageWidth, int imageHeight, int imagePitch, char *output_code) { + + char code_temp[512] = { 0 }; + //string timestamp = generateTimestamp(); + //auto start = high_resolution_clock::now(); // }lp + Mat image(imageHeight, imageWidth, CV_8UC3, const_cast<unsigned char*>(imageData)); + + // Check if image is empty + if (image.empty()) { + printf("\nInvalid image data.\n"); + } + else { + Mat tempImg; + char* img_buf = new char[imageWidth * imageHeight * 3]; // RGB 3 channels + + int i = 0, j = 0; + for (i = 0; i < imageHeight; i++) + { + for (j = 0; j < imageWidth; j++) + { + img_buf[i * imageWidth * 3 + j * 3] = imageData[i * imagePitch + j + imagePitch * imageHeight * 2]; // Blue + img_buf[i * imageWidth * 3 + j * 3 + 1] = imageData[i * imagePitch + j + imagePitch * imageHeight]; // Green + img_buf[i * imageWidth * 3 + j * 3 + 2] = imageData[i * imagePitch + j]; // Red + } + } + + tempImg = Mat(imageHeight, imageWidth, CV_8UC3, img_buf); // Directly assign the array to the source of the Mat. + // imwrite("/emmc/plugin/Aida_data/storage/3chanel_image_" + timestamp + ".jpg", tempImg); + + // Create a QR code reader + ImageScanner scanner; + + // Configure the reader for QR code + scanner.set_config(ZBAR_QRCODE, ZBAR_CFG_ENABLE, 1); + scanner.enable_cache(false); + + // Convert image to grayscale + Mat grayImage; + cvtColor(tempImg, grayImage, COLOR_RGB2GRAY); + + // Apply Gaussian filter + //Mat gaussianFilter; + //GaussianBlur(grayImage, gaussianFilter, Size(3, 3), 0, 0); + // imwrite("/emmc/plugin/Aida_data/storage/gaussian_image_" + timestamp + ".jpg", gaussianFilter); + + // Binarize the image + Mat binaryImage; + threshold(grayImage, binaryImage, 128, 255, THRESH_BINARY); + // imwrite("/emmc/plugin/Aida_data/storage/binary_image_" + timestamp + ".jpg", binaryImage); + + // Wrap grayscale image data + Image zbarImage(binaryImage.cols, binaryImage.rows, "Y800", binaryImage.data, binaryImage.cols * binaryImage.rows); + + // Scan the image for QR codes + int n = scanner.scan(zbarImage); + + // Extract results + for (Image::SymbolIterator symbol = zbarImage.symbol_begin(); symbol != zbarImage.symbol_end(); ++symbol) { + //auto end = high_resolution_clock::now(); // p + //duration<double> duration = end - start; // pɶt + //cout << "decoded " << symbol->get_type_name() << " symbol " << symbol->get_data() <<" "<< endl; + //cout << "ӶOɶG" << duration.count() << " " << endl; // XӶOɶ + if (symbol->get_type() == ZBAR_QRCODE) + { + strcpy(code_temp, strdup(symbol->get_data().c_str())); + break; + } + } + + // Release resources + + //auto end = high_resolution_clock::now(); // p + //duration<double> duration = end - start; // pɶt + + //cout << "ӶOɶG" << duration.count() << " " << endl; // XӶOɶ + + if (img_buf != NULL) { + delete(img_buf); + img_buf = NULL; + } + if (!tempImg.empty()) + tempImg.release(); + + if (!grayImage.empty()) + grayImage.release(); + + //if (!gaussianFilter.empty()) + //gaussianFilter.release(); + + if (!binaryImage.empty()) + binaryImage.release(); + + scanner.recycle_image(zbarImage); + zbarImage.set_data(NULL, 0); + } + + if (!image.empty()) + image.release(); + + if (strlen(code_temp) >= 1) { + strcpy(output_code,code_temp); + } + +} + +#if 0 +char* readQRCodeFromImage(const char* imagePath) { + + char code_temp[512] = { 0 }; + + // load the image + Mat image = imread(imagePath, IMREAD_GRAYSCALE); + + // check if the image was loaded successfully + if (image.empty()) { + printf("\nFailed to load image: %s\n", imagePath); + } + else { + + // wrap image data + Image zbarImage(image.cols, image.rows, "Y800", image.data, image.cols * image.rows); + + ImageScanner scanner; + // configure the reader to detect QR codes + scanner.set_config(ZBAR_QRCODE, ZBAR_CFG_ENABLE, 1); + scanner.enable_cache(false); + + // scan the image for QR codes + int n = scanner.scan(zbarImage); + + // extract results + for (Image::SymbolIterator symbol = zbarImage.symbol_begin(); symbol != zbarImage.symbol_end(); ++symbol) { + // check if the detected symbol is a QR code + if (symbol->get_type() == ZBAR_QRCODE) { + strcpy(code_temp, strdup(symbol->get_data().c_str())); + break; + } + } + + scanner.recycle_image(zbarImage); + zbarImage.set_data(NULL, 0); + } + + if (!image.empty()) + image.release(); + + if (strlen(code_temp) >= 1) { + return code_temp; + } + else { + return nullptr; + } +} +#endif + +// +void readBarCode(const unsigned char* imageData, int imageWidth, int imageHeight, int imagePitch, char *output_code) { + + char code_temp[512] = { 0 }; + + //string timestamp = generateTimestamp(); + //auto start = high_resolution_clock::now(); // }lp + Mat image(imageHeight, imageWidth, CV_8UC3, const_cast<unsigned char*>(imageData)); + + // Check if image is empty + if (image.empty()) { + printf("\nInvalid image data.\n"); + } + else { + Mat tempImg; + char* img_buf = new char[imageWidth * imageHeight * 3]; // RGB 3 channels + + int i = 0, j = 0; + for (i = 0; i < imageHeight; i++) + { + for (j = 0; j < imageWidth; j++) + { + img_buf[i * imageWidth * 3 + j * 3] = imageData[i * imagePitch + j + imagePitch * imageHeight * 2]; // Blue + img_buf[i * imageWidth * 3 + j * 3 + 1] = imageData[i * imagePitch + j + imagePitch * imageHeight]; // Green + img_buf[i * imageWidth * 3 + j * 3 + 2] = imageData[i * imagePitch + j]; // Red + } + } + + tempImg = Mat(imageHeight, imageWidth, CV_8UC3, img_buf); // Directly assign the array to the source of the Mat. + // imwrite("/emmc/plugin/Aida_data/storage/3chanel_image_" + timestamp + ".jpg", tempImg); + + // Create a QR code reader + ImageScanner scanner; + + // Configure the reader for QR code + scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); + scanner.enable_cache(false); + + // Convert image to grayscale + Mat grayImage; + cvtColor(tempImg, grayImage, COLOR_RGB2GRAY); + + // Apply Gaussian filter + Mat gaussianFilter; + GaussianBlur(grayImage, gaussianFilter, Size(3, 3), 0, 0); + // imwrite("/emmc/plugin/Aida_data/storage/gaussian_image_" + timestamp + ".jpg", gaussianFilter); + + // Binarize the image + Mat binaryImage; + threshold(gaussianFilter, binaryImage, 128, 255, THRESH_BINARY); + // imwrite("/emmc/plugin/Aida_data/storage/binary_image_" + timestamp + ".jpg", binaryImage); + + // Wrap grayscale image data + Image zbarImage(binaryImage.cols, binaryImage.rows, "Y800", binaryImage.data, binaryImage.cols * binaryImage.rows); + + // Scan the image for QR codes + int n = scanner.scan(zbarImage); + + // Extract results + for (Image::SymbolIterator symbol = zbarImage.symbol_begin(); symbol != zbarImage.symbol_end(); ++symbol) { + //auto end = high_resolution_clock::now(); // p + //duration<double> duration = end - start; // pɶt + + //cout << "ӶOɶG" << duration.count() << " " << endl; // XӶOɶ + if (symbol->get_type() == ZBAR_EAN8 || + symbol->get_type() == ZBAR_UPCE || + symbol->get_type() == ZBAR_ISBN10 || + symbol->get_type() == ZBAR_UPCA || + symbol->get_type() == ZBAR_EAN13 || + symbol->get_type() == ZBAR_ISBN13 || + symbol->get_type() == ZBAR_I25 || + symbol->get_type() == ZBAR_CODE39 || + //symbol->get_type() == ZBAR_PDF417 || + symbol->get_type() == ZBAR_CODE128 || + //symbol->get_type() == ZBAR_SYMBOL || + symbol->get_type() == ZBAR_ADDON2 || + symbol->get_type() == ZBAR_ADDON5 || + symbol->get_type() == ZBAR_ADDON + ) { + strcpy(code_temp, strdup(symbol->get_data().c_str())); + break; + } + } + + // Release resources + + //auto end = high_resolution_clock::now(); // p + //duration<double> duration = end - start; // pɶt + + //cout << "ӶOɶG" << duration.count() << " " << endl; // XӶOɶ + + if (img_buf != NULL) { + delete(img_buf); + img_buf = NULL; + } + if (!tempImg.empty()) + tempImg.release(); + + if (!grayImage.empty()) + grayImage.release(); + + if (!gaussianFilter.empty()) + gaussianFilter.release(); + + if (!binaryImage.empty()) + binaryImage.release(); + + scanner.recycle_image(zbarImage); + zbarImage.set_data(NULL, 0); + } + + if (!image.empty()) + image.release(); + + if (strlen(code_temp) >= 1) { + strcpy(output_code, code_temp); + } +} + +#if 0 +char* readBarCodeFromImage(const char* imagePath) { + + char code_temp[512] = { 0 }; + + // load the image + Mat image = imread(imagePath, IMREAD_GRAYSCALE); + + if (image.empty()) { + printf("\nFailed to load image: %s\n", imagePath); + } + else{ + + // wrap image data + Image zbarImage(image.cols, image.rows, "Y800", image.data, image.cols * image.rows); + + ImageScanner scanner; + // configure the reader + scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); + scanner.enable_cache(false); + // scan the image for barcodes + int n = scanner.scan(zbarImage); + + // extract results + for (Image::SymbolIterator symbol = zbarImage.symbol_begin(); symbol != zbarImage.symbol_end(); ++symbol) { + if (symbol->get_type() == ZBAR_EAN8 || + symbol->get_type() == ZBAR_UPCE || + symbol->get_type() == ZBAR_ISBN10 || + symbol->get_type() == ZBAR_UPCA || + symbol->get_type() == ZBAR_EAN13 || + symbol->get_type() == ZBAR_ISBN13 || + symbol->get_type() == ZBAR_I25 || + symbol->get_type() == ZBAR_CODE39 || + //symbol->get_type() == ZBAR_PDF417 || + symbol->get_type() == ZBAR_CODE128 || + //symbol->get_type() == ZBAR_SYMBOL || + symbol->get_type() == ZBAR_ADDON2 || + symbol->get_type() == ZBAR_ADDON5 || + symbol->get_type() == ZBAR_ADDON + ) { + strcpy(code_temp, strdup(symbol->get_data().c_str())); + break; + } + } + + scanner.recycle_image(zbarImage); + zbarImage.set_data(NULL, 0); + } + + if (!image.empty()) + image.release(); + + if (strlen(code_temp) >= 1) { + return code_temp; + } + else { + return nullptr; + } +} +#endif \ No newline at end of file diff --git a/src/barcode.h b/src/barcode.h new file mode 100644 index 0000000..bf68b4a --- /dev/null +++ b/src/barcode.h @@ -0,0 +1,19 @@ +#ifndef BARCODE_H +#define BARCODE_H +#include "define_inc.h" +#include "vproc.h" +#ifdef __cplusplus +extern "C" { +#endif +// 讀取 QR Code +// char* readQRCode(const unsigned char* imageData, int imageWidth, int imageHeight); +void readQRCode(const unsigned char* imageData, int imageWidth, int imageHeight, int imagePitch, char *output_code); +// 讀取 BarCode +// char* readBarCode(const unsigned char* imageData, int imageWidth, int imageHeight); +void readBarCode(const unsigned char* imageData, int imageWidth, int imageHeight, int imagePitch, char *output_code); +// char* readBarCodeFromImage(const char* imagePath); +#ifdef __cplusplus +} +#endif + +#endif // BARCODE_H diff --git a/src/base64.c b/src/base64.c new file mode 100644 index 0000000..629c274 --- /dev/null +++ b/src/base64.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/// +static const char encoding_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/' }; +static const int mod_table[] = { 0, 2, 1 }; + + +void base64_encode_a(unsigned char *data, + size_t input_length, + size_t *output_length, + char *encoded_data) { + + *output_length = 4 * ((input_length + 2) / 3); + + //printf("\nbuild launchTime :%p\n", encoded_data); + + if (*output_length <= 0) { + + } + else { + for (int i = 0, j = 0; i < input_length;) { + + unsigned int octet_a = i < input_length ? (unsigned char)data[i++] : 0; + unsigned int octet_b = i < input_length ? (unsigned char)data[i++] : 0; + unsigned int octet_c = i < input_length ? (unsigned char)data[i++] : 0; + + unsigned int triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; + + encoded_data[j++] = encoding_table[(triple >> 3 * 6) & 0x3F]; + encoded_data[j++] = encoding_table[(triple >> 2 * 6) & 0x3F]; + encoded_data[j++] = encoding_table[(triple >> 1 * 6) & 0x3F]; + encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F]; + } + + for (int i = 0; i < mod_table[input_length % 3]; i++) + encoded_data[*output_length - 1 - i] = '='; + } + //return encoded_data; +} +/// + diff --git a/src/base64.h b/src/base64.h new file mode 100644 index 0000000..0d7a0cf --- /dev/null +++ b/src/base64.h @@ -0,0 +1,6 @@ +#pragma once +#ifndef _BASE64_H_ +#define _BASE64_H_ +#include "define_inc.h" +void base64_encode_a(unsigned char *data,size_t input_length,size_t *output_length,char *encoded_data); +#endif \ No newline at end of file diff --git a/src/batchnorm_layer.c b/src/batchnorm_layer.c new file mode 100644 index 0000000..ebff387 --- /dev/null +++ b/src/batchnorm_layer.c @@ -0,0 +1,279 @@ +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "blas.h" +#include <stdio.h> + +layer make_batchnorm_layer(int batch, int w, int h, int c) +{ + fprintf(stderr, "Batch Normalization Layer: %d x %d x %d image\n", w,h,c); + layer l = {0}; + l.type = BATCHNORM; + l.batch = batch; + l.h = l.out_h = h; + l.w = l.out_w = w; + l.c = l.out_c = c; + l.output = calloc(h * w * c * batch, sizeof(float)); + l.delta = calloc(h * w * c * batch, sizeof(float)); + l.inputs = w*h*c; + l.outputs = l.inputs; + + l.scales = calloc(c, sizeof(float)); + l.scale_updates = calloc(c, sizeof(float)); + l.biases = calloc(c, sizeof(float)); + l.bias_updates = calloc(c, sizeof(float)); + int i; + for(i = 0; i < c; ++i){ + l.scales[i] = 1; + } + + l.mean = calloc(c, sizeof(float)); + l.variance = calloc(c, sizeof(float)); + + l.rolling_mean = calloc(c, sizeof(float)); + l.rolling_variance = calloc(c, sizeof(float)); + + l.forward = forward_batchnorm_layer; + l.backward = backward_batchnorm_layer; +#ifdef GPU + l.forward_gpu = forward_batchnorm_layer_gpu; + l.backward_gpu = backward_batchnorm_layer_gpu; + + l.output_gpu = cuda_make_array(l.output, h * w * c * batch); + l.delta_gpu = cuda_make_array(l.delta, h * w * c * batch); + + l.biases_gpu = cuda_make_array(l.biases, c); + l.bias_updates_gpu = cuda_make_array(l.bias_updates, c); + + l.scales_gpu = cuda_make_array(l.scales, c); + l.scale_updates_gpu = cuda_make_array(l.scale_updates, c); + + l.mean_gpu = cuda_make_array(l.mean, c); + l.variance_gpu = cuda_make_array(l.variance, c); + + l.rolling_mean_gpu = cuda_make_array(l.mean, c); + l.rolling_variance_gpu = cuda_make_array(l.variance, c); + + l.mean_delta_gpu = cuda_make_array(l.mean, c); + l.variance_delta_gpu = cuda_make_array(l.variance, c); + + l.x_gpu = cuda_make_array(l.output, l.batch*l.outputs); + l.x_norm_gpu = cuda_make_array(l.output, l.batch*l.outputs); + #ifdef CUDNN + cudnnCreateTensorDescriptor(&l.normTensorDesc); + cudnnCreateTensorDescriptor(&l.dstTensorDesc); + cudnnSetTensor4dDescriptor(l.dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l.batch, l.out_c, l.out_h, l.out_w); + cudnnSetTensor4dDescriptor(l.normTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l.out_c, 1, 1); + + #endif +#endif + return l; +} + +void backward_scale_cpu(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates) +{ + int i,b,f; + for(f = 0; f < n; ++f){ + float sum = 0; + for(b = 0; b < batch; ++b){ + for(i = 0; i < size; ++i){ + int index = i + size*(f + n*b); + sum += delta[index] * x_norm[index]; + } + } + scale_updates[f] += sum; + } +} + +void mean_delta_cpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta) +{ + + int i,j,k; + for(i = 0; i < filters; ++i){ + mean_delta[i] = 0; + for (j = 0; j < batch; ++j) { + for (k = 0; k < spatial; ++k) { + int index = j*filters*spatial + i*spatial + k; + mean_delta[i] += delta[index]; + } + } + mean_delta[i] *= (-1./sqrt(variance[i] + .00001f)); + } +} +void variance_delta_cpu(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta) +{ + + int i,j,k; + for(i = 0; i < filters; ++i){ + variance_delta[i] = 0; + for(j = 0; j < batch; ++j){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + i*spatial + k; + variance_delta[i] += delta[index]*(x[index] - mean[i]); + } + } + variance_delta[i] *= -.5 * pow(variance[i] + .00001f, (float)(-3./2.)); + } +} +void normalize_delta_cpu(float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta) +{ + int f, j, k; + for(j = 0; j < batch; ++j){ + for(f = 0; f < filters; ++f){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + f*spatial + k; + delta[index] = delta[index] * 1./(sqrt(variance[f] + .00001f)) + variance_delta[f] * 2. * (x[index] - mean[f]) / (spatial * batch) + mean_delta[f]/(spatial*batch); + } + } + } +} + +void resize_batchnorm_layer(layer *layer, int w, int h) +{ + fprintf(stderr, "Not implemented\n"); +} + +void forward_batchnorm_layer(layer l, network net) +{ + if(l.type == BATCHNORM) copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); + copy_cpu(l.outputs*l.batch, l.output, 1, l.x, 1); + if(net.train){ + mean_cpu(l.output, l.batch, l.out_c, l.out_h*l.out_w, l.mean); + variance_cpu(l.output, l.mean, l.batch, l.out_c, l.out_h*l.out_w, l.variance); + + scal_cpu(l.out_c, .99, l.rolling_mean, 1); + axpy_cpu(l.out_c, .01, l.mean, 1, l.rolling_mean, 1); + scal_cpu(l.out_c, .99, l.rolling_variance, 1); + axpy_cpu(l.out_c, .01, l.variance, 1, l.rolling_variance, 1); + + normalize_cpu(l.output, l.mean, l.variance, l.batch, l.out_c, l.out_h*l.out_w); + copy_cpu(l.outputs*l.batch, l.output, 1, l.x_norm, 1); + } else { + normalize_cpu(l.output, l.rolling_mean, l.rolling_variance, l.batch, l.out_c, l.out_h*l.out_w); + } + scale_bias(l.output, l.scales, l.batch, l.out_c, l.out_h*l.out_w); + add_bias(l.output, l.biases, l.batch, l.out_c, l.out_h*l.out_w); +} + +void backward_batchnorm_layer(layer l, network net) +{ + if(!net.train){ + l.mean = l.rolling_mean; + l.variance = l.rolling_variance; + } + backward_bias(l.bias_updates, l.delta, l.batch, l.out_c, l.out_w*l.out_h); + backward_scale_cpu(l.x_norm, l.delta, l.batch, l.out_c, l.out_w*l.out_h, l.scale_updates); + + scale_bias(l.delta, l.scales, l.batch, l.out_c, l.out_h*l.out_w); + + mean_delta_cpu(l.delta, l.variance, l.batch, l.out_c, l.out_w*l.out_h, l.mean_delta); + variance_delta_cpu(l.x, l.delta, l.mean, l.variance, l.batch, l.out_c, l.out_w*l.out_h, l.variance_delta); + normalize_delta_cpu(l.x, l.mean, l.variance, l.mean_delta, l.variance_delta, l.batch, l.out_c, l.out_w*l.out_h, l.delta); + if(l.type == BATCHNORM) copy_cpu(l.outputs*l.batch, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void pull_batchnorm_layer(layer l) +{ + cuda_pull_array(l.scales_gpu, l.scales, l.c); + cuda_pull_array(l.rolling_mean_gpu, l.rolling_mean, l.c); + cuda_pull_array(l.rolling_variance_gpu, l.rolling_variance, l.c); +} +void push_batchnorm_layer(layer l) +{ + cuda_push_array(l.scales_gpu, l.scales, l.c); + cuda_push_array(l.rolling_mean_gpu, l.rolling_mean, l.c); + cuda_push_array(l.rolling_variance_gpu, l.rolling_variance, l.c); +} + +void forward_batchnorm_layer_gpu(layer l, network net) +{ + if(l.type == BATCHNORM) copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1); + copy_gpu(l.outputs*l.batch, l.output_gpu, 1, l.x_gpu, 1); + if (net.train) { +#ifdef CUDNN + float one = 1; + float zero = 0; + cudnnBatchNormalizationForwardTraining(cudnn_handle(), + CUDNN_BATCHNORM_SPATIAL, + &one, + &zero, + l.dstTensorDesc, + l.x_gpu, + l.dstTensorDesc, + l.output_gpu, + l.normTensorDesc, + l.scales_gpu, + l.biases_gpu, + .01, + l.rolling_mean_gpu, + l.rolling_variance_gpu, + .00001, + l.mean_gpu, + l.variance_gpu); +#else + fast_mean_gpu(l.output_gpu, l.batch, l.out_c, l.out_h*l.out_w, l.mean_gpu); + fast_variance_gpu(l.output_gpu, l.mean_gpu, l.batch, l.out_c, l.out_h*l.out_w, l.variance_gpu); + + scal_gpu(l.out_c, .99, l.rolling_mean_gpu, 1); + axpy_gpu(l.out_c, .01, l.mean_gpu, 1, l.rolling_mean_gpu, 1); + scal_gpu(l.out_c, .99, l.rolling_variance_gpu, 1); + axpy_gpu(l.out_c, .01, l.variance_gpu, 1, l.rolling_variance_gpu, 1); + + copy_gpu(l.outputs*l.batch, l.output_gpu, 1, l.x_gpu, 1); + normalize_gpu(l.output_gpu, l.mean_gpu, l.variance_gpu, l.batch, l.out_c, l.out_h*l.out_w); + copy_gpu(l.outputs*l.batch, l.output_gpu, 1, l.x_norm_gpu, 1); + + scale_bias_gpu(l.output_gpu, l.scales_gpu, l.batch, l.out_c, l.out_h*l.out_w); + add_bias_gpu(l.output_gpu, l.biases_gpu, l.batch, l.out_c, l.out_w*l.out_h); +#endif + } else { + normalize_gpu(l.output_gpu, l.rolling_mean_gpu, l.rolling_variance_gpu, l.batch, l.out_c, l.out_h*l.out_w); + scale_bias_gpu(l.output_gpu, l.scales_gpu, l.batch, l.out_c, l.out_h*l.out_w); + add_bias_gpu(l.output_gpu, l.biases_gpu, l.batch, l.out_c, l.out_w*l.out_h); + } + +} + +void backward_batchnorm_layer_gpu(layer l, network net) +{ + if(!net.train){ + l.mean_gpu = l.rolling_mean_gpu; + l.variance_gpu = l.rolling_variance_gpu; + } +#ifdef CUDNN + float one = 1; + float zero = 0; + cudnnBatchNormalizationBackward(cudnn_handle(), + CUDNN_BATCHNORM_SPATIAL, + &one, + &zero, + &one, + &one, + l.dstTensorDesc, + l.x_gpu, + l.dstTensorDesc, + l.delta_gpu, + l.dstTensorDesc, + l.x_norm_gpu, + l.normTensorDesc, + l.scales_gpu, + l.scale_updates_gpu, + l.bias_updates_gpu, + .00001, + l.mean_gpu, + l.variance_gpu); + copy_gpu(l.outputs*l.batch, l.x_norm_gpu, 1, l.delta_gpu, 1); +#else + backward_bias_gpu(l.bias_updates_gpu, l.delta_gpu, l.batch, l.out_c, l.out_w*l.out_h); + backward_scale_gpu(l.x_norm_gpu, l.delta_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.scale_updates_gpu); + + scale_bias_gpu(l.delta_gpu, l.scales_gpu, l.batch, l.out_c, l.out_h*l.out_w); + + fast_mean_delta_gpu(l.delta_gpu, l.variance_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.mean_delta_gpu); + fast_variance_delta_gpu(l.x_gpu, l.delta_gpu, l.mean_gpu, l.variance_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.variance_delta_gpu); + normalize_delta_gpu(l.x_gpu, l.mean_gpu, l.variance_gpu, l.mean_delta_gpu, l.variance_delta_gpu, l.batch, l.out_c, l.out_w*l.out_h, l.delta_gpu); +#endif + if(l.type == BATCHNORM) copy_gpu(l.outputs*l.batch, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif diff --git a/src/batchnorm_layer.h b/src/batchnorm_layer.h new file mode 100644 index 0000000..a04e5db --- /dev/null +++ b/src/batchnorm_layer.h @@ -0,0 +1,20 @@ +#pragma once +#ifndef BATCHNORM_LAYER_H +#define BATCHNORM_LAYER_H +#include "define_inc.h" +#include "image.h" +#include "layer.h" +#include "network.h" + +layer make_batchnorm_layer(int batch, int w, int h, int c); +void forward_batchnorm_layer(layer l, network net); +void backward_batchnorm_layer(layer l, network net); + +#ifdef GPU +void forward_batchnorm_layer_gpu(layer l, network net); +void backward_batchnorm_layer_gpu(layer l, network net); +void pull_batchnorm_layer(layer l); +void push_batchnorm_layer(layer l); +#endif + +#endif diff --git a/src/blas.c b/src/blas.c new file mode 100644 index 0000000..19b5773 --- /dev/null +++ b/src/blas.c @@ -0,0 +1,354 @@ +#include "blas.h" + +#include <math.h> +#include <assert.h> +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +void reorg_cpu(float *x, int w, int h, int c, int batch, int stride, int forward, float *out) +{ + int b,i,j,k; + int out_c = c/(stride*stride); + + for(b = 0; b < batch; ++b){ + for(k = 0; k < c; ++k){ + for(j = 0; j < h; ++j){ + for(i = 0; i < w; ++i){ + int in_index = i + w*(j + h*(k + c*b)); + int c2 = k % out_c; + int offset = k / out_c; + int w2 = i*stride + offset % stride; + int h2 = j*stride + offset / stride; + int out_index = w2 + w*stride*(h2 + h*stride*(c2 + out_c*b)); + if(forward) out[out_index] = x[in_index]; + else out[in_index] = x[out_index]; + } + } + } + } +} + +void flatten(float *x, int size, int layers, int batch, int forward) +{ + float *swap = calloc(size*layers*batch, sizeof(float)); + int i,c,b; + for(b = 0; b < batch; ++b){ + for(c = 0; c < layers; ++c){ + for(i = 0; i < size; ++i){ + int i1 = b*layers*size + c*size + i; + int i2 = b*layers*size + i*layers + c; + if (forward) swap[i2] = x[i1]; + else swap[i1] = x[i2]; + } + } + } + memcpy(x, swap, size*layers*batch*sizeof(float)); + if (swap) { + free(swap); + swap = NULL; + } +} + +void weighted_sum_cpu(float *a, float *b, float *s, int n, float *c) +{ + int i; + for(i = 0; i < n; ++i){ + c[i] = s[i]*a[i] + (1-s[i])*(b ? b[i] : 0); + } +} + +void weighted_delta_cpu(float *a, float *b, float *s, float *da, float *db, float *ds, int n, float *dc) +{ + int i; + for(i = 0; i < n; ++i){ + if(da) da[i] += dc[i] * s[i]; + if(db) db[i] += dc[i] * (1-s[i]); + ds[i] += dc[i] * (a[i] - b[i]); + } +} + +void shortcut_cpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float s1, float s2, float *out) +{ + int stride = w1/w2; + int sample = w2/w1; + assert(stride == h1/h2); + assert(sample == h2/h1); + if(stride < 1) stride = 1; + if(sample < 1) sample = 1; + int minw = (w1 < w2) ? w1 : w2; + int minh = (h1 < h2) ? h1 : h2; + int minc = (c1 < c2) ? c1 : c2; + + int i,j,k,b; + for(b = 0; b < batch; ++b){ + for(k = 0; k < minc; ++k){ + for(j = 0; j < minh; ++j){ + for(i = 0; i < minw; ++i){ + int out_index = i*sample + w2*(j*sample + h2*(k + c2*b)); + int add_index = i*stride + w1*(j*stride + h1*(k + c1*b)); + out[out_index] = s1*out[out_index] + s2*add[add_index]; + } + } + } + } +} + +void mean_cpu(float *x, int batch, int filters, int spatial, float *mean) +{ + float scale = 1./(batch * spatial); + int i,j,k; + for(i = 0; i < filters; ++i){ + mean[i] = 0; + for(j = 0; j < batch; ++j){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + i*spatial + k; + mean[i] += x[index]; + } + } + mean[i] *= scale; + } +} + +void variance_cpu(float *x, float *mean, int batch, int filters, int spatial, float *variance) +{ + float scale = 1./(batch * spatial - 1); + int i,j,k; + for(i = 0; i < filters; ++i){ + variance[i] = 0; + for(j = 0; j < batch; ++j){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + i*spatial + k; + variance[i] += pow((x[index] - mean[i]), 2); + } + } + variance[i] *= scale; + } +} + +void l2normalize_cpu(float *x, float *dx, int batch, int filters, int spatial) +{ + int b,f,i; + for(b = 0; b < batch; ++b){ + for(i = 0; i < spatial; ++i){ + float sum = 0; + for(f = 0; f < filters; ++f){ + int index = b*filters*spatial + f*spatial + i; + sum += powf(x[index], 2); + } + sum = sqrtf(sum); + for(f = 0; f < filters; ++f){ + int index = b*filters*spatial + f*spatial + i; + x[index] /= sum; + dx[index] = (1 - x[index]) / sum; + } + } + } +} + + +void normalize_cpu(float *x, float *mean, float *variance, int batch, int filters, int spatial) +{ + int b, f, i; + for(b = 0; b < batch; ++b){ + for(f = 0; f < filters; ++f){ + for(i = 0; i < spatial; ++i){ + int index = b*filters*spatial + f*spatial + i; + x[index] = (x[index] - mean[f])/(sqrt(variance[f]) + .000001f); + } + } + } +} + +void const_cpu(int N, float ALPHA, float *X, int INCX) +{ + int i; + for(i = 0; i < N; ++i) X[i*INCX] = ALPHA; +} + +void mul_cpu(int N, float *X, int INCX, float *Y, int INCY) +{ + int i; + for(i = 0; i < N; ++i) Y[i*INCY] *= X[i*INCX]; +} + +void pow_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY) +{ + int i; + for(i = 0; i < N; ++i) Y[i*INCY] = pow(X[i*INCX], ALPHA); +} + +void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY) +{ + int i; + for(i = 0; i < N; ++i) Y[i*INCY] += ALPHA*X[i*INCX]; +} + +void scal_cpu(int N, float ALPHA, float *X, int INCX) +{ + int i; + for(i = 0; i < N; ++i) X[i*INCX] *= ALPHA; +} + +void fill_cpu(int N, float ALPHA, float *X, int INCX) +{ + int i; + for(i = 0; i < N; ++i) X[i*INCX] = ALPHA; +} + +void deinter_cpu(int NX, float *X, int NY, float *Y, int B, float *OUT) +{ + int i, j; + int index = 0; + for(j = 0; j < B; ++j) { + for(i = 0; i < NX; ++i){ + if(X) X[j*NX + i] += OUT[index]; + ++index; + } + for(i = 0; i < NY; ++i){ + if(Y) Y[j*NY + i] += OUT[index]; + ++index; + } + } +} + +void inter_cpu(int NX, float *X, int NY, float *Y, int B, float *OUT) +{ + int i, j; + int index = 0; + for(j = 0; j < B; ++j) { + for(i = 0; i < NX; ++i){ + OUT[index++] = X[j*NX + i]; + } + for(i = 0; i < NY; ++i){ + OUT[index++] = Y[j*NY + i]; + } + } +} + +void copy_cpu(int N, float *X, int INCX, float *Y, int INCY) +{ + int i; + for(i = 0; i < N; ++i) Y[i*INCY] = X[i*INCX]; +} + +void mult_add_into_cpu(int N, float *X, float *Y, float *Z) +{ + int i; + for(i = 0; i < N; ++i) Z[i] += X[i]*Y[i]; +} + +void smooth_l1_cpu(int n, float *pred, float *truth, float *delta, float *error) +{ + int i; + for(i = 0; i < n; ++i){ + float diff = truth[i] - pred[i]; + float abs_val = fabs(diff); + if(abs_val < 1) { + error[i] = diff * diff; + delta[i] = diff; + } + else { + error[i] = 2*abs_val - 1; + delta[i] = (diff < 0) ? 1 : -1; + } + } +} + +void l1_cpu(int n, float *pred, float *truth, float *delta, float *error) +{ + int i; + for(i = 0; i < n; ++i){ + float diff = truth[i] - pred[i]; + error[i] = fabs(diff); + delta[i] = diff > 0 ? 1 : -1; + } +} + +void softmax_x_ent_cpu(int n, float *pred, float *truth, float *delta, float *error) +{ + int i; + for(i = 0; i < n; ++i){ + float t = truth[i]; + float p = pred[i]; + error[i] = (t) ? -log(p) : 0; + delta[i] = t-p; + } +} + +void logistic_x_ent_cpu(int n, float *pred, float *truth, float *delta, float *error) +{ + int i; + for(i = 0; i < n; ++i){ + float t = truth[i]; + float p = pred[i]; + error[i] = -t*log(p) - (1-t)*log(1-p); + delta[i] = t-p; + } +} + +void l2_cpu(int n, float *pred, float *truth, float *delta, float *error) +{ + int i; + for(i = 0; i < n; ++i){ + float diff = truth[i] - pred[i]; + error[i] = diff * diff; + delta[i] = diff; + } +} + +float dot_cpu(int N, float *X, int INCX, float *Y, int INCY) +{ + int i; + float dot = 0; + for(i = 0; i < N; ++i) dot += X[i*INCX] * Y[i*INCY]; + return dot; +} + +void softmax(float *input, int n, float temp, int stride, float *output) +{ + int i; + float sum = 0; + float largest = -FLT_MAX; + for(i = 0; i < n; ++i){ + if(input[i*stride] > largest) largest = input[i*stride]; + } + for(i = 0; i < n; ++i){ + float e = exp(input[i*stride]/temp - largest/temp); + sum += e; + output[i*stride] = e; + } + for(i = 0; i < n; ++i){ + output[i*stride] /= sum; + } +} + + +void softmax_cpu(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output) +{ + int g, b; + for(b = 0; b < batch; ++b){ + for(g = 0; g < groups; ++g){ + softmax(input + b*batch_offset + g*group_offset, n, temp, stride, output + b*batch_offset + g*group_offset); + } + } +} + +void upsample_cpu(float *in, int w, int h, int c, int batch, int stride, int forward, float scale, float *out) +{ + int i, j, k, b; + for(b = 0; b < batch; ++b){ + for(k = 0; k < c; ++k){ + for(j = 0; j < h*stride; ++j){ + for(i = 0; i < w*stride; ++i){ + int in_index = b*w*h*c + k*w*h + (j/stride)*w + i/stride; + int out_index = b*w*h*c*stride*stride + k*w*h*stride*stride + j*w*stride + i; + if(forward) out[out_index] = scale*in[in_index]; + else in[in_index] += scale*out[out_index]; + } + } + } + } +} + + diff --git a/src/blas.h b/src/blas.h new file mode 100644 index 0000000..aa1ebf4 --- /dev/null +++ b/src/blas.h @@ -0,0 +1,136 @@ +#pragma once +#ifndef BLAS_H +#define BLAS_H +#include "define_inc.h" +#include "darknet.h" + +void flatten(float *x, int size, int layers, int batch, int forward); +void pm(int M, int N, float *A); +float *random_matrix(int rows, int cols); +void time_random_matrix(int TA, int TB, int m, int k, int n); +void reorg_cpu(float *x, int w, int h, int c, int batch, int stride, int forward, float *out); + +void test_blas(); + +void inter_cpu(int NX, float *X, int NY, float *Y, int B, float *OUT); +void deinter_cpu(int NX, float *X, int NY, float *Y, int B, float *OUT); +void mult_add_into_cpu(int N, float *X, float *Y, float *Z); + +void const_cpu(int N, float ALPHA, float *X, int INCX); +void constrain_gpu(int N, float ALPHA, float * X, int INCX); +void pow_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); +void mul_cpu(int N, float *X, int INCX, float *Y, int INCY); + + +float dot_cpu(int N, float *X, int INCX, float *Y, int INCY); +void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); +void copy_cpu(int N, float *X, int INCX, float *Y, int INCY); +void scal_cpu(int N, float ALPHA, float *X, int INCX); +void fill_cpu(int N, float ALPHA, float * X, int INCX); +void normalize_cpu(float *x, float *mean, float *variance, int batch, int filters, int spatial); +void softmax(float *input, int n, float temp, int stride, float *output); + + +int test_gpu_blas(); +void shortcut_cpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float s1, float s2, float *out); + +void mean_cpu(float *x, int batch, int filters, int spatial, float *mean); +void variance_cpu(float *x, float *mean, int batch, int filters, int spatial, float *variance); + +void scale_bias(float *output, float *scales, int batch, int n, int size); +void backward_scale_cpu(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates); +void mean_delta_cpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta); +void variance_delta_cpu(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta); +void normalize_delta_cpu(float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta); +void l2normalize_cpu(float *x, float *dx, int batch, int filters, int spatial); + +void smooth_l1_cpu(int n, float *pred, float *truth, float *delta, float *error); +void l2_cpu(int n, float *pred, float *truth, float *delta, float *error); +void l1_cpu(int n, float *pred, float *truth, float *delta, float *error); +void logistic_x_ent_cpu(int n, float *pred, float *truth, float *delta, float *error); +void softmax_x_ent_cpu(int n, float *pred, float *truth, float *delta, float *error); +void weighted_sum_cpu(float *a, float *b, float *s, int num, float *c); +void weighted_delta_cpu(float *a, float *b, float *s, float *da, float *db, float *ds, int n, float *dc); + +void softmax(float *input, int n, float temp, int stride, float *output); +void softmax_cpu(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output); +void upsample_cpu(float *in, int w, int h, int c, int batch, int stride, int forward, float scale, float *out); + +#ifdef GPU +#include "cuda.h" +#include "tree.h" + +void axpy_gpu(int N, float ALPHA, float * X, int INCX, float * Y, int INCY); +void axpy_gpu_offset(int N, float ALPHA, float * X, int OFFX, int INCX, float * Y, int OFFY, int INCY); +void copy_gpu(int N, float * X, int INCX, float * Y, int INCY); +void copy_gpu_offset(int N, float * X, int OFFX, int INCX, float * Y, int OFFY, int INCY); +void add_gpu(int N, float ALPHA, float * X, int INCX); +void supp_gpu(int N, float ALPHA, float * X, int INCX); +void mask_gpu(int N, float * X, float mask_num, float * mask, float val); +void scale_mask_gpu(int N, float * X, float mask_num, float * mask, float scale); +void const_gpu(int N, float ALPHA, float *X, int INCX); +void pow_gpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); +void mul_gpu(int N, float *X, int INCX, float *Y, int INCY); + +void mean_gpu(float *x, int batch, int filters, int spatial, float *mean); +void variance_gpu(float *x, float *mean, int batch, int filters, int spatial, float *variance); +void normalize_gpu(float *x, float *mean, float *variance, int batch, int filters, int spatial); +void l2normalize_gpu(float *x, float *dx, int batch, int filters, int spatial); + +void normalize_delta_gpu(float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta); + +void fast_mean_delta_gpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta); +void fast_variance_delta_gpu(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta); + +void fast_variance_gpu(float *x, float *mean, int batch, int filters, int spatial, float *variance); +void fast_mean_gpu(float *x, int batch, int filters, int spatial, float *mean); +void shortcut_gpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float s1, float s2, float *out); +void scale_bias_gpu(float *output, float *biases, int batch, int n, int size); +void backward_scale_gpu(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates); +void scale_bias_gpu(float *output, float *biases, int batch, int n, int size); +void add_bias_gpu(float *output, float *biases, int batch, int n, int size); +void backward_bias_gpu(float *bias_updates, float *delta, int batch, int n, int size); + +void logistic_x_ent_gpu(int n, float *pred, float *truth, float *delta, float *error); +void softmax_x_ent_gpu(int n, float *pred, float *truth, float *delta, float *error); +void smooth_l1_gpu(int n, float *pred, float *truth, float *delta, float *error); +void l2_gpu(int n, float *pred, float *truth, float *delta, float *error); +void l1_gpu(int n, float *pred, float *truth, float *delta, float *error); +void wgan_gpu(int n, float *pred, float *truth, float *delta, float *error); +void weighted_delta_gpu(float *a, float *b, float *s, float *da, float *db, float *ds, int num, float *dc); +void weighted_sum_gpu(float *a, float *b, float *s, int num, float *c); +void mult_add_into_gpu(int num, float *a, float *b, float *c); +void inter_gpu(int NX, float *X, int NY, float *Y, int B, float *OUT); +void deinter_gpu(int NX, float *X, int NY, float *Y, int B, float *OUT); + +void reorg_gpu(float *x, int w, int h, int c, int batch, int stride, int forward, float *out); + +void softmax_gpu(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output); +void adam_update_gpu(float *w, float *d, float *m, float *v, float B1, float B2, float eps, float decay, float rate, int n, int batch, int t); +void adam_gpu(int n, float *x, float *m, float *v, float B1, float B2, float rate, float eps, int t); + +void flatten_gpu(float *x, int spatial, int layers, int batch, int forward, float *out); +void softmax_tree(float *input, int spatial, int batch, int stride, float temp, float *output, tree hier); +void upsample_gpu(float *in, int w, int h, int c, int batch, int stride, int forward, float scale, float *out); + +void axpy_gpu(int N, float ALPHA, float * X, int INCX, float * Y, int INCY); +void fill_gpu(int N, float ALPHA, float * X, int INCX); +void scal_gpu(int N, float ALPHA, float * X, int INCX); +void copy_gpu(int N, float * X, int INCX, float * Y, int INCY); + +void cuda_set_device(int n); +void cuda_free(float *x_gpu); +float *cuda_make_array(float *x, size_t n); +void cuda_pull_array(float *x_gpu, float *x, size_t n); +float cuda_mag_array(float *x_gpu, size_t n); +void cuda_push_array(float *x_gpu, float *x, size_t n); + +void forward_network_gpu(network *net); +void backward_network_gpu(network *net); +void update_network_gpu(network *net); + +float train_networks(network **nets, int n, data d, int interval); +void sync_nets(network **nets, int n, int interval); +void harmless_update_network_gpu(network *net); +#endif +#endif diff --git a/src/blas_kernels.cu b/src/blas_kernels.cu new file mode 100644 index 0000000..47e8217 --- /dev/null +++ b/src/blas_kernels.cu @@ -0,0 +1,1035 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" +#include <assert.h> + +extern "C" { +#include "blas.h" +#include "cuda.h" +#include "utils.h" +} + +__global__ void scale_bias_kernel(float *output, float *biases, int n, int size) +{ + int offset = blockIdx.x * blockDim.x + threadIdx.x; + int filter = blockIdx.y; + int batch = blockIdx.z; + + if(offset < size) output[(batch*n+filter)*size + offset] *= biases[filter]; +} + +void scale_bias_gpu(float *output, float *biases, int batch, int n, int size) +{ + dim3 dimGrid((size-1)/BLOCK + 1, n, batch); + dim3 dimBlock(BLOCK, 1, 1); + + scale_bias_kernel<<<dimGrid, dimBlock>>>(output, biases, n, size); + check_error(cudaPeekAtLastError()); +} + +__global__ void backward_scale_kernel(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates) +{ + __shared__ float part[BLOCK]; + int i,b; + int filter = blockIdx.x; + int p = threadIdx.x; + float sum = 0; + for(b = 0; b < batch; ++b){ + for(i = 0; i < size; i += BLOCK){ + int index = p + i + size*(filter + n*b); + sum += (p+i < size) ? delta[index]*x_norm[index] : 0; + } + } + part[p] = sum; + __syncthreads(); + if (p == 0) { + for(i = 0; i < BLOCK; ++i) scale_updates[filter] += part[i]; + } +} + +void backward_scale_gpu(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates) +{ + backward_scale_kernel<<<n, BLOCK>>>(x_norm, delta, batch, n, size, scale_updates); + check_error(cudaPeekAtLastError()); +} + +__global__ void add_bias_kernel(float *output, float *biases, int batch, int n, int size) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (index >= n*size*batch) return; + int i = index % size; + index /= size; + int j = index % n; + index /= n; + int k = index; + + output[(k*n+j)*size + i] += biases[j]; +} + +void add_bias_gpu(float *output, float *biases, int batch, int n, int size) +{ + int num = n*size*batch; + + add_bias_kernel<<<cuda_gridsize(num), BLOCK>>>(output, biases, batch, n, size); + check_error(cudaPeekAtLastError()); +} + +__global__ void backward_bias_conn_kernel(float *bias_updates, float *delta, int batch, int n) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (index >= n) return; + int b; + float sum = 0; + for(b = 0; b < batch; ++b){ + int i = b*n + index; + sum += delta[i]; + } + bias_updates[index] += sum; +} + +__global__ void backward_bias_kernel(float *bias_updates, float *delta, int batch, int n, int size) +{ + __shared__ float part[BLOCK]; + int i,b; + int filter = blockIdx.x; + int p = threadIdx.x; + float sum = 0; + for(b = 0; b < batch; ++b){ + for(i = 0; i < size; i += BLOCK){ + int index = p + i + size*(filter + n*b); + sum += (p+i < size) ? delta[index] : 0; + } + } + part[p] = sum; + __syncthreads(); + if (p == 0) { + for(i = 0; i < BLOCK; ++i) bias_updates[filter] += part[i]; + } +} + +void backward_bias_gpu(float *bias_updates, float *delta, int batch, int n, int size) +{ + if(size == 1){ + backward_bias_conn_kernel<<<cuda_gridsize(n), BLOCK>>>(bias_updates, delta, batch, n); + }else{ + backward_bias_kernel<<<n, BLOCK>>>(bias_updates, delta, batch, n, size); + } + check_error(cudaPeekAtLastError()); +} + +/* +__global__ void dot_kernel(float *output, float scale, int batch, int n, int size, float *delta) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + int f1 = index / n; + int f2 = index % n; + if (f2 <= f1) return; + + float sum = 0; + float norm1 = 0; + float norm2 = 0; + int b, i; + for(b = 0; b < batch; ++b){ + for(i = 0; i < size; ++i){ + int i1 = b * size * n + f1 * size + i; + int i2 = b * size * n + f2 * size + i; + sum += output[i1] * output[i2]; + norm1 += output[i1] * output[i1]; + norm2 += output[i2] * output[i2]; + } + } + norm1 = sqrt(norm1); + norm2 = sqrt(norm2); + float norm = norm1 * norm2; + sum = sum / norm; + for(b = 0; b < batch; ++b){ + for(i = 0; i < size; ++i){ + int i1 = b * size * n + f1 * size + i; + int i2 = b * size * n + f2 * size + i; + delta[i1] += - scale * sum * output[i2] / norm; + delta[i2] += - scale * sum * output[i1] / norm; + } + } +} + +void dot_error_gpu(layer l) +{ + dot_kernel<<<cuda_gridsize(l.n*l.n), BLOCK>>>(l.output_gpu, l.dot, l.batch, l.n, l.out_w * l.out_h, l.delta_gpu); + check_error(cudaPeekAtLastError()); +} +*/ + + +__global__ void adam_kernel(int N, float *x, float *m, float *v, float B1, float B2, float rate, float eps, int t) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (index >= N) return; + + float mhat = m[index] / (1.f - powf(B1, t)); + float vhat = v[index] / (1.f - powf(B2, t)); + + x[index] = x[index] + rate * mhat / (sqrtf(vhat) + eps); +} + +extern "C" void adam_gpu(int n, float *x, float *m, float *v, float B1, float B2, float rate, float eps, int t) +{ + adam_kernel<<<cuda_gridsize(n), BLOCK>>>(n, x, m, v, B1, B2, rate, eps, t); + check_error(cudaPeekAtLastError()); +} + +extern "C" void adam_update_gpu(float *w, float *d, float *m, float *v, float B1, float B2, float eps, float decay, float rate, int n, int batch, int t) +{ + scal_gpu(n, B1, m, 1); + scal_gpu(n, B2, v, 1); + axpy_gpu(n, -decay*batch, w, 1, d, 1); + + axpy_gpu(n, (1-B1), d, 1, m, 1); + mul_gpu(n, d, 1, d, 1); + axpy_gpu(n, (1-B2), d, 1, v, 1); + + adam_gpu(n, w, m, v, B1, B2, rate, eps, t); + fill_gpu(n, 0, d, 1); +} + +__global__ void normalize_kernel(int N, float *x, float *mean, float *variance, int batch, int filters, int spatial) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (index >= N) return; + int f = (index/spatial)%filters; + + x[index] = (x[index] - mean[f])/(sqrtf(variance[f] + .00001f)); +} + +__global__ void normalize_delta_kernel(int N, float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (index >= N) return; + int f = (index/spatial)%filters; + + delta[index] = delta[index] * 1.f/(sqrtf(variance[f] + .00001f)) + variance_delta[f] * 2.f * (x[index] - mean[f]) / (spatial * batch) + mean_delta[f]/(spatial*batch); +} + +extern "C" void normalize_delta_gpu(float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta) +{ + size_t N = batch*filters*spatial; + normalize_delta_kernel<<<cuda_gridsize(N), BLOCK>>>(N, x, mean, variance, mean_delta, variance_delta, batch, filters, spatial, delta); + check_error(cudaPeekAtLastError()); +} + +__global__ void variance_delta_kernel(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (i >= filters) return; + int j,k; + variance_delta[i] = 0; + for(j = 0; j < batch; ++j){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + i*spatial + k; + variance_delta[i] += delta[index]*(x[index] - mean[i]); + } + } + variance_delta[i] *= -.5f * powf(variance[i] + .00001f, (float)(-3.f/2.f)); +} + +__global__ void accumulate_kernel(float *x, int n, int groups, float *sum) +{ + int k; + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (i >= groups) return; + sum[i] = 0; + for(k = 0; k < n; ++k){ + sum[i] += x[k*groups + i]; + } +} + +__global__ void fast_mean_delta_kernel(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta) +{ + const int threads = BLOCK; + __shared__ float local[threads]; + + int id = threadIdx.x; + local[id] = 0; + + int filter = blockIdx.x; + + int i, j; + for(j = 0; j < batch; ++j){ + for(i = 0; i < spatial; i += threads){ + int index = j*spatial*filters + filter*spatial + i + id; + local[id] += (i+id < spatial) ? delta[index] : 0; + } + } + + __syncthreads(); + + if(id == 0){ + mean_delta[filter] = 0; + for(i = 0; i < threads; ++i){ + mean_delta[filter] += local[i]; + } + mean_delta[filter] *= (-1.f/sqrtf(variance[filter] + .00001f)); + } +} + +__global__ void fast_variance_delta_kernel(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta) +{ + const int threads = BLOCK; + __shared__ float local[threads]; + + int id = threadIdx.x; + local[id] = 0; + + int filter = blockIdx.x; + + int i, j; + for(j = 0; j < batch; ++j){ + for(i = 0; i < spatial; i += threads){ + int index = j*spatial*filters + filter*spatial + i + id; + + local[id] += (i+id < spatial) ? delta[index]*(x[index] - mean[filter]) : 0; + } + } + + __syncthreads(); + + if(id == 0){ + variance_delta[filter] = 0; + for(i = 0; i < threads; ++i){ + variance_delta[filter] += local[i]; + } + variance_delta[filter] *= -.5f * powf(variance[filter] + .00001f, (float)(-3.f/2.f)); + } +} + + +__global__ void mean_delta_kernel(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (i >= filters) return; + int j,k; + mean_delta[i] = 0; + for (j = 0; j < batch; ++j) { + for (k = 0; k < spatial; ++k) { + int index = j*filters*spatial + i*spatial + k; + mean_delta[i] += delta[index]; + } + } + mean_delta[i] *= (-1.f/sqrtf(variance[i] + .00001f)); +} + +extern "C" void mean_delta_gpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta) +{ + mean_delta_kernel<<<cuda_gridsize(filters), BLOCK>>>(delta, variance, batch, filters, spatial, mean_delta); + check_error(cudaPeekAtLastError()); +} + +extern "C" void fast_mean_delta_gpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta) +{ + fast_mean_delta_kernel<<<filters, BLOCK>>>(delta, variance, batch, filters, spatial, mean_delta); + check_error(cudaPeekAtLastError()); +} + +extern "C" void fast_variance_delta_gpu(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta) +{ + fast_variance_delta_kernel<<<filters, BLOCK>>>(x, delta, mean, variance, batch, filters, spatial, variance_delta); + check_error(cudaPeekAtLastError()); +} + +__global__ void mean_kernel(float *x, int batch, int filters, int spatial, float *mean) +{ + float scale = 1.f/(batch * spatial); + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (i >= filters) return; + int j,k; + mean[i] = 0; + for(j = 0; j < batch; ++j){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + i*spatial + k; + mean[i] += x[index]; + } + } + mean[i] *= scale; +} + +__global__ void variance_kernel(float *x, float *mean, int batch, int filters, int spatial, float *variance) +{ + float scale = 1.f/(batch * spatial - 1); + int j,k; + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (i >= filters) return; + variance[i] = 0; + for(j = 0; j < batch; ++j){ + for(k = 0; k < spatial; ++k){ + int index = j*filters*spatial + i*spatial + k; + variance[i] += powf((x[index] - mean[i]), 2); + } + } + variance[i] *= scale; +} + +__global__ void reorg_kernel(int N, float *x, int w, int h, int c, int batch, int stride, int forward, float *out) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i >= N) return; + int in_index = i; + int in_w = i%w; + i = i/w; + int in_h = i%h; + i = i/h; + int in_c = i%c; + i = i/c; + int b = i%batch; + + int out_c = c/(stride*stride); + + int c2 = in_c % out_c; + int offset = in_c / out_c; + int w2 = in_w*stride + offset % stride; + int h2 = in_h*stride + offset / stride; + //printf("%d\n", offset); + int out_index = w2 + w*stride*(h2 + h*stride*(c2 + out_c*b)); + + // printf("%d %d %d\n", w2, h2, c2); + //printf("%d %d\n", in_index, out_index); + //if(out_index >= N || out_index < 0) printf("bad bad bad \n"); + + if(forward) out[out_index] = x[in_index]; + else out[in_index] = x[out_index]; + //if(forward) out[1] = x[1]; + //else out[0] = x[0]; +} + +__global__ void axpy_kernel(int N, float ALPHA, float *X, int OFFX, int INCX, float *Y, int OFFY, int INCY) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) Y[OFFY+i*INCY] += ALPHA*X[OFFX+i*INCX]; +} + +__global__ void pow_kernel(int N, float ALPHA, float *X, int INCX, float *Y, int INCY) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) Y[i*INCY] = pow(X[i*INCX], ALPHA); +} + +__global__ void const_kernel(int N, float ALPHA, float *X, int INCX) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) X[i*INCX] = ALPHA; +} + +__global__ void constrain_kernel(int N, float ALPHA, float *X, int INCX) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) X[i*INCX] = fminf(ALPHA, fmaxf(-ALPHA, X[i*INCX])); +} + +__global__ void supp_kernel(int N, float ALPHA, float *X, int INCX) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) { + if((X[i*INCX] * X[i*INCX]) < (ALPHA * ALPHA)) X[i*INCX] = 0; + } +} + +__global__ void add_kernel(int N, float ALPHA, float *X, int INCX) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) X[i*INCX] += ALPHA; +} + +__global__ void scal_kernel(int N, float ALPHA, float *X, int INCX) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) X[i*INCX] *= ALPHA; +} + +__global__ void fill_kernel(int N, float ALPHA, float *X, int INCX) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) X[i*INCX] = ALPHA; +} + +__global__ void copy_kernel(int N, float *X, int OFFX, int INCX, float *Y, int OFFY, int INCY) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) Y[i*INCY + OFFY] = X[i*INCX + OFFX]; +} + +__global__ void mul_kernel(int N, float *X, int INCX, float *Y, int INCY) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < N) Y[i*INCY] *= X[i*INCX]; +} + + +extern "C" void normalize_gpu(float *x, float *mean, float *variance, int batch, int filters, int spatial) +{ + size_t N = batch*filters*spatial; + normalize_kernel<<<cuda_gridsize(N), BLOCK>>>(N, x, mean, variance, batch, filters, spatial); + check_error(cudaPeekAtLastError()); +} + +__global__ void l2norm_kernel(int N, float *x, float *dx, int batch, int filters, int spatial) +{ + int index = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (index >= N) return; + int b = index / spatial; + int i = index % spatial; + int f; + float sum = 0; + for(f = 0; f < filters; ++f){ + int index = b*filters*spatial + f*spatial + i; + sum += powf(x[index], 2); + } + sum = sqrtf(sum); + if(sum == 0) sum = 1; + //printf("%f\n", sum); + for(f = 0; f < filters; ++f){ + int index = b*filters*spatial + f*spatial + i; + x[index] /= sum; + dx[index] = (1 - x[index]) / sum; + } +} + +extern "C" void l2normalize_gpu(float *x, float *dx, int batch, int filters, int spatial) +{ + size_t N = batch*spatial; + l2norm_kernel<<<cuda_gridsize(N), BLOCK>>>(N, x, dx, batch, filters, spatial); + check_error(cudaPeekAtLastError()); +} + +__global__ void fast_mean_kernel(float *x, int batch, int filters, int spatial, float *mean) +{ + const int threads = BLOCK; + __shared__ float local[threads]; + + int id = threadIdx.x; + local[id] = 0; + + int filter = blockIdx.x; + + int i, j; + for(j = 0; j < batch; ++j){ + for(i = 0; i < spatial; i += threads){ + int index = j*spatial*filters + filter*spatial + i + id; + local[id] += (i+id < spatial) ? x[index] : 0; + } + } + + __syncthreads(); + + if(id == 0){ + mean[filter] = 0; + for(i = 0; i < threads; ++i){ + mean[filter] += local[i]; + } + mean[filter] /= spatial * batch; + } +} + +__global__ void fast_variance_kernel(float *x, float *mean, int batch, int filters, int spatial, float *variance) +{ + const int threads = BLOCK; + __shared__ float local[threads]; + + int id = threadIdx.x; + local[id] = 0; + + int filter = blockIdx.x; + + int i, j; + for(j = 0; j < batch; ++j){ + for(i = 0; i < spatial; i += threads){ + int index = j*spatial*filters + filter*spatial + i + id; + + local[id] += (i+id < spatial) ? powf((x[index] - mean[filter]), 2) : 0; + } + } + + __syncthreads(); + + if(id == 0){ + variance[filter] = 0; + for(i = 0; i < threads; ++i){ + variance[filter] += local[i]; + } + variance[filter] /= (spatial * batch - 1); + } +} + +extern "C" void fast_mean_gpu(float *x, int batch, int filters, int spatial, float *mean) +{ + fast_mean_kernel<<<filters, BLOCK>>>(x, batch, filters, spatial, mean); + check_error(cudaPeekAtLastError()); +} + +extern "C" void fast_variance_gpu(float *x, float *mean, int batch, int filters, int spatial, float *variance) +{ + fast_variance_kernel<<<filters, BLOCK>>>(x, mean, batch, filters, spatial, variance); + check_error(cudaPeekAtLastError()); +} + + +extern "C" void mean_gpu(float *x, int batch, int filters, int spatial, float *mean) +{ + mean_kernel<<<cuda_gridsize(filters), BLOCK>>>(x, batch, filters, spatial, mean); + check_error(cudaPeekAtLastError()); +} + +extern "C" void variance_gpu(float *x, float *mean, int batch, int filters, int spatial, float *variance) +{ + variance_kernel<<<cuda_gridsize(filters), BLOCK>>>(x, mean, batch, filters, spatial, variance); + check_error(cudaPeekAtLastError()); +} + +extern "C" void axpy_gpu(int N, float ALPHA, float * X, int INCX, float * Y, int INCY) +{ + axpy_gpu_offset(N, ALPHA, X, 0, INCX, Y, 0, INCY); +} + +extern "C" void pow_gpu(int N, float ALPHA, float * X, int INCX, float * Y, int INCY) +{ + pow_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX, Y, INCY); + check_error(cudaPeekAtLastError()); +} + +extern "C" void axpy_gpu_offset(int N, float ALPHA, float * X, int OFFX, int INCX, float * Y, int OFFY, int INCY) +{ + axpy_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, OFFX, INCX, Y, OFFY, INCY); + check_error(cudaPeekAtLastError()); +} + +extern "C" void copy_gpu(int N, float * X, int INCX, float * Y, int INCY) +{ + copy_gpu_offset(N, X, 0, INCX, Y, 0, INCY); +} + +extern "C" void mul_gpu(int N, float * X, int INCX, float * Y, int INCY) +{ + mul_kernel<<<cuda_gridsize(N), BLOCK>>>(N, X, INCX, Y, INCY); + check_error(cudaPeekAtLastError()); +} + +extern "C" void copy_gpu_offset(int N, float * X, int OFFX, int INCX, float * Y, int OFFY, int INCY) +{ + copy_kernel<<<cuda_gridsize(N), BLOCK>>>(N, X, OFFX, INCX, Y, OFFY, INCY); + check_error(cudaPeekAtLastError()); +} + +__global__ void flatten_kernel(int N, float *x, int spatial, int layers, int batch, int forward, float *out) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i >= N) return; + int in_s = i%spatial; + i = i/spatial; + int in_c = i%layers; + i = i/layers; + int b = i; + + int i1 = b*layers*spatial + in_c*spatial + in_s; + int i2 = b*layers*spatial + in_s*layers + in_c; + + if (forward) out[i2] = x[i1]; + else out[i1] = x[i2]; +} + +extern "C" void flatten_gpu(float *x, int spatial, int layers, int batch, int forward, float *out) +{ + int size = spatial*batch*layers; + flatten_kernel<<<cuda_gridsize(size), BLOCK>>>(size, x, spatial, layers, batch, forward, out); + check_error(cudaPeekAtLastError()); +} + +extern "C" void reorg_gpu(float *x, int w, int h, int c, int batch, int stride, int forward, float *out) +{ + int size = w*h*c*batch; + reorg_kernel<<<cuda_gridsize(size), BLOCK>>>(size, x, w, h, c, batch, stride, forward, out); + check_error(cudaPeekAtLastError()); +} + +__global__ void mask_kernel(int n, float *x, float mask_num, float *mask, float val) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n && mask[i] == mask_num) x[i] = val; +} + +extern "C" void mask_gpu(int N, float * X, float mask_num, float * mask, float val) +{ + mask_kernel<<<cuda_gridsize(N), BLOCK>>>(N, X, mask_num, mask, val); + check_error(cudaPeekAtLastError()); +} + +__global__ void scale_mask_kernel(int n, float *x, float mask_num, float *mask, float scale) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n && mask[i] == mask_num) x[i] *= scale; +} + +extern "C" void scale_mask_gpu(int N, float * X, float mask_num, float * mask, float scale) +{ + scale_mask_kernel<<<cuda_gridsize(N), BLOCK>>>(N, X, mask_num, mask, scale); + check_error(cudaPeekAtLastError()); +} + +extern "C" void const_gpu(int N, float ALPHA, float * X, int INCX) +{ + const_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX); + check_error(cudaPeekAtLastError()); +} + +extern "C" void constrain_gpu(int N, float ALPHA, float * X, int INCX) +{ + constrain_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX); + check_error(cudaPeekAtLastError()); +} + + +extern "C" void add_gpu(int N, float ALPHA, float * X, int INCX) +{ + add_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX); + check_error(cudaPeekAtLastError()); +} + +extern "C" void scal_gpu(int N, float ALPHA, float * X, int INCX) +{ + scal_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX); + check_error(cudaPeekAtLastError()); +} + +extern "C" void supp_gpu(int N, float ALPHA, float * X, int INCX) +{ + supp_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX); + check_error(cudaPeekAtLastError()); +} + +extern "C" void fill_gpu(int N, float ALPHA, float * X, int INCX) +{ + fill_kernel<<<cuda_gridsize(N), BLOCK>>>(N, ALPHA, X, INCX); + check_error(cudaPeekAtLastError()); +} + +__global__ void shortcut_kernel(int size, int minw, int minh, int minc, int stride, int sample, int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float s1, float s2, float *out) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (id >= size) return; + int i = id % minw; + id /= minw; + int j = id % minh; + id /= minh; + int k = id % minc; + id /= minc; + int b = id % batch; + + int out_index = i*sample + w2*(j*sample + h2*(k + c2*b)); + int add_index = i*stride + w1*(j*stride + h1*(k + c1*b)); + out[out_index] = s1*out[out_index] + s2*add[add_index]; + //out[out_index] += add[add_index]; +} + +extern "C" void shortcut_gpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float s1, float s2, float *out) +{ + int minw = (w1 < w2) ? w1 : w2; + int minh = (h1 < h2) ? h1 : h2; + int minc = (c1 < c2) ? c1 : c2; + + int stride = w1/w2; + int sample = w2/w1; + assert(stride == h1/h2); + assert(sample == h2/h1); + if(stride < 1) stride = 1; + if(sample < 1) sample = 1; + + int size = batch * minw * minh * minc; + shortcut_kernel<<<cuda_gridsize(size), BLOCK>>>(size, minw, minh, minc, stride, sample, batch, w1, h1, c1, add, w2, h2, c2, s1, s2, out); + check_error(cudaPeekAtLastError()); +} + +__global__ void smooth_l1_kernel(int n, float *pred, float *truth, float *delta, float *error) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + float diff = truth[i] - pred[i]; + float abs_val = fabsf(diff); + if(abs_val < 1) { + error[i] = diff * diff; + delta[i] = diff; + } + else { + error[i] = 2*abs_val - 1; + delta[i] = (diff > 0) ? 1 : -1; + } + } +} + +extern "C" void smooth_l1_gpu(int n, float *pred, float *truth, float *delta, float *error) +{ + smooth_l1_kernel<<<cuda_gridsize(n), BLOCK>>>(n, pred, truth, delta, error); + check_error(cudaPeekAtLastError()); +} + +__global__ void softmax_x_ent_kernel(int n, float *pred, float *truth, float *delta, float *error) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + float t = truth[i]; + float p = pred[i]; + error[i] = (t) ? -log(p) : 0; + delta[i] = t-p; + } +} + +extern "C" void softmax_x_ent_gpu(int n, float *pred, float *truth, float *delta, float *error) +{ + softmax_x_ent_kernel<<<cuda_gridsize(n), BLOCK>>>(n, pred, truth, delta, error); + check_error(cudaPeekAtLastError()); +} + +__global__ void logistic_x_ent_kernel(int n, float *pred, float *truth, float *delta, float *error) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + float t = truth[i]; + float p = pred[i]; + error[i] = -t*log(p+.0000001) - (1-t)*log(1-p+.0000001); + delta[i] = t-p; + } +} + +extern "C" void logistic_x_ent_gpu(int n, float *pred, float *truth, float *delta, float *error) +{ + logistic_x_ent_kernel<<<cuda_gridsize(n), BLOCK>>>(n, pred, truth, delta, error); + check_error(cudaPeekAtLastError()); +} + +__global__ void l2_kernel(int n, float *pred, float *truth, float *delta, float *error) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + float diff = truth[i] - pred[i]; + error[i] = diff * diff; //I know this is technically wrong, deal with it. + delta[i] = diff; + } +} + +extern "C" void l2_gpu(int n, float *pred, float *truth, float *delta, float *error) +{ + l2_kernel<<<cuda_gridsize(n), BLOCK>>>(n, pred, truth, delta, error); + check_error(cudaPeekAtLastError()); +} + +__global__ void l1_kernel(int n, float *pred, float *truth, float *delta, float *error) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + float diff = truth[i] - pred[i]; + error[i] = abs(diff); + delta[i] = (diff > 0) ? 1 : -1; + } +} + +extern "C" void l1_gpu(int n, float *pred, float *truth, float *delta, float *error) +{ + l1_kernel<<<cuda_gridsize(n), BLOCK>>>(n, pred, truth, delta, error); + check_error(cudaPeekAtLastError()); +} + +__global__ void wgan_kernel(int n, float *pred, float *truth, float *delta, float *error) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + error[i] = truth[i] ? -pred[i] : pred[i]; + delta[i] = (truth[i] > 0) ? 1 : -1; + } +} + +extern "C" void wgan_gpu(int n, float *pred, float *truth, float *delta, float *error) +{ + wgan_kernel<<<cuda_gridsize(n), BLOCK>>>(n, pred, truth, delta, error); + check_error(cudaPeekAtLastError()); +} + + + + +__global__ void weighted_sum_kernel(int n, float *a, float *b, float *s, float *c) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + c[i] = s[i]*a[i] + (1-s[i])*(b ? b[i] : 0); + } +} + +__global__ void deinter_kernel(int NX, float *X, int NY, float *Y, int B, float *OUT) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < (NX+NY)*B){ + int b = i / (NX+NY); + int j = i % (NX+NY); + if (j < NX){ + if(X) X[b*NX + j] += OUT[i]; + } else { + if(Y) Y[b*NY + j - NX] += OUT[i]; + } + } +} + +extern "C" void deinter_gpu(int NX, float *X, int NY, float *Y, int B, float *OUT) +{ + deinter_kernel<<<cuda_gridsize((NX+NY)*B), BLOCK>>>(NX, X, NY, Y, B, OUT); + check_error(cudaPeekAtLastError()); +} + +__global__ void inter_kernel(int NX, float *X, int NY, float *Y, int B, float *OUT) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < (NX+NY)*B){ + int b = i / (NX+NY); + int j = i % (NX+NY); + if (j < NX){ + OUT[i] = X[b*NX + j]; + } else { + OUT[i] = Y[b*NY + j - NX]; + } + } +} + +extern "C" void inter_gpu(int NX, float *X, int NY, float *Y, int B, float *OUT) +{ + inter_kernel<<<cuda_gridsize((NX+NY)*B), BLOCK>>>(NX, X, NY, Y, B, OUT); + check_error(cudaPeekAtLastError()); +} + +extern "C" void weighted_sum_gpu(float *a, float *b, float *s, int num, float *c) +{ + weighted_sum_kernel<<<cuda_gridsize(num), BLOCK>>>(num, a, b, s, c); + check_error(cudaPeekAtLastError()); +} + +__global__ void weighted_delta_kernel(int n, float *a, float *b, float *s, float *da, float *db, float *ds, float *dc) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + if(da) da[i] += dc[i] * s[i]; + if(db) db[i] += dc[i] * (1-s[i]); + ds[i] += dc[i] * (a[i] - b[i]); + } +} + +extern "C" void weighted_delta_gpu(float *a, float *b, float *s, float *da, float *db, float *ds, int num, float *dc) +{ + weighted_delta_kernel<<<cuda_gridsize(num), BLOCK>>>(num, a, b, s, da, db, ds, dc); + check_error(cudaPeekAtLastError()); +} + +__global__ void mult_add_into_kernel(int n, float *a, float *b, float *c) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i < n){ + c[i] += a[i]*b[i]; + } +} + +extern "C" void mult_add_into_gpu(int num, float *a, float *b, float *c) +{ + mult_add_into_kernel<<<cuda_gridsize(num), BLOCK>>>(num, a, b, c); + check_error(cudaPeekAtLastError()); +} + + +__device__ void softmax_device(float *input, int n, float temp, int stride, float *output) +{ + int i; + float sum = 0; + float largest = -INFINITY; + for(i = 0; i < n; ++i){ + int val = input[i*stride]; + largest = (val>largest) ? val : largest; + } + for(i = 0; i < n; ++i){ + float e = expf(input[i*stride]/temp - largest/temp); + sum += e; + output[i*stride] = e; + } + for(i = 0; i < n; ++i){ + output[i*stride] /= sum; + } +} + + +__global__ void softmax_tree_kernel(float *input, int spatial, int batch, int stride, float temp, float *output, int groups, int *group_size, int *group_offset) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (id >= spatial*batch*groups) return; + int s = id % spatial; + id = id / spatial; + int g = id % groups; + int b = id / groups; + int goff = group_offset[g]*spatial; + int boff = b*stride; + softmax_device(input + goff + boff + s, group_size[g], temp, spatial, output + goff + boff + s); +} + +extern "C" void softmax_tree(float *input, int spatial, int batch, int stride, float temp, float *output, tree hier) +{ + int *tree_groups_size = cuda_make_int_array(hier.group_size, hier.groups); + int *tree_groups_offset = cuda_make_int_array(hier.group_offset, hier.groups); + /* + static int *tree_groups_size = 0; + static int *tree_groups_offset = 0; + if(!tree_groups_size){ + tree_groups_size = cuda_make_int_array(hier.group_size, hier.groups); + tree_groups_offset = cuda_make_int_array(hier.group_offset, hier.groups); + } + */ + int num = spatial*batch*hier.groups; + softmax_tree_kernel<<<cuda_gridsize(num), BLOCK>>>(input, spatial, batch, stride, temp, output, hier.groups, tree_groups_size, tree_groups_offset); + check_error(cudaPeekAtLastError()); + cuda_free((float *)tree_groups_size); + cuda_free((float *)tree_groups_offset); +} + +__global__ void softmax_kernel(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (id >= batch*groups) return; + int b = id / groups; + int g = id % groups; + softmax_device(input + b*batch_offset + g*group_offset, n, temp, stride, output + b*batch_offset + g*group_offset); +} + +extern "C" void softmax_gpu(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output) +{ + softmax_kernel<<<cuda_gridsize(batch*groups), BLOCK>>>(input, n, batch, batch_offset, groups, group_offset, stride, temp, output); + check_error(cudaPeekAtLastError()); +} + + +__global__ void upsample_kernel(size_t N, float *x, int w, int h, int c, int batch, int stride, int forward, float scale, float *out) +{ + size_t i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(i >= N) return; + int out_index = i; + int out_w = i%(w*stride); + i = i/(w*stride); + int out_h = i%(h*stride); + i = i/(h*stride); + int out_c = i%c; + i = i/c; + int b = i%batch; + + int in_w = out_w / stride; + int in_h = out_h / stride; + int in_c = out_c; + + int in_index = b*w*h*c + in_c*w*h + in_h*w + in_w; + + + if(forward) out[out_index] += scale * x[in_index]; + else atomicAdd(x+in_index, scale * out[out_index]); +} +extern "C" void upsample_gpu(float *in, int w, int h, int c, int batch, int stride, int forward, float scale, float *out) +{ + size_t size = w*h*c*batch*stride*stride; + upsample_kernel<<<cuda_gridsize(size), BLOCK>>>(size, in, w, h, c, batch, stride, forward, scale, out); + check_error(cudaPeekAtLastError()); +} diff --git a/src/block_to_send.c b/src/block_to_send.c new file mode 100644 index 0000000..c058025 --- /dev/null +++ b/src/block_to_send.c @@ -0,0 +1,296 @@ +#include <sys/select.h> + +#include "block_to_send.h" +#include <time.h> + +#ifdef GY_OS_WIN +#include <direct.h> +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined GY_OS_AMBA || defined GY_OS_NOVA +#include <errno.h> +#include <netdb.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/tcp.h> + +#include <netinet/in.h> +#include <arpa/inet.h> + +typedef unsigned int DWORD; +typedef unsigned char BYTE; +#endif + + +#define is_sock_ready_write(s, u) is_sock_ready_write_ex(s, u, __FILE__, __func__, __LINE__) + +int is_sock_ready_write_ex( int sock , long usec, const char *fp, const char *fn, int ln ) +{ + int rc; + fd_set fdwrites; + struct timeval tv; + + FD_ZERO(&fdwrites); + if(sock > 0) FD_SET(sock, &fdwrites); + else return -1; + + if(usec < 1000000 ) + { + tv.tv_sec = 0; + tv.tv_usec = usec; + } + else + { + tv.tv_sec = usec / 1000000; + tv.tv_usec = usec % 1000000; + } + + rc = select(sock+1, NULL, &fdwrites, NULL, &tv); + + if (rc < 0) + { + + //KDEBUG("%s:%s:%d - %d:(%d)\n", fp, fn, ln, sock, errno); + return -1; + } + else + { + return FD_ISSET(sock, &fdwrites) ? 1 : 0; + } +} + +void get_sys_monotonic_raw_time( struct timespec *monotonic_time ) +{ + //clock_gettime( CLK_MONOTONIC_TYPE, monotonic_time); + clock_gettime(CLOCK_MONOTONIC_RAW, monotonic_time); +} + +void wait_untilTimeout( DWORD timeout_usec, struct timespec *s_timespec ) +{ + struct timespec e_timespec; + DWORD used_usec = 0; + get_sys_monotonic_raw_time( &e_timespec ); + + used_usec = ( ((e_timespec.tv_sec - s_timespec->tv_sec)*1000000) + (e_timespec.tv_nsec/1000) - (s_timespec->tv_nsec/1000)); + if( used_usec > 0 ) + { + if( used_usec < timeout_usec ) + usSleep( (timeout_usec-used_usec ) ); + } +} + +unsigned long GetPortBySocket(int conn_fd) +{ + struct sockaddr_in sa; + int sa_len; + sa_len = sizeof(sa); + if (getpeername(conn_fd, (struct sockaddr *)&sa, (socklen_t *)&sa_len) == -1) + { + ///printf("\nGetPortBySocket: getpeername() failed.\n"); + return 0; + } + + return htons(sa.sin_port); +} + +#if 0 +char *GetIPv4StringBySocket(int conn_fd, char *szIPv4) +{ + struct in_addr sin; + sin.s_addr = GetIPv4BySocket(conn_fd); + inet_ntop(AF_INET, &sin, szIPv4, MAX_IP_ADDR_LEN); + return szIPv4; +} +#endif + + +long block_to_send(int fd, BYTE* data, long datalen, DWORD usec, long dispart_size, char *dest ) +{ + int max_retry = 0; + long len = 0; + long already_send = 0; + long rest_len = 0; + DWORD rest_timeout = 0; + DWORD standard_timeout = 1000000; + DWORD curr_timeout = 0; + struct timespec sendTimeSpec; + int ready_w = 0; + + //printf("block block block block block block block block: send len: %d \n", strlen(data)); + + if( usec > standard_timeout ) + { + max_retry = usec / standard_timeout; + if ( usec % standard_timeout ) + { + rest_timeout = usec % standard_timeout; + max_retry ++; + } + else + rest_timeout = standard_timeout; + } + else + { + max_retry = 1; + rest_timeout = usec; + } + + if( dispart_size > 0) + { + rest_len = datalen; + while( max_retry ) + { + get_sys_monotonic_raw_time( &sendTimeSpec ); + if ( max_retry == 1 ) + curr_timeout = rest_timeout; + else + curr_timeout = standard_timeout; + + //printf("b_AAAAA \n"); + + ready_w = is_sock_ready_write( fd, curr_timeout ); + if( ready_w > 0 ) + { + if (rest_len >= dispart_size) + { + len = send(fd, data + already_send, dispart_size, MSG_NOSIGNAL); + + //printf("b_BBBBB %ld \n", len); + } + else + { + len = send(fd, data + already_send, rest_len, MSG_NOSIGNAL); + //printf("b_CCCCC %ld \n", len); + } + + if(len > 0)//if can sent try until failed. + { + //printf("b_DDDDD\n"); + + already_send += len; + rest_len = datalen - already_send; + if(already_send >= datalen ) + break; + else + { + //KDEBUG("already_send:%ld\n",already_send); + usSleep(1); + continue; + } + } + else if (len < 0) + { + //printf("b_EEEEE\n"); +#if 0 + if( errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS ) + { + //KDEBUG("%d %s errno %d\n", fd, dest?dest:"",errno); + --max_retry; + wait_untilTimeout( curr_timeout, &sendTimeSpec); + continue; + } + else + { + char szIPv4[32] = {0}; + GetIPv4StringBySocket(fd, szIPv4); + //KDEBUG("%s(%d) (%d) %s.\n", szIPv4, fd, errno, dest?dest:""); + + already_send = -1; + break; + } +#endif + break; + } + else + { + --max_retry; + wait_untilTimeout( curr_timeout, &sendTimeSpec); + continue; + } + } + else if( ready_w == 0) + { + --max_retry; + wait_untilTimeout( curr_timeout, &sendTimeSpec); + continue; + } + else + { + break; + } + } + } + else + { + //printf("b_FFFFF\n"); + while( max_retry ) + { + get_sys_monotonic_raw_time( &sendTimeSpec ); + if ( max_retry == 1 ) + curr_timeout = rest_timeout; + else + curr_timeout = standard_timeout; + + ready_w = is_sock_ready_write( fd, curr_timeout ); + if( ready_w > 0 ) + { + //printf("s, r: %d, %d \n", already_send, (datalen - already_send)); + //printf("b_GGGGG send: \n %s \n", data); + len = send( fd , data + already_send, datalen - already_send, MSG_NOSIGNAL); + if(len > 0)//if can sent try until failed. + { + //printf("b_HHHHH\n"); + already_send += len; + if(already_send >= datalen ) + break; + else + { + usSleep(1); + continue; + } + } + else if(len < 0) + { + //printf("b_IIIII\n"); + if( errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS ) + { + //KDEBUG("%d %s errno %d\n", fd, dest?dest:"",errno); + --max_retry; + wait_untilTimeout( curr_timeout, &sendTimeSpec); + continue; + } + else + { +#if 0 + char szIPv4[32] = {0}; + GetIPv4StringBySocket(fd, szIPv4); + //KDEBUG("%s(%d) (%d) %s.\n", szIPv4, fd, errno, dest?dest:""); + + already_send = -1; +#endif + break; + } + } + else + { + --max_retry; + wait_untilTimeout( curr_timeout, &sendTimeSpec); + continue; + } + } + else if( ready_w == 0 ) + { + --max_retry; + wait_untilTimeout( curr_timeout, &sendTimeSpec); + continue; + } + else + { + break; + } + } + } + + return already_send; +} \ No newline at end of file diff --git a/src/block_to_send.h b/src/block_to_send.h new file mode 100644 index 0000000..308b9e0 --- /dev/null +++ b/src/block_to_send.h @@ -0,0 +1,18 @@ +#pragma once +#ifndef BLOCKTOSEND_H +#define BLOCKTOSEND_H +#include "define_inc.h" +#include <sys/select.h> +#include <stddef.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> + +#include "utility.h" + +typedef unsigned int DWORD; +typedef unsigned char BYTE; + +long block_to_send(int fd, BYTE* data, long datalen, DWORD usec, long dispart_size, char *dest); + +#endif \ No newline at end of file diff --git a/src/box.c b/src/box.c new file mode 100644 index 0000000..8a1772c --- /dev/null +++ b/src/box.c @@ -0,0 +1,357 @@ +#include "box.h" +#include <stdio.h> +#include <math.h> +#include <stdlib.h> + +int nms_comparator(const void *pa, const void *pb) +{ + detection a = *(detection *)pa; + detection b = *(detection *)pb; + float diff = 0; + if(b.sort_class >= 0){ + diff = a.prob[b.sort_class] - b.prob[b.sort_class]; + } else { + diff = a.objectness - b.objectness; + } + if(diff < 0) return 1; + else if(diff > 0) return -1; + return 0; +} + +void do_nms_obj(detection *dets, int total, int classes, float thresh) +{ + int i, j, k; + k = total-1; + for(i = 0; i <= k; ++i){ + if(dets[i].objectness == 0){ + detection swap = dets[i]; + dets[i] = dets[k]; + dets[k] = swap; + --k; + --i; + } + } + total = k+1; + + for(i = 0; i < total; ++i){ + dets[i].sort_class = -1; + } + + qsort(dets, total, sizeof(detection), nms_comparator); + for(i = 0; i < total; ++i){ + if(dets[i].objectness == 0) continue; + box a = dets[i].bbox; + for(j = i+1; j < total; ++j){ + if(dets[j].objectness == 0) continue; + box b = dets[j].bbox; + if (box_iou(a, b) > thresh){ + dets[j].objectness = 0; + for(k = 0; k < classes; ++k){ + dets[j].prob[k] = 0; + } + } + } + } +} + + +void do_nms_sort(detection *dets, int total, int classes, float thresh) +{ + int i, j, k; + k = total-1; + for(i = 0; i <= k; ++i){ + if(dets[i].objectness == 0){ + detection swap = dets[i]; + dets[i] = dets[k]; + dets[k] = swap; + --k; + --i; + } + } + total = k+1; + + for(k = 0; k < classes; ++k){ + for(i = 0; i < total; ++i){ + dets[i].sort_class = k; + } + qsort(dets, total, sizeof(detection), nms_comparator); + for(i = 0; i < total; ++i){ + if(dets[i].prob[k] == 0) continue; + box a = dets[i].bbox; + for(j = i+1; j < total; ++j){ + box b = dets[j].bbox; + if (box_iou(a, b) > thresh){ + dets[j].prob[k] = 0; + } + } + } + } +} + +box float_to_box(float *f, int stride) +{ + box b = {0}; + b.x = f[0]; + b.y = f[1*stride]; + b.w = f[2*stride]; + b.h = f[3*stride]; + return b; +} + +dbox derivative(box a, box b) +{ + dbox d; + d.dx = 0; + d.dw = 0; + float l1 = a.x - a.w/2; + float l2 = b.x - b.w/2; + if (l1 > l2){ + d.dx -= 1; + d.dw += .5; + } + float r1 = a.x + a.w/2; + float r2 = b.x + b.w/2; + if(r1 < r2){ + d.dx += 1; + d.dw += .5; + } + if (l1 > r2) { + d.dx = -1; + d.dw = 0; + } + if (r1 < l2){ + d.dx = 1; + d.dw = 0; + } + + d.dy = 0; + d.dh = 0; + float t1 = a.y - a.h/2; + float t2 = b.y - b.h/2; + if (t1 > t2){ + d.dy -= 1; + d.dh += .5; + } + float b1 = a.y + a.h/2; + float b2 = b.y + b.h/2; + if(b1 < b2){ + d.dy += 1; + d.dh += .5; + } + if (t1 > b2) { + d.dy = -1; + d.dh = 0; + } + if (b1 < t2){ + d.dy = 1; + d.dh = 0; + } + return d; +} + +float overlap(float x1, float w1, float x2, float w2) +{ + float l1 = x1 - w1/2; + float l2 = x2 - w2/2; + float left = l1 > l2 ? l1 : l2; + float r1 = x1 + w1/2; + float r2 = x2 + w2/2; + float right = r1 < r2 ? r1 : r2; + return right - left; +} + +float box_intersection(box a, box b) +{ + float w = overlap(a.x, a.w, b.x, b.w); + float h = overlap(a.y, a.h, b.y, b.h); + if(w < 0 || h < 0) return 0; + float area = w*h; + return area; +} + +float box_union(box a, box b) +{ + float i = box_intersection(a, b); + float u = a.w*a.h + b.w*b.h - i; + return u; +} + +float box_iou(box a, box b) +{ + return box_intersection(a, b)/box_union(a, b); +} + +float box_rmse(box a, box b) +{ + return sqrt(pow(a.x-b.x, 2) + + pow(a.y-b.y, 2) + + pow(a.w-b.w, 2) + + pow(a.h-b.h, 2)); +} + +dbox dintersect(box a, box b) +{ + float w = overlap(a.x, a.w, b.x, b.w); + float h = overlap(a.y, a.h, b.y, b.h); + dbox dover = derivative(a, b); + dbox di; + + di.dw = dover.dw*h; + di.dx = dover.dx*h; + di.dh = dover.dh*w; + di.dy = dover.dy*w; + + return di; +} + +dbox dunion(box a, box b) +{ + dbox du; + + dbox di = dintersect(a, b); + du.dw = a.h - di.dw; + du.dh = a.w - di.dh; + du.dx = -di.dx; + du.dy = -di.dy; + + return du; +} + + +void test_dunion() +{ + box a = {0, 0, 1, 1}; + box dxa= {0+.0001, 0, 1, 1}; + box dya= {0, 0+.0001, 1, 1}; + box dwa= {0, 0, 1+.0001, 1}; + box dha= {0, 0, 1, 1+.0001}; + + box b = {.5, .5, .2, .2}; + dbox di = dunion(a,b); + printf("Union: %f %f %f %f\n", di.dx, di.dy, di.dw, di.dh); + float inter = box_union(a, b); + float xinter = box_union(dxa, b); + float yinter = box_union(dya, b); + float winter = box_union(dwa, b); + float hinter = box_union(dha, b); + xinter = (xinter - inter)/(.0001); + yinter = (yinter - inter)/(.0001); + winter = (winter - inter)/(.0001); + hinter = (hinter - inter)/(.0001); + printf("Union Manual %f %f %f %f\n", xinter, yinter, winter, hinter); +} +void test_dintersect() +{ + box a = {0, 0, 1, 1}; + box dxa= {0+.0001, 0, 1, 1}; + box dya= {0, 0+.0001, 1, 1}; + box dwa= {0, 0, 1+.0001, 1}; + box dha= {0, 0, 1, 1+.0001}; + + box b = {.5, .5, .2, .2}; + dbox di = dintersect(a,b); + printf("Inter: %f %f %f %f\n", di.dx, di.dy, di.dw, di.dh); + float inter = box_intersection(a, b); + float xinter = box_intersection(dxa, b); + float yinter = box_intersection(dya, b); + float winter = box_intersection(dwa, b); + float hinter = box_intersection(dha, b); + xinter = (xinter - inter)/(.0001); + yinter = (yinter - inter)/(.0001); + winter = (winter - inter)/(.0001); + hinter = (hinter - inter)/(.0001); + printf("Inter Manual %f %f %f %f\n", xinter, yinter, winter, hinter); +} + +void test_box() +{ + test_dintersect(); + test_dunion(); + box a = {0, 0, 1, 1}; + box dxa= {0+.00001, 0, 1, 1}; + box dya= {0, 0+.00001, 1, 1}; + box dwa= {0, 0, 1+.00001, 1}; + box dha= {0, 0, 1, 1+.00001}; + + box b = {.5, 0, .2, .2}; + + float iou = box_iou(a,b); + iou = (1-iou)*(1-iou); + printf("%f\n", iou); + dbox d = diou(a, b); + printf("%f %f %f %f\n", d.dx, d.dy, d.dw, d.dh); + + float xiou = box_iou(dxa, b); + float yiou = box_iou(dya, b); + float wiou = box_iou(dwa, b); + float hiou = box_iou(dha, b); + xiou = ((1-xiou)*(1-xiou) - iou)/(.00001); + yiou = ((1-yiou)*(1-yiou) - iou)/(.00001); + wiou = ((1-wiou)*(1-wiou) - iou)/(.00001); + hiou = ((1-hiou)*(1-hiou) - iou)/(.00001); + printf("manual %f %f %f %f\n", xiou, yiou, wiou, hiou); +} + +dbox diou(box a, box b) +{ + float u = box_union(a,b); + float i = box_intersection(a,b); + dbox di = dintersect(a,b); + dbox du = dunion(a,b); + dbox dd = {0,0,0,0}; + + if(i <= 0 || 1) { + dd.dx = b.x - a.x; + dd.dy = b.y - a.y; + dd.dw = b.w - a.w; + dd.dh = b.h - a.h; + return dd; + } + + dd.dx = 2*pow((1-(i/u)),1)*(di.dx*u - du.dx*i)/(u*u); + dd.dy = 2*pow((1-(i/u)),1)*(di.dy*u - du.dy*i)/(u*u); + dd.dw = 2*pow((1-(i/u)),1)*(di.dw*u - du.dw*i)/(u*u); + dd.dh = 2*pow((1-(i/u)),1)*(di.dh*u - du.dh*i)/(u*u); + return dd; +} + + +void do_nms(box *boxes, float **probs, int total, int classes, float thresh) +{ + int i, j, k; + for(i = 0; i < total; ++i){ + int any = 0; + for(k = 0; k < classes; ++k) any = any || (probs[i][k] > 0); + if(!any) { + continue; + } + for(j = i+1; j < total; ++j){ + if (box_iou(boxes[i], boxes[j]) > thresh){ + for(k = 0; k < classes; ++k){ + if (probs[i][k] < probs[j][k]) probs[i][k] = 0; + else probs[j][k] = 0; + } + } + } + } +} + +box encode_box(box b, box anchor) +{ + box encode; + encode.x = (b.x - anchor.x) / anchor.w; + encode.y = (b.y - anchor.y) / anchor.h; + encode.w = log2(b.w / anchor.w); + encode.h = log2(b.h / anchor.h); + return encode; +} + +box decode_box(box b, box anchor) +{ + box decode; + decode.x = b.x * anchor.w + anchor.x; + decode.y = b.y * anchor.h + anchor.y; + decode.w = pow(2., b.w) * anchor.w; + decode.h = pow(2., b.h) * anchor.h; + return decode; +} diff --git a/src/box.h b/src/box.h new file mode 100644 index 0000000..bbac24c --- /dev/null +++ b/src/box.h @@ -0,0 +1,41 @@ +#pragma once +#ifndef BOX_H +#define BOX_H +#include "define_inc.h" +#include "darknet.h" + + +typedef struct { + float x, y, w, h; +} box; + +typedef struct{ + float dx, dy, dw, dh; +} dbox; + +typedef struct detection { + box bbox; + int classes; + float *prob; + float *mask; + float objectness; + int sort_class; +} detection; + +float box_rmse(box a, box b); +dbox diou(box a, box b); +box decode_box(box b, box anchor); +box encode_box(box b, box anchor); + +float box_iou(box a, box b); + + +box float_to_box(float *f, int stride); + +void free_detections(detection *dets, int n); + +char **get_labels(char *filename); +void do_nms_obj(detection *dets, int total, int classes, float thresh); +void do_nms_sort(detection *dets, int total, int classes, float thresh); + +#endif diff --git a/src/cJSON.c b/src/cJSON.c new file mode 100644 index 0000000..4a73576 --- /dev/null +++ b/src/cJSON.c @@ -0,0 +1,2948 @@ +/* +Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/* cJSON */ +/* JSON parser in C. */ + +/* disable warnings about old C89 functions in MSVC */ +#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#ifdef __GNUC__ +#pragma GCC visibility push(default) +#endif +#if defined(_MSC_VER) +#pragma warning (push) +/* disable warning about single line comments in system headers */ +#pragma warning (disable : 4001) +#endif + +#include <string.h> +#include <stdio.h> +#include <math.h> +#include <stdlib.h> +#include <limits.h> +#include <ctype.h> + +#ifdef ENABLE_LOCALES +#include <locale.h> +#endif + +#if defined(_MSC_VER) +#pragma warning (pop) +#endif +#ifdef __GNUC__ +#pragma GCC visibility pop +#endif + +#include "cJSON.h" + +/* define our own boolean type */ +#define true ((cJSON_bool)1) +#define false ((cJSON_bool)0) + +typedef struct { + const unsigned char *json; + size_t position; +} error; +static error global_error = { NULL, 0 }; + +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*)(global_error.json + global_error.position); +} + +CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) { + if (!cJSON_IsString(item)) { + return NULL; + } + + return item->valuestring; +} + +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 7) +#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#endif + +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + + return version; +} + +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +{ + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; + } + + if (string1 == string2) + { + return 0; + } + + for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); +} + +typedef struct internal_hooks +{ + void *(*allocate)(size_t size); + void(*deallocate)(void *pointer); + void *(*reallocate)(void *pointer, size_t size); +} internal_hooks; + +#if defined(_MSC_VER) +/* work around MSVC error C2322: '...' address of dillimport '...' is not static */ +static void *internal_malloc(size_t size) +{ + return malloc(size); +} +static void internal_free(void *pointer) +{ + if (pointer) { + free(pointer); + pointer = NULL; + } +} + +static void *internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); +} +#else +#define internal_malloc malloc +#define internal_free free +#define internal_realloc realloc +#endif + +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; + +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; + + if (string == NULL) + { + return NULL; + } + + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) + { + return NULL; + } + memcpy(copy, string, length); + + return copy; +} + +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + + global_hooks.deallocate = free; + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } + + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } +} + +/* Internal constructor. */ +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } + + return node; +} + +/* Delete a cJSON structure. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) +{ + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + item->child = NULL; + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + item->valuestring = NULL; + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + item->string = NULL; + } + global_hooks.deallocate(item); + item = NULL; + if(next != NULL) + item = next; + } +} + +/* get the decimal point character of the current locale */ +static unsigned char get_decimal_point(void) +{ +#ifdef ENABLE_LOCALES + struct lconv *lconv = localeconv(); + return (unsigned char)lconv->decimal_point[0]; +#else + return '.'; +#endif +} + +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; +} parse_buffer; + +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +/* check if the buffer can be accessed at the given index (starting with 0) */ +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) +/* get a pointer to the buffer at the position */ +#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) + +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; + + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } + } +loop_end: + number_c_string[i] = '\0'; + + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } + + item->valuedouble = number; + + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } + + item->type = cJSON_Number; + + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; +} + +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } + + return object->valuedouble = number; +} + +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; +} printbuffer; + +/* realloc printbuffer if necessary to have at least "needed" bytes more */ +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; + + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; + } + + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } + + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + if (newbuffer) + { + memcpy(newbuffer, p->buffer, p->offset + 1); + } + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; +} + +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; + + buffer->offset += strlen((const char*)buffer_pointer); +} + +/* Render the number nicely from the given item into a string. */ +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26]; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test; + + if (output_buffer == NULL) + { + return false; + } + + /* This checks for NaN and Infinity */ + if ((d * 0) != 0) + { + length = sprintf((char*)number_buffer, "null"); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); + + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) + { + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); + } + } + + /* sprintf failed or buffer overrun occured */ + if ((length < 0) || (length >(int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; +} + +/* parse 4 digit hexadecimal number */ +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; + + for (i = 0; i < 4; i++) + { + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int)input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int)10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int)10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } + } + + return h; +} + +/* converts a UTF-16 literal to UTF-8 +* A literal can be one or two sequences of the form \uXXXX */ +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; + + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); + + /* check that the code is valid */ + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; + } + + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ + + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } + + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } + + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; + +fail: + return 0; +} + +/* Parse the input text into an unescaped cinput, and populate item. */ +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; + + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { + goto fail; + } + + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } + + /* This is at most how much we need for the output */ + allocation_length = (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } + + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } + + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t)(input_end - input_buffer->content); + input_buffer->offset++; + + return true; + +fail: + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } + + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } + + return false; +} + +/* Render the cstring provided to an escaped version that can be printed. */ +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; + + if (output_buffer == NULL) + { + return false; + } + + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); + + return true; + } + + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } + + output[0] = '\"'; + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; +} + +/* Invoke print_string_ptr (which is useful) on an item. */ +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); +} + +/* Predeclare these prototypes. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); + +/* Utility to jump whitespace and cr/lf */ +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } + + return buffer; +} + +/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) + { + return NULL; + } + + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + { + buffer->offset += 3; + } + + return buffer; +} + +/* Parse an object - create a new root, and populate. */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + parse_buffer buffer = { 0, 0, 0, 0,{ 0, 0, 0 } }; + cJSON *item = NULL; + + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; + + if (value == NULL) + { + goto fail; + } + + buffer.content = (const unsigned char*)value; + buffer.length = strlen((const char*)value) + sizeof(""); + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; + +fail: + if (item != NULL) + { + cJSON_Delete(item); + } + + if (value != NULL) + { + error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; + } + + return NULL; +} + +/* Default options for cJSON_Parse */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); +} + +#define cjson_min(a, b) ((a < b) ? a : b) + +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + static const size_t default_buffer_size = 256; + printbuffer buffer[1]; + unsigned char *printed = NULL; + + memset(buffer, 0, sizeof(buffer)); + + /* create buffer */ + buffer->buffer = (unsigned char*)hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; + } + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; + } + update_offset(buffer); + + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*)hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (printed == NULL) { + goto fail; + } + buffer->buffer = NULL; + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*)hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ + + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; + +fail: + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } + + if (printed != NULL) + { + hooks->deallocate(printed); + } + + return NULL; +} + +/* Render a cJSON item/entity/structure to text. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0,{ 0, 0, 0 } }; + + if (prebuffer < 0) + { + return NULL; + } + + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } + + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; + + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } + + return (char*)p.buffer; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0,{ 0, 0, 0 } }; + + if ((len < 0) || (buf == NULL)) + { + return false; + } + + p.buffer = (unsigned char*)buf; + p.length = (size_t)len; + p.offset = 0; + p.noalloc = true; + p.format = fmt; + p.hooks = global_hooks; + + return print_value(item, &p); +} + +/* Parser core - when encountering text, process appropriately. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +{ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } + + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } + + return false; +} + +/* Render a value to text. */ +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output = NULL; + + if ((item == NULL) || (output_buffer == NULL)) + { + return false; + } + + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; + } +} + +/* Build an array from input text. */ +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Array; + item->child = head; + + input_buffer->offset++; + + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an array to text */ +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t)(output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if (output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Build an object from the text. */ +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* faile to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Object; + item->child = head; + + input_buffer->offset++; + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an object to text. */ +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output: */ + length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + output_buffer->offset += length; + + while (current_item) + { + if (output_buffer->format) + { + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } + + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t)(output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = (size_t)((output_buffer->format ? 1 : 0) + (current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; + } + + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Get Array size/item / object item. */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; + + if (array == NULL) + { + return 0; + } + + child = array->child; + + while (child != NULL) + { + size++; + child = child->next; + } + + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ + + return (int)size; +} + +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); +} + +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + //return get_object_item(object, string, false); + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; +} + +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; +} + +/* Utility for handling references. */ +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } + + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } + + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; +} + +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; + + if ((item == NULL) || (array == NULL)) + { + return false; + } + + child = array->child; + + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + } + else + { + /* append to the end */ + while (child->next) + { + child = child->next; + } + suffix_object(child, item); + } + + return true; +} + +/* Add item to array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + add_item_to_array(array, item); +} + +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#pragma GCC diagnostic push +#endif +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wcast-qual" +#endif +/* helper function to cast away const */ +static void* cast_away_const(const void* string) +{ + return (void*)string; +} +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#pragma GCC diagnostic pop +#endif + + +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +{ + char *new_key = NULL; + int new_type = cJSON_Invalid; + + if ((object == NULL) || (string == NULL) || (item == NULL)) + { + return false; + } + + if (constant_key) + { + new_key = (char*)cast_away_const(string); + new_type = item->type | cJSON_StringIsConst; + } + else + { + new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + if (new_key == NULL) + { + return false; + } + + new_type = item->type & ~cJSON_StringIsConst; + } + + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + hooks->deallocate(item->string); + } + + item->string = new_key; + item->type = new_type; + + return add_item_to_array(object, item); +} + +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + if (object != NULL && item != NULL) { + add_item_to_object(object, string, item, &global_hooks, false); + } +} + +/* Add an item to an object with constant string as key */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + if (object != NULL && item != NULL) { + add_item_to_object(object, string, item, &global_hooks, true); + } +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return; + } + + add_item_to_array(array, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return; + } + + add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +{ + cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) + { + return null; + } + + cJSON_Delete(null); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +{ + cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) + { + return true_item; + } + + cJSON_Delete(true_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +{ + cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) + { + return false_item; + } + + cJSON_Delete(false_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +{ + cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) + { + return bool_item; + } + + cJSON_Delete(bool_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +{ + cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) + { + return number_item; + } + + cJSON_Delete(number_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +{ + cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) + { + return string_item; + } + + cJSON_Delete(string_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +{ + cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) + { + return raw_item; + } + + cJSON_Delete(raw_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +{ + cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) + { + return object_item; + } + + cJSON_Delete(object_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +{ + cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) + { + return array; + } + + cJSON_Delete(array); + return NULL; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item->prev != NULL) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +} + +/* Replace array/object items with new ones. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; + + if (which < 0) + { + return; + } + + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + add_item_to_array(array, newitem); + return; + } + + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; + } + + if (replacement == item) + { + return true; + } + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (parent->child == item) + { + parent->child = replacement; + } + + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return; + } + + cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); +} + +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } + + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->type &= ~cJSON_StringIsConst; + + cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + if (object != NULL && newitem != NULL) { + replace_item_in_object(object, string, newitem, false); + } +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + if (object != NULL && newitem != NULL) { + replace_item_in_object(object, string, newitem, true); + } +} + +/* Create basic types: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_NULL; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_True; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = b ? cJSON_True : cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if (!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) + { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char*)cast_away_const(string); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if (!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Array; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; +} + +/* Create Arrays: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if (!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if (!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if (!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (strings == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if (!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +/* Duplication */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +{ + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; + + /* Bail on bad ptr */ + if (!item) + { + goto fail; + } + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; + } + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + + return newitem; + +fail: + if (newitem != NULL) + { + cJSON_Delete(newitem); + } + + return NULL; +} + +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + unsigned char *into = (unsigned char*)json; + + if (json == NULL) + { + return; + } + + while (*json) + { + if (*json == ' ') + { + json++; + } + else if (*json == '\t') + { + /* Whitespace characters. */ + json++; + } + else if (*json == '\r') + { + json++; + } + else if (*json == '\n') + { + json++; + } + else if ((*json == '/') && (json[1] == '/')) + { + /* double-slash comments, to end of line. */ + while (*json && (*json != '\n')) + { + json++; + } + } + else if ((*json == '/') && (json[1] == '*')) + { + /* multiline comments. */ + while (*json && !((*json == '*') && (json[1] == '/'))) + { + json++; + } + json += 2; + } + else if (*json == '\"') + { + /* string literals, which are \" sensitive. */ + *into++ = (unsigned char)*json++; + while (*json && (*json != '\"')) + { + if (*json == '\\') + { + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + else + { + /* All other characters. */ + *into++ = (unsigned char)*json++; + } + } + + /* and null-terminate. */ + *into = '\0'; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Invalid; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +{ + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) + { + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (a->valuedouble == b->valuedouble) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; + } +} + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/src/cJSON.h b/src/cJSON.h new file mode 100644 index 0000000..f09aaef --- /dev/null +++ b/src/cJSON.h @@ -0,0 +1,277 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +#pragma once +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 7 +#define CJSON_VERSION_PATCH 7 +#include "define_inc.h" +#include <stddef.h> + +/* cJSON Types: */ +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + +#define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 + +/* The cJSON structure: */ +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; + + /* The type of the item, as above. */ + int type; + + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; + + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; +} cJSON; + +typedef struct cJSON_Hooks +{ + void *(*malloc_fn)(size_t sz); + void (*free_fn)(void *ptr); +} cJSON_Hooks; + +typedef int cJSON_bool; + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif +#ifdef __WINDOWS__ + +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol + +For *nix builds that support visibility attribute, you can define similar behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + +*/ + +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_EXPORT_SYMBOLS +#endif + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type __stdcall +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type __stdcall +#elif defined(CJSON_IMPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllimport) type __stdcall +#endif +#else /* !WIN32 */ +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ +#ifndef CJSON_NESTING_LIMIT +#define CJSON_NESTING_LIMIT 1000 +#endif + +/* returns the version of cJSON as a string */ +CJSON_PUBLIC(const char*) cJSON_Version(void); + +/* Supply malloc, realloc and free functions to cJSON */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); + +/* Render a cJSON entity to text for transfer/storage. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. */ +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); +/* Delete a cJSON entity and all subentities. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); + +/* Returns the number of items in an array (or object). */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); +/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); +/* Get item "string" from object. Case insensitive. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + +/* Check if the item is a string and return its valuestring */ +CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); + +/* These functions check the type of an item */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + +/* These calls create a cJSON item of the appropriate type. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); +/* raw json */ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + +/* Create a string where valuestring references a string so + * it will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); +/* Create an object/arrray that only references it's elements so + * they will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); + +/* These utilities create an Array of count items. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); + +/* Append item to the specified array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + +/* Remove/Detatch items from Arrays/Objects. */ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); + +/* Update array items. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will +need to be released. With recurse!=0, it will duplicate any children connected to the item. +The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); + + +CJSON_PUBLIC(void) cJSON_Minify(char *json); + +/* Helper functions for creating and adding items to an object at the same time. + * They return the added item or NULL on failure. */ +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* helper for the cJSON_SetNumberValue macro */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) + +/* Macro for iterating over an array or object */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size); +CJSON_PUBLIC(void) cJSON_free(void *object); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/cavalry_gen.h b/src/cavalry_gen.h new file mode 100644 index 0000000..5c43722 --- /dev/null +++ b/src/cavalry_gen.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2018-2018 Ambarella, Inc. + * 2018/08/17 - [Monica Yang] created file + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign copyrights. + * This Software is also the confidential and proprietary information of + * Ambarella, Inc. and its licensors. You may not use, reproduce, disclose, + * distribute, modify, or otherwise prepare derivative works of this Software + * or any portion thereof except pursuant to a signed license agreement or + * nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and + * return this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; + * 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. + */ +#pragma once +#ifndef __CAVALRY_GEN_H__ +#define __CAVALRY_GEN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#define CAVALRY_GEN_VERSION (0x02010007) +#define CAVALRY_FILENAME_MAX (128) +#define CAVALRY_VAR_NAME_MAX (128) +#define CAVALRY_IO_NAME_MAX (512) +#define CAVALRY_IO_DEMNGL_NAME_MAX (512) +#define CAVALRY_IO_PARENT_NAME_MAX (64) +#define CAVALRY_VPROC_VAR_NAME_MAX (32) +#define CAVALRY_VPROC_SMB_NAME_MAX (16) +#define CAVALRY_PATH_MAX (2048) +#define CAVALRY_LINE_LEN_MAX (1024) + +/* cavalry_gen will set invalid value if not found data_format */ +typedef enum datasize_type_s { + DATASIZE_8_BITS = 0, + DATASIZE_16_BITS = 1, + DATASIZE_32_BITS = 2, + DATASIZE_64_BITS = 3, + DATASIZE_INVALID = 0xFF, +} datasize_type_t; + +/* header info */ +typedef struct cavalry_gen_header_s { + uint32_t version_info; + uint32_t version_hash; + uint32_t dvi_num; +} cavalry_gen_header_t; + +/*per dvi descriptor */ +typedef struct dvi_desc_s { + uint8_t dvi_id; + uint8_t vproc_id; + uint8_t dvi_ppv; + uint8_t reserve_dvi; + uint32_t dvi_img_vaddr; + uint32_t dvi_img_size; + uint32_t dvi_dag_vaddr; + uint32_t input_num; + uint32_t output_num; + uint32_t dvi_pkg_size; + char dag_name[CAVALRY_VAR_NAME_MAX]; +} dvi_desc_t; + +/*per port descriptor (HMB_input HMB_output) */ +typedef struct io_descriptor_s{ + uint32_t port_dim_p; + uint32_t port_dim_d; + uint32_t port_dim_h; + uint32_t port_dim_w; + uint32_t port_pitch; /* dpitch_num_bytes */ + uint32_t port_pitch_offset; + uint32_t port_pitch_bsize: 6; + uint32_t port_dram_format: 4; + uint32_t port_dim_bitvector: 1; + uint32_t port_drotate: 1; + uint32_t port_hflip: 1; + uint32_t port_vflip: 1; + uint32_t port_dflip: 1; + uint32_t port_pflip: 1; + uint32_t reserve_port: 7; + uint32_t port_slice_total_num : 4; + uint32_t port_slice_seq : 4; + uint32_t port_is_main_io: 1; + uint32_t port_slice_byte_offset; + char port_slice_parent_name[CAVALRY_IO_PARENT_NAME_MAX]; + + uint32_t port_drotate_bit_offset; + uint32_t port_hflip_bit_offset; + uint32_t port_vflip_bit_offset; + uint32_t port_dflip_bit_offset; + uint32_t port_pflip_bit_offset; + + uint8_t port_data_sign; /*data format: sign, datasize, expoffset, expbits*/ + uint8_t port_data_size; + int8_t port_data_expoffset; + uint8_t port_data_expbits; + + uint32_t port_size; + uint32_t port_byte_offset; /* dbase_byte_offset */ + char port_name[CAVALRY_IO_NAME_MAX]; + char port_demangled_name[CAVALRY_IO_DEMNGL_NAME_MAX]; +} io_descriptor_t; + +/* vproc descriptors */ +typedef struct vproc_desc_s { + uint32_t var_num; + uint32_t smb_num; + uint32_t vproc_pkg_size; +}vproc_desc_t; + +/* functional parameters */ +typedef struct func_variable_s{ + char var_name[CAVALRY_VPROC_VAR_NAME_MAX]; + uint32_t var_boffset; + uint32_t var_bsize; +} func_variable_t; + +/* SMB descriptor */ +typedef struct smb_descriptor_s{ + char smb_name[CAVALRY_VPROC_SMB_NAME_MAX]; + uint32_t vbase_byte_offset; +} smb_descriptor_t; + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/cavalry_ioctl.h b/src/cavalry_ioctl.h new file mode 100644 index 0000000..b4a181d --- /dev/null +++ b/src/cavalry_ioctl.h @@ -0,0 +1,467 @@ +/* + * Copyright (c) 2018-2018 Ambarella, Inc. + * 2018/06/01 - [Zhikan Yang] created file + * + * This file and its contents ("Software") are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign copyrights. + * This Software is also the confidential and proprietary information of + * Ambarella, Inc. and its licensors. You may not use, reproduce, disclose, + * distribute, modify, or otherwise prepare derivative works of this Software + * or any portion thereof except pursuant to a signed license agreement or + * nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and + * return this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; + * 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. + */ +#pragma once +#ifndef __CAVALRY_IOCTL_H__ +#define __CAVALRY_IOCTL_H__ +#include "define_inc.h" +#include <linux/ioctl.h> +#include <config.h> + +#if defined (BUILD_AMBARELLA_AMBACV_DRV) && defined (BUILD_AMBARELLA_CAVALRY_DRV) +#error "Can not enable ambacv and cavalry at the same time" +#elif defined (BUILD_AMBARELLA_AMBACV_DRV) +#define CAVALRY_DEV_NODE "/dev/ambacv" +#else +#define CAVALRY_DEV_NODE "/dev/cavalry" +#endif + +#define CAVALRY_MONITOR_ERR_PATH "/sys/devices/platform/sub_scheduler0/monitor/cavalry_err" +#define CAVALRY_MONITOR_INFO_PATH "/sys/devices/platform/sub_scheduler0/monitor/cavalry_info" + +#define MAX_PORT_CNT (128) +#define MAX_POKE_CNT (64) +#define MAX_DAG_CNT (256) + +#define VERSION_INFO_OFFSET (0x40) + +#define CAVALRY_SLOT_ID_OFFSET (0x04) + +#define CAVALRY_HARRIS_H_BLOCKS (8) +#define CAVALRY_HARRIS_V_BLOCKS (8) +#define CAVALRY_HARRIS_MAX_POINTS_PER_BLOCK (32) + +#define FEX_MIN_NMS_WINDOW (1) +#define FEX_MAX_NMS_WINDOW (8) + +#define DEFAULT_AUDIO_CLK_HZ (12288000) + +#define CAVALRY_MONITOR_MSG_SIZE (128) + +typedef enum { + CHIP_TYPE_CV22 = 0, + CHIP_TYPE_CV2 = 1, + CHIP_TYPE_CV25 = 2, +} chip_type_t; + +typedef enum { + CAVALRY_LOG_LEVEL_SILENT = 0, + CAVALRY_LOG_LEVEL_MINIMAL, + CAVALRY_LOG_LEVEL_NORMAL, + CAVALRY_LOG_LEVEL_VERBOSE, + CAVALRY_LOG_LEVEL_DEBUG, + CAVALRY_LOG_LEVEL_NUM, + CAVALRY_LOG_LEVEL_FIRST = CAVALRY_LOG_LEVEL_SILENT, + CAVALRY_LOG_LEVEL_LAST = CAVALRY_LOG_LEVEL_DEBUG, +} cavalry_log_level_t; + +struct cavalry_set_log_level { + cavalry_log_level_t log_level; + uint32_t rval; +}; + +struct version_info_s { + uint32_t chip; + uint32_t ucode_version; + uint32_t build_date; + uint32_t git_hash; + uint32_t hotlink_fw_version; +}; + +typedef enum { + CAVALRY_MEM_ALL = 0x00, + CAVALRY_MEM_CMD = 0x01, + CAVALRY_MEM_MSG = 0x02, + CAVALRY_MEM_LOG = 0x03, + CAVALRY_MEM_CMD_FEX = 0x04, + CAVALRY_MEM_MSG_FEX = 0x05, + CAVALRY_MEM_CMD_FMA = 0x06, + CAVALRY_MEM_MSG_FMA = 0x07, + CAVALRY_MEM_UCODE = 0x08, + CAVALRY_MEM_HOTLINK_SLOT0 = 0x09, + CAVALRY_MEM_HOTLINK_SLOT1 = 0x0A, + CAVALRY_MEM_HOTLINK_SLOT2 = 0x0B, + CAVALRY_MEM_HOTLINK_SLOT3 = 0x0C, + CAVALRY_MEM_USER = 0x0D, + CAVALRY_MEM_NUM = 0x0E, + CAVALRY_MEM_FIRST = CAVALRY_MEM_ALL, + CAVALRY_MEM_LAST = CAVALRY_MEM_USER, +} CAVALRY_MEM; + +struct cavalry_log_entry { + uint32_t seq_num; + uint8_t thread_id; + uint8_t slot_id; + uint8_t reserved[2]; + uint32_t format_offset; + uint32_t arg1; + uint32_t arg2; + uint32_t arg3; + uint32_t arg4; + uint32_t arg5; +}; + +struct cavalry_querybuf { + CAVALRY_MEM buf; + unsigned long length; + unsigned long offset; +}; + +struct cavalry_port_desc { + uint32_t port_dram_addr; + uint32_t port_boffset_in_dag; + uint32_t port_dram_size; + uint32_t port_daddr_increment; +}; + +struct cavalry_poke_desc { + uint32_t poke_val; + uint32_t poke_vaddr; + uint32_t poke_bsize; +}; + +struct cavalry_dag_desc { + uint32_t dvi_mode : 1; + uint32_t use_ping_pong_vmem : 1; + uint32_t reserved : 14; + uint32_t dag_loop_cnt : 16; + uint32_t dvi_dram_addr; + uint32_t dvi_img_vaddr; + uint32_t dvi_img_size; + uint32_t dvi_dag_vaddr; + + uint32_t reserved1[4]; + + uint32_t port_cnt; + uint32_t poke_cnt; + struct cavalry_port_desc port_desc[MAX_PORT_CNT]; + struct cavalry_poke_desc poke_desc[MAX_POKE_CNT]; +}; + +typedef enum { + MSG_RVAL_NONE, + MSG_RVAL_INVALID_CMD, + MSG_RVAL_INVALID_DAGCNT, + MSG_RVAL_INVALID_DAGDESC, + MSG_RVAL_INVALID_SLOT_ID, + MSG_RVAL_FEX_INSUFFICIENT_DRAM, + MSG_RVAL_FMA_INSUFFICIENT_DRAM, + MSG_RVAL_VP_RESERVED_VMEM_TRASHED, +} cavalry_msg_rval_t; + +typedef enum { + HOTLINK_SLOT_0 = 0, + HOTLINK_SLOT_1 = 1, + HOTLINK_SLOT_2 = 2, + HOTLINK_SLOT_3 = 3, + HOTLINK_SLOT_NUM = 4, + HOTLINK_SLOT_FIRST = HOTLINK_SLOT_0, + HOTLINK_SLOT_LAST = HOTLINK_SLOT_3, + HOTLINK_SLOT_CAVALRY_FRAMEWORK = 0xFF, +} hotlink_slot_t; + +typedef enum { + CAVALRY_FMA_MODE_TEMPORAL = 0, + CAVALRY_FMA_MODE_STEREO, + CAVALRY_FMA_MODE_NUM, + CAVALRY_FMA_MODE_FIRST = CAVALRY_FMA_MODE_TEMPORAL, + CAVALRY_FMA_MODE_LAST = CAVALRY_FMA_MODE_STEREO, +} cavalry_fma_mode_t; + +struct cavalry_run_dags { + uint32_t rval; + uint32_t start_tick; + uint32_t end_tick; + uint32_t finish_dags; + uint32_t dag_cnt; + struct cavalry_dag_desc dag_desc[MAX_DAG_CNT]; +}; + +struct cavalry_early_quit { + uint32_t early_quit_all : 1; + uint32_t reserved : 31; +}; + +struct cavalry_mem { + uint32_t cache_en : 1; /* 0: nocached; 1: cached */ + uint32_t reserved : 31; + + unsigned long length; /* as input: the mem part size to be allocated + as return: the real size of the allocated mem part */ + unsigned long offset; /* the physical address of the allocated mem part */ +}; + +struct cavalry_cache_mem { + uint32_t clean : 1; /* do after arm write: cache -> dram */ + uint32_t invalid : 1; /* do before arm read: dram -> cache */ + uint32_t reserved : 30; + + unsigned long length; + + unsigned long offset; /* the physical address of the allocated mem part */ +}; + +struct cavalry_usage_mem { + unsigned long used_length; + unsigned long free_length; +}; + +struct cavalry_run_hotlink_slot { + uint8_t slot_id; + uint8_t reserved0[3]; + uint32_t arg_daddr; + uint32_t slot_rval; + uint32_t start_tick; + uint32_t end_tick; +}; + +struct cavalry_fex_query { + /* Input */ + uint16_t img_width; + uint16_t img_height; + uint16_t img_pitch; + uint16_t harris_en : 2; + uint16_t stereo_en : 1; + uint16_t dump_harris_score : 1; + uint16_t reserved1 : 12; + /* Output */ + uint32_t dram_required; +}; + +typedef enum { + FEX_CFG_MASK_NMS_THRESHOLD = (1 << 0), + FEX_CFG_MASK_NMS_WINDOW_FOR_HARRIS = (1 << 1), + FEX_CFG_MASK_ALL = FEX_CFG_MASK_NMS_THRESHOLD | FEX_CFG_MASK_NMS_WINDOW_FOR_HARRIS, +} fex_cfg_mask_t; + +struct fex_user_cfg { + uint32_t cfg_mask; + uint16_t nms_threshold; + uint16_t nms_window_for_harris : 4; + uint16_t reserved2 : 12; +}; + +typedef enum { + STEREO_PROFILE_DEFAULT = 0, + STEREO_PROFILE_1, + STEREO_PROFILE_NUM, +} stereo_profile_t; + +struct cavalry_fex_run { + /* Input */ + uint16_t img_width; + uint16_t img_height; + uint16_t img_pitch; + uint16_t harris_en : 2; + uint16_t stereo_en : 1; + uint16_t stereo_profile : 5; + uint16_t dump_harris_score : 1; + uint16_t reserved1 : 7; + struct fex_user_cfg fex_cfg; + uint32_t output_daddr; + uint32_t output_size; + uint32_t luma_daddr[2]; + + /* Output */ + uint32_t rval; + uint32_t disparity_daddr; + uint32_t disparity_size; + uint32_t invalid_disparities; + uint16_t disparity_width; + uint16_t disparity_height; + uint16_t disparity_pitch; + uint16_t reserved2; + uint32_t harris_count_daddr[2]; + uint32_t harris_count_size[2]; + uint32_t harris_point_daddr[2]; + uint32_t harris_point_size[2]; + uint32_t brief_descriptor_daddr[2]; + uint32_t brief_descriptor_size[2]; + uint32_t start_tick; + uint32_t end_tick; +}; + +struct cavalry_fma_query { + /* Output */ + uint32_t dram_required; +}; + +typedef enum { + FMA_CFG_MASK_MIN_THRESHOLD = (1 << 0), + FMA_CFG_MASK_RATIO_THRESHOLD = (1 << 1), + FMA_CFG_MASK_WIN_WIDTH = (1 << 2), + FMA_CFG_MASK_WIN_HEIGHT = (1 << 3), + FMA_CFG_MASK_X_THRESHOLD_R = (1 << 4), + FMA_CFG_MASK_X_THRESHOLD_L = (1 << 5), + FMA_CFG_MASK_Y_THRESHOLD_U = (1 << 6), + FMA_CFG_MASK_Y_THRESHOLD_D = (1 << 7), + FMA_CFG_MASK_ALL = FMA_CFG_MASK_MIN_THRESHOLD | FMA_CFG_MASK_RATIO_THRESHOLD | + FMA_CFG_MASK_WIN_WIDTH | FMA_CFG_MASK_WIN_HEIGHT | + FMA_CFG_MASK_X_THRESHOLD_R | FMA_CFG_MASK_X_THRESHOLD_L | + FMA_CFG_MASK_Y_THRESHOLD_U | FMA_CFG_MASK_Y_THRESHOLD_D, +} fma_cfg_mask_t; + +struct fma_user_cfg { + uint32_t cfg_mask; + uint32_t min_threshold; + + uint16_t ratio_threshold; + uint16_t reserved; + + uint16_t win_width; + uint16_t win_height; + + uint16_t x_threshold_r; + uint16_t x_threshold_l; + uint16_t y_threshold_u; + uint16_t y_threshold_d; +}; + +struct cavalry_fma_run { + /* Input */ + uint32_t output_daddr; + uint32_t output_size; + uint32_t target_coord_daddr; + uint32_t target_descriptor_daddr; + uint32_t reference_coord_daddr; + uint32_t reference_descriptor_daddr; + uint32_t mode : 1; // 0 for temporal, 1 for stereo + uint32_t reserved1 : 31; + struct fma_user_cfg stereo_cfg; + struct fma_user_cfg temporal_cfg; + + /* Output */ + uint32_t rval; + uint32_t result_score_daddr; + uint32_t result_score_size; + uint32_t result_index_daddr; + uint32_t result_index_size; + uint32_t temporal_coord_daddr; + uint32_t temporal_coord_size; + uint32_t start_tick; + uint32_t end_tick; +}; + +struct cavalry_stats_get { + uint32_t is_vp_idle : 1; + uint32_t reserved : 31; + int vp_current_pid; +}; + +struct cavalry_vp_core_dump { + uint32_t is_vp_hang : 1; + uint32_t reserved0 : 31; + uint32_t core_dump_daddr; + uint32_t core_dump_size; +}; + +typedef enum { + MONITOR_ERR_VP_HANG = 0, + MONITOR_ERR_FEX_HANG = 1, + MONITOR_ERR_FMA_HANG = 2, + MONITOR_ERR_NUM, + MONITOR_ERR_FIRST = MONITOR_ERR_VP_HANG, + MONITOR_ERR_LAST = MONITOR_ERR_FMA_HANG, +} cavalry_monitor_err_t; + +typedef enum { + MONITOR_INFO_VP_TIMEOUT = 0, + MONITOR_INFO_FEX_TIMEOUT = 1, + MONITOR_INFO_FMA_TIMEOUT = 2, + MONITOR_INFO_NUM, + MONITOR_INFO_FIRST = MONITOR_INFO_VP_TIMEOUT, + MONITOR_INFO_LAST = MONITOR_INFO_FMA_TIMEOUT, +} cavalry_monitor_info_t; + +struct cavalry_monitor_msg_err { + uint64_t tv_sec; + uint64_t tv_usec; + cavalry_monitor_err_t err_code; + uint32_t line_num; + char func_name[CAVALRY_MONITOR_MSG_SIZE]; + char msg_string[CAVALRY_MONITOR_MSG_SIZE]; + uint32_t extra_size; + char extra_data[0]; +}; + +struct cavalry_monitor_msg_info { + uint64_t tv_sec; + uint64_t tv_usec; + cavalry_monitor_info_t info_code; + uint32_t line_num; + char func_name[CAVALRY_MONITOR_MSG_SIZE]; + char msg_string[CAVALRY_MONITOR_MSG_SIZE]; + uint32_t extra_size; + char extra_data[0]; +}; + +struct cavalry_clock_cfg { + uint32_t vp_clk_flag : 1; /* set it when want configure vp clock */ + uint32_t reserved_1 : 31; + + uint32_t vp_clk_numerator; + uint32_t vp_clk_denominator; + + uint32_t reserved_2[4]; +}; + +#define CAVALRY_QUERY_BUF _IOWR ('C', 0x0, struct cavalry_querybuf *) +#define CAVALRY_START_VP _IOWR ('C', 0x1, void *) +#define CAVALRY_STOP_VP _IOWR ('C', 0x2, void *) +#define CAVALRY_RUN_DAGS _IOWR ('C', 0x3, struct cavalry_run_dags *) +#define CAVALRY_START_LOG _IOWR ('C', 0x4, void *) +#define CAVALRY_STOP_LOG _IOWR ('C', 0x5, void *) +#define CAVALRY_EARLY_QUIT _IOWR ('C', 0x6, struct cavalry_early_quit *) + +/* cv user memory ioctl */ +#define CAVALRY_ALLOC_MEM _IOWR ('C', 0x7, struct cavalry_mem *) +#define CAVALRY_FREE_MEM _IOWR ('C', 0x8, struct cavalry_mem *) +#define CAVALRY_SYNC_CACHE_MEM _IOWR ('C', 0x9, struct cavalry_cache_mem *) +#define CAVALRY_GET_USAGE_MEM _IOWR ('C', 0xA, struct cavalry_usage_mem *) + +#define CAVALRY_RUN_HOTLINK_SLOT _IOWR ('C', 0xB, struct cavalry_run_hotlink_slot *) +#define CAVALRY_SET_HOTLINK_SLOT_CFG _IOWR ('C', 0xC, uint32_t *) +#define CAVALRY_GET_HOTLINK_SLOT_CFG _IOWR ('C', 0xD, uint32_t *) + +#define CAVALRY_FEX_QUERY _IOWR ('C', 0xE, struct cavalry_fex_query *) +#define CAVALRY_FEX_RUN _IOWR ('C', 0xF, struct cavalry_fex_run *) + +#define CAVALRY_FMA_QUERY _IOWR ('C', 0x10, struct cavalry_fma_query *) +#define CAVALRY_FMA_RUN _IOWR ('C', 0x11, struct cavalry_fma_run *) + +#define CAVALRY_SET_LOG_LEVEL _IOWR ('C', 0x12, struct cavalry_set_log_level *) + +#define CAVALRY_GET_STATS _IOWR ('C', 0x13, struct cavalry_stats_get *) + +#define CAVALRY_QUERY_VP_CORE_DUMP _IOWR ('C', 0x14, struct cavalry_vp_core_dump *) + +/* misc ioctl */ +#define CAVALRY_GET_AUDIO_CLK _IOR ('C', 0x80, uint64_t *) + +#define CAVALRY_SET_CAVALRY_CLK _IOW ('C', 0x81, struct cavalry_clock_cfg *) +#define CAVALRY_GET_CAVALRY_CLK _IOWR ('C', 0x82, struct cavalry_clock_cfg *) + +#endif //__CAVALRY_IOCTL_H__ diff --git a/src/cgicmd.cpp b/src/cgicmd.cpp new file mode 100644 index 0000000..bbd12ec --- /dev/null +++ b/src/cgicmd.cpp @@ -0,0 +1,3464 @@ +#if 1 +#include "cgicmd.h" +#include <stdio.h> +#include <stdlib.h> +#include <vector> +#include <utility> +#include <string> + +#include "cJSON.h" +#include "utility.h" + +using namespace std; + +char aida_port_for_cgicmd[512] = { 0 }; +char aida_username_for_cgicmd[512] = { 0 }; +char aida_device_name_for_cgicmd[512] = { 0 }; + +static unsigned char char_to_hex(unsigned char x) +{ + return (unsigned char)(x > 9 ? x + 55 : x + 48); +} + +static int is_alpha_number_char(unsigned char c) +{ + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) + return 1; + return 0; +} + +static int normal_char(unsigned char c) +{ + if (c == '~' || + c == '`' || + c == '!' || + c == '$' || + //c == '%' || + c == '^' || + c == '&' || + c == '*' || + c == '(' || + c == ')' || + c == '-' || + c == '_' || + c == '+' || + c == '=' || + c == '[' || + c == ']' || + c == '{' || + c == '}' || + c == '|' || + c == '\\' || + c == ';' || + c == '"' || + c == '\'' || + c == '<' || + c == '>' || + c == ',' || + c == '.') { + return 1; + } + return 0; +} + +//urlsX{ +void urlencode(unsigned char * src, int src_len, unsigned char * dest, int dest_len) +{ + unsigned char ch; + int len = 0; + + while (len < (dest_len - 4) && *src) + { + ch = (unsigned char)*src; + + /* + if (*src == ' ') + { + *dest++ = '+'; + }*/ + if (is_alpha_number_char(ch) || normal_char(ch)) + { + *dest++ = *src; + } + else + { + *dest++ = '%'; + *dest++ = char_to_hex((unsigned char)(ch >> 4)); + *dest++ = char_to_hex((unsigned char)(ch % 16)); + } + ++src; + ++len; + } + *dest = 0; + return; +} + +//urlsX{ +unsigned char* urldecode(unsigned char* encd, unsigned char* decd) +{ + char *cd = (char*)encd; + char p[2]; + size_t j = 0; + + for (size_t i = 0; i < strlen(cd); i++) + { + //memset(p, '/0', 2); + memset(p, 0, 2); + if (cd[i] != '%') + { + decd[j++] = cd[i]; + continue; + } + + p[0] = cd[++i]; + p[1] = cd[++i]; + + p[0] = p[0] - 48 - ((p[0] >= 'A') ? 7 : 0) - ((p[0] >= 'a') ? 32 : 0); + p[1] = p[1] - 48 - ((p[1] >= 'A') ? 7 : 0) - ((p[1] >= 'a') ? 32 : 0); + decd[j++] = (unsigned char)(p[0] * 16 + p[1]); + + } + decd[j] = 0; + + return decd; +} + +bool is_number(const std::string& s) +{ + std::string::const_iterator it = s.begin(); + while (it != s.end() && std::isdigit(*it)) ++it; + return !s.empty() && it == s.end(); +} + +CgiCmdRtnCode cgicmd_process(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize) +{ + CgiCmdRtnCode rtn_val = _CGICMD_FAIL; + + std::vector<std::pair<std::string, std::string> > CmdVec; + //printf("\n[cgicmd_process] 1\n"); + { + int len, nel; + char *q, *name, *value; + + /* Parse into individual assignments */ + //printf("\n[cgicmd_process] 2\n"); + q = Cmd; + + len = strlen(Cmd); + nel = 1; + while (strsep(&q, "&")) + nel++; + //printf("\n[cgicmd_process] 3\n"); + //printf("CGI[nel string] : %d\n", nel); + + for (q = Cmd; q < (Cmd + len);) { + value = name = q; + + /* Skip to next assignment */ + //printf("CGI[string] : %s\n", q); + //printf("CGI[string len] : %d\n", strlen(q)); + //printf("CGI[address] : %x\n", q); + for (q += strlen(q); q < (Cmd + len) && !*q; q++); + /* Assign variable */ + name = strsep(&value, "="); + //printf("CGI[name ] : %s\n", name); + //printf("CGI[value] : %s\n", value); + + //CmdVec.push_back(std::make_pair(name, value)); + + unsigned char DecodeCmdName[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeName = DecodeCmdName; + urldecode((unsigned char *)name, (unsigned char *)DecodeName); + //printf("CGI[DecodeName] : %s\n", DecodeName); + + unsigned char DecodeCmdValue[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeValue = DecodeCmdValue; + urldecode((unsigned char *)value, (unsigned char *)DecodeValue); + //printf("CGI[Decodevalue] : %s\n", DecodeValue); + + CmdVec.push_back(std::make_pair((char*)DecodeName, (char *)DecodeValue)); + } + /* + for (size_t i = 0; i < CmdVec.size(); i++) + { + printf("CGI[name %d] : %s\n", i,CmdVec[i].first.c_str()); + printf("CGI[value %d] : %s\n", i,CmdVec[i].second.c_str()); + }*/ + //printf("\n[cgicmd_process] 4\n"); + } + + //check cmd size & content not empty + { + //check cmd size + if (CmdVec.size() == 0) + { + printf("CmdVec.size == 0\n"); + return rtn_val; + } + //check cmd content is not empty + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (CmdVec[i].first.empty()) + { + printf("[ERROR] CmdVec[%ld].first.empty()\n", (long int)i); + return rtn_val; + } + if (CmdVec[i].second.empty()) + { + printf("[ERROR] CmdVec[%ld].second.empty()\n", (long int)i); + return rtn_val; + } + } + } + //printf("\n[cgicmd_process] 5\n"); + if (type == _CGICMD_GET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = configPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd_process] 6\n"); + + int check_if_ch_all = 0; + + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("2CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("2CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + //getconfig?reload=1 + if ((CmdVec[i].first.compare("reload") == 0) && (CmdVec[i].second.compare("1") == 0)) + { + return _CGICMD_RELOAD; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("3") == 0)) + { + return _CGICMD_DEFAULT_3; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("all") == 0)) + { + return _CGICMD_DEFAULT_ALL; + } + else if ((CmdVec[i].first.compare("default") == 0)) + { + return _CGICMD_DEFAULT_NUMBER; + } + else + { + string str_search; + + //chh + //ch=<ch_id> + //ch=all + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + cj_parent = cj_root; + + //ch=<ch_id> //ch=all + if ((is_number(CmdVec[i].second)) || (CmdVec[i].second.compare("all") == 0)) + { + if (CmdVec[i].second.compare("all") == 0) + check_if_ch_all = 1; + str_search.clear(); + str_search.assign("view_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //MŷjMr + str_search.clear(); + + if (is_number(CmdVec[i].second)) + { + //printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + + //ch=<ch_id> + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 1]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 2]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else if (CmdVec[i].second.compare("all") == 0) //<ch> = all or <tag> = all + { + //printf("CGI[value %d] : %s all\n", i, CmdVec[i].second.c_str()); + break; //~򰵡A^G + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 3]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + printf("[ERROR 4]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + cj_parent = cj_current; + } + //printf("\n[cgicmd_process] 7\n"); + if (cj_current != NULL) + { + char* JsonString = NULL; + JsonString = cJSON_PrintUnformatted(cj_current); + + + if (check_if_ch_all == 1) { + { + char *loc = strstr(JsonString, ",\"username\":\"guest\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString, ",\"username\":\"guest\",", temp); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString, ",\"password\":\"GP12345\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString, ",\"password\":\"GP12345\",", temp); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString, "\"channel_id\":\"\""); + if (loc != NULL) { + char temp[256] = "\"channel_id\":\"0\""; + char *temp2 = StrReplace(JsonString, "\"channel_id\":\"\"", temp); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString, "\"camera_name\":\"\""); + if (loc != NULL) { + char temp[1024] = { 0 }; + sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); + char *temp2 = StrReplace(JsonString, "\"camera_name\":\"\"", temp); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString, "ip\":\"47.176.29.11"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString, "ip\":\"47.176.29.11", "ip\":\"localhost"); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString, "http_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString, "http_port\":\"80", temp); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + + } + } + + { + char *loc = strstr(JsonString, "video_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString, "video_port\":\"80", temp); + strcpy(JsonString, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + } + + //printf("\nJsonString:%s\n", JsonString); + //printf("\nstrlen(JsonString):%d\n", strlen(JsonString)); + //printf("\nnPassInSize:%d\n", nPassInSize); + + if ((size_t)nPassInSize > strlen(JsonString)) + { + strcpy(szPassIn, JsonString); + rtn_val = _CGICMD_SUCCESS; + //printf("\nhello1\n"); + } + else + { + printf("[ERROR 5]\n"); + rtn_val = _CGICMD_FAIL_INSUFFICIENT_BUFFER; + //printf("\nhello2\n"); + } + + //printf("\nhello3:JsonString_size:%d\n",strlen(JsonString)); + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + //printf("\nhello4:JsonString_size:%d\n", strlen(JsonString)); + //printf("\nhello4\n"); + } + + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + //printf("\nhello5\n"); + //printf("\n[cgicmd_process] 8\n"); + } + else if (type == _CGICMD_SET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + + #if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + #endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = configPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + if (g_config_root == NULL) { + char *fileBuf = ReadAllBytes(filename); + if(fileBuf == NULL) + return rtn_val; + g_config_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + } + cj_root = g_config_root; + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + string str_search; + + //chh + //ch=<ch_id> + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + //̫@h//uch@hALk]wA^~ + if ((i + 1) == CmdVec.size()) + { + printf("[ERROR 6]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else + { + cj_parent = cj_root; + + //ch=<ch_id> + if (is_number(CmdVec[i].second)) + { + str_search.clear(); + str_search.assign("view_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //̫@hA + if ((i + 1) == CmdVec.size()) + { + /*//uch@hALk]wA^~ + if (CmdVec[i].first.compare("ch") == 0) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else*/ + { + /*//cj_current is array + if (cJSON_IsArray(cj_current)) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + //cj_current is string + else*/ + if (cJSON_IsString(cj_current)) + { + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateString(CmdVec[i].second.c_str())); + } + //cj_current is number + else if (cJSON_IsNumber(cj_current)) + { + if (is_number(CmdVec[i].second)) + { + int num = atoi(CmdVec[i].second.c_str()); + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateNumber(num)); + } + else + { + printf("[ERROR 7]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + else + { + printf("[ERROR 8]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + } + else + { + //MŷjMr + str_search.clear(); + + if (is_number(CmdVec[i].second)) + { + //printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 9]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 10]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 11]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + } + else + { + printf("[ERROR 12]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + + cj_parent = cj_current; + } + + //update config.json +#if 1 + if (cj_current != NULL) + { + rtn_val = _CGICMD_SUCCESS; + } +#endif + } + + return rtn_val; +} + +CgiCmdRtnCode cgicmd_process_events(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize) +{ + CgiCmdRtnCode rtn_val = _CGICMD_FAIL; + //printf("\n[cgicmd process events] 1\n"); + std::vector<std::pair<std::string, std::string> > CmdVec; + + { + int len, nel; + char *q, *name, *value; + + /* Parse into individual assignments */ + //printf("\n[cgicmd process events] 2\n"); + q = Cmd; + + len = strlen(Cmd); + nel = 1; + while (strsep(&q, "&")) { + nel++; + } + //printf("CGI[nel string] : %d\n", nel); + //printf("\n[cgicmd_process_events] 3\n"); + + int enter_post_url = 0; + for (q = Cmd; q < (Cmd + len);) { + value = name = q; + + /* Skip to next assignment */ + //printf("CGI[string] : %s\n", q); + //printf("CGI[string len] : %d\n", strlen(q)); + //printf("CGI[address] : %x\n", q); + for (q += strlen(q); q < (Cmd + len) && !*q; q++); + /* Assign variable */ + name = strsep(&value, "="); + + //printf("CGI[name ] : %s\n", name); + //printf("CGI[value] : %s\n", value); + + //CmdVec.push_back(std::make_pair(name, value)); + + unsigned char DecodeCmdName[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeName = DecodeCmdName; + urldecode((unsigned char *)name, (unsigned char *)DecodeName); + //printf("CGI[DecodeName] : %s\n", DecodeName); + + unsigned char DecodeCmdValue[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeValue = DecodeCmdValue; + urldecode((unsigned char *)value, (unsigned char *)DecodeValue); + + + if (strcmp((char*)DecodeName, "post_url") == 0 || enter_post_url == 1) { + char temp_buf[MAX_CMD_SIZE] = { 0 }; + int m = 0; + + for (int k = 0; k < (int)strlen((char*)DecodeValue); k++) { + if ((char)DecodeValue[k] == ' ') { + temp_buf[m] = '_'; + m++; + } + else { + temp_buf[m] = (char)DecodeValue[k]; + m++; + } + } + temp_buf[m] = '\0'; + + CmdVec.push_back(std::make_pair((char*)DecodeName, temp_buf)); + enter_post_url = 1; + } + else { + CmdVec.push_back(std::make_pair((char*)DecodeName, (char *)DecodeValue)); + } + + //printf("CGI[Decodevalue] : %s\n", DecodeValue); + + + } + //printf("\n[cgicmd process events] 4\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + + if (strcmp(CmdVec[i].first.c_str(), "post_url") == 0) { + if (i < CmdVec.size() - 1) { + for (size_t j = i + 1; j < CmdVec.size(); j++) { + CmdVec[i].second.append("&"); + CmdVec[i].second.append(CmdVec[j].first.c_str()); + CmdVec[i].second.append("="); + CmdVec[i].second.append(CmdVec[j].second.c_str()); + } + } + } + + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + } + //printf("\n[cgicmd process events] 5\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + + if (strcmp(CmdVec[i].first.c_str(), "post_url") == 0) { + if (i < CmdVec.size() - 1) { + for (size_t j = i + 1; j < CmdVec.size();) { + CmdVec.pop_back(); + } + } + } + } + + } + //printf("\n[cgicmd process events] 6\n"); + //check cmd size & content not empty + { + //check cmd size + if (CmdVec.size() == 0) + { + printf("CmdVec.size == 0\n"); + return rtn_val; + } + //check cmd content is not empty + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (CmdVec[i].first.empty()) + { + printf("[ERROR] CmdVec[%ld].first.empty()\n", (long int)i); + return rtn_val; + } + if (CmdVec[i].second.empty()) + { + printf("[ERROR] CmdVec[%ld].second.empty()\n", (long int)i); + return rtn_val; + } + } + } + + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (strcmp(CmdVec[i].first.c_str(), "post_password") == 0) { + if (strcmp(CmdVec[i].second.c_str(), ";") == 0) { + CmdVec[i].second.clear(); + } + } + } + + + //printf("\n[cgicmd process events] 7\n"); + if (type == _CGICMD_GET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = eventsPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + //printf("\n[cgicmd process events] 8\n"); + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd process events] 9\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + //getconfig?reload=1 + if ((CmdVec[i].first.compare("reload") == 0) && (CmdVec[i].second.compare("1") == 0)) + { + return _CGICMD_RELOAD; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("3") == 0)) + { + return _CGICMD_DEFAULT_3; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("all") == 0)) + { + return _CGICMD_DEFAULT_ALL; + } + else if ((CmdVec[i].first.compare("default") == 0)) + { + return _CGICMD_DEFAULT_NUMBER; + } + else + { + string str_search; + + //chh + //ch=<ch_id> + //ch=all + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + cj_parent = cj_root; + + //ch=<ch_id> //ch=all + if ((is_number(CmdVec[i].second)) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("notification"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //MŷjMr + str_search.clear(); + /* + if (is_number(CmdVec[i].second)) + { + printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + + //ch=<ch_id> + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 1]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 2]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + }*/ + if (CmdVec[i].second.compare("all") == 0) //<ch> = all or <tag> = all + { + //printf("CGI[value %d] : %s all\n", i, CmdVec[i].second.c_str()); + break; //~򰵡A^G + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 3]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + printf("[ERROR 4]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + cj_parent = cj_current; + } + //printf("\n[cgicmd process events] 10\n"); + if (cj_current != NULL) + { + char* JsonString = NULL; + + JsonString = cJSON_PrintUnformatted(cj_current); + //printf("\nJsonString:%s\n", JsonString); + //printf("\nstrlen(JsonString):%d\n", strlen(JsonString)); + //printf("\nnPassInSize:%d\n", nPassInSize); + + /* + { + char *loc = strstr(JsonString, "password\":\""); + char *loc_last = NULL; + for (int i = 0; i < 8; i++) + { + if (loc != NULL) { + //printf("%s",loc); + loc_last = strstr(loc + 11, "\""); + + } + else + break; + if (loc_last != NULL) { + //printf("%s",loc_last); + + int index_start = (int)(loc - JsonString) + 11; + int index_end = (int)(loc_last - JsonString); + for (int i = index_start; i < index_end; i++) + JsonString[i] = '*'; + //printf("\nloc:%lu\n", loc - JsonString); + + loc = strstr(loc_last, "password\":\""); + } + else + break; + } + }*/ + + if ((size_t)nPassInSize > strlen(JsonString)) + { + strcpy(szPassIn, JsonString); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("[ERROR 5]\n"); + rtn_val = _CGICMD_FAIL_INSUFFICIENT_BUFFER; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + //printf("\n[cgicmd process events] 11\n"); + } + else if (type == _CGICMD_SET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = eventsPATH; + //printf("\n[cgicmd process events] 12\n"); + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + //printf("\n[cgicmd process events] 13\n"); + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd process events] 14\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + string str_search; + + //chh + //ch=<ch_id> + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + //̫@h//uch@hALk]wA^~ + if ((i + 1) == CmdVec.size()) + { + printf("[ERROR 6]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else + { + cj_parent = cj_root; + + //ch=<ch_id> + if (is_number(CmdVec[i].second) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("notification"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //̫@hA + if ((i + 1) == CmdVec.size()) + { + /*//uch@hALk]wA^~ + if (CmdVec[i].first.compare("ch") == 0) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else*/ + { + /*//cj_current is array + if (cJSON_IsArray(cj_current)) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + //cj_current is string + else*/ + if (cJSON_IsString(cj_current)) + { + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateString(CmdVec[i].second.c_str())); + } + //cj_current is number + else if (cJSON_IsNumber(cj_current)) + { + if (is_number(CmdVec[i].second)) + { + int num = atoi(CmdVec[i].second.c_str()); + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateNumber(num)); + } + else + { + printf("[ERROR 7]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + else + { + printf("[ERROR 8]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + } + else + { + //MŷjMr + str_search.clear(); + + if (is_number(CmdVec[i].second)) + { + //printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + /* + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else*/ + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 9]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 10]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 11]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + } + else + { + printf("[ERROR 12]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + + cj_parent = cj_current; + } + //printf("\n[cgicmd process events] 15\n"); + //update config.json + if (cj_current != NULL) + { + char* JsonString = cJSON_Print(cj_root); + + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("Fail to open Config.json \n"); + rtn_val = _CGICMD_FAIL_SET; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + //printf("\n[cgicmd process events] 16\n"); + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + } + + return rtn_val; +} + +CgiCmdRtnCode cgicmd_process_event_counters(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize) +{ + CgiCmdRtnCode rtn_val = _CGICMD_FAIL; + //printf("\n[cgicmd process event counters] 1\n"); + std::vector<std::pair<std::string, std::string> > CmdVec; + + { + int len, nel; + char *q, *name, *value; + + /* Parse into individual assignments */ + //printf("\n[cgicmd process event counters] 2\n"); + q = Cmd; + + len = strlen(Cmd); + nel = 1; + while (strsep(&q, "&")) { + nel++; + } + //printf("CGI[nel string] : %d\n", nel); + //printf("\n[cgicmd process event counters] 3\n"); + for (q = Cmd; q < (Cmd + len);) { + value = name = q; + + /* Skip to next assignment */ + //printf("CGI[string] : %s\n", q); + //printf("CGI[string len] : %d\n", strlen(q)); + //printf("CGI[address] : %x\n", q); + for (q += strlen(q); q < (Cmd + len) && !*q; q++); + /* Assign variable */ + name = strsep(&value, "="); + + //printf("CGI[name ] : %s\n", name); + //printf("CGI[value] : %s\n", value); + + //CmdVec.push_back(std::make_pair(name, value)); + + unsigned char DecodeCmdName[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeName = DecodeCmdName; + urldecode((unsigned char *)name, (unsigned char *)DecodeName); + //printf("CGI[DecodeName] : %s\n", DecodeName); + + unsigned char DecodeCmdValue[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeValue = DecodeCmdValue; + urldecode((unsigned char *)value, (unsigned char *)DecodeValue); + //printf("CGI[Decodevalue] : %s\n", DecodeValue); + + CmdVec.push_back(std::make_pair((char*)DecodeName, (char *)DecodeValue)); + } + } + //printf("\n[cgicmd process event counters] 6\n"); + //check cmd size & content not empty + { + //check cmd size + if (CmdVec.size() == 0) + { + printf("CmdVec.size == 0\n"); + return rtn_val; + } + //check cmd content is not empty + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (CmdVec[i].first.empty()) + { + printf("[ERROR] CmdVec[%ld].first.empty()\n", (long int)i); + return rtn_val; + } + if (CmdVec[i].second.empty()) + { + printf("[ERROR] CmdVec[%ld].second.empty()\n", (long int)i); + return rtn_val; + } + } + } + + //printf("\n[cgicmd process event counters] 7\n"); + if (type == _CGICMD_GET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = eventsPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + //printf("\n[cgicmd process event counters] 8\n"); + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd process event counters] 9\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + //getconfig?reload=1 + if ((CmdVec[i].first.compare("reload") == 0) && (CmdVec[i].second.compare("1") == 0)) + { + return _CGICMD_RELOAD; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("3") == 0)) + { + return _CGICMD_DEFAULT_3; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("all") == 0)) + { + return _CGICMD_DEFAULT_ALL; + } + else if ((CmdVec[i].first.compare("default") == 0)) + { + return _CGICMD_DEFAULT_NUMBER; + } + else + { + string str_search; + + //chh + //ch=<ch_id> + //ch=all + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + cj_parent = cj_root; + + //ch=<ch_id> //ch=all + if ((is_number(CmdVec[i].second)) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("event_counter_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //MŷjMr + str_search.clear(); + /* + if (is_number(CmdVec[i].second)) + { + printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + + //ch=<ch_id> + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 1]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 2]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + }*/ + if (CmdVec[i].second.compare("all") == 0) //<ch> = all or <tag> = all + { + //printf("CGI[value %d] : %s all\n", i, CmdVec[i].second.c_str()); + break; //~򰵡A^G + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 3]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + printf("[ERROR 4]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + cj_parent = cj_current; + } + //printf("\n[cgicmd process event counters] 10\n"); + if (cj_current != NULL) + { + char* JsonString = NULL; + + JsonString = cJSON_PrintUnformatted(cj_current); + //printf("\nJsonString:%s\n", JsonString); + //printf("\nstrlen(JsonString):%d\n", strlen(JsonString)); + //printf("\nnPassInSize:%d\n", nPassInSize); + + if ((size_t)nPassInSize > strlen(JsonString)) + { + strcpy(szPassIn, JsonString); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("[ERROR 5]\n"); + rtn_val = _CGICMD_FAIL_INSUFFICIENT_BUFFER; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + //printf("\n[cgicmd process event counters] 11\n"); + } + else if (type == _CGICMD_SET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = eventsPATH; + //printf("\n[cgicmd process event counters] 12\n"); + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + //printf("\n[cgicmd process event counters] 13\n"); + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd process event counters] 14\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + string str_search; + + //chh + //ch=<ch_id> + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + //̫@h//uch@hALk]wA^~ + if ((i + 1) == CmdVec.size()) + { + printf("[ERROR 6]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else + { + cj_parent = cj_root; + + //ch=<ch_id> + if (is_number(CmdVec[i].second) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("event_counter_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //̫@hA + if ((i + 1) == CmdVec.size()) + { + /*//uch@hALk]wA^~ + if (CmdVec[i].first.compare("ch") == 0) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else*/ + { + /*//cj_current is array + if (cJSON_IsArray(cj_current)) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + //cj_current is string + else*/ + if (cJSON_IsString(cj_current)) + { + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateString(CmdVec[i].second.c_str())); + } + //cj_current is number + else if (cJSON_IsNumber(cj_current)) + { + if (is_number(CmdVec[i].second)) + { + int num = atoi(CmdVec[i].second.c_str()); + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateNumber(num)); + } + else + { + printf("[ERROR 7]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + else + { + printf("[ERROR 8]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + } + else + { + //MŷjMr + str_search.clear(); + + if (is_number(CmdVec[i].second)) + { + //printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + /* + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else*/ + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 9]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 10]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 11]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + } + else + { + printf("[ERROR 12]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + + cj_parent = cj_current; + } + //printf("\n[cgicmd process event counters] 15\n"); + //update config.json + if (cj_current != NULL) + { + char* JsonString = cJSON_Print(cj_root); + + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("Fail to open Config.json \n"); + rtn_val = _CGICMD_FAIL_SET; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + //printf("\n[cgicmd process event counters] 16\n"); + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + } + + return rtn_val; +} + +CgiCmdRtnCode cgicmd_process_email_setting(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize) +{ + CgiCmdRtnCode rtn_val = _CGICMD_FAIL; + //printf("\n[cgicmd process event counters] 1\n"); + std::vector<std::pair<std::string, std::string> > CmdVec; + + { + int len, nel; + char *q, *name, *value; + + /* Parse into individual assignments */ + //printf("\n[cgicmd process event counters] 2\n"); + q = Cmd; + + len = strlen(Cmd); + nel = 1; + while (strsep(&q, "&")) { + nel++; + } + //printf("CGI[nel string] : %d\n", nel); + //printf("\n[cgicmd process event counters] 3\n"); + for (q = Cmd; q < (Cmd + len);) { + value = name = q; + + /* Skip to next assignment */ + //printf("CGI[string] : %s\n", q); + //printf("CGI[string len] : %d\n", strlen(q)); + //printf("CGI[address] : %x\n", q); + for (q += strlen(q); q < (Cmd + len) && !*q; q++); + /* Assign variable */ + name = strsep(&value, "="); + + //printf("CGI[name ] : %s\n", name); + //printf("CGI[value] : %s\n", value); + + //CmdVec.push_back(std::make_pair(name, value)); + + unsigned char DecodeCmdName[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeName = DecodeCmdName; + urldecode((unsigned char *)name, (unsigned char *)DecodeName); + //printf("CGI[DecodeName] : %s\n", DecodeName); + + unsigned char DecodeCmdValue[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeValue = DecodeCmdValue; + urldecode((unsigned char *)value, (unsigned char *)DecodeValue); + //printf("CGI[Decodevalue] : %s\n", DecodeValue); + + CmdVec.push_back(std::make_pair((char*)DecodeName, (char *)DecodeValue)); + } + } + //printf("\n[cgicmd process event counters] 6\n"); + //check cmd size & content not empty + { + //check cmd size + if (CmdVec.size() == 0) + { + printf("CmdVec.size == 0\n"); + return rtn_val; + } + //check cmd content is not empty + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (CmdVec[i].first.empty()) + { + printf("[ERROR] CmdVec[%ld].first.empty()\n", (long int)i); + return rtn_val; + } + if (CmdVec[i].second.empty()) + { + printf("[ERROR] CmdVec[%ld].second.empty()\n", (long int)i); + return rtn_val; + } + } + } + + //printf("\n[cgicmd process event counters] 7\n"); + if (type == _CGICMD_GET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = eventsPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + //printf("\n[cgicmd process event counters] 8\n"); + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd process event counters] 9\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + //getconfig?reload=1 + if ((CmdVec[i].first.compare("reload") == 0) && (CmdVec[i].second.compare("1") == 0)) + { + return _CGICMD_RELOAD; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("3") == 0)) + { + return _CGICMD_DEFAULT_3; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("all") == 0)) + { + return _CGICMD_DEFAULT_ALL; + } + else if ((CmdVec[i].first.compare("default") == 0)) + { + return _CGICMD_DEFAULT_NUMBER; + } + else + { + string str_search; + + //chh + //ch=<ch_id> + //ch=all + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + cj_parent = cj_root; + + //ch=<ch_id> //ch=all + if ((is_number(CmdVec[i].second)) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("email_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //MŷjMr + str_search.clear(); + /* + if (is_number(CmdVec[i].second)) + { + printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + + //ch=<ch_id> + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 1]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 2]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + }*/ + if (CmdVec[i].second.compare("all") == 0) //<ch> = all or <tag> = all + { + //printf("CGI[value %d] : %s all\n", i, CmdVec[i].second.c_str()); + break; //~򰵡A^G + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 3]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + printf("[ERROR 4]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + cj_parent = cj_current; + } + //printf("\n[cgicmd process event counters] 10\n"); + if (cj_current != NULL) + { + char* JsonString = NULL; + + JsonString = cJSON_PrintUnformatted(cj_current); + //printf("\nJsonString:%s\n", JsonString); + //printf("\nstrlen(JsonString):%d\n", strlen(JsonString)); + //printf("\nnPassInSize:%d\n", nPassInSize); + + if ((size_t)nPassInSize > strlen(JsonString)) + { + strcpy(szPassIn, JsonString); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("[ERROR 5]\n"); + rtn_val = _CGICMD_FAIL_INSUFFICIENT_BUFFER; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + //printf("\n[cgicmd process event counters] 11\n"); + } + else if (type == _CGICMD_SET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + + char *filename; + filename = eventsPATH; + //printf("\n[cgicmd process event counters] 12\n"); + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + //printf("\n[cgicmd process event counters] 13\n"); + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + //printf("\n[cgicmd process event counters] 14\n"); + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + string str_search; + + //chh + //ch=<ch_id> + //ch=<tag> + if (CmdVec[i].first.compare("ch") == 0) + { + //̫@h//uch@hALk]wA^~ + if ((i + 1) == CmdVec.size()) + { + printf("[ERROR 6]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else + { + cj_parent = cj_root; + + //ch=<ch_id> + if (is_number(CmdVec[i].second) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("email_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //̫@hA + if ((i + 1) == CmdVec.size()) + { + /*//uch@hALk]wA^~ + if (CmdVec[i].first.compare("ch") == 0) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else*/ + { + /*//cj_current is array + if (cJSON_IsArray(cj_current)) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + //cj_current is string + else*/ + if (cJSON_IsString(cj_current)) + { + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateString(CmdVec[i].second.c_str())); + } + //cj_current is number + else if (cJSON_IsNumber(cj_current)) + { + if (is_number(CmdVec[i].second)) + { + int num = atoi(CmdVec[i].second.c_str()); + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateNumber(num)); + } + else + { + printf("[ERROR 7]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + else + { + printf("[ERROR 8]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + } + else + { + //MŷjMr + str_search.clear(); + + if (is_number(CmdVec[i].second)) + { + //printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + /* + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else*/ + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 9]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 10]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("ch") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 11]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + } + else + { + printf("[ERROR 12]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + + cj_parent = cj_current; + } + //printf("\n[cgicmd process event counters] 15\n"); + //update config.json + if (cj_current != NULL) + { + char* JsonString = cJSON_Print(cj_root); + + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("Fail to open Config.json \n"); + rtn_val = _CGICMD_FAIL_SET; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + //printf("\n[cgicmd process event counters] 16\n"); + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + } + + return rtn_val; +} + +CgiCmdRtnCode cgicmd_process_cold_objects(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize) +{ + CgiCmdRtnCode rtn_val = _CGICMD_FAIL; + + std::vector<std::pair<std::string, std::string> > CmdVec; + + { + int len, nel; + char *q, *name, *value; + + /* Parse into individual assignments */ + + q = Cmd; + + len = strlen(Cmd); + nel = 1; + while (strsep(&q, "&")) + nel++; + //printf("CGI[nel string] : %d\n", nel); + + for (q = Cmd; q < (Cmd + len);) { + value = name = q; + + /* Skip to next assignment */ + //printf("CGI[string] : %s\n", q); + //printf("CGI[string len] : %d\n", strlen(q)); + //printf("CGI[address] : %x\n", q); + for (q += strlen(q); q < (Cmd + len) && !*q; q++); + /* Assign variable */ + name = strsep(&value, "="); + //printf("CGI[name ] : %s\n", name); + //printf("CGI[value] : %s\n", value); + + //CmdVec.push_back(std::make_pair(name, value)); + + unsigned char DecodeCmdName[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeName = DecodeCmdName; + urldecode((unsigned char *)name, (unsigned char *)DecodeName); + //printf("CGI[DecodeName] : %s\n", DecodeName); + + unsigned char DecodeCmdValue[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeValue = DecodeCmdValue; + urldecode((unsigned char *)value, (unsigned char *)DecodeValue); + //printf("CGI[Decodevalue] : %s\n", DecodeValue); + + CmdVec.push_back(std::make_pair((char*)DecodeName, (char *)DecodeValue)); + } + /* + for (size_t i = 0; i < CmdVec.size(); i++) + { + printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + } + */ + } + + //check cmd size & content not empty + { + //check cmd size + if (CmdVec.size() == 0) + { + printf("CmdVec.size == 0\n"); + return rtn_val; + } + //check cmd content is not empty + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (CmdVec[i].first.empty()) + { + printf("[ERROR] CmdVec[%ld].first.empty()\n", (long int)i); + return rtn_val; + } + if (CmdVec[i].second.empty()) + { + printf("[ERROR] CmdVec[%ld].second.empty()\n", (long int)i); + return rtn_val; + } + } + } + + if (type == _CGICMD_GET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + + + char cold_objectsPATH[1024] = { 0 }; + strcpy(cold_objectsPATH, exePath); + strcat(cold_objectsPATH, "cold_objects.json"); + + char *filename; + filename = cold_objectsPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + /* + if ((CmdVec[i].first.compare("reload") == 0) && (CmdVec[i].second.compare("1") == 0)) + { + return _CGICMD_RELOAD; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("3") == 0)) + { + return _CGICMD_DEFAULT_3; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("all") == 0)) + { + return _CGICMD_DEFAULT_ALL; + } + else if ((CmdVec[i].first.compare("default") == 0)) + { + return _CGICMD_DEFAULT_NUMBER; + } + else*/ + { + string str_search; + + //chh + //ch=<ch_id> + //ch=all + //ch=<tag> + if (CmdVec[i].first.compare("coldobjects") == 0) + { + cj_parent = cj_root; + + //ch=<ch_id> //ch=all + if (CmdVec[i].second.compare("all") == 0) + { + str_search.clear(); + str_search.assign("root_cold_objects"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //MŷjMr + str_search.clear(); + /* + if (is_number(CmdVec[i].second)) + { + printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + + //ch=<ch_id> + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 1]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 2]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + }*/ + if (CmdVec[i].second.compare("all") == 0) //<ch> = all or <tag> = all + { + //printf("CGI[value %d] : %s all\n", i, CmdVec[i].second.c_str()); + break; //~򰵡A^G + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("coldobjects") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 3]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + printf("[ERROR 4]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + cj_parent = cj_current; + } + + if (cj_current != NULL) + { + char* JsonString = NULL; + + JsonString = cJSON_PrintUnformatted(cj_current); + //printf("\nJsonString:%s\n", JsonString); + //printf("\nstrlen(JsonString):%d\n", strlen(JsonString)); + //printf("\nnPassInSize:%d\n", nPassInSize); + + if ((size_t)nPassInSize > strlen(JsonString)) + { + strcpy(szPassIn, JsonString); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("[ERROR 5]\n"); + rtn_val = _CGICMD_FAIL_INSUFFICIENT_BUFFER; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + } + else if (type == _CGICMD_SET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + + char cold_objectsPATH[1024] = { 0 }; + strcpy(cold_objectsPATH, exePath); + strcat(cold_objectsPATH, "cold_objects.json"); + + char *filename; + filename = cold_objectsPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + string str_search; + + //chh + //ch=<ch_id> + //ch=<tag> + if (CmdVec[i].first.compare("coldobjects") == 0) + { + //̫@h//uch@hALk]wA^~ + if ((i + 1) == CmdVec.size()) + { + printf("[ERROR 6]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else + { + cj_parent = cj_root; + + //ch=<ch_id> + if (is_number(CmdVec[i].second) || (CmdVec[i].second.compare("all") == 0)) + { + str_search.clear(); + str_search.assign("root_cold_objects"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //̫@hA + if ((i + 1) == CmdVec.size()) + { + /*//uch@hALk]wA^~ + if (CmdVec[i].first.compare("ch") == 0) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + else*/ + { + /*//cj_current is array + if (cJSON_IsArray(cj_current)) + { + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + //cj_current is string + else*/ + if (cJSON_IsString(cj_current)) + { + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateString(CmdVec[i].second.c_str())); + } + //cj_current is number + else if (cJSON_IsNumber(cj_current)) + { + if (is_number(CmdVec[i].second)) + { + int num = atoi(CmdVec[i].second.c_str()); + cJSON_ReplaceItemInObject(cj_parent, str_search.c_str(), cJSON_CreateNumber(num)); + } + else + { + printf("[ERROR 7]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + else + { + printf("[ERROR 8]\n"); + rtn_val = _CGICMD_FAIL_SET; + cj_current = NULL; + break; + } + } + } + else + { + //MŷjMr + str_search.clear(); + + if (is_number(CmdVec[i].second)) + { + //printf("CGI[value %d] : %s is digit\n", i, CmdVec[i].second.c_str()); + int idx = atoi(CmdVec[i].second.c_str()); + /* + if (CmdVec[i].first.compare("ch") == 0) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", idx); + + cj_parent = cj_current; + //str_search.clear(); + str_search = CameraID; + } + else*/ + { + if (cJSON_IsArray(cj_current) && (idx < cJSON_GetArraySize(cj_current))) + { + cj_parent = cj_current; + cj_current = cJSON_GetArrayItem(cj_parent, idx); + + if (cj_current == NULL) + { + printf("[ERROR 9]\n"); + rtn_val = _CGICMD_FAIL; + break; + } + } + else + { + printf("[ERROR 10]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("coldobjects") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + } + else + { + printf("[ERROR 11]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + } + else + { + printf("[ERROR 12]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + + cj_parent = cj_current; + } + + //update config.json + if (cj_current != NULL) + { + char* JsonString = cJSON_Print(cj_root); + + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("Fail to open cold_objects.json \n"); + rtn_val = _CGICMD_FAIL_SET; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + } + + return rtn_val; +} + +CgiCmdRtnCode cgicmd_process_detection_zone(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize) +{ + CgiCmdRtnCode rtn_val = _CGICMD_FAIL; + + std::vector<std::pair<std::string, std::string> > CmdVec; + + { + int len, nel; + char *q, *name, *value; + + /* Parse into individual assignments */ + + q = Cmd; + + len = strlen(Cmd); + nel = 1; + while (strsep(&q, "&")) + nel++; + //printf("CGI[nel string] : %d\n", nel); + + for (q = Cmd; q < (Cmd + len);) { + value = name = q; + + /* Skip to next assignment */ + //printf("CGI[string] : %s\n", q); + //printf("CGI[string len] : %d\n", strlen(q)); + //printf("CGI[address] : %x\n", q); + for (q += strlen(q); q < (Cmd + len) && !*q; q++); + /* Assign variable */ + name = strsep(&value, "="); + //printf("CGI[name ] : %s\n", name); + //printf("CGI[value] : %s\n", value); + + //CmdVec.push_back(std::make_pair(name, value)); + + unsigned char DecodeCmdName[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeName = DecodeCmdName; + urldecode((unsigned char *)name, (unsigned char *)DecodeName); + //printf("CGI[DecodeName] : %s\n", DecodeName); + + unsigned char DecodeCmdValue[MAX_CMD_SIZE] = { 0 }; + unsigned char* DecodeValue = DecodeCmdValue; + urldecode((unsigned char *)value, (unsigned char *)DecodeValue); + //printf("CGI[Decodevalue] : %s\n", DecodeValue); + + CmdVec.push_back(std::make_pair((char*)DecodeName, (char *)DecodeValue)); + } + /* + for (int i = 0; i < CmdVec.size(); i++) + { + printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + } + */ + } + + //check cmd size & content not empty + { + //check cmd size + if (CmdVec.size() == 0) + { + printf("CmdVec.size == 0\n"); + return rtn_val; + } + //check cmd content is not empty + for (size_t i = 0; i < CmdVec.size(); i++) + { + if (CmdVec[i].first.empty()) + { + printf("[ERROR] CmdVec[%ld].first.empty()\n", (long int)i); + return rtn_val; + } + if (CmdVec[i].second.empty()) + { + printf("[ERROR] CmdVec[%ld].second.empty()\n", (long int)i); + return rtn_val; + } + } + } + + if (type == _CGICMD_GET) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); +#endif //GY_OS_AMBA + + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + char *filename; + filename = configPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return rtn_val; + } + + //size_t nfileSize = ReadFileSize(filename); + //printf("nfileSize:%d\n", nfileSize); + char *fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) + return rtn_val; + cJSON *cj_root = NULL; + + cJSON *cj_current = NULL; + cJSON *cj_parent = NULL; + + cj_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + cj_parent = cj_root; + + if (cj_root == NULL) + { + printf("cj_root is NULL\n"); + return rtn_val; + } + + for (size_t i = 0; i < CmdVec.size(); i++) + { + //printf("CGI[name %d] : %s\n", i, CmdVec[i].first.c_str()); + //printf("CGI[value %d] : %s\n", i, CmdVec[i].second.c_str()); + + /* + if ((CmdVec[i].first.compare("reload") == 0) && (CmdVec[i].second.compare("1") == 0)) + { + return _CGICMD_RELOAD; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("3") == 0)) + { + return _CGICMD_DEFAULT_3; + } + else if ((CmdVec[i].first.compare("default") == 0) && (CmdVec[i].second.compare("all") == 0)) + { + return _CGICMD_DEFAULT_ALL; + } + else if ((CmdVec[i].first.compare("default") == 0)) + { + return _CGICMD_DEFAULT_NUMBER; + } + else*/ + { + string str_search; + + //chh + //ch=<ch_id> + //ch=all + //ch=<tag> + if (CmdVec[i].first.compare("detection_zone") == 0) + { + cj_parent = cj_root; + + //ch=<ch_id> //ch=all + if (CmdVec[i].second.compare("all") == 0) + { + str_search.clear(); + str_search.assign("view_setting"); + } + //ch=<tag> + else + { + str_search.clear(); + str_search = CmdVec[i].second; + } + } + else + { + str_search.clear(); + str_search = CmdVec[i].first; + } + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + cj_parent = cj_current; + str_search.clear(); + str_search.assign("camera01"); + } + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + cj_parent = cj_current; + str_search.clear(); + str_search.assign("detection_zone"); + } + + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + //MŷjMr + str_search.clear(); + + if (CmdVec[i].second.compare("all") == 0) //<ch> = all or <tag> = all + { + //printf("CGI[value %d] : %s all\n", i, CmdVec[i].second.c_str()); + break; //~򰵡A^G + } + else + { + cj_parent = cj_current; + + if (CmdVec[i].first.compare("detection_zone") != 0) + { + //printf("CGI[value %d] : %s other tag\n", i, CmdVec[i].second.c_str()); + str_search.clear(); + str_search = CmdVec[i].second; + } + } + + //jMrꤣ + if (!str_search.empty()) + { + if (cJSON_HasObjectItem(cj_parent, str_search.c_str())) + { + cj_current = cJSON_GetObjectItem(cj_parent, str_search.c_str()); + + } + else + { + printf("[ERROR 3]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + } + else + { + printf("[ERROR 4]\n"); + rtn_val = _CGICMD_FAIL; + cj_current = NULL; + break; + } + } + cj_parent = cj_current; + } + + if (cj_current != NULL) + { + char* JsonString = NULL; + + JsonString = cJSON_PrintUnformatted(cj_current); + //printf("\nJsonString:%s\n", JsonString); + //printf("\nstrlen(JsonString):%d\n", strlen(JsonString)); + //printf("\nnPassInSize:%d\n", nPassInSize); + + if ((size_t)nPassInSize > strlen(JsonString)) + { + strcpy(szPassIn, JsonString); + rtn_val = _CGICMD_SUCCESS; + } + else + { + printf("[ERROR 5]\n"); + rtn_val = _CGICMD_FAIL_INSUFFICIENT_BUFFER; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + if (cj_root) { + cJSON_Delete(cj_root); + cj_root = NULL; + } + } + return rtn_val; +} +#endif \ No newline at end of file diff --git a/src/cgicmd.h b/src/cgicmd.h new file mode 100644 index 0000000..9c12c14 --- /dev/null +++ b/src/cgicmd.h @@ -0,0 +1,41 @@ +#if 1 + +#pragma once +#ifndef CGICMD_H +#define CGICMD_H +#include "define_inc.h" +#include <stdio.h> +#include <string.h> +#include "setting.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_CMD_SIZE 8192 + +typedef enum { _CGICMD_SET, _CGICMD_GET} CgiCmdType; +typedef enum { _CGICMD_SUCCESS, _CGICMD_FAIL , _CGICMD_FAIL_INSUFFICIENT_BUFFER , _CGICMD_FAIL_SET ,_CGICMD_RELOAD, _CGICMD_DEFAULT_ALL, _CGICMD_DEFAULT_3, _CGICMD_DEFAULT_NUMBER} CgiCmdRtnCode; + + +CgiCmdRtnCode cgicmd_process(char cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize); +CgiCmdRtnCode cgicmd_process_events(char cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize); +CgiCmdRtnCode cgicmd_process_cold_objects(char cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize); +CgiCmdRtnCode cgicmd_process_detection_zone(char cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize); +CgiCmdRtnCode cgicmd_process_event_counters(char cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize); +CgiCmdRtnCode cgicmd_process_email_setting(char Cmd[MAX_CMD_SIZE], CgiCmdType type, char* szPassIn, int nPassInSize); + +extern char aida_port_for_cgicmd[512]; +extern char aida_username_for_cgicmd[512]; +extern char aida_device_name_for_cgicmd[512]; + +void urlencode(unsigned char * src, int src_len, unsigned char * dest, int dest_len); +unsigned char* urldecode(unsigned char* encd, unsigned char* decd); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/src/col2im.c b/src/col2im.c new file mode 100644 index 0000000..5c4605e --- /dev/null +++ b/src/col2im.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <math.h> +void col2im_add_pixel(float *im, int height, int width, int channels, + int row, int col, int channel, int pad, float val) +{ + row -= pad; + col -= pad; + + if (row < 0 || col < 0 || + row >= height || col >= width) return; + im[col + width*(row + height*channel)] += val; +} +//This one might be too, can't remember. +void col2im_cpu(float* data_col, + int channels, int height, int width, + int ksize, int stride, int pad, float* data_im) +{ + int c,h,w; + int height_col = (height + 2*pad - ksize) / stride + 1; + int width_col = (width + 2*pad - ksize) / stride + 1; + + int channels_col = channels * ksize * ksize; + for (c = 0; c < channels_col; ++c) { + int w_offset = c % ksize; + int h_offset = (c / ksize) % ksize; + int c_im = c / ksize / ksize; + for (h = 0; h < height_col; ++h) { + for (w = 0; w < width_col; ++w) { + int im_row = h_offset + h * stride; + int im_col = w_offset + w * stride; + int col_index = (c * height_col + h) * width_col + w; + double val = data_col[col_index]; + col2im_add_pixel(data_im, height, width, channels, + im_row, im_col, c_im, pad, val); + } + } + } +} + diff --git a/src/col2im.h b/src/col2im.h new file mode 100644 index 0000000..142b680 --- /dev/null +++ b/src/col2im.h @@ -0,0 +1,14 @@ +#pragma once +#ifndef COL2IM_H +#define COL2IM_H +#include "define_inc.h" +void col2im_cpu(float* data_col, + int channels, int height, int width, + int ksize, int stride, int pad, float* data_im); + +#ifdef GPU +void col2im_gpu(float *data_col, + int channels, int height, int width, + int ksize, int stride, int pad, float *data_im); +#endif +#endif diff --git a/src/col2im_kernels.cu b/src/col2im_kernels.cu new file mode 100644 index 0000000..ba45e0f --- /dev/null +++ b/src/col2im_kernels.cu @@ -0,0 +1,58 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "col2im.h" +#include "cuda.h" +} + +// src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu +// You may also want to read: https://github.com/BVLC/caffe/blob/master/LICENSE + +__global__ void col2im_gpu_kernel(const int n, const float* data_col, + const int height, const int width, const int ksize, + const int pad, + const int stride, + const int height_col, const int width_col, + float *data_im) { + int index = blockIdx.x*blockDim.x+threadIdx.x; + for(; index < n; index += blockDim.x*gridDim.x){ + float val = 0; + int w = index % width + pad; + int h = (index / width) % height + pad; + int c = index / (width * height); + // compute the start and end of the output + int w_col_start = (w < ksize) ? 0 : (w - ksize) / stride + 1; + int w_col_end = min(w / stride + 1, width_col); + int h_col_start = (h < ksize) ? 0 : (h - ksize) / stride + 1; + int h_col_end = min(h / stride + 1, height_col); + // equivalent implementation + int offset = + (c * ksize * ksize + h * ksize + w) * height_col * width_col; + int coeff_h_col = (1 - stride * ksize * height_col) * width_col; + int coeff_w_col = (1 - stride * height_col * width_col); + for (int h_col = h_col_start; h_col < h_col_end; ++h_col) { + for (int w_col = w_col_start; w_col < w_col_end; ++w_col) { + val += data_col[offset + h_col * coeff_h_col + w_col * coeff_w_col]; + } + } + data_im[index] += val; + } +} + +void col2im_gpu(float *data_col, + int channels, int height, int width, + int ksize, int stride, int pad, float *data_im){ + // We are going to launch channels * height_col * width_col kernels, each + // kernel responsible for copying a single-channel grid. + int height_col = (height + 2 * pad - ksize) / stride + 1; + int width_col = (width + 2 * pad - ksize) / stride + 1; + int num_kernels = channels * height * width; + col2im_gpu_kernel<<<(num_kernels+BLOCK-1)/BLOCK, + BLOCK>>>( + num_kernels, data_col, height, width, ksize, pad, + stride, height_col, + width_col, data_im); +} + diff --git a/src/cold_zone.c b/src/cold_zone.c new file mode 100644 index 0000000..8df368c --- /dev/null +++ b/src/cold_zone.c @@ -0,0 +1,437 @@ +#if 1 +#include "cold_zone.h" +//#include "setting.h" +#include "utility.h" +#include "cJSON.h" + +ColdZone g_stColdZone[MAX_DETECTION_ZONE] = {0}; + +void ColdZoneInit() +{ + for (int i = 0; i < MAX_DETECTION_ZONE; i++) + { + for (int j = 0; j < MAX_LENGTH_ARRAY_COLD_OBJECTS; j++) + { + strcpy(g_stColdZone[i].stColdObject[j].sColdObjectName, ""); + g_stColdZone[i].stColdObject[j].iLeft_x = -1; + g_stColdZone[i].stColdObject[j].iTop_y = -1; + g_stColdZone[i].stColdObject[j].iWidth = -1; + g_stColdZone[i].stColdObject[j].iHeight = -1; + g_stColdZone[i].stColdObject[j].iReduceConfidence = 20; //Default every time reduce value = 10% + } + + g_stColdZone[i].iRecodeIdx = 0; + g_stColdZone[i].iColdObjectNum = 0; + g_stColdZone[i].iEnableColdZone = 0; + } +} + +int ReadColdZoneJsonFile() +{ + int ret = 0; + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char cold_objectsPATH[1024] = { 0 }; + strcpy(cold_objectsPATH, exePath); + strcat(cold_objectsPATH, "cold_objects.json"); + + char *filename_cold_objects = cold_objectsPATH; + if (!FileExist(filename_cold_objects)) + { + printf("%s doesn't exist.\n", filename_cold_objects); + //rtn = _CGICMD_FAIL; + ret = -1; + g_stColdZone[0].iColdObjectNum = 0; + return ret; + } + else + { + char *fileBuf_cold_objects = ReadAllBytes(filename_cold_objects); + + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_cold_objects); + + if (fileBuf_cold_objects) { + free(fileBuf_cold_objects); + fileBuf_cold_objects = NULL; + } + + if (root == NULL) + { + printf("root_cold_objects is NULL\n"); + ret = -1; + g_stColdZone[0].iColdObjectNum = 0; + return ret; + } + else + { + g_stColdZone[0].iColdObjectNum = 0; //re-count code objects + + cJSON *root_cold_objects, *index/*, *object_number*/, *cold_object_list, *cold_object; + cJSON *left_x, *top_y, *width, *height, *obj_name; + + root_cold_objects = cJSON_GetObjectItem(root, "root_cold_objects"); + index = cJSON_GetObjectItem(root_cold_objects, "index"); //Write array index + + g_stColdZone[0].iRecodeIdx = index->valueint; + + cold_object_list = cJSON_GetObjectItem(root_cold_objects, "cold_objects"); + + int i = 0; + cJSON_ArrayForEach(cold_object, cold_object_list) + { + left_x = cJSON_GetObjectItem(cold_object, "X"); + top_y = cJSON_GetObjectItem(cold_object, "Y"); + width = cJSON_GetObjectItem(cold_object, "W"); + height = cJSON_GetObjectItem(cold_object, "H"); + obj_name = cJSON_GetObjectItem(cold_object, "Object"); + + g_stColdZone[0].stColdObject[i].iLeft_x = left_x->valueint; + g_stColdZone[0].stColdObject[i].iTop_y = top_y->valueint; + g_stColdZone[0].stColdObject[i].iWidth = width->valueint; + g_stColdZone[0].stColdObject[i].iHeight = height->valueint; + strcpy(g_stColdZone[0].stColdObject[i].sColdObjectName, obj_name->valuestring); + + if (strlen(g_stColdZone[0].stColdObject[i].sColdObjectName) >= 1) { + g_stColdZone[0].iColdObjectNum++; + + } + + i++; + } + + if (i < MAX_LENGTH_ARRAY_COLD_OBJECTS) { + g_stColdZone[0].iColdObjectNum = 0; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + + /* + for (int i = 0; i < 8; i++) + { + printf("r[%d]------------\n", i); + printf("rX = %d\n", g_stColdZone[0].stColdObject[i].iLeft_x); + printf("rY = %d\n", g_stColdZone[0].stColdObject[i].iTop_y); + printf("rW = %d\n", g_stColdZone[0].stColdObject[i].iWidth); + printf("rH = %d\n", g_stColdZone[0].stColdObject[i].iHeight); + printf("rName = %s\n", g_stColdZone[0].stColdObject[i].sColdObjectName); + } + */ + return ret; +} + +void WriteColdZoneJsonFile() +{ + //int ret = 0; + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char cold_objectsPATH[1024] = { 0 }; + strcpy(cold_objectsPATH, exePath); + strcat(cold_objectsPATH, "cold_objects.json"); + + char *filename_cold_objects = cold_objectsPATH; + if (!FileExist(filename_cold_objects)) + { + printf("%s doesn't exist.\n", filename_cold_objects); + //rtn = _CGICMD_FAIL; + //ret = -1; + //return ret; + return; + } + else + { + //size_t nfileSize_cold_objects = ReadFileSize(filename_cold_objects); + //printf("nfileSize_cold_objects:%d\n", nfileSize_cold_objects); + char *fileBuf_cold_objects = ReadAllBytes(filename_cold_objects); + + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_cold_objects); + + if (fileBuf_cold_objects) { + free(fileBuf_cold_objects); + fileBuf_cold_objects = NULL; + } + + if (root == NULL) + { + printf("root_cold_objects is NULL\n"); + //ret = -1; + //return ret; + return; + } + else + { + cJSON *root_cold_objects, /**index,*/ *cold_object_list, *cold_object; + /*cJSON *left_x, *top_y, *width, *height, *obj_name;*/ + + root_cold_objects = cJSON_GetObjectItem(root, "root_cold_objects"); + //index = cJSON_GetObjectItem(root_cold_objects, "index"); //Write array index + cold_object_list = cJSON_GetObjectItem(root_cold_objects, "cold_objects"); + + cJSON_ReplaceItemInObject(root_cold_objects, "index", cJSON_CreateNumber(g_stColdZone[0].iRecodeIdx)); + + int i = 0; + cJSON_ArrayForEach(cold_object, cold_object_list) + { + //g_stColdZone[0].stColdObject[i].iLeft_x + cJSON_ReplaceItemInObject(cold_object, "X", cJSON_CreateNumber(g_stColdZone[0].stColdObject[i].iLeft_x)); + cJSON_ReplaceItemInObject(cold_object, "Y", cJSON_CreateNumber(g_stColdZone[0].stColdObject[i].iTop_y)); + cJSON_ReplaceItemInObject(cold_object, "W", cJSON_CreateNumber(g_stColdZone[0].stColdObject[i].iWidth)); + cJSON_ReplaceItemInObject(cold_object, "H", cJSON_CreateNumber(g_stColdZone[0].stColdObject[i].iHeight)); + cJSON_ReplaceItemInObject(cold_object, "Object", cJSON_CreateString(g_stColdZone[0].stColdObject[i].sColdObjectName)); + + i++; + } + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_cold_objects, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + printf("Fail to open cold_object.json \n"); + //ret = -1; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } //if (root) + + cJSON_Delete(root); + } + + //return ret; + return; +} + +//int SetColdZone(int iZoneIdx, int iObjIdx, int iLeftX, int iTopY, int iWidth, int iHeight, char *sObjName) +int SetColdZone(char *sCmd) +{ + int ret = 0; + + //Parse Cmd + const char *del = "&"; + char a_data_coldobject[MAX_SIZE_A_COLD_OBJECT][STRSPLIT_SIZE] = {0}; + int a_data_coldobject_num = 0; + + const char *del2 = "="; + char a_data_coldobject_pair[MAX_SIZE_A_COLD_OBJECT][2][STRSPLIT_SIZE] = { 0 }; + //int a_data_coldobject_pair_num[MAX_SIZE_A_COLD_OBJECT] = { 0 }; + + int x_coldobject = 0; + int y_coldobject = 0; + int w_coldobject = 0; + int h_coldobject = 0; + char object_coldobject[MAX_SIZE_COLD_OBJECT_LABEL]; + + int iRecordIndex = g_stColdZone[0].iRecodeIdx; + + a_data_coldobject_num = StrSplit(sCmd, a_data_coldobject, del); + //printf("\n------UU:1\n"); + iRecordIndex++; + if (iRecordIndex >= MAX_LENGTH_ARRAY_COLD_OBJECTS) + iRecordIndex = 0; + + g_stColdZone[0].iRecodeIdx = iRecordIndex; + + if (a_data_coldobject_num == MAX_SIZE_A_COLD_OBJECT) + { + for (int i = 0; i < a_data_coldobject_num; i++) + { + //printf("\n%s\n",a_data_coldobject[i]); + if (a_data_coldobject[i]) + { + //a_data_coldobject_pair_num[i] = + StrSplit(a_data_coldobject[i], a_data_coldobject_pair[i], del2); + //printf("\n------UU:2\n"); + + if (strcmp(a_data_coldobject_pair[i][0], "x") == 0 || + strcmp(a_data_coldobject_pair[i][0], "X") == 0) { + x_coldobject = atoi(a_data_coldobject_pair[i][1]); + g_stColdZone[0].stColdObject[iRecordIndex].iLeft_x = x_coldobject; + } + else if (strcmp(a_data_coldobject_pair[i][0], "y") == 0 || + strcmp(a_data_coldobject_pair[i][0], "Y") == 0) { + y_coldobject = atoi(a_data_coldobject_pair[i][1]); + g_stColdZone[0].stColdObject[iRecordIndex].iTop_y = y_coldobject; + } + else if (strcmp(a_data_coldobject_pair[i][0], "w") == 0 || + strcmp(a_data_coldobject_pair[i][0], "W") == 0) { + w_coldobject = atoi(a_data_coldobject_pair[i][1]); + g_stColdZone[0].stColdObject[iRecordIndex].iWidth = w_coldobject; + } + else if (strcmp(a_data_coldobject_pair[i][0], "h") == 0 || + strcmp(a_data_coldobject_pair[i][0], "H") == 0) { + h_coldobject = atoi(a_data_coldobject_pair[i][1]); + g_stColdZone[0].stColdObject[iRecordIndex].iHeight = h_coldobject; + } + else if (strcmp(a_data_coldobject_pair[i][0], "object") == 0 || + strcmp(a_data_coldobject_pair[i][0], "Object") == 0) { + strcpy(object_coldobject, a_data_coldobject_pair[i][1]); + sprintf(g_stColdZone[0].stColdObject[iRecordIndex].sColdObjectName, "%s", object_coldobject); + } + else if (strcmp(a_data_coldobject_pair[i][0], "objectid") == 0 || + strcmp(a_data_coldobject_pair[i][0], "Objectid") == 0) { + get_classname(atoi(a_data_coldobject_pair[i][1]), object_coldobject); + sprintf(g_stColdZone[0].stColdObject[iRecordIndex].sColdObjectName, "%s", object_coldobject); + } + } //if (a_data_coldobject[i]) + } //for each cold object elements. + + g_stColdZone[0].iColdObjectNum++; + } //if (a_data_coldobject_num == MAX_SIZE_A_COLD_OBJECT) + else + ret = -1; + + /* + for (int i = 0; i < 8; i++) + { + printf("[%d]------------\n", i); + printf("X = %d\n", g_stColdZone[0].stColdObject[i].iLeft_x); + printf("Y = %d\n", g_stColdZone[0].stColdObject[i].iTop_y); + printf("W = %d\n", g_stColdZone[0].stColdObject[i].iWidth); + printf("H = %d\n", g_stColdZone[0].stColdObject[i].iHeight); + printf("Name = %s\n", g_stColdZone[0].stColdObject[i].sColdObjectName); + } + */ + return ret; +} + +//1: Enable, 0: Disable +int IsEnableColdZone() +{ + int ret = 0; + + if (g_stColdZone[0].iColdObjectNum <= 0) + ret = 0; + else if (g_stColdZone[0].iColdObjectNum > 0) + ret = 1; + + return ret; +} + +void ColdObjectCheck(detection_pos* PosInfo, int total_element_size, int i_ori_yuv_width, int i_ori_yuv_height) +{ + if (PosInfo) + { + for (int i = 0; i < total_element_size; i++) + { + detection_pos *pNext = NULL; + pNext = PosInfo + i; + + if (pNext && pNext->confidence > 0 && strlen(pNext->name) >= 1 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + //printf("\n----(%d)-pNext->name:%s\n",i, pNext->name); + if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + //P^rMƦr + pNext->confidence = 0.0; + } + else { + for (int j = 0; j < MAX_LENGTH_ARRAY_COLD_OBJECTS; j++) + { + if (strlen(g_stColdZone[0].stColdObject[j].sColdObjectName) >= 1 + && strcmp(pNext->name, g_stColdZone[0].stColdObject[j].sColdObjectName) == 0) + { + if (g_stColdZone[0].stColdObject[j].iLeft_x >= 1 && + g_stColdZone[0].stColdObject[j].iTop_y >= 1 && + g_stColdZone[0].stColdObject[j].iWidth >= 1 && + g_stColdZone[0].stColdObject[j].iHeight >= 1) { + + detection_pos pNext2 = { 0 }; + pNext2.left_x = (float)g_stColdZone[0].stColdObject[j].iLeft_x * (float)i_ori_yuv_width / (float)SCALE_BOUNDING_BOX_WIDTH; + pNext2.top_y = (float)g_stColdZone[0].stColdObject[j].iTop_y * (float)i_ori_yuv_height / (float)SCALE_BOUNDING_BOX_HEIGHT; + pNext2.width = (float)g_stColdZone[0].stColdObject[j].iWidth * (float)i_ori_yuv_width / (float)SCALE_BOUNDING_BOX_WIDTH; + pNext2.height = (float)g_stColdZone[0].stColdObject[j].iHeight * (float)i_ori_yuv_height / (float)SCALE_BOUNDING_BOX_HEIGHT; + + if (detection_overlap_ratio(pNext, &pNext2) > (75.0 / 100.0)) + { + //printf("Check Confidence %f, %d \n", pNext->confidence, REDUCE_CONFIDENCE_VALUE); + pNext->confidence = pNext->confidence - (float)REDUCE_CONFIDENCE_VALUE; + if (pNext->confidence < 0.0) + pNext->confidence = 0.0; + + //printf("Check Confidence %f \n", pNext->confidence); + } + } + } + else if (strlen(g_stColdZone[0].stColdObject[j].sColdObjectName) >= 1 + && strcmp("ban_zone", g_stColdZone[0].stColdObject[j].sColdObjectName) == 0) { + + if (g_stColdZone[0].stColdObject[j].iLeft_x >= 1 && + g_stColdZone[0].stColdObject[j].iTop_y >= 1 && + g_stColdZone[0].stColdObject[j].iWidth >= 1 && + g_stColdZone[0].stColdObject[j].iHeight >= 1) { + detection_pos pNext2 = { 0 }; + pNext2.left_x = (float)g_stColdZone[0].stColdObject[j].iLeft_x * (float)i_ori_yuv_width / (float)SCALE_BOUNDING_BOX_WIDTH; + pNext2.top_y = (float)g_stColdZone[0].stColdObject[j].iTop_y * (float)i_ori_yuv_height / (float)SCALE_BOUNDING_BOX_HEIGHT; + pNext2.width = (float)g_stColdZone[0].stColdObject[j].iWidth * (float)i_ori_yuv_width / (float)SCALE_BOUNDING_BOX_WIDTH; + pNext2.height = (float)g_stColdZone[0].stColdObject[j].iHeight * (float)i_ori_yuv_height / (float)SCALE_BOUNDING_BOX_HEIGHT; + + if (detection_overlap_ratio(pNext, &pNext2) > 0.0) + { + //printf("Check Confidence %f, %d \n", pNext->confidence, REDUCE_CONFIDENCE_VALUE); + pNext->confidence = 0.0; + + //printf("Check Confidence %f \n", pNext->confidence); + } + } + } + else if (strlen(g_stColdZone[0].stColdObject[j].sColdObjectName) >= 1 + && strcmp("buffer_zone", g_stColdZone[0].stColdObject[j].sColdObjectName) == 0) { + + if (g_stColdZone[0].stColdObject[j].iLeft_x >= 1 && + g_stColdZone[0].stColdObject[j].iTop_y >= 1 && + g_stColdZone[0].stColdObject[j].iWidth >= 1 && + g_stColdZone[0].stColdObject[j].iHeight >= 1) { + detection_pos pNext2 = { 0 }; + pNext2.left_x = (float)g_stColdZone[0].stColdObject[j].iLeft_x * (float)i_ori_yuv_width / (float)SCALE_BOUNDING_BOX_WIDTH; + pNext2.top_y = (float)g_stColdZone[0].stColdObject[j].iTop_y * (float)i_ori_yuv_height / (float)SCALE_BOUNDING_BOX_HEIGHT; + pNext2.width = (float)g_stColdZone[0].stColdObject[j].iWidth * (float)i_ori_yuv_width / (float)SCALE_BOUNDING_BOX_WIDTH; + pNext2.height = (float)g_stColdZone[0].stColdObject[j].iHeight * (float)i_ori_yuv_height / (float)SCALE_BOUNDING_BOX_HEIGHT; + + if (detection_overlap_ratio(pNext, &pNext2) > (75.0 / 100.0)) + { + //printf("Check Confidence %f, %d \n", pNext->confidence, REDUCE_CONFIDENCE_VALUE); + pNext->confidence = pNext->confidence - (float)REDUCE_CONFIDENCE_VALUE; + if (pNext->confidence < 0.0) + pNext->confidence = 0.0; + + //printf("Check Confidence %f \n", pNext->confidence); + } + } + } + + } + } + } + } + } +} +#endif + diff --git a/src/cold_zone.h b/src/cold_zone.h new file mode 100644 index 0000000..62f5fe7 --- /dev/null +++ b/src/cold_zone.h @@ -0,0 +1,39 @@ +#if 1 +#pragma once +#ifndef COLD_ZONE_H +#define COLD_ZONE_H +#include "define_inc.h" +#include "utility.h" +//#include "nweb.h" + +#define MAX_LENGTH_ARRAY_COLD_OBJECTS 8 +#define MAX_SIZE_A_COLD_OBJECT 5 +#define MAX_SIZE_COLD_OBJECT_LABEL 256 +#define REDUCE_CONFIDENCE_VALUE 20 + +typedef struct { + int iLeft_x; + int iTop_y; + int iWidth; + int iHeight; + char sColdObjectName[MAX_SIZE_COLD_OBJECT_LABEL]; + int iReduceConfidence; +} ColdZoneObj; + +typedef struct { + ColdZoneObj stColdObject[MAX_LENGTH_ARRAY_COLD_OBJECTS]; + int iEnableColdZone; + int iColdObjectNum; + int iRecodeIdx; +} ColdZone; + + +void ColdZoneInit(); +int ReadColdZoneJsonFile(); +void WriteColdZoneJsonFile(); +int SetColdZone(char *sCmd); +int IsEnableColdZone(); +void ColdObjectCheck(detection_pos* PosInfo, int total_element_size, int i_ori_yuv_width, int i_ori_yuv_height); + +#endif +#endif diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..8f82543 --- /dev/null +++ b/src/config.h @@ -0,0 +1,323 @@ +/* + * + * Automatically generated file; DO NOT EDIT. + * Ambarella Build Configuration + * + */ +#pragma once +#ifndef AMBA_AUTO_CONFIG +#define AMBA_AUTO_CONFIG +#include "define_inc.h" +#define CONFIG_AMBARELLA_LIBXML2_SUPPORT 1 +#define AMBOOT_AUDIO_16BIT 1 +#define BUILD_AMBARELLA_SECURITY_PACKAGE 1 +#define CONFIG_AMBOOT_ETH_PHY_CLK_EXTERNAL 1 +#define CONFIG_LINUX_KERNEL_VERSION "4.14" +#define CONFIG_AMBARELLA_SERIAL_PORT2_NA 1 +#define DSP_IAVRSVD_SIZE 0x1200000 +#define AMBCMA_DEFAULT_CACHED_BUF_MAP 0x2627e +#define CONFIG_AMBARELLA_LIBEDIT_SUPPORT 1 +#define BUILD_AMBARELLA_CMA 1 +#define BUILD_AMBARELLA_UNIT_TESTS_AMBADEBUG 1 +#define CV_RAM_START 0x60000000 +#define CONFIG_AMBARELLA_AAC_ENC_LC_SUPPORT 1 +#define CONFIG_AMBOOT_ENABLE_SD 1 +#define CONFIG_AMBARELLA_NCURSES_SUPPORT 1 +#define BUILD_AMBARELLA_VPROC_PACKAGE_BIN_INSTALL_PATH "/usr/local/vproc" +#define CONFIG_AMBARELLA_AUTO_TELNETD 1 +#define CONFIG_AMBARELLA_INIT_SYSTEMD 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_NNCTRL_MTCNN 1 +#define CONFIG_DIGITAL_SIGNATURE_LIBRARY_NATIVE 1 +#define CONFIG_YUV_LT6911 1 +#define KERNEL_VIF "$(AMB_TOPDIR)/amboot/vif/kernel.info" +#define CONFIG_AMBARELLA_WPA_SUPPLICANT_SUPPORT 1 +#define CONFIG_AMBARELLA_LIBELF_SUPPORT 1 +#define CONFIG_AMBARELLA_DEWARP_LIBRARY 1 +#define CONFIG_AMBOOT_ETH_PHY_CLK_INVERT 1 +#define BUILD_AMBARELLA_DEBUG 1 +#define CONFIG_CV25_HAZELNUT_SELECT_SPI1 1 +//#define ADD "" +#define BUILD_AMBARELLA_LW_MEDIA_LINUXFB 1 +#define CONFIG_AMBARELLA_OPENCV_SUPPORT 1 +#define IAV_MEM_MV_SIZE 0x0000000 +#define CONFIG_AMBARELLA_CA_CERTIFICATES_SUPPORT 1 +#define AMBOOT_DEV_NORMAL_MODE 1 +#define AMBOOT_AUDIO_MODE_MASTER 1 +#define CONFIG_SENSOR_AR0237P 1 +#define CONFIG_AMBARELLA_DEWARP_VERSION_2 1 +#define IDSP_RAM_START 0x40000000 +#define CONFIG_AMBARELLA_OPENSSL_SUPPORT 1 +#define CONFIG_AMBARELLA_PAM_SUPPORT 1 +#define IAV_MEM_ROI_MATRIX_SIZE 0x0020000 +#define BUILD_AMBARELLA_NETLINK 1 +#define BUILD_AMBARELLA_SDK_ENABLE_FORTIFY_SOURCE 1 +#define IAV_ROI_NUM_FOR_IPB_FRAMES 1 +#define BUILD_AMBARELLA_UNIT_TESTS_PACKAGE 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_IMAGENET 1 +#define BUILD_AMBARELLA_MIDDLEWARE 1 +#define CONFIG_SENSOR_AR0521_MIPI 1 +#define CONFIG_AMBOOT_ENABLE_NAND 1 +#define CONFIG_DSP_LOG_START_IAVMEM 1 +#define CONFIG_SENSOR_AR0230P 1 +#define CONFIG_SENSOR_IMX334_MIPI 1 +#define DSP "" +#define CONFIG_IMGPROC_MEM_SMALL 1 +#define CONFIG_AMBARELLA_EXPAT_SUPPORT 1 +#define CONFIG_SD_SHMOO_SD_PHY 1 +#define BUILD_AMBARELLA_LW_MEDIA_AMBA_DSP 1 +#define CONFIG_SENSOR_AR0230 1 +#define CONFIG_AMBARELLA_DNSMASQ_SUPPORT 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CALIBRATION 1 +#define CONFIG_AMBARELLA_ETH0 1 +#define BUILD_OPENSSL_PERFORMANCE_UNIT_TEST 1 +#define CONFIG_AMBARELLA_IAV_GUARD_VSYNC_LOSS 1 +#define CONFIG_AMBARELLA_PREBUILD 1 +#define CONFIG_SENSOR_IMX335_MIPI 1 +#define BUILD_AMBARELLA_UNIT_TESTS_BENCHMARK 1 +#define CONFIG_AMBARELLA_IMAGE_DATA_OLD_METHOD 1 +#define CONFIG_AMBARELLA_SW_CVLIB 1 +#define BUILD_AMBARELLA_IAV 1 +#define BUILD_AMBARELLA_LW_MEDIA_FFMPEG_LIBRARY 1 +#define BUILD_AMBARELLA_LW_MEDIA_ALSA_LIBRARY 1 +#define CONFIG_NAND_ERASE_UNUSED_BLOCK 1 +#define CONFIG_CV25_HAZELNUT_SELECT_I2C1_I2C2 1 +#define CONFIG_OS08A10_MAX_4KP30 1 +#define CONFIG_IMAGE_DEVICE_INSTALL_DIR "$(AMBABUILD_TOPDIR)/prebuild/img_dev" +#define CONFIG_AMBARELLA_LIBTASN1_SUPPORT 1 +#define CONFIG_AMBARELLA_ETH0_IP_MASK "255.255.255.0" +#define CONFIG_AMBARELLA_DSP_LOG_SIZE 0x80000 +#define CONFIG_NAND_USE_FLASH_BBT 1 +#define BUILD_AMBARELLA_SDK_ENABLE_FULL_RELRO 1 +#define CONFIG_AMBARELLA_MOUNT_MNT "" +#define RPK "$(AMB_TOPDIR)/amboot/build/keys/rot_public.bin" +#define CONFIG_AMBARELLA_ASKFIRST_CONSOLE_NA 1 +#define CONFIG_AMBARELLA_FREETYPE_SUPPORT 1 +#define BUILD_AMBARELLA_MIDDLEWARE_PROC 1 +#define CONFIG_AMBARELLA_SPAWN_FCGI_SUPPORT 1 +#define CONFIG_AMBARELLA_NO_BLUETOOTH_SUPPORT 1 +#define CONFIG_DSP_FIRMWARE_GERNEIC 1 +#define CONFIG_AMBARELLA_IAV_DRAM_VOUT_NONE 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CUSTOM_IDSP 1 +#define SECONDARY "" +#define BUILD_AMBARELLA_UNIT_TESTS_CV_SSD 1 +#define BUILD_AMBARELLA_APP_UTILITY_LOAD_UCODE 1 +#define CONFIG_AMBARELLA_FCGI_SUPPORT 1 +#define CONFIG_AMBARELLA_BUSYBOX_PREBUILD 1 +#define CONFIG_AMBOOT_ENABLE_PCA953X 1 +#define CONFIG_SENSOR_IMX290_MIPI 1 +#define CONFIG_AMBARELLA_ETH0_GW_ADDRESS "10.0.0.1" +#define BUILD_AMBARELLA_UNIT_TESTS_BANDWIDTH 1 +#define FRAMEBUFFER_SIZE 0x0000000 +#define BUILD_AMBARELLA_LW_MEDIA_VIDEO_DECODER_AMBA 1 +#define CONFIG_UNIT_TEST_INSTALL_DIR "$(FAKEROOT_DIR)/usr/local/bin" +#define CONFIG_AMBARELLA_ETHTOOL_SUPPORT 1 +#define IAV_MEM_IMG_SBP_SIZE 0x0 +#define RAMDISK_VIF "" +#define LNX "$(AMB_BOARD_OUT)/rootfs/ubifs" +#define CONFIG_AMBARELLA_OPENCV_VIDEOIO_LIB_SUPPORT 1 +#define KERNEL_RAM_START 0x00280000 +#define CONFIG_AMBARELLA_FCGIWRAP_SUPPORT 1 +#define CONFIG_AMBARELLA_LIBPCRE_SUPPORT 1 +#define LEGACY_FIRMWARE_LAYOUT 1 +#define BUILD_AMBARELLA_TEXTINSERT_PACKAGE 1 +#define BUILD_AMBARELLA_DPROC_PACKAGE 1 +#define CONFIG_PIC_STATISTICS_DUMP_STREAM_NUM 0 +#define CONFIG_CPU_CORTEXA53 1 +#define CONFIG_AMBOOT_ENABLE_ETH 1 +#define CONFIG_UART_CONSOLE_115200 1 +#define ROMFS_VIF "" +#define CONFIG_AMBARELLA_ZLIB_SUPPORT 1 +#define CONFIG_EMMC_BUS_WIDTH_8 1 +#define CONFIG_AMBOOT_BD_CMDLINE "" +#define CONFIG_AMBARELLA_NGINX_SUPPORT 1 +#define AMBOOT_BLD_RAM_START 0x00000000 +#define DSP_VIF "" +#define CONFIG_SENSOR_OV4689_MIPI 1 +#define CONFIG_AMBOOT_COMMAND_SUPPORT 1 +#define BUILD_AMBARELLA_PRIVATE_LINUX_UNIT_TESTS 1 +#define CONFIG_4K_BOOT_IMAGE 1 +#define BUILD_AMBARELLA_LW_MEDIA_DEMUXER_RTSP 1 +#define CONFIG_AMBOOT_CONSOLE_UART0 1 +#define CONFIG_AMBARELLA_DSP_SYNC_FIRST_VOUT_FRAME_OFF 1 +#define AMBOOT_HEAP_SIZE 0x00080000 +#define BUILD_AMBARELLA_LW_MEDIA_LINUX_UVC 1 +#define CONFIG_AMBARELLA_BIND99_LIB_SUPPORT 1 +#define BUILD_OPENSSL_WRAPPER_LIBRARY 1 +#define ADD_VIF "" +#define CONFIG_AMBARELLA_LIBJPEG_TURBO_SUPPORT 1 +#define BUILD_AMBARELLA_APPLICATION 1 +#define CONFIG_AMBARELLA_EXT_CMD_FILE "" +#define AMBARELLA_BUILD_IAV_SYMBOL 1 +#define CONFIG_AMBARELLA_ALSA_UTILS_SUPPORT 1 +#define CONFIG_EMMC_BUS_MODE_DS 1 +#define CONFIG_DTB_SIZE 0x00008000 +#define BUILD_AMBARELLA_UNIT_TESTS_VIN 1 +#define BUILD_AMBARELLA_BSREADER_PACKAGE 1 +#define CONFIG_APP_IPCAM_CONFIG_DIR "$(FAKEROOT_DIR)/etc/ambaipcam" +#define CONFIG_AMBOOT_ENABLE_IDC 1 +#define CONFIG_AMBOOT_ENABLE_USB 1 +#define CONFIG_SENSOR_AR0237 1 +#define CONFIG_AMBARELLA_OPENCV_IMGCODECS_LIB_SUPPORT 1 +#define BUILD_AMBARELLA_LW_MEDIA_DEMUXER_MP4 1 +#define CONFIG_AMBARELLA_LIBSEPOL_SUPPORT 1 +#define CONFIG_AMBARELLA_TFTPD_SUPPORT 1 +#define CONFIG_AMBARELLA_IAV_DSP_MEM_CMA 1 +#define CONFIG_AMBARELLA_AAC_DEC_LC_SUPPORT 1 +#define CONFIG_AMBARELLA_NETTLE_SUPPORT 1 +#define CONFIG_AMBARELLA_CAVALRY_OPT_LAYERS_LIBRARY 1 +#define DSP_FASTAUDIO_SIZE 0x0000000 +#define DSP_FASTDATA_SIZE 0x0000000 +#define AMBARELLA_INITRD_PHYS 0x00800000 +#define CONFIG_AMBARELLA_IMAGE_DATA_DISTRIBUTED 1 +#define CONFIG_AMBARELLA_DBUS_SUPPORT 1 +#define AMBOOT_AUDIO_16000 1 +#define IAV_MEM_BLUR_SIZE 0x0000000 +#define CONFIG_KERNEL_MODULES_INSTALL_DIR "$(FAKEROOT_DIR)" +#define CONFIG_NAND_P2K_E128K 1 +#define BUILD_AMBARELLA_PUBLIC_LINUX_UNIT_TESTS 1 +#define BUILD_AMBARELLA_PACKAGE 1 +#define BUILD_AMBARELLA_UNIT_TESTS_IDSP 1 +#define CONFIG_SENSOR_IMX326_MIPI 1 +#define CONFIG_AMBARELLA_DBUS_GLIB_SUPPORT 1 +#define CONFIG_AMBARELLA_AICAM_PREBUILD 1 +#define CONFIG_AMBARELLA_IMAGE_DATA 1 +#define CONFIG_SENSOR_OS05A10 1 +#define CONFIG_AMBARELLA_DVE 1 +#define AMBARELLA_COMMON_MACROS 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_YOLOV2 1 +#define AMBCMA_DEFAULT_DSP_BUFFER_SIZE 0x14000000 +#define BUILD_AMBAREALLA_UTILITY_SCRIPTS_ALL 1 +#define BUILD_AMBARELLA_DATATX_PACKAGE 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_REGRESSION_SERVER 1 +#define CONFIG_BOOT_MEDIA_NAND 1 +#define BUILD_AMBARELLA_SMARTFB_PACKAGE 1 +#define CONFIG_AMBARELLA_IMAGE_METHOD 1 +#define BUILD_AMBARELLA_UNIT_TESTS 1 +#define BUILD_AMBARELLA_CAVALRY_DRV 1 +#define DSP_BSB_SIZE 0x0A00000 +#define BUILD_AMBARELLA_VIN 1 +#define BUILD_AMBARELLA_MULTI_CHAN_LUA_PARSER 1 +#define AMBOOT_BOOT_SECONDARY_CORTEX 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_NNCTRL_LIVE 1 +#define CONFIG_ARCH_CV25 1 +#define CONFIG_AMBARELLA_LIBSELINUX_SUPPORT 1 +#define BUILD_AMBARELLA_LW_MEDIA_VIDEO_RENDERER_AMBA 1 +#define CONFIG_AMBARELLA_MKFS 1 +#define RAMDISK "" +#define CONFIG_AMBARELLA_LIBBZIP2_SUPPORT 1 +#define KERNEL "$(AMB_BOARD_OUT)/kernel/Image" +#define CONFIG_AMBARELLA_ROOT_PASSWORD "" +#define IAV_MEM_INTRA_PB_SIZE 0x0 +#define CONFIG_AMBARELLA_LIBNDP_SUPPORT 1 +#define CONFIG_AMBARELLA_GLIB_NETWORKING_SUPPORT 1 +#define CONFIG_MIDDLEWARE_INSTALL_DIR "$(AMBABUILD_TOPDIR)/prebuild/img_mw" +#define BUILD_AMBARELLA_DSP 1 +#define MEMFWPROG_RAM_START 0x00400000 +#define CONFIG_AMBOOT_ENABLE_OTP 1 +#define BUILD_AES_WITH_CRYPTO_ENGINE 1 +#define CONFIG_AMBARELLA_LIBNGHTTP2_SUPPORT 1 +#define CONFIG_AMBARELLA_LIBGCRYPT_SUPPORT 1 +#define BUILD_AMBARELLA_NNCTRL_PACKAGE 1 +#define CONFIG_UTIL_LINUX_SUPPORT 1 +#define BUILD_AMBARELLA_LINUX_KERNEL 1 +#define AMBCMA_DEFAULT_PREALLOC_BUF_MAP 0x378101 +#define CONFIG_AMBARELLA_FFMPEG_SUPPORT 1 +#define SWP "" +#define CONFIG_AMBARELLA_GNUTLS_SUPPORT 1 +#define DRAM_TYPE_DDR4 1 +#define BUILD_AMBARELLA_UNIT_TESTS_NBENCH 1 +#define ROMFS "" +#define BUILD_AMBARELLA_LW_CRYPTOGRAPHY 1 +#define BUILD_AMBARELLA_HW_TIMER 1 +#define CONFIG_AMBARELLA_FREE_FONTS_SUPPORT 1 +#define CONFIG_AMBARELLA_DHCPCD_SUPPORT 1 +#define CONFIG_AMBARELLA_IW_SUPPORT 1 +#define BUILD_AMBARELLA_APP_UTILITY_DSPLOG 1 +#define CONFIG_AMBARELLA_DHCP_TOOL_DHCLIENT 1 +#define CONFIG_AMBARELLA_LIBNL_SUPPORT 1 +#define CONFIG_AMBARELLA_LIBGPG_ERROR_SUPPORT 1 +#define CONFIG_SENSOR_OS08A10 1 +#define BUILD_AMBARELLA_DIGITAL_SIGNATURE 1 +#define BUILD_AMBARELLA_PRIVATE_MODULES 1 +#define CONFIG_AMBARELLA_SMARTCAM_PREBUILD 1 +#define AMBOOT_DEFAULT_SN "" +#define CONFIG_IMX334_MIPI_1782MBPS 1 +#define CONFIG_BSP_BOARD_CV25_HAZELNUT 1 +#define BUILD_AMBARELLA_LW_MEDIA 1 +#define BUILD_AMBARELLA_SDK_ENABLE_STACK_PROTECTOR 1 +#define CONFIG_AMBARELLA_GMP_SUPPORT 1 +#define PBA "" +#define CONFIG_BOARD_VERSION_CV25S_HAZELNUT_1596_DDR4 1 +#define IAV_MEM_USR_SIZE 0x0000000 +#define CONFIG_AMBOOT_ENABLE_UART 1 +#define CONFIG_AMBARELLA_OPENCV_IMGPROC_LIB_SUPPORT 1 +#define CONFIG_FLASH_ERASE_128K 1 +#define CONFIG_AMBARELLA_HDMI 1 +#define CONFIG_AMBARELLA_START_WATCHDOG 1 +#define BUILD_AMBARELLA_CAVALRY_MEM_PACKAGE 1 +#define CONFIG_SENSOR_IMX327_MIPI 1 +#define BUILD_AMBARELLA_UNIT_TESTS_MEMTESTER 1 +#define CONFIG_AMBARELLA_LIBUNISTRING_SUPPORT 1 +#define ADC "" +#define CONFIG_AMBARELLA_LIBIDN2_SUPPORT 1 +#define BUILD_AMBARELLA_UNIT_TESTS_VOUT 1 +#define CONFIG_AMBARELLA_ROOTFS_UBIFS 1 +#define CONFIG_APP_INSTALL_DIR "$(FAKEROOT_DIR)/usr/local/bin" +#define CONFIG_BOARD_TYPE_SINGLE_SEN 1 +#define CONFIG_IMAGE_DATA_INSTALL_PATH "$(FAKEROOT_DIR)/etc/idsp" +#define BUILD_AMBARELLA_APP_UTILITY_DSP 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_YOLOV3 1 +#define IAV_MV_STREAM_NUM 1 +#define AMBOOT_STACK_SIZE 0x00008000 +#define CONFIG_AMBARELLA_SERIAL_PORT0_GETTY 1 +#define CONFIG_AMBARELLA_LIBSSH2_SUPPORT 1 +#define CONFIG_AMBARELLA_OPENCV_CORE_LIB_SUPPORT 1 +#define CONFIG_AMBARELLA_MAX_CHANNEL_NUM 2 +#define CONFIG_AMBARELLA_LIBPNG_SUPPORT 1 +#define CONFIG_AMBARELLA_LIBCAP_SUPPORT 1 +#define BUILD_AMBARELLA_UNIT_TESTS_SHMOO_V2 1 +#define CONFIG_AMBARELLA_IAV_DRAM_WARP_MEM 1 +#define CONFIG_YUV_AMBDD 1 +#define CONFIG_DRIVER_VERSION_V5 1 +#define BUILD_AMBARELLA_VOUT 1 +#define CONFIG_AMBARELLA_LIBCURL_SUPPORT 1 +#define LNX_VIF "$(AMB_TOPDIR)/amboot/vif/ubifs.info" +#define PBA_VIF "" +#define BUILD_AMBARELLA_APP_DEBUG_SANITIZE_NONE 1 +#define BUILD_AMBAREALLA_APP_UTILITY 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV_PVANET 1 +#define CONFIG_AMBARELLA_LIBFFI_SUPPORT 1 +#define BUILD_AMBARELLA_DSP_LOG 1 +#define CONFIG_SENSOR_IMX123 1 +#define SWP_VIF "" +#define CONFIG_KERNEL_DEFCONFIG_STRING "ambarella_cv25_defconfig" +#define CONFIG_AR0237_HDR_RATIO_8_TO_1 1 +#define CONFIG_FLASH_PAGE_2K 1 +#define CONFIG_OS05A10_USE_24MCLK 1 +#define BUILD_AMBARELLA_IMAGE_DEVICE_PROC 1 +#define BUILD_AMBARELLA_VPROC_PACKAGE 1 +#define CONFIG_AMBOOT_ENABLE_GPIO 1 +#define CONFIG_AMBARELLA_ETH0_ADDRESS "10.0.0.2" +#define ADC_VIF "" +#define BUILD_AMBARELLA_LW_MEDIA_MUXER_MP4 1 +#define CONFIG_AMBARELLA_NETWORKMANAGER_SUPPORT 1 +#define CONFIG_AMBARELLA_LIBATTR_SUPPORT 1 +#define BUILD_AMBAREALLA_UTILITY_SCRIPTS 1 +#define BUILD_AMBARELLA_UTILITIES_PACKAGE 1 +#define CONFIG_AMBARELLA_LUA_SUPPORT 1 +#define CONFIG_AMBARELLA_GLIB_SUPPORT 1 +#define CONFIG_AMBARELLA_SERIAL_PORT1_NA 1 +#define IAV_MEM_OVERLAY_SIZE 0x0800000 +#define AMBCMA_DEFAULT_NOFREE_PREALLOC_BUF_MAP 0x328100 +#define BUILD_AMBARELLA_IMGPROC_DRV 1 +#define SECONDARY_VIF "" +#define CONFIG_SENSOR_IMX274_MIPI 1 +#define CONFIG_AMBARELLA_ALSA_SUPPORT 1 +#define BUILD_AMBARELLA_UNIT_TESTS_IAV 1 +#define AMBOOT_DEV_AUTO_BOOT 1 +#define CONFIG_SENSOR_IMX123_MIPI 1 +#define CONFIG_AMBARELLA_DHCP_SUPPORT 1 +#define BUILD_AMBARELLA_UNIT_TESTS_CV 1 +#define CONFIG_AMBARELLA_WPA_SUPPLICANT_LATEST_SUPPORT 1 + +#endif /* AMBA_AUTO_CONFIG */ diff --git a/src/connected_layer.c b/src/connected_layer.c new file mode 100644 index 0000000..353f4e5 --- /dev/null +++ b/src/connected_layer.c @@ -0,0 +1,336 @@ +#include "connected_layer.h" +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam) +{ + int i; + layer l = {0}; + l.learning_rate_scale = 1; + l.type = CONNECTED; + + l.inputs = inputs; + l.outputs = outputs; + l.batch=batch; + l.batch_normalize = batch_normalize; + l.h = 1; + l.w = 1; + l.c = inputs; + l.out_h = 1; + l.out_w = 1; + l.out_c = outputs; + + l.output = calloc(batch*outputs, sizeof(float)); + l.delta = calloc(batch*outputs, sizeof(float)); + + l.weight_updates = calloc(inputs*outputs, sizeof(float)); + l.bias_updates = calloc(outputs, sizeof(float)); + + l.weights = calloc(outputs*inputs, sizeof(float)); + l.biases = calloc(outputs, sizeof(float)); + + l.forward = forward_connected_layer; + l.backward = backward_connected_layer; + l.update = update_connected_layer; + + //float scale = 1./sqrt(inputs); + float scale = sqrt(2./inputs); + for(i = 0; i < outputs*inputs; ++i){ + l.weights[i] = scale*rand_uniform(-1, 1); + } + + for(i = 0; i < outputs; ++i){ + l.biases[i] = 0; + } + + if(adam){ + l.m = calloc(l.inputs*l.outputs, sizeof(float)); + l.v = calloc(l.inputs*l.outputs, sizeof(float)); + l.bias_m = calloc(l.outputs, sizeof(float)); + l.scale_m = calloc(l.outputs, sizeof(float)); + l.bias_v = calloc(l.outputs, sizeof(float)); + l.scale_v = calloc(l.outputs, sizeof(float)); + } + if(batch_normalize){ + l.scales = calloc(outputs, sizeof(float)); + l.scale_updates = calloc(outputs, sizeof(float)); + for(i = 0; i < outputs; ++i){ + l.scales[i] = 1; + } + + l.mean = calloc(outputs, sizeof(float)); + l.mean_delta = calloc(outputs, sizeof(float)); + l.variance = calloc(outputs, sizeof(float)); + l.variance_delta = calloc(outputs, sizeof(float)); + + l.rolling_mean = calloc(outputs, sizeof(float)); + l.rolling_variance = calloc(outputs, sizeof(float)); + + l.x = calloc(batch*outputs, sizeof(float)); + l.x_norm = calloc(batch*outputs, sizeof(float)); + } + +#ifdef GPU + l.forward_gpu = forward_connected_layer_gpu; + l.backward_gpu = backward_connected_layer_gpu; + l.update_gpu = update_connected_layer_gpu; + + l.weights_gpu = cuda_make_array(l.weights, outputs*inputs); + l.biases_gpu = cuda_make_array(l.biases, outputs); + + l.weight_updates_gpu = cuda_make_array(l.weight_updates, outputs*inputs); + l.bias_updates_gpu = cuda_make_array(l.bias_updates, outputs); + + l.output_gpu = cuda_make_array(l.output, outputs*batch); + l.delta_gpu = cuda_make_array(l.delta, outputs*batch); + if (adam) { + l.m_gpu = cuda_make_array(0, inputs*outputs); + l.v_gpu = cuda_make_array(0, inputs*outputs); + l.bias_m_gpu = cuda_make_array(0, outputs); + l.bias_v_gpu = cuda_make_array(0, outputs); + l.scale_m_gpu = cuda_make_array(0, outputs); + l.scale_v_gpu = cuda_make_array(0, outputs); + } + + if(batch_normalize){ + l.mean_gpu = cuda_make_array(l.mean, outputs); + l.variance_gpu = cuda_make_array(l.variance, outputs); + + l.rolling_mean_gpu = cuda_make_array(l.mean, outputs); + l.rolling_variance_gpu = cuda_make_array(l.variance, outputs); + + l.mean_delta_gpu = cuda_make_array(l.mean, outputs); + l.variance_delta_gpu = cuda_make_array(l.variance, outputs); + + l.scales_gpu = cuda_make_array(l.scales, outputs); + l.scale_updates_gpu = cuda_make_array(l.scale_updates, outputs); + + l.x_gpu = cuda_make_array(l.output, l.batch*outputs); + l.x_norm_gpu = cuda_make_array(l.output, l.batch*outputs); +#ifdef CUDNN + cudnnCreateTensorDescriptor(&l.normTensorDesc); + cudnnCreateTensorDescriptor(&l.dstTensorDesc); + cudnnSetTensor4dDescriptor(l.dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l.batch, l.out_c, l.out_h, l.out_w); + cudnnSetTensor4dDescriptor(l.normTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l.out_c, 1, 1); +#endif + } +#endif + l.activation = activation; + fprintf(stderr, "connected %4d -> %4d\n", inputs, outputs); + return l; +} + +void update_connected_layer(layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + axpy_cpu(l.outputs, learning_rate/batch, l.bias_updates, 1, l.biases, 1); + scal_cpu(l.outputs, momentum, l.bias_updates, 1); + + if(l.batch_normalize){ + axpy_cpu(l.outputs, learning_rate/batch, l.scale_updates, 1, l.scales, 1); + scal_cpu(l.outputs, momentum, l.scale_updates, 1); + } + + axpy_cpu(l.inputs*l.outputs, -decay*batch, l.weights, 1, l.weight_updates, 1); + axpy_cpu(l.inputs*l.outputs, learning_rate/batch, l.weight_updates, 1, l.weights, 1); + scal_cpu(l.inputs*l.outputs, momentum, l.weight_updates, 1); +} + +void forward_connected_layer(layer l, network net) +{ + fill_cpu(l.outputs*l.batch, 0, l.output, 1); + int m = l.batch; + int k = l.inputs; + int n = l.outputs; + float *a = net.input; + float *b = l.weights; + float *c = l.output; + gemm(0,1,m,n,k,1,a,k,b,k,1,c,n); + if(l.batch_normalize){ + forward_batchnorm_layer(l, net); + } else { + add_bias(l.output, l.biases, l.batch, l.outputs, 1); + } + activate_array(l.output, l.outputs*l.batch, l.activation); +} + +void backward_connected_layer(layer l, network net) +{ + gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); + + if(l.batch_normalize){ + backward_batchnorm_layer(l, net); + } else { + backward_bias(l.bias_updates, l.delta, l.batch, l.outputs, 1); + } + + int m = l.outputs; + int k = l.batch; + int n = l.inputs; + float *a = l.delta; + float *b = net.input; + float *c = l.weight_updates; + gemm(1,0,m,n,k,1,a,m,b,n,1,c,n); + + m = l.batch; + k = l.outputs; + n = l.inputs; + + a = l.delta; + b = l.weights; + c = net.delta; + + if(c) gemm(0,0,m,n,k,1,a,k,b,n,1,c,n); +} + + +void denormalize_connected_layer(layer l) +{ + int i, j; + for(i = 0; i < l.outputs; ++i){ + float scale = l.scales[i]/sqrt(l.rolling_variance[i] + .000001); + for(j = 0; j < l.inputs; ++j){ + l.weights[i*l.inputs + j] *= scale; + } + l.biases[i] -= l.rolling_mean[i] * scale; + l.scales[i] = 1; + l.rolling_mean[i] = 0; + l.rolling_variance[i] = 1; + } +} + + +void statistics_connected_layer(layer l) +{ + if(l.batch_normalize){ + printf("Scales "); + print_statistics(l.scales, l.outputs); + /* + printf("Rolling Mean "); + print_statistics(l.rolling_mean, l.outputs); + printf("Rolling Variance "); + print_statistics(l.rolling_variance, l.outputs); + */ + } + printf("Biases "); + print_statistics(l.biases, l.outputs); + printf("Weights "); + print_statistics(l.weights, l.outputs); +} + +#ifdef GPU + +void pull_connected_layer(layer l) +{ + cuda_pull_array(l.weights_gpu, l.weights, l.inputs*l.outputs); + cuda_pull_array(l.biases_gpu, l.biases, l.outputs); + cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.inputs*l.outputs); + cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.outputs); + if (l.batch_normalize){ + cuda_pull_array(l.scales_gpu, l.scales, l.outputs); + cuda_pull_array(l.rolling_mean_gpu, l.rolling_mean, l.outputs); + cuda_pull_array(l.rolling_variance_gpu, l.rolling_variance, l.outputs); + } +} + +void push_connected_layer(layer l) +{ + cuda_push_array(l.weights_gpu, l.weights, l.inputs*l.outputs); + cuda_push_array(l.biases_gpu, l.biases, l.outputs); + cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.inputs*l.outputs); + cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.outputs); + if (l.batch_normalize){ + cuda_push_array(l.scales_gpu, l.scales, l.outputs); + cuda_push_array(l.rolling_mean_gpu, l.rolling_mean, l.outputs); + cuda_push_array(l.rolling_variance_gpu, l.rolling_variance, l.outputs); + } +} + +void update_connected_layer_gpu(layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + if(a.adam){ + adam_update_gpu(l.weights_gpu, l.weight_updates_gpu, l.m_gpu, l.v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.inputs*l.outputs, batch, a.t); + adam_update_gpu(l.biases_gpu, l.bias_updates_gpu, l.bias_m_gpu, l.bias_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.outputs, batch, a.t); + if(l.scales_gpu){ + adam_update_gpu(l.scales_gpu, l.scale_updates_gpu, l.scale_m_gpu, l.scale_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.outputs, batch, a.t); + } + }else{ + axpy_gpu(l.outputs, learning_rate/batch, l.bias_updates_gpu, 1, l.biases_gpu, 1); + scal_gpu(l.outputs, momentum, l.bias_updates_gpu, 1); + + if(l.batch_normalize){ + axpy_gpu(l.outputs, learning_rate/batch, l.scale_updates_gpu, 1, l.scales_gpu, 1); + scal_gpu(l.outputs, momentum, l.scale_updates_gpu, 1); + } + + axpy_gpu(l.inputs*l.outputs, -decay*batch, l.weights_gpu, 1, l.weight_updates_gpu, 1); + axpy_gpu(l.inputs*l.outputs, learning_rate/batch, l.weight_updates_gpu, 1, l.weights_gpu, 1); + scal_gpu(l.inputs*l.outputs, momentum, l.weight_updates_gpu, 1); + } +} + +void forward_connected_layer_gpu(layer l, network net) +{ + fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1); + + int m = l.batch; + int k = l.inputs; + int n = l.outputs; + float * a = net.input_gpu; + float * b = l.weights_gpu; + float * c = l.output_gpu; + gemm_gpu(0,1,m,n,k,1,a,k,b,k,1,c,n); + + if (l.batch_normalize) { + forward_batchnorm_layer_gpu(l, net); + } else { + add_bias_gpu(l.output_gpu, l.biases_gpu, l.batch, l.outputs, 1); + } + activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation); +} + +void backward_connected_layer_gpu(layer l, network net) +{ + constrain_gpu(l.outputs*l.batch, 1, l.delta_gpu, 1); + gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); + if(l.batch_normalize){ + backward_batchnorm_layer_gpu(l, net); + } else { + backward_bias_gpu(l.bias_updates_gpu, l.delta_gpu, l.batch, l.outputs, 1); + } + + int m = l.outputs; + int k = l.batch; + int n = l.inputs; + float * a = l.delta_gpu; + float * b = net.input_gpu; + float * c = l.weight_updates_gpu; + gemm_gpu(1,0,m,n,k,1,a,m,b,n,1,c,n); + + m = l.batch; + k = l.outputs; + n = l.inputs; + + a = l.delta_gpu; + b = l.weights_gpu; + c = net.delta_gpu; + + if(c) gemm_gpu(0,0,m,n,k,1,a,k,b,n,1,c,n); +} +#endif diff --git a/src/connected_layer.h b/src/connected_layer.h new file mode 100644 index 0000000..dc0601f --- /dev/null +++ b/src/connected_layer.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef CONNECTED_LAYER_H +#define CONNECTED_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "layer.h" +#include "network.h" + +layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam); + +void forward_connected_layer(layer l, network net); +void backward_connected_layer(layer l, network net); +void update_connected_layer(layer l, update_args a); + +#ifdef GPU +void forward_connected_layer_gpu(layer l, network net); +void backward_connected_layer_gpu(layer l, network net); +void update_connected_layer_gpu(layer l, update_args a); +void push_connected_layer(layer l); +void pull_connected_layer(layer l); +#endif + +#endif + diff --git a/src/convolutional_kernels.cu b/src/convolutional_kernels.cu new file mode 100644 index 0000000..4a1047b --- /dev/null +++ b/src/convolutional_kernels.cu @@ -0,0 +1,330 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "gemm.h" +#include "blas.h" +#include "im2col.h" +#include "col2im.h" +#include "utils.h" +#include "cuda.h" +} + +__global__ void binarize_kernel(float *x, int n, float *binary) +{ + int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (i >= n) return; + binary[i] = (x[i] >= 0) ? 1 : -1; +} + +void binarize_gpu(float *x, int n, float *binary) +{ + binarize_kernel<<<cuda_gridsize(n), BLOCK>>>(x, n, binary); + check_error(cudaPeekAtLastError()); +} + +__global__ void binarize_input_kernel(float *input, int n, int size, float *binary) +{ + int s = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (s >= size) return; + int i = 0; + float mean = 0; + for(i = 0; i < n; ++i){ + mean += fabsf(input[i*size + s]); + } + mean = mean / n; + for(i = 0; i < n; ++i){ + binary[i*size + s] = (input[i*size + s] > 0) ? mean : -mean; + } +} + +void binarize_input_gpu(float *input, int n, int size, float *binary) +{ + binarize_input_kernel<<<cuda_gridsize(size), BLOCK>>>(input, n, size, binary); + check_error(cudaPeekAtLastError()); +} + + +__global__ void binarize_weights_kernel(float *weights, int n, int size, float *binary) +{ + int f = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if (f >= n) return; + int i = 0; + float mean = 0; + for(i = 0; i < size; ++i){ + mean += fabsf(weights[f*size + i]); + } + mean = mean / size; + for(i = 0; i < size; ++i){ + binary[f*size + i] = (weights[f*size + i] > 0) ? mean : -mean; + //binary[f*size + i] = weights[f*size + i]; + } +} + +void binarize_weights_gpu(float *weights, int n, int size, float *binary) +{ + binarize_weights_kernel<<<cuda_gridsize(n), BLOCK>>>(weights, n, size, binary); + check_error(cudaPeekAtLastError()); +} + +void forward_convolutional_layer_gpu(convolutional_layer l, network net) +{ + fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1); + if(l.binary){ + binarize_weights_gpu(l.weights_gpu, l.n, l.c/l.groups*l.size*l.size, l.binary_weights_gpu); + swap_binary(&l); + } + + if(l.xnor){ + binarize_weights_gpu(l.weights_gpu, l.n, l.c/l.groups*l.size*l.size, l.binary_weights_gpu); + swap_binary(&l); + binarize_gpu(net.input_gpu, l.c*l.h*l.w*l.batch, l.binary_input_gpu); + net.input_gpu = l.binary_input_gpu; + } + +#ifdef CUDNN + float one = 1; + cudnnConvolutionForward(cudnn_handle(), + &one, + l.srcTensorDesc, + net.input_gpu, + l.weightDesc, + l.weights_gpu, + l.convDesc, + l.fw_algo, + net.workspace, + l.workspace_size, + &one, + l.dstTensorDesc, + l.output_gpu); + +#else + int i, j; + int m = l.n/l.groups; + int k = l.size*l.size*l.c/l.groups; + int n = l.out_w*l.out_h; + for(i = 0; i < l.batch; ++i){ + for(j = 0; j < l.groups; ++j){ + float *a = l.weights_gpu + j*l.nweights/l.groups; + float *b = net.workspace; + float *c = l.output_gpu + (i*l.groups + j)*n*m; + float *im = net.input_gpu + (i*l.groups + j)*l.c/l.groups*l.h*l.w; + + if (l.size == 1){ + b = im; + } else { + im2col_gpu(im, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, b); + } + gemm_gpu(0,0,m,n,k,1,a,k,b,n,1,c,n); + } + } +#endif + + if (l.batch_normalize) { + forward_batchnorm_layer_gpu(l, net); + } else { + add_bias_gpu(l.output_gpu, l.biases_gpu, l.batch, l.n, l.out_w*l.out_h); + } + + activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation); + //if(l.dot > 0) dot_error_gpu(l); + if(l.binary || l.xnor) swap_binary(&l); +} + +__global__ void smooth_kernel(float *x, int n, int w, int h, int c, int size, float rate, float *delta) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= n) return; + + int j = id % w; + id /= w; + int i = id % h; + id /= h; + int k = id % c; + id /= c; + int b = id; + + int w_offset = -(size/2.f); + int h_offset = -(size/2.f); + + int out_index = j + w*(i + h*(k + c*b)); + int l, m; + for(l = 0; l < size; ++l){ + for(m = 0; m < size; ++m){ + int cur_h = h_offset + i + l; + int cur_w = w_offset + j + m; + int index = cur_w + w*(cur_h + h*(k + b*c)); + int valid = (cur_h >= 0 && cur_h < h && + cur_w >= 0 && cur_w < w); + delta[out_index] += valid ? rate*(x[index] - x[out_index]) : 0; + } + } +} + +extern "C" void smooth_layer(layer l, int size, float rate) +{ + int h = l.out_h; + int w = l.out_w; + int c = l.out_c; + + size_t n = h*w*c*l.batch; + + smooth_kernel<<<cuda_gridsize(n), BLOCK>>>(l.output_gpu, n, l.w, l.h, l.c, size, rate, l.delta_gpu); + check_error(cudaPeekAtLastError()); +} + +void backward_convolutional_layer_gpu(convolutional_layer l, network net) +{ + if(l.smooth){ + smooth_layer(l, 5, l.smooth); + } + //constrain_gpu(l.outputs*l.batch, 1, l.delta_gpu, 1); + gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); + + + if(l.batch_normalize){ + backward_batchnorm_layer_gpu(l, net); + } else { + backward_bias_gpu(l.bias_updates_gpu, l.delta_gpu, l.batch, l.n, l.out_w*l.out_h); + } + float *original_input = net.input_gpu; + + if(l.xnor) net.input_gpu = l.binary_input_gpu; +#ifdef CUDNN + float one = 1; + cudnnConvolutionBackwardFilter(cudnn_handle(), + &one, + l.srcTensorDesc, + net.input_gpu, + l.ddstTensorDesc, + l.delta_gpu, + l.convDesc, + l.bf_algo, + net.workspace, + l.workspace_size, + &one, + l.dweightDesc, + l.weight_updates_gpu); + + if(net.delta_gpu){ + if(l.binary || l.xnor) swap_binary(&l); + cudnnConvolutionBackwardData(cudnn_handle(), + &one, + l.weightDesc, + l.weights_gpu, + l.ddstTensorDesc, + l.delta_gpu, + l.convDesc, + l.bd_algo, + net.workspace, + l.workspace_size, + &one, + l.dsrcTensorDesc, + net.delta_gpu); + if(l.binary || l.xnor) swap_binary(&l); + if(l.xnor) gradient_array_gpu(original_input, l.batch*l.c*l.h*l.w, HARDTAN, net.delta_gpu); + } + +#else + int m = l.n/l.groups; + int n = l.size*l.size*l.c/l.groups; + int k = l.out_w*l.out_h; + + int i, j; + for(i = 0; i < l.batch; ++i){ + for(j = 0; j < l.groups; ++j){ + float *a = l.delta_gpu + (i*l.groups + j)*m*k; + float *b = net.workspace; + float *c = l.weight_updates_gpu + j*l.nweights/l.groups; + + float *im = net.input_gpu+(i*l.groups + j)*l.c/l.groups*l.h*l.w; + float *imd = net.delta_gpu+(i*l.groups + j)*l.c/l.groups*l.h*l.w; + + im2col_gpu(im, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, b); + gemm_gpu(0,1,m,n,k,1,a,k,b,k,1,c,n); + + if (net.delta_gpu) { + if (l.binary || l.xnor) swap_binary(&l); + a = l.weights_gpu + j*l.nweights/l.groups; + b = l.delta_gpu + (i*l.groups + j)*m*k; + c = net.workspace; + if (l.size == 1) { + c = imd; + } + + gemm_gpu(1,0,n,k,m,1,a,n,b,k,0,c,k); + + if (l.size != 1) { + col2im_gpu(net.workspace, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, imd); + } + if(l.binary || l.xnor) { + swap_binary(&l); + } + } + if(l.xnor) gradient_array_gpu(original_input + i*l.c*l.h*l.w, l.c*l.h*l.w, HARDTAN, net.delta_gpu + i*l.c*l.h*l.w); + } + } +#endif +} + +void pull_convolutional_layer(layer l) +{ + cuda_pull_array(l.weights_gpu, l.weights, l.nweights); + cuda_pull_array(l.biases_gpu, l.biases, l.n); + cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.nweights); + cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.n); + if (l.batch_normalize){ + cuda_pull_array(l.scales_gpu, l.scales, l.n); + cuda_pull_array(l.rolling_mean_gpu, l.rolling_mean, l.n); + cuda_pull_array(l.rolling_variance_gpu, l.rolling_variance, l.n); + } +} + +void push_convolutional_layer(layer l) +{ + cuda_push_array(l.weights_gpu, l.weights, l.nweights); + cuda_push_array(l.biases_gpu, l.biases, l.n); + cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.nweights); + cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.n); + if (l.batch_normalize){ + cuda_push_array(l.scales_gpu, l.scales, l.n); + cuda_push_array(l.rolling_mean_gpu, l.rolling_mean, l.n); + cuda_push_array(l.rolling_variance_gpu, l.rolling_variance, l.n); + } +} + +void update_convolutional_layer_gpu(layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + + if(a.adam){ + adam_update_gpu(l.weights_gpu, l.weight_updates_gpu, l.m_gpu, l.v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.nweights, batch, a.t); + adam_update_gpu(l.biases_gpu, l.bias_updates_gpu, l.bias_m_gpu, l.bias_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.n, batch, a.t); + if(l.scales_gpu){ + adam_update_gpu(l.scales_gpu, l.scale_updates_gpu, l.scale_m_gpu, l.scale_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.n, batch, a.t); + } + }else{ + axpy_gpu(l.nweights, -decay*batch, l.weights_gpu, 1, l.weight_updates_gpu, 1); + axpy_gpu(l.nweights, learning_rate/batch, l.weight_updates_gpu, 1, l.weights_gpu, 1); + scal_gpu(l.nweights, momentum, l.weight_updates_gpu, 1); + + axpy_gpu(l.n, learning_rate/batch, l.bias_updates_gpu, 1, l.biases_gpu, 1); + scal_gpu(l.n, momentum, l.bias_updates_gpu, 1); + + if(l.scales_gpu){ + axpy_gpu(l.n, learning_rate/batch, l.scale_updates_gpu, 1, l.scales_gpu, 1); + scal_gpu(l.n, momentum, l.scale_updates_gpu, 1); + } + } + if(l.clip){ + constrain_gpu(l.nweights, l.clip, l.weights_gpu, 1); + } +} + + diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c new file mode 100644 index 0000000..0e9b276 --- /dev/null +++ b/src/convolutional_layer.c @@ -0,0 +1,779 @@ +#include "convolutional_layer.h" +#include "utils.h" +#include "batchnorm_layer.h" +#include "im2col.h" +#include "col2im.h" +#include "blas.h" +#include "gemm.h" +#include <stdio.h> +#include <time.h> + +#ifdef AI2 +#include "xnor_layer.h" +#endif + +void swap_binary(convolutional_layer *l) +{ + float *swap = l->weights; + l->weights = l->binary_weights; + l->binary_weights = swap; + +#ifdef GPU + swap = l->weights_gpu; + l->weights_gpu = l->binary_weights_gpu; + l->binary_weights_gpu = swap; +#endif +} + +void binarize_weights(float *weights, int n, int size, float *binary) +{ + int i, f; + for(f = 0; f < n; ++f){ + float mean = 0; + for(i = 0; i < size; ++i){ + mean += fabs(weights[f*size + i]); + } + mean = mean / size; + for(i = 0; i < size; ++i){ + binary[f*size + i] = (weights[f*size + i] > 0) ? mean : -mean; + } + } +} + +void binarize_cpu(float *input, int n, float *binary) +{ + int i; + for(i = 0; i < n; ++i){ + binary[i] = (input[i] > 0) ? 1 : -1; + } +} + +void binarize_input(float *input, int n, int size, float *binary) +{ + int i, s; + for(s = 0; s < size; ++s){ + float mean = 0; + for(i = 0; i < n; ++i){ + mean += fabs(input[i*size + s]); + } + mean = mean / n; + for(i = 0; i < n; ++i){ + binary[i*size + s] = (input[i*size + s] > 0) ? mean : -mean; + } + } +} + +int convolutional_out_height(convolutional_layer l) +{ + return (l.h + 2*l.pad - l.size) / l.stride + 1; +} + +int convolutional_out_width(convolutional_layer l) +{ + return (l.w + 2*l.pad - l.size) / l.stride + 1; +} + +image get_convolutional_image(convolutional_layer l) +{ + return float_to_image(l.out_w,l.out_h,l.out_c,l.output); +} + +image get_convolutional_delta(convolutional_layer l) +{ + return float_to_image(l.out_w,l.out_h,l.out_c,l.delta); +} + +static size_t get_workspace_size(layer l){ +#ifdef CUDNN + if(gpu_index >= 0){ + size_t most = 0; + size_t s = 0; + cudnnGetConvolutionForwardWorkspaceSize(cudnn_handle(), + l.srcTensorDesc, + l.weightDesc, + l.convDesc, + l.dstTensorDesc, + l.fw_algo, + &s); + if (s > most) most = s; + cudnnGetConvolutionBackwardFilterWorkspaceSize(cudnn_handle(), + l.srcTensorDesc, + l.ddstTensorDesc, + l.convDesc, + l.dweightDesc, + l.bf_algo, + &s); + if (s > most) most = s; + cudnnGetConvolutionBackwardDataWorkspaceSize(cudnn_handle(), + l.weightDesc, + l.ddstTensorDesc, + l.convDesc, + l.dsrcTensorDesc, + l.bd_algo, + &s); + if (s > most) most = s; + return most; + } +#endif + return (size_t)l.out_h*l.out_w*l.size*l.size*l.c/l.groups*sizeof(float); +} + +#ifdef GPU +#ifdef CUDNN +void cudnn_convolutional_setup(layer *l) +{ + cudnnSetTensor4dDescriptor(l->dsrcTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l->batch, l->c, l->h, l->w); + cudnnSetTensor4dDescriptor(l->ddstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l->batch, l->out_c, l->out_h, l->out_w); + + cudnnSetTensor4dDescriptor(l->srcTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l->batch, l->c, l->h, l->w); + cudnnSetTensor4dDescriptor(l->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l->batch, l->out_c, l->out_h, l->out_w); + cudnnSetTensor4dDescriptor(l->normTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l->out_c, 1, 1); + + cudnnSetFilter4dDescriptor(l->dweightDesc, CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, l->n, l->c/l->groups, l->size, l->size); + cudnnSetFilter4dDescriptor(l->weightDesc, CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, l->n, l->c/l->groups, l->size, l->size); + #if CUDNN_MAJOR >= 6 + cudnnSetConvolution2dDescriptor(l->convDesc, l->pad, l->pad, l->stride, l->stride, 1, 1, CUDNN_CROSS_CORRELATION, CUDNN_DATA_FLOAT); + #else + cudnnSetConvolution2dDescriptor(l->convDesc, l->pad, l->pad, l->stride, l->stride, 1, 1, CUDNN_CROSS_CORRELATION); + #endif + + #if CUDNN_MAJOR >= 7 + cudnnSetConvolutionGroupCount(l->convDesc, l->groups); + #else + if(l->groups > 1){ + error("CUDNN < 7 doesn't support groups, please upgrade!"); + } + #endif + + cudnnGetConvolutionForwardAlgorithm(cudnn_handle(), + l->srcTensorDesc, + l->weightDesc, + l->convDesc, + l->dstTensorDesc, + CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT, + 2000000000, + &l->fw_algo); + cudnnGetConvolutionBackwardDataAlgorithm(cudnn_handle(), + l->weightDesc, + l->ddstTensorDesc, + l->convDesc, + l->dsrcTensorDesc, + CUDNN_CONVOLUTION_BWD_DATA_SPECIFY_WORKSPACE_LIMIT, + 2000000000, + &l->bd_algo); + cudnnGetConvolutionBackwardFilterAlgorithm(cudnn_handle(), + l->srcTensorDesc, + l->ddstTensorDesc, + l->convDesc, + l->dweightDesc, + CUDNN_CONVOLUTION_BWD_FILTER_SPECIFY_WORKSPACE_LIMIT, + 2000000000, + &l->bf_algo); +} +#endif +#endif + +convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int groups, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam) +{ + int i; + convolutional_layer l = {0}; + l.type = CONVOLUTIONAL; + + l.groups = groups; + l.h = h; + l.w = w; + l.c = c; + l.n = n; + l.binary = binary; + l.xnor = xnor; + l.batch = batch; + l.stride = stride; + l.size = size; + l.pad = padding; + l.batch_normalize = batch_normalize; + + l.weights = calloc(c/groups*n*size*size, sizeof(float)); + l.weight_updates = calloc(c/groups*n*size*size, sizeof(float)); + + l.biases = calloc(n, sizeof(float)); + l.bias_updates = calloc(n, sizeof(float)); + + l.nweights = c/groups*n*size*size; + l.nbiases = n; + + // float scale = 1./sqrt(size*size*c); + float scale = sqrt(2./(size*size*c/l.groups)); + //printf("convscale %f\n", scale); + //scale = .02; + //for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_uniform(-1, 1); + for(i = 0; i < l.nweights; ++i) l.weights[i] = scale*rand_normal(); + int out_w = convolutional_out_width(l); + int out_h = convolutional_out_height(l); + l.out_h = out_h; + l.out_w = out_w; + l.out_c = n; + l.outputs = l.out_h * l.out_w * l.out_c; + l.inputs = l.w * l.h * l.c; + + l.output = calloc(l.batch*l.outputs, sizeof(float)); + l.delta = calloc(l.batch*l.outputs, sizeof(float)); + + l.forward = forward_convolutional_layer; + l.backward = backward_convolutional_layer; + l.update = update_convolutional_layer; + if(binary){ + l.binary_weights = calloc(l.nweights, sizeof(float)); + l.cweights = calloc(l.nweights, sizeof(char)); + l.scales = calloc(n, sizeof(float)); + } + if(xnor){ + l.binary_weights = calloc(l.nweights, sizeof(float)); + l.binary_input = calloc(l.inputs*l.batch, sizeof(float)); + } + + if(batch_normalize){ + l.scales = calloc(n, sizeof(float)); + l.scale_updates = calloc(n, sizeof(float)); + for(i = 0; i < n; ++i){ + l.scales[i] = 1; + } + + l.mean = calloc(n, sizeof(float)); + l.variance = calloc(n, sizeof(float)); + + l.mean_delta = calloc(n, sizeof(float)); + l.variance_delta = calloc(n, sizeof(float)); + + l.rolling_mean = calloc(n, sizeof(float)); + l.rolling_variance = calloc(n, sizeof(float)); + l.x = calloc(l.batch*l.outputs, sizeof(float)); + l.x_norm = calloc(l.batch*l.outputs, sizeof(float)); + } + if(adam){ + l.m = calloc(l.nweights, sizeof(float)); + l.v = calloc(l.nweights, sizeof(float)); + l.bias_m = calloc(n, sizeof(float)); + l.scale_m = calloc(n, sizeof(float)); + l.bias_v = calloc(n, sizeof(float)); + l.scale_v = calloc(n, sizeof(float)); + } + +#ifdef GPU + l.forward_gpu = forward_convolutional_layer_gpu; + l.backward_gpu = backward_convolutional_layer_gpu; + l.update_gpu = update_convolutional_layer_gpu; + + if(gpu_index >= 0){ + if (adam) { + l.m_gpu = cuda_make_array(l.m, l.nweights); + l.v_gpu = cuda_make_array(l.v, l.nweights); + l.bias_m_gpu = cuda_make_array(l.bias_m, n); + l.bias_v_gpu = cuda_make_array(l.bias_v, n); + l.scale_m_gpu = cuda_make_array(l.scale_m, n); + l.scale_v_gpu = cuda_make_array(l.scale_v, n); + } + + l.weights_gpu = cuda_make_array(l.weights, l.nweights); + l.weight_updates_gpu = cuda_make_array(l.weight_updates, l.nweights); + + l.biases_gpu = cuda_make_array(l.biases, n); + l.bias_updates_gpu = cuda_make_array(l.bias_updates, n); + + l.delta_gpu = cuda_make_array(l.delta, l.batch*out_h*out_w*n); + l.output_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + + if(binary){ + l.binary_weights_gpu = cuda_make_array(l.weights, l.nweights); + } + if(xnor){ + l.binary_weights_gpu = cuda_make_array(l.weights, l.nweights); + l.binary_input_gpu = cuda_make_array(0, l.inputs*l.batch); + } + + if(batch_normalize){ + l.mean_gpu = cuda_make_array(l.mean, n); + l.variance_gpu = cuda_make_array(l.variance, n); + + l.rolling_mean_gpu = cuda_make_array(l.mean, n); + l.rolling_variance_gpu = cuda_make_array(l.variance, n); + + l.mean_delta_gpu = cuda_make_array(l.mean, n); + l.variance_delta_gpu = cuda_make_array(l.variance, n); + + l.scales_gpu = cuda_make_array(l.scales, n); + l.scale_updates_gpu = cuda_make_array(l.scale_updates, n); + + l.x_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + l.x_norm_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + } +#ifdef CUDNN + cudnnCreateTensorDescriptor(&l.normTensorDesc); + cudnnCreateTensorDescriptor(&l.srcTensorDesc); + cudnnCreateTensorDescriptor(&l.dstTensorDesc); + cudnnCreateFilterDescriptor(&l.weightDesc); + cudnnCreateTensorDescriptor(&l.dsrcTensorDesc); + cudnnCreateTensorDescriptor(&l.ddstTensorDesc); + cudnnCreateFilterDescriptor(&l.dweightDesc); + cudnnCreateConvolutionDescriptor(&l.convDesc); + cudnn_convolutional_setup(&l); +#endif + } +#endif + l.workspace_size = get_workspace_size(l); + l.activation = activation; + + fprintf(stderr, "conv %5d %2d x%2d /%2d %4d x%4d x%4d -> %4d x%4d x%4d %5.3f BFLOPs\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c, (2.0 * l.n * l.size*l.size*l.c/l.groups * l.out_h*l.out_w)/1000000000.); + + return l; +} + +void denormalize_convolutional_layer(convolutional_layer l) +{ + int i, j; + for(i = 0; i < l.n; ++i){ + float scale = l.scales[i]/sqrt(l.rolling_variance[i] + .00001); + for(j = 0; j < l.c/l.groups*l.size*l.size; ++j){ + l.weights[i*l.c/l.groups*l.size*l.size + j] *= scale; + } + l.biases[i] -= l.rolling_mean[i] * scale; + l.scales[i] = 1; + l.rolling_mean[i] = 0; + l.rolling_variance[i] = 1; + } +} + +/* +void test_convolutional_layer() +{ + convolutional_layer l = make_convolutional_layer(1, 5, 5, 3, 2, 5, 2, 1, LEAKY, 1, 0, 0, 0); + l.batch_normalize = 1; + float data[] = {1,1,1,1,1, + 1,1,1,1,1, + 1,1,1,1,1, + 1,1,1,1,1, + 1,1,1,1,1, + 2,2,2,2,2, + 2,2,2,2,2, + 2,2,2,2,2, + 2,2,2,2,2, + 2,2,2,2,2, + 3,3,3,3,3, + 3,3,3,3,3, + 3,3,3,3,3, + 3,3,3,3,3, + 3,3,3,3,3}; + //net.input = data; + //forward_convolutional_layer(l); +} +*/ + +void resize_convolutional_layer(convolutional_layer *l, int w, int h) +{ + l->w = w; + l->h = h; + int out_w = convolutional_out_width(*l); + int out_h = convolutional_out_height(*l); + + l->out_w = out_w; + l->out_h = out_h; + + l->outputs = l->out_h * l->out_w * l->out_c; + l->inputs = l->w * l->h * l->c; + + l->output = realloc(l->output, l->batch*l->outputs*sizeof(float)); + l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float)); + if(l->batch_normalize){ + l->x = realloc(l->x, l->batch*l->outputs*sizeof(float)); + l->x_norm = realloc(l->x_norm, l->batch*l->outputs*sizeof(float)); + } + +#ifdef GPU + cuda_free(l->delta_gpu); + cuda_free(l->output_gpu); + + l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs); + l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs); + + if(l->batch_normalize){ + cuda_free(l->x_gpu); + cuda_free(l->x_norm_gpu); + + l->x_gpu = cuda_make_array(l->output, l->batch*l->outputs); + l->x_norm_gpu = cuda_make_array(l->output, l->batch*l->outputs); + } +#ifdef CUDNN + cudnn_convolutional_setup(l); +#endif +#endif + l->workspace_size = get_workspace_size(*l); +} + +void add_bias(float *output, float *biases, int batch, int n, int size) +{ + int i,j,b; + for(b = 0; b < batch; ++b){ + for(i = 0; i < n; ++i){ + for(j = 0; j < size; ++j){ + output[(b*n + i)*size + j] += biases[i]; + } + } + } +} + +void scale_bias(float *output, float *scales, int batch, int n, int size) +{ + int i,j,b; + for(b = 0; b < batch; ++b){ + for(i = 0; i < n; ++i){ + for(j = 0; j < size; ++j){ + output[(b*n + i)*size + j] *= scales[i]; + } + } + } +} + +void backward_bias(float *bias_updates, float *delta, int batch, int n, int size) +{ + int i,b; + for(b = 0; b < batch; ++b){ + for(i = 0; i < n; ++i){ + bias_updates[i] += sum_array(delta+size*(i+b*n), size); + } + } +} + +void forward_convolutional_layer(convolutional_layer l, network net) +{ + int i, j; + + fill_cpu(l.outputs*l.batch, 0, l.output, 1); + + if(l.xnor){ + binarize_weights(l.weights, l.n, l.c/l.groups*l.size*l.size, l.binary_weights); + swap_binary(&l); + binarize_cpu(net.input, l.c*l.h*l.w*l.batch, l.binary_input); + net.input = l.binary_input; + } + + int m = l.n/l.groups; + int k = l.size*l.size*l.c/l.groups; + int n = l.out_w*l.out_h; + for(i = 0; i < l.batch; ++i){ + for(j = 0; j < l.groups; ++j){ + float *a = l.weights + j*l.nweights/l.groups; + float *b = net.workspace; + float *c = l.output + (i*l.groups + j)*n*m; + float *im = net.input + (i*l.groups + j)*l.c/l.groups*l.h*l.w; + + if (l.size == 1) { + b = im; + } else { + im2col_cpu(im, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, b); + } + gemm(0,0,m,n,k,1,a,k,b,n,1,c,n); + } + } + + if(l.batch_normalize){ + forward_batchnorm_layer(l, net); + } else { + add_bias(l.output, l.biases, l.batch, l.n, l.out_h*l.out_w); + } + + activate_array(l.output, l.outputs*l.batch, l.activation); + if(l.binary || l.xnor) swap_binary(&l); +} + +void backward_convolutional_layer(convolutional_layer l, network net) +{ + int i, j; + int m = l.n/l.groups; + int n = l.size*l.size*l.c/l.groups; + int k = l.out_w*l.out_h; + + gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); + + if(l.batch_normalize){ + backward_batchnorm_layer(l, net); + } else { + backward_bias(l.bias_updates, l.delta, l.batch, l.n, k); + } + + for(i = 0; i < l.batch; ++i){ + for(j = 0; j < l.groups; ++j){ + float *a = l.delta + (i*l.groups + j)*m*k; + float *b = net.workspace; + float *c = l.weight_updates + j*l.nweights/l.groups; + + float *im = net.input + (i*l.groups + j)*l.c/l.groups*l.h*l.w; + float *imd = net.delta + (i*l.groups + j)*l.c/l.groups*l.h*l.w; + + if(l.size == 1){ + b = im; + } else { + im2col_cpu(im, l.c/l.groups, l.h, l.w, + l.size, l.stride, l.pad, b); + } + + gemm(0,1,m,n,k,1,a,k,b,k,1,c,n); + + if (net.delta) { + a = l.weights + j*l.nweights/l.groups; + b = l.delta + (i*l.groups + j)*m*k; + c = net.workspace; + if (l.size == 1) { + c = imd; + } + + gemm(1,0,n,k,m,1,a,n,b,k,0,c,k); + + if (l.size != 1) { + col2im_cpu(net.workspace, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, imd); + } + } + } + } +} + +void update_convolutional_layer(convolutional_layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + + axpy_cpu(l.n, learning_rate/batch, l.bias_updates, 1, l.biases, 1); + scal_cpu(l.n, momentum, l.bias_updates, 1); + + if(l.scales){ + axpy_cpu(l.n, learning_rate/batch, l.scale_updates, 1, l.scales, 1); + scal_cpu(l.n, momentum, l.scale_updates, 1); + } + + axpy_cpu(l.nweights, -decay*batch, l.weights, 1, l.weight_updates, 1); + axpy_cpu(l.nweights, learning_rate/batch, l.weight_updates, 1, l.weights, 1); + scal_cpu(l.nweights, momentum, l.weight_updates, 1); +} + + +image get_convolutional_weight(convolutional_layer l, int i) +{ + int h = l.size; + int w = l.size; + int c = l.c/l.groups; + return float_to_image(w,h,c,l.weights+i*h*w*c); +} + +void rgbgr_weights(convolutional_layer l) +{ + int i; + for(i = 0; i < l.n; ++i){ + image im = get_convolutional_weight(l, i); + if (im.c == 3) { + rgbgr_image(im); + } + } +} + +void rescale_weights(convolutional_layer l, float scale, float trans) +{ + int i; + for(i = 0; i < l.n; ++i){ + image im = get_convolutional_weight(l, i); + if (im.c == 3) { + scale_image(im, scale); + float sum = sum_array(im.data, im.w*im.h*im.c); + l.biases[i] += sum*trans; + } + } +} + +image *get_weights(convolutional_layer l) +{ + image *weights = calloc(l.n, sizeof(image)); + int i; + for(i = 0; i < l.n; ++i){ + weights[i] = copy_image(get_convolutional_weight(l, i)); + normalize_image(weights[i]); + /* + char buff[256]; + sprintf(buff, "filter%d", i); + save_image(weights[i], buff); + */ + } + //error("hey"); + return weights; +} + +image *visualize_convolutional_layer(convolutional_layer l, char *window, image *prev_weights) +{ + image *single_weights = get_weights(l); + show_images(single_weights, l.n, window); + + image delta = get_convolutional_image(l); + image dc = collapse_image_layers(delta, 1); + char buff[256]; + sprintf(buff, "%s: Output", window); + //show_image(dc, buff); + //save_image(dc, buff); + free_image(dc); + return single_weights; +} + +#ifdef ALLEN_MODIFIED +convolutional_layer make_convolutional_layer_mem(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam, int use_bin_output) +{ + int i; + convolutional_layer l = { 0 }; + l.type = CONVOLUTIONAL; + + l.h = h; + l.w = w; + l.c = c; + l.n = n; + l.binary = binary; + l.xnor = xnor; + l.use_bin_output = use_bin_output; + l.batch = batch; + l.stride = stride; + l.size = size; + l.pad = padding; + l.batch_normalize = batch_normalize; + + l.weights = calloc(c*n*size*size, sizeof(float)); + l.weight_updates = calloc(c*n*size*size, sizeof(float)); + + l.biases = calloc(n, sizeof(float)); + l.bias_updates = calloc(n, sizeof(float)); + + // float scale = 1./sqrt(size*size*c); + float scale = sqrt(2. / (size*size*c)); + for (i = 0; i < c*n*size*size; ++i) l.weights[i] = scale * rand_uniform(-1, 1); + int out_h = convolutional_out_height(l); + int out_w = convolutional_out_width(l); + l.out_h = out_h; + l.out_w = out_w; + l.out_c = n; + l.outputs = l.out_h * l.out_w * l.out_c; + l.inputs = l.w * l.h * l.c; + + l.output = calloc(l.batch*l.outputs, sizeof(float)); + l.delta = calloc(l.batch*l.outputs, sizeof(float)); + + l.forward = forward_convolutional_layer; + l.backward = backward_convolutional_layer; + l.update = update_convolutional_layer; + if (binary) { + l.binary_weights = calloc(c*n*size*size, sizeof(float)); + l.cweights = calloc(c*n*size*size, sizeof(char)); + l.scales = calloc(n, sizeof(float)); + } + if (xnor) { + l.binary_weights = calloc(c*n*size*size, sizeof(float)); + l.binary_input = calloc(l.inputs*l.batch, sizeof(float)); + + int align = 32;// 8; + int src_align = l.out_h*l.out_w; + l.bit_align = src_align + (align - src_align % align); + } + + if (batch_normalize) { + l.scales = calloc(n, sizeof(float)); + l.scale_updates = calloc(n, sizeof(float)); + for (i = 0; i < n; ++i) { + l.scales[i] = 1; + } + + l.mean = calloc(n, sizeof(float)); + l.variance = calloc(n, sizeof(float)); + + l.mean_delta = calloc(n, sizeof(float)); + l.variance_delta = calloc(n, sizeof(float)); + + l.rolling_mean = calloc(n, sizeof(float)); + l.rolling_variance = calloc(n, sizeof(float)); + l.x = calloc(l.batch*l.outputs, sizeof(float)); + l.x_norm = calloc(l.batch*l.outputs, sizeof(float)); + } + if (adam) { + l.adam = 1; + l.m = calloc(c*n*size*size, sizeof(float)); + l.v = calloc(c*n*size*size, sizeof(float)); + } + +#ifdef GPU + l.forward_gpu = forward_convolutional_layer_gpu; + l.backward_gpu = backward_convolutional_layer_gpu; + l.update_gpu = update_convolutional_layer_gpu; + + if (gpu_index >= 0) { + if (adam) { + l.m_gpu = cuda_make_array(l.m, c*n*size*size); + l.v_gpu = cuda_make_array(l.v, c*n*size*size); + } + + l.weights_gpu = cuda_make_array(l.weights, c*n*size*size); +#ifdef CUDNN_HALF + l.weights_gpu16 = cuda_make_array(NULL, c*n*size*size / 2); //cuda_make_array(l.weights, c*n*size*size / 2); + l.weight_updates_gpu16 = cuda_make_array(NULL, c*n*size*size / 2); //cuda_make_array(l.weight_updates, c*n*size*size / 2); +#endif + l.weight_updates_gpu = cuda_make_array(l.weight_updates, c*n*size*size); + + l.biases_gpu = cuda_make_array(l.biases, n); + l.bias_updates_gpu = cuda_make_array(l.bias_updates, n); + + l.delta_gpu = cuda_make_array(l.delta, l.batch*out_h*out_w*n); + l.output_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + + if (binary) { + l.binary_weights_gpu = cuda_make_array(l.weights, c*n*size*size); + } + if (xnor) { + l.binary_weights_gpu = cuda_make_array(l.weights, c*n*size*size); + l.binary_input_gpu = cuda_make_array(0, l.inputs*l.batch); + } + + if (batch_normalize) { + l.mean_gpu = cuda_make_array(l.mean, n); + l.variance_gpu = cuda_make_array(l.variance, n); + + l.rolling_mean_gpu = cuda_make_array(l.mean, n); + l.rolling_variance_gpu = cuda_make_array(l.variance, n); + + l.mean_delta_gpu = cuda_make_array(l.mean, n); + l.variance_delta_gpu = cuda_make_array(l.variance, n); + + l.scales_gpu = cuda_make_array(l.scales, n); + l.scale_updates_gpu = cuda_make_array(l.scale_updates, n); + + l.x_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + l.x_norm_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + } +#ifdef CUDNN + cudnnCreateTensorDescriptor(&l.normDstTensorDesc); + cudnnCreateTensorDescriptor(&l.normDstTensorDescF16); + cudnnCreateTensorDescriptor(&l.normTensorDesc); + cudnnCreateTensorDescriptor(&l.srcTensorDesc); + cudnnCreateTensorDescriptor(&l.dstTensorDesc); + cudnnCreateFilterDescriptor(&l.weightDesc); + cudnnCreateTensorDescriptor(&l.dsrcTensorDesc); + cudnnCreateTensorDescriptor(&l.ddstTensorDesc); + cudnnCreateFilterDescriptor(&l.dweightDesc); + cudnnCreateConvolutionDescriptor(&l.convDesc); + cudnn_convolutional_setup(&l, cudnn_fastest); +#endif + } +#endif + l.workspace_size = get_workspace_size(l); + l.activation = activation; + + //fprintf(stderr, "conv %5d %2d x%2d /%2d %4d x%4d x%4d -> %4d x%4d x%4d\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c); + l.bflops = (2.0 * l.n * l.size*l.size*l.c * l.out_h*l.out_w) / 1000000000.; + //if (l.xnor && l.use_bin_output) fprintf(stderr, "convXB"); + //else if (l.xnor) fprintf(stderr, "convX "); + //else fprintf(stderr, "conv "); + //fprintf(stderr, "%5d %2d x%2d /%2d %4d x%4d x%4d -> %4d x%4d x%4d %5.3f BF\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c, l.bflops); + + return l; +} +#endif \ No newline at end of file diff --git a/src/convolutional_layer.h b/src/convolutional_layer.h new file mode 100644 index 0000000..895ac22 --- /dev/null +++ b/src/convolutional_layer.h @@ -0,0 +1,69 @@ +#pragma once +#ifndef CONVOLUTIONAL_LAYER_H +#define CONVOLUTIONAL_LAYER_H +#include "define_inc.h" +#include "cuda.h" +#include "image.h" +#include "activations.h" +#include "layer.h" +#include "network.h" +#include "option_list.h" + +typedef layer convolutional_layer; + +#ifdef GPU +void forward_convolutional_layer_gpu(convolutional_layer layer, network net); +void backward_convolutional_layer_gpu(convolutional_layer layer, network net); +void update_convolutional_layer_gpu(convolutional_layer layer, update_args a); + +void push_convolutional_layer(convolutional_layer layer); +void pull_convolutional_layer(convolutional_layer layer); + +void add_bias_gpu(float *output, float *biases, int batch, int n, int size); +void backward_bias_gpu(float *bias_updates, float *delta, int batch, int n, int size); +void adam_update_gpu(float *w, float *d, float *m, float *v, float B1, float B2, float eps, float decay, float rate, int n, int batch, int t); +#ifdef CUDNN +void cudnn_convolutional_setup(layer *l); +#endif +#endif + +convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int groups, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam); +void resize_convolutional_layer(convolutional_layer *layer, int w, int h); +void forward_convolutional_layer(const convolutional_layer layer, network net); +void update_convolutional_layer(convolutional_layer layer, update_args a); +image *visualize_convolutional_layer(convolutional_layer layer, char *window, image *prev_weights); +void binarize_weights(float *weights, int n, int size, float *binary); +void swap_binary(convolutional_layer *l); +void binarize_weights2(float *weights, int n, int size, char *binary, float *scales); + +void backward_convolutional_layer(convolutional_layer layer, network net); + +void add_bias(float *output, float *biases, int batch, int n, int size); +void backward_bias(float *bias_updates, float *delta, int batch, int n, int size); + +image get_convolutional_image(convolutional_layer layer); +image get_convolutional_delta(convolutional_layer layer); +image get_convolutional_weight(convolutional_layer layer, int i); + +int convolutional_out_height(convolutional_layer layer); +int convolutional_out_width(convolutional_layer layer); + +void denormalize_connected_layer(layer l); +void denormalize_convolutional_layer(layer l); +void statistics_connected_layer(layer l); +void rescale_weights(layer l, float scale, float trans); +void rgbgr_weights(layer l); +image *get_weights(layer l); + +void get_detection_detections(layer l, int w, int h, float thresh, detection *dets); + + +void zero_objectness(layer l); +void get_region_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets); +int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets); + +#ifdef ALLEN_MODIFIED + convolutional_layer make_convolutional_layer_mem(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam, int use_bin_output); +#endif + +#endif \ No newline at end of file diff --git a/src/cost_layer.c b/src/cost_layer.c new file mode 100644 index 0000000..2138ff2 --- /dev/null +++ b/src/cost_layer.c @@ -0,0 +1,176 @@ +#include "cost_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include <math.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +COST_TYPE get_cost_type(char *s) +{ + if (strcmp(s, "seg")==0) return SEG; + if (strcmp(s, "sse")==0) return SSE; + if (strcmp(s, "masked")==0) return MASKED; + if (strcmp(s, "smooth")==0) return SMOOTH; + if (strcmp(s, "L1")==0) return L1; + if (strcmp(s, "wgan")==0) return WGAN; + fprintf(stderr, "Couldn't find cost type %s, going with SSE\n", s); + return SSE; +} + +char *get_cost_string(COST_TYPE a) +{ + switch(a){ + case SEG: + return "seg"; + case SSE: + return "sse"; + case MASKED: + return "masked"; + case SMOOTH: + return "smooth"; + case L1: + return "L1"; + case WGAN: + return "wgan"; + } + return "sse"; +} + +cost_layer make_cost_layer(int batch, int inputs, COST_TYPE cost_type, float scale) +{ + fprintf(stderr, "cost %4d\n", inputs); + cost_layer l = {0}; + l.type = COST; + + l.scale = scale; + l.batch = batch; + l.inputs = inputs; + l.outputs = inputs; + l.cost_type = cost_type; + l.delta = calloc(inputs*batch, sizeof(float)); + l.output = calloc(inputs*batch, sizeof(float)); + l.cost = calloc(1, sizeof(float)); + + l.forward = forward_cost_layer; + l.backward = backward_cost_layer; + #ifdef GPU + l.forward_gpu = forward_cost_layer_gpu; + l.backward_gpu = backward_cost_layer_gpu; + + l.delta_gpu = cuda_make_array(l.output, inputs*batch); + l.output_gpu = cuda_make_array(l.delta, inputs*batch); + #endif + return l; +} + +void resize_cost_layer(cost_layer *l, int inputs) +{ + l->inputs = inputs; + l->outputs = inputs; + l->delta = realloc(l->delta, inputs*l->batch*sizeof(float)); + l->output = realloc(l->output, inputs*l->batch*sizeof(float)); +#ifdef GPU + cuda_free(l->delta_gpu); + cuda_free(l->output_gpu); + l->delta_gpu = cuda_make_array(l->delta, inputs*l->batch); + l->output_gpu = cuda_make_array(l->output, inputs*l->batch); +#endif +} + +void forward_cost_layer(cost_layer l, network net) +{ + if (!net.truth) return; + if(l.cost_type == MASKED){ + int i; + for(i = 0; i < l.batch*l.inputs; ++i){ + if(net.truth[i] == SECRET_NUM) net.input[i] = SECRET_NUM; + } + } + if(l.cost_type == SMOOTH){ + smooth_l1_cpu(l.batch*l.inputs, net.input, net.truth, l.delta, l.output); + }else if(l.cost_type == L1){ + l1_cpu(l.batch*l.inputs, net.input, net.truth, l.delta, l.output); + } else { + l2_cpu(l.batch*l.inputs, net.input, net.truth, l.delta, l.output); + } + l.cost[0] = sum_array(l.output, l.batch*l.inputs); +} + +void backward_cost_layer(const cost_layer l, network net) +{ + axpy_cpu(l.batch*l.inputs, l.scale, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void pull_cost_layer(cost_layer l) +{ + cuda_pull_array(l.delta_gpu, l.delta, l.batch*l.inputs); +} + +void push_cost_layer(cost_layer l) +{ + cuda_push_array(l.delta_gpu, l.delta, l.batch*l.inputs); +} + +int float_abs_compare (const void * a, const void * b) +{ + float fa = *(const float*) a; + if(fa < 0) fa = -fa; + float fb = *(const float*) b; + if(fb < 0) fb = -fb; + return (fa > fb) - (fa < fb); +} + +void forward_cost_layer_gpu(cost_layer l, network net) +{ + if (!net.truth) return; + if(l.smooth){ + scal_gpu(l.batch*l.inputs, (1-l.smooth), net.truth_gpu, 1); + add_gpu(l.batch*l.inputs, l.smooth * 1./l.inputs, net.truth_gpu, 1); + } + + if(l.cost_type == SMOOTH){ + smooth_l1_gpu(l.batch*l.inputs, net.input_gpu, net.truth_gpu, l.delta_gpu, l.output_gpu); + } else if (l.cost_type == L1){ + l1_gpu(l.batch*l.inputs, net.input_gpu, net.truth_gpu, l.delta_gpu, l.output_gpu); + } else if (l.cost_type == WGAN){ + wgan_gpu(l.batch*l.inputs, net.input_gpu, net.truth_gpu, l.delta_gpu, l.output_gpu); + } else { + l2_gpu(l.batch*l.inputs, net.input_gpu, net.truth_gpu, l.delta_gpu, l.output_gpu); + } + + if (l.cost_type == SEG && l.noobject_scale != 1) { + scale_mask_gpu(l.batch*l.inputs, l.delta_gpu, 0, net.truth_gpu, l.noobject_scale); + scale_mask_gpu(l.batch*l.inputs, l.output_gpu, 0, net.truth_gpu, l.noobject_scale); + } + if (l.cost_type == MASKED) { + mask_gpu(l.batch*l.inputs, net.delta_gpu, SECRET_NUM, net.truth_gpu, 0); + } + + if(l.ratio){ + cuda_pull_array(l.delta_gpu, l.delta, l.batch*l.inputs); + qsort(l.delta, l.batch*l.inputs, sizeof(float), float_abs_compare); + int n = (1-l.ratio) * l.batch*l.inputs; + float thresh = l.delta[n]; + thresh = 0; + printf("%f\n", thresh); + supp_gpu(l.batch*l.inputs, thresh, l.delta_gpu, 1); + } + + if(l.thresh){ + supp_gpu(l.batch*l.inputs, l.thresh*1./l.inputs, l.delta_gpu, 1); + } + + cuda_pull_array(l.output_gpu, l.output, l.batch*l.inputs); + l.cost[0] = sum_array(l.output, l.batch*l.inputs); +} + +void backward_cost_layer_gpu(const cost_layer l, network net) +{ + axpy_gpu(l.batch*l.inputs, l.scale, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif + diff --git a/src/cost_layer.h b/src/cost_layer.h new file mode 100644 index 0000000..92f2f50 --- /dev/null +++ b/src/cost_layer.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef COST_LAYER_H +#define COST_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" + +typedef layer cost_layer; + +COST_TYPE get_cost_type(char *s); +char *get_cost_string(COST_TYPE a); +cost_layer make_cost_layer(int batch, int inputs, COST_TYPE type, float scale); +void forward_cost_layer(const cost_layer l, network net); +void backward_cost_layer(const cost_layer l, network net); +void resize_cost_layer(cost_layer *l, int inputs); + +#ifdef GPU +void forward_cost_layer_gpu(cost_layer l, network net); +void backward_cost_layer_gpu(const cost_layer l, network net); +#endif + +#endif diff --git a/src/crnn_layer.c b/src/crnn_layer.c new file mode 100644 index 0000000..7dd29f6 --- /dev/null +++ b/src/crnn_layer.c @@ -0,0 +1,283 @@ +#include "crnn_layer.h" +#include "convolutional_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void increment_layer(layer *l, int steps) +{ + int num = l->outputs*l->batch*steps; + l->output += num; + l->delta += num; + l->x += num; + l->x_norm += num; + +#ifdef GPU + l->output_gpu += num; + l->delta_gpu += num; + l->x_gpu += num; + l->x_norm_gpu += num; +#endif +} + +layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize) +{ + fprintf(stderr, "CRNN Layer: %d x %d x %d image, %d filters\n", h,w,c,output_filters); + batch = batch / steps; + layer l = {0}; + l.batch = batch; + l.type = CRNN; + l.steps = steps; + l.h = h; + l.w = w; + l.c = c; + l.out_h = h; + l.out_w = w; + l.out_c = output_filters; + l.inputs = h*w*c; + l.hidden = h * w * hidden_filters; + l.outputs = l.out_h * l.out_w * l.out_c; + + l.state = calloc(l.hidden*batch*(steps+1), sizeof(float)); + + l.input_layer = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.input_layer) = make_convolutional_layer(batch*steps, h, w, c, hidden_filters, 1, 3, 1, 1, activation, batch_normalize, 0, 0, 0); + l.input_layer->batch = batch; + + l.self_layer = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.self_layer) = make_convolutional_layer(batch*steps, h, w, hidden_filters, hidden_filters, 1, 3, 1, 1, activation, batch_normalize, 0, 0, 0); + l.self_layer->batch = batch; + + l.output_layer = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.output_layer) = make_convolutional_layer(batch*steps, h, w, hidden_filters, output_filters, 1, 3, 1, 1, activation, batch_normalize, 0, 0, 0); + l.output_layer->batch = batch; + + l.output = l.output_layer->output; + l.delta = l.output_layer->delta; + + l.forward = forward_crnn_layer; + l.backward = backward_crnn_layer; + l.update = update_crnn_layer; + +#ifdef GPU + l.forward_gpu = forward_crnn_layer_gpu; + l.backward_gpu = backward_crnn_layer_gpu; + l.update_gpu = update_crnn_layer_gpu; + + l.state_gpu = cuda_make_array(l.state, l.hidden*batch*(steps+1)); + l.output_gpu = l.output_layer->output_gpu; + l.delta_gpu = l.output_layer->delta_gpu; +#endif + + return l; +} + +void update_crnn_layer(layer l, update_args a) +{ + update_convolutional_layer(*(l.input_layer), a); + update_convolutional_layer(*(l.self_layer), a); + update_convolutional_layer(*(l.output_layer), a); +} + +void forward_crnn_layer(layer l, network net) +{ + network s = net; + s.train = net.train; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + + fill_cpu(l.outputs * l.batch * l.steps, 0, output_layer.delta, 1); + fill_cpu(l.hidden * l.batch * l.steps, 0, self_layer.delta, 1); + fill_cpu(l.hidden * l.batch * l.steps, 0, input_layer.delta, 1); + if(net.train) fill_cpu(l.hidden * l.batch, 0, l.state, 1); + + for (i = 0; i < l.steps; ++i) { + s.input = net.input; + forward_convolutional_layer(input_layer, s); + + s.input = l.state; + forward_convolutional_layer(self_layer, s); + + float *old_state = l.state; + if(net.train) l.state += l.hidden*l.batch; + if(l.shortcut){ + copy_cpu(l.hidden * l.batch, old_state, 1, l.state, 1); + }else{ + fill_cpu(l.hidden * l.batch, 0, l.state, 1); + } + axpy_cpu(l.hidden * l.batch, 1, input_layer.output, 1, l.state, 1); + axpy_cpu(l.hidden * l.batch, 1, self_layer.output, 1, l.state, 1); + + s.input = l.state; + forward_convolutional_layer(output_layer, s); + + net.input += l.inputs*l.batch; + increment_layer(&input_layer, 1); + increment_layer(&self_layer, 1); + increment_layer(&output_layer, 1); + } +} + +void backward_crnn_layer(layer l, network net) +{ + network s = net; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + + increment_layer(&input_layer, l.steps-1); + increment_layer(&self_layer, l.steps-1); + increment_layer(&output_layer, l.steps-1); + + l.state += l.hidden*l.batch*l.steps; + for (i = l.steps-1; i >= 0; --i) { + copy_cpu(l.hidden * l.batch, input_layer.output, 1, l.state, 1); + axpy_cpu(l.hidden * l.batch, 1, self_layer.output, 1, l.state, 1); + + s.input = l.state; + s.delta = self_layer.delta; + backward_convolutional_layer(output_layer, s); + + l.state -= l.hidden*l.batch; + /* + if(i > 0){ + copy_cpu(l.hidden * l.batch, input_layer.output - l.hidden*l.batch, 1, l.state, 1); + axpy_cpu(l.hidden * l.batch, 1, self_layer.output - l.hidden*l.batch, 1, l.state, 1); + }else{ + fill_cpu(l.hidden * l.batch, 0, l.state, 1); + } + */ + + s.input = l.state; + s.delta = self_layer.delta - l.hidden*l.batch; + if (i == 0) s.delta = 0; + backward_convolutional_layer(self_layer, s); + + copy_cpu(l.hidden*l.batch, self_layer.delta, 1, input_layer.delta, 1); + if (i > 0 && l.shortcut) axpy_cpu(l.hidden*l.batch, 1, self_layer.delta, 1, self_layer.delta - l.hidden*l.batch, 1); + s.input = net.input + i*l.inputs*l.batch; + if(net.delta) s.delta = net.delta + i*l.inputs*l.batch; + else s.delta = 0; + backward_convolutional_layer(input_layer, s); + + increment_layer(&input_layer, -1); + increment_layer(&self_layer, -1); + increment_layer(&output_layer, -1); + } +} + +#ifdef GPU + +void pull_crnn_layer(layer l) +{ + pull_convolutional_layer(*(l.input_layer)); + pull_convolutional_layer(*(l.self_layer)); + pull_convolutional_layer(*(l.output_layer)); +} + +void push_crnn_layer(layer l) +{ + push_convolutional_layer(*(l.input_layer)); + push_convolutional_layer(*(l.self_layer)); + push_convolutional_layer(*(l.output_layer)); +} + +void update_crnn_layer_gpu(layer l, update_args a) +{ + update_convolutional_layer_gpu(*(l.input_layer), a); + update_convolutional_layer_gpu(*(l.self_layer), a); + update_convolutional_layer_gpu(*(l.output_layer), a); +} + +void forward_crnn_layer_gpu(layer l, network net) +{ + network s = net; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + + fill_gpu(l.outputs * l.batch * l.steps, 0, output_layer.delta_gpu, 1); + fill_gpu(l.hidden * l.batch * l.steps, 0, self_layer.delta_gpu, 1); + fill_gpu(l.hidden * l.batch * l.steps, 0, input_layer.delta_gpu, 1); + if(net.train) fill_gpu(l.hidden * l.batch, 0, l.state_gpu, 1); + + for (i = 0; i < l.steps; ++i) { + s.input_gpu = net.input_gpu; + forward_convolutional_layer_gpu(input_layer, s); + + s.input_gpu = l.state_gpu; + forward_convolutional_layer_gpu(self_layer, s); + + float *old_state = l.state_gpu; + if(net.train) l.state_gpu += l.hidden*l.batch; + if(l.shortcut){ + copy_gpu(l.hidden * l.batch, old_state, 1, l.state_gpu, 1); + }else{ + fill_gpu(l.hidden * l.batch, 0, l.state_gpu, 1); + } + axpy_gpu(l.hidden * l.batch, 1, input_layer.output_gpu, 1, l.state_gpu, 1); + axpy_gpu(l.hidden * l.batch, 1, self_layer.output_gpu, 1, l.state_gpu, 1); + + s.input_gpu = l.state_gpu; + forward_convolutional_layer_gpu(output_layer, s); + + net.input_gpu += l.inputs*l.batch; + increment_layer(&input_layer, 1); + increment_layer(&self_layer, 1); + increment_layer(&output_layer, 1); + } +} + +void backward_crnn_layer_gpu(layer l, network net) +{ + network s = net; + s.train = net.train; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + increment_layer(&input_layer, l.steps - 1); + increment_layer(&self_layer, l.steps - 1); + increment_layer(&output_layer, l.steps - 1); + l.state_gpu += l.hidden*l.batch*l.steps; + for (i = l.steps-1; i >= 0; --i) { + copy_gpu(l.hidden * l.batch, input_layer.output_gpu, 1, l.state_gpu, 1); + axpy_gpu(l.hidden * l.batch, 1, self_layer.output_gpu, 1, l.state_gpu, 1); + + s.input_gpu = l.state_gpu; + s.delta_gpu = self_layer.delta_gpu; + backward_convolutional_layer_gpu(output_layer, s); + + l.state_gpu -= l.hidden*l.batch; + + s.input_gpu = l.state_gpu; + s.delta_gpu = self_layer.delta_gpu - l.hidden*l.batch; + if (i == 0) s.delta_gpu = 0; + backward_convolutional_layer_gpu(self_layer, s); + + copy_gpu(l.hidden*l.batch, self_layer.delta_gpu, 1, input_layer.delta_gpu, 1); + if (i > 0 && l.shortcut) axpy_gpu(l.hidden*l.batch, 1, self_layer.delta_gpu, 1, self_layer.delta_gpu - l.hidden*l.batch, 1); + s.input_gpu = net.input_gpu + i*l.inputs*l.batch; + if(net.delta_gpu) s.delta_gpu = net.delta_gpu + i*l.inputs*l.batch; + else s.delta_gpu = 0; + backward_convolutional_layer_gpu(input_layer, s); + + increment_layer(&input_layer, -1); + increment_layer(&self_layer, -1); + increment_layer(&output_layer, -1); + } +} +#endif diff --git a/src/crnn_layer.h b/src/crnn_layer.h new file mode 100644 index 0000000..82fc71a --- /dev/null +++ b/src/crnn_layer.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef CRNN_LAYER_H +#define CRNN_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "layer.h" +#include "network.h" + +layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize); + +void forward_crnn_layer(layer l, network net); +void backward_crnn_layer(layer l, network net); +void update_crnn_layer(layer l, update_args a); + +#ifdef GPU +void forward_crnn_layer_gpu(layer l, network net); +void backward_crnn_layer_gpu(layer l, network net); +void update_crnn_layer_gpu(layer l, update_args a); +void push_crnn_layer(layer l); +void pull_crnn_layer(layer l); +#endif + +#endif + diff --git a/src/crop_layer.c b/src/crop_layer.c new file mode 100644 index 0000000..3b91852 --- /dev/null +++ b/src/crop_layer.c @@ -0,0 +1,103 @@ +#include "crop_layer.h" +#include "cuda.h" +#include <stdio.h> + +image get_crop_image(crop_layer l) +{ + int h = l.out_h; + int w = l.out_w; + int c = l.out_c; + return float_to_image(w,h,c,l.output); +} + +void backward_crop_layer(const crop_layer l, network net){} +void backward_crop_layer_gpu(const crop_layer l, network net){} + +crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure) +{ + fprintf(stderr, "Crop Layer: %d x %d -> %d x %d x %d image\n", h,w,crop_height,crop_width,c); + crop_layer l = {0}; + l.type = CROP; + l.batch = batch; + l.h = h; + l.w = w; + l.c = c; + l.scale = (float)crop_height / h; + l.flip = flip; + l.angle = angle; + l.saturation = saturation; + l.exposure = exposure; + l.out_w = crop_width; + l.out_h = crop_height; + l.out_c = c; + l.inputs = l.w * l.h * l.c; + l.outputs = l.out_w * l.out_h * l.out_c; + l.output = calloc(l.outputs*batch, sizeof(float)); + l.forward = forward_crop_layer; + l.backward = backward_crop_layer; + + #ifdef GPU + l.forward_gpu = forward_crop_layer_gpu; + l.backward_gpu = backward_crop_layer_gpu; + l.output_gpu = cuda_make_array(l.output, l.outputs*batch); + l.rand_gpu = cuda_make_array(0, l.batch*8); + #endif + return l; +} + +void resize_crop_layer(layer *l, int w, int h) +{ + l->w = w; + l->h = h; + + l->out_w = l->scale*w; + l->out_h = l->scale*h; + + l->inputs = l->w * l->h * l->c; + l->outputs = l->out_h * l->out_w * l->out_c; + + l->output = realloc(l->output, l->batch*l->outputs*sizeof(float)); + #ifdef GPU + cuda_free(l->output_gpu); + l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); + #endif +} + + +void forward_crop_layer(const crop_layer l, network net) +{ + int i,j,c,b,row,col; + int index; + int count = 0; + int flip = (l.flip && rand()%2); + int dh = rand()%(l.h - l.out_h + 1); + int dw = rand()%(l.w - l.out_w + 1); + float scale = 2; + float trans = -1; + if(l.noadjust){ + scale = 1; + trans = 0; + } + if(!net.train){ + flip = 0; + dh = (l.h - l.out_h)/2; + dw = (l.w - l.out_w)/2; + } + for(b = 0; b < l.batch; ++b){ + for(c = 0; c < l.c; ++c){ + for(i = 0; i < l.out_h; ++i){ + for(j = 0; j < l.out_w; ++j){ + if(flip){ + col = l.w - dw - j - 1; + }else{ + col = j + dw; + } + row = i + dh; + index = col+l.w*(row+l.h*(c + l.c*b)); + l.output[count++] = net.input[index]*scale + trans; + } + } + } + } +} + diff --git a/src/crop_layer.h b/src/crop_layer.h new file mode 100644 index 0000000..b6f084a --- /dev/null +++ b/src/crop_layer.h @@ -0,0 +1,21 @@ +#pragma once +#ifndef CROP_LAYER_H +#define CROP_LAYER_H +#include "define_inc.h" +#include "image.h" +#include "layer.h" +#include "network.h" + +typedef layer crop_layer; + +image get_crop_image(crop_layer l); +crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure); +void forward_crop_layer(const crop_layer l, network net); +void resize_crop_layer(layer *l, int w, int h); + +#ifdef GPU +void forward_crop_layer_gpu(crop_layer l, network net); +#endif + +#endif + diff --git a/src/crop_layer_kernels.cu b/src/crop_layer_kernels.cu new file mode 100644 index 0000000..b5b9f55 --- /dev/null +++ b/src/crop_layer_kernels.cu @@ -0,0 +1,225 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "crop_layer.h" +#include "utils.h" +#include "cuda.h" +#include "image.h" +} + +__device__ float get_pixel_kernel(float *image, int w, int h, int x, int y, int c) +{ + if(x < 0 || x >= w || y < 0 || y >= h) return 0; + return image[x + w*(y + c*h)]; +} + +__device__ float3 rgb_to_hsv_kernel(float3 rgb) +{ + float r = rgb.x; + float g = rgb.y; + float b = rgb.z; + + float h, s, v; + float max = (r > g) ? ( (r > b) ? r : b) : ( (g > b) ? g : b); + float min = (r < g) ? ( (r < b) ? r : b) : ( (g < b) ? g : b); + float delta = max - min; + v = max; + if(max == 0){ + s = 0; + h = -1; + }else{ + s = delta/max; + if(r == max){ + h = (g - b) / delta; + } else if (g == max) { + h = 2 + (b - r) / delta; + } else { + h = 4 + (r - g) / delta; + } + if (h < 0) h += 6; + } + return make_float3(h, s, v); +} + +__device__ float3 hsv_to_rgb_kernel(float3 hsv) +{ + float h = hsv.x; + float s = hsv.y; + float v = hsv.z; + + float r, g, b; + float f, p, q, t; + + if (s == 0) { + r = g = b = v; + } else { + int index = (int) floorf(h); + f = h - index; + p = v*(1-s); + q = v*(1-s*f); + t = v*(1-s*(1-f)); + if(index == 0){ + r = v; g = t; b = p; + } else if(index == 1){ + r = q; g = v; b = p; + } else if(index == 2){ + r = p; g = v; b = t; + } else if(index == 3){ + r = p; g = q; b = v; + } else if(index == 4){ + r = t; g = p; b = v; + } else { + r = v; g = p; b = q; + } + } + r = (r < 0) ? 0 : ((r > 1) ? 1 : r); + g = (g < 0) ? 0 : ((g > 1) ? 1 : g); + b = (b < 0) ? 0 : ((b > 1) ? 1 : b); + return make_float3(r, g, b); +} + +__device__ float bilinear_interpolate_kernel(float *image, int w, int h, float x, float y, int c) +{ + int ix = (int) floorf(x); + int iy = (int) floorf(y); + + float dx = x - ix; + float dy = y - iy; + + float val = (1-dy) * (1-dx) * get_pixel_kernel(image, w, h, ix, iy, c) + + dy * (1-dx) * get_pixel_kernel(image, w, h, ix, iy+1, c) + + (1-dy) * dx * get_pixel_kernel(image, w, h, ix+1, iy, c) + + dy * dx * get_pixel_kernel(image, w, h, ix+1, iy+1, c); + return val; +} + +__global__ void levels_image_kernel(float *image, float *rand, int batch, int w, int h, int train, float saturation, float exposure, float translate, float scale, float shift) +{ + int size = batch * w * h; + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= size) return; + int x = id % w; + id /= w; + int y = id % h; + id /= h; + float rshift = rand[0]; + float gshift = rand[1]; + float bshift = rand[2]; + float r0 = rand[8*id + 0]; + float r1 = rand[8*id + 1]; + float r2 = rand[8*id + 2]; + float r3 = rand[8*id + 3]; + + saturation = r0*(saturation - 1) + 1; + saturation = (r1 > .5f) ? 1.f/saturation : saturation; + exposure = r2*(exposure - 1) + 1; + exposure = (r3 > .5f) ? 1.f/exposure : exposure; + + size_t offset = id * h * w * 3; + image += offset; + float r = image[x + w*(y + h*0)]; + float g = image[x + w*(y + h*1)]; + float b = image[x + w*(y + h*2)]; + float3 rgb = make_float3(r,g,b); + if(train){ + float3 hsv = rgb_to_hsv_kernel(rgb); + hsv.y *= saturation; + hsv.z *= exposure; + rgb = hsv_to_rgb_kernel(hsv); + } else { + shift = 0; + } + image[x + w*(y + h*0)] = rgb.x*scale + translate + (rshift - .5f)*shift; + image[x + w*(y + h*1)] = rgb.y*scale + translate + (gshift - .5f)*shift; + image[x + w*(y + h*2)] = rgb.z*scale + translate + (bshift - .5f)*shift; +} + +__global__ void forward_crop_layer_kernel(float *input, float *rand, int size, int c, int h, int w, int crop_height, int crop_width, int train, int flip, float angle, float *output) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= size) return; + + float cx = w/2.f; + float cy = h/2.f; + + int count = id; + int j = id % crop_width; + id /= crop_width; + int i = id % crop_height; + id /= crop_height; + int k = id % c; + id /= c; + int b = id; + + float r4 = rand[8*b + 4]; + float r5 = rand[8*b + 5]; + float r6 = rand[8*b + 6]; + float r7 = rand[8*b + 7]; + + float dw = (w - crop_width)*r4; + float dh = (h - crop_height)*r5; + flip = (flip && (r6 > .5f)); + angle = 2*angle*r7 - angle; + if(!train){ + dw = (w - crop_width)/2.f; + dh = (h - crop_height)/2.f; + flip = 0; + angle = 0; + } + + input += w*h*c*b; + + float x = (flip) ? w - dw - j - 1 : j + dw; + float y = i + dh; + + float rx = cosf(angle)*(x-cx) - sinf(angle)*(y-cy) + cx; + float ry = sinf(angle)*(x-cx) + cosf(angle)*(y-cy) + cy; + + output[count] = bilinear_interpolate_kernel(input, w, h, rx, ry, k); +} + +extern "C" void forward_crop_layer_gpu(crop_layer layer, network net) +{ + cuda_random(layer.rand_gpu, layer.batch*8); + + float radians = layer.angle*3.14159265f/180.f; + + float scale = 2; + float translate = -1; + if(layer.noadjust){ + scale = 1; + translate = 0; + } + + int size = layer.batch * layer.w * layer.h; + + levels_image_kernel<<<cuda_gridsize(size), BLOCK>>>(net.input_gpu, layer.rand_gpu, layer.batch, layer.w, layer.h, net.train, layer.saturation, layer.exposure, translate, scale, layer.shift); + check_error(cudaPeekAtLastError()); + + size = layer.batch*layer.c*layer.out_w*layer.out_h; + + forward_crop_layer_kernel<<<cuda_gridsize(size), BLOCK>>>(net.input_gpu, layer.rand_gpu, size, layer.c, layer.h, layer.w, layer.out_h, layer.out_w, net.train, layer.flip, radians, layer.output_gpu); + check_error(cudaPeekAtLastError()); + +/* + cuda_pull_array(layer.output_gpu, layer.output, size); + image im = float_to_image(layer.crop_width, layer.crop_height, layer.c, layer.output + 0*(size/layer.batch)); + image im2 = float_to_image(layer.crop_width, layer.crop_height, layer.c, layer.output + 1*(size/layer.batch)); + image im3 = float_to_image(layer.crop_width, layer.crop_height, layer.c, layer.output + 2*(size/layer.batch)); + + translate_image(im, -translate); + scale_image(im, 1/scale); + translate_image(im2, -translate); + scale_image(im2, 1/scale); + translate_image(im3, -translate); + scale_image(im3, 1/scale); + + show_image(im, "cropped"); + show_image(im2, "cropped2"); + show_image(im3, "cropped3"); + cvWaitKey(0); + */ +} + diff --git a/src/cryptionPlus.cpp b/src/cryptionPlus.cpp new file mode 100644 index 0000000..2780890 --- /dev/null +++ b/src/cryptionPlus.cpp @@ -0,0 +1,661 @@ +/* encrypt.cpp +* Performs encryption using AES 128-bit +* @author Cecelia Wisniewska +*/ +//#include "stdafx.h" +#include <iostream> +#include <fstream> +#include <bitset> +#include <climits> +#include "cryptionPlus.h" +//using namespace std; +//typedef std::bitset<8> byte; +//typedef std::bitset<32> word; + +#include "define_inc.h" +// Encryption: Forward Rijndael S-box + +unsigned char key[16] = +{ + 0x6c, 0x69, 0x6c, 0x69, + 0x6e, 0x61, 0x65, 0x73, + 0x63, 0x72, 0x79, 0x70, + 0x74, 0x6b, 0x65, 0x79 +}; + + +unsigned char expandedKey[176]; //AES-128 XiK_Tw + +char* decoding_table = NULL; + +/* Serves as the initial round during encryption +* AddRoundKey is simply an XOR of a 128-bit block with the 128-bit key. +*/ +void AddRoundKey(unsigned char * state, unsigned char * roundKey) { + for (int i = 0; i < 16; i++) { + state[i] ^= roundKey[i]; + } +} + +/* Perform substitution to each of the 16 bytes +* Uses S-box as lookup table +*/ +void EncryptSubBytes(unsigned char * state) { + for (int i = 0; i < 16; i++) { + state[i] = s[state[i]]; + } +} + +// Shift left, adds diffusion +void EncryptShiftRows(unsigned char * state) { + unsigned char tmp[16]; + + /* Column 1 */ + tmp[0] = state[0]; + tmp[1] = state[5]; + tmp[2] = state[10]; + tmp[3] = state[15]; + + /* Column 2 */ + tmp[4] = state[4]; + tmp[5] = state[9]; + tmp[6] = state[14]; + tmp[7] = state[3]; + + /* Column 3 */ + tmp[8] = state[8]; + tmp[9] = state[13]; + tmp[10] = state[2]; + tmp[11] = state[7]; + + /* Column 4 */ + tmp[12] = state[12]; + tmp[13] = state[1]; + tmp[14] = state[6]; + tmp[15] = state[11]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +/* MixColumns uses mul2, mul3 look-up tables +* Source of diffusion +*/ +void MixColumns(unsigned char * state) { + unsigned char tmp[16]; + + tmp[0] = (unsigned char)mul2[state[0]] ^ mul3[state[1]] ^ state[2] ^ state[3]; + tmp[1] = (unsigned char)state[0] ^ mul2[state[1]] ^ mul3[state[2]] ^ state[3]; + tmp[2] = (unsigned char)state[0] ^ state[1] ^ mul2[state[2]] ^ mul3[state[3]]; + tmp[3] = (unsigned char)mul3[state[0]] ^ state[1] ^ state[2] ^ mul2[state[3]]; + + tmp[4] = (unsigned char)mul2[state[4]] ^ mul3[state[5]] ^ state[6] ^ state[7]; + tmp[5] = (unsigned char)state[4] ^ mul2[state[5]] ^ mul3[state[6]] ^ state[7]; + tmp[6] = (unsigned char)state[4] ^ state[5] ^ mul2[state[6]] ^ mul3[state[7]]; + tmp[7] = (unsigned char)mul3[state[4]] ^ state[5] ^ state[6] ^ mul2[state[7]]; + + tmp[8] = (unsigned char)mul2[state[8]] ^ mul3[state[9]] ^ state[10] ^ state[11]; + tmp[9] = (unsigned char)state[8] ^ mul2[state[9]] ^ mul3[state[10]] ^ state[11]; + tmp[10] = (unsigned char)state[8] ^ state[9] ^ mul2[state[10]] ^ mul3[state[11]]; + tmp[11] = (unsigned char)mul3[state[8]] ^ state[9] ^ state[10] ^ mul2[state[11]]; + + tmp[12] = (unsigned char)mul2[state[12]] ^ mul3[state[13]] ^ state[14] ^ state[15]; + tmp[13] = (unsigned char)state[12] ^ mul2[state[13]] ^ mul3[state[14]] ^ state[15]; + tmp[14] = (unsigned char)state[12] ^ state[13] ^ mul2[state[14]] ^ mul3[state[15]]; + tmp[15] = (unsigned char)mul3[state[12]] ^ state[13] ^ state[14] ^ mul2[state[15]]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +/* Each round operates on 128 bits at a time +* The number of rounds is defined in AESEncrypt() +*/ +void EncryptRound(unsigned char * state, unsigned char * key) { + EncryptSubBytes(state); + EncryptShiftRows(state); + MixColumns(state); + AddRoundKey(state, key); +} + +// Same as Round() except it doesn't mix columns +void FinalRound(unsigned char * state, unsigned char * key) { + EncryptSubBytes(state); + EncryptShiftRows(state); + AddRoundKey(state, key); +} + +/* The AES encryption function +* Organizes the confusion and diffusion steps into one function +*/ +void AESEncrypt(unsigned char * message, unsigned char * expandedKey, unsigned char * encryptedMessage) { + unsigned char state[16]; // Stores the first 16 bytes of original message + + for (int i = 0; i < 16; i++) { + state[i] = message[i]; + } + + int numberOfRounds = 9; + + AddRoundKey(state, expandedKey); // Initial round + + for (int i = 0; i < numberOfRounds; i++) { + EncryptRound(state, expandedKey + (16 * (i + 1))); + } + + FinalRound(state, expandedKey + 160); + + // Copy encrypted state to buffer + for (int i = 0; i < 16; i++) { + encryptedMessage[i] = state[i]; + } +} + +char* Resize(char*& old, size_t length, size_t resize_to) +{ + char* new_ptr; + new_ptr = new char[resize_to]; + size_t least = (length < resize_to) ? length : resize_to; + for (size_t i = 0; i < least; ++i) + new_ptr[i] = old[i]; + delete[] old; + old = nullptr; + +#if 0 + new_ptr = (char*)malloc(resize_to * sizeof(char)); + size_t least = (length < resize_to) ? length : resize_to; + for (size_t i = 0; i < least; ++i) + memcpy(&new_ptr[i], &old[i], sizeof(char)); + if (old) { + free(old); + old = NULL; + } + old = NULL; +#endif + return new_ptr; +} + +void AESEncryptFileToFile(const char* inFile, unsigned char * expandedKey, const char* outFile, size_t encrypt_len) +{ + // Nɮ inFile [Kɮ outFile + char data[16]; + char encrypt[16]; + size_t encrypt_size = 0; + + std::ifstream in; + std::ofstream out; + in.open(inFile, std::ios::binary); + out.open(outFile, std::ios::binary | std::ios::trunc); + while (in.read(data, sizeof(data))) + { + if (encrypt_size < encrypt_len || encrypt_len == 0) + { + AESEncrypt((unsigned char *)data, expandedKey, (unsigned char *)encrypt); + out.write(encrypt, sizeof(data)); + encrypt_size += sizeof(encrypt); + } + else + { + out.write(data, sizeof(data)); + } + memset(data, 0x00, sizeof(data)); // m + } + in.close(); + out.close(); +} +size_t AESEncryptFileToArray(const char* inFile, unsigned char * expandedKey, char* outArray, size_t outArraySize) +{ + // Nɮ inFile [Kr}C outArray + // `N outArray jp[K/ѱKej + char data[16]; + char encrypt[16]; + size_t encrypt_size = 0; + + std::ifstream in; + in.open(inFile, std::ios::binary); + while (in.read(data, sizeof(data))) + { + AESEncrypt((unsigned char *)data, expandedKey, (unsigned char *)encrypt); + if (outArraySize < encrypt_size + sizeof(encrypt)) + { + //resize(outArray, encrypt_size + sizeof(encrypt)); + //outArray = Resize(outArray, outArraySize, encrypt_size + sizeof(encrypt)); + printf("[AESEncryptFileToArray]outArraySize is too small."); + break; + } + memcpy(outArray + encrypt_size, encrypt, sizeof(encrypt)); + encrypt_size += sizeof(encrypt); + memset(data, 0x00, sizeof(data)); + } + in.close(); + return encrypt_size; +} +void AESEncryptArrayToFile(char* inArray, size_t inArraySize, unsigned char * expandedKey, const char* outFile) +{ + // Nr}C inArray [Kɮ outFile + char data[16]; + char encrypt[16]; + + std::ofstream out; + out.open(outFile, std::ios::binary | std::ios::trunc); + + for (size_t i = 0; i < inArraySize; i += sizeof(data)) + { + if (i + sizeof(data) > inArraySize) + { + memcpy(data, inArray + i, inArraySize - i); + } + else + memcpy(data, inArray + i, sizeof(data)); + AESEncrypt((unsigned char *)data, expandedKey, (unsigned char *)encrypt); + out.write(encrypt, sizeof(data)); + memset(data, 0x00, sizeof(data)); + } + out.close(); +} +size_t AESEncryptArrayToArray(char* inArray, size_t inArraySize, unsigned char * expandedKey, unsigned char* outArray, size_t outArraySize) +{ + // Nr}C inArray [Kr}C outArray + char data[16]; + char encrypt[16]; + size_t encrypt_size = 0; + + for (size_t i = 0; i < inArraySize; i += sizeof(data)) + { + if (i + sizeof(data) > inArraySize) + { + memcpy(data, inArray + i, inArraySize - i); + } + else + memcpy(data, inArray + i, sizeof(data)); + AESEncrypt((unsigned char *)data, expandedKey, (unsigned char *)encrypt); + if (outArraySize < encrypt_size + sizeof(encrypt)) + { + //resize(outArray, encrypt_size + sizeof(encrypt)); + //outArray = Resize(outArray, outArraySize, encrypt_size + sizeof(encrypt)); + printf("[AESEncryptArrayToArray]outArraySize is too small."); + break; + } + memcpy(outArray + encrypt_size, encrypt, sizeof(encrypt)); + encrypt_size += sizeof(encrypt); + memset(data, 0x00, sizeof(data)); + } + return encrypt_size; +} +//-------------------------------------------- + +/* decrypt.cpp +* Performs decryption using AES 128-bit +* @author Cecelia Wisniewska +*/ + +/* Used in Round() and serves as the final round during decryption +* SubRoundKey is simply an XOR of a 128-bit block with the 128-bit key. +* So basically does the same as AddRoundKey in the encryption +*/ +void SubRoundKey(unsigned char * state, unsigned char * roundKey) { + for (int i = 0; i < 16; i++) { + state[i] ^= roundKey[i]; + } +} + +/* InverseMixColumns uses mul9, mul11, mul13, mul14 look-up tables +* Unmixes the columns by reversing the effect of MixColumns in encryption +*/ +void InverseMixColumns(unsigned char * state) { + unsigned char tmp[16]; + + tmp[0] = (unsigned char)mul14[state[0]] ^ mul11[state[1]] ^ mul13[state[2]] ^ mul9[state[3]]; + tmp[1] = (unsigned char)mul9[state[0]] ^ mul14[state[1]] ^ mul11[state[2]] ^ mul13[state[3]]; + tmp[2] = (unsigned char)mul13[state[0]] ^ mul9[state[1]] ^ mul14[state[2]] ^ mul11[state[3]]; + tmp[3] = (unsigned char)mul11[state[0]] ^ mul13[state[1]] ^ mul9[state[2]] ^ mul14[state[3]]; + + tmp[4] = (unsigned char)mul14[state[4]] ^ mul11[state[5]] ^ mul13[state[6]] ^ mul9[state[7]]; + tmp[5] = (unsigned char)mul9[state[4]] ^ mul14[state[5]] ^ mul11[state[6]] ^ mul13[state[7]]; + tmp[6] = (unsigned char)mul13[state[4]] ^ mul9[state[5]] ^ mul14[state[6]] ^ mul11[state[7]]; + tmp[7] = (unsigned char)mul11[state[4]] ^ mul13[state[5]] ^ mul9[state[6]] ^ mul14[state[7]]; + + tmp[8] = (unsigned char)mul14[state[8]] ^ mul11[state[9]] ^ mul13[state[10]] ^ mul9[state[11]]; + tmp[9] = (unsigned char)mul9[state[8]] ^ mul14[state[9]] ^ mul11[state[10]] ^ mul13[state[11]]; + tmp[10] = (unsigned char)mul13[state[8]] ^ mul9[state[9]] ^ mul14[state[10]] ^ mul11[state[11]]; + tmp[11] = (unsigned char)mul11[state[8]] ^ mul13[state[9]] ^ mul9[state[10]] ^ mul14[state[11]]; + + tmp[12] = (unsigned char)mul14[state[12]] ^ mul11[state[13]] ^ mul13[state[14]] ^ mul9[state[15]]; + tmp[13] = (unsigned char)mul9[state[12]] ^ mul14[state[13]] ^ mul11[state[14]] ^ mul13[state[15]]; + tmp[14] = (unsigned char)mul13[state[12]] ^ mul9[state[13]] ^ mul14[state[14]] ^ mul11[state[15]]; + tmp[15] = (unsigned char)mul11[state[12]] ^ mul13[state[13]] ^ mul9[state[14]] ^ mul14[state[15]]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +// Shifts rows right (rather than left) for decryption +void DecryptShiftRows(unsigned char * state) { + unsigned char tmp[16]; + + /* Column 1 */ + tmp[0] = state[0]; + tmp[1] = state[13]; + tmp[2] = state[10]; + tmp[3] = state[7]; + + /* Column 2 */ + tmp[4] = state[4]; + tmp[5] = state[1]; + tmp[6] = state[14]; + tmp[7] = state[11]; + + /* Column 3 */ + tmp[8] = state[8]; + tmp[9] = state[5]; + tmp[10] = state[2]; + tmp[11] = state[15]; + + /* Column 4 */ + tmp[12] = state[12]; + tmp[13] = state[9]; + tmp[14] = state[6]; + tmp[15] = state[3]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +/* Perform substitution to each of the 16 bytes +* Uses inverse S-box as lookup table +*/ +void DecryptSubBytes(unsigned char * state) { + for (int i = 0; i < 16; i++) { // Perform substitution to each of the 16 bytes + state[i] = inv_s[state[i]]; + } +} + +/* Each round operates on 128 bits at a time +* The number of rounds is defined in AESDecrypt() +* Not surprisingly, the steps are the encryption steps but reversed +*/ +void DecryptRound(unsigned char * state, unsigned char * key) { + SubRoundKey(state, key); + InverseMixColumns(state); + DecryptShiftRows(state); + DecryptSubBytes(state); +} + +// Same as Round() but no InverseMixColumns +void InitialRound(unsigned char * state, unsigned char * key) { + SubRoundKey(state, key); + DecryptShiftRows(state); + DecryptSubBytes(state); +} + +/* The AES decryption function +* Organizes all the decryption steps into one function +*/ +void AESDecrypt(unsigned char * encryptedMessage, unsigned char * expandedKey, unsigned char * decryptedMessage) +{ + unsigned char state[16]; // Stores the first 16 bytes of encrypted message + + for (int i = 0; i < 16; i++) { + state[i] = encryptedMessage[i]; + } + + InitialRound(state, expandedKey + 160); + + for (int i = 8; i >= 0; i--) { + DecryptRound(state, expandedKey + (16 * (i + 1))); + } + + SubRoundKey(state, expandedKey); // Final round + + // Copy decrypted state to buffer + for (int i = 0; i < 16; i++) { + decryptedMessage[i] = state[i]; + } +} + +void AESDecryptFileToFile(const char* inFile, unsigned char * expandedKey, const char* outFile) +{ + // Nɮ inFile ѱKɮ outFile + char data[16]; + char decrypt[16]; + + std::ifstream in; + std::ofstream out; + in.open(inFile, std::ios::binary); + out.open(outFile, std::ios::binary | std::ios::trunc); + + while (in.read((char*)data, sizeof(data))) + { + AESDecrypt((unsigned char *)data, expandedKey, (unsigned char *)decrypt); + out.write(decrypt, sizeof(decrypt)); + memset(data, 0x00, sizeof(data)); + } + in.close(); + out.close(); +} +size_t AESDecryptFileToArray(const char* inFile, unsigned char * expandedKey, char* outArray, size_t outArraySize) +{ + // Nɮ inFile ѱKr}C outArray + // Please notice the length of outArray must be larger than decrypted result + char data[16]; + char decrypt[16]; + size_t decrypt_size = 0; + + std::ifstream in; + + in.open(inFile, std::ios::binary); + in.seekg(0, std::ios::end); + //int file_size = in.tellg(); + in.seekg(0, std::ios::beg); + + while (in.read(data, sizeof(data))) + { + AESDecrypt((unsigned char *)data, expandedKey, (unsigned char *)decrypt); + if (outArraySize < decrypt_size + sizeof(decrypt)) + { + //resize(outArray, decrypt_size + sizeof(decrypt)); + //outArray = Resize(outArray, outArraySize, decrypt_size + sizeof(decrypt)); + printf("[AESDecryptFileToArray]outArraySize is too small."); + break; + } + memcpy(outArray + decrypt_size, decrypt, sizeof(decrypt)); + decrypt_size += sizeof(decrypt); + memset(data, 0x00, sizeof(data)); + } + //if (in.gcount() > 0) { + // AESEncrypt((unsigned char *)data, expandedKey, (unsigned char *)decrypt); + // //memcpy(outArray + decrypt_size, decrypt, sizeof(decrypt)); + // if (decrypt_size + sizeof(decrypt) > file_size) + // { + // memcpy(outArray + decrypt_size, decrypt, file_size - decrypt_size); + // } + // decrypt_size += (file_size - decrypt_size); + //} + in.close(); + return decrypt_size; +} + +size_t AESDecryptFileToArrayPercent(const char* inFile, unsigned char * expandedKey, char* outArray, size_t outArraySize, size_t encrypt_len) +{ + // Nɮ inFile ѱKr}C outArray + // Please notice the length of outArray must be larger than decrypted result + char data[16]; + char decrypt[16]; + size_t decrypt_size = 0; + size_t total_size = 0; + + std::ifstream in; + in.open(inFile, std::ios::binary); + in.seekg(0, std::ios::end); + size_t file_size = in.tellg(); + int n_percent_len = file_size / 33; + int n_percent_decrypt_size = 0; + in.seekg(0, std::ios::beg); + + while (in.read(data, sizeof(data))) + { + if (decrypt_size < encrypt_len) + { + AESDecrypt((unsigned char *)data, expandedKey, (unsigned char *)decrypt); + if (outArraySize < decrypt_size + sizeof(decrypt)) + { + //resize(outArray, decrypt_size + sizeof(decrypt)); + //outArray = Resize(outArray, outArraySize, decrypt_size + sizeof(decrypt)); + printf("[AESDecryptFileToArray]outArraySize is too small."); + break; + } + memcpy(outArray + decrypt_size, decrypt, sizeof(decrypt)); + decrypt_size += sizeof(decrypt); + total_size += sizeof(decrypt); + } + else + { + memcpy(outArray + total_size, data, sizeof(data)); + total_size += sizeof(data); + } + + memset(data, 0x00, sizeof(data)); + n_percent_decrypt_size += sizeof(data); + if (n_percent_decrypt_size >= n_percent_len) + { + fprintf(stderr, "\rLoading weights from %s...%ld%%", inFile, (long int)(total_size * 100 / file_size)); + n_percent_decrypt_size = 0; + } + } + + fprintf(stderr, "\rLoading weights from %s...%ld%%", inFile, (long int)(total_size * 100 / file_size)); + in.close(); + return total_size; +} + +void AESDecryptArrayToFile(char* inArray, size_t inArraySize, unsigned char * expandedKey, const char* outFile) +{ + // Nr}C inArray ѱKɮ outFile + char data[16]; + char decrypt[16]; + + std::ofstream out; + out.open(outFile, std::ios::binary | std::ios::trunc); + + for (size_t i = 0; i < inArraySize; i += sizeof(data)) + { + if (i + sizeof(data) > inArraySize) + { + memcpy(data, inArray + i, inArraySize - i); + } + else + memcpy(data, inArray + i, sizeof(data)); + AESDecrypt((unsigned char *)data, expandedKey, (unsigned char *)decrypt); + out.write(decrypt, sizeof(data)); + memset(data, 0x00, sizeof(data)); + } + out.close(); +} +size_t AESDecryptArrayToArray(char* inArray, size_t inArraySize, unsigned char * expandedKey, char* outArray, size_t outArraySize) +{ + // Nr}C inArray [Kr}C outArray + char data[16]; + char decrypt[16]; + size_t decrypt_size = 0; + + for (size_t i = 0; i < inArraySize; i += sizeof(data)) + { + if (i + sizeof(data) > inArraySize) + { + memcpy(data, inArray + i, inArraySize - i); + } + else + memcpy(data, inArray + i, sizeof(data)); + AESDecrypt((unsigned char *)data, expandedKey, (unsigned char *)decrypt); + if (outArraySize < decrypt_size + sizeof(decrypt)) + { + //resize(outArray, decrypt_size + sizeof(decrypt)); + //outArray = Resize(outArray, outArraySize, decrypt_size + sizeof(decrypt)); + printf("[AESDecryptArrayToArray]outArraySize is too small."); + break; + } + memcpy(outArray + decrypt_size, decrypt, sizeof(decrypt)); + decrypt_size += sizeof(decrypt); + memset(data, 0x00, sizeof(data)); + } + return decrypt_size; +} + +void base64_encode(const unsigned char *data, size_t input_length, size_t *output_length,char *encoded_data) +{ + *output_length = 4 * ((input_length + 2) / 3); + if (*output_length <= 0) { + + } + else { + for (size_t i = 0, j = 0; i < input_length;) { + + uint32_t octet_a = i < input_length ? (unsigned char)data[i++] : 0; + uint32_t octet_b = i < input_length ? (unsigned char)data[i++] : 0; + uint32_t octet_c = i < input_length ? (unsigned char)data[i++] : 0; + + uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; + + encoded_data[j++] = encoding_table[(triple >> 3 * 6) & 0x3F]; + encoded_data[j++] = encoding_table[(triple >> 2 * 6) & 0x3F]; + encoded_data[j++] = encoding_table[(triple >> 1 * 6) & 0x3F]; + encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F]; + } + + for (int i = 0; i < mod_table[input_length % 3]; i++) + encoded_data[*output_length - 1 - i] = '='; + } +} + +void base64_decode(const char *data, size_t input_length, size_t *output_length, unsigned char * decoded_data) +{ + + if (decoding_table == NULL) + build_decoding_table(); + + if (input_length % 4 != 0){} + else { + *output_length = input_length / 4 * 3; + if (data[input_length - 1] == '=') (*output_length)--; + if (data[input_length - 2] == '=') (*output_length)--; + + if (*output_length <= 0) {} + else { + for (size_t i = 0, j = 0; i < input_length;) { + + uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[(int)data[i++]]; + uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[(int)data[i++]]; + uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[(int)data[i++]]; + uint32_t sextet_d = data[i] == '=' ? 0 & i++ : decoding_table[(int)data[i++]]; + + uint32_t triple = (sextet_a << 3 * 6) + + (sextet_b << 2 * 6) + + (sextet_c << 1 * 6) + + (sextet_d << 0 * 6); + + if (j < *output_length) decoded_data[j++] = (triple >> 2 * 8) & 0xFF; + if (j < *output_length) decoded_data[j++] = (triple >> 1 * 8) & 0xFF; + if (j < *output_length) decoded_data[j++] = (triple >> 0 * 8) & 0xFF; + } + } + } +} + +void build_decoding_table() { + + decoding_table = (char *)malloc(256); + + for (int i = 0; i < 64; i++) + decoding_table[(unsigned char)encoding_table[i]] = i; +} + +void base64_cleanup() { + if (decoding_table != NULL) { + free(decoding_table); + decoding_table = NULL; + } +} diff --git a/src/cryptionPlus.h b/src/cryptionPlus.h new file mode 100644 index 0000000..12afb37 --- /dev/null +++ b/src/cryptionPlus.h @@ -0,0 +1,82 @@ +#pragma once +#ifndef CRYPTIONPLUS_H +#define CRYPTIONPLUS_H + +#ifdef __cplusplus +extern "C" { +#include "define_inc.h" +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include "structures.h" +#endif + + extern unsigned char key[16]; + extern unsigned char expandedKey[176]; + +#ifdef GY_OS_AMBA + /* + static unsigned char key_email[16] = + { + 0x49, 0x56, 0x53, 0x43, + 0x4F, 0x65, 0x6D, 0x63, + 0x6B, 0x64, 0x73, 0x32, + 0x34, 0x38, 0x5A, 0x65 + };*/ + //IVSCOemckds248Ze + + //static unsigned char expandedKey_email[176]; //AES-128 XiK_Tw +#endif + + + static const char encoding_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/' }; + static const int mod_table[] = { 0, 2, 1 }; + + // The AES encryption function + //void AddRoundKey(unsigned char * state, unsigned char * roundKey); + //void EncryptSubBytes(unsigned char * state); + //void EncryptShiftRows(unsigned char * state); + //void MixColumns(unsigned char * state); + //void EncryptRound(unsigned char * state, unsigned char * key); + //void FinalRound(unsigned char * state, unsigned char * key); + void AESEncrypt(unsigned char * message, unsigned char * expandedKey, unsigned char * encryptedMessage); + void AESEncryptFileToFile(const char* inFile, unsigned char * expandedKey, const char* outFile, size_t encrypt_len); + size_t AESEncryptFileToArray(const char* inFile, unsigned char * expandedKey, char* outArray, size_t outArraySize); + void AESEncryptArrayToFile(char* inArray, size_t inArraySize, unsigned char * expandedKey, const char* outFile); + size_t AESEncryptArrayToArray(char* inArray, size_t inArraySize, unsigned char * expandedKey, unsigned char* outArray, size_t outArraySize); + + // The AES decryption function + //void SubRoundKey(unsigned char * state, unsigned char * roundKey); + //void InverseMixColumns(unsigned char * state); + //void DecryptShiftRows(unsigned char * state); + //void DecryptSubBytes(unsigned char * state); + //void DecryptRound(unsigned char * state, unsigned char * key); + //void InitialRound(unsigned char * state, unsigned char * key); + void AESDecrypt(unsigned char * encryptedMessage, unsigned char * expandedKey, unsigned char * decryptedMessage); + void AESDecryptFileToFile(const char* inFile, unsigned char * expandedKey, const char* outFile); + size_t AESDecryptFileToArray(const char* inFile, unsigned char * expandedKey, char* outArray, size_t outArraySize); + size_t AESDecryptFileToArrayPercent(const char* inFile, unsigned char * expandedKey, char* outArray, size_t outArraySize, size_t encrypt_len); + void AESDecryptArrayToFile(char* inArray, size_t inArraySize, unsigned char * expandedKey, char* const outFile); + size_t AESDecryptArrayToArray(char* inArray, size_t inArraySize, unsigned char * expandedKey, char* outArray, size_t outArraySize); + + //base64 encode/decode function + void build_decoding_table(); + void base64_encode(const unsigned char *data, size_t input_length, size_t *output_length, char *encoded_data); + void base64_decode(const char *data, size_t input_length, size_t *output_length, unsigned char * decoded_data); + void base64_cleanup(); + + extern int LILIN_File_Decryption(char* source_file, char* dest_file, unsigned char* key_ptr, int original_length, int debug_mode); + //extern int LILIN_File_Encryption(char* source_file, char* dest_file, unsigned char* key_ptr, long* returned_length, int debug_mode); +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/cuda.c b/src/cuda.c new file mode 100644 index 0000000..265df2e --- /dev/null +++ b/src/cuda.c @@ -0,0 +1,184 @@ +int gpu_index = 0; + +#ifdef GPU + +#include "cuda.h" +#include "utils.h" +#include "blas.h" +#include <assert.h> +#include <stdlib.h> +#include <time.h> + +void cuda_set_device(int n) +{ + gpu_index = n; + cudaError_t status = cudaSetDevice(n); + check_error(status); +} + +int cuda_get_device() +{ + int n = 0; + cudaError_t status = cudaGetDevice(&n); + check_error(status); + return n; +} + +void check_error(cudaError_t status) +{ + //cudaDeviceSynchronize(); + cudaError_t status2 = cudaGetLastError(); + if (status != cudaSuccess) + { + const char *s = cudaGetErrorString(status); + char buffer[256]; + printf("CUDA Error: %s\n", s); + assert(0); + snprintf(buffer, 256, "CUDA Error: %s", s); + error(buffer); + } + if (status2 != cudaSuccess) + { + const char *s = cudaGetErrorString(status); + char buffer[256]; + printf("CUDA Error Prev: %s\n", s); + assert(0); + snprintf(buffer, 256, "CUDA Error Prev: %s", s); + error(buffer); + } +} + +dim3 cuda_gridsize(size_t n){ + size_t k = (n-1) / BLOCK + 1; + size_t x = k; + size_t y = 1; + if(x > 65535){ + x = ceil(sqrt(k)); + y = (n-1)/(x*BLOCK) + 1; + } + dim3 d = {x, y, 1}; + //printf("%ld %ld %ld %ld\n", n, x, y, x*y*BLOCK); + return d; +} + +#ifdef CUDNN +cudnnHandle_t cudnn_handle() +{ + static int init[16] = {0}; + static cudnnHandle_t handle[16]; + int i = cuda_get_device(); + if(!init[i]) { + cudnnCreate(&handle[i]); + init[i] = 1; + } + return handle[i]; +} +#endif + +cublasHandle_t blas_handle() +{ + static int init[16] = {0}; + static cublasHandle_t handle[16]; + int i = cuda_get_device(); + if(!init[i]) { + cublasCreate(&handle[i]); + init[i] = 1; + } + return handle[i]; +} + +float *cuda_make_array(float *x, size_t n) +{ + float *x_gpu; + size_t size = sizeof(float)*n; + cudaError_t status = cudaMalloc((void **)&x_gpu, size); + check_error(status); + if(x){ + status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice); + check_error(status); + } else { + fill_gpu(n, 0, x_gpu, 1); + } + if(!x_gpu) error("Cuda malloc failed\n"); + return x_gpu; +} + +void cuda_random(float *x_gpu, size_t n) +{ + static curandGenerator_t gen[16]; + static int init[16] = {0}; + int i = cuda_get_device(); + if(!init[i]){ + curandCreateGenerator(&gen[i], CURAND_RNG_PSEUDO_DEFAULT); + curandSetPseudoRandomGeneratorSeed(gen[i], time(0)); + init[i] = 1; + } + curandGenerateUniform(gen[i], x_gpu, n); + check_error(cudaPeekAtLastError()); +} + +float cuda_compare(float *x_gpu, float *x, size_t n, char *s) +{ + float *tmp = calloc(n, sizeof(float)); + cuda_pull_array(x_gpu, tmp, n); + //int i; + //for(i = 0; i < n; ++i) printf("%f %f\n", tmp[i], x[i]); + axpy_cpu(n, -1, x, 1, tmp, 1); + float err = dot_cpu(n, tmp, 1, tmp, 1); + printf("Error %s: %f\n", s, sqrt(err/n)); + if (tmp) { + free(tmp); + tmp = NULL; + } + return err; +} + +int *cuda_make_int_array(int *x, size_t n) +{ + int *x_gpu; + size_t size = sizeof(int)*n; + cudaError_t status = cudaMalloc((void **)&x_gpu, size); + check_error(status); + if(x){ + status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice); + check_error(status); + } + if(!x_gpu) error("Cuda malloc failed\n"); + return x_gpu; +} + +void cuda_free(float *x_gpu) +{ + cudaError_t status = cudaFree(x_gpu); + check_error(status); +} + +void cuda_push_array(float *x_gpu, float *x, size_t n) +{ + size_t size = sizeof(float)*n; + cudaError_t status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice); + check_error(status); +} + +void cuda_pull_array(float *x_gpu, float *x, size_t n) +{ + size_t size = sizeof(float)*n; + cudaError_t status = cudaMemcpy(x, x_gpu, size, cudaMemcpyDeviceToHost); + check_error(status); +} + +float cuda_mag_array(float *x_gpu, size_t n) +{ + float *temp = calloc(n, sizeof(float)); + cuda_pull_array(x_gpu, temp, n); + float m = mag_array(temp, n); + if (temp) { + free(temp); + temp = NULL; + } + return m; +} +#else +void cuda_set_device(int n){} + +#endif diff --git a/src/cuda.h b/src/cuda.h new file mode 100644 index 0000000..192e017 --- /dev/null +++ b/src/cuda.h @@ -0,0 +1,32 @@ +#pragma once +#ifndef CUDA_H +#define CUDA_H +#include "define_inc.h" +#include "darknet.h" + +extern int gpu_index; + +#ifdef GPU +#define BLOCK 512 + +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +#ifdef CUDNN +#include "cudnn.h" +#endif + +void check_error(cudaError_t status); +cublasHandle_t blas_handle(); +int *cuda_make_int_array(int *x, size_t n); +void cuda_random(float *x_gpu, size_t n); +float cuda_compare(float *x_gpu, float *x, size_t n, char *s); +dim3 cuda_gridsize(size_t n); + +#ifdef CUDNN +cudnnHandle_t cudnn_handle(); +#endif + +#endif +#endif diff --git a/src/curl/Makefile b/src/curl/Makefile new file mode 100644 index 0000000..12ee886 --- /dev/null +++ b/src/curl/Makefile @@ -0,0 +1,714 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# include/curl/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/curl +pkglibdir = $(libdir)/curl +pkglibexecdir = $(libexecdir)/curl +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = x86_64-pc-linux-gnu +host_triplet = x86_64-pc-linux-gnu +subdir = include/curl +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compile_check_sizeof.m4 \ + $(top_srcdir)/m4/curl-amissl.m4 \ + $(top_srcdir)/m4/curl-bearssl.m4 \ + $(top_srcdir)/m4/curl-compilers.m4 \ + $(top_srcdir)/m4/curl-confopts.m4 \ + $(top_srcdir)/m4/curl-functions.m4 \ + $(top_srcdir)/m4/curl-gnutls.m4 \ + $(top_srcdir)/m4/curl-mbedtls.m4 \ + $(top_srcdir)/m4/curl-mesalink.m4 $(top_srcdir)/m4/curl-nss.m4 \ + $(top_srcdir)/m4/curl-openssl.m4 \ + $(top_srcdir)/m4/curl-override.m4 \ + $(top_srcdir)/m4/curl-reentrant.m4 \ + $(top_srcdir)/m4/curl-rustls.m4 \ + $(top_srcdir)/m4/curl-schannel.m4 \ + $(top_srcdir)/m4/curl-sectransp.m4 \ + $(top_srcdir)/m4/curl-sysconfig.m4 \ + $(top_srcdir)/m4/curl-wolfssl.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/xc-am-iface.m4 \ + $(top_srcdir)/m4/xc-cc-check.m4 \ + $(top_srcdir)/m4/xc-lt-iface.m4 \ + $(top_srcdir)/m4/xc-translit.m4 \ + $(top_srcdir)/m4/xc-val-flgs.m4 \ + $(top_srcdir)/m4/zz40-xc-ovr.m4 \ + $(top_srcdir)/m4/zz50-xc-ovr.m4 \ + $(top_srcdir)/m4/zz60-xc-ovr.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(pkginclude_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/lib/curl_config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(pkgincludedir)" +HEADERS = $(pkginclude_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkgincludedir = $(includedir)/curl +ACLOCAL = ${SHELL} '/media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/missing' aclocal-1.16 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 0 +AR = /usr/bin/ar +AR_FLAGS = cr +AS = as +AUTOCONF = ${SHELL} '/media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/missing' autoconf +AUTOHEADER = ${SHELL} '/media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/missing' autoheader +AUTOMAKE = ${SHELL} '/media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/missing' automake-1.16 +AWK = gawk +BLANK_AT_MAKETIME = +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -Werror-implicit-function-declaration -O2 -Wno-system-headers -pthread +CFLAG_CURL_SYMBOL_HIDING = -fvisibility=hidden +CONFIGURE_OPTIONS = " '--prefix=/usr/local/curl' '--disable-shared' '--enable-static' '--without-libidn' '--without-ssl' '--without-librtmp' '--without-gnutls' '--without-nss' '--without-libssh2' '--without-zlib' '--without-winidn' '--disable-rtsp' '--disable-ldap' '--disable-ldaps' '--disable-ipv6'" +CPP = gcc -E +CPPFLAGS = +CPPFLAG_CURL_STATICLIB = -DCURL_STATICLIB +CURLVERSION = 7.78.0 +CURL_CA_BUNDLE = +CURL_CFLAG_EXTRAS = +CURL_DISABLE_DICT = +CURL_DISABLE_FILE = +CURL_DISABLE_FTP = +CURL_DISABLE_GOPHER = +CURL_DISABLE_HTTP = +CURL_DISABLE_IMAP = +CURL_DISABLE_LDAP = 1 +CURL_DISABLE_LDAPS = 1 +CURL_DISABLE_MQTT = +CURL_DISABLE_POP3 = +CURL_DISABLE_PROXY = +CURL_DISABLE_RTSP = 1 +CURL_DISABLE_SMB = +CURL_DISABLE_SMTP = +CURL_DISABLE_TELNET = +CURL_DISABLE_TFTP = +CURL_LT_SHLIB_VERSIONED_FLAVOUR = +CURL_NETWORK_AND_TIME_LIBS = +CURL_NETWORK_LIBS = +CURL_WITH_MULTI_SSL = +CYGPATH_W = echo +DEFAULT_SSL_BACKEND = no +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +DLLTOOL = false +DSYMUTIL = +DUMPBIN = +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +ENABLE_SHARED = no +ENABLE_STATIC = yes +EXEEXT = +FGREP = /bin/grep -F +FISH_FUNCTIONS_DIR = ${prefix}/share/fish/vendor_completions.d +GCOV = +GREP = /bin/grep +HAVE_BROTLI = +HAVE_GNUTLS_SRP = +HAVE_LDAP_SSL = +HAVE_LIBZ = +HAVE_OPENSSL_SRP = +HAVE_PROTO_BSDSOCKET_H = +HAVE_ZSTD = +IDN_ENABLED = +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +IPV6_ENABLED = +LCOV = +LD = /usr/bin/ld -m elf_x86_64 +LDFLAGS = +LIBCURL_LIBS = -pthread +LIBCURL_NO_SHARED = -pthread +LIBOBJS = +LIBS = +LIBTOOL = $(SHELL) $(top_builddir)/libtool +LIPO = +LN_S = cp -pR +LTLIBOBJS = +LT_SYS_LIBRARY_PATH = +MAINT = # +MAKEINFO = ${SHELL} '/media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/missing' makeinfo +MANIFEST_TOOL = : +MANOPT = -man +MKDIR_P = /bin/mkdir -p +NM = /usr/bin/nm -B +NMEDIT = +NROFF = /usr/bin/nroff +NSS_LIBS = +OBJDUMP = objdump +OBJEXT = o +OTOOL = +OTOOL64 = +PACKAGE = curl +PACKAGE_BUGREPORT = a suitable curl mailing list: https://curl.se/mail/ +PACKAGE_NAME = curl +PACKAGE_STRING = curl - +PACKAGE_TARNAME = curl +PACKAGE_URL = +PACKAGE_VERSION = - +PATH_SEPARATOR = : +PERL = /usr/bin/perl +PKGADD_NAME = curl - a client that groks URLs +PKGADD_PKG = HAXXcurl +PKGADD_VENDOR = curl.se +PKGCONFIG = no +RANDOM_FILE = +RANLIB = ranlib +REQUIRE_LIB_DEPS = yes +SED = /bin/sed +SET_MAKE = +SHELL = /bin/bash +SSL_BACKENDS = +SSL_ENABLED = +SSL_LIBS = +STRIP = strip +SUPPORT_FEATURES = AsynchDNS Largefile UnixSockets alt-svc +SUPPORT_PROTOCOLS = DICT FILE FTP GOPHER HTTP IMAP MQTT POP3 SMTP TELNET TFTP +USE_ARES = +USE_BEARSSL = +USE_GNUTLS = +USE_HYPER = +USE_LIBRTMP = +USE_LIBSSH = +USE_LIBSSH2 = +USE_MBEDTLS = +USE_MESALINK = +USE_NGHTTP2 = +USE_NGHTTP3 = +USE_NGTCP2 = +USE_NGTCP2_CRYPTO_GNUTLS = +USE_NGTCP2_CRYPTO_OPENSSL = +USE_NSS = +USE_OPENLDAP = +USE_QUICHE = +USE_RUSTLS = +USE_SCHANNEL = +USE_SECTRANSP = +USE_UNIX_SOCKETS = 1 +USE_WIN32_CRYPTO = +USE_WIN32_LARGE_FILES = +USE_WIN32_SMALL_FILES = +USE_WINDOWS_SSPI = +USE_WOLFSSH = +USE_WOLFSSL = +VERSION = - +VERSIONNUM = 074e00 +ZLIB_LIBS = +ZSH_FUNCTIONS_DIR = ${prefix}/share/zsh/site-functions +abs_builddir = /media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/include/curl +abs_srcdir = /media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/include/curl +abs_top_builddir = /media/sf_AIUbuntu/AIUbuntu/curl-7.78.0 +abs_top_srcdir = /media/sf_AIUbuntu/AIUbuntu/curl-7.78.0 +ac_ct_AR = +ac_ct_CC = gcc +ac_ct_DUMPBIN = +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build = x86_64-pc-linux-gnu +build_alias = +build_cpu = x86_64 +build_os = linux-gnu +build_vendor = pc +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host = x86_64-pc-linux-gnu +host_alias = +host_cpu = x86_64 +host_os = linux-gnu +host_vendor = pc +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /media/sf_AIUbuntu/AIUbuntu/curl-7.78.0/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +libext = a +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local/curl +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +subdirs = +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../../ +top_builddir = ../.. +top_srcdir = ../.. + +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +########################################################################### +pkginclude_HEADERS = \ + curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \ + typecheck-gcc.h system.h urlapi.h options.h + +CHECKSRC = $(CS_$(V)) +CS_0 = @echo " RUN " $@; +CS_1 = +CS_ = $(CS_0) +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/curl/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign include/curl/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: # $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): # $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkgincludedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(pkgincludedir)'; $(am__uninstall_files_from_dir) + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-local: +all-am: Makefile $(HEADERS) all-local +installdirs: + for dir in "$(DESTDIR)$(pkgincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-pkgincludeHEADERS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkgincludeHEADERS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am all-local check check-am clean \ + clean-generic clean-libtool cscopelist-am ctags ctags-am \ + distclean distclean-generic distclean-libtool distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-pkgincludeHEADERS \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-pkgincludeHEADERS + +.PRECIOUS: Makefile + + +checksrc: + $(CHECKSRC)/usr/bin/perl $(top_srcdir)/lib/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS) + +# for debug builds, we scan the sources on all regular make invokes +#all-local: checksrc + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/curl/Makefile.am b/src/curl/Makefile.am new file mode 100644 index 0000000..e772737 --- /dev/null +++ b/src/curl/Makefile.am @@ -0,0 +1,39 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +########################################################################### +pkginclude_HEADERS = \ + curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \ + typecheck-gcc.h system.h urlapi.h options.h + +pkgincludedir= $(includedir)/curl + +CHECKSRC = $(CS_$(V)) +CS_0 = @echo " RUN " $@; +CS_1 = +CS_ = $(CS_0) + +checksrc: + $(CHECKSRC)@PERL@ $(top_srcdir)/lib/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS) + +if CURLDEBUG +# for debug builds, we scan the sources on all regular make invokes +all-local: checksrc +endif diff --git a/src/curl/Makefile.in b/src/curl/Makefile.in new file mode 100644 index 0000000..ed8b594 --- /dev/null +++ b/src/curl/Makefile.in @@ -0,0 +1,714 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = include/curl +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compile_check_sizeof.m4 \ + $(top_srcdir)/m4/curl-amissl.m4 \ + $(top_srcdir)/m4/curl-bearssl.m4 \ + $(top_srcdir)/m4/curl-compilers.m4 \ + $(top_srcdir)/m4/curl-confopts.m4 \ + $(top_srcdir)/m4/curl-functions.m4 \ + $(top_srcdir)/m4/curl-gnutls.m4 \ + $(top_srcdir)/m4/curl-mbedtls.m4 \ + $(top_srcdir)/m4/curl-mesalink.m4 $(top_srcdir)/m4/curl-nss.m4 \ + $(top_srcdir)/m4/curl-openssl.m4 \ + $(top_srcdir)/m4/curl-override.m4 \ + $(top_srcdir)/m4/curl-reentrant.m4 \ + $(top_srcdir)/m4/curl-rustls.m4 \ + $(top_srcdir)/m4/curl-schannel.m4 \ + $(top_srcdir)/m4/curl-sectransp.m4 \ + $(top_srcdir)/m4/curl-sysconfig.m4 \ + $(top_srcdir)/m4/curl-wolfssl.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/xc-am-iface.m4 \ + $(top_srcdir)/m4/xc-cc-check.m4 \ + $(top_srcdir)/m4/xc-lt-iface.m4 \ + $(top_srcdir)/m4/xc-translit.m4 \ + $(top_srcdir)/m4/xc-val-flgs.m4 \ + $(top_srcdir)/m4/zz40-xc-ovr.m4 \ + $(top_srcdir)/m4/zz50-xc-ovr.m4 \ + $(top_srcdir)/m4/zz60-xc-ovr.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(pkginclude_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/lib/curl_config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(pkgincludedir)" +HEADERS = $(pkginclude_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +pkgincludedir = $(includedir)/curl +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AR_FLAGS = @AR_FLAGS@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BLANK_AT_MAKETIME = @BLANK_AT_MAKETIME@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CFLAG_CURL_SYMBOL_HIDING = @CFLAG_CURL_SYMBOL_HIDING@ +CONFIGURE_OPTIONS = @CONFIGURE_OPTIONS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CPPFLAG_CURL_STATICLIB = @CPPFLAG_CURL_STATICLIB@ +CURLVERSION = @CURLVERSION@ +CURL_CA_BUNDLE = @CURL_CA_BUNDLE@ +CURL_CFLAG_EXTRAS = @CURL_CFLAG_EXTRAS@ +CURL_DISABLE_DICT = @CURL_DISABLE_DICT@ +CURL_DISABLE_FILE = @CURL_DISABLE_FILE@ +CURL_DISABLE_FTP = @CURL_DISABLE_FTP@ +CURL_DISABLE_GOPHER = @CURL_DISABLE_GOPHER@ +CURL_DISABLE_HTTP = @CURL_DISABLE_HTTP@ +CURL_DISABLE_IMAP = @CURL_DISABLE_IMAP@ +CURL_DISABLE_LDAP = @CURL_DISABLE_LDAP@ +CURL_DISABLE_LDAPS = @CURL_DISABLE_LDAPS@ +CURL_DISABLE_MQTT = @CURL_DISABLE_MQTT@ +CURL_DISABLE_POP3 = @CURL_DISABLE_POP3@ +CURL_DISABLE_PROXY = @CURL_DISABLE_PROXY@ +CURL_DISABLE_RTSP = @CURL_DISABLE_RTSP@ +CURL_DISABLE_SMB = @CURL_DISABLE_SMB@ +CURL_DISABLE_SMTP = @CURL_DISABLE_SMTP@ +CURL_DISABLE_TELNET = @CURL_DISABLE_TELNET@ +CURL_DISABLE_TFTP = @CURL_DISABLE_TFTP@ +CURL_LT_SHLIB_VERSIONED_FLAVOUR = @CURL_LT_SHLIB_VERSIONED_FLAVOUR@ +CURL_NETWORK_AND_TIME_LIBS = @CURL_NETWORK_AND_TIME_LIBS@ +CURL_NETWORK_LIBS = @CURL_NETWORK_LIBS@ +CURL_WITH_MULTI_SSL = @CURL_WITH_MULTI_SSL@ +CYGPATH_W = @CYGPATH_W@ +DEFAULT_SSL_BACKEND = @DEFAULT_SSL_BACKEND@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ENABLE_SHARED = @ENABLE_SHARED@ +ENABLE_STATIC = @ENABLE_STATIC@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +FISH_FUNCTIONS_DIR = @FISH_FUNCTIONS_DIR@ +GCOV = @GCOV@ +GREP = @GREP@ +HAVE_BROTLI = @HAVE_BROTLI@ +HAVE_GNUTLS_SRP = @HAVE_GNUTLS_SRP@ +HAVE_LDAP_SSL = @HAVE_LDAP_SSL@ +HAVE_LIBZ = @HAVE_LIBZ@ +HAVE_OPENSSL_SRP = @HAVE_OPENSSL_SRP@ +HAVE_PROTO_BSDSOCKET_H = @HAVE_PROTO_BSDSOCKET_H@ +HAVE_ZSTD = @HAVE_ZSTD@ +IDN_ENABLED = @IDN_ENABLED@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +IPV6_ENABLED = @IPV6_ENABLED@ +LCOV = @LCOV@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBCURL_LIBS = @LIBCURL_LIBS@ +LIBCURL_NO_SHARED = @LIBCURL_NO_SHARED@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MANOPT = @MANOPT@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NROFF = @NROFF@ +NSS_LIBS = @NSS_LIBS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PKGADD_NAME = @PKGADD_NAME@ +PKGADD_PKG = @PKGADD_PKG@ +PKGADD_VENDOR = @PKGADD_VENDOR@ +PKGCONFIG = @PKGCONFIG@ +RANDOM_FILE = @RANDOM_FILE@ +RANLIB = @RANLIB@ +REQUIRE_LIB_DEPS = @REQUIRE_LIB_DEPS@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SSL_BACKENDS = @SSL_BACKENDS@ +SSL_ENABLED = @SSL_ENABLED@ +SSL_LIBS = @SSL_LIBS@ +STRIP = @STRIP@ +SUPPORT_FEATURES = @SUPPORT_FEATURES@ +SUPPORT_PROTOCOLS = @SUPPORT_PROTOCOLS@ +USE_ARES = @USE_ARES@ +USE_BEARSSL = @USE_BEARSSL@ +USE_GNUTLS = @USE_GNUTLS@ +USE_HYPER = @USE_HYPER@ +USE_LIBRTMP = @USE_LIBRTMP@ +USE_LIBSSH = @USE_LIBSSH@ +USE_LIBSSH2 = @USE_LIBSSH2@ +USE_MBEDTLS = @USE_MBEDTLS@ +USE_MESALINK = @USE_MESALINK@ +USE_NGHTTP2 = @USE_NGHTTP2@ +USE_NGHTTP3 = @USE_NGHTTP3@ +USE_NGTCP2 = @USE_NGTCP2@ +USE_NGTCP2_CRYPTO_GNUTLS = @USE_NGTCP2_CRYPTO_GNUTLS@ +USE_NGTCP2_CRYPTO_OPENSSL = @USE_NGTCP2_CRYPTO_OPENSSL@ +USE_NSS = @USE_NSS@ +USE_OPENLDAP = @USE_OPENLDAP@ +USE_QUICHE = @USE_QUICHE@ +USE_RUSTLS = @USE_RUSTLS@ +USE_SCHANNEL = @USE_SCHANNEL@ +USE_SECTRANSP = @USE_SECTRANSP@ +USE_UNIX_SOCKETS = @USE_UNIX_SOCKETS@ +USE_WIN32_CRYPTO = @USE_WIN32_CRYPTO@ +USE_WIN32_LARGE_FILES = @USE_WIN32_LARGE_FILES@ +USE_WIN32_SMALL_FILES = @USE_WIN32_SMALL_FILES@ +USE_WINDOWS_SSPI = @USE_WINDOWS_SSPI@ +USE_WOLFSSH = @USE_WOLFSSH@ +USE_WOLFSSL = @USE_WOLFSSL@ +VERSION = @VERSION@ +VERSIONNUM = @VERSIONNUM@ +ZLIB_LIBS = @ZLIB_LIBS@ +ZSH_FUNCTIONS_DIR = @ZSH_FUNCTIONS_DIR@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +libext = @libext@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ + +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +########################################################################### +pkginclude_HEADERS = \ + curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \ + typecheck-gcc.h system.h urlapi.h options.h + +CHECKSRC = $(CS_$(V)) +CS_0 = @echo " RUN " $@; +CS_1 = +CS_ = $(CS_0) +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/curl/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign include/curl/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkgincludedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(pkgincludedir)'; $(am__uninstall_files_from_dir) + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +@CURLDEBUG_FALSE@all-local: +all-am: Makefile $(HEADERS) all-local +installdirs: + for dir in "$(DESTDIR)$(pkgincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-pkgincludeHEADERS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkgincludeHEADERS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am all-local check check-am clean \ + clean-generic clean-libtool cscopelist-am ctags ctags-am \ + distclean distclean-generic distclean-libtool distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-pkgincludeHEADERS \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-pkgincludeHEADERS + +.PRECIOUS: Makefile + + +checksrc: + $(CHECKSRC)@PERL@ $(top_srcdir)/lib/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS) + +# for debug builds, we scan the sources on all regular make invokes +@CURLDEBUG_TRUE@all-local: checksrc + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/curl/curl.h b/src/curl/curl.h new file mode 100644 index 0000000..521c254 --- /dev/null +++ b/src/curl/curl.h @@ -0,0 +1,3070 @@ +#ifndef CURLINC_CURL_H +#define CURLINC_CURL_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * If you have libcurl problems, all docs and details are found here: + * https://curl.se/libcurl/ + * + * curl-library mailing list subscription and unsubscription web interface: + * https://cool.haxx.se/mailman/listinfo/curl-library/ + */ + +#ifdef CURL_NO_OLDIES +#define CURL_STRICTER +#endif + +#include "curlver.h" /* libcurl version defines */ +#include "system.h" /* determine things run-time */ + +/* + * Define CURL_WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && \ + !defined(__SYMBIAN32__) +#define CURL_WIN32 +#endif + +#include <stdio.h> +#include <limits.h> + +#if defined(__FreeBSD__) && (__FreeBSD__ >= 2) +/* Needed for __FreeBSD_version symbol definition */ +#include <osreldate.h> +#endif + +/* The include stuff here below is mainly for time_t! */ +#include <sys/types.h> +#include <time.h> + +#if defined(CURL_WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) +#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \ + defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)) +/* The check above prevents the winsock2 inclusion if winsock.h already was + included, since they can't co-exist without problems */ +#include <winsock2.h> +#include <ws2tcpip.h> +#endif +#endif + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on systems that are known to + require it! */ +#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ + defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ + defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \ + defined(__CYGWIN__) || defined(AMIGA) || defined(__NuttX__) || \ + (defined(__FreeBSD_version) && (__FreeBSD_version < 800000)) || \ + defined(__VXWORKS__) +#include <sys/select.h> +#endif + +#if !defined(CURL_WIN32) && !defined(_WIN32_WCE) +#include <sys/socket.h> +#endif + +#if !defined(CURL_WIN32) && !defined(__WATCOMC__) && !defined(__VXWORKS__) +#include <sys/time.h> +#endif + +#ifdef __BEOS__ +#include <support/SupportDefs.h> +#endif + +/* Compatibility for non-Clang compilers */ +#ifndef __has_declspec_attribute +# define __has_declspec_attribute(x) 0 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) +typedef struct Curl_easy CURL; +typedef struct Curl_share CURLSH; +#else +typedef void CURL; +typedef void CURLSH; +#endif + +/* + * libcurl external API function linkage decorations. + */ + +#ifdef CURL_STATICLIB +# define CURL_EXTERN +#elif defined(CURL_WIN32) || defined(__SYMBIAN32__) || \ + (__has_declspec_attribute(dllexport) && \ + __has_declspec_attribute(dllimport)) +# if defined(BUILDING_LIBCURL) +# define CURL_EXTERN __declspec(dllexport) +# else +# define CURL_EXTERN __declspec(dllimport) +# endif +#elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS) +# define CURL_EXTERN CURL_EXTERN_SYMBOL +#else +# define CURL_EXTERN +#endif + +#ifndef curl_socket_typedef +/* socket typedef */ +#if defined(CURL_WIN32) && !defined(__LWIP_OPT_H__) && !defined(LWIP_HDR_OPT_H) +typedef SOCKET curl_socket_t; +#define CURL_SOCKET_BAD INVALID_SOCKET +#else +typedef int curl_socket_t; +#define CURL_SOCKET_BAD -1 +#endif +#define curl_socket_typedef +#endif /* curl_socket_typedef */ + +/* enum for the different supported SSL backends */ +typedef enum { + CURLSSLBACKEND_NONE = 0, + CURLSSLBACKEND_OPENSSL = 1, + CURLSSLBACKEND_GNUTLS = 2, + CURLSSLBACKEND_NSS = 3, + CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */ + CURLSSLBACKEND_GSKIT = 5, + CURLSSLBACKEND_POLARSSL = 6, + CURLSSLBACKEND_WOLFSSL = 7, + CURLSSLBACKEND_SCHANNEL = 8, + CURLSSLBACKEND_SECURETRANSPORT = 9, + CURLSSLBACKEND_AXTLS = 10, /* never used since 7.63.0 */ + CURLSSLBACKEND_MBEDTLS = 11, + CURLSSLBACKEND_MESALINK = 12, + CURLSSLBACKEND_BEARSSL = 13, + CURLSSLBACKEND_RUSTLS = 14 +} curl_sslbackend; + +/* aliases for library clones and renames */ +#define CURLSSLBACKEND_LIBRESSL CURLSSLBACKEND_OPENSSL +#define CURLSSLBACKEND_BORINGSSL CURLSSLBACKEND_OPENSSL + +/* deprecated names: */ +#define CURLSSLBACKEND_CYASSL CURLSSLBACKEND_WOLFSSL +#define CURLSSLBACKEND_DARWINSSL CURLSSLBACKEND_SECURETRANSPORT + +struct curl_httppost { + struct curl_httppost *next; /* next entry in the list */ + char *name; /* pointer to allocated name */ + long namelength; /* length of name length */ + char *contents; /* pointer to allocated data contents */ + long contentslength; /* length of contents field, see also + CURL_HTTPPOST_LARGE */ + char *buffer; /* pointer to allocated buffer contents */ + long bufferlength; /* length of buffer field */ + char *contenttype; /* Content-Type */ + struct curl_slist *contentheader; /* list of extra headers for this form */ + struct curl_httppost *more; /* if one field name has more than one + file, this link should link to following + files */ + long flags; /* as defined below */ + +/* specified content is a file name */ +#define CURL_HTTPPOST_FILENAME (1<<0) +/* specified content is a file name */ +#define CURL_HTTPPOST_READFILE (1<<1) +/* name is only stored pointer do not free in formfree */ +#define CURL_HTTPPOST_PTRNAME (1<<2) +/* contents is only stored pointer do not free in formfree */ +#define CURL_HTTPPOST_PTRCONTENTS (1<<3) +/* upload file from buffer */ +#define CURL_HTTPPOST_BUFFER (1<<4) +/* upload file from pointer contents */ +#define CURL_HTTPPOST_PTRBUFFER (1<<5) +/* upload file contents by using the regular read callback to get the data and + pass the given pointer as custom pointer */ +#define CURL_HTTPPOST_CALLBACK (1<<6) +/* use size in 'contentlen', added in 7.46.0 */ +#define CURL_HTTPPOST_LARGE (1<<7) + + char *showfilename; /* The file name to show. If not set, the + actual file name will be used (if this + is a file part) */ + void *userp; /* custom pointer used for + HTTPPOST_CALLBACK posts */ + curl_off_t contentlen; /* alternative length of contents + field. Used if CURL_HTTPPOST_LARGE is + set. Added in 7.46.0 */ +}; + + +/* This is a return code for the progress callback that, when returned, will + signal libcurl to continue executing the default progress function */ +#define CURL_PROGRESSFUNC_CONTINUE 0x10000001 + +/* This is the CURLOPT_PROGRESSFUNCTION callback prototype. It is now + considered deprecated but was the only choice up until 7.31.0 */ +typedef int (*curl_progress_callback)(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); + +/* This is the CURLOPT_XFERINFOFUNCTION callback prototype. It was introduced + in 7.32.0, avoids the use of floating point numbers and provides more + detailed information. */ +typedef int (*curl_xferinfo_callback)(void *clientp, + curl_off_t dltotal, + curl_off_t dlnow, + curl_off_t ultotal, + curl_off_t ulnow); + +#ifndef CURL_MAX_READ_SIZE + /* The maximum receive buffer size configurable via CURLOPT_BUFFERSIZE. */ +#define CURL_MAX_READ_SIZE 524288 +#endif + +#ifndef CURL_MAX_WRITE_SIZE + /* Tests have proven that 20K is a very bad buffer size for uploads on + Windows, while 16K for some odd reason performed a lot better. + We do the ifndef check to allow this value to easier be changed at build + time for those who feel adventurous. The practical minimum is about + 400 bytes since libcurl uses a buffer of this size as a scratch area + (unrelated to network send operations). */ +#define CURL_MAX_WRITE_SIZE 16384 +#endif + +#ifndef CURL_MAX_HTTP_HEADER +/* The only reason to have a max limit for this is to avoid the risk of a bad + server feeding libcurl with a never-ending header that will cause reallocs + infinitely */ +#define CURL_MAX_HTTP_HEADER (100*1024) +#endif + +/* This is a magic return code for the write callback that, when returned, + will signal libcurl to pause receiving on the current transfer. */ +#define CURL_WRITEFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_write_callback)(char *buffer, + size_t size, + size_t nitems, + void *outstream); + +/* This callback will be called when a new resolver request is made */ +typedef int (*curl_resolver_start_callback)(void *resolver_state, + void *reserved, void *userdata); + +/* enumeration of file types */ +typedef enum { + CURLFILETYPE_FILE = 0, + CURLFILETYPE_DIRECTORY, + CURLFILETYPE_SYMLINK, + CURLFILETYPE_DEVICE_BLOCK, + CURLFILETYPE_DEVICE_CHAR, + CURLFILETYPE_NAMEDPIPE, + CURLFILETYPE_SOCKET, + CURLFILETYPE_DOOR, /* is possible only on Sun Solaris now */ + + CURLFILETYPE_UNKNOWN /* should never occur */ +} curlfiletype; + +#define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) +#define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) +#define CURLFINFOFLAG_KNOWN_TIME (1<<2) +#define CURLFINFOFLAG_KNOWN_PERM (1<<3) +#define CURLFINFOFLAG_KNOWN_UID (1<<4) +#define CURLFINFOFLAG_KNOWN_GID (1<<5) +#define CURLFINFOFLAG_KNOWN_SIZE (1<<6) +#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) + +/* Information about a single file, used when doing FTP wildcard matching */ +struct curl_fileinfo { + char *filename; + curlfiletype filetype; + time_t time; /* always zero! */ + unsigned int perm; + int uid; + int gid; + curl_off_t size; + long int hardlinks; + + struct { + /* If some of these fields is not NULL, it is a pointer to b_data. */ + char *time; + char *perm; + char *user; + char *group; + char *target; /* pointer to the target filename of a symlink */ + } strings; + + unsigned int flags; + + /* used internally */ + char *b_data; + size_t b_size; + size_t b_used; +}; + +/* return codes for CURLOPT_CHUNK_BGN_FUNCTION */ +#define CURL_CHUNK_BGN_FUNC_OK 0 +#define CURL_CHUNK_BGN_FUNC_FAIL 1 /* tell the lib to end the task */ +#define CURL_CHUNK_BGN_FUNC_SKIP 2 /* skip this chunk over */ + +/* if splitting of data transfer is enabled, this callback is called before + download of an individual chunk started. Note that parameter "remains" works + only for FTP wildcard downloading (for now), otherwise is not used */ +typedef long (*curl_chunk_bgn_callback)(const void *transfer_info, + void *ptr, + int remains); + +/* return codes for CURLOPT_CHUNK_END_FUNCTION */ +#define CURL_CHUNK_END_FUNC_OK 0 +#define CURL_CHUNK_END_FUNC_FAIL 1 /* tell the lib to end the task */ + +/* If splitting of data transfer is enabled this callback is called after + download of an individual chunk finished. + Note! After this callback was set then it have to be called FOR ALL chunks. + Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. + This is the reason why we don't need "transfer_info" parameter in this + callback and we are not interested in "remains" parameter too. */ +typedef long (*curl_chunk_end_callback)(void *ptr); + +/* return codes for FNMATCHFUNCTION */ +#define CURL_FNMATCHFUNC_MATCH 0 /* string corresponds to the pattern */ +#define CURL_FNMATCHFUNC_NOMATCH 1 /* pattern doesn't match the string */ +#define CURL_FNMATCHFUNC_FAIL 2 /* an error occurred */ + +/* callback type for wildcard downloading pattern matching. If the + string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ +typedef int (*curl_fnmatch_callback)(void *ptr, + const char *pattern, + const char *string); + +/* These are the return codes for the seek callbacks */ +#define CURL_SEEKFUNC_OK 0 +#define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */ +#define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so + libcurl might try other means instead */ +typedef int (*curl_seek_callback)(void *instream, + curl_off_t offset, + int origin); /* 'whence' */ + +/* This is a return code for the read callback that, when returned, will + signal libcurl to immediately abort the current transfer. */ +#define CURL_READFUNC_ABORT 0x10000000 +/* This is a return code for the read callback that, when returned, will + signal libcurl to pause sending data on the current transfer. */ +#define CURL_READFUNC_PAUSE 0x10000001 + +/* Return code for when the trailing headers' callback has terminated + without any errors*/ +#define CURL_TRAILERFUNC_OK 0 +/* Return code for when was an error in the trailing header's list and we + want to abort the request */ +#define CURL_TRAILERFUNC_ABORT 1 + +typedef size_t (*curl_read_callback)(char *buffer, + size_t size, + size_t nitems, + void *instream); + +typedef int (*curl_trailer_callback)(struct curl_slist **list, + void *userdata); + +typedef enum { + CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */ + CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */ + CURLSOCKTYPE_LAST /* never use */ +} curlsocktype; + +/* The return code from the sockopt_callback can signal information back + to libcurl: */ +#define CURL_SOCKOPT_OK 0 +#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return + CURLE_ABORTED_BY_CALLBACK */ +#define CURL_SOCKOPT_ALREADY_CONNECTED 2 + +typedef int (*curl_sockopt_callback)(void *clientp, + curl_socket_t curlfd, + curlsocktype purpose); + +struct curl_sockaddr { + int family; + int socktype; + int protocol; + unsigned int addrlen; /* addrlen was a socklen_t type before 7.18.0 but it + turned really ugly and painful on the systems that + lack this type */ + struct sockaddr addr; +}; + +typedef curl_socket_t +(*curl_opensocket_callback)(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address); + +typedef int +(*curl_closesocket_callback)(void *clientp, curl_socket_t item); + +typedef enum { + CURLIOE_OK, /* I/O operation successful */ + CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ + CURLIOE_FAILRESTART, /* failed to restart the read */ + CURLIOE_LAST /* never use */ +} curlioerr; + +typedef enum { + CURLIOCMD_NOP, /* no operation */ + CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ + CURLIOCMD_LAST /* never use */ +} curliocmd; + +typedef curlioerr (*curl_ioctl_callback)(CURL *handle, + int cmd, + void *clientp); + +#ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS +/* + * The following typedef's are signatures of malloc, free, realloc, strdup and + * calloc respectively. Function pointers of these types can be passed to the + * curl_global_init_mem() function to set user defined memory management + * callback routines. + */ +typedef void *(*curl_malloc_callback)(size_t size); +typedef void (*curl_free_callback)(void *ptr); +typedef void *(*curl_realloc_callback)(void *ptr, size_t size); +typedef char *(*curl_strdup_callback)(const char *str); +typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); + +#define CURL_DID_MEMORY_FUNC_TYPEDEFS +#endif + +/* the kind of data that is passed to information_callback*/ +typedef enum { + CURLINFO_TEXT = 0, + CURLINFO_HEADER_IN, /* 1 */ + CURLINFO_HEADER_OUT, /* 2 */ + CURLINFO_DATA_IN, /* 3 */ + CURLINFO_DATA_OUT, /* 4 */ + CURLINFO_SSL_DATA_IN, /* 5 */ + CURLINFO_SSL_DATA_OUT, /* 6 */ + CURLINFO_END +} curl_infotype; + +typedef int (*curl_debug_callback) + (CURL *handle, /* the handle/transfer this concerns */ + curl_infotype type, /* what kind of data */ + char *data, /* points to the data */ + size_t size, /* size of the data pointed to */ + void *userptr); /* whatever the user please */ + +/* All possible error codes from all sorts of curl functions. Future versions + may return other values, stay prepared. + + Always add new return codes last. Never *EVER* remove any. The return + codes must remain the same! + */ + +typedef enum { + CURLE_OK = 0, + CURLE_UNSUPPORTED_PROTOCOL, /* 1 */ + CURLE_FAILED_INIT, /* 2 */ + CURLE_URL_MALFORMAT, /* 3 */ + CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for + 7.17.0, reused in April 2011 for 7.21.5] */ + CURLE_COULDNT_RESOLVE_PROXY, /* 5 */ + CURLE_COULDNT_RESOLVE_HOST, /* 6 */ + CURLE_COULDNT_CONNECT, /* 7 */ + CURLE_WEIRD_SERVER_REPLY, /* 8 */ + CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server + due to lack of access - when login fails + this is not returned. */ + CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for + 7.15.4, reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */ + CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server + [was obsoleted in August 2007 for 7.17.0, + reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */ + CURLE_FTP_WEIRD_227_FORMAT, /* 14 */ + CURLE_FTP_CANT_GET_HOST, /* 15 */ + CURLE_HTTP2, /* 16 - A problem in the http2 framing layer. + [was obsoleted in August 2007 for 7.17.0, + reused in July 2014 for 7.38.0] */ + CURLE_FTP_COULDNT_SET_TYPE, /* 17 */ + CURLE_PARTIAL_FILE, /* 18 */ + CURLE_FTP_COULDNT_RETR_FILE, /* 19 */ + CURLE_OBSOLETE20, /* 20 - NOT USED */ + CURLE_QUOTE_ERROR, /* 21 - quote command failure */ + CURLE_HTTP_RETURNED_ERROR, /* 22 */ + CURLE_WRITE_ERROR, /* 23 */ + CURLE_OBSOLETE24, /* 24 - NOT USED */ + CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */ + CURLE_READ_ERROR, /* 26 - couldn't open/read from file */ + CURLE_OUT_OF_MEMORY, /* 27 */ + /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error + instead of a memory allocation error if CURL_DOES_CONVERSIONS + is defined + */ + CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */ + CURLE_OBSOLETE29, /* 29 - NOT USED */ + CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */ + CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */ + CURLE_OBSOLETE32, /* 32 - NOT USED */ + CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */ + CURLE_HTTP_POST_ERROR, /* 34 */ + CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */ + CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */ + CURLE_FILE_COULDNT_READ_FILE, /* 37 */ + CURLE_LDAP_CANNOT_BIND, /* 38 */ + CURLE_LDAP_SEARCH_FAILED, /* 39 */ + CURLE_OBSOLETE40, /* 40 - NOT USED */ + CURLE_FUNCTION_NOT_FOUND, /* 41 - NOT USED starting with 7.53.0 */ + CURLE_ABORTED_BY_CALLBACK, /* 42 */ + CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */ + CURLE_OBSOLETE44, /* 44 - NOT USED */ + CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */ + CURLE_OBSOLETE46, /* 46 - NOT USED */ + CURLE_TOO_MANY_REDIRECTS, /* 47 - catch endless re-direct loops */ + CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */ + CURLE_SETOPT_OPTION_SYNTAX, /* 49 - Malformed setopt option */ + CURLE_OBSOLETE50, /* 50 - NOT USED */ + CURLE_OBSOLETE51, /* 51 - NOT USED */ + CURLE_GOT_NOTHING, /* 52 - when this is a specific error */ + CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */ + CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as + default */ + CURLE_SEND_ERROR, /* 55 - failed sending network data */ + CURLE_RECV_ERROR, /* 56 - failure in receiving network data */ + CURLE_OBSOLETE57, /* 57 - NOT IN USE */ + CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */ + CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */ + CURLE_PEER_FAILED_VERIFICATION, /* 60 - peer's certificate or fingerprint + wasn't verified fine */ + CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */ + CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */ + CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */ + CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */ + CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind + that failed */ + CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */ + CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not + accepted and we failed to login */ + CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */ + CURLE_TFTP_PERM, /* 69 - permission problem on server */ + CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */ + CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */ + CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */ + CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */ + CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */ + CURLE_CONV_FAILED, /* 75 - conversion failed */ + CURLE_CONV_REQD, /* 76 - caller must register conversion + callbacks using curl_easy_setopt options + CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOPT_CONV_TO_NETWORK_FUNCTION, and + CURLOPT_CONV_FROM_UTF8_FUNCTION */ + CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing + or wrong format */ + CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */ + CURLE_SSH, /* 79 - error from the SSH layer, somewhat + generic so the error message will be of + interest when this has happened */ + + CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL + connection */ + CURLE_AGAIN, /* 81 - socket is not ready for send/recv, + wait till it's ready and try again (Added + in 7.18.2) */ + CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or + wrong format (Added in 7.19.0) */ + CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in + 7.19.0) */ + CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */ + CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */ + CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */ + CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */ + CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */ + CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the + session will be queued */ + CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not + match */ + CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */ + CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer + */ + CURLE_RECURSIVE_API_CALL, /* 93 - an api function was called from + inside a callback */ + CURLE_AUTH_ERROR, /* 94 - an authentication function returned an + error */ + CURLE_HTTP3, /* 95 - An HTTP/3 layer problem */ + CURLE_QUIC_CONNECT_ERROR, /* 96 - QUIC connection error */ + CURLE_PROXY, /* 97 - proxy handshake error */ + CURLE_SSL_CLIENTCERT, /* 98 - client-side certificate required */ + CURL_LAST /* never use! */ +} CURLcode; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Previously obsolete error code re-used in 7.38.0 */ +#define CURLE_OBSOLETE16 CURLE_HTTP2 + +/* Previously obsolete error codes re-used in 7.24.0 */ +#define CURLE_OBSOLETE10 CURLE_FTP_ACCEPT_FAILED +#define CURLE_OBSOLETE12 CURLE_FTP_ACCEPT_TIMEOUT + +/* compatibility with older names */ +#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING +#define CURLE_FTP_WEIRD_SERVER_REPLY CURLE_WEIRD_SERVER_REPLY + +/* The following were added in 7.62.0 */ +#define CURLE_SSL_CACERT CURLE_PEER_FAILED_VERIFICATION + +/* The following were added in 7.21.5, April 2011 */ +#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION + +/* Added for 7.78.0 */ +#define CURLE_TELNET_OPTION_SYNTAX CURLE_SETOPT_OPTION_SYNTAX + +/* The following were added in 7.17.1 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_SSL_PEER_CERTIFICATE CURLE_PEER_FAILED_VERIFICATION + +/* The following were added in 7.17.0 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_OBSOLETE CURLE_OBSOLETE50 /* no one should be using this! */ +#define CURLE_BAD_PASSWORD_ENTERED CURLE_OBSOLETE46 +#define CURLE_BAD_CALLING_ORDER CURLE_OBSOLETE44 +#define CURLE_FTP_USER_PASSWORD_INCORRECT CURLE_OBSOLETE10 +#define CURLE_FTP_CANT_RECONNECT CURLE_OBSOLETE16 +#define CURLE_FTP_COULDNT_GET_SIZE CURLE_OBSOLETE32 +#define CURLE_FTP_COULDNT_SET_ASCII CURLE_OBSOLETE29 +#define CURLE_FTP_WEIRD_USER_REPLY CURLE_OBSOLETE12 +#define CURLE_FTP_WRITE_ERROR CURLE_OBSOLETE20 +#define CURLE_LIBRARY_NOT_FOUND CURLE_OBSOLETE40 +#define CURLE_MALFORMAT_USER CURLE_OBSOLETE24 +#define CURLE_SHARE_IN_USE CURLE_OBSOLETE57 +#define CURLE_URL_MALFORMAT_USER CURLE_NOT_BUILT_IN + +#define CURLE_FTP_ACCESS_DENIED CURLE_REMOTE_ACCESS_DENIED +#define CURLE_FTP_COULDNT_SET_BINARY CURLE_FTP_COULDNT_SET_TYPE +#define CURLE_FTP_QUOTE_ERROR CURLE_QUOTE_ERROR +#define CURLE_TFTP_DISKFULL CURLE_REMOTE_DISK_FULL +#define CURLE_TFTP_EXISTS CURLE_REMOTE_FILE_EXISTS +#define CURLE_HTTP_RANGE_ERROR CURLE_RANGE_ERROR +#define CURLE_FTP_SSL_FAILED CURLE_USE_SSL_FAILED + +/* The following were added earlier */ + +#define CURLE_OPERATION_TIMEOUTED CURLE_OPERATION_TIMEDOUT + +#define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR +#define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED +#define CURLE_FTP_COULDNT_STOR_FILE CURLE_UPLOAD_FAILED + +#define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE +#define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME + +/* This was the error code 50 in 7.7.3 and a few earlier versions, this + is no longer used by libcurl but is instead #defined here only to not + make programs break */ +#define CURLE_ALREADY_COMPLETE 99999 + +/* Provide defines for really old option names */ +#define CURLOPT_FILE CURLOPT_WRITEDATA /* name changed in 7.9.7 */ +#define CURLOPT_INFILE CURLOPT_READDATA /* name changed in 7.9.7 */ +#define CURLOPT_WRITEHEADER CURLOPT_HEADERDATA + +/* Since long deprecated options with no code in the lib that does anything + with them. */ +#define CURLOPT_WRITEINFO CURLOPT_OBSOLETE40 +#define CURLOPT_CLOSEPOLICY CURLOPT_OBSOLETE72 + +#endif /*!CURL_NO_OLDIES*/ + +/* + * Proxy error codes. Returned in CURLINFO_PROXY_ERROR if CURLE_PROXY was + * return for the transfers. + */ +typedef enum { + CURLPX_OK, + CURLPX_BAD_ADDRESS_TYPE, + CURLPX_BAD_VERSION, + CURLPX_CLOSED, + CURLPX_GSSAPI, + CURLPX_GSSAPI_PERMSG, + CURLPX_GSSAPI_PROTECTION, + CURLPX_IDENTD, + CURLPX_IDENTD_DIFFER, + CURLPX_LONG_HOSTNAME, + CURLPX_LONG_PASSWD, + CURLPX_LONG_USER, + CURLPX_NO_AUTH, + CURLPX_RECV_ADDRESS, + CURLPX_RECV_AUTH, + CURLPX_RECV_CONNECT, + CURLPX_RECV_REQACK, + CURLPX_REPLY_ADDRESS_TYPE_NOT_SUPPORTED, + CURLPX_REPLY_COMMAND_NOT_SUPPORTED, + CURLPX_REPLY_CONNECTION_REFUSED, + CURLPX_REPLY_GENERAL_SERVER_FAILURE, + CURLPX_REPLY_HOST_UNREACHABLE, + CURLPX_REPLY_NETWORK_UNREACHABLE, + CURLPX_REPLY_NOT_ALLOWED, + CURLPX_REPLY_TTL_EXPIRED, + CURLPX_REPLY_UNASSIGNED, + CURLPX_REQUEST_FAILED, + CURLPX_RESOLVE_HOST, + CURLPX_SEND_AUTH, + CURLPX_SEND_CONNECT, + CURLPX_SEND_REQUEST, + CURLPX_UNKNOWN_FAIL, + CURLPX_UNKNOWN_MODE, + CURLPX_USER_REJECTED, + CURLPX_LAST /* never use */ +} CURLproxycode; + +/* This prototype applies to all conversion callbacks */ +typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length); + +typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */ + void *ssl_ctx, /* actually an OpenSSL + or WolfSSL SSL_CTX, + or an mbedTLS + mbedtls_ssl_config */ + void *userptr); + +typedef enum { + CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use + CONNECT HTTP/1.1 */ + CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT + HTTP/1.0 */ + CURLPROXY_HTTPS = 2, /* added in 7.52.0 */ + CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already + in 7.10 */ + CURLPROXY_SOCKS5 = 5, /* added in 7.10 */ + CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */ + CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the + host name rather than the IP address. added + in 7.18.0 */ +} curl_proxytype; /* this enum was added in 7.10 */ + +/* + * Bitmasks for CURLOPT_HTTPAUTH and CURLOPT_PROXYAUTH options: + * + * CURLAUTH_NONE - No HTTP authentication + * CURLAUTH_BASIC - HTTP Basic authentication (default) + * CURLAUTH_DIGEST - HTTP Digest authentication + * CURLAUTH_NEGOTIATE - HTTP Negotiate (SPNEGO) authentication + * CURLAUTH_GSSNEGOTIATE - Alias for CURLAUTH_NEGOTIATE (deprecated) + * CURLAUTH_NTLM - HTTP NTLM authentication + * CURLAUTH_DIGEST_IE - HTTP Digest authentication with IE flavour + * CURLAUTH_NTLM_WB - HTTP NTLM authentication delegated to winbind helper + * CURLAUTH_BEARER - HTTP Bearer token authentication + * CURLAUTH_ONLY - Use together with a single other type to force no + * authentication or just that single type + * CURLAUTH_ANY - All fine types set + * CURLAUTH_ANYSAFE - All fine types except Basic + */ + +#define CURLAUTH_NONE ((unsigned long)0) +#define CURLAUTH_BASIC (((unsigned long)1)<<0) +#define CURLAUTH_DIGEST (((unsigned long)1)<<1) +#define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2) +/* Deprecated since the advent of CURLAUTH_NEGOTIATE */ +#define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE +/* Used for CURLOPT_SOCKS5_AUTH to stay terminologically correct */ +#define CURLAUTH_GSSAPI CURLAUTH_NEGOTIATE +#define CURLAUTH_NTLM (((unsigned long)1)<<3) +#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) +#define CURLAUTH_NTLM_WB (((unsigned long)1)<<5) +#define CURLAUTH_BEARER (((unsigned long)1)<<6) +#define CURLAUTH_AWS_SIGV4 (((unsigned long)1)<<7) +#define CURLAUTH_ONLY (((unsigned long)1)<<31) +#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) +#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) + +#define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */ +#define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */ +#define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */ +#define CURLSSH_AUTH_PASSWORD (1<<1) /* password */ +#define CURLSSH_AUTH_HOST (1<<2) /* host key files */ +#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ +#define CURLSSH_AUTH_AGENT (1<<4) /* agent (ssh-agent, pageant...) */ +#define CURLSSH_AUTH_GSSAPI (1<<5) /* gssapi (kerberos, ...) */ +#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY + +#define CURLGSSAPI_DELEGATION_NONE 0 /* no delegation (default) */ +#define CURLGSSAPI_DELEGATION_POLICY_FLAG (1<<0) /* if permitted by policy */ +#define CURLGSSAPI_DELEGATION_FLAG (1<<1) /* delegate always */ + +#define CURL_ERROR_SIZE 256 + +enum curl_khtype { + CURLKHTYPE_UNKNOWN, + CURLKHTYPE_RSA1, + CURLKHTYPE_RSA, + CURLKHTYPE_DSS, + CURLKHTYPE_ECDSA, + CURLKHTYPE_ED25519 +}; + +struct curl_khkey { + const char *key; /* points to a null-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ + size_t len; + enum curl_khtype keytype; +}; + +/* this is the set of return values expected from the curl_sshkeycallback + callback */ +enum curl_khstat { + CURLKHSTAT_FINE_ADD_TO_FILE, + CURLKHSTAT_FINE, + CURLKHSTAT_REJECT, /* reject the connection, return an error */ + CURLKHSTAT_DEFER, /* do not accept it, but we can't answer right now so + this causes a CURLE_DEFER error but otherwise the + connection will be left intact etc */ + CURLKHSTAT_FINE_REPLACE, /* accept and replace the wrong key*/ + CURLKHSTAT_LAST /* not for use, only a marker for last-in-list */ +}; + +/* this is the set of status codes pass in to the callback */ +enum curl_khmatch { + CURLKHMATCH_OK, /* match */ + CURLKHMATCH_MISMATCH, /* host found, key mismatch! */ + CURLKHMATCH_MISSING, /* no matching host/key found */ + CURLKHMATCH_LAST /* not for use, only a marker for last-in-list */ +}; + +typedef int + (*curl_sshkeycallback) (CURL *easy, /* easy handle */ + const struct curl_khkey *knownkey, /* known */ + const struct curl_khkey *foundkey, /* found */ + enum curl_khmatch, /* libcurl's view on the keys */ + void *clientp); /* custom pointer passed from app */ + +/* parameter for the CURLOPT_USE_SSL option */ +typedef enum { + CURLUSESSL_NONE, /* do not attempt to use SSL */ + CURLUSESSL_TRY, /* try using SSL, proceed anyway otherwise */ + CURLUSESSL_CONTROL, /* SSL for the control connection or fail */ + CURLUSESSL_ALL, /* SSL for all communication or fail */ + CURLUSESSL_LAST /* not an option, never use */ +} curl_usessl; + +/* Definition of bits for the CURLOPT_SSL_OPTIONS argument: */ + +/* - ALLOW_BEAST tells libcurl to allow the BEAST SSL vulnerability in the + name of improving interoperability with older servers. Some SSL libraries + have introduced work-arounds for this flaw but those work-arounds sometimes + make the SSL communication fail. To regain functionality with those broken + servers, a user can this way allow the vulnerability back. */ +#define CURLSSLOPT_ALLOW_BEAST (1<<0) + +/* - NO_REVOKE tells libcurl to disable certificate revocation checks for those + SSL backends where such behavior is present. */ +#define CURLSSLOPT_NO_REVOKE (1<<1) + +/* - NO_PARTIALCHAIN tells libcurl to *NOT* accept a partial certificate chain + if possible. The OpenSSL backend has this ability. */ +#define CURLSSLOPT_NO_PARTIALCHAIN (1<<2) + +/* - REVOKE_BEST_EFFORT tells libcurl to ignore certificate revocation offline + checks and ignore missing revocation list for those SSL backends where such + behavior is present. */ +#define CURLSSLOPT_REVOKE_BEST_EFFORT (1<<3) + +/* - CURLSSLOPT_NATIVE_CA tells libcurl to use standard certificate store of + operating system. Currently implemented under MS-Windows. */ +#define CURLSSLOPT_NATIVE_CA (1<<4) + +/* - CURLSSLOPT_AUTO_CLIENT_CERT tells libcurl to automatically locate and use + a client certificate for authentication. (Schannel) */ +#define CURLSSLOPT_AUTO_CLIENT_CERT (1<<5) + +/* The default connection attempt delay in milliseconds for happy eyeballs. + CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.3 and happy-eyeballs-timeout-ms.d document + this value, keep them in sync. */ +#define CURL_HET_DEFAULT 200L + +/* The default connection upkeep interval in milliseconds. */ +#define CURL_UPKEEP_INTERVAL_DEFAULT 60000L + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2009 */ + +#define CURLFTPSSL_NONE CURLUSESSL_NONE +#define CURLFTPSSL_TRY CURLUSESSL_TRY +#define CURLFTPSSL_CONTROL CURLUSESSL_CONTROL +#define CURLFTPSSL_ALL CURLUSESSL_ALL +#define CURLFTPSSL_LAST CURLUSESSL_LAST +#define curl_ftpssl curl_usessl +#endif /*!CURL_NO_OLDIES*/ + +/* parameter for the CURLOPT_FTP_SSL_CCC option */ +typedef enum { + CURLFTPSSL_CCC_NONE, /* do not send CCC */ + CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */ + CURLFTPSSL_CCC_ACTIVE, /* Initiate the shutdown */ + CURLFTPSSL_CCC_LAST /* not an option, never use */ +} curl_ftpccc; + +/* parameter for the CURLOPT_FTPSSLAUTH option */ +typedef enum { + CURLFTPAUTH_DEFAULT, /* let libcurl decide */ + CURLFTPAUTH_SSL, /* use "AUTH SSL" */ + CURLFTPAUTH_TLS, /* use "AUTH TLS" */ + CURLFTPAUTH_LAST /* not an option, never use */ +} curl_ftpauth; + +/* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ +typedef enum { + CURLFTP_CREATE_DIR_NONE, /* do NOT create missing dirs! */ + CURLFTP_CREATE_DIR, /* (FTP/SFTP) if CWD fails, try MKD and then CWD + again if MKD succeeded, for SFTP this does + similar magic */ + CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD + again even if MKD failed! */ + CURLFTP_CREATE_DIR_LAST /* not an option, never use */ +} curl_ftpcreatedir; + +/* parameter for the CURLOPT_FTP_FILEMETHOD option */ +typedef enum { + CURLFTPMETHOD_DEFAULT, /* let libcurl pick */ + CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */ + CURLFTPMETHOD_NOCWD, /* no CWD at all */ + CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */ + CURLFTPMETHOD_LAST /* not an option, never use */ +} curl_ftpmethod; + +/* bitmask defines for CURLOPT_HEADEROPT */ +#define CURLHEADER_UNIFIED 0 +#define CURLHEADER_SEPARATE (1<<0) + +/* CURLALTSVC_* are bits for the CURLOPT_ALTSVC_CTRL option */ +#define CURLALTSVC_READONLYFILE (1<<2) +#define CURLALTSVC_H1 (1<<3) +#define CURLALTSVC_H2 (1<<4) +#define CURLALTSVC_H3 (1<<5) + + +struct curl_hstsentry { + char *name; + size_t namelen; + unsigned int includeSubDomains:1; + char expire[18]; /* YYYYMMDD HH:MM:SS [null-terminated] */ +}; + +struct curl_index { + size_t index; /* the provided entry's "index" or count */ + size_t total; /* total number of entries to save */ +}; + +typedef enum { + CURLSTS_OK, + CURLSTS_DONE, + CURLSTS_FAIL +} CURLSTScode; + +typedef CURLSTScode (*curl_hstsread_callback)(CURL *easy, + struct curl_hstsentry *e, + void *userp); +typedef CURLSTScode (*curl_hstswrite_callback)(CURL *easy, + struct curl_hstsentry *e, + struct curl_index *i, + void *userp); + +/* CURLHSTS_* are bits for the CURLOPT_HSTS option */ +#define CURLHSTS_ENABLE (long)(1<<0) +#define CURLHSTS_READONLYFILE (long)(1<<1) + +/* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ +#define CURLPROTO_HTTP (1<<0) +#define CURLPROTO_HTTPS (1<<1) +#define CURLPROTO_FTP (1<<2) +#define CURLPROTO_FTPS (1<<3) +#define CURLPROTO_SCP (1<<4) +#define CURLPROTO_SFTP (1<<5) +#define CURLPROTO_TELNET (1<<6) +#define CURLPROTO_LDAP (1<<7) +#define CURLPROTO_LDAPS (1<<8) +#define CURLPROTO_DICT (1<<9) +#define CURLPROTO_FILE (1<<10) +#define CURLPROTO_TFTP (1<<11) +#define CURLPROTO_IMAP (1<<12) +#define CURLPROTO_IMAPS (1<<13) +#define CURLPROTO_POP3 (1<<14) +#define CURLPROTO_POP3S (1<<15) +#define CURLPROTO_SMTP (1<<16) +#define CURLPROTO_SMTPS (1<<17) +#define CURLPROTO_RTSP (1<<18) +#define CURLPROTO_RTMP (1<<19) +#define CURLPROTO_RTMPT (1<<20) +#define CURLPROTO_RTMPE (1<<21) +#define CURLPROTO_RTMPTE (1<<22) +#define CURLPROTO_RTMPS (1<<23) +#define CURLPROTO_RTMPTS (1<<24) +#define CURLPROTO_GOPHER (1<<25) +#define CURLPROTO_SMB (1<<26) +#define CURLPROTO_SMBS (1<<27) +#define CURLPROTO_MQTT (1<<28) +#define CURLPROTO_GOPHERS (1<<29) +#define CURLPROTO_ALL (~0) /* enable everything */ + +/* long may be 32 or 64 bits, but we should never depend on anything else + but 32 */ +#define CURLOPTTYPE_LONG 0 +#define CURLOPTTYPE_OBJECTPOINT 10000 +#define CURLOPTTYPE_FUNCTIONPOINT 20000 +#define CURLOPTTYPE_OFF_T 30000 +#define CURLOPTTYPE_BLOB 40000 + +/* *STRINGPOINT is an alias for OBJECTPOINT to allow tools to extract the + string options from the header file */ + + +#define CURLOPT(na,t,nu) na = t + nu + +/* CURLOPT aliases that make no run-time difference */ + +/* 'char *' argument to a string with a trailing zero */ +#define CURLOPTTYPE_STRINGPOINT CURLOPTTYPE_OBJECTPOINT + +/* 'struct curl_slist *' argument */ +#define CURLOPTTYPE_SLISTPOINT CURLOPTTYPE_OBJECTPOINT + +/* 'void *' argument passed untouched to callback */ +#define CURLOPTTYPE_CBPOINT CURLOPTTYPE_OBJECTPOINT + +/* 'long' argument with a set of values/bitmask */ +#define CURLOPTTYPE_VALUES CURLOPTTYPE_LONG + +/* + * All CURLOPT_* values. + */ + +typedef enum { + /* This is the FILE * or void * the regular output should be written to. */ + CURLOPT(CURLOPT_WRITEDATA, CURLOPTTYPE_CBPOINT, 1), + + /* The full URL to get/put */ + CURLOPT(CURLOPT_URL, CURLOPTTYPE_STRINGPOINT, 2), + + /* Port number to connect to, if other than default. */ + CURLOPT(CURLOPT_PORT, CURLOPTTYPE_LONG, 3), + + /* Name of proxy to use. */ + CURLOPT(CURLOPT_PROXY, CURLOPTTYPE_STRINGPOINT, 4), + + /* "user:password;options" to use when fetching. */ + CURLOPT(CURLOPT_USERPWD, CURLOPTTYPE_STRINGPOINT, 5), + + /* "user:password" to use with proxy. */ + CURLOPT(CURLOPT_PROXYUSERPWD, CURLOPTTYPE_STRINGPOINT, 6), + + /* Range to get, specified as an ASCII string. */ + CURLOPT(CURLOPT_RANGE, CURLOPTTYPE_STRINGPOINT, 7), + + /* not used */ + + /* Specified file stream to upload from (use as input): */ + CURLOPT(CURLOPT_READDATA, CURLOPTTYPE_CBPOINT, 9), + + /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE + * bytes big. */ + CURLOPT(CURLOPT_ERRORBUFFER, CURLOPTTYPE_OBJECTPOINT, 10), + + /* Function that will be called to store the output (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CURLOPT(CURLOPT_WRITEFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 11), + + /* Function that will be called to read the input (instead of fread). The + * parameters will use fread() syntax, make sure to follow them. */ + CURLOPT(CURLOPT_READFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 12), + + /* Time-out the read operation after this amount of seconds */ + CURLOPT(CURLOPT_TIMEOUT, CURLOPTTYPE_LONG, 13), + + /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about + * how large the file being sent really is. That allows better error + * checking and better verifies that the upload was successful. -1 means + * unknown size. + * + * For large file support, there is also a _LARGE version of the key + * which takes an off_t type, allowing platforms with larger off_t + * sizes to handle larger files. See below for INFILESIZE_LARGE. + */ + CURLOPT(CURLOPT_INFILESIZE, CURLOPTTYPE_LONG, 14), + + /* POST static input fields. */ + CURLOPT(CURLOPT_POSTFIELDS, CURLOPTTYPE_OBJECTPOINT, 15), + + /* Set the referrer page (needed by some CGIs) */ + CURLOPT(CURLOPT_REFERER, CURLOPTTYPE_STRINGPOINT, 16), + + /* Set the FTP PORT string (interface name, named or numerical IP address) + Use i.e '-' to use default address. */ + CURLOPT(CURLOPT_FTPPORT, CURLOPTTYPE_STRINGPOINT, 17), + + /* Set the User-Agent string (examined by some CGIs) */ + CURLOPT(CURLOPT_USERAGENT, CURLOPTTYPE_STRINGPOINT, 18), + + /* If the download receives less than "low speed limit" bytes/second + * during "low speed time" seconds, the operations is aborted. + * You could i.e if you have a pretty high speed connection, abort if + * it is less than 2000 bytes/sec during 20 seconds. + */ + + /* Set the "low speed limit" */ + CURLOPT(CURLOPT_LOW_SPEED_LIMIT, CURLOPTTYPE_LONG, 19), + + /* Set the "low speed time" */ + CURLOPT(CURLOPT_LOW_SPEED_TIME, CURLOPTTYPE_LONG, 20), + + /* Set the continuation offset. + * + * Note there is also a _LARGE version of this key which uses + * off_t types, allowing for large file offsets on platforms which + * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. + */ + CURLOPT(CURLOPT_RESUME_FROM, CURLOPTTYPE_LONG, 21), + + /* Set cookie in request: */ + CURLOPT(CURLOPT_COOKIE, CURLOPTTYPE_STRINGPOINT, 22), + + /* This points to a linked list of headers, struct curl_slist kind. This + list is also used for RTSP (in spite of its name) */ + CURLOPT(CURLOPT_HTTPHEADER, CURLOPTTYPE_SLISTPOINT, 23), + + /* This points to a linked list of post entries, struct curl_httppost */ + CURLOPT(CURLOPT_HTTPPOST, CURLOPTTYPE_OBJECTPOINT, 24), + + /* name of the file keeping your private SSL-certificate */ + CURLOPT(CURLOPT_SSLCERT, CURLOPTTYPE_STRINGPOINT, 25), + + /* password for the SSL or SSH private key */ + CURLOPT(CURLOPT_KEYPASSWD, CURLOPTTYPE_STRINGPOINT, 26), + + /* send TYPE parameter? */ + CURLOPT(CURLOPT_CRLF, CURLOPTTYPE_LONG, 27), + + /* send linked-list of QUOTE commands */ + CURLOPT(CURLOPT_QUOTE, CURLOPTTYPE_SLISTPOINT, 28), + + /* send FILE * or void * to store headers to, if you use a callback it + is simply passed to the callback unmodified */ + CURLOPT(CURLOPT_HEADERDATA, CURLOPTTYPE_CBPOINT, 29), + + /* point to a file to read the initial cookies from, also enables + "cookie awareness" */ + CURLOPT(CURLOPT_COOKIEFILE, CURLOPTTYPE_STRINGPOINT, 31), + + /* What version to specifically try to use. + See CURL_SSLVERSION defines below. */ + CURLOPT(CURLOPT_SSLVERSION, CURLOPTTYPE_VALUES, 32), + + /* What kind of HTTP time condition to use, see defines */ + CURLOPT(CURLOPT_TIMECONDITION, CURLOPTTYPE_VALUES, 33), + + /* Time to use with the above condition. Specified in number of seconds + since 1 Jan 1970 */ + CURLOPT(CURLOPT_TIMEVALUE, CURLOPTTYPE_LONG, 34), + + /* 35 = OBSOLETE */ + + /* Custom request, for customizing the get command like + HTTP: DELETE, TRACE and others + FTP: to use a different list command + */ + CURLOPT(CURLOPT_CUSTOMREQUEST, CURLOPTTYPE_STRINGPOINT, 36), + + /* FILE handle to use instead of stderr */ + CURLOPT(CURLOPT_STDERR, CURLOPTTYPE_OBJECTPOINT, 37), + + /* 38 is not used */ + + /* send linked-list of post-transfer QUOTE commands */ + CURLOPT(CURLOPT_POSTQUOTE, CURLOPTTYPE_SLISTPOINT, 39), + + /* OBSOLETE, do not use! */ + CURLOPT(CURLOPT_OBSOLETE40, CURLOPTTYPE_OBJECTPOINT, 40), + + /* talk a lot */ + CURLOPT(CURLOPT_VERBOSE, CURLOPTTYPE_LONG, 41), + + /* throw the header out too */ + CURLOPT(CURLOPT_HEADER, CURLOPTTYPE_LONG, 42), + + /* shut off the progress meter */ + CURLOPT(CURLOPT_NOPROGRESS, CURLOPTTYPE_LONG, 43), + + /* use HEAD to get http document */ + CURLOPT(CURLOPT_NOBODY, CURLOPTTYPE_LONG, 44), + + /* no output on http error codes >= 400 */ + CURLOPT(CURLOPT_FAILONERROR, CURLOPTTYPE_LONG, 45), + + /* this is an upload */ + CURLOPT(CURLOPT_UPLOAD, CURLOPTTYPE_LONG, 46), + + /* HTTP POST method */ + CURLOPT(CURLOPT_POST, CURLOPTTYPE_LONG, 47), + + /* bare names when listing directories */ + CURLOPT(CURLOPT_DIRLISTONLY, CURLOPTTYPE_LONG, 48), + + /* Append instead of overwrite on upload! */ + CURLOPT(CURLOPT_APPEND, CURLOPTTYPE_LONG, 50), + + /* Specify whether to read the user+password from the .netrc or the URL. + * This must be one of the CURL_NETRC_* enums below. */ + CURLOPT(CURLOPT_NETRC, CURLOPTTYPE_VALUES, 51), + + /* use Location: Luke! */ + CURLOPT(CURLOPT_FOLLOWLOCATION, CURLOPTTYPE_LONG, 52), + + /* transfer data in text/ASCII format */ + CURLOPT(CURLOPT_TRANSFERTEXT, CURLOPTTYPE_LONG, 53), + + /* HTTP PUT */ + CURLOPT(CURLOPT_PUT, CURLOPTTYPE_LONG, 54), + + /* 55 = OBSOLETE */ + + /* DEPRECATED + * Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_progress_callback + * prototype defines. */ + CURLOPT(CURLOPT_PROGRESSFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 56), + + /* Data passed to the CURLOPT_PROGRESSFUNCTION and CURLOPT_XFERINFOFUNCTION + callbacks */ + CURLOPT(CURLOPT_XFERINFODATA, CURLOPTTYPE_CBPOINT, 57), +#define CURLOPT_PROGRESSDATA CURLOPT_XFERINFODATA + + /* We want the referrer field set automatically when following locations */ + CURLOPT(CURLOPT_AUTOREFERER, CURLOPTTYPE_LONG, 58), + + /* Port of the proxy, can be set in the proxy string as well with: + "[host]:[port]" */ + CURLOPT(CURLOPT_PROXYPORT, CURLOPTTYPE_LONG, 59), + + /* size of the POST input data, if strlen() is not good to use */ + CURLOPT(CURLOPT_POSTFIELDSIZE, CURLOPTTYPE_LONG, 60), + + /* tunnel non-http operations through a HTTP proxy */ + CURLOPT(CURLOPT_HTTPPROXYTUNNEL, CURLOPTTYPE_LONG, 61), + + /* Set the interface string to use as outgoing network interface */ + CURLOPT(CURLOPT_INTERFACE, CURLOPTTYPE_STRINGPOINT, 62), + + /* Set the krb4/5 security level, this also enables krb4/5 awareness. This + * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string + * is set but doesn't match one of these, 'private' will be used. */ + CURLOPT(CURLOPT_KRBLEVEL, CURLOPTTYPE_STRINGPOINT, 63), + + /* Set if we should verify the peer in ssl handshake, set 1 to verify. */ + CURLOPT(CURLOPT_SSL_VERIFYPEER, CURLOPTTYPE_LONG, 64), + + /* The CApath or CAfile used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_CAINFO, CURLOPTTYPE_STRINGPOINT, 65), + + /* 66 = OBSOLETE */ + /* 67 = OBSOLETE */ + + /* Maximum number of http redirects to follow */ + CURLOPT(CURLOPT_MAXREDIRS, CURLOPTTYPE_LONG, 68), + + /* Pass a long set to 1 to get the date of the requested document (if + possible)! Pass a zero to shut it off. */ + CURLOPT(CURLOPT_FILETIME, CURLOPTTYPE_LONG, 69), + + /* This points to a linked list of telnet options */ + CURLOPT(CURLOPT_TELNETOPTIONS, CURLOPTTYPE_SLISTPOINT, 70), + + /* Max amount of cached alive connections */ + CURLOPT(CURLOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 71), + + /* OBSOLETE, do not use! */ + CURLOPT(CURLOPT_OBSOLETE72, CURLOPTTYPE_LONG, 72), + + /* 73 = OBSOLETE */ + + /* Set to explicitly use a new connection for the upcoming transfer. + Do not use this unless you're absolutely sure of this, as it makes the + operation slower and is less friendly for the network. */ + CURLOPT(CURLOPT_FRESH_CONNECT, CURLOPTTYPE_LONG, 74), + + /* Set to explicitly forbid the upcoming transfer's connection to be re-used + when done. Do not use this unless you're absolutely sure of this, as it + makes the operation slower and is less friendly for the network. */ + CURLOPT(CURLOPT_FORBID_REUSE, CURLOPTTYPE_LONG, 75), + + /* Set to a file name that contains random data for libcurl to use to + seed the random engine when doing SSL connects. */ + CURLOPT(CURLOPT_RANDOM_FILE, CURLOPTTYPE_STRINGPOINT, 76), + + /* Set to the Entropy Gathering Daemon socket pathname */ + CURLOPT(CURLOPT_EGDSOCKET, CURLOPTTYPE_STRINGPOINT, 77), + + /* Time-out connect operations after this amount of seconds, if connects are + OK within this time, then fine... This only aborts the connect phase. */ + CURLOPT(CURLOPT_CONNECTTIMEOUT, CURLOPTTYPE_LONG, 78), + + /* Function that will be called to store headers (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CURLOPT(CURLOPT_HEADERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 79), + + /* Set this to force the HTTP request to get back to GET. Only really usable + if POST, PUT or a custom request have been used first. + */ + CURLOPT(CURLOPT_HTTPGET, CURLOPTTYPE_LONG, 80), + + /* Set if we should verify the Common name from the peer certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches the + * provided hostname. */ + CURLOPT(CURLOPT_SSL_VERIFYHOST, CURLOPTTYPE_LONG, 81), + + /* Specify which file name to write all known cookies in after completed + operation. Set file name to "-" (dash) to make it go to stdout. */ + CURLOPT(CURLOPT_COOKIEJAR, CURLOPTTYPE_STRINGPOINT, 82), + + /* Specify which SSL ciphers to use */ + CURLOPT(CURLOPT_SSL_CIPHER_LIST, CURLOPTTYPE_STRINGPOINT, 83), + + /* Specify which HTTP version to use! This must be set to one of the + CURL_HTTP_VERSION* enums set below. */ + CURLOPT(CURLOPT_HTTP_VERSION, CURLOPTTYPE_VALUES, 84), + + /* Specifically switch on or off the FTP engine's use of the EPSV command. By + default, that one will always be attempted before the more traditional + PASV command. */ + CURLOPT(CURLOPT_FTP_USE_EPSV, CURLOPTTYPE_LONG, 85), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ + CURLOPT(CURLOPT_SSLCERTTYPE, CURLOPTTYPE_STRINGPOINT, 86), + + /* name of the file keeping your private SSL-key */ + CURLOPT(CURLOPT_SSLKEY, CURLOPTTYPE_STRINGPOINT, 87), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ + CURLOPT(CURLOPT_SSLKEYTYPE, CURLOPTTYPE_STRINGPOINT, 88), + + /* crypto engine for the SSL-sub system */ + CURLOPT(CURLOPT_SSLENGINE, CURLOPTTYPE_STRINGPOINT, 89), + + /* set the crypto engine for the SSL-sub system as default + the param has no meaning... + */ + CURLOPT(CURLOPT_SSLENGINE_DEFAULT, CURLOPTTYPE_LONG, 90), + + /* Non-zero value means to use the global dns cache */ + /* DEPRECATED, do not use! */ + CURLOPT(CURLOPT_DNS_USE_GLOBAL_CACHE, CURLOPTTYPE_LONG, 91), + + /* DNS cache timeout */ + CURLOPT(CURLOPT_DNS_CACHE_TIMEOUT, CURLOPTTYPE_LONG, 92), + + /* send linked-list of pre-transfer QUOTE commands */ + CURLOPT(CURLOPT_PREQUOTE, CURLOPTTYPE_SLISTPOINT, 93), + + /* set the debug function */ + CURLOPT(CURLOPT_DEBUGFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 94), + + /* set the data for the debug function */ + CURLOPT(CURLOPT_DEBUGDATA, CURLOPTTYPE_CBPOINT, 95), + + /* mark this as start of a cookie session */ + CURLOPT(CURLOPT_COOKIESESSION, CURLOPTTYPE_LONG, 96), + + /* The CApath directory used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_CAPATH, CURLOPTTYPE_STRINGPOINT, 97), + + /* Instruct libcurl to use a smaller receive buffer */ + CURLOPT(CURLOPT_BUFFERSIZE, CURLOPTTYPE_LONG, 98), + + /* Instruct libcurl to not use any signal/alarm handlers, even when using + timeouts. This option is useful for multi-threaded applications. + See libcurl-the-guide for more background information. */ + CURLOPT(CURLOPT_NOSIGNAL, CURLOPTTYPE_LONG, 99), + + /* Provide a CURLShare for mutexing non-ts data */ + CURLOPT(CURLOPT_SHARE, CURLOPTTYPE_OBJECTPOINT, 100), + + /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default), + CURLPROXY_HTTPS, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and + CURLPROXY_SOCKS5. */ + CURLOPT(CURLOPT_PROXYTYPE, CURLOPTTYPE_VALUES, 101), + + /* Set the Accept-Encoding string. Use this to tell a server you would like + the response to be compressed. Before 7.21.6, this was known as + CURLOPT_ENCODING */ + CURLOPT(CURLOPT_ACCEPT_ENCODING, CURLOPTTYPE_STRINGPOINT, 102), + + /* Set pointer to private data */ + CURLOPT(CURLOPT_PRIVATE, CURLOPTTYPE_OBJECTPOINT, 103), + + /* Set aliases for HTTP 200 in the HTTP Response header */ + CURLOPT(CURLOPT_HTTP200ALIASES, CURLOPTTYPE_SLISTPOINT, 104), + + /* Continue to send authentication (user+password) when following locations, + even when hostname changed. This can potentially send off the name + and password to whatever host the server decides. */ + CURLOPT(CURLOPT_UNRESTRICTED_AUTH, CURLOPTTYPE_LONG, 105), + + /* Specifically switch on or off the FTP engine's use of the EPRT command ( + it also disables the LPRT attempt). By default, those ones will always be + attempted before the good old traditional PORT command. */ + CURLOPT(CURLOPT_FTP_USE_EPRT, CURLOPTTYPE_LONG, 106), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_USERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CURLOPT(CURLOPT_HTTPAUTH, CURLOPTTYPE_VALUES, 107), + + /* Set the ssl context callback function, currently only for OpenSSL or + WolfSSL ssl_ctx, or mbedTLS mbedtls_ssl_config in the second argument. + The function must match the curl_ssl_ctx_callback prototype. */ + CURLOPT(CURLOPT_SSL_CTX_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 108), + + /* Set the userdata for the ssl context callback function's third + argument */ + CURLOPT(CURLOPT_SSL_CTX_DATA, CURLOPTTYPE_CBPOINT, 109), + + /* FTP Option that causes missing dirs to be created on the remote server. + In 7.19.4 we introduced the convenience enums for this option using the + CURLFTP_CREATE_DIR prefix. + */ + CURLOPT(CURLOPT_FTP_CREATE_MISSING_DIRS, CURLOPTTYPE_LONG, 110), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CURLOPT(CURLOPT_PROXYAUTH, CURLOPTTYPE_VALUES, 111), + + /* FTP option that changes the timeout, in seconds, associated with + getting a response. This is different from transfer timeout time and + essentially places a demand on the FTP server to acknowledge commands + in a timely manner. */ + CURLOPT(CURLOPT_FTP_RESPONSE_TIMEOUT, CURLOPTTYPE_LONG, 112), +#define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT + + /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to + tell libcurl to use those IP versions only. This only has effect on + systems with support for more than one, i.e IPv4 _and_ IPv6. */ + CURLOPT(CURLOPT_IPRESOLVE, CURLOPTTYPE_VALUES, 113), + + /* Set this option to limit the size of a file that will be downloaded from + an HTTP or FTP server. + + Note there is also _LARGE version which adds large file support for + platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ + CURLOPT(CURLOPT_MAXFILESIZE, CURLOPTTYPE_LONG, 114), + + /* See the comment for INFILESIZE above, but in short, specifies + * the size of the file being uploaded. -1 means unknown. + */ + CURLOPT(CURLOPT_INFILESIZE_LARGE, CURLOPTTYPE_OFF_T, 115), + + /* Sets the continuation offset. There is also a CURLOPTTYPE_LONG version + * of this; look above for RESUME_FROM. + */ + CURLOPT(CURLOPT_RESUME_FROM_LARGE, CURLOPTTYPE_OFF_T, 116), + + /* Sets the maximum size of data that will be downloaded from + * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. + */ + CURLOPT(CURLOPT_MAXFILESIZE_LARGE, CURLOPTTYPE_OFF_T, 117), + + /* Set this option to the file name of your .netrc file you want libcurl + to parse (using the CURLOPT_NETRC option). If not set, libcurl will do + a poor attempt to find the user's home directory and check for a .netrc + file in there. */ + CURLOPT(CURLOPT_NETRC_FILE, CURLOPTTYPE_STRINGPOINT, 118), + + /* Enable SSL/TLS for FTP, pick one of: + CURLUSESSL_TRY - try using SSL, proceed anyway otherwise + CURLUSESSL_CONTROL - SSL for the control connection or fail + CURLUSESSL_ALL - SSL for all communication or fail + */ + CURLOPT(CURLOPT_USE_SSL, CURLOPTTYPE_VALUES, 119), + + /* The _LARGE version of the standard POSTFIELDSIZE option */ + CURLOPT(CURLOPT_POSTFIELDSIZE_LARGE, CURLOPTTYPE_OFF_T, 120), + + /* Enable/disable the TCP Nagle algorithm */ + CURLOPT(CURLOPT_TCP_NODELAY, CURLOPTTYPE_LONG, 121), + + /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 123 OBSOLETE. Gone in 7.16.0 */ + /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 127 OBSOLETE. Gone in 7.16.0 */ + /* 128 OBSOLETE. Gone in 7.16.0 */ + + /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option + can be used to change libcurl's default action which is to first try + "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK + response has been received. + + Available parameters are: + CURLFTPAUTH_DEFAULT - let libcurl decide + CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS + CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL + */ + CURLOPT(CURLOPT_FTPSSLAUTH, CURLOPTTYPE_VALUES, 129), + + CURLOPT(CURLOPT_IOCTLFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 130), + CURLOPT(CURLOPT_IOCTLDATA, CURLOPTTYPE_CBPOINT, 131), + + /* 132 OBSOLETE. Gone in 7.16.0 */ + /* 133 OBSOLETE. Gone in 7.16.0 */ + + /* null-terminated string for pass on to the FTP server when asked for + "account" info */ + CURLOPT(CURLOPT_FTP_ACCOUNT, CURLOPTTYPE_STRINGPOINT, 134), + + /* feed cookie into cookie engine */ + CURLOPT(CURLOPT_COOKIELIST, CURLOPTTYPE_STRINGPOINT, 135), + + /* ignore Content-Length */ + CURLOPT(CURLOPT_IGNORE_CONTENT_LENGTH, CURLOPTTYPE_LONG, 136), + + /* Set to non-zero to skip the IP address received in a 227 PASV FTP server + response. Typically used for FTP-SSL purposes but is not restricted to + that. libcurl will then instead use the same IP address it used for the + control connection. */ + CURLOPT(CURLOPT_FTP_SKIP_PASV_IP, CURLOPTTYPE_LONG, 137), + + /* Select "file method" to use when doing FTP, see the curl_ftpmethod + above. */ + CURLOPT(CURLOPT_FTP_FILEMETHOD, CURLOPTTYPE_VALUES, 138), + + /* Local port number to bind the socket to */ + CURLOPT(CURLOPT_LOCALPORT, CURLOPTTYPE_LONG, 139), + + /* Number of ports to try, including the first one set with LOCALPORT. + Thus, setting it to 1 will make no additional attempts but the first. + */ + CURLOPT(CURLOPT_LOCALPORTRANGE, CURLOPTTYPE_LONG, 140), + + /* no transfer, set up connection and let application use the socket by + extracting it with CURLINFO_LASTSOCKET */ + CURLOPT(CURLOPT_CONNECT_ONLY, CURLOPTTYPE_LONG, 141), + + /* Function that will be called to convert from the + network encoding (instead of using the iconv calls in libcurl) */ + CURLOPT(CURLOPT_CONV_FROM_NETWORK_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 142), + + /* Function that will be called to convert to the + network encoding (instead of using the iconv calls in libcurl) */ + CURLOPT(CURLOPT_CONV_TO_NETWORK_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 143), + + /* Function that will be called to convert from UTF8 + (instead of using the iconv calls in libcurl) + Note that this is used only for SSL certificate processing */ + CURLOPT(CURLOPT_CONV_FROM_UTF8_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 144), + + /* if the connection proceeds too quickly then need to slow it down */ + /* limit-rate: maximum number of bytes per second to send or receive */ + CURLOPT(CURLOPT_MAX_SEND_SPEED_LARGE, CURLOPTTYPE_OFF_T, 145), + CURLOPT(CURLOPT_MAX_RECV_SPEED_LARGE, CURLOPTTYPE_OFF_T, 146), + + /* Pointer to command string to send if USER/PASS fails. */ + CURLOPT(CURLOPT_FTP_ALTERNATIVE_TO_USER, CURLOPTTYPE_STRINGPOINT, 147), + + /* callback function for setting socket options */ + CURLOPT(CURLOPT_SOCKOPTFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 148), + CURLOPT(CURLOPT_SOCKOPTDATA, CURLOPTTYPE_CBPOINT, 149), + + /* set to 0 to disable session ID re-use for this transfer, default is + enabled (== 1) */ + CURLOPT(CURLOPT_SSL_SESSIONID_CACHE, CURLOPTTYPE_LONG, 150), + + /* allowed SSH authentication methods */ + CURLOPT(CURLOPT_SSH_AUTH_TYPES, CURLOPTTYPE_VALUES, 151), + + /* Used by scp/sftp to do public/private key authentication */ + CURLOPT(CURLOPT_SSH_PUBLIC_KEYFILE, CURLOPTTYPE_STRINGPOINT, 152), + CURLOPT(CURLOPT_SSH_PRIVATE_KEYFILE, CURLOPTTYPE_STRINGPOINT, 153), + + /* Send CCC (Clear Command Channel) after authentication */ + CURLOPT(CURLOPT_FTP_SSL_CCC, CURLOPTTYPE_LONG, 154), + + /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ + CURLOPT(CURLOPT_TIMEOUT_MS, CURLOPTTYPE_LONG, 155), + CURLOPT(CURLOPT_CONNECTTIMEOUT_MS, CURLOPTTYPE_LONG, 156), + + /* set to zero to disable the libcurl's decoding and thus pass the raw body + data to the application even when it is encoded/compressed */ + CURLOPT(CURLOPT_HTTP_TRANSFER_DECODING, CURLOPTTYPE_LONG, 157), + CURLOPT(CURLOPT_HTTP_CONTENT_DECODING, CURLOPTTYPE_LONG, 158), + + /* Permission used when creating new files and directories on the remote + server for protocols that support it, SFTP/SCP/FILE */ + CURLOPT(CURLOPT_NEW_FILE_PERMS, CURLOPTTYPE_LONG, 159), + CURLOPT(CURLOPT_NEW_DIRECTORY_PERMS, CURLOPTTYPE_LONG, 160), + + /* Set the behavior of POST when redirecting. Values must be set to one + of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ + CURLOPT(CURLOPT_POSTREDIR, CURLOPTTYPE_VALUES, 161), + + /* used by scp/sftp to verify the host's public key */ + CURLOPT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, CURLOPTTYPE_STRINGPOINT, 162), + + /* Callback function for opening socket (instead of socket(2)). Optionally, + callback is able change the address or refuse to connect returning + CURL_SOCKET_BAD. The callback should have type + curl_opensocket_callback */ + CURLOPT(CURLOPT_OPENSOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 163), + CURLOPT(CURLOPT_OPENSOCKETDATA, CURLOPTTYPE_CBPOINT, 164), + + /* POST volatile input fields. */ + CURLOPT(CURLOPT_COPYPOSTFIELDS, CURLOPTTYPE_OBJECTPOINT, 165), + + /* set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy */ + CURLOPT(CURLOPT_PROXY_TRANSFER_MODE, CURLOPTTYPE_LONG, 166), + + /* Callback function for seeking in the input stream */ + CURLOPT(CURLOPT_SEEKFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 167), + CURLOPT(CURLOPT_SEEKDATA, CURLOPTTYPE_CBPOINT, 168), + + /* CRL file */ + CURLOPT(CURLOPT_CRLFILE, CURLOPTTYPE_STRINGPOINT, 169), + + /* Issuer certificate */ + CURLOPT(CURLOPT_ISSUERCERT, CURLOPTTYPE_STRINGPOINT, 170), + + /* (IPv6) Address scope */ + CURLOPT(CURLOPT_ADDRESS_SCOPE, CURLOPTTYPE_LONG, 171), + + /* Collect certificate chain info and allow it to get retrievable with + CURLINFO_CERTINFO after the transfer is complete. */ + CURLOPT(CURLOPT_CERTINFO, CURLOPTTYPE_LONG, 172), + + /* "name" and "pwd" to use when fetching. */ + CURLOPT(CURLOPT_USERNAME, CURLOPTTYPE_STRINGPOINT, 173), + CURLOPT(CURLOPT_PASSWORD, CURLOPTTYPE_STRINGPOINT, 174), + + /* "name" and "pwd" to use with Proxy when fetching. */ + CURLOPT(CURLOPT_PROXYUSERNAME, CURLOPTTYPE_STRINGPOINT, 175), + CURLOPT(CURLOPT_PROXYPASSWORD, CURLOPTTYPE_STRINGPOINT, 176), + + /* Comma separated list of hostnames defining no-proxy zones. These should + match both hostnames directly, and hostnames within a domain. For + example, local.com will match local.com and www.local.com, but NOT + notlocal.com or www.notlocal.com. For compatibility with other + implementations of this, .local.com will be considered to be the same as + local.com. A single * is the only valid wildcard, and effectively + disables the use of proxy. */ + CURLOPT(CURLOPT_NOPROXY, CURLOPTTYPE_STRINGPOINT, 177), + + /* block size for TFTP transfers */ + CURLOPT(CURLOPT_TFTP_BLKSIZE, CURLOPTTYPE_LONG, 178), + + /* Socks Service */ + /* DEPRECATED, do not use! */ + CURLOPT(CURLOPT_SOCKS5_GSSAPI_SERVICE, CURLOPTTYPE_STRINGPOINT, 179), + + /* Socks Service */ + CURLOPT(CURLOPT_SOCKS5_GSSAPI_NEC, CURLOPTTYPE_LONG, 180), + + /* set the bitmask for the protocols that are allowed to be used for the + transfer, which thus helps the app which takes URLs from users or other + external inputs and want to restrict what protocol(s) to deal + with. Defaults to CURLPROTO_ALL. */ + CURLOPT(CURLOPT_PROTOCOLS, CURLOPTTYPE_LONG, 181), + + /* set the bitmask for the protocols that libcurl is allowed to follow to, + as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs + to be set in both bitmasks to be allowed to get redirected to. */ + CURLOPT(CURLOPT_REDIR_PROTOCOLS, CURLOPTTYPE_LONG, 182), + + /* set the SSH knownhost file name to use */ + CURLOPT(CURLOPT_SSH_KNOWNHOSTS, CURLOPTTYPE_STRINGPOINT, 183), + + /* set the SSH host key callback, must point to a curl_sshkeycallback + function */ + CURLOPT(CURLOPT_SSH_KEYFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 184), + + /* set the SSH host key callback custom pointer */ + CURLOPT(CURLOPT_SSH_KEYDATA, CURLOPTTYPE_CBPOINT, 185), + + /* set the SMTP mail originator */ + CURLOPT(CURLOPT_MAIL_FROM, CURLOPTTYPE_STRINGPOINT, 186), + + /* set the list of SMTP mail receiver(s) */ + CURLOPT(CURLOPT_MAIL_RCPT, CURLOPTTYPE_SLISTPOINT, 187), + + /* FTP: send PRET before PASV */ + CURLOPT(CURLOPT_FTP_USE_PRET, CURLOPTTYPE_LONG, 188), + + /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ + CURLOPT(CURLOPT_RTSP_REQUEST, CURLOPTTYPE_VALUES, 189), + + /* The RTSP session identifier */ + CURLOPT(CURLOPT_RTSP_SESSION_ID, CURLOPTTYPE_STRINGPOINT, 190), + + /* The RTSP stream URI */ + CURLOPT(CURLOPT_RTSP_STREAM_URI, CURLOPTTYPE_STRINGPOINT, 191), + + /* The Transport: header to use in RTSP requests */ + CURLOPT(CURLOPT_RTSP_TRANSPORT, CURLOPTTYPE_STRINGPOINT, 192), + + /* Manually initialize the client RTSP CSeq for this handle */ + CURLOPT(CURLOPT_RTSP_CLIENT_CSEQ, CURLOPTTYPE_LONG, 193), + + /* Manually initialize the server RTSP CSeq for this handle */ + CURLOPT(CURLOPT_RTSP_SERVER_CSEQ, CURLOPTTYPE_LONG, 194), + + /* The stream to pass to INTERLEAVEFUNCTION. */ + CURLOPT(CURLOPT_INTERLEAVEDATA, CURLOPTTYPE_CBPOINT, 195), + + /* Let the application define a custom write method for RTP data */ + CURLOPT(CURLOPT_INTERLEAVEFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 196), + + /* Turn on wildcard matching */ + CURLOPT(CURLOPT_WILDCARDMATCH, CURLOPTTYPE_LONG, 197), + + /* Directory matching callback called before downloading of an + individual file (chunk) started */ + CURLOPT(CURLOPT_CHUNK_BGN_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 198), + + /* Directory matching callback called after the file (chunk) + was downloaded, or skipped */ + CURLOPT(CURLOPT_CHUNK_END_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 199), + + /* Change match (fnmatch-like) callback for wildcard matching */ + CURLOPT(CURLOPT_FNMATCH_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 200), + + /* Let the application define custom chunk data pointer */ + CURLOPT(CURLOPT_CHUNK_DATA, CURLOPTTYPE_CBPOINT, 201), + + /* FNMATCH_FUNCTION user pointer */ + CURLOPT(CURLOPT_FNMATCH_DATA, CURLOPTTYPE_CBPOINT, 202), + + /* send linked-list of name:port:address sets */ + CURLOPT(CURLOPT_RESOLVE, CURLOPTTYPE_SLISTPOINT, 203), + + /* Set a username for authenticated TLS */ + CURLOPT(CURLOPT_TLSAUTH_USERNAME, CURLOPTTYPE_STRINGPOINT, 204), + + /* Set a password for authenticated TLS */ + CURLOPT(CURLOPT_TLSAUTH_PASSWORD, CURLOPTTYPE_STRINGPOINT, 205), + + /* Set authentication type for authenticated TLS */ + CURLOPT(CURLOPT_TLSAUTH_TYPE, CURLOPTTYPE_STRINGPOINT, 206), + + /* Set to 1 to enable the "TE:" header in HTTP requests to ask for + compressed transfer-encoded responses. Set to 0 to disable the use of TE: + in outgoing requests. The current default is 0, but it might change in a + future libcurl release. + + libcurl will ask for the compressed methods it knows of, and if that + isn't any, it will not ask for transfer-encoding at all even if this + option is set to 1. + + */ + CURLOPT(CURLOPT_TRANSFER_ENCODING, CURLOPTTYPE_LONG, 207), + + /* Callback function for closing socket (instead of close(2)). The callback + should have type curl_closesocket_callback */ + CURLOPT(CURLOPT_CLOSESOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 208), + CURLOPT(CURLOPT_CLOSESOCKETDATA, CURLOPTTYPE_CBPOINT, 209), + + /* allow GSSAPI credential delegation */ + CURLOPT(CURLOPT_GSSAPI_DELEGATION, CURLOPTTYPE_VALUES, 210), + + /* Set the name servers to use for DNS resolution */ + CURLOPT(CURLOPT_DNS_SERVERS, CURLOPTTYPE_STRINGPOINT, 211), + + /* Time-out accept operations (currently for FTP only) after this amount + of milliseconds. */ + CURLOPT(CURLOPT_ACCEPTTIMEOUT_MS, CURLOPTTYPE_LONG, 212), + + /* Set TCP keepalive */ + CURLOPT(CURLOPT_TCP_KEEPALIVE, CURLOPTTYPE_LONG, 213), + + /* non-universal keepalive knobs (Linux, AIX, HP-UX, more) */ + CURLOPT(CURLOPT_TCP_KEEPIDLE, CURLOPTTYPE_LONG, 214), + CURLOPT(CURLOPT_TCP_KEEPINTVL, CURLOPTTYPE_LONG, 215), + + /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */ + CURLOPT(CURLOPT_SSL_OPTIONS, CURLOPTTYPE_VALUES, 216), + + /* Set the SMTP auth originator */ + CURLOPT(CURLOPT_MAIL_AUTH, CURLOPTTYPE_STRINGPOINT, 217), + + /* Enable/disable SASL initial response */ + CURLOPT(CURLOPT_SASL_IR, CURLOPTTYPE_LONG, 218), + + /* Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_xferinfo_callback + * prototype defines. (Deprecates CURLOPT_PROGRESSFUNCTION) */ + CURLOPT(CURLOPT_XFERINFOFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 219), + + /* The XOAUTH2 bearer token */ + CURLOPT(CURLOPT_XOAUTH2_BEARER, CURLOPTTYPE_STRINGPOINT, 220), + + /* Set the interface string to use as outgoing network + * interface for DNS requests. + * Only supported by the c-ares DNS backend */ + CURLOPT(CURLOPT_DNS_INTERFACE, CURLOPTTYPE_STRINGPOINT, 221), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CURLOPT(CURLOPT_DNS_LOCAL_IP4, CURLOPTTYPE_STRINGPOINT, 222), + + /* Set the local IPv6 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CURLOPT(CURLOPT_DNS_LOCAL_IP6, CURLOPTTYPE_STRINGPOINT, 223), + + /* Set authentication options directly */ + CURLOPT(CURLOPT_LOGIN_OPTIONS, CURLOPTTYPE_STRINGPOINT, 224), + + /* Enable/disable TLS NPN extension (http2 over ssl might fail without) */ + CURLOPT(CURLOPT_SSL_ENABLE_NPN, CURLOPTTYPE_LONG, 225), + + /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */ + CURLOPT(CURLOPT_SSL_ENABLE_ALPN, CURLOPTTYPE_LONG, 226), + + /* Time to wait for a response to a HTTP request containing an + * Expect: 100-continue header before sending the data anyway. */ + CURLOPT(CURLOPT_EXPECT_100_TIMEOUT_MS, CURLOPTTYPE_LONG, 227), + + /* This points to a linked list of headers used for proxy requests only, + struct curl_slist kind */ + CURLOPT(CURLOPT_PROXYHEADER, CURLOPTTYPE_SLISTPOINT, 228), + + /* Pass in a bitmask of "header options" */ + CURLOPT(CURLOPT_HEADEROPT, CURLOPTTYPE_VALUES, 229), + + /* The public key in DER form used to validate the peer public key + this option is used only if SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_PINNEDPUBLICKEY, CURLOPTTYPE_STRINGPOINT, 230), + + /* Path to Unix domain socket */ + CURLOPT(CURLOPT_UNIX_SOCKET_PATH, CURLOPTTYPE_STRINGPOINT, 231), + + /* Set if we should verify the certificate status. */ + CURLOPT(CURLOPT_SSL_VERIFYSTATUS, CURLOPTTYPE_LONG, 232), + + /* Set if we should enable TLS false start. */ + CURLOPT(CURLOPT_SSL_FALSESTART, CURLOPTTYPE_LONG, 233), + + /* Do not squash dot-dot sequences */ + CURLOPT(CURLOPT_PATH_AS_IS, CURLOPTTYPE_LONG, 234), + + /* Proxy Service Name */ + CURLOPT(CURLOPT_PROXY_SERVICE_NAME, CURLOPTTYPE_STRINGPOINT, 235), + + /* Service Name */ + CURLOPT(CURLOPT_SERVICE_NAME, CURLOPTTYPE_STRINGPOINT, 236), + + /* Wait/don't wait for pipe/mutex to clarify */ + CURLOPT(CURLOPT_PIPEWAIT, CURLOPTTYPE_LONG, 237), + + /* Set the protocol used when curl is given a URL without a protocol */ + CURLOPT(CURLOPT_DEFAULT_PROTOCOL, CURLOPTTYPE_STRINGPOINT, 238), + + /* Set stream weight, 1 - 256 (default is 16) */ + CURLOPT(CURLOPT_STREAM_WEIGHT, CURLOPTTYPE_LONG, 239), + + /* Set stream dependency on another CURL handle */ + CURLOPT(CURLOPT_STREAM_DEPENDS, CURLOPTTYPE_OBJECTPOINT, 240), + + /* Set E-xclusive stream dependency on another CURL handle */ + CURLOPT(CURLOPT_STREAM_DEPENDS_E, CURLOPTTYPE_OBJECTPOINT, 241), + + /* Do not send any tftp option requests to the server */ + CURLOPT(CURLOPT_TFTP_NO_OPTIONS, CURLOPTTYPE_LONG, 242), + + /* Linked-list of host:port:connect-to-host:connect-to-port, + overrides the URL's host:port (only for the network layer) */ + CURLOPT(CURLOPT_CONNECT_TO, CURLOPTTYPE_SLISTPOINT, 243), + + /* Set TCP Fast Open */ + CURLOPT(CURLOPT_TCP_FASTOPEN, CURLOPTTYPE_LONG, 244), + + /* Continue to send data if the server responds early with an + * HTTP status code >= 300 */ + CURLOPT(CURLOPT_KEEP_SENDING_ON_ERROR, CURLOPTTYPE_LONG, 245), + + /* The CApath or CAfile used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_PROXY_CAINFO, CURLOPTTYPE_STRINGPOINT, 246), + + /* The CApath directory used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_PROXY_CAPATH, CURLOPTTYPE_STRINGPOINT, 247), + + /* Set if we should verify the proxy in ssl handshake, + set 1 to verify. */ + CURLOPT(CURLOPT_PROXY_SSL_VERIFYPEER, CURLOPTTYPE_LONG, 248), + + /* Set if we should verify the Common name from the proxy certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches + * the provided hostname. */ + CURLOPT(CURLOPT_PROXY_SSL_VERIFYHOST, CURLOPTTYPE_LONG, 249), + + /* What version to specifically try to use for proxy. + See CURL_SSLVERSION defines below. */ + CURLOPT(CURLOPT_PROXY_SSLVERSION, CURLOPTTYPE_VALUES, 250), + + /* Set a username for authenticated TLS for proxy */ + CURLOPT(CURLOPT_PROXY_TLSAUTH_USERNAME, CURLOPTTYPE_STRINGPOINT, 251), + + /* Set a password for authenticated TLS for proxy */ + CURLOPT(CURLOPT_PROXY_TLSAUTH_PASSWORD, CURLOPTTYPE_STRINGPOINT, 252), + + /* Set authentication type for authenticated TLS for proxy */ + CURLOPT(CURLOPT_PROXY_TLSAUTH_TYPE, CURLOPTTYPE_STRINGPOINT, 253), + + /* name of the file keeping your private SSL-certificate for proxy */ + CURLOPT(CURLOPT_PROXY_SSLCERT, CURLOPTTYPE_STRINGPOINT, 254), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") for + proxy */ + CURLOPT(CURLOPT_PROXY_SSLCERTTYPE, CURLOPTTYPE_STRINGPOINT, 255), + + /* name of the file keeping your private SSL-key for proxy */ + CURLOPT(CURLOPT_PROXY_SSLKEY, CURLOPTTYPE_STRINGPOINT, 256), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") for + proxy */ + CURLOPT(CURLOPT_PROXY_SSLKEYTYPE, CURLOPTTYPE_STRINGPOINT, 257), + + /* password for the SSL private key for proxy */ + CURLOPT(CURLOPT_PROXY_KEYPASSWD, CURLOPTTYPE_STRINGPOINT, 258), + + /* Specify which SSL ciphers to use for proxy */ + CURLOPT(CURLOPT_PROXY_SSL_CIPHER_LIST, CURLOPTTYPE_STRINGPOINT, 259), + + /* CRL file for proxy */ + CURLOPT(CURLOPT_PROXY_CRLFILE, CURLOPTTYPE_STRINGPOINT, 260), + + /* Enable/disable specific SSL features with a bitmask for proxy, see + CURLSSLOPT_* */ + CURLOPT(CURLOPT_PROXY_SSL_OPTIONS, CURLOPTTYPE_LONG, 261), + + /* Name of pre proxy to use. */ + CURLOPT(CURLOPT_PRE_PROXY, CURLOPTTYPE_STRINGPOINT, 262), + + /* The public key in DER form used to validate the proxy public key + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_PROXY_PINNEDPUBLICKEY, CURLOPTTYPE_STRINGPOINT, 263), + + /* Path to an abstract Unix domain socket */ + CURLOPT(CURLOPT_ABSTRACT_UNIX_SOCKET, CURLOPTTYPE_STRINGPOINT, 264), + + /* Suppress proxy CONNECT response headers from user callbacks */ + CURLOPT(CURLOPT_SUPPRESS_CONNECT_HEADERS, CURLOPTTYPE_LONG, 265), + + /* The request target, instead of extracted from the URL */ + CURLOPT(CURLOPT_REQUEST_TARGET, CURLOPTTYPE_STRINGPOINT, 266), + + /* bitmask of allowed auth methods for connections to SOCKS5 proxies */ + CURLOPT(CURLOPT_SOCKS5_AUTH, CURLOPTTYPE_LONG, 267), + + /* Enable/disable SSH compression */ + CURLOPT(CURLOPT_SSH_COMPRESSION, CURLOPTTYPE_LONG, 268), + + /* Post MIME data. */ + CURLOPT(CURLOPT_MIMEPOST, CURLOPTTYPE_OBJECTPOINT, 269), + + /* Time to use with the CURLOPT_TIMECONDITION. Specified in number of + seconds since 1 Jan 1970. */ + CURLOPT(CURLOPT_TIMEVALUE_LARGE, CURLOPTTYPE_OFF_T, 270), + + /* Head start in milliseconds to give happy eyeballs. */ + CURLOPT(CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, CURLOPTTYPE_LONG, 271), + + /* Function that will be called before a resolver request is made */ + CURLOPT(CURLOPT_RESOLVER_START_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 272), + + /* User data to pass to the resolver start callback. */ + CURLOPT(CURLOPT_RESOLVER_START_DATA, CURLOPTTYPE_CBPOINT, 273), + + /* send HAProxy PROXY protocol header? */ + CURLOPT(CURLOPT_HAPROXYPROTOCOL, CURLOPTTYPE_LONG, 274), + + /* shuffle addresses before use when DNS returns multiple */ + CURLOPT(CURLOPT_DNS_SHUFFLE_ADDRESSES, CURLOPTTYPE_LONG, 275), + + /* Specify which TLS 1.3 ciphers suites to use */ + CURLOPT(CURLOPT_TLS13_CIPHERS, CURLOPTTYPE_STRINGPOINT, 276), + CURLOPT(CURLOPT_PROXY_TLS13_CIPHERS, CURLOPTTYPE_STRINGPOINT, 277), + + /* Disallow specifying username/login in URL. */ + CURLOPT(CURLOPT_DISALLOW_USERNAME_IN_URL, CURLOPTTYPE_LONG, 278), + + /* DNS-over-HTTPS URL */ + CURLOPT(CURLOPT_DOH_URL, CURLOPTTYPE_STRINGPOINT, 279), + + /* Preferred buffer size to use for uploads */ + CURLOPT(CURLOPT_UPLOAD_BUFFERSIZE, CURLOPTTYPE_LONG, 280), + + /* Time in ms between connection upkeep calls for long-lived connections. */ + CURLOPT(CURLOPT_UPKEEP_INTERVAL_MS, CURLOPTTYPE_LONG, 281), + + /* Specify URL using CURL URL API. */ + CURLOPT(CURLOPT_CURLU, CURLOPTTYPE_OBJECTPOINT, 282), + + /* add trailing data just after no more data is available */ + CURLOPT(CURLOPT_TRAILERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 283), + + /* pointer to be passed to HTTP_TRAILER_FUNCTION */ + CURLOPT(CURLOPT_TRAILERDATA, CURLOPTTYPE_CBPOINT, 284), + + /* set this to 1L to allow HTTP/0.9 responses or 0L to disallow */ + CURLOPT(CURLOPT_HTTP09_ALLOWED, CURLOPTTYPE_LONG, 285), + + /* alt-svc control bitmask */ + CURLOPT(CURLOPT_ALTSVC_CTRL, CURLOPTTYPE_LONG, 286), + + /* alt-svc cache file name to possibly read from/write to */ + CURLOPT(CURLOPT_ALTSVC, CURLOPTTYPE_STRINGPOINT, 287), + + /* maximum age of a connection to consider it for reuse (in seconds) */ + CURLOPT(CURLOPT_MAXAGE_CONN, CURLOPTTYPE_LONG, 288), + + /* SASL authorisation identity */ + CURLOPT(CURLOPT_SASL_AUTHZID, CURLOPTTYPE_STRINGPOINT, 289), + + /* allow RCPT TO command to fail for some recipients */ + CURLOPT(CURLOPT_MAIL_RCPT_ALLLOWFAILS, CURLOPTTYPE_LONG, 290), + + /* the private SSL-certificate as a "blob" */ + CURLOPT(CURLOPT_SSLCERT_BLOB, CURLOPTTYPE_BLOB, 291), + CURLOPT(CURLOPT_SSLKEY_BLOB, CURLOPTTYPE_BLOB, 292), + CURLOPT(CURLOPT_PROXY_SSLCERT_BLOB, CURLOPTTYPE_BLOB, 293), + CURLOPT(CURLOPT_PROXY_SSLKEY_BLOB, CURLOPTTYPE_BLOB, 294), + CURLOPT(CURLOPT_ISSUERCERT_BLOB, CURLOPTTYPE_BLOB, 295), + + /* Issuer certificate for proxy */ + CURLOPT(CURLOPT_PROXY_ISSUERCERT, CURLOPTTYPE_STRINGPOINT, 296), + CURLOPT(CURLOPT_PROXY_ISSUERCERT_BLOB, CURLOPTTYPE_BLOB, 297), + + /* the EC curves requested by the TLS client (RFC 8422, 5.1); + * OpenSSL support via 'set_groups'/'set_curves': + * https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set1_groups.html + */ + CURLOPT(CURLOPT_SSL_EC_CURVES, CURLOPTTYPE_STRINGPOINT, 298), + + /* HSTS bitmask */ + CURLOPT(CURLOPT_HSTS_CTRL, CURLOPTTYPE_LONG, 299), + /* HSTS file name */ + CURLOPT(CURLOPT_HSTS, CURLOPTTYPE_STRINGPOINT, 300), + + /* HSTS read callback */ + CURLOPT(CURLOPT_HSTSREADFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 301), + CURLOPT(CURLOPT_HSTSREADDATA, CURLOPTTYPE_CBPOINT, 302), + + /* HSTS write callback */ + CURLOPT(CURLOPT_HSTSWRITEFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 303), + CURLOPT(CURLOPT_HSTSWRITEDATA, CURLOPTTYPE_CBPOINT, 304), + + /* Parameters for V4 signature */ + CURLOPT(CURLOPT_AWS_SIGV4, CURLOPTTYPE_STRINGPOINT, 305), + + /* Same as CURLOPT_SSL_VERIFYPEER but for DoH (DNS-over-HTTPS) servers. */ + CURLOPT(CURLOPT_DOH_SSL_VERIFYPEER, CURLOPTTYPE_LONG, 306), + + /* Same as CURLOPT_SSL_VERIFYHOST but for DoH (DNS-over-HTTPS) servers. */ + CURLOPT(CURLOPT_DOH_SSL_VERIFYHOST, CURLOPTTYPE_LONG, 307), + + /* Same as CURLOPT_SSL_VERIFYSTATUS but for DoH (DNS-over-HTTPS) servers. */ + CURLOPT(CURLOPT_DOH_SSL_VERIFYSTATUS, CURLOPTTYPE_LONG, 308), + + /* The CA certificates as "blob" used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_CAINFO_BLOB, CURLOPTTYPE_BLOB, 309), + + /* The CA certificates as "blob" used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CURLOPT(CURLOPT_PROXY_CAINFO_BLOB, CURLOPTTYPE_BLOB, 310), + + CURLOPT_LASTENTRY /* the last unused */ +} CURLoption; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2011 */ + +/* This was added in version 7.19.1 */ +#define CURLOPT_POST301 CURLOPT_POSTREDIR + +/* These are scheduled to disappear by 2009 */ + +/* The following were added in 7.17.0 */ +#define CURLOPT_SSLKEYPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_FTPAPPEND CURLOPT_APPEND +#define CURLOPT_FTPLISTONLY CURLOPT_DIRLISTONLY +#define CURLOPT_FTP_SSL CURLOPT_USE_SSL + +/* The following were added earlier */ + +#define CURLOPT_SSLCERTPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_KRB4LEVEL CURLOPT_KRBLEVEL + +#else +/* This is set if CURL_NO_OLDIES is defined at compile-time */ +#undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ +#endif + + + /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ +#define CURL_IPRESOLVE_WHATEVER 0 /* default, uses addresses to all IP + versions that your system allows */ +#define CURL_IPRESOLVE_V4 1 /* uses only IPv4 addresses/connections */ +#define CURL_IPRESOLVE_V6 2 /* uses only IPv6 addresses/connections */ + + /* three convenient "aliases" that follow the name scheme better */ +#define CURLOPT_RTSPHEADER CURLOPT_HTTPHEADER + + /* These enums are for use with the CURLOPT_HTTP_VERSION option. */ +enum { + CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd + like the library to choose the best possible + for us! */ + CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */ + CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */ + CURL_HTTP_VERSION_2_0, /* please use HTTP 2 in the request */ + CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */ + CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1 + Upgrade */ + CURL_HTTP_VERSION_3 = 30, /* Makes use of explicit HTTP/3 without fallback. + Use CURLOPT_ALTSVC to enable HTTP/3 upgrade */ + CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ +}; + +/* Convenience definition simple because the name of the version is HTTP/2 and + not 2.0. The 2_0 version of the enum name was set while the version was + still planned to be 2.0 and we stick to it for compatibility. */ +#define CURL_HTTP_VERSION_2 CURL_HTTP_VERSION_2_0 + +/* + * Public API enums for RTSP requests + */ +enum { + CURL_RTSPREQ_NONE, /* first in list */ + CURL_RTSPREQ_OPTIONS, + CURL_RTSPREQ_DESCRIBE, + CURL_RTSPREQ_ANNOUNCE, + CURL_RTSPREQ_SETUP, + CURL_RTSPREQ_PLAY, + CURL_RTSPREQ_PAUSE, + CURL_RTSPREQ_TEARDOWN, + CURL_RTSPREQ_GET_PARAMETER, + CURL_RTSPREQ_SET_PARAMETER, + CURL_RTSPREQ_RECORD, + CURL_RTSPREQ_RECEIVE, + CURL_RTSPREQ_LAST /* last in list */ +}; + + /* These enums are for use with the CURLOPT_NETRC option. */ +enum CURL_NETRC_OPTION { + CURL_NETRC_IGNORED, /* The .netrc will never be read. + * This is the default. */ + CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred + * to one in the .netrc. */ + CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. + * Unless one is set programmatically, the .netrc + * will be queried. */ + CURL_NETRC_LAST +}; + +enum { + CURL_SSLVERSION_DEFAULT, + CURL_SSLVERSION_TLSv1, /* TLS 1.x */ + CURL_SSLVERSION_SSLv2, + CURL_SSLVERSION_SSLv3, + CURL_SSLVERSION_TLSv1_0, + CURL_SSLVERSION_TLSv1_1, + CURL_SSLVERSION_TLSv1_2, + CURL_SSLVERSION_TLSv1_3, + + CURL_SSLVERSION_LAST /* never use, keep last */ +}; + +enum { + CURL_SSLVERSION_MAX_NONE = 0, + CURL_SSLVERSION_MAX_DEFAULT = (CURL_SSLVERSION_TLSv1 << 16), + CURL_SSLVERSION_MAX_TLSv1_0 = (CURL_SSLVERSION_TLSv1_0 << 16), + CURL_SSLVERSION_MAX_TLSv1_1 = (CURL_SSLVERSION_TLSv1_1 << 16), + CURL_SSLVERSION_MAX_TLSv1_2 = (CURL_SSLVERSION_TLSv1_2 << 16), + CURL_SSLVERSION_MAX_TLSv1_3 = (CURL_SSLVERSION_TLSv1_3 << 16), + + /* never use, keep last */ + CURL_SSLVERSION_MAX_LAST = (CURL_SSLVERSION_LAST << 16) +}; + +enum CURL_TLSAUTH { + CURL_TLSAUTH_NONE, + CURL_TLSAUTH_SRP, + CURL_TLSAUTH_LAST /* never use, keep last */ +}; + +/* symbols to use with CURLOPT_POSTREDIR. + CURL_REDIR_POST_301, CURL_REDIR_POST_302 and CURL_REDIR_POST_303 + can be bitwise ORed so that CURL_REDIR_POST_301 | CURL_REDIR_POST_302 + | CURL_REDIR_POST_303 == CURL_REDIR_POST_ALL */ + +#define CURL_REDIR_GET_ALL 0 +#define CURL_REDIR_POST_301 1 +#define CURL_REDIR_POST_302 2 +#define CURL_REDIR_POST_303 4 +#define CURL_REDIR_POST_ALL \ + (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) + +typedef enum { + CURL_TIMECOND_NONE, + + CURL_TIMECOND_IFMODSINCE, + CURL_TIMECOND_IFUNMODSINCE, + CURL_TIMECOND_LASTMOD, + + CURL_TIMECOND_LAST +} curl_TimeCond; + +/* Special size_t value signaling a null-terminated string. */ +#define CURL_ZERO_TERMINATED ((size_t) -1) + +/* curl_strequal() and curl_strnequal() are subject for removal in a future + release */ +CURL_EXTERN int curl_strequal(const char *s1, const char *s2); +CURL_EXTERN int curl_strnequal(const char *s1, const char *s2, size_t n); + +/* Mime/form handling support. */ +typedef struct curl_mime curl_mime; /* Mime context. */ +typedef struct curl_mimepart curl_mimepart; /* Mime part context. */ + +/* + * NAME curl_mime_init() + * + * DESCRIPTION + * + * Create a mime context and return its handle. The easy parameter is the + * target handle. + */ +CURL_EXTERN curl_mime *curl_mime_init(CURL *easy); + +/* + * NAME curl_mime_free() + * + * DESCRIPTION + * + * release a mime handle and its substructures. + */ +CURL_EXTERN void curl_mime_free(curl_mime *mime); + +/* + * NAME curl_mime_addpart() + * + * DESCRIPTION + * + * Append a new empty part to the given mime context and return a handle to + * the created part. + */ +CURL_EXTERN curl_mimepart *curl_mime_addpart(curl_mime *mime); + +/* + * NAME curl_mime_name() + * + * DESCRIPTION + * + * Set mime/form part name. + */ +CURL_EXTERN CURLcode curl_mime_name(curl_mimepart *part, const char *name); + +/* + * NAME curl_mime_filename() + * + * DESCRIPTION + * + * Set mime part remote file name. + */ +CURL_EXTERN CURLcode curl_mime_filename(curl_mimepart *part, + const char *filename); + +/* + * NAME curl_mime_type() + * + * DESCRIPTION + * + * Set mime part type. + */ +CURL_EXTERN CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype); + +/* + * NAME curl_mime_encoder() + * + * DESCRIPTION + * + * Set mime data transfer encoder. + */ +CURL_EXTERN CURLcode curl_mime_encoder(curl_mimepart *part, + const char *encoding); + +/* + * NAME curl_mime_data() + * + * DESCRIPTION + * + * Set mime part data source from memory data, + */ +CURL_EXTERN CURLcode curl_mime_data(curl_mimepart *part, + const char *data, size_t datasize); + +/* + * NAME curl_mime_filedata() + * + * DESCRIPTION + * + * Set mime part data source from named file. + */ +CURL_EXTERN CURLcode curl_mime_filedata(curl_mimepart *part, + const char *filename); + +/* + * NAME curl_mime_data_cb() + * + * DESCRIPTION + * + * Set mime part data source from callback function. + */ +CURL_EXTERN CURLcode curl_mime_data_cb(curl_mimepart *part, + curl_off_t datasize, + curl_read_callback readfunc, + curl_seek_callback seekfunc, + curl_free_callback freefunc, + void *arg); + +/* + * NAME curl_mime_subparts() + * + * DESCRIPTION + * + * Set mime part data source from subparts. + */ +CURL_EXTERN CURLcode curl_mime_subparts(curl_mimepart *part, + curl_mime *subparts); +/* + * NAME curl_mime_headers() + * + * DESCRIPTION + * + * Set mime part headers. + */ +CURL_EXTERN CURLcode curl_mime_headers(curl_mimepart *part, + struct curl_slist *headers, + int take_ownership); + +typedef enum { + CURLFORM_NOTHING, /********* the first one is unused ************/ + CURLFORM_COPYNAME, + CURLFORM_PTRNAME, + CURLFORM_NAMELENGTH, + CURLFORM_COPYCONTENTS, + CURLFORM_PTRCONTENTS, + CURLFORM_CONTENTSLENGTH, + CURLFORM_FILECONTENT, + CURLFORM_ARRAY, + CURLFORM_OBSOLETE, + CURLFORM_FILE, + + CURLFORM_BUFFER, + CURLFORM_BUFFERPTR, + CURLFORM_BUFFERLENGTH, + + CURLFORM_CONTENTTYPE, + CURLFORM_CONTENTHEADER, + CURLFORM_FILENAME, + CURLFORM_END, + CURLFORM_OBSOLETE2, + + CURLFORM_STREAM, + CURLFORM_CONTENTLEN, /* added in 7.46.0, provide a curl_off_t length */ + + CURLFORM_LASTENTRY /* the last unused */ +} CURLformoption; + +/* structure to be used as parameter for CURLFORM_ARRAY */ +struct curl_forms { + CURLformoption option; + const char *value; +}; + +/* use this for multipart formpost building */ +/* Returns code for curl_formadd() + * + * Returns: + * CURL_FORMADD_OK on success + * CURL_FORMADD_MEMORY if the FormInfo allocation fails + * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form + * CURL_FORMADD_NULL if a null pointer was given for a char + * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed + * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used + * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) + * CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated + * CURL_FORMADD_MEMORY if some allocation for string copying failed. + * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array + * + ***************************************************************************/ +typedef enum { + CURL_FORMADD_OK, /* first, no error */ + + CURL_FORMADD_MEMORY, + CURL_FORMADD_OPTION_TWICE, + CURL_FORMADD_NULL, + CURL_FORMADD_UNKNOWN_OPTION, + CURL_FORMADD_INCOMPLETE, + CURL_FORMADD_ILLEGAL_ARRAY, + CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */ + + CURL_FORMADD_LAST /* last */ +} CURLFORMcode; + +/* + * NAME curl_formadd() + * + * DESCRIPTION + * + * Pretty advanced function for building multi-part formposts. Each invoke + * adds one part that together construct a full post. Then use + * CURLOPT_HTTPPOST to send it off to libcurl. + */ +CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, + struct curl_httppost **last_post, + ...); + +/* + * callback function for curl_formget() + * The void *arg pointer will be the one passed as second argument to + * curl_formget(). + * The character buffer passed to it must not be freed. + * Should return the buffer length passed to it as the argument "len" on + * success. + */ +typedef size_t (*curl_formget_callback)(void *arg, const char *buf, + size_t len); + +/* + * NAME curl_formget() + * + * DESCRIPTION + * + * Serialize a curl_httppost struct built with curl_formadd(). + * Accepts a void pointer as second argument which will be passed to + * the curl_formget_callback function. + * Returns 0 on success. + */ +CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, + curl_formget_callback append); +/* + * NAME curl_formfree() + * + * DESCRIPTION + * + * Free a multipart formpost previously built with curl_formadd(). + */ +CURL_EXTERN void curl_formfree(struct curl_httppost *form); + +/* + * NAME curl_getenv() + * + * DESCRIPTION + * + * Returns a malloc()'ed string that MUST be curl_free()ed after usage is + * complete. DEPRECATED - see lib/README.curlx + */ +CURL_EXTERN char *curl_getenv(const char *variable); + +/* + * NAME curl_version() + * + * DESCRIPTION + * + * Returns a static ascii string of the libcurl version. + */ +CURL_EXTERN char *curl_version(void); + +/* + * NAME curl_easy_escape() + * + * DESCRIPTION + * + * Escapes URL strings (converts all letters consider illegal in URLs to their + * %XX versions). This function returns a new allocated string or NULL if an + * error occurred. + */ +CURL_EXTERN char *curl_easy_escape(CURL *handle, + const char *string, + int length); + +/* the previous version: */ +CURL_EXTERN char *curl_escape(const char *string, + int length); + + +/* + * NAME curl_easy_unescape() + * + * DESCRIPTION + * + * Unescapes URL encoding in strings (converts all %XX codes to their 8bit + * versions). This function returns a new allocated string or NULL if an error + * occurred. + * Conversion Note: On non-ASCII platforms the ASCII %XX codes are + * converted into the host encoding. + */ +CURL_EXTERN char *curl_easy_unescape(CURL *handle, + const char *string, + int length, + int *outlength); + +/* the previous version */ +CURL_EXTERN char *curl_unescape(const char *string, + int length); + +/* + * NAME curl_free() + * + * DESCRIPTION + * + * Provided for de-allocation in the same translation unit that did the + * allocation. Added in libcurl 7.10 + */ +CURL_EXTERN void curl_free(void *p); + +/* + * NAME curl_global_init() + * + * DESCRIPTION + * + * curl_global_init() should be invoked exactly once for each application that + * uses libcurl and before any call of other libcurl functions. + * + * This function is not thread-safe! + */ +CURL_EXTERN CURLcode curl_global_init(long flags); + +/* + * NAME curl_global_init_mem() + * + * DESCRIPTION + * + * curl_global_init() or curl_global_init_mem() should be invoked exactly once + * for each application that uses libcurl. This function can be used to + * initialize libcurl and set user defined memory management callback + * functions. Users can implement memory management routines to check for + * memory leaks, check for mis-use of the curl library etc. User registered + * callback routines will be invoked by this library instead of the system + * memory management routines like malloc, free etc. + */ +CURL_EXTERN CURLcode curl_global_init_mem(long flags, + curl_malloc_callback m, + curl_free_callback f, + curl_realloc_callback r, + curl_strdup_callback s, + curl_calloc_callback c); + +/* + * NAME curl_global_cleanup() + * + * DESCRIPTION + * + * curl_global_cleanup() should be invoked exactly once for each application + * that uses libcurl + */ +CURL_EXTERN void curl_global_cleanup(void); + +/* linked-list structure for the CURLOPT_QUOTE option (and other) */ +struct curl_slist { + char *data; + struct curl_slist *next; +}; + +/* + * NAME curl_global_sslset() + * + * DESCRIPTION + * + * When built with multiple SSL backends, curl_global_sslset() allows to + * choose one. This function can only be called once, and it must be called + * *before* curl_global_init(). + * + * The backend can be identified by the id (e.g. CURLSSLBACKEND_OPENSSL). The + * backend can also be specified via the name parameter (passing -1 as id). + * If both id and name are specified, the name will be ignored. If neither id + * nor name are specified, the function will fail with + * CURLSSLSET_UNKNOWN_BACKEND and set the "avail" pointer to the + * NULL-terminated list of available backends. + * + * Upon success, the function returns CURLSSLSET_OK. + * + * If the specified SSL backend is not available, the function returns + * CURLSSLSET_UNKNOWN_BACKEND and sets the "avail" pointer to a NULL-terminated + * list of available SSL backends. + * + * The SSL backend can be set only once. If it has already been set, a + * subsequent attempt to change it will result in a CURLSSLSET_TOO_LATE. + */ + +struct curl_ssl_backend { + curl_sslbackend id; + const char *name; +}; +typedef struct curl_ssl_backend curl_ssl_backend; + +typedef enum { + CURLSSLSET_OK = 0, + CURLSSLSET_UNKNOWN_BACKEND, + CURLSSLSET_TOO_LATE, + CURLSSLSET_NO_BACKENDS /* libcurl was built without any SSL support */ +} CURLsslset; + +CURL_EXTERN CURLsslset curl_global_sslset(curl_sslbackend id, const char *name, + const curl_ssl_backend ***avail); + +/* + * NAME curl_slist_append() + * + * DESCRIPTION + * + * Appends a string to a linked list. If no list exists, it will be created + * first. Returns the new list, after appending. + */ +CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *, + const char *); + +/* + * NAME curl_slist_free_all() + * + * DESCRIPTION + * + * free a previously built curl_slist. + */ +CURL_EXTERN void curl_slist_free_all(struct curl_slist *); + +/* + * NAME curl_getdate() + * + * DESCRIPTION + * + * Returns the time, in seconds since 1 Jan 1970 of the time string given in + * the first argument. The time argument in the second parameter is unused + * and should be set to NULL. + */ +CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); + +/* info about the certificate chain, only for OpenSSL, GnuTLS, Schannel, NSS + and GSKit builds. Asked for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ +struct curl_certinfo { + int num_of_certs; /* number of certificates with information */ + struct curl_slist **certinfo; /* for each index in this array, there's a + linked list with textual information in the + format "name: value" */ +}; + +/* Information about the SSL library used and the respective internal SSL + handle, which can be used to obtain further information regarding the + connection. Asked for with CURLINFO_TLS_SSL_PTR or CURLINFO_TLS_SESSION. */ +struct curl_tlssessioninfo { + curl_sslbackend backend; + void *internals; +}; + +#define CURLINFO_STRING 0x100000 +#define CURLINFO_LONG 0x200000 +#define CURLINFO_DOUBLE 0x300000 +#define CURLINFO_SLIST 0x400000 +#define CURLINFO_PTR 0x400000 /* same as SLIST */ +#define CURLINFO_SOCKET 0x500000 +#define CURLINFO_OFF_T 0x600000 +#define CURLINFO_MASK 0x0fffff +#define CURLINFO_TYPEMASK 0xf00000 + +typedef enum { + CURLINFO_NONE, /* first, never use this */ + CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1, + CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, + CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3, + CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4, + CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5, + CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6, + CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7, + CURLINFO_SIZE_UPLOAD_T = CURLINFO_OFF_T + 7, + CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8, + CURLINFO_SIZE_DOWNLOAD_T = CURLINFO_OFF_T + 8, + CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9, + CURLINFO_SPEED_DOWNLOAD_T = CURLINFO_OFF_T + 9, + CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10, + CURLINFO_SPEED_UPLOAD_T = CURLINFO_OFF_T + 10, + CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11, + CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12, + CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13, + CURLINFO_FILETIME = CURLINFO_LONG + 14, + CURLINFO_FILETIME_T = CURLINFO_OFF_T + 14, + CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15, + CURLINFO_CONTENT_LENGTH_DOWNLOAD_T = CURLINFO_OFF_T + 15, + CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16, + CURLINFO_CONTENT_LENGTH_UPLOAD_T = CURLINFO_OFF_T + 16, + CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17, + CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18, + CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19, + CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20, + CURLINFO_PRIVATE = CURLINFO_STRING + 21, + CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22, + CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23, + CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24, + CURLINFO_OS_ERRNO = CURLINFO_LONG + 25, + CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26, + CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27, + CURLINFO_COOKIELIST = CURLINFO_SLIST + 28, + CURLINFO_LASTSOCKET = CURLINFO_LONG + 29, + CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30, + CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31, + CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32, + CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33, + CURLINFO_CERTINFO = CURLINFO_PTR + 34, + CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35, + CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36, + CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37, + CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38, + CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39, + CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40, + CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, + CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, + CURLINFO_TLS_SESSION = CURLINFO_PTR + 43, + CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44, + CURLINFO_TLS_SSL_PTR = CURLINFO_PTR + 45, + CURLINFO_HTTP_VERSION = CURLINFO_LONG + 46, + CURLINFO_PROXY_SSL_VERIFYRESULT = CURLINFO_LONG + 47, + CURLINFO_PROTOCOL = CURLINFO_LONG + 48, + CURLINFO_SCHEME = CURLINFO_STRING + 49, + CURLINFO_TOTAL_TIME_T = CURLINFO_OFF_T + 50, + CURLINFO_NAMELOOKUP_TIME_T = CURLINFO_OFF_T + 51, + CURLINFO_CONNECT_TIME_T = CURLINFO_OFF_T + 52, + CURLINFO_PRETRANSFER_TIME_T = CURLINFO_OFF_T + 53, + CURLINFO_STARTTRANSFER_TIME_T = CURLINFO_OFF_T + 54, + CURLINFO_REDIRECT_TIME_T = CURLINFO_OFF_T + 55, + CURLINFO_APPCONNECT_TIME_T = CURLINFO_OFF_T + 56, + CURLINFO_RETRY_AFTER = CURLINFO_OFF_T + 57, + CURLINFO_EFFECTIVE_METHOD = CURLINFO_STRING + 58, + CURLINFO_PROXY_ERROR = CURLINFO_LONG + 59, + CURLINFO_REFERER = CURLINFO_STRING + 60, + + CURLINFO_LASTONE = 60 +} CURLINFO; + +/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as + CURLINFO_HTTP_CODE */ +#define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE + +typedef enum { + CURLCLOSEPOLICY_NONE, /* first, never use this */ + + CURLCLOSEPOLICY_OLDEST, + CURLCLOSEPOLICY_LEAST_RECENTLY_USED, + CURLCLOSEPOLICY_LEAST_TRAFFIC, + CURLCLOSEPOLICY_SLOWEST, + CURLCLOSEPOLICY_CALLBACK, + + CURLCLOSEPOLICY_LAST /* last, never use this */ +} curl_closepolicy; + +#define CURL_GLOBAL_SSL (1<<0) /* no purpose since since 7.57.0 */ +#define CURL_GLOBAL_WIN32 (1<<1) +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_NOTHING 0 +#define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL +#define CURL_GLOBAL_ACK_EINTR (1<<2) + + +/***************************************************************************** + * Setup defines, protos etc for the sharing stuff. + */ + +/* Different data locks for a single share */ +typedef enum { + CURL_LOCK_DATA_NONE = 0, + /* CURL_LOCK_DATA_SHARE is used internally to say that + * the locking is just made to change the internal state of the share + * itself. + */ + CURL_LOCK_DATA_SHARE, + CURL_LOCK_DATA_COOKIE, + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_SSL_SESSION, + CURL_LOCK_DATA_CONNECT, + CURL_LOCK_DATA_PSL, + CURL_LOCK_DATA_LAST +} curl_lock_data; + +/* Different lock access types */ +typedef enum { + CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */ + CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */ + CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */ + CURL_LOCK_ACCESS_LAST /* never use */ +} curl_lock_access; + +typedef void (*curl_lock_function)(CURL *handle, + curl_lock_data data, + curl_lock_access locktype, + void *userptr); +typedef void (*curl_unlock_function)(CURL *handle, + curl_lock_data data, + void *userptr); + + +typedef enum { + CURLSHE_OK, /* all is fine */ + CURLSHE_BAD_OPTION, /* 1 */ + CURLSHE_IN_USE, /* 2 */ + CURLSHE_INVALID, /* 3 */ + CURLSHE_NOMEM, /* 4 out of memory */ + CURLSHE_NOT_BUILT_IN, /* 5 feature not present in lib */ + CURLSHE_LAST /* never use */ +} CURLSHcode; + +typedef enum { + CURLSHOPT_NONE, /* don't use */ + CURLSHOPT_SHARE, /* specify a data type to share */ + CURLSHOPT_UNSHARE, /* specify which data type to stop sharing */ + CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */ + CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */ + CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock + callback functions */ + CURLSHOPT_LAST /* never use */ +} CURLSHoption; + +CURL_EXTERN CURLSH *curl_share_init(void); +CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...); +CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *); + +/**************************************************************************** + * Structures for querying information about the curl library at runtime. + */ + +typedef enum { + CURLVERSION_FIRST, + CURLVERSION_SECOND, + CURLVERSION_THIRD, + CURLVERSION_FOURTH, + CURLVERSION_FIFTH, + CURLVERSION_SIXTH, + CURLVERSION_SEVENTH, + CURLVERSION_EIGHTH, + CURLVERSION_NINTH, + CURLVERSION_TENTH, + CURLVERSION_LAST /* never actually use this */ +} CURLversion; + +/* The 'CURLVERSION_NOW' is the symbolic name meant to be used by + basically all programs ever that want to get version information. It is + meant to be a built-in version number for what kind of struct the caller + expects. If the struct ever changes, we redefine the NOW to another enum + from above. */ +#define CURLVERSION_NOW CURLVERSION_TENTH + +struct curl_version_info_data { + CURLversion age; /* age of the returned struct */ + const char *version; /* LIBCURL_VERSION */ + unsigned int version_num; /* LIBCURL_VERSION_NUM */ + const char *host; /* OS/host/cpu/machine when configured */ + int features; /* bitmask, see defines below */ + const char *ssl_version; /* human readable string */ + long ssl_version_num; /* not used anymore, always 0 */ + const char *libz_version; /* human readable string */ + /* protocols is terminated by an entry with a NULL protoname */ + const char * const *protocols; + + /* The fields below this were added in CURLVERSION_SECOND */ + const char *ares; + int ares_num; + + /* This field was added in CURLVERSION_THIRD */ + const char *libidn; + + /* These field were added in CURLVERSION_FOURTH */ + + /* Same as '_libiconv_version' if built with HAVE_ICONV */ + int iconv_ver_num; + + const char *libssh_version; /* human readable string */ + + /* These fields were added in CURLVERSION_FIFTH */ + unsigned int brotli_ver_num; /* Numeric Brotli version + (MAJOR << 24) | (MINOR << 12) | PATCH */ + const char *brotli_version; /* human readable string. */ + + /* These fields were added in CURLVERSION_SIXTH */ + unsigned int nghttp2_ver_num; /* Numeric nghttp2 version + (MAJOR << 16) | (MINOR << 8) | PATCH */ + const char *nghttp2_version; /* human readable string. */ + const char *quic_version; /* human readable quic (+ HTTP/3) library + + version or NULL */ + + /* These fields were added in CURLVERSION_SEVENTH */ + const char *cainfo; /* the built-in default CURLOPT_CAINFO, might + be NULL */ + const char *capath; /* the built-in default CURLOPT_CAPATH, might + be NULL */ + + /* These fields were added in CURLVERSION_EIGHTH */ + unsigned int zstd_ver_num; /* Numeric Zstd version + (MAJOR << 24) | (MINOR << 12) | PATCH */ + const char *zstd_version; /* human readable string. */ + + /* These fields were added in CURLVERSION_NINTH */ + const char *hyper_version; /* human readable string. */ + + /* These fields were added in CURLVERSION_TENTH */ + const char *gsasl_version; /* human readable string. */ +}; +typedef struct curl_version_info_data curl_version_info_data; + +#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */ +#define CURL_VERSION_KERBEROS4 (1<<1) /* Kerberos V4 auth is supported + (deprecated) */ +#define CURL_VERSION_SSL (1<<2) /* SSL options are present */ +#define CURL_VERSION_LIBZ (1<<3) /* libz features are present */ +#define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */ +#define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth is supported + (deprecated) */ +#define CURL_VERSION_DEBUG (1<<6) /* Built with debug capabilities */ +#define CURL_VERSION_ASYNCHDNS (1<<7) /* Asynchronous DNS resolves */ +#define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth is supported */ +#define CURL_VERSION_LARGEFILE (1<<9) /* Supports files larger than 2GB */ +#define CURL_VERSION_IDN (1<<10) /* Internationized Domain Names are + supported */ +#define CURL_VERSION_SSPI (1<<11) /* Built against Windows SSPI */ +#define CURL_VERSION_CONV (1<<12) /* Character conversions supported */ +#define CURL_VERSION_CURLDEBUG (1<<13) /* Debug memory tracking supported */ +#define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */ +#define CURL_VERSION_NTLM_WB (1<<15) /* NTLM delegation to winbind helper + is supported */ +#define CURL_VERSION_HTTP2 (1<<16) /* HTTP2 support built-in */ +#define CURL_VERSION_GSSAPI (1<<17) /* Built against a GSS-API library */ +#define CURL_VERSION_KERBEROS5 (1<<18) /* Kerberos V5 auth is supported */ +#define CURL_VERSION_UNIX_SOCKETS (1<<19) /* Unix domain sockets support */ +#define CURL_VERSION_PSL (1<<20) /* Mozilla's Public Suffix List, used + for cookie domain verification */ +#define CURL_VERSION_HTTPS_PROXY (1<<21) /* HTTPS-proxy support built-in */ +#define CURL_VERSION_MULTI_SSL (1<<22) /* Multiple SSL backends available */ +#define CURL_VERSION_BROTLI (1<<23) /* Brotli features are present. */ +#define CURL_VERSION_ALTSVC (1<<24) /* Alt-Svc handling built-in */ +#define CURL_VERSION_HTTP3 (1<<25) /* HTTP3 support built-in */ +#define CURL_VERSION_ZSTD (1<<26) /* zstd features are present */ +#define CURL_VERSION_UNICODE (1<<27) /* Unicode support on Windows */ +#define CURL_VERSION_HSTS (1<<28) /* HSTS is supported */ +#define CURL_VERSION_GSASL (1<<29) /* libgsasl is supported */ + + /* + * NAME curl_version_info() + * + * DESCRIPTION + * + * This function returns a pointer to a static copy of the version info + * struct. See above. + */ +CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion); + +/* + * NAME curl_easy_strerror() + * + * DESCRIPTION + * + * The curl_easy_strerror function may be used to turn a CURLcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_easy_strerror(CURLcode); + +/* + * NAME curl_share_strerror() + * + * DESCRIPTION + * + * The curl_share_strerror function may be used to turn a CURLSHcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_share_strerror(CURLSHcode); + +/* + * NAME curl_easy_pause() + * + * DESCRIPTION + * + * The curl_easy_pause function pauses or unpauses transfers. Select the new + * state by setting the bitmask, use the convenience defines below. + * + */ +CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); + +#define CURLPAUSE_RECV (1<<0) +#define CURLPAUSE_RECV_CONT (0) + +#define CURLPAUSE_SEND (1<<2) +#define CURLPAUSE_SEND_CONT (0) + +#define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) +#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) + +#ifdef __cplusplus +} +#endif + +/* unfortunately, the easy.h and multi.h include files need options and info + stuff before they can be included! */ +#include "easy.h" /* nothing in curl is fun without the easy stuff */ +#include "multi.h" +#include "urlapi.h" +#include "options.h" + +/* the typechecker doesn't work in C++ (yet) */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \ + !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK) +#include "typecheck-gcc.h" +#else +#if defined(__STDC__) && (__STDC__ >= 1) +/* This preprocessor magic that replaces a call with the exact same call is + only done to make sure application authors pass exactly three arguments + to these functions. */ +#define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) +#define curl_easy_getinfo(handle,info,arg) curl_easy_getinfo(handle,info,arg) +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) +#endif /* __STDC__ >= 1 */ +#endif /* gcc >= 4.3 && !__cplusplus */ + +#endif /* CURLINC_CURL_H */ diff --git a/src/curl/curlver.h b/src/curl/curlver.h new file mode 100644 index 0000000..d2ccdba --- /dev/null +++ b/src/curl/curlver.h @@ -0,0 +1,77 @@ +#ifndef CURLINC_CURLVER_H +#define CURLINC_CURLVER_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* This header file contains nothing but libcurl version info, generated by + a script at release-time. This was made its own header file in 7.11.2 */ + +/* This is the global package copyright */ +#define LIBCURL_COPYRIGHT "1996 - 2021 Daniel Stenberg, <daniel@haxx.se>." + +/* This is the version number of the libcurl package from which this header + file origins: */ +#define LIBCURL_VERSION "7.78.0" + +/* The numeric version number is also available "in parts" by using these + defines: */ +#define LIBCURL_VERSION_MAJOR 7 +#define LIBCURL_VERSION_MINOR 78 +#define LIBCURL_VERSION_PATCH 0 + +/* This is the numeric version of the libcurl version number, meant for easier + parsing and comparisons by programs. The LIBCURL_VERSION_NUM define will + always follow this syntax: + + 0xXXYYZZ + + Where XX, YY and ZZ are the main version, release and patch numbers in + hexadecimal (using 8 bits each). All three numbers are always represented + using two digits. 1.2 would appear as "0x010200" while version 9.11.7 + appears as "0x090b07". + + This 6-digit (24 bits) hexadecimal number does not show pre-release number, + and it is always a greater number in a more recent release. It makes + comparisons with greater than and less than work. + + Note: This define is the full hex number and _does not_ use the + CURL_VERSION_BITS() macro since curl's own configure script greps for it + and needs it to contain the full number. +*/ +#define LIBCURL_VERSION_NUM 0x074e00 + +/* + * This is the date and time when the full source package was created. The + * timestamp is not stored in git, as the timestamp is properly set in the + * tarballs by the maketgz script. + * + * The format of the date follows this template: + * + * "2007-11-23" + */ +#define LIBCURL_TIMESTAMP "2021-07-21" + +#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z)) +#define CURL_AT_LEAST_VERSION(x,y,z) \ + (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) + +#endif /* CURLINC_CURLVER_H */ diff --git a/src/curl/easy.h b/src/curl/easy.h new file mode 100644 index 0000000..2dbfb26 --- /dev/null +++ b/src/curl/easy.h @@ -0,0 +1,123 @@ +#ifndef CURLINC_EASY_H +#define CURLINC_EASY_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +/* Flag bits in the curl_blob struct: */ +#define CURL_BLOB_COPY 1 /* tell libcurl to copy the data */ +#define CURL_BLOB_NOCOPY 0 /* tell libcurl to NOT copy the data */ + +struct curl_blob { + void *data; + size_t len; + unsigned int flags; /* bit 0 is defined, the rest are reserved and should be + left zeroes */ +}; + +CURL_EXTERN CURL *curl_easy_init(void); +CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); +CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); +CURL_EXTERN void curl_easy_cleanup(CURL *curl); + +/* + * NAME curl_easy_getinfo() + * + * DESCRIPTION + * + * Request internal information from the curl session with this function. The + * third argument MUST be a pointer to a long, a pointer to a char * or a + * pointer to a double (as the documentation describes elsewhere). The data + * pointed to will be filled in accordingly and can be relied upon only if the + * function returns CURLE_OK. This function is intended to get used *AFTER* a + * performed transfer, all results from this function are undefined until the + * transfer is completed. + */ +CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); + + +/* + * NAME curl_easy_duphandle() + * + * DESCRIPTION + * + * Creates a new curl session handle with the same options set for the handle + * passed in. Duplicating a handle could only be a matter of cloning data and + * options, internal state info and things like persistent connections cannot + * be transferred. It is useful in multithreaded applications when you can run + * curl_easy_duphandle() for each new thread to avoid a series of identical + * curl_easy_setopt() invokes in every thread. + */ +CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl); + +/* + * NAME curl_easy_reset() + * + * DESCRIPTION + * + * Re-initializes a CURL handle to the default values. This puts back the + * handle to the same state as it was in when it was just created. + * + * It does keep: live connections, the Session ID cache, the DNS cache and the + * cookies. + */ +CURL_EXTERN void curl_easy_reset(CURL *curl); + +/* + * NAME curl_easy_recv() + * + * DESCRIPTION + * + * Receives data from the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, + size_t *n); + +/* + * NAME curl_easy_send() + * + * DESCRIPTION + * + * Sends data over the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, + size_t buflen, size_t *n); + + +/* + * NAME curl_easy_upkeep() + * + * DESCRIPTION + * + * Performs connection upkeep for the given session handle. + */ +CURL_EXTERN CURLcode curl_easy_upkeep(CURL *curl); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/curl/mprintf.h b/src/curl/mprintf.h new file mode 100644 index 0000000..3549552 --- /dev/null +++ b/src/curl/mprintf.h @@ -0,0 +1,50 @@ +#ifndef CURLINC_MPRINTF_H +#define CURLINC_MPRINTF_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include <stdarg.h> +#include <stdio.h> /* needed for FILE */ +#include "curl.h" /* for CURL_EXTERN */ + +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN int curl_mprintf(const char *format, ...); +CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); +CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); +CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, + const char *format, ...); +CURL_EXTERN int curl_mvprintf(const char *format, va_list args); +CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); +CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); +CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, + const char *format, va_list args); +CURL_EXTERN char *curl_maprintf(const char *format, ...); +CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); + +#ifdef __cplusplus +} +#endif + +#endif /* CURLINC_MPRINTF_H */ diff --git a/src/curl/multi.h b/src/curl/multi.h new file mode 100644 index 0000000..187a5f6 --- /dev/null +++ b/src/curl/multi.h @@ -0,0 +1,456 @@ +#ifndef CURLINC_MULTI_H +#define CURLINC_MULTI_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* + This is an "external" header file. Don't give away any internals here! + + GOALS + + o Enable a "pull" interface. The application that uses libcurl decides where + and when to ask libcurl to get/send data. + + o Enable multiple simultaneous transfers in the same thread without making it + complicated for the application. + + o Enable the application to select() on its own file descriptors and curl's + file descriptors simultaneous easily. + +*/ + +/* + * This header file should not really need to include "curl.h" since curl.h + * itself includes this file and we expect user applications to do #include + * <curl/curl.h> without the need for especially including multi.h. + * + * For some reason we added this include here at one point, and rather than to + * break existing (wrongly written) libcurl applications, we leave it as-is + * but with this warning attached. + */ +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) +typedef struct Curl_multi CURLM; +#else +typedef void CURLM; +#endif + +typedef enum { + CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or + curl_multi_socket*() soon */ + CURLM_OK, + CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ + CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ + CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ + CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ + CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ + CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ + CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was + attempted to get added - again */ + CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a + callback */ + CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */ + CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */ + CURLM_LAST +} CURLMcode; + +/* just to make code nicer when using curl_multi_socket() you can now check + for CURLM_CALL_MULTI_SOCKET too in the same style it works for + curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ +#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM + +/* bitmask bits for CURLMOPT_PIPELINING */ +#define CURLPIPE_NOTHING 0L +#define CURLPIPE_HTTP1 1L +#define CURLPIPE_MULTIPLEX 2L + +typedef enum { + CURLMSG_NONE, /* first, not used */ + CURLMSG_DONE, /* This easy handle has completed. 'result' contains + the CURLcode of the transfer */ + CURLMSG_LAST /* last, not used */ +} CURLMSG; + +struct CURLMsg { + CURLMSG msg; /* what this message means */ + CURL *easy_handle; /* the handle it concerns */ + union { + void *whatever; /* message-specific data */ + CURLcode result; /* return code for transfer */ + } data; +}; +typedef struct CURLMsg CURLMsg; + +/* Based on poll(2) structure and values. + * We don't use pollfd and POLL* constants explicitly + * to cover platforms without poll(). */ +#define CURL_WAIT_POLLIN 0x0001 +#define CURL_WAIT_POLLPRI 0x0002 +#define CURL_WAIT_POLLOUT 0x0004 + +struct curl_waitfd { + curl_socket_t fd; + short events; + short revents; /* not supported yet */ +}; + +/* + * Name: curl_multi_init() + * + * Desc: inititalize multi-style curl usage + * + * Returns: a new CURLM handle to use in all 'curl_multi' functions. + */ +CURL_EXTERN CURLM *curl_multi_init(void); + +/* + * Name: curl_multi_add_handle() + * + * Desc: add a standard curl handle to the multi stack + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, + fd_set *read_fd_set, + fd_set *write_fd_set, + fd_set *exc_fd_set, + int *max_fd); + +/* + * Name: curl_multi_wait() + * + * Desc: Poll on all fds within a CURLM set as well as any + * additional fds passed to the function. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, + struct curl_waitfd extra_fds[], + unsigned int extra_nfds, + int timeout_ms, + int *ret); + + /* + * Name: curl_multi_poll() + * + * Desc: Poll on all fds within a CURLM set as well as any + * additional fds passed to the function. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle, + struct curl_waitfd extra_fds[], + unsigned int extra_nfds, + int timeout_ms, + int *ret); + +/* + * Name: curl_multi_wakeup() + * + * Desc: wakes up a sleeping curl_multi_poll call. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle); + + /* + * Name: curl_multi_perform() + * + * Desc: When the app thinks there's data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on individual transfers even when + * this returns OK. + */ +CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, + int *running_handles); + + /* + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); + +/* + * Name: curl_multi_info_read() + * + * Desc: Ask the multi handle if there's any messages/informationals from + * the individual transfers. Messages include informationals such as + * error code from the transfer or just the fact that a transfer is + * completed. More details on these should be written down as well. + * + * Repeated calls to this function will return a new struct each + * time, until a special "end of msgs" struct is returned as a signal + * that there is no more to get at this point. + * + * The data the returned pointer points to will not survive calling + * curl_multi_cleanup(). + * + * The 'CURLMsg' struct is meant to be very simple and only contain + * very basic information. If more involved information is wanted, + * we will provide the particular "transfer handle" in that struct + * and that should/could/would be used in subsequent + * curl_easy_getinfo() calls (or similar). The point being that we + * must never expose complex structs to applications, as then we'll + * undoubtably get backwards compatibility problems in the future. + * + * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out + * of structs. It also writes the number of messages left in the + * queue (after this read) in the integer the second argument points + * to. + */ +CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, + int *msgs_in_queue); + +/* + * Name: curl_multi_strerror() + * + * Desc: The curl_multi_strerror function may be used to turn a CURLMcode + * value into the equivalent human readable error string. This is + * useful for printing meaningful error messages. + * + * Returns: A pointer to a null-terminated error message. + */ +CURL_EXTERN const char *curl_multi_strerror(CURLMcode); + +/* + * Name: curl_multi_socket() and + * curl_multi_socket_all() + * + * Desc: An alternative version of curl_multi_perform() that allows the + * application to pass in one of the file descriptors that have been + * detected to have "action" on them and let libcurl perform. + * See man page for details. + */ +#define CURL_POLL_NONE 0 +#define CURL_POLL_IN 1 +#define CURL_POLL_OUT 2 +#define CURL_POLL_INOUT 3 +#define CURL_POLL_REMOVE 4 + +#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD + +#define CURL_CSELECT_IN 0x01 +#define CURL_CSELECT_OUT 0x02 +#define CURL_CSELECT_ERR 0x04 + +typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ + curl_socket_t s, /* socket */ + int what, /* see above */ + void *userp, /* private callback + pointer */ + void *socketp); /* private socket + pointer */ +/* + * Name: curl_multi_timer_callback + * + * Desc: Called by libcurl whenever the library detects a change in the + * maximum number of milliseconds the app is allowed to wait before + * curl_multi_socket() or curl_multi_perform() must be called + * (to allow libcurl's timed events to take place). + * + * Returns: The callback should return zero. + */ +typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ + long timeout_ms, /* see above */ + void *userp); /* private callback + pointer */ + +CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, + curl_socket_t s, + int ev_bitmask, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, + int *running_handles); + +#ifndef CURL_ALLOW_OLD_MULTI_SOCKET +/* This macro below was added in 7.16.3 to push users who recompile to use + the new curl_multi_socket_action() instead of the old curl_multi_socket() +*/ +#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) +#endif + +/* + * Name: curl_multi_timeout() + * + * Desc: Returns the maximum number of milliseconds the app is allowed to + * wait before curl_multi_socket() or curl_multi_perform() must be + * called (to allow libcurl's timed events to take place). + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, + long *milliseconds); + +typedef enum { + /* This is the socket callback function pointer */ + CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1), + + /* This is the argument passed to the socket callback */ + CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2), + + /* set to 1 to enable pipelining for this multi handle */ + CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3), + + /* This is the timer callback function pointer */ + CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4), + + /* This is the argument passed to the timer callback */ + CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5), + + /* maximum number of entries in the connection cache */ + CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6), + + /* maximum number of (pipelining) connections to one host */ + CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7), + + /* maximum number of requests in a pipeline */ + CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8), + + /* a connection with a content-length longer than this + will not be considered for pipelining */ + CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9), + + /* a connection with a chunk length longer than this + will not be considered for pipelining */ + CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10), + + /* a list of site names(+port) that are blocked from pipelining */ + CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11), + + /* a list of server types that are blocked from pipelining */ + CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12), + + /* maximum number of open connections in total */ + CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13), + + /* This is the server push callback function pointer */ + CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14), + + /* This is the argument passed to the server push callback */ + CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15), + + /* maximum number of concurrent streams to support on a connection */ + CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16), + + CURLMOPT_LASTENTRY /* the last unused */ +} CURLMoption; + + +/* + * Name: curl_multi_setopt() + * + * Desc: Sets options for the multi handle. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, + CURLMoption option, ...); + + +/* + * Name: curl_multi_assign() + * + * Desc: This function sets an association in the multi handle between the + * given socket and a private pointer of the application. This is + * (only) useful for curl_multi_socket uses. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, + curl_socket_t sockfd, void *sockp); + + +/* + * Name: curl_push_callback + * + * Desc: This callback gets called when a new stream is being pushed by the + * server. It approves or denies the new stream. It can also decide + * to completely fail the connection. + * + * Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT + */ +#define CURL_PUSH_OK 0 +#define CURL_PUSH_DENY 1 +#define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */ + +struct curl_pushheaders; /* forward declaration only */ + +CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, + size_t num); +CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, + const char *name); + +typedef int (*curl_push_callback)(CURL *parent, + CURL *easy, + size_t num_headers, + struct curl_pushheaders *headers, + void *userp); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/src/curl/options.h b/src/curl/options.h new file mode 100644 index 0000000..14373b5 --- /dev/null +++ b/src/curl/options.h @@ -0,0 +1,68 @@ +#ifndef CURLINC_OPTIONS_H +#define CURLINC_OPTIONS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2018 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + CURLOT_LONG, /* long (a range of values) */ + CURLOT_VALUES, /* (a defined set or bitmask) */ + CURLOT_OFF_T, /* curl_off_t (a range of values) */ + CURLOT_OBJECT, /* pointer (void *) */ + CURLOT_STRING, /* (char * to zero terminated buffer) */ + CURLOT_SLIST, /* (struct curl_slist *) */ + CURLOT_CBPTR, /* (void * passed as-is to a callback) */ + CURLOT_BLOB, /* blob (struct curl_blob *) */ + CURLOT_FUNCTION /* function pointer */ +} curl_easytype; + +/* Flag bits */ + +/* "alias" means it is provided for old programs to remain functional, + we prefer another name */ +#define CURLOT_FLAG_ALIAS (1<<0) + +/* The CURLOPTTYPE_* id ranges can still be used to figure out what type/size + to use for curl_easy_setopt() for the given id */ +struct curl_easyoption { + const char *name; + CURLoption id; + curl_easytype type; + unsigned int flags; +}; + +CURL_EXTERN const struct curl_easyoption * +curl_easy_option_by_name(const char *name); + +CURL_EXTERN const struct curl_easyoption * +curl_easy_option_by_id (CURLoption id); + +CURL_EXTERN const struct curl_easyoption * +curl_easy_option_next(const struct curl_easyoption *prev); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif +#endif /* CURLINC_OPTIONS_H */ diff --git a/src/curl/stdcheaders.h b/src/curl/stdcheaders.h new file mode 100644 index 0000000..60596c7 --- /dev/null +++ b/src/curl/stdcheaders.h @@ -0,0 +1,33 @@ +#ifndef CURLINC_STDCHEADERS_H +#define CURLINC_STDCHEADERS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include <sys/types.h> + +size_t fread(void *, size_t, size_t, FILE *); +size_t fwrite(const void *, size_t, size_t, FILE *); + +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); + +#endif /* CURLINC_STDCHEADERS_H */ diff --git a/src/curl/system.h b/src/curl/system.h new file mode 100644 index 0000000..faf8fcf --- /dev/null +++ b/src/curl/system.h @@ -0,0 +1,504 @@ +#ifndef CURLINC_SYSTEM_H +#define CURLINC_SYSTEM_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * Try to keep one section per platform, compiler and architecture, otherwise, + * if an existing section is reused for a different one and later on the + * original is adjusted, probably the piggybacking one can be adversely + * changed. + * + * In order to differentiate between platforms/compilers/architectures use + * only compiler built in predefined preprocessor symbols. + * + * curl_off_t + * ---------- + * + * For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit + * wide signed integral data type. The width of this data type must remain + * constant and independent of any possible large file support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit + * wide signed integral data type if there is no 64-bit type. + * + * As a general rule, curl_off_t shall not be mapped to off_t. This rule shall + * only be violated if off_t is the only 64-bit data type available and the + * size of off_t is independent of large file support settings. Keep your + * build on the safe side avoiding an off_t gating. If you have a 64-bit + * off_t then take for sure that another 64-bit data type exists, dig deeper + * and you will find it. + * + */ + +#if defined(__DJGPP__) || defined(__GO32__) +# if defined(__DJGPP__) && (__DJGPP__ > 1) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__SALFORDC__) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__BORLANDC__) +# if (__BORLANDC__ < 0x520) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__TURBOC__) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__WATCOMC__) +# if defined(__386__) +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__POCC__) +# if (__POCC__ < 280) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# elif defined(_MSC_VER) +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__LCC__) +# if defined(__e2k__) /* MCST eLbrus C Compiler */ +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# else /* Local (or Little) C Compiler */ +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# endif + +#elif defined(__SYMBIAN32__) +# if defined(__EABI__) /* Treat all ARM compilers equally */ +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__CW32__) +# pragma longlong on +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__VC32__) +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int + +#elif defined(__MWERKS__) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(_WIN32_WCE) +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__MINGW32__) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_WS2TCPIP_H 1 + +#elif defined(__VMS) +# if defined(__VAX) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int + +#elif defined(__OS400__) +# if defined(__ILEC400__) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__MVS__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# elif defined(_LP64) +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__370__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# elif defined(_LP64) +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(TPF) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +#elif defined(__TINYC__) /* also known as tcc */ +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Oracle Solaris Studio */ +# if !defined(__LP64) && (defined(__ILP32) || \ + defined(__i386) || \ + defined(__sparcv8) || \ + defined(__sparcv8plus)) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64) || \ + defined(__amd64) || defined(__sparcv9) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#elif defined(__xlc__) /* IBM xlc compiler */ +# if !defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +/* ===================================== */ +/* KEEP MSVC THE PENULTIMATE ENTRY */ +/* ===================================== */ + +#elif defined(_MSC_VER) +# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int + +/* ===================================== */ +/* KEEP GENERIC GCC THE LAST ENTRY */ +/* ===================================== */ + +#elif defined(__GNUC__) && !defined(_SCO_DS) +# if !defined(__LP64__) && \ + (defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \ + defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \ + defined(__sparc__) || defined(__mips__) || defined(__sh__) || \ + defined(__XTENSA__) || \ + (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4) || \ + (defined(__LONG_MAX__) && __LONG_MAX__ == 2147483647L)) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64__) || \ + defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \ + defined(__e2k__) || \ + (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) || \ + (defined(__LONG_MAX__) && __LONG_MAX__ == 9223372036854775807L) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#else +/* generic "safe guess" on old 32 bit style */ +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +#endif + +#ifdef _AIX +/* AIX needs <sys/poll.h> */ +#define CURL_PULL_SYS_POLL_H +#endif + + +/* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */ +/* ws2tcpip.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_WS2TCPIP_H +# include <winsock2.h> +# include <windows.h> +# include <ws2tcpip.h> +#endif + +/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ +/* sys/types.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_TYPES_H +# include <sys/types.h> +#endif + +/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ +/* sys/socket.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_SOCKET_H +# include <sys/socket.h> +#endif + +/* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */ +/* sys/poll.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_POLL_H +# include <sys/poll.h> +#endif + +/* Data type definition of curl_socklen_t. */ +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T + typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; +#endif + +/* Data type definition of curl_off_t. */ + +#ifdef CURL_TYPEOF_CURL_OFF_T + typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; +#endif + +/* + * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow + * these to be visible and exported by the external libcurl interface API, + * while also making them visible to the library internals, simply including + * curl_setup.h, without actually needing to include curl.h internally. + * If some day this section would grow big enough, all this should be moved + * to its own header file. + */ + +/* + * Figure out if we can use the ## preprocessor operator, which is supported + * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ + * or __cplusplus so we need to carefully check for them too. + */ + +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ + defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ + defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ + defined(__ILEC400__) + /* This compiler is believed to have an ISO compatible preprocessor */ +#define CURL_ISOCPP +#else + /* This compiler is believed NOT to have an ISO compatible preprocessor */ +#undef CURL_ISOCPP +#endif + +/* + * Macros for minimum-width signed and unsigned curl_off_t integer constants. + */ + +#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) +# define CURLINC_OFF_T_C_HLPR2(x) x +# define CURLINC_OFF_T_C_HLPR1(x) CURLINC_OFF_T_C_HLPR2(x) +# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \ + CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \ + CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) +#else +# ifdef CURL_ISOCPP +# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix +# else +# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix +# endif +# define CURLINC_OFF_T_C_HLPR1(Val,Suffix) CURLINC_OFF_T_C_HLPR2(Val,Suffix) +# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) +#endif + +#endif /* CURLINC_SYSTEM_H */ diff --git a/src/curl/typecheck-gcc.h b/src/curl/typecheck-gcc.h new file mode 100644 index 0000000..34d0267 --- /dev/null +++ b/src/curl/typecheck-gcc.h @@ -0,0 +1,705 @@ +#ifndef CURLINC_TYPECHECK_GCC_H +#define CURLINC_TYPECHECK_GCC_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* wraps curl_easy_setopt() with typechecking */ + +/* To add a new kind of warning, add an + * if(curlcheck_sometype_option(_curl_opt)) + * if(!curlcheck_sometype(value)) + * _curl_easy_setopt_err_sometype(); + * block and define curlcheck_sometype_option, curlcheck_sometype and + * _curl_easy_setopt_err_sometype below + * + * NOTE: We use two nested 'if' statements here instead of the && operator, in + * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x + * when compiling with -Wlogical-op. + * + * To add an option that uses the same type as an existing option, you'll just + * need to extend the appropriate _curl_*_option macro + */ +#define curl_easy_setopt(handle, option, value) \ + __extension__({ \ + __typeof__(option) _curl_opt = option; \ + if(__builtin_constant_p(_curl_opt)) { \ + if(curlcheck_long_option(_curl_opt)) \ + if(!curlcheck_long(value)) \ + _curl_easy_setopt_err_long(); \ + if(curlcheck_off_t_option(_curl_opt)) \ + if(!curlcheck_off_t(value)) \ + _curl_easy_setopt_err_curl_off_t(); \ + if(curlcheck_string_option(_curl_opt)) \ + if(!curlcheck_string(value)) \ + _curl_easy_setopt_err_string(); \ + if(curlcheck_write_cb_option(_curl_opt)) \ + if(!curlcheck_write_cb(value)) \ + _curl_easy_setopt_err_write_callback(); \ + if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION) \ + if(!curlcheck_resolver_start_callback(value)) \ + _curl_easy_setopt_err_resolver_start_callback(); \ + if((_curl_opt) == CURLOPT_READFUNCTION) \ + if(!curlcheck_read_cb(value)) \ + _curl_easy_setopt_err_read_cb(); \ + if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ + if(!curlcheck_ioctl_cb(value)) \ + _curl_easy_setopt_err_ioctl_cb(); \ + if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ + if(!curlcheck_sockopt_cb(value)) \ + _curl_easy_setopt_err_sockopt_cb(); \ + if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ + if(!curlcheck_opensocket_cb(value)) \ + _curl_easy_setopt_err_opensocket_cb(); \ + if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ + if(!curlcheck_progress_cb(value)) \ + _curl_easy_setopt_err_progress_cb(); \ + if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ + if(!curlcheck_debug_cb(value)) \ + _curl_easy_setopt_err_debug_cb(); \ + if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ + if(!curlcheck_ssl_ctx_cb(value)) \ + _curl_easy_setopt_err_ssl_ctx_cb(); \ + if(curlcheck_conv_cb_option(_curl_opt)) \ + if(!curlcheck_conv_cb(value)) \ + _curl_easy_setopt_err_conv_cb(); \ + if((_curl_opt) == CURLOPT_SEEKFUNCTION) \ + if(!curlcheck_seek_cb(value)) \ + _curl_easy_setopt_err_seek_cb(); \ + if(curlcheck_cb_data_option(_curl_opt)) \ + if(!curlcheck_cb_data(value)) \ + _curl_easy_setopt_err_cb_data(); \ + if((_curl_opt) == CURLOPT_ERRORBUFFER) \ + if(!curlcheck_error_buffer(value)) \ + _curl_easy_setopt_err_error_buffer(); \ + if((_curl_opt) == CURLOPT_STDERR) \ + if(!curlcheck_FILE(value)) \ + _curl_easy_setopt_err_FILE(); \ + if(curlcheck_postfields_option(_curl_opt)) \ + if(!curlcheck_postfields(value)) \ + _curl_easy_setopt_err_postfields(); \ + if((_curl_opt) == CURLOPT_HTTPPOST) \ + if(!curlcheck_arr((value), struct curl_httppost)) \ + _curl_easy_setopt_err_curl_httpost(); \ + if((_curl_opt) == CURLOPT_MIMEPOST) \ + if(!curlcheck_ptr((value), curl_mime)) \ + _curl_easy_setopt_err_curl_mimepost(); \ + if(curlcheck_slist_option(_curl_opt)) \ + if(!curlcheck_arr((value), struct curl_slist)) \ + _curl_easy_setopt_err_curl_slist(); \ + if((_curl_opt) == CURLOPT_SHARE) \ + if(!curlcheck_ptr((value), CURLSH)) \ + _curl_easy_setopt_err_CURLSH(); \ + } \ + curl_easy_setopt(handle, _curl_opt, value); \ + }) + +/* wraps curl_easy_getinfo() with typechecking */ +#define curl_easy_getinfo(handle, info, arg) \ + __extension__({ \ + __typeof__(info) _curl_info = info; \ + if(__builtin_constant_p(_curl_info)) { \ + if(curlcheck_string_info(_curl_info)) \ + if(!curlcheck_arr((arg), char *)) \ + _curl_easy_getinfo_err_string(); \ + if(curlcheck_long_info(_curl_info)) \ + if(!curlcheck_arr((arg), long)) \ + _curl_easy_getinfo_err_long(); \ + if(curlcheck_double_info(_curl_info)) \ + if(!curlcheck_arr((arg), double)) \ + _curl_easy_getinfo_err_double(); \ + if(curlcheck_slist_info(_curl_info)) \ + if(!curlcheck_arr((arg), struct curl_slist *)) \ + _curl_easy_getinfo_err_curl_slist(); \ + if(curlcheck_tlssessioninfo_info(_curl_info)) \ + if(!curlcheck_arr((arg), struct curl_tlssessioninfo *)) \ + _curl_easy_getinfo_err_curl_tlssesssioninfo(); \ + if(curlcheck_certinfo_info(_curl_info)) \ + if(!curlcheck_arr((arg), struct curl_certinfo *)) \ + _curl_easy_getinfo_err_curl_certinfo(); \ + if(curlcheck_socket_info(_curl_info)) \ + if(!curlcheck_arr((arg), curl_socket_t)) \ + _curl_easy_getinfo_err_curl_socket(); \ + if(curlcheck_off_t_info(_curl_info)) \ + if(!curlcheck_arr((arg), curl_off_t)) \ + _curl_easy_getinfo_err_curl_off_t(); \ + } \ + curl_easy_getinfo(handle, _curl_info, arg); \ + }) + +/* + * For now, just make sure that the functions are called with three arguments + */ +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) + + +/* the actual warnings, triggered by calling the _curl_easy_setopt_err* + * functions */ + +/* To define a new warning, use _CURL_WARNING(identifier, "message") */ +#define CURLWARNING(id, message) \ + static void __attribute__((__warning__(message))) \ + __attribute__((__unused__)) __attribute__((__noinline__)) \ + id(void) { __asm__(""); } + +CURLWARNING(_curl_easy_setopt_err_long, + "curl_easy_setopt expects a long argument for this option") +CURLWARNING(_curl_easy_setopt_err_curl_off_t, + "curl_easy_setopt expects a curl_off_t argument for this option") +CURLWARNING(_curl_easy_setopt_err_string, + "curl_easy_setopt expects a " + "string ('char *' or char[]) argument for this option" + ) +CURLWARNING(_curl_easy_setopt_err_write_callback, + "curl_easy_setopt expects a curl_write_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_resolver_start_callback, + "curl_easy_setopt expects a " + "curl_resolver_start_callback argument for this option" + ) +CURLWARNING(_curl_easy_setopt_err_read_cb, + "curl_easy_setopt expects a curl_read_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_ioctl_cb, + "curl_easy_setopt expects a curl_ioctl_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_sockopt_cb, + "curl_easy_setopt expects a curl_sockopt_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_opensocket_cb, + "curl_easy_setopt expects a " + "curl_opensocket_callback argument for this option" + ) +CURLWARNING(_curl_easy_setopt_err_progress_cb, + "curl_easy_setopt expects a curl_progress_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_debug_cb, + "curl_easy_setopt expects a curl_debug_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_ssl_ctx_cb, + "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_conv_cb, + "curl_easy_setopt expects a curl_conv_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_seek_cb, + "curl_easy_setopt expects a curl_seek_callback argument for this option") +CURLWARNING(_curl_easy_setopt_err_cb_data, + "curl_easy_setopt expects a " + "private data pointer as argument for this option") +CURLWARNING(_curl_easy_setopt_err_error_buffer, + "curl_easy_setopt expects a " + "char buffer of CURL_ERROR_SIZE as argument for this option") +CURLWARNING(_curl_easy_setopt_err_FILE, + "curl_easy_setopt expects a 'FILE *' argument for this option") +CURLWARNING(_curl_easy_setopt_err_postfields, + "curl_easy_setopt expects a 'void *' or 'char *' argument for this option") +CURLWARNING(_curl_easy_setopt_err_curl_httpost, + "curl_easy_setopt expects a 'struct curl_httppost *' " + "argument for this option") +CURLWARNING(_curl_easy_setopt_err_curl_mimepost, + "curl_easy_setopt expects a 'curl_mime *' " + "argument for this option") +CURLWARNING(_curl_easy_setopt_err_curl_slist, + "curl_easy_setopt expects a 'struct curl_slist *' argument for this option") +CURLWARNING(_curl_easy_setopt_err_CURLSH, + "curl_easy_setopt expects a CURLSH* argument for this option") + +CURLWARNING(_curl_easy_getinfo_err_string, + "curl_easy_getinfo expects a pointer to 'char *' for this info") +CURLWARNING(_curl_easy_getinfo_err_long, + "curl_easy_getinfo expects a pointer to long for this info") +CURLWARNING(_curl_easy_getinfo_err_double, + "curl_easy_getinfo expects a pointer to double for this info") +CURLWARNING(_curl_easy_getinfo_err_curl_slist, + "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info") +CURLWARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo, + "curl_easy_getinfo expects a pointer to " + "'struct curl_tlssessioninfo *' for this info") +CURLWARNING(_curl_easy_getinfo_err_curl_certinfo, + "curl_easy_getinfo expects a pointer to " + "'struct curl_certinfo *' for this info") +CURLWARNING(_curl_easy_getinfo_err_curl_socket, + "curl_easy_getinfo expects a pointer to curl_socket_t for this info") +CURLWARNING(_curl_easy_getinfo_err_curl_off_t, + "curl_easy_getinfo expects a pointer to curl_off_t for this info") + +/* groups of curl_easy_setops options that take the same type of argument */ + +/* To add a new option to one of the groups, just add + * (option) == CURLOPT_SOMETHING + * to the or-expression. If the option takes a long or curl_off_t, you don't + * have to do anything + */ + +/* evaluates to true if option takes a long argument */ +#define curlcheck_long_option(option) \ + (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) + +#define curlcheck_off_t_option(option) \ + (((option) > CURLOPTTYPE_OFF_T) && ((option) < CURLOPTTYPE_BLOB)) + +/* evaluates to true if option takes a char* argument */ +#define curlcheck_string_option(option) \ + ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \ + (option) == CURLOPT_ACCEPT_ENCODING || \ + (option) == CURLOPT_ALTSVC || \ + (option) == CURLOPT_CAINFO || \ + (option) == CURLOPT_CAPATH || \ + (option) == CURLOPT_COOKIE || \ + (option) == CURLOPT_COOKIEFILE || \ + (option) == CURLOPT_COOKIEJAR || \ + (option) == CURLOPT_COOKIELIST || \ + (option) == CURLOPT_CRLFILE || \ + (option) == CURLOPT_CUSTOMREQUEST || \ + (option) == CURLOPT_DEFAULT_PROTOCOL || \ + (option) == CURLOPT_DNS_INTERFACE || \ + (option) == CURLOPT_DNS_LOCAL_IP4 || \ + (option) == CURLOPT_DNS_LOCAL_IP6 || \ + (option) == CURLOPT_DNS_SERVERS || \ + (option) == CURLOPT_DOH_URL || \ + (option) == CURLOPT_EGDSOCKET || \ + (option) == CURLOPT_FTPPORT || \ + (option) == CURLOPT_FTP_ACCOUNT || \ + (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ + (option) == CURLOPT_HSTS || \ + (option) == CURLOPT_INTERFACE || \ + (option) == CURLOPT_ISSUERCERT || \ + (option) == CURLOPT_KEYPASSWD || \ + (option) == CURLOPT_KRBLEVEL || \ + (option) == CURLOPT_LOGIN_OPTIONS || \ + (option) == CURLOPT_MAIL_AUTH || \ + (option) == CURLOPT_MAIL_FROM || \ + (option) == CURLOPT_NETRC_FILE || \ + (option) == CURLOPT_NOPROXY || \ + (option) == CURLOPT_PASSWORD || \ + (option) == CURLOPT_PINNEDPUBLICKEY || \ + (option) == CURLOPT_PRE_PROXY || \ + (option) == CURLOPT_PROXY || \ + (option) == CURLOPT_PROXYPASSWORD || \ + (option) == CURLOPT_PROXYUSERNAME || \ + (option) == CURLOPT_PROXYUSERPWD || \ + (option) == CURLOPT_PROXY_CAINFO || \ + (option) == CURLOPT_PROXY_CAPATH || \ + (option) == CURLOPT_PROXY_CRLFILE || \ + (option) == CURLOPT_PROXY_ISSUERCERT || \ + (option) == CURLOPT_PROXY_KEYPASSWD || \ + (option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \ + (option) == CURLOPT_PROXY_SERVICE_NAME || \ + (option) == CURLOPT_PROXY_SSLCERT || \ + (option) == CURLOPT_PROXY_SSLCERTTYPE || \ + (option) == CURLOPT_PROXY_SSLKEY || \ + (option) == CURLOPT_PROXY_SSLKEYTYPE || \ + (option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \ + (option) == CURLOPT_PROXY_TLS13_CIPHERS || \ + (option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \ + (option) == CURLOPT_PROXY_TLSAUTH_TYPE || \ + (option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \ + (option) == CURLOPT_RANDOM_FILE || \ + (option) == CURLOPT_RANGE || \ + (option) == CURLOPT_REFERER || \ + (option) == CURLOPT_REQUEST_TARGET || \ + (option) == CURLOPT_RTSP_SESSION_ID || \ + (option) == CURLOPT_RTSP_STREAM_URI || \ + (option) == CURLOPT_RTSP_TRANSPORT || \ + (option) == CURLOPT_SASL_AUTHZID || \ + (option) == CURLOPT_SERVICE_NAME || \ + (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ + (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ + (option) == CURLOPT_SSH_KNOWNHOSTS || \ + (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ + (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ + (option) == CURLOPT_SSLCERT || \ + (option) == CURLOPT_SSLCERTTYPE || \ + (option) == CURLOPT_SSLENGINE || \ + (option) == CURLOPT_SSLKEY || \ + (option) == CURLOPT_SSLKEYTYPE || \ + (option) == CURLOPT_SSL_CIPHER_LIST || \ + (option) == CURLOPT_TLS13_CIPHERS || \ + (option) == CURLOPT_TLSAUTH_PASSWORD || \ + (option) == CURLOPT_TLSAUTH_TYPE || \ + (option) == CURLOPT_TLSAUTH_USERNAME || \ + (option) == CURLOPT_UNIX_SOCKET_PATH || \ + (option) == CURLOPT_URL || \ + (option) == CURLOPT_USERAGENT || \ + (option) == CURLOPT_USERNAME || \ + (option) == CURLOPT_AWS_SIGV4 || \ + (option) == CURLOPT_USERPWD || \ + (option) == CURLOPT_XOAUTH2_BEARER || \ + (option) == CURLOPT_SSL_EC_CURVES || \ + 0) + +/* evaluates to true if option takes a curl_write_callback argument */ +#define curlcheck_write_cb_option(option) \ + ((option) == CURLOPT_HEADERFUNCTION || \ + (option) == CURLOPT_WRITEFUNCTION) + +/* evaluates to true if option takes a curl_conv_callback argument */ +#define curlcheck_conv_cb_option(option) \ + ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) + +/* evaluates to true if option takes a data argument to pass to a callback */ +#define curlcheck_cb_data_option(option) \ + ((option) == CURLOPT_CHUNK_DATA || \ + (option) == CURLOPT_CLOSESOCKETDATA || \ + (option) == CURLOPT_DEBUGDATA || \ + (option) == CURLOPT_FNMATCH_DATA || \ + (option) == CURLOPT_HEADERDATA || \ + (option) == CURLOPT_HSTSREADDATA || \ + (option) == CURLOPT_HSTSWRITEDATA || \ + (option) == CURLOPT_INTERLEAVEDATA || \ + (option) == CURLOPT_IOCTLDATA || \ + (option) == CURLOPT_OPENSOCKETDATA || \ + (option) == CURLOPT_PROGRESSDATA || \ + (option) == CURLOPT_READDATA || \ + (option) == CURLOPT_SEEKDATA || \ + (option) == CURLOPT_SOCKOPTDATA || \ + (option) == CURLOPT_SSH_KEYDATA || \ + (option) == CURLOPT_SSL_CTX_DATA || \ + (option) == CURLOPT_WRITEDATA || \ + (option) == CURLOPT_RESOLVER_START_DATA || \ + (option) == CURLOPT_TRAILERDATA || \ + 0) + +/* evaluates to true if option takes a POST data argument (void* or char*) */ +#define curlcheck_postfields_option(option) \ + ((option) == CURLOPT_POSTFIELDS || \ + (option) == CURLOPT_COPYPOSTFIELDS || \ + 0) + +/* evaluates to true if option takes a struct curl_slist * argument */ +#define curlcheck_slist_option(option) \ + ((option) == CURLOPT_HTTP200ALIASES || \ + (option) == CURLOPT_HTTPHEADER || \ + (option) == CURLOPT_MAIL_RCPT || \ + (option) == CURLOPT_POSTQUOTE || \ + (option) == CURLOPT_PREQUOTE || \ + (option) == CURLOPT_PROXYHEADER || \ + (option) == CURLOPT_QUOTE || \ + (option) == CURLOPT_RESOLVE || \ + (option) == CURLOPT_TELNETOPTIONS || \ + (option) == CURLOPT_CONNECT_TO || \ + 0) + +/* groups of curl_easy_getinfo infos that take the same type of argument */ + +/* evaluates to true if info expects a pointer to char * argument */ +#define curlcheck_string_info(info) \ + (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG && \ + (info) != CURLINFO_PRIVATE) + +/* evaluates to true if info expects a pointer to long argument */ +#define curlcheck_long_info(info) \ + (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) + +/* evaluates to true if info expects a pointer to double argument */ +#define curlcheck_double_info(info) \ + (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) + +/* true if info expects a pointer to struct curl_slist * argument */ +#define curlcheck_slist_info(info) \ + (((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST)) + +/* true if info expects a pointer to struct curl_tlssessioninfo * argument */ +#define curlcheck_tlssessioninfo_info(info) \ + (((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION)) + +/* true if info expects a pointer to struct curl_certinfo * argument */ +#define curlcheck_certinfo_info(info) ((info) == CURLINFO_CERTINFO) + +/* true if info expects a pointer to struct curl_socket_t argument */ +#define curlcheck_socket_info(info) \ + (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T) + +/* true if info expects a pointer to curl_off_t argument */ +#define curlcheck_off_t_info(info) \ + (CURLINFO_OFF_T < (info)) + + +/* typecheck helpers -- check whether given expression has requested type*/ + +/* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros, + * otherwise define a new macro. Search for __builtin_types_compatible_p + * in the GCC manual. + * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is + * the actual expression passed to the curl_easy_setopt macro. This + * means that you can only apply the sizeof and __typeof__ operators, no + * == or whatsoever. + */ + +/* XXX: should evaluate to true if expr is a pointer */ +#define curlcheck_any_ptr(expr) \ + (sizeof(expr) == sizeof(void *)) + +/* evaluates to true if expr is NULL */ +/* XXX: must not evaluate expr, so this check is not accurate */ +#define curlcheck_NULL(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) + +/* evaluates to true if expr is type*, const type* or NULL */ +#define curlcheck_ptr(expr, type) \ + (curlcheck_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), type *) || \ + __builtin_types_compatible_p(__typeof__(expr), const type *)) + +/* evaluates to true if expr is one of type[], type*, NULL or const type* */ +#define curlcheck_arr(expr, type) \ + (curlcheck_ptr((expr), type) || \ + __builtin_types_compatible_p(__typeof__(expr), type [])) + +/* evaluates to true if expr is a string */ +#define curlcheck_string(expr) \ + (curlcheck_arr((expr), char) || \ + curlcheck_arr((expr), signed char) || \ + curlcheck_arr((expr), unsigned char)) + +/* evaluates to true if expr is a long (no matter the signedness) + * XXX: for now, int is also accepted (and therefore short and char, which + * are promoted to int when passed to a variadic function) */ +#define curlcheck_long(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), long) || \ + __builtin_types_compatible_p(__typeof__(expr), signed long) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ + __builtin_types_compatible_p(__typeof__(expr), int) || \ + __builtin_types_compatible_p(__typeof__(expr), signed int) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ + __builtin_types_compatible_p(__typeof__(expr), short) || \ + __builtin_types_compatible_p(__typeof__(expr), signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), char) || \ + __builtin_types_compatible_p(__typeof__(expr), signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned char)) + +/* evaluates to true if expr is of type curl_off_t */ +#define curlcheck_off_t(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) + +/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ +/* XXX: also check size of an char[] array? */ +#define curlcheck_error_buffer(expr) \ + (curlcheck_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), char *) || \ + __builtin_types_compatible_p(__typeof__(expr), char[])) + +/* evaluates to true if expr is of type (const) void* or (const) FILE* */ +#if 0 +#define curlcheck_cb_data(expr) \ + (curlcheck_ptr((expr), void) || \ + curlcheck_ptr((expr), FILE)) +#else /* be less strict */ +#define curlcheck_cb_data(expr) \ + curlcheck_any_ptr(expr) +#endif + +/* evaluates to true if expr is of type FILE* */ +#define curlcheck_FILE(expr) \ + (curlcheck_NULL(expr) || \ + (__builtin_types_compatible_p(__typeof__(expr), FILE *))) + +/* evaluates to true if expr can be passed as POST data (void* or char*) */ +#define curlcheck_postfields(expr) \ + (curlcheck_ptr((expr), void) || \ + curlcheck_arr((expr), char) || \ + curlcheck_arr((expr), unsigned char)) + +/* helper: __builtin_types_compatible_p distinguishes between functions and + * function pointers, hide it */ +#define curlcheck_cb_compatible(func, type) \ + (__builtin_types_compatible_p(__typeof__(func), type) || \ + __builtin_types_compatible_p(__typeof__(func) *, type)) + +/* evaluates to true if expr is of type curl_resolver_start_callback */ +#define curlcheck_resolver_start_callback(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_resolver_start_callback)) + +/* evaluates to true if expr is of type curl_read_callback or "similar" */ +#define curlcheck_read_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), __typeof__(fread) *) || \ + curlcheck_cb_compatible((expr), curl_read_callback) || \ + curlcheck_cb_compatible((expr), _curl_read_callback1) || \ + curlcheck_cb_compatible((expr), _curl_read_callback2) || \ + curlcheck_cb_compatible((expr), _curl_read_callback3) || \ + curlcheck_cb_compatible((expr), _curl_read_callback4) || \ + curlcheck_cb_compatible((expr), _curl_read_callback5) || \ + curlcheck_cb_compatible((expr), _curl_read_callback6)) +typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *); +typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *); +typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *); +typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *); +typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *); +typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *); + +/* evaluates to true if expr is of type curl_write_callback or "similar" */ +#define curlcheck_write_cb(expr) \ + (curlcheck_read_cb(expr) || \ + curlcheck_cb_compatible((expr), __typeof__(fwrite) *) || \ + curlcheck_cb_compatible((expr), curl_write_callback) || \ + curlcheck_cb_compatible((expr), _curl_write_callback1) || \ + curlcheck_cb_compatible((expr), _curl_write_callback2) || \ + curlcheck_cb_compatible((expr), _curl_write_callback3) || \ + curlcheck_cb_compatible((expr), _curl_write_callback4) || \ + curlcheck_cb_compatible((expr), _curl_write_callback5) || \ + curlcheck_cb_compatible((expr), _curl_write_callback6)) +typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *); +typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t, + const void *); +typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *); +typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *); +typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t, + const void *); +typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *); + +/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ +#define curlcheck_ioctl_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_ioctl_callback) || \ + curlcheck_cb_compatible((expr), _curl_ioctl_callback1) || \ + curlcheck_cb_compatible((expr), _curl_ioctl_callback2) || \ + curlcheck_cb_compatible((expr), _curl_ioctl_callback3) || \ + curlcheck_cb_compatible((expr), _curl_ioctl_callback4)) +typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *); +typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *); +typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *); +typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *); + +/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ +#define curlcheck_sockopt_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_sockopt_callback) || \ + curlcheck_cb_compatible((expr), _curl_sockopt_callback1) || \ + curlcheck_cb_compatible((expr), _curl_sockopt_callback2)) +typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); +typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t, + curlsocktype); + +/* evaluates to true if expr is of type curl_opensocket_callback or + "similar" */ +#define curlcheck_opensocket_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_opensocket_callback) || \ + curlcheck_cb_compatible((expr), _curl_opensocket_callback1) || \ + curlcheck_cb_compatible((expr), _curl_opensocket_callback2) || \ + curlcheck_cb_compatible((expr), _curl_opensocket_callback3) || \ + curlcheck_cb_compatible((expr), _curl_opensocket_callback4)) +typedef curl_socket_t (*_curl_opensocket_callback1) + (void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (*_curl_opensocket_callback2) + (void *, curlsocktype, const struct curl_sockaddr *); +typedef curl_socket_t (*_curl_opensocket_callback3) + (const void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (*_curl_opensocket_callback4) + (const void *, curlsocktype, const struct curl_sockaddr *); + +/* evaluates to true if expr is of type curl_progress_callback or "similar" */ +#define curlcheck_progress_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_progress_callback) || \ + curlcheck_cb_compatible((expr), _curl_progress_callback1) || \ + curlcheck_cb_compatible((expr), _curl_progress_callback2)) +typedef int (*_curl_progress_callback1)(void *, + double, double, double, double); +typedef int (*_curl_progress_callback2)(const void *, + double, double, double, double); + +/* evaluates to true if expr is of type curl_debug_callback or "similar" */ +#define curlcheck_debug_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_debug_callback) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback1) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback2) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback3) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback4) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback5) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback6) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback7) || \ + curlcheck_cb_compatible((expr), _curl_debug_callback8)) +typedef int (*_curl_debug_callback1) (CURL *, + curl_infotype, char *, size_t, void *); +typedef int (*_curl_debug_callback2) (CURL *, + curl_infotype, char *, size_t, const void *); +typedef int (*_curl_debug_callback3) (CURL *, + curl_infotype, const char *, size_t, void *); +typedef int (*_curl_debug_callback4) (CURL *, + curl_infotype, const char *, size_t, const void *); +typedef int (*_curl_debug_callback5) (CURL *, + curl_infotype, unsigned char *, size_t, void *); +typedef int (*_curl_debug_callback6) (CURL *, + curl_infotype, unsigned char *, size_t, const void *); +typedef int (*_curl_debug_callback7) (CURL *, + curl_infotype, const unsigned char *, size_t, void *); +typedef int (*_curl_debug_callback8) (CURL *, + curl_infotype, const unsigned char *, size_t, const void *); + +/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ +/* this is getting even messier... */ +#define curlcheck_ssl_ctx_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_ssl_ctx_callback) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback1) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback2) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback3) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback4) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback5) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback6) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback7) || \ + curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback8)) +typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *); +typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *); +typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *); +typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *, + const void *); +#ifdef HEADER_SSL_H +/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX + * this will of course break if we're included before OpenSSL headers... + */ +typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX *, void *); +typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX *, const void *); +typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX *, void *); +typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX *, + const void *); +#else +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; +#endif + +/* evaluates to true if expr is of type curl_conv_callback or "similar" */ +#define curlcheck_conv_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_conv_callback) || \ + curlcheck_cb_compatible((expr), _curl_conv_callback1) || \ + curlcheck_cb_compatible((expr), _curl_conv_callback2) || \ + curlcheck_cb_compatible((expr), _curl_conv_callback3) || \ + curlcheck_cb_compatible((expr), _curl_conv_callback4)) +typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); +typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); +typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); +typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); + +/* evaluates to true if expr is of type curl_seek_callback or "similar" */ +#define curlcheck_seek_cb(expr) \ + (curlcheck_NULL(expr) || \ + curlcheck_cb_compatible((expr), curl_seek_callback) || \ + curlcheck_cb_compatible((expr), _curl_seek_callback1) || \ + curlcheck_cb_compatible((expr), _curl_seek_callback2)) +typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); +typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); + + +#endif /* CURLINC_TYPECHECK_GCC_H */ diff --git a/src/curl/urlapi.h b/src/curl/urlapi.h new file mode 100644 index 0000000..1d70880 --- /dev/null +++ b/src/curl/urlapi.h @@ -0,0 +1,126 @@ +#ifndef CURLINC_URLAPI_H +#define CURLINC_URLAPI_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2018 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* the error codes for the URL API */ +typedef enum { + CURLUE_OK, + CURLUE_BAD_HANDLE, /* 1 */ + CURLUE_BAD_PARTPOINTER, /* 2 */ + CURLUE_MALFORMED_INPUT, /* 3 */ + CURLUE_BAD_PORT_NUMBER, /* 4 */ + CURLUE_UNSUPPORTED_SCHEME, /* 5 */ + CURLUE_URLDECODE, /* 6 */ + CURLUE_OUT_OF_MEMORY, /* 7 */ + CURLUE_USER_NOT_ALLOWED, /* 8 */ + CURLUE_UNKNOWN_PART, /* 9 */ + CURLUE_NO_SCHEME, /* 10 */ + CURLUE_NO_USER, /* 11 */ + CURLUE_NO_PASSWORD, /* 12 */ + CURLUE_NO_OPTIONS, /* 13 */ + CURLUE_NO_HOST, /* 14 */ + CURLUE_NO_PORT, /* 15 */ + CURLUE_NO_QUERY, /* 16 */ + CURLUE_NO_FRAGMENT /* 17 */ +} CURLUcode; + +typedef enum { + CURLUPART_URL, + CURLUPART_SCHEME, + CURLUPART_USER, + CURLUPART_PASSWORD, + CURLUPART_OPTIONS, + CURLUPART_HOST, + CURLUPART_PORT, + CURLUPART_PATH, + CURLUPART_QUERY, + CURLUPART_FRAGMENT, + CURLUPART_ZONEID /* added in 7.65.0 */ +} CURLUPart; + +#define CURLU_DEFAULT_PORT (1<<0) /* return default port number */ +#define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set, + if the port number matches the + default for the scheme */ +#define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if + missing */ +#define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */ +#define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */ +#define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */ +#define CURLU_URLDECODE (1<<6) /* URL decode on get */ +#define CURLU_URLENCODE (1<<7) /* URL encode on set */ +#define CURLU_APPENDQUERY (1<<8) /* append a form style part */ +#define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */ +#define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the + scheme is unknown. */ +#define CURLU_ALLOW_SPACE (1<<11) /* Allow spaces in the URL */ + +typedef struct Curl_URL CURLU; + +/* + * curl_url() creates a new CURLU handle and returns a pointer to it. + * Must be freed with curl_url_cleanup(). + */ +CURL_EXTERN CURLU *curl_url(void); + +/* + * curl_url_cleanup() frees the CURLU handle and related resources used for + * the URL parsing. It will not free strings previously returned with the URL + * API. + */ +CURL_EXTERN void curl_url_cleanup(CURLU *handle); + +/* + * curl_url_dup() duplicates a CURLU handle and returns a new copy. The new + * handle must also be freed with curl_url_cleanup(). + */ +CURL_EXTERN CURLU *curl_url_dup(CURLU *in); + +/* + * curl_url_get() extracts a specific part of the URL from a CURLU + * handle. Returns error code. The returned pointer MUST be freed with + * curl_free() afterwards. + */ +CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what, + char **part, unsigned int flags); + +/* + * curl_url_set() sets a specific part of the URL in a CURLU handle. Returns + * error code. The passed in string will be copied. Passing a NULL instead of + * a part string, clears that part. + */ +CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what, + const char *part, unsigned int flags); + + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif /* CURLINC_URLAPI_H */ diff --git a/src/cv_point_transform.cpp b/src/cv_point_transform.cpp new file mode 100644 index 0000000..94f14fb --- /dev/null +++ b/src/cv_point_transform.cpp @@ -0,0 +1,333 @@ + + +#include <vector> +#include "cv_point_transform.hpp" +#include "nweb.h" +#include "setting.h" + +#ifdef GY_OS_AMBA + +using namespace std; +extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; +extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; + +list *create_list() +{ + list *l = (list *)malloc(sizeof(list)); + l->size = 0; + l->front = 0; + l->back = 0; + return l; +} + +void list_add(list *l, void *val) +{ + node *new_node = (node*)malloc(sizeof(node)); + new_node->val = val; + new_node->next = 0; + + if (!l->back) { + l->front = new_node; + new_node->prev = 0; + } + else { + l->back->next = new_node; + new_node->prev = l->back; + } + l->back = new_node; + ++l->size; +} + +//void distance_insert(list *l, int box_idx_1, int box_idx_2, float distance) +//{ + //distance_node *dis_pair = (distance_node*)malloc(sizeof(distance_node)); + + //dis_pair->box_idx_1 = box_idx_1; + //dis_pair->box_idx_2 = box_idx_2; + //dis_pair->box_distance = distance; + + //list_add(l, dis_pair); +//} + + +#if 0 +void SetPerspectiveTransform(detection_pos* PosInfo, int total_element_size, CvMat *M, int social_zone_idx, float set_distance, float ratio_w, float ratio_h) +{ + detection_pos *pNext = NULL, *pNext_b = NULL; + CvMat* input = cvCreateMat(1, 4, CV_32FC2); + CvMat* output = cvCreateMat(1, 4, CV_32FC2); + float data[8] = { 0 }; + float pos_trans[MAX_DETECT_OBJECTS][2]; + + if (!M) + return; + + //printf("== SetPerspectiveTransform tal_ele_size: %d, zone_idx: %d, set_dis: %f, w: %f, h: %f \n", total_element_size, social_zone_idx, set_distance, ratio_w, ratio_h); + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + data[0] = pNext->center_x * ratio_w; + data[1] = (pNext->center_y + pNext->height/2) * ratio_h; + + for (int j = 0; j < 8; j++) + { + input->data.fl[j] = data[j]; + } + + cvPerspectiveTransform(input, output, M); + + pos_trans[i][0] = output->data.fl[0]; + pos_trans[i][1] = output->data.fl[1]; + + //printf("[%d] in: %f, %f out: %f, %f \n", i, (3840 / 960) * pNext->center_x, (2160 / 540) * pNext->center_y, pos_trans[i][0], pos_trans[i][1]); + } + + float distance = 0.0; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (!pNext->zone_violation_idx[social_zone_idx]) + continue; + //could filter object kind + //if (strcmp(pNext->name, "car") != 0) + // continue; + + //Next->social_distence_repet_list = create_list(); + //pNext->social_distance_new_list = create_list(); + int k = 0; int l = 0; + for (int j = 0; j < total_element_size; j++) + { + pNext_b = PosInfo + j; + + if (!pNext_b->zone_violation_idx[social_zone_idx]) + continue; + //could filter object kind + //if (strcmp(pNext_b->name, "car") != 0) + // continue; + + if (j < i) + { + //distance_insert(pNext->social_distence_repet_list, i, j, distance); + //printf("rep[%d, %d] = %f \n", i, j, distance); + pNext->social_distance_dup_list[k].social_obj_tracking_id = pNext_b->obj_tracking_id; + for (int m = 0; m < MAX_DETECT_OBJECTS; m++) + { + if (pNext->obj_tracking_id == pNext_b->social_distance_new_list[m].social_obj_tracking_id) + { + pNext->social_distance_dup_list[k].social_distance = pNext_b->social_distance_new_list[m].social_distance; + if (pNext->social_distance_dup_list[k].social_distance < set_distance) + { + pNext->distance_violation = 1; + } + break; + } + } + k++; + } + else if (j > i) + { + //distance_insert(pNext->social_distance_new_list, i, j, distance); + //printf("new[%d, %d] = %f \n", i, j, distance); + distance = sqrt(pow((pos_trans[i][0] - pos_trans[j][0]), 2) + pow((pos_trans[i][1] - pos_trans[j][1]), 2)); + pNext->social_distance_new_list[l].social_obj_tracking_id = pNext_b->obj_tracking_id; + pNext->social_distance_new_list[l].social_distance = distance; + //printf("dis = %f \n", distance); + if (pNext->social_distance_new_list[l].social_distance < set_distance) + { + pNext->distance_violation = 1; + } + l++; + } + } + } + + cvReleaseMat(&input); + cvReleaseMat(&output); +} +#endif + +float SetPerspectiveTransform_GetObjSpeed(detection_pos* PosInfo_old, detection_pos* PosInfo_new, CvMat *M, int det_zone_idx, float ratio_w, float ratio_h) +{ + CvMat* input = cvCreateMat(1, 4, CV_32FC2); + CvMat* output = cvCreateMat(1, 4, CV_32FC2); + float data[8] = { 0 }; + float pos_trans_old[2]; + float pos_trans_new[2]; + float obj_speed = 0.0; + float distance = 0.0; + //double delta_time = 0.0; + float delta_milli_sec = 0; + + +#if 0 + time_t t_old, t_new; + t_old = PosInfo_old->det_time; + t_new = PosInfo_new->det_time; + //struct tm tm = *gmtime(&now); + //struct tm tm_old = *localtime(&now); + struct tm tm_old = *localtime(&t_old); + struct tm tm_new = *localtime(&t_new); + + //struct timeval timeVal_old, timeVal_new; + //gettimeofday(&timeVal_old, NULL); + //int milli = curTime.tv_usec / 1000; +#endif + if (!M) + { + //printf("no MMMMMM \n"); + } + else { + //printf("obj x, y, w, h = %f, %f, %f, %f \n", PosInfo_old->left_x, PosInfo_old->top_y, PosInfo_old->width, PosInfo_old->height); + + //Get Old PosInfo transform pos + //data[0] = PosInfo_old->center_x * ratio_w; //x + //data[1] = (PosInfo_old->center_y + PosInfo_old->height / 2) * ratio_h; //y + +#if 1 + + data[0] = PosInfo_old->center_x; //x + data[1] = PosInfo_old->center_y; //y + + //printf("box center old: [%01f, %01f] ---- \n", data[0], data[1]); + + for (int j = 0; j < 8; j++) + { + input->data.fl[j] = data[j]; + } + + cvPerspectiveTransform(input, output, M); + + pos_trans_old[0] = output->data.fl[0]; + pos_trans_old[1] = output->data.fl[1]; + + //printf("---- t_old: [%01f, %01f] \n", pos_trans_old[0], pos_trans_old[1]); +#endif + + ///------------------------------------- +#if 1 + //Get New PosInfo transform pos + //data[0] = PosInfo_new->center_x * ratio_w; + //data[1] = (PosInfo_new->center_y + PosInfo_new->height / 2) * ratio_h; + data[0] = PosInfo_new->center_x; + data[1] = PosInfo_new->center_y; + + for (int j = 0; j < 8; j++) + { + input->data.fl[j] = data[j]; + } + + cvPerspectiveTransform(input, output, M); + + pos_trans_new[0] = output->data.fl[0]; + pos_trans_new[1] = output->data.fl[1]; + + //printf("box center old: [%01f, %01f] ---- \n", data[0], data[1]); + //printf("------------------------new: [%01f, %01f] ---- \n", pos_trans_new[0], pos_trans_new[1]); + //printf("---------- t_new: [%01f, %01f] \n", pos_trans_new[0], pos_trans_new[1]); +#endif + ///------------------------------------- + + distance = sqrt(pow((pos_trans_old[0] - pos_trans_new[0]), 2) + pow((pos_trans_old[1] - pos_trans_new[1]), 2)); + //printf("dis = %f \n", distance); + + //delta_time = 3600 * difftime(PosInfo_old->det_time, PosInfo_new->det_time); + delta_milli_sec = (float)(PosInfo_new->det_milli_sec - PosInfo_old->det_milli_sec); + + //printf("move spend time: %d ms\n", delta_milli_sec); +#if 1 + //printf("dis = %f \n", distance); + if (delta_milli_sec > 0.0) + { + if (strcmp(viewDetectionZone[0][det_zone_idx].world_time_unit, "KPH") == 0) + { + //3600000 / 1000 = 3600 m -> km + obj_speed = (3600.0 * distance / delta_milli_sec); + //printf("obj_speed = %f hour/per \n", obj_speed); + } + else + { + //3600000 / 1000 = 3600000 m -> 3600 km -> 2236 mi + obj_speed = (2236.0 * distance / delta_milli_sec); + //printf("obj_speed = %f hour/per \n", obj_speed); + } + } +#endif + } + cvReleaseMat(&input); + cvReleaseMat(&output); + + return obj_speed; +} + + +CvMat* GetPerspectiveTransformArray(int tracking_channel_idx, int social_zone_idx) +//CvMat* GetObjectSocialDistance(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, int social_zone_idx, float ratio_w, float ratio_h) +{ + //float d_x1, d_y1, d_x2, d_y2, d_x3, d_y3, d_x4, d_y4; + CvPoint2D32f src_points[DETECTION_POINTS_COUNT]; + CvPoint2D32f dst_points[DETECTION_POINTS_COUNT]; + + for (int i = 0; i < DETECTION_POINTS_COUNT; i++) + { + src_points[i].x = viewDetectionZone[tracking_channel_idx][social_zone_idx].Points[i].x * viewChannelData[tracking_channel_idx].speed_view_width_ratio; + src_points[i].y = viewDetectionZone[tracking_channel_idx][social_zone_idx].Points[i].y * viewChannelData[tracking_channel_idx].speed_view_height_ratio; + } + + dst_points[0].x = src_points[0].x; + dst_points[0].y = src_points[0].y; + + float dist_a0_a1 = sqrt(pow(src_points[1].x- src_points[0].x,2.0) + pow(src_points[1].y - src_points[0].y, 2.0)); + float x_a0_a1 = (src_points[1].x - src_points[0].x) / dist_a0_a1; + float y_a0_a1 = (src_points[1].y - src_points[0].y) / dist_a0_a1; + + dst_points[1].x = src_points[0].x + x_a0_a1 * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[0]; + dst_points[1].y = src_points[0].y + y_a0_a1 * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[0]; + + float x_a1_a2 = x_a0_a1; + float y_a1_a2 = y_a0_a1 * (-1.0); + + float x_a1_a2_other = x_a0_a1 * (-1.0); + float y_a1_a2_other = y_a0_a1; + + float dist_min = sqrt(pow(dst_points[1].x + x_a1_a2 - src_points[2].x, 2.0) + pow(dst_points[1].y + y_a1_a2 - src_points[2].y, 2.0)); + float dist_min_other = sqrt(pow(dst_points[1].x + x_a1_a2_other - src_points[2].x, 2.0) + pow(dst_points[1].y + y_a1_a2_other - src_points[2].y, 2.0)); + + if (dist_min < dist_min_other) { + dst_points[2].x = dst_points[1].x + x_a1_a2 * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[1]; + dst_points[2].y = dst_points[1].y + y_a1_a2 * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[1]; + } + else { + dst_points[2].x = dst_points[1].x + x_a1_a2_other * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[1]; + dst_points[2].y = dst_points[1].y + y_a1_a2_other * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[1]; + } + + float x_a2_a3 = x_a0_a1 * (-1.0); + float y_a2_a3 = y_a0_a1 * (-1.0); + + dst_points[3].x = dst_points[2].x + x_a2_a3 * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[0]; + dst_points[3].y = dst_points[2].y + y_a2_a3 * viewDetectionZone[tracking_channel_idx][social_zone_idx].world_distance[0]; + + //printf("[GetPerspectiveTransformArray][%d] [%f, %f], [%f, %f], [%f, %f], [%f, %f] \n", social_zone_idx, dst_points[0].x, dst_points[0].y, dst_points[1].x, dst_points[1].y, + // dst_points[2].x, dst_points[2].y, dst_points[3].x, dst_points[3].y); + + //printf("MMMMMMMMMMMMMMM wr = %f, hr = %f \n", viewChannelData[tracking_channel_idx].speed_view_width_ratio, viewChannelData[tracking_channel_idx].speed_view_height_ratio); + + if (viewChannelData[tracking_channel_idx].speed_view_width_ratio > 0 && viewChannelData[tracking_channel_idx].speed_view_height_ratio > 0) + { + //printf("Create MMMMMM \n"); + CvMat *M = cvCreateMat(3, 3, CV_32FC1); + cvGetPerspectiveTransform(src_points, dst_points, M); + return M; + } + else + { + //printf("NULL MMMMMM \n"); + return NULL; + } +} + +#endif \ No newline at end of file diff --git a/src/cv_point_transform.hpp b/src/cv_point_transform.hpp new file mode 100644 index 0000000..ad26c0a --- /dev/null +++ b/src/cv_point_transform.hpp @@ -0,0 +1,58 @@ + +#pragma once + +#ifndef CV_POINT_TRANSFORM_H +#define CV_POINT_TRANSFORM_H +#include "define_inc.h" +#include "utility.h" +#include "cv.h" +#include "list.h" +#include <math.h> + +#ifdef GY_OS_AMBA +#ifdef OPENCV +//#include <opencv2/core/core.hpp> +//#include "opencv2/features2d.hpp" +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/core/core_c.h" +//#include "opencv2/core/core.hpp" +#include "opencv2/core/version.hpp" +#include "opencv2/imgproc/imgproc_c.h" +#ifndef CV_VERSION_EPOCH +#include "opencv2/videoio/videoio_c.h" +//#define OPENCV_VERSION CVAUX_STR(CV_VERSION_MAJOR)"" CVAUX_STR(CV_VERSION_MINOR)"" CVAUX_STR(CV_VERSION_REVISION) +#define OPENCV_VERSION "347" +#pragma comment(lib, "opencv_world" OPENCV_VERSION ".lib") +#else +#define OPENCV_VERSION CVAUX_STR(CV_VERSION_EPOCH)"" CVAUX_STR(CV_VERSION_MAJOR)"" CVAUX_STR(CV_VERSION_MINOR) +#pragma comment(lib, "opencv_core" OPENCV_VERSION ".lib") +#pragma comment(lib, "opencv_imgproc" OPENCV_VERSION ".lib") +#pragma comment(lib, "opencv_highgui" OPENCV_VERSION ".lib") +#endif +#endif + +#ifdef __cplusplus +//#include "human_pose_estimator.hpp" +//using namespace human_pose_estimation; + + + +extern "C" { +#endif +//typedef struct { +// int social_obj_tracking_id; +// //int box_idx_2; +// float distance; +//} distance_node; + + +//void SetPerspectiveTransform(detection_pos* PosInfo, int total_element_size, CvMat *M, int social_zone_idx, float set_distance, float ratio_w, float ratio_h); +float SetPerspectiveTransform_GetObjSpeed(detection_pos* PosInfo_old, detection_pos* PosInfo_new, CvMat *M, int det_zone_idx, float ratio_w, float ratio_h); +CvMat* GetPerspectiveTransformArray(int tracking_channel_idx, int social_zone_idx); + +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/darknet.c b/src/darknet.c new file mode 100644 index 0000000..fe2f30b --- /dev/null +++ b/src/darknet.c @@ -0,0 +1,230 @@ +//#define _CRTDBG_MAP_ALLOC +#include <stdlib.h> +//#include <crtdbg.h> + +#include "darknet.h" + +#include <time.h> + +#include <stdio.h> + +//#include "network.h" +#include "utils.h" + +//#include "blas.h" +//#include "connected_layer.h" +//#include "convolutional_layer.h" +#include "test_nnctrl_live.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +#include "utility.h" + +#include <signal.h> +//===================== +//sophia add 2020/10/08 + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include "signal_test.h" +#endif +#include <execinfo.h> +//===================== + +extern int check_if_start_run_server; + +//extern void gogoTextW(int i); +//extern void gogoText(int i); + +//===================== +//sophia add 2020/10/08 + +void sigstoproutine(int dunno) +{ // 信號處理常式,其中dunno將會得到信號的值 + if(dunno == SIGUSR1) + printf("sigroutine %d process id is %d SIGUSR1 (%d)\n", dunno, getpid(), SIGUSR1); + else if(dunno == SIGTERM) + printf("sigroutine %d process id is %d SIGTERM (%d)\n", dunno, getpid(), SIGTERM); + else if (dunno == SIGQUIT) + printf("sigroutine %d process id is %d SIGQUIT (%d)\n", dunno, getpid(), SIGQUIT); + else if (dunno == SIGINT) + printf("sigroutine %d process id is %d SIGINT (%d)\n", dunno, getpid(), SIGINT); + + if (dunno == SIGUSR1 || dunno == SIGTERM || dunno == SIGQUIT || dunno == SIGINT)//收到SIGUSR1 + { + //printf("\n--------sigstoproutine:%d\n",1); + stop_test_nn_cavalry("sigstoproutine"); + //printf("\n--------sigstoproutine:%d\n",2); + //stop_server(); + //printf("\n--------sigstoproutine:%d\n", 3); + } +} +//===================== + +// 信號處理器函數 +void signal_crash(int sig) { + if (check_if_start_run_server == 1) { + check_if_start_run_server = 0; + + record_process_note_write_to_log(); + + void *buffer[100]; + int nptrs; + + // 根據捕捉到的信號打印不同的消息 + if (sig == SIGSEGV) { + printf("Caught SIGSEGV (Segmentation Fault)\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg, sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "Caught SIGSEGV(Segmentation Fault)"); + write_to_logs_html(temp_msg, "signal_crash", "ERROR", "Yes"); + //write_to_log_for_start(temp_msg, "signal_crash", "ERROR"); + } + else if (sig == SIGABRT) { + printf("Caught SIGABRT (Abort)\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg, sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "Caught SIGABRT (Abort)"); + write_to_logs_html(temp_msg, "signal_crash", "ERROR", "Yes"); + //write_to_log_for_start(temp_msg, "signal_crash", "ERROR"); + } + + if (sig == SIGSEGV || sig == SIGABRT) { + //printf("\n-------hello 2\n"); + // 捕捉呼叫堆疊 + nptrs = backtrace(buffer, 100); + //printf("\n-------hello 3\n"); + + { + printf("backtrace() returned %d addresses\n", nptrs); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg, sizeof(temp_msg), "backtrace() returned %d addresses", nptrs); + write_to_logs_html(temp_msg, "signal_crash", "ERROR", "Yes"); + //write_to_log_for_start(temp_msg, "signal_crash", "ERROR"); + } + + // 打印呼叫堆疊 + char **symbols = backtrace_symbols(buffer, nptrs); + + if (symbols == NULL) { + stop_test_nn_cavalry("signal crash exit #2"); + } + else { + for (int i = 0; i < nptrs; i++) { + char temp_msg[8192] = { 0 }; + printf("\nerror(%d),%s\n", i, symbols[i]); + snprintf(temp_msg, sizeof(temp_msg), "error(%d),%s", i, symbols[i]); + write_to_logs_html(temp_msg, "signal_crash", "ERROR", "Yes"); + //write_to_log_for_start(temp_msg, "signal_crash", "ERROR"); + } + + if (symbols) { + free(symbols); + } + + stop_test_nn_cavalry("signal crash exit"); + } + } + } +} + +int main(int argc, char **argv) +//int main() +{ + /* + int argc = 4; + char argv[20][50] = { 0 }; + strcpy(argv[0],"/emmc/plugin/Aida_data/gynet"); + strcpy(argv[1], "server"); + strcpy(argv[2], "-http_port"); + strcpy(argv[3], "8592");*/ + + /* + for (int i = 0; i < argc; i++) + printf("argv[%d]:%s\n", i, argv[i]);*/ + + printf("\n*****************************\n"); + printf("gynet"); + printf("\n*****************************\n"); + +#if 1 +//===================== +//sophia add 2020/10/08 + if (chdir("/emmc/plugin") != 0) + { + //perror("chdir() to /emmc/plugin fail"); + printf("\nchdir() to /emmc/plugin fail\n"); + return 0; + } + + //printf("parent process id is %d \n", getpid()); + //printf("argc %d argv[0] %s\n", argc, argv[0]); + + // Linux Signal Handling + /*signal(SIGINT, sigstop); // When user pressed the combination CTRL+C + signal(SIGQUIT, sigstop); // When user pressed the quit key + signal(SIGTERM, sigstop); // When the application terminates*/ + + signal(SIGSEGV, signal_crash); + signal(SIGABRT, signal_crash); + + signal(SIGUSR1, sigstoproutine);//設置信號SIGUSR1的處理方法 + signal(SIGTERM, sigstoproutine); + signal(SIGQUIT, sigstoproutine); + signal(SIGINT, sigstoproutine); + + //===================== + + //else if (0 == strcmp(argv[1], "server")) { + if (0 == strcmp(argv[1], "server")) { + + usSleep(2000000); + //gogoTextW(9456); + //gogoText(9999); + //test_open_cv(); + //printf("\n------------gynet 2.0 ver 1.0.4 \n"); + //pid_t pid = GetPIDbyName_Wrapper("gynet"); + //printf("pid %d\n", pid); + pid_t pid = GetPIDbyName_Wrapper("gynet",1); + if (pid != -1 && pid != -2 && pid != -3) + { + printf("\npid %d server\n", pid); + run_server(argc, argv); + } + else if(pid == -3){ + printf("\n[gynet]too many server\n"); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", "too many server"); + write_to_logs_html(temp_msg, "main", "INFO", "Yes"); + write_to_log_for_start(temp_msg, "main", "INFO"); + } + } + } + else if (0 == strcmp(argv[1], "stop")) + { + //找 GYNET 是否已執行 + pid_t pid = GetPIDbyName_Wrapper("gynet",0); + printf("\npid %d\n", pid); + if (pid != -1 && pid != -2) + { + printf("\nkill pid %d\n", pid); + + //debug使用 正式啟用要註解 避免第二個gynet離不開 + + kill(pid, SIGUSR1);//向child 1 子進程發送SIGUSR1中斷 + + //目前的 第二個GYNET結束 + printf("\nexit(0)\n"); + exit(0); + } + } + else { + fprintf(stderr, "Not an option:: %s\n", argv[1]); + } +#endif + printf("\n[main] end\n"); + //_CrtDumpMemoryLeaks(); + return 0; +} + diff --git a/src/darknet.h b/src/darknet.h new file mode 100644 index 0000000..61344d6 --- /dev/null +++ b/src/darknet.h @@ -0,0 +1,47 @@ +#pragma once +#ifndef DARKNET_API +#define DARKNET_API +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <pthread.h> +#include <wchar.h> +#include <locale.h> + +#include "define_inc.h" + +#ifndef ALLEN_MODIFIED +#define ALLEN_MODIFIED +#endif + +//#define REBOOT_BY_CPU_GPU_USAGE + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#define closesocket close +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum{ + MULT, ADD, SUB, DIV +} BINARY_ACTIVATION; + +typedef struct { + int w; + int h; + float scale; + float rad; + float dx; + float dy; + float aspect; +} augment_args; + +void sigstoproutine(int dunno); +void signal_crash(int sig); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/data.c b/src/data.c new file mode 100644 index 0000000..ce3d0b1 --- /dev/null +++ b/src/data.c @@ -0,0 +1,1014 @@ +#include "data.h" +#include "utils.h" +#include "image.h" +#include "cuda.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +list *get_paths(char *filename) +{ + char *path; + FILE *file = fopen(filename, "r"); + if(!file) file_error(filename); + list *lines = make_list(); + while((path=fgetl(file))){ + list_insert(lines, path); + } + fclose(file); + return lines; +} + +/* +char **get_random_paths_indexes(char **paths, int n, int m, int *indexes) +{ + char **random_paths = calloc(n, sizeof(char*)); + int i; + pthread_mutex_lock(&mutex); + for(i = 0; i < n; ++i){ + int index = rand()%m; + indexes[i] = index; + random_paths[i] = paths[index]; + if(i == 0) printf("%s\n", paths[index]); + } + pthread_mutex_unlock(&mutex); + return random_paths; +} +*/ + +char **get_random_paths(char **paths, int n, int m) +{ + char **random_paths = calloc(n, sizeof(char*)); + int i; + pthread_mutex_lock(&mutex); + for(i = 0; i < n; ++i){ + int index = rand()%m; + random_paths[i] = paths[index]; + //if(i == 0) printf("%s\n", paths[index]); + } + pthread_mutex_unlock(&mutex); + return random_paths; +} + +matrix load_image_paths_gray(char **paths, int n, int w, int h) +{ + int i; + matrix X; + X.rows = n; + X.vals = calloc(X.rows, sizeof(float*)); + X.cols = 0; + + for(i = 0; i < n; ++i){ + image im = load_image(paths[i], w, h, 3); + + image gray = grayscale_image(im); + free_image(im); + im = gray; + + X.vals[i] = im.data; + X.cols = im.h*im.w*im.c; + } + return X; +} + +matrix load_image_paths(char **paths, int n, int w, int h) +{ + int i; + matrix X; + X.rows = n; + X.vals = calloc(X.rows, sizeof(float*)); + X.cols = 0; + + for(i = 0; i < n; ++i){ + image im = load_image_color(paths[i], w, h); + X.vals[i] = im.data; + X.cols = im.h*im.w*im.c; + } + return X; +} + +matrix load_image_augment_paths(char **paths, int n, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure, int center) +{ + int i; + matrix X; + X.rows = n; + X.vals = calloc(X.rows, sizeof(float*)); + X.cols = 0; + + for(i = 0; i < n; ++i){ + image im = load_image_color(paths[i], 0, 0); + image crop; + if(center){ + crop = center_crop_image(im, size, size); + } else { + crop = random_augment_image(im, angle, aspect, min, max, size, size); + } + int flip = rand()%2; + if (flip) flip_image(crop); + random_distort_image(crop, hue, saturation, exposure); + + /* + show_image(im, "orig"); + show_image(crop, "crop"); + cvWaitKey(0); + */ + //grayscale_image_3c(crop); + free_image(im); + X.vals[i] = crop.data; + X.cols = crop.h*crop.w*crop.c; + } + return X; +} + + +box_label *read_boxes(char *filename, int *n) +{ + FILE *file = fopen(filename, "r"); + if(!file) file_error(filename); + float x, y, h, w; + int id; + int count = 0; + int size = 64; + box_label *boxes = calloc(size, sizeof(box_label)); + while(fscanf(file, "%d %f %f %f %f", &id, &x, &y, &w, &h) == 5){ + if(count == size) { + size = size * 2; + boxes = realloc(boxes, size*sizeof(box_label)); + } + boxes[count].id = id; + boxes[count].x = x; + boxes[count].y = y; + boxes[count].h = h; + boxes[count].w = w; + boxes[count].left = x - w/2; + boxes[count].right = x + w/2; + boxes[count].top = y - h/2; + boxes[count].bottom = y + h/2; + ++count; + } + fclose(file); + *n = count; + return boxes; +} + +void randomize_boxes(box_label *b, int n) +{ + int i; + for(i = 0; i < n; ++i){ + box_label swap = b[i]; + int index = rand()%n; + b[i] = b[index]; + b[index] = swap; + } +} + +void correct_boxes(box_label *boxes, int n, float dx, float dy, float sx, float sy, int flip) +{ + int i; + for(i = 0; i < n; ++i){ + if(boxes[i].x == 0 && boxes[i].y == 0) { + boxes[i].x = 999999; + boxes[i].y = 999999; + boxes[i].w = 999999; + boxes[i].h = 999999; + continue; + } + boxes[i].left = boxes[i].left * sx - dx; + boxes[i].right = boxes[i].right * sx - dx; + boxes[i].top = boxes[i].top * sy - dy; + boxes[i].bottom = boxes[i].bottom* sy - dy; + + if(flip){ + float swap = boxes[i].left; + boxes[i].left = 1. - boxes[i].right; + boxes[i].right = 1. - swap; + } + + boxes[i].left = constrain(0, 1, boxes[i].left); + boxes[i].right = constrain(0, 1, boxes[i].right); + boxes[i].top = constrain(0, 1, boxes[i].top); + boxes[i].bottom = constrain(0, 1, boxes[i].bottom); + + boxes[i].x = (boxes[i].left+boxes[i].right)/2; + boxes[i].y = (boxes[i].top+boxes[i].bottom)/2; + boxes[i].w = (boxes[i].right - boxes[i].left); + boxes[i].h = (boxes[i].bottom - boxes[i].top); + + boxes[i].w = constrain(0, 1, boxes[i].w); + boxes[i].h = constrain(0, 1, boxes[i].h); + } +} + +void fill_truth_swag(char *path, float *truth, int classes, int flip, float dx, float dy, float sx, float sy) +{ + char labelpath[4096]; + find_replace(path, "images", "labels", labelpath); + find_replace(labelpath, "JPEGImages", "labels", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + + int count = 0; + box_label *boxes = read_boxes(labelpath, &count); + randomize_boxes(boxes, count); + correct_boxes(boxes, count, dx, dy, sx, sy, flip); + float x,y,w,h; + int id; + int i; + + for (i = 0; i < count && i < 90; ++i) { + x = boxes[i].x; + y = boxes[i].y; + w = boxes[i].w; + h = boxes[i].h; + id = boxes[i].id; + + if (w < .0 || h < .0) continue; + + int index = (4+classes) * i; + + truth[index++] = x; + truth[index++] = y; + truth[index++] = w; + truth[index++] = h; + + if (id < classes) truth[index+id] = 1; + } + + if (boxes) { + free(boxes); + boxes = NULL; + } +} + +void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int flip, float dx, float dy, float sx, float sy) +{ + char labelpath[4096]; + find_replace(path, "images", "labels", labelpath); + find_replace(labelpath, "JPEGImages", "labels", labelpath); + + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".png", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + int count = 0; + box_label *boxes = read_boxes(labelpath, &count); + randomize_boxes(boxes, count); + correct_boxes(boxes, count, dx, dy, sx, sy, flip); + float x,y,w,h; + int id; + int i; + + for (i = 0; i < count; ++i) { + x = boxes[i].x; + y = boxes[i].y; + w = boxes[i].w; + h = boxes[i].h; + id = boxes[i].id; + + if (w < .005 || h < .005) continue; + + int col = (int)(x*num_boxes); + int row = (int)(y*num_boxes); + + x = x*num_boxes - col; + y = y*num_boxes - row; + + int index = (col+row*num_boxes)*(5+classes); + if (truth[index]) continue; + truth[index++] = 1; + + if (id < classes) truth[index+id] = 1; + index += classes; + + truth[index++] = x; + truth[index++] = y; + truth[index++] = w; + truth[index++] = h; + } + + if (boxes) { + free(boxes); + boxes = NULL; + } +} + +void load_rle(image im, int *rle, int n) +{ + int count = 0; + int curr = 0; + int i,j; + for(i = 0; i < n; ++i){ + for(j = 0; j < rle[i]; ++j){ + im.data[count++] = curr; + } + curr = 1 - curr; + } + for(; count < im.h*im.w*im.c; ++count){ + im.data[count] = curr; + } +} + +void or_image(image src, image dest, int c) +{ + int i; + for(i = 0; i < src.w*src.h; ++i){ + if(src.data[i]) dest.data[dest.w*dest.h*c + i] = 1; + } +} + +void exclusive_image(image src) +{ + int k, j, i; + int s = src.w*src.h; + for(k = 0; k < src.c-1; ++k){ + for(i = 0; i < s; ++i){ + if (src.data[k*s + i]){ + for(j = k+1; j < src.c; ++j){ + src.data[j*s + i] = 0; + } + } + } + } +} + +box bound_image(image im) +{ + int x,y; + int minx = im.w; + int miny = im.h; + int maxx = 0; + int maxy = 0; + for(y = 0; y < im.h; ++y){ + for(x = 0; x < im.w; ++x){ + if(im.data[y*im.w + x]){ + minx = (x < minx) ? x : minx; + miny = (y < miny) ? y : miny; + maxx = (x > maxx) ? x : maxx; + maxy = (y > maxy) ? y : maxy; + } + } + } + box b = {minx, miny, maxx-minx + 1, maxy-miny + 1}; + //printf("%f %f %f %f\n", b.x, b.y, b.w, b.h); + return b; +} + +void fill_truth_iseg(char *path, int num_boxes, float *truth, int classes, int w, int h, augment_args aug, int flip, int mw, int mh) +{ + char labelpath[4096]; + find_replace(path, "images", "mask", labelpath); + find_replace(labelpath, "JPEGImages", "mask", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + FILE *file = fopen(labelpath, "r"); + if(!file) file_error(labelpath); + char buff[32788]; + int id; + int i = 0; + int j; + image part = make_image(w, h, 1); + while((fscanf(file, "%d %s", &id, buff) == 2) && i < num_boxes){ + int n = 0; + int *rle = read_intlist(buff, &n, 0); + load_rle(part, rle, n); + image sized = rotate_crop_image(part, aug.rad, aug.scale, aug.w, aug.h, aug.dx, aug.dy, aug.aspect); + if(flip) flip_image(sized); + + image mask = resize_image(sized, mw, mh); + truth[i*(mw*mh+1)] = id; + for(j = 0; j < mw*mh; ++j){ + truth[i*(mw*mh + 1) + 1 + j] = mask.data[j]; + } + ++i; + + free_image(mask); + free_image(sized); + + if (rle) { + free(rle); + rle = NULL; + } + } + if(i < num_boxes) truth[i*(mw*mh+1)] = -1; + fclose(file); + free_image(part); +} + +void fill_truth_mask(char *path, int num_boxes, float *truth, int classes, int w, int h, augment_args aug, int flip, int mw, int mh) +{ + char labelpath[4096]; + find_replace(path, "images", "mask", labelpath); + find_replace(labelpath, "JPEGImages", "mask", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + FILE *file = fopen(labelpath, "r"); + if(!file) file_error(labelpath); + char buff[32788]; + int id; + int i = 0; + image part = make_image(w, h, 1); + while((fscanf(file, "%d %s", &id, buff) == 2) && i < num_boxes){ + int n = 0; + int *rle = read_intlist(buff, &n, 0); + load_rle(part, rle, n); + image sized = rotate_crop_image(part, aug.rad, aug.scale, aug.w, aug.h, aug.dx, aug.dy, aug.aspect); + if(flip) flip_image(sized); + box b = bound_image(sized); + if(b.w > 0){ + image crop = crop_image(sized, b.x, b.y, b.w, b.h); + image mask = resize_image(crop, mw, mh); + truth[i*(4 + mw*mh + 1) + 0] = (b.x + b.w/2.)/sized.w; + truth[i*(4 + mw*mh + 1) + 1] = (b.y + b.h/2.)/sized.h; + truth[i*(4 + mw*mh + 1) + 2] = b.w/sized.w; + truth[i*(4 + mw*mh + 1) + 3] = b.h/sized.h; + int j; + for(j = 0; j < mw*mh; ++j){ + truth[i*(4 + mw*mh + 1) + 4 + j] = mask.data[j]; + } + truth[i*(4 + mw*mh + 1) + 4 + mw*mh] = id; + free_image(crop); + free_image(mask); + ++i; + } + free_image(sized); + if (rle) { + free(rle); + rle = NULL; + } + } + fclose(file); + free_image(part); +} + + +void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, int flip, float dx, float dy, float sx, float sy) +{ + char labelpath[4096]; + find_replace(path, "images", "labels", labelpath); + find_replace(labelpath, "JPEGImages", "labels", labelpath); + + find_replace(labelpath, "raw", "labels", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".png", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + int count = 0; + box_label *boxes = read_boxes(labelpath, &count); + randomize_boxes(boxes, count); + correct_boxes(boxes, count, dx, dy, sx, sy, flip); + if(count > num_boxes) count = num_boxes; + float x,y,w,h; + int id; + int i; + int sub = 0; + + for (i = 0; i < count; ++i) { + x = boxes[i].x; + y = boxes[i].y; + w = boxes[i].w; + h = boxes[i].h; + id = boxes[i].id; + + if ((w < .001 || h < .001)) { + ++sub; + continue; + } + + truth[(i-sub)*5+0] = x; + truth[(i-sub)*5+1] = y; + truth[(i-sub)*5+2] = w; + truth[(i-sub)*5+3] = h; + truth[(i-sub)*5+4] = id; + } + if (boxes) { + free(boxes); + boxes = NULL; + } +} + +#define NUMCHARS 37 + +void print_letters(float *pred, int n) +{ + int i; + for(i = 0; i < n; ++i){ + int index = max_index(pred+i*NUMCHARS, NUMCHARS); + printf("%c", int_to_alphanum(index)); + } + printf("\n"); +} + +void fill_truth_captcha(char *path, int n, float *truth) +{ + char *begin = strrchr(path, '/'); + ++begin; + int i; + for(i = 0; i < strlen(begin) && i < n && begin[i] != '.'; ++i){ + int index = alphanum_to_int(begin[i]); + if(index > 35) printf("Bad %c\n", begin[i]); + truth[i*NUMCHARS+index] = 1; + } + for(;i < n; ++i){ + truth[i*NUMCHARS + NUMCHARS-1] = 1; + } +} + +void fill_truth(char *path, char **labels, int k, float *truth) +{ + int i; + memset(truth, 0, k*sizeof(float)); + int count = 0; + for(i = 0; i < k; ++i){ + if(strstr(path, labels[i])){ + truth[i] = 1; + ++count; + //printf("%s %s %d\n", path, labels[i], i); + } + } + if(count != 1 && (k != 1 || count != 0)) printf("Too many or too few labels: %d, %s\n", count, path); +} + +void fill_hierarchy(float *truth, int k, tree *hierarchy) +{ + int j; + for(j = 0; j < k; ++j){ + if(truth[j]){ + int parent = hierarchy->parent[j]; + while(parent >= 0){ + truth[parent] = 1; + parent = hierarchy->parent[parent]; + } + } + } + int i; + int count = 0; + for(j = 0; j < hierarchy->groups; ++j){ + //printf("%d\n", count); + int mask = 1; + for(i = 0; i < hierarchy->group_size[j]; ++i){ + if(truth[count + i]){ + mask = 0; + break; + } + } + if (mask) { + for(i = 0; i < hierarchy->group_size[j]; ++i){ + truth[count + i] = SECRET_NUM; + } + } + count += hierarchy->group_size[j]; + } +} + +matrix load_regression_labels_paths(char **paths, int n, int k) +{ + matrix y = make_matrix(n, k); + int i,j; + for(i = 0; i < n; ++i){ + char labelpath[4096]; + find_replace(paths[i], "images", "labels", labelpath); + find_replace(labelpath, "JPEGImages", "labels", labelpath); + find_replace(labelpath, ".BMP", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPeG", ".txt", labelpath); + find_replace(labelpath, ".Jpeg", ".txt", labelpath); + find_replace(labelpath, ".PNG", ".txt", labelpath); + find_replace(labelpath, ".TIF", ".txt", labelpath); + find_replace(labelpath, ".bmp", ".txt", labelpath); + find_replace(labelpath, ".jpeg", ".txt", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".png", ".txt", labelpath); + find_replace(labelpath, ".tif", ".txt", labelpath); + + FILE *file = fopen(labelpath, "r"); + for(j = 0; j < k; ++j){ + fscanf(file, "%f", &(y.vals[i][j])); + } + fclose(file); + } + return y; +} + +matrix load_labels_paths(char **paths, int n, char **labels, int k, tree *hierarchy) +{ + matrix y = make_matrix(n, k); + int i; + for(i = 0; i < n && labels; ++i){ + fill_truth(paths[i], labels, k, y.vals[i]); + if(hierarchy){ + fill_hierarchy(y.vals[i], k, hierarchy); + } + } + return y; +} + +matrix load_tags_paths(char **paths, int n, int k) +{ + matrix y = make_matrix(n, k); + int i; + //int count = 0; + for(i = 0; i < n; ++i){ + char label[4096]; + find_replace(paths[i], "images", "labels", label); + find_replace(label, ".jpg", ".txt", label); + FILE *file = fopen(label, "r"); + if (!file) continue; + //++count; + int tag; + while(fscanf(file, "%d", &tag) == 1){ + if(tag < k){ + y.vals[i][tag] = 1; + } + } + fclose(file); + } + //printf("%d/%d\n", count, n); + return y; +} + +char **get_labels(char *filename) +{ + list *plist = get_paths(filename); + char **labels = (char **)list_to_array(plist); + free_list(plist); + return labels; +} + +void free_data(data d) +{ + if(!d.shallow){ + free_matrix(d.X); + free_matrix(d.y); + }else{ + if (d.X.vals) { + free(d.X.vals); + d.X.vals = NULL; + } + + if (d.y.vals) { + free(d.y.vals); + d.y.vals = NULL; + } + } +} + +image get_segmentation_image(char *path, int w, int h, int classes) +{ + char labelpath[4096]; + find_replace(path, "images", "mask", labelpath); + find_replace(labelpath, "JPEGImages", "mask", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + image mask = make_image(w, h, classes); + FILE *file = fopen(labelpath, "r"); + if(!file) file_error(labelpath); + char buff[32788]; + int id; + image part = make_image(w, h, 1); + while(fscanf(file, "%d %s", &id, buff) == 2){ + int n = 0; + int *rle = read_intlist(buff, &n, 0); + load_rle(part, rle, n); + or_image(part, mask, id); + if (rle) { + free(rle); + rle = NULL; + } + } + //exclusive_image(mask); + fclose(file); + free_image(part); + return mask; +} + +image get_segmentation_image2(char *path, int w, int h, int classes) +{ + char labelpath[4096]; + find_replace(path, "images", "mask", labelpath); + find_replace(labelpath, "JPEGImages", "mask", labelpath); + find_replace(labelpath, ".jpg", ".txt", labelpath); + find_replace(labelpath, ".JPG", ".txt", labelpath); + find_replace(labelpath, ".JPEG", ".txt", labelpath); + image mask = make_image(w, h, classes+1); + int i; + for(i = 0; i < w*h; ++i){ + mask.data[w*h*classes + i] = 1; + } + FILE *file = fopen(labelpath, "r"); + if(!file) file_error(labelpath); + char buff[32788]; + int id; + image part = make_image(w, h, 1); + while(fscanf(file, "%d %s", &id, buff) == 2){ + int n = 0; + int *rle = read_intlist(buff, &n, 0); + load_rle(part, rle, n); + or_image(part, mask, id); + for(i = 0; i < w*h; ++i){ + if(part.data[i]) mask.data[w*h*classes + i] = 0; + } + if (rle) { + free(rle); + rle = NULL; + } + } + //exclusive_image(mask); + fclose(file); + free_image(part); + return mask; +} + +data select_data(data *orig, int *inds) +{ + data d = {0}; + d.shallow = 1; + d.w = orig[0].w; + d.h = orig[0].h; + + d.X.rows = orig[0].X.rows; + d.y.rows = orig[0].X.rows; + + d.X.cols = orig[0].X.cols; + d.y.cols = orig[0].y.cols; + + d.X.vals = calloc(orig[0].X.rows, sizeof(float *)); + d.y.vals = calloc(orig[0].y.rows, sizeof(float *)); + int i; + for(i = 0; i < d.X.rows; ++i){ + d.X.vals[i] = orig[inds[i]].X.vals[i]; + d.y.vals[i] = orig[inds[i]].y.vals[i]; + } + return d; +} + +data *tile_data(data orig, int divs, int size) +{ + data *ds = calloc(divs*divs, sizeof(data)); + int i, j; +#pragma omp parallel for + for(i = 0; i < divs*divs; ++i){ + data d; + d.shallow = 0; + d.w = orig.w/divs * size; + d.h = orig.h/divs * size; + d.X.rows = orig.X.rows; + d.X.cols = d.w*d.h*3; + d.X.vals = calloc(d.X.rows, sizeof(float*)); + + d.y = copy_matrix(orig.y); +#pragma omp parallel for + for(j = 0; j < orig.X.rows; ++j){ + int x = (i%divs) * orig.w / divs - (d.w - orig.w/divs)/2; + int y = (i/divs) * orig.h / divs - (d.h - orig.h/divs)/2; + image im = float_to_image(orig.w, orig.h, 3, orig.X.vals[j]); + d.X.vals[j] = crop_image(im, x, y, d.w, d.h).data; + } + ds[i] = d; + } + return ds; +} + +data resize_data(data orig, int w, int h) +{ + data d = {0}; + d.shallow = 0; + d.w = w; + d.h = h; + int i; + d.X.rows = orig.X.rows; + d.X.cols = w*h*3; + d.X.vals = calloc(d.X.rows, sizeof(float*)); + + d.y = copy_matrix(orig.y); +#pragma omp parallel for + for(i = 0; i < orig.X.rows; ++i){ + image im = float_to_image(orig.w, orig.h, 3, orig.X.vals[i]); + d.X.vals[i] = resize_image(im, w, h).data; + } + return d; +} + +matrix concat_matrix(matrix m1, matrix m2) +{ + int i, count = 0; + matrix m; + m.cols = m1.cols; + m.rows = m1.rows+m2.rows; + m.vals = calloc(m1.rows + m2.rows, sizeof(float*)); + for(i = 0; i < m1.rows; ++i){ + m.vals[count++] = m1.vals[i]; + } + for(i = 0; i < m2.rows; ++i){ + m.vals[count++] = m2.vals[i]; + } + return m; +} + +data concat_data(data d1, data d2) +{ + data d = {0}; + d.shallow = 1; + d.X = concat_matrix(d1.X, d2.X); + d.y = concat_matrix(d1.y, d2.y); + d.w = d1.w; + d.h = d1.h; + return d; +} + +data concat_datas(data *d, int n) +{ + int i; + data out = {0}; + for(i = 0; i < n; ++i){ + data new = concat_data(d[i], out); + free_data(out); + out = new; + } + return out; +} + +data load_categorical_data_csv(char *filename, int target, int k) +{ + data d = {0}; + d.shallow = 0; + matrix X = csv_to_matrix(filename); + float *truth_1d = pop_column(&X, target); + float **truth = one_hot_encode(truth_1d, X.rows, k); + matrix y; + y.rows = X.rows; + y.cols = k; + y.vals = truth; + d.X = X; + d.y = y; + if (truth_1d) { + free(truth_1d); + truth_1d = NULL; + } + return d; +} + +void get_random_batch(data d, int n, float *X, float *y) +{ + int j; + for(j = 0; j < n; ++j){ + int index = rand()%d.X.rows; + memcpy(X+j*d.X.cols, d.X.vals[index], d.X.cols*sizeof(float)); + memcpy(y+j*d.y.cols, d.y.vals[index], d.y.cols*sizeof(float)); + } +} + +void get_next_batch(data d, int n, int offset, float *X, float *y) +{ + int j; + for(j = 0; j < n; ++j){ + int index = offset + j; + memcpy(X+j*d.X.cols, d.X.vals[index], d.X.cols*sizeof(float)); + if(y) memcpy(y+j*d.y.cols, d.y.vals[index], d.y.cols*sizeof(float)); + } +} + +void smooth_data(data d) +{ + int i, j; + float scale = 1. / d.y.cols; + float eps = .1; + for(i = 0; i < d.y.rows; ++i){ + for(j = 0; j < d.y.cols; ++j){ + d.y.vals[i][j] = eps * scale + (1-eps) * d.y.vals[i][j]; + } + } +} + +void randomize_data(data d) +{ + int i; + for(i = d.X.rows-1; i > 0; --i){ + int index = rand()%i; + float *swap = d.X.vals[index]; + d.X.vals[index] = d.X.vals[i]; + d.X.vals[i] = swap; + + swap = d.y.vals[index]; + d.y.vals[index] = d.y.vals[i]; + d.y.vals[i] = swap; + } +} + +void scale_data_rows(data d, float s) +{ + int i; + for(i = 0; i < d.X.rows; ++i){ + scale_array(d.X.vals[i], d.X.cols, s); + } +} + +void translate_data_rows(data d, float s) +{ + int i; + for(i = 0; i < d.X.rows; ++i){ + translate_array(d.X.vals[i], d.X.cols, s); + } +} + +data copy_data(data d) +{ + data c = {0}; + c.w = d.w; + c.h = d.h; + c.shallow = 0; + c.num_boxes = d.num_boxes; + c.boxes = d.boxes; + c.X = copy_matrix(d.X); + c.y = copy_matrix(d.y); + return c; +} + +void normalize_data_rows(data d) +{ + int i; + for(i = 0; i < d.X.rows; ++i){ + normalize_array(d.X.vals[i], d.X.cols); + } +} + +data get_data_part(data d, int part, int total) +{ + data p = {0}; + p.shallow = 1; + p.X.rows = d.X.rows * (part + 1) / total - d.X.rows * part / total; + p.y.rows = d.y.rows * (part + 1) / total - d.y.rows * part / total; + p.X.cols = d.X.cols; + p.y.cols = d.y.cols; + p.X.vals = d.X.vals + d.X.rows * part / total; + p.y.vals = d.y.vals + d.y.rows * part / total; + return p; +} + +data get_random_data(data d, int num) +{ + data r = {0}; + r.shallow = 1; + + r.X.rows = num; + r.y.rows = num; + + r.X.cols = d.X.cols; + r.y.cols = d.y.cols; + + r.X.vals = calloc(num, sizeof(float *)); + r.y.vals = calloc(num, sizeof(float *)); + + int i; + for(i = 0; i < num; ++i){ + int index = rand()%d.X.rows; + r.X.vals[i] = d.X.vals[index]; + r.y.vals[i] = d.y.vals[index]; + } + return r; +} + +data *split_data(data d, int part, int total) +{ + data *split = calloc(2, sizeof(data)); + int i; + int start = part*d.X.rows/total; + int end = (part+1)*d.X.rows/total; + data train; + data test; + train.shallow = test.shallow = 1; + + test.X.rows = test.y.rows = end-start; + train.X.rows = train.y.rows = d.X.rows - (end-start); + train.X.cols = test.X.cols = d.X.cols; + train.y.cols = test.y.cols = d.y.cols; + + train.X.vals = calloc(train.X.rows, sizeof(float*)); + test.X.vals = calloc(test.X.rows, sizeof(float*)); + train.y.vals = calloc(train.y.rows, sizeof(float*)); + test.y.vals = calloc(test.y.rows, sizeof(float*)); + + for(i = 0; i < start; ++i){ + train.X.vals[i] = d.X.vals[i]; + train.y.vals[i] = d.y.vals[i]; + } + for(i = start; i < end; ++i){ + test.X.vals[i-start] = d.X.vals[i]; + test.y.vals[i-start] = d.y.vals[i]; + } + for(i = end; i < d.X.rows; ++i){ + train.X.vals[i-(end-start)] = d.X.vals[i]; + train.y.vals[i-(end-start)] = d.y.vals[i]; + } + split[0] = train; + split[1] = test; + return split; +} + diff --git a/src/data.h b/src/data.h new file mode 100644 index 0000000..e39ce5e --- /dev/null +++ b/src/data.h @@ -0,0 +1,107 @@ +#pragma once +#ifndef DATA_H +#define DATA_H +#include <pthread.h> +#include "define_inc.h" +#include "darknet.h" +#include "matrix.h" +#include "list.h" +#include "image.h" +#include "tree.h" + +static inline float distance_from_edge(int x, int max) +{ + int dx = (max/2) - x; + if (dx < 0) dx = -dx; + dx = (max/2) + 1 - dx; + dx *= 2; + float dist = (float)dx/max; + if (dist > 1) dist = 1; + return dist; +} + +typedef struct { + int w, h; + matrix X; + matrix y; + int shallow; + int *num_boxes; + box **boxes; +} data; + +typedef enum { + CLASSIFICATION_DATA, DETECTION_DATA, CAPTCHA_DATA, REGION_DATA, IMAGE_DATA, COMPARE_DATA, WRITING_DATA, SWAG_DATA, TAG_DATA, OLD_CLASSIFICATION_DATA, STUDY_DATA, DET_DATA, SUPER_DATA, LETTERBOX_DATA, REGRESSION_DATA, SEGMENTATION_DATA, INSTANCE_DATA, ISEG_DATA +} data_type; + +typedef struct load_args { + int threads; + char **paths; + char *path; + int n; + int m; + char **labels; + int h; + int w; + int out_w; + int out_h; + int nh; + int nw; + int num_boxes; + int min, max, size; + int classes; + int background; + int scale; + int center; + int coords; + float jitter; + float angle; + float aspect; + float saturation; + float exposure; + float hue; + data *d; + image *im; + image *resized; + data_type type; + tree *hierarchy; +} load_args; + +typedef struct { + int id; + float x, y, w, h; + float left, right, top, bottom; +} box_label; + +void free_data(data d); + +void print_letters(float *pred, int n); + + + +matrix load_image_augment_paths(char **paths, int n, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure, int center); + +void get_random_batch(data d, int n, float *X, float *y); +data get_data_part(data d, int part, int total); +data get_random_data(data d, int num); +data load_categorical_data_csv(char *filename, int target, int k); +void normalize_data_rows(data d); +void scale_data_rows(data d, float s); +void translate_data_rows(data d, float s); +void randomize_data(data d); +data *split_data(data d, int part, int total); +data concat_datas(data *d, int n); +void fill_truth(char *path, char **labels, int k, float *truth); + +data resize_data(data orig, int w, int h); +data *tile_data(data orig, int divs, int size); +data select_data(data *orig, int *inds); + +data copy_data(data d); +data concat_data(data d1, data d2); + +void get_next_batch(data d, int n, int offset, float *X, float *y); + +box_label *read_boxes(char *filename, int *n); + + +#endif diff --git a/src/dbscan.c b/src/dbscan.c new file mode 100644 index 0000000..1452b63 --- /dev/null +++ b/src/dbscan.c @@ -0,0 +1,345 @@ +/* Copyright 2015 Gagarine Yaikhom (MIT License) */ +#include <limits.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> + +#define UNCLASSIFIED -1 +#define NOISE -2 + +#define CORE_POINT 1 +#define NOT_CORE_POINT 0 + +#define SUCCESS 0 +#define FAILURE -3 + +typedef struct point_s point_t; +struct point_s { + double x, y, z; + int cluster_id, nop; // Ken 2022-10-26 add nop ( number of cluster points ) variable for rule-based classifier +}; + +typedef struct node_s node_t; +struct node_s { + unsigned int index; + node_t *next; +}; + +typedef struct epsilon_neighbours_s epsilon_neighbours_t; +struct epsilon_neighbours_s { + unsigned int num_members; + node_t *head, *tail; +}; + +node_t *create_node(unsigned int index); +int append_at_end( + unsigned int index, + epsilon_neighbours_t *en); +epsilon_neighbours_t *get_epsilon_neighbours( + unsigned int index, + point_t *points, + unsigned int num_points, + double epsilon, + double (*dist)(point_t *a, point_t *b)); +void print_epsilon_neighbours( + point_t *points, + epsilon_neighbours_t *en); +void destroy_epsilon_neighbours(epsilon_neighbours_t *en); +void dbscan( + point_t *points, + unsigned int num_points, + double epsilon, + unsigned int minpts, + double (*dist)(point_t *a, point_t *b)); +int expand( + unsigned int index, + unsigned int cluster_id, + point_t *points, + unsigned int num_points, + double epsilon, + unsigned int minpts, + double (*dist)(point_t *a, point_t *b)); +int spread( + unsigned int index, + epsilon_neighbours_t *seeds, + unsigned int cluster_id, + point_t *points, + unsigned int num_points, + double epsilon, + unsigned int minpts, + double (*dist)(point_t *a, point_t *b)); +double euclidean_dist(point_t *a, point_t *b); +double adjacent_intensity_dist(point_t *a, point_t *b); +unsigned int parse_input( + FILE *file, + point_t **points, + double *epsilon, + unsigned int *minpts); +void print_points( + point_t *points, + unsigned int num_points); + +node_t *create_node(unsigned int index) +{ + node_t *n = (node_t *) calloc(1, sizeof(node_t)); + if (n == NULL) + perror("Failed to allocate node."); + else { + n->index = index; + n->next = NULL; + } + return n; +} + +int append_at_end( + unsigned int index, + epsilon_neighbours_t *en) +{ + node_t *n = create_node(index); + if (n == NULL) { + free(en); + return FAILURE; + } + if (en->head == NULL) { + en->head = n; + en->tail = n; + } else { + en->tail->next = n; + en->tail = n; + } + ++(en->num_members); + return SUCCESS; +} + +epsilon_neighbours_t *get_epsilon_neighbours( + unsigned int index, + point_t *points, + unsigned int num_points, + double epsilon, + double (*dist)(point_t *a, point_t *b)) +{ + epsilon_neighbours_t *en = (epsilon_neighbours_t *) + calloc(1, sizeof(epsilon_neighbours_t)); + if (en == NULL) { + perror("Failed to allocate epsilon neighbours."); + return en; + } + for (int i = 0; i < (int)num_points; ++i) { + if ((unsigned int)i == index) + continue; + // printf("dist(&points[index], &points[i]):%f\n", dist(&points[index], &points[i])); + if (dist(&points[index], &points[i]) > epsilon) + continue; + else { + if (append_at_end(i, en) == FAILURE) { + destroy_epsilon_neighbours(en); + en = NULL; + break; + } + } + } + return en; +} + +void print_epsilon_neighbours( + point_t *points, + epsilon_neighbours_t *en) +{ + if (en) { + node_t *h = en->head; + while (h) { + printf("(%lfm, %lf, %lf)\n", + points[h->index].x, + points[h->index].y, + points[h->index].z); + h = h->next; + } + } +} + +void destroy_epsilon_neighbours(epsilon_neighbours_t *en) +{ + if (en) { + node_t *t, *h = en->head; + while (h) { + t = h->next; + free(h); + h = t; + } + free(en); + } +} + +void dbscan( + point_t *points, + unsigned int num_points, + double epsilon, + unsigned int minpts, + double (*dist)(point_t *a, point_t *b)) +{ + unsigned int i, cluster_id = 0; + for (i = 0; i < num_points; ++i) { + // printf("points[i].cluster_id:%d\n",points[i].cluster_id); + if (points[i].cluster_id == UNCLASSIFIED) { + if (expand(i, cluster_id, points, + num_points, epsilon, minpts, + dist) == CORE_POINT) + ++cluster_id; + } + } +} + +int expand( + unsigned int index, + unsigned int cluster_id, + point_t *points, + unsigned int num_points, + double epsilon, + unsigned int minpts, + double (*dist)(point_t *a, point_t *b)) +{ + int return_value = NOT_CORE_POINT; + epsilon_neighbours_t *seeds = + get_epsilon_neighbours(index, points, + num_points, epsilon, + dist); + if (seeds == NULL) + return FAILURE; + // printf("seeds->num_members:%u\n", seeds->num_members); + if (seeds->num_members < minpts) + points[index].cluster_id = NOISE; + else { + points[index].cluster_id = cluster_id; + node_t *h = seeds->head; + while (h) { + points[h->index].cluster_id = cluster_id; + h = h->next; + } + + h = seeds->head; + while (h) { + spread(h->index, seeds, cluster_id, points, + num_points, epsilon, minpts, dist); + h = h->next; + } + + return_value = CORE_POINT; + } + destroy_epsilon_neighbours(seeds); + return return_value; +} + +int spread( + unsigned int index, + epsilon_neighbours_t *seeds, + unsigned int cluster_id, + point_t *points, + unsigned int num_points, + double epsilon, + unsigned int minpts, + double (*dist)(point_t *a, point_t *b)) +{ + epsilon_neighbours_t *spread = + get_epsilon_neighbours(index, points, + num_points, epsilon, + dist); + if (spread == NULL) + return FAILURE; + if (spread->num_members >= minpts) { + node_t *n = spread->head; + point_t *d; + while (n) { + d = &points[n->index]; + if (d->cluster_id == NOISE || + d->cluster_id == UNCLASSIFIED) { + if (d->cluster_id == UNCLASSIFIED) { + if (append_at_end(n->index, seeds) + == FAILURE) { + destroy_epsilon_neighbours(spread); + return FAILURE; + } + } + d->cluster_id = cluster_id; + } + n = n->next; + } + } + + destroy_epsilon_neighbours(spread); + return SUCCESS; +} + +double euclidean_dist(point_t *a, point_t *b) +{ + return sqrt(pow(a->x - b->x, 2) + + pow(a->y - b->y, 2) + + pow(a->z - b->z, 2)); +} + +// 2022-10-26 Ken for rule-based classifier +double euclidean_dist_to_op(point_t *a) // op : original point +{ + return sqrt(pow(a->x - 0.0, 2) + + pow(a->y - 0.0, 2) + + pow(a->z - 0.0, 2)); +} + +unsigned int parse_input( + FILE *file, + point_t **points, + double *epsilon, + unsigned int *minpts) +{ + unsigned int num_points, i = 0; + fscanf(file, "%lf %u %u\n", + epsilon, minpts, &num_points); + point_t *p = (point_t *) + calloc(num_points, sizeof(point_t)); + if (p == NULL) { + perror("Failed to allocate points array"); + return 0; + } + while (i < num_points) { + fscanf(file, "%lf %lf %lf\n", + &(p[i].x), &(p[i].y), &(p[i].z)); + p[i].cluster_id = UNCLASSIFIED; + ++i; + } + *points = p; + return num_points; +} + +void print_points( + point_t *points, + unsigned int num_points) +{ + unsigned int i = 0; + printf("Number of points: %u\n" + " x y z cluster_id\n" + "-----------------------------\n" + , num_points); + while (i < num_points) { + printf("%5.2lf %5.2lf %5.2lf: %d\n", + points[i].x, + points[i].y, points[i].z, + points[i].cluster_id); + ++i; + } +} + +// int main(void) { +// point_t *points; +// double epsilon; +// unsigned int minpts; +// unsigned int num_points = +// parse_input(stdin, &points, &epsilon, &minpts); +// if (num_points) { +// dbscan(points, num_points, epsilon, +// minpts, euclidean_dist); +// printf("Epsilon: %lf\n", epsilon); +// printf("Minimum points: %u\n", minpts); +// print_points(points, num_points); +// } +// free(points); +// return 0; +// } diff --git a/src/dbscan_example.dat b/src/dbscan_example.dat new file mode 100644 index 0000000..630e67f --- /dev/null +++ b/src/dbscan_example.dat @@ -0,0 +1,54 @@ +1 2 53 +1.0 3.0 1.0 +1.0 4.0 1.0 +1.0 5.0 1.0 +1.0 6.0 1.0 +2.0 2.0 1.0 +2.0 3.0 0.0 +2.0 4.0 0.0 +2.0 5.0 0.0 +2.0 6.0 0.0 +2.0 7.0 1.0 +3.0 1.0 1.0 +3.0 2.0 1.0 +3.0 3.0 1.0 +3.0 4.0 0.0 +3.0 5.0 0.0 +3.0 6.0 1.0 +3.0 7.0 1.0 +4.0 1.0 1.0 +4.0 2.0 1.0 +4.0 3.0 0.0 +4.0 4.0 0.0 +4.0 5.0 1.0 +4.0 6.0 0.0 +4.0 7.0 1.0 +4.0 8.0 1.0 +5.0 1.0 1.0 +5.0 2.0 0.0 +5.0 3.0 0.0 +5.0 4.0 0.0 +5.0 5.0 0.0 +5.0 6.0 0.0 +5.0 7.0 1.0 +5.0 8.0 1.0 +6.0 1.0 1.0 +6.0 2.0 0.0 +6.0 3.0 1.0 +6.0 4.0 1.0 +6.0 5.0 1.0 +6.0 6.0 1.0 +6.0 7.0 1.0 +7.0 1.0 1.0 +7.0 2.0 0.0 +7.0 3.0 0.0 +7.0 4.0 0.0 +7.0 5.0 1.0 +8.0 1.0 1.0 +8.0 2.0 1.0 +8.0 3.0 0.0 +8.0 4.0 1.0 +8.0 5.0 1.0 +8.0 6.0 1.0 +9.0 2.0 1.0 +9.0 3.0 1.0 diff --git a/src/deconvolutional_kernels.cu b/src/deconvolutional_kernels.cu new file mode 100644 index 0000000..8267dcf --- /dev/null +++ b/src/deconvolutional_kernels.cu @@ -0,0 +1,139 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "convolutional_layer.h" +#include "deconvolutional_layer.h" +#include "batchnorm_layer.h" +#include "gemm.h" +#include "blas.h" +#include "im2col.h" +#include "col2im.h" +#include "utils.h" +#include "cuda.h" +} + +extern "C" void forward_deconvolutional_layer_gpu(layer l, network net) +{ + int i; + + int m = l.size*l.size*l.n; + int n = l.h*l.w; + int k = l.c; + + fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1); + + for(i = 0; i < l.batch; ++i){ + float *a = l.weights_gpu; + float *b = net.input_gpu + i*l.c*l.h*l.w; + float *c = net.workspace; + + gemm_gpu(1,0,m,n,k,1,a,m,b,n,0,c,n); + + col2im_gpu(net.workspace, l.out_c, l.out_h, l.out_w, l.size, l.stride, l.pad, l.output_gpu+i*l.outputs); + } + if (l.batch_normalize) { + forward_batchnorm_layer_gpu(l, net); + } else { + add_bias_gpu(l.output_gpu, l.biases_gpu, l.batch, l.n, l.out_w*l.out_h); + } + activate_array_gpu(l.output_gpu, l.batch*l.n*l.out_w*l.out_h, l.activation); +} + +extern "C" void backward_deconvolutional_layer_gpu(layer l, network net) +{ + int i; + + //constrain_gpu(l.outputs*l.batch, 1, l.delta_gpu, 1); + gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); + + if(l.batch_normalize){ + backward_batchnorm_layer_gpu(l, net); + } else { + backward_bias_gpu(l.bias_updates_gpu, l.delta_gpu, l.batch, l.n, l.out_w*l.out_h); + } + + //if(net.delta_gpu) memset(net.delta_gpu, 0, l.batch*l.h*l.w*l.c*sizeof(float)); + + for(i = 0; i < l.batch; ++i){ + int m = l.c; + int n = l.size*l.size*l.n; + int k = l.h*l.w; + + float *a = net.input_gpu + i*m*k; + float *b = net.workspace; + float *c = l.weight_updates_gpu; + + im2col_gpu(l.delta_gpu + i*l.outputs, l.out_c, l.out_h, l.out_w, + l.size, l.stride, l.pad, b); + gemm_gpu(0,1,m,n,k,1,a,k,b,k,1,c,n); + + if(net.delta_gpu){ + int m = l.c; + int n = l.h*l.w; + int k = l.size*l.size*l.n; + + float *a = l.weights_gpu; + float *b = net.workspace; + float *c = net.delta_gpu + i*n*m; + + gemm_gpu(0,0,m,n,k,1,a,k,b,n,1,c,n); + } + } +} + +extern "C" void pull_deconvolutional_layer(layer l) +{ + cuda_pull_array(l.weights_gpu, l.weights, l.c*l.n*l.size*l.size); + cuda_pull_array(l.biases_gpu, l.biases, l.n); + cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.c*l.n*l.size*l.size); + cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.n); + if (l.batch_normalize){ + cuda_pull_array(l.scales_gpu, l.scales, l.n); + cuda_pull_array(l.rolling_mean_gpu, l.rolling_mean, l.n); + cuda_pull_array(l.rolling_variance_gpu, l.rolling_variance, l.n); + } +} + +extern "C" void push_deconvolutional_layer(layer l) +{ + cuda_push_array(l.weights_gpu, l.weights, l.c*l.n*l.size*l.size); + cuda_push_array(l.biases_gpu, l.biases, l.n); + cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.c*l.n*l.size*l.size); + cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.n); + if (l.batch_normalize){ + cuda_push_array(l.scales_gpu, l.scales, l.n); + cuda_push_array(l.rolling_mean_gpu, l.rolling_mean, l.n); + cuda_push_array(l.rolling_variance_gpu, l.rolling_variance, l.n); + } +} + +void update_deconvolutional_layer_gpu(layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + + if(a.adam){ + adam_update_gpu(l.weights_gpu, l.weight_updates_gpu, l.m_gpu, l.v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.nweights, batch, a.t); + adam_update_gpu(l.biases_gpu, l.bias_updates_gpu, l.bias_m_gpu, l.bias_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.n, batch, a.t); + if(l.scales_gpu){ + adam_update_gpu(l.scales_gpu, l.scale_updates_gpu, l.scale_m_gpu, l.scale_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.n, batch, a.t); + } + }else{ + axpy_gpu(l.nweights, -decay*batch, l.weights_gpu, 1, l.weight_updates_gpu, 1); + axpy_gpu(l.nweights, learning_rate/batch, l.weight_updates_gpu, 1, l.weights_gpu, 1); + scal_gpu(l.nweights, momentum, l.weight_updates_gpu, 1); + + axpy_gpu(l.n, learning_rate/batch, l.bias_updates_gpu, 1, l.biases_gpu, 1); + scal_gpu(l.n, momentum, l.bias_updates_gpu, 1); + + if(l.scales_gpu){ + axpy_gpu(l.n, learning_rate/batch, l.scale_updates_gpu, 1, l.scales_gpu, 1); + scal_gpu(l.n, momentum, l.scale_updates_gpu, 1); + } + } +} + diff --git a/src/deconvolutional_layer.c b/src/deconvolutional_layer.c new file mode 100644 index 0000000..00c0e85 --- /dev/null +++ b/src/deconvolutional_layer.c @@ -0,0 +1,312 @@ +#include "deconvolutional_layer.h" +#include "convolutional_layer.h" +#include "batchnorm_layer.h" +#include "utils.h" +#include "im2col.h" +#include "col2im.h" +#include "blas.h" +#include "gemm.h" + +#include <stdio.h> +#include <time.h> + + +static size_t get_workspace_size(layer l){ + return (size_t)l.h*l.w*l.size*l.size*l.n*sizeof(float); +} + +void bilinear_init(layer l) +{ + int i,j,f; + float center = (l.size-1) / 2.; + for(f = 0; f < l.n; ++f){ + for(j = 0; j < l.size; ++j){ + for(i = 0; i < l.size; ++i){ + float val = (1 - fabs(i - center)) * (1 - fabs(j - center)); + int c = f%l.c; + int ind = f*l.size*l.size*l.c + c*l.size*l.size + j*l.size + i; + l.weights[ind] = val; + } + } + } +} + + +layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam) +{ + int i; + layer l = {0}; + l.type = DECONVOLUTIONAL; + + l.h = h; + l.w = w; + l.c = c; + l.n = n; + l.batch = batch; + l.stride = stride; + l.size = size; + + l.nweights = c*n*size*size; + l.nbiases = n; + + l.weights = calloc(c*n*size*size, sizeof(float)); + l.weight_updates = calloc(c*n*size*size, sizeof(float)); + + l.biases = calloc(n, sizeof(float)); + l.bias_updates = calloc(n, sizeof(float)); + //float scale = n/(size*size*c); + //printf("scale: %f\n", scale); + float scale = .02; + for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_normal(); + //bilinear_init(l); + for(i = 0; i < n; ++i){ + l.biases[i] = 0; + } + l.pad = padding; + + l.out_h = (l.h - 1) * l.stride + l.size - 2*l.pad; + l.out_w = (l.w - 1) * l.stride + l.size - 2*l.pad; + l.out_c = n; + l.outputs = l.out_w * l.out_h * l.out_c; + l.inputs = l.w * l.h * l.c; + + scal_cpu(l.nweights, (float)l.out_w*l.out_h/(l.w*l.h), l.weights, 1); + + l.output = calloc(l.batch*l.outputs, sizeof(float)); + l.delta = calloc(l.batch*l.outputs, sizeof(float)); + + l.forward = forward_deconvolutional_layer; + l.backward = backward_deconvolutional_layer; + l.update = update_deconvolutional_layer; + + l.batch_normalize = batch_normalize; + + if(batch_normalize){ + l.scales = calloc(n, sizeof(float)); + l.scale_updates = calloc(n, sizeof(float)); + for(i = 0; i < n; ++i){ + l.scales[i] = 1; + } + + l.mean = calloc(n, sizeof(float)); + l.variance = calloc(n, sizeof(float)); + + l.mean_delta = calloc(n, sizeof(float)); + l.variance_delta = calloc(n, sizeof(float)); + + l.rolling_mean = calloc(n, sizeof(float)); + l.rolling_variance = calloc(n, sizeof(float)); + l.x = calloc(l.batch*l.outputs, sizeof(float)); + l.x_norm = calloc(l.batch*l.outputs, sizeof(float)); + } + if(adam){ + l.m = calloc(c*n*size*size, sizeof(float)); + l.v = calloc(c*n*size*size, sizeof(float)); + l.bias_m = calloc(n, sizeof(float)); + l.scale_m = calloc(n, sizeof(float)); + l.bias_v = calloc(n, sizeof(float)); + l.scale_v = calloc(n, sizeof(float)); + } + +#ifdef GPU + l.forward_gpu = forward_deconvolutional_layer_gpu; + l.backward_gpu = backward_deconvolutional_layer_gpu; + l.update_gpu = update_deconvolutional_layer_gpu; + + if(gpu_index >= 0){ + + if (adam) { + l.m_gpu = cuda_make_array(l.m, c*n*size*size); + l.v_gpu = cuda_make_array(l.v, c*n*size*size); + l.bias_m_gpu = cuda_make_array(l.bias_m, n); + l.bias_v_gpu = cuda_make_array(l.bias_v, n); + l.scale_m_gpu = cuda_make_array(l.scale_m, n); + l.scale_v_gpu = cuda_make_array(l.scale_v, n); + } + l.weights_gpu = cuda_make_array(l.weights, c*n*size*size); + l.weight_updates_gpu = cuda_make_array(l.weight_updates, c*n*size*size); + + l.biases_gpu = cuda_make_array(l.biases, n); + l.bias_updates_gpu = cuda_make_array(l.bias_updates, n); + + l.delta_gpu = cuda_make_array(l.delta, l.batch*l.out_h*l.out_w*n); + l.output_gpu = cuda_make_array(l.output, l.batch*l.out_h*l.out_w*n); + + if(batch_normalize){ + l.mean_gpu = cuda_make_array(0, n); + l.variance_gpu = cuda_make_array(0, n); + + l.rolling_mean_gpu = cuda_make_array(0, n); + l.rolling_variance_gpu = cuda_make_array(0, n); + + l.mean_delta_gpu = cuda_make_array(0, n); + l.variance_delta_gpu = cuda_make_array(0, n); + + l.scales_gpu = cuda_make_array(l.scales, n); + l.scale_updates_gpu = cuda_make_array(0, n); + + l.x_gpu = cuda_make_array(0, l.batch*l.out_h*l.out_w*n); + l.x_norm_gpu = cuda_make_array(0, l.batch*l.out_h*l.out_w*n); + } + } + #ifdef CUDNN + cudnnCreateTensorDescriptor(&l.dstTensorDesc); + cudnnCreateTensorDescriptor(&l.normTensorDesc); + cudnnSetTensor4dDescriptor(l.dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l.batch, l.out_c, l.out_h, l.out_w); + cudnnSetTensor4dDescriptor(l.normTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l.out_c, 1, 1); + #endif +#endif + + l.activation = activation; + l.workspace_size = get_workspace_size(l); + + fprintf(stderr, "deconv%5d %2d x%2d /%2d %4d x%4d x%4d -> %4d x%4d x%4d\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c); + + return l; +} + +void denormalize_deconvolutional_layer(layer l) +{ + int i, j; + for(i = 0; i < l.n; ++i){ + float scale = l.scales[i]/sqrt(l.rolling_variance[i] + .00001); + for(j = 0; j < l.c*l.size*l.size; ++j){ + l.weights[i*l.c*l.size*l.size + j] *= scale; + } + l.biases[i] -= l.rolling_mean[i] * scale; + l.scales[i] = 1; + l.rolling_mean[i] = 0; + l.rolling_variance[i] = 1; + } +} + +void resize_deconvolutional_layer(layer *l, int h, int w) +{ + l->h = h; + l->w = w; + l->out_h = (l->h - 1) * l->stride + l->size - 2*l->pad; + l->out_w = (l->w - 1) * l->stride + l->size - 2*l->pad; + + l->outputs = l->out_h * l->out_w * l->out_c; + l->inputs = l->w * l->h * l->c; + + l->output = realloc(l->output, l->batch*l->outputs*sizeof(float)); + l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float)); + if(l->batch_normalize){ + l->x = realloc(l->x, l->batch*l->outputs*sizeof(float)); + l->x_norm = realloc(l->x_norm, l->batch*l->outputs*sizeof(float)); + } + +#ifdef GPU + cuda_free(l->delta_gpu); + cuda_free(l->output_gpu); + + l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs); + l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs); + + if(l->batch_normalize){ + cuda_free(l->x_gpu); + cuda_free(l->x_norm_gpu); + + l->x_gpu = cuda_make_array(l->output, l->batch*l->outputs); + l->x_norm_gpu = cuda_make_array(l->output, l->batch*l->outputs); + } + #ifdef CUDNN + cudnnSetTensor4dDescriptor(l->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, l->batch, l->out_c, l->out_h, l->out_w); + cudnnSetTensor4dDescriptor(l->normTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l->out_c, 1, 1); + #endif +#endif + l->workspace_size = get_workspace_size(*l); +} + +void forward_deconvolutional_layer(const layer l, network net) +{ + int i; + + int m = l.size*l.size*l.n; + int n = l.h*l.w; + int k = l.c; + + fill_cpu(l.outputs*l.batch, 0, l.output, 1); + + for(i = 0; i < l.batch; ++i){ + float *a = l.weights; + float *b = net.input + i*l.c*l.h*l.w; + float *c = net.workspace; + + gemm_cpu(1,0,m,n,k,1,a,m,b,n,0,c,n); + + col2im_cpu(net.workspace, l.out_c, l.out_h, l.out_w, l.size, l.stride, l.pad, l.output+i*l.outputs); + } + if (l.batch_normalize) { + forward_batchnorm_layer(l, net); + } else { + add_bias(l.output, l.biases, l.batch, l.n, l.out_w*l.out_h); + } + activate_array(l.output, l.batch*l.n*l.out_w*l.out_h, l.activation); +} + +void backward_deconvolutional_layer(layer l, network net) +{ + int i; + + gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); + + if(l.batch_normalize){ + backward_batchnorm_layer(l, net); + } else { + backward_bias(l.bias_updates, l.delta, l.batch, l.n, l.out_w*l.out_h); + } + + //if(net.delta) memset(net.delta, 0, l.batch*l.h*l.w*l.c*sizeof(float)); + + for(i = 0; i < l.batch; ++i){ + int m = l.c; + int n = l.size*l.size*l.n; + int k = l.h*l.w; + + float *a = net.input + i*m*k; + float *b = net.workspace; + float *c = l.weight_updates; + + im2col_cpu(l.delta + i*l.outputs, l.out_c, l.out_h, l.out_w, + l.size, l.stride, l.pad, b); + gemm_cpu(0,1,m,n,k,1,a,k,b,k,1,c,n); + + if(net.delta){ + int m = l.c; + int n = l.h*l.w; + int k = l.size*l.size*l.n; + + float *a = l.weights; + float *b = net.workspace; + float *c = net.delta + i*n*m; + + gemm_cpu(0,0,m,n,k,1,a,k,b,n,1,c,n); + } + } +} + +void update_deconvolutional_layer(layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + + int size = l.size*l.size*l.c*l.n; + axpy_cpu(l.n, learning_rate/batch, l.bias_updates, 1, l.biases, 1); + scal_cpu(l.n, momentum, l.bias_updates, 1); + + if(l.scales){ + axpy_cpu(l.n, learning_rate/batch, l.scale_updates, 1, l.scales, 1); + scal_cpu(l.n, momentum, l.scale_updates, 1); + } + + axpy_cpu(size, -decay*batch, l.weights, 1, l.weight_updates, 1); + axpy_cpu(size, learning_rate/batch, l.weight_updates, 1, l.weights, 1); + scal_cpu(size, momentum, l.weight_updates, 1); +} + + + diff --git a/src/deconvolutional_layer.h b/src/deconvolutional_layer.h new file mode 100644 index 0000000..7abe09f --- /dev/null +++ b/src/deconvolutional_layer.h @@ -0,0 +1,26 @@ +#pragma once +#ifndef DECONVOLUTIONAL_LAYER_H +#define DECONVOLUTIONAL_LAYER_H +#include "define_inc.h" +#include "cuda.h" +#include "image.h" +#include "activations.h" +#include "layer.h" +#include "network.h" + +#ifdef GPU +void forward_deconvolutional_layer_gpu(layer l, network net); +void backward_deconvolutional_layer_gpu(layer l, network net); +void update_deconvolutional_layer_gpu(layer l, update_args a); +void push_deconvolutional_layer(layer l); +void pull_deconvolutional_layer(layer l); +#endif + +layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam); +void resize_deconvolutional_layer(layer *l, int h, int w); +void forward_deconvolutional_layer(const layer l, network net); +void update_deconvolutional_layer(layer l, update_args a); +void backward_deconvolutional_layer(layer l, network net); + +#endif + diff --git a/src/decrypt.c b/src/decrypt.c new file mode 100644 index 0000000..62c45fe --- /dev/null +++ b/src/decrypt.c @@ -0,0 +1,310 @@ +/* decrypt.cpp + * Performs decryption using AES 128-bit + * @author Cecelia Wisniewska + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "structures.h" + +/* Used in Round() and serves as the final round during decryption + * SubRoundKey is simply an XOR of a 128-bit block with the 128-bit key. + * So basically does the same as AddRoundKey in the encryption + */ +void SubRoundKey(unsigned char * state, unsigned char * roundKey) { + for (int i = 0; i < 16; i++) { + state[i] ^= roundKey[i]; + } +} + +/* InverseMixColumns uses mul9, mul11, mul13, mul14 look-up tables + * Unmixes the columns by reversing the effect of MixColumns in encryption + */ +void InverseMixColumns(unsigned char * state) { + unsigned char tmp[16]; + + tmp[0] = (unsigned char)mul14[state[0]] ^ mul11[state[1]] ^ mul13[state[2]] ^ mul9[state[3]]; + tmp[1] = (unsigned char)mul9[state[0]] ^ mul14[state[1]] ^ mul11[state[2]] ^ mul13[state[3]]; + tmp[2] = (unsigned char)mul13[state[0]] ^ mul9[state[1]] ^ mul14[state[2]] ^ mul11[state[3]]; + tmp[3] = (unsigned char)mul11[state[0]] ^ mul13[state[1]] ^ mul9[state[2]] ^ mul14[state[3]]; + + tmp[4] = (unsigned char)mul14[state[4]] ^ mul11[state[5]] ^ mul13[state[6]] ^ mul9[state[7]]; + tmp[5] = (unsigned char)mul9[state[4]] ^ mul14[state[5]] ^ mul11[state[6]] ^ mul13[state[7]]; + tmp[6] = (unsigned char)mul13[state[4]] ^ mul9[state[5]] ^ mul14[state[6]] ^ mul11[state[7]]; + tmp[7] = (unsigned char)mul11[state[4]] ^ mul13[state[5]] ^ mul9[state[6]] ^ mul14[state[7]]; + + tmp[8] = (unsigned char)mul14[state[8]] ^ mul11[state[9]] ^ mul13[state[10]] ^ mul9[state[11]]; + tmp[9] = (unsigned char)mul9[state[8]] ^ mul14[state[9]] ^ mul11[state[10]] ^ mul13[state[11]]; + tmp[10] = (unsigned char)mul13[state[8]] ^ mul9[state[9]] ^ mul14[state[10]] ^ mul11[state[11]]; + tmp[11] = (unsigned char)mul11[state[8]] ^ mul13[state[9]] ^ mul9[state[10]] ^ mul14[state[11]]; + + tmp[12] = (unsigned char)mul14[state[12]] ^ mul11[state[13]] ^ mul13[state[14]] ^ mul9[state[15]]; + tmp[13] = (unsigned char)mul9[state[12]] ^ mul14[state[13]] ^ mul11[state[14]] ^ mul13[state[15]]; + tmp[14] = (unsigned char)mul13[state[12]] ^ mul9[state[13]] ^ mul14[state[14]] ^ mul11[state[15]]; + tmp[15] = (unsigned char)mul11[state[12]] ^ mul13[state[13]] ^ mul9[state[14]] ^ mul14[state[15]]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +// Shifts rows right (rather than left) for decryption +void ShiftRows(unsigned char * state) { + unsigned char tmp[16]; + + /* Column 1 */ + tmp[0] = state[0]; + tmp[1] = state[13]; + tmp[2] = state[10]; + tmp[3] = state[7]; + + /* Column 2 */ + tmp[4] = state[4]; + tmp[5] = state[1]; + tmp[6] = state[14]; + tmp[7] = state[11]; + + /* Column 3 */ + tmp[8] = state[8]; + tmp[9] = state[5]; + tmp[10] = state[2]; + tmp[11] = state[15]; + + /* Column 4 */ + tmp[12] = state[12]; + tmp[13] = state[9]; + tmp[14] = state[6]; + tmp[15] = state[3]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +/* Perform substitution to each of the 16 bytes + * Uses inverse S-box as lookup table + */ +void SubBytes(unsigned char * state) { + for (int i = 0; i < 16; i++) { // Perform substitution to each of the 16 bytes + state[i] = inv_s[state[i]]; + } +} + +/* Each round operates on 128 bits at a time + * The number of rounds is defined in AESDecrypt() + * Not surprisingly, the steps are the encryption steps but reversed + */ +void Round(unsigned char * state, unsigned char * key) { + SubRoundKey(state, key); + InverseMixColumns(state); + ShiftRows(state); + SubBytes(state); +} + +// Same as Round() but no InverseMixColumns +void InitialRound(unsigned char * state, unsigned char * key) { + SubRoundKey(state, key); + ShiftRows(state); + SubBytes(state); +} + +/* The AES decryption function + * Organizes all the decryption steps into one function + */ +void LILIN_AESDecrypt(unsigned char * encryptedMessage, unsigned char * expandedKey, unsigned char * decryptedMessage) +{ + unsigned char state[16]; // Stores the first 16 bytes of encrypted message + + for (int i = 0; i < 16; i++) { + state[i] = encryptedMessage[i]; + } + + InitialRound(state, expandedKey+160); + + //int numberOfRounds = 9; + + for (int i = 8; i >= 0; i--) { + Round(state, expandedKey + (16 * (i + 1))); + } + + SubRoundKey(state, expandedKey); // Final round + + // Copy decrypted state to buffer + for (int i = 0; i < 16; i++) { + decryptedMessage[i] = state[i]; + } +} + +int hex2int(char ch) +{ + if (ch >= '0' && ch <= '9') + return ch - '0'; + if (ch >= 'A' && ch <= 'F') + return ch - 'A' + 10; + if (ch >= 'a' && ch <= 'f') + return ch - 'a' + 10; + return -1; +} + +int LILIN_File_Decryption(char* source_file, char* dest_file, unsigned char * key_ptr, int original_length, int debug_mode) +{ + FILE* infile; + char *infile_name = NULL; + char *outfile_name = NULL; + unsigned char *encrypted_content; + long size = 0; + + infile_name = (source_file == NULL)? "message.aes" : source_file; + outfile_name = (dest_file == NULL)? "message.restored" : dest_file; + + if (debug_mode) + { + printf("[LILIN File Decryption] infile_name = %s\n", infile_name); + printf("[LILIN File Decryption] outfile_name = %s\n", outfile_name); + } + + infile = fopen(infile_name, "rb"); + if (infile != NULL) + { + fseek(infile, 0, SEEK_END); + size = ftell(infile); + encrypted_content = malloc(sizeof(unsigned char) * size); + if (encrypted_content == NULL) + { + printf("[LILIN File Decryption] Memory allocation error for encrypted content! Require %ld bytes of available memory spaces.\n", size); + return 1; + } + rewind(infile); + size_t read_result = fread(encrypted_content, 1, size, infile); + if (read_result != size) + { + printf("[LILIN File Decryption] Encrypted content read failure! Encrypted file may corrupt.\n"); + return 2; + } + fclose(infile); + if (debug_mode) + { + printf("[LILIN File Decryption] Encrypted message length = %ld", size); + printf("[LILIN File Decryption] Read encrypted message from '%s':\n", infile_name); + printf("------------------------------------\n"); + printf("%s\n", encrypted_content); + printf("------------------------------------\n"); + } + } + else + { + printf("[LILIN File Decryption] Unable to open file '%s'.\n", infile_name); + return 3; + } + + if (debug_mode) + { + printf("[LILIN File Decryption] Encrypted message in decimal = "); + for (int i = 0; i < size; i++) + { + printf("%d ", (int) encrypted_content[i]); + if (i >= 1024) + { + printf("...(File too large. Ignored.)..."); + break; + } + } + printf("\n"); + } + + if (key_ptr != NULL) + { + if (debug_mode) + { + printf("[LILIN File Decryption] Key (int) = "); + for (int i=0; i<16; i++) + printf("%d ", key_ptr[i]); + printf("\n"); + } + + unsigned char expandedKey[176]; + KeyExpansion(key_ptr, expandedKey); + + long messageLen = size; + unsigned char * decrypted_content = malloc(sizeof(unsigned char) * messageLen); + if (decrypted_content == NULL) + { + printf("[LILIN File Decryption] Memory allocation error for decrypted message! Require %ld bytes of available memory spaces.\n", messageLen); + return 4; + } + + for (int i = 0; i < messageLen; i += 16) + LILIN_AESDecrypt(encrypted_content + i, expandedKey, decrypted_content + i); + + if (debug_mode) + { + printf("[LILIN File Decryption] Decrypted message in decimal = \n"); + //printf("Decrypted message in ASCII (may be incomplete when reading NULL character):\n"); + printf("------------------------------------\n"); + for (int i = 0; i < messageLen; i++) + { + printf("%d ", (int)decrypted_content[i]); + //printf("%c", decrypted_content[i]); + if (i >= 1024) + { + printf("...(File too large. Ignored.)..."); + break; + } + } + printf("\n"); + printf("------------------------------------\n"); + } + + FILE* outfile = fopen(outfile_name, "wb"); + if (outfile != NULL) + { + if (original_length == 0) + original_length = size; + + fwrite(decrypted_content, sizeof(char), original_length, outfile); + if (debug_mode) + { + printf("[LILIN File Decryption] Wrote decrypted message to file '%s'.\n", outfile_name); + printf("[LILIN File Decryption] Total file length = %ld\n", ftell(outfile)); // Should be the same to padded message length. + } + fclose(outfile); + return 5; + } + else + { + printf("[LILIN File Decryption] Unable to write encrypted content to the destination file!\n"); + return 6; + } + if (encrypted_content) { + free(encrypted_content); + encrypted_content = NULL; + } + + if (decrypted_content) { + free(decrypted_content); + decrypted_content = NULL; + } + } + else + { + printf("[LILIN File Decryption] Unable to open key file!\n"); + return 7; + } +} + +/*int main(int argc, char* argv[]) +{ + printf("=====================================\n"); + printf(" LILIN 128-bit AES Decryption Tool \n"); + printf("=====================================\n"); + + int debug_flag = 0; + int length = 0; + //printf("Please input original length: "); + //int originalLen = scanf("%d", &length); + + if (argc == 1) + LILIN_AES128_Decrypt(NULL, NULL, "public_keyfile", length, debug_flag); + else + LILIN_AES128_Decrypt(argv[1], argv[2], argv[3], length, debug_flag); +}*/ diff --git a/src/define_inc.h b/src/define_inc.h new file mode 100644 index 0000000..a0ee51e --- /dev/null +++ b/src/define_inc.h @@ -0,0 +1,19 @@ +#pragma once +#ifndef DEFINE_INC_H +#define DEFINE_INC_H + +//#define GY_OS_WIN +#define GY_OS_AMBA +//#define GY_OS_NOVA +//#define GY_OS_V_SERIES + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +//#define _DEBUG_AMBA + //#define HTTP_DEBUG_AMBA + //#define HTTP_POST_AMBA + //#define COLOR_MERGE + //#define NOT_USE + #define TEST_DETECTOR_MEM +#endif + +#endif diff --git a/src/demo.c b/src/demo.c new file mode 100644 index 0000000..b89efb8 --- /dev/null +++ b/src/demo.c @@ -0,0 +1,349 @@ +#include "network.h" +#include "detection_layer.h" +#include "region_layer.h" +#include "cost_layer.h" +#include "utils.h" +#include "parser.h" +#include "box.h" +#include "image.h" +#include "demo.h" +#include <sys/time.h> + +#define DEMO 1 + +#ifdef OPENCV + +static char **demo_names; +static image **demo_alphabet; +static int demo_classes; + +static network *net; +static image buff [3]; +static image buff_letter[3]; +static int buff_index = 0; +static void * cap; +static float fps = 0; +static float demo_thresh = 0; +static float demo_hier = .5; +static int running = 0; + +static int demo_frame = 3; +static int demo_index = 0; +static float **predictions; +static float *avg; +static int demo_done = 0; +static int demo_total = 0; +double demo_time; + +detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num); + +int size_network(network *net) +{ + int i; + int count = 0; + for(i = 0; i < net->n; ++i){ + layer l = net->layers[i]; + if(l.type == YOLO || l.type == REGION || l.type == DETECTION){ + count += l.outputs; + } + } + return count; +} + +void remember_network(network *net) +{ + int i; + int count = 0; + for(i = 0; i < net->n; ++i){ + layer l = net->layers[i]; + if(l.type == YOLO || l.type == REGION || l.type == DETECTION){ + memcpy(predictions[demo_index] + count, net->layers[i].output, sizeof(float) * l.outputs); + count += l.outputs; + } + } +} + +detection *avg_predictions(network *net, int *nboxes) +{ + int i, j; + int count = 0; + fill_cpu(demo_total, 0, avg, 1); + for(j = 0; j < demo_frame; ++j){ + axpy_cpu(demo_total, 1./demo_frame, predictions[j], 1, avg, 1); + } + for(i = 0; i < net->n; ++i){ + layer l = net->layers[i]; + if(l.type == YOLO || l.type == REGION || l.type == DETECTION){ + memcpy(l.output, avg + count, sizeof(float) * l.outputs); + count += l.outputs; + } + } + detection *dets = get_network_boxes(net, buff[0].w, buff[0].h, demo_thresh, demo_hier, 0, 1, nboxes); + return dets; +} + +void *detect_in_thread(void *ptr) +{ + running = 1; + float nms = .4; + + layer l = net->layers[net->n-1]; + float *X = buff_letter[(buff_index+2)%3].data; + network_predict(net, X); + + /* + if(l.type == DETECTION){ + get_detection_boxes(l, 1, 1, demo_thresh, probs, boxes, 0); + } else */ + remember_network(net); + detection *dets = 0; + int nboxes = 0; + dets = avg_predictions(net, &nboxes); + + + /* + int i,j; + box zero = {0}; + int classes = l.classes; + for(i = 0; i < demo_detections; ++i){ + avg[i].objectness = 0; + avg[i].bbox = zero; + memset(avg[i].prob, 0, classes*sizeof(float)); + for(j = 0; j < demo_frame; ++j){ + axpy_cpu(classes, 1./demo_frame, dets[j][i].prob, 1, avg[i].prob, 1); + avg[i].objectness += dets[j][i].objectness * 1./demo_frame; + avg[i].bbox.x += dets[j][i].bbox.x * 1./demo_frame; + avg[i].bbox.y += dets[j][i].bbox.y * 1./demo_frame; + avg[i].bbox.w += dets[j][i].bbox.w * 1./demo_frame; + avg[i].bbox.h += dets[j][i].bbox.h * 1./demo_frame; + } + //copy_cpu(classes, dets[0][i].prob, 1, avg[i].prob, 1); + //avg[i].objectness = dets[0][i].objectness; + } + */ + + if (nms > 0) do_nms_obj(dets, nboxes, l.classes, nms); + + printf("\033[2J"); + printf("\033[1;1H"); + printf("\nFPS:%.1f\n",fps); + printf("Objects:\n\n"); + image display = buff[(buff_index+2) % 3]; + draw_detections(display, dets, nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes); + free_detections(dets, nboxes); + + demo_index = (demo_index + 1)%demo_frame; + running = 0; + return 0; +} + +void *fetch_in_thread(void *ptr) +{ + free_image(buff[buff_index]); + buff[buff_index] = get_image_from_stream(cap); + if(buff[buff_index].data == 0) { + demo_done = 1; + return 0; + } + letterbox_image_into(buff[buff_index], net->w, net->h, buff_letter[buff_index]); + return 0; +} + +void *display_in_thread(void *ptr) +{ + int c = show_image(buff[(buff_index + 1)%3], "Demo", 1); + if (c != -1) c = c%256; + if (c == 27) { + demo_done = 1; + return 0; + } else if (c == 82) { + demo_thresh += .02; + } else if (c == 84) { + demo_thresh -= .02; + if(demo_thresh <= .02) demo_thresh = .02; + } else if (c == 83) { + demo_hier += .02; + } else if (c == 81) { + demo_hier -= .02; + if(demo_hier <= .0) demo_hier = .0; + } + return 0; +} + +void *display_loop(void *ptr) +{ + while(1){ + display_in_thread(0); + } +} + +void *detect_loop(void *ptr) +{ + while(1){ + detect_in_thread(0); + } +} + +void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int delay, char *prefix, int avg_frames, float hier, int w, int h, int frames, int fullscreen) +{ + //demo_frame = avg_frames; + image **alphabet = load_alphabet(); + demo_names = names; + demo_alphabet = alphabet; + demo_classes = classes; + demo_thresh = thresh; + demo_hier = hier; + printf("Demo\n"); + net = load_network(cfgfile, weightfile, 0); + set_batch_network(net, 1); + pthread_t detect_thread; + pthread_t fetch_thread; + + srand(2222222); + + int i; + demo_total = size_network(net); + predictions = calloc(demo_frame, sizeof(float*)); + for (i = 0; i < demo_frame; ++i){ + predictions[i] = calloc(demo_total, sizeof(float)); + } + avg = calloc(demo_total, sizeof(float)); + + if(filename){ + printf("video file: %s\n", filename); + cap = open_video_stream(filename, 0, 0, 0, 0); + }else{ + cap = open_video_stream(0, cam_index, w, h, frames); + } + + if(!cap) error("Couldn't connect to webcam.\n"); + + buff[0] = get_image_from_stream(cap); + buff[1] = copy_image(buff[0]); + buff[2] = copy_image(buff[0]); + buff_letter[0] = letterbox_image(buff[0], net->w, net->h); + buff_letter[1] = letterbox_image(buff[0], net->w, net->h); + buff_letter[2] = letterbox_image(buff[0], net->w, net->h); + + int count = 0; + if(!prefix){ + make_window("Demo", 1352, 1013, fullscreen); + } + + demo_time = what_time_is_it_now(); + + while(!demo_done){ + buff_index = (buff_index + 1) %3; + if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); + if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); + if(!prefix){ + fps = 1./(what_time_is_it_now() - demo_time); + demo_time = what_time_is_it_now(); + display_in_thread(0); + }else{ + char name[256]; + sprintf(name, "%s_%08d", prefix, count); + save_image(buff[(buff_index + 1)%3], name); + } + pthread_join(fetch_thread, 0); + pthread_join(detect_thread, 0); + ++count; + } +} + +/* + void demo_compare(char *cfg1, char *weight1, char *cfg2, char *weight2, float thresh, int cam_index, const char *filename, char **names, int classes, int delay, char *prefix, int avg_frames, float hier, int w, int h, int frames, int fullscreen) + { + demo_frame = avg_frames; + predictions = calloc(demo_frame, sizeof(float*)); + image **alphabet = load_alphabet(); + demo_names = names; + demo_alphabet = alphabet; + demo_classes = classes; + demo_thresh = thresh; + demo_hier = hier; + printf("Demo\n"); + net = load_network(cfg1, weight1, 0); + set_batch_network(net, 1); + pthread_t detect_thread; + pthread_t fetch_thread; + + srand(2222222); + + if(filename){ + printf("video file: %s\n", filename); + cap = cvCaptureFromFile(filename); + }else{ + cap = cvCaptureFromCAM(cam_index); + + if(w){ + cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH, w); + } + if(h){ + cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, h); + } + if(frames){ + cvSetCaptureProperty(cap, CV_CAP_PROP_FPS, frames); + } + } + + if(!cap) error("Couldn't connect to webcam.\n"); + + layer l = net->layers[net->n-1]; + demo_detections = l.n*l.w*l.h; + int j; + + avg = (float *) calloc(l.outputs, sizeof(float)); + for(j = 0; j < demo_frame; ++j) predictions[j] = (float *) calloc(l.outputs, sizeof(float)); + + boxes = (box *)calloc(l.w*l.h*l.n, sizeof(box)); + probs = (float **)calloc(l.w*l.h*l.n, sizeof(float *)); + for(j = 0; j < l.w*l.h*l.n; ++j) probs[j] = (float *)calloc(l.classes+1, sizeof(float)); + + buff[0] = get_image_from_stream(cap); + buff[1] = copy_image(buff[0]); + buff[2] = copy_image(buff[0]); + buff_letter[0] = letterbox_image(buff[0], net->w, net->h); + buff_letter[1] = letterbox_image(buff[0], net->w, net->h); + buff_letter[2] = letterbox_image(buff[0], net->w, net->h); + ipl = cvCreateImage(cvSize(buff[0].w,buff[0].h), IPL_DEPTH_8U, buff[0].c); + + int count = 0; + if(!prefix){ + cvNamedWindow("Demo", CV_WINDOW_NORMAL); + if(fullscreen){ + cvSetWindowProperty("Demo", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); + } else { + cvMoveWindow("Demo", 0, 0); + cvResizeWindow("Demo", 1352, 1013); + } + } + + demo_time = what_time_is_it_now(); + + while(!demo_done){ +buff_index = (buff_index + 1) %3; +if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); +if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); +if(!prefix){ + fps = 1./(what_time_is_it_now() - demo_time); + demo_time = what_time_is_it_now(); + display_in_thread(0); +}else{ + char name[256]; + sprintf(name, "%s_%08d", prefix, count); + save_image(buff[(buff_index + 1)%3], name); +} +pthread_join(fetch_thread, 0); +pthread_join(detect_thread, 0); +++count; +} +} +*/ +#else +void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int delay, char *prefix, int avg, float hier, int w, int h, int frames, int fullscreen) +{ + fprintf(stderr, "Demo needs OpenCV for webcam images.\n"); +} +#endif + diff --git a/src/demo.h b/src/demo.h new file mode 100644 index 0000000..230c9a4 --- /dev/null +++ b/src/demo.h @@ -0,0 +1,9 @@ +#pragma once +#ifndef DEMO_H +#define DEMO_H +#include "define_inc.h" +#include "image.h" + +void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, int avg, float hier_thresh, int w, int h, int fps, int fullscreen); + +#endif diff --git a/src/detection_layer.c b/src/detection_layer.c new file mode 100644 index 0000000..662a465 --- /dev/null +++ b/src/detection_layer.c @@ -0,0 +1,278 @@ +#include "detection_layer.h" +#include "activations.h" +#include "softmax_layer.h" +#include "blas.h" +#include "box.h" +#include "cuda.h" +#include "utils.h" + +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +detection_layer make_detection_layer(int batch, int inputs, int n, int side, int classes, int coords, int rescore) +{ + detection_layer l = {0}; + l.type = DETECTION; + + l.n = n; + l.batch = batch; + l.inputs = inputs; + l.classes = classes; + l.coords = coords; + l.rescore = rescore; + l.side = side; + l.w = side; + l.h = side; + assert(side*side*((1 + l.coords)*l.n + l.classes) == inputs); + l.cost = calloc(1, sizeof(float)); + l.outputs = l.inputs; + l.truths = l.side*l.side*(1+l.coords+l.classes); + l.output = calloc(batch*l.outputs, sizeof(float)); + l.delta = calloc(batch*l.outputs, sizeof(float)); + + l.forward = forward_detection_layer; + l.backward = backward_detection_layer; +#ifdef GPU + l.forward_gpu = forward_detection_layer_gpu; + l.backward_gpu = backward_detection_layer_gpu; + l.output_gpu = cuda_make_array(l.output, batch*l.outputs); + l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs); +#endif + + fprintf(stderr, "Detection Layer\n"); + srand(0); + + return l; +} + +void forward_detection_layer(const detection_layer l, network net) +{ + int locations = l.side*l.side; + int i,j; + memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); + //if(l.reorg) reorg(l.output, l.w*l.h, size*l.n, l.batch, 1); + int b; + if (l.softmax){ + for(b = 0; b < l.batch; ++b){ + int index = b*l.inputs; + for (i = 0; i < locations; ++i) { + int offset = i*l.classes; + softmax(l.output + index + offset, l.classes, 1, 1, + l.output + index + offset); + } + } + } + if(net.train){ + float avg_iou = 0; + float avg_cat = 0; + float avg_allcat = 0; + float avg_obj = 0; + float avg_anyobj = 0; + int count = 0; + *(l.cost) = 0; + int size = l.inputs * l.batch; + memset(l.delta, 0, size * sizeof(float)); + for (b = 0; b < l.batch; ++b){ + int index = b*l.inputs; + for (i = 0; i < locations; ++i) { + int truth_index = (b*locations + i)*(1+l.coords+l.classes); + int is_obj = net.truth[truth_index]; + for (j = 0; j < l.n; ++j) { + int p_index = index + locations*l.classes + i*l.n + j; + l.delta[p_index] = l.noobject_scale*(0 - l.output[p_index]); + *(l.cost) += l.noobject_scale*pow(l.output[p_index], 2); + avg_anyobj += l.output[p_index]; + } + + int best_index = -1; + float best_iou = 0; + float best_rmse = 20; + + if (!is_obj){ + continue; + } + + int class_index = index + i*l.classes; + for(j = 0; j < l.classes; ++j) { + l.delta[class_index+j] = l.class_scale * (net.truth[truth_index+1+j] - l.output[class_index+j]); + *(l.cost) += l.class_scale * pow(net.truth[truth_index+1+j] - l.output[class_index+j], 2); + if(net.truth[truth_index + 1 + j]) avg_cat += l.output[class_index+j]; + avg_allcat += l.output[class_index+j]; + } + + box truth = float_to_box(net.truth + truth_index + 1 + l.classes, 1); + truth.x /= l.side; + truth.y /= l.side; + + for(j = 0; j < l.n; ++j){ + int box_index = index + locations*(l.classes + l.n) + (i*l.n + j) * l.coords; + box out = float_to_box(l.output + box_index, 1); + out.x /= l.side; + out.y /= l.side; + + if (l.sqrt){ + out.w = out.w*out.w; + out.h = out.h*out.h; + } + + float iou = box_iou(out, truth); + //iou = 0; + float rmse = box_rmse(out, truth); + if(best_iou > 0 || iou > 0){ + if(iou > best_iou){ + best_iou = iou; + best_index = j; + } + }else{ + if(rmse < best_rmse){ + best_rmse = rmse; + best_index = j; + } + } + } + + if(l.forced){ + if(truth.w*truth.h < .1){ + best_index = 1; + }else{ + best_index = 0; + } + } + if(l.random && *(net.seen) < 64000){ + best_index = rand()%l.n; + } + + int box_index = index + locations*(l.classes + l.n) + (i*l.n + best_index) * l.coords; + int tbox_index = truth_index + 1 + l.classes; + + box out = float_to_box(l.output + box_index, 1); + out.x /= l.side; + out.y /= l.side; + if (l.sqrt) { + out.w = out.w*out.w; + out.h = out.h*out.h; + } + float iou = box_iou(out, truth); + + //printf("%d,", best_index); + int p_index = index + locations*l.classes + i*l.n + best_index; + *(l.cost) -= l.noobject_scale * pow(l.output[p_index], 2); + *(l.cost) += l.object_scale * pow(1-l.output[p_index], 2); + avg_obj += l.output[p_index]; + l.delta[p_index] = l.object_scale * (1.-l.output[p_index]); + + if(l.rescore){ + l.delta[p_index] = l.object_scale * (iou - l.output[p_index]); + } + + l.delta[box_index+0] = l.coord_scale*(net.truth[tbox_index + 0] - l.output[box_index + 0]); + l.delta[box_index+1] = l.coord_scale*(net.truth[tbox_index + 1] - l.output[box_index + 1]); + l.delta[box_index+2] = l.coord_scale*(net.truth[tbox_index + 2] - l.output[box_index + 2]); + l.delta[box_index+3] = l.coord_scale*(net.truth[tbox_index + 3] - l.output[box_index + 3]); + if(l.sqrt){ + l.delta[box_index+2] = l.coord_scale*(sqrt(net.truth[tbox_index + 2]) - l.output[box_index + 2]); + l.delta[box_index+3] = l.coord_scale*(sqrt(net.truth[tbox_index + 3]) - l.output[box_index + 3]); + } + + *(l.cost) += pow(1-iou, 2); + avg_iou += iou; + ++count; + } + } + + if(0){ + float *costs = calloc(l.batch*locations*l.n, sizeof(float)); + for (b = 0; b < l.batch; ++b) { + int index = b*l.inputs; + for (i = 0; i < locations; ++i) { + for (j = 0; j < l.n; ++j) { + int p_index = index + locations*l.classes + i*l.n + j; + costs[b*locations*l.n + i*l.n + j] = l.delta[p_index]*l.delta[p_index]; + } + } + } + int indexes[100]; + top_k(costs, l.batch*locations*l.n, 100, indexes); + float cutoff = costs[indexes[99]]; + for (b = 0; b < l.batch; ++b) { + int index = b*l.inputs; + for (i = 0; i < locations; ++i) { + for (j = 0; j < l.n; ++j) { + int p_index = index + locations*l.classes + i*l.n + j; + if (l.delta[p_index]*l.delta[p_index] < cutoff) l.delta[p_index] = 0; + } + } + } + if (costs) { + free(costs); + costs = NULL; + } + } + + + *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2); + + + printf("Detection Avg IOU: %f, Pos Cat: %f, All Cat: %f, Pos Obj: %f, Any Obj: %f, count: %d\n", avg_iou/count, avg_cat/count, avg_allcat/(count*l.classes), avg_obj/count, avg_anyobj/(l.batch*locations*l.n), count); + //if(l.reorg) reorg(l.delta, l.w*l.h, size*l.n, l.batch, 0); + } +} + +void backward_detection_layer(const detection_layer l, network net) +{ + axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); +} + +void get_detection_detections(layer l, int w, int h, float thresh, detection *dets) +{ + int i,j,n; + float *predictions = l.output; + //int per_cell = 5*num+classes; + for (i = 0; i < l.side*l.side; ++i){ + int row = i / l.side; + int col = i % l.side; + for(n = 0; n < l.n; ++n){ + int index = i*l.n + n; + int p_index = l.side*l.side*l.classes + i*l.n + n; + float scale = predictions[p_index]; + int box_index = l.side*l.side*(l.classes + l.n) + (i*l.n + n)*4; + box b; + b.x = (predictions[box_index + 0] + col) / l.side * w; + b.y = (predictions[box_index + 1] + row) / l.side * h; + b.w = pow(predictions[box_index + 2], (l.sqrt?2:1)) * w; + b.h = pow(predictions[box_index + 3], (l.sqrt?2:1)) * h; + dets[index].bbox = b; + dets[index].objectness = scale; + for(j = 0; j < l.classes; ++j){ + int class_index = i*l.classes; + float prob = scale*predictions[class_index+j]; + dets[index].prob[j] = (prob > thresh) ? prob : 0; + } + } + } +} + +#ifdef GPU + +void forward_detection_layer_gpu(const detection_layer l, network net) +{ + if(!net.train){ + copy_gpu(l.batch*l.inputs, net.input_gpu, 1, l.output_gpu, 1); + return; + } + + cuda_pull_array(net.input_gpu, net.input, l.batch*l.inputs); + forward_detection_layer(l, net); + cuda_push_array(l.output_gpu, l.output, l.batch*l.outputs); + cuda_push_array(l.delta_gpu, l.delta, l.batch*l.inputs); +} + +void backward_detection_layer_gpu(detection_layer l, network net) +{ + axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1); + //copy_gpu(l.batch*l.inputs, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif + diff --git a/src/detection_layer.h b/src/detection_layer.h new file mode 100644 index 0000000..1a9ef19 --- /dev/null +++ b/src/detection_layer.h @@ -0,0 +1,19 @@ +#pragma once +#ifndef DETECTION_LAYER_H +#define DETECTION_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" + +typedef layer detection_layer; + +detection_layer make_detection_layer(int batch, int inputs, int n, int size, int classes, int coords, int rescore); +void forward_detection_layer(const detection_layer l, network net); +void backward_detection_layer(const detection_layer l, network net); + +#ifdef GPU +void forward_detection_layer_gpu(const detection_layer l, network net); +void backward_detection_layer_gpu(detection_layer l, network net); +#endif + +#endif diff --git a/src/detector.c b/src/detector.c new file mode 100644 index 0000000..dc42137 --- /dev/null +++ b/src/detector.c @@ -0,0 +1,31830 @@ + +#include "darknet.h" +#include "utils.h" +#include "demo.h" +#include "blas.h" +#include "option_list.h" +#include "setting.h" +#include "utility.h" +#include "libgen.h" +#include "iniReader.h" +#include "network.h" +#include "cJSON.h" +#include "cryptionPlus.h" +#include "nweb.h" +#include "gettest.h" +#include "test_nnctrl_live.h" +#include "fflpr_plate_db.h" +#ifdef GY_OS_AMBA +//#include "websocket_client.h" +#endif +#include "url_encode.h" +#ifdef GY_OS_AMBA +//#include "tof.h" +#include "ptz.h" +#endif +#include "cold_zone.h" +#include "cgicmd.h" +#include <mcheck.h> +#include "pns.h" +#include <netinet/tcp.h> +#include "fork_pipe_lib.h" +#include <errno.h> +#include <time.h> +#include "net_curl.h" +#include <pythonR.h> +#include "structures.h" + +#if defined GY_OS_AMBA +#include "ir_control.h" +#endif + +#ifdef GY_OS_AMBA +#include "send_osd_data.h" + +//#include "radar.h" +//#include "radar_driver.h" +//#include "radar_receive.h" +//#include "radar_parser.h" +#include "cv_point_transform.hpp" +//#include "cv_point_transform.h" +#include "cv.h" +//#include "face_parser.h" +#include "levenshtein.h" +#endif + + +///Steven MARK TEMP +//#include "zlog.h" +//===================== +//sophia add 2020/09/24 +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include "alm_queue.h" +#endif +//===================== + +#include <pthread.h> +#include <math.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#include <unistd.h> + +#include <curl/curl.h> +#include <curl/easy.h> +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif + +#include "onvif_data.h" +#include "anpr_rule.h" + +//pthread_mutex_t mutex_tcp_layer[MAX_LAYER_NUM]; +//pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; +//pthread_mutex_t mutex_post_notification; +//pthread_mutex_t mutex_post_notification_push; +pthread_mutex_t mutex_post_notification_pop; +pthread_mutex_t mutex_getalarmmotion; +pthread_mutex_t mutex_alm; +pthread_mutex_t mutex_curl; +pthread_mutex_t mutex_dn; +pthread_mutex_t mutex_websocket; +pthread_mutex_t mutex_enable_lpr_db; +#ifdef GY_OS_AMBA +pthread_mutex_t mutex_enable_face_db; +#endif +pthread_mutex_t mutex_username; +pthread_mutex_t mutex_pns; +pthread_mutex_t mutex_snap; +//pthread_mutex_t mutex_get_canvas; +//pthread_mutex_t mutex_cropped_roi; +pthread_mutex_t mutex_config_json; +#if defined GY_OS_AMBA +//pthread_mutex_t mutex_jvc_config_json; +#endif +pthread_mutex_t mutex_events_json; +pthread_mutex_t mutex_web; +pthread_mutex_t mutex_http_connection_handler; +pthread_mutex_t mutex_base64; +pthread_mutex_t mutex_run_one_net; +#ifdef GY_OS_NOVA +//pthread_mutex_t mutex_run_parse_json; +#endif +pthread_mutex_t mutex_send_jpeg; +pthread_mutex_t mutex_heatmap_jpeg; +//pthread_mutex_t mutex_strsplit; +#ifdef GY_OS_AMBA +pthread_mutex_t mutex_perspective_transform; +#endif +//pthread_mutex_t mutex_snap_hd_image; +pthread_mutex_t mutex_snap_image; +pthread_mutex_t mutex_get_image; +pthread_mutex_t mutex_get_image_HD; + +pthread_mutex_t mutex_if_enable_lpr_db_is_Yes; +pthread_mutex_t mutex_get_network_input; +pthread_mutex_t mutex_differ_image; + +pthread_mutex_t mutex_run_one_net_anpr; + +pthread_mutex_t mutex_check_license; +pthread_mutex_t mutex_read_ipcam; + +pthread_mutex_t mutex_update_candidate; +pthread_mutex_t mutex_send_cgi; + +//pthread_mutex_t mutex_parse_bbox; + +pthread_mutex_t mutex_compute_median; +//pthread_mutex_t mutex_long_term; +//pthread_mutex_t mutex_short_term; + +//pthread_mutex_t mutex_long_term_yuv; +//pthread_mutex_t mutex_short_term_yuv; + +pthread_mutex_t mutex_set_http_request; +pthread_mutex_t mutex_reset_counter; + +#ifdef GY_OS_AMBA + +pthread_mutex_t mutex_get_depth; +//pthread_mutex_t mutex_tof_data; +pthread_mutex_t mutex_write_pcd_data; +pthread_mutex_t mutex_write_pcd_data_L; +pthread_mutex_t mutex_write_pcd_data_M; +pthread_mutex_t mutex_write_pcd_data_S; + + +pthread_mutex_t mutex_remotesnap_image; // Ken 2022-09-26 +pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 +pthread_mutex_t mutex_tof_json; // Ken 2022-12-13 +pthread_mutex_t mutex_buffer; // Ming 2022-08-28 +pthread_mutex_t mutex_run_osd; +#endif + +#ifdef GY_OS_NOVA +pthread_mutex_t mutex_pre_bbox_receive; +pthread_mutex_t mutex_pre_connection; +pthread_mutex_t mutex_pre_image_receive; +#endif + +//pthread_mutex_t mutex_color_detect; + +int g_match_mac = 0; +char g_mac_address[256] = { 0 }; + +int g_sdk_version = -1; + +int g_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +int g_temp_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +float g_parking_space_recording_x[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +float g_parking_space_recording_y[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +time_t g_parking_space_update_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +time_t g_parking_space_status_change_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; + +long g_osdSysTimeStamp = 0; +int check_if_run_post = -1; +int check_if_correct_post = 0; + +int check_if_start_run_server = 0; +char record_process_note[MAX_RECORD_PROCESS][MAX_PROCESS_LENGTH] = { 0 }; +int current_index_record = 0; +int size_record_process_note = 0; + +//http server parameters +SocketInfo socketRecords[MAX_CLIENT_SOCKET] = { 0 }; +ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW] = { 0 }; +DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE] = { 0 }; +SystemSettingInfo SystemSetting; +PostEventInfo postEventList[MAX_POST_EVENTS] = { 0 }; +#ifdef GY_OS_V_SERIES + +#else +EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS] = { 0 }; +ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS] = { 0 }; +SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT] = { 0 }; +#endif + +AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM] = { 0 }; //20201027 sophia add +IPCAMServiceInfo IPCAMService; +SnapHDInfo snapHDList[MAX_SNAP_HD_LIST] = { 0 }; +EmailInfo emailData; +WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST] = { 0 }; +char WeightFileModeName[35] = { 0 }; +HeartbeatInfo heartbeatData; +#ifdef GY_OS_AMBA +TofInfo tofData; +#endif + +//int g_check_if_set_no_preset_no_autopan = 0; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER] = {0}; +#endif +ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER] = { 0 }; +PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; +PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + +//MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA] = { 0 }; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +ImageDn imageDnData; +#endif +#ifdef GY_OS_AMBA +OSDInfo OSDData[MAX_SIZE_OSD_ARRAY] = { 0 }; +SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY] = { 0 }; +#endif +int g_PlateFilterTimes; //Times +int g_PlateFilterTime; //Second +int g_PlateRecorderFreeTime; //Second + +struct tm *cgi_reload_start_Time; +struct tm *cgi_startTime_buff; +struct tm *cgi_whenTime_buff; + +struct amba_content stAMBAcontent; + +static int protected_sqlite_fflpr_db_close = 0; + +int g_check_ping_OK = 1; + +int g_check_if_no_brand = 0; + +//static unsigned char g_snapshot_addr_to_post[MAX_IMG_SIZE] = { 0 }; + +int g_control_read_ipcam = 0; +#ifdef GY_OS_AMBA +int g_sensors_type = 1;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 +#endif +#ifdef GY_OS_NOVA +int g_sensors_type = 1;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 +#endif +int g_max_sensor_size = MAX_SENSOR_TYPE0; + +int g_IsRadarDevice = 0; +int g_IsPTZDevice = 0; +int g_IsRadarFake = 0; +int g_check_if_OK_thermal = 0; + +int unlockingKeyInnoFR = 0; +int unlockingKeyInnoFR_success = 0; +#ifdef GY_OS_AMBA +char radar_json_data[4096]; +#endif +int g_check_if_OK_to_start_osd_server = 0; + +int g_IsSDK_3_0 = 0; +int g_IsToFDevice = 0; +int g_IsCustomWeight = 0; +int g_IsHelm_without_car = 0; + +float g_thres_bbox_stability = 0.02;//0.02 0.1 +float g_thres_bbox_stability_plate = 0.01; +float g_thres_bbox_stability_predict = 0.32; + +float g_initial_background_learning_rate_x = 0.5; +float g_initial_background_learning_rate_y = 0.5; +float g_initial_background_learning_rate_error_x = 0.0; +float g_initial_background_learning_rate_error_y = 0.0; + +float g_initial_background_mean_diff_x = 0.0; +float g_initial_background_mean_diff_y = 0.0; +float g_initial_background_error_diff_x = 0.0; +float g_initial_background_error_diff_y = 0.0; + +int g_check_current_resolution = 1; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +cJSON *g_config_root = NULL; +char* get_enable_python_file_value(const char *filename); +#endif + +/*typedef struct { + network net; + layer layer; + char *datacfg; + char *cfgfile; + char *weightfile; + float nms; + float thresh; + float hier_thresh; + int dont_show; + int ext_output; + int save_labels; +} NetworkInfo;*/ + +/*typedef struct { + NetworkInfo networkLayer[2]; + int layerCount; + char **alphabet; + ServerType serverType; + LicenseType licenseType; + AuthFailStatusCode afsCode; + unsigned int featureType; +} NetworkPool;*/ + +//static int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90}; + +short td_weight_num = 0; +ThirdPartyWeight td_weight_info[MAX_LAYER_NUM]; + +//CURLM* g_multi_handle; +//int g_handle_count; +CURL* g_http_handle = NULL; + +bool isGYNetReady; + +extern int reload_dataset_from_jsonfile(void); +//extern int default_dataset_for_jsonfile(void); + +//#define DISAPPEAR_FRAME_MAX 8 +static int DISAPPEAR_FRAME_MAX = 8; + +void set_DISAPPEAR_FRAME_MAX(int disappear_frame_max_temp) { + DISAPPEAR_FRAME_MAX = disappear_frame_max_temp; +} + +void setPthreadName(char *p_name) +{ + if (p_name != NULL) + { + (void)prctl(PR_SET_NAME, (unsigned long)p_name);//lname ̦h16?r + } +} + +//static NetworkPool networkPool[MAX_NETWORK_POOL_NUM]; +//static int layer_count; +static int dont_show; +static int show; +static int tcp_port; +//static char *out_filename; +//static char *outfile; +//static char *prefix; +static float thresh; +static float hier_thresh; +static int cam_index; +static int frame_skip; +static int num_of_clusters; +static int yuv_width; +static int yuv_height; +static int ext_output; +static int save_labels; +static int http_port; +//static char* unlocking_key; + +static int gpu_idx; +//static char* c_cnn_type; + +pthread_t http_thread; +#ifdef GY_OS_NOVA +pthread_t http_thread_parse_json_data; +pthread_t http_thread_pre_image_receive; +#endif +pthread_t post_notification_thread; +pthread_t runpython_thread; +pthread_t getalarmmotion_thread; + +pthread_t delete_jpg_in_seven_days_detector_thread_id; +pthread_t send_udp_thread; +pthread_t test_nnctrl_live_thread; + +pthread_t fps_loading_thread; + +pthread_t getimage_thread; + +pthread_t resolution_changed_thread; + +#ifdef GY_OS_V_SERIES + +#else +pthread_t counter_thread; +#endif + +#ifdef GY_OS_AMBA +pthread_t getimage_hd_thread; +pthread_t gettofdata_thread; + +pthread_t getstream_thread; +pthread_t get_face_websocket_thread; +pthread_t parse_face_thread; +pthread_t radar_reciever_id; +pthread_t render_radar_thread; +pthread_t radar_parser_thread; +pthread_t thread_id_run_osd_server; +#endif +#ifdef GY_OS_NOVA +pthread_t thread_id_get_nova_driver; +#endif +//pthread_t thread_id_run_system_time_sync; +static int check_if_is_existing_weight = 0; + +float overlap_ratio_limit; +extern float confidence_limit; + +int input_resizable; +char* custom_cpu_library; +char* custom_cldnn; +int performance_counter; + +static CNNType cnn_type; +//static image **alphabet=NULL; +//static network nets[MAX_LAYER_NUM]; +//static layer layers[MAX_LAYER_NUM]; +//static list *options[MAX_LAYER_NUM]; +//static char *name_list[MAX_LAYER_NUM]; +//static char **names[MAX_LAYER_NUM]; +//static network net2; +//static layer L2; +//static list *options2; +//static char *name_list2; +//static char **names2; +//static float nms[MAX_LAYER_NUM]; +//static float nms2; +//ini +static char ppIniKeyValue[MAX_LAYER_NUM][MAX_SECTION_VARIABLE][50] = { 0 }; +//http server parameters +//static CNNType http_cnn_type; +//static network http_nets[MAX_LAYER_NUM]; +//static network http_net2; +//static char **http_names[MAX_LAYER_NUM]; +//static char **http_names2; +//static image **http_alphabet; +//static float http_nms[MAX_LAYER_NUM]; +//static float http_nms2; +//static float http_thresh; +//static float http_hier_thresh; +//static int http_dont_show; +//static int http_ext_output; +//static int http_save_labels; +//static char *http_ip_address; +//static char *http_mac_address; +//static int http_http_port; +//static int http_layer_count; +//static char http_dataset_version; +//static LicenseType http_licenseType; +//static LicenseType http_advLicenseType; +//static AuthFailStatusCode http_afsCode; +//static size_t http_featureType; +static size_t layerFeatureType[MAX_LAYER_NUM] = { 0 }; +static size_t layerFeatureType2[MAX_LAYER_NUM] = { 0 }; +//static char* layerUTF8Country[MAX_LAYER_NUM]; +static char strLicenseType[MAX_MSG_LEN] = { 0 }; +char strLicenseStatus[MAX_MSG_LEN] = { 0 }; +char strUnlockingKey[MAX_MSG_LEN] = { 0 }; +int bHttpServerThreadStart = 0; +double http_license_fps; +int http_sleep_interval = 2; + +int bPreloadHttpServerThreadStart = 0; + +//#ifdef GY_OS_WIN +//static char msgText[MAX_MSG_LEN]; +//#elif _DEBUG_AMBA +//static char msgText[MAX_MSG_LEN]; +//#endif + +int nIsCompatibleCPU = 0; +int nIsCompatibleGPU = 0; +int nIsCompatibleVPU = 0; +int nIsHardwareOK = 1; + +size_t featureType; +size_t featureType2; +size_t advancedType; + +CPoint trafficLightPoint = { 0 }; +int traffic_light_zone_width = 0; +int traffic_light_zone_height = 0; + +LicenseType licenseType; +AdvanceLicenseType advLicenseType; +AuthFailStatusCode afsCode; +HttpCode httpCode; + +MYBOOL activeDisplayDash; +MYBOOL activeDisplayProperties; +MYBOOL activePostNotification; +MYBOOL activeSNMPPost; +MYBOOL testPostNotification; + +char g_device_name[512] = { 0 }; + +int check_if_correct_mail = 0; +int check_if_fe_fail = 0; + +int g_enable_person_for_metadata[MAX_DETECTION_ZONE] = { 0 }; + +//struct amba_content stAMBAcontent; + +int protect_set_record_process_note = 0; +void set_record_process_note(char *process_note) { + if (check_if_start_run_server == 1 && protect_set_record_process_note == 0) { + protect_set_record_process_note = 1; + memset(record_process_note[current_index_record], 0x00, sizeof(record_process_note[current_index_record])); + snprintf(record_process_note[current_index_record], sizeof(record_process_note[current_index_record]), "%s", process_note); + + current_index_record++; + if (current_index_record >= MAX_RECORD_PROCESS) { + current_index_record = 0; + } + + if (size_record_process_note < MAX_RECORD_PROCESS) { + size_record_process_note++; + } + protect_set_record_process_note = 0; + } +} + +void record_process_note_write_to_log() { + if (check_if_start_run_server == 0) { + + char temp_msg[8192] = { 0 }; + for (int count_record = size_record_process_note - 1; count_record >= 0; count_record--) { + int index_record = current_index_record - 1 - count_record; + if (index_record < 0) { + index_record += size_record_process_note; + } + + if (count_record == 0) { + char temp_temp_msg[8192] = { 0 }; + snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s", record_process_note[index_record]); + } + else { + if (count_record == size_record_process_note - 1) { + char temp_temp_msg[8192] = { 0 }; + snprintf(temp_temp_msg, sizeof(temp_temp_msg), "free:%d,%s,", get_free_mem_data(), record_process_note[index_record]); + strcpy(temp_msg, temp_temp_msg); + } + else { + char temp_temp_msg[8192] = { 0 }; + snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s,", record_process_note[index_record]); + strcat(temp_msg, temp_temp_msg); + } + } + } + write_to_logs_html(temp_msg, "record process", "ERROR", "Yes"); + } +} + + +int get_check_if_correct_mail() { + return check_if_correct_mail; +} +#ifdef GY_OS_NOVA +void *thread_get_nova_driver(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("start nova driver"); + usSleep(12000000); + while (bHttpServerThreadStart) + { + start_nova_driver(); + usSleep(3000000); + } + pthread_exit(NULL); +} +#endif +void *thread_getimage(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("getimage"); + while (bHttpServerThreadStart) + { + //printf("\n---------thread getimage start\n"); + if (atoi(SystemSetting.getimage_encoder_id) - 1 >= 0) { + get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id) - 1, 1); + }else if(unlockingKeyInnoFR_success == 1){ + get_snap_with_profile_id(0, 1); + } + //printf("\n---------thread getimage end\n"); + usSleep(3000000); + } + pthread_exit(NULL); +} + +void *thread_getimage_hd(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("getimage_hd"); + while (bHttpServerThreadStart) + { + if (atoi(SystemSetting.getimage_encoder_id_HD) - 1 >= 0 && atoi(SystemSetting.getimage_encoder_id_HD) != atoi(SystemSetting.getimage_encoder_id)) { + get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id_HD) - 1, 0); + } + usSleep(3000000); + } + pthread_exit(NULL); +} + +void *run_http_server_thread(void *ptr) +{ + //printf("[run http server thread]Pthread started and detached. No new addr.\n"); + pthread_detach(pthread_self()); + + setPthreadName("run_http"); + +//#ifdef _DEBUG_AMBA + //printf("\n[run_http_server_thread] start\n"); +//#endif + + bHttpServerThreadStart = 1; + + while (bHttpServerThreadStart) + { + bHttpServerMainStart = 1; + + run_http_server("", zc, cnn_type/*, layer_count, http_nets, names, alphabet, nms*/, thresh, hier_thresh, dont_show, ext_output, save_labels, NULL, NULL, http_port, licenseType, advLicenseType, afsCode, layerFeatureType, strLicenseType); + + //printf("\n[run http server thread] in while bHttpServerThreadStart-1 bHttpServerThreadStart:%d\n", bHttpServerThreadStart); + //printf("\n[run http server thread] in while bHttpServerThreadStart-2 :%d\n", bHttpServerThreadStart); + //printf("\nerr_count: %u\n",err_count); + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + usSleep(1000); + } + //printf("\n[run http server thread] while out :%d\n", bHttpServerThreadStart); + + bHttpServerThreadStart = 0; + bHttpServerMainStart = 0; + + //printf("\n-----------run http server thread:exit\n"); + + //20201014 - sophia add for restart + pthread_exit(NULL); +} + +extern int run_preload_http_server(int http_port); +void *run_preload_http_server_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_preload"); + + +#if 1 + + bPreloadHttpServerThreadStart = 1; + + while (bPreloadHttpServerThreadStart) + { + bPreloadHttpServerMainStart = 1; +#if 1 + run_preload_http_server(http_port); +#endif + bPreloadHttpServerThreadStart = 0; + + //printf("\n**********************\n"); + //printf("preload server close"); + //printf("\n**********************\n"); + + usSleep(100000); + } + + bPreloadHttpServerThreadStart = 0; + bPreloadHttpServerMainStart = 0; + +#endif + + //20210617-Steven add for preload + + + + pthread_exit(NULL); +} + +#ifdef GY_OS_V_SERIES + +#else +void reset_counter(int index_counter, time_t now_time) +{ + time_t ori_now_time = now_time; + struct tm *nowTime = localtime(&now_time); + int current_year = nowTime->tm_year + 1900; + int current_month = nowTime->tm_mon + 1; + int current_month_day = nowTime->tm_mday; + int current_week_day = nowTime->tm_wday + 1; + int current_hour = nowTime->tm_hour; + int current_min = nowTime->tm_min; + int current_sec = nowTime->tm_sec; + + if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 minute") == 0) + { + nowTime->tm_min = nowTime->tm_min + 1; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "5 minutes") == 0) + { + nowTime->tm_min = nowTime->tm_min + 5; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "30 minutes") == 0) + { + nowTime->tm_min = nowTime->tm_min + 30; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 hour") == 0) + { + nowTime->tm_hour = nowTime->tm_hour + 1; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 day") == 0) + { + nowTime->tm_mday = nowTime->tm_mday + 1; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 week") == 0) + { + + nowTime->tm_mday = nowTime->tm_mday + 7; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 month") == 0) + { + nowTime->tm_mon = nowTime->tm_mon + 1; + } + + time_t next_time = mktime(nowTime); + + int next_year = current_year; + int next_month = current_month; + int next_month_day = current_month_day; + int next_week_day = current_week_day; + int next_hour = current_hour; + int next_min = current_min; + int next_sec = current_sec; + + if (next_time != -1) { + struct tm *nextTime = localtime(&next_time); + next_year = nextTime->tm_year + 1900; + next_month = nextTime->tm_mon + 1; + next_month_day = nextTime->tm_mday; + next_week_day = nextTime->tm_wday + 1; + next_hour = nextTime->tm_hour; + next_min = nextTime->tm_min; + next_sec = nextTime->tm_sec; + } + else { + next_time = ori_now_time; + } + + struct tm * gmtTime = gmtime(&next_time); + int gmt_year = gmtTime->tm_year + 1900; + int gmt_month = gmtTime->tm_mon + 1; + int gmt_month_day = gmtTime->tm_mday; + int gmt_week_day = gmtTime->tm_wday + 1; + int gmt_hour = gmtTime->tm_hour; + int gmt_min = gmtTime->tm_min; + int gmt_sec = gmtTime->tm_sec; + + eventCounterList[index_counter].reset_year = current_year; + eventCounterList[index_counter].reset_month = current_month; + eventCounterList[index_counter].reset_month_day = current_month_day; + eventCounterList[index_counter].reset_week_day = current_week_day; + eventCounterList[index_counter].reset_hour = current_hour; + eventCounterList[index_counter].reset_min = current_min; + eventCounterList[index_counter].reset_sec = current_sec; + + eventCounterList[index_counter].gmt_year = gmt_year; + eventCounterList[index_counter].gmt_month = gmt_month; + eventCounterList[index_counter].gmt_month_day = gmt_month_day; + eventCounterList[index_counter].gmt_week_day = gmt_week_day; + eventCounterList[index_counter].gmt_hour = gmt_hour; + eventCounterList[index_counter].gmt_min = gmt_min; + eventCounterList[index_counter].gmt_sec = gmt_sec; + + eventCounterList[index_counter].next_year = next_year; + eventCounterList[index_counter].next_month = next_month; + eventCounterList[index_counter].next_month_day = next_month_day; + eventCounterList[index_counter].next_week_day = next_week_day; + eventCounterList[index_counter].next_hour = next_hour; + eventCounterList[index_counter].next_min = next_min; + eventCounterList[index_counter].next_sec = next_sec; + + eventCounterList[index_counter].timetResetAt = ori_now_time; + eventCounterList[index_counter].next_timetResetAt = next_time; + + time_t temp_next_time = next_time; + time_t temp_gmt_time = mktime(gmtTime); + if (temp_gmt_time != -1) { + double dTime = 0.0; + char sign_of_dtime[2] = { 0 }; + if (temp_next_time > temp_gmt_time) { + dTime = difftime(temp_next_time, temp_gmt_time); + strcpy(sign_of_dtime,"+"); + } + else if (temp_next_time < temp_gmt_time) { + dTime = difftime(temp_gmt_time, temp_next_time); + strcpy(sign_of_dtime, "-"); + } + else { + strcpy(sign_of_dtime, "+"); + } + + int iHour = (int)(dTime / 60.0 / 60.0); + int iMin = (int)((dTime - (double)iHour * 60.0 * 60.0) / 60.0); + + char ResetTime[50] = { 0 }; + sprintf(ResetTime,"%02d:%02d:%02d%s%02d:%02d", gmt_hour, gmt_min, gmt_sec, sign_of_dtime, iHour, iMin); + + strcpy(eventCounterList[index_counter].ResetTime, ResetTime); + } + else { + strcpy(eventCounterList[index_counter].ResetTime, ""); + } + + eventCounterList[index_counter].counter_count = eventCounterList[index_counter].reset_value; + eventCounterList[index_counter].already_reset = 1; + + //printf("\nreset time:%04d-%02d-%02dT%02d:%02d:%02d\n" + //, eventCounterList[index_counter].reset_year + //, eventCounterList[index_counter].reset_month + //, eventCounterList[index_counter].reset_month_day + //, eventCounterList[index_counter].reset_hour + //, eventCounterList[index_counter].reset_min + //, eventCounterList[index_counter].reset_sec + //); + + //printf("\nnext time:%04d-%02d-%02dT%02d:%02d:%02d\n" + // , eventCounterList[index_counter].next_year + // , eventCounterList[index_counter].next_month + // , eventCounterList[index_counter].next_month_day + // , eventCounterList[index_counter].next_hour + // , eventCounterList[index_counter].next_min + // , eventCounterList[index_counter].next_sec + //); +} + +void set_counter_zone() { + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + eventCounterList[j].counter_zone = 0; + } + + int tracking_channel_idx = 0; + int base_zone = 1; + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + if (index_zone >= 1) { + base_zone = base_zone * 2; + } + + for (int trigger_idx = 0; trigger_idx < MAX_TRIGGER_EVENT; trigger_idx++) + { + if (viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].detect_event_id); + + if (trigger_event_type == TRIGGER_GO_STRAIGHT || + trigger_event_type == TRIGGER_QUEUING_VIOLATION) + { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + + for (int index_event_counter = 0; index_event_counter < event_counter_num; index_event_counter++) + { + for (int index_event_list = 0; index_event_list < MAX_EVENT_COUNTERS; index_event_list++) + { + if (strlen(eachEventCounter[index_event_counter]) >= 1 && strcmp(eachEventCounter[index_event_counter], eventCounterList[index_event_list].counter_name) == 0) + { + eventCounterList[index_event_list].counter_zone += base_zone; + break; + } + } + } + + } + + break; + } + } + } + +} + +int g_last_hour_for_counter_mail = -1; +void run_counter_mail(char * mail_content,int mail_content_size) { + if (strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") != 0 && strlen(SystemSetting.send_counter_at_specific_hour) >= 1) + { + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + struct tm *local_time = localtime(&now_time); + int current_hour = local_time->tm_hour; + + if (g_last_hour_for_counter_mail == -1 || g_last_hour_for_counter_mail < current_hour || (g_last_hour_for_counter_mail == 23 && current_hour == 0)) + { + int object_hour = atoi(SystemSetting.send_counter_at_specific_hour); + if (current_hour == object_hour) + { + if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0)) + { + QueueInfo q_info = { 0 }; + q_info.image_buff_size = 0; + + memcpy(q_info.content, mail_content, mail_content_size); + q_info.content[mail_content_size] = '\0'; + + strcpy(q_info.post_url, "post_to_mail"); + + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcpy(q_info.behavior_desc, "\xe8\xa8\x88\xe6\x95\xb8\xe5\x99\xa8\xe6\x95\xb8\xe5\x80\xbc");//pƾƭ + else//en_gb + strcpy(q_info.behavior_desc, "Counter value");//pƾƭ + + QueuePush(q_info, _POST_NOTIFICATION); + + pthread_mutex_lock(&mutex_reset_counter); + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + + g_last_hour_for_counter_mail = current_hour; + } + } + } + } +} + +#endif + + + +//쥻W٬Ocheck_http_socket_threadA{b令run_event_counter_thread +void *run_event_counter_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_counter"); +#ifdef GY_OS_V_SERIES + +#else + //printf("\n[run event counter thread]pthread create\n"); + + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + struct tm *nowTime = localtime(&now_time); + //int reset_year = nowTime->tm_year + 1900; + int reset_month = nowTime->tm_mon + 1; + int reset_month_day = nowTime->tm_mday; + int reset_week_day = nowTime->tm_wday + 1; + int reset_hour = nowTime->tm_hour; + int reset_min = nowTime->tm_min; + //int reset_sec = nowTime->tm_sec; + + //struct tm * gmtTime = gmtime(&now_time); + //int gmt_year = gmtTime->tm_year + 1900; + //int gmt_month = gmtTime->tm_mon + 1; + //int gmt_month_day = gmtTime->tm_mday; + //int gmt_week_day = gmtTime->tm_wday + 1; + //int gmt_hour = gmtTime->tm_hour; + //int gmt_min = gmtTime->tm_min; + //int gmt_sec = gmtTime->tm_sec; + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + + set_counter_zone(); + + while (bHttpServerThreadStart) + { + //printf("\n-----run event counter thread start\n"); + //if (strcmp(eventCounterList[j].enable_reset_only_cloud, "No") == 0) + if (//(strcmp(SystemSetting.cloud_enable_notification, "No") == 0) && + (strcmp(SystemSetting.enable_email_notification, "No") == 0 || + (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && Get_mail_post_interval() == -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0)) + ) + { + set_record_process_note("counter_start"); + now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + nowTime = localtime(&now_time); + //int current_year = nowTime->tm_year + 1900; + int current_month = nowTime->tm_mon + 1; + int current_month_day = nowTime->tm_mday; + int current_week_day = nowTime->tm_wday + 1; + int current_hour = nowTime->tm_hour; + int current_min = nowTime->tm_min; + int current_sec = nowTime->tm_sec; + +#if 1 + pthread_mutex_lock(&mutex_reset_counter); + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + //reset_year = eventCounterList[j].reset_year; + reset_month = eventCounterList[j].reset_month; + reset_month_day = eventCounterList[j].reset_month_day; + reset_week_day = eventCounterList[j].reset_week_day; + reset_hour = eventCounterList[j].reset_hour; + reset_min = eventCounterList[j].reset_min; + //reset_sec = eventCounterList[j].reset_sec; + + //gmt_year = eventCounterList[j].gmt_year; + //gmt_month = eventCounterList[j].gmt_month; + //gmt_month_day = eventCounterList[j].gmt_month_day; + //gmt_week_day = eventCounterList[j].gmt_week_day; + //gmt_hour = eventCounterList[j].gmt_hour; + //gmt_min = eventCounterList[j].gmt_min; + //gmt_sec = eventCounterList[j].gmt_sec; + + if (strcmp(eventCounterList[j].enable_reset_time_interval, "Yes") == 0) + { + if (strcmp(eventCounterList[j].reset_time_interval, "1 minute") == 0) + { + eventCounterList[j].dwell_time = current_sec; + strcpy(eventCounterList[j].dwell_unit, "sec"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1S"); + + if (eventCounterList[j].already_reset == 1 && current_sec >= 30) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_sec < 30 && current_min != reset_min) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "5 minutes") == 0) + { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + + if (eventCounterList[j].already_reset == 1 && current_min % 5 != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_min % 5 == 0 && current_min != reset_min) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "30 minutes") == 0) + { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + + if (eventCounterList[j].already_reset == 1 && current_min % 30 != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_min % 30 == 0 && current_min != reset_min) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 hour") == 0) + { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + + if (eventCounterList[j].already_reset == 1 && current_min != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_min == 0 && current_hour != reset_hour) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 day") == 0) + { + eventCounterList[j].dwell_time = current_hour; + strcpy(eventCounterList[j].dwell_unit, "hour"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1H"); + + if (eventCounterList[j].already_reset == 1 && current_hour % 24 != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_hour % 24 == 0 && current_week_day != reset_week_day) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 week") == 0) + { + eventCounterList[j].dwell_time = current_week_day; + strcpy(eventCounterList[j].dwell_unit, "wday"); + strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); + + if (eventCounterList[j].already_reset == 1 && current_week_day != 1) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_month == 1 && current_month_day != reset_month_day) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 month") == 0) + { + eventCounterList[j].dwell_time = current_month_day; + strcpy(eventCounterList[j].dwell_unit, "mday"); + strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); + + if (eventCounterList[j].already_reset == 1 && current_month_day != 1) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_month_day == 1 && current_month != reset_month) + { + reset_counter(j, now_time); + } + } + else { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + } + } + + } + pthread_mutex_unlock(&mutex_reset_counter); +#endif + set_record_process_note("counter_end"); + usSleep(1000000); + } + else { + usSleep(5000000); + } + //printf("\n-----run event counter thread end\n"); + } + //printf("\n[run event counter thread] end\n"); +#endif + pthread_exit(NULL); +} + +struct timeval currtime_control_alarm_gpio; +static long last_ms_control_alarm_gpio = 0; +//post the notification back to the origianl socket +void *run_post_notification_thread(void *ptr) +{ + //printf("\n[run post notification thread]pthread create\n"); + + pthread_detach(pthread_self()); + setPthreadName("run_post"); + QueueInfo q_info_copy = { 0 }; + + char sendLargeBuffer[BUFSIZE_V2] = { 0 }; + + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + + int count_g_http_handle = 0; + + unsigned int count_to_refresh_smtp_service = 0; + int count_delay = 0; + + int count_initial_global_curl = 0; + +#ifdef GY_OS_AMBA + int count_ptz = 0; +#endif + + while (bHttpServerThreadStart) + { + //printf("\n-----run post notification start\n"); + set_record_process_note("run_post_start"); + //printf("out que size = %d \n", QueueSize(_POST_NOTIFICATION)); + if (!QueueIsEmpty(_POST_NOTIFICATION) && QueueSize(_POST_NOTIFICATION) >= 1) + { + //printf("\n-----------QueueSize(_POST_NOTIFICATION) = %d \n", QueueSize(_POST_NOTIFICATION)); + // +#if 1 + pthread_mutex_lock(&mutex_post_notification_pop); + q_info_copy = QueueFront(_POST_NOTIFICATION); + + QueuePop(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_post_notification_pop); + + memset(sendLargeBuffer, 0x00, BUFSIZE_V2); + +//AA +#if 1 + //HU----------- + if (strcmp(q_info_copy.post_url,"post_to_cloud")==0) { + + + //printf("\n----------------\n"); + //printf("\nq_info_copy.cloud_aiengine:%s\n", q_info_copy.cloud_aiengine); + //printf("\n----------------\n"); + char behavior_ID_temp[50] = {0}; + sprintf(behavior_ID_temp,"%d", q_info_copy.behavior_ID); + + char behavior_ID_16_temp[50] = { 0 }; + sprintf(behavior_ID_16_temp, "0x%08X", q_info_copy.behavior_ID); + + //printf("\n-------%s\n", behavior_ID_16_temp); + + /* + printf("\n----------------\n"); + printf("\nbehavior_name:%s,behavior_ID_temp:%s,behavior_desc:%s\n", q_info_copy.behavior_name, behavior_ID_temp, q_info_copy.behavior_desc); + printf("\n----------------\n");*/ + //if 0 No PNS_Send_Multipart_POST ̤jW162,000byte +#if 1 + + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Send_Multipart_POST(q_info_copy.cloud_aiengine, q_info_copy.behavior_name, behavior_ID_temp, behavior_ID_16_temp, q_info_copy.behavior_desc, SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/" , returned_msg, q_info_copy.image_buff, q_info_copy.image_buff_size, q_info_copy.rawtime); + strcpy(SystemSetting.cloud_statue,returned_msg); + + + //printf("\n------------Segmentation fault:%d\n",1); + + //PNS_Send_Multipart_POSTO鬪|ӦhAwMzAMz᭫sl + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); +#endif + } + else if (strcmp(q_info_copy.post_url, "post_to_mail") == 0) + { + //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + SendMailEventCondition(q_info_copy.behavior_desc, q_info_copy.content, q_info_copy.image_buff, q_info_copy.image_buff_size); +#endif + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + } + else if (strcmp(q_info_copy.post_url, "curl_to_ftp") == 0) + { + //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); +//#if defined GY_OS_AMBA + net_curl_ftp_post_push_info_attached_image(q_info_copy.image_buff, q_info_copy.image_buff_size); +//#endif + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + } +#if defined GY_OS_AMBA + else if (strlen(q_info_copy.snmp_host_ip) >= 1) + { + //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); + + SetSNMPRequest(&q_info_copy); + + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + } +#endif + else { + if (strlen(q_info_copy.post_url) >= 1) { + + char *temp_post_url = StrReplace(q_info_copy.post_url, "space", "%20"); + strcpy(q_info_copy.post_url, temp_post_url); + if (temp_post_url != NULL) { + free(temp_post_url); + temp_post_url = NULL; + } + + //printf("\n----------q_info_copy.post_url:%s\n", q_info_copy.post_url); + + pthread_mutex_lock(&mutex_set_http_request); +#ifdef GY_OS_NOVA + if (strcmp(q_info_copy.host_name, "127.0.0.1") != 0 && strcmp(q_info_copy.host_name, "localhost") != 0) { + SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); + } + else { + SetHttpRequest_sock(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); + } +#endif + +#ifdef GY_OS_AMBA + SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); +#endif + + pthread_mutex_unlock(&mutex_set_http_request); + } + } + //HW----------- +#endif + //printf("\n------------Segmentation fault:%d\n", 2); +#endif + } + +#ifdef GY_OS_AMBA + if (g_IsPTZDevice == 1 && get_try_once_ptz() == 1) { + if (IsTracking() == 1) { + if (count_ptz % 15 == 0) { + count_ptz = 0; + UpdatePTZIPcamSetting(); + } + else if (count_ptz % 15 == 4) { + UpdatePTZCurPos(); + } + else if (count_ptz % 15 == 7) { + update_PTZ_limits(); + } + else if (count_ptz % 15 == 10) { + UpdateRecoveryTime(); + } + } + else { + if (count_ptz % 40 == 0) { + count_ptz = 0; + UpdatePTZIPcamSetting(); + } + } + count_ptz++; + } +#endif + + if (count_delay % 200 == 0) { + count_delay = 0; + update_system_time(); + } + count_delay++; + + if (count_initial_global_curl % 15 == 0) { + count_initial_global_curl = 0; + + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + else { + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + } + count_initial_global_curl++; + + if (g_IsSDK_3_0 == 0) { + if (count_to_refresh_smtp_service % MAX_COUNT_TO_REFRESH_SMTP_SERVICE * 5 == 0) { + count_to_refresh_smtp_service = 0; + copy_ipcam_smtp_service_to_gynet(); + } + count_to_refresh_smtp_service++; + } + + if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { + if (strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { + gettimeofday(&currtime_control_alarm_gpio, NULL); + long current_ms_control_alarm_gpio = (currtime_control_alarm_gpio.tv_sec * 1000) + (currtime_control_alarm_gpio.tv_usec / 1000); + + if (last_ms_control_alarm_gpio == 0) { + last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + + if (current_ms_control_alarm_gpio >= last_ms_control_alarm_gpio + atoi(viewChannelData[0].dwell_lpr_upon_triggered) * 1000) { + copy_control_io_to_gynet(); + last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + } + } + + if (count_g_http_handle >= 5) { + //printf("\n------------Segmentation fault:%d\n", 3); + count_g_http_handle = 0; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + else { + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + //printf("\n------------Segmentation fault:%d\n", 4); + } + else if (g_http_handle == NULL) { + count_g_http_handle = 0; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle == NULL) { + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + } + + count_g_http_handle++; + set_record_process_note("run_post_end"); + //printf("\n-----run post notification end\n"); + usSleep(SLEEP_QUEUE_POP_POST*1000); + } + + pthread_mutex_lock(&mutex_curl); + curl_easy_cleanup(g_http_handle); + g_http_handle = NULL; + pthread_mutex_unlock(&mutex_curl); + + pthread_mutex_lock(&mutex_post_notification_pop); + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_post_notification_pop); + + //printf("\n-------[run post notification thread] pthread_exit\n"); + + pthread_exit(NULL); +} + +//post the getalarmmotion back to the origianl socket +static char MultiPartBuffer[CONTENT_BUFSIZE] = { 0 }; +static char contentBuffer[CONTENT_BUFSIZE] = { 0 }; +static char contentBuffer_websocket[CONTENT_BUFSIZE] = { 0 }; +void *run_getalarmmotion_thread(void *ptr) +{ + //printf("\n[run getalarmmotion thread]pthread create\n"); + + pthread_detach(pthread_self()); + setPthreadName("run_getalarm"); + char sendBuffer[ALMBUFSIZE] = {0}; + //int nmlocsendBufferSize = 1024; + //int PAD_BUFFERSIZE = 512; + char l_send_buf[ALMBUFSIZE] = { 0 }; + UNIX_MESSAGE_V1_T l_unix_msg; + int l_packet_len = 0; + char tempStr[MAX_MSG_LEN] = { 0 }; + + QueueInfo q_info_copy = { 0 }; + + while (bHttpServerThreadStart) + { + //printf("\n getalarmmotion out que size = %d \n", QueueSize(_GETALARMMOTION)); + if (!QueueIsEmpty(_GETALARMMOTION)) + { + //printf("\n-------run getalarmmotion start\n"); + set_record_process_note("run_getalarm_start"); + //memset(sendBuffer, 0x00, sizeof(sendBuffer)); //20201104 sophia add + memset(MultiPartBuffer, 0x00, sizeof(MultiPartBuffer)); + memset(contentBuffer, 0x00, sizeof(contentBuffer)); + memset(contentBuffer_websocket, 0x00, sizeof(contentBuffer_websocket)); + memset(websocket_alarm, 0x00, sizeof(websocket_alarm)); + + pthread_mutex_lock(&mutex_getalarmmotion); + + q_info_copy = QueueFront(_GETALARMMOTION); + QueuePop(_GETALARMMOTION); + + pthread_mutex_unlock(&mutex_getalarmmotion); + + time_t now = time(0); + //struct tm tm = *gmtime(&now); + struct tm tm = *localtime(&now); + + struct timeval curTime; + gettimeofday(&curTime, NULL); + + strcpy(contentBuffer, "CamTime: "); + + memset(tempStr, 0x00, sizeof(tempStr)); + strftime(tempStr, sizeof(tempStr) - 1, "%Y-%m-%d %H:%M:%S", &tm); + strcat(contentBuffer, tempStr); + + int milli = curTime.tv_usec / 1000; + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, " %s%d", "ms:", milli); + strcat(contentBuffer, tempStr); + strcat(contentBuffer, "\r\n"); + strcat(contentBuffer, "\r\n"); + + strcpy(contentBuffer_websocket, contentBuffer); + + strcat(contentBuffer, q_info_copy.content); + strcat(contentBuffer, "\r\n"); + strcat(contentBuffer, "\r\n"); + + strcat(contentBuffer_websocket, q_info_copy.content_no_base64_image); + strcat(contentBuffer_websocket, "\r\n"); + strcat(contentBuffer_websocket, "\r\n"); + + //strcat(contentBuffer, "--myboundary\r\n"); + //strcat(contentBuffer, "\r\n"); + + //ץg_IsRadarDeviceMg_IsToFDevice䴩contentMcontent_no_base64_imageA]websocketgetalarmmotionnno_base64_imageC + //Ӥ@getalarmmotionAhOϥcontentC + //memcpy(websocket_alarm, contentBuffer, strlen(contentBuffer)); + memcpy(websocket_alarm, contentBuffer_websocket, strlen(contentBuffer_websocket)); + + long int contentLen_buffer = strlen(q_info_copy.content); + + strcpy(MultiPartBuffer, "--myboundary\r\n"); + //strcat(MultiPartBuffer, "\r\n"); + + //strcat(MultiPartBuffer, "Host: localhost:8592\r\n"); + //strcat(MultiPartBuffer, "Connection: keep-alive\r\n"); + //strcat(MultiPartBuffer, "Pragma: no-cache\r\n"); + //strcat(MultiPartBuffer, "Cache-Control: no-cache"); + //strcat(MultiPartBuffer, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36\r\n"); + //strcat(MultiPartBuffer, "Accept: */*\r\n"); + //strcat(MultiPartBuffer, "Referer: \r\n"); + //strcat(MultiPartBuffer, "Accept-Encoding: gzip, deflate\r\n"); + //strcat(MultiPartBuffer, "Accept-Language: zh-TW,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\r\n"); + //strcat(MultiPartBuffer, "Cookie: \r\n"); + //strcat(MultiPartBuffer, "Content-Type: multipart/form-data; boundary=----WebKitFormBoundarylilinboundary\r\n"); + + strcat(MultiPartBuffer, "Content-Type: text/plain\r\n"); + //strcat(MultiPartBuffer, "Content-Type: text/plain; charset=utf-8;\r\n"); + + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", contentLen_buffer); + strcat(MultiPartBuffer, tempStr); + strcat(MultiPartBuffer, "\r\n"); + //strcat(MultiPartBuffer, "Content-Type: text/html; charset=utf-8\r\n"); + + + strcat(MultiPartBuffer, contentBuffer); + //getalarmmotion doesn't need to append --myboundary END + size_t MultiPartLen = strlen(MultiPartBuffer); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + int sock_idx = i; + if (socketRecords[i].used == 1 && socketRecords[i].sock != -1 && socketRecords[i].isGetAlarmMotion) + { + //memset(sendBuffer, 0x00, nmlocsendBufferSize); //20201104 sophia add + ////ˬdO_ưjApGOAhĤ@alarmC + + //printf("\n[run getalarmmotion thread] socketRecords[%d].sock:%ld contentLen_buffer:%d MultiPartLen:%d\n", i, socketRecords[i].sock, contentLen_buffer, MultiPartLen); + + if (socketRecords[i].isUdpSocket == TRUE) + { + //printf("\n----------%d\n", strlen(q_info_copy.udp_aiengine)); + ///getalarmmotion looping +#if 1 + if(strlen(q_info_copy.udp_aiengine) >= 1 && strlen(q_info_copy.udp_aiengine) <= 15000) + { + memset(sendBuffer, 0x00, sizeof(sendBuffer)); + + unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; //type + unsigned int contentlen = strlen(q_info_copy.udp_aiengine); //len + size_t sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, nmlocsendBufferSize); + } + + //start code + { + strcat(sendBuffer, "UMV01"); + sendBufferSize = sendBufferSize + 5; + } + + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + ALMQueueInfo alm_q_info = { 0 }; + + memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info.nSize = sendBufferSize + 1; + alm_q_info.infoType = 1; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if(ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); + } + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + } + } + else if(strlen(q_info_copy.udp_aiengine) > 15000 && strlen(q_info_copy.udp_aiengine) <= 30000) + { + memset(sendBuffer, 0x00, sizeof(sendBuffer)); + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 1); + /////////////////start + unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; + unsigned int UDP_PACKAGE_TYPE = 0x0000; //start type 0x0000 body type 0x0001 end type 0x0002 + unsigned int contentlen = 15000; //len + size_t sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 2); + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, ALMBUFSIZE); + } + + //start code + { + strcat(sendBuffer, "UMV02"); + sendBufferSize = sendBufferSize + 5; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); + sendBufferSize = sendBufferSize + 4; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 4); + ALMQueueInfo alm_q_info_1 = { 0 }; + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + + + memset(alm_q_info_1.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info_1.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info_1.nSize = sendBufferSize + 1; + alm_q_info_1.infoType = 1; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + } + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 5); + /////////////////end + UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; + UDP_PACKAGE_TYPE = 0x0002; //start type 0x0000 body type 0x0001 end type 0x0002 + contentlen = strlen(q_info_copy.udp_aiengine) - 15000; //len + sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 6); + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, ALMBUFSIZE); + } + + //start code + { + strcat(sendBuffer, "UMV02"); + sendBufferSize = sendBufferSize + 5; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); + sendBufferSize = sendBufferSize + 4; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 7); + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine + 15000, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 8); + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + ALMQueueInfo alm_q_info_2 = { 0 }; + + memset(alm_q_info_2.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info_2.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info_2.nSize = sendBufferSize + 1; + alm_q_info_2.infoType = 1; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) { + ALMQueuePush(alm_q_info_1, sock_idx); + ALMQueuePush(alm_q_info_2, sock_idx); + } + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); + } + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 9); + + } + } +#endif + //getalarmmotion cloud + if(strcmp(SystemSetting.enable_cloud_v2,"Yes")==0 && strcmp(q_info_copy.post_url,"cloud_v2")==0 && strlen(q_info_copy.cloud_v2_aiengine)>=1) + { + memset(sendBuffer, 0x00, sizeof(sendBuffer)); + + unsigned int UNIX_MESSAGE_TYPE_POST_CLOUD = 0x0001; //type + unsigned int contentlen = strlen(q_info_copy.cloud_v2_aiengine); //len + + //printf("\n-----------q_info_copy.cloud_v2_aiengine:%s\n", q_info_copy.cloud_v2_aiengine); + + size_t sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, nmlocsendBufferSize); + } + + //start code + { + strcat(sendBuffer, "UMV01"); + sendBufferSize = sendBufferSize + 5; + } + + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_POST_CLOUD, sizeof(UNIX_MESSAGE_TYPE_POST_CLOUD)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.cloud_v2_aiengine, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + ALMQueueInfo alm_q_info = { 0 }; + + memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info.nSize = sendBufferSize + 1; + alm_q_info.infoType = 2; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); + } + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + + } + } + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + //send_count = 0; + //printf("UDP 0003 \n"); + + memset(&l_unix_msg, 0, sizeof(UNIX_MESSAGE_V1_T)); + l_unix_msg.type = UNIX_MESSAGE_TYPE_RTSP_META; + + { + //printf("onvif lx, ty, rx, by = %.2f, %.2f, %.2f, %.2f \n", q_info_copy.onvif_object[0].left_x, q_info_copy.onvif_object[0].top_y, q_info_copy.onvif_object[0].right_x, q_info_copy.onvif_object[0].bottom_y); + //printf("onvif cx, cy= %.2f, %.2f \n", q_info_copy.onvif_object[0].center_x, q_info_copy.onvif_object[0].center_y); + + create_onvif_packet(&l_unix_msg, q_info_copy.onvif_object, q_info_copy.onvif_object_num,q_info_copy.onvif_counter); + //printf("l_unix_msg.buf = %s \n", l_unix_msg.buf); + } + + l_unix_msg.length = strlen(l_unix_msg.buf); + if (l_unix_msg.length >= 1) + { + //printf("[%s]\n", l_unix_msg.buf); + l_packet_len = l_unix_msg.length + sizeof(unsigned int) + sizeof(unsigned int); + + memset(l_send_buf, 0, sizeof(l_send_buf)); + + memcpy(l_send_buf, UNIX_MESSAGE_V1, sizeof(UNIX_MESSAGE_V1)); + memcpy(l_send_buf + sizeof(UNIX_MESSAGE_V1) - 1, (char *)&l_unix_msg, l_packet_len); + l_packet_len += sizeof(UNIX_MESSAGE_V1); + + { + ALMQueueInfo alm_q_info = { 0 }; + + memset(alm_q_info.pszContent, 0x00, l_packet_len + 1); + memcpy(alm_q_info.pszContent, l_send_buf, l_packet_len + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info.nSize = l_packet_len + 1; + alm_q_info.infoType = 6; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + } + } + } + } + + } + else if(socketRecords[i].isWebSocketConnect == TRUE) + { + //printf("\n------ALMQueueSize(sock_idx):%d\n", ALMQueueSize(sock_idx)); + //printf("\n[run getalarmmotion thread] MultiPartLen:%d\n", MultiPartLen); + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + if(strlen(websocket_alarm) >= 1) + { + ALMQueueInfo alm_q_info = { 0 }; + //strcpy(alm_q_info.pszContent,MultiPartBuffer); + strcpy(alm_q_info.pszContent, websocket_alarm); + //strcpy(alm_q_info.websocket_content, websocket_alarm); + //alm_q_info.nSize = strlen(alm_q_info.pszContent); + alm_q_info.nSize = MultiPartLen; + alm_q_info.infoType = 5; + //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); + } + } + } + else if(socketRecords[i].isGetAlarmMotion == TRUE) + { + if (strlen(MultiPartBuffer) >= 1) + { + ALMQueueInfo alm_q_info = { 0 }; + strcpy(alm_q_info.pszContent, MultiPartBuffer); + //strcpy(alm_q_info.websocket_content, websocket_alarm); + //alm_q_info.nSize = strlen(alm_q_info.pszContent); + alm_q_info.nSize = MultiPartLen; + alm_q_info.infoType = 5; + //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); + } + } + } + } + } + set_record_process_note("run_getalarm_end"); + usSleep(10000); + //printf("\n-------run getalarmmotion end\n"); + } + else { + usSleep(10000); + } + } + + pthread_mutex_lock(&mutex_getalarmmotion); + QueueClear(_GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + + //printf("[run getalarmmotion thread] pthread_exit\n"); + + pthread_exit(NULL); +} + + + +#if 1 +void *run_send_udp_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_udp"); + //printf("\n[run_send_udp_thread]pthread create\n"); + //printf("\n[run_send_udp_thread]no new address\n"); +#ifdef _DEBUG_AMBA + printf("\n[run_send_udp_thread] start\n"); +#endif //_DEBUG_AMBA + + //int thread_id = (int)ptr; + + int l_sockfd; + struct sockaddr_un serveraddr; + char path[64] = "/tmp/udp_unix"; + + // Creating socket file descriptor + bzero(&serveraddr, sizeof(serveraddr)); + //memset(&serveraddr, 0, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, path); + + l_sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); + if (l_sockfd < 0) + { + printf("\nudp socket creation failed\n"); + printf("\n[run_send_udp_thread] udp socket creation failed\n"); + } + else + { + //20210714 ADD + + int reuse = 1; + setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(l_sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = l_sockfd; + + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = TRUE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = TRUE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 2; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + //printf("\n(%d) [run_send_udp_thread] socketRecords[%d].sock:%d\n", l_sockfd, i, socketRecords[i].sock); + socketRecords[i].used = 1; + break; + } + } + + while (bHttpServerThreadStart) + { + //printf("\n----------run send udp thread start\n"); + + int sock_idx = -1; + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //if (socketRecord_ALM[i].sock == l_sockfd) { + //sock_idx = i; + //} + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == l_sockfd) + { + socketRecords[i].debug_type = 2; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + sock_idx = i; + break; + } + } + } + +#ifdef _DEBUG_AMBA + printf("\n(%d) [run_send_udp_thread] sock_idx:%d\n", l_sockfd, sock_idx); +#endif + + if (sock_idx >= 0) + { + pthread_mutex_lock(&mutex_alm); + int len = ALMQueueSize(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\n(%d) [run_send_udp_thread] ALMQueueSize:%d\n", l_sockfd, len); + if (len > 0) + { + set_record_process_note("udp_start"); + //printf("\nKKKKKKKKK 1\n"); + int l_ret = 1; + + for (int index_len = 0; index_len < len; index_len++) { + pthread_mutex_lock(&mutex_alm); + ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); + int dupstr_len = alm_q_info.nSize; + //char dupstr[ALMBUFSIZE] = { 0 }; + + //memset(dupstr, 0x00, dupstr_len); + //memcpy(dupstr, alm_q_info.pszContent, dupstr_len); + + + ALMQueuePop(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nKKKKKKKKK 2\n"); + if (dupstr_len >= 1) + { + //printf("\nKKKKKKKKK 3\n"); + int l_len = strlen(serveraddr.sun_path) + sizeof(serveraddr.sun_family); + l_ret = sendto(l_sockfd, alm_q_info.pszContent, dupstr_len, 0, (struct sockaddr*)&serveraddr, l_len); + + if (l_ret <= 0) + { + printf("\n(%d) [run_send_udp_thread] send error\n", l_sockfd); + printf("\nsendto error\n"); + + if (alm_q_info.infoType == 2) { + memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); + strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP fail."); + write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + else if (alm_q_info.infoType == 3) { + memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); + strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP fail."); + write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + + //closesocket(l_sockfd); + break; + } + else { + if (alm_q_info.infoType == 2) { + memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); + strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP OK."); + write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); + } + else if (alm_q_info.infoType == 3) { + memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); + strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP OK."); + write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); + } + } + } + else { + if (alm_q_info.infoType == 2) { + memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); + strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: nSize could not be zero."); + write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + else if (alm_q_info.infoType == 3) { + memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); + strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: nSize could not be zero."); + write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + } + + if (index_len < len - 1) { + usSleep(10000); + } + } + + set_record_process_note("udp_end"); + if (l_ret <= 0) + { + break; + } + usSleep(10000); + } + else { + usSleep(10000); + } + } + else { + usSleep(1000000); + } + //printf("\n----------run send udp thread end\n"); + + } + + closesocket(l_sockfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == l_sockfd) + { + socketRecords[i].sock = -1; + + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + pthread_mutex_lock(&mutex_alm); + ALMQueueClear(i); + pthread_mutex_unlock(&mutex_alm); + + socketRecords[i].used = 0; + break; + } + } + } + + //printf("\n[run_send_udp_thread]pthread exit\n"); + pthread_exit(NULL); +} +#endif //GY_OS_AMBA + +#if GY_OS_WIN +int UpdateTrafficLightZone(int tracking_channel_idx) +{ + CPoint zone_polygon[DETECTION_POINTS_COUNT] = { 0 }; + int b_IsInsideZone = 0; + int b_ZoneExist = 0; + + int point_x = 0; + int point_y = 0; + int diagonal_x = 0; + int diagonal_y = 0; + //int zone_width = 0; + //int zone_height = 0; + int traffic_light_zone_idx = viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1; + int min_x = 1920 * 4; + int point_idx = 0; + int diagonal_idx = 0; + for (int k = 0; k < DETECTION_POINTS_COUNT; k++) + { + if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x < min_x) + { + point_idx = k; + min_x = viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x; + } + else if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x == min_x) + { + if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].y < viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y) + { + point_idx = k; + } + } + } + + if (point_idx + 2 >= DETECTION_POINTS_COUNT) + diagonal_idx = point_idx + 2 - DETECTION_POINTS_COUNT; + else + diagonal_idx = point_idx + 2; + + if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x > 0 || viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y > 0) + b_ZoneExist = 1; + + if (b_ZoneExist) + { + point_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + point_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + diagonal_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + diagonal_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + //zone_width = diagonal_x - point_x; + //zone_height = diagonal_y - point_y; + trafficLightPoint.x = point_x; + trafficLightPoint.y = point_y; + traffic_light_zone_width = diagonal_x - point_x; + traffic_light_zone_height = diagonal_y - point_y; + } +} +#endif //GY_OS_WIN - UpdateTrafficLightZone + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void linear_regression(detection_pos** p, int pointCount, double* a, double* b) +{ + double sum_x, sum_x_sqare, sum_y, sum_xy; + double a11, a12, a21, a22, b1, b2; + + sum_x = sum_x_sqare = sum_y = sum_xy = 0.0; + + int validCount = 0; + + double count_top = 0; + double count_middle = 0; + double count_bottom = 0; + + for (int i = 0; i < pointCount; ++i) + { + if (p[i]->left_x < 1 || p[i]->top_y < 1) + continue; + else + { + if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { + count_top++; + } + else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { + count_middle++; + } + else { + count_bottom++; + } + } + } + + double multi_ratio = 1; + if (count_top >= 1.0) { + multi_ratio *= count_top; + } + if (count_middle >= 1.0) { + multi_ratio *= count_middle; + } + if (count_bottom >= 1.0) { + multi_ratio *= count_bottom; + } + + //printf("\n-------count_top:%lf,count_middle:%lf,count_bottom:%lf\n", count_top, count_middle, count_bottom); + + for (int i = 0; i < pointCount; ++i) + { + if (p[i]->left_x < 1 || p[i]->top_y < 1) + continue; + else + { + double temp_multi_ratio = 1.0; + + if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { + temp_multi_ratio = multi_ratio / count_top; + } + else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { + temp_multi_ratio = multi_ratio / count_middle; + } + else { + temp_multi_ratio = multi_ratio / count_bottom; + } + + //sum_x += p[i]->left_x + p[i]->width / 2; + //sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2); + //sum_y += p[i]->top_y + p[i]->height / 2; + //sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2); + + //printf("[%d] x,y, w,h = %f, %f, %f, %f \n", i, p[i]->left_x, p[i]->top_y, p[i]->width, p[i]->height); + + sum_x += (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; + sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; + //sum_y += p[i]->center_y + p[i]->height / 2; + sum_y += (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; + //sum_y += p[i]->center_y; + sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; + + validCount += temp_multi_ratio; + } + } + + a11 = sum_x; + //a12 = pointCount; + a12 = validCount; + a21 = sum_x_sqare; + a22 = sum_x; + b1 = sum_y; + b2 = sum_xy; + + *a = (b1 * a22 - a12 * b2) / (a11 * a22 - a12 * a21); + *b = (a11 * b2 - a21 * b1) / (a11 * a22 - a12 * a21); + + //printf("the line is y = %lf x + %lf\n", *a, *b); +} + +void assign_row_number(detection_pos* PosInfo, detection_pos* pNext1, detection_pos* pNext2, int total_element_size, int element_size2, int parent_idx, float* arc) +{ + detection_pos *detPoints[32]; + double a = 0; + double c = 0; + double dist_tmp = 0; + double dist_up = 0; + double dist_down = 0; + float height_up = 0; + int n_lr = 0; + int element_size_lr2 = element_size2; + int name_len = 0; + + for (int n = 0; n < element_size2; n++) + { + pNext2 = PosInfo + total_element_size + n; + + //printf("\n[assign_row_number] _prefix1 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id,total_element_size,n, total_element_size + n); + + //n_lr = n; + name_len = strlen(pNext2->name); + if (memcmp(pNext2->name, MOVE_FORWARD_PREFIX, strlen(MOVE_FORWARD_PREFIX)) == 0) + { + //printf("\n[assign_row_number] _prefix1 pNext2->name:%s", pNext2->name); + memmove(pNext2->name, pNext2->name + strlen(MOVE_FORWARD_PREFIX), name_len - strlen(MOVE_FORWARD_PREFIX)); + pNext2->name[name_len - strlen(MOVE_FORWARD_PREFIX)] = '\0'; + pNext2->number_row = 0; + pNext2->obj_type = _PREFIX; + element_size_lr2--; + continue; + } + + detPoints[n_lr] = pNext2; + n_lr++; + } + + linear_regression(detPoints, element_size_lr2, &a, &c); + *arc = atan(a); + //float degree = arch * 180 / MATH_PI; + //printf("XXXXXXXXXXXXXXXXX element_size2 = %d \n", element_size2); + + for (int j = 0; j < element_size2; j++) + { + //printf("total_element_size = %d \n", total_element_size); + + pNext2 = PosInfo + total_element_size + j; + pNext2->arc = *arc; + + //printf("\n[assign_row_number] _prefix2 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id, total_element_size, j, total_element_size + j); + + if (pNext2->number_row == 0) + { + //printf("\n[assign_row_number] _prefix2 pNext2->name:%s", pNext2->name); + + pNext2->left_x += pNext1->left_x; + pNext2->top_y += pNext1->top_y; + pNext2->parent_idx = parent_idx; + pNext2->obj_type = _PREFIX; + continue; + } + else + { + if (featureType & FEATURE_LPR_CNT && strcmp(pNext1->name, "L._Plate_CNT_VERTICAL") == 0) { + if ((pNext2->left_x + pNext2->width / 2) <= (pNext2->top_y + pNext2->height / 2) * a + c) + { + pNext2->number_row = 1; + //double sq = sqrt(a*a + (-1)*(-1)); + dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + 1); + if (dist_tmp > dist_up) + { + dist_up = dist_tmp; + height_up = pNext2->width; + } + } + else + { + pNext2->number_row = 2; + dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + (-1)*(-1)); + if (dist_tmp > dist_down) + { + dist_down = dist_tmp; + height_up = pNext2->width; + } + } + } + else { + if ((pNext2->top_y + pNext2->height / 2) <= (pNext2->left_x + pNext2->width / 2) * a + c) + { + pNext2->number_row = 1; + //double sq = sqrt(a*a + (-1)*(-1)); + dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + 1); + if (dist_tmp > dist_up) + { + dist_up = dist_tmp; + height_up = pNext2->height; + } + } + else + { + pNext2->number_row = 2; + dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + (-1)*(-1)); + if (dist_tmp > dist_down) + { + dist_down = dist_tmp; + height_up = pNext2->height; + } + } + } + + pNext2->left_x += pNext1->left_x; + pNext2->top_y += pNext1->top_y; + pNext2->parent_idx = parent_idx; + pNext2->obj_type = _NUMBER; + //printf("Set [%d] parent idx = %d \n", j, parent_idx); + } + } + + if ((dist_up + dist_down) < height_up * 0.5 || (dist_up == 0 && dist_down == 0 && height_up == 0)) + { + for (int j = 0; j < element_size2; j++) + { + pNext2 = PosInfo + total_element_size + j; + if (pNext2->number_row == 0) + { + continue; + } + else + { + pNext2->number_row = 1; + } + } + } +} +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int SortObjects(detection_pos* PosInfo, int total_element_size) +{ + + detection_pos *pNext = NULL, *pFirstNumber = NULL; + int pre_parent_idx = -1; + int sortLogicUSA = 0; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if ((pNext->engine_type == FEATURE_LPR_USA) && pNext->obj_type == _NUMBER) + { + sortLogicUSA = 1; + if (pNext->parent_idx != pre_parent_idx) + { + pFirstNumber = pNext; + pNext->visual_left_x = pNext->left_x; + pre_parent_idx = pNext->parent_idx; + } + else + { + for (int j = 0; j < pNext - pFirstNumber; j++) + { + if ((pFirstNumber + j)->obj_type == _PREFIX) + continue; + if (pNext->left_x + pNext->width / 2 > (pFirstNumber + j)->left_x && pNext->left_x + pNext->width / 2 < (pFirstNumber + j)->left_x + (pFirstNumber + j)->width) + { + pNext->visual_left_x = (pFirstNumber + j)->visual_left_x; + break; + } + else { + pNext->visual_left_x = pNext->left_x; + } + } + } + } + else + { + pNext->visual_left_x = pNext->left_x; + } + } + return sortLogicUSA; + +} +#endif //GY_OS_WIN - SortObjects + +#if 1 +void SetCorrectClassID(detection_pos *PosInfo, int total_element_size, int element_size1) +{ + detection_pos *pNext = NULL, *pNext2 = NULL; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + int nDistance_y = 2160; + + if (g_IsToFDevice == 1) { + if (pNext->class_id == 1) {//hand + pNext->class_id = 250; + } + } + else if (strcmp(pNext->name, "person")==0) { + pNext->class_id = 0; + } + else if (strcmp(pNext->name, "bicycle")==0) { + pNext->class_id = 1; + } + else if (strcmp(pNext->name, "car")==0) { + pNext->class_id = 2; + } + else if (strcmp(pNext->name, "motorbike")==0) { + pNext->class_id = 3; + } + else if (strcmp(pNext->name, "bus")==0) { + pNext->class_id = 5; + } + else if (strcmp(pNext->name, "truck")==0) { + pNext->class_id = 7; + } + else if(IsANPRCategory_L_Plate(pNext->name)){ + if (strcmp(pNext->name, "ambulance") == 0) { + pNext->class_id = 104; + } + + if (strcmp(pNext->name, "stop_sign") == 0) { + pNext->class_id = 11; + } + + if (strncmp(pNext->name, "L._Plate_",9) == 0) { + pNext->class_id = 900; + } + + if (strcmp(pNext->name, "face") == 0) { + pNext->class_id = 0; + } + } + else if (IsANPRCategory(pNext->engine_type)) { + if ((pNext->engine_type & FEATURE_LPR_THA)) { + //ꨮP S19class_idܦ@몺19 + if (pNext->class_id >= 39 && pNext->class_id <= 47) + { + pNext->class_id -= 38; + } + } + } + else { + +#ifdef GY_OS_AMBA + if (strcmp(WeightFileModeName, "mod004") == 0) + { + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + else if (pNext->class_id == 8)//boat + { + pNext->class_id = 158; + } + } + } + else { + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + else if (pNext->class_id == 5)//bus + { + pNext->class_id = 2; + } + else if (pNext->class_id == 6)//train + { + pNext->class_id = 2; + } + else if (pNext->class_id == 7)//truck + { + pNext->class_id = 2; + } + } + } + else { + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + } + } + } +#else + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + } +#endif + + if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) + { + if (pNext->class_id == 39 || + pNext->class_id == 40 || + pNext->class_id == 114) { + pNext->class_id = 39; + } + else if (pNext->class_id == 41 || + pNext->class_id == 45) { + pNext->class_id = 41; + } + else if (pNext->class_id == 110 || + pNext->class_id == 115) { + pNext->class_id = 433; + } + else if (pNext->class_id == 111 || + pNext->class_id == 112) { + pNext->class_id = 19; + } + else if (pNext->class_id == 116 || + pNext->class_id == 117) { + pNext->class_id = 102; + } + else if (pNext->class_id == 118 || + pNext->class_id == 120) { + pNext->class_id = 99; + } + } + + if ((pNext->engine_type & FEATURE_AIFIRE)) + { + //printf("fire id = %d \n", pNext->class_id); + + if (pNext->class_id <= 3) + { + pNext->class_id += 105; + } + else if (pNext->class_id == 6 || pNext->class_id == 7) + { + pNext->class_id += 314; + } + else { + pNext->class_id += 141; + } + } + + if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIAREO)) + { + pNext->class_id += 136; + } + + //printf("\nFEATURE_HUM_DET---1\n"); + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIMASK)) + { + //printf("fire id = %d \n", pNext->class_id); + if (strcmp(WeightFileModeName, "mod003") != 0) { + if (pNext->class_id == 88) + { + pNext->class_id = 80; //face + } + else if (pNext->class_id == 89) + { + pNext->class_id = 81; //half_mask + } + else if (pNext->class_id == 90) + { + pNext->class_id = 82; //mask + } + } + else { + pNext->class_id += 140; + } + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIHELM)) + { + if (pNext->class_id >= 95 && pNext->class_id <= 97) { + pNext->class_id += 1; + } + else if(pNext->class_id == 98){ + pNext->class_id = 318; + } + else if (pNext->class_id >= 99) { + pNext->class_id += 271; + } + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AISHIP)) + { + //printf("fire id = %d \n", pNext->class_id); + pNext->class_id += 150; + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIPRODUCTION)) + { + //printf("fire id = %d \n", pNext->class_id); + + pNext->class_id += 430; + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIAML)) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + //printf("fire id = %d \n", pNext->class_id); + pNext->class_id += 167; + } + else { + pNext->class_id += 340; + } + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIRADAR)) + { + // printf("radar id = %d \n", pNext->class_id); + pNext->class_id += 950; + } + + if ((pNext->engine_type & FEATURE_AIRAIL) && (pNext->engine_type2 & FEATURE_AIFLOW)) + { + if (pNext->class_id >= 3) { + pNext->class_id += 111; + } + else if (pNext->class_id == 9) { + pNext->class_id = 129; + } + else { + pNext->class_id += 110; + } + } + + if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AISPORTS) && strcmp(WeightFileModeName, "mod002") == 0) + { + pNext->class_id += 400; + } + + if ((pNext->engine_type & FEATURE_TRAF_DET)) + { +/*#ifdef GY_OS_AMBA + if (pNext->class_id == 80) + { + pNext->class_id = 88; // TUK TUK + } + else if (pNext->class_id == 81) + { + pNext->class_id = 89; // Truck trailer + } + else if (pNext->class_id == 82) + { + pNext->class_id = 90; // Pickup truck + } +#else + if ( + pNext->class_id == 81 || + pNext->class_id == 82 || + pNext->class_id == 85 + ) + { + pNext->class_id = 2; + } + else if ( + pNext->class_id == 6 || + pNext->class_id == 80 || + pNext->class_id == 83 || + pNext->class_id == 131 || + pNext->class_id == 132 || + pNext->class_id == 133 || + pNext->class_id == 134 + ) { + pNext->class_id = 7; + } +#endif*/ + } + + if ((pNext->engine_type & FEATURE_LPR_LOGO)) + { + pNext->class_id += 500; + + detection_pos* pDistance = NULL; + for (int j = 0; j < total_element_size; j++) + { + pNext2 = PosInfo + j; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + if (pNext->left_x > pNext2->left_x && (pNext->left_x + pNext->width) < (pNext2->left_x + pNext2->width) && pNext->top_y < pNext2->top_y) + { + if (pNext2->top_y - pNext->top_y < nDistance_y) + { + nDistance_y = pNext2->top_y - pNext->top_y; + pDistance = pNext2; + } + } + } + } + if (pDistance) { + + char temp_buf[50] = { 0 }; + int index_temp_buf = 0; + + for (int m = 0; m < (int)strlen(pNext->name); m++) { + if (m < (int)strlen(pNext->name) - 1 && pNext->name[m] == 'l' && pNext->name[m + 1] == '_') { + m++; + } + else { + temp_buf[index_temp_buf] = pNext->name[m]; + index_temp_buf++; + } + } + temp_buf[index_temp_buf] = '\0'; + + snprintf(pDistance->properties.logo, sizeof(pDistance->properties.logo), "%s", temp_buf); + snprintf(pDistance->logo, sizeof(pDistance->logo), "%s", temp_buf); + } + } + } + } + +} +#endif //GY_OS_WIN - SetCorrectClassID + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int IsMatchAUSPattern(char* PlatePattern, char* area) +{ + int nMatchPattern = 0; + if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH)) + { + char *local = "ACT"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH)) + { + char *local = "NSW"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_SLI)) + { + char *local = "NSW"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NTE_VEH)) + { + char *local = "NT"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_QUE_VEH)) + { + char *local = "QUEENSLAND"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_SAU_VEH)) + { + char *local = "SA"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_TAS_VEH)) + { + char *local = "Tasmania"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_VIC_VEH)) + { + char *local = "VICTORIA"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_WAU_VEH)) + { + char *local = "WA"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH_PRE)) + { + char *local = "ACT"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH_PRE)) + { + char *local = "NSW"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 0; + } + + return nMatchPattern; +} +#endif //GY_OS_WIN - IsMatchAUSPattern + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int IsMatchGBRPattern(char* PlatePattern, char* area) +{ + int nMatchPattern = 0; + if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + for (int i = 0; i < strlen(PlatePattern); i++) + { + if (*(PlatePattern + i) == '-') + memmove(PlatePattern + i, PlatePattern + i + 1, strlen(PlatePattern) - i); + } + + if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH_)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH_)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2_)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 0; + } + } + + return nMatchPattern; +} +#endif //GY_OS_WIN - IsMatchGBRPattern + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int IsMatchIDNPattern(char* PlatePattern, char* area) +{ + int nMatchPattern = 0; + if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BANT_VEH)) + { + char *local = "Banten"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA1_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG1_VEH)) + { + char *local = "Yogyakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA2_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA1_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA2_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAKA_VEH)) + { + char *local = "Jakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUM_VEH)) + { + char *local = "West Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WCNS_VEH)) + { + char *local = "West coast of North Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BENG_VEH)) + { + char *local = "Bengkulu"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_LAMP_VEH)) + { + char *local = "Lampung"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSUM_VEH)) + { + char *local = "South Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAMB_VEH)) + { + char *local = "Jambi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ECNS_VEH)) + { + char *local = "East coast of North Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ACEH_VEH)) + { + char *local = "Aceh"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RIAU_VEH)) + { + char *local = "Riau"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BBEL_VEH)) + { + char *local = "Bangka Belitung"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RISL_VEH)) + { + char *local = "Riau Islands"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA1_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SKAL_VEH)) + { + char *local = "South Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU1_VEH)) + { + char *local = "North Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUL_VEH)) + { + char *local = "West Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU1_VEH)) + { + char *local = "South Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_MALU_VEH)) + { + char *local = "Maluku"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NMAL_VEH)) + { + char *local = "North Maluku"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTT_VEH)) + { + char *local = "East Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BALI_VEH)) + { + char *local = "Bali"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU2_VEH)) + { + char *local = "North Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_GORO_VEH)) + { + char *local = "Gorontalo"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CSUL_VEH)) + { + char *local = "Central Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU2_VEH)) + { + char *local = "South Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTL_VEH)) + { + char *local = "West Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SESU_VEH)) + { + char *local = "Southeast Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU3_VEH)) + { + char *local = "South Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA2_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTS_VEH)) + { + char *local = "West Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTF_VEH)) + { + char *local = "East Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTS_VEH)) + { + char *local = "East Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA3_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA3_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA4_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA5_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WKAL_VEH)) + { + char *local = "West Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CKAL_VEH)) + { + char *local = "Central Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EKAL_VEH)) + { + char *local = "East Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NKAL_VEH)) + { + char *local = "North Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA3_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA4_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA5_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA6_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_PAPU_VEH)) + { + char *local = "Papua"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WPAP_VEH)) + { + char *local = "West Papua"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA6_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA7_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SURA_VEH)) + { + char *local = "Surabaya"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA4_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA8_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG2_VEH)) + { + char *local = "Yogyakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG3_VEH)) + { + char *local = "Yogyakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA5_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 0; + } + + return nMatchPattern; +} +#endif //GY_OS_WIN - IsMatchIDNPattern + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int PlatePatternParser(detection_pos* PosInfo, int total_element_size, size_t featureType/*, float arc*/) +{ + //printf("\n[PlatePatternParser] start\n"); + detection_pos *pNext = PosInfo; + //detection_pos *pBeginIndex = NULL; + int nNumCount = 0; + int result = 0; + char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + /*char country[30] = { 0 }; + char area[30] = { 0 };*/ + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + //char *dash = "-"; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->engine_type & FEATURE_LPR_TWN) + { + char country[30] = { 0 }; + char area[30] = { 0 }; + sprintf(country, "%s", "TWN"); + //detection_pos *pNext = PosInfo; + //int nNumCount = 0; + + //եΰ + //for (int i = 0; i < total_element_size; i++) + //{ + //pNext = PosInfo + i; + //sprintf(pNext->name, "%s", "1"); + //pNext->confidence = 35; + //pNext->left_x = 165; + //pNext->top_y = 127; + //pNext->width = 4; + //pNext->height = 26; + //pNext->obj_type == _NUMBER; + //} + + if (pNext->obj_type == _NUMBER) + nNumCount++; + else + continue; + + if (nNumCount == 1) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && + (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + } + else + { + pNext->arc = (pNext->arc > 0) ? pNext->arc : -pNext->arc; + //float angle = arc * 180 / MATH_PI; +#if 0 + if (activeDisplayDash) + { + if (pNext->arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely + { + float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); + //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + else + { + float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + } +#endif + + if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) + { + //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && + ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + nNumCount = 0; + } + } + } +#if 0 + else if (pNext->engine_type & FEATURE_LPR_EUR) + { + char country[30] = { 0 }; + char area[30] = { 0 }; + sprintf(country, "%s", "EUR");//European //EU/UK/IN + //detection_pos *pNext = PosInfo; + //int nNumCount = 0; + + //եΰ + /*for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + sprintf(pNext->name, "%s", "1"); + pNext->confidence = 35; + pNext->left_x = 165; + pNext->top_y = 127; + pNext->width = 4; + pNext->height = 26; + pNext->obj_type == _NUMBER; + }*/ + + if (pNext->obj_type == _NUMBER) + nNumCount++; + else + continue; + + if (nNumCount == 1) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && + (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + } + else + { + arc = (arc > 0) ? arc : -arc; + //float angle = arc * 180 / MATH_PI; + if (activeDisplayDash) + { + if (arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely + { + float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); + //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + else + { + float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + } + + if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) + { + //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && + ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + nNumCount = 0; + } + } + } +#endif +#if 0 + else if (pNext->engine_type & FEATURE_LPR_AUS) + { + /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->parent_idx < 0) + continue; + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + }*/ + } + else + { + if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) + { + PossiblePlate[IndexPattern] = dash; + IndexPattern++; + } + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + }*/ + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchAUSPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + } + } + else if (Index0orO > 0) + { + int rows = pow(2, Index0orO); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index0orO * sizeof *array[i]); + } + int *each = malloc(Index0orO * sizeof(int)); + int c = 0; + BinaryDFS(0, Index0orO, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index0orO; j++) + { + if (array[i][j] == _0) + *ElementPos0orO[j] = '0'; + else if (array[i][j] == _O) + *ElementPos0orO[j] = 'O'; + } + //printf("\n"); + if (Index0orO > 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchAUSPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + } + if (each) { + free(each); + each = NULL; + } + for (int i = 0; i < rows; i++) { + if (array[i]) { + free(array[i]); + array[i] = NULL; + } + } + if (array) { + free(array); + array = NULL; + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + ElementPos0orO[i] = NULL; + ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + //} + } +#endif +#if 0 + else if (pNext->engine_type & FEATURE_LPR_EUR)//FEATURE_LPR_GBR + { + /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->parent_idx < 0) + continue; + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + } + else + { + /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) + { + PossiblePlate[IndexPattern] = dash; + IndexPattern++; + }*/ + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) + { + snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); + }*/ + if (bMatch) + break; + } + else if (Index0orO > 0) + { + int rows = pow(2, Index0orO); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index0orO * sizeof *array[i]); + } + int *each = malloc(Index0orO * sizeof(int)); + int c = 0; + BinaryDFS(0, Index0orO, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index0orO; j++) + { + if (array[i][j] == _0) + *ElementPos0orO[j] = '0'; + else if (array[i][j] == _O) + *ElementPos0orO[j] = 'O'; + } + + if (Index0orO > 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + + } + else if (Index0orO > 0 && Index1orI > 0) + { + int rows2 = pow(2, Index1orI); + int **array2; + array2 = malloc(rows2 * sizeof *array2); + for (int index_i = 0; index_i < rows2; index_i++) + { + array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); + } + + int *each2 = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each2, array2, &c); + for (int index_i = 0; index_i < rows2; index_i++) + { + for (int index_j = 0; index_j < Index1orI; index_j++) + { + if (array2[index_i][index_j] == _1) + *ElementPos1orI[index_j] = '1'; + else if (array2[index_i][index_j] == _I) + *ElementPos1orI[index_j] = 'I'; + } + + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int index_i = 0; index_i < rows2; index_i++) { + if (array2[index_i] != NULL) { + free(array2[index_i]); + array2[index_i] = NULL; + } + } + if (array2 != NULL) { + free(array2); + array2 = NULL; + } + + if (each2 != NULL) { + free(each2); + each2 = NULL; + } + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + else if (Index1orI > 0) + { + int rows = pow(2, Index1orI); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index1orI * sizeof *array[i]); + } + int *each = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index1orI; j++) + { + if (array[i][j] == _1) + *ElementPos1orI[j] = '1'; + else if (array[i][j] == _I) + *ElementPos1orI[j] = 'I'; + //printf("%d", array[i][j]); + } + //printf("\n"); + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + ElementPos0orO[i] = NULL; + ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + //} + } +#endif +#if 1 + else if (pNext->engine_type & FEATURE_LPR_GBR) + { + /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->parent_idx < 0) + continue; + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + } + else + { + /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) + { + PossiblePlate[IndexPattern] = dash; + IndexPattern++; + }*/ + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) + { + snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); + }*/ + if (bMatch) + break; + } + else if (Index0orO > 0) + { + int rows = pow(2, Index0orO); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index0orO * sizeof *array[i]); + } + int *each = malloc(Index0orO * sizeof(int)); + int c = 0; + BinaryDFS(0, Index0orO, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index0orO; j++) + { + if (array[i][j] == _0) + *ElementPos0orO[j] = '0'; + else if (array[i][j] == _O) + *ElementPos0orO[j] = 'O'; + } + + if (Index0orO > 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + + } + else if (Index0orO > 0 && Index1orI > 0) + { + int rows2 = pow(2, Index1orI); + int **array2; + array2 = malloc(rows2 * sizeof *array2); + for (int index_i = 0; index_i < rows2; index_i++) + { + array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); + } + + int *each2 = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each2, array2, &c); + for (int index_i = 0; index_i < rows2; index_i++) + { + for (int index_j = 0; index_j < Index1orI; index_j++) + { + if (array2[index_i][index_j] == _1) + *ElementPos1orI[index_j] = '1'; + else if (array2[index_i][index_j] == _I) + *ElementPos1orI[index_j] = 'I'; + } + + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int index_i = 0; index_i < rows2; index_i++) { + if (array2[index_i] != NULL) { + free(array2[index_i]); + array2[index_i] = NULL; + } + } + if (array2 != NULL) { + free(array2); + array2 = NULL; + } + + if (each2 != NULL) { + free(each2); + each2 = NULL; + } + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + else if (Index1orI > 0) + { + int rows = pow(2, Index1orI); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index1orI * sizeof *array[i]); + } + int *each = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index1orI; j++) + { + if (array[i][j] == _1) + *ElementPos1orI[j] = '1'; + else if (array[i][j] == _I) + *ElementPos1orI[j] = 'I'; + //printf("%d", array[i][j]); + } + //printf("\n"); + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + ElementPos0orO[i] = NULL; + ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + //} + } +#endif + +#if 0 + else if (pNext->engine_type & FEATURE_LPR_IDN) + { + /*char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->obj_type == _NUMBER) + { + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + } + else + { + if (strlen(pNext->name) > 5) + printf("Test number"); + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchIDNPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "IDN"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + //ElementPos0orO[i] = NULL; + //ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + } + //} + } +#endif + else + { + //if (pNext->engine_type & FEATURE_LPR_TWN) + // sprintf(country, "%s", "TWN"); + char country[30] = { 0 }; + char area[30] = { 0 }; + int area_id = -1; + pNext->properties.area_id = area_id; + + /*if (pNext->engine_type & FEATURE_LPR_CNA) + sprintf(country, "%s", "CNA");*/ + if (pNext->engine_type & FEATURE_LPR_USA) + sprintf(country, "%s", "USA/CA"); + else if (pNext->engine_type & FEATURE_LPR_EUR) + sprintf(country, "%s", "EUR"); + /*else if (pNext->engine_type & FEATURE_LPR_TWN) + sprintf(country, "%s", "TWN");*/ + else if (pNext->engine_type & FEATURE_LPR_JPN) + sprintf(country, "%s", "JPN"); + else if (pNext->engine_type & FEATURE_LPR_BGD) + sprintf(country, "%s", "BGD"); + else if (pNext->engine_type & FEATURE_LPR_MEA) + sprintf(country, "%s", "MEA"); + else if (pNext->engine_type & FEATURE_LPR_SEA || + pNext->engine_type & FEATURE_LPR_IDN || + pNext->engine_type & FEATURE_LPR_VNM) + sprintf(country, "%s", "SEA"); + else if (pNext->engine_type & FEATURE_LPR_THA) + sprintf(country, "%s", "THA"); + else if (pNext->engine_type & FEATURE_LPR_LAO) + sprintf(country, "%s", "LAO"); + else if (pNext->engine_type & FEATURE_LPR_PHL) + sprintf(country, "%s", "PHL"); + else if (pNext->engine_type & FEATURE_LPR_CNT) + sprintf(country, "%s", "CNT"); + else if (pNext->engine_type & FEATURE_LPR_AUS) + sprintf(country, "%s", "AUS"); + else + sprintf(country, "%s", ""); + + if (IsANPRCategory(pNext->engine_type)) + { + //pNext = PosInfo + i; + + /*if (pNext->class_id >= 0) + { + if (strcmp(ppIniKeyValue[pNext->class_id], "") != 0) + { + strcpy(pNext->name, ppIniKeyValue[pNext->class_id]); + } + }*/ + + if (pNext->obj_type == _PLATE || pNext->obj_type == _LOGO) + continue; + + + if (pNext->obj_type == _PREFIX) + { + //printf("\n[PlatePatternParser]pNext->obj_type == _PREFIX area:%s area_id:%d\n", pNext->name, pNext->class_id); + sprintf(area, "%s", pNext->name); + area_id = pNext->class_id; + + // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty + + if (featureType & FEATURE_LPR_JPN /*|| featureType & FEATURE_LPR_CNA*/) + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + } + else + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + } + } + + + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + } + else + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + //char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + //PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty + /*if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_CNA) + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + } + else + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + }*/ + + //break; + } + + for (int j = 0; j < MAX_PLATE_NUMBER; j++) + { + //ElementPos0orO[i] = NULL; + //ElementPos1orI[i] = NULL; + PossiblePlate[j] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + } + } + } + //printf("\n[PlatePatternParser] end\n"); + return result; +} +#endif //GY_OS_WIN - PlatePatternParser + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void ReplaceWithUTF8(detection_pos* PosInfo, int total_element_size) +{ + detection_pos *pNext = NULL; + int layer_idx = 0; + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (i > 0 && pNext->parent_idx >= 0) + { + //printf("\npNext->engine_type\n") + + + //if ( ((pNext->engine_type == (pNext - 1)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((pNext - 1)->engine_type) && pNext->obj_type == _NUMBER && (pNext - 1)->obj_type == _PLATE) ) + if (((pNext->engine_type == (PosInfo + pNext->parent_idx)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((PosInfo + pNext->parent_idx)->engine_type) && (pNext->obj_type == _NUMBER || pNext->obj_type == _PREFIX) && (PosInfo + pNext->parent_idx)->obj_type == _PLATE)) + { + + for (int j = 0; j < MAX_LAYER_NUM; j++) + { + if (j > 0) + { + if (layerFeatureType[j - 1] == pNext->engine_type && layerFeatureType[j] == pNext->engine_type) + { + layer_idx = j; + break; + } + } + } + + if (pNext->class_id >= 0) + { + if (strcmp(ppIniKeyValue[layer_idx][pNext->class_id], "") != 0) + { + strcpy(pNext->name, ppIniKeyValue[layer_idx][pNext->class_id]); + } + } + } + } + + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + for (int j = 0; j < MAX_LAYER_NUM - 1; j++) + { + if (layerFeatureType[j] == pNext->engine_type && layerFeatureType[j + 1] == pNext->engine_type) + { + layer_idx = j + 1; + break; + } + } + + if (pNext->properties.area_id >= 0) + { + if (strcmp(ppIniKeyValue[layer_idx][pNext->properties.area_id], "") != 0) + { + strcpy(pNext->properties.area, ppIniKeyValue[layer_idx][pNext->properties.area_id]); + } + } + } + } +} + +void AssignPlateNumber(detection_pos* PosInfo, int total_element_size, int featureType) +{ + detection_pos* pNext = NULL; + detection_pos* pNext2 = NULL; + detection_pos* pNext_correct = NULL; + int differ_top_y = 20; + + int mea_record_idx = 0; + +#if 0 + int record_correct_PosInfo_i_order[256]; + int record_first_PosInfo_i = 0; + int min_top_y = 100000; + + for (int i = 0; i < 256; i++) { + if (i < total_element_size) { + record_correct_PosInfo_i_order[i] = i; + } + else { + record_correct_PosInfo_i_order[i] = -1; + } + } + + //Selection Sort: pNext->left_x + for (int i = 0; i < total_element_size; i = i + 1) + { + pNext = PosInfo + i; + for (int j = i + 1; j < total_element_size; j = j + 1) + { + pNext2 = PosInfo + j; + if (pNext->left_x > pNext2->left_x) + { + //ܼƥ洫 + int tmp_record_i = record_correct_PosInfo_i_order[i]; + record_correct_PosInfo_i_order[i] = record_correct_PosInfo_i_order[j]; + record_correct_PosInfo_i_order[j] = tmp_record_i; + } + } + + if (pNext->top_y < min_top_y) + { + min_top_y = pNext->top_y; + } + } + + for (int i = 0; i < total_element_size; i = i + 1) + { + pNext = PosInfo + record_correct_PosInfo_i_order[i]; + if (abs((int)((pNext->top_y - min_top_y) / min_top_y * 100)) <= differ_top_y) { + record_first_PosInfo_i = i; + break; + } + } +#endif + int enable_the_first_word = 0; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (IsANPRCategory(pNext->engine_type)) + { + + if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) + { + if (pNext->obj_type == _PREFIX) + { + if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) + continue; + } +#if 0 + if (featureType & FEATURE_LPR_TWN) { + if (activeDisplayDash) + { + if (pNext->obj_type == _DASH) + { + if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { + strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); + } + } + } + } +#endif + //printf("\n------pNext->width:%f\n", pNext->width); + +#if 0 + if (featureType & FEATURE_LPR_SEA) { + if (pNext->width < 1) + continue; + } + else { + if (get_g_ori_yuv_width() <= 1280) { + if (pNext->width < 70) + continue; + } + else { + if (pNext->width < 100) + continue; + } + } +#endif + //if (strcmp(pNext->name, "_") == 0) + // strcpy(pNext->name, " "); + + //printf("\n----------area:%s\n", (PosInfo + pNext->parent_idx)->properties.area); + + if (featureType & FEATURE_LPR_USA) { + if (strlen((PosInfo + pNext->parent_idx)->properties.area)>=1) { + differ_top_y = 20; + } + else { + differ_top_y = 200; + } + } + else if (featureType & FEATURE_LPR_TWN) { + differ_top_y = 20; + //printf("\n---------TW\n"); + } + else { + differ_top_y = 20; + } + + int check_if_the_first_word = 0; + if (enable_the_first_word == 0) { + for (int j = i + 1; j < total_element_size; j++) { + pNext2 = PosInfo + j; + //printf("\n-----yyyy:%d,%f,%f\n", abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)), pNext->top_y, pNext2->top_y); + if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { + + } + else { + if (pNext->top_y <= pNext2->top_y) { + + } + else { + check_if_the_first_word = 1; + } + } + + enable_the_first_word = 1; + break; + } + } + + int check_the_same_left_x = 0; + + for (int j = i - 1; j < i && j >= 0; j++) { + pNext2 = PosInfo + j; + if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { + if ((j - 1) >= 0) { + pNext_correct = PosInfo + (j - 1); + if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { + (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); + } + } + check_the_same_left_x = 1; + } + break; + } + + + if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { + if (strlen((PosInfo + pNext->parent_idx)->properties.plate) == 0) { + if (featureType & FEATURE_LPR_MEA) { + //printf("area: %s, country: %s \n", (PosInfo + pNext->parent_idx)->properties.area, (PosInfo + pNext->parent_idx)->properties.country); + + //check number level + //printf("B level: %d , s = %s\n", pNext->number_row, pNext->name); + + memset((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, '\0', sizeof((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name)); + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = 0; + + + ///record mea number + (PosInfo + pNext->parent_idx)->plate_number_count = 0; + mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; + + if (isdigit(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; + //printf("isdigit: %s \n", pNext->name); + } + + if (isalpha(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; + //printf("isalpht: %s \n", pNext->name); + } + + strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; + + //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); + + (PosInfo + pNext->parent_idx)->plate_number_count++; + + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; + } + else { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; + } + + //float temp = pNext->confidence; + //(PosInfo + pNext->parent_idx)->confidence = temp; + //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + } + else { + if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) + { + if (featureType & FEATURE_LPR_MEA) + { + + //check number level + //printf("A level: %d , s = %s, box_x = %f\n", pNext->number_row, pNext->name, pNext->box_x); + + ///record mea number + mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; + + if (isdigit(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; + //printf("isdigit: %s \n", pNext->name); + } + + if (isalpha(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; + //printf("isalpht: %s \n", pNext->name); + } + + strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; + + //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); + + (PosInfo + pNext->parent_idx)->plate_number_count++; + + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + //printf("plate %d name = %s, y = %f, plate_y = %f, row = %d\n", i, (PosInfo + pNext->parent_idx)->properties.plate, pNext->top_y, (PosInfo + pNext->parent_idx)->plate_char_top_y, pNext->number_row); + } + else { + if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + + //float temp = (PosInfo + pNext->parent_idx)->confidence; + //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); + } + } + } + else { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + //float temp = (PosInfo + pNext->parent_idx)->confidence; + //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); + } + //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + } + } + + + } + } + } + + enable_the_first_word = 0; + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (IsANPRCategory(pNext->engine_type)) + { + if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) + { + + if (pNext->obj_type == _PREFIX) + { + if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) + continue; + } +#if 0 + if (featureType & FEATURE_LPR_TWN) { + if (activeDisplayDash) + { + if (pNext->obj_type == _DASH) + { + if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { + strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); + } + } + } + } +#endif +#if 0 + if (get_g_ori_yuv_width() <= 1280) { + if (pNext->width < 70) + continue; + } + else { + if (pNext->width < 100) + continue; + } +#endif + + if (featureType & FEATURE_LPR_USA) { + if (strlen((PosInfo + pNext->parent_idx)->properties.area) >= 1) { + differ_top_y = 20; + } + else { + differ_top_y = 200; + } + } + else if (featureType & FEATURE_LPR_TWN) { + differ_top_y = 20; + } + else { + differ_top_y = 20; + } + + int check_if_the_first_word = 0; + if (enable_the_first_word == 0) { + for (int j = i + 1; j < total_element_size; j++) { + pNext2 = PosInfo + j; + + if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { + check_if_the_first_word = 1; + } + else { + if (pNext->top_y <= pNext2->top_y) { + check_if_the_first_word = 1; + } + else { + + } + } + + enable_the_first_word = 1; + break; + } + } + + int check_the_same_left_x = 0; + + for (int j = i - 1; j < i && j >= 0; j++) { + pNext2 = PosInfo + j; + if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { + if ((j - 1) >= 0) { + pNext_correct = PosInfo + (j - 1); + if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { + (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); + } + } + check_the_same_left_x = 1; + + } + break; + } + + if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { + if (strlen((PosInfo + pNext->parent_idx)->properties.plate) >= 0) { + if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) + { + if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { + + } + else { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + //float temp = (PosInfo + pNext->parent_idx)->confidence; + //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); + } + } + //printf("[2]%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + } + } + } + } + } +} +#endif +void ReplacePlateWithDB(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { + detection_pos *pNext = NULL; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_type != _PLATE) + { + continue; + } + + if (strlen(pNext->properties.plate) <= 0) + { + continue; + } + + if (pNext->confidence <= 0.0) + { + continue; + } + + if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) + { + for (int index_levenshtein = 0; index_levenshtein <= atoi(viewChannelData[tracking_channel_idx].levenshtein_distance); index_levenshtein++) { + int check_if_OK = 0; + + char afterBuf[256] = { 0 }; + strcpy(afterBuf, pNext->properties.plate); + + char afterBuf_dest[256] = { 0 }; + + if (check_if_in_white(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { + if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { + strcpy(pNext->properties.plate, afterBuf_dest); + } + check_if_OK = 1; + break; + } + else if (check_if_in_black(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { + if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { + strcpy(pNext->properties.plate, afterBuf_dest); + } + check_if_OK = 1; + break; + } + + if (check_if_OK == 1) + break; + } + } + else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + pNext->confidence = 0.0; + } + } +} + +void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType,int tracking_channel_idx) { + detection_pos *pNext = NULL,*pNext1 = NULL; + detection_pos pNext_plate; + double iDiffSec = 0.0; + //float diff_box_y = 0; + + //g_PlateFilterTime = 3; + //g_PlateFilterTimes = 10; + //g_PlateRecorderFreeTime = 6; + g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; + g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; + //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; + + g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 + if (g_PlateRecorderFreeTime == 0) { + g_PlateRecorderFreeTime = 1; + } + + if (g_PlateFilterTime == 0) { + g_PlateFilterTime = 1; + } + + if (g_PlateFilterTimes == 0) { + g_PlateFilterTimes = 1; + } + + //AۦPPu1C + //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); + + //Free over Recoder time + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_UpdateTime); + //printf("\nFFF------------[%d]iDiffSec:%lf,g_PlateRecorderFreeTime:%d\n",j, iDiffSec, g_PlateRecorderFreeTime); + if (g_PlateRecorderFreeTime >= 1 && iDiffSec > (double)g_PlateRecorderFreeTime) + { + g_PlateRecorderList[j].iGetCounter = 0; + g_PlateRecorderList[j].t_UpdateTime = 0; + g_PlateRecorderList[j].t_FirstGetTime = 0; + g_PlateRecorderList[j].t_LoopTime = 0; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PlateRecorderList[j].check_if_counted[m] = 0; + } + g_PlateRecorderList[j].iIfUse = 0; + } + } + } + + //printf("---------> ver EEE \n"); + + //Filter plate by time and frequency + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->confidence <= 0.0) + { + continue; + } + + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + { +#if 1 + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + pNext_plate.left_x = g_PlateRecorderList[j].box_x; + pNext_plate.top_y = g_PlateRecorderList[j].box_y; + pNext_plate.width = g_PlateRecorderList[j].box_w; + pNext_plate.height = g_PlateRecorderList[j].box_h; + pNext_plate.center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2.0; + pNext_plate.center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2.0; + + + + if ((detection_overlap_ratio(&pNext_plate, pNext) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(&pNext_plate, pNext) > (90.0 / 100.0) || ((pNext_plate.center_x <= pNext->left_x + pNext->width && pNext_plate.center_x >= pNext->left_x) && + (pNext_plate.center_y <= pNext->top_y + pNext->height && pNext_plate.center_y >= pNext->top_y)) + ) + { + pNext->linked_plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->linked_plate); + strcpy(pNext->car_type_name, pNext->name); + break; + } + } + } +#endif + } + else if(IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) + { + char afterBuf[256] = { 0 }; + + strcpy(afterBuf, pNext->properties.plate); + + //printf("\n-----------afterBuf:%s\n", afterBuf); + + pNext->properties.plate_length = Modify_Plate_and_Recount_Length(afterBuf, pNext->properties.plate); + + //printf("\n-----------[fff]pNext->properties.plate:%s\n", pNext->properties.plate); + + pNext->linked_plate_length = pNext->properties.plate_length; + strcpy(pNext->linked_plate, pNext->properties.plate); + + if ((pNext->properties.plate_length < atoi(viewChannelData[0].min_characters) || + pNext->properties.plate_length > atoi(viewChannelData[0].max_characters)) && strcmp(pNext->name, "ambulance") != 0 && strcmp(pNext->name, "blank") != 0 && strcmp(pNext->name, "stop_sign") != 0 && strcmp(pNext->name, "face") != 0) + { + + } + else + { + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET) { + if (viewChannelData[0].enable_traffic) { + for (int m = 0; m < total_element_size; m++) { + pNext1 = PosInfo + m; + if (IsVehicleCategory(pNext1) || IsMotorbikeCategory(pNext1)) { + if (detection_overlap_ratio(pNext, pNext1) > (90.0 / 100.0) || ((pNext->center_x <= pNext1->left_x + pNext1->width && pNext->center_x >= pNext1->left_x) && + (pNext->center_y <= pNext1->top_y + pNext1->height && pNext->center_y >= pNext1->top_y)) + ) + { + strcpy(pNext->car_type_name, pNext1->name); + break; + } + } + } + } + } + + int iFindMatchPlate = 0; + int index_g_PlateRecorderList_max = -1; + int iGetCounter_max = 0; + int record_plate_index[MAX_PLATE_RECORDER] = { 0 }; + int size_record_plate = 0; + + //printf("\n-----------Plate:%s\n", pNext->properties.plate); + + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 + && strcmp(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) + { + iFindMatchPlate = 1; + g_PlateRecorderList[j].t_UpdateTime = time(0); + g_PlateRecorderList[j].iGetCounter++; + + if (strlen(pNext->car_type_name) >= 1) { + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + } + else { + strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); + } + + g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; + g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; + g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; + g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; + + g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; + g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { + if (g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes + 100) + { + g_PlateRecorderList[j].iGetCounter = g_PlateFilterTimes + 100; + } + } + break; + } + } + } + + if (iFindMatchPlate == 0) + { + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 0) + { + if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { + if (strstr(pNext->properties.plate, "-") != NULL) { + g_PlateRecorderList[j].existing_dash = 1; + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + + if (strcmp(pNext->name, "ambulance") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "blank") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); + } + + g_PlateRecorderList[j].t_FirstGetTime = time(0); + g_PlateRecorderList[j].t_LoopTime = 0; + g_PlateRecorderList[j].t_UpdateTime = time(0); + g_PlateRecorderList[j].iGetCounter = 1; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PlateRecorderList[j].check_if_counted[m] = 0; + } + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + g_PlateRecorderList[j].last_box_x = pNext->left_x; + g_PlateRecorderList[j].last_box_y = pNext->top_y; + g_PlateRecorderList[j].last_box_w = pNext->width; + g_PlateRecorderList[j].last_box_h = pNext->height; + + g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; + g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; + + g_PlateRecorderList[j].iPlateZoomOutCounter = 0; + g_PlateRecorderList[j].iPlateZoomInCounter = 0; + + g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + + g_PlateRecorderList[j].iIfUse = 1; + iFindMatchPlate = 1; + break; + } + } + + if (iFindMatchPlate == 0) { + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iGetCounter <= 0) + { + if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { + if (strstr(pNext->properties.plate, "-") != NULL) { + g_PlateRecorderList[j].existing_dash = 1; + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + + if (strcmp(pNext->name, "ambulance") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "blank") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); + } + + g_PlateRecorderList[j].t_FirstGetTime = time(0); + g_PlateRecorderList[j].t_LoopTime = 0; + g_PlateRecorderList[j].t_UpdateTime = time(0); + g_PlateRecorderList[j].iGetCounter = 1; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PlateRecorderList[j].check_if_counted[m] = 0; + } + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + g_PlateRecorderList[j].last_box_x = pNext->left_x; + g_PlateRecorderList[j].last_box_y = pNext->top_y; + g_PlateRecorderList[j].last_box_w = pNext->width; + g_PlateRecorderList[j].last_box_h = pNext->height; + + g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; + g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; + + g_PlateRecorderList[j].iPlateZoomOutCounter = 0; + g_PlateRecorderList[j].iPlateZoomInCounter = 0; + + g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + + g_PlateRecorderList[j].iIfUse = 1; + iFindMatchPlate = 1; + break; + } + } + } + } + + time_t early_t_FirstGetTime = time(0); + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + //printf("\n-----sPlateNumber:%s,plate:%s,levenshtein_distance:%d\n", g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && + LevenshteinDistance(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + + if (g_PlateRecorderList[j].t_FirstGetTime < early_t_FirstGetTime) { + early_t_FirstGetTime = g_PlateRecorderList[j].t_FirstGetTime; + } + + record_plate_index[size_record_plate] = j; + size_record_plate++; + } + } + } + + for (int temp_j = 0; temp_j < size_record_plate; temp_j++) + { + int j = record_plate_index[temp_j]; + g_PlateRecorderList[j].t_FirstGetTime = early_t_FirstGetTime; + + if (g_PlateRecorderList[j].iGetCounter > iGetCounter_max || + (index_g_PlateRecorderList_max >= 0 && iGetCounter_max >= 1 && g_PlateRecorderList[j].iGetCounter == iGetCounter_max && g_PlateRecorderList[j].t_UpdateTime > g_PlateRecorderList[index_g_PlateRecorderList_max].t_UpdateTime)) { + + iDiffSec = difftime(time(0), g_PlateRecorderList[j].t_FirstGetTime); + if (iDiffSec >= (double)g_PlateFilterTime || g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes) + { + index_g_PlateRecorderList_max = j; + iGetCounter_max = g_PlateRecorderList[j].iGetCounter; + } + } + + //printf("\n---iGetCounter:%d,iGetCounter_max:%d,%s\n", g_PlateRecorderList[j].iGetCounter, iGetCounter_max, g_PlateRecorderList[j].sPlateNumber); + } + + if (index_g_PlateRecorderList_max >= 0) { + int j = index_g_PlateRecorderList_max; + iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_FirstGetTime); + + if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { + + if (strlen(pNext->car_type_name) >= 1) { + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + } + else { + strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); + } + + g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; + g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; + g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; + g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; + + g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; + g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + //printf("\n-----------[%d]pNext->properties.plate up:%s,g_Plate:%s\n",j, pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber); + pNext->properties.plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate); + //printf("\n-----------pNext->properties.plate down:%s\n", pNext->properties.plate); + pNext->linked_plate_length = pNext->properties.plate_length; + strcpy(pNext->linked_plate, pNext->properties.plate); + + if((int)iDiffSec > 0 && ((int)iDiffSec) % g_PlateFilterTime == 0){ + for (int index_record = 0; index_record < size_record_plate; index_record++) { + if (record_plate_index[index_record] != j) { + g_PlateRecorderList[index_record].iGetCounter = (g_PlateRecorderList[index_record].iGetCounter / 2) - 1; + if(g_PlateRecorderList[index_record].iGetCounter <= 0) + g_PlateRecorderList[index_record].iGetCounter = 0; + } + } + } + + if (strcmp(heartbeatData.enable_only_once_to_post, "Yes") == 0) { + if (g_PlateRecorderList[j].t_LoopTime == 0) { + g_PlateRecorderList[j].t_LoopTime = time(0); + } + + double iDiffLoopSec = difftime(time(0), g_PlateRecorderList[j].t_LoopTime); + if ((int)iDiffLoopSec > 0 && ((int)iDiffLoopSec) % g_PlateFilterTime == 0) { + for (int k = 0; k < MAX_TRACKING_NUM; k++) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1 && + strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, g_PlateRecorderList[j].sPlateNumber) == 0) + { + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + pNext->check_if_having_been_counted[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][k].check_if_having_been_counted[index_zone] = 0; + g_PlateRecorderList[j].check_if_counted[index_zone] = 0; + } + g_TrackingRecords[tracking_channel_idx][k].disappear_count = 0; + break; + } + } + + for (int k = 0; k < MAX_POST_RECODER_SIZE; k++) + { + if (g_PostRecorderList[k].iIfUse == 0 && g_longterm_PostRecorderList[k].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[k].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + g_PostRecorderList[k].iIfUse = 0; + g_PostRecorderList[k].t_FirstGetTime = 0; + g_PostRecorderList[k].t_FirstGetTime_total = 0; + g_PostRecorderList[k].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[k].check_if_post[m] = 0; + } + g_PostRecorderList[k].check_if_cloud = 0; + g_PostRecorderList[k].check_if_cloud_v2 = 0; + g_PostRecorderList[k].check_if_cloud_record_v2 = 0; + g_PostRecorderList[k].check_if_email = 0; + g_PostRecorderList[k].check_if_ftp = 0; + g_PostRecorderList[k].check_if_getalarmmotion = 0; + + g_PostRecorderList[k].box_x = 0; + g_PostRecorderList[k].box_y = 0; + g_PostRecorderList[k].box_w = 0; + g_PostRecorderList[k].box_h = 0; + + g_PostRecorderList[k].object_id = 0; + g_PostRecorderList[k].zone_idx = 0; + strcpy(g_PostRecorderList[k].sPlateNumber, ""); + + g_PostRecorderList[k].count_trigger = 0; + //g_PostRecorderList[k].the_same_id = 0; + } + } + + if (g_longterm_PostRecorderList[k].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_longterm_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + g_longterm_PostRecorderList[k].iIfUse = 0; + g_longterm_PostRecorderList[k].t_FirstGetTime = 0; + g_longterm_PostRecorderList[k].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[k].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[k].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[k].check_if_cloud = 0; + g_longterm_PostRecorderList[k].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[k].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[k].check_if_email = 0; + g_longterm_PostRecorderList[k].check_if_ftp = 0; + g_longterm_PostRecorderList[k].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[k].box_x = 0; + g_longterm_PostRecorderList[k].box_y = 0; + g_longterm_PostRecorderList[k].box_w = 0; + g_longterm_PostRecorderList[k].box_h = 0; + + g_longterm_PostRecorderList[k].object_id = 0; + g_longterm_PostRecorderList[k].zone_idx = 0; + strcpy(g_longterm_PostRecorderList[k].sPlateNumber, ""); + + g_longterm_PostRecorderList[k].count_trigger = 0; + //g_longterm_PostRecorderList[k].the_same_id = 0; + } + } + } + + g_PlateRecorderList[j].t_LoopTime = time(0); + } + } + + g_PlateRecorderList[j].t_UpdateTime = time(0); + for (int index_record = 0; index_record < size_record_plate; index_record++) { + if (record_plate_index[index_record] != j) { + g_PlateRecorderList[index_record].t_UpdateTime = time(0); + } + } + } + } + else { + pNext->confidence = 0; + } + } + + } + else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + pNext->confidence = 0.0; + } + } + + qsort(&g_PlateRecorderList, MAX_PLATE_RECORDER, sizeof(PlateRecoder), sort_record_plate); +} + +void ObjectFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { + + detection_pos *pNext = NULL/*, *pNext1 = NULL*/; + //detection_pos pNext_plate; + double iDiffSec = 0.0; + //float diff_box_y = 0; + + //g_PlateFilterTime = 3; + //g_PlateFilterTimes = 10; + //g_PlateRecorderFreeTime = 6; + //g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; + //g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; + //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; + + //g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 + //if (g_PlateRecorderFreeTime == 0) { + //g_PlateRecorderFreeTime = 2; + //} + + int object_free_time = atoi(SystemSetting.tracking_id_dwell) + 1;//2 + + //AۦPPu1C + //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); + + //Free over Recoder time + for (int j = 0; j < MAX_OBJECT_RECORDER; j++) + { + if (g_ObjectRecorderList[j].iIfUse == 1) + { + iDiffSec = difftime(time(0),g_ObjectRecorderList[j].t_UpdateTime); + //printf("\nEEE------------iDiffSec:%d\n", iDiffSec); + if (object_free_time >= 1 && iDiffSec > (double)object_free_time) + { + g_ObjectRecorderList[j].iIfUse = 0; + g_ObjectRecorderList[j].iGetCounter = 0; + g_ObjectRecorderList[j].t_UpdateTime = 0; + g_ObjectRecorderList[j].t_FirstGetTime = 0; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_ObjectRecorderList[j].check_if_counted[m] = 0; + } + g_ObjectRecorderList[j].box_x = 0; + g_ObjectRecorderList[j].box_y = 0; + g_ObjectRecorderList[j].box_w = 0; + g_ObjectRecorderList[j].box_h = 0; + g_ObjectRecorderList[j].iTrackingID = 0; + } + } + } + + //printf("---------> ver EEE \n"); + + //Filter plate by time and frequency + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_tracking_id_idx < 0 || pNext->obj_tracking_id <= 0) { + + } + else { + if (IsANPRCategory(pNext->engine_type)) { + + } + else { + if (strlen(pNext->name) >= 1) + { + int iFindMatchObject = 0; + + for (int j = 0; j < MAX_OBJECT_RECORDER; j++) + { + //printf("if %d use = %d \n", j, g_ObjectRecorderList[j].iIfUse); + if (g_ObjectRecorderList[j].iIfUse == 1) + { + if (g_ObjectRecorderList[j].iTrackingID == pNext->obj_tracking_id) + { + //printf("find match id \n"); + iFindMatchObject = 1; + g_ObjectRecorderList[j].t_UpdateTime = time(0); + //g_ObjectRecorderList[j].iGetCounter++; + + //g_ObjectRecorderList[j].left_x = pNext->left_x; + //g_ObjectRecorderList[j].top_y = pNext->top_y; + g_ObjectRecorderList[j].box_x = pNext->left_x; + g_ObjectRecorderList[j].box_y = pNext->top_y; + g_ObjectRecorderList[j].box_w = pNext->width; + g_ObjectRecorderList[j].box_h = pNext->height; + + //printf("%d history data, x = %f \n", j, g_ObjectRecorderList[j].box_x); + //printf("y = %f ", g_ObjectRecorderList[j].box_y); + //printf("h = %f ", g_ObjectRecorderList[j].box_h); + //printf("w = %f ", g_ObjectRecorderList[j].box_w); + //printf("ob_id = %d \n", g_ObjectRecorderList[j].iTrackingID); + break; + } + } + } + + //printf("iFindMatch = %d \n", iFindMatchObject); + + if (iFindMatchObject == 0) + { + for (int j = 0; j < MAX_OBJECT_RECORDER; j++) + { + if (g_ObjectRecorderList[j].iIfUse == 0) + { + g_ObjectRecorderList[j].iIfUse = 1; + g_ObjectRecorderList[j].t_FirstGetTime = time(0); + g_ObjectRecorderList[j].t_UpdateTime = time(0); + g_ObjectRecorderList[j].iGetCounter = 1; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_ObjectRecorderList[j].check_if_counted[m] = 0; + } + g_ObjectRecorderList[j].box_x = pNext->left_x; + g_ObjectRecorderList[j].box_y = pNext->top_y; + g_ObjectRecorderList[j].box_w = pNext->width; + g_ObjectRecorderList[j].box_h = pNext->height; + + g_ObjectRecorderList[j].iTrackingID = pNext->obj_tracking_id; + //g_ObjectRecorderList[j].iTrackingIDidx = pNext->obj_tracking_id_idx; + + break; + } + //else if (j == MAX_OBJECT_RECORDER - 1) { + //printf("\n---------MAX_OBJECT_RECORDER - 1\n"); + //} + } + } + + } + } + } + } + + qsort(&g_ObjectRecorderList, MAX_OBJECT_RECORDER, sizeof(ObjectRecoder), sort_record_object); +} +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void AddTWPlateDASH(detection_pos* PosInfo, int total_element_size, int featureType) +{ + if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { + detection_pos* pNext = NULL; + + int iPlate_len = 0; + + int iFront_alpha_num = 0; + int iFront_digit_num = 0; + int iBack_alpha_num = 0; + int iBack_digit_num = 0; + + //for TWN plate, add dash if miss the dash. + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_type != _PLATE) + { + continue; + } + + if (strlen(pNext->properties.plate) <= 0) + { + continue; + } + + if (pNext->confidence <= 0.0) + { + continue; + } + + if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) { + //Plate miss "-" + if (strstr(pNext->properties.plate, "-") == NULL) + { + iPlate_len = strlen(pNext->properties.plate); + + if (iPlate_len == 7) + { + insert_string(pNext->properties.plate, "-", 3); + } + else if (iPlate_len == 6) + { + iFront_alpha_num = 0; + iFront_digit_num = 0; + iBack_alpha_num = 0; + iBack_digit_num = 0; + int iFront_digit_num_length_4 = 0; + int iBack_digit_num_length_4 = 0; + int iFront_alpha_num_length_2 = 0; + int iBack_alpha_num_length_2 = 0; + + + for (int j = 0; j < 4; j++) + { + if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) + { + iFront_digit_num++; + } + + if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_digit_num++; + } + + if (j <= 3 && isdigit(pNext->properties.plate[j]) != 0) + { + iFront_digit_num_length_4++; + } + + if (j <= 3 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_digit_num_length_4++; + } + + if (j <= 2 && isalpha(pNext->properties.plate[j]) != 0) + { + iFront_alpha_num++; + } + + if (j <= 2 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_alpha_num++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) + { + iFront_alpha_num_length_2++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_alpha_num_length_2++; + } + } + + if ((iFront_digit_num == 3 && iBack_alpha_num == 3) || + (iFront_alpha_num == 3 && iBack_digit_num == 3)) { + insert_string(pNext->properties.plate, "-", 3); + } + else if ((iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 2) || + (iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 1)) { + insert_string(pNext->properties.plate, "-", 4); + } + else if (iFront_alpha_num_length_2 <= 2 && iFront_alpha_num_length_2 >= 1 && iBack_digit_num_length_4 == 4) { + insert_string(pNext->properties.plate, "-", 2); + } + else if (iFront_alpha_num <= 2 && iFront_alpha_num >= 1 && iBack_digit_num == 3) { + insert_string(pNext->properties.plate, "-", 3); + } + } + else if (iPlate_len == 5) + { + iFront_alpha_num = 0; + iFront_digit_num = 0; + iBack_alpha_num = 0; + iBack_digit_num = 0; + + for (int j = 0; j < 3; j++) + { + if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) + { + iFront_digit_num++; + } + + if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_digit_num++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) + { + iFront_alpha_num++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_alpha_num++; + } + } + + if ((iFront_digit_num == 3 && iBack_alpha_num == 2) || + (iFront_digit_num == 3 && iBack_digit_num == 1 && iBack_alpha_num == 1)) { + insert_string(pNext->properties.plate, "-", 3); + } + else if ((iFront_alpha_num == 2 && iBack_digit_num == 3) || + (iFront_alpha_num == 1 && iFront_digit_num == 1 && iBack_digit_num == 3)) { + insert_string(pNext->properties.plate, "-", 2); + } + } + else if (iPlate_len == 4) + { + insert_string(pNext->properties.plate, "-", 2); + } + + //printf(">>>>>>>>>>>>>>>>>>>>>>>> plate: %s \n", pNext->properties.plate); + } + + if (strstr(pNext->properties.plate, "-") == NULL) + { + pNext->confidence = 0.0; + } + } + else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + pNext->confidence = 0.0; + } + } + } +} + +void MEAPlateRule(detection_pos* PosInfo, int total_element_size) +{ + detection_pos* pNext = NULL; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (IsANPRCategory_L_Plate(pNext->name)) + { + //printf("%d plate %d name = %s \n", i, pNext->parent_idx, pNext->properties.plate); + check_rule(pNext); + } + } + //printf("**************************************** \n"); +} +#endif + +#if 1 +int CheckTriggerCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int tracking_obj_idx, int trigger_type, int total_element_size, detection_pos* PosInfo, int result_idx) +{ + //int nNotChecked = 0; + int nNeedTrigger = 0; + double diffSecs = 0; + double diffSecs2 = 0; + int detection_count = 0; + //char MetaData1[BUFSIZE] = { 0 }; + //char MetaData2[BUFSIZE] = { 0 }; + //char MetaOut1[512][50] = { 0 }; + //char MetaOut2[512][50] = { 0 }; + double d_no_parking_time = (double)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { + d_no_parking_time = (double)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); + } + + detection_count = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + + detection_pos* pNext_b; + + //for (int i = 0; i < MAX_TRIGGER_EVENT; i++) + //{ + +#if 0 + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].checked <= 0) + return nNeedTrigger; +#endif + + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + //char metadata1[512][STRSPLIT_SIZE] = { 0 }; //for vehicle + //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); + + //printf("\n----CheckTriggerCondition--- start\n"); + int metadata1_num = get_metadata1_num(detection_zone_idx); + //printf("\n----CheckTriggerCondition--- end\n"); + + int temp_enable_person_for_metadata = person_if_existing_in_metaout(detection_zone_idx); + //for (int i = 0; i < metadata1_num; i++) + //{ + //UpperToLower(metadata1[i]); + //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); + + //if (strcmp("person", MetaOut1[i]) == 0) { + //temp_enable_person_for_metadata = 1; + //} + //} + + g_enable_person_for_metadata[detection_zone_idx] = temp_enable_person_for_metadata; + +#if 0 + char metadata2[10][STRSPLIT_SIZE] = { 0 }; //for person + strcpy(MetaData2, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata2); + int metadata2_num = StrSplit(MetaData2, metadata2, ","); + for (int i = 0; i < metadata2_num; i++) + { + UpperToLower(metadata2[i]); + TrimSpace(MetaOut2[i], sizeof(MetaOut2[i]), metadata2[i], 0); + } +#endif + +#if 0 + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); +#endif + //for name comparison without case sensitive + + //float dewell_time = 2.78;//2.78 //4.2 + //float dewell_time2 = 4.2; + + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + if (trigger_type == TRIGGER_ALLOW_LIST) + { + if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || + (strcmp(pNext->name, "ambulance") == 0) + || (strcmp(pNext->name, "blank") == 0) + || (strcmp(pNext->name, "stop_sign") == 0) + //|| (strcmp(pNext->name, "face") == 0) + ) + { + char afterBuf[256] = { 0 }; + if (strcmp(pNext->name, "ambulance") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "blank") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else + strcpy(afterBuf, pNext->properties.plate); + + if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) +#ifdef GY_OS_AMBA + //|| check_if_in_white_face(pNext->FDFR.face_name) +#endif + ) { + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + /*if (strcmp(pNext->name, "face") == 0) + { +#ifdef GY_OS_AMBA + get_schedule_start_in_white_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_white_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_white_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); +#endif + } + else */{ + get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + } + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + ///////////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + + //printf("trigger type 2 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //printf("trigger type 3 \n"); + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#if 0 + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } +#endif + + //printf("trigger type 4 \n"); + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_BLOCK_LIST) + { + if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) + || (strcmp(pNext->name, "blank") == 0) + || (strcmp(pNext->name, "stop_sign") == 0) + //|| (strcmp(pNext->name, "face") == 0) + ) + { + char afterBuf[256] = { 0 }; + if (strcmp(pNext->name, "ambulance") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "blank") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else + strcpy(afterBuf, pNext->properties.plate); + //printf("trigger type 1111 : %s\n", afterBuf); + + if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) +#ifdef GY_OS_AMBA + //|| check_if_in_black_face(pNext->FDFR.face_name) +#endif + ) { + //printf("trigger type 2 \n"); + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + /*if (strcmp(pNext->name, "face") == 0) + { +#ifdef GY_OS_AMBA + get_schedule_start_in_black_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_black_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_black_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); +#endif + } + else */{ + get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + } + + //printf("\n--------schedule_start:%s,schedule_end:%s\n", schedule_start, schedule_end); + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + /////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#if 0 + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } +#endif + + + //printf("\nnNeedTrigger:%d\n", nNeedTrigger); + //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + } + } + } + else if (trigger_type == TRIGGER_GUEST_LIST) + { + if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) + || (strcmp(pNext->name, "blank") == 0) + || (strcmp(pNext->name, "stop_sign") == 0) + //|| (strcmp(pNext->name, "face") == 0) + ) + { + char afterBuf[256] = { 0 }; + if (strcmp(pNext->name, "ambulance") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "blank") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else + strcpy(afterBuf, pNext->properties.plate); + int check_if_white_or_black_within_lifetime = 0; + +#if 1 + if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + ///////////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + check_if_white_or_black_within_lifetime = 1; + } + } + } + + if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { + //printf("trigger type 2 \n"); + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + /////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + check_if_white_or_black_within_lifetime = 1; + } + } + } +#endif + if (check_if_white_or_black_within_lifetime == 0) { + //printf("trigger type 2 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //printf("trigger type 3 \n"); + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#if 0 + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } +#endif + + //printf("trigger type 4 \n"); + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + + } + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT) + { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n");*/ + + + + int check_if_stability = 1; + + + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if(check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx)==1) + { + if (IsANPRCategory_L_Plate(pNext->name)==1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + if (IsANPRCategory_L_Plate(pNext->name) == 1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + if (IsANPRCategory_L_Plate(pNext->name) == 1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + if (IsANPRCategory_L_Plate(pNext->name) == 1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + } + else if (trigger_type == TRIGGER_PARKING_VIOLATION) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { + //printf("1111 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + // printf("1111-1 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + // printf("1111-2 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + int nDiffSecs2 = (int)diffSecs2; + float distCenter = 0; + pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; + distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + if (/*(strcmp(ObjectName, "car") == 0 || (strcmp(ObjectName, "truck") == 0)) + && */distCenter > 1) + { + //printf("distCenter = %f \n", distCenter); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } + + //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); + //printf("\ndiffSecs: %d\n",(int)diffSecs); + //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; + + //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0 /*|| strstr(ObjectName, "plate") != NULL*/) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { +#if 0 //Open for عq קK먮~ + //printf("AAAAAAA %s \n", "nNeedTrigger 1"); + //nNeedTrigger = 1; + //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; + //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + //printf("center diff = %d \n", distCenter); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] + //check prev iou > 60 + //printf("iou self 1 = %d \n", pNext->iou_prev_self); + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 1; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else + //printf("33334444 \n"); + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; +#endif + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { +#if 0 //Open for عq קK먮~ + //printf("iou self 2 = %d \n", pNext->iou_prev_self); + //check prev iou > 60 + + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 2; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else //Normal + if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) + { + nNeedTrigger = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#endif + } +#if 0 //Open for عq קK먮~ + if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) + { + + pNext->trigger_type = trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + break; + } + else + break; +#else + //printf("33338888 \n"); + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; +#endif + + } + } + } + } + + //printf("4444 \n"); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + + } + } + else if (trigger_type == TRIGGER_ZONE_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if(check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#ifdef GY_OS_AMBA + else if (trigger_type == TRIGGER_SPEED_HIGH) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_SPEED_LOW) + { + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#endif + else if (trigger_type == TRIGGER_ALL_OBJECTS) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + //printf("\nAAAAAAAAAAA: 1\n"); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + + int nearest_index = -1; + float nearest_distance = (float)INF; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) { + if (check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx) && IsGarbageCategory(pNext_bring)) + { + //nNeedTrigger = 1; + //printf("\n-----plate(%f,%f),object(%f,%f)\n", pNext->center_x, pNext->center_y, pNext_bring->center_x, pNext_bring->center_y); + + float temp_nearest_distance = sqrt(pow(pNext->center_x- pNext_bring->center_x,2)+ pow(pNext->center_y - pNext_bring->center_y,2)); + if (temp_nearest_distance < nearest_distance) { + nearest_index = j; + nearest_distance = temp_nearest_distance; + } + } + } + } + } + + if (nearest_index >= 0) { + + detection_pos *pNext_bring = PosInfo + nearest_index; + + pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; + pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; + pNext_bring->zone_violation_idx[detection_zone_idx] = 1; + + strcpy(pNext_bring->linked_plate, pNext->properties.plate); + pNext_bring->linked_plate_length = pNext->properties.plate_length; + + if (pNext_bring->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; + } + } + } + } + } + else { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 /*&& ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)*/) { + + int nearest_index = -1; + float nearest_distance = (float)INF; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + + if (check_if_object_in_zone_simple_version_not_plate(pNext_bring, detection_zone_idx) /*&& IsGarbageCategory(pNext_bring)*/) + { + float temp_nearest_distance = sqrt(pow(pNext->center_x - pNext_bring->center_x, 2) + pow(pNext->center_y - pNext_bring->center_y, 2)); + if (temp_nearest_distance < nearest_distance) { + nearest_index = j; + nearest_distance = temp_nearest_distance; + } + } + } + } + + if (nearest_index >= 0) { + + detection_pos *pNext_bring = PosInfo + nearest_index; + + pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; + pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; + pNext_bring->zone_violation_idx[detection_zone_idx] = 1; + + strcpy(pNext_bring->linked_plate, pNext->properties.plate); + pNext_bring->linked_plate_length = pNext->properties.plate_length; + + if (pNext_bring->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; + } + } + } + } + } + } +#endif + } + else{ + if (trigger_type == TRIGGER_MISSING_UNATTENDED) + { + //printf("1111 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + // printf("1111-1 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + // printf("1111-2 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + int nDiffSecs2 = (int)diffSecs2; + float distCenter = 0; + pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; + distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + if ((strcmp(ObjectName, "object") == 0) && distCenter > 1) + { + //printf("distCenter = %f \n", distCenter); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } + + //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); + //printf("\ndiffSecs: %d\n",(int)diffSecs); + //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; + //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); + + if (strcmp(ObjectName,"object")==0) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { +#if 0 //Open for عq קK먮~ + //printf("AAAAAAA %s \n", "nNeedTrigger 1"); + //nNeedTrigger = 1; + //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; + //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + //printf("center diff = %d \n", distCenter); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] +//check prev iou > 60 + //printf("iou self 1 = %d \n", pNext->iou_prev_self); + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 1; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else + //printf("33334444 \n"); + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; +#endif + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { +#if 0 //Open for عq קK먮~ + //printf("iou self 2 = %d \n", pNext->iou_prev_self); + //check prev iou > 60 + + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 2; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else //Normal + if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) + { + nNeedTrigger = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#endif + } +#if 0 //Open for عq קK먮~ + if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) + { + + pNext->trigger_type = trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } +#else + //printf("33338888 \n"); + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; +#endif + + } + } + } + //printf("4444 \n"); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) + { + if (strcmp(ObjectName, "object") == 0) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT) + { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ( (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_PARKING_VIOLATION) + { + //printf("1111 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + // printf("1111-1 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + // printf("1111-2 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + int nDiffSecs2 = (int)diffSecs2; + float distCenter = 0; + pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; + distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + if (/*(strcmp(ObjectName, "car") == 0 || strcmp(ObjectName, "truck") == 0 || strcmp(ObjectName, "car_front_back") == 0)*/ + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + && distCenter > 1) + { + //printf("distCenter = %f \n", distCenter); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } + + //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); + //printf("\ndiffSecs: %d\n",(int)diffSecs); + //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); + + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + if(check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; + + //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); + //for (int j = 0; j < metadata1_num; j++) + { + if (check_vehicle_over_time(pNext, detection_zone_idx, d_no_parking_time)) /*|| strstr(ObjectName, "plate") != NULL*/ + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { +#if 0 //Open for عq קK먮~ + //printf("AAAAAAA %s \n", "nNeedTrigger 1"); + //nNeedTrigger = 1; + //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; + //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + //printf("center diff = %d \n", distCenter); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] +//check prev iou > 60 + //printf("iou self 1 = %d \n", pNext->iou_prev_self); + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 1; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else + //printf("33334444 \n"); + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; +#endif + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { +#if 0 //Open for عq קK먮~ + //printf("iou self 2 = %d \n", pNext->iou_prev_self); + //check prev iou > 60 + + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 2; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else //Normal + if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) + { + nNeedTrigger = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#endif + } +#if 0 //Open for عq קK먮~ + if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) + { + + pNext->trigger_type = trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + //else + //break; +#else + //printf("33338888 \n"); + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; +#endif + + } + } + } + } + + //printf("4444 \n"); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + else if (trigger_type == TRIGGER_ZONE_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0 || strcmp("person", pNext->name) == 0 || + // (diff_secs_in_zone >= 1 && diff_secs_in_zone > 0 && (int)(pNext->center_stability) != DIRECTION_DEFAULT)) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#ifdef GY_OS_AMBA + else if (trigger_type == TRIGGER_DISTANCE_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + //printf("\n--------g_max_tof_range:%f\n", g_max_tof_range); + //printf("\n-------atof(tofData.distance_threshold):%f\n", atof(tofData.distance_threshold)); + + int check_if_OK_tof = 0; + + if (strcmp(tofData.distance_options, "gt") == 0) { + if (strcmp(tofData.distance_min_max, "min") == 0) { + if (g_min_tof_distance > atof(tofData.distance_threshold) && pNext->min_distance != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.distance_min_max, "max") == 0) { + if (g_max_tof_distance > atof(tofData.distance_threshold) && pNext->max_distance != 0) { + check_if_OK_tof = 1; + } + } + } + else if (strcmp(tofData.distance_options, "lt") == 0) { + if (strcmp(tofData.distance_min_max, "min") == 0) { + if (g_min_tof_distance < atof(tofData.distance_threshold) && pNext->min_distance != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.distance_min_max, "max") == 0) { + if (g_max_tof_distance < atof(tofData.distance_threshold) && pNext->max_distance != 0) { + check_if_OK_tof = 1; + } + } + } + + if(check_if_OK_tof == 1) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName,"tof_point") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_HIGH_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + + int check_if_OK_tof = 0; + + if (strcmp(tofData.height_options, "gt") == 0) { + if (strcmp(tofData.height_min_max, "min") == 0) { + if (g_min_tof_height > atof(tofData.height_threshold) && pNext->min_height != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.height_min_max, "max") == 0) { + if (g_max_tof_height > atof(tofData.height_threshold) && pNext->max_height != 0) { + check_if_OK_tof = 1; + } + } + } + else if (strcmp(tofData.height_options, "lt") == 0) { + if (strcmp(tofData.height_min_max, "min") == 0) { + if (g_min_tof_height < atof(tofData.height_threshold) && pNext->min_height != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.height_min_max, "max") == 0) { + if (g_max_tof_height < atof(tofData.height_threshold) && pNext->max_height != 0) { + check_if_OK_tof = 1; + } + } + } + + if (check_if_OK_tof == 1) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName, "tof_point") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#endif + else if (trigger_type == TRIGGER_FORGET_TO_GIVE_WAY) + { + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + //pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_check_giveway[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_SPEED_HIGH) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if(pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_SPEED_LOW) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_TAMPERING) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName, "tampering") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + //{ + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //} + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + //{ + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + //{ + //nNeedTrigger = 2; //post: yes, counter: no + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //} + //} + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + } + } + else if (trigger_type == TRIGGER_ALL_OBJECTS) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + //printf("\nAAAAAAAAAAA: 1\n"); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { + int temp_count_meta = 0; + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) + { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if(check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) + //{ + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if(check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta == metadata1_num - 1) + if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + else if ((strcmp(ObjectName, "person") == 0) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + int temp_count_meta = 0; + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) + //{ + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta >= 1) + if (pNext->num_bring_with_object[detection_zone_idx] >= 1) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + else if ((IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) + + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (check_if_existing_in_metaout(BringName, detection_zone_idx) && IsGarbageCategory(pNext_bring)) + if (IsGarbageCategory(pNext_bring)) + { + //nNeedTrigger = 1; + + pNext->trigger_type = trigger_type | pNext->trigger_type; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + + if (pNext->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + } + } + } + + } + } + } + } + } + } + else { + + //printf("\nAAAAAAAAAAA: 2\n"); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + //printf("\nAAAAAAAAAAA: 2-1------%d\n", get_g_check_if_all_existing(detection_zone_idx)); + //if ((int)pNext->obj_dwell_time % 2 == 0) + if (get_g_check_if_all_existing(detection_zone_idx) == 1) + { + //printf("\nAAAAAAAAAAA: 2-2\n"); + //for (int j = 0; j < metadata1_num; j++) + { + if(check_if_object_in_zone_simple_version_not_plate(pNext, detection_zone_idx)) + { + //printf("\nAAAAAAAAAAA: 2-3\n"); + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + else if (trigger_type == TRIGGER_LACK_OF_ANY_OBJECT) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { + int temp_count_meta = 0; + + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (strcmp(BringName, MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta == metadata1_num - 1) + if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) + { + + } + else { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + else if ((strcmp(ObjectName, "person") == 0 || IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + int temp_count_meta = 0; + + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 + && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (strcmp(BringName, MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta >= 1) + if (pNext->num_bring_with_object[detection_zone_idx] >= 1) + { + + } + else { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + } + } + else + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + /*if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0)*/ { + if (get_g_check_if_NAND(detection_zone_idx) == 1) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + if (check_if_object_in_zone_simple_version(pNext, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + + + } + + } + } + } + } + else if (trigger_type == TRIGGER_QUEUING_VIOLATION) + { + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_line >= 1) { + + + } + else { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + int check_if_enable_linked_to_dwell_time = 0; +#ifdef GY_OS_V_SERIES + +#else +#if 1 + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + g_IsCustomWeight == 1) { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + //printf("\n------UU:4\n"); + + for (int i = 0; i < event_counter_num; i++) + { + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + if (strlen(eachEventCounter[i]) >= 1 && strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) + { + if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0) { + check_if_enable_linked_to_dwell_time = 1; + break; + } + } + } + if (check_if_enable_linked_to_dwell_time == 1) + break; + } + } +#endif +#endif + + if(check_if_enable_linked_to_dwell_time == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //pNext->trigger_type = trigger_type; + pNext->zone_violation_idx[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else if (check_if_enable_linked_to_dwell_time == 1) { + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //pNext->trigger_type = trigger_type; + pNext->zone_violation_idx[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + + //break; + } + } + } + } + } + } + } +#if 0 + else if (trigger_type == TRIGGER_MISSING_OBJECT_DETECTION) + { + /* + printf("\n----------------------------------\n"); + printf("\nobj_first_dwell_time: %lf\n",pNext->obj_first_dwell_time); + printf("\nobj_last_dwell_time: %lf\n", pNext->obj_last_dwell_time); + printf("\n----------------------------------\n");*/ + + /*if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + + } + }*/ + if (pNext->obj_dwell_time > g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time + d_no_parking_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + { + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = 0.0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = 0.0; + } + + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //if (diffSecs >= dewell_time2) + { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //break; + } + } + } + } + +#endif +#if 0 + if (trigger_event_type == TRIGGER_TURN_LEFT) + { + if (trigger_type == TRIGGER_TURN_LEFT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_RIGHT) + { + if (trigger_type == TRIGGER_TURN_RIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_WRONG_WAY) + { + if (trigger_type == TRIGGER_WRONG_WAY) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + { + if (trigger_type == TRIGGER_TURN_LEFT_VIOLATION) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + { + if (trigger_type == TRIGGER_TURN_RIGHT_VIOLATION) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + { + if (trigger_type == TRIGGER_U_TURN_VIOLATION) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line /*&& g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx] == backward_line*/ && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + /* + if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + */ +#endif + + /* + if (trigger_event_type == TRIGGER_BG_LEARNING) + { + if (trigger_type == TRIGGER_BG_LEARNING) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName, "bg_learning") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + } + } + }*/ + + } + + if (strcmp(SystemSetting.enable_person_independent, "Yes") == 0) { + //printf("\nTTTTTTTTTT : 1\n"); + if (strcmp(ObjectName, "person") == 0) { + int temp_count_meta = 0; + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + //printf("\nTTTTTTTTTT : 2\n"); + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + if (!IsANPRCategory(pNext_bring->engine_type)) { + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if (strcmp(BringName, "person") != 0) { + //printf("\nTTTTTTTTTT : 3\n"); + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) + { + { + + //nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext_bring->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; + pNext_bring->zone_violation_idx[detection_zone_idx] = 0; + pNext_bring->check_person_inter = 1; + if (pNext_bring->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = 0; + int det_count_temp = g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].detection_count; + if(det_count_temp >= 1) + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].prev_detections[det_count_temp - 1].check_person_inter = 1; + } + } + //printf("\nTTTTTTTTTT : 4\n"); + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + if (detection_count >= 1) + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + //printf("\nTTTTTTTTTT : 5\n"); + } + } + } + } + } + //printf("\nTTTTTTTTTT : 6\n"); + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { + if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + count_correct_meta++; + //break; + } + } + } + + if (count_correct_meta >= 1) { + nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; + + pNext->check_person_inter = 1; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + //pNext->trigger_idx[detection_zone_idx] = trigger_idx; + //pNext->zone_violation_idx[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + else { + pNext->check_person_inter = 0; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; + } + + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //pNext->num_bring_with_object[detection_zone_idx] = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + //printf("\nTTTTTTTTTT : 7\n"); + } + else { + + if (!IsANPRCategory(pNext->engine_type)) { + //printf("\nTTTTTTTTTT : 8\n"); + if (pNext->check_person_inter == 1) { + nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; + //printf("\nTTTTTTTTTT : 9\n"); + } + else { + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (diff_secs_in_zone < d_no_parking_time && diff_secs_in_zone > 0) + { + nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; + + pNext->check_person_inter = 1; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; + + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + } + //printf("\nTTTTTTTTTT : 10\n"); + } + } + else { + pNext->check_person_inter = 0; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; + //printf("\nTTTTTTTTTT : 11\n"); + } + } + } + + return nNeedTrigger; +} +#endif +#if 1 +char g_last_token_name[256] = { 0 }; +char g_last_token_confidence[10] = { 0 }; +char g_last_token_left_x[10] = { 0 }; +char g_last_token_top_y[10] = { 0 }; +char g_last_token_width[10] = { 0 }; +char g_last_token_height[10] = { 0 }; +char g_last_token_center_x[10] = { 0 }; +char g_last_token_center_y[10] = { 0 }; +char g_last_token_center_speed[35] = { 0 }; +char g_last_token_center_direction[10] = { 0 }; +char g_last_token_center_stability[10] = { 0 }; +char g_last_token_obj_tracking_id[10] = { 0 }; +char g_last_token_obj_dwell_time[20] = { 0 }; +char g_last_token_class_id[10] = { 0 }; +char g_last_token_color[20] = { 0 }; +char g_last_token_plate[256] = { 0 }; +char g_last_token_country[256] = { 0 }; +char g_last_token_area[256] = { 0 }; +char g_last_token_plate_list[256] = { 0 }; +char g_last_token_logo[256] = { 0 }; +char g_last_token_behavior_id[1024] = { 0 }; +char g_last_token_zone_id[10] = { 0 }; +char g_last_token_behavior_name[256] = { 0 }; +char g_last_token_linked_plate[256] = { 0 }; + +size_t ReplaceKeyWords(detection_pos* pNext, int space_zone,int space_id,char* InputString,char *OutputString,int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64,int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) +{ + char *replacement = NULL; + char *replacement_t = NULL; + char msg[MAX_MSG_LEN] = { 0 }; + + replacement = InputString; + + //קK᭱replacementSkfreeC + replacement_t = StrReplace(replacement, "<|test_token|>", "Hello"); + replacement = replacement_t; + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (strcmp(pNext->name, "car") == 0) { + sprintf(msg, "%s", "vehicle"); + strcpy(g_last_token_name, "vehicle"); + } + else if (strcmp(pNext->name, "person") == 0) { + sprintf(msg, "%s", "human"); + strcpy(g_last_token_name, "human"); + } + else { + sprintf(msg, "%s", pNext->name); + strcpy(g_last_token_name, pNext->name); + } + } + else { + sprintf(msg, "%s", pNext->name); + strcpy(g_last_token_name, pNext->name); + } + + replacement_t = StrReplace(replacement, "<|name|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_name); + + replacement_t = StrReplace(replacement, "<|name|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->confidence); + sprintf(g_last_token_confidence, "%d", (int)pNext->confidence); + + replacement_t = StrReplace(replacement, "<|confidence|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_confidence); + + replacement_t = StrReplace(replacement, "<|confidence|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->left_x - pNext->width / 3.0)); + sprintf(g_last_token_left_x, "%d", (int)(pNext->left_x - pNext->width / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->left_x); + sprintf(g_last_token_left_x, "%d", (int)pNext->left_x); + } + + replacement_t = StrReplace(replacement, "<|left_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_left_x); + + replacement_t = StrReplace(replacement, "<|left_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->top_y - pNext->height / 3.0)); + sprintf(g_last_token_top_y, "%d", (int)(pNext->top_y - pNext->height / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->top_y); + sprintf(g_last_token_top_y, "%d", (int)pNext->top_y); + } + + replacement_t = StrReplace(replacement, "<|top_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_top_y); + + replacement_t = StrReplace(replacement, "<|top_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->width * 5.0 / 3.0)); + sprintf(g_last_token_width, "%d", (int)(pNext->width * 5.0 / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->width); + sprintf(g_last_token_width, "%d", (int)pNext->width); + } + + replacement_t = StrReplace(replacement, "<|width|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_width); + + replacement_t = StrReplace(replacement, "<|width|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->height * 5.0 / 3.0)); + sprintf(g_last_token_height, "%d", (int)(pNext->height * 5.0 / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->height); + sprintf(g_last_token_height, "%d", (int)pNext->height); + } + + replacement_t = StrReplace(replacement, "<|height|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_height); + + replacement_t = StrReplace(replacement, "<|height|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->center_x); + sprintf(g_last_token_center_x, "%d", (int)pNext->center_x); + + replacement_t = StrReplace(replacement, "<|center_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_x); + + replacement_t = StrReplace(replacement, "<|center_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->center_y); + sprintf(g_last_token_center_y, "%d", (int)pNext->center_y); + + replacement_t = StrReplace(replacement, "<|center_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_y); + + replacement_t = StrReplace(replacement, "<|center_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + char msg_center_speed[35] = { 0 }; + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { + sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); + + if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { + strcat(msg_center_speed, " km/h"); + } + else { + strcat(msg_center_speed, " mi/h"); + } + } + else { + sprintf(msg_center_speed, "%s", ""); + } + sprintf(g_last_token_center_speed, "%s", msg_center_speed); + + replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg_center_speed, "%s", g_last_token_center_speed); + + replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { + sprintf(msg, "%d", (int)pNext->center_direction); + sprintf(g_last_token_center_direction, "%d", (int)pNext->center_direction); + } + else { + sprintf(msg, "%s", ""); + sprintf(g_last_token_center_direction, "%s", ""); + } + + replacement_t = StrReplace(replacement, "<|center_direction|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_direction); + + replacement_t = StrReplace(replacement, "<|center_direction|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { + sprintf(msg, "%d", (int)pNext->center_stability); + sprintf(g_last_token_center_stability, "%d", (int)pNext->center_stability); + } + else { + sprintf(msg, "%s", ""); + sprintf(g_last_token_center_stability, "%s", ""); + } + + replacement_t = StrReplace(replacement, "<|center_stability|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_stability); + + replacement_t = StrReplace(replacement, "<|center_stability|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->obj_tracking_id); + sprintf(g_last_token_obj_tracking_id, "%d", (int)pNext->obj_tracking_id); + + replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_obj_tracking_id); + + replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)(pNext->obj_dwell_time * 100) / 100); + sprintf(g_last_token_obj_dwell_time, "%d", (int)(pNext->obj_dwell_time * 100) / 100); + + replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_obj_dwell_time); + + replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", pNext->class_id); + sprintf(g_last_token_class_id, "%d", pNext->class_id); + + replacement_t = StrReplace(replacement, "<|class_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_class_id); + + replacement_t = StrReplace(replacement, "<|class_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + +#ifdef GY_OS_AMBA + char mycolor[20] = { 0 }; + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { + if (!IsANPRCategory(pNext->engine_type)) { + if (pNext->image_id != -1 && get_check_first_downsized_cropped_roi_for_object() == 1) { + if (pNext->color_id == 1) + strcpy(mycolor, "Red"); + else if (pNext->color_id == 2) + strcpy(mycolor, "Orange"); + else if (pNext->color_id == 3) + strcpy(mycolor, "Yellow"); + else if (pNext->color_id == 4) + strcpy(mycolor, "Green"); + else if (pNext->color_id == 5) + strcpy(mycolor, "Blue"); + else if (pNext->color_id == 6) + strcpy(mycolor, "Cyan"); + else if (pNext->color_id == 7) + strcpy(mycolor, "Purple"); + else if (pNext->color_id == 8) + strcpy(mycolor, "Black"); + else if (pNext->color_id == 9) + strcpy(mycolor, "White"); + else if (pNext->color_id == 11) + strcpy(mycolor, "Darkgray"); + else if (pNext->color_id == 10) + strcpy(mycolor, "Gray");//Silver + } + } + } + } + else { + sprintf(mycolor, "%s", ""); + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0) { + sprintf(g_last_token_color, "%s", mycolor); + + replacement_t = StrReplace(replacement, "<|color|>", mycolor); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(mycolor, "%s", g_last_token_color); + + replacement_t = StrReplace(replacement, "<|color|>", mycolor); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + +#endif + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|plate|>", pNext->properties.plate); + sprintf(g_last_token_plate, "%s", pNext->properties.plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|plate|>", g_last_token_plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|country|>", pNext->properties.country); + sprintf(g_last_token_country, "%s", pNext->properties.country); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|country|>", g_last_token_country); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|area|>", pNext->properties.area); + sprintf(g_last_token_area, "%s", pNext->properties.area); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|area|>", g_last_token_area); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|plate_list|>", pNext->properties.plate_list); + sprintf(g_last_token_plate_list, "%s", pNext->properties.plate_list); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|plate_list|>", g_last_token_plate_list); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|logo|>", pNext->logo); + sprintf(g_last_token_logo, "%s", pNext->logo); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|logo|>", g_last_token_logo); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } +#ifdef GY_OS_AMBA + int hex_token_base = 1; + int sum_hex = 0; + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + if (index_zone >= 1) { + hex_token_base *= 2; + } + + if (viewDetectionZone[tracking_channel_idx][index_zone].prev_queuing_num >= 1) { + sum_hex += hex_token_base; + } + } + + char buf_hex[50] = { 0 }; + sprintf(buf_hex, "%d", sum_hex); + replacement_t = StrReplace(replacement, "<|hextoint|>", buf_hex); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; +#endif + + int behavior_ID = 0; + if (detection_zone_idx >= 0 && trigger_idx >= 0) + behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + + sprintf(msg, "%d", behavior_ID);//(int)pNext->trigger_type + if (detection_zone_idx >= 0 && trigger_idx >= 0) { + replacement_t = StrReplace(replacement, "<|behavior_id|>", msg); + sprintf(g_last_token_behavior_id, "%s", msg); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|behavior_id|>", g_last_token_behavior_id); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { + sprintf(msg, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); + sprintf(g_last_token_zone_id, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); + replacement_t = StrReplace(replacement, "<|zone_id|>", msg); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|zone_id|>", g_last_token_zone_id); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + + char behavior_name[256] = { 0 }; + if ((behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { + strcpy(behavior_name, "Prohibit_zone"); + } + else if ((behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { + strcpy(behavior_name, "Distance_violation"); + } + else if ((behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { + strcpy(behavior_name, "Height_detection"); + } + else if ((behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { + strcpy(behavior_name, "Forget_to_give_way_detection");//§ + } + else if ((behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { + strcpy(behavior_name, "Max_speed_detection"); + } + else if ((behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { + strcpy(behavior_name, "Min_speed_detection"); + } + else if ((behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { + strcpy(behavior_name, "Zone_with_dwell_Parking_violation");//Tϭɰ / HW + } + else if ((behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { + strcpy(behavior_name, "Tripwire_Traffic_flow");//ĵٽu / 氻 + } + else if ((behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { + strcpy(behavior_name, "Tripwire_on_red_Running_red_lights");//Oĵٽu / O + } + else if ((behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { + strcpy(behavior_name, "Turning_left_on_red");//O + } + else if ((behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { + strcpy(behavior_name, "Turning_right_on_red");//Ok + } + else if ((behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { + strcpy(behavior_name, "Turn_left");//఻ + } + else if ((behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { + strcpy(behavior_name, "Turn_right");//k఻ + } + else if ((behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { + strcpy(behavior_name, "LPR_allowed_list_detection_in_zone");//զWĵٰϰ + } + else if ((behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { + strcpy(behavior_name, "LPR_visitor_list_detection_in_zone");//XȦWĵٰϰ + } + else if ((behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { + strcpy(behavior_name, "LPR_denial_list_detection_in_zone");//¦Wĵٰϰ + } + else if ((behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { + strcpy(behavior_name, "Density_detection");//Kװ + } + else if ((behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { + strcpy(behavior_name, "AI_missing_object_detection");//AI򥢪 + } + else if ((behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { + strcpy(behavior_name, "Unattended_or_missing_object");//򥢪οd + } + else if ((behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { + strcpy(behavior_name, "Tampering_detection");//}a + } + else if ((behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { + strcpy(behavior_name, "All_objects_detection_AND");//ئPɦsb (AND) + } + else if ((behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { + strcpy(behavior_name, "Lack_of_any_object_detection_NAND");//ʤ֥@ئPɦsb (NAND) + } + if (detection_zone_idx >= 0 && trigger_idx >= 0) { + replacement_t = StrReplace(replacement, "<|behavior_name|>", behavior_name); + sprintf(g_last_token_behavior_name, "%s", behavior_name); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|behavior_name|>", g_last_token_behavior_name); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { + replacement_t = StrReplace(replacement, "<|linked_plate|>", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); + sprintf(g_last_token_linked_plate, "%s", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|linked_plate|>", g_last_token_linked_plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + //time_t rawtime = time(0); + time_t rawtime = g_osdSysTimeStamp; + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + //printf("\n---g_osdSysTimeStamp:%ld,%04d-%02d-%02dT%02d:%02d:%02d\n", g_osdSysTimeStamp, 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + //timeinfo->tm_min, timeinfo->tm_sec); + + /* + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d-%02d-%02dT%02d:%02d:%02d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec); + */ + + char buf_time_t[50] = { 0 }; + sprintf(buf_time_t, "%ld", rawtime); + replacement_t = StrReplace(replacement, "<|time_t|>", buf_time_t); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_year[20] = { 0 }; + sprintf(buf_year, "%04d", 1900 + timeinfo->tm_year); + replacement_t = StrReplace(replacement, "<|YYYY|>", buf_year); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_month[20] = { 0 }; + sprintf(buf_month, "%02d", 1 + timeinfo->tm_mon); + replacement_t = StrReplace(replacement, "<|MM|>", buf_month); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_date[10] = { 0 }; + sprintf(buf_date, "%02d", timeinfo->tm_mday); + replacement_t = StrReplace(replacement, "<|DD|>", buf_date); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_hour[10] = { 0 }; + sprintf(buf_hour, "%02d", timeinfo->tm_hour); + replacement_t = StrReplace(replacement, "<|hh|>", buf_hour); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_minute[10] = { 0 }; + sprintf(buf_minute, "%02d", timeinfo->tm_min); + replacement_t = StrReplace(replacement, "<|mm|>", buf_minute); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_second[10] = { 0 }; + sprintf(buf_second, "%02d", timeinfo->tm_sec); + replacement_t = StrReplace(replacement, "<|ss|>", buf_second); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + struct tm * gmtinfo; + gmtinfo = gmtime(&rawtime); + + char buf_gmthour[10] = { 0 }; + sprintf(buf_gmthour, "%02d", gmtinfo->tm_hour); + replacement_t = StrReplace(replacement, "<|GMThh|>", buf_gmthour); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + +#ifdef GY_OS_V_SERIES + +#else + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) + { + char temp_label[30] = { 0 }; + sprintf(temp_label, "<|counter%02d_count|>", index_counter + 1); + + char temp_counter_count[30] = { 0 }; + sprintf(temp_counter_count,"%d", eventCounterList[index_counter].counter_count); + + replacement_t = StrReplace(replacement, temp_label, temp_counter_count); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char temp_label_dwell[30] = { 0 }; + sprintf(temp_label_dwell, "<|counter%02d_dwell|>", index_counter + 1); + + char temp_counter_timetResetAt[50] = { 0 }; + sprintf(temp_counter_timetResetAt, "%d", eventCounterList[index_counter].dwell_time); + + replacement_t = StrReplace(replacement, temp_label_dwell, temp_counter_timetResetAt); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char temp_label_dwell_unit[50] = { 0 }; + sprintf(temp_label_dwell_unit, "<|counter%02d_dwell_unit|>", index_counter + 1); + + replacement_t = StrReplace(replacement, temp_label_dwell_unit, eventCounterList[index_counter].dwell_unit); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + } +#endif + char fetch_mac_addr[30] = { 0 }; + if (g_match_mac) + strcpy(fetch_mac_addr, g_mac_address); + else + { + GetMACAddress(fetch_mac_addr); + //printf("mac addr = %s \n", fetch_mac_addr); + int i = 0; + while (fetch_mac_addr[i] != '\0') + { + if (fetch_mac_addr[i] == '\n') + { + fetch_mac_addr[i] = '\0'; + break; + } + i++; + } + } + replacement_t = StrReplace(replacement, "<|mac_address|>", fetch_mac_addr); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + replacement_t = StrReplace(replacement, "<|device_name|>", g_device_name); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + replacement_t = StrReplace(replacement, "<|dataset_ver|>", Buffer_ver); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char temp_soft_ver[50] = { 0 }; + strcat(temp_soft_ver, APP_VERSION); + strcat(temp_soft_ver, "-"); + strcat(temp_soft_ver, WeightFileModeName); + replacement_t = StrReplace(replacement, "<|soft_ver|>", temp_soft_ver); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_frame_id[50] = { 0 }; + sprintf(buf_frame_id, "%u", get_frame_id()); + replacement_t = StrReplace(replacement, "<|frame_id|>", buf_frame_id); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_parking_space[50] = { 0 }; + sprintf(buf_parking_space, "%d", viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space); + replacement_t = StrReplace(replacement, "<|total_space|>", buf_parking_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + if (space_zone >= 0 && space_id >= 0) { + + int temp_space_id = space_id; + for (int index_zone = 0; index_zone < space_zone; index_zone++) { + temp_space_id += (viewDetectionZone[tracking_channel_idx][space_zone].parking_space + 1); + } + + char buf_space_id[50] = { 0 }; + sprintf(buf_space_id, "%02d", temp_space_id + 1); + replacement_t = StrReplace(replacement, "<|space_id|>", buf_space_id); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_space_zone[50] = { 0 }; + sprintf(buf_space_zone, "%d", space_zone + 1); + replacement_t = StrReplace(replacement, "<|space_zone|>", buf_space_zone); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_space_status[50] = { 0 }; + sprintf(buf_space_status, "%d", g_parking_space_check_table[space_zone][space_id]); + replacement_t = StrReplace(replacement, "<|space_status|>", buf_space_status); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + time_t rawtime_space = g_parking_space_status_change_time[space_zone][space_id]; + + struct tm * timeinfo_space; + struct tm * gmtinfo_space; + timeinfo_space = localtime(&rawtime_space); + gmtinfo_space = gmtime(&rawtime_space); + + char buf_time_t_space[50] = { 0 }; + sprintf(buf_time_t_space, "%ld", rawtime_space); + replacement_t = StrReplace(replacement, "<|space_time_t|>", buf_time_t_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_year_space[20] = { 0 }; + sprintf(buf_year_space, "%04d", 1900 + timeinfo_space->tm_year); + replacement_t = StrReplace(replacement, "<|space_YYYY|>", buf_year_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_month_space[20] = { 0 }; + sprintf(buf_month_space, "%02d", 1 + timeinfo_space->tm_mon); + replacement_t = StrReplace(replacement, "<|space_MM|>", buf_month_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_date_space[10] = { 0 }; + sprintf(buf_date_space, "%02d", timeinfo_space->tm_mday); + replacement_t = StrReplace(replacement, "<|space_DD|>", buf_date_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_gmthour_space[10] = { 0 }; + sprintf(buf_gmthour_space, "%02d", gmtinfo_space->tm_hour); + replacement_t = StrReplace(replacement, "<|space_GMThh|>", buf_gmthour_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_hour_space[10] = { 0 }; + sprintf(buf_hour, "%02d", timeinfo_space->tm_hour); + replacement_t = StrReplace(replacement, "<|space_hh|>", buf_hour_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_minute_space[10] = { 0 }; + sprintf(buf_minute_space, "%02d", timeinfo_space->tm_min); + replacement_t = StrReplace(replacement, "<|space_mm|>", buf_minute_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_second_space[10] = { 0 }; + sprintf(buf_second_space, "%02d", timeinfo_space->tm_sec); + replacement_t = StrReplace(replacement, "<|space_ss|>", buf_second_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_difftime_space[10] = { 0 }; + sprintf(buf_difftime_space, "%d", (int)difftime(g_osdSysTimeStamp, rawtime_space)); + replacement_t = StrReplace(replacement, "<|difftime|>", buf_difftime_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + + if (enable_base64_image == 1) { + + char buf_image_size[50] = { 0 }; + sprintf(buf_image_size, "%d", image_buff_size_base64); + replacement_t = StrReplace(replacement, "<|snap_size|>", buf_image_size); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + replacement_t = StrReplace(replacement, "<|snap_image|>", image_buff_base64); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + if (pNext != NULL && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && pNext->image_id >= 0 && pNext->image_id < MAX_PLATE_BUF_NUM && cropped_image_size_base64[pNext->image_id] >= 1) { + if (cropped_image_base64 != NULL && cropped_image_base64[pNext->image_id] != NULL) { + char buf_image_size[50] = { 0 }; + sprintf(buf_image_size, "%d", cropped_image_size_base64[pNext->image_id]); + replacement_t = StrReplace(replacement, "<|cropped_size|>", buf_image_size); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + cropped_image_base64[pNext->image_id][cropped_image_size_base64[pNext->image_id]] = '\0'; + replacement_t = StrReplace(replacement, "<|cropped_image|>", cropped_image_base64[pNext->image_id]); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + } + + strcpy(OutputString, replacement); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + //printf("\n-----%s\n", OutputString); + return strlen(OutputString); + +} +//ReplaceKeyWords// + +size_t ReplaceKeyWords_space(detection_pos* pNext,char *SequenceString, int space_zone, int space_id, char* InputString, char *OutputString, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64, int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) +{ + //printf("\n-------ReplaceKeyWords space----0\n"); + size_t content_size = 0; + //printf("\n-------ReplaceKeyWords space----1\n"); + if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString,"<|space_zone|><|space_id|>")==0 && strstr(InputString,"<|space_zone|>")!=NULL && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) + { + //printf("\n-------ReplaceKeyWords space----2\n"); + char content_temp[BUFSIZE_V3] = { 0 }; + strcpy(content_temp,"["); + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) { + char content_current[BUFSIZE_V3] = { 0 }; + ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); + + if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) { + strcat(content_temp, content_current); + } + else { + strcat(content_temp, content_current); + strcat(content_temp, ","); + } + } + } + strcat(content_temp, "]"); + content_size = strlen(content_temp); + strcpy(OutputString, content_temp); + //printf("\n-------ReplaceKeyWords space----3\n"); + //printf("\n-------OutputString:%s\n", OutputString); + } + else if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString, "<|space_id|>") == 0 && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) + { + //printf("\n-------ReplaceKeyWords space----4\n"); + char content_temp[BUFSIZE_V3] = { 0 }; + strcpy(content_temp, "["); + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) + { + char content_current[BUFSIZE_V3] = { 0 }; + ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); + + if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) + { + strcat(content_temp, content_current); + } + else + { + strcat(content_temp, content_current); + strcat(content_temp, ","); + } + } + } + strcat(content_temp, "]"); + content_size = strlen(content_temp); + strcpy(OutputString, content_temp); + //viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space + //printf("\n-------OutputString:%s\n", OutputString); + //printf("\n-------ReplaceKeyWords space----5\n"); + } + else if(pNext != NULL) + { + //printf("\n-------ReplaceKeyWords space----6\n"); + char content_temp[BUFSIZE_V3] = { 0 }; + ReplaceKeyWords(pNext, space_zone, space_id, InputString, content_temp, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); + content_size = strlen(content_temp); + strcpy(OutputString, content_temp); + //printf("\n-------ReplaceKeyWords space----7\n"); + } + else + { + content_size = 0; + } + + return content_size; +} + +#endif + +//|ΨUTF8 Encoder +void UpdateBehaviorData(QueueInfo* q_info, int tracking_channel_idx, int detection_zone_idx,int trigger_idx, int enable_lang) { + q_info->behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + if ((q_info->behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//Tϰ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Prohibit zone");//Tϰ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_ZONE_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe8\xb7\x9d\xe9\x9b\xa2\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\xb5\xe6\xb8\xac");//ZHW UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Distance violation");//ZHW UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_DISTANCE_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\xab\x98\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//װ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Height detection");//װ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_HIGH_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe4\xb8\x8d\xe7\xa6\xae\xe8\xae\x93\xe5\x81\xb5\xe6\xb8\xac");//§ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Forget to give way detection");//§ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_FORGET_TO_GIVE_WAY"); + } + else if ((q_info->behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe5\xa4\xa7\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//̤jtװ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Max speed detection");//̤jtװ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_SPEED_HIGH"); + } + else if ((q_info->behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe4\xbd\x8e\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//̧Ctװ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Min speed detection");//̧Ctװ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_SPEED_LOW"); + } + else if ((q_info->behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe9\x99\x90\xe6\x99\x82\xe5\x81\xb5\xe6\xb8\xac\x20\x2f\x20\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\x9c\xe8\xbb\x8a");//Tϭɰ / HW + else//en_gb + strcpy(q_info->behavior_desc, "Zone with dwell / Parking violation");//Tϭɰ / HW + strcpy(q_info->behavior_name, "TRIGGER_PARKING_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\x9b\xb4\xe8\xa1\x8c\xe5\x81\xb5\xe6\xb8\xac");//ĵٽu / 氻 + else//en_gb + strcpy(q_info->behavior_desc, "Tripwire / Traffic flow");//ĵٽu / 氻 + strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\xb4\x85\xe7\x87\x88\xe7\x9b\xb4\xe8\xa1\x8c");//Oĵٽu / O + else//en_gb + strcpy(q_info->behavior_desc, "Tripwire on red / Running red lights");//Oĵٽu / O + strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT_RED_LIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\xb7\xa6\xe8\xbd\x89");//O + else//en_gb + strcpy(q_info->behavior_desc, "Turning left on red");//O + strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT_RED_LIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\x8f\xb3\xe8\xbd\x89");//Ok + else//en_gb + strcpy(q_info->behavior_desc, "Turning right on red");//Ok + strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT_RED_LIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\xb7\xa6\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//఻ + else//en_gb + strcpy(q_info->behavior_desc, "Turn left");//఻ + strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\x8f\xb3\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//k఻ + else//en_gb + strcpy(q_info->behavior_desc, "Turn right");//k఻ + strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\x99\xbd\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//զWĵٰϰ + else//en_gb + strcpy(q_info->behavior_desc, "LPR allowed list detection in zone");//զWĵٰϰ + strcpy(q_info->behavior_name, "TRIGGER_ALLOW_LIST"); + } + else if ((q_info->behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe8\xa8\xaa\xe5\xae\xa2\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//XȦWĵٰϰ + else//en_gb + strcpy(q_info->behavior_desc, "LPR visitor list detection in zone");//XȦWĵٰϰ + strcpy(q_info->behavior_name, "TRIGGER_GUEST_LIST"); + } + else if ((q_info->behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\xbb\x91\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//¦Wĵٰϰ + else//en_gb + strcpy(q_info->behavior_desc, "LPR denial list detection in zone");//¦Wĵٰϰ + strcpy(q_info->behavior_name, "TRIGGER_BLOCK_LIST"); + } + else if ((q_info->behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\xaf\x86\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//Kװ + else//en_gb + strcpy(q_info->behavior_desc, "Density detection");//Kװ + strcpy(q_info->behavior_name, "TRIGGER_QUEUING_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\x41\x49\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//AI򥢪 + else//en_gb + strcpy(q_info->behavior_desc, "AI missing object detection");//AI򥢪 + strcpy(q_info->behavior_name, "TRIGGER_MISSING_OBJECT_DETECTION"); + } + else if ((q_info->behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x8f\x8a\xe9\x81\xba\xe7\x95\x99\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//򥢪οd + else//en_gb + strcpy(q_info->behavior_desc, "Unattended or missing object");//򥢪οd + strcpy(q_info->behavior_name, "TRIGGER_MISSING_UNATTENDED"); + } + else if ((q_info->behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\x98\xb2\xe7\xa0\xb4\xe5\xa3\x9e\xe5\x81\xb5\xe6\xb8\xac");//}a + else//en_gb + strcpy(q_info->behavior_desc, "Tampering detection");//}a + strcpy(q_info->behavior_name, "TRIGGER_TAMPERING"); + } + else if ((q_info->behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x41\x4e\x44\x29");//P˪ئPɦsb + else//en_gb + strcpy(q_info->behavior_desc, "All objects detection (AND)");//ئPɦsb (AND) + strcpy(q_info->behavior_name, "TRIGGER_ALL_OBJECTS"); + } + else if ((q_info->behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xbc\xba\xe5\xb0\x91\xe4\xbb\xbb\xe4\xb8\x80\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x4e\x41\x4e\x44\x29");//ʤ֥@ئPɦsb (NAND) + else//en_gb + strcpy(q_info->behavior_desc, "Lack of any object detection (NAND)");//ʤ֥@ئPɦsb (NAND) + strcpy(q_info->behavior_name, "TRIGGER_LACK_OF_ANY_OBJECT"); + } + + //TRIGGER_SPEED_HIGHMTRIGGER_SPEED_LOWeNF + + /* + else if (q_info->behavior_ID & TRIGGER_BG_LEARNING) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\xad\xb8\xe7\xbf\x92\xe8\x83\x8c\xe6\x99\xaf\xe4\xb8\xad");//Dz߭I + else//en_gb + strcpy(q_info->behavior_desc, "BG learning");//Dz߭I + strcpy(q_info->behavior_name, "TRIGGER_BG_LEARNING"); + }*/ +} + +long Get_eventCounterList_post_interval(int index_counter) { +#ifdef GY_OS_V_SERIES + + +#else + if (strcmp(eventCounterList[index_counter].post_interval,"1 minute") == 0) { + return 60; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "5 minutes") == 0) { + return 60 * 5; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "30 minutes") == 0) { + return 60 * 30; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 hour") == 0) { + return 60 * 60; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 day") == 0) { + return 60 * 60 * 24; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 week") == 0) { + return 60 * 60 * 24 * 7; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 month") == 0) { + return 60 * 60 * 24 * 30; + } + else +#endif + return -1; +} + +long Get_mail_post_interval() { + if (strcmp(SystemSetting.email_reset_time_interval, "1 minute") == 0) { + return 60; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "5 minutes") == 0) { + return 60 * 5; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "30 minutes") == 0) { + return 60 * 30; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 hour") == 0) { + return 60 * 60; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 day") == 0) { + return 60 * 60 * 24; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 week") == 0) { + return 60 * 60 * 24 * 7; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 month") == 0) { + return 60 * 60 * 24 * 30; + } + else + return -1; +} + +struct timeval currtime_CheckPostEventCondition[MAX_DETECTION_ZONE]; +static long last_ms_CheckPostEventCondition[MAX_DETECTION_ZONE] = { 0 }; +#ifdef GY_OS_AMBA +struct timeval currtime_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE]; +static long last_ms_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE] = { 0 }; +#endif +struct timeval currtime_CheckPostEventCondition_cloud; +static long last_ms_CheckPostEventCondition_cloud = 0; + +struct timeval currtime_CheckPostEventCondition_cloud_v2; +static long last_ms_CheckPostEventCondition_cloud_v2 = 0; + +//struct timeval currtime_CheckPostEventCondition_cloud_record_v2; +//static long last_ms_CheckPostEventCondition_cloud_record_v2 = 0; + +struct timeval currtime_CheckPostEventCondition_counter[MAX_DETECTION_ZONE]; +static long last_ms_CheckPostEventCondition_counter[MAX_DETECTION_ZONE] = { 0 }; + +struct timeval currtime_CheckPostEventCondition_email; +static long last_ms_CheckPostEventCondition_email = 0; + +//#ifdef GY_OS_AMBA +struct timeval currtime_CheckPostEventCondition_ftp; +static long last_ms_CheckPostEventCondition_ftp = 0; +//#endif + +void initial_g_PostRecorderList() { + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + g_PostRecorderList[i].iIfUse = 0; + g_PostRecorderList[i].t_FirstGetTime = 0; + g_PostRecorderList[i].t_FirstGetTime_total = 0; + g_PostRecorderList[i].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[i].check_if_post[m] = 0; + } + g_PostRecorderList[i].check_if_cloud = 0; + g_PostRecorderList[i].check_if_cloud_v2 = 0; + g_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_PostRecorderList[i].check_if_email = 0; + g_PostRecorderList[i].check_if_ftp = 0; + g_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_PostRecorderList[i].box_x = 0.0; + g_PostRecorderList[i].box_y = 0.0; + g_PostRecorderList[i].box_w = 0.0; + g_PostRecorderList[i].box_h = 0.0; + + g_PostRecorderList[i].object_id = 0.0; + g_PostRecorderList[i].zone_idx = 0.0; + + strcpy(g_PostRecorderList[i].sPlateNumber, ""); + strcpy(g_PostRecorderList[i].name, ""); + + g_PostRecorderList[i].count_trigger = 0; + //g_PostRecorderList[i].the_same_id = 0; + //-------------------------------- + + g_longterm_PostRecorderList[i].iIfUse = 0; + g_longterm_PostRecorderList[i].t_FirstGetTime = 0; + g_longterm_PostRecorderList[i].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[i].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[i].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[i].check_if_cloud = 0; + g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[i].check_if_email = 0; + g_longterm_PostRecorderList[i].check_if_ftp = 0; + g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[i].box_x = 0.0; + g_longterm_PostRecorderList[i].box_y = 0.0; + g_longterm_PostRecorderList[i].box_w = 0.0; + g_longterm_PostRecorderList[i].box_h = 0.0; + + g_longterm_PostRecorderList[i].object_id = 0.0; + g_longterm_PostRecorderList[i].zone_idx = 0.0; + + strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); + strcpy(g_longterm_PostRecorderList[i].name, ""); + + g_longterm_PostRecorderList[i].count_trigger = 0; + //g_longterm_PostRecorderList[i].the_same_id = 0; + } +} + +void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx,int force_to_push,char* aiengine_data,int counter_idx, char* image_buff,int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) +{ + long d_no_parking_time = (long)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { + d_no_parking_time = (long)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); + } + + gettimeofday(&currtime_CheckPostEventCondition[detection_zone_idx], NULL); + long current_ms_CheckPostEventCondition = (currtime_CheckPostEventCondition[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition[detection_zone_idx].tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_cloud, NULL); + long current_ms_CheckPostEventCondition_cloud = (currtime_CheckPostEventCondition_cloud.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud.tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_cloud_v2, NULL); + long current_ms_CheckPostEventCondition_cloud_v2 = (currtime_CheckPostEventCondition_cloud_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_v2.tv_usec / 1000); + + //gettimeofday(&currtime_CheckPostEventCondition_cloud_record_v2, NULL); + //long current_ms_CheckPostEventCondition_cloud_record_v2 = (currtime_CheckPostEventCondition_cloud_record_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_record_v2.tv_usec / 1000); + + + gettimeofday(&currtime_CheckPostEventCondition_counter[detection_zone_idx], NULL); + long current_ms_CheckPostEventCondition_counter = (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_email, NULL); + long current_ms_CheckPostEventCondition_email = (currtime_CheckPostEventCondition_email.tv_sec * 1000) + (currtime_CheckPostEventCondition_email.tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_ftp, NULL); + long current_ms_CheckPostEventCondition_ftp = (currtime_CheckPostEventCondition_ftp.tv_sec * 1000) + (currtime_CheckPostEventCondition_ftp.tv_usec / 1000); + +#ifdef GY_OS_AMBA + gettimeofday(&currtime_CheckPostEventCondition_snmp[detection_zone_idx], NULL); + long current_ms_CheckPostEventCondition_snmp = (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_usec / 1000); +#endif + + //printf("\n--------------QueueSize:%d\n",(int)QueueSize(_POST_NOTIFICATION)); + + int check_if_ok_for_location = 0; + int index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + int size_g_PostRecorderList = 0; + + //int check_if_ok_for_location_longterm = 0; + int index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; + int size_g_PostRecorderList_longterm = 0; + + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + + if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0) { + //printf("\nFFFFFFF : 1\n"); + if (pNext != NULL /*&& aiengine_data != NULL && strlen(aiengine_data) >= 1*/ && counter_idx == -1) { + //printf("\nFFFFFFF : 2\n"); + if (strlen(pNext->name) >= 1 && pNext->width > 0 && pNext->height > 0 /*&& !(IsANPRCategory_L_Plate(pNext->name))*/) + { + //printf("\nFFFFFFF : 3\n"); + //Free over Recoder time + + + int iFindMatchPost = 0; + int iFindMatchPost_longterm = 0; + time_t now_time = time(0); + + double max_dwell_short = 0.0; + + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + if (g_PostRecorderList[i].iIfUse == 0 && g_longterm_PostRecorderList[i].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[i].iIfUse == 1 /*&& g_PostRecorderList[i].zone_idx == detection_zone_idx*/) + { + if (g_PostRecorderList[i].box_w > 0 && g_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_PostRecorderList[i].box_x; + temp_A.top_y = g_PostRecorderList[i].box_y; + temp_A.width = g_PostRecorderList[i].box_w; + temp_A.height = g_PostRecorderList[i].box_h; + strcpy(temp_A.name, g_PostRecorderList[i].name); + + float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + { + if (strcmp(g_PostRecorderList[i].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + } + else { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + } + } + } + } + } + + if (g_longterm_PostRecorderList[i].iIfUse == 1 /*&& g_longterm_PostRecorderList[i].zone_idx == detection_zone_idx*/) + { + if (g_longterm_PostRecorderList[i].box_w > 0 && g_longterm_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_longterm_PostRecorderList[i].box_x; + temp_A.top_y = g_longterm_PostRecorderList[i].box_y; + temp_A.width = g_longterm_PostRecorderList[i].box_w; + temp_A.height = g_longterm_PostRecorderList[i].box_h; + strcpy(temp_A.name, g_longterm_PostRecorderList[i].name); + + float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + { + if (strcmp(g_longterm_PostRecorderList[i].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + } + else { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + } + } + } + } + } + } + +#if 1 + if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { + if (iFindMatchPost_longterm == 0) + { + //printf("\nFFFFFFF : 4\n"); + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + if (g_longterm_PostRecorderList[i].iIfUse == 0) + { + g_longterm_PostRecorderList[i].iIfUse = 1; + g_longterm_PostRecorderList[i].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[i].t_FirstGetTime_total = now_time; + g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[i].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[i].check_if_cloud = 0; + g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[i].check_if_email = 0; + g_longterm_PostRecorderList[i].check_if_ftp = 0; + g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; + g_longterm_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; + g_longterm_PostRecorderList[i].box_w = pNext->width / 3.0; + g_longterm_PostRecorderList[i].box_h = pNext->height / 3.0; + + g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); + + if (IsANPRCategory_L_Plate(pNext->name)) { + strcpy(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate); + } + else { + strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); + } + strcpy(g_longterm_PostRecorderList[i].name, pNext->name); + + g_longterm_PostRecorderList[i].count_trigger = 1; + //g_longterm_PostRecorderList[i].the_same_id = 0; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + break; + } + } + + } + } +#endif + + if (iFindMatchPost == 0) + { + //printf("\nFFFFFFF : 4\n"); + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + if (g_PostRecorderList[i].iIfUse == 0) + { + g_PostRecorderList[i].iIfUse = 1; + g_PostRecorderList[i].t_FirstGetTime = now_time; + g_PostRecorderList[i].t_FirstGetTime_total = now_time; + g_PostRecorderList[i].t_UpdateTime = now_time; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[i].check_if_post[m] = 0; + } + g_PostRecorderList[i].check_if_cloud = 0; + g_PostRecorderList[i].check_if_cloud_v2 = 0; + g_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_PostRecorderList[i].check_if_email = 0; + g_PostRecorderList[i].check_if_ftp = 0; + g_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; + g_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; + g_PostRecorderList[i].box_w = pNext->width / 3.0; + g_PostRecorderList[i].box_h = pNext->height / 3.0; + + g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); + + if (IsANPRCategory_L_Plate(pNext->name)){ + strcpy(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate); + } + else { + strcpy(g_PostRecorderList[i].sPlateNumber, ""); + } + strcpy(g_PostRecorderList[i].name, pNext->name); + + g_PostRecorderList[i].count_trigger = 1; + //g_PostRecorderList[i].the_same_id = 0; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + break; + } + } + + } + } + + } + } + + //printf("\n--------check_if_ok_for_location :%d\n", check_if_ok_for_location); + +#ifdef GY_OS_AMBA + if (pNext == NULL || strcmp(SystemSetting.enable_post_only_if_both_detected, "No") == 0 || + (strcmp(SystemSetting.enable_post_only_if_both_detected, "Yes") == 0 && + pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) || + !(viewChannelData[0].enable_anpr) || + !(viewChannelData[0].enable_face) || + !(viewChannelData[0].enable_traffic) || + !IsANPRCategory(featureType) || + !(featureType & FEATURE_TRAF_DET)) +#endif + { + + if (activePostNotification && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + + //printf("\n----------------check_if_post:%d,size_g_PostRecorderList:%d\n", g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx], size_g_PostRecorderList); + //printf("\n--------CheckPostEventCondition:1\n"); + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx] == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_post[detection_zone_idx] == 0)))) { + //printf("\n--------CheckPostEventCondition:2\n"); + if (last_ms_CheckPostEventCondition[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition - last_ms_CheckPostEventCondition[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { + + + + //printf("\n--------CheckPostEventCondition:3\n"); + char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); + int post_event_num = StrSplit(Temp, eachPostEvent, ","); + //printf("\n------UU:5\n"); + //char *replacement = NULL; + //char *replacement_t = NULL; + + int check_if_SD_recording_post = 0; + int index_SD_post = -1; + + int check_if_white_LED_post = 0; + int index_LED_post = -1; + + int index_first_post = -1; + + if (post_event_num >= 1 && strcmp(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name,"Null")!=0) { + + for (int i = 0; i < post_event_num; i++) + { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) + { + if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) + { + if (index_first_post == -1) { + index_first_post = j; + } + + if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "SD recording") != NULL && g_check_if_no_brand == 0) { + index_SD_post = j; + check_if_SD_recording_post = 1; + } + + if (g_camera_white_LED == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "White LED") != NULL && g_check_if_no_brand == 0) { + index_LED_post = j; + check_if_white_LED_post = 1; + } + } + else + { + /* + printf("Post queue is full!\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + pthread_mutex_lock(&mutex_curl); + if(QueueSize(_POST_NOTIFICATION) >= 1) + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_post_notification_pop); + printf("Post queue is full!end\n");*/ + } + //break; + } + } + } + + if (index_SD_post == -1 && index_LED_post >= 0) { + index_SD_post = index_LED_post; + } + + if (index_SD_post == -1) { + index_SD_post = index_first_post; + } + + //printf("\n-----------index_SD_post:%d\n", index_SD_post); + + int check_if_status_cloud = 0; + + if (index_SD_post >= 0) { + time_t rawtime_temp = g_post_SysTimeStamp; + + //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); + //if(aiengine_data != NULL) + //printf("\n------------aiengine_data:%s\n", aiengine_data); + //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); + //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); + + if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && g_check_if_no_brand == 0 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL)) + ) + { + + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { + if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { + check_if_status_cloud = 1; + } + } + } + + //printf("\n---------check_if_SD_recording_post:%d,check_if_status_cloud:%d\n", check_if_SD_recording_post, check_if_status_cloud); + + if ((check_if_SD_recording_post == 0 && check_if_white_LED_post == 0) || check_if_status_cloud == 1) { + + last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_post[detection_zone_idx] = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_post[detection_zone_idx] = 1; + } + + //printf("\n--------CheckPostEventCondition:4\n"); + for (int post_times = 0; post_times < 2; post_times++) { + + int temp_index_post = 0; + if (post_times == 0 && index_SD_post >= 0) { + temp_index_post = index_SD_post; + } + else { + if (check_if_SD_recording_post == 1 && check_if_white_LED_post == 1 && index_LED_post >= 0) { + temp_index_post = index_LED_post; + } + else { + break; + } + } + + pthread_mutex_lock(&mutex_post_notification_pop); + postEventList[temp_index_post].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[temp_index_post].post_event_name); + strcpy(q_info.post_protocol, postEventList[temp_index_post].post_protocol); + strcpy(q_info.post_method, postEventList[temp_index_post].post_event_method); + strcpy(q_info.host_name, postEventList[temp_index_post].post_host_ip); + strcpy(q_info.host_port, postEventList[temp_index_post].post_host_port); + strcpy(q_info.post_timeout, postEventList[temp_index_post].post_timeout); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (strlen(postEventList[temp_index_post].post_url) >= 1) { + //if (pNext != NULL) { + size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[temp_index_post].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.post_url, postEventList[temp_index_post].post_url); + //} + q_info.post_url[url_size] = '\0'; + } + else + q_info.post_url[0] = '\0'; + + //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); + + strcpy(q_info.post_username, postEventList[temp_index_post].post_username); + strcpy(q_info.post_password, postEventList[temp_index_post].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[temp_index_post].post_jpeg_file_name); + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + if (strcmp(postEventList[temp_index_post].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[temp_index_post].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[temp_index_post].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + if (strcmp(postEventList[temp_index_post].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + + if (strlen(postEventList[temp_index_post].post_content) >= 1) { + + //if (pNext != NULL) { + //printf("\n------check post 2--------6------3\n"); + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //q_info.content_size = 0; + //printf("\n-----size:%lu\n", q_info.content_size); + //printf("\n------check post 2--------6------4\n"); + //} + //else { + //strcpy(q_info.content, postEventList[temp_index_post].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[temp_index_post].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[temp_index_post].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.content, postEventList[temp_index_post].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + //printf("\n----------_POST_NOTIFICATION\n"); + //printf("\n------check post 3\n"); + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + //printf("\n------check post 3--------1\n"); + if (force_to_push == 1) { + //printf("\n------check post 3--------2\n"); + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if(g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + //printf("\n------check post 3--------3\n"); + } + else { + //printf("\n------check post 3--------4\n"); + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + //printf("\n------check post 3--------5\n"); + } + } + //printf("\n------check post 4\n"); + pthread_mutex_unlock(&mutex_post_notification_pop); + } + + //if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && check_if_SD_recording_post == 1 && + //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1))) + + if (check_if_status_cloud == 1) + { + //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) + { + //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) + { + //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + //printf("\n------------Segmentation fault:%d\n", 5); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "post_to_cloud"); + strcpy(q_info.cloud_aiengine, aiengine_data); + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + q_info.rawtime = rawtime_temp; + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); + + /** + printf("\n-------------\n"); + printf("\nbehavior_ID: %d\n", q_info.behavior_ID); + printf("\n-------------\n");*/ + + + QueuePush(q_info, _POST_NOTIFICATION); + + //printf("\n------------Segmentation fault:%d\n", 6); + } + last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; + } + } + } + } + + } + } + + for (int i = 0; i < post_event_num; i++) + { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) + { + if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) + { + if (index_SD_post != j && index_LED_post != j) { + + last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; + + for (int k = 0; k < size_g_PostRecorderList; k++) { + g_PostRecorderList[index_g_PostRecorderList[k]].check_if_post[detection_zone_idx] = 1; + } + + for (int k = 0; k < size_g_PostRecorderList_longterm; k++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[k]].check_if_post[detection_zone_idx] = 1; + } + + pthread_mutex_lock(&mutex_post_notification_pop); + postEventList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[j].post_event_name); + strcpy(q_info.post_protocol, postEventList[j].post_protocol); + strcpy(q_info.post_method, postEventList[j].post_event_method); + strcpy(q_info.host_name, postEventList[j].post_host_ip); + strcpy(q_info.host_port, postEventList[j].post_host_port); + strcpy(q_info.post_timeout, postEventList[j].post_timeout); + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + + if (strlen(postEventList[j].post_url) >= 1) { + //if (pNext != NULL) { + size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.post_url, postEventList[j].post_url); + //} + q_info.post_url[url_size] = '\0'; + } + else + q_info.post_url[0] = '\0'; + + //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); + + strcpy(q_info.post_username, postEventList[j].post_username); + strcpy(q_info.post_password, postEventList[j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + //printf("\n----------_POST_NOTIFICATION\n"); + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (force_to_push == 1) { + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + else { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + } + } + } + } + } + else { + time_t rawtime_temp = g_post_SysTimeStamp; + + int check_if_status_cloud = 0; + //printf("\n--------CheckPostEventCondition:4\n"); + //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); + //if(aiengine_data != NULL) + //printf("\n------------aiengine_data:%s\n", aiengine_data); + //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); + //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); + /* + if (aiengine_data != NULL) { + printf("\n--------strlen(aiengine_data):%d\n", strlen(aiengine_data)); + } + else { + printf("\n-------strlen(aiengine_data):NULL\n"); + } + + if (pNext == NULL) { + printf("\n--------pNext:NULL\n"); + } + else { + printf("\n--------pNext:not NUll\n"); + }*/ + + if (aiengine_data != NULL && strlen(aiengine_data) >= 1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + //printf("\n--------CheckPostEventCondition:5--1\n"); + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { + + //printf("\n--------CheckPostEventCondition:5--2\n"); + if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { + check_if_status_cloud = 1; + } + } + } + //printf("\n--------check_if_status_cloud:%d\n", check_if_status_cloud); + if (check_if_status_cloud == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && g_check_if_no_brand == 0) + { + //printf("\n--------CheckPostEventCondition:6\n"); + //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) + { + //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) + { + //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + //printf("\n------------Segmentation fault:%d\n", 5); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "post_to_cloud"); + strcpy(q_info.cloud_aiengine, aiengine_data); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + q_info.rawtime = rawtime_temp; + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); + + /** + printf("\n-------------\n"); + printf("\nbehavior_ID: %d\n", q_info.behavior_ID); + printf("\n-------------\n");*/ + + + QueuePush(q_info, _POST_NOTIFICATION); + + //printf("\n------------Segmentation fault:%d\n", 6); + } + last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; + } + } + } + } + } + } + } + } + + if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0 && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud_v2 == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud_v2)))) { + if (last_ms_CheckPostEventCondition_cloud_v2 == 0 || (current_ms_CheckPostEventCondition_cloud_v2 - last_ms_CheckPostEventCondition_cloud_v2) >= atoi(SystemSetting.cloud_v2_notification_dwell) * 1000) { + //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + //printf("\n------------Segmentation fault:%d\n", 5); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "cloud_v2"); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (strlen(SystemSetting.cloud_v2_content) >= 1) { + //if (pNext != NULL) { + size_t v2_size = ReplaceKeyWords(pNext, -1, -1, SystemSetting.cloud_v2_content, q_info.cloud_v2_aiengine, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 1); + //} + //else { + //strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); + //} + q_info.cloud_v2_aiengine[v2_size] = '\0'; + } + else + q_info.cloud_v2_aiengine[0] = '\0'; + + //strcpy(q_info.cloud_v2_aiengine, aiengine_data); + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); + + /** + printf("\n-------------\n"); + printf("\nbehavior_ID: %d\n", q_info.behavior_ID); + printf("\n-------------\n");*/ + + + QueuePush(q_info, _GETALARMMOTION); + + //printf("\n------------Segmentation fault:%d\n", 6); + } + last_ms_CheckPostEventCondition_cloud_v2 = current_ms_CheckPostEventCondition_cloud_v2; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud_v2 = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud_v2 = 1; + } + } + } + } + +#ifdef GY_OS_AMBA + if (activeSNMPPost && /*strcmp(SystemSetting.enable_cloud, "Yes") == 0 &&*/ counter_idx == -1) { + + //printf("\n--------CheckPostEventCondition:2\n"); + if (last_ms_CheckPostEventCondition_snmp[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition_snmp - last_ms_CheckPostEventCondition_snmp[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { + + //printf("\n--------CheckPostEventCondition:3\n"); + char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); + int post_event_num = StrSplit(Temp, eachPostEvent, ","); + //printf("\n------UU:10\n"); + //char *replacement = NULL; + //char *replacement_t = NULL; + + for (int i = 0; i < post_event_num; i++) + { + for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) + { + if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], SNMPManagementList[j].snmp_event_name) == 0) + { + if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && SNMPManagementList[j].check_if_delivering == 0) + { + //printf("\n--------CheckPostEventCondition:4\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + SNMPManagementList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + + strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); + strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); + strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); + strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); + strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); + strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); + strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); + + if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value,"<|hextoint|>")==0){ + size_t snmp_size = ReplaceKeyWords(pNext, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); + q_info.snmp_value[snmp_size] = '\0'; + } + else { + strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); + } + + //printf("\n------q_info.snmp_value:%s\n", q_info.snmp_value); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + //printf("\n----------_POST_NOTIFICATION\n"); + + if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { + if (force_to_push == 1) { + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + else { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + else + { + /* + printf("Post queue is full!\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + pthread_mutex_lock(&mutex_curl); + if(QueueSize(_POST_NOTIFICATION) >= 1) + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_post_notification_pop); + printf("Post queue is full!end\n");*/ + } + break; + } + } + } + last_ms_CheckPostEventCondition_snmp[detection_zone_idx] = current_ms_CheckPostEventCondition_snmp; + } + } +#endif + +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + if (activePostNotification && counter_idx >= 0 && Get_eventCounterList_post_interval(counter_idx) != -1) { + if (last_ms_CheckPostEventCondition_counter[detection_zone_idx] == 0 || (Get_eventCounterList_post_interval(counter_idx) != -1 && (current_ms_CheckPostEventCondition_counter - last_ms_CheckPostEventCondition_counter[detection_zone_idx]) >= Get_eventCounterList_post_interval(counter_idx) * 1000)) { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strlen(postEventList[j].post_event_name) >= 1 && strcmp(eventCounterList[counter_idx].link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + postEventList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[j].post_event_name); + strcpy(q_info.post_protocol, postEventList[j].post_protocol); + strcpy(q_info.post_method, postEventList[j].post_event_method); + strcpy(q_info.host_name, postEventList[j].post_host_ip); + strcpy(q_info.host_port, postEventList[j].post_host_port); + strcpy(q_info.post_timeout, postEventList[j].post_timeout); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (strlen(postEventList[j].post_url) >= 1) { + //if (pNext != NULL) { + size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,0); + //} + //else { + //strcpy(q_info.post_url, postEventList[j].post_url); + //} + q_info.post_url[url_size] = '\0'; + } + else + q_info.post_url[0] = '\0'; + + //printf("\n------ q_info.post_url #2:%s\n", q_info.post_url); + + strcpy(q_info.post_username, postEventList[j].post_username); + strcpy(q_info.post_password, postEventList[j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + /*if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + + g_IsCustomWeight == 1) { + char buf_content[256] = { '\0' }; + sprintf(buf_content, "{\"counter_name\":\"%s\",\"counter_count\":%d}", eventCounterList[counter_idx].counter_name, eventCounterList[counter_idx].counter_count); + + strcpy(q_info.content, buf_content); + }*/ + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (force_to_push == 1) { + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + else { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + else + { + /* + printf("Post queue is full!\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + pthread_mutex_lock(&mutex_curl); + if(QueueSize(_POST_NOTIFICATION) >= 1) + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_post_notification_pop); + printf("Post queue is full!end\n");*/ + } + break; + } + } + + last_ms_CheckPostEventCondition_counter[detection_zone_idx] = current_ms_CheckPostEventCondition_counter; + } + } + } +#endif + + if (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_email == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_email == 0)))) { + if (last_ms_CheckPostEventCondition_email == 0 || + (Get_mail_post_interval() == -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && + (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > d_no_parking_time * 1000) || + (Get_mail_post_interval() != -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && + (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000) || + force_to_push == 1) { + if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + QueueInfo q_info = { 0 }; + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (image_buff_size_base64 >= 1) { + memcpy(q_info.image_buff, image_buff_base64, image_buff_size_base64); + q_info.image_buff_size = image_buff_size_base64; + } + else { + q_info.image_buff_size = 0; + } + + if (strlen(emailData.email_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords(pNext, -1, -1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); + //} + //else { + //strcpy(q_info.content, emailData.email_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else { + q_info.content[0] = ' '; + q_info.content[1] = '\0'; + } + + strcpy(q_info.post_url, "post_to_mail"); + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); + + + QueuePush(q_info, _POST_NOTIFICATION); + +#ifdef GY_OS_V_SERIES + +#else + if (Get_mail_post_interval() != -1) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } + } +#endif + } + last_ms_CheckPostEventCondition_email = current_ms_CheckPostEventCondition_email; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_email = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_email = 1; + } + } + } + } +//#ifdef GY_OS_AMBA + if (strcmp(SystemSetting.enable_ftp, "Yes") == 0 && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_ftp == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_ftp == 0)))){ + if (last_ms_CheckPostEventCondition_ftp == 0 || (current_ms_CheckPostEventCondition_ftp - last_ms_CheckPostEventCondition_ftp) > d_no_parking_time * 1000 || force_to_push == 1) + { + if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + QueueInfo q_info = { 0 }; + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (image_buff_size_base64 >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + /* + if (strlen(emailData.email_content) >= 1) { + if (pNext != NULL) { + ReplaceKeyWords(pNext,-1,-1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); + } + else { + strcpy(q_info.content, emailData.email_content); + } + } + else*/ + { + q_info.content[0] = ' '; + q_info.content[1] = '\0'; + } + + strcpy(q_info.post_url, "curl_to_ftp"); + //UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); + + if (q_info.image_buff_size >= 1) { + QueuePush(q_info, _POST_NOTIFICATION); + } + } + last_ms_CheckPostEventCondition_ftp = current_ms_CheckPostEventCondition_ftp; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_ftp = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_ftp = 1; + } + } + } + } +//#endif + } +} + +struct timeval currtime_HeartbeatPost; +static long last_ms_HeartbeatPost = 0; +#if defined GY_OS_AMBA +struct timeval currtime_snmp_HeartbeatPost; +static long last_ms_snmp_HeartbeatPost = 0; +#endif +void HeartbeatPost() +{ + if (activePostNotification && strcmp(heartbeatData.enable_heartbeat,"Yes")==0) { + gettimeofday(&currtime_HeartbeatPost, NULL); + long current_ms_HeartbeatPost = (currtime_HeartbeatPost.tv_sec * 1000) + (currtime_HeartbeatPost.tv_usec / 1000); + if (last_ms_HeartbeatPost == 0 || (current_ms_HeartbeatPost - last_ms_HeartbeatPost) >= atoi(heartbeatData.heartbeat_dwell) * 1000 * 60) { + + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(heartbeatData.heartbeat_link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + int index_j = j; + + postEventList[index_j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_HeartbeatPost = current_ms_HeartbeatPost; + } + } +#if defined GY_OS_AMBA + if (activeSNMPPost && strcmp(heartbeatData.enable_snmp_heartbeat, "Yes") == 0) { + gettimeofday(&currtime_snmp_HeartbeatPost, NULL); + long current_ms_snmp_HeartbeatPost = (currtime_snmp_HeartbeatPost.tv_sec * 1000) + (currtime_snmp_HeartbeatPost.tv_usec / 1000); + if (last_ms_snmp_HeartbeatPost == 0 || (current_ms_snmp_HeartbeatPost - last_ms_snmp_HeartbeatPost) >= (long)(atof(heartbeatData.snmp_heartbeat_dwell) * 1000.0)) { + for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) + { + if (strcmp(heartbeatData.snmp_heartbeat_link_to_post_event_name, SNMPManagementList[j].snmp_event_name) == 0) + { + if (SNMPManagementList[j].check_if_delivering == 0) { + pthread_mutex_lock(&mutex_post_notification_pop); + + SNMPManagementList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + + strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); + strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); + strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); + strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); + strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); + strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); + strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); + strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); + + if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value, "<|hextoint|>") == 0) { + size_t snmp_size = ReplaceKeyWords(NULL, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, 0, 0, 0, NULL, 0, 0, NULL, 0, 0); + q_info.snmp_value[snmp_size] = '\0'; + } + else { + strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); + } + + if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_snmp_HeartbeatPost = current_ms_snmp_HeartbeatPost; + } + } +#endif +} +#ifdef GY_OS_AMBA +struct timeval currtime_check_start_PTZ_autotracking_Post; +static long last_ms_check_start_PTZ_autotracking_Post = 0; +int last_state_PTZ_autotracking_for_start = 0; +int current_state_PTZ_autotracking_for_start = 0; +void check_start_PTZ_autotracking_Post() +{ + if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { + current_state_PTZ_autotracking_for_start = 1; + } + else { + current_state_PTZ_autotracking_for_start = 0; + } + + gettimeofday(&currtime_check_start_PTZ_autotracking_Post, NULL); + long current_ms_check_start_PTZ_autotracking_Post = (currtime_check_start_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_start_PTZ_autotracking_Post.tv_usec / 1000); + + if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_start_autotracking, "Yes") == 0) { + if (last_ms_check_start_PTZ_autotracking_Post == 0 || (current_ms_check_start_PTZ_autotracking_Post - last_ms_check_start_PTZ_autotracking_Post) >= 2000) { + if (last_state_PTZ_autotracking_for_start == 0 && current_state_PTZ_autotracking_for_start == 1) { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(heartbeatData.ptz_start_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + int index_j = j; + + postEventList[index_j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; + } + else{ + last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; + } + } + } +} + +struct timeval currtime_check_end_PTZ_autotracking_Post; +static long last_ms_check_end_PTZ_autotracking_Post = 0; +int last_state_PTZ_autotracking_for_end = 0; +int current_state_PTZ_autotracking_for_end = 0; +void check_end_PTZ_autotracking_Post() +{ + if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { + current_state_PTZ_autotracking_for_end = 1; + } + else { + current_state_PTZ_autotracking_for_end = 0; + } + + gettimeofday(&currtime_check_end_PTZ_autotracking_Post, NULL); + long current_ms_check_end_PTZ_autotracking_Post = (currtime_check_end_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_end_PTZ_autotracking_Post.tv_usec / 1000); + + if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_end_autotracking, "Yes") == 0) { + if (last_ms_check_end_PTZ_autotracking_Post == 0 || (current_ms_check_end_PTZ_autotracking_Post - last_ms_check_end_PTZ_autotracking_Post) >= 2000) { + if (last_state_PTZ_autotracking_for_end == 1 && current_state_PTZ_autotracking_for_end == 0) { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(heartbeatData.ptz_end_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + int index_j = j; + + postEventList[index_j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; + } + else{ + last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; + } + } + } +} +#endif +curl_information_smtp_t user_smtp; +void SendMailEventCondition(char *my_subject,char * my_content, char* image_buff, int image_buff_size) { + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + size_t snapshot_size = 0; + if (image_buff_size >= 1) { + snapshot_size = (size_t)image_buff_size; + memcpy(snapshot_addr, image_buff, snapshot_size); + } + + strcpy(user_smtp.receiver[0], IPCAMService.email_address1); + strcpy(user_smtp.receiver[1], IPCAMService.email_address2); + strcpy(user_smtp.receiver[2], IPCAMService.email_address3); + strcpy(user_smtp.receiver[3], IPCAMService.email_address4); + strcpy(user_smtp.receiver[4], IPCAMService.email_address5); + + strcpy(user_smtp.address, IPCAMService.email_address); + strcpy(user_smtp.server, IPCAMService.smtp_server); + sprintf(user_smtp.auth_mode, "%d", IPCAMService.smtp_auth_mode); + strcpy(user_smtp.port, IPCAMService.smtp_port); + sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); + strcpy(user_smtp.user, IPCAMService.auth_account); + strcpy(user_smtp.password, IPCAMService.auth_password); + + strcpy(user_smtp.subject, my_subject); + strcpy(user_smtp.memory_data.memory, my_content); + user_smtp.memory_data.size = strlen(my_content); + + strcpy(user_smtp.attachment, "snap.jpg"); + + + if (net_curl_smtp_data(&user_smtp, snapshot_addr,(int)snapshot_size) < 0) { + printf("\nSMTP Fail\n"); + } + else { + printf("\nSMTP OK\n"); + } +} + +void ResetCheckIfDelivering() { + for (int i = 0; i < MAX_POST_EVENTS; i++) + { + postEventList[i].check_if_delivering = 0; + } +//#ifdef GY_OS_AMBA + //for (int i = 0; i < MAX_SNMP_MANAGEMENT; i++) + //{ + //SNMPManagementList[i].check_if_delivering = 0; + //} +//#endif +} + +#ifdef GY_OS_V_SERIES + +#else +//struct timeval last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE], now_t_CheckEventCounterCondition; +//static long s_last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE] = { 0 }; +//static long s_now_t_CheckEventCounterCondition = 0; +int g_record_counter_count[MAX_EVENT_COUNTERS] = { 0 }; +long g_record_counter_time[MAX_EVENT_COUNTERS] = { 0 }; + +#endif + +struct timeval currtime_CheckEventCounterCondition[MAX_EVENT_COUNTERS]; +static long last_ms_CheckEventCounterCondition[MAX_EVENT_COUNTERS] = { 0 }; + +void CheckEventCounterCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int enable_counter_post, char* image_buff, int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) +{ +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1 || unlockingKeyInnoFR_success == 1 ) { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + //printf("\n------UU:11\n"); + + //gettimeofday(&now_t_CheckEventCounterCondition, NULL); + //s_now_t_CheckEventCounterCondition = now_t_CheckEventCounterCondition.tv_sec; //쬰 + + float dwell_time_event_counter = (float)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { + dwell_time_event_counter = (float)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); + } + + + + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + + /////////////////////////// + + char ObjectName[30] = { 0 }; + + if (pNext != NULL) { + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + } + + + //char metadata1[512][STRSPLIT_SIZE] = {0}; //for vehicle + //char MetaData1[BUFSIZE] = { 0 }; + //char MetaOut1[512][50] = { 0 }; + //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); + + //int metadata1_num = get_metadata1_num(detection_zone_idx); + + + //for (int i = 0; i < metadata1_num; i++) + //{ + //UpperToLower(metadata1[i]); + //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); + //} + + //////////////////////// + + for (int i = 0; i < event_counter_num; i++) + { + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + if (strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) + { + gettimeofday(&currtime_CheckEventCounterCondition[j], NULL); + long current_ms_CheckEventCounterCondition = (currtime_CheckEventCounterCondition[j].tv_sec * 1000) + (currtime_CheckEventCounterCondition[j].tv_usec / 1000); + + if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") != 0 || (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0 && + (last_ms_CheckEventCounterCondition[j] == 0 || (current_ms_CheckEventCounterCondition - last_ms_CheckEventCounterCondition[j]) > dwell_time_event_counter * 1000))) + { + last_ms_CheckEventCounterCondition[j] = current_ms_CheckEventCounterCondition; + //eventCounterList[j].metadata1_num = metadata1_num; + + //for (int m = 0; m < metadata1_num; m++) { + //strcpy(eventCounterList[j].MetaOut1[m], get_meta_class(m, detection_zone_idx)); + //} + + if (pNext == NULL) { + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count > 2000000000) { + eventCounterList[j].counter_count = 2000000000; + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { + //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count < 0) { + eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { + //eventCounterList[j].counter_count = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + else { + if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { + + eventCounterList[j].counter_count = g_record_counter_count[j]; + + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + } + } + } + else if ((strcmp(eventCounterList[j].enable_time_range, "Yes") != 0 && + (((!((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) ) || + (pNext != NULL && !(IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) || + (pNext != NULL && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) )) + ) || + (pNext != NULL && strcmp(eventCounterList[j].enable_time_range, "Yes") == 0 && pNext->det_time >= eventCounterList[j].timetTimeRangeFrom && pNext->det_time < eventCounterList[j].timetTimeRangeTo)) + { + + //printf("\n----------eventCounterList[j].counter_count:%d\n", eventCounterList[j].counter_count); + //printf("\n----------viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num:%d\n", viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num); + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count > 2000000000) { + eventCounterList[j].counter_count = 2000000000; + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { + //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count < 0) { + eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + else { + if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { + + eventCounterList[j].counter_count = g_record_counter_count[j]; + + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + } + } + + //printf("\neventCounterList[%d].counter_count:%d\n",j, eventCounterList[j].counter_count); + } + } + + if (enable_counter_post == 1) { + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment != -2) + CheckPostEventCondition(pNext, tracking_channel_idx, detection_zone_idx, trigger_idx, 0, "", j, image_buff, image_buff_size, image_buff_base64, image_buff_size_base64, cropped_image_base64, cropped_image_size_base64); + } + + + break; + } + } + + } + + //printf("\n-------------------\n"); + } +#endif +} + +void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, CPoint* zone_polygon,int side_number,int zone_index,int iSource_ori_w, int iSource_ori_h) { + + CPoint p_person[MAX_SENSOR_TYPE0]; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 0; + int count_four_points_touch = 0; + int count_touch = 0; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + + if (g_sensors_type == 0) { + p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / iSource_ori_w); + p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / iSource_ori_h); + } + else { + p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / iSource_ori_w); + p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / iSource_ori_h); + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] = isInside(zone_polygon, side_number, p_person[index_p]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] == 1) { + count_touch++; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] = isInside(zone_polygon, 4, p_person[index_p]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] == 1) { + count_four_points_touch++; + } + } + + //printf("\n----------count_four_points_touch:%d\n", count_four_points_touch); + //printf("\n----------count_touch:%d\n", count_touch); + + int threahold_div = g_sensors_type == 0 ? 1 : 7; + + if (count_four_points_touch >= 45/threahold_div) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 1; + } + + if (count_touch >= 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 1; + pNext->IsInsideZone[zone_index] = 1; + } + +} + +struct timeval last_t_UpdateZoneStatus, now_t_UpdateZoneStatus; +static long s_last_t_UpdateZoneStatus[MAX_DETECTION_ZONE] = {0}; +static long s_now_t_UpdateZoneStatus = 0; +void MissingObjectDetection_VanishInZone(int tracking_channel_idx) { + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { + if (s_last_t_UpdateZoneStatus[j] == 0) { + gettimeofday(&last_t_UpdateZoneStatus, NULL); + s_last_t_UpdateZoneStatus[j] = last_t_UpdateZoneStatus.tv_sec; + } + } + + gettimeofday(&now_t_UpdateZoneStatus, NULL); + s_now_t_UpdateZoneStatus = now_t_UpdateZoneStatus.tv_sec; //쬰 + + int check_if_missing = 0; + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION) { + + float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; + + if ((s_now_t_UpdateZoneStatus - s_last_t_UpdateZoneStatus[j]) > dwell_time_missing_object_detection) { + s_last_t_UpdateZoneStatus[j] = s_now_t_UpdateZoneStatus; + + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) + break; + else { + int check_if_ever_existing = 0; + for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { + if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) + break; + else if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]) { + check_if_ever_existing = 1; + break; + } + } + + if (check_if_ever_existing == 1) { + + for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { + if (viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) + break; + else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] == 0 || + index_obj_tracking_id_in_zone_temp == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { + check_if_missing = 1; + break; + } + } + if (check_if_missing == 1) { + printf("\n-------------TRIGGER_MISSING_OBJECT_DETECTION check_if_missing: Yes------------\n"); + break; + } + } + } + } + + //TRIGGER_MISSING_OBJECT_DETECTION +#if 0 + printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION\n"); + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + printf("%d,", viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); + + } + printf("\n-----------------------------------------\n"); + + printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last\n"); + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); + + } + printf("\n-----------------------------------------\n"); + + printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last_two\n"); + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); + + } + printf("\n-----------------------------------------\n"); +#endif + + int k = 0; + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { + if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) + break; + else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]!= 0 && viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) { + viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[k] = viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; + k++; + } + } + } + for (int index_obj_tracking_id_in_zone = k; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) + viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; + + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; + } + + if (check_if_missing == 1) { + viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; + } + else { + viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; + } + } + } + } + } + } +} + + +void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, float fInSourceOri_w, float fInSourceOri_h, int total_element_size, detection_pos* PosInfo, int result_idx) +{ + int side_number = 6;//side_number = viewDetectionZone[tracking_channel_idx][j].point_num; + CPoint zone_polygon[6] = { 0 }; + int b_ZoneExist = 0; + + detection_pos* pNext2 = NULL; + int BindNewLicensePlateOk = 0; + + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + if (IsANPRCategory(featureType)) + { + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext->properties.plate); + pNext->linked_plate_length = pNext->properties.plate_length; + } + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; + } + + if (viewChannelData[0].enable_traffic) { + for (int m = 0; m < total_element_size; m++) + { + pNext2 = PosInfo + m; + if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { + + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && + (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) + ) + { + strcpy(pNext->car_type_name, pNext2->name); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); + + break; + } + } + } + } + } + else if (viewChannelData[0].enable_traffic) + { + //BindLicensePlateToVehicle + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + { + for (int k = 0/*result_idx + 1*/; k < total_element_size; k++) + { + pNext2 = PosInfo + k; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && + (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) + ) + { + + pNext2->car_logo_idx = result_idx; + strcpy(pNext2->car_type_name, pNext->name); + if (pNext2->obj_tracking_id_idx >= 0) { + strcpy(g_TrackingRecords[tracking_channel_idx][pNext2->obj_tracking_id_idx].car_type_name, pNext2->car_type_name); + } + //Steven MARK 20200930 + //printf("track_obj_id[%d]Plate = %s \n", tracking_obj_idx, pNext2->properties.plate); + + if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate)) + { + //if (levenshtein_distance(pNext2->properties.plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate) <= 3) + //{ + + if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext2->properties.plate); + pNext->linked_plate_length = pNext2->properties.plate_length; + + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext2->properties.plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext2->properties.plate_length; + //printf("track_obj_id[%d]linkPlate = %s \n", tracking_obj_idx, pUpdateZoneNext->linked_plate); + BindNewLicensePlateOk = 1; + } + //} + } + break; + } + + } + } + + if (!BindNewLicensePlateOk) + { + if (strlen(pNext->linked_plate) == 0) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length >= atoi(viewChannelData[0].min_characters) && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate); + pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length; + } + } + else { + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; + } + } + } + } + } + } + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + int check_existing_in_metaout = 0; + check_existing_in_metaout = check_if_existing_in_metaout(ObjectName, j); + //int metadata1_num = get_metadata1_num(j); + + if (check_existing_in_metaout == 0 && strcmp(ObjectName, "object") != 0 && strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0 && strcmp(ObjectName, "face") != 0 && IsANPRCategory_L_Plate(pNext->name) == 0) + { + continue; + } + + int check_if_go_straight_existing = 0; + int check_if_speed_existing = 0; + float ratio_area_zone_polygon = 0.0; + int index_of_trigger_event_to_checked = -1; + unsigned int trigger_event_type = 0; + + for (int m = 0; m < MAX_TRIGGER_EVENT; m++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { + trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); + + if ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) { + check_if_go_straight_existing = 1; + } + else if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || /*|| (featureType & FEATURE_LPR_TWN) != 0*/ + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) + ) + { + if (check_existing_in_metaout == 1 || (check_existing_in_metaout == 0 && strcmp(pNext->name, "blank") == 0)) + { + if (viewDetectionZone[tracking_channel_idx][j].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][j].parking_line >= 1) + { + viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = m; + int index_plot = -1; + float min_parking_distance = 10000; + for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][j].parking_space; index_parking++) { + /* + detection_pos pNext_plot; + pNext_plot.left_x = g_parking_space_recording_x[j][index_parking] - pNext->width * 0.25; + pNext_plot.top_y = g_parking_space_recording_y[j][index_parking] - pNext->height * 0.25; + pNext_plot.width = pNext->width * 0.5; + pNext_plot.height = pNext->height * 0.5;*/ + + if (g_parking_space_recording_x[j][index_parking] != 0 && g_parking_space_recording_y[j][index_parking] != 0) { + + if (g_parking_space_recording_x[j][index_parking] >= pNext->left_x - pNext->width * 0.25 && g_parking_space_recording_x[j][index_parking] <= (pNext->left_x + pNext->width*1.25) && + g_parking_space_recording_y[j][index_parking] >= pNext->top_y - pNext->height * 0.25 && g_parking_space_recording_y[j][index_parking] <= (pNext->top_y + pNext->height*1.25) && + g_temp_parking_space_check_table[j][index_parking] == 0 /*&& detection_overlap_ratio_union(pNext,&pNext_plot) >= 0.9*/) + { + if (index_plot == -1) { + index_plot = index_parking; + min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + } + else { + float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + if (temp_min_parking_distance < min_parking_distance) { + index_plot = index_parking; + min_parking_distance = temp_min_parking_distance; + } + } + } + else if (strcmp(pNext->name, "blank") == 0) { + if (index_plot == -1) { + index_plot = index_parking; + min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + } + else { + float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + if (temp_min_parking_distance < min_parking_distance) { + index_plot = index_parking; + min_parking_distance = temp_min_parking_distance; + } + } + } + } + } + + if (index_plot >= 0) { + g_temp_parking_space_check_table[j][index_plot] = 1; + pNext->zone_violation_idx[j] = 1; + } + } + } + } + } + else { + if (!(IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE)) { + ratio_area_zone_polygon = polygon_area(zone_polygon, 6) / (float)(CANVAS_WIDTH * CANVAS_HEIGHT); + + + if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { + + } + else if (trigger_event_type == TRIGGER_SPEED_HIGH || + trigger_event_type == TRIGGER_SPEED_LOW) { + check_if_speed_existing = 1; + } + } + else if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { + if (trigger_event_type == TRIGGER_SPEED_HIGH || + trigger_event_type == TRIGGER_SPEED_LOW) { + check_if_speed_existing = 1; + } + } + + } + + index_of_trigger_event_to_checked = m; + break; + } + } + + if (strlen(viewChannelData[tracking_channel_idx].red_light_zone) >= 1 && strcmp(viewChannelData[tracking_channel_idx].red_light_zone, "NULL") != 0) { + if (j == atoi(viewChannelData[tracking_channel_idx].red_light_zone)) { + continue; + } + } + + b_ZoneExist = 0; + //zone_polygon bclientݼgJ]wɮɤwର 889*500 + + for (int k = 0; k < 6; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].Points[k].x > 0 || viewDetectionZone[tracking_channel_idx][j].Points[k].y > 0) + b_ZoneExist = 1; + + zone_polygon[k].x = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + zone_polygon[k].y = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + } + + if (!b_ZoneExist || j == viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1) + continue; + + if (g_IsRadarDevice == 0 && strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0) // 2022-10-20 Ken + { + if ((((pNext->width * pNext->height) / ((float)fInSourceOri_w * (float)fInSourceOri_h)) > ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_max_proportion_in_zone) / 100.0)) || + (((pNext->width * pNext->height) / ((float)fInSourceOri_w *(float)fInSourceOri_h)) < ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_min_proportion_in_zone) / 100.0)) + ) { + continue; + } + } + + if (g_IsPTZDevice == 0 && trigger_event_type == 0) + continue; + + if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1 && strncmp(viewDetectionZone[tracking_channel_idx][j].enable_speed, "No", strlen("No")) == 0) { + continue; + } + + //int iIfDoZone = 1; + //int do_event_trigger = 1; + + //if (iIfDoZone == 1 || g_check_if_set_no_preset_no_autopan == 1) + { + //printf("\n------------ratio_area_zone_polygon:%f\n", ratio_area_zone_polygon); + Record_Point_Touch_and_IsInsideZone(pNext, tracking_channel_idx, tracking_obj_idx, det_count_idx, zone_polygon, side_number, j, fInSourceOri_w, fInSourceOri_h); + } + + if (g_check_if_metadata_stop_happened[j] == 1) { + continue; + } + + //printf("\n------------get_g_check_if_current_light_is_red:%d\n", get_g_check_if_current_light_is_red()); + + //if(do_event_trigger == 1 || g_check_if_set_no_preset_no_autopan == 1) + { + if (det_count_idx > 0 && index_of_trigger_event_to_checked >= 0) + { + //printf("\n---BBB------pNext->engine_type:%d\n", pNext->engine_type); + //printf("\n---BBB------pNext->obj_type:%d\n", pNext->obj_type); + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); + //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); + + if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0) { + + //printf("\n-----------------B2\n"); + + int current_count_touch = 0; + int last_count_touch = 0; + float threshold_for_count_touch = 0.77; + int threshold_for_last_count_touch = 55; + int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 + + if (ratio_area_zone_polygon >= 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 560 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 480 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 420 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 360 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 300 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 260 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 220 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 190 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 170 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 150 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { + threshold_for_count_touch = 0.73; + threshold_for_last_count_touch = 105 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { + threshold_for_count_touch = 0.74; + threshold_for_last_count_touch = 85 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { + threshold_for_count_touch = 0.76; + threshold_for_last_count_touch = 65 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { + threshold_for_count_touch = 0.77; + threshold_for_last_count_touch = 55 / threahold_div; + } + else { + threshold_for_count_touch = 0.78; + threshold_for_last_count_touch = 45 / threahold_div; + } + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; + last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; + } + //printf("\n------------current_count_touch:%d\n", current_count_touch); + //printf("\n------------last_count_touch:%d\n", last_count_touch); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { + if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { + + //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + if(strcmp(pNext->name,"person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) + { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p==q | p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + + } + + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + + if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { + if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || + (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { + + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + printf("\n[p=q error]------------------\n"); + printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, + viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, + viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, + viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, + viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + else { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + /*if (strcmp(pNext->name, "person") == 0) { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + else*/ { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } +#endif + /* + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + //printf("\n------------YYYYYYYYYYYYYYYYY\n"); + for (int kl = 0; kl < g_max_sensor_size; kl++) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + } + } + }*/ + } + } + //printf("\n-------------------[doIntersect]: end\n"); + //printf("\nFEATURE_HUM_DET---4\n"); + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + /* + else if (trigger_event_type == TRIGGER_TURN_LEFT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_WRONG_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); + */ + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + + } + //|y~ApGID諸 + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) + continue; + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + } + } + } + else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { + //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); + //Ĥ@izone ɶ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + //printf("\n----------------A:2\n"); + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + int nNeedTrigger = 0; + + if (trigger_event_type == TRIGGER_SPEED_HIGH) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_SPEED_LOW) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + } + else { + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + int nNeedTrigger = 0; + //printf("\n-----------In_zone\n"); + if (trigger_event_type == TRIGGER_ALLOW_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_BLOCK_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GUEST_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ALL_OBJECTS) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + } + } + else { + + //TRIGGER_SPEED_HIGHMTRIGGER_SPEED_LOW᭱C + + if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) + { +#if 1 + { + if (trigger_event_type == TRIGGER_TAMPERING) { + if (strcmp(ObjectName, "tampering") == 0) + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; + //pNext->detection_zone_idx = j; + pNext->trigger_idx[j] = index_of_trigger_event_to_checked; + pNext->zone_violation_idx[j] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 1) { + //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); + //Ĥ@izone ɶ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + //printf("\n----------------A:2\n"); + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + + { + //TRIGGER_MISSING_OBJECT_DETECTION + float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; + if (check_if_existing_in_metaout(ObjectName, j)) + { + int check_obj_tracking_id_in_zone = 0; + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id) { + check_obj_tracking_id_in_zone = 1; + break; + } + } + +#if 1 + if (check_obj_tracking_id_in_zone == 0) { + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0 || + (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time) > dwell_time_missing_object_detection) + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; + break; + } + if (index_obj_tracking_id_in_zone == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { + for (int index_obj_tracking_id_in_zone_temp = MAX_OBJ_TRACKING_ID_IN_ZONE - 1; index_obj_tracking_id_in_zone_temp >= 1; index_obj_tracking_id_in_zone_temp--) { + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp - 1]; + } + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[0] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; + } + } + } +#endif + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = pNext->obj_dwell_time; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; + + pNext->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; + pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; + } + else { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = pNext->obj_dwell_time; + pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; + } + } + } + + + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_DISTANCE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_DISTANCE_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_HIGH_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_HIGH_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_MISSING_UNATTENDED) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_MISSING_UNATTENDED, total_element_size, PosInfo, result_idx); + //else if (trigger_event_type == TRIGGER_BG_LEARNING) + //nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BG_LEARNING, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ALL_OBJECTS) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_LACK_OF_ANY_OBJECT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_FORGET_TO_GIVE_WAY, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + g_IsCustomWeight == 1) + { + { + nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_QUEUING_VIOLATION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) + viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = index_of_trigger_event_to_checked; + } + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 0) { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + + { + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } +#endif + } + else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1){ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { + //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); + //Ĥ@izone ɶ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + //printf("\n----------------A:2\n"); + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + int nNeedTrigger = 0; + + if (trigger_event_type == TRIGGER_SPEED_HIGH) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_SPEED_LOW) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + } + else if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0){ + + //printf("\n-----------------B2\n"); + + int current_count_touch = 0; + int last_count_touch = 0; + float threshold_for_count_touch = 0.77; + int threshold_for_last_count_touch = 55; + int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 + + if (ratio_area_zone_polygon >= 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 560 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 480 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 420 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 360 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 300 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 260 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 220 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 190 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 170 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 150 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { + threshold_for_count_touch = 0.73; + threshold_for_last_count_touch = 105 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { + threshold_for_count_touch = 0.74; + threshold_for_last_count_touch = 85 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { + threshold_for_count_touch = 0.76; + threshold_for_last_count_touch = 65 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { + threshold_for_count_touch = 0.77; + threshold_for_last_count_touch = 55 / threahold_div; + } + else{ + threshold_for_count_touch = 0.78; + threshold_for_last_count_touch = 45 / threahold_div; + } + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; + last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; + } + //printf("\n------------current_count_touch:%d\n", current_count_touch); + //printf("\n------------last_count_touch:%d\n", last_count_touch); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { + if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { + + //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx-1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) + { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx-1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p==q | p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } +#endif + } + + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + + } + } + + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { + if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || + (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { + + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + printf("\n[p=q error]------------------\n"); + printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, + viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, + viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, + viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, + viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + else { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + /*if (strcmp(pNext->name, "person") == 0) { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + else*/ { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } +#endif + /* + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + //printf("\n------------YYYYYYYYYYYYYYYYY\n"); + for (int kl = 0; kl < g_max_sensor_size; kl++) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + } + } + }*/ + } + } + //printf("\n-------------------[doIntersect]: end\n"); + //printf("\nFEATURE_HUM_DET---4\n"); + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + /* + else if (trigger_event_type == TRIGGER_TURN_LEFT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_WRONG_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); + */ + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + + } + //|y~ApGID諸 + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) + continue; + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + } + } + } + } + } + else if(det_count_idx == 0 && index_of_trigger_event_to_checked >= 0) + { + if (IsANPRCategory_L_Plate(pNext->name)==1 && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext->properties.plate); + pNext->linked_plate_length = pNext->properties.plate_length; + } + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; + } + + if (viewChannelData[0].enable_traffic) { + for (int m = 0; m < total_element_size; m++) + { + pNext2 = PosInfo + m; + if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { + if (detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && + (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) + ) + { + strcpy(pNext->car_type_name, pNext2->name); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); + + break; + } + } + } + } + + //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); + //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { + int nNeedTrigger = 0; + //printf("\n-----------In_zone\n"); + if (trigger_event_type == TRIGGER_ALLOW_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_BLOCK_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GUEST_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + } + else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) { +#ifdef GY_OS_AMBA + if (trigger_event_type == TRIGGER_TAMPERING) { + if (strcmp(ObjectName, "tampering") == 0) + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; + //pNext->detection_zone_idx = j; + pNext->trigger_idx[j] = index_of_trigger_event_to_checked; + pNext->zone_violation_idx[j] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } +#endif +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { + if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + { + //for (int k = 0; k < metadata1_num; k++) + { + if (check_if_existing_in_metaout(ObjectName, j)) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + pNext->trigger_type = TRIGGER_ZONE_VIOLATION | pNext->trigger_type; + //pNext->detection_zone_idx = j; + pNext->trigger_idx[j] = index_of_trigger_event_to_checked; + pNext->zone_violation_idx[j] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } +#endif + } + } + } + } + +} + + +void ApplyTrackingTableAndPrevDetection(detection_pos* PosInfo, int total_element_size,int tracking_channel_idx,int id_idx,int obj_idx) { + + //printf("\n--------%d,%d\n", (int)(PosInfo + obj_idx)->width, (int)(PosInfo + obj_idx)->height); + + if ((PosInfo + obj_idx)->width > 0 && (PosInfo + obj_idx)->height > 0) { + int det_count = 0; + int plate_len = 0, old_plate_len = 0; + det_count = g_TrackingRecords[tracking_channel_idx][id_idx].detection_count; + det_count++; + if (det_count > TRACKING_BUFFER_SIZE) + { + det_count = TRACKING_BUFFER_SIZE; + } + + if (det_count >= 2) {//ĤGframeHW + + if (IsANPRCategory((PosInfo + obj_idx)->engine_type) && strlen((PosInfo + obj_idx)->properties.plate) >= 1) { + + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 + //&& strcmp((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) + && LevenshteinDistance((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + float ratio_y = ((PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y) / (float)get_g_ori_yuv_height(); + float ratio_x = ((PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x) / (float)get_g_ori_yuv_width(); + float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); + + + + if (fabs(ratio_x_y) <= g_thres_bbox_stability_plate) + { + (PosInfo + obj_idx)->top_y = g_PlateRecorderList[j].last_box_y; + (PosInfo + obj_idx)->height = g_PlateRecorderList[j].last_box_h; + (PosInfo + obj_idx)->left_x = g_PlateRecorderList[j].last_box_x; + (PosInfo + obj_idx)->width = g_PlateRecorderList[j].last_box_w; + (PosInfo + obj_idx)->center_y = g_PlateRecorderList[j].last_box_center_y; + (PosInfo + obj_idx)->center_x = g_PlateRecorderList[j].last_box_center_x; + (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; + (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; + } + else + { + float delta_y = (PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y; + float delta_x = (PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x;; + (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; + (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); + } + + break; + } + } + } + + } + else { + + float ratio_y = ((PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y) / (float)get_g_ori_yuv_height(); + float ratio_x = ((PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x) / (float)get_g_ori_yuv_width(); + float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); + + if (fabs(ratio_x_y) <= g_thres_bbox_stability) + { + (PosInfo + obj_idx)->top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y; + (PosInfo + obj_idx)->height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height; + (PosInfo + obj_idx)->left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x; + (PosInfo + obj_idx)->width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width; + (PosInfo + obj_idx)->center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; + (PosInfo + obj_idx)->center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; + (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; + (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; + } + else + { + float delta_y = (PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; + float delta_x = (PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; + (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; + (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); + } + } + + (PosInfo + obj_idx)->check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter; + + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + + (PosInfo + obj_idx)->num_bring_with_object[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone]; + for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { + strcpy((PosInfo + obj_idx)->bring_with_object[index_zone][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[index_zone][index_bring]); + } + + (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone]; + //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone]; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; + + (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; + (PosInfo + obj_idx)->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; + + (PosInfo + obj_idx)->obj_dwell_time = (int)difftime((PosInfo + obj_idx)->det_time, g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + (PosInfo + obj_idx)->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_first_dwell_time; + (PosInfo + obj_idx)->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_last_dwell_time; + + //strcpy((PosInfo + obj_idx)->replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name); + } + else if (det_count == 1) {//Ĥ@framel + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = g_initial_background_learning_rate_x; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = g_initial_background_learning_rate_y; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_initial_background_learning_rate_error_x; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_initial_background_learning_rate_error_y; + + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = g_initial_background_mean_diff_x; + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = g_initial_background_mean_diff_y; + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = g_initial_background_error_diff_x; + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = g_initial_background_error_diff_y; + + (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; + (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; + + (PosInfo + obj_idx)->check_person_inter = 0; + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + (PosInfo + obj_idx)->num_bring_with_object[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] = 0; + (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = 0; + //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone] = 0; + //g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone] = 0; + } + + if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count != 0) + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = 0; + if (g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count != 0) + g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; + + + g_TrackingIDAndChannel[tracking_channel_idx]++; + if (td_weight_num >= 1 && check_if_correct_mail == 1) + { + if (g_TrackingIDAndChannel[tracking_channel_idx] > 19999 || g_TrackingIDAndChannel[tracking_channel_idx] < 10001) + g_TrackingIDAndChannel[tracking_channel_idx] = 10001; + } + else + { + if (g_TrackingIDAndChannel[tracking_channel_idx] > 9999) + g_TrackingIDAndChannel[tracking_channel_idx] = 1; + } + + (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; + (PosInfo + obj_idx)->obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; + g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; + + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = (PosInfo + obj_idx)->det_time; + + //g_TrackingRecords[tracking_channel_idx][id_idx].frame_count = 0; + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].name, (PosInfo + obj_idx)->name); + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name, (PosInfo + obj_idx)->replaced_name); + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time_to_enter_zone[index_zone] = -1; + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[index_zone] = -1; + (PosInfo + obj_idx)->obj_speed[index_zone] = -1; + + g_TrackingRecords[tracking_channel_idx][id_idx].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; + } + //g_TrackingRecords[tracking_channel_idx][id_idx].avg_det_interval = 1.1; + + (PosInfo + obj_idx)->obj_dwell_time = 0; + (PosInfo + obj_idx)->obj_first_dwell_time = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].obj_first_dwell_time = 0; + (PosInfo + obj_idx)->obj_last_dwell_time = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].obj_last_dwell_time = 0; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].bAssign_flag = 1; + g_TrackingRecords[tracking_channel_idx][id_idx].Assign_obj_idx = obj_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].detection_count = det_count; + //g_TrackingRecords[tracking_channel_idx][id_idx].fake_detection_count = 0; + + if (det_count >= 1) { + if ((PosInfo + obj_idx)->obj_type == _PLATE && strlen((PosInfo + obj_idx)->properties.plate) >= 1) + { + plate_len = strlen((PosInfo + obj_idx)->properties.plate); + old_plate_len = strlen(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); + + //printf("[%d] plate1 = %s, %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate); + if (plate_len >= old_plate_len) + { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); + } + else if (plate_len < old_plate_len) + { + //strcpy((PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); + strcpy((PosInfo + obj_idx)->car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name); + } + + //printf("[%d] plate2 = %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate); + } + } +#if 1 + for (int n = 0; n < det_count - 1; n++) + { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].name); + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].replaced_name); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].progress_bar = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].progress_bar; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_direction = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_direction; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_stability = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_stability; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].width; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].height; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].plate_char_top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].plate_char_top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].parent_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].parent_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_logo_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_logo_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].number_row = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].number_row; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].visual_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].visual_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].class_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].class_id; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sec_color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sec_color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_type; +#ifdef GY_OS_AMBA + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_height; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_height; +#endif + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_violation_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_violation_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_check_giveway[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_check_giveway[index_zone]; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].near_iou_count[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].near_iou_count[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone_four_points[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone_four_points[index_zone]; + + if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id == g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id) { + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_having_been_counted[index_zone]; + } + else { + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = 0; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_speed[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_speed[index_zone]; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].s_last_t_Counter[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_within_zone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_within_zone[index_zone]; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_w = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_w; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_h = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_h; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].dash_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].dash_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_milli_sec = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_milli_sec; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_first_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_last_dwell_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate_length; + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_type_name); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].logo); + + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.country, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.pose, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area_id; + //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.counter_count[index_counter] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.counter_count[index_counter]; + //} + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_list, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_length; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id_idx; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].vote_value = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].vote_value; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].disappear_count = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].disappear_count; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].iou_prev_self = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].iou_prev_self; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].test_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].test_id; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].image_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].image_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].adjust_obj_speed; + + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sPlateDirection, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sPlateDirection); + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_person_inter; + + for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].num_bring_with_object[k]; + for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].bring_with_object[k][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].bring_with_object[k][index_bring]); + } + + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n + 1]; + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n + 1]; + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n + 1][index_p]; + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n + 1][index_p]; + } + } + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n + 1]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n + 1]; + } + + if (det_count >= 1) { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].name, (PosInfo + obj_idx)->name); + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].replaced_name, (PosInfo + obj_idx)->replaced_name); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence = (PosInfo + obj_idx)->confidence; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence2 = (PosInfo + obj_idx)->confidence2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].progress_bar = (PosInfo + obj_idx)->progress_bar; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type = (PosInfo + obj_idx)->engine_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type2 = (PosInfo + obj_idx)->engine_type2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x = (PosInfo + obj_idx)->left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y = (PosInfo + obj_idx)->top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x = (PosInfo + obj_idx)->center_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y = (PosInfo + obj_idx)->center_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_direction = (PosInfo + obj_idx)->center_direction; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_stability = (PosInfo + obj_idx)->center_stability; + //printf("\n-------prev #2:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width = (PosInfo + obj_idx)->width; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height = (PosInfo + obj_idx)->height; + //printf("\n-------prev #3:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].plate_char_top_y = (PosInfo + obj_idx)->plate_char_top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].parent_idx = (PosInfo + obj_idx)->parent_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_logo_idx = (PosInfo + obj_idx)->car_logo_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].number_row = (PosInfo + obj_idx)->number_row; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_type = (PosInfo + obj_idx)->obj_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].visual_left_x = (PosInfo + obj_idx)->visual_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].class_id = (PosInfo + obj_idx)->class_id; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color, (PosInfo + obj_idx)->color); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color_id = (PosInfo + obj_idx)->color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sec_color_id = (PosInfo + obj_idx)->sec_color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_type = (PosInfo + obj_idx)->trigger_type; +#ifdef GY_OS_AMBA + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_distance = (PosInfo + obj_idx)->min_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_distance = (PosInfo + obj_idx)->max_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_height = (PosInfo + obj_idx)->min_height; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_height = (PosInfo + obj_idx)->max_height; +#endif + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_idx[index_zone] = (PosInfo + obj_idx)->trigger_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_violation_idx[index_zone] = (PosInfo + obj_idx)->zone_violation_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_check_giveway[index_zone] = (PosInfo + obj_idx)->zone_check_giveway[index_zone]; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].near_iou_count[index_zone] = (PosInfo + obj_idx)->near_iou_count[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone[index_zone] = (PosInfo + obj_idx)->IsInsideZone[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone_four_points[index_zone] = (PosInfo + obj_idx)->IsInsideZone_four_points[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_having_been_counted[index_zone] = (PosInfo + obj_idx)->check_if_having_been_counted[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_speed[index_zone] = (PosInfo + obj_idx)->obj_speed[index_zone]; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].s_last_t_Counter[index_zone] = (PosInfo + obj_idx)->s_last_t_Counter[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id = (PosInfo + obj_idx)->obj_tracking_id; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_x = (PosInfo + obj_idx)->box_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_y = (PosInfo + obj_idx)->box_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_w = (PosInfo + obj_idx)->box_w; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_h = (PosInfo + obj_idx)->box_h; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].dash_left_x = (PosInfo + obj_idx)->dash_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time = (PosInfo + obj_idx)->det_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_milli_sec = (PosInfo + obj_idx)->det_milli_sec; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_dwell_time = (PosInfo + obj_idx)->obj_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_first_dwell_time = (PosInfo + obj_idx)->obj_first_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_last_dwell_time = (PosInfo + obj_idx)->obj_last_dwell_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate, (PosInfo + obj_idx)->linked_plate); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate_length = (PosInfo + obj_idx)->linked_plate_length; + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].logo, (PosInfo + obj_idx)->logo); + + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate, sizeof((PosInfo + obj_idx)->properties.plate)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.country, (PosInfo + obj_idx)->properties.country, sizeof((PosInfo + obj_idx)->properties.country)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area, (PosInfo + obj_idx)->properties.area, sizeof((PosInfo + obj_idx)->properties.area)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.logo, (PosInfo + obj_idx)->properties.logo, sizeof((PosInfo + obj_idx)->properties.logo)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.color, (PosInfo + obj_idx)->properties.color, sizeof((PosInfo + obj_idx)->properties.color)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.pose, (PosInfo + obj_idx)->properties.pose, sizeof((PosInfo + obj_idx)->properties.pose)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area_id = (PosInfo + obj_idx)->properties.area_id; + //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.counter_count[index_counter] = (PosInfo + obj_idx)->properties.counter_count[index_counter]; + //} + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_list, (PosInfo + obj_idx)->properties.plate_list, sizeof((PosInfo + obj_idx)->properties.plate_list)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_length = (PosInfo + obj_idx)->properties.plate_length; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id_idx = (PosInfo + obj_idx)->obj_tracking_id_idx; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].vote_value = (PosInfo + obj_idx)->vote_value; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = (PosInfo + obj_idx)->disappear_count; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].iou_prev_self = (PosInfo + obj_idx)->iou_prev_self; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].test_id = (PosInfo + obj_idx)->test_id; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].image_id = (PosInfo + obj_idx)->image_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].adjust_obj_speed = (PosInfo + obj_idx)->adjust_obj_speed; + + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sPlateDirection, (PosInfo + obj_idx)->sPlateDirection); + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter = (PosInfo + obj_idx)->check_person_inter; + + + + for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] = (PosInfo + obj_idx)->num_bring_with_object[k]; + for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[k][index_bring], (PosInfo + obj_idx)->bring_with_object[k][index_bring]); + } + + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][det_count - 1] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][det_count - 1] = 0; + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][det_count - 1][index_p] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][det_count - 1][index_p] = 0; + } + } + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[det_count - 1] = (PosInfo + obj_idx)->center_direction; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[det_count - 1] = (PosInfo + obj_idx)->center_stability; + } +#endif + + if (det_count >= 1) { + //printf("\n-----www----%f,%f\n", g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y); + if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width > 0.0 && g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height > 0.0) { + + float diff_x = 0; + float diff_y = 0; + //float diff_time = 0; + if (det_count >= 2) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_x; + diff_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_y; + + if (strcmp((PosInfo + obj_idx)->name, "person")==0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; + } + + //diff_time = difftime(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].det_time); +#ifdef GY_OS_AMBA + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (((int)(PosInfo + obj_idx)->center_direction) != DIRECTION_DEFAULT && det_count >= 3) { + float obj_speed; + float obj_speed_old; + float obj_speed_very_old; + detection_pos *PosInfo_very_old, *PosInfo_old, *PosInfo_new; + + PosInfo_new = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1]; + PosInfo_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2]; + PosInfo_very_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 3]; + + float fIou_union_1 = detection_overlap_ratio_union(PosInfo_new, PosInfo_old); + float fIou_union_2 = detection_overlap_ratio_union(PosInfo_new, PosInfo_very_old); + if (fIou_union_1 < 0.85 && fIou_union_2 < 0.85) { + + pthread_mutex_lock(&mutex_perspective_transform); + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = -1; + int count_speed_zone = 0; + + for (int social_zone_idx = 0; social_zone_idx < viewChannelData[tracking_channel_idx].count_zone; social_zone_idx++) { + if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 /*&& + strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "No", strlen("No")) == 0*/) { + if (viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray != NULL) { + obj_speed = SetPerspectiveTransform_GetObjSpeed(PosInfo_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); + obj_speed_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); + obj_speed_very_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_old, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); + + float temp_obj_speed = pow(obj_speed * obj_speed_old * obj_speed_very_old, 1.0 / 3.0); + if (temp_obj_speed < 0.1) + temp_obj_speed = 0.1; + + if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] == -1) + { + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = temp_obj_speed; + } + else if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] >= 0) + { + //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) + //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) + + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = sqrt(g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * temp_obj_speed); + } + + (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + + if (g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg == -1) { + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + } + else { + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg += g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + } + count_speed_zone++; + } + }/* + else if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 && + strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "Yes", strlen("Yes")) == 0) { + + for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { + if (SpeedData[i].flag_protected == 1) { // get_g_ori_yuv_height() get_g_ori_yuv_width(); + + float point_x = SpeedData[i].x * get_g_ori_yuv_width() / SpeedData[i].res_width; + float point_y = SpeedData[i].y * get_g_ori_yuv_height() / SpeedData[i].res_height; + + float bbox_min_x = (PosInfo + obj_idx)->left_x; + float bbox_min_y = (PosInfo + obj_idx)->top_y; + float bbox_max_x = (PosInfo + obj_idx)->left_x + (PosInfo + obj_idx)->width; + float bbox_max_y = (PosInfo + obj_idx)->top_y + (PosInfo + obj_idx)->height; + + if (point_x > bbox_min_x && point_x < bbox_max_x && + point_y > bbox_min_y && point_y < bbox_max_y) { + + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = SpeedData[i].speed; + (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + count_speed_zone++; + + SpeedData[i].flag_protected = 0; + break; + } + } + } + } + */ + } + + if (count_speed_zone >= 1) { + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg /= count_speed_zone; + (PosInfo + obj_idx)->adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg; + } + + pthread_mutex_unlock(&mutex_perspective_transform); + } + } + } +#endif + } + + float temp_diff_x = diff_x; + float temp_diff_y = diff_y; + + diff_x = diff_x + diff_x * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x; + diff_y = diff_y + diff_y * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y; + + if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = 0; + } + + if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = 0; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_x = (PosInfo + obj_idx)->center_x + diff_x; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_y = (PosInfo + obj_idx)->center_y + diff_y; + //g_TrackingRecords[tracking_channel_idx][id_idx].det_interval = diff_time; + + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.left_x = (PosInfo + obj_idx)->left_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.top_y = (PosInfo + obj_idx)->top_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.width = (PosInfo + obj_idx)->width + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2;//* (ratio_w) + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.height = (PosInfo + obj_idx)->height + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2;//* (ratio_h) + + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_x = (PosInfo + obj_idx)->box_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_y = (PosInfo + obj_idx)->box_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_w = (PosInfo + obj_idx)->box_w + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_h = (PosInfo + obj_idx)->box_h + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2; + + float sum_diff_x = 0; + float sum_diff_y = 0; + for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { + sum_diff_x += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x); + sum_diff_y += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y); + } + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = sum_diff_x / (float)det_count; + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = sum_diff_y / (float)det_count; + float sum_2_diff_x = 0; + float sum_2_diff_y = 0; + for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { + sum_2_diff_x += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x, 2.0); + sum_2_diff_y += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y, 2.0); + } + + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = sqrt(sum_2_diff_x); + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = sqrt(sum_2_diff_y); + + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = (temp_diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x + 1.0); + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = (temp_diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y + 1.0); + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x * 1.0; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y * 1.0; + + g_initial_background_learning_rate_x = g_initial_background_learning_rate_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x * 0.01; + g_initial_background_learning_rate_y = g_initial_background_learning_rate_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y * 0.01; + g_initial_background_learning_rate_error_x = g_initial_background_learning_rate_error_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 0.01; + g_initial_background_learning_rate_error_y = g_initial_background_learning_rate_error_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 0.01; + } + } + + } +} + +//#ifdef GY_OS_WIN +//#define CHAO_METH +#define METH_1 + +#define IOU_HISTORY_FRAMES 3 + +//VOTE number +#define VOTE_NAME 20 +#define VOTE_PERSON 25 + +#define VOTE_WITHIN_ZONE 70 + +#define VOTE_MAX_UNION_PREDICT_IOU 100 +#define VOTE_MAX_PREDICT_IOU 100 +#define VOTE_MAX_UNION_PREV_IOU 90 +#define VOTE_MAX_PREV_IOU 90 + +#define VOTE_MAX_UNION_PREDICT_IOU_BONUS 50 +#define VOTE_MAX_PREDICT_IOU_BONUS 50 +#define VOTE_MAX_UNION_PREV_IOU_BONUS 45 +#define VOTE_MAX_PREV_IOU_BONUS 45 + +#define VOTE_SIZE_AVOID_PUNISH 25 //30 +#define VOTE_WRONG_NAME_PUNISH 15 //30 + +#define VOTE_NEIGHBOR 80 +#define VOTE_STATIC 70 +#define VOTE_THE_SAME_SIZE 45 +#define VOTE_PLATE 350 //50 +#define VOTE_PLATE_MIN_SCORE 50 + +//#endif //GY_OS_WIN - DEFINE + +//#ifdef GY_OS_WIN +void reset_id_obj(int tracking_channel_idx, int id_idx) +{ + int disappearCount = g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count; + + if (strlen(g_TrackingRecords[tracking_channel_idx][id_idx].name) >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][id_idx].name) == 1) + { + if (disappearCount >= DISAPPEAR_FRAME_MAX * 20) + { + memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); + } + } + else { + if (disappearCount >= DISAPPEAR_FRAME_MAX) + { + memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); + } + } +} +//#endif //GY_OS_WIN - reset_id_obj + +//#ifdef GY_OS_WIN +float prev_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +float predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +float union_predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +float union_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +int vote_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +//#endif //GY_OS_WIN + +//#ifdef GY_OS_WIN +void update_iou_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) +{ + float fIOU, predit_IOU, union_IOU, union_predit_IOU; + detection_pos* pNext = NULL; + int det_count; + + // iou about obj to obj. + //detection_pos* pNext_b = NULL; + //float fIou_union; + + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + //iou_count = 0; + det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; + //frame_count = g_TrackingRecords[tracking_channel_idx][i].frame_count; + + if (det_count == 0) + continue; + + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //PW@ + union_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //PW@ + + predit_IOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //PwI + union_predit_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //PwI + + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][i].name) == 1 || (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1)) { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][i].name) == 1 && + IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate) == 0*/) { + fIOU = 1.0; + predit_IOU = 1.0; + union_predit_IOU = 1.0; + union_IOU = 1.0; + } + else{ + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + else if (fIOU > 0.0 || predit_IOU > 0.0 || union_predit_IOU > 0.0 || union_IOU > 0.0){ + if (IsVehicleCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { + if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { + + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { + int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width / 2)); + int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height / 2)); + + int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width); + int deltaHeight = abs(pNext->height - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height); + + int threshold_3 = 25; + + if (deltaX <= threshold_3 && deltaY <= threshold_3 && deltaWidth <= threshold_3 && deltaHeight <= threshold_3) { + + } + else { + fIOU = 0.0; + union_IOU = 0.0; + } + + predit_IOU = 0.0; + union_predit_IOU = 0.0; + } + } + } + else if (strcmp(pNext->name, "person") == 0 || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { + if (strcmp(pNext->name, "person") == 0 && strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { + + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { + int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width / 2)); + int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height / 2)); + + int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width); + int deltaHeight = abs(pNext->height - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height); + + int threshold_3 = 25; + + if (deltaX <= threshold_3 && deltaY <= threshold_3 && deltaWidth <= threshold_3 && deltaHeight <= threshold_3) { + + } + else { + fIOU = 0.0; + union_IOU = 0.0; + } + + predit_IOU = 0.0; + union_predit_IOU = 0.0; + } + } + } + else if (IsGarbageCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { + if (IsGarbageCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { + + } + else { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + else if (IsMotorbikeCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { + if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { + + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + } + } + + prev_iou_table[i][j] = fIOU; + predit_iou_table[i][j] = predit_IOU; + union_predit_iou_table[i][j] = union_predit_IOU; + union_iou_table[i][j] = union_IOU; + } + } +} +//#endif //GY_OS_WIN - update_iou_table + +//#ifdef GY_OS_WIN +void update_vote_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) +{ + detection_pos* pNext = NULL; + detection_pos* pNext2 = NULL; + + int det_count; + int vote_value = 0; + + int max_iou_idx = -1; + float max_iou = 0.0; + + int max_predict_iou_idx = -1; + float max_predict_iou = 0.0; + + int max_union_iou_idx = -1; + float max_union_iou = 0.0; + + int max_union_predict_iou_idx = -1; + float max_union_predict_iou = 0.0; + + + float pre_H, pre_W; + float delta_w, delta_h; + //int old_confidence; + + if (IsANPRCategory(featureType)) { + for (int m = 0; m < total_element_size; m++) + { + pNext = PosInfo + m; + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { + for (int k = 0; k < total_element_size; k++) + { + pNext2 = PosInfo + k; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && + (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) + ) + { + strcpy(pNext2->car_type_name, pNext->name); + + if (strlen(pNext2->properties.plate) > strlen(pNext->linked_plate)) + { + if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + + strcpy(pNext->linked_plate, pNext2->properties.plate); + pNext->linked_plate_length = pNext2->properties.plate_length; + } + } + + break; + } + } + } + } + } + } + + for (int k = 0; k < MAX_TRACKING_NUM; k++) + { + max_iou = 0.0; + max_iou_idx = -1; + + max_predict_iou = 0.0; + max_predict_iou_idx = -1; + + max_union_iou = 0.0; + max_union_iou_idx = -1; + + max_union_predict_iou = 0.0; + max_union_predict_iou_idx = -1; + + det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + + if (det_count == 0) + continue; + + for (int m = 0; m < total_element_size; m++) + { + pNext = PosInfo + m; + + vote_value = 0; + vote_table[k][m] = vote_value; + + ////PvMwInAƥ[v + { + vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU * prev_iou_table[k][m]); + if (prev_iou_table[k][m] > max_iou) + { + max_iou = prev_iou_table[k][m]; + max_iou_idx = m; + } + + vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU * predit_iou_table[k][m]); + if (predit_iou_table[k][m] > max_predict_iou) + { + max_predict_iou = predit_iou_table[k][m]; + max_predict_iou_idx = m; + } + + vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU * union_iou_table[k][m]); + //PWvIpnIOU + if (union_iou_table[k][m] > max_union_iou) + { + max_union_iou = union_iou_table[k][m]; + max_union_iou_idx = m; + } + + vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU * union_predit_iou_table[k][m]); + //PwIpn IOU + if (union_predit_iou_table[k][m] > max_union_predict_iou) + { + max_union_predict_iou = union_predit_iou_table[k][m]; + max_union_predict_iou_idx = m; + } + } + + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + //printf("\n-------pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); + + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][m] += VOTE_PLATE_MIN_SCORE; + + if (prev_iou_table[k][m] > max_iou) + { + max_iou = prev_iou_table[k][m]; + max_iou_idx = m; + } + + if (predit_iou_table[k][m] > max_predict_iou) + { + max_predict_iou = predit_iou_table[k][m]; + max_predict_iou_idx = m; + } + + //PWvIpnIOU + if (union_iou_table[k][m] > max_union_iou) + { + max_union_iou = union_iou_table[k][m]; + max_union_iou_idx = m; + } + + //PwIpn IOU + if (union_predit_iou_table[k][m] > max_union_predict_iou) + { + max_union_predict_iou = union_predit_iou_table[k][m]; + max_union_predict_iou_idx = m; + } + //printf("\n-------same plate #1\n"); + } + else { + vote_table[k][m] = 0; + //printf("\n-------not same plate #2\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + //printf("\n----#2---pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); + //printf("\n---------same car\n"); + vote_table[k][m] += VOTE_PLATE_MIN_SCORE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + + //ӧOإ[Jv + //max_iou_idx + + if (max_iou_idx != -1) + { + vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU_BONUS); + //obj name same + pNext = PosInfo + max_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #1\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + if (max_union_iou_idx != -1) + { + vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU_BONUS); + //obj name same + pNext = PosInfo + max_union_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_union_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #2\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_union_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + + if (max_predict_iou_idx != -1) + { + vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU_BONUS); + //obj name same + pNext = PosInfo + max_predict_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_predict_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #1\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_predict_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + if (max_union_predict_iou_idx != -1) + { + vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU_BONUS); + pNext = PosInfo + max_union_predict_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #3\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + for (int m = 0; m < total_element_size; m++) + { + pNext = PosInfo + m; + + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + + } + else { + vote_table[k][m] = 0; + continue; + } + } + + if (IsVehicleCategory(pNext)) { + if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "van")) { + + + + } + else { + if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { + vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + } + } + } + else if (IsMotorbikeCategory(pNext)) { + if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ng")) { + + } + else { + if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { + vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + } + } + } + else { + /*if (strcmp(pNext->name,"new_object")==0) { + int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width, pNext->height, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0); + if (checkisInside == 1) { + vote_table[k][m] += VOTE_PERSON; + } + else { + if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { + vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + } + } + } + else */ + //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { + //if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) { + //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + //} + //else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 2) { + //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH * 10; + //} + //} + } + + if (get_g_check_if_show_parking() == 1) { + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + if (g_TrackingRecords[tracking_channel_idx][k].check_if_within_zone[index_zone] == PosInfo->check_if_within_zone[index_zone]) + { + vote_table[k][m] += VOTE_WITHIN_ZONE; + } + } + } + + //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { + //vote_table[k][m] += VOTE_NAME; + //if (strcmp("person", pNext->name) == 0) + //{ + //vote_table[k][m] += VOTE_PERSON; + //} + //} +#if 1 + //PwIe + pre_H = g_TrackingRecords[tracking_channel_idx][k].predict_detection.height; + pre_W = g_TrackingRecords[tracking_channel_idx][k].predict_detection.width; + + delta_h = 1.0 - fabs(pNext->height / pre_H - 1.0); + delta_w = 1.0 - fabs(pNext->width / pre_W - 1.0); + + vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_h; + vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_w; + + double new_width = 0.0; + double new_height = 0.0; + double new_slide = 0.0; + + double new_pred_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].predict_detection.left_x; + double new_pred_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].predict_detection.top_y; + double new_pred_vec = sqrt(new_pred_vec_x*new_pred_vec_x + new_pred_vec_y * new_pred_vec_y); + + if (strcmp(pNext->name, "person") == 0 && strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { + new_width = pre_W * 5.5; + new_height = pre_H * 4.5; + new_slide = sqrt(new_width*new_width + new_height * new_height); + } + else { + new_width = pre_W * 2.5; + new_height = pre_H * 2.5; + new_slide = sqrt(new_width*new_width + new_height * new_height); + } + + //F񪺹wI + if (new_pred_vec <= new_slide) { + vote_table[k][m] += VOTE_NEIGHBOR * (new_slide - new_pred_vec) / (new_slide); + } + + if (det_count >= 1) { + int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)); + int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2)); + + //ˬdשMe׬O_b@wd + int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width); + int deltaHeight = abs(pNext->height - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height); + + int threshold = 5; + int threshold_2 = 10; + int threshold_3 = 25; + + if (deltaX <= threshold && deltaY <= threshold && deltaWidth <= threshold && deltaHeight <= threshold) { + vote_table[k][m] += VOTE_STATIC; + } + else if (deltaX <= threshold_2 && deltaY <= threshold_2 && deltaWidth <= threshold_2 && deltaHeight <= threshold_2) { + vote_table[k][m] += VOTE_STATIC * 0.8; + } + else if (deltaX <= threshold_3 && deltaY <= threshold_3 && deltaWidth <= threshold_3 && deltaHeight <= threshold_3) { + vote_table[k][m] += VOTE_STATIC * 0.2; + } + } +#endif +#if 1 + //vyV + if (det_count >= 2) + { + double new_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x; + double new_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y; + + //double new_vec = sqrt(new_vec_x*new_vec_x + new_vec_y* new_vec_y); + + double old_vec_x = 0.0; + double old_vec_y = 0.0; + + old_vec_x = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].left_x; + old_vec_y = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].top_y; + + //첾Vۤ + if (old_vec_x < 0) + { + if (new_vec_x > 0 && abs(new_vec_x) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)) //3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + + if (old_vec_x > 0) + { + if (new_vec_x < 0 && abs(new_vec_x) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2))//3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + + if (old_vec_y < 0) + { + if (new_vec_y > 0 && abs(new_vec_y) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + + if (old_vec_y > 0) + { + if (new_vec_y < 0 && abs(new_vec_y) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + } +#endif + } + } +} +//#endif //GY_OS_WIN - update_vote_table + +int find_possible_obj(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, int id_idx,int use_high_or_low_score) +{ + int max_vote_value = 0; + int obj_idx = -1; + detection_pos* pNext = NULL; + + //printf("\n-------id_idx:%d\n", id_idx); + + if(use_high_or_low_score == 0) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_0; + else if(use_high_or_low_score == 1) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_1; + else if (use_high_or_low_score == 2) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_2; + else if (use_high_or_low_score == 3) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_3; + + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->obj_tracking_id > 0) + continue; + + //printf("\n---------vote_table[id_idx][%d]:%d\n",j, vote_table[id_idx][j]); + if (vote_table[id_idx][j] > max_vote_value) + { + max_vote_value = vote_table[id_idx][j]; + obj_idx = j; + } + } + + ///if bbox j already assign id, check vote_value + //printf("\n------id_idx:%d---obj_idx:%d\n", id_idx, obj_idx); + if (obj_idx != -1) + { + //printf("\n---------obj_idx:%d\n", obj_idx); + + pNext = PosInfo + obj_idx; + + //pNext->vote_value = max_vote_value; + pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; + pNext->obj_tracking_id_idx = id_idx; + } + //if bbox j already assign id, check vote_value + + return obj_idx; +} +//#endif //GY_OS_WIN - find_possible_obj + +int Modify_Plate_and_Recount_Length(char *input_plate,char *output_plate) { + char afterBuf[256] = { 0 }; + strcpy(afterBuf, input_plate); + + char buf[64] = { 0 }; + memset(buf, 0x00, sizeof(buf)); + strcpy(buf, afterBuf); + + int k = 0; + int plate_length = 0; + + //printf("\n------1\n"); + //printf("\nbuf:%s\n",buf); + //printf("\n------2\n"); + for (int m = 0; m < strlen(buf); m++) + { + //printf("[%x]",buf[m]); + if (buf[m] >= 65 && buf[m] <= 90) { + + if (buf[m] == 73 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { + afterBuf[m] = '1'; + } + else if (buf[m] == 79 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { + afterBuf[m] = '0'; + } + + //alphabets++; + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + else if (buf[m] >= 97 && buf[m] <= 122) { + if (buf[m] == 105 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { + afterBuf[m] = '1'; + } + else if (buf[m] == 111 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { + afterBuf[m] = '0'; + } + + if ((featureType & FEATURE_LPR_TWN) <= 0) { + //alphabets++; + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + } + else if (buf[m] >= 48 && buf[m] <= 57) { + //digits++; + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + else { + //specialcharacters++; + if ((featureType & FEATURE_LPR_JPN) > 0) { + //ѦҤUTF-8ATcզ@ӤAĤ@cA|227-239C + if (buf[m] >= 227 && buf[m] <= 239 && (m + 2) < strlen(buf)) { + afterBuf[k] = afterBuf[m]; + k++; + afterBuf[k] = afterBuf[m + 1]; + k++; + afterBuf[k] = afterBuf[m + 2]; + k++; + m = m + 2; + + plate_length++; + } + } + else if ((featureType & FEATURE_LPR_THA) > 0 || (featureType & FEATURE_LPR_BGD) > 0) { + //ѦҮΩs[ԤUTF-8ATcզ@ӮΩs[ԤAĤ@cA|O224C + if (buf[m] == 224 && (m + 2) < strlen(buf)) { + afterBuf[k] = afterBuf[m]; + k++; + afterBuf[k] = afterBuf[m + 1]; + k++; + afterBuf[k] = afterBuf[m + 2]; + k++; + m = m + 2; + + plate_length++; + } + } + else if ((featureType & FEATURE_LPR_MEA) > 0) { + //ѦҪԧBUTF-8Acզ@ӪԧBAĤ@cA|O67C + if (buf[m] >= 216 && buf[m] <= 217 && (m + 1) < strlen(buf)) { + + //if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) + { + //afterBuf[k] = afterBuf[m]; + //k++; + //afterBuf[k] = afterBuf[m + 1]; + //k++; + m = m + 1; + + //plate_length++; + } + //else { + //m = m + 1; + //} + } + //䴩, ť + else if (buf[m] == 45 + || buf[m] == 32) { + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + } + else if ((featureType & FEATURE_LPR_TWN) > 0) { + //䴩rUTF-8ATcզ@ӤAĤ@cA|228-233C + if (buf[m] >= 228 && buf[m] <= 233 && (m + 2) < strlen(buf)) { + + if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) { + afterBuf[k] = afterBuf[m]; + k++; + afterBuf[k] = afterBuf[m + 1]; + k++; + afterBuf[k] = afterBuf[m + 2]; + k++; + m = m + 2; + + plate_length++; + } + else { + m = m + 2; + } + } + else if (buf[m] == 45) {//䴩 + if (activeDisplayDash) + { + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + } + } + } + } + //printf("\n------\n"); + afterBuf[k] = '\0'; + //printf("\nafterBuf:%s\n", afterBuf); + + if (((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION && strcmp(WeightFileModeName, "mod003") == 0)) { + strcpy(afterBuf, input_plate); + k = strlen(input_plate); + afterBuf[k] = '\0'; + plate_length = k; + } + + if (plate_length >= atoi(viewChannelData[0].min_characters) && + plate_length <= atoi(viewChannelData[0].max_characters)) + strcpy(output_plate, afterBuf); + else + plate_length = 0; + return plate_length; +} + +void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size) +{ +#ifdef GY_OS_AMBA + detection_pos* pNext = NULL; + for (int i = 0; i < total_element_size; i++) + { + //printf("\n[start all nets] while 10-1\n"); + pNext = PosInfo + i; /** sizeof(detection_pos)*/ + + + if (strlen(pNext->name) == 0) { + continue; + } + char c_logo[50] = { 0 }; + + int iCar_idx = pNext->car_logo_idx;//pNext->car_logo_idx + detection_pos *pNext_car; + + if (iCar_idx >= 0) + { + pNext_car = PosInfo + iCar_idx;//iCar_idx + int iLogo_idx = pNext_car->car_logo_idx; + detection_pos *pNext_logo = NULL; + //printf("\n----------iLogo_idx:%d\n", iLogo_idx); + if (IsVehicleCategory(pNext_car)) { + if (iLogo_idx >= 0) + { + pNext_logo = PosInfo + iLogo_idx; + //printf("\n---------pNext_logo->name:%s\n", pNext_logo->name); + if (pNext_logo->name + && strlen(pNext_logo->name) > 0 + && !IsANPRCategory_L_Plate(pNext_logo->name) + && !IsVehicleCategory(pNext_logo) + && strcmp(pNext_logo->name, "person") != 0 + && (pNext_logo->name[0] != '0' && + pNext_logo->name[0] != '1' && + pNext_logo->name[0] != '2' && + pNext_logo->name[0] != '3' && + pNext_logo->name[0] != '4' && + pNext_logo->name[0] != '5' && + pNext_logo->name[0] != '6' && + pNext_logo->name[0] != '7' && + pNext_logo->name[0] != '8' && + pNext_logo->name[0] != '9') + ) { + char temp_buf[50] = { 0 }; + int index_temp_buf = 0; + + for (int m = 0; m < (int)strlen(pNext_logo->name); m++) { + if (m < (int)strlen(pNext_logo->name) - 1 && pNext_logo->name[m] == 'l' && pNext_logo->name[m + 1] == '_') { + m++; + } + else { + temp_buf[index_temp_buf] = pNext_logo->name[m]; + index_temp_buf++; + } + } + temp_buf[index_temp_buf] = '\0'; + + sprintf(c_logo, "%s", temp_buf); + } + else { + sprintf(c_logo, "%s", ""); + } + strcpy(pNext_logo->logo, c_logo); + } + else { + sprintf(c_logo, "%s", ""); + } + strcpy(pNext_car->logo, c_logo); + } + else { + sprintf(c_logo, "%s", ""); + } + strcpy(pNext->properties.logo, c_logo); + } + + int check_if_logo = 0; + char temp_name[30] = { 0 }; + int index_temp_name = 0; + for (int index_name = 0; index_name < (int)strlen(pNext->name); index_name++) { + if (index_name < (int)strlen(pNext->name) - 1 && pNext->name[index_name] == 'l' && pNext->name[index_name + 1] == '_') { + index_name++; + check_if_logo = 1; + } + else { + temp_name[index_temp_name] = pNext->name[index_name]; + index_temp_name++; + } + } + temp_name[index_temp_name] = '\0'; + if (check_if_logo == 1) { + strcpy(pNext->name, temp_name); + strcpy(pNext->properties.logo, temp_name); + } + } +#endif +} + +void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_temp, int tracking_channel_idx, time_t curr_det_time, int i_InSourceOri_w, int i_InSourceOri_h) +{ + int total_element_size = * total_element_size_temp; + + struct timeval currtime; + gettimeofday(&currtime, NULL); + int det_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); + + gettimeofday(&currtime, NULL); + long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + long last_ms = now_ms; + + double dw_FPS_time_delta = (double)(now_ms - last_ms); + + /*double dur; + clock_t start, end; + start = clock();*/ +#ifdef GY_OS_NOVA + g_sensors_type = 1; +#endif + +#ifdef GY_OS_AMBA + g_sensors_type = 1; + //g_sensors_type = atoi(SystemSetting.sensors_type); +#endif + //g_max_sensor_size = g_sensors_type == 0 ? MAX_SENSOR_TYPE0 : MAX_SENSOR_TYPE1; + + float ratio_w = (float)i_InSourceOri_w;//0.25f + float ratio_h = (float)i_InSourceOri_h;//0.3f + + //printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\nGetObjectTrackingIDNew: %d\n",10); + //printf("\nratio_w: %f\n", ratio_w); + //printf("\nratio_h: %f\n", ratio_h); + //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + + detection_pos* pNext = NULL; + //detection_pos* pNext_temp = NULL; + + for (int k = 0; k < MAX_DETECTION_ZONE; k++) + { + //eventCounterList[j].counter_count = 0; + viewDetectionZone[tracking_channel_idx][k].queuing_trigger_event_idx = -1; + } + + //printf("----det time = %d ms\n", det_ms); + + //2020-04-10 Updated + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + pNext->obj_tracking_id = 0; + //pNext->vote_value = 0; + pNext->det_time = curr_det_time; + pNext->det_milli_sec = det_ms; + pNext->trigger_type = 0; + //pNext->disappear_count = 0; + pNext->obj_tracking_id_idx = -1; + + pNext->replaced_id = 0; + pNext->replaced_id_idx = -1; + + //printf("[%d] p_name 10 = %s \n", i, pNext->name); + //pNext->iou_prev_self = 0; + pNext->adjust_obj_speed = -1; + pNext->check_if_replaced_in_zone = 0; + //strcpy(pNext->replaced_name, ""); + + //pNext->image_id = -1; + + pNext->obj_dwell_time = 0; + pNext->obj_first_dwell_time = 0; + pNext->obj_last_dwell_time = 0; + } + + memset(prev_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + memset(predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + memset(union_predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + memset(union_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + + memset(vote_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + reset_id_obj(tracking_channel_idx, i); + g_TrackingRecords[tracking_channel_idx][i].bAssign_flag = 0; + //g_TrackingRecords[tracking_channel_idx][i].vote_value = 0; + g_TrackingRecords[tracking_channel_idx][i].Assign_obj_idx = -1; + } + + /// + update_iou_table(PosInfo, total_element_size, tracking_channel_idx); + update_vote_table(PosInfo, total_element_size, tracking_channel_idx); + /// + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #1:%lf ms\n", dw_FPS_time_delta); + + int det_count = 0; +#if 1 + ///Search Multi connection bbox + int closest_obj_idx = -1; + int bFindTrackingObjects = 0; + + for (int index_score = 0; index_score < 4; index_score++) { + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + //reset_id_obj(&g_TrackingRecords[tracking_channel_idx][i],i); + + det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; + if (det_count == 0) + continue; + + if (g_TrackingRecords[tracking_channel_idx][i].bAssign_flag == 1) + continue; + + //first time : find_possible_obj for high score + //second time : find_possible_obj for low score + //more time : find_possible_obj for lower score + closest_obj_idx = find_possible_obj(PosInfo, total_element_size, tracking_channel_idx, i, index_score); + + bFindTrackingObjects = 0; + if (closest_obj_idx != -1) + bFindTrackingObjects = 1; + + //printf("\n-------i:%d-------closest_obj_idx:%d\n",i, closest_obj_idx); + + if (bFindTrackingObjects) + { + ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, i, closest_obj_idx); + } + } + } +#endif + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #2:%lf ms\n", dw_FPS_time_delta); + + ///Assign New obj ID to new bounding box + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + det_count = 0; + + if (pNext->obj_tracking_id <= 0) + { + ///Check prev data again + float max_prev_iou = 0.0; + int closest_id_idx = -1; + for (int j = 0; j < MAX_TRACKING_NUM; j++) + { + if (g_TrackingRecords[tracking_channel_idx][j].bAssign_flag) + continue; + + det_count = g_TrackingRecords[tracking_channel_idx][j].detection_count; + + if (det_count >= 1) + { + float fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1]); + + if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 1) { + if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate) == 0*/) { + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + } + else if (strcmp(pNext->name, "ambulance") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (strcmp(pNext->name, "blank") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (strcmp(pNext->name, "face") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate) == 0*/) { + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + } + } + } + else if (g_TrackingRecords[tracking_channel_idx][j].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + + } + else if (det_count >= 2 && + g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + } + else if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][j].name) == 0) { + if (fIOU > max_prev_iou) + { + + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + //printf("\n---------max_prev_iou:%f,top_y:%f\n", max_prev_iou,pNext->top_y); + } + else if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "van"))) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + } + else if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ng"))) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + } + else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(heartbeatData.events_default_version, "4") == 0) + { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + } + + } + } + + if (closest_id_idx != -1) + { + //pNext->vote_value = max_prev_iou; + pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][closest_id_idx].obj_tracking_id; + pNext->obj_tracking_id_idx = closest_id_idx; + + ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, closest_id_idx, i); + } + else { + for (int m = 0; m < MAX_TRACKING_NUM; m++) + { + if (g_TrackingRecords[tracking_channel_idx][m].bAssign_flag) + continue; + + det_count = g_TrackingRecords[tracking_channel_idx][m].detection_count; + if (det_count == 0) + { + //pNext->vote_value = 0; + pNext->obj_tracking_id = 0; + pNext->obj_tracking_id_idx = m; + + ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, m, i); + + break; + } + } + } + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #3:%lf ms\n", dw_FPS_time_delta); + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) + { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && pNext->obj_dwell_time >= 1 && strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && + pNext->height >= 1 && pNext->width >= 1) + { + int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width * 1.5, pNext->height * 1.5, g_ori_yuv_width, g_ori_yuv_height, 0); + + if (checkisInside == 1 && (pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.2 + && pNext->width / (float)g_ori_yuv_width < 0.2 && pNext->height / (float)g_ori_yuv_height < 0.2) { + + det_count = g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].detection_count; + for (int index_det = det_count - 1 - 1; index_det >= 0; index_det--) { + if (strlen(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name) >= 1 && + strcmp(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name, "object") != 0) + { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name); + break; + } + } + + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (pNext->height / pNext->width <= 1.05 || ((pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height)) >= 0.05 || + pNext->width / (float)g_ori_yuv_width > 0.05) { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "car"); + pNext->check_if_replaced_in_zone = 1; + } + else { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "person"); + pNext->check_if_replaced_in_zone = 1; + } + } + } + } + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #4:%lf ms\n", dw_FPS_time_delta); + + time_t current_time = time(0); + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + pop_not_to_track_vehicles(j, current_time); + } + + ///}lƥIJoUpdateZoneStatus + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + //if (strcmp(pNext->name, "object") == 0) + //{ + //if (strlen(pNext->replaced_name) >= 1) { + //strcpy(pNext->name, pNext->replaced_name); + //} + //} + + { + int k = pNext->obj_tracking_id_idx; + det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + UpdateZoneStatus(pNext, tracking_channel_idx, k, det_count - 1, ratio_w, ratio_h, total_element_size, PosInfo, i); + } + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #5:%lf ms\n", dw_FPS_time_delta); + /////////-------------- + + for (int k = 0; k < MAX_TRACKING_NUM; k++) { + if (g_TrackingRecords[tracking_channel_idx][k].bAssign_flag == 0) { + det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + if (det_count >= 1) { + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].disappear_count++; + } + g_TrackingRecords[tracking_channel_idx][k].disappear_count++; + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #6:%lf ms\n", dw_FPS_time_delta); +#if 1 + + int ZoneQueuingCount[MAX_DETECTION_ZONE] = { 0 }; + int ZoneGivewayCount[MAX_DETECTION_ZONE] = { 0 }; + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + ZoneQueuingCount[i] = 0; + ZoneGivewayCount[i] = 0; + } + + ////////----------Forget to give way detection § + int index_zone_protect = -1; + int index_zone_keep_away = -1; + int index_zone_protect_2 = -1; + int index_zone_keep_away_2 = -1; + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect) == 1) { + index_zone_protect = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect); + } + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away) == 1) { + index_zone_keep_away = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away); + } + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2) == 1) { + index_zone_protect_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2); + } + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2) == 1) { + index_zone_keep_away_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2); + } + + + if ((index_zone_protect >= 0 && index_zone_keep_away >= 0) || (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0)) { + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_check_giveway[i] == 1) + { + ZoneGivewayCount[i]++; + } + } + } + + if (index_zone_protect >= 0 && index_zone_keep_away >= 0) { + if (ZoneGivewayCount[index_zone_protect] >= 1 && ZoneGivewayCount[index_zone_keep_away] >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_check_giveway[index_zone_keep_away] == 1) + { + pNext->zone_violation_idx[index_zone_keep_away] = 1; + pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; + pNext->trigger_idx[index_zone_keep_away] = k; + if (pNext->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; + } + } + } + break; + } + } + } + } + + if (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0) { + if (ZoneGivewayCount[index_zone_protect_2] >= 1 && ZoneGivewayCount[index_zone_keep_away_2] >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away_2].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_check_giveway[index_zone_keep_away_2] == 1) + { + pNext->zone_violation_idx[index_zone_keep_away_2] = 1; + pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; + pNext->trigger_idx[index_zone_keep_away_2] = k; + if (pNext->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; + } + } + } + break; + } + } + } + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #7:%lf ms\n", dw_FPS_time_delta); + + ///pƾp + + /*end = clock(); + dur = (double)(end - start); + printf("\nGet Object Tracking ID New[5]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) + { + ZoneQueuingCount[i]++; + } + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #8:%lf ms\n", dw_FPS_time_delta); + /* + end = clock(); + dur = (double)(end - start); + printf("\nGet Object Tracking ID New[6]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + /* + if (ZoneQueuingCount[i]>0) { + printf("\n---------------\n"); + printf("\nZoneQueuingCount[%d]:%d\n",i, ZoneQueuingCount[i]); + printf("\n---------------\n"); + }*/ + +#ifdef GY_OS_V_SERIES + int check_if_enable_linked_to_dwell_time = 0; + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; +#else + int check_if_enable_linked_to_dwell_time = 0; + +#if 1 + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { + + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][i].trigger_event[k].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + //printf("\n------UU:14\n"); + + for (int w = 0; w < event_counter_num; w++) + { + for (int m = 0; m < MAX_EVENT_COUNTERS; m++) + { + if (strlen(eachEventCounter[w]) >= 1 && strcmp(eachEventCounter[w], eventCounterList[m].counter_name) == 0) + { + if (strcmp(eventCounterList[m].enable_linked_to_dwell_time, "Yes") == 0) { + check_if_enable_linked_to_dwell_time = 1; + break; + } + } + } + if (check_if_enable_linked_to_dwell_time == 1) + break; + } + } + } +#endif +#endif + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + g_IsCustomWeight == 1) { + + if (viewDetectionZone[tracking_channel_idx][i].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][i].parking_line >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { + + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1) { + viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx = k; + + int count_plot = 0; + for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][i].parking_space; index_plot++) + { + if (g_parking_space_check_table[i][index_plot] == 1) { + count_plot++; + } + } + + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = count_plot; + + if (viewDetectionZone[tracking_channel_idx][i].prev_queuing_num >= viewDetectionZone[tracking_channel_idx][i].queuing_count + && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + + int temp_m = -1; + if (pNext->zone_violation_idx[i] == 1) { + //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); + pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; + //pNext->detection_zone_idx = i; + pNext->trigger_idx[i] = k; + + for (int m = 0; m < MAX_TRACKING_NUM; m++) + { + if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) + { + g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; + g_TrackingRecords[tracking_channel_idx][m].trigger_zone_id = i + 1; + temp_m = m; + break; + } + } + } + + pNext->check_if_having_been_counted[i] = 0; + if(temp_m >= 0) + g_TrackingRecords[tracking_channel_idx][temp_m].check_if_having_been_counted[i] = 0; + } + } + else { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) { + pNext->zone_violation_idx[i] = 0; + } + } + } + } + } + } + } + else{ + + if (check_if_enable_linked_to_dwell_time == 0) + { + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + } + + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { + + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { + + if (ZoneQueuingCount[i] >= viewDetectionZone[tracking_channel_idx][i].queuing_count + && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) + { + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) { + //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); + pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; + //pNext->detection_zone_idx = i; + pNext->trigger_idx[i] = k; + + for (int m = 0; m < MAX_TRACKING_NUM; m++) + { + if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) + { + g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; + break; + } + } + } + } + } + } + } + } + + } + } + else { + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + } + } + /** + end = clock(); + dur = (double)(end - start); + printf("\nGet Object Tracking ID New[7]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC));*/ +#endif + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----Get Object Tracking IDNew #9:%lf ms\n", dw_FPS_time_delta); + *total_element_size_temp = total_element_size; +} + +#ifdef GY_OS_WIN +unsigned int GetObjectSocialDistance(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, IplImage* ipl_img, float distance_heigh, float distance_width) +{ + float x1 = viewDetectionZone[tracking_channel_idx][0].Points[0].x; + float y1 = viewDetectionZone[tracking_channel_idx][0].Points[0].y; + + float x2 = viewDetectionZone[tracking_channel_idx][0].Points[1].x; + float y2 = viewDetectionZone[tracking_channel_idx][0].Points[1].y; + + float x3 = viewDetectionZone[tracking_channel_idx][0].Points[2].x; + float y3 = viewDetectionZone[tracking_channel_idx][0].Points[2].y; + + float x4 = viewDetectionZone[tracking_channel_idx][0].Points[3].x; + float y4 = viewDetectionZone[tracking_channel_idx][0].Points[3].y; + + float d_x1, d_y1, d_x2, d_y2, d_x3, d_y3, d_x4, d_y4; + +#if 1 + CvPoint2D32f src_points[4]; + CvPoint2D32f dst_points[4]; + + float ratio_window_h, ratio_window_w; + ratio_window_h = ipl_img->height / CANVAS_HEIGHT; + ratio_window_w = ipl_img->width / CANVAS_WIDTH; + + + //window size -> real resultion of camera + x1 = x1 * ratio_window_w; + y1 = y1 * ratio_window_h; + + x2 = x2 * ratio_window_w; + y2 = y2 * ratio_window_h; + + x3 = x3 * ratio_window_w; + y3 = y3 * ratio_window_h; + + x4 = x4 * ratio_window_w; + y4 = y4 * ratio_window_h; + + + //x1 = (x1 / CANVAS_WIDTH) * 3840; + //y1 = (y1 / CANVAS_HEIGHT) * 2160; + + //x2 = (x2 / CANVAS_WIDTH) * 3840; + //y2 = (y2 / CANVAS_HEIGHT) * 2160; + + //x3 = (x3 / CANVAS_WIDTH) * 3840; + //y3 = (y3 / CANVAS_HEIGHT) * 2160; + + //x4 = (x4 / CANVAS_WIDTH) * 3840; + //y4 = (y4 / CANVAS_HEIGHT) * 2160; + + //d_x1 = (d_x1 / CANVAS_WIDTH) * 3840; + //d_y1 = (d_y1 / CANVAS_HEIGHT) * 2160; + //d_x2 = (d_x2 / CANVAS_WIDTH) * 3840; + //d_y2 = (d_y2 / CANVAS_HEIGHT) * 2160; + + //d_x3 = (d_x3 / CANVAS_WIDTH) * 3840; + //d_y3 = (d_y3 / CANVAS_HEIGHT) * 2160; + //d_x4 = (d_x4 / CANVAS_WIDTH) * 3840; + //d_y4 = (d_y4 / CANVAS_HEIGHT) * 2160; + + d_x1 = 0; + d_y1 = 0; + d_x2 = distance_width; + d_y2 = 0; + d_x3 = distance_width; + d_y3 = distance_heigh; + d_x4 = 0; + d_y4 = distance_heigh; + + src_points[0].x = x1; + src_points[0].y = y1; + src_points[1].x = x2; + src_points[1].y = y2; + + src_points[2].x = x3; + src_points[2].y = y3; + src_points[3].x = x4; + src_points[3].y = y4; + + + dst_points[0].x = d_x1; + dst_points[0].y = d_y1; + dst_points[1].x = d_x2; + dst_points[1].y = d_y2; + + dst_points[2].x = d_x3; + dst_points[2].y = d_y3; + dst_points[3].x = d_x4; + dst_points[3].y = d_y4; + + CvMat *M = cvCreateMat(3, 3, CV_32FC1); + cvGetPerspectiveTransform(src_points, dst_points, M); + + PerspectiveTransform(PosInfo, total_element_size, M, distance_heigh, distance_width, ipl_img->height, ipl_img->width); + +#if 0 + IplImage* dst = NULL; + CvSize ImageSize1 = cvSize(994, 364); + dst = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3); + cvZero(dst); + + CvScalar fillval = cvScalarAll(0); + + cvWarpPerspective(ipl_img, dst, M, CV_INTER_LINEAR, fillval); + cvNamedWindow("Affine_Transform", 1); + cvShowImage("Affine_Transform", dst); + + cvWaitKey(1); +#endif + //cvReleaseImage(&dst); + //cvReleaseMat(M); + cvReleaseMat(&M); +#endif +} +#endif //GY_OS_WIN - GetObjectSocialDistance + +void BindLicensePlateToVehicle(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) +{ + detection_pos* pNext = NULL; + detection_pos* pNext2 = NULL; + int BindNewLicensePlateOk = 0; + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (i == total_element_size - 1) + break; + + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + { + //printf("tracking_channel_idx ==== %d \n", tracking_channel_idx); + for (int k = 0; k < MAX_TRACKING_NUM; k++) + { + if (g_TrackingRecords[tracking_channel_idx][k].obj_tracking_id == pNext->obj_tracking_id) + { + for (int j = i + 1; j < total_element_size; j++) + { + pNext2 = PosInfo + j; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0)) + { + if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][k].linked_plate)) + { + int det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + //StrReplace(pNext2->properties.plate, "-", ""); + + if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext2->properties.plate); + pNext->linked_plate_length = pNext2->properties.plate_length; + strcpy(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext2->properties.plate); + g_TrackingRecords[tracking_channel_idx][k].linked_plate_length = pNext2->properties.plate_length; + + if (det_count > 0) + { + strcpy(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate, pNext2->properties.plate); + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate_length = pNext2->properties.plate_length; + } + + BindNewLicensePlateOk = 1; + } + } + break; + } + } + } + + if (!BindNewLicensePlateOk) { + if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= atoi(viewChannelData[0].min_characters) && + g_TrackingRecords[tracking_channel_idx][k].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][k].linked_plate); + pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][k].linked_plate_length; + } + } + } + } + } + } +} + +int number_of_digits(long long n) +{ + int count = 0; + while (n != 0) + { + // n = n/10 + n /= 10; + ++count; + } + return count; +} + +void check_license(int license, int adv_license, int bMacMatch, time_t start_time, time_t end_time, char* filename) +{ + pthread_mutex_lock(&mutex_check_license); + //printf("\n[check_license] start\n"); + //printf("\n[check_license] filename:%s\n", filename); + + //memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); + + //#ifdef GY_OS_WIN + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *s_root, *tlt_code; + s_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (s_root) { + tlt_code = cJSON_GetObjectItem(s_root, "TLT code"); //trial launch time + //cJSON* virtual_mac = cJSON_GetObjectItem(s_root, "VM code"); //virtual MAC + + //ѽXWɶ - step 1:base64 decode + size_t base64_decode_length = 0; + char EncryptKeyData[256]; + char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + base64_decode(tlt_code->valuestring, strlen(tlt_code->valuestring), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //ѽXWɶ - step 2:AES descrytion + KeyExpansion(key, expandedKey); + AESDecryptArrayToArray(EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); + + //oWɶXT + time_t last_launch_time = atoll(DecryptKeyData); + + //ˬdPWɶO_T + time_t now_time = g_osdSysTimeStamp; + + if (now_time < 1000000000) { + now_time = time(0); + } + + while (number_of_digits(last_launch_time) > number_of_digits(now_time)) { + last_launch_time /= 10; + } + + char strLaunchTime[16] = { 0 }; +#ifdef GY_OS_WIN + snprintf(strLaunchTime, sizeof(strLaunchTime), "%I64d", now_time); +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //onlldAldA|D + snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); +#endif + //printf("\nstrLaunchTime:%s", strLaunchTime); +//#endif + + /*{ + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&now_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nnow_time:%s", buff); + } + { + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&start_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nstart_time:%s", buff); + } + { + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&end_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nend_time:%s", buff); + } + { + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&last_launch_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nlast_launch_time:%s", buff); + }*/ + + //printf("\n--------------license:%d\n", license); + + if (license == 0 && check_if_fe_fail == 0) + { + licenseType = _NO_LICENSE; + afsCode = _NOT_LICENSED; + strcpy(strLicenseStatus, "Invalid license"); + printf("\n[check_license] Invalid license:%d\n", licenseType); + } + else if (check_if_fe_fail == 1 || license == _PERMANENT_LICENSE_MULTI || license == _PERMANENT_LICENSE_SINGLE || license == _PERMANENT_LICENSE_MULTI_POST || license == _PERMANENT_LICENSE_SINGLE_POST || + license == _LICENSE_FPS06 || license == _LICENSE_FPS12 || license == _LICENSE_FPS18 || license == _LICENSE_FPS24 || license == _LICENSE_FPS30 || + license == _LICENSE_FPS36 || license == _LICENSE_FPS42 || license == _LICENSE_FPS48 || license == _LICENSE_FPS54 || license == _LICENSE_FPS60) + { + + switch (license) + { + case _PERMANENT_LICENSE_MULTI: + licenseType = _PERMANENT_LICENSE_MULTI; + http_license_fps = 60; + break; + case _PERMANENT_LICENSE_SINGLE: + licenseType = _PERMANENT_LICENSE_SINGLE; + break; + case _PERMANENT_LICENSE_MULTI_POST: + licenseType = _PERMANENT_LICENSE_MULTI_POST; + break; + case _PERMANENT_LICENSE_SINGLE_POST: + licenseType = _PERMANENT_LICENSE_SINGLE_POST; + break; + case _LICENSE_FPS06: + licenseType = _LICENSE_FPS06; + http_license_fps = 6; + break; + case _LICENSE_FPS12: + licenseType = _LICENSE_FPS12; + http_license_fps = 12; + break; + case _LICENSE_FPS18: + licenseType = _LICENSE_FPS18; + http_license_fps = 18; + break; + case _LICENSE_FPS24: + licenseType = _LICENSE_FPS24; + http_license_fps = 24; + break; + case _LICENSE_FPS30: + licenseType = _LICENSE_FPS30; + http_license_fps = 30; + break; + case _LICENSE_FPS36: + licenseType = _LICENSE_FPS36; + http_license_fps = 36; + break; + case _LICENSE_FPS42: + licenseType = _LICENSE_FPS42; + http_license_fps = 42; + break; + case _LICENSE_FPS48: + licenseType = _LICENSE_FPS48; + http_license_fps = 48; + break; + case _LICENSE_FPS54: + licenseType = _LICENSE_FPS54; + http_license_fps = 54; + break; + case _LICENSE_FPS60: + licenseType = _LICENSE_FPS60; + http_license_fps = 60; + break; + default: + licenseType = _LICENSE_FPS06; + http_license_fps = 6; + } + + switch (adv_license) + { + case _AD_LICENSE_BASIC: + advLicenseType = _AD_LICENSE_BASIC; + break; + case _AD_LICENSE_01: + advLicenseType = _AD_LICENSE_01; + break; + default: + advLicenseType = _AD_LICENSE_BASIC; + } + + if (!bMacMatch) + { + afsCode = _MAC_MISMATCH; + strcpy(strLicenseStatus, "License mismatch the system ID"); + } + else + { + afsCode = _LICENSED; + strcpy(strLicenseStatus, "Licensed."); + } + } + else if (license == _TRIAL_LICENSE_MULTI || license == _TRIAL_LICENSE_SINGLE || + license == _TRIAL_LICENSE_FPS06 || license == _TRIAL_LICENSE_FPS12 || license == _TRIAL_LICENSE_FPS18 || license == _TRIAL_LICENSE_FPS24 || license == _TRIAL_LICENSE_FPS30 || + license == _TRIAL_LICENSE_FPS36 || license == _TRIAL_LICENSE_FPS42 || license == _TRIAL_LICENSE_FPS48 || license == _TRIAL_LICENSE_FPS54 || license == _TRIAL_LICENSE_FPS60) + { + + switch (license) + { + case _TRIAL_LICENSE_MULTI: + licenseType = _TRIAL_LICENSE_MULTI; + http_license_fps = 60; + break; + case _TRIAL_LICENSE_SINGLE: + licenseType = _TRIAL_LICENSE_SINGLE; + break; + case _TRIAL_LICENSE_FPS06: + licenseType = _TRIAL_LICENSE_FPS06; + http_license_fps = 6; + break; + case _TRIAL_LICENSE_FPS12: + licenseType = _TRIAL_LICENSE_FPS12; + http_license_fps = 12; + break; + case _TRIAL_LICENSE_FPS18: + licenseType = _TRIAL_LICENSE_FPS18; + http_license_fps = 18; + break; + case _TRIAL_LICENSE_FPS24: + licenseType = _TRIAL_LICENSE_FPS24; + http_license_fps = 24; + break; + case _TRIAL_LICENSE_FPS30: + licenseType = _TRIAL_LICENSE_FPS30; + http_license_fps = 30; + break; + case _TRIAL_LICENSE_FPS36: + licenseType = _TRIAL_LICENSE_FPS36; + http_license_fps = 36; + break; + case _TRIAL_LICENSE_FPS42: + licenseType = _TRIAL_LICENSE_FPS42; + http_license_fps = 42; + break; + case _TRIAL_LICENSE_FPS48: + licenseType = _TRIAL_LICENSE_FPS48; + http_license_fps = 48; + break; + case _TRIAL_LICENSE_FPS54: + licenseType = _TRIAL_LICENSE_FPS54; + http_license_fps = 54; + break; + case _TRIAL_LICENSE_FPS60: + licenseType = _TRIAL_LICENSE_FPS60; + http_license_fps = 60; + break; + default: + licenseType = _TRIAL_LICENSE_FPS06; + http_license_fps = 6; + } + + switch (adv_license) + { + case _AD_LICENSE_BASIC: + advLicenseType = _AD_LICENSE_BASIC; + break; + case _AD_LICENSE_01: + advLicenseType = _AD_LICENSE_01; + break; + default: + advLicenseType = _AD_LICENSE_BASIC; + } + + if (!bMacMatch) + { + afsCode = _MAC_MISMATCH; + strcpy(strLicenseStatus, "Trial mismatch the system ID"); + } + else if (now_time < start_time-3600*24) + { + afsCode = _UNINITIALIZED; + strcpy(strLicenseStatus, "Trial has expired. Trial not initialized."); //Trial not initialized + } + else if (last_launch_time- 3600 * 24 > now_time) //Yeɶj󥻦ɶ, ܨtήɶQקL + { + printf("\n------------------[Incorrect system time detected]-------------------\n"); + char msg_temp[512] = { 0 }; + printf("\nlast_launch_time: %lld , now_time: %lld\n", (long long int)last_launch_time, (long long int)now_time); + sprintf(msg_temp,"last_launch_time: %lld , now_time: %lld", (long long int)last_launch_time, (long long int)now_time); + afsCode = _EXPIRED; + strcpy(strLicenseStatus, "Trial has expired. Incorrect system time detected."); + strcat(strLicenseStatus, msg_temp); + now_time = last_launch_time; + } + else if (now_time > end_time+3600*24) + { + afsCode = _EXPIRED; + strcpy(strLicenseStatus, "Trial has expired"); + } + else + { + afsCode = _LICENSED; + char Msg[256] = { 0 }; + double diffDays = difftime(end_time, now_time) / (60 * 60 * 24); + if (diffDays < 0) + diffDays = 0; + snprintf(Msg, sizeof(Msg), "Licensed(%d days left)", (int)diffDays); + strcpy(strLicenseStatus, Msg); + } + } + + //#ifdef GY_OS_WIN + //Nɶ[K, gJɮ + if (!(last_launch_time > now_time)) + { + //printf("\n[check_license] write file\n"); + KeyExpansion(key, expandedKey); + unsigned char EncryptData[1 * 1024]; + memset(EncryptData, 0x00, sizeof(EncryptData)); + int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); + + size_t base64_encode_length = 0; + char launchTime[1024] = { 0 }; + base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); + *(launchTime + base64_encode_length) = '\0'; + + cJSON_ReplaceItemInObject(s_root, "TLT code", cJSON_CreateString(launchTime)); + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(filename, "w"); + if (f == NULL) + { + printf("---------------------------Error opening setting file!-----------------------------\n"); +#if 1 + stop_test_nn_cavalry("Error opening setting file!"); + //stop_server(); + +#endif + //exit(EXIT_FAILURE); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + //#endif + + stAMBAcontent.licenseType = licenseType; + stAMBAcontent.afsCode = afsCode; + stAMBAcontent.advLicenseType = advLicenseType; + + //printf("\n-------strLicenseStatus:%s\n", strLicenseStatus); + + //printf("\n[check_license] licenseType:%d %d %d\n", licenseType, afsCode,advLicenseType); + } + } + + pthread_mutex_unlock(&mutex_check_license); +} + +void SetDatasetCategory(int licenseType, char* strDatasetCategory) +{ + switch (licenseType) + { + case _PERMANENT_LICENSE_MULTI: + case _LICENSE_FPS06: + case _LICENSE_FPS12: + case _LICENSE_FPS18: + case _LICENSE_FPS24: + case _LICENSE_FPS30: + case _LICENSE_FPS36: + case _LICENSE_FPS42: + case _LICENSE_FPS48: + case _LICENSE_FPS54: + case _LICENSE_FPS60: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _PERMANENT_LICENSE_SINGLE: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _TRIAL_LICENSE_MULTI: + case _TRIAL_LICENSE_FPS06: + case _TRIAL_LICENSE_FPS12: + case _TRIAL_LICENSE_FPS18: + case _TRIAL_LICENSE_FPS24: + case _TRIAL_LICENSE_FPS30: + case _TRIAL_LICENSE_FPS36: + case _TRIAL_LICENSE_FPS42: + case _TRIAL_LICENSE_FPS48: + case _TRIAL_LICENSE_FPS54: + case _TRIAL_LICENSE_FPS60: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _TRIAL_LICENSE_SINGLE: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _PERMANENT_LICENSE_MULTI_POST: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _PERMANENT_LICENSE_SINGLE_POST: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + default: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + } +} + +void check_feature() +{ + char strDatasetCategory[MAX_MSG_LEN] = { 0 }; + char *strDatasetCountry = NULL; + memset(strLicenseType, 0x00, sizeof(strLicenseType)); + int nHasFeature = 0; + + if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && + g_IsRadarDevice == 0 && + g_IsToFDevice == 0 && + unlockingKeyInnoFR_success == 0) { + if (!IsExistingWeight(featureType, featureType2)) { + sprintf(strLicenseType, " Weight Error:"); + } + } + + if (g_match_mac == 1 || unlockingKeyInnoFR == 1) { + + if (g_IsHelm_without_car == 1) { + + } + else { + + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA)) + { +#ifdef GY_OS_NOVA + sprintf(strDatasetCategory, "%s", "EDGEFENCE (Home Security)");//01AI +#endif +#ifdef GY_OS_AMBA + sprintf(strDatasetCategory, "%s", "EDGEFLOW (Home Security)");//01AI +#endif + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) + { +#ifdef GY_OS_NOVA + sprintf(strDatasetCategory, "%s", "EDGEDENSITY (Flow Counter)");//03AI +#endif +#ifdef GY_OS_AMBA + sprintf(strDatasetCategory, "%s", "EDGECAP (Flow Counter)");//03AI +#endif + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + } + + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0){ + sprintf(strDatasetCategory, "%s", "EDGEGARBAGE (Garbage Recognition)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) + { + sprintf(strDatasetCategory, "%s", "EDGERAIL (Rail Security)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) + { + sprintf(strDatasetCategory, "%s", "EDGESPORTS (Sports Recognition)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) + { + sprintf(strDatasetCategory, "%s", "EDGEFIRE (Environment Safety)");//05AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) + { + sprintf(strDatasetCategory, "%s", "EDGEAERO (Aero Recognition)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + //printf("\nFEATURE_HUM_DET---6\n"); + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + { + sprintf(strDatasetCategory, "%s", "EDGESAFTY (Construction Site Safety)");//04AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + //printf("\nFEATURE_HUM_DET---7\n"); + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + sprintf(strDatasetCategory, "%s", "EDGEMASK (Health Care)");//02AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + else { + sprintf(strDatasetCategory, "%s", "EDGEGENDER (Human gender)");//02AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + sprintf(strDatasetCategory, "%s", "EDGEVESSEL (Vessel Recognition)");//08AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + + sprintf(strDatasetCategory, "%s", "EDGEPRODUCTION (Production Line)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + sprintf(strDatasetCategory, "%s", "EDGEANIMAL (Animal Recognition)");//09AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + else { + sprintf(strDatasetCategory, "%s", "EDGEFRONTBACK (Car Front & Back)");//09AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + } + + //printf("\nFEATURE_HUM_DET---8\n"); + if ((featureType & FEATURE_POK_DET) != 0) + { + sprintf(strDatasetCategory, "%s", "Poker pattern recognition"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_HUM_POS) != 0) + { + sprintf(strDatasetCategory, "%s", "Human pose estimator"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LED_DGT) != 0) + { + sprintf(strDatasetCategory, "%s", "LED digits recognition"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_SHOES_DET) != 0) + { + sprintf(strDatasetCategory, "%s", "Shoes recognition"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_LOGO) != 0) + { + sprintf(strDatasetCategory, "%s", "EDGECARMAKE (Car Make)");//07AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_TWN) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "TW/EC (Taiwan, Ecuador)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_EUR) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "EU (Belgium, Italy, Croatia, France, Turkey, Germany, Spain, Portugal, Slovenia)"; //European //EU/UK/IN + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_SEA) != 0 || + (featureType & FEATURE_LPR_VNM) != 0 || + (featureType & FEATURE_LPR_IDN) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "MY/HK/SG/VN/ID (Malaysia, Hong Kong, Singapore, Vietnam, Indonesia)";//South East Asia + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + /* + if ((featureType & FEATURE_LPR_CNA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "China"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + }*/ + if ((featureType & FEATURE_LPR_MEA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "AE/SA (UAE, Saudi Arabia)";//Middle East Asia + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_USA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "US/CA (50 states, Guam, Canada)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_AUS) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "AU (Australia)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_GBR) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "GB/IN (UK, India)"; //UK/IN //United Kingdom + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_JPN) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "JP (Japan)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + + if ((featureType & FEATURE_LPR_THA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "TH (Thailand)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + }/* + if ((featureType & FEATURE_LPR_LAO) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "Laos"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + }*/ + if ((featureType & FEATURE_LPR_BGD) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "BD (Bangladesh)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_PHL) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "PH (Philippines)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_LPR_CNT) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "CNT (Container)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (td_weight_num >= 1 && check_if_correct_mail == 1) { + char *strDatasetCategory = "Third Party"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (g_IsRadarDevice == 1) { + char *strDatasetCategory = "EDGERADAR (Radar Recognition)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (g_IsToFDevice == 1) + { + char *strDatasetCategory = "EDGETOF (ToF Recognition)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (unlockingKeyInnoFR_success == 1) { + char *strDatasetCategory = "EDGEFACE (Face Recognition)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + //printf("setting License Type : EDGEFACE (Face Recognition)\n"); + //printf("srtLicenseType = %s\n", strLicenseType); + + nHasFeature = 1; + } + + if (!nHasFeature) + { + char *strDatasetCategory = "No license"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + } + //printf("srtLicenseType = %s\n", strLicenseType); + //printf("featureType = %d\n", featureType); + //printf("featureType2 = %d\n", featureType2); + } + else{ + char *strDatasetCategory = "Mac address is not supported"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + } +} + +//void stop_detector() +//{ +// bHttpServerThreadStart = 0; +//} + +//20201027 sophia add +/* +command: +/usr/local/bin/nvclient -k user.password0 +/usr/local/bin/nvclient -k user.account0 +... +/usr/local/bin/nvclient -k user.password9 +/usr/local/bin/nvclient -k user.account9 + +return : +NVRAM Client, Version:1.0.0 +Get nvram data, ret:0 +Key=user.account0 +Data=admin +TStamp=172 +Max data size=32 +*/ + +//#if defined GY_OS_AMBA + +void get_image_dn() { + + { + if (imageDnData.color_mode == 1) { + imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; + imageDnData.current_day_or_night_mode = 1; + + for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { + imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; + } + if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { + imageDnData.check_if_switch_happened[0] = 1; + usSleep(2500000); + } + else { + imageDnData.check_if_switch_happened[0] = 0; + } + } + else if (imageDnData.color_mode == 2) { + imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; + imageDnData.current_day_or_night_mode = 2; + + for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { + imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; + } + if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { + imageDnData.check_if_switch_happened[0] = 1; + usSleep(2500000); + } + else { + imageDnData.check_if_switch_happened[0] = 0; + } + } + + //printf("\n-----------imageDnData.check_if_switch_happened[0]:%d\n", imageDnData.check_if_switch_happened[0]); + } +} + +int get_check_if_existing_any_switch_happened() { + int rtn = 0; + for (int i = 0; i < MAX_SIZE_SWITCH_HAPPENED; i++) { + if (imageDnData.check_if_switch_happened[i] == 1) { + rtn = 1; + break; + } + } + return rtn; +} + +//#endif + +//20201027 sophia add +void update_config_account_setting(void) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + + //post events setting + //char filename[] = "config.json"; + char* filename; + filename = configPATH; + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + } + else { + //printf("read config.json.\n"); + +#if 1 + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* root, *account_setting; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } +#if 1 + account_setting = cJSON_GetObjectItem(root, "account_setting"); + if (root) { + //printf("config.json parse OK.1\n"); + cJSON* account_data_array, *content; + cJSON* account_username, *account_password, *account_type, *account_status; + account_data_array = cJSON_CreateArray(); + +#if 1 + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) + { + content = cJSON_CreateObject(); + cJSON_AddItemToArray(account_data_array, content); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[i].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[i].account_password, (unsigned char *)buf_account2); + + account_username = cJSON_CreateString(buf_account); + cJSON_AddItemToObject(content, "account_username", account_username); + account_password = cJSON_CreateString(buf_account2); + cJSON_AddItemToObject(content, "account_password", account_password); + account_type = cJSON_CreateNumber(accountData[i].account_type); + cJSON_AddItemToObject(content, "account_type", account_type); + account_status = cJSON_CreateNumber(accountData[i].account_status); + cJSON_AddItemToObject(content, "account_status", account_status); + + } + usSleep(2000); + size_t base64_encode_length = 0; + unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + + char* AccountJsonString = cJSON_Print(account_data_array); + //printf("\n--------------AccountJsonString: %s\n", AccountJsonString); + + KeyExpansion(key, expandedKey); + size_t encryptSize = AESEncryptArrayToArray(AccountJsonString, strlen(AccountJsonString), expandedKey, EncryptKeyData, sizeof(EncryptKeyData)); + + char ResultEncryptData[MAX_ACCOUNT_DATA_BUFF_SIZE] = { 0 }; + base64_encode(EncryptKeyData, encryptSize, &base64_encode_length, ResultEncryptData); + *(ResultEncryptData + base64_encode_length) = '\0'; + + usSleep(2000); + + cJSON_ReplaceItemInObject(account_setting, "account_data", cJSON_CreateString((const char *)ResultEncryptData)); + + if (AccountJsonString) { + free(AccountJsonString); + AccountJsonString = NULL; + } + + //save back to config.json & bak + char* JsonString = cJSON_Print(root); + FILE* fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + //copy config.json to config_bak.json + CopyFileTo(filename, config_bakPATH); + } + else + { + //fclose(fp); + printf("Fail to open Config.json \n"); + } +#endif + if (root) { + //cJSON_Delete(root); + cJSON_Delete(root); + root = NULL; + } +#if 1 + + if (account_data_array != NULL) { + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) + { + cJSON_DeleteItemFromArray(account_data_array,i); + } + cJSON_free(account_data_array); + account_data_array = NULL; + } +#endif +#if 1 + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } +#endif + usSleep(2000); + } + else + printf("config.json parse FAIL.1\n"); +#endif + } +#endif + } +} + +void update_accountData() { + int count_username = 0; +#ifdef GY_OS_AMBA + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 4; i++) +#else + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 5; i++) +#endif + { + if (i == MAX_ACCOUNT_DATA_NUM) + count_username = 0; + + FILE *fp = NULL; + char path[1024] = { 0 }; + char command[1024] = { 0 }; + const char *find = "Data="; + int find_len = 5; + + memset(path, 0, sizeof(path)); + memset(command, 0, sizeof(command)); +#ifdef GY_OS_AMBA + if (i < MAX_ACCOUNT_DATA_NUM) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.account%d", i); + else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); + else if (i == MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.mirror"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.flip"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.rotate"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k FEATURE_SYS_DUAL_SENSOR"); +#else + if (i < MAX_ACCOUNT_DATA_NUM) + sprintf(command, "/usr/local/bin/nvclient -k user.account%d", i); + else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "/usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); + else if (i == MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "/usr/local/bin/nvclient -k image.mirror"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) + sprintf(command, "/usr/local/bin/nvclient -k image.flip"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) + sprintf(command, "/usr/local/bin/nvclient -k image.rotate"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) + sprintf(command, "/usr/local/bin/nvclient -k features.irled.type"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) + sprintf(command, "/usr/local/bin/nvclient -k features.irled2.type"); +#endif + + + +#ifdef _DEBUG_AMBA + printf("\n[read_ipcam_account_setting] i:%d - command:%s", i, command); +#endif + + /* Open the command for reading.*/ + fp = vpopen(command, "r"); + if (fp == NULL) { + fp = vpopen(command, "r"); + } + + if (fp == NULL) + { + + printf("\nFailed to run command: %s\n", command); + printf("Error opening file unexist.ent: %s\n", strerror(errno)); + + char fail_buffer[2048] = { 0 }; + sprintf(fail_buffer, "\nFailed to run command: %s\n", command); + write_to_log_if_error_nvclient(fail_buffer); + + //write_to_log_if_error(fail_buffer); + /* + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + }*/ + } + else { + /* Read the output a line at a time - output it.*/ + while (fgets(path, sizeof(path), fp) != NULL) + { + char *p = strstr(path, find); + int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n + //printf("\n(%d):cpylen:%d\n",i,cpy_len); + if (p != NULL && cpy_len >= 1) + { + char *cpy_start = p + find_len; + +#ifdef _DEBUG_AMBA + printf("\n%s strlen(path):%d", p + find_len, strlen(path)); +#endif + + if (cpy_len >= 1) { + char temp_cpy[100] = { 0 }; + strncpy(temp_cpy, cpy_start, cpy_len); + temp_cpy[cpy_len] = '\0'; + + if (i < MAX_ACCOUNT_DATA_NUM) { + if (strstr(temp_cpy, " ") == NULL) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account,512); + memcpy(accountData[count_username].account_username, temp_account, strlen(temp_account)); + accountData[count_username].account_username[strlen(temp_account)] = '\0'; + } + count_username++; + } + else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) { + if (strstr(temp_cpy, " ") == NULL) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account, 512); + memcpy(accountData[count_username].account_password, temp_account, strlen(temp_account)); + accountData[count_username].account_password[strlen(temp_account)] = '\0'; + } + count_username++; + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2) { + //if (g_IsPTZDevice == 0) + { + if (strstr(temp_cpy, " ") == NULL) { + strncpy(accountData[0].account_mirror, temp_cpy, cpy_len); + accountData[0].account_mirror[cpy_len] = '\0'; + } + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) { + //if (g_IsPTZDevice == 0) + { + if (strstr(temp_cpy, " ") == NULL) { + strncpy(accountData[0].account_flip, temp_cpy, cpy_len); + accountData[0].account_flip[cpy_len] = '\0'; + } + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) { + //if (g_IsPTZDevice == 0) + { + if (strstr(temp_cpy, " ") == NULL) { + strncpy(accountData[0].account_rotate, temp_cpy, cpy_len); + accountData[0].account_rotate[cpy_len] = '\0'; + } + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) { + //if (g_IsPTZDevice == 0) + if(strstr(temp_cpy,"1") != NULL) + { +#ifdef GY_OS_AMBA + g_dual_sensor = 1; +#else + g_camera_white_LED = 1; +#endif + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) { + //if (g_IsPTZDevice == 0) + if (strstr(temp_cpy, "1") != NULL) + { + g_camera_white_LED = 1; + } + } + } + + break; + } + + memset(path, 0, sizeof(path)); + } + if (fp != NULL) { + if (vpclose(fp) < 0) + printf("\nupdate accountData: vpclose fail\n"); + fp = NULL; + } + } + + usSleep(1000); + } +} + +void update_accountData_port() { + char read_port_cmd[1024]; + memset(&read_port_cmd, 0, sizeof(read_port_cmd)); + +#ifdef GY_OS_AMBA + char read_port_cmd_1[256] = "timeout 3s /usr/local/bin/nvclient -k http.port"; +#else + char read_port_cmd_1[256] = "/usr/local/bin/nvclient -k http.port"; +#endif + strcat(read_port_cmd, read_port_cmd_1); + + FILE *read_port = vpopen(read_port_cmd, "r"); + if (read_port == NULL) + { + printf("\n[read_ipcam_account_setting]:Error to read port"); + } + else + { + const char *find = "Data="; + int find_len = 5; + char path[1024] = { 0 }; + + /* Read the output a line at a time - output it.*/ + while (fgets(path, sizeof(path), read_port) != NULL) + { + char *p = strstr(path, find); + int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n + + if (p != NULL && cpy_len > 0) + { + char *cpy_start = p + find_len; + + if (cpy_len >= 1) { + strncpy(accountData[0].account_port, cpy_start, cpy_len); + accountData[0].account_port[cpy_len] = '\0'; + } + + //printf("\n[read_ipcam_account_setting]:Correct to read port %s\n",accountData[0].account_port); + break; + } + memset(path, 0, sizeof(path)); + } + if (read_port != NULL) + vpclose(read_port); + + } +} + +void accountData_written_to_events_json() { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char eventsPATH[1024] = { 0 }; + strcpy(eventsPATH, exePath); + + strcat(eventsPATH, "events.json"); + + char *filename_events; + filename_events = eventsPATH; + if (!FileExist(filename_events)) + { + printf("%s doesn't exist.\n", filename_events); + } + else { + //size_t nfileSize_events = ReadFileSize(filename_events); + char *fileBuf_events = ReadAllBytes(filename_events); + if (fileBuf_events) { + //printf("\n[read_ipcam_account_setting]\n"); + //printf("\nfileBuf_events: %s\n", fileBuf_events); + cJSON *root, *notification, *http_post_events, *http_post; + root = cJSON_Parse(fileBuf_events); + if (fileBuf_events) { + free(fileBuf_events); + fileBuf_events = NULL; + } + + if (root == NULL) + { + printf("root is NULL\n"); + + int del = remove(filename_events); + if (!del) { + //printf("events.json is deleted successfully."); + } + else { + printf("events.json cannot be deleted.\n"); + } +#if 1 + stop_test_nn_cavalry("events json not exist"); + //stop_server(); + +#endif + pthread_exit(NULL); + } + else + { + notification = cJSON_GetObjectItem(root, "notification"); + { + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + + int i = 0; + cJSON_ArrayForEach(http_post, http_post_events) + { + if (i <= 3) { + if (strlen(accountData[0].account_port) >= 1) + cJSON_ReplaceItemInObject(http_post, "post_host_port", cJSON_CreateString(accountData[0].account_port)); + if (strlen(accountData[0].account_username) >= 1) { + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + cJSON_ReplaceItemInObject(http_post, "post_username", cJSON_CreateString(buf_account)); + } + if (strlen(accountData[0].account_password) >= 1) { + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + cJSON_ReplaceItemInObject(http_post, "post_password", cJSON_CreateString(buf_account2)); + } + } + else + break; + + i++; + } + } + + char *filename = eventsPATH; + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open events.json \n"); + } + + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } +} + +static char events_port[512] = { 0 }; +static char events_username[512] = {0}; +static char events_password[512] = { 0 }; +void get_current_events_json_data() { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char eventsPATH[1024] = { 0 }; + char events_bakPATH[1024] = { 0 }; + + strcpy(eventsPATH, exePath); + strcat(eventsPATH, "events.json"); + + strcpy(events_bakPATH, exePath); + strcat(events_bakPATH, "events_bak.json"); + + char *filename_events; + filename_events = eventsPATH; + if (!FileExist(filename_events)) + { + printf("%s doesn't exist.\n", filename_events); + } + else { + //size_t nfileSize_events = ReadFileSize(filename_events); + char *fileBuf_events = ReadAllBytes(filename_events); + if (fileBuf_events) { + //printf("\n[read_ipcam_account_setting]\n"); + //printf("\nfileBuf_events: %s\n", fileBuf_events); + cJSON *root, *notification, *http_post_events, *http_post, *post_host_port, *post_username, *post_password; + root = cJSON_Parse(fileBuf_events); + if (fileBuf_events) { + free(fileBuf_events); + fileBuf_events = NULL; + } + + if (root == NULL) + { + printf("root is NULL\n"); + + int del = remove(filename_events); + if (!del) { + //printf("events.json is deleted successfully."); + } + else { + printf("events.json cannot be deleted.\n"); + } + + if (FileExist(events_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(events_bakPATH, eventsPATH); + } + else { +#if 1 + stop_test_nn_cavalry("events_bak json not exist"); + //stop_server(); +#endif + } + pthread_exit(NULL); + } + else + { + notification = cJSON_GetObjectItem(root, "notification"); + { + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + + int i = 0; + cJSON_ArrayForEach(http_post, http_post_events) + { + + post_host_port = cJSON_GetObjectItem(http_post, "post_host_port"); + post_username = cJSON_GetObjectItem(http_post, "post_username"); + post_password = cJSON_GetObjectItem(http_post, "post_password"); + + strcpy(events_port, post_host_port->valuestring); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(events_username, temp_account, strlen(temp_account)); + events_username[strlen(temp_account)] = '\0'; + + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(events_password, temp_account2, strlen(temp_account2)); + events_password[strlen(temp_account2)] = '\0'; + + //strcpy(events_username, post_username->valuestring); + //strcpy(events_password, post_password->valuestring); + + break; + i++; + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } +} + +/*void *run_osd_time_sync_thread() { + pthread_detach(pthread_self()); + setPthreadName("run_osd_time"); + //update_system_time(); + //int count_delay = 0; + int count_post = 0; + + while (bHttpServerThreadStart) + { + //if (count_delay >= 10) + { + //count_delay = 0; + //update_system_time(); + } + //else + { + //count_delay++; + g_osdSysTimeStamp++; + } + +#if 1 + if (count_post >= 14400) { + count_post = 0; + if (check_if_correct_post == 1) { + if (check_if_run_post == 1) { + + } + else if(check_if_run_post == 0){ + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "There is cloud post error existing for 4 hours. Reboot the camera to restart gynet."); + write_to_logs_html(temp_msg, "run osd time sync thread", "CGI_REBOOT", "Yes"); + //printf("\n-----------------------There is no post for 4 hours.: exit-----------------------\n"); + write_to_log_if_error(temp_msg, "run osd time sync thread", "CGI_REBOOT"); + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + } + else { + if (check_if_run_post != 0) { + count_post = 0; + } + + count_post++; + } +#endif + + usSleep(1000000); + } + + pthread_exit(NULL); +}*/ +#ifdef GY_OS_AMBA +#define SHELLSCRIPT "sh /emmc/plugin/Aida_data/run_osd_server.sh" +#define SHELLSCRIPT_TOF_DRIVER "sh /emmc/plugin/Aida_data/run_tof_driver.sh" + + +void *run_osd_server_thread(void* ptr) { + pthread_detach(pthread_self()); + setPthreadName("osd_server"); + if (strcmp(SystemSetting.enable_display_OSD, "Yes")==0 /*&& strcmp(SystemSetting.enable_cloud,"Yes")==0*/) { + pthread_t auto_system_thread_id; + if (pthread_create(&auto_system_thread_id, 0, auto_system, NULL)) + { + printf("\ncreate auto system thread faile \n"); + } + pthread_join(auto_system_thread_id, NULL); + //usSleep(2000000); + + g_check_if_OK_to_start_osd_server = 1; + + pthread_mutex_lock(&mutex_run_osd); + close_udp_socket(); + init_udp_socket(); + pthread_mutex_unlock(&mutex_run_osd); + + usSleep(2000000); + char cmd_1[256] = "killall -15 osd_server"; + + FILE *read_port = vpopen(cmd_1, "r"); + if (read_port != NULL) + vpclose(read_port); + + usSleep(2000000); + + g_check_if_OK_to_start_osd_server = 0; +#if 1 + system(SHELLSCRIPT); +#endif + +#if 0 + char cmd_2[256] = "/emmc/plugin/Aida_data/osd_server server"; + + read_port = vpopen(cmd_2, "r"); + if (read_port != NULL) + vpclose(read_port); +#endif + usSleep(2000000); + } + else{ + g_check_if_OK_to_start_osd_server = 1; + close_udp_socket(); + + usSleep(2000000); + + char cmd_2[256] = "killall -15 osd_server"; + FILE *read_port = vpopen(cmd_2, "r"); + if (read_port != NULL) + vpclose(read_port); + + usSleep(2000000); + g_check_if_OK_to_start_osd_server = 0; + } + + pthread_exit(NULL); +} +#endif +struct timeval currtime_read_ipcam_account_setting_thread; +static long last_ms_currtime_read_ipcam_account_setting_thread = 0; +void *read_ipcam_account_setting_thread(void* ptr) { + pthread_detach(pthread_self()); + setPthreadName("read_ipcam"); + + //printf("\n----------read ipcam account setting thread start\n"); + + gettimeofday(&currtime_read_ipcam_account_setting_thread, NULL); + long current_ms_currtime_read_ipcam_account_setting_thread = (currtime_read_ipcam_account_setting_thread.tv_sec * 1000) + (currtime_read_ipcam_account_setting_thread.tv_usec / 1000); + + + if (last_ms_currtime_read_ipcam_account_setting_thread == 0 || current_ms_currtime_read_ipcam_account_setting_thread - last_ms_currtime_read_ipcam_account_setting_thread >= 5000) { + + if (g_control_read_ipcam == 0) { + + pthread_mutex_lock(&mutex_read_ipcam); + g_control_read_ipcam = 1; + + get_current_events_json_data(); + + /*while (bHttpServerThreadStart)*/ { + read_ipcam_account_setting(); + //usSleep(READ_IPCAM_SETTING*1000); + } + + + int get_OK = 0; + char temp_device_name[512] = { 0 }; + get_OK = PNS_Get_Device_Name(1, temp_device_name); + //int len_device = 0; + if (get_OK >= 1) { + url_decode(temp_device_name,strlen(temp_device_name)); + strcpy(g_device_name, temp_device_name); + } + g_control_read_ipcam = 0; + pthread_mutex_unlock(&mutex_read_ipcam); + + } + + last_ms_currtime_read_ipcam_account_setting_thread = current_ms_currtime_read_ipcam_account_setting_thread; + } + + //printf("\n----------read ipcam account setting thread end\n"); + + pthread_exit(NULL); +} + +int g_start_update_config = 0; +void read_ipcam_account_setting() +{ + + update_accountData(); + update_accountData_port(); + + if (g_start_update_config == 0) { + update_config_account_setting(); + g_start_update_config = 1; + } + if (strlen(accountData[0].account_port) >= 1 && strlen(accountData[0].account_username) >= 1 && + strlen(events_port) >= 1 && strlen(events_username) >= 1) + { + if (strcmp(accountData[0].account_port, events_port) != 0 || + strcmp(accountData[0].account_username, events_username) != 0 || + strcmp(accountData[0].account_password, events_password) != 0) + { + if (g_start_update_config == 1) { + update_config_account_setting(); + } + accountData_written_to_events_json(); + for (int i = 0; i < 4; i++) { + strcpy(postEventList[i].post_host_port, accountData[0].account_port); + strcpy(postEventList[i].post_username, accountData[0].account_username); + strcpy(postEventList[i].post_password, accountData[0].account_password); + } + get_current_events_json_data(); + } + } +#if 0 + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\naccountData[0].account_mirror: %s\n", accountData[0].account_mirror); + printf("\naccountData[0].account_flip: %s\n", accountData[0].account_flip); + printf("\naccountData[0].account_rotate: %s\n", accountData[0].account_rotate); + printf("\naccountData[0].account_port: %s\n", accountData[0].account_port); + printf("\naccountData[0].account_username: %s\n", accountData[0].account_username); + printf("\naccountData[0].account_password: %s\n", accountData[0].account_password); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); +#endif +} + +int external_memory_fragmentation_management() { + + FILE * pPipe = NULL; + char cmd[256] = { 0 }; + int size_psBuffer = 256; + char psBuffer[256] = { 0 }; + + int chunk_number = -1; + + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s echo 1 > /proc/sys/vm/compact_memory"); +#else + sprintf(cmd, "echo 1 > /proc/sys/vm/compact_memory"); +#endif + + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) + { + + } + else { + printf("\nFail: external memory fragmentation management #1\n"); + } + if (pPipe != NULL) + vpclose(pPipe); + + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); +#else + sprintf(cmd, "cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); +#endif + + + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) + { + //printf("Run: external memory fragmetation\n"); + char* temp; + memset(psBuffer, 0x00, sizeof(psBuffer)); + temp = fgets(psBuffer, size_psBuffer, pPipe); + if (temp != NULL) { + chunk_number = atoi(psBuffer); + printf("\n[buddyinfo] chunk_number:%d\n", chunk_number); + } + } + else { + printf("\nFail: external memory fragmentation management #2\n"); + } + if (pPipe != NULL) + vpclose(pPipe); + + return chunk_number; +} + +// 2020.11.23 Sophia added. +// 2021.05.12 Cayman modified returned values. +extern char* strptime_c(const char* buf, const char* fmt, struct tm* tm); +int reload_dataset_from_jsonfile(void) +{ + time_t start_time = 0; + time_t now_time = 0; + now_time = (time_t)time(0); + + struct tm *localnowTime = localtime(&now_time); + int diffSecs = 0; + if (cgi_whenTime_buff != NULL && cgi_startTime_buff != NULL) { + memcpy(cgi_whenTime_buff, localnowTime, sizeof(struct tm)); + diffSecs = cgi_whenTime_buff->tm_sec - cgi_startTime_buff->tm_sec; + } + + if (abs(diffSecs) < 2) + return 1; + + start_time = time(0); + cgi_reload_start_Time = localtime(&start_time); + + if (cgi_startTime_buff != NULL) { + memcpy(cgi_startTime_buff, cgi_reload_start_Time, sizeof(struct tm)); + } + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename_event; + filename_event = eventsPATH; + + if (!FileExist(filename_event)) + { + printf("%s doesn't exist.\n", filename_event); + return 1; + } + size_t nfileSize_event = ReadFileSize(filename_event); + printf("nfileSize_event:%ld\n", (long int)nfileSize_event); + char *fileBuf_event = ReadAllBytes(filename_event); + if (fileBuf_event == NULL) { + printf("fileBuf_event is NULL\n"); + return 1; + } + + cJSON /* *n_root,*/ *notification, *events_default_version,*enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, + *post_customized_header; + cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr,*enable_check_ptz_start_autotracking, + *enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + //n_root = cJSON_Parse(fileBuf_event); + cJSON *root; + root = cJSON_Parse(fileBuf_event); + if (fileBuf_event) { + free(fileBuf_event); + fileBuf_event = NULL; + } + + if (root == NULL) + { + printf("root is NULL\n"); + return 1; + } + notification = cJSON_GetObjectItem(root, "notification"); + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + + if (events_default_version) { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + } + else { + strcpy(heartbeatData.events_default_version, "1"); + } + + if (enable_post) + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + else + activeSNMPPost = _FALSE; + if (enable_heartbeat) { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + } + else { + strcpy(heartbeatData.enable_heartbeat, "No"); + } + + if (enable_snmp_heartbeat) { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + } + else { + strcpy(heartbeatData.enable_snmp_heartbeat, "No"); + } + + if (snmp_heartbeat_dwell) { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + } + else { + strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); + } + + if (snmp_heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); + } + + if (enable_check_ptz_start_autotracking) { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + } + else { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); + } + + if (enable_check_ptz_end_autotracking) { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + } + else { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); + } + + if (enable_only_once_to_post) { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + } + else { + strcpy(heartbeatData.enable_only_once_to_post, "Yes"); + } + + if (enable_obj_once_to_post) { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + } + else { + strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); + } + + if (enable_location_once_to_post) { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + } + else { + strcpy(heartbeatData.enable_location_once_to_post, "Yes"); + } + + if (enable_nvr_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + } + else { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); + } + + if (enable_8592_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + } + else { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); + } + + if (dwell_to_the_same_location) { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + } + else { + strcpy(heartbeatData.dwell_to_the_same_location, "5"); + } + + if (heartbeat_dwell) { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + } + else { + strcpy(heartbeatData.heartbeat_dwell, "10"); + } + + if (heatmap_max) { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + } + else { + strcpy(heartbeatData.heatmap_max, "100"); + } + + if (enable_heatmap) { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + } + else { + strcpy(heartbeatData.enable_heatmap, "No"); + } + + if (heatmap_frequency) { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + } + else { + strcpy(heartbeatData.heatmap_frequency, "5"); + } + + if (lpr_title) { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + } + else { + strcpy(heartbeatData.lpr_title, "My Car Park"); + } + + if (heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); + } + + if (ptz_start_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); + } + + if (ptz_end_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); + } + + if (enable_counter_snap) { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + } + else { + strcpy(heartbeatData.enable_counter_snap, "No"); + } + + if (enable_barcode_qr) { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + } + else { + strcpy(heartbeatData.enable_barcode_qr, "No"); + } + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + strcpy(postEventList[i].post_protocol, post_protocol->valuestring); + strcpy(postEventList[i].post_event_method, post_event_method->valuestring); + strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); + strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); + strcpy(postEventList[i].post_host_port, post_host_port->valuestring); + strcpy(postEventList[i].post_url, post_url->valuestring); + //strcpy(postEventList[i].post_username, post_username->valuestring); + //strcpy(postEventList[i].post_password, post_password->valuestring); + strcpy(postEventList[i].post_content, post_content->valuestring); + strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); + + if (post_sequence) + strcpy(postEventList[i].post_sequence, post_sequence->valuestring); + else { + strcpy(postEventList[i].post_sequence, ""); + } + + if (post_timeout) + strcpy(postEventList[i].post_timeout, post_timeout->valuestring); + else { + strcpy(postEventList[i].post_timeout, "5"); + } + + if(post_file_format) + strcpy(postEventList[i].post_file_format, post_file_format->valuestring); + else { + strcpy(postEventList[i].post_file_format, "text"); + } + + if(post_jpeg_file_name_format) + strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); + } + + if(post_jpeg_file_name) + strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name, "snap"); + } + i++; + } + +#ifdef GY_OS_V_SERIES + cJSON *counter_name; +#else + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; + cJSON *link_to_post_event_name, *post_interval; + + event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + + i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + strcpy(eventCounterList[i].counter_name, counter_name->valuestring); + strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); + strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); + + if (reset_value) + eventCounterList[i].reset_value = atoi(reset_value->valuestring); + else + eventCounterList[i].reset_value = 0; + strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_at, reset_at->valuestring); + strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); + strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); + strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); + struct tm tm; + strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); +#if 0 + eventCounterList[i].timetResetAt = mktime(&tm); + + struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); + eventCounterList[i].reset_month = resetTime->tm_mon; + eventCounterList[i].reset_month_day = resetTime->tm_mday; + eventCounterList[i].reset_week_day = resetTime->tm_wday; + eventCounterList[i].reset_hour = resetTime->tm_hour; + eventCounterList[i].reset_min = resetTime->tm_min; + eventCounterList[i].reset_sec = resetTime->tm_sec; +#endif + strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeFrom = mktime(&tm); + strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeTo = mktime(&tm); + + if (link_to_post_event_name) { + strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); + } + else { + strcpy(eventCounterList[i].link_to_post_event_name, ""); + } + + if (post_interval) { + strcpy(eventCounterList[i].post_interval, post_interval->valuestring); + } + else { + strcpy(eventCounterList[i].post_interval, "5 minutes"); + } + + if (enable_reset_only_cloud) { + strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + } + else { + strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); + } + + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + } + else { + strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); + } + + i++; + } + + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, + *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + if (report_counters) { + i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + if (counter_a) { + strcpy(reportCounterList[i].counter_a, counter_a->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a, "Counter01"); + } + + if (counter_a_name) { + strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_name, "Name"); + } + + if (counter_a_zone) { + strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_zone, "1"); + } + + if (counter_b) { + strcpy(reportCounterList[i].counter_b, counter_b->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b, ""); + } + + if (counter_b_name) { + strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_name, ""); + } + + if (counter_b_zone) { + strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_zone, "0"); + } + + if (counter_c_name) { + strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_c_name, ""); + } + + if (report_max_value) { + strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); + } + else { + strcpy(reportCounterList[i].report_max_value, "100"); + } + + if (enable_report) { + strcpy(reportCounterList[i].enable_report, enable_report->valuestring); + } + else { + strcpy(reportCounterList[i].enable_report, "No"); + } + + if (counter_mode) { + strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); + } + else { + strcpy(reportCounterList[i].counter_mode, "0"); + } + + if (initial_icon) { + strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); + } + else { + strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); + } + + if (detection_output) { + strcpy(reportCounterList[i].detection_output, detection_output->valuestring); + } + else { + strcpy(reportCounterList[i].detection_output, "No entry for cars"); + } + + if (output_icon) { + strcpy(reportCounterList[i].output_icon, output_icon->valuestring); + } + else { + strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); + } + + i++; + } + } + + if (i < MAX_REPORT_COUNTERS) { + for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + } + } + else { + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + } + + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + if (snmp_management) { + i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + if (snmp_event_name) { + strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); + } + else { + char temp_name[20] = { 0 }; + sprintf(temp_name,"SNMP %d",i+1); + strcpy(SNMPManagementList[i].snmp_event_name, temp_name); + } + + if (snmp_version) { + strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_version, "v1"); + } + + if (snmp_group_name) { + strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_group_name, "public"); + } + + if (snmp_host_ip) { + strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); + } + + if (snmp_host_port) { + strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_port, "161"); + } + + if (snmp_oid) { + strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + } + + if (snmp_value) { + strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_value, "mylocation"); + } + + if (snmp_type) { + strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_type, "string"); + } + + i++; + } + } + + if (i < MAX_SNMP_MANAGEMENT) { + for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + } + } + } + else { + for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + } + } +#endif + + +#if 0 + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } +#endif + + cJSON *email_setting,*email_content; + email_setting = cJSON_GetObjectItem(root, "email_setting"); + if (email_setting) { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) + strcpy(emailData.email_content, email_content->valuestring); + else + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + else { + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + + //trigger events settings + char *filename_config; + filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + return 1; + } + + size_t nfileSize_config = ReadFileSize(filename_config); + printf("nfileSize_config:%ld\n", (long int)nfileSize_config); + char *fileBuf_config = ReadAllBytes(filename_config); + + if (fileBuf_config == NULL) { + printf("fileBuf_config is NULL\n"); + return 1; + } + + //cJSON* cam_ip, * http_port, * video_port, * cam_username, * cam_pwd, * channel_id; + cJSON* view_setting, * camera, * camera_name, * enable_anpr, *enable_face, * enable_traffic, * enable_logo, * tab_view_size, * enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, + *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking, *ptz_tracking_mode, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, + *cJSON_enable_only_show_metadata1,*count_zone, *ivs_mode, * detection_zone, * detect, + *levenshtein_distance, *obj_min_proportion, *obj_max_proportion,*min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, + *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute,*queuing_count, *ptz_zone_to_preset,*trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, + *point_number, + *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6, + *enable_speed,*set_distance,*world_distance_unit,*world_distance_side1,*world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, + *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion,*confidence_unknown_object, *confidence2_unknown_object,*dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, + *plate_filter_times,*plate_filter_time,*plate_free_time,*obj_max_proportion_in_zone,*obj_min_proportion_in_zone,*red_light_zone,*no_give_way_zone_to_protect,*no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2, + *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed; + + //cJSON* root = cJSON_Parse(fileBuf_config); + //printf("\n-----------------reload: %s\n", fileBuf_config); + + if (g_config_root == NULL) { + g_config_root = cJSON_Parse(fileBuf_config); + if (fileBuf_config) { + free(fileBuf_config); + fileBuf_config = NULL; + } + if (g_config_root == NULL) + { + printf("root is NULL\n"); + return 1; + } + } + view_setting = cJSON_GetObjectItem(g_config_root, "view_setting"); + + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + /*cam_ip = cJSON_GetObjectItem(camera, "ip"); + http_port = cJSON_GetObjectItem(camera, "http_port"); + video_port = cJSON_GetObjectItem(camera, "video_port"); + cam_username = cJSON_GetObjectItem(camera, "username"); + cam_pwd = cJSON_GetObjectItem(camera, "password"); + channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + + plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); + plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); + plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); + + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); //None SΨ + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); //None SΨ + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + + if (plate_filter_times) + viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); + else + viewChannelData[n].i_plate_filter_times = 4; + + if (plate_filter_time) + viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); + else + viewChannelData[n].i_plate_filter_time = 3; + + if (plate_free_time) + viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); + else + viewChannelData[n].i_plate_free_time = 3; + + strcpy(viewChannelData[n].confidence, confidence->valuestring); + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + //printf("\nenable_lpr_db-----6\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + pthread_mutex_unlock(&mutex_enable_lpr_db); + + enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); + set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); + + enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); + set_enable_zone_crop_1(enable_zone_crop_1->valueint); + + viewChannelData[n].count_zone = count_zone->valueint; + + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + //printf("\n[reload_dataset_from_jsonfile]tab_view_size: %s\n", tab_view_size->valuestring); + + char temp_array[256] = { 0 }; + strcpy(temp_array, tab_view_size->valuestring); + + char outArray[2][STRSPLIT_SIZE] = {0}; + StrSplit(temp_array, outArray, "x"); + //printf("\n------UU:15\n"); + viewChannelData[n].channel_idx = n; + if (outArray[0]) + viewChannelData[n].tab_view_width = atoi(outArray[0]); + if (outArray[1]) + viewChannelData[n].tab_view_height = atoi(outArray[1]); + + //printf("\n[reload_dataset_from_jsonfile]end:tab_view_size: %s\n", tab_view_size->valuestring); + + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + if (strcmp(enable_face->valuestring, "Yes") == 0) + viewChannelData[n].enable_face = 1; + else + viewChannelData[n].enable_face = 0; + + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + + enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); + if (enable_add_face_frequent_list) + if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) + viewChannelData[n].enable_add_face_frequent_list = 1; + else + viewChannelData[n].enable_add_face_frequent_list = 0; + else { + viewChannelData[n].enable_add_face_frequent_list = 0; + } + + enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); + strcpy(viewChannelData[n].enable_PTZ ,enable_PTZ->valuestring); + + ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); + strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); + + ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); + strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); + + ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); + strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); + + //Tracking MODE + //1: First in First out + //2: Bigger first + //3: All + ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); + if (ptz_tracking_mode) + viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); + else + { + viewChannelData[n].ptz_tracking_mode = 1; + } + + ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); + if (ptz_tracking_by_enter_zone) { + if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + else + viewChannelData[n].ptz_tracking_by_enter_zone = 0; + } + else { + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + } + + enable_track = cJSON_GetObjectItem(camera, "enable_track"); + if (enable_track) + strcpy(viewChannelData[n].enable_track, enable_track->valuestring); + else { + strcpy(viewChannelData[n].enable_track, "No"); + } + + enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); + if (enable_tracking_limits) + strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); + else { + strcpy(viewChannelData[n].enable_tracking_limits, "No"); + } + + ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); + if (ptz_pan_left_limit) + strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); + } + + ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); + if (ptz_pan_right_limit) + strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); + } + + ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); + if (ptz_tilt_up_limit) + strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); + } + + ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); + if (ptz_tilt_down_limit) + strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); + } + + ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); + if (ptz_speed) + strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); + else { + strcpy(viewChannelData[n].ptz_speed, "3"); + } + + enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); + if (enable_unknown_object) + strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_unknown_object, "No"); + } + + enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); + if (enable_ivs_person_detection) + strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); + } + + assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); + if (assign_ivs_object_to) + strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); + else { + strcpy(viewChannelData[n].assign_ivs_object_to, ""); + } + + enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); + if (enable_ambulance) + strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); + else { + strcpy(viewChannelData[n].enable_ambulance, "No"); + } + + enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); + if (enable_blank_plate) + strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); + else { + strcpy(viewChannelData[n].enable_blank_plate, "No"); + } + + enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); + if (enable_stop_sign) + strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); + else { + strcpy(viewChannelData[n].enable_stop_sign, "No"); + } + + enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); + if (enable_show_unknown_object) + strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_show_unknown_object, "No"); + } + + enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); + if (enable_ivs_fix_mode) + strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); + } + + enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); + if (enable_ivs_and_ai) + strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); + } + + enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); + if (enable_lpr_upon_triggered) + strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); + } + + dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); + if (dwell_lpr_upon_triggered) + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); + } + + unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); + if(unknown_object_max_proportion) + strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); + else + strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); + + unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); + if (unknown_object_min_proportion) + strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); + else + strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); + + confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); + if (confidence_unknown_object) + strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); + else + strcpy(viewChannelData[n].confidence_unknown_object, "0"); + + confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); + if (confidence2_unknown_object) + strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); + else + strcpy(viewChannelData[n].confidence2_unknown_object, "0"); + + dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); + if(dwell_unknown_object) + strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); + else + strcpy(viewChannelData[n].dwell_unknown_object, "30"); + + dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); + if (dwell_minute_focus_on) + strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); + else + strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); + + + person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); + if (person_obj_fov) + strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); + else + strcpy(viewChannelData[n].person_obj_fov, "100"); + + + ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); + if (ivs_mode) + strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); + else + strcpy(viewChannelData[n].ivs_mode, "3"); + + getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); + if (getnetwork_buffer_id) { + if (strlen(viewChannelData[n].getnetwork_buffer_id)>=1 && strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) { +#ifdef GY_OS_AMBA + printf("\n-----------------------get network buffer id: exit-----------------------\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); + write_to_logs_html(temp_msg, "reload dataset", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "reload dataset", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } +#else + +#endif + } + } + else + strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); + + red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); + if (red_light_zone) + strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); + else + strcpy(viewChannelData[n].red_light_zone, ""); + + no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); + if (no_give_way_zone_to_protect) + strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); + + no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); + if (no_give_way_zone_to_keep_away) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); + + no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); + if (no_give_way_zone_to_protect_2) + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); + + no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); + if (no_give_way_zone_to_keep_away_2) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); + + ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); + if (ptz_sensitivity) + viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); + else + { + viewChannelData[n].ptz_sensitivity = 6; + } + //printf("\n-------------ptz_sensitivity:%d\n", viewChannelData[n].ptz_sensitivity); + + ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); + + cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); + enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; + + detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + + viewChannelData[n].enable_traffic_light_zone = 0; + + int i = 0; + cJSON_ArrayForEach(detect, detection_zone) + { + obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); + obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); + + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + + enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); + enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); + enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); + world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); + + ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); + + trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); + + point_number = cJSON_GetObjectItem(detect, "point_number"); + + parking_space = cJSON_GetObjectItem(detect, "parking_space"); + parking_line = cJSON_GetObjectItem(detect, "parking_line"); + + //Social Distance + set_distance = cJSON_GetObjectItem(detect, "set_distance"); + world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); + world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); + world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); + //Social Distance + + /* + if(point_number) + printf("load point number = %d \n", point_number->valueint); +*/ + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + if(metadata_stop) + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + if (no_parking_time) + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + if (no_parking_time_in_minute) + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + if (queuing_count) + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + + if (parking_space) + { + viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); + } + + if (parking_line) + { + viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); + } + + //Social Distance + if (set_distance) + { + viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); + } + + if (world_distance_unit) + { + strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); + } + if (world_distance_side1) + { + viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); + viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); + } + + + //Fake data + //viewDetectionZone[n][i].world_distance[0] = 1000; + //viewDetectionZone[n][i].world_distance[2] = 1000; + + if (world_distance_side2) + { + viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); + viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); + } + //Social Distance + if(obj_max_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); + if(obj_min_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); + + if (point_number) + { + viewDetectionZone[n][i].point_num = point_number->valueint; + } + + if (enable_speed) + strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); + if (enable_radar_speed) + strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); + if (enable_ivs_zone) + strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); + if (world_time_unit) + strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); + + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].Points[3].y = y4->valueint; + + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + + if (x5 && x6) + { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].Points[5].y = y6->valueint; + + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + } + + + viewChannelData[n].tab_view_width_ratio = (float)1; + viewChannelData[n].tab_view_height_ratio = (float)1; + + viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); + viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); + + //viewChannelData[n].tab_view_height = 1; + + + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; + //UpdateTrafficLightZone(n); + } + +#ifdef GY_OS_AMBA + if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) + { + int social_zone_idx = i; + if (social_zone_idx >= 0) + { + pthread_mutex_lock(&mutex_perspective_transform); + if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); + viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); + pthread_mutex_unlock(&mutex_perspective_transform); + } + } +#endif + + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + //int arraySize = cJSON_GetArraySize(detection_zone); + int k = 0; + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + k = 0; + cJSON_ArrayForEach(detect, trigger_events[j]) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + } + } + + cJSON *system_setting,*enable_cloud,*enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*nms_thres, *tracking_id_dwell,*enable_person_independent,*enable_onvif_profile_m, *enable_crop_mode,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language,*display_properties,*display_OSD, + *enable_bounding_box,*enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror,*ai_mirror_feature,*enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content,*enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, + *enable_email_notification,*email_reset_time_interval,*enable_system_logs,*enable_email_jpeg, *send_counter_at_specific_hour,*display_dash,*sensors_type,*enable_ftp,*ftp_url,*ftp_port,*ftp_username,*ftp_password,*ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; + cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; + + system_setting = cJSON_GetObjectItem(g_config_root, "system_setting"); + + enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); + strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); + + enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); + strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); + + enable_crop_mode = cJSON_GetObjectItem(system_setting, "enable_crop_mode"); + strcpy(SystemSetting.enable_crop_mode, enable_crop_mode->valuestring); + + nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); + strcpy(SystemSetting.nms_thres, nms_thres->valuestring); + + tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); + strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); + + enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); + strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); + + enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); + strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); + + enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); + strcpy(SystemSetting.enable_python, enable_python->valuestring); + + enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); + strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); + + cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); + strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); + + cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); + strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); + + cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); + strcpy(SystemSetting.cloud_account, cloud_account->valuestring); + + cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); + strcpy(SystemSetting.cloud_password, cloud_password->valuestring); + + cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); + strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); + + cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); + strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); + + cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); + strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); + + cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); + strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); + + language = cJSON_GetObjectItem(system_setting, "language"); + strcpy(SystemSetting.language, language->valuestring); + + display_dash = cJSON_GetObjectItem(system_setting, "display dash"); + activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + + display_properties = cJSON_GetObjectItem(system_setting, "display properties"); + strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); + + display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); + strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); + + enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); + strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); + + enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); + strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); + + enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); + strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); + + force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); + strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); + + force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); + strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); + + enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); + strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); + + enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); + strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); + + ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); + strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); + + enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); + strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); + + cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); + strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); + + cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); + strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); + + enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); + strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); + + cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); + strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); + + cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); + strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); + + enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); + strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); + + enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); + strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); + + getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); + strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); + + getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); + strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); + + osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); + strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); + + osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); + strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); + + osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); + strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); + + enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); + strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); + + osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); + strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); + + osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); + strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); + + sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); + strcpy(SystemSetting.sensors_type, sensors_type->valuestring); + + enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); + strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); + + external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); + strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); + + external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); + strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); + + external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); + strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); + + external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); + strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); + + enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); + strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); + + enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); + strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); + + enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); + strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); + + send_counter_at_specific_hour = cJSON_GetObjectItem(system_setting, "send_counter_at_specific_hour"); + strcpy(SystemSetting.send_counter_at_specific_hour, send_counter_at_specific_hour->valuestring); + + email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); + strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); + + enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); + strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); + + ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); + strcpy(SystemSetting.ftp_url, ftp_url->valuestring); + + ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); + strcpy(SystemSetting.ftp_port, ftp_port->valuestring); + + ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); + strcpy(SystemSetting.ftp_username, ftp_username->valuestring); + + ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); + strcpy(SystemSetting.ftp_password, ftp_password->valuestring); + + ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); + strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); + + ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); + strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); + + ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); + strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); + + cJSON *about_box,*cJSON_strUnlockingKey; + about_box = cJSON_GetObjectItem(g_config_root, "about_box"); + if (about_box) { + cJSON_strUnlockingKey = cJSON_GetObjectItem(about_box, "unlocking key"); + if (cJSON_strUnlockingKey && strlen(cJSON_strUnlockingKey->valuestring)>=1 && strcmp(strUnlockingKey, cJSON_strUnlockingKey->valuestring)!=0) { + memset(strUnlockingKey,0x00,sizeof(strUnlockingKey)); + strcpy(strUnlockingKey, cJSON_strUnlockingKey->valuestring); + + char buf_exe[1024] = {}; + readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); + + char exePath_temp[1024] = {}; + getFilePath(buf_exe, exePath_temp, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath_temp); + strcat(keyPATH, "key.txt"); + if (FileExist(keyPATH) == 1) { + FILE *pFile; + + if ((pFile = fopen(keyPATH, "w")) != NULL) + { + fprintf(pFile, strUnlockingKey); + fclose(pFile); + + } + else + printf("Fail to open key.txt \n"); + } + + memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); + strcpy(strLicenseStatus, "Please restart gynet to run AI with new key."); + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + + if (g_config_root) { + cJSON_Delete(g_config_root); + g_config_root = NULL; + } +#ifdef GY_OS_AMBA + /*int zone_to_preset[MAX_DETECTION_ZONE]; + + for (int i = 0; i < MAX_DETECTION_ZONE; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, + viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + if (g_IsPTZDevice == 1) { + UpdatePTZConfigSetting(); + + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + } + +#endif + //Reload cold zone + /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); + +#ifdef GY_OS_AMBA + if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { + if (enable_ai_mirror && ai_mirror_feature) { + if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { + + if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 2"); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + else { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 0"); +#endif + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + } + } + } +#endif + + return 0; +} + +// 2021.01.21 Jim added. +// 2021.05.12 Cayman fixed returned values. +#if 0 +int default_dataset_for_jsonfile(void) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + + + char *filename; + //filename = config_bakPATH; + filename = configPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return 1; + } + + //printf("read config.json. %s\n", filename); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) { + printf("fileBuf FAIL.\n"); + return 1; + } + + cJSON *root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (root) { + //printf("config.json parse OK.\n"); + } + else + { + printf("config.json parse FAIL.\n"); + return 1; + } + + cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(filename, config_bakPATH); + } + else + { + printf("Fail to open Config.json \n"); + return 1; + } + + //copy config.json to config_bak.json + + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + return 0; +} +#endif //GY_OS_AMBA + + +#ifdef GY_OS_AMBA +static long delete_now_heatmap = 0; +struct timeval delete_currtime_heatmap; +void delete_heatmap_image() { + gettimeofday(&delete_currtime_heatmap, NULL); + delete_now_heatmap = (delete_currtime_heatmap.tv_sec * 1000) + (delete_currtime_heatmap.tv_usec / 1000); //쬰@ + delete_now_heatmap = delete_now_heatmap / 1000 * 1000; + + pthread_mutex_lock(&mutex_heatmap_jpeg); + DIR *d_file; + struct dirent *dir_file; + d_file = opendir("/emmc/plugin/Aida_data/playback"); + if (d_file) { + while ((dir_file = readdir(d_file)) != NULL) { + if (strlen(dir_file->d_name) >= 17) { + char temp_d_name[50] = { 0 }; + for (int i = 0; i < strlen(dir_file->d_name)-4; i++) { + temp_d_name[i] = dir_file->d_name[i]; + } + + if (atol(temp_d_name) <= delete_now_heatmap - 15 * 24 * 60 * 60 * 1000 / 2) {//15/2=7.5 + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + //usSleep(10000); + + //printf("\n-------temp_d_name:%ld\n", atol(temp_d_name)); + } + } + closedir(d_file); + } + pthread_mutex_unlock(&mutex_heatmap_jpeg); + + //printf("\n-------delete_now_heatmap:%ld\n", delete_now_heatmap); +} +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void * delete_jpg_in_seven_days_detector(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("delete_seven"); + int check_delete = 0; + int delete_time = 1; + int delete_time2 = 7; + int delete_time3 = 13; + int delete_time4 = 19; + + delete_jpg_in_seven_days(); +#ifdef GY_OS_AMBA + delete_heatmap_image(); +#endif + + while (bHttpServerThreadStart) { + + //printf("\n------delete jpg in seven days detector start\n"); + + if (iFeature_lpr_layer_index >= 0) { + + time_t rawtime = time(0); + struct tm * timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + + if ((timeinfo->tm_hour == delete_time || + timeinfo->tm_hour == delete_time2 || + timeinfo->tm_hour == delete_time3 || + timeinfo->tm_hour == delete_time4) + && check_delete == 0) { + if (unlockingKeyInnoFR == 1) { +#ifdef GY_OS_AMBA + //delete_jpg_in_seven_days_face(); +#endif + } + else { + delete_jpg_in_seven_days(); + } +#ifdef GY_OS_AMBA + delete_heatmap_image(); +#endif + check_delete = 1; + } + else if (timeinfo->tm_hour != delete_time && timeinfo->tm_hour != delete_time2 && timeinfo->tm_hour != delete_time3 && timeinfo->tm_hour != delete_time4) { + check_delete = 0; + } + + //printf("\n------delete jpg in seven days detector end\n"); + + //usSleep(60000000); + usSleep(1000000); + } + else { + usSleep(10000000); + } + } + + //printf("\n---------delete jpg in seven days detector:exit\n"); + + pthread_exit(NULL); +} +#endif +//CURLM* g_multi_handle; +//int g_handle_count; + +//modified the input from file to memory based on test_detector() +#ifdef TEST_DETECTOR_MEM +void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, float thresh, float hier_thresh, int ext_output, int save_labels, char* model, char* target_device, int input_resizable, char* custom_cpu_library, char* custom_cldnn, int performance_counter, int IsHardwareOK) +{ + + //printf("\n[test detector mem]------------------------:1\n"); + //UTF8 trans.name table + char buff[MAX_MSG_LEN] = { 0 }; + //char strKeyValue[MAX_MSG_LEN] = { 0 }; // Assign ini file key value + char section[16] = { 0 }; + +#ifdef GY_OS_V_SERIES + +#else + for (int n = 0; n < MAX_LAYER_NUM; n++) + { + for (int i = 0; i < MAX_SECTION_VARIABLE; i++) + { + //if (section) + if (layerFeatureType[n] == FEATURE_LPR_MEA + || layerFeatureType[n] == FEATURE_LPR_SEA + || layerFeatureType[n] == FEATURE_LPR_VNM + || layerFeatureType[n] == FEATURE_LPR_IDN + || layerFeatureType[n] == FEATURE_LPR_USA + || layerFeatureType[n] == FEATURE_LPR_JPN + || layerFeatureType[n] == FEATURE_LPR_THA + || layerFeatureType[n] == FEATURE_LPR_LAO + || layerFeatureType[n] == FEATURE_LPR_BGD + || layerFeatureType[n] == FEATURE_LPR_TWN + || layerFeatureType[n] == FEATURE_LPR_EUR + ) + { + if (layerFeatureType[n] == FEATURE_LPR_MEA && layerFeatureType[n - 1] == FEATURE_LPR_MEA && n > 0) + strcpy(section, "[MEA]"); + if ((layerFeatureType[n] == FEATURE_LPR_SEA && layerFeatureType[n - 1] == FEATURE_LPR_SEA && n > 0) || + (layerFeatureType[n] == FEATURE_LPR_VNM && layerFeatureType[n - 1] == FEATURE_LPR_VNM && n > 0) || + (layerFeatureType[n] == FEATURE_LPR_IDN && layerFeatureType[n - 1] == FEATURE_LPR_IDN && n > 0)) + strcpy(section, "[SEA]"); + if (layerFeatureType[n] == FEATURE_LPR_USA && layerFeatureType[n - 1] == FEATURE_LPR_USA && n > 0) + strcpy(section, "[USA]"); + if (layerFeatureType[n] == FEATURE_LPR_JPN && layerFeatureType[n - 1] == FEATURE_LPR_JPN && n > 0) + strcpy(section, "[JPN]"); + if (layerFeatureType[n] == FEATURE_LPR_THA && layerFeatureType[n - 1] == FEATURE_LPR_THA && n > 0) + strcpy(section, "[THA]"); + if (layerFeatureType[n] == FEATURE_LPR_LAO && layerFeatureType[n - 1] == FEATURE_LPR_LAO && n > 0) + strcpy(section, "[LAO]"); + if (layerFeatureType[n] == FEATURE_LPR_BGD && layerFeatureType[n - 1] == FEATURE_LPR_BGD && n > 0) + strcpy(section, "[BGD]"); + if (layerFeatureType[n] == FEATURE_LPR_TWN && layerFeatureType[n - 1] == FEATURE_LPR_TWN && n > 0) + strcpy(section, "[TWN]"); + if (layerFeatureType[n] == FEATURE_LPR_EUR && layerFeatureType[n - 1] == FEATURE_LPR_EUR && n > 0) + strcpy(section, "[EUR]"); + + sprintf(buff, "%d", i); + char* value = GetIniKeyString(section, buff, INI_FILE_PATH); + if (value != NULL) { + if (strlen(value) > 0) { + strcpy(ppIniKeyValue[n][i], value); + } + else { + strcpy(ppIniKeyValue[n][i], ""); + } + } + else { + strcpy(ppIniKeyValue[n][i], ""); + } + } + else { + strcpy(ppIniKeyValue[n][i], ""); + } + } + } +#endif + +#ifdef GY_OS_AMBA + memset_snapshot_addr(); +#endif + //===================== + //sophia add 2020/09/24 + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif +// +//#ifdef GY_OS_WIN + // socketRecords[i].prev_frame_data = NULL; + /*if (socketRecords[i].prev_frame_data) + free(socketRecords[i].prev_frame_data);*/ +//#endif + socketRecords[i].used = 0; + + //socketRecord_ALM[i].sock = -1; + } + //printf("\nKKKKKKKKKKKKKKKK:3\n"); + + //for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + //{ + //socketRecord_ALM[i].sock = -1; + + /*socketRecord_ALM[i].head = NULL; + socketRecord_ALM[i].tail = NULL;*/ + //} + + mtrace(); + set_metadata(); + reset_onvif(); + initial_ivs(); + initial_g_PostRecorderList(); + check_if_is_existing_weight = 0; + + //===================== + // Create a HTTP thread + +#if 1 + //printf("\nKKKKKKKKKKKKKKKK:4\n"); + if (http_port > 0) + { + // HTTP server + //printf("\nKKKKKKKKKKKKKKKK:5\n"); + g_write_config_file_dirty_flag = 0; + protected_sqlite_fflpr_db_close = 1; +#if defined GY_OS_AMBA || defined GY_OS_NOVA + fflpr_log_db_init(); +#ifdef GY_OS_AMBA + if(unlockingKeyInnoFR == 1) + { + //face_log_db_init(); + } +#endif +#endif + isGYNetReady = TRUE; //Set GYNet is ready! + + //printf("\nKKKKKKKKKKKKKKKK:6\n"); + //run_serverLAOonA@A]nsg_IsPTZDeviceC + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed #1\n"); + } + pthread_join(thread_id_getipcamsettings, NULL); + + + + +#if 1 + //329Memory not freed `IȬ| + if (pthread_create(&http_thread, 0, run_http_server_thread, 0)) + error("HTTP server thread creation failed\n"); + +#endif + + //printf("\nKKKKKKKKKKKKKKKK:8\n"); + //printf("\n[test detector mem]------------------------:2\n"); + +#ifdef GY_OS_AMBA +#if 0 + if ( g_IsToFDevice == 1) + { + // إ߰O@ɰ + long data_size = sizeof(frameimage) + sizeof(rbuf_t); + tof_depth_shmid = Initial_ShareMemory(data_size, 888); + if (tof_depth_shmid == -1) { + perror("Create shared memory failed !\n"); + } + else { + // lƽwİ + ringbuf_init(&tof_ring_buffer); + + bTofDataStart = 1; + + if (pthread_create(&gettofdata_thread, 0, thread_getTofData, 0)) + error("thread gettofdata creation failed\n"); + } + } +#endif +#endif + +#ifdef GY_OS_AMBA + if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { + + if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { + if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 2"); +#endif + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + else { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 0"); +#endif + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + } + } +#endif + + //printf("\nKKKKKKKKKKKKKKKK:7\n"); + int check_if_setting_general_mode = 1; + if (g_IsPTZDevice == 0) + { + if (strcmp(accountData[0].account_flip, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0 || + strcmp(accountData[0].account_rotate, "1") == 0) + { + check_if_setting_general_mode = 0; + } + } + else if (g_IsPTZDevice == 1) + { + if (strcmp(accountData[0].account_rotate, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0) + { + check_if_setting_general_mode = 0; + } + } + +#if 1 + //Fdelete_jpg_in_seven_days_detectorS}AXp10,878,464byte1983ӰO鬪|(`:u@zoneABoutputu]w@ӵJݡAdwell time6) + //Fdelete_jpg_in_seven_days_detectorMrun_post_notification_threadAAS}AXp11,276,800byte1978ӰO鬪| + //Fdelete_jpg_in_seven_days_detectorMrun_post_notification_threadS}AXp11,232,112byte1467ӰO鬪|Aj1983-1467=516ӰO鬪|Orun_post_notification_thready + //Fdelete_jpg_in_seven_days_detectorS}AXp10,891,264byte1500ӰO鬪|(ɤO:u@zoneAoutput]w|ӵJݡAdwell time6) + //Fdelete_jpg_in_seven_days_detectorS}AXp11,190,784byte1568ӰO鬪|(|zoneɤO:4zoneABCoutput]w|ӵJݡAdwell time6) + //Fdelete_jpg_in_seven_days_detectorS}AXp11,518,976byte1992ӰO鬪|(|zoneɤO:4zoneABCoutput]w|ӵJݡAdwell time1) + //Fdelete_jpg_in_seven_days_detectorS}AXp11,319,296byte1697ӰO鬪|(|zoneɤO:4zoneABCoutput8ӳ}Adwell time1)//諸IPA|vTO鬪| + + bHttpServerThreadStart = 1; + + if (pthread_create(&post_notification_thread, 0, run_post_notification_thread, NULL)) + error("Post notification thread creation failed\n"); +#endif + +#ifdef GY_OS_NOVA + if (pthread_create(&resolution_changed_thread, 0, auto_resolution_changed, NULL)) + error("resolution changed thread failed\n"); +#else + if (get_run_check_current_resolution() == -1) { + set_run_check_current_resolution(0); + if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) + error("check current resolution thread failed\n"); + } +#endif + + if (IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1) + { + // printf("\n[test detector mem] IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1)\n"); + check_if_is_existing_weight = 1; + bHttpServerThreadStart = 1; + + /* + if (g_IsToFDevice == 1) { + system(SHELLSCRIPT_TOF_DRIVER); + }*/ +#if 1 + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + { + printf("\n[gynet] g_IsRadarDevice || g_IsToFDevice\n"); + if (pthread_create(&getimage_thread, 0, thread_getimage, 0)) + error("thread getimage creation failed\n"); +#ifdef GY_OS_AMBA + if (pthread_create(&getimage_hd_thread, 0, thread_getimage_hd, 0)) + error("thread getimage creation failed\n"); +#endif + } + +#endif +#ifdef GY_OS_AMBA +#if 0 + if (g_IsRadarDevice == 1) + { + if (pthread_create(&render_radar_thread, 0, thread_render_radar_img, 0)) + error("thread render_radar creation failed\n"); + + if (g_IsRadarFake == 1) + { + if (pthread_create(&radar_reciever_id, NULL, RADAR_recieve, (void *)&radar_json_data) < 0) + error("RADAR_recieve creation failed\n"); + } + else + { + if (pthread_create(&getstream_thread, 0, thread_getstream, 0)) + error("thread getimage creation failed\n"); + + if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0)) + error("thread radar parser creation failed\n"); + } + } +#endif + // unlockingKeyInnoFR_success = faceengine_start_and_check_license(); + // unlockingKeyInnoFR_success = 1; +#if 0 + if (unlockingKeyInnoFR_success == 1) { +#ifdef GY_OS_AMBA + faceengine_start(); +#endif + } +#endif +#if 0 + //ثePfaceengine + if(unlockingKeyInnoFR_success == 1){ +#ifdef GY_OS_AMBA + if (pthread_create(&get_face_websocket_thread, 0, thread_get_face_websocket, 0)) + error("thread get_face_websocket creation failed\n"); + if (pthread_create(&parse_face_thread, 0, thread_parse_face, 0)) + error("thread parse_face creation failed\n"); +#endif + } +#endif + +#endif + + //printf("\nKKKKKKKKKKKKKKKK:9\n"); + +#if 1 + //test_nn_main & run_send_udp_thread & run_getalarmmotion_thread output.log 8,532,480byte -> 1167ӰO鬪| j1167-1072=95ӰO鬪|Orun_getalarmmotion_thready + if (pthread_create(&getalarmmotion_thread, 0, run_getalarmmotion_thread, NULL)) + error("Getalarmmotion thread creation failed\n"); +#endif + +#ifdef GY_OS_V_SERIES + +#else + //329Memory not freed `IȬ| + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { +#if 1 + ////쥻W٬Ocheck_http_socket_threadA{b令run_event_counter_thread + if (pthread_create(&counter_thread, 0, run_event_counter_thread, NULL)) + error("check http socket thread creation failed\n"); +#endif + } +#endif + +#ifdef GY_OS_V_SERIES + +#else +#if 1 + //329Memory not freed `IȬ| + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (pthread_create(&delete_jpg_in_seven_days_detector_thread_id, 0, delete_jpg_in_seven_days_detector, NULL)) + printf("create delete_jpg_in_seven_days_detector thread faile \n"); + } +#endif +#endif + //printf("\nKKKKKKKKKKKKKKKK:10\n"); + // UDP thread to send getalarmotion +#if 1 + //test_nn_main & run_send_udp_thread output.log 8,579,969byte -> 1072ӰO鬪| j1072-875=197ӰO鬪|Orun_send_udp_thready + if (pthread_create(&send_udp_thread, 0, run_send_udp_thread, NULL)) + error("check http socket thread creation failed\n"); +#endif + +#ifdef GY_OS_AMBA + //**oٷ|O鬪| + //output.log 8,392,192byte ->934ӰO鬪| output.logWTܦ40,000byte + //}start_all_nets 105,984byte->343ӰO鬪| IȬ|@II `OK + //}while (live_mode_flag) 119,808byte->337ӰO鬪| IȬ|@II `OK + //if (g_IsRadarDevice == 0) + { +#if 1 + if (pthread_create(&test_nnctrl_live_thread, 0, test_nn_main, &stAMBAcontent)) + error("Test nnctrl live thread creation failed\n"); +#endif + } +#endif + +#ifdef GY_OS_NOVA + if (pthread_create(&test_nnctrl_live_thread, 0, nnctrl_main, &stAMBAcontent)) + error("Test nnctrl live thread creation failed\n"); +#endif + +#if 1 + //329Memory not freed `IȬ| + //Get CPU/VPU loading & AI FPS + if (pthread_create(&fps_loading_thread, 0, run_fps_loading_thread, NULL)) + error("fps loading thread creation failed\n"); +#endif +#ifdef GY_OS_AMBA +#if 1 + //OSD server إ + if (pthread_create(&thread_id_run_osd_server, 0, run_osd_server_thread, NULL)) { + printf("\nrun osd server thread creation failed\n"); + } +#endif +#endif + +#ifdef GY_OS_NOVA + if (pthread_create(&thread_id_get_nova_driver, 0, thread_get_nova_driver, 0)) + error("thread get nova driver creation failed\n"); +#endif + + //System time sync + //if (pthread_create(&thread_id_run_system_time_sync, 0, run_osd_time_sync_thread, NULL)) { + //printf("\nrun osd server thread creation failed\n"); + //} + } + else + bHttpServerThreadStart = 1; + + //printf("\nKKKKKKKKKKKKKKKK:12\n"); + //printf("\n[test_detector_mem] &stAMBAcontent:%x\n", &stAMBAcontent); + //printf("\n[test_detector_mem] stAMBAcontent.licenseType:%d\n", stAMBAcontent.licenseType); + RefreshCheckExistingWeight(); + int count_timeout = 0; + while (bHttpServerThreadStart) + { + if (AI_fps >= 1) + break; + else if (count_timeout >= 30) //count_timeout 100|S + { + printf("\n[Error]: Not Ready to run test_nn_main\n"); + break; + } + count_timeout++; + usSleep(1000000); + } + } + +#endif + + //muntrace(); + + //o|vTCPUįSleepӧC// + + while (bHttpServerThreadStart) + { + //printf("while bHttpServerThreadStart :%d\n", bHttpServerThreadStart); +#if defined GY_OS_NOVA + usSleep(3600000000);//3600000000 +#else + usSleep(1500000); +#endif + } + ////////////////////᭱i|Sfree + + printf("\n------------test detector mem:1\n"); + + +#if 0 + for (int n = 0; n < MAX_LAYER_NUM; n++) + { + if (layer_count > 0) + { + if (tcp_port > 0) + free_ptrs((void**)names[n], nets[n].layers[nets[n].n - 1].classes); + else if (http_port > 0) + free_ptrs((void**)names[n], http_nets[n].layers[http_nets[n].n - 1].classes); +#ifdef GY_OS_WIN + if (tcp_port > 0) + free_network(nets[n]); + + if (http_port > 0) + free_network(http_nets[n]); +#endif + //free_list_contents_kvp(options[n]); + free_list(options[n]); + } + } +#endif + + //free_ptrs(pPosInfo, element_size); + printf("\n------------test detector mem:2\n"); + + /* + if (alphabet != NULL) //20201015 sophia add + { + const int nsize = 8; + for (int j = 0; j < nsize; ++j) + { + for (int i = 32; i < 127; ++i) + { + free_image(alphabet[j][i]); + } + if (alphabet[j]) { + free(alphabet[j]); + alphabet[j] = NULL; + } + } + if (alphabet) { + free(alphabet); + alphabet = NULL; + } + }*/ + + printf("\n[test detector mem] end\n"); + + stop_server(); +} +#endif + +void stop_btHttpServer() { + // share_memory_stop(); +#if 0 + bTofDataStart = 0; +#endif + + bHttpServerThreadStart = 0; + bHttpServerMainStart = 0; + //printf("\n----------stop_btHttpServer:%d\n",1); + if (cgi_startTime_buff) { + free(cgi_startTime_buff); + cgi_startTime_buff = NULL; + } + if (cgi_whenTime_buff) { + free(cgi_whenTime_buff); + cgi_whenTime_buff = NULL; + } + //printf("\n----------stop_btHttpServer:%d\n", 2); +#ifdef GY_OS_AMBA + //if (g_IsPTZDevice == 1) { + //Free_PTZ_g_curl_connect(); + //} +#endif + //printf("\n----------stop_btHttpServer:%d\n", 3); + curl_global_cleanup(); + //printf("\n----------stop_btHttpServer:%d\n", 4); + base64_cleanup(); + //printf("\n----------stop_btHttpServer:%d\n", 5); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sqlite_fflpr_db_close(); +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR == 1) { + //sqlite_face_db_close(); + } +#endif +#endif + //printf("\n----------stop_btHttpServer:%d\n", 6); + //printf("Stop btHttpServer - finished. \n"); +} + +int get_bHttpServerThreadStart() { + return bHttpServerThreadStart; +} + +void stop_server() +{ + printf("Stop Server - started.\n"); + //pthread_mutex_lock(&mutex_run_one_net); + //bHttpServerThreadStart = 0; + //bHttpServerMainStart = 0; + //pthread_mutex_unlock(&mutex_run_one_net); + + stop_btHttpServer(); + //printf("\n----------stop server 1\n"); +#if 1 +#ifdef GY_OS_AMBA + StopPTZupdateStatusThread(); +#endif + //printf("\n----------stop server 2\n"); +//#ifdef GY_OS_AMBA + + //close 4 threads + //http server - run_http_server_thread() + //post notification - run_post_notification_thread() + //run event counter thread - run_event_counter_thread() + //test nnctrl live - test_nn_main() + +//#endif //GY_OS_AMBA +#endif + printf("Stop Server - finished. \n"); + + //destroy pthread_mutex +#if 1 + //pthread_mutex_destroy(&mutex_post_notification); + //pthread_mutex_destroy(&mutex_post_notification_push); + pthread_mutex_destroy(&mutex_post_notification_pop); + //printf("\n----------stop server 3\n"); + pthread_mutex_destroy(&mutex_getalarmmotion); + pthread_mutex_destroy(&mutex_alm); + pthread_mutex_destroy(&mutex_curl); + pthread_mutex_destroy(&mutex_dn); + + pthread_mutex_destroy(&mutex_websocket); + pthread_mutex_destroy(&mutex_enable_lpr_db); +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_enable_face_db); +#endif + pthread_mutex_destroy(&mutex_username); + pthread_mutex_destroy(&mutex_pns); + //pthread_mutex_destroy(&mutex_get_canvas); + + //printf("\n----------stop server 4\n"); + pthread_mutex_destroy(&mutex_snap); + //pthread_mutex_destroy(&mutex_cropped_roi); + //pthread_mutex_destroy(&mutex_snap_hd_image); + pthread_mutex_destroy(&mutex_snap_image); +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_remotesnap_image); // Ken 2022-09-26 + pthread_mutex_destroy(&mutex_radar_json); + pthread_mutex_destroy(&mutex_tof_json); +#endif + pthread_mutex_destroy(&mutex_get_image); + pthread_mutex_destroy(&mutex_get_image_HD); + + pthread_mutex_destroy(&mutex_config_json); +#if defined GY_OS_AMBA + //pthread_mutex_destroy(&mutex_jvc_config_json); +#endif + pthread_mutex_destroy(&mutex_events_json); + pthread_mutex_destroy(&mutex_web); + //printf("\n----------stop server 5\n"); + //pthread_mutex_destroy(&mutex_http_connection_handler); + pthread_mutex_destroy(&mutex_base64); + pthread_mutex_destroy(&mutex_run_one_net); +#ifdef GY_OS_NOVA + //pthread_mutex_destroy(&mutex_run_parse_json); +#endif + pthread_mutex_destroy(&mutex_send_jpeg); + pthread_mutex_destroy(&mutex_heatmap_jpeg); + //pthread_mutex_destroy(&mutex_strsplit); + +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_perspective_transform); +#endif + //printf("\n----------stop server 6\n"); + pthread_mutex_destroy(&mutex_get_network_input); + pthread_mutex_destroy(&mutex_differ_image); + + pthread_mutex_destroy(&mutex_run_one_net_anpr); + pthread_mutex_destroy(&mutex_check_license); + pthread_mutex_destroy(&mutex_read_ipcam); + + pthread_mutex_destroy(&mutex_update_candidate); + pthread_mutex_destroy(&mutex_send_cgi); + + //pthread_mutex_destroy(&mutex_parse_bbox); + //pthread_mutex_destroy(&mutex_color_detect); + + pthread_mutex_destroy(&mutex_compute_median); + //pthread_mutex_destroy(&mutex_long_term); + //pthread_mutex_destroy(&mutex_short_term); + + //pthread_mutex_destroy(&mutex_long_term_yuv); + //pthread_mutex_destroy(&mutex_short_term_yuv); + + pthread_mutex_destroy(&mutex_set_http_request); + pthread_mutex_destroy(&mutex_reset_counter); +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_run_osd); + + pthread_mutex_destroy(&mutex_get_depth); + //pthread_mutex_destroy(&mutex_tof_data); + pthread_mutex_destroy(&mutex_write_pcd_data); + pthread_mutex_destroy(&mutex_write_pcd_data_L); + pthread_mutex_destroy(&mutex_write_pcd_data_M); + pthread_mutex_destroy(&mutex_write_pcd_data_S); +#endif +#ifdef GY_OS_NOVA + pthread_mutex_destroy(&mutex_pre_bbox_receive); + pthread_mutex_destroy(&mutex_pre_connection); + pthread_mutex_destroy(&mutex_pre_image_receive); +#endif + +#endif + + + printf("Stop Server - pthread finished. #2\n"); +} + +#ifdef GY_OS_AMBA +void write_to_enable_tracking(char *enable_tracking) { + //printf("\n--------------[enable tracking]-----------------: %s\n", enable_tracking); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + char config_bakPATH[1024] = { 0 }; + strcpy(config_bakPATH, exePath); + strcat(config_bakPATH, "config_bak.json"); + + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + if (fileBuf_config) { + free(fileBuf_config); + fileBuf_config = NULL; + } + + if (root == NULL) + { + printf("root_config is NULL\n"); + } + else + { + cJSON *view_setting, *camera01, *ptz_enable_tracking; + + view_setting = cJSON_GetObjectItem(root, "view_setting"); + camera01 = cJSON_GetObjectItem(view_setting, "camera01"); + ptz_enable_tracking = cJSON_GetObjectItem(camera01, "ptz_enable_tracking"); + + + if (ptz_enable_tracking) { + + cJSON_ReplaceItemInObject(camera01, "ptz_enable_tracking", cJSON_CreateString(enable_tracking)); + + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(configPATH, config_bakPATH); + } + else + { + printf("Fail to open config.json \n"); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } +} +#endif +#ifdef GY_OS_AMBA +int read_bin(char *fileDir, unsigned char *addr) +{ + //fread + printf("read_bin \n"); + + //int rval = 0; + int lSize = 0; + +#if 0 + FILE *fp = NULL; + + + //lSize = ftell(fileDir); + lSize = 460800; + + printf("read_bin return\n"); + return lSize; + + if (lSize > 0) + { + fp = fopen(fileDir, "r"); + //char addr[500000]; + //int readCnt = fread(addr, 1, lSize, fp); /* return 0*/ + //int readCnt = fread(buffer,1,sizeof(buffer),fp); /* return 11 */ + //printf("readCnt = %d\n", readCnt); + fclose(fp); + } + else + return 0; +#endif + printf("read_bin return\n"); + return lSize; +} + +int teststoreYUV(char *file, int size, void *addr) +{ + FILE *fp = NULL; + int rval = 0; + + do { + if ((fp = fopen(file, "wb")) == NULL) { + printf("\n%s\n", file); + rval = -1; + break; + } + + + + if (fwrite(addr, 1, size, fp) != size) { + printf("\nfwrite]n"); + rval = -1; + break; + } + + fclose(fp); + fp = NULL; + + } while (0); + + if (fp) { + fclose(fp); + fp = NULL; + } + + return rval; +} + +int testbinfile(char *filename, char *buffer) +{ + printf("file name: %s \n", filename); + + int lSize = 0; + + FILE *fp = NULL; + + fp = fopen(filename, "r"); + + fseek(fp, 0, SEEK_END); + lSize = ftell(fp); + + rewind(fp); //set read point to start + /*size_t read_result = */fread(buffer, 1, lSize, fp); + + //char img_name[512] = { 0 }; + //sprintf(img_name, "/emmc/plugin/Aida_data/storage/hello_tofyuv.bin"); //same + ////store_bin(img_name, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt); + + //teststoreYUV(img_name, lSize, buffer); + //int readCnt = fread(buffer, 1, sizeof(buffer), fp); + + fclose(fp); + + return lSize; +} +#endif + +void move_file() { + + for(int i = 0 ; i < 13 ; i++) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + if( i == 0 ) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage"); + else if( i == 1 ) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/default.jpg"); + else if( i == 2 ) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/default.jpg"); + else if (i == 3) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/face"); + else if (i == 4) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/face/default.jpg"); + else if (i == 5) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/face/default.jpg"); + else if (i == 6) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/template"); + else if (i == 7) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/template/default.jpg"); + else if (i == 8) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/template/default.jpg"); + else if (i == 9) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/playback"); + else if (i == 10) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/playback/default.jpg"); + else if (i == 11) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/playback/default.jpg"); + else if (i == 12) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/sfe/storage"); + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + +} +void *start_run_python_thread(void* pythonpath) { + pthread_detach(pthread_self()); + setPthreadName("run_python"); + char *value = get_enable_python_file_value((const char*)pythonpath); + + while (python_check_webstatus == 0) + { + // python_check_webstatus = 0 + // python_check_webstatus = 1 } + printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); + continue; + } + // printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); + sleep(15); // Ȱ 15 A Web thread } + if (value == NULL) { + printf("Failed to retrieve enable_python_file value\n"); + pthread_exit(NULL); + } + // python ɮ + if (strstr(value, ".py") != NULL) { + printf("enable_python_file is a Python file: %s\n", value); + const char *prefix = "lifile_liname="; + char pythonfile[256]; + snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, value); + runPython(pythonfile); + } else { + printf("enable_python_file is not a Python file: %s\n", value); + } + pthread_exit(NULL); +} +char* get_enable_python_file_value(const char *filename) { + FILE *file = fopen(filename, "r"); + if (file == NULL) { + printf("Could not open file %s\n", filename); + return NULL; + } + + // jp + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Ū󤺮e줺s + char *file_content = (char *)malloc(file_size + 1); + if (file_content == NULL) { + printf("Memory allocation failed\n"); + fclose(file); + return NULL; + } + fread(file_content, 1, file_size, file); + file_content[file_size] = '\0'; + fclose(file); + + // ѪR JSON + cJSON *json = cJSON_Parse(file_content); + free(file_content); + if (json == NULL) { + printf("Error parsing JSON file\n"); + return NULL; + } + + // system_setting + cJSON *system_setting = cJSON_GetObjectItem(json, "system_setting"); + if (system_setting == NULL) { + printf("system_setting not found in JSON\n"); + cJSON_Delete(json); + return NULL; + } + + // enable_python_file + cJSON *enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + char *result = NULL; + if (enable_python_file != NULL && cJSON_IsString(enable_python_file)) { + result = strdup(enable_python_file->valuestring); // ƻsrŦ + } + + // Mz cJSON H + cJSON_Delete(json); + printf("[get_enable_python_file_value] result : %s \n",result); + // ^G + return result; +} +void run_server(int argc, char **argv) +{ + //HUSO鬪|------------------------20210803 + + check_if_start_run_server = 1; + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "The start of gynet."); + write_to_logs_html(temp_msg, "run server", "INFO", "Yes"); + write_to_log_for_start(temp_msg, "run server", "INFO"); + } + +#ifdef _DEBUG_AMBA + printf("\n[run_server] start\n"); + for (int i = 0;i < argc;i++) + printf("[run_server] argv[%d]:%s\n", i, argv[i]); +#endif // _DEBUG_AMBA + + file_management(); + initial_weight_settings(); + + getCameraPlugInInfo(); + update_accountData(); + update_accountData_port(); + + move_file(); + + g_IsRadarFake = 0; + + setlocale(LC_ALL, "en_US.UTF-8"); + + g_match_mac = 0; + + char init_CPU_usage[256] = "20"; + char init_GPU_usage[256] = "20"; + + sprintf(CPU_usage, "%s", init_CPU_usage); + sprintf(GPU_usage, "%s", init_GPU_usage);//psBuffer_send2 + +#ifdef REBOOT_BY_CPU_GPU_USAGE + CPU_usage_int = atoi(CPU_usage); + GPU_usage_int = atoi(GPU_usage); +#endif + + ColdZoneInit(); + + /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; +#ifdef GY_OS_NOVA + char config_smallPATH[1024] = { 0 }; +#endif + char config_installPATH[1024] = { 0 }; + +#ifdef GY_OS_NOVA + char config_small_installPATH[1024] = { 0 }; +#endif + char config_bakPATH[1024] = { 0 }; + + char events_installPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + char events_bakPATH[1024] = { 0 }; + + char tof_installPATH[1024] = { 0 }; + char tofPATH[1024] = { 0 }; + char tof_bakPATH[1024] = { 0 }; + + char emails_installPATH[1024] = { 0 }; + char emailsPATH[1024] = { 0 }; + char emails_bakPATH[1024] = { 0 }; + + char cold_objects_installPATH[1024] = { 0 }; + char cold_objectsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_smallPATH, exePath); +#endif + strcpy(config_installPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_small_installPATH, exePath); +#endif + strcpy(config_bakPATH, exePath); + + strcpy(eventsPATH, exePath); + strcpy(events_installPATH, exePath); + strcpy(events_bakPATH, exePath); + + strcpy(tofPATH, exePath); + strcpy(tof_installPATH, exePath); + strcpy(tof_bakPATH, exePath); + + strcpy(emailsPATH, exePath); + strcpy(emails_installPATH, exePath); + strcpy(emails_bakPATH, exePath); + + strcpy(cold_objectsPATH, exePath); + strcpy(cold_objects_installPATH, exePath); + + strcat(configPATH, "config.json"); +#ifdef GY_OS_NOVA + strcat(config_smallPATH, "config_small.json"); +#endif + strcat(config_installPATH, "config_install.json"); + +#ifdef GY_OS_NOVA + strcat(config_small_installPATH, "config_small_install.json"); +#endif + strcat(config_bakPATH, "config_bak.json"); + + strcat(eventsPATH, "events.json"); + strcat(events_installPATH, "events_install.json"); + strcat(events_bakPATH, "events_bak.json"); + + strcat(tofPATH, "tof.json"); + strcat(tof_installPATH, "tof_install.json"); + strcat(tof_bakPATH, "tof_bak.json"); + + strcat(emailsPATH, "emails.json"); + strcat(emails_installPATH, "emails_install.json"); + strcat(emails_bakPATH, "emails_bak.json"); + + strcat(cold_objectsPATH, "cold_objects.json"); + strcat(cold_objects_installPATH, "cold_objects_install.json"); + + //arguments + dont_show = find_arg(argc, argv, "-dont_show"); + show = find_arg(argc, argv, "-show"); + tcp_port = find_int_arg(argc, argv, "-tcp_port", -1); + //out_filename = find_char_arg(argc, argv, "-out_filename", 0); + //outfile = find_char_arg(argc, argv, "-out", 0); + //prefix = find_char_arg(argc, argv, "-prefix", 0); + thresh = find_float_arg(argc, argv, "-thresh", .24); + hier_thresh = find_float_arg(argc, argv, "-hier", .5); + cam_index = find_int_arg(argc, argv, "-c", 0); + frame_skip = find_int_arg(argc, argv, "-s", 0); + num_of_clusters = find_int_arg(argc, argv, "-num_of_clusters", 5); + yuv_width = find_int_arg(argc, argv, "-width", -1); + yuv_height = find_int_arg(argc, argv, "-height", -1); + ext_output = find_arg(argc, argv, "-ext_output"); + save_labels = find_arg(argc, argv, "-save_labels"); + http_port = find_int_arg(argc, argv, "-http_port", 0); + //unlocking_key = find_char_arg(argc, argv, "-unlocking_key", 0); + //char *ip_address = find_char_arg(argc, argv, "-ip_address", 0); + gpu_idx = find_int_arg(argc, argv, "-gpu_idx", 0); + //c_cnn_type = find_char_arg(argc, argv, "-cnn_type", 0); +#if 0 + radar_log = find_arg(argc, argv, "-radar_log"); // 10-19 leo +#endif + // radar_log = 1; // 2022-10-28 Ken for V1 classification testing info + //printf("radar_log:%d\n", radar_log); + + //char* model = find_char_arg(argc, argv, "-m", ""); + input_resizable = find_int_arg(argc, argv, "-auto_resize", 0); + custom_cpu_library = find_char_arg(argc, argv, "-l", ""); + custom_cldnn = find_char_arg(argc, argv, "-c", ""); + performance_counter = find_int_arg(argc, argv, "-pc", 0); + + isGYNetReady = FALSE; + + //pthread_mutex_init(&mutex_post_notification, NULL); + //pthread_mutex_init(&mutex_post_notification_push, NULL); + pthread_mutex_init(&mutex_post_notification_pop, NULL); + pthread_mutex_init(&mutex_getalarmmotion, NULL); + pthread_mutex_init(&mutex_alm, NULL); + pthread_mutex_init(&mutex_curl, NULL); + pthread_mutex_init(&mutex_dn, NULL); + + pthread_mutex_init(&mutex_websocket, NULL); + pthread_mutex_init(&mutex_enable_lpr_db,NULL); +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_enable_face_db,NULL); +#endif + pthread_mutex_init(&mutex_username, NULL); + pthread_mutex_init(&mutex_pns, NULL); + pthread_mutex_init(&mutex_snap, NULL); + //pthread_mutex_init(&mutex_get_canvas, NULL); + + //pthread_mutex_init(&mutex_cropped_roi, NULL); + //pthread_mutex_init(&mutex_snap_hd_image, NULL); + pthread_mutex_init(&mutex_snap_image, NULL); +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_remotesnap_image, NULL); // Ken 2022-09-26 + pthread_mutex_init(&mutex_radar_json, NULL); + pthread_mutex_init(&mutex_tof_json, NULL); +#endif + pthread_mutex_init(&mutex_get_image, NULL); + pthread_mutex_init(&mutex_get_image_HD, NULL); + + pthread_mutex_init(&mutex_config_json, NULL); +#if defined GY_OS_AMBA + //pthread_mutex_init(&mutex_jvc_config_json, NULL); +#endif + pthread_mutex_init(&mutex_events_json, NULL); + pthread_mutex_init(&mutex_web, NULL); + //pthread_mutex_init(&mutex_http_connection_handler, NULL); + pthread_mutex_init(&mutex_base64, NULL); + pthread_mutex_init(&mutex_run_one_net, NULL); +#ifdef GY_OS_NOVA + //pthread_mutex_init(&mutex_run_parse_json, NULL); +#endif + pthread_mutex_init(&mutex_send_jpeg, NULL); + pthread_mutex_init(&mutex_heatmap_jpeg, NULL); + //pthread_mutex_init(&mutex_strsplit, NULL); + +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_perspective_transform, NULL); +#endif + pthread_mutex_init(&mutex_get_network_input, NULL); + pthread_mutex_init(&mutex_differ_image, NULL); + + pthread_mutex_init(&mutex_run_one_net_anpr, NULL); + pthread_mutex_init(&mutex_check_license, NULL); + pthread_mutex_init(&mutex_read_ipcam, NULL); + pthread_mutex_init(&mutex_update_candidate, NULL); + + pthread_mutex_init(&mutex_send_cgi, NULL); + //pthread_mutex_init(&mutex_parse_bbox, NULL); + //pthread_mutex_init(&mutex_color_detect, NULL); + pthread_mutex_init(&mutex_compute_median, NULL); + //pthread_mutex_init(&mutex_long_term, NULL); + //pthread_mutex_init(&mutex_short_term, NULL); + + //pthread_mutex_init(&mutex_long_term_yuv, NULL); + //pthread_mutex_init(&mutex_short_term_yuv, NULL); + + pthread_mutex_init(&mutex_set_http_request, NULL); + pthread_mutex_init(&mutex_reset_counter, NULL); +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_run_osd, NULL); + + pthread_mutex_init(&mutex_get_depth, NULL); + //pthread_mutex_init(&mutex_tof_data, NULL); + pthread_mutex_init(&mutex_write_pcd_data, NULL); + pthread_mutex_init(&mutex_write_pcd_data_L, NULL); + pthread_mutex_init(&mutex_write_pcd_data_M, NULL); + pthread_mutex_init(&mutex_write_pcd_data_S, NULL); +#endif +#ifdef GY_OS_NOVA + pthread_mutex_init(&mutex_pre_bbox_receive, NULL); + pthread_mutex_init(&mutex_pre_connection, NULL); + pthread_mutex_init(&mutex_pre_image_receive, NULL); +#endif + //g_multi_handle = curl_multi_init(); //Curl init + + //QueueLockInit(); + + //HWSO鬪|------------------------20210803 + + //100ӥkO鬪| + memset(&accountData, 0, sizeof(accountData)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + + pthread_mutex_lock(&mutex_curl); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + pthread_mutex_unlock(&mutex_curl); + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed\n"); + } + pthread_join(thread_id_getipcamsettings, NULL); + //StartPTZupdateStatusThread(); + +#ifdef GY_OS_NOVA + ipcam_getfeatures(); +#else + if (strcmp(WeightFileModeName, "mod004") == 0) { + ipcam_getfeatures(); + } +#endif + + ///ŪSMTP service + + copy_ipcam_smtp_service_to_gynet(); + + //printf("000 get password = %s \n", accountData[0].account_password); + +#if 1 + + //1ӰO鬪| + if (http_port > 0) + { + //printf("\n**********************\n"); + //printf("preload server open"); + //printf("\n**********************\n"); + + pthread_t preload_http_thread; + if (pthread_create(&preload_http_thread, 0, run_preload_http_server_thread, 0)) + error("preload http server thread creation failed\n"); + + } + + //0ӥkO鬪| + //char returned_msg[MEMORY_SIZE] = { 0 }; + //PNS_Query_Service_Status(returned_msg); + +#endif + + + + + //**bOKO鬪| + //output.log 138,240byte ->330ӰO鬪| output.logWTܤC + //get_current_events_json_data |O鬪|AO`ihC + g_IsPTZDevice = 0; + + + +#endif + + //init CGI CMD time + + //ӰO鬪| bstop_server~| + cgi_startTime_buff = (struct tm*)malloc(sizeof(struct tm)); + cgi_whenTime_buff = (struct tm*)malloc(sizeof(struct tm)); + + //printf("GyNet is starting......\n"); + + td_weight_num = 0; + + char customWeightPATH[1024] = { 0 }; + strcpy(customWeightPATH, exePath); + strcat(customWeightPATH, "customWeight.json"); + + cJSON* root_third, * weight_number; + cJSON *third_party_weight_list, *td_party_weight, *weight_name,*anchor_name,*label_name, *encryption; + + //printf("111 get password = %s \n", accountData[0].account_password); + + if (!FileExist(customWeightPATH)) + { + td_weight_num = 0; + printf("%s doesn't exist.\n", customWeightPATH); + } + else + { + //printf("read customWeight.json.\n"); + + char* fileBuf_third = ReadAllBytes(customWeightPATH); + if (fileBuf_third) { + root_third = cJSON_Parse(fileBuf_third); + + if (fileBuf_third) { + free(fileBuf_third); + fileBuf_third = NULL; + } + weight_number = cJSON_GetObjectItem(root_third, "Weight Number"); + if (weight_number) + td_weight_num = (short)weight_number->valueint; + + third_party_weight_list = cJSON_GetObjectItem(root_third, "Third party weight"); + + if (third_party_weight_list) + { + int k = 0; + cJSON_ArrayForEach(td_party_weight, third_party_weight_list) + { + if (td_party_weight && k < MAX_LAYER_NUM) + { + weight_name = cJSON_GetObjectItem(td_party_weight, "Weight Name"); + if (weight_name) + sprintf(td_weight_info[k].weight_name, "%s", weight_name->valuestring); + + anchor_name = cJSON_GetObjectItem(td_party_weight, "Anchor Name"); + if (anchor_name) + sprintf(td_weight_info[k].anchor_name, "%s", anchor_name->valuestring); + + label_name = cJSON_GetObjectItem(td_party_weight, "Label Name"); + if (label_name) + sprintf(td_weight_info[k].label_name, "%s", label_name->valuestring); + + encryption = cJSON_GetObjectItem(td_party_weight, "Encryption"); + if (encryption && strcmp(encryption->valuestring,"Yes")==0) + td_weight_info[k].is_encryption = 1; + else + td_weight_info[k].is_encryption = 0; + k++; + } + } + } + + if (root_third) { + cJSON_Delete(root_third); + root_third = NULL; + } + } + } + +#if 0 + for (int i = 0; i < td_weight_num; i++) { + printf("\nWeight Name: %s\n", td_weight_info[i].weight_name); + printf("\nis_encryption: %hd\n", td_weight_info[i].is_encryption); + } +#endif + + int new_data_write_to_config_file_flag = 0; + int new_data_write_to_events_file_flag = 0; + int new_data_write_to_tof_file_flag = 0; + //printf("\n-------------------http_port: %d\n", http_port); + sprintf(accountData[0].account_aida_port, "%d", http_port); + + if (tcp_port > 0 || http_port > 0) + { + + //read settings from config.json + //char filename[] = config_bakPATH; + char *filename = configPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return; + } + + //printf("read config.json. %s\n", filename); + //size_t nfileSize = ReadFileSize(filename); + + char* fileBuf = ReadAllBytes(filename); + + if(fileBuf){ + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //printf("config.json parse OK.\n"); + cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); + //cJSON* nic_name = cJSON_GetObjectItem(about_box, "NIC name"); + cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + //printf(">>>>>>>>>>> uk key = %s \n", unlock_key->valuestring); + + /* + if (td_weight_num >= 1) { + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("Third_party")); + unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + }*/ + + if (unlock_key && (int)strlen(unlock_key->valuestring) == 0) { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath); + strcat(keyPATH, "key.txt"); + if (FileExist(keyPATH) == 1) { + + char key_buff[1024] = { 0 };//creating char array to store data of file + + FILE *pFile; + + if ((pFile = fopen(keyPATH, "r")) != NULL) + { + fscanf(pFile, "%s", key_buff); + fclose(pFile); + + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(key_buff)); + unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + + + char* JsonString = cJSON_Print(root); + + FILE *f = fopen(configPATH, "w"); + if (f == NULL) + { + printf("Error opening config.json!\n"); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + CopyFileTo(configPATH, config_bakPATH); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + else + printf("Fail to open key.txt \n"); + } + } + + //ѽXunlockingKey - step 1:base64 decode + size_t base64_decode_length = 0; + unsigned char EncryptKeyData[256]; + char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + + base64_decode(unlock_key->valuestring, strlen(unlock_key->valuestring), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //printf("\n--------------OriEncryptData:%s\n", OriEncryptData); + //printf("\n--------------EncryptKeyData:%s\n", EncryptKeyData); + + //ѽXunlockingKey - step 2:AES descrytion + KeyExpansion(key, expandedKey); + //printf("\n---------expandedKey:%s\n", expandedKey); + AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); + //printf("unlocking_key descrytion OK.\n"); + + //printf("key info = %s \n", DecryptKeyData); + + //printf("\n--------------DecryptKeyData:%s\n", DecryptKeyData); + + //ounlockingKeyXT + cJSON *keyRoot, *fe, *fe2, *li, *ad, *st, *et, *id; + keyRoot = cJSON_Parse(DecryptKeyData); + fe = cJSON_GetObjectItem(keyRoot, "fe"); + fe2 = cJSON_GetObjectItem(keyRoot, "fe2"); + li = cJSON_GetObjectItem(keyRoot, "li"); + ad = cJSON_GetObjectItem(keyRoot, "ad"); + st = cJSON_GetObjectItem(keyRoot, "st"); + et = cJSON_GetObjectItem(keyRoot, "et"); + id = cJSON_GetObjectItem(keyRoot, "id"); + + + unsigned char first_half_char_key[512] = { 0 }; + unsigned char mykey_custom[512] = { 0 }; + + //unsigned char expandedmykey_custom[176] = { 0 }; + char mygmail_after_ddDec[512] = { 0 }; + + // If lilin ID and independent face license are not consistent, the verification will fail. + if (!id && unlock_key && strlen(unlock_key->valuestring) >= 4 && strncmp(unlock_key->valuestring, "face", 4) != 0) + { + printf("[ERROR] Null System ID\n"); + + //printf("\n--------------unlock_key->valuestring:%s\n", unlock_key->valuestring); + + memcpy(first_half_char_key, unlock_key->valuestring, 16); + if ((int)strlen((char *)first_half_char_key) < 16) { + for (int i = (int)strlen((char *)first_half_char_key); i < 16; i++) { + first_half_char_key[i] = '0'; + } + } + //printf("\n--------------first_half_char_key:%s\n", first_half_char_key); + + ddDec(unlock_key->valuestring, mygmail_after_ddDec); + //printf("\n---------------mygmail_after_ddDec: %s\n", mygmail_after_ddDec); + + if (strstr(mygmail_after_ddDec, "@") != NULL && + strstr(mygmail_after_ddDec, "email:") != NULL) { + + for (int i = 0; i < 16; i++) { + //mykey_custom[i] = first_half_char_key[i]; + sprintf((char*)mykey_custom + i * 2, "%02x", (char*)first_half_char_key[i]); + } + + //printf("\n---------------mykey_custom: %s\n", mykey_custom); + check_if_correct_mail = 1; + } + + } + else { + //printf("System ID: %s\n", id->valuestring); + } + + //oøT + strcpy(g_filename_TLT, TLT_FILE_NAME); + //strcpy(filename2, exePath); + //first time + if (!FileExist(g_filename_TLT) || ReadFileSize(g_filename_TLT) == 0) + { + printf("TLT file doesn't exist.\n"); + + //create gysetting.json with current time + { + time_t now_time = time(0); + char strLaunchTime[16] = { 0 }; + snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); + + //Nɶ[K, gJɮ + //if (!(last_launch_time > now_time)) + { + KeyExpansion(key, expandedKey); + unsigned char EncryptData[1 * 1024]; + memset(EncryptData, 0x00, sizeof(EncryptData)); + int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); + + size_t base64_encode_length = 0; + char launchTime[1024] = { 0 }; + base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); + *(launchTime + base64_encode_length) = '\0'; + + cJSON *s_root = cJSON_CreateObject(); + cJSON_AddItemToObject(s_root, "TLT code", cJSON_CreateString(launchTime)); + cJSON_AddItemToObject(s_root, "VM code", cJSON_CreateString("%")); + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(g_filename_TLT, "w"); + if (f == NULL) + { + printf("Error opening setting file!\n"); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (s_root) { + free(s_root); + s_root = NULL; + } + } + } + } + + //printf("\n----------------mode: %s\n", WeightFileModeName); + + int bMacMatch = 0; + if (g_match_mac == 1) { + bMacMatch = 1; + } + //int nEnableNIC = 0; + char * find; + + + ///omac + { + char fetch_mac_addr[64] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + GetMACAddress(fetch_mac_addr); + //printf("\n--------------------------:25\n"); + //http_mac_address = fetch_mac_addr; + + //printf("\nfetch_mac_addr:%s\n", fetch_mac_addr); + //printf("\nid->valuestring:%s\n", id->valuestring); + + find = strchr(fetch_mac_addr, '\n'); + if (find) + *find = '\0'; + + strcpy(g_mac_address, fetch_mac_addr); + } + + //printf("111-9 get password = %s \n", accountData[0].account_password); + // Check SDK3.0 and independent face license +#ifdef GY_OS_AMBA +#if 0 + if (g_IsSDK_3_0 == 1 && unlock_key && strncmp(unlock_key->valuestring, "face", 4) == 0) { + unlockingKeyInnoFR = 1; + // printf("unlocking key : %s\n", unlock_key->valuestring); + + char temp_key[512] = { 0 }; + //memcpy(temp_key, unlock_key->valuestring + 4, strlen(unlock_key->valuestring) - 4); + char formatted_mac[30] = { 0 }; +#if 0 + char fetch_mac_addr[30] = { 0 }; + //printf("\n--------g_mac_address:%s\n", g_mac_address); + strcpy(fetch_mac_addr, g_mac_address); + char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); + //printf("\n--------new_mac_addr:%s\n", new_mac_addr); + + //sprintf(formatted_mac, "%s", new_mac_addr + 2); + if (new_mac_addr) { + free(new_mac_addr); + new_mac_addr = NULL; + } +#endif + + getContractSignature(temp_key, formatted_mac); + + //printf("\n--------formatted_mac:%s\n", formatted_mac); + //printf("\n--------temp_key:%s\n", temp_key); + + memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); + strcpy(strUnlockingKey,"face"); + strcat(strUnlockingKey, temp_key); + + char object_key[512] = { 0 }; + strcpy(object_key, unlock_key->valuestring+4); + if (strcmp(temp_key, object_key)!=0) { + //printf("\nAAAAAAAAAA:Diff\n"); + char buffer_content[1024] = { 0 }; + strcpy(buffer_content,"{\"unlocking_key\":\""); + strcat(buffer_content,strUnlockingKey); + strcat(buffer_content,"\"}"); + update_config(buffer_content); + } + else { + //printf("\nAAAAAAAAAA:OK\n"); + } + + unlockingKeyInnoFR_success = faceengine_start_and_check_license(); // if strat faceengine earlily(when getContractSignature), faceengine will stuck + + //unlockingKeyInnoFR_success = 1;//ҰfaceengineAݯणih + //if (unlockingKeyInnoFR_success == 1) + //{ + + //} + } +#endif +#endif + + +#ifdef GY_OS_AMBA + if (strcmp(WeightFileModeName, "mod001") == 0 || + strcmp(WeightFileModeName, "mod002") == 0 || + strcmp(WeightFileModeName, "mod003") == 0 || + strcmp(WeightFileModeName, "mod004") == 0) { + if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring, "auto") == 0) { + check_if_fe_fail = 1; + } + } +#else + if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring,"auto")==0) { + check_if_fe_fail = 1; + } +#endif + + if ((fe && fe2 && li && st && et && id && td_weight_num == 0) || (td_weight_num >= 1 && check_if_correct_mail == 1) || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) + { + //ovɶ + time_t start_time; + time_t end_time; + struct tm* m_time; + + if (fe && fe2) { + featureType = fe->valueint; + featureType2 = fe2->valueint; + + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + } + /*else if (unlockingKeyInnoFR_success == 1) { + featureType = FEATURE_EMPTY; + featureType2 = FEATURE_AIFACE; + stAMBAcontent.featureType = FEATURE_EMPTY; + stAMBAcontent.featureType2 = FEATURE_AIFACE; + }*/ + else if (check_if_fe_fail == 1) { + featureType = FEATURE_TRAF_DET; +#ifdef GY_OS_V_SERIES + featureType2 = FEATURE_AIFLOW; +#elif defined GY_OS_NOVA + featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; +#else + /*if (g_check_if_OK_getfeatures == 0) { + featureType2 = FEATURE_AIFLOW; + } + else*/ + + featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; +#endif + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + } + else { + featureType = 0x0000; + featureType2 = 0x0000; + stAMBAcontent.featureType = 0x0000; + stAMBAcontent.featureType2 = 0x0000; + } + + if (li && st && et && id) { + start_time = st->valueint; + m_time = gmtime(&start_time); + m_time->tm_mday += et->valueint; + end_time = mktime(m_time); + g_start_time = start_time; + g_end_time = end_time; + } + else { + start_time = 0; + end_time = 0; + g_start_time = start_time; + g_end_time = end_time; + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIRADAR) == FEATURE_AIRADAR) + { + g_IsRadarDevice = 1; + printf("g_IsRadarDevice : %d\n", g_IsRadarDevice); + printf("g_IsRadarFake : %d\n", g_IsRadarFake); + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AITOF) == FEATURE_AITOF) + { + g_IsToFDevice = 1; + printf("\ng_IsToFDevice : %d\n", g_IsToFDevice); + } + + if (td_weight_num >= 1 && check_if_correct_mail == 1) { + g_IsCustomWeight = 1; + printf("\ng_IsCustomWeight : %d\n", g_IsCustomWeight); + //featureType = FEATURE_ACCESS_CTRL; + //featureType2 = 0x0000; + //stAMBAcontent.featureType = FEATURE_ACCESS_CTRL; + //stAMBAcontent.featureType2 = 0x0000; + } + + //printf("111-8 get password = %s \n", accountData[0].account_password); + + // printf("Check licence:\n"); + //printf("--------------featureType = 0x%x \n", featureType); + //printf("--------------featureType2 = 0x%x \n", featureType2); + // printf("--------------li->valueint: %d\n", li->valueint); + // printf("--------------st->valueint: %d\n", st->valueint); + // printf("--------------et->valueint: %d\n", et->valueint); + // printf("--------------id->valueint: %d\n", id->valueint); + + ///////////////////////////////////////////////////////HWfeaturetype oa + /* + if (strstr(EncryptKeyData, "@") == NULL) { + printf("\nThere is no @.\n"); + } + else { + printf("\nThere is existing @.\n"); + }*/ + + //oMAC Address + //20201111 sophia add + + if (g_match_mac == 0) + { + char fetch_mac_addr[30] = { 0 }; + strcpy(fetch_mac_addr, g_mac_address); + + char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); + //printf("new_mac_addr = %s\n", new_mac_addr); + + //char* find_lilin_mac = strstr((const char*)new_mac_addr, "000FFC"); //begin 00-0f-fc //000FFC + + if (strstr(new_mac_addr, "000FFC") != NULL || strstr(new_mac_addr, "142FFD") != NULL) + { + if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { + if (id && strcmp(id->valuestring, new_mac_addr) == 0) + { + //printf("find_lilin_mac = 0x%x\n", find_lilin_mac); + bMacMatch = 1; //ŦXMAC address + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { + bMacMatch = 1; + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + else + { + bMacMatch = 0; + g_match_mac = 0; + g_bMacMatch = bMacMatch; + } + } + else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { + bMacMatch = 1; + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + else if(check_if_correct_mail == 1){ + bMacMatch = 1; + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + /*else if (g_IsRadarDevice == 1) {//{bkeyFANݭnŦXMAC address + bMacMatch = 1; + g_match_mac = 1; + } + else if (g_IsToFDevice == 1)//{bkeyFANݭnŦXMAC address + { + bMacMatch = 1; + g_match_mac = 1; + }*/ + else { + bMacMatch = 0; + g_match_mac = 0; + g_bMacMatch = bMacMatch; + } + } + else + { + g_match_mac = 0; + printf("\n============This is not LILIN mac address.\n"); + } + /* + printf("\ng_match_mac: %d\n", g_match_mac); + printf("\ng_mac_address: %s\n", g_mac_address); + */ + if (new_mac_addr) { + free(new_mac_addr); + new_mac_addr = NULL; + } + } + + //printf("111-711 0 get password = %s \n", accountData[0].account_password); + + update_system_time(); + + if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && g_IsRadarDevice == 0 && unlockingKeyInnoFR_success == 0) { + if (li) + g_li = li->valueint; + else + g_li = 0; + + if (ad) + g_ad = ad->valueint; + else + g_ad = 0; + + if (ad && li) + check_license(li->valueint, ad->valueint, bMacMatch, start_time, end_time, g_filename_TLT); + else if(li) + check_license(li->valueint, 0, bMacMatch, start_time, end_time, g_filename_TLT); + else + check_license(0, 0, bMacMatch, start_time, end_time, g_filename_TLT); + } + + check_feature(); + //printf("111-7 0 get password = %s \n", accountData[0].account_password); + //post events setting + //char filename2[] = "events.json"; + char *filename2 = eventsPATH; + char *filename_tof = tofPATH; + if (!FileExist(filename2)) + { + printf("%s doesn't exist.\n", filename2); + printf("Press any key to exit...\n"); + getchar(); + return; + } + if (!FileExist(filename_tof)) + { + printf("%s doesn't exist.\n", filename_tof); + printf("Press any key to exit...\n"); + getchar(); + return; + } + //printf("111-7 1 get password = %s \n", accountData[0].account_password); + cJSON *tof_root; + cJSON *tof_version,*tof_debug,*tof_install_angle,*tof_enable_camera,*enable_tof_ground,*enable_tof_wall,*tof_camera; + cJSON *tof_camera_ip,*tof_camera_port,*tof_camera_sub_url,*tof_auth_key,*tof_ip_setting,*tof_camera_username,*tof_camera_password; + cJSON *distance_options, *distance_threshold, *height_options, *height_threshold,*distance_min_max,*height_min_max; + cJSON *ground_x, *ground_y; + + fileBuf = ReadAllBytes(filename_tof); + if (fileBuf) { + tof_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + + tof_version = cJSON_GetObjectItem(tof_root, "version"); + tof_debug = cJSON_GetObjectItem(tof_root, "debug"); + tof_install_angle = cJSON_GetObjectItem(tof_root, "install_angle"); + tof_enable_camera = cJSON_GetObjectItem(tof_root, "enable_camera"); + enable_tof_ground = cJSON_GetObjectItem(tof_root, "enable_tof_ground"); + enable_tof_wall = cJSON_GetObjectItem(tof_root, "enable_tof_wall"); + tof_camera = cJSON_GetObjectItem(tof_root, "camera"); + distance_options = cJSON_GetObjectItem(tof_root, "distance_options"); + distance_threshold = cJSON_GetObjectItem(tof_root, "distance_threshold"); + height_options = cJSON_GetObjectItem(tof_root, "height_options"); + height_threshold = cJSON_GetObjectItem(tof_root, "height_threshold"); + distance_min_max = cJSON_GetObjectItem(tof_root, "distance_min_max"); + height_min_max = cJSON_GetObjectItem(tof_root, "height_min_max"); + + ground_x = cJSON_GetObjectItem(tof_root, "ground_x"); + ground_y = cJSON_GetObjectItem(tof_root, "ground_y"); + +#ifdef GY_OS_AMBA + if (tof_version) { + tofData.tof_version = tof_version->valueint; + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_version = 1; + } + + + if (tof_debug) { + if (cJSON_IsTrue(tof_debug)) + { + tofData.tof_debug = true; + } + else + { + tofData.tof_debug = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_debug = false; + } + + + if (tof_install_angle) { + tofData.tof_install_angle = tof_install_angle->valueint; + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_install_angle = 90; + } + + if (tof_enable_camera) { + if (cJSON_IsTrue(tof_enable_camera)) + { + tofData.tof_enable_camera = true; + } + else + { + tofData.tof_enable_camera = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_enable_camera = false; + } + + if (enable_tof_ground) { + if (cJSON_IsTrue(enable_tof_ground)) + { + tofData.enable_tof_ground = true; + } + else + { + tofData.enable_tof_ground = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.enable_tof_ground = false; + } + + if (enable_tof_wall) { + if (cJSON_IsTrue(enable_tof_wall)) + { + tofData.enable_tof_wall = true; + } + else + { + tofData.enable_tof_wall = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.enable_tof_wall = false; + } + + if (distance_options) { + strcpy(tofData.distance_options, distance_options->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.distance_options, "lt"); + } + + if (distance_min_max) { + strcpy(tofData.distance_min_max, distance_min_max->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.distance_min_max, "min"); + } + + if (distance_threshold) { + strcpy(tofData.distance_threshold, distance_threshold->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.distance_threshold, "0.5"); + } + + if (height_options) { + strcpy(tofData.height_options, height_options->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.height_options, "gt"); + } + + if (height_min_max) { + strcpy(tofData.height_min_max, height_min_max->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.height_min_max, "max"); + } + + if (ground_x) { + strcpy(tofData.ground_x, ground_x->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.ground_x, "320"); + } + + if (ground_y) { + strcpy(tofData.ground_y, ground_y->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.ground_y, "240"); + } + + if (height_threshold) { + strcpy(tofData.height_threshold, height_threshold->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.height_threshold, "1.5"); + } + + if (tof_camera) { + tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); + tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); + tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); + tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); + tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); + tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); + tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); + + if (tof_camera_ip) { + strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_ip, "192.168.50.200"); + } + + if (tof_camera_port) { + strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_port, "80"); + } + + if (tof_camera_sub_url) { + strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_sub_url, "/stream0"); + } + + if (tof_auth_key) { + strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); + } + + if (tof_ip_setting) { + if (cJSON_IsTrue(tof_ip_setting)) + { + tofData.tof_ip_setting = true; + } + else + { + tofData.tof_ip_setting = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_ip_setting = false; + } + + if (tof_camera_username) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); + tofData.tof_camera_username[strlen(temp_account)] = '\0'; + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_username, "admin"); + } + + if (tof_camera_password) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); + tofData.tof_camera_password[strlen(temp_account)] = '\0'; + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_password, "pass"); + } + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_ip, "192.168.50.200"); + strcpy(tofData.tof_camera_port, "80"); + strcpy(tofData.tof_camera_sub_url, "/stream0"); + strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); + tofData.tof_ip_setting = false; + strcpy(tofData.tof_camera_username, "admin"); + strcpy(tofData.tof_camera_password, "pass"); + } +#endif + } + } + //printf("111-7 2 get password = %s \n", accountData[0].account_password); + cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content + ,*post_customized_header; + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone,*counter_c_name, + *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + cJSON *link_to_post_event_name, *post_interval; + cJSON *email_setting,*email_content; + cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + fileBuf = ReadAllBytes(filename2); + if (fileBuf) { + n_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + notification = cJSON_GetObjectItem(n_root, "notification"); + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + + if (events_default_version) { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.events_default_version, "1"); + } + + if (enable_snmp_post) + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + else { + new_data_write_to_events_file_flag = 1; + activeSNMPPost = _FALSE; + } + + if (enable_heartbeat) { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_heartbeat, "No"); + } + + if (enable_snmp_heartbeat) { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_snmp_heartbeat, "No"); + } + + if (snmp_heartbeat_dwell) { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); + } + + if (snmp_heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); + } + + if (enable_check_ptz_start_autotracking) { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); + } + + if (enable_check_ptz_end_autotracking) { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); + } + + if (enable_only_once_to_post) { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_only_once_to_post, "Yes"); + } + + if (enable_obj_once_to_post) { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); + } + + if (enable_location_once_to_post) { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_location_once_to_post, "Yes"); + } + + if (enable_nvr_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); + } + + if (enable_8592_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); + } + + if (dwell_to_the_same_location) { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.dwell_to_the_same_location, "5"); + } + + if (heartbeat_dwell) { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heartbeat_dwell, "10"); + } + + if (heatmap_max) { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heatmap_max, "100"); + } + + if (enable_heatmap) { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_heatmap, "No"); + } + + if (heatmap_frequency) { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heatmap_frequency, "5"); + } + + if (lpr_title) { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.lpr_title, "My Car Park"); + } + + if (heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); + } + + if (ptz_start_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); + } + + if (ptz_end_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); + } + + if (enable_counter_snap) { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_counter_snap, "No"); + } + + if (enable_barcode_qr) { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_barcode_qr, "No"); + } + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + strcpy(postEventList[i].post_protocol, post_protocol->valuestring); + strcpy(postEventList[i].post_event_method, post_event_method->valuestring); + strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); + + if (g_camera_white_LED == 1 && i == 2 && strcmp(postEventList[i].post_event_name, "Camera virtual 3 / White LED") != 0) { + new_data_write_to_events_file_flag = 1; + strcpy(postEventList[i].post_event_name, "Camera virtual 3 / White LED"); + } + + strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); + strcpy(postEventList[i].post_host_port, post_host_port->valuestring); + strcpy(postEventList[i].post_url, post_url->valuestring); + //strcpy(postEventList[i].post_username, post_username->valuestring); + //strcpy(postEventList[i].post_password, post_password->valuestring); + strcpy(postEventList[i].post_content, post_content->valuestring); + strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); + + if (post_sequence) + strcpy(postEventList[i].post_sequence, post_sequence->valuestring); + else { + strcpy(postEventList[i].post_sequence, ""); + new_data_write_to_events_file_flag = 1; + } + + if (post_timeout) + strcpy(postEventList[i].post_timeout, post_timeout->valuestring); + else { + strcpy(postEventList[i].post_timeout, "5"); + new_data_write_to_events_file_flag = 1; + } + + if (post_file_format) + strcpy(postEventList[i].post_file_format, post_file_format->valuestring); + else { + strcpy(postEventList[i].post_file_format, "text"); + new_data_write_to_events_file_flag = 1; + } + + if (post_jpeg_file_name_format) + strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); + new_data_write_to_events_file_flag = 1; + } + + if (post_jpeg_file_name) + strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name, "snap"); + new_data_write_to_events_file_flag = 1; + } + + postEventList[i].check_if_delivering = 0;//La褣Al + i++; + } + if (i < 9) { + strcpy(postEventList[i].post_protocol, "HTTP"); + strcpy(postEventList[i].post_event_method, "GET"); + strcpy(postEventList[i].post_event_name, "Go to PTZ preset"); + strcpy(postEventList[i].post_host_ip, "localhost"); + strcpy(postEventList[i].post_host_port, accountData[0].account_aida_port); + strcpy(postEventList[i].post_url, "/ptzpreset?camid=1&ai_goto_preset=1"); + strcpy(postEventList[i].post_username, "admin"); + strcpy(postEventList[i].post_password, "Pass1234"); + strcpy(postEventList[i].post_content, ""); + strcpy(postEventList[i].post_customized_header, ""); + strcpy(postEventList[i].post_sequence, ""); + strcpy(postEventList[i].post_file_format, "text"); + strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); + strcpy(postEventList[i].post_jpeg_file_name, "snap"); + strcpy(postEventList[i].post_timeout, "5"); + + new_data_write_to_events_file_flag = 1; + } + +#ifdef GY_OS_V_SERIES + +#else + event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + strcpy(eventCounterList[i].counter_name, counter_name->valuestring); + + if (counter_cust_name) + strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); + else { + strcpy(eventCounterList[i].counter_cust_name, eventCounterList[i].counter_name); + new_data_write_to_events_file_flag = 1; + } + strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); + if (reset_value) + eventCounterList[i].reset_value = atoi(reset_value->valuestring); + else { + eventCounterList[i].reset_value = 0; + new_data_write_to_events_file_flag = 1; + } + strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_at, reset_at->valuestring); + strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); + strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); + strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); + struct tm tm; + strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetResetAt = mktime(&tm); + + struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); + eventCounterList[i].reset_month = resetTime->tm_mon; + eventCounterList[i].reset_month_day = resetTime->tm_mday; + eventCounterList[i].reset_week_day = resetTime->tm_wday; + eventCounterList[i].reset_hour = resetTime->tm_hour; + eventCounterList[i].reset_min = resetTime->tm_min; + eventCounterList[i].reset_sec = resetTime->tm_sec; + strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeFrom = mktime(&tm); + strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeTo = mktime(&tm); + + if (link_to_post_event_name) { + strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].link_to_post_event_name, ""); + } + + if (post_interval) { + strcpy(eventCounterList[i].post_interval, post_interval->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].post_interval, "5 minutes"); + } + + if (enable_reset_only_cloud) { + strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); + } + + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); + } + + i++; + } + if (i < 8) { + new_data_write_to_events_file_flag = 1; + } + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + + if (report_counters) { + i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + if (counter_a) { + strcpy(reportCounterList[i].counter_a, counter_a->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a, "Counter01"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_a_name) { + strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_name, "Name"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_a_zone) { + strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_zone, "1"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_b) { + strcpy(reportCounterList[i].counter_b, counter_b->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b, ""); + new_data_write_to_events_file_flag = 1; + } + + if (counter_b_name) { + strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_name, ""); + new_data_write_to_events_file_flag = 1; + } + + if (counter_b_zone) { + strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_zone, "0"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_c_name) { + strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_c_name, ""); + new_data_write_to_events_file_flag = 1; + } + + if (report_max_value) { + strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); + } + else { + strcpy(reportCounterList[i].report_max_value, "100"); + new_data_write_to_events_file_flag = 1; + } + + if (enable_report) { + strcpy(reportCounterList[i].enable_report, enable_report->valuestring); + } + else { + strcpy(reportCounterList[i].enable_report, "No"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_mode) { + strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); + } + else { + strcpy(reportCounterList[i].counter_mode, "0"); + new_data_write_to_events_file_flag = 1; + } + + if (initial_icon) { + strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); + } + else { + strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); + new_data_write_to_events_file_flag = 1; + } + + if (detection_output) { + strcpy(reportCounterList[i].detection_output, detection_output->valuestring); + } + else { + strcpy(reportCounterList[i].detection_output, "No entry for cars"); + new_data_write_to_events_file_flag = 1; + } + + if (output_icon) { + strcpy(reportCounterList[i].output_icon, output_icon->valuestring); + } + else { + strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); + new_data_write_to_events_file_flag = 1; + } + + i++; + } + } + + if (i < MAX_REPORT_COUNTERS) { + for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + + new_data_write_to_events_file_flag = 1; + } + } + else { + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + + new_data_write_to_events_file_flag = 1; + } + + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + + if (snmp_management) { + i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + if (snmp_event_name) { + strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); + } + else { + char temp_name[10] = { 0 }; + sprintf(temp_name, "SNMP %d", i + 1); + strcpy(SNMPManagementList[i].snmp_event_name, temp_name); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_version) { + strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_version, "v1"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_group_name) { + strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_group_name, "public"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_host_ip) { + strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_host_port) { + strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_port, "161"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_oid) { + strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_value) { + strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_value, "mylocation"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_type) { + strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_type, "string"); + new_data_write_to_events_file_flag = 1; + } + + SNMPManagementList[i].check_if_delivering = 0;//La褣Al + i++; + } + } + + if (i < MAX_SNMP_MANAGEMENT) { + for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + + SNMPManagementList[index_snmp].check_if_delivering = 0;//La褣Al + } + + new_data_write_to_events_file_flag = 1; + } + } + else { + for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + + SNMPManagementList[index_snmp].check_if_delivering = 0;//La褣Al + } + + new_data_write_to_events_file_flag = 1; + } + +#endif + + email_setting = cJSON_GetObjectItem(n_root, "email_setting"); + if (email_setting) { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) { + strcpy(emailData.email_content, email_content->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + } + //printf("111-7 3 get password = %s \n", accountData[0].account_password); + //trigger events settings + //cJSON* cam_ip, * http_port, * video_port, * cam_pwd, * channel_id; + cJSON *view_setting, *camera, *camera_name, *enable_anpr, *enable_face, *enable_traffic, *enable_logo, *tab_view_size, *enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, + *enable_track,*enable_PTZ, *ptz_tracking_fov_min, *ptz_tracking_fov_max, *ptz_enable_tracking, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, + *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, + *cJSON_enable_only_show_metadata1, + *count_zone, *ivs_mode, *detection_zone, *detect, *ptz_tracking_mode, + *levenshtein_distance, *min_characters, *max_characters, *obj_min_proportion, *obj_max_proportion, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, + *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, + *point_number, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5 = NULL, *y5, *x6 = NULL, *y6, + *ptz_zone_to_preset = NULL, + *enable_speed, *set_distance, *world_distance_unit, *world_distance_side1, *world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, + *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered, *unknown_object_max_proportion, *unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object, *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, + *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; + + //root = cJSON_Parse(fileBuf); + view_setting = cJSON_GetObjectItem(root, "view_setting"); + + //printf("111-7 get password = %s \n", accountData[0].account_password); + + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + /*cam_ip = cJSON_GetObjectItem(camera, "ip"); + http_port = cJSON_GetObjectItem(camera, "http_port"); + video_port = cJSON_GetObjectItem(camera, "video_port"); + cam_username = cJSON_GetObjectItem(camera, "username"); + cam_pwd = cJSON_GetObjectItem(camera, "password"); + channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + + plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); + plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); + plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); + + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + + if (plate_filter_times) + viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); + else { + viewChannelData[n].i_plate_filter_times = 4; + new_data_write_to_config_file_flag = 1; + } + + if (plate_filter_time) + viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); + else { + viewChannelData[n].i_plate_filter_time = 3; + new_data_write_to_config_file_flag = 1; + } + + if (plate_free_time) + viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); + else { + viewChannelData[n].i_plate_free_time = 3; + new_data_write_to_config_file_flag = 1; + } + + strcpy(viewChannelData[n].confidence, confidence->valuestring); + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + + if (count_zone) + viewChannelData[n].count_zone = count_zone->valueint; + else { + viewChannelData[n].count_zone = 1; + new_data_write_to_config_file_flag = 1; + } + //printf("\nenable_lpr_db-----8\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + if (enable_lpr_db) + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + else { + strcpy(viewChannelData[n].enable_lpr_db, "Yes"); + new_data_write_to_config_file_flag = 1; + } + pthread_mutex_unlock(&mutex_enable_lpr_db); + + enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); + if (enable_downsized_cropped_roi) { + set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); + } + else { + set_enable_downsized_cropped_roi(1); + new_data_write_to_config_file_flag = 1; + } + + enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); + if (enable_zone_crop_1) { + set_enable_zone_crop_1(enable_zone_crop_1->valueint); + } + else { + set_enable_zone_crop_1(0); + new_data_write_to_config_file_flag = 1; + } + + enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); + if (enable_add_face_frequent_list) + if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) + viewChannelData[n].enable_add_face_frequent_list = 1; + else + viewChannelData[n].enable_add_face_frequent_list = 0; + else { + viewChannelData[n].enable_add_face_frequent_list = 1; + new_data_write_to_config_file_flag = 1; + } + enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); + if (enable_PTZ) + strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); + else { + strcpy(viewChannelData[n].enable_PTZ, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_track = cJSON_GetObjectItem(camera, "enable_track"); + if (enable_track) + strcpy(viewChannelData[n].enable_track, enable_track->valuestring); + else { + strcpy(viewChannelData[n].enable_track, "No"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); + if (ptz_tracking_fov_min) + strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); + else { + strcpy(viewChannelData[n].ptz_tracking_fov_min, "0"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); + if (ptz_tracking_fov_max) + strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); + else { + strcpy(viewChannelData[n].ptz_tracking_fov_max, "40"); + new_data_write_to_config_file_flag = 1; + } + + ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); + if (ptz_enable_tracking) + strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); + else { + strcpy(viewChannelData[n].ptz_enable_tracking, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + //Tracking MODE + //1: First in First out + //2: Bigger first + //3: All + ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); + if (ptz_tracking_mode) + viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); + else + { + viewChannelData[n].ptz_tracking_mode = 1; + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); + if (ptz_tracking_by_enter_zone) { + if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + else + viewChannelData[n].ptz_tracking_by_enter_zone = 0; + } + else { + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + new_data_write_to_config_file_flag = 1; + } + + enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); + if (enable_tracking_limits) + strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); + else { + strcpy(viewChannelData[n].enable_tracking_limits, "No"); + new_data_write_to_config_file_flag = 1; + } + + ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); + if (ptz_pan_left_limit) + strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); + new_data_write_to_config_file_flag = 1; + } + + ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); + if (ptz_pan_right_limit) + strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); + if (ptz_tilt_up_limit) + strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); + if (ptz_tilt_down_limit) + strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); + new_data_write_to_config_file_flag = 1; + } + + ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); + if (ptz_speed) + strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); + else { + strcpy(viewChannelData[n].ptz_speed, "3"); + new_data_write_to_config_file_flag = 1; + } + + enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); + if (enable_unknown_object) + strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_unknown_object, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); + if (enable_ivs_person_detection) + strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); + new_data_write_to_config_file_flag = 1; + } + + assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); + if (assign_ivs_object_to) + strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); + else { + strcpy(viewChannelData[n].assign_ivs_object_to, ""); + new_data_write_to_config_file_flag = 1; + } + + enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); + if (enable_ambulance) + strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); + else { + strcpy(viewChannelData[n].enable_ambulance, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); + if (enable_blank_plate) + strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); + else { + strcpy(viewChannelData[n].enable_blank_plate, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); + if (enable_stop_sign) + strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); + else { + strcpy(viewChannelData[n].enable_stop_sign, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); + if (enable_show_unknown_object) + strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_show_unknown_object, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); + if (enable_ivs_fix_mode) + strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); + if (enable_ivs_and_ai) + strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); + if (enable_lpr_upon_triggered) + strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); + new_data_write_to_config_file_flag = 1; + } + + dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); + if (dwell_lpr_upon_triggered) + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); + new_data_write_to_config_file_flag = 1; + } + + ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); + if (ivs_mode) + strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); + else { + strcpy(viewChannelData[n].ivs_mode, "3"); + new_data_write_to_config_file_flag = 1; + } + + unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); + if (unknown_object_max_proportion) + strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); + else { + strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); + new_data_write_to_config_file_flag = 1; + } + + unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); + if (unknown_object_min_proportion) + strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); + else { + strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); + new_data_write_to_config_file_flag = 1; + } + + confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); + if (confidence_unknown_object) + strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].confidence_unknown_object, "0"); + new_data_write_to_config_file_flag = 1; + } + + confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); + if (confidence2_unknown_object) + strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].confidence2_unknown_object, "0"); + new_data_write_to_config_file_flag = 1; + } + + dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); + if (dwell_unknown_object) + strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].dwell_unknown_object, "30"); + new_data_write_to_config_file_flag = 1; + } + + dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); + if (dwell_minute_focus_on) + strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); + else { + strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); + new_data_write_to_config_file_flag = 1; + } + + person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); + if (person_obj_fov) + strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); + else { + strcpy(viewChannelData[n].person_obj_fov, "100"); + new_data_write_to_config_file_flag = 1; + } + + getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); + if (getnetwork_buffer_id) + strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); + else { + strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); + new_data_write_to_config_file_flag = 1; + } + + red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); + if (red_light_zone) + strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); + else { + strcpy(viewChannelData[n].red_light_zone, ""); + new_data_write_to_config_file_flag = 1; + } + + no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); + if (no_give_way_zone_to_protect) + strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); + new_data_write_to_config_file_flag = 1; + } + + no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); + if (no_give_way_zone_to_keep_away) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); + new_data_write_to_config_file_flag = 1; + } + + + no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); + if (no_give_way_zone_to_protect_2) + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); + new_data_write_to_config_file_flag = 1; + } + + no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); + if (no_give_way_zone_to_keep_away_2) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); + new_data_write_to_config_file_flag = 1; + } + + ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); + if (ptz_sensitivity) + viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); + else + { + viewChannelData[n].ptz_sensitivity = 6; + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); + if (ptz_tracking_resume_dwell) + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); + else { + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, "3"); + new_data_write_to_config_file_flag = 1; + } + + cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); + if (cJSON_enable_only_show_metadata1) + enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; + else { + enable_only_show_metadata1 = 0; + new_data_write_to_config_file_flag = 1; + } + + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + //printf("\n[run_server]tab_view_size: %s\n", tab_view_size->valuestring); + char outArray[2][STRSPLIT_SIZE]={0}; + char temp_tab[50] = { 0 }; + strcpy(temp_tab, tab_view_size->valuestring); + StrSplit(temp_tab, outArray, "x"); + //printf("\n------UU:16\n"); + viewChannelData[n].channel_idx = n; + if (outArray[0]) + viewChannelData[n].tab_view_width = atoi(outArray[0]); + else + new_data_write_to_config_file_flag = 1; + if (outArray[1]) + viewChannelData[n].tab_view_height = atoi(outArray[1]); + else + new_data_write_to_config_file_flag = 1; + + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + + + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + if (enable_face) { + if (strcmp(enable_face->valuestring, "Yes") == 0) + viewChannelData[n].enable_face = 1; + else + viewChannelData[n].enable_face = 0; + } + else { + new_data_write_to_config_file_flag = 1; + viewChannelData[n].enable_face = 1; + } + + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + + detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + + viewChannelData[n].enable_traffic_light_zone = 0; + + int i = 0; + + cJSON_ArrayForEach(detect, detection_zone) + { + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); + obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); + obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); + + enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); + enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); + enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); + parking_space = cJSON_GetObjectItem(detect, "parking_space"); + parking_line = cJSON_GetObjectItem(detect, "parking_line"); + set_distance = cJSON_GetObjectItem(detect, "set_distance"); + world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); + world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); + world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); + world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); + + if (obj_max_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); + else { + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, "80"); + new_data_write_to_config_file_flag = 1; + } + + if (obj_min_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); + else { + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (ptz_zone_to_preset) + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); + else { + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_speed) + strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); + else { + strcpy(viewDetectionZone[n][i].enable_speed, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_radar_speed) + strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); + else { + strcpy(viewDetectionZone[n][i].enable_radar_speed, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_ivs_zone) + strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); + else { + strcpy(viewDetectionZone[n][i].enable_ivs_zone, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (parking_space) { + viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); + } + else { + viewDetectionZone[n][i].parking_space = 0; + new_data_write_to_config_file_flag = 1; + } + + if (parking_line) { + viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); + } + else { + viewDetectionZone[n][i].parking_line = 0; + new_data_write_to_config_file_flag = 1; + } + + if (set_distance) { + viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); + } + else { + viewDetectionZone[n][i].set_distance = 10; + new_data_write_to_config_file_flag = 1; + } + + if (world_distance_unit) + strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); + else { + strcpy(viewDetectionZone[n][i].world_distance_unit, "meter"); + new_data_write_to_config_file_flag = 1; + } + + if (world_distance_side1) + { + viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); + viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); + viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); + } + else { + viewDetectionZone[n][i].world_distance_side1 = 10; + viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; + viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; + + new_data_write_to_config_file_flag = 1; + } + //printf("[%d]World dis 1 = %f \n", i, viewDetectionZone[n][i].world_distance_side1); + + if (world_distance_side2) + { + viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); + viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); + viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); + } + else { + viewDetectionZone[n][i].world_distance_side2 = 10; + viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; + viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; + new_data_write_to_config_file_flag = 1; + } + //printf("[%d]World dis 2 = %f \n", i, viewDetectionZone[n][i].world_distance_side2); + + viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); + viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); + + if (world_time_unit) + strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); + else { + strcpy(viewDetectionZone[n][i].world_time_unit, "KPH"); + new_data_write_to_config_file_flag = 1; + } + + trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); + + point_number = cJSON_GetObjectItem(detect, "point_number"); + /* + if (point_number) + printf("load point number 2 = %d \n", point_number->valueint); + */ + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + + if (metadata_stop) + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + else { + strcpy(viewDetectionZone[n][i].metadata_stop, ""); + new_data_write_to_config_file_flag = 1; + } + + if (no_parking_time) + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + else { + viewDetectionZone[n][i].no_parking_time = 5; + new_data_write_to_config_file_flag = 1; + } + + if (no_parking_time_in_minute) + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + else { + viewDetectionZone[n][i].no_parking_time_in_minute = 0; + new_data_write_to_config_file_flag = 1; + } + + if (queuing_count && strlen(queuing_count->valuestring) >= 1) + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + else { + viewDetectionZone[n][i].queuing_count = 1; + new_data_write_to_config_file_flag = 1; + } + + if (point_number) + viewDetectionZone[n][i].point_num = point_number->valueint; + else { + viewDetectionZone[n][i].point_num = 6; + new_data_write_to_config_file_flag = 1; + } + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].Points[3].y = y4->valueint; + + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + + if (x5 && x6) + { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].Points[5].y = y6->valueint; + + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + } + else + new_data_write_to_config_file_flag = 1; + + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; + //UpdateTrafficLightZone(n); + } + +#ifdef GY_OS_AMBA + if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) + { + int social_zone_idx = i; + if (social_zone_idx >= 0) + { + pthread_mutex_lock(&mutex_perspective_transform); + if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); + viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); + pthread_mutex_unlock(&mutex_perspective_transform); + } + } +#endif + + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + int original_zone_size = i; + + //int arraySize = cJSON_GetArraySize(detection_zone); + + int k = 0; + for (int j = 0; j < MAX_DETECTION_ZONE && j < original_zone_size; j++) + { + k = 0; + + cJSON_ArrayForEach(detect, trigger_events[j]) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + if (!detect_event_id || !detect_event_name || strlen(detect_event_id->valuestring) == 0 || strlen(detect_event_name->valuestring) == 0) { + new_data_write_to_config_file_flag = 1; + } + else { + viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + k++; + } + if (k < MAX_TRIGGER_EVENT) { + + if(k < 10) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00800000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Visitor list"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 11) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x01000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Unattended object or missing object"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 12) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x02000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "BG learning"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 13) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x04000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Tampering detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 14) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x40000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "All objects detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 15) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x80000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lack of any object detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 16) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00002000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Over speed detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 17) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00004000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lower speed detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 18) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000400"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Running red lights"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 19) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000800"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning left on red"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 20) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00001000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning right on red"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 21) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00008000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Forget to give way detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 22) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00040000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Distance violation"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 23) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x08000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Height detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + new_data_write_to_config_file_flag = 1; + } + } + + if (original_zone_size < MAX_DETECTION_ZONE) { + for (int index_zone = original_zone_size; index_zone < MAX_DETECTION_ZONE; index_zone++) { + strcpy(viewDetectionZone[n][index_zone].obj_max_proportion_in_zone, "80"); + strcpy(viewDetectionZone[n][index_zone].obj_min_proportion_in_zone, "0"); + strcpy(viewDetectionZone[n][index_zone].ptz_zone_to_preset, "0"); + strcpy(viewDetectionZone[n][index_zone].enable_speed, "No"); + strcpy(viewDetectionZone[n][index_zone].enable_radar_speed, "No"); + strcpy(viewDetectionZone[n][index_zone].enable_ivs_zone, "No"); + viewDetectionZone[n][index_zone].parking_space = 0; + viewDetectionZone[n][index_zone].parking_line = 0; + viewDetectionZone[n][index_zone].set_distance = 10; + strcpy(viewDetectionZone[n][index_zone].world_distance_unit, "meter"); + viewDetectionZone[n][index_zone].world_distance_side1 = 10; + viewDetectionZone[n][index_zone].world_distance[0] = viewDetectionZone[n][index_zone].world_distance_side1; + viewDetectionZone[n][index_zone].world_distance[2] = viewDetectionZone[n][index_zone].world_distance_side1; + viewDetectionZone[n][index_zone].world_distance_side2 = 10; + viewDetectionZone[n][index_zone].world_distance[1] = viewDetectionZone[n][index_zone].world_distance_side2; + viewDetectionZone[n][index_zone].world_distance[3] = viewDetectionZone[n][index_zone].world_distance_side2; + strcpy(viewDetectionZone[n][index_zone].world_time_unit, "KPH"); + strcpy(viewDetectionZone[n][index_zone].detection_time, ""); + strcpy(viewDetectionZone[n][index_zone].metadata1, ""); + strcpy(viewDetectionZone[n][index_zone].metadata2, ""); + strcpy(viewDetectionZone[n][index_zone].metadata_stop, ""); + strcpy(viewDetectionZone[n][index_zone].link_to_counter, ""); + strcpy(viewDetectionZone[n][index_zone].enable_direction1, "No"); + strcpy(viewDetectionZone[n][index_zone].enable_direction2, ""); + strcpy(viewDetectionZone[n][index_zone].direction1, "1"); + strcpy(viewDetectionZone[n][index_zone].direction2, ""); + viewDetectionZone[n][index_zone].no_parking_time = 5; + viewDetectionZone[n][index_zone].no_parking_time_in_minute = 0; + viewDetectionZone[n][index_zone].queuing_count = 1; + viewDetectionZone[n][index_zone].point_num = 6; + + viewDetectionZone[n][index_zone].Points[0].x = 19; + viewDetectionZone[n][index_zone].Points[0].y = 16; + viewDetectionZone[n][index_zone].Points[1].x = 19; + viewDetectionZone[n][index_zone].Points[1].y = 250; + viewDetectionZone[n][index_zone].Points[2].x = 19; + viewDetectionZone[n][index_zone].Points[2].y = 484; + viewDetectionZone[n][index_zone].Points[3].x = 870; + viewDetectionZone[n][index_zone].Points[3].y = 484; + viewDetectionZone[n][index_zone].Points[4].x = 870; + viewDetectionZone[n][index_zone].Points[4].y = 250; + viewDetectionZone[n][index_zone].Points[5].x = 870; + viewDetectionZone[n][index_zone].Points[5].y = 16; + + viewDetectionZone[n][index_zone].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].y, CANVAS_HEIGHT / 2); + + strcpy(viewDetectionZone[n][index_zone].enable_traffic_light, ""); + + for (int index_trigger = 0; index_trigger < MAX_TRIGGER_EVENT; index_trigger++) { + viewDetectionZone[n][index_zone].trigger_event[index_trigger].checked = 0; + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_id, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_id); + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_name, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_name); + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].post_event_name, ""); + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_name, ""); + viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_increment = -2; + } + } + + new_data_write_to_config_file_flag = 1; + } + } + + //cJSON* cnn_device[MAX_LAYER_NUM]; + cJSON* system_setting/*, *load_cnn_type*/, *display_dash, *display_properties,*display_OSD/*, *enable_log*/, *overlap_thresh, *confidence_thresh,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage, + *enable_person_independent,*enable_onvif_profile_m, *enable_crop_mode,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language, + *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran,*osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, + *enable_email_notification,*enable_system_logs,*enable_email_jpeg, *send_counter_at_specific_hour,*email_reset_time_interval,*sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; + cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; + + + system_setting = cJSON_GetObjectItem(root, "system_setting"); + //cJSON* api_version = cJSON_GetObjectItem(system_setting, "api version"); + //load_cnn_type = cJSON_GetObjectItem(system_setting, "cnn type"); + overlap_thresh = cJSON_GetObjectItem(system_setting, "overlap thresh"); + confidence_thresh = cJSON_GetObjectItem(system_setting, "confidence thresh"); + enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); + enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); + enable_crop_mode = cJSON_GetObjectItem(system_setting, "enable_crop_mode"); + nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); + tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); + cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); + enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); + enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); + enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); + enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); + cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); + cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); + cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); + cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); + cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); + cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); + cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); + language = cJSON_GetObjectItem(system_setting, "language"); + enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); + enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); + enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); + force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); + force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); + enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); + enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); + ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); + + enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); + cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); + cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); + enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); + cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); + cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); + + enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); + enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); + getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); + getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); + osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); + osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); + osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); + enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); + osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); + osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); + sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); + enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); + external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); + external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); + external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); + external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); + enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); + enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); + send_counter_at_specific_hour = cJSON_GetObjectItem(system_setting, "send_counter_at_specific_hour"); + email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); + enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); + + enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); + ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); + ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); + ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); + ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); + ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); + ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); + ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); + + if (enable_person_independent) + strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); + else { + strcpy(SystemSetting.enable_person_independent, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_onvif_profile_m) + strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); + else { + strcpy(SystemSetting.enable_onvif_profile_m, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_crop_mode) + strcpy(SystemSetting.enable_crop_mode, enable_crop_mode->valuestring); + else { + strcpy(SystemSetting.enable_crop_mode, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (nms_thres) + strcpy(SystemSetting.nms_thres, nms_thres->valuestring); + else { + strcpy(SystemSetting.nms_thres, "10"); + new_data_write_to_config_file_flag = 1; + } + + if (tracking_id_dwell) + strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); + else { + strcpy(SystemSetting.tracking_id_dwell, "5"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_enable_snap) + strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); + else { + strcpy(SystemSetting.cloud_enable_snap, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_cloud) + strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); + else { + strcpy(SystemSetting.enable_cloud, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_special_edition) + strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); + else { + strcpy(SystemSetting.enable_special_edition, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_python) + strcpy(SystemSetting.enable_python, enable_python->valuestring); + else { + strcpy(SystemSetting.enable_python, "No"); + new_data_write_to_config_file_flag = 1; + } + if (enable_python_file) + { + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + + if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { + perror("check current runpython thread failed\n"); + exit(EXIT_FAILURE); + } + } + else { + strcpy(SystemSetting.enable_python_file, "No python running."); + new_data_write_to_config_file_flag = 1; + } + if (enable_low_cpu_usage) + strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); + else { + strcpy(SystemSetting.enable_low_cpu_usage, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_enable_notification) + strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); + else { + strcpy(SystemSetting.cloud_enable_notification, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_account) + strcpy(SystemSetting.cloud_account, cloud_account->valuestring); + else { + strcpy(SystemSetting.cloud_account, "myaccount@mail.com"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_password) + strcpy(SystemSetting.cloud_password, cloud_password->valuestring); + else { + strcpy(SystemSetting.cloud_password, "mypass"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_notification_dwell) + strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); + else { + strcpy(SystemSetting.cloud_notification_dwell, "60"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_statue) + strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); + else { + strcpy(SystemSetting.cloud_statue, ""); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_v2_statue) + strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); + else { + strcpy(SystemSetting.cloud_v2_statue, ""); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_record_v2_statue) + strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); + else { + strcpy(SystemSetting.cloud_record_v2_statue, ""); + new_data_write_to_config_file_flag = 1; + } + + if (enable_special_char) + strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); + else + { + strcpy(SystemSetting.enable_special_char, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_bounding_box) + strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); + else + { + strcpy(SystemSetting.enable_bounding_box, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_dwell_bounding_box) + strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); + else + { + strcpy(SystemSetting.enable_dwell_bounding_box, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (force_i_to_one) + strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); + else + { + strcpy(SystemSetting.force_i_to_one, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (force_o_to_zero) + strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); + else + { + strcpy(SystemSetting.force_o_to_zero, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_plate_angle_correction) + strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); + else + { + strcpy(SystemSetting.enable_plate_angle_correction, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_ai_mirror) + strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); + else + { + strcpy(SystemSetting.enable_ai_mirror, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (ai_mirror_feature) + strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); + else + { + strcpy(SystemSetting.ai_mirror_feature, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_cloud_v2) + strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); + else + { + strcpy(SystemSetting.enable_cloud_v2, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_v2_notification_dwell) + strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); + else + { + strcpy(SystemSetting.cloud_v2_notification_dwell, "60"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_v2_content) + strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); + else + { + strcpy(SystemSetting.cloud_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_cloud_record_v2) + strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); + else + { + strcpy(SystemSetting.enable_cloud_record_v2, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_record_v2_notification_dwell) + strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); + else + { + strcpy(SystemSetting.cloud_record_v2_notification_dwell, "60"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_record_v2_content) + strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); + else + { + strcpy(SystemSetting.cloud_record_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_post_only_if_both_detected) + strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); + else + { + strcpy(SystemSetting.enable_post_only_if_both_detected, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_getalarmmotion_snap) + strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); + else + { + strcpy(SystemSetting.enable_getalarmmotion_snap, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (getimage_encoder_id) + strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); + else + { +#ifdef GY_OS_NOVA + strcpy(SystemSetting.getimage_encoder_id, "3"); +#endif + +#ifdef GY_OS_AMBA + strcpy(SystemSetting.getimage_encoder_id, "4"); +#endif + new_data_write_to_config_file_flag = 1; + } + + if (getimage_encoder_id_HD) + strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); + else + { +#ifdef GY_OS_NOVA + strcpy(SystemSetting.getimage_encoder_id_HD, "0"); +#endif +#ifdef GY_OS_AMBA + strcpy(SystemSetting.getimage_encoder_id_HD, "4"); +#endif + + new_data_write_to_config_file_flag = 1; + } + + if (osd_encoder_id) + strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); + else + { + strcpy(SystemSetting.osd_encoder_id, "2"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_font_size) + strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); + else + { + strcpy(SystemSetting.osd_font_size, "26"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_outline_lilin) + strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); + else + { + strcpy(SystemSetting.osd_outline_lilin, "4"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_osd_bottom) + strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); + else + { + strcpy(SystemSetting.enable_osd_bottom, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_bottom_bg_tran) + strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); + else + { + strcpy(SystemSetting.osd_bottom_bg_tran, "255"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_bottom_content) + strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); + else + { + strcpy(SystemSetting.osd_bottom_content, "Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>"); + new_data_write_to_config_file_flag = 1; + } + + if (sensors_type) + strcpy(SystemSetting.sensors_type, sensors_type->valuestring); + else + { + strcpy(SystemSetting.sensors_type, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_sync_external_lpr_db) + strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); + else + { + strcpy(SystemSetting.enable_sync_external_lpr_db, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_IP) + strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_IP, "192.168.0.200"); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_port) + strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_port, accountData[0].account_aida_port); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_username) + strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_username, "admin"); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_password) + strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_password, "pass"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_system_logs) + strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); + else + { + strcpy(SystemSetting.enable_system_logs, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_email_jpeg) + strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); + else + { + strcpy(SystemSetting.enable_email_jpeg, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (send_counter_at_specific_hour) + strcpy(SystemSetting.send_counter_at_specific_hour, send_counter_at_specific_hour->valuestring); + else + { + strcpy(SystemSetting.send_counter_at_specific_hour, "NULL"); + new_data_write_to_config_file_flag = 1; + } + + if (email_reset_time_interval) + strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); + else + { + strcpy(SystemSetting.email_reset_time_interval, ""); + new_data_write_to_config_file_flag = 1; + } + + if (enable_ftp) + strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); + else + { + strcpy(SystemSetting.enable_ftp, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_url) + strcpy(SystemSetting.ftp_url, ftp_url->valuestring); + else + { + strcpy(SystemSetting.ftp_url, "ftp.example.com"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_port) + strcpy(SystemSetting.ftp_port, ftp_port->valuestring); + else + { + strcpy(SystemSetting.ftp_port, "21"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_username) + strcpy(SystemSetting.ftp_username, ftp_username->valuestring); + else + { + strcpy(SystemSetting.ftp_username, ""); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_password) + strcpy(SystemSetting.ftp_password, ftp_password->valuestring); + else + { + strcpy(SystemSetting.ftp_password, ""); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_remote_directory) + strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); + else + { + strcpy(SystemSetting.ftp_remote_directory, "myfolder/myfile"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_jpeg_file_name_format) + strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); + else + { + strcpy(SystemSetting.ftp_jpeg_file_name_format, "fixed"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_jpeg_file_name) + strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); + else + { + strcpy(SystemSetting.ftp_jpeg_file_name, "snap"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_email_notification) + strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); + else + { + strcpy(SystemSetting.enable_email_notification, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (language) + strcpy(SystemSetting.language, language->valuestring); + else { + strcpy(SystemSetting.language, "en_gb"); + new_data_write_to_config_file_flag = 1; + } + + + display_properties = cJSON_GetObjectItem(system_setting, "display properties"); + if (display_properties) + strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); + else { + strcpy(SystemSetting.enable_display_properties, "No"); + new_data_write_to_config_file_flag = 1; + } + + display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); + if (display_OSD) + strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); + else { + strcpy(SystemSetting.enable_display_OSD, "No"); + new_data_write_to_config_file_flag = 1; + } + + //enable_log = cJSON_GetObjectItem(system_setting, "enable log"); + //api_format_ver = atoi(api_version->valuestring); + + overlap_ratio_limit = 75; + if (overlap_thresh) + overlap_ratio_limit = overlap_thresh->valuedouble; + + confidence_limit = 0; + stAMBAcontent.confidence_plate = 0; + stAMBAcontent.confidence_traffic = 0; + if (confidence_thresh) + { + confidence_limit = confidence_thresh->valuedouble; + stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; + stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; + } + + display_dash = cJSON_GetObjectItem(system_setting, "display dash"); + activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + + activeDisplayProperties = (strcmp(display_properties->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + + //printf("111-6 get password = %s \n", accountData[0].account_password); + + //20201027 sophia add + //account settings + cJSON *account_setting, *account_data; + account_setting = cJSON_GetObjectItem(root, "account_setting"); + account_data = cJSON_GetObjectItem(account_setting, "account_data"); + +#if 1 + { + //ѽXaccount_data - step 1:base64 decode + size_t base64_decode_length = 0; + unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; + char DecryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + base64_decode(account_data->valuestring, strlen(account_data->valuestring), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //ѽXaccount_data - step 2:AES descrytion + KeyExpansion(key, expandedKey); + AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); + //printf("account_data descrytion OK.\n"); +#ifdef _DEBUG_AMBA + printf("account_data = %s \n", DecryptKeyData); +#endif + + //oaccount_dataXT + cJSON *keyRoot, *detect; + cJSON *account_username, *account_password, *account_type, *account_status; + keyRoot = cJSON_Parse(DecryptKeyData); + int i = 0; + cJSON_ArrayForEach(detect, keyRoot) + { + account_username = cJSON_GetObjectItem(detect, "account_username"); + account_password = cJSON_GetObjectItem(detect, "account_password"); + account_type = cJSON_GetObjectItem(detect, "account_type"); + account_status = cJSON_GetObjectItem(detect, "account_status"); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)account_username->valuestring, strlen(account_username->valuestring), (unsigned char *)temp_account, 512); + + memcpy(accountData[i].account_username, temp_account, strlen(temp_account)); + accountData[i].account_username[strlen(temp_account)] = '\0'; + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)account_password->valuestring, strlen(account_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(accountData[i].account_password, temp_account2, strlen(temp_account2)); + accountData[i].account_password[strlen(temp_account2)] = '\0'; + + + //printf("111-6-0 get password = %s \n", account_password->valuestring); + //printf("111-6-0 password size = %d \n", strlen(account_password->valuestring)); + + //printf("111-6-1 get password = %s \n", accountData[i].account_password); + //printf("111-6-1 password size = %d \n", strlen(accountData[i].account_password)); + + //strcpy(accountData[i].account_username, account_username->valuestring); + //strcpy(accountData[i].account_password, account_password->valuestring); + accountData[i].account_type = account_type->valueint; + accountData[i].account_status = account_status->valueint; + + //printf("111-6-2 get password = %s \n", accountData[i].account_password); + +#ifdef _DEBUG_AMBA + printf("\naccountData[%d].account_username:%s", i, accountData[i].account_username); + printf("\naccountData[%d].account_password:%s", i, accountData[i].account_password); + printf("\naccountData[%d].account_type:%d", i, accountData[i].account_type); + printf("\naccountData[%d].account_status:%d", i, accountData[i].account_status); +#endif + + i++; + } + if (keyRoot) { + cJSON_Delete(keyRoot); + keyRoot = NULL; + } + } +#endif + + overlap_ratio_limit = 75; + if (overlap_thresh) + overlap_ratio_limit = overlap_thresh->valuedouble; + + confidence_limit = 0; + stAMBAcontent.confidence_plate = 0; + stAMBAcontent.confidence_traffic = 0; + if (confidence_thresh) + { + confidence_limit = confidence_thresh->valuedouble; + stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; + stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; + } + + { + char* fileBuf = ReadAllBytes(emailsPATH); + + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (root) + { + cJSON *auth_password; + auth_password = cJSON_GetObjectItem(root, "auth_password"); + + if (auth_password && strlen(auth_password->valuestring) >= 1) + { + size_t base64_decode_length = 0; + char EncryptKeyData[256]; + char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + char temp_auth_password[256] = { 0 }; + memcpy(temp_auth_password, auth_password->valuestring, strlen(auth_password->valuestring)); + + //KeyExpansion(key_email, expandedKey_email); + //int decryptSize = AESDecryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); + + base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + strcpy(IPCAMService.auth_password, EncryptKeyData); + + //printf("\n-------------temp_auth_password:%s\n", temp_auth_password); + //printf("\n-------------DecryptKeyData:%s\n", DecryptKeyData); + //printf("\n-------------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); + + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else { + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + printf("\nFail to read emailsPATH or emails.json\n"); + } + } + + //printf("\n---------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); + + //printf("GYNet Version=%s\n", APP_VERSION); + //printf("LicenseType=%s\n", strLicenseType);// + //printf("LicenseStatus=%s\n", strLicenseStatus); + //printf("111-5 get password = %s \n", accountData[0].account_password); + //printf("\n----------g_match_mac:%d\n", g_match_mac); + if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { + if (strcmp(strLicenseStatus, "Trial mismatch the system ID") != 0) { + if (strcmp(strLicenseStatus, "License mismatch the system ID") != 0) { + if (IsExistingWeight(featureType, featureType2)) { + if (strncmp(strUnlockingKey, "face", 4) == 0) { + + } + else { + strcpy(strUnlockingKey, unlock_key->valuestring); + } + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char keyPATH[1024]; + + strcpy(keyPATH, exePath); + + strcat(keyPATH, "key.txt"); + + + FILE *pFile; + if ((pFile = fopen(keyPATH, "w")) != NULL) + { + fprintf(pFile, strUnlockingKey); + fclose(pFile); + } + else + { + printf("Fail to open key.txt \n"); + } + + } + else + strcpy(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type"); + } + else + strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); + } + else + strcpy(strUnlockingKey, "Trial_mismatch_the_system_ID"); + } + else { + if (g_match_mac == 1) { + strcpy(strUnlockingKey, "Third_party"); + } + else { + strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); + } + } + + //printf("\nUnlockingKey=%s\n", strUnlockingKey); + //printf("111-4 get password = %s \n", accountData[0].account_password); + if (new_data_write_to_config_file_flag == 1 + || strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") == 0 + || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0 + || strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") == 0 + || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0) + { + + cJSON *new_data_root, *ai_server, *view_setting, *camera01, *detection_zone, *detect, *trigger_events, *trigger, *system_setting, *account_setting, *about_box; + new_data_root = cJSON_CreateObject(); + ai_server = cJSON_CreateObject(); + view_setting = cJSON_CreateObject(); + camera01 = cJSON_CreateObject(); + detection_zone = cJSON_CreateArray(); + system_setting = cJSON_CreateObject(); + account_setting = cJSON_CreateObject(); + about_box = cJSON_CreateObject(); + + cJSON_AddItemToObject(new_data_root, "ai_server", ai_server); + cJSON_AddItemToObject(ai_server, "ip", cJSON_CreateString("127.0.0.1")); + + cJSON_AddItemToObject(ai_server, "http_port", cJSON_CreateString(accountData[0].account_aida_port)); + cJSON_AddItemToObject(ai_server, "video_port", cJSON_CreateString("8591")); + + cJSON_AddItemToObject(new_data_root, "view_setting", view_setting); + cJSON_AddItemToObject(view_setting, "camera01", camera01); + cJSON_AddItemToObject(camera01, "ip", cJSON_CreateString("47.176.29.11")); + cJSON_AddItemToObject(camera01, "http_port", cJSON_CreateString("80")); + cJSON_AddItemToObject(camera01, "video_port", cJSON_CreateString("80")); + cJSON_AddItemToObject(camera01, "username", cJSON_CreateString("guest")); + cJSON_AddItemToObject(camera01, "password", cJSON_CreateString("GP12345")); + cJSON_AddItemToObject(camera01, "channel_id", cJSON_CreateString("")); + cJSON_AddItemToObject(camera01, "enable_repeat", cJSON_CreateNumber(0)); + cJSON_AddItemToObject(camera01, "camera_name", cJSON_CreateString("")); + cJSON_AddItemToObject(camera01, "obj_max_proportion", cJSON_CreateString(obj_max_proportion->valuestring)); + cJSON_AddItemToObject(camera01, "obj_min_proportion", cJSON_CreateString(obj_min_proportion->valuestring)); + + if (plate_filter_times) + cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); + else + cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString("4")); + + if (plate_filter_time) + cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); + else + cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString("3")); + + if (plate_free_time) + cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); + else + cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString("3")); + + cJSON_AddItemToObject(camera01, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); + cJSON_AddItemToObject(camera01, "enable_face", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(camera01, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); + cJSON_AddItemToObject(camera01, "enable_logo", cJSON_CreateString("No")); + cJSON_AddItemToObject(camera01, "enable_human", cJSON_CreateString("No")); + cJSON_AddItemToObject(camera01, "enable_helmet", cJSON_CreateString("No")); + cJSON_AddItemToObject(camera01, "levenshtein_distance", cJSON_CreateString(levenshtein_distance->valuestring)); + cJSON_AddItemToObject(camera01, "min_characters", cJSON_CreateString(min_characters->valuestring)); + cJSON_AddItemToObject(camera01, "max_characters", cJSON_CreateString(max_characters->valuestring)); + cJSON_AddItemToObject(camera01, "confidence", cJSON_CreateString(confidence->valuestring)); + cJSON_AddItemToObject(camera01, "confidence2", cJSON_CreateString(confidence2->valuestring)); + cJSON_AddItemToObject(camera01, "confidence3", cJSON_CreateString(confidence3->valuestring)); + cJSON_AddItemToObject(camera01, "confidence4", cJSON_CreateString(confidence4->valuestring)); + cJSON_AddItemToObject(camera01, "tab_view_size", cJSON_CreateString("889x500")); + cJSON_AddItemToObject(camera01, "count_zone", cJSON_CreateNumber(viewChannelData[0].count_zone)); + + //printf("\nenable_lpr_db-----9\n"); + if (enable_lpr_db) { + cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString(enable_lpr_db->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString("Yes")); + } + + if (enable_track) { + cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString(enable_track->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString("No")); + } + + if (enable_PTZ) { + cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString(enable_PTZ->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString("No")); + } + + if (ptz_tracking_fov_min) { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString(ptz_tracking_fov_min->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString("0")); + } + + if (ptz_tracking_fov_max) { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString(ptz_tracking_fov_max->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString("40")); + } + + if (ptz_enable_tracking) { + cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString(ptz_enable_tracking->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString("Yes")); + } + + if (ptz_tracking_mode) { + cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString("1")); + } + + if (ptz_tracking_by_enter_zone) { + cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString("Yes")); + } + + if (enable_tracking_limits) { + cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString(enable_tracking_limits->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString("No")); + } + + if (ptz_pan_left_limit) { + cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString(ptz_pan_left_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString("0")); + } + + if (ptz_pan_right_limit) { + cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString(ptz_pan_right_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString("360")); + } + + if (ptz_tilt_up_limit) { + cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString(ptz_tilt_up_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString("0")); + } + + if (ptz_tilt_down_limit) { + cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString(ptz_tilt_down_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString("210")); + } + + if (ptz_speed) { + cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString(ptz_speed->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString("3")); + } + + if (ptz_sensitivity) { + cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString("6")); + } + if (ptz_tracking_resume_dwell) { + cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString(ptz_tracking_resume_dwell->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString("3")); + } + + if (cJSON_enable_only_show_metadata1) { + cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(cJSON_enable_only_show_metadata1->valueint)); + } + else { + cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); + } + + if (enable_downsized_cropped_roi) { + cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); + } + else { + cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(1)); + } + + if (enable_zone_crop_1) { + cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); + } + else { + cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(0)); + } + + if (enable_unknown_object) { + cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString(enable_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString("No")); + } + + if (enable_ivs_person_detection) { + cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString(enable_ivs_person_detection->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString("No")); + } + + if (assign_ivs_object_to) { + cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString(assign_ivs_object_to->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString("")); + } + + if (enable_ambulance) { + cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString(enable_ambulance->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString("No")); + } + + if (enable_blank_plate) { + cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString(enable_blank_plate->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString("No")); + } + + if (enable_stop_sign) { + cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString(enable_stop_sign->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString("No")); + } + + if (enable_show_unknown_object) { + cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString(enable_show_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString("No")); + } + + if (enable_ivs_fix_mode) { + cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString(enable_ivs_fix_mode->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString("No")); + } + + if (enable_ivs_and_ai) { + cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString(enable_ivs_and_ai->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString("No")); + } + + if (enable_add_face_frequent_list) { + cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString("No")); + } + + if (enable_lpr_upon_triggered) { + cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString(enable_lpr_upon_triggered->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString("No")); + } + + if (dwell_lpr_upon_triggered) { + cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString(dwell_lpr_upon_triggered->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString("10")); + } + + if (unknown_object_max_proportion) { + cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString(unknown_object_max_proportion->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString("20")); + } + + if (unknown_object_min_proportion) { + cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString(unknown_object_min_proportion->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString("0")); + } + + if (confidence_unknown_object) { + cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString(confidence_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString("0")); + } + + if (confidence2_unknown_object) { + cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString(confidence2_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString("0")); + } + + if (dwell_unknown_object) { + cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString(dwell_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString("30")); + } + + if (dwell_minute_focus_on) { + cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString(dwell_minute_focus_on->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString("5")); + } + + if (person_obj_fov) { + cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString(person_obj_fov->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString("100")); + } + + if (ivs_mode) { + cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString(ivs_mode->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString("3")); + } + + if (getnetwork_buffer_id) { + cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString(getnetwork_buffer_id->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString("1")); + } + + if (red_light_zone) { + cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString(red_light_zone->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_protect) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString(no_give_way_zone_to_protect->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_keep_away) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString(no_give_way_zone_to_keep_away->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_protect_2) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString(no_give_way_zone_to_protect_2->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_keep_away_2) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(no_give_way_zone_to_keep_away_2->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString("")); + } + + cJSON_AddItemToObject(camera01, "detection_zone", detection_zone); + + for (int index_i = 0; index_i < MAX_DETECTION_ZONE; index_i++) + { + detect = cJSON_CreateObject(); + cJSON_AddItemToArray(detection_zone, detect); + cJSON_AddItemToObject(detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[0][index_i].enable_direction1)); + cJSON_AddItemToObject(detect, "enable_direction2", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "direction1", cJSON_CreateString(viewDetectionZone[0][index_i].direction1)); + cJSON_AddItemToObject(detect, "direction2", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "enable_tripwire", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "enable_traffic_light", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "enable_social_distance", cJSON_CreateString("")); + + cJSON_AddItemToObject(detect, "metadata1", cJSON_CreateString(viewDetectionZone[0][index_i].metadata1)); + cJSON_AddItemToObject(detect, "metadata2", cJSON_CreateString(viewDetectionZone[0][index_i].metadata2)); + cJSON_AddItemToObject(detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[0][index_i].metadata_stop)); + + char str[25] = { 0 }; + sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time); + cJSON_AddItemToObject(detect, "no_parking_time", cJSON_CreateString(str)); + + memset(str, 0x00, sizeof(str)); + sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time_in_minute); + cJSON_AddItemToObject(detect, "no_parking_time_in_minute", cJSON_CreateString(str)); + + memset(str,0x00,sizeof(str)); + sprintf(str, "%d", viewDetectionZone[0][index_i].queuing_count); + + cJSON_AddItemToObject(detect, "queuing_count", cJSON_CreateString(str)); + cJSON_AddItemToObject(detect, "distance_violation_count", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "detection_time", cJSON_CreateString(viewDetectionZone[0][index_i].detection_time)); + cJSON_AddItemToObject(detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[0][index_i].link_to_counter)); + + if (obj_max_proportion_in_zone) + cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_max_proportion_in_zone)); + else { + cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString("80")); + } + + if (obj_min_proportion_in_zone) + cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_min_proportion_in_zone)); + else { + cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString("0")); + } + + if (ptz_zone_to_preset) + cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[0][index_i].ptz_zone_to_preset)); + else { + cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString("0")); + } + + if (enable_speed) + cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_speed)); + else { + cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString("No")); + } + + if (enable_radar_speed) + cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_radar_speed)); + else { + cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString("No")); + } + + if (enable_ivs_zone) + cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[0][index_i].enable_ivs_zone)); + else { + cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString("No")); + } + + if (parking_space) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_space); + cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString("0")); + } + + if (parking_line) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_line); + cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString("0")); + } + + if (set_distance) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp,"%f", viewDetectionZone[0][index_i].set_distance); + cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString("10")); + } + + if (world_distance_unit) + cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_distance_unit)); + else { + cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString("meter")); + } + + if (world_distance_side1) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side1); + cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString("10")); + } + + if (world_distance_side2) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side2); + cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString("10")); + } + + if (world_time_unit) { + cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_time_unit)); + } + else { + cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString("KPH")); + } + + trigger_events = cJSON_CreateArray(); + cJSON_AddItemToObject(detect, "trigger_events", trigger_events); + + for (int index_j = 0; index_j < MAX_TRIGGER_EVENT; index_j++) + { + trigger = cJSON_CreateObject(); + cJSON_AddItemToArray(trigger_events, trigger); + + char str_counter_increment[50] = { 0 }; + if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment==1) { + strcpy(str_counter_increment,"counter_increment_add"); + } + else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == -1) { + strcpy(str_counter_increment, "counter_increment_minus"); + } + else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == 0) { + strcpy(str_counter_increment, "counter_increment_equal"); + } + else { + strcpy(str_counter_increment,""); + } + + cJSON_AddItemToObject(trigger, "checked", cJSON_CreateNumber(viewDetectionZone[0][index_i].trigger_event[index_j].checked)); + + if (index_j == 0) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000001")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Prohibit zone (AIAREA)")); + } + else if (index_j == 1) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000004")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Parking violation (AIAREA/AICAP)")); + } + else if (index_j == 2) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00200000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Allowed list")); + } + else if (index_j == 3) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00400000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Denial list")); + } + else if (index_j == 4) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000008")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Traffic flow (AIFLOW/AICAP)")); + } + else if (index_j == 5) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000010")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn left (AIFLOW)")); + } + else if (index_j == 6) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000020")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn right (AIFLOW)")); + } + else if (index_j == 7) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x10000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Density detection (03AI)")); + } + else if (index_j == 8) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x20000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Missing object detection (01AI)")); + } + else if (index_j == 9) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00800000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Visitor list")); + } + else if (index_j == 10) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x01000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Unattended object or missing object")); + } + else if (index_j == 11) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x02000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("BG learning")); + } + else if (index_j == 12) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x04000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Tampering detection")); + } + else if (index_j == 13) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x40000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("All objects detection")); + } + else if (index_j == 14) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x80000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lack of any object detection")); + } + else if (index_j == 15) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00002000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Over speed detection")); + } + else if (index_j == 16) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00004000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lower speed detection")); + } + else if (index_j == 17) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000400")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Running red lights")); + } + else if (index_j == 18) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000800")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning left on red")); + } + else if (index_j == 19) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00001000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning right on red")); + } + else if (index_j == 20) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00008000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Forget to give way detection")); + } + else if (index_j == 21) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00040000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Distance violation")); + } + else if (index_j == 22) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x08000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Height detection")); + } + + cJSON_AddItemToObject(trigger, "post_event_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].post_event_name)); + cJSON_AddItemToObject(trigger, "counter_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].counter_name)); + cJSON_AddItemToObject(trigger, "counter_increment", cJSON_CreateString(str_counter_increment)); + + } + cJSON_AddItemToObject(detect, "point_number", cJSON_CreateNumber(6)); + cJSON_AddItemToObject(detect, "x1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].x)); + cJSON_AddItemToObject(detect, "y1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].y)); + cJSON_AddItemToObject(detect, "x2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].x)); + cJSON_AddItemToObject(detect, "y2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].y)); + cJSON_AddItemToObject(detect, "x3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].x)); + cJSON_AddItemToObject(detect, "y3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].y)); + cJSON_AddItemToObject(detect, "x4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].x)); + cJSON_AddItemToObject(detect, "y4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].y)); + if (x5 && x6) + { + cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].x)); + cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].y)); + cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].x)); + cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].y)); + } + else + { + cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(579)); + cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(250)); + cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(579)); + cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(100)); + } + } + + cJSON_AddItemToObject(new_data_root, "system_setting", system_setting); + cJSON_AddItemToObject(system_setting, "AI dataset", cJSON_CreateString("")); + cJSON_AddItemToObject(system_setting, "dataset category", cJSON_CreateString("; Total 60 FPS")); + cJSON_AddItemToObject(system_setting, "snapshot folder", cJSON_CreateString("D:\\\\")); + if (language) { + cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString(language->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString("en_gb")); + } + cJSON_AddItemToObject(system_setting, "enable log", cJSON_CreateString("No")); + cJSON_AddItemToObject(system_setting, "auto reconnect", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "auto start", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "enable watchdog", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "enable watchdog UI", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "cpu usage limit", cJSON_CreateString("80")); + cJSON_AddItemToObject(system_setting, "display OSD", cJSON_CreateString("No")); + + if (activeDisplayDash) { + cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString("No")); + } + + if (display_properties) + cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString(display_properties->valuestring)); + else { + cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString("No")); + } + + + cJSON_AddItemToObject(system_setting, "display tracking ID", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "overlap thresh", cJSON_CreateNumber(70)); + cJSON_AddItemToObject(system_setting, "confidence thresh", cJSON_CreateNumber(0)); + cJSON_AddItemToObject(system_setting, "cnn type", cJSON_CreateString("CUDA")); + cJSON_AddItemToObject(system_setting, "cnn device1", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device2", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device3", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device4", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device5", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device6", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device7", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device8", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "whitelist", cJSON_CreateString("No")); + cJSON_AddItemToObject(system_setting, "blacklist", cJSON_CreateString("No")); + + + if (enable_person_independent) { + cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString(enable_person_independent->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString("No")); + } + + if (enable_onvif_profile_m) { + cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString(enable_onvif_profile_m->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString("No")); + } + + if (enable_crop_mode) { + cJSON_AddItemToObject(system_setting, "enable_crop_mode", cJSON_CreateString(enable_crop_mode->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_crop_mode", cJSON_CreateString("Yes")); + } + + if (nms_thres) { + cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString(nms_thres->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString("10")); + } + + if (tracking_id_dwell) { + cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString(tracking_id_dwell->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString("5")); + } + + if (enable_cloud) { + cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString(enable_cloud->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString("No")); + } + + if (enable_special_edition) { + cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString(enable_special_edition->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); + } + + if (enable_python) { + cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString(enable_python->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString("No")); + } + + if (enable_python_file) { + cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString(enable_python_file->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); + } + + if (enable_low_cpu_usage) { + cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString(enable_low_cpu_usage->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString("No")); + } + + if (cloud_enable_snap) { + cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString(cloud_enable_snap->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString("Yes")); + } + + if (cloud_enable_notification) { + cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString(cloud_enable_notification->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString("No")); + } + + if (cloud_account) { + cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString(cloud_account->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString("myaccount@mail.com")); + } + + if (cloud_password) { + cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString(cloud_password->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString("mypass")); + } + + if (cloud_notification_dwell) { + cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString(cloud_notification_dwell->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString("60")); + } + + if (cloud_statue) { + cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString(cloud_statue->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString("")); + } + + if (cloud_v2_statue) { + cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString(cloud_v2_statue->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString("")); + } + + if (cloud_record_v2_statue) { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString(cloud_record_v2_statue->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString("")); + } + + if (enable_special_char) + cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString(enable_special_char->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString("No")); + } + + if (enable_bounding_box) + cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString("Yes")); + } + + if (enable_dwell_bounding_box) + cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString("No")); + } + + if (force_i_to_one) + cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString(force_i_to_one->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString("Yes")); + } + + if (force_o_to_zero) + cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString(force_o_to_zero->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString("Yes")); + } + + if (enable_plate_angle_correction) + cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString(enable_plate_angle_correction->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString("No")); + } + + if (enable_ai_mirror) + cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString(enable_ai_mirror->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString("No")); + } + + if (ai_mirror_feature) + cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString(ai_mirror_feature->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString("0")); + } + + if (enable_cloud_v2) + cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString(enable_cloud_v2->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString("No")); + } + + if (cloud_v2_notification_dwell) + cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(cloud_v2_notification_dwell->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString("60")); + } + + if (cloud_v2_content) + cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString(cloud_v2_content->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); + } + + if (enable_cloud_record_v2) + cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString(enable_cloud_record_v2->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString("No")); + } + + if (cloud_record_v2_notification_dwell) + cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(cloud_record_v2_notification_dwell->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString("60")); + } + + if (cloud_record_v2_content) + cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString(cloud_record_v2_content->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); + } + + if (enable_post_only_if_both_detected) + cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(enable_post_only_if_both_detected->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString("No")); + } + + if (enable_getalarmmotion_snap) + cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(enable_getalarmmotion_snap->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString("No")); + } + + if (getimage_encoder_id) + cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString(getimage_encoder_id->valuestring)); + else + { +#ifdef GY_OS_NOVA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("3")); +#endif +#ifdef GY_OS_AMBA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("4")); +#endif + } + + if (getimage_encoder_id_HD) + cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString(getimage_encoder_id_HD->valuestring)); + else + { +#ifdef GY_OS_NOVA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("0")); +#endif +#ifdef GY_OS_AMBA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("4")); +#endif + } + + if (osd_encoder_id) + cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString(osd_encoder_id->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString("2")); + } + + if (osd_font_size) + cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString(osd_font_size->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString("26")); + } + + if (osd_outline_lilin) + cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString(osd_outline_lilin->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString("4")); + } + + if (enable_osd_bottom) + cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString(enable_osd_bottom->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString("Yes")); + } + + if (osd_bottom_bg_tran) + cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString(osd_bottom_bg_tran->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString("255")); + } + + if (osd_bottom_content) + cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString(osd_bottom_content->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString("Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>")); + } + + if (sensors_type) + cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString(sensors_type->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString("0")); + } + + if (enable_sync_external_lpr_db) + cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(enable_sync_external_lpr_db->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString("No")); + } + + if (external_lpr_db_IP) + cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString(external_lpr_db_IP->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString("192.168.0.200")); + } + + if (external_lpr_db_port) + cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(external_lpr_db_port->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(accountData[0].account_aida_port)); + } + + if (external_lpr_db_username) + cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString(external_lpr_db_username->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString("admin")); + } + + if (external_lpr_db_password) + cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString(external_lpr_db_password->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString("pass")); + } + + if (enable_system_logs) + cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString(enable_system_logs->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString("No")); + } + + if (enable_email_jpeg) + cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString(enable_email_jpeg->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString("Yes")); + } + + if (send_counter_at_specific_hour) + cJSON_AddItemToObject(system_setting, "send_counter_at_specific_hour", cJSON_CreateString(send_counter_at_specific_hour->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "send_counter_at_specific_hour", cJSON_CreateString("NULL")); + } + + if (email_reset_time_interval) + cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString(email_reset_time_interval->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString("")); + } + + if (enable_ftp) + cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString(enable_ftp->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString("No")); + } + + if (ftp_url) + cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString(ftp_url->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString("ftp.example.com")); + } + + if (ftp_port) + cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString(ftp_port->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString("21")); + } + + if (ftp_username) + cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString(ftp_username->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString("")); + } + + if (ftp_password) + cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString(ftp_password->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString("")); + } + + if (ftp_remote_directory) + cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString(ftp_remote_directory->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString("myfolder/myfile")); + } + + + if (ftp_jpeg_file_name_format) + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(ftp_jpeg_file_name_format->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString("fixed")); + } + + + if (ftp_jpeg_file_name) + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString(ftp_jpeg_file_name->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString("snap")); + } + + if (enable_email_notification) + cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString(enable_email_notification->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString("No")); + } + + cJSON_AddItemToObject(new_data_root, "account_setting", account_setting); + cJSON_AddItemToObject(account_setting, "account_data", cJSON_CreateString(account_data->valuestring)); + + cJSON_AddItemToObject(new_data_root, "about_box", about_box); + cJSON_AddItemToObject(about_box, "dataset version", cJSON_CreateString("")); + cJSON_AddItemToObject(about_box, "software version", cJSON_CreateString("2.0.2")); + cJSON_AddItemToObject(about_box, "system id", cJSON_CreateString("")); + cJSON_AddItemToObject(about_box, "NIC name", cJSON_CreateString("AӺ")); + + if(strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") != 0) + { + if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { + if (strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") != 0) { + if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { + + if (strncmp(strUnlockingKey, "face", 4) == 0) { + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + } + else { + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(unlock_key->valuestring)); + } + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_mismatch_the_system_ID")); + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_or_license_mismatch_the_feature_type")); + + + char *filename; + filename = configPATH; + + int del = remove(filename); + if (!del) { + //printf("config is Deleted successfully."); + } + else { + printf("config cannot be Deleted.\n"); + } + + char* JsonString = cJSON_Print(new_data_root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open config.json \n"); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (new_data_root) { + cJSON_Delete(new_data_root); + new_data_root = NULL; + } + new_data_write_to_config_file_flag = 0; + } + + //printf("111-3 get password = %s \n", accountData[0].account_password); + if (new_data_write_to_events_file_flag == 1) { + cJSON *new_data_root, *notification, *event_counter_setting/*,*enable_post*//*,*enable_snmp_post*/,*http_post_events,*a_http_post_event,*event_counters, + *a_event_counter; + cJSON *a_report, *report_counters; + cJSON *a_snmp, *snmp_management; + cJSON *email_setting; + new_data_root = cJSON_CreateObject(); + notification = cJSON_CreateObject(); + event_counter_setting = cJSON_CreateObject(); + email_setting = cJSON_CreateObject(); +; + cJSON_AddItemToObject(new_data_root, "notification", notification); + cJSON_AddItemToObject(new_data_root, "event_counter_setting", event_counter_setting); + cJSON_AddItemToObject(new_data_root, "email_setting", email_setting); + + if(activePostNotification) + cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("Yes")); + else + cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("No")); + + if (activeSNMPPost) + cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("Yes")); + else + cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("No")); + + cJSON_AddItemToObject(notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + cJSON_AddItemToObject(notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); + + cJSON_AddItemToObject(notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); + cJSON_AddItemToObject(notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); + cJSON_AddItemToObject(notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); + + cJSON_AddItemToObject(notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); + cJSON_AddItemToObject(notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); + cJSON_AddItemToObject(notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); + cJSON_AddItemToObject(notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); + cJSON_AddItemToObject(notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); + cJSON_AddItemToObject(notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); + cJSON_AddItemToObject(notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); + cJSON_AddItemToObject(notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); + cJSON_AddItemToObject(notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); + cJSON_AddItemToObject(notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); + cJSON_AddItemToObject(notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); + cJSON_AddItemToObject(notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); + cJSON_AddItemToObject(notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); + cJSON_AddItemToObject(notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); + cJSON_AddItemToObject(notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); + cJSON_AddItemToObject(notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); + cJSON_AddItemToObject(notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); + cJSON_AddItemToObject(notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); + + http_post_events = cJSON_CreateArray(); + cJSON_AddItemToObject(notification, "http_post_events", http_post_events); + + for (int index_http_post = 0; index_http_post < MAX_POST_EVENTS; index_http_post++) { + a_http_post_event = cJSON_CreateObject(); + cJSON_AddItemToArray(http_post_events, a_http_post_event); + + cJSON_AddItemToObject(a_http_post_event, "post_protocol", cJSON_CreateString(postEventList[index_http_post].post_protocol)); + cJSON_AddItemToObject(a_http_post_event, "post_event_method", cJSON_CreateString(postEventList[index_http_post].post_event_method)); + cJSON_AddItemToObject(a_http_post_event, "post_event_name", cJSON_CreateString(postEventList[index_http_post].post_event_name)); + cJSON_AddItemToObject(a_http_post_event, "post_host_ip", cJSON_CreateString(postEventList[index_http_post].post_host_ip)); + cJSON_AddItemToObject(a_http_post_event, "post_host_port", cJSON_CreateString(postEventList[index_http_post].post_host_port)); + cJSON_AddItemToObject(a_http_post_event, "post_url", cJSON_CreateString(postEventList[index_http_post].post_url)); + cJSON_AddItemToObject(a_http_post_event, "post_content_type", cJSON_CreateString("text/html; charset=utf-8")); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)postEventList[index_http_post].post_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)postEventList[index_http_post].post_password, (unsigned char *)buf_account2); + + cJSON_AddItemToObject(a_http_post_event, "post_username", cJSON_CreateString(buf_account)); + cJSON_AddItemToObject(a_http_post_event, "post_password", cJSON_CreateString(buf_account2)); + cJSON_AddItemToObject(a_http_post_event, "post_customized_header", cJSON_CreateString(postEventList[index_http_post].post_customized_header)); + cJSON_AddItemToObject(a_http_post_event, "post_content", cJSON_CreateString(postEventList[index_http_post].post_content)); + cJSON_AddItemToObject(a_http_post_event, "post_sequence", cJSON_CreateString(postEventList[index_http_post].post_sequence)); + cJSON_AddItemToObject(a_http_post_event, "post_file_format", cJSON_CreateString(postEventList[index_http_post].post_file_format)); + cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name_format)); + cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name)); + cJSON_AddItemToObject(a_http_post_event, "post_timeout", cJSON_CreateString(postEventList[index_http_post].post_timeout)); + } + event_counters = cJSON_CreateArray(); + cJSON_AddItemToObject(event_counter_setting, "event_counters", event_counters); + report_counters = cJSON_CreateArray(); + cJSON_AddItemToObject(event_counter_setting, "report_counters", report_counters); + snmp_management = cJSON_CreateArray(); + cJSON_AddItemToObject(event_counter_setting, "snmp_management", snmp_management); + +#ifdef GY_OS_V_SERIES + for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { + a_event_counter = cJSON_CreateObject(); + cJSON_AddItemToArray(event_counters, a_event_counter); + + char str_name[50] = { 0 }; + sprintf(str_name, "Counter0%d", index_event_counter+1); + + cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(str_name)); + cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(str_name)); + cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); + cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString("0")); + cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString("1 minute")); + cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); + cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString("Camera virtual 4")); + cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString("5 minutes")); + cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString("No")); + } + + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + a_report = cJSON_CreateObject(); + cJSON_AddItemToArray(report_counters, a_report); + + cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString("Counter01")); + cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString("Name")); + cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString("1")); + cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString("")); + cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString("")); + cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString("0")); + cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString("")); + cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString("100")); + cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString("0")); + cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString("car_300X300_white")); + cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString("No entry for cars")); + cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString("car_1_300X300_red")); + } + + for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + a_snmp = cJSON_CreateObject(); + cJSON_AddItemToArray(snmp_management, a_snmp); + + + char str_name[50] = { 0 }; + + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(str_name, "SNMP %d", index_snmp + 1); + } + else { + sprintf(str_name, "%s", "Heartbeat"); + } + + cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(str_name)); + cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString("v1")); + cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString("public")); + cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString("192.168.0.200")); + cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString("161")); + cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(".1.3.6.1.2.1.1.6.0")); + cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString("mylocation")); + cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString("string")); + } +#else + for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { + a_event_counter = cJSON_CreateObject(); + cJSON_AddItemToArray(event_counters, a_event_counter); + + char str_reset_value[50] = { 0 }; + sprintf(str_reset_value,"%d", eventCounterList[index_event_counter].reset_value); + + cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_name)); + cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_cust_name)); + cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); + cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString(str_reset_value)); + cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_time_interval)); + cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].reset_time_interval)); + cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); + cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString(eventCounterList[index_event_counter].link_to_post_event_name)); + cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString(eventCounterList[index_event_counter].post_interval)); + cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_only_cloud)); + cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[index_event_counter].enable_linked_to_dwell_time)); + } + + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + a_report = cJSON_CreateObject(); + cJSON_AddItemToArray(report_counters, a_report); + + cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString(reportCounterList[index_report].counter_a)); + cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString(reportCounterList[index_report].counter_a_name)); + cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[index_report].counter_a_zone)); + cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString(reportCounterList[index_report].counter_b)); + cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString(reportCounterList[index_report].counter_b_name)); + cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[index_report].counter_b_zone)); + cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString(reportCounterList[index_report].counter_c_name)); + cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString(reportCounterList[index_report].report_max_value)); + cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString(reportCounterList[index_report].enable_report)); + cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString(reportCounterList[index_report].counter_mode)); + cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString(reportCounterList[index_report].initial_icon)); + cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString(reportCounterList[index_report].detection_output)); + cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString(reportCounterList[index_report].output_icon)); + } + + for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + a_snmp = cJSON_CreateObject(); + cJSON_AddItemToArray(snmp_management, a_snmp); + + cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_event_name)); + cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_version)); + cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_group_name)); + cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_ip)); + cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_port)); + cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_oid)); + cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_value)); + cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_type)); + } +#endif + cJSON_AddItemToObject(email_setting, "email_content", cJSON_CreateString(emailData.email_content)); + + char *filename; + filename = eventsPATH; + + int del = remove(filename); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("events cannot be Deleted.\n"); + } + + char* JsonString = cJSON_Print(new_data_root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open events.json \n"); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (new_data_root) { + cJSON_Delete(new_data_root); + new_data_root = NULL; + } + new_data_write_to_events_file_flag = 0; + } + + //printf("111-2 get password = %s \n", accountData[0].account_password); +#ifdef GY_OS_AMBA + if (new_data_write_to_tof_file_flag == 1) { + cJSON *new_data_root,*new_tof_camera; + + new_data_root = cJSON_CreateObject(); + new_tof_camera = cJSON_CreateObject(); + + cJSON_AddItemToObject(new_data_root, "version", cJSON_CreateNumber(tofData.tof_version)); + cJSON_AddItemToObject(new_data_root, "debug", cJSON_CreateBool(tofData.tof_debug)); + cJSON_AddItemToObject(new_data_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); + cJSON_AddItemToObject(new_data_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); + cJSON_AddItemToObject(new_data_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); + cJSON_AddItemToObject(new_data_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); + + cJSON_AddItemToObject(new_data_root, "distance_options", cJSON_CreateString(tofData.distance_options)); + cJSON_AddItemToObject(new_data_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); + cJSON_AddItemToObject(new_data_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); + cJSON_AddItemToObject(new_data_root, "height_options", cJSON_CreateString(tofData.height_options)); + cJSON_AddItemToObject(new_data_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); + cJSON_AddItemToObject(new_data_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); + + cJSON_AddItemToObject(new_data_root, "ground_x", cJSON_CreateString(tofData.ground_x)); + cJSON_AddItemToObject(new_data_root, "ground_y", cJSON_CreateString(tofData.ground_y)); + + cJSON_AddItemToObject(new_data_root, "camera", new_tof_camera); + + cJSON_AddItemToObject(new_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); + cJSON_AddItemToObject(new_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); + cJSON_AddItemToObject(new_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); + cJSON_AddItemToObject(new_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); + cJSON_AddItemToObject(new_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)tofData.tof_camera_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)tofData.tof_camera_password, (unsigned char *)buf_account2); + + cJSON_AddItemToObject(new_tof_camera, "camera_username", cJSON_CreateString(buf_account)); + cJSON_AddItemToObject(new_tof_camera, "camera_password", cJSON_CreateString(buf_account2)); + + char *filename; + filename = tofPATH; + + int del = remove(filename); + if (!del) { + //printf("tof is Deleted successfully."); + } + else { + printf("tof cannot be Deleted.\n"); + } + + char* JsonString = cJSON_Print(new_data_root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open events.json \n"); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (new_data_root) { + cJSON_Delete(new_data_root); + new_data_root = NULL; + } + new_data_write_to_tof_file_flag = 0; + } +#endif + //20201123 sophia add + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (tof_root) { + cJSON_Delete(tof_root); + tof_root = NULL; + } + if (n_root) { + cJSON_Delete(n_root); + n_root = NULL; + } + if (keyRoot) { + cJSON_Delete(keyRoot); + keyRoot = NULL; + } + + //http_ip_address = (ip_address) ? ip_address : NULL; + //http_http_port = http_port; + + http_sleep_interval = 2; + //http_dataset_version = dataset_version; + //set base time for reload + struct tm* b_time = localtime(&start_time);; + memset(b_time, 0, sizeof(struct tm)); + b_time->tm_hour = 0; // 24 hour format, 0 = midnight, 23 = 11pm + b_time->tm_min = 0; + b_time->tm_sec = 0; + b_time->tm_mon = 0; // 0 based, 0 = jan, 11 = dec + b_time->tm_mday = 1; + b_time->tm_year = 100; // current - 1900 + + //time_t base_time = mktime(b_time); + + //initialize socketRecords + /*for (int i = 0; i < sizeof(socketRecords); i++) + { + socketRecords[i].sock = INVALID_SOCKET; + socketRecords[i].last_recv_time = 0; + }*/ + + int layer_idx = 0; +#ifdef GY_OS_NOVA + cJSON *root_weight,*net_number,*net_info_list,*net_info,*weight_name,*anc_name,*label_name,*feature_type; + root_weight = cJSON_CreateObject(); + net_info_list = cJSON_CreateArray(); + cJSON_AddItemToObject(root_weight, "net_info_list", net_info_list); +#endif + /*for (int i = 0; i < MAX_LAYER_NUM; i++) + { + if (layerUTF8Country[i] != NULL) + { + free(layerUTF8Country[i]); + layerUTF8Country[i] = NULL; + } + + layerUTF8Country[i] = malloc(128); + strcpy(layerUTF8Country[layer_idx], ""); + }*/ + + ///Steven MARK TEMP + ////license keyJP //MAX_IMG_BUFF_SIZE * MAX_CLIENT_SOCKET + + //printf("\nKKKKKKKKKKKKKKKK:1\n"); + /* + printf("\n--------------------\n"); + printf("\nfeatureType: 0x%x\n", featureType); + printf("\nfeatureType2: 0x%x\n", featureType2); + printf("\n--------------------\n");*/ + + //printf("\n--------------------------:5\n"); + + //printf("111-1 get password = %s \n", accountData[0].account_password); + + if (IsExistingWeight(featureType, featureType2)) { + +#ifdef GY_OS_AMBA + //AMBA Weight + if (strcmp(WeightFileModeName, "mod004") == 0) { + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_WGT.aes", "/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_ANC.aes", "/emmc/plugin/Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITHERMAL/GYNet_AITHERMAL_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITHERMAL/AMB_AITHERMAL_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin"); + } + } + + //if (g_check_if_OK_thermal == 1 && g_IsPTZDevice == 1) + if(g_dual_sensor == 1) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + } + } + else { + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + else { + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { + featureType = featureType | FEATURE_TRAF_DET; + featureType2 = featureType2 | FEATURE_AICAP; + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + g_IsHelm_without_car = 1; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + (strcmp(WeightFileModeName, "mod003") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK)) { + featureType = featureType | FEATURE_TRAF_DET; + featureType2 = featureType2 | FEATURE_AIFLOW; + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + g_IsHelm_without_car = 1; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + } + } + //AMBA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_WGT.aes", "/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_ANC.aes", "/emmc/plugin/Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGARBAGE/GYNet_AIGARBAGE_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGARBAGE/AMB_AIGARBAGE_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_LOGO) == FEATURE_LPR_LOGO) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_WGT.aes", "/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin", key, 0, false); + + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_ANC.aes", "/emmc/plugin/Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AICarMake/GYNet_LOGO_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AICarMake/AMB_LOGO_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_LOGO; + layerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_LOGO; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE /*&& (featureType2 & FEATURE_DET_AIFIRE) == FEATURE_DET_AIFIRE*/) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_WGT.aes", "/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_ANC.aes", "/emmc/plugin/Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFIRE/GYNet_AIFIRE_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFIRE/AMB_AIFIRE_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_AIFIRE; + layerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIFIRE; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_WGT.aes", "/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_ANC.aes", "/emmc/plugin/Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAERO/GYNet_AIAERO_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAERO/AMB_AIAERO_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREO; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREO; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) ///Steven TEMP MARK FEATURE_HUM_DET + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_WGT.aes", "/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_ANC.aes", "/emmc/plugin/Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISAFTY/GYNet_AISAFTY_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISAFTY/AMB_AISAFTY_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIHELM; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIHELM; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) ///Steven TEMP MARK FEATURE_HUM_DET + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_WGT.aes", "/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_ANC.aes", "/emmc/plugin/Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRAILWAY/GYNet_AIRAILWAY_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRAILWAY/AMB_AIRAILWAY_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_AIRAIL; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIRAIL; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) ///Steven TEMP MARK FEATURE_HUM_DET + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_WGT.aes", "/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_ANC.aes", "/emmc/plugin/Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISPORTS/GYNet_AISPORTS_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISPORTS/AMB_AISPORTS_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AISPORTS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISPORTS; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_WGT.aes", "/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_ANC.aes", "/emmc/plugin/Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIHUMAN/GYNet_Human_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIHUMAN/AMB_Human_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin"); + } + } + else { + LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_WGT.aes", "/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_ANC.aes", "/emmc/plugin/Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGENDER/GYNet_AIGENDER_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGENDER/AMB_AIGENDER_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin"); + } + } + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIMASK; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIMASK; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + if (layer_idx < MAX_LAYER_NUM) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_WGT.aes", "/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_ANC.aes", "/emmc/plugin/Aida/AIAML/anchors_GYNet_AIAML_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAML/anchors_GYNet_AIAML_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAML/GYNet_AIAML_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAML/AMB_AIAML_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin"); + } + } + else { + LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_WGT.aes", "/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_ANC.aes", "/emmc/plugin/Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFRONTBACK/GYNet_AIFRONTBACK_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFRONTBACK/AMB_AIFRONTBACK_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin"); + } + } + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAML; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAML; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_WGT.aes", "/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_ANC.aes", "/emmc/plugin/Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISHIP/GYNet_AISHIP_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISHIP/AMB_AISHIP_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AISHIP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISHIP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_WGT.aes", "/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_ANC.aes", "/emmc/plugin/Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIPRODUCTION/GYNet_AIPRODUCTION_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIPRODUCTION/AMB_AIPRODUCTION_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_TWN\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/AMB_ANPR_TWN_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR)//20201216 Jim add + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_EUR\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/AMB_ANPR_EUR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA || + (featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM || + (featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_SEA\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/AMB_ANPR_SEA_VER.txt,"); + + if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) { + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + else if ((featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM) { + layerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + else if ((featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) { + layerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA)//20201216 Jim add + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_MEA\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/AMB_ANPR_MEA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_USA\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/AMB_ANPR_USA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_GBR\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/AMB_ANPR_GBR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/AMB_ANPR_JPN_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/AMB_ANPR_THA_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_BGD) == FEATURE_LPR_BGD) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_LPD_Label_BGD.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_OCR_Label_BGD.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRBGD/AMB_ANPR_BGD_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/AMB_ANPR_PHL_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_CNT) == FEATURE_LPR_CNT) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_LPD_Label_CNT.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_OCR_Label_CNT.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRCNT/AMB_ANPR_CNT_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/AMB_ANPR_AUS_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin"); + } + } + } + //AMBA Weight + if (g_IsToFDevice == 1) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_WGT.aes", "/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_ANC.aes", "/emmc/plugin/Aida/AITOF/anchors_GYNet_AITOF_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITOF/anchors_GYNet_AITOF_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITOF/GYNet_AITOF_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITOF/AMB_AITOF_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AITOF; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AITOF; + stAMBAcontent.tiny_enable[layer_idx] = 1; + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin"); + } + } + + } + //AMBA Weight + if (g_IsRadarDevice == 1) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRADAR/GYNet_Radar_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRADAR/AMB_AIRADAR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIRADAR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIRADAR; + // stAMBAcontent.tiny_enable[layer_idx] = 1; // Radar ??????n YOLO + layer_idx++; + } + } +#endif + +#ifdef GY_OS_NOVA + //NOVA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + if (layer_idx < MAX_LAYER_NUM) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt")); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/NOV_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIFLOW)); + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIAREA)); + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AICAP)); + } + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/NOV_ANPR_TWN_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_LPD_Label_USA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_OCR_Label_USA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/NOV_ANPR_USA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + layerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + layerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/NOV_ANPR_PHL_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_LPD_Label_THA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_OCR_Label_THA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/NOV_ANPR_THA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + layerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + layerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/NOV_ANPR_SEA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/NOV_ANPR_MEA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_LPD_Label_EUR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_OCR_Label_EUR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/NOV_ANPR_EUR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/NOV_ANPR_GBR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/NOV_ANPR_JPN_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/NOV_ANPR_AUS_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + } +#endif + } + +#ifdef GY_OS_NOVA + cJSON_AddItemToObject(root_weight, "net_number", cJSON_CreateNumber(layer_idx)); + + char * JsonString_weight = cJSON_PrintUnformatted(root_weight); + //(Nova: ͦv]w nova_driver_valid_weight.txt) + write_driver_setting_file(JsonString_weight); + + if (JsonString_weight != NULL) { + free(JsonString_weight); + JsonString_weight = NULL; + } + + if (root_weight) { + cJSON_Delete(root_weight); + root_weight = NULL; + } + + if (IsExistingWeight(featureType, featureType2)) + { + pthread_t NOVA_detection/*, NOVA_listener, NOVA_listener_image*/; + pthread_create(&NOVA_detection, 0, RUN_NOVA_DETECTION, NULL); //A11en create pthread to run detection + printf("\n==== Gynet create nova_driver ====\n"); + } +#endif + + /* + printf("\n--------------------\n"); + printf("\nfeatureType: 0x%x\n", featureType); + printf("\nfeatureType2: 0x%x\n", featureType2); + printf("\n--------------------\n"); + */ + + //printf("333 get password = %s \n", accountData[0].account_password); +#ifdef GY_OS_AMBA + //Third party weight + //printf("td_weight_num: %d \n", td_weight_num); + + //printf("\n---------------key:%s\n",key); + //printf("\n---------------mykey_custom:%s\n", mykey_custom); + //printf("\n---------------first_half_char_key:%s\n", first_half_char_key); + if(check_if_correct_mail == 1 && g_match_mac == 1) + { + for (int read_td_weight_idx = 0; read_td_weight_idx < td_weight_num; read_td_weight_idx++) + { + if (layer_idx < MAX_LAYER_NUM) + { + char ori_weight_name[MAX_MSG_LEN] = { 0 }; + strcpy(ori_weight_name,"/emmc/plugin/Aida"); + strcat(ori_weight_name, td_weight_info[read_td_weight_idx].weight_name); + + char new_weight_name[MAX_MSG_LEN] = { 0 }; + strcpy(new_weight_name, "/emmc/plugin/Aida"); + strcat(new_weight_name, td_weight_info[read_td_weight_idx].weight_name); + new_weight_name[strlen(new_weight_name) - 3] = 'b'; + new_weight_name[strlen(new_weight_name) - 2] = 'i'; + new_weight_name[strlen(new_weight_name) - 1] = 'n'; + + //printf("\n-------------new_weight_name:%s\n", new_weight_name); + if (td_weight_info[read_td_weight_idx].is_encryption == 1) { + LILIN_File_Decryption(ori_weight_name, new_weight_name, first_half_char_key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, new_weight_name); + } + else + strcat(stAMBAcontent.sz_amba_NetworkNames, ori_weight_name); + strcat(stAMBAcontent.sz_amba_NetworkNames, ","); + + + char ori_anchor_name[MAX_MSG_LEN] = { 0 }; + strcpy(ori_anchor_name, "/emmc/plugin/Aida"); + strcat(ori_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); + + char new_anchor_name[MAX_MSG_LEN] = { 0 }; + strcpy(new_anchor_name, "/emmc/plugin/Aida"); + strcat(new_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); + new_anchor_name[strlen(new_anchor_name) - 3] = 't'; + new_anchor_name[strlen(new_anchor_name) - 2] = 'x'; + new_anchor_name[strlen(new_anchor_name) - 1] = 't'; + + //printf("\n-------------new_anchor_name:%s\n", new_anchor_name); + if (td_weight_info[read_td_weight_idx].is_encryption == 1) { + LILIN_File_Decryption(ori_anchor_name, new_anchor_name, first_half_char_key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, new_anchor_name); + } + else + strcat(stAMBAcontent.sz_amba_anchor_fileNames, ori_anchor_name); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, ","); + + char ori_label_name[MAX_MSG_LEN] = { 0 }; + strcpy(ori_label_name, "/emmc/plugin/Aida"); + strcat(ori_label_name, td_weight_info[read_td_weight_idx].label_name); + + //printf("\n-------------ori_label_name:%s\n", ori_label_name); + + strcat(stAMBAcontent.sz_amba_label_fileNames, ori_label_name); + strcat(stAMBAcontent.sz_amba_label_fileNames, ","); + + layerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; + stAMBAcontent.tiny_enable[layer_idx] = 1; + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0(new_weight_name); + } + } + } + } +#endif + + //printf("\n%s\n", stAMBAcontent.sz_amba_ver_fileNames); + +#ifdef TEST_DETECTOR_MEM + //즹Ou|j1304 + + //printf("\n--------------------------:6\n"); + test_detector_mem(NULL, cnn_type, stAMBAcontent.sz_amba_NetworkNames, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, custom_cpu_library, custom_cldnn, performance_counter, nIsHardwareOK); +#endif + } + else + { + printf("\n****************\n"); + printf("No License Key"); + printf("\n****************\n"); + + //Slicense key٬O|Bhttp server, iH/serverdߦAA + //http_ip_address = (ip_address) ? ip_address : NULL; + + //http_http_port = http_port; + licenseType = _TRIAL_LICENSE_FPS06; + + +#ifdef TEST_DETECTOR_MEM + test_detector_mem(NULL, cnn_type, NULL, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, NULL, NULL, performance_counter, nIsHardwareOK); +#endif + }/// if (fe && li && st && et && id) + } + else + printf("config.json parse FAIL.\n"); + } + } + else + printf("-http_port %d not found!\n", http_port); + + //printf("999 get password = %s \n", accountData[0].account_password); + + printf("\n[run_server] end\n"); +} + +void getCameraPlugInInfo() { + //printf("\n---------------get Camera PlugIn Info start\n"); + char filename[1024] = { 0 }; + strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + cJSON *description; + description = cJSON_GetObjectItem(plugin, "description"); + + if (description) { + if (strstr(description->valuestring, "LILIN") != NULL) { + //printf("\n---------------get Camera PlugIn Info 1\n"); + g_check_if_no_brand = 0; + } + else { + //printf("\n---------------get Camera PlugIn Info 2\n"); + g_check_if_no_brand = 1; + } + } + else { + //printf("\n---------------get Camera PlugIn Info 3\n"); + g_check_if_no_brand = 0; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + //printf("\n---------------get Camera PlugIn Info end\n"); +} + +long getCurrentTime() { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + +static int CheckIsExistingWeight = 1; +int IsExistingWeight(size_t featureType, size_t featureType2) +{ + int nHasFeature = 0; + int count_weight = 0; + +#ifdef GY_OS_AMBA + if (strcmp(WeightFileModeName, "mod004") == 0) + { + if (weightfileList[30].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[30].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + CheckIsExistingWeight = 0; + } + } + else +#endif + { + if (weightfileList[15].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { +#ifdef GY_OS_V_SERIES + if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + } +#else + nHasFeature = 1; + count_weight++; +#endif + + CheckIsExistingSpeed = 1; + } + else if (weightfileList[15].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + CheckIsExistingWeight = 0; + } + } + + if (weightfileList[27].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[27].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[28].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[28].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[11].enable_weight_to_run == 1 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[11].enable_weight_to_run == 0 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[13].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[13].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[22].enable_weight_to_run == 1 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[22].enable_weight_to_run == 0 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + CheckIsExistingWeight = 0; + } + + if (weightfileList[23].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[23].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) { + CheckIsExistingWeight = 0; + } + + if (strcmp(WeightFileModeName, "mod003") != 0) { + if (weightfileList[12].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[12].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + CheckIsExistingWeight = 0; + } + } + else { + if (weightfileList[25].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[25].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + CheckIsExistingWeight = 0; + } + } + + if (weightfileList[14].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[14].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[26].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[26].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + CheckIsExistingWeight = 0; + } + + if (strcmp(WeightFileModeName, "mod003") != 0) { + if (weightfileList[0].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[0].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + CheckIsExistingWeight = 0; + } + } + else { + if (weightfileList[29].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[29].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + CheckIsExistingWeight = 0; + } + } + + if ((featureType & FEATURE_AIFISHTRAF) == FEATURE_AIFISHTRAF) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_POK_DET) != 0) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_HUM_POS) != 0) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_LED_DGT) != 0) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_SHOES_DET) != 0) + { + CheckIsExistingWeight = 0; + } + if (weightfileList[10].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_LOGO) != 0) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[10].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_LOGO) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[7].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_TWN) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[7].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_TWN) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[1].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_EUR) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[1].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_EUR) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_SEA) != 0) || + (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) || + (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0)) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if ((weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_SEA) != 0) || + (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) || + (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0)) + { + CheckIsExistingWeight = 0; + } + +#if 0 + if (weightfileList[9].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[9].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) + { + CheckIsExistingWeight = 0; + } +#endif + + /* + if ((featureType & FEATURE_LPR_CNA) != 0) + { + CheckIsExistingWeight = 0; + }*/ + + if (weightfileList[17].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_MEA) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[17].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_MEA) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[19].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_AUS) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[19].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_AUS) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[8].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_USA) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if(weightfileList[8].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_USA) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[2].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_GBR) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[2].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_GBR) != 0) + { + CheckIsExistingWeight = 0; + } + +#if 0 + if (weightfileList[24].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[24].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0) + { + CheckIsExistingWeight = 0; + } +#endif + + if (weightfileList[3].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_JPN) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[3].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_JPN) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((featureType & FEATURE_LPR_IND) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[6].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_THA) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[6].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_THA) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((featureType & FEATURE_LPR_LAO) != 0) + { + CheckIsExistingWeight = 0; + } + if (weightfileList[16].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_BGD) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[16].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_BGD) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[4].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_PHL) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[4].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_PHL) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[18].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_CNT) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[18].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_CNT) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + featureType2 == FEATURE_EMPTY) + { + CheckIsExistingWeight = 0; + } + + if (g_IsCustomWeight == 1) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + + if (weightfileList[20].enable_weight_to_run == 1 && g_IsRadarDevice == 1) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[20].enable_weight_to_run == 0 && g_IsRadarDevice == 1) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[21].enable_weight_to_run == 1 && g_IsToFDevice == 1) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if(weightfileList[21].enable_weight_to_run == 0 && g_IsToFDevice == 1){ + CheckIsExistingWeight = 0; + } + + if (unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 1) { + nHasFeature = 1; + count_weight++; + } + else if(unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 0){ + CheckIsExistingWeight = 0; + } + + if (count_weight >= 2) { +#ifdef GY_OS_NOVA + CheckIsExistingWeight = 0; +#endif + } + + return (CheckIsExistingWeight) > 0 && nHasFeature == 1 ? 1 : 0; +} +void RefreshCheckExistingWeight() +{ + CheckIsExistingWeight = 1; +} +#ifdef GY_OS_AMBA +void cavalry_gen_sdk_3_0(char * bin_name) { + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "/usr/local/bin/cavalry_gen -f %s -t /emmc/plugin/Aida/temp.bin -V 2.2.8.3", bin_name); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "cp /emmc/plugin/Aida/temp.bin %s", bin_name); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -f /emmc/plugin/Aida/temp.bin"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } +} +#endif + +void initial_weight_settings() { + //|ھڳ]wɡAإvO_Ұ + strcpy(weightfileList[0].weight_repository, "AIAML"); + strcpy(weightfileList[1].weight_repository, "AIANPREUR"); + strcpy(weightfileList[2].weight_repository, "AIANPRGBR"); + strcpy(weightfileList[3].weight_repository, "AIANPRJPN"); + strcpy(weightfileList[4].weight_repository, "AIANPRPHL"); + strcpy(weightfileList[5].weight_repository, "AIANPRSEA"); + strcpy(weightfileList[6].weight_repository, "AIANPRTHA"); + strcpy(weightfileList[7].weight_repository, "AIANPRTWN"); + strcpy(weightfileList[8].weight_repository, "AIANPRUSA"); + strcpy(weightfileList[9].weight_repository, "AIANPRVNM"); + strcpy(weightfileList[10].weight_repository, "AICarMake"); + strcpy(weightfileList[11].weight_repository, "AIFIRE"); + strcpy(weightfileList[12].weight_repository, "AIHUMAN"); + strcpy(weightfileList[13].weight_repository, "AISAFTY"); + strcpy(weightfileList[14].weight_repository, "AISHIP"); + strcpy(weightfileList[15].weight_repository, "AITRAFFIC"); + strcpy(weightfileList[16].weight_repository, "AIANPRBGD"); + strcpy(weightfileList[17].weight_repository, "AIANPRMEA"); + strcpy(weightfileList[18].weight_repository, "AIANPRCNT"); + strcpy(weightfileList[19].weight_repository, "AIANPRAUS"); + strcpy(weightfileList[20].weight_repository, "AIRADAR"); // Ken 2022-10-13 + strcpy(weightfileList[21].weight_repository, "AITOF"); + strcpy(weightfileList[22].weight_repository, "AIRAILWAY"); + strcpy(weightfileList[23].weight_repository, "AISPORTS"); + strcpy(weightfileList[24].weight_repository, "AIANPRIDN"); + strcpy(weightfileList[25].weight_repository, "AIGENDER"); + strcpy(weightfileList[26].weight_repository, "AIPRODUCTION"); + strcpy(weightfileList[27].weight_repository, "AIGARBAGE"); + strcpy(weightfileList[28].weight_repository, "AIAERO"); + strcpy(weightfileList[29].weight_repository, "AIFRONTBACK"); + strcpy(weightfileList[30].weight_repository, "AITHERMAL"); + + for (size_t index_weightfile = 0; index_weightfile < MAX_WEIGHT_FILE_LIST; index_weightfile++) { + weightfileList[index_weightfile].enable_weight_to_run = 0; + } + + char c_file_name_weight_setting[1024] = { 0 }; + strcpy(c_file_name_weight_setting, "/emmc/plugin/Aida_data/weight_setting.json"); + + if (!FileExist(c_file_name_weight_setting) || ReadFileSize(c_file_name_weight_setting) == 0) + { + printf("weight_setting file doesn't exist.\n"); + cJSON *s_root = cJSON_CreateObject(); + cJSON_AddItemToObject(s_root, "mode_name", cJSON_CreateString("mode_err")); + //AIAML,AIANPREUR,AIANPRGBR,AIANPRJPN,AIANPRPHL,AIANPRSEA,AIANPRTHA,AIANPRTWN,AIANPRUSA,AIANPRVNM,AICarMake,AIFIRE,AIHUMAN,AISAFTY,AISHIP,AITRAFFIC + cJSON_AddItemToObject(s_root, "mode_repository", cJSON_CreateString("")); + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(c_file_name_weight_setting, "w"); + if (f == NULL) + { + printf("Error opening setting file!\n"); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (s_root) { + free(s_root); + s_root = NULL; + } + } + + cJSON* root_weight_setting, *mode_name, *mode_repository; + + if (!FileExist(c_file_name_weight_setting)) + { + printf("%s doesn't exist.\n", c_file_name_weight_setting); + } + else + { + char* fileBuf_weight_setting = ReadAllBytes(c_file_name_weight_setting); + if (fileBuf_weight_setting) { + root_weight_setting = cJSON_Parse(fileBuf_weight_setting); + + if (fileBuf_weight_setting) { + free(fileBuf_weight_setting); + fileBuf_weight_setting = NULL; + } + mode_name = cJSON_GetObjectItem(root_weight_setting, "mode_name"); + mode_repository = cJSON_GetObjectItem(root_weight_setting, "mode_repository"); + + strcpy(WeightFileModeName, mode_name->valuestring); + char temp_buf_mode_repository[1024] = { 0 }; + strcpy(temp_buf_mode_repository, mode_repository->valuestring); + + if (strstr(temp_buf_mode_repository, "AIAML") != NULL) { + weightfileList[0].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPREUR") != NULL) { + weightfileList[1].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRGBR") != NULL) { + weightfileList[2].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRJPN") != NULL) { + weightfileList[3].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRPHL") != NULL) { + weightfileList[4].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRSEA") != NULL) { + weightfileList[5].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRTHA") != NULL) { + weightfileList[6].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRTWN") != NULL) { + weightfileList[7].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRUSA") != NULL) { + weightfileList[8].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRVNM") != NULL) { + weightfileList[9].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AICarMake") != NULL) { + weightfileList[10].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIFIRE") != NULL) { + weightfileList[11].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIHUMAN") != NULL) { + weightfileList[12].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AISAFTY") != NULL) { + weightfileList[13].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AISHIP") != NULL) { + weightfileList[14].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AITRAFFIC") != NULL) { + weightfileList[15].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRBGD") != NULL) { + weightfileList[16].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRMEA") != NULL) { + weightfileList[17].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRCNT") != NULL) { + weightfileList[18].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRAUS") != NULL) { + weightfileList[19].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIRADAR") != NULL) { + weightfileList[20].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AITOF") != NULL) { + weightfileList[21].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIRAILWAY") != NULL) { + weightfileList[22].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AISPORTS") != NULL) { + weightfileList[23].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIANPRIDN") != NULL) { + weightfileList[24].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIGENDER") != NULL) { + weightfileList[25].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIPRODUCTION") != NULL) { + weightfileList[26].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIGARBAGE") != NULL) { + weightfileList[27].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIAERO") != NULL) { + weightfileList[28].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIFRONTBACK") != NULL) { + weightfileList[29].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AITHERMAL") != NULL) { + weightfileList[30].enable_weight_to_run = 1; + } + + if (root_weight_setting) { + cJSON_Delete(root_weight_setting); + root_weight_setting = NULL; + } + } + } +} + +void file_management() { + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; +#ifdef GY_OS_NOVA + char config_smallPATH[1024] = { 0 }; +#endif + char config_installPATH[1024] = { 0 }; + +#ifdef GY_OS_NOVA + char config_small_installPATH[1024] = { 0 }; +#endif + char config_bakPATH[1024] = { 0 }; + + char events_installPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + char events_bakPATH[1024] = { 0 }; + + char tof_installPATH[1024] = { 0 }; + char tofPATH[1024] = { 0 }; + char tof_bakPATH[1024] = { 0 }; + + char emails_installPATH[1024] = { 0 }; + char emailsPATH[1024] = { 0 }; + char emails_bakPATH[1024] = { 0 }; + + char cold_objects_installPATH[1024] = { 0 }; + char cold_objectsPATH[1024] = { 0 }; + + char face_installPATH[1024] = { 0 }; + char facePATH[1024] = { 0 }; + + char db_fflprPATH[1024] = { 0 }; + char db_fflpr_installPATH[1024] = { 0 }; + char db_fflpr_bakPATH[1024] = { 0 }; + + char db_facePATH[1024] = { 0 }; + char db_face_installPATH[1024] = { 0 }; + char db_face_bakPATH[1024] = { 0 }; + + char face_license_PATH[1024] = { 0 }; + char face_license_installPATH[1024] = { 0 }; + char face_license_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_smallPATH, exePath); +#endif + strcpy(config_installPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_small_installPATH, exePath); +#endif + strcpy(config_bakPATH, exePath); + + strcpy(eventsPATH, exePath); + strcpy(events_installPATH, exePath); + strcpy(events_bakPATH, exePath); + + strcpy(tofPATH, exePath); + strcpy(tof_installPATH, exePath); + strcpy(tof_bakPATH, exePath); + + strcpy(emailsPATH, exePath); + strcpy(emails_installPATH, exePath); + strcpy(emails_bakPATH, exePath); + + strcpy(cold_objectsPATH, exePath); + strcpy(cold_objects_installPATH, exePath); + + strcpy(facePATH, exePath); + strcpy(face_installPATH, exePath); + + strcpy(db_fflprPATH, exePath); + strcpy(db_fflpr_installPATH, exePath); + strcpy(db_fflpr_bakPATH, exePath); + + strcpy(db_facePATH, exePath); + strcpy(db_face_installPATH, exePath); + strcpy(db_face_bakPATH, exePath); + + strcpy(face_license_PATH, exePath); + strcpy(face_license_installPATH, exePath); + strcpy(face_license_bakPATH, exePath); + + strcat(configPATH, "config.json"); +#ifdef GY_OS_NOVA + strcat(config_smallPATH, "config_small.json"); +#endif + strcat(config_installPATH, "config_install.json"); + +#ifdef GY_OS_NOVA + strcat(config_small_installPATH, "config_small_install.json"); +#endif + strcat(config_bakPATH, "config_bak.json"); + + strcat(eventsPATH, "events.json"); + strcat(events_installPATH, "events_install.json"); + strcat(events_bakPATH, "events_bak.json"); + + strcat(tofPATH, "tof.json"); + strcat(tof_installPATH, "tof_install.json"); + strcat(tof_bakPATH, "tof_bak.json"); + + strcat(emailsPATH, "emails.json"); + strcat(emails_installPATH, "emails_install.json"); + strcat(emails_bakPATH, "emails_bak.json"); + + strcat(cold_objectsPATH, "cold_objects.json"); + strcat(cold_objects_installPATH, "cold_objects_install.json"); + + strcat(facePATH, "sfe/iengine.lic"); + strcat(face_installPATH, "sfe/iengine_install.lic"); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + strcat(db_fflprPATH, "db_fflpr.db"); + strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); + + strcat(db_facePATH, "db_face.db"); + strcat(db_face_installPATH, "db_face_install_2.db"); + +#endif + + //T{config_bak.jsonSa + { + char* fileBuf = ReadAllBytes(config_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("config_bakPATH parse FAIL.0\n"); + + if (FileExist(config_bakPATH)) { + int del = unlink(config_bakPATH); + if (!del) { + //printf("config_bakPATH is Deleted successfully."); + } + else { + printf("config_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) >= 20000) + { + //CopyFileTo(configPATH, config_bakPATH); + CopyFileTo(config_bakPATH, configPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bak to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + else if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) < 20000) + { + int del = remove(config_bakPATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("config_bak cannot be Deleted.\n"); + } + } + + //T{config.jsonSa + { + char* fileBuf = ReadAllBytes(configPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("configPATH parse FAIL.0\n"); + + if (FileExist(config_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bakPATH to main_0 config <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(config_bakPATH, configPATH); + } + else { + if (FileExist(configPATH)) { + int del = unlink(configPATH); + if (!del) { + //printf("configPATH is Deleted successfully."); + } + else { + printf("configPATH cannot be Deleted.\n"); + } + } + } + } + } + } + + //T{events_bak.jsonSa + { + char* fileBuf = ReadAllBytes(events_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("events_bakPATH parse FAIL.0\n"); + + if (FileExist(events_bakPATH)) { + int del = unlink(events_bakPATH); + if (!del) { + //printf("config_bakPATH is Deleted successfully."); + } + else { + printf("events_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) >= 8000) + { + CopyFileTo(events_bakPATH, eventsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bak to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + else if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) < 8000) + { + int del = remove(events_bakPATH); + if (!del) { + //printf("events_bak is Deleted successfully."); + } + else { + printf("events_bak cannot be Deleted.\n"); + } + } + + //T{events.jsonSa + { + char* fileBuf = ReadAllBytes(eventsPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("eventsPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("eventsPATH parse FAIL.0\n"); + + if (FileExist(events_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(events_bakPATH, eventsPATH); + } + else { + if (FileExist(events_bakPATH)) { + int del = unlink(events_bakPATH); + if (!del) { + //printf("events_bakPATH is Deleted successfully."); + } + else { + printf("events_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + } + + //T{tof_bak.jsonSa + { + char* fileBuf = ReadAllBytes(tof_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("tof_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("tof_bakPATH parse FAIL.0\n"); + + if (FileExist(tof_bakPATH)) { + int del = unlink(tof_bakPATH); + if (!del) { + //printf("tof_bakPATH is Deleted successfully."); + } + else { + printf("tof_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) >= 250) + { + CopyFileTo(tof_bakPATH, tofPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bak to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + else if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) < 250) + { + int del = remove(tof_bakPATH); + if (!del) { + //printf("tof_bak is Deleted successfully."); + } + else { + printf("tof_bak cannot be Deleted.\n"); + } + } + + //T{tof.jsonSa + { + char* fileBuf = ReadAllBytes(tofPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("eventsPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("tofPATH parse FAIL.0\n"); + + if (FileExist(tof_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bakPATH to main_0 tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(tof_bakPATH, tofPATH); + } + else { + if (FileExist(tof_bakPATH)) { + int del = unlink(tof_bakPATH); + if (!del) { + //printf("tof_bakPATH is Deleted successfully."); + } + else { + printf("tof_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + } + + //T{emails_bak.jsonSa + { + char* fileBuf = ReadAllBytes(emails_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("emails_bakPATH parse FAIL.0\n"); + + if (FileExist(emails_bakPATH)) { + int del = unlink(emails_bakPATH); + if (!del) { + //printf("emails_bakPATH is Deleted successfully."); + } + else { + printf("emails_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + //T{emails.jsonSa + { + char* fileBuf = ReadAllBytes(emailsPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("eventsPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("emailsPATH parse FAIL.0\n"); + + if (FileExist(emails_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_bakPATH to main_0 emails <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(emails_bakPATH, emailsPATH); + } + else { + if (FileExist(emails_bakPATH)) { + int del = unlink(emails_bakPATH); + if (!del) { + //printf("emails_bakPATH is Deleted successfully."); + } + else { + printf("emails_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + } +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //T{OOupdate LPKGApGOhRªdbAHŦXsdb榡C + { + char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; + if (FileExist(NEW_UPDATE_PATH)) { + int del = unlink(NEW_UPDATE_PATH); + if (!del) { + //printf("txt is Deleted successfully."); + } + else { + printf("NEW UPDATE PATH cannot be Deleted.\n"); + } + + /*char DB_FFLPR_PATH[1024] = "/emmc/plugin/Aida_data/db_fflpr.db"; + if (FileExist(DB_FFLPR_PATH)) { + int del = unlink(DB_FFLPR_PATH); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("DB FFLPR PATH cannot be Deleted.\n"); + } + }*/ + + + char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; + if (FileExist(DB_FACE_PATH)) { + int del = unlink(DB_FACE_PATH); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("DB FACE PATH cannot be Deleted.\n"); + } + } + + delete_file("/emmc/plugin/Aida_data/sfe/storage/entities.rec"); + delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.map"); + delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.rec"); + delete_file("/emmc/plugin/Aida_data/sfe/storage/labels.rec"); + + } + } + + { //face db + char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; + if (FileExist(NEW_UPDATE_PATH)) { + int del = unlink(NEW_UPDATE_PATH); + if (!del) { + //printf("txt is Deleted successfully."); + } + else { + printf("NEW UPDATE PATH cannot be Deleted.\n"); + } + + char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; + if (FileExist(DB_FACE_PATH)) { + int del = unlink(DB_FACE_PATH); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("DB FACE PATH cannot be Deleted.\n"); + } + } + } + } +#endif + if (FileExist(config_installPATH) == 1 && (FileExist(configPATH) == 0 || ReadFileSize(configPATH) == 0)) { + CopyFileTo(config_installPATH, configPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(config_installPATH) == 1 && (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) == 0)) { + CopyFileTo(config_installPATH, config_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to back config <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + +#ifdef GY_OS_NOVA + if (FileExist(config_small_installPATH) == 1 && (FileExist(config_smallPATH) == 0 || ReadFileSize(config_smallPATH) == 0)) { + CopyFileTo(config_small_installPATH, config_smallPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_small_installPATH to main config_small <<<<<<<<<<<<<<<<<<<<<<<\n"); + } +#endif + + if (FileExist(events_installPATH) == 1 && (FileExist(eventsPATH) == 0 || ReadFileSize(eventsPATH) == 0)) { + CopyFileTo(events_installPATH, eventsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(events_installPATH) == 1 && (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) == 0)) { + CopyFileTo(events_installPATH, events_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to back events <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(tof_installPATH) == 1 && (FileExist(tofPATH) == 0 || ReadFileSize(tofPATH) == 0)) { + CopyFileTo(tof_installPATH, tofPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(tof_installPATH) == 1 && (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) == 0)) { + CopyFileTo(tof_installPATH, tof_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to back tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(emails_installPATH) == 1 && (FileExist(emailsPATH) == 0 || ReadFileSize(emailsPATH) == 0)) { + CopyFileTo(emails_installPATH, emailsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to main emails <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(emails_installPATH) == 1 && (FileExist(emails_bakPATH) == 1 && ReadFileSize(emails_bakPATH) == 0)) { + CopyFileTo(emails_installPATH, emails_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to back emails <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + if (FileExist(db_fflpr_installPATH) == 1 && (FileExist(db_fflprPATH) == 0 || ReadFileSize(db_fflprPATH) == 0)) { + CopyFileTo(db_fflpr_installPATH, db_fflprPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_fflpr_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + if (FileExist(db_face_installPATH) == 1 && (FileExist(db_facePATH) == 0 || ReadFileSize(db_facePATH) == 0)) { + CopyFileTo(db_face_installPATH, db_facePATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_face_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); + } +#endif + if (FileExist(face_installPATH) == 1 && (FileExist(facePATH) == 0 || ReadFileSize(facePATH) == 0)) { + CopyFileTo(face_installPATH, facePATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy face_install to main face <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(cold_objects_installPATH) == 1 && (FileExist(cold_objectsPATH) == 0 || ReadFileSize(cold_objectsPATH) == 0)) { + CopyFileTo(cold_objects_installPATH, cold_objectsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy cold_objects_install to main cold_objects <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_bak.js", "/emmc/plugin/Aida/heatmap_data.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_bak to main heatmap_data <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_1_bak.js", "/emmc/plugin/Aida/heatmap_data_1.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_1_bak to main heatmap_data_1 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_2_bak.js", "/emmc/plugin/Aida/heatmap_data_2.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_2_bak to main heatmap_data_2 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_3_bak.js", "/emmc/plugin/Aida/heatmap_data_3.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_3_bak to main heatmap_data_3 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_4_bak.js", "/emmc/plugin/Aida/heatmap_data_4.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_4_bak to main heatmap_data_4 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_5_bak.js", "/emmc/plugin/Aida/heatmap_data_5.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_5_bak to main heatmap_data_5 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_6_bak.js", "/emmc/plugin/Aida/heatmap_data_6.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_6_bak to main heatmap_data_6 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_7_bak.js", "/emmc/plugin/Aida/heatmap_data_7.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_7_bak to main heatmap_data_7 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + +#ifdef GY_OS_AMBA + char sdk_versionPATH[1024] = { 0 }; + strcpy(sdk_versionPATH, exePath); + strcat(sdk_versionPATH, "sdk_version.txt"); + + { + char *filename = sdk_versionPATH; + if (FileExist(filename)) { + char* fileBuf = ReadAllBytes(filename); + + //printf("\n[run server]----sdk version:%s\n", fileBuf); + + if (strstr(fileBuf, "3.0") != NULL) { + g_IsSDK_3_0 = 1; + } + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + } + } +#endif +} + +#ifdef GY_OS_NOVA +int get_pid_nova_driver() { + char *temp = NULL; + int size_psBuffer = 512; + char psBuffer[512] = { 0 }; + + { + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "pidof nova_driver"); + FILE * pPipe; + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) { + temp = fgets(psBuffer, size_psBuffer, pPipe); + if (pPipe != NULL) + vpclose(pPipe); + } + } + if (temp != NULL && (int)strlen(psBuffer) >= 1) { + /* + printf("\n-------------------------------\n"); + printf("\psBuffer: %d\n", atoi(psBuffer)); + printf("\n-------------------------------\n"); + */ + return atoi(psBuffer); + } + + return -1; +} + +int g_check_run_nova_detection = 0; +void *RUN_NOVA_DETECTION(void *ptr) { //A11en + pthread_detach(pthread_self()); + setPthreadName("RUN_NOVA"); + usSleep(1000000); + + system("killall -15 nova_driver"); + usSleep(15000000); + char cmd[256] = { 0 }; + sprintf(cmd,"/emmc/plugin/Aida_data/nova_driver server -http_port %s &", accountData[0].account_aida_port); + g_check_run_nova_detection = 1; + system(cmd); + + usSleep(2000000); + + if (get_live_mode_flag() == 1 && g_check_run_nova_detection == 1) { + if (get_pid_nova_driver() == -1) { + + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "get_pid_nova_driver() == -1"); + write_to_logs_html(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } + } + + pthread_exit(NULL); +} +#endif \ No newline at end of file diff --git a/src/detector.h b/src/detector.h new file mode 100644 index 0000000..5f4ebf5 --- /dev/null +++ b/src/detector.h @@ -0,0 +1,17 @@ +#pragma once +#ifndef DETECTOR_H +#define DETECTOR_H +#include "define_inc.h" +#include <tchar.h> +#include "setting.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/detector_Ming.c b/src/detector_Ming.c new file mode 100644 index 0000000..cc6dbc9 --- /dev/null +++ b/src/detector_Ming.c @@ -0,0 +1,32092 @@ + +#include "darknet.h" +#include "utils.h" +#include "demo.h" +#include "blas.h" +#include "option_list.h" +#include "setting.h" +#include "utility.h" +#include "libgen.h" +#include "iniReader.h" +#include "network.h" +#include "cJSON.h" +#include "cryptionPlus.h" +#include "nweb.h" +#include "gettest.h" +#include "test_nnctrl_live.h" +#include "fflpr_plate_db.h" +#ifdef GY_OS_AMBA +//#include "websocket_client.h" +#endif +#include "url_encode.h" +#ifdef GY_OS_AMBA +//#include "tof.h" +#include "ptz.h" +#endif +#include "cold_zone.h" +#include "cgicmd.h" +#include <mcheck.h> +#include "pns.h" +#include <netinet/tcp.h> +#include "fork_pipe_lib.h" +#include <errno.h> +#include <time.h> +#include "net_curl.h" +#include <pythonR.h> +#include "structures.h" + +#if defined GY_OS_AMBA +#include "ir_control.h" +#endif + +#ifdef GY_OS_AMBA +#include "send_osd_data.h" + +//#include "radar.h" +//#include "radar_driver.h" +//#include "radar_receive.h" +//#include "radar_parser.h" +#include "cv_point_transform.hpp" +//#include "cv_point_transform.h" +#include "cv.h" +//#include "face_parser.h" +#include "levenshtein.h" +#endif + + +///Steven MARK TEMP +//#include "zlog.h" +//===================== +//sophia add 2020/09/24 +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include "alm_queue.h" +#endif +//===================== + +#include <pthread.h> +#include <math.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#include <unistd.h> + +#include <curl/curl.h> +#include <curl/easy.h> +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif + +#include "onvif_data.h" +#include "anpr_rule.h" + +//pthread_mutex_t mutex_tcp_layer[MAX_LAYER_NUM]; +//pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; +//pthread_mutex_t mutex_post_notification; +//pthread_mutex_t mutex_post_notification_push; +pthread_mutex_t mutex_post_notification_pop; +pthread_mutex_t mutex_getalarmmotion; +pthread_mutex_t mutex_alm; +pthread_mutex_t mutex_curl; +pthread_mutex_t mutex_dn; +pthread_mutex_t mutex_websocket; +pthread_mutex_t mutex_enable_lpr_db; +#ifdef GY_OS_AMBA +pthread_mutex_t mutex_enable_face_db; +#endif +pthread_mutex_t mutex_username; +pthread_mutex_t mutex_pns; +pthread_mutex_t mutex_snap; +//pthread_mutex_t mutex_get_canvas; +//pthread_mutex_t mutex_cropped_roi; +pthread_mutex_t mutex_config_json; +#if defined GY_OS_AMBA +//pthread_mutex_t mutex_jvc_config_json; +#endif +pthread_mutex_t mutex_events_json; +pthread_mutex_t mutex_web; +pthread_mutex_t mutex_http_connection_handler; +pthread_mutex_t mutex_base64; +pthread_mutex_t mutex_run_one_net; +#ifdef GY_OS_NOVA +pthread_mutex_t mutex_run_parse_json; +#endif +pthread_mutex_t mutex_send_jpeg; +pthread_mutex_t mutex_heatmap_jpeg; +//pthread_mutex_t mutex_strsplit; +#ifdef GY_OS_AMBA +pthread_mutex_t mutex_perspective_transform; +#endif +//pthread_mutex_t mutex_snap_hd_image; +pthread_mutex_t mutex_snap_image; +pthread_mutex_t mutex_get_image; +pthread_mutex_t mutex_get_image_HD; + +pthread_mutex_t mutex_if_enable_lpr_db_is_Yes; +pthread_mutex_t mutex_get_network_input; +pthread_mutex_t mutex_differ_image; + +pthread_mutex_t mutex_run_one_net_anpr; + +pthread_mutex_t mutex_check_license; +pthread_mutex_t mutex_read_ipcam; + +pthread_mutex_t mutex_update_candidate; +pthread_mutex_t mutex_send_cgi; + +//pthread_mutex_t mutex_parse_bbox; + +pthread_mutex_t mutex_compute_median; +//pthread_mutex_t mutex_long_term; +//pthread_mutex_t mutex_short_term; + +//pthread_mutex_t mutex_long_term_yuv; +//pthread_mutex_t mutex_short_term_yuv; + +pthread_mutex_t mutex_set_http_request; +pthread_mutex_t mutex_reset_counter; + +#ifdef GY_OS_AMBA + +pthread_mutex_t mutex_get_depth; +//pthread_mutex_t mutex_tof_data; +pthread_mutex_t mutex_write_pcd_data; +pthread_mutex_t mutex_write_pcd_data_L; +pthread_mutex_t mutex_write_pcd_data_M; +pthread_mutex_t mutex_write_pcd_data_S; + + +pthread_mutex_t mutex_remotesnap_image; // Ken 2022-09-26 +pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 +pthread_mutex_t mutex_tof_json; // Ken 2022-12-13 +pthread_mutex_t mutex_buffer; // Ming 2022-08-28 +pthread_mutex_t mutex_run_osd; +#endif + +#ifdef GY_OS_NOVA +pthread_mutex_t mutex_pre_bbox_receive; +pthread_mutex_t mutex_pre_connection; +pthread_mutex_t mutex_pre_image_receive; +#endif + +//pthread_mutex_t mutex_color_detect; + +int g_match_mac = 0; +char g_mac_address[256] = { 0 }; + +int g_sdk_version = -1; + +int g_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +int g_temp_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +float g_parking_space_recording_x[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +float g_parking_space_recording_y[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +time_t g_parking_space_update_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; +time_t g_parking_space_status_change_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; + +long g_osdSysTimeStamp = 0; +int check_if_run_post = -1; +int check_if_correct_post = 0; + +int check_if_start_run_server = 0; +char record_process_note[MAX_RECORD_PROCESS][MAX_PROCESS_LENGTH] = { 0 }; +int current_index_record = 0; +int size_record_process_note = 0; + +//http server parameters +SocketInfo socketRecords[MAX_CLIENT_SOCKET] = { 0 }; +ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW] = { 0 }; +DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE] = { 0 }; +SystemSettingInfo SystemSetting; +PostEventInfo postEventList[MAX_POST_EVENTS] = { 0 }; +#ifdef GY_OS_V_SERIES + +#else +EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS] = { 0 }; +ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS] = { 0 }; +SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT] = { 0 }; +#endif + +AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM] = { 0 }; //20201027 sophia add +IPCAMServiceInfo IPCAMService; +SnapHDInfo snapHDList[MAX_SNAP_HD_LIST] = { 0 }; +EmailInfo emailData; +WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST] = { 0 }; +char WeightFileModeName[35] = { 0 }; +HeartbeatInfo heartbeatData; +#ifdef GY_OS_AMBA +TofInfo tofData; +#endif + +int g_check_if_set_no_preset_no_autopan = 0; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER] = {0}; +#endif +ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER] = { 0 }; +PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; +PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + +//MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA] = { 0 }; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +ImageDn imageDnData; +#endif +#ifdef GY_OS_AMBA +OSDInfo OSDData[MAX_SIZE_OSD_ARRAY] = { 0 }; +SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY] = { 0 }; +#endif +int g_PlateFilterTimes; //Times +int g_PlateFilterTime; //Second +int g_PlateRecorderFreeTime; //Second + +struct tm *cgi_reload_start_Time; +struct tm *cgi_startTime_buff; +struct tm *cgi_whenTime_buff; + +struct amba_content stAMBAcontent; + +static int protected_sqlite_fflpr_db_close = 0; + +int g_check_ping_OK = 1; + +int g_check_if_no_brand = 0; + +//static unsigned char g_snapshot_addr_to_post[MAX_IMG_SIZE] = { 0 }; + +int g_control_read_ipcam = 0; +#ifdef GY_OS_AMBA +int g_sensors_type = 0;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 +#endif +#ifdef GY_OS_NOVA +int g_sensors_type = 1;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 +#endif +int g_max_sensor_size = MAX_SENSOR_TYPE0; + +int g_IsRadarDevice = 0; +int g_IsPTZDevice = 0; +int g_IsRadarFake = 0; +int g_check_if_OK_thermal = 0; + +int unlockingKeyInnoFR = 0; +int unlockingKeyInnoFR_success = 0; +#ifdef GY_OS_AMBA +char radar_json_data[4096]; +#endif +int g_check_if_OK_to_start_osd_server = 0; + +int g_IsSDK_3_0 = 0; +int g_IsToFDevice = 0; +int g_IsCustomWeight = 0; +int g_IsHelm_without_car = 0; + +float g_thres_bbox_stability = 0.02;//0.02 0.1 +float g_thres_bbox_stability_plate = 0.01; +float g_thres_bbox_stability_predict = 0.32; + +float g_initial_background_learning_rate_x = 0.5; +float g_initial_background_learning_rate_y = 0.5; +float g_initial_background_learning_rate_error_x = 0.0; +float g_initial_background_learning_rate_error_y = 0.0; + +float g_initial_background_mean_diff_x = 0.0; +float g_initial_background_mean_diff_y = 0.0; +float g_initial_background_error_diff_x = 0.0; +float g_initial_background_error_diff_y = 0.0; + +int g_check_current_resolution = 1; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +cJSON *g_config_root = NULL; +char* get_enable_python_file_value(const char *filename); +#endif + +/*typedef struct { + network net; + layer layer; + char *datacfg; + char *cfgfile; + char *weightfile; + float nms; + float thresh; + float hier_thresh; + int dont_show; + int ext_output; + int save_labels; +} NetworkInfo;*/ + +/*typedef struct { + NetworkInfo networkLayer[2]; + int layerCount; + char **alphabet; + ServerType serverType; + LicenseType licenseType; + AuthFailStatusCode afsCode; + unsigned int featureType; +} NetworkPool;*/ + +//static int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90}; + +short td_weight_num = 0; +ThirdPartyWeight td_weight_info[MAX_LAYER_NUM]; + +//CURLM* g_multi_handle; +//int g_handle_count; +CURL* g_http_handle = NULL; + +bool isGYNetReady; + +extern int reload_dataset_from_jsonfile(void); +//extern int default_dataset_for_jsonfile(void); + +//#define DISAPPEAR_FRAME_MAX 8 +static int DISAPPEAR_FRAME_MAX = 8; + +void set_DISAPPEAR_FRAME_MAX(int disappear_frame_max_temp) { + DISAPPEAR_FRAME_MAX = disappear_frame_max_temp; +} + +void setPthreadName(char *p_name) +{ + if (p_name != NULL) + { + (void)prctl(PR_SET_NAME, (unsigned long)p_name);//lname ̦h16?r + } +} + +//static NetworkPool networkPool[MAX_NETWORK_POOL_NUM]; +//static int layer_count; +static int dont_show; +static int show; +static int tcp_port; +//static char *out_filename; +//static char *outfile; +//static char *prefix; +static float thresh; +static float hier_thresh; +static int cam_index; +static int frame_skip; +static int num_of_clusters; +static int yuv_width; +static int yuv_height; +static int ext_output; +static int save_labels; +static int http_port; +//static char* unlocking_key; + +static int gpu_idx; +//static char* c_cnn_type; + +pthread_t http_thread; +#ifdef GY_OS_NOVA +pthread_t http_thread_parse_json_data; +pthread_t http_thread_pre_image_receive; +#endif +pthread_t post_notification_thread; +pthread_t runpython_thread; +pthread_t getalarmmotion_thread; + +pthread_t delete_jpg_in_seven_days_detector_thread_id; +pthread_t send_udp_thread; +pthread_t test_nnctrl_live_thread; + +pthread_t fps_loading_thread; + +pthread_t getimage_thread; + +pthread_t resolution_changed_thread; + +#ifdef GY_OS_V_SERIES + +#else +pthread_t counter_thread; +#endif + +#ifdef GY_OS_AMBA +pthread_t getimage_hd_thread; +pthread_t gettofdata_thread; + +pthread_t getstream_thread; +pthread_t get_face_websocket_thread; +pthread_t parse_face_thread; +pthread_t radar_reciever_id; +pthread_t render_radar_thread; +pthread_t radar_parser_thread; +pthread_t thread_id_run_osd_server; +#endif +#ifdef GY_OS_NOVA +pthread_t thread_id_get_nova_driver; +#endif +//pthread_t thread_id_run_system_time_sync; +static int check_if_is_existing_weight = 0; + +float overlap_ratio_limit; +extern float confidence_limit; + +int input_resizable; +char* custom_cpu_library; +char* custom_cldnn; +int performance_counter; + +static CNNType cnn_type; +//static image **alphabet=NULL; +//static network nets[MAX_LAYER_NUM]; +//static layer layers[MAX_LAYER_NUM]; +//static list *options[MAX_LAYER_NUM]; +//static char *name_list[MAX_LAYER_NUM]; +//static char **names[MAX_LAYER_NUM]; +//static network net2; +//static layer L2; +//static list *options2; +//static char *name_list2; +//static char **names2; +//static float nms[MAX_LAYER_NUM]; +//static float nms2; +//ini +static char ppIniKeyValue[MAX_LAYER_NUM][MAX_SECTION_VARIABLE][50] = { 0 }; +//http server parameters +//static CNNType http_cnn_type; +//static network http_nets[MAX_LAYER_NUM]; +//static network http_net2; +//static char **http_names[MAX_LAYER_NUM]; +//static char **http_names2; +//static image **http_alphabet; +//static float http_nms[MAX_LAYER_NUM]; +//static float http_nms2; +//static float http_thresh; +//static float http_hier_thresh; +//static int http_dont_show; +//static int http_ext_output; +//static int http_save_labels; +//static char *http_ip_address; +//static char *http_mac_address; +//static int http_http_port; +//static int http_layer_count; +//static char http_dataset_version; +//static LicenseType http_licenseType; +//static LicenseType http_advLicenseType; +//static AuthFailStatusCode http_afsCode; +//static size_t http_featureType; +static size_t layerFeatureType[MAX_LAYER_NUM] = { 0 }; +static size_t layerFeatureType2[MAX_LAYER_NUM] = { 0 }; +//static char* layerUTF8Country[MAX_LAYER_NUM]; +static char strLicenseType[MAX_MSG_LEN] = { 0 }; +char strLicenseStatus[MAX_MSG_LEN] = { 0 }; +char strUnlockingKey[MAX_MSG_LEN] = { 0 }; +int bHttpServerThreadStart = 0; +double http_license_fps; +int http_sleep_interval = 2; +int bPreloadHttpServerThreadStart = 0; + +//#ifdef GY_OS_WIN +//static char msgText[MAX_MSG_LEN]; +//#elif _DEBUG_AMBA +//static char msgText[MAX_MSG_LEN]; +//#endif + +int nIsCompatibleCPU = 0; +int nIsCompatibleGPU = 0; +int nIsCompatibleVPU = 0; +int nIsHardwareOK = 1; + +size_t featureType; +size_t featureType2; +size_t advancedType; + +CPoint trafficLightPoint = { 0 }; +int traffic_light_zone_width = 0; +int traffic_light_zone_height = 0; + +LicenseType licenseType; +AdvanceLicenseType advLicenseType; +AuthFailStatusCode afsCode; +HttpCode httpCode; + +MYBOOL activeDisplayDash; +MYBOOL activeDisplayProperties; +MYBOOL activePostNotification; +MYBOOL activeSNMPPost; +MYBOOL testPostNotification; + +char g_device_name[512] = { 0 }; + +int check_if_correct_mail = 0; +int check_if_fe_fail = 0; + +int g_enable_person_for_metadata[MAX_DETECTION_ZONE] = { 0 }; + +//struct amba_content stAMBAcontent; + +int protect_set_record_process_note = 0; +void set_record_process_note(char *process_note) { + if (check_if_start_run_server == 1 && protect_set_record_process_note == 0) { + protect_set_record_process_note = 1; + memset(record_process_note[current_index_record], 0x00, sizeof(record_process_note[current_index_record])); + snprintf(record_process_note[current_index_record], sizeof(record_process_note[current_index_record]), "%s", process_note); + + current_index_record++; + if (current_index_record >= MAX_RECORD_PROCESS) { + current_index_record = 0; + } + + if (size_record_process_note < MAX_RECORD_PROCESS) { + size_record_process_note++; + } + protect_set_record_process_note = 0; + } +} + +void record_process_note_write_to_log() { + if (check_if_start_run_server == 0) { + + char temp_msg[8192] = { 0 }; + for (int count_record = size_record_process_note - 1; count_record >= 0; count_record--) { + int index_record = current_index_record - 1 - count_record; + if (index_record < 0) { + index_record += size_record_process_note; + } + + if (count_record == 0) { + char temp_temp_msg[8192] = { 0 }; + snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s", record_process_note[index_record]); + } + else { + if (count_record == size_record_process_note - 1) { + char temp_temp_msg[8192] = { 0 }; + snprintf(temp_temp_msg, sizeof(temp_temp_msg), "free:%d,%s,", get_free_mem_data(), record_process_note[index_record]); + strcpy(temp_msg, temp_temp_msg); + } + else { + char temp_temp_msg[8192] = { 0 }; + snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s,", record_process_note[index_record]); + strcat(temp_msg, temp_temp_msg); + } + } + } + write_to_logs_html(temp_msg, "record process", "ERROR", "Yes"); + } +} + + +int get_check_if_correct_mail() { + return check_if_correct_mail; +} +#ifdef GY_OS_NOVA +void *thread_get_nova_driver(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("start nova driver"); + usSleep(12000000); + while (bHttpServerThreadStart) + { + start_nova_driver(); + usSleep(3000000); + } + pthread_exit(NULL); +} +#endif +void *thread_getimage(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("getimage"); + while (bHttpServerThreadStart) + { + //printf("\n---------thread getimage start\n"); + if (atoi(SystemSetting.getimage_encoder_id) - 1 >= 0) { + get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id) - 1, 1); + }else if(unlockingKeyInnoFR_success == 1){ + get_snap_with_profile_id(0, 1); + } + //printf("\n---------thread getimage end\n"); + usSleep(3000000); + } + pthread_exit(NULL); +} + +void *thread_getimage_hd(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("getimage_hd"); + while (bHttpServerThreadStart) + { + if (atoi(SystemSetting.getimage_encoder_id_HD) - 1 >= 0 && atoi(SystemSetting.getimage_encoder_id_HD) != atoi(SystemSetting.getimage_encoder_id)) { + get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id_HD) - 1, 0); + } + usSleep(3000000); + } + pthread_exit(NULL); +} + +void *run_http_server_thread(void *ptr) +{ + //printf("[run http server thread]Pthread started and detached. No new addr.\n"); + pthread_detach(pthread_self()); + + setPthreadName("run_http"); + +//#ifdef _DEBUG_AMBA + //printf("\n[run_http_server_thread] start\n"); +//#endif + + bHttpServerThreadStart = 1; + printf("[run_http_server_thread] !! \n"); + while (bHttpServerThreadStart) + { + bHttpServerMainStart = 1; + + run_http_server("", zc, cnn_type/*, layer_count, http_nets, names, alphabet, nms*/, thresh, hier_thresh, dont_show, ext_output, save_labels, NULL, NULL, http_port, licenseType, advLicenseType, afsCode, layerFeatureType, strLicenseType); + + //printf("\n[run http server thread] in while bHttpServerThreadStart-1 bHttpServerThreadStart:%d\n", bHttpServerThreadStart); + //printf("\n[run http server thread] in while bHttpServerThreadStart-2 :%d\n", bHttpServerThreadStart); + //printf("\nerr_count: %u\n",err_count); + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + usSleep(1000); + } + //printf("\n[run http server thread] while out :%d\n", bHttpServerThreadStart); + + bHttpServerThreadStart = 0; + bHttpServerMainStart = 0; + + //printf("\n-----------run http server thread:exit\n"); + + //20201014 - sophia add for restart + pthread_exit(NULL); +} + +extern int run_preload_http_server(int http_port); +void *run_preload_http_server_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_preload"); + + +#if 1 + + bPreloadHttpServerThreadStart = 1; + + while (bPreloadHttpServerThreadStart) + { + bPreloadHttpServerMainStart = 1; +#if 1 + run_preload_http_server(http_port); +#endif + bPreloadHttpServerThreadStart = 0; + + //printf("\n**********************\n"); + //printf("preload server close"); + //printf("\n**********************\n"); + + usSleep(100000); + } + + bPreloadHttpServerThreadStart = 0; + bPreloadHttpServerMainStart = 0; + +#endif + + //20210617-Steven add for preload + + + + pthread_exit(NULL); +} + +#ifdef GY_OS_V_SERIES + +#else +void reset_counter(int index_counter, time_t now_time) +{ + time_t ori_now_time = now_time; + struct tm *nowTime = localtime(&now_time); + int current_year = nowTime->tm_year + 1900; + int current_month = nowTime->tm_mon + 1; + int current_month_day = nowTime->tm_mday; + int current_week_day = nowTime->tm_wday + 1; + int current_hour = nowTime->tm_hour; + int current_min = nowTime->tm_min; + int current_sec = nowTime->tm_sec; + + if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 minute") == 0) + { + nowTime->tm_min = nowTime->tm_min + 1; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "5 minutes") == 0) + { + nowTime->tm_min = nowTime->tm_min + 5; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "30 minutes") == 0) + { + nowTime->tm_min = nowTime->tm_min + 30; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 hour") == 0) + { + nowTime->tm_hour = nowTime->tm_hour + 1; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 day") == 0) + { + nowTime->tm_mday = nowTime->tm_mday + 1; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 week") == 0) + { + + nowTime->tm_mday = nowTime->tm_mday + 7; + } + else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 month") == 0) + { + nowTime->tm_mon = nowTime->tm_mon + 1; + } + + time_t next_time = mktime(nowTime); + + int next_year = current_year; + int next_month = current_month; + int next_month_day = current_month_day; + int next_week_day = current_week_day; + int next_hour = current_hour; + int next_min = current_min; + int next_sec = current_sec; + + if (next_time != -1) { + struct tm *nextTime = localtime(&next_time); + next_year = nextTime->tm_year + 1900; + next_month = nextTime->tm_mon + 1; + next_month_day = nextTime->tm_mday; + next_week_day = nextTime->tm_wday + 1; + next_hour = nextTime->tm_hour; + next_min = nextTime->tm_min; + next_sec = nextTime->tm_sec; + } + else { + next_time = ori_now_time; + } + + struct tm * gmtTime = gmtime(&next_time); + int gmt_year = gmtTime->tm_year + 1900; + int gmt_month = gmtTime->tm_mon + 1; + int gmt_month_day = gmtTime->tm_mday; + int gmt_week_day = gmtTime->tm_wday + 1; + int gmt_hour = gmtTime->tm_hour; + int gmt_min = gmtTime->tm_min; + int gmt_sec = gmtTime->tm_sec; + + eventCounterList[index_counter].reset_year = current_year; + eventCounterList[index_counter].reset_month = current_month; + eventCounterList[index_counter].reset_month_day = current_month_day; + eventCounterList[index_counter].reset_week_day = current_week_day; + eventCounterList[index_counter].reset_hour = current_hour; + eventCounterList[index_counter].reset_min = current_min; + eventCounterList[index_counter].reset_sec = current_sec; + + eventCounterList[index_counter].gmt_year = gmt_year; + eventCounterList[index_counter].gmt_month = gmt_month; + eventCounterList[index_counter].gmt_month_day = gmt_month_day; + eventCounterList[index_counter].gmt_week_day = gmt_week_day; + eventCounterList[index_counter].gmt_hour = gmt_hour; + eventCounterList[index_counter].gmt_min = gmt_min; + eventCounterList[index_counter].gmt_sec = gmt_sec; + + eventCounterList[index_counter].next_year = next_year; + eventCounterList[index_counter].next_month = next_month; + eventCounterList[index_counter].next_month_day = next_month_day; + eventCounterList[index_counter].next_week_day = next_week_day; + eventCounterList[index_counter].next_hour = next_hour; + eventCounterList[index_counter].next_min = next_min; + eventCounterList[index_counter].next_sec = next_sec; + + eventCounterList[index_counter].timetResetAt = ori_now_time; + eventCounterList[index_counter].next_timetResetAt = next_time; + + time_t temp_next_time = next_time; + time_t temp_gmt_time = mktime(gmtTime); + if (temp_gmt_time != -1) { + double dTime = 0.0; + char sign_of_dtime[2] = { 0 }; + if (temp_next_time > temp_gmt_time) { + dTime = difftime(temp_next_time, temp_gmt_time); + strcpy(sign_of_dtime,"+"); + } + else if (temp_next_time < temp_gmt_time) { + dTime = difftime(temp_gmt_time, temp_next_time); + strcpy(sign_of_dtime, "-"); + } + else { + strcpy(sign_of_dtime, "+"); + } + + int iHour = (int)(dTime / 60.0 / 60.0); + int iMin = (int)((dTime - (double)iHour * 60.0 * 60.0) / 60.0); + + char ResetTime[50] = { 0 }; + sprintf(ResetTime,"%02d:%02d:%02d%s%02d:%02d", gmt_hour, gmt_min, gmt_sec, sign_of_dtime, iHour, iMin); + + strcpy(eventCounterList[index_counter].ResetTime, ResetTime); + } + else { + strcpy(eventCounterList[index_counter].ResetTime, ""); + } + + eventCounterList[index_counter].counter_count = eventCounterList[index_counter].reset_value; + eventCounterList[index_counter].already_reset = 1; + + //printf("\nreset time:%04d-%02d-%02dT%02d:%02d:%02d\n" + //, eventCounterList[index_counter].reset_year + //, eventCounterList[index_counter].reset_month + //, eventCounterList[index_counter].reset_month_day + //, eventCounterList[index_counter].reset_hour + //, eventCounterList[index_counter].reset_min + //, eventCounterList[index_counter].reset_sec + //); + + //printf("\nnext time:%04d-%02d-%02dT%02d:%02d:%02d\n" + // , eventCounterList[index_counter].next_year + // , eventCounterList[index_counter].next_month + // , eventCounterList[index_counter].next_month_day + // , eventCounterList[index_counter].next_hour + // , eventCounterList[index_counter].next_min + // , eventCounterList[index_counter].next_sec + //); +} + +void set_counter_zone() { + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + eventCounterList[j].counter_zone = 0; + } + + int tracking_channel_idx = 0; + int base_zone = 1; + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + if (index_zone >= 1) { + base_zone = base_zone * 2; + } + + for (int trigger_idx = 0; trigger_idx < MAX_TRIGGER_EVENT; trigger_idx++) + { + if (viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].detect_event_id); + + if (trigger_event_type == TRIGGER_GO_STRAIGHT || + trigger_event_type == TRIGGER_QUEUING_VIOLATION) + { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + + for (int index_event_counter = 0; index_event_counter < event_counter_num; index_event_counter++) + { + for (int index_event_list = 0; index_event_list < MAX_EVENT_COUNTERS; index_event_list++) + { + if (strlen(eachEventCounter[index_event_counter]) >= 1 && strcmp(eachEventCounter[index_event_counter], eventCounterList[index_event_list].counter_name) == 0) + { + eventCounterList[index_event_list].counter_zone += base_zone; + break; + } + } + } + + } + + break; + } + } + } + +} + +#endif + + + +//쥻W٬Ocheck_http_socket_threadA{b令run_event_counter_thread +void *run_event_counter_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_counter"); +#ifdef GY_OS_V_SERIES + +#else + //printf("\n[run event counter thread]pthread create\n"); + + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + struct tm *nowTime = localtime(&now_time); + //int reset_year = nowTime->tm_year + 1900; + int reset_month = nowTime->tm_mon + 1; + int reset_month_day = nowTime->tm_mday; + int reset_week_day = nowTime->tm_wday + 1; + int reset_hour = nowTime->tm_hour; + int reset_min = nowTime->tm_min; + //int reset_sec = nowTime->tm_sec; + + //struct tm * gmtTime = gmtime(&now_time); + //int gmt_year = gmtTime->tm_year + 1900; + //int gmt_month = gmtTime->tm_mon + 1; + //int gmt_month_day = gmtTime->tm_mday; + //int gmt_week_day = gmtTime->tm_wday + 1; + //int gmt_hour = gmtTime->tm_hour; + //int gmt_min = gmtTime->tm_min; + //int gmt_sec = gmtTime->tm_sec; + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + + set_counter_zone(); + + while (bHttpServerThreadStart) + { + //printf("\n-----run event counter thread start\n"); + //if (strcmp(eventCounterList[j].enable_reset_only_cloud, "No") == 0) + if (//(strcmp(SystemSetting.cloud_enable_notification, "No") == 0) && + (strcmp(SystemSetting.enable_email_notification, "No") == 0 || (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && Get_mail_post_interval() == -1)) + ) + { + set_record_process_note("counter_start"); + now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + nowTime = localtime(&now_time); + //int current_year = nowTime->tm_year + 1900; + int current_month = nowTime->tm_mon + 1; + int current_month_day = nowTime->tm_mday; + int current_week_day = nowTime->tm_wday + 1; + int current_hour = nowTime->tm_hour; + int current_min = nowTime->tm_min; + int current_sec = nowTime->tm_sec; + +#if 1 + pthread_mutex_lock(&mutex_reset_counter); + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + //reset_year = eventCounterList[j].reset_year; + reset_month = eventCounterList[j].reset_month; + reset_month_day = eventCounterList[j].reset_month_day; + reset_week_day = eventCounterList[j].reset_week_day; + reset_hour = eventCounterList[j].reset_hour; + reset_min = eventCounterList[j].reset_min; + //reset_sec = eventCounterList[j].reset_sec; + + //gmt_year = eventCounterList[j].gmt_year; + //gmt_month = eventCounterList[j].gmt_month; + //gmt_month_day = eventCounterList[j].gmt_month_day; + //gmt_week_day = eventCounterList[j].gmt_week_day; + //gmt_hour = eventCounterList[j].gmt_hour; + //gmt_min = eventCounterList[j].gmt_min; + //gmt_sec = eventCounterList[j].gmt_sec; + + if (strcmp(eventCounterList[j].enable_reset_time_interval, "Yes") == 0) + { + if (strcmp(eventCounterList[j].reset_time_interval, "1 minute") == 0) + { + eventCounterList[j].dwell_time = current_sec; + strcpy(eventCounterList[j].dwell_unit, "sec"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1S"); + + if (eventCounterList[j].already_reset == 1 && current_sec >= 30) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_sec < 30 && current_min != reset_min) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "5 minutes") == 0) + { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + + if (eventCounterList[j].already_reset == 1 && current_min % 5 != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_min % 5 == 0 && current_min != reset_min) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "30 minutes") == 0) + { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + + if (eventCounterList[j].already_reset == 1 && current_min % 30 != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_min % 30 == 0 && current_min != reset_min) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 hour") == 0) + { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + + if (eventCounterList[j].already_reset == 1 && current_min != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_min == 0 && current_hour != reset_hour) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 day") == 0) + { + eventCounterList[j].dwell_time = current_hour; + strcpy(eventCounterList[j].dwell_unit, "hour"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1H"); + + if (eventCounterList[j].already_reset == 1 && current_hour % 24 != 0) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_hour % 24 == 0 && current_week_day != reset_week_day) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 week") == 0) + { + eventCounterList[j].dwell_time = current_week_day; + strcpy(eventCounterList[j].dwell_unit, "wday"); + strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); + + if (eventCounterList[j].already_reset == 1 && current_week_day != 1) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_month == 1 && current_month_day != reset_month_day) + { + reset_counter(j, now_time); + } + } + else if (strcmp(eventCounterList[j].reset_time_interval, "1 month") == 0) + { + eventCounterList[j].dwell_time = current_month_day; + strcpy(eventCounterList[j].dwell_unit, "mday"); + strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); + + if (eventCounterList[j].already_reset == 1 && current_month_day != 1) { + eventCounterList[j].already_reset = 0; + } + + if (eventCounterList[j].already_reset == 0 && current_month_day == 1 && current_month != reset_month) + { + reset_counter(j, now_time); + } + } + else { + eventCounterList[j].dwell_time = current_min; + strcpy(eventCounterList[j].dwell_unit, "min"); + strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); + } + } + + } + pthread_mutex_unlock(&mutex_reset_counter); +#endif + set_record_process_note("counter_end"); + usSleep(1000000); + } + else { + usSleep(5000000); + } + //printf("\n-----run event counter thread end\n"); + } + //printf("\n[run event counter thread] end\n"); +#endif + pthread_exit(NULL); +} + +struct timeval currtime_control_alarm_gpio; +static long last_ms_control_alarm_gpio = 0; +//post the notification back to the origianl socket +void *run_post_notification_thread(void *ptr) +{ + //printf("\n[run post notification thread]pthread create\n"); + + pthread_detach(pthread_self()); + setPthreadName("run_post"); + QueueInfo q_info_copy = { 0 }; + + char sendLargeBuffer[BUFSIZE_V2] = { 0 }; + + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + + int count_g_http_handle = 0; + + unsigned int count_to_refresh_smtp_service = 0; + int count_delay = 0; + + int count_initial_global_curl = 0; + +#ifdef GY_OS_AMBA + int count_ptz = 0; +#endif + + while (bHttpServerThreadStart) + { + //printf("\n-----run post notification start\n"); + set_record_process_note("run_post_start"); + //printf("out que size = %d \n", QueueSize(_POST_NOTIFICATION)); + if (!QueueIsEmpty(_POST_NOTIFICATION) && QueueSize(_POST_NOTIFICATION) >= 1) + { + //printf("\n-----------QueueSize(_POST_NOTIFICATION) = %d \n", QueueSize(_POST_NOTIFICATION)); + // +#if 1 + pthread_mutex_lock(&mutex_post_notification_pop); + q_info_copy = QueueFront(_POST_NOTIFICATION); + + QueuePop(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_post_notification_pop); + + memset(sendLargeBuffer, 0x00, BUFSIZE_V2); + +//AA +#if 1 + //HU----------- + if (strcmp(q_info_copy.post_url,"post_to_cloud")==0) { + + + //printf("\n----------------\n"); + //printf("\nq_info_copy.cloud_aiengine:%s\n", q_info_copy.cloud_aiengine); + //printf("\n----------------\n"); + char behavior_ID_temp[50] = {0}; + sprintf(behavior_ID_temp,"%d", q_info_copy.behavior_ID); + + char behavior_ID_16_temp[50] = { 0 }; + sprintf(behavior_ID_16_temp, "0x%08X", q_info_copy.behavior_ID); + + //printf("\n-------%s\n", behavior_ID_16_temp); + + /* + printf("\n----------------\n"); + printf("\nbehavior_name:%s,behavior_ID_temp:%s,behavior_desc:%s\n", q_info_copy.behavior_name, behavior_ID_temp, q_info_copy.behavior_desc); + printf("\n----------------\n");*/ + //if 0 No PNS_Send_Multipart_POST ̤jW162,000byte +#if 1 + + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Send_Multipart_POST(q_info_copy.cloud_aiengine, q_info_copy.behavior_name, behavior_ID_temp, behavior_ID_16_temp, q_info_copy.behavior_desc, SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/" , returned_msg, q_info_copy.image_buff, q_info_copy.image_buff_size, q_info_copy.rawtime); + strcpy(SystemSetting.cloud_statue,returned_msg); + + + //printf("\n------------Segmentation fault:%d\n",1); + + //PNS_Send_Multipart_POSTO鬪|ӦhAwMzAMz᭫sl + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); +#endif + } + else if (strcmp(q_info_copy.post_url, "post_to_mail") == 0) + { + //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + SendMailEventCondition(q_info_copy.behavior_desc, q_info_copy.content, q_info_copy.image_buff, q_info_copy.image_buff_size); +#endif + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + } + else if (strcmp(q_info_copy.post_url, "curl_to_ftp") == 0) + { + //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); +//#if defined GY_OS_AMBA + net_curl_ftp_post_push_info_attached_image(q_info_copy.image_buff, q_info_copy.image_buff_size); +//#endif + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + } +#if defined GY_OS_AMBA + else if (strlen(q_info_copy.snmp_host_ip) >= 1) + { + //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); + + SetSNMPRequest(&q_info_copy); + + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + } +#endif + else { + if (strlen(q_info_copy.post_url) >= 1) { + + char *temp_post_url = StrReplace(q_info_copy.post_url, "space", "%20"); + strcpy(q_info_copy.post_url, temp_post_url); + if (temp_post_url != NULL) { + free(temp_post_url); + temp_post_url = NULL; + } + + //printf("\n----------q_info_copy.post_url:%s\n", q_info_copy.post_url); + + pthread_mutex_lock(&mutex_set_http_request); +#ifdef GY_OS_NOVA + if (strcmp(q_info_copy.host_name, "127.0.0.1") != 0 && strcmp(q_info_copy.host_name, "localhost") != 0) { + SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); + } + else { + SetHttpRequest_sock(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); + } +#endif + +#ifdef GY_OS_AMBA + SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); +#endif + + pthread_mutex_unlock(&mutex_set_http_request); + } + } + //HW----------- +#endif + //printf("\n------------Segmentation fault:%d\n", 2); +#endif + } + +#ifdef GY_OS_AMBA + if (g_IsPTZDevice == 1 && get_try_once_ptz() == 1) { + if (IsTracking() == 1) { + if (count_ptz % 15 == 0) { + count_ptz = 0; + UpdatePTZIPcamSetting(); + } + else if (count_ptz % 15 == 4) { + UpdatePTZCurPos(); + } + else if (count_ptz % 15 == 7) { + update_PTZ_limits(); + } + else if (count_ptz % 15 == 10) { + UpdateRecoveryTime(); + } + } + else { + if (count_ptz % 40 == 0) { + count_ptz = 0; + UpdatePTZIPcamSetting(); + } + } + count_ptz++; + } +#endif + + if (count_delay % 200 == 0) { + count_delay = 0; + update_system_time(); + } + count_delay++; + + if (count_initial_global_curl % 15 == 0) { + count_initial_global_curl = 0; + + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + else { + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + } + count_initial_global_curl++; + + if (g_IsSDK_3_0 == 0) { + if (count_to_refresh_smtp_service % MAX_COUNT_TO_REFRESH_SMTP_SERVICE * 5 == 0) { + count_to_refresh_smtp_service = 0; + copy_ipcam_smtp_service_to_gynet(); + } + count_to_refresh_smtp_service++; + } + + if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { + if (strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { + gettimeofday(&currtime_control_alarm_gpio, NULL); + long current_ms_control_alarm_gpio = (currtime_control_alarm_gpio.tv_sec * 1000) + (currtime_control_alarm_gpio.tv_usec / 1000); + + if (last_ms_control_alarm_gpio == 0) { + last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + + if (current_ms_control_alarm_gpio >= last_ms_control_alarm_gpio + atoi(viewChannelData[0].dwell_lpr_upon_triggered) * 1000) { + copy_control_io_to_gynet(); + last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + } + } + + if (count_g_http_handle >= 5) { + //printf("\n------------Segmentation fault:%d\n", 3); + count_g_http_handle = 0; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + + //curl_global_cleanup(); + //curl_global_init(CURL_GLOBAL_SSL); + + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + else { + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + //printf("\n------------Segmentation fault:%d\n", 4); + } + else if (g_http_handle == NULL) { + count_g_http_handle = 0; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle == NULL) { + g_http_handle = curl_easy_init(); + } + pthread_mutex_unlock(&mutex_curl); + } + + count_g_http_handle++; + set_record_process_note("run_post_end"); + //printf("\n-----run post notification end\n"); + usSleep(SLEEP_QUEUE_POP_POST*1000); + } + + pthread_mutex_lock(&mutex_curl); + curl_easy_cleanup(g_http_handle); + g_http_handle = NULL; + pthread_mutex_unlock(&mutex_curl); + + pthread_mutex_lock(&mutex_post_notification_pop); + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_post_notification_pop); + + //printf("\n-------[run post notification thread] pthread_exit\n"); + + pthread_exit(NULL); +} + +//post the getalarmmotion back to the origianl socket +static char MultiPartBuffer[CONTENT_BUFSIZE] = { 0 }; +static char contentBuffer[CONTENT_BUFSIZE] = { 0 }; +static char contentBuffer_websocket[CONTENT_BUFSIZE] = { 0 }; +void *run_getalarmmotion_thread(void *ptr) +{ + //printf("\n[run getalarmmotion thread]pthread create\n"); + + pthread_detach(pthread_self()); + setPthreadName("run_getalarm"); + char sendBuffer[ALMBUFSIZE] = {0}; + //int nmlocsendBufferSize = 1024; + //int PAD_BUFFERSIZE = 512; + char l_send_buf[ALMBUFSIZE] = { 0 }; + UNIX_MESSAGE_V1_T l_unix_msg; + int l_packet_len = 0; + char tempStr[MAX_MSG_LEN] = { 0 }; + + QueueInfo q_info_copy = { 0 }; + + while (bHttpServerThreadStart) + { + //printf("\n getalarmmotion out que size = %d \n", QueueSize(_GETALARMMOTION)); + if (!QueueIsEmpty(_GETALARMMOTION)) + { + //printf("\n-------run getalarmmotion start\n"); + set_record_process_note("run_getalarm_start"); + //memset(sendBuffer, 0x00, sizeof(sendBuffer)); //20201104 sophia add + memset(MultiPartBuffer, 0x00, sizeof(MultiPartBuffer)); + memset(contentBuffer, 0x00, sizeof(contentBuffer)); + memset(contentBuffer_websocket, 0x00, sizeof(contentBuffer_websocket)); + memset(websocket_alarm, 0x00, sizeof(websocket_alarm)); + + pthread_mutex_lock(&mutex_getalarmmotion); + + q_info_copy = QueueFront(_GETALARMMOTION); + QueuePop(_GETALARMMOTION); + + pthread_mutex_unlock(&mutex_getalarmmotion); + + time_t now = time(0); + //struct tm tm = *gmtime(&now); + struct tm tm = *localtime(&now); + + struct timeval curTime; + gettimeofday(&curTime, NULL); + + strcpy(contentBuffer, "CamTime: "); + + memset(tempStr, 0x00, sizeof(tempStr)); + strftime(tempStr, sizeof(tempStr) - 1, "%Y-%m-%d %H:%M:%S", &tm); + strcat(contentBuffer, tempStr); + + int milli = curTime.tv_usec / 1000; + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, " %s%d", "ms:", milli); + strcat(contentBuffer, tempStr); + strcat(contentBuffer, "\r\n"); + strcat(contentBuffer, "\r\n"); + + strcpy(contentBuffer_websocket, contentBuffer); + + strcat(contentBuffer, q_info_copy.content); + strcat(contentBuffer, "\r\n"); + strcat(contentBuffer, "\r\n"); + + strcat(contentBuffer_websocket, q_info_copy.content_no_base64_image); + strcat(contentBuffer_websocket, "\r\n"); + strcat(contentBuffer_websocket, "\r\n"); + + //strcat(contentBuffer, "--myboundary\r\n"); + //strcat(contentBuffer, "\r\n"); + + //ץg_IsRadarDeviceMg_IsToFDevice䴩contentMcontent_no_base64_imageA]websocketgetalarmmotionnno_base64_imageC + //Ӥ@getalarmmotionAhOϥcontentC + //memcpy(websocket_alarm, contentBuffer, strlen(contentBuffer)); + memcpy(websocket_alarm, contentBuffer_websocket, strlen(contentBuffer_websocket)); + + long int contentLen_buffer = strlen(q_info_copy.content); + + strcpy(MultiPartBuffer, "--myboundary\r\n"); + //strcat(MultiPartBuffer, "\r\n"); + + //strcat(MultiPartBuffer, "Host: localhost:8592\r\n"); + //strcat(MultiPartBuffer, "Connection: keep-alive\r\n"); + //strcat(MultiPartBuffer, "Pragma: no-cache\r\n"); + //strcat(MultiPartBuffer, "Cache-Control: no-cache"); + //strcat(MultiPartBuffer, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36\r\n"); + //strcat(MultiPartBuffer, "Accept: */*\r\n"); + //strcat(MultiPartBuffer, "Referer: \r\n"); + //strcat(MultiPartBuffer, "Accept-Encoding: gzip, deflate\r\n"); + //strcat(MultiPartBuffer, "Accept-Language: zh-TW,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\r\n"); + //strcat(MultiPartBuffer, "Cookie: \r\n"); + //strcat(MultiPartBuffer, "Content-Type: multipart/form-data; boundary=----WebKitFormBoundarylilinboundary\r\n"); + + strcat(MultiPartBuffer, "Content-Type: text/plain\r\n"); + //strcat(MultiPartBuffer, "Content-Type: text/plain; charset=utf-8;\r\n"); + + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", contentLen_buffer); + strcat(MultiPartBuffer, tempStr); + strcat(MultiPartBuffer, "\r\n"); + //strcat(MultiPartBuffer, "Content-Type: text/html; charset=utf-8\r\n"); + + + strcat(MultiPartBuffer, contentBuffer); + //getalarmmotion doesn't need to append --myboundary END + size_t MultiPartLen = strlen(MultiPartBuffer); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + int sock_idx = i; + if (socketRecords[i].used == 1 && socketRecords[i].sock != -1 && socketRecords[i].isGetAlarmMotion) + { + //memset(sendBuffer, 0x00, nmlocsendBufferSize); //20201104 sophia add + ////ˬdO_ưjApGOAhĤ@alarmC + + //printf("\n[run getalarmmotion thread] socketRecords[%d].sock:%ld contentLen_buffer:%d MultiPartLen:%d\n", i, socketRecords[i].sock, contentLen_buffer, MultiPartLen); + + if (socketRecords[i].isUdpSocket == TRUE) + { + //printf("\n----------%d\n", strlen(q_info_copy.udp_aiengine)); + ///getalarmmotion looping +#if 1 + if(strlen(q_info_copy.udp_aiengine) >= 1 && strlen(q_info_copy.udp_aiengine) <= 15000) + { + memset(sendBuffer, 0x00, sizeof(sendBuffer)); + + unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; //type + unsigned int contentlen = strlen(q_info_copy.udp_aiengine); //len + size_t sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, nmlocsendBufferSize); + } + + //start code + { + strcat(sendBuffer, "UMV01"); + sendBufferSize = sendBufferSize + 5; + } + + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + ALMQueueInfo alm_q_info = { 0 }; + + memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info.nSize = sendBufferSize + 1; + alm_q_info.infoType = 1; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if(ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); + } + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + } + } + else if(strlen(q_info_copy.udp_aiengine) > 15000 && strlen(q_info_copy.udp_aiengine) <= 30000) + { + memset(sendBuffer, 0x00, sizeof(sendBuffer)); + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 1); + /////////////////start + unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; + unsigned int UDP_PACKAGE_TYPE = 0x0000; //start type 0x0000 body type 0x0001 end type 0x0002 + unsigned int contentlen = 15000; //len + size_t sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 2); + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, ALMBUFSIZE); + } + + //start code + { + strcat(sendBuffer, "UMV02"); + sendBufferSize = sendBufferSize + 5; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); + sendBufferSize = sendBufferSize + 4; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 4); + ALMQueueInfo alm_q_info_1 = { 0 }; + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + + + memset(alm_q_info_1.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info_1.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info_1.nSize = sendBufferSize + 1; + alm_q_info_1.infoType = 1; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + } + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 5); + /////////////////end + UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; + UDP_PACKAGE_TYPE = 0x0002; //start type 0x0000 body type 0x0001 end type 0x0002 + contentlen = strlen(q_info_copy.udp_aiengine) - 15000; //len + sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 6); + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, ALMBUFSIZE); + } + + //start code + { + strcat(sendBuffer, "UMV02"); + sendBufferSize = sendBufferSize + 5; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); + sendBufferSize = sendBufferSize + 4; + } + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 7); + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine + 15000, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 8); + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + ALMQueueInfo alm_q_info_2 = { 0 }; + + memset(alm_q_info_2.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info_2.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info_2.nSize = sendBufferSize + 1; + alm_q_info_2.infoType = 1; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) { + ALMQueuePush(alm_q_info_1, sock_idx); + ALMQueuePush(alm_q_info_2, sock_idx); + } + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); + } + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 9); + + } + } +#endif + //getalarmmotion cloud + if(strcmp(SystemSetting.enable_cloud_v2,"Yes")==0 && strcmp(q_info_copy.post_url,"cloud_v2")==0 && strlen(q_info_copy.cloud_v2_aiengine)>=1) + { + memset(sendBuffer, 0x00, sizeof(sendBuffer)); + + unsigned int UNIX_MESSAGE_TYPE_POST_CLOUD = 0x0001; //type + unsigned int contentlen = strlen(q_info_copy.cloud_v2_aiengine); //len + + //printf("\n-----------q_info_copy.cloud_v2_aiengine:%s\n", q_info_copy.cloud_v2_aiengine); + + size_t sendBufferSize = 0; + + //================================================================ + //get sendBuffer + //if sendBuffer size too small, refresh a new one + + //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) + { + //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; + //memset(sendBuffer, 0x00, nmlocsendBufferSize); + } + + //start code + { + strcat(sendBuffer, "UMV01"); + sendBufferSize = sendBufferSize + 5; + } + + //type + { + memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_POST_CLOUD, sizeof(UNIX_MESSAGE_TYPE_POST_CLOUD)); + sendBufferSize = sendBufferSize + 4; + } + //len + { + memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); + sendBufferSize = sendBufferSize + 4; + } + + //#ifdef _DEBUG_AMBA + /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); + printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); + for (int pp = 0;pp < sendBufferSize;pp++) + { + printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); + }*/ + //#endif + + //content + memcpy(sendBuffer + sendBufferSize, q_info_copy.cloud_v2_aiengine, contentlen); + sendBufferSize = sendBufferSize + contentlen; +#ifdef _DEBUG_AMBA + printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); +#endif + //================================================================ + + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + { + + ALMQueueInfo alm_q_info = { 0 }; + + memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); + memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info.nSize = sendBufferSize + 1; + alm_q_info.infoType = 2; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); + } + + /*#ifdef _DEBUG_AMBA + for (int bb = 0;bb < 15;bb++) + { + printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); + } + printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); + #endif*/ + + } + } + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + //send_count = 0; + //printf("UDP 0003 \n"); + + memset(&l_unix_msg, 0, sizeof(UNIX_MESSAGE_V1_T)); + l_unix_msg.type = UNIX_MESSAGE_TYPE_RTSP_META; + + { + //printf("onvif lx, ty, rx, by = %.2f, %.2f, %.2f, %.2f \n", q_info_copy.onvif_object[0].left_x, q_info_copy.onvif_object[0].top_y, q_info_copy.onvif_object[0].right_x, q_info_copy.onvif_object[0].bottom_y); + //printf("onvif cx, cy= %.2f, %.2f \n", q_info_copy.onvif_object[0].center_x, q_info_copy.onvif_object[0].center_y); + + create_onvif_packet(&l_unix_msg, q_info_copy.onvif_object, q_info_copy.onvif_object_num,q_info_copy.onvif_counter); + //printf("l_unix_msg.buf = %s \n", l_unix_msg.buf); + } + + l_unix_msg.length = strlen(l_unix_msg.buf); + if (l_unix_msg.length >= 1) + { + //printf("[%s]\n", l_unix_msg.buf); + l_packet_len = l_unix_msg.length + sizeof(unsigned int) + sizeof(unsigned int); + + memset(l_send_buf, 0, sizeof(l_send_buf)); + + memcpy(l_send_buf, UNIX_MESSAGE_V1, sizeof(UNIX_MESSAGE_V1)); + memcpy(l_send_buf + sizeof(UNIX_MESSAGE_V1) - 1, (char *)&l_unix_msg, l_packet_len); + l_packet_len += sizeof(UNIX_MESSAGE_V1); + + { + ALMQueueInfo alm_q_info = { 0 }; + + memset(alm_q_info.pszContent, 0x00, l_packet_len + 1); + memcpy(alm_q_info.pszContent, l_send_buf, l_packet_len + 1); + //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); + alm_q_info.nSize = l_packet_len + 1; + alm_q_info.infoType = 6; + //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + } + } + } + } + + } + else if(socketRecords[i].isWebSocketConnect == TRUE) + { + //printf("\n------ALMQueueSize(sock_idx):%d\n", ALMQueueSize(sock_idx)); + //printf("\n[run getalarmmotion thread] MultiPartLen:%d\n", MultiPartLen); + //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) + if(strlen(websocket_alarm) >= 1) + { + ALMQueueInfo alm_q_info = { 0 }; + //strcpy(alm_q_info.pszContent,MultiPartBuffer); + strcpy(alm_q_info.pszContent, websocket_alarm); + //strcpy(alm_q_info.websocket_content, websocket_alarm); + //alm_q_info.nSize = strlen(alm_q_info.pszContent); + alm_q_info.nSize = MultiPartLen; + alm_q_info.infoType = 5; + //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); + } + } + } + else if(socketRecords[i].isGetAlarmMotion == TRUE) + { + if (strlen(MultiPartBuffer) >= 1) + { + ALMQueueInfo alm_q_info = { 0 }; + strcpy(alm_q_info.pszContent, MultiPartBuffer); + //strcpy(alm_q_info.websocket_content, websocket_alarm); + //alm_q_info.nSize = strlen(alm_q_info.pszContent); + alm_q_info.nSize = MultiPartLen; + alm_q_info.infoType = 5; + //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); + if (AI_fps >= 1) { + pthread_mutex_lock(&mutex_alm); + if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) + ALMQueuePush(alm_q_info, sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); + } + } + } + } + } + set_record_process_note("run_getalarm_end"); + usSleep(10000); + //printf("\n-------run getalarmmotion end\n"); + } + else { + usSleep(10000); + } + } + + pthread_mutex_lock(&mutex_getalarmmotion); + QueueClear(_GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + + //printf("[run getalarmmotion thread] pthread_exit\n"); + + pthread_exit(NULL); +} + + + +#if 1 +void *run_send_udp_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_udp"); + //printf("\n[run_send_udp_thread]pthread create\n"); + //printf("\n[run_send_udp_thread]no new address\n"); +#ifdef _DEBUG_AMBA + printf("\n[run_send_udp_thread] start\n"); +#endif //_DEBUG_AMBA + + //int thread_id = (int)ptr; + + int l_sockfd; + struct sockaddr_un serveraddr; + char path[64] = "/tmp/udp_unix"; + + // Creating socket file descriptor + bzero(&serveraddr, sizeof(serveraddr)); + //memset(&serveraddr, 0, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, path); + + l_sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); + if (l_sockfd < 0) + { + printf("\nudp socket creation failed\n"); + printf("\n[run_send_udp_thread] udp socket creation failed\n"); + } + else + { + //20210714 ADD + + int reuse = 1; + setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(l_sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = l_sockfd; + + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = TRUE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = TRUE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 2; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + //printf("\n(%d) [run_send_udp_thread] socketRecords[%d].sock:%d\n", l_sockfd, i, socketRecords[i].sock); + socketRecords[i].used = 1; + break; + } + } + + while (bHttpServerThreadStart) + { + //printf("\n----------run send udp thread start\n"); + + int sock_idx = -1; + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //if (socketRecord_ALM[i].sock == l_sockfd) { + //sock_idx = i; + //} + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == l_sockfd) + { + socketRecords[i].debug_type = 2; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + sock_idx = i; + break; + } + } + } + +#ifdef _DEBUG_AMBA + printf("\n(%d) [run_send_udp_thread] sock_idx:%d\n", l_sockfd, sock_idx); +#endif + + if (sock_idx >= 0) + { + pthread_mutex_lock(&mutex_alm); + int len = ALMQueueSize(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\n(%d) [run_send_udp_thread] ALMQueueSize:%d\n", l_sockfd, len); + if (len > 0) + { + set_record_process_note("udp_start"); + //printf("\nKKKKKKKKK 1\n"); + int l_ret = 1; + + for (int index_len = 0; index_len < len; index_len++) { + pthread_mutex_lock(&mutex_alm); + ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); + int dupstr_len = alm_q_info.nSize; + //char dupstr[ALMBUFSIZE] = { 0 }; + + //memset(dupstr, 0x00, dupstr_len); + //memcpy(dupstr, alm_q_info.pszContent, dupstr_len); + + + ALMQueuePop(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\nKKKKKKKKK 2\n"); + if (dupstr_len >= 1) + { + //printf("\nKKKKKKKKK 3\n"); + int l_len = strlen(serveraddr.sun_path) + sizeof(serveraddr.sun_family); + l_ret = sendto(l_sockfd, alm_q_info.pszContent, dupstr_len, 0, (struct sockaddr*)&serveraddr, l_len); + + if (l_ret <= 0) + { + printf("\n(%d) [run_send_udp_thread] send error\n", l_sockfd); + printf("\nsendto error\n"); + + if (alm_q_info.infoType == 2) { + memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); + strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP fail."); + write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + else if (alm_q_info.infoType == 3) { + memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); + strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP fail."); + write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + + //closesocket(l_sockfd); + break; + } + else { + if (alm_q_info.infoType == 2) { + memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); + strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP OK."); + write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); + } + else if (alm_q_info.infoType == 3) { + memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); + strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP OK."); + write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); + } + } + } + else { + if (alm_q_info.infoType == 2) { + memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); + strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: nSize could not be zero."); + write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + else if (alm_q_info.infoType == 3) { + memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); + strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: nSize could not be zero."); + write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); + } + } + + if (index_len < len - 1) { + usSleep(10000); + } + } + + set_record_process_note("udp_end"); + if (l_ret <= 0) + { + break; + } + usSleep(10000); + } + else { + usSleep(10000); + } + } + else { + usSleep(1000000); + } + //printf("\n----------run send udp thread end\n"); + + } + + closesocket(l_sockfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == l_sockfd) + { + socketRecords[i].sock = -1; + + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + pthread_mutex_lock(&mutex_alm); + ALMQueueClear(i); + pthread_mutex_unlock(&mutex_alm); + + socketRecords[i].used = 0; + break; + } + } + } + + //printf("\n[run_send_udp_thread]pthread exit\n"); + pthread_exit(NULL); +} +#endif //GY_OS_AMBA + +#if GY_OS_WIN +int UpdateTrafficLightZone(int tracking_channel_idx) +{ + CPoint zone_polygon[DETECTION_POINTS_COUNT] = { 0 }; + int b_IsInsideZone = 0; + int b_ZoneExist = 0; + + int point_x = 0; + int point_y = 0; + int diagonal_x = 0; + int diagonal_y = 0; + //int zone_width = 0; + //int zone_height = 0; + int traffic_light_zone_idx = viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1; + int min_x = 1920 * 4; + int point_idx = 0; + int diagonal_idx = 0; + for (int k = 0; k < DETECTION_POINTS_COUNT; k++) + { + if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x < min_x) + { + point_idx = k; + min_x = viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x; + } + else if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x == min_x) + { + if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].y < viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y) + { + point_idx = k; + } + } + } + + if (point_idx + 2 >= DETECTION_POINTS_COUNT) + diagonal_idx = point_idx + 2 - DETECTION_POINTS_COUNT; + else + diagonal_idx = point_idx + 2; + + if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x > 0 || viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y > 0) + b_ZoneExist = 1; + + if (b_ZoneExist) + { + point_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + point_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + diagonal_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + diagonal_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + //zone_width = diagonal_x - point_x; + //zone_height = diagonal_y - point_y; + trafficLightPoint.x = point_x; + trafficLightPoint.y = point_y; + traffic_light_zone_width = diagonal_x - point_x; + traffic_light_zone_height = diagonal_y - point_y; + } +} +#endif //GY_OS_WIN - UpdateTrafficLightZone + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void linear_regression(detection_pos** p, int pointCount, double* a, double* b) +{ + double sum_x, sum_x_sqare, sum_y, sum_xy; + double a11, a12, a21, a22, b1, b2; + + sum_x = sum_x_sqare = sum_y = sum_xy = 0.0; + + int validCount = 0; + + double count_top = 0; + double count_middle = 0; + double count_bottom = 0; + + for (int i = 0; i < pointCount; ++i) + { + if (p[i]->left_x < 1 || p[i]->top_y < 1) + continue; + else + { + if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { + count_top++; + } + else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { + count_middle++; + } + else { + count_bottom++; + } + } + } + + double multi_ratio = 1; + if (count_top >= 1.0) { + multi_ratio *= count_top; + } + if (count_middle >= 1.0) { + multi_ratio *= count_middle; + } + if (count_bottom >= 1.0) { + multi_ratio *= count_bottom; + } + + //printf("\n-------count_top:%lf,count_middle:%lf,count_bottom:%lf\n", count_top, count_middle, count_bottom); + + for (int i = 0; i < pointCount; ++i) + { + if (p[i]->left_x < 1 || p[i]->top_y < 1) + continue; + else + { + double temp_multi_ratio = 1.0; + + if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { + temp_multi_ratio = multi_ratio / count_top; + } + else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { + temp_multi_ratio = multi_ratio / count_middle; + } + else { + temp_multi_ratio = multi_ratio / count_bottom; + } + + //sum_x += p[i]->left_x + p[i]->width / 2; + //sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2); + //sum_y += p[i]->top_y + p[i]->height / 2; + //sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2); + + //printf("[%d] x,y, w,h = %f, %f, %f, %f \n", i, p[i]->left_x, p[i]->top_y, p[i]->width, p[i]->height); + + sum_x += (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; + sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; + //sum_y += p[i]->center_y + p[i]->height / 2; + sum_y += (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; + //sum_y += p[i]->center_y; + sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; + + validCount += temp_multi_ratio; + } + } + + a11 = sum_x; + //a12 = pointCount; + a12 = validCount; + a21 = sum_x_sqare; + a22 = sum_x; + b1 = sum_y; + b2 = sum_xy; + + *a = (b1 * a22 - a12 * b2) / (a11 * a22 - a12 * a21); + *b = (a11 * b2 - a21 * b1) / (a11 * a22 - a12 * a21); + + //printf("the line is y = %lf x + %lf\n", *a, *b); +} + +void assign_row_number(detection_pos* PosInfo, detection_pos* pNext1, detection_pos* pNext2, int total_element_size, int element_size2, int parent_idx, float* arc) +{ + detection_pos *detPoints[32]; + double a = 0; + double c = 0; + double dist_tmp = 0; + double dist_up = 0; + double dist_down = 0; + float height_up = 0; + int n_lr = 0; + int element_size_lr2 = element_size2; + int name_len = 0; + + for (int n = 0; n < element_size2; n++) + { + pNext2 = PosInfo + total_element_size + n; + + //printf("\n[assign_row_number] _prefix1 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id,total_element_size,n, total_element_size + n); + + //n_lr = n; + name_len = strlen(pNext2->name); + if (memcmp(pNext2->name, MOVE_FORWARD_PREFIX, strlen(MOVE_FORWARD_PREFIX)) == 0) + { + //printf("\n[assign_row_number] _prefix1 pNext2->name:%s", pNext2->name); + memmove(pNext2->name, pNext2->name + strlen(MOVE_FORWARD_PREFIX), name_len - strlen(MOVE_FORWARD_PREFIX)); + pNext2->name[name_len - strlen(MOVE_FORWARD_PREFIX)] = '\0'; + pNext2->number_row = 0; + pNext2->obj_type = _PREFIX; + element_size_lr2--; + continue; + } + + detPoints[n_lr] = pNext2; + n_lr++; + } + + linear_regression(detPoints, element_size_lr2, &a, &c); + *arc = atan(a); + //float degree = arch * 180 / MATH_PI; + //printf("XXXXXXXXXXXXXXXXX element_size2 = %d \n", element_size2); + + for (int j = 0; j < element_size2; j++) + { + //printf("total_element_size = %d \n", total_element_size); + + pNext2 = PosInfo + total_element_size + j; + pNext2->arc = *arc; + + //printf("\n[assign_row_number] _prefix2 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id, total_element_size, j, total_element_size + j); + + if (pNext2->number_row == 0) + { + //printf("\n[assign_row_number] _prefix2 pNext2->name:%s", pNext2->name); + + pNext2->left_x += pNext1->left_x; + pNext2->top_y += pNext1->top_y; + pNext2->parent_idx = parent_idx; + pNext2->obj_type = _PREFIX; + continue; + } + else + { + if (featureType & FEATURE_LPR_CNT && strcmp(pNext1->name, "L._Plate_CNT_VERTICAL") == 0) { + if ((pNext2->left_x + pNext2->width / 2) <= (pNext2->top_y + pNext2->height / 2) * a + c) + { + pNext2->number_row = 1; + //double sq = sqrt(a*a + (-1)*(-1)); + dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + 1); + if (dist_tmp > dist_up) + { + dist_up = dist_tmp; + height_up = pNext2->width; + } + } + else + { + pNext2->number_row = 2; + dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + (-1)*(-1)); + if (dist_tmp > dist_down) + { + dist_down = dist_tmp; + height_up = pNext2->width; + } + } + } + else { + if ((pNext2->top_y + pNext2->height / 2) <= (pNext2->left_x + pNext2->width / 2) * a + c) + { + pNext2->number_row = 1; + //double sq = sqrt(a*a + (-1)*(-1)); + dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + 1); + if (dist_tmp > dist_up) + { + dist_up = dist_tmp; + height_up = pNext2->height; + } + } + else + { + pNext2->number_row = 2; + dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + (-1)*(-1)); + if (dist_tmp > dist_down) + { + dist_down = dist_tmp; + height_up = pNext2->height; + } + } + } + + pNext2->left_x += pNext1->left_x; + pNext2->top_y += pNext1->top_y; + pNext2->parent_idx = parent_idx; + pNext2->obj_type = _NUMBER; + //printf("Set [%d] parent idx = %d \n", j, parent_idx); + } + } + + if ((dist_up + dist_down) < height_up * 0.5 || (dist_up == 0 && dist_down == 0 && height_up == 0)) + { + for (int j = 0; j < element_size2; j++) + { + pNext2 = PosInfo + total_element_size + j; + if (pNext2->number_row == 0) + { + continue; + } + else + { + pNext2->number_row = 1; + } + } + } +} +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int SortObjects(detection_pos* PosInfo, int total_element_size) +{ + + detection_pos *pNext = NULL, *pFirstNumber = NULL; + int pre_parent_idx = -1; + int sortLogicUSA = 0; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if ((pNext->engine_type == FEATURE_LPR_USA) && pNext->obj_type == _NUMBER) + { + sortLogicUSA = 1; + if (pNext->parent_idx != pre_parent_idx) + { + pFirstNumber = pNext; + pNext->visual_left_x = pNext->left_x; + pre_parent_idx = pNext->parent_idx; + } + else + { + for (int j = 0; j < pNext - pFirstNumber; j++) + { + if ((pFirstNumber + j)->obj_type == _PREFIX) + continue; + if (pNext->left_x + pNext->width / 2 > (pFirstNumber + j)->left_x && pNext->left_x + pNext->width / 2 < (pFirstNumber + j)->left_x + (pFirstNumber + j)->width) + { + pNext->visual_left_x = (pFirstNumber + j)->visual_left_x; + break; + } + else { + pNext->visual_left_x = pNext->left_x; + } + } + } + } + else + { + pNext->visual_left_x = pNext->left_x; + } + } + return sortLogicUSA; + +} +#endif //GY_OS_WIN - SortObjects + +#if 1 +void SetCorrectClassID(detection_pos *PosInfo, int total_element_size, int element_size1) +{ + detection_pos *pNext = NULL, *pNext2 = NULL; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + int nDistance_y = 2160; + + if (g_IsToFDevice == 1) { + if (pNext->class_id == 1) {//hand + pNext->class_id = 250; + } + } + else if (strcmp(pNext->name, "person")==0) { + pNext->class_id = 0; + } + else if (strcmp(pNext->name, "bicycle")==0) { + pNext->class_id = 1; + } + else if (strcmp(pNext->name, "car")==0) { + pNext->class_id = 2; + } + else if (strcmp(pNext->name, "motorbike")==0) { + pNext->class_id = 3; + } + else if (strcmp(pNext->name, "bus")==0) { + pNext->class_id = 5; + } + else if (strcmp(pNext->name, "truck")==0) { + pNext->class_id = 7; + } + else if(IsANPRCategory_L_Plate(pNext->name)){ + if (strcmp(pNext->name, "ambulance") == 0) { + pNext->class_id = 104; + } + + if (strcmp(pNext->name, "stop_sign") == 0) { + pNext->class_id = 11; + } + + if (strncmp(pNext->name, "L._Plate_",9) == 0) { + pNext->class_id = 900; + } + + if (strcmp(pNext->name, "face") == 0) { + pNext->class_id = 0; + } + } + else if (IsANPRCategory(pNext->engine_type)) { + if ((pNext->engine_type & FEATURE_LPR_THA)) { + //ꨮP S19class_idܦ@몺19 + if (pNext->class_id >= 39 && pNext->class_id <= 47) + { + pNext->class_id -= 38; + } + } + } + else { + +#ifdef GY_OS_AMBA + if (strcmp(WeightFileModeName, "mod004") == 0) + { + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + else if (pNext->class_id == 8)//boat + { + pNext->class_id = 158; + } + } + } + else { + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + else if (pNext->class_id == 5)//bus + { + pNext->class_id = 2; + } + else if (pNext->class_id == 6)//train + { + pNext->class_id = 2; + } + else if (pNext->class_id == 7)//truck + { + pNext->class_id = 2; + } + } + } + else { + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + } + } + } +#else + if ((pNext->engine_type & FEATURE_TRAF_DET) && + ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) + )) ///Steven TEMP MARK + { + if (pNext->class_id == 15)//cat + { + pNext->class_id = 247; + } + else if (pNext->class_id == 16)//dog + { + pNext->class_id = 248; + } + } +#endif + + if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) + { + if (pNext->class_id == 39 || + pNext->class_id == 40 || + pNext->class_id == 114) { + pNext->class_id = 39; + } + else if (pNext->class_id == 41 || + pNext->class_id == 45) { + pNext->class_id = 41; + } + else if (pNext->class_id == 110 || + pNext->class_id == 115) { + pNext->class_id = 433; + } + else if (pNext->class_id == 111 || + pNext->class_id == 112) { + pNext->class_id = 19; + } + else if (pNext->class_id == 116 || + pNext->class_id == 117) { + pNext->class_id = 102; + } + else if (pNext->class_id == 118 || + pNext->class_id == 120) { + pNext->class_id = 99; + } + } + + if ((pNext->engine_type & FEATURE_AIFIRE)) + { + //printf("fire id = %d \n", pNext->class_id); + + if (pNext->class_id <= 3) + { + pNext->class_id += 105; + } + else if (pNext->class_id == 6 || pNext->class_id == 7) + { + pNext->class_id += 314; + } + else { + pNext->class_id += 141; + } + } + + if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIAREO)) + { + pNext->class_id += 136; + } + + //printf("\nFEATURE_HUM_DET---1\n"); + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIMASK)) + { + //printf("fire id = %d \n", pNext->class_id); + if (strcmp(WeightFileModeName, "mod003") != 0) { + if (pNext->class_id == 88) + { + pNext->class_id = 80; //face + } + else if (pNext->class_id == 89) + { + pNext->class_id = 81; //half_mask + } + else if (pNext->class_id == 90) + { + pNext->class_id = 82; //mask + } + } + else { + pNext->class_id += 140; + } + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIHELM)) + { + if (pNext->class_id >= 95 && pNext->class_id <= 97) { + pNext->class_id += 1; + } + else if(pNext->class_id == 98){ + pNext->class_id = 318; + } + else if (pNext->class_id >= 99) { + pNext->class_id += 271; + } + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AISHIP)) + { + //printf("fire id = %d \n", pNext->class_id); + pNext->class_id += 150; + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIPRODUCTION)) + { + //printf("fire id = %d \n", pNext->class_id); + + pNext->class_id += 430; + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIAML)) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + //printf("fire id = %d \n", pNext->class_id); + pNext->class_id += 167; + } + else { + pNext->class_id += 340; + } + } + + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIRADAR)) + { + // printf("radar id = %d \n", pNext->class_id); + pNext->class_id += 950; + } + + if ((pNext->engine_type & FEATURE_AIRAIL) && (pNext->engine_type2 & FEATURE_AIFLOW)) + { + if (pNext->class_id >= 3) { + pNext->class_id += 111; + } + else if (pNext->class_id == 9) { + pNext->class_id = 129; + } + else { + pNext->class_id += 110; + } + } + + if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AISPORTS) && strcmp(WeightFileModeName, "mod002") == 0) + { + pNext->class_id += 400; + } + + if ((pNext->engine_type & FEATURE_TRAF_DET)) + { +/*#ifdef GY_OS_AMBA + if (pNext->class_id == 80) + { + pNext->class_id = 88; // TUK TUK + } + else if (pNext->class_id == 81) + { + pNext->class_id = 89; // Truck trailer + } + else if (pNext->class_id == 82) + { + pNext->class_id = 90; // Pickup truck + } +#else + if ( + pNext->class_id == 81 || + pNext->class_id == 82 || + pNext->class_id == 85 + ) + { + pNext->class_id = 2; + } + else if ( + pNext->class_id == 6 || + pNext->class_id == 80 || + pNext->class_id == 83 || + pNext->class_id == 131 || + pNext->class_id == 132 || + pNext->class_id == 133 || + pNext->class_id == 134 + ) { + pNext->class_id = 7; + } +#endif*/ + } + + if ((pNext->engine_type & FEATURE_LPR_LOGO)) + { + pNext->class_id += 500; + + detection_pos* pDistance = NULL; + for (int j = 0; j < total_element_size; j++) + { + pNext2 = PosInfo + j; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + if (pNext->left_x > pNext2->left_x && (pNext->left_x + pNext->width) < (pNext2->left_x + pNext2->width) && pNext->top_y < pNext2->top_y) + { + if (pNext2->top_y - pNext->top_y < nDistance_y) + { + nDistance_y = pNext2->top_y - pNext->top_y; + pDistance = pNext2; + } + } + } + } + if (pDistance) { + + char temp_buf[50] = { 0 }; + int index_temp_buf = 0; + + for (int m = 0; m < (int)strlen(pNext->name); m++) { + if (m < (int)strlen(pNext->name) - 1 && pNext->name[m] == 'l' && pNext->name[m + 1] == '_') { + m++; + } + else { + temp_buf[index_temp_buf] = pNext->name[m]; + index_temp_buf++; + } + } + temp_buf[index_temp_buf] = '\0'; + + snprintf(pDistance->properties.logo, sizeof(pDistance->properties.logo), "%s", temp_buf); + snprintf(pDistance->logo, sizeof(pDistance->logo), "%s", temp_buf); + } + } + } + } + +} +#endif //GY_OS_WIN - SetCorrectClassID + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int IsMatchAUSPattern(char* PlatePattern, char* area) +{ + int nMatchPattern = 0; + if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH)) + { + char *local = "ACT"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH)) + { + char *local = "NSW"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_SLI)) + { + char *local = "NSW"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NTE_VEH)) + { + char *local = "NT"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_QUE_VEH)) + { + char *local = "QUEENSLAND"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_SAU_VEH)) + { + char *local = "SA"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_TAS_VEH)) + { + char *local = "Tasmania"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_VIC_VEH)) + { + char *local = "VICTORIA"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_WAU_VEH)) + { + char *local = "WA"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH_PRE)) + { + char *local = "ACT"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH_PRE)) + { + char *local = "NSW"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 0; + } + + return nMatchPattern; +} +#endif //GY_OS_WIN - IsMatchAUSPattern + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int IsMatchGBRPattern(char* PlatePattern, char* area) +{ + int nMatchPattern = 0; + if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + for (int i = 0; i < strlen(PlatePattern); i++) + { + if (*(PlatePattern + i) == '-') + memmove(PlatePattern + i, PlatePattern + i + 1, strlen(PlatePattern) - i); + } + + if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH_)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH_)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2_)) + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 0; + } + } + + return nMatchPattern; +} +#endif //GY_OS_WIN - IsMatchGBRPattern + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int IsMatchIDNPattern(char* PlatePattern, char* area) +{ + int nMatchPattern = 0; + if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BANT_VEH)) + { + char *local = "Banten"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA1_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG1_VEH)) + { + char *local = "Yogyakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA2_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA1_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA2_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAKA_VEH)) + { + char *local = "Jakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUM_VEH)) + { + char *local = "West Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WCNS_VEH)) + { + char *local = "West coast of North Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BENG_VEH)) + { + char *local = "Bengkulu"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_LAMP_VEH)) + { + char *local = "Lampung"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSUM_VEH)) + { + char *local = "South Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAMB_VEH)) + { + char *local = "Jambi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ECNS_VEH)) + { + char *local = "East coast of North Sumatra"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ACEH_VEH)) + { + char *local = "Aceh"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RIAU_VEH)) + { + char *local = "Riau"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BBEL_VEH)) + { + char *local = "Bangka Belitung"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RISL_VEH)) + { + char *local = "Riau Islands"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA1_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SKAL_VEH)) + { + char *local = "South Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU1_VEH)) + { + char *local = "North Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUL_VEH)) + { + char *local = "West Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU1_VEH)) + { + char *local = "South Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_MALU_VEH)) + { + char *local = "Maluku"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NMAL_VEH)) + { + char *local = "North Maluku"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTT_VEH)) + { + char *local = "East Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BALI_VEH)) + { + char *local = "Bali"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU2_VEH)) + { + char *local = "North Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_GORO_VEH)) + { + char *local = "Gorontalo"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CSUL_VEH)) + { + char *local = "Central Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU2_VEH)) + { + char *local = "South Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTL_VEH)) + { + char *local = "West Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SESU_VEH)) + { + char *local = "Southeast Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU3_VEH)) + { + char *local = "South Sulawesi"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA2_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTS_VEH)) + { + char *local = "West Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTF_VEH)) + { + char *local = "East Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTS_VEH)) + { + char *local = "East Nusa Tenggara"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA3_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA3_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA4_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA5_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WKAL_VEH)) + { + char *local = "West Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CKAL_VEH)) + { + char *local = "Central Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EKAL_VEH)) + { + char *local = "East Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NKAL_VEH)) + { + char *local = "North Kalimantan"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA3_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA4_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA5_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA6_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_PAPU_VEH)) + { + char *local = "Papua"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WPAP_VEH)) + { + char *local = "West Papua"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA6_VEH)) + { + char *local = "Central Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA7_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SURA_VEH)) + { + char *local = "Surabaya"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA4_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA8_VEH)) + { + char *local = "East Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG2_VEH)) + { + char *local = "Yogyakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG3_VEH)) + { + char *local = "Yogyakarta"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA5_VEH)) + { + char *local = "West Java"; + memcpy(area, local, strlen(local)); + nMatchPattern = 1; + } + else + { + char *local = ""; + memcpy(area, local, strlen(local)); + nMatchPattern = 0; + } + + return nMatchPattern; +} +#endif //GY_OS_WIN - IsMatchIDNPattern + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int PlatePatternParser(detection_pos* PosInfo, int total_element_size, size_t featureType/*, float arc*/) +{ + //printf("\n[PlatePatternParser] start\n"); + detection_pos *pNext = PosInfo; + //detection_pos *pBeginIndex = NULL; + int nNumCount = 0; + int result = 0; + char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + /*char country[30] = { 0 }; + char area[30] = { 0 };*/ + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + //char *dash = "-"; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->engine_type & FEATURE_LPR_TWN) + { + char country[30] = { 0 }; + char area[30] = { 0 }; + sprintf(country, "%s", "TWN"); + //detection_pos *pNext = PosInfo; + //int nNumCount = 0; + + //եΰ + //for (int i = 0; i < total_element_size; i++) + //{ + //pNext = PosInfo + i; + //sprintf(pNext->name, "%s", "1"); + //pNext->confidence = 35; + //pNext->left_x = 165; + //pNext->top_y = 127; + //pNext->width = 4; + //pNext->height = 26; + //pNext->obj_type == _NUMBER; + //} + + if (pNext->obj_type == _NUMBER) + nNumCount++; + else + continue; + + if (nNumCount == 1) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && + (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + } + else + { + pNext->arc = (pNext->arc > 0) ? pNext->arc : -pNext->arc; + //float angle = arc * 180 / MATH_PI; +#if 0 + if (activeDisplayDash) + { + if (pNext->arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely + { + float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); + //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + else + { + float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + } +#endif + + if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) + { + //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && + ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + nNumCount = 0; + } + } + } +#if 0 + else if (pNext->engine_type & FEATURE_LPR_EUR) + { + char country[30] = { 0 }; + char area[30] = { 0 }; + sprintf(country, "%s", "EUR");//European //EU/UK/IN + //detection_pos *pNext = PosInfo; + //int nNumCount = 0; + + //եΰ + /*for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + sprintf(pNext->name, "%s", "1"); + pNext->confidence = 35; + pNext->left_x = 165; + pNext->top_y = 127; + pNext->width = 4; + pNext->height = 26; + pNext->obj_type == _NUMBER; + }*/ + + if (pNext->obj_type == _NUMBER) + nNumCount++; + else + continue; + + if (nNumCount == 1) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && + (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + } + else + { + arc = (arc > 0) ? arc : -arc; + //float angle = arc * 180 / MATH_PI; + if (activeDisplayDash) + { + if (arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely + { + float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); + //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + else + { + float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); + float distWidth1 = (pNext - 1)->width / 2; + float distWidth2 = pNext->width / 2; + + if (distCenter > (distWidth1 + distWidth2)*1.22) + { + pNext->obj_type = _DASH; + pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; + } + } + } + + if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) + { + //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + + //if (strcmp(pNext->name, "1") == 0) + { + //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. + if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && + ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) + { + //pNext->obj_type = _MISTAKE; + //result++; + } + } + nNumCount = 0; + } + } + } +#endif +#if 0 + else if (pNext->engine_type & FEATURE_LPR_AUS) + { + /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->parent_idx < 0) + continue; + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + }*/ + } + else + { + if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) + { + PossiblePlate[IndexPattern] = dash; + IndexPattern++; + } + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + }*/ + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchAUSPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + } + } + else if (Index0orO > 0) + { + int rows = pow(2, Index0orO); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index0orO * sizeof *array[i]); + } + int *each = malloc(Index0orO * sizeof(int)); + int c = 0; + BinaryDFS(0, Index0orO, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index0orO; j++) + { + if (array[i][j] == _0) + *ElementPos0orO[j] = '0'; + else if (array[i][j] == _O) + *ElementPos0orO[j] = 'O'; + } + //printf("\n"); + if (Index0orO > 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchAUSPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + } + if (each) { + free(each); + each = NULL; + } + for (int i = 0; i < rows; i++) { + if (array[i]) { + free(array[i]); + array[i] = NULL; + } + } + if (array) { + free(array); + array = NULL; + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + ElementPos0orO[i] = NULL; + ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + //} + } +#endif +#if 0 + else if (pNext->engine_type & FEATURE_LPR_EUR)//FEATURE_LPR_GBR + { + /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->parent_idx < 0) + continue; + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + } + else + { + /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) + { + PossiblePlate[IndexPattern] = dash; + IndexPattern++; + }*/ + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) + { + snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); + }*/ + if (bMatch) + break; + } + else if (Index0orO > 0) + { + int rows = pow(2, Index0orO); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index0orO * sizeof *array[i]); + } + int *each = malloc(Index0orO * sizeof(int)); + int c = 0; + BinaryDFS(0, Index0orO, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index0orO; j++) + { + if (array[i][j] == _0) + *ElementPos0orO[j] = '0'; + else if (array[i][j] == _O) + *ElementPos0orO[j] = 'O'; + } + + if (Index0orO > 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + + } + else if (Index0orO > 0 && Index1orI > 0) + { + int rows2 = pow(2, Index1orI); + int **array2; + array2 = malloc(rows2 * sizeof *array2); + for (int index_i = 0; index_i < rows2; index_i++) + { + array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); + } + + int *each2 = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each2, array2, &c); + for (int index_i = 0; index_i < rows2; index_i++) + { + for (int index_j = 0; index_j < Index1orI; index_j++) + { + if (array2[index_i][index_j] == _1) + *ElementPos1orI[index_j] = '1'; + else if (array2[index_i][index_j] == _I) + *ElementPos1orI[index_j] = 'I'; + } + + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int index_i = 0; index_i < rows2; index_i++) { + if (array2[index_i] != NULL) { + free(array2[index_i]); + array2[index_i] = NULL; + } + } + if (array2 != NULL) { + free(array2); + array2 = NULL; + } + + if (each2 != NULL) { + free(each2); + each2 = NULL; + } + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + else if (Index1orI > 0) + { + int rows = pow(2, Index1orI); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index1orI * sizeof *array[i]); + } + int *each = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index1orI; j++) + { + if (array[i][j] == _1) + *ElementPos1orI[j] = '1'; + else if (array[i][j] == _I) + *ElementPos1orI[j] = 'I'; + //printf("%d", array[i][j]); + } + //printf("\n"); + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + ElementPos0orO[i] = NULL; + ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + //} + } +#endif +#if 1 + else if (pNext->engine_type & FEATURE_LPR_GBR) + { + /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; + char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; + char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->parent_idx < 0) + continue; + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + } + else + { + /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) + { + PossiblePlate[IndexPattern] = dash; + IndexPattern++; + }*/ + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) + { + ElementPos0orO[Index0orO] = pNext->name; + Index0orO++; + } + if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) + { + ElementPos1orI[Index1orI] = pNext->name; + Index1orI++; + } + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) + { + snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); + }*/ + if (bMatch) + break; + } + else if (Index0orO > 0) + { + int rows = pow(2, Index0orO); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index0orO * sizeof *array[i]); + } + int *each = malloc(Index0orO * sizeof(int)); + int c = 0; + BinaryDFS(0, Index0orO, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index0orO; j++) + { + if (array[i][j] == _0) + *ElementPos0orO[j] = '0'; + else if (array[i][j] == _O) + *ElementPos0orO[j] = 'O'; + } + + if (Index0orO > 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + + } + else if (Index0orO > 0 && Index1orI > 0) + { + int rows2 = pow(2, Index1orI); + int **array2; + array2 = malloc(rows2 * sizeof *array2); + for (int index_i = 0; index_i < rows2; index_i++) + { + array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); + } + + int *each2 = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each2, array2, &c); + for (int index_i = 0; index_i < rows2; index_i++) + { + for (int index_j = 0; index_j < Index1orI; index_j++) + { + if (array2[index_i][index_j] == _1) + *ElementPos1orI[index_j] = '1'; + else if (array2[index_i][index_j] == _I) + *ElementPos1orI[index_j] = 'I'; + } + + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int index_i = 0; index_i < rows2; index_i++) { + if (array2[index_i] != NULL) { + free(array2[index_i]); + array2[index_i] = NULL; + } + } + if (array2 != NULL) { + free(array2); + array2 = NULL; + } + + if (each2 != NULL) { + free(each2); + each2 = NULL; + } + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + else if (Index1orI > 0) + { + int rows = pow(2, Index1orI); + int **array; + array = malloc(rows * sizeof *array); + for (int i = 0; i < rows; i++) + { + array[i] = malloc(Index1orI * sizeof *array[i]); + } + int *each = malloc(Index1orI * sizeof(int)); + int c = 0; + BinaryDFS(0, Index1orI, each, array, &c); + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < Index1orI; j++) + { + if (array[i][j] == _1) + *ElementPos1orI[j] = '1'; + else if (array[i][j] == _I) + *ElementPos1orI[j] = 'I'; + //printf("%d", array[i][j]); + } + //printf("\n"); + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchGBRPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + break; + } + } + + for (int i = 0; i < rows; i++) { + if (array[i] != NULL) { + free(array[i]); + array[i] = NULL; + } + } + if (array != NULL) { + free(array); + array = NULL; + } + + if (each != NULL) { + free(each); + each = NULL; + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + ElementPos0orO[i] = NULL; + ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + //} + } +#endif + +#if 0 + else if (pNext->engine_type & FEATURE_LPR_IDN) + { + /*char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; + int Index0orO = 0, Index1orI = 0, IndexPattern = 0; + char *dash = "-"; + detection_pos *pNext = PosInfo*/ + //for (int i = 0; i < total_element_size; i++) + //{ + pNext = PosInfo + i; + if (pNext->obj_type == _NUMBER) + { + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + //pBeginIndex = PosInfo + i; + } + else + { + if (strlen(pNext->name) > 5) + printf("Test number"); + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + char area[30] = { 0 }; + int bMatch = IsMatchIDNPattern(PlatePattern, area); + if (bMatch) + { + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "IDN"); + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + } + } + + for (int i = 0; i < MAX_PLATE_NUMBER; i++) + { + //ElementPos0orO[i] = NULL; + //ElementPos1orI[i] = NULL; + PossiblePlate[i] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + } + //} + } +#endif + else + { + //if (pNext->engine_type & FEATURE_LPR_TWN) + // sprintf(country, "%s", "TWN"); + char country[30] = { 0 }; + char area[30] = { 0 }; + int area_id = -1; + pNext->properties.area_id = area_id; + + /*if (pNext->engine_type & FEATURE_LPR_CNA) + sprintf(country, "%s", "CNA");*/ + if (pNext->engine_type & FEATURE_LPR_USA) + sprintf(country, "%s", "USA/CA"); + else if (pNext->engine_type & FEATURE_LPR_EUR) + sprintf(country, "%s", "EUR"); + /*else if (pNext->engine_type & FEATURE_LPR_TWN) + sprintf(country, "%s", "TWN");*/ + else if (pNext->engine_type & FEATURE_LPR_JPN) + sprintf(country, "%s", "JPN"); + else if (pNext->engine_type & FEATURE_LPR_BGD) + sprintf(country, "%s", "BGD"); + else if (pNext->engine_type & FEATURE_LPR_MEA) + sprintf(country, "%s", "MEA"); + else if (pNext->engine_type & FEATURE_LPR_SEA || + pNext->engine_type & FEATURE_LPR_IDN || + pNext->engine_type & FEATURE_LPR_VNM) + sprintf(country, "%s", "SEA"); + else if (pNext->engine_type & FEATURE_LPR_THA) + sprintf(country, "%s", "THA"); + else if (pNext->engine_type & FEATURE_LPR_LAO) + sprintf(country, "%s", "LAO"); + else if (pNext->engine_type & FEATURE_LPR_PHL) + sprintf(country, "%s", "PHL"); + else if (pNext->engine_type & FEATURE_LPR_CNT) + sprintf(country, "%s", "CNT"); + else if (pNext->engine_type & FEATURE_LPR_AUS) + sprintf(country, "%s", "AUS"); + else + sprintf(country, "%s", ""); + + if (IsANPRCategory(pNext->engine_type)) + { + //pNext = PosInfo + i; + + /*if (pNext->class_id >= 0) + { + if (strcmp(ppIniKeyValue[pNext->class_id], "") != 0) + { + strcpy(pNext->name, ppIniKeyValue[pNext->class_id]); + } + }*/ + + if (pNext->obj_type == _PLATE || pNext->obj_type == _LOGO) + continue; + + + if (pNext->obj_type == _PREFIX) + { + //printf("\n[PlatePatternParser]pNext->obj_type == _PREFIX area:%s area_id:%d\n", pNext->name, pNext->class_id); + sprintf(area, "%s", pNext->name); + area_id = pNext->class_id; + + // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty + + if (featureType & FEATURE_LPR_JPN /*|| featureType & FEATURE_LPR_CNA*/) + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + } + else + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + } + } + + + + if (IndexPattern == 0) + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + } + else + { + PossiblePlate[IndexPattern] = pNext->name; + IndexPattern++; + + if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) + { + if (Index0orO <= 0 && Index1orI <= 0) + { + int m = 0; + //char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; + while (PossiblePlate[m] != NULL) + { + //PlatePattern[m] = *PossiblePlate[m]; + m++; + } + + snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); + // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty + /*if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_CNA) + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + } + else + { + snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); + (PosInfo + pNext->parent_idx)->properties.area_id = area_id; + }*/ + + //break; + } + + for (int j = 0; j < MAX_PLATE_NUMBER; j++) + { + //ElementPos0orO[i] = NULL; + //ElementPos1orI[i] = NULL; + PossiblePlate[j] = NULL; + IndexPattern = 0; + Index0orO = 0; + Index1orI = 0; + } + } + } + } + } + } + //printf("\n[PlatePatternParser] end\n"); + return result; +} +#endif //GY_OS_WIN - PlatePatternParser + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void ReplaceWithUTF8(detection_pos* PosInfo, int total_element_size) +{ + detection_pos *pNext = NULL; + int layer_idx = 0; + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (i > 0 && pNext->parent_idx >= 0) + { + //printf("\npNext->engine_type\n") + + + //if ( ((pNext->engine_type == (pNext - 1)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((pNext - 1)->engine_type) && pNext->obj_type == _NUMBER && (pNext - 1)->obj_type == _PLATE) ) + if (((pNext->engine_type == (PosInfo + pNext->parent_idx)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((PosInfo + pNext->parent_idx)->engine_type) && (pNext->obj_type == _NUMBER || pNext->obj_type == _PREFIX) && (PosInfo + pNext->parent_idx)->obj_type == _PLATE)) + { + + for (int j = 0; j < MAX_LAYER_NUM; j++) + { + if (j > 0) + { + if (layerFeatureType[j - 1] == pNext->engine_type && layerFeatureType[j] == pNext->engine_type) + { + layer_idx = j; + break; + } + } + } + + if (pNext->class_id >= 0) + { + if (strcmp(ppIniKeyValue[layer_idx][pNext->class_id], "") != 0) + { + strcpy(pNext->name, ppIniKeyValue[layer_idx][pNext->class_id]); + } + } + } + } + + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + for (int j = 0; j < MAX_LAYER_NUM - 1; j++) + { + if (layerFeatureType[j] == pNext->engine_type && layerFeatureType[j + 1] == pNext->engine_type) + { + layer_idx = j + 1; + break; + } + } + + if (pNext->properties.area_id >= 0) + { + if (strcmp(ppIniKeyValue[layer_idx][pNext->properties.area_id], "") != 0) + { + strcpy(pNext->properties.area, ppIniKeyValue[layer_idx][pNext->properties.area_id]); + } + } + } + } +} + +void AssignPlateNumber(detection_pos* PosInfo, int total_element_size, int featureType) +{ + detection_pos* pNext = NULL; + detection_pos* pNext2 = NULL; + detection_pos* pNext_correct = NULL; + int differ_top_y = 20; + + int mea_record_idx = 0; + +#if 0 + int record_correct_PosInfo_i_order[256]; + int record_first_PosInfo_i = 0; + int min_top_y = 100000; + + for (int i = 0; i < 256; i++) { + if (i < total_element_size) { + record_correct_PosInfo_i_order[i] = i; + } + else { + record_correct_PosInfo_i_order[i] = -1; + } + } + + //Selection Sort: pNext->left_x + for (int i = 0; i < total_element_size; i = i + 1) + { + pNext = PosInfo + i; + for (int j = i + 1; j < total_element_size; j = j + 1) + { + pNext2 = PosInfo + j; + if (pNext->left_x > pNext2->left_x) + { + //ܼƥ洫 + int tmp_record_i = record_correct_PosInfo_i_order[i]; + record_correct_PosInfo_i_order[i] = record_correct_PosInfo_i_order[j]; + record_correct_PosInfo_i_order[j] = tmp_record_i; + } + } + + if (pNext->top_y < min_top_y) + { + min_top_y = pNext->top_y; + } + } + + for (int i = 0; i < total_element_size; i = i + 1) + { + pNext = PosInfo + record_correct_PosInfo_i_order[i]; + if (abs((int)((pNext->top_y - min_top_y) / min_top_y * 100)) <= differ_top_y) { + record_first_PosInfo_i = i; + break; + } + } +#endif + int enable_the_first_word = 0; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (IsANPRCategory(pNext->engine_type)) + { + + if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) + { + if (pNext->obj_type == _PREFIX) + { + if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) + continue; + } +#if 0 + if (featureType & FEATURE_LPR_TWN) { + if (activeDisplayDash) + { + if (pNext->obj_type == _DASH) + { + if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { + strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); + } + } + } + } +#endif + //printf("\n------pNext->width:%f\n", pNext->width); + +#if 0 + if (featureType & FEATURE_LPR_SEA) { + if (pNext->width < 1) + continue; + } + else { + if (get_g_ori_yuv_width() <= 1280) { + if (pNext->width < 70) + continue; + } + else { + if (pNext->width < 100) + continue; + } + } +#endif + //if (strcmp(pNext->name, "_") == 0) + // strcpy(pNext->name, " "); + + //printf("\n----------area:%s\n", (PosInfo + pNext->parent_idx)->properties.area); + + if (featureType & FEATURE_LPR_USA) { + if (strlen((PosInfo + pNext->parent_idx)->properties.area)>=1) { + differ_top_y = 20; + } + else { + differ_top_y = 200; + } + } + else if (featureType & FEATURE_LPR_TWN) { + differ_top_y = 20; + //printf("\n---------TW\n"); + } + else { + differ_top_y = 20; + } + + int check_if_the_first_word = 0; + if (enable_the_first_word == 0) { + for (int j = i + 1; j < total_element_size; j++) { + pNext2 = PosInfo + j; + //printf("\n-----yyyy:%d,%f,%f\n", abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)), pNext->top_y, pNext2->top_y); + if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { + + } + else { + if (pNext->top_y <= pNext2->top_y) { + + } + else { + check_if_the_first_word = 1; + } + } + + enable_the_first_word = 1; + break; + } + } + + int check_the_same_left_x = 0; + + for (int j = i - 1; j < i && j >= 0; j++) { + pNext2 = PosInfo + j; + if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { + if ((j - 1) >= 0) { + pNext_correct = PosInfo + (j - 1); + if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { + (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); + } + } + check_the_same_left_x = 1; + } + break; + } + + + if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { + if (strlen((PosInfo + pNext->parent_idx)->properties.plate) == 0) { + if (featureType & FEATURE_LPR_MEA) { + //printf("area: %s, country: %s \n", (PosInfo + pNext->parent_idx)->properties.area, (PosInfo + pNext->parent_idx)->properties.country); + + //check number level + //printf("B level: %d , s = %s\n", pNext->number_row, pNext->name); + + memset((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, '\0', sizeof((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name)); + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = 0; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = 0; + + + ///record mea number + (PosInfo + pNext->parent_idx)->plate_number_count = 0; + mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; + + if (isdigit(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; + //printf("isdigit: %s \n", pNext->name); + } + + if (isalpha(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; + //printf("isalpht: %s \n", pNext->name); + } + + strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; + + //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); + + (PosInfo + pNext->parent_idx)->plate_number_count++; + + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; + } + else { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; + } + + //float temp = pNext->confidence; + //(PosInfo + pNext->parent_idx)->confidence = temp; + //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + } + else { + if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) + { + if (featureType & FEATURE_LPR_MEA) + { + + //check number level + //printf("A level: %d , s = %s, box_x = %f\n", pNext->number_row, pNext->name, pNext->box_x); + + ///record mea number + mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; + + if (isdigit(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; + //printf("isdigit: %s \n", pNext->name); + } + + if (isalpha(pNext->name[0]) != 0) + { + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; + //printf("isalpht: %s \n", pNext->name); + } + + strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; + (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; + + //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); + + (PosInfo + pNext->parent_idx)->plate_number_count++; + + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + //printf("plate %d name = %s, y = %f, plate_y = %f, row = %d\n", i, (PosInfo + pNext->parent_idx)->properties.plate, pNext->top_y, (PosInfo + pNext->parent_idx)->plate_char_top_y, pNext->number_row); + } + else { + if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + + //float temp = (PosInfo + pNext->parent_idx)->confidence; + //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); + } + } + } + else { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + //float temp = (PosInfo + pNext->parent_idx)->confidence; + //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); + } + //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + } + } + + + } + } + } + + enable_the_first_word = 0; + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (IsANPRCategory(pNext->engine_type)) + { + if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) + { + + if (pNext->obj_type == _PREFIX) + { + if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) + continue; + } +#if 0 + if (featureType & FEATURE_LPR_TWN) { + if (activeDisplayDash) + { + if (pNext->obj_type == _DASH) + { + if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { + strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); + } + } + } + } +#endif +#if 0 + if (get_g_ori_yuv_width() <= 1280) { + if (pNext->width < 70) + continue; + } + else { + if (pNext->width < 100) + continue; + } +#endif + + if (featureType & FEATURE_LPR_USA) { + if (strlen((PosInfo + pNext->parent_idx)->properties.area) >= 1) { + differ_top_y = 20; + } + else { + differ_top_y = 200; + } + } + else if (featureType & FEATURE_LPR_TWN) { + differ_top_y = 20; + } + else { + differ_top_y = 20; + } + + int check_if_the_first_word = 0; + if (enable_the_first_word == 0) { + for (int j = i + 1; j < total_element_size; j++) { + pNext2 = PosInfo + j; + + if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { + check_if_the_first_word = 1; + } + else { + if (pNext->top_y <= pNext2->top_y) { + check_if_the_first_word = 1; + } + else { + + } + } + + enable_the_first_word = 1; + break; + } + } + + int check_the_same_left_x = 0; + + for (int j = i - 1; j < i && j >= 0; j++) { + pNext2 = PosInfo + j; + if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { + if ((j - 1) >= 0) { + pNext_correct = PosInfo + (j - 1); + if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { + (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); + } + } + check_the_same_left_x = 1; + + } + break; + } + + if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { + if (strlen((PosInfo + pNext->parent_idx)->properties.plate) >= 0) { + if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) + { + if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { + + } + else { + strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); + //float temp = (PosInfo + pNext->parent_idx)->confidence; + //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); + } + } + //printf("[2]%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + } + } + } + } + } +} +#endif +void ReplacePlateWithDB(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { + detection_pos *pNext = NULL; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_type != _PLATE) + { + continue; + } + + if (strlen(pNext->properties.plate) <= 0) + { + continue; + } + + if (pNext->confidence <= 0.0) + { + continue; + } + + if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) + { + for (int index_levenshtein = 0; index_levenshtein <= atoi(viewChannelData[tracking_channel_idx].levenshtein_distance); index_levenshtein++) { + int check_if_OK = 0; + + char afterBuf[256] = { 0 }; + strcpy(afterBuf, pNext->properties.plate); + + char afterBuf_dest[256] = { 0 }; + + if (check_if_in_white(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { + if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { + strcpy(pNext->properties.plate, afterBuf_dest); + } + check_if_OK = 1; + break; + } + else if (check_if_in_black(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { + if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { + strcpy(pNext->properties.plate, afterBuf_dest); + } + check_if_OK = 1; + break; + } + + if (check_if_OK == 1) + break; + } + } + else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + pNext->confidence = 0.0; + } + } +} + +void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType,int tracking_channel_idx) { + detection_pos *pNext = NULL,*pNext1 = NULL; + detection_pos pNext_plate; + double iDiffSec = 0.0; + //float diff_box_y = 0; + + //g_PlateFilterTime = 3; + //g_PlateFilterTimes = 10; + //g_PlateRecorderFreeTime = 6; + g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; + g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; + //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; + + g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 + if (g_PlateRecorderFreeTime == 0) { + g_PlateRecorderFreeTime = 1; + } + + if (g_PlateFilterTime == 0) { + g_PlateFilterTime = 1; + } + + if (g_PlateFilterTimes == 0) { + g_PlateFilterTimes = 1; + } + + //AۦPPu1C + //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); + + //Free over Recoder time + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_UpdateTime); + //printf("\nFFF------------[%d]iDiffSec:%lf,g_PlateRecorderFreeTime:%d\n",j, iDiffSec, g_PlateRecorderFreeTime); + if (g_PlateRecorderFreeTime >= 1 && iDiffSec > (double)g_PlateRecorderFreeTime) + { + g_PlateRecorderList[j].iGetCounter = 0; + g_PlateRecorderList[j].t_UpdateTime = 0; + g_PlateRecorderList[j].t_FirstGetTime = 0; + g_PlateRecorderList[j].t_LoopTime = 0; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PlateRecorderList[j].check_if_counted[m] = 0; + } + g_PlateRecorderList[j].iIfUse = 0; + } + } + } + + //printf("---------> ver EEE \n"); + + //Filter plate by time and frequency + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->confidence <= 0.0) + { + continue; + } + + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + { +#if 1 + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + pNext_plate.left_x = g_PlateRecorderList[j].box_x; + pNext_plate.top_y = g_PlateRecorderList[j].box_y; + pNext_plate.width = g_PlateRecorderList[j].box_w; + pNext_plate.height = g_PlateRecorderList[j].box_h; + pNext_plate.center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2.0; + pNext_plate.center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2.0; + + + + if ((detection_overlap_ratio(&pNext_plate, pNext) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(&pNext_plate, pNext) > (90.0 / 100.0) || ((pNext_plate.center_x <= pNext->left_x + pNext->width && pNext_plate.center_x >= pNext->left_x) && + (pNext_plate.center_y <= pNext->top_y + pNext->height && pNext_plate.center_y >= pNext->top_y)) + ) + { + pNext->linked_plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->linked_plate); + strcpy(pNext->car_type_name, pNext->name); + break; + } + } + } +#endif + } + else if(IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) + { + char afterBuf[256] = { 0 }; + + strcpy(afterBuf, pNext->properties.plate); + + //printf("\n-----------afterBuf:%s\n", afterBuf); + + pNext->properties.plate_length = Modify_Plate_and_Recount_Length(afterBuf, pNext->properties.plate); + + //printf("\n-----------[fff]pNext->properties.plate:%s\n", pNext->properties.plate); + + pNext->linked_plate_length = pNext->properties.plate_length; + strcpy(pNext->linked_plate, pNext->properties.plate); + + if ((pNext->properties.plate_length < atoi(viewChannelData[0].min_characters) || + pNext->properties.plate_length > atoi(viewChannelData[0].max_characters)) && strcmp(pNext->name, "ambulance") != 0 && strcmp(pNext->name, "blank") != 0 && strcmp(pNext->name, "stop_sign") != 0 && strcmp(pNext->name, "face") != 0) + { + + } + else + { + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET) { + if (viewChannelData[0].enable_traffic) { + for (int m = 0; m < total_element_size; m++) { + pNext1 = PosInfo + m; + if (IsVehicleCategory(pNext1) || IsMotorbikeCategory(pNext1)) { + if (detection_overlap_ratio(pNext, pNext1) > (90.0 / 100.0) || ((pNext->center_x <= pNext1->left_x + pNext1->width && pNext->center_x >= pNext1->left_x) && + (pNext->center_y <= pNext1->top_y + pNext1->height && pNext->center_y >= pNext1->top_y)) + ) + { + strcpy(pNext->car_type_name, pNext1->name); + break; + } + } + } + } + } + + int iFindMatchPlate = 0; + int index_g_PlateRecorderList_max = -1; + int iGetCounter_max = 0; + int record_plate_index[MAX_PLATE_RECORDER] = { 0 }; + int size_record_plate = 0; + + //printf("\n-----------Plate:%s\n", pNext->properties.plate); + + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 + && strcmp(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) + { + iFindMatchPlate = 1; + g_PlateRecorderList[j].t_UpdateTime = time(0); + g_PlateRecorderList[j].iGetCounter++; + + if (strlen(pNext->car_type_name) >= 1) { + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + } + else { + strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); + } + + g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; + g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; + g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; + g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; + + g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; + g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { + if (g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes + 100) + { + g_PlateRecorderList[j].iGetCounter = g_PlateFilterTimes + 100; + } + } + break; + } + } + } + + if (iFindMatchPlate == 0) + { + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 0) + { + if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { + if (strstr(pNext->properties.plate, "-") != NULL) { + g_PlateRecorderList[j].existing_dash = 1; + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + + if (strcmp(pNext->name, "ambulance") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "blank") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); + } + + g_PlateRecorderList[j].t_FirstGetTime = time(0); + g_PlateRecorderList[j].t_LoopTime = 0; + g_PlateRecorderList[j].t_UpdateTime = time(0); + g_PlateRecorderList[j].iGetCounter = 1; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PlateRecorderList[j].check_if_counted[m] = 0; + } + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + g_PlateRecorderList[j].last_box_x = pNext->left_x; + g_PlateRecorderList[j].last_box_y = pNext->top_y; + g_PlateRecorderList[j].last_box_w = pNext->width; + g_PlateRecorderList[j].last_box_h = pNext->height; + + g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; + g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; + + g_PlateRecorderList[j].iPlateZoomOutCounter = 0; + g_PlateRecorderList[j].iPlateZoomInCounter = 0; + + g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + + g_PlateRecorderList[j].iIfUse = 1; + iFindMatchPlate = 1; + break; + } + } + + if (iFindMatchPlate == 0) { + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iGetCounter <= 0) + { + if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { + if (strstr(pNext->properties.plate, "-") != NULL) { + g_PlateRecorderList[j].existing_dash = 1; + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + } + else { + g_PlateRecorderList[j].existing_dash = 0; + } + + if (strcmp(pNext->name, "ambulance") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "blank") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); + } + else { + sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); + } + + g_PlateRecorderList[j].t_FirstGetTime = time(0); + g_PlateRecorderList[j].t_LoopTime = 0; + g_PlateRecorderList[j].t_UpdateTime = time(0); + g_PlateRecorderList[j].iGetCounter = 1; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PlateRecorderList[j].check_if_counted[m] = 0; + } + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + g_PlateRecorderList[j].last_box_x = pNext->left_x; + g_PlateRecorderList[j].last_box_y = pNext->top_y; + g_PlateRecorderList[j].last_box_w = pNext->width; + g_PlateRecorderList[j].last_box_h = pNext->height; + + g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; + g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; + + g_PlateRecorderList[j].iPlateZoomOutCounter = 0; + g_PlateRecorderList[j].iPlateZoomInCounter = 0; + + g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + + g_PlateRecorderList[j].iIfUse = 1; + iFindMatchPlate = 1; + break; + } + } + } + } + + time_t early_t_FirstGetTime = time(0); + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + //printf("\n-----sPlateNumber:%s,plate:%s,levenshtein_distance:%d\n", g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && + LevenshteinDistance(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + + if (g_PlateRecorderList[j].t_FirstGetTime < early_t_FirstGetTime) { + early_t_FirstGetTime = g_PlateRecorderList[j].t_FirstGetTime; + } + + record_plate_index[size_record_plate] = j; + size_record_plate++; + } + } + } + + for (int temp_j = 0; temp_j < size_record_plate; temp_j++) + { + int j = record_plate_index[temp_j]; + g_PlateRecorderList[j].t_FirstGetTime = early_t_FirstGetTime; + + if (g_PlateRecorderList[j].iGetCounter > iGetCounter_max || + (index_g_PlateRecorderList_max >= 0 && iGetCounter_max >= 1 && g_PlateRecorderList[j].iGetCounter == iGetCounter_max && g_PlateRecorderList[j].t_UpdateTime > g_PlateRecorderList[index_g_PlateRecorderList_max].t_UpdateTime)) { + + iDiffSec = difftime(time(0), g_PlateRecorderList[j].t_FirstGetTime); + if (iDiffSec >= (double)g_PlateFilterTime || g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes) + { + index_g_PlateRecorderList_max = j; + iGetCounter_max = g_PlateRecorderList[j].iGetCounter; + } + } + + //printf("\n---iGetCounter:%d,iGetCounter_max:%d,%s\n", g_PlateRecorderList[j].iGetCounter, iGetCounter_max, g_PlateRecorderList[j].sPlateNumber); + } + + if (index_g_PlateRecorderList_max >= 0) { + int j = index_g_PlateRecorderList_max; + iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_FirstGetTime); + + if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { + + if (strlen(pNext->car_type_name) >= 1) { + strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); + } + else { + strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); + } + + g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; + g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; + g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; + g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; + + g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; + g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; + + g_PlateRecorderList[j].box_x = pNext->left_x; + g_PlateRecorderList[j].box_y = pNext->top_y; + g_PlateRecorderList[j].box_w = pNext->width; + g_PlateRecorderList[j].box_h = pNext->height; + + //printf("\n-----------[%d]pNext->properties.plate up:%s,g_Plate:%s\n",j, pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber); + pNext->properties.plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate); + //printf("\n-----------pNext->properties.plate down:%s\n", pNext->properties.plate); + pNext->linked_plate_length = pNext->properties.plate_length; + strcpy(pNext->linked_plate, pNext->properties.plate); + + if((int)iDiffSec > 0 && ((int)iDiffSec) % g_PlateFilterTime == 0){ + for (int index_record = 0; index_record < size_record_plate; index_record++) { + if (record_plate_index[index_record] != j) { + g_PlateRecorderList[index_record].iGetCounter = (g_PlateRecorderList[index_record].iGetCounter / 2) - 1; + if(g_PlateRecorderList[index_record].iGetCounter <= 0) + g_PlateRecorderList[index_record].iGetCounter = 0; + } + } + } + + if (strcmp(heartbeatData.enable_only_once_to_post, "Yes") == 0) { + if (g_PlateRecorderList[j].t_LoopTime == 0) { + g_PlateRecorderList[j].t_LoopTime = time(0); + } + + double iDiffLoopSec = difftime(time(0), g_PlateRecorderList[j].t_LoopTime); + if ((int)iDiffLoopSec > 0 && ((int)iDiffLoopSec) % g_PlateFilterTime == 0) { + for (int k = 0; k < MAX_TRACKING_NUM; k++) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1 && + strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, g_PlateRecorderList[j].sPlateNumber) == 0) + { + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + pNext->check_if_having_been_counted[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][k].check_if_having_been_counted[index_zone] = 0; + g_PlateRecorderList[j].check_if_counted[index_zone] = 0; + } + g_TrackingRecords[tracking_channel_idx][k].disappear_count = 0; + break; + } + } + + for (int k = 0; k < MAX_POST_RECODER_SIZE; k++) + { + if (g_PostRecorderList[k].iIfUse == 0 && g_longterm_PostRecorderList[k].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[k].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + g_PostRecorderList[k].iIfUse = 0; + g_PostRecorderList[k].t_FirstGetTime = 0; + g_PostRecorderList[k].t_FirstGetTime_total = 0; + g_PostRecorderList[k].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[k].check_if_post[m] = 0; + } + g_PostRecorderList[k].check_if_cloud = 0; + g_PostRecorderList[k].check_if_cloud_v2 = 0; + g_PostRecorderList[k].check_if_cloud_record_v2 = 0; + g_PostRecorderList[k].check_if_email = 0; + g_PostRecorderList[k].check_if_ftp = 0; + g_PostRecorderList[k].check_if_getalarmmotion = 0; + + g_PostRecorderList[k].box_x = 0; + g_PostRecorderList[k].box_y = 0; + g_PostRecorderList[k].box_w = 0; + g_PostRecorderList[k].box_h = 0; + + g_PostRecorderList[k].object_id = 0; + g_PostRecorderList[k].zone_idx = 0; + strcpy(g_PostRecorderList[k].sPlateNumber, ""); + + g_PostRecorderList[k].count_trigger = 0; + //g_PostRecorderList[k].the_same_id = 0; + } + } + + if (g_longterm_PostRecorderList[k].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_longterm_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + g_longterm_PostRecorderList[k].iIfUse = 0; + g_longterm_PostRecorderList[k].t_FirstGetTime = 0; + g_longterm_PostRecorderList[k].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[k].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[k].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[k].check_if_cloud = 0; + g_longterm_PostRecorderList[k].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[k].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[k].check_if_email = 0; + g_longterm_PostRecorderList[k].check_if_ftp = 0; + g_longterm_PostRecorderList[k].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[k].box_x = 0; + g_longterm_PostRecorderList[k].box_y = 0; + g_longterm_PostRecorderList[k].box_w = 0; + g_longterm_PostRecorderList[k].box_h = 0; + + g_longterm_PostRecorderList[k].object_id = 0; + g_longterm_PostRecorderList[k].zone_idx = 0; + strcpy(g_longterm_PostRecorderList[k].sPlateNumber, ""); + + g_longterm_PostRecorderList[k].count_trigger = 0; + //g_longterm_PostRecorderList[k].the_same_id = 0; + } + } + } + + g_PlateRecorderList[j].t_LoopTime = time(0); + } + } + + g_PlateRecorderList[j].t_UpdateTime = time(0); + for (int index_record = 0; index_record < size_record_plate; index_record++) { + if (record_plate_index[index_record] != j) { + g_PlateRecorderList[index_record].t_UpdateTime = time(0); + } + } + } + } + else { + pNext->confidence = 0; + } + } + + } + else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + pNext->confidence = 0.0; + } + } + + qsort(&g_PlateRecorderList, MAX_PLATE_RECORDER, sizeof(PlateRecoder), sort_record_plate); +} + +void ObjectFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { + + detection_pos *pNext = NULL/*, *pNext1 = NULL*/; + //detection_pos pNext_plate; + double iDiffSec = 0.0; + //float diff_box_y = 0; + + //g_PlateFilterTime = 3; + //g_PlateFilterTimes = 10; + //g_PlateRecorderFreeTime = 6; + //g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; + //g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; + //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; + + //g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 + //if (g_PlateRecorderFreeTime == 0) { + //g_PlateRecorderFreeTime = 2; + //} + + int object_free_time = atoi(SystemSetting.tracking_id_dwell) + 1;//2 + + //AۦPPu1C + //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); + + //Free over Recoder time + for (int j = 0; j < MAX_OBJECT_RECORDER; j++) + { + if (g_ObjectRecorderList[j].iIfUse == 1) + { + iDiffSec = difftime(time(0),g_ObjectRecorderList[j].t_UpdateTime); + //printf("\nEEE------------iDiffSec:%d\n", iDiffSec); + if (object_free_time >= 1 && iDiffSec > (double)object_free_time) + { + g_ObjectRecorderList[j].iIfUse = 0; + g_ObjectRecorderList[j].iGetCounter = 0; + g_ObjectRecorderList[j].t_UpdateTime = 0; + g_ObjectRecorderList[j].t_FirstGetTime = 0; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_ObjectRecorderList[j].check_if_counted[m] = 0; + } + g_ObjectRecorderList[j].box_x = 0; + g_ObjectRecorderList[j].box_y = 0; + g_ObjectRecorderList[j].box_w = 0; + g_ObjectRecorderList[j].box_h = 0; + g_ObjectRecorderList[j].iTrackingID = 0; + } + } + } + + //printf("---------> ver EEE \n"); + + //Filter plate by time and frequency + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_tracking_id_idx < 0 || pNext->obj_tracking_id <= 0) { + + } + else { + if (IsANPRCategory(pNext->engine_type)) { + + } + else { + if (strlen(pNext->name) >= 1) + { + int iFindMatchObject = 0; + + for (int j = 0; j < MAX_OBJECT_RECORDER; j++) + { + //printf("if %d use = %d \n", j, g_ObjectRecorderList[j].iIfUse); + if (g_ObjectRecorderList[j].iIfUse == 1) + { + if (g_ObjectRecorderList[j].iTrackingID == pNext->obj_tracking_id) + { + //printf("find match id \n"); + iFindMatchObject = 1; + g_ObjectRecorderList[j].t_UpdateTime = time(0); + //g_ObjectRecorderList[j].iGetCounter++; + + //g_ObjectRecorderList[j].left_x = pNext->left_x; + //g_ObjectRecorderList[j].top_y = pNext->top_y; + g_ObjectRecorderList[j].box_x = pNext->left_x; + g_ObjectRecorderList[j].box_y = pNext->top_y; + g_ObjectRecorderList[j].box_w = pNext->width; + g_ObjectRecorderList[j].box_h = pNext->height; + + //printf("%d history data, x = %f \n", j, g_ObjectRecorderList[j].box_x); + //printf("y = %f ", g_ObjectRecorderList[j].box_y); + //printf("h = %f ", g_ObjectRecorderList[j].box_h); + //printf("w = %f ", g_ObjectRecorderList[j].box_w); + //printf("ob_id = %d \n", g_ObjectRecorderList[j].iTrackingID); + break; + } + } + } + + //printf("iFindMatch = %d \n", iFindMatchObject); + + if (iFindMatchObject == 0) + { + for (int j = 0; j < MAX_OBJECT_RECORDER; j++) + { + if (g_ObjectRecorderList[j].iIfUse == 0) + { + g_ObjectRecorderList[j].iIfUse = 1; + g_ObjectRecorderList[j].t_FirstGetTime = time(0); + g_ObjectRecorderList[j].t_UpdateTime = time(0); + g_ObjectRecorderList[j].iGetCounter = 1; + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_ObjectRecorderList[j].check_if_counted[m] = 0; + } + g_ObjectRecorderList[j].box_x = pNext->left_x; + g_ObjectRecorderList[j].box_y = pNext->top_y; + g_ObjectRecorderList[j].box_w = pNext->width; + g_ObjectRecorderList[j].box_h = pNext->height; + + g_ObjectRecorderList[j].iTrackingID = pNext->obj_tracking_id; + //g_ObjectRecorderList[j].iTrackingIDidx = pNext->obj_tracking_id_idx; + + break; + } + //else if (j == MAX_OBJECT_RECORDER - 1) { + //printf("\n---------MAX_OBJECT_RECORDER - 1\n"); + //} + } + } + + } + } + } + } + + qsort(&g_ObjectRecorderList, MAX_OBJECT_RECORDER, sizeof(ObjectRecoder), sort_record_object); +} +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void AddTWPlateDASH(detection_pos* PosInfo, int total_element_size, int featureType) +{ + if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { + detection_pos* pNext = NULL; + + int iPlate_len = 0; + + int iFront_alpha_num = 0; + int iFront_digit_num = 0; + int iBack_alpha_num = 0; + int iBack_digit_num = 0; + + //for TWN plate, add dash if miss the dash. + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_type != _PLATE) + { + continue; + } + + if (strlen(pNext->properties.plate) <= 0) + { + continue; + } + + if (pNext->confidence <= 0.0) + { + continue; + } + + if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) { + //Plate miss "-" + if (strstr(pNext->properties.plate, "-") == NULL) + { + iPlate_len = strlen(pNext->properties.plate); + + if (iPlate_len == 7) + { + insert_string(pNext->properties.plate, "-", 3); + } + else if (iPlate_len == 6) + { + iFront_alpha_num = 0; + iFront_digit_num = 0; + iBack_alpha_num = 0; + iBack_digit_num = 0; + int iFront_digit_num_length_4 = 0; + int iBack_digit_num_length_4 = 0; + int iFront_alpha_num_length_2 = 0; + int iBack_alpha_num_length_2 = 0; + + + for (int j = 0; j < 4; j++) + { + if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) + { + iFront_digit_num++; + } + + if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_digit_num++; + } + + if (j <= 3 && isdigit(pNext->properties.plate[j]) != 0) + { + iFront_digit_num_length_4++; + } + + if (j <= 3 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_digit_num_length_4++; + } + + if (j <= 2 && isalpha(pNext->properties.plate[j]) != 0) + { + iFront_alpha_num++; + } + + if (j <= 2 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_alpha_num++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) + { + iFront_alpha_num_length_2++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_alpha_num_length_2++; + } + } + + if ((iFront_digit_num == 3 && iBack_alpha_num == 3) || + (iFront_alpha_num == 3 && iBack_digit_num == 3)) { + insert_string(pNext->properties.plate, "-", 3); + } + else if ((iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 2) || + (iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 1)) { + insert_string(pNext->properties.plate, "-", 4); + } + else if (iFront_alpha_num_length_2 <= 2 && iFront_alpha_num_length_2 >= 1 && iBack_digit_num_length_4 == 4) { + insert_string(pNext->properties.plate, "-", 2); + } + else if (iFront_alpha_num <= 2 && iFront_alpha_num >= 1 && iBack_digit_num == 3) { + insert_string(pNext->properties.plate, "-", 3); + } + } + else if (iPlate_len == 5) + { + iFront_alpha_num = 0; + iFront_digit_num = 0; + iBack_alpha_num = 0; + iBack_digit_num = 0; + + for (int j = 0; j < 3; j++) + { + if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) + { + iFront_digit_num++; + } + + if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_digit_num++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) + { + iFront_alpha_num++; + } + + if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) + { + iBack_alpha_num++; + } + } + + if ((iFront_digit_num == 3 && iBack_alpha_num == 2) || + (iFront_digit_num == 3 && iBack_digit_num == 1 && iBack_alpha_num == 1)) { + insert_string(pNext->properties.plate, "-", 3); + } + else if ((iFront_alpha_num == 2 && iBack_digit_num == 3) || + (iFront_alpha_num == 1 && iFront_digit_num == 1 && iBack_digit_num == 3)) { + insert_string(pNext->properties.plate, "-", 2); + } + } + else if (iPlate_len == 4) + { + insert_string(pNext->properties.plate, "-", 2); + } + + //printf(">>>>>>>>>>>>>>>>>>>>>>>> plate: %s \n", pNext->properties.plate); + } + + if (strstr(pNext->properties.plate, "-") == NULL) + { + pNext->confidence = 0.0; + } + } + else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) + { + pNext->confidence = 0.0; + } + } + } +} + +void MEAPlateRule(detection_pos* PosInfo, int total_element_size) +{ + detection_pos* pNext = NULL; + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (IsANPRCategory_L_Plate(pNext->name)) + { + //printf("%d plate %d name = %s \n", i, pNext->parent_idx, pNext->properties.plate); + check_rule(pNext); + } + } + //printf("**************************************** \n"); +} +#endif + +#if 1 +int CheckTriggerCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int tracking_obj_idx, int trigger_type, int total_element_size, detection_pos* PosInfo, int result_idx) +{ + //int nNotChecked = 0; + int nNeedTrigger = 0; + double diffSecs = 0; + double diffSecs2 = 0; + int detection_count = 0; + //char MetaData1[BUFSIZE] = { 0 }; + //char MetaData2[BUFSIZE] = { 0 }; + //char MetaOut1[512][50] = { 0 }; + //char MetaOut2[512][50] = { 0 }; + double d_no_parking_time = (double)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { + d_no_parking_time = (double)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); + } + + detection_count = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + + detection_pos* pNext_b; + + //for (int i = 0; i < MAX_TRIGGER_EVENT; i++) + //{ + +#if 0 + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].checked <= 0) + return nNeedTrigger; +#endif + + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + //char metadata1[512][STRSPLIT_SIZE] = { 0 }; //for vehicle + //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); + + //printf("\n----CheckTriggerCondition--- start\n"); + int metadata1_num = get_metadata1_num(detection_zone_idx); + //printf("\n----CheckTriggerCondition--- end\n"); + + int temp_enable_person_for_metadata = person_if_existing_in_metaout(detection_zone_idx); + //for (int i = 0; i < metadata1_num; i++) + //{ + //UpperToLower(metadata1[i]); + //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); + + //if (strcmp("person", MetaOut1[i]) == 0) { + //temp_enable_person_for_metadata = 1; + //} + //} + + g_enable_person_for_metadata[detection_zone_idx] = temp_enable_person_for_metadata; + +#if 0 + char metadata2[10][STRSPLIT_SIZE] = { 0 }; //for person + strcpy(MetaData2, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata2); + int metadata2_num = StrSplit(MetaData2, metadata2, ","); + for (int i = 0; i < metadata2_num; i++) + { + UpperToLower(metadata2[i]); + TrimSpace(MetaOut2[i], sizeof(MetaOut2[i]), metadata2[i], 0); + } +#endif + +#if 0 + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); +#endif + //for name comparison without case sensitive + + //float dewell_time = 2.78;//2.78 //4.2 + //float dewell_time2 = 4.2; + + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + if (trigger_type == TRIGGER_ALLOW_LIST) + { + if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || + (strcmp(pNext->name, "ambulance") == 0) + || (strcmp(pNext->name, "blank") == 0) + || (strcmp(pNext->name, "stop_sign") == 0) + //|| (strcmp(pNext->name, "face") == 0) + ) + { + char afterBuf[256] = { 0 }; + if (strcmp(pNext->name, "ambulance") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "blank") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else + strcpy(afterBuf, pNext->properties.plate); + + if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) +#ifdef GY_OS_AMBA + //|| check_if_in_white_face(pNext->FDFR.face_name) +#endif + ) { + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + /*if (strcmp(pNext->name, "face") == 0) + { +#ifdef GY_OS_AMBA + get_schedule_start_in_white_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_white_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_white_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); +#endif + } + else */{ + get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + } + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + ///////////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + + //printf("trigger type 2 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //printf("trigger type 3 \n"); + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#if 0 + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } +#endif + + //printf("trigger type 4 \n"); + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_BLOCK_LIST) + { + if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) + || (strcmp(pNext->name, "blank") == 0) + || (strcmp(pNext->name, "stop_sign") == 0) + //|| (strcmp(pNext->name, "face") == 0) + ) + { + char afterBuf[256] = { 0 }; + if (strcmp(pNext->name, "ambulance") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "blank") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else + strcpy(afterBuf, pNext->properties.plate); + //printf("trigger type 1111 : %s\n", afterBuf); + + if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) +#ifdef GY_OS_AMBA + //|| check_if_in_black_face(pNext->FDFR.face_name) +#endif + ) { + //printf("trigger type 2 \n"); + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + /*if (strcmp(pNext->name, "face") == 0) + { +#ifdef GY_OS_AMBA + get_schedule_start_in_black_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_black_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_black_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); +#endif + } + else */{ + get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + } + + //printf("\n--------schedule_start:%s,schedule_end:%s\n", schedule_start, schedule_end); + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + /////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#if 0 + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } +#endif + + + //printf("\nnNeedTrigger:%d\n", nNeedTrigger); + //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + } + } + } + else if (trigger_type == TRIGGER_GUEST_LIST) + { + if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) + || (strcmp(pNext->name, "blank") == 0) + || (strcmp(pNext->name, "stop_sign") == 0) + //|| (strcmp(pNext->name, "face") == 0) + ) + { + char afterBuf[256] = { 0 }; + if (strcmp(pNext->name, "ambulance") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "blank") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + strcpy(afterBuf, pNext->name); + LowerToUpper(afterBuf); + } + else + strcpy(afterBuf, pNext->properties.plate); + int check_if_white_or_black_within_lifetime = 0; + +#if 1 + if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + ///////////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + check_if_white_or_black_within_lifetime = 1; + } + } + } + + if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { + //printf("trigger type 2 \n"); + char schedule_start[50] = { 0 }; + char schedule_end[50] = { 0 }; + char detect_endtime[50] = { 0 }; + + get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); + + if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { + char c_start_hour[10] = { 0 }; + char c_start_minute[10] = { 0 }; + + char c_end_hour[10] = { 0 }; + char c_end_minute[10] = { 0 }; + + c_start_hour[0] = schedule_start[0]; + c_start_hour[1] = schedule_start[1]; + c_start_hour[2] = '\0'; + + c_start_minute[0] = schedule_start[3]; + c_start_minute[1] = schedule_start[4]; + c_start_minute[2] = '\0'; + + int i_start_hour = atoi(c_start_hour); + int i_start_minute = atoi(c_start_minute); + int i_total_start_minute = i_start_hour * 60 + i_start_minute; + + c_end_hour[0] = schedule_end[0]; + c_end_hour[1] = schedule_end[1]; + c_end_hour[2] = '\0'; + + c_end_minute[0] = schedule_end[3]; + c_end_minute[1] = schedule_end[4]; + c_end_minute[2] = '\0'; + + int i_end_hour = atoi(c_end_hour); + int i_end_minute = atoi(c_end_minute); + int i_total_end_minute = i_end_hour * 60 + i_end_minute; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; + + /////////////////// + + char c_year_endtime[10] = { 0 }; + c_year_endtime[0] = detect_endtime[0]; + c_year_endtime[1] = detect_endtime[1]; + c_year_endtime[2] = detect_endtime[2]; + c_year_endtime[3] = detect_endtime[3]; + c_year_endtime[4] = '\0'; + int i_year_endtime = atoi(c_year_endtime); + + char c_month_endtime[10] = { 0 }; + c_month_endtime[0] = detect_endtime[5]; + c_month_endtime[1] = detect_endtime[6]; + c_month_endtime[2] = '\0'; + int i_month_endtime = atoi(c_month_endtime); + + char c_day_endtime[10] = { 0 }; + c_day_endtime[0] = detect_endtime[8]; + c_day_endtime[1] = detect_endtime[9]; + c_day_endtime[2] = '\0'; + int i_day_endtime = atoi(c_day_endtime); + + char c_hour_endtime[10] = { 0 }; + c_hour_endtime[0] = detect_endtime[11]; + c_hour_endtime[1] = detect_endtime[12]; + c_hour_endtime[2] = '\0'; + int i_hour_endtime = atoi(c_hour_endtime); + + char c_minute_endtime[10] = { 0 }; + c_minute_endtime[0] = detect_endtime[14]; + c_minute_endtime[1] = detect_endtime[15]; + c_minute_endtime[2] = '\0'; + int i_minute_endtime = atoi(c_minute_endtime); + + int check_if_OK = 0; + if (1900 + timeinfo->tm_year < i_year_endtime) + check_if_OK = 1; + else if (1900 + timeinfo->tm_year == i_year_endtime) { + if (1 + timeinfo->tm_mon < i_month_endtime) + check_if_OK = 1; + else if (1 + timeinfo->tm_mon == i_month_endtime) { + if (timeinfo->tm_mday < i_day_endtime) + check_if_OK = 1; + else if (timeinfo->tm_mday == i_day_endtime) { + if (timeinfo->tm_hour < i_hour_endtime) + check_if_OK = 1; + else if (timeinfo->tm_hour == i_hour_endtime) { + if (timeinfo->tm_min < i_minute_endtime) + check_if_OK = 1; + } + } + } + } + + if (((i_total_start_minute < i_total_end_minute && + i_total_current_minute >= i_total_start_minute && + i_total_current_minute <= i_total_end_minute) || + (i_total_start_minute > i_total_end_minute && + (i_total_current_minute >= i_total_start_minute || + i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { + check_if_white_or_black_within_lifetime = 1; + } + } + } +#endif + if (check_if_white_or_black_within_lifetime == 0) { + //printf("trigger type 2 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //printf("trigger type 3 \n"); + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#if 0 + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } +#endif + + //printf("trigger type 4 \n"); + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + + } + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT) + { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n");*/ + + + + int check_if_stability = 1; + + + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if(check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx)==1) + { + if (IsANPRCategory_L_Plate(pNext->name)==1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + if (IsANPRCategory_L_Plate(pNext->name) == 1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + if (IsANPRCategory_L_Plate(pNext->name) == 1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + if (IsANPRCategory_L_Plate(pNext->name) == 1) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + } + } + } + else if (trigger_type == TRIGGER_PARKING_VIOLATION) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { + //printf("1111 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + // printf("1111-1 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + // printf("1111-2 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + int nDiffSecs2 = (int)diffSecs2; + float distCenter = 0; + pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; + distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + if (/*(strcmp(ObjectName, "car") == 0 || (strcmp(ObjectName, "truck") == 0)) + && */distCenter > 1) + { + //printf("distCenter = %f \n", distCenter); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } + + //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); + //printf("\ndiffSecs: %d\n",(int)diffSecs); + //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; + + //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0 /*|| strstr(ObjectName, "plate") != NULL*/) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { +#if 0 //Open for عq קK먮~ + //printf("AAAAAAA %s \n", "nNeedTrigger 1"); + //nNeedTrigger = 1; + //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; + //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + //printf("center diff = %d \n", distCenter); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] + //check prev iou > 60 + //printf("iou self 1 = %d \n", pNext->iou_prev_self); + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 1; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else + //printf("33334444 \n"); + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; +#endif + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { +#if 0 //Open for عq קK먮~ + //printf("iou self 2 = %d \n", pNext->iou_prev_self); + //check prev iou > 60 + + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 2; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else //Normal + if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) + { + nNeedTrigger = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#endif + } +#if 0 //Open for عq קK먮~ + if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) + { + + pNext->trigger_type = trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + break; + } + else + break; +#else + //printf("33338888 \n"); + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + if (diff_secs_in_zone < d_no_parking_time + 5) { + viewDetectionZone[0][detection_zone_idx].det_time = time(0); + } +#endif + + } + } + } + } + + //printf("4444 \n"); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + + } + } + else if (trigger_type == TRIGGER_ZONE_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if(check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#ifdef GY_OS_AMBA + else if (trigger_type == TRIGGER_SPEED_HIGH) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_SPEED_LOW) + { + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#endif + else if (trigger_type == TRIGGER_ALL_OBJECTS) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + //printf("\nAAAAAAAAAAA: 1\n"); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + + int nearest_index = -1; + float nearest_distance = (float)INF; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) { + if (check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx) && IsGarbageCategory(pNext_bring)) + { + //nNeedTrigger = 1; + //printf("\n-----plate(%f,%f),object(%f,%f)\n", pNext->center_x, pNext->center_y, pNext_bring->center_x, pNext_bring->center_y); + + float temp_nearest_distance = sqrt(pow(pNext->center_x- pNext_bring->center_x,2)+ pow(pNext->center_y - pNext_bring->center_y,2)); + if (temp_nearest_distance < nearest_distance) { + nearest_index = j; + nearest_distance = temp_nearest_distance; + } + } + } + } + } + + if (nearest_index >= 0) { + + detection_pos *pNext_bring = PosInfo + nearest_index; + + pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; + pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; + pNext_bring->zone_violation_idx[detection_zone_idx] = 1; + + strcpy(pNext_bring->linked_plate, pNext->properties.plate); + pNext_bring->linked_plate_length = pNext->properties.plate_length; + + if (pNext_bring->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; + } + } + } + } + } + else { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 /*&& ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)*/) { + + int nearest_index = -1; + float nearest_distance = (float)INF; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + + if (check_if_object_in_zone_simple_version_not_plate(pNext_bring, detection_zone_idx) /*&& IsGarbageCategory(pNext_bring)*/) + { + float temp_nearest_distance = sqrt(pow(pNext->center_x - pNext_bring->center_x, 2) + pow(pNext->center_y - pNext_bring->center_y, 2)); + if (temp_nearest_distance < nearest_distance) { + nearest_index = j; + nearest_distance = temp_nearest_distance; + } + } + } + } + + if (nearest_index >= 0) { + + detection_pos *pNext_bring = PosInfo + nearest_index; + + pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; + pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; + pNext_bring->zone_violation_idx[detection_zone_idx] = 1; + + strcpy(pNext_bring->linked_plate, pNext->properties.plate); + pNext_bring->linked_plate_length = pNext->properties.plate_length; + + if (pNext_bring->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; + } + } + } + } + } + } +#endif + } + else{ + if (trigger_type == TRIGGER_MISSING_UNATTENDED) + { + //printf("1111 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + // printf("1111-1 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + // printf("1111-2 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + int nDiffSecs2 = (int)diffSecs2; + float distCenter = 0; + pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; + distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + if ((strcmp(ObjectName, "object") == 0) && distCenter > 1) + { + //printf("distCenter = %f \n", distCenter); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } + + //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); + //printf("\ndiffSecs: %d\n",(int)diffSecs); + //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; + //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); + + if (strcmp(ObjectName,"object")==0) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { +#if 0 //Open for عq קK먮~ + //printf("AAAAAAA %s \n", "nNeedTrigger 1"); + //nNeedTrigger = 1; + //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; + //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + //printf("center diff = %d \n", distCenter); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] +//check prev iou > 60 + //printf("iou self 1 = %d \n", pNext->iou_prev_self); + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 1; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else + //printf("33334444 \n"); + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; +#endif + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { +#if 0 //Open for عq קK먮~ + //printf("iou self 2 = %d \n", pNext->iou_prev_self); + //check prev iou > 60 + + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 2; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else //Normal + if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) + { + nNeedTrigger = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#endif + } +#if 0 //Open for عq קK먮~ + if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) + { + + pNext->trigger_type = trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } +#else + //printf("33338888 \n"); + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; +#endif + + } + } + } + //printf("4444 \n"); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) + { + if (strcmp(ObjectName, "object") == 0) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT) + { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ( (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (get_g_check_if_current_light_is_red() == 1) { + int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); + //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; + //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; + int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; + + //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); + //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); + int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; + /* + printf("\n----center direction queue:"); + for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { + printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); + } + printf("----center direction end--\n"); + */ + + int check_if_stability = 1; + if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { + if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { + float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); + if (diff_angle > 180.0) + diff_angle = 360.0 - diff_angle; + + if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { + check_if_stability = 0; + //printf("\ndrop out\n"); + } + } + } + + if (check_if_stability == 1) { + //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); + //for (int j = 0; j < metadata1_num; j++) + { + + + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + } + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + } + } + } + else if (trigger_type == TRIGGER_PARKING_VIOLATION) + { + //printf("1111 \n"); + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + // printf("1111-1 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + // printf("1111-2 \n"); + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + int nDiffSecs2 = (int)diffSecs2; + float distCenter = 0; + pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; + distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + if (/*(strcmp(ObjectName, "car") == 0 || strcmp(ObjectName, "truck") == 0 || strcmp(ObjectName, "car_front_back") == 0)*/ + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + && distCenter > 1) + { + //printf("distCenter = %f \n", distCenter); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } + + //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); + //printf("\ndiffSecs: %d\n",(int)diffSecs); + //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; + + //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) /*|| strstr(ObjectName, "plate") != NULL*/) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { +#if 0 //Open for عq קK먮~ + //printf("AAAAAAA %s \n", "nNeedTrigger 1"); + //nNeedTrigger = 1; + //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; + //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); + + //printf("center diff = %d \n", distCenter); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] +//check prev iou > 60 + //printf("iou self 1 = %d \n", pNext->iou_prev_self); + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 1; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else + //printf("33334444 \n"); + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; +#endif + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { +#if 0 //Open for عq קK먮~ + //printf("iou self 2 = %d \n", pNext->iou_prev_self); + //check prev iou > 60 + + if (pNext->iou_prev_self >= 98) + { + if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) + { + if (pNext->near_iou_count[detection_zone_idx] <= 1) + { + //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); + nNeedTrigger = 2; + + //pNext->trigger_type = trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; + } +#else //Normal + if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) + { + nNeedTrigger = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } +#endif + } +#if 0 //Open for عq קK먮~ + if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) + { + + pNext->trigger_type = trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + //else + //break; +#else + //printf("33338888 \n"); + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + if (diff_secs_in_zone < d_no_parking_time + 5) { + viewDetectionZone[0][detection_zone_idx].det_time = time(0); + } +#endif + + } + } + } + } + + //printf("4444 \n"); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + else if (trigger_type == TRIGGER_ZONE_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0 || strcmp("person", pNext->name) == 0 || + // (diff_secs_in_zone >= 1 && diff_secs_in_zone > 0 && (int)(pNext->center_stability) != DIRECTION_DEFAULT)) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#ifdef GY_OS_AMBA + else if (trigger_type == TRIGGER_DISTANCE_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + //printf("\n--------g_max_tof_range:%f\n", g_max_tof_range); + //printf("\n-------atof(tofData.distance_threshold):%f\n", atof(tofData.distance_threshold)); + + int check_if_OK_tof = 0; + + if (strcmp(tofData.distance_options, "gt") == 0) { + if (strcmp(tofData.distance_min_max, "min") == 0) { + if (g_min_tof_distance > atof(tofData.distance_threshold) && pNext->min_distance != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.distance_min_max, "max") == 0) { + if (g_max_tof_distance > atof(tofData.distance_threshold) && pNext->max_distance != 0) { + check_if_OK_tof = 1; + } + } + } + else if (strcmp(tofData.distance_options, "lt") == 0) { + if (strcmp(tofData.distance_min_max, "min") == 0) { + if (g_min_tof_distance < atof(tofData.distance_threshold) && pNext->min_distance != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.distance_min_max, "max") == 0) { + if (g_max_tof_distance < atof(tofData.distance_threshold) && pNext->max_distance != 0) { + check_if_OK_tof = 1; + } + } + } + + if(check_if_OK_tof == 1) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName,"tof_point") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_HIGH_VIOLATION) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + + int check_if_OK_tof = 0; + + if (strcmp(tofData.height_options, "gt") == 0) { + if (strcmp(tofData.height_min_max, "min") == 0) { + if (g_min_tof_height > atof(tofData.height_threshold) && pNext->min_height != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.height_min_max, "max") == 0) { + if (g_max_tof_height > atof(tofData.height_threshold) && pNext->max_height != 0) { + check_if_OK_tof = 1; + } + } + } + else if (strcmp(tofData.height_options, "lt") == 0) { + if (strcmp(tofData.height_min_max, "min") == 0) { + if (g_min_tof_height < atof(tofData.height_threshold) && pNext->min_height != 0) { + check_if_OK_tof = 1; + } + } + else if (strcmp(tofData.height_min_max, "max") == 0) { + if (g_max_tof_height < atof(tofData.height_threshold) && pNext->max_height != 0) { + check_if_OK_tof = 1; + } + } + } + + if (check_if_OK_tof == 1) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName, "tof_point") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#endif + else if (trigger_type == TRIGGER_FORGET_TO_GIVE_WAY) + { + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + //pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_check_giveway[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_SPEED_HIGH) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if(pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_SPEED_LOW) + { + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + //nNeedTrigger = 2; //post: yes, counter: no + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + else if (trigger_type == TRIGGER_TAMPERING) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //if (detection_count > 1) + //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + //int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName, "tampering") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + //{ + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //} + //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + //{ + //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + //{ + //nNeedTrigger = 2; //post: yes, counter: no + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //} + //} + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + } + } + else if (trigger_type == TRIGGER_ALL_OBJECTS) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + //printf("\nAAAAAAAAAAA: 1\n"); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { + int temp_count_meta = 0; + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) + { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if(check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) + //{ + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if(check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta == metadata1_num - 1) + if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + else if ((strcmp(ObjectName, "person") == 0) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + int temp_count_meta = 0; + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) + //{ + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta >= 1) + if (pNext->num_bring_with_object[detection_zone_idx] >= 1) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + else if ((IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) + + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (check_if_existing_in_metaout(BringName, detection_zone_idx) && IsGarbageCategory(pNext_bring)) + if (IsGarbageCategory(pNext_bring)) + { + //nNeedTrigger = 1; + + pNext->trigger_type = trigger_type | pNext->trigger_type; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + + if (pNext->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + } + } + } + + } + } + } + } + } + } + else { + + //printf("\nAAAAAAAAAAA: 2\n"); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + //printf("\nAAAAAAAAAAA: 2-1------%d\n", get_g_check_if_all_existing(detection_zone_idx)); + //if ((int)pNext->obj_dwell_time % 2 == 0) + if (get_g_check_if_all_existing(detection_zone_idx) == 1) + { + //printf("\nAAAAAAAAAAA: 2-2\n"); + //for (int j = 0; j < metadata1_num; j++) + { + if(check_if_object_in_zone_simple_version_not_plate(pNext, detection_zone_idx)) + { + //printf("\nAAAAAAAAAAA: 2-3\n"); + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + else if (trigger_type == TRIGGER_LACK_OF_ANY_OBJECT) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { + int temp_count_meta = 0; + + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (strcmp(BringName, MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta == metadata1_num - 1) + if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) + { + + } + else { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + else if ((strcmp(ObjectName, "person") == 0 || IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { + int temp_count_meta = 0; + + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 + && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { + + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) + { + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //if (strcmp(BringName, MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + } + } + } + } + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { + //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) + //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + //count_correct_meta++; + //break; + } + //} + } + + //if (count_correct_meta >= 1) + if (pNext->num_bring_with_object[detection_zone_idx] >= 1) + { + + } + else { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; + pNext->num_bring_with_object[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + } + } + } + else + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + /*if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0)*/ { + if (get_g_check_if_NAND(detection_zone_idx) == 1) + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + if (check_if_object_in_zone_simple_version(pNext, detection_zone_idx)) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); + printf("\ntrigger_type:%d\n",trigger_type); + */ + + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + /* + printf("\nnNeedTrigger:%d\n", nNeedTrigger); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + + + } + + } + } + } + } + else if (trigger_type == TRIGGER_QUEUING_VIOLATION) + { + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_line >= 1) { + + + } + else { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + int check_if_enable_linked_to_dwell_time = 0; +#ifdef GY_OS_V_SERIES + +#else +#if 1 + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + g_IsCustomWeight == 1) { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + //printf("\n------UU:4\n"); + + for (int i = 0; i < event_counter_num; i++) + { + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + if (strlen(eachEventCounter[i]) >= 1 && strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) + { + if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0) { + check_if_enable_linked_to_dwell_time = 1; + break; + } + } + } + if (check_if_enable_linked_to_dwell_time == 1) + break; + } + } +#endif +#endif + + if(check_if_enable_linked_to_dwell_time == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //pNext->trigger_type = trigger_type; + pNext->zone_violation_idx[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + else if (check_if_enable_linked_to_dwell_time == 1) { + + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //pNext->trigger_type = trigger_type; + pNext->zone_violation_idx[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + + //break; + } + } + } + } + } + } + } +#if 0 + else if (trigger_type == TRIGGER_MISSING_OBJECT_DETECTION) + { + /* + printf("\n----------------------------------\n"); + printf("\nobj_first_dwell_time: %lf\n",pNext->obj_first_dwell_time); + printf("\nobj_last_dwell_time: %lf\n", pNext->obj_last_dwell_time); + printf("\n----------------------------------\n");*/ + + /*if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { + int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { + + } + }*/ + if (pNext->obj_dwell_time > g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time + d_no_parking_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + { + nNeedTrigger = 1; + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = 0.0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = 0.0; + } + + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 2; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //if (diffSecs >= dewell_time2) + { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + //break; + } + } + } + } + +#endif +#if 0 + if (trigger_event_type == TRIGGER_TURN_LEFT) + { + if (trigger_type == TRIGGER_TURN_LEFT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_RIGHT) + { + if (trigger_type == TRIGGER_TURN_RIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + //if (strcmp(ObjectName, MetaOut1[j]) == 0) + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_WRONG_WAY) + { + if (trigger_type == TRIGGER_WRONG_WAY) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + { + if (trigger_type == TRIGGER_TURN_LEFT_VIOLATION) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + { + if (trigger_type == TRIGGER_TURN_RIGHT_VIOLATION) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + { + if (trigger_type == TRIGGER_U_TURN_VIOLATION) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line /*&& g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx] == backward_line*/ && forward_line > 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + /* + if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + + if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) + { + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); + if (diffSecs < dewell_time) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + } + pNext->trigger_type = trigger_type; + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + + } + } + } + else + { + //for (int j = 0; j < metadata1_num; j++) + { + if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) + { + nNeedTrigger = 0; + //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } + } + */ +#endif + + /* + if (trigger_event_type == TRIGGER_BG_LEARNING) + { + if (trigger_type == TRIGGER_BG_LEARNING) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) + { + //lasting time since enter zone + diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + if (detection_count > 1) + diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); + int nDiffSecs = (int)diffSecs; + //int nDiffSecs2 = (int)diffSecs2; + + //if ((int)pNext->obj_dwell_time % 2 == 0) + { + //for (int j = 0; j < metadata1_num; j++) + { + if (strcmp(ObjectName, "bg_learning") == 0) + { + //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); + //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); + + if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) + { + nNeedTrigger = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) + { + if (nDiffSecs % TRIGGER_INTERVAL == 0) + { + nNeedTrigger = 2; //post: yes, counter: no + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + } + } + + //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); + + pNext->trigger_type = trigger_type; + + //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); + + pNext->zone_violation_idx[detection_zone_idx] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + } + } + }*/ + + } + + if (strcmp(SystemSetting.enable_person_independent, "Yes") == 0) { + //printf("\nTTTTTTTTTT : 1\n"); + if (strcmp(ObjectName, "person") == 0) { + int temp_count_meta = 0; + temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; + //printf("\nTTTTTTTTTT : 2\n"); + for (int j = 0; j < total_element_size; j++) + { + if (j != result_idx) { + detection_pos *pNext_bring = PosInfo + j; + if (!IsANPRCategory(pNext_bring->engine_type)) { + char BringName[30] = { 0 }; + sprintf(BringName, "%s", pNext_bring->name); + UpperToLower(BringName); + if (strcmp(BringName, "person") != 0) { + //printf("\nTTTTTTTTTT : 3\n"); + //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); + if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) + { + { + + //nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext_bring->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; + pNext_bring->zone_violation_idx[detection_zone_idx] = 0; + pNext_bring->check_person_inter = 1; + if (pNext_bring->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = 0; + int det_count_temp = g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].detection_count; + if(det_count_temp >= 1) + g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].prev_detections[det_count_temp - 1].check_person_inter = 1; + } + } + //printf("\nTTTTTTTTTT : 4\n"); + if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { + int check_if_not_bring = 1; + for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { + if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { + check_if_not_bring = 0; + break; + } + } + + if (check_if_not_bring) { + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + if (check_if_existing_in_metaout(BringName, detection_zone_idx)) + { + strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); + if (detection_count >= 1) + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); + temp_count_meta++; + pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; + //break; + } + } + } + } + //printf("\nTTTTTTTTTT : 5\n"); + } + } + } + } + } + //printf("\nTTTTTTTTTT : 6\n"); + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) + { + int count_correct_meta = 0; + //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) + { + for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { + if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) + { + count_correct_meta++; + //break; + } + } + } + + if (count_correct_meta >= 1) { + nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; + + pNext->check_person_inter = 1; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; + //nNeedTrigger = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + //pNext->trigger_type = trigger_type | pNext->trigger_type; + //pNext->detection_zone_idx = detection_zone_idx; + //pNext->trigger_idx[detection_zone_idx] = trigger_idx; + //pNext->zone_violation_idx[detection_zone_idx] = 1; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + else { + pNext->check_person_inter = 0; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; + } + + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + //pNext->num_bring_with_object[detection_zone_idx] = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; + } + //printf("\nTTTTTTTTTT : 7\n"); + } + else { + + if (!IsANPRCategory(pNext->engine_type)) { + //printf("\nTTTTTTTTTT : 8\n"); + if (pNext->check_person_inter == 1) { + nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; + //printf("\nTTTTTTTTTT : 9\n"); + } + else { + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; + //if (diff_secs_in_zone < d_no_parking_time && diff_secs_in_zone > 0) + { + nNeedTrigger = 0; + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; + pNext->trigger_type = 0; + //pNext->detection_zone_idx = detection_zone_idx; + pNext->trigger_idx[detection_zone_idx] = trigger_idx; + pNext->zone_violation_idx[detection_zone_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; + + pNext->check_person_inter = 1; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; + + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; + } + //printf("\nTTTTTTTTTT : 10\n"); + } + } + else { + pNext->check_person_inter = 0; + if (detection_count >= 1) + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; + //printf("\nTTTTTTTTTT : 11\n"); + } + } + } + + return nNeedTrigger; +} +#endif +#if 1 +char g_last_token_name[256] = { 0 }; +char g_last_token_confidence[10] = { 0 }; +char g_last_token_left_x[10] = { 0 }; +char g_last_token_top_y[10] = { 0 }; +char g_last_token_width[10] = { 0 }; +char g_last_token_height[10] = { 0 }; +char g_last_token_center_x[10] = { 0 }; +char g_last_token_center_y[10] = { 0 }; +char g_last_token_center_speed[35] = { 0 }; +char g_last_token_center_direction[10] = { 0 }; +char g_last_token_center_stability[10] = { 0 }; +char g_last_token_obj_tracking_id[10] = { 0 }; +char g_last_token_obj_dwell_time[20] = { 0 }; +char g_last_token_class_id[10] = { 0 }; +char g_last_token_color[20] = { 0 }; +char g_last_token_plate[256] = { 0 }; +char g_last_token_country[256] = { 0 }; +char g_last_token_area[256] = { 0 }; +char g_last_token_plate_list[256] = { 0 }; +char g_last_token_logo[256] = { 0 }; +char g_last_token_behavior_id[1024] = { 0 }; +char g_last_token_zone_id[10] = { 0 }; +char g_last_token_behavior_name[256] = { 0 }; +char g_last_token_linked_plate[256] = { 0 }; + +size_t ReplaceKeyWords(detection_pos* pNext, int space_zone,int space_id,char* InputString,char *OutputString,int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64,int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) +{ + char *replacement = NULL; + char *replacement_t = NULL; + char msg[MAX_MSG_LEN] = { 0 }; + + replacement = InputString; + + //קK᭱replacementSkfreeC + replacement_t = StrReplace(replacement, "<|test_token|>", "Hello"); + replacement = replacement_t; + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%s", pNext->name); + strcpy(g_last_token_name, pNext->name); + + replacement_t = StrReplace(replacement, "<|name|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_name); + + replacement_t = StrReplace(replacement, "<|name|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->confidence); + sprintf(g_last_token_confidence, "%d", (int)pNext->confidence); + + replacement_t = StrReplace(replacement, "<|confidence|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_confidence); + + replacement_t = StrReplace(replacement, "<|confidence|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->left_x - pNext->width / 3.0)); + sprintf(g_last_token_left_x, "%d", (int)(pNext->left_x - pNext->width / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->left_x); + sprintf(g_last_token_left_x, "%d", (int)pNext->left_x); + } + + replacement_t = StrReplace(replacement, "<|left_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_left_x); + + replacement_t = StrReplace(replacement, "<|left_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->top_y - pNext->height / 3.0)); + sprintf(g_last_token_top_y, "%d", (int)(pNext->top_y - pNext->height / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->top_y); + sprintf(g_last_token_top_y, "%d", (int)pNext->top_y); + } + + replacement_t = StrReplace(replacement, "<|top_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_top_y); + + replacement_t = StrReplace(replacement, "<|top_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->width * 5.0 / 3.0)); + sprintf(g_last_token_width, "%d", (int)(pNext->width * 5.0 / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->width); + sprintf(g_last_token_width, "%d", (int)pNext->width); + } + + replacement_t = StrReplace(replacement, "<|width|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_width); + + replacement_t = StrReplace(replacement, "<|width|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (show_large_bbox == 1) { + sprintf(msg, "%d", (int)(pNext->height * 5.0 / 3.0)); + sprintf(g_last_token_height, "%d", (int)(pNext->height * 5.0 / 3.0)); + } + else { + sprintf(msg, "%d", (int)pNext->height); + sprintf(g_last_token_height, "%d", (int)pNext->height); + } + + replacement_t = StrReplace(replacement, "<|height|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_height); + + replacement_t = StrReplace(replacement, "<|height|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->center_x); + sprintf(g_last_token_center_x, "%d", (int)pNext->center_x); + + replacement_t = StrReplace(replacement, "<|center_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_x); + + replacement_t = StrReplace(replacement, "<|center_x|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->center_y); + sprintf(g_last_token_center_y, "%d", (int)pNext->center_y); + + replacement_t = StrReplace(replacement, "<|center_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_y); + + replacement_t = StrReplace(replacement, "<|center_y|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + char msg_center_speed[35] = { 0 }; + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { + sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); + + if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { + strcat(msg_center_speed, " km/h"); + } + else { + strcat(msg_center_speed, " mi/h"); + } + } + else { + sprintf(msg_center_speed, "%s", ""); + } + sprintf(g_last_token_center_speed, "%s", msg_center_speed); + + replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg_center_speed, "%s", g_last_token_center_speed); + + replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { + sprintf(msg, "%d", (int)pNext->center_direction); + sprintf(g_last_token_center_direction, "%d", (int)pNext->center_direction); + } + else { + sprintf(msg, "%s", ""); + sprintf(g_last_token_center_direction, "%s", ""); + } + + replacement_t = StrReplace(replacement, "<|center_direction|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_direction); + + replacement_t = StrReplace(replacement, "<|center_direction|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { + sprintf(msg, "%d", (int)pNext->center_stability); + sprintf(g_last_token_center_stability, "%d", (int)pNext->center_stability); + } + else { + sprintf(msg, "%s", ""); + sprintf(g_last_token_center_stability, "%s", ""); + } + + replacement_t = StrReplace(replacement, "<|center_stability|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_center_stability); + + replacement_t = StrReplace(replacement, "<|center_stability|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)pNext->obj_tracking_id); + sprintf(g_last_token_obj_tracking_id, "%d", (int)pNext->obj_tracking_id); + + replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_obj_tracking_id); + + replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", (int)(pNext->obj_dwell_time * 100) / 100); + sprintf(g_last_token_obj_dwell_time, "%d", (int)(pNext->obj_dwell_time * 100) / 100); + + replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_obj_dwell_time); + + replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + sprintf(msg, "%d", pNext->class_id); + sprintf(g_last_token_class_id, "%d", pNext->class_id); + + replacement_t = StrReplace(replacement, "<|class_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(msg, "%s", g_last_token_class_id); + + replacement_t = StrReplace(replacement, "<|class_id|>", msg); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + +#ifdef GY_OS_AMBA + char mycolor[20] = { 0 }; + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { + if (!IsANPRCategory(pNext->engine_type)) { + if (pNext->image_id != -1 && get_check_first_downsized_cropped_roi_for_object() == 1) { + if (pNext->color_id == 1) + strcpy(mycolor, "Red"); + else if (pNext->color_id == 2) + strcpy(mycolor, "Orange"); + else if (pNext->color_id == 3) + strcpy(mycolor, "Yellow"); + else if (pNext->color_id == 4) + strcpy(mycolor, "Green"); + else if (pNext->color_id == 5) + strcpy(mycolor, "Blue"); + else if (pNext->color_id == 6) + strcpy(mycolor, "Cyan"); + else if (pNext->color_id == 7) + strcpy(mycolor, "Purple"); + else if (pNext->color_id == 8) + strcpy(mycolor, "Black"); + else if (pNext->color_id == 9) + strcpy(mycolor, "White"); + else if (pNext->color_id == 11) + strcpy(mycolor, "Darkgray"); + else if (pNext->color_id == 10) + strcpy(mycolor, "Gray");//Silver + } + } + } + } + else { + sprintf(mycolor, "%s", ""); + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0) { + sprintf(g_last_token_color, "%s", mycolor); + + replacement_t = StrReplace(replacement, "<|color|>", mycolor); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + sprintf(mycolor, "%s", g_last_token_color); + + replacement_t = StrReplace(replacement, "<|color|>", mycolor); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + +#endif + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|plate|>", pNext->properties.plate); + sprintf(g_last_token_plate, "%s", pNext->properties.plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|plate|>", g_last_token_plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|country|>", pNext->properties.country); + sprintf(g_last_token_country, "%s", pNext->properties.country); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|country|>", g_last_token_country); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|area|>", pNext->properties.area); + sprintf(g_last_token_area, "%s", pNext->properties.area); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|area|>", g_last_token_area); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|plate_list|>", pNext->properties.plate_list); + sprintf(g_last_token_plate_list, "%s", pNext->properties.plate_list); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|plate_list|>", g_last_token_plate_list); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { + replacement_t = StrReplace(replacement, "<|logo|>", pNext->logo); + sprintf(g_last_token_logo, "%s", pNext->logo); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|logo|>", g_last_token_logo); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } +#ifdef GY_OS_AMBA + int hex_token_base = 1; + int sum_hex = 0; + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + if (index_zone >= 1) { + hex_token_base *= 2; + } + + if (viewDetectionZone[tracking_channel_idx][index_zone].prev_queuing_num >= 1) { + sum_hex += hex_token_base; + } + } + + char buf_hex[50] = { 0 }; + sprintf(buf_hex, "%d", sum_hex); + replacement_t = StrReplace(replacement, "<|hextoint|>", buf_hex); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; +#endif + + int behavior_ID = 0; + if (detection_zone_idx >= 0 && trigger_idx >= 0) + behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + + sprintf(msg, "%d", behavior_ID);//(int)pNext->trigger_type + if (detection_zone_idx >= 0 && trigger_idx >= 0) { + replacement_t = StrReplace(replacement, "<|behavior_id|>", msg); + sprintf(g_last_token_behavior_id, "%s", msg); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|behavior_id|>", g_last_token_behavior_id); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { + sprintf(msg, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); + sprintf(g_last_token_zone_id, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); + replacement_t = StrReplace(replacement, "<|zone_id|>", msg); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|zone_id|>", g_last_token_zone_id); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + + char behavior_name[256] = { 0 }; + if ((behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { + strcpy(behavior_name, "Prohibit_zone"); + } + else if ((behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { + strcpy(behavior_name, "Distance_violation"); + } + else if ((behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { + strcpy(behavior_name, "Height_detection"); + } + else if ((behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { + strcpy(behavior_name, "Forget_to_give_way_detection");//§ + } + else if ((behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { + strcpy(behavior_name, "Max_speed_detection"); + } + else if ((behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { + strcpy(behavior_name, "Min_speed_detection"); + } + else if ((behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { + strcpy(behavior_name, "Zone_with_dwell_Parking_violation");//Tϭɰ / HW + } + else if ((behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { + strcpy(behavior_name, "Tripwire_Traffic_flow");//ĵٽu / 氻 + } + else if ((behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { + strcpy(behavior_name, "Tripwire_on_red_Running_red_lights");//Oĵٽu / O + } + else if ((behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { + strcpy(behavior_name, "Turning_left_on_red");//O + } + else if ((behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { + strcpy(behavior_name, "Turning_right_on_red");//Ok + } + else if ((behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { + strcpy(behavior_name, "Turn_left");//఻ + } + else if ((behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { + strcpy(behavior_name, "Turn_right");//k఻ + } + else if ((behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { + strcpy(behavior_name, "LPR_allowed_list_detection_in_zone");//զWĵٰϰ + } + else if ((behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { + strcpy(behavior_name, "LPR_visitor_list_detection_in_zone");//XȦWĵٰϰ + } + else if ((behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { + strcpy(behavior_name, "LPR_denial_list_detection_in_zone");//¦Wĵٰϰ + } + else if ((behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { + strcpy(behavior_name, "Density_detection");//Kװ + } + else if ((behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { + strcpy(behavior_name, "AI_missing_object_detection");//AI򥢪 + } + else if ((behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { + strcpy(behavior_name, "Unattended_or_missing_object");//򥢪οd + } + else if ((behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { + strcpy(behavior_name, "Tampering_detection");//}a + } + else if ((behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { + strcpy(behavior_name, "All_objects_detection_AND");//ئPɦsb (AND) + } + else if ((behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { + strcpy(behavior_name, "Lack_of_any_object_detection_NAND");//ʤ֥@ئPɦsb (NAND) + } + if (detection_zone_idx >= 0 && trigger_idx >= 0) { + replacement_t = StrReplace(replacement, "<|behavior_name|>", behavior_name); + sprintf(g_last_token_behavior_name, "%s", behavior_name); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|behavior_name|>", g_last_token_behavior_name); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { + replacement_t = StrReplace(replacement, "<|linked_plate|>", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); + sprintf(g_last_token_linked_plate, "%s", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + else { + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + replacement_t = StrReplace(replacement, "<|linked_plate|>", g_last_token_linked_plate); + + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + + //time_t rawtime = time(0); + time_t rawtime = g_osdSysTimeStamp; + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + //printf("\n---g_osdSysTimeStamp:%ld,%04d-%02d-%02dT%02d:%02d:%02d\n", g_osdSysTimeStamp, 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + //timeinfo->tm_min, timeinfo->tm_sec); + + /* + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d-%02d-%02dT%02d:%02d:%02d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec); + */ + + char buf_time_t[50] = { 0 }; + sprintf(buf_time_t, "%ld", rawtime); + replacement_t = StrReplace(replacement, "<|time_t|>", buf_time_t); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_year[20] = { 0 }; + sprintf(buf_year, "%04d", 1900 + timeinfo->tm_year); + replacement_t = StrReplace(replacement, "<|YYYY|>", buf_year); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_month[20] = { 0 }; + sprintf(buf_month, "%02d", 1 + timeinfo->tm_mon); + replacement_t = StrReplace(replacement, "<|MM|>", buf_month); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_date[10] = { 0 }; + sprintf(buf_date, "%02d", timeinfo->tm_mday); + replacement_t = StrReplace(replacement, "<|DD|>", buf_date); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_hour[10] = { 0 }; + sprintf(buf_hour, "%02d", timeinfo->tm_hour); + replacement_t = StrReplace(replacement, "<|hh|>", buf_hour); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_minute[10] = { 0 }; + sprintf(buf_minute, "%02d", timeinfo->tm_min); + replacement_t = StrReplace(replacement, "<|mm|>", buf_minute); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_second[10] = { 0 }; + sprintf(buf_second, "%02d", timeinfo->tm_sec); + replacement_t = StrReplace(replacement, "<|ss|>", buf_second); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + struct tm * gmtinfo; + gmtinfo = gmtime(&rawtime); + + char buf_gmthour[10] = { 0 }; + sprintf(buf_gmthour, "%02d", gmtinfo->tm_hour); + replacement_t = StrReplace(replacement, "<|GMThh|>", buf_gmthour); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + +#ifdef GY_OS_V_SERIES + +#else + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) + { + char temp_label[30] = { 0 }; + sprintf(temp_label, "<|counter%02d_count|>", index_counter + 1); + + char temp_counter_count[30] = { 0 }; + sprintf(temp_counter_count,"%d", eventCounterList[index_counter].counter_count); + + replacement_t = StrReplace(replacement, temp_label, temp_counter_count); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char temp_label_dwell[30] = { 0 }; + sprintf(temp_label_dwell, "<|counter%02d_dwell|>", index_counter + 1); + + char temp_counter_timetResetAt[50] = { 0 }; + sprintf(temp_counter_timetResetAt, "%d", eventCounterList[index_counter].dwell_time); + + replacement_t = StrReplace(replacement, temp_label_dwell, temp_counter_timetResetAt); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char temp_label_dwell_unit[50] = { 0 }; + sprintf(temp_label_dwell_unit, "<|counter%02d_dwell_unit|>", index_counter + 1); + + replacement_t = StrReplace(replacement, temp_label_dwell_unit, eventCounterList[index_counter].dwell_unit); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + } +#endif + char fetch_mac_addr[30] = { 0 }; + if (g_match_mac) + strcpy(fetch_mac_addr, g_mac_address); + else + { + GetMACAddress(fetch_mac_addr); + //printf("mac addr = %s \n", fetch_mac_addr); + int i = 0; + while (fetch_mac_addr[i] != '\0') + { + if (fetch_mac_addr[i] == '\n') + { + fetch_mac_addr[i] = '\0'; + break; + } + i++; + } + } + replacement_t = StrReplace(replacement, "<|mac_address|>", fetch_mac_addr); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + replacement_t = StrReplace(replacement, "<|device_name|>", g_device_name); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + replacement_t = StrReplace(replacement, "<|dataset_ver|>", Buffer_ver); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char temp_soft_ver[50] = { 0 }; + strcat(temp_soft_ver, APP_VERSION); + strcat(temp_soft_ver, "-"); + strcat(temp_soft_ver, WeightFileModeName); + replacement_t = StrReplace(replacement, "<|soft_ver|>", temp_soft_ver); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_frame_id[50] = { 0 }; + sprintf(buf_frame_id, "%u", get_frame_id()); + replacement_t = StrReplace(replacement, "<|frame_id|>", buf_frame_id); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_parking_space[50] = { 0 }; + sprintf(buf_parking_space, "%d", viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space); + replacement_t = StrReplace(replacement, "<|total_space|>", buf_parking_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + if (space_zone >= 0 && space_id >= 0) { + + int temp_space_id = space_id; + for (int index_zone = 0; index_zone < space_zone; index_zone++) { + temp_space_id += (viewDetectionZone[tracking_channel_idx][space_zone].parking_space + 1); + } + + char buf_space_id[50] = { 0 }; + sprintf(buf_space_id, "%02d", temp_space_id + 1); + replacement_t = StrReplace(replacement, "<|space_id|>", buf_space_id); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_space_zone[50] = { 0 }; + sprintf(buf_space_zone, "%d", space_zone + 1); + replacement_t = StrReplace(replacement, "<|space_zone|>", buf_space_zone); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_space_status[50] = { 0 }; + sprintf(buf_space_status, "%d", g_parking_space_check_table[space_zone][space_id]); + replacement_t = StrReplace(replacement, "<|space_status|>", buf_space_status); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + time_t rawtime_space = g_parking_space_status_change_time[space_zone][space_id]; + + struct tm * timeinfo_space; + struct tm * gmtinfo_space; + timeinfo_space = localtime(&rawtime_space); + gmtinfo_space = gmtime(&rawtime_space); + + char buf_time_t_space[50] = { 0 }; + sprintf(buf_time_t_space, "%ld", rawtime_space); + replacement_t = StrReplace(replacement, "<|space_time_t|>", buf_time_t_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_year_space[20] = { 0 }; + sprintf(buf_year_space, "%04d", 1900 + timeinfo_space->tm_year); + replacement_t = StrReplace(replacement, "<|space_YYYY|>", buf_year_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_month_space[20] = { 0 }; + sprintf(buf_month_space, "%02d", 1 + timeinfo_space->tm_mon); + replacement_t = StrReplace(replacement, "<|space_MM|>", buf_month_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_date_space[10] = { 0 }; + sprintf(buf_date_space, "%02d", timeinfo_space->tm_mday); + replacement_t = StrReplace(replacement, "<|space_DD|>", buf_date_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_gmthour_space[10] = { 0 }; + sprintf(buf_gmthour_space, "%02d", gmtinfo_space->tm_hour); + replacement_t = StrReplace(replacement, "<|space_GMThh|>", buf_gmthour_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_hour_space[10] = { 0 }; + sprintf(buf_hour, "%02d", timeinfo_space->tm_hour); + replacement_t = StrReplace(replacement, "<|space_hh|>", buf_hour_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_minute_space[10] = { 0 }; + sprintf(buf_minute_space, "%02d", timeinfo_space->tm_min); + replacement_t = StrReplace(replacement, "<|space_mm|>", buf_minute_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_second_space[10] = { 0 }; + sprintf(buf_second_space, "%02d", timeinfo_space->tm_sec); + replacement_t = StrReplace(replacement, "<|space_ss|>", buf_second_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + char buf_difftime_space[10] = { 0 }; + sprintf(buf_difftime_space, "%d", (int)difftime(g_osdSysTimeStamp, rawtime_space)); + replacement_t = StrReplace(replacement, "<|difftime|>", buf_difftime_space); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + + if (enable_base64_image == 1) { + + char buf_image_size[50] = { 0 }; + sprintf(buf_image_size, "%d", image_buff_size_base64); + replacement_t = StrReplace(replacement, "<|snap_size|>", buf_image_size); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + replacement_t = StrReplace(replacement, "<|snap_image|>", image_buff_base64); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + if (pNext != NULL && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && pNext->image_id >= 0 && pNext->image_id < MAX_PLATE_BUF_NUM && cropped_image_size_base64[pNext->image_id] >= 1) { + if (cropped_image_base64 != NULL && cropped_image_base64[pNext->image_id] != NULL) { + char buf_image_size[50] = { 0 }; + sprintf(buf_image_size, "%d", cropped_image_size_base64[pNext->image_id]); + replacement_t = StrReplace(replacement, "<|cropped_size|>", buf_image_size); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + + cropped_image_base64[pNext->image_id][cropped_image_size_base64[pNext->image_id]] = '\0'; + replacement_t = StrReplace(replacement, "<|cropped_image|>", cropped_image_base64[pNext->image_id]); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + replacement = replacement_t; + } + } + } + + strcpy(OutputString, replacement); + if (replacement != NULL) { + free(replacement); + replacement = NULL; + } + //printf("\n-----%s\n", OutputString); + return strlen(OutputString); + +} +//ReplaceKeyWords// + +size_t ReplaceKeyWords_space(detection_pos* pNext,char *SequenceString, int space_zone, int space_id, char* InputString, char *OutputString, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64, int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) +{ + //printf("\n-------ReplaceKeyWords space----0\n"); + size_t content_size = 0; + //printf("\n-------ReplaceKeyWords space----1\n"); + if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString,"<|space_zone|><|space_id|>")==0 && strstr(InputString,"<|space_zone|>")!=NULL && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) + { + //printf("\n-------ReplaceKeyWords space----2\n"); + char content_temp[BUFSIZE_V3] = { 0 }; + strcpy(content_temp,"["); + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) { + char content_current[BUFSIZE_V3] = { 0 }; + ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); + + if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) { + strcat(content_temp, content_current); + } + else { + strcat(content_temp, content_current); + strcat(content_temp, ","); + } + } + } + strcat(content_temp, "]"); + content_size = strlen(content_temp); + strcpy(OutputString, content_temp); + //printf("\n-------ReplaceKeyWords space----3\n"); + //printf("\n-------OutputString:%s\n", OutputString); + } + else if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString, "<|space_id|>") == 0 && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) + { + //printf("\n-------ReplaceKeyWords space----4\n"); + char content_temp[BUFSIZE_V3] = { 0 }; + strcpy(content_temp, "["); + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) + { + char content_current[BUFSIZE_V3] = { 0 }; + ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); + + if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) + { + strcat(content_temp, content_current); + } + else + { + strcat(content_temp, content_current); + strcat(content_temp, ","); + } + } + } + strcat(content_temp, "]"); + content_size = strlen(content_temp); + strcpy(OutputString, content_temp); + //viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space + //printf("\n-------OutputString:%s\n", OutputString); + //printf("\n-------ReplaceKeyWords space----5\n"); + } + else if(pNext != NULL) + { + //printf("\n-------ReplaceKeyWords space----6\n"); + char content_temp[BUFSIZE_V3] = { 0 }; + ReplaceKeyWords(pNext, space_zone, space_id, InputString, content_temp, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); + content_size = strlen(content_temp); + strcpy(OutputString, content_temp); + //printf("\n-------ReplaceKeyWords space----7\n"); + } + else + { + content_size = 0; + } + + return content_size; +} + +#endif + +//|ΨUTF8 Encoder +void UpdateBehaviorData(QueueInfo* q_info, int tracking_channel_idx, int detection_zone_idx,int trigger_idx, int enable_lang) { + q_info->behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + if ((q_info->behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//Tϰ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Prohibit zone");//Tϰ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_ZONE_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe8\xb7\x9d\xe9\x9b\xa2\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\xb5\xe6\xb8\xac");//ZHW UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Distance violation");//ZHW UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_DISTANCE_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\xab\x98\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//װ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Height detection");//װ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_HIGH_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe4\xb8\x8d\xe7\xa6\xae\xe8\xae\x93\xe5\x81\xb5\xe6\xb8\xac");//§ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Forget to give way detection");//§ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_FORGET_TO_GIVE_WAY"); + } + else if ((q_info->behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe5\xa4\xa7\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//̤jtװ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Max speed detection");//̤jtװ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_SPEED_HIGH"); + } + else if ((q_info->behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe4\xbd\x8e\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//̧Ctװ UTF8 Encoder + else//en_gb + strcpy(q_info->behavior_desc, "Min speed detection");//̧Ctװ UTF8 Encoder + strcpy(q_info->behavior_name, "TRIGGER_SPEED_LOW"); + } + else if ((q_info->behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe9\x99\x90\xe6\x99\x82\xe5\x81\xb5\xe6\xb8\xac\x20\x2f\x20\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\x9c\xe8\xbb\x8a");//Tϭɰ / HW + else//en_gb + strcpy(q_info->behavior_desc, "Zone with dwell / Parking violation");//Tϭɰ / HW + strcpy(q_info->behavior_name, "TRIGGER_PARKING_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\x9b\xb4\xe8\xa1\x8c\xe5\x81\xb5\xe6\xb8\xac");//ĵٽu / 氻 + else//en_gb + strcpy(q_info->behavior_desc, "Tripwire / Traffic flow");//ĵٽu / 氻 + strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\xb4\x85\xe7\x87\x88\xe7\x9b\xb4\xe8\xa1\x8c");//Oĵٽu / O + else//en_gb + strcpy(q_info->behavior_desc, "Tripwire on red / Running red lights");//Oĵٽu / O + strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT_RED_LIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\xb7\xa6\xe8\xbd\x89");//O + else//en_gb + strcpy(q_info->behavior_desc, "Turning left on red");//O + strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT_RED_LIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\x8f\xb3\xe8\xbd\x89");//Ok + else//en_gb + strcpy(q_info->behavior_desc, "Turning right on red");//Ok + strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT_RED_LIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\xb7\xa6\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//఻ + else//en_gb + strcpy(q_info->behavior_desc, "Turn left");//఻ + strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT"); + } + else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\x8f\xb3\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//k఻ + else//en_gb + strcpy(q_info->behavior_desc, "Turn right");//k఻ + strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT"); + } + else if ((q_info->behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\x99\xbd\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//զWĵٰϰ + else//en_gb + strcpy(q_info->behavior_desc, "LPR allowed list detection in zone");//զWĵٰϰ + strcpy(q_info->behavior_name, "TRIGGER_ALLOW_LIST"); + } + else if ((q_info->behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe8\xa8\xaa\xe5\xae\xa2\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//XȦWĵٰϰ + else//en_gb + strcpy(q_info->behavior_desc, "LPR visitor list detection in zone");//XȦWĵٰϰ + strcpy(q_info->behavior_name, "TRIGGER_GUEST_LIST"); + } + else if ((q_info->behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\xbb\x91\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//¦Wĵٰϰ + else//en_gb + strcpy(q_info->behavior_desc, "LPR denial list detection in zone");//¦Wĵٰϰ + strcpy(q_info->behavior_name, "TRIGGER_BLOCK_LIST"); + } + else if ((q_info->behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\xaf\x86\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//Kװ + else//en_gb + strcpy(q_info->behavior_desc, "Density detection");//Kװ + strcpy(q_info->behavior_name, "TRIGGER_QUEUING_VIOLATION"); + } + else if ((q_info->behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\x41\x49\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//AI򥢪 + else//en_gb + strcpy(q_info->behavior_desc, "AI missing object detection");//AI򥢪 + strcpy(q_info->behavior_name, "TRIGGER_MISSING_OBJECT_DETECTION"); + } + else if ((q_info->behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x8f\x8a\xe9\x81\xba\xe7\x95\x99\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//򥢪οd + else//en_gb + strcpy(q_info->behavior_desc, "Unattended or missing object");//򥢪οd + strcpy(q_info->behavior_name, "TRIGGER_MISSING_UNATTENDED"); + } + else if ((q_info->behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe9\x98\xb2\xe7\xa0\xb4\xe5\xa3\x9e\xe5\x81\xb5\xe6\xb8\xac");//}a + else//en_gb + strcpy(q_info->behavior_desc, "Tampering detection");//}a + strcpy(q_info->behavior_name, "TRIGGER_TAMPERING"); + } + else if ((q_info->behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x41\x4e\x44\x29");//P˪ئPɦsb + else//en_gb + strcpy(q_info->behavior_desc, "All objects detection (AND)");//ئPɦsb (AND) + strcpy(q_info->behavior_name, "TRIGGER_ALL_OBJECTS"); + } + else if ((q_info->behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe7\xbc\xba\xe5\xb0\x91\xe4\xbb\xbb\xe4\xb8\x80\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x4e\x41\x4e\x44\x29");//ʤ֥@ئPɦsb (NAND) + else//en_gb + strcpy(q_info->behavior_desc, "Lack of any object detection (NAND)");//ʤ֥@ئPɦsb (NAND) + strcpy(q_info->behavior_name, "TRIGGER_LACK_OF_ANY_OBJECT"); + } + + //TRIGGER_SPEED_HIGHMTRIGGER_SPEED_LOWeNF + + /* + else if (q_info->behavior_ID & TRIGGER_BG_LEARNING) { + if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) + strcpy(q_info->behavior_desc, "\xe5\xad\xb8\xe7\xbf\x92\xe8\x83\x8c\xe6\x99\xaf\xe4\xb8\xad");//Dz߭I + else//en_gb + strcpy(q_info->behavior_desc, "BG learning");//Dz߭I + strcpy(q_info->behavior_name, "TRIGGER_BG_LEARNING"); + }*/ +} + +long Get_eventCounterList_post_interval(int index_counter) { +#ifdef GY_OS_V_SERIES + + +#else + if (strcmp(eventCounterList[index_counter].post_interval,"1 minute") == 0) { + return 60; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "5 minutes") == 0) { + return 60 * 5; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "30 minutes") == 0) { + return 60 * 30; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 hour") == 0) { + return 60 * 60; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 day") == 0) { + return 60 * 60 * 24; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 week") == 0) { + return 60 * 60 * 24 * 7; + } + else if (strcmp(eventCounterList[index_counter].post_interval, "1 month") == 0) { + return 60 * 60 * 24 * 30; + } + else +#endif + return -1; +} + +long Get_mail_post_interval() { + if (strcmp(SystemSetting.email_reset_time_interval, "1 minute") == 0) { + return 60; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "5 minutes") == 0) { + return 60 * 5; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "30 minutes") == 0) { + return 60 * 30; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 hour") == 0) { + return 60 * 60; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 day") == 0) { + return 60 * 60 * 24; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 week") == 0) { + return 60 * 60 * 24 * 7; + } + else if (strcmp(SystemSetting.email_reset_time_interval, "1 month") == 0) { + return 60 * 60 * 24 * 30; + } + else + return -1; +} + +struct timeval currtime_CheckPostEventCondition[MAX_DETECTION_ZONE]; +static long last_ms_CheckPostEventCondition[MAX_DETECTION_ZONE] = { 0 }; +#ifdef GY_OS_AMBA +struct timeval currtime_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE]; +static long last_ms_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE] = { 0 }; +#endif +struct timeval currtime_CheckPostEventCondition_cloud; +static long last_ms_CheckPostEventCondition_cloud = 0; + +struct timeval currtime_CheckPostEventCondition_cloud_v2; +static long last_ms_CheckPostEventCondition_cloud_v2 = 0; + +//struct timeval currtime_CheckPostEventCondition_cloud_record_v2; +//static long last_ms_CheckPostEventCondition_cloud_record_v2 = 0; + +struct timeval currtime_CheckPostEventCondition_counter[MAX_DETECTION_ZONE]; +static long last_ms_CheckPostEventCondition_counter[MAX_DETECTION_ZONE] = { 0 }; + +struct timeval currtime_CheckPostEventCondition_email; +static long last_ms_CheckPostEventCondition_email = 0; + +//#ifdef GY_OS_AMBA +struct timeval currtime_CheckPostEventCondition_ftp; +static long last_ms_CheckPostEventCondition_ftp = 0; +//#endif + +void initial_g_PostRecorderList() { + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + g_PostRecorderList[i].iIfUse = 0; + g_PostRecorderList[i].t_FirstGetTime = 0; + g_PostRecorderList[i].t_FirstGetTime_total = 0; + g_PostRecorderList[i].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[i].check_if_post[m] = 0; + } + g_PostRecorderList[i].check_if_cloud = 0; + g_PostRecorderList[i].check_if_cloud_v2 = 0; + g_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_PostRecorderList[i].check_if_email = 0; + g_PostRecorderList[i].check_if_ftp = 0; + g_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_PostRecorderList[i].box_x = 0.0; + g_PostRecorderList[i].box_y = 0.0; + g_PostRecorderList[i].box_w = 0.0; + g_PostRecorderList[i].box_h = 0.0; + + g_PostRecorderList[i].object_id = 0.0; + g_PostRecorderList[i].zone_idx = 0.0; + + strcpy(g_PostRecorderList[i].sPlateNumber, ""); + strcpy(g_PostRecorderList[i].name, ""); + + g_PostRecorderList[i].count_trigger = 0; + //g_PostRecorderList[i].the_same_id = 0; + //-------------------------------- + + g_longterm_PostRecorderList[i].iIfUse = 0; + g_longterm_PostRecorderList[i].t_FirstGetTime = 0; + g_longterm_PostRecorderList[i].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[i].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[i].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[i].check_if_cloud = 0; + g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[i].check_if_email = 0; + g_longterm_PostRecorderList[i].check_if_ftp = 0; + g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[i].box_x = 0.0; + g_longterm_PostRecorderList[i].box_y = 0.0; + g_longterm_PostRecorderList[i].box_w = 0.0; + g_longterm_PostRecorderList[i].box_h = 0.0; + + g_longterm_PostRecorderList[i].object_id = 0.0; + g_longterm_PostRecorderList[i].zone_idx = 0.0; + + strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); + strcpy(g_longterm_PostRecorderList[i].name, ""); + + g_longterm_PostRecorderList[i].count_trigger = 0; + //g_longterm_PostRecorderList[i].the_same_id = 0; + } +} + +void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx,int force_to_push,char* aiengine_data,int counter_idx, char* image_buff,int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) +{ + long d_no_parking_time = (long)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { + d_no_parking_time = (long)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); + } + + gettimeofday(&currtime_CheckPostEventCondition[detection_zone_idx], NULL); + long current_ms_CheckPostEventCondition = (currtime_CheckPostEventCondition[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition[detection_zone_idx].tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_cloud, NULL); + long current_ms_CheckPostEventCondition_cloud = (currtime_CheckPostEventCondition_cloud.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud.tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_cloud_v2, NULL); + long current_ms_CheckPostEventCondition_cloud_v2 = (currtime_CheckPostEventCondition_cloud_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_v2.tv_usec / 1000); + + //gettimeofday(&currtime_CheckPostEventCondition_cloud_record_v2, NULL); + //long current_ms_CheckPostEventCondition_cloud_record_v2 = (currtime_CheckPostEventCondition_cloud_record_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_record_v2.tv_usec / 1000); + + + gettimeofday(&currtime_CheckPostEventCondition_counter[detection_zone_idx], NULL); + long current_ms_CheckPostEventCondition_counter = (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_email, NULL); + long current_ms_CheckPostEventCondition_email = (currtime_CheckPostEventCondition_email.tv_sec * 1000) + (currtime_CheckPostEventCondition_email.tv_usec / 1000); + + gettimeofday(&currtime_CheckPostEventCondition_ftp, NULL); + long current_ms_CheckPostEventCondition_ftp = (currtime_CheckPostEventCondition_ftp.tv_sec * 1000) + (currtime_CheckPostEventCondition_ftp.tv_usec / 1000); + +#ifdef GY_OS_AMBA + gettimeofday(&currtime_CheckPostEventCondition_snmp[detection_zone_idx], NULL); + long current_ms_CheckPostEventCondition_snmp = (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_usec / 1000); +#endif + + //printf("\n--------------QueueSize:%d\n",(int)QueueSize(_POST_NOTIFICATION)); + + int check_if_ok_for_location = 0; + int index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + int size_g_PostRecorderList = 0; + + //int check_if_ok_for_location_longterm = 0; + int index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; + int size_g_PostRecorderList_longterm = 0; + + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + + if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0) { + //printf("\nFFFFFFF : 1\n"); + if (pNext != NULL /*&& aiengine_data != NULL && strlen(aiengine_data) >= 1*/ && counter_idx == -1) { + //printf("\nFFFFFFF : 2\n"); + if (strlen(pNext->name) >= 1 && pNext->width > 0 && pNext->height > 0 /*&& !(IsANPRCategory_L_Plate(pNext->name))*/) + { + //printf("\nFFFFFFF : 3\n"); + //Free over Recoder time + + + int iFindMatchPost = 0; + int iFindMatchPost_longterm = 0; + time_t now_time = time(0); + + double max_dwell_short = 0.0; + + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + if (g_PostRecorderList[i].iIfUse == 0 && g_longterm_PostRecorderList[i].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[i].iIfUse == 1 /*&& g_PostRecorderList[i].zone_idx == detection_zone_idx*/) + { + if (g_PostRecorderList[i].box_w > 0 && g_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_PostRecorderList[i].box_x; + temp_A.top_y = g_PostRecorderList[i].box_y; + temp_A.width = g_PostRecorderList[i].box_w; + temp_A.height = g_PostRecorderList[i].box_h; + strcpy(temp_A.name, g_PostRecorderList[i].name); + + float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + { + if (strcmp(g_PostRecorderList[i].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + } + else { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + iFindMatchPost = 1; + //g_PostRecorderList[i].t_UpdateTime = now_time; + //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + } + } + } + } + } + } + } + + if (g_longterm_PostRecorderList[i].iIfUse == 1 /*&& g_longterm_PostRecorderList[i].zone_idx == detection_zone_idx*/) + { + if (g_longterm_PostRecorderList[i].box_w > 0 && g_longterm_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_longterm_PostRecorderList[i].box_x; + temp_A.top_y = g_longterm_PostRecorderList[i].box_y; + temp_A.width = g_longterm_PostRecorderList[i].box_w; + temp_A.height = g_longterm_PostRecorderList[i].box_h; + strcpy(temp_A.name, g_longterm_PostRecorderList[i].name); + + float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + { + if (strcmp(g_longterm_PostRecorderList[i].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + } + else { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + iFindMatchPost_longterm = 1; + //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + } + } + } + } + } + } + } + } + +#if 1 + if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { + if (iFindMatchPost_longterm == 0) + { + //printf("\nFFFFFFF : 4\n"); + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + if (g_longterm_PostRecorderList[i].iIfUse == 0) + { + g_longterm_PostRecorderList[i].iIfUse = 1; + g_longterm_PostRecorderList[i].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[i].t_FirstGetTime_total = now_time; + g_longterm_PostRecorderList[i].t_UpdateTime = now_time; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[i].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[i].check_if_cloud = 0; + g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[i].check_if_email = 0; + g_longterm_PostRecorderList[i].check_if_ftp = 0; + g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; + g_longterm_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; + g_longterm_PostRecorderList[i].box_w = pNext->width / 3.0; + g_longterm_PostRecorderList[i].box_h = pNext->height / 3.0; + + g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; + + //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); + + if (IsANPRCategory_L_Plate(pNext->name)) { + strcpy(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate); + } + else { + strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); + } + strcpy(g_longterm_PostRecorderList[i].name, pNext->name); + + g_longterm_PostRecorderList[i].count_trigger = 1; + //g_longterm_PostRecorderList[i].the_same_id = 0; + + //check_if_ok_for_location_longterm = 1; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; + size_g_PostRecorderList_longterm++; + } + break; + } + } + + } + } +#endif + + if (iFindMatchPost == 0) + { + //printf("\nFFFFFFF : 4\n"); + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) + { + if (g_PostRecorderList[i].iIfUse == 0) + { + g_PostRecorderList[i].iIfUse = 1; + g_PostRecorderList[i].t_FirstGetTime = now_time; + g_PostRecorderList[i].t_FirstGetTime_total = now_time; + g_PostRecorderList[i].t_UpdateTime = now_time; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[i].check_if_post[m] = 0; + } + g_PostRecorderList[i].check_if_cloud = 0; + g_PostRecorderList[i].check_if_cloud_v2 = 0; + g_PostRecorderList[i].check_if_cloud_record_v2 = 0; + g_PostRecorderList[i].check_if_email = 0; + g_PostRecorderList[i].check_if_ftp = 0; + g_PostRecorderList[i].check_if_getalarmmotion = 0; + + g_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; + g_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; + g_PostRecorderList[i].box_w = pNext->width / 3.0; + g_PostRecorderList[i].box_h = pNext->height / 3.0; + + g_PostRecorderList[i].object_id = pNext->obj_tracking_id; + g_PostRecorderList[i].zone_idx = detection_zone_idx; + + //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); + + if (IsANPRCategory_L_Plate(pNext->name)){ + strcpy(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate); + } + else { + strcpy(g_PostRecorderList[i].sPlateNumber, ""); + } + strcpy(g_PostRecorderList[i].name, pNext->name); + + g_PostRecorderList[i].count_trigger = 1; + //g_PostRecorderList[i].the_same_id = 0; + + check_if_ok_for_location = 1; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = i; + size_g_PostRecorderList++; + } + break; + } + } + + } + } + + } + } + + //printf("\n--------check_if_ok_for_location :%d\n", check_if_ok_for_location); + +#ifdef GY_OS_AMBA + if (pNext == NULL || strcmp(SystemSetting.enable_post_only_if_both_detected, "No") == 0 || + (strcmp(SystemSetting.enable_post_only_if_both_detected, "Yes") == 0 && + pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) || + !(viewChannelData[0].enable_anpr) || + !(viewChannelData[0].enable_face) || + !(viewChannelData[0].enable_traffic) || + !IsANPRCategory(featureType) || + !(featureType & FEATURE_TRAF_DET)) +#endif + { + + if (activePostNotification && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + + //printf("\n----------------check_if_post:%d,size_g_PostRecorderList:%d\n", g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx], size_g_PostRecorderList); + //printf("\n--------CheckPostEventCondition:1\n"); + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx] == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_post[detection_zone_idx] == 0)))) { + //printf("\n--------CheckPostEventCondition:2\n"); + if (last_ms_CheckPostEventCondition[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition - last_ms_CheckPostEventCondition[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { + + + + //printf("\n--------CheckPostEventCondition:3\n"); + char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); + int post_event_num = StrSplit(Temp, eachPostEvent, ","); + //printf("\n------UU:5\n"); + //char *replacement = NULL; + //char *replacement_t = NULL; + + int check_if_SD_recording_post = 0; + int index_SD_post = -1; + + int check_if_white_LED_post = 0; + int index_LED_post = -1; + + int index_first_post = -1; + + if (post_event_num >= 1 && strcmp(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name,"Null")!=0) { + + for (int i = 0; i < post_event_num; i++) + { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) + { + if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) + { + if (index_first_post == -1) { + index_first_post = j; + } + + if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "SD recording") != NULL && g_check_if_no_brand == 0) { + index_SD_post = j; + check_if_SD_recording_post = 1; + } + + if (g_camera_white_LED == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "White LED") != NULL && g_check_if_no_brand == 0) { + index_LED_post = j; + check_if_white_LED_post = 1; + } + } + else + { + /* + printf("Post queue is full!\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + pthread_mutex_lock(&mutex_curl); + if(QueueSize(_POST_NOTIFICATION) >= 1) + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_post_notification_pop); + printf("Post queue is full!end\n");*/ + } + //break; + } + } + } + + if (index_SD_post == -1 && index_LED_post >= 0) { + index_SD_post = index_LED_post; + } + + if (index_SD_post == -1) { + index_SD_post = index_first_post; + } + + //printf("\n-----------index_SD_post:%d\n", index_SD_post); + + int check_if_status_cloud = 0; + + if (index_SD_post >= 0) { + time_t rawtime_temp = g_post_SysTimeStamp; + + //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); + //if(aiengine_data != NULL) + //printf("\n------------aiengine_data:%s\n", aiengine_data); + //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); + //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); + + if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && g_check_if_no_brand == 0 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL)) + ) + { + + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { + if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { + check_if_status_cloud = 1; + } + } + } + + //printf("\n---------check_if_SD_recording_post:%d,check_if_status_cloud:%d\n", check_if_SD_recording_post, check_if_status_cloud); + + if ((check_if_SD_recording_post == 0 && check_if_white_LED_post == 0) || check_if_status_cloud == 1) { + + last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_post[detection_zone_idx] = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_post[detection_zone_idx] = 1; + } + + //printf("\n--------CheckPostEventCondition:4\n"); + for (int post_times = 0; post_times < 2; post_times++) { + + int temp_index_post = 0; + if (post_times == 0 && index_SD_post >= 0) { + temp_index_post = index_SD_post; + } + else { + if (check_if_SD_recording_post == 1 && check_if_white_LED_post == 1 && index_LED_post >= 0) { + temp_index_post = index_LED_post; + } + else { + break; + } + } + + pthread_mutex_lock(&mutex_post_notification_pop); + postEventList[temp_index_post].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[temp_index_post].post_event_name); + strcpy(q_info.post_protocol, postEventList[temp_index_post].post_protocol); + strcpy(q_info.post_method, postEventList[temp_index_post].post_event_method); + strcpy(q_info.host_name, postEventList[temp_index_post].post_host_ip); + strcpy(q_info.host_port, postEventList[temp_index_post].post_host_port); + strcpy(q_info.post_timeout, postEventList[temp_index_post].post_timeout); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (strlen(postEventList[temp_index_post].post_url) >= 1) { + //if (pNext != NULL) { + size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[temp_index_post].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.post_url, postEventList[temp_index_post].post_url); + //} + q_info.post_url[url_size] = '\0'; + } + else + q_info.post_url[0] = '\0'; + + //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); + + strcpy(q_info.post_username, postEventList[temp_index_post].post_username); + strcpy(q_info.post_password, postEventList[temp_index_post].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[temp_index_post].post_jpeg_file_name); + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + if (strcmp(postEventList[temp_index_post].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[temp_index_post].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[temp_index_post].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + if (strcmp(postEventList[temp_index_post].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + + if (strlen(postEventList[temp_index_post].post_content) >= 1) { + + //if (pNext != NULL) { + //printf("\n------check post 2--------6------3\n"); + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //q_info.content_size = 0; + //printf("\n-----size:%lu\n", q_info.content_size); + //printf("\n------check post 2--------6------4\n"); + //} + //else { + //strcpy(q_info.content, postEventList[temp_index_post].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[temp_index_post].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[temp_index_post].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.content, postEventList[temp_index_post].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + //printf("\n----------_POST_NOTIFICATION\n"); + //printf("\n------check post 3\n"); + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + //printf("\n------check post 3--------1\n"); + if (force_to_push == 1) { + //printf("\n------check post 3--------2\n"); + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if(g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + //printf("\n------check post 3--------3\n"); + } + else { + //printf("\n------check post 3--------4\n"); + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + //printf("\n------check post 3--------5\n"); + } + } + //printf("\n------check post 4\n"); + pthread_mutex_unlock(&mutex_post_notification_pop); + } + + //if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && check_if_SD_recording_post == 1 && + //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1))) + + if (check_if_status_cloud == 1) + { + //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) + { + //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) + { + //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + //printf("\n------------Segmentation fault:%d\n", 5); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "post_to_cloud"); + strcpy(q_info.cloud_aiengine, aiengine_data); + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + q_info.rawtime = rawtime_temp; + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); + + /** + printf("\n-------------\n"); + printf("\nbehavior_ID: %d\n", q_info.behavior_ID); + printf("\n-------------\n");*/ + + + QueuePush(q_info, _POST_NOTIFICATION); + + //printf("\n------------Segmentation fault:%d\n", 6); + } + last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; + } + } + } + } + + } + } + + for (int i = 0; i < post_event_num; i++) + { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) + { + if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) + { + if (index_SD_post != j && index_LED_post != j) { + + last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; + + for (int k = 0; k < size_g_PostRecorderList; k++) { + g_PostRecorderList[index_g_PostRecorderList[k]].check_if_post[detection_zone_idx] = 1; + } + + for (int k = 0; k < size_g_PostRecorderList_longterm; k++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[k]].check_if_post[detection_zone_idx] = 1; + } + + pthread_mutex_lock(&mutex_post_notification_pop); + postEventList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[j].post_event_name); + strcpy(q_info.post_protocol, postEventList[j].post_protocol); + strcpy(q_info.post_method, postEventList[j].post_event_method); + strcpy(q_info.host_name, postEventList[j].post_host_ip); + strcpy(q_info.host_port, postEventList[j].post_host_port); + strcpy(q_info.post_timeout, postEventList[j].post_timeout); + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + + if (strlen(postEventList[j].post_url) >= 1) { + //if (pNext != NULL) { + size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.post_url, postEventList[j].post_url); + //} + q_info.post_url[url_size] = '\0'; + } + else + q_info.post_url[0] = '\0'; + + //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); + + strcpy(q_info.post_username, postEventList[j].post_username); + strcpy(q_info.post_password, postEventList[j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + //printf("\n----------_POST_NOTIFICATION\n"); + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (force_to_push == 1) { + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + else { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + } + } + } + } + } + else { + time_t rawtime_temp = g_post_SysTimeStamp; + + int check_if_status_cloud = 0; + //printf("\n--------CheckPostEventCondition:4\n"); + //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); + //if(aiengine_data != NULL) + //printf("\n------------aiengine_data:%s\n", aiengine_data); + //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); + //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); + /* + if (aiengine_data != NULL) { + printf("\n--------strlen(aiengine_data):%d\n", strlen(aiengine_data)); + } + else { + printf("\n-------strlen(aiengine_data):NULL\n"); + } + + if (pNext == NULL) { + printf("\n--------pNext:NULL\n"); + } + else { + printf("\n--------pNext:not NUll\n"); + }*/ + + if (aiengine_data != NULL && strlen(aiengine_data) >= 1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + //printf("\n--------CheckPostEventCondition:5--1\n"); + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { + + //printf("\n--------CheckPostEventCondition:5--2\n"); + if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { + check_if_status_cloud = 1; + } + } + } + //printf("\n--------check_if_status_cloud:%d\n", check_if_status_cloud); + if (check_if_status_cloud == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && g_check_if_no_brand == 0) + { + //printf("\n--------CheckPostEventCondition:6\n"); + //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) + { + //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) + { + //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + //printf("\n------------Segmentation fault:%d\n", 5); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "post_to_cloud"); + strcpy(q_info.cloud_aiengine, aiengine_data); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + q_info.rawtime = rawtime_temp; + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); + + /** + printf("\n-------------\n"); + printf("\nbehavior_ID: %d\n", q_info.behavior_ID); + printf("\n-------------\n");*/ + + + QueuePush(q_info, _POST_NOTIFICATION); + + //printf("\n------------Segmentation fault:%d\n", 6); + } + last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; + } + } + } + } + } + } + } + } + + if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0 && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud_v2 == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud_v2)))) { + if (last_ms_CheckPostEventCondition_cloud_v2 == 0 || (current_ms_CheckPostEventCondition_cloud_v2 - last_ms_CheckPostEventCondition_cloud_v2) >= atoi(SystemSetting.cloud_v2_notification_dwell) * 1000) { + //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + //printf("\n------------Segmentation fault:%d\n", 5); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "cloud_v2"); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (strlen(SystemSetting.cloud_v2_content) >= 1) { + //if (pNext != NULL) { + size_t v2_size = ReplaceKeyWords(pNext, -1, -1, SystemSetting.cloud_v2_content, q_info.cloud_v2_aiengine, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 1); + //} + //else { + //strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); + //} + q_info.cloud_v2_aiengine[v2_size] = '\0'; + } + else + q_info.cloud_v2_aiengine[0] = '\0'; + + //strcpy(q_info.cloud_v2_aiengine, aiengine_data); + + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); + + /** + printf("\n-------------\n"); + printf("\nbehavior_ID: %d\n", q_info.behavior_ID); + printf("\n-------------\n");*/ + + + QueuePush(q_info, _GETALARMMOTION); + + //printf("\n------------Segmentation fault:%d\n", 6); + } + last_ms_CheckPostEventCondition_cloud_v2 = current_ms_CheckPostEventCondition_cloud_v2; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud_v2 = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud_v2 = 1; + } + } + } + } + +#ifdef GY_OS_AMBA + if (activeSNMPPost && /*strcmp(SystemSetting.enable_cloud, "Yes") == 0 &&*/ counter_idx == -1) { + + //printf("\n--------CheckPostEventCondition:2\n"); + if (last_ms_CheckPostEventCondition_snmp[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition_snmp - last_ms_CheckPostEventCondition_snmp[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { + + //printf("\n--------CheckPostEventCondition:3\n"); + char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); + int post_event_num = StrSplit(Temp, eachPostEvent, ","); + //printf("\n------UU:10\n"); + //char *replacement = NULL; + //char *replacement_t = NULL; + + for (int i = 0; i < post_event_num; i++) + { + for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) + { + if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], SNMPManagementList[j].snmp_event_name) == 0) + { + if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && SNMPManagementList[j].check_if_delivering == 0) + { + //printf("\n--------CheckPostEventCondition:4\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + SNMPManagementList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + + strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); + strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); + strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); + strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); + strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); + strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); + strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); + + if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value,"<|hextoint|>")==0){ + size_t snmp_size = ReplaceKeyWords(pNext, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); + q_info.snmp_value[snmp_size] = '\0'; + } + else { + strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); + } + + //printf("\n------q_info.snmp_value:%s\n", q_info.snmp_value); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + //printf("\n----------_POST_NOTIFICATION\n"); + + if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { + if (force_to_push == 1) { + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + else { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + else + { + /* + printf("Post queue is full!\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + pthread_mutex_lock(&mutex_curl); + if(QueueSize(_POST_NOTIFICATION) >= 1) + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_post_notification_pop); + printf("Post queue is full!end\n");*/ + } + break; + } + } + } + last_ms_CheckPostEventCondition_snmp[detection_zone_idx] = current_ms_CheckPostEventCondition_snmp; + } + } +#endif + +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + if (activePostNotification && counter_idx >= 0 && Get_eventCounterList_post_interval(counter_idx) != -1) { + if (last_ms_CheckPostEventCondition_counter[detection_zone_idx] == 0 || (Get_eventCounterList_post_interval(counter_idx) != -1 && (current_ms_CheckPostEventCondition_counter - last_ms_CheckPostEventCondition_counter[detection_zone_idx]) >= Get_eventCounterList_post_interval(counter_idx) * 1000)) { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strlen(postEventList[j].post_event_name) >= 1 && strcmp(eventCounterList[counter_idx].link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + postEventList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[j].post_event_name); + strcpy(q_info.post_protocol, postEventList[j].post_protocol); + strcpy(q_info.post_method, postEventList[j].post_event_method); + strcpy(q_info.host_name, postEventList[j].post_host_ip); + strcpy(q_info.host_port, postEventList[j].post_host_port); + strcpy(q_info.post_timeout, postEventList[j].post_timeout); + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (strlen(postEventList[j].post_url) >= 1) { + //if (pNext != NULL) { + size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,0); + //} + //else { + //strcpy(q_info.post_url, postEventList[j].post_url); + //} + q_info.post_url[url_size] = '\0'; + } + else + q_info.post_url[0] = '\0'; + + //printf("\n------ q_info.post_url #2:%s\n", q_info.post_url); + + strcpy(q_info.post_username, postEventList[j].post_username); + strcpy(q_info.post_password, postEventList[j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); + if (image_buff_size >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[j].post_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); + //} + //else { + //strcpy(q_info.content, postEventList[j].post_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + /*if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + + g_IsCustomWeight == 1) { + char buf_content[256] = { '\0' }; + sprintf(buf_content, "{\"counter_name\":\"%s\",\"counter_count\":%d}", eventCounterList[counter_idx].counter_name, eventCounterList[counter_idx].counter_count); + + strcpy(q_info.content, buf_content); + }*/ + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (force_to_push == 1) { + for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + else { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + else + { + /* + printf("Post queue is full!\n"); + pthread_mutex_lock(&mutex_post_notification_pop); + pthread_mutex_lock(&mutex_curl); + if(QueueSize(_POST_NOTIFICATION) >= 1) + QueueClear(_POST_NOTIFICATION); + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_post_notification_pop); + printf("Post queue is full!end\n");*/ + } + break; + } + } + + last_ms_CheckPostEventCondition_counter[detection_zone_idx] = current_ms_CheckPostEventCondition_counter; + } + } + } +#endif + + if (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_email == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_email == 0)))) { + if (last_ms_CheckPostEventCondition_email == 0 || + (Get_mail_post_interval() == -1 && (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > d_no_parking_time * 1000) || + (Get_mail_post_interval() != -1 && (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000) || + force_to_push == 1) { + if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + QueueInfo q_info = { 0 }; + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (image_buff_size_base64 >= 1) { + memcpy(q_info.image_buff, image_buff_base64, image_buff_size_base64); + q_info.image_buff_size = image_buff_size_base64; + } + else { + q_info.image_buff_size = 0; + } + + if (strlen(emailData.email_content) >= 1) { + //if (pNext != NULL) { + q_info.content_size = ReplaceKeyWords(pNext, -1, -1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); + //} + //else { + //strcpy(q_info.content, emailData.email_content); + //} + q_info.content[q_info.content_size] = '\0'; + } + else { + q_info.content[0] = ' '; + q_info.content[1] = '\0'; + } + + strcpy(q_info.post_url, "post_to_mail"); + UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); + + + QueuePush(q_info, _POST_NOTIFICATION); + +#if 1 +#ifdef GY_OS_V_SERIES + +#else + if (Get_mail_post_interval() != -1) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } + } +#endif +#endif + } + last_ms_CheckPostEventCondition_email = current_ms_CheckPostEventCondition_email; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_email = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_email = 1; + } + } + } + } +//#ifdef GY_OS_AMBA + if (strcmp(SystemSetting.enable_ftp, "Yes") == 0 && counter_idx == -1 && + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| + ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { + if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || + (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_ftp == 0 && + (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_ftp == 0)))){ + if (last_ms_CheckPostEventCondition_ftp == 0 || (current_ms_CheckPostEventCondition_ftp - last_ms_CheckPostEventCondition_ftp) > d_no_parking_time * 1000 || force_to_push == 1) + { + if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + { + QueueInfo q_info = { 0 }; + + if (pNext != NULL) { + strcpy(q_info.q_name, pNext->name); + if (pNext->linked_plate_length >= 1) { + strcpy(q_info.q_plate, pNext->linked_plate); + } + else { + strcpy(q_info.q_plate, pNext->properties.plate); + } + } + + if (image_buff_size_base64 >= 1) { + memcpy(q_info.image_buff, image_buff, image_buff_size); + q_info.image_buff_size = image_buff_size; + } + else { + q_info.image_buff_size = 0; + } + + /* + if (strlen(emailData.email_content) >= 1) { + if (pNext != NULL) { + ReplaceKeyWords(pNext,-1,-1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); + } + else { + strcpy(q_info.content, emailData.email_content); + } + } + else*/ + { + q_info.content[0] = ' '; + q_info.content[1] = '\0'; + } + + strcpy(q_info.post_url, "curl_to_ftp"); + //UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); + + if (q_info.image_buff_size >= 1) { + QueuePush(q_info, _POST_NOTIFICATION); + } + } + last_ms_CheckPostEventCondition_ftp = current_ms_CheckPostEventCondition_ftp; + + for (int i = 0; i < size_g_PostRecorderList; i++) { + g_PostRecorderList[index_g_PostRecorderList[i]].check_if_ftp = 1; + } + + for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_ftp = 1; + } + } + } + } +//#endif + } +} + +struct timeval currtime_HeartbeatPost; +static long last_ms_HeartbeatPost = 0; +#if defined GY_OS_AMBA +struct timeval currtime_snmp_HeartbeatPost; +static long last_ms_snmp_HeartbeatPost = 0; +#endif +void HeartbeatPost() +{ + if (activePostNotification && strcmp(heartbeatData.enable_heartbeat,"Yes")==0) { + gettimeofday(&currtime_HeartbeatPost, NULL); + long current_ms_HeartbeatPost = (currtime_HeartbeatPost.tv_sec * 1000) + (currtime_HeartbeatPost.tv_usec / 1000); + if (last_ms_HeartbeatPost == 0 || (current_ms_HeartbeatPost - last_ms_HeartbeatPost) >= atoi(heartbeatData.heartbeat_dwell) * 1000 * 60) { + + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(heartbeatData.heartbeat_link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + int index_j = j; + + postEventList[index_j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_HeartbeatPost = current_ms_HeartbeatPost; + } + } +#if defined GY_OS_AMBA + if (activeSNMPPost && strcmp(heartbeatData.enable_snmp_heartbeat, "Yes") == 0) { + gettimeofday(&currtime_snmp_HeartbeatPost, NULL); + long current_ms_snmp_HeartbeatPost = (currtime_snmp_HeartbeatPost.tv_sec * 1000) + (currtime_snmp_HeartbeatPost.tv_usec / 1000); + if (last_ms_snmp_HeartbeatPost == 0 || (current_ms_snmp_HeartbeatPost - last_ms_snmp_HeartbeatPost) >= (long)(atof(heartbeatData.snmp_heartbeat_dwell) * 1000.0)) { + for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) + { + if (strcmp(heartbeatData.snmp_heartbeat_link_to_post_event_name, SNMPManagementList[j].snmp_event_name) == 0) + { + if (SNMPManagementList[j].check_if_delivering == 0) { + pthread_mutex_lock(&mutex_post_notification_pop); + + SNMPManagementList[j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + + strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); + strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); + strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); + strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); + strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); + strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); + strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); + strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); + + if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value, "<|hextoint|>") == 0) { + size_t snmp_size = ReplaceKeyWords(NULL, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, 0, 0, 0, NULL, 0, 0, NULL, 0, 0); + q_info.snmp_value[snmp_size] = '\0'; + } + else { + strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); + } + + if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_snmp_HeartbeatPost = current_ms_snmp_HeartbeatPost; + } + } +#endif +} +#ifdef GY_OS_AMBA +struct timeval currtime_check_start_PTZ_autotracking_Post; +static long last_ms_check_start_PTZ_autotracking_Post = 0; +int last_state_PTZ_autotracking_for_start = 0; +int current_state_PTZ_autotracking_for_start = 0; +void check_start_PTZ_autotracking_Post() +{ + if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { + current_state_PTZ_autotracking_for_start = 1; + } + else { + current_state_PTZ_autotracking_for_start = 0; + } + + gettimeofday(&currtime_check_start_PTZ_autotracking_Post, NULL); + long current_ms_check_start_PTZ_autotracking_Post = (currtime_check_start_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_start_PTZ_autotracking_Post.tv_usec / 1000); + + if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_start_autotracking, "Yes") == 0) { + if (last_ms_check_start_PTZ_autotracking_Post == 0 || (current_ms_check_start_PTZ_autotracking_Post - last_ms_check_start_PTZ_autotracking_Post) >= 2000) { + if (last_state_PTZ_autotracking_for_start == 0 && current_state_PTZ_autotracking_for_start == 1) { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(heartbeatData.ptz_start_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + int index_j = j; + + postEventList[index_j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; + } + else{ + last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; + } + } + } +} + +struct timeval currtime_check_end_PTZ_autotracking_Post; +static long last_ms_check_end_PTZ_autotracking_Post = 0; +int last_state_PTZ_autotracking_for_end = 0; +int current_state_PTZ_autotracking_for_end = 0; +void check_end_PTZ_autotracking_Post() +{ + if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { + current_state_PTZ_autotracking_for_end = 1; + } + else { + current_state_PTZ_autotracking_for_end = 0; + } + + gettimeofday(&currtime_check_end_PTZ_autotracking_Post, NULL); + long current_ms_check_end_PTZ_autotracking_Post = (currtime_check_end_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_end_PTZ_autotracking_Post.tv_usec / 1000); + + if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_end_autotracking, "Yes") == 0) { + if (last_ms_check_end_PTZ_autotracking_Post == 0 || (current_ms_check_end_PTZ_autotracking_Post - last_ms_check_end_PTZ_autotracking_Post) >= 2000) { + if (last_state_PTZ_autotracking_for_end == 1 && current_state_PTZ_autotracking_for_end == 0) { + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(heartbeatData.ptz_end_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) + { + if (postEventList[j].check_if_delivering == 0) + { + pthread_mutex_lock(&mutex_post_notification_pop); + int index_j = j; + + postEventList[index_j].check_if_delivering = 1; + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { + if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) + QueuePush(q_info, _POST_NOTIFICATION); + } + pthread_mutex_unlock(&mutex_post_notification_pop); + } + break; + } + } + last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; + } + else{ + last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; + last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; + } + } + } +} +#endif +curl_information_smtp_t user_smtp; +void SendMailEventCondition(char *my_subject,char * my_content, char* image_buff, int image_buff_size) { + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + size_t snapshot_size = 0; + if (image_buff_size >= 1) { + snapshot_size = (size_t)image_buff_size; + memcpy(snapshot_addr, image_buff, snapshot_size); + } + + strcpy(user_smtp.receiver[0], IPCAMService.email_address1); + strcpy(user_smtp.receiver[1], IPCAMService.email_address2); + strcpy(user_smtp.receiver[2], IPCAMService.email_address3); + strcpy(user_smtp.receiver[3], IPCAMService.email_address4); + strcpy(user_smtp.receiver[4], IPCAMService.email_address5); + + strcpy(user_smtp.address, IPCAMService.email_address); + strcpy(user_smtp.server, IPCAMService.smtp_server); + sprintf(user_smtp.auth_mode, "%d", IPCAMService.smtp_auth_mode); + strcpy(user_smtp.port, IPCAMService.smtp_port); + sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); + strcpy(user_smtp.user, IPCAMService.auth_account); + strcpy(user_smtp.password, IPCAMService.auth_password); + + strcpy(user_smtp.subject, my_subject); + strcpy(user_smtp.memory_data.memory, my_content); + user_smtp.memory_data.size = strlen(my_content); + + strcpy(user_smtp.attachment, "snap.jpg"); + + + if (net_curl_smtp_data(&user_smtp, snapshot_addr,(int)snapshot_size) < 0) { + printf("\nSMTP Fail\n"); + } + else { + printf("\nSMTP OK\n"); + } +} + +void ResetCheckIfDelivering() { + for (int i = 0; i < MAX_POST_EVENTS; i++) + { + postEventList[i].check_if_delivering = 0; + } +//#ifdef GY_OS_AMBA + //for (int i = 0; i < MAX_SNMP_MANAGEMENT; i++) + //{ + //SNMPManagementList[i].check_if_delivering = 0; + //} +//#endif +} + +#ifdef GY_OS_V_SERIES + +#else +//struct timeval last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE], now_t_CheckEventCounterCondition; +//static long s_last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE] = { 0 }; +//static long s_now_t_CheckEventCounterCondition = 0; +int g_record_counter_count[MAX_EVENT_COUNTERS] = { 0 }; +long g_record_counter_time[MAX_EVENT_COUNTERS] = { 0 }; + +#endif + +struct timeval currtime_CheckEventCounterCondition[MAX_EVENT_COUNTERS]; +static long last_ms_CheckEventCounterCondition[MAX_EVENT_COUNTERS] = { 0 }; + +void CheckEventCounterCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int enable_counter_post, char* image_buff, int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) +{ +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1 || unlockingKeyInnoFR_success == 1 ) { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + //printf("\n------UU:11\n"); + + //gettimeofday(&now_t_CheckEventCounterCondition, NULL); + //s_now_t_CheckEventCounterCondition = now_t_CheckEventCounterCondition.tv_sec; //쬰 + + float dwell_time_event_counter = (float)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { + dwell_time_event_counter = (float)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); + } + + + + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); + + /////////////////////////// + + char ObjectName[30] = { 0 }; + + if (pNext != NULL) { + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + } + + + //char metadata1[512][STRSPLIT_SIZE] = {0}; //for vehicle + //char MetaData1[BUFSIZE] = { 0 }; + //char MetaOut1[512][50] = { 0 }; + //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); + + //int metadata1_num = get_metadata1_num(detection_zone_idx); + + + //for (int i = 0; i < metadata1_num; i++) + //{ + //UpperToLower(metadata1[i]); + //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); + //} + + //////////////////////// + + for (int i = 0; i < event_counter_num; i++) + { + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + if (strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) + { + gettimeofday(&currtime_CheckEventCounterCondition[j], NULL); + long current_ms_CheckEventCounterCondition = (currtime_CheckEventCounterCondition[j].tv_sec * 1000) + (currtime_CheckEventCounterCondition[j].tv_usec / 1000); + + if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") != 0 || (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0 && + (last_ms_CheckEventCounterCondition[j] == 0 || (current_ms_CheckEventCounterCondition - last_ms_CheckEventCounterCondition[j]) > dwell_time_event_counter * 1000))) + { + last_ms_CheckEventCounterCondition[j] = current_ms_CheckEventCounterCondition; + //eventCounterList[j].metadata1_num = metadata1_num; + + //for (int m = 0; m < metadata1_num; m++) { + //strcpy(eventCounterList[j].MetaOut1[m], get_meta_class(m, detection_zone_idx)); + //} + + if (pNext == NULL) { + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count > 2000000000) { + eventCounterList[j].counter_count = 2000000000; + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { + //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count < 0) { + eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { + //eventCounterList[j].counter_count = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + else { + if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { + + eventCounterList[j].counter_count = g_record_counter_count[j]; + + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + } + } + } + else if ((strcmp(eventCounterList[j].enable_time_range, "Yes") != 0 && + (((!((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) ) || + (pNext != NULL && !(IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) || + (pNext != NULL && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) )) + ) || + (pNext != NULL && strcmp(eventCounterList[j].enable_time_range, "Yes") == 0 && pNext->det_time >= eventCounterList[j].timetTimeRangeFrom && pNext->det_time < eventCounterList[j].timetTimeRangeTo)) + { + + //printf("\n----------eventCounterList[j].counter_count:%d\n", eventCounterList[j].counter_count); + //printf("\n----------viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num:%d\n", viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num); + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count > 2000000000) { + eventCounterList[j].counter_count = 2000000000; + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { + //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); + eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; + if (eventCounterList[j].counter_count < 0) { + eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value + } + } + else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { + + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + else { + if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { + + eventCounterList[j].counter_count = g_record_counter_count[j]; + + g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; + g_record_counter_time[j] = g_osdSysTimeStamp; + } + } + } + + //printf("\neventCounterList[%d].counter_count:%d\n",j, eventCounterList[j].counter_count); + } + } + + if (enable_counter_post == 1) { + if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment != -2) + CheckPostEventCondition(pNext, tracking_channel_idx, detection_zone_idx, trigger_idx, 0, "", j, image_buff, image_buff_size, image_buff_base64, image_buff_size_base64, cropped_image_base64, cropped_image_size_base64); + } + + + break; + } + } + + } + + //printf("\n-------------------\n"); + } +#endif +} + +void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, CPoint* zone_polygon,int side_number,int zone_index,int iSource_ori_w, int iSource_ori_h) { + + CPoint p_person[MAX_SENSOR_TYPE0]; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 0; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 0; + int count_four_points_touch = 0; + int count_touch = 0; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + + if (g_sensors_type == 0) { + p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / iSource_ori_w); + p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / iSource_ori_h); + } + else { + p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / iSource_ori_w); + p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / iSource_ori_h); + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] = isInside(zone_polygon, side_number, p_person[index_p]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] == 1) { + count_touch++; + } + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] = isInside(zone_polygon, 4, p_person[index_p]); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] == 1) { + count_four_points_touch++; + } + } + + //printf("\n----------count_four_points_touch:%d\n", count_four_points_touch); + //printf("\n----------count_touch:%d\n", count_touch); + + int threahold_div = g_sensors_type == 0 ? 1 : 7; + + if (count_four_points_touch >= 45/threahold_div) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 1; + } + + if (count_touch >= 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 1; + pNext->IsInsideZone[zone_index] = 1; + } + +} + +struct timeval last_t_UpdateZoneStatus, now_t_UpdateZoneStatus; +static long s_last_t_UpdateZoneStatus[MAX_DETECTION_ZONE] = {0}; +static long s_now_t_UpdateZoneStatus = 0; +void MissingObjectDetection_VanishInZone(int tracking_channel_idx) { + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { + if (s_last_t_UpdateZoneStatus[j] == 0) { + gettimeofday(&last_t_UpdateZoneStatus, NULL); + s_last_t_UpdateZoneStatus[j] = last_t_UpdateZoneStatus.tv_sec; + } + } + + gettimeofday(&now_t_UpdateZoneStatus, NULL); + s_now_t_UpdateZoneStatus = now_t_UpdateZoneStatus.tv_sec; //쬰 + + int check_if_missing = 0; + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION) { + + float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; + + if ((s_now_t_UpdateZoneStatus - s_last_t_UpdateZoneStatus[j]) > dwell_time_missing_object_detection) { + s_last_t_UpdateZoneStatus[j] = s_now_t_UpdateZoneStatus; + + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) + break; + else { + int check_if_ever_existing = 0; + for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { + if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) + break; + else if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]) { + check_if_ever_existing = 1; + break; + } + } + + if (check_if_ever_existing == 1) { + + for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { + if (viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) + break; + else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] == 0 || + index_obj_tracking_id_in_zone_temp == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { + check_if_missing = 1; + break; + } + } + if (check_if_missing == 1) { + printf("\n-------------TRIGGER_MISSING_OBJECT_DETECTION check_if_missing: Yes------------\n"); + break; + } + } + } + } + + //TRIGGER_MISSING_OBJECT_DETECTION +#if 0 + printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION\n"); + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + printf("%d,", viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); + + } + printf("\n-----------------------------------------\n"); + + printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last\n"); + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); + + } + printf("\n-----------------------------------------\n"); + + printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last_two\n"); + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); + + } + printf("\n-----------------------------------------\n"); +#endif + + int k = 0; + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { + if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) + break; + else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]!= 0 && viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) { + viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[k] = viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; + k++; + } + } + } + for (int index_obj_tracking_id_in_zone = k; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) + viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; + + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; + } + + if (check_if_missing == 1) { + viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; + } + else { + viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; + } + } + } + } + } + } +} + + +void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, float fInSourceOri_w, float fInSourceOri_h, int total_element_size, detection_pos* PosInfo, int result_idx) +{ + + int side_number; + CPoint zone_polygon[6] = { 0 }; + //CPoint temp_zone_polygon[6] = { 0 }; + int b_ZoneExist = 0; + + detection_pos* pNext2 = NULL; + int BindNewLicensePlateOk = 0; + + /*//MAX_OBJ_DWELL_TIME + if (pNext->obj_dwell_time >= 20) { + pNext->obj_dwell_time = 21474830; + }*/ + + //for name comparison without case sensitive + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + //char MetaData1[BUFSIZE] = { 0 }; + //char MetaOut1[512][50] = { 0 }; + + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext->properties.plate); + pNext->linked_plate_length = pNext->properties.plate_length; + } + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; + } + + + if (viewChannelData[0].enable_traffic) { + for (int m = 0; m < total_element_size; m++) + { + pNext2 = PosInfo + m; + if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { + + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && + (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) + ) + { + strcpy(pNext->car_type_name, pNext2->name); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); + + break; + } + } + } + } + } + else { +#if 1 + //BindLicensePlateToVehicle + if (IsANPRCategory(featureType)) { + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + { + //test levenshtein_distance + //int dst = levenshtein_distance("Saturday", "Sunday"); //dst = 3 + //printf("dst = %d\n", dst); + + //pUpdateZoneNext = PosInfo + result_idx; + for (int k = 0/*result_idx + 1*/; k < total_element_size; k++) + { + pNext2 = PosInfo + k; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { +#ifdef _DEBUG_ZONE + printf("[%d]pNext2->engine_type == _PLATE \n", k); +#endif + + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && + (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) + ) + { +#ifdef _DEBUG_ZONE + printf("[%d]detection_overlap_ratio > 0.95 \n", k); +#endif + pNext2->car_logo_idx = result_idx; + strcpy(pNext2->car_type_name, pNext->name); + if (pNext2->obj_tracking_id_idx >= 0) { + strcpy(g_TrackingRecords[tracking_channel_idx][pNext2->obj_tracking_id_idx].car_type_name, pNext2->car_type_name); + } + //Steven MARK 20200930 + //printf("track_obj_id[%d]Plate = %s \n", tracking_obj_idx, pNext2->properties.plate); + + if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate)) + { + //if (levenshtein_distance(pNext2->properties.plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate) <= 3) + //{ + + if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext2->properties.plate); + pNext->linked_plate_length = pNext2->properties.plate_length; +#ifdef _DEBUG_ZONE + printf("=[%d] 11 set- [0x%x] pNext->link_plate = %s, name = %s, type = %d \n", j, pNext, pNext->linked_plate, pNext->name, pNext->obj_type); +#endif + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext2->properties.plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext2->properties.plate_length; + //printf("track_obj_id[%d]linkPlate = %s \n", tracking_obj_idx, pUpdateZoneNext->linked_plate); + BindNewLicensePlateOk = 1; + } + //} + } + break; + } + + } + } + + if (!BindNewLicensePlateOk) + { + if (strlen(pNext->linked_plate) == 0) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length >= atoi(viewChannelData[0].min_characters) && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate); + pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length; + } + } + else { + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; + } + } +#ifdef _DEBUG_ZONE + printf("=[%d] 22 set [0x%x] pUpdateZoneNext->link_plate = %s \n", j, pNext, pNext->linked_plate); +#endif + } + } + } +#endif //Steven TEMP MARK 20201012 + } + + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + side_number = viewDetectionZone[tracking_channel_idx][j].point_num; + side_number = 6; + + int check_existing_in_metaout = 0; + check_existing_in_metaout = check_if_existing_in_metaout(ObjectName, j); + //int metadata1_num = get_metadata1_num(j); + + if (check_existing_in_metaout == 0 && strcmp(ObjectName, "object") != 0 && strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0 && strcmp(ObjectName, "face") != 0 && IsANPRCategory_L_Plate(pNext->name) == 0) + { + continue; + } + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || /*|| (featureType & FEATURE_LPR_TWN) != 0*/ + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) + ) { + if (check_existing_in_metaout == 1 || (check_existing_in_metaout == 0 && strcmp(pNext->name, "blank") == 0)) { + if (viewDetectionZone[tracking_channel_idx][j].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][j].parking_line >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = k; + int index_plot = -1; + float min_parking_distance = 10000; + for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][j].parking_space; index_parking++) { + /* + detection_pos pNext_plot; + pNext_plot.left_x = g_parking_space_recording_x[j][index_parking] - pNext->width * 0.25; + pNext_plot.top_y = g_parking_space_recording_y[j][index_parking] - pNext->height * 0.25; + pNext_plot.width = pNext->width * 0.5; + pNext_plot.height = pNext->height * 0.5;*/ + + if (g_parking_space_recording_x[j][index_parking] != 0 && g_parking_space_recording_y[j][index_parking] != 0) { + + if (g_parking_space_recording_x[j][index_parking] >= pNext->left_x - pNext->width * 0.25 && g_parking_space_recording_x[j][index_parking] <= (pNext->left_x + pNext->width*1.25) && + g_parking_space_recording_y[j][index_parking] >= pNext->top_y - pNext->height * 0.25 && g_parking_space_recording_y[j][index_parking] <= (pNext->top_y + pNext->height*1.25) && + g_temp_parking_space_check_table[j][index_parking] == 0 /*&& detection_overlap_ratio_union(pNext,&pNext_plot) >= 0.9*/) + { + if (index_plot == -1) { + index_plot = index_parking; + min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + } + else { + float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + if (temp_min_parking_distance < min_parking_distance) { + index_plot = index_parking; + min_parking_distance = temp_min_parking_distance; + } + } + } + else if (strcmp(pNext->name, "blank") == 0) { + if (index_plot == -1) { + index_plot = index_parking; + min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + } + else { + float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); + if (temp_min_parking_distance < min_parking_distance) { + index_plot = index_parking; + min_parking_distance = temp_min_parking_distance; + } + } + } + } + } + + if (index_plot >= 0) { + g_temp_parking_space_check_table[j][index_plot] = 1; + pNext->zone_violation_idx[j] = 1; + } + } + } + } + } + } + } + + if (strlen(viewChannelData[tracking_channel_idx].red_light_zone) >= 1 && strcmp(viewChannelData[tracking_channel_idx].red_light_zone, "NULL") != 0) { + if (j == atoi(viewChannelData[tracking_channel_idx].red_light_zone)) { + continue; + } + } + + b_ZoneExist = 0; + //zone_polygon bclientݼgJ]wɮɤwର 889*500 + + for (int k = 0; k < 6; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].Points[k].x > 0 || viewDetectionZone[tracking_channel_idx][j].Points[k].y > 0) + b_ZoneExist = 1; + + zone_polygon[k].x = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + zone_polygon[k].y = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + + //temp_zone_polygon[k].x = zone_polygon[k].x; + //temp_zone_polygon[k].y = zone_polygon[k].y; + } + + if (!b_ZoneExist || j == viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1) + continue; + + if (g_IsRadarDevice != 1) // 2022-10-20 Ken + { + if (strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0) { + if ((((pNext->width * pNext->height) / ((float)fInSourceOri_w * (float)fInSourceOri_h)) > ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_max_proportion_in_zone) / 100.0)) || + (((pNext->width * pNext->height) / ((float)fInSourceOri_w *(float)fInSourceOri_h)) < ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_min_proportion_in_zone) / 100.0)) + ) { + continue; + } + } + } + + int check_if_go_straight_existing = 0; + int check_if_speed_existing = 0; + float ratio_area_zone_polygon = 0.0; + int index_of_trigger_event_to_checked = -1; + unsigned int trigger_event_type = 0; +#ifdef GY_OS_AMBA + //int check_if_forget_to_give_way = -1; +#endif + for (int m = 0; m < MAX_TRIGGER_EVENT; m++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { + trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); + + if ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) { + check_if_go_straight_existing = 1; + } + else { + if (!(IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE)) { + ratio_area_zone_polygon = polygon_area(zone_polygon, 6) / (float)(CANVAS_WIDTH * CANVAS_HEIGHT); + + + if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { +#ifdef GY_OS_AMBA + //check_if_forget_to_give_way = 1; +#endif + } + else if (trigger_event_type == TRIGGER_SPEED_HIGH || + trigger_event_type == TRIGGER_SPEED_LOW) { + check_if_speed_existing = 1; + } + } + else if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { + if (trigger_event_type == TRIGGER_SPEED_HIGH || + trigger_event_type == TRIGGER_SPEED_LOW) { + check_if_speed_existing = 1; + } + } + + } + + index_of_trigger_event_to_checked = m; + break; + } + } + + if (g_IsPTZDevice == 0 && trigger_event_type == 0) + continue; + + if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1 && strncmp(viewDetectionZone[tracking_channel_idx][j].enable_speed, "No", strlen("No")) == 0) { + continue; + } + +#if 0 + if (AI_fps >= 1 && bHttpServerThreadStart) + { + + int iIsDoDestoryDetected = 0; + for (int m = 0; m < MAX_TRIGGER_EVENT; m++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); + + if ((trigger_event_type == TRIGGER_MISSING_UNATTENDED) || + (trigger_event_type == TRIGGER_TAMPERING)) //TRIGGER_ALL_OBJECTS + { + iIsDoDestoryDetected = 1; + } + } + } + + ///bo, _hLtrigger]|vT + //iIsDoDestoryDetected: P_O_}ү}a(bPTZW, ubPRESETI~ϥΦ\) + //if (iIsDoDestoryDetected == 0) + //{ + //O_]wZoneToPreset, : ѦPreset, S: ݹw]I, NmҥiIJo. + //int iZoneMapPresetIdx = 0; + //iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + + // if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 0 + //&& IsTracking() != 1 + // ) + // continue; + //} + //else if (iIsDoDestoryDetected == 1) + //{ + // if (IsPTZinPreset() == 0) + // { + // continue; + // } + //} + } +#endif + //Check zone_to_preset and is_ptz_device + + int iIfDoZone = 1; +#ifdef GY_OS_AMBA +#if 0 + { + int iZoneMapPresetIdx = 0; + int iIsSetZoneToPreset = 0; + + if (g_IsPTZDevice == 1 && check_if_forget_to_give_way != 1) + { + if (!(IsPTZinAutoTracking() == 0 && IsPTZinAutoPan() == 1)) { + + if (viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset) != 0) + { + iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + if (iZoneMapPresetIdx != 0) + { + iIsSetZoneToPreset = 1; + } + else + { + iIsSetZoneToPreset = 0; + } + } + else + { + iIsSetZoneToPreset = 0; + } + + //if (IsPTZinAutoTracking() == 1) + //{ + if (iIsSetZoneToPreset == 1) + { + //iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + iZoneMapPresetIdx = IsPTZinPreset(); //1. jwzone link preset, unbpresetIW|ilܧP_ + if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 0) + { + iIfDoZone = 0; + } + } + + //} + } + } //IsPTZ() == 1 + } +#endif +#endif + + + + int do_event_trigger = 1; +#ifdef GY_OS_AMBA +#if 0 + { + int iZoneMapPresetIdx = 0; + int iIsSetZoneToPreset = 0; + + if (g_IsPTZDevice == 1 && check_if_forget_to_give_way != 1) + { + if (IsPTZinAutoTracking() == 0 && IsPTZinAutoPan() == 0) { + do_event_trigger = 0; + + if (viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset) != 0) + { + iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + if (iZoneMapPresetIdx != 0) + { + iIsSetZoneToPreset = 1; + } + else + { + iIsSetZoneToPreset = 0; + } + } + else + { + iIsSetZoneToPreset = 0; + } + + //if (IsPTZinAutoTracking() == 1) + //{ + if (iIsSetZoneToPreset == 1) + { + iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 1) + { + do_event_trigger = 1; + } + } + + if (strcmp(ObjectName, "tampering") == 0) { + do_event_trigger = 1; + } + } + else if (IsPTZinAutoTracking() == 1 && IsPTZinAutoPan() == 1) + { + do_event_trigger = 0; + + if (viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset) != 0) + { + iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + if (iZoneMapPresetIdx != 0) + { + iIsSetZoneToPreset = 1; + } + else + { + iIsSetZoneToPreset = 0; + } + } + else + { + iIsSetZoneToPreset = 0; + } + + if (iIsSetZoneToPreset == 1) + { + iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); + if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 1) + { + do_event_trigger = 1; + } + } + } + //} + } //IsPTZ() == 1 + } +#endif +#endif + //int poly_num = sizeof(zone_polygon) / sizeof(zone_polygon[0]); + + if (iIfDoZone == 1 || g_check_if_set_no_preset_no_autopan == 1) + { + //printf("\n------------ratio_area_zone_polygon:%f\n", ratio_area_zone_polygon); + Record_Point_Touch_and_IsInsideZone(pNext, tracking_channel_idx, tracking_obj_idx, det_count_idx, zone_polygon, side_number, j, fInSourceOri_w, fInSourceOri_h); + } +#ifdef GY_OS_AMBA +#if 0 + if (g_IsPTZDevice == 1) + { + if (IsPTZinAutoTracking() == 1) + { + continue; + } + + } +#endif +#endif + if (g_check_if_metadata_stop_happened[j] == 1) { + continue; + } + + //printf("\n------------get_g_check_if_current_light_is_red:%d\n", get_g_check_if_current_light_is_red()); + + if(do_event_trigger == 1 || g_check_if_set_no_preset_no_autopan == 1){ + if (det_count_idx > 0 && index_of_trigger_event_to_checked >= 0) + { + //printf("\n---BBB------pNext->engine_type:%d\n", pNext->engine_type); + //printf("\n---BBB------pNext->obj_type:%d\n", pNext->obj_type); + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); + //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); + + if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0) { + + //printf("\n-----------------B2\n"); + + int current_count_touch = 0; + int last_count_touch = 0; + float threshold_for_count_touch = 0.77; + int threshold_for_last_count_touch = 55; + int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 + + if (ratio_area_zone_polygon >= 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 560 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 480 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 420 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 360 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 300 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 260 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 220 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 190 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 170 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 150 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { + threshold_for_count_touch = 0.73; + threshold_for_last_count_touch = 105 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { + threshold_for_count_touch = 0.74; + threshold_for_last_count_touch = 85 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { + threshold_for_count_touch = 0.76; + threshold_for_last_count_touch = 65 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { + threshold_for_count_touch = 0.77; + threshold_for_last_count_touch = 55 / threahold_div; + } + else { + threshold_for_count_touch = 0.78; + threshold_for_last_count_touch = 45 / threahold_div; + } + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; + last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; + } + //printf("\n------------current_count_touch:%d\n", current_count_touch); + //printf("\n------------last_count_touch:%d\n", last_count_touch); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { + if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { + + //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + if(strcmp(pNext->name,"person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) + { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + #if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p==q | p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + #endif + } + + { + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + + } + } + } + + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + + if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { + if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || + (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { + + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + printf("\n[p=q error]------------------\n"); + printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, + viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, + viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, + viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, + viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + else { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + /*if (strcmp(pNext->name, "person") == 0) { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + else*/ { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } +#endif + /* + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + //printf("\n------------YYYYYYYYYYYYYYYYY\n"); + for (int kl = 0; kl < g_max_sensor_size; kl++) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + } + } + }*/ + } + } + //printf("\n-------------------[doIntersect]: end\n"); + //printf("\nFEATURE_HUM_DET---4\n"); + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + /* + else if (trigger_event_type == TRIGGER_TURN_LEFT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_WRONG_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); + */ + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + + } + } + + } + //|y~ApGID諸 + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) + continue; + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + } + } + } + else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { + //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); + //Ĥ@izone ɶ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; + + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { + //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + //} + //else { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //} + + viewDetectionZone[0][j].det_time = pNext->det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + //printf("\n----------------A:2\n"); + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + int nNeedTrigger = 0; + + if (trigger_event_type == TRIGGER_SPEED_HIGH) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_SPEED_LOW) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + } + else { + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { + //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + //} + //else { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //} + viewDetectionZone[0][j].det_time = pNext->det_time; + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + int nNeedTrigger = 0; + //printf("\n-----------In_zone\n"); + if (trigger_event_type == TRIGGER_ALLOW_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_BLOCK_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GUEST_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ALL_OBJECTS) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + } + } + else { + + //TRIGGER_SPEED_HIGHMTRIGGER_SPEED_LOW᭱C + + if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) + { + #if 1 + { + if (trigger_event_type == TRIGGER_TAMPERING) { + if (strcmp(ObjectName, "tampering") == 0) + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; + //pNext->detection_zone_idx = j; + pNext->trigger_idx[j] = index_of_trigger_event_to_checked; + pNext->zone_violation_idx[j] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } + } + + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 1) { + //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); + //Ĥ@izone ɶ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { + //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + //} + //else { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //} + viewDetectionZone[0][j].det_time = pNext->det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + //printf("\n----------------A:2\n"); + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + + { + //TRIGGER_MISSING_OBJECT_DETECTION + float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; + if (check_if_existing_in_metaout(ObjectName, j)) + { + int check_obj_tracking_id_in_zone = 0; + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id) { + check_obj_tracking_id_in_zone = 1; + break; + } + } + +#if 1 + if (check_obj_tracking_id_in_zone == 0) { + for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { + if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0 || + (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time) > dwell_time_missing_object_detection) + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; + break; + } + if (index_obj_tracking_id_in_zone == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { + for (int index_obj_tracking_id_in_zone_temp = MAX_OBJ_TRACKING_ID_IN_ZONE - 1; index_obj_tracking_id_in_zone_temp >= 1; index_obj_tracking_id_in_zone_temp--) { + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp - 1]; + } + viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[0] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; + } + } + } +#endif + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = pNext->obj_dwell_time; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; + + pNext->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; + pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; + } + else { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = pNext->obj_dwell_time; + pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; + } + } + } + + + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_DISTANCE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_DISTANCE_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_HIGH_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_HIGH_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_MISSING_UNATTENDED) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_MISSING_UNATTENDED, total_element_size, PosInfo, result_idx); + //else if (trigger_event_type == TRIGGER_BG_LEARNING) + //nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BG_LEARNING, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ALL_OBJECTS) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_LACK_OF_ANY_OBJECT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_FORGET_TO_GIVE_WAY, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + g_IsCustomWeight == 1) + { + { + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_QUEUING_VIOLATION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) + viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = index_of_trigger_event_to_checked; + } + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 0) { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + + { + //CPoint zone_polygon_temp[MAX_DETECTION_ZONE][6]; + //for (int m = 0; m < viewChannelData[tracking_channel_idx].count_zone; m++) { + + /* + for (int k = 0; k < 6; k++) + { + zone_polygon_temp[j][k].x = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + zone_polygon_temp[j][k].y = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + } + */ + //if (polygon_area(zone_polygon_temp[j], 6) <= (float)(CANVAS_WIDTH * CANVAS_HEIGHT * THRESHOLD_POLYGON_AREA)) + { + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + //} + + + } + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + + /* + else { + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time >= 1.0) + { + int nNeedTrigger = 0; + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, k, tracking_obj_idx, TRIGGER_MISSING_OBJECT_DETECTION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + } + } + } + }*/ + #endif + } + else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1){ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { + //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); + //Ĥ@izone ɶ + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; + //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { + //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; + //} + //else { + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; + //} + viewDetectionZone[0][j].det_time = pNext->det_time; + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); + } + + //printf("\n----------------A:2\n"); + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + int nNeedTrigger = 0; + + if (trigger_event_type == TRIGGER_SPEED_HIGH) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_SPEED_LOW) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { + + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + else { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; + } + } + else if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0){ + + //printf("\n-----------------B2\n"); + + int current_count_touch = 0; + int last_count_touch = 0; + float threshold_for_count_touch = 0.77; + int threshold_for_last_count_touch = 55; + int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 + + if (ratio_area_zone_polygon >= 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 560 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { + threshold_for_count_touch = 0.67; + threshold_for_last_count_touch = 480 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 420 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { + threshold_for_count_touch = 0.68; + threshold_for_last_count_touch = 360 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 300 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { + threshold_for_count_touch = 0.69; + threshold_for_last_count_touch = 260 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 220 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { + threshold_for_count_touch = 0.7; + threshold_for_last_count_touch = 190 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 170 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { + threshold_for_count_touch = 0.71; + threshold_for_last_count_touch = 150 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { + threshold_for_count_touch = 0.73; + threshold_for_last_count_touch = 105 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { + threshold_for_count_touch = 0.74; + threshold_for_last_count_touch = 85 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { + threshold_for_count_touch = 0.76; + threshold_for_last_count_touch = 65 / threahold_div; + } + else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { + threshold_for_count_touch = 0.77; + threshold_for_last_count_touch = 55 / threahold_div; + } + else{ + threshold_for_count_touch = 0.78; + threshold_for_last_count_touch = 45 / threahold_div; + } + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; + last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; + } + //printf("\n------------current_count_touch:%d\n", current_count_touch); + //printf("\n------------last_count_touch:%d\n", last_count_touch); + + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { + if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { + + //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); + + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx-1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) + { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx-1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + #if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p==q | p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + #endif + } + + { + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + + } + } + } + + } + } + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); + memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; + + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + if (g_sensors_type == 0) { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); + } + else { + p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + + q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); + q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); + } + } + + if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { + if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || + (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { + + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + printf("\n[p=q error]------------------\n"); + printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, + viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, + viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, + viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, + viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } + else { + int m = 0; + int array_zone_count[4] = { 0 }; + for (int k = 0; k < 4; k++) { + array_zone_count[k] = 0; + } + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + /*if (strcmp(pNext->name, "person") == 0) { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + else*/ { + for (int kl = 0; kl < g_max_sensor_size; kl++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (doIntersect(p1[kl], q1[kl], p2, q2)) + { + array_zone_count[k]++; + } + } + } + } + } + + for (int k = g_max_sensor_size; k >= 1; k--) { //zone Ӽ * doIntersect + for (int kl = 0; kl < 4; kl++) { //zoneӼ + if (array_zone_count[kl] >= k) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; + break; + } + } + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { + break; + } + } + + +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + int m = 0; + + float object_mean_x = 0.0; + float object_mean_y = 0.0; + float object_count = 0.0; + + for (int k = 0; k < g_max_sensor_size; k++) { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { + object_count++; + object_mean_x += (float)q1[k].x; + object_mean_y += (float)q1[k].y; + } + } + + if (object_count >= 1.0) { + object_mean_x /= object_count; + object_mean_y /= object_count; + + float min_distance = 0; + float min_zone_line = 0; + for (int k = 0; k < 4; k++) + { + if (k == 4 - 1) + m = 0; + else + m = k + 1; + CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; + + printf("\n[p!=q error]------------------\n"); + printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); + + float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; + float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; + float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; + float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; + float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; + float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; + float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + + float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; + float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; + + if (min_zone_line == 0) { + min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + min_zone_line = k + 1; + } + else { + float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); + if (distance_temp < min_distance) { + min_zone_line = k + 1; + } + } + } + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; + } + } +#endif + /* + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { + //printf("\n------------YYYYYYYYYYYYYYYYY\n"); + for (int kl = 0; kl < g_max_sensor_size; kl++) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { + //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); + } + } + }*/ + } + } + //printf("\n-------------------[doIntersect]: end\n"); + //printf("\nFEATURE_HUM_DET---4\n"); + { + //printf("\n-------------GO STRAIGHT: start------------\n"); + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + /* + else if (trigger_event_type == TRIGGER_TURN_LEFT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_WRONG_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); + */ + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + + } + } + + } + //|y~ApGID諸 + else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) + { + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) + continue; + + //printf("\nFEATURE_HUM_DET---5\n"); + { + #if 0 + { + int nNeedTrigger = 0; + if (trigger_event_type == TRIGGER_GO_STRAIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); + /* + else if (trigger_event_type == TRIGGER_TURN_LEFT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_WRONG_WAY) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); + */ + + if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + + } + } + #endif + } + + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); + memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; + + } + } + } + } + } + else if(det_count_idx == 0 && index_of_trigger_event_to_checked >= 0) + { + if (IsANPRCategory_L_Plate(pNext->name)==1 && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext->properties.plate); + pNext->linked_plate_length = pNext->properties.plate_length; + } + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; + } + + if (viewChannelData[0].enable_traffic) { + for (int m = 0; m < total_element_size; m++) + { + pNext2 = PosInfo + m; + if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { + if (detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && + (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) + ) + { + strcpy(pNext->car_type_name, pNext2->name); + strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); + + break; + } + } + } + } + + //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); + //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { + int nNeedTrigger = 0; + //printf("\n-----------In_zone\n"); + if (trigger_event_type == TRIGGER_ALLOW_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_BLOCK_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_GUEST_LIST) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); + else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); + + if (nNeedTrigger) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + } + + } + } + else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) { +#ifdef GY_OS_AMBA + if (trigger_event_type == TRIGGER_TAMPERING) { + if (strcmp(ObjectName, "tampering") == 0) + { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; + //pNext->detection_zone_idx = j; + pNext->trigger_idx[j] = index_of_trigger_event_to_checked; + pNext->zone_violation_idx[j] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + } + } +#endif +#if 1 + if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { + //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j]) % MAX_OBJ_DWELL_TIME; + //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0 || strcmp("person", pNext->name) == 0 || + //(diff_secs_in_zone >= 1 && diff_secs_in_zone > 0 && (int)(pNext->center_stability) != DIRECTION_DEFAULT)) + { + if (trigger_event_type == TRIGGER_ZONE_VIOLATION) + { + //for (int k = 0; k < metadata1_num; k++) + { + if (check_if_existing_in_metaout(ObjectName, j)) { + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + pNext->trigger_type = TRIGGER_ZONE_VIOLATION | pNext->trigger_type; + //pNext->detection_zone_idx = j; + pNext->trigger_idx[j] = index_of_trigger_event_to_checked; + pNext->zone_violation_idx[j] = 1; + g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; + //break; + } + } + } + } + } +#endif + } + } + } + } + +} + + +void ApplyTrackingTableAndPrevDetection(detection_pos* PosInfo, int total_element_size,int tracking_channel_idx,int id_idx,int obj_idx) { + + //printf("\n--------%d,%d\n", (int)(PosInfo + obj_idx)->width, (int)(PosInfo + obj_idx)->height); + + if ((PosInfo + obj_idx)->width > 0 && (PosInfo + obj_idx)->height > 0) { + int det_count = 0; + int plate_len = 0, old_plate_len = 0; + det_count = g_TrackingRecords[tracking_channel_idx][id_idx].detection_count; + det_count++; + if (det_count > TRACKING_BUFFER_SIZE) + { + det_count = TRACKING_BUFFER_SIZE; + } + + if (det_count >= 2) {//ĤGframeHW + + if (IsANPRCategory((PosInfo + obj_idx)->engine_type) && strlen((PosInfo + obj_idx)->properties.plate) >= 1) { + + for (int j = 0; j < MAX_PLATE_RECORDER; j++) + { + if (g_PlateRecorderList[j].iIfUse == 1) + { + if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 + //&& strcmp((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) + && LevenshteinDistance((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + float ratio_y = ((PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y) / (float)get_g_ori_yuv_height(); + float ratio_x = ((PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x) / (float)get_g_ori_yuv_width(); + float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); + + + + if (fabs(ratio_x_y) <= g_thres_bbox_stability_plate) + { + (PosInfo + obj_idx)->top_y = g_PlateRecorderList[j].last_box_y; + (PosInfo + obj_idx)->height = g_PlateRecorderList[j].last_box_h; + (PosInfo + obj_idx)->left_x = g_PlateRecorderList[j].last_box_x; + (PosInfo + obj_idx)->width = g_PlateRecorderList[j].last_box_w; + (PosInfo + obj_idx)->center_y = g_PlateRecorderList[j].last_box_center_y; + (PosInfo + obj_idx)->center_x = g_PlateRecorderList[j].last_box_center_x; + (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; + (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; + } + else + { + float delta_y = (PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y; + float delta_x = (PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x;; + (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; + (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); + } + + break; + } + } + } + + } + else { + + float ratio_y = ((PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y) / (float)get_g_ori_yuv_height(); + float ratio_x = ((PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x) / (float)get_g_ori_yuv_width(); + float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); + + if (fabs(ratio_x_y) <= g_thres_bbox_stability) + { + (PosInfo + obj_idx)->top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y; + (PosInfo + obj_idx)->height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height; + (PosInfo + obj_idx)->left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x; + (PosInfo + obj_idx)->width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width; + (PosInfo + obj_idx)->center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; + (PosInfo + obj_idx)->center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; + (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; + (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; + } + else + { + float delta_y = (PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; + float delta_x = (PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; + (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; + (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); + } + } + + (PosInfo + obj_idx)->check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter; + + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + + (PosInfo + obj_idx)->num_bring_with_object[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone]; + for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { + strcpy((PosInfo + obj_idx)->bring_with_object[index_zone][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[index_zone][index_bring]); + } + + (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone]; + //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone]; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; + + (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; + (PosInfo + obj_idx)->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; + + (PosInfo + obj_idx)->obj_dwell_time = (int)difftime((PosInfo + obj_idx)->det_time, g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time) % MAX_OBJ_DWELL_TIME; + (PosInfo + obj_idx)->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_first_dwell_time; + (PosInfo + obj_idx)->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_last_dwell_time; + + //strcpy((PosInfo + obj_idx)->replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name); + } + else if (det_count == 1) {//Ĥ@framel + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = g_initial_background_learning_rate_x; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = g_initial_background_learning_rate_y; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_initial_background_learning_rate_error_x; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_initial_background_learning_rate_error_y; + + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = g_initial_background_mean_diff_x; + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = g_initial_background_mean_diff_y; + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = g_initial_background_error_diff_x; + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = g_initial_background_error_diff_y; + + (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; + (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; + + (PosInfo + obj_idx)->check_person_inter = 0; + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + (PosInfo + obj_idx)->num_bring_with_object[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] = 0; + (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = 0; + //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone] = 0; + //g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone] = 0; + } + + if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count != 0) + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = 0; + if (g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count != 0) + g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; + + + g_TrackingIDAndChannel[tracking_channel_idx]++; + if (td_weight_num >= 1 && check_if_correct_mail == 1) + { + if (g_TrackingIDAndChannel[tracking_channel_idx] > 19999 || g_TrackingIDAndChannel[tracking_channel_idx] < 10001) + g_TrackingIDAndChannel[tracking_channel_idx] = 10001; + } + else + { + if (g_TrackingIDAndChannel[tracking_channel_idx] > 9999) + g_TrackingIDAndChannel[tracking_channel_idx] = 1; + } + + (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; + (PosInfo + obj_idx)->obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; + g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; + + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = (PosInfo + obj_idx)->det_time; + + //g_TrackingRecords[tracking_channel_idx][id_idx].frame_count = 0; + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].name, (PosInfo + obj_idx)->name); + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name, (PosInfo + obj_idx)->replaced_name); + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time_to_enter_zone[index_zone] = -1; + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[index_zone] = -1; + (PosInfo + obj_idx)->obj_speed[index_zone] = -1; + + g_TrackingRecords[tracking_channel_idx][id_idx].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; + if ((PosInfo + obj_idx)->check_if_within_zone[index_zone] == 1 && index_zone < viewChannelData[tracking_channel_idx].count_zone && + viewDetectionZone[0][index_zone].det_time > 0 && + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time > viewDetectionZone[0][index_zone].det_time) { + + int diff_secs_in_zone = (int)difftime(g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time, viewDetectionZone[0][index_zone].det_time) % MAX_OBJ_DWELL_TIME; + if (diff_secs_in_zone < 60 && diff_secs_in_zone >= 2){ + if (diff_secs_in_zone >= 2) { + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = viewDetectionZone[0][index_zone].det_time - diff_secs_in_zone; + (PosInfo + obj_idx)->det_time = viewDetectionZone[0][index_zone].det_time - diff_secs_in_zone; + } + else { + g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = viewDetectionZone[0][index_zone].det_time - 30; + (PosInfo + obj_idx)->det_time = viewDetectionZone[0][index_zone].det_time - 30; + } + } + } + } + //g_TrackingRecords[tracking_channel_idx][id_idx].avg_det_interval = 1.1; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].bAssign_flag = 1; + g_TrackingRecords[tracking_channel_idx][id_idx].Assign_obj_idx = obj_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].detection_count = det_count; + //g_TrackingRecords[tracking_channel_idx][id_idx].fake_detection_count = 0; + + if (det_count >= 1) { + if ((PosInfo + obj_idx)->obj_type == _PLATE && strlen((PosInfo + obj_idx)->properties.plate) >= 1) + { + plate_len = strlen((PosInfo + obj_idx)->properties.plate); + old_plate_len = strlen(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); + + //printf("[%d] plate1 = %s, %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate); + if (plate_len >= old_plate_len) + { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); + } + else if (plate_len < old_plate_len) + { + //strcpy((PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); + strcpy((PosInfo + obj_idx)->car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name); + } + + //printf("[%d] plate2 = %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate); + } + } +#if 1 + for (int n = 0; n < det_count - 1; n++) + { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].name); + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].replaced_name); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].progress_bar = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].progress_bar; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_direction = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_direction; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_stability = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_stability; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].width; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].height; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].plate_char_top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].plate_char_top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].parent_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].parent_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_logo_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_logo_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].number_row = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].number_row; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].visual_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].visual_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].class_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].class_id; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sec_color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sec_color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_type; +#ifdef GY_OS_AMBA + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_height; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_height; +#endif + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_violation_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_violation_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_check_giveway[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_check_giveway[index_zone]; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].near_iou_count[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].near_iou_count[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone_four_points[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone_four_points[index_zone]; + + if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id == g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id) { + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_having_been_counted[index_zone]; + } + else { + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = 0; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_speed[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_speed[index_zone]; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].s_last_t_Counter[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_within_zone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_within_zone[index_zone]; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_w = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_w; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_h = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_h; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].dash_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].dash_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_milli_sec = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_milli_sec; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_first_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_last_dwell_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate_length; + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_type_name); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].logo); + + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.country, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.pose, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area_id; + //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.counter_count[index_counter] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.counter_count[index_counter]; + //} + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_list, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_length; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id_idx; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].vote_value = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].vote_value; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].disappear_count = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].disappear_count; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].iou_prev_self = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].iou_prev_self; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].test_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].test_id; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].image_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].image_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].adjust_obj_speed; + + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sPlateDirection, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sPlateDirection); + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_person_inter; + + for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].num_bring_with_object[k]; + for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].bring_with_object[k][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].bring_with_object[k][index_bring]); + } + + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n + 1]; + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n + 1]; + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n + 1][index_p]; + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n + 1][index_p]; + } + } + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n + 1]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n + 1]; + } + + if (det_count >= 1) { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].name, (PosInfo + obj_idx)->name); + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].replaced_name, (PosInfo + obj_idx)->replaced_name); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence = (PosInfo + obj_idx)->confidence; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence2 = (PosInfo + obj_idx)->confidence2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].progress_bar = (PosInfo + obj_idx)->progress_bar; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type = (PosInfo + obj_idx)->engine_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type2 = (PosInfo + obj_idx)->engine_type2; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x = (PosInfo + obj_idx)->left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y = (PosInfo + obj_idx)->top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x = (PosInfo + obj_idx)->center_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y = (PosInfo + obj_idx)->center_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_direction = (PosInfo + obj_idx)->center_direction; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_stability = (PosInfo + obj_idx)->center_stability; + //printf("\n-------prev #2:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width = (PosInfo + obj_idx)->width; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height = (PosInfo + obj_idx)->height; + //printf("\n-------prev #3:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].plate_char_top_y = (PosInfo + obj_idx)->plate_char_top_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].parent_idx = (PosInfo + obj_idx)->parent_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_logo_idx = (PosInfo + obj_idx)->car_logo_idx; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].number_row = (PosInfo + obj_idx)->number_row; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_type = (PosInfo + obj_idx)->obj_type; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].visual_left_x = (PosInfo + obj_idx)->visual_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].class_id = (PosInfo + obj_idx)->class_id; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color, (PosInfo + obj_idx)->color); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color_id = (PosInfo + obj_idx)->color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sec_color_id = (PosInfo + obj_idx)->sec_color_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_type = (PosInfo + obj_idx)->trigger_type; +#ifdef GY_OS_AMBA + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_distance = (PosInfo + obj_idx)->min_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_distance = (PosInfo + obj_idx)->max_distance; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_height = (PosInfo + obj_idx)->min_height; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_height = (PosInfo + obj_idx)->max_height; +#endif + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_idx[index_zone] = (PosInfo + obj_idx)->trigger_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_violation_idx[index_zone] = (PosInfo + obj_idx)->zone_violation_idx[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_check_giveway[index_zone] = (PosInfo + obj_idx)->zone_check_giveway[index_zone]; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].near_iou_count[index_zone] = (PosInfo + obj_idx)->near_iou_count[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone[index_zone] = (PosInfo + obj_idx)->IsInsideZone[index_zone]; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone_four_points[index_zone] = (PosInfo + obj_idx)->IsInsideZone_four_points[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_having_been_counted[index_zone] = (PosInfo + obj_idx)->check_if_having_been_counted[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_speed[index_zone] = (PosInfo + obj_idx)->obj_speed[index_zone]; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].s_last_t_Counter[index_zone] = (PosInfo + obj_idx)->s_last_t_Counter[index_zone]; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id = (PosInfo + obj_idx)->obj_tracking_id; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_x = (PosInfo + obj_idx)->box_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_y = (PosInfo + obj_idx)->box_y; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_w = (PosInfo + obj_idx)->box_w; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_h = (PosInfo + obj_idx)->box_h; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].dash_left_x = (PosInfo + obj_idx)->dash_left_x; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time = (PosInfo + obj_idx)->det_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_milli_sec = (PosInfo + obj_idx)->det_milli_sec; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_dwell_time = (PosInfo + obj_idx)->obj_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_first_dwell_time = (PosInfo + obj_idx)->obj_first_dwell_time; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_last_dwell_time = (PosInfo + obj_idx)->obj_last_dwell_time; + + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate, (PosInfo + obj_idx)->linked_plate); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate_length = (PosInfo + obj_idx)->linked_plate_length; + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].logo, (PosInfo + obj_idx)->logo); + + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate, sizeof((PosInfo + obj_idx)->properties.plate)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.country, (PosInfo + obj_idx)->properties.country, sizeof((PosInfo + obj_idx)->properties.country)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area, (PosInfo + obj_idx)->properties.area, sizeof((PosInfo + obj_idx)->properties.area)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.logo, (PosInfo + obj_idx)->properties.logo, sizeof((PosInfo + obj_idx)->properties.logo)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.color, (PosInfo + obj_idx)->properties.color, sizeof((PosInfo + obj_idx)->properties.color)); + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.pose, (PosInfo + obj_idx)->properties.pose, sizeof((PosInfo + obj_idx)->properties.pose)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area_id = (PosInfo + obj_idx)->properties.area_id; + //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.counter_count[index_counter] = (PosInfo + obj_idx)->properties.counter_count[index_counter]; + //} + memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_list, (PosInfo + obj_idx)->properties.plate_list, sizeof((PosInfo + obj_idx)->properties.plate_list)); + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_length = (PosInfo + obj_idx)->properties.plate_length; + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id_idx = (PosInfo + obj_idx)->obj_tracking_id_idx; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].vote_value = (PosInfo + obj_idx)->vote_value; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = (PosInfo + obj_idx)->disappear_count; + + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].iou_prev_self = (PosInfo + obj_idx)->iou_prev_self; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].test_id = (PosInfo + obj_idx)->test_id; + //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].image_id = (PosInfo + obj_idx)->image_id; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].adjust_obj_speed = (PosInfo + obj_idx)->adjust_obj_speed; + + //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sPlateDirection, (PosInfo + obj_idx)->sPlateDirection); + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter = (PosInfo + obj_idx)->check_person_inter; + + + + for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { + + g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] = (PosInfo + obj_idx)->num_bring_with_object[k]; + for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { + strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[k][index_bring], (PosInfo + obj_idx)->bring_with_object[k][index_bring]); + } + + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][det_count - 1] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][det_count - 1] = 0; + for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][det_count - 1][index_p] = 0; + g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][det_count - 1][index_p] = 0; + } + } + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[det_count - 1] = (PosInfo + obj_idx)->center_direction; + g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[det_count - 1] = (PosInfo + obj_idx)->center_stability; + } +#endif + + if (det_count >= 1) { + //printf("\n-----www----%f,%f\n", g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y); + if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width > 0.0 && g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height > 0.0) { + + float diff_x = 0; + float diff_y = 0; + //float diff_time = 0; + if (det_count >= 2) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_x; + diff_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_y; + + if (strcmp((PosInfo + obj_idx)->name, "person")==0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; + } + + //diff_time = difftime(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].det_time); +#ifdef GY_OS_AMBA + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (((int)(PosInfo + obj_idx)->center_direction) != DIRECTION_DEFAULT && det_count >= 3) { + float obj_speed; + float obj_speed_old; + float obj_speed_very_old; + detection_pos *PosInfo_very_old, *PosInfo_old, *PosInfo_new; + + PosInfo_new = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1]; + PosInfo_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2]; + PosInfo_very_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 3]; + + float fIou_union_1 = detection_overlap_ratio_union(PosInfo_new, PosInfo_old); + float fIou_union_2 = detection_overlap_ratio_union(PosInfo_new, PosInfo_very_old); + if (fIou_union_1 < 0.85 && fIou_union_2 < 0.85) { + + pthread_mutex_lock(&mutex_perspective_transform); + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = -1; + int count_speed_zone = 0; + + for (int social_zone_idx = 0; social_zone_idx < viewChannelData[tracking_channel_idx].count_zone; social_zone_idx++) { + if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 /*&& + strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "No", strlen("No")) == 0*/) { + if (viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray != NULL) { + obj_speed = SetPerspectiveTransform_GetObjSpeed(PosInfo_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); + obj_speed_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); + obj_speed_very_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_old, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); + + float temp_obj_speed = pow(obj_speed * obj_speed_old * obj_speed_very_old, 1.0 / 3.0); + if (temp_obj_speed < 0.1) + temp_obj_speed = 0.1; + + if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] == -1) + { + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = temp_obj_speed; + } + else if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] >= 0) + { + //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) + //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) + + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = sqrt(g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * temp_obj_speed); + } + + (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + + if (g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg == -1) { + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + } + else { + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg += g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + } + count_speed_zone++; + } + }/* + else if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 && + strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "Yes", strlen("Yes")) == 0) { + + for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { + if (SpeedData[i].flag_protected == 1) { // get_g_ori_yuv_height() get_g_ori_yuv_width(); + + float point_x = SpeedData[i].x * get_g_ori_yuv_width() / SpeedData[i].res_width; + float point_y = SpeedData[i].y * get_g_ori_yuv_height() / SpeedData[i].res_height; + + float bbox_min_x = (PosInfo + obj_idx)->left_x; + float bbox_min_y = (PosInfo + obj_idx)->top_y; + float bbox_max_x = (PosInfo + obj_idx)->left_x + (PosInfo + obj_idx)->width; + float bbox_max_y = (PosInfo + obj_idx)->top_y + (PosInfo + obj_idx)->height; + + if (point_x > bbox_min_x && point_x < bbox_max_x && + point_y > bbox_min_y && point_y < bbox_max_y) { + + g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = SpeedData[i].speed; + (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; + count_speed_zone++; + + SpeedData[i].flag_protected = 0; + break; + } + } + } + } + */ + } + + if (count_speed_zone >= 1) { + g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg /= count_speed_zone; + (PosInfo + obj_idx)->adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg; + } + + pthread_mutex_unlock(&mutex_perspective_transform); + } + } + } +#endif + } + + float temp_diff_x = diff_x; + float temp_diff_y = diff_y; + + diff_x = diff_x + diff_x * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x; + diff_y = diff_y + diff_y * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y; + + if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = 0; + } + + if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { + diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = 0; + } + + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_x = (PosInfo + obj_idx)->center_x + diff_x; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_y = (PosInfo + obj_idx)->center_y + diff_y; + //g_TrackingRecords[tracking_channel_idx][id_idx].det_interval = diff_time; + + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.left_x = (PosInfo + obj_idx)->left_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.top_y = (PosInfo + obj_idx)->top_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.width = (PosInfo + obj_idx)->width + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2;//* (ratio_w) + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.height = (PosInfo + obj_idx)->height + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2;//* (ratio_h) + + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_x = (PosInfo + obj_idx)->box_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_y = (PosInfo + obj_idx)->box_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_w = (PosInfo + obj_idx)->box_w + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2; + g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_h = (PosInfo + obj_idx)->box_h + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2; + + float sum_diff_x = 0; + float sum_diff_y = 0; + for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { + sum_diff_x += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x); + sum_diff_y += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y); + } + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = sum_diff_x / (float)det_count; + g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = sum_diff_y / (float)det_count; + float sum_2_diff_x = 0; + float sum_2_diff_y = 0; + for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { + sum_2_diff_x += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x, 2.0); + sum_2_diff_y += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y, 2.0); + } + + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = sqrt(sum_2_diff_x); + g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = sqrt(sum_2_diff_y); + + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = (temp_diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x + 1.0); + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = (temp_diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y + 1.0); + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x * 1.0; + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y * 1.0; + + g_initial_background_learning_rate_x = g_initial_background_learning_rate_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x * 0.01; + g_initial_background_learning_rate_y = g_initial_background_learning_rate_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y * 0.01; + g_initial_background_learning_rate_error_x = g_initial_background_learning_rate_error_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 0.01; + g_initial_background_learning_rate_error_y = g_initial_background_learning_rate_error_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 0.01; + } + } + + } +} + +//#ifdef GY_OS_WIN +//#define CHAO_METH +#define METH_1 + +#define IOU_HISTORY_FRAMES 3 + +//VOTE number +#define VOTE_NAME 20 +#define VOTE_PERSON 25 + +#define VOTE_WITHIN_ZONE 70 + +#define VOTE_MAX_UNION_PREDICT_IOU 100 +#define VOTE_MAX_PREDICT_IOU 100 +#define VOTE_MAX_UNION_PREV_IOU 90 +#define VOTE_MAX_PREV_IOU 90 + +#define VOTE_MAX_UNION_PREDICT_IOU_BONUS 50 +#define VOTE_MAX_PREDICT_IOU_BONUS 50 +#define VOTE_MAX_UNION_PREV_IOU_BONUS 45 +#define VOTE_MAX_PREV_IOU_BONUS 45 + +#define VOTE_SIZE_AVOID_PUNISH 25 //30 +#define VOTE_WRONG_NAME_PUNISH 25 //30 + +#define VOTE_NEIGHBOR 150 +#define VOTE_THE_SAME_SIZE 45 +#define VOTE_PLATE 350 //50 +#define VOTE_PLATE_MIN_SCORE 50 + +//#endif //GY_OS_WIN - DEFINE + +//#ifdef GY_OS_WIN +void reset_id_obj(int tracking_channel_idx, int id_idx) +{ + int disappearCount = g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count; + + if (strlen(g_TrackingRecords[tracking_channel_idx][id_idx].name) >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][id_idx].name) == 1) + { + if (disappearCount >= DISAPPEAR_FRAME_MAX * 20) + { + memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); + } + } + else { + if (disappearCount >= DISAPPEAR_FRAME_MAX) + { + memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); + } + } +} +//#endif //GY_OS_WIN - reset_id_obj + +//#ifdef GY_OS_WIN +float prev_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +float predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +float union_predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +float union_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +int vote_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +//#endif //GY_OS_WIN + +//#ifdef GY_OS_WIN +void update_iou_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) +{ + float fIOU, predit_IOU, union_IOU, union_predit_IOU; + detection_pos* pNext = NULL; + int det_count; + + // iou about obj to obj. + //detection_pos* pNext_b = NULL; + //float fIou_union; + + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + //iou_count = 0; + det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; + //frame_count = g_TrackingRecords[tracking_channel_idx][i].frame_count; + + if (det_count == 0) + continue; + + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //PW@ + union_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //PW@ + + predit_IOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //PwI + union_predit_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //PwI + + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][i].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate) == 0*/) { + fIOU = 1.0; + predit_IOU = 1.0; + union_predit_IOU = 1.0; + union_IOU = 1.0; + } + else{ + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + else { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1) { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + + if (IsVehicleCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { + if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { + + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + } + + if (IsMotorbikeCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { + if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { + + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + } + + if (strcmp(pNext->name,"person")==0 || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { + if (strcmp(pNext->name, "person") == 0 && strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { + + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + } + + if (IsGarbageCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { + if (IsGarbageCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || + strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { + + } + else { + fIOU = 0.0; + predit_IOU = 0.0; + union_predit_IOU = 0.0; + union_IOU = 0.0; + } + } + + prev_iou_table[i][j] = fIOU; + predit_iou_table[i][j] = predit_IOU; + union_predit_iou_table[i][j] = union_predit_IOU; + union_iou_table[i][j] = union_IOU; + } + } +} +//#endif //GY_OS_WIN - update_iou_table + +//#ifdef GY_OS_WIN +void update_vote_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) +{ + detection_pos* pNext = NULL; + detection_pos* pNext2 = NULL; + + int det_count; + int vote_value = 0; + + int max_iou_idx = -1; + float max_iou = 0.0; + + int max_predict_iou_idx = -1; + float max_predict_iou = 0.0; + + int max_union_iou_idx = -1; + float max_union_iou = 0.0; + + int max_union_predict_iou_idx = -1; + float max_union_predict_iou = 0.0; + + + float pre_H, pre_W; + float delta_w, delta_h; + //int old_confidence; + + if (IsANPRCategory(featureType)) { + for (int m = 0; m < total_element_size; m++) + { + pNext = PosInfo + m; + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { + for (int k = 0; k < total_element_size; k++) + { + pNext2 = PosInfo + k; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && + (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) + ) + { + strcpy(pNext2->car_type_name, pNext->name); + + if (strlen(pNext2->properties.plate) > strlen(pNext->linked_plate)) + { + if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + + strcpy(pNext->linked_plate, pNext2->properties.plate); + pNext->linked_plate_length = pNext2->properties.plate_length; + } + } + + break; + } + } + } + } + } + } + + for (int k = 0; k < MAX_TRACKING_NUM; k++) + { + max_iou = 0.0; + max_iou_idx = -1; + + max_predict_iou = 0.0; + max_predict_iou_idx = -1; + + max_union_iou = 0.0; + max_union_iou_idx = -1; + + max_union_predict_iou = 0.0; + max_union_predict_iou_idx = -1; + + det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + + if (det_count == 0) + continue; + + for (int m = 0; m < total_element_size; m++) + { + pNext = PosInfo + m; + + vote_value = 0; + vote_table[k][m] = vote_value; + + ////PvMwInAƥ[v + { + vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU * prev_iou_table[k][m]); + if (prev_iou_table[k][m] > max_iou) + { + max_iou = prev_iou_table[k][m]; + max_iou_idx = m; + } + + vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU * predit_iou_table[k][m]); + if (predit_iou_table[k][m] > max_predict_iou) + { + max_predict_iou = predit_iou_table[k][m]; + max_predict_iou_idx = m; + } + + vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU * union_iou_table[k][m]); + //PWvIpnIOU + if (union_iou_table[k][m] > max_union_iou) + { + max_union_iou = union_iou_table[k][m]; + max_union_iou_idx = m; + } + + vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU * union_predit_iou_table[k][m]); + //PwIpn IOU + if (union_predit_iou_table[k][m] > max_union_predict_iou) + { + max_union_predict_iou = union_predit_iou_table[k][m]; + max_union_predict_iou_idx = m; + } + } + + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + //printf("\n-------pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); + + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][m] += VOTE_PLATE_MIN_SCORE; + + if (prev_iou_table[k][m] > max_iou) + { + max_iou = prev_iou_table[k][m]; + max_iou_idx = m; + } + + if (predit_iou_table[k][m] > max_predict_iou) + { + max_predict_iou = predit_iou_table[k][m]; + max_predict_iou_idx = m; + } + + //PWvIpnIOU + if (union_iou_table[k][m] > max_union_iou) + { + max_union_iou = union_iou_table[k][m]; + max_union_iou_idx = m; + } + + //PwIpn IOU + if (union_predit_iou_table[k][m] > max_union_predict_iou) + { + max_union_predict_iou = union_predit_iou_table[k][m]; + max_union_predict_iou_idx = m; + } + //printf("\n-------same plate #1\n"); + } + else { + vote_table[k][m] = 0; + //printf("\n-------not same plate #2\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + //printf("\n----#2---pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); + //printf("\n---------same car\n"); + vote_table[k][m] += VOTE_PLATE_MIN_SCORE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + + //ӧOإ[Jv + //max_iou_idx + + if (max_iou_idx != -1) + { + vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU_BONUS); + //obj name same + pNext = PosInfo + max_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #1\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + if (max_union_iou_idx != -1) + { + vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU_BONUS); + //obj name same + pNext = PosInfo + max_union_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_union_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #2\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_union_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + + if (max_predict_iou_idx != -1) + { + vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU_BONUS); + //obj name same + pNext = PosInfo + max_predict_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_predict_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #1\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_predict_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + if (max_union_predict_iou_idx != -1) + { + vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU_BONUS); + pNext = PosInfo + max_union_predict_iou_idx; + if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) + { + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; + //printf("\n-------same plate #3\n"); + } + } + else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 + /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { + + vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; + //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); + } + } + } + + for (int m = 0; m < total_element_size; m++) + { + pNext = PosInfo + m; + + if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { + if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { + + } + else { + vote_table[k][m] = 0; + continue; + } + } + + if (IsVehicleCategory(pNext)) { + if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "van")) { + + + + } + else { + if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { + vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + } + } + } + else if (IsMotorbikeCategory(pNext)) { + if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ng")) { + + } + else { + if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { + vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + } + } + } + else { + /*if (strcmp(pNext->name,"new_object")==0) { + int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width, pNext->height, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0); + if (checkisInside == 1) { + vote_table[k][m] += VOTE_PERSON; + } + else { + if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { + vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + } + } + } + else */ + //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { + //if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) { + //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; + //} + //else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 2) { + //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH * 10; + //} + //} + } + + if (get_g_check_if_show_parking() == 1) { + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + if (g_TrackingRecords[tracking_channel_idx][k].check_if_within_zone[index_zone] == PosInfo->check_if_within_zone[index_zone]) + { + vote_table[k][m] += VOTE_WITHIN_ZONE; + } + } + } + + //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { + //vote_table[k][m] += VOTE_NAME; + //if (strcmp("person", pNext->name) == 0) + //{ + //vote_table[k][m] += VOTE_PERSON; + //} + //} +#if 1 + //PwIe + pre_H = g_TrackingRecords[tracking_channel_idx][k].predict_detection.height; + pre_W = g_TrackingRecords[tracking_channel_idx][k].predict_detection.width; + + delta_h = 1.0 - fabs(pNext->height / pre_H - 1.0); + delta_w = 1.0 - fabs(pNext->width / pre_W - 1.0); + + vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_h; + vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_w; + + double new_width = 0.0; + double new_height = 0.0; + double new_slide = 0.0; + + double new_pred_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].predict_detection.left_x; + double new_pred_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].predict_detection.top_y; + double new_pred_vec = sqrt(new_pred_vec_x*new_pred_vec_x + new_pred_vec_y * new_pred_vec_y); + + if (strcmp(pNext->name, "person") == 0 && strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { + new_width = pre_W * 5.5; + new_height = pre_H * 5.5; + new_slide = sqrt(new_width*new_width + new_height * new_height); + } + else { + new_width = pre_W * 2.5; + new_height = pre_H * 2.5; + new_slide = sqrt(new_width*new_width + new_height * new_height); + } + + //F񪺹wI + if (new_pred_vec <= new_slide) { + vote_table[k][m] += VOTE_NEIGHBOR * (new_slide - new_pred_vec) / (new_slide); + } +#endif +#if 1 + //vyV + if (det_count >= 2) + { + double new_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x; + double new_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y; + + //double new_vec = sqrt(new_vec_x*new_vec_x + new_vec_y* new_vec_y); + + double old_vec_x = 0.0; + double old_vec_y = 0.0; + + old_vec_x = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].left_x; + old_vec_y = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].top_y; + + //첾Vۤ + if (old_vec_x < 0) + { + if (new_vec_x > 0 && abs(new_vec_x) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)) //3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + + if (old_vec_x > 0) + { + if (new_vec_x < 0 && abs(new_vec_x) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2))//3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + + if (old_vec_y < 0) + { + if (new_vec_y > 0 && abs(new_vec_y) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + + if (old_vec_y > 0) + { + if (new_vec_y < 0 && abs(new_vec_y) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 + { + vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; + } + else { + + } + } + } +#endif + } + } +} +//#endif //GY_OS_WIN - update_vote_table + +int find_possible_obj(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, int id_idx,int use_high_or_low_score) +{ + int max_vote_value = 0; + int obj_idx = -1; + detection_pos* pNext = NULL; + + //printf("\n-------id_idx:%d\n", id_idx); + + if(use_high_or_low_score == 0) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_0; + else if(use_high_or_low_score == 1) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_1; + else if (use_high_or_low_score == 2) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_2; + else if (use_high_or_low_score == 3) + max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_3; + + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->obj_tracking_id > 0) + continue; + + //printf("\n---------vote_table[id_idx][%d]:%d\n",j, vote_table[id_idx][j]); + if (vote_table[id_idx][j] > max_vote_value) + { + max_vote_value = vote_table[id_idx][j]; + obj_idx = j; + } + } + + ///if bbox j already assign id, check vote_value + //printf("\n------id_idx:%d---obj_idx:%d\n", id_idx, obj_idx); + if (obj_idx != -1) + { + //printf("\n---------obj_idx:%d\n", obj_idx); + + pNext = PosInfo + obj_idx; + + //pNext->vote_value = max_vote_value; + pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; + pNext->obj_tracking_id_idx = id_idx; + } + //if bbox j already assign id, check vote_value + + return obj_idx; +} +//#endif //GY_OS_WIN - find_possible_obj + +int Modify_Plate_and_Recount_Length(char *input_plate,char *output_plate) { + char afterBuf[256] = { 0 }; + strcpy(afterBuf, input_plate); + + char buf[64] = { 0 }; + memset(buf, 0x00, sizeof(buf)); + strcpy(buf, afterBuf); + + int k = 0; + int plate_length = 0; + + //printf("\n------1\n"); + //printf("\nbuf:%s\n",buf); + //printf("\n------2\n"); + for (int m = 0; m < strlen(buf); m++) + { + //printf("[%x]",buf[m]); + if (buf[m] >= 65 && buf[m] <= 90) { + + if (buf[m] == 73 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { + afterBuf[m] = '1'; + } + else if (buf[m] == 79 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { + afterBuf[m] = '0'; + } + + //alphabets++; + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + else if (buf[m] >= 97 && buf[m] <= 122) { + if (buf[m] == 105 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { + afterBuf[m] = '1'; + } + else if (buf[m] == 111 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { + afterBuf[m] = '0'; + } + + if ((featureType & FEATURE_LPR_TWN) <= 0) { + //alphabets++; + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + } + else if (buf[m] >= 48 && buf[m] <= 57) { + //digits++; + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + else { + //specialcharacters++; + if ((featureType & FEATURE_LPR_JPN) > 0) { + //ѦҤUTF-8ATcզ@ӤAĤ@cA|227-239C + if (buf[m] >= 227 && buf[m] <= 239 && (m + 2) < strlen(buf)) { + afterBuf[k] = afterBuf[m]; + k++; + afterBuf[k] = afterBuf[m + 1]; + k++; + afterBuf[k] = afterBuf[m + 2]; + k++; + m = m + 2; + + plate_length++; + } + } + else if ((featureType & FEATURE_LPR_THA) > 0 || (featureType & FEATURE_LPR_BGD) > 0) { + //ѦҮΩs[ԤUTF-8ATcզ@ӮΩs[ԤAĤ@cA|O224C + if (buf[m] == 224 && (m + 2) < strlen(buf)) { + afterBuf[k] = afterBuf[m]; + k++; + afterBuf[k] = afterBuf[m + 1]; + k++; + afterBuf[k] = afterBuf[m + 2]; + k++; + m = m + 2; + + plate_length++; + } + } + else if ((featureType & FEATURE_LPR_MEA) > 0) { + //ѦҪԧBUTF-8Acզ@ӪԧBAĤ@cA|O67C + if (buf[m] >= 216 && buf[m] <= 217 && (m + 1) < strlen(buf)) { + + //if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) + { + //afterBuf[k] = afterBuf[m]; + //k++; + //afterBuf[k] = afterBuf[m + 1]; + //k++; + m = m + 1; + + //plate_length++; + } + //else { + //m = m + 1; + //} + } + //䴩, ť + else if (buf[m] == 45 + || buf[m] == 32) { + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + } + else if ((featureType & FEATURE_LPR_TWN) > 0) { + //䴩rUTF-8ATcզ@ӤAĤ@cA|228-233C + if (buf[m] >= 228 && buf[m] <= 233 && (m + 2) < strlen(buf)) { + + if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) { + afterBuf[k] = afterBuf[m]; + k++; + afterBuf[k] = afterBuf[m + 1]; + k++; + afterBuf[k] = afterBuf[m + 2]; + k++; + m = m + 2; + + plate_length++; + } + else { + m = m + 2; + } + } + else if (buf[m] == 45) {//䴩 + if (activeDisplayDash) + { + afterBuf[k] = afterBuf[m]; + k++; + + plate_length++; + } + } + } + } + } + //printf("\n------\n"); + afterBuf[k] = '\0'; + //printf("\nafterBuf:%s\n", afterBuf); + + if (((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION && strcmp(WeightFileModeName, "mod003") == 0)) { + strcpy(afterBuf, input_plate); + k = strlen(input_plate); + afterBuf[k] = '\0'; + plate_length = k; + } + + if (plate_length >= atoi(viewChannelData[0].min_characters) && + plate_length <= atoi(viewChannelData[0].max_characters)) + strcpy(output_plate, afterBuf); + else + plate_length = 0; + return plate_length; +} + +void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size) +{ +#ifdef GY_OS_AMBA + detection_pos* pNext = NULL; + for (int i = 0; i < total_element_size; i++) + { + //printf("\n[start all nets] while 10-1\n"); + pNext = PosInfo + i; /** sizeof(detection_pos)*/ + + + if (strlen(pNext->name) == 0) { + continue; + } + char c_logo[50] = { 0 }; + + int iCar_idx = pNext->car_logo_idx;//pNext->car_logo_idx + detection_pos *pNext_car; + + if (iCar_idx >= 0) + { + pNext_car = PosInfo + iCar_idx;//iCar_idx + int iLogo_idx = pNext_car->car_logo_idx; + detection_pos *pNext_logo = NULL; + //printf("\n----------iLogo_idx:%d\n", iLogo_idx); + if (IsVehicleCategory(pNext_car)) { + if (iLogo_idx >= 0) + { + pNext_logo = PosInfo + iLogo_idx; + //printf("\n---------pNext_logo->name:%s\n", pNext_logo->name); + if (pNext_logo->name + && strlen(pNext_logo->name) > 0 + && !IsANPRCategory_L_Plate(pNext_logo->name) + && !IsVehicleCategory(pNext_logo) + && strcmp(pNext_logo->name, "person") != 0 + && (pNext_logo->name[0] != '0' && + pNext_logo->name[0] != '1' && + pNext_logo->name[0] != '2' && + pNext_logo->name[0] != '3' && + pNext_logo->name[0] != '4' && + pNext_logo->name[0] != '5' && + pNext_logo->name[0] != '6' && + pNext_logo->name[0] != '7' && + pNext_logo->name[0] != '8' && + pNext_logo->name[0] != '9') + ) { + char temp_buf[50] = { 0 }; + int index_temp_buf = 0; + + for (int m = 0; m < (int)strlen(pNext_logo->name); m++) { + if (m < (int)strlen(pNext_logo->name) - 1 && pNext_logo->name[m] == 'l' && pNext_logo->name[m + 1] == '_') { + m++; + } + else { + temp_buf[index_temp_buf] = pNext_logo->name[m]; + index_temp_buf++; + } + } + temp_buf[index_temp_buf] = '\0'; + + sprintf(c_logo, "%s", temp_buf); + } + else { + sprintf(c_logo, "%s", ""); + } + strcpy(pNext_logo->logo, c_logo); + } + else { + sprintf(c_logo, "%s", ""); + } + strcpy(pNext_car->logo, c_logo); + } + else { + sprintf(c_logo, "%s", ""); + } + strcpy(pNext->properties.logo, c_logo); + } + + int check_if_logo = 0; + char temp_name[30] = { 0 }; + int index_temp_name = 0; + for (int index_name = 0; index_name < (int)strlen(pNext->name); index_name++) { + if (index_name < (int)strlen(pNext->name) - 1 && pNext->name[index_name] == 'l' && pNext->name[index_name + 1] == '_') { + index_name++; + check_if_logo = 1; + } + else { + temp_name[index_temp_name] = pNext->name[index_name]; + index_temp_name++; + } + } + temp_name[index_temp_name] = '\0'; + if (check_if_logo == 1) { + strcpy(pNext->name, temp_name); + strcpy(pNext->properties.logo, temp_name); + } + } +#endif +} + +void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_temp, int tracking_channel_idx, time_t curr_det_time, int i_InSourceOri_w, int i_InSourceOri_h) +{ + int total_element_size = * total_element_size_temp; + /*double dur; + clock_t start, end; + start = clock();*/ +#ifdef GY_OS_NOVA + g_sensors_type = 1; +#endif + +#ifdef GY_OS_AMBA + g_sensors_type = atoi(SystemSetting.sensors_type); +#endif + g_max_sensor_size = g_sensors_type == 0 ? MAX_SENSOR_TYPE0 : MAX_SENSOR_TYPE1; + + float ratio_w = (float)i_InSourceOri_w;//0.25f + float ratio_h = (float)i_InSourceOri_h;//0.3f + + //printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\nGetObjectTrackingIDNew: %d\n",10); + //printf("\nratio_w: %f\n", ratio_w); + //printf("\nratio_h: %f\n", ratio_h); + //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + + detection_pos* pNext = NULL; + //detection_pos* pNext_temp = NULL; + + for (int k = 0; k < MAX_DETECTION_ZONE; k++) + { + //eventCounterList[j].counter_count = 0; + viewDetectionZone[tracking_channel_idx][k].queuing_trigger_event_idx = -1; + } + + struct timeval currtime; + gettimeofday(&currtime, NULL); + int det_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); + //printf("----det time = %d ms\n", det_ms); + + //2020-04-10 Updated + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + pNext->obj_tracking_id = 0; + //pNext->vote_value = 0; + pNext->det_time = curr_det_time; + pNext->det_milli_sec = det_ms; + pNext->trigger_type = 0; + //pNext->disappear_count = 0; + pNext->obj_tracking_id_idx = -1; + + pNext->replaced_id = 0; + pNext->replaced_id_idx = -1; + + //printf("[%d] p_name 10 = %s \n", i, pNext->name); + //pNext->iou_prev_self = 0; + pNext->adjust_obj_speed = -1; + pNext->check_if_replaced_in_zone = 0; + //strcpy(pNext->replaced_name, ""); + + //pNext->image_id = -1; + } + + memset(prev_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + memset(predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + memset(union_predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + memset(union_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + + memset(vote_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); + + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + reset_id_obj(tracking_channel_idx, i); + g_TrackingRecords[tracking_channel_idx][i].bAssign_flag = 0; + //g_TrackingRecords[tracking_channel_idx][i].vote_value = 0; + g_TrackingRecords[tracking_channel_idx][i].Assign_obj_idx = -1; + } + + /// + update_iou_table(PosInfo, total_element_size, tracking_channel_idx); + update_vote_table(PosInfo, total_element_size, tracking_channel_idx); + /// + + int det_count = 0; +#if 1 + ///Search Multi connection bbox + int closest_obj_idx = -1; + int bFindTrackingObjects = 0; + + for (int index_score = 0; index_score < 4; index_score++) { + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + //reset_id_obj(&g_TrackingRecords[tracking_channel_idx][i],i); + + det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; + if (det_count == 0) + continue; + + if (g_TrackingRecords[tracking_channel_idx][i].bAssign_flag == 1) + continue; + + //first time : find_possible_obj for high score + //second time : find_possible_obj for low score + //more time : find_possible_obj for lower score + closest_obj_idx = find_possible_obj(PosInfo, total_element_size, tracking_channel_idx, i, index_score); + + bFindTrackingObjects = 0; + if (closest_obj_idx != -1) + bFindTrackingObjects = 1; + + //printf("\n-------i:%d-------closest_obj_idx:%d\n",i, closest_obj_idx); + + if (bFindTrackingObjects) + { + ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, i, closest_obj_idx); + } + } + } +#endif + + ///Assign New obj ID to new bounding box + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + det_count = 0; + + if (pNext->obj_tracking_id <= 0) + { + ///Check prev data again + float max_prev_iou = 0.0; + int closest_id_idx = -1; + for (int j = 0; j < MAX_TRACKING_NUM; j++) + { + if (g_TrackingRecords[tracking_channel_idx][j].bAssign_flag) + continue; + + det_count = g_TrackingRecords[tracking_channel_idx][j].detection_count; + + if (det_count >= 1) + { + float fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1]); + + if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 1) { + if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate) == 0*/) { + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + } + else if (strcmp(pNext->name, "ambulance") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (strcmp(pNext->name, "blank") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (strcmp(pNext->name, "stop_sign") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (strcmp(pNext->name, "face") == 0) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + //break; + } + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate) == 0*/) { + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + } + } + } + else if (g_TrackingRecords[tracking_channel_idx][j].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + + } + else if (det_count >= 2 && + g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate_length >= 1 && + (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && + LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + //if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + break; + } + } + else if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][j].name) == 0) { + if (fIOU > max_prev_iou) + { + + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + //printf("\n---------max_prev_iou:%f,top_y:%f\n", max_prev_iou,pNext->top_y); + } + else if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "car") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "bus") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "truck") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "tuktuk") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "trailer") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "pickup") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "SUV") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "dual_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "single_headlight") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "van"))) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + } + else if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "motorbike") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ok") || + strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ng"))) { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + } + else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(heartbeatData.events_default_version, "4") == 0) + { + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + else if (det_count >= 2) { + fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); + if (fIOU > max_prev_iou) + { + max_prev_iou = fIOU; + closest_id_idx = j; + } + } + } + + } + } + + if (closest_id_idx != -1) + { + //pNext->vote_value = max_prev_iou; + pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][closest_id_idx].obj_tracking_id; + pNext->obj_tracking_id_idx = closest_id_idx; + + ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, closest_id_idx, i); + } + else { + for (int m = 0; m < MAX_TRACKING_NUM; m++) + { + if (g_TrackingRecords[tracking_channel_idx][m].bAssign_flag) + continue; + + det_count = g_TrackingRecords[tracking_channel_idx][m].detection_count; + if (det_count == 0) + { + //pNext->vote_value = 0; + pNext->obj_tracking_id = 0; + pNext->obj_tracking_id_idx = m; + + ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, m, i); + + break; + } + } + } + } + } + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) + { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && pNext->obj_dwell_time >= 1 && strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && + pNext->height >= 1 && pNext->width >= 1) + { + int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width * 1.5, pNext->height * 1.5, g_ori_yuv_width, g_ori_yuv_height, 0); + + if (checkisInside == 1 && (pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.2 + && pNext->width / (float)g_ori_yuv_width < 0.2 && pNext->height / (float)g_ori_yuv_height < 0.2) { + + det_count = g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].detection_count; + for (int index_det = det_count - 1 - 1; index_det >= 0; index_det--) { + if (strlen(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name) >= 1 && + strcmp(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name, "object") != 0) + { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name); + break; + } + } + + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (pNext->height / pNext->width >= 1.15 && (pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.05 && + pNext->width / (float)g_ori_yuv_width <= 0.05) { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "person"); + pNext->check_if_replaced_in_zone = 1; + } + else if (pNext->height / pNext->width <= 0.95 || ((float)g_ori_yuv_width * (float)g_ori_yuv_height) >= 0.05 || + pNext->width / (float)g_ori_yuv_width > 0.05) { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "car"); + pNext->check_if_replaced_in_zone = 1; + } + } + } + } + } + } + + ///}lƥIJoUpdateZoneStatus + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + //if (strcmp(pNext->name, "object") == 0) + //{ + //if (strlen(pNext->replaced_name) >= 1) { + //strcpy(pNext->name, pNext->replaced_name); + //} + //} + + { + int k = pNext->obj_tracking_id_idx; + det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + UpdateZoneStatus(pNext, tracking_channel_idx, k, det_count - 1, ratio_w, ratio_h, total_element_size, PosInfo, i); + } + } + } + + /////////-------------- + + for (int k = 0; k < MAX_TRACKING_NUM; k++) { + if (g_TrackingRecords[tracking_channel_idx][k].bAssign_flag == 0) { + det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + if (det_count >= 1) { + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].disappear_count++; + } + g_TrackingRecords[tracking_channel_idx][k].disappear_count++; + } + } + +#if 1 + + int ZoneQueuingCount[MAX_DETECTION_ZONE] = { 0 }; + int ZoneGivewayCount[MAX_DETECTION_ZONE] = { 0 }; + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + ZoneQueuingCount[i] = 0; + ZoneGivewayCount[i] = 0; + } + + ////////----------Forget to give way detection § + int index_zone_protect = -1; + int index_zone_keep_away = -1; + int index_zone_protect_2 = -1; + int index_zone_keep_away_2 = -1; + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect) == 1) { + index_zone_protect = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect); + } + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away) == 1) { + index_zone_keep_away = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away); + } + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2) == 1) { + index_zone_protect_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2); + } + + if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2) == 1) { + index_zone_keep_away_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2); + } + + + if ((index_zone_protect >= 0 && index_zone_keep_away >= 0) || (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0)) { + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_check_giveway[i] == 1) + { + ZoneGivewayCount[i]++; + } + } + } + + if (index_zone_protect >= 0 && index_zone_keep_away >= 0) { + if (ZoneGivewayCount[index_zone_protect] >= 1 && ZoneGivewayCount[index_zone_keep_away] >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_check_giveway[index_zone_keep_away] == 1) + { + pNext->zone_violation_idx[index_zone_keep_away] = 1; + pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; + pNext->trigger_idx[index_zone_keep_away] = k; + if (pNext->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; + } + } + } + break; + } + } + } + } + + if (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0) { + if (ZoneGivewayCount[index_zone_protect_2] >= 1 && ZoneGivewayCount[index_zone_keep_away_2] >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away_2].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_check_giveway[index_zone_keep_away_2] == 1) + { + pNext->zone_violation_idx[index_zone_keep_away_2] = 1; + pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; + pNext->trigger_idx[index_zone_keep_away_2] = k; + if (pNext->obj_tracking_id_idx >= 0) { + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; + } + } + } + break; + } + } + } + } + } + + ///pƾp + + /*end = clock(); + dur = (double)(end - start); + printf("\nGet Object Tracking ID New[5]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) + { + ZoneQueuingCount[i]++; + } + } + } + /* + end = clock(); + dur = (double)(end - start); + printf("\nGet Object Tracking ID New[6]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + /* + if (ZoneQueuingCount[i]>0) { + printf("\n---------------\n"); + printf("\nZoneQueuingCount[%d]:%d\n",i, ZoneQueuingCount[i]); + printf("\n---------------\n"); + }*/ + +#ifdef GY_OS_V_SERIES + int check_if_enable_linked_to_dwell_time = 0; + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; +#else + int check_if_enable_linked_to_dwell_time = 0; + +#if 1 + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { + + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][i].trigger_event[k].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + //printf("\n------UU:14\n"); + + for (int w = 0; w < event_counter_num; w++) + { + for (int m = 0; m < MAX_EVENT_COUNTERS; m++) + { + if (strlen(eachEventCounter[w]) >= 1 && strcmp(eachEventCounter[w], eventCounterList[m].counter_name) == 0) + { + if (strcmp(eventCounterList[m].enable_linked_to_dwell_time, "Yes") == 0) { + check_if_enable_linked_to_dwell_time = 1; + break; + } + } + } + if (check_if_enable_linked_to_dwell_time == 1) + break; + } + } + } +#endif +#endif + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + g_IsCustomWeight == 1) { + + if (viewDetectionZone[tracking_channel_idx][i].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][i].parking_line >= 1) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { + + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1) { + viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx = k; + + int count_plot = 0; + for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][i].parking_space; index_plot++) + { + if (g_parking_space_check_table[i][index_plot] == 1) { + count_plot++; + } + } + + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = count_plot; + + if (viewDetectionZone[tracking_channel_idx][i].prev_queuing_num >= viewDetectionZone[tracking_channel_idx][i].queuing_count + && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + + int temp_m = -1; + if (pNext->zone_violation_idx[i] == 1) { + //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); + pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; + //pNext->detection_zone_idx = i; + pNext->trigger_idx[i] = k; + + for (int m = 0; m < MAX_TRACKING_NUM; m++) + { + if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) + { + g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; + g_TrackingRecords[tracking_channel_idx][m].trigger_zone_id = i + 1; + temp_m = m; + break; + } + } + } + + pNext->check_if_having_been_counted[i] = 0; + if(temp_m >= 0) + g_TrackingRecords[tracking_channel_idx][temp_m].check_if_having_been_counted[i] = 0; + } + } + else { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) { + pNext->zone_violation_idx[i] = 0; + } + } + } + } + } + } + } + else{ + + if (check_if_enable_linked_to_dwell_time == 0) + { + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + } + + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { + + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { + + if (ZoneQueuingCount[i] >= viewDetectionZone[tracking_channel_idx][i].queuing_count + && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) + { + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) { + //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); + pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; + //pNext->detection_zone_idx = i; + pNext->trigger_idx[i] = k; + + for (int m = 0; m < MAX_TRACKING_NUM; m++) + { + if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) + { + g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; + break; + } + } + } + } + } + } + } + } + + } + } + else { + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + } + } + /** + end = clock(); + dur = (double)(end - start); + printf("\nGet Object Tracking ID New[7]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC));*/ +#endif + + check_record_if_overtime(); + if (get_g_check_if_show_parking() == 1) { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2) + && pNext->check_if_replaced_in_zone == 1 && (int)pNext->obj_dwell_time >= 10) + { + if (strcmp(pNext->name, "object") != 0) { + if ((pNext->trigger_type & (unsigned int)TRIGGER_PARKING_VIOLATION) == (unsigned int)TRIGGER_PARKING_VIOLATION || + (pNext->trigger_type & (unsigned int)TRIGGER_MISSING_UNATTENDED) == (unsigned int)TRIGGER_MISSING_UNATTENDED || + (pNext->trigger_type & (unsigned int)TRIGGER_TAMPERING) == (unsigned int)TRIGGER_TAMPERING || + (pNext->trigger_type & (unsigned int)TRIGGER_QUEUING_VIOLATION) == (unsigned int)TRIGGER_QUEUING_VIOLATION || + (pNext->trigger_type & (unsigned int)TRIGGER_MISSING_OBJECT_DETECTION) == (unsigned int)TRIGGER_MISSING_OBJECT_DETECTION || + (pNext->trigger_type & (unsigned int)TRIGGER_ALL_OBJECTS) == (unsigned int)TRIGGER_ALL_OBJECTS || + (pNext->trigger_type & (unsigned int)TRIGGER_LACK_OF_ANY_OBJECT) == (unsigned int)TRIGGER_LACK_OF_ANY_OBJECT || + (pNext->trigger_type & (unsigned int)TRIGGER_FORGET_TO_GIVE_WAY) == (unsigned int)TRIGGER_FORGET_TO_GIVE_WAY) + { + clear_a_record_locked_ivs(pNext->left_x, pNext->top_y, pNext->width, pNext->height, g_ori_yuv_width, g_ori_yuv_height, pNext->name); + } + else { + set_a_record_locked_ivs(pNext->left_x, pNext->top_y, pNext->width, pNext->height, g_ori_yuv_width, g_ori_yuv_height, pNext->name); + } + } + } + } + } + + *total_element_size_temp = total_element_size; +} + +#ifdef GY_OS_WIN +unsigned int GetObjectSocialDistance(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, IplImage* ipl_img, float distance_heigh, float distance_width) +{ + float x1 = viewDetectionZone[tracking_channel_idx][0].Points[0].x; + float y1 = viewDetectionZone[tracking_channel_idx][0].Points[0].y; + + float x2 = viewDetectionZone[tracking_channel_idx][0].Points[1].x; + float y2 = viewDetectionZone[tracking_channel_idx][0].Points[1].y; + + float x3 = viewDetectionZone[tracking_channel_idx][0].Points[2].x; + float y3 = viewDetectionZone[tracking_channel_idx][0].Points[2].y; + + float x4 = viewDetectionZone[tracking_channel_idx][0].Points[3].x; + float y4 = viewDetectionZone[tracking_channel_idx][0].Points[3].y; + + float d_x1, d_y1, d_x2, d_y2, d_x3, d_y3, d_x4, d_y4; + +#if 1 + CvPoint2D32f src_points[4]; + CvPoint2D32f dst_points[4]; + + float ratio_window_h, ratio_window_w; + ratio_window_h = ipl_img->height / CANVAS_HEIGHT; + ratio_window_w = ipl_img->width / CANVAS_WIDTH; + + + //window size -> real resultion of camera + x1 = x1 * ratio_window_w; + y1 = y1 * ratio_window_h; + + x2 = x2 * ratio_window_w; + y2 = y2 * ratio_window_h; + + x3 = x3 * ratio_window_w; + y3 = y3 * ratio_window_h; + + x4 = x4 * ratio_window_w; + y4 = y4 * ratio_window_h; + + + //x1 = (x1 / CANVAS_WIDTH) * 3840; + //y1 = (y1 / CANVAS_HEIGHT) * 2160; + + //x2 = (x2 / CANVAS_WIDTH) * 3840; + //y2 = (y2 / CANVAS_HEIGHT) * 2160; + + //x3 = (x3 / CANVAS_WIDTH) * 3840; + //y3 = (y3 / CANVAS_HEIGHT) * 2160; + + //x4 = (x4 / CANVAS_WIDTH) * 3840; + //y4 = (y4 / CANVAS_HEIGHT) * 2160; + + //d_x1 = (d_x1 / CANVAS_WIDTH) * 3840; + //d_y1 = (d_y1 / CANVAS_HEIGHT) * 2160; + //d_x2 = (d_x2 / CANVAS_WIDTH) * 3840; + //d_y2 = (d_y2 / CANVAS_HEIGHT) * 2160; + + //d_x3 = (d_x3 / CANVAS_WIDTH) * 3840; + //d_y3 = (d_y3 / CANVAS_HEIGHT) * 2160; + //d_x4 = (d_x4 / CANVAS_WIDTH) * 3840; + //d_y4 = (d_y4 / CANVAS_HEIGHT) * 2160; + + d_x1 = 0; + d_y1 = 0; + d_x2 = distance_width; + d_y2 = 0; + d_x3 = distance_width; + d_y3 = distance_heigh; + d_x4 = 0; + d_y4 = distance_heigh; + + src_points[0].x = x1; + src_points[0].y = y1; + src_points[1].x = x2; + src_points[1].y = y2; + + src_points[2].x = x3; + src_points[2].y = y3; + src_points[3].x = x4; + src_points[3].y = y4; + + + dst_points[0].x = d_x1; + dst_points[0].y = d_y1; + dst_points[1].x = d_x2; + dst_points[1].y = d_y2; + + dst_points[2].x = d_x3; + dst_points[2].y = d_y3; + dst_points[3].x = d_x4; + dst_points[3].y = d_y4; + + CvMat *M = cvCreateMat(3, 3, CV_32FC1); + cvGetPerspectiveTransform(src_points, dst_points, M); + + PerspectiveTransform(PosInfo, total_element_size, M, distance_heigh, distance_width, ipl_img->height, ipl_img->width); + +#if 0 + IplImage* dst = NULL; + CvSize ImageSize1 = cvSize(994, 364); + dst = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3); + cvZero(dst); + + CvScalar fillval = cvScalarAll(0); + + cvWarpPerspective(ipl_img, dst, M, CV_INTER_LINEAR, fillval); + cvNamedWindow("Affine_Transform", 1); + cvShowImage("Affine_Transform", dst); + + cvWaitKey(1); +#endif + //cvReleaseImage(&dst); + //cvReleaseMat(M); + cvReleaseMat(&M); +#endif +} +#endif //GY_OS_WIN - GetObjectSocialDistance + +void BindLicensePlateToVehicle(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) +{ + detection_pos* pNext = NULL; + detection_pos* pNext2 = NULL; + int BindNewLicensePlateOk = 0; + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (i == total_element_size - 1) + break; + + if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) + { + //printf("tracking_channel_idx ==== %d \n", tracking_channel_idx); + for (int k = 0; k < MAX_TRACKING_NUM; k++) + { + if (g_TrackingRecords[tracking_channel_idx][k].obj_tracking_id == pNext->obj_tracking_id) + { + for (int j = i + 1; j < total_element_size; j++) + { + pNext2 = PosInfo + j; + if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) + { + + if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0)) + { + if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][k].linked_plate)) + { + int det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; + //StrReplace(pNext2->properties.plate, "-", ""); + + if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, pNext2->properties.plate); + pNext->linked_plate_length = pNext2->properties.plate_length; + strcpy(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext2->properties.plate); + g_TrackingRecords[tracking_channel_idx][k].linked_plate_length = pNext2->properties.plate_length; + + if (det_count > 0) + { + strcpy(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate, pNext2->properties.plate); + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate_length = pNext2->properties.plate_length; + } + + BindNewLicensePlateOk = 1; + } + } + break; + } + } + } + + if (!BindNewLicensePlateOk) { + if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= atoi(viewChannelData[0].min_characters) && + g_TrackingRecords[tracking_channel_idx][k].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][k].linked_plate); + pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][k].linked_plate_length; + } + } + } + } + } + } +} + +int number_of_digits(long long n) +{ + int count = 0; + while (n != 0) + { + // n = n/10 + n /= 10; + ++count; + } + return count; +} + +void check_license(int license, int adv_license, int bMacMatch, time_t start_time, time_t end_time, char* filename) +{ + pthread_mutex_lock(&mutex_check_license); + //printf("\n[check_license] start\n"); + //printf("\n[check_license] filename:%s\n", filename); + + //memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); + + //#ifdef GY_OS_WIN + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *s_root, *tlt_code; + s_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (s_root) { + tlt_code = cJSON_GetObjectItem(s_root, "TLT code"); //trial launch time + //cJSON* virtual_mac = cJSON_GetObjectItem(s_root, "VM code"); //virtual MAC + + //ѽXWɶ - step 1:base64 decode + size_t base64_decode_length = 0; + char EncryptKeyData[256]; + char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + base64_decode(tlt_code->valuestring, strlen(tlt_code->valuestring), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //ѽXWɶ - step 2:AES descrytion + KeyExpansion(key, expandedKey); + AESDecryptArrayToArray(EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); + + //oWɶXT + time_t last_launch_time = atoll(DecryptKeyData); + + //ˬdPWɶO_T + time_t now_time = g_osdSysTimeStamp; + + if (now_time < 1000000000) { + now_time = time(0); + } + + while (number_of_digits(last_launch_time) > number_of_digits(now_time)) { + last_launch_time /= 10; + } + + char strLaunchTime[16] = { 0 }; +#ifdef GY_OS_WIN + snprintf(strLaunchTime, sizeof(strLaunchTime), "%I64d", now_time); +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //onlldAldA|D + snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); +#endif + //printf("\nstrLaunchTime:%s", strLaunchTime); +//#endif + + /*{ + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&now_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nnow_time:%s", buff); + } + { + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&start_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nstart_time:%s", buff); + } + { + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&end_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nend_time:%s", buff); + } + { + char buff[20]; + struct tm * timeinfo; + timeinfo = localtime(&last_launch_time); + strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); + printf("\nlast_launch_time:%s", buff); + }*/ + + //printf("\n--------------license:%d\n", license); + + if (license == 0 && check_if_fe_fail == 0) + { + licenseType = _NO_LICENSE; + afsCode = _NOT_LICENSED; + strcpy(strLicenseStatus, "Invalid license"); + printf("\n[check_license] Invalid license:%d\n", licenseType); + } + else if (check_if_fe_fail == 1 || license == _PERMANENT_LICENSE_MULTI || license == _PERMANENT_LICENSE_SINGLE || license == _PERMANENT_LICENSE_MULTI_POST || license == _PERMANENT_LICENSE_SINGLE_POST || + license == _LICENSE_FPS06 || license == _LICENSE_FPS12 || license == _LICENSE_FPS18 || license == _LICENSE_FPS24 || license == _LICENSE_FPS30 || + license == _LICENSE_FPS36 || license == _LICENSE_FPS42 || license == _LICENSE_FPS48 || license == _LICENSE_FPS54 || license == _LICENSE_FPS60) + { + + switch (license) + { + case _PERMANENT_LICENSE_MULTI: + licenseType = _PERMANENT_LICENSE_MULTI; + http_license_fps = 60; + break; + case _PERMANENT_LICENSE_SINGLE: + licenseType = _PERMANENT_LICENSE_SINGLE; + break; + case _PERMANENT_LICENSE_MULTI_POST: + licenseType = _PERMANENT_LICENSE_MULTI_POST; + break; + case _PERMANENT_LICENSE_SINGLE_POST: + licenseType = _PERMANENT_LICENSE_SINGLE_POST; + break; + case _LICENSE_FPS06: + licenseType = _LICENSE_FPS06; + http_license_fps = 6; + break; + case _LICENSE_FPS12: + licenseType = _LICENSE_FPS12; + http_license_fps = 12; + break; + case _LICENSE_FPS18: + licenseType = _LICENSE_FPS18; + http_license_fps = 18; + break; + case _LICENSE_FPS24: + licenseType = _LICENSE_FPS24; + http_license_fps = 24; + break; + case _LICENSE_FPS30: + licenseType = _LICENSE_FPS30; + http_license_fps = 30; + break; + case _LICENSE_FPS36: + licenseType = _LICENSE_FPS36; + http_license_fps = 36; + break; + case _LICENSE_FPS42: + licenseType = _LICENSE_FPS42; + http_license_fps = 42; + break; + case _LICENSE_FPS48: + licenseType = _LICENSE_FPS48; + http_license_fps = 48; + break; + case _LICENSE_FPS54: + licenseType = _LICENSE_FPS54; + http_license_fps = 54; + break; + case _LICENSE_FPS60: + licenseType = _LICENSE_FPS60; + http_license_fps = 60; + break; + default: + licenseType = _LICENSE_FPS06; + http_license_fps = 6; + } + + switch (adv_license) + { + case _AD_LICENSE_BASIC: + advLicenseType = _AD_LICENSE_BASIC; + break; + case _AD_LICENSE_01: + advLicenseType = _AD_LICENSE_01; + break; + default: + advLicenseType = _AD_LICENSE_BASIC; + } + + if (!bMacMatch) + { + afsCode = _MAC_MISMATCH; + strcpy(strLicenseStatus, "License mismatch the system ID"); + } + else + { + afsCode = _LICENSED; + strcpy(strLicenseStatus, "Licensed."); + } + } + else if (license == _TRIAL_LICENSE_MULTI || license == _TRIAL_LICENSE_SINGLE || + license == _TRIAL_LICENSE_FPS06 || license == _TRIAL_LICENSE_FPS12 || license == _TRIAL_LICENSE_FPS18 || license == _TRIAL_LICENSE_FPS24 || license == _TRIAL_LICENSE_FPS30 || + license == _TRIAL_LICENSE_FPS36 || license == _TRIAL_LICENSE_FPS42 || license == _TRIAL_LICENSE_FPS48 || license == _TRIAL_LICENSE_FPS54 || license == _TRIAL_LICENSE_FPS60) + { + + switch (license) + { + case _TRIAL_LICENSE_MULTI: + licenseType = _TRIAL_LICENSE_MULTI; + http_license_fps = 60; + break; + case _TRIAL_LICENSE_SINGLE: + licenseType = _TRIAL_LICENSE_SINGLE; + break; + case _TRIAL_LICENSE_FPS06: + licenseType = _TRIAL_LICENSE_FPS06; + http_license_fps = 6; + break; + case _TRIAL_LICENSE_FPS12: + licenseType = _TRIAL_LICENSE_FPS12; + http_license_fps = 12; + break; + case _TRIAL_LICENSE_FPS18: + licenseType = _TRIAL_LICENSE_FPS18; + http_license_fps = 18; + break; + case _TRIAL_LICENSE_FPS24: + licenseType = _TRIAL_LICENSE_FPS24; + http_license_fps = 24; + break; + case _TRIAL_LICENSE_FPS30: + licenseType = _TRIAL_LICENSE_FPS30; + http_license_fps = 30; + break; + case _TRIAL_LICENSE_FPS36: + licenseType = _TRIAL_LICENSE_FPS36; + http_license_fps = 36; + break; + case _TRIAL_LICENSE_FPS42: + licenseType = _TRIAL_LICENSE_FPS42; + http_license_fps = 42; + break; + case _TRIAL_LICENSE_FPS48: + licenseType = _TRIAL_LICENSE_FPS48; + http_license_fps = 48; + break; + case _TRIAL_LICENSE_FPS54: + licenseType = _TRIAL_LICENSE_FPS54; + http_license_fps = 54; + break; + case _TRIAL_LICENSE_FPS60: + licenseType = _TRIAL_LICENSE_FPS60; + http_license_fps = 60; + break; + default: + licenseType = _TRIAL_LICENSE_FPS06; + http_license_fps = 6; + } + + switch (adv_license) + { + case _AD_LICENSE_BASIC: + advLicenseType = _AD_LICENSE_BASIC; + break; + case _AD_LICENSE_01: + advLicenseType = _AD_LICENSE_01; + break; + default: + advLicenseType = _AD_LICENSE_BASIC; + } + + if (!bMacMatch) + { + afsCode = _MAC_MISMATCH; + strcpy(strLicenseStatus, "Trial mismatch the system ID"); + } + else if (now_time < start_time-3600*24) + { + afsCode = _UNINITIALIZED; + strcpy(strLicenseStatus, "Trial has expired. Trial not initialized."); //Trial not initialized + } + else if (last_launch_time- 3600 * 24 > now_time) //Yeɶj󥻦ɶ, ܨtήɶQקL + { + printf("\n------------------[Incorrect system time detected]-------------------\n"); + char msg_temp[512] = { 0 }; + printf("\nlast_launch_time: %lld , now_time: %lld\n", (long long int)last_launch_time, (long long int)now_time); + sprintf(msg_temp,"last_launch_time: %lld , now_time: %lld", (long long int)last_launch_time, (long long int)now_time); + afsCode = _EXPIRED; + strcpy(strLicenseStatus, "Trial has expired. Incorrect system time detected."); + strcat(strLicenseStatus, msg_temp); + now_time = last_launch_time; + } + else if (now_time > end_time+3600*24) + { + afsCode = _EXPIRED; + strcpy(strLicenseStatus, "Trial has expired"); + } + else + { + afsCode = _LICENSED; + char Msg[256] = { 0 }; + double diffDays = difftime(end_time, now_time) / (60 * 60 * 24); + if (diffDays < 0) + diffDays = 0; + snprintf(Msg, sizeof(Msg), "Licensed(%d days left)", (int)diffDays); + strcpy(strLicenseStatus, Msg); + } + } + + //#ifdef GY_OS_WIN + //Nɶ[K, gJɮ + if (!(last_launch_time > now_time)) + { + //printf("\n[check_license] write file\n"); + KeyExpansion(key, expandedKey); + unsigned char EncryptData[1 * 1024]; + memset(EncryptData, 0x00, sizeof(EncryptData)); + int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); + + size_t base64_encode_length = 0; + char launchTime[1024] = { 0 }; + base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); + *(launchTime + base64_encode_length) = '\0'; + + cJSON_ReplaceItemInObject(s_root, "TLT code", cJSON_CreateString(launchTime)); + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(filename, "w"); + if (f == NULL) + { + printf("---------------------------Error opening setting file!-----------------------------\n"); +#if 1 + stop_test_nn_cavalry("Error opening setting file!"); + //stop_server(); + +#endif + //exit(EXIT_FAILURE); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + //#endif + + stAMBAcontent.licenseType = licenseType; + stAMBAcontent.afsCode = afsCode; + stAMBAcontent.advLicenseType = advLicenseType; + + //printf("\n-------strLicenseStatus:%s\n", strLicenseStatus); + + //printf("\n[check_license] licenseType:%d %d %d\n", licenseType, afsCode,advLicenseType); + } + } + + pthread_mutex_unlock(&mutex_check_license); +} + +void SetDatasetCategory(int licenseType, char* strDatasetCategory) +{ + switch (licenseType) + { + case _PERMANENT_LICENSE_MULTI: + case _LICENSE_FPS06: + case _LICENSE_FPS12: + case _LICENSE_FPS18: + case _LICENSE_FPS24: + case _LICENSE_FPS30: + case _LICENSE_FPS36: + case _LICENSE_FPS42: + case _LICENSE_FPS48: + case _LICENSE_FPS54: + case _LICENSE_FPS60: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _PERMANENT_LICENSE_SINGLE: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _TRIAL_LICENSE_MULTI: + case _TRIAL_LICENSE_FPS06: + case _TRIAL_LICENSE_FPS12: + case _TRIAL_LICENSE_FPS18: + case _TRIAL_LICENSE_FPS24: + case _TRIAL_LICENSE_FPS30: + case _TRIAL_LICENSE_FPS36: + case _TRIAL_LICENSE_FPS42: + case _TRIAL_LICENSE_FPS48: + case _TRIAL_LICENSE_FPS54: + case _TRIAL_LICENSE_FPS60: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _TRIAL_LICENSE_SINGLE: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _PERMANENT_LICENSE_MULTI_POST: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + case _PERMANENT_LICENSE_SINGLE_POST: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + break; + default: + sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI + } +} + +void check_feature() +{ + char strDatasetCategory[MAX_MSG_LEN] = { 0 }; + char *strDatasetCountry = NULL; + memset(strLicenseType, 0x00, sizeof(strLicenseType)); + int nHasFeature = 0; + + if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && + g_IsRadarDevice == 0 && + g_IsToFDevice == 0 && + unlockingKeyInnoFR_success == 0) { + if (!IsExistingWeight(featureType, featureType2)) { + sprintf(strLicenseType, " Weight Error:"); + } + } + + if (g_match_mac == 1 || unlockingKeyInnoFR == 1) { + + if (g_IsHelm_without_car == 1) { + + } + else { + + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA)) + { +#ifdef GY_OS_NOVA + sprintf(strDatasetCategory, "%s", "EDGEFENCE (Home Security)");//01AI +#endif +#ifdef GY_OS_AMBA + sprintf(strDatasetCategory, "%s", "EDGEFLOW (Home Security)");//01AI +#endif + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) + { +#ifdef GY_OS_NOVA + sprintf(strDatasetCategory, "%s", "EDGEDENSITY (Flow Counter)");//03AI +#endif +#ifdef GY_OS_AMBA + sprintf(strDatasetCategory, "%s", "EDGECAP (Flow Counter)");//03AI +#endif + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + } + + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0){ + sprintf(strDatasetCategory, "%s", "EDGEGARBAGE (Garbage Recognition)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) + { + sprintf(strDatasetCategory, "%s", "EDGERAIL (Rail Security)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) + { + sprintf(strDatasetCategory, "%s", "EDGESPORTS (Sports Recognition)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) + { + sprintf(strDatasetCategory, "%s", "EDGEFIRE (Environment Safety)");//05AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) + { + sprintf(strDatasetCategory, "%s", "EDGEAERO (Aero Recognition)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + //printf("\nFEATURE_HUM_DET---6\n"); + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + { + sprintf(strDatasetCategory, "%s", "EDGESAFTY (Construction Site Safety)");//04AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + //printf("\nFEATURE_HUM_DET---7\n"); + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + sprintf(strDatasetCategory, "%s", "EDGEMASK (Health Care)");//02AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + else { + sprintf(strDatasetCategory, "%s", "EDGEGENDER (Human gender)");//02AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + sprintf(strDatasetCategory, "%s", "EDGEVESSEL (Vessel Recognition)");//08AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + + sprintf(strDatasetCategory, "%s", "EDGEPRODUCTION (Production Line)"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + sprintf(strDatasetCategory, "%s", "EDGEANIMAL (Animal Recognition)");//09AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + else { + sprintf(strDatasetCategory, "%s", "EDGEFRONTBACK (Car Front & Back)");//09AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + } + + //printf("\nFEATURE_HUM_DET---8\n"); + if ((featureType & FEATURE_POK_DET) != 0) + { + sprintf(strDatasetCategory, "%s", "Poker pattern recognition"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_HUM_POS) != 0) + { + sprintf(strDatasetCategory, "%s", "Human pose estimator"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LED_DGT) != 0) + { + sprintf(strDatasetCategory, "%s", "LED digits recognition"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_SHOES_DET) != 0) + { + sprintf(strDatasetCategory, "%s", "Shoes recognition"); + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_LOGO) != 0) + { + sprintf(strDatasetCategory, "%s", "EDGECARMAKE (Car Make)");//07AI + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_TWN) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "TW/EC (Taiwan, Ecuador)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_EUR) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "EU (Belgium, Italy, Croatia, France, Turkey, Germany, Spain, Portugal, Slovenia)"; //European //EU/UK/IN + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_SEA) != 0 || + (featureType & FEATURE_LPR_VNM) != 0 || + (featureType & FEATURE_LPR_IDN) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "MY/HK/SG/VN/ID (Malaysia, Hong Kong, Singapore, Vietnam, Indonesia)";//South East Asia + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + /* + if ((featureType & FEATURE_LPR_CNA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "China"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + }*/ + if ((featureType & FEATURE_LPR_MEA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "AE/SA (UAE, Saudi Arabia)";//Middle East Asia + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_USA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "US/CA (50 states, Guam, Canada)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_AUS) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "AU (Australia)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_GBR) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "GB/IN (UK, India)"; //UK/IN //United Kingdom + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_JPN) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "JP (Japan)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + + if ((featureType & FEATURE_LPR_THA) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "TH (Thailand)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + }/* + if ((featureType & FEATURE_LPR_LAO) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "Laos"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + }*/ + if ((featureType & FEATURE_LPR_BGD) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "BD (Bangladesh)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + if ((featureType & FEATURE_LPR_PHL) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "PH (Philippines)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if ((featureType & FEATURE_LPR_CNT) != 0) + { + SetDatasetCategory(licenseType, strDatasetCategory); + strDatasetCountry = "CNT (Container)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, "-"); + strcat(strLicenseType, strDatasetCountry); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (td_weight_num >= 1 && check_if_correct_mail == 1) { + char *strDatasetCategory = "Third Party"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (g_IsRadarDevice == 1) { + char *strDatasetCategory = "EDGERADAR (Radar Recognition)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (g_IsToFDevice == 1) + { + char *strDatasetCategory = "EDGETOF (ToF Recognition)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + nHasFeature = 1; + } + + if (unlockingKeyInnoFR_success == 1) { + char *strDatasetCategory = "EDGEFACE (Face Recognition)"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + //printf("setting License Type : EDGEFACE (Face Recognition)\n"); + //printf("srtLicenseType = %s\n", strLicenseType); + + nHasFeature = 1; + } + + if (!nHasFeature) + { + char *strDatasetCategory = "No license"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + } + //printf("srtLicenseType = %s\n", strLicenseType); + //printf("featureType = %d\n", featureType); + //printf("featureType2 = %d\n", featureType2); + } + else{ + char *strDatasetCategory = "Mac address is not supported"; + strcat(strLicenseType, " "); + strcat(strLicenseType, strDatasetCategory); + strcat(strLicenseType, ","); + } +} + +//void stop_detector() +//{ +// bHttpServerThreadStart = 0; +//} + +//20201027 sophia add +/* +command: +/usr/local/bin/nvclient -k user.password0 +/usr/local/bin/nvclient -k user.account0 +... +/usr/local/bin/nvclient -k user.password9 +/usr/local/bin/nvclient -k user.account9 + +return : +NVRAM Client, Version:1.0.0 +Get nvram data, ret:0 +Key=user.account0 +Data=admin +TStamp=172 +Max data size=32 +*/ + +//#if defined GY_OS_AMBA + +void get_image_dn() { + + { + if (imageDnData.color_mode == 1) { + imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; + imageDnData.current_day_or_night_mode = 1; + + for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { + imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; + } + if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { + imageDnData.check_if_switch_happened[0] = 1; + usSleep(2500000); + } + else { + imageDnData.check_if_switch_happened[0] = 0; + } + } + else if (imageDnData.color_mode == 2) { + imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; + imageDnData.current_day_or_night_mode = 2; + + for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { + imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; + } + if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { + imageDnData.check_if_switch_happened[0] = 1; + usSleep(2500000); + } + else { + imageDnData.check_if_switch_happened[0] = 0; + } + } + + //printf("\n-----------imageDnData.check_if_switch_happened[0]:%d\n", imageDnData.check_if_switch_happened[0]); + } +} + +int get_check_if_existing_any_switch_happened() { + int rtn = 0; + for (int i = 0; i < MAX_SIZE_SWITCH_HAPPENED; i++) { + if (imageDnData.check_if_switch_happened[i] == 1) { + rtn = 1; + break; + } + } + return rtn; +} + +//#endif + +//20201027 sophia add +void update_config_account_setting(void) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + + //post events setting + //char filename[] = "config.json"; + char* filename; + filename = configPATH; + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + } + else { + //printf("read config.json.\n"); + +#if 1 + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* root, *account_setting; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } +#if 1 + account_setting = cJSON_GetObjectItem(root, "account_setting"); + if (root) { + //printf("config.json parse OK.1\n"); + cJSON* account_data_array, *content; + cJSON* account_username, *account_password, *account_type, *account_status; + account_data_array = cJSON_CreateArray(); + +#if 1 + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) + { + content = cJSON_CreateObject(); + cJSON_AddItemToArray(account_data_array, content); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[i].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[i].account_password, (unsigned char *)buf_account2); + + account_username = cJSON_CreateString(buf_account); + cJSON_AddItemToObject(content, "account_username", account_username); + account_password = cJSON_CreateString(buf_account2); + cJSON_AddItemToObject(content, "account_password", account_password); + account_type = cJSON_CreateNumber(accountData[i].account_type); + cJSON_AddItemToObject(content, "account_type", account_type); + account_status = cJSON_CreateNumber(accountData[i].account_status); + cJSON_AddItemToObject(content, "account_status", account_status); + + } + usSleep(2000); + size_t base64_encode_length = 0; + unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + + char* AccountJsonString = cJSON_Print(account_data_array); + //printf("\n--------------AccountJsonString: %s\n", AccountJsonString); + + KeyExpansion(key, expandedKey); + size_t encryptSize = AESEncryptArrayToArray(AccountJsonString, strlen(AccountJsonString), expandedKey, EncryptKeyData, sizeof(EncryptKeyData)); + + char ResultEncryptData[MAX_ACCOUNT_DATA_BUFF_SIZE] = { 0 }; + base64_encode(EncryptKeyData, encryptSize, &base64_encode_length, ResultEncryptData); + *(ResultEncryptData + base64_encode_length) = '\0'; + + usSleep(2000); + + cJSON_ReplaceItemInObject(account_setting, "account_data", cJSON_CreateString((const char *)ResultEncryptData)); + + if (AccountJsonString) { + free(AccountJsonString); + AccountJsonString = NULL; + } + + //save back to config.json & bak + char* JsonString = cJSON_Print(root); + FILE* fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + //copy config.json to config_bak.json + CopyFileTo(filename, config_bakPATH); + } + else + { + //fclose(fp); + printf("Fail to open Config.json \n"); + } +#endif + if (root) { + //cJSON_Delete(root); + cJSON_Delete(root); + root = NULL; + } +#if 1 + + if (account_data_array != NULL) { + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) + { + cJSON_DeleteItemFromArray(account_data_array,i); + } + cJSON_free(account_data_array); + account_data_array = NULL; + } +#endif +#if 1 + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } +#endif + usSleep(2000); + } + else + printf("config.json parse FAIL.1\n"); +#endif + } +#endif + } +} + +void update_accountData() { + int count_username = 0; +#ifdef GY_OS_AMBA + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 4; i++) +#else + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 5; i++) +#endif + { + if (i == MAX_ACCOUNT_DATA_NUM) + count_username = 0; + + FILE *fp = NULL; + char path[1024] = { 0 }; + char command[1024] = { 0 }; + const char *find = "Data="; + int find_len = 5; + + memset(path, 0, sizeof(path)); + memset(command, 0, sizeof(command)); +#ifdef GY_OS_AMBA + if (i < MAX_ACCOUNT_DATA_NUM) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.account%d", i); + else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); + else if (i == MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.mirror"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.flip"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.rotate"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k FEATURE_SYS_DUAL_SENSOR"); +#else + if (i < MAX_ACCOUNT_DATA_NUM) + sprintf(command, "/usr/local/bin/nvclient -k user.account%d", i); + else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "/usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); + else if (i == MAX_ACCOUNT_DATA_NUM * 2) + sprintf(command, "/usr/local/bin/nvclient -k image.mirror"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) + sprintf(command, "/usr/local/bin/nvclient -k image.flip"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) + sprintf(command, "/usr/local/bin/nvclient -k image.rotate"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) + sprintf(command, "/usr/local/bin/nvclient -k features.irled.type"); + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) + sprintf(command, "/usr/local/bin/nvclient -k features.irled2.type"); +#endif + + + +#ifdef _DEBUG_AMBA + printf("\n[read_ipcam_account_setting] i:%d - command:%s", i, command); +#endif + + /* Open the command for reading.*/ + fp = vpopen(command, "r"); + if (fp == NULL) { + fp = vpopen(command, "r"); + } + + if (fp == NULL) + { + + printf("\nFailed to run command: %s\n", command); + printf("Error opening file unexist.ent: %s\n", strerror(errno)); + + char fail_buffer[2048] = { 0 }; + sprintf(fail_buffer, "\nFailed to run command: %s\n", command); + write_to_log_if_error_nvclient(fail_buffer); + + //write_to_log_if_error(fail_buffer); + /* + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + }*/ + } + else { + /* Read the output a line at a time - output it.*/ + while (fgets(path, sizeof(path), fp) != NULL) + { + char *p = strstr(path, find); + int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n + //printf("\n(%d):cpylen:%d\n",i,cpy_len); + if (p != NULL && cpy_len >= 1) + { + char *cpy_start = p + find_len; + +#ifdef _DEBUG_AMBA + printf("\n%s strlen(path):%d", p + find_len, strlen(path)); +#endif + + if (cpy_len >= 1) { + char temp_cpy[100] = { 0 }; + strncpy(temp_cpy, cpy_start, cpy_len); + temp_cpy[cpy_len] = '\0'; + + if (i < MAX_ACCOUNT_DATA_NUM) { + if (strstr(temp_cpy, " ") == NULL) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account,512); + memcpy(accountData[count_username].account_username, temp_account, strlen(temp_account)); + accountData[count_username].account_username[strlen(temp_account)] = '\0'; + } + count_username++; + } + else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) { + if (strstr(temp_cpy, " ") == NULL) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account, 512); + memcpy(accountData[count_username].account_password, temp_account, strlen(temp_account)); + accountData[count_username].account_password[strlen(temp_account)] = '\0'; + } + count_username++; + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2) { + //if (g_IsPTZDevice == 0) + { + if (strstr(temp_cpy, " ") == NULL) { + strncpy(accountData[0].account_mirror, temp_cpy, cpy_len); + accountData[0].account_mirror[cpy_len] = '\0'; + } + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) { + //if (g_IsPTZDevice == 0) + { + if (strstr(temp_cpy, " ") == NULL) { + strncpy(accountData[0].account_flip, temp_cpy, cpy_len); + accountData[0].account_flip[cpy_len] = '\0'; + } + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) { + //if (g_IsPTZDevice == 0) + { + if (strstr(temp_cpy, " ") == NULL) { + strncpy(accountData[0].account_rotate, temp_cpy, cpy_len); + accountData[0].account_rotate[cpy_len] = '\0'; + } + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) { + //if (g_IsPTZDevice == 0) + if(strstr(temp_cpy,"1") != NULL) + { +#ifdef GY_OS_AMBA + g_dual_sensor = 1; +#else + g_camera_white_LED = 1; +#endif + } + } + else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) { + //if (g_IsPTZDevice == 0) + if (strstr(temp_cpy, "1") != NULL) + { + g_camera_white_LED = 1; + } + } + } + + break; + } + + memset(path, 0, sizeof(path)); + } + if (fp != NULL) { + if (vpclose(fp) < 0) + printf("\nupdate accountData: vpclose fail\n"); + fp = NULL; + } + } + + usSleep(1000); + } +} + +void update_accountData_port() { + char read_port_cmd[1024]; + memset(&read_port_cmd, 0, sizeof(read_port_cmd)); + +#ifdef GY_OS_AMBA + char read_port_cmd_1[256] = "timeout 3s /usr/local/bin/nvclient -k http.port"; +#else + char read_port_cmd_1[256] = "/usr/local/bin/nvclient -k http.port"; +#endif + strcat(read_port_cmd, read_port_cmd_1); + + FILE *read_port = vpopen(read_port_cmd, "r"); + if (read_port == NULL) + { + printf("\n[read_ipcam_account_setting]:Error to read port"); + } + else + { + const char *find = "Data="; + int find_len = 5; + char path[1024] = { 0 }; + + /* Read the output a line at a time - output it.*/ + while (fgets(path, sizeof(path), read_port) != NULL) + { + char *p = strstr(path, find); + int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n + + if (p != NULL && cpy_len > 0) + { + char *cpy_start = p + find_len; + + if (cpy_len >= 1) { + strncpy(accountData[0].account_port, cpy_start, cpy_len); + accountData[0].account_port[cpy_len] = '\0'; + } + + //printf("\n[read_ipcam_account_setting]:Correct to read port %s\n",accountData[0].account_port); + break; + } + memset(path, 0, sizeof(path)); + } + if (read_port != NULL) + vpclose(read_port); + + } +} + +void accountData_written_to_events_json() { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char eventsPATH[1024] = { 0 }; + strcpy(eventsPATH, exePath); + + strcat(eventsPATH, "events.json"); + + char *filename_events; + filename_events = eventsPATH; + if (!FileExist(filename_events)) + { + printf("%s doesn't exist.\n", filename_events); + } + else { + //size_t nfileSize_events = ReadFileSize(filename_events); + char *fileBuf_events = ReadAllBytes(filename_events); + if (fileBuf_events) { + //printf("\n[read_ipcam_account_setting]\n"); + //printf("\nfileBuf_events: %s\n", fileBuf_events); + cJSON *root, *notification, *http_post_events, *http_post; + root = cJSON_Parse(fileBuf_events); + if (fileBuf_events) { + free(fileBuf_events); + fileBuf_events = NULL; + } + + if (root == NULL) + { + printf("root is NULL\n"); + + int del = remove(filename_events); + if (!del) { + //printf("events.json is deleted successfully."); + } + else { + printf("events.json cannot be deleted.\n"); + } +#if 1 + stop_test_nn_cavalry("events json not exist"); + //stop_server(); + +#endif + pthread_exit(NULL); + } + else + { + notification = cJSON_GetObjectItem(root, "notification"); + { + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + + int i = 0; + cJSON_ArrayForEach(http_post, http_post_events) + { + if (i <= 3) { + if (strlen(accountData[0].account_port) >= 1) + cJSON_ReplaceItemInObject(http_post, "post_host_port", cJSON_CreateString(accountData[0].account_port)); + if (strlen(accountData[0].account_username) >= 1) { + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + cJSON_ReplaceItemInObject(http_post, "post_username", cJSON_CreateString(buf_account)); + } + if (strlen(accountData[0].account_password) >= 1) { + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + cJSON_ReplaceItemInObject(http_post, "post_password", cJSON_CreateString(buf_account2)); + } + } + else + break; + + i++; + } + } + + char *filename = eventsPATH; + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open events.json \n"); + } + + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } +} + +static char events_port[512] = { 0 }; +static char events_username[512] = {0}; +static char events_password[512] = { 0 }; +void get_current_events_json_data() { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char eventsPATH[1024] = { 0 }; + char events_bakPATH[1024] = { 0 }; + + strcpy(eventsPATH, exePath); + strcat(eventsPATH, "events.json"); + + strcpy(events_bakPATH, exePath); + strcat(events_bakPATH, "events_bak.json"); + + char *filename_events; + filename_events = eventsPATH; + if (!FileExist(filename_events)) + { + printf("%s doesn't exist.\n", filename_events); + } + else { + //size_t nfileSize_events = ReadFileSize(filename_events); + char *fileBuf_events = ReadAllBytes(filename_events); + if (fileBuf_events) { + //printf("\n[read_ipcam_account_setting]\n"); + //printf("\nfileBuf_events: %s\n", fileBuf_events); + cJSON *root, *notification, *http_post_events, *http_post, *post_host_port, *post_username, *post_password; + root = cJSON_Parse(fileBuf_events); + if (fileBuf_events) { + free(fileBuf_events); + fileBuf_events = NULL; + } + + if (root == NULL) + { + printf("root is NULL\n"); + + int del = remove(filename_events); + if (!del) { + //printf("events.json is deleted successfully."); + } + else { + printf("events.json cannot be deleted.\n"); + } + + if (FileExist(events_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(events_bakPATH, eventsPATH); + } + else { +#if 1 + stop_test_nn_cavalry("events_bak json not exist"); + //stop_server(); +#endif + } + pthread_exit(NULL); + } + else + { + notification = cJSON_GetObjectItem(root, "notification"); + { + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + + int i = 0; + cJSON_ArrayForEach(http_post, http_post_events) + { + + post_host_port = cJSON_GetObjectItem(http_post, "post_host_port"); + post_username = cJSON_GetObjectItem(http_post, "post_username"); + post_password = cJSON_GetObjectItem(http_post, "post_password"); + + strcpy(events_port, post_host_port->valuestring); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(events_username, temp_account, strlen(temp_account)); + events_username[strlen(temp_account)] = '\0'; + + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(events_password, temp_account2, strlen(temp_account2)); + events_password[strlen(temp_account2)] = '\0'; + + //strcpy(events_username, post_username->valuestring); + //strcpy(events_password, post_password->valuestring); + + break; + i++; + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } +} + +/*void *run_osd_time_sync_thread() { + pthread_detach(pthread_self()); + setPthreadName("run_osd_time"); + //update_system_time(); + //int count_delay = 0; + int count_post = 0; + + while (bHttpServerThreadStart) + { + //if (count_delay >= 10) + { + //count_delay = 0; + //update_system_time(); + } + //else + { + //count_delay++; + g_osdSysTimeStamp++; + } + +#if 1 + if (count_post >= 14400) { + count_post = 0; + if (check_if_correct_post == 1) { + if (check_if_run_post == 1) { + + } + else if(check_if_run_post == 0){ + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "There is cloud post error existing for 4 hours. Reboot the camera to restart gynet."); + write_to_logs_html(temp_msg, "run osd time sync thread", "CGI_REBOOT", "Yes"); + //printf("\n-----------------------There is no post for 4 hours.: exit-----------------------\n"); + write_to_log_if_error(temp_msg, "run osd time sync thread", "CGI_REBOOT"); + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + } + else { + if (check_if_run_post != 0) { + count_post = 0; + } + + count_post++; + } +#endif + + usSleep(1000000); + } + + pthread_exit(NULL); +}*/ +#ifdef GY_OS_AMBA +#define SHELLSCRIPT "sh /emmc/plugin/Aida_data/run_osd_server.sh" +#define SHELLSCRIPT_TOF_DRIVER "sh /emmc/plugin/Aida_data/run_tof_driver.sh" + + +void *run_osd_server_thread(void* ptr) { + pthread_detach(pthread_self()); + setPthreadName("osd_server"); + if (strcmp(SystemSetting.enable_display_OSD, "Yes")==0 /*&& strcmp(SystemSetting.enable_cloud,"Yes")==0*/) { + pthread_t auto_system_thread_id; + if (pthread_create(&auto_system_thread_id, 0, auto_system, NULL)) + { + printf("\ncreate auto system thread faile \n"); + } + pthread_join(auto_system_thread_id, NULL); + //usSleep(2000000); + + g_check_if_OK_to_start_osd_server = 1; + + pthread_mutex_lock(&mutex_run_osd); + close_udp_socket(); + init_udp_socket(); + pthread_mutex_unlock(&mutex_run_osd); + + usSleep(2000000); + char cmd_1[256] = "killall -15 osd_server"; + + FILE *read_port = vpopen(cmd_1, "r"); + if (read_port != NULL) + vpclose(read_port); + + usSleep(2000000); + + g_check_if_OK_to_start_osd_server = 0; +#if 1 + system(SHELLSCRIPT); +#endif + +#if 0 + char cmd_2[256] = "/emmc/plugin/Aida_data/osd_server server"; + + read_port = vpopen(cmd_2, "r"); + if (read_port != NULL) + vpclose(read_port); +#endif + usSleep(2000000); + } + else{ + g_check_if_OK_to_start_osd_server = 1; + close_udp_socket(); + + usSleep(2000000); + + char cmd_2[256] = "killall -15 osd_server"; + FILE *read_port = vpopen(cmd_2, "r"); + if (read_port != NULL) + vpclose(read_port); + + usSleep(2000000); + g_check_if_OK_to_start_osd_server = 0; + } + + pthread_exit(NULL); +} +#endif +struct timeval currtime_read_ipcam_account_setting_thread; +static long last_ms_currtime_read_ipcam_account_setting_thread = 0; +void *read_ipcam_account_setting_thread(void* ptr) { + pthread_detach(pthread_self()); + setPthreadName("read_ipcam"); + + //printf("\n----------read ipcam account setting thread start\n"); + + gettimeofday(&currtime_read_ipcam_account_setting_thread, NULL); + long current_ms_currtime_read_ipcam_account_setting_thread = (currtime_read_ipcam_account_setting_thread.tv_sec * 1000) + (currtime_read_ipcam_account_setting_thread.tv_usec / 1000); + + + if (last_ms_currtime_read_ipcam_account_setting_thread == 0 || current_ms_currtime_read_ipcam_account_setting_thread - last_ms_currtime_read_ipcam_account_setting_thread >= 5000) { + + if (g_control_read_ipcam == 0) { + + pthread_mutex_lock(&mutex_read_ipcam); + g_control_read_ipcam = 1; + + get_current_events_json_data(); + + /*while (bHttpServerThreadStart)*/ { + read_ipcam_account_setting(); + //usSleep(READ_IPCAM_SETTING*1000); + } + + + int get_OK = 0; + char temp_device_name[512] = { 0 }; + get_OK = PNS_Get_Device_Name(1, temp_device_name); + //int len_device = 0; + if (get_OK >= 1) { + url_decode(temp_device_name,strlen(temp_device_name)); + strcpy(g_device_name, temp_device_name); + } + g_control_read_ipcam = 0; + pthread_mutex_unlock(&mutex_read_ipcam); + + } + + last_ms_currtime_read_ipcam_account_setting_thread = current_ms_currtime_read_ipcam_account_setting_thread; + } + + //printf("\n----------read ipcam account setting thread end\n"); + + pthread_exit(NULL); +} + +int g_start_update_config = 0; +void read_ipcam_account_setting() +{ + + update_accountData(); + update_accountData_port(); + + if (g_start_update_config == 0) { + update_config_account_setting(); + g_start_update_config = 1; + } + if (strlen(accountData[0].account_port) >= 1 && strlen(accountData[0].account_username) >= 1 && + strlen(events_port) >= 1 && strlen(events_username) >= 1) + { + if (strcmp(accountData[0].account_port, events_port) != 0 || + strcmp(accountData[0].account_username, events_username) != 0 || + strcmp(accountData[0].account_password, events_password) != 0) + { + if (g_start_update_config == 1) { + update_config_account_setting(); + } + accountData_written_to_events_json(); + for (int i = 0; i < 4; i++) { + strcpy(postEventList[i].post_host_port, accountData[0].account_port); + strcpy(postEventList[i].post_username, accountData[0].account_username); + strcpy(postEventList[i].post_password, accountData[0].account_password); + } + get_current_events_json_data(); + } + } +#if 0 + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\naccountData[0].account_mirror: %s\n", accountData[0].account_mirror); + printf("\naccountData[0].account_flip: %s\n", accountData[0].account_flip); + printf("\naccountData[0].account_rotate: %s\n", accountData[0].account_rotate); + printf("\naccountData[0].account_port: %s\n", accountData[0].account_port); + printf("\naccountData[0].account_username: %s\n", accountData[0].account_username); + printf("\naccountData[0].account_password: %s\n", accountData[0].account_password); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); +#endif +} + +int external_memory_fragmentation_management() { + + FILE * pPipe = NULL; + char cmd[256] = { 0 }; + int size_psBuffer = 256; + char psBuffer[256] = { 0 }; + + int chunk_number = -1; + + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s echo 1 > /proc/sys/vm/compact_memory"); +#else + sprintf(cmd, "echo 1 > /proc/sys/vm/compact_memory"); +#endif + + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) + { + + } + else { + printf("\nFail: external memory fragmentation management #1\n"); + } + if (pPipe != NULL) + vpclose(pPipe); + + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); +#else + sprintf(cmd, "cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); +#endif + + + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) + { + //printf("Run: external memory fragmetation\n"); + char* temp; + memset(psBuffer, 0x00, sizeof(psBuffer)); + temp = fgets(psBuffer, size_psBuffer, pPipe); + if (temp != NULL) { + chunk_number = atoi(psBuffer); + printf("\n[buddyinfo] chunk_number:%d\n", chunk_number); + } + } + else { + printf("\nFail: external memory fragmentation management #2\n"); + } + if (pPipe != NULL) + vpclose(pPipe); + + return chunk_number; +} + +// 2020.11.23 Sophia added. +// 2021.05.12 Cayman modified returned values. +extern char* strptime_c(const char* buf, const char* fmt, struct tm* tm); +int reload_dataset_from_jsonfile(void) +{ + time_t start_time = 0; + time_t now_time = 0; + now_time = (time_t)time(0); + + struct tm *localnowTime = localtime(&now_time); + int diffSecs = 0; + if (cgi_whenTime_buff != NULL && cgi_startTime_buff != NULL) { + memcpy(cgi_whenTime_buff, localnowTime, sizeof(struct tm)); + diffSecs = cgi_whenTime_buff->tm_sec - cgi_startTime_buff->tm_sec; + } + + if (abs(diffSecs) < 2) + return 1; + + start_time = time(0); + cgi_reload_start_Time = localtime(&start_time); + + if (cgi_startTime_buff != NULL) { + memcpy(cgi_startTime_buff, cgi_reload_start_Time, sizeof(struct tm)); + } + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + char *filename_event; + filename_event = eventsPATH; + + if (!FileExist(filename_event)) + { + printf("%s doesn't exist.\n", filename_event); + return 1; + } + size_t nfileSize_event = ReadFileSize(filename_event); + printf("nfileSize_event:%ld\n", (long int)nfileSize_event); + char *fileBuf_event = ReadAllBytes(filename_event); + if (fileBuf_event == NULL) { + printf("fileBuf_event is NULL\n"); + return 1; + } + + cJSON /* *n_root,*/ *notification, *events_default_version,*enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, + *post_customized_header; + cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr,*enable_check_ptz_start_autotracking, + *enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + //n_root = cJSON_Parse(fileBuf_event); + cJSON *root; + root = cJSON_Parse(fileBuf_event); + if (fileBuf_event) { + free(fileBuf_event); + fileBuf_event = NULL; + } + + if (root == NULL) + { + printf("root is NULL\n"); + return 1; + } + notification = cJSON_GetObjectItem(root, "notification"); + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + + if (events_default_version) { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + } + else { + strcpy(heartbeatData.events_default_version, "1"); + } + + if (enable_post) + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + else + activeSNMPPost = _FALSE; + if (enable_heartbeat) { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + } + else { + strcpy(heartbeatData.enable_heartbeat, "No"); + } + + if (enable_snmp_heartbeat) { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + } + else { + strcpy(heartbeatData.enable_snmp_heartbeat, "No"); + } + + if (snmp_heartbeat_dwell) { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + } + else { + strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); + } + + if (snmp_heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); + } + + if (enable_check_ptz_start_autotracking) { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + } + else { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); + } + + if (enable_check_ptz_end_autotracking) { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + } + else { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); + } + + if (enable_only_once_to_post) { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + } + else { + strcpy(heartbeatData.enable_only_once_to_post, "Yes"); + } + + if (enable_obj_once_to_post) { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + } + else { + strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); + } + + if (enable_location_once_to_post) { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + } + else { + strcpy(heartbeatData.enable_location_once_to_post, "Yes"); + } + + if (enable_nvr_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + } + else { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); + } + + if (enable_8592_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + } + else { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); + } + + if (dwell_to_the_same_location) { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + } + else { + strcpy(heartbeatData.dwell_to_the_same_location, "5"); + } + + if (heartbeat_dwell) { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + } + else { + strcpy(heartbeatData.heartbeat_dwell, "10"); + } + + if (heatmap_max) { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + } + else { + strcpy(heartbeatData.heatmap_max, "100"); + } + + if (enable_heatmap) { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + } + else { + strcpy(heartbeatData.enable_heatmap, "No"); + } + + if (heatmap_frequency) { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + } + else { + strcpy(heartbeatData.heatmap_frequency, "5"); + } + + if (lpr_title) { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + } + else { + strcpy(heartbeatData.lpr_title, "My Car Park"); + } + + if (heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); + } + + if (ptz_start_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); + } + + if (ptz_end_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + } + else { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); + } + + if (enable_counter_snap) { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + } + else { + strcpy(heartbeatData.enable_counter_snap, "No"); + } + + if (enable_barcode_qr) { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + } + else { + strcpy(heartbeatData.enable_barcode_qr, "No"); + } + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + strcpy(postEventList[i].post_protocol, post_protocol->valuestring); + strcpy(postEventList[i].post_event_method, post_event_method->valuestring); + strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); + strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); + strcpy(postEventList[i].post_host_port, post_host_port->valuestring); + strcpy(postEventList[i].post_url, post_url->valuestring); + //strcpy(postEventList[i].post_username, post_username->valuestring); + //strcpy(postEventList[i].post_password, post_password->valuestring); + strcpy(postEventList[i].post_content, post_content->valuestring); + strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); + + if (post_sequence) + strcpy(postEventList[i].post_sequence, post_sequence->valuestring); + else { + strcpy(postEventList[i].post_sequence, ""); + } + + if (post_timeout) + strcpy(postEventList[i].post_timeout, post_timeout->valuestring); + else { + strcpy(postEventList[i].post_timeout, "5"); + } + + if(post_file_format) + strcpy(postEventList[i].post_file_format, post_file_format->valuestring); + else { + strcpy(postEventList[i].post_file_format, "text"); + } + + if(post_jpeg_file_name_format) + strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); + } + + if(post_jpeg_file_name) + strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name, "snap"); + } + i++; + } + +#ifdef GY_OS_V_SERIES + cJSON *counter_name; +#else + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; + cJSON *link_to_post_event_name, *post_interval; + + event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + + i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + strcpy(eventCounterList[i].counter_name, counter_name->valuestring); + strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); + strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); + + if (reset_value) + eventCounterList[i].reset_value = atoi(reset_value->valuestring); + else + eventCounterList[i].reset_value = 0; + strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_at, reset_at->valuestring); + strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); + strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); + strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); + struct tm tm; + strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); +#if 0 + eventCounterList[i].timetResetAt = mktime(&tm); + + struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); + eventCounterList[i].reset_month = resetTime->tm_mon; + eventCounterList[i].reset_month_day = resetTime->tm_mday; + eventCounterList[i].reset_week_day = resetTime->tm_wday; + eventCounterList[i].reset_hour = resetTime->tm_hour; + eventCounterList[i].reset_min = resetTime->tm_min; + eventCounterList[i].reset_sec = resetTime->tm_sec; +#endif + strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeFrom = mktime(&tm); + strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeTo = mktime(&tm); + + if (link_to_post_event_name) { + strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); + } + else { + strcpy(eventCounterList[i].link_to_post_event_name, ""); + } + + if (post_interval) { + strcpy(eventCounterList[i].post_interval, post_interval->valuestring); + } + else { + strcpy(eventCounterList[i].post_interval, "5 minutes"); + } + + if (enable_reset_only_cloud) { + strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + } + else { + strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); + } + + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + } + else { + strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); + } + + i++; + } + + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, + *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + if (report_counters) { + i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + if (counter_a) { + strcpy(reportCounterList[i].counter_a, counter_a->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a, "Counter01"); + } + + if (counter_a_name) { + strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_name, "Name"); + } + + if (counter_a_zone) { + strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_zone, "1"); + } + + if (counter_b) { + strcpy(reportCounterList[i].counter_b, counter_b->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b, ""); + } + + if (counter_b_name) { + strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_name, ""); + } + + if (counter_b_zone) { + strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_zone, "0"); + } + + if (counter_c_name) { + strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_c_name, ""); + } + + if (report_max_value) { + strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); + } + else { + strcpy(reportCounterList[i].report_max_value, "100"); + } + + if (enable_report) { + strcpy(reportCounterList[i].enable_report, enable_report->valuestring); + } + else { + strcpy(reportCounterList[i].enable_report, "No"); + } + + if (counter_mode) { + strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); + } + else { + strcpy(reportCounterList[i].counter_mode, "0"); + } + + if (initial_icon) { + strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); + } + else { + strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); + } + + if (detection_output) { + strcpy(reportCounterList[i].detection_output, detection_output->valuestring); + } + else { + strcpy(reportCounterList[i].detection_output, "No entry for cars"); + } + + if (output_icon) { + strcpy(reportCounterList[i].output_icon, output_icon->valuestring); + } + else { + strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); + } + + i++; + } + } + + if (i < MAX_REPORT_COUNTERS) { + for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + } + } + else { + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + } + + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + if (snmp_management) { + i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + if (snmp_event_name) { + strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); + } + else { + char temp_name[20] = { 0 }; + sprintf(temp_name,"SNMP %d",i+1); + strcpy(SNMPManagementList[i].snmp_event_name, temp_name); + } + + if (snmp_version) { + strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_version, "v1"); + } + + if (snmp_group_name) { + strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_group_name, "public"); + } + + if (snmp_host_ip) { + strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); + } + + if (snmp_host_port) { + strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_port, "161"); + } + + if (snmp_oid) { + strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + } + + if (snmp_value) { + strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_value, "mylocation"); + } + + if (snmp_type) { + strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_type, "string"); + } + + i++; + } + } + + if (i < MAX_SNMP_MANAGEMENT) { + for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + } + } + } + else { + for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + } + } +#endif + + +#if 0 + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } +#endif + + cJSON *email_setting,*email_content; + email_setting = cJSON_GetObjectItem(root, "email_setting"); + if (email_setting) { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) + strcpy(emailData.email_content, email_content->valuestring); + else + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + else { + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + + //trigger events settings + char *filename_config; + filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + return 1; + } + + size_t nfileSize_config = ReadFileSize(filename_config); + printf("nfileSize_config:%ld\n", (long int)nfileSize_config); + char *fileBuf_config = ReadAllBytes(filename_config); + + if (fileBuf_config == NULL) { + printf("fileBuf_config is NULL\n"); + return 1; + } + + //cJSON* cam_ip, * http_port, * video_port, * cam_username, * cam_pwd, * channel_id; + cJSON* view_setting, * camera, * camera_name, * enable_anpr, *enable_face, * enable_traffic, * enable_logo, * tab_view_size, * enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, + *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking, *ptz_tracking_mode, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, + *cJSON_enable_only_show_metadata1,*count_zone, *ivs_mode, * detection_zone, * detect, + *levenshtein_distance, *obj_min_proportion, *obj_max_proportion,*min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, + *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute,*queuing_count, *ptz_zone_to_preset,*trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, + *point_number, + *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6, + *enable_speed,*set_distance,*world_distance_unit,*world_distance_side1,*world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, + *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion,*confidence_unknown_object, *confidence2_unknown_object,*dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, + *plate_filter_times,*plate_filter_time,*plate_free_time,*obj_max_proportion_in_zone,*obj_min_proportion_in_zone,*red_light_zone,*no_give_way_zone_to_protect,*no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2, + *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed; + + //cJSON* root = cJSON_Parse(fileBuf_config); + //printf("\n-----------------reload: %s\n", fileBuf_config); + + if (g_config_root == NULL) { + g_config_root = cJSON_Parse(fileBuf_config); + if (fileBuf_config) { + free(fileBuf_config); + fileBuf_config = NULL; + } + if (g_config_root == NULL) + { + printf("root is NULL\n"); + return 1; + } + } + view_setting = cJSON_GetObjectItem(g_config_root, "view_setting"); + + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + /*cam_ip = cJSON_GetObjectItem(camera, "ip"); + http_port = cJSON_GetObjectItem(camera, "http_port"); + video_port = cJSON_GetObjectItem(camera, "video_port"); + cam_username = cJSON_GetObjectItem(camera, "username"); + cam_pwd = cJSON_GetObjectItem(camera, "password"); + channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + + plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); + plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); + plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); + + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); //None SΨ + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); //None SΨ + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + + if (plate_filter_times) + viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); + else + viewChannelData[n].i_plate_filter_times = 4; + + if (plate_filter_time) + viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); + else + viewChannelData[n].i_plate_filter_time = 3; + + if (plate_free_time) + viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); + else + viewChannelData[n].i_plate_free_time = 3; + + strcpy(viewChannelData[n].confidence, confidence->valuestring); + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + //printf("\nenable_lpr_db-----6\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + pthread_mutex_unlock(&mutex_enable_lpr_db); + + enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); + set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); + + enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); + set_enable_zone_crop_1(enable_zone_crop_1->valueint); + + viewChannelData[n].count_zone = count_zone->valueint; + + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + //printf("\n[reload_dataset_from_jsonfile]tab_view_size: %s\n", tab_view_size->valuestring); + + char temp_array[256] = { 0 }; + strcpy(temp_array, tab_view_size->valuestring); + + char outArray[2][STRSPLIT_SIZE] = {0}; + StrSplit(temp_array, outArray, "x"); + //printf("\n------UU:15\n"); + viewChannelData[n].channel_idx = n; + if (outArray[0]) + viewChannelData[n].tab_view_width = atoi(outArray[0]); + if (outArray[1]) + viewChannelData[n].tab_view_height = atoi(outArray[1]); + + //printf("\n[reload_dataset_from_jsonfile]end:tab_view_size: %s\n", tab_view_size->valuestring); + + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + if (strcmp(enable_face->valuestring, "Yes") == 0) + viewChannelData[n].enable_face = 1; + else + viewChannelData[n].enable_face = 0; + + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + + enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); + if (enable_add_face_frequent_list) + if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) + viewChannelData[n].enable_add_face_frequent_list = 1; + else + viewChannelData[n].enable_add_face_frequent_list = 0; + else { + viewChannelData[n].enable_add_face_frequent_list = 0; + } + + enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); + strcpy(viewChannelData[n].enable_PTZ ,enable_PTZ->valuestring); + + ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); + strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); + + ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); + strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); + + ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); + strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); + + //Tracking MODE + //1: First in First out + //2: Bigger first + //3: All + ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); + if (ptz_tracking_mode) + viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); + else + { + viewChannelData[n].ptz_tracking_mode = 1; + } + + ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); + if (ptz_tracking_by_enter_zone) { + if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + else + viewChannelData[n].ptz_tracking_by_enter_zone = 0; + } + else { + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + } + + enable_track = cJSON_GetObjectItem(camera, "enable_track"); + if (enable_track) + strcpy(viewChannelData[n].enable_track, enable_track->valuestring); + else { + strcpy(viewChannelData[n].enable_track, "No"); + } + + enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); + if (enable_tracking_limits) + strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); + else { + strcpy(viewChannelData[n].enable_tracking_limits, "No"); + } + + ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); + if (ptz_pan_left_limit) + strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); + } + + ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); + if (ptz_pan_right_limit) + strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); + } + + ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); + if (ptz_tilt_up_limit) + strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); + } + + ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); + if (ptz_tilt_down_limit) + strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); + } + + ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); + if (ptz_speed) + strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); + else { + strcpy(viewChannelData[n].ptz_speed, "3"); + } + + enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); + if (enable_unknown_object) + strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_unknown_object, "No"); + } + + enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); + if (enable_ivs_person_detection) + strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); + } + + assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); + if (assign_ivs_object_to) + strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); + else { + strcpy(viewChannelData[n].assign_ivs_object_to, ""); + } + + enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); + if (enable_ambulance) + strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); + else { + strcpy(viewChannelData[n].enable_ambulance, "No"); + } + + enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); + if (enable_blank_plate) + strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); + else { + strcpy(viewChannelData[n].enable_blank_plate, "No"); + } + + enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); + if (enable_stop_sign) + strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); + else { + strcpy(viewChannelData[n].enable_stop_sign, "No"); + } + + enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); + if (enable_show_unknown_object) + strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_show_unknown_object, "No"); + } + + enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); + if (enable_ivs_fix_mode) + strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); + } + + enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); + if (enable_ivs_and_ai) + strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); + } + + enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); + if (enable_lpr_upon_triggered) + strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); + } + + dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); + if (dwell_lpr_upon_triggered) + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); + } + + unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); + if(unknown_object_max_proportion) + strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); + else + strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); + + unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); + if (unknown_object_min_proportion) + strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); + else + strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); + + confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); + if (confidence_unknown_object) + strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); + else + strcpy(viewChannelData[n].confidence_unknown_object, "0"); + + confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); + if (confidence2_unknown_object) + strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); + else + strcpy(viewChannelData[n].confidence2_unknown_object, "0"); + + dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); + if(dwell_unknown_object) + strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); + else + strcpy(viewChannelData[n].dwell_unknown_object, "30"); + + dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); + if (dwell_minute_focus_on) + strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); + else + strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); + + + person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); + if (person_obj_fov) + strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); + else + strcpy(viewChannelData[n].person_obj_fov, "100"); + + + ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); + if (ivs_mode) + strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); + else + strcpy(viewChannelData[n].ivs_mode, "3"); + + getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); + if (getnetwork_buffer_id) { + if (strlen(viewChannelData[n].getnetwork_buffer_id)>=1 && strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) { +#ifdef GY_OS_AMBA + printf("\n-----------------------get network buffer id: exit-----------------------\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); + write_to_logs_html(temp_msg, "reload dataset", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "reload dataset", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } +#else + +#endif + } + } + else + strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); + + red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); + if (red_light_zone) + strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); + else + strcpy(viewChannelData[n].red_light_zone, ""); + + no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); + if (no_give_way_zone_to_protect) + strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); + + no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); + if (no_give_way_zone_to_keep_away) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); + + no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); + if (no_give_way_zone_to_protect_2) + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); + + no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); + if (no_give_way_zone_to_keep_away_2) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); + else + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); + + ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); + if (ptz_sensitivity) + viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); + else + { + viewChannelData[n].ptz_sensitivity = 6; + } + //printf("\n-------------ptz_sensitivity:%d\n", viewChannelData[n].ptz_sensitivity); + + ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); + + cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); + enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; + + detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + + viewChannelData[n].enable_traffic_light_zone = 0; + + int i = 0; + cJSON_ArrayForEach(detect, detection_zone) + { + obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); + obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); + + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + + enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); + enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); + enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); + world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); + + ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); + + trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); + + point_number = cJSON_GetObjectItem(detect, "point_number"); + + parking_space = cJSON_GetObjectItem(detect, "parking_space"); + parking_line = cJSON_GetObjectItem(detect, "parking_line"); + + //Social Distance + set_distance = cJSON_GetObjectItem(detect, "set_distance"); + world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); + world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); + world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); + //Social Distance + + /* + if(point_number) + printf("load point number = %d \n", point_number->valueint); +*/ + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + if(metadata_stop) + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + if (no_parking_time) + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + if (no_parking_time_in_minute) + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + if (queuing_count) + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + + if (parking_space) + { + viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); + } + + if (parking_line) + { + viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); + } + + //Social Distance + if (set_distance) + { + viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); + } + + if (world_distance_unit) + { + strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); + } + if (world_distance_side1) + { + viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); + viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); + } + + + //Fake data + //viewDetectionZone[n][i].world_distance[0] = 1000; + //viewDetectionZone[n][i].world_distance[2] = 1000; + + if (world_distance_side2) + { + viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); + viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); + } + //Social Distance + if(obj_max_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); + if(obj_min_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); + + if (point_number) + { + viewDetectionZone[n][i].point_num = point_number->valueint; + } + + if (enable_speed) + strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); + if (enable_radar_speed) + strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); + if (enable_ivs_zone) + strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); + if (world_time_unit) + strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); + + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].Points[3].y = y4->valueint; + + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + + if (x5 && x6) + { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].Points[5].y = y6->valueint; + + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + } + + + viewChannelData[n].tab_view_width_ratio = (float)1; + viewChannelData[n].tab_view_height_ratio = (float)1; + + viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); + viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); + + //viewChannelData[n].tab_view_height = 1; + + + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; + //UpdateTrafficLightZone(n); + } + +#ifdef GY_OS_AMBA + if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) + { + int social_zone_idx = i; + if (social_zone_idx >= 0) + { + pthread_mutex_lock(&mutex_perspective_transform); + if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); + viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); + pthread_mutex_unlock(&mutex_perspective_transform); + } + } +#endif + + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + //int arraySize = cJSON_GetArraySize(detection_zone); + int k = 0; + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + k = 0; + cJSON_ArrayForEach(detect, trigger_events[j]) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + } + } + + cJSON *system_setting,*enable_cloud,*enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*nms_thres, *tracking_id_dwell,*enable_person_independent,*enable_onvif_profile_m,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language,*display_properties,*display_OSD, + *enable_bounding_box,*enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror,*ai_mirror_feature,*enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content,*enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, + *enable_email_notification,*email_reset_time_interval,*enable_system_logs,*enable_email_jpeg,*display_dash,*sensors_type,*enable_ftp,*ftp_url,*ftp_port,*ftp_username,*ftp_password,*ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; + cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; + + system_setting = cJSON_GetObjectItem(g_config_root, "system_setting"); + + enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); + strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); + + enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); + strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); + + nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); + strcpy(SystemSetting.nms_thres, nms_thres->valuestring); + + tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); + strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); + + enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); + strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); + + enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); + strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); + + enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); + strcpy(SystemSetting.enable_python, enable_python->valuestring); + + enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); + strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); + + cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); + strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); + + cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); + strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); + + cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); + strcpy(SystemSetting.cloud_account, cloud_account->valuestring); + + cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); + strcpy(SystemSetting.cloud_password, cloud_password->valuestring); + + cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); + strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); + + cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); + strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); + + cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); + strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); + + cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); + strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); + + language = cJSON_GetObjectItem(system_setting, "language"); + strcpy(SystemSetting.language, language->valuestring); + + display_dash = cJSON_GetObjectItem(system_setting, "display dash"); + activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + + display_properties = cJSON_GetObjectItem(system_setting, "display properties"); + strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); + + display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); + strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); + + enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); + strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); + + enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); + strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); + + enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); + strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); + + force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); + strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); + + force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); + strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); + + enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); + strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); + + enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); + strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); + + ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); + strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); + + enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); + strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); + + cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); + strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); + + cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); + strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); + + enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); + strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); + + cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); + strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); + + cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); + strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); + + enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); + strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); + + enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); + strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); + + getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); + strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); + + getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); + strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); + + osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); + strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); + + osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); + strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); + + osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); + strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); + + enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); + strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); + + osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); + strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); + + osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); + strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); + + sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); + strcpy(SystemSetting.sensors_type, sensors_type->valuestring); + + enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); + strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); + + external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); + strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); + + external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); + strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); + + external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); + strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); + + external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); + strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); + + enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); + strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); + + enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); + strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); + + enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); + strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); + + email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); + strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); + + enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); + strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); + + ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); + strcpy(SystemSetting.ftp_url, ftp_url->valuestring); + + ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); + strcpy(SystemSetting.ftp_port, ftp_port->valuestring); + + ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); + strcpy(SystemSetting.ftp_username, ftp_username->valuestring); + + ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); + strcpy(SystemSetting.ftp_password, ftp_password->valuestring); + + ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); + strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); + + ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); + strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); + + ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); + strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); + + cJSON *about_box,*cJSON_strUnlockingKey; + about_box = cJSON_GetObjectItem(g_config_root, "about_box"); + if (about_box) { + cJSON_strUnlockingKey = cJSON_GetObjectItem(about_box, "unlocking key"); + if (cJSON_strUnlockingKey && strlen(cJSON_strUnlockingKey->valuestring)>=1 && strcmp(strUnlockingKey, cJSON_strUnlockingKey->valuestring)!=0) { + memset(strUnlockingKey,0x00,sizeof(strUnlockingKey)); + strcpy(strUnlockingKey, cJSON_strUnlockingKey->valuestring); + + char buf_exe[1024] = {}; + readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); + + char exePath_temp[1024] = {}; + getFilePath(buf_exe, exePath_temp, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath_temp); + strcat(keyPATH, "key.txt"); + if (FileExist(keyPATH) == 1) { + FILE *pFile; + + if ((pFile = fopen(keyPATH, "w")) != NULL) + { + fprintf(pFile, strUnlockingKey); + fclose(pFile); + + } + else + printf("Fail to open key.txt \n"); + } + + memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); + strcpy(strLicenseStatus, "Please restart gynet to run AI with new key."); + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + + if (g_config_root) { + cJSON_Delete(g_config_root); + g_config_root = NULL; + } +#ifdef GY_OS_AMBA + /*int zone_to_preset[MAX_DETECTION_ZONE]; + + for (int i = 0; i < MAX_DETECTION_ZONE; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, + viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + if (g_IsPTZDevice == 1) { + UpdatePTZConfigSetting(); + + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + } + +#endif + //Reload cold zone + /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); + +#ifdef GY_OS_AMBA + if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { + if (enable_ai_mirror && ai_mirror_feature) { + if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { + + if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 2"); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + else { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 0"); +#endif + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + } + } + } +#endif + + return 0; +} + +// 2021.01.21 Jim added. +// 2021.05.12 Cayman fixed returned values. +#if 0 +int default_dataset_for_jsonfile(void) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + + + char *filename; + //filename = config_bakPATH; + filename = configPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return 1; + } + + //printf("read config.json. %s\n", filename); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf == NULL) { + printf("fileBuf FAIL.\n"); + return 1; + } + + cJSON *root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (root) { + //printf("config.json parse OK.\n"); + } + else + { + printf("config.json parse FAIL.\n"); + return 1; + } + + cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(filename, config_bakPATH); + } + else + { + printf("Fail to open Config.json \n"); + return 1; + } + + //copy config.json to config_bak.json + + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + return 0; +} +#endif //GY_OS_AMBA + + +#ifdef GY_OS_AMBA +static long delete_now_heatmap = 0; +struct timeval delete_currtime_heatmap; +void delete_heatmap_image() { + gettimeofday(&delete_currtime_heatmap, NULL); + delete_now_heatmap = (delete_currtime_heatmap.tv_sec * 1000) + (delete_currtime_heatmap.tv_usec / 1000); //쬰@ + delete_now_heatmap = delete_now_heatmap / 1000 * 1000; + + pthread_mutex_lock(&mutex_heatmap_jpeg); + DIR *d_file; + struct dirent *dir_file; + d_file = opendir("/emmc/plugin/Aida_data/playback"); + if (d_file) { + while ((dir_file = readdir(d_file)) != NULL) { + if (strlen(dir_file->d_name) >= 17) { + char temp_d_name[50] = { 0 }; + for (int i = 0; i < strlen(dir_file->d_name)-4; i++) { + temp_d_name[i] = dir_file->d_name[i]; + } + + if (atol(temp_d_name) <= delete_now_heatmap - 15 * 24 * 60 * 60 * 1000 / 2) {//15/2=7.5 + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + //usSleep(10000); + + //printf("\n-------temp_d_name:%ld\n", atol(temp_d_name)); + } + } + closedir(d_file); + } + pthread_mutex_unlock(&mutex_heatmap_jpeg); + + //printf("\n-------delete_now_heatmap:%ld\n", delete_now_heatmap); +} +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void * delete_jpg_in_seven_days_detector(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("delete_seven"); + int check_delete = 0; + int delete_time = 1; + int delete_time2 = 7; + int delete_time3 = 13; + int delete_time4 = 19; + + delete_jpg_in_seven_days(); +#ifdef GY_OS_AMBA + delete_heatmap_image(); +#endif + + while (bHttpServerThreadStart) { + + //printf("\n------delete jpg in seven days detector start\n"); + + if (iFeature_lpr_layer_index >= 0) { + + time_t rawtime = time(0); + struct tm * timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + + if ((timeinfo->tm_hour == delete_time || + timeinfo->tm_hour == delete_time2 || + timeinfo->tm_hour == delete_time3 || + timeinfo->tm_hour == delete_time4) + && check_delete == 0) { + if (unlockingKeyInnoFR == 1) { +#ifdef GY_OS_AMBA + //delete_jpg_in_seven_days_face(); +#endif + } + else { + delete_jpg_in_seven_days(); + } +#ifdef GY_OS_AMBA + delete_heatmap_image(); +#endif + check_delete = 1; + } + else if (timeinfo->tm_hour != delete_time && timeinfo->tm_hour != delete_time2 && timeinfo->tm_hour != delete_time3 && timeinfo->tm_hour != delete_time4) { + check_delete = 0; + } + + //printf("\n------delete jpg in seven days detector end\n"); + + //usSleep(60000000); + usSleep(1000000); + } + else { + usSleep(10000000); + } + } + + //printf("\n---------delete jpg in seven days detector:exit\n"); + + pthread_exit(NULL); +} +#endif +//CURLM* g_multi_handle; +//int g_handle_count; + +//modified the input from file to memory based on test_detector() +#ifdef TEST_DETECTOR_MEM +void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, float thresh, float hier_thresh, int ext_output, int save_labels, char* model, char* target_device, int input_resizable, char* custom_cpu_library, char* custom_cldnn, int performance_counter, int IsHardwareOK) +{ + + //printf("\n[test detector mem]------------------------:1\n"); + //UTF8 trans.name table + char buff[MAX_MSG_LEN] = { 0 }; + //char strKeyValue[MAX_MSG_LEN] = { 0 }; // Assign ini file key value + char section[16] = { 0 }; + +#ifdef GY_OS_V_SERIES + +#else + for (int n = 0; n < MAX_LAYER_NUM; n++) + { + for (int i = 0; i < MAX_SECTION_VARIABLE; i++) + { + //if (section) + if (layerFeatureType[n] == FEATURE_LPR_MEA + || layerFeatureType[n] == FEATURE_LPR_SEA + || layerFeatureType[n] == FEATURE_LPR_VNM + || layerFeatureType[n] == FEATURE_LPR_IDN + || layerFeatureType[n] == FEATURE_LPR_USA + || layerFeatureType[n] == FEATURE_LPR_JPN + || layerFeatureType[n] == FEATURE_LPR_THA + || layerFeatureType[n] == FEATURE_LPR_LAO + || layerFeatureType[n] == FEATURE_LPR_BGD + || layerFeatureType[n] == FEATURE_LPR_TWN + || layerFeatureType[n] == FEATURE_LPR_EUR + ) + { + if (layerFeatureType[n] == FEATURE_LPR_MEA && layerFeatureType[n - 1] == FEATURE_LPR_MEA && n > 0) + strcpy(section, "[MEA]"); + if ((layerFeatureType[n] == FEATURE_LPR_SEA && layerFeatureType[n - 1] == FEATURE_LPR_SEA && n > 0) || + (layerFeatureType[n] == FEATURE_LPR_VNM && layerFeatureType[n - 1] == FEATURE_LPR_VNM && n > 0) || + (layerFeatureType[n] == FEATURE_LPR_IDN && layerFeatureType[n - 1] == FEATURE_LPR_IDN && n > 0)) + strcpy(section, "[SEA]"); + if (layerFeatureType[n] == FEATURE_LPR_USA && layerFeatureType[n - 1] == FEATURE_LPR_USA && n > 0) + strcpy(section, "[USA]"); + if (layerFeatureType[n] == FEATURE_LPR_JPN && layerFeatureType[n - 1] == FEATURE_LPR_JPN && n > 0) + strcpy(section, "[JPN]"); + if (layerFeatureType[n] == FEATURE_LPR_THA && layerFeatureType[n - 1] == FEATURE_LPR_THA && n > 0) + strcpy(section, "[THA]"); + if (layerFeatureType[n] == FEATURE_LPR_LAO && layerFeatureType[n - 1] == FEATURE_LPR_LAO && n > 0) + strcpy(section, "[LAO]"); + if (layerFeatureType[n] == FEATURE_LPR_BGD && layerFeatureType[n - 1] == FEATURE_LPR_BGD && n > 0) + strcpy(section, "[BGD]"); + if (layerFeatureType[n] == FEATURE_LPR_TWN && layerFeatureType[n - 1] == FEATURE_LPR_TWN && n > 0) + strcpy(section, "[TWN]"); + if (layerFeatureType[n] == FEATURE_LPR_EUR && layerFeatureType[n - 1] == FEATURE_LPR_EUR && n > 0) + strcpy(section, "[EUR]"); + + sprintf(buff, "%d", i); + char* value = GetIniKeyString(section, buff, INI_FILE_PATH); + if (value != NULL) { + if (strlen(value) > 0) { + strcpy(ppIniKeyValue[n][i], value); + } + else { + strcpy(ppIniKeyValue[n][i], ""); + } + } + else { + strcpy(ppIniKeyValue[n][i], ""); + } + } + else { + strcpy(ppIniKeyValue[n][i], ""); + } + } + } +#endif + +#ifdef GY_OS_AMBA + memset_snapshot_addr(); +#endif + //===================== + //sophia add 2020/09/24 + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif +// +//#ifdef GY_OS_WIN + // socketRecords[i].prev_frame_data = NULL; + /*if (socketRecords[i].prev_frame_data) + free(socketRecords[i].prev_frame_data);*/ +//#endif + socketRecords[i].used = 0; + + //socketRecord_ALM[i].sock = -1; + } + //printf("\nKKKKKKKKKKKKKKKK:3\n"); + + //for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + //{ + //socketRecord_ALM[i].sock = -1; + + /*socketRecord_ALM[i].head = NULL; + socketRecord_ALM[i].tail = NULL;*/ + //} + + mtrace(); + set_metadata(); + reset_onvif(); + initial_ivs(); + initial_g_PostRecorderList(); + check_if_is_existing_weight = 0; + + //===================== + // Create a HTTP thread + +#if 1 + //printf("\nKKKKKKKKKKKKKKKK:4\n"); + if (http_port > 0) + { + // HTTP server + //printf("\nKKKKKKKKKKKKKKKK:5\n"); + g_write_config_file_dirty_flag = 0; + protected_sqlite_fflpr_db_close = 1; +#if defined GY_OS_AMBA || defined GY_OS_NOVA + fflpr_log_db_init(); +#ifdef GY_OS_AMBA + if(unlockingKeyInnoFR == 1) + { + //face_log_db_init(); + } +#endif +#endif + isGYNetReady = TRUE; //Set GYNet is ready! + + //printf("\nKKKKKKKKKKKKKKKK:6\n"); + //run_serverLAOonA@A]nsg_IsPTZDeviceC + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed #1\n"); + } + pthread_join(thread_id_getipcamsettings, NULL); + + + + +#if 1 + //329Memory not freed `IȬ| + if (pthread_create(&http_thread, 0, run_http_server_thread, 0)) + error("HTTP server thread creation failed\n"); + +#endif + + //printf("\nKKKKKKKKKKKKKKKK:8\n"); + //printf("\n[test detector mem]------------------------:2\n"); + +#ifdef GY_OS_AMBA +#if 0 + if ( g_IsToFDevice == 1) + { + // إ߰O@ɰ + long data_size = sizeof(frameimage) + sizeof(rbuf_t); + tof_depth_shmid = Initial_ShareMemory(data_size, 888); + if (tof_depth_shmid == -1) { + perror("Create shared memory failed !\n"); + } + else { + // lƽwİ + ringbuf_init(&tof_ring_buffer); + + bTofDataStart = 1; + + if (pthread_create(&gettofdata_thread, 0, thread_getTofData, 0)) + error("thread gettofdata creation failed\n"); + } + } +#endif +#endif + +#ifdef GY_OS_AMBA + if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { + + if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { + if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 2"); +#endif + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + else { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); +#else + sprintf(cmd, "/usr/local/bin/test_vin -m 0"); +#endif + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + } + } +#endif + + //printf("\nKKKKKKKKKKKKKKKK:7\n"); + int check_if_setting_general_mode = 1; + if (g_IsPTZDevice == 0) + { + if (strcmp(accountData[0].account_flip, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0 || + strcmp(accountData[0].account_rotate, "1") == 0) + { + check_if_setting_general_mode = 0; + } + } + else if (g_IsPTZDevice == 1) + { + if (strcmp(accountData[0].account_rotate, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0) + { + check_if_setting_general_mode = 0; + } + } + +#if 1 + //Fdelete_jpg_in_seven_days_detectorS}AXp10,878,464byte1983ӰO鬪|(`:u@zoneABoutputu]w@ӵJݡAdwell time6) + //Fdelete_jpg_in_seven_days_detectorMrun_post_notification_threadAAS}AXp11,276,800byte1978ӰO鬪| + //Fdelete_jpg_in_seven_days_detectorMrun_post_notification_threadS}AXp11,232,112byte1467ӰO鬪|Aj1983-1467=516ӰO鬪|Orun_post_notification_thready + //Fdelete_jpg_in_seven_days_detectorS}AXp10,891,264byte1500ӰO鬪|(ɤO:u@zoneAoutput]w|ӵJݡAdwell time6) + //Fdelete_jpg_in_seven_days_detectorS}AXp11,190,784byte1568ӰO鬪|(|zoneɤO:4zoneABCoutput]w|ӵJݡAdwell time6) + //Fdelete_jpg_in_seven_days_detectorS}AXp11,518,976byte1992ӰO鬪|(|zoneɤO:4zoneABCoutput]w|ӵJݡAdwell time1) + //Fdelete_jpg_in_seven_days_detectorS}AXp11,319,296byte1697ӰO鬪|(|zoneɤO:4zoneABCoutput8ӳ}Adwell time1)//諸IPA|vTO鬪| + + bHttpServerThreadStart = 1; + + if (pthread_create(&post_notification_thread, 0, run_post_notification_thread, NULL)) + error("Post notification thread creation failed\n"); +#endif + +#ifdef GY_OS_NOVA + if (pthread_create(&resolution_changed_thread, 0, auto_resolution_changed, NULL)) + error("resolution changed thread failed\n"); +#else + if (get_run_check_current_resolution() == -1) { + set_run_check_current_resolution(0); + if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) + error("check current resolution thread failed\n"); + } +#endif + + if (IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1) + { + // printf("\n[test detector mem] IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1)\n"); + check_if_is_existing_weight = 1; + bHttpServerThreadStart = 1; + + /* + if (g_IsToFDevice == 1) { + system(SHELLSCRIPT_TOF_DRIVER); + }*/ +#if 1 + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + { + printf("\n[gynet] g_IsRadarDevice || g_IsToFDevice\n"); + if (pthread_create(&getimage_thread, 0, thread_getimage, 0)) + error("thread getimage creation failed\n"); +#ifdef GY_OS_AMBA + if (pthread_create(&getimage_hd_thread, 0, thread_getimage_hd, 0)) + error("thread getimage creation failed\n"); +#endif + } + +#endif +#ifdef GY_OS_AMBA +#if 0 + if (g_IsRadarDevice == 1) + { + if (pthread_create(&render_radar_thread, 0, thread_render_radar_img, 0)) + error("thread render_radar creation failed\n"); + + if (g_IsRadarFake == 1) + { + if (pthread_create(&radar_reciever_id, NULL, RADAR_recieve, (void *)&radar_json_data) < 0) + error("RADAR_recieve creation failed\n"); + } + else + { + if (pthread_create(&getstream_thread, 0, thread_getstream, 0)) + error("thread getimage creation failed\n"); + + if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0)) + error("thread radar parser creation failed\n"); + } + } +#endif + // unlockingKeyInnoFR_success = faceengine_start_and_check_license(); + // unlockingKeyInnoFR_success = 1; +#if 0 + if (unlockingKeyInnoFR_success == 1) { +#ifdef GY_OS_AMBA + faceengine_start(); +#endif + } +#endif +#if 0 + //ثePfaceengine + if(unlockingKeyInnoFR_success == 1){ +#ifdef GY_OS_AMBA + if (pthread_create(&get_face_websocket_thread, 0, thread_get_face_websocket, 0)) + error("thread get_face_websocket creation failed\n"); + if (pthread_create(&parse_face_thread, 0, thread_parse_face, 0)) + error("thread parse_face creation failed\n"); +#endif + } +#endif + +#endif + + //printf("\nKKKKKKKKKKKKKKKK:9\n"); + +#if 1 + //test_nn_main & run_send_udp_thread & run_getalarmmotion_thread output.log 8,532,480byte -> 1167ӰO鬪| j1167-1072=95ӰO鬪|Orun_getalarmmotion_thready + if (pthread_create(&getalarmmotion_thread, 0, run_getalarmmotion_thread, NULL)) + error("Getalarmmotion thread creation failed\n"); +#endif + +#ifdef GY_OS_V_SERIES + +#else + //329Memory not freed `IȬ| + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { +#if 1 + ////쥻W٬Ocheck_http_socket_threadA{b令run_event_counter_thread + if (pthread_create(&counter_thread, 0, run_event_counter_thread, NULL)) + error("check http socket thread creation failed\n"); +#endif + } +#endif + +#ifdef GY_OS_V_SERIES + +#else +#if 1 + //329Memory not freed `IȬ| + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (pthread_create(&delete_jpg_in_seven_days_detector_thread_id, 0, delete_jpg_in_seven_days_detector, NULL)) + printf("create delete_jpg_in_seven_days_detector thread faile \n"); + } +#endif +#endif + //printf("\nKKKKKKKKKKKKKKKK:10\n"); + // UDP thread to send getalarmotion +#if 1 + //test_nn_main & run_send_udp_thread output.log 8,579,969byte -> 1072ӰO鬪| j1072-875=197ӰO鬪|Orun_send_udp_thready + if (pthread_create(&send_udp_thread, 0, run_send_udp_thread, NULL)) + error("check http socket thread creation failed\n"); +#endif + +#ifdef GY_OS_AMBA + //**oٷ|O鬪| + //output.log 8,392,192byte ->934ӰO鬪| output.logWTܦ40,000byte + //}start_all_nets 105,984byte->343ӰO鬪| IȬ|@II `OK + //}while (live_mode_flag) 119,808byte->337ӰO鬪| IȬ|@II `OK + //if (g_IsRadarDevice == 0) + { +#if 1 + if (pthread_create(&test_nnctrl_live_thread, 0, test_nn_main, &stAMBAcontent)) + error("Test nnctrl live thread creation failed\n"); +#endif + } +#endif + +#ifdef GY_OS_NOVA + if (pthread_create(&test_nnctrl_live_thread, 0, nnctrl_main, &stAMBAcontent)) + error("Test nnctrl live thread creation failed\n"); +#endif + +#if 1 + //329Memory not freed `IȬ| + //Get CPU/VPU loading & AI FPS + if (pthread_create(&fps_loading_thread, 0, run_fps_loading_thread, NULL)) + error("fps loading thread creation failed\n"); +#endif +#ifdef GY_OS_AMBA +#if 1 + //OSD server إ + if (pthread_create(&thread_id_run_osd_server, 0, run_osd_server_thread, NULL)) { + printf("\nrun osd server thread creation failed\n"); + } +#endif +#endif + +#ifdef GY_OS_NOVA + if (pthread_create(&thread_id_get_nova_driver, 0, thread_get_nova_driver, 0)) + error("thread get nova driver creation failed\n"); +#endif + + //System time sync + //if (pthread_create(&thread_id_run_system_time_sync, 0, run_osd_time_sync_thread, NULL)) { + //printf("\nrun osd server thread creation failed\n"); + //} + } + else + bHttpServerThreadStart = 1; + + //printf("\nKKKKKKKKKKKKKKKK:12\n"); + //printf("\n[test_detector_mem] &stAMBAcontent:%x\n", &stAMBAcontent); + //printf("\n[test_detector_mem] stAMBAcontent.licenseType:%d\n", stAMBAcontent.licenseType); + RefreshCheckExistingWeight(); + int count_timeout = 0; + while (bHttpServerThreadStart) + { + if (AI_fps >= 1) + break; + else if (count_timeout >= 30) //count_timeout 100|S + { + printf("\n[Error]: Not Ready to run test_nn_main\n"); + break; + } + count_timeout++; + usSleep(1000000); + } + } + +#endif + + //muntrace(); + + //o|vTCPUįSleepӧC// + + while (bHttpServerThreadStart) + { + //printf("while bHttpServerThreadStart :%d\n", bHttpServerThreadStart); +#if defined GY_OS_NOVA + usSleep(3600000000);//3600000000 +#else + usSleep(1500000); +#endif + } + ////////////////////᭱i|Sfree + + printf("\n------------test detector mem:1\n"); + + +#if 0 + for (int n = 0; n < MAX_LAYER_NUM; n++) + { + if (layer_count > 0) + { + if (tcp_port > 0) + free_ptrs((void**)names[n], nets[n].layers[nets[n].n - 1].classes); + else if (http_port > 0) + free_ptrs((void**)names[n], http_nets[n].layers[http_nets[n].n - 1].classes); +#ifdef GY_OS_WIN + if (tcp_port > 0) + free_network(nets[n]); + + if (http_port > 0) + free_network(http_nets[n]); +#endif + //free_list_contents_kvp(options[n]); + free_list(options[n]); + } + } +#endif + + //free_ptrs(pPosInfo, element_size); + printf("\n------------test detector mem:2\n"); + + /* + if (alphabet != NULL) //20201015 sophia add + { + const int nsize = 8; + for (int j = 0; j < nsize; ++j) + { + for (int i = 32; i < 127; ++i) + { + free_image(alphabet[j][i]); + } + if (alphabet[j]) { + free(alphabet[j]); + alphabet[j] = NULL; + } + } + if (alphabet) { + free(alphabet); + alphabet = NULL; + } + }*/ + + printf("\n[test detector mem] end\n"); + + stop_server(); +} +#endif + +void stop_btHttpServer() { + // share_memory_stop(); +#if 0 + bTofDataStart = 0; +#endif + + bHttpServerThreadStart = 0; + bHttpServerMainStart = 0; + //printf("\n----------stop_btHttpServer:%d\n",1); + if (cgi_startTime_buff) { + free(cgi_startTime_buff); + cgi_startTime_buff = NULL; + } + if (cgi_whenTime_buff) { + free(cgi_whenTime_buff); + cgi_whenTime_buff = NULL; + } + //printf("\n----------stop_btHttpServer:%d\n", 2); +#ifdef GY_OS_AMBA + //if (g_IsPTZDevice == 1) { + //Free_PTZ_g_curl_connect(); + //} +#endif + //printf("\n----------stop_btHttpServer:%d\n", 3); + curl_global_cleanup(); + //printf("\n----------stop_btHttpServer:%d\n", 4); + base64_cleanup(); + //printf("\n----------stop_btHttpServer:%d\n", 5); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sqlite_fflpr_db_close(); +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR == 1) { + //sqlite_face_db_close(); + } +#endif +#endif + //printf("\n----------stop_btHttpServer:%d\n", 6); + //printf("Stop btHttpServer - finished. \n"); +} + +int get_bHttpServerThreadStart() { + return bHttpServerThreadStart; +} + +void stop_server() +{ + printf("Stop Server - started.\n"); + //pthread_mutex_lock(&mutex_run_one_net); + //bHttpServerThreadStart = 0; + //bHttpServerMainStart = 0; + //pthread_mutex_unlock(&mutex_run_one_net); + + stop_btHttpServer(); + //printf("\n----------stop server 1\n"); +#if 1 +#ifdef GY_OS_AMBA + StopPTZupdateStatusThread(); +#endif + //printf("\n----------stop server 2\n"); +//#ifdef GY_OS_AMBA + + //close 4 threads + //http server - run_http_server_thread() + //post notification - run_post_notification_thread() + //run event counter thread - run_event_counter_thread() + //test nnctrl live - test_nn_main() + +//#endif //GY_OS_AMBA +#endif + printf("Stop Server - finished. \n"); +#if 0 +#ifdef GY_OS_AMBA + if (http_port > 0) { + if (check_if_is_existing_weight == 1) { + printf("\n---------------pthread join:1\n"); + pthread_join(http_thread, NULL); + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + { + printf("\n---------------pthread join:1.1\n"); + pthread_join(getimage_thread, NULL); +#ifdef GY_OS_AMBA + pthread_join(getimage_hd_thread, NULL); + pthread_join(gettofdata_thread, NULL); +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + printf("\n---------------pthread join:1.2\n"); + pthread_join(delete_jpg_in_seven_days_detector_thread_id, NULL); +#endif + } + + printf("\n---------------pthread join:1.3\n"); + +#ifdef GY_OS_AMBA + if (g_IsRadarDevice == 1) + { + pthread_join(render_radar_thread, NULL); + printf("\n---------------pthread join:1.4\n"); + if (g_IsRadarFake == 1) + { + pthread_join(radar_reciever_id, NULL); + } + else + { + pthread_join(getstream_thread, NULL); + printf("\n---------------pthread join:1.5\n"); + pthread_join(radar_parser_thread, NULL); + } + } + if(unlockingKeyInnoFR_success == 1) + { +#ifdef GY_OS_AMBA + pthread_join(get_face_websocket_thread, NULL); + + pthread_join(parse_face_thread, NULL); +#endif + } +#endif +#ifdef GY_OS_NOVA + pthread_join(http_thread_parse_json_data, NULL); +#endif + printf("\n---------------pthread join:2\n"); + pthread_join(post_notification_thread, NULL); + printf("\n---------------pthread join:3\n"); + pthread_join(getalarmmotion_thread, NULL); + printf("\n---------------pthread join:4\n"); + + pthread_join(resolution_changed_thread, NULL); + +#ifdef GY_OS_V_SERIES + +#else + pthread_join(counter_thread, NULL); +#endif + printf("\n---------------pthread join:5\n"); + pthread_join(send_udp_thread, NULL); + printf("\n---------------pthread join:6\n"); + pthread_join(test_nnctrl_live_thread, NULL); + printf("\n---------------pthread join:7\n"); + pthread_join(fps_loading_thread, NULL); + printf("\n---------------pthread join:8\n"); + +#ifdef GY_OS_AMBA + pthread_join(thread_id_run_osd_server, NULL); +#endif + //pthread_join(thread_id_run_system_time_sync, NULL); +#ifdef GY_OS_NOVA + pthread_join(thread_id_get_nova_driver, NULL); +#endif + } + else { + pthread_join(post_notification_thread, NULL); + pthread_join(resolution_changed_thread, NULL); + pthread_join(http_thread, NULL); + } + } +#endif +#endif + //destroy pthread_mutex +#if 1 + //pthread_mutex_destroy(&mutex_post_notification); + //pthread_mutex_destroy(&mutex_post_notification_push); + pthread_mutex_destroy(&mutex_post_notification_pop); + //printf("\n----------stop server 3\n"); + pthread_mutex_destroy(&mutex_getalarmmotion); + pthread_mutex_destroy(&mutex_alm); + pthread_mutex_destroy(&mutex_curl); + pthread_mutex_destroy(&mutex_dn); + + pthread_mutex_destroy(&mutex_websocket); + pthread_mutex_destroy(&mutex_enable_lpr_db); +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_enable_face_db); +#endif + pthread_mutex_destroy(&mutex_username); + pthread_mutex_destroy(&mutex_pns); + //pthread_mutex_destroy(&mutex_get_canvas); + + //printf("\n----------stop server 4\n"); + pthread_mutex_destroy(&mutex_snap); + //pthread_mutex_destroy(&mutex_cropped_roi); + //pthread_mutex_destroy(&mutex_snap_hd_image); + pthread_mutex_destroy(&mutex_snap_image); +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_remotesnap_image); // Ken 2022-09-26 + pthread_mutex_destroy(&mutex_radar_json); + pthread_mutex_destroy(&mutex_tof_json); +#endif + pthread_mutex_destroy(&mutex_get_image); + pthread_mutex_destroy(&mutex_get_image_HD); + + pthread_mutex_destroy(&mutex_config_json); +#if defined GY_OS_AMBA + //pthread_mutex_destroy(&mutex_jvc_config_json); +#endif + pthread_mutex_destroy(&mutex_events_json); + pthread_mutex_destroy(&mutex_web); + //printf("\n----------stop server 5\n"); + //pthread_mutex_destroy(&mutex_http_connection_handler); + pthread_mutex_destroy(&mutex_base64); + pthread_mutex_destroy(&mutex_run_one_net); +#ifdef GY_OS_NOVA + pthread_mutex_destroy(&mutex_run_parse_json); +#endif + pthread_mutex_destroy(&mutex_send_jpeg); + pthread_mutex_destroy(&mutex_heatmap_jpeg); + //pthread_mutex_destroy(&mutex_strsplit); + +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_perspective_transform); +#endif + //printf("\n----------stop server 6\n"); + pthread_mutex_destroy(&mutex_get_network_input); + pthread_mutex_destroy(&mutex_differ_image); + + pthread_mutex_destroy(&mutex_run_one_net_anpr); + pthread_mutex_destroy(&mutex_check_license); + pthread_mutex_destroy(&mutex_read_ipcam); + + pthread_mutex_destroy(&mutex_update_candidate); + pthread_mutex_destroy(&mutex_send_cgi); + + //pthread_mutex_destroy(&mutex_parse_bbox); + //pthread_mutex_destroy(&mutex_color_detect); + + pthread_mutex_destroy(&mutex_compute_median); + //pthread_mutex_destroy(&mutex_long_term); + //pthread_mutex_destroy(&mutex_short_term); + + //pthread_mutex_destroy(&mutex_long_term_yuv); + //pthread_mutex_destroy(&mutex_short_term_yuv); + + pthread_mutex_destroy(&mutex_set_http_request); + pthread_mutex_destroy(&mutex_reset_counter); +#ifdef GY_OS_AMBA + pthread_mutex_destroy(&mutex_run_osd); + + pthread_mutex_destroy(&mutex_get_depth); + //pthread_mutex_destroy(&mutex_tof_data); + pthread_mutex_destroy(&mutex_write_pcd_data); + pthread_mutex_destroy(&mutex_write_pcd_data_L); + pthread_mutex_destroy(&mutex_write_pcd_data_M); + pthread_mutex_destroy(&mutex_write_pcd_data_S); +#endif +#ifdef GY_OS_NOVA + pthread_mutex_destroy(&mutex_pre_bbox_receive); + pthread_mutex_destroy(&mutex_pre_connection); + pthread_mutex_destroy(&mutex_pre_image_receive); +#endif + +#endif + + + printf("Stop Server - pthread finished. #2\n"); +} + +#ifdef GY_OS_AMBA +void write_to_enable_tracking(char *enable_tracking) { + //printf("\n--------------[enable tracking]-----------------: %s\n", enable_tracking); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + char config_bakPATH[1024] = { 0 }; + strcpy(config_bakPATH, exePath); + strcat(config_bakPATH, "config_bak.json"); + + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + if (fileBuf_config) { + free(fileBuf_config); + fileBuf_config = NULL; + } + + if (root == NULL) + { + printf("root_config is NULL\n"); + } + else + { + cJSON *view_setting, *camera01, *ptz_enable_tracking; + + view_setting = cJSON_GetObjectItem(root, "view_setting"); + camera01 = cJSON_GetObjectItem(view_setting, "camera01"); + ptz_enable_tracking = cJSON_GetObjectItem(camera01, "ptz_enable_tracking"); + + + if (ptz_enable_tracking) { + + cJSON_ReplaceItemInObject(camera01, "ptz_enable_tracking", cJSON_CreateString(enable_tracking)); + + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(configPATH, config_bakPATH); + } + else + { + printf("Fail to open config.json \n"); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } +} +#endif +#ifdef GY_OS_AMBA +int read_bin(char *fileDir, unsigned char *addr) +{ + //fread + printf("read_bin \n"); + + //int rval = 0; + int lSize = 0; + +#if 0 + FILE *fp = NULL; + + + //lSize = ftell(fileDir); + lSize = 460800; + + printf("read_bin return\n"); + return lSize; + + if (lSize > 0) + { + fp = fopen(fileDir, "r"); + //char addr[500000]; + //int readCnt = fread(addr, 1, lSize, fp); /* return 0*/ + //int readCnt = fread(buffer,1,sizeof(buffer),fp); /* return 11 */ + //printf("readCnt = %d\n", readCnt); + fclose(fp); + } + else + return 0; +#endif + printf("read_bin return\n"); + return lSize; +} + +int teststoreYUV(char *file, int size, void *addr) +{ + FILE *fp = NULL; + int rval = 0; + + do { + if ((fp = fopen(file, "wb")) == NULL) { + printf("\n%s\n", file); + rval = -1; + break; + } + + + + if (fwrite(addr, 1, size, fp) != size) { + printf("\nfwrite]n"); + rval = -1; + break; + } + + fclose(fp); + fp = NULL; + + } while (0); + + if (fp) { + fclose(fp); + fp = NULL; + } + + return rval; +} + +int testbinfile(char *filename, char *buffer) +{ + printf("file name: %s \n", filename); + + int lSize = 0; + + FILE *fp = NULL; + + fp = fopen(filename, "r"); + + fseek(fp, 0, SEEK_END); + lSize = ftell(fp); + + rewind(fp); //set read point to start + /*size_t read_result = */fread(buffer, 1, lSize, fp); + + //char img_name[512] = { 0 }; + //sprintf(img_name, "/emmc/plugin/Aida_data/storage/hello_tofyuv.bin"); //same + ////store_bin(img_name, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt); + + //teststoreYUV(img_name, lSize, buffer); + //int readCnt = fread(buffer, 1, sizeof(buffer), fp); + + fclose(fp); + + return lSize; +} +#endif + +void move_file() { + + for(int i = 0 ; i < 13 ; i++) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + if( i == 0 ) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage"); + else if( i == 1 ) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/default.jpg"); + else if( i == 2 ) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/default.jpg"); + else if (i == 3) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/face"); + else if (i == 4) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/face/default.jpg"); + else if (i == 5) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/face/default.jpg"); + else if (i == 6) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/template"); + else if (i == 7) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/template/default.jpg"); + else if (i == 8) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/template/default.jpg"); + else if (i == 9) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/playback"); + else if (i == 10) + sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/playback/default.jpg"); + else if (i == 11) + sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/playback/default.jpg"); + else if (i == 12) + sprintf(cmd, "mkdir /emmc/plugin/Aida_data/sfe/storage"); + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + +} +void *start_run_python_thread(void* pythonpath) { + pthread_detach(pthread_self()); + setPthreadName("run_python"); + char *value = get_enable_python_file_value((const char*)pythonpath); + + while (python_check_webstatus == 0) + { + // python_check_webstatus = 0 + // python_check_webstatus = 1 } + printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); + continue; + } + // printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); + sleep(15); // Ȱ 15 A Web thread } + if (value == NULL) { + printf("Failed to retrieve enable_python_file value\n"); + pthread_exit(NULL); + } + // python ɮ + if (strstr(value, ".py") != NULL) { + printf("enable_python_file is a Python file: %s\n", value); + const char *prefix = "lifile_liname="; + char pythonfile[256]; + snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, value); + runPython(pythonfile); + } else { + printf("enable_python_file is not a Python file: %s\n", value); + } + pthread_exit(NULL); +} +char* get_enable_python_file_value(const char *filename) { + FILE *file = fopen(filename, "r"); + if (file == NULL) { + printf("Could not open file %s\n", filename); + return NULL; + } + + // jp + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Ū󤺮e줺s + char *file_content = (char *)malloc(file_size + 1); + if (file_content == NULL) { + printf("Memory allocation failed\n"); + fclose(file); + return NULL; + } + fread(file_content, 1, file_size, file); + file_content[file_size] = '\0'; + fclose(file); + + // ѪR JSON + cJSON *json = cJSON_Parse(file_content); + free(file_content); + if (json == NULL) { + printf("Error parsing JSON file\n"); + return NULL; + } + + // system_setting + cJSON *system_setting = cJSON_GetObjectItem(json, "system_setting"); + if (system_setting == NULL) { + printf("system_setting not found in JSON\n"); + cJSON_Delete(json); + return NULL; + } + + // enable_python_file + cJSON *enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + char *result = NULL; + if (enable_python_file != NULL && cJSON_IsString(enable_python_file)) { + result = strdup(enable_python_file->valuestring); // ƻsrŦ + } + + // Mz cJSON H + cJSON_Delete(json); + printf("[get_enable_python_file_value] result : %s \n",result); + // ^G + return result; +} +void run_server(int argc, char **argv) +{ + //HUSO鬪|------------------------20210803 + + check_if_start_run_server = 1; + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "The start of gynet."); + write_to_logs_html(temp_msg, "run server", "INFO", "Yes"); + write_to_log_for_start(temp_msg, "run server", "INFO"); + } + +#ifdef _DEBUG_AMBA + printf("\n[run_server] start\n"); + for (int i = 0;i < argc;i++) + printf("[run_server] argv[%d]:%s\n", i, argv[i]); +#endif // _DEBUG_AMBA + + file_management(); + initial_weight_settings(); + + getCameraPlugInInfo(); + update_accountData(); + update_accountData_port(); + + move_file(); + + g_IsRadarFake = 0; + + setlocale(LC_ALL, "en_US.UTF-8"); + + g_match_mac = 0; + + char init_CPU_usage[256] = "20"; + char init_GPU_usage[256] = "20"; + + sprintf(CPU_usage, "%s", init_CPU_usage); + sprintf(GPU_usage, "%s", init_GPU_usage);//psBuffer_send2 + +#ifdef REBOOT_BY_CPU_GPU_USAGE + CPU_usage_int = atoi(CPU_usage); + GPU_usage_int = atoi(GPU_usage); +#endif + + ColdZoneInit(); + + /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; +#ifdef GY_OS_NOVA + char config_smallPATH[1024] = { 0 }; +#endif + char config_installPATH[1024] = { 0 }; + +#ifdef GY_OS_NOVA + char config_small_installPATH[1024] = { 0 }; +#endif + char config_bakPATH[1024] = { 0 }; + + char events_installPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + char events_bakPATH[1024] = { 0 }; + + char tof_installPATH[1024] = { 0 }; + char tofPATH[1024] = { 0 }; + char tof_bakPATH[1024] = { 0 }; + + char emails_installPATH[1024] = { 0 }; + char emailsPATH[1024] = { 0 }; + char emails_bakPATH[1024] = { 0 }; + + char cold_objects_installPATH[1024] = { 0 }; + char cold_objectsPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_smallPATH, exePath); +#endif + strcpy(config_installPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_small_installPATH, exePath); +#endif + strcpy(config_bakPATH, exePath); + + strcpy(eventsPATH, exePath); + strcpy(events_installPATH, exePath); + strcpy(events_bakPATH, exePath); + + strcpy(tofPATH, exePath); + strcpy(tof_installPATH, exePath); + strcpy(tof_bakPATH, exePath); + + strcpy(emailsPATH, exePath); + strcpy(emails_installPATH, exePath); + strcpy(emails_bakPATH, exePath); + + strcpy(cold_objectsPATH, exePath); + strcpy(cold_objects_installPATH, exePath); + + strcat(configPATH, "config.json"); +#ifdef GY_OS_NOVA + strcat(config_smallPATH, "config_small.json"); +#endif + strcat(config_installPATH, "config_install.json"); + +#ifdef GY_OS_NOVA + strcat(config_small_installPATH, "config_small_install.json"); +#endif + strcat(config_bakPATH, "config_bak.json"); + // if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { + // perror("check current runpython thread failed\n"); + // exit(EXIT_FAILURE); + // } + strcat(eventsPATH, "events.json"); + strcat(events_installPATH, "events_install.json"); + strcat(events_bakPATH, "events_bak.json"); + + strcat(tofPATH, "tof.json"); + strcat(tof_installPATH, "tof_install.json"); + strcat(tof_bakPATH, "tof_bak.json"); + + strcat(emailsPATH, "emails.json"); + strcat(emails_installPATH, "emails_install.json"); + strcat(emails_bakPATH, "emails_bak.json"); + + strcat(cold_objectsPATH, "cold_objects.json"); + strcat(cold_objects_installPATH, "cold_objects_install.json"); + + //arguments + dont_show = find_arg(argc, argv, "-dont_show"); + show = find_arg(argc, argv, "-show"); + tcp_port = find_int_arg(argc, argv, "-tcp_port", -1); + //out_filename = find_char_arg(argc, argv, "-out_filename", 0); + //outfile = find_char_arg(argc, argv, "-out", 0); + //prefix = find_char_arg(argc, argv, "-prefix", 0); + thresh = find_float_arg(argc, argv, "-thresh", .24); + hier_thresh = find_float_arg(argc, argv, "-hier", .5); + cam_index = find_int_arg(argc, argv, "-c", 0); + frame_skip = find_int_arg(argc, argv, "-s", 0); + num_of_clusters = find_int_arg(argc, argv, "-num_of_clusters", 5); + yuv_width = find_int_arg(argc, argv, "-width", -1); + yuv_height = find_int_arg(argc, argv, "-height", -1); + ext_output = find_arg(argc, argv, "-ext_output"); + save_labels = find_arg(argc, argv, "-save_labels"); + http_port = find_int_arg(argc, argv, "-http_port", 0); + //unlocking_key = find_char_arg(argc, argv, "-unlocking_key", 0); + //char *ip_address = find_char_arg(argc, argv, "-ip_address", 0); + gpu_idx = find_int_arg(argc, argv, "-gpu_idx", 0); + //c_cnn_type = find_char_arg(argc, argv, "-cnn_type", 0); +#if 0 + radar_log = find_arg(argc, argv, "-radar_log"); // 10-19 leo +#endif + // radar_log = 1; // 2022-10-28 Ken for V1 classification testing info + //printf("radar_log:%d\n", radar_log); + + //char* model = find_char_arg(argc, argv, "-m", ""); + input_resizable = find_int_arg(argc, argv, "-auto_resize", 0); + custom_cpu_library = find_char_arg(argc, argv, "-l", ""); + custom_cldnn = find_char_arg(argc, argv, "-c", ""); + performance_counter = find_int_arg(argc, argv, "-pc", 0); + + isGYNetReady = FALSE; + + //pthread_mutex_init(&mutex_post_notification, NULL); + //pthread_mutex_init(&mutex_post_notification_push, NULL); + pthread_mutex_init(&mutex_post_notification_pop, NULL); + pthread_mutex_init(&mutex_getalarmmotion, NULL); + pthread_mutex_init(&mutex_alm, NULL); + pthread_mutex_init(&mutex_curl, NULL); + pthread_mutex_init(&mutex_dn, NULL); + + pthread_mutex_init(&mutex_websocket, NULL); + pthread_mutex_init(&mutex_enable_lpr_db,NULL); +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_enable_face_db,NULL); +#endif + pthread_mutex_init(&mutex_username, NULL); + pthread_mutex_init(&mutex_pns, NULL); + pthread_mutex_init(&mutex_snap, NULL); + //pthread_mutex_init(&mutex_get_canvas, NULL); + + //pthread_mutex_init(&mutex_cropped_roi, NULL); + //pthread_mutex_init(&mutex_snap_hd_image, NULL); + pthread_mutex_init(&mutex_snap_image, NULL); +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_remotesnap_image, NULL); // Ken 2022-09-26 + pthread_mutex_init(&mutex_radar_json, NULL); + pthread_mutex_init(&mutex_tof_json, NULL); +#endif + pthread_mutex_init(&mutex_get_image, NULL); + pthread_mutex_init(&mutex_get_image_HD, NULL); + + pthread_mutex_init(&mutex_config_json, NULL); +#if defined GY_OS_AMBA + //pthread_mutex_init(&mutex_jvc_config_json, NULL); +#endif + pthread_mutex_init(&mutex_events_json, NULL); + pthread_mutex_init(&mutex_web, NULL); + //pthread_mutex_init(&mutex_http_connection_handler, NULL); + pthread_mutex_init(&mutex_base64, NULL); + pthread_mutex_init(&mutex_run_one_net, NULL); +#ifdef GY_OS_NOVA + pthread_mutex_init(&mutex_run_parse_json, NULL); +#endif + pthread_mutex_init(&mutex_send_jpeg, NULL); + pthread_mutex_init(&mutex_heatmap_jpeg, NULL); + //pthread_mutex_init(&mutex_strsplit, NULL); + +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_perspective_transform, NULL); +#endif + pthread_mutex_init(&mutex_get_network_input, NULL); + pthread_mutex_init(&mutex_differ_image, NULL); + + pthread_mutex_init(&mutex_run_one_net_anpr, NULL); + pthread_mutex_init(&mutex_check_license, NULL); + pthread_mutex_init(&mutex_read_ipcam, NULL); + pthread_mutex_init(&mutex_update_candidate, NULL); + + pthread_mutex_init(&mutex_send_cgi, NULL); + //pthread_mutex_init(&mutex_parse_bbox, NULL); + //pthread_mutex_init(&mutex_color_detect, NULL); + pthread_mutex_init(&mutex_compute_median, NULL); + //pthread_mutex_init(&mutex_long_term, NULL); + //pthread_mutex_init(&mutex_short_term, NULL); + + //pthread_mutex_init(&mutex_long_term_yuv, NULL); + //pthread_mutex_init(&mutex_short_term_yuv, NULL); + + pthread_mutex_init(&mutex_set_http_request, NULL); + pthread_mutex_init(&mutex_reset_counter, NULL); +#ifdef GY_OS_AMBA + pthread_mutex_init(&mutex_run_osd, NULL); + + pthread_mutex_init(&mutex_get_depth, NULL); + //pthread_mutex_init(&mutex_tof_data, NULL); + pthread_mutex_init(&mutex_write_pcd_data, NULL); + pthread_mutex_init(&mutex_write_pcd_data_L, NULL); + pthread_mutex_init(&mutex_write_pcd_data_M, NULL); + pthread_mutex_init(&mutex_write_pcd_data_S, NULL); +#endif +#ifdef GY_OS_NOVA + pthread_mutex_init(&mutex_pre_bbox_receive, NULL); + pthread_mutex_init(&mutex_pre_connection, NULL); + pthread_mutex_init(&mutex_pre_image_receive, NULL); +#endif + //g_multi_handle = curl_multi_init(); //Curl init + + //QueueLockInit(); + + //HWSO鬪|------------------------20210803 + + //100ӥkO鬪| + memset(&accountData, 0, sizeof(accountData)); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + + pthread_mutex_lock(&mutex_curl); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + pthread_mutex_unlock(&mutex_curl); + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed\n"); + } + pthread_join(thread_id_getipcamsettings, NULL); + //StartPTZupdateStatusThread(); + +#ifdef GY_OS_NOVA + ipcam_getfeatures(); +#else + if (strcmp(WeightFileModeName, "mod004") == 0) { + ipcam_getfeatures(); + } +#endif + + ///ŪSMTP service + + copy_ipcam_smtp_service_to_gynet(); + + //printf("000 get password = %s \n", accountData[0].account_password); + +#if 1 + + //1ӰO鬪| + if (http_port > 0) + { + //printf("\n**********************\n"); + //printf("preload server open"); + //printf("\n**********************\n"); + + pthread_t preload_http_thread; + if (pthread_create(&preload_http_thread, 0, run_preload_http_server_thread, 0)) + error("preload http server thread creation failed\n"); + + } + + //0ӥkO鬪| + //char returned_msg[MEMORY_SIZE] = { 0 }; + //PNS_Query_Service_Status(returned_msg); + +#endif + + //**bOKO鬪| + //output.log 138,240byte ->330ӰO鬪| output.logWTܤC + //get_current_events_json_data |O鬪|AO`ihC + g_IsPTZDevice = 0; + + + +#endif + + //init CGI CMD time + + //ӰO鬪| bstop_server~| + cgi_startTime_buff = (struct tm*)malloc(sizeof(struct tm)); + cgi_whenTime_buff = (struct tm*)malloc(sizeof(struct tm)); + + //printf("GyNet is starting......\n"); + + td_weight_num = 0; + + char customWeightPATH[1024] = { 0 }; + strcpy(customWeightPATH, exePath); + strcat(customWeightPATH, "customWeight.json"); + + cJSON* root_third, * weight_number; + cJSON *third_party_weight_list, *td_party_weight, *weight_name,*anchor_name,*label_name, *encryption; + + //printf("111 get password = %s \n", accountData[0].account_password); + + if (!FileExist(customWeightPATH)) + { + td_weight_num = 0; + printf("%s doesn't exist.\n", customWeightPATH); + } + else + { + //printf("read customWeight.json.\n"); + + char* fileBuf_third = ReadAllBytes(customWeightPATH); + if (fileBuf_third) { + root_third = cJSON_Parse(fileBuf_third); + + if (fileBuf_third) { + free(fileBuf_third); + fileBuf_third = NULL; + } + weight_number = cJSON_GetObjectItem(root_third, "Weight Number"); + if (weight_number) + td_weight_num = (short)weight_number->valueint; + + third_party_weight_list = cJSON_GetObjectItem(root_third, "Third party weight"); + + if (third_party_weight_list) + { + int k = 0; + cJSON_ArrayForEach(td_party_weight, third_party_weight_list) + { + if (td_party_weight && k < MAX_LAYER_NUM) + { + weight_name = cJSON_GetObjectItem(td_party_weight, "Weight Name"); + if (weight_name) + sprintf(td_weight_info[k].weight_name, "%s", weight_name->valuestring); + + anchor_name = cJSON_GetObjectItem(td_party_weight, "Anchor Name"); + if (anchor_name) + sprintf(td_weight_info[k].anchor_name, "%s", anchor_name->valuestring); + + label_name = cJSON_GetObjectItem(td_party_weight, "Label Name"); + if (label_name) + sprintf(td_weight_info[k].label_name, "%s", label_name->valuestring); + + encryption = cJSON_GetObjectItem(td_party_weight, "Encryption"); + if (encryption && strcmp(encryption->valuestring,"Yes")==0) + td_weight_info[k].is_encryption = 1; + else + td_weight_info[k].is_encryption = 0; + k++; + } + } + } + + if (root_third) { + cJSON_Delete(root_third); + root_third = NULL; + } + } + } + +#if 0 + for (int i = 0; i < td_weight_num; i++) { + printf("\nWeight Name: %s\n", td_weight_info[i].weight_name); + printf("\nis_encryption: %hd\n", td_weight_info[i].is_encryption); + } +#endif + + int new_data_write_to_config_file_flag = 0; + int new_data_write_to_events_file_flag = 0; + int new_data_write_to_tof_file_flag = 0; + //printf("\n-------------------http_port: %d\n", http_port); + sprintf(accountData[0].account_aida_port, "%d", http_port); + + if (tcp_port > 0 || http_port > 0) + { + + //read settings from config.json + //char filename[] = config_bakPATH; + char *filename = configPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + return; + } + + //printf("read config.json. %s\n", filename); + //size_t nfileSize = ReadFileSize(filename); + + char* fileBuf = ReadAllBytes(filename); + + if(fileBuf){ + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //printf("config.json parse OK.\n"); + cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); + //cJSON* nic_name = cJSON_GetObjectItem(about_box, "NIC name"); + cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + //printf(">>>>>>>>>>> uk key = %s \n", unlock_key->valuestring); + + /* + if (td_weight_num >= 1) { + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("Third_party")); + unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + }*/ + + if (unlock_key && (int)strlen(unlock_key->valuestring) == 0) { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath); + strcat(keyPATH, "key.txt"); + if (FileExist(keyPATH) == 1) { + + char key_buff[1024] = { 0 };//creating char array to store data of file + + FILE *pFile; + + if ((pFile = fopen(keyPATH, "r")) != NULL) + { + fscanf(pFile, "%s", key_buff); + fclose(pFile); + + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(key_buff)); + unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + + + char* JsonString = cJSON_Print(root); + + FILE *f = fopen(configPATH, "w"); + if (f == NULL) + { + printf("Error opening config.json!\n"); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + CopyFileTo(configPATH, config_bakPATH); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + else + printf("Fail to open key.txt \n"); + } + } + + //ѽXunlockingKey - step 1:base64 decode + size_t base64_decode_length = 0; + unsigned char EncryptKeyData[256]; + char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + + base64_decode(unlock_key->valuestring, strlen(unlock_key->valuestring), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //printf("\n--------------OriEncryptData:%s\n", OriEncryptData); + //printf("\n--------------EncryptKeyData:%s\n", EncryptKeyData); + + //ѽXunlockingKey - step 2:AES descrytion + KeyExpansion(key, expandedKey); + //printf("\n---------expandedKey:%s\n", expandedKey); + AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); + //printf("unlocking_key descrytion OK.\n"); + + //printf("key info = %s \n", DecryptKeyData); + + //printf("\n--------------DecryptKeyData:%s\n", DecryptKeyData); + + //ounlockingKeyXT + cJSON *keyRoot, *fe, *fe2, *li, *ad, *st, *et, *id; + keyRoot = cJSON_Parse(DecryptKeyData); + fe = cJSON_GetObjectItem(keyRoot, "fe"); + fe2 = cJSON_GetObjectItem(keyRoot, "fe2"); + li = cJSON_GetObjectItem(keyRoot, "li"); + ad = cJSON_GetObjectItem(keyRoot, "ad"); + st = cJSON_GetObjectItem(keyRoot, "st"); + et = cJSON_GetObjectItem(keyRoot, "et"); + id = cJSON_GetObjectItem(keyRoot, "id"); + + + unsigned char first_half_char_key[512] = { 0 }; + unsigned char mykey_custom[512] = { 0 }; + + //unsigned char expandedmykey_custom[176] = { 0 }; + char mygmail_after_ddDec[512] = { 0 }; + + // If lilin ID and independent face license are not consistent, the verification will fail. + if (!id && unlock_key && strlen(unlock_key->valuestring) >= 4 && strncmp(unlock_key->valuestring, "face", 4) != 0) + { + printf("[ERROR] Null System ID\n"); + + //printf("\n--------------unlock_key->valuestring:%s\n", unlock_key->valuestring); + + memcpy(first_half_char_key, unlock_key->valuestring, 16); + if ((int)strlen((char *)first_half_char_key) < 16) { + for (int i = (int)strlen((char *)first_half_char_key); i < 16; i++) { + first_half_char_key[i] = '0'; + } + } + //printf("\n--------------first_half_char_key:%s\n", first_half_char_key); + + ddDec(unlock_key->valuestring, mygmail_after_ddDec); + //printf("\n---------------mygmail_after_ddDec: %s\n", mygmail_after_ddDec); + + if (strstr(mygmail_after_ddDec, "@") != NULL && + strstr(mygmail_after_ddDec, "email:") != NULL) { + + for (int i = 0; i < 16; i++) { + //mykey_custom[i] = first_half_char_key[i]; + sprintf((char*)mykey_custom + i * 2, "%02x", (char*)first_half_char_key[i]); + } + + //printf("\n---------------mykey_custom: %s\n", mykey_custom); + check_if_correct_mail = 1; + } + + } + else { + //printf("System ID: %s\n", id->valuestring); + } + + //oøT + strcpy(g_filename_TLT, TLT_FILE_NAME); + //strcpy(filename2, exePath); + //first time + if (!FileExist(g_filename_TLT) || ReadFileSize(g_filename_TLT) == 0) + { + printf("TLT file doesn't exist.\n"); + + //create gysetting.json with current time + { + time_t now_time = time(0); + char strLaunchTime[16] = { 0 }; + snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); + + //Nɶ[K, gJɮ + //if (!(last_launch_time > now_time)) + { + KeyExpansion(key, expandedKey); + unsigned char EncryptData[1 * 1024]; + memset(EncryptData, 0x00, sizeof(EncryptData)); + int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); + + size_t base64_encode_length = 0; + char launchTime[1024] = { 0 }; + base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); + *(launchTime + base64_encode_length) = '\0'; + + cJSON *s_root = cJSON_CreateObject(); + cJSON_AddItemToObject(s_root, "TLT code", cJSON_CreateString(launchTime)); + cJSON_AddItemToObject(s_root, "VM code", cJSON_CreateString("%")); + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(g_filename_TLT, "w"); + if (f == NULL) + { + printf("Error opening setting file!\n"); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (s_root) { + free(s_root); + s_root = NULL; + } + } + } + } + + //printf("\n----------------mode: %s\n", WeightFileModeName); + + int bMacMatch = 0; + if (g_match_mac == 1) { + bMacMatch = 1; + } + //int nEnableNIC = 0; + char * find; + + + ///omac + { + char fetch_mac_addr[64] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + GetMACAddress(fetch_mac_addr); + //printf("\n--------------------------:25\n"); + //http_mac_address = fetch_mac_addr; + + //printf("\nfetch_mac_addr:%s\n", fetch_mac_addr); + //printf("\nid->valuestring:%s\n", id->valuestring); + + find = strchr(fetch_mac_addr, '\n'); + if (find) + *find = '\0'; + + strcpy(g_mac_address, fetch_mac_addr); + } + + //printf("111-9 get password = %s \n", accountData[0].account_password); + // Check SDK3.0 and independent face license +#ifdef GY_OS_AMBA +#if 0 + if (g_IsSDK_3_0 == 1 && unlock_key && strncmp(unlock_key->valuestring, "face", 4) == 0) { + unlockingKeyInnoFR = 1; + // printf("unlocking key : %s\n", unlock_key->valuestring); + + char temp_key[512] = { 0 }; + //memcpy(temp_key, unlock_key->valuestring + 4, strlen(unlock_key->valuestring) - 4); + char formatted_mac[30] = { 0 }; +#if 0 + char fetch_mac_addr[30] = { 0 }; + //printf("\n--------g_mac_address:%s\n", g_mac_address); + strcpy(fetch_mac_addr, g_mac_address); + char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); + //printf("\n--------new_mac_addr:%s\n", new_mac_addr); + + //sprintf(formatted_mac, "%s", new_mac_addr + 2); + if (new_mac_addr) { + free(new_mac_addr); + new_mac_addr = NULL; + } +#endif + + getContractSignature(temp_key, formatted_mac); + + //printf("\n--------formatted_mac:%s\n", formatted_mac); + //printf("\n--------temp_key:%s\n", temp_key); + + memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); + strcpy(strUnlockingKey,"face"); + strcat(strUnlockingKey, temp_key); + + char object_key[512] = { 0 }; + strcpy(object_key, unlock_key->valuestring+4); + if (strcmp(temp_key, object_key)!=0) { + //printf("\nAAAAAAAAAA:Diff\n"); + char buffer_content[1024] = { 0 }; + strcpy(buffer_content,"{\"unlocking_key\":\""); + strcat(buffer_content,strUnlockingKey); + strcat(buffer_content,"\"}"); + update_config(buffer_content); + } + else { + //printf("\nAAAAAAAAAA:OK\n"); + } + + unlockingKeyInnoFR_success = faceengine_start_and_check_license(); // if strat faceengine earlily(when getContractSignature), faceengine will stuck + + //unlockingKeyInnoFR_success = 1;//ҰfaceengineAݯणih + //if (unlockingKeyInnoFR_success == 1) + //{ + + //} + } +#endif +#endif + + +#ifdef GY_OS_AMBA + if (strcmp(WeightFileModeName, "mod001") == 0 || + strcmp(WeightFileModeName, "mod002") == 0 || + strcmp(WeightFileModeName, "mod003") == 0 || + strcmp(WeightFileModeName, "mod004") == 0) { + if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring, "auto") == 0) { + check_if_fe_fail = 1; + } + } +#else + if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring,"auto")==0) { + check_if_fe_fail = 1; + } +#endif + + if ((fe && fe2 && li && st && et && id && td_weight_num == 0) || (td_weight_num >= 1 && check_if_correct_mail == 1) || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) + { + //ovɶ + time_t start_time; + time_t end_time; + struct tm* m_time; + + if (fe && fe2) { + featureType = fe->valueint; + featureType2 = fe2->valueint; + + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + } + /*else if (unlockingKeyInnoFR_success == 1) { + featureType = FEATURE_EMPTY; + featureType2 = FEATURE_AIFACE; + stAMBAcontent.featureType = FEATURE_EMPTY; + stAMBAcontent.featureType2 = FEATURE_AIFACE; + }*/ + else if (check_if_fe_fail == 1) { + featureType = FEATURE_TRAF_DET; +#ifdef GY_OS_V_SERIES + featureType2 = FEATURE_AIFLOW; +#elif GY_OS_NOVA + featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; +#else + /*if (g_check_if_OK_getfeatures == 0) { + featureType2 = FEATURE_AIFLOW; + } + else*/ + if(strcmp(WeightFileModeName, "mod004") == 0){ + featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; + } + else if (strcmp(WeightFileModeName, "mod001") == 0 || + strcmp(WeightFileModeName, "mod002") == 0 || + strcmp(WeightFileModeName, "mod003") == 0) { + featureType2 = FEATURE_AIFLOW; + } +#endif + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + } + else { + featureType = 0x0000; + featureType2 = 0x0000; + stAMBAcontent.featureType = 0x0000; + stAMBAcontent.featureType2 = 0x0000; + } + + if (li && st && et && id) { + start_time = st->valueint; + m_time = gmtime(&start_time); + m_time->tm_mday += et->valueint; + end_time = mktime(m_time); + g_start_time = start_time; + g_end_time = end_time; + } + else { + start_time = 0; + end_time = 0; + g_start_time = start_time; + g_end_time = end_time; + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIRADAR) == FEATURE_AIRADAR) + { + g_IsRadarDevice = 1; + printf("g_IsRadarDevice : %d\n", g_IsRadarDevice); + printf("g_IsRadarFake : %d\n", g_IsRadarFake); + } + + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AITOF) == FEATURE_AITOF) + { + g_IsToFDevice = 1; + printf("\ng_IsToFDevice : %d\n", g_IsToFDevice); + } + + if (td_weight_num >= 1 && check_if_correct_mail == 1) { + g_IsCustomWeight = 1; + printf("\ng_IsCustomWeight : %d\n", g_IsCustomWeight); + //featureType = FEATURE_ACCESS_CTRL; + //featureType2 = 0x0000; + //stAMBAcontent.featureType = FEATURE_ACCESS_CTRL; + //stAMBAcontent.featureType2 = 0x0000; + } + + //printf("111-8 get password = %s \n", accountData[0].account_password); + + // printf("Check licence:\n"); + //printf("--------------featureType = 0x%x \n", featureType); + //printf("--------------featureType2 = 0x%x \n", featureType2); + // printf("--------------li->valueint: %d\n", li->valueint); + // printf("--------------st->valueint: %d\n", st->valueint); + // printf("--------------et->valueint: %d\n", et->valueint); + // printf("--------------id->valueint: %d\n", id->valueint); + + ///////////////////////////////////////////////////////HWfeaturetype oa + /* + if (strstr(EncryptKeyData, "@") == NULL) { + printf("\nThere is no @.\n"); + } + else { + printf("\nThere is existing @.\n"); + }*/ + + //oMAC Address + //20201111 sophia add + + if (g_match_mac == 0) + { + char fetch_mac_addr[30] = { 0 }; + strcpy(fetch_mac_addr, g_mac_address); + + char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); + //printf("new_mac_addr = %s\n", new_mac_addr); + + //char* find_lilin_mac = strstr((const char*)new_mac_addr, "000FFC"); //begin 00-0f-fc //000FFC + + if (strstr(new_mac_addr, "000FFC") != NULL || strstr(new_mac_addr, "142FFD") != NULL) + { + if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { + if (id && strcmp(id->valuestring, new_mac_addr) == 0) + { + //printf("find_lilin_mac = 0x%x\n", find_lilin_mac); + bMacMatch = 1; //ŦXMAC address + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { + bMacMatch = 1; + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + else + { + bMacMatch = 0; + g_match_mac = 0; + g_bMacMatch = bMacMatch; + } + } + else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { + bMacMatch = 1; + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + else if(check_if_correct_mail == 1){ + bMacMatch = 1; + g_match_mac = 1; + g_bMacMatch = bMacMatch; + } + /*else if (g_IsRadarDevice == 1) {//{bkeyFANݭnŦXMAC address + bMacMatch = 1; + g_match_mac = 1; + } + else if (g_IsToFDevice == 1)//{bkeyFANݭnŦXMAC address + { + bMacMatch = 1; + g_match_mac = 1; + }*/ + else { + bMacMatch = 0; + g_match_mac = 0; + g_bMacMatch = bMacMatch; + } + } + else + { + g_match_mac = 0; + printf("\n============This is not LILIN mac address.\n"); + } + /* + printf("\ng_match_mac: %d\n", g_match_mac); + printf("\ng_mac_address: %s\n", g_mac_address); + */ + if (new_mac_addr) { + free(new_mac_addr); + new_mac_addr = NULL; + } + } + + //printf("111-711 0 get password = %s \n", accountData[0].account_password); + + update_system_time(); + + if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && g_IsRadarDevice == 0 && unlockingKeyInnoFR_success == 0) { + if (li) + g_li = li->valueint; + else + g_li = 0; + + if (ad) + g_ad = ad->valueint; + else + g_ad = 0; + + if (ad && li) + check_license(li->valueint, ad->valueint, bMacMatch, start_time, end_time, g_filename_TLT); + else if(li) + check_license(li->valueint, 0, bMacMatch, start_time, end_time, g_filename_TLT); + else + check_license(0, 0, bMacMatch, start_time, end_time, g_filename_TLT); + } + + check_feature(); + //printf("111-7 0 get password = %s \n", accountData[0].account_password); + //post events setting + //char filename2[] = "events.json"; + char *filename2 = eventsPATH; + char *filename_tof = tofPATH; + if (!FileExist(filename2)) + { + printf("%s doesn't exist.\n", filename2); + printf("Press any key to exit...\n"); + getchar(); + return; + } + if (!FileExist(filename_tof)) + { + printf("%s doesn't exist.\n", filename_tof); + printf("Press any key to exit...\n"); + getchar(); + return; + } + //printf("111-7 1 get password = %s \n", accountData[0].account_password); + cJSON *tof_root; + cJSON *tof_version,*tof_debug,*tof_install_angle,*tof_enable_camera,*enable_tof_ground,*enable_tof_wall,*tof_camera; + cJSON *tof_camera_ip,*tof_camera_port,*tof_camera_sub_url,*tof_auth_key,*tof_ip_setting,*tof_camera_username,*tof_camera_password; + cJSON *distance_options, *distance_threshold, *height_options, *height_threshold,*distance_min_max,*height_min_max; + cJSON *ground_x, *ground_y; + + fileBuf = ReadAllBytes(filename_tof); + if (fileBuf) { + tof_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + + tof_version = cJSON_GetObjectItem(tof_root, "version"); + tof_debug = cJSON_GetObjectItem(tof_root, "debug"); + tof_install_angle = cJSON_GetObjectItem(tof_root, "install_angle"); + tof_enable_camera = cJSON_GetObjectItem(tof_root, "enable_camera"); + enable_tof_ground = cJSON_GetObjectItem(tof_root, "enable_tof_ground"); + enable_tof_wall = cJSON_GetObjectItem(tof_root, "enable_tof_wall"); + tof_camera = cJSON_GetObjectItem(tof_root, "camera"); + distance_options = cJSON_GetObjectItem(tof_root, "distance_options"); + distance_threshold = cJSON_GetObjectItem(tof_root, "distance_threshold"); + height_options = cJSON_GetObjectItem(tof_root, "height_options"); + height_threshold = cJSON_GetObjectItem(tof_root, "height_threshold"); + distance_min_max = cJSON_GetObjectItem(tof_root, "distance_min_max"); + height_min_max = cJSON_GetObjectItem(tof_root, "height_min_max"); + + ground_x = cJSON_GetObjectItem(tof_root, "ground_x"); + ground_y = cJSON_GetObjectItem(tof_root, "ground_y"); + +#ifdef GY_OS_AMBA + if (tof_version) { + tofData.tof_version = tof_version->valueint; + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_version = 1; + } + + + if (tof_debug) { + if (cJSON_IsTrue(tof_debug)) + { + tofData.tof_debug = true; + } + else + { + tofData.tof_debug = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_debug = false; + } + + + if (tof_install_angle) { + tofData.tof_install_angle = tof_install_angle->valueint; + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_install_angle = 90; + } + + if (tof_enable_camera) { + if (cJSON_IsTrue(tof_enable_camera)) + { + tofData.tof_enable_camera = true; + } + else + { + tofData.tof_enable_camera = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_enable_camera = false; + } + + if (enable_tof_ground) { + if (cJSON_IsTrue(enable_tof_ground)) + { + tofData.enable_tof_ground = true; + } + else + { + tofData.enable_tof_ground = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.enable_tof_ground = false; + } + + if (enable_tof_wall) { + if (cJSON_IsTrue(enable_tof_wall)) + { + tofData.enable_tof_wall = true; + } + else + { + tofData.enable_tof_wall = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.enable_tof_wall = false; + } + + if (distance_options) { + strcpy(tofData.distance_options, distance_options->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.distance_options, "lt"); + } + + if (distance_min_max) { + strcpy(tofData.distance_min_max, distance_min_max->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.distance_min_max, "min"); + } + + if (distance_threshold) { + strcpy(tofData.distance_threshold, distance_threshold->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.distance_threshold, "0.5"); + } + + if (height_options) { + strcpy(tofData.height_options, height_options->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.height_options, "gt"); + } + + if (height_min_max) { + strcpy(tofData.height_min_max, height_min_max->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.height_min_max, "max"); + } + + if (ground_x) { + strcpy(tofData.ground_x, ground_x->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.ground_x, "320"); + } + + if (ground_y) { + strcpy(tofData.ground_y, ground_y->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.ground_y, "240"); + } + + if (height_threshold) { + strcpy(tofData.height_threshold, height_threshold->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.height_threshold, "1.5"); + } + + if (tof_camera) { + tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); + tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); + tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); + tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); + tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); + tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); + tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); + + if (tof_camera_ip) { + strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_ip, "192.168.50.200"); + } + + if (tof_camera_port) { + strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_port, "80"); + } + + if (tof_camera_sub_url) { + strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_sub_url, "/stream0"); + } + + if (tof_auth_key) { + strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); + } + + if (tof_ip_setting) { + if (cJSON_IsTrue(tof_ip_setting)) + { + tofData.tof_ip_setting = true; + } + else + { + tofData.tof_ip_setting = false; + } + } + else { + new_data_write_to_tof_file_flag = 1; + tofData.tof_ip_setting = false; + } + + if (tof_camera_username) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); + tofData.tof_camera_username[strlen(temp_account)] = '\0'; + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_username, "admin"); + } + + if (tof_camera_password) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); + tofData.tof_camera_password[strlen(temp_account)] = '\0'; + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_password, "pass"); + } + } + else { + new_data_write_to_tof_file_flag = 1; + strcpy(tofData.tof_camera_ip, "192.168.50.200"); + strcpy(tofData.tof_camera_port, "80"); + strcpy(tofData.tof_camera_sub_url, "/stream0"); + strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); + tofData.tof_ip_setting = false; + strcpy(tofData.tof_camera_username, "admin"); + strcpy(tofData.tof_camera_password, "pass"); + } +#endif + } + } + //printf("111-7 2 get password = %s \n", accountData[0].account_password); + cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content + ,*post_customized_header; + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone,*counter_c_name, + *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + cJSON *link_to_post_event_name, *post_interval; + cJSON *email_setting,*email_content; + cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + fileBuf = ReadAllBytes(filename2); + if (fileBuf) { + n_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + notification = cJSON_GetObjectItem(n_root, "notification"); + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + + if (events_default_version) { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.events_default_version, "1"); + } + + if (enable_snmp_post) + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + else { + new_data_write_to_events_file_flag = 1; + activeSNMPPost = _FALSE; + } + + if (enable_heartbeat) { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_heartbeat, "No"); + } + + if (enable_snmp_heartbeat) { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_snmp_heartbeat, "No"); + } + + if (snmp_heartbeat_dwell) { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); + } + + if (snmp_heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); + } + + if (enable_check_ptz_start_autotracking) { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); + } + + if (enable_check_ptz_end_autotracking) { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); + } + + if (enable_only_once_to_post) { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_only_once_to_post, "Yes"); + } + + if (enable_obj_once_to_post) { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); + } + + if (enable_location_once_to_post) { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_location_once_to_post, "Yes"); + } + + if (enable_nvr_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); + } + + if (enable_8592_once_to_getalarmmotion) { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); + } + + if (dwell_to_the_same_location) { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.dwell_to_the_same_location, "5"); + } + + if (heartbeat_dwell) { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heartbeat_dwell, "10"); + } + + if (heatmap_max) { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heatmap_max, "100"); + } + + if (enable_heatmap) { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_heatmap, "No"); + } + + if (heatmap_frequency) { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heatmap_frequency, "5"); + } + + if (lpr_title) { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.lpr_title, "My Car Park"); + } + + if (heartbeat_link_to_post_event_name) { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); + } + + if (ptz_start_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); + } + + if (ptz_end_autotracking_link_to_post_event_name) { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); + } + + if (enable_counter_snap) { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_counter_snap, "No"); + } + + if (enable_barcode_qr) { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(heartbeatData.enable_barcode_qr, "No"); + } + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + strcpy(postEventList[i].post_protocol, post_protocol->valuestring); + strcpy(postEventList[i].post_event_method, post_event_method->valuestring); + strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); + + if (g_camera_white_LED == 1 && i == 2 && strcmp(postEventList[i].post_event_name, "Camera virtual 3 / White LED") != 0) { + new_data_write_to_events_file_flag = 1; + strcpy(postEventList[i].post_event_name, "Camera virtual 3 / White LED"); + } + + strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); + strcpy(postEventList[i].post_host_port, post_host_port->valuestring); + strcpy(postEventList[i].post_url, post_url->valuestring); + //strcpy(postEventList[i].post_username, post_username->valuestring); + //strcpy(postEventList[i].post_password, post_password->valuestring); + strcpy(postEventList[i].post_content, post_content->valuestring); + strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); + + if (post_sequence) + strcpy(postEventList[i].post_sequence, post_sequence->valuestring); + else { + strcpy(postEventList[i].post_sequence, ""); + new_data_write_to_events_file_flag = 1; + } + + if (post_timeout) + strcpy(postEventList[i].post_timeout, post_timeout->valuestring); + else { + strcpy(postEventList[i].post_timeout, "5"); + new_data_write_to_events_file_flag = 1; + } + + if (post_file_format) + strcpy(postEventList[i].post_file_format, post_file_format->valuestring); + else { + strcpy(postEventList[i].post_file_format, "text"); + new_data_write_to_events_file_flag = 1; + } + + if (post_jpeg_file_name_format) + strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); + new_data_write_to_events_file_flag = 1; + } + + if (post_jpeg_file_name) + strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); + else { + strcpy(postEventList[i].post_jpeg_file_name, "snap"); + new_data_write_to_events_file_flag = 1; + } + + postEventList[i].check_if_delivering = 0;//La褣Al + i++; + } + if (i < 9) { + strcpy(postEventList[i].post_protocol, "HTTP"); + strcpy(postEventList[i].post_event_method, "GET"); + strcpy(postEventList[i].post_event_name, "Go to PTZ preset"); + strcpy(postEventList[i].post_host_ip, "localhost"); + strcpy(postEventList[i].post_host_port, accountData[0].account_aida_port); + strcpy(postEventList[i].post_url, "/ptzpreset?camid=1&ai_goto_preset=1"); + strcpy(postEventList[i].post_username, "admin"); + strcpy(postEventList[i].post_password, "Pass1234"); + strcpy(postEventList[i].post_content, ""); + strcpy(postEventList[i].post_customized_header, ""); + strcpy(postEventList[i].post_sequence, ""); + strcpy(postEventList[i].post_file_format, "text"); + strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); + strcpy(postEventList[i].post_jpeg_file_name, "snap"); + strcpy(postEventList[i].post_timeout, "5"); + + new_data_write_to_events_file_flag = 1; + } + +#ifdef GY_OS_V_SERIES + +#else + event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + strcpy(eventCounterList[i].counter_name, counter_name->valuestring); + + if (counter_cust_name) + strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); + else { + strcpy(eventCounterList[i].counter_cust_name, eventCounterList[i].counter_name); + new_data_write_to_events_file_flag = 1; + } + strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); + if (reset_value) + eventCounterList[i].reset_value = atoi(reset_value->valuestring); + else { + eventCounterList[i].reset_value = 0; + new_data_write_to_events_file_flag = 1; + } + strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_at, reset_at->valuestring); + strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); + strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); + strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); + struct tm tm; + strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetResetAt = mktime(&tm); + + struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); + eventCounterList[i].reset_month = resetTime->tm_mon; + eventCounterList[i].reset_month_day = resetTime->tm_mday; + eventCounterList[i].reset_week_day = resetTime->tm_wday; + eventCounterList[i].reset_hour = resetTime->tm_hour; + eventCounterList[i].reset_min = resetTime->tm_min; + eventCounterList[i].reset_sec = resetTime->tm_sec; + strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeFrom = mktime(&tm); + strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeTo = mktime(&tm); + + if (link_to_post_event_name) { + strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].link_to_post_event_name, ""); + } + + if (post_interval) { + strcpy(eventCounterList[i].post_interval, post_interval->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].post_interval, "5 minutes"); + } + + if (enable_reset_only_cloud) { + strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); + } + + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); + } + + i++; + } + if (i < 8) { + new_data_write_to_events_file_flag = 1; + } + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + + if (report_counters) { + i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + if (counter_a) { + strcpy(reportCounterList[i].counter_a, counter_a->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a, "Counter01"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_a_name) { + strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_name, "Name"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_a_zone) { + strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_a_zone, "1"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_b) { + strcpy(reportCounterList[i].counter_b, counter_b->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b, ""); + new_data_write_to_events_file_flag = 1; + } + + if (counter_b_name) { + strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_name, ""); + new_data_write_to_events_file_flag = 1; + } + + if (counter_b_zone) { + strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); + } + else { + strcpy(reportCounterList[i].counter_b_zone, "0"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_c_name) { + strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); + } + else { + strcpy(reportCounterList[i].counter_c_name, ""); + new_data_write_to_events_file_flag = 1; + } + + if (report_max_value) { + strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); + } + else { + strcpy(reportCounterList[i].report_max_value, "100"); + new_data_write_to_events_file_flag = 1; + } + + if (enable_report) { + strcpy(reportCounterList[i].enable_report, enable_report->valuestring); + } + else { + strcpy(reportCounterList[i].enable_report, "No"); + new_data_write_to_events_file_flag = 1; + } + + if (counter_mode) { + strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); + } + else { + strcpy(reportCounterList[i].counter_mode, "0"); + new_data_write_to_events_file_flag = 1; + } + + if (initial_icon) { + strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); + } + else { + strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); + new_data_write_to_events_file_flag = 1; + } + + if (detection_output) { + strcpy(reportCounterList[i].detection_output, detection_output->valuestring); + } + else { + strcpy(reportCounterList[i].detection_output, "No entry for cars"); + new_data_write_to_events_file_flag = 1; + } + + if (output_icon) { + strcpy(reportCounterList[i].output_icon, output_icon->valuestring); + } + else { + strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); + new_data_write_to_events_file_flag = 1; + } + + i++; + } + } + + if (i < MAX_REPORT_COUNTERS) { + for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + + new_data_write_to_events_file_flag = 1; + } + } + else { + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + strcpy(reportCounterList[index_report].counter_a, "Counter01"); + strcpy(reportCounterList[index_report].counter_a_name, "Name"); + strcpy(reportCounterList[index_report].counter_a_zone, "1"); + strcpy(reportCounterList[index_report].counter_b, ""); + strcpy(reportCounterList[index_report].counter_b_name, ""); + strcpy(reportCounterList[index_report].counter_b_zone, "0"); + strcpy(reportCounterList[index_report].counter_c_name, ""); + strcpy(reportCounterList[index_report].report_max_value, "100"); + strcpy(reportCounterList[index_report].enable_report, "No"); + strcpy(reportCounterList[index_report].counter_mode, "0"); + strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); + strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); + strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); + } + + new_data_write_to_events_file_flag = 1; + } + + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + + if (snmp_management) { + i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + if (snmp_event_name) { + strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); + } + else { + char temp_name[10] = { 0 }; + sprintf(temp_name, "SNMP %d", i + 1); + strcpy(SNMPManagementList[i].snmp_event_name, temp_name); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_version) { + strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_version, "v1"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_group_name) { + strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_group_name, "public"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_host_ip) { + strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_host_port) { + strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_host_port, "161"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_oid) { + strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_value) { + strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_value, "mylocation"); + new_data_write_to_events_file_flag = 1; + } + + if (snmp_type) { + strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); + } + else { + strcpy(SNMPManagementList[i].snmp_type, "string"); + new_data_write_to_events_file_flag = 1; + } + + SNMPManagementList[i].check_if_delivering = 0;//La褣Al + i++; + } + } + + if (i < MAX_SNMP_MANAGEMENT) { + for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + + SNMPManagementList[index_snmp].check_if_delivering = 0;//La褣Al + } + + new_data_write_to_events_file_flag = 1; + } + } + else { + for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + char temp_name[10] = { 0 }; + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(temp_name, "SNMP %d", index_snmp + 1); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + else { + sprintf(temp_name, "%s", "Heartbeat"); + strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); + strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); + strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); + strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); + strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); + strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); + strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); + strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); + } + + SNMPManagementList[index_snmp].check_if_delivering = 0;//La褣Al + } + + new_data_write_to_events_file_flag = 1; + } + +#endif + + email_setting = cJSON_GetObjectItem(n_root, "email_setting"); + if (email_setting) { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) { + strcpy(emailData.email_content, email_content->valuestring); + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + } + else { + new_data_write_to_events_file_flag = 1; + strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); + } + } + //printf("111-7 3 get password = %s \n", accountData[0].account_password); + //trigger events settings + //cJSON* cam_ip, * http_port, * video_port, * cam_pwd, * channel_id; + cJSON *view_setting, *camera, *camera_name, *enable_anpr, *enable_face, *enable_traffic, *enable_logo, *tab_view_size, *enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, + *enable_track,*enable_PTZ, *ptz_tracking_fov_min, *ptz_tracking_fov_max, *ptz_enable_tracking, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, + *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, + *cJSON_enable_only_show_metadata1, + *count_zone, *ivs_mode, *detection_zone, *detect, *ptz_tracking_mode, + *levenshtein_distance, *min_characters, *max_characters, *obj_min_proportion, *obj_max_proportion, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, + *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, + *point_number, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5 = NULL, *y5, *x6 = NULL, *y6, + *ptz_zone_to_preset = NULL, + *enable_speed, *set_distance, *world_distance_unit, *world_distance_side1, *world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, + *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered, *unknown_object_max_proportion, *unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object, *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, + *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; + + //root = cJSON_Parse(fileBuf); + view_setting = cJSON_GetObjectItem(root, "view_setting"); + + //printf("111-7 get password = %s \n", accountData[0].account_password); + + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + /*cam_ip = cJSON_GetObjectItem(camera, "ip"); + http_port = cJSON_GetObjectItem(camera, "http_port"); + video_port = cJSON_GetObjectItem(camera, "video_port"); + cam_username = cJSON_GetObjectItem(camera, "username"); + cam_pwd = cJSON_GetObjectItem(camera, "password"); + channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + + plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); + plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); + plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); + + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + + if (plate_filter_times) + viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); + else { + viewChannelData[n].i_plate_filter_times = 4; + new_data_write_to_config_file_flag = 1; + } + + if (plate_filter_time) + viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); + else { + viewChannelData[n].i_plate_filter_time = 3; + new_data_write_to_config_file_flag = 1; + } + + if (plate_free_time) + viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); + else { + viewChannelData[n].i_plate_free_time = 3; + new_data_write_to_config_file_flag = 1; + } + + strcpy(viewChannelData[n].confidence, confidence->valuestring); + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + + if (count_zone) + viewChannelData[n].count_zone = count_zone->valueint; + else { + viewChannelData[n].count_zone = 1; + new_data_write_to_config_file_flag = 1; + } + //printf("\nenable_lpr_db-----8\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + if (enable_lpr_db) + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + else { + strcpy(viewChannelData[n].enable_lpr_db, "Yes"); + new_data_write_to_config_file_flag = 1; + } + pthread_mutex_unlock(&mutex_enable_lpr_db); + + enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); + if (enable_downsized_cropped_roi) { + set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); + } + else { + set_enable_downsized_cropped_roi(1); + new_data_write_to_config_file_flag = 1; + } + + enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); + if (enable_zone_crop_1) { + set_enable_zone_crop_1(enable_zone_crop_1->valueint); + } + else { + set_enable_zone_crop_1(0); + new_data_write_to_config_file_flag = 1; + } + + enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); + if (enable_add_face_frequent_list) + if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) + viewChannelData[n].enable_add_face_frequent_list = 1; + else + viewChannelData[n].enable_add_face_frequent_list = 0; + else { + viewChannelData[n].enable_add_face_frequent_list = 1; + new_data_write_to_config_file_flag = 1; + } + enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); + if (enable_PTZ) + strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); + else { + strcpy(viewChannelData[n].enable_PTZ, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_track = cJSON_GetObjectItem(camera, "enable_track"); + if (enable_track) + strcpy(viewChannelData[n].enable_track, enable_track->valuestring); + else { + strcpy(viewChannelData[n].enable_track, "No"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); + if (ptz_tracking_fov_min) + strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); + else { + strcpy(viewChannelData[n].ptz_tracking_fov_min, "0"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); + if (ptz_tracking_fov_max) + strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); + else { + strcpy(viewChannelData[n].ptz_tracking_fov_max, "40"); + new_data_write_to_config_file_flag = 1; + } + + ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); + if (ptz_enable_tracking) + strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); + else { + strcpy(viewChannelData[n].ptz_enable_tracking, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + //Tracking MODE + //1: First in First out + //2: Bigger first + //3: All + ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); + if (ptz_tracking_mode) + viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); + else + { + viewChannelData[n].ptz_tracking_mode = 1; + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); + if (ptz_tracking_by_enter_zone) { + if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + else + viewChannelData[n].ptz_tracking_by_enter_zone = 0; + } + else { + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + new_data_write_to_config_file_flag = 1; + } + + enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); + if (enable_tracking_limits) + strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); + else { + strcpy(viewChannelData[n].enable_tracking_limits, "No"); + new_data_write_to_config_file_flag = 1; + } + + ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); + if (ptz_pan_left_limit) + strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); + new_data_write_to_config_file_flag = 1; + } + + ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); + if (ptz_pan_right_limit) + strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); + if (ptz_tilt_up_limit) + strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); + new_data_write_to_config_file_flag = 1; + } + + ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); + if (ptz_tilt_down_limit) + strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); + else { + strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); + new_data_write_to_config_file_flag = 1; + } + + ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); + if (ptz_speed) + strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); + else { + strcpy(viewChannelData[n].ptz_speed, "3"); + new_data_write_to_config_file_flag = 1; + } + + enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); + if (enable_unknown_object) + strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_unknown_object, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); + if (enable_ivs_person_detection) + strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); + new_data_write_to_config_file_flag = 1; + } + + assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); + if (assign_ivs_object_to) + strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); + else { + strcpy(viewChannelData[n].assign_ivs_object_to, ""); + new_data_write_to_config_file_flag = 1; + } + + enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); + if (enable_ambulance) + strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); + else { + strcpy(viewChannelData[n].enable_ambulance, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); + if (enable_blank_plate) + strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); + else { + strcpy(viewChannelData[n].enable_blank_plate, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); + if (enable_stop_sign) + strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); + else { + strcpy(viewChannelData[n].enable_stop_sign, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); + if (enable_show_unknown_object) + strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].enable_show_unknown_object, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); + if (enable_ivs_fix_mode) + strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); + if (enable_ivs_and_ai) + strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); + else { + strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); + new_data_write_to_config_file_flag = 1; + } + + enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); + if (enable_lpr_upon_triggered) + strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); + new_data_write_to_config_file_flag = 1; + } + + dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); + if (dwell_lpr_upon_triggered) + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); + else { + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); + new_data_write_to_config_file_flag = 1; + } + + ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); + if (ivs_mode) + strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); + else { + strcpy(viewChannelData[n].ivs_mode, "3"); + new_data_write_to_config_file_flag = 1; + } + + unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); + if (unknown_object_max_proportion) + strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); + else { + strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); + new_data_write_to_config_file_flag = 1; + } + + unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); + if (unknown_object_min_proportion) + strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); + else { + strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); + new_data_write_to_config_file_flag = 1; + } + + confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); + if (confidence_unknown_object) + strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].confidence_unknown_object, "0"); + new_data_write_to_config_file_flag = 1; + } + + confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); + if (confidence2_unknown_object) + strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].confidence2_unknown_object, "0"); + new_data_write_to_config_file_flag = 1; + } + + dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); + if (dwell_unknown_object) + strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); + else { + strcpy(viewChannelData[n].dwell_unknown_object, "30"); + new_data_write_to_config_file_flag = 1; + } + + dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); + if (dwell_minute_focus_on) + strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); + else { + strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); + new_data_write_to_config_file_flag = 1; + } + + person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); + if (person_obj_fov) + strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); + else { + strcpy(viewChannelData[n].person_obj_fov, "100"); + new_data_write_to_config_file_flag = 1; + } + + getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); + if (getnetwork_buffer_id) + strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); + else { + strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); + new_data_write_to_config_file_flag = 1; + } + + red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); + if (red_light_zone) + strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); + else { + strcpy(viewChannelData[n].red_light_zone, ""); + new_data_write_to_config_file_flag = 1; + } + + no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); + if (no_give_way_zone_to_protect) + strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); + new_data_write_to_config_file_flag = 1; + } + + no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); + if (no_give_way_zone_to_keep_away) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); + new_data_write_to_config_file_flag = 1; + } + + + no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); + if (no_give_way_zone_to_protect_2) + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); + new_data_write_to_config_file_flag = 1; + } + + no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); + if (no_give_way_zone_to_keep_away_2) + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); + else { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); + new_data_write_to_config_file_flag = 1; + } + + ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); + if (ptz_sensitivity) + viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); + else + { + viewChannelData[n].ptz_sensitivity = 6; + new_data_write_to_config_file_flag = 1; + } + + ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); + if (ptz_tracking_resume_dwell) + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); + else { + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, "3"); + new_data_write_to_config_file_flag = 1; + } + + cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); + if (cJSON_enable_only_show_metadata1) + enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; + else { + enable_only_show_metadata1 = 0; + new_data_write_to_config_file_flag = 1; + } + + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + //printf("\n[run_server]tab_view_size: %s\n", tab_view_size->valuestring); + char outArray[2][STRSPLIT_SIZE]={0}; + char temp_tab[50] = { 0 }; + strcpy(temp_tab, tab_view_size->valuestring); + StrSplit(temp_tab, outArray, "x"); + //printf("\n------UU:16\n"); + viewChannelData[n].channel_idx = n; + if (outArray[0]) + viewChannelData[n].tab_view_width = atoi(outArray[0]); + else + new_data_write_to_config_file_flag = 1; + if (outArray[1]) + viewChannelData[n].tab_view_height = atoi(outArray[1]); + else + new_data_write_to_config_file_flag = 1; + + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + + + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + if (enable_face) { + if (strcmp(enable_face->valuestring, "Yes") == 0) + viewChannelData[n].enable_face = 1; + else + viewChannelData[n].enable_face = 0; + } + else { + new_data_write_to_config_file_flag = 1; + viewChannelData[n].enable_face = 1; + } + + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + + detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + + viewChannelData[n].enable_traffic_light_zone = 0; + + int i = 0; + + cJSON_ArrayForEach(detect, detection_zone) + { + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); + obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); + obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); + + enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); + enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); + enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); + parking_space = cJSON_GetObjectItem(detect, "parking_space"); + parking_line = cJSON_GetObjectItem(detect, "parking_line"); + set_distance = cJSON_GetObjectItem(detect, "set_distance"); + world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); + world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); + world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); + world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); + + if (obj_max_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); + else { + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, "80"); + new_data_write_to_config_file_flag = 1; + } + + if (obj_min_proportion_in_zone) + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); + else { + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (ptz_zone_to_preset) + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); + else { + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_speed) + strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); + else { + strcpy(viewDetectionZone[n][i].enable_speed, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_radar_speed) + strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); + else { + strcpy(viewDetectionZone[n][i].enable_radar_speed, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_ivs_zone) + strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); + else { + strcpy(viewDetectionZone[n][i].enable_ivs_zone, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (parking_space) { + viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); + } + else { + viewDetectionZone[n][i].parking_space = 0; + new_data_write_to_config_file_flag = 1; + } + + if (parking_line) { + viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); + } + else { + viewDetectionZone[n][i].parking_line = 0; + new_data_write_to_config_file_flag = 1; + } + + if (set_distance) { + viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); + } + else { + viewDetectionZone[n][i].set_distance = 10; + new_data_write_to_config_file_flag = 1; + } + + if (world_distance_unit) + strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); + else { + strcpy(viewDetectionZone[n][i].world_distance_unit, "meter"); + new_data_write_to_config_file_flag = 1; + } + + if (world_distance_side1) + { + viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); + viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); + viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); + } + else { + viewDetectionZone[n][i].world_distance_side1 = 10; + viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; + viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; + + new_data_write_to_config_file_flag = 1; + } + //printf("[%d]World dis 1 = %f \n", i, viewDetectionZone[n][i].world_distance_side1); + + if (world_distance_side2) + { + viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); + viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); + viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); + } + else { + viewDetectionZone[n][i].world_distance_side2 = 10; + viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; + viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; + new_data_write_to_config_file_flag = 1; + } + //printf("[%d]World dis 2 = %f \n", i, viewDetectionZone[n][i].world_distance_side2); + + viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); + viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); + + if (world_time_unit) + strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); + else { + strcpy(viewDetectionZone[n][i].world_time_unit, "KPH"); + new_data_write_to_config_file_flag = 1; + } + + trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); + + point_number = cJSON_GetObjectItem(detect, "point_number"); + /* + if (point_number) + printf("load point number 2 = %d \n", point_number->valueint); + */ + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + + if (metadata_stop) + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + else { + strcpy(viewDetectionZone[n][i].metadata_stop, ""); + new_data_write_to_config_file_flag = 1; + } + + if (no_parking_time) + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + else { + viewDetectionZone[n][i].no_parking_time = 5; + new_data_write_to_config_file_flag = 1; + } + + if (no_parking_time_in_minute) + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + else { + viewDetectionZone[n][i].no_parking_time_in_minute = 0; + new_data_write_to_config_file_flag = 1; + } + + if (queuing_count && strlen(queuing_count->valuestring) >= 1) + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + else { + viewDetectionZone[n][i].queuing_count = 1; + new_data_write_to_config_file_flag = 1; + } + + if (point_number) + viewDetectionZone[n][i].point_num = point_number->valueint; + else { + viewDetectionZone[n][i].point_num = 6; + new_data_write_to_config_file_flag = 1; + } + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].Points[3].y = y4->valueint; + + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + + if (x5 && x6) + { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].Points[5].y = y6->valueint; + + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + } + else + new_data_write_to_config_file_flag = 1; + + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; + //UpdateTrafficLightZone(n); + } + +#ifdef GY_OS_AMBA + if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) + { + int social_zone_idx = i; + if (social_zone_idx >= 0) + { + pthread_mutex_lock(&mutex_perspective_transform); + if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); + viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); + pthread_mutex_unlock(&mutex_perspective_transform); + } + } +#endif + + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + int original_zone_size = i; + + //int arraySize = cJSON_GetArraySize(detection_zone); + + int k = 0; + for (int j = 0; j < MAX_DETECTION_ZONE && j < original_zone_size; j++) + { + k = 0; + + cJSON_ArrayForEach(detect, trigger_events[j]) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + if (!detect_event_id || !detect_event_name || strlen(detect_event_id->valuestring) == 0 || strlen(detect_event_name->valuestring) == 0) { + new_data_write_to_config_file_flag = 1; + } + else { + viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + k++; + } + if (k < MAX_TRIGGER_EVENT) { + + if(k < 10) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00800000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Visitor list"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 11) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x01000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Unattended object or missing object"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 12) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x02000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "BG learning"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 13) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x04000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Tampering detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 14) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x40000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "All objects detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 15) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x80000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lack of any object detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 16) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00002000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Over speed detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 17) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00004000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lower speed detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 18) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000400"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Running red lights"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 19) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000800"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning left on red"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 20) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00001000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning right on red"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 21) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00008000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Forget to give way detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 22) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00040000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Distance violation"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + if (k < 23) { + viewDetectionZone[n][j].trigger_event[k].checked = 0; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x08000000"); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Height detection"); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + + new_data_write_to_config_file_flag = 1; + } + } + + if (original_zone_size < MAX_DETECTION_ZONE) { + for (int index_zone = original_zone_size; index_zone < MAX_DETECTION_ZONE; index_zone++) { + strcpy(viewDetectionZone[n][index_zone].obj_max_proportion_in_zone, "80"); + strcpy(viewDetectionZone[n][index_zone].obj_min_proportion_in_zone, "0"); + strcpy(viewDetectionZone[n][index_zone].ptz_zone_to_preset, "0"); + strcpy(viewDetectionZone[n][index_zone].enable_speed, "No"); + strcpy(viewDetectionZone[n][index_zone].enable_radar_speed, "No"); + strcpy(viewDetectionZone[n][index_zone].enable_ivs_zone, "No"); + viewDetectionZone[n][index_zone].parking_space = 0; + viewDetectionZone[n][index_zone].parking_line = 0; + viewDetectionZone[n][index_zone].set_distance = 10; + strcpy(viewDetectionZone[n][index_zone].world_distance_unit, "meter"); + viewDetectionZone[n][index_zone].world_distance_side1 = 10; + viewDetectionZone[n][index_zone].world_distance[0] = viewDetectionZone[n][index_zone].world_distance_side1; + viewDetectionZone[n][index_zone].world_distance[2] = viewDetectionZone[n][index_zone].world_distance_side1; + viewDetectionZone[n][index_zone].world_distance_side2 = 10; + viewDetectionZone[n][index_zone].world_distance[1] = viewDetectionZone[n][index_zone].world_distance_side2; + viewDetectionZone[n][index_zone].world_distance[3] = viewDetectionZone[n][index_zone].world_distance_side2; + strcpy(viewDetectionZone[n][index_zone].world_time_unit, "KPH"); + strcpy(viewDetectionZone[n][index_zone].detection_time, ""); + strcpy(viewDetectionZone[n][index_zone].metadata1, ""); + strcpy(viewDetectionZone[n][index_zone].metadata2, ""); + strcpy(viewDetectionZone[n][index_zone].metadata_stop, ""); + strcpy(viewDetectionZone[n][index_zone].link_to_counter, ""); + strcpy(viewDetectionZone[n][index_zone].enable_direction1, "No"); + strcpy(viewDetectionZone[n][index_zone].enable_direction2, ""); + strcpy(viewDetectionZone[n][index_zone].direction1, "1"); + strcpy(viewDetectionZone[n][index_zone].direction2, ""); + viewDetectionZone[n][index_zone].no_parking_time = 5; + viewDetectionZone[n][index_zone].no_parking_time_in_minute = 0; + viewDetectionZone[n][index_zone].queuing_count = 1; + viewDetectionZone[n][index_zone].point_num = 6; + + viewDetectionZone[n][index_zone].Points[0].x = 19; + viewDetectionZone[n][index_zone].Points[0].y = 16; + viewDetectionZone[n][index_zone].Points[1].x = 19; + viewDetectionZone[n][index_zone].Points[1].y = 250; + viewDetectionZone[n][index_zone].Points[2].x = 19; + viewDetectionZone[n][index_zone].Points[2].y = 484; + viewDetectionZone[n][index_zone].Points[3].x = 870; + viewDetectionZone[n][index_zone].Points[3].y = 484; + viewDetectionZone[n][index_zone].Points[4].x = 870; + viewDetectionZone[n][index_zone].Points[4].y = 250; + viewDetectionZone[n][index_zone].Points[5].x = 870; + viewDetectionZone[n][index_zone].Points[5].y = 16; + + viewDetectionZone[n][index_zone].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].y, CANVAS_HEIGHT / 2); + viewDetectionZone[n][index_zone].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].x, CANVAS_WIDTH / 2); + viewDetectionZone[n][index_zone].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].y, CANVAS_HEIGHT / 2); + + strcpy(viewDetectionZone[n][index_zone].enable_traffic_light, ""); + + for (int index_trigger = 0; index_trigger < MAX_TRIGGER_EVENT; index_trigger++) { + viewDetectionZone[n][index_zone].trigger_event[index_trigger].checked = 0; + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_id, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_id); + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_name, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_name); + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].post_event_name, ""); + strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_name, ""); + viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_increment = -2; + } + } + + new_data_write_to_config_file_flag = 1; + } + } + + //cJSON* cnn_device[MAX_LAYER_NUM]; + cJSON* system_setting/*, *load_cnn_type*/, *display_dash, *display_properties,*display_OSD/*, *enable_log*/, *overlap_thresh, *confidence_thresh,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage, + *enable_person_independent,*enable_onvif_profile_m,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language, + *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran,*osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, + *enable_email_notification,*enable_system_logs,*enable_email_jpeg,*email_reset_time_interval,*sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; + cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; + + + system_setting = cJSON_GetObjectItem(root, "system_setting"); + //cJSON* api_version = cJSON_GetObjectItem(system_setting, "api version"); + //load_cnn_type = cJSON_GetObjectItem(system_setting, "cnn type"); + overlap_thresh = cJSON_GetObjectItem(system_setting, "overlap thresh"); + confidence_thresh = cJSON_GetObjectItem(system_setting, "confidence thresh"); + enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); + enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); + nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); + tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); + cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); + enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); + enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); + enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); + enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); + cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); + cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); + cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); + cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); + cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); + cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); + cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); + language = cJSON_GetObjectItem(system_setting, "language"); + enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); + enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); + enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); + force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); + force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); + enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); + enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); + ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); + + enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); + cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); + cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); + enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); + cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); + cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); + + enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); + enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); + getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); + getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); + osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); + osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); + osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); + enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); + osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); + osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); + sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); + enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); + external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); + external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); + external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); + external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); + enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); + enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); + email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); + enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); + + enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); + ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); + ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); + ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); + ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); + ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); + ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); + ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); + + if (enable_person_independent) + strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); + else { + strcpy(SystemSetting.enable_person_independent, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_onvif_profile_m) + strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); + else { + strcpy(SystemSetting.enable_onvif_profile_m, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (nms_thres) + strcpy(SystemSetting.nms_thres, nms_thres->valuestring); + else { + strcpy(SystemSetting.nms_thres, "10"); + new_data_write_to_config_file_flag = 1; + } + + if (tracking_id_dwell) + strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); + else { + strcpy(SystemSetting.tracking_id_dwell, "5"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_enable_snap) + strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); + else { + strcpy(SystemSetting.cloud_enable_snap, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_cloud) + strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); + else { + strcpy(SystemSetting.enable_cloud, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_special_edition) + strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); + else { + strcpy(SystemSetting.enable_special_edition, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_python) + strcpy(SystemSetting.enable_python, enable_python->valuestring); + else { + strcpy(SystemSetting.enable_python, "No"); + new_data_write_to_config_file_flag = 1; + } + if (enable_python_file) + { + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + + if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { + perror("check current runpython thread failed\n"); + exit(EXIT_FAILURE); + } + } + else { + strcpy(SystemSetting.enable_python_file, "No python running."); + new_data_write_to_config_file_flag = 1; + } + if (enable_low_cpu_usage) + strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); + else { + strcpy(SystemSetting.enable_low_cpu_usage, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_enable_notification) + strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); + else { + strcpy(SystemSetting.cloud_enable_notification, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_account) + strcpy(SystemSetting.cloud_account, cloud_account->valuestring); + else { + strcpy(SystemSetting.cloud_account, "myaccount@mail.com"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_password) + strcpy(SystemSetting.cloud_password, cloud_password->valuestring); + else { + strcpy(SystemSetting.cloud_password, "mypass"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_notification_dwell) + strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); + else { + strcpy(SystemSetting.cloud_notification_dwell, "60"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_statue) + strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); + else { + strcpy(SystemSetting.cloud_statue, ""); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_v2_statue) + strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); + else { + strcpy(SystemSetting.cloud_v2_statue, ""); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_record_v2_statue) + strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); + else { + strcpy(SystemSetting.cloud_record_v2_statue, ""); + new_data_write_to_config_file_flag = 1; + } + + if (enable_special_char) + strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); + else + { + strcpy(SystemSetting.enable_special_char, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_bounding_box) + strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); + else + { + strcpy(SystemSetting.enable_bounding_box, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_dwell_bounding_box) + strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); + else + { + strcpy(SystemSetting.enable_dwell_bounding_box, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (force_i_to_one) + strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); + else + { + strcpy(SystemSetting.force_i_to_one, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (force_o_to_zero) + strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); + else + { + strcpy(SystemSetting.force_o_to_zero, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_plate_angle_correction) + strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); + else + { + strcpy(SystemSetting.enable_plate_angle_correction, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_ai_mirror) + strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); + else + { + strcpy(SystemSetting.enable_ai_mirror, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (ai_mirror_feature) + strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); + else + { + strcpy(SystemSetting.ai_mirror_feature, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_cloud_v2) + strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); + else + { + strcpy(SystemSetting.enable_cloud_v2, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_v2_notification_dwell) + strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); + else + { + strcpy(SystemSetting.cloud_v2_notification_dwell, "60"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_v2_content) + strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); + else + { + strcpy(SystemSetting.cloud_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_cloud_record_v2) + strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); + else + { + strcpy(SystemSetting.enable_cloud_record_v2, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_record_v2_notification_dwell) + strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); + else + { + strcpy(SystemSetting.cloud_record_v2_notification_dwell, "60"); + new_data_write_to_config_file_flag = 1; + } + + if (cloud_record_v2_content) + strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); + else + { + strcpy(SystemSetting.cloud_record_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_post_only_if_both_detected) + strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); + else + { + strcpy(SystemSetting.enable_post_only_if_both_detected, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_getalarmmotion_snap) + strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); + else + { + strcpy(SystemSetting.enable_getalarmmotion_snap, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (getimage_encoder_id) + strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); + else + { +#ifdef GY_OS_NOVA + strcpy(SystemSetting.getimage_encoder_id, "3"); +#endif + +#ifdef GY_OS_AMBA + strcpy(SystemSetting.getimage_encoder_id, "4"); +#endif + new_data_write_to_config_file_flag = 1; + } + + if (getimage_encoder_id_HD) + strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); + else + { +#ifdef GY_OS_NOVA + strcpy(SystemSetting.getimage_encoder_id_HD, "0"); +#endif +#ifdef GY_OS_AMBA + strcpy(SystemSetting.getimage_encoder_id_HD, "4"); +#endif + + new_data_write_to_config_file_flag = 1; + } + + if (osd_encoder_id) + strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); + else + { + strcpy(SystemSetting.osd_encoder_id, "2"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_font_size) + strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); + else + { + strcpy(SystemSetting.osd_font_size, "26"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_outline_lilin) + strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); + else + { + strcpy(SystemSetting.osd_outline_lilin, "4"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_osd_bottom) + strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); + else + { + strcpy(SystemSetting.enable_osd_bottom, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_bottom_bg_tran) + strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); + else + { + strcpy(SystemSetting.osd_bottom_bg_tran, "255"); + new_data_write_to_config_file_flag = 1; + } + + if (osd_bottom_content) + strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); + else + { + strcpy(SystemSetting.osd_bottom_content, "Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>"); + new_data_write_to_config_file_flag = 1; + } + + if (sensors_type) + strcpy(SystemSetting.sensors_type, sensors_type->valuestring); + else + { + strcpy(SystemSetting.sensors_type, "0"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_sync_external_lpr_db) + strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); + else + { + strcpy(SystemSetting.enable_sync_external_lpr_db, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_IP) + strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_IP, "192.168.0.200"); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_port) + strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_port, accountData[0].account_aida_port); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_username) + strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_username, "admin"); + new_data_write_to_config_file_flag = 1; + } + + if (external_lpr_db_password) + strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); + else + { + strcpy(SystemSetting.external_lpr_db_password, "pass"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_system_logs) + strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); + else + { + strcpy(SystemSetting.enable_system_logs, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_email_jpeg) + strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); + else + { + strcpy(SystemSetting.enable_email_jpeg, "Yes"); + new_data_write_to_config_file_flag = 1; + } + + if (email_reset_time_interval) + strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); + else + { + strcpy(SystemSetting.email_reset_time_interval, ""); + new_data_write_to_config_file_flag = 1; + } + + if (enable_ftp) + strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); + else + { + strcpy(SystemSetting.enable_ftp, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_url) + strcpy(SystemSetting.ftp_url, ftp_url->valuestring); + else + { + strcpy(SystemSetting.ftp_url, "ftp.example.com"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_port) + strcpy(SystemSetting.ftp_port, ftp_port->valuestring); + else + { + strcpy(SystemSetting.ftp_port, "21"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_username) + strcpy(SystemSetting.ftp_username, ftp_username->valuestring); + else + { + strcpy(SystemSetting.ftp_username, ""); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_password) + strcpy(SystemSetting.ftp_password, ftp_password->valuestring); + else + { + strcpy(SystemSetting.ftp_password, ""); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_remote_directory) + strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); + else + { + strcpy(SystemSetting.ftp_remote_directory, "myfolder/myfile"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_jpeg_file_name_format) + strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); + else + { + strcpy(SystemSetting.ftp_jpeg_file_name_format, "fixed"); + new_data_write_to_config_file_flag = 1; + } + + if (ftp_jpeg_file_name) + strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); + else + { + strcpy(SystemSetting.ftp_jpeg_file_name, "snap"); + new_data_write_to_config_file_flag = 1; + } + + if (enable_email_notification) + strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); + else + { + strcpy(SystemSetting.enable_email_notification, "No"); + new_data_write_to_config_file_flag = 1; + } + + if (language) + strcpy(SystemSetting.language, language->valuestring); + else { + strcpy(SystemSetting.language, "en_gb"); + new_data_write_to_config_file_flag = 1; + } + + + display_properties = cJSON_GetObjectItem(system_setting, "display properties"); + if (display_properties) + strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); + else { + strcpy(SystemSetting.enable_display_properties, "No"); + new_data_write_to_config_file_flag = 1; + } + + display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); + if (display_OSD) + strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); + else { + strcpy(SystemSetting.enable_display_OSD, "No"); + new_data_write_to_config_file_flag = 1; + } + + //enable_log = cJSON_GetObjectItem(system_setting, "enable log"); + //api_format_ver = atoi(api_version->valuestring); + + overlap_ratio_limit = 75; + if (overlap_thresh) + overlap_ratio_limit = overlap_thresh->valuedouble; + + confidence_limit = 0; + stAMBAcontent.confidence_plate = 0; + stAMBAcontent.confidence_traffic = 0; + if (confidence_thresh) + { + confidence_limit = confidence_thresh->valuedouble; + stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; + stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; + } + + display_dash = cJSON_GetObjectItem(system_setting, "display dash"); + activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + + activeDisplayProperties = (strcmp(display_properties->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + + //printf("111-6 get password = %s \n", accountData[0].account_password); + + //20201027 sophia add + //account settings + cJSON *account_setting, *account_data; + account_setting = cJSON_GetObjectItem(root, "account_setting"); + account_data = cJSON_GetObjectItem(account_setting, "account_data"); + +#if 1 + { + //ѽXaccount_data - step 1:base64 decode + size_t base64_decode_length = 0; + unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; + char DecryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + base64_decode(account_data->valuestring, strlen(account_data->valuestring), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //ѽXaccount_data - step 2:AES descrytion + KeyExpansion(key, expandedKey); + AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); + //printf("account_data descrytion OK.\n"); +#ifdef _DEBUG_AMBA + printf("account_data = %s \n", DecryptKeyData); +#endif + + //oaccount_dataXT + cJSON *keyRoot, *detect; + cJSON *account_username, *account_password, *account_type, *account_status; + keyRoot = cJSON_Parse(DecryptKeyData); + int i = 0; + cJSON_ArrayForEach(detect, keyRoot) + { + account_username = cJSON_GetObjectItem(detect, "account_username"); + account_password = cJSON_GetObjectItem(detect, "account_password"); + account_type = cJSON_GetObjectItem(detect, "account_type"); + account_status = cJSON_GetObjectItem(detect, "account_status"); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)account_username->valuestring, strlen(account_username->valuestring), (unsigned char *)temp_account, 512); + + memcpy(accountData[i].account_username, temp_account, strlen(temp_account)); + accountData[i].account_username[strlen(temp_account)] = '\0'; + + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)account_password->valuestring, strlen(account_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(accountData[i].account_password, temp_account2, strlen(temp_account2)); + accountData[i].account_password[strlen(temp_account2)] = '\0'; + + + //printf("111-6-0 get password = %s \n", account_password->valuestring); + //printf("111-6-0 password size = %d \n", strlen(account_password->valuestring)); + + //printf("111-6-1 get password = %s \n", accountData[i].account_password); + //printf("111-6-1 password size = %d \n", strlen(accountData[i].account_password)); + + //strcpy(accountData[i].account_username, account_username->valuestring); + //strcpy(accountData[i].account_password, account_password->valuestring); + accountData[i].account_type = account_type->valueint; + accountData[i].account_status = account_status->valueint; + + //printf("111-6-2 get password = %s \n", accountData[i].account_password); + +#ifdef _DEBUG_AMBA + printf("\naccountData[%d].account_username:%s", i, accountData[i].account_username); + printf("\naccountData[%d].account_password:%s", i, accountData[i].account_password); + printf("\naccountData[%d].account_type:%d", i, accountData[i].account_type); + printf("\naccountData[%d].account_status:%d", i, accountData[i].account_status); +#endif + + i++; + } + if (keyRoot) { + cJSON_Delete(keyRoot); + keyRoot = NULL; + } + } +#endif + + overlap_ratio_limit = 75; + if (overlap_thresh) + overlap_ratio_limit = overlap_thresh->valuedouble; + + confidence_limit = 0; + stAMBAcontent.confidence_plate = 0; + stAMBAcontent.confidence_traffic = 0; + if (confidence_thresh) + { + confidence_limit = confidence_thresh->valuedouble; + stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; + stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; + } + + { + char* fileBuf = ReadAllBytes(emailsPATH); + + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (root) + { + cJSON *auth_password; + auth_password = cJSON_GetObjectItem(root, "auth_password"); + + if (auth_password && strlen(auth_password->valuestring) >= 1) + { + size_t base64_decode_length = 0; + char EncryptKeyData[256]; + char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + char temp_auth_password[256] = { 0 }; + memcpy(temp_auth_password, auth_password->valuestring, strlen(auth_password->valuestring)); + + //KeyExpansion(key_email, expandedKey_email); + //int decryptSize = AESDecryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); + + base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + strcpy(IPCAMService.auth_password, EncryptKeyData); + + //printf("\n-------------temp_auth_password:%s\n", temp_auth_password); + //printf("\n-------------DecryptKeyData:%s\n", DecryptKeyData); + //printf("\n-------------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); + + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else { + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + printf("\nFail to read emailsPATH or emails.json\n"); + } + } + + //printf("\n---------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); + + //printf("GYNet Version=%s\n", APP_VERSION); + //printf("LicenseType=%s\n", strLicenseType);// + //printf("LicenseStatus=%s\n", strLicenseStatus); + //printf("111-5 get password = %s \n", accountData[0].account_password); + //printf("\n----------g_match_mac:%d\n", g_match_mac); + if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { + if (strcmp(strLicenseStatus, "Trial mismatch the system ID") != 0) { + if (strcmp(strLicenseStatus, "License mismatch the system ID") != 0) { + if (IsExistingWeight(featureType, featureType2)) { + if (strncmp(strUnlockingKey, "face", 4) == 0) { + + } + else { + strcpy(strUnlockingKey, unlock_key->valuestring); + } + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char keyPATH[1024]; + + strcpy(keyPATH, exePath); + + strcat(keyPATH, "key.txt"); + + + FILE *pFile; + if ((pFile = fopen(keyPATH, "w")) != NULL) + { + fprintf(pFile, strUnlockingKey); + fclose(pFile); + } + else + { + printf("Fail to open key.txt \n"); + } + + } + else + strcpy(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type"); + } + else + strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); + } + else + strcpy(strUnlockingKey, "Trial_mismatch_the_system_ID"); + } + else { + if (g_match_mac == 1) { + strcpy(strUnlockingKey, "Third_party"); + } + else { + strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); + } + } + + //printf("\nUnlockingKey=%s\n", strUnlockingKey); + //printf("111-4 get password = %s \n", accountData[0].account_password); + if (new_data_write_to_config_file_flag == 1 + || strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") == 0 + || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0 + || strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") == 0 + || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0) + { + + cJSON *new_data_root, *ai_server, *view_setting, *camera01, *detection_zone, *detect, *trigger_events, *trigger, *system_setting, *account_setting, *about_box; + new_data_root = cJSON_CreateObject(); + ai_server = cJSON_CreateObject(); + view_setting = cJSON_CreateObject(); + camera01 = cJSON_CreateObject(); + detection_zone = cJSON_CreateArray(); + system_setting = cJSON_CreateObject(); + account_setting = cJSON_CreateObject(); + about_box = cJSON_CreateObject(); + + cJSON_AddItemToObject(new_data_root, "ai_server", ai_server); + cJSON_AddItemToObject(ai_server, "ip", cJSON_CreateString("127.0.0.1")); + + cJSON_AddItemToObject(ai_server, "http_port", cJSON_CreateString(accountData[0].account_aida_port)); + cJSON_AddItemToObject(ai_server, "video_port", cJSON_CreateString("8591")); + + cJSON_AddItemToObject(new_data_root, "view_setting", view_setting); + cJSON_AddItemToObject(view_setting, "camera01", camera01); + cJSON_AddItemToObject(camera01, "ip", cJSON_CreateString("47.176.29.11")); + cJSON_AddItemToObject(camera01, "http_port", cJSON_CreateString("80")); + cJSON_AddItemToObject(camera01, "video_port", cJSON_CreateString("80")); + cJSON_AddItemToObject(camera01, "username", cJSON_CreateString("guest")); + cJSON_AddItemToObject(camera01, "password", cJSON_CreateString("GP12345")); + cJSON_AddItemToObject(camera01, "channel_id", cJSON_CreateString("")); + cJSON_AddItemToObject(camera01, "enable_repeat", cJSON_CreateNumber(0)); + cJSON_AddItemToObject(camera01, "camera_name", cJSON_CreateString("")); + cJSON_AddItemToObject(camera01, "obj_max_proportion", cJSON_CreateString(obj_max_proportion->valuestring)); + cJSON_AddItemToObject(camera01, "obj_min_proportion", cJSON_CreateString(obj_min_proportion->valuestring)); + + if (plate_filter_times) + cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); + else + cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString("4")); + + if (plate_filter_time) + cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); + else + cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString("3")); + + if (plate_free_time) + cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); + else + cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString("3")); + + cJSON_AddItemToObject(camera01, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); + cJSON_AddItemToObject(camera01, "enable_face", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(camera01, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); + cJSON_AddItemToObject(camera01, "enable_logo", cJSON_CreateString("No")); + cJSON_AddItemToObject(camera01, "enable_human", cJSON_CreateString("No")); + cJSON_AddItemToObject(camera01, "enable_helmet", cJSON_CreateString("No")); + cJSON_AddItemToObject(camera01, "levenshtein_distance", cJSON_CreateString(levenshtein_distance->valuestring)); + cJSON_AddItemToObject(camera01, "min_characters", cJSON_CreateString(min_characters->valuestring)); + cJSON_AddItemToObject(camera01, "max_characters", cJSON_CreateString(max_characters->valuestring)); + cJSON_AddItemToObject(camera01, "confidence", cJSON_CreateString(confidence->valuestring)); + cJSON_AddItemToObject(camera01, "confidence2", cJSON_CreateString(confidence2->valuestring)); + cJSON_AddItemToObject(camera01, "confidence3", cJSON_CreateString(confidence3->valuestring)); + cJSON_AddItemToObject(camera01, "confidence4", cJSON_CreateString(confidence4->valuestring)); + cJSON_AddItemToObject(camera01, "tab_view_size", cJSON_CreateString("889x500")); + cJSON_AddItemToObject(camera01, "count_zone", cJSON_CreateNumber(viewChannelData[0].count_zone)); + + //printf("\nenable_lpr_db-----9\n"); + if (enable_lpr_db) { + cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString(enable_lpr_db->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString("Yes")); + } + + if (enable_track) { + cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString(enable_track->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString("No")); + } + + if (enable_PTZ) { + cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString(enable_PTZ->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString("No")); + } + + if (ptz_tracking_fov_min) { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString(ptz_tracking_fov_min->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString("0")); + } + + if (ptz_tracking_fov_max) { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString(ptz_tracking_fov_max->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString("40")); + } + + if (ptz_enable_tracking) { + cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString(ptz_enable_tracking->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString("Yes")); + } + + if (ptz_tracking_mode) { + cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString("1")); + } + + if (ptz_tracking_by_enter_zone) { + cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString("Yes")); + } + + if (enable_tracking_limits) { + cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString(enable_tracking_limits->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString("No")); + } + + if (ptz_pan_left_limit) { + cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString(ptz_pan_left_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString("0")); + } + + if (ptz_pan_right_limit) { + cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString(ptz_pan_right_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString("360")); + } + + if (ptz_tilt_up_limit) { + cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString(ptz_tilt_up_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString("0")); + } + + if (ptz_tilt_down_limit) { + cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString(ptz_tilt_down_limit->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString("210")); + } + + if (ptz_speed) { + cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString(ptz_speed->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString("3")); + } + + if (ptz_sensitivity) { + cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString("6")); + } + if (ptz_tracking_resume_dwell) { + cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString(ptz_tracking_resume_dwell->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString("3")); + } + + if (cJSON_enable_only_show_metadata1) { + cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(cJSON_enable_only_show_metadata1->valueint)); + } + else { + cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); + } + + if (enable_downsized_cropped_roi) { + cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); + } + else { + cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(1)); + } + + if (enable_zone_crop_1) { + cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); + } + else { + cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(0)); + } + + if (enable_unknown_object) { + cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString(enable_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString("No")); + } + + if (enable_ivs_person_detection) { + cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString(enable_ivs_person_detection->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString("No")); + } + + if (assign_ivs_object_to) { + cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString(assign_ivs_object_to->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString("")); + } + + if (enable_ambulance) { + cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString(enable_ambulance->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString("No")); + } + + if (enable_blank_plate) { + cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString(enable_blank_plate->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString("No")); + } + + if (enable_stop_sign) { + cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString(enable_stop_sign->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString("No")); + } + + if (enable_show_unknown_object) { + cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString(enable_show_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString("No")); + } + + if (enable_ivs_fix_mode) { + cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString(enable_ivs_fix_mode->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString("No")); + } + + if (enable_ivs_and_ai) { + cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString(enable_ivs_and_ai->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString("No")); + } + + if (enable_add_face_frequent_list) { + cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString("No")); + } + + if (enable_lpr_upon_triggered) { + cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString(enable_lpr_upon_triggered->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString("No")); + } + + if (dwell_lpr_upon_triggered) { + cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString(dwell_lpr_upon_triggered->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString("10")); + } + + if (unknown_object_max_proportion) { + cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString(unknown_object_max_proportion->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString("20")); + } + + if (unknown_object_min_proportion) { + cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString(unknown_object_min_proportion->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString("0")); + } + + if (confidence_unknown_object) { + cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString(confidence_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString("0")); + } + + if (confidence2_unknown_object) { + cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString(confidence2_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString("0")); + } + + if (dwell_unknown_object) { + cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString(dwell_unknown_object->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString("30")); + } + + if (dwell_minute_focus_on) { + cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString(dwell_minute_focus_on->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString("5")); + } + + if (person_obj_fov) { + cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString(person_obj_fov->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString("100")); + } + + if (ivs_mode) { + cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString(ivs_mode->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString("3")); + } + + if (getnetwork_buffer_id) { + cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString(getnetwork_buffer_id->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString("1")); + } + + if (red_light_zone) { + cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString(red_light_zone->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_protect) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString(no_give_way_zone_to_protect->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_keep_away) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString(no_give_way_zone_to_keep_away->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_protect_2) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString(no_give_way_zone_to_protect_2->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString("")); + } + + if (no_give_way_zone_to_keep_away_2) { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(no_give_way_zone_to_keep_away_2->valuestring)); + } + else { + cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString("")); + } + + cJSON_AddItemToObject(camera01, "detection_zone", detection_zone); + + for (int index_i = 0; index_i < MAX_DETECTION_ZONE; index_i++) + { + detect = cJSON_CreateObject(); + cJSON_AddItemToArray(detection_zone, detect); + cJSON_AddItemToObject(detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[0][index_i].enable_direction1)); + cJSON_AddItemToObject(detect, "enable_direction2", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "direction1", cJSON_CreateString(viewDetectionZone[0][index_i].direction1)); + cJSON_AddItemToObject(detect, "direction2", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "enable_tripwire", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "enable_traffic_light", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "enable_social_distance", cJSON_CreateString("")); + + cJSON_AddItemToObject(detect, "metadata1", cJSON_CreateString(viewDetectionZone[0][index_i].metadata1)); + cJSON_AddItemToObject(detect, "metadata2", cJSON_CreateString(viewDetectionZone[0][index_i].metadata2)); + cJSON_AddItemToObject(detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[0][index_i].metadata_stop)); + + char str[25] = { 0 }; + sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time); + cJSON_AddItemToObject(detect, "no_parking_time", cJSON_CreateString(str)); + + memset(str, 0x00, sizeof(str)); + sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time_in_minute); + cJSON_AddItemToObject(detect, "no_parking_time_in_minute", cJSON_CreateString(str)); + + memset(str,0x00,sizeof(str)); + sprintf(str, "%d", viewDetectionZone[0][index_i].queuing_count); + + cJSON_AddItemToObject(detect, "queuing_count", cJSON_CreateString(str)); + cJSON_AddItemToObject(detect, "distance_violation_count", cJSON_CreateString("")); + cJSON_AddItemToObject(detect, "detection_time", cJSON_CreateString(viewDetectionZone[0][index_i].detection_time)); + cJSON_AddItemToObject(detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[0][index_i].link_to_counter)); + + if (obj_max_proportion_in_zone) + cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_max_proportion_in_zone)); + else { + cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString("80")); + } + + if (obj_min_proportion_in_zone) + cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_min_proportion_in_zone)); + else { + cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString("0")); + } + + if (ptz_zone_to_preset) + cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[0][index_i].ptz_zone_to_preset)); + else { + cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString("0")); + } + + if (enable_speed) + cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_speed)); + else { + cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString("No")); + } + + if (enable_radar_speed) + cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_radar_speed)); + else { + cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString("No")); + } + + if (enable_ivs_zone) + cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[0][index_i].enable_ivs_zone)); + else { + cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString("No")); + } + + if (parking_space) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_space); + cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString("0")); + } + + if (parking_line) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_line); + cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString("0")); + } + + if (set_distance) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp,"%f", viewDetectionZone[0][index_i].set_distance); + cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString("10")); + } + + if (world_distance_unit) + cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_distance_unit)); + else { + cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString("meter")); + } + + if (world_distance_side1) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side1); + cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString("10")); + } + + if (world_distance_side2) { + char buf_temp[20] = { 0 }; + sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side2); + cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString(buf_temp)); + } + else { + cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString("10")); + } + + if (world_time_unit) { + cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_time_unit)); + } + else { + cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString("KPH")); + } + + trigger_events = cJSON_CreateArray(); + cJSON_AddItemToObject(detect, "trigger_events", trigger_events); + + for (int index_j = 0; index_j < MAX_TRIGGER_EVENT; index_j++) + { + trigger = cJSON_CreateObject(); + cJSON_AddItemToArray(trigger_events, trigger); + + char str_counter_increment[50] = { 0 }; + if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment==1) { + strcpy(str_counter_increment,"counter_increment_add"); + } + else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == -1) { + strcpy(str_counter_increment, "counter_increment_minus"); + } + else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == 0) { + strcpy(str_counter_increment, "counter_increment_equal"); + } + else { + strcpy(str_counter_increment,""); + } + + cJSON_AddItemToObject(trigger, "checked", cJSON_CreateNumber(viewDetectionZone[0][index_i].trigger_event[index_j].checked)); + + if (index_j == 0) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000001")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Prohibit zone (AIAREA)")); + } + else if (index_j == 1) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000004")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Parking violation (AIAREA/AICAP)")); + } + else if (index_j == 2) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00200000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Allowed list")); + } + else if (index_j == 3) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00400000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Denial list")); + } + else if (index_j == 4) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000008")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Traffic flow (AIFLOW/AICAP)")); + } + else if (index_j == 5) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000010")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn left (AIFLOW)")); + } + else if (index_j == 6) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000020")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn right (AIFLOW)")); + } + else if (index_j == 7) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x10000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Density detection (03AI)")); + } + else if (index_j == 8) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x20000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Missing object detection (01AI)")); + } + else if (index_j == 9) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00800000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Visitor list")); + } + else if (index_j == 10) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x01000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Unattended object or missing object")); + } + else if (index_j == 11) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x02000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("BG learning")); + } + else if (index_j == 12) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x04000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Tampering detection")); + } + else if (index_j == 13) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x40000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("All objects detection")); + } + else if (index_j == 14) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x80000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lack of any object detection")); + } + else if (index_j == 15) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00002000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Over speed detection")); + } + else if (index_j == 16) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00004000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lower speed detection")); + } + else if (index_j == 17) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000400")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Running red lights")); + } + else if (index_j == 18) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000800")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning left on red")); + } + else if (index_j == 19) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00001000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning right on red")); + } + else if (index_j == 20) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00008000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Forget to give way detection")); + } + else if (index_j == 21) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00040000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Distance violation")); + } + else if (index_j == 22) { + cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x08000000")); + cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Height detection")); + } + + cJSON_AddItemToObject(trigger, "post_event_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].post_event_name)); + cJSON_AddItemToObject(trigger, "counter_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].counter_name)); + cJSON_AddItemToObject(trigger, "counter_increment", cJSON_CreateString(str_counter_increment)); + + } + cJSON_AddItemToObject(detect, "point_number", cJSON_CreateNumber(6)); + cJSON_AddItemToObject(detect, "x1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].x)); + cJSON_AddItemToObject(detect, "y1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].y)); + cJSON_AddItemToObject(detect, "x2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].x)); + cJSON_AddItemToObject(detect, "y2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].y)); + cJSON_AddItemToObject(detect, "x3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].x)); + cJSON_AddItemToObject(detect, "y3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].y)); + cJSON_AddItemToObject(detect, "x4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].x)); + cJSON_AddItemToObject(detect, "y4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].y)); + if (x5 && x6) + { + cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].x)); + cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].y)); + cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].x)); + cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].y)); + } + else + { + cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(579)); + cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(250)); + cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(579)); + cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(100)); + } + } + + cJSON_AddItemToObject(new_data_root, "system_setting", system_setting); + cJSON_AddItemToObject(system_setting, "AI dataset", cJSON_CreateString("")); + cJSON_AddItemToObject(system_setting, "dataset category", cJSON_CreateString("; Total 60 FPS")); + cJSON_AddItemToObject(system_setting, "snapshot folder", cJSON_CreateString("D:\\\\")); + if (language) { + cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString(language->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString("en_gb")); + } + cJSON_AddItemToObject(system_setting, "enable log", cJSON_CreateString("No")); + cJSON_AddItemToObject(system_setting, "auto reconnect", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "auto start", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "enable watchdog", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "enable watchdog UI", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "cpu usage limit", cJSON_CreateString("80")); + cJSON_AddItemToObject(system_setting, "display OSD", cJSON_CreateString("No")); + + if (activeDisplayDash) { + cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString("No")); + } + + if (display_properties) + cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString(display_properties->valuestring)); + else { + cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString("No")); + } + + + cJSON_AddItemToObject(system_setting, "display tracking ID", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(system_setting, "overlap thresh", cJSON_CreateNumber(70)); + cJSON_AddItemToObject(system_setting, "confidence thresh", cJSON_CreateNumber(0)); + cJSON_AddItemToObject(system_setting, "cnn type", cJSON_CreateString("CUDA")); + cJSON_AddItemToObject(system_setting, "cnn device1", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device2", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device3", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device4", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device5", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device6", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device7", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "cnn device8", cJSON_CreateString("GPU")); + cJSON_AddItemToObject(system_setting, "whitelist", cJSON_CreateString("No")); + cJSON_AddItemToObject(system_setting, "blacklist", cJSON_CreateString("No")); + + + if (enable_person_independent) { + cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString(enable_person_independent->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString("No")); + } + + if (enable_onvif_profile_m) { + cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString(enable_onvif_profile_m->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString("No")); + } + + if (nms_thres) { + cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString(nms_thres->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString("10")); + } + + if (tracking_id_dwell) { + cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString(tracking_id_dwell->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString("5")); + } + + if (enable_cloud) { + cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString(enable_cloud->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString("No")); + } + + if (enable_special_edition) { + cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString(enable_special_edition->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); + } + + if (enable_python) { + cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString(enable_python->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString("No")); + } + + if (enable_python_file) { + cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString(enable_python_file->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); + } + + if (enable_low_cpu_usage) { + cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString(enable_low_cpu_usage->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString("No")); + } + + if (cloud_enable_snap) { + cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString(cloud_enable_snap->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString("Yes")); + } + + if (cloud_enable_notification) { + cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString(cloud_enable_notification->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString("No")); + } + + if (cloud_account) { + cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString(cloud_account->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString("myaccount@mail.com")); + } + + if (cloud_password) { + cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString(cloud_password->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString("mypass")); + } + + if (cloud_notification_dwell) { + cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString(cloud_notification_dwell->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString("60")); + } + + if (cloud_statue) { + cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString(cloud_statue->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString("")); + } + + if (cloud_v2_statue) { + cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString(cloud_v2_statue->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString("")); + } + + if (cloud_record_v2_statue) { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString(cloud_record_v2_statue->valuestring)); + } + else { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString("")); + } + + if (enable_special_char) + cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString(enable_special_char->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString("No")); + } + + if (enable_bounding_box) + cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString("Yes")); + } + + if (enable_dwell_bounding_box) + cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString("No")); + } + + if (force_i_to_one) + cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString(force_i_to_one->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString("Yes")); + } + + if (force_o_to_zero) + cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString(force_o_to_zero->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString("Yes")); + } + + if (enable_plate_angle_correction) + cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString(enable_plate_angle_correction->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString("No")); + } + + if (enable_ai_mirror) + cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString(enable_ai_mirror->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString("No")); + } + + if (ai_mirror_feature) + cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString(ai_mirror_feature->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString("0")); + } + + if (enable_cloud_v2) + cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString(enable_cloud_v2->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString("No")); + } + + if (cloud_v2_notification_dwell) + cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(cloud_v2_notification_dwell->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString("60")); + } + + if (cloud_v2_content) + cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString(cloud_v2_content->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); + } + + if (enable_cloud_record_v2) + cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString(enable_cloud_record_v2->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString("No")); + } + + if (cloud_record_v2_notification_dwell) + cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(cloud_record_v2_notification_dwell->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString("60")); + } + + if (cloud_record_v2_content) + cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString(cloud_record_v2_content->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); + } + + if (enable_post_only_if_both_detected) + cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(enable_post_only_if_both_detected->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString("No")); + } + + if (enable_getalarmmotion_snap) + cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(enable_getalarmmotion_snap->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString("No")); + } + + if (getimage_encoder_id) + cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString(getimage_encoder_id->valuestring)); + else + { +#ifdef GY_OS_NOVA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("3")); +#endif +#ifdef GY_OS_AMBA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("4")); +#endif + } + + if (getimage_encoder_id_HD) + cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString(getimage_encoder_id_HD->valuestring)); + else + { +#ifdef GY_OS_NOVA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("0")); +#endif +#ifdef GY_OS_AMBA + cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("4")); +#endif + } + + if (osd_encoder_id) + cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString(osd_encoder_id->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString("2")); + } + + if (osd_font_size) + cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString(osd_font_size->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString("26")); + } + + if (osd_outline_lilin) + cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString(osd_outline_lilin->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString("4")); + } + + if (enable_osd_bottom) + cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString(enable_osd_bottom->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString("Yes")); + } + + if (osd_bottom_bg_tran) + cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString(osd_bottom_bg_tran->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString("255")); + } + + if (osd_bottom_content) + cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString(osd_bottom_content->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString("Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>")); + } + + if (sensors_type) + cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString(sensors_type->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString("0")); + } + + if (enable_sync_external_lpr_db) + cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(enable_sync_external_lpr_db->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString("No")); + } + + if (external_lpr_db_IP) + cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString(external_lpr_db_IP->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString("192.168.0.200")); + } + + if (external_lpr_db_port) + cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(external_lpr_db_port->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(accountData[0].account_aida_port)); + } + + if (external_lpr_db_username) + cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString(external_lpr_db_username->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString("admin")); + } + + if (external_lpr_db_password) + cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString(external_lpr_db_password->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString("pass")); + } + + if (enable_system_logs) + cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString(enable_system_logs->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString("No")); + } + + if (enable_email_jpeg) + cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString(enable_email_jpeg->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString("Yes")); + } + + if (email_reset_time_interval) + cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString(email_reset_time_interval->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString("")); + } + + if (enable_ftp) + cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString(enable_ftp->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString("No")); + } + + if (ftp_url) + cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString(ftp_url->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString("ftp.example.com")); + } + + if (ftp_port) + cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString(ftp_port->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString("21")); + } + + if (ftp_username) + cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString(ftp_username->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString("")); + } + + if (ftp_password) + cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString(ftp_password->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString("")); + } + + if (ftp_remote_directory) + cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString(ftp_remote_directory->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString("myfolder/myfile")); + } + + + if (ftp_jpeg_file_name_format) + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(ftp_jpeg_file_name_format->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString("fixed")); + } + + + if (ftp_jpeg_file_name) + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString(ftp_jpeg_file_name->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString("snap")); + } + + if (enable_email_notification) + cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString(enable_email_notification->valuestring)); + else + { + cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString("No")); + } + + cJSON_AddItemToObject(new_data_root, "account_setting", account_setting); + cJSON_AddItemToObject(account_setting, "account_data", cJSON_CreateString(account_data->valuestring)); + + cJSON_AddItemToObject(new_data_root, "about_box", about_box); + cJSON_AddItemToObject(about_box, "dataset version", cJSON_CreateString("")); + cJSON_AddItemToObject(about_box, "software version", cJSON_CreateString("2.0.2")); + cJSON_AddItemToObject(about_box, "system id", cJSON_CreateString("")); + cJSON_AddItemToObject(about_box, "NIC name", cJSON_CreateString("AӺ")); + + if(strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") != 0) + { + if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { + if (strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") != 0) { + if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { + + if (strncmp(strUnlockingKey, "face", 4) == 0) { + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + } + else { + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(unlock_key->valuestring)); + } + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_mismatch_the_system_ID")); + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); + } + else + cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_or_license_mismatch_the_feature_type")); + + + char *filename; + filename = configPATH; + + int del = remove(filename); + if (!del) { + //printf("config is Deleted successfully."); + } + else { + printf("config cannot be Deleted.\n"); + } + + char* JsonString = cJSON_Print(new_data_root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open config.json \n"); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (new_data_root) { + cJSON_Delete(new_data_root); + new_data_root = NULL; + } + new_data_write_to_config_file_flag = 0; + } + + //printf("111-3 get password = %s \n", accountData[0].account_password); + if (new_data_write_to_events_file_flag == 1) { + cJSON *new_data_root, *notification, *event_counter_setting/*,*enable_post*//*,*enable_snmp_post*/,*http_post_events,*a_http_post_event,*event_counters, + *a_event_counter; + cJSON *a_report, *report_counters; + cJSON *a_snmp, *snmp_management; + cJSON *email_setting; + new_data_root = cJSON_CreateObject(); + notification = cJSON_CreateObject(); + event_counter_setting = cJSON_CreateObject(); + email_setting = cJSON_CreateObject(); +; + cJSON_AddItemToObject(new_data_root, "notification", notification); + cJSON_AddItemToObject(new_data_root, "event_counter_setting", event_counter_setting); + cJSON_AddItemToObject(new_data_root, "email_setting", email_setting); + + if(activePostNotification) + cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("Yes")); + else + cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("No")); + + if (activeSNMPPost) + cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("Yes")); + else + cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("No")); + + cJSON_AddItemToObject(notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + cJSON_AddItemToObject(notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); + + cJSON_AddItemToObject(notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); + cJSON_AddItemToObject(notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); + cJSON_AddItemToObject(notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); + + cJSON_AddItemToObject(notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); + cJSON_AddItemToObject(notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); + cJSON_AddItemToObject(notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); + cJSON_AddItemToObject(notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); + cJSON_AddItemToObject(notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); + cJSON_AddItemToObject(notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); + cJSON_AddItemToObject(notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); + cJSON_AddItemToObject(notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); + cJSON_AddItemToObject(notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); + cJSON_AddItemToObject(notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); + cJSON_AddItemToObject(notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); + cJSON_AddItemToObject(notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); + cJSON_AddItemToObject(notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); + cJSON_AddItemToObject(notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); + cJSON_AddItemToObject(notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); + cJSON_AddItemToObject(notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); + cJSON_AddItemToObject(notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); + cJSON_AddItemToObject(notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); + + http_post_events = cJSON_CreateArray(); + cJSON_AddItemToObject(notification, "http_post_events", http_post_events); + + for (int index_http_post = 0; index_http_post < MAX_POST_EVENTS; index_http_post++) { + a_http_post_event = cJSON_CreateObject(); + cJSON_AddItemToArray(http_post_events, a_http_post_event); + + cJSON_AddItemToObject(a_http_post_event, "post_protocol", cJSON_CreateString(postEventList[index_http_post].post_protocol)); + cJSON_AddItemToObject(a_http_post_event, "post_event_method", cJSON_CreateString(postEventList[index_http_post].post_event_method)); + cJSON_AddItemToObject(a_http_post_event, "post_event_name", cJSON_CreateString(postEventList[index_http_post].post_event_name)); + cJSON_AddItemToObject(a_http_post_event, "post_host_ip", cJSON_CreateString(postEventList[index_http_post].post_host_ip)); + cJSON_AddItemToObject(a_http_post_event, "post_host_port", cJSON_CreateString(postEventList[index_http_post].post_host_port)); + cJSON_AddItemToObject(a_http_post_event, "post_url", cJSON_CreateString(postEventList[index_http_post].post_url)); + cJSON_AddItemToObject(a_http_post_event, "post_content_type", cJSON_CreateString("text/html; charset=utf-8")); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)postEventList[index_http_post].post_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)postEventList[index_http_post].post_password, (unsigned char *)buf_account2); + + cJSON_AddItemToObject(a_http_post_event, "post_username", cJSON_CreateString(buf_account)); + cJSON_AddItemToObject(a_http_post_event, "post_password", cJSON_CreateString(buf_account2)); + cJSON_AddItemToObject(a_http_post_event, "post_customized_header", cJSON_CreateString(postEventList[index_http_post].post_customized_header)); + cJSON_AddItemToObject(a_http_post_event, "post_content", cJSON_CreateString(postEventList[index_http_post].post_content)); + cJSON_AddItemToObject(a_http_post_event, "post_sequence", cJSON_CreateString(postEventList[index_http_post].post_sequence)); + cJSON_AddItemToObject(a_http_post_event, "post_file_format", cJSON_CreateString(postEventList[index_http_post].post_file_format)); + cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name_format)); + cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name)); + cJSON_AddItemToObject(a_http_post_event, "post_timeout", cJSON_CreateString(postEventList[index_http_post].post_timeout)); + } + event_counters = cJSON_CreateArray(); + cJSON_AddItemToObject(event_counter_setting, "event_counters", event_counters); + report_counters = cJSON_CreateArray(); + cJSON_AddItemToObject(event_counter_setting, "report_counters", report_counters); + snmp_management = cJSON_CreateArray(); + cJSON_AddItemToObject(event_counter_setting, "snmp_management", snmp_management); + +#ifdef GY_OS_V_SERIES + for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { + a_event_counter = cJSON_CreateObject(); + cJSON_AddItemToArray(event_counters, a_event_counter); + + char str_name[50] = { 0 }; + sprintf(str_name, "Counter0%d", index_event_counter+1); + + cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(str_name)); + cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(str_name)); + cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); + cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString("0")); + cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString("Yes")); + cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString("1 minute")); + cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); + cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString("Camera virtual 4")); + cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString("5 minutes")); + cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString("No")); + } + + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + a_report = cJSON_CreateObject(); + cJSON_AddItemToArray(report_counters, a_report); + + cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString("Counter01")); + cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString("Name")); + cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString("1")); + cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString("")); + cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString("")); + cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString("0")); + cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString("")); + cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString("100")); + cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString("0")); + cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString("car_300X300_white")); + cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString("No entry for cars")); + cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString("car_1_300X300_red")); + } + + for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + a_snmp = cJSON_CreateObject(); + cJSON_AddItemToArray(snmp_management, a_snmp); + + + char str_name[50] = { 0 }; + + if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { + sprintf(str_name, "SNMP %d", index_snmp + 1); + } + else { + sprintf(str_name, "%s", "Heartbeat"); + } + + cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(str_name)); + cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString("v1")); + cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString("public")); + cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString("192.168.0.200")); + cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString("161")); + cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(".1.3.6.1.2.1.1.6.0")); + cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString("mylocation")); + cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString("string")); + } +#else + for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { + a_event_counter = cJSON_CreateObject(); + cJSON_AddItemToArray(event_counters, a_event_counter); + + char str_reset_value[50] = { 0 }; + sprintf(str_reset_value,"%d", eventCounterList[index_event_counter].reset_value); + + cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_name)); + cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_cust_name)); + cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); + cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString(str_reset_value)); + cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_time_interval)); + cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].reset_time_interval)); + cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); + cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); + cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); + cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString(eventCounterList[index_event_counter].link_to_post_event_name)); + cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString(eventCounterList[index_event_counter].post_interval)); + cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_only_cloud)); + cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[index_event_counter].enable_linked_to_dwell_time)); + } + + for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { + a_report = cJSON_CreateObject(); + cJSON_AddItemToArray(report_counters, a_report); + + cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString(reportCounterList[index_report].counter_a)); + cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString(reportCounterList[index_report].counter_a_name)); + cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[index_report].counter_a_zone)); + cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString(reportCounterList[index_report].counter_b)); + cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString(reportCounterList[index_report].counter_b_name)); + cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[index_report].counter_b_zone)); + cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString(reportCounterList[index_report].counter_c_name)); + cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString(reportCounterList[index_report].report_max_value)); + cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString(reportCounterList[index_report].enable_report)); + cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString(reportCounterList[index_report].counter_mode)); + cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString(reportCounterList[index_report].initial_icon)); + cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString(reportCounterList[index_report].detection_output)); + cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString(reportCounterList[index_report].output_icon)); + } + + for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { + a_snmp = cJSON_CreateObject(); + cJSON_AddItemToArray(snmp_management, a_snmp); + + cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_event_name)); + cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_version)); + cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_group_name)); + cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_ip)); + cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_port)); + cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_oid)); + cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_value)); + cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_type)); + } +#endif + cJSON_AddItemToObject(email_setting, "email_content", cJSON_CreateString(emailData.email_content)); + + char *filename; + filename = eventsPATH; + + int del = remove(filename); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("events cannot be Deleted.\n"); + } + + char* JsonString = cJSON_Print(new_data_root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open events.json \n"); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (new_data_root) { + cJSON_Delete(new_data_root); + new_data_root = NULL; + } + new_data_write_to_events_file_flag = 0; + } + + //printf("111-2 get password = %s \n", accountData[0].account_password); +#ifdef GY_OS_AMBA + if (new_data_write_to_tof_file_flag == 1) { + cJSON *new_data_root,*new_tof_camera; + + new_data_root = cJSON_CreateObject(); + new_tof_camera = cJSON_CreateObject(); + + cJSON_AddItemToObject(new_data_root, "version", cJSON_CreateNumber(tofData.tof_version)); + cJSON_AddItemToObject(new_data_root, "debug", cJSON_CreateBool(tofData.tof_debug)); + cJSON_AddItemToObject(new_data_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); + cJSON_AddItemToObject(new_data_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); + cJSON_AddItemToObject(new_data_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); + cJSON_AddItemToObject(new_data_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); + + cJSON_AddItemToObject(new_data_root, "distance_options", cJSON_CreateString(tofData.distance_options)); + cJSON_AddItemToObject(new_data_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); + cJSON_AddItemToObject(new_data_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); + cJSON_AddItemToObject(new_data_root, "height_options", cJSON_CreateString(tofData.height_options)); + cJSON_AddItemToObject(new_data_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); + cJSON_AddItemToObject(new_data_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); + + cJSON_AddItemToObject(new_data_root, "ground_x", cJSON_CreateString(tofData.ground_x)); + cJSON_AddItemToObject(new_data_root, "ground_y", cJSON_CreateString(tofData.ground_y)); + + cJSON_AddItemToObject(new_data_root, "camera", new_tof_camera); + + cJSON_AddItemToObject(new_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); + cJSON_AddItemToObject(new_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); + cJSON_AddItemToObject(new_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); + cJSON_AddItemToObject(new_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); + cJSON_AddItemToObject(new_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)tofData.tof_camera_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)tofData.tof_camera_password, (unsigned char *)buf_account2); + + cJSON_AddItemToObject(new_tof_camera, "camera_username", cJSON_CreateString(buf_account)); + cJSON_AddItemToObject(new_tof_camera, "camera_password", cJSON_CreateString(buf_account2)); + + char *filename; + filename = tofPATH; + + int del = remove(filename); + if (!del) { + //printf("tof is Deleted successfully."); + } + else { + printf("tof cannot be Deleted.\n"); + } + + char* JsonString = cJSON_Print(new_data_root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + fclose(fp); + printf("Fail to open events.json \n"); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (new_data_root) { + cJSON_Delete(new_data_root); + new_data_root = NULL; + } + new_data_write_to_tof_file_flag = 0; + } +#endif + //20201123 sophia add + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (tof_root) { + cJSON_Delete(tof_root); + tof_root = NULL; + } + if (n_root) { + cJSON_Delete(n_root); + n_root = NULL; + } + if (keyRoot) { + cJSON_Delete(keyRoot); + keyRoot = NULL; + } + + //http_ip_address = (ip_address) ? ip_address : NULL; + //http_http_port = http_port; + + http_sleep_interval = 2; + //http_dataset_version = dataset_version; + //set base time for reload + struct tm* b_time = localtime(&start_time);; + memset(b_time, 0, sizeof(struct tm)); + b_time->tm_hour = 0; // 24 hour format, 0 = midnight, 23 = 11pm + b_time->tm_min = 0; + b_time->tm_sec = 0; + b_time->tm_mon = 0; // 0 based, 0 = jan, 11 = dec + b_time->tm_mday = 1; + b_time->tm_year = 100; // current - 1900 + + //time_t base_time = mktime(b_time); + + //initialize socketRecords + /*for (int i = 0; i < sizeof(socketRecords); i++) + { + socketRecords[i].sock = INVALID_SOCKET; + socketRecords[i].last_recv_time = 0; + }*/ + + int layer_idx = 0; +#ifdef GY_OS_NOVA + cJSON *root_weight,*net_number,*net_info_list,*net_info,*weight_name,*anc_name,*label_name,*feature_type; + root_weight = cJSON_CreateObject(); + net_info_list = cJSON_CreateArray(); + cJSON_AddItemToObject(root_weight, "net_info_list", net_info_list); +#endif + /*for (int i = 0; i < MAX_LAYER_NUM; i++) + { + if (layerUTF8Country[i] != NULL) + { + free(layerUTF8Country[i]); + layerUTF8Country[i] = NULL; + } + + layerUTF8Country[i] = malloc(128); + strcpy(layerUTF8Country[layer_idx], ""); + }*/ + + ///Steven MARK TEMP + ////license keyJP //MAX_IMG_BUFF_SIZE * MAX_CLIENT_SOCKET + + //printf("\nKKKKKKKKKKKKKKKK:1\n"); + /* + printf("\n--------------------\n"); + printf("\nfeatureType: 0x%x\n", featureType); + printf("\nfeatureType2: 0x%x\n", featureType2); + printf("\n--------------------\n");*/ + + //printf("\n--------------------------:5\n"); + + //printf("111-1 get password = %s \n", accountData[0].account_password); + + if (IsExistingWeight(featureType, featureType2)) { + +#ifdef GY_OS_AMBA + //AMBA Weight + if (strcmp(WeightFileModeName, "mod004") == 0) { + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_WGT.aes", "/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_ANC.aes", "/emmc/plugin/Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITHERMAL/GYNet_AITHERMAL_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITHERMAL/AMB_AITHERMAL_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin"); + } + } + + //if (g_check_if_OK_thermal == 1 && g_IsPTZDevice == 1) + if(g_dual_sensor == 1) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + } + } + else { + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + else { + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { + featureType = featureType | FEATURE_TRAF_DET; + featureType2 = featureType2 | FEATURE_AICAP; + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + g_IsHelm_without_car = 1; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + (strcmp(WeightFileModeName, "mod003") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK)) { + featureType = featureType | FEATURE_TRAF_DET; + featureType2 = featureType2 | FEATURE_AIFLOW; + stAMBAcontent.featureType = featureType; + stAMBAcontent.featureType2 = featureType2; + + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); + + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + g_IsHelm_without_car = 1; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); + } + } + } + } + } + //AMBA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_WGT.aes", "/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_ANC.aes", "/emmc/plugin/Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGARBAGE/GYNet_AIGARBAGE_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGARBAGE/AMB_AIGARBAGE_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_LOGO) == FEATURE_LPR_LOGO) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_WGT.aes", "/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin", key, 0, false); + + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_ANC.aes", "/emmc/plugin/Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AICarMake/GYNet_LOGO_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AICarMake/AMB_LOGO_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_LOGO; + layerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_LOGO; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE /*&& (featureType2 & FEATURE_DET_AIFIRE) == FEATURE_DET_AIFIRE*/) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_WGT.aes", "/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_ANC.aes", "/emmc/plugin/Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFIRE/GYNet_AIFIRE_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFIRE/AMB_AIFIRE_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_AIFIRE; + layerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIFIRE; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_WGT.aes", "/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_ANC.aes", "/emmc/plugin/Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAERO/GYNet_AIAERO_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAERO/AMB_AIAERO_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREO; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREO; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) ///Steven TEMP MARK FEATURE_HUM_DET + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_WGT.aes", "/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_ANC.aes", "/emmc/plugin/Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISAFTY/GYNet_AISAFTY_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISAFTY/AMB_AISAFTY_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIHELM; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIHELM; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) ///Steven TEMP MARK FEATURE_HUM_DET + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_WGT.aes", "/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_ANC.aes", "/emmc/plugin/Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRAILWAY/GYNet_AIRAILWAY_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRAILWAY/AMB_AIRAILWAY_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_AIRAIL; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIRAIL; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) ///Steven TEMP MARK FEATURE_HUM_DET + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_WGT.aes", "/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_ANC.aes", "/emmc/plugin/Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISPORTS/GYNet_AISPORTS_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISPORTS/AMB_AISPORTS_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AISPORTS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISPORTS; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) ///Steven TEMP MARK + { + if (layer_idx < MAX_LAYER_NUM) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_WGT.aes", "/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_ANC.aes", "/emmc/plugin/Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIHUMAN/GYNet_Human_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIHUMAN/AMB_Human_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin"); + } + } + else { + LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_WGT.aes", "/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_ANC.aes", "/emmc/plugin/Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGENDER/GYNet_AIGENDER_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGENDER/AMB_AIGENDER_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin"); + } + } + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIMASK; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIMASK; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + if (layer_idx < MAX_LAYER_NUM) + { + if (strcmp(WeightFileModeName, "mod003") != 0) { + LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_WGT.aes", "/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_ANC.aes", "/emmc/plugin/Aida/AIAML/anchors_GYNet_AIAML_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAML/anchors_GYNet_AIAML_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAML/GYNet_AIAML_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAML/AMB_AIAML_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin"); + } + } + else { + LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_WGT.aes", "/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_ANC.aes", "/emmc/plugin/Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFRONTBACK/GYNet_AIFRONTBACK_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFRONTBACK/AMB_AIFRONTBACK_VER.txt,"); + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin"); + } + } + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAML; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAML; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_WGT.aes", "/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_ANC.aes", "/emmc/plugin/Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISHIP/GYNet_AISHIP_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISHIP/AMB_AISHIP_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AISHIP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISHIP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_WGT.aes", "/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_ANC.aes", "/emmc/plugin/Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIPRODUCTION/GYNet_AIPRODUCTION_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIPRODUCTION/AMB_AIPRODUCTION_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_TWN\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/AMB_ANPR_TWN_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR)//20201216 Jim add + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_EUR\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/AMB_ANPR_EUR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA || + (featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM || + (featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_SEA\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/AMB_ANPR_SEA_VER.txt,"); + + if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) { + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + else if ((featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM) { + layerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + else if ((featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) { + layerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA)//20201216 Jim add + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_MEA\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/AMB_ANPR_MEA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_USA\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/AMB_ANPR_USA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + //printf("feature type = FEATURE_LPR_GBR\n"); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/AMB_ANPR_GBR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/AMB_ANPR_JPN_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/AMB_ANPR_THA_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_BGD) == FEATURE_LPR_BGD) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_LPD_Label_BGD.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_OCR_Label_BGD.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRBGD/AMB_ANPR_BGD_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/AMB_ANPR_PHL_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_CNT) == FEATURE_LPR_CNT) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_LPD_Label_CNT.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_OCR_Label_CNT.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRCNT/AMB_ANPR_CNT_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin"); + } + } + } + //AMBA Weight + if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin", key, 0, false); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt", key, 0, false); + LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt", key, 0, false); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/AMB_ANPR_AUS_VER.txt,"); + + + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin"); + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin"); + } + } + } + //AMBA Weight + if (g_IsToFDevice == 1) + { + if (layer_idx < MAX_LAYER_NUM) + { + LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_WGT.aes", "/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin", key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin,"); + + LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_ANC.aes", "/emmc/plugin/Aida/AITOF/anchors_GYNet_AITOF_ANC.txt", key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITOF/anchors_GYNet_AITOF_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITOF/GYNet_AITOF_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITOF/AMB_AITOF_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AITOF; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AITOF; + stAMBAcontent.tiny_enable[layer_idx] = 1; + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin"); + } + } + + } + //AMBA Weight + if (g_IsRadarDevice == 1) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRADAR/GYNet_Radar_Tiny_Label.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRADAR/AMB_AIRADAR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_HUM_DET; + layerFeatureType2[layer_idx] = FEATURE_AIRADAR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIRADAR; + // stAMBAcontent.tiny_enable[layer_idx] = 1; // Radar ??????n YOLO + layer_idx++; + } + } +#endif + +#ifdef GY_OS_NOVA + //NOVA Weight + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + if (layer_idx < MAX_LAYER_NUM) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt")); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/NOV_Traffic_Tiny_VER.txt,"); + + if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIFLOW)); + } + else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIAREA)); + } + else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + layerFeatureType[layer_idx] = FEATURE_TRAF_DET; + layerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 + layer_idx++; + + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AICAP)); + } + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/NOV_ANPR_TWN_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_TWN; + layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_LPD_Label_USA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_OCR_Label_USA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/NOV_ANPR_USA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + layerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_USA; + layerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/NOV_ANPR_PHL_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_PHL; + layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_LPD_Label_THA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_OCR_Label_THA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/NOV_ANPR_THA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + layerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_THA; + layerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/NOV_ANPR_SEA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_SEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/NOV_ANPR_MEA_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_MEA; + layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_LPD_Label_EUR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_OCR_Label_EUR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/NOV_ANPR_EUR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_EUR; + layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/NOV_ANPR_GBR_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_GBR; + layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/NOV_ANPR_JPN_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_JPN; + layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + + + } + } + //NOVA Weight + if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) + { + if (layer_idx < MAX_LAYER_NUM - 1) + { + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); + + net_info = cJSON_CreateObject(); + cJSON_AddItemToArray(net_info_list, net_info); + cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); + cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); + cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names")); + cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); + cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); + + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); + strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); + strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); + + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); + + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); + strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); + + strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); + strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/NOV_ANPR_AUS_VER.txt,"); + + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + //Second setting is for OCR det. + layerFeatureType[layer_idx] = FEATURE_LPR_AUS; + layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; + stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp + //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); + layer_idx++; + } + } +#endif + } + +#ifdef GY_OS_NOVA + cJSON_AddItemToObject(root_weight, "net_number", cJSON_CreateNumber(layer_idx)); + + char * JsonString_weight = cJSON_PrintUnformatted(root_weight); + //(Nova: ͦv]w nova_driver_valid_weight.txt) + write_driver_setting_file(JsonString_weight); + + if (JsonString_weight != NULL) { + free(JsonString_weight); + JsonString_weight = NULL; + } + + if (root_weight) { + cJSON_Delete(root_weight); + root_weight = NULL; + } + + if (IsExistingWeight(featureType, featureType2)) + { + pthread_t NOVA_detection/*, NOVA_listener, NOVA_listener_image*/; + pthread_create(&NOVA_detection, 0, RUN_NOVA_DETECTION, NULL); //A11en create pthread to run detection + printf("\n==== Gynet create nova_driver ====\n"); + } +#endif + + /* + printf("\n--------------------\n"); + printf("\nfeatureType: 0x%x\n", featureType); + printf("\nfeatureType2: 0x%x\n", featureType2); + printf("\n--------------------\n"); + */ + + //printf("333 get password = %s \n", accountData[0].account_password); +#ifdef GY_OS_AMBA + //Third party weight + //printf("td_weight_num: %d \n", td_weight_num); + + //printf("\n---------------key:%s\n",key); + //printf("\n---------------mykey_custom:%s\n", mykey_custom); + //printf("\n---------------first_half_char_key:%s\n", first_half_char_key); + if(check_if_correct_mail == 1 && g_match_mac == 1) + { + for (int read_td_weight_idx = 0; read_td_weight_idx < td_weight_num; read_td_weight_idx++) + { + if (layer_idx < MAX_LAYER_NUM) + { + char ori_weight_name[MAX_MSG_LEN] = { 0 }; + strcpy(ori_weight_name,"/emmc/plugin/Aida"); + strcat(ori_weight_name, td_weight_info[read_td_weight_idx].weight_name); + + char new_weight_name[MAX_MSG_LEN] = { 0 }; + strcpy(new_weight_name, "/emmc/plugin/Aida"); + strcat(new_weight_name, td_weight_info[read_td_weight_idx].weight_name); + new_weight_name[strlen(new_weight_name) - 3] = 'b'; + new_weight_name[strlen(new_weight_name) - 2] = 'i'; + new_weight_name[strlen(new_weight_name) - 1] = 'n'; + + //printf("\n-------------new_weight_name:%s\n", new_weight_name); + if (td_weight_info[read_td_weight_idx].is_encryption == 1) { + LILIN_File_Decryption(ori_weight_name, new_weight_name, first_half_char_key, 0, false); + strcat(stAMBAcontent.sz_amba_NetworkNames, new_weight_name); + } + else + strcat(stAMBAcontent.sz_amba_NetworkNames, ori_weight_name); + strcat(stAMBAcontent.sz_amba_NetworkNames, ","); + + + char ori_anchor_name[MAX_MSG_LEN] = { 0 }; + strcpy(ori_anchor_name, "/emmc/plugin/Aida"); + strcat(ori_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); + + char new_anchor_name[MAX_MSG_LEN] = { 0 }; + strcpy(new_anchor_name, "/emmc/plugin/Aida"); + strcat(new_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); + new_anchor_name[strlen(new_anchor_name) - 3] = 't'; + new_anchor_name[strlen(new_anchor_name) - 2] = 'x'; + new_anchor_name[strlen(new_anchor_name) - 1] = 't'; + + //printf("\n-------------new_anchor_name:%s\n", new_anchor_name); + if (td_weight_info[read_td_weight_idx].is_encryption == 1) { + LILIN_File_Decryption(ori_anchor_name, new_anchor_name, first_half_char_key, 0, false); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, new_anchor_name); + } + else + strcat(stAMBAcontent.sz_amba_anchor_fileNames, ori_anchor_name); + strcat(stAMBAcontent.sz_amba_anchor_fileNames, ","); + + char ori_label_name[MAX_MSG_LEN] = { 0 }; + strcpy(ori_label_name, "/emmc/plugin/Aida"); + strcat(ori_label_name, td_weight_info[read_td_weight_idx].label_name); + + //printf("\n-------------ori_label_name:%s\n", ori_label_name); + + strcat(stAMBAcontent.sz_amba_label_fileNames, ori_label_name); + strcat(stAMBAcontent.sz_amba_label_fileNames, ","); + + layerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; + stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; + stAMBAcontent.tiny_enable[layer_idx] = 1; + layer_idx++; + + if (g_IsSDK_3_0 == 1) { + cavalry_gen_sdk_3_0(new_weight_name); + } + } + } + } +#endif + + //printf("\n%s\n", stAMBAcontent.sz_amba_ver_fileNames); + +#ifdef TEST_DETECTOR_MEM + //즹Ou|j1304 + + //printf("\n--------------------------:6\n"); + test_detector_mem(NULL, cnn_type, stAMBAcontent.sz_amba_NetworkNames, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, custom_cpu_library, custom_cldnn, performance_counter, nIsHardwareOK); +#endif + } + else + { + printf("\n****************\n"); + printf("No License Key"); + printf("\n****************\n"); + + //Slicense key٬O|Bhttp server, iH/serverdߦAA + //http_ip_address = (ip_address) ? ip_address : NULL; + + //http_http_port = http_port; + licenseType = _TRIAL_LICENSE_FPS06; + + +#ifdef TEST_DETECTOR_MEM + test_detector_mem(NULL, cnn_type, NULL, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, NULL, NULL, performance_counter, nIsHardwareOK); +#endif + }/// if (fe && li && st && et && id) + } + else + printf("config.json parse FAIL.\n"); + } + } + else + printf("-http_port %d not found!\n", http_port); + + //printf("999 get password = %s \n", accountData[0].account_password); + + printf("\n[run_server] end\n"); +} + +void getCameraPlugInInfo() { + //printf("\n---------------get Camera PlugIn Info start\n"); + char filename[1024] = { 0 }; + strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + cJSON *description; + description = cJSON_GetObjectItem(plugin, "description"); + + if (description) { + if (strstr(description->valuestring, "LILIN") != NULL) { + //printf("\n---------------get Camera PlugIn Info 1\n"); + g_check_if_no_brand = 0; + } + else { + //printf("\n---------------get Camera PlugIn Info 2\n"); + g_check_if_no_brand = 1; + } + } + else { + //printf("\n---------------get Camera PlugIn Info 3\n"); + g_check_if_no_brand = 0; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + //printf("\n---------------get Camera PlugIn Info end\n"); +} + +long getCurrentTime() { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + +static int CheckIsExistingWeight = 1; +int IsExistingWeight(size_t featureType, size_t featureType2) +{ + int nHasFeature = 0; + int count_weight = 0; + +#ifdef GY_OS_AMBA + if (strcmp(WeightFileModeName, "mod004") == 0) + { + if (weightfileList[30].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[30].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + CheckIsExistingWeight = 0; + } + } + else +#endif + { + if (weightfileList[15].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { +#ifdef GY_OS_V_SERIES + if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + } +#else + nHasFeature = 1; + count_weight++; +#endif + + CheckIsExistingSpeed = 1; + } + else if (weightfileList[15].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) + { + CheckIsExistingWeight = 0; + } + } + + if (weightfileList[27].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[27].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[28].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[28].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[11].enable_weight_to_run == 1 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[11].enable_weight_to_run == 0 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[13].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[13].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[22].enable_weight_to_run == 1 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[22].enable_weight_to_run == 0 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { + CheckIsExistingWeight = 0; + } + + if (weightfileList[23].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[23].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) { + CheckIsExistingWeight = 0; + } + + if (strcmp(WeightFileModeName, "mod003") != 0) { + if (weightfileList[12].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[12].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + CheckIsExistingWeight = 0; + } + } + else { + if (weightfileList[25].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[25].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) + { + CheckIsExistingWeight = 0; + } + } + + if (weightfileList[14].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[14].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[26].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + nHasFeature = 1; + count_weight++; + } + else if (weightfileList[26].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) + { + CheckIsExistingWeight = 0; + } + + if (strcmp(WeightFileModeName, "mod003") != 0) { + if (weightfileList[0].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[0].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + CheckIsExistingWeight = 0; + } + } + else { + if (weightfileList[29].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[29].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) + { + CheckIsExistingWeight = 0; + } + } + + if ((featureType & FEATURE_AIFISHTRAF) == FEATURE_AIFISHTRAF) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_POK_DET) != 0) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_HUM_POS) != 0) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_LED_DGT) != 0) + { + CheckIsExistingWeight = 0; + } + if ((featureType & FEATURE_SHOES_DET) != 0) + { + CheckIsExistingWeight = 0; + } + if (weightfileList[10].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_LOGO) != 0) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[10].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_LOGO) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[7].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_TWN) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[7].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_TWN) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[1].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_EUR) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[1].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_EUR) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_SEA) != 0) || + (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) || + (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0)) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if ((weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_SEA) != 0) || + (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) || + (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0)) + { + CheckIsExistingWeight = 0; + } + +#if 0 + if (weightfileList[9].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[9].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) + { + CheckIsExistingWeight = 0; + } +#endif + + /* + if ((featureType & FEATURE_LPR_CNA) != 0) + { + CheckIsExistingWeight = 0; + }*/ + + if (weightfileList[17].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_MEA) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[17].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_MEA) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[19].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_AUS) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[19].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_AUS) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[8].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_USA) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if(weightfileList[8].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_USA) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[2].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_GBR) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[2].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_GBR) != 0) + { + CheckIsExistingWeight = 0; + } + +#if 0 + if (weightfileList[24].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[24].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0) + { + CheckIsExistingWeight = 0; + } +#endif + + if (weightfileList[3].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_JPN) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[3].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_JPN) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((featureType & FEATURE_LPR_IND) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[6].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_THA) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[6].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_THA) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((featureType & FEATURE_LPR_LAO) != 0) + { + CheckIsExistingWeight = 0; + } + if (weightfileList[16].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_BGD) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[16].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_BGD) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[4].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_PHL) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[4].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_PHL) != 0) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[18].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_CNT) != 0) + { + if (g_check_if_OK_getfeatures == 0) { + CheckIsExistingWeight = 0; + } + else { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + } + else if (weightfileList[18].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_CNT) != 0) + { + CheckIsExistingWeight = 0; + } + + if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + featureType2 == FEATURE_EMPTY) + { + CheckIsExistingWeight = 0; + } + + if (g_IsCustomWeight == 1) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + + if (weightfileList[20].enable_weight_to_run == 1 && g_IsRadarDevice == 1) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if (weightfileList[20].enable_weight_to_run == 0 && g_IsRadarDevice == 1) + { + CheckIsExistingWeight = 0; + } + + if (weightfileList[21].enable_weight_to_run == 1 && g_IsToFDevice == 1) + { + nHasFeature = 1; + count_weight++; + CheckIsExistingSpeed = 1; + } + else if(weightfileList[21].enable_weight_to_run == 0 && g_IsToFDevice == 1){ + CheckIsExistingWeight = 0; + } + + if (unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 1) { + nHasFeature = 1; + count_weight++; + } + else if(unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 0){ + CheckIsExistingWeight = 0; + } + + if (count_weight >= 2) { +#ifdef GY_OS_NOVA + CheckIsExistingWeight = 0; +#endif + } + + return (CheckIsExistingWeight) > 0 && nHasFeature == 1 ? 1 : 0; +} +void RefreshCheckExistingWeight() +{ + CheckIsExistingWeight = 1; +} +#ifdef GY_OS_AMBA +void cavalry_gen_sdk_3_0(char * bin_name) { + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "/usr/local/bin/cavalry_gen -f %s -t /emmc/plugin/Aida/temp.bin -V 2.2.8.3", bin_name); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "cp /emmc/plugin/Aida/temp.bin %s", bin_name); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -f /emmc/plugin/Aida/temp.bin"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } +} +#endif + +void initial_weight_settings() { + //|ھڳ]wɡAإvO_Ұ + strcpy(weightfileList[0].weight_repository, "AIAML"); + strcpy(weightfileList[1].weight_repository, "AIANPREUR"); + strcpy(weightfileList[2].weight_repository, "AIANPRGBR"); + strcpy(weightfileList[3].weight_repository, "AIANPRJPN"); + strcpy(weightfileList[4].weight_repository, "AIANPRPHL"); + strcpy(weightfileList[5].weight_repository, "AIANPRSEA"); + strcpy(weightfileList[6].weight_repository, "AIANPRTHA"); + strcpy(weightfileList[7].weight_repository, "AIANPRTWN"); + strcpy(weightfileList[8].weight_repository, "AIANPRUSA"); + strcpy(weightfileList[9].weight_repository, "AIANPRVNM"); + strcpy(weightfileList[10].weight_repository, "AICarMake"); + strcpy(weightfileList[11].weight_repository, "AIFIRE"); + strcpy(weightfileList[12].weight_repository, "AIHUMAN"); + strcpy(weightfileList[13].weight_repository, "AISAFTY"); + strcpy(weightfileList[14].weight_repository, "AISHIP"); + strcpy(weightfileList[15].weight_repository, "AITRAFFIC"); + strcpy(weightfileList[16].weight_repository, "AIANPRBGD"); + strcpy(weightfileList[17].weight_repository, "AIANPRMEA"); + strcpy(weightfileList[18].weight_repository, "AIANPRCNT"); + strcpy(weightfileList[19].weight_repository, "AIANPRAUS"); + strcpy(weightfileList[20].weight_repository, "AIRADAR"); // Ken 2022-10-13 + strcpy(weightfileList[21].weight_repository, "AITOF"); + strcpy(weightfileList[22].weight_repository, "AIRAILWAY"); + strcpy(weightfileList[23].weight_repository, "AISPORTS"); + strcpy(weightfileList[24].weight_repository, "AIANPRIDN"); + strcpy(weightfileList[25].weight_repository, "AIGENDER"); + strcpy(weightfileList[26].weight_repository, "AIPRODUCTION"); + strcpy(weightfileList[27].weight_repository, "AIGARBAGE"); + strcpy(weightfileList[28].weight_repository, "AIAERO"); + strcpy(weightfileList[29].weight_repository, "AIFRONTBACK"); + strcpy(weightfileList[30].weight_repository, "AITHERMAL"); + + for (size_t index_weightfile = 0; index_weightfile < MAX_WEIGHT_FILE_LIST; index_weightfile++) { + weightfileList[index_weightfile].enable_weight_to_run = 0; + } + + char c_file_name_weight_setting[1024] = { 0 }; + strcpy(c_file_name_weight_setting, "/emmc/plugin/Aida_data/weight_setting.json"); + + if (!FileExist(c_file_name_weight_setting) || ReadFileSize(c_file_name_weight_setting) == 0) + { + printf("weight_setting file doesn't exist.\n"); + cJSON *s_root = cJSON_CreateObject(); + cJSON_AddItemToObject(s_root, "mode_name", cJSON_CreateString("mode_err")); + //AIAML,AIANPREUR,AIANPRGBR,AIANPRJPN,AIANPRPHL,AIANPRSEA,AIANPRTHA,AIANPRTWN,AIANPRUSA,AIANPRVNM,AICarMake,AIFIRE,AIHUMAN,AISAFTY,AISHIP,AITRAFFIC + cJSON_AddItemToObject(s_root, "mode_repository", cJSON_CreateString("")); + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(c_file_name_weight_setting, "w"); + if (f == NULL) + { + printf("Error opening setting file!\n"); + } + else { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (s_root) { + free(s_root); + s_root = NULL; + } + } + + cJSON* root_weight_setting, *mode_name, *mode_repository; + + if (!FileExist(c_file_name_weight_setting)) + { + printf("%s doesn't exist.\n", c_file_name_weight_setting); + } + else + { + char* fileBuf_weight_setting = ReadAllBytes(c_file_name_weight_setting); + if (fileBuf_weight_setting) { + root_weight_setting = cJSON_Parse(fileBuf_weight_setting); + + if (fileBuf_weight_setting) { + free(fileBuf_weight_setting); + fileBuf_weight_setting = NULL; + } + mode_name = cJSON_GetObjectItem(root_weight_setting, "mode_name"); + mode_repository = cJSON_GetObjectItem(root_weight_setting, "mode_repository"); + + strcpy(WeightFileModeName, mode_name->valuestring); + char temp_buf_mode_repository[1024] = { 0 }; + strcpy(temp_buf_mode_repository, mode_repository->valuestring); + + if (strstr(temp_buf_mode_repository, "AIAML") != NULL) { + weightfileList[0].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPREUR") != NULL) { + weightfileList[1].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRGBR") != NULL) { + weightfileList[2].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRJPN") != NULL) { + weightfileList[3].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRPHL") != NULL) { + weightfileList[4].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRSEA") != NULL) { + weightfileList[5].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRTHA") != NULL) { + weightfileList[6].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRTWN") != NULL) { + weightfileList[7].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRUSA") != NULL) { + weightfileList[8].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRVNM") != NULL) { + weightfileList[9].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AICarMake") != NULL) { + weightfileList[10].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIFIRE") != NULL) { + weightfileList[11].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIHUMAN") != NULL) { + weightfileList[12].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AISAFTY") != NULL) { + weightfileList[13].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AISHIP") != NULL) { + weightfileList[14].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AITRAFFIC") != NULL) { + weightfileList[15].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRBGD") != NULL) { + weightfileList[16].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRMEA") != NULL) { + weightfileList[17].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRCNT") != NULL) { + weightfileList[18].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIANPRAUS") != NULL) { + weightfileList[19].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AIRADAR") != NULL) { + weightfileList[20].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AITOF") != NULL) { + weightfileList[21].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIRAILWAY") != NULL) { + weightfileList[22].enable_weight_to_run = 1; + } + if (strstr(temp_buf_mode_repository, "AISPORTS") != NULL) { + weightfileList[23].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIANPRIDN") != NULL) { + weightfileList[24].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIGENDER") != NULL) { + weightfileList[25].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIPRODUCTION") != NULL) { + weightfileList[26].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIGARBAGE") != NULL) { + weightfileList[27].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIAERO") != NULL) { + weightfileList[28].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AIFRONTBACK") != NULL) { + weightfileList[29].enable_weight_to_run = 1; + } + + if (strstr(temp_buf_mode_repository, "AITHERMAL") != NULL) { + weightfileList[30].enable_weight_to_run = 1; + } + + if (root_weight_setting) { + cJSON_Delete(root_weight_setting); + root_weight_setting = NULL; + } + } + } +} + +void file_management() { + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; +#ifdef GY_OS_NOVA + char config_smallPATH[1024] = { 0 }; +#endif + char config_installPATH[1024] = { 0 }; + +#ifdef GY_OS_NOVA + char config_small_installPATH[1024] = { 0 }; +#endif + char config_bakPATH[1024] = { 0 }; + + char events_installPATH[1024] = { 0 }; + char eventsPATH[1024] = { 0 }; + char events_bakPATH[1024] = { 0 }; + + char tof_installPATH[1024] = { 0 }; + char tofPATH[1024] = { 0 }; + char tof_bakPATH[1024] = { 0 }; + + char emails_installPATH[1024] = { 0 }; + char emailsPATH[1024] = { 0 }; + char emails_bakPATH[1024] = { 0 }; + + char cold_objects_installPATH[1024] = { 0 }; + char cold_objectsPATH[1024] = { 0 }; + + char face_installPATH[1024] = { 0 }; + char facePATH[1024] = { 0 }; + + char db_fflprPATH[1024] = { 0 }; + char db_fflpr_installPATH[1024] = { 0 }; + char db_fflpr_bakPATH[1024] = { 0 }; + + char db_facePATH[1024] = { 0 }; + char db_face_installPATH[1024] = { 0 }; + char db_face_bakPATH[1024] = { 0 }; + + char face_license_PATH[1024] = { 0 }; + char face_license_installPATH[1024] = { 0 }; + char face_license_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_smallPATH, exePath); +#endif + strcpy(config_installPATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_small_installPATH, exePath); +#endif + strcpy(config_bakPATH, exePath); + + strcpy(eventsPATH, exePath); + strcpy(events_installPATH, exePath); + strcpy(events_bakPATH, exePath); + + strcpy(tofPATH, exePath); + strcpy(tof_installPATH, exePath); + strcpy(tof_bakPATH, exePath); + + strcpy(emailsPATH, exePath); + strcpy(emails_installPATH, exePath); + strcpy(emails_bakPATH, exePath); + + strcpy(cold_objectsPATH, exePath); + strcpy(cold_objects_installPATH, exePath); + + strcpy(facePATH, exePath); + strcpy(face_installPATH, exePath); + + strcpy(db_fflprPATH, exePath); + strcpy(db_fflpr_installPATH, exePath); + strcpy(db_fflpr_bakPATH, exePath); + + strcpy(db_facePATH, exePath); + strcpy(db_face_installPATH, exePath); + strcpy(db_face_bakPATH, exePath); + + strcpy(face_license_PATH, exePath); + strcpy(face_license_installPATH, exePath); + strcpy(face_license_bakPATH, exePath); + + strcat(configPATH, "config.json"); +#ifdef GY_OS_NOVA + strcat(config_smallPATH, "config_small.json"); +#endif + strcat(config_installPATH, "config_install.json"); + +#ifdef GY_OS_NOVA + strcat(config_small_installPATH, "config_small_install.json"); +#endif + strcat(config_bakPATH, "config_bak.json"); + + strcat(eventsPATH, "events.json"); + strcat(events_installPATH, "events_install.json"); + strcat(events_bakPATH, "events_bak.json"); + + strcat(tofPATH, "tof.json"); + strcat(tof_installPATH, "tof_install.json"); + strcat(tof_bakPATH, "tof_bak.json"); + + strcat(emailsPATH, "emails.json"); + strcat(emails_installPATH, "emails_install.json"); + strcat(emails_bakPATH, "emails_bak.json"); + + strcat(cold_objectsPATH, "cold_objects.json"); + strcat(cold_objects_installPATH, "cold_objects_install.json"); + + strcat(facePATH, "sfe/iengine.lic"); + strcat(face_installPATH, "sfe/iengine_install.lic"); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + strcat(db_fflprPATH, "db_fflpr.db"); + strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); + + strcat(db_facePATH, "db_face.db"); + strcat(db_face_installPATH, "db_face_install_2.db"); + +#endif + + //T{config_bak.jsonSa + { + char* fileBuf = ReadAllBytes(config_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("config_bakPATH parse FAIL.0\n"); + + if (FileExist(config_bakPATH)) { + int del = unlink(config_bakPATH); + if (!del) { + //printf("config_bakPATH is Deleted successfully."); + } + else { + printf("config_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) >= 20000) + { + //CopyFileTo(configPATH, config_bakPATH); + CopyFileTo(config_bakPATH, configPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bak to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + else if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) < 20000) + { + int del = remove(config_bakPATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("config_bak cannot be Deleted.\n"); + } + } + + //T{config.jsonSa + { + char* fileBuf = ReadAllBytes(configPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("configPATH parse FAIL.0\n"); + + if (FileExist(config_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bakPATH to main_0 config <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(config_bakPATH, configPATH); + } + else { + if (FileExist(configPATH)) { + int del = unlink(configPATH); + if (!del) { + //printf("configPATH is Deleted successfully."); + } + else { + printf("configPATH cannot be Deleted.\n"); + } + } + } + } + } + } + + //T{events_bak.jsonSa + { + char* fileBuf = ReadAllBytes(events_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("events_bakPATH parse FAIL.0\n"); + + if (FileExist(events_bakPATH)) { + int del = unlink(events_bakPATH); + if (!del) { + //printf("config_bakPATH is Deleted successfully."); + } + else { + printf("events_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) >= 8000) + { + CopyFileTo(events_bakPATH, eventsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bak to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + else if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) < 8000) + { + int del = remove(events_bakPATH); + if (!del) { + //printf("events_bak is Deleted successfully."); + } + else { + printf("events_bak cannot be Deleted.\n"); + } + } + + //T{events.jsonSa + { + char* fileBuf = ReadAllBytes(eventsPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("eventsPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("eventsPATH parse FAIL.0\n"); + + if (FileExist(events_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(events_bakPATH, eventsPATH); + } + else { + if (FileExist(events_bakPATH)) { + int del = unlink(events_bakPATH); + if (!del) { + //printf("events_bakPATH is Deleted successfully."); + } + else { + printf("events_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + } + + //T{tof_bak.jsonSa + { + char* fileBuf = ReadAllBytes(tof_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("tof_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("tof_bakPATH parse FAIL.0\n"); + + if (FileExist(tof_bakPATH)) { + int del = unlink(tof_bakPATH); + if (!del) { + //printf("tof_bakPATH is Deleted successfully."); + } + else { + printf("tof_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) >= 250) + { + CopyFileTo(tof_bakPATH, tofPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bak to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + else if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) < 250) + { + int del = remove(tof_bakPATH); + if (!del) { + //printf("tof_bak is Deleted successfully."); + } + else { + printf("tof_bak cannot be Deleted.\n"); + } + } + + //T{tof.jsonSa + { + char* fileBuf = ReadAllBytes(tofPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("eventsPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("tofPATH parse FAIL.0\n"); + + if (FileExist(tof_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bakPATH to main_0 tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(tof_bakPATH, tofPATH); + } + else { + if (FileExist(tof_bakPATH)) { + int del = unlink(tof_bakPATH); + if (!del) { + //printf("tof_bakPATH is Deleted successfully."); + } + else { + printf("tof_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + } + + //T{emails_bak.jsonSa + { + char* fileBuf = ReadAllBytes(emails_bakPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("config_bakPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + //printf("emails_bakPATH parse FAIL.0\n"); + + if (FileExist(emails_bakPATH)) { + int del = unlink(emails_bakPATH); + if (!del) { + //printf("emails_bakPATH is Deleted successfully."); + } + else { + printf("emails_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + + //T{emails.jsonSa + { + char* fileBuf = ReadAllBytes(emailsPATH); + if (fileBuf) { + cJSON* root; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + //printf("eventsPATH parse OK\n"); + cJSON_Delete(root); + root = NULL; + } + else { + printf("emailsPATH parse FAIL.0\n"); + + if (FileExist(emails_bakPATH)) { + printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_bakPATH to main_0 emails <<<<<<<<<<<<<<<<<<<<<<<\n"); + CopyFileTo(emails_bakPATH, emailsPATH); + } + else { + if (FileExist(emails_bakPATH)) { + int del = unlink(emails_bakPATH); + if (!del) { + //printf("emails_bakPATH is Deleted successfully."); + } + else { + printf("emails_bakPATH cannot be Deleted.\n"); + } + } + } + } + } + } +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //T{OOupdate LPKGApGOhRªdbAHŦXsdb榡C + { + char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; + if (FileExist(NEW_UPDATE_PATH)) { + int del = unlink(NEW_UPDATE_PATH); + if (!del) { + //printf("txt is Deleted successfully."); + } + else { + printf("NEW UPDATE PATH cannot be Deleted.\n"); + } + + /*char DB_FFLPR_PATH[1024] = "/emmc/plugin/Aida_data/db_fflpr.db"; + if (FileExist(DB_FFLPR_PATH)) { + int del = unlink(DB_FFLPR_PATH); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("DB FFLPR PATH cannot be Deleted.\n"); + } + }*/ + + + char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; + if (FileExist(DB_FACE_PATH)) { + int del = unlink(DB_FACE_PATH); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("DB FACE PATH cannot be Deleted.\n"); + } + } + + delete_file("/emmc/plugin/Aida_data/sfe/storage/entities.rec"); + delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.map"); + delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.rec"); + delete_file("/emmc/plugin/Aida_data/sfe/storage/labels.rec"); + + } + } + + { //face db + char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; + if (FileExist(NEW_UPDATE_PATH)) { + int del = unlink(NEW_UPDATE_PATH); + if (!del) { + //printf("txt is Deleted successfully."); + } + else { + printf("NEW UPDATE PATH cannot be Deleted.\n"); + } + + char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; + if (FileExist(DB_FACE_PATH)) { + int del = unlink(DB_FACE_PATH); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("DB FACE PATH cannot be Deleted.\n"); + } + } + } + } +#endif + if (FileExist(config_installPATH) == 1 && (FileExist(configPATH) == 0 || ReadFileSize(configPATH) == 0)) { + CopyFileTo(config_installPATH, configPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(config_installPATH) == 1 && (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) == 0)) { + CopyFileTo(config_installPATH, config_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to back config <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + +#ifdef GY_OS_NOVA + if (FileExist(config_small_installPATH) == 1 && (FileExist(config_smallPATH) == 0 || ReadFileSize(config_smallPATH) == 0)) { + CopyFileTo(config_small_installPATH, config_smallPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_small_installPATH to main config_small <<<<<<<<<<<<<<<<<<<<<<<\n"); + } +#endif + + if (FileExist(events_installPATH) == 1 && (FileExist(eventsPATH) == 0 || ReadFileSize(eventsPATH) == 0)) { + CopyFileTo(events_installPATH, eventsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(events_installPATH) == 1 && (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) == 0)) { + CopyFileTo(events_installPATH, events_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to back events <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(tof_installPATH) == 1 && (FileExist(tofPATH) == 0 || ReadFileSize(tofPATH) == 0)) { + CopyFileTo(tof_installPATH, tofPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(tof_installPATH) == 1 && (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) == 0)) { + CopyFileTo(tof_installPATH, tof_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to back tof <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(emails_installPATH) == 1 && (FileExist(emailsPATH) == 0 || ReadFileSize(emailsPATH) == 0)) { + CopyFileTo(emails_installPATH, emailsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to main emails <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(emails_installPATH) == 1 && (FileExist(emails_bakPATH) == 1 && ReadFileSize(emails_bakPATH) == 0)) { + CopyFileTo(emails_installPATH, emails_bakPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to back emails <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + if (FileExist(db_fflpr_installPATH) == 1 && (FileExist(db_fflprPATH) == 0 || ReadFileSize(db_fflprPATH) == 0)) { + CopyFileTo(db_fflpr_installPATH, db_fflprPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_fflpr_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + if (FileExist(db_face_installPATH) == 1 && (FileExist(db_facePATH) == 0 || ReadFileSize(db_facePATH) == 0)) { + CopyFileTo(db_face_installPATH, db_facePATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_face_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); + } +#endif + if (FileExist(face_installPATH) == 1 && (FileExist(facePATH) == 0 || ReadFileSize(facePATH) == 0)) { + CopyFileTo(face_installPATH, facePATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy face_install to main face <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist(cold_objects_installPATH) == 1 && (FileExist(cold_objectsPATH) == 0 || ReadFileSize(cold_objectsPATH) == 0)) { + CopyFileTo(cold_objects_installPATH, cold_objectsPATH); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy cold_objects_install to main cold_objects <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_bak.js", "/emmc/plugin/Aida/heatmap_data.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_bak to main heatmap_data <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_1_bak.js", "/emmc/plugin/Aida/heatmap_data_1.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_1_bak to main heatmap_data_1 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_2_bak.js", "/emmc/plugin/Aida/heatmap_data_2.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_2_bak to main heatmap_data_2 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_3_bak.js", "/emmc/plugin/Aida/heatmap_data_3.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_3_bak to main heatmap_data_3 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_4_bak.js", "/emmc/plugin/Aida/heatmap_data_4.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_4_bak to main heatmap_data_4 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_5_bak.js", "/emmc/plugin/Aida/heatmap_data_5.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_5_bak to main heatmap_data_5 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_6_bak.js", "/emmc/plugin/Aida/heatmap_data_6.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_6_bak to main heatmap_data_6 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + + if (FileExist("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") >= 1) { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_7_bak.js", "/emmc/plugin/Aida/heatmap_data_7.js"); + printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_7_bak to main heatmap_data_7 <<<<<<<<<<<<<<<<<<<<<<<\n"); + } + +#ifdef GY_OS_AMBA + char sdk_versionPATH[1024] = { 0 }; + strcpy(sdk_versionPATH, exePath); + strcat(sdk_versionPATH, "sdk_version.txt"); + + { + char *filename = sdk_versionPATH; + if (FileExist(filename)) { + char* fileBuf = ReadAllBytes(filename); + + //printf("\n[run server]----sdk version:%s\n", fileBuf); + + if (strstr(fileBuf, "3.0") != NULL) { + g_IsSDK_3_0 = 1; + } + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + } + } +#endif +} + +#ifdef GY_OS_NOVA +int get_pid_nova_driver() { + char *temp = NULL; + int size_psBuffer = 512; + char psBuffer[512] = { 0 }; + + { + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "pidof nova_driver"); + FILE * pPipe; + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) { + temp = fgets(psBuffer, size_psBuffer, pPipe); + if (pPipe != NULL) + vpclose(pPipe); + } + } + if (temp != NULL && (int)strlen(psBuffer) >= 1) { + /* + printf("\n-------------------------------\n"); + printf("\psBuffer: %d\n", atoi(psBuffer)); + printf("\n-------------------------------\n"); + */ + return atoi(psBuffer); + } + + return -1; +} + +int g_check_run_nova_detection = 0; +void *RUN_NOVA_DETECTION(void *ptr) { //A11en + pthread_detach(pthread_self()); + setPthreadName("RUN_NOVA"); + usSleep(1000000); + + system("killall -15 nova_driver"); + usSleep(15000000); + char cmd[256] = { 0 }; + sprintf(cmd,"/emmc/plugin/Aida_data/nova_driver server -http_port %s &", accountData[0].account_aida_port); + g_check_run_nova_detection = 1; + system(cmd); + + usSleep(2000000); + + if (get_live_mode_flag() == 1 && g_check_run_nova_detection == 1) { + if (get_pid_nova_driver() == -1) { + + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "get_pid_nova_driver() == -1"); + write_to_logs_html(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } + } + + pthread_exit(NULL); +} +#endif \ No newline at end of file diff --git a/src/detector_Ming.h b/src/detector_Ming.h new file mode 100644 index 0000000..5f4ebf5 --- /dev/null +++ b/src/detector_Ming.h @@ -0,0 +1,17 @@ +#pragma once +#ifndef DETECTOR_H +#define DETECTOR_H +#include "define_inc.h" +#include <tchar.h> +#include "setting.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/dropout_layer.c b/src/dropout_layer.c new file mode 100644 index 0000000..780554f --- /dev/null +++ b/src/dropout_layer.c @@ -0,0 +1,60 @@ +#include "dropout_layer.h" +#include "utils.h" +#include "cuda.h" +#include <stdlib.h> +#include <stdio.h> + +dropout_layer make_dropout_layer(int batch, int inputs, float probability) +{ + dropout_layer l = {0}; + l.type = DROPOUT; + l.probability = probability; + l.inputs = inputs; + l.outputs = inputs; + l.batch = batch; + l.rand = calloc(inputs*batch, sizeof(float)); + l.scale = 1./(1.-probability); + l.forward = forward_dropout_layer; + l.backward = backward_dropout_layer; + #ifdef GPU + l.forward_gpu = forward_dropout_layer_gpu; + l.backward_gpu = backward_dropout_layer_gpu; + l.rand_gpu = cuda_make_array(l.rand, inputs*batch); + #endif + fprintf(stderr, "dropout p = %.2f %4d -> %4d\n", probability, inputs, inputs); + return l; +} + +void resize_dropout_layer(dropout_layer *l, int inputs) +{ + l->rand = realloc(l->rand, l->inputs*l->batch*sizeof(float)); + #ifdef GPU + cuda_free(l->rand_gpu); + + l->rand_gpu = cuda_make_array(l->rand, inputs*l->batch); + #endif +} + +void forward_dropout_layer(dropout_layer l, network net) +{ + int i; + if (!net.train) return; + for(i = 0; i < l.batch * l.inputs; ++i){ + float r = rand_uniform(0, 1); + l.rand[i] = r; + if(r < l.probability) net.input[i] = 0; + else net.input[i] *= l.scale; + } +} + +void backward_dropout_layer(dropout_layer l, network net) +{ + int i; + if(!net.delta) return; + for(i = 0; i < l.batch * l.inputs; ++i){ + float r = l.rand[i]; + if(r < l.probability) net.delta[i] = 0; + else net.delta[i] *= l.scale; + } +} + diff --git a/src/dropout_layer.h b/src/dropout_layer.h new file mode 100644 index 0000000..3188a38 --- /dev/null +++ b/src/dropout_layer.h @@ -0,0 +1,21 @@ +#pragma once +#ifndef DROPOUT_LAYER_H +#define DROPOUT_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" + +typedef layer dropout_layer; + +dropout_layer make_dropout_layer(int batch, int inputs, float probability); + +void forward_dropout_layer(dropout_layer l, network net); +void backward_dropout_layer(dropout_layer l, network net); +void resize_dropout_layer(dropout_layer *l, int inputs); + +#ifdef GPU +void forward_dropout_layer_gpu(dropout_layer l, network net); +void backward_dropout_layer_gpu(dropout_layer l, network net); + +#endif +#endif diff --git a/src/dropout_layer_kernels.cu b/src/dropout_layer_kernels.cu new file mode 100644 index 0000000..bd12b67 --- /dev/null +++ b/src/dropout_layer_kernels.cu @@ -0,0 +1,41 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "dropout_layer.h" +#include "cuda.h" +#include "utils.h" +} + +__global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale) +{ + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id < size) input[id] = (rand[id] < prob) ? 0 : input[id]*scale; +} + +void forward_dropout_layer_gpu(dropout_layer layer, network net) +{ + if (!net.train) return; + int size = layer.inputs*layer.batch; + cuda_random(layer.rand_gpu, size); + /* + int i; + for(i = 0; i < size; ++i){ + layer.rand[i] = rand_uniform(); + } + cuda_push_array(layer.rand_gpu, layer.rand, size); + */ + + yoloswag420blazeit360noscope<<<cuda_gridsize(size), BLOCK>>>(net.input_gpu, size, layer.rand_gpu, layer.probability, layer.scale); + check_error(cudaPeekAtLastError()); +} + +void backward_dropout_layer_gpu(dropout_layer layer, network net) +{ + if(!net.delta_gpu) return; + int size = layer.inputs*layer.batch; + + yoloswag420blazeit360noscope<<<cuda_gridsize(size), BLOCK>>>(net.delta_gpu, size, layer.rand_gpu, layer.probability, layer.scale); + check_error(cudaPeekAtLastError()); +} diff --git a/src/encrypt.c b/src/encrypt.c new file mode 100644 index 0000000..8b2f78c --- /dev/null +++ b/src/encrypt.c @@ -0,0 +1,360 @@ +/* encrypt.cpp + * Performs encryption using AES 128-bit + * @author Cecelia Wisniewska + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "structures.h" + +/* Serves as the initial round during encryption + * AddRoundKey is simply an XOR of a 128-bit block with the 128-bit key. + */ +void AddRoundKey(unsigned char * state, unsigned char * roundKey) { + for (int i = 0; i < 16; i++) { + state[i] ^= roundKey[i]; + } +} + +/* Perform substitution to each of the 16 bytes + * Uses S-box as lookup table + */ +void SubBytes(unsigned char * state) { + for (int i = 0; i < 16; i++) { + state[i] = s[state[i]]; + } +} + +// Shift left, adds diffusion +void ShiftRows(unsigned char * state) { + unsigned char tmp[16]; + + /* Column 1 */ + tmp[0] = state[0]; + tmp[1] = state[5]; + tmp[2] = state[10]; + tmp[3] = state[15]; + + /* Column 2 */ + tmp[4] = state[4]; + tmp[5] = state[9]; + tmp[6] = state[14]; + tmp[7] = state[3]; + + /* Column 3 */ + tmp[8] = state[8]; + tmp[9] = state[13]; + tmp[10] = state[2]; + tmp[11] = state[7]; + + /* Column 4 */ + tmp[12] = state[12]; + tmp[13] = state[1]; + tmp[14] = state[6]; + tmp[15] = state[11]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + + /* MixColumns uses mul2, mul3 look-up tables + * Source of diffusion + */ +void MixColumns(unsigned char * state) { + unsigned char tmp[16]; + + tmp[0] = (unsigned char) mul2[state[0]] ^ mul3[state[1]] ^ state[2] ^ state[3]; + tmp[1] = (unsigned char) state[0] ^ mul2[state[1]] ^ mul3[state[2]] ^ state[3]; + tmp[2] = (unsigned char) state[0] ^ state[1] ^ mul2[state[2]] ^ mul3[state[3]]; + tmp[3] = (unsigned char) mul3[state[0]] ^ state[1] ^ state[2] ^ mul2[state[3]]; + + tmp[4] = (unsigned char)mul2[state[4]] ^ mul3[state[5]] ^ state[6] ^ state[7]; + tmp[5] = (unsigned char)state[4] ^ mul2[state[5]] ^ mul3[state[6]] ^ state[7]; + tmp[6] = (unsigned char)state[4] ^ state[5] ^ mul2[state[6]] ^ mul3[state[7]]; + tmp[7] = (unsigned char)mul3[state[4]] ^ state[5] ^ state[6] ^ mul2[state[7]]; + + tmp[8] = (unsigned char)mul2[state[8]] ^ mul3[state[9]] ^ state[10] ^ state[11]; + tmp[9] = (unsigned char)state[8] ^ mul2[state[9]] ^ mul3[state[10]] ^ state[11]; + tmp[10] = (unsigned char)state[8] ^ state[9] ^ mul2[state[10]] ^ mul3[state[11]]; + tmp[11] = (unsigned char)mul3[state[8]] ^ state[9] ^ state[10] ^ mul2[state[11]]; + + tmp[12] = (unsigned char)mul2[state[12]] ^ mul3[state[13]] ^ state[14] ^ state[15]; + tmp[13] = (unsigned char)state[12] ^ mul2[state[13]] ^ mul3[state[14]] ^ state[15]; + tmp[14] = (unsigned char)state[12] ^ state[13] ^ mul2[state[14]] ^ mul3[state[15]]; + tmp[15] = (unsigned char)mul3[state[12]] ^ state[13] ^ state[14] ^ mul2[state[15]]; + + for (int i = 0; i < 16; i++) { + state[i] = tmp[i]; + } +} + +/* Each round operates on 128 bits at a time + * The number of rounds is defined in AESEncrypt() + */ +void Round(unsigned char * state, unsigned char * key) { + SubBytes(state); + ShiftRows(state); + MixColumns(state); + AddRoundKey(state, key); +} + + // Same as Round() except it doesn't mix columns +void FinalRound(unsigned char * state, unsigned char * key) { + SubBytes(state); + ShiftRows(state); + AddRoundKey(state, key); +} + +/* The AES encryption function + * Organizes the confusion and diffusion steps into one function + */ +void LILIN_AESEncrypt(unsigned char * message, unsigned char * expandedKey, unsigned char * encryptedMessage) { + unsigned char state[16]; // Stores the first 16 bytes of original message + + for (int i = 0; i < 16; i++) { + state[i] = message[i]; + } + + int numberOfRounds = 9; + + AddRoundKey(state, expandedKey); // Initial round + + for (int i = 0; i < numberOfRounds; i++) { + Round(state, expandedKey + (16 * (i+1))); + } + + FinalRound(state, expandedKey + 160); + + // Copy encrypted state to buffer + for (int i = 0; i < 16; i++) { + encryptedMessage[i] = state[i]; + } +} + +int hex2int(char ch) +{ + if (ch >= '0' && ch <= '9') + return ch - '0'; + if (ch >= 'A' && ch <= 'F') + return ch - 'A' + 10; + if (ch >= 'a' && ch <= 'f') + return ch - 'a' + 10; + return -1; +} + + +int LILIN_File_Encryption(char* source_file, char* dest_file, unsigned char* key_ptr, long* returned_length, int debug_mode) +{ + char message[512]; + long originalLen; + unsigned char *original_content = NULL; + + if (source_file == NULL) + { + printf("No argument passed. Start in demo mode.\n"); + printf("Please enter the message to encrypt: "); + scanf("%511s", message); + originalLen = strlen((const char *)message); + printf("Original message length = %ld.\n", originalLen); + *returned_length = originalLen; // For outside use + } + else + { + FILE* infile = fopen(source_file, "rb"); + if (infile != NULL) + { + size_t result; + fseek(infile, 0, SEEK_END); + originalLen = ftell(infile); + *returned_length = originalLen; // For outside use + rewind(infile); + + original_content = (unsigned char*)malloc(sizeof(unsigned char) * originalLen); + if (original_content == NULL) + { + printf("Memory allocation error for original content! Require %ld bytes of available memory spaces.\n", originalLen); + return 1; + } + + result = fread(original_content, 1, originalLen, infile); + if (result != originalLen) + { + printf("Reading file interrupted or incomplete!\n"); + return 1; + } + + if (debug_mode) + { + printf("File content in ASCII:\n"); + printf("File content in decimal:\n"); + printf("------------------------------------\n"); + for (int i = 0; i < originalLen; i++) + { + printf("%d ", (int)original_content[i]); + if (i >= 1048576) + { + printf("...(File too large. Ignored.)..."); + break; + } + } + printf("\n"); + //printf("%s\n", original_content); + printf("------------------------------------\n"); + printf("File length = %ld bytes.\n", originalLen); + } + + fclose(infile); + } + else + { + printf("Unable to open file '%s'.\n", source_file); + return 1; + } + } + + long paddedMessageLen = originalLen; + if ((paddedMessageLen % 16) != 0) + { + paddedMessageLen = (paddedMessageLen / 16 + 1) * 16; // Pad message to 16 bytes + } + + unsigned char * paddedMessage = (unsigned char *)malloc(sizeof(unsigned char) * paddedMessageLen); + if (paddedMessage == NULL) + { + printf("Memory allocation error for padded message! Require %ld bytes of available memory spaces.\n", paddedMessageLen); + return 1; + } + + for (int i = 0; i < paddedMessageLen; i++) + { + if (i >= originalLen) + paddedMessage[i] = 0; + else + paddedMessage[i] = (source_file == NULL && original_content == NULL)? message[i] : original_content[i]; // Input by hands or from the file + } + + if (debug_mode) + { + printf("Padded message length = %ld\n", paddedMessageLen); + //printf("Padded message = %s\n", paddedMessage); + printf("Padded message in decimal = "); + for (int i = 0; i < paddedMessageLen; i++) + printf("%d ", (int)paddedMessage[i]); + printf("\n"); + } + + unsigned char * encryptedMessage = (unsigned char *)malloc(sizeof(unsigned char) * paddedMessageLen); + if (encryptedMessage == NULL) + { + printf("Memory allocation error for encrypted message! Require %ld bytes of available memory spaces.\n", paddedMessageLen); + return 1; + } + + if (key_ptr != NULL) + { + if (debug_mode) + { + printf("Key (int) = "); + for (int i=0; i<16; i++) + printf("%d ", key_ptr[i]); + printf("\n"); + } + + unsigned char expandedKey[176]; + KeyExpansion(key_ptr, expandedKey); + + for (int i = 0; i < paddedMessageLen; i += 16) + LILIN_AESEncrypt(paddedMessage+i, expandedKey, encryptedMessage+i); + + if (debug_mode) + { + printf("Encrypted message in decimal = "); + for (int i = 0; i < paddedMessageLen; i++) + { + printf("%d ", (int)encryptedMessage[i]); + if (i >= 1048576) + { + printf("...(File too large. Ignored.)..."); + break; + } + } + printf("\n"); + } + + // Write the encrypted string out to file "message.aes" + FILE* outfile; + char * write_filename; + if (dest_file != NULL) + { + outfile = fopen(dest_file, "wb"); + write_filename = dest_file; + } + else + { + write_filename = "message.aes"; + outfile = fopen(write_filename, "wb"); + } + + if (outfile != NULL) + { + fwrite(encryptedMessage, sizeof(char), paddedMessageLen, outfile); + if (debug_mode) + { + printf("Wrote encrypted message to file '%s'.\n", write_filename); + printf("Total file length = %ld\n", ftell(outfile)); // Should be the same to padded message length. + } + fclose(outfile); + } + else + { + printf("Unable to write encrypted content to the destination file!\n"); + return 1; + } + + // Free memory + if (original_content) { + free(original_content); + original_content = NULL; + } + + if (paddedMessage) { + free(paddedMessage); + paddedMessage = NULL; + } + + if (encryptedMessage) { + free(encryptedMessage); + encryptedMessage = NULL; + } + return 0; + } + else + { + printf("Unable to open key file!\n"); + return 1; + } +} + +/*int main(int argc, char *argv[]) +{ + printf("=====================================\n"); + printf(" LILIN 128-bit AES Encryption Tool \n"); + printf("=====================================\n"); + + int result = 0; + int debug_flag = 1; + long originalLen = 0; // Save original length when decrypting is required. + + if (argc == 1) // Only for debugging + { + result = LILIN_AES128_Encrypt(NULL, NULL, "public_keyfile", &originalLen, debug_flag); + } + else + { + result = LILIN_AES128_Encrypt(argv[1], argv[2], argv[3], &originalLen, debug_flag); + } + + return result; +}*/ diff --git a/src/exif.cpp b/src/exif.cpp new file mode 100644 index 0000000..9ad8ac3 --- /dev/null +++ b/src/exif.cpp @@ -0,0 +1,912 @@ +#include "exif.h" +#include <algorithm> +#include <cstdint> +#include <stdio.h> +#include <vector> + +using std::string; + +namespace { + struct Rational { + uint32_t numerator, denominator; + operator double() const { + if (denominator < 1e-20) { + return 0; + } + return static_cast<double>(numerator) / static_cast<double>(denominator); + } + }; + + // IF Entry + class IFEntry { + public: + using byte_vector = std::vector<uint8_t>; + using ascii_vector = std::string; + using short_vector = std::vector<uint16_t>; + using long_vector = std::vector<uint32_t>; + using rational_vector = std::vector<Rational>; + + IFEntry() + : tag_(0xFF), format_(0xFF), data_(0), length_(0), val_byte_(nullptr) {} + IFEntry(const IFEntry &) = delete; + IFEntry &operator=(const IFEntry &) = delete; + IFEntry(IFEntry &&other) + : tag_(other.tag_), + format_(other.format_), + data_(other.data_), + length_(other.length_), + val_byte_(other.val_byte_) { + other.tag_ = 0xFF; + other.format_ = 0xFF; + other.data_ = 0; + other.length_ = 0; + other.val_byte_ = nullptr; + } + ~IFEntry() { + delete_union(); + } + unsigned short tag() const { + return tag_; + } + void tag(unsigned short tag) { + tag_ = tag; + } + unsigned short format() const { + return format_; + } + bool format(unsigned short format) { + switch (format) { + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x07: + case 0x09: + case 0x0a: + case 0xff: + break; + default: + return false; + } + delete_union(); + format_ = format; + new_union(); + return true; + } + unsigned data() const { + return data_; + } + void data(unsigned data) { + data_ = data; + } + unsigned length() const { + return length_; + } + void length(unsigned length) { + length_ = length; + } + + // functions to access the data + // + // !! it's CALLER responsibility to check that format !! + // !! is correct before accessing it's field !! + // + // - getters are use here to allow future addition + // of checks if format is correct + byte_vector &val_byte() { + return *val_byte_; + } + ascii_vector &val_string() { + return *val_string_; + } + short_vector &val_short() { + return *val_short_; + } + long_vector &val_long() { + return *val_long_; + } + rational_vector &val_rational() { + return *val_rational_; + } + + private: + // Raw fields + unsigned short tag_; + unsigned short format_; + unsigned data_; + unsigned length_; + + // Parsed fields + union { + byte_vector *val_byte_; + ascii_vector *val_string_; + short_vector *val_short_; + long_vector *val_long_; + rational_vector *val_rational_; + }; + + void delete_union() { + switch (format_) { + case 0x1: + delete val_byte_; + val_byte_ = nullptr; + break; + case 0x2: + delete val_string_; + val_string_ = nullptr; + break; + case 0x3: + delete val_short_; + val_short_ = nullptr; + break; + case 0x4: + delete val_long_; + val_long_ = nullptr; + break; + case 0x5: + delete val_rational_; + val_rational_ = nullptr; + break; + case 0xff: + break; + default: + // should not get here + // should I throw an exception or ...? + break; + } + } + void new_union() { + switch (format_) { + case 0x1: + val_byte_ = new byte_vector(); + break; + case 0x2: + val_string_ = new ascii_vector(); + break; + case 0x3: + val_short_ = new short_vector(); + break; + case 0x4: + val_long_ = new long_vector(); + break; + case 0x5: + val_rational_ = new rational_vector(); + break; + case 0xff: + break; + default: + // should not get here + // should I throw an exception or ...? + break; + } + } + }; + + // Helper functions + template <typename T, bool alignIntel> + T parse(const unsigned char *buf); + + template <> + uint8_t parse<uint8_t, false>(const unsigned char *buf) { + return *buf; + } + + template <> + uint8_t parse<uint8_t, true>(const unsigned char *buf) { + return *buf; + } + + template <> + uint16_t parse<uint16_t, false>(const unsigned char *buf) { + return (static_cast<uint16_t>(buf[0]) << 8) | buf[1]; + } + + template <> + uint16_t parse<uint16_t, true>(const unsigned char *buf) { + return (static_cast<uint16_t>(buf[1]) << 8) | buf[0]; + } + + template <> + uint32_t parse<uint32_t, false>(const unsigned char *buf) { + return (static_cast<uint32_t>(buf[0]) << 24) | + (static_cast<uint32_t>(buf[1]) << 16) | + (static_cast<uint32_t>(buf[2]) << 8) | buf[3]; + } + + template <> + uint32_t parse<uint32_t, true>(const unsigned char *buf) { + return (static_cast<uint32_t>(buf[3]) << 24) | + (static_cast<uint32_t>(buf[2]) << 16) | + (static_cast<uint32_t>(buf[1]) << 8) | buf[0]; + } + + template <> + Rational parse<Rational, true>(const unsigned char *buf) { + Rational r; + r.numerator = parse<uint32_t, true>(buf); + r.denominator = parse<uint32_t, true>(buf + 4); + return r; + } + + template <> + Rational parse<Rational, false>(const unsigned char *buf) { + Rational r; + r.numerator = parse<uint32_t, false>(buf); + r.denominator = parse<uint32_t, false>(buf + 4); + return r; + } + + /** + * Try to read entry.length() values for this entry. + * + * Returns: + * true - entry.length() values were read + * false - something went wrong, vec's content was not touched + */ + template <typename T, bool alignIntel, typename C> + bool extract_values(C &container, const unsigned char *buf, const unsigned base, + const unsigned len, const IFEntry &entry) { + const unsigned char *data; + uint32_t reversed_data; + // if data fits into 4 bytes, they are stored directly in + // the data field in IFEntry + if (sizeof(T) * entry.length() <= 4) { + if (alignIntel) { + reversed_data = entry.data(); + } else { + reversed_data = entry.data(); + // this reversing works, but is ugly + unsigned char *data = reinterpret_cast<unsigned char *>(&reversed_data); + unsigned char tmp; + tmp = data[0]; + data[0] = data[3]; + data[3] = tmp; + tmp = data[1]; + data[1] = data[2]; + data[2] = tmp; + } + data = reinterpret_cast<const unsigned char *>(&(reversed_data)); + } else { + data = buf + base + entry.data(); + if (data + sizeof(T) * entry.length() > buf + len) { + return false; + } + } + container.resize(entry.length()); + for (size_t i = 0; i < entry.length(); ++i) { + container[i] = parse<T, alignIntel>(data + sizeof(T) * i); + } + return true; + } + + template <bool alignIntel> + void parseIFEntryHeader(const unsigned char *buf, unsigned short &tag, + unsigned short &format, unsigned &length, + unsigned &data) { + // Each directory entry is composed of: + // 2 bytes: tag number (data field) + // 2 bytes: data format + // 4 bytes: number of components + // 4 bytes: data value or offset to data value + tag = parse<uint16_t, alignIntel>(buf); + format = parse<uint16_t, alignIntel>(buf + 2); + length = parse<uint32_t, alignIntel>(buf + 4); + data = parse<uint32_t, alignIntel>(buf + 8); + } + + template <bool alignIntel> + void parseIFEntryHeader(const unsigned char *buf, IFEntry &result) { + unsigned short tag; + unsigned short format; + unsigned length; + unsigned data; + + parseIFEntryHeader<alignIntel>(buf, tag, format, length, data); + + result.tag(tag); + result.format(format); + result.length(length); + result.data(data); + } + + template <bool alignIntel> + IFEntry parseIFEntry_temp(const unsigned char *buf, const unsigned offs, + const unsigned base, const unsigned len) { + IFEntry result; + + // check if there even is enough data for IFEntry in the buffer + if (buf + offs + 12 > buf + len) { + result.tag(0xFF); + return result; + } + + parseIFEntryHeader<alignIntel>(buf + offs, result); + + // Parse value in specified format + switch (result.format()) { + case 1: + if (!extract_values<uint8_t, alignIntel>(result.val_byte(), buf, base, + len, result)) { + result.tag(0xFF); + } + break; + case 2: + // string is basically sequence of uint8_t (well, according to EXIF even + // uint7_t, but + // we don't have that), so just read it as bytes + if (!extract_values<uint8_t, alignIntel>(result.val_string(), buf, base, + len, result)) { + result.tag(0xFF); + } + // and cut zero byte at the end, since we don't want that in the + // std::string + if (result.val_string()[result.val_string().length() - 1] == '\0') { + result.val_string().resize(result.val_string().length() - 1); + } + break; + case 3: + if (!extract_values<uint16_t, alignIntel>(result.val_short(), buf, base, + len, result)) { + result.tag(0xFF); + } + break; + case 4: + if (!extract_values<uint32_t, alignIntel>(result.val_long(), buf, base, + len, result)) { + result.tag(0xFF); + } + break; + case 5: + if (!extract_values<Rational, alignIntel>(result.val_rational(), buf, + base, len, result)) { + result.tag(0xFF); + } + break; + case 7: + case 9: + case 10: + break; + default: + result.tag(0xFF); + } + return result; + } + + // helper functions for convinience + template <typename T> + T parse_value(const unsigned char *buf, bool alignIntel) { + if (alignIntel) { + return parse<T, true>(buf); + } else { + return parse<T, false>(buf); + } + } + + void parseIFEntryHeader(const unsigned char *buf, bool alignIntel, + unsigned short &tag, unsigned short &format, + unsigned &length, unsigned &data) { + if (alignIntel) { + parseIFEntryHeader<true>(buf, tag, format, length, data); + } else { + parseIFEntryHeader<false>(buf, tag, format, length, data); + } + } + + IFEntry parseIFEntry(const unsigned char *buf, const unsigned offs, + const bool alignIntel, const unsigned base, + const unsigned len) { + if (alignIntel) { + return parseIFEntry_temp<true>(buf, offs, base, len); + } else { + return parseIFEntry_temp<false>(buf, offs, base, len); + } + } +} + +// +// Locates the EXIF segment and parses it using parseFromEXIFSegment +// +int easyexif::EXIFInfo::parseFrom(const unsigned char *buf, unsigned len) { + // Sanity check: all JPEG files start with 0xFFD8. + if (!buf || len < 4) return PARSE_EXIF_ERROR_NO_JPEG; + if (buf[0] != 0xFF || buf[1] != 0xD8) return PARSE_EXIF_ERROR_NO_JPEG; + + // Sanity check: some cameras pad the JPEG image with some bytes at the end. + // Normally, we should be able to find the JPEG end marker 0xFFD9 at the end + // of the image buffer, but not always. As long as there are some bytes + // except 0xD9 at the end of the image buffer, keep decrementing len until + // an 0xFFD9 is found. If JPEG end marker 0xFFD9 is not found, + // then we can be reasonably sure that the buffer is not a JPEG. + while (len > 2) { + if (buf[len - 1] == 0xD9 && buf[len - 2] == 0xFF) + break; + len--; + } + if (len <= 2) + return PARSE_EXIF_ERROR_NO_JPEG; + + clear(); + + // Scan for EXIF header (bytes 0xFF 0xE1) and do a sanity check by + // looking for bytes "Exif\0\0". The marker length data is in Motorola + // byte order, which results in the 'false' parameter to parse16(). + // The marker has to contain at least the TIFF header, otherwise the + // EXIF data is corrupt. So the minimum length specified here has to be: + // 2 bytes: section size + // 6 bytes: "Exif\0\0" string + // 2 bytes: TIFF header (either "II" or "MM" string) + // 2 bytes: TIFF magic (short 0x2a00 in Motorola byte order) + // 4 bytes: Offset to first IFD + // ========= + // 16 bytes + unsigned offs = 0; // current offset into buffer + for (offs = 0; offs < len - 1; offs++) + if (buf[offs] == 0xFF && buf[offs + 1] == 0xE1) break; + if (offs + 4 > len) return PARSE_EXIF_ERROR_NO_EXIF; + offs += 2; + unsigned short section_length = parse_value<uint16_t>(buf + offs, false); + if (offs + section_length > len || section_length < 16) + return PARSE_EXIF_ERROR_CORRUPT; + offs += 2; + + return parseFromEXIFSegment(buf + offs, len - offs); +} + +int easyexif::EXIFInfo::parseFrom(const string &data) { + return parseFrom( + reinterpret_cast<const unsigned char *>(data.data()), static_cast<unsigned>(data.length())); +} + +// +// Main parsing function for an EXIF segment. +// +// PARAM: 'buf' start of the EXIF TIFF, which must be the bytes "Exif\0\0". +// PARAM: 'len' length of buffer +// +int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf, + unsigned len) { + bool alignIntel = true; // byte alignment (defined in EXIF header) + unsigned offs = 0; // current offset into buffer + if (!buf || len < 6) return PARSE_EXIF_ERROR_NO_EXIF; + + if (!std::equal(buf, buf + 6, "Exif\0\0")) return PARSE_EXIF_ERROR_NO_EXIF; + offs += 6; + + // Now parsing the TIFF header. The first two bytes are either "II" or + // "MM" for Intel or Motorola byte alignment. Sanity check by parsing + // the unsigned short that follows, making sure it equals 0x2a. The + // last 4 bytes are an offset into the first IFD, which are added to + // the global offset counter. For this block, we expect the following + // minimum size: + // 2 bytes: 'II' or 'MM' + // 2 bytes: 0x002a + // 4 bytes: offset to first IDF + // ----------------------------- + // 8 bytes + if (offs + 8 > len) return PARSE_EXIF_ERROR_CORRUPT; + unsigned tiff_header_start = offs; + if (buf[offs] == 'I' && buf[offs + 1] == 'I') + alignIntel = true; + else { + if (buf[offs] == 'M' && buf[offs + 1] == 'M') + alignIntel = false; + else + return PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN; + } + this->ByteAlign = alignIntel; + offs += 2; + if (0x2a != parse_value<uint16_t>(buf + offs, alignIntel)) + return PARSE_EXIF_ERROR_CORRUPT; + offs += 2; + unsigned first_ifd_offset = parse_value<uint32_t>(buf + offs, alignIntel); + offs += first_ifd_offset - 4; + if (offs >= len) return PARSE_EXIF_ERROR_CORRUPT; + + // Now parsing the first Image File Directory (IFD0, for the main image). + // An IFD consists of a variable number of 12-byte directory entries. The + // first two bytes of the IFD section contain the number of directory + // entries in the section. The last 4 bytes of the IFD contain an offset + // to the next IFD, which means this IFD must contain exactly 6 + 12 * num + // bytes of data. + if (offs + 2 > len) return PARSE_EXIF_ERROR_CORRUPT; + int num_entries = parse_value<uint16_t>(buf + offs, alignIntel); + if (offs + 6 + 12 * num_entries > len) return PARSE_EXIF_ERROR_CORRUPT; + offs += 2; + unsigned exif_sub_ifd_offset = len; + unsigned gps_sub_ifd_offset = len; + while (--num_entries >= 0) { + IFEntry result = + parseIFEntry(buf, offs, alignIntel, tiff_header_start, len); + offs += 12; + switch (result.tag()) { + case 0x102: + // Bits per sample + if (result.format() == 3 && result.val_short().size()) + this->BitsPerSample = result.val_short().front(); + break; + + case 0x10E: + // Image description + if (result.format() == 2) this->ImageDescription = result.val_string(); + break; + + case 0x10F: + // Digicam make + if (result.format() == 2) this->Make = result.val_string(); + break; + + case 0x110: + // Digicam model + if (result.format() == 2) this->Model = result.val_string(); + break; + + case 0x112: + // Orientation of image + if (result.format() == 3 && result.val_short().size()) + this->Orientation = result.val_short().front(); + break; + + case 0x131: + // Software used for image + if (result.format() == 2) this->Software = result.val_string(); + break; + + case 0x132: + // EXIF/TIFF date/time of image modification + if (result.format() == 2) this->DateTime = result.val_string(); + break; + + case 0x8298: + // Copyright information + if (result.format() == 2) this->Copyright = result.val_string(); + break; + + case 0x8825: + // GPS IFS offset + gps_sub_ifd_offset = tiff_header_start + result.data(); + break; + + case 0x8769: + // EXIF SubIFD offset + exif_sub_ifd_offset = tiff_header_start + result.data(); + break; + } + } + + // Jump to the EXIF SubIFD if it exists and parse all the information + // there. Note that it's possible that the EXIF SubIFD doesn't exist. + // The EXIF SubIFD contains most of the interesting information that a + // typical user might want. + if (exif_sub_ifd_offset + 4 <= len) { + offs = exif_sub_ifd_offset; + int num_entries = parse_value<uint16_t>(buf + offs, alignIntel); + if (offs + 6 + 12 * num_entries > len) return PARSE_EXIF_ERROR_CORRUPT; + offs += 2; + while (--num_entries >= 0) { + IFEntry result = + parseIFEntry(buf, offs, alignIntel, tiff_header_start, len); + switch (result.tag()) { + case 0x829a: + // Exposure time in seconds + if (result.format() == 5 && result.val_rational().size()) + this->ExposureTime = result.val_rational().front(); + break; + + case 0x829d: + // FNumber + if (result.format() == 5 && result.val_rational().size()) + this->FNumber = result.val_rational().front(); + break; + + case 0x8822: + // Exposure Program + if (result.format() == 3 && result.val_short().size()) + this->ExposureProgram = result.val_short().front(); + break; + + case 0x8827: + // ISO Speed Rating + if (result.format() == 3 && result.val_short().size()) + this->ISOSpeedRatings = result.val_short().front(); + break; + + case 0x9003: + // Original date and time + if (result.format() == 2) + this->DateTimeOriginal = result.val_string(); + break; + + case 0x9004: + // Digitization date and time + if (result.format() == 2) + this->DateTimeDigitized = result.val_string(); + break; + + case 0x9201: + // Shutter speed value + if (result.format() == 5 && result.val_rational().size()) + this->ShutterSpeedValue = result.val_rational().front(); + break; + + case 0x9204: + // Exposure bias value + if (result.format() == 5 && result.val_rational().size()) + this->ExposureBiasValue = result.val_rational().front(); + break; + + case 0x9206: + // Subject distance + if (result.format() == 5 && result.val_rational().size()) + this->SubjectDistance = result.val_rational().front(); + break; + + case 0x9209: + // Flash used + if (result.format() == 3 && result.val_short().size()) { + uint16_t data = result.val_short().front(); + + this->Flash = data & 1; + this->FlashReturnedLight = (data & 6) >> 1; + this->FlashMode = (data & 24) >> 3; + } + break; + + case 0x920a: + // Focal length + if (result.format() == 5 && result.val_rational().size()) + this->FocalLength = result.val_rational().front(); + break; + + case 0x9207: + // Metering mode + if (result.format() == 3 && result.val_short().size()) + this->MeteringMode = result.val_short().front(); + break; + + case 0x9291: + // Subsecond original time + if (result.format() == 2) + this->SubSecTimeOriginal = result.val_string(); + break; + + case 0xa002: + // EXIF Image width + if (result.format() == 4 && result.val_long().size()) + this->ImageWidth = result.val_long().front(); + if (result.format() == 3 && result.val_short().size()) + this->ImageWidth = result.val_short().front(); + break; + + case 0xa003: + // EXIF Image height + if (result.format() == 4 && result.val_long().size()) + this->ImageHeight = result.val_long().front(); + if (result.format() == 3 && result.val_short().size()) + this->ImageHeight = result.val_short().front(); + break; + + case 0xa20e: + // EXIF Focal plane X-resolution + if (result.format() == 5) { + this->LensInfo.FocalPlaneXResolution = result.val_rational()[0]; + } + break; + + case 0xa20f: + // EXIF Focal plane Y-resolution + if (result.format() == 5) { + this->LensInfo.FocalPlaneYResolution = result.val_rational()[0]; + } + break; + + case 0xa210: + // EXIF Focal plane resolution unit + if (result.format() == 3 && result.val_short().size()) { + this->LensInfo.FocalPlaneResolutionUnit = result.val_short().front(); + } + break; + + case 0xa405: + // Focal length in 35mm film + if (result.format() == 3 && result.val_short().size()) + this->FocalLengthIn35mm = result.val_short().front(); + break; + + case 0xa432: + // Focal length and FStop. + if (result.format() == 5) { + int sz = static_cast<unsigned>(result.val_rational().size()); + if (sz) + this->LensInfo.FocalLengthMin = result.val_rational()[0]; + if (sz > 1) + this->LensInfo.FocalLengthMax = result.val_rational()[1]; + if (sz > 2) + this->LensInfo.FStopMin = result.val_rational()[2]; + if (sz > 3) + this->LensInfo.FStopMax = result.val_rational()[3]; + } + break; + + case 0xa433: + // Lens make. + if (result.format() == 2) { + this->LensInfo.Make = result.val_string(); + } + break; + + case 0xa434: + // Lens model. + if (result.format() == 2) { + this->LensInfo.Model = result.val_string(); + } + break; + } + offs += 12; + } + } + + // Jump to the GPS SubIFD if it exists and parse all the information + // there. Note that it's possible that the GPS SubIFD doesn't exist. + if (gps_sub_ifd_offset + 4 <= len) { + offs = gps_sub_ifd_offset; + int num_entries = parse_value<uint16_t>(buf + offs, alignIntel); + if (offs + 6 + 12 * num_entries > len) return PARSE_EXIF_ERROR_CORRUPT; + offs += 2; + while (--num_entries >= 0) { + unsigned short tag, format; + unsigned length, data; + parseIFEntryHeader(buf + offs, alignIntel, tag, format, length, data); + switch (tag) { + case 1: + // GPS north or south + this->GeoLocation.LatComponents.direction = *(buf + offs + 8); + if (this->GeoLocation.LatComponents.direction == 0) { + this->GeoLocation.LatComponents.direction = '?'; + } + if ('S' == this->GeoLocation.LatComponents.direction) { + this->GeoLocation.Latitude = -this->GeoLocation.Latitude; + } + break; + + case 2: + // GPS latitude + if ((format == 5 || format == 10) && length == 3) { + this->GeoLocation.LatComponents.degrees = parse_value<Rational>( + buf + data + tiff_header_start, alignIntel); + this->GeoLocation.LatComponents.minutes = parse_value<Rational>( + buf + data + tiff_header_start + 8, alignIntel); + this->GeoLocation.LatComponents.seconds = parse_value<Rational>( + buf + data + tiff_header_start + 16, alignIntel); + this->GeoLocation.Latitude = + this->GeoLocation.LatComponents.degrees + + this->GeoLocation.LatComponents.minutes / 60 + + this->GeoLocation.LatComponents.seconds / 3600; + if ('S' == this->GeoLocation.LatComponents.direction) { + this->GeoLocation.Latitude = -this->GeoLocation.Latitude; + } + } + break; + + case 3: + // GPS east or west + this->GeoLocation.LonComponents.direction = *(buf + offs + 8); + if (this->GeoLocation.LonComponents.direction == 0) { + this->GeoLocation.LonComponents.direction = '?'; + } + if ('W' == this->GeoLocation.LonComponents.direction) { + this->GeoLocation.Longitude = -this->GeoLocation.Longitude; + } + break; + + case 4: + // GPS longitude + if ((format == 5 || format == 10) && length == 3) { + this->GeoLocation.LonComponents.degrees = parse_value<Rational>( + buf + data + tiff_header_start, alignIntel); + this->GeoLocation.LonComponents.minutes = parse_value<Rational>( + buf + data + tiff_header_start + 8, alignIntel); + this->GeoLocation.LonComponents.seconds = parse_value<Rational>( + buf + data + tiff_header_start + 16, alignIntel); + this->GeoLocation.Longitude = + this->GeoLocation.LonComponents.degrees + + this->GeoLocation.LonComponents.minutes / 60 + + this->GeoLocation.LonComponents.seconds / 3600; + if ('W' == this->GeoLocation.LonComponents.direction) + this->GeoLocation.Longitude = -this->GeoLocation.Longitude; + } + break; + + case 5: + // GPS altitude reference (below or above sea level) + this->GeoLocation.AltitudeRef = *(buf + offs + 8); + if (1 == this->GeoLocation.AltitudeRef) { + this->GeoLocation.Altitude = -this->GeoLocation.Altitude; + } + break; + + case 6: + // GPS altitude + if ((format == 5 || format == 10)) { + this->GeoLocation.Altitude = parse_value<Rational>( + buf + data + tiff_header_start, alignIntel); + if (1 == this->GeoLocation.AltitudeRef) { + this->GeoLocation.Altitude = -this->GeoLocation.Altitude; + } + } + break; + + case 11: + // GPS degree of precision (DOP) + if ((format == 5 || format == 10)) { + this->GeoLocation.DOP = parse_value<Rational>( + buf + data + tiff_header_start, alignIntel); + } + break; + } + offs += 12; + } + } + + return PARSE_EXIF_SUCCESS; +} + +void easyexif::EXIFInfo::clear() { + // Strings + ImageDescription = ""; + Make = ""; + Model = ""; + Software = ""; + DateTime = ""; + DateTimeOriginal = ""; + DateTimeDigitized = ""; + SubSecTimeOriginal = ""; + Copyright = ""; + + // Shorts / unsigned / double + ByteAlign = 0; + Orientation = 0; + + BitsPerSample = 0; + ExposureTime = 0; + FNumber = 0; + ExposureProgram = 0; + ISOSpeedRatings = 0; + ShutterSpeedValue = 0; + ExposureBiasValue = 0; + SubjectDistance = 0; + FocalLength = 0; + FocalLengthIn35mm = 0; + Flash = 0; + FlashReturnedLight = 0; + FlashMode = 0; + MeteringMode = 0; + ImageWidth = 0; + ImageHeight = 0; + + // Geolocation + GeoLocation.Latitude = 0; + GeoLocation.Longitude = 0; + GeoLocation.Altitude = 0; + GeoLocation.AltitudeRef = 0; + GeoLocation.DOP = 0; + GeoLocation.LatComponents.degrees = 0; + GeoLocation.LatComponents.minutes = 0; + GeoLocation.LatComponents.seconds = 0; + GeoLocation.LatComponents.direction = '?'; + GeoLocation.LonComponents.degrees = 0; + GeoLocation.LonComponents.minutes = 0; + GeoLocation.LonComponents.seconds = 0; + GeoLocation.LonComponents.direction = '?'; + + // LensInfo + LensInfo.FocalLengthMax = 0; + LensInfo.FocalLengthMin = 0; + LensInfo.FStopMax = 0; + LensInfo.FStopMin = 0; + LensInfo.FocalPlaneYResolution = 0; + LensInfo.FocalPlaneXResolution = 0; + LensInfo.FocalPlaneResolutionUnit = 0; + LensInfo.Make = ""; + LensInfo.Model = ""; +} \ No newline at end of file diff --git a/src/exif.h b/src/exif.h new file mode 100644 index 0000000..c4d3bb8 --- /dev/null +++ b/src/exif.h @@ -0,0 +1,174 @@ +#pragma once +#ifndef EXIF_H +#define EXIF_H + +/************************************************************************** + exif.h -- A simple ISO C++ library to parse basic EXIF + information from a JPEG file. + + Based on the description of the EXIF file format at: + -- http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html + -- http://www.media.mit.edu/pia/Research/deepview/exif.html + -- http://www.exif.org/Exif2-2.PDF + + Copyright (c) 2010-2016 Mayank Lahiri + mlahiri@gmail.com + All rights reserved. + + 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. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 THE FREEBSD PROJECT 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. +*/ +#ifndef __EXIF_H +#define __EXIF_H +#include "define_inc.h" +#include <string> + +namespace easyexif { + + // + // Class responsible for storing and parsing EXIF information from a JPEG blob + // + class EXIFInfo { + public: + // Parsing function for an entire JPEG image buffer. + // + // PARAM 'data': A pointer to a JPEG image. + // PARAM 'length': The length of the JPEG image. + // RETURN: PARSE_EXIF_SUCCESS (0) on succes with 'result' filled out + // error code otherwise, as defined by the PARSE_EXIF_ERROR_* macros + int parseFrom(const unsigned char *data, unsigned length); + int parseFrom(const std::string &data); + + // Parsing function for an EXIF segment. This is used internally by parseFrom() + // but can be called for special cases where only the EXIF section is + // available (i.e., a blob starting with the bytes "Exif\0\0"). + int parseFromEXIFSegment(const unsigned char *buf, unsigned len); + + // Set all data members to default values. + void clear(); + + // Data fields filled out by parseFrom() + char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel + std::string ImageDescription; // Image description + std::string Make; // Camera manufacturer's name + std::string Model; // Camera model + unsigned short Orientation; // Image orientation, start of data corresponds to + // 0: unspecified in EXIF data + // 1: upper left of image + // 3: lower right of image + // 6: upper right of image + // 8: lower left of image + // 9: undefined + unsigned short BitsPerSample; // Number of bits per component + std::string Software; // Software used + std::string DateTime; // File change date and time + std::string DateTimeOriginal; // Original file date and time (may not exist) + std::string DateTimeDigitized; // Digitization date and time (may not exist) + std::string SubSecTimeOriginal; // Sub-second time that original picture was taken + std::string Copyright; // File copyright information + double ExposureTime; // Exposure time in seconds + double FNumber; // F/stop + unsigned short ExposureProgram; // Exposure program + // 0: Not defined + // 1: Manual + // 2: Normal program + // 3: Aperture priority + // 4: Shutter priority + // 5: Creative program + // 6: Action program + // 7: Portrait mode + // 8: Landscape mode + unsigned short ISOSpeedRatings; // ISO speed + double ShutterSpeedValue; // Shutter speed (reciprocal of exposure time) + double ExposureBiasValue; // Exposure bias value in EV + double SubjectDistance; // Distance to focus point in meters + double FocalLength; // Focal length of lens in millimeters + unsigned short FocalLengthIn35mm; // Focal length in 35mm film + char Flash; // 0 = no flash, 1 = flash used + unsigned short FlashReturnedLight;// Flash returned light status + // 0: No strobe return detection function + // 1: Reserved + // 2: Strobe return light not detected + // 3: Strobe return light detected + unsigned short FlashMode; // Flash mode + // 0: Unknown + // 1: Compulsory flash firing + // 2: Compulsory flash suppression + // 3: Automatic mode + unsigned short MeteringMode; // Metering mode + // 1: average + // 2: center weighted average + // 3: spot + // 4: multi-spot + // 5: multi-segment + unsigned ImageWidth; // Image width reported in EXIF data + unsigned ImageHeight; // Image height reported in EXIF data + struct Geolocation_t { // GPS information embedded in file + double Latitude; // Image latitude expressed as decimal + double Longitude; // Image longitude expressed as decimal + double Altitude; // Altitude in meters, relative to sea level + char AltitudeRef; // 0 = above sea level, -1 = below sea level + double DOP; // GPS degree of precision (DOP) + struct Coord_t { + double degrees; + double minutes; + double seconds; + char direction; + } LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec + } GeoLocation; + struct LensInfo_t { // Lens information + double FStopMin; // Min aperture (f-stop) + double FStopMax; // Max aperture (f-stop) + double FocalLengthMin; // Min focal length (mm) + double FocalLengthMax; // Max focal length (mm) + double FocalPlaneXResolution; // Focal plane X-resolution + double FocalPlaneYResolution; // Focal plane Y-resolution + unsigned short FocalPlaneResolutionUnit; // Focal plane resolution unit + // 1: No absolute unit of measurement. + // 2: Inch. + // 3: Centimeter. + // 4: Millimeter. + // 5: Micrometer. + std::string Make; // Lens manufacturer + std::string Model; // Lens model + } LensInfo; + + + EXIFInfo() { + clear(); + } + }; + +} + +// Parse was successful +#define PARSE_EXIF_SUCCESS 0 +// No JPEG markers found in buffer, possibly invalid JPEG file +#define PARSE_EXIF_ERROR_NO_JPEG 1982 +// No EXIF header found in JPEG file. +#define PARSE_EXIF_ERROR_NO_EXIF 1983 +// Byte alignment specified in EXIF file was unknown (not Motorola or Intel). +#define PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN 1984 +// EXIF header was found, but data was corrupted. +#define PARSE_EXIF_ERROR_CORRUPT 1985 + +#endif + +#endif // EXIF_H \ No newline at end of file diff --git a/src/face_db.c b/src/face_db.c new file mode 100644 index 0000000..5ec49ce --- /dev/null +++ b/src/face_db.c @@ -0,0 +1,7031 @@ + +#include "face_db.h" +#include "face_req.h" +#include "cJSON.h" +// #include "radar_parser.h" + + +// int g_ftp_condition_channel=1; +// int g_httppost_condition_channel=1; +// int g_ftp_status=0; +// int g_httppost_status=0; + +//pthread_mutex_t mutex_db_sql_ffgroup; +database_info_t g_facegroup_db_info = {0}; +pthread_mutex_t mutex_db_face_Log; + +pthread_mutex_t mutex_db_face_add; +pthread_mutex_t mutex_db_face_delete; + +pthread_mutex_t mutex_db_face_import; +pthread_mutex_t mutex_db_face_insert_list; +pthread_mutex_t mutex_db_face_insert_db; + +int cgi_download_facedb_log_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount); +int cgi_download_facedb_list_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount); +int cgi_download_facedb_mapping_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int map_icount); + +static char g_MOD_TS[256] = {0}; + +//Config *pConfig; +// void getvalueForKey(char *keyValue, char *key, char *value) +// { +// char *end = NULL; +// char *p = keyValue; +// p = strstr(p, key); +// if (p == NULL) +// { +// return; +// } +// p = p + strlen(key); +// p = strstr(p, "="); +// if (p == NULL) +// { +// return; +// } +// p = p + strlen("="); +// end = strstr(p, "&"); +// if(end != NULL) +// { +// memcpy(value, p, strlen(p) - strlen(end)); +// return; +// } +// strcpy(value, p); +// return; +// } + +// char *rtrim(char *str) +// { +// if (str == NULL || *str == '\0') +// { +// return str; +// } + +// int len = strlen(str); +// char *p = str + len - 1; +// while (p >= str && isspace(*p)) +// { +// *p = '\0'; +// --p; +// } + +// return str; +// } + +void facedb_mutex_lock(sqlite3 *pdb) +{ + pthread_mutex_lock(&mutex_db_face_Log); + sqlite3_mutex_enter(sqlite3_db_mutex(pdb)); +} + +void facedb_mutex_unlock(sqlite3 *pdb) +{ + sqlite3_mutex_leave(sqlite3_db_mutex(pdb)); + pthread_mutex_unlock(&mutex_db_face_Log); +} + + +// void chk_log_data(char *odata,const char *idata) +// { +// if(strcmp(idata,"")==0) +// sprintf(odata,"%s" ,""); +// else +// sprintf(odata,"%s" ,idata); +// } + +void chk_sql_msg_tbname_face(char *ndata,char *listname) +{ + if(strcmp(listname,BKLISTNAME_FACE)==0) + { + sprintf(ndata,"%s",FACE_MSG_BLACKTABLE); + } + else if(strcmp(listname,CUSTLISTNAME_FACE)==0) + { + sprintf(ndata,"%s",FACE_MSG_CUSTOMERTABLE); + } + else if(strcmp(listname,WTLISTNAME_FACE)==0) + { + sprintf(ndata,"%s",FACE_MSG_WHITETABLE); + } + else if(strcmp(listname,LOGLISTNAME)==0) + { + sprintf(ndata,"%s",FACE_MSG_TABLE); + } + else if(strcmp(listname,MAPPINGNAME)==0) + { + sprintf(ndata,"%s",FACE_MAPPING_TABLE); + } +} + +void chk_import_dbname_face(char *ndata,char *plate_type) // strcmp plate_type with black & white list name should change this action for face +{ + if(strcmp(plate_type,ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,BKLISTNAME_FACE); + else if(strcmp(plate_type,ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,WTLISTNAME_FACE); + else if(strcmp(plate_type,WTLISTNAME_FACE)==0) + strcpy(ndata,WTLISTNAME_FACE); + else if(strcmp(plate_type,BKLISTNAME_FACE)==0) + strcpy(ndata,BKLISTNAME_FACE); + else if(strcmp(plate_type,S_ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,BKLISTNAME_FACE); + else if(strcmp(plate_type,S_ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,WTLISTNAME_FACE); +} + +void trans_download_face_type(char *ndata,char *iACT_PARAM) // strcmp iACT with black & white list name should change this action for face NOT RENAMED PLATE TO FACE ALSO +{ + if(strcmp(iACT_PARAM,BKLISTNAME_FACE)==0) + strcpy(ndata, ACT_PARAM_BKLISTNAME_FACE); + else if(strcmp(iACT_PARAM,WTLISTNAME_FACE)==0) + strcpy(ndata, ACT_PARAM_WTLISTNAME_FACE); + else if (strcmp(iACT_PARAM, S_ACT_PARAM_BKLISTNAME_FACE) == 0) + strcpy(ndata, ACT_PARAM_BKLISTNAME_FACE); + else if (strcmp(iACT_PARAM, S_ACT_PARAM_WTLISTNAME_FACE) == 0) + strcpy(ndata, ACT_PARAM_WTLISTNAME_FACE); + else if(strcmp(iACT_PARAM,ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,ACT_PARAM_BKLISTNAME); + else if(strcmp(iACT_PARAM,ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,ACT_PARAM_WTLISTNAME); + else if(strcmp(iACT_PARAM,S_ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,ACT_PARAM_BKLISTNAME); + else if(strcmp(iACT_PARAM,S_ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,ACT_PARAM_WTLISTNAME); +} +int db_get_face_version() //should change this action for face +{ + char l_sql[64] = {0}; + int l_log_db_version = 0; + int l_rc = 0; + + //if(!g_facegroup_db_info) return 0; + + sprintf(l_sql, "%s", CMD_QUERY_FACE_VERSION); + if (g_facegroup_db_info.pdb) { + facedb_mutex_lock(g_facegroup_db_info.pdb); + //db_lock(g_log_db_info->pdb); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + if (l_rc != 0) + { + printf("####### Error: Can't prepare SQL:%s\n", l_sql); + //sqlite_restore_database(g_facegroup_db_info.pdb); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + return -1; + } + + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + if (l_rc != 0) + { + printf("####### Error: Can't Step SQL:%s\n", l_sql); + //sqlite_restore_database(g_facegroup_db_info.pdb); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + return -1; + } + + l_log_db_version = db_get_column_value_int(g_facegroup_db_info.pstmt, 0); + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_log_db_info->pdb); + } + return l_log_db_version; +} + +int face_log_db_init() //(V)should change this action for face lpr version was call in detector.c +{ + printf("####### START face_log_db_init() \n"); + char *l_db_name = NULL, *l_db_dirname = NULL; + struct stat l_db_dir_st; + + int l_log_version = l_log_version; + int l_ret = 0; + char l_sql_create_cmd[1024]={0}; + //pthread_mutex_init(&mutex_db_sql_ffgroup ,NULL); + pthread_mutex_init(&mutex_db_face_add ,NULL); + pthread_mutex_init(&mutex_db_face_delete ,NULL); + pthread_mutex_init(&mutex_db_face_insert_db ,NULL); + pthread_mutex_init(&mutex_db_face_import ,NULL); + pthread_mutex_init(&mutex_db_face_insert_list ,NULL); + + + //if(!g_facegroup_db_info) + { + //g_facegroup_db_info = (database_info_t *)malloc(sizeof(database_info_t)); + //memset(g_facegroup_db_info,0x00,sizeof(database_info_t)); + /* + if(!g_facegroup_db_info) + { + //printf("Error: License Plate Db Init Fail...\n"); + + return -1; + }*/ + g_facegroup_db_info.pdb = NULL; + } + + l_db_name = strdup(DB_FACEGROUP_MSG_PATH); + + l_db_dirname = dirname(l_db_name); + + if(stat(l_db_dirname, &l_db_dir_st)) + { + //printf("Create License Plate Db directoy: %s\n", l_db_dirname); + mkdir(l_db_dirname, S_IRWXU | S_IRWXG | S_IRWXO); + } + + if (l_db_name) { + free(l_db_name); + l_db_name = NULL; + } + + snprintf(g_facegroup_db_info.db_name, sizeof(g_facegroup_db_info.db_name)-1, "%s", DB_FACEGROUP_MSG_PATH); + + if(g_facegroup_db_info.pdb) sqlite3_close(g_facegroup_db_info.pdb); + + l_ret = sqlite3_open_v2(g_facegroup_db_info.db_name, &g_facegroup_db_info.pdb, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL); + + //printf("\nxXX l_ret:%d", l_ret); + + if (l_ret != SQLITE_OK) + { + printf("####### Error: Open License Plate Db %s Fail...\n", g_facegroup_db_info.db_name); + + return -1; + }else{ + printf("####### Open Face Db %s Success...\n", g_facegroup_db_info.db_name); + + } + + + if(db_check_table_exist(g_facegroup_db_info.pdb, TABLE_FACE_VERSION) == 0) + { + db_exec_sql(g_facegroup_db_info.pdb, CMD_DROP_FACE_MSG_TABLE); + db_exec_sql(g_facegroup_db_info.pdb, CMD_CREATE_FACE_VERSION_TABLE); + + struct timeval l_now_time = {0,0}; + struct tm *l_tm_ptr = NULL; + char l_date_str[64] = {0}; + char l_sql[256] = {0}; + + gettimeofday(&l_now_time, NULL); + l_tm_ptr = localtime(&l_now_time.tv_sec); + strftime(l_date_str, sizeof(l_date_str)-1, "%Y/%m/%d %H:%M:%S", l_tm_ptr); + + sprintf(l_sql, FACE_INSERT_VERSION, 0, l_date_str, "Create License Plate Db Beta Version"); + db_exec_sql(g_facegroup_db_info.pdb, l_sql); + } + + //Create LPR Log Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_FACE_TABLE,FACE_MSG_TABLE); + db_exec_sql(g_facegroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR Log INDEX Table + db_exec_sql(g_facegroup_db_info.pdb, CMD_CREATE_FACE_INDEX); + + //Create LPR BLACK Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_FACELIST_TABLE,FACE_MSG_BLACKTABLE); + db_exec_sql(g_facegroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR WHITE Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_FACELIST_TABLE,FACE_MSG_WHITETABLE); + db_exec_sql(g_facegroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR CUSTOMER Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_FACELIST_TABLE,FACE_MSG_CUSTOMERTABLE); + db_exec_sql(g_facegroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR MAPPING TABLE + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_FACE_MAPPING_TABLE,FACE_MAPPING_TABLE); + db_exec_sql(g_facegroup_db_info.pdb, l_sql_create_cmd); + + //printf("\n------CMD_CREATE_LEVENSHTEIN\n"); + sqlite3_extension_init(g_facegroup_db_info.pdb); + //printf("\n------CMD_CREATE_LEVENSHTEIN---end\n"); + //set sqlite environment parameters + + db_exec_sql(g_facegroup_db_info.pdb,"PRAGMA encoding=\"UTF-8\";"); + db_exec_sql(g_facegroup_db_info.pdb,"PRAGMA journal_mode=DELETE;"); + db_exec_sql(g_facegroup_db_info.pdb,"PRAGMA synchronous = FULL;"); + db_exec_sql(g_facegroup_db_info.pdb,"PRAGMA page_size=4096;"); + + return l_ret; +} + +void get_face_db_import() //(^V)should change this action for face. lpr version was called in nweb.c +{ + //int l_result = 0; + int l_db_length = 0; + + if (g_facegroup_db_info.pdb) + { + /* + if (strncmp(l_lpr_cgi_param, CUSTLISTNAME_FACE, strlen(CUSTLISTNAME_FACE)) == 0) + { + cgi_get_db_face_log(socket_in, FACE_MSG_CUSTOMERTABLE, CUSTLISTNAME_FACE, COUNT_CUSTOMER); + } + else if (strncmp(l_lpr_cgi_param, BKLISTNAME_FACE, strlen(BKLISTNAME_FACE)) == 0) + { + cgi_get_db_face_log(socket_in, FACE_MSG_BLACKTABLE, BKLISTNAME_FACE, COUNT_BLACK); + } + else if (strncmp(l_lpr_cgi_param, WTLISTNAME_FACE, strlen(WTLISTNAME_FACE)) == 0) + { + cgi_get_db_face_log(socket_in, FACE_MSG_WHITETABLE, WTLISTNAME_FACE, COUNT_WHITE); + } + else if (strncmp(l_lpr_cgi_param, LOGLISTNAME, strlen(LOGLISTNAME)) == 0) + { + cgi_get_db_face_log(socket_in, FACE_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + }*/ + + //if (strcmp(list_name, LOGLISTNAME) == 0 || strcmp(list_name, CUSTLISTNAME_FACE) == 0) + //snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, sum_count); + //else + //snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name, sum_count); + + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info, 0, sizeof(facegroup_db_tb)); + char l_sql[256] = { 0 }; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", FACE_MSG_BLACKTABLE, COUNT_BLACK-100); + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE); + + { + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 6 l_rc:%d", l_rc); + } + if (l_rc != 0) + { + //printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + l_idx = -1; + } + else + { + if (l_lpr_record_cnts >= COUNT_BLACK - 100) + l_db_length = COUNT_BLACK - 100; + else + l_db_length = l_lpr_record_cnts; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(BKLISTNAME_FACE)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + //cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + // //cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "FR_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "FR_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "FR_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "FR_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "FR_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "FR_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "FR_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "FR_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "FR_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "FR_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "FR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "FR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "FR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "FR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "FR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "FR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "FR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToObject(child1, "FR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "FR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "FR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "FR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "FR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "FR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "FR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToObject(child1, "ff_face_name", cJSON_CreateString(l_db_lpr_tb_info.face_name)); + cJSON_AddItemToObject(child1, "ff_user_name", cJSON_CreateString(l_db_lpr_tb_info.user_name)); + cJSON_AddItemToObject(child1, "ff_face_tracking_uuid", cJSON_CreateString(l_db_lpr_tb_info.face_uuid)); + cJSON_AddItemToObject(child1, "ff_identification_score", cJSON_CreateString(l_db_lpr_tb_info.identification_score)); + cJSON_AddItemToObject(child1, "ff_face_trackingID", cJSON_CreateString(l_db_lpr_tb_info.face_trackingID)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + + printf("\n[get_face_db_import] 123 JsonString:%s\n", JsonString); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + //l_result = l_idx + 1; + } + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } +} + +void sqlite_face_db_close() //(V)should change this action for face most part might be in sqlite3 ? +{ + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + //PRINT_INFO_LOG("####### License Plate DB Close\n"); + facedb_mutex_lock(g_facegroup_db_info.pdb); + //db_lock(g_facegroup_db_info.pdb); + sqlite3_close(g_facegroup_db_info.pdb); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_log_db_info->pdb); + } + } +} + +void delete_jpg_in_seven_days_face() //(^V)should change this action for face will face save jpg for 7 days? +{ + + //clock_t t; + //t = clock(); + + /* + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + strcat(cmd, "ls image*.* | xargs -n50000 rm"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + }*/ + + cgi_get_db_face_log_delete_jpg(FACE_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + //printf("\nTTTTTTESTTTTTTTTTT:%s\n",g_MOD_TS); + if (strlen(g_MOD_TS) >= 19) + { +#if 1 + g_MOD_TS[10] = '-'; + g_MOD_TS[13] = '-'; + g_MOD_TS[16] = '-'; + const char *del = "-"; + char buf_MOD_TS[10][STRSPLIT_SIZE] = { 0 }; + int num_MOD_TS = 0; + + num_MOD_TS = StrSplit(g_MOD_TS, buf_MOD_TS, del); + //printf("\n------UU:17\n"); + //printf("\nnum_MOD_TS: %d\n", num_MOD_TS); + + + + if (num_MOD_TS == 6) + { + int end_year = atoi(buf_MOD_TS[0]); + int end_month = atoi(buf_MOD_TS[1]); + int end_day = atoi(buf_MOD_TS[2]); + //int end_hour = atoi(buf_MOD_TS[3]); + //int end_min = atoi(buf_MOD_TS[4]); + //int end_sec = atoi(buf_MOD_TS[5]); + + for (int the_past_i_day = 1; the_past_i_day <= 7; the_past_i_day++) { + int temp_day = 0; + int temp_month = 0; + if (end_day - the_past_i_day >= 1) { + temp_day = end_day - the_past_i_day; + temp_month = end_month; + } + else { + temp_month = end_month - 1 >= 1 ? end_month - 1 : 12; + if (temp_month == 1 || temp_month == 3 || temp_month == 5 || temp_month == 7 || temp_month == 8 || temp_month == 10 || temp_month == 12) { + temp_day = 31 - the_past_i_day + 1; + } + else if (temp_month == 4 || temp_month == 6 || temp_month == 9 || temp_month == 11) { + temp_day = 30 - the_past_i_day + 1; + } + else {//temp_month == 2 + temp_day = 28 - the_past_i_day + 1; + if (end_year % 4 == 0 && end_year % 100 != 0 && end_year % 400 == 0) { + temp_day = 29 - the_past_i_day + 1; + } + } + } + + //pthread_mutex_lock(&mutex_send_jpeg); + + for (int the_index_hour = 0; the_index_hour <= 23; the_index_hour++) { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_*.jpg", end_year, temp_month, temp_day,the_index_hour); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /tmp/face/%d_%d_%d_%d_*.jpg", end_year, temp_month, temp_day, the_index_hour); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + //pthread_mutex_unlock(&mutex_send_jpeg); + + usSleep(100000); + } + } + +#endif + } + memset(g_MOD_TS, 0, 256); + //t = clock() - t; + //printf("\nIt took me %d clicks (%f seconds).\n", t, ((float)t) / CLOCKS_PER_SEC); +} + +static int check_finish_delete_jpg = 0; +/* +void *delete_jpg_face(void * ptr) //should change this action for face +{ + + pthread_detach(pthread_self()); + printf("\n[delete_jpg_face]pthread create\n"); + if (check_finish_delete_jpg == 0) { + check_finish_delete_jpg = 1; + //clock_t t; + //t = clock(); + + + // { + // FILE * pPipe; + // char cmd[256] = { 0 }; + // memset(cmd, 0x00, sizeof(cmd)); + // strcat(cmd, "ls image*.* | xargs -n50000 rm"); + // pPipe = vpopen(cmd, "r"); + // if (pPipe != NULL) + // vpclose(pPipe); + // } + + // cgi_get_db_face_log_delete_jpg(FACE_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + //printf("\nTTTTTTESTTTTTTTTTT:%s\n",g_MOD_TS); + if (strlen(g_MOD_TS) >= 19) + { + + printf("\n-------[delete_jpg]-----\n"); + printf("\n%s\n", g_MOD_TS); + printf("\n---------end[delete_jpg]------\n"); + +#if 1 + g_MOD_TS[10] = '-'; + g_MOD_TS[13] = '-'; + g_MOD_TS[16] = '-'; + const char *del = "-"; + char buf_MOD_TS[10][STRSPLIT_SIZE] = { 0 }; + int num_MOD_TS = 0; + + num_MOD_TS = StrSplit(g_MOD_TS, buf_MOD_TS, del); + //printf("\nnum_MOD_TS: %d\n", num_MOD_TS); + if (num_MOD_TS == 6) + { + + //delete time length [start,end] + + //int start_year = atoi(buf_MOD_TS[0]); + //int start_month = atoi(buf_MOD_TS[1]); + + int end_year = atoi(buf_MOD_TS[0]); + int end_month = atoi(buf_MOD_TS[1]); + int end_day = atoi(buf_MOD_TS[2]); + int end_hour = atoi(buf_MOD_TS[3]); + int end_min = atoi(buf_MOD_TS[4]); + //int end_sec = atoi(buf_MOD_TS[5]); + +#if 0 + printf("\n%d_%d_%d_%d_%d_%d\n", end_year, end_month, end_day, end_hour, end_min, end_sec); + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/face/%d_*.jpg", end_year - 1); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/face/%d_%d_*.jpg", end_year, end_month - 1 >= 1 ? end_month - 1 : 12); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } +#endif + + //pthread_mutex_lock(&mutex_send_jpeg); + + for (int i = 1; i <= 59; i++) { + int temp_min = end_min - i; + if (temp_min >= 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/face/%d_%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, end_hour, temp_min); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + usSleep(10); + } + + for (int i = 1; i <= 23; i++) { + int temp_hour = end_hour - i; + if (temp_hour >= 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/face/%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, temp_hour); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + usSleep(10); + } + + //pthread_mutex_unlock(&mutex_send_jpeg); + } + + usSleep(100000); +#endif + } + memset(g_MOD_TS, 0, 256); + + //t = clock() - t; + //printf("\nIt took me %d clicks (%f seconds).\n", t, ((float)t) / CLOCKS_PER_SEC); + check_finish_delete_jpg = 0; + } + pthread_exit(NULL); +} +*/ + +void *delete_jpg_face(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("delete_jpg_face"); + //printf("\n[delete_jpg_face] pthread create\n"); + + if (check_finish_delete_jpg == 0) { + check_finish_delete_jpg = 1; + //clock_t t; + //t = clock(); + + /* + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + strcat(cmd, "ls image*.* | xargs -n50000 rm"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + }*/ + cgi_get_db_face_log_delete_jpg(FACE_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + //printf("\nTTTTTTESTTTTTTTTTT:%s\n",g_MOD_TS); + if (strlen(g_MOD_TS) >= 19) + { + /* + printf("\n-------[delete_jpg]-----\n"); + printf("\n%s\n", g_MOD_TS); + printf("\n---------end[delete_jpg]------\n"); + */ +#if 1 + g_MOD_TS[10] = '-'; + g_MOD_TS[13] = '-'; + g_MOD_TS[16] = '-'; + const char *del = "-"; + char buf_MOD_TS[10][STRSPLIT_SIZE] = { 0 }; + int num_MOD_TS = 0; + + num_MOD_TS = StrSplit(g_MOD_TS, buf_MOD_TS, del); + //printf("\n------UU:18\n"); + //printf("\nnum_MOD_TS: %d\n", num_MOD_TS); + if (num_MOD_TS == 6) + { + + //delete time length [start,end] + + //int start_year = atoi(buf_MOD_TS[0]); + //int start_month = atoi(buf_MOD_TS[1]); + + int end_year = atoi(buf_MOD_TS[0]); + int end_month = atoi(buf_MOD_TS[1]); + int end_day = atoi(buf_MOD_TS[2]); + int end_hour = atoi(buf_MOD_TS[3]); + int end_min = atoi(buf_MOD_TS[4]); + //int end_sec = atoi(buf_MOD_TS[5]); + +#if 0 + printf("\n%d_%d_%d_%d_%d_%d\n", end_year, end_month, end_day, end_hour, end_min, end_sec); + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_*.jpg", end_year - 1); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_*.jpg", end_year, end_month - 1 >= 1 ? end_month - 1 : 12); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } +#endif + + //pthread_mutex_lock(&mutex_send_jpeg); + + for (int i = 1; i <= 59; i++) { + int temp_min = end_min - i; + if (temp_min >= 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, end_hour, temp_min); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /tmp/face/%d_%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, end_hour, temp_min); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + usSleep(10); + } + + for (int i = 1; i <= 23; i++) { + int temp_hour = end_hour - i; + if (temp_hour >= 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, temp_hour); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10s rm -rf /tmp/face/%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, temp_hour); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + usSleep(10); + } + + //pthread_mutex_unlock(&mutex_send_jpeg); + } + + usSleep(100000); +#endif + } + memset(g_MOD_TS, 0, 256); + + //t = clock() - t; + //printf("\nIt took me %d clicks (%f seconds).\n", t, ((float)t) / CLOCKS_PER_SEC); + check_finish_delete_jpg = 0; + } + + pthread_exit(NULL); +} + +//no use +void* callback_insert_face_msg_to_db(void *data) //should change this action for face +{ + pthread_detach(pthread_self()); + // printf("\n[callback_insert_face_msg_to_db]pthread create\n"); + + int l_log_record_cnts = 0; + facegroup_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + int l_db_max_len=0; + + if(!data) + { + + } + else { + lpr_insert_data = (facegroup_db_tb *)data; + //printf("\n[callback_insert_face_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + //printf("\nXXX lpr_insert_data->sql_tbname:%s\n", lpr_insert_data->sql_tbname); + //if (g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + //db_lock(g_facegroup_db_info.pdb); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, CMD_QUERY_LOG_DESC); + + l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, lpr_insert_data->sql_tbname);//FACE_MSG_TABLE); + if (strcmp(lpr_insert_data->sql_tbname, FACE_MSG_CUSTOMERTABLE) == 0) + { + l_db_max_len = MAX_FACE_CUSTOMER_COUNT; + sprintf(lpr_insert_data->sql_count, "%d", COUNT_CUSTOMER); + } + else + { + l_db_max_len = MAX_FACE_COUNT; + sprintf(lpr_insert_data->sql_count, "%d", COUNT_LOG); + } + //int l_limitcount=(atoi(lpr_insert_data->sql_count)+DELETECOUNT); + + if (l_log_record_cnts >= l_db_max_len) + { +//#ifdef FACE_AMBA_DEBUG + printf("############## Log Records >= %d, Delete Oldest Log\n", atoi(lpr_insert_data->sql_count)); + //printf("123############## Log Records >= %d, Delete Oldest Log\n", atoi(lpr_insert_data->sql_count)); +//#endif + { + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, "DELETE FROM '%s' WHERE ff_index IN " + "(SELECT ff_index FROM '%s' WHERE Length(ff_mod_ts)>=1 ORDER BY ff_index LIMIT %d)", lpr_insert_data->sql_tbname, lpr_insert_data->sql_tbname, l_log_record_cnts - atoi(lpr_insert_data->sql_count)); + } +//#ifdef FACE_AMBA_DEBUG + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); +//#endif + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + +// l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + +// //facedb_mutex_unlock(g_facegroup_db_info.pdb); +// if (l_sql_ret) +// { +// #ifdef FACE_AMBA_DEBUG +// printf("Error:l_sql_ret:%d %s\n", l_sql_ret, l_sql_cmd); +// #endif +// } + /* + printf("\n-------[lpr_insert_data->MOD_TS]-------\n"); + printf("\n%s\n", lpr_insert_data->MOD_TS); + printf("\n-------end[lpr_insert_data->MOD_TS]-------\n");*/ + + pthread_t delete_jpg_thread_id; + if (pthread_create(&delete_jpg_thread_id, 0, delete_jpg_face, NULL)) //joy nR jpg + { + printf("create delete_jpg_face thread faile \n"); + } + } + + // printf("\n[callback_insert_face_msg_to_db] 0"); + if (strcmp(lpr_insert_data->face_uuid, "") != 0) + { + // printf("\n[callback_insert_face_msg_to_db] 1\n"); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_FACE_DATA_CMD + , lpr_insert_data->sql_tbname + , lpr_insert_data->TS + , lpr_insert_data->MOD_TS + , lpr_insert_data->CAR_ID + , lpr_insert_data->LPR + , lpr_insert_data->RTIME + , lpr_insert_data->ACTION + , lpr_insert_data->sec_color_id + , lpr_insert_data->ACT_PARAM + , lpr_insert_data->THRESHOLD + , lpr_insert_data->ROI_X + , lpr_insert_data->ROI_Y + , lpr_insert_data->ROI_W + , lpr_insert_data->ROI_H + , lpr_insert_data->LP_X + , lpr_insert_data->LP_Y + , lpr_insert_data->LP_W + , lpr_insert_data->LP_H + , lpr_insert_data->LP_BMP + , lpr_insert_data->ROI_BMP + , lpr_insert_data->COUNTRY + ,"","","","","","","", lpr_insert_data->IN_OTHER,"" + , lpr_insert_data->face_name + , lpr_insert_data->user_name + , lpr_insert_data->face_uuid + , lpr_insert_data->identification_score + , lpr_insert_data->face_trackingID + ); +#ifdef FACE_AMBA_DEBUG + printf("[callback_insert_face_msg_to_db] Insert '%s' LIST Log: %s\n", lpr_insert_data->sql_tbname , l_sql_cmd); +#endif + // ,lpr_insert_data->IN_USER + // ,lpr_insert_data->IN_PHONE + // ,lpr_insert_data->IN_ADDRESS + // ,lpr_insert_data->IN_PAYSTATUS + // ,lpr_insert_data->IN_EXIST + // ,lpr_insert_data->IN_SCHEDULE_START + // ,lpr_insert_data->IN_SCHEDULE_END + // ,lpr_insert_data->IN_OTHER + // ,lpr_insert_data->IN_DETECT_ENDTIME); + + // printf("Insert LPR Log: %s\n", l_sql_cmd); + + //facedb_mutex_unlock(g_facegroup_db_info.pdb); + //printf("\n[callback_insert_face_msg_to_db] 2 l_sql_ret:%d", l_sql_ret); + + //for (int try_times = 0; try_times < 5; try_times++) + { + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + // printf("do sql ret = 0 \n"); + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + // printf("do sql ret = %d \n", l_sql_ret); + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + // if (l_sql_ret) { + // printf("Error:2_sql_ret:%d %s\n", l_sql_ret, l_sql_cmd); + // } + // else { + // break; + // } + // usSleep(10000); + } + } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + //db_unlock(g_facegroup_db_info.pdb); + + } + } + //printf("2callback_insert_lpr_msg_to_db\n"); + //free(lpr_insert_data); + //printf("\n[callback_insert_face_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + } + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + //printf("\n[callback_insert_face_msg_to_db]pthread exit\n"); + pthread_exit(NULL); +} +void* callback_insert_facelist_msg_to_db(void *data) //should change this action for face +{ + pthread_detach(pthread_self()); + + char l_db_log_tbname[20]={0}; + facegroup_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + + } + else { + lpr_insert_data = (facegroup_db_tb *)data; + //printf("\n[callback_insert_facelist_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + //if(g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type and set table name + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_insert_data->tb_type); + + int l_lpr_record_cnts = 0; + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + if (l_lpr_record_cnts <= COUNT_BLACK - 100 && l_lpr_record_cnts <= COUNT_WHITE - 100) + { + //printf("do insert \n"); + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_FACELIST_DATA_CMD + , l_db_log_tbname + , lpr_insert_data->TS + , lpr_insert_data->MOD_TS + , lpr_insert_data->CAR_ID + , lpr_insert_data->LPR + , lpr_insert_data->RTIME + , lpr_insert_data->ACTION + , lpr_insert_data->sec_color_id + , lpr_insert_data->ACT_PARAM + , lpr_insert_data->THRESHOLD + , lpr_insert_data->ROI_X + , lpr_insert_data->ROI_Y + , lpr_insert_data->ROI_W + , lpr_insert_data->ROI_H + , lpr_insert_data->LP_X + , lpr_insert_data->LP_Y + , lpr_insert_data->LP_W + , lpr_insert_data->LP_H + , lpr_insert_data->LP_BMP //IMG name + , lpr_insert_data->ROI_BMP + , lpr_insert_data->COUNTRY + , lpr_insert_data->IN_USER //Last name + , lpr_insert_data->IN_PHONE + , lpr_insert_data->IN_ADDRESS + , lpr_insert_data->IN_PAYSTATUS + , lpr_insert_data->IN_EXIST + , lpr_insert_data->IN_SCHEDULE_START + , lpr_insert_data->IN_SCHEDULE_END + , lpr_insert_data->IN_OTHER //Other + , lpr_insert_data->IN_DETECT_ENDTIME + , lpr_insert_data->face_name //UUID + , lpr_insert_data->user_name //First name + , lpr_insert_data->face_uuid + , lpr_insert_data->identification_score + , lpr_insert_data->face_trackingID + , lpr_insert_data->face_count); +#ifdef FACE_AMBA_DEBUG + printf("[callback_insert_facelist_msg_to_db] Insert '%s' LIST Log: %s\n", l_db_log_tbname , l_sql_cmd); +#endif + //printf("insert sql cmd: \n%s", l_sql_cmd); + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if (l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_insert_data) { + // free(lpr_insert_data); + // lpr_insert_data = NULL; + // }*/ + // //sqlite_restore_database(g_facegroup_db_info.pdb); + // } + } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + + } + } + //printf("1callback_insert_lprlist_msg_to_db\n"); + + //printf("\n[callback_insert_facelist_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + //printf("\n[callback_insert_facelist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} + +void* callback_insert_from_loglist_to_db(void *data) //insert data from log_list to other_list +{ + pthread_detach(pthread_self()); + + char l_insert_table_name[20] = { 0 }; + facegroup_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = { 0 }; + int l_sql_ret = 0; + + if (!data) + { + + } + else { + lpr_insert_data = (facegroup_db_tb *)data; + printf("\n[callback_insert_facelist_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_insert_table_name, lpr_insert_data->tb_type); + + //printf("do insert from tb to tb\n"); + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_FACE_LOG_TO_TABLE_CMD + , l_insert_table_name + , l_insert_table_name + , lpr_insert_data->face_name + , lpr_insert_data->face_name + , lpr_insert_data->ff_mod_ts); + +#ifdef FACE_AMBA_DEBUG + printf("[callback_insert_facelist_msg_to_db] Insert '%s' LIST Log: %s\n", l_db_log_tbname, l_sql_cmd); +#endif + //printf("insert sql cmd: \n%s", l_sql_cmd); + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ +#if 1 //TEMP + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); +#endif + + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + + } + + //printf("1callback_insert_lprlist_msg_to_db\n"); + + //printf("\n[callback_insert_facelist_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + //printf("\n[callback_insert_facelist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} + +void* callback_insert_to_one_tb(void *data) //insert data from log_list to other_list +{ + pthread_detach(pthread_self()); + + char l_insert_table_name[20] = { 0 }; + facegroup_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = { 0 }; + int l_sql_ret = 0; + + if (!data) + { + + } + else { + lpr_insert_data = (facegroup_db_tb *)data; + printf("\n[callback_insert_to_one_tb]lpr_insert_data new address: %p\n", lpr_insert_data); + + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + //chk_sql_msg_tbname_face(l_insert_table_name, lpr_insert_data->tb_type); + + //printf("do insert from tb to tb\n"); + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_FACE_LOG_TO_TABLE_CMD_B + , "face_db_black_tb" + , "face_db_black_tb" + , lpr_insert_data->face_tracking_uuid + , "face_db_white_tb" + , lpr_insert_data->face_tracking_uuid + , lpr_insert_data->face_tracking_uuid); + +#ifdef FACE_AMBA_DEBUG + printf("[callback_insert_facelist_msg_to_db] Insert '%s' LIST Log: %s\n", l_db_log_tbname, l_sql_cmd); +#endif + //printf("insert sql cmd: \n%s", l_sql_cmd); + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ +#if 1 //TEMP + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); +#endif + + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + + } + + //printf("1callback_insert_lprlist_msg_to_db\n"); + + //printf("\n[callback_insert_facelist_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + //printf("\n[callback_insert_facelist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} + + +void* callback_insert_face_map_msg_to_db(void *data) //should change this action for face is there a face map msg? +{ + pthread_detach(pthread_self()); + + //printf("\n[callback_insert_face_map_msg_to_db]pthread create\n"); + + //int l_log_record_cnts = 0; + char l_db_log_tbname[20]={0}; + facegroup_mapping_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + + } + else { + lpr_insert_data = (facegroup_mapping_db_tb *)data; + //printf("\n[callback_insert_face_map_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + //if(g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_insert_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_FACE_MAPPING_CMD + , l_db_log_tbname + , lpr_insert_data->LPR_DETECT + , lpr_insert_data->LPR); +#ifdef FACE_AMBA_DEBUG + printf("Insert LPR MAP Log: %s\n", l_sql_cmd); +#endif + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if (l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_insert_data) { + // free(lpr_insert_data); + // lpr_insert_data = NULL; + // }*/ + + // //sqlite_restore_database(g_facegroup_db_info.pdb); + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + + } + } + //printf("1callback_insert_lprlist_msg_to_db\n"); + //printf("\n[callback_insert_face_map_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + //printf("\n[callback_insert_face_map_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_update_detectfacelist_msg_to_db(void *data) //should change this action for face +{ + pthread_detach(pthread_self()); + + //printf("\n[callback_update_detectfacelist_msg_to_db]pthread create\n"); + + //int l_log_record_cnts = 0; + char l_db_log_tbname[20]={0}; + facegroup_db_tb *lpr_update_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret=0; + + if(!data) + { + + } + else { + lpr_update_data = (facegroup_db_tb *)data; + //printf("\n[callback_update_detectfacelist_msg_to_db]lpr_update_data new address\n"); + + //if(g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_update_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, UPDATE_DETECT_FACELIST_CMD + , l_db_log_tbname + , lpr_update_data->TS + , lpr_update_data->MOD_TS + , lpr_update_data->CAR_ID + , lpr_update_data->RTIME + , lpr_update_data->ACTION + , lpr_update_data->sec_color_id + , lpr_update_data->ACT_PARAM + , lpr_update_data->THRESHOLD + , lpr_update_data->ROI_X + , lpr_update_data->ROI_Y + , lpr_update_data->ROI_W + , lpr_update_data->ROI_H + , lpr_update_data->LP_X + , lpr_update_data->LP_Y + , lpr_update_data->LP_W + , lpr_update_data->LP_H + , lpr_update_data->LP_BMP + , lpr_update_data->ROI_BMP + , lpr_update_data->COUNTRY + , lpr_update_data->LPR); + + // printf("Update Detection LPR List Log: %s\n", l_sql_cmd); + // printf("Update Detection LPR List Log: %s\n", l_sql_cmd); + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if (l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + + // if (lpr_update_data) { + // free(lpr_update_data); + // lpr_update_data = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + + } + } + //intf("3detectlprlist_msg_to_db\n"); + //printf("\n[callback_update_detectfacelist_msg_to_db]lpr_update_data free address\n"); + if (lpr_update_data) { + free(lpr_update_data); + lpr_update_data = NULL; + } + + //printf("\n[callback_update_detectfacelist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_update_facelist_msg_to_db(void *data) //should change this action for face +{ + pthread_detach(pthread_self()); + printf("\n[callback_update_facelist_msg_to_db]pthread create\n"); + + //int l_log_record_cnts = 0; + char l_db_log_tbname[20]={0}; + facegroup_listInfo_tb *lpr_update_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data){} + else { + + printf("IN updata lpr list\n"); + + lpr_update_lprlist_data = (facegroup_listInfo_tb *)data; + //printf("\n[callback_update_facelist_msg_to_db]lpr_update_lprlist_data new address: %p\n", lpr_update_lprlist_data); + + //if(g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_update_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, UPDATE_FACELIST_CMD + , l_db_log_tbname + , lpr_update_lprlist_data->IN_FIRST_NAME + , lpr_update_lprlist_data->ACT_PARAM + //, lpr_update_lprlist_data->IN_FACE_NAME + , lpr_update_lprlist_data->IN_USER + , lpr_update_lprlist_data->IN_PHONE + , lpr_update_lprlist_data->IN_ADDRESS + , lpr_update_lprlist_data->IN_PAYSTATUS + , lpr_update_lprlist_data->IN_EXIST + , lpr_update_lprlist_data->IN_SCHEDULE_START + , lpr_update_lprlist_data->IN_SCHEDULE_END + , lpr_update_lprlist_data->IN_OTHER + , lpr_update_lprlist_data->IN_DETECT_ENDTIME + , lpr_update_lprlist_data->IN_FACE_NAME); +#ifdef FACE_AMBA_DEBUG + printf("Update LPR LIST Log: %s\n", l_sql_cmd); +#endif + //FACE_MSG_BLACKTABLE + printf("Update LPR LIST Log: %s\n", l_sql_cmd); + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + // if (l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_update_lprlist_data) { + // free(lpr_update_lprlist_data); + // lpr_update_lprlist_data = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } + + //printf("\n[callback_update_facelist_msg_to_db]lpr_update_lprlist_data free address: %p\n", lpr_update_lprlist_data); + if (lpr_update_lprlist_data) { + free(lpr_update_lprlist_data); + lpr_update_lprlist_data = NULL; + } + //printf("OUT updata lpr list\n"); + //printf("\n[callback_update_facelist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_update_face_map_msg_to_db(void *data) //should change this action for face +{ + pthread_detach(pthread_self()); + + //printf("\n[callback_update_face_map_msg_to_db]pthread create\n"); + + //int l_map_record_cnts = 0; + char l_db_map_tbname[15]={0}; + facegroup_mapping_db_tb *lpr_update_lpr_map = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + + } + else { + lpr_update_lpr_map = (facegroup_mapping_db_tb *)data; + //printf("\n[callback_update_face_map_msg_to_db]lpr_update_lpr_map new address: %p\n", lpr_update_lpr_map); + + //if(g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_map_tbname, lpr_update_lpr_map->tb_type); + + + //l_map_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_map_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, UPDATE_FACE_MAPPING_CMD + , l_db_map_tbname + , lpr_update_lpr_map->LPR_DETECT + , lpr_update_lpr_map->LPR + , lpr_update_lpr_map->oLPR); +#ifdef FACE_AMBA_DEBUG + printf("Update LPR LIST Log: %s\n", l_sql_cmd); +#endif + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + // if (l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_update_lpr_map) { + // free(lpr_update_lpr_map); + // lpr_update_lpr_map = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } + //printf("\n[callback_update_face_map_msg_to_db]lpr_update_lpr_map free address: %p\n", lpr_update_lpr_map); + if (lpr_update_lpr_map) { + free(lpr_update_lpr_map); + lpr_update_lpr_map = NULL; + } + + //printf("\n[callback_update_face_map_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +//DELETE FROM %s WHERE ff_index=(SELECT ff_index FROM %s WHERE ff_lpr='%s'); +//void callback_del_facetab_msg_to_db(void *data) +int callback_del_facetab_msg_to_db(void *data,int nIndex,int sumIndex) //should change this action for face +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[20]={0}; + facegroup_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return 0; + } + + lpr_del_lprlist_data = (facegroup_db_tb *)data; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname,lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, DELETE_FACELIST_CMD + ,l_db_log_tbname + ,l_db_log_tbname + ,lpr_del_lprlist_data->face_name); + + printf("[Black List]delete cmd: %s \n", l_sql_cmd); +#ifdef FACE_AMBA_DEBUG + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); +#endif + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + // l_sql_ret=db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if(l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_del_lprlist_data) { + // free(lpr_del_lprlist_data); + // lpr_del_lprlist_data = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } + + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if((l_sql_ret==0) &&(nIndex==sumIndex-1)) + return 1; + else + return 0; + +} + +//DELETE FROM %s WHERE ff_index=(SELECT ff_index FROM %s WHERE ff_lpr='%s'); +//void callback_del_facetab_msg_to_db(void *data) +int callback_del_facelist_msg_to_db(void *data,int nIndex,int sumIndex) //should change this action for face +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[20]={0}; + facegroup_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return 0; + } + + lpr_del_lprlist_data = (facegroup_db_tb *)data; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname,lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, DELETE_FACELIST_CMD + ,l_db_log_tbname + ,l_db_log_tbname + ,lpr_del_lprlist_data->face_name); +#ifdef FACE_AMBA_DEBUG + printf("[callback_del_facelist_msg_to_db] Delete LPR Log: %s\n", l_sql_cmd); +#endif + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + // l_sql_ret=db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if(l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_del_lprlist_data) { + // free(lpr_del_lprlist_data); + // lpr_del_lprlist_data = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } + + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if((l_sql_ret==0) &&(nIndex==sumIndex-1)) + return 1; + else + return 0; + +} + +int callback_del_facetab_first_name_from_db(void *data, int nIndex, int sumIndex) //should change this action for face +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[20] = { 0 }; + facegroup_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = { 0 }; + int l_sql_ret = 0; + + if (!data) + { + return 0; + } + + lpr_del_lprlist_data = (facegroup_db_tb *)data; + + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type(set db table name) + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, DELETE_FACETAB_USER_NAME_CMD + , l_db_log_tbname + , l_db_log_tbname + , lpr_del_lprlist_data->user_name); + + printf("[black list] delete cmd: %s \n", l_sql_cmd); + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } +} + +int callback_del_facetab_time_msg_to_db(void *data, int nIndex, int sumIndex) //should change this action for face +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[20] = { 0 }; + facegroup_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = { 0 }; + int l_sql_ret = 0; + + if (!data) + { + return 0; + } + + lpr_del_lprlist_data = (facegroup_db_tb *)data; + + //if (g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type(set db table name) + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, DELETE_FACETAB_TIME_CMD + , l_db_log_tbname + , l_db_log_tbname + , lpr_del_lprlist_data->user_name); +#ifdef FACE_AMBA_DEBUG + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); +#endif + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if (l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_del_lprlist_data) { + // free(lpr_del_lprlist_data); + // lpr_del_lprlist_data = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } + + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if ((l_sql_ret == 0) && (nIndex == sumIndex - 1)) + return 1; + else + return 0; + +} + +int callback_del_face_map_msg_to_db(void *data,int nIndex,int sumIndex) //should change this action for face +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[20]={0}; + facegroup_mapping_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return 0; + } + + lpr_del_lprlist_data = ( facegroup_mapping_db_tb *)data; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname,lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, DELETE_FACE_MAPPING_CMD + ,l_db_log_tbname + ,l_db_log_tbname + ,lpr_del_lprlist_data->LPR_DETECT); +#ifdef FACE_AMBA_DEBUG + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); +#endif + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + // l_sql_ret=db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + // if(l_sql_ret) + // { + // printf("Error: %s\n", l_sql_cmd); + // /* + // facedb_mutex_unlock(g_facegroup_db_info.pdb); + // if (lpr_del_lprlist_data) { + // free(lpr_del_lprlist_data); + // lpr_del_lprlist_data = NULL; + // }*/ + // } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + } + } + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if((l_sql_ret==0) &&(nIndex==sumIndex-1)) + return 1; + else + return 0; + +} + +int callback_del_all_table(void *data) +{ + char l_db_log_tbname[20] = { 0 }; + char l_sql_cmd[2048] = { 0 }; + int l_sql_ret = 0; + + facegroup_db_tb *lpr_del_lprlist_data = NULL; + + if (!data) + { + return 0; + } + + lpr_del_lprlist_data = (facegroup_db_tb *)data; + + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_del_lprlist_data->tb_type); + + printf("type = %s, tbname = %s \n", lpr_del_lprlist_data->tb_type, l_db_log_tbname); + + //if (strcmp(list_name, "black") == 0) + // sprintf(selectTBname, "face_db_black_tb"); + //else if (strcmp(list_name, "white") == 0) + // sprintf(selectTBname, "face_db_white_tb"); + //printf("selectTBname = %s\n", selectTBname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, DELETE_ALL_RECORDS, l_db_log_tbname); +#ifdef FACE_AMBA_DEBUG + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); +#endif + printf("Delete LPR Log: %s\n", l_sql_cmd); + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } +} + +//void sqlite_facegroup_del( const char *LPR ,char *type_name,int nIndex,int sumIndex) +int sqlite_facegroup_del( const char *UUID ,char *type_name,int nIndex,int sumIndex) //should change variable name for face +{ + facegroup_db_tb *lpr_del_data = NULL; + //lpr_del_data = (facegroup_db_tb *)calloc(1, sizeof(facegroup_db_tb)); + lpr_del_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_del_data,0, sizeof(facegroup_db_tb)); + int l_result =0 ; + //if(lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->face_name, UUID); + chk_log_data(lpr_del_data->tb_type ,type_name); + l_result= callback_del_facetab_msg_to_db( (void *)lpr_del_data,nIndex,sumIndex); + + } + + return l_result; +} + +//void sqlite_facegroup_del( const char *LPR ,char *type_name,int nIndex,int sumIndex) +int sqlite_facegroup_delte_face_list( const char *FACE_NAME ,char *type_name,int nIndex,int sumIndex) //should change variable name for face +{ + facegroup_db_tb *lpr_del_data = NULL; + //lpr_del_data = (facegroup_db_tb *)calloc(1, sizeof(facegroup_db_tb)); + lpr_del_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_del_data,0, sizeof(facegroup_db_tb)); + int l_result =0 ; + //if(lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->face_name,FACE_NAME); + chk_log_data(lpr_del_data->tb_type ,type_name); + l_result= callback_del_facelist_msg_to_db( (void *)lpr_del_data,nIndex,sumIndex); + + } + return l_result; +} + +int sqlite_facegroup_del_time(const char *lpr_time, char *type_name, int nIndex, int sumIndex) //should change variable name for face +{ + //key = ff_mod_ts + + facegroup_db_tb *lpr_del_data = NULL; + //lpr_del_data = (facegroup_db_tb *)calloc(1, sizeof(facegroup_db_tb)); + lpr_del_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_del_data, 0, sizeof(facegroup_db_tb)); + int l_result = 0; + if (lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->MOD_TS, lpr_time); + chk_log_data(lpr_del_data->tb_type, type_name); + l_result = callback_del_facetab_time_msg_to_db((void *)lpr_del_data, nIndex, sumIndex); + + } + return l_result; +} + +int sqlite_facegroup_del_user_name(const char *lpr_oplate, char *type_name, int nIndex, int sumIndex) //should change variable name for face +{ + //key = Frist name + + facegroup_db_tb *lpr_del_data = NULL; + //lpr_del_data = (facegroup_db_tb *)calloc(1, sizeof(facegroup_db_tb)); + lpr_del_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_del_data, 0, sizeof(facegroup_db_tb)); + int l_result = 0; + if (lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->user_name, lpr_oplate); + chk_log_data(lpr_del_data->tb_type, type_name); + l_result = callback_del_facetab_first_name_from_db((void *)lpr_del_data, nIndex, sumIndex); + + } + return l_result; +} + +int sqlite_facegroup_del_map( const char *LPR_DETECT ,char *type_name,int nIndex,int sumIndex) //should change variable name for face +{ + facegroup_mapping_db_tb *lpr_del_data = NULL; + + lpr_del_data = (facegroup_mapping_db_tb *)malloc(sizeof( facegroup_mapping_db_tb)); + memset(lpr_del_data,0, sizeof( facegroup_mapping_db_tb)); + int l_result =0 ; + //if(lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->LPR_DETECT,LPR_DETECT); + chk_log_data(lpr_del_data->tb_type ,type_name); + l_result= callback_del_face_map_msg_to_db( (void *)lpr_del_data,nIndex,sumIndex); + + } + return l_result; +} + +int sqlite_facegroup_del_all_table(char *type_name) +{ +} + +void sqlite_facegroup_insert(facegroup_db_tb *l_ff_insert_data, char *type_name) //(^V)should change variable name for face +{ + // printf("\n[sqlite_facegroup_insert] 0-0"); + if (check_if_db_is_malformed == 1) { + if (g_facegroup_db_info.pdb) + { + //PRINT_INFO_LOG("####### License Plate DB Close\n"); + facedb_mutex_lock(g_facegroup_db_info.pdb); + //db_lock(g_facegroup_db_info.pdb); + sqlite3_close(g_facegroup_db_info.pdb); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_log_db_info->pdb); + } + + system(SHELLSCRIPT_FIX_DB_FACE); + check_if_db_is_malformed = 0; + + sqlite3_open_v2(g_facegroup_db_info.db_name, &g_facegroup_db_info.pdb, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL); + } + + // printf("\n[sqlite_facegroup_insert] 0"); + pthread_mutex_lock(&mutex_db_face_insert_db); + //printf("\n[sqlite_facegroup_insert] 0-1"); + facegroup_db_tb *lpr_insert_data = NULL; + //printf("\n[sqlite_facegroup_insert] 0-2"); + //lpr_insert_data = calloc(1, sizeof(facegroup_db_tb)); + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + + //printf("\n[sqlite_facegroup_insert] 0-3"); + + //printf("\n[sqlite_facegroup_insert] 0-4"); + + //if(lpr_insert_data != NULL) + { + memset(lpr_insert_data, 0, sizeof(facegroup_db_tb)); + // printf("\n[sqlite_facegroup_insert] 1"); + chk_log_data(lpr_insert_data->TS ,l_ff_insert_data->TS); + chk_log_data(lpr_insert_data->MOD_TS,l_ff_insert_data->MOD_TS); + chk_log_data(lpr_insert_data->CAR_ID,l_ff_insert_data->CAR_ID); + chk_log_data(lpr_insert_data->LPR,l_ff_insert_data->LPR); + chk_log_data(lpr_insert_data->RTIME,l_ff_insert_data->RTIME); + chk_log_data(lpr_insert_data->ACTION,l_ff_insert_data->ACTION); + chk_log_data(lpr_insert_data->sec_color_id, l_ff_insert_data->sec_color_id); + chk_log_data(lpr_insert_data->ACT_PARAM,l_ff_insert_data->ACT_PARAM); + chk_log_data(lpr_insert_data->THRESHOLD,l_ff_insert_data->THRESHOLD); + chk_log_data(lpr_insert_data->ROI_X,l_ff_insert_data->ROI_X); + chk_log_data(lpr_insert_data->ROI_Y,l_ff_insert_data->ROI_Y); + chk_log_data(lpr_insert_data->ROI_W,l_ff_insert_data->ROI_W); + chk_log_data(lpr_insert_data->ROI_H,l_ff_insert_data->ROI_H); + chk_log_data(lpr_insert_data->LP_X,l_ff_insert_data->LP_X); + chk_log_data(lpr_insert_data->LP_Y,l_ff_insert_data->LP_Y); + chk_log_data(lpr_insert_data->LP_W ,l_ff_insert_data->LP_W); + chk_log_data(lpr_insert_data->LP_H ,l_ff_insert_data->LP_H); + chk_log_data(lpr_insert_data->LP_BMP ,l_ff_insert_data->LP_BMP); + chk_log_data(lpr_insert_data->ROI_BMP ,l_ff_insert_data->ROI_BMP); + chk_log_data(lpr_insert_data->COUNTRY ,l_ff_insert_data->COUNTRY); + chk_log_data(lpr_insert_data->IN_USER ,l_ff_insert_data->IN_USER); + chk_log_data(lpr_insert_data->IN_PHONE ,l_ff_insert_data->IN_PHONE); + chk_log_data(lpr_insert_data->IN_ADDRESS ,l_ff_insert_data->IN_ADDRESS); + chk_log_data(lpr_insert_data->IN_PAYSTATUS ,l_ff_insert_data->IN_PAYSTATUS); + chk_log_data(lpr_insert_data->IN_EXIST ,l_ff_insert_data->IN_EXIST); + chk_log_data(lpr_insert_data->IN_SCHEDULE_START ,l_ff_insert_data->IN_SCHEDULE_START); + chk_log_data(lpr_insert_data->IN_SCHEDULE_END ,l_ff_insert_data->IN_SCHEDULE_END); + chk_log_data(lpr_insert_data->IN_OTHER ,l_ff_insert_data->IN_OTHER); + + chk_log_data(lpr_insert_data->sql_count ,l_ff_insert_data->sql_count); + chk_log_data(lpr_insert_data->sql_tbname ,l_ff_insert_data->sql_tbname); + + chk_log_data(lpr_insert_data->tb_type ,type_name); + //printf("\n[sqlite_facegroup_insert] type_name:%s\nlpr_insert_data->tb_type:%s\n", type_name, lpr_insert_data->tb_type); + chk_log_data(lpr_insert_data->IN_DETECT_ENDTIME ,l_ff_insert_data->IN_DETECT_ENDTIME); + + chk_log_data(lpr_insert_data->face_name ,l_ff_insert_data->face_name); + chk_log_data(lpr_insert_data->user_name ,l_ff_insert_data->user_name); + chk_log_data(lpr_insert_data->face_uuid ,l_ff_insert_data->face_uuid); + chk_log_data(lpr_insert_data->identification_score ,l_ff_insert_data->identification_score); + chk_log_data(lpr_insert_data->face_trackingID ,l_ff_insert_data->face_trackingID); + +#ifdef FACE_AMBA_DEBUG + printf("\n[sqlite_facegroup_insert] RTIME: %s, ACT_PARAM: %s, LP_BMP: %s, sql_tbname: %s, face_name: %s, user_name: %s, face_uuid: %s\n", + lpr_insert_data->RTIME, + lpr_insert_data->ACT_PARAM, + lpr_insert_data->LP_BMP, + lpr_insert_data->sql_tbname, + lpr_insert_data->face_name, + lpr_insert_data->user_name, + lpr_insert_data->face_uuid); +#endif + + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_insert_face_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + //printf("[sqlite_facegroup_insert][callback_insert_face_msg_to_db]lprdb_thread: %d",lprdb_thread); + + //printf("\n[sqlite_facegroup_insert] 3"); + } + pthread_mutex_unlock(&mutex_db_face_insert_db); +} +void sqlite_facegroup_add_list(const char *LPR , const char *IN_USER , const char *IN_PHONE,const char *IN_ADDRESS, + const char *IN_PAYSTATUS,const char *IN_EXIST, const char *IN_SCHEDULE_START, + const char *IN_SCHEDULE_END, const char *IN_OTHER ,char *IN_DETECT_ENDTIME,char *type_name) //(^V)should change this action for face +{ + pthread_mutex_lock(&mutex_db_face_add); + facegroup_db_tb *lpr_insert_data = NULL; + + //lpr_insert_data = calloc(1, sizeof(facegroup_db_tb)); + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_insert_data,0,sizeof(facegroup_db_tb)); + //if(lpr_insert_data != NULL) + { + chk_log_data(lpr_insert_data->LPR,LPR); + chk_log_data(lpr_insert_data->ACT_PARAM,type_name); + chk_log_data(lpr_insert_data->IN_USER ,IN_USER); + chk_log_data(lpr_insert_data->IN_PHONE ,IN_PHONE); + chk_log_data(lpr_insert_data->IN_ADDRESS ,IN_ADDRESS); + chk_log_data(lpr_insert_data->IN_PAYSTATUS ,IN_PAYSTATUS); + chk_log_data(lpr_insert_data->IN_EXIST ,IN_EXIST); + chk_log_data(lpr_insert_data->IN_SCHEDULE_START ,IN_SCHEDULE_START); + chk_log_data(lpr_insert_data->IN_SCHEDULE_END ,IN_SCHEDULE_END); + chk_log_data(lpr_insert_data->IN_OTHER ,IN_OTHER); + chk_log_data(lpr_insert_data->IN_DETECT_ENDTIME ,IN_DETECT_ENDTIME); + chk_log_data(lpr_insert_data->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_insert_facelist_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + } + pthread_mutex_unlock(&mutex_db_face_add); +} + +void sqlite_facegroup_add_from_table(const char *UUID, const char *MOD_TS, char *type_name) //(^V)should change this action for face +{ + //printf("\n[sqlite_facegroup_add_from_table]"); + pthread_mutex_lock(&mutex_db_face_add); + facegroup_db_tb *lpr_insert_data = NULL; + + char sUUID[64]; + + //printf("\n\nUUID = %s \n", UUID); + sprintf(sUUID, "%s", UUID); + + + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_insert_data, 0, sizeof(facegroup_db_tb)); + + chk_log_data(lpr_insert_data->tb_type, type_name); // db table name: "black"=watch or "white + chk_log_data(lpr_insert_data->face_name, sUUID); // UUID + chk_log_data(lpr_insert_data->ff_mod_ts, MOD_TS); + + +#ifdef FACE_AMBA_DEBUG + printf("\n[sqlite_facegroup_add_from_table]\n type_name: %s, UUID: %s, MOD_TS: %s \n\n", type_name, lpr_insert_data->face_name, lpr_insert_data->ff_mod_ts); +#endif + + pthread_t lprdb_thread; + + if (pthread_create(&lprdb_thread, 0, callback_insert_from_loglist_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + pthread_mutex_unlock(&mutex_db_face_add); +} + +void sqlite_facegroup_add_to_only_one_table(const char *tracking_uuid, char *type_name) +{ + //printf("\n[sqlite_facegroup_add_from_table]"); + pthread_mutex_lock(&mutex_db_face_add); + facegroup_db_tb *lpr_insert_data = NULL; + + + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_insert_data, 0, sizeof(facegroup_db_tb)); + + chk_log_data(lpr_insert_data->tb_type, type_name); // db table name: "black"=watch or "white + chk_log_data(lpr_insert_data->face_tracking_uuid, tracking_uuid); // tracking_uuid + + +#ifdef FACE_AMBA_DEBUG + printf("\n[sqlite_facegroup_add_from_table]\n type_name: %s, UUID: %s, MOD_TS: %s \n\n", type_name, lpr_insert_data->face_name, lpr_insert_data->ff_mod_ts); +#endif + + pthread_t lprdb_thread; + + if (pthread_create(&lprdb_thread, 0, callback_insert_to_one_tb, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + pthread_mutex_unlock(&mutex_db_face_add); +} + + +void sqlite_facegroup_add_face_list(const char *UUID, const char *FIRST_NAME, const char *LAST_NAME, const char *FACE_UUID, const char *IDENTIFICATION_SCORE,const char *FACE_BMP, + const char *FACE_TRACKING_ID, const char *IN_ADDRESS, const char *IN_OTHER,char *type_name, const char *IN_SCHEDULE_START, const char *IN_SCHEDULE_END, char *IN_DETECT_ENDTIME) //(^V)should change this action for face +{ + // printf("\n[sqlite_facegroup_add_face_list] 0-0"); + pthread_mutex_lock(&mutex_db_face_add); + facegroup_db_tb *lpr_insert_data = NULL; + + char sUUID[64]; + int iMaxUUID = 0; + + if (strlen(UUID) <= 0 || strlen(UUID) > 5) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + int log_table_max_num = db_search_max_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_TABLE); + int black_max_num = db_search_max_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE); + int white_table_max_num = db_search_max_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE); + + if (log_table_max_num > black_max_num && log_table_max_num > white_table_max_num) + iMaxUUID = log_table_max_num; + if (black_max_num > log_table_max_num && black_max_num > white_table_max_num) + iMaxUUID = black_max_num; + if (white_table_max_num > log_table_max_num && white_table_max_num > black_max_num) + iMaxUUID = white_table_max_num; + + //printf("Max UUID = %d \n", black_max_num); + sprintf(sUUID, "%05d", (iMaxUUID + 1)); + //printf("\n\nMax UUID = %s \n", sUUID); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + else + { + printf("\n\nUUID = %s \n", UUID); + sprintf(sUUID, "%s", UUID); + } + + printf("\n\nMax UUID = %s \n", sUUID); + + //lpr_insert_data = calloc(1, sizeof(facegroup_db_tb)); + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_insert_data,0,sizeof(facegroup_db_tb)); + // if(lpr_insert_data != NULL) + { + chk_log_data(lpr_insert_data->tb_type ,type_name); // DB Table Name: "watch" or "vip" + chk_log_data(lpr_insert_data->face_name , sUUID); // UUID + chk_log_data(lpr_insert_data->user_name , FIRST_NAME); // First Name + chk_log_data(lpr_insert_data->IN_USER, LAST_NAME); // Last Name + chk_log_data(lpr_insert_data->LP_BMP ,FACE_BMP); // Face BMP + chk_log_data(lpr_insert_data->face_uuid ,FACE_UUID); // Face Tracking UUID (Hash) + chk_log_data(lpr_insert_data->face_trackingID ,FACE_TRACKING_ID ); // Face Tracking ID + chk_log_data(lpr_insert_data->identification_score ,IDENTIFICATION_SCORE); // Face Identification Score + + chk_log_data(lpr_insert_data->IN_ADDRESS ,IN_ADDRESS); + chk_log_data(lpr_insert_data->IN_OTHER ,IN_OTHER); + + chk_log_data(lpr_insert_data->IN_SCHEDULE_START, IN_SCHEDULE_START); + chk_log_data(lpr_insert_data->IN_SCHEDULE_END, IN_SCHEDULE_END); + chk_log_data(lpr_insert_data->IN_DETECT_ENDTIME, IN_DETECT_ENDTIME); + + //chk_log_data(lpr_insert_data->LPR, LPR); + //chk_log_data(lpr_insert_data->ACT_PARAM, type_name); + //chk_log_data(lpr_insert_data->IN_USER, IN_USER); + //chk_log_data(lpr_insert_data->IN_PHONE, IN_PHONE); + //chk_log_data(lpr_insert_data->IN_ADDRESS, IN_ADDRESS); + //chk_log_data(lpr_insert_data->IN_PAYSTATUS, IN_PAYSTATUS); + //chk_log_data(lpr_insert_data->IN_EXIST, IN_EXIST); + //chk_log_data(lpr_insert_data->IN_SCHEDULE_START, "0:0"); + //chk_log_data(lpr_insert_data->IN_SCHEDULE_END, "23:59"); + //chk_log_data(lpr_insert_data->IN_OTHER, IN_OTHER); + //chk_log_data(lpr_insert_data->IN_DETECT_ENDTIME, '2200-12-30_23:59'); + //chk_log_data(lpr_insert_data->tb_type, type_name); + + +// #ifdef FACE_AMBA_DEBUG + printf("\n[sqlite_facegroup_add_face_list] type_name: %s lpr_insert_data->tb_type:%s face_name: %s user_name: %s",type_name, lpr_insert_data->tb_type, lpr_insert_data->face_name, lpr_insert_data->user_name); +// #endif + + pthread_t lprdb_thread; + + if (pthread_create(&lprdb_thread, 0, callback_insert_facelist_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + + } + pthread_mutex_unlock(&mutex_db_face_add); +} + + +void sqlite_facegroup_delete_face_list(const char *FACE_NAME, const char *USER_NAME, const char *FACE_UUID, const char *IDENTIFICATION_SCORE,/*const char *FACE_BMP,*/ + const char *FACE_TRACKING_ID, const char *IN_ADDRESS, const char *IN_OTHER,char *type_name) //(^V)should change this action for face +{ + // printf("\n[sqlite_facegroup_delete_face_list] 0-0"); + pthread_mutex_lock(&mutex_db_face_delete); + facegroup_db_tb *lpr_insert_data = NULL; + + //lpr_insert_data = calloc(1, sizeof(facegroup_db_tb)); + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_insert_data,0,sizeof(facegroup_db_tb)); + // if(lpr_insert_data != NULL) + { + chk_log_data(lpr_insert_data->tb_type ,type_name); // "black" or "white + chk_log_data(lpr_insert_data->face_name ,FACE_NAME); // face tracking uuid + chk_log_data(lpr_insert_data->user_name ,USER_NAME); //face name + // chk_log_data(lpr_insert_data->face_bmp ,FACE_BMP); //face name + chk_log_data(lpr_insert_data->face_uuid ,FACE_UUID); // face tracking uuid + chk_log_data(lpr_insert_data->identification_score ,IDENTIFICATION_SCORE); // face identification score + chk_log_data(lpr_insert_data->face_trackingID ,FACE_TRACKING_ID ); // face tracking id + chk_log_data(lpr_insert_data->IN_ADDRESS ,IN_ADDRESS); + chk_log_data(lpr_insert_data->IN_OTHER ,IN_OTHER); + + +#ifdef FACE_AMBA_DEBUG + printf("\n[sqlite_facegroup_delete_face_list] type_name: %s lpr_insert_data->tb_type:%s face_name: %s user_name: %s",type_name, lpr_insert_data->tb_type, lpr_insert_data->face_name, lpr_insert_data->user_name); +#endif + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_insert_facelist_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + } + pthread_mutex_unlock(&mutex_db_face_delete); +} +void sqlite_facegroup_delete_all_records(char *type_name) +{ + pthread_mutex_lock(&mutex_db_face_delete); + facegroup_db_tb *lpr_insert_data = NULL; + + //lpr_insert_data = calloc(1, sizeof(facegroup_db_tb)); + lpr_insert_data = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_insert_data, 0, sizeof(facegroup_db_tb)); + // if(lpr_insert_data != NULL) + { + //printf("type name a = %s \n", type_name); + chk_log_data(lpr_insert_data->tb_type, type_name); // "black" or "white + + printf("type name b = %s \n", lpr_insert_data->tb_type); +#ifdef FACE_AMBA_DEBUG + printf("\n[sqlite_facegroup_delete_face_list] type_name: %s lpr_insert_data->tb_type:%s face_name: %s user_name: %s", type_name, lpr_insert_data->tb_type, lpr_insert_data->face_name, lpr_insert_data->user_name); +#endif + pthread_t lprdb_del_thread; + if (pthread_create(&lprdb_del_thread, 0, callback_del_all_table, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + } + + pthread_mutex_unlock(&mutex_db_face_delete); +} + +void sqlite_facegroup_add_map_list(const char *LPR_DETECT ,const char *LPR,char *type_name) //should change this action for face +{ + facegroup_mapping_db_tb *lpr_insert_data = NULL; + + //lpr_insert_data = calloc(1, sizeof(facegroup_mapping_db_tb)); + lpr_insert_data = (facegroup_mapping_db_tb*)malloc(sizeof(facegroup_mapping_db_tb)); + memset(lpr_insert_data,0,sizeof(facegroup_mapping_db_tb)); + //if(lpr_insert_data != NULL) + { + chk_log_data(lpr_insert_data->LPR_DETECT,LPR_DETECT); + chk_log_data(lpr_insert_data->LPR,LPR); + + chk_log_data(lpr_insert_data->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_insert_face_map_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + } +} +void sqlite_facegroup_updateInfo_list(const char *LPR ,const char *IN_FIRST_NAME, const char *IN_USER , const char *IN_PHONE, + const char *IN_ADDRESS, const char *IN_PAYSTATUS,const char *IN_EXIST, + const char *IN_SCHEDULE_START,const char *IN_SCHEDULE_END, const char *IN_OTHER , + char *IN_DETECT_ENDTIME,char *type_name, char *IN_FACE_NAME) //should change this action for face +{ + printf("IN sqlite_facegroup_updateInfo_list \n"); + facegroup_listInfo_tb *lpr_updata_list = NULL; + + //lpr_updata_list = calloc(1, sizeof(facegroup_listInfo_tb)); + lpr_updata_list = (facegroup_listInfo_tb*)malloc(sizeof(facegroup_listInfo_tb)); + memset(lpr_updata_list,0,sizeof(facegroup_listInfo_tb)); + //if(lpr_updata_list != NULL) + { + + chk_log_data(lpr_updata_list->LPR,LPR); + chk_log_data(lpr_updata_list->ACT_PARAM,type_name); + chk_log_data(lpr_updata_list->IN_FIRST_NAME, IN_FIRST_NAME); + chk_log_data(lpr_updata_list->IN_USER ,IN_USER); + chk_log_data(lpr_updata_list->IN_PHONE ,IN_PHONE); + chk_log_data(lpr_updata_list->IN_ADDRESS ,IN_ADDRESS); + chk_log_data(lpr_updata_list->IN_PAYSTATUS ,IN_PAYSTATUS); + chk_log_data(lpr_updata_list->IN_EXIST ,IN_EXIST); + chk_log_data(lpr_updata_list->IN_SCHEDULE_START ,IN_SCHEDULE_START); + chk_log_data(lpr_updata_list->IN_SCHEDULE_END ,IN_SCHEDULE_END); + chk_log_data(lpr_updata_list->IN_OTHER ,IN_OTHER); + chk_log_data(lpr_updata_list->IN_DETECT_ENDTIME ,IN_DETECT_ENDTIME); + chk_log_data(lpr_updata_list->tb_type ,type_name); + chk_log_data(lpr_updata_list->IN_FACE_NAME, IN_FACE_NAME); //UUID + + printf("AAAAAAAAAAAAAAAAAAAAA IN FACE NAME = %s, %s \n", IN_FACE_NAME, lpr_updata_list->IN_FACE_NAME); + //FACE_MSG_BLACKTABLE + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_update_facelist_msg_to_db, (void *)lpr_updata_list)) + { + //printf("lilin_thread_pool_process full --> error\n"); + if (lpr_updata_list) { + free(lpr_updata_list); + lpr_updata_list = NULL; + } + } + + + } + +} +void sqlite_facegroup_update_map_list(const char *LPR_DETECT ,const char *LPR,const char *oLPR,char *type_name) //should change this action for face +{ + facegroup_mapping_db_tb *lpr_updata_map_list = NULL; + //lpr_updata_map_list = calloc(1, sizeof(facegroup_mapping_db_tb)); + lpr_updata_map_list = (facegroup_mapping_db_tb*)malloc(sizeof(facegroup_mapping_db_tb)); + memset(lpr_updata_map_list,0,sizeof(facegroup_mapping_db_tb)); + //if(lpr_updata_map_list != NULL) + { + + chk_log_data(lpr_updata_map_list->LPR_DETECT,LPR_DETECT); + chk_log_data(lpr_updata_map_list->LPR,LPR); + chk_log_data(lpr_updata_map_list->oLPR,oLPR); + chk_log_data(lpr_updata_map_list->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_update_face_map_msg_to_db, (void *)lpr_updata_map_list)) + { + //printf("lilin_thread_pool_process full --> error\n"); + if (lpr_updata_map_list) { + free(lpr_updata_map_list); + lpr_updata_map_list = NULL; + } + } + + } +} +void sqlite_facegroup_update(facegroup_db_tb *i_updata_list) //should change this action for face +{ + + facegroup_db_tb *lpr_iupdata_list = NULL; + //lpr_iupdata_list = calloc(1, sizeof(facegroup_db_tb)); + lpr_iupdata_list = (facegroup_db_tb *)malloc(sizeof(facegroup_db_tb)); + memset(lpr_iupdata_list,0,sizeof(facegroup_db_tb)); + //if(lpr_iupdata_list != NULL) + { + chk_log_data(lpr_iupdata_list->TS ,i_updata_list->TS); + chk_log_data(lpr_iupdata_list->MOD_TS,i_updata_list->MOD_TS); + chk_log_data(lpr_iupdata_list->CAR_ID,i_updata_list->CAR_ID); + chk_log_data(lpr_iupdata_list->LPR,i_updata_list->LPR); + chk_log_data(lpr_iupdata_list->RTIME,i_updata_list->RTIME); + chk_log_data(lpr_iupdata_list->ACTION,i_updata_list->ACTION); + chk_log_data(lpr_iupdata_list->sec_color_id, i_updata_list->sec_color_id); + chk_log_data(lpr_iupdata_list->ACT_PARAM,i_updata_list->ACT_PARAM); + chk_log_data(lpr_iupdata_list->THRESHOLD,i_updata_list->THRESHOLD); + chk_log_data(lpr_iupdata_list->ROI_X,i_updata_list->ROI_X); + chk_log_data(lpr_iupdata_list->ROI_Y,i_updata_list->ROI_Y); + chk_log_data(lpr_iupdata_list->ROI_W,i_updata_list->ROI_W); + chk_log_data(lpr_iupdata_list->ROI_H,i_updata_list->ROI_H); + chk_log_data(lpr_iupdata_list->LP_X,i_updata_list->LP_X); + chk_log_data(lpr_iupdata_list->LP_Y,i_updata_list->LP_Y); + chk_log_data(lpr_iupdata_list->LP_W ,i_updata_list->LP_W); + chk_log_data(lpr_iupdata_list->LP_H ,i_updata_list->LP_H); + chk_log_data(lpr_iupdata_list->LP_BMP ,i_updata_list->LP_BMP); + chk_log_data(lpr_iupdata_list->ROI_BMP ,i_updata_list->ROI_BMP); + chk_log_data(lpr_iupdata_list->COUNTRY ,i_updata_list->COUNTRY); + chk_log_data(lpr_iupdata_list->tb_type ,i_updata_list->tb_type); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_update_detectfacelist_msg_to_db, (void *)lpr_iupdata_list)) + { + //printf("lilin_thread_pool_process full --> error\n"); + if (lpr_iupdata_list) { + free(lpr_iupdata_list); + lpr_iupdata_list = NULL; + } + } + + } + +} + +int db_get_face_record(sqlite3_stmt *stmt, facegroup_db_tb *db_tb_info) //should change this action for face +{ + int l_result = 0; + + if(stmt) + { + int l_log_tb_columns = db_get_column_counts(g_facegroup_db_info.pstmt); + int l_jdx; + + for(l_jdx=0; l_jdx<l_log_tb_columns; l_jdx++) + { + if(!strcmp("ff_ts", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->TS, sizeof(db_tb_info->TS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_mod_ts", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->MOD_TS, sizeof(db_tb_info->MOD_TS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_car_id", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->CAR_ID, sizeof(db_tb_info->CAR_ID)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpr", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LPR, sizeof(db_tb_info->LPR)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_rtime", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->RTIME, sizeof(db_tb_info->RTIME)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_action", db_get_cloumn_name(stmt, l_jdx))) + { + + snprintf(db_tb_info->ACTION, sizeof(db_tb_info->ACTION)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if (!strcmp("ff_sec_color_id", db_get_cloumn_name(stmt, l_jdx))) + { + + snprintf(db_tb_info->sec_color_id, sizeof(db_tb_info->sec_color_id) - 1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_act_param", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ACT_PARAM, sizeof(db_tb_info->ACT_PARAM)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_threshold", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->THRESHOLD, sizeof(db_tb_info->THRESHOLD)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiX", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_X, sizeof(db_tb_info->ROI_X)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiY", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_Y, sizeof(db_tb_info->ROI_Y)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiW", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_W, sizeof(db_tb_info->ROI_W)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiH", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_H, sizeof(db_tb_info->ROI_H)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpX", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_X, sizeof(db_tb_info->LP_X)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpY", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_Y, sizeof(db_tb_info->LP_Y)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpW", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_W, sizeof(db_tb_info->LP_W)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpH", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_H, sizeof(db_tb_info->LP_H)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpbmp", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_BMP, sizeof(db_tb_info->LP_BMP)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lproi", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_BMP, sizeof(db_tb_info->ROI_BMP)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_country", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->COUNTRY, sizeof(db_tb_info->COUNTRY)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_user", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_USER, sizeof(db_tb_info->IN_USER)-1, db_get_column_value_str(stmt, l_jdx)); + snprintf(db_tb_info->last_name, sizeof(db_tb_info->last_name)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_phone", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_PHONE, sizeof(db_tb_info->IN_PHONE)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_address", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_ADDRESS, sizeof(db_tb_info->IN_ADDRESS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_paystatus", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_PAYSTATUS, sizeof(db_tb_info->IN_PAYSTATUS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_exist", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_EXIST, sizeof(db_tb_info->IN_EXIST)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_schedule_start", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_SCHEDULE_START, sizeof(db_tb_info->IN_SCHEDULE_START)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_schedule_end", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_SCHEDULE_END, sizeof(db_tb_info->IN_SCHEDULE_END)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_other", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_OTHER, sizeof(db_tb_info->IN_OTHER)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_detect_endtime", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_DETECT_ENDTIME, sizeof(db_tb_info->IN_DETECT_ENDTIME)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_face_name", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->face_name, sizeof(db_tb_info->face_name)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_user_name", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->user_name, sizeof(db_tb_info->user_name)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_face_uuid", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->face_uuid, sizeof(db_tb_info->face_uuid)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_identification_score", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->identification_score, sizeof(db_tb_info->identification_score)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_face_trackingID", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->face_trackingID, sizeof(db_tb_info->face_trackingID)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpbmp", db_get_cloumn_name(stmt, l_jdx))) + { + + snprintf(db_tb_info->LP_BMP, sizeof(db_tb_info->LP_BMP)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + } + } + + return l_result; +} +static int db_get_face_map_record(sqlite3_stmt *stmt, facegroup_mapping_db_tb *db_tb_info) //should change this action for face +{ + int l_result = 0; + + if(stmt) + { + int l_log_tb_columns = db_get_column_counts(g_facegroup_db_info.pstmt); + int l_jdx; + + for(l_jdx=0; l_jdx<l_log_tb_columns; l_jdx++) + { + if(!strcmp("ff_lpr", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LPR, sizeof(db_tb_info->LPR)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_det_lpr", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LPR_DETECT, sizeof(db_tb_info->LPR_DETECT)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + } + } + + return l_result; +} + +extern size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); +int cgi_get_db_face_log(SOCKET socket_in,char *db_tb_name,char *list_name,int sum_count) //should change this action for face +{ + + int l_result = 0; + int l_db_length=0; + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //printf("\n[cgi_get_db_face_log] 1---1"); + static char sendBuffer[3000*1000] = { 0 };//2000 + //printf("\n[cgi_get_db_face_log] 1---2"); + static char beforeSendBuffer[3000*1000] = { 0 };//2000 + //printf("\n[cgi_get_db_face_log] 1---3"); + int check_if_send = 0; + + //printf("\n[cgi_get_db_face_log] db_tb_name:%s list_name:%s sum_count:%d\n", db_tb_name,list_name, sum_count); + //if(g_facegroup_db_info) + //if(0) + { + //printf("\n[cgi_get_db_face_log] 1"); + + if(g_facegroup_db_info.pdb) + { + //printf("\n[cgi_get_db_face_log] 2"); + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_db_tb)); + char l_sql[128] = {0}; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + if(strcmp(list_name,LOGLISTNAME)==0||strcmp(list_name,CUSTLISTNAME_FACE)==0) + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name,sum_count); + else + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name,sum_count); + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //printf("\n[cgi_get_db_face_log] 3"); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, db_tb_name); + + /*if (l_lpr_record_cnts >= 0)*/ { + //printf("\n[cgi_get_db_face_log] 4"); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); +#ifdef FACE_AMBA_DEBUG + printf("\n[cgi_get_db_face_log] 5 l_rc:%d", l_rc); +#endif + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 6 l_rc:%d", l_rc); + } + if (l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + cJSON *root, *child; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(-1)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + + JsonString = cJSON_PrintUnformatted(root); + strcpy(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #1\n"); + + check_if_send = 1; + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + { + // printf("\n[cgi_get_db_face_log] 7"); + if (l_lpr_record_cnts >= sum_count) + l_db_length = sum_count; + else + l_db_length = l_lpr_record_cnts; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + //cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + //cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "FR_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "FR_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "FR_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "FR_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "FR_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "FR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "FR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "FR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "FR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "FR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "FR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "FR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToObject(child1, "face_name", cJSON_CreateString(l_db_lpr_tb_info.face_name)); + cJSON_AddItemToObject(child1, "user_name", cJSON_CreateString(l_db_lpr_tb_info.user_name)); + cJSON_AddItemToObject(child1, "last_name", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "face_uuid", cJSON_CreateString(l_db_lpr_tb_info.face_uuid)); + cJSON_AddItemToObject(child1, "identification_score", cJSON_CreateString(l_db_lpr_tb_info.identification_score)); + cJSON_AddItemToObject(child1, "face_trackingID", cJSON_CreateString(l_db_lpr_tb_info.face_trackingID)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + + // printf("\n[cgi_get_db_face_log] 7 JsonString:%s\n", JsonString); + strcpy(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_face_log] 9------sendBufferSize:%d\n", sendBufferSize); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2\n"); + //printf("\n[cgi_get_db_face_log] 10\n"); + + check_if_send = 1; + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + //printf("\n[cgi_get_db_face_log] 11\n"); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 12\n"); + + l_result = l_idx + 1; + } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + //printf("\n[cgi_get_db_face_log] 13\n"); + + //fflush(wp); + } + } + + if (check_if_send == 0) { + strcpy(beforeSendBuffer, ""); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_face_log] 9999\n"); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2222\n"); + } + + return l_result; +} + +int cgi_get_db_face_log_delete_jpg(char *db_tb_name, char *list_name, int sum_count) //should change this action for face +{ + int l_result = 0; + int l_db_length = 0; + + //printf("\n[cgi_get_db_face_log_delete_jpg] db_tb_name:%s list_name:%s sum_count:%d\n", db_tb_name,list_name, sum_count); + //if (g_facegroup_db_info) + { + //printf("\n[cgi_get_db_face_log_delete_jpg] 1"); + + if (g_facegroup_db_info.pdb) + { + //printf("\n[cgi_get_db_face_log_delete_jpg] 2"); + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info, 0, sizeof(facegroup_db_tb)); + //printf("\n[cgi_get_db_face_log_delete_jpg] 2-1"); + char l_sql[128] = { 0 }; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //printf("\n[cgi_get_db_face_log_delete_jpg] 2-2"); + if (strcmp(list_name, LOGLISTNAME) == 0 || strcmp(list_name, CUSTLISTNAME_FACE) == 0) + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, sum_count); + else + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name, sum_count); + //printf("\n[cgi_get_db_face_log_delete_jpg] 2-3"); + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //printf("\n[cgi_get_db_face_log_delete_jpg] 3"); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, db_tb_name); + + //printf("\n[cgi_get_db_face_log_delete_jpg] 4"); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + //printf("\n[cgi_get_db_face_log_delete_jpg] 5 l_rc:%d", l_rc); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 6 l_rc:%d", l_rc); + } + if (l_rc != 0) + { + l_idx = -1; + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + } + else + { + //printf("\n[cgi_get_db_face_log_delete_jpg] 7"); + if (l_lpr_record_cnts >= sum_count) + l_db_length = sum_count; + else + l_db_length = l_lpr_record_cnts; + + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + if (l_idx + 1 == 600) { + strcpy(g_MOD_TS, l_db_lpr_tb_info.MOD_TS); + } + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + //printf("\n[cgi_get_db_face_log] 11\n"); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 12\n"); + + l_result = l_idx + 1; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + //printf("\n[cgi_get_db_face_log] 13\n"); + //fflush(wp); + } + } + + return l_result; +} +#if 0 +int cgi_get_db_lpr_mapping(SOCKET socket_in,char *db_tb_name,char *list_name,int sum_count) +{ + int l_result = 0; + int l_db_length=0; + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_mapping_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_mapping_db_tb)); + char l_sql[128] = {0}; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name,sum_count); + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, db_tb_name); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + cJSON *root, *child; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(-1)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + + JsonString = cJSON_PrintUnformatted(root); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + + } + else + { + if(l_lpr_record_cnts >=sum_count) + l_db_length=sum_count; + else + l_db_length=l_lpr_record_cnts; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_face_map_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + cJSON_AddItemToObject(child1, "MAP_INDEX", cJSON_CreateNumber(l_idx+1)); + cJSON_AddItemToObject(child1, "LPR_DETECT", cJSON_CreateString(l_db_lpr_tb_info.LPR_DETECT)); + cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #4\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + l_result = l_idx + 1; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + return l_result; +} +#endif +#if 0 +int cgi_get_db_lpr_map_count(webs_t wp,char *db_tb_name,char *list_name,int sum_count,int tar_count) +{ + char l_lpr_cgi_res[512] = {0}; + int l_result = 0; + int l_db_length=0; + + snprintf(l_lpr_cgi_res , sizeof(l_lpr_cgi_res)-1, "HTTP/1.0 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_mapping_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_mapping_db_tb)); + char l_sql[200] = {0}; + int l_log_tb_columns = 0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + + websWrite(wp ,"%s" ,l_lpr_cgi_res); + + int l_rc; + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, db_tb_name); + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name,tar_count); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + websWrite (wp, "{\n"); + websWrite (wp, " \"LPR_COUNT\": -1,\r\n"); + websWrite (wp, " \"INFORMATION\": [\r\n"); + websWrite (wp, " ]\r\n"); + websWrite (wp, "}\r\n"); + + } + else + { + if(l_lpr_record_cnts>=sum_count) + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + } + else + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + + } + + websWrite (wp, "{"); + websWrite (wp, "\"LPR_COUNT\": %d,", l_db_length ); + websWrite (wp, "\"INFORMATION\": ["); + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_face_map_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + + websWrite (wp, "{" + "\"INDEX\":%d," + "\"LPR_DETECT\":\"%s\"," + "\"LPR\":\"%s\"", + l_idx+1, + l_db_lpr_tb_info.LPR_DETECT, + l_db_lpr_tb_info.LPR + ); + + if((l_idx+1) == l_db_length) + { + websWrite (wp, "}"); + } + else + { + websWrite (wp, "},"); + } + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + + websWrite (wp, "],\"LIST_TYPE\": \"%s\"",list_name); + websWrite (wp, "}"); + } + + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + l_result = l_idx + 1; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + fflush(wp); + + } + } + return l_result; +} +#endif +#if 1 +int cgi_get_db_face_log_count(SOCKET socket_in,char *db_tb_name,char *list_name,int sum_count,int tar_count) //should change this action for face +{ + int l_result = 0; + int l_db_length=0; + + char sendBuffer[2000 * 1000] = { 0 }; + char beforeSendBuffer[2000 * 1000] = { 0 }; + + char selectTBname[256] = { 0 }; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_db_tb)); + char l_sql[200] = {0}; + //int l_log_tb_columns = 0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + + int l_rc; + + printf("list_name = %s\n", list_name); + + if(strcmp(list_name,LOGLISTNAME)==0||strcmp(list_name,CUSTLISTNAME_FACE)==0) + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, /*MAX_ROW_DATA,*/ tar_count); + else + { + if (strcmp(list_name, "watch") == 0) + sprintf(selectTBname, "face_db_black_tb"); + else if (strcmp(list_name, "vip") == 0) + sprintf(selectTBname, "face_db_white_tb"); + + printf("selectTBname = %s\n", selectTBname); + + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", selectTBname, /*MAX_ROW_DATA,*/ tar_count); + } + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, db_tb_name); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + //printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + cJSON *root, *child; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(-1)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + + JsonString = cJSON_PrintUnformatted(root); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #1\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + { + if(l_lpr_record_cnts>=sum_count) + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + } + else + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + + } + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + //cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + //cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "FR_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "FR_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "FR_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "FR_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "FR_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "FR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "FR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "FR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "FR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "FR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "FR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "FR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + + //printf("\n[cgi_get_db_face_log] 7 JsonString:%s\n", JsonString); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_face_log] 9\n"); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2\n"); + //printf("\n[cgi_get_db_face_log] 10\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + l_result = l_idx + 1; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + //fflush(wp); + + } + } + return l_result; +} +#endif +facegroup_db_tb get_face_Data_from_frequent_VIP(char *column_name) { + int l_rc; + char l_sql[1024]; + + facegroup_db_tb l_db_info = {0}; // lƬŵc + + // O face_db_white_tb M face_db_black_tb SQL d + snprintf(l_sql, sizeof(l_sql) - 1, + "SELECT * FROM face_db_white_tb WHERE ff_face_name = '%s' ORDER BY ff_index DESC LIMIT 1;", + column_name); + + // wƮw + facedb_mutex_lock(g_facegroup_db_info.pdb); + + // dz SQL d + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + if (l_rc == 0) { + // d + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_info); + if (strcmp(l_db_info.face_name, "")) { + strcpy(l_db_info.group, "vip"); + } + } else { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + } + + // pGb white_tb SơAhb black_tb d + if (strcmp(l_db_info.group, "vip")) { + snprintf(l_sql, sizeof(l_sql) - 1, + "SELECT * FROM face_db_black_tb WHERE ff_face_name = '%s' ORDER BY ff_index DESC LIMIT 1;", + column_name); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + if (l_rc == 0) { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_info); + if (strcmp(l_db_info.face_name, "")) { + strcpy(l_db_info.group, "watch"); + } + } else { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + } + } + + // w + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + return l_db_info; // ^dߵG +} +#if 1 +int cgi_get_db_face_data(SOCKET socket_in, char *db_tb_name, char *list_name, char *column_name, char *searchStr) //should change this action for face +{ + int l_result = 0; + int l_db_length = 0; + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //printf("\n[cgi_get_db_face_log] 1---1"); + static char sendBuffer[3000 * 1000] = { 0 };//2000 + //printf("\n[cgi_get_db_face_log] 1---2"); + static char beforeSendBuffer[3000 * 1000] = { 0 };//2000 + //printf("\n[cgi_get_db_face_log] 1---3"); + int check_if_send = 0; + + char selectTBname[256] = { 0 }; + + //printf("n, n, n = %s, %s \n", column_name, searchStr); + + //printf("\n[cgi_get_db_face_log] db_tb_name:%s list_name:%s sum_count:%d\n", db_tb_name,list_name, sum_count); + //if(g_facegroup_db_info) + //if(0) + { + if (g_facegroup_db_info.pdb) + { + //printf("\n[cgi_get_db_face_log] 2"); + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info, 0, sizeof(facegroup_db_tb)); + char l_sql[128] = { 0 }; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //if (strcmp(list_name, LOGLISTNAME) == 0 || strcmp(list_name, CUSTLISTNAME_FACE) == 0) + // snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, sum_count); + //else + //snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name, sum_count); + + //snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s WHERE %s = '%s' ORDER BY ff_index DESC LIMIT 1;", db_tb_name, column_name, searchStr); + //SELECT * FROM face_db_tb WHERE ff_face_name = '00010' ORDER BY ff_index DESC LIMIT 1 + + //ASC: old, DESC: new + if (strcmp(list_name, LOGLISTNAME) == 0 || strcmp(list_name, CUSTLISTNAME_FACE) == 0) + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s WHERE %s = '%s' ORDER BY ff_index ASC LIMIT 1;", db_tb_name, column_name, searchStr); + else + { + if (strcmp(list_name, "watch") == 0) + sprintf(selectTBname, "face_db_black_tb"); + else if (strcmp(list_name, "vip") == 0) + sprintf(selectTBname, "face_db_white_tb"); + + //printf("selectTBname = %s\n", selectTBname); + + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s WHERE %s = '%s' ORDER BY ff_index ASC LIMIT 1;", selectTBname, column_name, searchStr); + } + + + //printf("l_sql = %s \n", l_sql); + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 6 l_rc:%d", l_rc); + } + + if (l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + } + else + { + //printf("get data num: %d \n", l_lpr_record_cnts); + l_db_length = 1; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "DATA_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + //cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + //cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "FR_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "FR_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "FR_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "FR_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "FR_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "FR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "FR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "FR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "FR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "FR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "FR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "FR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "FR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToObject(child1, "face_name", cJSON_CreateString(l_db_lpr_tb_info.face_name)); + cJSON_AddItemToObject(child1, "user_name", cJSON_CreateString(l_db_lpr_tb_info.user_name)); + cJSON_AddItemToObject(child1, "last_name", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "face_uuid", cJSON_CreateString(l_db_lpr_tb_info.face_uuid)); + cJSON_AddItemToObject(child1, "identification_score", cJSON_CreateString(l_db_lpr_tb_info.identification_score)); + cJSON_AddItemToObject(child1, "face_trackingID", cJSON_CreateString(l_db_lpr_tb_info.face_trackingID)); + cJSON_AddItemToArray(child, child1); + } + JsonString = cJSON_PrintUnformatted(root); + + strcpy(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_face_log] 9------sendBufferSize:%d\n", sendBufferSize); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2\n"); + + check_if_send = 1; + + db_free_sql_stmt(g_facegroup_db_info.pstmt); + //printf("\n[cgi_get_db_face_log] 12\n"); + + l_result = 1; //data number = 1 + } + +#ifdef FACE_AMBA_DEBUG + printf("\n[cgi_get_db_face_log] 5 l_rc:%d", l_rc); +#endif + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + + if (check_if_send == 0) { + strcpy(beforeSendBuffer, ""); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_face_log] 9999\n"); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2222\n"); + } + + return l_result; +} +#endif + +/* + --- get lpr information --- + 1.All list + 2.list count + 3.download list count +*/ + +int cgi_get_search_info_face(SOCKET socket_in, char *path) //(^V)should change this action for face +{ + //get all Information + //*Black List =>get_search_info?flist=black + //*White List =>get_search_info?flist=white + //*Log List =>get_search_info?flist=log + //*Customer List =>get_search_info?flist=visitor + //*config List =>get_search_info?flist=config + + //get List count + //*Black -> get_search_info?select=black&limit=1 + //*White -> get_search_info?select=white&limit=2 + //*Log -> get_search_info?select=log&limit=2 + //*Customer -> get_search_info?select=visitor&limit=2 + + //get download .csv + //*Black -> get_search_info?download=black&count=1 + //*White -> get_search_info?download=white&count=1 + //*Log -> get_search_info?download=log&count=1 + //*Customer -> get_search_info?download=visitor&count=1 + //*Customer -> get_search_info?download=ALL&count=1 + char l_lpr_cgi_param[BUFSIZE*4] = {0}; + //char l_lpr_type[BUFSIZE * 4] = {0}; + char l_count[BUFSIZE * 4] = {0}; + char l_limit[BUFSIZE * 4] = {0}; + char l_column_nmae[256] = { 0 }; + char l_search_nmae[256] = { 0 }; + char l_compare_str[BUFSIZE * 4] = {0}; + char l_compare_str2[BUFSIZE * 4] = {0}; + char l_compare_str3[BUFSIZE * 4] = {0}; + char l_compare_str4[BUFSIZE * 4] = {0}; + char l_compare_str5[BUFSIZE * 4] = {0}; +#ifdef FACE_AMBA_DEBUG + printf("\n[cgi_get_search_info] path:%s",path); +#endif + //printf("\n[cgi_get_search_info] 1\n"); + sprintf(l_compare_str, "%s=", SETTYPE_DOWNLOAD); + + if(strncmp(path,"flist=",6)==0) + { + //printf("\n[cgi_get_search_info] 2\n"); + strncpy(l_lpr_cgi_param, path+6, strlen(path)-6); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + + //printf("\n[cgi_get_search_info] l_lpr_cgi_param:%s", l_lpr_cgi_param); + //printf("\n[cgi_get_search_info] 3---0\n"); + if(strncmp(l_lpr_cgi_param,CUSTLISTNAME_FACE,strlen(CUSTLISTNAME_FACE))==0) + { + //printf("\n[cgi_get_search_info] 3--1\n"); + cgi_get_db_face_log(socket_in,FACE_MSG_CUSTOMERTABLE,CUSTLISTNAME_FACE,COUNT_CUSTOMER); + } + else if(strncmp(l_lpr_cgi_param,BKLISTNAME_FACE,strlen(BKLISTNAME_FACE))==0) + { + cgi_get_db_face_log(socket_in,FACE_MSG_BLACKTABLE,BKLISTNAME_FACE,COUNT_BLACK-100); + } + else if(strncmp(l_lpr_cgi_param,WTLISTNAME_FACE,strlen(WTLISTNAME_FACE))==0) + { + //printf("\n[cgi_get_search_info] 4\n"); + cgi_get_db_face_log(socket_in,FACE_MSG_WHITETABLE,WTLISTNAME_FACE,COUNT_WHITE-100); + // printf("\n[cgi_get_search_info] 5\n"); + } + else if(strncmp(l_lpr_cgi_param,LOGLISTNAME,strlen(LOGLISTNAME))==0) + { + cgi_get_db_face_log(socket_in,FACE_MSG_TABLE,LOGLISTNAME,COUNT_LOG); + // printf("\n[cgi_get_search_info] cgi_get_db_face_log list log\n"); + } +#if 0 + else if(strcmp(l_lpr_cgi_param,CONFIGLISTNAME)==0) + { + get_license_config(wp); + } +#endif +#if 0 + else if(strncmp(l_lpr_cgi_param,MAPPINGNAME,strlen(MAPPINGNAME))==0) + { + cgi_get_db_lpr_mapping(socket_in,FACE_MAPPING_TABLE, MAPPINGNAME,COUNT_MAPPING); + } +#endif + + } + else if(strncmp(path, "select=", 7) == 0) + { + int iFindLimit = 0, iLimit = 0; + int iFindColumn = 0, iFindSearchName = 0; + char sTableName[100] = { 0 }, sColumnName[100] = { 0 }, sSearchName[100] = { 0 }; + + const char *del = "&"; + const char *del2 = "="; + char sUrlData[50][100] = { 0 }; + char sUrlSecData[50][10][100] = { 0 }; + int iUrlDataNumber = 0; + int iUrlSecDataNumber = 0; + + //char sPathTEMP[8592]; + //sprintf(sPathTEMP, "%s", path); + + iUrlDataNumber = StrSplit(path, sUrlData, del); + + //printf("iUrlDataNumber = %d \n", iUrlDataNumber); + + for (int i = 0; i < iUrlDataNumber; i++) + { + if (sUrlData[i]) + { + //printf("[%d] %s \n", i, sUrlData[i]); + iUrlSecDataNumber = StrSplit(sUrlData[i], sUrlSecData[i], del2); + //printf(" %s, %s \n", sUrlSecData[i][0], sUrlSecData[i][1]); + + if (strcmp(sUrlSecData[i][0], "limit") == 0) + { + iFindLimit = 1; + iLimit = atoi(sUrlSecData[i][1]); + } + + //sTableName + if (strcmp(sUrlSecData[i][0], "select") == 0) + { + sprintf(sTableName, "%s", sUrlSecData[i][1]); + } + + //if (strcmp(sUrlSecData[i][0], "column_name") == 0) + //{ + // iFindColumn = 1; + // sprintf(sColumnName, "%s", sUrlSecData[i][1]); + //} + + if (strcmp(sUrlSecData[i][0], "face_name") == 0) + { + iFindSearchName = 1; + sprintf(sSearchName, "%s", sUrlSecData[i][1]); + } + } + } + + iFindColumn = 1; + sprintf(sColumnName, "%s", "ff_face_name"); + + //strncpy(l_lpr_cgi_param, path + 7, strlen(path) - 7); + //l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + + //printf("\n---------------path: %s\n",path); + + //char* c_limit = NULL; + //c_limit = strstr(path,"limit="); + + //char* c_face_uuName = NULL; + //c_face_uuName = strstr(path, "face_name="); + //printf("\n---------------limit: %s\n",c_limit); + + if (iFindLimit) { + + //strncpy(l_limit, c_limit + 6, strlen(c_limit) - 6); + //l_limit[strlen(l_limit)] = '\0'; + + if (strlen(l_limit) >= 1) { + + if (strncmp(sTableName, CUSTLISTNAME_FACE, strlen(CUSTLISTNAME_FACE)) == 0) + { + cgi_get_db_face_log_count(socket_in, FACE_MSG_CUSTOMERTABLE, CUSTLISTNAME_FACE, COUNT_CUSTOMER, iLimit); + } + else if (strncmp(sTableName, BKLISTNAME_FACE, strlen(BKLISTNAME_FACE)) == 0) + { + cgi_get_db_face_log_count(socket_in, FACE_MSG_BLACKTABLE, BKLISTNAME_FACE, COUNT_BLACK-100, iLimit); + } + else if (strncmp(sTableName, WTLISTNAME_FACE, strlen(WTLISTNAME_FACE)) == 0) + { + cgi_get_db_face_log_count(socket_in, FACE_MSG_WHITETABLE, WTLISTNAME_FACE, COUNT_WHITE-100, iLimit); + } + else if (strncmp(sTableName, LOGLISTNAME, strlen(LOGLISTNAME)) == 0) + { + cgi_get_db_face_log_count(socket_in, FACE_MSG_TABLE, LOGLISTNAME, COUNT_LOG, iLimit); + } + } + } + + + //char* c_column_name = NULL; + //c_column_name = strstr(path, "column_name="); + + //char* c_search_value = NULL; + //c_search_value = strstr(path, "face_name="); + + //printf("%s, %s, %s \n", sTableName, sColumnName, sSearchName); + //char l_column_nmae[256] = { 0 }; + //char l_search_nmae[256] = { 0 }; +#if 1 + if (iFindColumn && iFindSearchName) + { + //strncpy(l_column_nmae, c_column_name + 12, strlen(c_column_name) - 12); + //l_column_nmae[strlen(l_column_nmae)] = '\0'; + + //strncpy(l_search_nmae, c_search_value + 8, strlen(c_search_value) - 8); + //l_search_nmae[strlen(l_search_nmae)] = '\0'; + + //printf("l_face_uuNmae = %s \n", l_face_uuNmae); + if (strncmp(sTableName, CUSTLISTNAME_FACE, strlen(CUSTLISTNAME_FACE)) == 0) + { + //cgi_get_db_face_log_count(socket_in, FACE_MSG_CUSTOMERTABLE, CUSTLISTNAME_FACE, COUNT_CUSTOMER, atoi(l_limit)); + } + else if (strncmp(sTableName, BKLISTNAME_FACE, strlen(BKLISTNAME_FACE)) == 0) + { + //cgi_get_db_face_log_count(socket_in, FACE_MSG_BLACKTABLE, BKLISTNAME_FACE, COUNT_BLACK - 100, atoi(l_limit)); + cgi_get_db_face_data(socket_in, FACE_MSG_TABLE, BKLISTNAME_FACE, sColumnName, sSearchName); + } + else if (strncmp(sTableName, WTLISTNAME_FACE, strlen(WTLISTNAME_FACE)) == 0) + { + //cgi_get_db_face_log_count(socket_in, FACE_MSG_WHITETABLE, WTLISTNAME_FACE, COUNT_WHITE - 100, atoi(l_limit)); + cgi_get_db_face_data(socket_in, FACE_MSG_TABLE, WTLISTNAME_FACE, sColumnName, sSearchName); + } + else if (strncmp(sTableName, LOGLISTNAME, strlen(LOGLISTNAME)) == 0) + { + //cgi_get_db_face_log_count(socket_in, FACE_MSG_TABLE, LOGLISTNAME, COUNT_LOG, atoi(l_limit)); + //int cgi_get_db_face_data(SOCKET socket_in, char *db_tb_name, char *list_name, char *column_name, char *searchStr) + cgi_get_db_face_data(socket_in, FACE_MSG_TABLE, LOGLISTNAME, sColumnName, sSearchName); + } + + } +#endif + + } + else if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + //printf("\n[cgi_get_search_info] 3"); + + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + char l_compare_str_temp[16] = { 0 }; + sprintf(l_compare_str_temp,"%s",CUSTLISTNAME_FACE); + sprintf(l_compare_str2,"%s",BKLISTNAME_FACE); + sprintf(l_compare_str3,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + sprintf(l_compare_str5,"%s",LOGLISTNAME); + if(strncmp(l_lpr_cgi_param, l_compare_str_temp,strlen(l_compare_str_temp))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 4" ); + sprintf(l_compare_str_temp2,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_facedb_log_file(socket_in, CUSTLISTNAME_FACE,FACE_MSG_CUSTOMERTABLE,atoi(l_count)); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 5"); + sprintf(l_compare_str_temp2,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_facedb_log_file(socket_in, BKLISTNAME_FACE,FACE_MSG_BLACKTABLE,atoi(l_count)); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 6"); + sprintf(l_compare_str_temp2,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_facedb_log_file(socket_in, WTLISTNAME_FACE,FACE_MSG_WHITETABLE,atoi(l_count)); + } + + } + else if(strncmp(l_lpr_cgi_param,l_compare_str5,strlen(l_compare_str5))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 7"); + sprintf(l_compare_str_temp2,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_facedb_log_file(socket_in, LOGLISTNAME,FACE_MSG_TABLE,atoi(l_count)); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 8"); + sprintf(l_compare_str_temp2,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_facedb_mapping_file(socket_in, MAPPINGNAME,FACE_MAPPING_TABLE,atoi(l_count)); + } + else + { + cgi_download_facedb_mapping_file(socket_in, MAPPINGNAME,FACE_MAPPING_TABLE,COUNT_MAPPING); + } + + } + else if(strncmp(l_lpr_cgi_param,"ALL",3)==0) + { + //printf("\n[cgi_get_search_info] 9"); + int l_WnB_MAX_Count = COUNT_WHITE+COUNT_BLACK-200; + //if(GetValidVar(wp,"count",l_count)) + { + cgi_download_facedb_list_file(socket_in, LOGLISTNAME,FACE_MSG_TABLE,l_WnB_MAX_Count); + } + } + } + //printf("\n[cgi_get_search_info] 6\n"); + return 0; +} +int cgi_download_facedb_mapping_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int map_icount) //should change this action for face +{ + time_t lpr_now_time; + struct tm *lpr_map_tm = NULL; + char lpr_map_time_fmt[64] = {0}; + char lpr_map_filename[64] = {0}; + char lpr_map_cgi_res[512] = {0}; + char lpr_sql_tb[20] = {0}; + //int l_result = 0; + int l_db_length=0; + lpr_now_time = time(NULL); + unsigned char header[3] = {(unsigned char)0xEF, (unsigned char)0xBB, (unsigned char)0xBF}; + lpr_map_tm = localtime(&lpr_now_time); + strftime(lpr_map_time_fmt, sizeof(lpr_map_time_fmt)-1, "%Y%m%d%H%M%S", lpr_map_tm); + + snprintf(lpr_map_filename, sizeof(lpr_map_time_fmt)-1, "%s_info.csv",log_type); + + snprintf(lpr_map_cgi_res ,sizeof(lpr_map_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Date: Tue, 27 Dec 2011 09:25:53 GMT\r\n" + "Accept-Ranges: bytes\r\n" + "Connection: close\r\n" + "Content-type: text/html;charset=UTF-8;\r\n" + "Content-Disposition: attachment; filename=%s\r\n" + "\r\n", lpr_map_filename); + + sprintf(lpr_sql_tb,"%s",log_sql_tb); + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_mapping_db_tb l_db_tb_info; + memset(&l_db_tb_info,0,sizeof(facegroup_mapping_db_tb)); + char l_sql[512] = {0}; + int l_idx = 0; + int l_map_record_cnts = 0; + int l_rc; + + if (send(socket_in, lpr_map_cgi_res, strlen(lpr_map_cgi_res), MSG_MORE) == -1) + printf("\nsend error #5\n"); + + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;",log_sql_tb ,map_icount); + l_map_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, log_sql_tb); + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s\n", l_sql); + + l_idx = -1; + } + else + { + if(l_map_record_cnts>=map_icount) + l_db_length=map_icount; + else + l_db_length=l_map_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + + db_get_face_map_record(g_facegroup_db_info.pstmt, &l_db_tb_info); + if(l_idx==0) + { + if (send(socket_in, header, strlen((char *)header), MSG_MORE) == -1) + printf("\nsend error #6\n"); + } + memset(lpr_map_cgi_res, 0, sizeof(lpr_map_cgi_res)); + snprintf(lpr_map_cgi_res ,sizeof(lpr_map_cgi_res)-1, "%s\r\n", + //"%s\r\n", + l_db_tb_info.LPR_DETECT + //, l_db_tb_info.LPR + ); + + if (send(socket_in, lpr_map_cgi_res, strlen(lpr_map_cgi_res), MSG_MORE) == -1) + printf("\nsend error #7\n"); + + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + } + + //l_result = l_idx; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + } + } + return 0; +} + +bool check_if_not_in_black_and_white_face(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance) //should change this action for face +{ + + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + int l_black_len = db_get_record_counts_check_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + //printf("\n[check_if_not_in_black_and_white]:%d\n", 3); + int l_white_len = db_get_record_counts_check_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + int l_log_record_cnts = l_black_len + l_white_len; + //printf("\n[check_if_not_in_black_and_white]:%d\n", 4); + //printf("\nAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\n%d\n", l_log_record_cnts); + //printf("\nBBBBBBBBBBBBBBBBBBBB\n"); + + if (l_log_record_cnts == 0) { + //printf("\n[check_if_not_in_black_and_white]:%d\n", 5); + return true; + } + //printf("\n[check_if_not_in_black_and_white]:%d\n", 6); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + int l_black_len = db_get_record_counts_check_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance); + //printf("\n[check_if_not_in_black_and_white]:%d\n", 3); + int l_white_len = db_get_record_counts_check_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance); + int l_log_record_cnts = l_black_len + l_white_len; + //printf("\n[check_if_not_in_black_and_white]:%d\n", 4); + //printf("\nAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\n%d\n", l_log_record_cnts); + //printf("\nBBBBBBBBBBBBBBBBBBBB\n"); + + if (l_log_record_cnts == 0) { + //printf("\n[check_if_not_in_black_and_white]:%d\n", 5); + return true; + } + //printf("\n[check_if_not_in_black_and_white]:%d\n", 6); + } + else { + int l_black_len = db_get_record_counts_check_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance); + //printf("\n[check_if_not_in_black_and_white]:%d\n", 3); + int l_white_len = db_get_record_counts_check_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance); + int l_log_record_cnts = l_black_len + l_white_len; + //printf("\n[check_if_not_in_black_and_white]:%d\n", 4); + //printf("\nAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\n%d\n", l_log_record_cnts); + //printf("\nBBBBBBBBBBBBBBBBBBBB\n"); + + if (l_log_record_cnts == 0) { + //printf("\n[check_if_not_in_black_and_white]:%d\n", 5); + return true; + } + //printf("\n[check_if_not_in_black_and_white]:%d\n", 6); + } + return false; +} + +int db_get_record_counts_check_ff_face(sqlite3 *pdb, char *table_name ,char *ff_lpr_to_check) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_lpr = '%s';", table_name,ff_lpr_to_check); + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(levenshtein(ff_lpr)) FROM %s;", table_name); + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(levenshtein(ff_lpr,'%s',1)) FROM %s;", table_name, ff_lpr_to_check); + //sqlite3_extension_init(pdb, NULL, NULL); + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_face_name = '%s';", table_name, ff_lpr_to_check); + + //.load /emmc/plugin/Aida_data/lib/liblevenshtein.so\n + //snprintf(sql_buf, sizeof(sql_buf), "SELECT levenshtein('New-York', 'Paris')"); + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + //printf("\n-----------hello\n"); + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + else { + //printf("\n[db get record counts check ff lpr] Error:%d\n", l_ret); + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); + return nRows; +} + + + +bool check_if_in_black_face(char *ff_lpr_to_check) { + // printf("\n[check_if_in_black]:%d\n", 1); + { + int l_black_len = db_get_record_counts_check_ff_face(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check); + + if (l_black_len >= 1) { + return true; + } + } + return false; +} + +bool check_if_in_white_face(char *ff_lpr_to_check) { + // printf("\n[check_if_in_white]:%d\n", 1); + { + int l_white_len = db_get_record_counts_check_ff_face(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check); + + if (l_white_len >= 1) { + return true; + } + } + return false; +} + +bool get_schedule_start_in_black_face(char *ff_lpr_to_check, char *in_other_to_check,char *l_schedule_start, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_start_where_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + db_get_schedule_start_where_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_black]:%d\n", 1); + db_get_schedule_start_where_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_start) >= 1) + return true; + else + return false; +} + +bool get_schedule_start_in_white_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_start, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_start_where_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + db_get_schedule_start_where_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_white]:%d\n", 1); + db_get_schedule_start_where_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_start) >= 1) + return true; + else + return false; +} + +bool get_schedule_end_in_black_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_end_where_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + db_get_schedule_end_where_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_black]:%d\n", 1); + db_get_schedule_end_where_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_end) >= 1) + return true; + else + return false; +} + +bool get_schedule_end_in_white_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_end_where_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + db_get_schedule_end_where_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_white]:%d\n", 1); + db_get_schedule_end_where_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_end) >= 1) + return true; + else + return false; +} + +bool get_detect_endtime_in_black_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_detect_endtime_where_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + db_get_detect_endtime_where_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else { + //printf("\n[get_detect_endtime_in_black]:%d\n", 1); + db_get_detect_endtime_where_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + //printf("\n--------------------l_detect_endtime \n"); + } + + if (strlen(l_detect_endtime) >= 1) + return true; + else + return false; +} + +bool get_detect_endtime_in_white_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_detect_endtime_where_in_other_and_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0) { + db_get_detect_endtime_where_ff_lpr_upper(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else { + //printf("\n[get_detect_endtime_in_white]:%d\n", 1); + db_get_detect_endtime_where_ff_lpr(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + //printf("\n--------------------l_detect_endtime \n"); + } + + if (strlen(l_detect_endtime) >= 1) + return true; + else + return false; +} + +int cgi_download_facedb_list_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount) // change variable name done but called db_get_face_record not changed +{ + time_t face_now_time; + + struct tm *face_log_tm = NULL; + char face_log_time_fmt[64] = {0}; + char face_log_filename[64] = {0}; + char face_log_cgi_res[512] = {0}; + char face_log_cgi_res_2[4096] = { 0 }; + char face_sql_tb[20] = {0}; + //int l_result = 0; + int l_db_length=0; + face_now_time = time(NULL); + int l_Max_downloadListcount = COUNT_WHITE+COUNT_BLACK-200; + unsigned char header[3] = {(unsigned char)0xEF, (unsigned char)0xBB, (unsigned char)0xBF}; +#define downloadLPRFile "listinfo.csv" + FILE *fd = NULL; + + face_log_tm = localtime(&face_now_time); + strftime(face_log_time_fmt, sizeof(face_log_time_fmt)-1, "%Y%m%d%H%M%S", face_log_tm); + + snprintf(face_log_filename, sizeof(face_log_time_fmt)-1, "%sinfo.csv","list"); + char l_lprmsg_path[36]={0}; + sprintf(l_lprmsg_path,"/tmp/%s",downloadLPRFile); + char l_list_cmd1[64]={0}; + sprintf(l_list_cmd1,"%s/%s","rm /tmp",downloadLPRFile); + system(l_list_cmd1); + + + if (!(fd = fopen(l_lprmsg_path, "wb,css=utf-8"))) + { + printf( "create %s failure\n",l_lprmsg_path); + if (fd) + fclose(fd); + } + + snprintf(face_log_cgi_res ,sizeof(face_log_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Date: Tue, 27 Dec 2011 09:25:53 GMT\r\n" + "Accept-Ranges: bytes\r\n" + "Connection: close\r\n" + "Content-type: text/html;charset=UTF-8\r\n" + "Content-Disposition: attachment;filename=%s\r\n" + "\r\n", face_log_filename); + + sprintf(face_sql_tb,"%s",log_sql_tb); + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_db_tb l_db_tb_info; + memset(&l_db_tb_info,0,sizeof(facegroup_db_tb)); + char l_sql[2048] = {0}; + int l_idx = 0; + int l_log_record_cnts = 0; + int l_black_len=0; + int l_white_len=0; + int l_rc; + + if (send(socket_in, face_log_cgi_res, strlen(face_log_cgi_res), MSG_MORE) == -1) + printf("\nsend error #8\n"); + + snprintf(l_sql, sizeof(l_sql)-1, CMD_FACE_UNION_TABLE,l_Max_downloadListcount); + l_black_len=db_get_record_counts(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE); + l_white_len=db_get_record_counts(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE); + l_log_record_cnts = l_black_len+l_white_len; + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s\n", l_sql); + + l_idx = -1; + } + else + { + if(l_log_record_cnts>=log_icount) + l_db_length=log_icount; + else + l_db_length=l_log_record_cnts; + + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + char l_act_param[10]={0}; + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_tb_info); + trans_download_face_type(l_act_param,l_db_tb_info.ACT_PARAM); + if(fd) + { + fprintf (fd, + "%s," + "%s," + "%s," + "%s," + "%s," + "%s," + "%s\r\n", + l_db_tb_info.user_name, + l_db_tb_info.last_name, + l_db_tb_info.IN_SCHEDULE_START, + l_db_tb_info.IN_SCHEDULE_END, + l_db_tb_info.IN_OTHER, + l_db_tb_info.ACT_PARAM, + l_db_tb_info.LP_BMP); + + } + if(l_idx==0) + { + if (send(socket_in, header, strlen((char *)header), MSG_MORE) == -1) + printf("\nsend error #9\n"); + } + + // snprintf(face_log_cgi_res_2,sizeof(face_log_cgi_res_2)-1, + // "%s,%s,%s,%s,%s,%s,%s\r\n", + // l_db_tb_info.user_name, + // l_db_tb_info.last_name, + // l_db_tb_info.IN_SCHEDULE_START, + // l_db_tb_info.IN_SCHEDULE_END, + // l_db_tb_info.IN_OTHER, + // l_db_tb_info.ACT_PARAM, + // l_db_tb_info.LP_BMP); + + snprintf(face_log_cgi_res_2,sizeof(face_log_cgi_res_2)-1, + "%s," + "%s," + "%s," + "%s," + "%s," + "%s," + "%s\r\n", + l_db_tb_info.user_name, + l_db_tb_info.last_name, + l_db_tb_info.IN_SCHEDULE_START, + l_db_tb_info.IN_SCHEDULE_END, + l_db_tb_info.IN_OTHER, + l_db_tb_info.ACT_PARAM, + l_db_tb_info.LP_BMP); + + + if (send(socket_in, face_log_cgi_res_2, strlen(face_log_cgi_res_2), MSG_MORE) == -1) + printf("\nsend error #10\n"); + + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + + db_free_sql_stmt(g_facegroup_db_info.pstmt); + } + //l_result = l_idx; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + if (fd) + fclose(fd); + + char l_list_cmd[64]={0}; + sprintf(l_list_cmd,"%s/%s","chmod 755 /tmp",downloadLPRFile); + system(l_list_cmd); + + return 0; +} + +int cgi_download_facedb_log_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount) // change variable name done but not sure what the db does +{ + time_t face_now_time; + struct tm *face_log_tm = NULL; + char face_log_time_fmt[64] = {0}; + char face_log_filename[64] = {0}; + char face_log_cgi_res[512] = {0}; + char face_sql_tb[20] = {0}; + //int l_result = 0; + int l_db_length=0; + face_now_time = time(NULL); + + face_log_tm = localtime(&face_now_time); + strftime(face_log_time_fmt, sizeof(face_log_time_fmt)-1, "%Y%m%d%H%M%S", face_log_tm); + + snprintf(face_log_filename, sizeof(face_log_time_fmt)-1, "%sinfo.csv",log_type); + + + snprintf(face_log_cgi_res ,sizeof(face_log_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Date: Tue, 27 Dec 2011 09:25:53 GMT\r\n" + "Accept-Ranges: bytes\r\n" + "Connection: close\r\n" + "Content-type: text/html;charset=UTF-8;\r\n" + "Content-Disposition: attachment; filename=%s\r\n" + "\r\n", face_log_filename); + + sprintf(face_sql_tb,"%s",log_sql_tb); + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_db_tb l_db_tb_info; + memset(&l_db_tb_info,0,sizeof(facegroup_db_tb)); + char l_sql[512] = {0}; + int l_idx = 0; + int l_log_record_cnts = 0; + int l_rc; + + if (send(socket_in, face_log_cgi_res, strlen(face_log_cgi_res), MSG_MORE) == -1) + { + printf("\nsend error #11\n"); + } + if(strcmp(face_sql_tb,FACE_MSG_TABLE)==0 ||strcmp(face_sql_tb,FACE_MSG_CUSTOMERTABLE)==0) + { + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;",FACE_MSG_TABLE ,log_icount); + l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, FACE_MSG_TABLE); + } + else + { + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;",log_sql_tb ,log_icount); + l_log_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, log_sql_tb); + } + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s\n", l_sql); + + l_idx = -1; + } + else + { + if(l_log_record_cnts>=log_icount) + l_db_length=log_icount; + else + l_db_length=l_log_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_tb_info); + + memset(face_log_cgi_res, 0, sizeof(face_log_cgi_res)); + snprintf(face_log_cgi_res ,sizeof(face_log_cgi_res)-1, + "%s, " + //"%s, " + "%s\r\n", + l_db_tb_info.ACT_PARAM, + l_db_tb_info.MOD_TS + //, l_db_tb_info.LPR + ); + if (send(socket_in, face_log_cgi_res, strlen(face_log_cgi_res), MSG_MORE) == -1) + printf("\nsend error #12\n"); + + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + } + + //l_result = l_idx; + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + } + } + + return 0; +} +#if 0 +void GetValidVar_TO_SetValue(webs_t wp,char *chk_text,char *local_val,char *print_val) +{ + if(GetValidVar(wp,chk_text,local_val)) + { + sprintf(print_val,"%s",local_val); + //PDEBUG("%s:%s\n",chk_text,local_val); + } +} +#endif +int cgi_set_map_db_face(SOCKET socket_in, char *plist, int icount, char *itype) // change so variable name and with the db +{ + char type_name[16] = {0}; + char l_lpr_cgi_res[256]={0}; + snprintf(l_lpr_cgi_res , sizeof(l_lpr_cgi_res)-1, "HTTP/1.0 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + char in_det_plate[128] = {0}; + char in_plate[128] = {0}; + char in_oplate[5000] = {0}; + int l_result=1; + const char *del_value = ":"; + + getvalueForKey(plist,"lpr_map_det_plate",in_det_plate); + getvalueForKey(plist,"lpr_map_plate",in_plate); + getvalueForKey(plist,"lpr_map_oplate",in_oplate); + + //PDEBUG("plist:%s\n",plist); + char *end = strstr(plist, "&"); + if(end != NULL) + { + memcpy(type_name, plist, strlen(plist) - strlen(end)); + } + + printf("\ntype name = %s \n", type_name); + + if(icount==1) + { + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + sqlite_facegroup_update_map_list( in_det_plate,in_plate,in_oplate ,plist); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + sqlite_facegroup_add_map_list( in_det_plate,in_plate, type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + int l_ret =sqlite_facegroup_del_map(in_oplate, type_name,icount-1,icount); + if(l_ret) + { + l_result=0; + + } + } + } + else + { + + char str_det_plate[icount + 1][STRSPLIT_SIZE]; + char str_plate[icount + 1][STRSPLIT_SIZE]; + char str_oplate[icount + 1][STRSPLIT_SIZE]; + + StrSplit(in_det_plate, str_det_plate, del_value); + StrSplit(in_plate, str_plate, del_value); + StrSplit(in_oplate, str_oplate, del_value); + + int j=0; + int db_index=0; + while(j < icount) + { + db_index=j++; + + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + + sqlite_facegroup_update_map_list( *(str_det_plate+db_index), *(str_plate+db_index) , *(str_oplate+db_index),type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + + sqlite_facegroup_add_map_list( *(str_det_plate+db_index), *(str_plate+db_index) ,type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + int l_ret =sqlite_facegroup_del_map(*(str_oplate+db_index), type_name,db_index,icount); + if(l_ret) + { + l_result=0; + } + } + } + } + if(!l_result) + { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + char tmpStr[BUFSIZE] = {0}; + strcat(beforeSendBuffer, "<lprinfo>\r\n"); + sprintf(tmpStr," <lpr_res>%d</lpr_res>\r\n",l_result); + strcat(beforeSendBuffer, tmpStr); + strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #13\n"); + l_result=1; + } + return 0; +} + +int cgi_set_db_face(SOCKET socket_in, char *plist, int icount, char *itype) // change so variable name and with the db +{ + char type_name[16] = {0}; + + const char *del_value = ":"; + int iIsCopyFromLogTB = 0; + + //=====insert date======== + + char i_user[64*6+1] = {0}; + char i_plate[128] = {0}; + char i_oplate[5000] = {0}; + char i_phone[128] = {0}; + char i_address[1024] = {0}; + char i_paystatus[128] = {0}; + char i_exist[128] = {0}; + char i_schedule_s[128] = {0}; + char i_schedule_e[128] = {0}; + char i_other[64*6+1] = {0}; + char i_detect_endtime[128] = {0}; + int l_result=1; + + + char i_face_name[128] = {0}; + char i_user_name[128] = {0}; + char i_face_full_name[256] = {0}; + char i_face_first_name[128] = {0}; + char i_face_last_name[128] = {0}; + char i_face_address[1024] = {0}; + char i_face_mod_ts[256] = { 0 }; + char i_face_ts_date[256] = { 0 }; + char i_face_ts_time[256] = { 0 }; + + char i_copy_from_log_tb[10] = { 0 }; + + + getvalueForKey(plist,"lpr_user",i_user); //last name + getvalueForKey(plist,"lpr_plate",i_plate); + //getvalueForKey(plist,"lpr_oplate",i_oplate); + getvalueForKey(plist, "face_name", i_oplate); + getvalueForKey(plist,"lpr_phone",i_phone); + getvalueForKey(plist,"lpr_address",i_address); + getvalueForKey(plist,"lpr_paystatus",i_paystatus); + getvalueForKey(plist,"lpr_exist",i_exist); + getvalueForKey(plist,"lpr_schedule_s",i_schedule_s); + getvalueForKey(plist,"lpr_schedule_e",i_schedule_e); + getvalueForKey(plist,"lpr_other",i_other); + getvalueForKey(plist,"lpr_detect_endtime",i_detect_endtime); + + //printf("\n---------i_schedule_s:%s,i_schedule_e:%s,i_detect_endtime:%s\n", i_schedule_s, i_schedule_e, i_detect_endtime); + + getvalueForKey(plist, "face_name", i_face_name); //uuid + getvalueForKey(plist, "user_name", i_user_name); //last name + getvalueForKey(plist, "face_first_name", i_face_first_name); //first name + getvalueForKey(plist, "face_last_name", i_face_last_name); //last name = "user_name" + getvalueForKey(plist, "face_address", i_face_address); + + //getvalueForKey(plist, "face_mod_ts", i_face_mod_ts); + getvalueForKey(plist, "date", i_face_ts_date); + getvalueForKey(plist, "time", i_face_ts_time); + + sprintf(i_face_mod_ts, "%s %s", i_face_ts_date, i_face_ts_time); + printf("i_face_mod_ts = %s \n", i_face_mod_ts); + + getvalueForKey(plist, "copy_log", i_copy_from_log_tb); + + if (strlen(i_copy_from_log_tb) == 1) + iIsCopyFromLogTB = atoi(i_copy_from_log_tb); + + + snprintf(i_face_full_name, sizeof(i_face_full_name), "%s, %s", i_face_first_name, i_face_last_name); + + + printf("[cgi_set_db_face] i_face_name:%s, user_name:%s, oPlate:%s, first:%s, last:%s, full:%s, address:%s\n",i_face_name,i_user_name, i_oplate, i_face_first_name,i_face_last_name,i_face_full_name,i_face_address); + + + printf("XXX \n"); + + + //PDEBUG("plist:%s\n",plist); + char *end = strstr(plist, "&"); + if(end != NULL) + { + memcpy(type_name, plist, strlen(plist) - strlen(end)); + } + + //printf("\nplist = \n%s\n", plist); + //printf("\nend = \n%s\n", end); + //printf("\n type_name = %s, cutlen = %d \n", type_name, strlen(plist) - strlen(end)); + + //FACE_MSG_BLACKTABLE + if (icount == 99999) + { + ///no use + printf("DELETE ALL TABLE \n"); + sqlite_facegroup_delete_all_records(type_name); + l_result = 0; + } + else if(icount==1) + { + printf("icount = 1 \n"); + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + printf("UPDATE LIST \n"); + //printf("XXX \n"); + sqlite_facegroup_updateInfo_list( i_plate, i_face_first_name, i_user, i_phone, i_address, i_paystatus, i_exist, i_schedule_s,i_schedule_e, i_other,i_detect_endtime, type_name, i_face_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + // sqlite_facegroup_add_list(i_plate, i_user, i_phone,i_address, i_paystatus,i_exist, i_schedule_s,i_schedule_e, i_other ,i_detect_endtime,type_name); + printf("ADD LIST \n"); + + char l_compare_str[16] = {0}; + char l_compare_str1[16] = {0}; + // char type_str[16] = {0}; + // char type_str1[16] = {0}; + + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s",BKLISTNAME_FACE); + memset(l_compare_str1, 0, sizeof(l_compare_str1)); + sprintf(l_compare_str1,"%s",WTLISTNAME_FACE); + if(strncmp(type_name,l_compare_str,strlen(l_compare_str))==0){ + //add into black list/ watch list + printf("[cgi_set_db_face] add into black list/ watch list\n"); + sprintf(l_compare_str,"%s",BKLISTNAME_FACE); + sprintf(l_compare_str1,"%s",WTLISTNAME_FACE); + } + else if (strncmp(type_name, l_compare_str1, strlen(l_compare_str1)) == 0) { + // add into white list/ vip list + printf("[cgi_set_db_face] add into white list/ vip list\n"); + sprintf(l_compare_str,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str1,"%s",BKLISTNAME_FACE); + } + else { + printf("[cgi_set_db_face] add into white list/ vip list else \n"); + sprintf(l_compare_str,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str1,"%s",BKLISTNAME_FACE); + } + + if (iIsCopyFromLogTB == 1) + { + //printf("uuid: %s, mod_ts: %s \n", i_oplate, i_face_mod_ts); + + sqlite_facegroup_add_from_table(i_oplate, i_face_mod_ts, l_compare_str); + } + else + { + //sqlite_facegroup_add_face_list(i_face_name,i_face_full_name,"","","","",i_address,i_other,l_compare_str); + sqlite_facegroup_add_face_list(i_face_name, i_face_first_name, i_face_last_name, "", "", "", "", i_address, i_other, l_compare_str, i_schedule_s, i_schedule_e, i_detect_endtime); + + sqlite_facegroup_delte_face_list(i_face_name, l_compare_str1,icount-1,icount); + } + + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + //printf("[black list]delete 000\n"); + int l_ret =sqlite_facegroup_del(i_face_name, type_name,icount-1,icount); + if(l_ret) + { + l_result=0; + + } + } + } + else + { + printf("icount = %d \n", icount); + char str_user[icount + 1][STRSPLIT_SIZE]; + char str_first_name[icount + 1][STRSPLIT_SIZE]; + char str_plate[icount + 1][STRSPLIT_SIZE]; + char str_oplate[icount + 1][STRSPLIT_SIZE]; + char str_phone[icount + 1][STRSPLIT_SIZE]; + char str_address[icount + 1][STRSPLIT_SIZE]; + char str_paystatus[icount + 1][STRSPLIT_SIZE]; + char str_exist[icount + 1][STRSPLIT_SIZE]; + char str_schedule_s[icount + 1][STRSPLIT_SIZE]; + char str_schedule_e[icount + 1][STRSPLIT_SIZE]; + char str_other[icount + 1][STRSPLIT_SIZE]; + char str_detect_endtime[icount + 1][STRSPLIT_SIZE]; + char str_face_name[icount + 1][STRSPLIT_SIZE]; + + StrSplit(i_user, str_user, del_value); + StrSplit(i_face_first_name, str_first_name, del_value); + StrSplit(i_plate, str_plate, del_value); + StrSplit(i_oplate, str_oplate, del_value); + StrSplit(i_phone, str_phone, del_value); + StrSplit(i_address, str_address, del_value); + StrSplit(i_paystatus, str_paystatus, del_value); + StrSplit(i_exist, str_exist, del_value); + StrSplit(i_schedule_s, str_schedule_s, del_value); + StrSplit(i_schedule_e, str_schedule_e, del_value); + StrSplit(i_other, str_other, del_value); + StrSplit(i_detect_endtime, str_detect_endtime, del_value); + StrSplit(i_face_name, str_face_name, del_value); + + + int j=0; + int db_index=0; + while(j < icount) + { + db_index=j++; + + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + + sqlite_facegroup_updateInfo_list( *(str_plate+db_index), *(str_first_name + db_index), *(str_user+db_index), *(str_phone+db_index), *(str_address+db_index), *(str_paystatus+db_index), + *(str_exist+db_index), *(str_schedule_s+db_index), *(str_schedule_e+db_index), *(str_other+db_index),*(str_detect_endtime+db_index), type_name, i_face_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + + sqlite_facegroup_add_list( *(str_plate+db_index), *(str_user+db_index), *(str_phone+db_index),*(str_address+db_index), *(str_paystatus+db_index),*(str_exist+db_index), + *(str_schedule_s+db_index), *(str_schedule_e+db_index), *(str_other+db_index) ,*(str_detect_endtime+db_index) ,type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + //printf("*(str_oplate+a:%d):%s\n",db_index,*(str_oplate+db_index)); + //printf("icount:%d\n",icount); + int l_ret =sqlite_facegroup_del(*(str_face_name +db_index), type_name,db_index,icount); + if(l_ret) + { + //printf("1let:%d\n",l_ret); + //usSleep(10000); + l_result=0; + + //printf("2let:%d\n",l_ret); + } + } + } + } + + + if(!l_result) + { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE] = { 0 }; + + strcpy(beforeSendBuffer,"OK"); + + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //char tmpStr[BUFSIZE] = {0}; + //strcat(beforeSendBuffer, "<lprinfo>\r\n"); + //sprintf(tmpStr," <lpr_res>%d</lpr_res>\r\n",l_result); + //strcat(beforeSendBuffer, tmpStr); + //strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + + //printf("\n-------sendBuffer:%s\n", sendBuffer); + + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #14\n"); + l_result=1; + } + else { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE] = { 0 }; + + strcpy(beforeSendBuffer, "Fail"); + + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //char tmpStr[BUFSIZE] = { 0 }; + //strcat(beforeSendBuffer, "<lprinfo>\r\n"); + //sprintf(tmpStr, " <lpr_res>%d</lpr_res>\r\n", l_result); + //strcat(beforeSendBuffer, tmpStr); + //strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + + //printf("\n-------sendBuffer:%s\n", sendBuffer); + + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #142\n"); + } + + return 0; +} + + +int cgi_set_db_face_customer(SOCKET socket_in, char *plist, int icount, char *itype) // change so variable name and with the db +{ + char type_name[16] = { 0 }; + + const char *del_value = ":"; + const char *del_value2 = ";"; + + //=====insert date======== + + char i_first_name[64 * 6 + 1] = { 0 }; + char i_user[64 * 6 + 1] = { 0 }; + char i_plate[128] = { 0 }; + char i_oplate[5000] = { 0 }; + char i_phone[128] = { 0 }; + char i_address[1024] = { 0 }; + char i_paystatus[128] = { 0 }; + char i_exist[128] = { 0 }; + char i_schedule_s[128] = { 0 }; + char i_schedule_e[128] = { 0 }; + char i_other[64 * 6 + 1] = { 0 }; + char i_detect_endtime[128] = { 0 }; + int l_result = 1; + + char i_face_name[128] = { 0 }; + + char delete_mod_ts[5000] = { 0 }; + + + getvalueForKey(plist, "face_first_name", i_first_name); + getvalueForKey(plist, "lpr_user", i_user); + getvalueForKey(plist, "lpr_plate", i_plate); + //getvalueForKey(plist, "lpr_oplate", i_oplate); + getvalueForKey(plist, "face_name", i_oplate); + getvalueForKey(plist, "lpr_phone", i_phone); + getvalueForKey(plist, "lpr_address", i_address); + getvalueForKey(plist, "lpr_paystatus", i_paystatus); + getvalueForKey(plist, "lpr_exist", i_exist); + getvalueForKey(plist, "lpr_schedule_s", i_schedule_s); + getvalueForKey(plist, "lpr_schedule_e", i_schedule_e); + getvalueForKey(plist, "lpr_other", i_other); + getvalueForKey(plist, "lpr_detect_endtime", i_detect_endtime); + getvalueForKey(plist, "face_name", i_face_name); + + getvalueForKey(plist, "lpr_time", delete_mod_ts); + + //PDEBUG("plist:%s\n",plist); + char *end = strstr(plist, "&"); + if (end != NULL) + { + memcpy(type_name, plist, strlen(plist) - strlen(end)); + } + + printf("\nplist = \n%s\n", plist); + printf("\nend = \n%s\n", end); + printf("\n type_name = %s, cutlen = %d \n", type_name, strlen(plist) - strlen(end)); + + //FACE_MSG_BLACKTABLE + if (icount == 99999) + { + printf("DELETE ALL TABLE \n"); + sqlite_facegroup_delete_all_records(type_name); + l_result = 0; + } + else if (icount == 1) + { + if (strcmp(itype, SETTYPE_UPDATE) == 0) + { + sqlite_facegroup_updateInfo_list(i_plate, i_first_name, i_user, i_phone, i_address, i_paystatus, i_exist, i_schedule_s, i_schedule_e, i_other, i_detect_endtime, type_name, i_face_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_ADD) == 0) + { + sqlite_facegroup_add_list(i_plate, i_user, i_phone, i_address, i_paystatus, i_exist, i_schedule_s, i_schedule_e, i_other, i_detect_endtime, type_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_DELETE) == 0) + { + //int l_ret = sqlite_facegroup_del_time(delete_mod_ts, type_name, icount - 1, icount); + int l_ret = sqlite_facegroup_del_user_name(i_face_name, type_name, icount - 1, icount); + if (l_ret) + { + l_result = 0; + + } + } + } + else + { + char str_first_name[icount + 1][STRSPLIT_SIZE]; + char str_user[icount + 1][STRSPLIT_SIZE]; + char str_plate[icount + 1][STRSPLIT_SIZE]; + char str_oplate[icount + 1][STRSPLIT_SIZE]; + char str_phone[icount + 1][STRSPLIT_SIZE]; + char str_address[icount + 1][STRSPLIT_SIZE]; + char str_paystatus[icount + 1][STRSPLIT_SIZE]; + char str_exist[icount + 1][STRSPLIT_SIZE]; + char str_schedule_s[icount + 1][STRSPLIT_SIZE]; + char str_schedule_e[icount + 1][STRSPLIT_SIZE]; + char str_other[icount + 1][STRSPLIT_SIZE]; + char str_detect_endtime[icount + 1][STRSPLIT_SIZE]; + + char str_delete_mod_ts[icount + 1][STRSPLIT_SIZE]; + char str_face_name[icount + 1][STRSPLIT_SIZE]; + // + StrSplit(i_first_name, str_first_name, del_value); + StrSplit(i_user, str_user, del_value); + StrSplit(i_plate, str_plate, del_value); + StrSplit(i_oplate, str_oplate, del_value); + StrSplit(i_phone, str_phone, del_value); + StrSplit(i_address, str_address, del_value); + StrSplit(i_paystatus, str_paystatus, del_value); + StrSplit(i_exist, str_exist, del_value); + StrSplit(i_schedule_s, str_schedule_s, del_value); + StrSplit(i_schedule_e, str_schedule_e, del_value); + StrSplit(i_other, str_other, del_value); + StrSplit(i_detect_endtime, str_detect_endtime, del_value); + + StrSplit(delete_mod_ts, str_delete_mod_ts, del_value2); + StrSplit(i_face_name, str_face_name, del_value); + + + int j = 0; + int db_index = 0; + while (j < icount) + { + db_index = j++; + + if (strcmp(itype, SETTYPE_UPDATE) == 0) + { + + sqlite_facegroup_updateInfo_list(*(str_plate + db_index), *(str_first_name + db_index), *(str_user + db_index), *(str_phone + db_index), *(str_address + db_index), *(str_paystatus + db_index), + *(str_exist + db_index), *(str_schedule_s + db_index), *(str_schedule_e + db_index), *(str_other + db_index), *(str_detect_endtime + db_index), type_name, i_face_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_ADD) == 0) + { + + sqlite_facegroup_add_list(*(str_plate + db_index), *(str_user + db_index), *(str_phone + db_index), *(str_address + db_index), *(str_paystatus + db_index), *(str_exist + db_index), + *(str_schedule_s + db_index), *(str_schedule_e + db_index), *(str_other + db_index), *(str_detect_endtime + db_index), type_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_DELETE) == 0) + { + //printf("*(str_oplate+a:%d):%s\n",db_index,*(str_oplate+db_index)); + //printf("icount:%d\n",icount); + //int l_ret = sqlite_facegroup_del_time(*(str_delete_mod_ts + db_index), type_name, db_index, icount); + int l_ret = sqlite_facegroup_del_user_name(*(str_oplate + db_index), type_name, db_index, icount); + if (l_ret) + { + //printf("1let:%d\n",l_ret); + //usSleep(10000); + l_result = 0; + + //printf("2let:%d\n",l_ret); + } + } + } + } + + + if (!l_result) + { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + char tmpStr[BUFSIZE] = { 0 }; + strcat(beforeSendBuffer, "<lprinfo>\r\n"); + sprintf(tmpStr, " <lpr_res>%d</lpr_res>\r\n", l_result); + strcat(beforeSendBuffer, tmpStr); + strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #14-2\n"); + l_result = 1; + } + return 0; +} + +int cgi_set_face_clean(SOCKET socket_in, char *icmd) // change so variable name and with the db +{ + int l_sql_ret = 0; + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + facedb_mutex_lock(g_facegroup_db_info.pdb); + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, icmd); + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, icmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + if(!l_sql_ret) + { + strcat(beforeSendBuffer, "clean ok"); + } + else + { + strcat(beforeSendBuffer, "clean fail"); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #15\n"); + + return l_sql_ret; +} +#if 0 +int cgi_set_restart_detect(webs_t wp) +{ + char l_lpr_cgi_res[256]={0}; + snprintf(l_lpr_cgi_res , sizeof(l_lpr_cgi_res)-1, "HTTP/1.0 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + system("/usr/bin/killall -9 fflpr2"); + usSleep(1000000);//1s + fcntl(fileno(wp), F_SETFD, FD_CLOEXEC); + system("/www/ffgroup_lpr.sh &"); + usSleep(300000);//0.3s + + websWrite (wp, "%s","restart ok"); + return 0; +} + +/* + --- set_search_info --- + 1.delete list + 2.update list + 3.add list + 4.import list (X) + + 1.1 delete list (One) + *Black -> set_search_info?delete=black&count=1&lpr_oplate=BLACKABC + *White -> set_search_info?delete=white&count=1&lpr_oplate=WHITEABC + *Customer -> set_search_info?delete=visitor&count=1&lpr_oplate=CUSTOMERABC + + 1.2 delete list (Multi) + *Black -> set_search_info?delete=black&count=3&lpr_oplate=BLACKAB1:BLACKAB2:BLACKAB3 + *White -> set_search_info?delete=white&count=3&lpr_oplate=WHITEAB1:WHITEAB2:WHITEAB3 + *Customer -> set_search_info?delete=visitor&count=3&lpr_oplate=CUSTOMERAB1:CUSTOMERAB2:CUSTOMERAB3 + + 2.1 update list(One) + *Black -> set_search_info?update=black&count=1&lpr_plate=NBLACKABC&lpr_oplate=BLACKABC&lpr_user=BLACK + &lpr_phone=123456789 + &lpr_address=NEW TAIPE No.20&lpr_paystatus=1&lpr_exist=&lpr_schedule=&lpr_other= + *White -> set_search_info?update=white&count=1&lpr_plate=NWHITEABC&lpr_oplate=WHITEABC&lpr_user=WHITE + &lpr_phone=123456789 + &lpr_address=NEW TAIPE No.20&lpr_paystatus=1&lpr_exist=&lpr_schedule=&lpr_other= + 2.2 update list(Multi) + +*/ +#endif + +//cgi_set_search_info_face +int cgi_set_search_info_face(SOCKET socket_in, char *path) //(^V) change so variable name and with the db +{ + char l_lpr_cgi_param[BUFSIZE] = {0}; + char l_count[32] = {0}; + //char l_action_lpr[16] = {0}; + char l_compare_str[16] = {0}; + char l_compare_str2[16] = {0}; + char l_compare_str3[16] = {0}; + char l_compare_str4[16] = {0}; + char l_compare_str5[16] = {0}; + + //delete information + //printf("\n[cgi_set_search_info_face]path:%s\n",path); + + sprintf(l_compare_str,"%s=",SETTYPE_DELETE); //SETTYPE_DELETE = "delete" + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s",CUSTLISTNAME_FACE); + sprintf(l_compare_str2,"%s",BKLISTNAME_FACE); + sprintf(l_compare_str3,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + sprintf(l_compare_str5, "%s", LOGLISTNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str,strlen(l_compare_str))==0) + { + printf("\n[cgi_set_search_info]delete visitor\n"); + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_face_customer(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + printf("[Black list] delete 2: count = %d \n", atoi(l_count)); + + if(strlen(l_count)!=0) + { + cgi_set_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_map_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + return 0; + } + + //add information + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s=",SETTYPE_ADD); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_compare_str2, 0, sizeof(l_compare_str2)); + memset(l_compare_str3, 0, sizeof(l_compare_str3)); + memset(l_compare_str4, 0, sizeof(l_compare_str4)); + sprintf(l_compare_str,"%s",CUSTLISTNAME_FACE); + sprintf(l_compare_str2,"%s",BKLISTNAME_FACE); + sprintf(l_compare_str3,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_ADD); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_ADD); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_map_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_ADD); + } + } + } + //FACE_MSG_BLACKTABLE + + //update information + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s=",SETTYPE_UPDATE); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_compare_str2, 0, sizeof(l_compare_str2)); + memset(l_compare_str3, 0, sizeof(l_compare_str3)); + memset(l_compare_str4, 0, sizeof(l_compare_str4)); + sprintf(l_compare_str,"%s",CONFIGLISTNAME); + sprintf(l_compare_str2,"%s",BKLISTNAME_FACE); + sprintf(l_compare_str3,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_UPDATE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_UPDATE); + } + } +#if 0 + else if(strncmp(l_lpr_cgi_param,l_compare_str,strlen(l_compare_str))==0)//update=config + { + set_license_config(wp); + } +#endif + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"count"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_map_db_face(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_UPDATE); + } + } + } + + //clean all data + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s=",SETTYPE_CLEAN); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + char l_sql_cmd[128]={0}; + char l_sql_tbname[20]={0}; + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_compare_str2, 0, sizeof(l_compare_str2)); + memset(l_compare_str3, 0, sizeof(l_compare_str3)); + memset(l_compare_str4, 0, sizeof(l_compare_str4)); + sprintf(l_compare_str,"%s",CUSTLISTNAME_FACE); + sprintf(l_compare_str2,"%s",BKLISTNAME_FACE); + sprintf(l_compare_str3,"%s",WTLISTNAME_FACE); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + sprintf(l_compare_str5,"%s",LOGLISTNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + chk_sql_msg_tbname_face(l_sql_tbname,BKLISTNAME_FACE); + sprintf(l_sql_cmd,CMD_CLEAN_FACE_MSG_TABLE,l_sql_tbname); + cgi_set_face_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + chk_sql_msg_tbname_face(l_sql_tbname,WTLISTNAME_FACE); + sprintf(l_sql_cmd,CMD_CLEAN_FACE_MSG_TABLE,l_sql_tbname); + cgi_set_face_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str,strlen(l_compare_str))==0) + { + chk_sql_msg_tbname_face(l_sql_tbname,CUSTLISTNAME_FACE); + sprintf(l_sql_cmd,CMD_CLEAN_FACE_MSG_TABLE,l_sql_tbname); + cgi_set_face_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str5,strlen(l_compare_str5))==0) + { + chk_sql_msg_tbname_face(l_sql_tbname,LOGLISTNAME); + //char l_event_cmd[64]={0}; + //sprintf(l_event_cmd,"chmod 755 %s",FILEPATH_EVENTS_DB); + //system(l_event_cmd); + //char l_clean_cmd[64]={0}; + //sprintf(l_clean_cmd,"timeout 10s rm -rf %s",FILEPATH_EVENTS_DB); + //system(l_clean_cmd); + sprintf(l_sql_cmd,CMD_CLEAN_FACE_MSG_TABLE,l_sql_tbname); + cgi_set_face_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + chk_sql_msg_tbname_face(l_sql_tbname,MAPPINGNAME); + sprintf(l_sql_cmd,CMD_CLEAN_FACE_MSG_TABLE,l_sql_tbname); + cgi_set_face_clean(socket_in,l_sql_cmd); + } + } +#if 0 + //restart detect + //set_search_info?restart=detect + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"restart="); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + if(strcmp(l_lpr_cgi_param,"detect")==0) + { + cgi_set_restart_detect(wp); + printf("restart detection\n"); + } + } + + //about lpr queue action + //set_search_info?queue=start + //set_search_info?queue=stop + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"queue="); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + if(strcmp(l_lpr_cgi_param,"stop")==0) + { + nvram_set("FFGROUP_QUEUE_STATUS","0"); + g_FFGROUP_QUEUE_STATUS = atoi(nvram_get("FFGROUP_QUEUE_STATUS")); + clear_queue_data(); + printf("stop recheck queue\n"); + websWrite (wp, "%s","stop recheck queue"); + } + else if(strcmp(l_lpr_cgi_param,"start")==0) + { + nvram_set("FFGROUP_QUEUE_STATUS","1"); + g_FFGROUP_QUEUE_STATUS = atoi(nvram_get("FFGROUP_QUEUE_STATUS")); + printf("start lpr queue\n"); + websWrite (wp, "%s","start lpr queue"); + } + else if(strcmp(l_lpr_cgi_param,"clear")==0) + { + clear_queue_data(); + printf("clear lpr queue\n"); + websWrite (wp, "%s","clear lpr queue"); + } + } + //int g_ftp_condition_channel=1; + //int g_httppost_condition_channel=1; + //set_search_info?action=ftp&status=1&channel=1 + //set_search_info?action=ftp&status=0&channel=1 + //set_search_info?action=httppost&status=1&channel=1 + //set_search_info?action=httppost&status=0&channel=1 + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"action="); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + char l_channel[5]={0}; + char l_status[5]={0}; + char l_event_cgi_res[256]={0}; + snprintf(l_event_cgi_res , sizeof(l_event_cgi_res)-1, "HTTP/1.0 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + websWrite (wp, "%s",l_event_cgi_res); + + if(strcmp(l_action_lpr,"ftp")==0) + { + if(GetValidVar(wp,"status",l_status)) + { + g_ftp_status=atoi(l_status); + } + if(GetValidVar(wp,"channel",l_channel)) + { + g_ftp_condition_channel=atoi(l_channel); + } + } + if(strcmp(l_action_lpr,"httppost")==0) + { + if(GetValidVar(wp,"status",l_status)) + { + g_httppost_status=atoi(l_status); + } + if(GetValidVar(wp,"channel",l_channel)) + { + g_httppost_condition_channel=atoi(l_channel); + } + } + websWrite (wp, "%s","set ok"); + } +#endif + return 0; +} + +void callback_reset_db_list_face() // change so variable name and with the db +{ + char i_cmd_black[100]={0}; + char i_cmd_white[100]={0}; + sprintf(i_cmd_black,CMD_CLEAN_FACE_MSG_TABLE,FACE_MSG_BLACKTABLE); + sprintf(i_cmd_white,CMD_CLEAN_FACE_MSG_TABLE,FACE_MSG_WHITETABLE); + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + // db_exec_sql(g_facegroup_db_info.pdb, i_cmd_black); + // sleep(1); + // db_exec_sql(g_facegroup_db_info.pdb, i_cmd_white); + + + if (db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, i_cmd_black) == 0) + { + db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + + usSleep(1000); + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + if (db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, i_cmd_white) == 0) + { + db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + +} +void callback_reset_db_map_list_face() // change so variable name and with the db +{ + char s_cmd_map[100]={0}; + + sprintf(s_cmd_map,CMD_CLEAN_FACE_MSG_TABLE,FACE_MAPPING_TABLE); + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + facedb_mutex_lock(g_facegroup_db_info.pdb); + // db_exec_sql(g_facegroup_db_info.pdb, s_cmd_map); + + if (db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, s_cmd_map) == 0) + { + db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + +} +int callback_import_facelist_msg_to_db(void *data) // change so variable name and with the db +{ + char l_db_log_tbname[20]={0}; + facegroup_listInfo_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + int ret = 0; + + if(!data) + { + + } + else { + lpr_insert_data = (facegroup_listInfo_tb *)data; + + //if(g_facegroup_db_info) + { + if (g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //check List type + //printf("1lpr_insert_data->ACT_PARAM:%s\n",lpr_insert_data->ACT_PARAM); + chk_sql_msg_tbname_face(l_db_log_tbname, lpr_insert_data->ACT_PARAM); + //printf("2l_db_log_tbname:%s\n",l_db_log_tbname); + db_get_record_counts(g_facegroup_db_info.pdb, l_db_log_tbname); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_FACELIST_DATA_CMD + , l_db_log_tbname + , "" + , "" + , "" + , lpr_insert_data->LPR + , "" + , "" + , "" + , lpr_insert_data->ACT_PARAM + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , lpr_insert_data->IN_USER + , ""//lpr_insert_data->IN_PHONE + , "" + , lpr_insert_data->IN_PAYSTATUS + , ""//lpr_insert_data->IN_EXIST + , lpr_insert_data->IN_SCHEDULE_START + , lpr_insert_data->IN_SCHEDULE_END + , lpr_insert_data->IN_OTHER + , lpr_insert_data->IN_DETECT_ENDTIME + , "" + , "" + , "" + , "" + , "" + , 0); + + //printf("Insert #2 LPR LIST Log: %s\n", l_sql_cmd); + //printf("Insert LPR LIST Log: %s\n", l_sql_cmd); + + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + // l_sql_ret = db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /*if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + facedb_mutex_unlock(g_facegroup_db_info.pdb);*/ + //sqlite_restore_database(g_facegroup_db_info.pdb); + } + else { + ret = 1; + } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //db_unlock(g_facegroup_db_info.pdb); + + } + } + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + } + + return ret; +} + +void callback_import_face_map_msg_to_db(void *data) // change so variable name and with the db +{ + //int l_map_record_cnts = 0; + facegroup_mapping_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return; + } + + lpr_insert_data = (facegroup_mapping_db_tb *)data; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facedb_mutex_lock(g_facegroup_db_info.pdb); + + //l_map_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, FACE_MAPPING_TABLE); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, INSERT_FACE_MAPPING_CMD + ,FACE_MAPPING_TABLE + ,lpr_insert_data->LPR_DETECT + ,lpr_insert_data->LPR); +#ifdef FACE_AMBA_DEBUG + printf("import insert LPR MAP Log: %s\n", l_sql_cmd); +#endif + + // BUG3: db_exec_sql g db_prepare_sql M db_step_sql Φ + // l_sql_ret= db_exec_sql(g_facegroup_db_info.pdb, l_sql_cmd); + + l_sql_ret = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + if (l_sql_ret == 0) + { + l_sql_ret = db_step_sql(g_facegroup_db_info.pstmt); + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + + if(l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + */ + } + facedb_mutex_unlock(g_facegroup_db_info.pdb); + + } + } + + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + +} + + +// int str_levenshtein(const char *s, int ls, const char *t, int lt) // don't know what this for +// { +// int a, b, c; + +// /* if either string is empty, difference is inserting all chars +// * from the other +// */ +// if (!ls) return lt; +// if (!lt) return ls; + +// /* if last letters are the same, the difference is whatever is +// * required to edit the rest of the strings +// */ +// if (s[ls] == t[ls]) +// return str_levenshtein(s, ls - 1, t, lt - 1); + +// /* else try: +// * changing last letter of s to that of t; or +// * remove last letter of s; or +// * remove last letter of t, +// * any of which is 1 edit plus editing the rest of the strings +// */ +// a = str_levenshtein(s, ls - 1, t, lt - 1); +// b = str_levenshtein(s, ls, t, lt - 1); +// c = str_levenshtein(s, ls - 1, t, lt ); + +// if (a > b) a = b; +// if (a > c) a = c; + +// return a + 1; +// } + +// int compute_str_scale(double ret_levenshtein,double strlen1,double strlen2) // don't know what this for +// { +// int l_result=0; +// double l_scale=ret_levenshtein/COMPARE_MAX(strlen1,strlen2); +// l_result =((double)1-l_scale)*100; +// return l_result; +// } + + +//void action_face_import_infomation(char *iLPR , char *iACT_PARAM , char *iIN_USER , char *iIN_PHONE, +// char *iIN_PAYSTATUS, char *iIN_EXIST , char *iIN_SCHEDULE_START, +// char *iIN_SCHEDULE_END) +int action_face_import_infomation(char *iLPR , char *iACT_PARAM , char *iIN_USER ,char *iIN_OTHER, char *iIN_SCHEDULE_START, + char *iIN_SCHEDULE_END,char *iIN_ENDTIME, char *idet_level) //check where called this when rewritting +{ + int ret = 0; + pthread_mutex_lock(&mutex_db_face_import); + if(iLPR==NULL || iACT_PARAM ==NULL || iIN_USER ==NULL) + { + pthread_mutex_unlock(&mutex_db_face_import); + } + else { + //if(iIN_PHONE == NULL) + // sprintf(iIN_PHONE,"%s",""); + //if(iIN_ADDRESS == NULL) + // sprintf(iIN_ADDRESS,"%s",""); + //if(iIN_PAYSTATUS == NULL) + // sprintf(iIN_PAYSTATUS,"%s","0"); + //if(iIN_EXIST==NULL ) + // sprintf(iIN_EXIST,"%s","0"); + + char temp_iIN_SCHEDULE_START[10] = { 0 }; + char temp_iIN_SCHEDULE_END[10] = { 0 }; + char temp_idet_level[5] = { 0 }; + + if (strlen(iIN_SCHEDULE_START) != 5) + strcpy(temp_iIN_SCHEDULE_START, "00:00"); + else + strcpy(temp_iIN_SCHEDULE_START, iIN_SCHEDULE_START); + + if (strlen(iIN_SCHEDULE_END) != 5) + strcpy(temp_iIN_SCHEDULE_END, "23:59"); + else + strcpy(temp_iIN_SCHEDULE_END, iIN_SCHEDULE_END); + + + if (strlen(idet_level) != 1) + strcpy(temp_idet_level, "2"); + else + strcpy(temp_idet_level, idet_level); + + + char l_fix_endtime[64] = { 0 }; + char l_time[50] = { 0 }; + char l_yy[60] = { 0 }; + struct tm tm_ptr; + time_t the_time = time(NULL); + (void)time(&the_time); + localtime_r(&the_time, &tm_ptr); + + strftime(l_time, 30, "%Y_%m%d%H%M%S", &tm_ptr); + l_yy[0] = l_time[0]; + l_yy[1] = l_time[1]; + l_yy[2] = l_time[2]; + l_yy[3] = l_time[3]; + l_yy[4] = '\0'; + + sprintf(l_fix_endtime, "%d-%d-%d_%d:%d", atoi(l_yy) + 1, 12, 31, 23, 59); + + char l_act_param[10] = { 0 }; + + + chk_import_dbname_face(l_act_param, iACT_PARAM); + + + facegroup_listInfo_tb *l_import_data = NULL; + //l_import_data=calloc(1,sizeof(facegroup_listInfo_tb)); + l_import_data = (facegroup_listInfo_tb*)malloc(sizeof(facegroup_listInfo_tb)); + memset(l_import_data, 0, sizeof(facegroup_listInfo_tb)); + + + //if(l_import_data!=NULL) + { + sprintf(l_import_data->LPR, "%s", iLPR); + sprintf(l_import_data->ACT_PARAM, "%s", l_act_param); + strcpy(l_import_data->IN_USER, iIN_USER); + strcpy(l_import_data->IN_OTHER, iIN_OTHER); + sprintf(l_import_data->IN_SCHEDULE_START, "%s", temp_iIN_SCHEDULE_START); + sprintf(l_import_data->IN_SCHEDULE_END, "%s", temp_iIN_SCHEDULE_END); + + if (strcmp(iIN_ENDTIME, "") == 0) + sprintf(l_import_data->IN_DETECT_ENDTIME, "%s", l_fix_endtime); + else + sprintf(l_import_data->IN_DETECT_ENDTIME, "%s", iIN_ENDTIME); + + sprintf(l_import_data->IN_PAYSTATUS, "%s", temp_idet_level); + + + ret = callback_import_facelist_msg_to_db((void *)l_import_data); + } + pthread_mutex_unlock(&mutex_db_face_import); + } + return ret; +} +void action_import_face_map_info(char *iLPR_DETECT , char *iLPR) //check where called this when rewritting +{ + pthread_mutex_lock(&mutex_db_face_import); + if(iLPR_DETECT==NULL || iLPR ==NULL) + { + //usSleep(60000); + //printf("reload map list informatin\n"); + //stop_all_thread(); + //lilin_reboot_system(__FUNCTION__,__LINE__,LILIN_REBOOT_SYSTEM); + pthread_mutex_unlock(&mutex_db_face_import); + return; + + } + + facegroup_mapping_db_tb *l_import_map=NULL; + //l_import_map=calloc(1,sizeof(facegroup_mapping_db_tb)); + l_import_map = (facegroup_mapping_db_tb*)malloc(sizeof(facegroup_mapping_db_tb)); + memset(l_import_map,0,sizeof(facegroup_mapping_db_tb)); + + //if(l_import_map!=NULL) + { + sprintf(l_import_map->LPR_DETECT ,"%s" ,iLPR_DETECT); + sprintf(l_import_map->LPR ,"%s" ,iLPR); + + + callback_import_face_map_msg_to_db( (void *)l_import_map); + + } + pthread_mutex_unlock(&mutex_db_face_import); + +} +#if 0 +int switch_face_detect_strength(int istrength) +{ + int strength_percent=0; + switch(istrength) + { + case 0://DETECT_VERYWEAK: + strength_percent=25; + break; + case 1://DETECT_WEAK: + strength_percent=50; + break; + case 2://DETECT_NORMAL: + strength_percent=75; + break; + case 3://DETECT_STRONG: + strength_percent=100; + break; + } + return strength_percent; +} +//int checkTime(char *idetect_time,char *iendtime,char *lprlist_end) +int checkTime(char *idetect_time,char *iendtime,char *lprlist_start,char *lprlist_end) +{ + int l_ret = 0; + char l_ndet_time[64]={0}; + char l_lprself_endtime[64]={0}; + char l_lprself_startschedule[64]={0}; + char l_lprself_endschedule[64]={0}; + + int l_ndet_year=0; + int l_lprself_endyear=0; + + char l_ndet_hourmin[10]={0}; + int i_ndet_hourmin=0; + char l_lprself_startschedule_hourmin[10]={0}; + char l_lprself_endschedule_hourmin[10]={0}; + int i_lprself_endschedule_hourmin=0; + int i_lprself_endschedule_min=0; + + + char tmp_det_blank[10][STRSPLIT_SIZE]; + char tmp_det_bottombar[10][STRSPLIT_SIZE];//_ + char tmp_det_colon[10][STRSPLIT_SIZE];//: + char tmp_lprself_start_schedule_colon[10][STRSPLIT_SIZE]; + char tmp_lprself_end_schedule_colon[10][STRSPLIT_SIZE]; + char tmp_lprself_endtime[10][STRSPLIT_SIZE]; + char tmp_lprself_pre_etime[10][STRSPLIT_SIZE]; + char tmp_lprself_post_etime[10][STRSPLIT_SIZE]; + + + + char require_det_MMDD[10]={0}; + char require_det_hhmm[10]={0}; + char require_detdate[15]={0}; + char require_dettime[10]={0}; + + char require_lprself_pre_etime[20]={0}; + char require_lprself_post_etime[20]={0}; + char require_lprself_endtime_MMDD[10]={0}; + char require_lprself_endtime_hhmm[10]={0}; + int i_require_lprself_endtime_hhmm=0; + int i_require_lprself_endtime_mm=0; + + sprintf(l_ndet_time ,"%s",idetect_time); + sprintf(l_lprself_endtime ,"%s",iendtime); + sprintf(l_lprself_startschedule ,"%s",lprlist_start); + sprintf(l_lprself_endschedule ,"%s",lprlist_end); + + + if(strcmp(l_lprself_endtime,"")==0) + { + printf("l_lprself_endtime is null.\n"); + l_ret = 1; + } + else + { + if(strcmp(l_ndet_time,"")==0) + { + printf("l_detect_time is null.\n"); + } + else + { + StrSplit(l_lprself_endtime, tmp_lprself_endtime, "_"); + StrSplit(l_ndet_time, tmp_det_blank, " "); + + int i=0,k=0; + + while(i<2) + { + k=i++; + if(i==1) + { + //Split DETECT LPR TIME + sprintf(require_detdate,"%s",*(tmp_det_blank+k)); + //Split END TIME + sprintf(require_lprself_pre_etime,"%s",*(tmp_lprself_endtime+k)); + } + else if(i==2) + { + //Split DETECT LPR TIME + sprintf(require_dettime,"%s",*(tmp_det_blank+k)); + //Split END TIME + sprintf(require_lprself_post_etime,"%s",*(tmp_lprself_endtime+k)); + } + } + + if((strlen(require_detdate)>0)&&(strlen(require_dettime)>0)) + { + //DETECT LPR TIME + StrSplit(require_detdate, tmp_det_bottombar, "-"); + StrSplit(require_dettime, tmp_det_colon, ":"); + //END TIME + StrSplit(require_lprself_pre_etime, tmp_lprself_pre_etime, "-"); + StrSplit(require_lprself_post_etime, tmp_lprself_post_etime, ":"); + + StrSplit(l_lprself_endschedule, tmp_lprself_end_schedule_colon, ":"); + StrSplit(l_lprself_startschedule, tmp_lprself_start_schedule_colon, ":"); + + i=0; + k=0; + while(i<3) + { + k=i++; + char copy_lpr_str[5]={0}; + char copy_end_str[5]={0}; + + if(i==1) + { + l_ndet_year=atoi(*(tmp_det_bottombar+k)); + l_lprself_endyear=atoi(*(tmp_lprself_pre_etime+k)); + } + else if(i==2) + { + //DETECT MONTH + sprintf(copy_lpr_str,"%s",*(tmp_det_bottombar+k)); + strcat(require_det_MMDD,copy_lpr_str); + //ENDTIME MONTH + sprintf(copy_end_str,"%s",*(tmp_lprself_pre_etime+k)); + strcat(require_lprself_endtime_MMDD,copy_end_str); + } + else if(i==3) + { + //DETECT DAY + sprintf(copy_lpr_str,"%s",*(tmp_det_bottombar+k)); + strcat(require_det_MMDD,copy_lpr_str); + //ENDTIME DAY + sprintf(copy_end_str,"%s",*(tmp_lprself_pre_etime+k)); + strcat(require_lprself_endtime_MMDD,copy_end_str); + } + } + i=0; + k=0; + while(i<3) + { + k=i++; + char copy_lpr_str[5]={0}; + char copy_end_str[5]={0}; + if(i==1) + { + //DETECT HOUR + sprintf(copy_lpr_str,"%s",*(tmp_det_colon+k)); + strcat(require_det_hhmm,copy_lpr_str); + //ENDTIME HOUR + sprintf(copy_end_str,"%s",*(tmp_lprself_post_etime+k)); + + strcat(require_lprself_endtime_hhmm,copy_end_str); + //compare detectime + sprintf(l_ndet_hourmin,"%s",copy_lpr_str); + + //compare list + sprintf(l_lprself_startschedule_hourmin,"%s",*(tmp_lprself_start_schedule_colon+k)); + sprintf(l_lprself_endschedule_hourmin,"%s",*(tmp_lprself_end_schedule_colon+k)); + } + else if(i==2) + { + //DETECT MINS + sprintf(copy_lpr_str,"%s",*(tmp_det_colon+k)); + strcat(require_det_hhmm,copy_lpr_str); + //ENDTIME MINS + sprintf(copy_end_str,"%s",*(tmp_lprself_post_etime+k)); + strcat(require_lprself_endtime_hhmm,copy_end_str); + i_require_lprself_endtime_mm =atoi(copy_end_str); + //compare detectime + strcat(l_ndet_hourmin,copy_lpr_str); + + //compare list + strcat(l_lprself_startschedule_hourmin,*(tmp_lprself_start_schedule_colon+k)); + strcat(l_lprself_endschedule_hourmin,*(tmp_lprself_end_schedule_colon+k)); + i_lprself_endschedule_min=atoi(*(tmp_lprself_end_schedule_colon+k)); + } + + } + if(i_lprself_endschedule_min == 59) + { + i_lprself_endschedule_hourmin = atoi(l_lprself_endschedule_hourmin)+41; + i_lprself_endschedule_hourmin =i_lprself_endschedule_hourmin+1; + } + else + i_lprself_endschedule_hourmin = atoi(l_lprself_endschedule_hourmin)+1; + + if(i_require_lprself_endtime_mm == 59) + { + i_require_lprself_endtime_hhmm = atoi(require_lprself_endtime_hhmm)+41; + i_require_lprself_endtime_hhmm = i_require_lprself_endtime_hhmm+1; + } + else + i_require_lprself_endtime_hhmm = atoi(require_lprself_endtime_hhmm)+1; + i_ndet_hourmin =atoi(l_ndet_hourmin); + +// printf("l_ndet_hourmin:%s\n",l_ndet_hourmin); +// printf("i_ndet_hourmin:%d\n",i_ndet_hourmin); +// printf("l_lprself_startschedule_hourmin:%s\n",l_lprself_startschedule_hourmin); +// printf("l_lprself_endschedule_hourmin:%s\n",l_lprself_endschedule_hourmin); +// printf("i_lprself_endschedule_hourmin:%d\n",i_lprself_endschedule_hourmin); + if(i_ndet_hourmin >= atoi(l_lprself_startschedule_hourmin)) + { + if(atoi(l_ndet_hourmin) < i_lprself_endschedule_hourmin ) + { +// printf("atoi(require_det_hhmm):%d\n",atoi(require_det_hhmm)); +// printf("atoi(require_lprself_endtime_hhmm):%d\n",atoi(require_lprself_endtime_hhmm)); +// printf("i_require_lprself_endtime_hhmm:%d\n",i_require_lprself_endtime_hhmm); +// printf("atoi(require_det_MMDD):%d\n",atoi(require_det_MMDD)); +// printf("atoi(require_lprself_endtime_MMDD):%d\n",atoi(require_lprself_endtime_MMDD)); + if(l_ndet_year == l_lprself_endyear ) + { + if(atoi(require_det_MMDD) == atoi(require_lprself_endtime_MMDD)) + { + if(atoi(require_det_hhmm) < i_require_lprself_endtime_hhmm) + { + l_ret=1; + } + }else if(atoi(require_det_MMDD) < atoi(require_lprself_endtime_MMDD)) + { + l_ret=1; + } + + } + else + { + if(l_ndet_year < l_lprself_endyear ) + { + l_ret=1; + } + } + } + + } + } + } + } + + return l_ret; +} + +int insert_face_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr) +{ + + int l_result=0; + + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_db_tb)); + char l_db_name[15]={0}; + char l_sql_cmd[256]={0}; + int l_db_length=0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //check List type + chk_sql_msg_tbname_face(l_db_name,ilist_type); + + + sprintf(l_sql_cmd,CMD_SELECT_FACE,l_db_name); + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_name); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql_cmd, l_rc); + l_result= -1; + + } + else + { + l_db_length=l_lpr_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + + int l_det_threshold=switch_face_detect_strength(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)); + + int l_str_ret=str_levenshtein(l_db_lpr_tb_info.LPR, strlen(l_db_lpr_tb_info.LPR), idetect_lpr, strlen(idetect_lpr)); + + int l_lpr_percent=compute_str_scale((double)l_str_ret,(double) strlen(l_db_lpr_tb_info.LPR),(double)strlen(idetect_lpr)); + + if(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)==3) + { + if(l_str_ret==0) + { + + l_lpr_percent=100; + if(l_lpr_percent==l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + //printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + } + + } + else + { + if(l_lpr_percent > l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + //printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + + } + } + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + //printf("insert_face_Levenshtein:%d\n",l_result); + return l_result; +} + +int compute_face_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr,get_face_list_param *l_chk_lpr) +{ + + int l_result=0; + memset(l_chk_lpr,0,sizeof(get_face_list_param)); + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_db_tb)); + char l_db_name[15]={0}; + char l_sql_cmd[256]={0}; + int l_db_length=0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //check List type + chk_sql_msg_tbname_face(l_db_name,ilist_type); + + + sprintf(l_sql_cmd,CMD_SELECT_FACE,l_db_name); + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_name); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql_cmd, l_rc); + l_result= -1; + + } + else + { + l_db_length=l_lpr_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_face_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + + int l_det_threshold=switch_face_detect_strength(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)); + + int l_str_ret=str_levenshtein(l_db_lpr_tb_info.LPR, strlen(l_db_lpr_tb_info.LPR), idetect_lpr, strlen(idetect_lpr)); + + int l_lpr_percent=compute_str_scale((double)l_str_ret,(double) strlen(l_db_lpr_tb_info.LPR),(double)strlen(idetect_lpr)); + printf("l_str_ret:%d\n",l_str_ret); + printf("l_lpr_percent:%d\n",l_lpr_percent); + printf("l_det_threshold:%d\n",l_lpr_percent); + printf("atoi(l_db_lpr_tb_info.IN_PAYSTATUS):%d\n",atoi(l_db_lpr_tb_info.IN_PAYSTATUS)); + if(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)==3) + { + if(l_str_ret==0) + { + + l_lpr_percent=100; + if(l_lpr_percent==l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + sprintf(l_chk_lpr->LPR_USER,"%s",l_db_lpr_tb_info.IN_USER); + sprintf(l_chk_lpr->FR_OTHER,"%s",l_db_lpr_tb_info.IN_OTHER); + sprintf(l_chk_lpr->DETECT_START_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_START); + sprintf(l_chk_lpr->DETECT_END_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_END); + sprintf(l_chk_lpr->DETECT_STOP_TIME,"%s",l_db_lpr_tb_info.IN_DETECT_ENDTIME); + printf("1l_chk_lpr.LPR_USER:%s\n",l_chk_lpr->LPR_USER); + printf("1l_chk_lpr.FR_OTHER:%s\n",l_chk_lpr->FR_OTHER); + printf("1l_chk_lpr.DETECT_START_TIME:%s\n",l_chk_lpr->DETECT_START_TIME); + printf("1l_chk_lpr.DETECT_END_TIME:%s\n",l_chk_lpr->DETECT_END_TIME); + printf("1l_chk_lpr.DETECT_STOP_TIME:%s\n",l_chk_lpr->DETECT_STOP_TIME); + printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + } + + } + else + { + if(l_lpr_percent > l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + sprintf(l_chk_lpr->LPR_USER,"%s",l_db_lpr_tb_info.IN_USER); + sprintf(l_chk_lpr->FR_OTHER,"%s",l_db_lpr_tb_info.IN_OTHER); + sprintf(l_chk_lpr->DETECT_START_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_START); + sprintf(l_chk_lpr->DETECT_END_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_END); + sprintf(l_chk_lpr->DETECT_STOP_TIME,"%s",l_db_lpr_tb_info.IN_DETECT_ENDTIME); + printf("2l_chk_lpr.LPR_USER:%s\n",l_chk_lpr->LPR_USER); + printf("2l_chk_lpr.FR_OTHER:%s\n",l_chk_lpr->FR_OTHER); + printf("2l_chk_lpr.DETECT_START_TIME:%s\n",l_chk_lpr->DETECT_START_TIME); + printf("2l_chk_lpr.DETECT_END_TIME:%s\n",l_chk_lpr->DETECT_END_TIME); + printf("2l_chk_lpr.DETECT_STOP_TIME:%s\n",l_chk_lpr->DETECT_STOP_TIME); + printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + + } + } + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } + //printf("insert_face_Levenshtein:%d\n",l_result); + return l_result; +} + +void mapping_detect_face(char *ilist_type,char *idetect_lpr,char *mapping_lpr) +{ + //if(g_facegroup_db_info) + { + if(g_facegroup_db_info.pdb) + { + facegroup_mapping_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(facegroup_mapping_db_tb)); + char l_db_name[15]={0}; + char l_sql_cmd[256]={0}; + int l_db_length=0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //check List type + chk_sql_msg_tbname_face(l_db_name,ilist_type); + + + sprintf(l_sql_cmd,CMD_SELECT_FACE,l_db_name); + + + facedb_mutex_lock(g_facegroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_facegroup_db_info.pdb, l_db_name); + + l_rc = db_prepare_sql(g_facegroup_db_info.pdb, &g_facegroup_db_info.pstmt, l_sql_cmd); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_facegroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql_cmd, l_rc); + + } + else + { + l_db_length=l_lpr_record_cnts; + printf("mapping_detect_face length:%d\n",l_db_length); + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_face_map_record(g_facegroup_db_info.pstmt, &l_db_lpr_tb_info); + l_rc = db_move_next_record(g_facegroup_db_info.pstmt); + printf("l_db_lpr_tb_info.LPR_DETECT:%s\n",l_db_lpr_tb_info.LPR_DETECT); + printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + printf("idetect_lpr:%s\n",idetect_lpr); + + if(strcmp(idetect_lpr,l_db_lpr_tb_info.LPR_DETECT)==0) + { + sprintf(mapping_lpr,"%s",l_db_lpr_tb_info.LPR); + break; + } + } + if(strcmp(mapping_lpr,"")==0) + { + sprintf(mapping_lpr,"%s",idetect_lpr); + } + } + db_free_sql_stmt(g_facegroup_db_info.pstmt); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + } + } +} +#endif + +/** + * @brief + * + * @param pdb + * @param table_name + * @param ff_face_tracking_uuid_to_check + * @return int + */ +int db_get_record_counts_check_ff_face_tracking_uuid_inner_join(sqlite3 *pdb, char *ff_face_tracking_uuid_to_check) +{ + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_face_tracking_uuid = '%s';", table_name, ff_face_tracking_uuid_to_check); + snprintf(sql_buf, sizeof(sql_buf), CMD_SELECT_COUNT_TRACK_UUID, ff_face_tracking_uuid_to_check); + + //printf("sql cmd: \n %s \n\n", sql_buf); + + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + printf("sql error while \n"); + usSleep(10); + continue; + } + else + { + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + else { + // Handle the error if needed + } + + break; + } + printf("error sql while \n"); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + + return nRows; +} + +int db_get_record_counts_check_ff_face_name(sqlite3 *pdb, char *table_name, char *ff_face_name_to_check) +{ + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_face_name = '%s';", table_name, ff_face_name_to_check); + + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + usSleep(10); + continue; + } + else + { + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + else { + // Handle the error if needed + } + + break; + } + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + + return nRows; +} + + +/** + * @brief + * + * @param pdb + * @param table_name + * @param ff_face_tracking_uuid_to_check + * @return int + */ +int db_get_record_counts_check_ff_face_tracking_uuid(sqlite3 *pdb, char *table_name, char *ff_face_tracking_uuid_to_check) +{ + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_face_tracking_uuid = '%s';", table_name, ff_face_tracking_uuid_to_check); + + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + usSleep(10); + continue; + } + else + { + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + else { + // Handle the error if needed + } + + break; + } + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + + return nRows; +} + +bool check_if_not_in_white_face_name(char *ff_lpr_to_check) +{ + int l_white_len = db_get_record_counts_check_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check); + if (l_white_len == 0) { + return true; + } + return false; +} + +bool check_if_not_in_black_face_name(char *ff_lpr_to_check) +{ + int l_black_len = db_get_record_counts_check_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check); + if (l_black_len == 0) { + return true; + } + return false; +} + + +bool check_if_not_in_black_and_white_face_tracking_uuid(char *ff_lpr_to_check) +{ + { +#if 0 + int l_black_len = db_get_record_counts_check_ff_face_tracking_uuid(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, ff_lpr_to_check); + int l_white_len = db_get_record_counts_check_ff_face_tracking_uuid(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, ff_lpr_to_check); + int l_log_record_cnts = l_black_len + l_white_len; + // printf("watch :%d, vip: %d \n", l_black_len, l_white_len); + if (l_log_record_cnts == 0) { + return true; + } +#endif + +#if 1 + int l_black_white_count = db_get_record_counts_check_ff_face_tracking_uuid_inner_join(g_facegroup_db_info.pdb, ff_lpr_to_check); + //int l_log_record_cnts = l_black_white_count; + + //printf("\n cccccccccccccccccccccccccccccccccccccccc count: %d\n\n", l_black_white_count); + + if (l_black_white_count == 0) { + return true; + } +#endif + + + } + return false; +} + +int get_ff_face_name_max_num() +{ + // need to modify face_name + facedb_mutex_lock(g_facegroup_db_info.pdb); +#if 0 + int black_max_num = db_search_max_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE); + int white_max_num = db_search_max_ff_face_name(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + int max_num = black_max_num > white_max_num ? black_max_num : white_max_num; +#ifdef FACE_AMBA_DEBUG + printf("[get_ff_face_name_max_num] black:%d, white:%d, max_num:%d\n",black_max_num,white_max_num,max_num); +#endif +#endif + +#if 1 + int max_num = db_search_max_ff_face_name_union_two(g_facegroup_db_info.pdb, "ff_face_name", FACE_MSG_BLACKTABLE, FACE_MSG_WHITETABLE); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + //printf("[get_ff_face_name_max_num] max = %d \n", max_num ); +#endif + + return max_num; +} + + + +int get_ff_user_name_by_face_name(const char *target_face_name, char *result_user_name) +{ + facedb_mutex_lock(g_facegroup_db_info.pdb); + db_search_ff_user_name(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, target_face_name, result_user_name); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + if (strlen(result_user_name) > 0) { +#ifdef FACE_AMBA_DEBUG + printf("[get_ff_user_name_by_face_name] black ff_user_name for ff_face_name '%s': %s\n", target_face_name, result_user_name); +#endif + return 1; + } + facedb_mutex_lock(g_facegroup_db_info.pdb); + db_search_ff_user_name(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, target_face_name, result_user_name); + facedb_mutex_unlock(g_facegroup_db_info.pdb); + if (strlen(result_user_name) > 0) { +#ifdef FACE_AMBA_DEBUG + printf("[get_ff_user_name_by_face_name] white ff_user_name for ff_face_name '%s': %s\n", target_face_name, result_user_name); +#endif + return 1; + } + if(strlen(result_user_name) <= 0){ +#ifdef FACE_AMBA_DEBUG + printf("[get_ff_user_name_by_face_name] Failed to find ff_user_name or SQL error occurred\n"); +#endif + return 0; + } + + +} + + +void add_face_count_by_face_name(const char *target_face_name){ + + facedb_mutex_lock(g_facegroup_db_info.pdb); + int black = db_increment_ff_face_count(g_facegroup_db_info.pdb, FACE_MSG_BLACKTABLE, target_face_name);// 1 success 0 fail + int white = db_increment_ff_face_count(g_facegroup_db_info.pdb, FACE_MSG_WHITETABLE, target_face_name);// 1 success 0 fail + facedb_mutex_unlock(g_facegroup_db_info.pdb); +#ifdef FACE_AMBA_DEBUG + if(black == 0 && white == 0){ + printf("Failed to add face count or SQL error occurred target_face_name : %s\n",target_face_name); + } + if(black == 1) + printf("[add_face_count_by_face_name] black face count for ff_face_name '%s' is incremented\n", target_face_name); + if(white == 1) + printf("[add_face_count_by_face_name] white face count for ff_face_name '%s' is incremented\n", target_face_name); +#endif + + +} + +void face_del_watchlist_members(char *delUUID) +{ + int delete_flag = 1; + char face_del_url[512] = { 0 }; // "DELETE http://127.0.0.1:4242/api/v1/WatchlistMembers/00003" + //char face_del_url[512] = { 0 }; + int port = 4242; + int ret = 0; + char face_curl_username[128] = { 0 }; + char face_curl_password[128] = { 0 }; + char *method = "DELETE"; + char outputData[2048] = { 0 }; + + char face_curl_sendbuf[1] = { 0 }; + + if (strlen(delUUID) == 5) + { + sprintf(face_del_url, "http://127.0.0.1/api/v1/WatchlistMembers/%s", delUUID); + + ret = net_curl_face_req_cmd(face_del_url, face_curl_sendbuf, face_cmd_curl_callback, method, + face_curl_username, face_curl_password, port, outputData, "del watchlist members"); + } + + //printf("YYYYYYYYYY %s \n", outputData); +} + +void face_get_watchlist_members() +{ + int delete_flag = 1; + char face_get_url[512] = { 0 }; // "http://127.0.0.1/api/v1/WatchlistMembers" + //char face_del_url[512] = { 0 }; + int port = 4242; + int ret = 0; + char face_curl_username[128] = { 0 }; + char face_curl_password[128] = { 0 }; + char *method = "GET"; + char outputData[65536] = { 0 }; + + char face_curl_sendbuf[1] = { 0 }; + + sprintf(face_get_url, "http://127.0.0.1/api/v1/WatchlistMembers"); + + + ret = net_curl_face_req_cmd(face_get_url, face_curl_sendbuf, face_cmd_curl_callback, method, + face_curl_username, face_curl_password, port, outputData, "get watchlist members"); + + + if (ret >= 0) { + + cJSON *root = NULL; + cJSON *records, *frecord, *label; + + if (strlen(outputData) > 0) + { + printf("\n-------outputData:%s\n", outputData); +#if 0 + root = cJSON_Parse(outputData); + if (root) + { + records = cJSON_GetObjectItem(root, "records"); + + cJSON_ArrayForEach(frecord, records) + { + label = cJSON_GetObjectItem(frecord, "label"); + + if (label) + { + face_del_watchlist_members(label->valuestring); + } + //printf("XXXX label = %s \n", label->valuestring); + } + } +#endif + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } +} + +void face_engine_default() +{ + //clear face inno + face_get_watchlist_members(); + + +//#define BKLISTNAME_FACE "watch" +//#define WTLISTNAME_FACE "vip" +//#define CUSTLISTNAME_FACE "visitor" +//#define LOGLISTNAME "log" + + //clear db records + sqlite_facegroup_delete_all_records(LOGLISTNAME); + sqlite_facegroup_delete_all_records(BKLISTNAME_FACE); + sqlite_facegroup_delete_all_records(WTLISTNAME_FACE); + sqlite_facegroup_delete_all_records(CUSTLISTNAME_FACE); + + //clear face jpg + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/template"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/face"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } +} + + diff --git a/src/face_db.h b/src/face_db.h new file mode 100644 index 0000000..331419a --- /dev/null +++ b/src/face_db.h @@ -0,0 +1,535 @@ +#if 1 +#pragma once +#ifndef FACE_DB_H +#define FACE_DB_H + +// #define FACE_AMBA_DEBUG +//#include "../httpd/httpd.h" +//#include "../httpd/lilincgi.h" +//#include "../httpd/lilin_thread_pool.h" +//#include "../httpd/lilin_reboot.h" +//#include "../httpd/util/string_util.h" +//#include "../common/shutils.h" +//#include "../httpd/actionevent.h" +//#include "ff_license_plate.h" +//#include "../httpd/dynmic_ationevnet.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <stdbool.h> +#include <unistd.h> +#include <pthread.h> +#include <libgen.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <fcntl.h> +#include <ctype.h> + +#include <locale.h> +#include <wchar.h> + +#include "utility.h" +#include "cJSON.h" +#include "sqlite_db.h" +#include "fork_pipe_lib.h" +#include "levenshtein_sqlite.h" +#include "fflpr_plate_db.h" + +// #define COMPARE_MAX(x, y) (((x) > (y)) ? (x) : (y)) + +// #define ACT_PARAM_BKLISTNAME "Denial" +// #define ACT_PARAM_WTLISTNAME "Allowed" +// #define ACT_PARAM_CUSTLISTNAME "Visitor" + +// #define S_ACT_PARAM_BKLISTNAME "denial" +// #define S_ACT_PARAM_WTLISTNAME "allowed" +// #define S_ACT_PARAM_CUSTLISTNAME "visitor" + +// #define BKLISTNAME "black" +// #define WTLISTNAME "white" +// #define CUSTLISTNAME "customer" +// #define LOGLISTNAME "log" +// #define MAX_ROW_DATA 10 + +// #define CONFIGLISTNAME "config" +// #define MAPPINGNAME "mapping" + +// #define SETTYPE_DELETE "delete" +// #define SETTYPE_ADD "add" +// #define SETTYPE_UPDATE "update" +// #define SETTYPE_DOWNLOAD "download" +// #define SETTYPE_CLEAN "clean" +// #define SETTYPE_IMPORT "import" + +// #define DETECT_VERYWEAK 0 +// #define DETECT_WEAK 1 +// #define DETECT_NORMAL 2 +// #define DETECT_STRONG 3 + +//#define COUNT_MULTIPLATE 4 +//#define COUNT_MAXLPRCOUNT 2000 +//#define COUNT_COMPARE 3 +//#define COUNT_BLACK 5100 //100 + +//#define COUNT_LOG 600 //1000 +//#define COUNT_MAPPING 1000 +//#define DELETECOUNT 200 +#define MAX_FACE_COUNT 1200 //1200 + + +//#define COUNT_WHITE 5100 //2000 +//#define COUNT_CUSTOMER 600 //2000 +#define MAX_FACE_CUSTOMER_COUNT 1200 //2200 + + +#define FACELIST_TMP_IMPORTFILE "facelist_tmp.csv" +#define FACELIST_IMPORTFILE "facelist.csv" +#define DB_FACEGROUP_MSG_PATH "/emmc/plugin/Aida_data/db_face.db" //detector.c has this str "/emmc/plugin/Aida_data/db_fflpr.db" +#define FACEOPTSIZE 368640 //360KIB + +#define TABLE_FACE_VERSION "face_ver_tb" + +#define FACE_MSG_TABLE "face_db_tb" +#define FACE_MAPPING_TABLE "face_mapping_tb" + +#define FACE_MSG_BLACKTABLE "face_db_black_tb" +#define FACE_MSG_WHITETABLE "face_db_white_tb" +#define FACE_MSG_CUSTOMERTABLE "face_db_cust_tb" // test_nnctrl_live.c has this defined variable + + +//#define CHK_WORD_LENGTH 27 + +// extern int g_ftp_condition_channel; +// extern int g_httppost_condition_channel; +// extern int g_ftp_status; +// extern int g_httppost_status; + +struct memory_face_data +{ + char *memory; + size_t size; +}; + +typedef struct _facegroup_db_tb +{ + // + + // + char TS[20]; + char MOD_TS[30]; + char CAR_ID[20]; + char LPR[100]; + + char RTIME[20]; + char ACTION[5]; + char sec_color_id[5]; + char ACT_PARAM[30]; + char THRESHOLD[20]; + char ROI_X[6]; + char ROI_Y[6]; + char ROI_W[6]; + char ROI_H[6]; + char LP_X[6]; + char LP_Y[6]; + char LP_W[6]; + char LP_H[6]; + char LP_BMP[60]; + char ROI_BMP[60]; + char COUNTRY[10]; + + // add/edit the info + char IN_USER[512]; + char IN_PHONE[20]; + char IN_ADDRESS[200]; + char IN_PAYSTATUS[5]; + char IN_EXIST[5]; + char IN_SCHEDULE_START[20]; + char IN_SCHEDULE_END[20]; + char IN_OTHER[512]; + + char tb_type[20]; + char sql_tbname[20]; + char sql_count[5]; + char IN_DETECT_ENDTIME[64]; + + //chk_get_list + int onblack; + int onwhite; + char bksql_tbname[20]; + char wtsql_tbname[20]; + + // char face_bmp[128]; + char face_name[10]; //UUID + char user_name[30]; //first name + char last_name[30]; //last name + char face_uuid[60]; // int face_uuid; + char identification_score[20]; //float identification_score; + char face_trackingID[20]; // int face_trackingID + char face_tracking_uuid[20]; // char face_tracking_uuid + + char ff_mod_ts[256]; + char ff_ts_date[256]; + char ff_ts_time[256]; + + int face_count; // + char group[20]; +} facegroup_db_tb; + +typedef struct _facegroup_listInfo_tb +{ + char LPR[100]; + char oLPR[100]; + char ACT_PARAM[30]; + char IN_FIRST_NAME[512]; + char IN_USER[512]; + char IN_PHONE[20]; + char IN_ADDRESS[200]; + char IN_PAYSTATUS[5]; + char IN_EXIST[5]; + char IN_SCHEDULE_START[20]; + char IN_SCHEDULE_END[20]; + char IN_OTHER[512]; + char IN_DETECT_ENDTIME[64]; + + char IN_FACE_NAME[64]; //UUID + char tb_type[20]; +} facegroup_listInfo_tb; + + + +typedef struct _facegroup_compare_info +{ + //char s_count[20]; + //char s_chk_count[20]; + int count; + int detect; + facegroup_db_tb ary_mult[COUNT_MULTIPLATE+1]; +}facegroup_compare_info; + + + +typedef struct _get_face_list_param +{ + char LPR_USER[512]; + char LPR_OTHER[512]; + char DETECT_START_TIME[20]; + char DETECT_END_TIME[20]; + char DETECT_STOP_TIME[64]; + +} get_face_list_param; + +typedef struct _facegroup_mapping_db_tb +{ + char LPR_DETECT[100]; + char LPR[100]; + char oLPR[100]; + char tb_type[20]; + +} facegroup_mapping_db_tb; +#define CMD_CREATE_FACE_VERSION_TABLE "CREATE TABLE IF NOT EXISTS face_ver_tb("\ + "ff_ver_num INTEGER PRIMARY KEY NOT NULL,"\ + "ff_ver_date DATE NOT NULL,"\ + "ff_ver_comment CHAR(64));" + +#define CMD_CREATE_FACE_TABLE "CREATE TABLE IF NOT EXISTS %s("\ + "ff_index INTEGER PRIMARY KEY AUTOINCREMENT,"\ + "ff_ts CHAR(20) NOT NULL,"\ + "ff_mod_ts CHAR(30) NOT NULL,"\ + "ff_car_id CHAR(20) NOT NULL,"\ + "ff_lpr CHAR(100) NOT NULL,"\ + "ff_rtime CHAR(20) NOT NULL,"\ + "ff_action CHAR(5),"\ + "ff_sec_color_id CHAR(5),"\ + "ff_act_param CHAR(30),"\ + "ff_threshold CHAR(20) NOT NULL,"\ + "ff_roiX CHAR(6) NOT NULL,"\ + "ff_roiY CHAR(6) NOT NULL,"\ + "ff_roiW CHAR(6) NOT NULL,"\ + "ff_roiH CHAR(6) NOT NULL,"\ + "ff_lpX CHAR(6) NOT NULL,"\ + "ff_lpY CHAR(6) NOT NULL,"\ + "ff_lpW CHAR(6) NOT NULL,"\ + "ff_lpH CHAR(6) NOT NULL,"\ + "ff_lpbmp CHAR(60) NOT NULL,"\ + "ff_lproi CHAR(60) ,"\ + "ff_country CHAR(10),"\ + "in_user NCHAR(512),"\ + "in_phone CHAR(20),"\ + "in_address NCHAR(200),"\ + "in_paystatus CHAR(5),"\ + "in_exist CHAR(5),"\ + "in_schedule_start CHAR(20),"\ + "in_schedule_end CHAR(20),"\ + "in_other NCHAR(512),"\ + "in_detect_endtime CHAR(64),"\ + "ff_face_name CHAR(10),"\ + "ff_user_name CHAR(30),"\ + "ff_face_tracking_uuid CHAR(60),"\ + "ff_identification_score CHAR(20),"\ + "ff_face_trackingID CHAR(20));" + // "in_detect_endtime CHAR(64));" + //"in_address NCHAR(300)," + //"in_other NCHAR(128));" + +#define CMD_CREATE_FACELIST_TABLE "CREATE TABLE IF NOT EXISTS %s("\ + "ff_index INTEGER PRIMARY KEY AUTOINCREMENT,"\ + "ff_ts CHAR(20) ,"\ + "ff_mod_ts CHAR(30) ,"\ + "ff_car_id CHAR(20) ,"\ + "ff_lpr CHAR(100) NOT NULL,"\ + "ff_rtime CHAR(20) ,"\ + "ff_action CHAR(5),"\ + "ff_sec_color_id CHAR(5),"\ + "ff_act_param CHAR(30),"\ + "ff_threshold CHAR(20) ,"\ + "ff_roiX CHAR(6) ,"\ + "ff_roiY CHAR(6) ,"\ + "ff_roiW CHAR(6) ,"\ + "ff_roiH CHAR(6) ,"\ + "ff_lpX CHAR(6) ,"\ + "ff_lpY CHAR(6) ,"\ + "ff_lpW CHAR(6) ,"\ + "ff_lpH CHAR(6) ,"\ + "ff_lpbmp CHAR(60) ,"\ + "ff_lproi CHAR(60) ,"\ + "ff_country CHAR(10),"\ + "in_user NCHAR(512) NOT NULL,"\ + "in_phone CHAR(20),"\ + "in_address NCHAR(200),"\ + "in_paystatus CHAR(5),"\ + "in_exist CHAR(5) ,"\ + "in_schedule_start CHAR(20),"\ + "in_schedule_end CHAR(20),"\ + "in_other NCHAR(512),"\ + "in_detect_endtime CHAR(64),"\ + "ff_face_name CHAR(10),"\ + "ff_user_name CHAR(30),"\ + "ff_face_tracking_uuid CHAR(60),"\ + "ff_identification_score CHAR(20),"\ + "ff_face_trackingID CHAR(20),"\ + "ff_face_count INTEGER);" + //"in_address NCHAR(300)," + // "in_other NCHAR(128));" + +#define CMD_CREATE_FACE_MAPPING_TABLE "CREATE TABLE IF NOT EXISTS %s("\ + "ff_index INTEGER PRIMARY KEY AUTOINCREMENT,"\ + "ff_det_lpr CHAR(20) NOT NULL,"\ + "ff_lpr CHAR(100) NOT NULL);" + +#define CMD_CREATE_FACE_INDEX "CREATE INDEX IF NOT EXISTS logid ON face_db_tb (ff_index);" + +#define INSERT_FACE_DATA_CMD "INSERT INTO '%s' VALUES(NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" + +#define INSERT_FACELIST_DATA_CMD "INSERT INTO %s VALUES(NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%d');" + +#define INSERT_FACE_MAPPING_CMD "INSERT INTO %s VALUES(NULL,'%s','%s');" + +#define INSERT_FACE_LOG_TO_TABLE_CMD "INSERT INTO %s (ff_mod_ts, ff_lpr, ff_lpbmp, in_user, ff_face_name) "\ + "SELECT ff_mod_ts, ff_lpr, ff_lpbmp, in_user, ff_face_name "\ + "FROM face_db_tb "\ + "WHERE NOT EXISTS(SELECT 1 FROM %s WHERE ff_face_name = '%s') "\ + "AND ff_face_name = '%s' "\ + "AND ff_mod_ts = '%s' "\ + "ORDER BY ff_index DESC LIMIT 1" + +#define INSERT_FACE_LOG_TO_TABLE_CMD_B "INSERT INTO %s (ff_mod_ts, ff_lpr, ff_lpbmp, in_user, ff_face_name, ff_face_tracking_uuid) "\ + "SELECT ff_mod_ts, ff_lpr, ff_lpbmp, in_user, ff_face_name, ff_face_tracking_uuid "\ + "FROM face_db_tb "\ + "WHERE NOT EXISTS(SELECT 1 FROM %s WHERE ff_face_tracking_uuid = '%s') "\ + "AND NOT EXISTS(SELECT 1 FROM %s WHERE ff_face_tracking_uuid = '%s') "\ + "AND ff_face_tracking_uuid = '%s' "\ + "ORDER BY ff_index DESC LIMIT 1" + + +#define UPDATE_DETECT_FACELIST_CMD "UPDATE %s SET "\ + "ff_ts='%s',"\ + "ff_mod_ts='%s',"\ + "ff_car_id='%s',"\ + "ff_rtime='%s',"\ + "ff_action='%s',"\ + "ff_sec_color_id='%s',"\ + "ff_act_param='%s',"\ + "ff_threshold='%s',"\ + "ff_roiX='%s',"\ + "ff_roiY='%s',"\ + "ff_roiW='%s',"\ + "ff_roiH='%s',"\ + "ff_lpX='%s',"\ + "ff_lpY='%s',"\ + "ff_lpW='%s',"\ + "ff_lpH='%s',"\ + "ff_lpbmp='%s',"\ + "ff_lproi='%s',"\ + "ff_country='%s' "\ + "WHERE ff_face_name='%s';" + +#define UPDATE_FACELIST_CMD "UPDATE %s SET "\ + "ff_user_name='%s',"\ + "ff_act_param='%s',"\ + "in_user='%s',"\ + "in_phone='%s',"\ + "in_address='%s',"\ + "in_paystatus='%s',"\ + "in_exist='%s',"\ + "in_schedule_start='%s',"\ + "in_schedule_end='%s',"\ + "in_other='%s',"\ + "in_detect_endtime='%s' "\ + "WHERE ff_face_name='%s';" + +#define UPDATE_FACE_MAPPING_CMD "UPDATE %s SET "\ + "ff_det_lpr='%s',"\ + "ff_lpr='%s'"\ + "WHERE ff_det_lpr='%s';" + +#define UPDATE_FACEEXIST_CMD "UPDATE %s SET in_exist='%s';" + +#define DELETE_FACETAB_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_lpr='%s');" + +#define DELETE_FACELIST_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_face_name='%s');" + +#define DELETE_FACELIST_FIRST_NAME_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_user_name='%s');" + +#define DELETE_FACETAB_TIME_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_mod_ts='%s');" +#define DELETE_FACETAB_USER_NAME_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_user_name='%s');" + +#define DELETE_FACE_MAPPING_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_det_lpr='%s');" + +#define DELETE_ALL_RECORDS "DELETE FROM %s" + +#define CMD_QUERY_FACE_VERSION "SELECT * FROM face_ver_tb ORDER BY ff_ver_num DESC LIMIT 1;" + +#define FACE_INSERT_VERSION "INSERT INTO face_ver_tb VALUES('%d','%s','%s');" + +#define CMD_DROP_FACE_MSG_TABLE "DROP TABLE IF EXISTS face_db_tb;" + +#define CMD_FACE_EXIST_TABLE "SELECT ff_lpr='%s' FROM '%s' WHERE ff_lpr='%s';" + +#define CMD_FACE_UNION_TABLE "SELECT 'black' As Type,"\ + "ff_index,"\ + "ff_lpr,"\ + "in_user,"\ + "in_phone,"\ + "in_address,"\ + "in_paystatus,"\ + "in_exist,"\ + "in_schedule_start,"\ + "in_schedule_end,"\ + "in_other,"\ + "in_detect_endtime,"\ + "ff_user_name,"\ + "ff_lpbmp,"\ + "ff_act_param "\ + "FROM face_db_black_tb UNION "\ + "SELECT 'white' ,"\ + "ff_index,"\ + "ff_lpr,"\ + "in_user,"\ + "in_phone,"\ + "in_address,"\ + "in_paystatus,"\ + "in_exist,"\ + "in_schedule_start,"\ + "in_schedule_end,"\ + "in_other,"\ + "in_detect_endtime,"\ + "ff_user_name,"\ + "ff_lpbmp,"\ + "ff_act_param "\ + "FROM face_db_white_tb ORDER BY ff_index ASC LIMIT %d;" + + +#define CMD_CLEAN_FACE_MSG_TABLE "DELETE FROM %s;" + +#define CMD_SELECT_FACE "SELECT * FROM %s ORDER BY ff_index DESC;" + +#define SHELLSCRIPT_FIX_DB_FACE "sh /emmc/plugin/Aida_data/fix_db_face.sh" + +#define CMD_SELECT_COUNT_TRACK_UUID "SELECT COUNT(*) "\ + " FROM ( "\ + " SELECT ff_face_tracking_uuid FROM face_db_black_tb "\ + " UNION ALL "\ + " SELECT ff_face_tracking_uuid FROM face_db_white_tb "\ + " ) WHERE ff_face_tracking_uuid = '%s';" + +#define CMD_SELECT_MAX "SELECT MAX(CAST(ff_face_name AS INTEGER)) "\ + "FROM ( "\ + "SELECT ff_face_name FROM face_db_white_tb WHERE ff_face_name NOT LIKE '%%[^0-9]%%'"\ + "UNION SELECT ff_face_name FROM face_db_black_tb WHERE ff_face_name NOT LIKE '%%[^0-9]%%') ;" + + +//#define CMD_CHECK_LPR "SELECT LPR FROM face_db_black_tb , face_db_white_tb as white;" + +// some function below as fflpr was called in [detector.c, test_nnctrl_live.c, nweb.c] +// gota add coresponding code with face version + +// char *rtrim(char *str); + +int face_log_db_init(void); + +void sqlite_face_db_close(void); +int cgi_get_db_face_log_delete_jpg(char* db_tb_name, char* list_name, int sum_count); +int cgi_get_db_face_log(SOCKET socket_in, char *db_tb_name, char *list_name, int sum_count); + +void sqlite_facegroup_insert(facegroup_db_tb *l_ff_insert_data, char *type_name); +void sqlite_facegroup_update(facegroup_db_tb *i_updata_list); +int db_get_face_record(sqlite3_stmt *stmt, facegroup_db_tb *db_tb_info); + +void chk_sql_msg_tbname_face(char *listname,char *ndata); + +int cgi_get_search_info_face(SOCKET socket_in, char *path); +int cgi_set_search_info_face(SOCKET socket_in, char *path); + +int action_face_import_infomation(char *iLPR, char *iACT_PARAM , char *iIN_USER ,char *iIN_OTHER, char *iIN_SCHEDULE_START, + char *iIN_SCHEDULE_END,char *iIN_ENDTIME, char *idet_level); +void action_import_face_map_info(char *iLPR_DETECT , char *iLPR) ; + +int switch_face_detect_strength(int istrength); + +int insert_face_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr); +int compute_face_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr,get_face_list_param *l_chk_lpr); +void mapping_detect_face(char *ilist_type,char *idetect_lpr,char *mapping_lpr); +void callback_reset_db_list_face(); +void callback_reset_db_map_list_face(); +// void chk_log_data(char *odata,const char *idata); +// void getvalueForKey(char *keyValue, char *key, char *value); +bool check_if_not_in_black_and_white_face(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance); +bool check_if_in_black_face(char *ff_lpr_to_check); +bool check_if_in_white_face(char *ff_lpr_to_check); + +bool get_schedule_start_in_black_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_start, int levenshtein_distance); +bool get_schedule_start_in_white_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_start, int levenshtein_distance); +bool get_schedule_end_in_black_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance); +bool get_schedule_end_in_white_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance); + +bool get_detect_endtime_in_black_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance); +bool get_detect_endtime_in_white_face(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance); + +void *delete_jpg_face(void * ptr); +void delete_jpg_in_seven_days_face(); +extern pthread_mutex_t mutex_send_jpeg; +void get_face_db_import(); +bool check_if_not_in_black_face_name(char *ff_lpr_to_check); +bool check_if_not_in_white_face_name(char *ff_lpr_to_check); +bool check_if_not_in_black_and_white_face_tracking_uuid(char *ff_lpr_to_check); + +void sqlite_facegroup_add_face_list(const char *FACE_NAME, const char *USER_NAME, const char *LAST_NAME, const char *FACE_UUID, const char *IDENTIFICATION_SCORE,const char *FACE_BMP, + const char *FACE_TRACKING_ID, const char *IN_ADDRESS, const char *IN_OTHER,char *type_name, const char *IN_SCHEDULE_START, const char *IN_SCHEDULE_END, char *IN_DETECT_ENDTIME); + +int get_ff_face_name_max_num(); +int get_ff_user_name_by_face_name(const char *target_face_name, char *result_user_name); +void add_face_count_by_face_name(const char *target_face_name); +facegroup_db_tb get_face_Data_from_frequent_VIP(char *column_name); + +void sqlite_facegroup_add_from_table(const char *UUID, const char *MOD_TS, char *type_name); +void sqlite_face_tracking_uuid_register(const char *tracking_uuid, char *type_name); + +void face_get_watchlist_members(); +void face_del_watchlist_members(char *delUUID); +void face_engine_default(); +#endif +#endif \ No newline at end of file diff --git a/src/face_parser.cpp b/src/face_parser.cpp new file mode 100644 index 0000000..c536142 --- /dev/null +++ b/src/face_parser.cpp @@ -0,0 +1,1066 @@ +#include "face_parser.h" + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +#include <deque> +#include <string.h> +#include <list> +#include <dirent.h> +#include <sys/stat.h> +#include <unistd.h> +#include <math.h> +#include <cJSON.h> +// #include <b64/cdecode.h> +#include "cryptionPlus.h" + +#include <curl/curl.h> +#include <stdlib.h> +#include <utility.h> + + +#include "face_db.h" + + +static std::deque<FaceFrameData> g_FaceFrameQueue; + +FaceFrameData gstNewFaceFrame; + +FaceDataInfo g_face_data_info; + +int g_face_frame_uid = 1; + +int g_check_sync_face = 0; //face recognition global sync -leo + +void FaceQueuePush(FaceFrameData q_info) +{ + g_FaceFrameQueue.push_back(q_info); +} + +FaceFrameData FaceQueueFront() +{ + return g_FaceFrameQueue.front(); +} + +void FaceQueuePop() +{ + + //FaceFrameData q_info = FaceQueueFront(); + + g_FaceFrameQueue.pop_front(); + g_FaceFrameQueue.shrink_to_fit(); +} + +int FaceQueueSize() +{ + return g_FaceFrameQueue.size(); +} + +int FaceQueueIsEmpty() +{ + return FaceQueueSize() <= 0 ? 1 : 0; +} + +void FaceQueueClear() +{ + + while (!FaceQueueIsEmpty()) + { + FaceQueuePop(); + } + + if (!FaceQueueIsEmpty()) + { + g_FaceFrameQueue.clear(); + g_FaceFrameQueue.shrink_to_fit(); + } +} + + +void face_data_get(const char *recv_data, int recv_len) +{ + if (recv_len <= 0 || strlen(recv_data) <= 0) + { + + } + else { + + // int face_total_size = 0; + // int iIsEnd = 0; + + // Face data + if (strstr(recv_data, "{\"timestamp\":") != NULL) + { + // printf("-----get face data: %d \n", recv_len); + + // Queu push + + if (g_FaceFrameQueue.size() < Face_QUEUE_SIZE) + { + FaceFrameData qNewFaceData = { 0 }; + + //printf("\n---recv_data:%s\n", recv_data); + + memcpy(qNewFaceData.frame_buffer, recv_data, recv_len); + + //printf("\n---------frame_buffer:%s\n", qNewFaceData.frame_buffer); + + qNewFaceData.iDataSize = recv_len; + + g_FaceFrameQueue.push_back(qNewFaceData); +#ifdef FACE_AMBA_DEBUG + printf("-----push queue size = %d \n", g_FaceFrameQueue.size()); +#endif + } + + //printf("-----queue size = %d \n", g_FaceFrameQueue.size()); + + } + } +} + + +void appendLastChars(char* dest, const char* src, int n) +{ + size_t destLen = strlen(dest); + size_t srcLen = strlen(src); + + if (srcLen >= n) { + strcpy(dest + destLen, src + srcLen - n); + } else { + strcpy(dest + destLen, src); + } +} + + +static size_t read_callback(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t retcode = fread(ptr, size, nmemb, stream); + return retcode; +} + +/// @brief test_sfe_add_face_group +// BUG5: 修正 Single Entry, Single Exit +int test_sfe_add_face_group(char* tracking_uuid, char* file_path){ + // printf("====== run test_sfe_add_face_group\n"); + int result ; + if (!FileExist(file_path)) + { + printf("%s doesn't exist.\n", file_path); + result = -1; + } + else if(tracking_uuid == NULL || strlen(tracking_uuid) <= 0) + { + printf("tracking_uuid is NULL.\n"); + result = -1; + } + else { + + // char command[] = "curl -X POST http://192.168.50.203:4242/api/v1/WatchlistMembers/test_face_7/AddFace -T //emmc/plugin/Aida_data/face/face_pic1.jpg"; + // system(command); + + char part1[100] = "curl -X POST http://127.0.0.1:4242/api/v1/WatchlistMembers/"; + //char part2[37] = "test_face_8"; // Modify part2 content + char part3[50] = "/AddFace -T "; + //char part4[128] = "//emmc/plugin/Aida_data/storage/storage/face/face_pic1.jpg"; // Modify part4 content + + // Calculate the total length of the merged string + int total_length = strlen(part1) + strlen(tracking_uuid) + strlen(part3) + strlen(file_path); + + // Dynamically allocate memory to hold the merged string (including the null terminator '\0') + char merged_string[512] = { 0 }; + + // Merge the four parts into the merged_string array + strcpy(merged_string, part1); + strcat(merged_string, tracking_uuid); + strcat(merged_string, part3); + strcat(merged_string, file_path); + +#ifdef FACE_AMBA_DEBUG + printf("tracking_uuid = %s\n", tracking_uuid); + printf("file_path = %s\n", file_path); + + printf("====== system(command)\n"); + + printf("total_length = %d\n", total_length); + + // Print the merged string + printf("Merged String: %s\n", merged_string); + // system(merged_string); +#endif + + + char buffer[2048] = { 0 }; + + // 執行指令並取得輸出串流 + FILE* fp = vpopen(merged_string, "r"); + if (fp == NULL) { + printf("Error opening pipe.\n"); + result = -1; + } + else { + + // 讀取輸出串流的內容 + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + //#ifdef FACE_AMBA_DEBUG + //printf("Output: %s", buffer); + //#endif + } + + // 關閉串流 + if (fp != NULL) { + vpclose(fp); + fp = NULL; + } + //printf("popen end\n"); + + if (strstr(buffer, "template") != NULL) { + //printf("[test_sfe_add_face_group] output got Success\n"); + result = 1; + } + else if (((strstr(buffer, "error") != NULL) || (strstr(buffer, "Error") != NULL))) { + printf("[test_sfe_add_face_group] output got error\n"); + result = 0; + } + else { + printf("[test_sfe_add_face_group] output not template\n"); + result = 0; + } + } + } + return result ; +} + + +/* 目前未使用 */ +char* test_sfe_save_image(char* tracking_uuid){ + + char temp_save_base64_file_name[256]={0}; + char temp_save_base64_path[256]={0}; + + // char save_base64_path[128]={0}; + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + //printf("Current local time and date: %s", asctime(timeinfo)); + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + + sprintf(temp_save_base64_file_name, "%d_%d_%d_%d_%d_%d_%ld_%s", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time, tracking_uuid); + + sprintf(temp_save_base64_path, "/emmc/plugin/Aida_data/storage/face/%s.jpg", temp_save_base64_file_name); +#ifdef FACE_AMBA_DEBUG + printf("temp_save_base64_path = %s\n", temp_save_base64_path); +#endif + char* result = (char*)malloc(strlen(temp_save_base64_path) + 1); + strcpy(result, temp_save_base64_path); + return result; + +} + + +void delete_face_jpg() { + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + //printf("Current local time and date: %s", asctime(timeinfo)); + struct timeval time_now; + gettimeofday(&time_now, NULL); + // time_t msecs_time = time_now.tv_usec / 1000; + + + for (int the_index_hour = 0; the_index_hour <= 23; the_index_hour++) { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + // sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/face/%d_%d_%d_%d_*.jpg", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour); + sprintf(cmd, "timeout 10s rm -rf /tmp/face/%d_%d_%d_%d_*.jpg", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour); + pPipe = vpopen(cmd, "r"); + if(pPipe!=NULL) + vpclose(pPipe); + } +} + +void add_padding( char* base64_data, int* base64_data_len) { + int remainder = *base64_data_len % 4; + if (remainder != 0) { + int padding_count = 4 - remainder; + for (int i = 0; i < padding_count; i++) { + strcat(base64_data, "="); + } + *base64_data_len += padding_count; + } +} + + + +// write base64 image to file +size_t write_data(void* ptr, size_t size, size_t nmemb, FILE* stream) { + return fwrite(ptr, size, nmemb, stream); +} + +void check_directory_exists(const char* path) { + char* directory_path = strdup(path); + char* last_slash = strrchr(directory_path, '/'); + + if (last_slash != NULL) { + *last_slash = '\0'; + struct stat st = {0}; + + if (stat(directory_path, &st) == -1) { + if (mkdir(directory_path, 0700) == -1) { + perror("mkdir error"); + } + } + } + free(directory_path); +} + + +void save_base64_image(char* base64_data, const char* output_filename) { + check_directory_exists(output_filename); + FILE* output_file = fopen(output_filename, "wb"); + if (output_file == NULL) { + printf("Unable to open the output file.\n"); + return; + } + + + int base64_data_len = strlen(base64_data); + size_t decoded_data_len = 0; + if(base64_data_len % 4 != 0){ +#ifdef FACE_AMBA_DEBUG + printf("base64_data_len before: %d",base64_data_len); + add_padding(base64_data, &base64_data_len); + printf(", after: %d\n",base64_data_len); +#else + add_padding(base64_data, &base64_data_len); +#endif + } + + unsigned char* decoded_data = (unsigned char*)malloc(base64_data_len); + if (decoded_data == NULL) { + // malloc 分配內存失敗 + printf("Memory allocation failed.\n"); + + } +#ifdef FACE_AMBA_DEBUG + // printf("[save_base64_image]=== save_base64_image base64_data: %s .base64_data_len: %zu\n", base64_data, base64_data_len); +#endif + // base64_decode(const char *data, size_t input_length, size_t *output_length, unsigned char * decoded_data) + base64_decode(base64_data, base64_data_len, &decoded_data_len, decoded_data); + + + errno = 0; + if (fwrite(decoded_data, decoded_data_len, 1, output_file) != 1) { +#ifdef FACE_AMBA_DEBUG + printf("[save_base64_image] fwrite FAILL output_filename=%s !!\n", output_filename); +#endif + if (errno != 0) { + // 發生錯誤,根據實際情況處理錯誤原因,可以使用 perror 函式打印錯誤訊息 + perror("fwrite error"); + // Fail + } + } else { + // Sucess +#ifdef FACE_AMBA_DEBUG + printf("[save_base64_image] fwrite Success output_filename=%s !!\n",output_filename); +#endif + } +#ifdef FACE_AMBA_DEBUG + printf("[save_base64_image] === save_base64_image decoded_data: %s .decoded_data len:%zu\n", decoded_data, decoded_data_len); + + printf("[save_base64_image] Base64 image has been saved as:%s\n", output_filename); +#endif + if(decoded_data != NULL){ + free(decoded_data); + decoded_data = NULL; + } + if(output_file != NULL) + fclose(output_file); + +} + +//int g_save_base64_img_tmp = 0; + +void parse_face_data(cJSON* face_item, FaceData* face_data) { + // printf("====== run parse_face_data\n"); + + cJSON* face_detection_data = cJSON_GetObjectItem(face_item, "face_detection_data"); + if (face_detection_data != NULL && cJSON_IsObject(face_detection_data)) { + cJSON* bounding_box = cJSON_GetObjectItem(face_detection_data, "bounding_box"); + if (bounding_box != NULL && cJSON_IsObject(bounding_box)) { + cJSON* x = cJSON_GetObjectItem(bounding_box, "x"); + cJSON* y = cJSON_GetObjectItem(bounding_box, "y"); + cJSON* width = cJSON_GetObjectItem(bounding_box, "width"); + cJSON* height = cJSON_GetObjectItem(bounding_box, "height"); + if (x != NULL && cJSON_IsNumber(x) && y != NULL && cJSON_IsNumber(y) && width != NULL && cJSON_IsNumber(width) && height != NULL && cJSON_IsNumber(height)) { + face_data->face_detection_data.bounding_box.x = x->valuedouble; + face_data->face_detection_data.bounding_box.y = y->valuedouble; + face_data->face_detection_data.bounding_box.width = width->valuedouble; + face_data->face_detection_data.bounding_box.height = height->valuedouble; + } + } + cJSON* detection_confidence = cJSON_GetObjectItem(face_detection_data, "detection_confidence"); + if (detection_confidence != NULL && cJSON_IsNumber(detection_confidence)) { + face_data->face_detection_data.detection_confidence = detection_confidence->valuedouble; + } + cJSON* raw_detection_confidence = cJSON_GetObjectItem(face_detection_data, "raw_detection_confidence"); + if (raw_detection_confidence != NULL && cJSON_IsNumber(raw_detection_confidence)) { + face_data->face_detection_data.raw_detection_confidence = raw_detection_confidence->valuedouble; + } + } + + cJSON* face_tracking_data = cJSON_GetObjectItem(face_item, "face_tracking_data"); + if (face_tracking_data != NULL && cJSON_IsObject(face_tracking_data)) { + cJSON* tracking_id = cJSON_GetObjectItem(face_tracking_data, "tracking_id"); + if (tracking_id != NULL && cJSON_IsNumber(tracking_id)) { + face_data->face_tracking_data.tracking_id = tracking_id->valueint; + } + cJSON* tracking_uuid = cJSON_GetObjectItem(face_tracking_data, "tracking_uuid"); + if (tracking_uuid != NULL && cJSON_IsString(tracking_uuid)) { + strncpy(face_data->face_tracking_data.tracking_uuid, tracking_uuid->valuestring, sizeof(face_data->face_tracking_data.tracking_uuid) - 1); + face_data->face_tracking_data.tracking_uuid[sizeof(face_data->face_tracking_data.tracking_uuid) - 1] = '\0'; + } + cJSON* tracking_state = cJSON_GetObjectItem(face_tracking_data, "tracking_state"); + if (tracking_state != NULL && cJSON_IsNumber(tracking_state)) { + face_data->face_tracking_data.tracking_state = tracking_state->valueint; + } + } + + cJSON* cropping_data = cJSON_GetObjectItem(face_item, "cropping_data"); + if (cropping_data != NULL && cJSON_IsObject(cropping_data)) { + cJSON* crop_extension = cJSON_GetObjectItem(cropping_data, "crop_extension"); + if (crop_extension != NULL && cJSON_IsNumber(crop_extension)) { + face_data->cropping_data.crop_extension = crop_extension->valueint; + } + cJSON* crop_box = cJSON_GetObjectItem(cropping_data, "crop_box"); + if (crop_box != NULL && cJSON_IsObject(crop_box)) { + cJSON* x = cJSON_GetObjectItem(crop_box, "x"); + cJSON* y = cJSON_GetObjectItem(crop_box, "y"); + cJSON* width = cJSON_GetObjectItem(crop_box, "width"); + cJSON* height = cJSON_GetObjectItem(crop_box, "height"); + if (x != NULL && cJSON_IsNumber(x) && y != NULL && cJSON_IsNumber(y) && width != NULL && cJSON_IsNumber(width) && height != NULL && cJSON_IsNumber(height)) { + face_data->cropping_data.crop_box.x = x->valuedouble; + face_data->cropping_data.crop_box.y = y->valuedouble; + face_data->cropping_data.crop_box.width = width->valuedouble; + face_data->cropping_data.crop_box.height = height->valuedouble; + } + } + cJSON* crop_image = cJSON_GetObjectItem(cropping_data, "crop_image"); + if (crop_image != NULL && cJSON_IsObject(crop_image)) { + cJSON* width = cJSON_GetObjectItem(crop_image, "width"); + cJSON* height = cJSON_GetObjectItem(crop_image, "height"); + cJSON* data = cJSON_GetObjectItem(crop_image, "data"); + cJSON* image_format = cJSON_GetObjectItem(crop_image, "image_format"); + if (width != NULL && cJSON_IsNumber(width) && height != NULL && cJSON_IsNumber(height) && + data != NULL && cJSON_IsString(data) && image_format != NULL && cJSON_IsNumber(image_format)) { + face_data->cropping_data.crop_image.width = width->valueint; + face_data->cropping_data.crop_image.height = height->valueint; + strncpy(face_data->cropping_data.crop_image.data, data->valuestring, sizeof(face_data->cropping_data.crop_image.data) - 1); + face_data->cropping_data.crop_image.data[sizeof(face_data->cropping_data.crop_image.data) - 1] = '\0'; + face_data->cropping_data.crop_image.image_format = image_format->valueint; + } + } + } + + cJSON* identification_data_array = cJSON_GetObjectItem(face_item, "identification_data"); + if (identification_data_array != NULL && cJSON_IsArray(identification_data_array)) { + int identification_data_count = cJSON_GetArraySize(identification_data_array); +#ifdef FACE_AMBA_DEBUG + printf("identification_data_count = %d\n", identification_data_count); +#endif + for (int i = 0; i < identification_data_count && i < 10; i++) { + cJSON* identification_data_item = cJSON_GetArrayItem(identification_data_array, i); + if (identification_data_item != NULL && cJSON_IsObject(identification_data_item)) { + cJSON* id = cJSON_GetObjectItem(identification_data_item, "id"); + cJSON* name = cJSON_GetObjectItem(identification_data_item, "name"); + cJSON* score = cJSON_GetObjectItem(identification_data_item, "score"); + if (id != NULL && cJSON_IsNumber(id) && name != NULL && cJSON_IsString(name) && score != NULL && cJSON_IsNumber(score)) { + face_data->identification_data[i].id = id->valueint; + strncpy(face_data->identification_data[i].name, name->valuestring, sizeof(face_data->identification_data[i].name) - 1); + face_data->identification_data[i].name[sizeof(face_data->identification_data[i].name) - 1] = '\0'; + face_data->identification_data[i].score = score->valuedouble * 100; + } + } + } + } + else + { + // printf("setting name to null 3\n"); + } + + cJSON* template_data = cJSON_GetObjectItem(face_item, "template_data"); + if (template_data != NULL && cJSON_IsObject(template_data)) { + cJSON* template_value = cJSON_GetObjectItem(template_data, "template"); + if (template_value != NULL && cJSON_IsString(template_value)) { + strncpy(face_data->template_data.template_value, template_value->valuestring, sizeof(face_data->template_data.template_value)); + face_data->template_data.template_value[sizeof(face_data->template_data.template_value) - 1] = '\0'; + } + } +} + +void face_data_parser() +{ + int FaceDataSize; + char *FaceDataBuffer; + // int iCurrentRead = 0; + // int iDoCreateJson = 0; + + // BUG4: 修正 while(1) 改為 while(條件式檢查) + while (unlockingKeyInnoFR_success) + // while (1) + { + if (FaceQueueSize() > 0) + { + + FaceFrameData qPopFaceData = {0}; + + qPopFaceData = FaceQueueFront(); + FaceQueuePop(); + + FaceDataBuffer = qPopFaceData.frame_buffer; + FaceDataSize = qPopFaceData.iDataSize; + // printf("face data : %s \n", qPopFaceData.frame_buffer); + // printf("face size : %d \n", qPopFaceData.iDataSize); + // printf("-----\n"); + + // 解析 JSON 資料 + cJSON* root = cJSON_Parse(FaceDataBuffer); + if (root == NULL) { + // printf("Error parsing JSON: %s\n", cJSON_GetErrorPtr()); + } + else { + // 創建 FaceDataInfo 實例 + FaceDataInfo face_data_info = { 0 }; + + // 解析 timestamp + cJSON* timestamp = cJSON_GetObjectItem(root, "timestamp"); + if (timestamp != NULL && cJSON_IsObject(timestamp)) { + cJSON* seconds = cJSON_GetObjectItem(timestamp, "seconds"); + cJSON* nanos = cJSON_GetObjectItem(timestamp, "nanos"); + if (seconds != NULL && cJSON_IsNumber(seconds) && nanos != NULL && cJSON_IsNumber(nanos)) { + face_data_info.timestamp.seconds = seconds->valueint; + face_data_info.timestamp.nanos = nanos->valueint; + } + } + else { + face_data_info.timestamp.seconds = 0; + face_data_info.timestamp.nanos = 0; + } + + + // 解析 frame_number + cJSON* frame_number = cJSON_GetObjectItem(root, "frame_number"); + if (frame_number != NULL && cJSON_IsNumber(frame_number)) { + face_data_info.frame_number = frame_number->valueint; + } + else { + face_data_info.frame_number = -1; + } + + // 解析 face_data + cJSON* face_data = cJSON_GetObjectItem(root, "face_data"); + if (face_data != NULL && cJSON_IsArray(face_data)) { + int face_count = cJSON_GetArraySize(face_data); + //printf("Number of faces: %d\n", face_count); + + face_data_info.face_count = face_count; + + for (int i = 0; i < face_count; i++) { + cJSON* face_item = cJSON_GetArrayItem(face_data, i); + parse_face_data(face_item, &face_data_info.face_data[i]); + + // 在這裡可以對 face_data_info 做進一步處理 + + } + } + else { + //printf("Error reading face_data\n"); + face_data_info.face_count = 0; + } + + // 釋放 cJSON 的內存 + cJSON_Delete(root); + + // printf("face data parser end \n"); + //printf("face data struct frame_number = %d \n", face_data_info.frame_number); +#ifdef FACE_AMBA_DEBUG + printf("face data struct frame_number = %d \n", face_data_info.frame_number); +#endif + if (g_check_sync_face == 0) { + memset(&g_face_data_info, 0, sizeof(g_face_data_info)); + memcpy(&g_face_data_info, &face_data_info, sizeof(face_data_info)); + g_check_sync_face = 1; + } + + } + } + + usSleep(125000); + } +} + + + + +void base64_to_tpl(char* base64_data, char* output_filename) { + + + // char* base64_data = "SUNGADFXBwT+9gL6Afn6APz4C/r8AAb8C/z///4BAgb2/fsB/gcBC//0A/oL//oCBAT+Af8JAf/9/fn++Pn/BwD/BgL/A/f2CAQB+fr++AP8Af8CBwIGBAkIAgj9/wL+Bgr59/4B/P8G/QsD+QYCB/UEAQEM/PsG/v4CAQIJ/vsAAf74+AL69wH/AP/9BvoG/AYG9fj7AQMCAggKCQUBBAQF//oAAf0I+gH1//v7+gT4+v8HAwMEBAT7/fz2AgT8+wb7+v0CBAD5CgMC/gIB9voE//wG9/4DBfT++/YDBAQEBPkC/gEMCPj7AwIH/AAB/vn9DP37AfoB+/32BQEB/wAEA/0HAQD2AAb9/QD9AgkJCwf9AwT9+/76BAj1CvoADP4L+vX19gz8/AP5/QYI//73/wkBAAQDCAACCPgLA/f9APT7AwT6/fn7//wF/PYABgr5DAT2+ggH/vz+/AAFAgEGAAUABAAD/Pr+Av78CPn+/gH6+gICBv34AgUH/vv7A/4G+PoE+v4C/wr9AQL6CfsH9f0HAgQFCAv+9f7/B/8IAgMADAf5BgwC/PwJ+f0AAAEC+wP9CQb++gML/vz6CwUD///3AwT+/vwC+wAEBQb9+Ab9Av8G/vr0/gf9Bvv1BfQC//j6/Pr9Avb0/f0A9P//BwAAAwYE/v33BfoC9fX7/An7AP1/6bz/"; + // char* output_filename = "/emmc/plugin/Aida_data/storage/face/template.tpl"; + FILE* output_file = fopen(output_filename, "wb"); + if (output_file == NULL) { + printf("Unable to open the output file.\n"); + return; + } + + + int base64_data_len = strlen(base64_data); + size_t decoded_data_len = 0; + if(base64_data_len % 4 != 0){ +#ifdef FACE_AMBA_DEBUG + printf("[base64_to_tpl]base64_data_len before: %d",base64_data_len); +#endif + add_padding(base64_data, &base64_data_len); +#ifdef FACE_AMBA_DEBUG + printf(", after: %d\n",base64_data_len); +#endif + } + + unsigned char* decoded_data = (unsigned char*)malloc(base64_data_len); + if (decoded_data == NULL) { + // malloc 分配內存失敗 + printf("Memory allocation failed.\n"); + + } +#ifdef FACE_AMBA_DEBUG + // printf("[base64_to_tpl]=== save_base64_image base64_data: %s .base64_data_len: %zu\n", base64_data, base64_data_len); +#endif + // base64_decode(const char *data, size_t input_length, size_t *output_length, unsigned char * decoded_data) + base64_decode(base64_data, base64_data_len, &decoded_data_len, decoded_data); + + + errno = 0; + if (fwrite(decoded_data, decoded_data_len, 1, output_file) != 1) { +#ifdef FACE_AMBA_DEBUG + printf("[base64_to_tpl] fwrite FAILL output_filename=%s !!\n", output_filename); +#endif + if (errno != 0) { + // 發生錯誤,根據實際情況處理錯誤原因,可以使用 perror 函式打印錯誤訊息 + perror("fwrite error"); + // Fail + } + } else { +#ifdef FACE_AMBA_DEBUG + // Sucess + printf("[base64_to_tpl] fwrite Success output_filename=%s !!\n",output_filename); +#endif + } +#ifdef FACE_AMBA_DEBUG + printf("[base64_to_tpl] === save_base64_image decoded_data: %s .decoded_data len:%zu\n", decoded_data, decoded_data_len); + printf("[base64_to_tpl] Base64 image has been saved as:%s\n", output_filename); +#endif + if(decoded_data != NULL){ + free(decoded_data); + decoded_data = NULL; + } + if(output_file != NULL) + fclose(output_file); + +} + + +char *readJsonFile(const char *filePath) { + FILE *file = fopen(filePath, "r"); + if (file == NULL) { + perror("Error opening file"); + return NULL; + } + + fseek(file, 0, SEEK_END); + long fileSize = ftell(file); + fseek(file, 0, SEEK_SET); + + char *fileContent = (char *)malloc(fileSize + 1); + + fread(fileContent, 1, fileSize, file); + fclose(file); + + fileContent[fileSize] = '\0'; + return fileContent; +} + +void writeJsonToFile(const char *filePath, const char *jsonData) { + FILE *file = fopen(filePath, "w"); + if (file == NULL) { + perror("Error opening file"); + return; + } + + fprintf(file, "%s", jsonData); + fclose(file); +} + + +// BUG5: 修正 Single Entry, Single Exit +void getContractSignature(char *newSignature,char *formatted_mac) { + const char *filePath = "//emmc/plugin/Aida_data/sfe/iengine.lic"; // 修正路徑 + + char *inputJson = readJsonFile(filePath); + cJSON *root = NULL; + char *newJsonStr = NULL; + char buf_cust[256] = { 0 }; + + if (inputJson != NULL) { + root = cJSON_Parse(inputJson); + if (root != NULL) { + cJSON *contract_signature = cJSON_GetObjectItem(root, "contract_signature"); + cJSON *contract = cJSON_GetObjectItem(root, "contract"); + cJSON *expiration = cJSON_GetObjectItem(root, "expiration"); + + if (contract_signature) { + //cJSON_DeleteItemFromObject(root, "contract_signature"); + //cJSON_AddStringToObject(root, "contract_signature", newSignature); + strcpy(newSignature, contract_signature->valuestring); + } + + if (contract) { + cJSON *hwids = cJSON_GetObjectItem(contract, "hwids"); + cJSON *customer = cJSON_GetObjectItem(contract, "customer"); + cJSON *expiration = cJSON_GetObjectItem(contract, "expiration"); + + if (customer) { + strcpy(buf_cust, customer->valuestring); + } + + if (hwids) { + cJSON *hwid_array = cJSON_GetArrayItem(hwids, 0); + if (hwid_array != NULL) { + //cJSON_ReplaceItemInArray(hwids, 0, cJSON_CreateString(formatted_mac)); + strcpy(formatted_mac, hwid_array->valuestring); + } + } + + if (expiration) { + cJSON *cJSON_day = cJSON_GetObjectItem(expiration, "day"); + cJSON *cJSON_month = cJSON_GetObjectItem(expiration, "month"); + cJSON *cJSON_year = cJSON_GetObjectItem(expiration, "year"); + + int face_expiration_year = 0; + int face_expiration_month = 0; + int face_expiration_day = 0; + + if (cJSON_day) { + face_expiration_day = cJSON_day->valueint; + } + + if (cJSON_month) { + face_expiration_month = cJSON_month->valueint; + } + + if (cJSON_year) { + face_expiration_year = cJSON_year->valueint; + } + + if (face_expiration_day >= 1 && face_expiration_month >= 1 && face_expiration_year >= 1) { + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + int current_year = 1900 + timeinfo->tm_year; + int current_month = 1 + timeinfo->tm_mon; + int current_day = timeinfo->tm_mday; + + //printf("\n--------g_try_websocket_face:%d\n", g_try_websocket_face); + + memset(strLicenseStatus,0x00,sizeof(strLicenseStatus)); + if (g_try_websocket_face == 0 && face_expiration_year > current_year) { + sprintf(strLicenseStatus, "expiration:%d-%d-%d,hwids:%s,customer:%s", face_expiration_year, face_expiration_month, face_expiration_day, formatted_mac, buf_cust); + } + else if (face_expiration_year == current_year) { + int temp_current_day = (current_month-1) * 32 + current_day; + int face_current_day = (face_expiration_month - 1) * 32 + face_expiration_day; + + if (g_try_websocket_face >= 1 || face_current_day <= temp_current_day) { + sprintf(strLicenseStatus, "Trial has expired. expiration:%d-%d-%d,hwids:%s,customer:%s", face_expiration_year, face_expiration_month, face_expiration_day, formatted_mac, buf_cust); + } + else { + sprintf(strLicenseStatus, "expiration:%d-%d-%d,hwids:%s,customer:%s", face_expiration_year, face_expiration_month, face_expiration_day, formatted_mac, buf_cust); + } + } + else if (face_expiration_year < current_year) { + sprintf(strLicenseStatus, "Trial has expired. expiration:%d-%d-%d,hwids:%s,customer:%s", face_expiration_year, face_expiration_month, face_expiration_day, formatted_mac, buf_cust); + } + } + } + } + + newJsonStr = cJSON_Print(root); + + } + } + + if (root != NULL) { + cJSON_Delete(root); + } + + if (inputJson != NULL) { + free(inputJson); + } + + if (newJsonStr != NULL) { + writeJsonToFile(filePath, newJsonStr); + free(newJsonStr); + } +} +/* +// Leo Version +void getContractSignature(char *newSignature) { + + + // char *filePath = "//emmc/plugin/Aida_data/iengine.lic"; // fix path + const char *filePath = "//emmc/plugin/Aida_data/sfe/iengine.lic"; // fix path + + // const char *newSignature = "new_contract_signature_here"; + + char *inputJson = readJsonFile(filePath); + if (inputJson == NULL) { + return ; + } + + cJSON *root = cJSON_Parse(inputJson); + if (root == NULL) { + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) { + fprintf(stderr, "Error before: %s\n", error_ptr); + } + return; + } + + cJSON *contract_signature = cJSON_GetObjectItem(root, "contract_signature"); + if (contract_signature) { + cJSON_DeleteItemFromObject(root, "contract_signature"); + cJSON_AddStringToObject(root, "contract_signature", newSignature); + } + + char *newJsonStr = cJSON_Print(root); + + // 打印修改后的 JSON 字符串 + //printf("%s\n", newJsonStr); + + writeJsonToFile(filePath, newJsonStr); + + cJSON_Delete(root); + + if(newJsonStr != NULL){ + free(newJsonStr); + newJsonStr = NULL; + } + if(inputJson != NULL){ + free(inputJson); + inputJson = NULL; + } + +} +*/ + +/* +int faceengine_start() { + + // printf("[faceengine_start] 1 Sleep(5000);\n"); + // usSleep(5000000); + // printf("[faceengine_start] 2\n"); + + const char* command = "//root/sfe/faceengine start"; // The command to execute + const char* substringToCheck = "Found license is not valid."; + const char* substringToCheck1 = "Slove Error:"; + const char* substringToCheck2 = "faceengine Start End"; + char buffer[128]; + + // Execute the command and capture the output stream + FILE* fp = vpopen(command, "r"); + if (fp == NULL) { + printf("Error opening pipe.\n"); + return -1; + } + + // Read the content of the output stream + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + // printf("[faceengine_start] 2 : %d\n",sizeof(buffer)); + // printf("Output: %s", buffer); + + // Check if the output contains the specified substring + if (strstr(buffer, substringToCheck) != NULL) { + printf("The output contains the specified substring.\"Found license is not valid.\"\n"); + pclose(fp); + return 0; // Return 1 if the substring is found + } + // Check if the output contains the specified substring + if (strstr(buffer, substringToCheck1) != NULL) { + printf("The output contains the specified substring. \"Slove Error:\"\n"); + printf("faceengine_start fail : %s\n", strstr(buffer, substringToCheck1)); + pclose(fp); + return -1; // Return 1 if the substring is found + } + // Check if the output contains the specified substring + if (strstr(buffer, substringToCheck2) != NULL) { + printf("The output contains the specified substring. \"faceengine Start End\"\n"); + pclose(fp); + return 1; // Return 1 if the substring is found + } + } + + // Close the stream + pclose(fp); + printf("popen end\n"); + + return 1; // Return 0 if the substring is not found +} +*/ + +//#define SHELLSCRIPT_FACE_SERVER "sh /emmc/plugin/Aida_data/run_face_server.sh" +int faceengine_start() { + + //system(SHELLSCRIPT_FACE_SERVER); + +#if 1 + int result = -1; + + // printf("[faceengine_start] 1 Sleep(5000);\n"); + // printf("[faceengine_start] 2\n"); + + // const char* command = "//root/sfe/faceengine start"; // The command to execute + const char* command = "//emmc/plugin/Aida_data/sfe/faceengine start"; // The command to execute + const char* substringToCheck = "Found license is not valid."; + const char* substringToCheck1 = "Slove Error:"; + const char* substringToCheck2 = "faceengine Start End"; + char buffer[512] = { 0 }; + + // Execute the command and capture the output stream + FILE* fp = vpopen(command, "r"); + if (fp == NULL) { + printf("Error opening pipe.\n"); + result = -1; + } + else { + // Read the content of the output stream + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + // printf("[faceengine_start] 2 : %d\n",sizeof(buffer)); + // printf("Output: %s", buffer); + + // Check if the output contains the specified substring + if (strstr(buffer, substringToCheck) != NULL) { + // printf("The output contains the specified substring.\"Found license is not valid.\"\n"); + printf("\"Found license is not valid.\"\n"); + g_try_websocket_face = 5; + result = 0; + break; + } + // Check if the output contains the specified substring + else if (strstr(buffer, substringToCheck1) != NULL) { + // printf("The output contains the specified substring. \"Slove Error:\"\n"); + printf("\"Slove Error:\"\n"); + printf("faceengine_start fail : %s\n", strstr(buffer, substringToCheck1)); + g_try_websocket_face = 5; + result = -1; + break; + } + // Check if the output contains the specified substring + else if (strstr(buffer, substringToCheck2) != NULL) { + // printf("The output contains the specified substring. \"faceengine Start End\"\n"); + printf("\"faceengine Start End\"\n"); + result = 1; + break; + } + } + + // Close the stream + if (fp != NULL) { + vpclose(fp); + fp = NULL; + } + // printf("popen end\n"); + } +#endif + return result; // Return 0 if the substring is not found +} + + +int faceengine_start_and_check_license(){ + + + int command_result = faceengine_start(); + int result = 0; + //faceengine_start(); + // printf("[faceengine_start] 3 Sleep(5000);\n"); + //usSleep(1000000); + // printf("[faceengine_start] 4\n"); + + char cmd_1[256] = "/emmc/plugin/Aida_data/sfe/faceengine stop"; + FILE *read_port = vpopen(cmd_1, "r"); + if (read_port != NULL) + vpclose(read_port); + // BUG5: 修正 Single Entry, Single Exit + if (command_result == 1) { + printf("Inno Face Recognition Start Success!! \n"); + result = 1; + // return 0; + } else if (command_result == 0) { + printf("Inno Face Recognition License is not valid!! \n"); + // return 0; + } else { + printf("Inno Face Recognition Start Fail!! \n"); + // return 0; + } + return result; +} + +void copyFile(const char *srcPath, const char *destPath) { + FILE *srcFile = fopen(srcPath, "rb"); + FILE *destFile = fopen(destPath, "wb"); + + if (srcFile && destFile) { + char buffer[1024]; + size_t bytesRead; + + while ((bytesRead = fread(buffer, 1, sizeof(buffer), srcFile)) > 0) { + fwrite(buffer, 1, bytesRead, destFile); + } + + fclose(srcFile); + fclose(destFile); + } +} + +void copyDirectory(const char *srcDir, const char *destDir) { + DIR *dir = opendir(srcDir); + if (dir) { + struct dirent *entry; + struct stat fileInfo; + + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { + char srcPath[PATH_MAX]; + char destPath[PATH_MAX]; + snprintf(srcPath, sizeof(srcPath), "%s/%s", srcDir, entry->d_name); + snprintf(destPath, sizeof(destPath), "%s/%s", destDir, entry->d_name); + + stat(srcPath, &fileInfo); + if (S_ISDIR(fileInfo.st_mode)) { + mkdir(destPath, 0755); + copyDirectory(srcPath, destPath); + } else { + copyFile(srcPath, destPath); + } + } + } + + closedir(dir); + } +} + diff --git a/src/face_parser.h b/src/face_parser.h new file mode 100644 index 0000000..26c8e6d --- /dev/null +++ b/src/face_parser.h @@ -0,0 +1,134 @@ + +#pragma once +#ifndef FACE_PARSER_H_ +#define FACE_PARSER_H_ +#include "define_inc.h" +#include "setting.h" +//#include "websocket_client.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define MAX_FACE_DATA_SIZE 8192*13 +#define Face_QUEUE_SIZE 10 + +typedef struct +{ + char frame_buffer[MAX_FACE_DATA_SIZE]; + int iDataSize; + +} FaceFrameData; + +// 定義bounding_box結構 +typedef struct { + float x; + float y; + float width; + float height; +} BoundingBox; + +// 定義face_detection_data結構 +typedef struct { + BoundingBox bounding_box; + float detection_confidence; + float raw_detection_confidence; +} FaceDetectionData; + +// 定義face_tracking_data結構 +typedef struct { + int tracking_id; + char tracking_uuid[37]; // UUID字串的長度為36,再加上結尾的'\0' + int tracking_state; +} FaceTrackingData; + +// 定義crop_box結構 +typedef struct { + float x; + float y; + float width; + float height; +} CropBox; + +// 定義crop_image結構 +typedef struct { + int width; + int height; + char data[8192 * 4]; // 設定一個適當大小的字串陣列來存儲圖像數據 + int image_format; +} CropImage; + +// 定義identification_data結構 +typedef struct { + int id; + char name[50]; // 假設名稱長度不超過50個字符 + double score; +} IdentificationData; + +// 定義cropping_data結構 +typedef struct { + int crop_extension; + CropBox crop_box; + CropImage crop_image; +} CroppingData; + +typedef struct { + char template_value[8192]; +} TemplateData; + +// 定義face_data結構 +typedef struct { + FaceDetectionData face_detection_data; + FaceTrackingData face_tracking_data; + CroppingData cropping_data; + IdentificationData identification_data[20]; // 假設最多有10個識別資料 + TemplateData template_data; + char FACE_BMP[60]; +} FaceData; + +// 定義主要資料結構 +typedef struct { + struct { + int seconds; + int nanos; + } timestamp; + int frame_number; + char frame_image[1024]; // 假設圖像資料的大小不超過1024個字符 + FaceData face_data[20]; // 假設最多有10個臉部資料 + int face_count; +} FaceDataInfo; + +//extern int g_save_base64_img_tmp; +extern int g_face_frame_uid; +extern int g_check_sync_face; +extern int unlockingKeyInnoFR_success; + +extern char strLicenseStatus[MAX_MSG_LEN]; +extern int g_try_websocket_face; + +void FaceQueuePush(FaceFrameData q_info); +FaceFrameData FaceQueueFront(); +void FaceQueuePop(); +int FaceQueueSize(); +int FaceQueueIsEmpty(); +void FaceQueueClear(); + +void face_data_get(const char *recv_data, int recv_len); +void face_data_parser(); +void save_base64_image(char* base64_data, const char* output_filename); +int test_sfe_add_face_group(char* tracking_uuid, char* file_path); +void base64_to_tpl(char* base64_data, char* output_filename); +void getContractSignature(char *newSignature, char *formatted_mac); +int faceengine_start(); +//void faceengine_start(); +int faceengine_start_and_check_license(); + +extern FaceDataInfo g_face_data_info; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/face_req.c b/src/face_req.c new file mode 100644 index 0000000..dfa91cf --- /dev/null +++ b/src/face_req.c @@ -0,0 +1,149 @@ +#include "network.h" +#include "curl/curl.h" +#include "curl/easy.h" + + + +size_t face_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream) { + /* + time_t timep; + struct tm * timeinfo; + time(&timep); + timeinfo = localtime(&timep); + */ + size_t realsize = size * nmemb; + //cJSON *r_root, *r_tstamp; + + //time_t r_timep; + //struct tm * r_timeinfo; + //time(&timep); + if (stream) + { + //printf("Magic: %s \n", (char *)stream); + //free(stream); + + sprintf((char *)stream, "%s", (char *)ptr); + return realsize; + } + else + { + return 0; + } + + //printf(">>>>>>>>>>>>> Get PTZ Curl resp:\n %s \n", (char *)ptr); + //printf(">>>>>>>>>>>>> Response Time: %d-%02d-%02d ", (1900 + timeinfo->tm_year), (1 + timeinfo->tm_mon), timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + +} + +//sUrl: strcat(sUrl, "http://127.0.0.1/api/v1/WatchlistMembers"); + +int net_curl_face_req_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id) +{ + //pthread_mutex_lock(&mutex_send_cgi); + + CURL *curl = NULL; + CURLcode l_res; + int l_ret = -1; + //const int timeout = 30000; + //const int timeout = 100; + //char *sBuffer; + //char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + curl = curl_easy_init(); + + struct curl_slist *pList = NULL; + + char response_data[512] = { 0 }; + //char *response_data; + //response_data = malloc(512); + strcat(response_data, "mmmmmmmmmmmmmmagic"); + + if (curl != NULL) + { + + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type:application/json"); + pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //Connection: close + } + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Connection: close"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); + + //time_t s_timep = time(0); + //struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + //char test_countent[25] = { 0 }; + //strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + + curl_easy_setopt(curl, CURLOPT_URL, sUrl); + if (strcmp(method, "DELETE") == 0) + { + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + } + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); + curl_easy_setopt(curl, CURLOPT_PORT, iPort); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, face_cmd_curl_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, sOutputData); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "LILIN"); + + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + + curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); + + if (strcmp(method, "POST") == 0) + { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); + curl_easy_setopt(curl, CURLOPT_POST, 1L); + } + + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // ]wsuWɡA + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1000); + + curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + l_res = curl_easy_perform(curl); + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + //char temp_msg[8192] = { 0 }; + //snprintf(temp_msg,sizeof(temp_msg), "%s:%s", curl_easy_strerror(l_res), function_id); + //write_to_logs_html(temp_msg, "curl to ptz status", "ERROR", SystemSetting.enable_system_logs); + //l_ret = -1; + } + else { + //char temp_msg[8192] = { 0 }; + //snprintf(temp_msg,sizeof(temp_msg), "%s:%s", "OK", function_id); + //write_to_logs_html(temp_msg, "curl to ptz status", "DEBUG", SystemSetting.enable_system_logs); + l_ret = 0; + } + } + + curl_easy_cleanup(curl); + if(pList != NULL) + curl_slist_free_all(pList); + pList = NULL; + + //pthread_mutex_unlock(&mutex_send_cgi); + + return l_ret; +} \ No newline at end of file diff --git a/src/face_req.h b/src/face_req.h new file mode 100644 index 0000000..2e12fb7 --- /dev/null +++ b/src/face_req.h @@ -0,0 +1,12 @@ +#if 1 +#pragma once +#ifndef FACE_REQ_H +#define FACE_REQ_H +#include "define_inc.h" +size_t face_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream); + +int net_curl_face_req_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id); + +#endif +#endif \ No newline at end of file diff --git a/src/fflpr_plate_db.c b/src/fflpr_plate_db.c new file mode 100644 index 0000000..4b10508 --- /dev/null +++ b/src/fflpr_plate_db.c @@ -0,0 +1,5372 @@ + +#include "fflpr_plate_db.h" + + +int g_ftp_condition_channel=1; +int g_httppost_condition_channel=1; +int g_ftp_status=0; +int g_httppost_status=0; + +//pthread_mutex_t mutex_db_sql_ffgroup; +database_info_t g_ffgroup_db_info = {0}; +pthread_mutex_t mutex_db_lpr_Log; + +pthread_mutex_t mutex_db_lpr_add; + +pthread_mutex_t mutex_db_lpr_import; +pthread_mutex_t mutex_db_lpr_insert_list; +pthread_mutex_t mutex_db_lpr_insert_db; + +int cgi_download_lprdb_log_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount); +int cgi_download_lprdb_list_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount); +int cgi_download_lprdb_mapping_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int map_icount); + +static char g_MOD_TS[256] = {0}; + +//Config *pConfig; +void getvalueForKey(char *keyValue, char *key, char *value) +{ + char *end = NULL; + char *p = keyValue; + p = strstr(p, key); + if (p == NULL) + { + return; + } + p = p + strlen(key); + p = strstr(p, "="); + if (p == NULL) + { + return; + } + p = p + strlen("="); + end = strstr(p, "&"); + if(end != NULL) + { + memcpy(value, p, strlen(p) - strlen(end)); + return; + } + strcpy(value, p); + return; +} +char *rtrim(char *str) +{ + if (str == NULL || *str == '\0') + { + return str; + } + + int len = strlen(str); + char *p = str + len - 1; + while (p >= str && isspace(*p)) + { + *p = '\0'; + --p; + } + + return str; +} +void lprdb_mutex_lock(sqlite3 *pdb) +{ + pthread_mutex_lock(&mutex_db_lpr_Log); + sqlite3_mutex_enter(sqlite3_db_mutex(pdb)); +} + +void lprdb_mutex_unlock(sqlite3 *pdb) +{ + sqlite3_mutex_leave(sqlite3_db_mutex(pdb)); + pthread_mutex_unlock(&mutex_db_lpr_Log); +} + +void chk_log_data(char *odata,const char *idata) +{ + if(strcmp(idata,"")==0) + sprintf(odata,"%s" ,""); + else + sprintf(odata,"%s" ,idata); +} +void chk_sql_msg_tbname(char *ndata,char *listname) +{ + if(strcmp(listname,BKLISTNAME)==0) + { + sprintf(ndata,"%s",LPR_MSG_BLACKTABLE); + } + else if(strcmp(listname,CUSTLISTNAME)==0) + { + sprintf(ndata,"%s",LPR_MSG_CUSTOMERTABLE); + } + else if(strcmp(listname,WTLISTNAME)==0) + { + sprintf(ndata,"%s",LPR_MSG_WHITETABLE); + } + else if(strcmp(listname,LOGLISTNAME)==0) + { + sprintf(ndata,"%s",LPR_MSG_TABLE); + } + else if(strcmp(listname,MAPPINGNAME)==0) + { + sprintf(ndata,"%s",LPR_MAPPING_TABLE); + } +} +void chk_import_dbname(char *ndata,char *plate_type) +{ + if(strcmp(plate_type,ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,BKLISTNAME); + else if(strcmp(plate_type,ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,WTLISTNAME); + else if(strcmp(plate_type,WTLISTNAME)==0) + strcpy(ndata,WTLISTNAME); + else if(strcmp(plate_type,BKLISTNAME)==0) + strcpy(ndata,BKLISTNAME); + else if(strcmp(plate_type,S_ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,BKLISTNAME); + else if(strcmp(plate_type,S_ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,WTLISTNAME); +} +void trans_download_plate_type(char *ndata,char *iACT_PARAM) +{ + if(strcmp(iACT_PARAM,BKLISTNAME)==0) + strcpy(ndata,ACT_PARAM_BKLISTNAME); + else if(strcmp(iACT_PARAM,WTLISTNAME)==0) + strcpy(ndata,ACT_PARAM_WTLISTNAME); + else if(strcmp(iACT_PARAM,ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,ACT_PARAM_BKLISTNAME); + else if(strcmp(iACT_PARAM,ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,ACT_PARAM_WTLISTNAME); + else if(strcmp(iACT_PARAM,S_ACT_PARAM_BKLISTNAME)==0) + strcpy(ndata,ACT_PARAM_BKLISTNAME); + else if(strcmp(iACT_PARAM,S_ACT_PARAM_WTLISTNAME)==0) + strcpy(ndata,ACT_PARAM_WTLISTNAME); +} +int db_get_lpr_version() +{ + char l_sql[64] = {0}; + int l_log_db_version = 0; + int l_rc = 0; + + //if(!g_ffgroup_db_info) return 0; + + sprintf(l_sql, "%s", CMD_QUERY_LPR_VERSION); + if (g_ffgroup_db_info.pdb) { + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + //db_lock(g_log_db_info->pdb); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + if (l_rc != 0) + { + printf("####### Error: Can't prepare SQL:%s\n", l_sql); + //sqlite_restore_database(g_ffgroup_db_info.pdb); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + //db_unlock(g_ffgroup_db_info.pdb); + return -1; + } + + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + if (l_rc != 0) + { + printf("####### Error: Can't Step SQL:%s\n", l_sql); + //sqlite_restore_database(g_ffgroup_db_info.pdb); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + //db_unlock(g_ffgroup_db_info.pdb); + return -1; + } + + l_log_db_version = db_get_column_value_int(g_ffgroup_db_info.pstmt, 0); + + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + //db_unlock(g_log_db_info->pdb); + } + return l_log_db_version; +} + +int fflpr_log_db_init() +{ + char *l_db_name = NULL, *l_db_dirname = NULL; + struct stat l_db_dir_st; + + int l_log_version = l_log_version; + int l_ret = 0; + char l_sql_create_cmd[1024]={0}; + //pthread_mutex_init(&mutex_db_sql_ffgroup ,NULL); + pthread_mutex_init(&mutex_db_lpr_add ,NULL); + pthread_mutex_init(&mutex_db_lpr_insert_db ,NULL); + pthread_mutex_init(&mutex_db_lpr_import ,NULL); + pthread_mutex_init(&mutex_db_lpr_insert_list ,NULL); + + + //if(!g_ffgroup_db_info) + { + //g_ffgroup_db_info = (database_info_t *)malloc(sizeof(database_info_t)); + //memset(g_ffgroup_db_info,0x00,sizeof(database_info_t)); + /* + if(!g_ffgroup_db_info) + { + //printf("Error: License Plate Db Init Fail...\n"); + + return -1; + }*/ + g_ffgroup_db_info.pdb = NULL; + } + + l_db_name = strdup(DB_FFGROUP_MSG_PATH); + + l_db_dirname = dirname(l_db_name); + + if(stat(l_db_dirname, &l_db_dir_st)) + { + //printf("Create License Plate Db directoy: %s\n", l_db_dirname); + mkdir(l_db_dirname, S_IRWXU | S_IRWXG | S_IRWXO); + } + + if (l_db_name) { + free(l_db_name); + l_db_name = NULL; + } + + snprintf(g_ffgroup_db_info.db_name, sizeof(g_ffgroup_db_info.db_name)-1, "%s", DB_FFGROUP_MSG_PATH); + + if(g_ffgroup_db_info.pdb) sqlite3_close(g_ffgroup_db_info.pdb); + + l_ret = sqlite3_open_v2(g_ffgroup_db_info.db_name, &g_ffgroup_db_info.pdb, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL); + + //printf("\nxXX l_ret:%d", l_ret); + + if (l_ret != SQLITE_OK) + { + printf("####### Error: Open License Plate Db %s Fail...\n", g_ffgroup_db_info.db_name); + + return -1; + } + + if(db_check_table_exist(g_ffgroup_db_info.pdb, TABLE_LPR_VERSION) == 0) + { + db_exec_sql(g_ffgroup_db_info.pdb, CMD_DROP_LPR_MSG_TABLE); + db_exec_sql(g_ffgroup_db_info.pdb, CMD_CREATE_LPR_VERSION_TABLE); + + struct timeval l_now_time = {0,0}; + struct tm *l_tm_ptr = NULL; + char l_date_str[64] = {0}; + char l_sql[256] = {0}; + + gettimeofday(&l_now_time, NULL); + l_tm_ptr = localtime(&l_now_time.tv_sec); + strftime(l_date_str, sizeof(l_date_str)-1, "%Y/%m/%d %H:%M:%S", l_tm_ptr); + + sprintf(l_sql, LPR_INSERT_VERSION, 0, l_date_str, "Create License Plate Db Beta Version"); + db_exec_sql(g_ffgroup_db_info.pdb, l_sql); + } + + //Create LPR Log Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_LPR_TABLE,LPR_MSG_TABLE); + db_exec_sql(g_ffgroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR Log INDEX Table + db_exec_sql(g_ffgroup_db_info.pdb, CMD_CREATE_LPR_INDEX); + + //Create LPR BLACK Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_LPRLIST_TABLE,LPR_MSG_BLACKTABLE); + db_exec_sql(g_ffgroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR WHITE Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_LPRLIST_TABLE,LPR_MSG_WHITETABLE); + db_exec_sql(g_ffgroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR CUSTOMER Table + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_LPRLIST_TABLE,LPR_MSG_CUSTOMERTABLE); + db_exec_sql(g_ffgroup_db_info.pdb, l_sql_create_cmd); + + //Create LPR MAPPING TABLE + snprintf(l_sql_create_cmd, sizeof(l_sql_create_cmd)-1, CMD_CREATE_LPR_MAPPING_TABLE,LPR_MAPPING_TABLE); + db_exec_sql(g_ffgroup_db_info.pdb, l_sql_create_cmd); + + //printf("\n------CMD_CREATE_LEVENSHTEIN\n"); + sqlite3_extension_init(g_ffgroup_db_info.pdb); + //printf("\n------CMD_CREATE_LEVENSHTEIN---end\n"); + //set sqlite environment parameters + + db_exec_sql(g_ffgroup_db_info.pdb,"PRAGMA encoding=\"UTF-8\";"); + db_exec_sql(g_ffgroup_db_info.pdb,"PRAGMA journal_mode=DELETE;"); + db_exec_sql(g_ffgroup_db_info.pdb,"PRAGMA synchronous = FULL;"); + db_exec_sql(g_ffgroup_db_info.pdb,"PRAGMA page_size=4096;"); + + return l_ret; +} + +void get_fflpr_db_import() { + //int l_result = 0; + int l_db_length = 0; + + if (g_ffgroup_db_info.pdb) + { + /* + if (strncmp(l_lpr_cgi_param, CUSTLISTNAME, strlen(CUSTLISTNAME)) == 0) + { + cgi_get_db_lpr_log(socket_in, LPR_MSG_CUSTOMERTABLE, CUSTLISTNAME, COUNT_CUSTOMER); + } + else if (strncmp(l_lpr_cgi_param, BKLISTNAME, strlen(BKLISTNAME)) == 0) + { + cgi_get_db_lpr_log(socket_in, LPR_MSG_BLACKTABLE, BKLISTNAME, COUNT_BLACK); + } + else if (strncmp(l_lpr_cgi_param, WTLISTNAME, strlen(WTLISTNAME)) == 0) + { + cgi_get_db_lpr_log(socket_in, LPR_MSG_WHITETABLE, WTLISTNAME, COUNT_WHITE); + } + else if (strncmp(l_lpr_cgi_param, LOGLISTNAME, strlen(LOGLISTNAME)) == 0) + { + cgi_get_db_lpr_log(socket_in, LPR_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + }*/ + + //if (strcmp(list_name, LOGLISTNAME) == 0 || strcmp(list_name, CUSTLISTNAME) == 0) + //snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, sum_count); + //else + //snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name, sum_count); + + ffgroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info, 0, sizeof(ffgroup_db_tb)); + char l_sql[256] = { 0 }; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", LPR_MSG_BLACKTABLE, COUNT_BLACK-100); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE); + + { + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + if (l_rc != 0) + { + //printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + l_idx = -1; + } + else + { + if (l_lpr_record_cnts >= COUNT_BLACK - 100) + l_db_length = COUNT_BLACK - 100; + else + l_db_length = l_lpr_record_cnts; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(BKLISTNAME)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "LP_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "LP_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "LP_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "LP_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "LP_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "LPR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "LPR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "LPR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "LPR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "LPR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "LPR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "LPR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "LPR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "LPR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + + printf("\n[get_fflpr_db_import] 123 JsonString:%s\n", JsonString); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + //l_result = l_idx + 1; + } + + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } +} + +void sqlite_fflpr_db_close() +{ + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + //PRINT_INFO_LOG("####### License Plate DB Close\n"); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + //db_lock(g_ffgroup_db_info.pdb); + sqlite3_close(g_ffgroup_db_info.pdb); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + //db_unlock(g_log_db_info->pdb); + } + } +} + +void delete_jpg_in_seven_days() { + + //clock_t t; + //t = clock(); + + /* + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + strcat(cmd, "ls image*.* | xargs -n50000 rm"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + }*/ + + cgi_get_db_lpr_log_delete_jpg(LPR_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + //printf("\nTTTTTTESTTTTTTTTTT:%s\n",g_MOD_TS); + if (strlen(g_MOD_TS) >= 19) + { +#if 1 + g_MOD_TS[10] = '-'; + g_MOD_TS[13] = '-'; + g_MOD_TS[16] = '-'; + const char *del = "-"; + char buf_MOD_TS[10][STRSPLIT_SIZE]={0}; + int num_MOD_TS = 0; + + num_MOD_TS = StrSplit(g_MOD_TS, buf_MOD_TS, del); + //printf("\n------UU:17\n"); + //printf("\nnum_MOD_TS: %d\n", num_MOD_TS); + + + + if (num_MOD_TS == 6) + { + int end_year = atoi(buf_MOD_TS[0]); + int end_month = atoi(buf_MOD_TS[1]); + int end_day = atoi(buf_MOD_TS[2]); + //int end_hour = atoi(buf_MOD_TS[3]); + //int end_min = atoi(buf_MOD_TS[4]); + //int end_sec = atoi(buf_MOD_TS[5]); + + for (int the_past_i_day = 1; the_past_i_day <= 7; the_past_i_day++) { + int temp_day = 0; + int temp_month = 0; + if (end_day - the_past_i_day >= 1) { + temp_day = end_day - the_past_i_day; + temp_month = end_month; + } + else { + temp_month = end_month - 1 >= 1 ? end_month - 1 : 12; + if (temp_month == 1 || temp_month == 3 || temp_month == 5 || temp_month == 7 || temp_month == 8 || temp_month == 10 || temp_month == 12) { + temp_day = 31 - the_past_i_day + 1; + } + else if (temp_month == 4 || temp_month == 6 || temp_month == 9 || temp_month == 11) { + temp_day = 30 - the_past_i_day + 1; + } + else {//temp_month == 2 + temp_day = 28 - the_past_i_day + 1; + if (end_year % 4 == 0 && end_year % 100 != 0 && end_year % 400 == 0) { + temp_day = 29 - the_past_i_day + 1; + } + } + } + + //pthread_mutex_lock(&mutex_send_jpeg); + + for (int the_index_hour = 0; the_index_hour <= 23; the_index_hour++) { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_*.jpg", end_year, temp_month, temp_day,the_index_hour); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_*.jpg", end_year, temp_month, temp_day,the_index_hour); +#endif + pPipe = vpopen(cmd, "r"); + if(pPipe!=NULL) + vpclose(pPipe); + } + //pthread_mutex_unlock(&mutex_send_jpeg); + + usSleep(100000); + } + } + +#endif + } + memset(g_MOD_TS, 0, 256); + //t = clock() - t; + //printf("\nIt took me %d clicks (%f seconds).\n", t, ((float)t) / CLOCKS_PER_SEC); +} + +static int check_finish_delete_jpg = 0; +void *delete_jpg(void * ptr) { + + pthread_detach(pthread_self()); + setPthreadName("delete_jpg"); + + if (check_finish_delete_jpg == 0) { + check_finish_delete_jpg = 1; + //clock_t t; + //t = clock(); + + /* + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + strcat(cmd, "ls image*.* | xargs -n50000 rm"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + }*/ + + cgi_get_db_lpr_log_delete_jpg(LPR_MSG_TABLE, LOGLISTNAME, COUNT_LOG); + //printf("\nTTTTTTESTTTTTTTTTT:%s\n",g_MOD_TS); + if (strlen(g_MOD_TS) >= 19) + { + /* + printf("\n-------[delete_jpg]-----\n"); + printf("\n%s\n", g_MOD_TS); + printf("\n---------end[delete_jpg]------\n"); + */ +#if 1 + g_MOD_TS[10] = '-'; + g_MOD_TS[13] = '-'; + g_MOD_TS[16] = '-'; + const char *del = "-"; + char buf_MOD_TS[10][STRSPLIT_SIZE]={0}; + int num_MOD_TS = 0; + + num_MOD_TS = StrSplit(g_MOD_TS, buf_MOD_TS, del); + //printf("\n------UU:18\n"); + //printf("\nnum_MOD_TS: %d\n", num_MOD_TS); + if (num_MOD_TS == 6) + { + + //delete time length [start,end] + + //int start_year = atoi(buf_MOD_TS[0]); + //int start_month = atoi(buf_MOD_TS[1]); + + int end_year = atoi(buf_MOD_TS[0]); + int end_month = atoi(buf_MOD_TS[1]); + int end_day = atoi(buf_MOD_TS[2]); + int end_hour = atoi(buf_MOD_TS[3]); + int end_min = atoi(buf_MOD_TS[4]); + //int end_sec = atoi(buf_MOD_TS[5]); + +#if 0 + printf("\n%d_%d_%d_%d_%d_%d\n", end_year, end_month, end_day, end_hour, end_min, end_sec); + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_*.jpg", end_year - 1); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/%d_*.jpg", end_year - 1); +#endif + + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_*.jpg", end_year, end_month - 1 >= 1 ? end_month - 1 : 12); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/%d_%d_*.jpg", end_year, end_month - 1 >= 1 ? end_month - 1 : 12); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } +#endif + + //pthread_mutex_lock(&mutex_send_jpeg); + + for (int i = 1; i <= 59; i++) { + int temp_min = end_min - i; + if (temp_min >= 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, end_hour, temp_min); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, end_hour, temp_min); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + usSleep(10); + } + + for (int i = 1; i <= 23; i++) { + int temp_hour = end_hour - i; + if (temp_hour >= 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, temp_hour); +#else + sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/storage/%d_%d_%d_%d_*.jpg", end_year, end_month, end_day, temp_hour); +#endif + + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + usSleep(10); + } + + //pthread_mutex_unlock(&mutex_send_jpeg); + } + + usSleep(100000); +#endif + } + memset(g_MOD_TS, 0, 256); + + //t = clock() - t; + //printf("\nIt took me %d clicks (%f seconds).\n", t, ((float)t) / CLOCKS_PER_SEC); + check_finish_delete_jpg = 0; + } + pthread_exit(NULL); +} + +void callback_insert_lpr_msg_to_db(ffgroup_db_tb *l_ff_insert_data) +{ + //pthread_detach(pthread_self()); + //setPthreadName("insert_lpr"); + //printf("\n[callback_insert_lpr_msg_to_db]pthread create\n"); + + int l_log_record_cnts = 0; + ffgroup_db_tb *lpr_insert_data = l_ff_insert_data; + + int l_sql_ret = 0; + + int l_db_max_len=0; + + if(!lpr_insert_data) + { + + } + else { + //lpr_insert_data = (ffgroup_db_tb *)data; + //printf("\n[callback_insert_lpr_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + //printf("\nXXX lpr_insert_data->sql_tbname:%s\n", lpr_insert_data->sql_tbname); + //if (g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + //db_lock(g_ffgroup_db_info.pdb); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, CMD_QUERY_LOG_DESC); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, lpr_insert_data->sql_tbname);//LPR_MSG_TABLE); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (strcmp(lpr_insert_data->sql_tbname, LPR_MSG_CUSTOMERTABLE) == 0) + { + l_db_max_len = MAX_CUSTOMER_COUNT; + sprintf(lpr_insert_data->sql_count, "%d", COUNT_CUSTOMER); + } + else + { + l_db_max_len = MAX_COUNT; + sprintf(lpr_insert_data->sql_count, "%d", COUNT_LOG); + } + //int l_limitcount=(atoi(lpr_insert_data->sql_count)+DELETECOUNT); + + + if (strcmp(lpr_insert_data->LPR, "") != 0) + { + //printf("\n[callback_insert_lpr_msg_to_db] 1"); + char l_sql_cmd[4096] = { 0 }; + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_LPR_DATA_CMD + , lpr_insert_data->sql_tbname + , lpr_insert_data->TS + , lpr_insert_data->MOD_TS + , lpr_insert_data->CAR_ID + , lpr_insert_data->LPR + , lpr_insert_data->RTIME + , lpr_insert_data->ACTION + , lpr_insert_data->sec_color_id + , lpr_insert_data->ACT_PARAM + , lpr_insert_data->THRESHOLD + , lpr_insert_data->ROI_X + , lpr_insert_data->ROI_Y + , lpr_insert_data->ROI_W + , lpr_insert_data->ROI_H + , lpr_insert_data->LP_X + , lpr_insert_data->LP_Y + , lpr_insert_data->LP_W + , lpr_insert_data->LP_H + , lpr_insert_data->LP_BMP + , lpr_insert_data->ROI_BMP + , lpr_insert_data->COUNTRY + ,"","","","","","","", lpr_insert_data->IN_OTHER,""); + // ,lpr_insert_data->IN_USER + // ,lpr_insert_data->IN_PHONE + // ,lpr_insert_data->IN_ADDRESS + // ,lpr_insert_data->IN_PAYSTATUS + // ,lpr_insert_data->IN_EXIST + // ,lpr_insert_data->IN_SCHEDULE_START + // ,lpr_insert_data->IN_SCHEDULE_END + // ,lpr_insert_data->IN_OTHER + // ,lpr_insert_data->IN_DETECT_ENDTIME); + + // printf("Insert LPR Log: %s\n", l_sql_cmd); + + //lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + //printf("\n[callback_insert_lpr_msg_to_db] 2 l_sql_ret:%d", l_sql_ret); + + //for (int try_times = 0; try_times < 5; try_times++) { + //lprdb_mutex_lock(g_ffgroup_db_info.pdb); + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + //lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + //if (l_sql_ret) { + //printf("Error:2_sql_ret:%d %s\n", l_sql_ret, l_sql_cmd); + //} + //else { + //break; + //} + //usSleep(10000); + //} + } + + if (l_log_record_cnts >= l_db_max_len) + { + printf("############## Log Records >= %d, Delete Oldest Log\n", atoi(lpr_insert_data->sql_count)); + //printf("123############## Log Records >= %d, Delete Oldest Log\n", atoi(lpr_insert_data->sql_count)); + + char l_sql_cmd[4096] = { 0 }; + { + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, "DELETE FROM '%s' WHERE ff_index IN " + "(SELECT ff_index FROM '%s' WHERE Length(ff_mod_ts)>=1 ORDER BY ff_index LIMIT %d)", lpr_insert_data->sql_tbname, lpr_insert_data->sql_tbname, l_log_record_cnts - atoi(lpr_insert_data->sql_count)); + } + + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); + //lprdb_mutex_lock(g_ffgroup_db_info.pdb); + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + //lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + //lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (l_sql_ret) + { + printf("Error:l_sql_ret:%d %s\n", l_sql_ret, l_sql_cmd); + } + /* + printf("\n-------[lpr_insert_data->MOD_TS]-------\n"); + printf("\n%s\n", lpr_insert_data->MOD_TS); + printf("\n-------end[lpr_insert_data->MOD_TS]-------\n");*/ + } + + + //db_unlock(g_ffgroup_db_info.pdb); + + if (strcmp(lpr_insert_data->sql_tbname, "lpr_db_cust_tb") == 0) { + if (l_log_record_cnts >= l_db_max_len) { + pthread_t delete_jpg_thread_id; + if (pthread_create(&delete_jpg_thread_id, 0, delete_jpg, NULL)) + { + printf("create delete_jpg thread faile \n"); + } + } + } + } + } + //printf("2callback_insert_lpr_msg_to_db\n"); + //free(lpr_insert_data); + //printf("\n[callback_insert_lpr_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + } + //if (lpr_insert_data != NULL) + //{ + //free(lpr_insert_data); + //lpr_insert_data = NULL; + //} + + //printf("\n[callback_insert_lpr_msg_to_db]pthread exit\n"); + //pthread_exit(NULL); +} +void* callback_insert_lprlist_msg_to_db(void *data) +{ + pthread_detach(pthread_self()); + setPthreadName("insertlprlist"); + //printf("\n[callback_insert_lprlist_msg_to_db]pthread create\n"); + + char l_db_log_tbname[15]={0}; + ffgroup_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + + } + else { + lpr_insert_data = (ffgroup_db_tb *)data; + //printf("\n[callback_insert_lprlist_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + //if(g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + //check List type + chk_sql_msg_tbname(l_db_log_tbname, lpr_insert_data->tb_type); + + int l_lpr_record_cnts = 0; + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_lpr_record_cnts <= COUNT_BLACK - 100 && l_lpr_record_cnts <= COUNT_WHITE - 100) + { + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_LPRLIST_DATA_CMD + , l_db_log_tbname + , lpr_insert_data->TS + , lpr_insert_data->MOD_TS + , lpr_insert_data->CAR_ID + , lpr_insert_data->LPR + , lpr_insert_data->RTIME + , lpr_insert_data->ACTION + , lpr_insert_data->sec_color_id + , lpr_insert_data->ACT_PARAM + , lpr_insert_data->THRESHOLD + , lpr_insert_data->ROI_X + , lpr_insert_data->ROI_Y + , lpr_insert_data->ROI_W + , lpr_insert_data->ROI_H + , lpr_insert_data->LP_X + , lpr_insert_data->LP_Y + , lpr_insert_data->LP_W + , lpr_insert_data->LP_H + , lpr_insert_data->LP_BMP + , lpr_insert_data->ROI_BMP + , lpr_insert_data->COUNTRY + , lpr_insert_data->IN_USER + , lpr_insert_data->IN_PHONE + , lpr_insert_data->IN_ADDRESS + , lpr_insert_data->IN_PAYSTATUS + , lpr_insert_data->IN_EXIST + , lpr_insert_data->IN_SCHEDULE_START + , lpr_insert_data->IN_SCHEDULE_END + , lpr_insert_data->IN_OTHER + , lpr_insert_data->IN_DETECT_ENDTIME); + + printf("Insert #1 LPR LIST Log: %s\n", l_sql_cmd); + //printf("Insert LPR LIST Log: %s\n", l_sql_cmd); + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + }*/ + //sqlite_restore_database(g_ffgroup_db_info.pdb); + } + } + + //db_unlock(g_ffgroup_db_info.pdb); + + } + } + //printf("1callback_insert_lprlist_msg_to_db\n"); + + //printf("\n[callback_insert_lprlist_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + //printf("\n[callback_insert_lprlist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_insert_lpr_map_msg_to_db(void *data) +{ + pthread_detach(pthread_self()); + setPthreadName("insertlprmap"); + //printf("\n[callback_insert_lpr_map_msg_to_db]pthread create\n"); + + //int l_log_record_cnts = 0; + char l_db_log_tbname[15]={0}; + ffgroup_mapping_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + + } + else { + lpr_insert_data = (ffgroup_mapping_db_tb *)data; + //printf("\n[callback_insert_lpr_map_msg_to_db]lpr_insert_data new address: %p\n", lpr_insert_data); + + //if(g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + + //check List type + chk_sql_msg_tbname(l_db_log_tbname, lpr_insert_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_LPR_MAPPING_CMD + , l_db_log_tbname + , lpr_insert_data->LPR_DETECT + , lpr_insert_data->LPR); + + printf("Insert LPR MAP Log: %s\n", l_sql_cmd); + + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + }*/ + + //sqlite_restore_database(g_ffgroup_db_info.pdb); + } + + //db_unlock(g_ffgroup_db_info.pdb); + + } + } + //printf("1callback_insert_lprlist_msg_to_db\n"); + //printf("\n[callback_insert_lpr_map_msg_to_db]lpr_insert_data free address: %p\n", lpr_insert_data); + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + //printf("\n[callback_insert_lpr_map_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_update_detectlprlist_msg_to_db(void *data) +{ + pthread_detach(pthread_self()); + setPthreadName("updatelpr"); + //printf("\n[callback_update_detectlprlist_msg_to_db]pthread create\n"); + + //int l_log_record_cnts = 0; + char l_db_log_tbname[15]={0}; + ffgroup_db_tb *lpr_update_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret=0; + + if(!data) + { + + } + else { + lpr_update_data = (ffgroup_db_tb *)data; + //printf("\n[callback_update_detectlprlist_msg_to_db]lpr_update_data new address\n"); + + //if(g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + + //check List type + chk_sql_msg_tbname(l_db_log_tbname, lpr_update_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, UPDATE_DETECT_LPRLIST_CMD + , l_db_log_tbname + , lpr_update_data->TS + , lpr_update_data->MOD_TS + , lpr_update_data->CAR_ID + , lpr_update_data->RTIME + , lpr_update_data->ACTION + , lpr_update_data->sec_color_id + , lpr_update_data->ACT_PARAM + , lpr_update_data->THRESHOLD + , lpr_update_data->ROI_X + , lpr_update_data->ROI_Y + , lpr_update_data->ROI_W + , lpr_update_data->ROI_H + , lpr_update_data->LP_X + , lpr_update_data->LP_Y + , lpr_update_data->LP_W + , lpr_update_data->LP_H + , lpr_update_data->LP_BMP + , lpr_update_data->ROI_BMP + , lpr_update_data->COUNTRY + , lpr_update_data->LPR); + + // printf("Update Detection LPR List Log: %s\n", l_sql_cmd); + // printf("Update Detection LPR List Log: %s\n", l_sql_cmd); + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (lpr_update_data) { + free(lpr_update_data); + lpr_update_data = NULL; + }*/ + } + + //db_unlock(g_ffgroup_db_info.pdb); + + } + } + //intf("3detectlprlist_msg_to_db\n"); + //printf("\n[callback_update_detectlprlist_msg_to_db]lpr_update_data free address\n"); + if (lpr_update_data) { + free(lpr_update_data); + lpr_update_data = NULL; + } + + //printf("\n[callback_update_detectlprlist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_update_lprlist_msg_to_db(void *data) +{ + pthread_detach(pthread_self()); + setPthreadName("updatelpr2"); + //printf("\n[callback_update_lprlist_msg_to_db]pthread create\n"); + + //int l_log_record_cnts = 0; + char l_db_log_tbname[15]={0}; + ffgroup_listInfo_tb *lpr_update_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data){} + else { + + printf("IN updata lpr list\n"); + + lpr_update_lprlist_data = (ffgroup_listInfo_tb *)data; + //printf("\n[callback_update_lprlist_msg_to_db]lpr_update_lprlist_data new address: %p\n", lpr_update_lprlist_data); + + //if(g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + + //check List type + chk_sql_msg_tbname(l_db_log_tbname, lpr_update_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, UPDATE_LPRLIST_CMD + , l_db_log_tbname + , lpr_update_lprlist_data->LPR + , lpr_update_lprlist_data->ACT_PARAM + , lpr_update_lprlist_data->IN_USER + , lpr_update_lprlist_data->IN_PHONE + , lpr_update_lprlist_data->IN_ADDRESS + , lpr_update_lprlist_data->IN_PAYSTATUS + , lpr_update_lprlist_data->IN_EXIST + , lpr_update_lprlist_data->IN_SCHEDULE_START + , lpr_update_lprlist_data->IN_SCHEDULE_END + , lpr_update_lprlist_data->IN_OTHER + , lpr_update_lprlist_data->IN_DETECT_ENDTIME + , lpr_update_lprlist_data->oLPR); + + printf("Update LPR LIST Log: %s\n", l_sql_cmd); + + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_update_lprlist_data) { + free(lpr_update_lprlist_data); + lpr_update_lprlist_data = NULL; + }*/ + } + + + + } + } + + //printf("\n[callback_update_lprlist_msg_to_db]lpr_update_lprlist_data free address: %p\n", lpr_update_lprlist_data); + if (lpr_update_lprlist_data) { + free(lpr_update_lprlist_data); + lpr_update_lprlist_data = NULL; + } + //printf("OUT updata lpr list\n"); + //printf("\n[callback_update_lprlist_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +void* callback_update_lpr_map_msg_to_db(void *data) +{ + pthread_detach(pthread_self()); + setPthreadName("updatelpr3"); + //printf("\n[callback_update_lpr_map_msg_to_db]pthread create\n"); + + //int l_map_record_cnts = 0; + char l_db_map_tbname[15]={0}; + ffgroup_mapping_db_tb *lpr_update_lpr_map = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + + } + else { + lpr_update_lpr_map = (ffgroup_mapping_db_tb *)data; + //printf("\n[callback_update_lpr_map_msg_to_db]lpr_update_lpr_map new address: %p\n", lpr_update_lpr_map); + + //if(g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + //check List type + chk_sql_msg_tbname(l_db_map_tbname, lpr_update_lpr_map->tb_type); + + + //l_map_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_map_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, UPDATE_LPR_MAPPING_CMD + , l_db_map_tbname + , lpr_update_lpr_map->LPR_DETECT + , lpr_update_lpr_map->LPR + , lpr_update_lpr_map->oLPR); + + printf("Update LPR LIST Log: %s\n", l_sql_cmd); + + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_update_lpr_map) { + free(lpr_update_lpr_map); + lpr_update_lpr_map = NULL; + }*/ + } + + + + } + } + //printf("\n[callback_update_lpr_map_msg_to_db]lpr_update_lpr_map free address: %p\n", lpr_update_lpr_map); + if (lpr_update_lpr_map) { + free(lpr_update_lpr_map); + lpr_update_lpr_map = NULL; + } + + //printf("\n[callback_update_lpr_map_msg_to_db]pthread exit\n"); + } + pthread_exit(NULL); +} +//DELETE FROM %s WHERE ff_index=(SELECT ff_index FROM %s WHERE ff_lpr='%s'); +//void callback_del_lprtab_msg_to_db(void *data) +int callback_del_lprtab_msg_to_db(void *data,int nIndex,int sumIndex) +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[15]={0}; + ffgroup_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return 0; + } + + lpr_del_lprlist_data = (ffgroup_db_tb *)data; + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + + + //check List type + chk_sql_msg_tbname(l_db_log_tbname,lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, DELETE_LPRTAB_CMD + ,l_db_log_tbname + ,l_db_log_tbname + ,lpr_del_lprlist_data->LPR); + + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); + + + //l_sql_ret=db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if(l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + }*/ + } + + + + } + } + + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if((l_sql_ret==0) &&(nIndex==sumIndex-1)) + return 1; + else + return 0; + +} + +int callback_del_lprtab_time_msg_to_db(void *data, int nIndex, int sumIndex) +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[15] = { 0 }; + ffgroup_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = { 0 }; + int l_sql_ret = 0; + + if (!data) + { + return 0; + } + + lpr_del_lprlist_data = (ffgroup_db_tb *)data; + + //if (g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + + //check List type + chk_sql_msg_tbname(l_db_log_tbname, lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, DELETE_LPRTAB_TIME_CMD + , l_db_log_tbname + , l_db_log_tbname + , lpr_del_lprlist_data->MOD_TS); + + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + }*/ + } + + + + } + } + + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if ((l_sql_ret == 0) && (nIndex == sumIndex - 1)) + return 1; + else + return 0; + +} + +int callback_del_lpr_map_msg_to_db(void *data,int nIndex,int sumIndex) +{ + //int l_log_record_cnts = 0; + char l_db_log_tbname[15]={0}; + ffgroup_mapping_db_tb *lpr_del_lprlist_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return 0; + } + + lpr_del_lprlist_data = ( ffgroup_mapping_db_tb *)data; + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + + //check List type + chk_sql_msg_tbname(l_db_log_tbname,lpr_del_lprlist_data->tb_type); + + //l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, DELETE_LPR_MAPPING_CMD + ,l_db_log_tbname + ,l_db_log_tbname + ,lpr_del_lprlist_data->LPR_DETECT); + + printf("Delete LPR Log: %s\n", l_sql_cmd); + //printf("Delete LPR Log: %s\n", l_sql_cmd); + + + //l_sql_ret=db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if(l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + }*/ + } + + + } + } + if (lpr_del_lprlist_data) { + free(lpr_del_lprlist_data); + lpr_del_lprlist_data = NULL; + } + //printf("l_sql_ret:%d\n",l_sql_ret); + if((l_sql_ret==0) &&(nIndex==sumIndex-1)) + return 1; + else + return 0; + +} +//void sqlite_ffgroup_del( const char *LPR ,char *type_name,int nIndex,int sumIndex) +int sqlite_ffgroup_del( const char *LPR ,char *type_name,int nIndex,int sumIndex) +{ + ffgroup_db_tb *lpr_del_data = NULL; + //lpr_del_data = (ffgroup_db_tb *)calloc(1, sizeof(ffgroup_db_tb)); + lpr_del_data = (ffgroup_db_tb *)malloc(sizeof(ffgroup_db_tb)); + memset(lpr_del_data,0, sizeof(ffgroup_db_tb)); + int l_result =0 ; + //if(lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->LPR,LPR); + chk_log_data(lpr_del_data->tb_type ,type_name); + l_result= callback_del_lprtab_msg_to_db( (void *)lpr_del_data,nIndex,sumIndex); + + } + return l_result; +} + +int sqlite_ffgroup_del_time(const char *lpr_time, char *type_name, int nIndex, int sumIndex) +{ + ffgroup_db_tb *lpr_del_data = NULL; + //lpr_del_data = (ffgroup_db_tb *)calloc(1, sizeof(ffgroup_db_tb)); + lpr_del_data = (ffgroup_db_tb *)malloc(sizeof(ffgroup_db_tb)); + memset(lpr_del_data, 0, sizeof(ffgroup_db_tb)); + int l_result = 0; + if (lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->MOD_TS, lpr_time); + chk_log_data(lpr_del_data->tb_type, type_name); + l_result = callback_del_lprtab_time_msg_to_db((void *)lpr_del_data, nIndex, sumIndex); + + } + return l_result; +} + +int sqlite_ffgroup_del_map( const char *LPR_DETECT ,char *type_name,int nIndex,int sumIndex) +{ + ffgroup_mapping_db_tb *lpr_del_data = NULL; + + lpr_del_data = (ffgroup_mapping_db_tb *)malloc(sizeof( ffgroup_mapping_db_tb)); + memset(lpr_del_data,0, sizeof( ffgroup_mapping_db_tb)); + int l_result =0 ; + //if(lpr_del_data != NULL) + { + chk_log_data(lpr_del_data->LPR_DETECT,LPR_DETECT); + chk_log_data(lpr_del_data->tb_type ,type_name); + l_result= callback_del_lpr_map_msg_to_db( (void *)lpr_del_data,nIndex,sumIndex); + + } + return l_result; +} + + +void sqlite_ffgroup_insert(ffgroup_db_tb *l_ff_insert_data, char *type_name) +{ + if (check_if_db_is_malformed == 1) { + if (g_ffgroup_db_info.pdb) + { + //PRINT_INFO_LOG("####### License Plate DB Close\n"); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + //db_lock(g_ffgroup_db_info.pdb); + sqlite3_close(g_ffgroup_db_info.pdb); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + //db_unlock(g_log_db_info->pdb); + } + + system(SHELLSCRIPT_FIX_DB_FFLPR); + check_if_db_is_malformed = 0; + + sqlite3_open_v2(g_ffgroup_db_info.db_name, &g_ffgroup_db_info.pdb, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL); + } + + //printf("\n[sqlite_ffgroup_insert] 0"); + //pthread_mutex_lock(&mutex_db_lpr_insert_db); + //printf("\n[sqlite_ffgroup_insert] 0-1"); + //ffgroup_db_tb *lpr_insert_data = NULL; + ffgroup_db_tb lpr_insert_data; + //printf("\n[sqlite_ffgroup_insert] 0-2"); + //lpr_insert_data = calloc(1, sizeof(ffgroup_db_tb)); + //lpr_insert_data = (ffgroup_db_tb *)malloc(sizeof(ffgroup_db_tb)); + + //printf("\n[sqlite_ffgroup_insert] 0-3"); + + //printf("\n[sqlite_ffgroup_insert] 0-4"); + + //if(lpr_insert_data != NULL) + { + //memset(lpr_insert_data, 0, sizeof(ffgroup_db_tb)); + //printf("\n[sqlite_ffgroup_insert] 1"); + chk_log_data(lpr_insert_data.TS ,l_ff_insert_data->TS); + chk_log_data(lpr_insert_data.MOD_TS,l_ff_insert_data->MOD_TS); + chk_log_data(lpr_insert_data.CAR_ID,l_ff_insert_data->CAR_ID); + chk_log_data(lpr_insert_data.LPR,l_ff_insert_data->LPR); + chk_log_data(lpr_insert_data.RTIME,l_ff_insert_data->RTIME); + chk_log_data(lpr_insert_data.ACTION,l_ff_insert_data->ACTION); + chk_log_data(lpr_insert_data.sec_color_id, l_ff_insert_data->sec_color_id); + chk_log_data(lpr_insert_data.ACT_PARAM,l_ff_insert_data->ACT_PARAM); + chk_log_data(lpr_insert_data.THRESHOLD,l_ff_insert_data->THRESHOLD); + chk_log_data(lpr_insert_data.ROI_X,l_ff_insert_data->ROI_X); + chk_log_data(lpr_insert_data.ROI_Y,l_ff_insert_data->ROI_Y); + chk_log_data(lpr_insert_data.ROI_W,l_ff_insert_data->ROI_W); + chk_log_data(lpr_insert_data.ROI_H,l_ff_insert_data->ROI_H); + chk_log_data(lpr_insert_data.LP_X,l_ff_insert_data->LP_X); + chk_log_data(lpr_insert_data.LP_Y,l_ff_insert_data->LP_Y); + chk_log_data(lpr_insert_data.LP_W ,l_ff_insert_data->LP_W); + chk_log_data(lpr_insert_data.LP_H ,l_ff_insert_data->LP_H); + chk_log_data(lpr_insert_data.LP_BMP ,l_ff_insert_data->LP_BMP); + chk_log_data(lpr_insert_data.ROI_BMP ,l_ff_insert_data->ROI_BMP); + chk_log_data(lpr_insert_data.COUNTRY ,l_ff_insert_data->COUNTRY); + chk_log_data(lpr_insert_data.IN_USER ,l_ff_insert_data->IN_USER); + chk_log_data(lpr_insert_data.IN_PHONE ,l_ff_insert_data->IN_PHONE); + chk_log_data(lpr_insert_data.IN_ADDRESS ,l_ff_insert_data->IN_ADDRESS); + chk_log_data(lpr_insert_data.IN_PAYSTATUS ,l_ff_insert_data->IN_PAYSTATUS); + chk_log_data(lpr_insert_data.IN_EXIST ,l_ff_insert_data->IN_EXIST); + chk_log_data(lpr_insert_data.IN_SCHEDULE_START ,l_ff_insert_data->IN_SCHEDULE_START); + chk_log_data(lpr_insert_data.IN_SCHEDULE_END ,l_ff_insert_data->IN_SCHEDULE_END); + chk_log_data(lpr_insert_data.IN_OTHER ,l_ff_insert_data->IN_OTHER); + + chk_log_data(lpr_insert_data.sql_count ,l_ff_insert_data->sql_count); + chk_log_data(lpr_insert_data.sql_tbname ,l_ff_insert_data->sql_tbname); + + chk_log_data(lpr_insert_data.tb_type ,type_name); + //printf("\n[sqlite_ffgroup_insert] type_name:%s\nlpr_insert_data.tb_type:%s\n", type_name, lpr_insert_data.tb_type); + chk_log_data(lpr_insert_data.IN_DETECT_ENDTIME ,l_ff_insert_data->IN_DETECT_ENDTIME); + + //printf("\n[sqlite_ffgroup_insert] 2"); + + callback_insert_lpr_msg_to_db(&lpr_insert_data); + + //pthread_t lprdb_thread; + //if (pthread_create(&lprdb_thread, 0, callback_insert_lpr_msg_to_db, (void *)lpr_insert_data)) + //{ + //printf("lilin_thread_pool_process full --> error\n"); + + //if (lpr_insert_data != NULL) + //{ + //free(lpr_insert_data); + //lpr_insert_data = NULL; + //} + + //} + //pthread_join(lprdb_thread, NULL); + //printf("[sqlite_ffgroup_insert][callback_insert_lpr_msg_to_db]lprdb_thread: %d",lprdb_thread); + + //printf("\n[sqlite_ffgroup_insert] 3"); + } + + + //pthread_mutex_unlock(&mutex_db_lpr_insert_db); +} +void sqlite_ffgroup_add_list(const char *LPR , const char *IN_USER , const char *IN_PHONE,const char *IN_ADDRESS, + const char *IN_PAYSTATUS,const char *IN_EXIST, const char *IN_SCHEDULE_START, + const char *IN_SCHEDULE_END, const char *IN_OTHER ,char *IN_DETECT_ENDTIME,char *type_name) +{ + pthread_mutex_lock(&mutex_db_lpr_add); + ffgroup_db_tb *lpr_insert_data = NULL; + + //lpr_insert_data = calloc(1, sizeof(ffgroup_db_tb)); + lpr_insert_data = (ffgroup_db_tb *)malloc(sizeof(ffgroup_db_tb)); + memset(lpr_insert_data,0,sizeof(ffgroup_db_tb)); + //if(lpr_insert_data != NULL) + { + chk_log_data(lpr_insert_data->LPR,LPR); + chk_log_data(lpr_insert_data->ACT_PARAM,type_name); + chk_log_data(lpr_insert_data->IN_USER ,IN_USER); + chk_log_data(lpr_insert_data->IN_PHONE ,IN_PHONE); + chk_log_data(lpr_insert_data->IN_ADDRESS ,IN_ADDRESS); + chk_log_data(lpr_insert_data->IN_PAYSTATUS ,IN_PAYSTATUS); + chk_log_data(lpr_insert_data->IN_EXIST ,IN_EXIST); + chk_log_data(lpr_insert_data->IN_SCHEDULE_START ,IN_SCHEDULE_START); + chk_log_data(lpr_insert_data->IN_SCHEDULE_END ,IN_SCHEDULE_END); + chk_log_data(lpr_insert_data->IN_OTHER ,IN_OTHER); + chk_log_data(lpr_insert_data->IN_DETECT_ENDTIME ,IN_DETECT_ENDTIME); + chk_log_data(lpr_insert_data->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_insert_lprlist_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + } + pthread_mutex_unlock(&mutex_db_lpr_add); +} + +void sqlite_ffgroup_add_map_list(const char *LPR_DETECT ,const char *LPR,char *type_name) +{ + ffgroup_mapping_db_tb *lpr_insert_data = NULL; + + //lpr_insert_data = calloc(1, sizeof(ffgroup_mapping_db_tb)); + lpr_insert_data = (ffgroup_mapping_db_tb*)malloc(sizeof(ffgroup_mapping_db_tb)); + memset(lpr_insert_data,0,sizeof(ffgroup_mapping_db_tb)); + //if(lpr_insert_data != NULL) + { + chk_log_data(lpr_insert_data->LPR_DETECT,LPR_DETECT); + chk_log_data(lpr_insert_data->LPR,LPR); + + chk_log_data(lpr_insert_data->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_insert_lpr_map_msg_to_db, (void *)lpr_insert_data)) + { + //printf("lilin_thread_pool_process full --> error\n"); + + if (lpr_insert_data != NULL) + { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + + } + + } +} +void sqlite_ffgroup_updateInfo_list(const char *LPR ,const char *oLPR, const char *IN_USER , const char *IN_PHONE, + const char *IN_ADDRESS, const char *IN_PAYSTATUS,const char *IN_EXIST, + const char *IN_SCHEDULE_START,const char *IN_SCHEDULE_END, const char *IN_OTHER , + char *IN_DETECT_ENDTIME,char *type_name) +{ + + ffgroup_listInfo_tb *lpr_updata_list = NULL; + + //lpr_updata_list = calloc(1, sizeof(ffgroup_listInfo_tb)); + lpr_updata_list = (ffgroup_listInfo_tb*)malloc(sizeof(ffgroup_listInfo_tb)); + memset(lpr_updata_list,0,sizeof(ffgroup_listInfo_tb)); + //if(lpr_updata_list != NULL) + { + + chk_log_data(lpr_updata_list->LPR,LPR); + chk_log_data(lpr_updata_list->ACT_PARAM,type_name); + chk_log_data(lpr_updata_list->oLPR,oLPR); + chk_log_data(lpr_updata_list->IN_USER ,IN_USER); + chk_log_data(lpr_updata_list->IN_PHONE ,IN_PHONE); + chk_log_data(lpr_updata_list->IN_ADDRESS ,IN_ADDRESS); + chk_log_data(lpr_updata_list->IN_PAYSTATUS ,IN_PAYSTATUS); + chk_log_data(lpr_updata_list->IN_EXIST ,IN_EXIST); + chk_log_data(lpr_updata_list->IN_SCHEDULE_START ,IN_SCHEDULE_START); + chk_log_data(lpr_updata_list->IN_SCHEDULE_END ,IN_SCHEDULE_END); + chk_log_data(lpr_updata_list->IN_OTHER ,IN_OTHER); + chk_log_data(lpr_updata_list->IN_DETECT_ENDTIME ,IN_DETECT_ENDTIME); + chk_log_data(lpr_updata_list->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_update_lprlist_msg_to_db, (void *)lpr_updata_list)) + { + //printf("lilin_thread_pool_process full --> error\n"); + if (lpr_updata_list) { + free(lpr_updata_list); + lpr_updata_list = NULL; + } + } + + } + +} +void sqlite_ffgroup_update_map_list(const char *LPR_DETECT ,const char *LPR,const char *oLPR,char *type_name) +{ + ffgroup_mapping_db_tb *lpr_updata_map_list = NULL; + //lpr_updata_map_list = calloc(1, sizeof(ffgroup_mapping_db_tb)); + lpr_updata_map_list = (ffgroup_mapping_db_tb*)malloc(sizeof(ffgroup_mapping_db_tb)); + memset(lpr_updata_map_list,0,sizeof(ffgroup_mapping_db_tb)); + //if(lpr_updata_map_list != NULL) + { + + chk_log_data(lpr_updata_map_list->LPR_DETECT,LPR_DETECT); + chk_log_data(lpr_updata_map_list->LPR,LPR); + chk_log_data(lpr_updata_map_list->oLPR,oLPR); + chk_log_data(lpr_updata_map_list->tb_type ,type_name); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_update_lpr_map_msg_to_db, (void *)lpr_updata_map_list)) + { + //printf("lilin_thread_pool_process full --> error\n"); + if (lpr_updata_map_list) { + free(lpr_updata_map_list); + lpr_updata_map_list = NULL; + } + } + + } +} +void sqlite_ffgroup_update(ffgroup_db_tb *i_updata_list) +{ + + ffgroup_db_tb *lpr_iupdata_list = NULL; + //lpr_iupdata_list = calloc(1, sizeof(ffgroup_db_tb)); + lpr_iupdata_list = (ffgroup_db_tb *)malloc(sizeof(ffgroup_db_tb)); + memset(lpr_iupdata_list,0,sizeof(ffgroup_db_tb)); + //if(lpr_iupdata_list != NULL) + { + chk_log_data(lpr_iupdata_list->TS ,i_updata_list->TS); + chk_log_data(lpr_iupdata_list->MOD_TS,i_updata_list->MOD_TS); + chk_log_data(lpr_iupdata_list->CAR_ID,i_updata_list->CAR_ID); + chk_log_data(lpr_iupdata_list->LPR,i_updata_list->LPR); + chk_log_data(lpr_iupdata_list->RTIME,i_updata_list->RTIME); + chk_log_data(lpr_iupdata_list->ACTION,i_updata_list->ACTION); + chk_log_data(lpr_iupdata_list->sec_color_id, i_updata_list->sec_color_id); + chk_log_data(lpr_iupdata_list->ACT_PARAM,i_updata_list->ACT_PARAM); + chk_log_data(lpr_iupdata_list->THRESHOLD,i_updata_list->THRESHOLD); + chk_log_data(lpr_iupdata_list->ROI_X,i_updata_list->ROI_X); + chk_log_data(lpr_iupdata_list->ROI_Y,i_updata_list->ROI_Y); + chk_log_data(lpr_iupdata_list->ROI_W,i_updata_list->ROI_W); + chk_log_data(lpr_iupdata_list->ROI_H,i_updata_list->ROI_H); + chk_log_data(lpr_iupdata_list->LP_X,i_updata_list->LP_X); + chk_log_data(lpr_iupdata_list->LP_Y,i_updata_list->LP_Y); + chk_log_data(lpr_iupdata_list->LP_W ,i_updata_list->LP_W); + chk_log_data(lpr_iupdata_list->LP_H ,i_updata_list->LP_H); + chk_log_data(lpr_iupdata_list->LP_BMP ,i_updata_list->LP_BMP); + chk_log_data(lpr_iupdata_list->ROI_BMP ,i_updata_list->ROI_BMP); + chk_log_data(lpr_iupdata_list->COUNTRY ,i_updata_list->COUNTRY); + chk_log_data(lpr_iupdata_list->tb_type ,i_updata_list->tb_type); + + pthread_t lprdb_thread; + if (pthread_create(&lprdb_thread, 0, callback_update_detectlprlist_msg_to_db, (void *)lpr_iupdata_list)) + { + //printf("lilin_thread_pool_process full --> error\n"); + if (lpr_iupdata_list) { + free(lpr_iupdata_list); + lpr_iupdata_list = NULL; + } + } + + } + +} + +int db_get_lpr_record(sqlite3_stmt *stmt, ffgroup_db_tb *db_tb_info) +{ + int l_result = 0; + + if(stmt) + { + int l_log_tb_columns = db_get_column_counts(g_ffgroup_db_info.pstmt); + int l_jdx; + + for(l_jdx=0; l_jdx<l_log_tb_columns; l_jdx++) + { + if(!strcmp("ff_ts", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->TS, sizeof(db_tb_info->TS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_mod_ts", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->MOD_TS, sizeof(db_tb_info->MOD_TS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_car_id", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->CAR_ID, sizeof(db_tb_info->CAR_ID)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpr", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LPR, sizeof(db_tb_info->LPR)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_rtime", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->RTIME, sizeof(db_tb_info->RTIME)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_action", db_get_cloumn_name(stmt, l_jdx))) + { + + snprintf(db_tb_info->ACTION, sizeof(db_tb_info->ACTION)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if (!strcmp("ff_sec_color_id", db_get_cloumn_name(stmt, l_jdx))) + { + + snprintf(db_tb_info->sec_color_id, sizeof(db_tb_info->sec_color_id) - 1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_act_param", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ACT_PARAM, sizeof(db_tb_info->ACT_PARAM)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_threshold", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->THRESHOLD, sizeof(db_tb_info->THRESHOLD)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiX", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_X, sizeof(db_tb_info->ROI_X)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiY", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_Y, sizeof(db_tb_info->ROI_Y)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiW", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_W, sizeof(db_tb_info->ROI_W)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_roiH", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_H, sizeof(db_tb_info->ROI_H)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpX", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_X, sizeof(db_tb_info->LP_X)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpY", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_Y, sizeof(db_tb_info->LP_Y)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpW", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_W, sizeof(db_tb_info->LP_W)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpH", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_H, sizeof(db_tb_info->LP_H)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lpbmp", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LP_BMP, sizeof(db_tb_info->LP_BMP)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_lproi", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->ROI_BMP, sizeof(db_tb_info->ROI_BMP)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_country", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->COUNTRY, sizeof(db_tb_info->COUNTRY)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_user", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_USER, sizeof(db_tb_info->IN_USER)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_phone", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_PHONE, sizeof(db_tb_info->IN_PHONE)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_address", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_ADDRESS, sizeof(db_tb_info->IN_ADDRESS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_paystatus", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_PAYSTATUS, sizeof(db_tb_info->IN_PAYSTATUS)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_exist", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_EXIST, sizeof(db_tb_info->IN_EXIST)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_schedule_start", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_SCHEDULE_START, sizeof(db_tb_info->IN_SCHEDULE_START)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_schedule_end", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_SCHEDULE_END, sizeof(db_tb_info->IN_SCHEDULE_END)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_other", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_OTHER, sizeof(db_tb_info->IN_OTHER)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("in_detect_endtime", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->IN_DETECT_ENDTIME, sizeof(db_tb_info->IN_DETECT_ENDTIME)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + } + } + + return l_result; +} +static int db_get_lpr_map_record(sqlite3_stmt *stmt, ffgroup_mapping_db_tb *db_tb_info) +{ + int l_result = 0; + + if(stmt) + { + int l_log_tb_columns = db_get_column_counts(g_ffgroup_db_info.pstmt); + int l_jdx; + + for(l_jdx=0; l_jdx<l_log_tb_columns; l_jdx++) + { + if(!strcmp("ff_lpr", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LPR, sizeof(db_tb_info->LPR)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + else if(!strcmp("ff_det_lpr", db_get_cloumn_name(stmt, l_jdx))) + { + snprintf(db_tb_info->LPR_DETECT, sizeof(db_tb_info->LPR_DETECT)-1, db_get_column_value_str(stmt, l_jdx)); + continue; + } + } + } + + return l_result; +} + +extern size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); +int cgi_get_db_lpr_log(SOCKET socket_in,char *db_tb_name,char *list_name,int sum_count) +{ + + int l_result = 0; + int l_db_length=0; + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //printf("\n[cgi_get_db_lpr_log] 1---1"); + static char sendBuffer[3000*1000] = { 0 };//2000 + //printf("\n[cgi_get_db_lpr_log] 1---2"); + static char beforeSendBuffer[3000*1000] = { 0 };//2000 + //printf("\n[cgi_get_db_lpr_log] 1---3"); + int check_if_send = 0; + + //printf("\n[cgi_get_db_lpr_log] db_tb_name:%s list_name:%s sum_count:%d\n", db_tb_name,list_name, sum_count); + //if(g_ffgroup_db_info) + //if(0) + { + //printf("\n[cgi_get_db_lpr_log] 1"); + + if(g_ffgroup_db_info.pdb) + { + //printf("\n[cgi_get_db_lpr_log] 2"); + ffgroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_db_tb)); + char l_sql[128] = {0}; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + if(strcmp(list_name,LOGLISTNAME)==0||strcmp(list_name,CUSTLISTNAME)==0) + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name,sum_count); + else + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name,sum_count); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + //printf("\n[cgi_get_db_lpr_log] 3"); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, db_tb_name); + + /*if (l_lpr_record_cnts >= 0)*/ { + //printf("\n[cgi_get_db_lpr_log] 4"); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + //printf("\n[cgi_get_db_lpr_log] 5 l_rc:%d", l_rc); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + if (l_rc != 0) + { + //printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + cJSON *root, *child; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(-1)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + + JsonString = cJSON_PrintUnformatted(root); + strcpy(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #1\n"); + + check_if_send = 1; + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + { + //printf("\n[cgi_get_db_lpr_log] 7"); + if (l_lpr_record_cnts >= sum_count) + l_db_length = sum_count; + else + l_db_length = l_lpr_record_cnts; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "LP_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "LP_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "LP_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "LP_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "LP_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "LPR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "LPR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "LPR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "LPR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "LPR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "LPR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "LPR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "LPR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "LPR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + + //printf("\n[cgi_get_db_lpr_log] 7 JsonString:%s\n", JsonString); + strcpy(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_lpr_log] 9------sendBufferSize:%d\n", sendBufferSize); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2\n"); + //printf("\n[cgi_get_db_lpr_log] 10\n"); + + check_if_send = 1; + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + //printf("\n[cgi_get_db_lpr_log] 11\n"); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 12\n"); + + l_result = l_idx + 1; + } + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + //printf("\n[cgi_get_db_lpr_log] 13\n"); + + //fflush(wp); + } + } + + if (check_if_send == 0) { + strcpy(beforeSendBuffer, ""); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_lpr_log] 9999\n"); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2222\n"); + } + + return l_result; +} + +int cgi_get_db_lpr_log_delete_jpg(char *db_tb_name, char *list_name, int sum_count) +{ + int l_result = 0; + int l_db_length = 0; + + //printf("\n[cgi_get_db_lpr_log_delete_jpg] db_tb_name:%s list_name:%s sum_count:%d\n", db_tb_name,list_name, sum_count); + //if (g_ffgroup_db_info) + { + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 1"); + + if (g_ffgroup_db_info.pdb) + { + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 2"); + ffgroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info, 0, sizeof(ffgroup_db_tb)); + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 2-1"); + char l_sql[128] = { 0 }; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 2-2"); + if (strcmp(list_name, LOGLISTNAME) == 0 || strcmp(list_name, CUSTLISTNAME) == 0) + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, sum_count); + else + snprintf(l_sql, sizeof(l_sql) - 1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name, sum_count); + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 2-3"); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 3"); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, db_tb_name); + + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 4"); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 5 l_rc:%d", l_rc); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + if (l_rc != 0) + { + l_idx = -1; + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + } + else + { + //printf("\n[cgi_get_db_lpr_log_delete_jpg] 7"); + if (l_lpr_record_cnts >= sum_count) + l_db_length = sum_count; + else + l_db_length = l_lpr_record_cnts; + + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + + if (l_idx + 1 == 600) { + strcpy(g_MOD_TS, l_db_lpr_tb_info.MOD_TS); + } + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + //printf("\n[cgi_get_db_lpr_log] 11\n"); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 12\n"); + + l_result = l_idx + 1; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + //printf("\n[cgi_get_db_lpr_log] 13\n"); + //fflush(wp); + } + } + + return l_result; +} +#if 0 +int cgi_get_db_lpr_mapping(SOCKET socket_in,char *db_tb_name,char *list_name,int sum_count) +{ + int l_result = 0; + int l_db_length=0; + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_mapping_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_mapping_db_tb)); + char l_sql[128] = {0}; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name,sum_count); + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, db_tb_name); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + cJSON *root, *child; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(-1)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + + JsonString = cJSON_PrintUnformatted(root); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + + } + else + { + if(l_lpr_record_cnts >=sum_count) + l_db_length=sum_count; + else + l_db_length=l_lpr_record_cnts; + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_lpr_map_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + cJSON_AddItemToObject(child1, "MAP_INDEX", cJSON_CreateNumber(l_idx+1)); + cJSON_AddItemToObject(child1, "LPR_DETECT", cJSON_CreateString(l_db_lpr_tb_info.LPR_DETECT)); + cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #4\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + + l_result = l_idx + 1; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + return l_result; +} +#endif +#if 0 +int cgi_get_db_lpr_map_count(webs_t wp,char *db_tb_name,char *list_name,int sum_count,int tar_count) +{ + char l_lpr_cgi_res[512] = {0}; + int l_result = 0; + int l_db_length=0; + + snprintf(l_lpr_cgi_res , sizeof(l_lpr_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_mapping_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_mapping_db_tb)); + char l_sql[200] = {0}; + int l_log_tb_columns = 0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + + websWrite(wp ,"%s" ,l_lpr_cgi_res); + + int l_rc; + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, db_tb_name); + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name,tar_count); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + websWrite (wp, "{\n"); + websWrite (wp, " \"LPR_COUNT\": -1,\r\n"); + websWrite (wp, " \"INFORMATION\": [\r\n"); + websWrite (wp, " ]\r\n"); + websWrite (wp, "}\r\n"); + + } + else + { + if(l_lpr_record_cnts>=sum_count) + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + } + else + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + + } + + websWrite (wp, "{"); + websWrite (wp, "\"LPR_COUNT\": %d,", l_db_length ); + websWrite (wp, "\"INFORMATION\": ["); + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_lpr_map_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + + + websWrite (wp, "{" + "\"INDEX\":%d," + "\"LPR_DETECT\":\"%s\"," + "\"LPR\":\"%s\"", + l_idx+1, + l_db_lpr_tb_info.LPR_DETECT, + l_db_lpr_tb_info.LPR + ); + + if((l_idx+1) == l_db_length) + { + websWrite (wp, "}"); + } + else + { + websWrite (wp, "},"); + } + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + + websWrite (wp, "],\"LIST_TYPE\": \"%s\"",list_name); + websWrite (wp, "}"); + } + + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + + l_result = l_idx + 1; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + + fflush(wp); + + } + } + return l_result; +} +#endif +#if 1 +int cgi_get_db_lpr_log_count(SOCKET socket_in,char *db_tb_name,char *list_name,int sum_count,int tar_count) +{ + //printf("\n--------cgi get db lpr log count----0\n"); + int l_result = 0; + int l_db_length=0; + + //char sendBuffer[2000 * 1000] = { 0 }; + //char beforeSendBuffer[2000 * 1000] = { 0 }; + + char sendBuffer[BUFSIZE*10] = { 0 }; + char beforeSendBuffer[BUFSIZE*10] = { 0 }; + + //printf("\n--------cgi get db lpr log count----1\n"); + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_db_tb)); + char l_sql[200] = {0}; + //int l_log_tb_columns = 0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + + int l_rc; + //printf("\n------cgi get db lpr log count------2\n"); + if(strcmp(list_name,LOGLISTNAME)==0||strcmp(list_name,CUSTLISTNAME)==0) + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;", db_tb_name, /*MAX_ROW_DATA,*/ tar_count); + else + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;", db_tb_name, /*MAX_ROW_DATA,*/ tar_count); + + //printf("\n------cgi get db lpr log count------3\n"); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, db_tb_name); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + //printf("\n------cgi get db lpr log count------4\n"); + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + //printf("\n------cgi get db lpr log count------5\n"); + if ( l_rc != 0) + { + //printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql, l_rc); + + l_idx = -1; + cJSON *root, *child; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(-1)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + + JsonString = cJSON_PrintUnformatted(root); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #1\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + { + if(l_lpr_record_cnts>=sum_count) + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + } + else + { + if(l_lpr_record_cnts>=tar_count) + l_db_length=tar_count; + else + l_db_length=l_lpr_record_cnts; + + } + + cJSON *root, *child, *child1; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + cJSON_AddItemToObject(root, "LPR_COUNT", cJSON_CreateNumber(l_db_length)); + child = cJSON_CreateArray(); + //CJSON_CHK_FAIL(child, NULL); + cJSON_AddItemToObject(root, "INFORMATION", child); + cJSON_AddItemToObject(root, "LIST_TYPE", cJSON_CreateString(list_name)); + for (l_idx = 0; l_idx < l_db_length && l_rc == 0; l_idx++) + { + child1 = cJSON_CreateObject(); + //CJSON_CHK_FAIL(child1, NULL); + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + + cJSON_AddItemToObject(child1, "INDEX", cJSON_CreateNumber(l_idx + 1)); + cJSON_AddItemToObject(child1, "TS", cJSON_CreateString(l_db_lpr_tb_info.TS)); + cJSON_AddItemToObject(child1, "MOD_TS", cJSON_CreateString(l_db_lpr_tb_info.MOD_TS)); + cJSON_AddItemToObject(child1, "CAR_ID", cJSON_CreateString(l_db_lpr_tb_info.CAR_ID)); + cJSON_AddItemToObject(child1, "LPR", cJSON_CreateString(l_db_lpr_tb_info.LPR)); + cJSON_AddItemToObject(child1, "RTIME", cJSON_CreateString(l_db_lpr_tb_info.RTIME)); + cJSON_AddItemToObject(child1, "ACTION", cJSON_CreateString(l_db_lpr_tb_info.ACTION)); + cJSON_AddItemToObject(child1, "sec_color_id", cJSON_CreateString(l_db_lpr_tb_info.sec_color_id)); + cJSON_AddItemToObject(child1, "ACT_PARAM", cJSON_CreateString(l_db_lpr_tb_info.ACT_PARAM)); + cJSON_AddItemToObject(child1, "THRESHOLD", cJSON_CreateString(l_db_lpr_tb_info.THRESHOLD)); + cJSON_AddItemToObject(child1, "ROI_X", cJSON_CreateString(l_db_lpr_tb_info.ROI_X)); + cJSON_AddItemToObject(child1, "ROI_Y", cJSON_CreateString(l_db_lpr_tb_info.ROI_Y)); + cJSON_AddItemToObject(child1, "ROI_W", cJSON_CreateString(l_db_lpr_tb_info.ROI_W)); + cJSON_AddItemToObject(child1, "ROI_H", cJSON_CreateString(l_db_lpr_tb_info.ROI_H)); + cJSON_AddItemToObject(child1, "LP_X", cJSON_CreateString(l_db_lpr_tb_info.LP_X)); + cJSON_AddItemToObject(child1, "LP_Y", cJSON_CreateString(l_db_lpr_tb_info.LP_Y)); + cJSON_AddItemToObject(child1, "LP_W", cJSON_CreateString(l_db_lpr_tb_info.LP_W)); + cJSON_AddItemToObject(child1, "LP_H", cJSON_CreateString(l_db_lpr_tb_info.LP_H)); + cJSON_AddItemToObject(child1, "LP_BMP", cJSON_CreateString(l_db_lpr_tb_info.LP_BMP)); + cJSON_AddItemToObject(child1, "ROI_BMP", cJSON_CreateString(l_db_lpr_tb_info.ROI_BMP)); + cJSON_AddItemToObject(child1, "COUNTRY", cJSON_CreateString(l_db_lpr_tb_info.COUNTRY)); + cJSON_AddItemToObject(child1, "LPR_USER", cJSON_CreateString(l_db_lpr_tb_info.IN_USER)); + cJSON_AddItemToObject(child1, "LPR_PHONE", cJSON_CreateString(l_db_lpr_tb_info.IN_PHONE)); + cJSON_AddItemToObject(child1, "LPR_ADDRESS", cJSON_CreateString(l_db_lpr_tb_info.IN_ADDRESS)); + cJSON_AddItemToObject(child1, "LPR_PAYSTATUS", cJSON_CreateString(l_db_lpr_tb_info.IN_PAYSTATUS)); + cJSON_AddItemToObject(child1, "LPR_EXIST", cJSON_CreateString(l_db_lpr_tb_info.IN_EXIST)); + cJSON_AddItemToObject(child1, "LPR_SCHEDULE_S", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_START)); + cJSON_AddItemToObject(child1, "LPR_SCHEDULE_E", cJSON_CreateString(l_db_lpr_tb_info.IN_SCHEDULE_END)); + cJSON_AddItemToObject(child1, "LPR_OTHER", cJSON_CreateString(l_db_lpr_tb_info.IN_OTHER)); + cJSON_AddItemToObject(child1, "LPR_DETECT_ENDTIME", cJSON_CreateString(l_db_lpr_tb_info.IN_DETECT_ENDTIME)); + cJSON_AddItemToArray(child, child1); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + JsonString = cJSON_PrintUnformatted(root); + + //printf("\n[cgi_get_db_lpr_log] 7 JsonString:%s\n", JsonString); + strcat(beforeSendBuffer, JsonString); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //printf("\n[cgi_get_db_lpr_log] 9\n"); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2\n"); + //printf("\n[cgi_get_db_lpr_log] 10\n"); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + + l_result = l_idx + 1; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + + //fflush(wp); + + } + } + //printf("\n-----cgi get db lpr log count-------6\n"); + return l_result; +} +#endif + +/* + --- get lpr information --- + 1.All list + 2.list count + 3.download list count +*/ + +int cgi_get_search_info(SOCKET socket_in, char *path) +{ + //get all Information + //*Black List =>get_search_info?list=black + //*White List =>get_search_info?list=white + //*Log List =>get_search_info?list=log + //*Customer List =>get_search_info?list=customer + //*config List =>get_search_info?list=config + + //get List count + //*Black -> get_search_info?select=black&limit=1 + //*White -> get_search_info?select=white&limit=2 + //*Log -> get_search_info?select=log&limit=2 + //*Customer -> get_search_info?select=customer&limit=2 + + //get download .csv + //*Black -> get_search_info?download=black&lprcount=1 + //*White -> get_search_info?download=white&lprcount=1 + //*Log -> get_search_info?download=log&lprcount=1 + //*Customer -> get_search_info?download=customer&lprcount=1 + //*Customer -> get_search_info?download=ALL&lprcount=1 + char l_lpr_cgi_param[BUFSIZE*4] = {0}; + //char l_lpr_type[BUFSIZE * 4] = {0}; + char l_count[BUFSIZE * 4] = {0}; + char l_limit[BUFSIZE * 4] = {0}; + char l_compare_str[BUFSIZE * 4] = {0}; + char l_compare_str2[BUFSIZE * 4] = {0}; + char l_compare_str3[BUFSIZE * 4] = {0}; + char l_compare_str4[BUFSIZE * 4] = {0}; + char l_compare_str5[BUFSIZE * 4] = {0}; + + //printf("\n[cgi_get_search_info] path:%s",path); + //printf("\n[cgi_get_search_info] 1\n"); + sprintf(l_compare_str, "%s=", SETTYPE_DOWNLOAD); + + if(strncmp(path,"list=",5)==0) + { + //printf("\n[cgi_get_search_info] 2\n"); + strncpy(l_lpr_cgi_param, path+5, strlen(path)-5); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + + //printf("\n[cgi_get_search_info] l_lpr_cgi_param:%s", l_lpr_cgi_param); + //printf("\n[cgi_get_search_info] 3---0\n"); + if(strncmp(l_lpr_cgi_param,CUSTLISTNAME,strlen(CUSTLISTNAME))==0) + { + //printf("\n[cgi_get_search_info] 3--1\n"); + cgi_get_db_lpr_log(socket_in,LPR_MSG_CUSTOMERTABLE,CUSTLISTNAME,COUNT_CUSTOMER); + } + else if(strncmp(l_lpr_cgi_param,BKLISTNAME,strlen(BKLISTNAME))==0) + { + cgi_get_db_lpr_log(socket_in,LPR_MSG_BLACKTABLE,BKLISTNAME,COUNT_BLACK-100); + } + else if(strncmp(l_lpr_cgi_param,WTLISTNAME,strlen(WTLISTNAME))==0) + { + //printf("\n[cgi_get_search_info] 4\n"); + cgi_get_db_lpr_log(socket_in,LPR_MSG_WHITETABLE,WTLISTNAME,COUNT_WHITE-100); + //printf("\n[cgi_get_search_info] 5\n"); + } + else if(strncmp(l_lpr_cgi_param,LOGLISTNAME,strlen(LOGLISTNAME))==0) + { + cgi_get_db_lpr_log(socket_in,LPR_MSG_TABLE,LOGLISTNAME,COUNT_LOG); + } +#if 0 + else if(strcmp(l_lpr_cgi_param,CONFIGLISTNAME)==0) + { + get_license_config(wp); + } +#endif +#if 0 + else if(strncmp(l_lpr_cgi_param,MAPPINGNAME,strlen(MAPPINGNAME))==0) + { + cgi_get_db_lpr_mapping(socket_in,LPR_MAPPING_TABLE, MAPPINGNAME,COUNT_MAPPING); + } +#endif + + } + else if(strncmp(path, "select=", 7) == 0) + { + + strncpy(l_lpr_cgi_param, path + 7, strlen(path) - 7); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + + //printf("\n---------------path: %s\n",path); + //printf("\n---------------l_lpr_cgi_param: %s\n", l_lpr_cgi_param); + char* c_limit = NULL; + c_limit = strstr(path,"limit="); + //printf("\n---------------limit: %s\n",c_limit); + + if (c_limit != NULL) { + + strncpy(l_limit, c_limit + 6, strlen(c_limit) - 6); + l_limit[strlen(l_limit)] = '\0'; + //printf("\n---------------l_limit: %s\n", l_limit); + if (strlen(l_limit) >= 1) { + //printf("\n----strlen(l_limit):%d\n", strlen(l_limit)); + + if (strncmp(l_lpr_cgi_param, CUSTLISTNAME, strlen(CUSTLISTNAME)) == 0) + { + //printf("\n-------KKK 1\n"); + cgi_get_db_lpr_log_count(socket_in, LPR_MSG_CUSTOMERTABLE, CUSTLISTNAME, COUNT_CUSTOMER, atoi(l_limit)); + } + else if (strncmp(l_lpr_cgi_param, BKLISTNAME, strlen(BKLISTNAME)) == 0) + { + //printf("\n-------KKK 2\n"); + cgi_get_db_lpr_log_count(socket_in, LPR_MSG_BLACKTABLE, BKLISTNAME, COUNT_BLACK-100, atoi(l_limit)); + } + else if (strncmp(l_lpr_cgi_param, WTLISTNAME, strlen(WTLISTNAME)) == 0) + { + //printf("\n-------KKK 3\n"); + cgi_get_db_lpr_log_count(socket_in, LPR_MSG_WHITETABLE, WTLISTNAME, COUNT_WHITE-100, atoi(l_limit)); + } + else if (strncmp(l_lpr_cgi_param, LOGLISTNAME, strlen(LOGLISTNAME)) == 0) + { + //printf("\n-------KKK 4\n"); + //printf("\n-------atoi(l_limit):%d\n", atoi(l_limit)); + cgi_get_db_lpr_log_count(socket_in, LPR_MSG_TABLE, LOGLISTNAME, COUNT_LOG, atoi(l_limit)); + } + } + } + + + +#if 0 + else if(strcmp(l_lpr_type,MAPPINGNAME)==0) + { + if(CheckNumberRange(atoi(l_limit), 1, COUNT_MAPPING)) + { + cgi_get_db_lpr_map_count(socket_in,LPR_MAPPING_TABLE,MAPPINGNAME,COUNT_MAPPING,atoi(l_limit)); + } + } +#endif + + } + else if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + //printf("\n[cgi_get_search_info] 3"); + + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + char l_compare_str_temp[16] = { 0 }; + sprintf(l_compare_str_temp,"%s",CUSTLISTNAME); + sprintf(l_compare_str2,"%s",BKLISTNAME); + sprintf(l_compare_str3,"%s",WTLISTNAME); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + sprintf(l_compare_str5,"%s",LOGLISTNAME); + if(strncmp(l_lpr_cgi_param, l_compare_str_temp,strlen(l_compare_str_temp))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 4" ); + sprintf(l_compare_str_temp2,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_lprdb_log_file(socket_in, CUSTLISTNAME,LPR_MSG_CUSTOMERTABLE,atoi(l_count)); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 5"); + sprintf(l_compare_str_temp2,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_lprdb_log_file(socket_in, BKLISTNAME,LPR_MSG_BLACKTABLE,atoi(l_count)); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 6"); + sprintf(l_compare_str_temp2,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_lprdb_log_file(socket_in, WTLISTNAME,LPR_MSG_WHITETABLE,atoi(l_count)); + } + + } + else if(strncmp(l_lpr_cgi_param,l_compare_str5,strlen(l_compare_str5))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 7"); + sprintf(l_compare_str_temp2,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_lprdb_log_file(socket_in, LOGLISTNAME,LPR_MSG_TABLE,atoi(l_count)); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + char l_compare_str_temp2[16] = { 0 }; + //printf("\n[cgi_get_search_info] 8"); + sprintf(l_compare_str_temp2,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str_temp2, l_count); + if(strlen(l_count)!=0) + { + cgi_download_lprdb_mapping_file(socket_in, MAPPINGNAME,LPR_MAPPING_TABLE,atoi(l_count)); + } + else + { + cgi_download_lprdb_mapping_file(socket_in, MAPPINGNAME,LPR_MAPPING_TABLE,COUNT_MAPPING); + } + + } + else if(strncmp(l_lpr_cgi_param,"ALL",3)==0) + { + //printf("\n[cgi_get_search_info] 9"); + int l_WnB_MAX_Count = COUNT_WHITE+COUNT_BLACK-200; + //if(GetValidVar(wp,"lprcount",l_count)) + { + cgi_download_lprdb_list_file(socket_in, LOGLISTNAME,LPR_MSG_TABLE,l_WnB_MAX_Count); + } + } + } + //printf("\n[cgi_get_search_info] 6\n"); + return 0; +} +int cgi_download_lprdb_mapping_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int map_icount) +{ + time_t lpr_now_time; + struct tm *lpr_map_tm = NULL; + char lpr_map_time_fmt[64] = {0}; + char lpr_map_filename[64] = {0}; + char lpr_map_cgi_res[512] = {0}; + char lpr_sql_tb[20] = {0}; + //int l_result = 0; + int l_db_length=0; + lpr_now_time = time(NULL); + unsigned char header[3] = {(unsigned char)0xEF, (unsigned char)0xBB, (unsigned char)0xBF}; + lpr_map_tm = localtime(&lpr_now_time); + strftime(lpr_map_time_fmt, sizeof(lpr_map_time_fmt)-1, "%Y%m%d%H%M%S", lpr_map_tm); + + snprintf(lpr_map_filename, sizeof(lpr_map_time_fmt)-1, "%s_info.csv",log_type); + + snprintf(lpr_map_cgi_res ,sizeof(lpr_map_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Date: Tue, 27 Dec 2011 09:25:53 GMT\r\n" + "Accept-Ranges: bytes\r\n" + "Connection: close\r\n" + "Content-type: text/html;charset=UTF-8;\r\n" + "Content-Disposition: attachment; filename=%s\r\n" + "\r\n", lpr_map_filename); + + sprintf(lpr_sql_tb,"%s",log_sql_tb); + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_mapping_db_tb l_db_tb_info; + memset(&l_db_tb_info,0,sizeof(ffgroup_mapping_db_tb)); + char l_sql[512] = {0}; + int l_idx = 0; + int l_map_record_cnts = 0; + int l_rc; + + if (send(socket_in, lpr_map_cgi_res, strlen(lpr_map_cgi_res), MSG_MORE) == -1) + printf("\nsend error #5\n"); + + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;",log_sql_tb ,map_icount); + l_map_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, log_sql_tb); + + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s\n", l_sql); + + l_idx = -1; + } + else + { + if(l_map_record_cnts>=map_icount) + l_db_length=map_icount; + else + l_db_length=l_map_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + + db_get_lpr_map_record(g_ffgroup_db_info.pstmt, &l_db_tb_info); + if(l_idx==0) + { + if (send(socket_in, header, strlen((char *)header), MSG_MORE) == -1) + printf("\nsend error #6\n"); + } + memset(lpr_map_cgi_res, 0, sizeof(lpr_map_cgi_res)); + snprintf(lpr_map_cgi_res ,sizeof(lpr_map_cgi_res)-1, "%s," + "%s\r\n", + l_db_tb_info.LPR_DETECT, + l_db_tb_info.LPR); + + if (send(socket_in, lpr_map_cgi_res, strlen(lpr_map_cgi_res), MSG_MORE) == -1) + printf("\nsend error #7\n"); + + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + } + + //l_result = l_idx; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + } + } + return 0; +} + +bool check_if_not_in_black_and_white(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance){ + + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + int l_black_len = db_get_record_counts_check_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + //printf("\n[check_if_not_in_black_and_white]:%d\n", 3); + int l_white_len = db_get_record_counts_check_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + int l_log_record_cnts = l_black_len + l_white_len; + //printf("\n[check_if_not_in_black_and_white]:%d\n", 4); + //printf("\nAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\n%d\n", l_log_record_cnts); + //printf("\nBBBBBBBBBBBBBBBBBBBB\n"); + + if (l_log_record_cnts == 0) { + //printf("\n[check_if_not_in_black_and_white]:%d\n", 5); + return true; + } + //printf("\n[check_if_not_in_black_and_white]:%d\n", 6); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + int l_black_len = db_get_record_counts_check_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance); + //printf("\n[check_if_not_in_black_and_white]:%d\n", 3); + int l_white_len = db_get_record_counts_check_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance); + int l_log_record_cnts = l_black_len + l_white_len; + //printf("\n[check_if_not_in_black_and_white]:%d\n", 4); + //printf("\nAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\n%d\n", l_log_record_cnts); + //printf("\nBBBBBBBBBBBBBBBBBBBB\n"); + + if (l_log_record_cnts == 0) { + //printf("\n[check_if_not_in_black_and_white]:%d\n", 5); + return true; + } + //printf("\n[check_if_not_in_black_and_white]:%d\n", 6); + } + else { + int l_black_len = db_get_record_counts_check_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance); + //printf("\n[check_if_not_in_black_and_white]:%d\n", 3); + int l_white_len = db_get_record_counts_check_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance); + int l_log_record_cnts = l_black_len + l_white_len; + //printf("\n[check_if_not_in_black_and_white]:%d\n", 4); + //printf("\nAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\n%d\n", l_log_record_cnts); + //printf("\nBBBBBBBBBBBBBBBBBBBB\n"); + + if (l_log_record_cnts == 0) { + //printf("\n[check_if_not_in_black_and_white]:%d\n", 5); + return true; + } + //printf("\n[check_if_not_in_black_and_white]:%d\n", 6); + } + return false; +} + +bool check_if_in_black(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance, char *replaced_plate) { + //printf("\n[check_if_in_black]:%d\n", 1); + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + int l_black_len = db_get_record_counts_check_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + + if (l_black_len >= 1) { + + if (replaced_plate != NULL && levenshtein_distance >= 1 && unlockingKeyInnoFR_success == 0) { + db_get_record_plate_check_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance, replaced_plate); + } + + return true; + } + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + int l_black_len = db_get_record_counts_check_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance); + + if (l_black_len >= 1) { + + if (replaced_plate != NULL && levenshtein_distance >= 1 && unlockingKeyInnoFR_success == 0) { + db_get_record_plate_check_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance, replaced_plate); + } + + return true; + } + } + else { + int l_black_len = db_get_record_counts_check_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance); + + if (l_black_len >= 1) { + + if (replaced_plate != NULL && levenshtein_distance >= 1 && unlockingKeyInnoFR_success == 0) { + db_get_record_plate_check_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, levenshtein_distance, replaced_plate); + } + + return true; + } + } + return false; +} + +bool check_if_in_white(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance,char *replaced_plate) { + //printf("\n[check_if_in_white]:%d\n", 1); + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + int l_white_len = db_get_record_counts_check_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + + if (l_white_len >= 1) { + + if (replaced_plate != NULL && levenshtein_distance >= 1 && unlockingKeyInnoFR_success == 0) { + db_get_record_plate_check_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, levenshtein_distance, replaced_plate); + } + + return true; + } + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + int l_white_len = db_get_record_counts_check_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance); + + if (l_white_len >= 1) { + + if (replaced_plate != NULL && levenshtein_distance >= 1 && unlockingKeyInnoFR_success == 0) { + db_get_record_plate_check_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance, replaced_plate); + } + + return true; + } + } + else { + int l_white_len = db_get_record_counts_check_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance); + + if (l_white_len >= 1) { + + if (replaced_plate != NULL && levenshtein_distance >= 1 && unlockingKeyInnoFR_success == 0) { + db_get_record_plate_check_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, levenshtein_distance, replaced_plate); + } + + return true; + } + } + return false; +} + +bool get_schedule_start_in_black(char *ff_lpr_to_check, char *in_other_to_check,char *l_schedule_start, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_start_where_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + db_get_schedule_start_where_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_black]:%d\n", 1); + db_get_schedule_start_where_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_start) >= 1) + return true; + else + return false; +} + +bool get_schedule_start_in_white(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_start, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_start_where_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + db_get_schedule_start_where_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_white]:%d\n", 1); + db_get_schedule_start_where_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_start, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_start) >= 1) + return true; + else + return false; +} + +bool get_schedule_end_in_black(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_end_where_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + db_get_schedule_end_where_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_black]:%d\n", 1); + db_get_schedule_end_where_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_end) >= 1) + return true; + else + return false; +} + +bool get_schedule_end_in_white(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_schedule_end_where_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + db_get_schedule_end_where_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + } + else { + //printf("\n[get_schedule_start_in_white]:%d\n", 1); + db_get_schedule_end_where_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, l_schedule_end, levenshtein_distance); + //printf("\n--------------------l_schedule_start \n"); + } + + if (strlen(l_schedule_end) >= 1) + return true; + else + return false; +} + +bool get_detect_endtime_in_black(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_detect_endtime_where_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, in_other_to_check, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + db_get_detect_endtime_where_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else { + //printf("\n[get_detect_endtime_in_black]:%d\n", 1); + db_get_detect_endtime_where_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + //printf("\n--------------------l_detect_endtime \n"); + } + + if (strlen(l_detect_endtime) >= 1) + return true; + else + return false; +} + +bool get_detect_endtime_in_white(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance) { + if ((featureType & FEATURE_LPR_THA) != 0 || (featureType & FEATURE_LPR_BGD) != 0) { + db_get_detect_endtime_where_in_other_and_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, in_other_to_check, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { + db_get_detect_endtime_where_ff_lpr_upper(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + } + else { + //printf("\n[get_detect_endtime_in_white]:%d\n", 1); + db_get_detect_endtime_where_ff_lpr(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE, ff_lpr_to_check, l_detect_endtime, levenshtein_distance); + //printf("\n--------------------l_detect_endtime \n"); + } + + if (strlen(l_detect_endtime) >= 1) + return true; + else + return false; +} + +int cgi_download_lprdb_list_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount) +{ + time_t lpr_now_time; + + struct tm *lpr_log_tm = NULL; + char lpr_log_time_fmt[64] = {0}; + char lpr_log_filename[64] = {0}; + char lpr_log_cgi_res[512] = {0}; + char lpr_log_cgi_res_2[2048] = { 0 }; + char lpr_sql_tb[20] = {0}; + //int l_result = 0; + int l_db_length=0; + lpr_now_time = time(NULL); + int l_Max_downloadListcount = COUNT_WHITE+COUNT_BLACK-200; + unsigned char header[3] = {(unsigned char)0xEF, (unsigned char)0xBB, (unsigned char)0xBF}; +#define downloadLPRFile "listinfo.csv" + FILE *fd = NULL; + + lpr_log_tm = localtime(&lpr_now_time); + strftime(lpr_log_time_fmt, sizeof(lpr_log_time_fmt)-1, "%Y%m%d%H%M%S", lpr_log_tm); + + snprintf(lpr_log_filename, sizeof(lpr_log_time_fmt)-1, "%sinfo.csv","list"); + char l_lprmsg_path[36]={0}; + sprintf(l_lprmsg_path,"/tmp/%s",downloadLPRFile); + char l_list_cmd1[64]={0}; + sprintf(l_list_cmd1,"%s/%s","rm /tmp",downloadLPRFile); + system(l_list_cmd1); + + + if (!(fd = fopen(l_lprmsg_path, "wb,css=utf-8"))) + { + printf( "create %s failure\n",l_lprmsg_path); + if (fd) + fclose(fd); + } + + snprintf(lpr_log_cgi_res ,sizeof(lpr_log_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Date: Tue, 27 Dec 2011 09:25:53 GMT\r\n" + "Accept-Ranges: bytes\r\n" + "Connection: close\r\n" + "Content-type: text/html;charset=UTF-8\r\n" + "Content-Disposition: attachment;filename=%s\r\n" + "\r\n", lpr_log_filename); + + sprintf(lpr_sql_tb,"%s",log_sql_tb); + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_db_tb l_db_tb_info; + memset(&l_db_tb_info,0,sizeof(ffgroup_db_tb)); + char l_sql[2048] = {0}; + int l_idx = 0; + int l_log_record_cnts = 0; + int l_black_len=0; + int l_white_len=0; + int l_rc; + + if (send(socket_in, lpr_log_cgi_res, strlen(lpr_log_cgi_res), MSG_MORE) == -1) + printf("\nsend error #8\n"); + + snprintf(l_sql, sizeof(l_sql)-1, CMD_LPR_UNION_TABLE,l_Max_downloadListcount); + l_black_len=db_get_record_counts(g_ffgroup_db_info.pdb, LPR_MSG_BLACKTABLE); + l_white_len=db_get_record_counts(g_ffgroup_db_info.pdb, LPR_MSG_WHITETABLE); + l_log_record_cnts = l_black_len+l_white_len; + + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s\n", l_sql); + + l_idx = -1; + } + else + { + if(l_log_record_cnts>=log_icount) + l_db_length=log_icount; + else + l_db_length=l_log_record_cnts; + + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + char l_act_param[10]={0}; + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_tb_info); + trans_download_plate_type(l_act_param,l_db_tb_info.ACT_PARAM); + if(fd) + { + fprintf (fd, + "%s," + "%s," + "%s," + "%s," + "%s," + "%s," + "%s," + "%s\r\n", + l_act_param, + l_db_tb_info.LPR, + l_db_tb_info.IN_USER, + l_db_tb_info.IN_OTHER, + l_db_tb_info.IN_SCHEDULE_START, + l_db_tb_info.IN_SCHEDULE_END, + l_db_tb_info.IN_DETECT_ENDTIME, + l_db_tb_info.IN_PAYSTATUS); + + } + if(l_idx==0) + { + if (send(socket_in, header, strlen((char *)header), MSG_MORE) == -1) + printf("\nsend error #9\n"); + } + //memset(lpr_log_cgi_res, 0, sizeof(lpr_log_cgi_res)); + snprintf(lpr_log_cgi_res_2,sizeof(lpr_log_cgi_res_2)-1, + "%s,%s,%s,%s,%s,%s,%s,%s\r\n", + l_act_param, + l_db_tb_info.LPR, + l_db_tb_info.IN_USER, + l_db_tb_info.IN_OTHER, + l_db_tb_info.IN_SCHEDULE_START, + l_db_tb_info.IN_SCHEDULE_END, + l_db_tb_info.IN_DETECT_ENDTIME, + l_db_tb_info.IN_PAYSTATUS); + if (send(socket_in, lpr_log_cgi_res_2, strlen(lpr_log_cgi_res_2), MSG_MORE) == -1) + printf("\nsend error #10\n"); + + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + } + //l_result = l_idx; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + if (fd) + fclose(fd); + + char l_list_cmd[64]={0}; + sprintf(l_list_cmd,"%s/%s","chmod 755 /tmp",downloadLPRFile); + system(l_list_cmd); + + return 0; +} + +int cgi_download_lprdb_log_file(SOCKET socket_in, char *log_type,char *log_sql_tb,int log_icount) +{ + time_t lpr_now_time; + struct tm *lpr_log_tm = NULL; + char lpr_log_time_fmt[64] = {0}; + char lpr_log_filename[64] = {0}; + char lpr_log_cgi_res[512] = {0}; + char lpr_sql_tb[20] = {0}; + //int l_result = 0; + int l_db_length=0; + lpr_now_time = time(NULL); + + lpr_log_tm = localtime(&lpr_now_time); + strftime(lpr_log_time_fmt, sizeof(lpr_log_time_fmt)-1, "%Y%m%d%H%M%S", lpr_log_tm); + + snprintf(lpr_log_filename, sizeof(lpr_log_time_fmt)-1, "%sinfo.csv",log_type); + + + snprintf(lpr_log_cgi_res ,sizeof(lpr_log_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Date: Tue, 27 Dec 2011 09:25:53 GMT\r\n" + "Accept-Ranges: bytes\r\n" + "Connection: close\r\n" + "Content-type: text/html;charset=UTF-8;\r\n" + "Content-Disposition: attachment; filename=%s\r\n" + "\r\n", lpr_log_filename); + + sprintf(lpr_sql_tb,"%s",log_sql_tb); + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_db_tb l_db_tb_info; + memset(&l_db_tb_info,0,sizeof(ffgroup_db_tb)); + char l_sql[512] = {0}; + int l_idx = 0; + int l_log_record_cnts = 0; + int l_rc; + + if (send(socket_in, lpr_log_cgi_res, strlen(lpr_log_cgi_res), MSG_MORE) == -1) + printf("\nsend error #11\n"); + + if(strcmp(lpr_sql_tb,LPR_MSG_TABLE)==0 ||strcmp(lpr_sql_tb,LPR_MSG_CUSTOMERTABLE)==0) + { + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index DESC LIMIT %d;",LPR_MSG_TABLE ,log_icount); + l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, LPR_MSG_TABLE); + } + else + { + snprintf(l_sql, sizeof(l_sql)-1, "SELECT * FROM %s ORDER BY ff_index ASC LIMIT %d;",log_sql_tb ,log_icount); + l_log_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, log_sql_tb); + } + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s\n", l_sql); + + l_idx = -1; + } + else + { + if(l_log_record_cnts>=log_icount) + l_db_length=log_icount; + else + l_db_length=l_log_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_tb_info); + + memset(lpr_log_cgi_res, 0, sizeof(lpr_log_cgi_res)); + snprintf(lpr_log_cgi_res ,sizeof(lpr_log_cgi_res)-1, + "%s, " + "%s, " + "%s\r\n", + l_db_tb_info.ACT_PARAM, + l_db_tb_info.MOD_TS, + l_db_tb_info.LPR); + if (send(socket_in, lpr_log_cgi_res, strlen(lpr_log_cgi_res), MSG_MORE) == -1) + printf("\nsend error #12\n"); + + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + } + + //l_result = l_idx; + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + } + } + + return 0; +} +#if 0 +void GetValidVar_TO_SetValue(webs_t wp,char *chk_text,char *local_val,char *print_val) +{ + if(GetValidVar(wp,chk_text,local_val)) + { + sprintf(print_val,"%s",local_val); + //PDEBUG("%s:%s\n",chk_text,local_val); + } +} +#endif +int cgi_set_map_db_lpr(SOCKET socket_in, char *plist, int icount, char *itype) +{ + char type_name[16] = {0}; + char l_lpr_cgi_res[256]={0}; + snprintf(l_lpr_cgi_res , sizeof(l_lpr_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + char in_det_plate[128] = {0}; + char in_plate[128] = {0}; + char in_oplate[5000] = {0}; + int l_result=1; + const char *del_value = ":"; + + getvalueForKey(plist,"lpr_map_det_plate",in_det_plate); + getvalueForKey(plist,"lpr_map_plate",in_plate); + getvalueForKey(plist,"lpr_map_oplate",in_oplate); + + //PDEBUG("plist:%s\n",plist); + char *end = strstr(plist, "&"); + if(end != NULL) + { + memcpy(type_name, plist, strlen(plist) - strlen(end)); + } + + if(icount==1) + { + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + sqlite_ffgroup_update_map_list( in_det_plate,in_plate,in_oplate ,plist); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + sqlite_ffgroup_add_map_list( in_det_plate,in_plate, type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + int l_ret =sqlite_ffgroup_del_map(in_oplate, type_name,icount-1,icount); + if(l_ret) + { + l_result=0; + + } + } + } + else + { + + char str_det_plate[icount+1][STRSPLIT_SIZE] ; + char str_plate[icount+1][STRSPLIT_SIZE] ; + char str_oplate[icount+1][STRSPLIT_SIZE] ; + + StrSplit(in_det_plate, str_det_plate, del_value); + StrSplit(in_plate, str_plate, del_value); + StrSplit(in_oplate, str_oplate, del_value); + + int j=0; + int db_index=0; + while(j < icount) + { + db_index=j++; + + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + + sqlite_ffgroup_update_map_list( *(str_det_plate+db_index), *(str_plate+db_index) , *(str_oplate+db_index),type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + + sqlite_ffgroup_add_map_list( *(str_det_plate+db_index), *(str_plate+db_index) ,type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + int l_ret =sqlite_ffgroup_del_map(*(str_oplate+db_index), type_name,db_index,icount); + if(l_ret) + { + l_result=0; + } + } + } + } + if(!l_result) + { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + char tmpStr[BUFSIZE] = {0}; + strcat(beforeSendBuffer, "<lprinfo>\r\n"); + sprintf(tmpStr," <lpr_res>%d</lpr_res>\r\n",l_result); + strcat(beforeSendBuffer, tmpStr); + strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #13\n"); + l_result=1; + } + return 0; +} + +int cgi_set_db_lpr(SOCKET socket_in, char *plist, int icount, char *itype) +{ + char type_name[16] = {0}; + + const char *del_value = ":"; + + //=====insert date======== + + char i_user[64*6+1] = {0}; + char i_plate[128] = {0}; + char i_oplate[5000] = {0}; + char i_phone[128] = {0}; + char i_address[1024] = {0}; + char i_paystatus[128] = {0}; + char i_exist[128] = {0}; + char i_schedule_s[128] = {0}; + char i_schedule_e[128] = {0}; + char i_other[64*6+1] = {0}; + char i_detect_endtime[128] = {0}; + int l_result=1; + + getvalueForKey(plist,"lpr_user",i_user); + getvalueForKey(plist,"lpr_plate",i_plate); + getvalueForKey(plist,"lpr_oplate",i_oplate); + getvalueForKey(plist,"lpr_phone",i_phone); + getvalueForKey(plist,"lpr_address",i_address); + getvalueForKey(plist,"lpr_paystatus",i_paystatus); + getvalueForKey(plist,"lpr_exist",i_exist); + getvalueForKey(plist,"lpr_schedule_s",i_schedule_s); + getvalueForKey(plist,"lpr_schedule_e",i_schedule_e); + getvalueForKey(plist,"lpr_other",i_other); + getvalueForKey(plist,"lpr_detect_endtime",i_detect_endtime); + + //PDEBUG("plist:%s\n",plist); + char *end = strstr(plist, "&"); + if(end != NULL) + { + memcpy(type_name, plist, strlen(plist) - strlen(end)); + } + + if(icount==1) + { + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + sqlite_ffgroup_updateInfo_list( i_plate,i_oplate, i_user, i_phone, i_address, i_paystatus, i_exist, i_schedule_s,i_schedule_e, i_other,i_detect_endtime, type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + sqlite_ffgroup_add_list(i_plate, i_user, i_phone,i_address, i_paystatus,i_exist, i_schedule_s,i_schedule_e, i_other ,i_detect_endtime,type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + int l_ret =sqlite_ffgroup_del(i_oplate, type_name,icount-1,icount); + if(l_ret) + { + l_result=0; + + } + } + } + else + { + + char str_user[icount+1][STRSPLIT_SIZE] ; + char str_plate[icount+1][STRSPLIT_SIZE] ; + char str_oplate[icount+1][STRSPLIT_SIZE] ; + char str_phone[icount+1][STRSPLIT_SIZE] ; + char str_address[icount+1][STRSPLIT_SIZE] ; + char str_paystatus[icount+1][STRSPLIT_SIZE] ; + char str_exist[icount+1][STRSPLIT_SIZE] ; + char str_schedule_s[icount+1][STRSPLIT_SIZE] ; + char str_schedule_e[icount+1][STRSPLIT_SIZE] ; + char str_other[icount+1][STRSPLIT_SIZE] ; + char str_detect_endtime[icount+1][STRSPLIT_SIZE] ; + + + StrSplit(i_user, str_user, del_value); + StrSplit(i_plate, str_plate, del_value); + StrSplit(i_oplate, str_oplate, del_value); + StrSplit(i_phone, str_phone, del_value); + StrSplit(i_address, str_address, del_value); + StrSplit(i_paystatus, str_paystatus, del_value); + StrSplit(i_exist, str_exist, del_value); + StrSplit(i_schedule_s, str_schedule_s, del_value); + StrSplit(i_schedule_e, str_schedule_e, del_value); + StrSplit(i_other, str_other, del_value); + StrSplit(i_detect_endtime, str_detect_endtime, del_value); + + int j=0; + int db_index=0; + while(j < icount) + { + db_index=j++; + + if(strcmp(itype,SETTYPE_UPDATE)==0) + { + + sqlite_ffgroup_updateInfo_list( *(str_plate+db_index),*(str_oplate+db_index), *(str_user+db_index), *(str_phone+db_index), *(str_address+db_index), *(str_paystatus+db_index), + *(str_exist+db_index), *(str_schedule_s+db_index), *(str_schedule_e+db_index), *(str_other+db_index),*(str_detect_endtime+db_index), type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_ADD)==0) + { + + sqlite_ffgroup_add_list( *(str_plate+db_index), *(str_user+db_index), *(str_phone+db_index),*(str_address+db_index), *(str_paystatus+db_index),*(str_exist+db_index), + *(str_schedule_s+db_index), *(str_schedule_e+db_index), *(str_other+db_index) ,*(str_detect_endtime+db_index) ,type_name); + l_result=0; + } + else if(strcmp(itype,SETTYPE_DELETE)==0) + { + //printf("*(str_oplate+a:%d):%s\n",db_index,*(str_oplate+db_index)); + //printf("icount:%d\n",icount); + int l_ret =sqlite_ffgroup_del(*(str_oplate+db_index), type_name,db_index,icount); + if(l_ret) + { + //printf("1let:%d\n",l_ret); + //usSleep(10000); + l_result=0; + + //printf("2let:%d\n",l_ret); + } + } + } + } + + + if(!l_result) + { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE] = { 0 }; + + strcpy(beforeSendBuffer,"OK"); + + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //char tmpStr[BUFSIZE] = {0}; + //strcat(beforeSendBuffer, "<lprinfo>\r\n"); + //sprintf(tmpStr," <lpr_res>%d</lpr_res>\r\n",l_result); + //strcat(beforeSendBuffer, tmpStr); + //strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + + //printf("\n-------sendBuffer:%s\n", sendBuffer); + + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #14\n"); + l_result=1; + } + else { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE] = { 0 }; + + strcpy(beforeSendBuffer, "Fail"); + + //char sendBuffer[BUFSIZE] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + //char tmpStr[BUFSIZE] = { 0 }; + //strcat(beforeSendBuffer, "<lprinfo>\r\n"); + //sprintf(tmpStr, " <lpr_res>%d</lpr_res>\r\n", l_result); + //strcat(beforeSendBuffer, tmpStr); + //strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + + //printf("\n-------sendBuffer:%s\n", sendBuffer); + + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #142\n"); + } + + return 0; +} + + +int cgi_set_db_lpr_customer(SOCKET socket_in, char *plist, int icount, char *itype) +{ + char type_name[16] = { 0 }; + + const char *del_value = ":"; + const char *del_value2 = ";"; + + //=====insert date======== + + char i_user[64 * 6 + 1] = { 0 }; + char i_plate[128] = { 0 }; + char i_oplate[5000] = { 0 }; + char i_phone[128] = { 0 }; + char i_address[1024] = { 0 }; + char i_paystatus[128] = { 0 }; + char i_exist[128] = { 0 }; + char i_schedule_s[128] = { 0 }; + char i_schedule_e[128] = { 0 }; + char i_other[64 * 6 + 1] = { 0 }; + char i_detect_endtime[128] = { 0 }; + int l_result = 1; + + char delete_mod_ts[5000] = { 0 }; + + getvalueForKey(plist, "lpr_user", i_user); + getvalueForKey(plist, "lpr_plate", i_plate); + getvalueForKey(plist, "lpr_oplate", i_oplate); + getvalueForKey(plist, "lpr_phone", i_phone); + getvalueForKey(plist, "lpr_address", i_address); + getvalueForKey(plist, "lpr_paystatus", i_paystatus); + getvalueForKey(plist, "lpr_exist", i_exist); + getvalueForKey(plist, "lpr_schedule_s", i_schedule_s); + getvalueForKey(plist, "lpr_schedule_e", i_schedule_e); + getvalueForKey(plist, "lpr_other", i_other); + getvalueForKey(plist, "lpr_detect_endtime", i_detect_endtime); + + getvalueForKey(plist, "lpr_time", delete_mod_ts); + + //PDEBUG("plist:%s\n",plist); + char *end = strstr(plist, "&"); + if (end != NULL) + { + memcpy(type_name, plist, strlen(plist) - strlen(end)); + } + + if (icount == 1) + { + if (strcmp(itype, SETTYPE_UPDATE) == 0) + { + sqlite_ffgroup_updateInfo_list(i_plate, i_oplate, i_user, i_phone, i_address, i_paystatus, i_exist, i_schedule_s, i_schedule_e, i_other, i_detect_endtime, type_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_ADD) == 0) + { + sqlite_ffgroup_add_list(i_plate, i_user, i_phone, i_address, i_paystatus, i_exist, i_schedule_s, i_schedule_e, i_other, i_detect_endtime, type_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_DELETE) == 0) + { + int l_ret = sqlite_ffgroup_del_time(delete_mod_ts, type_name, icount - 1, icount); + if (l_ret) + { + l_result = 0; + + } + } + } + else + { + + char str_user[icount+1][STRSPLIT_SIZE] ; + char str_plate[icount+1][STRSPLIT_SIZE] ; + char str_oplate[icount+1][STRSPLIT_SIZE] ; + char str_phone[icount+1][STRSPLIT_SIZE] ; + char str_address[icount+1][STRSPLIT_SIZE] ; + char str_paystatus[icount+1][STRSPLIT_SIZE] ; + char str_exist[icount+1][STRSPLIT_SIZE] ; + char str_schedule_s[icount+1][STRSPLIT_SIZE] ; + char str_schedule_e[icount+1][STRSPLIT_SIZE] ; + char str_other[icount+1][STRSPLIT_SIZE] ; + char str_detect_endtime[icount+1][STRSPLIT_SIZE] ; + + char str_delete_mod_ts[icount+1][STRSPLIT_SIZE] ; + + + StrSplit(i_user, str_user, del_value); + StrSplit(i_plate, str_plate, del_value); + StrSplit(i_oplate, str_oplate, del_value); + StrSplit(i_phone, str_phone, del_value); + StrSplit(i_address, str_address, del_value); + StrSplit(i_paystatus, str_paystatus, del_value); + StrSplit(i_exist, str_exist, del_value); + StrSplit(i_schedule_s, str_schedule_s, del_value); + StrSplit(i_schedule_e, str_schedule_e, del_value); + StrSplit(i_other, str_other, del_value); + StrSplit(i_detect_endtime, str_detect_endtime, del_value); + + StrSplit(delete_mod_ts, str_delete_mod_ts, del_value2); + + int j = 0; + int db_index = 0; + while (j < icount) + { + db_index = j++; + + if (strcmp(itype, SETTYPE_UPDATE) == 0) + { + + sqlite_ffgroup_updateInfo_list(*(str_plate + db_index), *(str_oplate + db_index), *(str_user + db_index), *(str_phone + db_index), *(str_address + db_index), *(str_paystatus + db_index), + *(str_exist + db_index), *(str_schedule_s + db_index), *(str_schedule_e + db_index), *(str_other + db_index), *(str_detect_endtime + db_index), type_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_ADD) == 0) + { + + sqlite_ffgroup_add_list(*(str_plate + db_index), *(str_user + db_index), *(str_phone + db_index), *(str_address + db_index), *(str_paystatus + db_index), *(str_exist + db_index), + *(str_schedule_s + db_index), *(str_schedule_e + db_index), *(str_other + db_index), *(str_detect_endtime + db_index), type_name); + l_result = 0; + } + else if (strcmp(itype, SETTYPE_DELETE) == 0) + { + //printf("*(str_oplate+a:%d):%s\n",db_index,*(str_oplate+db_index)); + //printf("icount:%d\n",icount); + int l_ret = sqlite_ffgroup_del_time(*(str_delete_mod_ts + db_index), type_name, db_index, icount); + if (l_ret) + { + //printf("1let:%d\n",l_ret); + //usSleep(10000); + l_result = 0; + + //printf("2let:%d\n",l_ret); + } + } + } + } + + + if (!l_result) + { + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + char tmpStr[BUFSIZE] = { 0 }; + strcat(beforeSendBuffer, "<lprinfo>\r\n"); + sprintf(tmpStr, " <lpr_res>%d</lpr_res>\r\n", l_result); + strcat(beforeSendBuffer, tmpStr); + strcat(beforeSendBuffer, "</lprinfo>\r\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #14-2\n"); + l_result = 1; + } + return 0; +} + +int cgi_set_lpr_clean(SOCKET socket_in, char *icmd) +{ + int l_sql_ret=0; + //char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, icmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, icmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + if(!l_sql_ret) + { + strcat(beforeSendBuffer, "clean ok"); + } + else + { + strcat(beforeSendBuffer, "clean fail"); + } + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //if (send(socket_in, sendBuffer, sendBufferSize, MSG_MORE) == -1) + //printf("\nsend error #15\n"); + + + return l_sql_ret; +} +#if 0 +int cgi_set_restart_detect(webs_t wp) +{ + char l_lpr_cgi_res[256]={0}; + snprintf(l_lpr_cgi_res , sizeof(l_lpr_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + system("/usr/bin/killall -9 fflpr2"); + usSleep(1000000);//1s + fcntl(fileno(wp), F_SETFD, FD_CLOEXEC); + system("/www/ffgroup_lpr.sh &"); + usSleep(300000);//0.3s + + websWrite (wp, "%s","restart ok"); + return 0; +} + +/* + --- set_search_info --- + 1.delete list + 2.update list + 3.add list + 4.import list (X) + + 1.1 delete list (One) + *Black -> set_search_info?delete=black&lprcount=1&lpr_oplate=BLACKABC + *White -> set_search_info?delete=white&lprcount=1&lpr_oplate=WHITEABC + *Customer -> set_search_info?delete=customer&lprcount=1&lpr_oplate=CUSTOMERABC + + 1.2 delete list (Multi) + *Black -> set_search_info?delete=black&lprcount=3&lpr_oplate=BLACKAB1:BLACKAB2:BLACKAB3 + *White -> set_search_info?delete=white&lprcount=3&lpr_oplate=WHITEAB1:WHITEAB2:WHITEAB3 + *Customer -> set_search_info?delete=customer&lprcount=3&lpr_oplate=CUSTOMERAB1:CUSTOMERAB2:CUSTOMERAB3 + + 2.1 update list(One) + *Black -> set_search_info?update=black&lprcount=1&lpr_plate=NBLACKABC&lpr_oplate=BLACKABC&lpr_user=BLACK + &lpr_phone=123456789 + &lpr_address=NEW TAIPE No.20&lpr_paystatus=1&lpr_exist=&lpr_schedule=&lpr_other= + *White -> set_search_info?update=white&lprcount=1&lpr_plate=NWHITEABC&lpr_oplate=WHITEABC&lpr_user=WHITE + &lpr_phone=123456789 + &lpr_address=NEW TAIPE No.20&lpr_paystatus=1&lpr_exist=&lpr_schedule=&lpr_other= + 2.2 update list(Multi) + +*/ +#endif +int cgi_set_search_info(SOCKET socket_in, char *path) +{ + char l_lpr_cgi_param[BUFSIZE] = {0}; + char l_count[16] = {0}; + //char l_action_lpr[16] = {0}; + char l_compare_str[16] = {0}; + char l_compare_str2[16] = {0}; + char l_compare_str3[16] = {0}; + char l_compare_str4[16] = {0}; + char l_compare_str5[16] = {0}; + + //delete information + printf("\n[cgi_set_search_info]path:%s\n",path); + + sprintf(l_compare_str,"%s=",SETTYPE_DELETE); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s",CUSTLISTNAME); + sprintf(l_compare_str2,"%s",BKLISTNAME); + sprintf(l_compare_str3,"%s",WTLISTNAME); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str,strlen(l_compare_str))==0) + { + printf("\n[cgi_set_search_info]delete customer\n"); + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr_customer(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_map_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_DELETE); + } + } + return 0; + } + + //add information + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s=",SETTYPE_ADD); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_compare_str2, 0, sizeof(l_compare_str2)); + memset(l_compare_str3, 0, sizeof(l_compare_str3)); + memset(l_compare_str4, 0, sizeof(l_compare_str4)); + sprintf(l_compare_str,"%s",CUSTLISTNAME); + sprintf(l_compare_str2,"%s",BKLISTNAME); + sprintf(l_compare_str3,"%s",WTLISTNAME); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_ADD); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_ADD); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_map_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_ADD); + } + } + } + + //update information + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s=",SETTYPE_UPDATE); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_compare_str2, 0, sizeof(l_compare_str2)); + memset(l_compare_str3, 0, sizeof(l_compare_str3)); + memset(l_compare_str4, 0, sizeof(l_compare_str4)); + sprintf(l_compare_str,"%s",CONFIGLISTNAME); + sprintf(l_compare_str2,"%s",BKLISTNAME); + sprintf(l_compare_str3,"%s",WTLISTNAME); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_UPDATE); + } + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_UPDATE); + } + } +#if 0 + else if(strncmp(l_lpr_cgi_param,l_compare_str,strlen(l_compare_str))==0)//update=config + { + set_license_config(wp); + } +#endif + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"lprcount"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if(strlen(l_count)!=0) + { + cgi_set_map_db_lpr(socket_in, l_lpr_cgi_param, atoi(l_count),SETTYPE_UPDATE); + } + } + } + + //clean all data + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"%s=",SETTYPE_CLEAN); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + char l_sql_cmd[128]={0}; + char l_sql_tbname[20]={0}; + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_compare_str2, 0, sizeof(l_compare_str2)); + memset(l_compare_str3, 0, sizeof(l_compare_str3)); + memset(l_compare_str4, 0, sizeof(l_compare_str4)); + sprintf(l_compare_str,"%s",CUSTLISTNAME); + sprintf(l_compare_str2,"%s",BKLISTNAME); + sprintf(l_compare_str3,"%s",WTLISTNAME); + sprintf(l_compare_str4,"%s",MAPPINGNAME); + sprintf(l_compare_str5,"%s",LOGLISTNAME); + if(strncmp(l_lpr_cgi_param,l_compare_str2,strlen(l_compare_str2))==0) + { + chk_sql_msg_tbname(l_sql_tbname,BKLISTNAME); + sprintf(l_sql_cmd,CMD_CLEAN_LPR_MSG_TABLE,l_sql_tbname); + cgi_set_lpr_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str3,strlen(l_compare_str3))==0) + { + chk_sql_msg_tbname(l_sql_tbname,WTLISTNAME); + sprintf(l_sql_cmd,CMD_CLEAN_LPR_MSG_TABLE,l_sql_tbname); + cgi_set_lpr_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str,strlen(l_compare_str))==0) + { + chk_sql_msg_tbname(l_sql_tbname,CUSTLISTNAME); + sprintf(l_sql_cmd,CMD_CLEAN_LPR_MSG_TABLE,l_sql_tbname); + cgi_set_lpr_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str5,strlen(l_compare_str5))==0) + { + chk_sql_msg_tbname(l_sql_tbname,LOGLISTNAME); + //char l_event_cmd[64]={0}; + //sprintf(l_event_cmd,"chmod 755 %s",FILEPATH_EVENTS_DB); + //system(l_event_cmd); + //char l_clean_cmd[64]={0}; + //sprintf(l_clean_cmd,"timeout 10s rm -rf %s",FILEPATH_EVENTS_DB); + //system(l_clean_cmd); + sprintf(l_sql_cmd,CMD_CLEAN_LPR_MSG_TABLE,l_sql_tbname); + cgi_set_lpr_clean(socket_in,l_sql_cmd); + } + else if(strncmp(l_lpr_cgi_param,l_compare_str4,strlen(l_compare_str4))==0) + { + chk_sql_msg_tbname(l_sql_tbname,MAPPINGNAME); + sprintf(l_sql_cmd,CMD_CLEAN_LPR_MSG_TABLE,l_sql_tbname); + cgi_set_lpr_clean(socket_in,l_sql_cmd); + } + } +#if 0 + //restart detect + //set_search_info?restart=detect + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"restart="); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + if(strcmp(l_lpr_cgi_param,"detect")==0) + { + cgi_set_restart_detect(wp); + printf("restart detection\n"); + } + } + + //about lpr queue action + //set_search_info?queue=start + //set_search_info?queue=stop + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"queue="); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + if(strcmp(l_lpr_cgi_param,"stop")==0) + { + nvram_set("FFGROUP_QUEUE_STATUS","0"); + g_FFGROUP_QUEUE_STATUS = atoi(nvram_get("FFGROUP_QUEUE_STATUS")); + clear_queue_data(); + printf("stop recheck queue\n"); + websWrite (wp, "%s","stop recheck queue"); + } + else if(strcmp(l_lpr_cgi_param,"start")==0) + { + nvram_set("FFGROUP_QUEUE_STATUS","1"); + g_FFGROUP_QUEUE_STATUS = atoi(nvram_get("FFGROUP_QUEUE_STATUS")); + printf("start lpr queue\n"); + websWrite (wp, "%s","start lpr queue"); + } + else if(strcmp(l_lpr_cgi_param,"clear")==0) + { + clear_queue_data(); + printf("clear lpr queue\n"); + websWrite (wp, "%s","clear lpr queue"); + } + } + //int g_ftp_condition_channel=1; + //int g_httppost_condition_channel=1; + //set_search_info?action=ftp&status=1&channel=1 + //set_search_info?action=ftp&status=0&channel=1 + //set_search_info?action=httppost&status=1&channel=1 + //set_search_info?action=httppost&status=0&channel=1 + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str,"action="); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + char l_channel[5]={0}; + char l_status[5]={0}; + char l_event_cgi_res[256]={0}; + snprintf(l_event_cgi_res , sizeof(l_event_cgi_res)-1, "HTTP/1.1 200 OK\r\n" + "Server: httpd\r\n" + "Cache-Control: no-cache\r\n" + "Content-Type: text/html\r\n" + "\r\n"); + websWrite (wp, "%s",l_event_cgi_res); + + if(strcmp(l_action_lpr,"ftp")==0) + { + if(GetValidVar(wp,"status",l_status)) + { + g_ftp_status=atoi(l_status); + } + if(GetValidVar(wp,"channel",l_channel)) + { + g_ftp_condition_channel=atoi(l_channel); + } + } + if(strcmp(l_action_lpr,"httppost")==0) + { + if(GetValidVar(wp,"status",l_status)) + { + g_httppost_status=atoi(l_status); + } + if(GetValidVar(wp,"channel",l_channel)) + { + g_httppost_condition_channel=atoi(l_channel); + } + } + websWrite (wp, "%s","set ok"); + } +#endif + return 0; +} + +void callback_reset_db_list() +{ + char i_cmd_black[100]={0}; + char i_cmd_white[100]={0}; + sprintf(i_cmd_black,CMD_CLEAN_LPR_MSG_TABLE,LPR_MSG_BLACKTABLE); + sprintf(i_cmd_white,CMD_CLEAN_LPR_MSG_TABLE,LPR_MSG_WHITETABLE); + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + + //db_exec_sql(g_ffgroup_db_info.pdb, i_cmd_black); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, i_cmd_black); + if (l_rc == 0) + { + /*l_sql_ret = */db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + usSleep(1000); + //db_exec_sql(g_ffgroup_db_info.pdb, i_cmd_white); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + //int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, i_cmd_white); + if (l_rc == 0) + { + /*l_sql_ret = */db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + +} +void callback_reset_db_map_list() +{ + char s_cmd_map[100]={0}; + + sprintf(s_cmd_map,CMD_CLEAN_LPR_MSG_TABLE,LPR_MAPPING_TABLE); + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + //db_exec_sql(g_ffgroup_db_info.pdb, s_cmd_map); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, s_cmd_map); + if (l_rc == 0) + { + /*l_sql_ret = */db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + +} +int callback_import_lprlist_msg_to_db(void *data) +{ + char l_db_log_tbname[15]={0}; + ffgroup_listInfo_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + int ret = 0; + + if(!data) + { + + } + else { + lpr_insert_data = (ffgroup_listInfo_tb *)data; + + //if(g_ffgroup_db_info) + { + if (g_ffgroup_db_info.pdb) + { + + + //check List type + //printf("1lpr_insert_data->ACT_PARAM:%s\n",lpr_insert_data->ACT_PARAM); + chk_sql_msg_tbname(l_db_log_tbname, lpr_insert_data->ACT_PARAM); + //printf("2l_db_log_tbname:%s\n",l_db_log_tbname); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + db_get_record_counts(g_ffgroup_db_info.pdb, l_db_log_tbname); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd) - 1, INSERT_LPRLIST_DATA_CMD + , l_db_log_tbname + , "" + , "" + , "" + , lpr_insert_data->LPR + , "" + , "" + , "" + , lpr_insert_data->ACT_PARAM + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , lpr_insert_data->IN_USER + , ""//lpr_insert_data->IN_PHONE + , "" + , lpr_insert_data->IN_PAYSTATUS + , ""//lpr_insert_data->IN_EXIST + , lpr_insert_data->IN_SCHEDULE_START + , lpr_insert_data->IN_SCHEDULE_END + , lpr_insert_data->IN_OTHER + , lpr_insert_data->IN_DETECT_ENDTIME); + + //printf("Insert #2 LPR LIST Log: %s\n", l_sql_cmd); + //printf("Insert LPR LIST Log: %s\n", l_sql_cmd); + + + //l_sql_ret = db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if (l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /*if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + lprdb_mutex_unlock(g_ffgroup_db_info.pdb);*/ + //sqlite_restore_database(g_ffgroup_db_info.pdb); + } + else { + ret = 1; + } + + //db_unlock(g_ffgroup_db_info.pdb); + + } + } + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + } + + return ret; +} + +void callback_import_lpr_map_msg_to_db(void *data) +{ + //int l_map_record_cnts = 0; + ffgroup_mapping_db_tb *lpr_insert_data = NULL; + char l_sql_cmd[2048] = {0}; + int l_sql_ret = 0; + + if(!data) + { + return; + } + + lpr_insert_data = (ffgroup_mapping_db_tb *)data; + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + + //l_map_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, LPR_MAPPING_TABLE); + + snprintf(l_sql_cmd, sizeof(l_sql_cmd)-1, INSERT_LPR_MAPPING_CMD + ,LPR_MAPPING_TABLE + ,lpr_insert_data->LPR_DETECT + ,lpr_insert_data->LPR); + + printf("import insert LPR MAP Log: %s\n", l_sql_cmd); + + + //l_sql_ret=db_exec_sql(g_ffgroup_db_info.pdb, l_sql_cmd); + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + int l_rc; + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + if (l_rc == 0) + { + l_sql_ret = db_step_sql(g_ffgroup_db_info.pstmt); + //printf("\n[cgi_get_db_lpr_log] 6 l_rc:%d", l_rc); + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + + if(l_sql_ret) + { + printf("Error: %s\n", l_sql_cmd); + /* + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + */ + } + + } + } + + if (lpr_insert_data) { + free(lpr_insert_data); + lpr_insert_data = NULL; + } + +} + + +int str_levenshtein(const char *s, int ls, const char *t, int lt) +{ + int a, b, c; + + /* if either string is empty, difference is inserting all chars + * from the other + */ + if (!ls) return lt; + if (!lt) return ls; + + /* if last letters are the same, the difference is whatever is + * required to edit the rest of the strings + */ + if (s[ls] == t[ls]) + return str_levenshtein(s, ls - 1, t, lt - 1); + + /* else try: + * changing last letter of s to that of t; or + * remove last letter of s; or + * remove last letter of t, + * any of which is 1 edit plus editing the rest of the strings + */ + a = str_levenshtein(s, ls - 1, t, lt - 1); + b = str_levenshtein(s, ls, t, lt - 1); + c = str_levenshtein(s, ls - 1, t, lt ); + + if (a > b) a = b; + if (a > c) a = c; + + return a + 1; +} + +int compute_str_scale(double ret_levenshtein,double strlen1,double strlen2) +{ + int l_result=0; + double l_scale=ret_levenshtein/COMPARE_MAX(strlen1,strlen2); + l_result =((double)1-l_scale)*100; + return l_result; +} + + +//void action_lpr_import_infomation(char *iLPR , char *iACT_PARAM , char *iIN_USER , char *iIN_PHONE, +// char *iIN_PAYSTATUS, char *iIN_EXIST , char *iIN_SCHEDULE_START, +// char *iIN_SCHEDULE_END) +int action_lpr_import_infomation(char *iLPR , char *iACT_PARAM , char *iIN_USER ,char *iIN_OTHER, char *iIN_SCHEDULE_START, + char *iIN_SCHEDULE_END,char *iIN_ENDTIME, char *idet_level) +{ + int ret = 0; + pthread_mutex_lock(&mutex_db_lpr_import); + if(iLPR==NULL || iACT_PARAM ==NULL || iIN_USER ==NULL) + { + pthread_mutex_unlock(&mutex_db_lpr_import); + } + else { + //if(iIN_PHONE == NULL) + // sprintf(iIN_PHONE,"%s",""); + //if(iIN_ADDRESS == NULL) + // sprintf(iIN_ADDRESS,"%s",""); + //if(iIN_PAYSTATUS == NULL) + // sprintf(iIN_PAYSTATUS,"%s","0"); + //if(iIN_EXIST==NULL ) + // sprintf(iIN_EXIST,"%s","0"); + + char temp_iIN_SCHEDULE_START[10] = { 0 }; + char temp_iIN_SCHEDULE_END[10] = { 0 }; + char temp_idet_level[5] = { 0 }; + + if (strlen(iIN_SCHEDULE_START) != 5) + strcpy(temp_iIN_SCHEDULE_START, "00:00"); + else + strcpy(temp_iIN_SCHEDULE_START, iIN_SCHEDULE_START); + + if (strlen(iIN_SCHEDULE_END) != 5) + strcpy(temp_iIN_SCHEDULE_END, "23:59"); + else + strcpy(temp_iIN_SCHEDULE_END, iIN_SCHEDULE_END); + + + if (strlen(idet_level) != 1) + strcpy(temp_idet_level, "2"); + else + strcpy(temp_idet_level, idet_level); + + + char l_fix_endtime[64] = { 0 }; + char l_time[50] = { 0 }; + char l_yy[60] = { 0 }; + struct tm tm_ptr; + time_t the_time = time(NULL); + (void)time(&the_time); + localtime_r(&the_time, &tm_ptr); + + strftime(l_time, 30, "%Y_%m%d%H%M%S", &tm_ptr); + l_yy[0] = l_time[0]; + l_yy[1] = l_time[1]; + l_yy[2] = l_time[2]; + l_yy[3] = l_time[3]; + l_yy[4] = '\0'; + + sprintf(l_fix_endtime, "%d-%d-%d_%d:%d", atoi(l_yy) + 1, 12, 31, 23, 59); + + char l_act_param[10] = { 0 }; + + + chk_import_dbname(l_act_param, iACT_PARAM); + + + ffgroup_listInfo_tb *l_import_data = NULL; + //l_import_data=calloc(1,sizeof(ffgroup_listInfo_tb)); + l_import_data = (ffgroup_listInfo_tb*)malloc(sizeof(ffgroup_listInfo_tb)); + memset(l_import_data, 0, sizeof(ffgroup_listInfo_tb)); + + + //if(l_import_data!=NULL) + { + sprintf(l_import_data->LPR, "%s", iLPR); + sprintf(l_import_data->ACT_PARAM, "%s", l_act_param); + strcpy(l_import_data->IN_USER, iIN_USER); + strcpy(l_import_data->IN_OTHER, iIN_OTHER); + sprintf(l_import_data->IN_SCHEDULE_START, "%s", temp_iIN_SCHEDULE_START); + sprintf(l_import_data->IN_SCHEDULE_END, "%s", temp_iIN_SCHEDULE_END); + + if (strcmp(iIN_ENDTIME, "") == 0) + sprintf(l_import_data->IN_DETECT_ENDTIME, "%s", l_fix_endtime); + else + sprintf(l_import_data->IN_DETECT_ENDTIME, "%s", iIN_ENDTIME); + + sprintf(l_import_data->IN_PAYSTATUS, "%s", temp_idet_level); + + + ret = callback_import_lprlist_msg_to_db((void *)l_import_data); + } + pthread_mutex_unlock(&mutex_db_lpr_import); + } + return ret; +} +void action_import_lpr_map_info(char *iLPR_DETECT , char *iLPR) +{ + pthread_mutex_lock(&mutex_db_lpr_import); + if(iLPR_DETECT==NULL || iLPR ==NULL) + { + //usSleep(60000); + //printf("reload map list informatin\n"); + //stop_all_thread(); + //lilin_reboot_system(__FUNCTION__,__LINE__,LILIN_REBOOT_SYSTEM); + pthread_mutex_unlock(&mutex_db_lpr_import); + return; + + } + + ffgroup_mapping_db_tb *l_import_map=NULL; + //l_import_map=calloc(1,sizeof(ffgroup_mapping_db_tb)); + l_import_map = (ffgroup_mapping_db_tb*)malloc(sizeof(ffgroup_mapping_db_tb)); + memset(l_import_map,0,sizeof(ffgroup_mapping_db_tb)); + + //if(l_import_map!=NULL) + { + sprintf(l_import_map->LPR_DETECT ,"%s" ,iLPR_DETECT); + sprintf(l_import_map->LPR ,"%s" ,iLPR); + + + callback_import_lpr_map_msg_to_db( (void *)l_import_map); + + } + pthread_mutex_unlock(&mutex_db_lpr_import); + +} +#if 0 +int switch_lpr_detect_strength(int istrength) +{ + int strength_percent=0; + switch(istrength) + { + case 0://DETECT_VERYWEAK: + strength_percent=25; + break; + case 1://DETECT_WEAK: + strength_percent=50; + break; + case 2://DETECT_NORMAL: + strength_percent=75; + break; + case 3://DETECT_STRONG: + strength_percent=100; + break; + } + return strength_percent; +} +//int checkTime(char *idetect_time,char *iendtime,char *lprlist_end) +int checkTime(char *idetect_time,char *iendtime,char *lprlist_start,char *lprlist_end) +{ + int l_ret = 0; + char l_ndet_time[64]={0}; + char l_lprself_endtime[64]={0}; + char l_lprself_startschedule[64]={0}; + char l_lprself_endschedule[64]={0}; + + int l_ndet_year=0; + int l_lprself_endyear=0; + + char l_ndet_hourmin[10]={0}; + int i_ndet_hourmin=0; + char l_lprself_startschedule_hourmin[10]={0}; + char l_lprself_endschedule_hourmin[10]={0}; + int i_lprself_endschedule_hourmin=0; + int i_lprself_endschedule_min=0; + + + char tmp_det_blank[10][STRSPLIT_SIZE]; + char tmp_det_bottombar[10][STRSPLIT_SIZE];//_ + char tmp_det_colon[10][STRSPLIT_SIZE];//: + char tmp_lprself_start_schedule_colon[10][STRSPLIT_SIZE]; + char tmp_lprself_end_schedule_colon[10][STRSPLIT_SIZE]; + char tmp_lprself_endtime[10][STRSPLIT_SIZE]; + char tmp_lprself_pre_etime[10][STRSPLIT_SIZE]; + char tmp_lprself_post_etime[10][STRSPLIT_SIZE]; + + char require_det_MMDD[10]={0}; + char require_det_hhmm[10]={0}; + char require_detdate[15]={0}; + char require_dettime[10]={0}; + + char require_lprself_pre_etime[20]={0}; + char require_lprself_post_etime[20]={0}; + char require_lprself_endtime_MMDD[10]={0}; + char require_lprself_endtime_hhmm[10]={0}; + int i_require_lprself_endtime_hhmm=0; + int i_require_lprself_endtime_mm=0; + + sprintf(l_ndet_time ,"%s",idetect_time); + sprintf(l_lprself_endtime ,"%s",iendtime); + sprintf(l_lprself_startschedule ,"%s",lprlist_start); + sprintf(l_lprself_endschedule ,"%s",lprlist_end); + + + if(strcmp(l_lprself_endtime,"")==0) + { + printf("l_lprself_endtime is null.\n"); + l_ret = 1; + } + else + { + if(strcmp(l_ndet_time,"")==0) + { + printf("l_detect_time is null.\n"); + } + else + { + StrSplit(l_lprself_endtime, tmp_lprself_endtime, "_"); + StrSplit(l_ndet_time, tmp_det_blank, " "); + + int i=0,k=0; + + while(i<2) + { + k=i++; + if(i==1) + { + //Split DETECT LPR TIME + sprintf(require_detdate,"%s",*(tmp_det_blank+k)); + //Split END TIME + sprintf(require_lprself_pre_etime,"%s",*(tmp_lprself_endtime+k)); + } + else if(i==2) + { + //Split DETECT LPR TIME + sprintf(require_dettime,"%s",*(tmp_det_blank+k)); + //Split END TIME + sprintf(require_lprself_post_etime,"%s",*(tmp_lprself_endtime+k)); + } + } + + if((strlen(require_detdate)>0)&&(strlen(require_dettime)>0)) + { + + + + //DETECT LPR TIME + StrSplit(require_detdate, tmp_det_bottombar, "-"); + StrSplit(require_dettime, tmp_det_colon, ":"); + //END TIME + StrSplit(require_lprself_pre_etime, tmp_lprself_pre_etime, "-"); + StrSplit(require_lprself_post_etime, tmp_lprself_post_etime, ":"); + + StrSplit(l_lprself_endschedule, tmp_lprself_end_schedule_colon, ":"); + StrSplit(l_lprself_startschedule, tmp_lprself_start_schedule_colon, ":"); + + i=0; + k=0; + while(i<3) + { + k=i++; + char copy_lpr_str[5]={0}; + char copy_end_str[5]={0}; + + if(i==1) + { + l_ndet_year=atoi(*(tmp_det_bottombar+k)); + l_lprself_endyear=atoi(*(tmp_lprself_pre_etime+k)); + } + else if(i==2) + { + //DETECT MONTH + sprintf(copy_lpr_str,"%s",*(tmp_det_bottombar+k)); + strcat(require_det_MMDD,copy_lpr_str); + //ENDTIME MONTH + sprintf(copy_end_str,"%s",*(tmp_lprself_pre_etime+k)); + strcat(require_lprself_endtime_MMDD,copy_end_str); + } + else if(i==3) + { + //DETECT DAY + sprintf(copy_lpr_str,"%s",*(tmp_det_bottombar+k)); + strcat(require_det_MMDD,copy_lpr_str); + //ENDTIME DAY + sprintf(copy_end_str,"%s",*(tmp_lprself_pre_etime+k)); + strcat(require_lprself_endtime_MMDD,copy_end_str); + } + } + i=0; + k=0; + while(i<3) + { + k=i++; + char copy_lpr_str[5]={0}; + char copy_end_str[5]={0}; + if(i==1) + { + //DETECT HOUR + sprintf(copy_lpr_str,"%s",*(tmp_det_colon+k)); + strcat(require_det_hhmm,copy_lpr_str); + //ENDTIME HOUR + sprintf(copy_end_str,"%s",*(tmp_lprself_post_etime+k)); + + strcat(require_lprself_endtime_hhmm,copy_end_str); + //compare detectime + sprintf(l_ndet_hourmin,"%s",copy_lpr_str); + + //compare list + sprintf(l_lprself_startschedule_hourmin,"%s",*(tmp_lprself_start_schedule_colon+k)); + sprintf(l_lprself_endschedule_hourmin,"%s",*(tmp_lprself_end_schedule_colon+k)); + } + else if(i==2) + { + //DETECT MINS + sprintf(copy_lpr_str,"%s",*(tmp_det_colon+k)); + strcat(require_det_hhmm,copy_lpr_str); + //ENDTIME MINS + sprintf(copy_end_str,"%s",*(tmp_lprself_post_etime+k)); + strcat(require_lprself_endtime_hhmm,copy_end_str); + i_require_lprself_endtime_mm =atoi(copy_end_str); + //compare detectime + strcat(l_ndet_hourmin,copy_lpr_str); + + //compare list + strcat(l_lprself_startschedule_hourmin,*(tmp_lprself_start_schedule_colon+k)); + strcat(l_lprself_endschedule_hourmin,*(tmp_lprself_end_schedule_colon+k)); + i_lprself_endschedule_min=atoi(*(tmp_lprself_end_schedule_colon+k)); + } + + } + if(i_lprself_endschedule_min == 59) + { + i_lprself_endschedule_hourmin = atoi(l_lprself_endschedule_hourmin)+41; + i_lprself_endschedule_hourmin =i_lprself_endschedule_hourmin+1; + } + else + i_lprself_endschedule_hourmin = atoi(l_lprself_endschedule_hourmin)+1; + + if(i_require_lprself_endtime_mm == 59) + { + i_require_lprself_endtime_hhmm = atoi(require_lprself_endtime_hhmm)+41; + i_require_lprself_endtime_hhmm = i_require_lprself_endtime_hhmm+1; + } + else + i_require_lprself_endtime_hhmm = atoi(require_lprself_endtime_hhmm)+1; + i_ndet_hourmin =atoi(l_ndet_hourmin); + +// printf("l_ndet_hourmin:%s\n",l_ndet_hourmin); +// printf("i_ndet_hourmin:%d\n",i_ndet_hourmin); +// printf("l_lprself_startschedule_hourmin:%s\n",l_lprself_startschedule_hourmin); +// printf("l_lprself_endschedule_hourmin:%s\n",l_lprself_endschedule_hourmin); +// printf("i_lprself_endschedule_hourmin:%d\n",i_lprself_endschedule_hourmin); + if(i_ndet_hourmin >= atoi(l_lprself_startschedule_hourmin)) + { + if(atoi(l_ndet_hourmin) < i_lprself_endschedule_hourmin ) + { +// printf("atoi(require_det_hhmm):%d\n",atoi(require_det_hhmm)); +// printf("atoi(require_lprself_endtime_hhmm):%d\n",atoi(require_lprself_endtime_hhmm)); +// printf("i_require_lprself_endtime_hhmm:%d\n",i_require_lprself_endtime_hhmm); +// printf("atoi(require_det_MMDD):%d\n",atoi(require_det_MMDD)); +// printf("atoi(require_lprself_endtime_MMDD):%d\n",atoi(require_lprself_endtime_MMDD)); + if(l_ndet_year == l_lprself_endyear ) + { + if(atoi(require_det_MMDD) == atoi(require_lprself_endtime_MMDD)) + { + if(atoi(require_det_hhmm) < i_require_lprself_endtime_hhmm) + { + l_ret=1; + } + }else if(atoi(require_det_MMDD) < atoi(require_lprself_endtime_MMDD)) + { + l_ret=1; + } + + } + else + { + if(l_ndet_year < l_lprself_endyear ) + { + l_ret=1; + } + } + } + + } + } + } + } + + return l_ret; +} + +int insert_lpr_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr) +{ + + int l_result=0; + + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_db_tb)); + char l_db_name[15]={0}; + char l_sql_cmd[256]={0}; + int l_db_length=0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //check List type + chk_sql_msg_tbname(l_db_name,ilist_type); + + + sprintf(l_sql_cmd,CMD_SELECT_LPR,l_db_name); + + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_name); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql_cmd, l_rc); + l_result= -1; + + } + else + { + l_db_length=l_lpr_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + + int l_det_threshold=switch_lpr_detect_strength(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)); + + int l_str_ret=str_levenshtein(l_db_lpr_tb_info.LPR, strlen(l_db_lpr_tb_info.LPR), idetect_lpr, strlen(idetect_lpr)); + + int l_lpr_percent=compute_str_scale((double)l_str_ret,(double) strlen(l_db_lpr_tb_info.LPR),(double)strlen(idetect_lpr)); + + if(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)==3) + { + if(l_str_ret==0) + { + + l_lpr_percent=100; + if(l_lpr_percent==l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + //printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + } + + } + else + { + if(l_lpr_percent > l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + //printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + + } + } + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + //printf("insert_lpr_Levenshtein:%d\n",l_result); + return l_result; +} + +int compute_lpr_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr,get_lpr_list_param *l_chk_lpr) +{ + + int l_result=0; + memset(l_chk_lpr,0,sizeof(get_lpr_list_param)); + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_db_tb)); + char l_db_name[15]={0}; + char l_sql_cmd[256]={0}; + int l_db_length=0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //check List type + chk_sql_msg_tbname(l_db_name,ilist_type); + + + sprintf(l_sql_cmd,CMD_SELECT_LPR,l_db_name); + + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_name); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql_cmd, l_rc); + l_result= -1; + + } + else + { + l_db_length=l_lpr_record_cnts; + + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_lpr_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + + int l_det_threshold=switch_lpr_detect_strength(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)); + + int l_str_ret=str_levenshtein(l_db_lpr_tb_info.LPR, strlen(l_db_lpr_tb_info.LPR), idetect_lpr, strlen(idetect_lpr)); + + int l_lpr_percent=compute_str_scale((double)l_str_ret,(double) strlen(l_db_lpr_tb_info.LPR),(double)strlen(idetect_lpr)); + printf("l_str_ret:%d\n",l_str_ret); + printf("l_lpr_percent:%d\n",l_lpr_percent); + printf("l_det_threshold:%d\n",l_lpr_percent); + printf("atoi(l_db_lpr_tb_info.IN_PAYSTATUS):%d\n",atoi(l_db_lpr_tb_info.IN_PAYSTATUS)); + if(atoi(l_db_lpr_tb_info.IN_PAYSTATUS)==3) + { + if(l_str_ret==0) + { + + l_lpr_percent=100; + if(l_lpr_percent==l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + sprintf(l_chk_lpr->LPR_USER,"%s",l_db_lpr_tb_info.IN_USER); + sprintf(l_chk_lpr->LPR_OTHER,"%s",l_db_lpr_tb_info.IN_OTHER); + sprintf(l_chk_lpr->DETECT_START_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_START); + sprintf(l_chk_lpr->DETECT_END_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_END); + sprintf(l_chk_lpr->DETECT_STOP_TIME,"%s",l_db_lpr_tb_info.IN_DETECT_ENDTIME); + printf("1l_chk_lpr.LPR_USER:%s\n",l_chk_lpr->LPR_USER); + printf("1l_chk_lpr.LPR_OTHER:%s\n",l_chk_lpr->LPR_OTHER); + printf("1l_chk_lpr.DETECT_START_TIME:%s\n",l_chk_lpr->DETECT_START_TIME); + printf("1l_chk_lpr.DETECT_END_TIME:%s\n",l_chk_lpr->DETECT_END_TIME); + printf("1l_chk_lpr.DETECT_STOP_TIME:%s\n",l_chk_lpr->DETECT_STOP_TIME); + printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + } + + } + else + { + if(l_lpr_percent > l_det_threshold) + { + sprintf(result_lpr,"%s",l_db_lpr_tb_info.LPR); + sprintf(l_chk_lpr->LPR_USER,"%s",l_db_lpr_tb_info.IN_USER); + sprintf(l_chk_lpr->LPR_OTHER,"%s",l_db_lpr_tb_info.IN_OTHER); + sprintf(l_chk_lpr->DETECT_START_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_START); + sprintf(l_chk_lpr->DETECT_END_TIME,"%s",l_db_lpr_tb_info.IN_SCHEDULE_END); + sprintf(l_chk_lpr->DETECT_STOP_TIME,"%s",l_db_lpr_tb_info.IN_DETECT_ENDTIME); + printf("2l_chk_lpr.LPR_USER:%s\n",l_chk_lpr->LPR_USER); + printf("2l_chk_lpr.LPR_OTHER:%s\n",l_chk_lpr->LPR_OTHER); + printf("2l_chk_lpr.DETECT_START_TIME:%s\n",l_chk_lpr->DETECT_START_TIME); + printf("2l_chk_lpr.DETECT_END_TIME:%s\n",l_chk_lpr->DETECT_END_TIME); + printf("2l_chk_lpr.DETECT_STOP_TIME:%s\n",l_chk_lpr->DETECT_STOP_TIME); + printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + l_result=checkTime(idetect_time,l_db_lpr_tb_info.IN_DETECT_ENDTIME,l_db_lpr_tb_info.IN_SCHEDULE_START,l_db_lpr_tb_info.IN_SCHEDULE_END); + //l_result=1; + break; + } + + } + } + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } + //printf("insert_lpr_Levenshtein:%d\n",l_result); + return l_result; +} + +void mapping_detect_lpr(char *ilist_type,char *idetect_lpr,char *mapping_lpr) +{ + //if(g_ffgroup_db_info) + { + if(g_ffgroup_db_info.pdb) + { + ffgroup_mapping_db_tb l_db_lpr_tb_info; + memset(&l_db_lpr_tb_info,0,sizeof(ffgroup_mapping_db_tb)); + char l_db_name[15]={0}; + char l_sql_cmd[256]={0}; + int l_db_length=0; + int l_lpr_record_cnts = 0; + int l_idx = 0; + int l_rc; + //check List type + chk_sql_msg_tbname(l_db_name,ilist_type); + + + sprintf(l_sql_cmd,CMD_SELECT_LPR,l_db_name); + + + lprdb_mutex_lock(g_ffgroup_db_info.pdb); + + l_lpr_record_cnts = db_get_record_counts(g_ffgroup_db_info.pdb, l_db_name); + + l_rc = db_prepare_sql(g_ffgroup_db_info.pdb, &g_ffgroup_db_info.pstmt, l_sql_cmd); + + if (l_rc == 0) + { + l_rc = db_step_sql(g_ffgroup_db_info.pstmt); + } + + if ( l_rc != 0) + { + printf("####### Can't prepare SQL:%s, rc:%d\n", l_sql_cmd, l_rc); + + } + else + { + l_db_length=l_lpr_record_cnts; + printf("mapping_detect_lpr length:%d\n",l_db_length); + for(l_idx=0; l_idx<l_db_length && l_rc == 0; l_idx++) + { + db_get_lpr_map_record(g_ffgroup_db_info.pstmt, &l_db_lpr_tb_info); + l_rc = db_move_next_record(g_ffgroup_db_info.pstmt); + printf("l_db_lpr_tb_info.LPR_DETECT:%s\n",l_db_lpr_tb_info.LPR_DETECT); + printf("l_db_lpr_tb_info.LPR:%s\n",l_db_lpr_tb_info.LPR); + printf("idetect_lpr:%s\n",idetect_lpr); + + if(strcmp(idetect_lpr,l_db_lpr_tb_info.LPR_DETECT)==0) + { + sprintf(mapping_lpr,"%s",l_db_lpr_tb_info.LPR); + break; + } + } + if(strcmp(mapping_lpr,"")==0) + { + sprintf(mapping_lpr,"%s",idetect_lpr); + } + } + db_free_sql_stmt(g_ffgroup_db_info.pstmt); + lprdb_mutex_unlock(g_ffgroup_db_info.pdb); + } + } +} +#endif \ No newline at end of file diff --git a/src/fflpr_plate_db.h b/src/fflpr_plate_db.h new file mode 100644 index 0000000..89aae13 --- /dev/null +++ b/src/fflpr_plate_db.h @@ -0,0 +1,458 @@ +#if 1 +#pragma once +#ifndef FFLPR_PLATE_DB_H +#define FFLPR_PLATE_DB_H +#include "define_inc.h" +//#include "../httpd/httpd.h" +//#include "../httpd/lilincgi.h" +//#include "../httpd/lilin_thread_pool.h" +//#include "../httpd/lilin_reboot.h" +//#include "../httpd/util/string_util.h" +//#include "../common/shutils.h" +//#include "../httpd/actionevent.h" +//#include "ff_license_plate.h" +//#include "../httpd/dynmic_ationevnet.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <stdbool.h> +#include <unistd.h> +#include <pthread.h> +#include <libgen.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <fcntl.h> +#include <ctype.h> + +#include <locale.h> +#include <wchar.h> + +#include "utility.h" +#include "cJSON.h" +#include "sqlite_db.h" +#include "fork_pipe_lib.h" +#include "levenshtein_sqlite.h" + +#define COMPARE_MAX(x, y) (((x) > (y)) ? (x) : (y)) + +#define ACT_PARAM_BKLISTNAME "Denial" +#define ACT_PARAM_WTLISTNAME "Allowed" +#define ACT_PARAM_CUSTLISTNAME "Visitor" + +#define S_ACT_PARAM_BKLISTNAME "denial" +#define S_ACT_PARAM_WTLISTNAME "allowed" +#define S_ACT_PARAM_CUSTLISTNAME "visitor" + +#define ACT_PARAM_BKLISTNAME_FACE "Watch" +#define ACT_PARAM_WTLISTNAME_FACE "Vip" +#define ACT_PARAM_CUSTLISTNAME_FACE "Visitor" + +#define S_ACT_PARAM_BKLISTNAME_FACE "watch" +#define S_ACT_PARAM_WTLISTNAME_FACE "vip" +#define S_ACT_PARAM_CUSTLISTNAME_FACE "visitor" + +#define BKLISTNAME "black" +#define WTLISTNAME "white" +#define CUSTLISTNAME "customer" + + +#define BKLISTNAME_FACE "watch" +#define WTLISTNAME_FACE "vip" +#define CUSTLISTNAME_FACE "visitor" + +#define LOGLISTNAME "log" +#define MAX_ROW_DATA 10 + +#define CONFIGLISTNAME "config" +#define MAPPINGNAME "mapping" + +#define SETTYPE_SELECT "select" +#define SETTYPE_DELETE "delete" +#define SETTYPE_ADD "add" +#define SETTYPE_UPDATE "update" +#define SETTYPE_DOWNLOAD "download" +#define SETTYPE_CLEAN "clean" +#define SETTYPE_IMPORT "import" + +#define DETECT_VERYWEAK 0 +#define DETECT_WEAK 1 +#define DETECT_NORMAL 2 +#define DETECT_STRONG 3 + +#define COUNT_MULTIPLATE 4 +//#define COUNT_MAXLPRCOUNT 2000 +#define COUNT_COMPARE 3 +#define COUNT_BLACK 5100 //100 + +#define COUNT_LOG 600 //1000 +#define COUNT_MAPPING 1000 +#define DELETECOUNT 200 +#define MAX_COUNT 800 //1200 + + +#define COUNT_WHITE 5100 //2000 +#define COUNT_CUSTOMER 600 //2000 +#define MAX_CUSTOMER_COUNT 800 //2200 + + +#define LPRLIST_TMP_IMPORTFILE "lprlist_tmp.csv" +#define LPRLIST_IMPORTFILE "lprlist.csv" +#define DB_FFGROUP_MSG_PATH "/emmc/plugin/Aida_data/db_fflpr.db" +#define LPROPTSIZE 368640 //360KIB + +#define TABLE_LPR_VERSION "lpr_ver_tb" + +#define LPR_MSG_TABLE "lpr_db_tb" +#define LPR_MAPPING_TABLE "lpr_mapping_tb" + +#define LPR_MSG_BLACKTABLE "lpr_db_black_tb" +#define LPR_MSG_WHITETABLE "lpr_db_white_tb" +#define LPR_MSG_CUSTOMERTABLE "lpr_db_cust_tb" + + +#define CHK_WORD_LENGTH 27 + +extern int g_ftp_condition_channel; +extern int g_httppost_condition_channel; +extern int g_ftp_status; +extern int g_httppost_status; + +struct memory_lpr_data +{ + char *memory; + size_t size; +}; + +typedef struct _ffgroup_db_tb +{ + char TS[20]; + char MOD_TS[30]; + char CAR_ID[20]; + char LPR[100]; + + char RTIME[20]; + char ACTION[5]; + char sec_color_id[5]; + char ACT_PARAM[30]; + char THRESHOLD[20]; + char ROI_X[6]; + char ROI_Y[6]; + char ROI_W[6]; + char ROI_H[6]; + char LP_X[6]; + char LP_Y[6]; + char LP_W[6]; + char LP_H[6]; + char LP_BMP[100]; + char ROI_BMP[60]; + char COUNTRY[10]; + + // add/edit the info + char IN_USER[512]; + char IN_PHONE[20]; + char IN_ADDRESS[200]; + char IN_PAYSTATUS[5]; + char IN_EXIST[5]; + char IN_SCHEDULE_START[20]; + char IN_SCHEDULE_END[20]; + char IN_OTHER[512]; + + char tb_type[20]; + char sql_tbname[20]; + char sql_count[5]; + char IN_DETECT_ENDTIME[64]; + + //chk_get_list + int onblack; + int onwhite; + char bksql_tbname[20]; + char wtsql_tbname[20]; + +} ffgroup_db_tb; + +typedef struct _ffgroup_listInfo_tb +{ + char LPR[100]; + char oLPR[100]; + char ACT_PARAM[30]; + char IN_USER[512]; + char IN_PHONE[20]; + char IN_ADDRESS[200]; + char IN_PAYSTATUS[5]; + char IN_EXIST[5]; + char IN_SCHEDULE_START[20]; + char IN_SCHEDULE_END[20]; + char IN_OTHER[512]; + char IN_DETECT_ENDTIME[64]; + + char tb_type[20]; +} ffgroup_listInfo_tb; + + + +typedef struct _ffgroup_compare_info +{ + //char s_count[20]; + //char s_chk_count[20]; + int count; + int detect; + ffgroup_db_tb ary_mult[COUNT_MULTIPLATE+1]; +}ffgroup_compare_info; + + + +typedef struct _get_lpr_list_param +{ + char LPR_USER[512]; + char LPR_OTHER[512]; + char DETECT_START_TIME[20]; + char DETECT_END_TIME[20]; + char DETECT_STOP_TIME[64]; + +} get_lpr_list_param; + +typedef struct _ffgroup_mapping_db_tb +{ + char LPR_DETECT[100]; + char LPR[100]; + char oLPR[100]; + char tb_type[20]; + +} ffgroup_mapping_db_tb; +#define CMD_CREATE_LPR_VERSION_TABLE "CREATE TABLE IF NOT EXISTS lpr_ver_tb("\ + "ff_ver_num INTEGER PRIMARY KEY NOT NULL,"\ + "ff_ver_date DATE NOT NULL,"\ + "ff_ver_comment CHAR(64));" + +#define CMD_CREATE_LPR_TABLE "CREATE TABLE IF NOT EXISTS %s("\ + "ff_index INTEGER PRIMARY KEY AUTOINCREMENT,"\ + "ff_ts CHAR(20) NOT NULL,"\ + "ff_mod_ts CHAR(30) NOT NULL,"\ + "ff_car_id CHAR(20) NOT NULL,"\ + "ff_lpr CHAR(100) NOT NULL,"\ + "ff_rtime CHAR(20) NOT NULL,"\ + "ff_action CHAR(5),"\ + "ff_sec_color_id CHAR(5),"\ + "ff_act_param CHAR(30),"\ + "ff_threshold CHAR(20) NOT NULL,"\ + "ff_roiX CHAR(6) NOT NULL,"\ + "ff_roiY CHAR(6) NOT NULL,"\ + "ff_roiW CHAR(6) NOT NULL,"\ + "ff_roiH CHAR(6) NOT NULL,"\ + "ff_lpX CHAR(6) NOT NULL,"\ + "ff_lpY CHAR(6) NOT NULL,"\ + "ff_lpW CHAR(6) NOT NULL,"\ + "ff_lpH CHAR(6) NOT NULL,"\ + "ff_lpbmp CHAR(100) NOT NULL,"\ + "ff_lproi CHAR(60) ,"\ + "ff_country CHAR(10),"\ + "in_user NCHAR(512),"\ + "in_phone CHAR(20),"\ + "in_address NCHAR(200),"\ + "in_paystatus CHAR(5),"\ + "in_exist CHAR(5),"\ + "in_schedule_start CHAR(20),"\ + "in_schedule_end CHAR(20),"\ + "in_other NCHAR(512),"\ + "in_detect_endtime CHAR(64));" + //"in_address NCHAR(300)," + //"in_other NCHAR(128));" + +#define CMD_CREATE_LPRLIST_TABLE "CREATE TABLE IF NOT EXISTS %s("\ + "ff_index INTEGER PRIMARY KEY AUTOINCREMENT,"\ + "ff_ts CHAR(20) ,"\ + "ff_mod_ts CHAR(30) ,"\ + "ff_car_id CHAR(20) ,"\ + "ff_lpr CHAR(100) NOT NULL,"\ + "ff_rtime CHAR(20) ,"\ + "ff_action CHAR(5),"\ + "ff_sec_color_id CHAR(5),"\ + "ff_act_param CHAR(30),"\ + "ff_threshold CHAR(20) ,"\ + "ff_roiX CHAR(6) ,"\ + "ff_roiY CHAR(6) ,"\ + "ff_roiW CHAR(6) ,"\ + "ff_roiH CHAR(6) ,"\ + "ff_lpX CHAR(6) ,"\ + "ff_lpY CHAR(6) ,"\ + "ff_lpW CHAR(6) ,"\ + "ff_lpH CHAR(6) ,"\ + "ff_lpbmp CHAR(100) ,"\ + "ff_lproi CHAR(60) ,"\ + "ff_country CHAR(10),"\ + "in_user NCHAR(512) NOT NULL,"\ + "in_phone CHAR(20),"\ + "in_address NCHAR(200),"\ + "in_paystatus CHAR(5),"\ + "in_exist CHAR(5) ,"\ + "in_schedule_start CHAR(20),"\ + "in_schedule_end CHAR(20),"\ + "in_other NCHAR(512),"\ + "in_detect_endtime CHAR(64));" + //"in_address NCHAR(300)," + // "in_other NCHAR(128));" + +#define CMD_CREATE_LPR_MAPPING_TABLE "CREATE TABLE IF NOT EXISTS %s("\ + "ff_index INTEGER PRIMARY KEY AUTOINCREMENT,"\ + "ff_det_lpr CHAR(20) NOT NULL,"\ + "ff_lpr CHAR(100) NOT NULL);" + +#define CMD_CREATE_LPR_INDEX "CREATE INDEX IF NOT EXISTS logid ON lpr_db_tb (ff_index);" + +#define INSERT_LPR_DATA_CMD "INSERT INTO '%s' VALUES(NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" + +#define INSERT_LPRLIST_DATA_CMD "INSERT INTO %s VALUES(NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" + +#define INSERT_LPR_MAPPING_CMD "INSERT INTO %s VALUES(NULL,'%s','%s');" + + +#define UPDATE_DETECT_LPRLIST_CMD "UPDATE %s SET "\ + "ff_ts='%s',"\ + "ff_mod_ts='%s',"\ + "ff_car_id='%s',"\ + "ff_rtime='%s',"\ + "ff_action='%s',"\ + "ff_sec_color_id='%s',"\ + "ff_act_param='%s',"\ + "ff_threshold='%s',"\ + "ff_roiX='%s',"\ + "ff_roiY='%s',"\ + "ff_roiW='%s',"\ + "ff_roiH='%s',"\ + "ff_lpX='%s',"\ + "ff_lpY='%s',"\ + "ff_lpW='%s',"\ + "ff_lpH='%s',"\ + "ff_lpbmp='%s',"\ + "ff_lproi='%s',"\ + "ff_country='%s' "\ + "WHERE ff_lpr='%s';" + +#define UPDATE_LPRLIST_CMD "UPDATE %s SET "\ + "ff_lpr='%s',"\ + "ff_act_param='%s',"\ + "in_user='%s',"\ + "in_phone='%s',"\ + "in_address='%s',"\ + "in_paystatus='%s',"\ + "in_exist='%s',"\ + "in_schedule_start='%s',"\ + "in_schedule_end='%s',"\ + "in_other='%s',"\ + "in_detect_endtime='%s' "\ + "WHERE ff_lpr='%s';" + +#define UPDATE_LPR_MAPPING_CMD "UPDATE %s SET "\ + "ff_det_lpr='%s',"\ + "ff_lpr='%s'"\ + "WHERE ff_det_lpr='%s';" + +#define UPDATE_LPREXIST_CMD "UPDATE %s SET in_exist='%s';" + +#define DELETE_LPRTAB_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_lpr='%s');" + +#define DELETE_LPRTAB_TIME_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_mod_ts='%s');" + +#define DELETE_LPR_MAPPING_CMD "DELETE FROM %s WHERE ff_index IN (SELECT ff_index FROM %s WHERE ff_det_lpr='%s');" + +#define CMD_QUERY_LPR_VERSION "SELECT * FROM lpr_ver_tb ORDER BY ff_ver_num DESC LIMIT 1;" + +#define LPR_INSERT_VERSION "INSERT INTO lpr_ver_tb VALUES('%d','%s','%s');" + +#define CMD_DROP_LPR_MSG_TABLE "DROP TABLE IF EXISTS lpr_db_tb;" + +#define CMD_LPR_EXIST_TABLE "SELECT ff_lpr='%s' FROM '%s' WHERE ff_lpr='%s';" + +#define CMD_LPR_UNION_TABLE "SELECT 'black' As Type,"\ + "ff_index,"\ + "ff_lpr,"\ + "in_user,"\ + "in_phone,"\ + "in_address,"\ + "in_paystatus,"\ + "in_exist,"\ + "in_schedule_start,"\ + "in_schedule_end,"\ + "in_other,"\ + "in_detect_endtime,"\ + "ff_act_param "\ + "FROM lpr_db_black_tb UNION "\ + "SELECT 'white' ,"\ + "ff_index,"\ + "ff_lpr,"\ + "in_user,"\ + "in_phone,"\ + "in_address,"\ + "in_paystatus,"\ + "in_exist,"\ + "in_schedule_start,"\ + "in_schedule_end,"\ + "in_other,"\ + "in_detect_endtime,"\ + "ff_act_param "\ + "FROM lpr_db_white_tb ORDER BY ff_index ASC LIMIT %d;" + +#define CMD_CLEAN_LPR_MSG_TABLE "DELETE FROM %s;" + +#define CMD_SELECT_LPR "SELECT * FROM %s ORDER BY ff_index DESC;" + +#define SHELLSCRIPT_FIX_DB_FFLPR "sh /emmc/plugin/Aida_data/fix_db_fflpr.sh" + +//#define CMD_CHECK_LPR "SELECT LPR FROM lpr_db_black_tb , lpr_db_white_tb as white;" +//#define CMD_CHECK_LPR "SELECT LPR FROM lpr_db_black_tb , lpr_db_white_tb as vip;" + +extern int unlockingKeyInnoFR_success; + +char *rtrim(char *str); + +int fflpr_log_db_init(void); + +void sqlite_fflpr_db_close(void); +int cgi_get_db_lpr_log_delete_jpg(char* db_tb_name, char* list_name, int sum_count); +int cgi_get_db_lpr_log(SOCKET socket_in, char *db_tb_name, char *list_name, int sum_count); + +void sqlite_ffgroup_insert(ffgroup_db_tb *l_ff_insert_data, char *type_name); +void sqlite_ffgroup_update(ffgroup_db_tb *i_updata_list); +int db_get_lpr_record(sqlite3_stmt *stmt, ffgroup_db_tb *db_tb_info); + +void chk_sql_msg_tbname(char *listname,char *ndata); + +int cgi_get_search_info(SOCKET socket_in, char *path); +int cgi_set_search_info(SOCKET socket_in, char *path); + +int action_lpr_import_infomation(char *iLPR, char *iACT_PARAM , char *iIN_USER ,char *iIN_OTHER, char *iIN_SCHEDULE_START, + char *iIN_SCHEDULE_END,char *iIN_ENDTIME, char *idet_level); +void action_import_lpr_map_info(char *iLPR_DETECT , char *iLPR) ; + +int switch_lpr_detect_strength(int istrength); + +int insert_lpr_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr); +int compute_lpr_Levenshtein(char *ilist_type,char *idetect_lpr,char *idetect_time,char *result_lpr,get_lpr_list_param *l_chk_lpr); +void mapping_detect_lpr(char *ilist_type,char *idetect_lpr,char *mapping_lpr); +void callback_reset_db_list(); +void callback_reset_db_map_list(); +void chk_log_data(char *odata,const char *idata); +void getvalueForKey(char *keyValue, char *key, char *value); +bool check_if_not_in_black_and_white(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance); +bool check_if_in_black(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance, char *replaced_plate); +bool check_if_in_white(char *ff_lpr_to_check, char *in_other_to_check, int levenshtein_distance, char *replaced_plate); + +bool get_schedule_start_in_black(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_start, int levenshtein_distance); +bool get_schedule_start_in_white(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_start, int levenshtein_distance); +bool get_schedule_end_in_black(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance); +bool get_schedule_end_in_white(char *ff_lpr_to_check, char *in_other_to_check, char *l_schedule_end, int levenshtein_distance); + +bool get_detect_endtime_in_black(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance); +bool get_detect_endtime_in_white(char *ff_lpr_to_check, char *in_other_to_check, char *l_detect_endtime, int levenshtein_distance); + +void *delete_jpg(void * ptr); +void delete_jpg_in_seven_days(); +extern pthread_mutex_t mutex_send_jpeg; +void get_fflpr_db_import(); + +#endif +#endif \ No newline at end of file diff --git a/src/fork_pipe_lib.c b/src/fork_pipe_lib.c new file mode 100644 index 0000000..0bd7215 --- /dev/null +++ b/src/fork_pipe_lib.c @@ -0,0 +1,134 @@ + +#include "fork_pipe_lib.h" +#include "utility.h" +#include <sys/wait.h> + +static pid_t *childpid = NULL; +static int maxfd; + +//#ifdef OPEN_MAX +//static long openmax = OPEN_MAX; +//#else +static long openmax = 0; +//#endif + +/* + * If OPEN_MAX is indeterminate, we're not + * guaranteed that this is adequate. + */ +#define OPEN_MAX_GUESS 1024 + +long open_max(void) +{ + if (openmax == 0) { /* first time through */ + errno = 0; + if ((openmax = sysconf(_SC_OPEN_MAX)) < 0) { + if (errno == 0) + openmax = OPEN_MAX_GUESS; /* it's indeterminate */ + else + printf("sysconf error for _SC_OPEN_MAX"); + } + } + + return(openmax); +} + +FILE *vpopen(const char* cmdstring, const char *type) +{ + int pfd[2]; + FILE *fp; + pid_t pid; + + if ((type[0] != 'r' && type[0] != 'w') || type[1] != 0) + { + errno = EINVAL; + return(NULL); + } + + if (childpid == NULL) { /* first time through */ + /* allocate zeroed out array for child pids */ + maxfd = open_max(); + if ((childpid = (pid_t *)calloc(maxfd, sizeof(pid_t))) == NULL) + return(NULL); + } + + if (pipe(pfd) != 0) + { + return NULL; + } + + if ((pid = vfork()) < 0) + { + return(NULL); /* errno set by fork() */ + } + else if (pid == 0) { /* child */ + if (*type == 'r') + { + close(pfd[0]); + if (pfd[1] != STDOUT_FILENO) { + dup2(pfd[1], STDOUT_FILENO); + close(pfd[1]); + } + } + else + { + close(pfd[1]); + if (pfd[0] != STDIN_FILENO) { + dup2(pfd[0], STDIN_FILENO); + close(pfd[0]); + } + } + + /* close all descriptors in childpid[] */ + for (int i = 0; i < maxfd; i++) + if (childpid[i] > 0) + close(i); + + execl("/bin/sh", "sh", "-c", cmdstring, (char *)0); + _exit(127); + } + + if (*type == 'r') { + close(pfd[1]); + if ((fp = fdopen(pfd[0], type)) == NULL) + return(NULL); + } + else { + close(pfd[0]); + if ((fp = fdopen(pfd[1], type)) == NULL) + return(NULL); + } + + childpid[fileno(fp)] = pid; /* remember child pid for this fd */ + return(fp); +} + + +int vpclose(FILE *fp) +{ + int fd, stat; + pid_t pid; + + if (childpid == NULL) + return(-1); /* popen() has never been called */ + + fd = fileno(fp); + if ((pid = childpid[fd]) == 0) + return(-1); /* fp wasn't opened by popen() */ + + childpid[fd] = 0; + if (fclose(fp) == EOF) + return(-1); + /* + while (waitpid(pid, &stat, WNOHANG) < 0) + if (errno != EINTR) + return(-1); // error other than EINTR from waitpid() + */ + + pid = waitpid(-1, &stat, WNOHANG); + while (!pid) { + pid = waitpid(-1, &stat, WNOHANG); + } + + return(stat); /* return child's termination status */ +} \ No newline at end of file diff --git a/src/fork_pipe_lib.h b/src/fork_pipe_lib.h new file mode 100644 index 0000000..5065e39 --- /dev/null +++ b/src/fork_pipe_lib.h @@ -0,0 +1,19 @@ +#pragma once +#ifndef FORK_PIPE_LIB_H +#define FORK_PIPE_LIB_H +#include "define_inc.h" +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> + +//#include <sys/signal.h> + +long open_max(void); +FILE *vpopen(const char* cmdstring, const char *type); +int vpclose(FILE *fp); + + + +#endif \ No newline at end of file diff --git a/src/freetype.h b/src/freetype.h new file mode 100644 index 0000000..4b3f2ab --- /dev/null +++ b/src/freetype.h @@ -0,0 +1,4657 @@ +/***************************************************************************/ +/* */ +/* freetype.h */ +/* */ +/* FreeType high-level API and common types (specification only). */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +#pragma once +#ifndef FREETYPE_H_ +#define FREETYPE_H_ + + +#ifndef FT_FREETYPE_H +#error "`ft2build.h' hasn't been included yet!" +#error "Please always use macros to include FreeType header files." +#error "Example:" +#error " #include <ft2build.h>" +#error " #include FT_FREETYPE_H" +#endif + +#include "define_inc.h" +#include <ft2build.h> +#include FT_CONFIG_CONFIG_H +#include FT_TYPES_H +#include FT_ERRORS_H + + +FT_BEGIN_HEADER + + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* header_inclusion */ + /* */ + /* <Title> */ + /* FreeType's header inclusion scheme */ + /* */ + /* <Abstract> */ + /* How client applications should include FreeType header files. */ + /* */ + /* <Description> */ + /* To be as flexible as possible (and for historical reasons), */ + /* FreeType uses a very special inclusion scheme to load header */ + /* files, for example */ + /* */ + /* { */ + /* #include <ft2build.h> */ + /* */ + /* #include FT_FREETYPE_H */ + /* #include FT_OUTLINE_H */ + /* } */ + /* */ + /* A compiler and its preprocessor only needs an include path to find */ + /* the file `ft2build.h'; the exact locations and names of the other */ + /* FreeType header files are hidden by preprocessor macro names, */ + /* loaded by `ft2build.h'. The API documentation always gives the */ + /* header macro name needed for a particular function. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* user_allocation */ + /* */ + /* <Title> */ + /* User allocation */ + /* */ + /* <Abstract> */ + /* How client applications should allocate FreeType data structures. */ + /* */ + /* <Description> */ + /* FreeType assumes that structures allocated by the user and passed */ + /* as arguments are zeroed out except for the actual data. In other */ + /* words, it is recommended to use `calloc' (or variants of it) */ + /* instead of `malloc' for allocation. */ + /* */ + /*************************************************************************/ + + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* B A S I C T Y P E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* base_interface */ + /* */ + /* <Title> */ + /* Base Interface */ + /* */ + /* <Abstract> */ + /* The FreeType~2 base font interface. */ + /* */ + /* <Description> */ + /* This section describes the most important public high-level API */ + /* functions of FreeType~2. */ + /* */ + /* <Order> */ + /* FT_Library */ + /* FT_Face */ + /* FT_Size */ + /* FT_GlyphSlot */ + /* FT_CharMap */ + /* FT_Encoding */ + /* FT_ENC_TAG */ + /* */ + /* FT_FaceRec */ + /* */ + /* FT_FACE_FLAG_SCALABLE */ + /* FT_FACE_FLAG_FIXED_SIZES */ + /* FT_FACE_FLAG_FIXED_WIDTH */ + /* FT_FACE_FLAG_HORIZONTAL */ + /* FT_FACE_FLAG_VERTICAL */ + /* FT_FACE_FLAG_COLOR */ + /* FT_FACE_FLAG_SFNT */ + /* FT_FACE_FLAG_CID_KEYED */ + /* FT_FACE_FLAG_TRICKY */ + /* FT_FACE_FLAG_KERNING */ + /* FT_FACE_FLAG_MULTIPLE_MASTERS */ + /* FT_FACE_FLAG_VARIATION */ + /* FT_FACE_FLAG_GLYPH_NAMES */ + /* FT_FACE_FLAG_EXTERNAL_STREAM */ + /* FT_FACE_FLAG_HINTER */ + /* */ + /* FT_HAS_HORIZONTAL */ + /* FT_HAS_VERTICAL */ + /* FT_HAS_KERNING */ + /* FT_HAS_FIXED_SIZES */ + /* FT_HAS_GLYPH_NAMES */ + /* FT_HAS_COLOR */ + /* FT_HAS_MULTIPLE_MASTERS */ + /* */ + /* FT_IS_SFNT */ + /* FT_IS_SCALABLE */ + /* FT_IS_FIXED_WIDTH */ + /* FT_IS_CID_KEYED */ + /* FT_IS_TRICKY */ + /* FT_IS_NAMED_INSTANCE */ + /* FT_IS_VARIATION */ + /* */ + /* FT_STYLE_FLAG_BOLD */ + /* FT_STYLE_FLAG_ITALIC */ + /* */ + /* FT_SizeRec */ + /* FT_Size_Metrics */ + /* */ + /* FT_GlyphSlotRec */ + /* FT_Glyph_Metrics */ + /* FT_SubGlyph */ + /* */ + /* FT_Bitmap_Size */ + /* */ + /* FT_Init_FreeType */ + /* FT_Done_FreeType */ + /* */ + /* FT_New_Face */ + /* FT_Done_Face */ + /* FT_Reference_Face */ + /* FT_New_Memory_Face */ + /* FT_Face_Properties */ + /* FT_Open_Face */ + /* FT_Open_Args */ + /* FT_Parameter */ + /* FT_Attach_File */ + /* FT_Attach_Stream */ + /* */ + /* FT_Set_Char_Size */ + /* FT_Set_Pixel_Sizes */ + /* FT_Request_Size */ + /* FT_Select_Size */ + /* FT_Size_Request_Type */ + /* FT_Size_RequestRec */ + /* FT_Size_Request */ + /* FT_Set_Transform */ + /* FT_Load_Glyph */ + /* FT_Get_Char_Index */ + /* FT_Get_First_Char */ + /* FT_Get_Next_Char */ + /* FT_Get_Name_Index */ + /* FT_Load_Char */ + /* */ + /* FT_OPEN_MEMORY */ + /* FT_OPEN_STREAM */ + /* FT_OPEN_PATHNAME */ + /* FT_OPEN_DRIVER */ + /* FT_OPEN_PARAMS */ + /* */ + /* FT_LOAD_DEFAULT */ + /* FT_LOAD_RENDER */ + /* FT_LOAD_MONOCHROME */ + /* FT_LOAD_LINEAR_DESIGN */ + /* FT_LOAD_NO_SCALE */ + /* FT_LOAD_NO_HINTING */ + /* FT_LOAD_NO_BITMAP */ + /* FT_LOAD_NO_AUTOHINT */ + /* FT_LOAD_COLOR */ + /* */ + /* FT_LOAD_VERTICAL_LAYOUT */ + /* FT_LOAD_IGNORE_TRANSFORM */ + /* FT_LOAD_FORCE_AUTOHINT */ + /* FT_LOAD_NO_RECURSE */ + /* FT_LOAD_PEDANTIC */ + /* */ + /* FT_LOAD_TARGET_NORMAL */ + /* FT_LOAD_TARGET_LIGHT */ + /* FT_LOAD_TARGET_MONO */ + /* FT_LOAD_TARGET_LCD */ + /* FT_LOAD_TARGET_LCD_V */ + /* */ + /* FT_LOAD_TARGET_MODE */ + /* */ + /* FT_Render_Glyph */ + /* FT_Render_Mode */ + /* FT_Get_Kerning */ + /* FT_Kerning_Mode */ + /* FT_Get_Track_Kerning */ + /* FT_Get_Glyph_Name */ + /* FT_Get_Postscript_Name */ + /* */ + /* FT_CharMapRec */ + /* FT_Select_Charmap */ + /* FT_Set_Charmap */ + /* FT_Get_Charmap_Index */ + /* */ + /* FT_Get_FSType_Flags */ + /* FT_Get_SubGlyph_Info */ + /* */ + /* FT_Face_Internal */ + /* FT_Size_Internal */ + /* FT_Slot_Internal */ + /* */ + /* FT_FACE_FLAG_XXX */ + /* FT_STYLE_FLAG_XXX */ + /* FT_OPEN_XXX */ + /* FT_LOAD_XXX */ + /* FT_LOAD_TARGET_XXX */ + /* FT_SUBGLYPH_FLAG_XXX */ + /* FT_FSTYPE_XXX */ + /* */ + /* FT_HAS_FAST_GLYPHS */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Glyph_Metrics */ + /* */ + /* <Description> */ + /* A structure to model the metrics of a single glyph. The values */ + /* are expressed in 26.6 fractional pixel format; if the flag */ + /* @FT_LOAD_NO_SCALE has been used while loading the glyph, values */ + /* are expressed in font units instead. */ + /* */ + /* <Fields> */ + /* width :: */ + /* The glyph's width. */ + /* */ + /* height :: */ + /* The glyph's height. */ + /* */ + /* horiBearingX :: */ + /* Left side bearing for horizontal layout. */ + /* */ + /* horiBearingY :: */ + /* Top side bearing for horizontal layout. */ + /* */ + /* horiAdvance :: */ + /* Advance width for horizontal layout. */ + /* */ + /* vertBearingX :: */ + /* Left side bearing for vertical layout. */ + /* */ + /* vertBearingY :: */ + /* Top side bearing for vertical layout. Larger positive values */ + /* mean further below the vertical glyph origin. */ + /* */ + /* vertAdvance :: */ + /* Advance height for vertical layout. Positive values mean the */ + /* glyph has a positive advance downward. */ + /* */ + /* <Note> */ + /* If not disabled with @FT_LOAD_NO_HINTING, the values represent */ + /* dimensions of the hinted glyph (in case hinting is applicable). */ + /* */ + /* Stroking a glyph with an outside border does not increase */ + /* `horiAdvance' or `vertAdvance'; you have to manually adjust these */ + /* values to account for the added width and height. */ + /* */ + /* FreeType doesn't use the `VORG' table data for CFF fonts because */ + /* it doesn't have an interface to quickly retrieve the glyph height. */ + /* The y~coordinate of the vertical origin can be simply computed as */ + /* `vertBearingY + height' after loading a glyph. */ + /* */ + typedef struct FT_Glyph_Metrics_ + { + FT_Pos width; + FT_Pos height; + + FT_Pos horiBearingX; + FT_Pos horiBearingY; + FT_Pos horiAdvance; + + FT_Pos vertBearingX; + FT_Pos vertBearingY; + FT_Pos vertAdvance; + + } FT_Glyph_Metrics; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Bitmap_Size */ + /* */ + /* <Description> */ + /* This structure models the metrics of a bitmap strike (i.e., a set */ + /* of glyphs for a given point size and resolution) in a bitmap font. */ + /* It is used for the `available_sizes' field of @FT_Face. */ + /* */ + /* <Fields> */ + /* height :: The vertical distance, in pixels, between two */ + /* consecutive baselines. It is always positive. */ + /* */ + /* width :: The average width, in pixels, of all glyphs in the */ + /* strike. */ + /* */ + /* size :: The nominal size of the strike in 26.6 fractional */ + /* points. This field is not very useful. */ + /* */ + /* x_ppem :: The horizontal ppem (nominal width) in 26.6 fractional */ + /* pixels. */ + /* */ + /* y_ppem :: The vertical ppem (nominal height) in 26.6 fractional */ + /* pixels. */ + /* */ + /* <Note> */ + /* Windows FNT: */ + /* The nominal size given in a FNT font is not reliable. If the */ + /* driver finds it incorrect, it sets `size' to some calculated */ + /* values, and `x_ppem' and `y_ppem' to the pixel width and height */ + /* given in the font, respectively. */ + /* */ + /* TrueType embedded bitmaps: */ + /* `size', `width', and `height' values are not contained in the */ + /* bitmap strike itself. They are computed from the global font */ + /* parameters. */ + /* */ + typedef struct FT_Bitmap_Size_ + { + FT_Short height; + FT_Short width; + + FT_Pos size; + + FT_Pos x_ppem; + FT_Pos y_ppem; + + } FT_Bitmap_Size; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* O B J E C T C L A S S E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Library */ + /* */ + /* <Description> */ + /* A handle to a FreeType library instance. Each `library' is */ + /* completely independent from the others; it is the `root' of a set */ + /* of objects like fonts, faces, sizes, etc. */ + /* */ + /* It also embeds a memory manager (see @FT_Memory), as well as a */ + /* scan-line converter object (see @FT_Raster). */ + /* */ + /* In multi-threaded applications it is easiest to use one */ + /* `FT_Library' object per thread. In case this is too cumbersome, */ + /* a single `FT_Library' object across threads is possible also */ + /* (since FreeType version 2.5.6), as long as a mutex lock is used */ + /* around @FT_New_Face and @FT_Done_Face. */ + /* */ + /* <Note> */ + /* Library objects are normally created by @FT_Init_FreeType, and */ + /* destroyed with @FT_Done_FreeType. If you need reference-counting */ + /* (cf. @FT_Reference_Library), use @FT_New_Library and */ + /* @FT_Done_Library. */ + /* */ + typedef struct FT_LibraryRec_ *FT_Library; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* module_management */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Module */ + /* */ + /* <Description> */ + /* A handle to a given FreeType module object. A module can be a */ + /* font driver, a renderer, or anything else that provides services */ + /* to the former. */ + /* */ + typedef struct FT_ModuleRec_* FT_Module; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Driver */ + /* */ + /* <Description> */ + /* A handle to a given FreeType font driver object. A font driver */ + /* is a module capable of creating faces from font files. */ + /* */ + typedef struct FT_DriverRec_* FT_Driver; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Renderer */ + /* */ + /* <Description> */ + /* A handle to a given FreeType renderer. A renderer is a module in */ + /* charge of converting a glyph's outline image to a bitmap. It */ + /* supports a single glyph image format, and one or more target */ + /* surface depths. */ + /* */ + typedef struct FT_RendererRec_* FT_Renderer; + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* base_interface */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Face */ + /* */ + /* <Description> */ + /* A handle to a typographic face object. A face object models a */ + /* given typeface, in a given style. */ + /* */ + /* <Note> */ + /* A face object also owns a single @FT_GlyphSlot object, as well */ + /* as one or more @FT_Size objects. */ + /* */ + /* Use @FT_New_Face or @FT_Open_Face to create a new face object from */ + /* a given filepath or a custom input stream. */ + /* */ + /* Use @FT_Done_Face to destroy it (along with its slot and sizes). */ + /* */ + /* An `FT_Face' object can only be safely used from one thread at a */ + /* time. Similarly, creation and destruction of `FT_Face' with the */ + /* same @FT_Library object can only be done from one thread at a */ + /* time. On the other hand, functions like @FT_Load_Glyph and its */ + /* siblings are thread-safe and do not need the lock to be held as */ + /* long as the same `FT_Face' object is not used from multiple */ + /* threads at the same time. */ + /* */ + /* <Also> */ + /* See @FT_FaceRec for the publicly accessible fields of a given face */ + /* object. */ + /* */ + typedef struct FT_FaceRec_* FT_Face; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Size */ + /* */ + /* <Description> */ + /* A handle to an object that models a face scaled to a given */ + /* character size. */ + /* */ + /* <Note> */ + /* An @FT_Face has one _active_ @FT_Size object that is used by */ + /* functions like @FT_Load_Glyph to determine the scaling */ + /* transformation that in turn is used to load and hint glyphs and */ + /* metrics. */ + /* */ + /* You can use @FT_Set_Char_Size, @FT_Set_Pixel_Sizes, */ + /* @FT_Request_Size or even @FT_Select_Size to change the content */ + /* (i.e., the scaling values) of the active @FT_Size. */ + /* */ + /* You can use @FT_New_Size to create additional size objects for a */ + /* given @FT_Face, but they won't be used by other functions until */ + /* you activate it through @FT_Activate_Size. Only one size can be */ + /* activated at any given time per face. */ + /* */ + /* <Also> */ + /* See @FT_SizeRec for the publicly accessible fields of a given size */ + /* object. */ + /* */ + typedef struct FT_SizeRec_* FT_Size; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_GlyphSlot */ + /* */ + /* <Description> */ + /* A handle to a given `glyph slot'. A slot is a container that can */ + /* hold any of the glyphs contained in its parent face. */ + /* */ + /* In other words, each time you call @FT_Load_Glyph or */ + /* @FT_Load_Char, the slot's content is erased by the new glyph data, */ + /* i.e., the glyph's metrics, its image (bitmap or outline), and */ + /* other control information. */ + /* */ + /* <Also> */ + /* See @FT_GlyphSlotRec for the publicly accessible glyph fields. */ + /* */ + typedef struct FT_GlyphSlotRec_* FT_GlyphSlot; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_CharMap */ + /* */ + /* <Description> */ + /* A handle to a character map (usually abbreviated to `charmap'). A */ + /* charmap is used to translate character codes in a given encoding */ + /* into glyph indexes for its parent's face. Some font formats may */ + /* provide several charmaps per font. */ + /* */ + /* Each face object owns zero or more charmaps, but only one of them */ + /* can be `active', providing the data used by @FT_Get_Char_Index or */ + /* @FT_Load_Char. */ + /* */ + /* The list of available charmaps in a face is available through the */ + /* `face->num_charmaps' and `face->charmaps' fields of @FT_FaceRec. */ + /* */ + /* The currently active charmap is available as `face->charmap'. */ + /* You should call @FT_Set_Charmap to change it. */ + /* */ + /* <Note> */ + /* When a new face is created (either through @FT_New_Face or */ + /* @FT_Open_Face), the library looks for a Unicode charmap within */ + /* the list and automatically activates it. If there is no Unicode */ + /* charmap, FreeType doesn't set an `active' charmap. */ + /* */ + /* <Also> */ + /* See @FT_CharMapRec for the publicly accessible fields of a given */ + /* character map. */ + /* */ + typedef struct FT_CharMapRec_* FT_CharMap; + + + /*************************************************************************/ + /* */ + /* <Macro> */ + /* FT_ENC_TAG */ + /* */ + /* <Description> */ + /* This macro converts four-letter tags into an unsigned long. It is */ + /* used to define `encoding' identifiers (see @FT_Encoding). */ + /* */ + /* <Note> */ + /* Since many 16-bit compilers don't like 32-bit enumerations, you */ + /* should redefine this macro in case of problems to something like */ + /* this: */ + /* */ + /* { */ + /* #define FT_ENC_TAG( value, a, b, c, d ) value */ + /* } */ + /* */ + /* to get a simple enumeration without assigning special numbers. */ + /* */ + +#ifndef FT_ENC_TAG +#define FT_ENC_TAG( value, a, b, c, d ) \ + value = ( ( (FT_UInt32)(a) << 24 ) | \ + ( (FT_UInt32)(b) << 16 ) | \ + ( (FT_UInt32)(c) << 8 ) | \ + (FT_UInt32)(d) ) + +#endif /* FT_ENC_TAG */ + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Encoding */ + /* */ + /* <Description> */ + /* An enumeration to specify character sets supported by charmaps. */ + /* Used in the @FT_Select_Charmap API function. */ + /* */ + /* <Note> */ + /* Despite the name, this enumeration lists specific character */ + /* repertories (i.e., charsets), and not text encoding methods (e.g., */ + /* UTF-8, UTF-16, etc.). */ + /* */ + /* Other encodings might be defined in the future. */ + /* */ + /* <Values> */ + /* FT_ENCODING_NONE :: */ + /* The encoding value~0 is reserved. */ + /* */ + /* FT_ENCODING_UNICODE :: */ + /* The Unicode character set. This value covers all versions of */ + /* the Unicode repertoire, including ASCII and Latin-1. Most fonts */ + /* include a Unicode charmap, but not all of them. */ + /* */ + /* For example, if you want to access Unicode value U+1F028 (and */ + /* the font contains it), use value 0x1F028 as the input value for */ + /* @FT_Get_Char_Index. */ + /* */ + /* FT_ENCODING_MS_SYMBOL :: */ + /* Microsoft Symbol encoding, used to encode mathematical symbols */ + /* and wingdings. For more information, see */ + /* `https://www.microsoft.com/typography/otspec/recom.htm', */ + /* `http://www.kostis.net/charsets/symbol.htm', and */ + /* `http://www.kostis.net/charsets/wingding.htm'. */ + /* */ + /* This encoding uses character codes from the PUA (Private Unicode */ + /* Area) in the range U+F020-U+F0FF. */ + /* */ + /* FT_ENCODING_SJIS :: */ + /* Shift JIS encoding for Japanese. More info at */ + /* `https://en.wikipedia.org/wiki/Shift_JIS'. See note on */ + /* multi-byte encodings below. */ + /* */ + /* FT_ENCODING_PRC :: */ + /* Corresponds to encoding systems mainly for Simplified Chinese as */ + /* used in People's Republic of China (PRC). The encoding layout */ + /* is based on GB~2312 and its supersets GBK and GB~18030. */ + /* */ + /* FT_ENCODING_BIG5 :: */ + /* Corresponds to an encoding system for Traditional Chinese as */ + /* used in Taiwan and Hong Kong. */ + /* */ + /* FT_ENCODING_WANSUNG :: */ + /* Corresponds to the Korean encoding system known as Extended */ + /* Wansung (MS Windows code page 949). */ + /* For more information see */ + /* `https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit949.txt'. */ + /* */ + /* FT_ENCODING_JOHAB :: */ + /* The Korean standard character set (KS~C 5601-1992), which */ + /* corresponds to MS Windows code page 1361. This character set */ + /* includes all possible Hangul character combinations. */ + /* */ + /* FT_ENCODING_ADOBE_LATIN_1 :: */ + /* Corresponds to a Latin-1 encoding as defined in a Type~1 */ + /* PostScript font. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_STANDARD :: */ + /* Adobe Standard encoding, as found in Type~1, CFF, and */ + /* OpenType/CFF fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_EXPERT :: */ + /* Adobe Expert encoding, as found in Type~1, CFF, and OpenType/CFF */ + /* fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_ADOBE_CUSTOM :: */ + /* Corresponds to a custom encoding, as found in Type~1, CFF, and */ + /* OpenType/CFF fonts. It is limited to 256 character codes. */ + /* */ + /* FT_ENCODING_APPLE_ROMAN :: */ + /* Apple roman encoding. Many TrueType and OpenType fonts contain */ + /* a charmap for this 8-bit encoding, since older versions of Mac */ + /* OS are able to use it. */ + /* */ + /* FT_ENCODING_OLD_LATIN_2 :: */ + /* This value is deprecated and was neither used nor reported by */ + /* FreeType. Don't use or test for it. */ + /* */ + /* FT_ENCODING_MS_SJIS :: */ + /* Same as FT_ENCODING_SJIS. Deprecated. */ + /* */ + /* FT_ENCODING_MS_GB2312 :: */ + /* Same as FT_ENCODING_PRC. Deprecated. */ + /* */ + /* FT_ENCODING_MS_BIG5 :: */ + /* Same as FT_ENCODING_BIG5. Deprecated. */ + /* */ + /* FT_ENCODING_MS_WANSUNG :: */ + /* Same as FT_ENCODING_WANSUNG. Deprecated. */ + /* */ + /* FT_ENCODING_MS_JOHAB :: */ + /* Same as FT_ENCODING_JOHAB. Deprecated. */ + /* */ + /* <Note> */ + /* By default, FreeType enables a Unicode charmap and tags it with */ + /* FT_ENCODING_UNICODE when it is either provided or can be generated */ + /* from PostScript glyph name dictionaries in the font file. */ + /* All other encodings are considered legacy and tagged only if */ + /* explicitly defined in the font file. Otherwise, FT_ENCODING_NONE */ + /* is used. */ + /* */ + /* FT_ENCODING_NONE is set by the BDF and PCF drivers if the charmap */ + /* is neither Unicode nor ISO-8859-1 (otherwise it is set to */ + /* FT_ENCODING_UNICODE). Use @FT_Get_BDF_Charset_ID to find out */ + /* which encoding is really present. If, for example, the */ + /* `cs_registry' field is `KOI8' and the `cs_encoding' field is `R', */ + /* the font is encoded in KOI8-R. */ + /* */ + /* FT_ENCODING_NONE is always set (with a single exception) by the */ + /* winfonts driver. Use @FT_Get_WinFNT_Header and examine the */ + /* `charset' field of the @FT_WinFNT_HeaderRec structure to find out */ + /* which encoding is really present. For example, */ + /* @FT_WinFNT_ID_CP1251 (204) means Windows code page 1251 (for */ + /* Russian). */ + /* */ + /* FT_ENCODING_NONE is set if `platform_id' is @TT_PLATFORM_MACINTOSH */ + /* and `encoding_id' is not `TT_MAC_ID_ROMAN' (otherwise it is set to */ + /* FT_ENCODING_APPLE_ROMAN). */ + /* */ + /* If `platform_id' is @TT_PLATFORM_MACINTOSH, use the function */ + /* @FT_Get_CMap_Language_ID to query the Mac language ID that may */ + /* be needed to be able to distinguish Apple encoding variants. See */ + /* */ + /* https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt */ + /* */ + /* to get an idea how to do that. Basically, if the language ID */ + /* is~0, don't use it, otherwise subtract 1 from the language ID. */ + /* Then examine `encoding_id'. If, for example, `encoding_id' is */ + /* `TT_MAC_ID_ROMAN' and the language ID (minus~1) is */ + /* `TT_MAC_LANGID_GREEK', it is the Greek encoding, not Roman. */ + /* `TT_MAC_ID_ARABIC' with `TT_MAC_LANGID_FARSI' means the Farsi */ + /* variant the Arabic encoding. */ + /* */ + typedef enum FT_Encoding_ + { + FT_ENC_TAG( FT_ENCODING_NONE, 0, 0, 0, 0 ), + + FT_ENC_TAG( FT_ENCODING_MS_SYMBOL, 's', 'y', 'm', 'b' ), + FT_ENC_TAG( FT_ENCODING_UNICODE, 'u', 'n', 'i', 'c' ), + + FT_ENC_TAG( FT_ENCODING_SJIS, 's', 'j', 'i', 's' ), + FT_ENC_TAG( FT_ENCODING_PRC, 'g', 'b', ' ', ' ' ), + FT_ENC_TAG( FT_ENCODING_BIG5, 'b', 'i', 'g', '5' ), + FT_ENC_TAG( FT_ENCODING_WANSUNG, 'w', 'a', 'n', 's' ), + FT_ENC_TAG( FT_ENCODING_JOHAB, 'j', 'o', 'h', 'a' ), + + /* for backward compatibility */ + FT_ENCODING_GB2312 = FT_ENCODING_PRC, + FT_ENCODING_MS_SJIS = FT_ENCODING_SJIS, + FT_ENCODING_MS_GB2312 = FT_ENCODING_PRC, + FT_ENCODING_MS_BIG5 = FT_ENCODING_BIG5, + FT_ENCODING_MS_WANSUNG = FT_ENCODING_WANSUNG, + FT_ENCODING_MS_JOHAB = FT_ENCODING_JOHAB, + + FT_ENC_TAG( FT_ENCODING_ADOBE_STANDARD, 'A', 'D', 'O', 'B' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_EXPERT, 'A', 'D', 'B', 'E' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_CUSTOM, 'A', 'D', 'B', 'C' ), + FT_ENC_TAG( FT_ENCODING_ADOBE_LATIN_1, 'l', 'a', 't', '1' ), + + FT_ENC_TAG( FT_ENCODING_OLD_LATIN_2, 'l', 'a', 't', '2' ), + + FT_ENC_TAG( FT_ENCODING_APPLE_ROMAN, 'a', 'r', 'm', 'n' ) + + } FT_Encoding; + + + /* these constants are deprecated; use the corresponding `FT_Encoding' */ + /* values instead */ +#define ft_encoding_none FT_ENCODING_NONE +#define ft_encoding_unicode FT_ENCODING_UNICODE +#define ft_encoding_symbol FT_ENCODING_MS_SYMBOL +#define ft_encoding_latin_1 FT_ENCODING_ADOBE_LATIN_1 +#define ft_encoding_latin_2 FT_ENCODING_OLD_LATIN_2 +#define ft_encoding_sjis FT_ENCODING_SJIS +#define ft_encoding_gb2312 FT_ENCODING_PRC +#define ft_encoding_big5 FT_ENCODING_BIG5 +#define ft_encoding_wansung FT_ENCODING_WANSUNG +#define ft_encoding_johab FT_ENCODING_JOHAB + +#define ft_encoding_adobe_standard FT_ENCODING_ADOBE_STANDARD +#define ft_encoding_adobe_expert FT_ENCODING_ADOBE_EXPERT +#define ft_encoding_adobe_custom FT_ENCODING_ADOBE_CUSTOM +#define ft_encoding_apple_roman FT_ENCODING_APPLE_ROMAN + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_CharMapRec */ + /* */ + /* <Description> */ + /* The base charmap structure. */ + /* */ + /* <Fields> */ + /* face :: A handle to the parent face object. */ + /* */ + /* encoding :: An @FT_Encoding tag identifying the charmap. Use */ + /* this with @FT_Select_Charmap. */ + /* */ + /* platform_id :: An ID number describing the platform for the */ + /* following encoding ID. This comes directly from */ + /* the TrueType specification and gets emulated for */ + /* other formats. */ + /* */ + /* encoding_id :: A platform specific encoding number. This also */ + /* comes from the TrueType specification and gets */ + /* emulated similarly. */ + /* */ + typedef struct FT_CharMapRec_ + { + FT_Face face; + FT_Encoding encoding; + FT_UShort platform_id; + FT_UShort encoding_id; + + } FT_CharMapRec; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* B A S E O B J E C T C L A S S E S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Face_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Face_InternalRec' structure that models */ + /* the private data of a given @FT_Face object. */ + /* */ + /* This structure might change between releases of FreeType~2 and is */ + /* not generally available to client applications. */ + /* */ + typedef struct FT_Face_InternalRec_* FT_Face_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_FaceRec */ + /* */ + /* <Description> */ + /* FreeType root face class structure. A face object models a */ + /* typeface in a font file. */ + /* */ + /* <Fields> */ + /* num_faces :: The number of faces in the font file. Some */ + /* font formats can have multiple faces in */ + /* a single font file. */ + /* */ + /* face_index :: This field holds two different values. */ + /* Bits 0-15 are the index of the face in the */ + /* font file (starting with value~0). They */ + /* are set to~0 if there is only one face in */ + /* the font file. */ + /* */ + /* [Since 2.6.1] Bits 16-30 are relevant to GX */ + /* and OpenType variation fonts only, holding */ + /* the named instance index for the current */ + /* face index (starting with value~1; value~0 */ + /* indicates font access without a named */ + /* instance). For non-variation fonts, bits */ + /* 16-30 are ignored. If we have the third */ + /* named instance of face~4, say, `face_index' */ + /* is set to 0x00030004. */ + /* */ + /* Bit 31 is always zero (this is, */ + /* `face_index' is always a positive value). */ + /* */ + /* [Since 2.9] Changing the design coordinates */ + /* with @FT_Set_Var_Design_Coordinates or */ + /* @FT_Set_Var_Blend_Coordinates does not */ + /* influence the named instance index value */ + /* (only @FT_Set_Named_Instance does that). */ + /* */ + /* face_flags :: A set of bit flags that give important */ + /* information about the face; see */ + /* @FT_FACE_FLAG_XXX for the details. */ + /* */ + /* style_flags :: The lower 16~bits contain a set of bit */ + /* flags indicating the style of the face; see */ + /* @FT_STYLE_FLAG_XXX for the details. */ + /* */ + /* [Since 2.6.1] Bits 16-30 hold the number */ + /* of named instances available for the */ + /* current face if we have a GX or OpenType */ + /* variation (sub)font. Bit 31 is always zero */ + /* (this is, `style_flags' is always a */ + /* positive value). Note that a variation */ + /* font has always at least one named */ + /* instance, namely the default instance. */ + /* */ + /* num_glyphs :: The number of glyphs in the face. If the */ + /* face is scalable and has sbits (see */ + /* `num_fixed_sizes'), it is set to the number */ + /* of outline glyphs. */ + /* */ + /* For CID-keyed fonts (not in an SFNT */ + /* wrapper) this value gives the highest CID */ + /* used in the font. */ + /* */ + /* family_name :: The face's family name. This is an ASCII */ + /* string, usually in English, that describes */ + /* the typeface's family (like `Times New */ + /* Roman', `Bodoni', `Garamond', etc). This */ + /* is a least common denominator used to list */ + /* fonts. Some formats (TrueType & OpenType) */ + /* provide localized and Unicode versions of */ + /* this string. Applications should use the */ + /* format specific interface to access them. */ + /* Can be NULL (e.g., in fonts embedded in a */ + /* PDF file). */ + /* */ + /* In case the font doesn't provide a specific */ + /* family name entry, FreeType tries to */ + /* synthesize one, deriving it from other name */ + /* entries. */ + /* */ + /* style_name :: The face's style name. This is an ASCII */ + /* string, usually in English, that describes */ + /* the typeface's style (like `Italic', */ + /* `Bold', `Condensed', etc). Not all font */ + /* formats provide a style name, so this field */ + /* is optional, and can be set to NULL. As */ + /* for `family_name', some formats provide */ + /* localized and Unicode versions of this */ + /* string. Applications should use the format */ + /* specific interface to access them. */ + /* */ + /* num_fixed_sizes :: The number of bitmap strikes in the face. */ + /* Even if the face is scalable, there might */ + /* still be bitmap strikes, which are called */ + /* `sbits' in that case. */ + /* */ + /* available_sizes :: An array of @FT_Bitmap_Size for all bitmap */ + /* strikes in the face. It is set to NULL if */ + /* there is no bitmap strike. */ + /* */ + /* Note that FreeType tries to sanitize the */ + /* strike data since they are sometimes sloppy */ + /* or incorrect, but this can easily fail. */ + /* */ + /* num_charmaps :: The number of charmaps in the face. */ + /* */ + /* charmaps :: An array of the charmaps of the face. */ + /* */ + /* generic :: A field reserved for client uses. See the */ + /* @FT_Generic type description. */ + /* */ + /* bbox :: The font bounding box. Coordinates are */ + /* expressed in font units (see */ + /* `units_per_EM'). The box is large enough */ + /* to contain any glyph from the font. Thus, */ + /* `bbox.yMax' can be seen as the `maximum */ + /* ascender', and `bbox.yMin' as the `minimum */ + /* descender'. Only relevant for scalable */ + /* formats. */ + /* */ + /* Note that the bounding box might be off by */ + /* (at least) one pixel for hinted fonts. See */ + /* @FT_Size_Metrics for further discussion. */ + /* */ + /* units_per_EM :: The number of font units per EM square for */ + /* this face. This is typically 2048 for */ + /* TrueType fonts, and 1000 for Type~1 fonts. */ + /* Only relevant for scalable formats. */ + /* */ + /* ascender :: The typographic ascender of the face, */ + /* expressed in font units. For font formats */ + /* not having this information, it is set to */ + /* `bbox.yMax'. Only relevant for scalable */ + /* formats. */ + /* */ + /* descender :: The typographic descender of the face, */ + /* expressed in font units. For font formats */ + /* not having this information, it is set to */ + /* `bbox.yMin'. Note that this field is */ + /* negative for values below the baseline. */ + /* Only relevant for scalable formats. */ + /* */ + /* height :: This value is the vertical distance */ + /* between two consecutive baselines, */ + /* expressed in font units. It is always */ + /* positive. Only relevant for scalable */ + /* formats. */ + /* */ + /* If you want the global glyph height, use */ + /* `ascender - descender'. */ + /* */ + /* max_advance_width :: The maximum advance width, in font units, */ + /* for all glyphs in this face. This can be */ + /* used to make word wrapping computations */ + /* faster. Only relevant for scalable */ + /* formats. */ + /* */ + /* max_advance_height :: The maximum advance height, in font units, */ + /* for all glyphs in this face. This is only */ + /* relevant for vertical layouts, and is set */ + /* to `height' for fonts that do not provide */ + /* vertical metrics. Only relevant for */ + /* scalable formats. */ + /* */ + /* underline_position :: The position, in font units, of the */ + /* underline line for this face. It is the */ + /* center of the underlining stem. Only */ + /* relevant for scalable formats. */ + /* */ + /* underline_thickness :: The thickness, in font units, of the */ + /* underline for this face. Only relevant for */ + /* scalable formats. */ + /* */ + /* glyph :: The face's associated glyph slot(s). */ + /* */ + /* size :: The current active size for this face. */ + /* */ + /* charmap :: The current active charmap for this face. */ + /* */ + /* <Note> */ + /* Fields may be changed after a call to @FT_Attach_File or */ + /* @FT_Attach_Stream. */ + /* */ + /* For an OpenType variation font, the values of the following fields */ + /* can change after a call to @FT_Set_Var_Design_Coordinates (and */ + /* friends) if the font contains an `MVAR' table: `ascender', */ + /* `descender', `height', `underline_position', and */ + /* `underline_thickness'. */ + /* */ + /* Especially for TrueType fonts see also the documentation for */ + /* @FT_Size_Metrics. */ + /* */ + typedef struct FT_FaceRec_ + { + FT_Long num_faces; + FT_Long face_index; + + FT_Long face_flags; + FT_Long style_flags; + + FT_Long num_glyphs; + + FT_String* family_name; + FT_String* style_name; + + FT_Int num_fixed_sizes; + FT_Bitmap_Size* available_sizes; + + FT_Int num_charmaps; + FT_CharMap* charmaps; + + FT_Generic generic; + + /*# The following member variables (down to `underline_thickness') */ + /*# are only relevant to scalable outlines; cf. @FT_Bitmap_Size */ + /*# for bitmap fonts. */ + FT_BBox bbox; + + FT_UShort units_per_EM; + FT_Short ascender; + FT_Short descender; + FT_Short height; + + FT_Short max_advance_width; + FT_Short max_advance_height; + + FT_Short underline_position; + FT_Short underline_thickness; + + FT_GlyphSlot glyph; + FT_Size size; + FT_CharMap charmap; + + /*@private begin */ + + FT_Driver driver; + FT_Memory memory; + FT_Stream stream; + + FT_ListRec sizes_list; + + FT_Generic autohint; /* face-specific auto-hinter data */ + void* extensions; /* unused */ + + FT_Face_Internal internal; + + /*@private end */ + + } FT_FaceRec; + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_FACE_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the `face_flags' field of the */ + /* @FT_FaceRec structure. They inform client applications of */ + /* properties of the corresponding face. */ + /* */ + /* <Values> */ + /* FT_FACE_FLAG_SCALABLE :: */ + /* The face contains outline glyphs. Note that a face can contain */ + /* bitmap strikes also, i.e., a face can have both this flag and */ + /* @FT_FACE_FLAG_FIXED_SIZES set. */ + /* */ + /* FT_FACE_FLAG_FIXED_SIZES :: */ + /* The face contains bitmap strikes. See also the */ + /* `num_fixed_sizes' and `available_sizes' fields of @FT_FaceRec. */ + /* */ + /* FT_FACE_FLAG_FIXED_WIDTH :: */ + /* The face contains fixed-width characters (like Courier, Lucida, */ + /* MonoType, etc.). */ + /* */ + /* FT_FACE_FLAG_SFNT :: */ + /* The face uses the SFNT storage scheme. For now, this means */ + /* TrueType and OpenType. */ + /* */ + /* FT_FACE_FLAG_HORIZONTAL :: */ + /* The face contains horizontal glyph metrics. This should be set */ + /* for all common formats. */ + /* */ + /* FT_FACE_FLAG_VERTICAL :: */ + /* The face contains vertical glyph metrics. This is only */ + /* available in some formats, not all of them. */ + /* */ + /* FT_FACE_FLAG_KERNING :: */ + /* The face contains kerning information. If set, the kerning */ + /* distance can be retrieved using the function @FT_Get_Kerning. */ + /* Otherwise the function always return the vector (0,0). Note */ + /* that FreeType doesn't handle kerning data from the SFNT `GPOS' */ + /* table (as present in many OpenType fonts). */ + /* */ + /* FT_FACE_FLAG_FAST_GLYPHS :: */ + /* THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT. */ + /* */ + /* FT_FACE_FLAG_MULTIPLE_MASTERS :: */ + /* The face contains multiple masters and is capable of */ + /* interpolating between them. Supported formats are Adobe MM, */ + /* TrueType GX, and OpenType variation fonts. */ + /* */ + /* See section @multiple_masters for API details. */ + /* */ + /* FT_FACE_FLAG_GLYPH_NAMES :: */ + /* The face contains glyph names, which can be retrieved using */ + /* @FT_Get_Glyph_Name. Note that some TrueType fonts contain */ + /* broken glyph name tables. Use the function */ + /* @FT_Has_PS_Glyph_Names when needed. */ + /* */ + /* FT_FACE_FLAG_EXTERNAL_STREAM :: */ + /* Used internally by FreeType to indicate that a face's stream was */ + /* provided by the client application and should not be destroyed */ + /* when @FT_Done_Face is called. Don't read or test this flag. */ + /* */ + /* FT_FACE_FLAG_HINTER :: */ + /* The font driver has a hinting machine of its own. For example, */ + /* with TrueType fonts, it makes sense to use data from the SFNT */ + /* `gasp' table only if the native TrueType hinting engine (with */ + /* the bytecode interpreter) is available and active. */ + /* */ + /* FT_FACE_FLAG_CID_KEYED :: */ + /* The face is CID-keyed. In that case, the face is not accessed */ + /* by glyph indices but by CID values. For subsetted CID-keyed */ + /* fonts this has the consequence that not all index values are a */ + /* valid argument to @FT_Load_Glyph. Only the CID values for which */ + /* corresponding glyphs in the subsetted font exist make */ + /* `FT_Load_Glyph' return successfully; in all other cases you get */ + /* an `FT_Err_Invalid_Argument' error. */ + /* */ + /* Note that CID-keyed fonts that are in an SFNT wrapper (this is, */ + /* all OpenType/CFF fonts) don't have this flag set since the */ + /* glyphs are accessed in the normal way (using contiguous */ + /* indices); the `CID-ness' isn't visible to the application. */ + /* */ + /* FT_FACE_FLAG_TRICKY :: */ + /* The face is `tricky', this is, it always needs the font format's */ + /* native hinting engine to get a reasonable result. A typical */ + /* example is the old Chinese font `mingli.ttf' (but not */ + /* `mingliu.ttc') that uses TrueType bytecode instructions to move */ + /* and scale all of its subglyphs. */ + /* */ + /* It is not possible to auto-hint such fonts using */ + /* @FT_LOAD_FORCE_AUTOHINT; it will also ignore */ + /* @FT_LOAD_NO_HINTING. You have to set both @FT_LOAD_NO_HINTING */ + /* and @FT_LOAD_NO_AUTOHINT to really disable hinting; however, you */ + /* probably never want this except for demonstration purposes. */ + /* */ + /* Currently, there are about a dozen TrueType fonts in the list of */ + /* tricky fonts; they are hard-coded in file `ttobjs.c'. */ + /* */ + /* FT_FACE_FLAG_COLOR :: */ + /* [Since 2.5.1] The face has color glyph tables. To access color */ + /* glyphs use @FT_LOAD_COLOR. */ + /* */ + /* FT_FACE_FLAG_VARIATION :: */ + /* [Since 2.9] Set if the current face (or named instance) has been */ + /* altered with @FT_Set_MM_Design_Coordinates, */ + /* @FT_Set_Var_Design_Coordinates, or */ + /* @FT_Set_Var_Blend_Coordinates. This flag is unset by a call to */ + /* @FT_Set_Named_Instance. */ + /* */ +#define FT_FACE_FLAG_SCALABLE ( 1L << 0 ) +#define FT_FACE_FLAG_FIXED_SIZES ( 1L << 1 ) +#define FT_FACE_FLAG_FIXED_WIDTH ( 1L << 2 ) +#define FT_FACE_FLAG_SFNT ( 1L << 3 ) +#define FT_FACE_FLAG_HORIZONTAL ( 1L << 4 ) +#define FT_FACE_FLAG_VERTICAL ( 1L << 5 ) +#define FT_FACE_FLAG_KERNING ( 1L << 6 ) +#define FT_FACE_FLAG_FAST_GLYPHS ( 1L << 7 ) +#define FT_FACE_FLAG_MULTIPLE_MASTERS ( 1L << 8 ) +#define FT_FACE_FLAG_GLYPH_NAMES ( 1L << 9 ) +#define FT_FACE_FLAG_EXTERNAL_STREAM ( 1L << 10 ) +#define FT_FACE_FLAG_HINTER ( 1L << 11 ) +#define FT_FACE_FLAG_CID_KEYED ( 1L << 12 ) +#define FT_FACE_FLAG_TRICKY ( 1L << 13 ) +#define FT_FACE_FLAG_COLOR ( 1L << 14 ) +#define FT_FACE_FLAG_VARIATION ( 1L << 15 ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_HORIZONTAL( face ) + * + * @description: + * A macro that returns true whenever a face object contains + * horizontal metrics (this is true for all font formats though). + * + * @also: + * @FT_HAS_VERTICAL can be used to check for vertical metrics. + * + */ +#define FT_HAS_HORIZONTAL( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_HORIZONTAL ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_VERTICAL( face ) + * + * @description: + * A macro that returns true whenever a face object contains real + * vertical metrics (and not only synthesized ones). + * + */ +#define FT_HAS_VERTICAL( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_VERTICAL ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_KERNING( face ) + * + * @description: + * A macro that returns true whenever a face object contains kerning + * data that can be accessed with @FT_Get_Kerning. + * + */ +#define FT_HAS_KERNING( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_KERNING ) + + + /************************************************************************* + * + * @macro: + * FT_IS_SCALABLE( face ) + * + * @description: + * A macro that returns true whenever a face object contains a scalable + * font face (true for TrueType, Type~1, Type~42, CID, OpenType/CFF, + * and PFR font formats). + * + */ +#define FT_IS_SCALABLE( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_SCALABLE ) + + + /************************************************************************* + * + * @macro: + * FT_IS_SFNT( face ) + * + * @description: + * A macro that returns true whenever a face object contains a font + * whose format is based on the SFNT storage scheme. This usually + * means: TrueType fonts, OpenType fonts, as well as SFNT-based embedded + * bitmap fonts. + * + * If this macro is true, all functions defined in @FT_SFNT_NAMES_H and + * @FT_TRUETYPE_TABLES_H are available. + * + */ +#define FT_IS_SFNT( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_SFNT ) + + + /************************************************************************* + * + * @macro: + * FT_IS_FIXED_WIDTH( face ) + * + * @description: + * A macro that returns true whenever a face object contains a font face + * that contains fixed-width (or `monospace', `fixed-pitch', etc.) + * glyphs. + * + */ +#define FT_IS_FIXED_WIDTH( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_FIXED_SIZES( face ) + * + * @description: + * A macro that returns true whenever a face object contains some + * embedded bitmaps. See the `available_sizes' field of the + * @FT_FaceRec structure. + * + */ +#define FT_HAS_FIXED_SIZES( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_FIXED_SIZES ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_FAST_GLYPHS( face ) + * + * @description: + * Deprecated. + * + */ +#define FT_HAS_FAST_GLYPHS( face ) 0 + + + /************************************************************************* + * + * @macro: + * FT_HAS_GLYPH_NAMES( face ) + * + * @description: + * A macro that returns true whenever a face object contains some glyph + * names that can be accessed through @FT_Get_Glyph_Name. + * + */ +#define FT_HAS_GLYPH_NAMES( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_MULTIPLE_MASTERS( face ) + * + * @description: + * A macro that returns true whenever a face object contains some + * multiple masters. The functions provided by @FT_MULTIPLE_MASTERS_H + * are then available to choose the exact design you want. + * + */ +#define FT_HAS_MULTIPLE_MASTERS( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS ) + + + /************************************************************************* + * + * @macro: + * FT_IS_NAMED_INSTANCE( face ) + * + * @description: + * A macro that returns true whenever a face object is a named instance + * of a GX or OpenType variation font. + * + * [Since 2.9] Changing the design coordinates with + * @FT_Set_Var_Design_Coordinates or @FT_Set_Var_Blend_Coordinates does + * not influence the return value of this macro (only + * @FT_Set_Named_Instance does that). + * + * @since: + * 2.7 + * + */ +#define FT_IS_NAMED_INSTANCE( face ) \ + ( (face)->face_index & 0x7FFF0000L ) + + + /************************************************************************* + * + * @macro: + * FT_IS_VARIATION( face ) + * + * @description: + * A macro that returns true whenever a face object has been altered + * by @FT_Set_MM_Design_Coordinates, @FT_Set_Var_Design_Coordinates, or + * @FT_Set_Var_Blend_Coordinates. + * + * @since: + * 2.9 + * + */ +#define FT_IS_VARIATION( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_VARIATION ) + + + /************************************************************************* + * + * @macro: + * FT_IS_CID_KEYED( face ) + * + * @description: + * A macro that returns true whenever a face object contains a CID-keyed + * font. See the discussion of @FT_FACE_FLAG_CID_KEYED for more + * details. + * + * If this macro is true, all functions defined in @FT_CID_H are + * available. + * + */ +#define FT_IS_CID_KEYED( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_CID_KEYED ) + + + /************************************************************************* + * + * @macro: + * FT_IS_TRICKY( face ) + * + * @description: + * A macro that returns true whenever a face represents a `tricky' font. + * See the discussion of @FT_FACE_FLAG_TRICKY for more details. + * + */ +#define FT_IS_TRICKY( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_TRICKY ) + + + /************************************************************************* + * + * @macro: + * FT_HAS_COLOR( face ) + * + * @description: + * A macro that returns true whenever a face object contains + * tables for color glyphs. + * + * @since: + * 2.5.1 + * + */ +#define FT_HAS_COLOR( face ) \ + ( (face)->face_flags & FT_FACE_FLAG_COLOR ) + + + /*************************************************************************/ + /* */ + /* <Const> */ + /* FT_STYLE_FLAG_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags to indicate the style of a given face. These */ + /* are used in the `style_flags' field of @FT_FaceRec. */ + /* */ + /* <Values> */ + /* FT_STYLE_FLAG_ITALIC :: */ + /* The face style is italic or oblique. */ + /* */ + /* FT_STYLE_FLAG_BOLD :: */ + /* The face is bold. */ + /* */ + /* <Note> */ + /* The style information as provided by FreeType is very basic. More */ + /* details are beyond the scope and should be done on a higher level */ + /* (for example, by analyzing various fields of the `OS/2' table in */ + /* SFNT based fonts). */ + /* */ +#define FT_STYLE_FLAG_ITALIC ( 1 << 0 ) +#define FT_STYLE_FLAG_BOLD ( 1 << 1 ) + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Size_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Size_InternalRec' structure, used to */ + /* model private data of a given @FT_Size object. */ + /* */ + typedef struct FT_Size_InternalRec_* FT_Size_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_Metrics */ + /* */ + /* <Description> */ + /* The size metrics structure gives the metrics of a size object. */ + /* */ + /* <Fields> */ + /* x_ppem :: The width of the scaled EM square in pixels, hence */ + /* the term `ppem' (pixels per EM). It is also */ + /* referred to as `nominal width'. */ + /* */ + /* y_ppem :: The height of the scaled EM square in pixels, */ + /* hence the term `ppem' (pixels per EM). It is also */ + /* referred to as `nominal height'. */ + /* */ + /* x_scale :: A 16.16 fractional scaling value to convert */ + /* horizontal metrics from font units to 26.6 */ + /* fractional pixels. Only relevant for scalable */ + /* font formats. */ + /* */ + /* y_scale :: A 16.16 fractional scaling value to convert */ + /* vertical metrics from font units to 26.6 */ + /* fractional pixels. Only relevant for scalable */ + /* font formats. */ + /* */ + /* ascender :: The ascender in 26.6 fractional pixels, rounded up */ + /* to an integer value. See @FT_FaceRec for the */ + /* details. */ + /* */ + /* descender :: The descender in 26.6 fractional pixels, rounded */ + /* down to an integer value. See @FT_FaceRec for the */ + /* details. */ + /* */ + /* height :: The height in 26.6 fractional pixels, rounded to */ + /* an integer value. See @FT_FaceRec for the */ + /* details. */ + /* */ + /* max_advance :: The maximum advance width in 26.6 fractional */ + /* pixels, rounded to an integer value. See */ + /* @FT_FaceRec for the details. */ + /* */ + /* <Note> */ + /* The scaling values, if relevant, are determined first during a */ + /* size changing operation. The remaining fields are then set by the */ + /* driver. For scalable formats, they are usually set to scaled */ + /* values of the corresponding fields in @FT_FaceRec. Some values */ + /* like ascender or descender are rounded for historical reasons; */ + /* more precise values (for outline fonts) can be derived by scaling */ + /* the corresponding @FT_FaceRec values manually, with code similar */ + /* to the following. */ + /* */ + /* { */ + /* scaled_ascender = FT_MulFix( face->ascender, */ + /* size_metrics->y_scale ); */ + /* } */ + /* */ + /* Note that due to glyph hinting and the selected rendering mode */ + /* these values are usually not exact; consequently, they must be */ + /* treated as unreliable with an error margin of at least one pixel! */ + /* */ + /* Indeed, the only way to get the exact metrics is to render _all_ */ + /* glyphs. As this would be a definite performance hit, it is up to */ + /* client applications to perform such computations. */ + /* */ + /* The `FT_Size_Metrics' structure is valid for bitmap fonts also. */ + /* */ + /* */ + /* *TrueType* *fonts* *with* *native* *bytecode* *hinting* */ + /* */ + /* All applications that handle TrueType fonts with native hinting */ + /* must be aware that TTFs expect different rounding of vertical font */ + /* dimensions. The application has to cater for this, especially if */ + /* it wants to rely on a TTF's vertical data (for example, to */ + /* properly align box characters vertically). */ + /* */ + /* Only the application knows _in_ _advance_ that it is going to use */ + /* native hinting for TTFs! FreeType, on the other hand, selects the */ + /* hinting mode not at the time of creating an @FT_Size object but */ + /* much later, namely while calling @FT_Load_Glyph. */ + /* */ + /* Here is some pseudo code that illustrates a possible solution. */ + /* */ + /* { */ + /* font_format = FT_Get_Font_Format( face ); */ + /* */ + /* if ( !strcmp( font_format, "TrueType" ) && */ + /* do_native_bytecode_hinting ) */ + /* { */ + /* ascender = ROUND( FT_MulFix( face->ascender, */ + /* size_metrics->y_scale ) ); */ + /* descender = ROUND( FT_MulFix( face->descender, */ + /* size_metrics->y_scale ) ); */ + /* } */ + /* else */ + /* { */ + /* ascender = size_metrics->ascender; */ + /* descender = size_metrics->descender; */ + /* } */ + /* */ + /* height = size_metrics->height; */ + /* max_advance = size_metrics->max_advance; */ + /* } */ + /* */ + typedef struct FT_Size_Metrics_ + { + FT_UShort x_ppem; /* horizontal pixels per EM */ + FT_UShort y_ppem; /* vertical pixels per EM */ + + FT_Fixed x_scale; /* scaling values used to convert font */ + FT_Fixed y_scale; /* units to 26.6 fractional pixels */ + + FT_Pos ascender; /* ascender in 26.6 frac. pixels */ + FT_Pos descender; /* descender in 26.6 frac. pixels */ + FT_Pos height; /* text height in 26.6 frac. pixels */ + FT_Pos max_advance; /* max horizontal advance, in 26.6 pixels */ + + } FT_Size_Metrics; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SizeRec */ + /* */ + /* <Description> */ + /* FreeType root size class structure. A size object models a face */ + /* object at a given size. */ + /* */ + /* <Fields> */ + /* face :: Handle to the parent face object. */ + /* */ + /* generic :: A typeless pointer, unused by the FreeType library or */ + /* any of its drivers. It can be used by client */ + /* applications to link their own data to each size */ + /* object. */ + /* */ + /* metrics :: Metrics for this size object. This field is read-only. */ + /* */ + typedef struct FT_SizeRec_ + { + FT_Face face; /* parent face object */ + FT_Generic generic; /* generic pointer for client uses */ + FT_Size_Metrics metrics; /* size metrics */ + FT_Size_Internal internal; + + } FT_SizeRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_SubGlyph */ + /* */ + /* <Description> */ + /* The subglyph structure is an internal object used to describe */ + /* subglyphs (for example, in the case of composites). */ + /* */ + /* <Note> */ + /* The subglyph implementation is not part of the high-level API, */ + /* hence the forward structure declaration. */ + /* */ + /* You can however retrieve subglyph information with */ + /* @FT_Get_SubGlyph_Info. */ + /* */ + typedef struct FT_SubGlyphRec_* FT_SubGlyph; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FT_Slot_Internal */ + /* */ + /* <Description> */ + /* An opaque handle to an `FT_Slot_InternalRec' structure, used to */ + /* model private data of a given @FT_GlyphSlot object. */ + /* */ + typedef struct FT_Slot_InternalRec_* FT_Slot_Internal; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_GlyphSlotRec */ + /* */ + /* <Description> */ + /* FreeType root glyph slot class structure. A glyph slot is a */ + /* container where individual glyphs can be loaded, be they in */ + /* outline or bitmap format. */ + /* */ + /* <Fields> */ + /* library :: A handle to the FreeType library instance */ + /* this slot belongs to. */ + /* */ + /* face :: A handle to the parent face object. */ + /* */ + /* next :: In some cases (like some font tools), several */ + /* glyph slots per face object can be a good */ + /* thing. As this is rare, the glyph slots are */ + /* listed through a direct, single-linked list */ + /* using its `next' field. */ + /* */ + /* generic :: A typeless pointer unused by the FreeType */ + /* library or any of its drivers. It can be */ + /* used by client applications to link their own */ + /* data to each glyph slot object. */ + /* */ + /* metrics :: The metrics of the last loaded glyph in the */ + /* slot. The returned values depend on the last */ + /* load flags (see the @FT_Load_Glyph API */ + /* function) and can be expressed either in 26.6 */ + /* fractional pixels or font units. */ + /* */ + /* Note that even when the glyph image is */ + /* transformed, the metrics are not. */ + /* */ + /* linearHoriAdvance :: The advance width of the unhinted glyph. */ + /* Its value is expressed in 16.16 fractional */ + /* pixels, unless @FT_LOAD_LINEAR_DESIGN is set */ + /* when loading the glyph. This field can be */ + /* important to perform correct WYSIWYG layout. */ + /* Only relevant for outline glyphs. */ + /* */ + /* linearVertAdvance :: The advance height of the unhinted glyph. */ + /* Its value is expressed in 16.16 fractional */ + /* pixels, unless @FT_LOAD_LINEAR_DESIGN is set */ + /* when loading the glyph. This field can be */ + /* important to perform correct WYSIWYG layout. */ + /* Only relevant for outline glyphs. */ + /* */ + /* advance :: This shorthand is, depending on */ + /* @FT_LOAD_IGNORE_TRANSFORM, the transformed */ + /* (hinted) advance width for the glyph, in 26.6 */ + /* fractional pixel format. As specified with */ + /* @FT_LOAD_VERTICAL_LAYOUT, it uses either the */ + /* `horiAdvance' or the `vertAdvance' value of */ + /* `metrics' field. */ + /* */ + /* format :: This field indicates the format of the image */ + /* contained in the glyph slot. Typically */ + /* @FT_GLYPH_FORMAT_BITMAP, */ + /* @FT_GLYPH_FORMAT_OUTLINE, or */ + /* @FT_GLYPH_FORMAT_COMPOSITE, but other values */ + /* are possible. */ + /* */ + /* bitmap :: This field is used as a bitmap descriptor. */ + /* Note that the address and content of the */ + /* bitmap buffer can change between calls of */ + /* @FT_Load_Glyph and a few other functions. */ + /* */ + /* bitmap_left :: The bitmap's left bearing expressed in */ + /* integer pixels. */ + /* */ + /* bitmap_top :: The bitmap's top bearing expressed in integer */ + /* pixels. This is the distance from the */ + /* baseline to the top-most glyph scanline, */ + /* upwards y~coordinates being *positive*. */ + /* */ + /* outline :: The outline descriptor for the current glyph */ + /* image if its format is */ + /* @FT_GLYPH_FORMAT_OUTLINE. Once a glyph is */ + /* loaded, `outline' can be transformed, */ + /* distorted, emboldened, etc. However, it must */ + /* not be freed. */ + /* */ + /* num_subglyphs :: The number of subglyphs in a composite glyph. */ + /* This field is only valid for the composite */ + /* glyph format that should normally only be */ + /* loaded with the @FT_LOAD_NO_RECURSE flag. */ + /* */ + /* subglyphs :: An array of subglyph descriptors for */ + /* composite glyphs. There are `num_subglyphs' */ + /* elements in there. Currently internal to */ + /* FreeType. */ + /* */ + /* control_data :: Certain font drivers can also return the */ + /* control data for a given glyph image (e.g. */ + /* TrueType bytecode, Type~1 charstrings, etc.). */ + /* This field is a pointer to such data; it is */ + /* currently internal to FreeType. */ + /* */ + /* control_len :: This is the length in bytes of the control */ + /* data. Currently internal to FreeType. */ + /* */ + /* other :: Reserved. */ + /* */ + /* lsb_delta :: The difference between hinted and unhinted */ + /* left side bearing while auto-hinting is */ + /* active. Zero otherwise. */ + /* */ + /* rsb_delta :: The difference between hinted and unhinted */ + /* right side bearing while auto-hinting is */ + /* active. Zero otherwise. */ + /* */ + /* <Note> */ + /* If @FT_Load_Glyph is called with default flags (see */ + /* @FT_LOAD_DEFAULT) the glyph image is loaded in the glyph slot in */ + /* its native format (e.g., an outline glyph for TrueType and Type~1 */ + /* formats). [Since 2.9] The prospective bitmap metrics are */ + /* calculated according to @FT_LOAD_TARGET_XXX and other flags even */ + /* for the outline glyph, even if @FT_LOAD_RENDER is not set. */ + /* */ + /* This image can later be converted into a bitmap by calling */ + /* @FT_Render_Glyph. This function searches the current renderer for */ + /* the native image's format, then invokes it. */ + /* */ + /* The renderer is in charge of transforming the native image through */ + /* the slot's face transformation fields, then converting it into a */ + /* bitmap that is returned in `slot->bitmap'. */ + /* */ + /* Note that `slot->bitmap_left' and `slot->bitmap_top' are also used */ + /* to specify the position of the bitmap relative to the current pen */ + /* position (e.g., coordinates (0,0) on the baseline). Of course, */ + /* `slot->format' is also changed to @FT_GLYPH_FORMAT_BITMAP. */ + /* */ + /* Here is a small pseudo code fragment that shows how to use */ + /* `lsb_delta' and `rsb_delta' to do fractional positioning of */ + /* glyphs: */ + /* */ + /* { */ + /* FT_GlyphSlot slot = face->glyph; */ + /* FT_Pos origin_x = 0; */ + /* */ + /* */ + /* for all glyphs do */ + /* <load glyph with `FT_Load_Glyph'> */ + /* */ + /* FT_Outline_Translate( slot->outline, origin_x & 63, 0 ); */ + /* */ + /* <save glyph image, or render glyph, or ...> */ + /* */ + /* <compute kern between current and next glyph */ + /* and add it to `origin_x'> */ + /* */ + /* origin_x += slot->advance.x; */ + /* origin_x += slot->rsb_delta - slot->lsb_delta; */ + /* endfor */ + /* } */ + /* */ + /* Here is another small pseudo code fragment that shows how to use */ + /* `lsb_delta' and `rsb_delta' to improve integer positioning of */ + /* glyphs: */ + /* */ + /* { */ + /* FT_GlyphSlot slot = face->glyph; */ + /* FT_Pos origin_x = 0; */ + /* FT_Pos prev_rsb_delta = 0; */ + /* */ + /* */ + /* for all glyphs do */ + /* <compute kern between current and previous glyph */ + /* and add it to `origin_x'> */ + /* */ + /* <load glyph with `FT_Load_Glyph'> */ + /* */ + /* if ( prev_rsb_delta - slot->lsb_delta > 32 ) */ + /* origin_x -= 64; */ + /* else if ( prev_rsb_delta - slot->lsb_delta < -31 ) */ + /* origin_x += 64; */ + /* */ + /* prev_rsb_delta = slot->rsb_delta; */ + /* */ + /* <save glyph image, or render glyph, or ...> */ + /* */ + /* origin_x += slot->advance.x; */ + /* endfor */ + /* } */ + /* */ + /* If you use strong auto-hinting, you *must* apply these delta */ + /* values! Otherwise you will experience far too large inter-glyph */ + /* spacing at small rendering sizes in most cases. Note that it */ + /* doesn't harm to use the above code for other hinting modes also, */ + /* since the delta values are zero then. */ + /* */ + typedef struct FT_GlyphSlotRec_ + { + FT_Library library; + FT_Face face; + FT_GlyphSlot next; + FT_UInt reserved; /* retained for binary compatibility */ + FT_Generic generic; + + FT_Glyph_Metrics metrics; + FT_Fixed linearHoriAdvance; + FT_Fixed linearVertAdvance; + FT_Vector advance; + + FT_Glyph_Format format; + + FT_Bitmap bitmap; + FT_Int bitmap_left; + FT_Int bitmap_top; + + FT_Outline outline; + + FT_UInt num_subglyphs; + FT_SubGlyph subglyphs; + + void* control_data; + long control_len; + + FT_Pos lsb_delta; + FT_Pos rsb_delta; + + void* other; + + FT_Slot_Internal internal; + + } FT_GlyphSlotRec; + + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* F U N C T I O N S */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Init_FreeType */ + /* */ + /* <Description> */ + /* Initialize a new FreeType library object. The set of modules */ + /* that are registered by this function is determined at build time. */ + /* */ + /* <Output> */ + /* alibrary :: A handle to a new library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* In case you want to provide your own memory allocating routines, */ + /* use @FT_New_Library instead, followed by a call to */ + /* @FT_Add_Default_Modules (or a series of calls to @FT_Add_Module) */ + /* and @FT_Set_Default_Properties. */ + /* */ + /* See the documentation of @FT_Library and @FT_Face for */ + /* multi-threading issues. */ + /* */ + /* If you need reference-counting (cf. @FT_Reference_Library), use */ + /* @FT_New_Library and @FT_Done_Library. */ + /* */ + /* If compilation option FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES is */ + /* set, this function reads the `FREETYPE_PROPERTIES' environment */ + /* variable to control driver properties. See section @properties */ + /* for more. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Init_FreeType( FT_Library *alibrary ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_FreeType */ + /* */ + /* <Description> */ + /* Destroy a given FreeType library object and all of its children, */ + /* including resources, drivers, faces, sizes, etc. */ + /* */ + /* <Input> */ + /* library :: A handle to the target library object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_FreeType( FT_Library library ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_OPEN_XXX */ + /* */ + /* <Description> */ + /* A list of bit field constants used within the `flags' field of the */ + /* @FT_Open_Args structure. */ + /* */ + /* <Values> */ + /* FT_OPEN_MEMORY :: This is a memory-based stream. */ + /* */ + /* FT_OPEN_STREAM :: Copy the stream from the `stream' field. */ + /* */ + /* FT_OPEN_PATHNAME :: Create a new input stream from a C~path */ + /* name. */ + /* */ + /* FT_OPEN_DRIVER :: Use the `driver' field. */ + /* */ + /* FT_OPEN_PARAMS :: Use the `num_params' and `params' fields. */ + /* */ + /* <Note> */ + /* The `FT_OPEN_MEMORY', `FT_OPEN_STREAM', and `FT_OPEN_PATHNAME' */ + /* flags are mutually exclusive. */ + /* */ +#define FT_OPEN_MEMORY 0x1 +#define FT_OPEN_STREAM 0x2 +#define FT_OPEN_PATHNAME 0x4 +#define FT_OPEN_DRIVER 0x8 +#define FT_OPEN_PARAMS 0x10 + + + /* these constants are deprecated; use the corresponding `FT_OPEN_XXX' */ + /* values instead */ +#define ft_open_memory FT_OPEN_MEMORY +#define ft_open_stream FT_OPEN_STREAM +#define ft_open_pathname FT_OPEN_PATHNAME +#define ft_open_driver FT_OPEN_DRIVER +#define ft_open_params FT_OPEN_PARAMS + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Parameter */ + /* */ + /* <Description> */ + /* A simple structure to pass more or less generic parameters to */ + /* @FT_Open_Face and @FT_Face_Properties. */ + /* */ + /* <Fields> */ + /* tag :: A four-byte identification tag. */ + /* */ + /* data :: A pointer to the parameter data. */ + /* */ + /* <Note> */ + /* The ID and function of parameters are driver-specific. See */ + /* section @parameter_tags for more information. */ + /* */ + typedef struct FT_Parameter_ + { + FT_ULong tag; + FT_Pointer data; + + } FT_Parameter; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Open_Args */ + /* */ + /* <Description> */ + /* A structure to indicate how to open a new font file or stream. A */ + /* pointer to such a structure can be used as a parameter for the */ + /* functions @FT_Open_Face and @FT_Attach_Stream. */ + /* */ + /* <Fields> */ + /* flags :: A set of bit flags indicating how to use the */ + /* structure. */ + /* */ + /* memory_base :: The first byte of the file in memory. */ + /* */ + /* memory_size :: The size in bytes of the file in memory. */ + /* */ + /* pathname :: A pointer to an 8-bit file pathname. */ + /* */ + /* stream :: A handle to a source stream object. */ + /* */ + /* driver :: This field is exclusively used by @FT_Open_Face; */ + /* it simply specifies the font driver to use for */ + /* opening the face. If set to NULL, FreeType tries */ + /* to load the face with each one of the drivers in */ + /* its list. */ + /* */ + /* num_params :: The number of extra parameters. */ + /* */ + /* params :: Extra parameters passed to the font driver when */ + /* opening a new face. */ + /* */ + /* <Note> */ + /* The stream type is determined by the contents of `flags' that */ + /* are tested in the following order by @FT_Open_Face: */ + /* */ + /* If the @FT_OPEN_MEMORY bit is set, assume that this is a */ + /* memory file of `memory_size' bytes, located at `memory_address'. */ + /* The data are not copied, and the client is responsible for */ + /* releasing and destroying them _after_ the corresponding call to */ + /* @FT_Done_Face. */ + /* */ + /* Otherwise, if the @FT_OPEN_STREAM bit is set, assume that a */ + /* custom input stream `stream' is used. */ + /* */ + /* Otherwise, if the @FT_OPEN_PATHNAME bit is set, assume that this */ + /* is a normal file and use `pathname' to open it. */ + /* */ + /* If the @FT_OPEN_DRIVER bit is set, @FT_Open_Face only tries to */ + /* open the file with the driver whose handler is in `driver'. */ + /* */ + /* If the @FT_OPEN_PARAMS bit is set, the parameters given by */ + /* `num_params' and `params' is used. They are ignored otherwise. */ + /* */ + /* Ideally, both the `pathname' and `params' fields should be tagged */ + /* as `const'; this is missing for API backward compatibility. In */ + /* other words, applications should treat them as read-only. */ + /* */ + typedef struct FT_Open_Args_ + { + FT_UInt flags; + const FT_Byte* memory_base; + FT_Long memory_size; + FT_String* pathname; + FT_Stream stream; + FT_Module driver; + FT_Int num_params; + FT_Parameter* params; + + } FT_Open_Args; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Face */ + /* */ + /* <Description> */ + /* Call @FT_Open_Face to open a font by its pathname. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* pathname :: A path to the font file. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Use @FT_Done_Face to destroy the created @FT_Face object (along */ + /* with its slot and sizes). */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Face( FT_Library library, + const char* filepathname, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_New_Memory_Face */ + /* */ + /* <Description> */ + /* Call @FT_Open_Face to open a font that has been loaded into */ + /* memory. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* file_base :: A pointer to the beginning of the font data. */ + /* */ + /* file_size :: The size of the memory chunk used by the font data. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You must not deallocate the memory before calling @FT_Done_Face. */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Memory_Face( FT_Library library, + const FT_Byte* file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Open_Face */ + /* */ + /* <Description> */ + /* Create a face object from a given resource described by */ + /* @FT_Open_Args. */ + /* */ + /* <InOut> */ + /* library :: A handle to the library resource. */ + /* */ + /* <Input> */ + /* args :: A pointer to an `FT_Open_Args' structure that must */ + /* be filled by the caller. */ + /* */ + /* face_index :: This field holds two different values. Bits 0-15 */ + /* are the index of the face in the font file (starting */ + /* with value~0). Set it to~0 if there is only one */ + /* face in the font file. */ + /* */ + /* [Since 2.6.1] Bits 16-30 are relevant to GX and */ + /* OpenType variation fonts only, specifying the named */ + /* instance index for the current face index (starting */ + /* with value~1; value~0 makes FreeType ignore named */ + /* instances). For non-variation fonts, bits 16-30 are */ + /* ignored. Assuming that you want to access the third */ + /* named instance in face~4, `face_index' should be set */ + /* to 0x00030004. If you want to access face~4 without */ + /* variation handling, simply set `face_index' to */ + /* value~4. */ + /* */ + /* `FT_Open_Face' and its siblings can be used to */ + /* quickly check whether the font format of a given */ + /* font resource is supported by FreeType. In general, */ + /* if the `face_index' argument is negative, the */ + /* function's return value is~0 if the font format is */ + /* recognized, or non-zero otherwise. The function */ + /* allocates a more or less empty face handle in */ + /* `*aface' (if `aface' isn't NULL); the only two */ + /* useful fields in this special case are */ + /* `face->num_faces' and `face->style_flags'. For any */ + /* negative value of `face_index', `face->num_faces' */ + /* gives the number of faces within the font file. For */ + /* the negative value `-(N+1)' (with `N' a non-negative */ + /* 16-bit value), bits 16-30 in `face->style_flags' */ + /* give the number of named instances in face `N' if we */ + /* have a variation font (or zero otherwise). After */ + /* examination, the returned @FT_Face structure should */ + /* be deallocated with a call to @FT_Done_Face. */ + /* */ + /* <Output> */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Unlike FreeType 1.x, this function automatically creates a glyph */ + /* slot for the face object that can be accessed directly through */ + /* `face->glyph'. */ + /* */ + /* Each new face object created with this function also owns a */ + /* default @FT_Size object, accessible as `face->size'. */ + /* */ + /* One @FT_Library instance can have multiple face objects, this is, */ + /* @FT_Open_Face and its siblings can be called multiple times using */ + /* the same `library' argument. */ + /* */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Face. */ + /* */ + /* To loop over all faces, use code similar to the following snippet */ + /* (omitting the error handling). */ + /* */ + /* { */ + /* ... */ + /* FT_Face face; */ + /* FT_Long i, num_faces; */ + /* */ + /* */ + /* error = FT_Open_Face( library, args, -1, &face ); */ + /* if ( error ) { ... } */ + /* */ + /* num_faces = face->num_faces; */ + /* FT_Done_Face( face ); */ + /* */ + /* for ( i = 0; i < num_faces; i++ ) */ + /* { */ + /* ... */ + /* error = FT_Open_Face( library, args, i, &face ); */ + /* ... */ + /* FT_Done_Face( face ); */ + /* ... */ + /* } */ + /* } */ + /* */ + /* To loop over all valid values for `face_index', use something */ + /* similar to the following snippet, again without error handling. */ + /* The code accesses all faces immediately (thus only a single call */ + /* of `FT_Open_Face' within the do-loop), with and without named */ + /* instances. */ + /* */ + /* { */ + /* ... */ + /* FT_Face face; */ + /* */ + /* FT_Long num_faces = 0; */ + /* FT_Long num_instances = 0; */ + /* */ + /* FT_Long face_idx = 0; */ + /* FT_Long instance_idx = 0; */ + /* */ + /* */ + /* do */ + /* { */ + /* FT_Long id = ( instance_idx << 16 ) + face_idx; */ + /* */ + /* */ + /* error = FT_Open_Face( library, args, id, &face ); */ + /* if ( error ) { ... } */ + /* */ + /* num_faces = face->num_faces; */ + /* num_instances = face->style_flags >> 16; */ + /* */ + /* ... */ + /* */ + /* FT_Done_Face( face ); */ + /* */ + /* if ( instance_idx < num_instances ) */ + /* instance_idx++; */ + /* else */ + /* { */ + /* face_idx++; */ + /* instance_idx = 0; */ + /* } */ + /* */ + /* } while ( face_idx < num_faces ) */ + /* } */ + /* */ + FT_EXPORT( FT_Error ) + FT_Open_Face( FT_Library library, + const FT_Open_Args* args, + FT_Long face_index, + FT_Face *aface ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Attach_File */ + /* */ + /* <Description> */ + /* Call @FT_Attach_Stream to attach a file. */ + /* */ + /* <InOut> */ + /* face :: The target face object. */ + /* */ + /* <Input> */ + /* filepathname :: The pathname. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Attach_File( FT_Face face, + const char* filepathname ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Attach_Stream */ + /* */ + /* <Description> */ + /* `Attach' data to a face object. Normally, this is used to read */ + /* additional information for the face object. For example, you can */ + /* attach an AFM file that comes with a Type~1 font to get the */ + /* kerning values and other metrics. */ + /* */ + /* <InOut> */ + /* face :: The target face object. */ + /* */ + /* <Input> */ + /* parameters :: A pointer to @FT_Open_Args that must be filled by */ + /* the caller. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The meaning of the `attach' (i.e., what really happens when the */ + /* new file is read) is not fixed by FreeType itself. It really */ + /* depends on the font format (and thus the font driver). */ + /* */ + /* Client applications are expected to know what they are doing */ + /* when invoking this function. Most drivers simply do not implement */ + /* file or stream attachments. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Attach_Stream( FT_Face face, + FT_Open_Args* parameters ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Reference_Face */ + /* */ + /* <Description> */ + /* A counter gets initialized to~1 at the time an @FT_Face structure */ + /* is created. This function increments the counter. @FT_Done_Face */ + /* then only destroys a face if the counter is~1, otherwise it simply */ + /* decrements the counter. */ + /* */ + /* This function helps in managing life-cycles of structures that */ + /* reference @FT_Face objects. */ + /* */ + /* <Input> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Since> */ + /* 2.4.2 */ + /* */ + FT_EXPORT( FT_Error ) + FT_Reference_Face( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Done_Face */ + /* */ + /* <Description> */ + /* Discard a given face object, as well as all of its child slots and */ + /* sizes. */ + /* */ + /* <Input> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* See the discussion of reference counters in the description of */ + /* @FT_Reference_Face. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Done_Face( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Select_Size */ + /* */ + /* <Description> */ + /* Select a bitmap strike. To be more precise, this function sets */ + /* the scaling factors of the active @FT_Size object in a face so */ + /* that bitmaps from this particular strike are taken by */ + /* @FT_Load_Glyph and friends. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* strike_index :: The index of the bitmap strike in the */ + /* `available_sizes' field of @FT_FaceRec structure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* For bitmaps embedded in outline fonts it is common that only a */ + /* subset of the available glyphs at a given ppem value is available. */ + /* FreeType silently uses outlines if there is no bitmap for a given */ + /* glyph index. */ + /* */ + /* For GX and OpenType variation fonts, a bitmap strike makes sense */ + /* only if the default instance is active (this is, no glyph */ + /* variation takes place); otherwise, FreeType simply ignores bitmap */ + /* strikes. The same is true for all named instances that are */ + /* different from the default instance. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Select_Size( FT_Face face, + FT_Int strike_index ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Size_Request_Type */ + /* */ + /* <Description> */ + /* An enumeration type that lists the supported size request types, */ + /* i.e., what input size (in font units) maps to the requested output */ + /* size (in pixels, as computed from the arguments of */ + /* @FT_Size_Request). */ + /* */ + /* <Values> */ + /* FT_SIZE_REQUEST_TYPE_NOMINAL :: */ + /* The nominal size. The `units_per_EM' field of @FT_FaceRec is */ + /* used to determine both scaling values. */ + /* */ + /* This is the standard scaling found in most applications. In */ + /* particular, use this size request type for TrueType fonts if */ + /* they provide optical scaling or something similar. Note, */ + /* however, that `units_per_EM' is a rather abstract value which */ + /* bears no relation to the actual size of the glyphs in a font. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_REAL_DIM :: */ + /* The real dimension. The sum of the `ascender' and (minus of) */ + /* the `descender' fields of @FT_FaceRec is used to determine both */ + /* scaling values. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_BBOX :: */ + /* The font bounding box. The width and height of the `bbox' field */ + /* of @FT_FaceRec are used to determine the horizontal and vertical */ + /* scaling value, respectively. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_CELL :: */ + /* The `max_advance_width' field of @FT_FaceRec is used to */ + /* determine the horizontal scaling value; the vertical scaling */ + /* value is determined the same way as */ + /* @FT_SIZE_REQUEST_TYPE_REAL_DIM does. Finally, both scaling */ + /* values are set to the smaller one. This type is useful if you */ + /* want to specify the font size for, say, a window of a given */ + /* dimension and 80x24 cells. */ + /* */ + /* FT_SIZE_REQUEST_TYPE_SCALES :: */ + /* Specify the scaling values directly. */ + /* */ + /* <Note> */ + /* The above descriptions only apply to scalable formats. For bitmap */ + /* formats, the behaviour is up to the driver. */ + /* */ + /* See the note section of @FT_Size_Metrics if you wonder how size */ + /* requesting relates to scaling values. */ + /* */ + typedef enum FT_Size_Request_Type_ + { + FT_SIZE_REQUEST_TYPE_NOMINAL, + FT_SIZE_REQUEST_TYPE_REAL_DIM, + FT_SIZE_REQUEST_TYPE_BBOX, + FT_SIZE_REQUEST_TYPE_CELL, + FT_SIZE_REQUEST_TYPE_SCALES, + + FT_SIZE_REQUEST_TYPE_MAX + + } FT_Size_Request_Type; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_RequestRec */ + /* */ + /* <Description> */ + /* A structure to model a size request. */ + /* */ + /* <Fields> */ + /* type :: See @FT_Size_Request_Type. */ + /* */ + /* width :: The desired width, given as a 26.6 fractional */ + /* point value (with 72pt = 1in). */ + /* */ + /* height :: The desired height, given as a 26.6 fractional */ + /* point value (with 72pt = 1in). */ + /* */ + /* horiResolution :: The horizontal resolution (dpi, i.e., pixels per */ + /* inch). If set to zero, `width' is treated as a */ + /* 26.6 fractional *pixel* value, which gets */ + /* internally rounded to an integer. */ + /* */ + /* vertResolution :: The vertical resolution (dpi, i.e., pixels per */ + /* inch). If set to zero, `height' is treated as a */ + /* 26.6 fractional *pixel* value, which gets */ + /* internally rounded to an integer. */ + /* */ + /* <Note> */ + /* If `width' is zero, the horizontal scaling value is set equal */ + /* to the vertical scaling value, and vice versa. */ + /* */ + /* If `type' is FT_SIZE_REQUEST_TYPE_SCALES, `width' and `height' are */ + /* interpreted directly as 16.16 fractional scaling values, without */ + /* any further modification, and both `horiResolution' and */ + /* `vertResolution' are ignored. */ + /* */ + typedef struct FT_Size_RequestRec_ + { + FT_Size_Request_Type type; + FT_Long width; + FT_Long height; + FT_UInt horiResolution; + FT_UInt vertResolution; + + } FT_Size_RequestRec; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_Size_Request */ + /* */ + /* <Description> */ + /* A handle to a size request structure. */ + /* */ + typedef struct FT_Size_RequestRec_ *FT_Size_Request; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Request_Size */ + /* */ + /* <Description> */ + /* Resize the scale of the active @FT_Size object in a face. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* req :: A pointer to a @FT_Size_RequestRec. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Although drivers may select the bitmap strike matching the */ + /* request, you should not rely on this if you intend to select a */ + /* particular bitmap strike. Use @FT_Select_Size instead in that */ + /* case. */ + /* */ + /* The relation between the requested size and the resulting glyph */ + /* size is dependent entirely on how the size is defined in the */ + /* source face. The font designer chooses the final size of each */ + /* glyph relative to this size. For more information refer to */ + /* `https://www.freetype.org/freetype2/docs/glyphs/glyphs-2.html'. */ + /* */ + /* Contrary to @FT_Set_Char_Size, this function doesn't have special */ + /* code to normalize zero-valued widths, heights, or resolutions */ + /* (which lead to errors in most cases). */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Request_Size( FT_Face face, + FT_Size_Request req ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Char_Size */ + /* */ + /* <Description> */ + /* Call @FT_Request_Size to request the nominal size (in points). */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object. */ + /* */ + /* <Input> */ + /* char_width :: The nominal width, in 26.6 fractional points. */ + /* */ + /* char_height :: The nominal height, in 26.6 fractional points. */ + /* */ + /* horz_resolution :: The horizontal resolution in dpi. */ + /* */ + /* vert_resolution :: The vertical resolution in dpi. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* While this function allows fractional points as input values, the */ + /* resulting ppem value for the given resolution is always rounded to */ + /* the nearest integer. */ + /* */ + /* If either the character width or height is zero, it is set equal */ + /* to the other value. */ + /* */ + /* If either the horizontal or vertical resolution is zero, it is set */ + /* equal to the other value. */ + /* */ + /* A character width or height smaller than 1pt is set to 1pt; if */ + /* both resolution values are zero, they are set to 72dpi. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Char_Size( FT_Face face, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Pixel_Sizes */ + /* */ + /* <Description> */ + /* Call @FT_Request_Size to request the nominal size (in pixels). */ + /* */ + /* <InOut> */ + /* face :: A handle to the target face object. */ + /* */ + /* <Input> */ + /* pixel_width :: The nominal width, in pixels. */ + /* */ + /* pixel_height :: The nominal height, in pixels. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* You should not rely on the resulting glyphs matching or being */ + /* constrained to this pixel size. Refer to @FT_Request_Size to */ + /* understand how requested sizes relate to actual sizes. */ + /* */ + /* Don't use this function if you are using the FreeType cache API. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Pixel_Sizes( FT_Face face, + FT_UInt pixel_width, + FT_UInt pixel_height ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Load_Glyph */ + /* */ + /* <Description> */ + /* Load a glyph into the glyph slot of a face object. */ + /* */ + /* <InOut> */ + /* face :: A handle to the target face object where the glyph */ + /* is loaded. */ + /* */ + /* <Input> */ + /* glyph_index :: The index of the glyph in the font file. For */ + /* CID-keyed fonts (either in PS or in CFF format) */ + /* this argument specifies the CID value. */ + /* */ + /* load_flags :: A flag indicating what to load for this glyph. The */ + /* @FT_LOAD_XXX constants can be used to control the */ + /* glyph loading process (e.g., whether the outline */ + /* should be scaled, whether to load bitmaps or not, */ + /* whether to hint the outline, etc). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* The loaded glyph may be transformed. See @FT_Set_Transform for */ + /* the details. */ + /* */ + /* For subsetted CID-keyed fonts, `FT_Err_Invalid_Argument' is */ + /* returned for invalid CID values (this is, for CID values that */ + /* don't have a corresponding glyph in the font). See the discussion */ + /* of the @FT_FACE_FLAG_CID_KEYED flag for more details. */ + /* */ + /* If you receive `FT_Err_Glyph_Too_Big', try getting the glyph */ + /* outline at EM size, then scale it manually and fill it as a */ + /* graphics operation. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Load_Glyph( FT_Face face, + FT_UInt glyph_index, + FT_Int32 load_flags ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Load_Char */ + /* */ + /* <Description> */ + /* Load a glyph into the glyph slot of a face object, accessed by its */ + /* character code. */ + /* */ + /* <InOut> */ + /* face :: A handle to a target face object where the glyph */ + /* is loaded. */ + /* */ + /* <Input> */ + /* char_code :: The glyph's character code, according to the */ + /* current charmap used in the face. */ + /* */ + /* load_flags :: A flag indicating what to load for this glyph. The */ + /* @FT_LOAD_XXX constants can be used to control the */ + /* glyph loading process (e.g., whether the outline */ + /* should be scaled, whether to load bitmaps or not, */ + /* whether to hint the outline, etc). */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function simply calls @FT_Get_Char_Index and @FT_Load_Glyph. */ + /* */ + /* Many fonts contain glyphs that can't be loaded by this function */ + /* since its glyph indices are not listed in any of the font's */ + /* charmaps. */ + /* */ + /* If no active cmap is set up (i.e., `face->charmap' is zero), the */ + /* call to @FT_Get_Char_Index is omitted, and the function behaves */ + /* identically to @FT_Load_Glyph. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Load_Char( FT_Face face, + FT_ULong char_code, + FT_Int32 load_flags ); + + + /************************************************************************* + * + * @enum: + * FT_LOAD_XXX + * + * @description: + * A list of bit field constants for @FT_Load_Glyph to indicate what + * kind of operations to perform during glyph loading. + * + * @values: + * FT_LOAD_DEFAULT :: + * Corresponding to~0, this value is used as the default glyph load + * operation. In this case, the following happens: + * + * 1. FreeType looks for a bitmap for the glyph corresponding to the + * face's current size. If one is found, the function returns. + * The bitmap data can be accessed from the glyph slot (see note + * below). + * + * 2. If no embedded bitmap is searched for or found, FreeType looks + * for a scalable outline. If one is found, it is loaded from + * the font file, scaled to device pixels, then `hinted' to the + * pixel grid in order to optimize it. The outline data can be + * accessed from the glyph slot (see note below). + * + * Note that by default the glyph loader doesn't render outlines into + * bitmaps. The following flags are used to modify this default + * behaviour to more specific and useful cases. + * + * FT_LOAD_NO_SCALE :: + * Don't scale the loaded outline glyph but keep it in font units. + * + * This flag implies @FT_LOAD_NO_HINTING and @FT_LOAD_NO_BITMAP, and + * unsets @FT_LOAD_RENDER. + * + * If the font is `tricky' (see @FT_FACE_FLAG_TRICKY for more), using + * FT_LOAD_NO_SCALE usually yields meaningless outlines because the + * subglyphs must be scaled and positioned with hinting instructions. + * This can be solved by loading the font without FT_LOAD_NO_SCALE and + * setting the character size to `font->units_per_EM'. + * + * FT_LOAD_NO_HINTING :: + * Disable hinting. This generally generates `blurrier' bitmap glyphs + * when the glyph are rendered in any of the anti-aliased modes. See + * also the note below. + * + * This flag is implied by @FT_LOAD_NO_SCALE. + * + * FT_LOAD_RENDER :: + * Call @FT_Render_Glyph after the glyph is loaded. By default, the + * glyph is rendered in @FT_RENDER_MODE_NORMAL mode. This can be + * overridden by @FT_LOAD_TARGET_XXX or @FT_LOAD_MONOCHROME. + * + * This flag is unset by @FT_LOAD_NO_SCALE. + * + * FT_LOAD_NO_BITMAP :: + * Ignore bitmap strikes when loading. Bitmap-only fonts ignore this + * flag. + * + * @FT_LOAD_NO_SCALE always sets this flag. + * + * FT_LOAD_VERTICAL_LAYOUT :: + * Load the glyph for vertical text layout. In particular, the + * `advance' value in the @FT_GlyphSlotRec structure is set to the + * `vertAdvance' value of the `metrics' field. + * + * In case @FT_HAS_VERTICAL doesn't return true, you shouldn't use + * this flag currently. Reason is that in this case vertical metrics + * get synthesized, and those values are not always consistent across + * various font formats. + * + * FT_LOAD_FORCE_AUTOHINT :: + * Prefer the auto-hinter over the font's native hinter. See also + * the note below. + * + * FT_LOAD_PEDANTIC :: + * Make the font driver perform pedantic verifications during glyph + * loading. This is mostly used to detect broken glyphs in fonts. + * By default, FreeType tries to handle broken fonts also. + * + * In particular, errors from the TrueType bytecode engine are not + * passed to the application if this flag is not set; this might + * result in partially hinted or distorted glyphs in case a glyph's + * bytecode is buggy. + * + * FT_LOAD_NO_RECURSE :: + * Don't load composite glyphs recursively. Instead, the font + * driver should set the `num_subglyph' and `subglyphs' values of + * the glyph slot accordingly, and set `glyph->format' to + * @FT_GLYPH_FORMAT_COMPOSITE. The description of subglyphs can + * then be accessed with @FT_Get_SubGlyph_Info. + * + * This flag implies @FT_LOAD_NO_SCALE and @FT_LOAD_IGNORE_TRANSFORM. + * + * FT_LOAD_IGNORE_TRANSFORM :: + * Ignore the transform matrix set by @FT_Set_Transform. + * + * FT_LOAD_MONOCHROME :: + * This flag is used with @FT_LOAD_RENDER to indicate that you want to + * render an outline glyph to a 1-bit monochrome bitmap glyph, with + * 8~pixels packed into each byte of the bitmap data. + * + * Note that this has no effect on the hinting algorithm used. You + * should rather use @FT_LOAD_TARGET_MONO so that the + * monochrome-optimized hinting algorithm is used. + * + * FT_LOAD_LINEAR_DESIGN :: + * Keep `linearHoriAdvance' and `linearVertAdvance' fields of + * @FT_GlyphSlotRec in font units. See @FT_GlyphSlotRec for + * details. + * + * FT_LOAD_NO_AUTOHINT :: + * Disable the auto-hinter. See also the note below. + * + * FT_LOAD_COLOR :: + * [Since 2.5] Load embedded color bitmap images. The resulting color + * bitmaps, if available, will have the @FT_PIXEL_MODE_BGRA format. + * If the flag is not set and color bitmaps are found, they are + * converted to 256-level gray bitmaps transparently, using the + * @FT_PIXEL_MODE_GRAY format. + * + * FT_LOAD_COMPUTE_METRICS :: + * [Since 2.6.1] Compute glyph metrics from the glyph data, without + * the use of bundled metrics tables (for example, the `hdmx' table in + * TrueType fonts). This flag is mainly used by font validating or + * font editing applications, which need to ignore, verify, or edit + * those tables. + * + * Currently, this flag is only implemented for TrueType fonts. + * + * FT_LOAD_BITMAP_METRICS_ONLY :: + * [Since 2.7.1] Request loading of the metrics and bitmap image + * information of a (possibly embedded) bitmap glyph without + * allocating or copying the bitmap image data itself. No effect if + * the target glyph is not a bitmap image. + * + * This flag unsets @FT_LOAD_RENDER. + * + * FT_LOAD_CROP_BITMAP :: + * Ignored. Deprecated. + * + * FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH :: + * Ignored. Deprecated. + * + * @note: + * By default, hinting is enabled and the font's native hinter (see + * @FT_FACE_FLAG_HINTER) is preferred over the auto-hinter. You can + * disable hinting by setting @FT_LOAD_NO_HINTING or change the + * precedence by setting @FT_LOAD_FORCE_AUTOHINT. You can also set + * @FT_LOAD_NO_AUTOHINT in case you don't want the auto-hinter to be + * used at all. + * + * See the description of @FT_FACE_FLAG_TRICKY for a special exception + * (affecting only a handful of Asian fonts). + * + * Besides deciding which hinter to use, you can also decide which + * hinting algorithm to use. See @FT_LOAD_TARGET_XXX for details. + * + * Note that the auto-hinter needs a valid Unicode cmap (either a native + * one or synthesized by FreeType) for producing correct results. If a + * font provides an incorrect mapping (for example, assigning the + * character code U+005A, LATIN CAPITAL LETTER Z, to a glyph depicting a + * mathematical integral sign), the auto-hinter might produce useless + * results. + * + */ +#define FT_LOAD_DEFAULT 0x0 +#define FT_LOAD_NO_SCALE ( 1L << 0 ) +#define FT_LOAD_NO_HINTING ( 1L << 1 ) +#define FT_LOAD_RENDER ( 1L << 2 ) +#define FT_LOAD_NO_BITMAP ( 1L << 3 ) +#define FT_LOAD_VERTICAL_LAYOUT ( 1L << 4 ) +#define FT_LOAD_FORCE_AUTOHINT ( 1L << 5 ) +#define FT_LOAD_CROP_BITMAP ( 1L << 6 ) +#define FT_LOAD_PEDANTIC ( 1L << 7 ) +#define FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ( 1L << 9 ) +#define FT_LOAD_NO_RECURSE ( 1L << 10 ) +#define FT_LOAD_IGNORE_TRANSFORM ( 1L << 11 ) +#define FT_LOAD_MONOCHROME ( 1L << 12 ) +#define FT_LOAD_LINEAR_DESIGN ( 1L << 13 ) +#define FT_LOAD_NO_AUTOHINT ( 1L << 15 ) + /* Bits 16-19 are used by `FT_LOAD_TARGET_' */ +#define FT_LOAD_COLOR ( 1L << 20 ) +#define FT_LOAD_COMPUTE_METRICS ( 1L << 21 ) +#define FT_LOAD_BITMAP_METRICS_ONLY ( 1L << 22 ) + + /* */ + + /* used internally only by certain font drivers */ +#define FT_LOAD_ADVANCE_ONLY ( 1L << 8 ) +#define FT_LOAD_SBITS_ONLY ( 1L << 14 ) + + + /************************************************************************** + * + * @enum: + * FT_LOAD_TARGET_XXX + * + * @description: + * A list of values to select a specific hinting algorithm for the + * hinter. You should OR one of these values to your `load_flags' + * when calling @FT_Load_Glyph. + * + * Note that a font's native hinters may ignore the hinting algorithm + * you have specified (e.g., the TrueType bytecode interpreter). You + * can set @FT_LOAD_FORCE_AUTOHINT to ensure that the auto-hinter is + * used. + * + * @values: + * FT_LOAD_TARGET_NORMAL :: + * The default hinting algorithm, optimized for standard gray-level + * rendering. For monochrome output, use @FT_LOAD_TARGET_MONO + * instead. + * + * FT_LOAD_TARGET_LIGHT :: + * A lighter hinting algorithm for gray-level modes. Many generated + * glyphs are fuzzier but better resemble their original shape. This + * is achieved by snapping glyphs to the pixel grid only vertically + * (Y-axis), as is done by FreeType's new CFF engine or Microsoft's + * ClearType font renderer. This preserves inter-glyph spacing in + * horizontal text. The snapping is done either by the native font + * driver, if the driver itself and the font support it, or by the + * auto-hinter. + * + * Advance widths are rounded to integer values; however, using the + * `lsb_delta' and `rsb_delta' fields of @FT_GlyphSlotRec, it is + * possible to get fractional advance widths for subpixel positioning + * (which is recommended to use). + * + * If configuration option AF_CONFIG_OPTION_TT_SIZE_METRICS is active, + * TrueType-like metrics are used to make this mode behave similarly + * as in unpatched FreeType versions between 2.4.6 and 2.7.1 + * (inclusive). + * + * FT_LOAD_TARGET_MONO :: + * Strong hinting algorithm that should only be used for monochrome + * output. The result is probably unpleasant if the glyph is rendered + * in non-monochrome modes. + * + * FT_LOAD_TARGET_LCD :: + * A variant of @FT_LOAD_TARGET_LIGHT optimized for horizontally + * decimated LCD displays. + * + * FT_LOAD_TARGET_LCD_V :: + * A variant of @FT_LOAD_TARGET_NORMAL optimized for vertically + * decimated LCD displays. + * + * @note: + * You should use only _one_ of the FT_LOAD_TARGET_XXX values in your + * `load_flags'. They can't be ORed. + * + * If @FT_LOAD_RENDER is also set, the glyph is rendered in the + * corresponding mode (i.e., the mode that matches the used algorithm + * best). An exception is FT_LOAD_TARGET_MONO since it implies + * @FT_LOAD_MONOCHROME. + * + * You can use a hinting algorithm that doesn't correspond to the same + * rendering mode. As an example, it is possible to use the `light' + * hinting algorithm and have the results rendered in horizontal LCD + * pixel mode, with code like + * + * { + * FT_Load_Glyph( face, glyph_index, + * load_flags | FT_LOAD_TARGET_LIGHT ); + * + * FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD ); + * } + * + * In general, you should stick with one rendering mode. For example, + * switching between @FT_LOAD_TARGET_NORMAL and @FT_LOAD_TARGET_MONO + * enforces a lot of recomputation for TrueType fonts, which is slow. + * Another reason is caching: Selecting a different mode usually causes + * changes in both the outlines and the rasterized bitmaps; it is thus + * necessary to empty the cache after a mode switch to avoid false hits. + * + */ +#define FT_LOAD_TARGET_( x ) ( (FT_Int32)( (x) & 15 ) << 16 ) + +#define FT_LOAD_TARGET_NORMAL FT_LOAD_TARGET_( FT_RENDER_MODE_NORMAL ) +#define FT_LOAD_TARGET_LIGHT FT_LOAD_TARGET_( FT_RENDER_MODE_LIGHT ) +#define FT_LOAD_TARGET_MONO FT_LOAD_TARGET_( FT_RENDER_MODE_MONO ) +#define FT_LOAD_TARGET_LCD FT_LOAD_TARGET_( FT_RENDER_MODE_LCD ) +#define FT_LOAD_TARGET_LCD_V FT_LOAD_TARGET_( FT_RENDER_MODE_LCD_V ) + + + /************************************************************************** + * + * @macro: + * FT_LOAD_TARGET_MODE + * + * @description: + * Return the @FT_Render_Mode corresponding to a given + * @FT_LOAD_TARGET_XXX value. + * + */ +#define FT_LOAD_TARGET_MODE( x ) ( (FT_Render_Mode)( ( (x) >> 16 ) & 15 ) ) + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Transform */ + /* */ + /* <Description> */ + /* Set the transformation that is applied to glyph images when they */ + /* are loaded into a glyph slot through @FT_Load_Glyph. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the transformation's 2x2 matrix. Use NULL */ + /* for the identity matrix. */ + /* delta :: A pointer to the translation vector. Use NULL for the */ + /* null vector. */ + /* */ + /* <Note> */ + /* The transformation is only applied to scalable image formats after */ + /* the glyph has been loaded. It means that hinting is unaltered by */ + /* the transformation and is performed on the character size given in */ + /* the last call to @FT_Set_Char_Size or @FT_Set_Pixel_Sizes. */ + /* */ + /* Note that this also transforms the `face.glyph.advance' field, but */ + /* *not* the values in `face.glyph.metrics'. */ + /* */ + FT_EXPORT( void ) + FT_Set_Transform( FT_Face face, + FT_Matrix* matrix, + FT_Vector* delta ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Render_Mode */ + /* */ + /* <Description> */ + /* Render modes supported by FreeType~2. Each mode corresponds to a */ + /* specific type of scanline conversion performed on the outline. */ + /* */ + /* For bitmap fonts and embedded bitmaps the `bitmap->pixel_mode' */ + /* field in the @FT_GlyphSlotRec structure gives the format of the */ + /* returned bitmap. */ + /* */ + /* All modes except @FT_RENDER_MODE_MONO use 256 levels of opacity, */ + /* indicating pixel coverage. Use linear alpha blending and gamma */ + /* correction to correctly render non-monochrome glyph bitmaps onto a */ + /* surface; see @FT_Render_Glyph. */ + /* */ + /* <Values> */ + /* FT_RENDER_MODE_NORMAL :: */ + /* Default render mode; it corresponds to 8-bit anti-aliased */ + /* bitmaps. */ + /* */ + /* FT_RENDER_MODE_LIGHT :: */ + /* This is equivalent to @FT_RENDER_MODE_NORMAL. It is only */ + /* defined as a separate value because render modes are also used */ + /* indirectly to define hinting algorithm selectors. See */ + /* @FT_LOAD_TARGET_XXX for details. */ + /* */ + /* FT_RENDER_MODE_MONO :: */ + /* This mode corresponds to 1-bit bitmaps (with 2~levels of */ + /* opacity). */ + /* */ + /* FT_RENDER_MODE_LCD :: */ + /* This mode corresponds to horizontal RGB and BGR subpixel */ + /* displays like LCD screens. It produces 8-bit bitmaps that are */ + /* 3~times the width of the original glyph outline in pixels, and */ + /* which use the @FT_PIXEL_MODE_LCD mode. */ + /* */ + /* FT_RENDER_MODE_LCD_V :: */ + /* This mode corresponds to vertical RGB and BGR subpixel displays */ + /* (like PDA screens, rotated LCD displays, etc.). It produces */ + /* 8-bit bitmaps that are 3~times the height of the original */ + /* glyph outline in pixels and use the @FT_PIXEL_MODE_LCD_V mode. */ + /* */ + /* <Note> */ + /* Should you define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your */ + /* `ftoption.h', which enables patented ClearType-style rendering, */ + /* the LCD-optimized glyph bitmaps should be filtered to reduce color */ + /* fringes inherent to this technology. You can either set up LCD */ + /* filtering with @FT_Library_SetLcdFilter or @FT_Face_Properties, */ + /* or do the filtering yourself. The default FreeType LCD rendering */ + /* technology does not require filtering. */ + /* */ + /* The selected render mode only affects vector glyphs of a font. */ + /* Embedded bitmaps often have a different pixel mode like */ + /* @FT_PIXEL_MODE_MONO. You can use @FT_Bitmap_Convert to transform */ + /* them into 8-bit pixmaps. */ + /* */ + typedef enum FT_Render_Mode_ + { + FT_RENDER_MODE_NORMAL = 0, + FT_RENDER_MODE_LIGHT, + FT_RENDER_MODE_MONO, + FT_RENDER_MODE_LCD, + FT_RENDER_MODE_LCD_V, + + FT_RENDER_MODE_MAX + + } FT_Render_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Render_Mode' values instead */ +#define ft_render_mode_normal FT_RENDER_MODE_NORMAL +#define ft_render_mode_mono FT_RENDER_MODE_MONO + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Render_Glyph */ + /* */ + /* <Description> */ + /* Convert a given glyph image to a bitmap. It does so by inspecting */ + /* the glyph image format, finding the relevant renderer, and */ + /* invoking it. */ + /* */ + /* <InOut> */ + /* slot :: A handle to the glyph slot containing the image to */ + /* convert. */ + /* */ + /* <Input> */ + /* render_mode :: The render mode used to render the glyph image into */ + /* a bitmap. See @FT_Render_Mode for a list of */ + /* possible values. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* To get meaningful results, font scaling values must be set with */ + /* functions like @FT_Set_Char_Size before calling `FT_Render_Glyph'. */ + /* */ + /* When FreeType outputs a bitmap of a glyph, it really outputs an */ + /* alpha coverage map. If a pixel is completely covered by a */ + /* filled-in outline, the bitmap contains 0xFF at that pixel, meaning */ + /* that 0xFF/0xFF fraction of that pixel is covered, meaning the */ + /* pixel is 100% black (or 0% bright). If a pixel is only 50% */ + /* covered (value 0x80), the pixel is made 50% black (50% bright or a */ + /* middle shade of grey). 0% covered means 0% black (100% bright or */ + /* white). */ + /* */ + /* On high-DPI screens like on smartphones and tablets, the pixels */ + /* are so small that their chance of being completely covered and */ + /* therefore completely black are fairly good. On the low-DPI */ + /* screens, however, the situation is different. The pixels are too */ + /* large for most of the details of a glyph and shades of gray are */ + /* the norm rather than the exception. */ + /* */ + /* This is relevant because all our screens have a second problem: */ + /* they are not linear. 1~+~1 is not~2. Twice the value does not */ + /* result in twice the brightness. When a pixel is only 50% covered, */ + /* the coverage map says 50% black, and this translates to a pixel */ + /* value of 128 when you use 8~bits per channel (0-255). However, */ + /* this does not translate to 50% brightness for that pixel on our */ + /* sRGB and gamma~2.2 screens. Due to their non-linearity, they */ + /* dwell longer in the darks and only a pixel value of about 186 */ + /* results in 50% brightness -- 128 ends up too dark on both bright */ + /* and dark backgrounds. The net result is that dark text looks */ + /* burnt-out, pixely and blotchy on bright background, bright text */ + /* too frail on dark backgrounds, and colored text on colored */ + /* background (for example, red on green) seems to have dark halos or */ + /* `dirt' around it. The situation is especially ugly for diagonal */ + /* stems like in `w' glyph shapes where the quality of FreeType's */ + /* anti-aliasing depends on the correct display of grays. On */ + /* high-DPI screens where smaller, fully black pixels reign supreme, */ + /* this doesn't matter, but on our low-DPI screens with all the gray */ + /* shades, it does. 0% and 100% brightness are the same things in */ + /* linear and non-linear space, just all the shades in-between */ + /* aren't. */ + /* */ + /* The blending function for placing text over a background is */ + /* */ + /* { */ + /* dst = alpha * src + (1 - alpha) * dst , */ + /* } */ + /* */ + /* which is known as the OVER operator. */ + /* */ + /* To correctly composite an antialiased pixel of a glyph onto a */ + /* surface, */ + /* */ + /* 1. take the foreground and background colors (e.g., in sRGB space) */ + /* and apply gamma to get them in a linear space, */ + /* */ + /* 2. use OVER to blend the two linear colors using the glyph pixel */ + /* as the alpha value (remember, the glyph bitmap is an alpha */ + /* coverage bitmap), and */ + /* */ + /* 3. apply inverse gamma to the blended pixel and write it back to */ + /* the image. */ + /* */ + /* Internal testing at Adobe found that a target inverse gamma of~1.8 */ + /* for step~3 gives good results across a wide range of displays with */ + /* an sRGB gamma curve or a similar one. */ + /* */ + /* This process can cost performance. There is an approximation that */ + /* does not need to know about the background color; see */ + /* https://bel.fi/alankila/lcd/ and */ + /* https://bel.fi/alankila/lcd/alpcor.html for details. */ + /* */ + /* *ATTENTION*: Linear blending is even more important when dealing */ + /* with subpixel-rendered glyphs to prevent color-fringing! A */ + /* subpixel-rendered glyph must first be filtered with a filter that */ + /* gives equal weight to the three color primaries and does not */ + /* exceed a sum of 0x100, see section @lcd_filtering. Then the */ + /* only difference to gray linear blending is that subpixel-rendered */ + /* linear blending is done 3~times per pixel: red foreground subpixel */ + /* to red background subpixel and so on for green and blue. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Render_Glyph( FT_GlyphSlot slot, + FT_Render_Mode render_mode ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_Kerning_Mode */ + /* */ + /* <Description> */ + /* An enumeration to specify the format of kerning values returned by */ + /* @FT_Get_Kerning. */ + /* */ + /* <Values> */ + /* FT_KERNING_DEFAULT :: Return grid-fitted kerning distances in */ + /* 26.6 fractional pixels. */ + /* */ + /* FT_KERNING_UNFITTED :: Return un-grid-fitted kerning distances in */ + /* 26.6 fractional pixels. */ + /* */ + /* FT_KERNING_UNSCALED :: Return the kerning vector in original font */ + /* units. */ + /* */ + /* <Note> */ + /* FT_KERNING_DEFAULT returns full pixel values; it also makes */ + /* FreeType heuristically scale down kerning distances at small ppem */ + /* values so that they don't become too big. */ + /* */ + /* Both FT_KERNING_DEFAULT and FT_KERNING_UNFITTED use the current */ + /* horizontal scaling factor (as set e.g. with @FT_Set_Char_Size) to */ + /* convert font units to pixels. */ + /* */ + typedef enum FT_Kerning_Mode_ + { + FT_KERNING_DEFAULT = 0, + FT_KERNING_UNFITTED, + FT_KERNING_UNSCALED + + } FT_Kerning_Mode; + + + /* these constants are deprecated; use the corresponding */ + /* `FT_Kerning_Mode' values instead */ +#define ft_kerning_default FT_KERNING_DEFAULT +#define ft_kerning_unfitted FT_KERNING_UNFITTED +#define ft_kerning_unscaled FT_KERNING_UNSCALED + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Kerning */ + /* */ + /* <Description> */ + /* Return the kerning vector between two glyphs of the same face. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* left_glyph :: The index of the left glyph in the kern pair. */ + /* */ + /* right_glyph :: The index of the right glyph in the kern pair. */ + /* */ + /* kern_mode :: See @FT_Kerning_Mode for more information. */ + /* Determines the scale and dimension of the returned */ + /* kerning vector. */ + /* */ + /* <Output> */ + /* akerning :: The kerning vector. This is either in font units, */ + /* fractional pixels (26.6 format), or pixels for */ + /* scalable formats, and in pixels for fixed-sizes */ + /* formats. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Only horizontal layouts (left-to-right & right-to-left) are */ + /* supported by this method. Other layouts, or more sophisticated */ + /* kernings, are out of the scope of this API function -- they can be */ + /* implemented through format-specific interfaces. */ + /* */ + /* Kerning for OpenType fonts implemented in a `GPOS' table is not */ + /* supported; use @FT_HAS_KERNING to find out whether a font has data */ + /* that can be extracted with `FT_Get_Kerning'. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Kerning( FT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_UInt kern_mode, + FT_Vector *akerning ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Track_Kerning */ + /* */ + /* <Description> */ + /* Return the track kerning for a given face object at a given size. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* point_size :: The point size in 16.16 fractional points. */ + /* */ + /* degree :: The degree of tightness. Increasingly negative */ + /* values represent tighter track kerning, while */ + /* increasingly positive values represent looser track */ + /* kerning. Value zero means no track kerning. */ + /* */ + /* <Output> */ + /* akerning :: The kerning in 16.16 fractional points, to be */ + /* uniformly applied between all glyphs. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* Currently, only the Type~1 font driver supports track kerning, */ + /* using data from AFM files (if attached with @FT_Attach_File or */ + /* @FT_Attach_Stream). */ + /* */ + /* Only very few AFM files come with track kerning data; please refer */ + /* to Adobe's AFM specification for more details. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Track_Kerning( FT_Face face, + FT_Fixed point_size, + FT_Int degree, + FT_Fixed* akerning ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Glyph_Name */ + /* */ + /* <Description> */ + /* Retrieve the ASCII name of a given glyph in a face. This only */ + /* works for those faces where @FT_HAS_GLYPH_NAMES(face) returns~1. */ + /* */ + /* <Input> */ + /* face :: A handle to a source face object. */ + /* */ + /* glyph_index :: The glyph index. */ + /* */ + /* buffer_max :: The maximum number of bytes available in the */ + /* buffer. */ + /* */ + /* <Output> */ + /* buffer :: A pointer to a target buffer where the name is */ + /* copied to. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* An error is returned if the face doesn't provide glyph names or if */ + /* the glyph index is invalid. In all cases of failure, the first */ + /* byte of `buffer' is set to~0 to indicate an empty name. */ + /* */ + /* The glyph name is truncated to fit within the buffer if it is too */ + /* long. The returned string is always zero-terminated. */ + /* */ + /* Be aware that FreeType reorders glyph indices internally so that */ + /* glyph index~0 always corresponds to the `missing glyph' (called */ + /* `.notdef'). */ + /* */ + /* This function always returns an error if the config macro */ + /* `FT_CONFIG_OPTION_NO_GLYPH_NAMES' is not defined in `ftoption.h'. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Get_Glyph_Name( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Postscript_Name */ + /* */ + /* <Description> */ + /* Retrieve the ASCII PostScript name of a given face, if available. */ + /* This only works with PostScript, TrueType, and OpenType fonts. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Return> */ + /* A pointer to the face's PostScript name. NULL if unavailable. */ + /* */ + /* <Note> */ + /* The returned pointer is owned by the face and is destroyed with */ + /* it. */ + /* */ + /* For variation fonts, this string changes if you select a different */ + /* instance, and you have to call `FT_Get_PostScript_Name' again to */ + /* retrieve it. FreeType follows Adobe TechNote #5902, `Generating */ + /* PostScript Names for Fonts Using OpenType Font Variations'. */ + /* */ + /* https://download.macromedia.com/pub/developer/opentype/tech-notes/5902.AdobePSNameGeneration.html */ + /* */ + /* [Since 2.9] Special PostScript names for named instances are only */ + /* returned if the named instance is set with @FT_Set_Named_Instance */ + /* (and the font has corresponding entries in its `fvar' table). If */ + /* @FT_IS_VARIATION returns true, the algorithmically derived */ + /* PostScript name is provided, not looking up special entries for */ + /* named instances. */ + /* */ + FT_EXPORT( const char* ) + FT_Get_Postscript_Name( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Select_Charmap */ + /* */ + /* <Description> */ + /* Select a given charmap by its encoding tag (as listed in */ + /* `freetype.h'). */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* encoding :: A handle to the selected encoding. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function returns an error if no charmap in the face */ + /* corresponds to the encoding queried here. */ + /* */ + /* Because many fonts contain more than a single cmap for Unicode */ + /* encoding, this function has some special code to select the one */ + /* that covers Unicode best (`best' in the sense that a UCS-4 cmap is */ + /* preferred to a UCS-2 cmap). It is thus preferable to */ + /* @FT_Set_Charmap in this case. */ + /* */ + FT_EXPORT( FT_Error ) + FT_Select_Charmap( FT_Face face, + FT_Encoding encoding ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Set_Charmap */ + /* */ + /* <Description> */ + /* Select a given charmap for character code to glyph index mapping. */ + /* */ + /* <InOut> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Input> */ + /* charmap :: A handle to the selected charmap. */ + /* */ + /* <Return> */ + /* FreeType error code. 0~means success. */ + /* */ + /* <Note> */ + /* This function returns an error if the charmap is not part of */ + /* the face (i.e., if it is not listed in the `face->charmaps' */ + /* table). */ + /* */ + /* It also fails if an OpenType type~14 charmap is selected (which */ + /* doesn't map character codes to glyph indices at all). */ + /* */ + FT_EXPORT( FT_Error ) + FT_Set_Charmap( FT_Face face, + FT_CharMap charmap ); + + + /************************************************************************* + * + * @function: + * FT_Get_Charmap_Index + * + * @description: + * Retrieve index of a given charmap. + * + * @input: + * charmap :: + * A handle to a charmap. + * + * @return: + * The index into the array of character maps within the face to which + * `charmap' belongs. If an error occurs, -1 is returned. + * + */ + FT_EXPORT( FT_Int ) + FT_Get_Charmap_Index( FT_CharMap charmap ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Char_Index */ + /* */ + /* <Description> */ + /* Return the glyph index of a given character code. This function */ + /* uses the currently selected charmap to do the mapping. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* charcode :: The character code. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means `undefined character code'. */ + /* */ + /* <Note> */ + /* If you use FreeType to manipulate the contents of font files */ + /* directly, be aware that the glyph index returned by this function */ + /* doesn't always correspond to the internal indices used within the */ + /* file. This is done to ensure that value~0 always corresponds to */ + /* the `missing glyph'. If the first glyph is not named `.notdef', */ + /* then for Type~1 and Type~42 fonts, `.notdef' will be moved into */ + /* the glyph ID~0 position, and whatever was there will be moved to */ + /* the position `.notdef' had. For Type~1 fonts, if there is no */ + /* `.notdef' glyph at all, then one will be created at index~0 and */ + /* whatever was there will be moved to the last index -- Type~42 */ + /* fonts are considered invalid under this condition. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Char_Index( FT_Face face, + FT_ULong charcode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_First_Char */ + /* */ + /* <Description> */ + /* Return the first character code in the current charmap of a given */ + /* face, together with its corresponding glyph index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Output> */ + /* agindex :: Glyph index of first character code. 0~if charmap is */ + /* empty. */ + /* */ + /* <Return> */ + /* The charmap's first character code. */ + /* */ + /* <Note> */ + /* You should use this function together with @FT_Get_Next_Char to */ + /* parse all character codes available in a given charmap. The code */ + /* should look like this: */ + /* */ + /* { */ + /* FT_ULong charcode; */ + /* FT_UInt gindex; */ + /* */ + /* */ + /* charcode = FT_Get_First_Char( face, &gindex ); */ + /* while ( gindex != 0 ) */ + /* { */ + /* ... do something with (charcode,gindex) pair ... */ + /* */ + /* charcode = FT_Get_Next_Char( face, charcode, &gindex ); */ + /* } */ + /* } */ + /* */ + /* Be aware that character codes can have values up to 0xFFFFFFFF; */ + /* this might happen for non-Unicode or malformed cmaps. However, */ + /* even with regular Unicode encoding, so-called `last resort fonts' */ + /* (using SFNT cmap format 13, see function @FT_Get_CMap_Format) */ + /* normally have entries for all Unicode characters up to 0x1FFFFF, */ + /* which can cause *a lot* of iterations. */ + /* */ + /* Note that `*agindex' is set to~0 if the charmap is empty. The */ + /* result itself can be~0 in two cases: if the charmap is empty or */ + /* if the value~0 is the first valid character code. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_First_Char( FT_Face face, + FT_UInt *agindex ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Next_Char */ + /* */ + /* <Description> */ + /* Return the next character code in the current charmap of a given */ + /* face following the value `char_code', as well as the corresponding */ + /* glyph index. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* char_code :: The starting character code. */ + /* */ + /* <Output> */ + /* agindex :: Glyph index of next character code. 0~if charmap */ + /* is empty. */ + /* */ + /* <Return> */ + /* The charmap's next character code. */ + /* */ + /* <Note> */ + /* You should use this function with @FT_Get_First_Char to walk */ + /* over all character codes available in a given charmap. See the */ + /* note for that function for a simple code example. */ + /* */ + /* Note that `*agindex' is set to~0 when there are no more codes in */ + /* the charmap. */ + /* */ + FT_EXPORT( FT_ULong ) + FT_Get_Next_Char( FT_Face face, + FT_ULong char_code, + FT_UInt *agindex ); + + + /************************************************************************* + * + * @function: + * FT_Face_Properties + * + * @description: + * Set or override certain (library or module-wide) properties on a + * face-by-face basis. Useful for finer-grained control and avoiding + * locks on shared structures (threads can modify their own faces as + * they see fit). + * + * Contrary to @FT_Property_Set, this function uses @FT_Parameter so + * that you can pass multiple properties to the target face in one call. + * Note that only a subset of the available properties can be + * controlled. + * + * * @FT_PARAM_TAG_STEM_DARKENING (stem darkening, corresponding to the + * property `no-stem-darkening' provided by the `autofit', `cff', + * `type1', and `t1cid' modules; see @no-stem-darkening). + * + * * @FT_PARAM_TAG_LCD_FILTER_WEIGHTS (LCD filter weights, corresponding + * to function @FT_Library_SetLcdFilterWeights). + * + * * @FT_PARAM_TAG_RANDOM_SEED (seed value for the CFF, Type~1, and CID + * `random' operator, corresponding to the `random-seed' property + * provided by the `cff', `type1', and `t1cid' modules; see + * @random-seed). + * + * Pass NULL as `data' in @FT_Parameter for a given tag to reset the + * option and use the library or module default again. + * + * @input: + * face :: + * A handle to the source face object. + * + * num_properties :: + * The number of properties that follow. + * + * properties :: + * A handle to an @FT_Parameter array with `num_properties' elements. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Here an example that sets three properties. You must define + * FT_CONFIG_OPTION_SUBPIXEL_RENDERING to make the LCD filter examples + * work. + * + * { + * FT_Parameter property1; + * FT_Bool darken_stems = 1; + * + * FT_Parameter property2; + * FT_LcdFiveTapFilter custom_weight = + * { 0x11, 0x44, 0x56, 0x44, 0x11 }; + * + * FT_Parameter property3; + * FT_Int32 random_seed = 314159265; + * + * FT_Parameter properties[3] = { property1, + * property2, + * property3 }; + * + * + * property1.tag = FT_PARAM_TAG_STEM_DARKENING; + * property1.data = &darken_stems; + * + * property2.tag = FT_PARAM_TAG_LCD_FILTER_WEIGHTS; + * property2.data = custom_weight; + * + * property3.tag = FT_PARAM_TAG_RANDOM_SEED; + * property3.data = &random_seed; + * + * FT_Face_Properties( face, 3, properties ); + * } + * + * The next example resets a single property to its default value. + * + * { + * FT_Parameter property; + * + * + * property.tag = FT_PARAM_TAG_LCD_FILTER_WEIGHTS; + * property.data = NULL; + * + * FT_Face_Properties( face, 1, &property ); + * } + * + * @since: + * 2.8 + * + */ + FT_EXPORT( FT_Error ) + FT_Face_Properties( FT_Face face, + FT_UInt num_properties, + FT_Parameter* properties ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_Name_Index */ + /* */ + /* <Description> */ + /* Return the glyph index of a given glyph name. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* glyph_name :: The glyph name. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means `undefined character code'. */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Get_Name_Index( FT_Face face, + FT_String* glyph_name ); + + + /************************************************************************* + * + * @macro: + * FT_SUBGLYPH_FLAG_XXX + * + * @description: + * A list of constants describing subglyphs. Please refer to the + * `glyf' table description in the OpenType specification for the + * meaning of the various flags (which get synthesized for + * non-OpenType subglyphs). + * + * @values: + * FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS :: + * FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES :: + * FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID :: + * FT_SUBGLYPH_FLAG_SCALE :: + * FT_SUBGLYPH_FLAG_XY_SCALE :: + * FT_SUBGLYPH_FLAG_2X2 :: + * FT_SUBGLYPH_FLAG_USE_MY_METRICS :: + * + */ +#define FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS 1 +#define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES 2 +#define FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID 4 +#define FT_SUBGLYPH_FLAG_SCALE 8 +#define FT_SUBGLYPH_FLAG_XY_SCALE 0x40 +#define FT_SUBGLYPH_FLAG_2X2 0x80 +#define FT_SUBGLYPH_FLAG_USE_MY_METRICS 0x200 + + + /************************************************************************* + * + * @func: + * FT_Get_SubGlyph_Info + * + * @description: + * Retrieve a description of a given subglyph. Only use it if + * `glyph->format' is @FT_GLYPH_FORMAT_COMPOSITE; an error is + * returned otherwise. + * + * @input: + * glyph :: + * The source glyph slot. + * + * sub_index :: + * The index of the subglyph. Must be less than + * `glyph->num_subglyphs'. + * + * @output: + * p_index :: + * The glyph index of the subglyph. + * + * p_flags :: + * The subglyph flags, see @FT_SUBGLYPH_FLAG_XXX. + * + * p_arg1 :: + * The subglyph's first argument (if any). + * + * p_arg2 :: + * The subglyph's second argument (if any). + * + * p_transform :: + * The subglyph transformation (if any). + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * The values of `*p_arg1', `*p_arg2', and `*p_transform' must be + * interpreted depending on the flags returned in `*p_flags'. See the + * OpenType specification for details. + * + */ + FT_EXPORT( FT_Error ) + FT_Get_SubGlyph_Info( FT_GlyphSlot glyph, + FT_UInt sub_index, + FT_Int *p_index, + FT_UInt *p_flags, + FT_Int *p_arg1, + FT_Int *p_arg2, + FT_Matrix *p_transform ); + + + /*************************************************************************/ + /* */ + /* <Enum> */ + /* FT_FSTYPE_XXX */ + /* */ + /* <Description> */ + /* A list of bit flags used in the `fsType' field of the OS/2 table */ + /* in a TrueType or OpenType font and the `FSType' entry in a */ + /* PostScript font. These bit flags are returned by */ + /* @FT_Get_FSType_Flags; they inform client applications of embedding */ + /* and subsetting restrictions associated with a font. */ + /* */ + /* See */ + /* https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/FontPolicies.pdf */ + /* for more details. */ + /* */ + /* <Values> */ + /* FT_FSTYPE_INSTALLABLE_EMBEDDING :: */ + /* Fonts with no fsType bit set may be embedded and permanently */ + /* installed on the remote system by an application. */ + /* */ + /* FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING :: */ + /* Fonts that have only this bit set must not be modified, embedded */ + /* or exchanged in any manner without first obtaining permission of */ + /* the font software copyright owner. */ + /* */ + /* FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING :: */ + /* The font may be embedded and temporarily loaded on the remote */ + /* system. Documents containing Preview & Print fonts must be */ + /* opened `read-only'; no edits can be applied to the document. */ + /* */ + /* FT_FSTYPE_EDITABLE_EMBEDDING :: */ + /* The font may be embedded but must only be installed temporarily */ + /* on other systems. In contrast to Preview & Print fonts, */ + /* documents containing editable fonts may be opened for reading, */ + /* editing is permitted, and changes may be saved. */ + /* */ + /* FT_FSTYPE_NO_SUBSETTING :: */ + /* The font may not be subsetted prior to embedding. */ + /* */ + /* FT_FSTYPE_BITMAP_EMBEDDING_ONLY :: */ + /* Only bitmaps contained in the font may be embedded; no outline */ + /* data may be embedded. If there are no bitmaps available in the */ + /* font, then the font is unembeddable. */ + /* */ + /* <Note> */ + /* The flags are ORed together, thus more than a single value can be */ + /* returned. */ + /* */ + /* While the `fsType' flags can indicate that a font may be embedded, */ + /* a license with the font vendor may be separately required to use */ + /* the font in this way. */ + /* */ +#define FT_FSTYPE_INSTALLABLE_EMBEDDING 0x0000 +#define FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING 0x0002 +#define FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING 0x0004 +#define FT_FSTYPE_EDITABLE_EMBEDDING 0x0008 +#define FT_FSTYPE_NO_SUBSETTING 0x0100 +#define FT_FSTYPE_BITMAP_EMBEDDING_ONLY 0x0200 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Get_FSType_Flags */ + /* */ + /* <Description> */ + /* Return the `fsType' flags for a font. */ + /* */ + /* <Input> */ + /* face :: A handle to the source face object. */ + /* */ + /* <Return> */ + /* The `fsType' flags, see @FT_FSTYPE_XXX. */ + /* */ + /* <Note> */ + /* Use this function rather than directly reading the `fs_type' field */ + /* in the @PS_FontInfoRec structure, which is only guaranteed to */ + /* return the correct results for Type~1 fonts. */ + /* */ + /* <Since> */ + /* 2.3.8 */ + /* */ + FT_EXPORT( FT_UShort ) + FT_Get_FSType_Flags( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* glyph_variants */ + /* */ + /* <Title> */ + /* Unicode Variation Sequences */ + /* */ + /* <Abstract> */ + /* The FreeType~2 interface to Unicode Variation Sequences (UVS), */ + /* using the SFNT cmap format~14. */ + /* */ + /* <Description> */ + /* Many characters, especially for CJK scripts, have variant forms. */ + /* They are a sort of grey area somewhere between being totally */ + /* irrelevant and semantically distinct; for this reason, the Unicode */ + /* consortium decided to introduce Variation Sequences (VS), */ + /* consisting of a Unicode base character and a variation selector */ + /* instead of further extending the already huge number of */ + /* characters. */ + /* */ + /* Unicode maintains two different sets, namely `Standardized */ + /* Variation Sequences' and registered `Ideographic Variation */ + /* Sequences' (IVS), collected in the `Ideographic Variation */ + /* Database' (IVD). */ + /* */ + /* https://unicode.org/Public/UCD/latest/ucd/StandardizedVariants.txt */ + /* https://unicode.org/reports/tr37/ */ + /* https://unicode.org/ivd/ */ + /* */ + /* To date (January 2017), the character with the most ideographic */ + /* variations is U+9089, having 32 such IVS. */ + /* */ + /* Three Mongolian Variation Selectors have the values U+180B-U+180D; */ + /* 256 generic Variation Selectors are encoded in the ranges */ + /* U+FE00-U+FE0F and U+E0100-U+E01EF. IVS currently use Variation */ + /* Selectors from the range U+E0100-U+E01EF only. */ + /* */ + /* A VS consists of the base character value followed by a single */ + /* Variation Selector. For example, to get the first variation of */ + /* U+9089, you have to write the character sequence `U+9089 U+E0100'. */ + /* */ + /* Adobe and MS decided to support both standardized and ideographic */ + /* VS with a new cmap subtable (format~14). It is an odd subtable */ + /* because it is not a mapping of input code points to glyphs, but */ + /* contains lists of all variations supported by the font. */ + /* */ + /* A variation may be either `default' or `non-default' for a given */ + /* font. A default variation is the one you will get for that code */ + /* point if you look it up in the standard Unicode cmap. A */ + /* non-default variation is a different glyph. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharVariantIndex */ + /* */ + /* <Description> */ + /* Return the glyph index of a given character code as modified by */ + /* the variation selector. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character code point in Unicode. */ + /* */ + /* variantSelector :: */ + /* The Unicode code point of the variation selector. */ + /* */ + /* <Return> */ + /* The glyph index. 0~means either `undefined character code', or */ + /* `undefined selector code', or `no variation selector cmap */ + /* subtable', or `current CharMap is not Unicode'. */ + /* */ + /* <Note> */ + /* If you use FreeType to manipulate the contents of font files */ + /* directly, be aware that the glyph index returned by this function */ + /* doesn't always correspond to the internal indices used within */ + /* the file. This is done to ensure that value~0 always corresponds */ + /* to the `missing glyph'. */ + /* */ + /* This function is only meaningful if */ + /* a) the font has a variation selector cmap sub table, */ + /* and */ + /* b) the current charmap has a Unicode encoding. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt ) + FT_Face_GetCharVariantIndex( FT_Face face, + FT_ULong charcode, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharVariantIsDefault */ + /* */ + /* <Description> */ + /* Check whether this variation of this Unicode character is the one */ + /* to be found in the `cmap'. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character codepoint in Unicode. */ + /* */ + /* variantSelector :: */ + /* The Unicode codepoint of the variation selector. */ + /* */ + /* <Return> */ + /* 1~if found in the standard (Unicode) cmap, 0~if found in the */ + /* variation selector cmap, or -1 if it is not a variation. */ + /* */ + /* <Note> */ + /* This function is only meaningful if the font has a variation */ + /* selector cmap subtable. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_Int ) + FT_Face_GetCharVariantIsDefault( FT_Face face, + FT_ULong charcode, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetVariantSelectors */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode variation selectors found */ + /* in the font. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* <Return> */ + /* A pointer to an array of selector code points, or NULL if there is */ + /* no valid variation selector cmap subtable. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetVariantSelectors( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetVariantsOfChar */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode variation selectors found */ + /* for the specified character code. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* charcode :: */ + /* The character codepoint in Unicode. */ + /* */ + /* <Return> */ + /* A pointer to an array of variation selector code points that are */ + /* active for the given character, or NULL if the corresponding list */ + /* is empty. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetVariantsOfChar( FT_Face face, + FT_ULong charcode ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_GetCharsOfVariant */ + /* */ + /* <Description> */ + /* Return a zero-terminated list of Unicode character codes found for */ + /* the specified variation selector. */ + /* */ + /* <Input> */ + /* face :: */ + /* A handle to the source face object. */ + /* */ + /* variantSelector :: */ + /* The variation selector code point in Unicode. */ + /* */ + /* <Return> */ + /* A list of all the code points that are specified by this selector */ + /* (both default and non-default codes are returned) or NULL if there */ + /* is no valid cmap or the variation selector is invalid. */ + /* */ + /* <Note> */ + /* The last item in the array is~0; the array is owned by the */ + /* @FT_Face object but can be overwritten or released on the next */ + /* call to a FreeType function. */ + /* */ + /* <Since> */ + /* 2.3.6 */ + /* */ + FT_EXPORT( FT_UInt32* ) + FT_Face_GetCharsOfVariant( FT_Face face, + FT_ULong variantSelector ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* computations */ + /* */ + /* <Title> */ + /* Computations */ + /* */ + /* <Abstract> */ + /* Crunching fixed numbers and vectors. */ + /* */ + /* <Description> */ + /* This section contains various functions used to perform */ + /* computations on 16.16 fixed-float numbers or 2d vectors. */ + /* */ + /* <Order> */ + /* FT_MulDiv */ + /* FT_MulFix */ + /* FT_DivFix */ + /* FT_RoundFix */ + /* FT_CeilFix */ + /* FT_FloorFix */ + /* FT_Vector_Transform */ + /* FT_Matrix_Multiply */ + /* FT_Matrix_Invert */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_MulDiv */ + /* */ + /* <Description> */ + /* Compute `(a*b)/c' with maximum accuracy, using a 64-bit */ + /* intermediate integer whenever necessary. */ + /* */ + /* This function isn't necessarily as fast as some processor specific */ + /* operations, but is at least completely portable. */ + /* */ + /* <Input> */ + /* a :: The first multiplier. */ + /* */ + /* b :: The second multiplier. */ + /* */ + /* c :: The divisor. */ + /* */ + /* <Return> */ + /* The result of `(a*b)/c'. This function never traps when trying to */ + /* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ + /* on the signs of `a' and `b'. */ + /* */ + FT_EXPORT( FT_Long ) + FT_MulDiv( FT_Long a, + FT_Long b, + FT_Long c ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_MulFix */ + /* */ + /* <Description> */ + /* Compute `(a*b)/0x10000' with maximum accuracy. Its main use is to */ + /* multiply a given value by a 16.16 fixed-point factor. */ + /* */ + /* <Input> */ + /* a :: The first multiplier. */ + /* */ + /* b :: The second multiplier. Use a 16.16 factor here whenever */ + /* possible (see note below). */ + /* */ + /* <Return> */ + /* The result of `(a*b)/0x10000'. */ + /* */ + /* <Note> */ + /* This function has been optimized for the case where the absolute */ + /* value of `a' is less than 2048, and `b' is a 16.16 scaling factor. */ + /* As this happens mainly when scaling from notional units to */ + /* fractional pixels in FreeType, it resulted in noticeable speed */ + /* improvements between versions 2.x and 1.x. */ + /* */ + /* As a conclusion, always try to place a 16.16 factor as the */ + /* _second_ argument of this function; this can make a great */ + /* difference. */ + /* */ + FT_EXPORT( FT_Long ) + FT_MulFix( FT_Long a, + FT_Long b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_DivFix */ + /* */ + /* <Description> */ + /* Compute `(a*0x10000)/b' with maximum accuracy. Its main use is to */ + /* divide a given value by a 16.16 fixed-point factor. */ + /* */ + /* <Input> */ + /* a :: The numerator. */ + /* */ + /* b :: The denominator. Use a 16.16 factor here. */ + /* */ + /* <Return> */ + /* The result of `(a*0x10000)/b'. */ + /* */ + FT_EXPORT( FT_Long ) + FT_DivFix( FT_Long a, + FT_Long b ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_RoundFix */ + /* */ + /* <Description> */ + /* Round a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number to be rounded. */ + /* */ + /* <Return> */ + /* `a' rounded to the nearest 16.16 fixed integer, halfway cases away */ + /* from zero. */ + /* */ + /* <Note> */ + /* The function uses wrap-around arithmetic. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_RoundFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_CeilFix */ + /* */ + /* <Description> */ + /* Compute the smallest following integer of a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number for which the ceiling function is to be computed. */ + /* */ + /* <Return> */ + /* `a' rounded towards plus infinity. */ + /* */ + /* <Note> */ + /* The function uses wrap-around arithmetic. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_CeilFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_FloorFix */ + /* */ + /* <Description> */ + /* Compute the largest previous integer of a 16.16 fixed number. */ + /* */ + /* <Input> */ + /* a :: The number for which the floor function is to be computed. */ + /* */ + /* <Return> */ + /* `a' rounded towards minus infinity. */ + /* */ + FT_EXPORT( FT_Fixed ) + FT_FloorFix( FT_Fixed a ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Vector_Transform */ + /* */ + /* <Description> */ + /* Transform a single vector through a 2x2 matrix. */ + /* */ + /* <InOut> */ + /* vector :: The target vector to transform. */ + /* */ + /* <Input> */ + /* matrix :: A pointer to the source 2x2 matrix. */ + /* */ + /* <Note> */ + /* The result is undefined if either `vector' or `matrix' is invalid. */ + /* */ + FT_EXPORT( void ) + FT_Vector_Transform( FT_Vector* vec, + const FT_Matrix* matrix ); + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* version */ + /* */ + /* <Title> */ + /* FreeType Version */ + /* */ + /* <Abstract> */ + /* Functions and macros related to FreeType versions. */ + /* */ + /* <Description> */ + /* Note that those functions and macros are of limited use because */ + /* even a new release of FreeType with only documentation changes */ + /* increases the version number. */ + /* */ + /* <Order> */ + /* FT_Library_Version */ + /* */ + /* FREETYPE_MAJOR */ + /* FREETYPE_MINOR */ + /* FREETYPE_PATCH */ + /* */ + /* FT_Face_CheckTrueTypePatents */ + /* FT_Face_SetUnpatentedHinting */ + /* */ + /* FREETYPE_XXX */ + /* */ + /*************************************************************************/ + + + /************************************************************************* + * + * @enum: + * FREETYPE_XXX + * + * @description: + * These three macros identify the FreeType source code version. + * Use @FT_Library_Version to access them at runtime. + * + * @values: + * FREETYPE_MAJOR :: The major version number. + * FREETYPE_MINOR :: The minor version number. + * FREETYPE_PATCH :: The patch level. + * + * @note: + * The version number of FreeType if built as a dynamic link library + * with the `libtool' package is _not_ controlled by these three + * macros. + * + */ +#define FREETYPE_MAJOR 2 +#define FREETYPE_MINOR 9 +#define FREETYPE_PATCH 1 + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Library_Version */ + /* */ + /* <Description> */ + /* Return the version of the FreeType library being used. This is */ + /* useful when dynamically linking to the library, since one cannot */ + /* use the macros @FREETYPE_MAJOR, @FREETYPE_MINOR, and */ + /* @FREETYPE_PATCH. */ + /* */ + /* <Input> */ + /* library :: A source library handle. */ + /* */ + /* <Output> */ + /* amajor :: The major version number. */ + /* */ + /* aminor :: The minor version number. */ + /* */ + /* apatch :: The patch version number. */ + /* */ + /* <Note> */ + /* The reason why this function takes a `library' argument is because */ + /* certain programs implement library initialization in a custom way */ + /* that doesn't use @FT_Init_FreeType. */ + /* */ + /* In such cases, the library version might not be available before */ + /* the library object has been created. */ + /* */ + FT_EXPORT( void ) + FT_Library_Version( FT_Library library, + FT_Int *amajor, + FT_Int *aminor, + FT_Int *apatch ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_CheckTrueTypePatents */ + /* */ + /* <Description> */ + /* Deprecated, does nothing. */ + /* */ + /* <Input> */ + /* face :: A face handle. */ + /* */ + /* <Return> */ + /* Always returns false. */ + /* */ + /* <Note> */ + /* Since May 2010, TrueType hinting is no longer patented. */ + /* */ + /* <Since> */ + /* 2.3.5 */ + /* */ + FT_EXPORT( FT_Bool ) + FT_Face_CheckTrueTypePatents( FT_Face face ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_Face_SetUnpatentedHinting */ + /* */ + /* <Description> */ + /* Deprecated, does nothing. */ + /* */ + /* <Input> */ + /* face :: A face handle. */ + /* */ + /* value :: New boolean setting. */ + /* */ + /* <Return> */ + /* Always returns false. */ + /* */ + /* <Note> */ + /* Since May 2010, TrueType hinting is no longer patented. */ + /* */ + /* <Since> */ + /* 2.3.5 */ + /* */ + FT_EXPORT( FT_Bool ) + FT_Face_SetUnpatentedHinting( FT_Face face, + FT_Bool value ); + + /* */ + + +FT_END_HEADER + +#endif /* FREETYPE_H_ */ + + +/* END */ diff --git a/src/ft2build.h b/src/ft2build.h new file mode 100644 index 0000000..5356a55 --- /dev/null +++ b/src/ft2build.h @@ -0,0 +1,42 @@ +/***************************************************************************/ +/* */ +/* ft2build.h */ +/* */ +/* FreeType 2 build and setup macros. */ +/* */ +/* Copyright 1996-2018 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* This is the `entry point' for FreeType header file inclusions. It is */ + /* the only header file which should be included directly; all other */ + /* FreeType header files should be accessed with macro names (after */ + /* including `ft2build.h'). */ + /* */ + /* A typical example is */ + /* */ + /* #include <ft2build.h> */ + /* #include FT_FREETYPE_H */ + /* */ + /*************************************************************************/ + +#pragma once +#ifndef FT2BUILD_H_ +#define FT2BUILD_H_ +#include "define_inc.h" +#include <freetype/config/ftheader.h> + +#endif /* FT2BUILD_H_ */ + + +/* END */ diff --git a/src/gemm.c b/src/gemm.c new file mode 100644 index 0000000..6960e37 --- /dev/null +++ b/src/gemm.c @@ -0,0 +1,333 @@ +#include "gemm.h" +#include "utils.h" +#include "cuda.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> + +void gemm_bin(int M, int N, int K, float ALPHA, + char *A, int lda, + float *B, int ldb, + float *C, int ldc) +{ + int i,j,k; + for(i = 0; i < M; ++i){ + for(k = 0; k < K; ++k){ + char A_PART = A[i*lda+k]; + if(A_PART){ + for(j = 0; j < N; ++j){ + C[i*ldc+j] += B[k*ldb+j]; + } + } else { + for(j = 0; j < N; ++j){ + C[i*ldc+j] -= B[k*ldb+j]; + } + } + } + } +} + +float *random_matrix(int rows, int cols) +{ + int i; + float *m = calloc(rows*cols, sizeof(float)); + for(i = 0; i < rows*cols; ++i){ + m[i] = (float)rand()/RAND_MAX; + } + return m; +} + +void time_random_matrix(int TA, int TB, int m, int k, int n) +{ + float *a; + if(!TA) a = random_matrix(m,k); + else a = random_matrix(k,m); + int lda = (!TA)?k:m; + float *b; + if(!TB) b = random_matrix(k,n); + else b = random_matrix(n,k); + int ldb = (!TB)?n:k; + + float *c = random_matrix(m,n); + int i; + clock_t start = clock(), end; + for(i = 0; i<10; ++i){ + gemm_cpu(TA,TB,m,n,k,1,a,lda,b,ldb,1,c,n); + } + end = clock(); + printf("Matrix Multiplication %dx%d * %dx%d, TA=%d, TB=%d: %lf ms\n",m,k,k,n, TA, TB, (float)(end-start)/CLOCKS_PER_SEC); + if (a) { + free(a); + a = NULL; + } + if (b) { + free(b); + b = NULL; + } + if (c) { + free(c); + c = NULL; + } +} + + +void gemm(int TA, int TB, int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float BETA, + float *C, int ldc) +{ + gemm_cpu( TA, TB, M, N, K, ALPHA,A,lda, B, ldb,BETA,C,ldc); +} + +void gemm_nn(int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float *C, int ldc) +{ + int i,j,k; + #pragma omp parallel for + for(i = 0; i < M; ++i){ + for(k = 0; k < K; ++k){ + register float A_PART = ALPHA*A[i*lda+k]; + for(j = 0; j < N; ++j){ + C[i*ldc+j] += A_PART*B[k*ldb+j]; + } + } + } +} + +void gemm_nt(int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float *C, int ldc) +{ + int i,j,k; + #pragma omp parallel for + for(i = 0; i < M; ++i){ + for(j = 0; j < N; ++j){ + register float sum = 0; + for(k = 0; k < K; ++k){ + sum += ALPHA*A[i*lda+k]*B[j*ldb + k]; + } + C[i*ldc+j] += sum; + } + } +} + +void gemm_tn(int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float *C, int ldc) +{ + int i,j,k; + #pragma omp parallel for + for(i = 0; i < M; ++i){ + for(k = 0; k < K; ++k){ + register float A_PART = ALPHA*A[k*lda+i]; + for(j = 0; j < N; ++j){ + C[i*ldc+j] += A_PART*B[k*ldb+j]; + } + } + } +} + +void gemm_tt(int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float *C, int ldc) +{ + int i,j,k; + #pragma omp parallel for + for(i = 0; i < M; ++i){ + for(j = 0; j < N; ++j){ + register float sum = 0; + for(k = 0; k < K; ++k){ + sum += ALPHA*A[i+k*lda]*B[k+j*ldb]; + } + C[i*ldc+j] += sum; + } + } +} + + +void gemm_cpu(int TA, int TB, int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float BETA, + float *C, int ldc) +{ + //printf("cpu: %d %d %d %d %d %f %d %d %f %d\n",TA, TB, M, N, K, ALPHA, lda, ldb, BETA, ldc); + int i, j; + for(i = 0; i < M; ++i){ + for(j = 0; j < N; ++j){ + C[i*ldc + j] *= BETA; + } + } + if(!TA && !TB) + gemm_nn(M, N, K, ALPHA,A,lda, B, ldb,C,ldc); + else if(TA && !TB) + gemm_tn(M, N, K, ALPHA,A,lda, B, ldb,C,ldc); + else if(!TA && TB) + gemm_nt(M, N, K, ALPHA,A,lda, B, ldb,C,ldc); + else + gemm_tt(M, N, K, ALPHA,A,lda, B, ldb,C,ldc); +} + +#ifdef GPU + +#include <math.h> + +void gemm_gpu(int TA, int TB, int M, int N, int K, float ALPHA, + float *A_gpu, int lda, + float *B_gpu, int ldb, + float BETA, + float *C_gpu, int ldc) +{ + cublasHandle_t handle = blas_handle(); + cudaError_t status = cublasSgemm(handle, (TB ? CUBLAS_OP_T : CUBLAS_OP_N), + (TA ? CUBLAS_OP_T : CUBLAS_OP_N), N, M, K, &ALPHA, B_gpu, ldb, A_gpu, lda, &BETA, C_gpu, ldc); + check_error(status); +} + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +void time_gpu_random_matrix(int TA, int TB, int m, int k, int n) +{ + float *a; + if(!TA) a = random_matrix(m,k); + else a = random_matrix(k,m); + int lda = (!TA)?k:m; + float *b; + if(!TB) b = random_matrix(k,n); + else b = random_matrix(n,k); + int ldb = (!TB)?n:k; + + float *c = random_matrix(m,n); + int i; + clock_t start = clock(), end; + for(i = 0; i<32; ++i){ + gemm_gpu(TA,TB,m,n,k,1,a,lda,b,ldb,1,c,n); + } + end = clock(); + printf("Matrix Multiplication %dx%d * %dx%d, TA=%d, TB=%d: %lf s\n",m,k,k,n, TA, TB, (float)(end-start)/CLOCKS_PER_SEC); + free(a); + free(b); + free(c); +} + +void time_gpu(int TA, int TB, int m, int k, int n) +{ + int iter = 10; + float *a = random_matrix(m,k); + float *b = random_matrix(k,n); + + int lda = (!TA)?k:m; + int ldb = (!TB)?n:k; + + float *c = random_matrix(m,n); + + float *a_cl = cuda_make_array(a, m*k); + float *b_cl = cuda_make_array(b, k*n); + float *c_cl = cuda_make_array(c, m*n); + + int i; + clock_t start = clock(), end; + for(i = 0; i<iter; ++i){ + gemm_gpu(TA,TB,m,n,k,1,a_cl,lda,b_cl,ldb,1,c_cl,n); + cudaThreadSynchronize(); + } + double flop = ((double)m)*n*(2.*k + 2.)*iter; + double gflop = flop/pow(10., 9); + end = clock(); + double seconds = sec(end-start); + printf("Matrix Multiplication %dx%d * %dx%d, TA=%d, TB=%d: %lf s, %lf GFLOPS\n",m,k,k,n, TA, TB, seconds, gflop/seconds); + cuda_free(a_cl); + cuda_free(b_cl); + cuda_free(c_cl); + free(a); + free(b); + free(c); +} + + +void test_gpu_accuracy(int TA, int TB, int m, int k, int n) +{ + srand(0); + float *a; + if(!TA) a = random_matrix(m,k); + else a = random_matrix(k,m); + int lda = (!TA)?k:m; + float *b; + if(!TB) b = random_matrix(k,n); + else b = random_matrix(n,k); + int ldb = (!TB)?n:k; + + float *c = random_matrix(m,n); + float *c_gpu = random_matrix(m,n); + memset(c, 0, m*n*sizeof(float)); + memset(c_gpu, 0, m*n*sizeof(float)); + int i; + //pm(m,k,b); + gemm_gpu(TA,TB,m,n,k,1,a,lda,b,ldb,1,c_gpu,n); + //printf("GPU\n"); + //pm(m, n, c_gpu); + + gemm_cpu(TA,TB,m,n,k,1,a,lda,b,ldb,1,c,n); + //printf("\n\nCPU\n"); + //pm(m, n, c); + double sse = 0; + for(i = 0; i < m*n; ++i) { + //printf("%f %f\n", c[i], c_gpu[i]); + sse += pow(c[i]-c_gpu[i], 2); + } + printf("Matrix Multiplication %dx%d * %dx%d, TA=%d, TB=%d: %g SSE\n",m,k,k,n, TA, TB, sse/(m*n)); + free(a); + free(b); + free(c); + free(c_gpu); +} + +int test_gpu_blas() +{ + /* + test_gpu_accuracy(0,0,10,576,75); + + test_gpu_accuracy(0,0,17,10,10); + test_gpu_accuracy(1,0,17,10,10); + test_gpu_accuracy(0,1,17,10,10); + test_gpu_accuracy(1,1,17,10,10); + + test_gpu_accuracy(0,0,1000,10,100); + test_gpu_accuracy(1,0,1000,10,100); + test_gpu_accuracy(0,1,1000,10,100); + test_gpu_accuracy(1,1,1000,10,100); + + test_gpu_accuracy(0,0,10,10,10); + + time_gpu(0,0,64,2916,363); + time_gpu(0,0,64,2916,363); + time_gpu(0,0,64,2916,363); + time_gpu(0,0,192,729,1600); + time_gpu(0,0,384,196,1728); + time_gpu(0,0,256,196,3456); + time_gpu(0,0,256,196,2304); + time_gpu(0,0,128,4096,12544); + time_gpu(0,0,128,4096,4096); + */ + time_gpu(0,0,64,75,12544); + time_gpu(0,0,64,75,12544); + time_gpu(0,0,64,75,12544); + time_gpu(0,0,64,576,12544); + time_gpu(0,0,256,2304,784); + time_gpu(1,1,2304,256,784); + time_gpu(0,0,512,4608,196); + time_gpu(1,1,4608,512,196); + + return 0; +} +#endif + diff --git a/src/gemm.h b/src/gemm.h new file mode 100644 index 0000000..0024c6a --- /dev/null +++ b/src/gemm.h @@ -0,0 +1,35 @@ +#pragma once +#ifndef GEMM_H +#define GEMM_H +#include "define_inc.h" +void gemm_bin(int M, int N, int K, float ALPHA, + char *A, int lda, + float *B, int ldb, + float *C, int ldc); + +void gemm(int TA, int TB, int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float BETA, + float *C, int ldc); + +void gemm_cpu(int TA, int TB, int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float BETA, + float *C, int ldc); + +#ifdef GPU +void gemm_gpu(int TA, int TB, int M, int N, int K, float ALPHA, + float *A_gpu, int lda, + float *B_gpu, int ldb, + float BETA, + float *C_gpu, int ldc); + +void gemm_gpu(int TA, int TB, int M, int N, int K, float ALPHA, + float *A, int lda, + float *B, int ldb, + float BETA, + float *C, int ldc); +#endif +#endif diff --git a/src/gettest.cpp b/src/gettest.cpp new file mode 100644 index 0000000..8fcb041 --- /dev/null +++ b/src/gettest.cpp @@ -0,0 +1,7 @@ +#include "gettest.h" +#include <stdio.h> + +//void gogoTest() +//{ +// printf("gogoTest TTTTT \n\n"); +//} \ No newline at end of file diff --git a/src/gettest.h b/src/gettest.h new file mode 100644 index 0000000..786a54f --- /dev/null +++ b/src/gettest.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" + //void gogoTest(); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/gru_layer.c b/src/gru_layer.c new file mode 100644 index 0000000..b6601d8 --- /dev/null +++ b/src/gru_layer.c @@ -0,0 +1,406 @@ +#include "gru_layer.h" +#include "connected_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void increment_layer(layer *l, int steps) +{ + int num = l->outputs*l->batch*steps; + l->output += num; + l->delta += num; + l->x += num; + l->x_norm += num; + +#ifdef GPU + l->output_gpu += num; + l->delta_gpu += num; + l->x_gpu += num; + l->x_norm_gpu += num; +#endif +} + +layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam) +{ + fprintf(stderr, "GRU Layer: %d inputs, %d outputs\n", inputs, outputs); + batch = batch / steps; + layer l = {0}; + l.batch = batch; + l.type = GRU; + l.steps = steps; + l.inputs = inputs; + + l.uz = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.uz) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.uz->batch = batch; + + l.wz = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wz) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wz->batch = batch; + + l.ur = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.ur) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.ur->batch = batch; + + l.wr = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wr) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wr->batch = batch; + + + + l.uh = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.uh) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.uh->batch = batch; + + l.wh = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wh) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wh->batch = batch; + + l.batch_normalize = batch_normalize; + + + l.outputs = outputs; + l.output = calloc(outputs*batch*steps, sizeof(float)); + l.delta = calloc(outputs*batch*steps, sizeof(float)); + l.state = calloc(outputs*batch, sizeof(float)); + l.prev_state = calloc(outputs*batch, sizeof(float)); + l.forgot_state = calloc(outputs*batch, sizeof(float)); + l.forgot_delta = calloc(outputs*batch, sizeof(float)); + + l.r_cpu = calloc(outputs*batch, sizeof(float)); + l.z_cpu = calloc(outputs*batch, sizeof(float)); + l.h_cpu = calloc(outputs*batch, sizeof(float)); + + l.forward = forward_gru_layer; + l.backward = backward_gru_layer; + l.update = update_gru_layer; + +#ifdef GPU + l.forward_gpu = forward_gru_layer_gpu; + l.backward_gpu = backward_gru_layer_gpu; + l.update_gpu = update_gru_layer_gpu; + + l.forgot_state_gpu = cuda_make_array(0, batch*outputs); + l.forgot_delta_gpu = cuda_make_array(0, batch*outputs); + l.prev_state_gpu = cuda_make_array(0, batch*outputs); + l.state_gpu = cuda_make_array(0, batch*outputs); + l.output_gpu = cuda_make_array(0, batch*outputs*steps); + l.delta_gpu = cuda_make_array(0, batch*outputs*steps); + l.r_gpu = cuda_make_array(0, batch*outputs); + l.z_gpu = cuda_make_array(0, batch*outputs); + l.h_gpu = cuda_make_array(0, batch*outputs); + +#ifdef CUDNN + cudnnSetTensor4dDescriptor(l.uz->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.uz->out_c, l.uz->out_h, l.uz->out_w); + cudnnSetTensor4dDescriptor(l.uh->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.uh->out_c, l.uh->out_h, l.uh->out_w); + cudnnSetTensor4dDescriptor(l.ur->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.ur->out_c, l.ur->out_h, l.ur->out_w); + cudnnSetTensor4dDescriptor(l.wz->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wz->out_c, l.wz->out_h, l.wz->out_w); + cudnnSetTensor4dDescriptor(l.wh->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wh->out_c, l.wh->out_h, l.wh->out_w); + cudnnSetTensor4dDescriptor(l.wr->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wr->out_c, l.wr->out_h, l.wr->out_w); +#endif +#endif + + return l; +} + +void update_gru_layer(layer l, update_args a) +{ + update_connected_layer(*(l.ur), a); + update_connected_layer(*(l.uz), a); + update_connected_layer(*(l.uh), a); + update_connected_layer(*(l.wr), a); + update_connected_layer(*(l.wz), a); + update_connected_layer(*(l.wh), a); +} + +void forward_gru_layer(layer l, network net) +{ + network s = net; + s.train = net.train; + int i; + layer uz = *(l.uz); + layer ur = *(l.ur); + layer uh = *(l.uh); + + layer wz = *(l.wz); + layer wr = *(l.wr); + layer wh = *(l.wh); + + fill_cpu(l.outputs * l.batch * l.steps, 0, uz.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, ur.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, uh.delta, 1); + + fill_cpu(l.outputs * l.batch * l.steps, 0, wz.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, wr.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, wh.delta, 1); + if(net.train) { + fill_cpu(l.outputs * l.batch * l.steps, 0, l.delta, 1); + copy_cpu(l.outputs*l.batch, l.state, 1, l.prev_state, 1); + } + + for (i = 0; i < l.steps; ++i) { + s.input = l.state; + forward_connected_layer(wz, s); + forward_connected_layer(wr, s); + + s.input = net.input; + forward_connected_layer(uz, s); + forward_connected_layer(ur, s); + forward_connected_layer(uh, s); + + + copy_cpu(l.outputs*l.batch, uz.output, 1, l.z_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, wz.output, 1, l.z_cpu, 1); + + copy_cpu(l.outputs*l.batch, ur.output, 1, l.r_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, wr.output, 1, l.r_cpu, 1); + + activate_array(l.z_cpu, l.outputs*l.batch, LOGISTIC); + activate_array(l.r_cpu, l.outputs*l.batch, LOGISTIC); + + copy_cpu(l.outputs*l.batch, l.state, 1, l.forgot_state, 1); + mul_cpu(l.outputs*l.batch, l.r_cpu, 1, l.forgot_state, 1); + + s.input = l.forgot_state; + forward_connected_layer(wh, s); + + copy_cpu(l.outputs*l.batch, uh.output, 1, l.h_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, wh.output, 1, l.h_cpu, 1); + + if(l.tanh){ + activate_array(l.h_cpu, l.outputs*l.batch, TANH); + } else { + activate_array(l.h_cpu, l.outputs*l.batch, LOGISTIC); + } + + weighted_sum_cpu(l.state, l.h_cpu, l.z_cpu, l.outputs*l.batch, l.output); + + copy_cpu(l.outputs*l.batch, l.output, 1, l.state, 1); + + net.input += l.inputs*l.batch; + l.output += l.outputs*l.batch; + increment_layer(&uz, 1); + increment_layer(&ur, 1); + increment_layer(&uh, 1); + + increment_layer(&wz, 1); + increment_layer(&wr, 1); + increment_layer(&wh, 1); + } +} + +void backward_gru_layer(layer l, network net) +{ +} + +#ifdef GPU + +void pull_gru_layer(layer l) +{ +} + +void push_gru_layer(layer l) +{ +} + +void update_gru_layer_gpu(layer l, update_args a) +{ + update_connected_layer_gpu(*(l.ur), a); + update_connected_layer_gpu(*(l.uz), a); + update_connected_layer_gpu(*(l.uh), a); + update_connected_layer_gpu(*(l.wr), a); + update_connected_layer_gpu(*(l.wz), a); + update_connected_layer_gpu(*(l.wh), a); +} + +void forward_gru_layer_gpu(layer l, network net) +{ + network s = {0}; + s.train = net.train; + int i; + layer uz = *(l.uz); + layer ur = *(l.ur); + layer uh = *(l.uh); + + layer wz = *(l.wz); + layer wr = *(l.wr); + layer wh = *(l.wh); + + fill_gpu(l.outputs * l.batch * l.steps, 0, uz.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, ur.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, uh.delta_gpu, 1); + + fill_gpu(l.outputs * l.batch * l.steps, 0, wz.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, wr.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, wh.delta_gpu, 1); + if(net.train) { + fill_gpu(l.outputs * l.batch * l.steps, 0, l.delta_gpu, 1); + copy_gpu(l.outputs*l.batch, l.state_gpu, 1, l.prev_state_gpu, 1); + } + + for (i = 0; i < l.steps; ++i) { + s.input_gpu = l.state_gpu; + forward_connected_layer_gpu(wz, s); + forward_connected_layer_gpu(wr, s); + + s.input_gpu = net.input_gpu; + forward_connected_layer_gpu(uz, s); + forward_connected_layer_gpu(ur, s); + forward_connected_layer_gpu(uh, s); + + copy_gpu(l.outputs*l.batch, uz.output_gpu, 1, l.z_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, wz.output_gpu, 1, l.z_gpu, 1); + + copy_gpu(l.outputs*l.batch, ur.output_gpu, 1, l.r_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, wr.output_gpu, 1, l.r_gpu, 1); + + activate_array_gpu(l.z_gpu, l.outputs*l.batch, LOGISTIC); + activate_array_gpu(l.r_gpu, l.outputs*l.batch, LOGISTIC); + + copy_gpu(l.outputs*l.batch, l.state_gpu, 1, l.forgot_state_gpu, 1); + mul_gpu(l.outputs*l.batch, l.r_gpu, 1, l.forgot_state_gpu, 1); + + s.input_gpu = l.forgot_state_gpu; + forward_connected_layer_gpu(wh, s); + + copy_gpu(l.outputs*l.batch, uh.output_gpu, 1, l.h_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, wh.output_gpu, 1, l.h_gpu, 1); + + if(l.tanh){ + activate_array_gpu(l.h_gpu, l.outputs*l.batch, TANH); + } else { + activate_array_gpu(l.h_gpu, l.outputs*l.batch, LOGISTIC); + } + + weighted_sum_gpu(l.state_gpu, l.h_gpu, l.z_gpu, l.outputs*l.batch, l.output_gpu); + copy_gpu(l.outputs*l.batch, l.output_gpu, 1, l.state_gpu, 1); + + net.input_gpu += l.inputs*l.batch; + l.output_gpu += l.outputs*l.batch; + increment_layer(&uz, 1); + increment_layer(&ur, 1); + increment_layer(&uh, 1); + + increment_layer(&wz, 1); + increment_layer(&wr, 1); + increment_layer(&wh, 1); + } +} + +void backward_gru_layer_gpu(layer l, network net) +{ + network s = {0}; + s.train = net.train; + int i; + layer uz = *(l.uz); + layer ur = *(l.ur); + layer uh = *(l.uh); + + layer wz = *(l.wz); + layer wr = *(l.wr); + layer wh = *(l.wh); + + increment_layer(&uz, l.steps - 1); + increment_layer(&ur, l.steps - 1); + increment_layer(&uh, l.steps - 1); + + increment_layer(&wz, l.steps - 1); + increment_layer(&wr, l.steps - 1); + increment_layer(&wh, l.steps - 1); + + net.input_gpu += l.inputs*l.batch*(l.steps-1); + if(net.delta_gpu) net.delta_gpu += l.inputs*l.batch*(l.steps-1); + l.output_gpu += l.outputs*l.batch*(l.steps-1); + l.delta_gpu += l.outputs*l.batch*(l.steps-1); + float *end_state = l.output_gpu; + for (i = l.steps-1; i >= 0; --i) { + if(i != 0) copy_gpu(l.outputs*l.batch, l.output_gpu - l.outputs*l.batch, 1, l.state_gpu, 1); + else copy_gpu(l.outputs*l.batch, l.prev_state_gpu, 1, l.state_gpu, 1); + float *prev_delta_gpu = (i == 0) ? 0 : l.delta_gpu - l.outputs*l.batch; + + copy_gpu(l.outputs*l.batch, uz.output_gpu, 1, l.z_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, wz.output_gpu, 1, l.z_gpu, 1); + + copy_gpu(l.outputs*l.batch, ur.output_gpu, 1, l.r_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, wr.output_gpu, 1, l.r_gpu, 1); + + activate_array_gpu(l.z_gpu, l.outputs*l.batch, LOGISTIC); + activate_array_gpu(l.r_gpu, l.outputs*l.batch, LOGISTIC); + + copy_gpu(l.outputs*l.batch, uh.output_gpu, 1, l.h_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, wh.output_gpu, 1, l.h_gpu, 1); + + if(l.tanh){ + activate_array_gpu(l.h_gpu, l.outputs*l.batch, TANH); + } else { + activate_array_gpu(l.h_gpu, l.outputs*l.batch, LOGISTIC); + } + + weighted_delta_gpu(l.state_gpu, l.h_gpu, l.z_gpu, prev_delta_gpu, uh.delta_gpu, uz.delta_gpu, l.outputs*l.batch, l.delta_gpu); + + if(l.tanh){ + gradient_array_gpu(l.h_gpu, l.outputs*l.batch, TANH, uh.delta_gpu); + } else { + gradient_array_gpu(l.h_gpu, l.outputs*l.batch, LOGISTIC, uh.delta_gpu); + } + + copy_gpu(l.outputs*l.batch, uh.delta_gpu, 1, wh.delta_gpu, 1); + + copy_gpu(l.outputs*l.batch, l.state_gpu, 1, l.forgot_state_gpu, 1); + mul_gpu(l.outputs*l.batch, l.r_gpu, 1, l.forgot_state_gpu, 1); + fill_gpu(l.outputs*l.batch, 0, l.forgot_delta_gpu, 1); + + s.input_gpu = l.forgot_state_gpu; + s.delta_gpu = l.forgot_delta_gpu; + + backward_connected_layer_gpu(wh, s); + if(prev_delta_gpu) mult_add_into_gpu(l.outputs*l.batch, l.forgot_delta_gpu, l.r_gpu, prev_delta_gpu); + mult_add_into_gpu(l.outputs*l.batch, l.forgot_delta_gpu, l.state_gpu, ur.delta_gpu); + + gradient_array_gpu(l.r_gpu, l.outputs*l.batch, LOGISTIC, ur.delta_gpu); + copy_gpu(l.outputs*l.batch, ur.delta_gpu, 1, wr.delta_gpu, 1); + + gradient_array_gpu(l.z_gpu, l.outputs*l.batch, LOGISTIC, uz.delta_gpu); + copy_gpu(l.outputs*l.batch, uz.delta_gpu, 1, wz.delta_gpu, 1); + + s.input_gpu = l.state_gpu; + s.delta_gpu = prev_delta_gpu; + + backward_connected_layer_gpu(wr, s); + backward_connected_layer_gpu(wz, s); + + s.input_gpu = net.input_gpu; + s.delta_gpu = net.delta_gpu; + + backward_connected_layer_gpu(uh, s); + backward_connected_layer_gpu(ur, s); + backward_connected_layer_gpu(uz, s); + + + net.input_gpu -= l.inputs*l.batch; + if(net.delta_gpu) net.delta_gpu -= l.inputs*l.batch; + l.output_gpu -= l.outputs*l.batch; + l.delta_gpu -= l.outputs*l.batch; + increment_layer(&uz, -1); + increment_layer(&ur, -1); + increment_layer(&uh, -1); + + increment_layer(&wz, -1); + increment_layer(&wr, -1); + increment_layer(&wh, -1); + } + copy_gpu(l.outputs*l.batch, end_state, 1, l.state_gpu, 1); +} +#endif diff --git a/src/gru_layer.h b/src/gru_layer.h new file mode 100644 index 0000000..0d37f8c --- /dev/null +++ b/src/gru_layer.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef GRU_LAYER_H +#define GRU_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "layer.h" +#include "network.h" + +layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam); + +void forward_gru_layer(layer l, network state); +void backward_gru_layer(layer l, network state); +void update_gru_layer(layer l, update_args a); + +#ifdef GPU +void forward_gru_layer_gpu(layer l, network state); +void backward_gru_layer_gpu(layer l, network state); +void update_gru_layer_gpu(layer l, update_args a); +void push_gru_layer(layer l); +void pull_gru_layer(layer l); +#endif + +#endif + diff --git a/src/im2col.c b/src/im2col.c new file mode 100644 index 0000000..69ec98a --- /dev/null +++ b/src/im2col.c @@ -0,0 +1,40 @@ +#include "im2col.h" +#include <stdio.h> +float im2col_get_pixel(float *im, int height, int width, int channels, + int row, int col, int channel, int pad) +{ + row -= pad; + col -= pad; + + if (row < 0 || col < 0 || + row >= height || col >= width) return 0; + return im[col + width*(row + height*channel)]; +} + +//From Berkeley Vision's Caffe! +//https://github.com/BVLC/caffe/blob/master/LICENSE +void im2col_cpu(float* data_im, + int channels, int height, int width, + int ksize, int stride, int pad, float* data_col) +{ + int c,h,w; + int height_col = (height + 2*pad - ksize) / stride + 1; + int width_col = (width + 2*pad - ksize) / stride + 1; + + int channels_col = channels * ksize * ksize; + for (c = 0; c < channels_col; ++c) { + int w_offset = c % ksize; + int h_offset = (c / ksize) % ksize; + int c_im = c / ksize / ksize; + for (h = 0; h < height_col; ++h) { + for (w = 0; w < width_col; ++w) { + int im_row = h_offset + h * stride; + int im_col = w_offset + w * stride; + int col_index = (c * height_col + h) * width_col + w; + data_col[col_index] = im2col_get_pixel(data_im, height, width, channels, + im_row, im_col, c_im, pad); + } + } + } +} + diff --git a/src/im2col.h b/src/im2col.h new file mode 100644 index 0000000..82a2774 --- /dev/null +++ b/src/im2col.h @@ -0,0 +1,16 @@ +#pragma once +#ifndef IM2COL_H +#define IM2COL_H +#include "define_inc.h" +void im2col_cpu(float* data_im, + int channels, int height, int width, + int ksize, int stride, int pad, float* data_col); + +#ifdef GPU + +void im2col_gpu(float *im, + int channels, int height, int width, + int ksize, int stride, int pad,float *data_col); + +#endif +#endif diff --git a/src/im2col_kernels.cu b/src/im2col_kernels.cu new file mode 100644 index 0000000..07b5e67 --- /dev/null +++ b/src/im2col_kernels.cu @@ -0,0 +1,61 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "im2col.h" +#include "cuda.h" +} + +// src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu +// You may also want to read: https://github.com/BVLC/caffe/blob/master/LICENSE + +__global__ void im2col_gpu_kernel(const int n, const float* data_im, + const int height, const int width, const int ksize, + const int pad, + const int stride, + const int height_col, const int width_col, + float *data_col) { + int index = blockIdx.x*blockDim.x+threadIdx.x; + for(; index < n; index += blockDim.x*gridDim.x){ + int w_out = index % width_col; + int h_index = index / width_col; + int h_out = h_index % height_col; + int channel_in = h_index / height_col; + int channel_out = channel_in * ksize * ksize; + int h_in = h_out * stride - pad; + int w_in = w_out * stride - pad; + float* data_col_ptr = data_col; + data_col_ptr += (channel_out * height_col + h_out) * width_col + w_out; + const float* data_im_ptr = data_im; + data_im_ptr += (channel_in * height + h_in) * width + w_in; + for (int i = 0; i < ksize; ++i) { + for (int j = 0; j < ksize; ++j) { + int h = h_in + i; + int w = w_in + j; + + *data_col_ptr = (h >= 0 && w >= 0 && h < height && w < width) ? + data_im_ptr[i * width + j] : 0; + + //*data_col_ptr = data_im_ptr[ii * width + jj]; + + data_col_ptr += height_col * width_col; + } + } + } +} + +void im2col_gpu(float *im, + int channels, int height, int width, + int ksize, int stride, int pad, float *data_col){ + // We are going to launch channels * height_col * width_col kernels, each + // kernel responsible for copying a single-channel grid. + int height_col = (height + 2 * pad - ksize) / stride + 1; + int width_col = (width + 2 * pad - ksize) / stride + 1; + int num_kernels = channels * height_col * width_col; + im2col_gpu_kernel<<<(num_kernels+BLOCK-1)/BLOCK, + BLOCK>>>( + num_kernels, im, height, width, ksize, pad, + stride, height_col, + width_col, data_col); +} diff --git a/src/image.c b/src/image.c new file mode 100644 index 0000000..ae29049 --- /dev/null +++ b/src/image.c @@ -0,0 +1,1487 @@ +#include "image.h" +#include "utils.h" +#include "blas.h" +#include "cuda.h" +#include <stdio.h> +#include <math.h> + +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "stb_image_write.h" + +int windows = 0; + +float colors[6][3] = { {1,0,1}, {0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0,0} }; + +float get_color(int c, int x, int max) +{ + float ratio = ((float)x/max)*5; + int i = floor(ratio); + int j = ceil(ratio); + ratio -= i; + float r = (1-ratio) * colors[i][c] + ratio*colors[j][c]; + //printf("%f\n", r); + return r; +} + +image mask_to_rgb(image mask) +{ + int n = mask.c; + image im = make_image(mask.w, mask.h, 3); + int i, j; + for(j = 0; j < n; ++j){ + int offset = j*123457 % n; + float red = get_color(2,offset,n); + float green = get_color(1,offset,n); + float blue = get_color(0,offset,n); + for(i = 0; i < im.w*im.h; ++i){ + im.data[i + 0*im.w*im.h] += mask.data[j*im.h*im.w + i]*red; + im.data[i + 1*im.w*im.h] += mask.data[j*im.h*im.w + i]*green; + im.data[i + 2*im.w*im.h] += mask.data[j*im.h*im.w + i]*blue; + } + } + return im; +} + +static float get_pixel(image m, int x, int y, int c) +{ + assert(x < m.w && y < m.h && c < m.c); + return m.data[c*m.h*m.w + y*m.w + x]; +} +static float get_pixel_extend(image m, int x, int y, int c) +{ + if(x < 0 || x >= m.w || y < 0 || y >= m.h) return 0; + /* + if(x < 0) x = 0; + if(x >= m.w) x = m.w-1; + if(y < 0) y = 0; + if(y >= m.h) y = m.h-1; + */ + if(c < 0 || c >= m.c) return 0; + return get_pixel(m, x, y, c); +} +static void set_pixel(image m, int x, int y, int c, float val) +{ + if (x < 0 || y < 0 || c < 0 || x >= m.w || y >= m.h || c >= m.c) return; + assert(x < m.w && y < m.h && c < m.c); + m.data[c*m.h*m.w + y*m.w + x] = val; +} +static void add_pixel(image m, int x, int y, int c, float val) +{ + assert(x < m.w && y < m.h && c < m.c); + m.data[c*m.h*m.w + y*m.w + x] += val; +} + +static float bilinear_interpolate(image im, float x, float y, int c) +{ + int ix = (int) floorf(x); + int iy = (int) floorf(y); + + float dx = x - ix; + float dy = y - iy; + + float val = (1-dy) * (1-dx) * get_pixel_extend(im, ix, iy, c) + + dy * (1-dx) * get_pixel_extend(im, ix, iy+1, c) + + (1-dy) * dx * get_pixel_extend(im, ix+1, iy, c) + + dy * dx * get_pixel_extend(im, ix+1, iy+1, c); + return val; +} + + +void composite_image(image source, image dest, int dx, int dy) +{ + int x,y,k; + for(k = 0; k < source.c; ++k){ + for(y = 0; y < source.h; ++y){ + for(x = 0; x < source.w; ++x){ + float val = get_pixel(source, x, y, k); + float val2 = get_pixel_extend(dest, dx+x, dy+y, k); + set_pixel(dest, dx+x, dy+y, k, val * val2); + } + } + } +} + +image border_image(image a, int border) +{ + image b = make_image(a.w + 2*border, a.h + 2*border, a.c); + int x,y,k; + for(k = 0; k < b.c; ++k){ + for(y = 0; y < b.h; ++y){ + for(x = 0; x < b.w; ++x){ + float val = get_pixel_extend(a, x - border, y - border, k); + if(x - border < 0 || x - border >= a.w || y - border < 0 || y - border >= a.h) val = 1; + set_pixel(b, x, y, k, val); + } + } + } + return b; +} + +image tile_images(image a, image b, int dx) +{ + if(a.w == 0) return copy_image(b); + image c = make_image(a.w + b.w + dx, (a.h > b.h) ? a.h : b.h, (a.c > b.c) ? a.c : b.c); + fill_cpu(c.w*c.h*c.c, 1, c.data, 1); + embed_image(a, c, 0, 0); + composite_image(b, c, a.w + dx, 0); + return c; +} + +image get_label(image **characters, char *string, int size) +{ + size = size/10; + if(size > 7) size = 7; + image label = make_empty_image(0,0,0); + while(*string){ + image l = characters[size][(int)*string]; + image n = tile_images(label, l, -size - 1 + (size+1)/2); + free_image(label); + label = n; + ++string; + } + image b = border_image(label, label.h*.25); + free_image(label); + return b; +} + +void draw_label(image a, int r, int c, image label, const float *rgb) +{ + int w = label.w; + int h = label.h; + if (r - h >= 0) r = r - h; + + int i, j, k; + for(j = 0; j < h && j + r < a.h; ++j){ + for(i = 0; i < w && i + c < a.w; ++i){ + for(k = 0; k < label.c; ++k){ + float val = get_pixel(label, i, j, k); + set_pixel(a, i+c, j+r, k, rgb[k] * val); + } + } + } +} + +void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b) +{ + //normalize_image(a); + int i; + if(x1 < 0) x1 = 0; + if(x1 >= a.w) x1 = a.w-1; + if(x2 < 0) x2 = 0; + if(x2 >= a.w) x2 = a.w-1; + + if(y1 < 0) y1 = 0; + if(y1 >= a.h) y1 = a.h-1; + if(y2 < 0) y2 = 0; + if(y2 >= a.h) y2 = a.h-1; + + for(i = x1; i <= x2; ++i){ + a.data[i + y1*a.w + 0*a.w*a.h] = r; + a.data[i + y2*a.w + 0*a.w*a.h] = r; + + a.data[i + y1*a.w + 1*a.w*a.h] = g; + a.data[i + y2*a.w + 1*a.w*a.h] = g; + + a.data[i + y1*a.w + 2*a.w*a.h] = b; + a.data[i + y2*a.w + 2*a.w*a.h] = b; + } + for(i = y1; i <= y2; ++i){ + a.data[x1 + i*a.w + 0*a.w*a.h] = r; + a.data[x2 + i*a.w + 0*a.w*a.h] = r; + + a.data[x1 + i*a.w + 1*a.w*a.h] = g; + a.data[x2 + i*a.w + 1*a.w*a.h] = g; + + a.data[x1 + i*a.w + 2*a.w*a.h] = b; + a.data[x2 + i*a.w + 2*a.w*a.h] = b; + } +} + +void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b) +{ + int i; + for(i = 0; i < w; ++i){ + draw_box(a, x1+i, y1+i, x2-i, y2-i, r, g, b); + } +} + +void draw_bbox(image a, box bbox, int w, float r, float g, float b) +{ + int left = (bbox.x-bbox.w/2)*a.w; + int right = (bbox.x+bbox.w/2)*a.w; + int top = (bbox.y-bbox.h/2)*a.h; + int bot = (bbox.y+bbox.h/2)*a.h; + + int i; + for(i = 0; i < w; ++i){ + draw_box(a, left+i, top+i, right-i, bot-i, r, g, b); + } +} + +image **load_alphabet() +{ + int i, j; + const int nsize = 8; + image **alphabets = calloc(nsize, sizeof(image)); + for(j = 0; j < nsize; ++j){ + alphabets[j] = calloc(128, sizeof(image)); + for(i = 32; i < 127; ++i){ + char buff[256]; + sprintf(buff, "data/labels/%d_%d.png", i, j); + alphabets[j][i] = load_image_color(buff, 0, 0); + } + } + return alphabets; +} + +void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes) +{ + int i,j; + + for(i = 0; i < num; ++i){ + char labelstr[4096] = {0}; + int class = -1; + for(j = 0; j < classes; ++j){ + if (dets[i].prob[j] > thresh){ + if (class < 0) { + strcat(labelstr, names[j]); + class = j; + } else { + strcat(labelstr, ", "); + strcat(labelstr, names[j]); + } + printf("%s: %.0f%%\n", names[j], dets[i].prob[j]*100); + } + } + if(class >= 0){ + int width = im.h * .006; + + /* + if(0){ + width = pow(prob, 1./2.)*10+1; + alphabet = 0; + } + */ + + //printf("%d %s: %.0f%%\n", i, names[class], prob*100); + int offset = class*123457 % classes; + float red = get_color(2,offset,classes); + float green = get_color(1,offset,classes); + float blue = get_color(0,offset,classes); + float rgb[3]; + + //width = prob*20+2; + + rgb[0] = red; + rgb[1] = green; + rgb[2] = blue; + box b = dets[i].bbox; + //printf("%f %f %f %f\n", b.x, b.y, b.w, b.h); + + int left = (b.x-b.w/2.)*im.w; + int right = (b.x+b.w/2.)*im.w; + int top = (b.y-b.h/2.)*im.h; + int bot = (b.y+b.h/2.)*im.h; + + if(left < 0) left = 0; + if(right > im.w-1) right = im.w-1; + if(top < 0) top = 0; + if(bot > im.h-1) bot = im.h-1; + + draw_box_width(im, left, top, right, bot, width, red, green, blue); + if (alphabet) { + image label = get_label(alphabet, labelstr, (im.h*.03)); + draw_label(im, top + width, left, label, rgb); + free_image(label); + } + if (dets[i].mask){ + image mask = float_to_image(14, 14, 1, dets[i].mask); + image resized_mask = resize_image(mask, b.w*im.w, b.h*im.h); + image tmask = threshold_image(resized_mask, .5); + embed_image(tmask, im, left, top); + free_image(mask); + free_image(resized_mask); + free_image(tmask); + } + } + } +} + +void transpose_image(image im) +{ + assert(im.w == im.h); + int n, m; + int c; + for(c = 0; c < im.c; ++c){ + for(n = 0; n < im.w-1; ++n){ + for(m = n + 1; m < im.w; ++m){ + float swap = im.data[m + im.w*(n + im.h*c)]; + im.data[m + im.w*(n + im.h*c)] = im.data[n + im.w*(m + im.h*c)]; + im.data[n + im.w*(m + im.h*c)] = swap; + } + } + } +} + +void rotate_image_cw(image im, int times) +{ + assert(im.w == im.h); + times = (times + 400) % 4; + int i, x, y, c; + int n = im.w; + for(i = 0; i < times; ++i){ + for(c = 0; c < im.c; ++c){ + for(x = 0; x < n/2; ++x){ + for(y = 0; y < (n-1)/2 + 1; ++y){ + float temp = im.data[y + im.w*(x + im.h*c)]; + im.data[y + im.w*(x + im.h*c)] = im.data[n-1-x + im.w*(y + im.h*c)]; + im.data[n-1-x + im.w*(y + im.h*c)] = im.data[n-1-y + im.w*(n-1-x + im.h*c)]; + im.data[n-1-y + im.w*(n-1-x + im.h*c)] = im.data[x + im.w*(n-1-y + im.h*c)]; + im.data[x + im.w*(n-1-y + im.h*c)] = temp; + } + } + } + } +} + +void flip_image(image a) +{ + int i,j,k; + for(k = 0; k < a.c; ++k){ + for(i = 0; i < a.h; ++i){ + for(j = 0; j < a.w/2; ++j){ + int index = j + a.w*(i + a.h*(k)); + int flip = (a.w - j - 1) + a.w*(i + a.h*(k)); + float swap = a.data[flip]; + a.data[flip] = a.data[index]; + a.data[index] = swap; + } + } + } +} + +image image_distance(image a, image b) +{ + int i,j; + image dist = make_image(a.w, a.h, 1); + for(i = 0; i < a.c; ++i){ + for(j = 0; j < a.h*a.w; ++j){ + dist.data[j] += pow(a.data[i*a.h*a.w+j]-b.data[i*a.h*a.w+j],2); + } + } + for(j = 0; j < a.h*a.w; ++j){ + dist.data[j] = sqrt(dist.data[j]); + } + return dist; +} + +void ghost_image(image source, image dest, int dx, int dy) +{ + int x,y,k; + float max_dist = sqrt((-source.w/2. + .5)*(-source.w/2. + .5)); + for(k = 0; k < source.c; ++k){ + for(y = 0; y < source.h; ++y){ + for(x = 0; x < source.w; ++x){ + float dist = sqrt((x - source.w/2. + .5)*(x - source.w/2. + .5) + (y - source.h/2. + .5)*(y - source.h/2. + .5)); + float alpha = (1 - dist/max_dist); + if(alpha < 0) alpha = 0; + float v1 = get_pixel(source, x,y,k); + float v2 = get_pixel(dest, dx+x,dy+y,k); + float val = alpha*v1 + (1-alpha)*v2; + set_pixel(dest, dx+x, dy+y, k, val); + } + } + } +} + +void blocky_image(image im, int s) +{ + int i,j,k; + for(k = 0; k < im.c; ++k){ + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + im.data[i + im.w*(j + im.h*k)] = im.data[i/s*s + im.w*(j/s*s + im.h*k)]; + } + } + } +} + +void censor_image(image im, int dx, int dy, int w, int h) +{ + int i,j,k; + int s = 32; + if(dx < 0) dx = 0; + if(dy < 0) dy = 0; + + for(k = 0; k < im.c; ++k){ + for(j = dy; j < dy + h && j < im.h; ++j){ + for(i = dx; i < dx + w && i < im.w; ++i){ + im.data[i + im.w*(j + im.h*k)] = im.data[i/s*s + im.w*(j/s*s + im.h*k)]; + //im.data[i + j*im.w + k*im.w*im.h] = 0; + } + } + } +} + +void embed_image(image source, image dest, int dx, int dy) +{ + int x,y,k; + for(k = 0; k < source.c; ++k){ + for(y = 0; y < source.h; ++y){ + for(x = 0; x < source.w; ++x){ + float val = get_pixel(source, x,y,k); + set_pixel(dest, dx+x, dy+y, k, val); + } + } + } +} + +image collapse_image_layers(image source, int border) +{ + int h = source.h; + h = (h+border)*source.c - border; + image dest = make_image(source.w, h, 1); + int i; + for(i = 0; i < source.c; ++i){ + image layer = get_image_layer(source, i); + int h_offset = i*(source.h+border); + embed_image(layer, dest, 0, h_offset); + free_image(layer); + } + return dest; +} + +void constrain_image(image im) +{ + int i; + for(i = 0; i < im.w*im.h*im.c; ++i){ + if(im.data[i] < 0) im.data[i] = 0; + if(im.data[i] > 1) im.data[i] = 1; + } +} + +void normalize_image(image p) +{ + int i; + float min = 9999999; + float max = -999999; + + for(i = 0; i < p.h*p.w*p.c; ++i){ + float v = p.data[i]; + if(v < min) min = v; + if(v > max) max = v; + } + if(max - min < .000000001){ + min = 0; + max = 1; + } + for(i = 0; i < p.c*p.w*p.h; ++i){ + p.data[i] = (p.data[i] - min)/(max-min); + } +} + +void normalize_image2(image p) +{ + float *min = calloc(p.c, sizeof(float)); + float *max = calloc(p.c, sizeof(float)); + int i,j; + for(i = 0; i < p.c; ++i) min[i] = max[i] = p.data[i*p.h*p.w]; + + for(j = 0; j < p.c; ++j){ + for(i = 0; i < p.h*p.w; ++i){ + float v = p.data[i+j*p.h*p.w]; + if(v < min[j]) min[j] = v; + if(v > max[j]) max[j] = v; + } + } + for(i = 0; i < p.c; ++i){ + if(max[i] - min[i] < .000000001){ + min[i] = 0; + max[i] = 1; + } + } + for(j = 0; j < p.c; ++j){ + for(i = 0; i < p.w*p.h; ++i){ + p.data[i+j*p.h*p.w] = (p.data[i+j*p.h*p.w] - min[j])/(max[j]-min[j]); + } + } + if (min) { + free(min); + min = NULL; + } + if (max) { + free(max); + max = NULL; + } +} + +void copy_image_into(image src, image dest) +{ + memcpy(dest.data, src.data, src.h*src.w*src.c*sizeof(float)); +} + +image copy_image(image p) +{ + image copy = p; + copy.data = calloc(p.h*p.w*p.c, sizeof(float)); + memcpy(copy.data, p.data, p.h*p.w*p.c*sizeof(float)); + return copy; +} + +void rgbgr_image(image im) +{ + int i; + for(i = 0; i < im.w*im.h; ++i){ + float swap = im.data[i]; + im.data[i] = im.data[i+im.w*im.h*2]; + im.data[i+im.w*im.h*2] = swap; + } +} + +int show_image(image p, const char *name, int ms) +{ +#ifdef OPENCV + int c = show_image_cv(p, name, ms); + return c; +#else + fprintf(stderr, "Not compiled with OpenCV, saving to %s.png instead\n", name); + save_image(p, name); + return -1; +#endif +} + +void save_image_options(image im, const char *name, IMTYPE f, int quality) +{ + char buff[256]; + //sprintf(buff, "%s (%d)", name, windows); + if(f == PNG) sprintf(buff, "%s.png", name); + else if (f == BMP) sprintf(buff, "%s.bmp", name); + else if (f == TGA) sprintf(buff, "%s.tga", name); + else if (f == JPG) sprintf(buff, "%s.jpg", name); + else sprintf(buff, "%s.png", name); + unsigned char *data = calloc(im.w*im.h*im.c, sizeof(char)); + int i,k; + for(k = 0; k < im.c; ++k){ + for(i = 0; i < im.w*im.h; ++i){ + data[i*im.c+k] = (unsigned char) (255*im.data[i + k*im.w*im.h]); + } + } + int success = 0; + if(f == PNG) success = stbi_write_png(buff, im.w, im.h, im.c, data, im.w*im.c); + else if (f == BMP) success = stbi_write_bmp(buff, im.w, im.h, im.c, data); + else if (f == TGA) success = stbi_write_tga(buff, im.w, im.h, im.c, data); + else if (f == JPG) success = stbi_write_jpg(buff, im.w, im.h, im.c, data, quality); + if (data) { + free(data); + data = NULL; + } + if(!success) fprintf(stderr, "Failed to write image %s\n", buff); +} + +void save_image(image im, const char *name) +{ + save_image_options(im, name, JPG, 80); +} + +void show_image_layers(image p, char *name) +{ + int i; + char buff[256]; + for(i = 0; i < p.c; ++i){ + sprintf(buff, "%s - Layer %d", name, i); + image layer = get_image_layer(p, i); + show_image(layer, buff, 1); + free_image(layer); + } +} + +void show_image_collapsed(image p, char *name) +{ + image c = collapse_image_layers(p, 1); + show_image(c, name, 1); + free_image(c); +} + +image make_empty_image(int w, int h, int c) +{ + image out; + out.data = 0; + out.h = h; + out.w = w; + out.c = c; + return out; +} + +image make_image(int w, int h, int c) +{ + image out = make_empty_image(w,h,c); + out.data = calloc(h*w*c, sizeof(float)); + return out; +} + +image make_random_image(int w, int h, int c) +{ + image out = make_empty_image(w,h,c); + out.data = calloc(h*w*c, sizeof(float)); + int i; + for(i = 0; i < w*h*c; ++i){ + out.data[i] = (rand_normal() * .25) + .5; + } + return out; +} + +image float_to_image(int w, int h, int c, float *data) +{ + image out = make_empty_image(w,h,c); + out.data = data; + return out; +} + +void place_image(image im, int w, int h, int dx, int dy, image canvas) +{ + int x, y, c; + for(c = 0; c < im.c; ++c){ + for(y = 0; y < h; ++y){ + for(x = 0; x < w; ++x){ + float rx = ((float)x / w) * im.w; + float ry = ((float)y / h) * im.h; + float val = bilinear_interpolate(im, rx, ry, c); + set_pixel(canvas, x + dx, y + dy, c, val); + } + } + } +} + +image center_crop_image(image im, int w, int h) +{ + int m = (im.w < im.h) ? im.w : im.h; + image c = crop_image(im, (im.w - m) / 2, (im.h - m)/2, m, m); + image r = resize_image(c, w, h); + free_image(c); + return r; +} + +image rotate_crop_image(image im, float rad, float s, int w, int h, float dx, float dy, float aspect) +{ + int x, y, c; + float cx = im.w/2.; + float cy = im.h/2.; + image rot = make_image(w, h, im.c); + for(c = 0; c < im.c; ++c){ + for(y = 0; y < h; ++y){ + for(x = 0; x < w; ++x){ + float rx = cos(rad)*((x - w/2.)/s*aspect + dx/s*aspect) - sin(rad)*((y - h/2.)/s + dy/s) + cx; + float ry = sin(rad)*((x - w/2.)/s*aspect + dx/s*aspect) + cos(rad)*((y - h/2.)/s + dy/s) + cy; + float val = bilinear_interpolate(im, rx, ry, c); + set_pixel(rot, x, y, c, val); + } + } + } + return rot; +} + +image rotate_image(image im, float rad) +{ + int x, y, c; + float cx = im.w/2.; + float cy = im.h/2.; + image rot = make_image(im.w, im.h, im.c); + for(c = 0; c < im.c; ++c){ + for(y = 0; y < im.h; ++y){ + for(x = 0; x < im.w; ++x){ + float rx = cos(rad)*(x-cx) - sin(rad)*(y-cy) + cx; + float ry = sin(rad)*(x-cx) + cos(rad)*(y-cy) + cy; + float val = bilinear_interpolate(im, rx, ry, c); + set_pixel(rot, x, y, c, val); + } + } + } + return rot; +} + +void fill_image(image m, float s) +{ + int i; + for(i = 0; i < m.h*m.w*m.c; ++i) m.data[i] = s; +} + +void translate_image(image m, float s) +{ + int i; + for(i = 0; i < m.h*m.w*m.c; ++i) m.data[i] += s; +} + +void scale_image(image m, float s) +{ + int i; + for(i = 0; i < m.h*m.w*m.c; ++i) m.data[i] *= s; +} + +image crop_image(image im, int dx, int dy, int w, int h) +{ + image cropped = make_image(w, h, im.c); + int i, j, k; + for(k = 0; k < im.c; ++k){ + for(j = 0; j < h; ++j){ + for(i = 0; i < w; ++i){ + int r = j + dy; + int c = i + dx; + float val = 0; + r = constrain_int(r, 0, im.h-1); + c = constrain_int(c, 0, im.w-1); + val = get_pixel(im, c, r, k); + set_pixel(cropped, i, j, k, val); + } + } + } + return cropped; +} + +int best_3d_shift_r(image a, image b, int min, int max) +{ + if(min == max) return min; + int mid = floor((min + max) / 2.); + image c1 = crop_image(b, 0, mid, b.w, b.h); + image c2 = crop_image(b, 0, mid+1, b.w, b.h); + float d1 = dist_array(c1.data, a.data, a.w*a.h*a.c, 10); + float d2 = dist_array(c2.data, a.data, a.w*a.h*a.c, 10); + free_image(c1); + free_image(c2); + if(d1 < d2) return best_3d_shift_r(a, b, min, mid); + else return best_3d_shift_r(a, b, mid+1, max); +} + +int best_3d_shift(image a, image b, int min, int max) +{ + int i; + int best = 0; + float best_distance = FLT_MAX; + for(i = min; i <= max; i += 2){ + image c = crop_image(b, 0, i, b.w, b.h); + float d = dist_array(c.data, a.data, a.w*a.h*a.c, 100); + if(d < best_distance){ + best_distance = d; + best = i; + } + printf("%d %f\n", i, d); + free_image(c); + } + return best; +} + +void composite_3d(char *f1, char *f2, char *out, int delta) +{ + if(!out) out = "out"; + image a = load_image(f1, 0,0,0); + image b = load_image(f2, 0,0,0); + int shift = best_3d_shift_r(a, b, -a.h/100, a.h/100); + + image c1 = crop_image(b, 10, shift, b.w, b.h); + float d1 = dist_array(c1.data, a.data, a.w*a.h*a.c, 100); + image c2 = crop_image(b, -10, shift, b.w, b.h); + float d2 = dist_array(c2.data, a.data, a.w*a.h*a.c, 100); + + if(d2 < d1 && 0){ + image swap = a; + a = b; + b = swap; + shift = -shift; + printf("swapped, %d\n", shift); + } + else{ + printf("%d\n", shift); + } + + image c = crop_image(b, delta, shift, a.w, a.h); + int i; + for(i = 0; i < c.w*c.h; ++i){ + c.data[i] = a.data[i]; + } + save_image(c, out); +} + +void letterbox_image_into(image im, int w, int h, image boxed) +{ + int new_w = im.w; + int new_h = im.h; + if (((float)w/im.w) < ((float)h/im.h)) { + new_w = w; + new_h = (im.h * w)/im.w; + } else { + new_h = h; + new_w = (im.w * h)/im.h; + } + image resized = resize_image(im, new_w, new_h); + embed_image(resized, boxed, (w-new_w)/2, (h-new_h)/2); + free_image(resized); +} + +image letterbox_image(image im, int w, int h) +{ + int new_w = im.w; + int new_h = im.h; + if (((float)w/im.w) < ((float)h/im.h)) { + new_w = w; + new_h = (im.h * w)/im.w; + } else { + new_h = h; + new_w = (im.w * h)/im.h; + } + image resized = resize_image(im, new_w, new_h); + image boxed = make_image(w, h, im.c); + fill_image(boxed, .5); + //int i; + //for(i = 0; i < boxed.w*boxed.h*boxed.c; ++i) boxed.data[i] = 0; + embed_image(resized, boxed, (w-new_w)/2, (h-new_h)/2); + free_image(resized); + return boxed; +} + +image resize_max(image im, int max) +{ + int w = im.w; + int h = im.h; + if(w > h){ + h = (h * max) / w; + w = max; + } else { + w = (w * max) / h; + h = max; + } + if(w == im.w && h == im.h) return im; + image resized = resize_image(im, w, h); + return resized; +} + +image resize_min(image im, int min) +{ + int w = im.w; + int h = im.h; + if(w < h){ + h = (h * min) / w; + w = min; + } else { + w = (w * min) / h; + h = min; + } + if(w == im.w && h == im.h) return im; + image resized = resize_image(im, w, h); + return resized; +} + +image random_crop_image(image im, int w, int h) +{ + int dx = rand_int(0, im.w - w); + int dy = rand_int(0, im.h - h); + image crop = crop_image(im, dx, dy, w, h); + return crop; +} + +augment_args random_augment_args(image im, float angle, float aspect, int low, int high, int w, int h) +{ + augment_args a = {0}; + aspect = rand_scale(aspect); + int r = rand_int(low, high); + int min = (im.h < im.w*aspect) ? im.h : im.w*aspect; + float scale = (float)r / min; + + float rad = rand_uniform(-angle, angle) * TWO_PI / 360.; + + float dx = (im.w*scale/aspect - w) / 2.; + float dy = (im.h*scale - w) / 2.; + //if(dx < 0) dx = 0; + //if(dy < 0) dy = 0; + dx = rand_uniform(-dx, dx); + dy = rand_uniform(-dy, dy); + + a.rad = rad; + a.scale = scale; + a.w = w; + a.h = h; + a.dx = dx; + a.dy = dy; + a.aspect = aspect; + return a; +} + +image random_augment_image(image im, float angle, float aspect, int low, int high, int w, int h) +{ + augment_args a = random_augment_args(im, angle, aspect, low, high, w, h); + image crop = rotate_crop_image(im, a.rad, a.scale, a.w, a.h, a.dx, a.dy, a.aspect); + return crop; +} + +float three_way_max(float a, float b, float c) +{ + return (a > b) ? ( (a > c) ? a : c) : ( (b > c) ? b : c) ; +} + +float three_way_min(float a, float b, float c) +{ + return (a < b) ? ( (a < c) ? a : c) : ( (b < c) ? b : c) ; +} + +void yuv_to_rgb(image im) +{ + assert(im.c == 3); + int i, j; + float r, g, b; + float y, u, v; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + y = get_pixel(im, i , j, 0); + u = get_pixel(im, i , j, 1); + v = get_pixel(im, i , j, 2); + + r = y + 1.13983*v; + g = y + -.39465*u + -.58060*v; + b = y + 2.03211*u; + + set_pixel(im, i, j, 0, r); + set_pixel(im, i, j, 1, g); + set_pixel(im, i, j, 2, b); + } + } +} + +void rgb_to_yuv(image im) +{ + assert(im.c == 3); + int i, j; + float r, g, b; + float y, u, v; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + r = get_pixel(im, i , j, 0); + g = get_pixel(im, i , j, 1); + b = get_pixel(im, i , j, 2); + + y = .299*r + .587*g + .114*b; + u = -.14713*r + -.28886*g + .436*b; + v = .615*r + -.51499*g + -.10001*b; + + set_pixel(im, i, j, 0, y); + set_pixel(im, i, j, 1, u); + set_pixel(im, i, j, 2, v); + } + } +} + +// http://www.cs.rit.edu/~ncs/color/t_convert.html +void rgb_to_hsv(image im) +{ + assert(im.c == 3); + int i, j; + float r, g, b; + float h, s, v; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + r = get_pixel(im, i , j, 0); + g = get_pixel(im, i , j, 1); + b = get_pixel(im, i , j, 2); + float max = three_way_max(r,g,b); + float min = three_way_min(r,g,b); + float delta = max - min; + v = max; + if(max == 0){ + s = 0; + h = 0; + }else{ + s = delta/max; + if(r == max){ + h = (g - b) / delta; + } else if (g == max) { + h = 2 + (b - r) / delta; + } else { + h = 4 + (r - g) / delta; + } + if (h < 0) h += 6; + h = h/6.; + } + set_pixel(im, i, j, 0, h); + set_pixel(im, i, j, 1, s); + set_pixel(im, i, j, 2, v); + } + } +} + +void hsv_to_rgb(image im) +{ + assert(im.c == 3); + int i, j; + float r, g, b; + float h, s, v; + float f, p, q, t; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + h = 6 * get_pixel(im, i , j, 0); + s = get_pixel(im, i , j, 1); + v = get_pixel(im, i , j, 2); + if (s == 0) { + r = g = b = v; + } else { + int index = floor(h); + f = h - index; + p = v*(1-s); + q = v*(1-s*f); + t = v*(1-s*(1-f)); + if(index == 0){ + r = v; g = t; b = p; + } else if(index == 1){ + r = q; g = v; b = p; + } else if(index == 2){ + r = p; g = v; b = t; + } else if(index == 3){ + r = p; g = q; b = v; + } else if(index == 4){ + r = t; g = p; b = v; + } else { + r = v; g = p; b = q; + } + } + set_pixel(im, i, j, 0, r); + set_pixel(im, i, j, 1, g); + set_pixel(im, i, j, 2, b); + } + } +} + +void grayscale_image_3c(image im) +{ + assert(im.c == 3); + int i, j, k; + float scale[] = {0.299, 0.587, 0.114}; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + float val = 0; + for(k = 0; k < 3; ++k){ + val += scale[k]*get_pixel(im, i, j, k); + } + im.data[0*im.h*im.w + im.w*j + i] = val; + im.data[1*im.h*im.w + im.w*j + i] = val; + im.data[2*im.h*im.w + im.w*j + i] = val; + } + } +} + +image grayscale_image(image im) +{ + assert(im.c == 3); + int i, j, k; + image gray = make_image(im.w, im.h, 1); + float scale[] = {0.299, 0.587, 0.114}; + for(k = 0; k < im.c; ++k){ + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + gray.data[i+im.w*j] += scale[k]*get_pixel(im, i, j, k); + } + } + } + return gray; +} + +image threshold_image(image im, float thresh) +{ + int i; + image t = make_image(im.w, im.h, im.c); + for(i = 0; i < im.w*im.h*im.c; ++i){ + t.data[i] = im.data[i]>thresh ? 1 : 0; + } + return t; +} + +image blend_image(image fore, image back, float alpha) +{ + assert(fore.w == back.w && fore.h == back.h && fore.c == back.c); + image blend = make_image(fore.w, fore.h, fore.c); + int i, j, k; + for(k = 0; k < fore.c; ++k){ + for(j = 0; j < fore.h; ++j){ + for(i = 0; i < fore.w; ++i){ + float val = alpha * get_pixel(fore, i, j, k) + + (1 - alpha)* get_pixel(back, i, j, k); + set_pixel(blend, i, j, k, val); + } + } + } + return blend; +} + +void scale_image_channel(image im, int c, float v) +{ + int i, j; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + float pix = get_pixel(im, i, j, c); + pix = pix*v; + set_pixel(im, i, j, c, pix); + } + } +} + +void translate_image_channel(image im, int c, float v) +{ + int i, j; + for(j = 0; j < im.h; ++j){ + for(i = 0; i < im.w; ++i){ + float pix = get_pixel(im, i, j, c); + pix = pix+v; + set_pixel(im, i, j, c, pix); + } + } +} + +image binarize_image(image im) +{ + image c = copy_image(im); + int i; + for(i = 0; i < im.w * im.h * im.c; ++i){ + if(c.data[i] > .5) c.data[i] = 1; + else c.data[i] = 0; + } + return c; +} + +void saturate_image(image im, float sat) +{ + rgb_to_hsv(im); + scale_image_channel(im, 1, sat); + hsv_to_rgb(im); + constrain_image(im); +} + +void hue_image(image im, float hue) +{ + rgb_to_hsv(im); + int i; + for(i = 0; i < im.w*im.h; ++i){ + im.data[i] = im.data[i] + hue; + if (im.data[i] > 1) im.data[i] -= 1; + if (im.data[i] < 0) im.data[i] += 1; + } + hsv_to_rgb(im); + constrain_image(im); +} + +void exposure_image(image im, float sat) +{ + rgb_to_hsv(im); + scale_image_channel(im, 2, sat); + hsv_to_rgb(im); + constrain_image(im); +} + +void distort_image(image im, float hue, float sat, float val) +{ + rgb_to_hsv(im); + scale_image_channel(im, 1, sat); + scale_image_channel(im, 2, val); + int i; + for(i = 0; i < im.w*im.h; ++i){ + im.data[i] = im.data[i] + hue; + if (im.data[i] > 1) im.data[i] -= 1; + if (im.data[i] < 0) im.data[i] += 1; + } + hsv_to_rgb(im); + constrain_image(im); +} + +void random_distort_image(image im, float hue, float saturation, float exposure) +{ + float dhue = rand_uniform(-hue, hue); + float dsat = rand_scale(saturation); + float dexp = rand_scale(exposure); + distort_image(im, dhue, dsat, dexp); +} + +void saturate_exposure_image(image im, float sat, float exposure) +{ + rgb_to_hsv(im); + scale_image_channel(im, 1, sat); + scale_image_channel(im, 2, exposure); + hsv_to_rgb(im); + constrain_image(im); +} + +image resize_image(image im, int w, int h) +{ + image resized = make_image(w, h, im.c); + image part = make_image(w, im.h, im.c); + int r, c, k; + float w_scale = (float)(im.w - 1) / (w - 1); + float h_scale = (float)(im.h - 1) / (h - 1); + for(k = 0; k < im.c; ++k){ + for(r = 0; r < im.h; ++r){ + for(c = 0; c < w; ++c){ + float val = 0; + if(c == w-1 || im.w == 1){ + val = get_pixel(im, im.w-1, r, k); + } else { + float sx = c*w_scale; + int ix = (int) sx; + float dx = sx - ix; + val = (1 - dx) * get_pixel(im, ix, r, k) + dx * get_pixel(im, ix+1, r, k); + } + set_pixel(part, c, r, k, val); + } + } + } + for(k = 0; k < im.c; ++k){ + for(r = 0; r < h; ++r){ + float sy = r*h_scale; + int iy = (int) sy; + float dy = sy - iy; + for(c = 0; c < w; ++c){ + float val = (1-dy) * get_pixel(part, c, iy, k); + set_pixel(resized, c, r, k, val); + } + if(r == h-1 || im.h == 1) continue; + for(c = 0; c < w; ++c){ + float val = dy * get_pixel(part, c, iy+1, k); + add_pixel(resized, c, r, k, val); + } + } + } + + free_image(part); + return resized; +} + + +void test_resize(char *filename) +{ + image im = load_image(filename, 0,0, 3); + float mag = mag_array(im.data, im.w*im.h*im.c); + printf("L2 Norm: %f\n", mag); + image gray = grayscale_image(im); + + image c1 = copy_image(im); + image c2 = copy_image(im); + image c3 = copy_image(im); + image c4 = copy_image(im); + distort_image(c1, .1, 1.5, 1.5); + distort_image(c2, -.1, .66666, .66666); + distort_image(c3, .1, 1.5, .66666); + distort_image(c4, .1, .66666, 1.5); + + + show_image(im, "Original", 1); + show_image(gray, "Gray", 1); + show_image(c1, "C1", 1); + show_image(c2, "C2", 1); + show_image(c3, "C3", 1); + show_image(c4, "C4", 1); +#ifdef OPENCV + while(1){ + image aug = random_augment_image(im, 0, .75, 320, 448, 320, 320); + show_image(aug, "aug", 1); + free_image(aug); + + + float exposure = 1.15; + float saturation = 1.15; + float hue = .05; + + image c = copy_image(im); + + float dexp = rand_scale(exposure); + float dsat = rand_scale(saturation); + float dhue = rand_uniform(-hue, hue); + + distort_image(c, dhue, dsat, dexp); + show_image(c, "rand", 1); + printf("%f %f %f\n", dhue, dsat, dexp); + free_image(c); + } +#endif +} + + +image load_image_stb(char *filename, int channels) +{ + int w, h, c; + unsigned char *data = stbi_load(filename, &w, &h, &c, channels); + if (!data) { + fprintf(stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason()); + //printf(stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason()); + exit(0); + } + if(channels) c = channels; + int i,j,k; + image im = make_image(w, h, c); + for(k = 0; k < c; ++k){ + for(j = 0; j < h; ++j){ + for(i = 0; i < w; ++i){ + int dst_index = i + w*j + w*h*k; + int src_index = k + c*i + c*w*j; + im.data[dst_index] = (float)data[src_index]/255.; + } + } + } + if (data) { + free(data); + data = NULL; + } + return im; +} + +image load_image(char *filename, int w, int h, int c) +{ +#ifdef OPENCV + image out = load_image_cv(filename, c); +#else + image out = load_image_stb(filename, c); +#endif + + if((h && w) && (h != out.h || w != out.w)){ + image resized = resize_image(out, w, h); + free_image(out); + out = resized; + } + return out; +} + +image load_image_color(char *filename, int w, int h) +{ + return load_image(filename, w, h, 3); +} + +image get_image_layer(image m, int l) +{ + image out = make_image(m.w, m.h, 1); + int i; + for(i = 0; i < m.h*m.w; ++i){ + out.data[i] = m.data[i+l*m.h*m.w]; + } + return out; +} +void print_image(image m) +{ + int i, j, k; + for(i =0 ; i < m.c; ++i){ + for(j =0 ; j < m.h; ++j){ + for(k = 0; k < m.w; ++k){ + printf("%.2lf, ", m.data[i*m.h*m.w + j*m.w + k]); + if(k > 30) break; + } + printf("\n"); + if(j > 30) break; + } + printf("\n"); + } + printf("\n"); +} + +image collapse_images_vert(image *ims, int n) +{ + int color = 1; + int border = 1; + int h,w,c; + w = ims[0].w; + h = (ims[0].h + border) * n - border; + c = ims[0].c; + if(c != 3 || !color){ + w = (w+border)*c - border; + c = 1; + } + + image filters = make_image(w, h, c); + int i,j; + for(i = 0; i < n; ++i){ + int h_offset = i*(ims[0].h+border); + image copy = copy_image(ims[i]); + //normalize_image(copy); + if(c == 3 && color){ + embed_image(copy, filters, 0, h_offset); + } + else{ + for(j = 0; j < copy.c; ++j){ + int w_offset = j*(ims[0].w+border); + image layer = get_image_layer(copy, j); + embed_image(layer, filters, w_offset, h_offset); + free_image(layer); + } + } + free_image(copy); + } + return filters; +} + +image collapse_images_horz(image *ims, int n) +{ + int color = 1; + int border = 1; + int h,w,c; + int size = ims[0].h; + h = size; + w = (ims[0].w + border) * n - border; + c = ims[0].c; + if(c != 3 || !color){ + h = (h+border)*c - border; + c = 1; + } + + image filters = make_image(w, h, c); + int i,j; + for(i = 0; i < n; ++i){ + int w_offset = i*(size+border); + image copy = copy_image(ims[i]); + //normalize_image(copy); + if(c == 3 && color){ + embed_image(copy, filters, w_offset, 0); + } + else{ + for(j = 0; j < copy.c; ++j){ + int h_offset = j*(size+border); + image layer = get_image_layer(copy, j); + embed_image(layer, filters, w_offset, h_offset); + free_image(layer); + } + } + free_image(copy); + } + return filters; +} + +void show_image_normalized(image im, const char *name) +{ + image c = copy_image(im); + normalize_image(c); + show_image(c, name, 1); + free_image(c); +} + +void show_images(image *ims, int n, char *window) +{ + image m = collapse_images_vert(ims, n); + /* + int w = 448; + int h = ((float)m.h/m.w) * 448; + if(h > 896){ + h = 896; + w = ((float)m.w/m.h) * 896; + } + image sized = resize_image(m, w, h); + */ + normalize_image(m); + save_image(m, window); + show_image(m, window, 1); + free_image(m); +} + +void free_image(image m) +{ + printf("\nfree_image\n"); + if(m.data) + { + printf("\nfree_image1\n"); + if (m.data) { + free(m.data); + m.data = NULL; + } + printf("\nfree_image2\n"); + } + printf("\nfree_image3\n"); +} diff --git a/src/image.h b/src/image.h new file mode 100644 index 0000000..593fbb3 --- /dev/null +++ b/src/image.h @@ -0,0 +1,140 @@ +#pragma once +#ifndef IMAGE_H +#define IMAGE_H +#include "define_inc.h" +#include <stdlib.h> +#include <stdio.h> +#include <float.h> +#include <string.h> +#include <math.h> +#include "box.h" +#include "darknet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int w; + int h; + int c; + float *data; +} image; + +#ifdef OPENCV +void *open_video_stream(const char *f, int c, int w, int h, int fps); +image get_image_from_stream(void *p); +image load_image_cv(char *filename, int channels); +int show_image_cv(image im, const char* name, int ms); +#endif + +typedef enum { + PNG, BMP, TGA, JPG +} IMTYPE; + +float get_color(int c, int x, int max); +void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b); +void draw_bbox(image a, box bbox, int w, float r, float g, float b); +void write_label(image a, int r, int c, image *characters, char *string, float *rgb); +image image_distance(image a, image b); +void scale_image(image m, float s); +image rotate_crop_image(image im, float rad, float s, int w, int h, float dx, float dy, float aspect); +image random_crop_image(image im, int w, int h); +image random_augment_image(image im, float angle, float aspect, int low, int high, int w, int h); +augment_args random_augment_args(image im, float angle, float aspect, int low, int high, int w, int h); +void letterbox_image_into(image im, int w, int h, image boxed); +image resize_max(image im, int max); +void translate_image(image m, float s); +void embed_image(image source, image dest, int dx, int dy); +void place_image(image im, int w, int h, int dx, int dy, image canvas); +void saturate_image(image im, float sat); +void exposure_image(image im, float sat); +void distort_image(image im, float hue, float sat, float val); +void saturate_exposure_image(image im, float sat, float exposure); +void rgb_to_hsv(image im); +void hsv_to_rgb(image im); +void yuv_to_rgb(image im); +void rgb_to_yuv(image im); + + +image collapse_image_layers(image source, int border); +image collapse_images_horz(image *ims, int n); +image collapse_images_vert(image *ims, int n); + +void show_image_normalized(image im, const char *name); +void show_images(image *ims, int n, char *window); +void show_image_layers(image p, char *name); +void show_image_collapsed(image p, char *name); + +void print_image(image m); + +image make_empty_image(int w, int h, int c); +void copy_image_into(image src, image dest); + +image get_image_layer(image m, int l); + +void save_image_options(image im, const char *name, IMTYPE f, int quality); + +int best_3d_shift_r(image a, image b, int min, int max); + +image get_label(image **characters, char *string, int size); +void draw_label(image a, int r, int c, image label, const float *rgb); +void save_image(image im, const char *name); + +void grayscale_image_3c(image im); +void normalize_image(image p); + +void rgbgr_image(image im); + + +image make_random_image(int w, int h, int c); + + +image load_image(char *filename, int w, int h, int c); +image load_image_color(char *filename, int w, int h); +image make_image(int w, int h, int c); +image resize_image(image im, int w, int h); +void censor_image(image im, int dx, int dy, int w, int h); +image letterbox_image(image im, int w, int h); +image crop_image(image im, int dx, int dy, int w, int h); +image center_crop_image(image im, int w, int h); +image resize_min(image im, int min); +image resize_max(image im, int max); +image threshold_image(image im, float thresh); +image mask_to_rgb(image mask); + +int show_image(image p, const char *name, int ms); +image copy_image(image p); +void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b); + + +void constrain_image(image im); + +void flip_image(image a); +image float_to_image(int w, int h, int c, float *data); +void ghost_image(image source, image dest, int dx, int dy); + +void random_distort_image(image im, float hue, float saturation, float exposure); +void fill_image(image m, float s); +image grayscale_image(image im); +void rotate_image_cw(image im, int times); +double what_time_is_it_now(); +image rotate_image(image m, float rad); + + +image **load_alphabet(); + +void test_resize(char *filename); + +void composite_3d(char *f1, char *f2, char *out, int delta); + +void free_image(image m); + +void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/image_opencv.cpp b/src/image_opencv.cpp new file mode 100644 index 0000000..a80fe9e --- /dev/null +++ b/src/image_opencv.cpp @@ -0,0 +1,142 @@ +#define OPENCV +#ifdef OPENCV + +#include "stdio.h" +#include "stdlib.h" +#include "opencv2/opencv.hpp" +#include "image.h" + +#include <highgui.h> + +using namespace cv; + +extern "C" { + +IplImage *image_to_ipl(image im) +{ + int x,y,c; + IplImage *disp = cvCreateImage(cvSize(im.w,im.h), IPL_DEPTH_8U, im.c); + int step = disp->widthStep; + for(y = 0; y < im.h; ++y){ + for(x = 0; x < im.w; ++x){ + for(c= 0; c < im.c; ++c){ + float val = im.data[c*im.h*im.w + y*im.w + x]; + disp->imageData[y*step + x*im.c + c] = (unsigned char)(val*255); + } + } + } + return disp; +} + +image ipl_to_image(IplImage* src) +{ + int h = src->height; + int w = src->width; + int c = src->nChannels; + image im = make_image(w, h, c); + unsigned char *data = (unsigned char *)src->imageData; + int step = src->widthStep; + int i, j, k; + + for(i = 0; i < h; ++i){ + for(k= 0; k < c; ++k){ + for(j = 0; j < w; ++j){ + im.data[k*w*h + i*w + j] = data[i*step + j*c + k]/255.; + } + } + } + return im; +} + +Mat image_to_mat(image im) +{ + image copy = copy_image(im); + constrain_image(copy); + if(im.c == 3) rgbgr_image(copy); + + IplImage *ipl = image_to_ipl(copy); + Mat m = cvarrToMat(ipl, true); + cvReleaseImage(&ipl); + free_image(copy); + return m; +} + +image mat_to_image(Mat m) +{ +#ifdef GY_OS_WIN + IplImage ipl = m; +#elif defined GY_OS_AMBA + IplImage ipl = cvIplImage(m); +#endif + image im = ipl_to_image(&ipl); + rgbgr_image(im); + return im; +} + +void *open_video_stream(const char *f, int c, int w, int h, int fps) +{ + VideoCapture *cap; + if(f) cap = new VideoCapture(f); + else cap = new VideoCapture(c); + if(!cap->isOpened()) return 0; + if(w) cap->set(CV_CAP_PROP_FRAME_WIDTH, w); + if(h) cap->set(CV_CAP_PROP_FRAME_HEIGHT, w); + if(fps) cap->set(CV_CAP_PROP_FPS, w); + return (void *) cap; +} + +image get_image_from_stream(void *p) +{ + VideoCapture *cap = (VideoCapture *)p; + Mat m; + *cap >> m; + if(m.empty()) return make_empty_image(0,0,0); + return mat_to_image(m); +} + +image load_image_cv(char *filename, int channels) +{ + int flag = -1; + if (channels == 0) flag = -1; + else if (channels == 1) flag = 0; + else if (channels == 3) flag = 1; + else { + fprintf(stderr, "OpenCV can't force load with %d channels\n", channels); + } + Mat m; + m = imread(filename, flag); + if(!m.data){ + fprintf(stderr, "Cannot load image \"%s\"\n", filename); + char buff[256]; + sprintf(buff, "echo %s >> bad.list", filename); + system(buff); + return make_image(10,10,3); + //exit(0); + } + image im = mat_to_image(m); + return im; +} + +int show_image_cv(image im, const char* name, int ms) +{ + Mat m = image_to_mat(im); + imshow(name, m); + int c = waitKey(ms); + if (c != -1) c = c%256; + return c; +} + +void make_window(char *name, int w, int h, int fullscreen) +{ + namedWindow(name, WINDOW_NORMAL); + if (fullscreen) { + setWindowProperty(name, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); + } else { + resizeWindow(name, w, h); + if(strcmp(name, "Demo") == 0) moveWindow(name, 0, 0); + } +} + +} + +#endif diff --git a/src/iniReader.cpp b/src/iniReader.cpp new file mode 100644 index 0000000..1e71520 --- /dev/null +++ b/src/iniReader.cpp @@ -0,0 +1,148 @@ +#if 1 + +#include <string.h> +#ifdef WIN32 +#include <Windows.h> +#include <stdio.h> +#else +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#endif +#include "iniReader.h" +#include "utility.h" +char g_szConfigPath[MAX_PATH]; + +int GetCurrentPath(char buf[],char *pFileName) +{ +#ifdef WIN32 + GetModuleFileNameA(NULL,buf,MAX_PATH); +#else + char pidfile[64]; + int bytes; + int fd; + sprintf(pidfile, "/proc/%d/cmdline", getpid()); + + fd = open(pidfile, O_RDONLY, 0); + bytes = read(fd, buf, 256); + printf("[iniReader] %d read from file %s.\n", bytes, pidfile); + close(fd); + buf[MAX_PATH] = '\0'; +#endif + char * p = &buf[strlen(buf)]; + do + { + *p = '\0'; + p--; +#ifdef WIN32 + } while( '\\' != *p ); +#else + } while( '/' != *p ); +#endif + p++; + + memcpy(p,pFileName,strlen(pFileName)); + return 0; +} + +//read string from ini file +char *GetIniKeyString(char *section,char *key,char *filename) +{ + FILE *fp; + char szLine[1024]; + static char tmpstr[1024]; + int rtnval; + int i = 0; + int flag = 0; + char *tmp; + if((fp = fopen(filename, "r")) == NULL) + { + printf("[iniReader] File not found!\n"); + return NULL; + } + + while(!feof(fp)) + { + rtnval = fgetc(fp); + if(rtnval == EOF) + { + break; + } + else + { + szLine[i++] = rtnval; + } + if(rtnval == '\n') + { +#ifndef WIN32 + i--; +#endif + szLine[--i] = '\0'; + //DumpHex(szLine,10); + i = 0; + tmp = strchr(szLine, '='); + if(( tmp != NULL )&&(flag == 1)) + { + char keyName[128] = { 0 }; + strncpy(keyName, szLine, tmp - szLine); + if(strcmp(keyName,key)==0) + { + /*if (strcmp("53", key) == 0) + { + DumpHex(szLine, 10); + DumpHex(key, 10); + }*/ + //remark + if (';' == szLine[0]) + { + } + else + { + //copy the key value + memset(tmpstr, 0x00, sizeof(tmpstr)); + strcpy(tmpstr,tmp+1); + fclose(fp); + return tmpstr; + } + } + } + else + { + //remark + if (';' == szLine[0]) + { + } + + if (szLine[0] == '[' && szLine[strlen(szLine)-1] == ']') + { + strcpy(tmpstr, section); + if (strncmp(tmpstr, szLine, strlen(tmpstr)) == 0) + { + //find section + flag = 1; + } + else + { + int pre_flag = flag; + flag = 0; + if (pre_flag == 1) + break; + } + } + } + } + } + fclose(fp); + return NULL; +} + +//read int value from ini file +int GetIniKeyInt(char *section,char *key,char *filename) +{ + return atoi(GetIniKeyString(section,key,filename)); +} + +#endif + diff --git a/src/iniReader.h b/src/iniReader.h new file mode 100644 index 0000000..b2204e6 --- /dev/null +++ b/src/iniReader.h @@ -0,0 +1,23 @@ +#if 1 + +#pragma once +#ifndef INIREADER_H +#define INIREADER_H + + +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" +#define INI_FILE_PATH "/emmc/plugin/Aida_data/trans.names" +#define MAX_SECTION_VARIABLE 400 + + int GetCurrentPath(char buf[], char *pFileName); + char *GetIniKeyString(char *section, char *key, char *filename); + int GetIniKeyInt(char *title, char *key, char *filename); +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/intLib.c b/src/intLib.c new file mode 100644 index 0000000..dc97ab9 --- /dev/null +++ b/src/intLib.c @@ -0,0 +1,52 @@ +#if 1 +int tolower_w(int c) +{ + if (c >= 'A' && c <= 'Z') + { + return c + 'a' - 'A'; + } + else + { + return c; + } +} +#endif + +#if 1 +int htoi_w(char s[], int start, int len) +{ + int i, j; + int n = 0; + if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) //P_O_0x || 0X + { + i = 2; + } + else + { + i = 0; + } + i += start; + j = 0; + for (; (s[i] >= '0' && s[i] <= '9') + || (s[i] >= 'a' && s[i] <= 'f') || (s[i] >= 'A' && s[i] <= 'F'); ++i) + { + if (j >= len) + { + break; + } + if (tolower_w(s[i]) > '9') + { + n = 16 * n + (10 + tolower_w(s[i]) - 'a'); + } + else + { + n = 16 * n + (tolower_w(s[i]) - '0'); + } + j++; + } + + //printf("%d - ", n); + + return n; +} +#endif \ No newline at end of file diff --git a/src/intLib.h b/src/intLib.h new file mode 100644 index 0000000..00a3c34 --- /dev/null +++ b/src/intLib.h @@ -0,0 +1,7 @@ +#pragma once +#ifndef _INT_LIB_H_ +#define _INT_LIB_H_ +#include "define_inc.h" +int htoi_w(char s[], int start, int len); + +#endif diff --git a/src/ir_control.c b/src/ir_control.c new file mode 100644 index 0000000..eb638de --- /dev/null +++ b/src/ir_control.c @@ -0,0 +1,371 @@ + +#include "ir_control.h" + +pthread_t ir_status_thread; + +ImageDn g_stIRinfo; + +size_t ir_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream) { + /* + time_t timep; + struct tm * timeinfo; + time(&timep); + timeinfo = localtime(&timep); + */ + size_t realsize = size * nmemb; + //cJSON *r_root, *r_tstamp; + + //time_t r_timep; + //struct tm * r_timeinfo; + //time(&timep); + if (stream) + { + //printf("Magic: %s \n", (char *)stream); + //free(stream); + + sprintf((char *)stream, "%s", (char *)ptr); + return realsize; + } + else + { + return 0; + } + + //printf(">>>>>>>>>>>>> Get PTZ Curl resp:\n %s \n", (char *)ptr); + //printf(">>>>>>>>>>>>> Response Time: %d-%02d-%02d ", (1900 + timeinfo->tm_year), (1 + timeinfo->tm_mon), timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + +} + +int ir_curl_status_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id) +{ + pthread_mutex_lock(&mutex_curl); + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + //CURL *curl = NULL; + + int l_ret = -1; + //const int timeout = 30000; + //const int timeout = 100; + //char *sBuffer; + //char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + //curl = curl_easy_init(); + + + + //char response_data[512] = { 0 }; + //char *response_data; + //response_data = malloc(512); + //strcat(response_data, "mmmmmmmmmmmmmmagic"); + + char temp_sOutputData[1024] = { 0 }; + + if (g_http_handle != NULL) + { + struct curl_slist *pList = NULL; + //if (strcmp(method, "POST") == 0) + //{ + //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //} + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + //time_t s_timep = time(0); + //struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + //char test_countent[25] = { 0 }; + //strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, ir_cmd_curl_callback); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, temp_sOutputData); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L); + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + //if (strcmp(method, "POST") == 0) + //{ + //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, sData); + //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, strlen(sData)); + //curl_easy_setopt(g_http_handle, CURLOPT_POST, 1L); + //} + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + CURLcode l_res = curl_easy_perform(g_http_handle); + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s:%s", curl_easy_strerror(l_res), function_id); + write_to_logs_html(temp_msg, "curl to ir status", "ERROR", SystemSetting.enable_system_logs); + l_ret = -1; + } + else { + strcpy(sOutputData,temp_sOutputData); + //char temp_msg[8192] = { 0 }; + //snprintf(temp_msg,sizeof(temp_msg), "%s:%s", "OK", function_id); + //write_to_logs_html(temp_msg, "curl to ptz status", "DEBUG", SystemSetting.enable_system_logs); + l_ret = 0; + } + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + pList = NULL; + } + + + pthread_mutex_unlock(&mutex_curl); + //usSleep(10000); + return l_ret; +} + + +int ir_send_request(char *sInUrl, char *sOutputMessage) +{ + if (sInUrl == NULL + || sOutputMessage == NULL) + { + return -1; + } + + //char ir_curl_url[512] = { 0 }; + char ir_curl_sendbuf[1] = { 0 }; + char ir_curl_username[128] = { 0 }; + char ir_curl_password[128] = { 0 }; + char *method = "GET"; + + //strcat(ir_curl_url, "http://127.0.0.1/control?get=aiptz"); + strcat(ir_curl_username, accountData[0].account_username); + strcat(ir_curl_password, accountData[0].account_password); + + //int ret = 0; + + //char outputData[1024] = { 0 }; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //char **arr_sOutputDataList; + //int iPTZInfoCount = 0; + //char *del = "\r\n"; + + ir_curl_status_cmd(sInUrl, ir_curl_sendbuf, NULL, method, + ir_curl_username, ir_curl_password, atoi(accountData[0].account_port), sOutputMessage,"ir send request"); + + if (strlen(sOutputMessage) > 0) + { + //printf("====== get ir status: %s \n", sOutputMessage); + } + else + return -1; + + + return 0; +} + +void init_ir_status() { + g_stIRinfo.iAutoModeSwitchCount = 987654; +} + +void reset_ir_status() { + g_stIRinfo.current_day_or_night_mode = 0; + g_stIRinfo.color_mode = -1; +} + +void check_ir_status() { + FILE *fp; + char path[1024] = { 0 }; + char command[1024] = { 0 }; + char sOutputData[1024] = { 0 }; //for case 6 + const char *find = "Data="; + //const char *find2 = "image.dn.luminosity="; + int find_len = 5; + //int find2_len = 20; + + int check_if_finish_all_correctly = 0; + + int num_info = 1; + + { + //memset(path, 0x00, sizeof(path)); + //memset(command, 0x00, sizeof(command)); + + sprintf(command, "timeout 3s /usr/local/bin/nvclient -k DAYORNIGHT"); + + pthread_mutex_lock(&mutex_dn); + fp = vpopen(command, "r"); + if (fp == NULL) { + fp = vpopen(command, "r"); + } + + if (fp == NULL) + { + + printf("\nFailed to run command: %s\n", command); + printf("[get image dn]Error opening file unexist.ent: %s\n", strerror(errno)); + + char fail_buffer[2048] = { 0 }; + sprintf(fail_buffer, "\n[get image dn]Failed to run command #2: %s\n", command); + write_to_log_if_error_nvclient(fail_buffer); + } + else { + + /* Read the output a line at a time - output it.*/ + while (fgets(path, sizeof(path), fp) != NULL) + { + char *p = NULL; + int cpy_len = 0; + + p = strstr(path, find); + if (p != NULL) { + cpy_len = (strlen(path) - find_len - 1);//avoid copy \n + } + + //printf("\n(%d):cpylen:%d\n",i,cpy_len); + if (p != NULL && cpy_len >= 1) + { + char *cpy_start = NULL; + + cpy_start = p + find_len; + + //printf("\n%s strlen(path):%d", p + find_len, strlen(path)); + + if (cpy_start != NULL && cpy_len >= 1) { + char temp_cpy[1024] = { 0 }; + strncpy(temp_cpy, cpy_start, cpy_len); + temp_cpy[cpy_len] = '\0'; + + if (strstr(temp_cpy, " ") == NULL && strlen(temp_cpy) >= 1) { + + if (atoi(temp_cpy) == 1) { + g_stIRinfo.color_mode = 1; + } + else if (atoi(temp_cpy) == 0) { + g_stIRinfo.color_mode = 2; + } + + check_if_finish_all_correctly++; + } + } + + break; + } + memset(path, 0x00, sizeof(path)); + } + + if (fp != NULL) + { + vpclose(fp); + fp = NULL; + } + } + pthread_mutex_unlock(&mutex_dn); + } + + //color_mode = switch mode + //0: Auto, 1: Day, 2: Night, 3: Schedule + + if (check_if_finish_all_correctly == num_info) { + + //If in day mode + if (g_stIRinfo.color_mode == 1) + { + //LED Should be close (Off: Data = 0) + { + //printf("send ri led far off \n"); + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + char cmd1[256] = "http://"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/image?image.irledfarday=0"; + + strcpy(cmd, cmd1); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + /*ret = */ir_send_request(cmd, sOutputData); + } + + { + //printf("ir led near status error ! \n"); + //printf("send ri led near off \n"); + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + char cmd1[256] = "http://"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/image?image.irlednearday=0"; + + strcpy(cmd, cmd1); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + /*ret = */ir_send_request(cmd, sOutputData); + } + }//If in day mode + + }//If get all info +} + +int get_color_mode() { + return g_stIRinfo.color_mode; +} + +void *check_ir_status_thread() { + pthread_detach(pthread_self()); + setPthreadName("check_ir"); + init_ir_status(); + + reset_ir_status(); + + while (get_live_mode_flag()) + { + //printf("\nrun ir status thread \n"); + check_ir_status(); + usSleep(10000000); + } + + pthread_exit(NULL); +} + +void run_ir_status_thread() { + if (pthread_create(&ir_status_thread, 0, check_ir_status_thread, NULL)) + { + printf("\npthread create check ir status thread fail\n"); + } +} diff --git a/src/ir_control.h b/src/ir_control.h new file mode 100644 index 0000000..30eb450 --- /dev/null +++ b/src/ir_control.h @@ -0,0 +1,31 @@ +#pragma once +#ifndef IR_CONTROL_H +#define IR_CONTROL_H +#include "define_inc.h" +#include "utility.h" +#include "setting.h" +#include "network.h" +#include "nweb.h" +#include <math.h> +#include <pthread.h> +#include "ptz.h" +#include "test_nnctrl_live.h" + +#define IR_INFO_NUM 10 + +extern SystemSettingInfo SystemSetting; +extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add +extern CURL* g_http_handle; + +extern pthread_mutex_t mutex_curl; +extern pthread_mutex_t mutex_dn; + +void run_ir_status_thread(); +int ir_send_request(char *sInUrl, char *sOutputMessage); +int get_color_mode(); + +size_t ir_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream); +int ir_curl_status_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id); + +#endif \ No newline at end of file diff --git a/src/iseg_layer.c b/src/iseg_layer.c new file mode 100644 index 0000000..70bb146 --- /dev/null +++ b/src/iseg_layer.c @@ -0,0 +1,227 @@ +#include "iseg_layer.h" +#include "activations.h" +#include "blas.h" +#include "box.h" +#include "cuda.h" +#include "utils.h" + +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +layer make_iseg_layer(int batch, int w, int h, int classes, int ids) +{ + layer l = {0}; + l.type = ISEG; + + l.h = h; + l.w = w; + l.c = classes + ids; + l.out_w = l.w; + l.out_h = l.h; + l.out_c = l.c; + l.classes = classes; + l.batch = batch; + l.extra = ids; + l.cost = calloc(1, sizeof(float)); + l.outputs = h*w*l.c; + l.inputs = l.outputs; + l.truths = 90*(l.w*l.h+1); + l.delta = calloc(batch*l.outputs, sizeof(float)); + l.output = calloc(batch*l.outputs, sizeof(float)); + + l.counts = calloc(90, sizeof(int)); + l.sums = calloc(90, sizeof(float*)); + if(ids){ + int i; + for(i = 0; i < 90; ++i){ + l.sums[i] = calloc(ids, sizeof(float)); + } + } + + l.forward = forward_iseg_layer; + l.backward = backward_iseg_layer; +#ifdef GPU + l.forward_gpu = forward_iseg_layer_gpu; + l.backward_gpu = backward_iseg_layer_gpu; + l.output_gpu = cuda_make_array(l.output, batch*l.outputs); + l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs); +#endif + + fprintf(stderr, "iseg\n"); + srand(0); + + return l; +} + +void resize_iseg_layer(layer *l, int w, int h) +{ + l->w = w; + l->h = h; + + l->outputs = h*w*l->c; + l->inputs = l->outputs; + + l->output = realloc(l->output, l->batch*l->outputs*sizeof(float)); + l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float)); + +#ifdef GPU + cuda_free(l->delta_gpu); + cuda_free(l->output_gpu); + + l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs); + l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs); +#endif +} + +void forward_iseg_layer(const layer l, network net) +{ + + double time = what_time_is_it_now(); + int i,b,j,k; + int ids = l.extra; + memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); + memset(l.delta, 0, l.outputs * l.batch * sizeof(float)); + +#ifndef GPU + for (b = 0; b < l.batch; ++b){ + int index = b*l.outputs; + activate_array(l.output + index, l.classes*l.w*l.h, LOGISTIC); + } +#endif + + for (b = 0; b < l.batch; ++b){ + // a priori, each pixel has no class + for(i = 0; i < l.classes; ++i){ + for(k = 0; k < l.w*l.h; ++k){ + int index = b*l.outputs + i*l.w*l.h + k; + l.delta[index] = 0 - l.output[index]; + } + } + + // a priori, embedding should be small magnitude + for(i = 0; i < ids; ++i){ + for(k = 0; k < l.w*l.h; ++k){ + int index = b*l.outputs + (i+l.classes)*l.w*l.h + k; + l.delta[index] = .1 * (0 - l.output[index]); + } + } + + + memset(l.counts, 0, 90*sizeof(int)); + for(i = 0; i < 90; ++i){ + fill_cpu(ids, 0, l.sums[i], 1); + + int c = net.truth[b*l.truths + i*(l.w*l.h+1)]; + if(c < 0) break; + // add up metric embeddings for each instance + for(k = 0; k < l.w*l.h; ++k){ + int index = b*l.outputs + c*l.w*l.h + k; + float v = net.truth[b*l.truths + i*(l.w*l.h + 1) + 1 + k]; + if(v){ + l.delta[index] = v - l.output[index]; + axpy_cpu(ids, 1, l.output + b*l.outputs + l.classes*l.w*l.h + k, l.w*l.h, l.sums[i], 1); + ++l.counts[i]; + } + } + } + + float *mse = calloc(90, sizeof(float)); + for(i = 0; i < 90; ++i){ + int c = net.truth[b*l.truths + i*(l.w*l.h+1)]; + if(c < 0) break; + for(k = 0; k < l.w*l.h; ++k){ + float v = net.truth[b*l.truths + i*(l.w*l.h + 1) + 1 + k]; + if(v){ + int z; + float sum = 0; + for(z = 0; z < ids; ++z){ + int index = b*l.outputs + (l.classes + z)*l.w*l.h + k; + sum += pow(l.sums[i][z]/l.counts[i] - l.output[index], 2); + } + mse[i] += sum; + } + } + mse[i] /= l.counts[i]; + } + + // Calculate average embedding + for(i = 0; i < 90; ++i){ + if(!l.counts[i]) continue; + scal_cpu(ids, 1.f/l.counts[i], l.sums[i], 1); + if(b == 0 && net.gpu_index == 0){ + printf("%4d, %6.3f, ", l.counts[i], mse[i]); + for(j = 0; j < ids; ++j){ + printf("%6.3f,", l.sums[i][j]); + } + printf("\n"); + } + } + if (mse) { + free(mse); + mse = NULL; + } + // Calculate embedding loss + for(i = 0; i < 90; ++i){ + if(!l.counts[i]) continue; + for(k = 0; k < l.w*l.h; ++k){ + float v = net.truth[b*l.truths + i*(l.w*l.h + 1) + 1 + k]; + if(v){ + for(j = 0; j < 90; ++j){ + if(!l.counts[j])continue; + int z; + for(z = 0; z < ids; ++z){ + int index = b*l.outputs + (l.classes + z)*l.w*l.h + k; + float diff = l.sums[j][z] - l.output[index]; + if (j == i) l.delta[index] += diff < 0? -.1 : .1; + else l.delta[index] += -(diff < 0? -.1 : .1); + } + } + } + } + } + + for(i = 0; i < ids; ++i){ + for(k = 0; k < l.w*l.h; ++k){ + int index = b*l.outputs + (i+l.classes)*l.w*l.h + k; + l.delta[index] *= .01; + } + } + } + + *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2); + printf("took %lf sec\n", what_time_is_it_now() - time); +} + +void backward_iseg_layer(const layer l, network net) +{ + axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void forward_iseg_layer_gpu(const layer l, network net) +{ + copy_gpu(l.batch*l.inputs, net.input_gpu, 1, l.output_gpu, 1); + int b; + for (b = 0; b < l.batch; ++b){ + activate_array_gpu(l.output_gpu + b*l.outputs, l.classes*l.w*l.h, LOGISTIC); + //if(l.extra) activate_array_gpu(l.output_gpu + b*l.outputs + l.classes*l.w*l.h, l.extra*l.w*l.h, LOGISTIC); + } + + cuda_pull_array(l.output_gpu, net.input, l.batch*l.inputs); + forward_iseg_layer(l, net); + cuda_push_array(l.delta_gpu, l.delta, l.batch*l.outputs); +} + +void backward_iseg_layer_gpu(const layer l, network net) +{ + int b; + for (b = 0; b < l.batch; ++b){ + //if(l.extra) gradient_array_gpu(l.output_gpu + b*l.outputs + l.classes*l.w*l.h, l.extra*l.w*l.h, LOGISTIC, l.delta_gpu + b*l.outputs + l.classes*l.w*l.h); + } + axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif + diff --git a/src/iseg_layer.h b/src/iseg_layer.h new file mode 100644 index 0000000..50c5e4b --- /dev/null +++ b/src/iseg_layer.h @@ -0,0 +1,20 @@ +#pragma once +#ifndef ISEG_LAYER_H +#define ISEG_LAYER_H +#include "define_inc.h" +#include "darknet.h" +#include "layer.h" +#include "network.h" + +layer make_iseg_layer(int batch, int w, int h, int classes, int ids); +void forward_iseg_layer(const layer l, network net); +void backward_iseg_layer(const layer l, network net); +void resize_iseg_layer(layer *l, int w, int h); +int iseg_num_detections(layer l, float thresh); + +#ifdef GPU +void forward_iseg_layer_gpu(const layer l, network net); +void backward_iseg_layer_gpu(layer l, network net); +#endif + +#endif diff --git a/src/ivs.cpp b/src/ivs.cpp new file mode 100644 index 0000000..c14b102 --- /dev/null +++ b/src/ivs.cpp @@ -0,0 +1,5627 @@ + +#include <opencv2/opencv.hpp> +#include <opencv2/video.hpp> +#include <opencv2/img_hash.hpp> + +#include "ivs.hpp" +#include "ivsC.h" +#include "utility.h" +#include <sys/time.h> +#include <iostream> +#include <random> + + +using namespace cv; +using namespace std; + +//Ptr<BackgroundSubtractor> g_pMOG2; +int g_count_mog2 = 0; +//Ptr<BackgroundSubtractor> g_pMOG2_2; +int g_count_mog2_2 = 0; + +long last_ms_differ_image_test = 0; +long current_ms_differ_image_test = 0; + +Mat img_background_array_test[MAX_TIME_LENGTH_TEST]; +int store_img_background_array_length_test = 0; +int current_index_img_background_array_test = 0; +int virtual_index_img_background_array_test = 0; + +class MultiLayerMOG2 { +public: + MultiLayerMOG2(int layers, int history) : layers(layers), history(history){ + initialize(); + } + + //~MultiLayerGMM() { + //clearMemory(); // MŰO + //} + + void initialize() { + for (int i = 0; i < layers; ++i) { + // C@hϥΤP MOG2 I + Ptr<BackgroundSubtractor> mog2 = createBackgroundSubtractorMOG2(history, 20, false); + mog2Models.push_back(mog2); + } + + // ]wChoijp + filterSizes = { 5, 3 }; // oijp + //filterSizes = { 3 }; // oijp + } + + void processFrame(const Mat& frame, Mat& fgMask, double learning_rate) { + + double alpha = 0.5; + + Mat combinedMask = Mat::zeros(frame.size(), CV_8UC1); + Mat smoothedFrame; + + // bC@hei氪oi + for (int layer = 0; layer < layers; ++layer) { + // ھڼhƿܬoijp + int kernelSize = filterSizes[layer]; // 15, 9, 3 + GaussianBlur(frame, smoothedFrame, Size(kernelSize, kernelSize), 0); + + Mat layerMask; + // ιh MOG2 ҫ + mog2Models[layer]->apply(smoothedFrame, layerMask, learning_rate); + smoothedFrame.release(); + + // NCheҦX + Mat temp_combinedMask; + if (layer == 0) { + temp_combinedMask = layerMask.clone(); + } + else { + temp_combinedMask = alpha * combinedMask + (1 - alpha) * layerMask; + } + + combinedMask.release(); + layerMask.release(); + + combinedMask = temp_combinedMask.clone(); + temp_combinedMask.release(); + } + + fgMask = combinedMask.clone(); + combinedMask.release(); + } + + void clearMemory() { + mog2Models.clear(); // M MOG2 ҫC + filterSizes.clear(); + } + +private: + int layers; // h + int history; // v + vector<Ptr<BackgroundSubtractor>> mog2Models; // MOG2 ҫC + vector<int> filterSizes; // oijp +}; + +MultiLayerMOG2 g_multiLayerMOG2(2, 500); // 2 hAv׳] 500 +MultiLayerMOG2 g_multiLayerMOG2_2(2, 500); // 2 hAv׳] 500 + +struct IVSHashInfo{ + Rect bbox; + time_t firstSeen; // ɶ + time_t lastSeen; // ̫@sɶ + Mat hash_value; //ƭ +}; + +vector<IVSHashInfo> g_ivs_hash_record; + +Mat generateChecksumUsingHash(Mat& image, Rect region) { + Mat roi = image(region); + Mat hashValue; + //Mat binaryImg; + + //threshold(roi, binaryImg, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU); + + // ϥ pHash kͦ + img_hash::pHash(roi, hashValue); + + // uOdƭȪeӦ줸Aഫ 16 줸 + //unsigned short checksum = hashValue.at<uchar>(0) + (hashValue.at<uchar>(1) << 8); + + //binaryImg.release(); + roi.release(); + + return hashValue; + //return checksum; +} + +double hammingDistance(Mat& hash1, Mat& hash2) { + + Mat diff; + bitwise_xor(hash1, hash2, diff); + + // p XOR GDsӼ + //int hamming_Distance = countNonZero(diff); + double meanDiff = mean(diff)[0]; + + diff.release(); + + return meanDiff; +} + +// ˬdXAä\~td +int isChecksumSimilar(Mat& hash1, Mat& hash2, double tolerance) { + int ret = 0; + if (hash1.size() == hash2.size() && hash1.type() == hash2.type()) { + double distance = hammingDistance(hash1, hash2); + if (distance <= tolerance) { + ret = 1; + } + } + return ret; +} + +void clear_g_ivs_hash_record() { + for (int j = g_ivs_hash_record.size() - 1; j >= 0; --j) { // q᩹eMAקKRɼvT + g_ivs_hash_record[j].hash_value.release(); + g_ivs_hash_record.erase(g_ivs_hash_record.begin() + j); // RŦX󪺨 + } + if (g_ivs_hash_record.empty()) { + g_ivs_hash_record.clear(); // MҦ + g_ivs_hash_record.shrink_to_fit(); // 񥼨ϥΪO + } +} + +void push_back_to_record_hash(Rect region, Mat& region_hash_value) { + + if (g_ivs_hash_record.size() < MAX_QUEUE_HASH_SIZE) + { + IVSHashInfo newHash; + newHash.bbox.x = region.x; + newHash.bbox.y = region.y; + newHash.bbox.width = region.width; + newHash.bbox.height = region.height; + + time_t current_time = time(0); + newHash.firstSeen = current_time; + newHash.lastSeen = current_time; + + newHash.hash_value = region_hash_value.clone(); + + g_ivs_hash_record.push_back(newHash); + } +} + +void pop_not_to_record_hash(time_t current_time) { + // for jˬdO_ݭnM + if (g_ivs_hash_record.size() >= 1) { + for (int j = g_ivs_hash_record.size() - 1; j >= 0; --j) { // q᩹eMAקKRɼvT + double unseenDuration = difftime(current_time, g_ivs_hash_record[j].lastSeen); + if (unseenDuration > 10.0) + { + g_ivs_hash_record[j].hash_value.release(); + g_ivs_hash_record.erase(g_ivs_hash_record.begin() + j); // RŦX󪺨 + } + else { + unseenDuration = difftime(current_time, g_ivs_hash_record[j].firstSeen); + if (unseenDuration > 70.0) + { + g_ivs_hash_record[j].hash_value.release(); + g_ivs_hash_record.erase(g_ivs_hash_record.begin() + j); // RŦX󪺨 + } + } + } + if (g_ivs_hash_record.empty()) { + g_ivs_hash_record.clear(); // MҦ + g_ivs_hash_record.shrink_to_fit(); // 񥼨ϥΪO + } + } +} + +int check_if_ivs_hash_has_been_recorded(Mat& current_ivs_hash) { + int check_if_recorded = 0; + for (int i = 0; i < g_ivs_hash_record.size(); i++) { + if (isChecksumSimilar(current_ivs_hash, g_ivs_hash_record[i].hash_value,3.0)) { + check_if_recorded = 1; + time_t current_time = time(0); + g_ivs_hash_record[i].lastSeen = current_time; + break; + } + } + return check_if_recorded; +} + +float g_progress_bar = -1.0; + +void set_g_progress_bar(int progress_bar) { + g_progress_bar = (float)progress_bar; +} + +int get_g_progress_bar() { + return (int)g_progress_bar; +} + + +float rect_nms(Rect det1, Rect det2) { + float a1 = det1.width * det1.height; + float a2 = det2.width * det2.height; + + float left_nms = det1.x; + float low_nms = det1.y; + float right_nms = det1.x + det1.width; + float high_nms = det1.y + det1.height; + + if (det2.x > left_nms) + left_nms = det2.x; + if ((det2.x + det2.width) < right_nms) + right_nms = (det2.x + det2.width); + if (det2.y > low_nms) + low_nms = det2.y; + if ((det2.y + det2.height) < high_nms) + high_nms = det2.y + det2.height; + + if (left_nms >= right_nms || low_nms >= high_nms) + return 0.0; + + float sa = (right_nms - left_nms) * (high_nms - low_nms); + return sa / (a1 + a2 - sa); +} + +float rect_overlap_ratio_union(Rect det1, Rect det2) +{ + if (det1.x > det2.x + det2.width) { return 0.0; } + if (det1.y > det2.y + det2.height) { return 0.0; } + if (det1.x + det1.width < det2.x) { return 0.0; } + if (det1.y + det1.height < det2.y) { return 0.0; } + float colInt = abs(std::min(det1.x + det1.width, det2.x + det2.width) - std::max(det1.x, det2.x)); + float rowInt = abs(std::min(det1.y + det1.height, det2.y + det2.height) - std::max(det1.y, det2.y)); + float overlapArea = colInt * rowInt; //ۥBn + float area1 = det1.width * det1.height; + float area2 = det2.width * det2.height; + //float smallerArea = (area1 > area2) ? area2 : area1; + //return overlapArea / smallerArea; //ۥBnep + return overlapArea / (area1 + area2 - overlapArea); //ۥBnҥejp[` +} + +float rect_overlap_ratio(Rect det1, Rect det2) +{ + if (det1.x > det2.x + det2.width) { return 0.0; } + if (det1.y > det2.y + det2.height) { return 0.0; } + if (det1.x + det1.width < det2.x) { return 0.0; } + if (det1.y + det1.height < det2.y) { return 0.0; } + float colInt = abs(std::min(det1.x + det1.width, det2.x + det2.width) - std::max(det1.x, det2.x)); + float rowInt = abs(std::min(det1.y + det1.height, det2.y + det2.height) - std::max(det1.y, det2.y)); + float overlapArea = colInt * rowInt; //ۥBn + float area1 = det1.width * det1.height; + float area2 = det2.width * det2.height; + float smallerArea = (area1 > area2) ? area2 : area1; + return overlapArea / smallerArea; //ۥBnep + //return overlapArea / (area1 + area2 - overlapArea); //ۥBnҥejp[` +} + + +void initial_ivs() { + + // l MOG2 Iξ + //int history = 500; // OоvV + //double varThreshold = 20; // ܲH 16 + //bool detectShadows = false; // O_˴v + + //g_pMOG2 = createBackgroundSubtractorMOG2(history, varThreshold, detectShadows); + //g_pMOG2_2 = createBackgroundSubtractorMOG2(history, varThreshold, detectShadows); +} + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +char color_name[NUM_STRINGS_COLOR][MAX_LENGTH_COLOR] = { + {"White"}, + {"Silver"},//test_nnctrl_live.c convert Silver to Gray + {"Darkgray"}, + {"Black"}, + {"Red"}, + {"Yellow"}, + {"Green"}, + {"Cyan"}, + {"Blue"}, + {"Purple"}, + {"Orange"} +}; + +//Cyan id]w0N ŭ +int color_id_array[NUM_STRINGS_COLOR] = { + 9,10,11,8,1,3,4,6,5,7,2 +}; + +long last_ms_differ_image = 0; +long current_ms_differ_image = 0; + +Mat img_background_short_term; +Mat img_background_long_term; + +Mat img_median_short_term; +Mat img_median_long_term; + +Mat img_background_short_term_yuv; +Mat img_background_long_term_yuv; + +Mat img_background_array[MAX_TIME_LENGTH]; +int store_img_background_array_length = 0; +int current_index_img_background_array = 0; +int virtual_index_img_background_array = 0; + +int check_if_compute_median_finish = 1; +int check_if_tempering_happened = 0; +int check_if_tempering_many_times = -100;//TEMPERING_MANY_TIMES + +//int last_day_or_night_mode = -1; //day : 1 ; night : 2 +//int current_day_or_night_mode = -1; //day : 1 ; night : 2 +int record_change_state = 0; + +int current_store_object_x[MAX_NUM_OBJECT] = { 0 }; +int current_store_object_y[MAX_NUM_OBJECT] = { 0 }; +int current_store_object_w[MAX_NUM_OBJECT] = { 0 }; +int current_store_object_h[MAX_NUM_OBJECT] = { 0 }; +int current_store_object_size = 0; + +int last_store_object_x[MAX_NUM_OBJECT] = { 0 }; +int last_store_object_y[MAX_NUM_OBJECT] = { 0 }; +int last_store_object_w[MAX_NUM_OBJECT] = { 0 }; +int last_store_object_h[MAX_NUM_OBJECT] = { 0 }; +int last_store_object_size = 0; + +//int bg_learning_first_to_show = 0; + +int tempering_ready = 0; + +double single_channel_median(Mat channel,int color_max) +{ + double m = (channel.rows*channel.cols) / 2; + int bin = 0; + double med = -1.0; + + int histSize = color_max; + float range[] = { 0, (float)color_max }; + const float* histRange = { range }; + bool uniform = true; + bool accumulate = false; + Mat hist; + calcHist(&channel, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate); + + for (int i = 0; i < histSize && med < 0.0; ++i) + { + bin += cvRound(hist.at< float >(i)); + if (bin > m && med < 0.0) + med = i; + } + + return med; +} + +Mat compute_median(vector<Mat> vec) { + + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + // Note: Expects the image to be CV_8UC3 + Mat medianImg(vec[0].rows, vec[0].cols, CV_8UC3, Scalar(0, 0, 0)); + + //printf("\n-------vec[0].rows:%d\n", vec[0].rows); + //printf("\n-------vec[0].cols:%d\n", vec[0].cols); + + + int row_size = vec[0].rows; + + for (int row = 2; row < row_size; row++) { + for (int col = 0; col < vec[0].cols; col++) { + //if ((row + col) % 3 == 0 || (col % 2 == 0 && row % 3 == 0)) + { + + int record_element_B[256] = { 0 }; + int record_element_G[256] = { 0 }; + int record_element_R[256] = { 0 }; + + for (int imgNumber = 0; imgNumber < (int)vec.size(); imgNumber++) { + int i_B = vec[imgNumber].at<Vec3b>(row, col)[0]; + int i_G = vec[imgNumber].at<Vec3b>(row, col)[1]; + int i_R = vec[imgNumber].at<Vec3b>(row, col)[2]; + + i_B = i_B - (i_B % 3); + i_G = i_G - (i_G % 3); + i_R = i_R - (i_R % 3); + + record_element_B[i_B]++; + record_element_G[i_G]++; + record_element_R[i_R]++; + } + + int i_medianImg_B = -1; + int i_medianImg_G = -1; + int i_medianImg_R = -1; + + int current_count_record_B = 0; + int current_count_record_G = 0; + int current_count_record_R = 0; + + int last_count_record_B = 0; + int last_count_record_G = 0; + int last_count_record_R = 0; + + for (int index_record = 0; index_record < 256; index_record+=3) { + if (record_element_B[index_record] >= 1) { + current_count_record_B += record_element_B[index_record]; + if (last_count_record_B < (int)vec.size() / 2 && current_count_record_B >= (int)vec.size() / 2) { + i_medianImg_B = index_record; + } + last_count_record_B = current_count_record_B; + } + if (record_element_G[index_record] >= 1) { + current_count_record_G += record_element_G[index_record]; + if (last_count_record_G < (int)vec.size() / 2 && current_count_record_G >= (int)vec.size() / 2) { + i_medianImg_G = index_record; + } + last_count_record_G = current_count_record_G; + } + if (record_element_R[index_record] >= 1) { + current_count_record_R += record_element_R[index_record]; + if (last_count_record_R < (int)vec.size() / 2 && current_count_record_R >= (int)vec.size() / 2) { + i_medianImg_R = index_record; + } + last_count_record_R = current_count_record_R; + } + + if (i_medianImg_B >= 0 && i_medianImg_G >= 0 && i_medianImg_R >= 0) { + break; + } + } + + if (i_medianImg_B >= 0) + medianImg.at<Vec3b>(row, col)[0] = i_medianImg_B; + else + medianImg.at<Vec3b>(row, col)[0] = 0; + + if (i_medianImg_G >= 0) + medianImg.at<Vec3b>(row, col)[1] = i_medianImg_G; + else + medianImg.at<Vec3b>(row, col)[1] = 0; + + if (i_medianImg_R >= 0) + medianImg.at<Vec3b>(row, col)[2] = i_medianImg_R; + else + medianImg.at<Vec3b>(row, col)[2] = 0; + } + /*else { + if (col >= 1) { + medianImg.at<Vec3b>(row, col)[0] = medianImg.at<Vec3b>(row, col - 1)[0]; + medianImg.at<Vec3b>(row, col)[1] = medianImg.at<Vec3b>(row, col - 1)[1]; + medianImg.at<Vec3b>(row, col)[2] = medianImg.at<Vec3b>(row, col - 1)[2]; + } + else if(row >= 1) { + medianImg.at<Vec3b>(row, col)[0] = medianImg.at<Vec3b>(row - 1, col)[0]; + medianImg.at<Vec3b>(row, col)[1] = medianImg.at<Vec3b>(row - 1, col)[1]; + medianImg.at<Vec3b>(row, col)[2] = medianImg.at<Vec3b>(row - 1, col)[2]; + } + }*/ + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----compute median ms:%lf\n", dw_FPS_time_delta); + + return medianImg; +} + +int get_store_img_background_array_length_test() { + return store_img_background_array_length_test; +} + +void release_img_background() { + + //if (g_pMOG2 != nullptr) { + //g_pMOG2.release(); + //} + + //if (g_pMOG2_2 != nullptr) { + //g_pMOG2_2.release(); + //} + + // MzO + g_multiLayerMOG2.clearMemory(); + g_multiLayerMOG2_2.clearMemory(); + + for (int i = 0; i < store_img_background_array_length; i++) { + if (!img_background_array[i].empty()) { + img_background_array[i].release(); + } + } + + for (int i = 0; i < store_img_background_array_length_test; i++) { + if (!img_background_array_test[i].empty()) { + img_background_array_test[i].release(); + } + } + + if (!img_background_short_term.empty()) { + img_background_short_term.release(); + } + + if (!img_background_long_term.empty()) { + img_background_long_term.release(); + } + + if (!img_median_short_term.empty()) + img_median_short_term.release(); + + if (!img_median_long_term.empty()) + img_median_long_term.release(); + + if (!img_background_short_term_yuv.empty()) + img_background_short_term_yuv.release(); + + if (!img_background_long_term_yuv.empty()) + img_background_long_term_yuv.release(); + +} + +void run_compute_median() { + //pthread_detach(pthread_self()); + + if (strcmp(viewChannelData[0].ivs_mode, "3") == 0) { + + } + else { + if (store_img_background_array_length >= MAX_SHORT_TERM && strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) { + pthread_mutex_lock(&mutex_compute_median); + check_if_compute_median_finish = 0; + if (store_img_background_array_length >= MAX_SHORT_TERM) { + vector<Mat> frames_short; + vector<Mat> frames_long; + + int size_short_term = MAX_SHORT_TERM <= store_img_background_array_length ? MAX_SHORT_TERM : store_img_background_array_length; + size_short_term -= (1 - (size_short_term % 2)); + for (int i = 0; i < size_short_term; i++) { + int index_short_term = current_index_img_background_array - i; + if (index_short_term < 0) { + index_short_term = store_img_background_array_length + index_short_term; + } + //printf("\n---------index_short_term:%d:%d:%d\n", index_short_term, img_background_array[index_short_term].size().width, img_background_array[index_short_term].size().height); + if (!img_background_array[index_short_term].empty()) + frames_short.push_back(img_background_array[index_short_term]); + //printf("\n---------frames_short:%d:%d:%d\n", i, frames_short[i].size().width, frames_short[i].size().height); + } + //printf("\ndiffer image-------14\n"); + + + if (!img_median_short_term.empty()) + img_median_short_term.release(); + img_median_short_term = compute_median(frames_short); + + //pthread_mutex_lock(&mutex_short_term_yuv); + if (!img_background_short_term_yuv.empty()) + img_background_short_term_yuv.release(); + cvtColor(img_median_short_term, img_background_short_term_yuv, CV_BGR2YUV); + //pthread_mutex_unlock(&mutex_short_term_yuv); + + Mat img_gray_short_term; + //printf("\ndiffer image-------15\n"); + + //Is + //pthread_mutex_lock(&mutex_short_term); + if (!img_background_short_term.empty()) + img_background_short_term.release(); + cvtColor(img_median_short_term, img_gray_short_term, CV_BGR2GRAY); + + img_background_short_term = img_gray_short_term.clone(); + //blur(img_gray_short_term, img_background_short_term, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + + //pthread_mutex_unlock(&mutex_short_term); + + img_gray_short_term.release(); + + //printf("\ndiffer image-------16\n"); + int size_long_term = MAX_LONG_TERM <= store_img_background_array_length ? MAX_LONG_TERM : store_img_background_array_length; + size_long_term -= (1 - (size_long_term % 2)); + int ajust_size_long_term = size_short_term; + if (size_long_term < ajust_size_long_term) { + for (int i = 0; i < size_long_term; i++) { + int index_long_term = current_index_img_background_array - i; + if (index_long_term < 0) { + index_long_term = store_img_background_array_length + index_long_term; + } + //printf("\n---------index_long_term:%d:%d:%d\n", index_long_term, img_background_array[index_long_term].size().width, img_background_array[index_long_term].size().height); + if (!img_background_array[index_long_term].empty()) + frames_long.push_back(img_background_array[index_long_term]); + //printf("\n---------frames_long:%d:%d:%d\n", i, frames_long[i].size().width, frames_long[i].size().height); + } + } + else { + float unit_between_i = (float)size_long_term / (float)ajust_size_long_term; + for (int i = 0; i < ajust_size_long_term; i++) { + int temp_i = (int)((unit_between_i*(float)i)); + int index_long_term = current_index_img_background_array - temp_i; + if (index_long_term < 0) { + index_long_term = store_img_background_array_length + index_long_term; + } + //printf("\n---------index_long_term:%d:%d:%d\n", index_long_term, img_background_array[index_long_term].size().width, img_background_array[index_long_term].size().height); + if (!img_background_array[index_long_term].empty()) + frames_long.push_back(img_background_array[index_long_term]); + //printf("\n---------frames_long:%d:%d:%d\n", i, frames_long[i].size().width, frames_long[i].size().height); + } + } + //printf("\ndiffer image-------17\n"); + + if (!img_median_long_term.empty()) + img_median_long_term.release(); + img_median_long_term = compute_median(frames_long); + + //pthread_mutex_lock(&mutex_long_term_yuv); + if (!img_background_long_term_yuv.empty()) + img_background_long_term_yuv.release(); + cvtColor(img_median_short_term, img_background_long_term_yuv, CV_BGR2YUV); + //pthread_mutex_unlock(&mutex_long_term_yuv); + + Mat img_gray_long_term; + //printf("\ndiffer image-------18\n"); + + //Is + //pthread_mutex_lock(&mutex_long_term); + if (!img_background_long_term.empty()) + img_background_long_term.release(); + cvtColor(img_median_long_term, img_gray_long_term, CV_BGR2GRAY); + + img_background_long_term = img_gray_long_term.clone(); + //blur(img_gray_long_term, img_background_long_term, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + + //pthread_mutex_unlock(&mutex_long_term); + + img_gray_long_term.release(); + + for (int i = 0; i < (int)frames_short.size(); i++) { + frames_short[i].release(); + } + for (int i = 0; i < (int)frames_long.size(); i++) { + frames_long[i].release(); + } + + frames_short.clear(); + frames_long.clear(); + + vector<Mat>().swap(frames_short); + vector<Mat>().swap(frames_long); + + //printf("\n----------frames_short.size():%d\n",(int)frames_short.size()); + + /* + for (int i = 0; i < size_short_term; i++) { + int index_short_term = current_index_img_background_array - i; + if (index_short_term < 0) { + index_short_term = store_img_background_array_length + index_short_term; + } + printf("\n---------after free:index_short_term:%d:%d:%d\n", index_short_term, img_background_array[index_short_term].size().width, img_background_array[index_short_term].size().height); + }*/ + } + check_if_compute_median_finish = 1; + pthread_mutex_unlock(&mutex_compute_median); + + //printf("\ndiffer image-------19\n"); + + } + } + //pthread_exit(NULL); +} + +//int index_rand = 0; +int differ_image_test(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, int i_InSourceOri_w, int i_InSourceOri_h) +{ + if (AI_fps <= 0) { + return 0; + } + else { + + if (strcmp(viewChannelData[0].enable_unknown_object, "No") == 0) { + double temp_time_interval_with_msec = (double)(600.0) / ((double)MAX_SHORT_TERM_TEST - 1.0)*1000.0; //TIME_INTERVAL_WITH_MSEC + + if (store_img_background_array_length_test < MAX_SHORT_TERM_TEST) { + temp_time_interval_with_msec = (double)(60.0) / ((double)MAX_SHORT_TERM_TEST - 1.0)*1000.0; //TIME_INTERVAL_WITH_MSEC + } + + //int temp_AI_fps = AI_fps >= 2 ? AI_fps : 2; + + current_ms_differ_image_test = getCurrentTime(); + + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + + int ivs_width = 80; + int ivs_height = 45; + + Mat temp_img_decode; + temp_img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + + //printf("\n-----%d,%d,%d,%d\n", temp_img_decode.size().width, i_InSourceOri_w, temp_img_decode.size().height, i_InSourceOri_h); + + if (temp_img_decode.size().width != VIEW_WEB_WIDTH_HD || temp_img_decode.size().height != VIEW_WEB_HEIGHT_HD) + { + temp_img_decode.release(); + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + } + else { + + Mat img_decode; + resize(temp_img_decode, img_decode, Size(ivs_width, ivs_height), INTER_NEAREST); + temp_img_decode.release(); + + Mat img_gray; + cvtColor(img_decode, img_gray, CV_BGR2GRAY); + + float ratio_width = (float)i_InSourceOri_w / (float)ivs_width; + float ratio_height = (float)i_InSourceOri_h / (float)ivs_height; + +#if 1 + //Loɶbanner + { + + int mask_width = ivs_width; + int mask_height = ivs_height; + + int banner_filter = 2; + + Mat imageMask(mask_height, mask_width, CV_8UC3, Scalar(0, 0, 0)); + imageMask(Rect(0, banner_filter, mask_width, mask_height - banner_filter)) = Scalar(255, 255, 255); //make rectangle 1 + Mat imageMask_gray; + cvtColor(imageMask, imageMask_gray, CV_BGR2GRAY); + imageMask.release(); + + Mat maskedImage; + bitwise_and(img_gray, imageMask_gray, maskedImage); + imageMask_gray.release(); + img_gray.release(); + img_gray = maskedImage.clone(); + maskedImage.release(); + } +#endif + + Mat currFrame; + currFrame = img_gray.clone(); + + Mat currFrame_blur; + GaussianBlur(currFrame, currFrame_blur, Size(3, 3), 0); + + if (last_ms_differ_image_test == 0 || current_ms_differ_image_test - last_ms_differ_image_test >= (long)temp_time_interval_with_msec) { + + if (store_img_background_array_length_test < MAX_TIME_LENGTH_TEST) { + if (store_img_background_array_length_test == 0) { + last_ms_differ_image_test = 0; + } + img_background_array_test[store_img_background_array_length_test] = currFrame_blur.clone(); + current_index_img_background_array_test = store_img_background_array_length_test; + store_img_background_array_length_test++; + } + else { + if ((int)((current_ms_differ_image_test - last_ms_differ_image_test) / (long)temp_time_interval_with_msec) >= 1) { + //differ_image|ھڦpGcompute_median_threadpӤ[ɡA|hǷUIXiC + for (int count_vir = 0; count_vir < (int)((current_ms_differ_image_test - last_ms_differ_image_test) / (long)temp_time_interval_with_msec); count_vir++) { + img_background_array_test[virtual_index_img_background_array_test].release(); + img_background_array_test[virtual_index_img_background_array_test] = currFrame_blur.clone(); + current_index_img_background_array_test = virtual_index_img_background_array_test; + virtual_index_img_background_array_test++; + if (virtual_index_img_background_array_test >= MAX_TIME_LENGTH_TEST) { + virtual_index_img_background_array_test = 0; + } + } + } + else { + img_background_array_test[virtual_index_img_background_array_test].release(); + img_background_array_test[virtual_index_img_background_array_test] = currFrame_blur.clone(); + current_index_img_background_array_test = virtual_index_img_background_array_test; + virtual_index_img_background_array_test++; + if (virtual_index_img_background_array_test >= MAX_TIME_LENGTH_TEST) { + virtual_index_img_background_array_test = 0; + } + } + } + + if (last_ms_differ_image_test == 0) { + last_ms_differ_image_test = current_ms_differ_image_test; + } + else { + if ((int)((current_ms_differ_image_test - last_ms_differ_image_test) / (long)temp_time_interval_with_msec) >= 1) { + for (int count_vir = 0; count_vir < (int)((current_ms_differ_image_test - last_ms_differ_image_test) / (long)temp_time_interval_with_msec); count_vir++) { + last_ms_differ_image_test = last_ms_differ_image_test + (long)temp_time_interval_with_msec; + } + } + else { + last_ms_differ_image_test = last_ms_differ_image_test + (long)temp_time_interval_with_msec; + } + } + + + } + + if (store_img_background_array_length_test >= MAX_SHORT_TERM_TEST) { + // l +#if 1 + Mat img_thres; + double thresh = 25;//25 + int maxVal = 255; + threshold(currFrame_blur, img_thres, thresh, maxVal, THRESH_BINARY);////THRESH_OTSU THRESH_BINARY + + int dilation_size = 1; + Mat element = getStructuringElement(MORPH_RECT, Size(2 * dilation_size + 1, 2 * dilation_size + 1), Point(dilation_size, dilation_size)); + + Mat recorded_map = Mat::zeros(img_thres.size(), img_thres.type()); + img_thres.release(); +#endif + //Nlvv@i줸ξާ@ + //i = 0 + + for (int i = 0; i < MAX_SHORT_TERM_TEST - (int)(MAX_SHORT_TERM_TEST / 2); i++) { + int index_mat = current_index_img_background_array_test - i; + int index_mat_shift = current_index_img_background_array_test - i - (int)(MAX_SHORT_TERM_TEST / 2); + + if (index_mat < 0) { + index_mat = MAX_TIME_LENGTH_TEST - 1; + } + + if (index_mat_shift < 0) { + index_mat_shift = MAX_TIME_LENGTH_TEST - 1; + } + + Mat img_absdiff_temp, img_thres_temp, img_dilated_temp, img_eroded_temp; + absdiff(img_background_array_test[index_mat], img_background_array_test[index_mat_shift], img_absdiff_temp); + threshold(img_absdiff_temp, img_thres_temp, thresh, maxVal, THRESH_BINARY);////THRESH_OTSU THRESH_BINARY + img_absdiff_temp.release(); + + erode(img_thres_temp, img_eroded_temp, element); + img_thres_temp.release(); + dilate(img_eroded_temp, img_dilated_temp, element); + img_eroded_temp.release(); + + recorded_map += (img_dilated_temp * 2.5 / MAX_SHORT_TERM_TEST);//2.5 + img_dilated_temp.release(); + } + + element.release(); + + if (i_InSourceOri_h >= 1 && i_InSourceOri_w >= 1 && g_framesize_height >= 1 && g_framesize_width >= 1) + { + float temp_framsize_height = (float)g_framesize_height; + float temp_framsize_width = (float)g_framesize_width; + float temp_g_ori_yuv_height = (float)i_InSourceOri_h; + float temp_g_ori_yuv_width = (float)i_InSourceOri_w; + + float ratio_height_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_height / temp_framsize_height; + float ratio_width_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_width / temp_framsize_width; + + float thres_x_min = 0.0; + float thres_x_max = 1.0; + float thres_y_min = 0.0; + float thres_y_max = 1.0; + + float cut_thres_ratio = 0.0; + + if (g_check_if_OK_thermal == 0 && g_IsPTZDevice == 1 && strcmp(SystemSetting.enable_crop_mode, "Yes") == 0) + { + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + thres_x_min += ((1.0 - cut_thres_ratio) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio) / 2.0); + } + else if (ratio_width_g_ori_yuv_to_ai_webpage < ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + thres_y_min += ((1.0 - cut_thres_ratio) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio) / 2.0); + } + } + + vector<Rect> store_rect_contours; + int contours_size = 0; + + //for (int index_slice = 1; index_slice < MAX_SLICE_SIZE; index_slice++) + { + Mat slice_map; + + int index_slice = 1; + + vector<vector<Point>> contours; + + double thresh_slice = 25 + ((maxVal - 25) / (MAX_SLICE_SIZE)) * index_slice; + threshold(recorded_map, slice_map, thresh_slice, maxVal, THRESH_BINARY);////THRESH_OTSU THRESH_BINARY + + findContours(slice_map, contours, noArray(), RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); + slice_map.release(); + + if (g_check_if_OK_thermal == 0 && g_IsPTZDevice == 1 && strcmp(SystemSetting.enable_crop_mode, "Yes") == 0) + { + for (int i = 0; i < (int)contours.size(); i++) { + Rect temp_rect = boundingRect(contours[i]); + if (temp_rect.area() < 10)//50 + { + + } + else { + float rect_left_x = ((float)(temp_rect.x))*ratio_width; + float rect_top_y = ((float)(temp_rect.y))*ratio_height; + float rect_width = ((float)(temp_rect.width))*ratio_width; + float rect_height = ((float)(temp_rect.height))*ratio_height; + + if (rect_left_x < 0) { + rect_width += (rect_left_x - 1); + rect_left_x = 0; + } + + if (rect_top_y < 0) { + rect_height += (rect_top_y - 1); + rect_top_y = 0; + } + + if (rect_left_x + rect_width > temp_g_ori_yuv_width - 1) { + rect_width = temp_g_ori_yuv_width - 1 - rect_left_x; + } + + if (rect_top_y + rect_height > temp_g_ori_yuv_height - 1) { + rect_height = temp_g_ori_yuv_height - 1 - rect_top_y; + } + + //float rect_center_x = rect_left_x + rect_width / 2.0; + //float rect_center_y = rect_top_y + rect_height / 2.0; + + float obj_x_max = (rect_left_x + rect_width) / temp_g_ori_yuv_width; + float obj_x_min = rect_left_x / temp_g_ori_yuv_width; + + float obj_y_max = (rect_top_y + rect_height) / temp_g_ori_yuv_height; + float obj_y_min = rect_top_y / temp_g_ori_yuv_height; + + if (obj_x_max <= thres_x_min || + obj_x_min >= thres_x_max || + obj_y_max <= thres_y_min || + obj_y_min >= thres_y_max) + { + + } + else { + if (obj_x_min < thres_x_min) { + obj_x_min = thres_x_min; + } + + if (obj_x_max > thres_x_max) { + obj_x_max = thres_x_max; + } + + if (obj_y_min < thres_y_min) { + obj_y_min = thres_y_min; + } + + if (obj_y_max > thres_y_max) { + obj_y_max = thres_y_max; + } + + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + float obj_center_x = (obj_x_min + obj_x_max) / 2.0; + float obj_width = (obj_x_max - obj_x_min); + + obj_center_x = (obj_center_x - 0.5) * (1.0 / cut_thres_ratio) + 0.5; + obj_width = obj_width * (1.0 / cut_thres_ratio); + + obj_x_min = obj_center_x - obj_width / 2.0; + obj_x_max = obj_center_x + obj_width / 2.0; + } + else { + float obj_center_y = (obj_y_min + obj_y_max) / 2.0; + float obj_height = (obj_y_max - obj_y_min); + + obj_center_y = (obj_center_y - 0.5) * (1.0 / cut_thres_ratio) + 0.5; + obj_height = obj_height * (1.0 / cut_thres_ratio); + + obj_y_min = obj_center_y - obj_height / 2.0; + obj_y_max = obj_center_y + obj_height / 2.0; + } + + + if (obj_x_min < 0.0) + obj_x_min = 0.0; + + if (obj_x_max > 1.0) + obj_x_max = 1.0; + + if (obj_y_min < 0.0) + obj_y_min = 0.0; + + if (obj_y_max > 1.0) + obj_y_max = 1.0; + + obj_x_min = obj_x_min * (float)i_InSourceOri_w; //1920 + obj_x_max = obj_x_max * (float)i_InSourceOri_w; //1920 + obj_y_min = obj_y_min * (float)i_InSourceOri_h; //1080 + obj_y_max = obj_y_max * (float)i_InSourceOri_h; //1080 + + rect_left_x = obj_x_min; + rect_top_y = obj_y_min; + rect_width = (obj_x_max - obj_x_min); + rect_height = (obj_y_max - obj_y_min); + //rect_center_x = rect_left_x + rect_width / 2.0; + //rect_center_y = rect_top_y + rect_height / 2.0; + + store_rect_contours.push_back(temp_rect); + if (store_rect_contours[contours_size].x < 0) { + store_rect_contours[contours_size].width += (store_rect_contours[contours_size].x - 1); + store_rect_contours[contours_size].x = 0; + } + + if (store_rect_contours[contours_size].y < 0) { + store_rect_contours[contours_size].height += (store_rect_contours[contours_size].y - 1); + store_rect_contours[contours_size].y = 0; + } + + if (store_rect_contours[contours_size].x + store_rect_contours[contours_size].width > ivs_width - 1) { + store_rect_contours[contours_size].width = ivs_width - 1 - store_rect_contours[contours_size].x; + } + + if (store_rect_contours[contours_size].y + store_rect_contours[contours_size].height > ivs_height - 1) { + store_rect_contours[contours_size].height = ivs_height - 1 - store_rect_contours[contours_size].y; + } + + contours_size++; + } + } + contours[i].clear(); + vector<Point>().swap(contours[i]); + } + + //printf("\n----#1---[%d]%d\n", index_slice,contours_size); + } + else { + for (int i = 0; i < (int)contours.size(); i++) { + Rect temp_rect = boundingRect(contours[i]); + if (temp_rect.area() < 10)//50 + { + + } + else { + float rect_left_x = ((float)(temp_rect.x))*ratio_width; + float rect_top_y = ((float)(temp_rect.y))*ratio_height; + float rect_width = ((float)(temp_rect.width))*ratio_width; + float rect_height = ((float)(temp_rect.height))*ratio_height; + + if (rect_left_x < 0) { + rect_width += (rect_left_x - 1); + rect_left_x = 0; + } + + if (rect_top_y < 0) { + rect_height += (rect_top_y - 1); + rect_top_y = 0; + } + + if (rect_left_x + rect_width > temp_g_ori_yuv_width - 1) { + rect_width = temp_g_ori_yuv_width - 1 - rect_left_x; + } + + if (rect_top_y + rect_height > temp_g_ori_yuv_height - 1) { + rect_height = temp_g_ori_yuv_height - 1 - rect_top_y; + } + + //float rect_center_x = rect_left_x + rect_width / 2.0; + //float rect_center_y = rect_top_y + rect_height / 2.0; + + + store_rect_contours.push_back(temp_rect); + if (store_rect_contours[contours_size].x < 0) { + store_rect_contours[contours_size].width += (store_rect_contours[contours_size].x - 1); + store_rect_contours[contours_size].x = 0; + } + + if (store_rect_contours[contours_size].y < 0) { + store_rect_contours[contours_size].height += (store_rect_contours[contours_size].y - 1); + store_rect_contours[contours_size].y = 0; + } + + if (store_rect_contours[contours_size].x + store_rect_contours[contours_size].width > ivs_width - 1) { + store_rect_contours[contours_size].width = ivs_width - 1 - store_rect_contours[contours_size].x; + } + + if (store_rect_contours[contours_size].y + store_rect_contours[contours_size].height > ivs_height - 1) { + store_rect_contours[contours_size].height = ivs_height - 1 - store_rect_contours[contours_size].y; + } + + contours_size++; + + } + contours[i].clear(); + vector<Point>().swap(contours[i]); + } + + //printf("\n----#2---[%d]%d\n", index_slice, contours_size); + } + contours.clear(); + vector<vector<Point>>().swap(contours); + } + + if (contours_size >= 1) { + + + vector<Rect> mergedRectangles; + + for (int i = 0; i < ((int)store_rect_contours.size()) - 1; i++) { + Rect rect1 = store_rect_contours[i]; + if (rect1.width >= 1 && rect1.height >= 1) { + //Mat slice1 = slice_map(rect1); // lx} + + //double BlackRatio_1 = sum(slice1 == 0)[0] / double(rect1.width*rect1.height); + //slice1.release(); + + int merge_ok = 0; + + for (int j = i + 1; j < (int)store_rect_contours.size(); j++) { + Rect rect2 = store_rect_contours[j]; + if (rect2.width >= 1 && rect2.height >= 1) { + Rect unionRect = rect1 & rect2; + double unionArea = double(unionRect.width*unionRect.height); + if (unionArea >= 1) { + { + //Mat sliceUnion = slice_map(unionRect); // plx} + //double BlackRatio_sum = sum(sliceUnion == 0)[0] / unionArea; + //sliceUnion.release(); + + //if (BlackRatio_sum >= BlackRatio_1) + { + rect1 = unionRect; // Merge rect2 into rect1 + //store_rect_contours[i] = rect1; + //store_rect_contours[j] = Rect(); + mergedRectangles.push_back(rect1); + merge_ok = 1; + + } + } + } + } + } + + if (merge_ok == 0) { + mergedRectangles.push_back(rect1); // Add non-merged rectangle to result + } + } + } + + store_rect_contours.clear(); + vector<Rect>().swap(store_rect_contours); + + //printf("\n-----------total_num:%d\n", (int)mergedRectangles.size()); +#if 0 + for (int i = 0; i < (int)mergedRectangles.size(); i++) { + for (int index_motion = 0; index_motion < MAX_MOTION_AREA; index_motion++) { + if (g_Motion_Area_Data[index_motion].used == 0 && g_Motion_Area_Data[index_motion].locked == 0) { + g_Motion_Area_Data[index_motion].locked = 1; + + g_Motion_Area_Data[index_motion].box_x = ((float)(mergedRectangles[i].x))*ratio_width; + g_Motion_Area_Data[index_motion].box_y = ((float)(mergedRectangles[i].y))*ratio_height; + g_Motion_Area_Data[index_motion].box_w = ((float)(mergedRectangles[i].width))*ratio_width; + g_Motion_Area_Data[index_motion].box_h = ((float)(mergedRectangles[i].height))*ratio_height; + + g_Motion_Area_Data[index_motion].used = 1; + g_Motion_Area_Data[index_motion].locked = 0; + break; + } + } + } +#endif + + if (*image_size == 0) { + for (const Rect& a_rect : mergedRectangles) { + rectangle(recorded_map, a_rect, Scalar(255, 255, 255), 2); + } + } + + mergedRectangles.clear(); + vector<Rect>().swap(mergedRectangles); + } + } + +#if 1 + //char file_path_jpeg[256] = { 0 }; + //sprintf(file_path_jpeg, "/emmc/plugin/Aida_data/storage/output_image_%d.jpeg", index_rand); + //index_rand++; + //if (index_rand == 20) { + //index_rand = 0; + //} + //imwrite(file_path_jpeg, recorded_map); + + if (*image_size == 0) { + vector<uchar> data_encode; + imencode(".jpeg", recorded_map, data_encode); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } +#endif + recorded_map.release(); + } + + currFrame.release(); + currFrame_blur.release(); + img_gray.release(); + img_decode.release(); + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + } + } + return 0; + } +} + +int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, int snaphd_image_size, detection_pos* PosInfo, int i_InSourceOri_w, int i_InSourceOri_h,int draw_img_long, int draw_img_short,int* no_tempering, int not_to_show_tempering) // For normal type +{ + if (AI_fps <= 0 || strcmp(viewChannelData[0].enable_unknown_object, "No") == 0 || check_if_compute_median_finish == 0) { + return 0; + } + else { + //printf("\ndiffer_image--------------------start-----1\n"); + detection_pos* pNext = NULL; + double temp_time_interval_with_msec = (double)atoi(viewChannelData[0].dwell_unknown_object) / ((double)MAX_SHORT_TERM - 1.0)*1000.0; //TIME_INTERVAL_WITH_MSEC + //printf("\n------temp_time_interval_with_msec:%lf\n", temp_time_interval_with_msec); + //printf("\nTTTTTTTTT no_tempering:%d\n", *no_tempering); + + int temp_AI_fps = AI_fps >= 2 ? AI_fps : 2; + + //printf("\nTTTTTTTTTT i_InSourceOri_w:%d , i_InSourceOri_h:%d\n", i_InSourceOri_w, i_InSourceOri_h); + //printf("\ndiffer image-------1\n"); + + current_ms_differ_image = getCurrentTime(); + //printf("\n-------------%ld\n", current_ms_differ_image); + + + //printf("\nTTTTTTTTTT ratio_width:%f , ratio_height:%f\n", ratio_width, ratio_height); + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + + Mat img_gray; + Mat img_blur; + Mat img_thres; + //Mat img_morph_open_one; + //Mat img_morph_open_twice; + //Mat img_morph_close_one; + Mat img_morph_close_twice; + + Mat img_absdiff; + + Mat bitwise_and_before_contours; + Mat short_term_contours; + Mat long_term_contours; + + //vector<Mat> img_channels; + + uint32_t valid_bbox_idx = 0; + + Mat img_absdiff_short_term; + Mat img_blur_short_term; + + Mat img_absdiff_long_term; + Mat img_blur_long_term; + + Mat img_yuv; + Mat img_blur_yuv; + + Mat masked_certain; + + int thres_light[3] = { 0 };//25 + + ////////////N쥻nechar * decodemat + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + + Mat temp_img_decode; + temp_img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + + //printf("\ndiffer image-------2\n"); + int ivs_width = 80; + int ivs_height = 45; + float ratio_width = (float)i_InSourceOri_w / (float)ivs_width; + float ratio_height = (float)i_InSourceOri_h / (float)ivs_height; + + //printf("\n-----%d,%d,%d,%d\n", temp_img_decode.size().width, i_InSourceOri_w, temp_img_decode.size().height, i_InSourceOri_h); + + if (temp_img_decode.size().width != VIEW_WEB_WIDTH_HD || temp_img_decode.size().height != VIEW_WEB_HEIGHT_HD) + { + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + temp_img_decode.release(); + return 0; + } + else + { + Mat img_decode; + resize(temp_img_decode, img_decode, Size(ivs_width, ivs_height), INTER_NEAREST); + temp_img_decode.release(); + + /////////////q}lopencv򥻼vp + //printf("\ndiffer_image--------------------start-----1-------1\n"); + if (check_if_tempering_many_times == -100) { + check_if_tempering_many_times = (temp_AI_fps - 1) * 4; + } + + //Ƕ + cvtColor(img_decode, img_gray, CV_BGR2GRAY); + //printf("\ndiffer_image--------------------start-----1-------2\n"); +#if 1 + //Loɶbanner + { + + int mask_width = ivs_width; + int mask_height = ivs_height; + + Mat imageMask(mask_height, mask_width, CV_8UC3, Scalar(0, 0, 0)); + imageMask(Rect(0, 2, mask_width, mask_height-2)) = Scalar(255, 255, 255); //make rectangle 1 + Mat imageMask_gray; + cvtColor(imageMask, imageMask_gray, CV_BGR2GRAY); + imageMask.release(); + + Mat maskedImage; + bitwise_and(img_gray, imageMask_gray, maskedImage); + imageMask_gray.release(); + img_gray.release(); + img_gray = maskedImage.clone(); + maskedImage.release(); + } +#endif + //printf("\ndiffer_image--------------------start-----1-------3\n"); + //split(img_decode, img_channels); + + //Mat abs_r_g = abs(img_channels[2] - img_channels[1]); + //Mat abs_r_b = abs(img_channels[2] - img_channels[0]); + //Mat abs_g_b = abs(img_channels[1] - img_channels[0]); + + //double r_g = countNonZero(abs_r_g); + //double r_b = countNonZero(abs_r_b); + //double g_b = countNonZero(abs_g_b); + + //abs_r_g.release(); + //abs_r_b.release(); + //abs_g_b.release(); + + //img_channels[0].release(); + //img_channels[1].release(); + //img_channels[2].release(); + //img_channels.clear(); + //vector<Mat>().swap(img_channels); + + //double ratio_determine_if_color = (r_g + r_b + g_b) / ((double)ivs_width*(double)ivs_height); + + //printf("\n-------imageDnData.current_day_or_night_mode:%d\n", imageDnData.current_day_or_night_mode); + //printf("\n-------imageDnData.check_if_switch_happene[0]:%d\n", imageDnData.check_if_switch_happened[0]); + //printf("\ndiffer_image--------------------start-----1-------4\n"); + //if (not_to_show_tempering == 0) { + //if (imageDnData.current_day_or_night_mode == 1) { + //printf("\nimage is color:%lf\n", ratio_determine_if_color); + //last_day_or_night_mode = current_day_or_night_mode; + //current_day_or_night_mode = 1; + //} + //else { + //printf("\nimage is grayscale:%lf\n", ratio_determine_if_color); + //last_day_or_night_mode = current_day_or_night_mode; + //current_day_or_night_mode = 2; + //} + //} + + thres_light[0] = 6;//80 //8 + thres_light[1] = 0;//25 //3 + thres_light[2] = 0;//25 //3 + + if (strcmp(viewChannelData[0].ivs_mode, "0") == 0) { + thres_light[0] = 6;//80 //8 + } + else if (strcmp(viewChannelData[0].ivs_mode, "1") == 0) { + thres_light[0] = 4;//80 //8 + } + else if (strcmp(viewChannelData[0].ivs_mode, "2") == 0) { + thres_light[0] = 2;//80 //8 + } + + //ҽk + img_blur = img_gray.clone(); + //blur(img_gray, img_blur, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + + //GaussianBlur(img_gray, img_blur, Size(4, 4),0,0); + + img_gray.release(); + //printf("\ndiffer_image--------------------start-----1-------5\n"); + if (img_blur.size().width == 0 || img_blur.size().height == 0) { + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + img_blur.release(); + return 0; + } + else + { + //printf("\ndiffer_image--------------------start-----1-------6\n"); + //printf("\ndiffer image-------3\n"); + //simg_decodeɶbW + //printf("\n--------check_if_compute_median_finish:%d,check_if_tempering_happened:%d\n", check_if_compute_median_finish, check_if_tempering_happened); + + //printf("\n----current_ms_differ_image - last_ms_differ_image:%ld\n", current_ms_differ_image - last_ms_differ_image); + //printf("\n--------(current_ms_differ_image - last_ms_differ_image) / temp_time_interval_with_msec : %d\n", + //(int)((current_ms_differ_image - last_ms_differ_image)/ (long)temp_time_interval_with_msec)); + if (last_ms_differ_image == 0 || current_ms_differ_image - last_ms_differ_image >= (long)temp_time_interval_with_msec) { + if (check_if_compute_median_finish == 1 && check_if_tempering_happened <= 0) { + + if (store_img_background_array_length < MAX_TIME_LENGTH) { + if (store_img_background_array_length == 0) { + last_ms_differ_image = 0; + } + img_background_array[store_img_background_array_length] = img_decode.clone(); + current_index_img_background_array = store_img_background_array_length; + store_img_background_array_length++; + } + else { + if ((int)((current_ms_differ_image - last_ms_differ_image) / (long)temp_time_interval_with_msec) >= 1) { + //differ_image|ھڦpGcompute_median_threadpӤ[ɡA|hǷUIXiC + for (int count_vir = 0; count_vir < (int)((current_ms_differ_image - last_ms_differ_image) / (long)temp_time_interval_with_msec); count_vir++) { + img_background_array[virtual_index_img_background_array].release(); + img_background_array[virtual_index_img_background_array] = img_decode.clone(); + current_index_img_background_array = virtual_index_img_background_array; + virtual_index_img_background_array++; + if (virtual_index_img_background_array >= MAX_TIME_LENGTH) { + virtual_index_img_background_array = 0; + } + } + } + else { + img_background_array[virtual_index_img_background_array].release(); + img_background_array[virtual_index_img_background_array] = img_decode.clone(); + current_index_img_background_array = virtual_index_img_background_array; + virtual_index_img_background_array++; + if (virtual_index_img_background_array >= MAX_TIME_LENGTH) { + virtual_index_img_background_array = 0; + } + } + } + + if (last_ms_differ_image == 0) { + last_ms_differ_image = current_ms_differ_image; + } + else { + if ((int)((current_ms_differ_image - last_ms_differ_image) / (long)temp_time_interval_with_msec) >= 1) { + for (int count_vir = 0; count_vir < (int)((current_ms_differ_image - last_ms_differ_image) / (long)temp_time_interval_with_msec); count_vir++) { + last_ms_differ_image = last_ms_differ_image + (long)temp_time_interval_with_msec; + } + } + else { + last_ms_differ_image = last_ms_differ_image + (long)temp_time_interval_with_msec; + } + } + } + } + + //printf("\ndiffer_image--------------------start-----1-------7\n"); + if (check_if_tempering_happened <= 0) { + if (store_img_background_array_length < MAX_SHORT_TERM) { + *no_tempering = 0; + check_if_tempering_many_times = (temp_AI_fps - 1) * 4; + g_progress_bar = (float)100.0 * (float)store_img_background_array_length / (float)MAX_SHORT_TERM; + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + img_blur.release(); + + /*if (PosInfo != NULL && bg_learning_first_to_show == 0) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "bg_learning"); + + pNext->confidence = (float)sqrt((double)1.0 * (double)100)*10.0; + pNext->progress_bar = (float)100.0 * (float)store_img_background_array_length / (float)MAX_SHORT_TERM; + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + + pNext->left_x = (float)ivs_width * (float)ratio_width * (float)0.35;//0.03 + pNext->top_y = (float)ivs_height * (float)ratio_height * (float)0.35;//0.1 + pNext->width = (float)ivs_width * (float)ratio_width * (float)0.3;//0.05 + pNext->height = (float)ivs_height * (float)ratio_height * (float)0.3;//0.05 + + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 1; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + }*/ + + return (int)valid_bbox_idx; + } + } + else if (check_if_tempering_happened >= 1) { + g_progress_bar = 1.0; + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + img_blur.release(); + + if (!img_background_short_term_yuv.empty()) + img_background_short_term_yuv.release(); + + if (!img_background_long_term_yuv.empty()) + img_background_long_term_yuv.release(); + + if (PosInfo != NULL && not_to_show_tempering == 0) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "tampering"); + + pNext->confidence = (float)sqrt((double)1.0 * (double)100)*10.0; + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + + pNext->left_x = (float)ivs_width * ratio_width * (float)0.35; + pNext->top_y = (float)ivs_height * ratio_height * (float)0.35; + pNext->width = (float)ivs_width * ratio_width * (float)0.3; + pNext->height = (float)ivs_height * ratio_height * (float)0.3; + + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 1; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + check_if_tempering_happened--; + + return (int)valid_bbox_idx; + } + //printf("\ndiffer_image--------------------start-----2\n"); + //bg_learning_first_to_show = 1; + g_progress_bar = 0.0; + + //printf("\ndiffer image-------4\n"); + //pvt//short term + //if (get_check_if_existing_any_switch_happened() == 0 || store_img_background_array_length <= MAX_SIZE_SWITCH_HAPPENED) + { + if (!img_background_short_term.empty() && !img_background_short_term_yuv.empty()) { + absdiff(img_blur, img_background_short_term, img_absdiff); + } + else { + img_absdiff = Mat::zeros(img_blur.size(), img_blur.type()); + } + } +#if 0 + else { + if (imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) { + Mat gray_last_frame; + Mat blur_last_frame; + + int index_last_frame; + if (current_index_img_background_array - (GAP_SWITCH_HAPPENED - 1) >= 0) { + index_last_frame = current_index_img_background_array - (GAP_SWITCH_HAPPENED - 1); + } + else { + index_last_frame = current_index_img_background_array - (GAP_SWITCH_HAPPENED - 1) + store_img_background_array_length; + } + + cvtColor(img_background_array[index_last_frame], gray_last_frame, CV_BGR2GRAY); + + blur_last_frame = gray_last_frame.clone(); + //blur(gray_last_frame, blur_last_frame, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + + absdiff(img_blur, blur_last_frame, img_absdiff); + + gray_last_frame.release(); + blur_last_frame.release(); + } + else { + img_absdiff = Mat::zeros(img_blur.size(), img_blur.type()); + } + } +#endif + //GȤ THRESH_OTSU|۰ʧ̨λ֭ + double thresh = 25;//25 + int maxVal = 255; + //double new_threshold = 0; + /*new_threshold =*/ + threshold(img_absdiff, img_thres, thresh, maxVal, THRESH_BINARY);////THRESH_OTSU THRESH_BINARY + + //ȫIk + //Mat morph_matrix = getStructuringElement(MORPH_RECT, Size(9, 5), Point(-1, -1)); //5 5 + Mat morph_matrix = getStructuringElement(MORPH_RECT, Size(5, 3), Point(-1, -1)); + //morphologyEx(img_thres, img_morph_close_twice, CV_MOP_CLOSE, morph_matrix);//CV_MOP_OPEN + img_morph_close_twice = img_thres.clone(); + //morphologyEx(img_thres, img_morph_open_one, CV_MOP_OPEN, morph_matrix);//CV_MOP_OPEN + //morphologyEx(img_morph_open_one, img_morph_open_twice, CV_MOP_OPEN, morph_matrix);//CV_MOP_OPEN + //morphologyEx(img_morph_open_twice, img_morph_close_one, CV_MOP_CLOSE, morph_matrix); + //morphologyEx(img_morph_close_one, img_morph_close_twice, CV_MOP_CLOSE, morph_matrix); + if (!img_morph_close_twice.empty() && img_morph_close_twice.size().width >= 1 && img_morph_close_twice.size().height >= 1) { + short_term_contours = img_morph_close_twice.clone(); + //short_term_contours = img_thres.clone(); + } + else + short_term_contours = Mat::zeros(img_blur.size(), img_blur.type()); + + img_absdiff.release(); + img_thres.release(); + img_morph_close_twice.release(); + //img_morph_close_one.release(); + //img_morph_open_twice.release(); + //img_morph_open_one.release(); + + //pvt//long term + //if (get_check_if_existing_any_switch_happened() == 0 || store_img_background_array_length <= MAX_SIZE_SWITCH_HAPPENED) + { + if (!img_background_long_term.empty() && !img_background_long_term_yuv.empty()) { + absdiff(img_blur, img_background_long_term, img_absdiff); + } + else { + img_absdiff = Mat::zeros(img_blur.size(), img_blur.type()); + } + } +#if 0 + else { + if (imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) { + Mat gray_last_frame; + Mat blur_last_frame; + + int index_last_frame; + if (current_index_img_background_array - (GAP_SWITCH_HAPPENED - 1) >= 0) { + index_last_frame = current_index_img_background_array - (GAP_SWITCH_HAPPENED - 1); + } + else { + index_last_frame = current_index_img_background_array - (GAP_SWITCH_HAPPENED - 1) + store_img_background_array_length; + } + + cvtColor(img_background_array[index_last_frame], gray_last_frame, CV_BGR2GRAY); + + blur_last_frame = gray_last_frame.clone(); + //blur(gray_last_frame, blur_last_frame, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + + absdiff(img_blur, blur_last_frame, img_absdiff); + + gray_last_frame.release(); + blur_last_frame.release(); + } + else { + img_absdiff = Mat::zeros(img_blur.size(), img_blur.type()); + } + } +#endif + //GȤ THRESH_OTSU|۰ʧ̨λ֭ + threshold(img_absdiff, img_thres, thresh, maxVal, THRESH_BINARY);//THRESH_OTSU THRESH_BINARY + + //ȫIk + //morphologyEx(img_thres, img_morph_close_twice, CV_MOP_CLOSE, morph_matrix);//CV_MOP_OPEN + img_morph_close_twice = img_thres.clone(); + //morphologyEx(img_thres, img_morph_open_one, CV_MOP_OPEN, morph_matrix);//CV_MOP_OPEN + //morphologyEx(img_morph_open_one, img_morph_open_twice, CV_MOP_OPEN, morph_matrix);//CV_MOP_OPEN + //morphologyEx(img_morph_open_twice, img_morph_close_one, CV_MOP_CLOSE, morph_matrix); + //morphologyEx(img_morph_close_one, img_morph_close_twice, CV_MOP_CLOSE, morph_matrix); + if (!img_morph_close_twice.empty() && img_morph_close_twice.size().width >= 1 && img_morph_close_twice.size().height >= 1) { + long_term_contours = img_morph_close_twice.clone(); + //long_term_contours = img_thres.clone(); + } + else + long_term_contours = Mat::zeros(img_blur.size(), img_blur.type()); + + img_absdiff.release(); + img_thres.release(); + morph_matrix.release(); + img_morph_close_twice.release(); + //img_morph_close_one.release(); + //img_morph_open_twice.release(); + //img_morph_open_one.release(); + + ///////////////YUVˬdU + cvtColor(img_decode, img_yuv, CV_BGR2YUV); + + img_blur_yuv = img_yuv.clone(); + //blur(img_yuv, img_blur_yuv, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + + if (!img_background_short_term_yuv.empty()) + { + img_blur_short_term = img_background_short_term_yuv.clone(); + //blur(img_background_short_term_yuv, img_blur_short_term, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + } + + if (!img_background_long_term_yuv.empty()) + { + img_blur_long_term = img_background_long_term_yuv.clone(); + //blur(img_background_long_term_yuv, img_blur_long_term, Size(BLUR_SIZE, BLUR_SIZE));//5 5 + } + + if (!img_blur_short_term.empty() && !img_blur_long_term.empty() /*&& get_check_if_existing_any_switch_happened()==0*/) + { + vector<Mat> img_channels_short_term; + vector<Mat> img_channels_long_term; + + Mat bitwise_temp1; + Mat bitwise_temp2; + Mat bitwise_temp3; + Mat bitwise_temp_temp; + + vector<Mat> img_channels_certain_short_term; + Mat merge_certain_short_term; + Mat inrange_short_term; + + vector<Mat> img_channels_certain_long_term; + Mat merge_certain_long_term; + Mat inrange_long_term; + + absdiff(img_blur_yuv, img_blur_short_term, img_absdiff_short_term); + absdiff(img_blur_yuv, img_blur_long_term, img_absdiff_long_term); + + split(img_absdiff_short_term, img_channels_short_term); + split(img_absdiff_long_term, img_channels_long_term); + + for (int color_index = 0; color_index < 3; color_index++) { + img_channels_certain_short_term.push_back(img_channels_short_term[color_index]); + img_channels_certain_short_term.push_back(img_channels_short_term[color_index]); + img_channels_certain_short_term.push_back(img_channels_short_term[color_index]); + img_channels_certain_long_term.push_back(img_channels_long_term[color_index]); + img_channels_certain_long_term.push_back(img_channels_long_term[color_index]); + img_channels_certain_long_term.push_back(img_channels_long_term[color_index]); + + merge(img_channels_certain_short_term, merge_certain_short_term); + inRange(merge_certain_short_term, Scalar(thres_light[color_index], thres_light[color_index], thres_light[color_index]), Scalar(255, 255, 255), inrange_short_term); + + merge(img_channels_certain_long_term, merge_certain_long_term); + inRange(merge_certain_long_term, Scalar(thres_light[color_index], thres_light[color_index], thres_light[color_index]), Scalar(255, 255, 255), inrange_long_term); + + if (color_index == 0) + bitwise_and(inrange_short_term, inrange_long_term, bitwise_temp1); + else if (color_index == 1) + bitwise_and(inrange_short_term, inrange_long_term, bitwise_temp2); + else + bitwise_and(inrange_short_term, inrange_long_term, bitwise_temp3); + + img_channels_certain_short_term[0].release(); + img_channels_certain_short_term[1].release(); + img_channels_certain_short_term[2].release(); + img_channels_certain_short_term.clear(); + vector<Mat>().swap(img_channels_certain_short_term); + img_channels_certain_long_term[0].release(); + img_channels_certain_long_term[1].release(); + img_channels_certain_long_term[2].release(); + img_channels_certain_long_term.clear(); + vector<Mat>().swap(img_channels_certain_long_term); + + merge_certain_short_term.release(); + inrange_short_term.release(); + merge_certain_long_term.release(); + inrange_long_term.release(); + } + + bitwise_or(bitwise_temp1, bitwise_temp2, bitwise_temp_temp); + bitwise_or(bitwise_temp3, bitwise_temp_temp, masked_certain); + + bitwise_temp1.release(); + bitwise_temp2.release(); + bitwise_temp3.release(); + bitwise_temp_temp.release(); + + img_channels_short_term[0].release(); + img_channels_short_term[1].release(); + img_channels_short_term[2].release(); + img_channels_short_term.clear(); + vector<Mat>().swap(img_channels_short_term); + + img_channels_long_term[0].release(); + img_channels_long_term[1].release(); + img_channels_long_term[2].release(); + img_channels_long_term.clear(); + vector<Mat>().swap(img_channels_long_term); + + img_absdiff_short_term.release(); + img_absdiff_long_term.release(); + } + else + { + masked_certain = Mat::zeros(img_blur_yuv.size(), CV_8UC1); + } + + //printf("\ndiffer image-------5\n"); + //Mat temp_bitwise; + //bitwise_not(short_term_contours, temp_bitwise); + bitwise_and(short_term_contours, long_term_contours, bitwise_and_before_contours); + //temp_bitwise.release(); + + //printf("\ndiffer image-------6\n"); + img_blur.release(); + + vector<vector<Point>> contours; + vector<Rect> store_rect_contours; + vector<Rect> combine_rect_contours; + //vector<Rect>::iterator it_store_rect_contours; + + vector<Rect> store_rect_contours_not_in_zone; + + vector<Rect> store_ivs_object; + + //printf("\ndiffer image-------7\n"); + + Rect draw_border_to_zero(0, 0, ivs_width, ivs_height); + + rectangle(bitwise_and_before_contours, + draw_border_to_zero, + Scalar(0, 0, 0), + BORDER_WIDTH_TO_IGNORE_IVS, 8, 0); + + rectangle(short_term_contours, + draw_border_to_zero, + Scalar(0, 0, 0), + BORDER_WIDTH_TO_IGNORE_IVS, 8, 0); + + rectangle(long_term_contours, + draw_border_to_zero, + Scalar(0, 0, 0), + BORDER_WIDTH_TO_IGNORE_IVS, 8, 0); + + findContours(bitwise_and_before_contours, contours, noArray(), RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); + Size inflationSize(2, 2); + Point inflationOffset(-1, -1); + + int contours_size = 0; + int contours_size_not_in_zone = 0; + + if (g_check_if_OK_thermal == 0 && g_IsPTZDevice == 1 && strcmp(SystemSetting.enable_crop_mode, "Yes") == 0) { + if (i_InSourceOri_h >= 1 && i_InSourceOri_w >= 1 && g_framesize_height >= 1 && g_framesize_width >= 1) { + float temp_framsize_height = (float)g_framesize_height; + float temp_framsize_width = (float)g_framesize_width; + float temp_g_ori_yuv_height = (float)i_InSourceOri_h; + float temp_g_ori_yuv_width = (float)i_InSourceOri_w; + + float ratio_height_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_height / temp_framsize_height; + float ratio_width_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_width / temp_framsize_width; + + float thres_x_min = 0.0; + float thres_x_max = 1.0; + float thres_y_min = 0.0; + float thres_y_max = 1.0; + + float cut_thres_ratio = 0.0; + + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + thres_x_min += ((1.0 - cut_thres_ratio) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio) / 2.0); + } + else if (ratio_width_g_ori_yuv_to_ai_webpage < ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + thres_y_min += ((1.0 - cut_thres_ratio) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio) / 2.0); + } + + for (int i = 0; i < (int)contours.size(); i++) { + //if (contourArea(contours[i]) < (ivs_width*ivs_height) / 2000) + //continue; + + Rect temp_rect = boundingRect(contours[i]); + float rect_left_x = ((float)(temp_rect.x))*ratio_width; + float rect_top_y = ((float)(temp_rect.y))*ratio_height; + float rect_width = ((float)(temp_rect.width))*ratio_width; + float rect_height = ((float)(temp_rect.height))*ratio_height; + + if (rect_left_x < 0) { + rect_width += (rect_left_x - 1); + rect_left_x = 0; + } + + if (rect_top_y < 0) { + rect_height += (rect_top_y - 1); + rect_top_y = 0; + } + + if (rect_left_x + rect_width > temp_g_ori_yuv_width - 1) { + rect_width = temp_g_ori_yuv_width - 1 - rect_left_x; + } + + if (rect_top_y + rect_height > temp_g_ori_yuv_height - 1) { + rect_height = temp_g_ori_yuv_height - 1 - rect_top_y; + } + + float rect_center_x = rect_left_x + rect_width / 2.0; + float rect_center_y = rect_top_y + rect_height / 2.0; + + float obj_x_max = (rect_left_x + rect_width) / temp_g_ori_yuv_width; + float obj_x_min = rect_left_x / temp_g_ori_yuv_width; + + float obj_y_max = (rect_top_y + rect_height) / temp_g_ori_yuv_height; + float obj_y_min = rect_top_y / temp_g_ori_yuv_height; + + if (obj_x_max <= thres_x_min || + obj_x_min >= thres_x_max || + obj_y_max <= thres_y_min || + obj_y_min >= thres_y_max) + { + continue; + } + else { + if (obj_x_min < thres_x_min) { + obj_x_min = thres_x_min; + } + + if (obj_x_max > thres_x_max) { + obj_x_max = thres_x_max; + } + + if (obj_y_min < thres_y_min) { + obj_y_min = thres_y_min; + } + + if (obj_y_max > thres_y_max) { + obj_y_max = thres_y_max; + } + + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + float obj_center_x = (obj_x_min + obj_x_max) / 2.0; + float obj_width = (obj_x_max - obj_x_min); + + obj_center_x = (obj_center_x - 0.5) * (1.0 / cut_thres_ratio) + 0.5; + obj_width = obj_width * (1.0 / cut_thres_ratio); + + obj_x_min = obj_center_x - obj_width / 2.0; + obj_x_max = obj_center_x + obj_width / 2.0; + } + else { + float obj_center_y = (obj_y_min + obj_y_max) / 2.0; + float obj_height = (obj_y_max - obj_y_min); + + obj_center_y = (obj_center_y - 0.5) * (1.0 / cut_thres_ratio) + 0.5; + obj_height = obj_height * (1.0 / cut_thres_ratio); + + obj_y_min = obj_center_y - obj_height / 2.0; + obj_y_max = obj_center_y + obj_height / 2.0; + } + + + if (obj_x_min < 0.0) + obj_x_min = 0.0; + + if (obj_x_max > 1.0) + obj_x_max = 1.0; + + if (obj_y_min < 0.0) + obj_y_min = 0.0; + + if (obj_y_max > 1.0) + obj_y_max = 1.0; + + obj_x_min = obj_x_min * (float)i_InSourceOri_w; //1920 + obj_x_max = obj_x_max * (float)i_InSourceOri_w; //1920 + obj_y_min = obj_y_min * (float)i_InSourceOri_h; //1080 + obj_y_max = obj_y_max * (float)i_InSourceOri_h; //1080 + + rect_left_x = obj_x_min; + rect_top_y = obj_y_min; + rect_width = (obj_x_max - obj_x_min); + rect_height = (obj_y_max - obj_y_min); + rect_center_x = rect_left_x + rect_width / 2.0; + rect_center_y = rect_top_y + rect_height / 2.0; + + int checkisInside = 1; + if (strcmp(SystemSetting.enable_bounding_box, "No") == 0) { + checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 0); + } + + if (checkisInside == 1) { + store_rect_contours.push_back(temp_rect); + store_rect_contours[contours_size] += inflationOffset; + store_rect_contours[contours_size] += inflationSize; + if (store_rect_contours[contours_size].x < 0) { + store_rect_contours[contours_size].width += (store_rect_contours[contours_size].x - 1); + store_rect_contours[contours_size].x = 0; + } + + if (store_rect_contours[contours_size].y < 0) { + store_rect_contours[contours_size].height += (store_rect_contours[contours_size].y - 1); + store_rect_contours[contours_size].y = 0; + } + + if (store_rect_contours[contours_size].x + store_rect_contours[contours_size].width > ivs_width - 1) { + store_rect_contours[contours_size].width = ivs_width - 1 - store_rect_contours[contours_size].x; + } + + if (store_rect_contours[contours_size].y + store_rect_contours[contours_size].height > ivs_height - 1) { + store_rect_contours[contours_size].height = ivs_height - 1 - store_rect_contours[contours_size].y; + } + + contours_size++; + } + else { + store_rect_contours_not_in_zone.push_back(temp_rect); + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width += (store_rect_contours_not_in_zone[contours_size_not_in_zone].x - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].x = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height += (store_rect_contours_not_in_zone[contours_size_not_in_zone].y - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].y = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x + store_rect_contours_not_in_zone[contours_size_not_in_zone].width > ivs_width - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width = ivs_width - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].x; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y + store_rect_contours_not_in_zone[contours_size_not_in_zone].height > ivs_height - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height = ivs_height - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].y; + } + contours_size_not_in_zone++; + } + } + } + } + } + else { + if (i_InSourceOri_h >= 1 && i_InSourceOri_w >= 1) { + float temp_g_ori_yuv_height = (float)i_InSourceOri_h; + float temp_g_ori_yuv_width = (float)i_InSourceOri_w; + for (int i = 0; i < (int)contours.size(); i++) { + //if (contourArea(contours[i]) < (ivs_width*ivs_height) / 2000) + //continue; + + Rect temp_rect = boundingRect(contours[i]); + float rect_left_x = ((float)(temp_rect.x))*ratio_width; + float rect_top_y = ((float)(temp_rect.y))*ratio_height; + float rect_width = ((float)(temp_rect.width))*ratio_width; + float rect_height = ((float)(temp_rect.height))*ratio_height; + + if (rect_left_x < 0) { + rect_width += (rect_left_x - 1); + rect_left_x = 0; + } + + if (rect_top_y < 0) { + rect_height += (rect_top_y - 1); + rect_top_y = 0; + } + + if (rect_left_x + rect_width > temp_g_ori_yuv_width - 1) { + rect_width = temp_g_ori_yuv_width - 1 - rect_left_x; + } + + if (rect_top_y + rect_height > temp_g_ori_yuv_height - 1) { + rect_height = temp_g_ori_yuv_height - 1 - rect_top_y; + } + + float rect_center_x = rect_left_x + rect_width / 2.0; + float rect_center_y = rect_top_y + rect_height / 2.0; + + //int checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 1); + int checkisInside = 1; + if (strcmp(SystemSetting.enable_bounding_box, "No") == 0) { + checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 0); + } + //printf("\n--------checkisInside:%d,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d\n", checkisInside, rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, + //temp_rect.x, temp_rect.y, temp_rect.width, temp_rect.height); + + if (checkisInside == 1) { + store_rect_contours.push_back(temp_rect); + store_rect_contours[contours_size] += inflationOffset; + store_rect_contours[contours_size] += inflationSize; + if (store_rect_contours[contours_size].x < 0) { + store_rect_contours[contours_size].width += (store_rect_contours[contours_size].x - 1); + store_rect_contours[contours_size].x = 0; + } + + if (store_rect_contours[contours_size].y < 0) { + store_rect_contours[contours_size].height += (store_rect_contours[contours_size].y - 1); + store_rect_contours[contours_size].y = 0; + } + + if (store_rect_contours[contours_size].x + store_rect_contours[contours_size].width > ivs_width - 1) { + store_rect_contours[contours_size].width = ivs_width - 1 - store_rect_contours[contours_size].x; + } + + if (store_rect_contours[contours_size].y + store_rect_contours[contours_size].height > ivs_height - 1) { + store_rect_contours[contours_size].height = ivs_height - 1 - store_rect_contours[contours_size].y; + } + + contours_size++; + } + else { + store_rect_contours_not_in_zone.push_back(temp_rect); + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width += (store_rect_contours_not_in_zone[contours_size_not_in_zone].x - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].x = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height += (store_rect_contours_not_in_zone[contours_size_not_in_zone].y - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].y = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x + store_rect_contours_not_in_zone[contours_size_not_in_zone].width > ivs_width - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width = ivs_width - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].x; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y + store_rect_contours_not_in_zone[contours_size_not_in_zone].height > ivs_height - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height = ivs_height - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].y; + } + contours_size_not_in_zone++; + } + } + } + } + + //printf("\ndiffer image-------8\n"); + + //float distance_filter = 30.0; +#if 1 + while ((int)store_rect_contours.size() >= 1) { + combine_rect_contours.push_back(store_rect_contours[(int)store_rect_contours.size() - 1]); + store_ivs_object.push_back(store_rect_contours[(int)store_rect_contours.size() - 1]); + + store_rect_contours.pop_back(); + + +#if 0 + Rect bounding_for_a_object; + bounding_for_a_object = combine_rect_contours[(int)combine_rect_contours.size() - 1]; + //int center_a_x = bounding_for_a_object.x + (bounding_for_a_object.width / 2); + //int center_a_y = bounding_for_a_object.y + (bounding_for_a_object.height / 2); + + for (int i = 0; i < (int)store_rect_contours.size(); i++) { + it_store_rect_contours = store_rect_contours.begin() + i; + Rect bounding_for_b_object(it_store_rect_contours->x, it_store_rect_contours->y, + it_store_rect_contours->width, it_store_rect_contours->height); + //int center_b_x = bounding_for_b_object.x + (bounding_for_b_object.width / 2); + //int center_b_y = bounding_for_b_object.y + (bounding_for_b_object.height / 2); + + Rect bounding_for_intersection_object = bounding_for_a_object & bounding_for_b_object; + Rect bounding_for_union_object = bounding_for_a_object | bounding_for_b_object; + + //printf("\n-----inter:%d,union:%d,a:%d,b:%d\n", bounding_for_intersection_object.area(), bounding_for_union_object.area(), bounding_for_a_object.area(), bounding_for_b_object.area()); + + //int distance_a_and_b = (int)sqrt((double)((center_a_x - center_b_x)*(center_a_x - center_b_x) + (center_a_y - center_b_y)*(center_a_y - center_b_y))); + if (bounding_for_intersection_object.area() >= 1 || + //distance_a_and_b <= (int)distance_filter + //|| bounding_for_union_object.area() == bounding_for_a_object.area() + //|| bounding_for_union_object.area() == bounding_for_b_object.area() + //|| rect_overlap_ratio_union(bounding_for_a_object, bounding_for_b_object) > 0.0 + //|| rect_overlap_ratio(bounding_for_a_object, bounding_for_b_object) > 0.0 + /*||*/ rect_nms(bounding_for_a_object, bounding_for_b_object) > 0.0 + ) { + combine_rect_contours.pop_back(); + store_ivs_object.pop_back(); + + store_rect_contours.erase(it_store_rect_contours); + i--; + combine_rect_contours.push_back(bounding_for_union_object); + store_ivs_object.push_back(bounding_for_union_object); + + bounding_for_a_object = bounding_for_union_object; + //center_a_x = bounding_for_a_object.x + (bounding_for_a_object.width / 2); + //center_a_y = bounding_for_a_object.y + (bounding_for_a_object.height / 2); + + + } + } +#endif + } +#endif + //printf("\ndiffer image-------9\n"); + + int sum_area = 0; + for (int i = 0; i < (int)combine_rect_contours.size(); i++) { + Rect bounding_for_a_object; + bounding_for_a_object = combine_rect_contours[i]; + sum_area += bounding_for_a_object.area(); + + double object_width = (double)bounding_for_a_object.width; + double object_height = (double)bounding_for_a_object.height; + double object_x_left = (double)bounding_for_a_object.x; + double object_y_top = (double)bounding_for_a_object.y; + double object_center_x = object_x_left + object_width / 2.0; + double object_center_y = object_y_top + object_height / 2.0; + double object_x_right = object_x_left + object_width; + double object_y_bottom = object_y_top + object_height; + + if (object_width / object_height > 16.0 / 9.0) { + double temp_height = object_width * 9.0 / 16.0; + object_y_top = object_center_y - temp_height / 2.0; + object_y_bottom = object_center_y + temp_height / 2.0; + if (object_y_top < 0.0) { + temp_height = temp_height + object_y_top; + object_y_top = 0.0; + } + + if (object_y_bottom > ((double)ivs_height) - 1.0) { + temp_height = temp_height - (object_y_bottom - (((double)ivs_height) - 1.0)); + object_y_bottom = ((double)ivs_height) - 1.0; + } + + object_center_y = (object_y_top + object_y_bottom) / 2.0; + object_height = object_y_bottom - object_y_top; + } + else if (object_width / object_height < 5.0 / 5.0) { + double temp_width = object_height * 5.0 / 5.0; + object_x_left = object_center_x - temp_width / 2.0; + object_x_right = object_center_x + temp_width / 2.0; + if (object_x_left < 0.0) { + temp_width = temp_width + object_x_left; + object_x_left = 0.0; + } + + if (object_x_right > ((double)ivs_width) - 1.0) { + temp_width = temp_width - (object_x_right - (((double)ivs_width) - 1.0)); + object_x_right = ((double)ivs_width) - 1.0; + } + + object_center_x = (object_x_left + object_x_right) / 2.0; + object_width = object_x_right - object_x_left; + } + + combine_rect_contours[i].x = (int)object_x_left; + combine_rect_contours[i].y = (int)object_y_top; + combine_rect_contours[i].width = (int)object_width; + combine_rect_contours[i].height = (int)object_height; + } + + double area_scale = ((double)sum_area) / ((double)ivs_width * (double)ivs_height); + + //printf("\n-----------area_scale:%lf\n", area_scale); + //printf("\ndiffer image --------------- check_if_tempering_many_times:%d\n", check_if_tempering_many_times); + //printf("\n-------tempering_ready:%d\n", tempering_ready); + //printf("\n-------switch_happened:%d\n", get_check_if_existing_any_switch_happened()); + + if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0)) + { + check_if_tempering_many_times = (temp_AI_fps - 1) * 4; + + current_store_object_size = 0; + tempering_ready = 0; + + if (not_to_show_tempering == 0 && (/*(last_day_or_night_mode > 0 && last_day_or_night_mode != current_day_or_night_mode)*/ + /*get_check_if_existing_any_switch_happened() == 1 ||*/ *no_tempering == 1 || record_change_state == 1)) { + record_change_state = 1; + //printf("\ndiffer image --------------- 66\n"); + if (check_if_compute_median_finish == 1) { + for (int i = 0; i < store_img_background_array_length; i++) { + img_background_array[i].release(); + } + store_img_background_array_length = 0; + current_index_img_background_array = 0; + virtual_index_img_background_array = 0; + check_if_tempering_happened = 0; + record_change_state = 0; + *no_tempering = 0; + } + } + else + { +#if 0 + if (strcmp(viewChannelData[0].enable_ivs_and_ai, "Yes") == 0) { + if (strcmp(viewChannelData[0].enable_ivs_fix_mode, "Yes") == 0) { + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + //if (strcmp(viewDetectionZone[0][index_zone].enable_ivs_zone, "Yes") == 0) + { + float min_x_points = (float)viewDetectionZone[0][index_zone].min_x_points * (float)ivs_width / (float)CANVAS_WIDTH; + float max_x_points = (float)viewDetectionZone[0][index_zone].max_x_points * (float)ivs_width / (float)CANVAS_WIDTH; + float min_y_points = (float)viewDetectionZone[0][index_zone].min_y_points * (float)ivs_height / (float)CANVAS_HEIGHT; + float max_y_points = (float)viewDetectionZone[0][index_zone].max_y_points * (float)ivs_height / (float)CANVAS_HEIGHT; + + if (PosInfo != NULL) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = 0.8 * 100; + pNext->confidence2 = 0.8 * 100; + + float temp_a_x = min_x_points; + float temp_a_y = min_y_points; + float temp_a_width = max_x_points - min_x_points; + float temp_a_height = max_y_points - min_y_points; + + float thres_a_width = 8.0; + float thres_a_height = 6.0; + + if (temp_a_x + temp_a_width < thres_a_width) { + temp_a_x = 0; + temp_a_width = thres_a_width; + } + else if (temp_a_x >= ivs_width - thres_a_width) { + temp_a_x = ivs_width - thres_a_width - 1; + temp_a_width = thres_a_width; + } + else { + if (temp_a_width < thres_a_width) { + temp_a_x -= (thres_a_width - temp_a_width) / 2.0; + temp_a_width = thres_a_width; + } + } + + if (temp_a_y + temp_a_height < thres_a_height) { + temp_a_y = 0; + temp_a_height = thres_a_height; + } + else if (temp_a_y >= ivs_height - thres_a_height) { + temp_a_y = ivs_height - thres_a_height - 1; + temp_a_height = thres_a_height; + } + else { + if (temp_a_height < thres_a_height) { + temp_a_y -= (thres_a_height - temp_a_height) / 2.0; + temp_a_height = thres_a_height; + } + } + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = temp_a_x * ratio_width; + pNext->top_y = temp_a_y * ratio_height; + pNext->width = temp_a_width * ratio_width; + pNext->height = temp_a_height * ratio_height; + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 2; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } + else { + for (int i = 0; i < (int)combine_rect_contours.size(); i++) + { + Rect bounding_for_a_object; + + bounding_for_a_object = combine_rect_contours[i]; + + //current_store_objectAblast_store_object_sizḙ + current_store_object_x[current_store_object_size] = bounding_for_a_object.x; + current_store_object_y[current_store_object_size] = bounding_for_a_object.y; + current_store_object_w[current_store_object_size] = bounding_for_a_object.width; + current_store_object_h[current_store_object_size] = bounding_for_a_object.height; + current_store_object_size++; + + if (last_store_object_size >= 1) { + double intersect_ratio = 0.0; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + Rect bounding_for_b_object(last_store_object_x[index_last], last_store_object_y[index_last], + last_store_object_w[index_last], last_store_object_h[index_last]); + Rect bounding_for_intersection_object = bounding_for_a_object & bounding_for_b_object; + if (bounding_for_intersection_object.area() >= 1) + { + double temp_intersect_ratio = (double)bounding_for_intersection_object.area() / (double)bounding_for_a_object.area(); + if (temp_intersect_ratio > intersect_ratio) { + intersect_ratio = temp_intersect_ratio; + } + } + } + + Mat roi_a_object = masked_certain(bounding_for_a_object); + double count_non_zero = ((double)countNonZero(roi_a_object)) / ((double)bounding_for_a_object.width*(double)bounding_for_a_object.height); + roi_a_object.release(); + + //printf("\n---------count_non_zero:%lf\n", count_non_zero); + + if (intersect_ratio >= (double)atoi(viewChannelData[0].confidence_unknown_object) / 100.0 && + count_non_zero >= (double)atoi(viewChannelData[0].confidence2_unknown_object) / 100.0) + { + + rectangle(bitwise_and_before_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + + rectangle(short_term_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + + rectangle(long_term_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + +#if 0 + printf("\n------------bounding_for_a_object.x:%d,bounding_for_a_object.y:%d\n", bounding_for_a_object.x, bounding_for_a_object.y); +#endif + if (PosInfo != NULL) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = intersect_ratio * 100; + pNext->confidence2 = count_non_zero * 100; + + float temp_a_x = (float)(bounding_for_a_object.x); + float temp_a_y = (float)(bounding_for_a_object.y); + float temp_a_width = (float)(bounding_for_a_object.width); + float temp_a_height = (float)(bounding_for_a_object.height); + + float thres_a_width = 8.0; + float thres_a_height = 6.0; + + if (temp_a_x + temp_a_width < thres_a_width) { + temp_a_x = 0; + temp_a_width = thres_a_width; + } + else if (temp_a_x >= ivs_width - thres_a_width) { + temp_a_x = ivs_width - thres_a_width - 1; + temp_a_width = thres_a_width; + } + else { + if (temp_a_width < thres_a_width) { + temp_a_x -= (thres_a_width - temp_a_width) / 2.0; + temp_a_width = thres_a_width; + } + } + + if (temp_a_y + temp_a_height < thres_a_height) { + temp_a_y = 0; + temp_a_height = thres_a_height; + } + else if (temp_a_y >= ivs_height - thres_a_height) { + temp_a_y = ivs_height - thres_a_height - 1; + temp_a_height = thres_a_height; + } + else { + if (temp_a_height < thres_a_height) { + temp_a_y -= (thres_a_height - temp_a_height) / 2.0; + temp_a_height = thres_a_height; + } + } + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = temp_a_x * ratio_width; + pNext->top_y = temp_a_y * ratio_height; + pNext->width = temp_a_width * ratio_width; + pNext->height = temp_a_height * ratio_height; + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 2; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } + } + } +#endif + +#if 0 + for (int i = 0; i < (int)store_rect_contours_not_in_zone.size(); i++) { + Rect bounding_for_a_object; + + bounding_for_a_object = store_rect_contours_not_in_zone[i]; + + if (//(double)bounding_for_a_object.area() / ((double)ivs_width * (double)ivs_height) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + //(double)bounding_for_a_object.area() / ((double)ivs_width * (double)ivs_height) >= (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.width / ((double)ivs_width) > (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.height / ((double)ivs_height) > (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.width / ((double)ivs_width) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + (double)bounding_for_a_object.height / ((double)ivs_height) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + ((double)bounding_for_a_object.width * (double)bounding_for_a_object.height) / (((double)ivs_width) * ((double)ivs_height)) > (double)atoi(viewChannelData[0].obj_max_proportion) / 100.0 || + ((double)bounding_for_a_object.width * (double)bounding_for_a_object.height) / (((double)ivs_width) * ((double)ivs_height)) < (double)atoi(viewChannelData[0].obj_min_proportion) / 100.0 + //strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0 + ) + { + continue; + } + + //current_store_objectAblast_store_object_sizḙ + current_store_object_x[current_store_object_size] = bounding_for_a_object.x; + current_store_object_y[current_store_object_size] = bounding_for_a_object.y; + current_store_object_w[current_store_object_size] = bounding_for_a_object.width; + current_store_object_h[current_store_object_size] = bounding_for_a_object.height; + current_store_object_size++; + + if (last_store_object_size >= 1) { + double intersect_ratio = 0.0; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + Rect bounding_for_b_object(last_store_object_x[index_last], last_store_object_y[index_last], + last_store_object_w[index_last], last_store_object_h[index_last]); + Rect bounding_for_intersection_object = bounding_for_a_object & bounding_for_b_object; + if (bounding_for_intersection_object.area() >= 1) + { + double temp_intersect_ratio = (double)bounding_for_intersection_object.area() / (double)bounding_for_a_object.area(); + if (temp_intersect_ratio > intersect_ratio) { + intersect_ratio = temp_intersect_ratio; + } + } + } + + Mat roi_a_object = masked_certain(bounding_for_a_object); + double count_non_zero = ((double)countNonZero(roi_a_object)) / ((double)bounding_for_a_object.width*(double)bounding_for_a_object.height); + roi_a_object.release(); + + //printf("\n---------count_non_zero:%lf\n", count_non_zero); + + if (intersect_ratio >= (double)atoi(viewChannelData[0].confidence_unknown_object) / 100.0 && + count_non_zero >= (double)atoi(viewChannelData[0].confidence2_unknown_object) / 100.0) { + + rectangle(bitwise_and_before_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + + rectangle(short_term_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + + rectangle(long_term_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + +#if 0 + printf("\n------------bounding_for_a_object.x:%d,bounding_for_a_object.y:%d\n", bounding_for_a_object.x, bounding_for_a_object.y); +#endif + if (PosInfo != NULL) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = intersect_ratio * 100; + pNext->confidence2 = count_non_zero * 100; + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = ((float)(bounding_for_a_object.x))*ratio_width; + pNext->top_y = ((float)(bounding_for_a_object.y))*ratio_height; + pNext->width = ((float)(bounding_for_a_object.width))*ratio_width; + pNext->height = ((float)(bounding_for_a_object.height))*ratio_height; + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 1; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } +#endif +#if 1 + for (int i = 0; i < (int)store_ivs_object.size() /*&& area_scale <= 0.45*/; i++) { + Rect bounding_for_a_object; + + bounding_for_a_object = store_ivs_object[i]; + + if (//(double)bounding_for_a_object.area() / ((double)ivs_width * (double)ivs_height) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + //(double)bounding_for_a_object.area() / ((double)ivs_width * (double)ivs_height) >= (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.width / ((double)ivs_width) > (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.height / ((double)ivs_height) > (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.width / ((double)ivs_width) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + (double)bounding_for_a_object.height / ((double)ivs_height) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + ((double)bounding_for_a_object.width * (double)bounding_for_a_object.height) / (((double)ivs_width) * ((double)ivs_height)) > (double)atoi(viewChannelData[0].obj_max_proportion) / 100.0 || + ((double)bounding_for_a_object.width * (double)bounding_for_a_object.height) / (((double)ivs_width) * ((double)ivs_height)) < (double)atoi(viewChannelData[0].obj_min_proportion) / 100.0 + //strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0 + ) + { + continue; + } + + //current_store_objectAblast_store_object_sizḙ + current_store_object_x[current_store_object_size] = bounding_for_a_object.x; + current_store_object_y[current_store_object_size] = bounding_for_a_object.y; + current_store_object_w[current_store_object_size] = bounding_for_a_object.width; + current_store_object_h[current_store_object_size] = bounding_for_a_object.height; + current_store_object_size++; + + if (last_store_object_size >= 1) { + double intersect_ratio = 0.0; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + Rect bounding_for_b_object(last_store_object_x[index_last], last_store_object_y[index_last], + last_store_object_w[index_last], last_store_object_h[index_last]); + Rect bounding_for_intersection_object = bounding_for_a_object & bounding_for_b_object; + if (bounding_for_intersection_object.area() >= 1) + { + double temp_intersect_ratio = (double)bounding_for_intersection_object.area() / (double)bounding_for_a_object.area(); + if (temp_intersect_ratio > intersect_ratio) { + intersect_ratio = temp_intersect_ratio; + } + } + } + + Mat roi_a_object = masked_certain(bounding_for_a_object); + double count_non_zero = ((double)countNonZero(roi_a_object)) / ((double)bounding_for_a_object.width*(double)bounding_for_a_object.height); + roi_a_object.release(); + + //printf("\n---------count_non_zero:%lf\n", count_non_zero); + + if (intersect_ratio >= (double)atoi(viewChannelData[0].confidence_unknown_object) / 100.0 && + count_non_zero >= (double)atoi(viewChannelData[0].confidence2_unknown_object) / 100.0) { + + rectangle(bitwise_and_before_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + + rectangle(short_term_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + + rectangle(long_term_contours, + bounding_for_a_object, + Scalar(255, 255, 255), + 3, 8, 0); + +#if 0 + printf("\n------------bounding_for_a_object.x:%d,bounding_for_a_object.y:%d\n", bounding_for_a_object.x, bounding_for_a_object.y); +#endif + if (PosInfo != NULL) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = intersect_ratio * 100; + pNext->confidence2 = count_non_zero * 100; + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = ((float)(bounding_for_a_object.x))*ratio_width; + pNext->top_y = ((float)(bounding_for_a_object.y))*ratio_height; + pNext->width = ((float)(bounding_for_a_object.width))*ratio_width; + pNext->height = ((float)(bounding_for_a_object.height))*ratio_height; + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 1; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } +#endif + + last_store_object_size = current_store_object_size; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + last_store_object_x[index_last] = current_store_object_x[index_last]; + last_store_object_y[index_last] = current_store_object_y[index_last]; + last_store_object_w[index_last] = current_store_object_w[index_last]; + last_store_object_h[index_last] = current_store_object_h[index_last]; + } + } + } + else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && check_if_tempering_many_times <= 0) || tempering_ready == 1))//(area_scale >= 0.83 && imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) || + { + + current_store_object_size = 0; + last_store_object_size = current_store_object_size; + + tempering_ready = 1; + + if (check_if_compute_median_finish == 1) { + //printf("\ndiffer image --------------- 3\n"); + for (int i = 0; i < store_img_background_array_length; i++) { + img_background_array[i].release(); + } + store_img_background_array_length = 0; + current_index_img_background_array = 0; + virtual_index_img_background_array = 0; + check_if_tempering_happened = (temp_AI_fps - 1) * 2; + record_change_state = 0; + *no_tempering = 0; + tempering_ready = 0; + } + } +#if 0 + else if ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) || + record_change_state == 1) { + + current_store_object_size = 0; + last_store_object_size = current_store_object_size; + + record_change_state = 1; + //printf("\ndiffer image --------------- 6\n"); + if (check_if_compute_median_finish == 1) { + for (int i = 0; i < store_img_background_array_length; i++) { + img_background_array[i].release(); + } + store_img_background_array_length = 0; + current_index_img_background_array = 0; + virtual_index_img_background_array = 0; + check_if_tempering_happened = 0; + record_change_state = 0; + *no_tempering = 0; + tempering_ready = 0; + } + } +#endif + else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1)) { + current_store_object_size = 0; + last_store_object_size = current_store_object_size; + /* + printf("\ndiffer image --------------- 4\n"); + + printf("\n------------last_day_or_night_mode:%d\n", last_day_or_night_mode); + printf("\n------------current_day_or_night_mode:%d\n", current_day_or_night_mode); + printf("\n------------no_tempering:%d\n", *no_tempering); + printf("\n------------record_change_state:%d\n", record_change_state);*/ + if (/*last_day_or_night_mode > 0 && last_day_or_night_mode == current_day_or_night_mode */ + /*get_check_if_existing_any_switch_happened() == 0 &&*/ *no_tempering == 0 && record_change_state == 0) { + //printf("\ndiffer image --------------- 5\n"); + check_if_tempering_many_times--; + } + else if (/*(last_day_or_night_mode > 0 && last_day_or_night_mode != current_day_or_night_mode) */ + /*imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1 ||*/ *no_tempering == 1 || record_change_state == 1 /*|| + get_check_if_existing_any_switch_happened() == 1*/) { + record_change_state = 1; + //printf("\ndiffer image --------------- 6\n"); + if (check_if_compute_median_finish == 1) { + for (int i = 0; i < store_img_background_array_length; i++) { + img_background_array[i].release(); + } + store_img_background_array_length = 0; + current_index_img_background_array = 0; + virtual_index_img_background_array = 0; + check_if_tempering_happened = 0; + record_change_state = 0; + *no_tempering = 0; + tempering_ready = 0; + } + } + } + + + for (int i = 0; i < (int)contours.size(); i++) { + contours[i].clear(); + vector<Point>().swap(contours[i]); + } + + contours.clear(); + vector<vector<Point>>().swap(contours); + + store_rect_contours.clear(); + vector<Rect>().swap(store_rect_contours); + + store_ivs_object.clear(); + vector<Rect>().swap(store_ivs_object); + + store_rect_contours_not_in_zone.clear(); + vector<Rect>().swap(store_rect_contours_not_in_zone); + + + combine_rect_contours.clear(); + vector<Rect>().swap(combine_rect_contours); + //printf("\ndiffer image-------10\n"); + //////////////////N̫ᵲGmat encodeഫchar *e + if (*image_size == 0) { + if (draw_img_long == 1 && draw_img_short == 0) { + vector<uchar> data_encode; + imencode(".jpeg", long_term_contours, data_encode); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + else if (draw_img_long == 0 && draw_img_short == 1) { + vector<uchar> data_encode; + imencode(".jpeg", short_term_contours, data_encode); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + else { + vector<uchar> data_encode; + imencode(".jpeg", bitwise_and_before_contours, data_encode); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + } + //printf("\ndiffer image-------11\n");// + short_term_contours.release(); + long_term_contours.release(); + + bitwise_and_before_contours.release(); + + //////////////////O + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + + img_decode.release(); + //printf("\ndiffer image-------12\n"); + + + if (!img_blur_short_term.empty()) + img_blur_short_term.release(); + + if (!img_blur_long_term.empty()) + img_blur_long_term.release(); + + img_yuv.release(); + img_blur_yuv.release(); + masked_certain.release(); + + //printf("\ndiffer_image--------------------end\n"); + + return (int)valid_bbox_idx; + //return length; + } + } + } +} + +//int count_mog2 = 0; +int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, detection_pos* PosInfo, int i_InSourceOri_w, int i_InSourceOri_h, int draw_img_long, int draw_img_short, int* no_tempering, int not_to_show_tempering) // For normal type +{ + if (AI_fps <= 0 || strcmp(viewChannelData[0].enable_unknown_object, "No") == 0 || check_if_compute_median_finish == 0) { + return 0; + } + else { + //printf("\ndiffer_image--------------------start-----1\n"); + detection_pos* pNext = NULL; + + int temp_AI_fps = AI_fps >= 2 ? AI_fps : 2; + + if (check_if_tempering_many_times == -100) { + check_if_tempering_many_times = (temp_AI_fps - 1) * 2; + } + + uint32_t valid_bbox_idx = 0; + + int ivs_width = 240;//320 + int ivs_height = 135;//180 + float ratio_width = (float)i_InSourceOri_w / (float)ivs_width; + float ratio_height = (float)i_InSourceOri_h / (float)ivs_height; + + if (not_to_show_tempering == 0 && check_if_tempering_happened <= 0) { + *no_tempering = 0; + check_if_tempering_many_times = (temp_AI_fps - 1) * 2; + g_progress_bar = 100.0; + } + else if (not_to_show_tempering == 0 && check_if_tempering_happened >= 1) { + g_progress_bar = 1.0; + + if (PosInfo != NULL && not_to_show_tempering == 0) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "tampering"); + + pNext->confidence = (float)sqrt((double)1.0 * (double)100)*10.0; + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + + pNext->left_x = (float)ivs_width * ratio_width * (float)0.35; + pNext->top_y = (float)ivs_height * ratio_height * (float)0.35; + pNext->width = (float)ivs_width * ratio_width * (float)0.3; + pNext->height = (float)ivs_height * ratio_height * (float)0.3; + + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 1; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + + if (check_if_tempering_happened == 1){ + g_multiLayerMOG2.clearMemory(); + g_multiLayerMOG2.initialize(); + + g_count_mog2 = 0; + + g_multiLayerMOG2_2.clearMemory(); + g_multiLayerMOG2_2.initialize(); + + g_count_mog2_2 = 0; + } + check_if_tempering_happened--; + + + return (int)valid_bbox_idx; + } + + g_progress_bar = 0.0; + + double learning_rate = 1.0 / ((double)temp_AI_fps * 120.0); + double temp_time_interval_with_msec = (double)atoi(viewChannelData[0].dwell_unknown_object) / ((double)MAX_SHORT_TERM - 1.0)*1000.0; //TIME_INTERVAL_WITH_MSEC + //printf("\n------temp_time_interval_with_msec:%lf\n", temp_time_interval_with_msec); + //printf("\nTTTTTTTTT no_tempering:%d\n", *no_tempering); + + time_t current_time = time(0); + pop_not_to_record_hash(current_time); + + //printf("\nTTTTTTTTTT i_InSourceOri_w:%d , i_InSourceOri_h:%d\n", i_InSourceOri_w, i_InSourceOri_h); + //printf("\ndiffer image-------1\n"); + + current_ms_differ_image = getCurrentTime(); + //printf("\n-------------%ld\n", current_ms_differ_image); + + //printf("\nTTTTTTTTTT ratio_width:%f , ratio_height:%f\n", ratio_width, ratio_height); + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + + Mat img_gray; + Mat img_blur; + Mat img_blur_hash; + Mat img_thres; + //Mat img_morph_open_one; + //Mat img_morph_open_twice; + //Mat img_morph_close_one; + //Mat img_morph_close_twice; + + Mat img_absdiff; + + //Mat bitwise_and_before_contours; + //Mat short_term_contours; + //Mat long_term_contours; + + //vector<Mat> img_channels; + + //Mat img_absdiff_short_term; + //Mat img_blur_short_term; + + //Mat img_absdiff_long_term; + //Mat img_blur_long_term; + + //Mat img_yuv; + //Mat img_blur_yuv; + + //Mat masked_certain; + + //int thres_light[3] = { 0 };//25 + + //printf("\ndiffer image-------2\n"); + + ////////////N쥻nechar * decodemat + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + + Mat temp_img_decode; + temp_img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + + + + //printf("\n-----%d,%d,%d,%d\n", temp_img_decode.size().width, i_InSourceOri_w, temp_img_decode.size().height, i_InSourceOri_h); + + if (temp_img_decode.size().width != VIEW_WEB_WIDTH_HD || temp_img_decode.size().height != VIEW_WEB_HEIGHT_HD /*|| g_pMOG2 == nullptr || g_pMOG2_2 == nullptr*/) + { + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + temp_img_decode.release(); + return 0; + } + else + { + Mat img_decode; + resize(temp_img_decode, img_decode, Size(ivs_width, ivs_height), INTER_NEAREST); + temp_img_decode.release(); + + /////////////q}lopencv򥻼vp + //printf("\ndiffer_image--------------------start-----1-------1\n"); + + + //Ƕ + cvtColor(img_decode, img_gray, CV_BGR2GRAY); + //printf("\ndiffer_image--------------------start-----1-------2\n"); +#if 1 + //Loɶbanner + { + + int mask_width = ivs_width; + int mask_height = ivs_height; + + Mat imageMask(mask_height, mask_width, CV_8UC3, Scalar(0, 0, 0)); + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + imageMask(Rect(6, 10, mask_width - 12, mask_height - 20)) = Scalar(255, 255, 255); //make rectangle 1 + } + else { + imageMask(Rect(6, 10, mask_width - 12, mask_height - 20)) = Scalar(255, 255, 255); //make rectangle 1 + } + + Mat imageMask_gray; + cvtColor(imageMask, imageMask_gray, CV_BGR2GRAY); + imageMask.release(); + + Mat maskedImage; + bitwise_and(img_gray, imageMask_gray, maskedImage); + imageMask_gray.release(); + img_gray.release(); + img_gray = maskedImage.clone(); + maskedImage.release(); + } +#endif + //printf("\ndiffer_image--------------------start-----1-------3\n"); + //split(img_decode, img_channels); + + //Mat abs_r_g = abs(img_channels[2] - img_channels[1]); + //Mat abs_r_b = abs(img_channels[2] - img_channels[0]); + //Mat abs_g_b = abs(img_channels[1] - img_channels[0]); + + //double r_g = countNonZero(abs_r_g); + //double r_b = countNonZero(abs_r_b); + //double g_b = countNonZero(abs_g_b); + + //abs_r_g.release(); + //abs_r_b.release(); + //abs_g_b.release(); + + //img_channels[0].release(); + //img_channels[1].release(); + //img_channels[2].release(); + //img_channels.clear(); + //vector<Mat>().swap(img_channels); + + //double ratio_determine_if_color = (r_g + r_b + g_b) / ((double)ivs_width*(double)ivs_height); + + //printf("\n-------imageDnData.current_day_or_night_mode:%d\n", imageDnData.current_day_or_night_mode); + //printf("\n-------imageDnData.check_if_switch_happene[0]:%d\n", imageDnData.check_if_switch_happened[0]); + //printf("\ndiffer_image--------------------start-----1-------4\n"); + //if (not_to_show_tempering == 0) { + //if (imageDnData.current_day_or_night_mode == 1) { + //printf("\nimage is color:%lf\n", ratio_determine_if_color); + //last_day_or_night_mode = current_day_or_night_mode; + //current_day_or_night_mode = 1; + //} + //else { + //printf("\nimage is grayscale:%lf\n", ratio_determine_if_color); + //last_day_or_night_mode = current_day_or_night_mode; + //current_day_or_night_mode = 2; + //} + //} + + //thres_light[0] = 6;//80 //8 + //thres_light[1] = 0;//25 //3 + //thres_light[2] = 0;//25 //3 + + //if (strcmp(viewChannelData[0].ivs_mode, "0") == 0) { + //thres_light[0] = 6;//80 //8 + //} + //else if (strcmp(viewChannelData[0].ivs_mode, "1") == 0) { + //thres_light[0] = 4;//80 //8 + //} + //else if (strcmp(viewChannelData[0].ivs_mode, "2") == 0) { + //thres_light[0] = 2;//80 //8 + //} + + //ҽk + img_blur = img_gray.clone(); + blur(img_gray, img_blur_hash, Size(3, 3));//5 5 //BLUR_SIZE + //bilateralFilter(img_gray, img_blur, 5, 75, 75); + //GaussianBlur(img_gray, img_blur_hash, Size(3, 3),0,0);//4 4 3 3 + + img_gray.release(); + //printf("\ndiffer_image--------------------start-----1-------5\n"); + if (img_blur.size().width == 0 || img_blur.size().height == 0) { + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + img_blur.release(); + img_blur_hash.release(); + return 0; + } + else + { + g_progress_bar = 0.0; + + Mat img_absdiff; + +#if 1 + if (g_count_mog2 >= 250 && g_count_mog2_2 >= 250) { + //int history = 500; // OоvV + //double varThreshold = 20; // ܲH + //bool detectShadows = false; // O_˴v + if (g_count_mog2 >= g_count_mog2_2) { + //g_pMOG2.release(); + //g_pMOG2 = createBackgroundSubtractorMOG2(history, varThreshold, detectShadows); + g_multiLayerMOG2.clearMemory(); + g_multiLayerMOG2.initialize(); + + g_count_mog2 = 0; + } + else { + //g_pMOG2_2.release(); + //g_pMOG2_2 = createBackgroundSubtractorMOG2(history, varThreshold, detectShadows); + g_multiLayerMOG2_2.clearMemory(); + g_multiLayerMOG2_2.initialize(); + + g_count_mog2_2 = 0; + } + } + + if (g_count_mog2 >= g_count_mog2_2) { + //g_pMOG2_2->apply(img_blur, img_absdiff, learning_rate);// MOG2iIAó]mDz߲v0.01 + g_multiLayerMOG2_2.processFrame(img_blur, img_absdiff, learning_rate); + + g_count_mog2_2++; + + img_absdiff.release(); + + //g_pMOG2->apply(img_blur, img_absdiff, learning_rate);// MOG2iIAó]mDz߲v0.01 + g_multiLayerMOG2.processFrame(img_blur, img_absdiff, learning_rate); + g_count_mog2++; + } + else { + //g_pMOG2->apply(img_blur, img_absdiff, learning_rate);// MOG2iIAó]mDz߲v0.01 + g_multiLayerMOG2.processFrame(img_blur, img_absdiff, learning_rate); + g_count_mog2++; + + img_absdiff.release(); + + //g_pMOG2_2->apply(img_blur, img_absdiff, learning_rate);// MOG2iIAó]mDz߲v0.01 + g_multiLayerMOG2_2.processFrame(img_blur, img_absdiff, learning_rate); + g_count_mog2_2++; + } +#endif + + + + vector<vector<Point>> contours; + vector<Rect> store_rect_contours; + vector<Rect> combine_rect_contours; + //vector<Rect>::iterator it_store_rect_contours; + + vector<Rect> store_rect_contours_not_in_zone; + + vector<Rect> store_ivs_object; + + //GȤ THRESH_OTSU|۰ʧ̨λ֭ + double thresh = 50;//25 //100 //50 + int maxVal = 255; + //double new_threshold = 0; + /*new_threshold =*/ + threshold(img_absdiff, img_thres, thresh, maxVal, THRESH_BINARY);////THRESH_OTSU THRESH_BINARY //THRESH_BINARY | THRESH_OTSU + + Mat morph_matrix = getStructuringElement(MORPH_RECT, Size(2, 2));//3 3 + Mat dilate_img/*, dilate_img_2*/; + dilate(img_thres, dilate_img, morph_matrix);//CV_MOP_OPEN + //morphologyEx(img_thres, dilate_img, CV_MOP_OPEN, morph_matrix);//CV_MOP_OPEN + //dilate(dilate_img, dilate_img_2, morph_matrix); + + morph_matrix.release(); + img_absdiff.release(); + img_thres.release(); + + findContours(dilate_img, contours, noArray(), RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); + Size inflationSize(2, 2); + Point inflationOffset(-1, -1); + + //dilate_img_2.release(); + + int contours_size = 0; + int contours_size_not_in_zone = 0; + + if (g_check_if_OK_thermal == 0 && g_IsPTZDevice == 1 && strcmp(SystemSetting.enable_crop_mode, "Yes") == 0) { + if (i_InSourceOri_h >= 1 && i_InSourceOri_w >= 1 && g_framesize_height >= 1 && g_framesize_width >= 1) { + float temp_framsize_height = (float)g_framesize_height; + float temp_framsize_width = (float)g_framesize_width; + float temp_g_ori_yuv_height = (float)i_InSourceOri_h; + float temp_g_ori_yuv_width = (float)i_InSourceOri_w; + + float ratio_height_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_height / temp_framsize_height; + float ratio_width_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_width / temp_framsize_width; + + float thres_x_min = 0.0; + float thres_x_max = 1.0; + float thres_y_min = 0.0; + float thres_y_max = 1.0; + + float cut_thres_ratio = 0.0; + + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + thres_x_min += ((1.0 - cut_thres_ratio) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio) / 2.0); + } + else if (ratio_width_g_ori_yuv_to_ai_webpage < ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + thres_y_min += ((1.0 - cut_thres_ratio) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio) / 2.0); + } + + for (int i = 0; i < (int)contours.size(); i++) { + //if (contourArea(contours[i]) < (ivs_width*ivs_height) / 2000) + //continue; + + Rect temp_rect = boundingRect(contours[i]); + float rect_left_x = ((float)(temp_rect.x))*ratio_width; + float rect_top_y = ((float)(temp_rect.y))*ratio_height; + float rect_width = ((float)(temp_rect.width))*ratio_width; + float rect_height = ((float)(temp_rect.height))*ratio_height; + + if (rect_left_x < 0) { + rect_width += (rect_left_x - 1); + rect_left_x = 0; + } + + if (rect_top_y < 0) { + rect_height += (rect_top_y - 1); + rect_top_y = 0; + } + + if (rect_left_x + rect_width > temp_g_ori_yuv_width - 1) { + rect_width = temp_g_ori_yuv_width - 1 - rect_left_x; + } + + if (rect_top_y + rect_height > temp_g_ori_yuv_height - 1) { + rect_height = temp_g_ori_yuv_height - 1 - rect_top_y; + } + + float rect_center_x = rect_left_x + rect_width / 2.0; + float rect_center_y = rect_top_y + rect_height / 2.0; + + float obj_x_max = (rect_left_x + rect_width) / temp_g_ori_yuv_width; + float obj_x_min = rect_left_x / temp_g_ori_yuv_width; + + float obj_y_max = (rect_top_y + rect_height) / temp_g_ori_yuv_height; + float obj_y_min = rect_top_y / temp_g_ori_yuv_height; + + if (obj_x_max <= thres_x_min || + obj_x_min >= thres_x_max || + obj_y_max <= thres_y_min || + obj_y_min >= thres_y_max) + { + continue; + } + else { + if (obj_x_min < thres_x_min) { + obj_x_min = thres_x_min; + } + + if (obj_x_max > thres_x_max) { + obj_x_max = thres_x_max; + } + + if (obj_y_min < thres_y_min) { + obj_y_min = thres_y_min; + } + + if (obj_y_max > thres_y_max) { + obj_y_max = thres_y_max; + } + + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + float obj_center_x = (obj_x_min + obj_x_max) / 2.0; + float obj_width = (obj_x_max - obj_x_min); + + obj_center_x = (obj_center_x - 0.5) * (1.0 / cut_thres_ratio) + 0.5; + obj_width = obj_width * (1.0 / cut_thres_ratio); + + obj_x_min = obj_center_x - obj_width / 2.0; + obj_x_max = obj_center_x + obj_width / 2.0; + } + else { + float obj_center_y = (obj_y_min + obj_y_max) / 2.0; + float obj_height = (obj_y_max - obj_y_min); + + obj_center_y = (obj_center_y - 0.5) * (1.0 / cut_thres_ratio) + 0.5; + obj_height = obj_height * (1.0 / cut_thres_ratio); + + obj_y_min = obj_center_y - obj_height / 2.0; + obj_y_max = obj_center_y + obj_height / 2.0; + } + + + if (obj_x_min < 0.0) + obj_x_min = 0.0; + + if (obj_x_max > 1.0) + obj_x_max = 1.0; + + if (obj_y_min < 0.0) + obj_y_min = 0.0; + + if (obj_y_max > 1.0) + obj_y_max = 1.0; + + obj_x_min = obj_x_min * (float)i_InSourceOri_w; //1920 + obj_x_max = obj_x_max * (float)i_InSourceOri_w; //1920 + obj_y_min = obj_y_min * (float)i_InSourceOri_h; //1080 + obj_y_max = obj_y_max * (float)i_InSourceOri_h; //1080 + + rect_left_x = obj_x_min; + rect_top_y = obj_y_min; + rect_width = (obj_x_max - obj_x_min); + rect_height = (obj_y_max - obj_y_min); + rect_center_x = rect_left_x + rect_width / 2.0; + rect_center_y = rect_top_y + rect_height / 2.0; + + //int checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 1); + int checkisInside = 1; + if (strcmp(SystemSetting.enable_bounding_box, "No") == 0) { + checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 0); + } + + if (checkisInside == 1) { + store_rect_contours.push_back(temp_rect); + store_rect_contours[contours_size] += inflationOffset; + store_rect_contours[contours_size] += inflationSize; + if (store_rect_contours[contours_size].x < 0) { + store_rect_contours[contours_size].width += (store_rect_contours[contours_size].x - 1); + store_rect_contours[contours_size].x = 0; + } + + if (store_rect_contours[contours_size].y < 0) { + store_rect_contours[contours_size].height += (store_rect_contours[contours_size].y - 1); + store_rect_contours[contours_size].y = 0; + } + + if (store_rect_contours[contours_size].x + store_rect_contours[contours_size].width > ivs_width - 1) { + store_rect_contours[contours_size].width = ivs_width - 1 - store_rect_contours[contours_size].x; + } + + if (store_rect_contours[contours_size].y + store_rect_contours[contours_size].height > ivs_height - 1) { + store_rect_contours[contours_size].height = ivs_height - 1 - store_rect_contours[contours_size].y; + } + + contours_size++; + } + else { + store_rect_contours_not_in_zone.push_back(temp_rect); + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width += (store_rect_contours_not_in_zone[contours_size_not_in_zone].x - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].x = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height += (store_rect_contours_not_in_zone[contours_size_not_in_zone].y - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].y = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x + store_rect_contours_not_in_zone[contours_size_not_in_zone].width > ivs_width - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width = ivs_width - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].x; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y + store_rect_contours_not_in_zone[contours_size_not_in_zone].height > ivs_height - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height = ivs_height - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].y; + } + contours_size_not_in_zone++; + } + } + } + } + } + else { + if (i_InSourceOri_h >= 1 && i_InSourceOri_w >= 1) { + float temp_g_ori_yuv_height = (float)i_InSourceOri_h; + float temp_g_ori_yuv_width = (float)i_InSourceOri_w; + for (int i = 0; i < (int)contours.size(); i++) { + //if (contourArea(contours[i]) < (ivs_width*ivs_height) / 2000) + //continue; + + Rect temp_rect = boundingRect(contours[i]); + float rect_left_x = ((float)(temp_rect.x))*ratio_width; + float rect_top_y = ((float)(temp_rect.y))*ratio_height; + float rect_width = ((float)(temp_rect.width))*ratio_width; + float rect_height = ((float)(temp_rect.height))*ratio_height; + + if (rect_left_x < 0) { + rect_width += (rect_left_x - 1); + rect_left_x = 0; + } + + if (rect_top_y < 0) { + rect_height += (rect_top_y - 1); + rect_top_y = 0; + } + + if (rect_left_x + rect_width > temp_g_ori_yuv_width - 1) { + rect_width = temp_g_ori_yuv_width - 1 - rect_left_x; + } + + if (rect_top_y + rect_height > temp_g_ori_yuv_height - 1) { + rect_height = temp_g_ori_yuv_height - 1 - rect_top_y; + } + + float rect_center_x = rect_left_x + rect_width / 2.0; + float rect_center_y = rect_top_y + rect_height / 2.0; + + //int checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 1); + int checkisInside = 1; + if (strcmp(SystemSetting.enable_bounding_box, "No") == 0) { + checkisInside = check_if_object_in_ivs_zone(rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, 0); + } + //printf("\n--------checkisInside:%d,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d\n", checkisInside, rect_center_x, rect_center_y, rect_width, rect_height, i_InSourceOri_w, i_InSourceOri_h, + //temp_rect.x, temp_rect.y, temp_rect.width, temp_rect.height); + + if (checkisInside == 1) { + store_rect_contours.push_back(temp_rect); + store_rect_contours[contours_size] += inflationOffset; + store_rect_contours[contours_size] += inflationSize; + if (store_rect_contours[contours_size].x < 0) { + store_rect_contours[contours_size].width += (store_rect_contours[contours_size].x - 1); + store_rect_contours[contours_size].x = 0; + } + + if (store_rect_contours[contours_size].y < 0) { + store_rect_contours[contours_size].height += (store_rect_contours[contours_size].y - 1); + store_rect_contours[contours_size].y = 0; + } + + if (store_rect_contours[contours_size].x + store_rect_contours[contours_size].width > ivs_width - 1) { + store_rect_contours[contours_size].width = ivs_width - 1 - store_rect_contours[contours_size].x; + } + + if (store_rect_contours[contours_size].y + store_rect_contours[contours_size].height > ivs_height - 1) { + store_rect_contours[contours_size].height = ivs_height - 1 - store_rect_contours[contours_size].y; + } + + contours_size++; + } + else { + store_rect_contours_not_in_zone.push_back(temp_rect); + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width += (store_rect_contours_not_in_zone[contours_size_not_in_zone].x - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].x = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y < 0) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height += (store_rect_contours_not_in_zone[contours_size_not_in_zone].y - 1); + store_rect_contours_not_in_zone[contours_size_not_in_zone].y = 0; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].x + store_rect_contours_not_in_zone[contours_size_not_in_zone].width > ivs_width - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].width = ivs_width - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].x; + } + + if (store_rect_contours_not_in_zone[contours_size_not_in_zone].y + store_rect_contours_not_in_zone[contours_size_not_in_zone].height > ivs_height - 1) { + store_rect_contours_not_in_zone[contours_size_not_in_zone].height = ivs_height - 1 - store_rect_contours_not_in_zone[contours_size_not_in_zone].y; + } + contours_size_not_in_zone++; + } + } + } + } + +#if 1 + while ((int)store_rect_contours.size() >= 1) { + combine_rect_contours.push_back(store_rect_contours[(int)store_rect_contours.size() - 1]); + store_ivs_object.push_back(store_rect_contours[(int)store_rect_contours.size() - 1]); + + store_rect_contours.pop_back(); + } +#endif + for (int i = 0; i < (int)g_ivs_hash_record.size(); i++) { + + double unseenDuration = difftime(current_time, g_ivs_hash_record[i].firstSeen); + if (unseenDuration > 5.0) + { + Mat a_object_hash_value = generateChecksumUsingHash(img_blur_hash, g_ivs_hash_record[i].bbox); + if (check_if_ivs_hash_has_been_recorded(a_object_hash_value)) { + + for (int j = store_ivs_object.size() - 1; j >= 0; --j) { + Rect intersection = store_ivs_object[j] & g_ivs_hash_record[i].bbox; + if (intersection.width * intersection.height) { + store_ivs_object.erase(store_ivs_object.begin() + j); // RŦX󪺨 + } + } + + if (store_ivs_object.empty()) { + store_ivs_object.clear(); // MҦ + store_ivs_object.shrink_to_fit(); // 񥼨ϥΪO + } + + store_ivs_object.push_back(g_ivs_hash_record[i].bbox); + } + a_object_hash_value.release(); + } + } + + int sum_area = 0; + for (int i = 0; i < (int)combine_rect_contours.size(); i++) { + Rect bounding_for_a_object; + bounding_for_a_object = combine_rect_contours[i]; + sum_area += bounding_for_a_object.area(); + + double object_width = (double)bounding_for_a_object.width; + double object_height = (double)bounding_for_a_object.height; + double object_x_left = (double)bounding_for_a_object.x; + double object_y_top = (double)bounding_for_a_object.y; + double object_center_x = object_x_left + object_width / 2.0; + double object_center_y = object_y_top + object_height / 2.0; + double object_x_right = object_x_left + object_width; + double object_y_bottom = object_y_top + object_height; + + if (object_width / object_height > 16.0 / 9.0) { + double temp_height = object_width * 9.0 / 16.0; + object_y_top = object_center_y - temp_height / 2.0; + object_y_bottom = object_center_y + temp_height / 2.0; + if (object_y_top < 0.0) { + temp_height = temp_height + object_y_top; + object_y_top = 0.0; + } + + if (object_y_bottom > ((double)ivs_height) - 1.0) { + temp_height = temp_height - (object_y_bottom - (((double)ivs_height) - 1.0)); + object_y_bottom = ((double)ivs_height) - 1.0; + } + + object_center_y = (object_y_top + object_y_bottom) / 2.0; + object_height = object_y_bottom - object_y_top; + } + else if (object_width / object_height < 5.0 / 5.0) { + double temp_width = object_height * 5.0 / 5.0; + object_x_left = object_center_x - temp_width / 2.0; + object_x_right = object_center_x + temp_width / 2.0; + if (object_x_left < 0.0) { + temp_width = temp_width + object_x_left; + object_x_left = 0.0; + } + + if (object_x_right > ((double)ivs_width) - 1.0) { + temp_width = temp_width - (object_x_right - (((double)ivs_width) - 1.0)); + object_x_right = ((double)ivs_width) - 1.0; + } + + object_center_x = (object_x_left + object_x_right) / 2.0; + object_width = object_x_right - object_x_left; + } + + combine_rect_contours[i].x = (int)object_x_left; + combine_rect_contours[i].y = (int)object_y_top; + combine_rect_contours[i].width = (int)object_width; + combine_rect_contours[i].height = (int)object_height; + } + + int image_center_x = ivs_width / 2; + int image_center_y = ivs_height / 2; + + // ϥ std::sort store_ivs_object iƧǡAϹIZ + sort(store_ivs_object.begin(), store_ivs_object.end(), + [image_center_x, image_center_y](const Rect& a, const Rect& b) { + // px a I + int center_a_x = a.x + a.width / 2; + int center_a_y = a.y + a.height / 2; + + // px b I + int center_b_x = b.x + b.width / 2; + int center_b_y = b.y + b.height / 2; + + // px a PϹIZ + double distance_a = sqrt(pow(center_a_x - image_center_x, 2) + pow(center_a_y - image_center_y, 2)); + + // px b PϹIZ + double distance_b = sqrt(pow(center_b_x - image_center_x, 2) + pow(center_b_y - image_center_y, 2)); + + // Zpu + return distance_a < distance_b; + }); + + double area_scale = ((double)sum_area) / ((double)ivs_width * (double)ivs_height); + + //printf("\n-------area scale:%lf\n", area_scale); + + if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0)) + { + check_if_tempering_many_times = (temp_AI_fps - 1) * 2; + + current_store_object_size = 0; + tempering_ready = 0; + + if (not_to_show_tempering == 0 && (/*(last_day_or_night_mode > 0 && last_day_or_night_mode != current_day_or_night_mode)*/ + /*get_check_if_existing_any_switch_happened() == 1 ||*/ *no_tempering == 1 || record_change_state == 1)) + { + record_change_state = 1; + check_if_tempering_happened = 0; + record_change_state = 0; + *no_tempering = 0; + } + else + { +#if 0 + if (strcmp(viewChannelData[0].enable_ivs_and_ai, "Yes") == 0) { + if (strcmp(viewChannelData[0].enable_ivs_fix_mode, "Yes") == 0) { + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + //if (strcmp(viewDetectionZone[0][index_zone].enable_ivs_zone, "Yes") == 0) + { + float min_x_points = (float)viewDetectionZone[0][index_zone].min_x_points * (float)ivs_width / (float)CANVAS_WIDTH; + float max_x_points = (float)viewDetectionZone[0][index_zone].max_x_points * (float)ivs_width / (float)CANVAS_WIDTH; + float min_y_points = (float)viewDetectionZone[0][index_zone].min_y_points * (float)ivs_height / (float)CANVAS_HEIGHT; + float max_y_points = (float)viewDetectionZone[0][index_zone].max_y_points * (float)ivs_height / (float)CANVAS_HEIGHT; + + if (PosInfo != NULL) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = 0.8 * 100; + pNext->confidence2 = 0.8 * 100; + + float temp_a_x = min_x_points; + float temp_a_y = min_y_points; + float temp_a_width = max_x_points - min_x_points; + float temp_a_height = max_y_points - min_y_points; + + float thres_a_width = 8.0; + float thres_a_height = 6.0; + + if (temp_a_x + temp_a_width < thres_a_width) { + temp_a_x = 0; + temp_a_width = thres_a_width; + } + else if (temp_a_x >= ivs_width - thres_a_width) { + temp_a_x = ivs_width - thres_a_width - 1; + temp_a_width = thres_a_width; + } + else { + if (temp_a_width < thres_a_width) { + temp_a_x -= (thres_a_width - temp_a_width) / 2.0; + temp_a_width = thres_a_width; + } + } + + if (temp_a_y + temp_a_height < thres_a_height) { + temp_a_y = 0; + temp_a_height = thres_a_height; + } + else if (temp_a_y >= ivs_height - thres_a_height) { + temp_a_y = ivs_height - thres_a_height - 1; + temp_a_height = thres_a_height; + } + else { + if (temp_a_height < thres_a_height) { + temp_a_y -= (thres_a_height - temp_a_height) / 2.0; + temp_a_height = thres_a_height; + } + } + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = temp_a_x * ratio_width; + pNext->top_y = temp_a_y * ratio_height; + pNext->width = temp_a_width * ratio_width; + pNext->height = temp_a_height * ratio_height; + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 2; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } + else { + for (int i = 0; i < (int)combine_rect_contours.size(); i++) + { + Rect bounding_for_a_object; + + bounding_for_a_object = combine_rect_contours[i]; + + //current_store_objectAblast_store_object_sizḙ + current_store_object_x[current_store_object_size] = bounding_for_a_object.x; + current_store_object_y[current_store_object_size] = bounding_for_a_object.y; + current_store_object_w[current_store_object_size] = bounding_for_a_object.width; + current_store_object_h[current_store_object_size] = bounding_for_a_object.height; + current_store_object_size++; + + if (last_store_object_size >= 1) { + double intersect_ratio = 0.0; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + Rect bounding_for_b_object(last_store_object_x[index_last], last_store_object_y[index_last], + last_store_object_w[index_last], last_store_object_h[index_last]); + Rect bounding_for_intersection_object = bounding_for_a_object & bounding_for_b_object; + if (bounding_for_intersection_object.area() >= 1) + { + double temp_intersect_ratio = (double)bounding_for_intersection_object.area() / (double)bounding_for_a_object.area(); + if (temp_intersect_ratio > intersect_ratio) { + intersect_ratio = temp_intersect_ratio; + } + } + } + + //Mat roi_a_object = masked_certain(bounding_for_a_object); + //double count_non_zero = ((double)countNonZero(roi_a_object)) / ((double)bounding_for_a_object.width*(double)bounding_for_a_object.height); + //roi_a_object.release(); + + //printf("\n---------count_non_zero:%lf\n", count_non_zero); + + if (intersect_ratio >= (double)atoi(viewChannelData[0].confidence_unknown_object) / 100.0 /*&& + count_non_zero >= (double)atoi(viewChannelData[0].confidence2_unknown_object) / 100.0*/) + { +#if 0 + printf("\n------------bounding_for_a_object.x:%d,bounding_for_a_object.y:%d\n", bounding_for_a_object.x, bounding_for_a_object.y); +#endif + if (PosInfo != NULL) { + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = intersect_ratio * 100; + pNext->confidence2 = 100; + + float temp_a_x = (float)(bounding_for_a_object.x); + float temp_a_y = (float)(bounding_for_a_object.y); + float temp_a_width = (float)(bounding_for_a_object.width); + float temp_a_height = (float)(bounding_for_a_object.height); + + float thres_a_width = 8.0; + float thres_a_height = 6.0; + + if (temp_a_x + temp_a_width < thres_a_width) { + temp_a_x = 0; + temp_a_width = thres_a_width; + } + else if (temp_a_x >= ivs_width - thres_a_width) { + temp_a_x = ivs_width - thres_a_width - 1; + temp_a_width = thres_a_width; + } + else { + if (temp_a_width < thres_a_width) { + temp_a_x -= (thres_a_width - temp_a_width) / 2.0; + temp_a_width = thres_a_width; + } + } + + if (temp_a_y + temp_a_height < thres_a_height) { + temp_a_y = 0; + temp_a_height = thres_a_height; + } + else if (temp_a_y >= ivs_height - thres_a_height) { + temp_a_y = ivs_height - thres_a_height - 1; + temp_a_height = thres_a_height; + } + else { + if (temp_a_height < thres_a_height) { + temp_a_y -= (thres_a_height - temp_a_height) / 2.0; + temp_a_height = thres_a_height; + } + } + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = temp_a_x * ratio_width; + pNext->top_y = temp_a_y * ratio_height; + pNext->width = temp_a_width * ratio_width; + pNext->height = temp_a_height * ratio_height; + pNext->center_x = pNext->left_x + pNext->width / 2; + pNext->center_y = pNext->top_y + pNext->height / 2; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 2; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } + } + } +#endif +#if 1 + for (int i = 0; i < (int)store_ivs_object.size() /*&& area_scale <= 0.45*/; i++) { + Rect bounding_for_a_object; + + bounding_for_a_object = store_ivs_object[i]; + + if (//(double)bounding_for_a_object.area() / ((double)ivs_width * (double)ivs_height) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + //(double)bounding_for_a_object.area() / ((double)ivs_width * (double)ivs_height) >= (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.width / ((double)ivs_width) > (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.height / ((double)ivs_height) > (double)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + (double)bounding_for_a_object.width / ((double)ivs_width) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + (double)bounding_for_a_object.height / ((double)ivs_height) <= (double)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + ((double)bounding_for_a_object.width * (double)bounding_for_a_object.height) / (((double)ivs_width) * ((double)ivs_height)) > (double)atoi(viewChannelData[0].obj_max_proportion) / 100.0 || + ((double)bounding_for_a_object.width * (double)bounding_for_a_object.height) / (((double)ivs_width) * ((double)ivs_height)) < (double)atoi(viewChannelData[0].obj_min_proportion) / 100.0 + //strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0 + ) + { + continue; + } + + //current_store_objectAblast_store_object_sizḙ + current_store_object_x[current_store_object_size] = bounding_for_a_object.x; + current_store_object_y[current_store_object_size] = bounding_for_a_object.y; + current_store_object_w[current_store_object_size] = bounding_for_a_object.width; + current_store_object_h[current_store_object_size] = bounding_for_a_object.height; + current_store_object_size++; + + if (last_store_object_size >= 1) { + double intersect_ratio = 0.0; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + Rect bounding_for_b_object(last_store_object_x[index_last], last_store_object_y[index_last], + last_store_object_w[index_last], last_store_object_h[index_last]); + Rect bounding_for_intersection_object = bounding_for_a_object & bounding_for_b_object; + if (bounding_for_intersection_object.area() >= 1) + { + double temp_intersect_ratio = (double)bounding_for_intersection_object.area() / (double)bounding_for_a_object.area(); + if (temp_intersect_ratio > intersect_ratio) { + intersect_ratio = temp_intersect_ratio; + } + } + } + + //Mat roi_a_object = masked_certain(bounding_for_a_object); + //double count_non_zero = ((double)countNonZero(roi_a_object)) / ((double)bounding_for_a_object.width*(double)bounding_for_a_object.height); + //roi_a_object.release(); + + //printf("\n---------count_non_zero:%lf\n", count_non_zero); + + if (intersect_ratio >= (double)atoi(viewChannelData[0].confidence_unknown_object) / 100.0 /*&& + count_non_zero >= (double)atoi(viewChannelData[0].confidence2_unknown_object) / 100.0*/) { + +#if 0 + printf("\n------------bounding_for_a_object.x:%d,bounding_for_a_object.y:%d\n", bounding_for_a_object.x, bounding_for_a_object.y); +#endif + float p_left_x = ((float)(bounding_for_a_object.x))*ratio_width; + float p_top_y = ((float)(bounding_for_a_object.y))*ratio_height; + float p_width = ((float)(bounding_for_a_object.width))*ratio_width; + float p_height = ((float)(bounding_for_a_object.height))*ratio_height; + float p_center_x = p_left_x + p_width / 2; + float p_center_y = p_top_y + p_height / 2; + + if (valid_bbox_idx <= 25 && p_center_y < (float)i_InSourceOri_h * 2 / 3 && p_width / (float)i_InSourceOri_w <= 0.25) { + if (PosInfo != NULL) { + + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (p_width / (float)i_InSourceOri_w <= 0.25 && ((p_height * p_width) / ((float)i_InSourceOri_w * (float)i_InSourceOri_h)) >= 0.025) + { + int check_if_in_zone = 0; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + int temp_check_if_in_zone = check_if_object_in_zone_width_zone(p_center_x, p_center_y, p_width * 1.1, p_height * 1.1, (float)i_InSourceOri_w, (float)i_InSourceOri_h, 0, index_zone); + if (temp_check_if_in_zone == 1) { + check_if_in_zone = temp_check_if_in_zone; + break; + } + } + + if (check_if_in_zone == 1) { + Mat a_object_hash_value = generateChecksumUsingHash(img_blur_hash, bounding_for_a_object); + if (!check_if_ivs_hash_has_been_recorded(a_object_hash_value)) + { + push_back_to_record_hash(bounding_for_a_object, a_object_hash_value); + } + a_object_hash_value.release(); + } + } + } + + pNext = PosInfo + valid_bbox_idx; + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "object"); + + //pNext->confidence = (float)sqrt(intersect_ratio * (double)100)*10.0; + + pNext->confidence = intersect_ratio * 100; + pNext->confidence2 = 100; + + pNext->engine_type = FEATURE_TRAF_DET;//layerFeatureType[layer_idx]; + pNext->engine_type2 = FEATURE_AIAREA; + pNext->left_x = p_left_x; + pNext->top_y = p_top_y; + pNext->width = p_width; + pNext->height = p_height; + pNext->center_x = p_center_x; + pNext->center_y = p_center_y; + pNext->parent_idx = -1; + pNext->car_logo_idx = -1; + pNext->number_row = 1; + pNext->class_id = 999; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + pNext->obj_type = _PLATE; + + valid_bbox_idx++; + } + } + } + } + } +#endif + + last_store_object_size = current_store_object_size; + for (int index_last = 0; index_last < last_store_object_size; index_last++) { + last_store_object_x[index_last] = current_store_object_x[index_last]; + last_store_object_y[index_last] = current_store_object_y[index_last]; + last_store_object_w[index_last] = current_store_object_w[index_last]; + last_store_object_h[index_last] = current_store_object_h[index_last]; + } + } + } + else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && check_if_tempering_many_times <= 0) || tempering_ready == 1)) + { + current_store_object_size = 0; + last_store_object_size = current_store_object_size; + + //tempering_ready = 1; + + check_if_tempering_happened = (temp_AI_fps - 1) * 2; + record_change_state = 0; + *no_tempering = 0; + tempering_ready = 0; + } + else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1)) + { + current_store_object_size = 0; + last_store_object_size = current_store_object_size; + + if (*no_tempering == 0 && record_change_state == 0) { + check_if_tempering_many_times--; + } + else if (*no_tempering == 1 || record_change_state == 1) + { + record_change_state = 1; + + check_if_tempering_happened = 0; + record_change_state = 0; + *no_tempering = 0; + tempering_ready = 0; + } + } + + dilate_img.release(); + img_blur.release(); + img_blur_hash.release(); + + for (int i = 0; i < (int)contours.size(); i++) { + contours[i].clear(); + vector<Point>().swap(contours[i]); + } + + contours.clear(); + vector<vector<Point>>().swap(contours); + + store_rect_contours.clear(); + vector<Rect>().swap(store_rect_contours); + + store_ivs_object.clear(); + vector<Rect>().swap(store_ivs_object); + + store_rect_contours_not_in_zone.clear(); + vector<Rect>().swap(store_rect_contours_not_in_zone); + + + combine_rect_contours.clear(); + vector<Rect>().swap(combine_rect_contours); + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + + img_decode.release(); + + //masked_certain.release(); + + return (int)valid_bbox_idx; + } + } + } +} + +int crop_image_ivs(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, detection_pos* pNext, int i_InSourceOri_w, int i_InSourceOri_h) { + + if (pNext == NULL) + return 0; + +#ifdef GY_OS_AMBA + float ratio_width = (float)VIEW_WEB_WIDTH_HD / (float)i_InSourceOri_w; + float ratio_height = (float)VIEW_WEB_HEIGHT_HD / (float)i_InSourceOri_h; +#else + float ratio_width = (float)VIEW_WEB_WIDTH_SMALL / (float)i_InSourceOri_w; + float ratio_height = (float)VIEW_WEB_HEIGHT_SMALL / (float)i_InSourceOri_h; +#endif + + + int offset_x = (int)(pNext->left_x * ratio_width); + int offset_y = (int)(pNext->top_y * ratio_height); + int offset_w = (int)(pNext->width * ratio_width); + int offset_h = (int)(pNext->height * ratio_height); + + if (offset_w == 0 || offset_h == 0) { + return 0; + } + +#ifdef GY_OS_AMBA + if ((offset_x + offset_w) >= VIEW_WEB_WIDTH_HD) { + offset_w = VIEW_WEB_WIDTH_HD - offset_x; + } + + if ((offset_y + offset_h) >= VIEW_WEB_HEIGHT_HD) { + offset_h = VIEW_WEB_HEIGHT_HD - offset_y; + } +#else + if ((offset_x + offset_w) >= VIEW_WEB_WIDTH_SMALL) { + offset_w = VIEW_WEB_WIDTH_SMALL - offset_x; + } + + if ((offset_y + offset_h) >= VIEW_WEB_HEIGHT_SMALL) { + offset_h = VIEW_WEB_HEIGHT_SMALL - offset_y; + } +#endif + + + + //printf("\n-------offset_x:%d,offset_y:%d,offset__w:%d,offset_h:%d\n", offset_x, offset_y, offset_w, offset_h); + + int correct_color_index = 0; + int number_grid_width = 10; + int number_grid_height = 10; + double ratio_color_array[NUM_STRINGS_COLOR] = { 0 }; + int sort_index_color[NUM_STRINGS_COLOR] = { 0 }; + + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + Mat img_decode; + + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + +#ifdef GY_OS_AMBA + if (img_decode.size().width != VIEW_WEB_WIDTH_HD || img_decode.size().height != VIEW_WEB_HEIGHT_HD) +#else + if (img_decode.size().width != VIEW_WEB_WIDTH_SMALL || img_decode.size().height != VIEW_WEB_HEIGHT_SMALL) +#endif + + { + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + return 0; + } + + // Transform it into the C++ cv::Mat format + Mat image = img_decode.clone(); + + // Setup a rectangle to define your region of interest + Rect myROI(offset_x, offset_y, offset_w, offset_h); + + // Crop the full image to that image contained by the rectangle myROI + // Note that this doesn't copy the data + + Mat croppedImage = image(myROI); + + Mat gray; + Mat hsv_image; + cvtColor(croppedImage, gray, COLOR_BGR2GRAY); + cvtColor(croppedImage, hsv_image, COLOR_BGR2HSV); + + Mat blurred; + Mat hsv_blurred; + GaussianBlur(gray, blurred, Size(3, 3), 0); + GaussianBlur(hsv_image, hsv_blurred, Size(5, 5), 0); + + Mat binaryIMG; + Canny(blurred, binaryIMG, 20, 160); + vector<vector<Point>> contours; + findContours(binaryIMG, contours, noArray(), RETR_LIST, CHAIN_APPROX_NONE); + + vector<Point> store_all_points; + vector<Point> convexhull_points; + Point temp_point; + Point center_point; + + for (int i = 0; i < (int)contours.size(); i++) { + for (int j = 0; j < (int)contours[i].size(); j++) { + if (contours[i][j].x >= (binaryIMG.cols / 20) && contours[i][j].x <= (binaryIMG.cols * 19 / 20) && + contours[i][j].y >= (binaryIMG.rows*4 / 20) && contours[i][j].y <= (binaryIMG.rows * 18 / 20)) { + temp_point.x = contours[i][j].x; + temp_point.y = contours[i][j].y; + store_all_points.push_back(temp_point); + //circle(croppedImage, temp_point, 0, Scalar(0, 255, 0), -1, 8, 0); + } + } + } + if (store_all_points.size() >= 1) { + convexHull(store_all_points, convexhull_points); + + if (convexhull_points.size() >= 1) { + + Rect bounding_for_a_object; + bounding_for_a_object = boundingRect(convexhull_points); + + if (bounding_for_a_object.width >= number_grid_width && bounding_for_a_object.height >= number_grid_height) { + for (int i = 0; i < number_grid_width; i++) { + for (int j = 0; j < number_grid_height; j++) { + //W kW U kU ̤W ̤U @32Ӧ + if (j == 0) + continue; + else if (j == 1 && (i <= 1 || i >= number_grid_width - 2)) + continue; + else if (j == 2 && (i <= 0 || i >= number_grid_width - 1)) + continue; + else if (j == number_grid_height - 3 && (i <= 0 || i >= number_grid_width - 1)) + continue; + else if (j == number_grid_height - 2 && (i <= 1 || i >= number_grid_width - 2)) + continue; + else if (j == number_grid_height - 1) + continue; + + int x_grid = bounding_for_a_object.x + bounding_for_a_object.width*i / number_grid_width; + int y_grid = bounding_for_a_object.y + bounding_for_a_object.height*j / number_grid_height; + int width_grid = bounding_for_a_object.width / number_grid_width; + int height_grid = bounding_for_a_object.height / number_grid_height; + + Rect a_grid(x_grid, y_grid, width_grid, height_grid); + Mat temp_hsv_blurred = hsv_blurred(a_grid); + Scalar scalar_hsv_value = mean(temp_hsv_blurred); + temp_hsv_blurred.release(); + Scalar scalar_bgr_value; + + double h_color = scalar_hsv_value[0] * 2.0; + double s_color = scalar_hsv_value[1] / 255.0; + double v_color = scalar_hsv_value[2] / 255.0; + + //printf("\n------h_color:%lf\n", h_color); + //printf("\n------s_color:%lf\n", s_color); + //printf("\n------v_color:%lf\n", v_color); + + if (h_color >= 15.0 && h_color < 30.0) { + if (v_color >= 0.12) + { + if (s_color <= 0.15) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(0, 165, 255); // + ratio_color_array[10]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color >= 30.0 && h_color <= 70.0) { + if (v_color >= 0.25) + { + if (s_color <= 0.20) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(0, 255, 255); // + ratio_color_array[5]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 70.0 && h_color <= 150.0) { + if (v_color >= 0.12) + { + if (s_color <= 0.07) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(0, 255, 0); // + ratio_color_array[6]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 150.0 && h_color <= 210.0) { + if (v_color >= 0.25) + { + if (s_color <= 0.25) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(255, 255, 0); //C + ratio_color_array[7]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 210.0 && h_color <= 270.0) { + if (v_color >= 0.25) + { + if (s_color <= 0.20) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(255, 0, 0); //Ŧ + ratio_color_array[8]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 270.0 && h_color <= 330.0) { + if (v_color >= 0.25) + { + if (s_color <= 0.20) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(255, 0, 255); // + ratio_color_array[9]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else { + if (v_color >= 0.12) + { + if (s_color <= 0.07) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 255); // + ratio_color_array[4]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + + if (*image_size == 0) { + rectangle(croppedImage, + a_grid, + scalar_bgr_value, + 1, 8, 0); + } + } + } + + for (int i = 0; i < NUM_STRINGS_COLOR; i++) { + ratio_color_array[i] = ratio_color_array[i] / (double)(number_grid_width*number_grid_height - 32); + sort_index_color[i] = i; + } + + for (int i = 0; i < NUM_STRINGS_COLOR - 1; i++) { + for (int j = i + 1; j < NUM_STRINGS_COLOR; j++) { + if (ratio_color_array[j] > ratio_color_array[i]) { + double temp_ratio = ratio_color_array[i]; + double temp_index = sort_index_color[i]; + ratio_color_array[i] = ratio_color_array[j]; + sort_index_color[i] = sort_index_color[j]; + ratio_color_array[j] = temp_ratio; + sort_index_color[j] = temp_index; + } + } + } + + /* + for (int i = 0; i < NUM_STRINGS_COLOR; i++) { + printf("\ncolor index:%d,color name:%s,count ratio:%lf\n", sort_index_color[i], color_name[sort_index_color[i]], ratio_color_array[i]); + }*/ + + + if (strcmp(color_name[sort_index_color[0]], "Blue") == 0) { + double sum_ratio_silver = 0; + for (int i = 1; i < NUM_STRINGS_COLOR; i++) { + if (strcmp(color_name[sort_index_color[i]], "Cyan") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + } + else if (strcmp(color_name[sort_index_color[i]], "Silver") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + } + } + + if (sum_ratio_silver >= ratio_color_array[0]) { + correct_color_index = 1; + } + else if (ratio_color_array[0] >= 0.85) { + correct_color_index = 9; + } + else { + correct_color_index = sort_index_color[0]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Cyan") == 0) { + double sum_ratio_silver = 0; + double blue_ratio = 0; + for (int i = 1; i < NUM_STRINGS_COLOR; i++) { + if (strcmp(color_name[sort_index_color[i]], "Blue") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + blue_ratio = ratio_color_array[i]; + } + else if (strcmp(color_name[sort_index_color[i]], "Silver") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + } + } + + if (sum_ratio_silver >= ratio_color_array[0] && blue_ratio < 0.14) { + correct_color_index = 1; + } + else if ( + ratio_color_array[0] >= 0.38 && ratio_color_array[0] < 0.68 && + strcmp(color_name[sort_index_color[1]], "Darkgray") == 0 && ratio_color_array[1] >= 0.18 && + ( + (strcmp(color_name[sort_index_color[2]], "Blue") == 0 && ratio_color_array[2] >= 0.14 && + strcmp(color_name[sort_index_color[3]], "Silver") == 0 && ratio_color_array[3] >= 0.1) || + (strcmp(color_name[sort_index_color[2]], "Silver") == 0 && ratio_color_array[2] >= 0.14 && + strcmp(color_name[sort_index_color[3]], "Blue") == 0 && ratio_color_array[3] >= 0.14) + ) + ) + { + correct_color_index = 1; + } + else if (ratio_color_array[0] >= 0.68) + { + correct_color_index = 8; + } + else { + correct_color_index = sort_index_color[0]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Red") == 0) { + int check_if_yellow = 0; + for (int i = 1; i < NUM_STRINGS_COLOR; i++) { + if (ratio_color_array[i] >= 0.12 && strcmp(color_name[sort_index_color[i]], "Yellow") == 0) { + check_if_yellow = 1; + } + } + if (check_if_yellow == 1) { + correct_color_index = 5; + } + else { + correct_color_index = sort_index_color[0]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Silver") == 0) { + if (ratio_color_array[0] >= 0.62) { + correct_color_index = 0; + } + else { + correct_color_index = sort_index_color[0]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Darkgray") == 0) { + if (ratio_color_array[0] >= 0.44) { + correct_color_index = sort_index_color[0]; + } + else if (strcmp(color_name[sort_index_color[1]], "Red") == 0 && ratio_color_array[1] >= 0.12) { + correct_color_index = sort_index_color[1]; + } + else if (strcmp(color_name[sort_index_color[1]], "Cyan") == 0 && ratio_color_array[1] >= 0.15) { + correct_color_index = 1; + } + else if (strcmp(color_name[sort_index_color[1]], "Silver") == 0 && ratio_color_array[1] >= 0.13) { + correct_color_index = sort_index_color[1]; + } + else if (strcmp(color_name[sort_index_color[1]], "Orange") == 0 && ratio_color_array[1] >= 0.15) { + correct_color_index = sort_index_color[1]; + } + else if (strcmp(color_name[sort_index_color[1]], "Green") == 0 && ratio_color_array[1] >= 0.15) { + correct_color_index = sort_index_color[1]; + } + else { + correct_color_index = sort_index_color[0]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Black") == 0) { + if (strcmp(color_name[sort_index_color[1]], "Darkgray") == 0 && ratio_color_array[1] <= 0.34) { + correct_color_index = sort_index_color[1]; + } + else { + correct_color_index = sort_index_color[0]; + } + } + else { + correct_color_index = sort_index_color[0]; + } + + if (correct_color_index == 2) {//convert Darkgray to Black + correct_color_index = 3; + } + else if (correct_color_index == 7) {//convert Cyan to Blue + correct_color_index = 8; + } + } + } + } + + //printf("\n------------current_color:%s\n", color_name[correct_color_index]); + + //polylines(croppedImage, convexhull_points,true, scalar_bgr_value,2,8,0); + + + + + //printf("\n----------size:%d\n", convexhull_points.size()); + + + if (*image_size == 0) { + vector<uchar> data_encode; + imencode(".jpeg", croppedImage, data_encode); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + + for (int i = 0; i < (int)contours.size(); i++) { + contours[i].clear(); + vector<Point>().swap(contours[i]); + } + contours.clear(); + vector<vector<Point>>().swap(contours); + + store_all_points.clear(); + vector<Point>().swap(store_all_points); + + convexhull_points.clear(); + vector<Point>().swap(convexhull_points); + + + image.release(); + croppedImage.release(); + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + + gray.release(); + hsv_blurred.release(); + hsv_image.release(); + blurred.release(); + binaryIMG.release(); + + return color_id_array[correct_color_index]; +} +#endif +int resize_image_ivs(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, int snaphd_image_width, int snaphd_image_height,int resize_width,int resize_height) { + + //int index_zone = 0; + int ret = 1; + + /* + printf("\n------start:%d:%d\n", snaphd_image_width, snaphd_image_height); + for (int index_point = 0; index_point < 6; index_point++) { + printf("(%d)[x:%d,y:%d],",index_point, g_zone_polygon[index_zone][index_point].x * snaphd_image_width / CANVAS_WIDTH, g_zone_polygon[index_zone][index_point].y * snaphd_image_height / CANVAS_HEIGHT); + } + printf("\n------end:%d\n", snaphd_image_size); + */ + + //printf("\n-------------crop zone image ivs-------2\n"); + + //printf("\n-------------crop zone image ivs-------3\n"); + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + Mat img_decode; + + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + //printf("\n-------------crop zone image ivs-------4\n"); + if (img_decode.size().width != snaphd_image_width || img_decode.size().height != snaphd_image_height || resize_width <= 0 || resize_height <= 0) { + //printf("\n-------------crop zone image ivs-------5\n"); + printf("\nimg decode size is error.\n"); + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + ret = 0; + *image_size = 0; + } + else { + //printf("\n-------------crop zone image ivs-------6\n"); + //printf("\n--------correct size\n"); + Mat image = img_decode.clone(); + + Mat dstImage; + + resize(image, dstImage, Size(resize_width, resize_height), 0, 0, INTER_CUBIC); + + { + vector<uchar> data_encode; + vector<int> param = vector<int>(2); + param[0] = CV_IMWRITE_JPEG_QUALITY; + param[1] = 25; //default(95) 0-100 + + imencode(".jpeg", dstImage, data_encode, param); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + + dstImage.release(); + image.release(); + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + } + //printf("\n-------------crop zone image ivs-------7\n"); + //printf("\n-------------crop zone image ivs-------8\n"); + return ret; +} +int crop_zone_image_ivs(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, int snaphd_image_width, int snaphd_image_height, int min_x_temp, int min_y_temp, int max_x_temp, int max_y_temp) { + + //int index_zone = 0; + int ret = 1; + + /* + printf("\n------start:%d:%d\n", snaphd_image_width, snaphd_image_height); + for (int index_point = 0; index_point < 6; index_point++) { + printf("(%d)[x:%d,y:%d],",index_point, g_zone_polygon[index_zone][index_point].x * snaphd_image_width / CANVAS_WIDTH, g_zone_polygon[index_zone][index_point].y * snaphd_image_height / CANVAS_HEIGHT); + } + printf("\n------end:%d\n", snaphd_image_size); + */ + + //printf("\n-------------crop zone image ivs-------1\n"); + + int min_x = min_x_temp * snaphd_image_width / CANVAS_WIDTH; + int max_x = max_x_temp * snaphd_image_width / CANVAS_WIDTH; + + int min_y = min_y_temp * snaphd_image_height / CANVAS_HEIGHT; + int max_y = max_y_temp * snaphd_image_height / CANVAS_HEIGHT; + //printf("\n-------------crop zone image ivs-------2\n"); + if (max_x >= min_x + 1 && max_y >= min_y + 1 && min_x >= 1 && min_y >= 1 && max_x <= snaphd_image_width && max_y <= snaphd_image_height) { + //printf("\n-------------crop zone image ivs-------3\n"); + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + Mat img_decode; + + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + //printf("\n-------------crop zone image ivs-------4\n"); + if (img_decode.size().width != snaphd_image_width || img_decode.size().height != snaphd_image_height) { + //printf("\n-------------crop zone image ivs-------5\n"); + printf("\nimg decode size is error.\n"); + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + ret = 0; + *image_size = 0; + } + else { + //printf("\n-------------crop zone image ivs-------6\n"); + //printf("\n--------correct size\n"); + Mat image = img_decode.clone(); + + Rect myROI(min_x, min_y, max_x - min_x, max_y - min_y); + Mat croppedImage = image(myROI); + + { + vector<uchar> data_encode; + vector<int> param = vector<int>(2); + param[0] = CV_IMWRITE_JPEG_QUALITY; + param[1] = 25; //default(95) 0-100 + + imencode(".jpeg", croppedImage, data_encode, param); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + + croppedImage.release(); + image.release(); + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + } + //printf("\n-------------crop zone image ivs-------7\n"); + } + else { + printf("\n[crop zone image ivs]zone x or y is error.\n"); + ret = 0; + *image_size = 0; + } + //printf("\n-------------crop zone image ivs-------8\n"); + return ret; +} + +int find_zone_color(/*char *output_image, int* image_size,*/ char * snaphd_image_buffer, int snaphd_image_size, int snaphd_image_width, int snaphd_image_height, int min_x_temp, int min_y_temp, int max_x_temp, int max_y_temp) { + + //int index_zone = 0; + int ret = 1; + + /* + printf("\n------start:%d:%d\n", snaphd_image_width, snaphd_image_height); + for (int index_point = 0; index_point < 6; index_point++) { + printf("(%d)[x:%d,y:%d],",index_point, g_zone_polygon[index_zone][index_point].x * snaphd_image_width / CANVAS_WIDTH, g_zone_polygon[index_zone][index_point].y * snaphd_image_height / CANVAS_HEIGHT); + } + printf("\n------end:%d\n", snaphd_image_size); + */ + + //printf("\n-------------crop zone image ivs-------1\n"); + + int min_x = min_x_temp * snaphd_image_width / CANVAS_WIDTH; + int max_x = max_x_temp * snaphd_image_width / CANVAS_WIDTH; + + int min_y = min_y_temp * snaphd_image_height / CANVAS_HEIGHT; + int max_y = max_y_temp * snaphd_image_height / CANVAS_HEIGHT; + //printf("\n-------------crop zone image ivs-------2\n"); + if (max_x >= min_x + 1 && max_y >= min_y + 1 && min_x >= 1 && min_y >= 1 && max_x <= snaphd_image_width && max_y <= snaphd_image_height) { + //printf("\n-------------crop zone image ivs-------3\n"); + char img_buf_differ[MAX_IMG_SIZE] = { 0 }; + Mat img_decode; + + memcpy(img_buf_differ, snaphd_image_buffer, snaphd_image_size); + vector<uchar> vector_uchar(img_buf_differ, img_buf_differ + snaphd_image_size); + img_decode = imdecode(vector_uchar, CV_LOAD_IMAGE_COLOR); + //printf("\n-------------crop zone image ivs-------4\n"); + if (img_decode.size().width != snaphd_image_width || img_decode.size().height != snaphd_image_height) { + //printf("\n-------------crop zone image ivs-------5\n"); + printf("\nimg decode size is error.\n"); + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + ret = 0; + //*image_size = 0; + } + else { + //printf("\n-------------crop zone image ivs-------6\n"); + //printf("\n--------correct size\n"); + Mat image = img_decode.clone(); + + Rect myROI(min_x, min_y, max_x - min_x, max_y - min_y); + Mat croppedImage = image(myROI); + Mat hsv_image, yuv_image, hsv_blurred, bgr_blurred, yuv_blurred; + + cvtColor(croppedImage, hsv_image, COLOR_BGR2HSV); + cvtColor(croppedImage, yuv_image, COLOR_BGR2YUV); + GaussianBlur(hsv_image, hsv_blurred, Size(5, 5), 0); + GaussianBlur(croppedImage, bgr_blurred, Size(5, 5), 0); + GaussianBlur(yuv_image, yuv_blurred, Size(5, 5), 0); + + vector<Mat> img_channels, bgr_channels, yuv_channels; + split(hsv_blurred, img_channels); + split(bgr_blurred, bgr_channels); + split(yuv_blurred, yuv_channels); + + double h_color = single_channel_median(img_channels[0], 180) * 2.0; + double s_color = single_channel_median(img_channels[1], 256) / 255.0; + double v_color = single_channel_median(img_channels[2], 256) / 255.0; + double b_color = single_channel_median(bgr_channels[0], 256); + //double g_color = single_channel_median(bgr_channels[1], 256); + double r_color = single_channel_median(bgr_channels[2], 256); + double y_color = single_channel_median(yuv_channels[0], 256); + //double u_color = single_channel_median(yuv_channels[1], 256); + double vv_color = single_channel_median(yuv_channels[2], 256); + + //printf("\n--------H:%f,S:%f,V:%f,B:%f,G:%f,R:%f,Y:%f,U:%f,VV:%f\n", h_color, s_color, v_color, b_color, g_color, r_color, y_color, u_color, vv_color); + + if (h_color == 0.0 && s_color == 0.0) {//¥ռҦ + if (v_color >= 0.5 || r_color >= 128 || y_color >= 128) { + ret = 1;//O + } + else { + ret = 0;//OO + } + } + else {//mҦ + if ((v_color >= 0.5 || r_color >= 128 || vv_color >= 160) && r_color > b_color) { + ret = 1;//O + } + else { + ret = 0;//OO + } + } + + + /* + { + vector<uchar> data_encode; + vector<int> param = vector<int>(2); + param[0] = CV_IMWRITE_JPEG_QUALITY; + param[1] = 25; //default(95) 0-100 + + imencode(".jpeg", croppedImage, data_encode, param); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + }*/ + + bgr_channels[0].release(); + bgr_channels[1].release(); + bgr_channels[2].release(); + bgr_channels.clear(); + vector<Mat>().swap(bgr_channels); + + yuv_channels[0].release(); + yuv_channels[1].release(); + yuv_channels[2].release(); + yuv_channels.clear(); + vector<Mat>().swap(yuv_channels); + + bgr_blurred.release(); + yuv_blurred.release(); + yuv_image.release(); + + img_channels[0].release(); + img_channels[1].release(); + img_channels[2].release(); + img_channels.clear(); + vector<Mat>().swap(img_channels); + + hsv_blurred.release(); + hsv_image.release(); + croppedImage.release(); + image.release(); + + vector_uchar.clear(); + vector<uchar>().swap(vector_uchar); + img_decode.release(); + } + //printf("\n-------------crop zone image ivs-------7\n"); + } + else { + printf("\n[find zone color]zone x or y is error.\n"); + ret = 0; + //*image_size = 0; + } + //printf("\n-------------crop zone image ivs-------8\n"); + return ret; +} + + +#if defined GY_OS_AMBA +int convert_to_general_image_for_lpr(char *output_image, int* image_size, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, int __element_interleaved__, int *sec_color_id) +{ + + //pthread_mutex_lock(&mutex_color_detect); + + //printf("\n------------------[Assign Object Color For Amba]----------------------start\n"); + + int i_object_width = __width__; + int i_object_pitch = __pitch__; + int i_object_height = __height__; + + Mat tempImg; + //clock_t cputime0 = clock(); + char* img_buf = new char[i_object_width * i_object_height * 3]; // RGB 3 channels + + if (__element_interleaved__ == 0) + { + //tempImg = Mat(cvSize(i_object_width, i_object_height), CV_8UC3); + + int i = 0, j = 0; + for (i = 0; i < i_object_height; i++) + { + for (j = 0; j < i_object_width; j++) + { + try + { + /*Vec3b& color = tempImg.at<Vec3b>(i, j); // Get the reference of the pixel + color[2] = __input_rgb_array__[i * i_object_pitch + j]; // Red + color[1] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height]; // Green + color[0] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height * 2]; // Blue*/ + //tempImg.at<Vec3b>(j, i) = color; // Write back if not using the reference. + //printf("RGB(%d, %d)=(%d, %d, %d)\n", j, i, color[2], color[1], color[0]); + + // Using the array transposition. + img_buf[i * i_object_width * 3 + j * 3] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height * 2]; // Blue + img_buf[i * i_object_width * 3 + j * 3 + 1] = __input_rgb_array__[i * i_object_pitch + j + i_object_pitch * i_object_height]; // Green + img_buf[i * i_object_width * 3 + j * 3 + 2] = __input_rgb_array__[i * i_object_pitch + j]; // Red + //printf("img_buf(%d, %d)=(%d, %d, %d)\n", i, j, img_buf[i * i_object_width * 3 + j * 3], img_buf[i * i_object_width * 3 + j * 3 + 1], img_buf[i * i_object_width * 3 + j * 3 + 2]); + } + catch (Exception& reason) + { + printf("Exception reason: %s\n", reason.what()); + } + } + } + + tempImg = Mat(i_object_height, i_object_width, CV_8UC3, img_buf); // Directly assign the array to the source of the Mat. + } + else + { + i_object_width = __width__; + i_object_pitch = __pitch__; + i_object_height = __height__; + tempImg = Mat(i_object_height, i_object_pitch, CV_8UC3, __input_rgb_array__); + + } + + int offset_w = (int)(tempImg.cols); + int offset_h = (int)(tempImg.rows); + + if (offset_w == 0 || offset_h == 0) { + + tempImg.release(); + delete(img_buf); + + return 0; + } + + //printf("\n------offset__w:%d,offset_h:%d\n", offset_w, offset_h); + + int correct_color_index = 0; + int correct_sec_color_index = -1; + int number_grid_width = 10; + int number_grid_height = 10; + double ratio_color_array[NUM_STRINGS_COLOR] = { 0 }; + int sort_index_color[NUM_STRINGS_COLOR] = { 0 }; + + // Transform it into the C++ cv::Mat format + Mat image = tempImg.clone(); + + Mat gray; + Mat hsv_image; + cvtColor(image, gray, COLOR_BGR2GRAY); + cvtColor(image, hsv_image, COLOR_BGR2HSV); + + Mat blurred; + Mat hsv_blurred; + GaussianBlur(gray, blurred, Size(3, 3), 0); + GaussianBlur(hsv_image, hsv_blurred, Size(5, 5), 0); + + Mat binaryIMG; + Canny(blurred, binaryIMG, 20, 160); + vector<vector<Point>> contours; + findContours(binaryIMG, contours, noArray(), RETR_LIST, CHAIN_APPROX_NONE); + + vector<Point> store_all_points; + vector<Point> convexhull_points; + Point temp_point; + Point center_point; + + + temp_point.x = offset_w * 2 / 10; + temp_point.y = offset_h * 2 / 10; + store_all_points.push_back(temp_point); + + temp_point.x = offset_w * 8 / 10; + temp_point.y = offset_h * 2 / 10; + store_all_points.push_back(temp_point); + + temp_point.x = offset_w * 8 / 10; + temp_point.y = offset_h * 8 / 10; + store_all_points.push_back(temp_point); + + temp_point.x = offset_w * 2 / 10; + temp_point.y = offset_h * 8 / 10; + store_all_points.push_back(temp_point); + + + if (store_all_points.size() >= 1) { + convexHull(store_all_points, convexhull_points); + if (convexhull_points.size() >= 1) { + Rect bounding_for_a_object; + bounding_for_a_object = boundingRect(convexhull_points); + if (bounding_for_a_object.width >= number_grid_width && bounding_for_a_object.height >= number_grid_height) { + for (int i = 0 + 3; i < number_grid_width-3; i++) { + for (int j = 0 + 2; j < number_grid_height - 2; j++) { + //W kW U kU ̤W ̤U @32Ӧ + + /* + if (j == 0) + continue; + else if (j == 1 && (i <= 1 || i >= number_grid_width - 2)) + continue; + else if (j == 2 && (i <= 0 || i >= number_grid_width - 1)) + continue; + else if (j == number_grid_height - 3 && (i <= 0 || i >= number_grid_width - 1)) + continue; + else if (j == number_grid_height - 2 && (i <= 1 || i >= number_grid_width - 2)) + continue; + else if (j == number_grid_height - 1) + continue;*/ + + int x_grid = bounding_for_a_object.x + bounding_for_a_object.width*i / number_grid_width; + int y_grid = bounding_for_a_object.y + bounding_for_a_object.height*j / number_grid_height; + int width_grid = bounding_for_a_object.width / number_grid_width; + int height_grid = bounding_for_a_object.height / number_grid_height; + + Rect a_grid(x_grid, y_grid, width_grid, height_grid); + Mat temp_hsv_blurred = hsv_blurred(a_grid); + + vector<Mat> img_channels; + split(temp_hsv_blurred, img_channels); + + //Scalar scalar_hsv_value = mean(temp_hsv_blurred); + + double h_color = single_channel_median(img_channels[0], 180) * 2.0; + double s_color = single_channel_median(img_channels[1], 256) / 255.0; + double v_color = single_channel_median(img_channels[2], 256) / 255.0; + + + temp_hsv_blurred.release(); + img_channels[0].release(); + img_channels[1].release(); + img_channels[2].release(); + img_channels.clear(); + vector<Mat>().swap(img_channels); + Scalar scalar_bgr_value; + + //double h_color = scalar_hsv_value[0] * 2.0; + //double s_color = scalar_hsv_value[1] / 255.0; + //double v_color = scalar_hsv_value[2] / 255.0; + + //printf("\n------h_color:%lf\n", h_color); + //printf("\n------s_color:%lf\n", s_color); + //printf("\n------v_color:%lf\n", v_color); + + /* + if (h_color >= 15.0 && h_color < 30.0) { + if (v_color >= 0.12) + { + if (s_color <= 0.15) { + if (v_color >= 0.75) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.75 && v_color >= 0.5) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(0, 165, 255); // + ratio_color_array[10]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + }*/ + if (h_color >= 22.0 && h_color <= 70.0) {//30 + if (v_color >= 0.12) + { + if (s_color <= 0.07) { + if (v_color >= 0.65) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.65 && v_color >= 0.4) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + if (v_color >= 0.85) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else { + scalar_bgr_value = Scalar(0, 255, 255); // + ratio_color_array[5]++; + } + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 70.0 && h_color <= 190.0) {//150.0 + if (v_color >= 0.12) + { + if (s_color <= 0.07) { + if (v_color >= 0.65) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.65 && v_color >= 0.4) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + if (v_color >= 0.75 && h_color >= 150.0) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else { + scalar_bgr_value = Scalar(0, 255, 0); // + ratio_color_array[6]++; + } + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 190.0 && h_color <= 210.0) {//150.0 + if (v_color >= 0.25) + { + if (s_color <= 0.35) { + if (v_color >= 0.65) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.65 && v_color >= 0.4) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(255, 255, 0); //C + ratio_color_array[7]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 210.0 && h_color <= 300.0) {//270 + if (v_color >= 0.25) + { + if (s_color <= 0.25) { + if (v_color >= 0.65) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.65 && v_color >= 0.4) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(255, 0, 0); //Ŧ + ratio_color_array[8]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else if (h_color > 300.0 && h_color <= 330.0) { + if (v_color >= 0.25) + { + if (s_color <= 0.20) { + if (v_color >= 0.65) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.65 && v_color >= 0.4) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(255, 0, 255); // + ratio_color_array[9]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + else { + if (v_color >= 0.12) + { + if (s_color <= 0.07) { + if (v_color >= 0.65) { + scalar_bgr_value = Scalar(255, 255, 255);//զ + ratio_color_array[0]++; + } + else if (v_color < 0.65 && v_color >= 0.4) { + scalar_bgr_value = Scalar(170, 170, 170);//L + ratio_color_array[1]++; + } + else { + scalar_bgr_value = Scalar(85, 85, 85);//` + ratio_color_array[2]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 255); // + ratio_color_array[4]++; + } + } + else { + scalar_bgr_value = Scalar(0, 0, 0); //¦ + ratio_color_array[3]++; + } + } + + } + } + + for (int i = 0; i < NUM_STRINGS_COLOR; i++) { + ratio_color_array[i] = ratio_color_array[i] / (double)(number_grid_width*number_grid_height - 76); + sort_index_color[i] = i; + } + + for (int i = 0; i < NUM_STRINGS_COLOR - 1; i++) { + for (int j = i + 1; j < NUM_STRINGS_COLOR; j++) { + if (ratio_color_array[j] > ratio_color_array[i]) { + double temp_ratio = ratio_color_array[i]; + double temp_index = sort_index_color[i]; + ratio_color_array[i] = ratio_color_array[j]; + sort_index_color[i] = sort_index_color[j]; + ratio_color_array[j] = temp_ratio; + sort_index_color[j] = temp_index; + } + } + } + + /* + for (int i = 0; i < NUM_STRINGS_COLOR; i++) { + printf("\ncolor index:%d,color name:%s,count ratio:%lf\n", sort_index_color[i], color_name[sort_index_color[i]], ratio_color_array[i]); + }*/ + + + if (strcmp(color_name[sort_index_color[0]], "Blue") == 0) { + double sum_ratio_silver = 0; + for (int i = 1; i < NUM_STRINGS_COLOR; i++) { + if (strcmp(color_name[sort_index_color[i]], "Cyan") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + } + else if (strcmp(color_name[sort_index_color[i]], "Silver") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + } + } + + if (sum_ratio_silver >= ratio_color_array[0]) { + //correct_color_index = 1; + correct_color_index = sort_index_color[0]; + if(ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (ratio_color_array[0] >= 0.85) { + //correct_color_index = 9; + correct_color_index = sort_index_color[0]; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Cyan") == 0) { + double sum_ratio_silver = 0; + double blue_ratio = 0; + double sum_ratio_white = 0; + for (int i = 1; i < NUM_STRINGS_COLOR; i++) { + if (strcmp(color_name[sort_index_color[i]], "Blue") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + blue_ratio = ratio_color_array[i]; + } + else if (strcmp(color_name[sort_index_color[i]], "Silver") == 0) { + sum_ratio_silver = sum_ratio_silver + ratio_color_array[i]; + sum_ratio_white = sum_ratio_white + ratio_color_array[i]; + } + else if (strcmp(color_name[sort_index_color[i]], "White") == 0) { + sum_ratio_white = sum_ratio_white + ratio_color_array[i]; + } + } + + if (sum_ratio_silver >= ratio_color_array[0] && blue_ratio < 0.14) { + correct_color_index = 1; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if ( + ratio_color_array[0] >= 0.38 && ratio_color_array[0] < 0.68 && + strcmp(color_name[sort_index_color[1]], "Darkgray") == 0 && ratio_color_array[1] >= 0.18 && + ( + (strcmp(color_name[sort_index_color[2]], "Blue") == 0 && ratio_color_array[2] >= 0.14 && + strcmp(color_name[sort_index_color[3]], "Silver") == 0 && ratio_color_array[3] >= 0.1) || + (strcmp(color_name[sort_index_color[2]], "Silver") == 0 && ratio_color_array[2] >= 0.14 && + strcmp(color_name[sort_index_color[3]], "Blue") == 0 && ratio_color_array[3] >= 0.14) + ) + ) + { + correct_color_index = 1; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (ratio_color_array[0] >= 0.68) + { + correct_color_index = 8; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (sum_ratio_white >= 0.30) + { + correct_color_index = 1; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Red") == 0) { + int check_if_yellow = 0; + for (int i = 1; i < NUM_STRINGS_COLOR; i++) { + if (ratio_color_array[i] >= 0.35 && strcmp(color_name[sort_index_color[i]], "Yellow") == 0) { + check_if_yellow = 1; + } + } + if (check_if_yellow == 1) { + correct_color_index = 5; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.21) { + correct_sec_color_index = sort_index_color[1]; + //printf("\n----------red---%f\n", ratio_color_array[1]); + } + } + } + else if (strcmp(color_name[sort_index_color[0]], "Silver") == 0) { + if (ratio_color_array[0] >= 0.62) { + correct_color_index = 0; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Darkgray") == 0) { + if (ratio_color_array[0] >= 0.44) { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + else if (strcmp(color_name[sort_index_color[1]], "Red") == 0 && ratio_color_array[1] >= 0.12) { + correct_color_index = sort_index_color[1]; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (strcmp(color_name[sort_index_color[1]], "Cyan") == 0 && ratio_color_array[1] >= 0.15) { + correct_color_index = 1; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (strcmp(color_name[sort_index_color[1]], "Silver") == 0 && ratio_color_array[1] >= 0.13) { + correct_color_index = sort_index_color[1]; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (strcmp(color_name[sort_index_color[1]], "Orange") == 0 && ratio_color_array[1] >= 0.15) { + correct_color_index = sort_index_color[1]; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else if (strcmp(color_name[sort_index_color[1]], "Green") == 0 && ratio_color_array[1] >= 0.15) { + correct_color_index = sort_index_color[1]; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + } + else if (strcmp(color_name[sort_index_color[0]], "Black") == 0) { + if (strcmp(color_name[sort_index_color[1]], "Darkgray") == 0 && ratio_color_array[1] <= 0.34) { + correct_color_index = sort_index_color[1]; + if (ratio_color_array[0] > 0.1) + correct_sec_color_index = sort_index_color[0]; + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + } + else { + correct_color_index = sort_index_color[0]; + if (ratio_color_array[1] > 0.1) + correct_sec_color_index = sort_index_color[1]; + } + + if (correct_color_index == 2) {//convert Darkgray to Black + correct_color_index = 3; + } + else if (correct_color_index == 7) {//convert Cyan to Blue + correct_color_index = 8; + } + else if (correct_color_index == 1) {//convert Silver to White + correct_color_index = 0; + } + else if (correct_color_index == 9 || correct_color_index == 10) {//convert Orange and Purple to Red + correct_color_index = 4; + } + + if (correct_sec_color_index == 2) {//convert Darkgray to Black + correct_sec_color_index = 3; + } + else if (correct_sec_color_index == 7) {//convert Cyan to Blue + correct_sec_color_index = 8; + } + else if (correct_sec_color_index == 1) {//convert Silver to White + correct_sec_color_index = 0; + } + else if (correct_sec_color_index == 9 || correct_sec_color_index == 10) {//convert Orange and Purple to Red + correct_sec_color_index = 4; + } + + if (correct_color_index == correct_sec_color_index) { + for (int i = 0; i < NUM_STRINGS_COLOR; i++) { + if ((ratio_color_array[i] > 0.1 && sort_index_color[i] != correct_color_index && correct_color_index != 4 ) ||//not red + (ratio_color_array[i] > 0.21 && sort_index_color[i] != correct_color_index && correct_color_index == 4)) {//red + + //printf("\n----------the same---%f\n", ratio_color_array[i]); + + int temp_color_index = sort_index_color[i]; + if (temp_color_index == 2) {//convert Darkgray to Black + temp_color_index = 3; + } + else if (temp_color_index == 7) {//convert Cyan to Blue + temp_color_index = 8; + } + else if (temp_color_index == 1) {//convert Silver to White + temp_color_index = 0; + } + else if (temp_color_index == 9 || temp_color_index == 10) {//convert Orange and Purple to Red + temp_color_index = 4; + } + + if (temp_color_index != correct_color_index) { + correct_sec_color_index = temp_color_index; + break; + } + } + } + } + } + } + } + + //printf("\n------------current_color:%s\n", color_name[correct_color_index]); + + + //printf("\n----------size:%d\n", convexhull_points.size()); + + + if (*image_size == 0) { + vector<uchar> data_encode; + imencode(".jpeg", tempImg, data_encode); + string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + memcpy(output_image, str_encode.c_str(), length); + *image_size = length; + + data_encode.clear(); + vector<uchar>().swap(data_encode); + } + + for (int i = 0; i < (int)contours.size(); i++) { + contours[i].clear(); + vector<Point>().swap(contours[i]); + } + contours.clear(); + vector<vector<Point>>().swap(contours); + + store_all_points.clear(); + vector<Point>().swap(store_all_points); + + convexhull_points.clear(); + vector<Point>().swap(convexhull_points); + + + image.release(); + + gray.release(); + hsv_blurred.release(); + hsv_image.release(); + blurred.release(); + binaryIMG.release(); + + tempImg.release(); + delete(img_buf); + + if (correct_sec_color_index >= 0) { + *sec_color_id = color_id_array[correct_sec_color_index]; + } + else { + *sec_color_id = color_id_array[correct_color_index]; + } + return color_id_array[correct_color_index]; +} + +#endif \ No newline at end of file diff --git a/src/ivs.hpp b/src/ivs.hpp new file mode 100644 index 0000000..056b433 --- /dev/null +++ b/src/ivs.hpp @@ -0,0 +1,11 @@ +#if 1 +#pragma once +#ifndef IVS_H_ +#define IVS_H_ +#include "define_inc.h" +#include <opencv2/opencv.hpp> +#include <queue> +#include "utility.h" + +#endif +#endif \ No newline at end of file diff --git a/src/ivsC.h b/src/ivsC.h new file mode 100644 index 0000000..2a8a39a --- /dev/null +++ b/src/ivsC.h @@ -0,0 +1,95 @@ +#if 1 +#pragma once +#ifndef IVSC_H_ +#define IVSC_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "test_nnctrl_live.h" +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <pthread.h> +#include "nweb.h" +#include "utility.h" + + +#define MAX_SHORT_TERM_TEST 15 //25 //ѩɶp⪺YAMAX_SHORT_TERMnOjMAX_LONG_TERM@bAoˤެO@}lIDzߪɶA٬OĤJIAbounding_boxAݺ@˪ɶAo̮ɶ|Oɶq@P +#define MAX_LONG_TERM_TEST 15 //51 //]IDz100Ahbounding_boxĤJIiu51AO٤jݭnA49(IĤJ)AXpj100C +#define MAX_TIME_LENGTH_TEST 15 //63 + +#define MAX_LENGTH_COLOR 25 +#define NUM_STRINGS_COLOR 11 +#define MAX_SHORT_TERM 25 //25 //ѩɶp⪺YAMAX_SHORT_TERMnOjMAX_LONG_TERM@bAoˤެO@}lIDzߪɶA٬OĤJIAbounding_boxAݺ@˪ɶAo̮ɶ|Oɶq@P +#define MAX_LONG_TERM 51 //51 //]IDz100Ahbounding_boxĤJIiu51AO٤jݭnA49(IĤJ)AXpj100C +#define MAX_TIME_LENGTH 57 //63 +#define TEMPERING_MANY_TIMES 50 //check_if_tempering_many_times +#define TEMPERING_HAPPENED 25 //check_if_tempering_happened +#define BORDER_WIDTH_TO_IGNORE 25 +#define BORDER_WIDTH_TO_IGNORE_IVS 1 +#define TIME_INTERVAL_WITH_MSEC 20000 //20000 +#define MAX_NUM_OBJECT 128 + +#define TOF_MAX_TIME_LENGTH 5 //83 +#define BLUR_SIZE 5 +#define MAX_SLICE_SIZE 7 + +#define MAX_QUEUE_HASH_SIZE 128 + +//int get_g_progress_bar(); +void set_g_progress_bar(int progress_bar); +int get_g_progress_bar(); +void initial_ivs(); + +int differ_image_test(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, int i_InSourceOri_w, int i_InSourceOri_h); +int get_store_img_background_array_length_test(); + +extern int g_framesize_width; +extern int g_framesize_height; +extern int g_IsPTZDevice; +extern int g_check_if_OK_thermal; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +extern pthread_mutex_t mutex_compute_median; +//extern pthread_mutex_t mutex_long_term; +//extern pthread_mutex_t mutex_short_term; +//extern pthread_mutex_t mutex_long_term_yuv; +//extern pthread_mutex_t mutex_short_term_yuv; + +extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; +extern HeartbeatInfo heartbeatData; + +//extern MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA]; + +int differ_image(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, detection_pos* PosInfo, int i_InSourceOri_w, int i_InSourceOri_h,int draw_img_long,int draw_img_short, int* no_tempering,int not_to_show_tempering); +int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, detection_pos* PosInfo, int i_InSourceOri_w, int i_InSourceOri_h, int draw_img_long, int draw_img_short, int* no_tempering, int not_to_show_tempering); + +void clear_g_ivs_hash_record(); + +int crop_image_ivs(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, detection_pos* pNext, int i_InSourceOri_w, int i_InSourceOri_h); +void release_img_background(); +//void *compute_median_thread(void *ptr); +void run_compute_median(); +int crop_zone_image_ivs(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, int snaphd_image_width, int snaphd_image_height, int min_x_temp, int min_y_temp, int max_x_temp, int max_y_temp); +int find_zone_color(/*char *output_image, int* image_size, */char * snaphd_image_buffer, int snaphd_image_size, int snaphd_image_width, int snaphd_image_height, int min_x_temp, int min_y_temp, int max_x_temp, int max_y_temp); + +#endif +int resize_image_ivs(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, int snaphd_image_width, int snaphd_image_height, int resize_width, int resize_height); +#if defined GY_OS_AMBA +int convert_to_general_image_for_lpr(char *output_image, int* image_size, char* __input_rgb_array__, int __width__, int __pitch__, int __height__, int __element_interleaved__,int *sec_color_id); + +//int tof_differ_image(char *output_image, int* image_size, char * snaphd_image_buffer, int snaphd_image_size, detection_pos* PosInfo, int i_InSourceOri_w, int i_InSourceOri_h, int draw_img_long, int draw_img_short); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/ivs_detection.cpp b/src/ivs_detection.cpp new file mode 100644 index 0000000..5dfe02e --- /dev/null +++ b/src/ivs_detection.cpp @@ -0,0 +1,51 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <iostream> +#include <random> +#include <opencv2/opencv.hpp> + +#include "ivs_detection.h" + +int CheckIVS(int iFovFilter,float obj_w, float obj_h, int i_InSourceOri_w, int i_InSourceOri_h,char *object_to) +{ + int ret = 0; + + if (iFovFilter <= 0) + { + ret = 0; + } + else { + //printf("fov_f %d\n", iWFovFilter); + + float f_W_fov_ratio = (obj_w / (float)i_InSourceOri_w); + float f_FovFilter = ((float)iFovFilter) / 100.0 * 1.1; + + //float f_area_fov_ratio = (obj_w / (float)i_InSourceOri_w) * (obj_h / (float)i_InSourceOri_h); + + //printf("\n------obj_w:%f,i_InSourceOri_w:%d\n", obj_w, i_InSourceOri_w); + //printf("\n------f_W_fov_ratio:%f,f_FovFilter:%f\n", f_W_fov_ratio, f_FovFilter); + + if (f_W_fov_ratio <= f_FovFilter /*&& f_area_fov_ratio <= f_FovFilter*/) + { + if (strcmp(object_to, "person") == 0) { + if (obj_h * 2.5 < obj_w) + { + ret = 0; + } + else { + ret = 1; + } + } + else { + ret = 1; + } + } + else + { + ret = 0; + } + } + + return ret; +} diff --git a/src/ivs_detection.h b/src/ivs_detection.h new file mode 100644 index 0000000..225ed55 --- /dev/null +++ b/src/ivs_detection.h @@ -0,0 +1,22 @@ +#if 1 +#pragma once +#ifndef IVS_DETECTION_H +#define IVS_DETECTION_H + +#include "define_inc.h" +#include "utility.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + int CheckIVS(int iFovFilter, float obj_w, float obj_h, int i_InSourceOri_w, int i_InSourceOri_h, char *object_to); + +#ifdef __cplusplus +} +#endif + + +#endif +#endif \ No newline at end of file diff --git a/src/jvc_progress.c b/src/jvc_progress.c new file mode 100644 index 0000000..a27a5d8 --- /dev/null +++ b/src/jvc_progress.c @@ -0,0 +1,1165 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "utility.h" +#include "cJSON.h" +#include "nweb.h" +#include "test_nnctrl_live.h" +#include "jvc_progress.h" + +extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; +extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; + +cJSON *j_view_setting, *j_camera; +cJSON *j_obj_min_proportion, *j_obj_max_proportion, *j_count_zone, *j_detection_zone; +cJSON *j_detect; +cJSON *jvc_enable_direction1, *jvc_direction1, *jvc_queuing_count, *jvc_no_parking_time; +cJSON *jvc_ptz_zone_to_preset, *metadata1, +*jvc_enable_detect, *jvc_person_check, *jvc_vehicle_check, +*jvc_person_confidence, *jvc_vehicle_confidence, +*jvc_obj_size, *jvc_behavior, *jvc_detect_priority, *jvc_enable_ptz, +*jvc_trigger_delay_time, *jvc_ptz_tracking_time, *jvc_ptz_fov, +*jvc_ptz_auto_intercept, *jvc_ptz_preset_intercept, +*jvc_trigger_times, *jvc_counter_name, *jvc_counter_value, +*jvc_density_value, *jvc_detect_mode, *jvc_detect_fov, +*jvc_points_num; + +cJSON *jx1, *jy1, *jx2, *jy2, *jx3, *jy3, *jx4, *jy4, *jx5, *jy5, *jx6, *jy6; + +int check_if_jvcsetfile_OK = 0; +int iViewIndex = 0; + +void saveJVCconfigFile() +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char config_PATH[1024]; + + char config_bakPATH[1024]; + strcpy(config_PATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(config_PATH, "jvc_config.json"); + strcat(config_bakPATH, "jvc_config_bak.json"); + //s_ + char* fileBuf = ReadAllBytes(config_PATH); + + int iIndex = 0; + + char tempBuf[128]; + + + if (fileBuf) { + cJSON *j_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (j_root) + { + iIndex = 0; + + j_view_setting = cJSON_GetObjectItem(j_root, "view_setting"); + + if (j_view_setting) + { + j_camera = cJSON_GetObjectItem(j_view_setting, "camera01"); + } + + if (j_camera) + { + j_detection_zone = cJSON_GetObjectItem(j_camera, "detection_zone"); + } + + if (j_detection_zone) { + cJSON_ArrayForEach(j_detect, j_detection_zone) + { + //printf("id: %d, enable detect: %d \n", iIndex, viewDetectionZone[0][iIndex].jvc_enable_detect); +#if 1 + + if (viewDetectionZone[0][iIndex].jvc_enable_detect == 1) { + sprintf(tempBuf, "%d", 1); + cJSON_ReplaceItemInObject(j_detect, "jvc_enable_detect", cJSON_CreateString("1")); + } + else { + sprintf(tempBuf, "%d", 0); + cJSON_ReplaceItemInObject(j_detect, "jvc_enable_detect", cJSON_CreateString("0")); + } + + if (viewDetectionZone[0][iIndex].jvc_person_check == 1) { + sprintf(tempBuf, "%d", 1); + cJSON_ReplaceItemInObject(j_detect, "jvc_person_check", cJSON_CreateString("1")); + } + else { + sprintf(tempBuf, "%d", 0); + cJSON_ReplaceItemInObject(j_detect, "jvc_person_check", cJSON_CreateString("0")); + } + + if (viewDetectionZone[0][iIndex].jvc_vehicle_check == 1) { + sprintf(tempBuf, "%d", 1); + cJSON_ReplaceItemInObject(j_detect, "jvc_vehicle_check", cJSON_CreateString("1")); + } + else { + sprintf(tempBuf, "%d", 0); + cJSON_ReplaceItemInObject(j_detect, "jvc_vehicle_check", cJSON_CreateString("0")); + } +#endif +#if 1 + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_person_confidence); + cJSON_ReplaceItemInObject(j_detect, "jvc_person_confidence", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_vehicle_confidence); + cJSON_ReplaceItemInObject(j_detect, "jvc_vehicle_confidence", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_obj_size); + cJSON_ReplaceItemInObject(j_detect, "jvc_obj_size", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_behavior); + cJSON_ReplaceItemInObject(j_detect, "jvc_behavior", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_detect_priority); + cJSON_ReplaceItemInObject(j_detect, "jvc_detect_priority", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_detect_mode); + cJSON_ReplaceItemInObject(j_detect, "jvc_detect_mode", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_detect_fov); + cJSON_ReplaceItemInObject(j_detect, "jvc_detect_fov", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_trigger_delay_time); + cJSON_ReplaceItemInObject(j_detect, "jvc_trigger_delay_time", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_trigger_times); + cJSON_ReplaceItemInObject(j_detect, "jvc_trigger_times", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_queuing_count); + cJSON_ReplaceItemInObject(j_detect, "jvc_queuing_count", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_enable_direction1); + cJSON_ReplaceItemInObject(j_detect, "jvc_enable_direction1", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%s", viewDetectionZone[0][iIndex].direction1); + cJSON_ReplaceItemInObject(j_detect, "direction1", cJSON_CreateString(tempBuf)); + + cJSON_ReplaceItemInObject(j_detect, "jvc_counter_name", cJSON_CreateString(viewDetectionZone[0][iIndex].jvc_counter_name)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_counter_value); + cJSON_ReplaceItemInObject(j_detect, "jvc_counter_value", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_density_value); + cJSON_ReplaceItemInObject(j_detect, "jvc_density_value", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_enable_ptz); + cJSON_ReplaceItemInObject(j_detect, "jvc_enable_ptz", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_ptz_tracking_time); + cJSON_ReplaceItemInObject(j_detect, "jvc_ptz_tracking_time", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_ptz_fov); + cJSON_ReplaceItemInObject(j_detect, "jvc_ptz_fov", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_ptz_auto_intercept); + cJSON_ReplaceItemInObject(j_detect, "jvc_ptz_auto_intercept", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_ptz_preset_intercept); + cJSON_ReplaceItemInObject(j_detect, "jvc_ptz_preset_intercept", cJSON_CreateString(tempBuf)); + + sprintf(tempBuf, "%d", viewDetectionZone[0][iIndex].jvc_ptz_zone_to_preset); + cJSON_ReplaceItemInObject(j_detect, "ptz_zone_to_preset", cJSON_CreateString(tempBuf)); + + cJSON_ReplaceItemInObject(j_detect, "point_number", cJSON_CreateNumber(viewDetectionZone[0][iIndex].point_num)); +#endif +#if 1 + + + cJSON_ReplaceItemInObject(j_detect, "x1", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[0].x)); + cJSON_ReplaceItemInObject(j_detect, "y1", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[0].y)); + + cJSON_ReplaceItemInObject(j_detect, "x2", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[1].x)); + cJSON_ReplaceItemInObject(j_detect, "y2", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[1].y)); + + cJSON_ReplaceItemInObject(j_detect, "x3", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[2].x)); + cJSON_ReplaceItemInObject(j_detect, "y3", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[2].y)); + + cJSON_ReplaceItemInObject(j_detect, "x4", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[3].x)); + cJSON_ReplaceItemInObject(j_detect, "y4", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[3].y)); + + cJSON_ReplaceItemInObject(j_detect, "x5", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[4].x)); + cJSON_ReplaceItemInObject(j_detect, "y5", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[4].y)); + + cJSON_ReplaceItemInObject(j_detect, "x6", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[5].x)); + cJSON_ReplaceItemInObject(j_detect, "y6", cJSON_CreateNumber(viewDetectionZone[0][iIndex].Points[5].y)); +#endif + iIndex++; + } //cJSON_ArrayForEach-s_detection_zone + } //if temp_detection_zone && s_detection_zone + + + ///save jvc_config & jvc_config_bak + char* JsonString = cJSON_Print(j_root); + + + //printf("save\n"); + +#if 1 + + FILE *f = fopen(config_PATH, "w"); + if (f != NULL) + { + //printf("save %s \n", JsonString); + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(config_PATH, config_bakPATH); + check_if_jvcsetfile_OK = 1; + //g_count_alter = 50; + } +#endif + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + if (j_root) { + cJSON_Delete(j_root); + j_root = NULL; + } + } //if root && j_root + } +} + +void setViewZoneData(int iZoneIndex) +{ + //viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; + //viewDetectionZone[0][iZoneIndex] + + + if (jvc_enable_detect) + { + viewDetectionZone[0][iZoneIndex].jvc_enable_detect = atoi(jvc_enable_detect->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_enable_detect = 0; + + if (jvc_person_check) + { + viewDetectionZone[0][iZoneIndex].jvc_person_check = atoi(jvc_person_check->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_person_check = 0; + + if (jvc_vehicle_check) + { + viewDetectionZone[0][iZoneIndex].jvc_vehicle_check = atoi(jvc_vehicle_check->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_vehicle_check = 0; + + if (jvc_person_confidence) + { + viewDetectionZone[0][iZoneIndex].jvc_person_confidence = atoi(jvc_person_confidence->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_person_confidence = 0; + + if (jvc_vehicle_confidence) + { + viewDetectionZone[0][iZoneIndex].jvc_vehicle_confidence = atoi(jvc_vehicle_confidence->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_vehicle_confidence = 0; + + if (jvc_obj_size) + { + viewDetectionZone[0][iZoneIndex].jvc_obj_size = atoi(jvc_obj_size->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_obj_size = 0; + + if (jvc_behavior) + { + viewDetectionZone[0][iZoneIndex].jvc_behavior = atoi(jvc_behavior->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_behavior = 0; + + if (jvc_detect_priority) + { + viewDetectionZone[0][iZoneIndex].jvc_detect_priority = atoi(jvc_detect_priority->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_detect_priority = 0; + + if (jvc_detect_mode) + { + viewDetectionZone[0][iZoneIndex].jvc_detect_mode = atoi(jvc_detect_mode->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_detect_mode = 0; + + if (jvc_detect_fov) + { + viewDetectionZone[0][iZoneIndex].jvc_detect_fov = atoi(jvc_detect_fov->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_detect_fov = 0; + + if (jvc_trigger_delay_time) + { + viewDetectionZone[0][iZoneIndex].jvc_trigger_delay_time = atoi(jvc_trigger_delay_time->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_trigger_delay_time = 0; + + if (jvc_trigger_times) + { + viewDetectionZone[0][iZoneIndex].jvc_trigger_times = atoi(jvc_trigger_times->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_trigger_times = 0; + + if (jvc_queuing_count) + { + viewDetectionZone[0][iZoneIndex].jvc_queuing_count = atoi(jvc_queuing_count->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_queuing_count = 0; + + if (jvc_enable_direction1) + { + viewDetectionZone[0][iZoneIndex].jvc_enable_direction1 = atoi(jvc_enable_direction1->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_enable_direction1 = 0; + + if (jvc_direction1) + { + viewDetectionZone[0][iZoneIndex].jvc_direction1 = atoi(jvc_direction1->valuestring); + sprintf(viewDetectionZone[0][iZoneIndex].direction1, "%s", jvc_direction1->valuestring); + } + else + { + viewDetectionZone[0][iZoneIndex].jvc_direction1 = 1; + sprintf(viewDetectionZone[0][iZoneIndex].direction1, "%s", "1"); + } + printf("direction1: %s, %d \n", viewDetectionZone[0][iZoneIndex].direction1, viewDetectionZone[0][iZoneIndex].jvc_direction1); + + if (jvc_counter_name) + { + strcpy(viewDetectionZone[0][iZoneIndex].jvc_counter_name, jvc_counter_name->valuestring); + } + + if (jvc_counter_value) + { + viewDetectionZone[0][iZoneIndex].jvc_counter_value = atoi(jvc_counter_value->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_counter_value = 0; + + if (jvc_density_value) + { + viewDetectionZone[0][iZoneIndex].jvc_density_value = atoi(jvc_density_value->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_density_value = 0; + + if (jvc_enable_ptz) + { + viewDetectionZone[0][iZoneIndex].jvc_enable_ptz = atoi(jvc_enable_ptz->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_enable_ptz = 0; + + if (jvc_ptz_tracking_time) + { + viewDetectionZone[0][iZoneIndex].jvc_ptz_tracking_time = atoi(jvc_ptz_tracking_time->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_ptz_tracking_time = 0; + + if (jvc_ptz_fov) + { + viewDetectionZone[0][iZoneIndex].jvc_ptz_fov = atoi(jvc_ptz_fov->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_ptz_fov = 0; + + if (jvc_ptz_auto_intercept) + { + viewDetectionZone[0][iZoneIndex].jvc_ptz_auto_intercept = atoi(jvc_ptz_auto_intercept->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_ptz_auto_intercept = 0; + + if (jvc_ptz_preset_intercept) + { + viewDetectionZone[0][iZoneIndex].jvc_ptz_preset_intercept = atoi(jvc_ptz_preset_intercept->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_ptz_preset_intercept = 0; + + if (jvc_ptz_zone_to_preset) + { + viewDetectionZone[0][iZoneIndex].jvc_ptz_zone_to_preset = atoi(jvc_ptz_zone_to_preset->valuestring); + } + else + viewDetectionZone[0][iZoneIndex].jvc_ptz_zone_to_preset = 0; + + if (jvc_points_num) + { + viewDetectionZone[0][iZoneIndex].point_num = jvc_points_num->valueint; + } + else + viewDetectionZone[0][iZoneIndex].point_num = 6; + + printf("points_num = %d \n", viewDetectionZone[0][iZoneIndex].point_num); + + if (jx1) + { + viewDetectionZone[0][iZoneIndex].Points[0].x = jx1->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)jx1->valueint, CANVAS_WIDTH / 2); +} + else + { + viewDetectionZone[0][iZoneIndex].Points[0].x = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[0].x = 0; + } + + if (jy1) + { + viewDetectionZone[0][iZoneIndex].Points[0].y = jy1->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)jy1->valueint, CANVAS_HEIGHT / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[0].y = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[0].y = 0; + } + + if (jx2) +{ + viewDetectionZone[0][iZoneIndex].Points[1].x = jx2->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)jx2->valueint, CANVAS_WIDTH / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[1].x = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[1].x = 0; + } + + if (jy2) + { + viewDetectionZone[0][iZoneIndex].Points[1].y = jy2->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)jy2->valueint, CANVAS_HEIGHT / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[1].y = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[1].y = 0; + } + + if (jx3) + { + viewDetectionZone[0][iZoneIndex].Points[2].x = jx3->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)jx3->valueint, CANVAS_WIDTH / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[2].x = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[2].x = 0; + } + + if (jy3) + { + viewDetectionZone[0][iZoneIndex].Points[2].y = jy3->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)jy3->valueint, CANVAS_HEIGHT / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[2].y = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[2].y = 0; + } + + if (jx4) + { + viewDetectionZone[0][iZoneIndex].Points[3].x = jx4->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)jx4->valueint, CANVAS_WIDTH / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[3].x = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[3].x = 0; + } + + if (jy4) + { + viewDetectionZone[0][iZoneIndex].Points[3].y = jy4->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)jy4->valueint, CANVAS_HEIGHT / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[3].y = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[3].y = 0; + } + + if (jx5) + { + viewDetectionZone[0][iZoneIndex].Points[4].x = jx5->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)jx5->valueint, CANVAS_WIDTH / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[4].x = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[4].x = 0; + } + + if (jy5) + { + viewDetectionZone[0][iZoneIndex].Points[4].y = jy5->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)jy5->valueint, CANVAS_HEIGHT / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[4].y = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[4].y = 0; + } + + if (jx6) + { + viewDetectionZone[0][iZoneIndex].Points[5].x = jx6->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)jx6->valueint, CANVAS_WIDTH / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[5].x = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[5].x = 0; + } + + if (jy6) + { + viewDetectionZone[0][iZoneIndex].Points[5].y = jy6->valueint; + viewDetectionZone[0][iZoneIndex].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)jy6->valueint, CANVAS_HEIGHT / 2); + } + else + { + viewDetectionZone[0][iZoneIndex].Points[5].y = 0; + viewDetectionZone[0][iZoneIndex].onvif_Points[5].y = 0; + } + + //printf("p6 y = %d \n", viewDetectionZone[0][iZoneIndex].Points[5].y); +} + +///save jvc_config +void jvc_setconfig(char *file_Content) +{ + //printf("get content: \n %s \n", file_Content); + //return; + + int iZoneIdx = 0; + + if (file_Content) { + cJSON *root = cJSON_Parse(file_Content); + + if (root) + { + j_view_setting = cJSON_GetObjectItem(root, "view_setting"); + + if (j_view_setting) + { + j_camera = cJSON_GetObjectItem(j_view_setting, "camera01"); + } + + if (j_camera) + { + j_obj_min_proportion = cJSON_GetObjectItem(j_camera, "obj_min_proportion"); + j_obj_max_proportion = cJSON_GetObjectItem(j_camera, "obj_max_proportion"); + j_count_zone = cJSON_GetObjectItem(j_camera, "count_zone"); + j_detection_zone = cJSON_GetObjectItem(j_camera, "detection_zone"); //detection_zone + } + + if (j_detection_zone) { + cJSON_ArrayForEach(j_detect, j_detection_zone) { + jvc_enable_detect = cJSON_GetObjectItem(j_detect, "jvc_enable_detect"); + jvc_person_check = cJSON_GetObjectItem(j_detect, "jvc_person_check"); + jvc_vehicle_check = cJSON_GetObjectItem(j_detect, "jvc_vehicle_check"); + jvc_person_confidence = cJSON_GetObjectItem(j_detect, "jvc_person_confidence"); + jvc_vehicle_confidence = cJSON_GetObjectItem(j_detect, "jvc_vehicle_confidence"); + jvc_obj_size = cJSON_GetObjectItem(j_detect, "jvc_obj_size"); + jvc_behavior = cJSON_GetObjectItem(j_detect, "jvc_behavior"); + jvc_detect_priority = cJSON_GetObjectItem(j_detect, "jvc_detect_priority"); + jvc_detect_mode = cJSON_GetObjectItem(j_detect, "jvc_detect_mode"); + jvc_detect_fov = cJSON_GetObjectItem(j_detect, "jvc_detect_fov"); + jvc_trigger_delay_time = cJSON_GetObjectItem(j_detect, "jvc_trigger_delay_time"); + jvc_trigger_times = cJSON_GetObjectItem(j_detect, "jvc_trigger_times"); + jvc_queuing_count = cJSON_GetObjectItem(j_detect, "queuing_count"); //no use + jvc_enable_direction1 = cJSON_GetObjectItem(j_detect, "enable_direction1"); //no use + jvc_direction1 = cJSON_GetObjectItem(j_detect, "direction1"); // "jvc_direction1":no use + jvc_counter_name = cJSON_GetObjectItem(j_detect, "jvc_counter_name"); + jvc_counter_value = cJSON_GetObjectItem(j_detect, "jvc_counter_value"); + jvc_density_value = cJSON_GetObjectItem(j_detect, "jvc_density_value"); + + jvc_enable_ptz = cJSON_GetObjectItem(j_detect, "jvc_enable_ptz"); + jvc_ptz_tracking_time = cJSON_GetObjectItem(j_detect, "jvc_ptz_tracking_time"); + jvc_ptz_fov = cJSON_GetObjectItem(j_detect, "jvc_ptz_fov"); + jvc_ptz_auto_intercept = cJSON_GetObjectItem(j_detect, "jvc_ptz_auto_intercept"); + jvc_ptz_preset_intercept = cJSON_GetObjectItem(j_detect, "jvc_ptz_preset_intercept"); + jvc_ptz_zone_to_preset = cJSON_GetObjectItem(j_detect, "ptz_zone_to_preset"); + jvc_points_num = cJSON_GetObjectItem(j_detect, "point_number"); + + + + jx1 = cJSON_GetObjectItem(j_detect, "x1"); + jy1 = cJSON_GetObjectItem(j_detect, "y1"); + + jx2 = cJSON_GetObjectItem(j_detect, "x2"); + jy2 = cJSON_GetObjectItem(j_detect, "y2"); + + jx3 = cJSON_GetObjectItem(j_detect, "x3"); + jy3 = cJSON_GetObjectItem(j_detect, "y3"); + + jx4 = cJSON_GetObjectItem(j_detect, "x4"); + jy4 = cJSON_GetObjectItem(j_detect, "y4"); + + jx5 = cJSON_GetObjectItem(j_detect, "x5"); + jy5 = cJSON_GetObjectItem(j_detect, "y5"); + + jx6 = cJSON_GetObjectItem(j_detect, "x6"); + jy6 = cJSON_GetObjectItem(j_detect, "y6"); + + //Set viewDetectionZone + setViewZoneData(iZoneIdx); + + iZoneIdx++; + } + } + + for (int a = 0; a < MAX_DETECTION_ZONE; a++) + { + printf("B direction1: %s, %d \n", viewDetectionZone[0][a].direction1, viewDetectionZone[0][a].jvc_direction1); + printf("B points_num = %d \n", viewDetectionZone[0][a].point_num); + } + + saveJVCconfigFile(); + + import_config(); + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } // if root + } +} + +/* +static int g_metadata1_num[MAX_DETECTION_ZONE] = { 0 }; +char MetaData3[BUFSIZE] = { 0 }; +char metadata3c[512][STRSPLIT_SIZE] = { 0 }; +int nummeta = 0; +void jvc_setMainSetting() +{ + viewChannelData[0].count_zone = 8; + + int iIsPersonDetection = 0, iIsVehicleDetection = 0; + + for (int iZoneIndex = 0; iZoneIndex < MAX_DETECTION_ZONE; iZoneIndex++) + { + ///set zone + + + ///set metadata + sprintf(viewDetectionZone[0][iZoneIndex].metadata1, "%s", ""); + + //viewDetectionZone[0][iZoneIndex] + if (viewDetectionZone[0][iZoneIndex].jvc_person_check == 1) { + strcat(viewDetectionZone[0][iZoneIndex].metadata1, "person,"); + } + + if (viewDetectionZone[0][iZoneIndex].jvc_vehicle_check == 1) { + strcat(viewDetectionZone[0][iZoneIndex].metadata1, "car,"); + } + + if (viewDetectionZone[0][iZoneIndex].jvc_person_check == 1 || + viewDetectionZone[0][iZoneIndex].jvc_vehicle_check == 1) + { + //viewDetectionZone[0][iZoneIndex].trigger_event[0].checked = 1; + //strcpy(viewDetectionZone[0][iZoneIndex].trigger_event[k].detect_event_id, detect_event_id->valuestring); + //strcpy(viewDetectionZone[0][iZoneIndex].trigger_event[k].detect_event_name, detect_event_name->valuestring); + //strcpy(viewDetectionZone[0][iZoneIndex].trigger_event[k].post_event_name, post_event_name->valuestring); + //strcpy(viewDetectionZone[0][iZoneIndex].trigger_event[k].counter_name, counter_name->valuestring); + } + + + + //printf("%d, matedata = %s \n", iZoneIndex, viewDetectionZone[0][iZoneIndex].metadata1); + //nummeta = StrSplit(viewDetectionZone[0][iZoneIndex].metadata1, metadata3c, ","); + //g_metadata1_num_for_zone[index_zone] = nummeta; + //printf("%d, num = %d \n", iZoneIndex, nummeta); + //viewDetectionZone[0][iZoneIndex].metadata1; + } + + set_metadata(); +} +*/ +extern pthread_mutex_t mutex_config_json; + +void import_config() +{ + pthread_mutex_lock(&mutex_config_json); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char config_PATH[1024]; + strcpy(config_PATH, exePath); + strcat(config_PATH, "config.json"); + + char config_bakPATH[1024]; + strcpy(config_bakPATH, exePath); + strcat(config_bakPATH, "config_bak.json"); + + { + char* fileBuf2 = ReadAllBytes(config_PATH); +#if 1 + if (fileBuf2) { + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (s_root) + { + printf("in root \n"); + + cJSON *s_levenshtein_distance, *s_min_characters, *s_max_characters, *s_obj_min_proportion, *s_obj_max_proportion, + *s_confidence, *s_confidence2, *s_confidence3, *s_confidence4, *s_count_zone, *s_enable_lpr_db, *s_enable_downsized_cropped_roi, + *s_enable_zone_crop_1, *s_enable_add_face_frequent_list, // joy add + *s_enable_PTZ, *s_ptz_tracking_fov_min, *s_ptz_tracking_fov_max, *s_ptz_enable_tracking, *s_ptz_tracking_mode, + *s_ptz_tracking_by_enter_zone, + *s_enable_tracking_limits, *s_ptz_pan_left_limit, *s_ptz_pan_right_limit, *s_ptz_tilt_up_limit, *s_ptz_tilt_down_limit, + *s_ptz_speed, + *s_enable_unknown_object, *s_enable_ivs_person_detection, *s_assign_ivs_object_to, *s_enable_show_unknown_object, + *s_enable_lpr_upon_triggered, *s_dwell_lpr_upon_triggered, *s_unknown_object_max_proportion, *s_unknown_object_min_proportion, + *s_confidence_unknown_object, *s_confidence2_unknown_object, *s_enable_ambulance, *s_enable_blank_plate, *s_enable_stop_sign, + *s_dwell_unknown_object, *s_dwell_minute_focus_on, *s_person_obj_fov, *s_ptz_sensitivity, *s_ptz_tracking_resume_dwell, + *s_cJSON_enable_only_show_metadata1, *s_getnetwork_buffer_id, + *s_tab_view_size, *s_enable_anpr, *s_enable_face, *s_enable_traffic, *s_enable_logo, + *temp_detection_zone, *detect, *s_enable_traffic_light, *s_detection_time, *s_metadata1, *s_metadata2, *s_metadata_stop, + *s_link_to_counter, *s_enable_direction1, *s_enable_direction2, *s_direction1, *s_direction2, *s_no_parking_time, + *s_no_parking_time_in_minute, *s_queuing_count, *s_ptz_zone_to_preset, *s_enable_speed, *s_enable_radar_speed, + *s_set_distance, *s_world_distance_unit, *s_world_distance_side1, *s_world_distance_side2, *s_world_time_unit, + *s_parking_space, *s_parking_line, + *s_point_number, *s_x1, *s_y1, *s_x2, *s_y2, *s_x3, *s_y3, *s_x4, *s_y4, *s_x5, *s_y5, *s_x6, *s_y6, + *s_plate_filter_times, *s_plate_filter_time, *s_plate_free_time, *s_obj_max_proportion_in_zone, *s_obj_min_proportion_in_zone, + *s_red_light_zone, *s_no_give_way_zone_to_protect, *s_no_give_way_zone_to_keep_away, *s_no_give_way_zone_to_protect_2, + *s_no_give_way_zone_to_keep_away_2; + cJSON *trigger_events_0, *trigger_events_1, *trigger_events_2, *trigger_events_3, *trigger_events_4, *trigger_events_5, + *trigger_events_6, *trigger_events_7; + cJSON *s_view_setting, *s_camera, *s_detection_zone, *s_detect, *s_trigger_events_0, *s_trigger_events_1, + *s_trigger_events_2, *s_trigger_events_3, *s_trigger_events_4, *s_trigger_events_5, *s_trigger_events_6, + *s_trigger_events_7; + + cJSON *s_trigger_event, *s_trigger_events_temp; + cJSON * s_detect_event_id, *s_checked, *s_detect_event_name, *s_post_event_name, + *s_counter_name/*,*counter_cust_name*/, *s_counter_increment; + + + s_view_setting = cJSON_GetObjectItem(s_root, "view_setting"); + + if (s_view_setting) { + + for (int iViewIdx = 0; iViewIdx < MAX_AI_ENGINE_VIEW; iViewIdx++) + { + + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", iViewIdx + 1); + s_camera = cJSON_GetObjectItem(s_view_setting, CameraID); + + if (s_camera) { + //camera_name = cJSON_GetObjectItem(camera, "camera_name"); + s_levenshtein_distance = cJSON_GetObjectItem(s_camera, "levenshtein_distance"); + s_min_characters = cJSON_GetObjectItem(s_camera, "min_characters"); + s_max_characters = cJSON_GetObjectItem(s_camera, "max_characters"); + s_obj_min_proportion = cJSON_GetObjectItem(s_camera, "obj_min_proportion"); + s_obj_max_proportion = cJSON_GetObjectItem(s_camera, "obj_max_proportion"); + s_plate_filter_times = cJSON_GetObjectItem(s_camera, "PlateFilterTimes"); + s_plate_filter_time = cJSON_GetObjectItem(s_camera, "PlateFilterTime"); + s_plate_free_time = cJSON_GetObjectItem(s_camera, "PlateRecorderFreeTime"); + s_confidence = cJSON_GetObjectItem(s_camera, "confidence"); //Plate P + s_confidence2 = cJSON_GetObjectItem(s_camera, "confidence2"); //Traffic q + s_confidence3 = cJSON_GetObjectItem(s_camera, "confidence3"); + s_confidence4 = cJSON_GetObjectItem(s_camera, "confidence4"); + s_count_zone = cJSON_GetObjectItem(s_camera, "count_zone"); + s_enable_lpr_db = cJSON_GetObjectItem(s_camera, "enable_lpr_db"); + s_enable_downsized_cropped_roi = cJSON_GetObjectItem(s_camera, "enable_downsized_cropped_roi"); + s_enable_add_face_frequent_list = cJSON_GetObjectItem(s_camera, "enable_add_face_frequent_list"); + s_enable_zone_crop_1 = cJSON_GetObjectItem(s_camera, "enable_zone_crop_1"); + s_enable_PTZ = cJSON_GetObjectItem(s_camera, "enable_PTZ"); + s_ptz_tracking_fov_min = cJSON_GetObjectItem(s_camera, "ptz_tracking_fov_min"); + s_ptz_tracking_fov_max = cJSON_GetObjectItem(s_camera, "ptz_tracking_fov_max"); + s_ptz_enable_tracking = cJSON_GetObjectItem(s_camera, "ptz_enable_tracking"); + s_ptz_tracking_mode = cJSON_GetObjectItem(s_camera, "ptz_tracking_mode"); + s_ptz_tracking_by_enter_zone = cJSON_GetObjectItem(s_camera, "ptz_tracking_by_enter_zone"); + s_enable_tracking_limits = cJSON_GetObjectItem(s_camera, "enable_tracking_limits"); + s_ptz_pan_left_limit = cJSON_GetObjectItem(s_camera, "ptz_pan_left_limit"); + s_ptz_pan_right_limit = cJSON_GetObjectItem(s_camera, "ptz_pan_right_limit"); + s_ptz_tilt_up_limit = cJSON_GetObjectItem(s_camera, "ptz_tilt_up_limit"); + s_ptz_tilt_down_limit = cJSON_GetObjectItem(s_camera, "ptz_tilt_down_limit"); + s_ptz_speed = cJSON_GetObjectItem(s_camera, "ptz_speed"); + s_enable_unknown_object = cJSON_GetObjectItem(s_camera, "enable_unknown_object"); + s_enable_ivs_person_detection = cJSON_GetObjectItem(s_camera, "enable_ivs_person_detection"); + s_assign_ivs_object_to = cJSON_GetObjectItem(s_camera, "assign_ivs_object_to"); + s_enable_ambulance = cJSON_GetObjectItem(s_camera, "enable_ambulance"); + s_enable_blank_plate = cJSON_GetObjectItem(s_camera, "enable_blank_plate"); + s_enable_stop_sign = cJSON_GetObjectItem(s_camera, "enable_stop_sign"); + s_enable_show_unknown_object = cJSON_GetObjectItem(s_camera, "enable_show_unknown_object"); + s_enable_lpr_upon_triggered = cJSON_GetObjectItem(s_camera, "enable_lpr_upon_triggered"); + s_dwell_lpr_upon_triggered = cJSON_GetObjectItem(s_camera, "dwell_lpr_upon_triggered"); + s_unknown_object_max_proportion = cJSON_GetObjectItem(s_camera, "unknown_object_max_proportion"); + s_unknown_object_min_proportion = cJSON_GetObjectItem(s_camera, "unknown_object_min_proportion"); + s_confidence_unknown_object = cJSON_GetObjectItem(s_camera, "confidence_unknown_object"); + s_confidence2_unknown_object = cJSON_GetObjectItem(s_camera, "confidence2_unknown_object"); + s_dwell_unknown_object = cJSON_GetObjectItem(s_camera, "dwell_unknown_object"); + s_dwell_minute_focus_on = cJSON_GetObjectItem(s_camera, "dwell_minute_focus_on"); + s_person_obj_fov = cJSON_GetObjectItem(s_camera, "person_obj_fov"); + s_getnetwork_buffer_id = cJSON_GetObjectItem(s_camera, "getnetwork_buffer_id"); + s_red_light_zone = cJSON_GetObjectItem(s_camera, "red_light_zone"); + s_no_give_way_zone_to_protect = cJSON_GetObjectItem(s_camera, "no_give_way_zone_to_protect"); + s_no_give_way_zone_to_keep_away = cJSON_GetObjectItem(s_camera, "no_give_way_zone_to_keep_away"); + s_no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(s_camera, "no_give_way_zone_to_protect_2"); + s_no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(s_camera, "no_give_way_zone_to_keep_away_2"); + s_ptz_sensitivity = cJSON_GetObjectItem(s_camera, "ptz_sensitivity"); + s_ptz_tracking_resume_dwell = cJSON_GetObjectItem(s_camera, "ptz_tracking_resume_dwell"); + s_cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(s_camera, "enable_only_show_metadata1"); + s_tab_view_size = cJSON_GetObjectItem(s_camera, "tab_view_size"); + s_enable_anpr = cJSON_GetObjectItem(s_camera, "enable_anpr"); + s_enable_face = cJSON_GetObjectItem(s_camera, "enable_face"); + s_enable_traffic = cJSON_GetObjectItem(s_camera, "enable_traffic"); + s_enable_logo = cJSON_GetObjectItem(s_camera, "enable_logo"); + + if (s_enable_traffic) { + viewChannelData[0].enable_traffic = 1; + cJSON_ReplaceItemInObject(s_camera, "enable_traffic", cJSON_CreateString("Yes")); + } + + if (s_count_zone) { + viewChannelData[0].enable_traffic = 1; + cJSON_ReplaceItemInObject(s_camera, "count_zone", cJSON_CreateNumber(MAX_DETECTION_ZONE)); + } + + + s_detection_zone = cJSON_GetObjectItem(s_camera, "detection_zone"); + ///Set each detection + if (s_detection_zone) { + int iZoneIdx = 0; + + cJSON_ArrayForEach(s_detect, s_detection_zone) + { + if (s_detect) + { + s_enable_traffic_light = cJSON_GetObjectItem(s_detect, "enable_traffic_light"); + s_detection_time = cJSON_GetObjectItem(s_detect, "detection_time"); + s_metadata1 = cJSON_GetObjectItem(s_detect, "metadata1"); + { + sprintf(viewDetectionZone[iViewIdx][iZoneIdx].metadata1, "%s", ""); + + //viewDetectionZone[0][iZoneIdx] + if (viewDetectionZone[iViewIdx][iZoneIdx].jvc_person_check == 1) { + strcat(viewDetectionZone[iViewIdx][iZoneIdx].metadata1, "person,"); + } + + if (viewDetectionZone[iViewIdx][iZoneIdx].jvc_vehicle_check == 1) { + strcat(viewDetectionZone[iViewIdx][iZoneIdx].metadata1, "car,"); + } + + int iMetadataLen = strlen(viewDetectionZone[iViewIdx][iZoneIdx].metadata1); + if (viewDetectionZone[iViewIdx][iZoneIdx].metadata1[iMetadataLen - 1] == ',') + viewDetectionZone[iViewIdx][iZoneIdx].metadata1[iMetadataLen - 1] = '\0'; + + + cJSON_ReplaceItemInObject(s_detect, "metadata1", cJSON_CreateString(viewDetectionZone[iViewIdx][iZoneIdx].metadata1)); + } + + //s_metadata2 = cJSON_GetObjectItem(s_detect, "metadata2"); + //s_metadata_stop = cJSON_GetObjectItem(s_detect, "metadata_stop"); + s_link_to_counter = cJSON_GetObjectItem(s_detect, "link_to_counter"); + s_enable_direction1 = cJSON_GetObjectItem(s_detect, "enable_direction1"); + s_enable_direction2 = cJSON_GetObjectItem(s_detect, "enable_direction2"); + s_direction1 = cJSON_GetObjectItem(s_detect, "direction1"); + s_direction2 = cJSON_GetObjectItem(s_detect, "direction2"); + if (s_direction1) { + cJSON_ReplaceItemInObject(s_detect, "direction1", cJSON_CreateString(viewDetectionZone[iViewIdx][iZoneIdx].direction1)); + } + + s_no_parking_time = cJSON_GetObjectItem(s_detect, "no_parking_time"); + if (s_no_parking_time) + { + cJSON_ReplaceItemInObject(s_detect, "no_parking_time", cJSON_CreateString("2")); + } + + s_no_parking_time_in_minute = cJSON_GetObjectItem(s_detect, "no_parking_time_in_minute"); + s_queuing_count = cJSON_GetObjectItem(s_detect, "queuing_count"); + s_ptz_zone_to_preset = cJSON_GetObjectItem(s_detect, "ptz_zone_to_preset"); + s_obj_max_proportion_in_zone = cJSON_GetObjectItem(s_detect, "obj_max_proportion_in_zone"); + s_obj_min_proportion_in_zone = cJSON_GetObjectItem(s_detect, "obj_min_proportion_in_zone"); + + s_enable_speed = cJSON_GetObjectItem(s_detect, "enable_speed"); + s_enable_radar_speed = cJSON_GetObjectItem(s_detect, "enable_radar_speed"); + s_parking_space = cJSON_GetObjectItem(s_detect, "parking_space"); + s_parking_line = cJSON_GetObjectItem(s_detect, "parking_line"); + s_set_distance = cJSON_GetObjectItem(s_detect, "set_distance"); + s_world_distance_unit = cJSON_GetObjectItem(s_detect, "world_distance_unit"); + s_world_distance_side1 = cJSON_GetObjectItem(s_detect, "world_distance_side1"); + s_world_distance_side2 = cJSON_GetObjectItem(s_detect, "world_distance_side2"); + s_world_time_unit = cJSON_GetObjectItem(s_detect, "world_time_unit"); + + if (iZoneIdx == 0) { + s_trigger_events_0 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 1) { + s_trigger_events_1 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 2) { + s_trigger_events_2 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 3) { + s_trigger_events_3 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 4) { + s_trigger_events_4 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 5) { + s_trigger_events_5 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 6) { + s_trigger_events_6 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (iZoneIdx == 7) { + s_trigger_events_7 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + + s_point_number = cJSON_GetObjectItem(s_detect, "point_number"); + s_x1 = cJSON_GetObjectItem(s_detect, "x1"); + s_y1 = cJSON_GetObjectItem(s_detect, "y1"); + s_x2 = cJSON_GetObjectItem(s_detect, "x2"); + s_y2 = cJSON_GetObjectItem(s_detect, "y2"); + s_x3 = cJSON_GetObjectItem(s_detect, "x3"); + s_y3 = cJSON_GetObjectItem(s_detect, "y3"); + s_x4 = cJSON_GetObjectItem(s_detect, "x4"); + s_y4 = cJSON_GetObjectItem(s_detect, "y4"); + s_x5 = cJSON_GetObjectItem(s_detect, "x5"); + s_y5 = cJSON_GetObjectItem(s_detect, "y5"); + s_x6 = cJSON_GetObjectItem(s_detect, "x6"); + s_y6 = cJSON_GetObjectItem(s_detect, "y6"); + + if (s_point_number) { + cJSON_ReplaceItemInObject(s_detect, "point_number", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].point_num)); + } + if (s_x1) { + cJSON_ReplaceItemInObject(s_detect, "x1", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[0].x)); + } + if (s_y1) { + cJSON_ReplaceItemInObject(s_detect, "y1", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[0].y)); + } + if (s_x2) { + cJSON_ReplaceItemInObject(s_detect, "x2", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[1].x)); + } + if (s_y2) { + cJSON_ReplaceItemInObject(s_detect, "y2", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[1].y)); + } + if (s_x3) { + cJSON_ReplaceItemInObject(s_detect, "x3", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[2].x)); + } + if (s_y3) { + cJSON_ReplaceItemInObject(s_detect, "y3", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[2].y)); + } + if (s_x4) { + cJSON_ReplaceItemInObject(s_detect, "x4", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[3].x)); + } + if (s_y4) { + cJSON_ReplaceItemInObject(s_detect, "y4", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[3].y)); + } + if (s_x5) { + cJSON_ReplaceItemInObject(s_detect, "x5", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[4].x)); + } + if (s_y5) { + cJSON_ReplaceItemInObject(s_detect, "y5", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[4].y)); + } + if (s_x6) { + cJSON_ReplaceItemInObject(s_detect, "x6", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[5].x)); + } + if (s_y6) { + cJSON_ReplaceItemInObject(s_detect, "y6", cJSON_CreateNumber(viewDetectionZone[iViewIdx][iZoneIdx].Points[5].y)); + } + } + + iZoneIdx++; + } + } //if (s_detection_zone) { + + ///Set each zone trigger event + for (int iZoneIdx = 0; iZoneIdx < MAX_DETECTION_ZONE; iZoneIdx++) { + if (iZoneIdx == 0) { + s_trigger_events_temp = s_trigger_events_0; + } + else if (iZoneIdx == 1) { + s_trigger_events_temp = s_trigger_events_1; + } + else if (iZoneIdx == 2) { + s_trigger_events_temp = s_trigger_events_2; + } + else if (iZoneIdx == 3) { + s_trigger_events_temp = s_trigger_events_3; + } + else if (iZoneIdx == 4) { + s_trigger_events_temp = s_trigger_events_4; + } + else if (iZoneIdx == 5) { + s_trigger_events_temp = s_trigger_events_5; + } + else if (iZoneIdx == 6) { + s_trigger_events_temp = s_trigger_events_6; + } + else if (iZoneIdx == 7) { + s_trigger_events_temp = s_trigger_events_7; + } + //jvc_behavior + int iEventIdx = 0; + if (s_trigger_events_temp) { + iEventIdx = 0; + cJSON_ArrayForEach(s_trigger_event, s_trigger_events_temp) + { + if (s_trigger_event) + { + s_detect_event_id = cJSON_GetObjectItem(s_trigger_event, "detect_event_id"); + + if (s_detect_event_id) + { + if (strcmp("0x00000001", s_detect_event_id->valuestring) == 0) + { + s_checked = cJSON_GetObjectItem(s_trigger_event, "checked"); + s_detect_event_name = cJSON_GetObjectItem(s_trigger_event, "detect_event_name"); + s_post_event_name = cJSON_GetObjectItem(s_trigger_event, "post_event_name"); + s_counter_name = cJSON_GetObjectItem(s_trigger_event, "counter_name"); + s_counter_increment = cJSON_GetObjectItem(s_trigger_event, "counter_increment"); + + printf("%d zone, enable detect = %d \n ", iZoneIdx, viewDetectionZone[0][iZoneIdx].jvc_enable_detect); + + if (s_checked) + { + if (viewDetectionZone[0][iZoneIdx].jvc_behavior == 0 && + viewDetectionZone[0][iZoneIdx].jvc_enable_detect == 1) + { + printf("set bea a = 1 \n"); + viewDetectionZone[0][iZoneIdx].trigger_event[iEventIdx].checked = 1; + cJSON_ReplaceItemInObject(s_trigger_event, "checked", cJSON_CreateNumber(1)); + } + else + { + printf("set bea a = 0 \n"); + viewDetectionZone[0][iZoneIdx].trigger_event[iEventIdx].checked = 0; + cJSON_ReplaceItemInObject(s_trigger_event, "checked", cJSON_CreateNumber(0)); + } + } + } + + if (strcmp("0x00000008", s_detect_event_id->valuestring) == 0) + { + s_checked = cJSON_GetObjectItem(s_trigger_event, "checked"); + s_detect_event_name = cJSON_GetObjectItem(s_trigger_event, "detect_event_name"); + s_post_event_name = cJSON_GetObjectItem(s_trigger_event, "post_event_name"); + s_counter_name = cJSON_GetObjectItem(s_trigger_event, "counter_name"); + s_counter_increment = cJSON_GetObjectItem(s_trigger_event, "counter_increment"); + + if (s_checked) + { + if (viewDetectionZone[0][iZoneIdx].jvc_behavior == 1 && + viewDetectionZone[0][iZoneIdx].jvc_enable_detect == 1) + { + viewDetectionZone[0][iZoneIdx].trigger_event[iEventIdx].checked = 1; + cJSON_ReplaceItemInObject(s_trigger_event, "checked", cJSON_CreateNumber(1)); + } + else + { + viewDetectionZone[0][iZoneIdx].trigger_event[iEventIdx].checked = 0; + cJSON_ReplaceItemInObject(s_trigger_event, "checked", cJSON_CreateNumber(0)); + } + } + } + + if (strcmp("0x10000000", s_detect_event_id->valuestring) == 0) + { + s_checked = cJSON_GetObjectItem(s_trigger_event, "checked"); + s_detect_event_name = cJSON_GetObjectItem(s_trigger_event, "detect_event_name"); + s_post_event_name = cJSON_GetObjectItem(s_trigger_event, "post_event_name"); + s_counter_name = cJSON_GetObjectItem(s_trigger_event, "counter_name"); + s_counter_increment = cJSON_GetObjectItem(s_trigger_event, "counter_increment"); + + if (s_checked) + { + if (viewDetectionZone[0][iZoneIdx].jvc_behavior == 2 && + viewDetectionZone[0][iZoneIdx].jvc_enable_detect == 1) + { + viewDetectionZone[0][iZoneIdx].trigger_event[iEventIdx].checked = 1; + cJSON_ReplaceItemInObject(s_trigger_event, "checked", cJSON_CreateNumber(1)); + } + else + { + viewDetectionZone[0][iZoneIdx].trigger_event[iEventIdx].checked = 0; + cJSON_ReplaceItemInObject(s_trigger_event, "checked", cJSON_CreateNumber(0)); + } + } + } + } + } + iEventIdx++; + } + } + } + }//if (s_camera) + } + } + + + char* JsonString = cJSON_Print(s_root); + + //printf("write: \n\n %s \n\n\n\n", JsonString); +#if 1 + FILE *f = fopen(config_PATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + + //CopyFileTo(config_PATH, config_bakPATH); + //check_if_setfile_OK = 1; + //g_count_alter = 50; + } +#endif + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } //s_root + + } + //.metadata1 + set_metadata(); + +#endif + } + + + pthread_mutex_unlock(&mutex_config_json); +} \ No newline at end of file diff --git a/src/jvc_progress.h b/src/jvc_progress.h new file mode 100644 index 0000000..aa9bb65 --- /dev/null +++ b/src/jvc_progress.h @@ -0,0 +1,11 @@ +#pragma once +#ifndef JVC_PROGRESS_H +#define JVC_PROGRESS_H + +#include "utility.h" + +void jvc_setconfig(char *contentBuf); +void jvc_setMainSetting(); +void import_config(); + +#endif \ No newline at end of file diff --git a/src/k_means.c b/src/k_means.c new file mode 100644 index 0000000..79c5623 --- /dev/null +++ b/src/k_means.c @@ -0,0 +1,184 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include "k_means.h" + +// ------------------------------------ +// variable +double data[DCNT][DIM_SIZE] = { 0 }; /* l */ +double cent[DCNT][DIM_SIZE] = { 0 }; /* */ +double dis_k[K_NUM][DIM_SIZE] = { 0 }; /* OEZ */ +int table[DCNT] = { 0 }; /* ƩOE*/ +int cent_c[K_NUM] = { 0 }; /* OEƼ*/ + +// ------------------------------------ + +int g_real_data_number = 0; +int g_cen_adapter = 0; + +// main function +int mea_plate_kmeans(KmeansPoint *label_points, int point_num) +{ + int ch_pt; /* ܰʤI */ + int iter = 0; /* Npƾ */ + double sse1; /* W@Nsse */ + double sse2; /* Nsse */ + + srand((unsigned)time(NULL)); + get_data(label_points, point_num); /* step 0 - o */ + kmeans_init(point_num); /* step 1 - l,Ho */ + sse2 = update_table(&ch_pt); /* step 2 - s@ */ + do { + sse1 = sse2, ++iter; + update_cent(); /* step 3 - s */ + sse2 = update_table(&ch_pt); /* step 4 - s */ + } while (iter<MAX_ITER && sse1 != sse2 && ch_pt>MIN_PT); // ı + + //print_cent(); // ̫ܳ᭫ߦm + //printf("sse = %.2lf\n", sse2); + //printf("ch_pt = %d\n", ch_pt); + //printf("iter = %d\n", iter); + + for (int i = 0; i < point_num; i++) + { + //printf("table[%d] = %d \n", i, table[i]); + label_points[i].cluster_idx = table[i]; + } + + return 0; +} + +// ------------------------------------ +// pGIZ +double cal_dis(double *x, double *y, int dim) +{ + int i; + double t, sum = 0.0; + for (i = 0; i < dim; ++i) + t = x[i] - y[i], sum += t * t; + return sum; +} + +// ------------------------------------ +// oơABHH +void get_data(KmeansPoint *label_points, int point_num) +{ + //int i, j; + //for (i = 0; i < DCNT; ++i) + //for (j = 0; j < DIM_SIZE; ++j) + //data[i][j] = LOW_K + (double)rand()*(UP_K - LOW_K) / RAND_MAX; + + int i/*, j*/; + for (i = 0; i < point_num; i++) + { + data[i][0] = label_points[i].x; + //printf("%d, data = %f \n", i, data[i][0]); + + g_cen_adapter += label_points[i].w; + + if (i != 0) + g_cen_adapter /= 2; + } + + /* + data[0][0] = 0; + data[0][1] = 2.5; + data[0][2] = 3.5; + data[0][3] = 4.5; + data[0][4] = 5.5; + data[0][5] = 6.5; + data[0][6] = 7.5; + data[0][7] = 8.5; + */ +} +// ------------------------------------ +// tƪl +void kmeans_init(int point_num) +{ + int /*i, */j, k/*, rnd*/; + int pick[K_NUM] = { 0 }; + // HK ӤPI + /* + for (k = 0; k < K_NUM; ++k) { + rnd = rand() % DCNT; // H@ + for (i = 0; i < k && pick[i] != rnd; ++i); + if (i == k) pick[k] = rnd; // S + else --k; // , A@ + } + */ + + if (point_num != 0) + g_real_data_number = point_num; + else + g_real_data_number = DCNT; + + // 2I: P̥γ̥k + pick[0] = 0; + pick[1] = point_num - 1; + + + // NK ӸIeƨ쭫cent + for (k = 0; k < K_NUM; ++k) + { + for (j = 0; j < DIM_SIZE; ++j) + { + cent[k][j] = data[pick[k]][j] - g_cen_adapter; + + //printf("%d, %d, cent = %f \n", k, j, cent[k][j]); + } + } +} + +// ------------------------------------ +// stable, Ǧ^sse, sJIܰʼ +double update_table(int* ch_pt) +{ + int i, j, k, min_k; + double dis, min_dis, t_sse = 0.0; + + *ch_pt = 0; // ܰIƳ]0 + memset(cent_c, 0, sizeof(cent_c)); // UOEƼƲM0 + memset(dis_k, 0, sizeof(dis_k)); // UOEZMM0 + + for (i = 0; i < g_real_data_number; ++i) { + // Mݭ + min_dis = cal_dis(data[i], cent[0], DIM_SIZE); + min_k = 0; + for (k = 1; k < K_NUM; ++k) { + dis = cal_dis(data[i], cent[k], DIM_SIZE); + if (dis < min_dis) + min_dis = dis, min_k = k; + } + *ch_pt += (table[i] != min_k); // sܰI + table[i] = min_k; // sݭ + ++cent_c[min_k]; // ֭p߸Ƽ + t_sse += min_dis; // ֭p`߶Z + for (j = 0; j < DIM_SIZE; ++j) // sUOE`Z + dis_k[min_k][j] += data[i][j]; + } + return t_sse; +} + +// ------------------------------------ +// sߦm +void update_cent() +{ + int k, j; + for (k = 0; k < K_NUM; ++k) + for (j = 0; j < DIM_SIZE; ++j) + cent[k][j] = dis_k[k][j] / cent_c[k]; +} + +// ------------------------------------ +// ܭߦm +void print_cent() +{ + int j, k; + for (k = 0; k < K_NUM; ++k) { + for (j = 0; j < DIM_SIZE; ++j) + printf("%6.2lf ", cent[k][j]); + putchar('\n'); + } +} \ No newline at end of file diff --git a/src/k_means.h b/src/k_means.h new file mode 100644 index 0000000..c7369a1 --- /dev/null +++ b/src/k_means.h @@ -0,0 +1,33 @@ + +#pragma once +#ifndef K_MEANS_H +#define K_MEANS_H +// ------------------------------------ +// param define +#define DCNT 30 /* ƭӼ */ //->אּڦr +#define DIM_SIZE 1 /* ƺ */ //->ثeuѦx +#define K_NUM 2 /* OEӼ */ //->kⰼ +#define MAX_ITER 50 /* ̤jN */ //->HK +#define MIN_PT 5 /* ̤pܰI */ +//#define LOW_K 0 /* ƤU */ //->vjp(w) min +//#define UP_K 4000 /* ƤW */ //->vjp(w) max + +typedef struct +{ + int x; + int y; + int w; + int cluster_idx; +} KmeansPoint; + +int mea_plate_kmeans(KmeansPoint *label_points, int point_num); +// ------------------------------------ +// function declare +double cal_dis(double *x, double *y, int dim); +void get_data(KmeansPoint *label_points, int point_num); // o +void kmeans_init(int point_num); // tkl +double update_table(int* ch_pt); // stable +void update_cent(); // sߦm +void print_cent(); // ܭߦm + +#endif \ No newline at end of file diff --git a/src/l2norm_layer.c b/src/l2norm_layer.c new file mode 100644 index 0000000..d099479 --- /dev/null +++ b/src/l2norm_layer.c @@ -0,0 +1,63 @@ +#include "l2norm_layer.h" +#include "activations.h" +#include "blas.h" +#include "cuda.h" + +#include <float.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> + +layer make_l2norm_layer(int batch, int inputs) +{ + fprintf(stderr, "l2norm %4d\n", inputs); + layer l = {0}; + l.type = L2NORM; + l.batch = batch; + l.inputs = inputs; + l.outputs = inputs; + l.output = calloc(inputs*batch, sizeof(float)); + l.scales = calloc(inputs*batch, sizeof(float)); + l.delta = calloc(inputs*batch, sizeof(float)); + + l.forward = forward_l2norm_layer; + l.backward = backward_l2norm_layer; + #ifdef GPU + l.forward_gpu = forward_l2norm_layer_gpu; + l.backward_gpu = backward_l2norm_layer_gpu; + + l.output_gpu = cuda_make_array(l.output, inputs*batch); + l.scales_gpu = cuda_make_array(l.output, inputs*batch); + l.delta_gpu = cuda_make_array(l.delta, inputs*batch); + #endif + return l; +} + +void forward_l2norm_layer(const layer l, network net) +{ + copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); + l2normalize_cpu(l.output, l.scales, l.batch, l.out_c, l.out_w*l.out_h); +} + +void backward_l2norm_layer(const layer l, network net) +{ + //axpy_cpu(l.inputs*l.batch, 1, l.scales, 1, l.delta, 1); + axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void forward_l2norm_layer_gpu(const layer l, network net) +{ + copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1); + l2normalize_gpu(l.output_gpu, l.scales_gpu, l.batch, l.out_c, l.out_w*l.out_h); +} + +void backward_l2norm_layer_gpu(const layer l, network net) +{ + axpy_gpu(l.batch*l.inputs, 1, l.scales_gpu, 1, l.delta_gpu, 1); + axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1); +} + +#endif diff --git a/src/l2norm_layer.h b/src/l2norm_layer.h new file mode 100644 index 0000000..17e7f1a --- /dev/null +++ b/src/l2norm_layer.h @@ -0,0 +1,17 @@ +#pragma once +#ifndef L2NORM_LAYER_H +#define L2NORM_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" + +layer make_l2norm_layer(int batch, int inputs); +void forward_l2norm_layer(const layer l, network net); +void backward_l2norm_layer(const layer l, network net); + +#ifdef GPU +void forward_l2norm_layer_gpu(const layer l, network net); +void backward_l2norm_layer_gpu(const layer l, network net); +#endif + +#endif diff --git a/src/layer.c b/src/layer.c new file mode 100644 index 0000000..c27b477 --- /dev/null +++ b/src/layer.c @@ -0,0 +1,97 @@ +#include "layer.h" +#include "cuda.h" + +#include <stdlib.h> + +void free_layer(layer l) +{ + if(l.type == DROPOUT){ + if(l.rand) free(l.rand); +#ifdef GPU + if(l.rand_gpu) cuda_free(l.rand_gpu); +#endif + return; + } + if(l.cweights) free(l.cweights); + if(l.indexes) free(l.indexes); + if(l.input_layers) free(l.input_layers); + if(l.input_sizes) free(l.input_sizes); + if(l.map) free(l.map); + if(l.rand) free(l.rand); + if(l.cost) free(l.cost); + if(l.state) free(l.state); + if(l.prev_state) free(l.prev_state); + if(l.forgot_state) free(l.forgot_state); + if(l.forgot_delta) free(l.forgot_delta); + if(l.state_delta) free(l.state_delta); + if(l.concat) free(l.concat); + if(l.concat_delta) free(l.concat_delta); + if(l.binary_weights) free(l.binary_weights); + if(l.biases) free(l.biases); + if(l.bias_updates) free(l.bias_updates); + if(l.scales) free(l.scales); + if(l.scale_updates) free(l.scale_updates); + if(l.weights) free(l.weights); + if(l.weight_updates) free(l.weight_updates); + if(l.delta) free(l.delta); + if(l.output) free(l.output); + if(l.squared) free(l.squared); + if(l.norms) free(l.norms); + if(l.spatial_mean) free(l.spatial_mean); + if(l.mean) free(l.mean); + if(l.variance) free(l.variance); + if(l.mean_delta) free(l.mean_delta); + if(l.variance_delta) free(l.variance_delta); + if(l.rolling_mean) free(l.rolling_mean); + if(l.rolling_variance) free(l.rolling_variance); + if(l.x) free(l.x); + if(l.x_norm) free(l.x_norm); + if(l.m) free(l.m); + if(l.v) free(l.v); + if(l.z_cpu) free(l.z_cpu); + if(l.r_cpu) free(l.r_cpu); + if(l.h_cpu) free(l.h_cpu); + if(l.binary_input) free(l.binary_input); + +#ifdef GPU + if(l.indexes_gpu) cuda_free((float *)l.indexes_gpu); + + if(l.z_gpu) cuda_free(l.z_gpu); + if(l.r_gpu) cuda_free(l.r_gpu); + if(l.h_gpu) cuda_free(l.h_gpu); + if(l.m_gpu) cuda_free(l.m_gpu); + if(l.v_gpu) cuda_free(l.v_gpu); + if(l.prev_state_gpu) cuda_free(l.prev_state_gpu); + if(l.forgot_state_gpu) cuda_free(l.forgot_state_gpu); + if(l.forgot_delta_gpu) cuda_free(l.forgot_delta_gpu); + if(l.state_gpu) cuda_free(l.state_gpu); + if(l.state_delta_gpu) cuda_free(l.state_delta_gpu); + if(l.gate_gpu) cuda_free(l.gate_gpu); + if(l.gate_delta_gpu) cuda_free(l.gate_delta_gpu); + if(l.save_gpu) cuda_free(l.save_gpu); + if(l.save_delta_gpu) cuda_free(l.save_delta_gpu); + if(l.concat_gpu) cuda_free(l.concat_gpu); + if(l.concat_delta_gpu) cuda_free(l.concat_delta_gpu); + if(l.binary_input_gpu) cuda_free(l.binary_input_gpu); + if(l.binary_weights_gpu) cuda_free(l.binary_weights_gpu); + if(l.mean_gpu) cuda_free(l.mean_gpu); + if(l.variance_gpu) cuda_free(l.variance_gpu); + if(l.rolling_mean_gpu) cuda_free(l.rolling_mean_gpu); + if(l.rolling_variance_gpu) cuda_free(l.rolling_variance_gpu); + if(l.variance_delta_gpu) cuda_free(l.variance_delta_gpu); + if(l.mean_delta_gpu) cuda_free(l.mean_delta_gpu); + if(l.x_gpu) cuda_free(l.x_gpu); + if(l.x_norm_gpu) cuda_free(l.x_norm_gpu); + if(l.weights_gpu) cuda_free(l.weights_gpu); + if(l.weight_updates_gpu) cuda_free(l.weight_updates_gpu); + if(l.biases_gpu) cuda_free(l.biases_gpu); + if(l.bias_updates_gpu) cuda_free(l.bias_updates_gpu); + if(l.scales_gpu) cuda_free(l.scales_gpu); + if(l.scale_updates_gpu) cuda_free(l.scale_updates_gpu); + if(l.output_gpu) cuda_free(l.output_gpu); + if(l.delta_gpu) cuda_free(l.delta_gpu); + if(l.rand_gpu) cuda_free(l.rand_gpu); + if(l.squared_gpu) cuda_free(l.squared_gpu); + if(l.norms_gpu) cuda_free(l.norms_gpu); +#endif +} diff --git a/src/layer.h b/src/layer.h new file mode 100644 index 0000000..11edd0e --- /dev/null +++ b/src/layer.h @@ -0,0 +1,408 @@ +#pragma once +#ifndef BASE_LAYER_H +#define BASE_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "tree.h" + +struct network_state; + +struct network; +typedef struct network network; + +struct layer; +typedef struct layer layer; + +typedef enum { + CONVOLUTIONAL, + DECONVOLUTIONAL, + CONNECTED, + MAXPOOL, + SOFTMAX, + DETECTION, + DROPOUT, + CROP, + ROUTE, + COST, + NORMALIZATION, + AVGPOOL, + LOCAL, + SHORTCUT, + ACTIVE, + RNN, + GRU, + LSTM, + CRNN, + BATCHNORM, + NETWORK, + XNOR, + REGION, + YOLO, + ISEG, + REORG, + UPSAMPLE, + LOGXENT, + L2NORM, + REORG_OLD, + BLANK +} LAYER_TYPE; + +typedef enum { + SSE, MASKED, L1, SEG, SMOOTH, WGAN +} COST_TYPE; + +typedef struct { + int batch; + float learning_rate; + float momentum; + float decay; + int adam; + float B1; + float B2; + float eps; + int t; +} update_args; + +struct layer { + LAYER_TYPE type; + ACTIVATION activation; + COST_TYPE cost_type; + void(*forward) (struct layer, struct network); + void(*backward) (struct layer, struct network); + void(*update) (struct layer, update_args); + void(*forward_gpu) (struct layer, struct network); + void(*backward_gpu) (struct layer, struct network); + void(*update_gpu) (struct layer, update_args); + int batch_normalize; + int shortcut; + int batch; + int forced; + int flipped; + int inputs; + int outputs; + int nweights; + int nbiases; + int extra; + int truths; + int h, w, c; + int out_h, out_w, out_c; + int n; + int max_boxes; + int groups; + int size; + int side; + int stride; + int reverse; + int flatten; + int spatial; + int pad; + int sqrt; + int flip; + int index; + int binary; + int xnor; + int use_bin_output; + int steps; + int hidden; + int truth; + float smooth; + float dot; + float angle; + float jitter; + float saturation; + float exposure; + float shift; + float ratio; + int focal_loss; + float learning_rate_scale; + float clip; + int noloss; + int softmax; + int classes; + int coords; + int background; + int rescore; + int objectness; + int joint; + int noadjust; + int reorg; + int log; + int tanh; + int *mask; + int total; + float bflops; + + int adam; + float B1; + float B2; + float eps; + float *m_gpu; + float *v_gpu; + int t; + float *m; + //float *v; + + //tree *softmax_tree; + + float alpha; + float beta; + float kappa; + + float coord_scale; + float object_scale; + float noobject_scale; + float mask_scale; + float class_scale; + int bias_match; + int random; + float ignore_thresh; + float truth_thresh; + float thresh; + float focus; + int classfix; + int absolute; + + int onlyforward; + int stopbackward; + int dontload; + int dontsave; + int dontloadscales; + int numload; + + float temperature; + float probability; + float scale; + + char * cweights; + int * indexes; + int * input_layers; + int * input_sizes; + int * map; + int * counts; + float ** sums; + float * rand; + float * cost; + float * state; + float * prev_state; + float * forgot_state; + float * forgot_delta; + float * state_delta; + float * combine_cpu; + float * combine_delta_cpu; + + float * concat; + float * concat_delta; + + float * binary_weights; + + float * biases; + float * bias_updates; + + float * scales; + float * scale_updates; + + float * weights; + float * weight_updates; + + char *align_bit_weights_gpu; + float *mean_arr_gpu; + float *align_workspace_gpu; + float *transposed_align_workspace_gpu; + int align_workspace_size; + + char *align_bit_weights; + float *mean_arr; + int align_bit_weights_size; + int lda_align; + int new_lda; + int bit_align; + + float *col_image; + + float * delta; + float * output; + float * loss; + float * squared; + float * norms; + + float * spatial_mean; + float * mean; + float * variance; + + float * mean_delta; + float * variance_delta; + + float * rolling_mean; + float * rolling_variance; + + float * x; + float * x_norm; + + //float * m; + float * v; + + float * bias_m; + float * bias_v; + float * scale_m; + float * scale_v; + + + float *z_cpu; + float *r_cpu; + float *h_cpu; + float * prev_state_cpu; + + float *temp_cpu; + float *temp2_cpu; + float *temp3_cpu; + + float *dh_cpu; + float *hh_cpu; + float *prev_cell_cpu; + float *cell_cpu; + float *f_cpu; + float *i_cpu; + float *g_cpu; + float *o_cpu; + float *c_cpu; + float *dc_cpu; + + float * binary_input; + + struct layer *input_layer; + struct layer *self_layer; + struct layer *output_layer; + + struct layer *reset_layer; + struct layer *update_layer; + struct layer *state_layer; + + struct layer *input_gate_layer; + struct layer *state_gate_layer; + struct layer *input_save_layer; + struct layer *state_save_layer; + struct layer *input_state_layer; + struct layer *state_state_layer; + + struct layer *input_z_layer; + struct layer *state_z_layer; + + struct layer *input_r_layer; + struct layer *state_r_layer; + + struct layer *input_h_layer; + struct layer *state_h_layer; + + struct layer *wz; + struct layer *uz; + struct layer *wr; + struct layer *ur; + struct layer *wh; + struct layer *uh; + struct layer *uo; + struct layer *wo; + struct layer *uf; + struct layer *wf; + struct layer *ui; + struct layer *wi; + struct layer *ug; + struct layer *wg; + + tree *softmax_tree; + + size_t workspace_size; + +#ifdef GPU + int *indexes_gpu; + + float *z_gpu; + float *r_gpu; + float *h_gpu; + + float *temp_gpu; + float *temp2_gpu; + float *temp3_gpu; + + float *dh_gpu; + float *hh_gpu; + float *prev_cell_gpu; + float *cell_gpu; + float *f_gpu; + float *i_gpu; + float *g_gpu; + float *o_gpu; + float *c_gpu; + float *dc_gpu; + + float *m_gpu; + float *v_gpu; + float *bias_m_gpu; + float *scale_m_gpu; + float *bias_v_gpu; + float *scale_v_gpu; + + float * combine_gpu; + float * combine_delta_gpu; + + float * prev_state_gpu; + float * forgot_state_gpu; + float * forgot_delta_gpu; + float * state_gpu; + float * state_delta_gpu; + float * gate_gpu; + float * gate_delta_gpu; + float * save_gpu; + float * save_delta_gpu; + float * concat_gpu; + float * concat_delta_gpu; + + float * binary_input_gpu; + float * binary_weights_gpu; + + float * mean_gpu; + float * variance_gpu; + + float * rolling_mean_gpu; + float * rolling_variance_gpu; + + float * variance_delta_gpu; + float * mean_delta_gpu; + + float * x_gpu; + float * x_norm_gpu; + float * weights_gpu; + float * weight_updates_gpu; + float * weight_change_gpu; + + float * biases_gpu; + float * bias_updates_gpu; + float * bias_change_gpu; + + float * scales_gpu; + float * scale_updates_gpu; + float * scale_change_gpu; + + float * output_gpu; + float * loss_gpu; + float * delta_gpu; + float * rand_gpu; + float * squared_gpu; + float * norms_gpu; +#ifdef CUDNN + cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc; + cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc; + cudnnTensorDescriptor_t normTensorDesc; + cudnnFilterDescriptor_t weightDesc; + cudnnFilterDescriptor_t dweightDesc; + cudnnConvolutionDescriptor_t convDesc; + cudnnConvolutionFwdAlgo_t fw_algo; + cudnnConvolutionBwdDataAlgo_t bd_algo; + cudnnConvolutionBwdFilterAlgo_t bf_algo; +#endif +#endif +}; + + +void free_layer(layer); + +#endif \ No newline at end of file diff --git a/src/levenshtein.c b/src/levenshtein.c new file mode 100644 index 0000000..e0c7490 --- /dev/null +++ b/src/levenshtein.c @@ -0,0 +1,79 @@ + +#include "levenshtein.h" + +int minimum3(int a, int b, int c) { + int min = a; + if (b < min) min = b; + if (c < min) min = c; + return min; +} + +int LevenshteinDistance(char *s, char *t, int max_distance) { + int rtn_bool = 0; + +#if 1 + //Step 1 + if (s && t) { + int n = strlen(s); + int m = strlen(t); + if ((n == 0) || (m == 0) || abs(n - m) > max_distance) { + rtn_bool = 0; + } + else { + + if (max_distance == 0) { + if (strcmp(s, t) == 0) { + rtn_bool = 1; + } + else { + rtn_bool = 0; + } + } + else { + int d[16384] = { 0 };//128*128 + m++; + n++; + + //Step 2 + int k; + for (k = 0; k < n; k++) d[k] = k; + for (k = 0; k < m; k++) d[k*n] = k; + + //Step 3 and 4 + int i, j; + for (i = 1; i < n; i++) { + for (j = 1; j < m; j++) { + int cost; + + //Step 5 + //cost = s[i-1] != t[j-1]; + if (s[i - 1] == t[j - 1]) { + cost = 0; + } + else { + cost = 1; + } + + //Step 6 + d[j*n + i] = minimum3(d[(j - 1)*n + i] + 1, d[j*n + i - 1] + 1, d[(j - 1)*n + i - 1] + cost); + } + } + int distance = d[n*m - 1]; + + if (distance <= max_distance) { + rtn_bool = 1; + } + else { + rtn_bool = 0; + } + } + } + } + else { + rtn_bool = 0; + } +#endif + return rtn_bool; +} + + diff --git a/src/levenshtein.h b/src/levenshtein.h new file mode 100644 index 0000000..86d4aad --- /dev/null +++ b/src/levenshtein.h @@ -0,0 +1,14 @@ +#pragma once +#ifndef LEVENSHTEIN_DISTANCE_H +#define LEVENSHTEIN_DISTANCE_H +#include "define_inc.h" +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <ctype.h> + +int minimum3(int a, int b, int c); + +int LevenshteinDistance(char *s, char *t, int max_distance); + +#endif \ No newline at end of file diff --git a/src/levenshtein_sqlite.c b/src/levenshtein_sqlite.c new file mode 100644 index 0000000..ad7703f --- /dev/null +++ b/src/levenshtein_sqlite.c @@ -0,0 +1,100 @@ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <ctype.h> +#include "levenshtein_sqlite.h" + + +/* + function to determine levenshtein distance + levenshtein(src,dts,max_distance) => bool +*/ + +void levenshteinFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +) { + if (argc == 3) { + if (argv[0] && argv[1] && argv[2]) { + + const char *s = (const char *)sqlite3_value_text(argv[0]); + const char *t = (const char *)sqlite3_value_text(argv[1]); + + if (s && t) { + + int max_distance = sqlite3_value_int(argv[2]); + + //Step 1 + int n = strlen(s); + int m = strlen(t); + if ((n == 0) || (m == 0) || abs(n - m) > max_distance) { + sqlite3_result_int(context, 0); + } + else { + int d[16384] = { 0 };//128*128 + m++; + n++; + + //Step 2 + int k; + for (k = 0; k < n; k++) d[k] = k; + for (k = 0; k < m; k++) d[k*n] = k; + + //Step 3 and 4 + int i, j; + for (i = 1; i < n; i++) { + for (j = 1; j < m; j++) { + int cost; + + //Step 5 + //cost = s[i-1] != t[j-1]; + if (s[i - 1] == t[j - 1]) { + cost = 0; + } + else { + cost = 1; + } + + //Step 6 + d[j*n + i] = minimum(d[(j - 1)*n + i] + 1, d[j*n + i - 1] + 1, d[(j - 1)*n + i - 1] + cost); + } + } + int distance = d[n*m - 1]; + sqlite3_result_int(context, distance <= max_distance); + } + } + else { + sqlite3_result_int(context, 0); + } + } + else { + sqlite3_result_int(context, 0); + } + } + else { + sqlite3_result_int(context, 0); + } +} + + +int minimum(int a, int b, int c) { + int min = a; + if (b < min) min = b; + if (c < min) min = c; + return min; +} + +/* SQLite invokes this routine once when it loads the extension. +** Create new functions, collating sequences, and virtual table +** modules here. This is usually the only exported symbol in +** the shared library. +*/ +int sqlite3_extension_init( + sqlite3 *db +) { + sqlite3_create_function(db, "levenshtein", 3, SQLITE_UTF8, NULL, &levenshteinFunc, NULL, NULL); + + return 0; +} \ No newline at end of file diff --git a/src/levenshtein_sqlite.h b/src/levenshtein_sqlite.h new file mode 100644 index 0000000..8597905 --- /dev/null +++ b/src/levenshtein_sqlite.h @@ -0,0 +1,20 @@ +#pragma once +#ifndef LEVENSHTEIN_SQLITE_H +#define LEVENSHTEIN_SQLITE_H +#include "define_inc.h" +#include "sqlite3.h" + +int sqlite3_extension_init( + sqlite3 *db +); + +// helpers +int minimum(int a, int b, int c); + +void levenshteinFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +); + +#endif \ No newline at end of file diff --git a/src/lib_data_process.c b/src/lib_data_process.c new file mode 100644 index 0000000..27f2f5e --- /dev/null +++ b/src/lib_data_process.c @@ -0,0 +1,199 @@ +/******************************************************************************* + * lib_data_process.c + * + * History: + * 2017/07/25 - [Hao Qian] created file + * + * Copyright (c) 2017 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "lib_data_process_priv.h" +#include "amba_ssd_detection_out.h" +#include "amba_yolov3_out.h" +#include "test_nnctrl_live.h" + + +dproc_context_t dproc_ctx[MAX_NET_NUM]; + +AMBA_API int dproc_init(dproc_config_t *config, int dproc_ctx_id) +{ + int rval = 0; + + do { + if (config == NULL) { + printf("dproc_config_t is NULL!\n"); + rval = -1; + break; + } + + switch (config->layer_type) { + case DPROC_SSD_DETECTION_OUT: + if (dproc_ctx[dproc_ctx_id].ssd_detection_output.init_flag == 1) { + printf("dproc SSD is inited, please run deinit() first!\n"); + rval = -1; + break; + } +#ifdef GY_OS_AMBA + rval = amba_ssd_detection_output_init(&(dproc_ctx[dproc_ctx_id].ssd_detection_output), + &(config->arg.ssd_config)); +#endif //GY_OS_AMBA + if (rval < 0) { + printf("Failt to init dproc SSD!\n"); + rval = -1; + } else { + dproc_ctx[dproc_ctx_id].ssd_detection_output.init_flag = 1; + } + break; + case DPROC_YOLOV3_OUT: + //printf("dproc init [%d] \n", dproc_ctx_id); + if (dproc_ctx[dproc_ctx_id].yolov3_output.init_flag == 1) { + printf("dproc yolov3 [%d] is inited, please run deinit() first!\n", dproc_ctx_id); + rval = -1; + break; + } +#ifdef GY_OS_AMBA + rval = amba_yolov3_output_init(&(dproc_ctx[dproc_ctx_id].yolov3_output), + &(config->arg.yolov3_config)); +#endif //GY_OS_AMBA + if (rval < 0) { + printf("Failt to init [%d] dproc yolov3!\n", dproc_ctx_id); + rval = -1; + } else { + dproc_ctx[dproc_ctx_id].yolov3_output.init_flag = 1; + } + break; + + default: + printf("Error layer type when init!\n"); + rval = -1; + break; + } + } while (0); + + return rval; +} + +AMBA_API int dproc_run(dproc_run_param_t *run_param, dproc_result_t *result, int dproc_ctx_id, float nms_threshold) +{ + int rval = 0; + + do { + if (result == NULL) { + printf("dproc_result_t is NULL!\n"); + rval = -1; + break; + } + + switch (run_param->layer_type) { + case DPROC_SSD_DETECTION_OUT: + if (dproc_ctx[dproc_ctx_id].ssd_detection_output.init_flag != 1) { + printf("Please init this dproc SSD output layer first!\n"); + rval = -1; + break; + } +#ifdef GY_OS_AMBA + rval = amba_ssd_detection_output_run(&(dproc_ctx[dproc_ctx_id].ssd_detection_output), + &(run_param->arg.ssd_param), result->arg.ssd_result, result->arg_debug.ssd_debug_info); +#endif + break; + case DPROC_YOLOV3_OUT: + if (dproc_ctx[dproc_ctx_id].yolov3_output.init_flag != 1) { + printf("Please init this dproc Yolov3 output layer first!\n"); + rval = -1; + break; + } +#ifdef GY_OS_AMBA + rval = amba_yolov3_output_run(&(dproc_ctx[dproc_ctx_id].yolov3_output), + &(run_param->arg.yolov3_param), result->arg.yolov3_result, nms_threshold); +#endif //GY_OS_AMBA + break; + + default: + printf("Error layer type when run!\n"); + rval = -1; + break; + } + } while (0); + + return rval; +} + +AMBA_API int dproc_deinit(enum dproc_layer_type layer_type, int dproc_ctx_id) +{ + int rval = 0; + + do { + switch (layer_type) { + case DPROC_SSD_DETECTION_OUT: + if (dproc_ctx[dproc_ctx_id].ssd_detection_output.init_flag != 1) { + printf("Please init this dproc SSD output layer first!\n"); + rval = -1; + break; + } +#ifdef GY_OS_AMBA + rval = amba_ssd_detection_output_deinit(&(dproc_ctx[dproc_ctx_id].ssd_detection_output)); +#endif //GY_OS_AMBA + if (rval < 0) { + printf("Failt to deinit dproc SSD!\n"); + rval = -1; + } else { + dproc_ctx[dproc_ctx_id].ssd_detection_output.init_flag = 0; + } + break; + case DPROC_YOLOV3_OUT: + if (dproc_ctx[dproc_ctx_id].yolov3_output.init_flag != 1) { + printf("Please init this dproc Yolov3 output layer first!\n"); + rval = -1; + break; + } +#ifdef GY_OS_AMBA + rval = amba_yolov3_output_deinit(&(dproc_ctx[dproc_ctx_id].yolov3_output)); +#endif //GY_OS_AMBA + if (rval < 0) { + printf("Failt to init dproc yolov3!\n"); + rval = -1; + } else { + dproc_ctx[dproc_ctx_id].yolov3_output.init_flag = 0; + } + break; + + default: + printf("Error layer type when deinit!\n"); + rval = -1; + break; + } + } while (0); + + return rval; +} diff --git a/src/lib_data_process.h b/src/lib_data_process.h new file mode 100644 index 0000000..f55e7a3 --- /dev/null +++ b/src/lib_data_process.h @@ -0,0 +1,351 @@ +/******************************************************************************* + * @file lib_data_process.h + * @brief This file shows the dproc library API. + * + * History: + * 2018/10/23 - [Hao Qian] created file + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ +#pragma once +#ifndef _DPROC_LIB_H +#define _DPROC_LIB_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" +#include <stdint.h> + +#define AMBA_API __attribute__((visibility("default"))) + +/*! + * @addtogroup dproc-helper + * @{ + */ + +/*! + * @brief Define the layer type of dproc. + */ +enum dproc_layer_type { + DPROC_SSD_DETECTION_OUT = 0, /*!< for SSD */ + DPROC_YOLOV3_OUT = 1, /*!< for YOLOV3 or TINY_YOLOV3 */ + DPROC_TYPE_NUM, +}; + + +/*************** Share Structure ***************/ +/*! + * @brief Description of the parameters of the bounding box. + */ +typedef struct dproc_bbox_param_s { + float x_min; /*!< X-coordinate of starting point */ + float y_min; /*!< Y-coordinate of starting point */ + float x_max; /*!< X-coordinate of end point */ + float y_max; /*!< Y-coordinate of end point */ +} dproc_bbox_param_t; +/*************** Share Structure ***************/ + + +/*************** SSD detection_out ***************/ +/*! + * @brief Some debugging information for SSD. + */ +typedef struct dproc_ssd_class_dbg_info_s { + int num_bboxes_above_threshold; /*!< The number of bbox that exceed the threshold */ + int num_bboxes_post_nms; /*!< The number of bbox returned by nms() */ +} dproc_ssd_class_dbg_info_t; + +/*! + * @brief Description of the coordinate type of the bounding box. + */ +typedef enum amba_bbox_codetype_s { + AMBA_BBOX_CORNER = 0, + AMBA_BBOX_CENTER_SIZE = 1, /*!< The coordinate type of the bbox is CENTER */ + AMBA_BBOX_CORNER_SIZE = 2, /*!< The coordinate type of the bbox is CORNER */ + AMBA_BBOX_NUM_CODETYPE, +} amba_bbox_codetype_t; + +/*************** TF SSD Scale ***************/ +/*! + * @brief Description of the scale factors of SSD for TF. + */ +typedef struct ssd_tf_scale_factors_s { + uint32_t center_x_scale; /*!< The scale value of X-coordinate for the center point of bbox */ + uint32_t center_y_scale; /*!< The scale value of Y-coordinate for the center point of bbox */ + uint32_t width_scale; /*!< The scale value of the width of bbox */ + uint32_t height_scale; /*!< The scale value of the height of bbox */ +} ssd_tf_scale_factors_t; +/*************** TF SSD Scale ***************/ + +/*! + * @brief Description of the configuration of SSD detection output. + */ +typedef struct dproc_ssd_detection_output_config_s { + /* basic related */ + uint16_t img_width; /*!< the width of output image */ + uint16_t img_height; /*!< the height of output image */ + uint32_t num_classes; /*!< the number of classes */ + uint32_t background_label_id; /*!< the label id of background */ + uint32_t mbox_loc_num_elements; /*!< Number of all elements */ + uint32_t num_all_bboxes; /*!< Number of all bboxes */ + + /* detection related */ + float conf_threshold; /*!< the threshold for filter_bboxes */ + uint32_t keep_top_k; /*!< Keep the maximum number of objects */ + + /* nms related */ + float nms_threshold; /*!< the threshold for nms */ + uint32_t nms_top_k; /*!< keep the maximum number of objects by nms*/ + + /* bounding box related */ + /*! + * refer to struct @ref amba_bbox_codetype_s, SSD supports CENTER_SIZE + */ + amba_bbox_codetype_t code_type; + uint32_t share_location : 1; /*!< only supports True */ + uint32_t unnormalized : 1; /*!< whether the parameter is unnormalized */ + uint32_t reserved : 30; + + /* TF Related */ + /*! + * refer to struct @ref ssd_tf_scale_factors_s. + */ + ssd_tf_scale_factors_t scale_factors; + +} dproc_ssd_detection_output_config_t; + +/*! + * @brief Output parameters after running SSD. + */ +typedef struct dproc_run_ssd_detection_output_param_s { + uint8_t *mbox_loc; /*!< output from cavalry */ + uint8_t *mbox_conf_flatten; /*!< output from cavalry */ + + /*! + * Binary which is generated by CV offline tool. + */ + float *mbox_priorbox; +} dproc_run_ssd_detection_output_param_t; + +/*! + * @brief Description of the result of SSD detection output. + */ +typedef struct dproc_ssd_detection_output_result_s { + int label; /*!< label id */ + float score; /*!< score */ + + dproc_bbox_param_t bbox; /*!< refer to struct @ref dproc_bbox_param_s. */ +} dproc_ssd_detection_output_result_t; +/*************** SSD detection_out ***************/ + + +/*************** Yolov3 yolo layer ***************/ +/*! + * @brief The number of anchor for TINY_YOLOV3. It is a constant. + */ +#define TINY_YOLOV3_ANCHOR_NUM 12 + +/*! + * @brief The number of anchor for YOLOV3. It is a constant. + */ +#define YOLOV3_ANCHOR_NUM 18 + +/*! + * @brief The number of feature map for YOLOV3 or TINY_YOLOV3. + */ +typedef enum amba_yolov3_feature_type_s { + AMBA_YOLOV3_FEATURE_MAP_32 = 0, + AMBA_YOLOV3_FEATURE_MAP_16 = 1, + AMBA_YOLOV3_FEATURE_MAP_8 = 2, /*!< For TINY_YOLOV3 */ + AMBA_YOLOV3_FEATURE_NUM = 3, /*!< For YOLOV3 */ +} amba_yolov3_feature_type_t; + +/*! + * @brief Description of the configuration of YOLOV3 detection output. + */ +typedef struct dproc_yolov3_output_config_s { + /* basic related */ + uint16_t img_width; /*!< the width of output image */ + uint16_t img_height; /*!< the height of output image */ + uint32_t num_classes; /*!< the number of classes */ + + /* detection and nms threshold */ + float conf_threshold; /*!< the threshold for yolov3_layer */ + float nms_threshold; /*!< the threshold for nms */ + + /* anchors */ + float *anchors; /*!< Address of the storage anchor */ + + /* others */ + uint32_t tiny_enable : 1; /*!< default is full yolov3, use this to enable tiny_yolov3 */ + uint32_t unnormalized : 1; /*!< whether the parameter is unnormalized */ + uint32_t padding_disable : 1; /*!< whether padding is disabled */ + uint32_t reserved : 29; + +} dproc_yolov3_output_config_t; + +/*! + * @brief Description of the parameters of YOLOV3 output. + */ +typedef struct dproc_run_yolov3_output_param_s { + /*! + * Output from cavalry. + * YOLOV3 use 3 feature maps, TINY_YOLOV3 only use 2 feature maps. + */ + float *feature_map[AMBA_YOLOV3_FEATURE_NUM]; +} dproc_run_yolov3_output_param_t; + +/*! + * @brief Description of the parameters of YOLOV3 output result. + */ +typedef struct dproc_yolov3_output_result_s { + uint32_t valid : 1; + uint32_t reserved : 31; + int label; + float score; + + dproc_bbox_param_t bbox; /*!< refer to struct @ref dproc_bbox_param_s. */ +} dproc_yolov3_output_result_t; +/*************** Yolov3 yolo layer ***************/ + + +/*! + * @brief Description of the configuration of dproc. + */ +typedef struct dproc_config_s { + enum dproc_layer_type layer_type; /*!< refer to enum @ref dproc_layer_type. */ + + union { + /*! + * refer to struct @ref dproc_ssd_detection_output_config_s. + */ + dproc_ssd_detection_output_config_t ssd_config; + /*! + * refer to struct @ref dproc_yolov3_output_config_s. + */ + dproc_yolov3_output_config_t yolov3_config; + } arg; +} dproc_config_t; + +/*! + * @brief Description of the running parameters of dproc. + */ +typedef struct dproc_run_param_s { + enum dproc_layer_type layer_type; /*!< refer to enum @ref dproc_layer_type */ + + union { + /*! + * refer to struct @ref dproc_run_ssd_detection_output_param_s. + */ + dproc_run_ssd_detection_output_param_t ssd_param; + /*! + * refer to struct @ref dproc_run_yolov3_output_param_s. + */ + dproc_run_yolov3_output_param_t yolov3_param; + } arg; +} dproc_run_param_t; + +/*! + * @brief Describe the results after running dproc. + */ +typedef struct dproc_result_s { + union { + /*! + * refer to struct @ref dproc_ssd_detection_output_result_s. + */ + dproc_ssd_detection_output_result_t *ssd_result; + /*! + * refer to struct @ref dproc_yolov3_output_result_s. + */ + dproc_yolov3_output_result_t *yolov3_result; + } arg; + + union { + /*! + * refer to struct @ref dproc_ssd_class_dbg_info_s. + */ + dproc_ssd_class_dbg_info_t *ssd_debug_info; + } arg_debug; +} dproc_result_t; + +/*! @} */ + + +/*! + * @addtogroup dproc-api + * @{ + */ + +/*! + * This API initializes control parameters for dproc. + * Call it before running the library. + * + * @param config The required configuration for dproc initialization. + * <br> User can refer to struct @ref dproc_config_s. + * @return 0: success; -1: error. + */ +AMBA_API int dproc_init(dproc_config_t *config, int dproc_ctx_id); + +/*! + * This API performs corresponding data processing on the output data + * of different network models. The currently supported models are + * SSD, YOLOV3, TINY_YOLOV3. + * Call this API after initialization. + * + * @param run_param The running parameters for dproc. + * <br> User can refer to struct @ref dproc_run_param_s. + * + * @param result The results after running dproc. + * <br> User can refer to struct @ref dproc_result_s. + * + * @return 0: success; -1: error. + */ +AMBA_API int dproc_run(dproc_run_param_t *run_param, dproc_result_t *result, int dproc_ctx_id, float nms_threshold); + +/*! + * This API is used to release the library session. + * Call this API at the very end. + * + * @param layer_type The layer type of dproc. + * <br> User can refer to enum @ref dproc_layer_type. + * + * @return 0: success; -1: error. + */ +AMBA_API int dproc_deinit(enum dproc_layer_type layer_type, int dproc_ctx_id); + +/*! @} */ + +#ifdef __cplusplus +} +#endif + +#endif //_DPROC_LIB_H + diff --git a/src/lib_data_process_priv.h b/src/lib_data_process_priv.h new file mode 100644 index 0000000..106e0b1 --- /dev/null +++ b/src/lib_data_process_priv.h @@ -0,0 +1,71 @@ +/******************************************************************************* + * lib_data_process_priv.h + * + * History: + * 2018/10/24 - [Hao Qian] created file + * + * Copyright (c) 2018 Ambarella International LP + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella International LP and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella International LP or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella International LP. + * + * This file includes sample code and is only for internal testing and evaluation. If you + * distribute this sample code (whether in source, object, or binary code form), it will be + * without any warranty or indemnity protection from Ambarella International LP or its affiliates. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ +#pragma once +#ifndef _DPROC_LIB_PRIV_H +#define _DPROC_LIB_PRIV_H +#include "define_inc.h" +#include "lib_data_process.h" +#include "amba_bbox_utils.h" + +typedef struct dproc_ssd_detection_output_s { + uint32_t init_flag; + + dproc_ssd_detection_output_config_t config; + uint32_t max_objects; + dproc_bbox_param_t *bboxes; + dproc_ssd_detection_output_result_t *ssd_class; + uint8_t *bboxes_kept_idx_array; +} dproc_ssd_detection_output_t; + +typedef struct dproc_yolov3_output_s { + uint32_t init_flag; + + dproc_yolov3_output_config_t config; + uint32_t max_objects; + uint16_t feature_map_num; + uint16_t feature_map_width[AMBA_YOLOV3_FEATURE_NUM]; + uint16_t feature_map_height[AMBA_YOLOV3_FEATURE_NUM]; + uint16_t feature_map_pitch[AMBA_YOLOV3_FEATURE_NUM]; + uint32_t anchors_start_offset; +} dproc_yolov3_output_t; + +typedef struct dproc_context_s { + dproc_ssd_detection_output_t ssd_detection_output; + dproc_yolov3_output_t yolov3_output; +} dproc_context_t; + +#endif //_DPROC_LIB_PRIV_H + diff --git a/src/lib_smartfb_priv.h b/src/lib_smartfb_priv.h new file mode 100644 index 0000000..359aeae --- /dev/null +++ b/src/lib_smartfb_priv.h @@ -0,0 +1,107 @@ +/******************************************************************************* + * lib_smartfb_priv.h + * + * History: + * 2017/07/25 - [Hao Qian] created file + * + * Copyright (c) 2017 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ +#pragma once +#ifndef _SMARTFB_LIB_PRIV_H +#define _SMARTFB_LIB_PRIV_H +#include "define_inc.h" +#include "lib_smartfb.h" + +#ifndef LINE_SPACING +#define LINE_SPACING(x) ((x) * 3 / 2) +#endif + +#define SMARTFB_MAX_STRING_LEN (32) +#define SMARTFB_BITS_PER_PIXEL_8 (8) +#define SMARTFB_BITS_PER_PIXEL_32 (32) +#define SMARTFB_MOSAIC_USED_COLOR_TAB_NUM (64) +#define SMARTFB_USED_COLOR_TAB_NUM (SMARTFB_COLOR_NUM * SMARTFB_ALPHA_NUM) + +enum line_type { + SMARTFB_LINE_DEGREE0_0 = 0, + SMARTFB_LINE_DEGREE0_45 = 1, + SMARTFB_LINE_DEGREE45_90 = 2, + SMARTFB_LINE_DEGREE90_90 = 3, + SMARTFB_LINE_DEGREE90_135 = 4, + SMARTFB_LINE_DEGREE135_180 = 5, + SMARTFB_LINE_TYPE_NUM, +}; + +typedef struct fb_color_s { + u16 r; + u16 g; + u16 b; +} fb_color_t; + +struct fb_cmap_user { + u32 start; /* First entry */ + u32 len; /* Number of entries */ + u16 *r; + u16 *g; + u16 *b; + u16 *transparent; /* transparency, can be NULL */ +}; + +typedef struct smartfb_saved_cap_area_params_s { + u16 offset_x; + u16 offset_y; + u16 width; + u16 height; + char name[MAX_NAME_SIZE]; + u8 *buffer; +} smartfb_saved_cap_area_params_t; + +typedef struct smartfb_saved_cap_area_s { + smartfb_saved_cap_area_params_t params[MAX_CAP_AREA_NUM]; + u32 used_map : MAX_CAP_AREA_NUM; + u32 reserved : (32 - MAX_CAP_AREA_NUM); +} smartfb_saved_cap_area_t; + +typedef struct smartfb_context_s { + u8 *fb_mem; + u32 init_done : 1; + u32 cycle_buffer_num : 4; + u32 cur_cycle_buffer : 4; + u32 drawed_cycle_buffer : 4; + u32 mode_name : 1; + u32 reserved : 18; + int fb; + + // linux fb header + struct fb_var_screeninfo var; + struct fb_fix_screeninfo fix; + + // saved capture area + smartfb_saved_cap_area_t saved_areas; +} smartfb_context_t; + +#endif //_SMARTFB_LIB_PRIV_H + diff --git a/src/list.c b/src/list.c new file mode 100644 index 0000000..55972a4 --- /dev/null +++ b/src/list.c @@ -0,0 +1,101 @@ +#include <stdlib.h> +#include <string.h> +#include "list.h" + +list *make_list() +{ + list *l = malloc(sizeof(list)); + l->size = 0; + l->front = 0; + l->back = 0; + return l; +} + +/* +void transfer_node(list *s, list *d, node *n) +{ + node *prev, *next; + prev = n->prev; + next = n->next; + if(prev) prev->next = next; + if(next) next->prev = prev; + --s->size; + if(s->front == n) s->front = next; + if(s->back == n) s->back = prev; +} +*/ + +void *list_pop(list *l){ + if(!l->back) return 0; + node *b = l->back; + void *val = b->val; + l->back = b->prev; + if(l->back) l->back->next = 0; + if (b) { + free(b); + b = NULL; + } + --l->size; + + return val; +} + +void list_insert(list *l, void *val) +{ + node *new = malloc(sizeof(node)); + new->val = val; + new->next = 0; + + if(!l->back){ + l->front = new; + new->prev = 0; + }else{ + l->back->next = new; + new->prev = l->back; + } + l->back = new; + ++l->size; +} + +void free_node(node *n) +{ + node *next; + while(n) { + next = n->next; + if (n) { + free(n); + n = NULL; + } + n = next; + } +} + +void free_list(list *l) +{ + free_node(l->front); + free(l); +} + +void free_list_contents(list *l) +{ + node *n = l->front; + while(n){ + if (n->val) { + free(n->val); + n->val = NULL; + } + n = n->next; + } +} + +void **list_to_array(list *l) +{ + void **a = calloc(l->size, sizeof(void*)); + int count = 0; + node *n = l->front; + while(n){ + a[count++] = n->val; + n = n->next; + } + return a; +} diff --git a/src/list.h b/src/list.h new file mode 100644 index 0000000..eacb50b --- /dev/null +++ b/src/list.h @@ -0,0 +1,41 @@ +#pragma once +#ifndef LIST_H +#define LIST_H +#include "define_inc.h" +#include "darknet.h" + +typedef struct node { + void *val; + struct node *next; + struct node *prev; +} node; + +typedef struct list { + int size; + node *front; + node *back; +} list; + +list *make_list(); +int list_find(list *l, void *val); + +void list_insert(list *, void *); + +void free_list_contents(list *l); + +list *read_data_cfg(char *filename); +list *read_cfg(char *filename); + +char *option_find_str(list *l, char *key, char *def); +int option_find_int(list *l, char *key, int def); +int option_find_int_quiet(list *l, char*key, int def); + +list *get_paths(char *filename); + +void **list_to_array(list *l); + +void free_list(list *l); + +int *read_intlist(char *s, int *n, int d); + +#endif diff --git a/src/local_layer.c b/src/local_layer.c new file mode 100644 index 0000000..74f6910 --- /dev/null +++ b/src/local_layer.c @@ -0,0 +1,293 @@ +#include "local_layer.h" +#include "utils.h" +#include "im2col.h" +#include "col2im.h" +#include "blas.h" +#include "gemm.h" +#include <stdio.h> +#include <time.h> + +int local_out_height(local_layer l) +{ + int h = l.h; + if (!l.pad) h -= l.size; + else h -= 1; + return h/l.stride + 1; +} + +int local_out_width(local_layer l) +{ + int w = l.w; + if (!l.pad) w -= l.size; + else w -= 1; + return w/l.stride + 1; +} + +local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation) +{ + int i; + local_layer l = {0}; + l.type = LOCAL; + + l.h = h; + l.w = w; + l.c = c; + l.n = n; + l.batch = batch; + l.stride = stride; + l.size = size; + l.pad = pad; + + int out_h = local_out_height(l); + int out_w = local_out_width(l); + int locations = out_h*out_w; + l.out_h = out_h; + l.out_w = out_w; + l.out_c = n; + l.outputs = l.out_h * l.out_w * l.out_c; + l.inputs = l.w * l.h * l.c; + + l.weights = calloc(c*n*size*size*locations, sizeof(float)); + l.weight_updates = calloc(c*n*size*size*locations, sizeof(float)); + + l.biases = calloc(l.outputs, sizeof(float)); + l.bias_updates = calloc(l.outputs, sizeof(float)); + + // float scale = 1./sqrt(size*size*c); + float scale = sqrt(2./(size*size*c)); + for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_uniform(-1,1); + + l.output = calloc(l.batch*out_h * out_w * n, sizeof(float)); + l.delta = calloc(l.batch*out_h * out_w * n, sizeof(float)); + + l.workspace_size = out_h*out_w*size*size*c; + + l.forward = forward_local_layer; + l.backward = backward_local_layer; + l.update = update_local_layer; + +#ifdef GPU + l.forward_gpu = forward_local_layer_gpu; + l.backward_gpu = backward_local_layer_gpu; + l.update_gpu = update_local_layer_gpu; + + l.weights_gpu = cuda_make_array(l.weights, c*n*size*size*locations); + l.weight_updates_gpu = cuda_make_array(l.weight_updates, c*n*size*size*locations); + + l.biases_gpu = cuda_make_array(l.biases, l.outputs); + l.bias_updates_gpu = cuda_make_array(l.bias_updates, l.outputs); + + l.delta_gpu = cuda_make_array(l.delta, l.batch*out_h*out_w*n); + l.output_gpu = cuda_make_array(l.output, l.batch*out_h*out_w*n); + +#endif + l.activation = activation; + + fprintf(stderr, "Local Layer: %d x %d x %d image, %d filters -> %d x %d x %d image\n", h,w,c,n, out_h, out_w, n); + + return l; +} + +void forward_local_layer(const local_layer l, network net) +{ + int out_h = local_out_height(l); + int out_w = local_out_width(l); + int i, j; + int locations = out_h * out_w; + + for(i = 0; i < l.batch; ++i){ + copy_cpu(l.outputs, l.biases, 1, l.output + i*l.outputs, 1); + } + + for(i = 0; i < l.batch; ++i){ + float *input = net.input + i*l.w*l.h*l.c; + im2col_cpu(input, l.c, l.h, l.w, + l.size, l.stride, l.pad, net.workspace); + float *output = l.output + i*l.outputs; + for(j = 0; j < locations; ++j){ + float *a = l.weights + j*l.size*l.size*l.c*l.n; + float *b = net.workspace + j; + float *c = output + j; + + int m = l.n; + int n = 1; + int k = l.size*l.size*l.c; + + gemm(0,0,m,n,k,1,a,k,b,locations,1,c,locations); + } + } + activate_array(l.output, l.outputs*l.batch, l.activation); +} + +void backward_local_layer(local_layer l, network net) +{ + int i, j; + int locations = l.out_w*l.out_h; + + gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); + + for(i = 0; i < l.batch; ++i){ + axpy_cpu(l.outputs, 1, l.delta + i*l.outputs, 1, l.bias_updates, 1); + } + + for(i = 0; i < l.batch; ++i){ + float *input = net.input + i*l.w*l.h*l.c; + im2col_cpu(input, l.c, l.h, l.w, + l.size, l.stride, l.pad, net.workspace); + + for(j = 0; j < locations; ++j){ + float *a = l.delta + i*l.outputs + j; + float *b = net.workspace + j; + float *c = l.weight_updates + j*l.size*l.size*l.c*l.n; + int m = l.n; + int n = l.size*l.size*l.c; + int k = 1; + + gemm(0,1,m,n,k,1,a,locations,b,locations,1,c,n); + } + + if(net.delta){ + for(j = 0; j < locations; ++j){ + float *a = l.weights + j*l.size*l.size*l.c*l.n; + float *b = l.delta + i*l.outputs + j; + float *c = net.workspace + j; + + int m = l.size*l.size*l.c; + int n = 1; + int k = l.n; + + gemm(1,0,m,n,k,1,a,m,b,locations,0,c,locations); + } + + col2im_cpu(net.workspace, l.c, l.h, l.w, l.size, l.stride, l.pad, net.delta+i*l.c*l.h*l.w); + } + } +} + +void update_local_layer(local_layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + axpy_cpu(l.outputs, learning_rate/batch, l.bias_updates, 1, l.biases, 1); + scal_cpu(l.outputs, momentum, l.bias_updates, 1); + + axpy_cpu(size, -decay*batch, l.weights, 1, l.weight_updates, 1); + axpy_cpu(size, learning_rate/batch, l.weight_updates, 1, l.weights, 1); + scal_cpu(size, momentum, l.weight_updates, 1); +} + +#ifdef GPU + +void forward_local_layer_gpu(const local_layer l, network net) +{ + int out_h = local_out_height(l); + int out_w = local_out_width(l); + int i, j; + int locations = out_h * out_w; + + for(i = 0; i < l.batch; ++i){ + copy_gpu(l.outputs, l.biases_gpu, 1, l.output_gpu + i*l.outputs, 1); + } + + for(i = 0; i < l.batch; ++i){ + float *input = net.input_gpu + i*l.w*l.h*l.c; + im2col_gpu(input, l.c, l.h, l.w, + l.size, l.stride, l.pad, net.workspace); + float *output = l.output_gpu + i*l.outputs; + for(j = 0; j < locations; ++j){ + float *a = l.weights_gpu + j*l.size*l.size*l.c*l.n; + float *b = net.workspace + j; + float *c = output + j; + + int m = l.n; + int n = 1; + int k = l.size*l.size*l.c; + + gemm_gpu(0,0,m,n,k,1,a,k,b,locations,1,c,locations); + } + } + activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation); +} + +void backward_local_layer_gpu(local_layer l, network net) +{ + int i, j; + int locations = l.out_w*l.out_h; + + gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); + for(i = 0; i < l.batch; ++i){ + axpy_gpu(l.outputs, 1, l.delta_gpu + i*l.outputs, 1, l.bias_updates_gpu, 1); + } + + for(i = 0; i < l.batch; ++i){ + float *input = net.input_gpu + i*l.w*l.h*l.c; + im2col_gpu(input, l.c, l.h, l.w, + l.size, l.stride, l.pad, net.workspace); + + for(j = 0; j < locations; ++j){ + float *a = l.delta_gpu + i*l.outputs + j; + float *b = net.workspace + j; + float *c = l.weight_updates_gpu + j*l.size*l.size*l.c*l.n; + int m = l.n; + int n = l.size*l.size*l.c; + int k = 1; + + gemm_gpu(0,1,m,n,k,1,a,locations,b,locations,1,c,n); + } + + if(net.delta_gpu){ + for(j = 0; j < locations; ++j){ + float *a = l.weights_gpu + j*l.size*l.size*l.c*l.n; + float *b = l.delta_gpu + i*l.outputs + j; + float *c = net.workspace + j; + + int m = l.size*l.size*l.c; + int n = 1; + int k = l.n; + + gemm_gpu(1,0,m,n,k,1,a,m,b,locations,0,c,locations); + } + + col2im_gpu(net.workspace, l.c, l.h, l.w, l.size, l.stride, l.pad, net.delta_gpu+i*l.c*l.h*l.w); + } + } +} + +void update_local_layer_gpu(local_layer l, update_args a) +{ + float learning_rate = a.learning_rate*l.learning_rate_scale; + float momentum = a.momentum; + float decay = a.decay; + int batch = a.batch; + + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + axpy_gpu(l.outputs, learning_rate/batch, l.bias_updates_gpu, 1, l.biases_gpu, 1); + scal_gpu(l.outputs, momentum, l.bias_updates_gpu, 1); + + axpy_gpu(size, -decay*batch, l.weights_gpu, 1, l.weight_updates_gpu, 1); + axpy_gpu(size, learning_rate/batch, l.weight_updates_gpu, 1, l.weights_gpu, 1); + scal_gpu(size, momentum, l.weight_updates_gpu, 1); +} + +void pull_local_layer(local_layer l) +{ + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + cuda_pull_array(l.weights_gpu, l.weights, size); + cuda_pull_array(l.biases_gpu, l.biases, l.outputs); +} + +void push_local_layer(local_layer l) +{ + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + cuda_push_array(l.weights_gpu, l.weights, size); + cuda_push_array(l.biases_gpu, l.biases, l.outputs); +} +#endif diff --git a/src/local_layer.h b/src/local_layer.h new file mode 100644 index 0000000..ea515a0 --- /dev/null +++ b/src/local_layer.h @@ -0,0 +1,32 @@ +#pragma once +#ifndef LOCAL_LAYER_H +#define LOCAL_LAYER_H +#include "define_inc.h" +#include "cuda.h" +#include "image.h" +#include "activations.h" +#include "layer.h" +#include "network.h" + +typedef layer local_layer; + +#ifdef GPU +void forward_local_layer_gpu(local_layer layer, network net); +void backward_local_layer_gpu(local_layer layer, network net); +void update_local_layer_gpu(local_layer layer, update_args a); + +void push_local_layer(local_layer layer); +void pull_local_layer(local_layer layer); +#endif + +local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation); + +void forward_local_layer(const local_layer layer, network net); +void backward_local_layer(local_layer layer, network net); +void update_local_layer(local_layer layer, update_args a); + +void bias_output(float *output, float *biases, int batch, int n, int size); +void backward_bias(float *bias_updates, float *delta, int batch, int n, int size); + +#endif + diff --git a/src/logistic_layer.c b/src/logistic_layer.c new file mode 100644 index 0000000..487aef3 --- /dev/null +++ b/src/logistic_layer.c @@ -0,0 +1,72 @@ +#include "logistic_layer.h" +#include "activations.h" +#include "utils.h" +#include "blas.h" +#include "cuda.h" + +#include <float.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> + +layer make_logistic_layer(int batch, int inputs) +{ + fprintf(stderr, "logistic x entropy %4d\n", inputs); + layer l = {0}; + l.type = LOGXENT; + l.batch = batch; + l.inputs = inputs; + l.outputs = inputs; + l.loss = calloc(inputs*batch, sizeof(float)); + l.output = calloc(inputs*batch, sizeof(float)); + l.delta = calloc(inputs*batch, sizeof(float)); + l.cost = calloc(1, sizeof(float)); + + l.forward = forward_logistic_layer; + l.backward = backward_logistic_layer; + #ifdef GPU + l.forward_gpu = forward_logistic_layer_gpu; + l.backward_gpu = backward_logistic_layer_gpu; + + l.output_gpu = cuda_make_array(l.output, inputs*batch); + l.loss_gpu = cuda_make_array(l.loss, inputs*batch); + l.delta_gpu = cuda_make_array(l.delta, inputs*batch); + #endif + return l; +} + +void forward_logistic_layer(const layer l, network net) +{ + copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); + activate_array(l.output, l.outputs*l.batch, LOGISTIC); + if(net.truth){ + logistic_x_ent_cpu(l.batch*l.inputs, l.output, net.truth, l.delta, l.loss); + l.cost[0] = sum_array(l.loss, l.batch*l.inputs); + } +} + +void backward_logistic_layer(const layer l, network net) +{ + axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void forward_logistic_layer_gpu(const layer l, network net) +{ + copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1); + activate_array_gpu(l.output_gpu, l.outputs*l.batch, LOGISTIC); + if(net.truth){ + logistic_x_ent_gpu(l.batch*l.inputs, l.output_gpu, net.truth_gpu, l.delta_gpu, l.loss_gpu); + cuda_pull_array(l.loss_gpu, l.loss, l.batch*l.inputs); + l.cost[0] = sum_array(l.loss, l.batch*l.inputs); + } +} + +void backward_logistic_layer_gpu(const layer l, network net) +{ + axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1); +} + +#endif diff --git a/src/logistic_layer.h b/src/logistic_layer.h new file mode 100644 index 0000000..3aeb5e5 --- /dev/null +++ b/src/logistic_layer.h @@ -0,0 +1,17 @@ +#pragma once +#ifndef LOGISTIC_LAYER_H +#define LOGISTIC_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" + +layer make_logistic_layer(int batch, int inputs); +void forward_logistic_layer(const layer l, network net); +void backward_logistic_layer(const layer l, network net); + +#ifdef GPU +void forward_logistic_layer_gpu(const layer l, network net); +void backward_logistic_layer_gpu(const layer l, network net); +#endif + +#endif diff --git a/src/lstm_layer.c b/src/lstm_layer.c new file mode 100644 index 0000000..fb07de2 --- /dev/null +++ b/src/lstm_layer.c @@ -0,0 +1,626 @@ +#include "lstm_layer.h" +#include "connected_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void increment_layer(layer *l, int steps) +{ + int num = l->outputs*l->batch*steps; + l->output += num; + l->delta += num; + l->x += num; + l->x_norm += num; + +#ifdef GPU + l->output_gpu += num; + l->delta_gpu += num; + l->x_gpu += num; + l->x_norm_gpu += num; +#endif +} + +layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam) +{ + fprintf(stderr, "LSTM Layer: %d inputs, %d outputs\n", inputs, outputs); + batch = batch / steps; + layer l = { 0 }; + l.batch = batch; + l.type = LSTM; + l.steps = steps; + l.inputs = inputs; + + l.uf = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.uf) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.uf->batch = batch; + + l.ui = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.ui) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.ui->batch = batch; + + l.ug = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.ug) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.ug->batch = batch; + + l.uo = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.uo) = make_connected_layer(batch*steps, inputs, outputs, LINEAR, batch_normalize, adam); + l.uo->batch = batch; + + l.wf = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wf) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wf->batch = batch; + + l.wi = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wi) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wi->batch = batch; + + l.wg = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wg) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wg->batch = batch; + + l.wo = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.wo) = make_connected_layer(batch*steps, outputs, outputs, LINEAR, batch_normalize, adam); + l.wo->batch = batch; + + l.batch_normalize = batch_normalize; + l.outputs = outputs; + + l.output = calloc(outputs*batch*steps, sizeof(float)); + l.state = calloc(outputs*batch, sizeof(float)); + + l.forward = forward_lstm_layer; + l.update = update_lstm_layer; + + l.prev_state_cpu = calloc(batch*outputs, sizeof(float)); + l.prev_cell_cpu = calloc(batch*outputs, sizeof(float)); + l.cell_cpu = calloc(batch*outputs*steps, sizeof(float)); + + l.f_cpu = calloc(batch*outputs, sizeof(float)); + l.i_cpu = calloc(batch*outputs, sizeof(float)); + l.g_cpu = calloc(batch*outputs, sizeof(float)); + l.o_cpu = calloc(batch*outputs, sizeof(float)); + l.c_cpu = calloc(batch*outputs, sizeof(float)); + l.h_cpu = calloc(batch*outputs, sizeof(float)); + l.temp_cpu = calloc(batch*outputs, sizeof(float)); + l.temp2_cpu = calloc(batch*outputs, sizeof(float)); + l.temp3_cpu = calloc(batch*outputs, sizeof(float)); + l.dc_cpu = calloc(batch*outputs, sizeof(float)); + l.dh_cpu = calloc(batch*outputs, sizeof(float)); + +#ifdef GPU + l.forward_gpu = forward_lstm_layer_gpu; + l.backward_gpu = backward_lstm_layer_gpu; + l.update_gpu = update_lstm_layer_gpu; + + l.output_gpu = cuda_make_array(0, batch*outputs*steps); + l.delta_gpu = cuda_make_array(0, batch*l.outputs*steps); + + l.prev_state_gpu = cuda_make_array(0, batch*outputs); + l.prev_cell_gpu = cuda_make_array(0, batch*outputs); + l.cell_gpu = cuda_make_array(0, batch*outputs*steps); + + l.f_gpu = cuda_make_array(0, batch*outputs); + l.i_gpu = cuda_make_array(0, batch*outputs); + l.g_gpu = cuda_make_array(0, batch*outputs); + l.o_gpu = cuda_make_array(0, batch*outputs); + l.c_gpu = cuda_make_array(0, batch*outputs); + l.h_gpu = cuda_make_array(0, batch*outputs); + l.temp_gpu = cuda_make_array(0, batch*outputs); + l.temp2_gpu = cuda_make_array(0, batch*outputs); + l.temp3_gpu = cuda_make_array(0, batch*outputs); + l.dc_gpu = cuda_make_array(0, batch*outputs); + l.dh_gpu = cuda_make_array(0, batch*outputs); +#ifdef CUDNN + cudnnSetTensor4dDescriptor(l.wf->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wf->out_c, l.wf->out_h, l.wf->out_w); + cudnnSetTensor4dDescriptor(l.wi->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wi->out_c, l.wi->out_h, l.wi->out_w); + cudnnSetTensor4dDescriptor(l.wg->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wg->out_c, l.wg->out_h, l.wg->out_w); + cudnnSetTensor4dDescriptor(l.wo->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.wo->out_c, l.wo->out_h, l.wo->out_w); + + cudnnSetTensor4dDescriptor(l.uf->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.uf->out_c, l.uf->out_h, l.uf->out_w); + cudnnSetTensor4dDescriptor(l.ui->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.ui->out_c, l.ui->out_h, l.ui->out_w); + cudnnSetTensor4dDescriptor(l.ug->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.ug->out_c, l.ug->out_h, l.ug->out_w); + cudnnSetTensor4dDescriptor(l.uo->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.uo->out_c, l.uo->out_h, l.uo->out_w); +#endif + +#endif + + return l; +} + +void update_lstm_layer(layer l, update_args a) +{ + update_connected_layer(*(l.wf), a); + update_connected_layer(*(l.wi), a); + update_connected_layer(*(l.wg), a); + update_connected_layer(*(l.wo), a); + update_connected_layer(*(l.uf), a); + update_connected_layer(*(l.ui), a); + update_connected_layer(*(l.ug), a); + update_connected_layer(*(l.uo), a); +} + +void forward_lstm_layer(layer l, network state) +{ + network s = { 0 }; + s.train = state.train; + int i; + layer wf = *(l.wf); + layer wi = *(l.wi); + layer wg = *(l.wg); + layer wo = *(l.wo); + + layer uf = *(l.uf); + layer ui = *(l.ui); + layer ug = *(l.ug); + layer uo = *(l.uo); + + fill_cpu(l.outputs * l.batch * l.steps, 0, wf.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, wi.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, wg.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, wo.delta, 1); + + fill_cpu(l.outputs * l.batch * l.steps, 0, uf.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, ui.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, ug.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, uo.delta, 1); + if (state.train) { + fill_cpu(l.outputs * l.batch * l.steps, 0, l.delta, 1); + } + + for (i = 0; i < l.steps; ++i) { + s.input = l.h_cpu; + forward_connected_layer(wf, s); + forward_connected_layer(wi, s); + forward_connected_layer(wg, s); + forward_connected_layer(wo, s); + + s.input = state.input; + forward_connected_layer(uf, s); + forward_connected_layer(ui, s); + forward_connected_layer(ug, s); + forward_connected_layer(uo, s); + + copy_cpu(l.outputs*l.batch, wf.output, 1, l.f_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, uf.output, 1, l.f_cpu, 1); + + copy_cpu(l.outputs*l.batch, wi.output, 1, l.i_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, ui.output, 1, l.i_cpu, 1); + + copy_cpu(l.outputs*l.batch, wg.output, 1, l.g_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, ug.output, 1, l.g_cpu, 1); + + copy_cpu(l.outputs*l.batch, wo.output, 1, l.o_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, uo.output, 1, l.o_cpu, 1); + + activate_array(l.f_cpu, l.outputs*l.batch, LOGISTIC); + activate_array(l.i_cpu, l.outputs*l.batch, LOGISTIC); + activate_array(l.g_cpu, l.outputs*l.batch, TANH); + activate_array(l.o_cpu, l.outputs*l.batch, LOGISTIC); + + copy_cpu(l.outputs*l.batch, l.i_cpu, 1, l.temp_cpu, 1); + mul_cpu(l.outputs*l.batch, l.g_cpu, 1, l.temp_cpu, 1); + mul_cpu(l.outputs*l.batch, l.f_cpu, 1, l.c_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, l.temp_cpu, 1, l.c_cpu, 1); + + copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.h_cpu, 1); + activate_array(l.h_cpu, l.outputs*l.batch, TANH); + mul_cpu(l.outputs*l.batch, l.o_cpu, 1, l.h_cpu, 1); + + copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.cell_cpu, 1); + copy_cpu(l.outputs*l.batch, l.h_cpu, 1, l.output, 1); + + state.input += l.inputs*l.batch; + l.output += l.outputs*l.batch; + l.cell_cpu += l.outputs*l.batch; + + increment_layer(&wf, 1); + increment_layer(&wi, 1); + increment_layer(&wg, 1); + increment_layer(&wo, 1); + + increment_layer(&uf, 1); + increment_layer(&ui, 1); + increment_layer(&ug, 1); + increment_layer(&uo, 1); + } +} + +void backward_lstm_layer(layer l, network state) +{ + network s = { 0 }; + s.train = state.train; + int i; + layer wf = *(l.wf); + layer wi = *(l.wi); + layer wg = *(l.wg); + layer wo = *(l.wo); + + layer uf = *(l.uf); + layer ui = *(l.ui); + layer ug = *(l.ug); + layer uo = *(l.uo); + + increment_layer(&wf, l.steps - 1); + increment_layer(&wi, l.steps - 1); + increment_layer(&wg, l.steps - 1); + increment_layer(&wo, l.steps - 1); + + increment_layer(&uf, l.steps - 1); + increment_layer(&ui, l.steps - 1); + increment_layer(&ug, l.steps - 1); + increment_layer(&uo, l.steps - 1); + + state.input += l.inputs*l.batch*(l.steps - 1); + if (state.delta) state.delta += l.inputs*l.batch*(l.steps - 1); + + l.output += l.outputs*l.batch*(l.steps - 1); + l.cell_cpu += l.outputs*l.batch*(l.steps - 1); + l.delta += l.outputs*l.batch*(l.steps - 1); + + for (i = l.steps - 1; i >= 0; --i) { + if (i != 0) copy_cpu(l.outputs*l.batch, l.cell_cpu - l.outputs*l.batch, 1, l.prev_cell_cpu, 1); + copy_cpu(l.outputs*l.batch, l.cell_cpu, 1, l.c_cpu, 1); + if (i != 0) copy_cpu(l.outputs*l.batch, l.output - l.outputs*l.batch, 1, l.prev_state_cpu, 1); + copy_cpu(l.outputs*l.batch, l.output, 1, l.h_cpu, 1); + + l.dh_cpu = (i == 0) ? 0 : l.delta - l.outputs*l.batch; + + copy_cpu(l.outputs*l.batch, wf.output, 1, l.f_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, uf.output, 1, l.f_cpu, 1); + + copy_cpu(l.outputs*l.batch, wi.output, 1, l.i_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, ui.output, 1, l.i_cpu, 1); + + copy_cpu(l.outputs*l.batch, wg.output, 1, l.g_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, ug.output, 1, l.g_cpu, 1); + + copy_cpu(l.outputs*l.batch, wo.output, 1, l.o_cpu, 1); + axpy_cpu(l.outputs*l.batch, 1, uo.output, 1, l.o_cpu, 1); + + activate_array(l.f_cpu, l.outputs*l.batch, LOGISTIC); + activate_array(l.i_cpu, l.outputs*l.batch, LOGISTIC); + activate_array(l.g_cpu, l.outputs*l.batch, TANH); + activate_array(l.o_cpu, l.outputs*l.batch, LOGISTIC); + + copy_cpu(l.outputs*l.batch, l.delta, 1, l.temp3_cpu, 1); + + copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.temp_cpu, 1); + activate_array(l.temp_cpu, l.outputs*l.batch, TANH); + + copy_cpu(l.outputs*l.batch, l.temp3_cpu, 1, l.temp2_cpu, 1); + mul_cpu(l.outputs*l.batch, l.o_cpu, 1, l.temp2_cpu, 1); + + gradient_array(l.temp_cpu, l.outputs*l.batch, TANH, l.temp2_cpu); + axpy_cpu(l.outputs*l.batch, 1, l.dc_cpu, 1, l.temp2_cpu, 1); + + copy_cpu(l.outputs*l.batch, l.c_cpu, 1, l.temp_cpu, 1); + activate_array(l.temp_cpu, l.outputs*l.batch, TANH); + mul_cpu(l.outputs*l.batch, l.temp3_cpu, 1, l.temp_cpu, 1); + gradient_array(l.o_cpu, l.outputs*l.batch, LOGISTIC, l.temp_cpu); + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wo.delta, 1); + s.input = l.prev_state_cpu; + s.delta = l.dh_cpu; + backward_connected_layer(wo, s); + + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, uo.delta, 1); + s.input = state.input; + s.delta = state.delta; + backward_connected_layer(uo, s); + + copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1); + mul_cpu(l.outputs*l.batch, l.i_cpu, 1, l.temp_cpu, 1); + gradient_array(l.g_cpu, l.outputs*l.batch, TANH, l.temp_cpu); + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wg.delta, 1); + s.input = l.prev_state_cpu; + s.delta = l.dh_cpu; + backward_connected_layer(wg, s); + + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, ug.delta, 1); + s.input = state.input; + s.delta = state.delta; + backward_connected_layer(ug, s); + + copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1); + mul_cpu(l.outputs*l.batch, l.g_cpu, 1, l.temp_cpu, 1); + gradient_array(l.i_cpu, l.outputs*l.batch, LOGISTIC, l.temp_cpu); + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wi.delta, 1); + s.input = l.prev_state_cpu; + s.delta = l.dh_cpu; + backward_connected_layer(wi, s); + + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, ui.delta, 1); + s.input = state.input; + s.delta = state.delta; + backward_connected_layer(ui, s); + + copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1); + mul_cpu(l.outputs*l.batch, l.prev_cell_cpu, 1, l.temp_cpu, 1); + gradient_array(l.f_cpu, l.outputs*l.batch, LOGISTIC, l.temp_cpu); + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, wf.delta, 1); + s.input = l.prev_state_cpu; + s.delta = l.dh_cpu; + backward_connected_layer(wf, s); + + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, uf.delta, 1); + s.input = state.input; + s.delta = state.delta; + backward_connected_layer(uf, s); + + copy_cpu(l.outputs*l.batch, l.temp2_cpu, 1, l.temp_cpu, 1); + mul_cpu(l.outputs*l.batch, l.f_cpu, 1, l.temp_cpu, 1); + copy_cpu(l.outputs*l.batch, l.temp_cpu, 1, l.dc_cpu, 1); + + state.input -= l.inputs*l.batch; + if (state.delta) state.delta -= l.inputs*l.batch; + l.output -= l.outputs*l.batch; + l.cell_cpu -= l.outputs*l.batch; + l.delta -= l.outputs*l.batch; + + increment_layer(&wf, -1); + increment_layer(&wi, -1); + increment_layer(&wg, -1); + increment_layer(&wo, -1); + + increment_layer(&uf, -1); + increment_layer(&ui, -1); + increment_layer(&ug, -1); + increment_layer(&uo, -1); + } +} + +#ifdef GPU +void update_lstm_layer_gpu(layer l, update_args a) +{ + update_connected_layer_gpu(*(l.wf), a); + update_connected_layer_gpu(*(l.wi), a); + update_connected_layer_gpu(*(l.wg), a); + update_connected_layer_gpu(*(l.wo), a); + update_connected_layer_gpu(*(l.uf), a); + update_connected_layer_gpu(*(l.ui), a); + update_connected_layer_gpu(*(l.ug), a); + update_connected_layer_gpu(*(l.uo), a); +} + +void forward_lstm_layer_gpu(layer l, network state) +{ + network s = { 0 }; + s.train = state.train; + int i; + layer wf = *(l.wf); + layer wi = *(l.wi); + layer wg = *(l.wg); + layer wo = *(l.wo); + + layer uf = *(l.uf); + layer ui = *(l.ui); + layer ug = *(l.ug); + layer uo = *(l.uo); + + fill_gpu(l.outputs * l.batch * l.steps, 0, wf.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, wi.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, wg.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, wo.delta_gpu, 1); + + fill_gpu(l.outputs * l.batch * l.steps, 0, uf.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, ui.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, ug.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, uo.delta_gpu, 1); + if (state.train) { + fill_gpu(l.outputs * l.batch * l.steps, 0, l.delta_gpu, 1); + } + + for (i = 0; i < l.steps; ++i) { + s.input_gpu = l.h_gpu; + forward_connected_layer_gpu(wf, s); + forward_connected_layer_gpu(wi, s); + forward_connected_layer_gpu(wg, s); + forward_connected_layer_gpu(wo, s); + + s.input_gpu = state.input_gpu; + forward_connected_layer_gpu(uf, s); + forward_connected_layer_gpu(ui, s); + forward_connected_layer_gpu(ug, s); + forward_connected_layer_gpu(uo, s); + + copy_gpu(l.outputs*l.batch, wf.output_gpu, 1, l.f_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, uf.output_gpu, 1, l.f_gpu, 1); + + copy_gpu(l.outputs*l.batch, wi.output_gpu, 1, l.i_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, ui.output_gpu, 1, l.i_gpu, 1); + + copy_gpu(l.outputs*l.batch, wg.output_gpu, 1, l.g_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, ug.output_gpu, 1, l.g_gpu, 1); + + copy_gpu(l.outputs*l.batch, wo.output_gpu, 1, l.o_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, uo.output_gpu, 1, l.o_gpu, 1); + + activate_array_gpu(l.f_gpu, l.outputs*l.batch, LOGISTIC); + activate_array_gpu(l.i_gpu, l.outputs*l.batch, LOGISTIC); + activate_array_gpu(l.g_gpu, l.outputs*l.batch, TANH); + activate_array_gpu(l.o_gpu, l.outputs*l.batch, LOGISTIC); + + copy_gpu(l.outputs*l.batch, l.i_gpu, 1, l.temp_gpu, 1); + mul_gpu(l.outputs*l.batch, l.g_gpu, 1, l.temp_gpu, 1); + mul_gpu(l.outputs*l.batch, l.f_gpu, 1, l.c_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, l.temp_gpu, 1, l.c_gpu, 1); + + copy_gpu(l.outputs*l.batch, l.c_gpu, 1, l.h_gpu, 1); + activate_array_gpu(l.h_gpu, l.outputs*l.batch, TANH); + mul_gpu(l.outputs*l.batch, l.o_gpu, 1, l.h_gpu, 1); + + copy_gpu(l.outputs*l.batch, l.c_gpu, 1, l.cell_gpu, 1); + copy_gpu(l.outputs*l.batch, l.h_gpu, 1, l.output_gpu, 1); + + state.input_gpu += l.inputs*l.batch; + l.output_gpu += l.outputs*l.batch; + l.cell_gpu += l.outputs*l.batch; + + increment_layer(&wf, 1); + increment_layer(&wi, 1); + increment_layer(&wg, 1); + increment_layer(&wo, 1); + + increment_layer(&uf, 1); + increment_layer(&ui, 1); + increment_layer(&ug, 1); + increment_layer(&uo, 1); + } +} + +void backward_lstm_layer_gpu(layer l, network state) +{ + network s = { 0 }; + s.train = state.train; + int i; + layer wf = *(l.wf); + layer wi = *(l.wi); + layer wg = *(l.wg); + layer wo = *(l.wo); + + layer uf = *(l.uf); + layer ui = *(l.ui); + layer ug = *(l.ug); + layer uo = *(l.uo); + + increment_layer(&wf, l.steps - 1); + increment_layer(&wi, l.steps - 1); + increment_layer(&wg, l.steps - 1); + increment_layer(&wo, l.steps - 1); + + increment_layer(&uf, l.steps - 1); + increment_layer(&ui, l.steps - 1); + increment_layer(&ug, l.steps - 1); + increment_layer(&uo, l.steps - 1); + + state.input_gpu += l.inputs*l.batch*(l.steps - 1); + if (state.delta_gpu) state.delta_gpu += l.inputs*l.batch*(l.steps - 1); + + l.output_gpu += l.outputs*l.batch*(l.steps - 1); + l.cell_gpu += l.outputs*l.batch*(l.steps - 1); + l.delta_gpu += l.outputs*l.batch*(l.steps - 1); + + for (i = l.steps - 1; i >= 0; --i) { + if (i != 0) copy_gpu(l.outputs*l.batch, l.cell_gpu - l.outputs*l.batch, 1, l.prev_cell_gpu, 1); + copy_gpu(l.outputs*l.batch, l.cell_gpu, 1, l.c_gpu, 1); + if (i != 0) copy_gpu(l.outputs*l.batch, l.output_gpu - l.outputs*l.batch, 1, l.prev_state_gpu, 1); + copy_gpu(l.outputs*l.batch, l.output_gpu, 1, l.h_gpu, 1); + + l.dh_gpu = (i == 0) ? 0 : l.delta_gpu - l.outputs*l.batch; + + copy_gpu(l.outputs*l.batch, wf.output_gpu, 1, l.f_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, uf.output_gpu, 1, l.f_gpu, 1); + + copy_gpu(l.outputs*l.batch, wi.output_gpu, 1, l.i_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, ui.output_gpu, 1, l.i_gpu, 1); + + copy_gpu(l.outputs*l.batch, wg.output_gpu, 1, l.g_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, ug.output_gpu, 1, l.g_gpu, 1); + + copy_gpu(l.outputs*l.batch, wo.output_gpu, 1, l.o_gpu, 1); + axpy_gpu(l.outputs*l.batch, 1, uo.output_gpu, 1, l.o_gpu, 1); + + activate_array_gpu(l.f_gpu, l.outputs*l.batch, LOGISTIC); + activate_array_gpu(l.i_gpu, l.outputs*l.batch, LOGISTIC); + activate_array_gpu(l.g_gpu, l.outputs*l.batch, TANH); + activate_array_gpu(l.o_gpu, l.outputs*l.batch, LOGISTIC); + + copy_gpu(l.outputs*l.batch, l.delta_gpu, 1, l.temp3_gpu, 1); + + copy_gpu(l.outputs*l.batch, l.c_gpu, 1, l.temp_gpu, 1); + activate_array_gpu(l.temp_gpu, l.outputs*l.batch, TANH); + + copy_gpu(l.outputs*l.batch, l.temp3_gpu, 1, l.temp2_gpu, 1); + mul_gpu(l.outputs*l.batch, l.o_gpu, 1, l.temp2_gpu, 1); + + gradient_array_gpu(l.temp_gpu, l.outputs*l.batch, TANH, l.temp2_gpu); + axpy_gpu(l.outputs*l.batch, 1, l.dc_gpu, 1, l.temp2_gpu, 1); + + copy_gpu(l.outputs*l.batch, l.c_gpu, 1, l.temp_gpu, 1); + activate_array_gpu(l.temp_gpu, l.outputs*l.batch, TANH); + mul_gpu(l.outputs*l.batch, l.temp3_gpu, 1, l.temp_gpu, 1); + gradient_array_gpu(l.o_gpu, l.outputs*l.batch, LOGISTIC, l.temp_gpu); + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, wo.delta_gpu, 1); + s.input_gpu = l.prev_state_gpu; + s.delta_gpu = l.dh_gpu; + backward_connected_layer_gpu(wo, s); + + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, uo.delta_gpu, 1); + s.input_gpu = state.input_gpu; + s.delta_gpu = state.delta_gpu; + backward_connected_layer_gpu(uo, s); + + copy_gpu(l.outputs*l.batch, l.temp2_gpu, 1, l.temp_gpu, 1); + mul_gpu(l.outputs*l.batch, l.i_gpu, 1, l.temp_gpu, 1); + gradient_array_gpu(l.g_gpu, l.outputs*l.batch, TANH, l.temp_gpu); + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, wg.delta_gpu, 1); + s.input_gpu = l.prev_state_gpu; + s.delta_gpu = l.dh_gpu; + backward_connected_layer_gpu(wg, s); + + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, ug.delta_gpu, 1); + s.input_gpu = state.input_gpu; + s.delta_gpu = state.delta_gpu; + backward_connected_layer_gpu(ug, s); + + copy_gpu(l.outputs*l.batch, l.temp2_gpu, 1, l.temp_gpu, 1); + mul_gpu(l.outputs*l.batch, l.g_gpu, 1, l.temp_gpu, 1); + gradient_array_gpu(l.i_gpu, l.outputs*l.batch, LOGISTIC, l.temp_gpu); + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, wi.delta_gpu, 1); + s.input_gpu = l.prev_state_gpu; + s.delta_gpu = l.dh_gpu; + backward_connected_layer_gpu(wi, s); + + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, ui.delta_gpu, 1); + s.input_gpu = state.input_gpu; + s.delta_gpu = state.delta_gpu; + backward_connected_layer_gpu(ui, s); + + copy_gpu(l.outputs*l.batch, l.temp2_gpu, 1, l.temp_gpu, 1); + mul_gpu(l.outputs*l.batch, l.prev_cell_gpu, 1, l.temp_gpu, 1); + gradient_array_gpu(l.f_gpu, l.outputs*l.batch, LOGISTIC, l.temp_gpu); + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, wf.delta_gpu, 1); + s.input_gpu = l.prev_state_gpu; + s.delta_gpu = l.dh_gpu; + backward_connected_layer_gpu(wf, s); + + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, uf.delta_gpu, 1); + s.input_gpu = state.input_gpu; + s.delta_gpu = state.delta_gpu; + backward_connected_layer_gpu(uf, s); + + copy_gpu(l.outputs*l.batch, l.temp2_gpu, 1, l.temp_gpu, 1); + mul_gpu(l.outputs*l.batch, l.f_gpu, 1, l.temp_gpu, 1); + copy_gpu(l.outputs*l.batch, l.temp_gpu, 1, l.dc_gpu, 1); + + state.input_gpu -= l.inputs*l.batch; + if (state.delta_gpu) state.delta_gpu -= l.inputs*l.batch; + l.output_gpu -= l.outputs*l.batch; + l.cell_gpu -= l.outputs*l.batch; + l.delta_gpu -= l.outputs*l.batch; + + increment_layer(&wf, -1); + increment_layer(&wi, -1); + increment_layer(&wg, -1); + increment_layer(&wo, -1); + + increment_layer(&uf, -1); + increment_layer(&ui, -1); + increment_layer(&ug, -1); + increment_layer(&uo, -1); + } +} +#endif diff --git a/src/lstm_layer.h b/src/lstm_layer.h new file mode 100644 index 0000000..57f0021 --- /dev/null +++ b/src/lstm_layer.h @@ -0,0 +1,21 @@ +#pragma once +#ifndef LSTM_LAYER_H +#define LSTM_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "layer.h" +#include "network.h" +#define USET + +layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam); + +void forward_lstm_layer(layer l, network net); +void update_lstm_layer(layer l, update_args a); + +#ifdef GPU +void forward_lstm_layer_gpu(layer l, network net); +void backward_lstm_layer_gpu(layer l, network net); +void update_lstm_layer_gpu(layer l, update_args a); + +#endif +#endif diff --git a/src/matrix.c b/src/matrix.c new file mode 100644 index 0000000..db0f695 --- /dev/null +++ b/src/matrix.c @@ -0,0 +1,212 @@ +#include "matrix.h" +#include "utils.h" +#include "blas.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <math.h> + +void free_matrix(matrix m) +{ + int i; + for (i = 0; i < m.rows; ++i) + if (m.vals[i]) { + free(m.vals[i]); + m.vals[i] = NULL; + } + if (m.vals) { + free(m.vals); + m.vals = NULL; + } +} + +float matrix_topk_accuracy(matrix truth, matrix guess, int k) +{ + int *indexes = calloc(k, sizeof(int)); + int n = truth.cols; + int i,j; + int correct = 0; + for(i = 0; i < truth.rows; ++i){ + top_k(guess.vals[i], n, k, indexes); + for(j = 0; j < k; ++j){ + int class = indexes[j]; + if(truth.vals[i][class]){ + ++correct; + break; + } + } + } + if (indexes) { + free(indexes); + indexes = NULL; + } + return (float)correct/truth.rows; +} + +void scale_matrix(matrix m, float scale) +{ + int i,j; + for(i = 0; i < m.rows; ++i){ + for(j = 0; j < m.cols; ++j){ + m.vals[i][j] *= scale; + } + } +} + +matrix resize_matrix(matrix m, int size) +{ + int i; + if (m.rows == size) return m; + if (m.rows < size) { + m.vals = realloc(m.vals, size*sizeof(float*)); + for (i = m.rows; i < size; ++i) { + m.vals[i] = calloc(m.cols, sizeof(float)); + } + } else if (m.rows > size) { + for (i = size; i < m.rows; ++i) { + if (m.vals[i]) { + free(m.vals[i]); + m.vals[i] = NULL; + } + } + m.vals = realloc(m.vals, size*sizeof(float*)); + } + m.rows = size; + return m; +} + +void matrix_add_matrix(matrix from, matrix to) +{ + assert(from.rows == to.rows && from.cols == to.cols); + int i,j; + for(i = 0; i < from.rows; ++i){ + for(j = 0; j < from.cols; ++j){ + to.vals[i][j] += from.vals[i][j]; + } + } +} + +matrix copy_matrix(matrix m) +{ + matrix c = {0}; + c.rows = m.rows; + c.cols = m.cols; + c.vals = calloc(c.rows, sizeof(float *)); + int i; + for(i = 0; i < c.rows; ++i){ + c.vals[i] = calloc(c.cols, sizeof(float)); + copy_cpu(c.cols, m.vals[i], 1, c.vals[i], 1); + } + return c; +} + +matrix make_matrix(int rows, int cols) +{ + int i; + matrix m; + m.rows = rows; + m.cols = cols; + m.vals = calloc(m.rows, sizeof(float *)); + for(i = 0; i < m.rows; ++i){ + m.vals[i] = calloc(m.cols, sizeof(float)); + } + return m; +} + +matrix hold_out_matrix(matrix *m, int n) +{ + int i; + matrix h; + h.rows = n; + h.cols = m->cols; + h.vals = calloc(h.rows, sizeof(float *)); + for(i = 0; i < n; ++i){ + int index = rand()%m->rows; + h.vals[i] = m->vals[index]; + m->vals[index] = m->vals[--(m->rows)]; + } + return h; +} + +float *pop_column(matrix *m, int c) +{ + float *col = calloc(m->rows, sizeof(float)); + int i, j; + for(i = 0; i < m->rows; ++i){ + col[i] = m->vals[i][c]; + for(j = c; j < m->cols-1; ++j){ + m->vals[i][j] = m->vals[i][j+1]; + } + } + --m->cols; + return col; +} + +matrix csv_to_matrix(char *filename) +{ + FILE *fp = fopen(filename, "r"); + if(!fp) file_error(filename); + + matrix m; + m.cols = -1; + + char *line; + + int n = 0; + int size = 1024; + m.vals = calloc(size, sizeof(float*)); + while((line = fgetl(fp))){ + if(m.cols == -1) m.cols = count_fields(line); + if(n == size){ + size *= 2; + m.vals = realloc(m.vals, size*sizeof(float*)); + } + m.vals[n] = parse_fields(line, m.cols); + if (line) { + free(line); + line = NULL; + } + ++n; + } + m.vals = realloc(m.vals, n*sizeof(float*)); + m.rows = n; + return m; +} + +void matrix_to_csv(matrix m) +{ + int i, j; + + for(i = 0; i < m.rows; ++i){ + for(j = 0; j < m.cols; ++j){ + if(j > 0) printf(","); + printf("%.17g", m.vals[i][j]); + } + printf("\n"); + } +} + +void print_matrix(matrix m) +{ + int i, j; + printf("%d X %d Matrix:\n",m.rows, m.cols); + printf(" __"); + for(j = 0; j < 16*m.cols-1; ++j) printf(" "); + printf("__ \n"); + + printf("| "); + for(j = 0; j < 16*m.cols-1; ++j) printf(" "); + printf(" |\n"); + + for(i = 0; i < m.rows; ++i){ + printf("| "); + for(j = 0; j < m.cols; ++j){ + printf("%15.7f ", m.vals[i][j]); + } + printf(" |\n"); + } + printf("|__"); + for(j = 0; j < 16*m.cols-1; ++j) printf(" "); + printf("__|\n"); +} diff --git a/src/matrix.h b/src/matrix.h new file mode 100644 index 0000000..d37c8c6 --- /dev/null +++ b/src/matrix.h @@ -0,0 +1,30 @@ +#pragma once +#ifndef MATRIX_H +#define MATRIX_H +#include "define_inc.h" +#include "darknet.h" + +typedef struct matrix { + int rows, cols; + float **vals; +} matrix; + +matrix copy_matrix(matrix m); +void print_matrix(matrix m); + +matrix hold_out_matrix(matrix *m, int n); +matrix resize_matrix(matrix m, int size); + +float *pop_column(matrix *m, int c); + +void matrix_to_csv(matrix m); +float matrix_topk_accuracy(matrix truth, matrix guess, int k); +void matrix_add_matrix(matrix from, matrix to); +void scale_matrix(matrix m, float scale); +matrix csv_to_matrix(char *filename); + +void free_matrix(matrix m); + +matrix make_matrix(int rows, int cols); + +#endif diff --git a/src/maxpool_layer.c b/src/maxpool_layer.c new file mode 100644 index 0000000..8338d3d --- /dev/null +++ b/src/maxpool_layer.c @@ -0,0 +1,162 @@ +#include "maxpool_layer.h" +#include "cuda.h" +#include <stdio.h> + +image get_maxpool_image(maxpool_layer l) +{ + int h = l.out_h; + int w = l.out_w; + int c = l.c; + return float_to_image(w,h,c,l.output); +} + +image get_maxpool_delta(maxpool_layer l) +{ + int h = l.out_h; + int w = l.out_w; + int c = l.c; + return float_to_image(w,h,c,l.delta); +} + +maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding) +{ + maxpool_layer l = {0}; + l.type = MAXPOOL; + l.batch = batch; + l.h = h; + l.w = w; + l.c = c; + l.pad = padding; + l.out_w = (w + padding - size)/stride + 1; + l.out_h = (h + padding - size)/stride + 1; + l.out_c = c; + l.outputs = l.out_h * l.out_w * l.out_c; + l.inputs = h*w*c; + l.size = size; + l.stride = stride; + int output_size = l.out_h * l.out_w * l.out_c * batch; + l.indexes = calloc(output_size, sizeof(int)); + l.output = calloc(output_size, sizeof(float)); + l.delta = calloc(output_size, sizeof(float)); + l.forward = forward_maxpool_layer; + l.backward = backward_maxpool_layer; + #ifdef GPU + l.forward_gpu = forward_maxpool_layer_gpu; + l.backward_gpu = backward_maxpool_layer_gpu; + l.indexes_gpu = cuda_make_int_array(0, output_size); + l.output_gpu = cuda_make_array(l.output, output_size); + l.delta_gpu = cuda_make_array(l.delta, output_size); + #endif + fprintf(stderr, "max %d x %d / %d %4d x%4d x%4d -> %4d x%4d x%4d\n", size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c); + return l; +} + +void resize_maxpool_layer(maxpool_layer *l, int w, int h) +{ + l->h = h; + l->w = w; + l->inputs = h*w*l->c; + + l->out_w = (w + l->pad - l->size)/l->stride + 1; + l->out_h = (h + l->pad - l->size)/l->stride + 1; + l->outputs = l->out_w * l->out_h * l->c; + int output_size = l->outputs * l->batch; + + l->indexes = realloc(l->indexes, output_size * sizeof(int)); + l->output = realloc(l->output, output_size * sizeof(float)); + l->delta = realloc(l->delta, output_size * sizeof(float)); + + #ifdef GPU + cuda_free((float *)l->indexes_gpu); + cuda_free(l->output_gpu); + cuda_free(l->delta_gpu); + l->indexes_gpu = cuda_make_int_array(0, output_size); + l->output_gpu = cuda_make_array(l->output, output_size); + l->delta_gpu = cuda_make_array(l->delta, output_size); + #endif +} + +void forward_maxpool_layer(const maxpool_layer l, network net) +{ + int b,i,j,k,m,n; + int w_offset = -l.pad/2; + int h_offset = -l.pad/2; + + int h = l.out_h; + int w = l.out_w; + int c = l.c; + + for(b = 0; b < l.batch; ++b){ + for(k = 0; k < c; ++k){ + for(i = 0; i < h; ++i){ + for(j = 0; j < w; ++j){ + int out_index = j + w*(i + h*(k + c*b)); + float max = -FLT_MAX; + int max_i = -1; + for(n = 0; n < l.size; ++n){ + for(m = 0; m < l.size; ++m){ + int cur_h = h_offset + i*l.stride + n; + int cur_w = w_offset + j*l.stride + m; + int index = cur_w + l.w*(cur_h + l.h*(k + b*l.c)); + int valid = (cur_h >= 0 && cur_h < l.h && + cur_w >= 0 && cur_w < l.w); + float val = (valid != 0) ? net.input[index] : -FLT_MAX; + max_i = (val > max) ? index : max_i; + max = (val > max) ? val : max; + } + } + l.output[out_index] = max; + l.indexes[out_index] = max_i; + } + } + } + } +} + +void backward_maxpool_layer(const maxpool_layer l, network net) +{ + int i; + int h = l.out_h; + int w = l.out_w; + int c = l.c; + for(i = 0; i < h*w*c*l.batch; ++i){ + int index = l.indexes[i]; + net.delta[index] += l.delta[i]; + } +} + +#ifdef ALLEN_MODIFIED +maxpool_layer make_maxpool_layer_mem(int batch, int h, int w, int c, int size, int stride, int padding) +{ + maxpool_layer l = { 0 }; + l.type = MAXPOOL; + l.batch = batch; + l.h = h; + l.w = w; + l.c = c; + l.pad = padding; + l.out_w = (w + padding - size) / stride + 1; + l.out_h = (h + padding - size) / stride + 1; + l.out_c = c; + l.outputs = l.out_h * l.out_w * l.out_c; + l.inputs = h * w*c; + l.size = size; + l.stride = stride; + int output_size = l.out_h * l.out_w * l.out_c * batch; + l.indexes = calloc(output_size, sizeof(int)); + l.output = calloc(output_size, sizeof(float)); + l.delta = calloc(output_size, sizeof(float)); + l.forward = forward_maxpool_layer; + l.backward = backward_maxpool_layer; +#ifdef GPU + l.forward_gpu = forward_maxpool_layer_gpu; + l.backward_gpu = backward_maxpool_layer_gpu; + l.indexes_gpu = cuda_make_int_array(output_size); + l.output_gpu = cuda_make_array(l.output, output_size); + l.delta_gpu = cuda_make_array(l.delta, output_size); +#endif + l.bflops = (l.size*l.size*l.c * l.out_h*l.out_w) / 1000000000.; + //fprintf(stderr, "max %d x %d / %d %4d x%4d x%4d -> %4d x%4d x%4d %5.3f BF\n", size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c, l.bflops); + return l; +} +#endif \ No newline at end of file diff --git a/src/maxpool_layer.h b/src/maxpool_layer.h new file mode 100644 index 0000000..73fe40c --- /dev/null +++ b/src/maxpool_layer.h @@ -0,0 +1,28 @@ +#pragma once +#ifndef MAXPOOL_LAYER_H +#define MAXPOOL_LAYER_H +#include "define_inc.h" +#include "image.h" +#include "cuda.h" +#include "layer.h" +#include "network.h" +#include "option_list.h" + +typedef layer maxpool_layer; + +image get_maxpool_image(maxpool_layer l); +maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding); +#ifdef ALLEN_MODIFIED +maxpool_layer make_maxpool_layer_mem(int batch, int h, int w, int c, int size, int stride, int padding); +#endif +void resize_maxpool_layer(maxpool_layer *l, int w, int h); +void forward_maxpool_layer(const maxpool_layer l, network net); +void backward_maxpool_layer(const maxpool_layer l, network net); + +#ifdef GPU +void forward_maxpool_layer_gpu(maxpool_layer l, network net); +void backward_maxpool_layer_gpu(maxpool_layer l, network net); +#endif + +#endif + diff --git a/src/maxpool_layer_kernels.cu b/src/maxpool_layer_kernels.cu new file mode 100644 index 0000000..869ef46 --- /dev/null +++ b/src/maxpool_layer_kernels.cu @@ -0,0 +1,106 @@ +#include "cuda_runtime.h" +#include "curand.h" +#include "cublas_v2.h" + +extern "C" { +#include "maxpool_layer.h" +#include "cuda.h" +} + +__global__ void forward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *input, float *output, int *indexes) +{ + int h = (in_h + pad - size)/stride + 1; + int w = (in_w + pad - size)/stride + 1; + int c = in_c; + + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= n) return; + + int j = id % w; + id /= w; + int i = id % h; + id /= h; + int k = id % c; + id /= c; + int b = id; + + int w_offset = -pad/2; + int h_offset = -pad/2; + + int out_index = j + w*(i + h*(k + c*b)); + float max = -INFINITY; + int max_i = -1; + int l, m; + for(l = 0; l < size; ++l){ + for(m = 0; m < size; ++m){ + int cur_h = h_offset + i*stride + l; + int cur_w = w_offset + j*stride + m; + int index = cur_w + in_w*(cur_h + in_h*(k + b*in_c)); + int valid = (cur_h >= 0 && cur_h < in_h && + cur_w >= 0 && cur_w < in_w); + float val = (valid != 0) ? input[index] : -INFINITY; + max_i = (val > max) ? index : max_i; + max = (val > max) ? val : max; + } + } + output[out_index] = max; + indexes[out_index] = max_i; +} + +__global__ void backward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *delta, float *prev_delta, int *indexes) +{ + int h = (in_h + pad - size)/stride + 1; + int w = (in_w + pad - size)/stride + 1; + int c = in_c; + int area = (size-1)/stride; + + int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; + if(id >= n) return; + + int index = id; + int j = id % in_w; + id /= in_w; + int i = id % in_h; + id /= in_h; + int k = id % in_c; + id /= in_c; + int b = id; + + int w_offset = -pad/2; + int h_offset = -pad/2; + + float d = 0; + int l, m; + for(l = -area; l < area+1; ++l){ + for(m = -area; m < area+1; ++m){ + int out_w = (j-w_offset)/stride + m; + int out_h = (i-h_offset)/stride + l; + int out_index = out_w + w*(out_h + h*(k + c*b)); + int valid = (out_w >= 0 && out_w < w && + out_h >= 0 && out_h < h); + d += (valid && indexes[out_index] == index) ? delta[out_index] : 0; + } + } + prev_delta[index] += d; +} + +extern "C" void forward_maxpool_layer_gpu(maxpool_layer layer, network net) +{ + int h = layer.out_h; + int w = layer.out_w; + int c = layer.c; + + size_t n = h*w*c*layer.batch; + + forward_maxpool_layer_kernel<<<cuda_gridsize(n), BLOCK>>>(n, layer.h, layer.w, layer.c, layer.stride, layer.size, layer.pad, net.input_gpu, layer.output_gpu, layer.indexes_gpu); + check_error(cudaPeekAtLastError()); +} + +extern "C" void backward_maxpool_layer_gpu(maxpool_layer layer, network net) +{ + size_t n = layer.h*layer.w*layer.c*layer.batch; + + backward_maxpool_layer_kernel<<<cuda_gridsize(n), BLOCK>>>(n, layer.h, layer.w, layer.c, layer.stride, layer.size, layer.pad, layer.delta_gpu, net.delta_gpu, layer.indexes_gpu); + check_error(cudaPeekAtLastError()); +} + diff --git a/src/md5.c b/src/md5.c new file mode 100644 index 0000000..9b50ca6 --- /dev/null +++ b/src/md5.c @@ -0,0 +1,256 @@ +/* + * Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm + * and modified slightly to be functionally identical but condensed into control structures. + */ + +#include "md5.h" + +/* + * Constants defined by the MD5 algorithm + */ +#define A 0x67452301 +#define B 0xefcdab89 +#define C 0x98badcfe +#define D 0x10325476 + +static uint32_t S[] = {7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, + 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, + 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, + 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21}; + +static uint32_t K[] = {0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}; + +/* + * Padding used to make the size (in bits) of the input congruent to 448 mod 512 + */ +static uint8_t PADDING[] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +/* + * Initialize a context + */ +void md5Init(MD5Context *ctx){ + ctx->size = (uint64_t)0; + + ctx->buffer[0] = (uint32_t)A; + ctx->buffer[1] = (uint32_t)B; + ctx->buffer[2] = (uint32_t)C; + ctx->buffer[3] = (uint32_t)D; +} + +/* + * Add some amount of input to the context + * + * If the input fills out a block of 512 bits, apply the algorithm (md5Step) + * and save the result in the buffer. Also updates the overall size. + */ + +void md5Update(MD5Context *ctx, uint8_t *input_buffer, size_t input_len){ + uint32_t input[16]; + unsigned int offset = ctx->size % 64; + ctx->size += (uint64_t)input_len; + + // Copy each byte in input_buffer into the next space in our context input + for(unsigned int i = 0; i < input_len; ++i){ + ctx->input[offset++] = (uint8_t)*(input_buffer + i); + + // If we've filled our context input, copy it into our local array input + // then reset the offset to 0 and fill in a new buffer + // The local array input is a list of 16 32-bit words for use in the algorithm + if(offset % 64 == 0){ + for(unsigned int j = 0; j < 16; ++j){ + // Convert to little-endian + input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 | + (uint32_t)(ctx->input[(j * 4) + 2]) << 16 | + (uint32_t)(ctx->input[(j * 4) + 1]) << 8 | + (uint32_t)(ctx->input[(j * 4)]); + } + md5Step(ctx->buffer, input); + offset = 0; + } + } +} + +/* + * Pad the current input to get to 448 bytes, append the size in bits to the very end, + * and save the result of the final iteration into digest. + */ +void md5Finalize(MD5Context *ctx){ + uint32_t input[16]; + unsigned int offset = ctx->size % 64; + unsigned int padding_length = offset < 56 ? 56 - offset : (56 + 64) - offset; + + // Fill in the padding andndo the changes to size that resulted from the update + md5Update(ctx, PADDING, padding_length); + ctx->size -= (uint64_t)padding_length; + + // Do a final update (internal to this function) + // Last two 32-bit words are the two halves of the size (converted from bytes to bits) + for(unsigned int j = 0; j < 14; ++j){ + input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 | + (uint32_t)(ctx->input[(j * 4) + 2]) << 16 | + (uint32_t)(ctx->input[(j * 4) + 1]) << 8 | + (uint32_t)(ctx->input[(j * 4)]); + } + input[14] = (uint32_t)(ctx->size * 8); + input[15] = (uint32_t)((ctx->size * 8) >> 32); + + md5Step(ctx->buffer, input); + + // Move the result into digest + // (Convert from little-endian) + for(unsigned int i = 0; i < 4; ++i){ + ctx->digest[(i * 4) + 0] = (uint8_t)((ctx->buffer[i] & 0x000000FF)); + ctx->digest[(i * 4) + 1] = (uint8_t)((ctx->buffer[i] & 0x0000FF00) >> 8); + ctx->digest[(i * 4) + 2] = (uint8_t)((ctx->buffer[i] & 0x00FF0000) >> 16); + ctx->digest[(i * 4) + 3] = (uint8_t)((ctx->buffer[i] & 0xFF000000) >> 24); + } +} + +/* + * Step on 512 bits of input with the main MD5 algorithm. + */ +void md5Step(uint32_t *buffer, uint32_t *input){ + uint32_t AA = buffer[0]; + uint32_t BB = buffer[1]; + uint32_t CC = buffer[2]; + uint32_t DD = buffer[3]; + + uint32_t E; + + unsigned int j; + + for(unsigned int i = 0; i < 64; ++i){ + switch(i / 16){ + case 0: + E = F(BB, CC, DD); + j = i; + break; + case 1: + E = G(BB, CC, DD); + j = ((i * 5) + 1) % 16; + break; + case 2: + E = H(BB, CC, DD); + j = ((i * 3) + 5) % 16; + break; + default: + E = I(BB, CC, DD); + j = (i * 7) % 16; + break; + } + + uint32_t temp = DD; + DD = CC; + CC = BB; + BB = BB + rotate_left(AA + E + K[i] + input[j], S[i]); + AA = temp; + } + + buffer[0] += AA; + buffer[1] += BB; + buffer[2] += CC; + buffer[3] += DD; +} + +/* + * Functions that will return a pointer to the hash of the provided input + */ +void md5String(char *input, uint8_t* output) { + MD5Context ctx; + md5Init(&ctx); + md5Update(&ctx, (uint8_t *)input, strlen(input)); + md5Finalize(&ctx); + + //uint8_t *result = malloc(16); + memcpy(output, ctx.digest, 16); + //return result; +} + +uint8_t* md5File(FILE *file){ + char *input_buffer = malloc(1024); + size_t input_size = 0; + + MD5Context ctx; + md5Init(&ctx); + + while((input_size = fread(input_buffer, 1, 1024, file)) > 0){ + md5Update(&ctx, (uint8_t *)input_buffer, input_size); + } + + md5Finalize(&ctx); + + free(input_buffer); + + uint8_t *result = malloc(16); + memcpy(result, ctx.digest, 16); + return result; +} + +/* + * Bit-manipulation functions defined by the MD5 algorithm + */ +uint32_t F(uint32_t X, uint32_t Y, uint32_t Z){ + return (X & Y) | (~X & Z); +} + +uint32_t G(uint32_t X, uint32_t Y, uint32_t Z){ + return (X & Z) | (Y & ~Z); +} + +uint32_t H(uint32_t X, uint32_t Y, uint32_t Z){ + return X ^ Y ^ Z; +} + +uint32_t I(uint32_t X, uint32_t Y, uint32_t Z){ + return Y ^ (X | ~Z); +} + +/* + * Rotates a 32-bit word left by n bits + */ +uint32_t rotate_left(uint32_t x, uint32_t n){ + return (x << n) | (x >> (32 - n)); +} + +/* + * Printing bytes from buffers or the hash + */ +void print_bytes(void *p, size_t length){ + uint8_t *pp = (uint8_t *)p; + for(unsigned int i = 0; i < length; ++i){ + if(i && !(i % 16)){ + printf("\n"); + } + printf("%02X ", pp[i]); + } + printf("\n"); +} + +void print_hash(uint8_t *p){ + for(unsigned int i = 0; i < 16; ++i){ + printf("%02x", p[i]); + } + printf("\n"); +} diff --git a/src/md5.h b/src/md5.h new file mode 100644 index 0000000..68c6663 --- /dev/null +++ b/src/md5.h @@ -0,0 +1,35 @@ +#pragma once +#ifndef MD5_H +#define MD5_H +#include "define_inc.h" +#include <stdio.h> +#include <stdint.h> +#include <string.h> +#include <stdlib.h> + +typedef struct{ + uint64_t size; // Size of input in bytes + uint32_t buffer[4]; // Current accumulation of hash + uint8_t input[64]; // Input to be used in the next step + uint8_t digest[16]; // Result of algorithm +}MD5Context; + +void md5Init(MD5Context *ctx); +void md5Update(MD5Context *ctx, uint8_t *input, size_t input_len); +void md5Finalize(MD5Context *ctx); +void md5Step(uint32_t *buffer, uint32_t *input); + +void md5String(char *input, uint8_t* output); +uint8_t* md5File(FILE *file); + +uint32_t F(uint32_t X, uint32_t Y, uint32_t Z); +uint32_t G(uint32_t X, uint32_t Y, uint32_t Z); +uint32_t H(uint32_t X, uint32_t Y, uint32_t Z); +uint32_t I(uint32_t X, uint32_t Y, uint32_t Z); + +uint32_t rotate_left(uint32_t x, uint32_t n); + +void print_bytes(void *p, size_t length); +void print_hash(uint8_t *p); + +#endif \ No newline at end of file diff --git a/src/md5_f.c b/src/md5_f.c new file mode 100644 index 0000000..1f8f657 --- /dev/null +++ b/src/md5_f.c @@ -0,0 +1,325 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "md5_f.h" +//================================= file,h ================================= +typedef struct +{ + unsigned int count[2]; + unsigned int state[4]; + unsigned char buffer[64]; +}MD5_CTX; + + +#define F(x,y,z) ((x & y) | (~x & z)) +#define G(x,y,z) ((x & z) | (y & ~z)) +#define H(x,y,z) (x^y^z) +#define I(x,y,z) (y ^ (x | ~z)) +#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) +#define FF(a,b,c,d,x,s,ac) \ + { \ + a += F(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ + } +#define GG(a,b,c,d,x,s,ac) \ + { \ + a += G(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ + } +#define HH(a,b,c,d,x,s,ac) \ + { \ + a += H(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ + } +#define II(a,b,c,d,x,s,ac) \ + { \ + a += I(b,c,d) + x + ac; \ + a = ROTATE_LEFT(a,s); \ + a += b; \ + } +void MD5Init(MD5_CTX *context); +void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen); +void MD5Final(MD5_CTX *context,unsigned char digest[16]); +void MD5Transform(unsigned int state[4],unsigned char block[64]); +void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len); +void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len); + +unsigned char PADDING[]={0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + +//================================= file,h ================================= + +//================================= function ================================= +void MD5Init(MD5_CTX *context) +{ + context->count[0] = 0; + context->count[1] = 0; + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; +} +void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen) +{ + unsigned int i = 0,index = 0,partlen = 0; + index = (context->count[0] >> 3) & 0x3F; + partlen = 64 - index; + context->count[0] += inputlen << 3; + if(context->count[0] < (inputlen << 3)) + context->count[1]++; + context->count[1] += inputlen >> 29; + + if(inputlen >= partlen) + { + memcpy(&context->buffer[index],input,partlen); + MD5Transform(context->state,context->buffer); + for(i = partlen;i+64 <= inputlen;i+=64) + MD5Transform(context->state,&input[i]); + index = 0; + } + else + { + i = 0; + } + memcpy(&context->buffer[index],&input[i],inputlen-i); +} +void MD5Final(MD5_CTX *context,unsigned char digest[16]) +{ + unsigned int index = 0,padlen = 0; + unsigned char bits[8]; + index = (context->count[0] >> 3) & 0x3F; + padlen = (index < 56)?(56-index):(120-index); + MD5Encode(bits,context->count,8); + MD5Update(context,PADDING,padlen); + MD5Update(context,bits,8); + MD5Encode(digest,context->state,16); +} +void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) +{ + unsigned int i = 0,j = 0; + while(j < len) + { + output[j] = input[i] & 0xFF; + output[j+1] = (input[i] >> 8) & 0xFF; + output[j+2] = (input[i] >> 16) & 0xFF; + output[j+3] = (input[i] >> 24) & 0xFF; + i++; + j+=4; + } +} +void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len) +{ + unsigned int i = 0,j = 0; + while(j < len) + { + output[i] = (input[j]) | + (input[j+1] << 8) | + (input[j+2] << 16) | + (input[j+3] << 24); + i++; + j+=4; + } +} +void MD5Transform(unsigned int state[4],unsigned char block[64]) +{ + unsigned int a = state[0]; + unsigned int b = state[1]; + unsigned int c = state[2]; + unsigned int d = state[3]; + unsigned int x[64]; + MD5Decode(x,block,64); + FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */ + FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */ + FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */ + FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */ + FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */ + FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */ + FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */ + FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */ + FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */ + FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */ + FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */ + FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */ + FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */ + FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */ + FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */ + FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */ + GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */ + GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */ + GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */ + GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */ + GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */ + GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */ + GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */ + GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */ + GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */ + GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */ + GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */ + GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */ + GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */ + GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */ + GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */ + HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */ + HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */ + HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */ + HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */ + HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */ + HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */ + HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */ + HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */ + HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */ + HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */ + HH(b, c, d, a, x[ 6], 23, 0x4881d05); /* 44 */ + HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */ + HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */ + HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */ + HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */ + II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */ + II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */ + II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */ + II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */ + II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */ + II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */ + II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */ + II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */ + II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */ + II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */ + II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */ + II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */ + II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */ + II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */ + II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} +//================================= function ================================= + +//================================= extern ================================= +void DoMD5(unsigned char *in ,unsigned char *out) +{ + MD5_CTX md5; + MD5Init(&md5); + MD5Update(&md5,in,strlen((char *)in)); + MD5Final(&md5,out); +} + +void DoDigestUserhash( const char *username, const char *realm, char *response ) +{ + unsigned char A1[16] = {0}; + unsigned char str[ MAX_MD5_BUF_LEN ] = {0}; + + sprintf((char *)str, "%s:%s", username, realm); + DoMD5( str, A1 ); + sprintf((char *)response, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + ,A1[ 0],A1[ 1],A1[ 2],A1[ 3],A1[ 4],A1[ 5],A1[ 6],A1[ 7] + ,A1[ 8],A1[ 9],A1[10],A1[11],A1[12],A1[13],A1[14],A1[15] ); +} + +int DoDigestResponse( const char *username, const char *realm, const char *password, const char *method, const char *uri, const char *nonce, char *response ) +{ + unsigned char A1[16] = {0}; + unsigned char A2[16] = {0}; + unsigned char ANS[16] = {0}; + unsigned char str[ MAX_MD5_BUF_LEN ] = {0}; + + //memset( str, 0, MAX_MD5_BUF_LEN ); + sprintf((char *)str, "%s:%s:%s", username, realm, password); + DoMD5( str, A1 ); + + //memset( str, 0, MAX_MD5_BUF_LEN ); + snprintf((char *)str, MAX_MD5_BUF_LEN, "%s:%s", method, uri); + DoMD5( str, A2 ); + + //memset( str, 0, MAX_MD5_BUF_LEN); + snprintf((char *)str, MAX_MD5_BUF_LEN, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + ":" + "%s" + ":" + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + ,A1[ 0],A1[ 1],A1[ 2],A1[ 3],A1[ 4],A1[ 5],A1[ 6],A1[ 7] + ,A1[ 8],A1[ 9],A1[10],A1[11],A1[12],A1[13],A1[14],A1[15] + ,nonce + ,A2[ 0],A2[ 1],A2[ 2],A2[ 3],A2[ 4],A2[ 5],A2[ 6],A2[ 7] + ,A2[ 8],A2[ 9],A2[10],A2[11],A2[12],A2[13],A2[14],A2[15] ); + DoMD5( str, ANS ); + + sprintf((char *)response, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + ,ANS[ 0],ANS[ 1],ANS[ 2],ANS[ 3],ANS[ 4],ANS[ 5],ANS[ 6],ANS[ 7] + ,ANS[ 8],ANS[ 9],ANS[10],ANS[11],ANS[12],ANS[13],ANS[14],ANS[15] ); + + return 0; +} + +/* +realm, nonce, uri,qop : provided by ip cam +cnonce : a client ramdon string is defined by user +nc : nonce count define to 00000001 +responce : md5 result + +[Test case] +username="admin" +realm="AXIS_WS_00408C940F7F" +nonce="00002519Y133420c5abff33aba54b089560776d2ef567b" +uri="/onvif-cgi/jpg/image.cgi" +cnonce="5686cd1776c590c35b90fac63835bb95" +nc=00000001 +qop="auth" +response="d7cd8f19ff448d0e395b97b7c39d2556" + +*/ +int DoQOPDigestResponse(const char *username ,const char * password, const char * realm, const char * uri, const char *method,const char * nonce,char * response) +{ + unsigned char A1[16] = {0}; + unsigned char A2[16] = {0}; + unsigned char ANS[16] = {0}; + unsigned char str[ MAX_MD5_BUF_LEN ] = {0}; + + //memset( str, 0, MAX_MD5_BUF_LEN ); + sprintf((char *)str, "%s:%s:%s", username, realm, password); + DoMD5( str, A1 ); + + //memset( str, 0, MAX_MD5_BUF_LEN ); + snprintf((char *)str, MAX_MD5_BUF_LEN, "%s:%s", method, uri); + DoMD5( str, A2 ); + + //memset( str ,0 , MAX_MD5_BUF_LEN ); + + sprintf((char *)str, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x:%s:%s:%s" + ":auth:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + ,A1[0],A1[1],A1[ 2],A1[ 3],A1[ 4],A1[ 5],A1[ 6],A1[ 7] + ,A1[8],A1[9],A1[10],A1[11],A1[12],A1[13],A1[14],A1[15] + ,nonce,NC,CNONCE // MAX_REALM_LEN(128), 8, 32 + ,A2[0],A2[1],A2[ 2],A2[ 3],A2[ 4],A2[ 5],A2[ 6],A2[ 7] + ,A2[8],A2[9],A2[10],A2[11],A2[12],A2[13],A2[14],A2[15] ); + DoMD5( str, ANS ); + + // HA1:nonce:nonceCount:ClientNonce:qop:HA2 + + + sprintf((char *)response, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + ,ANS[0],ANS[1],ANS[ 2],ANS[ 3],ANS[ 4],ANS[ 5],ANS[ 6],ANS[ 7] + ,ANS[8],ANS[9],ANS[10],ANS[11],ANS[12],ANS[13],ANS[14],ANS[15] ); + + return 0; +} diff --git a/src/md5_f.h b/src/md5_f.h new file mode 100644 index 0000000..f6ad278 --- /dev/null +++ b/src/md5_f.h @@ -0,0 +1,25 @@ +#pragma once +#ifndef _md5_h_ +#define _md5_h_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" +#define NC "00000001" +#define NONCE "00002519Y133420c5abff33aba54b089560776d2ef567b" +#define CNONCE "5686cd1776c590c35b90fac63835bb95" +#define MD5_RESP_LEN (33) //32 + 1('\0') +#define MAX_MD5_BUF_LEN (2048) // refer to uri (like server_file(2048) in httpc_client) + +void DoMD5(unsigned char *in ,unsigned char *out); +void DoDigestUserhash( const char *username, const char *realm, char *response ); +int DoDigestResponse( const char *username, const char *realm, const char *password, const char *method, const char *uri, const char *nonce, char *response ); +//QOP "quality of protection" +int DoQOPDigestResponse(const char *username ,const char * password, const char * realm, const char * uri, const char *method,const char * nonce,char * response); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/net_curl.c b/src/net_curl.c new file mode 100644 index 0000000..fa3c2c9 --- /dev/null +++ b/src/net_curl.c @@ -0,0 +1,951 @@ + +#include "net_curl.h" + +//#include "base64_util.h" +//#include "common_function.h" + +static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp) +{ + //samlpe of https://curl.haxx.se/libcurl/c/getinmemory.html + size_t realsize = size * nmemb; + struct memory_data_s *mem = (struct memory_data_s *)userp; + int l_ret = 0; + + /* + char *l_ptr = (char *)realloc(mem->memory, mem->size + realsize + 1); + + if (l_ptr == NULL) + { + printf("not enough memory (realloc returned NULL)\n"); + return 0; + } + + mem->memory = l_ptr;*/ + + memcpy(&(mem->memory[mem->size]), contents, realsize); + + mem->size += realsize; + mem->memory[mem->size] = 0; + + l_ret = realsize; + + return l_ret; +} + +int net_curl_http_get_stream(const char *path, int auth, + const char *user, const char *passwd, write_memory_callback_fun callback_fun, void *callback_data) +{ + + //CURL *l_curl = NULL; + CURLcode l_res; + int l_ret = -1; + + if (path == NULL) return -1; + + pthread_mutex_lock(&mutex_curl); + //l_curl = curl_easy_init(); + if (g_http_handle) + { + //open debug message + //curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_URL, path); + if (auth) + { + curl_easy_setopt(g_http_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, user); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, passwd); + } + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, callback_fun); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, callback_data); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 16L); + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); + + //curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 10L); + + l_res = curl_easy_perform(g_http_handle); + if (l_res == CURLE_OK) + { + l_ret = 0; + } + else + { + l_ret = -1; + } + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + return l_ret; +} + +int net_curl_http_get(const char *path, int auth, + const char *user, const char *passwd, int wtimeout, char *data_buf, int buffer_size) +{ + + //CURL *l_curl = NULL; + CURLcode l_res; + struct memory_data_s l_http_chunk; + int l_http_get_timeout = wtimeout; + int l_ret = -1; + + if (path == NULL) return -1; + pthread_mutex_lock(&mutex_curl); + //l_curl = curl_easy_init(); + if (g_http_handle) + { + /* + do + { + l_http_chunk.memory = (char *)calloc(1, sizeof(char)); + } while (l_http_chunk.memory == NULL);*/ + + memset(l_http_chunk.memory,0x00, MAX_MEMORY_SIZE_V); + l_http_chunk.size = 0; + + curl_easy_setopt(g_http_handle, CURLOPT_URL, path); + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, l_http_get_timeout); + if (auth) + { + curl_easy_setopt(g_http_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, user); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, passwd); + } + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, write_memory_callback); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, (void *)&l_http_chunk); + + //2019-06-04, Ming, set timeout for limit usage time of sending E-Mail + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 60L); + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 10L); + + l_res = curl_easy_perform(g_http_handle); + if (l_res == CURLE_OK) + { + if (data_buf && buffer_size > 0) + { + l_ret = MIN(l_http_chunk.size, (size_t)buffer_size); + memcpy(data_buf, l_http_chunk.memory, l_ret); + } + l_ret = 0; + } + else + { + snprintf(data_buf, sizeof(buffer_size), "%s", curl_easy_strerror(l_res)); + l_ret = -1; + } + curl_easy_reset(g_http_handle); + + /* + if (l_http_chunk.memory != NULL) + { + free(l_http_chunk.memory); + l_http_chunk.memory = NULL; + }*/ + } + pthread_mutex_unlock(&mutex_curl); + return l_ret; +} + +int net_curl_https_get(const char *path, int auth, + const char *user, const char *passwd, char *data_buf, int buffer_size) +{ + + //CURL *l_curl = NULL; + CURLcode l_res; + struct memory_data_s l_http_chunk; + int l_http_get_timeout = 30; + int l_ret = -1; + + if (path == NULL) return -1; + pthread_mutex_lock(&mutex_curl); + //l_curl = curl_easy_init(); + if (g_http_handle) + { + /* + do + { + l_http_chunk.memory = (char *)calloc(1, sizeof(char)); + } while (l_http_chunk.memory == NULL);*/ + + memset(l_http_chunk.memory, 0x00, MAX_MEMORY_SIZE_V); + l_http_chunk.size = 0; + + curl_easy_setopt(g_http_handle, CURLOPT_URL, path); + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, l_http_get_timeout); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0); + if (auth) + { + curl_easy_setopt(g_http_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, user); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, passwd); + } + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, write_memory_callback); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, (void *)&l_http_chunk); + + //2019-06-04, Ming, set timeout for limit usage time of sending E-Mail + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 60L); + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 10L); + + l_res = curl_easy_perform(g_http_handle); + if (l_res == CURLE_OK) + { + if (data_buf && buffer_size > 0) + { + l_ret = MIN(l_http_chunk.size, (size_t)buffer_size); + memcpy(data_buf, l_http_chunk.memory, l_ret); + } + l_ret = 0; + } + else + { + snprintf(data_buf, sizeof(buffer_size), "%s", curl_easy_strerror(l_res)); + l_ret = -1; + } + curl_easy_reset(g_http_handle); + + /* + if (l_http_chunk.memory != NULL) + { + free(l_http_chunk.memory); + l_http_chunk.memory = NULL; + }*/ + } + pthread_mutex_unlock(&mutex_curl); + return l_ret; +} + +#if 0 +static size_t ftp_read_memory_callback(void *ptr, size_t size, size_t nmemb, void *pMem) +{ + struct memory_data_s *wt = (struct memory_data_s *)pMem; + size_t buffer_size = size * nmemb; + + if (wt->size) + { + /* copy as much as possible from the source to the destination */ + size_t copy_this_much = wt->size; + if (copy_this_much > buffer_size) + copy_this_much = buffer_size; + memcpy(ptr, wt->memory, copy_this_much); + + wt->memory += copy_this_much; + wt->size -= copy_this_much; + return copy_this_much; /* we copied this many bytes */ + } + + return 0; /* no more data left to deliver */ +} +#endif +#if 0 +int net_curl_ftp_one_file(curl_information_ftp_t *user_ftp) +{ + + int l_result = -1; + //CURL *curl; + CURLcode res; + + if (user_ftp == NULL) return -1; + pthread_mutex_lock(&mutex_curl); + + //curl = curl_easy_init(); + if (g_http_handle) + { + curl_easy_setopt(g_http_handle, CURLOPT_URL, user_ftp->url); //sample "ftp://ip:port/abc/def/123.jpg" + curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_READFUNCTION, ftp_read_memory_callback); + curl_easy_setopt(g_http_handle, CURLOPT_READDATA, (void *)&user_ftp->memory_data.memory); + curl_easy_setopt(g_http_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)user_ftp->memory_data.size); + + //open debug message + //curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, user_ftp->user); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, user_ftp->password); + + //2019-06-04, Ming, set timeout for limit usage time of sending E-Mail + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10L); + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5L); + + res = curl_easy_perform(g_http_handle); + if (res == CURLE_REMOTE_ACCESS_DENIED) + { + struct curl_slist *h = NULL; + char cmd[256] = { 0 }; + snprintf(cmd, sizeof(cmd), "MKD %s", user_ftp->file_path); + h = curl_slist_append(h, cmd); + + curl_easy_setopt(g_http_handle, CURLOPT_QUOTE, h); + res = curl_easy_perform(g_http_handle); + } + + if (res != CURLE_OK) + { + printf("net_curl_ftp_one_file curl_easy_perform() failed[%d]: %s\n", res, curl_easy_strerror(res)); + l_result = -1; + } + else + { + double speed_upload, total_time; + curl_easy_getinfo(g_http_handle, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(g_http_handle, CURLINFO_TOTAL_TIME, &total_time); + + l_result = 0; + + //printf("speed_upload %f\n",speed_upload); + //printf("total_time %f\n",total_time); + } + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + return l_result; +} +#endif +int net_curl_http_post_data(curl_information_http_post_t *user_http_post) +{ + + + int l_result = -1; + //CURL *curl; + CURLcode res; + + if (user_http_post == NULL) return -1; + pthread_mutex_lock(&mutex_curl); + //curl = curl_easy_init(); + if (g_http_handle) + { + //open debug message + //curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 1L); + + struct curl_slist *l_headerlist = NULL; + + curl_easy_setopt(g_http_handle, CURLOPT_HEADER, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_URL, user_http_post->url); + curl_easy_setopt(g_http_handle, CURLOPT_POST, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_CUSTOMREQUEST, "POST"); + + if ((user_http_post->user != NULL) && (user_http_post->password != NULL)) + { +#if 0 + curl_easy_setopt(g_http_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, user_http_post->user); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, user_http_post->password); +#else + char l_userpwd[256] = { 0 }; + char l_userpwd_b64[256] = { 0 }; + size_t base64_decode_length = 0; + char l_userpwd_send[512] = { 0 }; + snprintf(l_userpwd, sizeof(l_userpwd), "%s:%s", user_http_post->user, user_http_post->password); + base64_decode(l_userpwd, strlen(l_userpwd), &base64_decode_length, (unsigned char*)l_userpwd_b64); + snprintf(l_userpwd_send, sizeof(l_userpwd_send), "Authorization: Basic %s", l_userpwd_b64); + l_headerlist = curl_slist_append(l_headerlist, l_userpwd_send); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, l_headerlist); + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST | CURLAUTH_BASIC); + curl_easy_setopt(g_http_handle, CURLOPT_USERPWD, l_userpwd); +#endif + //curl_easy_setopt(g_http_handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE); + // + // + } + printf("net_curl_http_post_data: data%s, size:%lu\n", user_http_post->memory_data.memory, + (unsigned long)user_http_post->memory_data.size); + // user_http_post->memory_data.size = 0; + if (user_http_post->memory_data.size > 0) + { + curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, (long)user_http_post->memory_data.size); + curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, user_http_post->memory_data.memory); + } + + //2019-06-04, Ming, set timeout for limit usage time of sending E-Mail + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10L); + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5L); + + res = curl_easy_perform(g_http_handle); + if (res != CURLE_OK) + { + printf("net_curl_http_post_data curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + l_result = -1; + } + else + { + double speed_upload, total_time; + curl_easy_getinfo(g_http_handle, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(g_http_handle, CURLINFO_TOTAL_TIME, &total_time); + //printf("speed_upload %f\n",speed_upload); + //printf("total_time %f\n",total_time); + l_result = 0; + } + + curl_easy_reset(g_http_handle); + curl_slist_free_all(l_headerlist); + } + + pthread_mutex_unlock(&mutex_curl); + + return l_result; +} + +const char g_payload_template[] = +"Date: %s\r\n" +"To: %s\r\n" +"From: %s\r\n" +"Message-ID: <%s@example.com>\r\n" +"Subject: %s\r\n" +"\r\n" +"%s\r\n\r\n"; + +struct upload_status +{ + char readptr[MAX_IMG_SIZE]; + size_t sizeleft; +}; + +static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct upload_status *upload_ctx = (struct upload_status *)userp; + //const char *data; + + + // read 65536 bytes/cycle. + + size_t bytes_to_copy = upload_ctx->sizeleft < size * nmemb ? upload_ctx->sizeleft : size * nmemb; + //bytes_to_copy = upload_ctx->sizeleft < 10 ? upload_ctx->sizeleft : 10; + // size_t bytes_to_copy = upload_ctx->sizeleft; + + if (size * nmemb < 1) + return 0; + + if (upload_ctx->sizeleft) + { + //printf("payload_source #1: size=%d, nmemb=%d, upload_ctx->sizeleft=%d\n", size, nmemb, upload_ctx->sizeleft); + + memcpy((char*)ptr, (char*)upload_ctx->readptr, bytes_to_copy); + upload_ctx->readptr[0] = upload_ctx->readptr[bytes_to_copy]; + upload_ctx->sizeleft -= bytes_to_copy; + + //printf("payload_source #2: size=%d, nmemb=%d, upload_ctx->sizeleft=%d\n", size, nmemb, upload_ctx->sizeleft); + + return bytes_to_copy; + } + + return 0; +} + +int net_smtp_creat_mail_body(char *l_mail_header_buf, curl_information_smtp_t *user_smtp, char* image_buff, int image_buff_size) +{ + if (!user_smtp || strlen(user_smtp->memory_data.memory)==0 || + user_smtp->memory_data.size == 0) + { + return 0; + } + + //#define SEND_MAIL_DEBUG + + + + if (user_smtp->memory_data.size > ATTATHMENT_SIZE_LIMIT) + { + return 0; + } + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + size_t snapshot_size = 0; + if (image_buff_size >= 1) { + snapshot_size = (size_t)image_buff_size; + memcpy(snapshot_addr, image_buff, snapshot_size); + } + + + int l_attachment_file_size = 0; + int /*l_base64_encode_size = 0,*/ /*l_mail_header_buf_size = 0,*/ l_buf_inx = 0/*, l_fbuf_inx = 0,*/ /*l_file_num_of_row = 0*/; + //char l_mail_header_buf[MAX_IMG_SIZE] = { 0 }/*, *l_attchment_file_buf = NULL*/; + char l_attachment_tmp_buf[MAX_IMG_SIZE] = { 0 }, l_b64_encode_buf[MAX_IMG_SIZE] = { 0 }; + int l_inx; + + time_t l_rawtime; + struct tm *l_timeinfo, tm_result; + char l_time_buffer[128] = { 0 }; + int l_read_file_size = 0; + + if (snapshot_size > 0) + { + + l_attachment_file_size = (int)snapshot_size; + //l_base64_encode_size = l_attachment_file_size; + l_read_file_size = l_attachment_file_size; +#if 0 + if (l_attachment_file_size % 3) + { + l_base64_encode_size = ((l_attachment_file_size / 3) + 1) * 4; + } + else + { + l_base64_encode_size = l_attachment_file_size / 3 * 4; + } +#endif + + //l_mail_header_buf_size = (ADD_HEADER_SIZE * SEND_BUFER_SIZE) + l_base64_encode_size + (l_base64_encode_size / SEND_BUFER_SIZE) * 2 + 2; + } + else + { + //l_mail_header_buf_size = (ADD_HEADER_SIZE * SEND_BUFER_SIZE); + } + + /* + do + { + l_mail_header_buf = (char *)calloc(l_mail_header_buf_size, 1); + } while (l_mail_header_buf == NULL); + */ + + //printf("send_mail: alloc attachment buf size=%d, file_size=%d, b64_file_sz=%d\n", l_mail_header_buf_size, l_attachment_file_size, l_base64_encode_size); + + l_buf_inx = 0; + + l_rawtime = time(NULL); + l_timeinfo = localtime_r(&l_rawtime, &tm_result); + + + strftime(l_time_buffer, sizeof(l_time_buffer), "%a, %d %b %Y %H:%M:%S %z", l_timeinfo); + sprintf(&l_mail_header_buf[l_buf_inx], "Date: %s\r\n", l_time_buffer); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + sprintf(&l_mail_header_buf[l_buf_inx], "From:<%s>\r\n", user_smtp->address); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + + int count_user = 0; + for (l_inx = 0; l_inx < USER_SMTP_SIZE; l_inx++) + { + if (strlen(user_smtp->receiver[l_inx])>=1) + { + count_user++; + } + } + + int temp_user = 0; + for (l_inx = 0; l_inx < USER_SMTP_SIZE; l_inx++) + { + if (strlen(user_smtp->receiver[l_inx])) + { + if (count_user == 1) { + sprintf(&l_mail_header_buf[l_buf_inx], "To:<%s>\r\n", user_smtp->receiver[l_inx]); + } + else if (temp_user == 0) { + sprintf(&l_mail_header_buf[l_buf_inx], "To:<%s>", user_smtp->receiver[l_inx]); + } + else if (temp_user == count_user - 1) { + sprintf(&l_mail_header_buf[l_buf_inx], ",<%s>\r\n", user_smtp->receiver[l_inx]); + } + else { + sprintf(&l_mail_header_buf[l_buf_inx], ",<%s>", user_smtp->receiver[l_inx]); + } + + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + temp_user++; + } + } + + sprintf(&l_mail_header_buf[l_buf_inx], "Subject:%s\r\n", user_smtp->subject); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + strcat(&l_mail_header_buf[l_buf_inx], "MIME-Version: 1.0\r\n"); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + sprintf(&l_mail_header_buf[l_buf_inx], "Content-Type: multipart/form-data; boundary=\"%s\"\r\n", BOUNDARY_TEXT); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + +#if 0 + if (snapshot_size > 0) { + sprintf(&l_mail_header_buf[l_buf_inx], "Content-Type: multipart/mixed; boundary=\"%s\"\r\n", BOUNDARY_TEXT); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + } + else { + sprintf(&l_mail_header_buf[l_buf_inx], "Content-Type: multipart/alternative; boundary=\"%s\"\r\n", BOUNDARY_TEXT); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + } +#endif + + strcat(&l_mail_header_buf[l_buf_inx], "\r\n"); + l_buf_inx += 2; + + sprintf(&l_mail_header_buf[l_buf_inx], "--%s\r\n", BOUNDARY_TEXT); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + //strcat(&l_mail_header_buf[l_buf_inx], "Content-Type: text/plain; charset=utf-8\r\n"); + //l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + //strcat(&l_mail_header_buf[l_buf_inx], "Content-Transfer-Encoding: quoted-printable\r\n"); + //strcat(&l_mail_header_buf[l_buf_inx], "Content-Transfer-Encoding: 7bit\r\n"); + //l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + strcat(&l_mail_header_buf[l_buf_inx], "\r\n"); + l_buf_inx += 2; + + //printf("@@@@ send_mail: content_size:%d\n", strlen(user_smtp->memory_data.memory)); + //mail content + sprintf(&l_mail_header_buf[l_buf_inx], "%s\r\n", user_smtp->memory_data.memory); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + //printf("@@@@ send_mail: db2, inx:%d\n", l_buf_inx); + + //printf("@@@@ send_mail: attachment content=%p, size=%d\n", snapshot_addr, (int)snapshot_size); + +#if 1 + if (snapshot_size > 0 && strcmp(SystemSetting.enable_email_jpeg, "Yes") == 0) + { + sprintf(&l_mail_header_buf[l_buf_inx], "--%s\r\n", BOUNDARY_TEXT); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + //if (!strcmp(user_smtp->attachment_type, ".jpg")) + { + sprintf(&l_mail_header_buf[l_buf_inx], "Content-Type: image/jpg; name=%s\r\n", user_smtp->attachment); + + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + } + +#if 0 + else + { + sprintf(&l_mail_header_buf[l_buf_inx], "Content-Type: application/x-msdownload; name=%s\r\n", user_smtp->attachment); + + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + } +#endif + strcat(&l_mail_header_buf[l_buf_inx], "Content-Transfer-Encoding: base64\r\n"); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + sprintf(&l_mail_header_buf[l_buf_inx], "Content-Disposition: attachment; filename=\"%s\"\r\n", user_smtp->attachment); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + strcat(&l_mail_header_buf[l_buf_inx], "\r\n"); + l_buf_inx += 2; + + //printf("send_mail: mail header, inx:%d\n", l_buf_inx); + + memcpy(l_mail_header_buf + l_buf_inx, snapshot_addr, l_attachment_file_size); + l_buf_inx += l_attachment_file_size; + //printf("\n------------l_buf_inx:%d\n", l_buf_inx); + +#if 0 +#if 0 + if (l_attachment_file_size % 54) + { + l_file_num_of_row = (l_attachment_file_size / 54) + 1; + } + else + { + l_file_num_of_row = (l_attachment_file_size / 54); + } +#endif + + //l_attchment_file_buf = user_smtp->attachment_content; + + + //for (l_inx = 0; l_inx < l_file_num_of_row && l_read_file_size < l_attachment_file_size; l_inx++) + { +#if 0 + if ((l_fbuf_inx + 54) > l_attachment_file_size) + { + l_read_file_size = (l_attachment_file_size - l_fbuf_inx); + } + else + { + l_read_file_size = 54; + } +#endif + + //memcpy(l_attachment_tmp_buf, &l_attchment_file_buf[l_fbuf_inx], l_read_file_size); + memcpy(l_attachment_tmp_buf, snapshot_addr /*+ l_fbuf_inx*/, l_read_file_size); + + base64_decode(l_attachment_tmp_buf, l_read_file_size, l_b64_encode_buf, sizeof(l_b64_encode_buf)); + +#if 0 + printf("b64_encode: [%d] %s\n", l_read_file_size, l_b64_encode_buf); +#endif + sprintf(&l_mail_header_buf[l_buf_inx], l_b64_encode_buf, strlen(l_b64_encode_buf)); + + l_buf_inx += strlen(l_b64_encode_buf); + + strcat(&l_mail_header_buf[l_buf_inx], "\r\n"); + + l_buf_inx += 2; + + //l_fbuf_inx += l_read_file_size; + + } +#endif + } +#endif + + //printf("@@@@ send_mail: db, inx:%d\n", l_buf_inx); + + sprintf(&l_mail_header_buf[l_buf_inx], "\r\n--%s--\r\n", BOUNDARY_TEXT); + l_buf_inx += strlen(&l_mail_header_buf[l_buf_inx]); + + //printf("send_mail: buf_inx:%d, buf_size:%d\n", l_buf_inx, l_mail_header_buf_size); + + //strcat(&l_mail_header_buf[l_buf_inx], "\r\n.\r\n"); + //l_buf_inx += 5; +#if 0 + + printf("@@@@ [%d] %s\n", l_buf_inx, l_mail_header_buf); + +#endif + + return l_buf_inx; +} + +static int net_curl_stmp_log_error_msg(const char *log_file, const char *err_msg) +{ + if (!log_file || !err_msg || (strlen(err_msg) == 0)) return -1; + + time_t now = time(0); + // Update current time using time(&now); + time(&now); + char date[128]; + strftime(date, sizeof(date), "%a %b %d %T %Y", localtime(&now)); + + FILE *l_debug_fp = fopen(log_file, "w+"); + if (l_debug_fp) + { + //printf("@@@@ smtp_log: %s\n", err_msg); + //fwrite(err_msg, strlen(err_msg), 1, l_debug_fp); + fprintf(l_debug_fp, "%s: %s\n", date, err_msg); + fclose(l_debug_fp); + } + else { + printf("[net curl stmp]Error opening log_file!\n"); + } + return 0; +} + +int net_curl_smtp_data(curl_information_smtp_t *user_smtp, char* image_buff, int image_buff_size) +{ + if (user_smtp == NULL) return 0; + int l_result = -1; + int l_index = 0; + //CURL *curl; + CURLcode res; + struct curl_slist *l_recipients = NULL; + //struct upload_status l_upload_ctx = { NULL,0 }; + struct upload_status l_upload_ctx; + + char l_smtp_server[256] = { 0 }; + //char l_smtp_receiver[512] = { 0 }; + char l_smtp_capath[512] = { 0 }; + char l_smtp_debug_msg[256] = { 0 }; + char l_smtp_mail_body[MAX_IMG_SIZE] = {0}; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + size_t snapshot_size = 0; + if (image_buff_size >= 1) { + snapshot_size = (size_t)image_buff_size; + memcpy(snapshot_addr, image_buff, snapshot_size); + } + +#define SMTP_SEND_TIMEOUT (10L) +#define SMTP_CONNECTION_TIMEOUT (10L) + //#define SMTP_DEBUG_FILE "/tmp/smtpstatus.txt" + + //curl = curl_easy_init(); + + //if(curl && l_payload_text != NULL) + pthread_mutex_lock(&mutex_curl); + if (g_http_handle) + { + //open debug message + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + if (atoi(user_smtp->auth_mode) == 1) + { + //ssl + snprintf(l_smtp_server, sizeof(l_smtp_server), "smtps://%s:%s/127.0.0.1", user_smtp->server, user_smtp->port); + } + else + { + snprintf(l_smtp_server, sizeof(l_smtp_server), "smtp://%s:%s/127.0.0.1", user_smtp->server, user_smtp->port); + } + + curl_easy_setopt(g_http_handle, CURLOPT_URL, l_smtp_server); + + curl_easy_setopt(g_http_handle, CURLOPT_MAIL_FROM, user_smtp->address); + + for (l_index = 0; l_index < USER_SMTP_SIZE; l_index++) + { + if (strlen(user_smtp->receiver[l_index])) + { + l_recipients = curl_slist_append(l_recipients, user_smtp->receiver[l_index]); + } + } + + curl_easy_setopt(g_http_handle, CURLOPT_MAIL_RCPT, l_recipients); + + if (atoi(user_smtp->auth) == 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, user_smtp->user); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, user_smtp->password); + + if (strlen(user_smtp->ca_path)) + { + strcpy(l_smtp_capath, user_smtp->ca_path); + } + else + { + strcpy(l_smtp_capath, CURL_SMTP_CAPATH); + } + } + + if (atoi(user_smtp->auth_mode) == 1) + { + /* + CURLOPT_SSL_VERIFYPEER: + Tell libcurl whether to verify the smtp server certification. + This is done by using a CA certificate (ca-bundle.crt). + */ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); //? + } + else if (atoi(user_smtp->auth_mode) == 2) + { + curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); //? + } + + //printf("[smtp] server:%s, auth:%d, from:%s, to:%s, user:%s:%s \n", l_smtp_server, atoi(user_smtp->auth_mode), user_smtp->address, user_smtp->receiver[0], user_smtp->user, user_smtp->password); + + int length_mail_body = 0; + length_mail_body = net_smtp_creat_mail_body(l_smtp_mail_body,user_smtp, snapshot_addr, (int)snapshot_size); + if (length_mail_body >= 1) + { + memcpy(l_upload_ctx.readptr,l_smtp_mail_body, length_mail_body); + l_upload_ctx.sizeleft = (size_t)length_mail_body; + curl_easy_setopt(g_http_handle, CURLOPT_INFILESIZE, l_upload_ctx.sizeleft); + + //printf("send_mail: body_size=%d\n", (int)l_upload_ctx.sizeleft); + } + + //2019-06-04, Ming, set timeout for limit usage time of sending E-Mail + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, SMTP_SEND_TIMEOUT); + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, SMTP_CONNECTION_TIMEOUT); + + curl_easy_setopt(g_http_handle, CURLOPT_READFUNCTION, payload_source); + curl_easy_setopt(g_http_handle, CURLOPT_READDATA, &l_upload_ctx); + curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + //time_t l_send_start_time = time(NULL); + res = curl_easy_perform(g_http_handle); + //time_t l_send_end_time = time(NULL); + + //printf("send_mail: res:%d, send mail time: %d\n", res, (int)(l_send_end_time - l_send_start_time)); + + if (res != CURLE_OK) + { + snprintf(l_smtp_debug_msg, sizeof(l_smtp_debug_msg) - 1, "Send Mail Failed: %s", curl_easy_strerror(res)); + net_curl_stmp_log_error_msg(CURL_SMTP_DEBUG_FILE, l_smtp_debug_msg); + printf("net curl smtp data curl easy perform() failed: %s\n", l_smtp_debug_msg); + l_result = -1; + } + else + { + double speed_upload, total_time; + curl_easy_getinfo(g_http_handle, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(g_http_handle, CURLINFO_TOTAL_TIME, &total_time); + //printf("speed_upload %f\n",speed_upload); + //printf("total_time %f\n",total_time); + //printf("net curl smtp data curl easy perform(): %s\n", curl_easy_strerror(res)); + snprintf(l_smtp_debug_msg, sizeof(l_smtp_debug_msg) - 1, "Send Mail: Success"); + net_curl_stmp_log_error_msg(CURL_SMTP_DEBUG_FILE, l_smtp_debug_msg); + l_result = 0; + } + + if (l_recipients) + { + curl_slist_free_all(l_recipients); + } + + curl_easy_reset(g_http_handle); + + /* + if (l_smtp_mail_body) + { + free(l_smtp_mail_body); + l_smtp_mail_body = NULL; + }*/ + } + pthread_mutex_unlock(&mutex_curl); + return l_result; +} +#if 0 +static size_t read_push_callback(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct memory_data_s *read_data = (struct memory_data_s *)userp; + int nSize = 0; + + + if (read_data == NULL) + { + return 0; + } + nSize = size * nmemb; + /* + char *l_ptr = (char *)realloc(read_data->memory, read_data->size + nSize + 1); + + if (l_ptr == NULL) + { + printf("[%s] not enough memory (realloc returned NULL)\n", __func__); + return 0; + } + + read_data->memory = l_ptr;*/ + + memcpy(&(read_data->memory[read_data->size]), ptr, nSize); + read_data->size += nSize; + read_data->memory[read_data->size] = 0; + + return nSize; +} +#endif + +#if 0 +size_t ptz_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream) +{ + /* + time_t timep; + struct tm * timeinfo; + time(&timep); + timeinfo = localtime(&timep); + */ + size_t realsize = size * nmemb; + //cJSON *r_root, *r_tstamp; + + //time_t r_timep; + //struct tm * r_timeinfo; + //time(&timep); + if (stream) + { + //printf("Magic: %s \n", (char *)stream); + //free(stream); + + sprintf((char *)stream, "%s", (char *)ptr); + return realsize; + } + else + { + return 0; + } + + //printf(">>>>>>>>>>>>> Get PTZ Curl resp:\n %s \n", (char *)ptr); + //printf(">>>>>>>>>>>>> Response Time: %d-%02d-%02d ", (1900 + timeinfo->tm_year), (1 + timeinfo->tm_mon), timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + +} +#endif diff --git a/src/net_curl.h b/src/net_curl.h new file mode 100644 index 0000000..b4863de --- /dev/null +++ b/src/net_curl.h @@ -0,0 +1,124 @@ + +#pragma once +#ifndef _NET_CURL_h_ +#define _NET_CURL_h_ +#include "define_inc.h" +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <ctype.h> +#include <time.h> +#include <signal.h> +#include <setjmp.h> +#include "curl/curl.h" +#include "curl/easy.h" +#include "nweb.h" +#include "utility.h" +#include "setting.h" +#ifdef GY_OS_AMBA +#include "ptz.h" +#endif +#include "cryptionPlus.h" +#include "text_insert.h" + +//#define MIN(a,b) ((a)<(b)?(a):(b)) +#define ATTATHMENT_SIZE_LIMIT (10*1024*1024) +#define ADD_HEADER_SIZE (18) +#define SEND_BUFER_SIZE 76 +#define BOUNDARY_TEXT "__MESSAGE__ID__54yg6f6h6y456345" + +typedef size_t(*write_memory_callback_fun)(void *buffer, size_t size, size_t nmemb, void *callback_data); + +int net_curl_http_get_stream(const char *path, int auth, + const char *user, const char *passwd, write_memory_callback_fun callback_fun, void *callback_data); + +int net_curl_http_get(const char *path, int auth, + const char *user, const char *passwd, int wtimeout, char *data_buf, int buffer_size); + +int net_curl_https_get(const char *path, int auth, + const char *user, const char *passwd, char *data_buf, int buffer_size); + +#define USER_FTP_SIZE 5 +#define USER_SMTP_SIZE 5 +#define USER_HTTP_POST_SIZE 25 +#define MAX_MEMORY_SIZE_V 256*1024 + +typedef struct memory_data_s +{ + char memory[MAX_MEMORY_SIZE_V]; + size_t size; +} memory_data_t; + +#define CURL_FTP_URL_PATH 256 +#define CURL_FTP_URL_ALL_MAX 512 +#define CURL_HTTP_POST_URL_ALL_MAX 512 + +#define CURL_SMTP_DEBUG_FILE "/emmc/plugin/Aida_data/smtpstatus.txt" +#ifdef GY_OS_AMBA +#define CURL_SMTP_CAPATH "/etc/pki/tls/certs/ca-bundle.crt" +#endif + +#ifdef GY_OS_NOVA +#define CURL_SMTP_CAPATH "/ssl/certs/ca-bundle.crt" +#endif + +typedef struct curl_information_ftp_s +{ + memory_data_t memory_data; + char url[CURL_FTP_URL_ALL_MAX];//sample "ftp://ip:port/abc/def/123.jpg" + char file_path[CURL_FTP_URL_PATH]; + char *user; + char *password; +} curl_information_ftp_t; + +typedef struct curl_information_smtp_s +{ + memory_data_t memory_data; + char receiver[USER_SMTP_SIZE][50]; + char address[50]; + char server[50]; + char auth_mode[10]; + char port[10]; + char auth[10]; + char user[50]; + char password[50]; + char subject[128]; + char ca_path[512]; + char *attachment_type; + char attachment[512]; + char *attachment_content; + int attachment_size; +} curl_information_smtp_t; + +typedef struct curl_information_http_post_s +{ + memory_data_t memory_data; + char url[CURL_HTTP_POST_URL_ALL_MAX];//sample "http://ip:port/cgi1/cgi2/..." + char *user; + char *password; +} curl_information_http_post_t; + +typedef struct curl_information_push_s +{ + + memory_data_t memory_data; + char url[CURL_HTTP_POST_URL_ALL_MAX]; + char *mac; + char *sdata; +} curl_information_push_t; + +extern SystemSettingInfo SystemSetting; + +extern CURL* g_http_handle; + +extern pthread_mutex_t mutex_curl; + +#if 0 +int net_curl_ftp_one_file(curl_information_ftp_t *user_ftp); +#endif +int net_curl_http_post_data(curl_information_http_post_t *user_http_post); +int net_curl_smtp_data(curl_information_smtp_t *user_smtp, char* image_buff, int image_buff_size); +int net_smtp_creat_mail_body(char *l_mail_header_buf, curl_information_smtp_t *user_smtp, char* image_buff, int image_buff_size); + +//int net_curl_cgi_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, char *sUserNmae, char *sPassWord, int iPort, char *sOutputData); +#endif diff --git a/src/network.c b/src/network.c new file mode 100644 index 0000000..6822ffd --- /dev/null +++ b/src/network.c @@ -0,0 +1,1170 @@ +#include <stdio.h> +#include <time.h> +#include <assert.h> +#include "network.h" +#include "image.h" +#include "data.h" +#include "utils.h" +#include "blas.h" + +#include "crop_layer.h" +#include "connected_layer.h" +#include "gru_layer.h" +#include "rnn_layer.h" +#include "crnn_layer.h" +#include "local_layer.h" +#include "convolutional_layer.h" +#include "activation_layer.h" +#include "detection_layer.h" +#include "region_layer.h" +#include "yolo_layer.h" +#include "normalization_layer.h" +#include "batchnorm_layer.h" +#include "maxpool_layer.h" +#include "reorg_layer.h" +#include "avgpool_layer.h" +#include "cost_layer.h" +#include "softmax_layer.h" +#include "dropout_layer.h" +#include "route_layer.h" +#include "upsample_layer.h" +#include "shortcut_layer.h" +#include "parser.h" +#include "data.h" + +load_args get_base_args(network *net) +{ + load_args args = {0}; + args.w = net->w; + args.h = net->h; + args.size = net->w; + + args.min = net->min_crop; + args.max = net->max_crop; + args.angle = net->angle; + args.aspect = net->aspect; + args.exposure = net->exposure; + args.center = net->center; + args.saturation = net->saturation; + args.hue = net->hue; + return args; +} + +network *load_network(char *cfg, char *weights, int clear) +{ + network *net = parse_network_cfg(cfg); + if(weights && weights[0] != 0){ + load_weights(net, weights); + } + if(clear) (*net->seen) = 0; + return net; +} + +size_t get_current_batch(network *net) +{ + size_t batch_num = (*net->seen)/(net->batch*net->subdivisions); + return batch_num; +} + +void reset_network_state(network *net, int b) +{ + int i; + for (i = 0; i < net->n; ++i) { + #ifdef GPU + layer l = net->layers[i]; + if(l.state_gpu){ + fill_gpu(l.outputs, 0, l.state_gpu + l.outputs*b, 1); + } + if(l.h_gpu){ + fill_gpu(l.outputs, 0, l.h_gpu + l.outputs*b, 1); + } + #endif + } +} + +void reset_rnn(network *net) +{ + reset_network_state(net, 0); +} + +float get_current_rate(network *net) +{ + size_t batch_num = get_current_batch(net); + int i; + float rate; + if (batch_num < net->burn_in) return net->learning_rate * pow((float)batch_num / net->burn_in, net->power); + switch (net->policy) { + case CONSTANT: + return net->learning_rate; + case STEP: + return net->learning_rate * pow(net->scale, batch_num/net->step); + case STEPS: + rate = net->learning_rate; + for(i = 0; i < net->num_steps; ++i){ + if(net->steps[i] > batch_num) return rate; + rate *= net->scales[i]; + } + return rate; + case EXP: + return net->learning_rate * pow(net->gamma, batch_num); + case POLY: + return net->learning_rate * pow(1 - (float)batch_num / net->max_batches, net->power); + case RANDOM: + return net->learning_rate * pow(rand_uniform(0,1), net->power); + case SIG: + return net->learning_rate * (1./(1.+exp(net->gamma*(batch_num - net->step)))); + default: + fprintf(stderr, "Policy is weird!\n"); + return net->learning_rate; + } +} + +char *get_layer_string(LAYER_TYPE a) +{ + switch(a){ + case CONVOLUTIONAL: + return "convolutional"; + case ACTIVE: + return "activation"; + case LOCAL: + return "local"; + case DECONVOLUTIONAL: + return "deconvolutional"; + case CONNECTED: + return "connected"; + case RNN: + return "rnn"; + case GRU: + return "gru"; + case LSTM: + return "lstm"; + case CRNN: + return "crnn"; + case MAXPOOL: + return "maxpool"; + case REORG: + return "reorg"; + case AVGPOOL: + return "avgpool"; + case SOFTMAX: + return "softmax"; + case DETECTION: + return "detection"; + case REGION: + return "region"; + case YOLO: + return "yolo"; + case DROPOUT: + return "dropout"; + case CROP: + return "crop"; + case COST: + return "cost"; + case ROUTE: + return "route"; + case SHORTCUT: + return "shortcut"; + case NORMALIZATION: + return "normalization"; + case BATCHNORM: + return "batchnorm"; + default: + break; + } + return "none"; +} + +network *make_network(int n) +{ + network *net = calloc(1, sizeof(network)); + net->n = n; + net->layers = calloc(net->n, sizeof(layer)); + net->seen = calloc(1, sizeof(size_t)); + net->t = calloc(1, sizeof(int)); + net->cost = calloc(1, sizeof(float)); + return net; +} + +void forward_network(network *netp) +{ +#ifdef GPU + if(netp->gpu_index >= 0){ + forward_network_gpu(netp); + return; + } +#endif + network net = *netp; + int i; + for(i = 0; i < net.n; ++i){ + net.index = i; + layer l = net.layers[i]; + if(l.delta){ + fill_cpu(l.outputs * l.batch, 0, l.delta, 1); + } + l.forward(l, net); + net.input = l.output; + if(l.truth) { + net.truth = l.output; + } + } + calc_network_cost(netp); +} + +void update_network(network *netp) +{ +#ifdef GPU + if(netp->gpu_index >= 0){ + update_network_gpu(netp); + return; + } +#endif + network net = *netp; + int i; + update_args a = {0}; + a.batch = net.batch*net.subdivisions; + a.learning_rate = get_current_rate(netp); + a.momentum = net.momentum; + a.decay = net.decay; + a.adam = net.adam; + a.B1 = net.B1; + a.B2 = net.B2; + a.eps = net.eps; + ++*net.t; + a.t = *net.t; + + for(i = 0; i < net.n; ++i){ + layer l = net.layers[i]; + if(l.update){ + l.update(l, a); + } + } +} + +void calc_network_cost(network *netp) +{ + network net = *netp; + int i; + float sum = 0; + int count = 0; + for(i = 0; i < net.n; ++i){ + if(net.layers[i].cost){ + sum += net.layers[i].cost[0]; + ++count; + } + } + *net.cost = sum/count; +} + +int get_predicted_class_network(network *net) +{ + return max_index(net->output, net->outputs); +} + +void backward_network(network *netp) +{ +#ifdef GPU + if(netp->gpu_index >= 0){ + backward_network_gpu(netp); + return; + } +#endif + network net = *netp; + int i; + network orig = net; + for(i = net.n-1; i >= 0; --i){ + layer l = net.layers[i]; + if(l.stopbackward) break; + if(i == 0){ + net = orig; + }else{ + layer prev = net.layers[i-1]; + net.input = prev.output; + net.delta = prev.delta; + } + net.index = i; + l.backward(l, net); + } +} + +float train_network_datum(network *net) +{ + *net->seen += net->batch; + net->train = 1; + forward_network(net); + backward_network(net); + float error = *net->cost; + if(((*net->seen)/net->batch)%net->subdivisions == 0) update_network(net); + return error; +} + +float train_network_sgd(network *net, data d, int n) +{ + int batch = net->batch; + + int i; + float sum = 0; + for(i = 0; i < n; ++i){ + get_random_batch(d, batch, net->input, net->truth); + float err = train_network_datum(net); + sum += err; + } + return (float)sum/(n*batch); +} + +float train_network(network *net, data d) +{ + assert(d.X.rows % net->batch == 0); + int batch = net->batch; + int n = d.X.rows / batch; + + int i; + float sum = 0; + for(i = 0; i < n; ++i){ + get_next_batch(d, batch, i*batch, net->input, net->truth); + float err = train_network_datum(net); + sum += err; + } + return (float)sum/(n*batch); +} + +void set_temp_network(network *net, float t) +{ + int i; + for(i = 0; i < net->n; ++i){ + net->layers[i].temperature = t; + } +} + + +void set_batch_network(network *net, int b) +{ + net->batch = b; + int i; + for(i = 0; i < net->n; ++i){ + net->layers[i].batch = b; +#ifdef CUDNN + if(net->layers[i].type == CONVOLUTIONAL){ + cudnn_convolutional_setup(net->layers + i); + } + if(net->layers[i].type == DECONVOLUTIONAL){ + layer *l = net->layers + i; + cudnnSetTensor4dDescriptor(l->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l->out_c, l->out_h, l->out_w); + cudnnSetTensor4dDescriptor(l->normTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, l->out_c, 1, 1); + } +#endif + } +} + +int resize_network(network *net, int w, int h) +{ +#ifdef GPU + cuda_set_device(net->gpu_index); + cuda_free(net->workspace); +#endif + int i; + //if(w == net->w && h == net->h) return 0; + net->w = w; + net->h = h; + int inputs = 0; + size_t workspace_size = 0; + //fprintf(stderr, "Resizing to %d x %d...\n", w, h); + //fflush(stderr); + for (i = 0; i < net->n; ++i){ + layer l = net->layers[i]; + if(l.type == CONVOLUTIONAL){ + resize_convolutional_layer(&l, w, h); + }else if(l.type == CROP){ + resize_crop_layer(&l, w, h); + }else if(l.type == MAXPOOL){ + resize_maxpool_layer(&l, w, h); + }else if(l.type == REGION){ + resize_region_layer(&l, w, h); + }else if(l.type == YOLO){ + resize_yolo_layer(&l, w, h); + }else if(l.type == ROUTE){ + resize_route_layer(&l, net); + }else if(l.type == SHORTCUT){ + resize_shortcut_layer(&l, w, h); + }else if(l.type == UPSAMPLE){ + resize_upsample_layer(&l, w, h); + }else if(l.type == REORG){ + resize_reorg_layer(&l, w, h); + }else if(l.type == AVGPOOL){ + resize_avgpool_layer(&l, w, h); + }else if(l.type == NORMALIZATION){ + resize_normalization_layer(&l, w, h); + }else if(l.type == COST){ + resize_cost_layer(&l, inputs); + }else{ + error("Cannot resize this type of layer"); + } + if(l.workspace_size > workspace_size) workspace_size = l.workspace_size; + if(l.workspace_size > 2000000000) assert(0); + inputs = l.outputs; + net->layers[i] = l; + w = l.out_w; + h = l.out_h; + if(l.type == AVGPOOL) break; + } + layer out = get_network_output_layer(net); + net->inputs = net->layers[0].inputs; + net->outputs = out.outputs; + net->truths = out.outputs; + if(net->layers[net->n-1].truths) net->truths = net->layers[net->n-1].truths; + net->output = out.output; + if (net->input) { + free(net->input); + net->input = NULL; + } + if (net->truth) { + free(net->truth); + net->truth = NULL; + } + net->input = calloc(net->inputs*net->batch, sizeof(float)); + net->truth = calloc(net->truths*net->batch, sizeof(float)); +#ifdef GPU + if(gpu_index >= 0){ + cuda_free(net->input_gpu); + cuda_free(net->truth_gpu); + net->input_gpu = cuda_make_array(net->input, net->inputs*net->batch); + net->truth_gpu = cuda_make_array(net->truth, net->truths*net->batch); + if(workspace_size){ + net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1); + } + }else { + if (net->workspace) { + free(net->workspace); + net->workspace = NULL; +} + net->workspace = calloc(1, workspace_size); + } +#else + if (net->workspace) { + free(net->workspace); + net->workspace = NULL; + } + net->workspace = calloc(1, workspace_size); +#endif + //fprintf(stderr, " Done!\n"); + return 0; +} + +image get_network_image_layer(network *net, int i) +{ + layer l = net->layers[i]; +#ifdef GPU + //cuda_pull_array(l.output_gpu, l.output, l.outputs); +#endif + if (l.out_w && l.out_h && l.out_c){ + return float_to_image(l.out_w, l.out_h, l.out_c, l.output); + } + image def = {0}; + return def; +} + +image get_network_image(network *net) +{ + int i; + for(i = net->n-1; i >= 0; --i){ + image m = get_network_image_layer(net, i); + if(m.h != 0) return m; + } + image def = {0}; + return def; +} + +void visualize_network(network *net) +{ + image *prev = 0; + int i; + char buff[256]; + for(i = 0; i < net->n; ++i){ + sprintf(buff, "Layer %d", i); + layer l = net->layers[i]; + if(l.type == CONVOLUTIONAL){ + prev = visualize_convolutional_layer(l, buff, prev); + } + } +} + +void top_predictions(network *net, int k, int *index) +{ + top_k(net->output, net->outputs, k, index); +} + + +float *network_predict(network *net, float *input) +{ + network orig = *net; + net->input = input; + net->truth = 0; + net->train = 0; + net->delta = 0; + forward_network(net); + float *out = net->output; + *net = orig; + return out; +} + +int num_detections(network *net, float thresh) +{ + int i; + int s = 0; + for(i = 0; i < net->n; ++i){ + layer l = net->layers[i]; + if(l.type == YOLO){ + s += yolo_num_detections(l, thresh); + } + if(l.type == DETECTION || l.type == REGION){ + s += l.w*l.h*l.n; + } + } + return s; +} + +detection *make_network_boxes(network *net, float thresh, int *num) +{ + layer l = net->layers[net->n - 1]; + int i; + int nboxes = num_detections(net, thresh); + if(num) *num = nboxes; + detection *dets = calloc(nboxes, sizeof(detection)); + for(i = 0; i < nboxes; ++i){ + dets[i].prob = calloc(l.classes, sizeof(float)); + if(l.coords > 4){ + dets[i].mask = calloc(l.coords-4, sizeof(float)); + } + } + return dets; +} + +void fill_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, detection *dets) +{ + int j; + for(j = 0; j < net->n; ++j){ + layer l = net->layers[j]; + if(l.type == YOLO){ + int count = get_yolo_detections(l, w, h, net->w, net->h, thresh, map, relative, dets); + dets += count; + } + if(l.type == REGION){ + get_region_detections(l, w, h, net->w, net->h, thresh, map, hier, relative, dets); + dets += l.w*l.h*l.n; + } + if(l.type == DETECTION){ + get_detection_detections(l, w, h, thresh, dets); + dets += l.w*l.h*l.n; + } + } +} + +detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num) +{ + detection *dets = make_network_boxes(net, thresh, num); + fill_network_boxes(net, w, h, thresh, hier, map, relative, dets); + return dets; +} + +void free_detections(detection *dets, int n) +{ + int i; + for(i = 0; i < n; ++i){ + if (dets[i].prob) { + free(dets[i].prob); + dets[i].prob = NULL; + } + if (dets[i].mask) { + free(dets[i].mask); + dets[i].mask = NULL; + } + } + if (dets) { + free(dets); + dets = NULL; + } +} + +float *network_predict_image(network *net, image im) +{ + image imr = letterbox_image(im, net->w, net->h); + set_batch_network(net, 1); + float *p = network_predict(net, imr.data); + free_image(imr); + return p; +} + +int network_width(network *net){return net->w;} +int network_height(network *net){return net->h;} + +matrix network_predict_data_multi(network *net, data test, int n) +{ + int i,j,b,m; + int k = net->outputs; + matrix pred = make_matrix(test.X.rows, k); + float *X = calloc(net->batch*test.X.rows, sizeof(float)); + for(i = 0; i < test.X.rows; i += net->batch){ + for(b = 0; b < net->batch; ++b){ + if(i+b == test.X.rows) break; + memcpy(X+b*test.X.cols, test.X.vals[i+b], test.X.cols*sizeof(float)); + } + for(m = 0; m < n; ++m){ + float *out = network_predict(net, X); + for(b = 0; b < net->batch; ++b){ + if(i+b == test.X.rows) break; + for(j = 0; j < k; ++j){ + pred.vals[i+b][j] += out[j+b*k]/n; + } + } + } + } + if (X) { + free(X); + X = NULL; + } + return pred; +} + +matrix network_predict_data(network *net, data test) +{ + int i,j,b; + int k = net->outputs; + matrix pred = make_matrix(test.X.rows, k); + float *X = calloc(net->batch*test.X.cols, sizeof(float)); + for(i = 0; i < test.X.rows; i += net->batch){ + for(b = 0; b < net->batch; ++b){ + if(i+b == test.X.rows) break; + memcpy(X+b*test.X.cols, test.X.vals[i+b], test.X.cols*sizeof(float)); + } + float *out = network_predict(net, X); + for(b = 0; b < net->batch; ++b){ + if(i+b == test.X.rows) break; + for(j = 0; j < k; ++j){ + pred.vals[i+b][j] = out[j+b*k]; + } + } + } + if (X) { + free(X); + X = NULL; + } + return pred; +} + +void print_network(network *net) +{ + int i,j; + for(i = 0; i < net->n; ++i){ + layer l = net->layers[i]; + float *output = l.output; + int n = l.outputs; + float mean = mean_array(output, n); + float vari = variance_array(output, n); + fprintf(stderr, "Layer %d - Mean: %f, Variance: %f\n",i,mean, vari); + if(n > 100) n = 100; + for(j = 0; j < n; ++j) fprintf(stderr, "%f, ", output[j]); + if(n == 100)fprintf(stderr,".....\n"); + fprintf(stderr, "\n"); + } +} + +void compare_networks(network *n1, network *n2, data test) +{ + matrix g1 = network_predict_data(n1, test); + matrix g2 = network_predict_data(n2, test); + int i; + int a,b,c,d; + a = b = c = d = 0; + for(i = 0; i < g1.rows; ++i){ + int truth = max_index(test.y.vals[i], test.y.cols); + int p1 = max_index(g1.vals[i], g1.cols); + int p2 = max_index(g2.vals[i], g2.cols); + if(p1 == truth){ + if(p2 == truth) ++d; + else ++c; + }else{ + if(p2 == truth) ++b; + else ++a; + } + } + printf("%5d %5d\n%5d %5d\n", a, b, c, d); + float num = pow((abs(b - c) - 1.), 2.); + float den = b + c; + printf("%f\n", num/den); +} + +float network_accuracy(network *net, data d) +{ + matrix guess = network_predict_data(net, d); + float acc = matrix_topk_accuracy(d.y, guess,1); + free_matrix(guess); + return acc; +} + +float *network_accuracies(network *net, data d, int n) +{ + static float acc[2]; + matrix guess = network_predict_data(net, d); + acc[0] = matrix_topk_accuracy(d.y, guess, 1); + acc[1] = matrix_topk_accuracy(d.y, guess, n); + free_matrix(guess); + return acc; +} + +layer get_network_output_layer(network *net) +{ + int i; + for(i = net->n - 1; i >= 0; --i){ + if(net->layers[i].type != COST) break; + } + return net->layers[i]; +} + +float network_accuracy_multi(network *net, data d, int n) +{ + matrix guess = network_predict_data_multi(net, d, n); + float acc = matrix_topk_accuracy(d.y, guess,1); + free_matrix(guess); + return acc; +} + +void free_network(network *net) +{ + int i; + for(i = 0; i < net->n; ++i){ + free_layer(net->layers[i]); + } + if (net->layers) { + free(net->layers); + net->layers = NULL; + } + if (net->input) { + free(net->input); + net->input = NULL; + } + if (net->truth) { + free(net->truth); + net->truth = NULL; + } +#ifdef GPU + if(net->input_gpu) cuda_free(net->input_gpu); + if(net->truth_gpu) cuda_free(net->truth_gpu); +#endif + if (net) { + free(net); + net = NULL; + } +} + +// Some day... +// ^ What the hell is this comment for? + + +layer network_output_layer(network *net) +{ + int i; + for(i = net->n - 1; i >= 0; --i){ + if(net->layers[i].type != COST) break; + } + return net->layers[i]; +} + +int network_inputs(network *net) +{ + return net->layers[0].inputs; +} + +int network_outputs(network *net) +{ + return network_output_layer(net).outputs; +} + +float *network_output(network *net) +{ + return network_output_layer(net).output; +} + +#ifdef GPU + +void forward_network_gpu(network *netp) +{ + network net = *netp; + cuda_set_device(net.gpu_index); + cuda_push_array(net.input_gpu, net.input, net.inputs*net.batch); + if(net.truth){ + cuda_push_array(net.truth_gpu, net.truth, net.truths*net.batch); + } + + int i; + for(i = 0; i < net.n; ++i){ + net.index = i; + layer l = net.layers[i]; + if(l.delta_gpu){ + fill_gpu(l.outputs * l.batch, 0, l.delta_gpu, 1); + } + l.forward_gpu(l, net); + net.input_gpu = l.output_gpu; + net.input = l.output; + if(l.truth) { + net.truth_gpu = l.output_gpu; + net.truth = l.output; + } + } + pull_network_output(netp); + calc_network_cost(netp); +} + +void backward_network_gpu(network *netp) +{ + int i; + network net = *netp; + network orig = net; + cuda_set_device(net.gpu_index); + for(i = net.n-1; i >= 0; --i){ + layer l = net.layers[i]; + if(l.stopbackward) break; + if(i == 0){ + net = orig; + }else{ + layer prev = net.layers[i-1]; + net.input = prev.output; + net.delta = prev.delta; + net.input_gpu = prev.output_gpu; + net.delta_gpu = prev.delta_gpu; + } + net.index = i; + l.backward_gpu(l, net); + } +} + +void update_network_gpu(network *netp) +{ + network net = *netp; + cuda_set_device(net.gpu_index); + int i; + update_args a = {0}; + a.batch = net.batch*net.subdivisions; + a.learning_rate = get_current_rate(netp); + a.momentum = net.momentum; + a.decay = net.decay; + a.adam = net.adam; + a.B1 = net.B1; + a.B2 = net.B2; + a.eps = net.eps; + ++*net.t; + a.t = (*net.t); + + for(i = 0; i < net.n; ++i){ + layer l = net.layers[i]; + if(l.update_gpu){ + l.update_gpu(l, a); + } + } +} + +void harmless_update_network_gpu(network *netp) +{ + network net = *netp; + cuda_set_device(net.gpu_index); + int i; + for(i = 0; i < net.n; ++i){ + layer l = net.layers[i]; + if(l.weight_updates_gpu) fill_gpu(l.nweights, 0, l.weight_updates_gpu, 1); + if(l.bias_updates_gpu) fill_gpu(l.nbiases, 0, l.bias_updates_gpu, 1); + if(l.scale_updates_gpu) fill_gpu(l.nbiases, 0, l.scale_updates_gpu, 1); + } +} + +typedef struct { + network *net; + data d; + float *err; +} train_args; + +void *train_thread(void *ptr) +{ + train_args args = *(train_args*)ptr; + if (ptr) { + free(ptr); + ptr = NULL; + } + cuda_set_device(args.net->gpu_index); + *args.err = train_network(args.net, args.d); + return 0; +} + +pthread_t train_network_in_thread(network *net, data d, float *err) +{ + pthread_t thread; + train_args *ptr = (train_args *)calloc(1, sizeof(train_args)); + ptr->net = net; + ptr->d = d; + ptr->err = err; + if(pthread_create(&thread, 0, train_thread, ptr)) error("Thread creation failed"); + return thread; +} + +void merge_weights(layer l, layer base) +{ + if (l.type == CONVOLUTIONAL) { + axpy_cpu(l.n, 1, l.bias_updates, 1, base.biases, 1); + axpy_cpu(l.nweights, 1, l.weight_updates, 1, base.weights, 1); + if (l.scales) { + axpy_cpu(l.n, 1, l.scale_updates, 1, base.scales, 1); + } + } else if(l.type == CONNECTED) { + axpy_cpu(l.outputs, 1, l.bias_updates, 1, base.biases, 1); + axpy_cpu(l.outputs*l.inputs, 1, l.weight_updates, 1, base.weights, 1); + } +} + +void scale_weights(layer l, float s) +{ + if (l.type == CONVOLUTIONAL) { + scal_cpu(l.n, s, l.biases, 1); + scal_cpu(l.nweights, s, l.weights, 1); + if (l.scales) { + scal_cpu(l.n, s, l.scales, 1); + } + } else if(l.type == CONNECTED) { + scal_cpu(l.outputs, s, l.biases, 1); + scal_cpu(l.outputs*l.inputs, s, l.weights, 1); + } +} + + +void pull_weights(layer l) +{ + if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ + cuda_pull_array(l.biases_gpu, l.bias_updates, l.n); + cuda_pull_array(l.weights_gpu, l.weight_updates, l.nweights); + if(l.scales) cuda_pull_array(l.scales_gpu, l.scale_updates, l.n); + } else if(l.type == CONNECTED){ + cuda_pull_array(l.biases_gpu, l.bias_updates, l.outputs); + cuda_pull_array(l.weights_gpu, l.weight_updates, l.outputs*l.inputs); + } +} + +void push_weights(layer l) +{ + if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ + cuda_push_array(l.biases_gpu, l.biases, l.n); + cuda_push_array(l.weights_gpu, l.weights, l.nweights); + if(l.scales) cuda_push_array(l.scales_gpu, l.scales, l.n); + } else if(l.type == CONNECTED){ + cuda_push_array(l.biases_gpu, l.biases, l.outputs); + cuda_push_array(l.weights_gpu, l.weights, l.outputs*l.inputs); + } +} + +void distribute_weights(layer l, layer base) +{ + if (l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL) { + cuda_push_array(l.biases_gpu, base.biases, l.n); + cuda_push_array(l.weights_gpu, base.weights, l.nweights); + if (base.scales) cuda_push_array(l.scales_gpu, base.scales, l.n); + } else if (l.type == CONNECTED) { + cuda_push_array(l.biases_gpu, base.biases, l.outputs); + cuda_push_array(l.weights_gpu, base.weights, l.outputs*l.inputs); + } +} + + +/* + + void pull_updates(layer l) + { + if(l.type == CONVOLUTIONAL){ + cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.n); + cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.nweights); + if(l.scale_updates) cuda_pull_array(l.scale_updates_gpu, l.scale_updates, l.n); + } else if(l.type == CONNECTED){ + cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.outputs); + cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.outputs*l.inputs); + } + } + + void push_updates(layer l) + { + if(l.type == CONVOLUTIONAL){ + cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.n); + cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.nweights); + if(l.scale_updates) cuda_push_array(l.scale_updates_gpu, l.scale_updates, l.n); + } else if(l.type == CONNECTED){ + cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.outputs); + cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.outputs*l.inputs); + } + } + + void update_layer(layer l, network net) + { + int update_batch = net.batch*net.subdivisions; + float rate = get_current_rate(net); + l.t = get_current_batch(net); + if(l.update_gpu){ + l.update_gpu(l, update_batch, rate*l.learning_rate_scale, net.momentum, net.decay); + } + } + void merge_updates(layer l, layer base) + { + if (l.type == CONVOLUTIONAL) { + axpy_cpu(l.n, 1, l.bias_updates, 1, base.bias_updates, 1); + axpy_cpu(l.nweights, 1, l.weight_updates, 1, base.weight_updates, 1); + if (l.scale_updates) { + axpy_cpu(l.n, 1, l.scale_updates, 1, base.scale_updates, 1); + } + } else if(l.type == CONNECTED) { + axpy_cpu(l.outputs, 1, l.bias_updates, 1, base.bias_updates, 1); + axpy_cpu(l.outputs*l.inputs, 1, l.weight_updates, 1, base.weight_updates, 1); + } + } + + void distribute_updates(layer l, layer base) + { + if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ + cuda_push_array(l.bias_updates_gpu, base.bias_updates, l.n); + cuda_push_array(l.weight_updates_gpu, base.weight_updates, l.nweights); + if(base.scale_updates) cuda_push_array(l.scale_updates_gpu, base.scale_updates, l.n); + } else if(l.type == CONNECTED){ + cuda_push_array(l.bias_updates_gpu, base.bias_updates, l.outputs); + cuda_push_array(l.weight_updates_gpu, base.weight_updates, l.outputs*l.inputs); + } + } + */ + +/* + void sync_layer(network *nets, int n, int j) + { + int i; + network net = nets[0]; + layer base = net.layers[j]; + scale_weights(base, 0); + for (i = 0; i < n; ++i) { + cuda_set_device(nets[i].gpu_index); + layer l = nets[i].layers[j]; + pull_weights(l); + merge_weights(l, base); + } + scale_weights(base, 1./n); + for (i = 0; i < n; ++i) { + cuda_set_device(nets[i].gpu_index); + layer l = nets[i].layers[j]; + distribute_weights(l, base); + } + } + */ + +void sync_layer(network **nets, int n, int j) +{ + int i; + network *net = nets[0]; + layer base = net->layers[j]; + scale_weights(base, 0); + for (i = 0; i < n; ++i) { + cuda_set_device(nets[i]->gpu_index); + layer l = nets[i]->layers[j]; + pull_weights(l); + merge_weights(l, base); + } + scale_weights(base, 1./n); + for (i = 0; i < n; ++i) { + cuda_set_device(nets[i]->gpu_index); + layer l = nets[i]->layers[j]; + distribute_weights(l, base); + } +} + +typedef struct{ + network **nets; + int n; + int j; +} sync_args; + +void *sync_layer_thread(void *ptr) +{ + sync_args args = *(sync_args*)ptr; + sync_layer(args.nets, args.n, args.j); + if (ptr) { + free(ptr); + ptr = NULL; + } + return 0; +} + +pthread_t sync_layer_in_thread(network **nets, int n, int j) +{ + pthread_t thread; + sync_args *ptr = (sync_args *)calloc(1, sizeof(sync_args)); + ptr->nets = nets; + ptr->n = n; + ptr->j = j; + if(pthread_create(&thread, 0, sync_layer_thread, ptr)) error("Thread creation failed"); + return thread; +} + +void sync_nets(network **nets, int n, int interval) +{ + int j; + int layers = nets[0]->n; + pthread_t *threads = (pthread_t *) calloc(layers, sizeof(pthread_t)); + + *(nets[0]->seen) += interval * (n-1) * nets[0]->batch * nets[0]->subdivisions; + for (j = 0; j < n; ++j){ + *(nets[j]->seen) = *(nets[0]->seen); + } + for (j = 0; j < layers; ++j) { + threads[j] = sync_layer_in_thread(nets, n, j); + } + for (j = 0; j < layers; ++j) { + pthread_join(threads[j], 0); + } + if (threads) { + free(threads); + threads = NULL; + } +} + +float train_networks(network **nets, int n, data d, int interval) +{ + int i; + int batch = nets[0]->batch; + int subdivisions = nets[0]->subdivisions; + assert(batch * subdivisions * n == d.X.rows); + pthread_t *threads = (pthread_t *) calloc(n, sizeof(pthread_t)); + float *errors = (float *) calloc(n, sizeof(float)); + + float sum = 0; + for(i = 0; i < n; ++i){ + data p = get_data_part(d, i, n); + threads[i] = train_network_in_thread(nets[i], p, errors + i); + } + for(i = 0; i < n; ++i){ + pthread_join(threads[i], 0); + //printf("%f\n", errors[i]); + sum += errors[i]; + } + //cudaDeviceSynchronize(); + if (get_current_batch(nets[0]) % interval == 0) { + printf("Syncing... "); + fflush(stdout); + sync_nets(nets, n, interval); + printf("Done!\n"); + } + //cudaDeviceSynchronize(); + if (threads) { + free(threads); + threads = NULL; + } + if (errors) { + free(errors); + errors = NULL; + } + return (float)sum/(n); +} + +void pull_network_output(network *net) +{ + layer l = get_network_output_layer(net); + cuda_pull_array(l.output_gpu, l.output, l.outputs*l.batch); +} + +#endif diff --git a/src/network.h b/src/network.h new file mode 100644 index 0000000..aa9e249 --- /dev/null +++ b/src/network.h @@ -0,0 +1,152 @@ +// Oh boy, why am I about to do this.... +#pragma once +#ifndef NETWORK_H +#define NETWORK_H +#include "define_inc.h" +#include "darknet.h" + +#include "image.h" +#include "layer.h" +#include "data.h" +#include "tree.h" + +typedef enum { + CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM +} learning_rate_policy; + + +typedef struct network { + int n; + int batch; + size_t *seen; + int *t; + float epoch; + int subdivisions; + layer *layers; + float *output; + learning_rate_policy policy; + + float learning_rate; + float momentum; + float decay; + float gamma; + float scale; + float power; + int time_steps; + int step; + int max_batches; + float *scales; + int *steps; + int num_steps; + int burn_in; + + int adam; + float B1; + float B2; + float eps; + + int inputs; + int outputs; + int truths; + int notruth; + int h, w, c; + int max_crop; + int min_crop; + float max_ratio; + float min_ratio; + int center; + float angle; + float aspect; + float exposure; + float saturation; + float hue; + int random; + + int gpu_index; + tree *hierarchy; + + float *input; + float *truth; + float *delta; + float *workspace; + int train; + int index; + float *cost; + float clip; + +#ifdef GPU + float *input_gpu; + float *truth_gpu; + float *delta_gpu; + float *output_gpu; +#endif + +} network; + + +#ifdef GPU +void pull_network_output(network *net); +#endif + +void compare_networks(network *n1, network *n2, data d); +char *get_layer_string(LAYER_TYPE a); + +network *make_network(int n); +void forward_network(network *net); +void backward_network(network *net); +void update_network(network *net); + +network *load_network(char *cfg, char *weights, int clear); +load_args get_base_args(network *net); + +float network_accuracy_multi(network *net, data d, int n); +int get_predicted_class_network(network *net); +void print_network(network *net); +int resize_network(network *net, int w, int h); +void calc_network_cost(network *net); + +float train_network_sgd(network *net, data d, int n); +float *network_accuracies(network *net, data d, int n); +float train_network_datum(network *net); + + +network *parse_network_cfg(char *filename); +void save_weights(network *net, char *filename); +void load_weights(network *net, char *filename); +void save_weights_upto(network *net, char *filename, int cutoff); +void load_weights_upto(network *net, char *filename, int start, int cutoff); + +void free_network(network *net); +void set_batch_network(network *net, int b); +void set_temp_network(network *net, float t); + +int resize_network(network *net, int w, int h); +float get_current_rate(network *net); +size_t get_current_batch(network *net); + +image get_network_image_layer(network *net, int i); +layer get_network_output_layer(network *net); +void top_predictions(network *net, int n, int *index); + +float network_accuracy(network *net, data d); + +void visualize_network(network *net); + +matrix network_predict_data(network *net, data test); + +image get_network_image(network *net); +float *network_predict(network *net, float *input); + +int network_width(network *net); +int network_height(network *net); +float *network_predict_image(network *net, image im); + +detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num); + + +void reset_network_state(network *net, int b); + +float train_network(network *net, data d); + +#endif + diff --git a/src/normalization_layer.c b/src/normalization_layer.c new file mode 100644 index 0000000..424714f --- /dev/null +++ b/src/normalization_layer.c @@ -0,0 +1,151 @@ +#include "normalization_layer.h" +#include "blas.h" + +#include <stdio.h> + +layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa) +{ + fprintf(stderr, "Local Response Normalization Layer: %d x %d x %d image, %d size\n", w,h,c,size); + layer layer = {0}; + layer.type = NORMALIZATION; + layer.batch = batch; + layer.h = layer.out_h = h; + layer.w = layer.out_w = w; + layer.c = layer.out_c = c; + layer.kappa = kappa; + layer.size = size; + layer.alpha = alpha; + layer.beta = beta; + layer.output = calloc(h * w * c * batch, sizeof(float)); + layer.delta = calloc(h * w * c * batch, sizeof(float)); + layer.squared = calloc(h * w * c * batch, sizeof(float)); + layer.norms = calloc(h * w * c * batch, sizeof(float)); + layer.inputs = w*h*c; + layer.outputs = layer.inputs; + + layer.forward = forward_normalization_layer; + layer.backward = backward_normalization_layer; + #ifdef GPU + layer.forward_gpu = forward_normalization_layer_gpu; + layer.backward_gpu = backward_normalization_layer_gpu; + + layer.output_gpu = cuda_make_array(layer.output, h * w * c * batch); + layer.delta_gpu = cuda_make_array(layer.delta, h * w * c * batch); + layer.squared_gpu = cuda_make_array(layer.squared, h * w * c * batch); + layer.norms_gpu = cuda_make_array(layer.norms, h * w * c * batch); + #endif + return layer; +} + +void resize_normalization_layer(layer *layer, int w, int h) +{ + int c = layer->c; + int batch = layer->batch; + layer->h = h; + layer->w = w; + layer->out_h = h; + layer->out_w = w; + layer->inputs = w*h*c; + layer->outputs = layer->inputs; + layer->output = realloc(layer->output, h * w * c * batch * sizeof(float)); + layer->delta = realloc(layer->delta, h * w * c * batch * sizeof(float)); + layer->squared = realloc(layer->squared, h * w * c * batch * sizeof(float)); + layer->norms = realloc(layer->norms, h * w * c * batch * sizeof(float)); +#ifdef GPU + cuda_free(layer->output_gpu); + cuda_free(layer->delta_gpu); + cuda_free(layer->squared_gpu); + cuda_free(layer->norms_gpu); + layer->output_gpu = cuda_make_array(layer->output, h * w * c * batch); + layer->delta_gpu = cuda_make_array(layer->delta, h * w * c * batch); + layer->squared_gpu = cuda_make_array(layer->squared, h * w * c * batch); + layer->norms_gpu = cuda_make_array(layer->norms, h * w * c * batch); +#endif +} + +void forward_normalization_layer(const layer layer, network net) +{ + int k,b; + int w = layer.w; + int h = layer.h; + int c = layer.c; + scal_cpu(w*h*c*layer.batch, 0, layer.squared, 1); + + for(b = 0; b < layer.batch; ++b){ + float *squared = layer.squared + w*h*c*b; + float *norms = layer.norms + w*h*c*b; + float *input = net.input + w*h*c*b; + pow_cpu(w*h*c, 2, input, 1, squared, 1); + + const_cpu(w*h, layer.kappa, norms, 1); + for(k = 0; k < layer.size/2; ++k){ + axpy_cpu(w*h, layer.alpha, squared + w*h*k, 1, norms, 1); + } + + for(k = 1; k < layer.c; ++k){ + copy_cpu(w*h, norms + w*h*(k-1), 1, norms + w*h*k, 1); + int prev = k - ((layer.size-1)/2) - 1; + int next = k + (layer.size/2); + if(prev >= 0) axpy_cpu(w*h, -layer.alpha, squared + w*h*prev, 1, norms + w*h*k, 1); + if(next < layer.c) axpy_cpu(w*h, layer.alpha, squared + w*h*next, 1, norms + w*h*k, 1); + } + } + pow_cpu(w*h*c*layer.batch, -layer.beta, layer.norms, 1, layer.output, 1); + mul_cpu(w*h*c*layer.batch, net.input, 1, layer.output, 1); +} + +void backward_normalization_layer(const layer layer, network net) +{ + // TODO This is approximate ;-) + // Also this should add in to delta instead of overwritting. + + int w = layer.w; + int h = layer.h; + int c = layer.c; + pow_cpu(w*h*c*layer.batch, -layer.beta, layer.norms, 1, net.delta, 1); + mul_cpu(w*h*c*layer.batch, layer.delta, 1, net.delta, 1); +} + +#ifdef GPU +void forward_normalization_layer_gpu(const layer layer, network net) +{ + int k,b; + int w = layer.w; + int h = layer.h; + int c = layer.c; + scal_gpu(w*h*c*layer.batch, 0, layer.squared_gpu, 1); + + for(b = 0; b < layer.batch; ++b){ + float *squared = layer.squared_gpu + w*h*c*b; + float *norms = layer.norms_gpu + w*h*c*b; + float *input = net.input_gpu + w*h*c*b; + pow_gpu(w*h*c, 2, input, 1, squared, 1); + + const_gpu(w*h, layer.kappa, norms, 1); + for(k = 0; k < layer.size/2; ++k){ + axpy_gpu(w*h, layer.alpha, squared + w*h*k, 1, norms, 1); + } + + for(k = 1; k < layer.c; ++k){ + copy_gpu(w*h, norms + w*h*(k-1), 1, norms + w*h*k, 1); + int prev = k - ((layer.size-1)/2) - 1; + int next = k + (layer.size/2); + if(prev >= 0) axpy_gpu(w*h, -layer.alpha, squared + w*h*prev, 1, norms + w*h*k, 1); + if(next < layer.c) axpy_gpu(w*h, layer.alpha, squared + w*h*next, 1, norms + w*h*k, 1); + } + } + pow_gpu(w*h*c*layer.batch, -layer.beta, layer.norms_gpu, 1, layer.output_gpu, 1); + mul_gpu(w*h*c*layer.batch, net.input_gpu, 1, layer.output_gpu, 1); +} + +void backward_normalization_layer_gpu(const layer layer, network net) +{ + // TODO This is approximate ;-) + + int w = layer.w; + int h = layer.h; + int c = layer.c; + pow_gpu(w*h*c*layer.batch, -layer.beta, layer.norms_gpu, 1, net.delta_gpu, 1); + mul_gpu(w*h*c*layer.batch, layer.delta_gpu, 1, net.delta_gpu, 1); +} +#endif diff --git a/src/normalization_layer.h b/src/normalization_layer.h new file mode 100644 index 0000000..739b3a7 --- /dev/null +++ b/src/normalization_layer.h @@ -0,0 +1,20 @@ +#pragma once +#ifndef NORMALIZATION_LAYER_H +#define NORMALIZATION_LAYER_H +#include "define_inc.h" +#include "image.h" +#include "layer.h" +#include "network.h" + +layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa); +void resize_normalization_layer(layer *layer, int h, int w); +void forward_normalization_layer(const layer layer, network net); +void backward_normalization_layer(const layer layer, network net); +void visualize_normalization_layer(layer layer, char *window); + +#ifdef GPU +void forward_normalization_layer_gpu(const layer layer, network net); +void backward_normalization_layer_gpu(const layer layer, network net); +#endif + +#endif diff --git a/src/nweb.c b/src/nweb.c new file mode 100644 index 0000000..161b9b4 --- /dev/null +++ b/src/nweb.c @@ -0,0 +1,25894 @@ + + +#pragma comment(lib, "WS2_32.lib") /* program use socket library */ +#pragma warning(disable:4996) +#define _CRT_SECURE_NO_DEPRECATE + +#include "define_inc.h" +#include "url_encode.h" +#ifdef GY_OS_AMBA +#include "ptz.h" +//#include "tof.h" +//#include "radar.h" +//#include "radar_receive.h" // leo 09-28 +#endif +#include "cold_zone.h" +#include <mcheck.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <setjmp.h> +#ifdef GY_OS_AMBA +//#include "radar_parser.h" +#endif + +#ifndef TRY_CATCH +#define TRY_CATCH +#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){ +#define CATCH } else { +#define ETRY } }while(0) +#define THROW longjmp(ex_buf__, 1) +#endif + +#ifdef GY_OS_WIN +#include <direct.h> +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined GY_OS_AMBA || defined GY_OS_NOVA +#include <errno.h> +#include <netdb.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/tcp.h> + +#include <netinet/in.h> +#include <arpa/inet.h> + +#endif + +#include <fcntl.h> /* Added for the nonblocking socket */ +#include <time.h> +#include <pthread.h> + +//#include "image.h" +#include "layer.h" +#include "network.h" +#include "nweb.h" +#include "setting.h" +//#include "utility.h" +#include "cryptionPlus.h" +#include "cJSON.h" +#include "zlog.h" +#include "fflpr_plate_db.h" +#include "cgicmd.h" +#include "test_nnctrl_live.h" +#include "pns.h" +#include "net_curl.h" +#include "strptime_c.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +//#include "curl.h" + +//#include <openssl/ssl.h> +//#include "SSLClient.h" + +#include <curl/curl.h> +#include <curl/easy.h> + +#include "sha1.h" +#include "intLib.h" +#include "websocket.h" + +#include "url_encode.h" + +#ifdef GY_OS_AMBA +#include "pythonR.h" +//#include "jvc_progress.h" +#endif + +#ifdef OPENCV +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/core/types_c.h" +#include "opencv2/core/version.hpp" +#ifndef CV_VERSION_EPOCH +#include "opencv2/videoio/videoio_c.h" +#include "opencv2/imgcodecs/imgcodecs_c.h" +#endif +#endif + +#include "fork_pipe_lib.h" +#include "ivsC.h" + +#ifdef GY_OS_WIN +extern int UpdateTrafficLightZone(int tracking_channel_idx); +#endif + +#ifdef GY_OS_NOVA +extern RecvBbox g_current_bbox_list[MAX_TRACKING_NUM]; +extern int g_count_bbox_list; + +extern RecvBbox temp_current_bbox_list[MAX_TRACKING_NUM]; +extern int temp_count_bbox_list; + +extern int g_check_if_run_parse_json_data_from_bbox_receive; +#endif + +extern int reload_dataset_from_jsonfile(void); //0 fail, 1 success +//extern int default_dataset_for_jsonfile(void); //0 fail, 1 success + +pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; +extern pthread_mutex_t mutex_getalarmmotion; +extern pthread_mutex_t mutex_alm; +extern pthread_mutex_t mutex_curl; +extern pthread_mutex_t mutex_websocket; +extern pthread_mutex_t mutex_enable_lpr_db; +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_enable_face_db; +#endif +extern pthread_mutex_t mutex_username; +extern pthread_mutex_t mutex_config_json; +#if defined GY_OS_AMBA +//extern pthread_mutex_t mutex_jvc_config_json; +#endif +extern pthread_mutex_t mutex_events_json; +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 +extern pthread_mutex_t mutex_tof_json; +#endif +extern pthread_mutex_t mutex_web; +//extern pthread_mutex_t mutex_http_connection_handler; +extern pthread_mutex_t mutex_base64; +//extern pthread_mutex_t mutex_get_canvas; +extern pthread_mutex_t mutex_get_network_input; +extern pthread_mutex_t mutex_buffer; + +extern pthread_mutex_t mutex_set_http_request; +extern pthread_mutex_t mutex_reset_counter; +extern pthread_mutex_t mutex_get_image; +extern pthread_mutex_t mutex_get_image_HD; + +extern pthread_mutex_t mutex_snap_image; +#ifdef GY_OS_NOVA +extern pthread_mutex_t mutex_pre_connection; +#endif +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_remotesnap_image; +#endif +//extern pthread_mutex_t mutex_snap_hd_image; + +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_perspective_transform; +#endif + +#ifdef GY_OS_NOVA +//extern pthread_mutex_t mutex_run_parse_json; +#endif + +zlog_category_t *zc=NULL; + +extern int sharkhand_s(int client_socket, char *buffer, int *iIsWebsocket_hybi_00); + +extern int websocket_response(int connfd, char* message); + +extern char* global_message_for_pns_response; + +int g_socket; +// Ken +//extern char *global_message_for_radar_response; +#ifdef GY_OS_AMBA +extern char *g_radar_image_queue; +#endif + +struct timeval currtime_setosd; +long last_ms_setosd = 0; +long current_ms_setosd = 0; + +int CheckIsExistingSpeed = 0; + +int g_dual_sensor = 0; + +int g_camera_white_LED = 0; + +int g_change_getnetwork_buffer_id = 0; + +int g_check_h264_gop = 1; + +#if defined GY_OS_AMBA +int g_isAiRelay = 0; +#endif +struct +{ + char *ext; + char *filetype; +} +extensions[] = +{ +{ "gif", "image/gif" }, +{ "jpg", "image/jpeg" }, +{ "jpeg", "image/jpeg" }, +{ "png", "image/png" }, +{ "ico", "image/ico" }, +{ "zip", "image/zip" }, +{ "gz", "image/gz" }, +{ "tar", "image/tar" }, +{ "htm", "text/html" }, +{ "html", "text/html" }, +{ "css", "text/css" }, +{ "js", "text/javascript" }, +{ "wasm", "application/wasm" }, +{ 0, 0 } +}; + + +//===================== +//sophia add 2020/09/24 +#if defined GY_OS_AMBA || defined GY_OS_NOVA +//SocketInfo_ALM socketRecord_ALM[MAX_CLIENT_SOCKET] = { 0 }; +int bHttpServerMainStart = 0; +int bPreloadHttpServerMainStart = 0; +#endif +//===================== + +CNNType http_cnn_type; +//static network http_nets[MAX_LAYER_NUM]; +//static char **http_names[MAX_LAYER_NUM]; +//static image **http_alphabet; +static float http_thresh; +static float http_hier_thresh; +//static float http_nms[MAX_LAYER_NUM]; +static int http_dont_show; +static int http_ext_output; +static int http_save_labels; +//static char *http_ip_address; +//static char *http_mac_address; +static int http_http_port; +//static int http_layer_count; +static LicenseType http_licenseType; +static AdvanceLicenseType http_advLicenseType; +static AuthFailStatusCode http_afsCode; +static size_t http_featureType; +static size_t http_layerFeatureType[MAX_LAYER_NUM]; +static char *http_strLicenseType; +//static char *http_strLicenseStatus; +//static char *http_strUnlockingKey; + +extern double http_license_fps; +extern int http_sleep_interval; +unsigned int python_check_webstatus = 0; +float confidence_limit; + +extern CPoint trafficLightPoint; +extern int traffic_light_zone_width; +extern int traffic_light_zone_height; +//extern pthread_mutex_t mutex_post_notification; + +char websocket_alarm[CONTENT_BUFSIZE] = { 0 }; + +static float diff; + +int AI_fps = -1; // ܼƩwqAåB]wl +#ifdef GY_OS_NOVA +int AI_fps2 = -1; //nova_driverfps +#endif + +static char g_account_port_protected[512] = { 0 }; + +#ifdef REBOOT_BY_CPU_GPU_USAGE +int CPU_usage_int = -1; +int GPU_usage_int = -1; +#endif + +//bool enable_loop_getalarmmotion = FALSE; //ܼƩwqAåB]wl +//int times_of_enable_loop_getalarmmotion = 1; //enIsisFirstAlarmMotionX +char CPU_usage[256] = { 0 }; +char GPU_usage[256] = { 0 }; +char Buffer_ver[BUFSIZE] = { 0 }; +int g_write_config_file_dirty_flag = 0; + +static char g_record_session_id[MAX_NUMBER_SESSION][MAX_SESSION_ID] = { 0 }; + +#if 0 +static int enable_base64 = 0; +#endif + +int enable_only_show_metadata1 = 1; + +int g_check_if_get_picture_not_OK = 0; + +int g_i_get_cpu_loading = 0; + +//CURL_SEND g_stCURL_send_data = { 0 }; + +static char g_stCURL_send_data_q_name[30] = { 0 }; +static char g_stCURL_send_data_q_plate[60] = { 0 }; + +static char g_stCURL_send_data_curl_url[8192] = { 0 }; +static char g_stCURL_send_data_curl_sendbuf[MAX_IMG_SIZE] = { 0 }; +size_t g_stCURL_send_data_curl_sendbuf_size = 0; +static char g_stCURL_send_data_method[32] = { 0 }; +static char g_stCURL_send_data_protocol[32] = { 0 }; +static char g_stCURL_send_data_username[64] = { 0 }; +static char g_stCURL_send_data_password[64] = { 0 }; +static char g_stCURL_send_data_port[10] = { 0 }; //strtol(q_info->host_port, NULL, 10) +static char g_stCURL_send_data_timeout[10] = { 0 }; +static char g_stCURL_send_data_customized_header[8192] = { 0 }; +static int g_stCURL_image_buff_size=0; +static char g_stCURL_image_buff[MAX_IMG_SIZE] = {0}; +static int g_stCURL_check_127 = 0; +static int g_stCURL_enable_attached_image = 0; +static int g_stCURL_enable_filename_fixed = 0; +static char g_stCURL_send_jpeg_file_name[60] = { 0 }; +static char g_response_net_curl[MAX_IMG_SIZE] = { 0 }; +static int g_response_post_OK = 0; + +#ifdef GY_OS_AMBA +static char g_response_snmp[8192] = { 0 }; + +static char g_stCURL_lpr_db_url[8192] = { 0 }; +static char g_stCURL_lpr_db_username[64] = { 0 }; +static char g_stCURL_lpr_db_password[64] = { 0 }; +static char g_stCURL_lpr_db_port[10] = { 0 }; +static char g_response_lpr_db[8192] = { 0 }; +#endif + +static char g_headerBuffer[BUFSIZE_V2] = { 0 }; +static char g_multiPartBoundary[MAX_MSG_LEN] = { 0 }; +static int g_bIsMultipart = 0; +static char g_contentBuffer[CONTENT_BUFSIZE] = { 0 }; +static long g_nTotalContentLen = 0; +static int g_count_lpr_insert_times = -1; //-1NSbΰF 0N}l >0NimportӼ + +//static char g_image_buff[MAX_IMG_SIZE]; +//size_t g_image_buff_size; + +int switch_g_image_buff_ori = 0; +int g_current_max_num_image_buff = 5; +char g_image_buff_ori[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE] = { 0 }; +int g_image_buff_size_ori[MAX_NUM_IMAGE_BUFF] = { 0 }; +char g_image_state_response_ori[256] = { 0 }; + +long g_post_SysTimeStamp_ori[MAX_NUM_IMAGE_BUFF] = { 0 }; + +int g_video_start_HD = 1; +#if defined GY_OS_AMBA +char g_image_buff_HD[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE_HD] = { 0 }; +int g_image_buff_size_HD[MAX_NUM_IMAGE_BUFF] = { 0 }; +char g_image_buff_HD_pause[MAX_IMG_SIZE_HD] = { 0 }; +#endif +int g_image_buff_size_HD_pause = 0; +long g_image_HD_pasue_time = 0; + +int g_framesize_width = 0; +int g_framesize_height = 0; + +int g_framesize_width_HD = 0; +int g_framesize_height_HD = 0; + +#ifdef GY_OS_AMBA +//face +char g_image_buff[MAX_IMG_SIZE_HD] = { 0 }; +char g_decrypt_buff[MAX_IMG_SIZE_HD] = { 0 }; +//face end +#endif + +#ifdef GY_OS_AMBA +int g_check_if_change_preset = 0; +#endif +static int g_check_if_snap_running = 0; +char g_snap_snapshot_addr[MAX_IMG_SIZE] = { 0 }; +#ifdef GY_OS_AMBA +//static int g_check_if_remotesnap_running = 0; +//char g_remotesnap_snapshot_addr[MAX_IMG_SIZE] = {0}; +#endif +size_t g_snap_snapshot_size = 0; +#ifdef GY_OS_AMBA +size_t g_remotesnap_snapshot_size = 0; +#endif +static int start_to_import_file = 0; +#ifdef GY_OS_AMBA +float g_min_tof_range = 0.0; +int g_min_tof_range_x = 0; +int g_min_tof_range_y = 0; + +float g_max_tof_range = 0.0; +int g_max_tof_range_x = 0; +int g_max_tof_range_y = 0; + +float g_min_tof_degree = 0.0; +float g_min_tof_height = 0.0; +float g_min_tof_distance = 0.0; + +float g_max_tof_degree = 0.0; +float g_max_tof_height = 0.0; +float g_max_tof_distance = 0.0; + +float g_ground_tof_range = 0.0; +float g_ground_tof_degree = 0.0; +float g_ground_tof_height = 0.0; +float g_ground_tof_distance = 0.0; + +double g_tof_device_height = 0.0; + +int g_bIsSendTofPCD = 1; +int g_bIsWritingPCD = 0; + +#endif + +int g_control_alarm_gpio = 0; + +int g_is_check_credential = 0; + +char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; +unsigned int g_uiWebPythonCurrentBufferIndex = 0; +unsigned int g_uiWebPythonLastBufferIndex = 0; +unsigned int g_cWebPythonBufferSignal = 0; +unsigned int g_cWebPythonDeleteStatus = 0; +unsigned int g_cWebPythonStatus = 0; +char g_cWebPythonName[50]; +struct MemoryStruct +{ + char memory[MEMORY_SIZE];//256KB + size_t size; +}; + +int get_g_control_alarm_gpio() { + return g_control_alarm_gpio; +} + +void set_g_control_alarm_gpio_to_zero() { + g_control_alarm_gpio = 0; +} + +void set_g_control_alarm_gpio_to_one() { + g_control_alarm_gpio = 1; +} + +void memset_snapshot_addr() { + for (int i = 0; i < MAX_SNAP_HD_LIST; i++) { + memset(snapHDList[i].snapshot_addr, 0x00, MAX_IMG_SIZE); + } +} + +static size_t WriteResponseString(void* contents, size_t size, size_t nmemb, void* user_ptr) +{ + size_t realsize = size * nmemb; + struct MemoryStruct* mem = (struct MemoryStruct*)user_ptr; + + /* + char* ptr = realloc(mem->memory, mem->size + realsize + 1); + if (!ptr) { + // out of memory! + printf("\nnot enough memory (realloc returned NULL)\n"); + return 0; + }*/ + + if (mem->size + realsize + 1 >= MEMORY_SIZE)//25KB + { + printf("\nover MEMORY_SIZE KB memory (returned NULL)\n"); + return 0; + } + + //mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} + +#define SOCKET_SEND_ERROR_COUNT 10 +#if 0 +void syslog(int type, char *s1, char *s2, int num) +{ + FILE *fp; + static char log_buf[LOG_BUFSIZE]; + + switch (type) + { + case NW_ERROR: + sprintf(log_buf, "ERROR: %s:%s Errno = %d", s1, s2, errno); + break; + + case NW_SORRY: + sprintf(log_buf, + "<HTML><BODY><H2>nweb Web Server: %s %s</H2></BODY></HTML>\r\n", + s1, s2); + send(num, log_buf, strlen(log_buf), 0); + sprintf(log_buf, "SORRY: %s:%s", s1, s2); + break; + + case NW_LOG: + sprintf(log_buf, " INFO: %s:%s:%d", s1, s2, num); + break; + } + + /* write event data to the log file 'nweb.syslog' */ + if ((fp = fopen("nweb.syslog", "a")) != NULL) + { + strncat(log_buf, "\n", LOG_BUFSIZE); + fprintf(fp, log_buf); + fclose(fp); + } +#ifdef GY_OS_WIN + if (type == NW_ERROR || type == NW_SORRY) + { + WSACleanup(); + exit(1); + } +#endif +} +#endif + +char* FindHttpContentStart(char* buffer) +{ + for (int i = 0; i < BUFSIZE_V2; i++) + { + //char* b = buffer + i; + + if (memcmp(buffer + i, "\r\n\r\n", strlen("\r\n\r\n")) == 0) + { + return buffer + i + strlen("\r\n\r\n"); + break; + } + } + return NULL; +} + +void DumpCharacters(char* str, int length) +{ + for (int i = 0; i < length; i++) + printf("%c", *(str + i)); + printf("\n"); +} + +char *removeHTTPHeader(char *buffer, int *bodySize) { + char *t = strstr(buffer, "\r\n\r\n"); + t = t + 4; + + for (char* it = buffer; it != t; ++it) { + ++(*bodySize); + } + + return t; +} + +void getPicture(int socketfd, int bSize,int current_profile_id,int enable_check_profile_id) { + //printf("\n----------getPicture: 1\n"); + //printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); + + char buffer_image[MAX_IMG_SIZE_HD] = { 0 }; + char buffer[MAX_IMG_SIZE_HD] = { 0 }; + size_t bReceived; + + //bReceived = recv(socketfd, buffer, bSize, 0); + + int try_gethead = 0; + while (bHttpServerMainStart) { + bReceived = recv(socketfd, buffer, bSize, 0); + + if (strlen(buffer) == 0) { + g_check_if_get_picture_not_OK = 1; + } + else { + g_check_if_get_picture_not_OK = 0; + } + + if (strstr(buffer, "HTTP") != NULL) + break; + + if (try_gethead >= 10) + break; + + printf("\n-----------get Picture try to receive buffer head:%s\n", buffer); + memset(buffer, 0, bSize); + + try_gethead++; + + usSleep(1); + if (g_check_if_get_picture_not_OK == 1) { + usSleep(1000000); + } + } + if (g_check_if_get_picture_not_OK == 1) { + usSleep(1000000); + } + + int bodySize = 0; + int content_length_image = 0; + + + //char *t = removeHTTPHeader(buffer, &bodySize); + //bodySize = 0; +#if 0 + bodySize = bReceived - bodySize; + if (bodySize >= 1 && bodySize <= bSize) { + memcpy(buffer_image, t, bodySize); + } + printf("\n--------------getPicture---5-------bodySize:%d\n", bodySize); + printf("\n--------------buffer:%s\n", buffer); +#endif + + int framesize_width = 0; + int framesize_height = 0; + + if (strstr(buffer, "framesize=") != NULL) { + char *ptr_1 = strstr(buffer, "framesize=")+10; + char *ptr_2 = strstr(ptr_1,"&"); + if (ptr_2 != NULL) { + int ptr_length = ptr_2 - ptr_1; + char buff_temp[15] = { 0 }; + memcpy(buff_temp,ptr_1, ptr_length); + //printf("\n-----------------buff_temp:%s\n", buff_temp); + + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(buff_temp, outArray, "x"); + //printf("\n------UU:19\n"); + + framesize_width = atoi(outArray[0]); + framesize_height = atoi(outArray[1]); + //printf("\n----------buff_temp:%s\n", buff_temp); + //printf("\n----------outArray[0]:%s\n", outArray[0]); + //printf("\n----------outArray[1]:%s\n", outArray[1]); + //printf("\n------------g_framesize_width:%d,g_framesize_height:%d\n", g_framesize_width, g_framesize_height); + } + } + + if (enable_check_profile_id == 1) { + g_framesize_width = framesize_width; + g_framesize_height = framesize_height; + } + else { + g_framesize_width_HD = framesize_width; + g_framesize_height_HD = framesize_height; + } + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + //printf("\n----------getPicture: 2: %s\n", buffer); + if (strstr(buffer, "HTTP/1.1 200") != NULL && strstr(buffer, "encode=jpeg") != NULL && + framesize_width >= 1 && framesize_width <= 1280 && + framesize_height >= 1 && framesize_height <= 960) + { + + //bodySize = 0; + //if (content_length_image >= 1) + { + memset(buffer, 0, bSize); + bodySize = 0; + content_length_image = 0; + //printf("\n----------getPicture: 3\n"); + + while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, bSize, 0)) > 0) { + + //printf("\n----------get Picture start\n"); + + //if (switch_g_image_buff_ori == 1) + { + //if (enable_check_profile_id == 0) + { + //printf("\n-------------------------buffer:%s\n", buffer); + //printf("\n-------------------------bReceived:%d\n", bReceived); + } + + if (bReceived >= 3) { + if (strncmp(buffer, "--myboundary", 12) == 0) { + char *ptr_1 = strstr(buffer, "Content-Length: "); + char *ptr_buffer = strstr(buffer, "--myboundary"); + if (ptr_1) { + char *ptr_2 = strstr(ptr_1, "\r\n"); + if (ptr_2) { + int strlen_ptr = ptr_2 - ptr_1 - 16; + char boundary[256] = { 0 }; + if (strlen_ptr >= 1) { + strncpy(boundary, ptr_1 + 16, strlen_ptr); + //printf("\n-----------boundary:%s\n", boundary); + content_length_image = atoi(boundary); + //printf("\n-------------content_length_image:%d\n", content_length_image); + + ptr_2 = ptr_2 + 4; + + int head_length = ptr_2 - ptr_buffer; + + memset(buffer_image, 0x00, MAX_IMG_SIZE_HD); + if (head_length >= 1 && content_length_image >= 1) { + if (bReceived == head_length + content_length_image + 2) { + memcpy(buffer_image, ptr_2, content_length_image); + bodySize = content_length_image; + content_length_image = 0; + } + else if (bReceived == head_length + content_length_image) { + memcpy(buffer_image, ptr_2, content_length_image); + bodySize = content_length_image; + content_length_image = 0; + } + else if (bReceived > head_length) { + memcpy(buffer_image, ptr_2, bReceived - head_length); + bodySize = bReceived - head_length; + content_length_image -= bodySize; + } + + //if (enable_check_profile_id == 0) + { + //printf("\n-getPicture---TTT#2-bReceived:%d\n", bReceived); + //printf("\n-------------------buffer_image#2:%s\n", buffer_image); + + //printf("\n-----------content_length_image #2:%d\n", content_length_image); + //printf("\n-----------bodySize #2:%d\n", bodySize); + } + } + } + } + } + } + else { + if (content_length_image >= 1) { + if (bReceived == content_length_image + 2) { + memcpy(buffer_image + bodySize, buffer, content_length_image); + bodySize += content_length_image; + content_length_image = 0; + } + else if (bReceived == content_length_image) { + memcpy(buffer_image + bodySize, buffer, content_length_image); + bodySize += content_length_image; + content_length_image = 0; + } + else if (bReceived < content_length_image) { + memcpy(buffer_image + bodySize, buffer, bReceived); + bodySize += bReceived; + content_length_image -= bReceived; + } + + //if (enable_check_profile_id == 0) + { + //printf("\n--------------getPicture---TTT------bReceived:%d\n", bReceived); + //printf("\n-------------------buffer_image#1:%s\n", buffer_image); + + //printf("\n-----------content_length_image #1:%d\n", content_length_image); + //printf("\n-----------bodySize #1:%d\n", bodySize); + } + } + } + } + + if (content_length_image <= 0) { + if (bodySize >= 1) { + + //printf("\n--------bodySize:%d\n", bodySize); + + if (enable_check_profile_id == 1) { + pthread_mutex_lock(&mutex_get_image); + g_post_SysTimeStamp_ori[0] = g_osdSysTimeStamp; + for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { + if (g_image_buff_size_ori[i - 1]) { + memcpy(g_image_buff_ori[i], g_image_buff_ori[i - 1], g_image_buff_size_ori[i - 1]); + g_image_buff_size_ori[i] = g_image_buff_size_ori[i - 1]; + g_post_SysTimeStamp_ori[i] = g_post_SysTimeStamp_ori[i - 1]; + } + } + memcpy(g_image_buff_ori[0], buffer_image, bodySize); + g_image_buff_size_ori[0] = bodySize; + pthread_mutex_unlock(&mutex_get_image); + +#if defined GY_OS_AMBA + if (atoi(SystemSetting.getimage_encoder_id_HD) == atoi(SystemSetting.getimage_encoder_id)) { + pthread_mutex_lock(&mutex_get_image_HD); + for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { + if (g_image_buff_size_HD[i - 1]) { + memcpy(g_image_buff_HD[i], g_image_buff_HD[i - 1], g_image_buff_size_HD[i - 1]); + g_image_buff_size_HD[i] = g_image_buff_size_HD[i - 1]; + } + } + memcpy(g_image_buff_HD[0], buffer_image, bodySize); + g_image_buff_size_HD[0] = bodySize; + pthread_mutex_unlock(&mutex_get_image_HD); + } +#endif + } + else { +#if defined GY_OS_AMBA + pthread_mutex_lock(&mutex_get_image_HD); + for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { + if (g_image_buff_size_HD[i - 1]) { + memcpy(g_image_buff_HD[i], g_image_buff_HD[i - 1], g_image_buff_size_HD[i - 1]); + g_image_buff_size_HD[i] = g_image_buff_size_HD[i - 1]; + } + } + memcpy(g_image_buff_HD[0], buffer_image, bodySize); + g_image_buff_size_HD[0] = bodySize; + pthread_mutex_unlock(&mutex_get_image_HD); +#endif + } + + if(enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "OK"); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----image fps:%lf\n",1000.0/dw_FPS_time_delta); + //last_ms = now_ms; + } + else if (bodySize == 0) { + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Encoder: The resolution is not supported."); + } + bodySize = 0; + content_length_image = 0; + memset(buffer_image, 0x00, MAX_IMG_SIZE_HD); + //break; + } + + } + + //printf("\n----------get Picture end\n"); + //printf("\n-----strlen:%d\n",strlen(buffer)); + memset(buffer, 0, bSize); + //usSleep(65000); + usSleep(10000); + + if (enable_check_profile_id == 1) + { + if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id) - 1)) + break; + } +#if defined GY_OS_AMBA + else { + if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id_HD) - 1)) + break; + } +#endif + } + } + } + else { + //printf("\n----------getPicture: 4: %s\n", buffer); + + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori,"Encoder: The profile name is not jpeg."); + } + + //printf("\n------------bodySize:%d\n", bodySize); + //printf("\n----------getPicture: 5\n"); +} +#ifdef GY_OS_NOVA +void get_nova_driver(int socketfd) { + //printf("\n----------getPicture: 1\n"); + //printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); + + char buffer[65535] = { 0 }; + size_t bReceived; + + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, 65535, 0)) > 0) { + + //printf("\n----------get Picture start\n"); + + //printf("\n---------buffer:%s\n", buffer); + //printf("\n-------strlen:%d\n", strlen(buffer)); + if (strstr(buffer, "GET /send_nova_driver") != NULL) { + + //printf("\nKKKKKKKKKKK:g_check_if_run_parse_json_data_from_bbox_receive:%d,g_count_bbox_list:%d\n", g_check_if_run_parse_json_data_from_bbox_receive, g_count_bbox_list); + if (g_check_if_run_parse_json_data_from_bbox_receive == 0 && g_count_bbox_list == 0) { + //printf("\n-------kkkkkkkkkkkk: 1\n"); + + + + char * start_mydata = strstr(buffer, "{\"AiEngine\""); + if (start_mydata != NULL) { + //printf("\n-------kkkkkkkkkkkk: 2\n"); + char * end_mydata = strstr(start_mydata, "-----end_nova_driver"); + if (end_mydata != NULL) { + //printf("\n-------kkkkkkkkkkkk: 3\n"); + int recv_len = end_mydata - start_mydata; + if (recv_len >= 1) { + //printf("\n-------kkkkkkkkkkkk: 4\n"); + char mydata[BUFSIZE * 59] = { 0 }; + memcpy(mydata, start_mydata, recv_len); + //printf("\n---------mydata:%s\n", mydata); + + cJSON *root/*, *res_height, *res_width*/, *cJSON_AI_fps2, *detect_count, *AiEngine, *detect; + cJSON *id, *confidence, *class_id, *x, *y, *w, *h, *object_score, *class_score; + cJSON *parent_idx_temp, *obj_type_temp, *featuretype_temp, *enginetype_temp, *featuretype2_temp, *enginetype2_temp, *name_temp/*, *plate_temp*/; + cJSON *id_img, *size_base64_img, *cjson_crop_w, *cjson_crop_h; + + root = cJSON_Parse(mydata); + + if (root) { + //res_height = cJSON_GetObjectItem(root, "res_height"); + //res_width = cJSON_GetObjectItem(root, "res_width"); + detect_count = cJSON_GetObjectItem(root, "Count"); + AiEngine = cJSON_GetObjectItem(root, "AiEngine"); + cJSON_AI_fps2 = cJSON_GetObjectItem(root, "AI_fps"); + + if (cJSON_AI_fps2) { + AI_fps2 = cJSON_AI_fps2->valueint; + } + + /* + if (res_height) { + g_res_height = res_height->valueint; + } + else { + g_res_height = NET_SIZE_H; + } + + if (res_width) { + g_res_width = res_width->valueint; + } + else { + g_res_width = NET_SIZE_W; + }*/ + + if (detect_count) { + if (detect_count->valueint <= MAX_TRACKING_NUM) { + temp_count_bbox_list = detect_count->valueint; + } + else { + temp_count_bbox_list = MAX_TRACKING_NUM; + } + + //printf("\n---------------temp_count_bbox_list:%d\n", temp_count_bbox_list); + } + else { + temp_count_bbox_list = 0; + } + + if (temp_count_bbox_list >= 1) + { + int i = 0; + cJSON_ArrayForEach(detect, AiEngine) + { + id = cJSON_GetObjectItem(detect, "id"); + confidence = cJSON_GetObjectItem(detect, "confidence"); + object_score = cJSON_GetObjectItem(detect, "object_score"); + class_score = cJSON_GetObjectItem(detect, "class_score"); + class_id = cJSON_GetObjectItem(detect, "class_id"); + x = cJSON_GetObjectItem(detect, "x"); + y = cJSON_GetObjectItem(detect, "y"); + w = cJSON_GetObjectItem(detect, "w"); + h = cJSON_GetObjectItem(detect, "h"); + + parent_idx_temp = cJSON_GetObjectItem(detect, "parent_idx"); + obj_type_temp = cJSON_GetObjectItem(detect, "obj_type"); + featuretype_temp = cJSON_GetObjectItem(detect, "featuretype"); + enginetype_temp = cJSON_GetObjectItem(detect, "enginetype"); + featuretype2_temp = cJSON_GetObjectItem(detect, "featuretype2"); + enginetype2_temp = cJSON_GetObjectItem(detect, "enginetype2"); + + name_temp = cJSON_GetObjectItem(detect, "name"); + //plate_temp = cJSON_GetObjectItem(detect, "plate"); + + + + size_base64_img = cJSON_GetObjectItem(detect, "cropped_size"); + id_img = cJSON_GetObjectItem(detect, "id_img"); + cjson_crop_w = cJSON_GetObjectItem(detect, "crop_w"); + cjson_crop_h = cJSON_GetObjectItem(detect, "crop_h"); + + if (id && confidence && class_id && x && y && w && h && object_score && class_score + && parent_idx_temp && obj_type_temp && featuretype_temp && enginetype_temp && featuretype2_temp && enginetype2_temp && name_temp //&& plate_temp + /*&& base64_img && size_base64_img && cjson_crop_w && cjson_crop_h*/) { + + temp_current_bbox_list[i].id = id->valueint; + temp_current_bbox_list[i].confidence = (float)confidence->valueint; + temp_current_bbox_list[i].class_id = class_id->valueint; + temp_current_bbox_list[i].x = (float)x->valueint; + temp_current_bbox_list[i].y = (float)y->valueint; + temp_current_bbox_list[i].w = (float)w->valueint; + temp_current_bbox_list[i].h = (float)h->valueint; + + temp_current_bbox_list[i].object_score = (float)object_score->valueint; + temp_current_bbox_list[i].class_score = (float)class_score->valueint; + + temp_current_bbox_list[i].parent_idx = (int)parent_idx_temp->valueint; + temp_current_bbox_list[i].obj_type = (int)obj_type_temp->valueint; + temp_current_bbox_list[i].featureType = (size_t)featuretype_temp->valueint; + temp_current_bbox_list[i].engine_type = (unsigned int)enginetype_temp->valueint; + temp_current_bbox_list[i].featureType2 = (size_t)featuretype2_temp->valueint; + temp_current_bbox_list[i].engine_type2 = (unsigned int)enginetype2_temp->valueint; + + strcpy(temp_current_bbox_list[i].name, name_temp->valuestring); + /*if (plate_temp) { + strcpy(temp_current_bbox_list[i].plate, plate_temp->valuestring); + } + else { + strcpy(temp_current_bbox_list[i].plate, ""); + }*/ + + if (size_base64_img && size_base64_img->valueint >= 1 && id_img && id_img->valueint >= 0) { + //temp_current_bbox_list[i].size_base64_cropped_img = size_base64_img->valueint; + if (cjson_crop_w) { + temp_current_bbox_list[i].crop_w = cjson_crop_w->valueint; + } + else { + temp_current_bbox_list[i].crop_w = 0; + } + + if (cjson_crop_h) { + temp_current_bbox_list[i].crop_h = cjson_crop_h->valueint; + } + else { + temp_current_bbox_list[i].crop_h = 0; + } + + //memcpy(temp_current_bbox_list[i].base64_cropped_img, base64_img->valuestring, temp_current_bbox_list[i].size_base64_cropped_img); + + if (temp_current_bbox_list[i].crop_h >= 1 && temp_current_bbox_list[i].crop_w >= 1) { + g_size_base64_cropped_img[id_img->valueint] = size_base64_img->valueint; + //memcpy(g_base64_cropped_img[g_index_base64_cropped_img], base64_img->valuestring, g_size_base64_cropped_img[g_index_base64_cropped_img]); + temp_current_bbox_list[i].image_id = id_img->valueint; + //g_index_base64_cropped_img++; + //if (g_index_base64_cropped_img >= MAX_IMAGE_YUV) { + //g_index_base64_cropped_img = 0; + //} + } + else { + temp_current_bbox_list[i].image_id = -1; + } + } + else { + //temp_current_bbox_list[i].size_base64_cropped_img = 0; + temp_current_bbox_list[i].crop_w = 0; + temp_current_bbox_list[i].crop_h = 0; + temp_current_bbox_list[i].image_id = -1; + //strcpy(temp_current_bbox_list[i].base64_cropped_img, ""); + } + + i++; + } + + /* + printf("\n----[gynet][bbox receive]After parsing received TCP json data--id:%d,confidence:%f,class_id:%d,x:%f,y:%f,w:%f,h:%f\n", + temp_current_bbox_list[i].id, + temp_current_bbox_list[i].confidence, + temp_current_bbox_list[i].class_id, + temp_current_bbox_list[i].x, + temp_current_bbox_list[i].y, + temp_current_bbox_list[i].w, + temp_current_bbox_list[i].h);*/ + + if (i >= temp_count_bbox_list) + break; + } + temp_count_bbox_list = i; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + //printf("\n-------kkkkkkkkkkkk: 5\n"); + //if (check_if_finish_thread_bbox_list == 1) + { + //pthread_mutex_lock(&mutex_run_parse_json); + + if (temp_count_bbox_list >= 1) { + //printf("\nGGGGGGGGGGG:%d\n", temp_count_bbox_list); + for (int i = 0; i < temp_count_bbox_list; i++) { + g_current_bbox_list[i].id = temp_current_bbox_list[i].id; + g_current_bbox_list[i].confidence = temp_current_bbox_list[i].confidence; + g_current_bbox_list[i].class_id = temp_current_bbox_list[i].class_id; + g_current_bbox_list[i].x = temp_current_bbox_list[i].x; + g_current_bbox_list[i].y = temp_current_bbox_list[i].y; + g_current_bbox_list[i].w = temp_current_bbox_list[i].w; + g_current_bbox_list[i].h = temp_current_bbox_list[i].h; + + g_current_bbox_list[i].object_score = temp_current_bbox_list[i].object_score; + g_current_bbox_list[i].class_score = temp_current_bbox_list[i].class_score; + + g_current_bbox_list[i].parent_idx = temp_current_bbox_list[i].parent_idx; + g_current_bbox_list[i].obj_type = temp_current_bbox_list[i].obj_type; + g_current_bbox_list[i].featureType = temp_current_bbox_list[i].featureType; + g_current_bbox_list[i].engine_type = temp_current_bbox_list[i].engine_type; + g_current_bbox_list[i].featureType2 = temp_current_bbox_list[i].featureType2; + g_current_bbox_list[i].engine_type2 = temp_current_bbox_list[i].engine_type2; + + strcpy(g_current_bbox_list[i].name, temp_current_bbox_list[i].name); + //strcpy(g_current_bbox_list[i].plate, temp_current_bbox_list[i].plate); + + if (temp_current_bbox_list[i].image_id >= 0) { + //g_current_bbox_list[i].size_base64_cropped_img = temp_current_bbox_list[i].size_base64_cropped_img; + g_current_bbox_list[i].crop_w = temp_current_bbox_list[i].crop_w; + g_current_bbox_list[i].crop_h = temp_current_bbox_list[i].crop_h; + g_current_bbox_list[i].image_id = temp_current_bbox_list[i].image_id; + //memcpy(g_current_bbox_list[i].base64_cropped_img, temp_current_bbox_list[i].base64_cropped_img, g_current_bbox_list[i].size_base64_cropped_img); + } + else { + //g_current_bbox_list[i].size_base64_cropped_img = 0; + g_current_bbox_list[i].crop_w = 0; + g_current_bbox_list[i].crop_h = 0; + g_current_bbox_list[i].image_id = -1; + //strcpy(g_current_bbox_list[i].base64_cropped_img, ""); + } + + } + g_count_bbox_list = temp_count_bbox_list; + } + else { + g_count_bbox_list = 0; + } + //pthread_mutex_unlock(&mutex_run_parse_json); + + //check_if_finish_thread_bbox_list = 0; + } + } + + g_check_if_run_parse_json_data_from_bbox_receive = 1; + } + } + } + //g_check_if_run_parse_json_data_from_bbox_receive = 0; + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get nova driver ms:%lf\n", dw_FPS_time_delta); + //last_ms = now_ms; + } + } + + //printf("\n----------get Picture end\n"); + + memset(buffer, 0x00, 65535); + usSleep(70000); + } +} +#endif + +int get_g_framesize_width() { + return g_framesize_width; +} + +int get_g_framesize_height() { + return g_framesize_height; +} +#ifdef GY_OS_NOVA +void start_nova_driver() { + int nova_driver_port = 4343; + + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = AF_INET; + + //localhost test + info.sin_addr.s_addr = INADDR_ANY; + info.sin_port = htons(nova_driver_port); + //socketإ TCP_PORT_IMAGE + int sockfd = 0; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + struct timeval timeout; + timeout.tv_sec = 10; + timeout.tv_usec = 0; + + setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + int tcpnodelay = 1; + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + + int reuse = 1; + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + //printf("\n------------get snap with profile id:5\n"); + if (sockfd >= 0) { + + int err = connect(sockfd, (struct sockaddr *)&info, sizeof(info)); + if (err == -1) { + //printf("Connection error #2"); + } + else { + char msg[2560] = { 0 }; + + sprintf(msg, "GET /start_nova_driver HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %d\r\nConnection: close\r\n", nova_driver_port); + + err = send(sockfd, msg, strlen(msg), 0); + if (err == -1) { + printf("\nerror sending #2\n"); + + //exit(EXIT_FAILURE); + } + else { + get_nova_driver(sockfd); + } + } + + close(sockfd); + sockfd = -1; + } + else { + printf("\nCould not create socket!\n"); + } + +} +#endif +void get_snap_with_profile_id(int i_profileid,int enable_check_profile_id) { + if (g_check_h264_gop == 0) { + //printf("\n------------get snap with profile id:1\n"); + + //int snapshot_size = 0; + + int status; + struct addrinfo host_info; + struct addrinfo *host_info_list = NULL; + + memset(&host_info, 0, sizeof(host_info)); + + host_info.ai_family = AF_INET;//AF_UNSPEC + host_info.ai_socktype = SOCK_STREAM; + host_info.ai_protocol = 0; + + status = getaddrinfo("127.0.0.1", accountData[0].account_port, &host_info, &host_info_list); + if (status != 0) { + printf("\ngetaddrinfo error: %d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: getaddrinfo error"); + } + else + { + //printf("\n------------get snap with profile id:2\n"); + int socketfd = -1;; + //socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); + struct timeval timeout; + timeout.tv_sec = 3;//3 + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + + /* + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = PF_INET; + + //localhost test + info.sin_addr.s_addr = inet_addr("127.0.0.1"); + info.sin_port = htons(accountData[0].account_port); + //socketإ TCP_PORT_IMAGE + socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ + + int err = -1; + +#if 1 + struct addrinfo *rp; + for (rp = host_info_list; rp != NULL; rp = rp->ai_next) { + + socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (socketfd == -1) { + printf("\nsocket error:%d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: socket error"); + } + else { + //printf("\n-------open getimage connected (%d)\n", socketfd); + + setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) { + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = socketfd; + + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 3; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + + socketRecords[i].used = 1; + //printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); + break; + } + else { + if (i == MAX_CLIENT_SOCKET - 1) { + closesocket(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + //printf("\n------------get snap with profile id:3\n"); + } + } + } + + if (socketfd != -1) { + break; + } + } + else { + closesocket(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + //printf("\n------------get snap with profile id:4\n"); + } + } + } +#endif + //printf("\n------------get snap with profile id:5\n"); + if (socketfd >= 0) { + char Authorization[2560] = { 0 }; + if (strlen(accountData[0].account_username) > 0) + { + //strcat(sendBuffer, "Authorization: Basic "); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + strcpy(Authorization, buf_account); + strcat(Authorization, ":"); + + if (strlen(accountData[0].account_password) > 0) { + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + strcat(Authorization, buf_account2); + } + } + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + if (strlen(Authorization) >= 1) + { + + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + } + + + char msg[2560] = { 0 }; + + sprintf(msg, "GET /getimage?profileid=%d HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", i_profileid, accountData[0].account_port); + + strcat(msg, "Authorization: Basic "); + strcat(msg, httpAuth); + strcat(msg, "\r\n"); + strcat(msg, "\r\n"); + + //printf("\n-----------msg:%s\n", msg); + //printf("\n------------get snap with profile id:6\n"); + err = send(socketfd, msg, strlen(msg), 0); + if (err == -1) { + printf("\nerror sending:%d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: error sending"); + + //exit(EXIT_FAILURE); + } + else { + getPicture(socketfd, MAX_IMG_SIZE, i_profileid, enable_check_profile_id); + } + //printf("\n------------get snap with profile id:7\n"); + closesocket(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) + { + //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + socketRecords[i].used = 0; + break; + } + } + + socketfd = -1; + //printf("\n------------get snap with profile id:8\n"); + } + else { + printf("\nCould not create socket!:%d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: Could not create socket!"); + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed #1\n"); + } + pthread_join(thread_id_getipcamsettings, NULL); + } + } + //printf("\n------------get snap with profile id:9\n"); + if (host_info_list != NULL) { + freeaddrinfo(host_info_list); + host_info_list = NULL; + } + //printf("\n------------get snap with profile id:10\n"); + } +} + +void *net_curl_https_post_push_info_attached_image(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("curl_attached"); + pthread_mutex_lock(&mutex_curl); + + char sUrl[8192] = { 0 }; + strcpy(sUrl, g_stCURL_send_data_curl_url); + char sData[MAX_IMG_SIZE] = { 0 }; + //size_t sData_size = g_stCURL_send_data_curl_sendbuf_size; + memcpy(sData, g_stCURL_send_data_curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); + char method[32] = { 0 }; + strcpy(method, g_stCURL_send_data_method); + char sProtocol[32] = { 0 }; + strcpy(sProtocol, g_stCURL_send_data_protocol); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, g_stCURL_send_data_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, g_stCURL_send_data_password); + int iPort = atoi(g_stCURL_send_data_port); + char sCustomizedHeader[8192] = { 0 }; + strcpy(sCustomizedHeader, g_stCURL_send_data_customized_header); + int itimeout = atoi(g_stCURL_send_data_timeout); + + char s_q_name[30] = { 0 }; + strcpy(s_q_name, g_stCURL_send_data_q_name); + char s_q_plate[60] = { 0 }; + strcpy(s_q_plate, g_stCURL_send_data_q_plate); + + size_t snapshot_size = 0; + CURLcode ret; + curl_mime *mime1; + curl_mimepart *part1; + struct curl_slist *slist1; + char g_snapshot_addr_to_net_curl[MAX_IMG_SIZE] = { 0 }; + + if (g_stCURL_image_buff_size >= 1) { + memcpy(g_snapshot_addr_to_net_curl,g_stCURL_image_buff, g_stCURL_image_buff_size); + snapshot_size = (size_t)g_stCURL_image_buff_size; + } + else { +#ifdef GY_OS_AMBA + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(g_snapshot_addr_to_net_curl); + pthread_mutex_unlock(&mutex_get_network_input); +#endif + } + + //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); + + //snapshot_size = get_snap_with_profile_id(g_snapshot_addr_to_net_curl, 1); + + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 0); + //snapshot_size = (size_t)get_ori_c_image(g_snapshot_addr_to_net_curl); + + if (g_http_handle != NULL && (int)snapshot_size >= 1) { + mime1 = NULL; + slist1 = NULL; + +#if 1 + slist1 = curl_slist_append(slist1, "charset: utf-8"); + slist1 = curl_slist_append(slist1, "Expect:"); + if (strcmp(method, "POST") == 0) + { + if ((int)strlen(sCustomizedHeader) >= 1) { + slist1 = curl_slist_append(slist1, sCustomizedHeader); + //slist1 = curl_slist_append(slist1, "CK:DKB2219EFF5PE5U3YS"); + } + curl_easy_setopt(g_http_handle, CURLOPT_CUSTOMREQUEST, "POST"); + } +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + //curl_easy_setopt(g_http_handle, CURLOPT_URL, "http://0922992430:DKB2219EFF5PE5U3YS@iot.cht.com.tw:80/iot/v1/device/28354474443/snapshot"); + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + mime1 = curl_mime_init(g_http_handle); + part1 = curl_mime_addpart(mime1); + //curl_mime_data(part1, "{\"id\":\"pedestrian\",\"lat\":22.663136,\"lon\":120.303307,\"value\":[\"silver\"]}", CURL_ZERO_TERMINATED); + curl_mime_data(part1, sData, CURL_ZERO_TERMINATED); + curl_mime_name(part1, "meta"); + part1 = curl_mime_addpart(mime1); + //curl_mime_filedata(part1, "/emmc/plugin/Aida_data/storage/snap_buf.jpg"); + curl_mime_data(part1, g_snapshot_addr_to_net_curl, snapshot_size); + curl_mime_type(part1, "image/jpg"); + curl_mime_name(part1, "image"); + + char temp_file_jpg_name[512] = { 0 }; + + if (g_stCURL_enable_filename_fixed==1) { + sprintf(temp_file_jpg_name,"%s.jpg", g_stCURL_send_jpeg_file_name); + } + else { + time_t rawtime = g_osdSysTimeStamp; + if (rawtime < 1000000000) { + rawtime = time(0); + } + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d_%02d_%02d_%02d_%02d_%02d_%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + sprintf(temp_file_jpg_name,"%s_%s.jpg", g_stCURL_send_jpeg_file_name, buf_time_info); + } + curl_mime_filename(part1, temp_file_jpg_name); + + curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, mime1); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, slist1); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + /* Here is a list of options the curl code used that cannot get generated + as source easily. You may select to either not use them or implement + them yourself. + + CURLOPT_WRITEDATA set to a objectpointer + CURLOPT_INTERLEAVEDATA set to a objectpointer + CURLOPT_WRITEFUNCTION set to a functionpointer + CURLOPT_READDATA set to a objectpointer + CURLOPT_READFUNCTION set to a functionpointer + CURLOPT_SEEKDATA set to a objectpointer + CURLOPT_SEEKFUNCTION set to a functionpointer + CURLOPT_ERRORBUFFER set to a objectpointer + CURLOPT_STDERR set to a objectpointer + CURLOPT_DEBUGFUNCTION set to a functionpointer + CURLOPT_DEBUGDATA set to a objectpointer + CURLOPT_HEADERFUNCTION set to a functionpointer + CURLOPT_HEADERDATA set to a objectpointer + + */ + + ret = curl_easy_perform(g_http_handle); + + /* Check for errors */ + if (ret != CURLE_OK) + { + /* if errors have occured, tell us wath's wrong with 'ret'*/ + sprintf(g_response_net_curl, "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(ret)); + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(ret)); + write_to_logs_html(temp_msg, "curl to post image", "ERROR", SystemSetting.enable_system_logs); + fprintf(stderr, "#1 curl_easy_perform() failed: %s\n", curl_easy_strerror(ret)); + + if (strstr(temp_msg, "Timeout was reached") != NULL || + strstr(temp_msg, "timeout was reached") != NULL || + strstr(temp_msg, "Couldn't resolve host name") != NULL || + strstr(temp_msg, "couldn't resolve host name") != NULL) { + g_check_ping_OK = 0; + } + } + else { + if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { + sprintf(g_response_net_curl, "Notification OK:%s,%s,%s", s_q_name, s_q_plate,ptr_responded_msg->memory); + //printf("\n[net attached image]:CURLE_OK:%s\n", ptr_responded_msg->memory); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); + write_to_logs_html(temp_msg, "curl to post image", "INFO", SystemSetting.enable_system_logs); + } + else { + sprintf(g_response_net_curl, "Notification OK:%s,%s", s_q_name, s_q_plate); + //printf("\n[net attached image]:CURLE_OK\n"); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s", s_q_name, s_q_plate); + write_to_logs_html(temp_msg, "curl to post image", "INFO", SystemSetting.enable_system_logs); + } + } + + curl_easy_reset(g_http_handle); + curl_mime_free(mime1); + mime1 = NULL; + curl_slist_free_all(slist1); + slist1 = NULL; + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + } + g_response_post_OK = 1; + pthread_mutex_unlock(&mutex_curl); + pthread_exit(NULL); + //return (int)ret; +} + +//#define LOCAL_FILE "/emmc/plugin/Aida_data/snap.jpg" +#define UPLOAD_FILE_AS "myuploading.jpg" +//#define REMOTE_URL "ftp://example.com/" UPLOAD_FILE_AS +#define RENAME_FILE_TO "myname.jpg" + +/* NOTE: if you want this example to work on Windows with libcurl as a + DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION. + Failing to do so will give you a crash since a DLL may not use the + variable's memory when passed in to it from an app like this. */ +static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) +{ + unsigned long nread; + /* in real-world cases, this would probably get this data differently + as this fread() stuff is exactly what the library already would do + by default internally */ + size_t retcode = fread(ptr, size, nmemb, stream); + + if (retcode > 0) { + nread = (unsigned long)retcode; + fprintf(stderr, "*** We read %lu bytes from file\n", nread); + } + + return retcode; +} + +void net_curl_ftp_build_folder() +{ + + char sUrl[8192] = { 0 }; + strcpy(sUrl, "ftp://"); + strcat(sUrl, SystemSetting.ftp_url); + strcat(sUrl, "/"); + + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, SystemSetting.ftp_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, SystemSetting.ftp_password); + int iPort = atoi(SystemSetting.ftp_port); + + char spilt_folder[50][STRSPLIT_SIZE]={0}; + const char *del = "/"; + int num_spilt_folder = 0; + + char temp_buildfolder[1024] = { 0 }; + strcpy(temp_buildfolder,SystemSetting.ftp_remote_directory); + + if (strlen(temp_buildfolder) >= 1) { + num_spilt_folder = StrSplit(temp_buildfolder, spilt_folder, del); + //printf("\n------UU:20\n"); + for (int i = 0; i < num_spilt_folder; i++) { + char buildfolder[1024] = { 0 }; + + if (strlen(spilt_folder[i]) >= 1) { + + strcpy(buildfolder, "MKD "); + for (int j = 0; j <= i; j++) + { + strcat(buildfolder, spilt_folder[j]); + if (j < i) { + strcat(buildfolder, "/"); + } + } + + CURLcode res; + struct curl_slist *headerlist = NULL; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle) { + + headerlist = curl_slist_append(headerlist, buildfolder); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + + /* enable uploading */ + //curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + /* specify target */ + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + /* pass in that last of FTP commands to run after the transfer */ + curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); + + + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 䴩 + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + + /* Now run off and do what you have been told! */ + res = curl_easy_perform(g_http_handle); + /* Check for errors */ + if (res != CURLE_OK) { + fprintf(stderr, "#2 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + write_to_logs_html(temp_msg, "curl ftp to build folder", "ERROR", SystemSetting.enable_system_logs); + //check_if_build_new_dir = 0; + } + else { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg,"OK"); + write_to_logs_html(temp_msg, "curl ftp to build folder", "INFO", SystemSetting.enable_system_logs); + } + + /* clean up the FTP commands list */ + curl_slist_free_all(headerlist); + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + } + } + } +} + +void net_curl_ftp_delete_file() { + if (strcmp(SystemSetting.ftp_jpeg_file_name_format, "fixed") == 0) { + char sUrl[8192] = { 0 }; + strcpy(sUrl, "ftp://"); + strcat(sUrl, SystemSetting.ftp_url); + strcat(sUrl, "/"); + + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, SystemSetting.ftp_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, SystemSetting.ftp_password); + int iPort = atoi(SystemSetting.ftp_port); + + char temp_file_jpg_name[512] = { 0 }; + sprintf(temp_file_jpg_name, "%s.jpg", SystemSetting.ftp_jpeg_file_name); + + char buildfolder[2048] = { 0 }; + strcpy(buildfolder, "DELE "); + strcat(buildfolder, SystemSetting.ftp_remote_directory); + strcat(buildfolder,"/"); + strcat(buildfolder, temp_file_jpg_name); + + CURLcode res; + struct curl_slist *headerlist = NULL; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle) { + + headerlist = curl_slist_append(headerlist, buildfolder); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + + /* enable uploading */ + //curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + /* specify target */ + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + /* pass in that last of FTP commands to run after the transfer */ + curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); + + + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 䴩 + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + + /* Now run off and do what you have been told! */ + res = curl_easy_perform(g_http_handle); + /* Check for errors */ + if (res != CURLE_OK) { + fprintf(stderr, "#3 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + write_to_logs_html(temp_msg, "curl ftp to delete file", "ERROR", SystemSetting.enable_system_logs); + + //check_if_build_new_dir = 0; + } + else { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg, "OK"); + write_to_logs_html(temp_msg, "curl ftp to delete image", "INFO", SystemSetting.enable_system_logs); + } + /* clean up the FTP commands list */ + curl_slist_free_all(headerlist); + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + } +} + +void net_curl_ftp_post_push_info_attached_image(char* image_buff, int image_buff_size) +{ + net_curl_ftp_delete_file(); + if (image_buff_size >= 1) { + char write_filename[256] = "/emmc/plugin/Aida_data/"; + strcat(write_filename, "snap.jpg"); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + fwrite(image_buff, sizeof(char), image_buff_size, fp); + fclose(fp); + + char sUrl[8192] = { 0 }; + strcpy(sUrl, "ftp://"); + strcat(sUrl, SystemSetting.ftp_url); + strcat(sUrl, "/"); + strcat(sUrl, UPLOAD_FILE_AS); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, SystemSetting.ftp_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, SystemSetting.ftp_password); + int iPort = atoi(SystemSetting.ftp_port); + + char temp_file_jpg_name[512] = { 0 }; + if (strcmp(SystemSetting.ftp_jpeg_file_name_format,"fixed")==0) { + sprintf(temp_file_jpg_name, "%s.jpg", SystemSetting.ftp_jpeg_file_name); + } + else { + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d_%02d_%02d_%02d_%02d_%02d_%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + sprintf(temp_file_jpg_name, "%s_%s.jpg", SystemSetting.ftp_jpeg_file_name, buf_time_info); + } + + + char sFileto[1024] = { 0 }; + strcpy(sFileto, "RNTO "); + strcat(sFileto, "../"); + if (strlen(SystemSetting.ftp_remote_directory) >= 1) { + strcat(sFileto, SystemSetting.ftp_remote_directory); + strcat(sFileto, "/"); + } + strcat(sFileto, temp_file_jpg_name);//RENAME_FILE_TO + + //printf("\n------sFileto:%s\n", sFileto); + + CURLcode res; + FILE *hd_src; + struct stat file_info; + unsigned long fsize; + + struct curl_slist *headerlist = NULL; + //MKD bbDir + static const char buf_1[] = "RNFR " UPLOAD_FILE_AS; + //static const char buf_2[] = "RNTO " RENAME_FILE_TO; + //printf("\n------buf_2:%s\n", buf_2); + + /* get the file size of the local file */ + if (stat(write_filename, &file_info)) { + printf("Couldn't open '%s': %s\n", write_filename, strerror(errno)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Couldn't open '%s': %s", write_filename, strerror(errno)); + write_to_logs_html(temp_msg, "curl ftp to post image", "ERROR", SystemSetting.enable_system_logs); + } + else { + fsize = (unsigned long)file_info.st_size; + + printf("Local file size: %lu bytes.\n", fsize); + + /* get a FILE * of the same file */ + hd_src = fopen(write_filename, "rb"); + pthread_mutex_lock(&mutex_curl); + if (g_http_handle && hd_src != NULL) { + /* build a list of commands to pass to libcurl */ + headerlist = curl_slist_append(headerlist, buf_1); + headerlist = curl_slist_append(headerlist, sFileto); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + + /* we want to use our own read function */ + curl_easy_setopt(g_http_handle, CURLOPT_READFUNCTION, read_callback); + + /* enable uploading */ + curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + /* specify target */ + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + /* pass in that last of FTP commands to run after the transfer */ + curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); + + /* now specify which file to upload */ + curl_easy_setopt(g_http_handle, CURLOPT_READDATA, hd_src); + + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + curl_easy_setopt(g_http_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize); + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 䴩 + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + + /* Now run off and do what you have been told! */ + res = curl_easy_perform(g_http_handle); + /* Check for errors */ + if (res != CURLE_OK) { + fprintf(stderr, "#4 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + //check_if_build_new_dir = 0; + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + write_to_logs_html(temp_msg, "curl ftp to post image", "ERROR", SystemSetting.enable_system_logs); + } + else { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg, "OK"); + write_to_logs_html(temp_msg, "curl ftp to post image", "INFO", SystemSetting.enable_system_logs); + } + /* clean up the FTP commands list */ + curl_slist_free_all(headerlist); + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + if (hd_src != NULL) { + fclose(hd_src); /* close the local file */ + hd_src = NULL; + } + } + } + else + printf("net curl ftp] (For debugging) Error occurred when opening file I/O.\n"); + } +} + +#if 1 +void *net_curl_https_post_push_info(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("curl_post"); +#if 1 + pthread_mutex_lock(&mutex_curl); + //CURLM *multi_handle = NULL; + + //CURL_SEND *stCURL_send_data; + //stCURL_send_data = (CURL_SEND *)p_stCURL_send_data; + //memset(&stCURL_send_data, 0x00, sizeof(stCURL_send_data)); + + char sUrl[8192] = { 0 }; + strcpy(sUrl,g_stCURL_send_data_curl_url); + char sData[MAX_IMG_SIZE] = { 0 }; + size_t sData_size = g_stCURL_send_data_curl_sendbuf_size; + memcpy(sData, g_stCURL_send_data_curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); + char method[32] = { 0 }; + strcpy(method, g_stCURL_send_data_method); + char sProtocol[32] = { 0 }; + strcpy(sProtocol, g_stCURL_send_data_protocol); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, g_stCURL_send_data_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, g_stCURL_send_data_password); + int iPort = atoi(g_stCURL_send_data_port); + char sCustomizedHeader[8192] = { 0 }; + strcpy(sCustomizedHeader, g_stCURL_send_data_customized_header); + + int itimeout = atoi(g_stCURL_send_data_timeout); + + char s_q_name[30] = { 0 }; + strcpy(s_q_name, g_stCURL_send_data_q_name); + char s_q_plate[60] = { 0 }; + strcpy(s_q_plate, g_stCURL_send_data_q_plate); + + char l_smtp_capath[512] = { 0 }; + strcpy(l_smtp_capath, CURL_SMTP_CAPATH); + + //curl_mime* form = NULL; + //curl_mimepart* mimepart = NULL; + + + + //int still_running = 0; /* keep number of running handles */ + //int repeats = 0; + + //usSleep(100); + //usSleep(1000000); + + //const int timeout = 30000; + /*int timeout = 5; + if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) + timeout = 5; + else + timeout = 1;*/ + + //multi_handle = curl_multi_init(); + + //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); + //size_t snapshot_size = 0; + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 1); + + int check_reboot = 0; + + if (g_http_handle != NULL /*& multi_handle != NULL*/) + { + //form = curl_mime_init(g_http_handle); + + //struct curl_slist *pList = NULL; + // + + + struct curl_slist *pList = NULL; + //struct curl_slist *f_list = NULL; + + //pList = curl_slist_append(pList, "Accept: application/json"); + //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Content-Type: application/json"); + pList = curl_slist_append(pList, "Expect:"); + +#if 1 + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type: text/html; charset=utf-8"); + if ((int)strlen(sCustomizedHeader) >= 1) { + pList = curl_slist_append(pList, sCustomizedHeader); + } + //pList = curl_slist_append(pList, "X-Api-Key: AAAAAAAAAAA");//Tgk + //curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, "Content-Type: text/html; charset=utf-8"); + } +#endif + + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + + //printf("[%s] url: [%s]\n", __func__, "oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/4zxou-1615769161/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + /*if (g_stCURL_check_127 == 0)*/ + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + //printf("\n---------sUserNmae:%s\n", sUserNmae); + //printf("\n---------sPassWord:%s\n", sPassWord); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + /* + if (strcmp(sProtocol, "HTTPS") == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); + } + else {*/ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + //} + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + if (strcmp(method, "POST") == 0) + { + //printf("\nsData_size:%d\n",(int)sData_size); + //printf("\n%s\n", sData); + //fwrite(sData, 1, sData_size, stdout); + + + if (sData_size >= 1) { + + + curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, sData_size); + + //mimepart = curl_mime_addpart(form); + //curl_mime_name(mimepart, "meta"); + //curl_mime_type(mimepart, "text/plain"); + //curl_mime_data(mimepart, sData, sData_size); + } + + /* + if ((int)snapshot_size >= 1) + { + // Fill in the filename field + mimepart = curl_mime_addpart(form); + + f_list = curl_slist_append(f_list, "Content-Transfer-Encoding: 8bit"); + char temp_content_range[128] = { 0 }; + char temp_content_length[128] = { 0 }; + sprintf(temp_content_range , "Content-Range 0-%d/%d",(int)(snapshot_size-1), (int)snapshot_size); + sprintf(temp_content_length, "Content-Length %d", (int)snapshot_size); + f_list = curl_slist_append(f_list, temp_content_range); + f_list = curl_slist_append(f_list, temp_content_length); + + curl_mime_name(mimepart, "image"); + curl_mime_headers(mimepart, f_list, 1); + curl_mime_filedata(mimepart, "./storage/snap_buf.jpg"); + //curl_mime_data(mimepart, g_snapshot_addr_to_net_curl, snapshot_size); + } + curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, form); + */ + //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, outputmessage); + //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, strlen(outputmessage)); + curl_easy_setopt(g_http_handle, CURLOPT_POST, 1L); + } + CURLcode result = CURLE_FAILED_INIT; + //printf("\n-------------result:start\n"); + TRY + { + //printf("In Try Statement\n"); + result = curl_easy_perform(g_http_handle); + //THROW; + //printf("I do not appear\n"); + } + CATCH + { + result = CURLE_FAILED_INIT; + //printf("Got Exception!\n"); + } + ETRY; + //printf("\n-------------result:%d\n", (int)result); + + /* Check for errors */ + if (result != CURLE_OK) + { + /* if errors have occured, tell us wath's wrong with 'ret'*/ + sprintf(g_response_net_curl, "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(result)); + fprintf(stderr, "#5 curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(result)); + write_to_logs_html(temp_msg, "curl to post", "ERROR", SystemSetting.enable_system_logs); + + if (strstr(temp_msg, "Timeout was reached") != NULL || + strstr(temp_msg, "timeout was reached") != NULL || + strstr(temp_msg, "Couldn't resolve host name") != NULL || + strstr(temp_msg, "couldn't resolve host name") != NULL) { + g_check_ping_OK = 0; + } + + //printf("\n--------Notification failed:%s\n", curl_easy_strerror(result)); + } + else { + if (ptr_responded_msg!=NULL && ptr_responded_msg->size >= 1) { + sprintf(g_response_net_curl, "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); + //printf("\n[net curl https]:CURLE_OK:%s\n", ptr_responded_msg->memory); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); + write_to_logs_html(temp_msg, "curl to post", "INFO", SystemSetting.enable_system_logs); + } + else { + sprintf(g_response_net_curl, "Notification OK:%s,%s", s_q_name, s_q_plate); + //printf("\n[net curl https]:CURLE_OK\n"); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s", s_q_name, s_q_plate); + write_to_logs_html(temp_msg, "curl to post", "INFO", SystemSetting.enable_system_logs); + + } + } + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); +#if 0 + curl_multi_add_handle(multi_handle, g_http_handle); + curl_multi_perform(multi_handle, &still_running); + + //curl_multi_add_handle(g_multi_handle, curl); + //curl_multi_perform(g_multi_handle, &g_handle_count); +#endif + //Clean curl_ease ver2 +#if 0 + int repeats = 0; + while (still_running) { + CURLMcode mc; + int numfds; + + mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); + + if (mc != CURLM_OK) { + printf("\ncurl_multi_wait() failed, code %d.\n", mc); + break; + } + + if (!numfds) { + repeats++; /* count number of repeated zero numfds */ + if (repeats > 1) { + usSleep(100000); /* sleep 100 milliseconds */ + } + } + else + repeats = 0; + + //printf("Wait repeats %d \n", repeats); + + curl_multi_perform(multi_handle, &still_running); + } +#endif + +#if 1 + if (result == CURLE_OUT_OF_MEMORY) { + printf("\n[net curl https post push info]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + + check_reboot = 1; + } +#endif + + //curl_mime_free(form); + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + } + + + //curl_multi_remove_handle(multi_handle, g_http_handle); + //curl_multi_cleanup(multi_handle); + //g_http_handle = NULL; + +#endif + g_response_post_OK = 1; + pthread_mutex_unlock(&mutex_curl); + + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "curl to post", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "curl to post", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } + + pthread_exit(NULL); +} +#endif + +#ifdef GY_OS_AMBA +void *net_curl_https_get_other_lpr_db(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("curl_lpr"); +#if 1 + pthread_mutex_lock(&mutex_curl); + //CURLM *multi_handle = NULL; + + //CURL_SEND *stCURL_send_data; + //stCURL_send_data = (CURL_SEND *)p_stCURL_send_data; + //memset(&stCURL_send_data, 0x00, sizeof(stCURL_send_data)); + + + + char sUrl[8192] = { 0 }; + strcpy(sUrl, g_stCURL_lpr_db_url); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, g_stCURL_lpr_db_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, g_stCURL_lpr_db_password); + int iPort = atoi(g_stCURL_lpr_db_port); + + + + //char l_smtp_capath[512] = { 0 }; + //strcpy(l_smtp_capath, CURL_SMTP_CAPATH); + + //curl_mime* form = NULL; + //curl_mimepart* mimepart = NULL; + + + + //int still_running = 0; /* keep number of running handles */ + //int repeats = 0; + + //usSleep(100); + //usSleep(1000000); + + //const int timeout = 30000; + /*int timeout = 5; + if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) + timeout = 5; + else + timeout = 1;*/ + + //multi_handle = curl_multi_init(); + + //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); + //size_t snapshot_size = 0; + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 1); + int check_reboot = 0; + if (g_http_handle != NULL /*& multi_handle != NULL*/) + { + //form = curl_mime_init(g_http_handle); + + //struct curl_slist *pList = NULL; + // + + + struct curl_slist *pList = NULL; + //struct curl_slist *f_list = NULL; + + //pList = curl_slist_append(pList, "Accept: application/json"); + //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Content-Type: application/json"); + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + + //printf("[%s] url: [%s]\n", __func__, "oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/4zxou-1615769161/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + /*if (g_stCURL_check_127 == 0)*/ + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + /* + if (strcmp(sProtocol, "HTTPS") == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); + } + else {*/ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + //} + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + CURLcode result = CURLE_FAILED_INIT; + //printf("\n-------------result:start\n"); + TRY + { + //printf("In Try Statement\n"); + result = curl_easy_perform(g_http_handle); + //THROW; + //printf("I do not appear\n"); + } + CATCH + { + result = CURLE_FAILED_INIT; + //printf("Got Exception!\n"); + } + ETRY; + //printf("\n-------------result:%d\n", (int)result); + + /* Check for errors */ + if (result != CURLE_OK) + { + /* if errors have occured, tell us wath's wrong with 'ret'*/ + sprintf(g_response_lpr_db, "Notification failed:%s", curl_easy_strerror(result)); + fprintf(stderr, "#6 curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(result)); + write_to_logs_html(temp_msg, "curl to post to get lpr db", "ERROR", SystemSetting.enable_system_logs); + } + else { + if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { + sprintf(g_response_lpr_db, "Notification OK size:%ld", ptr_responded_msg->size);//ptr_responded_msg->memory + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char DB_FFLPR_IMPORT_PATH[1024]; + strcpy(DB_FFLPR_IMPORT_PATH, exePath); + strcat(DB_FFLPR_IMPORT_PATH, "db_fflpr_import.db"); + + + FILE *f = fopen(DB_FFLPR_IMPORT_PATH, "w"); + if (f != NULL) + { + fwrite(ptr_responded_msg->memory, ptr_responded_msg->size, 1, f); + fclose(f); + } + + printf("\n[net lpr db]:CURLE_OK size:%ld\n", ptr_responded_msg->size); + get_fflpr_db_import(); +#if 0 + if (unlockingKeyInnoFR == 1) { + get_face_db_import();// face - leo + } +#endif + } + else { + strcpy(g_response_lpr_db, "Notification OK"); + printf("\n[net lpr db]:CURLE_OK\n"); + } + } + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); +#if 0 + curl_multi_add_handle(multi_handle, g_http_handle); + curl_multi_perform(multi_handle, &still_running); + + //curl_multi_add_handle(g_multi_handle, curl); + //curl_multi_perform(g_multi_handle, &g_handle_count); +#endif + //Clean curl_ease ver2 +#if 0 + int repeats = 0; + while (still_running) { + CURLMcode mc; + int numfds; + + mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); + + if (mc != CURLM_OK) { + printf("\ncurl_multi_wait() failed, code %d.\n", mc); + break; + } + + if (!numfds) { + repeats++; /* count number of repeated zero numfds */ + if (repeats > 1) { + usSleep(100000); /* sleep 100 milliseconds */ + } + } + else + repeats = 0; + + //printf("Wait repeats %d \n", repeats); + + curl_multi_perform(multi_handle, &still_running); + } +#endif + +#if 1 + if (result == CURLE_OUT_OF_MEMORY) { + printf("\n[net curl https post push info]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "net curl https get other lpr db", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "net curl https get other lpr db", "CGI_REBOOT"); + + check_reboot = 1; + } +#endif + + //curl_mime_free(form); + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + } + + + //curl_multi_remove_handle(multi_handle, g_http_handle); + //curl_multi_cleanup(multi_handle); + //g_http_handle = NULL; + +#endif + g_response_post_OK = 1; + pthread_mutex_unlock(&mutex_curl); + + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "curl to post to get lpr db", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "curl to post to get lpr db", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } + + pthread_exit(NULL); +} +#endif +#ifdef GY_OS_AMBA +size_t SetSNMPRequest(QueueInfo *q_info) +{ + + if(strlen(q_info->snmp_version)>=1 && + strlen(q_info->snmp_group_name) >= 1 && + strlen(q_info->snmp_host_ip) >= 1 && + strlen(q_info->snmp_host_port) >= 1 && + strlen(q_info->snmp_oid) >= 1 && + strlen(q_info->snmp_value) >= 1 && + strlen(q_info->snmp_type) >= 1 + ) + { + FILE * pPipe; + char cmd[8192*4] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10 /bin/snmpset -%s -c %s %s:%s %s %s %s", + q_info->snmp_version, + q_info->snmp_group_name, + q_info->snmp_host_ip, + q_info->snmp_host_port, + q_info->snmp_oid, + q_info->snmp_type, + q_info->snmp_value); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) { + char path[1024] = { 0 }; + while (fgets(path, sizeof(path), pPipe) != NULL) + { + sprintf(g_response_snmp, "free:%d,%s,SNMP OK: %s", get_free_mem_data(), cmd, path); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP OK: %s", get_free_mem_data(), cmd, path); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "INFO", SystemSetting.enable_system_logs); + + break; + } + if (strlen(path) == 0) { + sprintf(g_response_snmp, "free:%d,%s,SNMP OK: Fail, no response.", get_free_mem_data(), cmd); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP OK: Fail, no response.", get_free_mem_data(), cmd); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); + + } + vpclose(pPipe); + } + else { + sprintf(g_response_snmp, "free:%d,%s,SNMP snmpset Fail.", get_free_mem_data(), cmd); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP snmpset Fail.", get_free_mem_data(),cmd); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); + } + } + else { + printf("\n[Set SNMP Request]SNMP was set wrongly.\n"); + sprintf(g_response_snmp,"free:%d,SNMP Format Failed.", get_free_mem_data()); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,SNMP Format Failed.", get_free_mem_data()); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); + } + + for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) + { + if (strlen(q_info->snmp_event_name) >= 1 && strcmp(q_info->snmp_event_name, SNMPManagementList[j].snmp_event_name) == 0) + { + SNMPManagementList[j].check_if_delivering = 0; + break; + } + } + + return 0; +} +#endif +#ifdef GY_OS_NOVA +size_t SetHttpRequest_sock(QueueInfo *q_info, char* sendBuffer, char* method) +{ + char sock_sendbuf[MAX_IMG_SIZE] = { 0 }; + char sock_url[8192] = { 0 }; + //size_t content_size_sendbuf = 0; + + char sock_method[32] = { 0 }; + char sock_protocol[32] = { 0 }; + char sock_username[64] = { 0 }; + char sock_password[64] = { 0 }; + char sock_port[10] = { 0 }; + char sock_header[8192] = { 0 }; + + if (strcmp(method, "POST") == 0) + { + if ((int)q_info->content_size >= 1) { + memcpy(sock_sendbuf, q_info->content, (int)q_info->content_size); + } + } + + + if (strcmp(q_info->post_protocol, "HTTP") == 0) { + strcpy(sock_url, "http://"); + } + else { + strcpy(sock_url, "https://"); + } + + if (strcmp(q_info->host_name, "127.0.0.1") != 0 && strcmp(q_info->host_name, "localhost") != 0) { + //if (strlen(q_info->post_username) >= 1) { + //strcat(sock_url, q_info->post_username); + //strcat(sock_url, ":"); + //strcat(sock_url, q_info->post_password); + //strcat(sock_url, "@"); + //} + strcat(sock_url, q_info->host_name); + } + else { + strcpy(q_info->host_name, "127.0.0.1"); + strcat(sock_url, q_info->host_name); + } + + if (strlen(q_info->host_port) >= 1) { + strcat(sock_url, ":"); + strcat(sock_url, q_info->host_port); + } + + //strcat(sock_url, q_info->post_url); + //content_size_sendbuf = q_info->content_size; + strcpy(sock_method, method); + strcpy(sock_protocol, q_info->post_protocol); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)q_info->post_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)q_info->post_password, (unsigned char *)buf_account2); + + strcpy(sock_username, buf_account); + strcpy(sock_password, buf_account2); + strcpy(sock_port, q_info->host_port); + strcpy(sock_header, q_info->post_customized_header); + + /* + g_stCURL_enable_attached_image = 0; + g_stCURL_enable_attached_image = q_info->enable_attached_image; + g_stCURL_enable_filename_fixed = 0; + g_stCURL_enable_filename_fixed = q_info->enable_filename_fixed; + strcpy(g_stCURL_send_jpeg_file_name, q_info->post_jpeg_file_name); + + if (q_info->image_buff_size >= 1) { + memcpy(g_stCURL_image_buff, q_info->image_buff, q_info->image_buff_size); + g_stCURL_image_buff_size = q_info->image_buff_size; + } + else { + g_stCURL_image_buff_size = 0; + }*/ + + { + //int snapshot_size = 0; + + int status; + struct addrinfo host_info; + struct addrinfo *host_info_list = NULL; + + memset(&host_info, 0, sizeof(host_info)); + + host_info.ai_family = AF_INET;//AF_UNSPEC + host_info.ai_socktype = SOCK_STREAM; + host_info.ai_protocol = 0; + + status = getaddrinfo("127.0.0.1", sock_port, &host_info, &host_info_list); + if (status != 0) { + printf("\n[SetHttpRequest sock]getaddrinfo error\n"); + strcpy(g_response_net_curl,"getaddrinfo error"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else + { + + int socketfd = -1;; + //socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); + struct timeval timeout; + timeout.tv_sec = 3;//3 + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + + /* + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = PF_INET; + + //localhost test + info.sin_addr.s_addr = inet_addr("127.0.0.1"); + info.sin_port = htons(accountData[0].account_port); + //socketإ TCP_PORT_IMAGE + socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ + + int err = -1; + +#if 1 + struct addrinfo *rp; + for (rp = host_info_list; rp != NULL; rp = rp->ai_next) { + + socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (socketfd == -1) { + printf("\n[SetHttpRequest sock]socket error\n"); + strcpy(g_response_net_curl, "socket error"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else { + //printf("\n-------open getimage connected (%d)\n", socketfd); + + setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) { + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = socketfd; + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 3; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + socketRecords[i].used = 1; + //printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); + break; + } + else { + if (i == MAX_CLIENT_SOCKET - 1) { + close(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + } + } + } + + if (socketfd != -1) { + break; + } + } + else { + close(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + } + } + } +#endif + + if (socketfd >= 0) { + char Authorization[2560] = { 0 }; + if (strlen(sock_username) > 0) + { + //strcat(sendBuffer, "Authorization: Basic "); + strcpy(Authorization, sock_username); + strcat(Authorization, ":"); + + if (strlen(sock_password) > 0) + strcat(Authorization, sock_password); + } + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + if (strlen(Authorization) >= 1) + { + + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + } + + //printf("\n------httpAuth:%s\n", httpAuth); + + char msg[2560] = { 0 }; + sprintf(msg, "%s %s HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", sock_method, q_info->post_url, sock_port); + + strcat(msg, "Authorization: Basic "); + strcat(msg, httpAuth); + strcat(msg, "\r\n"); + strcat(msg, "\r\n"); + + //printf("\n-----------msg:%s\n", msg); + + err = send(socketfd, msg, strlen(msg), 0); + if (err == -1) { + printf("\n[SetHttpRequest sock]error sending\n"); + strcpy(g_response_net_curl, "error sending"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else { + char b_buffer[MAX_IMG_SIZE] = { 0 }; + //size_t bReceived; + + /*bReceived = */recv(socketfd, b_buffer, MAX_IMG_SIZE, 0); + //printf("\n[SetHttpRequest sock]------:%s\n", b_buffer); + if (strstr(b_buffer, "200") != NULL) { + strcpy(g_response_net_curl, "OK"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "INFO", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else { + strcpy(g_response_net_curl, "error response"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + } + + close(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) + { + //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + socketRecords[i].used = 0; + break; + } + } + + socketfd = -1; + } + else { + printf("\n[SetHttpRequest sock]Could not create socket!\n"); + strcpy(g_response_net_curl, "Could not create socket!"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + } + + if (host_info_list != NULL) { + freeaddrinfo(host_info_list); + host_info_list = NULL; + } + } +} +#endif + +size_t SetHttpRequest(QueueInfo *q_info, char* sendBuffer, char* method) +{ + +#if 1 + // Declare and initialize variables + //SOCKET sock; + //char* ip = NULL; + //char HostName[MAX_MSG_LEN] = { 0 }; // an IP address or a hostname, like "www.google.com" by itself + //char HostPort[10] = { 0 }; + //unsigned char Authorization[2560] = { 0 }; + //char Temp[MAX_MSG_LEN] = { 0 }; + //size_t sendLen = 0; + + //struct addrinfo* result = NULL; + //struct addrinfo* ptr = NULL; + //struct addrinfo hints = { 0 }; + //struct sockaddr_in* sockaddr_ipv4 = NULL; + + /*if (MapFind("<post_host_name>", Value)) + strcpy(HostName, Value); + + if (MapFind("<post_host_port>", Value)) + strcpy(HostPort, Value);*/ + + //hints.ai_flags = AI_NUMERICHOST; + + /* + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + */ + char curl_sendbuf[MAX_IMG_SIZE] = ""; + char curl_url[8192] = ""; + +#ifdef FOR_CC_POST +#else + //DWORD ret = getaddrinfo(HostName, "http", &hints, &result); + DWORD ret = getaddrinfo(q_info->host_name, q_info->host_port, &hints, &result); + if (ret != 0) { + printf("\ngetaddrinfo failed with error: %d\n", ret); + return 1; + } + + for (ptr = result; ptr != NULL; ptr = ptr->ai_next) + { + sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); + + /*printf("\nsock: %d\n",sock); + printf("\nptr->ai_addrlen: %d\n",ptr->ai_addrlen);*/ + + if (sock == -1) + continue; + + if (connect(sock, ptr->ai_addr, ptr->ai_addrlen) != -1) + { + break; /* Success */ + } + + close(sock); + //closesocket(sock); + } + + if (ptr == NULL) + { + // jwg list ̫ALksu + fprintf(stderr, "Failed to send POST to %s%s:%s\n", "http://", q_info->host_name, q_info->host_port); + return 1; + } + + if (ptr->ai_family == AF_INET) + { + sockaddr_ipv4 = (struct sockaddr_in *) ptr->ai_addr; + ip = inet_ntoa(sockaddr_ipv4->sin_addr); + //printf("ip address=%s\n", ip); + } + freeaddrinfo(result); // servinfo OŶ +#endif + //http first line + //if (featureType & FEATURE_LPR_TUR) + { +#if 0 + strcat(sendBuffer, method); + strcat(sendBuffer, " "); + /*if (MapFind("<post_url>", Value)) + { + if(Value[0]=='/') + strcat(sendBuffer, Value); + else + { + strcat(sendBuffer, "/"); + strcat(sendBuffer, Value); + } + } + else + strcat(sendBuffer, "/");*/ + + if (q_info->post_url[0] == '/') + strcat(sendBuffer, q_info->post_url); + else + { + strcat(sendBuffer, "/"); + strcat(sendBuffer, q_info->post_url); + } + + strcat(sendBuffer, " "); + strcat(sendBuffer, "HTTP/1.1"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Host: "); + strcat(sendBuffer, q_info->host_name); + if (strlen(q_info->host_port) > 0) + { + strcat(sendBuffer, ":"); + strcat(sendBuffer, q_info->host_port); + } + + /*strcat(sendBuffer, "Host: "); + strcat(sendBuffer, q_info->host_name); + + if (MapFind("<post_host_name>", Value)) + { + strcat(sendBuffer, Value); + if (MapFind("<post_host_port>", Value)) + { + strcat(sendBuffer, ":"); + strcat(sendBuffer, Value); + } + }*/ + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Cache-Control: no-cache"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "User-Agent: IPVideo"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Accept: */*"); + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); + strcat(sendBuffer, "\r\n"); +#endif + +#if 0 + size_t contentLen = strlen(q_info->content); + + sprintf(Temp, "%ld", contentLen); + strcat(sendBuffer, "Content-Length: "); + strcat(sendBuffer, Temp); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Connection: Closed"); + strcat(sendBuffer, "\r\n"); + + if (strlen(q_info->post_username) > 0) + { + strcat(sendBuffer, "Authorization: Basic "); + strcpy(Authorization, q_info->post_username); + strcat(Authorization, ":"); + + if (strlen(q_info->post_password) > 0) + strcat(Authorization, q_info->post_password); + } +#endif + /*strcat(sendBuffer, "Authorization: Basic "); + if (MapFind("<post_username>", Value)) + strcpy(Authorization, Value); + if (MapFind("<post_password>", Value)) + { + strcat(Authorization, ":"); + strcat(Authorization, Value); + }*/ +#if 0 + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + strcpy(httpAuth,base64_encode(Authorization, strlen(Authorization), &base64_encode_length)); + httpAuth[base64_encode_length] = '\0'; + //*(httpAuth + base64_encode_length-1) = '6'; + + strcat(sendBuffer, httpAuth); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); +#endif + +#if 0 + size_t headerLen = strlen(sendBuffer); + /*if (MapFind("<post_content>", Value)) + { + strcat(sendBuffer, Value); + contentLen = strlen(Value); + }*/ + + //printf("sendBuffer= %s\n", sendBuffer); + //size_t headerLen = strlen(sendBuffer); + size_t totalLen = headerLen; +#endif + if (strcmp(method, "POST") == 0) + { +#if 0 + contentLen = strlen(q_info->content); + + memset(curl_sendbuf, 0, sizeof(curl_sendbuf)); +#endif + if ((int)q_info->content_size >= 1) { + memcpy(curl_sendbuf, q_info->content, (int)q_info->content_size); + } + +#if 0 + memcpy(curl_sendbuf, q_info->content, strlen(q_info->content)); + memcpy(sendBuffer + headerLen, q_info->content, contentLen); + totalLen = headerLen + contentLen; +#endif + } + + //printf("send= %s\n", sendBuffer); + +#if 0 + if (strcmp(q_info->post_protocol, "HTTPS") == 0) + { + strcat(curl_url, "https://"); + strcat(curl_url, q_info->host_name); + strcat(curl_url, q_info->post_url); + + printf("Https curl_url: %s \n", curl_url); + + memset(&g_stCURL_send_data, 0, sizeof(g_stCURL_send_data)); + + strncpy(g_stCURL_send_data.curl_url, curl_url, strlen(curl_url)); + strncpy(g_stCURL_send_data.curl_sendbuf, curl_sendbuf, strlen(curl_sendbuf)); + strncpy(g_stCURL_send_data.method, method, strlen(method)); + strncpy(g_stCURL_send_data.username, q_info->post_username, strlen(q_info->post_username)); + strncpy(g_stCURL_send_data.password, q_info->post_password, strlen(q_info->post_password)); + strncpy(g_stCURL_send_data.port, q_info->host_port, strlen(q_info->host_port)); + + + pthread_t curl_thread_id; + if (pthread_create(&curl_thread_id, 0, net_curl_https_post_push_info, NULL)) + { + printf("create curl thread faile \n"); + } + + //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL); + //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL, method, + // q_info->post_username, q_info->post_password, strtol(q_info->host_port, NULL, 10)); + } + else +#endif + { + if (strcmp(q_info->post_protocol, "HTTP") == 0) { + strcat(curl_url, "http://"); + } + else { + strcat(curl_url, "https://"); + } + + if (strcmp(q_info->host_name, "127.0.0.1") != 0 && strcmp(q_info->host_name, "localhost") != 0) { + g_stCURL_check_127 = 0; + //if (strlen(q_info->post_username) >= 1 /*&& strlen(q_info->post_password) >= 1*/) { + //strcat(curl_url, q_info->post_username); + //strcat(curl_url, ":"); + //strcat(curl_url, q_info->post_password); + //strcat(curl_url, "@"); + //} + strcat(curl_url, q_info->host_name); + } + else { + g_stCURL_check_127 = 1; + strcpy(q_info->host_name, "127.0.0.1"); + strcat(curl_url, q_info->host_name); + } + + if (strlen(q_info->host_port) >= 1) { + strcat(curl_url, ":"); + strcat(curl_url, q_info->host_port); + } + + strcat(curl_url, q_info->post_url); + + if (strstr(q_info->post_url, "control?virtual.input") != NULL && strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { + g_control_alarm_gpio = 1; + } + + + //printf("Http curl_url: %s \n", curl_url); + + //memset(&g_stCURL_send_data, 0, sizeof(g_stCURL_send_data)); + + //memset(g_stCURL_send_data_curl_url, 0, 8192); + //memset(g_stCURL_send_data_curl_sendbuf, 0, 8192); + //memset(g_stCURL_send_data_method, 0, 32); + //memset(g_stCURL_send_data_username, 0, 64); + //memset(g_stCURL_send_data_password, 0, 64); + //memset(g_stCURL_send_data_port, 0, 10); + + pthread_mutex_lock(&mutex_curl); + + strcpy(g_stCURL_send_data_curl_url, curl_url); + g_stCURL_send_data_curl_sendbuf_size = 0; + g_stCURL_send_data_curl_sendbuf_size = q_info->content_size; + memcpy(g_stCURL_send_data_curl_sendbuf, curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); + strcpy(g_stCURL_send_data_method, method); + strcpy(g_stCURL_send_data_protocol, q_info->post_protocol); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)q_info->post_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)q_info->post_password, (unsigned char *)buf_account2); + + strcpy(g_stCURL_send_data_username, buf_account); + strcpy(g_stCURL_send_data_password, buf_account2); + strcpy(g_stCURL_send_data_port, q_info->host_port); + strcpy(g_stCURL_send_data_timeout, q_info->post_timeout); + strcpy(g_stCURL_send_data_customized_header, q_info->post_customized_header); + g_stCURL_enable_attached_image = 0; + g_stCURL_enable_attached_image = q_info->enable_attached_image; + g_stCURL_enable_filename_fixed = 0; + g_stCURL_enable_filename_fixed = q_info->enable_filename_fixed; + strcpy(g_stCURL_send_jpeg_file_name, q_info->post_jpeg_file_name); + + if (q_info->image_buff_size >= 1) { + memcpy(g_stCURL_image_buff, q_info->image_buff, q_info->image_buff_size); + g_stCURL_image_buff_size = q_info->image_buff_size; + } + else { + g_stCURL_image_buff_size = 0; + } + + strcpy(g_stCURL_send_data_q_name, q_info->q_name); + strcpy(g_stCURL_send_data_q_plate, q_info->q_plate); + + pthread_mutex_unlock(&mutex_curl); + + /* + printf("\n-----------g_stCURL_send_data_curl_url:%s\n", g_stCURL_send_data_curl_url); + printf("\n-----------g_stCURL_send_data_curl_sendbuf_size:%d\n", g_stCURL_send_data_curl_sendbuf_size); + printf("\n-----------g_stCURL_send_data_curl_sendbuf:%s\n", g_stCURL_send_data_curl_sendbuf); + printf("\n-----------g_stCURL_send_data_method:%s\n", g_stCURL_send_data_method); + printf("\n-----------g_stCURL_send_data_protocol:%s\n", g_stCURL_send_data_protocol); + printf("\n-----------g_stCURL_send_data_username:%s\n", g_stCURL_send_data_username); + printf("\n-----------g_stCURL_send_data_password:%s\n", g_stCURL_send_data_password); + printf("\n-----------g_stCURL_send_data_port:%s\n", g_stCURL_send_data_port); + printf("\n-----------g_stCURL_send_data_customized_header:%s\n", g_stCURL_send_data_customized_header); + printf("\n-----------g_stCURL_enable_attached_image:%d\n", g_stCURL_enable_attached_image); + printf("\n-----------g_stCURL_enable_filename_fixed:%d\n", g_stCURL_enable_filename_fixed); + printf("\n-----------g_stCURL_send_jpeg_file_name:%s\n", g_stCURL_send_jpeg_file_name); + */ +#if 1 + + //if (IsValidURL(curl_url)==true) { + + if (g_check_ping_OK == 1) { + if (g_stCURL_enable_attached_image == 0) { + pthread_t curl_thread_id; + if (pthread_create(&curl_thread_id, 0, net_curl_https_post_push_info, NULL)) + { + printf("create curl thread faile \n"); + } + } + else if (g_stCURL_enable_attached_image == 1) { + pthread_t curl_image_thread_id; + if (pthread_create(&curl_image_thread_id, 0, net_curl_https_post_push_info_attached_image, NULL)) + { + printf("create curl image thread faile \n"); + } + } + } + + + //} +#endif + + //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL, method, + // q_info->post_username, q_info->post_password, strtol(q_info->host_port, NULL, 10)); +#if 0 + if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) + printf("\nsend error(post notification) #1\n"); + else + printf("\nSuccess to send.\n"); +#endif + } + + +#ifdef FOR_CC_POST +#else + closesocket(sock); +#endif + } + +#endif + return 0; +} +#ifdef GY_OS_AMBA +void Create_ptz_socket() +{ + char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + //int cfd; // Socket ɮ״yz (File Descriptor) + int gaiStatus; // getaddrinfo AX + struct addrinfo hints; // hints ѼơA]w getaddrinfo() ^Ǥ覡 + struct addrinfo *result; // getaddrinfo() 浲G addrinfo c + + // H memset M hints c + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + + // H getaddrinfo zL DNSAo addrinfo 쵲C (Linked List) + // Hqo Host IP } + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + // OH domain, type, protocol إ socket ɮ״yz + g_socket = socket(result->ai_family, result->ai_socktype, 0); + + g_socket = socket(AF_INET, SOCK_STREAM, 0); + fcntl(g_socket, F_SETFL, O_NONBLOCK); + + // H socket ɮ״yz (cfd), addr, addrlen isu + // 䤤Aresult->ai_addr gai o q socket }c -- sockaddr + if (connect(g_socket, result->ai_addr, result->ai_addrlen) < 0) + printf("fail connect\n"); + + + // getaddrinfo (Linked List) OŶ + freeaddrinfo(result); + result = NULL; +} + +void SetHttpRequest_ptz_re(char *cgi_url, char *sOutput_data, char *sUsername, char *sPassword) +{ + //char *host = "ptsv2.com"; // ؼ URI + //char *host = "127.0.0.1"; // ؼ URI + //char *PORT_NUM = "80"; // HTTP port + + char request[0xfff], response[0xfff]; // ШD P ^T + + //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // ШD + //char *requestLine = "GET /server HTTP/1.1\r\n"; // ШD + //char *headerFmt = "Host: %s\r\n"; // Host Y + char *headerFmt = "Host: 127.0.0.1\r\n"; // Host Y + char *CRLF = "\r\n"; // Y᪺ CRLF + + // RAtmYO + //size_t bufferLen = 1024; + char buffer[1024] = { 0 }; + + //ո˽ШDCGI + char requestLine[512] = { 0 }; //"GET /server HTTP/1.1\r\n"; // ШD + strcat(requestLine, "GET"); + strcat(requestLine, " "); + + if (strlen(cgi_url) > 0) + strcat(requestLine, cgi_url); + else + strcat(requestLine, "/server"); + + strcat(requestLine, " "); + strcat(requestLine, "HTTP/1.1"); + strcat(requestLine, CRLF); + + //ո˽ШDT + strcpy(request, requestLine); + + //snprintf(buffer, bufferLen, headerFmt, host); //(tXʺAtmO) + strcat(buffer, headerFmt); + strcat(request, buffer); + + strcat(request, "Accept: */*"); + strcat(request, CRLF); + + strcat(request, "Content-Type: application/json"); + strcat(request, CRLF); + + strcat(request, "Connection: close"); + strcat(request, CRLF); + + + //ո˱bK + strcat(request, "Authorization: Basic "); + //strcpy(Authorization, q_info->post_username); + + char Authorization[2560] = { 0 }; + strcpy(Authorization, sUsername); + strcat(Authorization, ":"); + strcat(Authorization, sPassword); + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + //char original_base64_output[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + + strcat(request, httpAuth); + strcat(request, CRLF); + strcat(request, CRLF); + + // 榡ƿXШDT + printf("----------\nRequest:\n----------\n%s\n", request); + + // oeШD + if (send(g_socket, request, strlen(request), 0) < 0) + printf("Send\n"); + + + // ^ + if (recv(g_socket, response, 0xfff, 0) < 0) + { + printf("Receive fail\n"); + } + else + { + size_t iRecvLen = strlen(response); + printf("ReceiveLen: %d\n", (int)iRecvLen); + printf("Receive: \n%s\n", response); + + + snprintf(sOutput_data, iRecvLen, response); + //strcpy(sOutput_data, response); + } +} + +void SetHttpRequest_ptz(char *cgi_url, char *sOutput_data, char *sUsername, char *sPassword) +{ + //char *host = "ptsv2.com"; // ؼ URI + char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + char request[0xfff], response[0xfff]; // ШD P ^T + + //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // ШD + //char *requestLine = "GET /server HTTP/1.1\r\n"; // ШD + //char *headerFmt = "Host: %s\r\n"; // Host Y + char *headerFmt = "Host: 127.0.0.1\r\n"; // Host Y + char *CRLF = "\r\n"; // Y᪺ CRLF + + int cfd; // Socket ɮ״yz (File Descriptor) + int gaiStatus; // getaddrinfo AX + struct addrinfo hints; // hints ѼơA]w getaddrinfo() ^Ǥ覡 + struct addrinfo *result; // getaddrinfo() 浲G addrinfo c + + // ʺAtmOAHMw Ywİ (Header Buffer) + //size_t bufferLen = strlen(headerFmt) + strlen(host) + 1; + //char *buffer = (char *)malloc(bufferLen); // Ywİ + + // RAtmYO + //size_t bufferLen = 1024; + char buffer[1024] = { 0 }; + + //ո˽ШDCGI + char requestLine[512] = { 0 }; //"GET /server HTTP/1.1\r\n"; // ШD + strcat(requestLine, "GET"); + strcat(requestLine, " "); + + if (strlen(cgi_url) > 0) + strcat(requestLine, cgi_url); + else + strcat(requestLine, "/server"); + + strcat(requestLine, " "); + strcat(requestLine, "HTTP/1.1"); + strcat(requestLine, CRLF); + + //ո˽ШDT + strcpy(request, requestLine); + + //snprintf(buffer, bufferLen, headerFmt, host); //(tXʺAtmO) + strcat(buffer, headerFmt); + strcat(request, buffer); + + strcat(request, "Accept: */*"); + strcat(request, CRLF); + + strcat(request, "Content-Type: application/json"); + strcat(request, CRLF); + + strcat(request, "Connection: close"); + strcat(request, CRLF); + + + //ո˱bK + strcat(request, "Authorization: Basic "); + //strcpy(Authorization, q_info->post_username); + + char Authorization[2560] = { 0 }; + strcpy(Authorization, sUsername); + strcat(Authorization, ":"); + strcat(Authorization, sPassword); + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + //char original_base64_output[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + + strcat(request, httpAuth); + strcat(request, CRLF); + strcat(request, CRLF); + + + // wİϰO (tXʺAtmO) + //free(buffer); + //buffer = NULL; + + // H memset M hints c + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + + // H getaddrinfo zL DNSAo addrinfo 쵲C (Linked List) + // Hqo Host IP } + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + + // OH domain, type, protocol إ socket ɮ״yz + cfd = socket(result->ai_family, result->ai_socktype, 0); + + cfd = socket(AF_INET, SOCK_STREAM, 0); + fcntl(cfd, F_SETFL, O_NONBLOCK); + + // H socket ɮ״yz (cfd), addr, addrlen isu + // 䤤Aresult->ai_addr gai o q socket }c -- sockaddr + if (connect(cfd, result->ai_addr, result->ai_addrlen) < 0) + printf("fail connect\n"); + + + // getaddrinfo (Linked List) OŶ + freeaddrinfo(result); + result = NULL; + + // 榡ƿXШDT + printf("----------\nRequest:\n----------\n%s\n", request); + + // oeШD + if (send(cfd, request, strlen(request), 0) < 0) + printf("Send\n"); + + + // ^ + if (recv(cfd, response, 0xfff, 0) < 0) + { + printf("Receive fail\n"); + } + else + { + size_t iRecvLen = strlen(response); + printf("ReceiveLen: %d\n", (int)iRecvLen); + printf("Receive: \n%s\n", response); + + + snprintf(sOutput_data, iRecvLen, response); + //strcpy(sOutput_data, response); + } + + close(cfd); +} + +void SetHttpRequest_ptz_ok() +{ + //char *host = "ptsv2.com"; // ؼ URI + char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + char request[0xfff], response[0xfff]; // ШD P ^T + //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // ШD + char *requestLine = "GET /server HTTP/1.1\r\n"; // ШD + char *headerFmt = "Host: %s\r\n"; // Host Y + char *CRLF = "\r\n"; // Y᪺ CRLF + + int cfd; // Socket ɮ״yz (File Descriptor) + int gaiStatus; // getaddrinfo AX + struct addrinfo hints; // hints ѼơA]w getaddrinfo() ^Ǥ覡 + struct addrinfo *result; // getaddrinfo() 浲G addrinfo c + + // ʺAtmOAHMw Ywİ (Header Buffer) + size_t bufferLen = strlen(headerFmt) + strlen(host) + 1; + char *buffer = (char *)malloc(bufferLen); // Ywİ + + //ո˽ШDT + strcpy(request, requestLine); + snprintf(buffer, bufferLen, headerFmt, host); + strcat(request, buffer); + strcat(request, CRLF); + + // wİϰO + if (buffer != NULL) + { + free(buffer); + buffer = NULL; + } + // H memset M hints c + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + + // H getaddrinfo zL DNSAo addrinfo 쵲C (Linked List) + // Hqo Host IP } + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + + // OH domain, type, protocol إ socket ɮ״yz + cfd = socket(result->ai_family, result->ai_socktype, 0); + + // H socket ɮ״yz (cfd), addr, addrlen isu + // 䤤Aresult->ai_addr gai o q socket }c -- sockaddr + if (connect(cfd, result->ai_addr, result->ai_addrlen) < 0) + printf("fail connect\n"); + + + // getaddrinfo (Linked List) OŶ + freeaddrinfo(result); + result = NULL; + + // 榡ƿXШDT + printf("----------\nRequest:\n----------\n%s\n", request); + + // oeШD + if (send(cfd, request, strlen(request), 0) < 0) + printf("Send\n"); + + // ^ + if (recv(cfd, response, 0xfff, 0) < 0) + printf("Receive fail\n"); + else + printf("Receive: %s\n", response); + +} + +#if 0 +void SetHttpRequest_ptz() +{ + QueueInfo single_queue_node; + + strcat(single_queue_node.host_name, "ptsv2.com"); + strcat(single_queue_node.post_url, "/t/g9mu2-1639036821/post"); + strcat(single_queue_node.post_protocol, "HTTP"); + strcat(single_queue_node.content, "/t/g9mu2-1639036821/post"); + + char *host = "ptsv2.com"; // ؼ URI + //char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + + //char sTestSendBuffer[512]; + //SetHttpRequest_ptz(&single_queue_node, sTestSendBuffer, "POST"); + + + struct addrinfo hints = { 0 }; + struct addrinfo* feed_server = NULL; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + //hints.ai_family = AF_INET; + //getaddrinfo("ptsv2.com", NULL, &hints, &feed_server); + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + + SOCKET sock; + + struct addrinfo *res; + for (res = feed_server; res != NULL; res = res->ai_next) { + struct sockaddr_in* saddr = (struct sockaddr_in*)res->ai_addr; + + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + /*printf("\nsock: %d\n",sock); + printf("\nres->ai_addrlen: %d\n",res->ai_addrlen);*/ + printf("22\n"); + + if (sock == -1) + continue; + + if (connect(sock, res->ai_addr, res->ai_addrlen) != -1) + { + printf("conn sock = %d \n", sock); + printf("hostname: %s\n", inet_ntoa(saddr->sin_addr)); + break; /* Success */ + } + + //closesocket(sock); + } + + if (res == NULL) + { + // jwg list ̫ALksu + printf("Failed to send POST to %s%s:%s\n", "http://", "127.0.0.1", "80"); + return; + } + + char sendBuffer[1024]; + char Temp[MAX_MSG_LEN] = { 0 }; + + //size_t sendLen = 0; + + { + strcat(sendBuffer, "POST"); + //strcat(sendBuffer, "GET"); + strcat(sendBuffer, " "); + + if (strcmp("HTTP", "HTTP") == 0) + { + //if (q_info->post_url[0] == '/') + //{ + //strcat(sendBuffer, q_info->post_url); + //} + //else + //{ + // strcat(sendBuffer, "/"); + //strcat(sendBuffer, q_info->post_url); + //} + } + //strcat(sendBuffer, q_info->post_url); + //strcat(sendBuffer, "/server"); + strcat(sendBuffer, "/t/g9mu2-1639036821/post"); + + strcat(sendBuffer, " "); + strcat(sendBuffer, "HTTP/1.1"); + strcat(sendBuffer, "\r\n"); + int first_line_len = strlen(sendBuffer); + + strcat(sendBuffer, "Host: "); + strcat(sendBuffer, "ptsv2.com"); + //strcat(sendBuffer, q_info->host_name); + + //if (strlen(q_info->host_port) > 0) + //{ + // strcat(sendBuffer, ":"); + // strcat(sendBuffer, q_info->host_port); + //} + + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cache-Control: no-cache"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "User-Agent: IPVideo"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept: */*"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); + strcat(sendBuffer, "Content-Type: application/json"); + strcat(sendBuffer, "\r\n"); + + + + //size_t contentLen = strlen(q_info->content); + //size_t contentLen = strlen("/t/g9mu2-1639036821/post"); + size_t contentLen = 0; + + strcat(sendBuffer, "Content-Length: "); + sprintf(Temp, "%ld", contentLen); + strcat(sendBuffer, Temp); + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Connection: Closed"); + //strcat(sendBuffer, "\r\n"); + + //unsigned char Authorization[2560] = { 0 }; + + ////if (strlen(q_info->post_username) > 0) + //if (strlen("admin") > 0) + //{ + // strcat(sendBuffer, "Authorization: Basic "); + // //strcpy(Authorization, q_info->post_username); + // strcpy(Authorization, "admin"); + // strcat(Authorization, ":"); + + // //if (strlen(q_info->post_password) > 0) + // if (strlen("Pass1234") > 0) + // strcat(Authorization, "Pass1234"); + //} + + + + //size_t base64_encode_length = 0; + //char httpAuth[2560] = { 0 }; + + ////char original_base64_output[8 * 8192] = { 0 }; + //base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + //httpAuth[base64_encode_length] = '\0'; + ////*(httpAuth + base64_encode_length-1) = '6'; + + //strcat(sendBuffer, httpAuth); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "\r\n"); + + + size_t headerLen = strlen(sendBuffer); + size_t totalLen = headerLen; +#if 0 + /*if (strcmp("GET", "POST") == 0) + { + contentLen = strlen("/t/g9mu2-1639036821/post"); + + memcpy(sendBuffer + headerLen, "/t/g9mu2-1639036821/post", contentLen); + totalLen = headerLen + contentLen; + }*/ + + if (strcmp("GET", "GET") == 0) + { + contentLen = strlen("/t/g9mu2-1639036821/post"); + + memcpy(sendBuffer + headerLen, "/t/g9mu2-1639036821/post", contentLen); + totalLen = headerLen + contentLen; + } +#endif + + printf("send= \n%s\n", sendBuffer); + + if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) + printf("\nsend error(post notification) #2\n"); + else + printf("\nSuccess to send.\n"); + + closesocket(sock); + } +} + + +size_t SetHttpRequest_ptz(QueueInfo *q_info, char* sendBuffer, char* method) +{ + // Declare and initialize variables + SOCKET sock; + char* ip = NULL; + char HostName[MAX_MSG_LEN] = { 0 }; // an IP address or a hostname, like "www.google.com" by itself + char HostPort[10] = { 0 }; + unsigned char Authorization[2560] = { 0 }; + char Temp[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + struct addrinfo* result = NULL, *tmp; + struct addrinfo* ptr = NULL; + struct addrinfo hints = { 0 }; + struct sockaddr_in* sockaddr_ipv4 = NULL; + + + + //hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + char curl_sendbuf[8192] = ""; + char curl_url[8192] = ""; + char host[256]; + + + //DWORD ret = getaddrinfo(HostName, "http", &hints, &result); + //DWORD ret = getaddrinfo(q_info->host_name, q_info->host_port, &hints, &result); + + printf("00\n"); + + DWORD ret = getaddrinfo("127.0.0.1", NULL, &hints, &result); + + printf("11\n"); + + if (ret != 0) { + printf("getaddrinfo failed with error: %d\n", ret); + return 1; + } + + //for (tmp = result; tmp != NULL; tmp = tmp->ai_next) { + // getnameinfo(tmp->ai_addr, tmp->ai_addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST); + // puts(host); + //} + + freeaddrinfo(result); + + for (ptr = result; ptr != NULL; ptr = ptr->ai_next) + { + sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); + /*printf("\nsock: %d\n",sock); + printf("\nptr->ai_addrlen: %d\n",ptr->ai_addrlen);*/ + printf("22\n"); + + if (sock == -1) + continue; + + if (connect(sock, ptr->ai_addr, ptr->ai_addrlen) != -1) + { + printf("conn sock = %d \n", sock); + break; /* Success */ + } + + closesocket(sock); + } + printf("33\n"); + if (ptr == NULL) + { + // jwg list ̫ALksu + fprintf(stderr, "Failed to send POST to %s%s:%s\n", "http://", "127.0.0.1", "80"); + return 1; + } + + if (ptr->ai_family == AF_INET) + { + sockaddr_ipv4 = (struct sockaddr_in *) ptr->ai_addr; + ip = inet_ntoa(sockaddr_ipv4->sin_addr); + //printf("ip address=%s\n", ip); + } + freeaddrinfo(result); // servinfo OŶ + + printf("44\n"); + + { + strcat(sendBuffer, method); + strcat(sendBuffer, " "); + + if (strcmp(q_info->post_protocol, "HTTP") == 0) + { + if (q_info->post_url[0] == '/') + { + //strcat(sendBuffer, q_info->post_url); + } + else + { + strcat(sendBuffer, "/"); + //strcat(sendBuffer, q_info->post_url); + } + } + //strcat(sendBuffer, q_info->post_url); + strcat(sendBuffer, "/server"); + + strcat(sendBuffer, " "); + strcat(sendBuffer, "HTTP/1.1"); + strcat(sendBuffer, "\r\n"); + int first_line_len = strlen(sendBuffer); + + strcat(sendBuffer, "Host: "); + strcat(sendBuffer, "127.0.0.1"); + //strcat(sendBuffer, q_info->host_name); + + //if (strlen(q_info->host_port) > 0) + //{ + // strcat(sendBuffer, ":"); + // strcat(sendBuffer, q_info->host_port); + //} + + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Cache-Control: no-cache"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "User-Agent: IPVideo"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Accept: */*"); + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); + strcat(sendBuffer, "\r\n"); + + + + //size_t contentLen = strlen(q_info->content); + size_t contentLen = strlen("\server"); + + strcat(sendBuffer, "Content-Length: "); + sprintf(Temp, "%ld", contentLen); + strcat(sendBuffer, Temp); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Connection: Closed"); + strcat(sendBuffer, "\r\n"); + + //if (strlen(q_info->post_username) > 0) + if (strlen("admin") > 0) + { + strcat(sendBuffer, "Authorization: Basic "); + //strcpy(Authorization, q_info->post_username); + strcpy(Authorization, "admin"); + strcat(Authorization, ":"); + + //if (strlen(q_info->post_password) > 0) + if (strlen("Pass1234") > 0) + strcat(Authorization, "Pass1234"); + } + + + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + //char original_base64_output[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + //*(httpAuth + base64_encode_length-1) = '6'; + + strcat(sendBuffer, httpAuth); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + + size_t headerLen = strlen(sendBuffer); + size_t totalLen = headerLen; + + if (strcmp(method, "POST") == 0) + { + contentLen = strlen(q_info->content); + + memcpy(sendBuffer + headerLen, q_info->content, contentLen); + totalLen = headerLen + contentLen; + } + + //printf("send= %s\n", sendBuffer); + + if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) + printf("\nsend error(post notification) #3\n"); + else + printf("\nSuccess to send.\n"); + + closesocket(sock); + } +#if 0 + + + + + + + //http first line + //if (featureType & FEATURE_LPR_TUR) + +#endif + + return 0; +} +#endif +#endif //#ifdef GY_OS_AMBA +size_t SetHttpResponse_server(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(sendBuffer, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(sendBuffer, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(sendBuffer, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(sendBuffer, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(sendBuffer, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(sendBuffer, "HTTP/1.1 404 Not Found"); + break; + } + //strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + //time_t now = time(0); + //struct tm tm = *gmtime(&now); + //memset(tempStr, 0x00, sizeof(tempStr)); + //strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + //strcat(sendBuffer, "Date: "); + //strcat(sendBuffer, tempStr); + //strcat(sendBuffer, "\r\n"); + //memset(tempStr, 0x00, sizeof(tempStr)); + //snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + //strcat(sendBuffer, tempStr); + + strcat(sendBuffer, "Content-Type: "); + strcat(sendBuffer, contentType); + strcat(sendBuffer, ";charset=utf-8;"); + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Headers: content-type"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Methods: POST,GET"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Origin: *"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Credentials: true"); + strcat(sendBuffer, "\r\n"); + /* + if (httpCode == _CODE_200) + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + else + strcat(sendBuffer, "Connection: Closed\r\n");*/ + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + + return sendLen; +} + +size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(sendBuffer, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(sendBuffer, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(sendBuffer, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(sendBuffer, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(sendBuffer, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(sendBuffer, "HTTP/1.1 404 Not Found"); + break; + } + //strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + //time_t now = time(0); + //struct tm tm = *gmtime(&now); + //memset(tempStr, 0x00, sizeof(tempStr)); + //strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + //strcat(sendBuffer, "Date: "); + //strcat(sendBuffer, tempStr); + //strcat(sendBuffer, "\r\n"); + //memset(tempStr, 0x00, sizeof(tempStr)); + //snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + //strcat(sendBuffer, tempStr); + /* + if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) + { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %d", contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + }*/ + strcat(sendBuffer, "Content-Type: "); + + if (strcmp(contentType, "text/html;") == 0) { + strcat(sendBuffer, contentType); + strcat(sendBuffer, "charset=utf-8;"); + } + else if (strcmp(contentType, "text/html") == 0) { + strcat(sendBuffer, contentType); + strcat(sendBuffer, ";charset=utf-8;"); + } + else { + strcat(sendBuffer, contentType); + strcat(sendBuffer, ";charset=utf-8;"); + } + + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Headers: content-type"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Methods: POST,GET"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Origin: *"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Credentials: true"); + strcat(sendBuffer, "\r\n"); + /* + if (httpCode == _CODE_200) + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + else + strcat(sendBuffer, "Connection: Closed\r\n");*/ + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + + return sendLen; +} +//claire, response attachment +size_t SetHttpResponse_att(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(tempStr, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(tempStr, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(tempStr, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(tempStr, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(tempStr, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(tempStr, "HTTP/1.1 404 Not Found"); + break; + } + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + time_t now = time(0); + struct tm tm = *gmtime(&now); + memset(tempStr, 0x00, sizeof(tempStr)); + strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + strcat(sendBuffer, "Date: "); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + strcat(sendBuffer, tempStr); + if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) + { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + } + strcat(sendBuffer, "Content-Type: "); + strcat(sendBuffer, contentType); + //strcat(sendBuffer, "; charset=utf-8"); + strcat(sendBuffer, "\r\n"); + if (httpCode == _CODE_200) { + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + } + else { + strcat(sendBuffer, "Connection: Closed\r\n"); + } + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + + return sendLen; +} +//20201028 sophia add +size_t SetHttpResponse_authHeader(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(tempStr, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(tempStr, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(tempStr, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(tempStr, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(tempStr, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(tempStr, "HTTP/1.1 404 Not Found"); + break; + } + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + time_t now = time(0); + struct tm tm = *gmtime(&now); + memset(tempStr, 0x00, sizeof(tempStr)); + strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + strcat(sendBuffer, "Date: "); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "WWW-Authenticate: Basic realm=\"IPVideo\""); + strcat(sendBuffer, "\r\n"); + if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) + { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + } + strcat(sendBuffer, "Content-Type: "); + strcat(sendBuffer, contentType); + //strcat(sendBuffer, "; charset=utf-8"); + strcat(sendBuffer, "\r\n"); + if (httpCode == _CODE_200) + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + else + strcat(sendBuffer, "Connection: Closed\r\n"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + #ifdef _DEBUG_AMBA + printf("\n[SetHttpResponse] sendBuffer:%s\n", sendBuffer); + #endif + return sendLen; +} + +//20201028 sophia add + +int run_connection_authorized = 0; +int is_connection_authorized(char* recvBuffer, SOCKET *client_socket, int isTcpTunnel) +{ + if (run_connection_authorized == 0) { + run_connection_authorized = 1; + //pthread_mutex_lock(&mutex_base64); + + SOCKET cli_socket = *client_socket; + + /* + printf("\n-----------------------\n"); + printf("\n%s\n",recvBuffer); + printf("\n-----------------------\n");*/ + + int check_if_data_loading_OK = 0; + + int is_authorized = 0; + if (is_authorized == 0) { + //char *is_localhost = strstr(recvBuffer, "127.0.0.1"); + //if (is_localhost == NULL) + { + //get id,pass + + char id[512] = { 0 }; + char pass[512] = { 0 }; + + //memset(id, 0x00, sizeof(id)); + //memset(pass, 0x00, sizeof(pass)); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] not localhost\n", cli_socket); + printf("\n(%d) [is_connection_authorized] recvBuffer: %s\n", cli_socket, recvBuffer); +#endif + + //is_authorized = 0; + + //check authorization process + char *start = strstr(recvBuffer, "Authorization: Basic "); + if (start != NULL) + { +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] Authorization: Basic here\n", cli_socket); +#endif + + start = start + strlen("Authorization: Basic "); + char *end = start; + int len = 0; + if (start) + { + while (*end != '\r' && *end != '\n' && *end != ' ' /*&& *end != '\r\n'*/) + { + len = len + 1; + end++; + } + + //decrypt id:pass + char EncryptIdPass[512]; + memset(EncryptIdPass, 0x00, sizeof(EncryptIdPass)); + strncpy(EncryptIdPass, start, len); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] EncryptIdPass:%s %d %d\n", cli_socket, EncryptIdPass, strlen(EncryptIdPass), len); +#endif + + size_t base64_decode_length = 0; + char DecryptData[512]; + memset(DecryptData, 0x00, sizeof(DecryptData)); + unsigned char OriEncryptData[1024] = { 0 }; + base64_decode(EncryptIdPass, strlen(EncryptIdPass), &base64_decode_length, OriEncryptData); + memcpy(DecryptData, OriEncryptData, base64_decode_length); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] ### OriEncryptData:%s DecryptData:%s\n", cli_socket, OriEncryptData, DecryptData); +#endif //_DEBUG_AMBA + + if (strlen(DecryptData) > 1) //more than ":" + { + //printf("\n--------------DecryptData:%s\n", DecryptData); + + char *delim = ":"; + char *pch = NULL; + char *pLeft = NULL; + pch = strtok_modified(DecryptData, delim, &pLeft); + if (pch != NULL) + { + char temp_cpy[100] = { 0 }; + sprintf(temp_cpy, "%s", pch); + char temp_account[512] = { 0 }; + urlencode((unsigned char *)temp_cpy, strlen(temp_cpy), (unsigned char *)temp_account, 512); + + sprintf(id, "%s", temp_account); + //printf("\n-------------id:%s\n",id); + pch = strtok_modified(NULL, delim, &pLeft); + if (pch != NULL) + { + char temp_cpy_2[100] = { 0 }; + sprintf(temp_cpy_2, "%s", pch); + char temp_account_2[512] = { 0 }; + urlencode((unsigned char *)temp_cpy_2, strlen(temp_cpy_2), (unsigned char *)temp_account_2, 512); + sprintf(pass, "%s", temp_account_2); + //printf("\n-------------pass:%s\n", pass); + } + } + +#if 0 + printf("\n(%d) [is_connection_authorized] ### id:%s pass:%s\n", cli_socket, id, pass); +#endif + + //comapre id,pass with accountData + + //{ + //int match = 0; + //int i = 0; + //while (!is_authorized && i < MAX_ACCOUNT_DATA_NUM /*&& strlen(id) >= 1 && strlen(pass) >= 1*/) + //{ + /* + if (strlen(accountData[i].account_username) >= 1 && strlen(accountData[i].account_password) >= 1) { + */ + // if (strcmp(id, accountData[i].account_username) == 0) + // { + // if (strcmp(pass, accountData[i].account_password) == 0) + // { + // is_authorized = 1; + // break; + // } + // } + //} + // i++; + //} + //} + } + } + } + + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nid: %s; pass: %s\n",id,pass); + for(int i = 0 ; i < 10 ; i++) + printf("\n(%d)username: %s; password: %s\n",i, accountData[i].account_username, accountData[i].account_password); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) { + if (strlen(accountData[i].account_username) == 0) { + continue; + } + + if (strlen(accountData[i].account_username) >= 1 && strlen(accountData[i].account_password) >= 1) { + check_if_data_loading_OK = 1; + } + + if (strcmp(id, accountData[i].account_username) == 0) + { + if (strcmp(pass, accountData[i].account_password) == 0) + { + is_authorized = 1; + break; + } + } + } + } + } + + /* + printf("\n-----------------------AABB\n"); + printf("\n%s\n", recvBuffer); + printf("\n-----------------------AABB\n"); + */ + + int iSockIdx = -1; + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == cli_socket) + { + iSockIdx = i; + break; + } + } + } + + + char *is_NVR_client = strstr(recvBuffer, "menu_on_nvr"); + if (is_NVR_client != NULL || (iSockIdx >= 0 && socketRecords[iSockIdx].isNvrRequest == 1)) + { + //printf("pppppppppppppppppppppppppppppppppppppppppppppppp find \n"); + + if(iSockIdx >= 0) + socketRecords[iSockIdx].isNvrRequest = 1; + + is_authorized = 1; + } + + if (is_authorized == 1 && (iSockIdx >= 0 && socketRecords[iSockIdx].isCredentialRequest == 1)) { + g_is_check_credential = 1; + } + else if (is_authorized == 0 && (iSockIdx >= 0 && socketRecords[iSockIdx].isCredentialRequest == 1)) { + g_is_check_credential = 0; + } + else if (g_is_check_credential == 1 || isTcpTunnel == TRUE) { + is_authorized = 1; + } + + //is_authorized = 1; + if (is_authorized == 0 && check_if_data_loading_OK == 1) + { + + //printf("\n---------------------------------------------\n"); + //printf("\n(%d) [is_connection_authorized] recvBuffer: %s\n", cli_socket, recvBuffer); + //printf("\n----------------------------------------------\n"); + + char msg[MAX_MSG_LEN]; + char sendBuffer[BUFSIZE_V2] = { 0 }; + char beforeSendBuffer[BUFSIZE_V2] = { 0 }; + char contentDescription[MAX_MSG_LEN] = { 0 }; + + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Unauthorized."); + printf(msg); + //syslog(NW_SORRY, msg, recvBuffer, cli_socket); + strcpy(beforeSendBuffer, msg); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_authHeader(sendBuffer, _CODE_401, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #16\n"); + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed####11\n"); + } + + //return; + }/* + else { + char msg[MAX_MSG_LEN]; + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + char contentDescription[MAX_MSG_LEN] = { 0 }; + + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "OK."); + printf(msg); + //syslog(NW_SORRY, msg, recvBuffer, cli_socket); + strcpy(beforeSendBuffer, msg); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_authHeader(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error\n"); + }*/ + + //pthread_mutex_unlock(&mutex_base64); + run_connection_authorized = 0; + return is_authorized; + } + else { + return 1; + } +} + +void update_config(char *recInfo) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("read config.json.\n"); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + + if (fileBuf) { + + cJSON* root, *about_box;//, * unlock_key, * sys_id; + cJSON *rec_json, *rec_key; + rec_json = cJSON_Parse(recInfo); + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + //static char* unlocking_key; + + if (root) + { + //printf("config.json parse OK.\n"); + about_box = cJSON_GetObjectItem(root, "about_box"); + //unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + //if (unlock_key) + // printf("unlocking_key exists.\n"); + //else + // printf("unlocking_key is NULL.\n"); + + //printf("get sys id = %s \n", fetch_mac_addr); + //printf("get jsonfile key = %s \n", unlock_key->valuestring); + + //Get MAC Address + /*printf("\ng_match_mac: %d\n", g_match_mac); + printf("\ng_mac_address: %s\n", g_mac_address);*/ + + if (g_match_mac == 1) { + cJSON_ReplaceItemInObject(about_box, "system id", cJSON_CreateString(g_mac_address)); + } + else { + char fetch_mac_addr[64] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + GetMACAddress(fetch_mac_addr); + //printf("mac addr = %s \n", fetch_mac_addr); + + char *find; + find = strchr(fetch_mac_addr, '\n'); + if (find) + *find = '\0'; + + cJSON_ReplaceItemInObject(about_box, "system id", cJSON_CreateString(fetch_mac_addr)); + } + + //sys_id = cJSON_GetObjectItem(about_box, "system id"); + //printf("show update sys id = %s \n", sys_id->valuestring); + //cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("testkey123456")); + + rec_key = cJSON_GetObjectItem(rec_json, "unlocking_key"); + //printf("get input key = %s \n", rec_key->valuestring); + + +//#ifdef GY_OS_AMBA + //if (rec_key && strlen(rec_key->valuestring)>=1) +//#else + if (rec_key) +//#endif + { + + memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); +//#ifdef GY_OS_AMBA + /*char temp_key[512] = { 0 }; + char formatted_mac[30] = { 0 }; + if (strstr(rec_key->valuestring, "face") != NULL) { + getContractSignature(temp_key, formatted_mac); + } + if (strstr(rec_key->valuestring, "face") != NULL) { + strcpy(strUnlockingKey, "face"); + strcat(strUnlockingKey, temp_key); + } + else *///{ + //strcpy(strUnlockingKey, rec_key->valuestring); + //} +//#else + if (strlen(rec_key->valuestring) >= 1) { + strcpy(strUnlockingKey, rec_key->valuestring); + } + else { + strcpy(strUnlockingKey,"auto"); + } +//#endif + + + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + + { + char buf_exe[1024] = {}; + readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); + + char exePath_temp[1024] = {}; + getFilePath(buf_exe, exePath_temp, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath_temp); + strcat(keyPATH, "key.txt"); + if (FileExist(keyPATH) == 1) { + FILE *pFile; + + if ((pFile = fopen(keyPATH, "w")) != NULL) + { + fprintf(pFile, strUnlockingKey); + fclose(pFile); + + } + else + printf("Fail to open key.txt \n"); + } + } + } + + //printf("read key = %s \n", unlock_key->valuestring); + + char* JsonString = cJSON_Print(root); + + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + CopyFileTo(configPATH, config_bakPATH); + } + else + { + printf("Fail to open Config.json \n"); + } + + if (rec_json) { + free(rec_json); + rec_json = NULL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } +} + +void update_enable_only_show_metadata1(int temp_enable_only_show_metadata1) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("read config.json.\n"); + + char* fileBuf = ReadAllBytes(filename); + + if (fileBuf) { + + cJSON* root, *view_setting,*camera01;//, * unlock_key, * sys_id; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (root) + { + //printf("config.json parse OK.\n"); + view_setting = cJSON_GetObjectItem(root, "view_setting"); + camera01 = cJSON_GetObjectItem(view_setting, "camera01"); + + cJSON_ReplaceItemInObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(temp_enable_only_show_metadata1)); + char* JsonString = cJSON_Print(root); + + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + CopyFileTo(configPATH, config_bakPATH); + } + else + { + printf("Fail to open Config.json \n"); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } +} + +void replace_one_line_in_a_file(char *path,int line,char *newline) { + /* File pointer to hold reference of input file */ + FILE * fPtr; + FILE * fTemp; + + char buffer[BUFFER_SIZE] = { 0 }; + int count; + + /* Open all required files */ + fPtr = fopen(path, "r"); + fTemp = fopen("replace.tmp", "w+"); + + /* fopen() return NULL if unable to open file in given mode. */ + if (fPtr == NULL ) + { + /* Unable to open file hence exit */ + printf("\nUnable to open [fPtr] file.\n"); + printf("Please check whether file exists and you have read/write privilege.\n"); + exit(EXIT_SUCCESS); + } + if (fTemp == NULL) + { + /* Unable to open file hence exit */ + printf("\nUnable to open [fTemp] file.\n"); + printf("Please check whether file exists and you have read/write privilege.\n"); + exit(EXIT_SUCCESS); + } + /* + * Read line from source file and write to destination + * file after replacing given line. + */ + count = 0; + while ((fgets(buffer, BUFFER_SIZE, fPtr)) != NULL) + { + count++; + + /* If current line is line to replace */ + if (count == line) + fputs(newline, fTemp); + else + fputs(buffer, fTemp); + memset(buffer, 0x00, sizeof(buffer)); + } + + /* Close all files to release resource */ + fclose(fPtr); + fclose(fTemp); + + /* Delete original source file */ + remove(path); + + /* Rename temporary file as original file */ + rename("replace.tmp", path); + //printf("\nSuccessfully replaced '%d' line with '%s'.", line, newline); +} + +size_t get_control_io_from_ipcam(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + //printf("\n-----get_control_io_from_ipcam start\n"); + pthread_mutex_lock(&mutex_curl); + //g_curl_handle_service_from_ipcam = curl_easy_init(); // Initialization for each handler. + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/control?get=io"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[get service from ipcam]cmd: %s\n", cmd); + + if (g_http_handle) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); + if (res_service_from_ipcam != CURLE_OK) // Check for errors + { + fprintf(stderr, "[get control io from ipcam] Failed to initialize the CURL handler for service from ipcam. #1 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[get control io from ipcam] CURL failed to initialize!\n"); + } + + //curl_easy_cleanup(g_curl_handle_service_from_ipcam); + //g_curl_handle_service_from_ipcam = NULL; + //printf("\n-----get_control_io_from_ipcam end\n"); + + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); + return response_size; +} + +//CURL* g_curl_handle_service_from_ipcam = NULL; +size_t get_service_from_ipcam(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + //printf("\n-----get_service_from_ipcam start\n"); + pthread_mutex_lock(&mutex_curl); + //g_curl_handle_service_from_ipcam = curl_easy_init(); // Initialization for each handler. + + /*if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + }*/ + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/service?get=all"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[get service from ipcam]cmd: %s\n", cmd); + + if (g_http_handle) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L); +#endif + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); + if (res_service_from_ipcam != CURLE_OK) // Check for errors + { + fprintf(stderr, "[get service from ipcam] Failed to initialize the CURL handler for service from ipcam. #1 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[get service from ipcam] CURL failed to initialize!\n"); + } + + //curl_easy_cleanup(g_curl_handle_service_from_ipcam); + //g_curl_handle_service_from_ipcam = NULL; + //printf("\n-----get_service_from_ipcam end\n"); + + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); + return response_size; +} + +CURL* g_curl_handle_set_gpio = NULL; +void build_one_gpio(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/service?post."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_gpio) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_PORT, port_num); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_CONNECTTIMEOUT, 3); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TIMEOUT, 5); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TIMEOUT, 3); +#endif + + //curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_smart_event = curl_easy_perform(g_curl_handle_set_gpio); + if (res_smart_event != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one gpio] Failed to initialize the CURL handler for gpio. Reason: %s\n", curl_easy_strerror(res_smart_event)); + } + + curl_easy_reset(g_curl_handle_set_gpio); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one gpio] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +CURL* g_curl_handle_set_smart_event = NULL; +void build_one_smart_event(char * myname,char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/event?event."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_smart_event) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_PORT, port_num); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_CONNECTTIMEOUT, 3); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TIMEOUT, 5); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TIMEOUT, 3); +#endif + + //curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_smart_event = curl_easy_perform(g_curl_handle_set_smart_event); + if (res_smart_event != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one smart event] Failed to initialize the CURL handler for smart event. Reason: %s\n", curl_easy_strerror(res_smart_event)); + } + + curl_easy_reset(g_curl_handle_set_smart_event); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one smart event] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_build_smart_events(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("smart_event"); + pthread_mutex_lock(&mutex_curl); + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_set_smart_event = g_http_handle; // Initialization for each handler. + + build_one_smart_event("event0000", "1"); + build_one_smart_event("name0000", "Aida%20Event%201"); +#ifdef GY_OS_AMBA + build_one_smart_event("c_name00000000", "Open%20Alarm%20And%20Close%20Virtual%201"); +#else + build_one_smart_event("c_name00000000", "Close%20Virtual%201"); +#endif + + build_one_smart_event("c_time00000000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00000000", "virtual_in/0/0/0/1/1"); + build_one_smart_event("c_schedule00000000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + +#ifdef GY_OS_AMBA + build_one_smart_event("c_action00000000", "do/0/1000/active/0/0/0,virtual_in/0/0/inactive/0/0/0,"); +#else + build_one_smart_event("c_action00000000", "virtual_in/0/0/inactive/0/0/0,"); +#endif + + build_one_smart_event("event0001", "1"); + build_one_smart_event("name0001", "Aida%20Event%202%20%2F%20SD%20Recording"); + build_one_smart_event("c_name00010000", "Close%20Virtual%202%20And%20Start%20Recording"); + build_one_smart_event("c_time00010000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00010000", "virtual_in/1/0/0/1/1"); + build_one_smart_event("c_schedule00010000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00010000", "sd/0/60000/active/0/0/0,virtual_in/1/0/inactive/0/0/0,"); + +#ifdef GY_OS_NOVA + if (g_camera_white_LED == 1) { + build_one_smart_event("event0002", "1"); + build_one_smart_event("name0002", "Aida%20Event%203%20%2F%20White%20LED"); + build_one_smart_event("c_name00020000", "Close%20Virtual%203%20And%20Start%20LED"); + build_one_smart_event("c_time00020000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00020000", "virtual_in/2/0/0/1/1"); + build_one_smart_event("c_schedule00020000", "0,7/0/21600,7/64800/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00020000", "ir_led/1/60000/active/0/0/0,virtual_in/2/0/inactive/0/0/0,"); + } +#endif + + +#ifdef GY_OS_AMBA + build_one_smart_event("event0002", "1"); + build_one_smart_event("name0002", "Aida%20Event%203"); + build_one_smart_event("c_name00020000", "Open%20Alarm%20And%20Close%20Virtual%203"); + build_one_smart_event("c_time00020000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00020000", "virtual_in/2/0/0/1/1"); + build_one_smart_event("c_schedule00020000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00020000", "do/0/1000/active/0/0/0,virtual_in/2/0/inactive/0/0/0,"); + + build_one_smart_event("event0003", "1"); + build_one_smart_event("name0003", "Aida%20Event%204"); + build_one_smart_event("c_name00030000", "Open%20Alarm%20And%20Close%20Virtual%204"); + build_one_smart_event("c_time00030000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00030000", "virtual_in/3/0/0/1/1"); + build_one_smart_event("c_schedule00030000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00030000", "do/0/1000/active/0/0/0,virtual_in/3/0/inactive/0/0/0,"); +#endif + + if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { +#ifdef GY_OS_V_SERIES + +#else + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_set_smart_event = g_http_handle; + + build_one_smart_event("event0004", "1"); + build_one_smart_event("name0004", "LPR%20Digital%20Trigger%201"); + build_one_smart_event("c_name00040000", "Open%20HTTP%20Post%20Service%201"); + build_one_smart_event("c_time00040000", "1,10500,0,0,1"); + build_one_smart_event("c_trigger00040000", "digital_in/0/0/8/1/0"); + build_one_smart_event("c_schedule00040000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00040000", "post/0/0/active/0/0/0"); +#endif + + curl_easy_reset(g_curl_handle_set_smart_event); + +#ifdef GY_OS_V_SERIES + +#else + g_curl_handle_set_gpio = g_http_handle; + + build_one_gpio("name0", "Digital_Trigger_Post"); + build_one_gpio("server0", "localhost"); + build_one_gpio("server_port0", accountData[0].account_aida_port); + build_one_gpio("account0", accountData[0].account_username); + build_one_gpio("password0", accountData[0].account_password); + build_one_gpio("url0", "/control?alarm.gpio=1"); + build_one_gpio("content0", "lilinstarthttpget"); + + curl_easy_reset(g_curl_handle_set_gpio); +#endif + } + + pthread_mutex_unlock(&mutex_curl); + + pthread_exit(NULL); + +} + +void* auto_build_smart_events_di_vi(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("smart_di_vi"); + if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { +#ifdef GY_OS_V_SERIES + +#else + pthread_mutex_lock(&mutex_curl); + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_set_smart_event = g_http_handle; // Initialization for each handler. + + build_one_smart_event("event0004", "1"); + build_one_smart_event("name0004", "LPR%20Digital%20Trigger%201"); + build_one_smart_event("c_name00040000", "Open%20HTTP%20Post%20Service%201"); + build_one_smart_event("c_time00040000", "1,10500,0,0,1"); + build_one_smart_event("c_trigger00040000", "digital_in/0/0/8/1/0"); + build_one_smart_event("c_schedule00040000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00040000", "post/0/0/active/0/0/0"); + + curl_easy_reset(g_curl_handle_set_smart_event); + + g_curl_handle_set_gpio = g_http_handle; + + build_one_gpio("name0", "Digital_Trigger_Post"); + build_one_gpio("server0", "localhost"); + build_one_gpio("server_port0", accountData[0].account_aida_port); + build_one_gpio("account0", accountData[0].account_username); + build_one_gpio("password0", accountData[0].account_password); + build_one_gpio("url0", "/control?alarm.gpio=1"); + build_one_gpio("content0", "lilinstarthttpget"); + + curl_easy_reset(g_curl_handle_set_gpio); + pthread_mutex_unlock(&mutex_curl); +#endif + } + pthread_exit(NULL); +} + +CURL* g_curl_handle_set_tof_basic = NULL; +void build_one_set_for_tof_basic(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/tof?image."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_tof_basic) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_set_tof_basic); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + + curl_easy_reset(g_curl_handle_set_tof_basic); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_set_tof_basic(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("tof_basic"); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_set_tof_basic = g_http_handle; // Initialization for each handler. + + build_one_set_for_tof_basic("mode", "1"); + + curl_easy_reset(g_curl_handle_set_tof_basic); + //g_curl_handle_set_tof_basic = NULL; + pthread_mutex_unlock(&mutex_curl); + pthread_exit(NULL); +} + +CURL* g_curl_handle_set_quality_basic = NULL; +void build_one_set_for_quality_basic(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/image?image."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_quality_basic) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_set_quality_basic); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + else { + if (strcmp(myname, "flip") == 0) { + strcpy(accountData[0].account_flip, myvalue); + } + else if (strcmp(myname, "mirror") == 0) { + strcpy(accountData[0].account_mirror, myvalue); + } + else if (strcmp(myname, "rotate") == 0) { + strcpy(accountData[0].account_rotate, myvalue); + } + } + + curl_easy_reset(g_curl_handle_set_quality_basic); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_set_quality_basic(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("set_qual"); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_set_quality_basic = g_http_handle; // Initialization for each handler. + + build_one_set_for_quality_basic("3dnrday", "0"); + build_one_set_for_quality_basic("3dnrnight", "0"); + build_one_set_for_quality_basic("sharpnessday", "0"); + build_one_set_for_quality_basic("sharpnessnight", "0"); + + curl_easy_reset(g_curl_handle_set_quality_basic); + //g_curl_handle_set_quality_basic = NULL; + pthread_mutex_unlock(&mutex_curl); + pthread_exit(NULL); + +} + +void sync_image_rotation_thread() { + //pthread_detach(pthread_self()); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_set_quality_basic = g_http_handle; + + if (strcmp(accountData[0].account_flip, "1") == 0){ + build_one_set_for_quality_basic("flip", "0"); + usSleep(50000); + } + + if (strcmp(accountData[0].account_mirror, "1") == 0){ + build_one_set_for_quality_basic("mirror", "0"); + usSleep(50000); + } + + if (strcmp(accountData[0].account_rotate, "1") == 0){ + build_one_set_for_quality_basic("rotate", "0"); + usSleep(50000); + } + + curl_easy_reset(g_curl_handle_set_quality_basic); + //g_curl_handle_set_quality_basic = NULL; + pthread_mutex_unlock(&mutex_curl); + //pthread_exit(NULL); +} + +//CURL* g_curl_handle_system_time = NULL; +size_t get_system_time_from_ipcam(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + pthread_mutex_lock(&mutex_curl); + //printf("\n-----get_system_time_from_ipcam start\n"); + //g_curl_handle_system_time = curl_easy_init(); // Initialization for each handler. + + /*if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + }*/ + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/system?get=server"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[get service from ipcam]cmd: %s\n", cmd); + + if (g_http_handle) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); + if (res_service_from_ipcam != CURLE_OK) // Check for errors + { + fprintf(stderr, "[get service from ipcam] Failed to initialize the CURL handler for service from ipcam. #2 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[get service from ipcam] CURL failed to initialize!\n"); + } + + //curl_easy_cleanup(g_curl_handle_system_time); + //g_curl_handle_system_time = NULL; + //printf("\n-----get_system_time_from_ipcam end\n"); + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); + return response_size; +} + +CURL* g_curl_handle_resolution_changed = NULL; +size_t build_resolution_changed(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/get_sencode_info"; + //char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + //strcat(cmd, myname); + //strcat(cmd, cmd5); + //strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_resolution_changed) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_resolution_changed); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build resolution changed] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_curl_handle_resolution_changed); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build resolution changed] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif + + return response_size; +} + +int g_check_if_different_width_or_height = 0; +void write_to_stream_width_and_stream_height(int stream_width,int stream_height) { + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char streamPATH[1024] = { 0 }; + strcpy(streamPATH, exePath); + strcat(streamPATH, "stream.json"); + + char stream_bakPATH[1024] = { 0 }; + strcpy(stream_bakPATH, exePath); + strcat(stream_bakPATH, "stream_bak.json"); + + char *filename_stream = streamPATH; + if (!FileExist(filename_stream) && !FileExist(stream_bakPATH)) + { + //printf("%s doesn't exist.\n", filename_stream); + + FILE *fp; + char JsonString[512] = { 0 }; + sprintf(JsonString,"{\"stream_width\":%d,\"stream_height\":%d}", stream_width, stream_height); + + if ((fp = fopen(filename_stream, "w+")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(streamPATH, stream_bakPATH); + } + else + { + printf("Fail to open stream.json #1\n"); + } + } + else + { + if ((!FileExist(streamPATH)) && FileExist(stream_bakPATH)) { + CopyFileTo(stream_bakPATH, streamPATH); + } + + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_stream = ReadAllBytes(filename_stream); + if (fileBuf_stream) { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_stream); + if (fileBuf_stream) { + free(fileBuf_stream); + fileBuf_stream = NULL; + } + + if (root == NULL) + { + printf("root_stream is NULL\n"); + } + else + { + cJSON *cjson_stream_width,*cjson_stream_height; + + cjson_stream_width = cJSON_GetObjectItem(root, "stream_width"); + cjson_stream_height = cJSON_GetObjectItem(root, "stream_height"); + + if (cjson_stream_width) { + if ((int)cjson_stream_width->valueint != stream_width) { + g_check_if_different_width_or_height = 1; + if (cjson_stream_width) { + cJSON_ReplaceItemInObject(root, "stream_width", cJSON_CreateNumber(stream_width)); + } + } + } + + if (cjson_stream_height) { + if ((int)cjson_stream_height->valueint != stream_height) { + g_check_if_different_width_or_height = 1; + if (cjson_stream_height) { + cJSON_ReplaceItemInObject(root, "stream_height", cJSON_CreateNumber(stream_height)); + } + } + } + + if (g_check_if_different_width_or_height == 1) { + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_stream, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(streamPATH, stream_bakPATH); + } + else + { + printf("Fail to open stream.json #2\n"); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } +} + +int get_g_check_if_different_width_or_height() { + return g_check_if_different_width_or_height; +} + +void* auto_resolution_changed(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("resolu"); + char sOutputResponse[MEMORY_SIZE] = { 0 }; + + int try_check_count = 0; + do{ + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_resolution_changed = g_http_handle; // Initialization for each handler. + + memset(sOutputResponse,0x00, MEMORY_SIZE); + int get_size = (int)build_resolution_changed(sOutputResponse); +#ifdef GY_OS_V_SERIES + int check_reboot = 0; +#endif + if (get_size >= 1) { + //printf("\n-----------sOutputResponse:%s\n", sOutputResponse); + char *stream_w = strstr(sOutputResponse, "<width>"); + char *stream_h = strstr(sOutputResponse, "<height>"); + + if (stream_w != NULL && stream_h != NULL){ + + char *stream_w_end = strstr(stream_w, "</width>"); + char *stream_h_end = strstr(stream_h, "</height>"); + if(stream_w_end != NULL && stream_w_end - stream_w - 7 >= 1 && + stream_h_end != NULL && stream_h_end - stream_h - 8 >= 1){ + char stream_width[25] = { 0 }; + memcpy(stream_width, stream_w + 7 , stream_w_end - stream_w - 7); + char stream_height[25] = { 0 }; + memcpy(stream_height, stream_h + 8, stream_h_end - stream_h - 8); + + int current_stream_width = atoi(stream_width); + int current_stream_height = atoi(stream_height); + + //printf("\n--------%d,%d\n", current_stream_width, current_stream_height); + write_to_stream_width_and_stream_height(current_stream_width, current_stream_height); + + if (g_check_if_different_width_or_height == 1) { +#ifdef GY_OS_V_SERIES + check_reboot = 1; +#endif + } + else { + try_check_count++; + } + } + } + + char *stream_encoder1 = strstr(sOutputResponse, "<stream>"); + if (stream_encoder1) { + char temp_stream_encoder1[2048] = { 0 }; + memcpy(temp_stream_encoder1, stream_encoder1 + 8, strlen(stream_encoder1) - 8); + char *stream_encoder2 = strstr(temp_stream_encoder1, "<stream>"); + if (stream_encoder2) { + char temp_stream_encoder2[2048] = { 0 }; + memcpy(temp_stream_encoder2, stream_encoder2 + 8, strlen(stream_encoder2) - 8); + char *stream_encoder3 = strstr(temp_stream_encoder2, "<stream>"); + if (stream_encoder3) { + char temp_stream_encoder3[2048] = { 0 }; + memcpy(temp_stream_encoder3, stream_encoder3 + 8, strlen(stream_encoder2) - 8); + char *stream_h264_gop = strstr(temp_stream_encoder3, "<h264_gop>"); + if (stream_h264_gop) { + char *stream_h264_gop_end = strstr(stream_h264_gop, "</h264_gop>"); + if (stream_h264_gop_end != NULL && stream_h264_gop_end - stream_h264_gop - 10 >= 1) { + char stream_gop[25] = { 0 }; + memcpy(stream_gop, stream_h264_gop + 10, stream_h264_gop_end - stream_h264_gop - 10); + int current_stream_gop = atoi(stream_gop); + g_check_h264_gop = current_stream_gop; + } + } + } + } + } + + } + curl_easy_reset(g_curl_handle_resolution_changed); + //g_curl_handle_resolution_changed = NULL; + pthread_mutex_unlock(&mutex_curl); + +#ifdef GY_OS_V_SERIES + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "different width or height"); + write_to_logs_html(temp_msg, "auto resolution changed", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "auto resolution changed", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } +#else + +#endif + + if (try_check_count >= 10) + break; + usSleep(10000000); + } while (bHttpServerMainStart); + + pthread_exit(NULL); + +} +#ifdef GY_OS_AMBA +int run_check_current_resolution = -1; + +void set_run_check_current_resolution(int set_value) { + run_check_current_resolution = set_value; +} + +int get_run_check_current_resolution() { + return run_check_current_resolution; +} + +void* check_current_resolution(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("check_resolu"); + set_record_process_note("resol_start"); + if (run_check_current_resolution == 0) { + run_check_current_resolution = 1; + int compared_width = 1920; + int compared_height = 1080; + + char sOutputResponse[MEMORY_SIZE] = { 0 }; + + int try_check_count = 0; + do { + pthread_mutex_lock(&mutex_curl); + g_curl_handle_resolution_changed = g_http_handle; // Initialization for each handler. + + memset(sOutputResponse, 0x00, MEMORY_SIZE); + int get_size = (int)build_resolution_changed(sOutputResponse); + if (get_size >= 1) { + //printf("\n-----------sOutputResponse:%s\n", sOutputResponse); + char *stream_w = strstr(sOutputResponse, "<width>"); + char *stream_h = strstr(sOutputResponse, "<height>"); + + if (stream_w != NULL && stream_h != NULL) { + + char *stream_w_end = strstr(stream_w, "</width>"); + char *stream_h_end = strstr(stream_h, "</height>"); + if (stream_w_end != NULL && stream_w_end - stream_w - 7 >= 1 && + stream_h_end != NULL && stream_h_end - stream_h - 8 >= 1) { + char stream_width[25] = { 0 }; + memcpy(stream_width, stream_w + 7, stream_w_end - stream_w - 7); + char stream_height[25] = { 0 }; + memcpy(stream_height, stream_h + 8, stream_h_end - stream_h - 8); + + int current_stream_width = atoi(stream_width); + int current_stream_height = atoi(stream_height); + + if (current_stream_width > compared_width || current_stream_height > compared_height) { + g_check_current_resolution = 0; + } + else { + try_check_count++; + } + } + } + + char *stream_encoder1 = strstr(sOutputResponse, "<stream>"); + if (stream_encoder1) { + char temp_stream_encoder1[2048] = { 0 }; + memcpy(temp_stream_encoder1, stream_encoder1 + 8, strlen(stream_encoder1) - 8); + char *stream_encoder2 = strstr(temp_stream_encoder1, "<stream>"); + if (stream_encoder2) { + char temp_stream_encoder2[2048] = { 0 }; + memcpy(temp_stream_encoder2, stream_encoder2 + 8, strlen(stream_encoder2) - 8); + char *stream_encoder3 = strstr(temp_stream_encoder2, "<stream>"); + if (stream_encoder3) { + char temp_stream_encoder3[2048] = { 0 }; + memcpy(temp_stream_encoder3, stream_encoder3 + 8, strlen(stream_encoder3) - 8); + char *stream_encoder4 = strstr(temp_stream_encoder3, "<stream>"); + if (stream_encoder4) { + char temp_stream_encoder4[2048] = { 0 }; + memcpy(temp_stream_encoder4, stream_encoder4 + 8, strlen(stream_encoder4) - 8); + char *stream_h264_gop = strstr(temp_stream_encoder4, "<h264_gop>"); + if (stream_h264_gop) { + char *stream_h264_gop_end = strstr(stream_h264_gop, "</h264_gop>"); + if (stream_h264_gop_end != NULL && stream_h264_gop_end - stream_h264_gop - 10 >= 1) { + char stream_gop[25] = { 0 }; + memcpy(stream_gop, stream_h264_gop + 10, stream_h264_gop_end - stream_h264_gop - 10); + int current_stream_gop = atoi(stream_gop); + g_check_h264_gop = current_stream_gop; + } + } + } + } + } + } + } + curl_easy_reset(g_curl_handle_resolution_changed); + //g_curl_handle_resolution_changed = NULL; + pthread_mutex_unlock(&mutex_curl); + + if (try_check_count >= 10) + break; + usSleep(10000000); + } while (bHttpServerMainStart); + run_check_current_resolution = -1; + } + set_record_process_note("resol_end"); + pthread_exit(NULL); +} +#endif +CURL* g_curl_handle_getfeatures = NULL; +int g_check_if_OK_getfeatures = 1; +void ipcam_getfeatures() { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/system?get=features"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_getfeatures = g_http_handle; + if (g_curl_handle_getfeatures) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_WRITEDATA, ptr_responded_msg); + + CURLcode res_getfeatures = curl_easy_perform(g_curl_handle_getfeatures); + if (res_getfeatures != CURLE_OK) // Check for errors + { + fprintf(stderr, "[ipcam getfeatures] Failed to initialize the CURL handler. Reason: %s\n", curl_easy_strerror(res_getfeatures)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "[ipcam getfeatures] Failed to initialize the CURL handler. Reason: %s", curl_easy_strerror(res_getfeatures)); + write_to_logs_html(temp_msg, "ipcam_getfeatures", "ERROR", SystemSetting.enable_system_logs); + } + else { + if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { + if (strstr(ptr_responded_msg->memory,"98529ab")!=NULL) { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg, "The camera doesn't support car plate."); + write_to_logs_html(temp_msg, "ipcam_getfeatures", "INFO", SystemSetting.enable_system_logs); + g_check_if_OK_getfeatures = 0; + } + + if (strstr(ptr_responded_msg->memory, "FEATURE_SYS_CAPTURE_EFR=1") != NULL) { + //char temp_msg[8192] = { 0 }; + //strcpy(temp_msg, "The camera support thermal."); + //write_to_logs_html(temp_msg, "ipcam_getfeatures", "INFO", SystemSetting.enable_system_logs); + g_check_if_OK_thermal = 1; + } + } + } + + curl_easy_reset(g_curl_handle_getfeatures); + if (pList != NULL) + curl_slist_free_all(pList); + + ptr_responded_msg->size = 0; + } + else + { + printf("[ipcam getfeatures] CURL failed to initialize!\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", "[ipcam getfeatures] CURL failed to initialize!"); + write_to_logs_html(temp_msg, "ipcam_getfeatures", "ERROR", SystemSetting.enable_system_logs); + } + + //curl_easy_cleanup(g_curl_handle_getfeatures); + //g_curl_handle_getfeatures = NULL; + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); +} + +CURL* g_curl_handle_reboot = NULL; +void build_reboot(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/maintenance?"; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_reboot) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_reboot, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_reboot); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + + curl_easy_reset(g_curl_handle_reboot); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_reboot(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("reboot"); + do{ + pthread_mutex_lock(&mutex_curl); + g_curl_handle_reboot = g_http_handle; // Initialization for each handler. + + build_reboot("reboot", "1"); + + curl_easy_reset(g_curl_handle_reboot); + //g_curl_handle_reboot = NULL; + pthread_mutex_unlock(&mutex_curl); + + usSleep(1000000); + } while (bHttpServerMainStart); + + pthread_exit(NULL); + +} + +CURL* g_curl_handle_system = NULL; +void build_system(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/system?"; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_system) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_system, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_system, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_system, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_system, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_system, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_system, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_system, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_system, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_system, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_system, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_system); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + + curl_easy_reset(g_curl_handle_system); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_system(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("osd_system"); + //do + { + pthread_mutex_lock(&mutex_curl); + g_curl_handle_system = g_http_handle; // Initialization for each handler. + + build_system("osd.font", "0"); + build_system("osd.time", "0"); + build_system("osd.status", "0"); + + curl_easy_reset(g_curl_handle_system); + //g_curl_handle_system = NULL; + pthread_mutex_unlock(&mutex_curl); + } + //while (bHttpServerMainStart); + + pthread_exit(NULL); + +} + +#if 0 +void GetAidaPort(){ + //printf("\nGetAidaPort 1\n"); + char filename[1024] = {0}; + strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("\nGetAidaPort 1-2\n"); + char* fileBuf = ReadAllBytes(filename); + + if (fileBuf) { + cJSON *plugin, *aida_port; + //printf("\nGetAidaPort 2\n"); + plugin = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + //printf("\nGetAidaPort 3\n"); + if (plugin != NULL) { + //printf("config.json parse OK.\n"); + aida_port = cJSON_GetObjectItem(plugin, "port"); + strcpy(accountData[0].account_aida_port, aida_port->valuestring); + //printf("\nKKKKKKK:%s\n", accountData[0].account_aida_port); + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } +} + +#endif + +#define TIME_ZONE_NUMBER 32 +//char g_time_zone_text[TIME_ZONE_NUMBER][10] = { "UTC","GMT","BST","IST","WET","WEST","CET","CEST","EET","EEST","MSK","MSD","AST","ADT","NST","NDT","EST","EDT","CST","CDT","MST","MDT","PST","PDT","HST","AKST","AKDT","AEST","AEDT","ACST","ACDT","AWST" }; +//float g_time_zone_number[TIME_ZONE_NUMBER] = { 0,0,1,1,0,1,1,2,2,3,3,4,-4,-3,-3.5,-2.5,-5,-4,-6,-5,-7,-6,-8,-7,-10,-9,-8,10,11,9.5,10.5,8 }; + +int get_timezone_info(char *time_zone_buf) +{ + int timeZone = 0; + + +#if 0 + char *findPos = NULL; + if (strstr(sOutputResponse, "+") != NULL) + { + } + else if (strstr(sOutputResponse, "-") != NULL) + { + } + else + { + for (int i = 0; i < TIME_ZONE_NUMBER; i++) + { + if (strcmp(sOutputResponse, g_time_zone_text[i]) != 0) + { + + break; + } + } + } +#endif + return timeZone; +} + +void update_system_time() { + char sOutputResponse[MEMORY_SIZE] = { 0 }; + char SystemTimeText[8192] = { 0 }; + //char SystemTimeText_withzone[8192] = { 0 }; + + int get_size = (int)get_system_time_from_ipcam(sOutputResponse); + + //printf("get size = %d \n, %s \n", get_size, sOutputResponse); + + if (get_size >= 1) { + sOutputResponse[get_size] = '\0'; + char *findPos = NULL; + findPos = strstr(sOutputResponse, "time="); + //char *findPosB = NULL; + //findPosB = strstr(sOutputResponse, "model="); + + if (findPos != NULL + && strlen(findPos) >= 24 + //& findPosB != NULL + ) //time=2022/12/02 14:37:23 + { + //int time_str_len = findPosB - (findPos + 5); + //memcpy(SystemTimeText_withzone, findPos + 5, time_str_len); //+19 + //printf("get sys time zone text= %s \n", SystemTimeText); + + //int iTimeZone = get_timezone_info(SystemTimeText_withzone); + + memcpy(SystemTimeText, findPos + 5, 19); //+19 + //printf("get sys time text= %s \n", SystemTimeText); + + int count_digit = 0; + for (int i = 0; i < strlen(SystemTimeText); i++) { + if (isdigit(SystemTimeText[i])) + { + count_digit++; + } + } + + if (count_digit == 14) { + struct tm tm_val; + time_t epoch = 0; + + //strptime + int r; + r = sscanf(SystemTimeText, "%d/%d/%d %d:%d:%d", &tm_val.tm_year, &tm_val.tm_mon, &tm_val.tm_mday, &tm_val.tm_hour, &tm_val.tm_min, &tm_val.tm_sec); + + if (r != 6) { + printf("expected %d numbers scanned in %s\n", r, SystemTimeText); + //char* defaultdata = "1900-01-01 01:01:01"; + } + + epoch = strptime_s(&tm_val); + //strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + //epoch = mktime(&tm_val); + //printf("get sys time stamp = %d \n", epoch); + //printf("\n-----g_osdSysTimeStamp:%ld,time(0):%ld\n", g_osdSysTimeStamp, time(0)); + + + if (epoch > time(0) && difftime(epoch, time(0)) >= 3540 && difftime(epoch, time(0)) <= 3660) { + g_osdSysTimeStamp = time(0); + } + else if (epoch < time(0) && difftime(time(0), epoch) >= 3540 && difftime(time(0), epoch) <= 3660) { + g_osdSysTimeStamp = time(0); + } + else{ + g_osdSysTimeStamp = epoch; + } + + //get gmt+0 time + time_t t, gmt_t; + struct tm *gmt; + t = time(NULL); + gmt = gmtime(&t); + gmt_t = mktime(gmt); + + int iTimeZone = 0; + + iTimeZone = epoch - gmt_t; + + g_osdSysTimeZoneInfo = iTimeZone; + + /*if (tm_val.tm_mday == gmt->tm_mday) + { + iTimeZone = tm_val.tm_hour - gmt->tm_hour; + } + else + { + if (tm_val.tm_mday > gmt->tm_mday) + { + iTimeZone = (24 + tm_val.tm_hour) - gmt->tm_hour; + } + else + { + iTimeZone = tm_val.tm_hour - (24 + gmt->tm_hour); + } + }*/ + + //printf("Time Zone info = %d \n", iTimeZone); + + + + //struct tm *tm_local; + //tm_local = localtime(&epoch); + //printf("time = %d-%d-%d %d:%d:%d \n", tm_local->tm_year+1900, tm_local->tm_mon+1, tm_local->tm_mday, tm_local->tm_hour, tm_local->tm_min, tm_local->tm_sec); + } + } + } +} + +void copy_control_io_to_gynet() { + char my_response[MEMORY_SIZE] = { 0 }; + int my_size = 0; + + int count_row = 0; + char data_service[MAX_SERVICE_SIZE][STRSPLIT_SIZE] = { 0 }; + + const char *del = "\n"; + const char *del2 = "="; + + char data_service_pair[MAX_SERVICE_SIZE][2][STRSPLIT_SIZE] = { 0 }; + //int data_service_pair_num[MAX_SERVICE_SIZE] = { 0 }; + + my_size = (int)get_control_io_from_ipcam(my_response); + + if (my_size >= 1) { + my_response[my_size] = '\0'; + + count_row = StrSplit(my_response, data_service, del); + //printf("\n------UU:21\n"); + + //int i_temp = -1; + + for (int i = 0; i < count_row; i++) + { + if (strlen(data_service[i]) >= 1) + { + /*data_service_pair_num[i] = + */ + StrSplit(data_service[i], data_service_pair[i], del2); + //printf("\n------UU:22\n"); + + + if (strcmp(data_service_pair[i][0], "alarm_input0") == 0) { + if (atoi(data_service_pair[i][1]) == 0) { + set_g_control_alarm_gpio_to_zero(); + } + else if(atoi(data_service_pair[i][1]) == 1){ + set_g_control_alarm_gpio_to_one(); + } + break; + } + } + } + } +} + +void copy_ipcam_smtp_service_to_gynet() { + char my_response[MEMORY_SIZE] = { 0 }; + int my_size = 0; + + int count_row = 0; + char data_service[MAX_SERVICE_SIZE][STRSPLIT_SIZE]={0}; + + const char *del = "\n"; + const char *del2 = "="; + + char data_service_pair[MAX_SERVICE_SIZE][2][STRSPLIT_SIZE]={0}; + //int data_service_pair_num[MAX_SERVICE_SIZE] = { 0 }; + + my_size = (int)get_service_from_ipcam(my_response); + + if (my_size >= 1) { + my_response[my_size] = '\0'; + + count_row = StrSplit(my_response, data_service, del); + //printf("\n------UU:21\n"); + + //int i_temp = -1; + + for (int i = 0; i < count_row; i++) + { + if (strlen(data_service[i]) >= 1) + { + /*data_service_pair_num[i] = + */ + StrSplit(data_service[i], data_service_pair[i], del2); + //printf("\n------UU:22\n"); + + if (strcmp(data_service_pair[i][0], "smtp.receiver0") == 0) { + strcpy(IPCAMService.email_address1, data_service_pair[i][1]); + IPCAMService.email_address1[strlen(IPCAMService.email_address1) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver1") == 0) { + strcpy(IPCAMService.email_address2, data_service_pair[i][1]); + IPCAMService.email_address2[strlen(IPCAMService.email_address2) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver2") == 0) { + strcpy(IPCAMService.email_address3, data_service_pair[i][1]); + IPCAMService.email_address3[strlen(IPCAMService.email_address3) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver3") == 0) { + strcpy(IPCAMService.email_address4, data_service_pair[i][1]); + IPCAMService.email_address4[strlen(IPCAMService.email_address4) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver4") == 0) { + strcpy(IPCAMService.email_address5, data_service_pair[i][1]); + IPCAMService.email_address5[strlen(IPCAMService.email_address5) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.address") == 0) { + strcpy(IPCAMService.email_address, data_service_pair[i][1]); + IPCAMService.email_address[strlen(IPCAMService.email_address) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.server") == 0) { + strcpy(IPCAMService.smtp_server, data_service_pair[i][1]); + IPCAMService.smtp_server[strlen(IPCAMService.smtp_server) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.auth_mode") == 0) { + IPCAMService.smtp_auth_mode = atoi(data_service_pair[i][1]); + } + else if (strcmp(data_service_pair[i][0], "smtp.port") == 0) { + strcpy(IPCAMService.smtp_port, data_service_pair[i][1]); + IPCAMService.smtp_port[strlen(IPCAMService.smtp_port) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.auth") == 0) { + IPCAMService.smtp_auth = atoi(data_service_pair[i][1]); + } + else if (strcmp(data_service_pair[i][0], "smtp.account") == 0) { + strcpy(IPCAMService.auth_account, data_service_pair[i][1]); + IPCAMService.auth_account[strlen(IPCAMService.auth_account) - 1] = '\0'; + } + } + } + /* + printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT start\n"); + printf("\nemail_address1:%s\n", IPCAMService.email_address1); + printf("\nemail_address2:%s\n", IPCAMService.email_address2); + printf("\nemail_address3:%s\n", IPCAMService.email_address3); + printf("\nemail_address4:%s\n", IPCAMService.email_address4); + printf("\nemail_address5:%s\n", IPCAMService.email_address5); + printf("\nemail_address:%s\n", IPCAMService.email_address); + printf("\nsmtp_server:%s\n", IPCAMService.smtp_server); + printf("\nsmtp_auth_mode:%d\n", IPCAMService.smtp_auth_mode); + printf("\nsmtp_port:%s\n", IPCAMService.smtp_port); + printf("\nsmtp_auth:%d\n", IPCAMService.smtp_auth); + printf("\nauth_account:%s\n", IPCAMService.auth_account); + + printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT end\n");*/ + } +} +#ifdef GY_OS_AMBA +void sync_other_camera_lpr_db() { + + char lpr_db_url[8192] = { 0 }; + + strcpy(lpr_db_url, "http://"); + + if (strlen(SystemSetting.external_lpr_db_username) >= 1 && strlen(SystemSetting.external_lpr_db_password) >= 1) { + strcat(lpr_db_url, SystemSetting.external_lpr_db_username); + strcat(lpr_db_url, ":"); + strcat(lpr_db_url, SystemSetting.external_lpr_db_password); + strcat(lpr_db_url, "@"); + } + + if (strcmp(SystemSetting.external_lpr_db_IP, "127.0.0.1") != 0 && strcmp(SystemSetting.external_lpr_db_IP, "localhost") != 0) { + strcat(lpr_db_url, SystemSetting.external_lpr_db_IP); + } + else { + strcpy(SystemSetting.external_lpr_db_IP, "127.0.0.1"); + strcat(lpr_db_url, SystemSetting.external_lpr_db_IP); + } + + if (strlen(SystemSetting.external_lpr_db_port) >= 1) { + strcat(lpr_db_url, ":"); + strcat(lpr_db_url, SystemSetting.external_lpr_db_port); + } + + strcat(lpr_db_url, "/Aida_data/db_fflpr.db"); + + printf("Http lpr_db_url: %s \n", lpr_db_url); + + strcpy(g_stCURL_lpr_db_url, lpr_db_url); + strcpy(g_stCURL_lpr_db_username, SystemSetting.external_lpr_db_username); + strcpy(g_stCURL_lpr_db_password, SystemSetting.external_lpr_db_password); + strcpy(g_stCURL_lpr_db_port, SystemSetting.external_lpr_db_port); + + pthread_t curl_lpr_db_thread_id; + if (pthread_create(&curl_lpr_db_thread_id, 0, net_curl_https_get_other_lpr_db, NULL)) + { + printf("create curl lpr db thread faile \n"); + } +} +#endif +void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, char* contentBuffer/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType, int* isGetalarmMotion, int sock_info_idx) +{ + + //printf("----------------------------[web process]recvBuffer: %s\n",recvBuffer); + int j = 0, buflen = 0, len = 0, /*bIsContent = 0,*/ bIsMultipart = 0; + long idx = 0, nTotalContentLen = 0; + //long nbytes = 0, nTotalBytes = 0, nContentLen = 0; + char* fstr, * ContentStart; + char msg[MAX_MSG_LEN] = {0}; + char sendBuffer[BUFSIZE_V2] = { 0 }; + char beforeSendBuffer[BUFSIZE_V2] = { 0 }; + char headerBuffer[BUFSIZE_V2] = { 0 }; + char firstBuffer[BUFSIZE_V2] = { 0 }; + char urlBuffer[BUFSIZE_V2] = { 0 }; + char httpCommand[8] = { 0 }; + + //char OriAttribute[512] = { 0 };//512 + char tempBuffer[BUFSIZE_V2] = { 0 }; + char out[MAX_MSG_LEN] = { 0 }; + char multiPartBoundary[MAX_MSG_LEN] = { 0 }; + char contentDescription[MAX_MSG_LEN] = { 0 }; + SOCKET cli_socket = *client_socket; + int tracking_channel = MAX_AI_ENGINE_VIEW; + int tracking_channel_idx = MAX_AI_ENGINE_VIEW - 1; +#if defined GY_OS_AMBA + int AIImage_width = 1920; + int AIImage_height = 1080; +#endif + /* read the web browser request through the TCP connection */ + //memset(recvBuffer, 0x00, sizeof(recvBuffer)); + //memset(sendBuffer, 0x00, sizeof(sendBuffer)); + //memset(headerBuffer, 0x00, sizeof(headerBuffer)); + //memset(httpCommand , 0x00, sizeof(httpCommand)); + //printf("\n------------recvBuffer:%s\n", recvBuffer); + + //printf("\n[web process]start\n"); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +//#ifdef _DEBUG_AMBA + //printf("\n(%d) [web process] Program binary path is: %s\n", cli_socket,buf); + //printf("\n(%d) [web process] mac_address: %s\n", cli_socket, mac_address); +//#endif + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024]; + char config_bakPATH[1024]; + char eventsPATH[1024]; + char events_bakPATH[1024]; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + strcpy(events_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + strcat(events_bakPATH, "events_bak.json"); + + clock_t t1 = clock(); + + if (strncmp(recvBuffer, "GET ", strlen("GET ")) == 0 || strncmp(recvBuffer, "get ", strlen("get ")) == 0) + memcpy(httpCommand, recvBuffer, strlen("GET ")); + else if (strncmp(recvBuffer, "POST ", strlen("POST ")) == 0 || strncmp(recvBuffer, "post ", strlen("post ")) == 0) + memcpy(httpCommand, recvBuffer, strlen("POST ")); + else + { + sprintf(msg, "Only simple GET and POST method is supported."); + printf(msg); + //syslog(NW_SORRY, msg, recvBuffer, cli_socket); + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #17\n"); + //printf("\n[web process]-1: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + //syslog(NW_LOG, "request", httpCommand, hit); + //printf("\n[web process]start 2\n"); + if (strcmp(httpCommand, "GET ") == 0 || strcmp(httpCommand, "POST ") == 0) + { + ContentStart = FindHttpContentStart(recvBuffer); + if (ContentStart) + { + memcpy(headerBuffer, recvBuffer, ContentStart - recvBuffer); + //DumpCharacters(headerBuffer, nTotalBytes + ContentStart - recvBuffer); + memcpy(contentBuffer, ContentStart, recvBuffer + recv_buff_size - ContentStart); + //printf("contentBuffer=%s", contentBuffer); + //DumpCharacters(contentBuffer, 8192); + //nContentLen = (recvBuffer + nbytes - ContentStart); + + if (strcmp(httpCommand, "POST ") == 0) + { + //char delim[2] = "HT"; + char *start = headerBuffer; + char *pDelim; + do + { + pDelim = strstr(start, "\r\n"); + // string between start and delim (or end of string if delim is NULL). + if (pDelim) + { + char attribute[512] = { 0 };//512 + memcpy(attribute, start, pDelim - start); + attribute[pDelim - start] = 0; + char att_var[10][STRSPLIT_SIZE]={0}; + char *del = ":"; + + if ((pDelim - start) >= 1) + { + if (strstr(attribute, "Content-Length") != NULL) { + //printf("\n------UU:23-1\n"); + StrSplit(attribute, att_var, del); + if (strcmp(att_var[0], "Content-Length") == 0) + { + nTotalContentLen = atoi(att_var[1]); + //printf("Content-Length %d:%d\n", cli_socket, nTotalContentLen); + } + } + else if (strstr(attribute, "Content-Type") != NULL) { + //printf("\n------UU:23-2\n"); + StrSplit(attribute, att_var, del); + if (strcmp(att_var[0], "Content-Type") == 0) + { + TrimSpace(out, sizeof(out), att_var[1], 0); + if (strncmp(MULTIPART_CONTENT, out, strlen(MULTIPART_CONTENT)) == 0) + { + bIsMultipart = 1; + strcat(multiPartBoundary, "--"); + strcat(multiPartBoundary, out + strlen(MULTIPART_CONTENT)); + } + } + } + else if (strstr(attribute, "Content-Description") != NULL) { + //printf("\n------UU:23-3\n"); + StrSplit(attribute, att_var, del); + if (strcmp(att_var[0], "Content-Description") == 0) + { + strcpy(contentDescription, att_var[1]); + char* channelNum = strstr(contentDescription, "-CH"); + if (channelNum) + { + channelNum = channelNum + strlen("-CH"); + tracking_channel = atoi(channelNum) /*+ 16*/; //1~16 reserved for AIEngine.exe. + tracking_channel_idx = tracking_channel; + } + else + { + channelNum = strstr(contentDescription, "CHANNEL") + strlen("CHANNEL"); + if (channelNum) + { + tracking_channel = atoi(channelNum); + tracking_channel_idx = tracking_channel - 1; + } + else + { + tracking_channel = MAX_TRACKING_NUM + 1; + tracking_channel_idx = MAX_TRACKING_NUM; + } + } + + char* jpegWidthNum = strstr(contentDescription, "width="); + if (jpegWidthNum) + { + jpegWidthNum = jpegWidthNum + strlen("width="); +#if defined GY_OS_AMBA + AIImage_width = atoi(jpegWidthNum); +#endif + } + + char* jpegHeightNum = strstr(contentDescription, "height="); + if (jpegHeightNum) + { + jpegHeightNum = jpegHeightNum + strlen("height="); +#if defined GY_OS_AMBA + AIImage_height = atoi(jpegHeightNum); +#endif + } + } + } + } + start = pDelim + 2; // Use length of your b string. + } + } + while (pDelim); + } + } + else + { + //printf("\n[web process]-2: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + printf("[web process] FindHttpContentStart returned error.\n"); + return; + } + } + //printf("\n[web process]start 3\n"); + //clock_t t2 = clock(); + //diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("parsing header time:%f\n", diff); + /* null-terminate after the second space to ignore extra stuff */ + + for (idx = strlen(httpCommand); idx < LINE_BUFSIZE; idx++) + { + if (headerBuffer[idx] == ' ') + { + /* string is "GET URL " +lots of other stuff */ + memcpy(urlBuffer, headerBuffer + strlen(httpCommand), idx - strlen(httpCommand)); + urlBuffer[idx - strlen(httpCommand)] = 0; + memcpy(firstBuffer, headerBuffer, idx); + firstBuffer[idx] = 0; + break; + } + } + +#if defined GY_OS_AMBA + //check /airelay + char *pch; + int newStrLen = 0; + pch = strstr(urlBuffer, "/airelay"); + if (pch != NULL) + { + if (pch == urlBuffer) + { + newStrLen = strlen(urlBuffer) - 8; + memcpy(urlBuffer, urlBuffer + 8, newStrLen); + urlBuffer[newStrLen] = 0; + } + } +#endif + + //printf("\n[web process]start 4\n"); + /* check for illegal parent directory use .. */ + for (j = 0; j < idx - 1 - strlen(httpCommand); j++) + { + if (urlBuffer[j] == '.' && urlBuffer[j + 1] == '.') + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Parent directory(..) path names not supported."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + //syslog(NW_SORRY, "Parent directory (..) path names not supported", firstBuffer, cli_socket); + //printf("\n(%d) [web process] Parent directory (..) path names not supported \n", cli_socket); + //printf("\n[web process]-3: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + } + //printf("\n[web process]start 5\n"); + char beforeSendBuffer_xtra[BUFSIZE * 60] = { 0 }; + + if (strlen(g_account_port_protected) == 0) { + strcpy(g_account_port_protected, accountData[0].account_port); + } + else { + if (strcmp(g_account_port_protected, accountData[0].account_port) != 0) { + memset(g_account_port_protected, 0x00, sizeof(g_account_port_protected)); + strcpy(g_account_port_protected, accountData[0].account_port); + } + } + //printf("\n[web process]start 6\n"); + // Analyze all HTTP requests + //printf("\n-------httpCommand:%s\n", httpCommand); + + if (strcmp(httpCommand, "GET ") == 0) + { +#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### sophia (%d) urlBuffer:%s start \n", cli_socket, cli_socket,urlBuffer); +#endif + + //printf("\n---------urlBuffer:%s\n", urlBuffer); + if (strcmp(urlBuffer, "/server") == 0) + { + //printf("\n[web process]start 7\n"); + + char Msg[256] = { 0 }; + strcpy(contentBuffer, "DeviceName=GYNet\r\n<br/>"); +#ifdef GY_OS_WIN + sprintf(Msg, "Version=%s\r\n", ProductVersion); +#elif defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "Version=%s\r\n", APP_VERSION); +#endif + strcat(contentBuffer, Msg); + strcat(contentBuffer, "Language="); + strcat(contentBuffer, SystemSetting.language); + strcat(contentBuffer, "\r\n<br/>"); +//#ifdef GY_OS_WIN + //sprintf(Msg, "SystemID=%s\r\n<br/>", mac_address); +//#elif defined GY_OS_AMBA || defined GY_OS_NOVA + //Get MAC Address + char fetch_mac_addr[30] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + GetMACAddress(fetch_mac_addr); + sprintf(Msg, "SystemID=%s\r\n<br/>", fetch_mac_addr); +//#endif + strcat(contentBuffer, Msg); + sprintf(Msg, "LicenseType=%s\r\n<br/>", strLicenseType); + strcat(contentBuffer, Msg); + sprintf(Msg, "Default=%s\r\n<br/>", heartbeatData.events_default_version); + strcat(contentBuffer, Msg); + + int check_input_key = 0; + + { + char buf_exe[1024] = {}; + readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); + + char exePath_temp[1024] = {}; + getFilePath(buf_exe, exePath_temp, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath_temp); + strcat(keyPATH, "key.txt"); + + char key_buff[1024] = { 0 };//creating char array to store data of file + + if (FileExist(keyPATH) == 1) { + + FILE *pFile; + if ((pFile = fopen(keyPATH, "r")) != NULL) + { + fscanf(pFile, "%s", key_buff); + fclose(pFile); + } + } + + if (strcmp(key_buff, strUnlockingKey)==0) { + check_input_key = 1; + } + } + + if (check_input_key == 1) + { + sprintf(Msg, "LicenseStatus=%s\r\n<br/>", strLicenseStatus); + strcat(contentBuffer, Msg); + sprintf(Msg, "UnlockingKey=%s\r\n<br/>", strUnlockingKey); + strcat(contentBuffer, Msg); + } + else { + sprintf(Msg, "LicenseStatus=%s\r\n<br/>", ""); + strcpy(strLicenseStatus,""); + strcat(contentBuffer, Msg); + sprintf(Msg, "UnlockingKey=%s\r\n<br/>", strUnlockingKey); + strcat(contentBuffer, Msg); + } + + /*else { + sprintf(Msg, "LicenseStatus=%s\r\n<br/>", "Fail to input key."); + strcpy(strLicenseStatus,"Fail to input key."); + strcat(contentBuffer, Msg); + sprintf(Msg, "UnlockingKey=%s\r\n<br/>", strUnlockingKey); + strcat(contentBuffer, Msg); + }*/ + + sprintf(Msg, "ModeName=%s\r\n<br/>", WeightFileModeName); + strcat(contentBuffer, Msg); + +#ifdef GY_OS_WIN + if (!nIsCompatibleCPU) + { + sprintf(Msg, "SysStatus=%s\r\n<br/>", "[ERROR] The CPU doesn't meet hardware requirements for OpenVINO!"); + strcat(contentBuffer, Msg); + } + else + strcat(contentBuffer, "SysStatus=OK\r\n<br/>"); +#endif + strcpy(beforeSendBuffer, contentBuffer); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_server(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18\n"); + //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } +#if 1 + else if (strcmp(urlBuffer, "/enable_downsized_cropped_roi") == 0 || strcmp(urlBuffer, "/disable_downsized_cropped_roi") == 0) + { +#ifdef GY_OS_AMBA + if (strcmp(urlBuffer, "/enable_downsized_cropped_roi") == 0) { + set_enable_downsized_cropped_roi(1); + strcpy(beforeSendBuffer, "Enable downsized cropped roi."); + } + else { + set_enable_downsized_cropped_roi(0); + strcpy(beforeSendBuffer, "Disable downsized cropped roi."); + } +#endif //GY_OS_AMBA + + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18-2\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/enable_zone_crop") == 0 || strcmp(urlBuffer, "/disable_zone_crop") == 0) + { +#ifdef GY_OS_AMBA + if (strcmp(urlBuffer, "/enable_zone_crop") == 0) { + set_enable_zone_crop_1(1); + strcpy(beforeSendBuffer, "Enable zone crop."); + } + else { + set_enable_zone_crop_1(0); + strcpy(beforeSendBuffer, "Disable zone crop."); + } +#endif //GY_OS_AMBA + + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18-212\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_cropped_roi") == 0) + { + char Msg[256] = { 0 }; +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "{\"CROPPED_ROI\":\"%d\",\"CROPPED_ZONE_1\":\"%d\"}", get_enable_downsized_cropped_roi(), get_enable_zone_crop_1()); +#endif //GY_OS_AMBA + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18-3\n"); + closesocket(cli_socket); + } +#endif + else if (strcmp(httpCommand, "GET ") == 0 && (strcmp(urlBuffer, "/getalarmmotion") == 0 || strstr(urlBuffer, "/getalarmmotion"))) + { + //printf("******************************************* recv getalarmmotion [%d]\n", cli_socket); + //printf("\n[web process]start 8\n"); + + *isGetalarmMotion = TRUE; + } + else if ((strcmp(urlBuffer, "/Aida/index.html") == 0) || + (strcmp(urlBuffer, "/Aida/radar.html") == 0) || + (strcmp(urlBuffer, "/Aida/radar.js") == 0) || + (strcmp(urlBuffer, "/Aida/face_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/face_list.html") == 0) || + (strcmp(urlBuffer, "/Aida/face_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/face_list.js") == 0) || + (strcmp(urlBuffer, "/Aida/face.js") == 0) || + (strcmp(urlBuffer, "/Aida/sweetalert2.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/css/sweetalert2.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/upload_img.html") == 0) || + (strcmp(urlBuffer, "/Aida/anpr_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/countdown.html") == 0) || + (strcmp(urlBuffer, "/Aida/countdown_output.html") == 0) || + (strcmp(urlBuffer, "/Aida/speed_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/speed_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/radar_speed_share.js") == 0) || + (strcmp(urlBuffer, "/Aida/ptz.html") == 0) || + (strcmp(urlBuffer, "/Aida/ptz.js") == 0) || + (strcmp(urlBuffer, "/Aida/tof.html") == 0) || + (strcmp(urlBuffer, "/Aida/tof.js") == 0) || + (strcmp(urlBuffer, "/Aida/setting.html") == 0) || + (strcmp(urlBuffer, "/Aida/license.html") == 0) || + (strcmp(urlBuffer, "/Aida/alarm.html") == 0) || + (strcmp(urlBuffer, "/Aida/airelay_init.html") == 0) || + (strcmp(urlBuffer, "/Aida/alarm_on_airelay.html") == 0) || + (strcmp(urlBuffer, "/Aida/alarm_on_airelay.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit1.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit2.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit3.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit3.wasm") == 0) || + (strcmp(urlBuffer, "/Aida/output.html") == 0) || + (strcmp(urlBuffer, "/Aida/logs.html") == 0) || + (strcmp(urlBuffer, "/Aida/pythonR.html") == 0) || + (strcmp(urlBuffer, "/Aida/python.html") == 0) || + //(strcmp(urlBuffer, "/Aida/logs_sample.html") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/bootstrap.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/jquery.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/bootstrap.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/geotools.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/geotools-swedish-zipcodes.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/moment.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/fancyTable.js") == 0) || + (strcmp(urlBuffer, "/Aida/object_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/js_3_5_1.js") == 0) || + //(strcmp(urlBuffer, "/Aida/lilinivs.js") == 0) || + (strcmp(urlBuffer, "/Aida/index.js") == 0) || + (strcmp(urlBuffer, "/Aida/config.js") == 0) || + (strcmp(urlBuffer, "/Aida/lang.js") == 0) || + (strcmp(urlBuffer, "/Aida/alarm.js") == 0) || + (strcmp(urlBuffer, "/Aida/state.js") == 0) || + (strcmp(urlBuffer, "/Aida/label_names.js") == 0) || + (strcmp(urlBuffer, "/Aida/third_party_label_names.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/setting_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/gauge.min_on_nvr.js") == 0) || + (strcmp(urlBuffer, "/Aida/css/style.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/timebar.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/timebar.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/owl.carousel.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/owl.theme.default.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/lib/owl.carousel.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/timebar.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/timebar.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/timebar-1.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery-ui.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.blockUI.js") == 0) || + (strcmp(urlBuffer, "/Aida/fabric.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lpr.html") == 0) || + (strcmp(urlBuffer, "/Aida/cool_counter_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_return.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_return2.png") == 0) || + (strcmp(urlBuffer, "/Aida/lpr.js") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.css") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.html") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.min.js") == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data.js",21) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_1.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_2.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_3.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_4.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_5.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_6.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_7.js", 23) == 0) || + (strcmp(urlBuffer, "/Aida/heatmap_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/prism.js") == 0) || + (strcmp(urlBuffer, "/Aida/cgi.js") == 0) || + (strcmp(urlBuffer, "/Aida/icon.js") == 0) || + (strcmp(urlBuffer, "/Aida/gauge.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/chirun_min.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.form.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_mapping.htm") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_list_upload.htm") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_list.html") == 0) || + (strcmp(urlBuffer, "/Aida/cool_counter.html") == 0) || + //(strcmp(urlBuffer, "/Aida/time_bar.html") == 0) || + (strcmp(urlBuffer, "/Aida/jquery-ui.css") == 0) || + (strcmp(urlBuffer, "/Aida/jqueryAll.js") == 0) || + (strcmp(urlBuffer, "/Aida/cool_counter.js") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.js") == 0) || + (strcmp(urlBuffer, "/Aida/cookie.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/fabric.js") == 0) || + (strcmp(urlBuffer, "/Aida/lang_cookie.js") == 0) || + (strcmp(urlBuffer, "/Aida/posttoken.html") == 0) || + (strcmp(urlBuffer, "/Aida/snmptoken.html") == 0) || + (strcmp(urlBuffer, "/Aida/osdtoken.html") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.easyui.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.slider.js") == 0) || + (strcmp(urlBuffer, "/Aida/aes.js") == 0) || + (strcmp(urlBuffer, "/Aida/easyui.css") == 0) || + (strcmp(urlBuffer, "/Aida/easyui_jvc.css") == 0) || + (strcmp(urlBuffer, "/Aida/object_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/bootstrap.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/warning.html") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/NoParking_Red_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/Counter_Green_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/SpeedWithRim_Red_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/CarWithRim_Yellow_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/ExclamationMark_Blue_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_alarm.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_ai_setting1.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_ai_setting2.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_anpr.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_export.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_import.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_license.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_lpr_list.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_lpr_list_upload.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_lpr_mapping.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_output.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_setting.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_radar.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_face.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_0.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_1.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_2.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_3.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_4.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_ptz.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_counter.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_stopwatch.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_tof.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/slider_handle.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/rotate.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/user_blue.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/snap_blue.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/combo_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/catalog.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/spinner_arrows_up.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/spinner_arrows_down.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/datebox_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_prevmonth.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_nextmonth.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_prevyear.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_nextyear.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/draw_arrow.js") == 0) || + (strcmp(urlBuffer, "/Aida/websocket.html") == 0) || + (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_65_ffffff_1x400.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_75_e6e6e6_1x400.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_75_dadada_1x400.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/gray_background.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-1-32X32.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-1-64X64.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-2-32X32.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-2-64X64.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-3-32X32.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-3-64X64.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/down_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/up_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/file.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/html.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/png.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/jpg.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/js.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/py.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/json.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/zip.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/bin.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/play.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/save.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/delete.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/uploadfile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/refreshfile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/deletefile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/addfile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/stop.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/clear.png") == 0) || + (strcmp(urlBuffer, "/Aida/") == 0) || + (strcmp(urlBuffer, "/Aida/favicon.ico") == 0) || + (strcmp(urlBuffer, "/favicon.ico") == 0) || + (strcmp(urlBuffer, "/Aida/fabric_jquery.easyui.min_compressed.js") == 0) || + (strcmp(urlBuffer, "/Aida/jqueryAll_compressed.js") == 0) || + (strcmp(urlBuffer, "/Aida/main.css") == 0) || + (strcmp(urlBuffer, "/Aida_data/logs.js") == 0) || + (strcmp(urlBuffer, "/Aida_data/db_fflpr.db") == 0) || + (strcmp(urlBuffer, "/Aida/alarm_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/ai_meta.html") == 0) || + //(strcmp(urlBuffer, "/Aida/ai_meta.js") == 0) ||//|W + (strcmp(urlBuffer, "/Aida/menu_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/jquery_3_2_1.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/fabric_jquery.easyui.min_compressed_on_nvr.js") == 0) || + (strcmp(urlBuffer, "/Aida/csvformat_help.html") == 0) || + (strncmp(urlBuffer, "/Aida/Icon/counter_icon/", 24) == 0) || + (strncmp(urlBuffer, "/Aida/labels/car_type/", 22) == 0) || + (strncmp(urlBuffer, "/Aida/labels/",13) == 0) || + (strcmp(urlBuffer, "/Aida/ruler/demo.js") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/ruler/ruler.js") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/ruler/ruler.min.js") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/ruler/ruler.min.css") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/pcl/pcl.html") == 0) || // add pcl .js + (strcmp(urlBuffer, "/Aida/pcl/test.html") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/OrbitControls.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/PCDLoader.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/three.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/TrackballControls.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/pcd/tof.pcd") == 0) || + (strcmp(urlBuffer, "/Aida/css/upload_img_demo.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/upload_img_style.css") == 0) || + (strcmp(urlBuffer, "/Aida/lilin.png") == 0) || + (strcmp(urlBuffer, "/Aida/normalize.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/cropper.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/cropper.min.js") == 0) + ) + { + + pthread_mutex_lock(&mutex_web); + + if (strcmp(urlBuffer, "/favicon.ico") == 0) { + strcpy(urlBuffer,"/Aida/favicon.ico"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data.js", 21) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_1.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_1.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_2.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_2.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_3.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_3.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_4.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_4.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_5.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_5.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_6.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_6.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_7.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_7.js"); + } + + //printf("\n[web process]start 9\n"); + + //printf("\nsock(%d):%s\n", cli_socket, urlBuffer); + char tmp_open_file[512]; + memset(tmp_open_file, 0, sizeof(tmp_open_file)); + + if (isGYNetReady == FALSE) + { + sprintf(tmp_open_file, "./Aida/wait.html"); + } + else if (g_IsPTZDevice == 0) + { + + if (strcmp(accountData[0].account_flip, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0 || + strcmp(accountData[0].account_rotate, "1") == 0) + { + sprintf(tmp_open_file, "./Aida/warning.html"); + } + else{ + sprintf(tmp_open_file, ".%s", urlBuffer); + } + } + else if (g_IsPTZDevice == 1) + { + + if (strcmp(accountData[0].account_rotate, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0) + { + sprintf(tmp_open_file, "./Aida/warning.html"); + } + else{ + sprintf(tmp_open_file, ".%s", urlBuffer); + } + } + + + /*//#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] http get tmp_open_file:%s\n", cli_socket,tmp_open_file); + //#endif //_DEBUG_AMBA*/ + + if ((strcmp(urlBuffer, "/Aida/cool_counter.html") != 0) || + (strcmp(urlBuffer, "/Aida/cool_counter.html") == 0 && (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) + ))) + { + int file_fd; + if ((file_fd = open(tmp_open_file, O_RDONLY)) == -1) + { + printf("Failed to open file : %s\n", tmp_open_file);//ɮצSQŪ + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19-2\n"); + } + else { + int iFileLength = 0; + char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; + iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); + close(file_fd); + + /* work out the file type and check if we support it */ + buflen = strlen(urlBuffer); + fstr = NULL; + for (idx = 0; extensions[idx].ext != 0; idx++) + { + len = strlen(extensions[idx].ext); + if (!strncmp(&urlBuffer[buflen - len], extensions[idx].ext, len)) + { + fstr = extensions[idx].filetype; + break; + } + } + + if (fstr == NULL) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19\n"); + } + else + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: %s;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n", fstr); /*\r\nCache - Control: max - age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #20\n"); + } + + int iSentLeft = 0; + int iSentLength = 0; + int iHaveSentLength = 0; + int iRetryCount = 5; + + + + iSentLeft = iFileLength; + + while (iSentLeft >= 1) { + iSentLength = send(cli_socket, sendBuffer_superlarge + iHaveSentLength, iSentLeft, MSG_MORE); + + if (iSentLength <= 0) + break; + + iHaveSentLength = iHaveSentLength + iSentLength; + iSentLeft = iSentLeft - iSentLength; + iRetryCount--; + + if (iSentLeft >= 1) { + //printf("\n[web process]iSentLeft: %d\n", iSentLeft); + } + + if (iRetryCount <= 0) + break; + //usSleep(100); + } + + + } + } + else if(strcmp(urlBuffer, "/Aida/cool_counter.html") == 0){ + strcpy(beforeSendBuffer, "The weight should support the counter function."); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + } + + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#if 1 + else if (strcmp(urlBuffer, "/getAidaInfo") == 0) + { + //printf("\n[web process]start 10\n"); + //Get MAC Address + char fetch_mac_addr[30] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + if (g_match_mac) + strcpy(fetch_mac_addr, g_mac_address); + else + { + GetMACAddress(fetch_mac_addr); + //printf("mac addr = %s \n", fetch_mac_addr); + int i = 0; + while (fetch_mac_addr[i] != '\0') + { + if (fetch_mac_addr[i] == '\n') + { + fetch_mac_addr[i] = '\0'; + break; + } + i++; + } + } + ///get config info + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { +#ifdef _DEBUG_AMBA + printf("read config.json.\n"); +#endif + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *config_root, *about_box, *unlock_key; + + config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (config_root) { + //printf("config.json parse OK.\n"); + about_box = cJSON_GetObjectItem(config_root, "about_box"); + //nic_name = cJSON_GetObjectItem(about_box, "NIC name"); + unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + + ///read config.json + + cJSON /**dataset_ver,*/ *root; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + /*jstr1 = cJSON_CreateString("json test1"); + jstr2 = cJSON_CreateString("json test2"); + jnum1 = cJSON_CreateNumber(4456);*/ + //sys_id = cJSON_CreateString(fetch_mac_addr); + //dataset_ver = cJSON_CreateString("1.0.0"); + //soft_ver = cJSON_CreateString("1.0.0"); + //dataset_ver = cJSON_GetObjectItem(about_box, "dataset version"); + //soft_ver = cJSON_GetObjectItem(about_box, "software version"); + /*license_type = cJSON_CreateString("licensed"); + license_status = cJSON_CreateString("test"); + license_des = cJSON_CreateString("test");*/ + + //printf("\n"); + //printf(unlock_key->valuestring); + //printf("\n"); +#ifdef GY_OS_AMBA + cJSON_AddItemToObject(root, "model_camera", cJSON_CreateNumber(get_g_PTZ_model())); +#else + cJSON_AddItemToObject(root, "model_camera", cJSON_CreateNumber(0)); +#endif + + cJSON_AddItemToObject(root, "unlock_key", cJSON_CreateString(unlock_key->valuestring)); + +#if 0 + char temp_key[512] = { 0 }; + char formatted_mac[30] = { 0 }; + if (strstr(unlock_key->valuestring, "face") != NULL) { + getContractSignature(temp_key, formatted_mac); + } +#endif + + cJSON_AddItemToObject(root, "sys_id", cJSON_CreateString(fetch_mac_addr)); + cJSON_AddItemToObject(root, "dataset_ver", cJSON_CreateString(Buffer_ver)); + char temp_soft_ver[50] = { 0 }; + strcat(temp_soft_ver, APP_VERSION); + strcat(temp_soft_ver, "-"); + strcat(temp_soft_ver, WeightFileModeName); + cJSON_AddItemToObject(root, "soft_ver", cJSON_CreateString(temp_soft_ver)); + cJSON_AddItemToObject(root, "license_type", cJSON_CreateString(http_strLicenseType)); + cJSON_AddItemToObject(root, "license_status", cJSON_CreateString(strLicenseStatus)); + +#ifdef GY_OS_V_SERIES + cJSON_AddItemToObject(root, "v_series", cJSON_CreateString("Yes")); +#else + cJSON_AddItemToObject(root, "v_series", cJSON_CreateString("No")); +#endif + + cJSON_AddItemToObject(root, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + + cJSON_AddItemToObject(root, "CheckIsExistingSpeed", cJSON_CreateNumber(CheckIsExistingSpeed)); + cJSON_AddItemToObject(root, "White_LED", cJSON_CreateNumber(g_camera_white_LED)); + cJSON_AddItemToObject(root, "No_brand", cJSON_CreateNumber(g_check_if_no_brand)); + cJSON_AddItemToObject(root, "sdk_version", cJSON_CreateNumber(g_sdk_version)); + + char licensePATH[1024] = { 0 }; + //strcpy(licensePATH, exePath); + strcpy(licensePATH, "/emmc/plugin/Aida/license.txt"); + + if (!FileExist(licensePATH)) + printf("%s doesn't exist.\n", licensePATH); + else + { + char* fileBuf = ReadAllBytes(licensePATH); + + if (fileBuf) { +#ifdef _DEBUG_AMBA + printf("licensePATH = %s \n", licensePATH); + printf("fileBuf = %s \n", fileBuf); +#endif + cJSON_AddItemToObject(root, "license_file_content", cJSON_CreateString(fileBuf)); + } + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + } + + JsonString = cJSON_PrintUnformatted(root); +#ifdef _DEBUG_AMBA + printf("return json str = %s \n", JsonString); +#endif + strcat(contentBuffer, JsonString); + + if (config_root) { + cJSON_Delete(config_root); + config_root = NULL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #21\n"); + + //send(cli_socket, JsonString, sizeof(JsonString), 0); + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(JsonString), JsonString); + //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + //{ + // printf("\nsend error\n"); + //} + //printf("get aida info \n"); + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getloading") == 0) //20201222 XCPUMGPU + { + /*if (!is_connection_authorized(recvBuffer, cli_socket, FALSE)) {} + else*/ { + //printf("\n[web process]start 11\n"); + char AI_fps_tojson[256] = { 0 }; + sprintf(AI_fps_tojson, "%d", AI_fps); + + char temp_CPU_usage[256] = { 0 }; + char temp_GPU_usage[256] = { 0 }; + char temp_AI_fps_tojson[256] = { 0 }; + + strcpy(temp_CPU_usage, CPU_usage); + strcpy(temp_GPU_usage, GPU_usage); + strcpy(temp_AI_fps_tojson, AI_fps_tojson); + + //get_loading(); + if (g_i_get_cpu_loading == 0) + { + g_i_get_cpu_loading = 1; + +#ifdef GY_OS_AMBA + pthread_t thread_id_getloading; + if (pthread_create(&thread_id_getloading, 0, get_loading, NULL)) + printf("\ngetloading thread creation failed\n"); +#endif + } + + //printf("getloading\n"); + + char convert_tojson1[256] = "{\"CPU_USAGE\":"; + char convert_tojson2[256] = ",\"GPU_USAGE\":"; + char convert_tojson3[256] = ",\"FPS\":"; + char convert_tojson4[256] = "}"; + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, temp_CPU_usage); + strcat(contentBuffer, convert_tojson2); + strcat(contentBuffer, temp_GPU_usage); + strcat(contentBuffer, convert_tojson3); + strcat(contentBuffer, temp_AI_fps_tojson); + strcat(contentBuffer, convert_tojson4); + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + } + //printf("\ngetloading \n"); + //if (pPipe != NULL) + // vpclose(pPipe); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getplayback_list") == 0) //20201222 XCPUMGPU + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[BUFSIZE_V2] = { 0 }; + + + pthread_mutex_lock(&mutex_heatmap_jpeg); + DIR *d_file; + struct dirent *dir_file; + d_file = opendir("/emmc/plugin/Aida_data/playback"); + if (d_file) { + while ((dir_file = readdir(d_file)) != NULL) { + if (strlen(dir_file->d_name) >= 17) { + strcat(Msg, dir_file->d_name); + strcat(Msg, ","); + } + } + closedir(d_file); + } + pthread_mutex_unlock(&mutex_heatmap_jpeg); + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/control?alarm.gpio=",20) == 0) //20201222 XCPUMGPU + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + char c_alarm_gpio[256] = { 0 }; + memset(c_alarm_gpio, 0x00, sizeof(c_alarm_gpio)); + strcpy(c_alarm_gpio, urlBuffer + 20); + + char Msg[256] = { 0 }; + if (strlen(c_alarm_gpio) == 1 && isdigit(c_alarm_gpio[0])) { + g_control_alarm_gpio = atoi(c_alarm_gpio); + sprintf(Msg, "%d", g_control_alarm_gpio); + } + else { + strcpy(Msg,"Fail."); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2299\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/run_osd_server") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); +#ifdef GY_OS_AMBA + //OSD server إ + pthread_t thread_id_osd; + if (pthread_create(&thread_id_osd, 0, run_osd_server_thread, NULL)) { + printf("\nrun osd server thread creation failed #22\n"); + } +#endif + strcpy(beforeSendBuffer, ""); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/getcheck_current_resolution") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", g_check_current_resolution); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2233\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getcountpost") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", get_g_counter_index_post()); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getcountlong") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", get_g_counter_index_long()); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #253\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getptztest") == 0) //20201222 XCPUMGPU + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "g_ori_yuv_height:%d,g_ori_yuv_width:%d,g_framesize_height:%d,g_framesize_width:%d", + g_ori_yuv_height, g_ori_yuv_width, g_framesize_height, g_framesize_width); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getfree") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg,"%d", get_free_mem_data()); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/setcamera",10) == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[512] = { 0 }; + sprintf(Msg, "%s", urlBuffer + 10); + printf("\n--------[setcamera]:%s\n", Msg); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2552\n"); + + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/exit_gynet") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + char Msg[256] = { 0 }; + sprintf(Msg, "%d", g_change_getnetwork_buffer_id); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + + if (g_change_getnetwork_buffer_id == 1) { + usSleep(2000000); +#ifdef GY_OS_AMBA + printf("\n-----------------------get network buffer id# 2: exit-----------------------\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); + write_to_logs_html(temp_msg, "exit gynet", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "exit gynet", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } +#endif + } + } +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/get_cur_pos") == 0) //20201222 XCPUMGPU + { + //UpdatePTZCurPos(); + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[512] = { 0 }; + sprintf(Msg, "{\"pan\":\"%d\",\"tilt\":\"%d\",\"zoom\":\"%d\"}", g_stPTZ_Handle.iPanABS, g_stPTZ_Handle.iTiltABS, g_stPTZ_Handle.iZoomABS); + //strcpy(Msg,"hello"); + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2882\n"); + + closesocket(cli_socket); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/clean_face_list") == 0) //20201222 XCPUMGPU + { + start_to_import_file = 0; + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%s", "OK"); + + { + //MŶ¥զWƮw + char urlBuffer_4[256] = "/set_search_info?clean=watch"; + char urlBuffer_5[256] = "/set_search_info?clean=vip"; + char urlBuffer_6[256] = "/set_search_info?clean=log"; + char urlBuffer_7[256] = "/set_search_info?clean=visitor"; + char urlBuffer_8[256] = "/set_search_info?clean=mapping"; + + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_6, strlen(urlBuffer_6)); + firstBuffer[strlen(urlBuffer_6)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_7, strlen(urlBuffer_7)); + firstBuffer[strlen(urlBuffer_7)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_8, strlen(urlBuffer_8)); + firstBuffer[strlen(urlBuffer_8)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2fff2\n"); + + closesocket(cli_socket); + } + +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + else if (strcmp(urlBuffer, "/clean_lpr_list") == 0) //20201222 XCPUMGPU + { + start_to_import_file = 0; + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%s", "OK"); + + { + //MŶ¥զWƮw + char urlBuffer_4[256] = "/set_search_info?clean=black"; + char urlBuffer_5[256] = "/set_search_info?clean=white"; + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2fff2\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_pause_time") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + char MSG[50] = { 0 }; + sprintf(MSG,"%ld", g_image_HD_pasue_time); + strcpy(beforeSendBuffer, MSG); + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_play_video") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + if (g_video_start_HD == 1) { + strcpy(beforeSendBuffer, "Yes"); + } + else { + strcpy(beforeSendBuffer, "No"); + } + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/play_video") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + if (g_video_start_HD == 0) { + g_video_start_HD = 1; + strcpy(beforeSendBuffer, "Yes"); + } + else { + g_video_start_HD = 0; + strcpy(beforeSendBuffer, "No"); + } + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_framesize_HD") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "{\"width_HD\":\"%d\",\"height_HD\":\"%d\"}", g_framesize_width_HD, g_framesize_height_HD); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strcmp(urlBuffer, "/reset_counter") == 0) + { + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + reset_onvif(); + + pthread_mutex_unlock(&mutex_reset_counter); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2212\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/resetcounting?counter_id=",26) == 0) + { + char c_counting_index[256] = { 0 }; + memset(c_counting_index, 0x00, sizeof(c_counting_index)); + strcpy(c_counting_index, urlBuffer + 26); + + int index_counting = -1; + if (strlen(c_counting_index) >= 1) { + if (strcmp(c_counting_index, "1") == 0) { + index_counting = 0; + } + else if (strcmp(c_counting_index, "2") == 0) { + index_counting = 1; + } + else if (strcmp(c_counting_index, "3") == 0) { + index_counting = 2; + } + else if (strcmp(c_counting_index, "4") == 0) { + index_counting = 3; + } + else if (strcmp(c_counting_index, "5") == 0) { + index_counting = 4; + } + else if (strcmp(c_counting_index, "6") == 0) { + index_counting = 5; + } + else if (strcmp(c_counting_index, "7") == 0) { + index_counting = 6; + } + else if (strcmp(c_counting_index, "8") == 0) { + index_counting = 7; + } + } + + if (index_counting >= 0) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + reset_counter(index_counting, now_time); + reset_certain_counter_onvif(index_counting); + pthread_mutex_unlock(&mutex_reset_counter); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2312\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/getcounting?counter_id=", 24) == 0) + { + char c_counting_index[256] = { 0 }; + memset(c_counting_index, 0x00, sizeof(c_counting_index)); + strcpy(c_counting_index, urlBuffer + 24); + + int index_counting = -1; + if (strlen(c_counting_index) >= 1) { + if (strcmp(c_counting_index, "1") == 0) { + index_counting = 0; + } + else if (strcmp(c_counting_index, "2") == 0) { + index_counting = 1; + } + else if (strcmp(c_counting_index, "3") == 0) { + index_counting = 2; + } + else if (strcmp(c_counting_index, "4") == 0) { + index_counting = 3; + } + else if (strcmp(c_counting_index, "5") == 0) { + index_counting = 4; + } + else if (strcmp(c_counting_index, "6") == 0) { + index_counting = 5; + } + else if (strcmp(c_counting_index, "7") == 0) { + index_counting = 6; + } + else if (strcmp(c_counting_index, "8") == 0) { + index_counting = 7; + } + } + + if (index_counting >= 0) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + sprintf(beforeSendBuffer,"%d", eventCounterList[index_counting].counter_count); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2312\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strcmp(urlBuffer, "/get_counter") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + char temp_count[256] = { 0 }; + char temp_buf[256] = { 0 }; + for (int index_j = 0; index_j < MAX_EVENT_COUNTERS; index_j++) + { + sprintf(temp_count, "%d", eventCounterList[index_j].counter_count); + strcat(temp_buf, temp_count); + if(index_j < MAX_EVENT_COUNTERS - 1) + strcat(temp_buf, ","); + } + strcpy(beforeSendBuffer, temp_buf); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2312\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strcmp(urlBuffer, "/get_counter_cust_name") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + char temp_count[1024] = { 0 }; + char temp_buf[1024] = { 0 }; + for (int index_j = 0; index_j < MAX_EVENT_COUNTERS; index_j++) + { + sprintf(temp_count, "%s", eventCounterList[index_j].counter_cust_name); + strcat(temp_buf, temp_count); + if (index_j < MAX_EVENT_COUNTERS - 1) + strcat(temp_buf, ","); + } + strcpy(beforeSendBuffer, temp_buf); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2382\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_check_if_illegal_id_or_pass") == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + int check_if_illegal_id_or_pass = 0; + /* + if (strstr(accountData[0].account_username, "?") != NULL || + strstr(accountData[0].account_username, ":") != NULL || + strstr(accountData[0].account_username, "/") != NULL || + strstr(accountData[0].account_username, " ") != NULL || + strstr(accountData[0].account_username, "@") != NULL || + strstr(accountData[0].account_username, "#") != NULL || + strstr(accountData[0].account_password, "?") != NULL || + strstr(accountData[0].account_password, ":") != NULL || + strstr(accountData[0].account_password, "/") != NULL || + strstr(accountData[0].account_password, " ") != NULL || + strstr(accountData[0].account_password, "@") != NULL || + strstr(accountData[0].account_password, "#") != NULL) { + check_if_illegal_id_or_pass = 1; + }*/ + + char Msg[256] = { 0 }; + sprintf(Msg, "%d", check_if_illegal_id_or_pass); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/getbar") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; +#ifdef GY_OS_AMBA + if (get_g_check_if_differ_image_is_running() == 1) { + sprintf(Msg, "%d", get_g_progress_bar()); + } + else { + sprintf(Msg, "%d", -1); + } +#else + sprintf(Msg, "%d",-1); +#endif + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #213\n"); + + closesocket(cli_socket); + } +#if 1 + else if (strncmp(urlBuffer, "/do_a_test_to_post&index=",25) == 0) + { + //printf("\n[do a test to post]return contentBuffer = %s \n", contentBuffer); + long int last_do_a_test, now_do_a_test; + struct timeval currtime_do_a_test; + gettimeofday(&currtime_do_a_test, NULL); + last_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); + + char index_post[50] = { 0 }; + strcpy(index_post, urlBuffer + 25); + + int index_j = atoi(index_post); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + char *replacement_t = NULL; + + replacement_t = StrReplace(postEventList[index_j].post_content, "<|snap_image|>", g_current_snapshot_addr_base64); + strcpy(q_info.content, replacement_t); + + if (replacement_t != NULL) { + free(replacement_t); + replacement_t = NULL; + } + + q_info.content_size = strlen(q_info.content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + + pthread_mutex_lock(&mutex_set_http_request); + struct timeval currtime_set_http_request; + gettimeofday(&currtime_set_http_request, NULL); + long current_ms_set_http_request = (currtime_set_http_request.tv_sec * 1000) + (currtime_set_http_request.tv_usec / 1000); + long last_ms_set_http_request = current_ms_set_http_request; + + int check_if_time_is_too_long = 0; + + g_response_post_OK = 0; +#ifdef GY_OS_NOVA + + if (strcmp(q_info.host_name, "127.0.0.1") != 0 && strcmp(q_info.host_name, "localhost") != 0) { + SetHttpRequest(&q_info, sendBuffer, q_info.post_method); + } + else { + SetHttpRequest_sock(&q_info, sendBuffer, q_info.post_method); + } +#endif +#ifdef GY_OS_AMBA + SetHttpRequest(&q_info, sendBuffer, q_info.post_method); +#endif + while (g_response_post_OK == 0) { + if (current_ms_set_http_request > last_ms_set_http_request + 10000) { + check_if_time_is_too_long = 1; + break; + } + + gettimeofday(&currtime_set_http_request, NULL); + current_ms_set_http_request = (currtime_set_http_request.tv_sec * 1000) + (currtime_set_http_request.tv_usec / 1000); + usSleep(1000); + } + + gettimeofday(&currtime_do_a_test, NULL); + now_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); //쬰@ + + if (check_if_time_is_too_long == 0) { + //strcpy(beforeSendBuffer, g_response_net_curl); + sprintf(beforeSendBuffer,"%s, Time:%ld ms, Size:%ld Bytes", g_response_net_curl, (now_do_a_test- last_do_a_test), (long int)q_info.content_size); + } + else { + //strcpy(beforeSendBuffer, "The Post time is too long (> 10 secs). We cannot continue to wait it."); + sprintf(beforeSendBuffer,"%s, Time:%ld ms, Size:%ld Bytes", "The Post time is too long (> 10 secs). We cannot continue to wait it.", (now_do_a_test - last_do_a_test), (long int)q_info.content_size); + } + g_response_post_OK = 0; + pthread_mutex_unlock(&mutex_set_http_request); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2122\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/do_a_snmp_to_post&index=", 25) == 0) + { + //printf("\n[do a test to post]return contentBuffer = %s \n", contentBuffer); + char index_post[50] = { 0 }; + strcpy(index_post, urlBuffer + 25); + + int index_j = atoi(index_post); + + if (SNMPManagementList[index_j].check_if_delivering == 0) { + SNMPManagementList[index_j].check_if_delivering = 1; + + static long last_do_a_test, now_do_a_test; + struct timeval currtime_do_a_test; + gettimeofday(&currtime_do_a_test, NULL); + last_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); + + QueueInfo q_info = { 0 }; + strcpy(q_info.snmp_event_name, SNMPManagementList[index_j].snmp_event_name); + strcpy(q_info.snmp_version, SNMPManagementList[index_j].snmp_version); + strcpy(q_info.snmp_group_name, SNMPManagementList[index_j].snmp_group_name); + strcpy(q_info.snmp_host_ip, SNMPManagementList[index_j].snmp_host_ip); + strcpy(q_info.snmp_host_port, SNMPManagementList[index_j].snmp_host_port); + strcpy(q_info.snmp_oid, SNMPManagementList[index_j].snmp_oid); + strcpy(q_info.snmp_value, SNMPManagementList[index_j].snmp_value); + strcpy(q_info.snmp_type, SNMPManagementList[index_j].snmp_type); + + SetSNMPRequest(&q_info); + + gettimeofday(&currtime_do_a_test, NULL); + now_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); //쬰@ + + { + //strcpy(beforeSendBuffer, g_response_net_curl); + sprintf(beforeSendBuffer, "%s, Time:%ld ms", g_response_snmp, now_do_a_test - last_do_a_test); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #21122\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/getdebugplate") == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + pthread_mutex_lock(&mutex_run_one_net); + strcpy(beforeSendBuffer, g_debug_plate); + pthread_mutex_unlock(&mutex_run_one_net); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } + +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + else if (strcmp(urlBuffer, "/get_g_count_lpr_insert_times") == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", g_count_lpr_insert_times); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22232\n"); + + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/getplugin") == 0) //get aida port + { + //printf("\n[web process]start 11-2\n"); + char filename[1024] = { 0 }; + strcat(filename,"/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else{ + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + + char* JsonString = NULL; + JsonString = cJSON_PrintUnformatted(plugin); + strcat(contentBuffer, JsonString); + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #21-2\n"); + + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/set_no_brand") == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + int check_if_set_no_brand = 0; + /* + char Cmd[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + 16); + int check_if_not_digit = 0; + for (int i = 0; i < strlen(Cmd); i++) + { + if (!isdigit(Cmd[i])) + { + check_if_not_digit = 1; + break; + } + }*/ + //if (check_if_not_digit == 0) + { + //printf("\nKKKK: Cmd: %s\n",Cmd); + /*int port_number = atoi(Cmd); + if (port_number < 0 && port_number > 65535) { + if (strlen(accountData[0].account_aida_port) >= 1) + port_number = atoi(accountData[0].account_aida_port); + } + //printf("\nKKKKKKKKK: port_number: %d\n",port_number); + char port_number_char[256] = { 0 }; + sprintf(port_number_char, "%d", port_number);*/ + + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + char temp_version[256] = { 0 }; + sprintf(temp_version,"%s-%s", APP_VERSION, WeightFileModeName); + + cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString("Camera Plug-in")); + cJSON_ReplaceItemInObject(plugin, "homepage", cJSON_CreateString("")); + cJSON_ReplaceItemInObject(plugin, "author", cJSON_CreateString("")); + cJSON_ReplaceItemInObject(plugin, "version", cJSON_CreateString(temp_version)); + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + strcpy(Cmd,JsonString); + check_if_set_no_brand = 1; + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + + if (strlen(Cmd) >= 1) { + strcpy(beforeSendBuffer, Cmd); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252-3\n"); + + closesocket(cli_socket); + + if (check_if_set_no_brand == 1) { + printf("\n[--------Set no brand successfully-------]: We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand.\n"); + usSleep(1000); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand."); + write_to_logs_html(temp_msg, "set no brand", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "set no brand", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + else if (strcmp(urlBuffer, "/set_lilin") == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + int check_if_set_lilin = 0; + /* + char Cmd[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + 16); + int check_if_not_digit = 0; + for (int i = 0; i < strlen(Cmd); i++) + { + if (!isdigit(Cmd[i])) + { + check_if_not_digit = 1; + break; + } + }*/ + //if (check_if_not_digit == 0) + { + //printf("\nKKKK: Cmd: %s\n",Cmd); + /*int port_number = atoi(Cmd); + if (port_number < 0 && port_number > 65535) { + if (strlen(accountData[0].account_aida_port) >= 1) + port_number = atoi(accountData[0].account_aida_port); + } + //printf("\nKKKKKKKKK: port_number: %d\n",port_number); + char port_number_char[256] = { 0 }; + sprintf(port_number_char, "%d", port_number);*/ + + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + char temp_version[256] = { 0 }; + sprintf(temp_version, "%s-%s", APP_VERSION, WeightFileModeName); + + cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString("LILIN Aida Camera Plug-in")); + cJSON_ReplaceItemInObject(plugin, "homepage", cJSON_CreateString("http://www.meritlilin.com")); + cJSON_ReplaceItemInObject(plugin, "author", cJSON_CreateString("LILIN <fae@meritlilin.com.tw>")); + cJSON_ReplaceItemInObject(plugin, "version", cJSON_CreateString(temp_version)); + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + strcpy(Cmd, JsonString); + check_if_set_lilin = 1; + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + + if (strlen(Cmd) >= 1) { + strcpy(beforeSendBuffer, Cmd); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252-32\n"); + + closesocket(cli_socket); + + if (check_if_set_lilin == 1) { + printf("\n[--------Set lilin successfully-------]: We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand.\n"); + usSleep(1000); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand."); + write_to_logs_html(temp_msg, "set lilin", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "set lilin", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + else if (strncmp(urlBuffer, "/setplugin?port=",16) == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + 16); + int check_if_not_digit = 0; + for (int i = 0; i < strlen(Cmd); i++) + { + if (!isdigit(Cmd[i])) + { + check_if_not_digit = 1; + break; + } + } + if (check_if_not_digit == 0) + { + //printf("\nKKKK: Cmd: %s\n",Cmd); + int port_number = atoi(Cmd); + if (port_number < 0 && port_number > 65535) { + if(strlen(accountData[0].account_aida_port)>=1) + port_number = atoi(accountData[0].account_aida_port); + } + //printf("\nKKKKKKKKK: port_number: %d\n",port_number); + char port_number_char[256] = { 0 }; + sprintf(port_number_char, "%d", port_number); + + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char newline_char[BUFFER_SIZE] = { 0 }; + strcpy(newline_char, "/emmc/plugin/Aida_data/mon -s 2 \"/emmc/plugin/Aida_data/gynet server -http_port "); + strcat(newline_char, port_number_char); + strcat(newline_char, "\" &\n"); + + //printf("%s",newline_char); + + replace_one_line_in_a_file("/emmc/plugin/Aida_data/aiengine", 31, newline_char); + FILE * pPipe2; + char cmd2[256] = { 0 }; + strcpy(cmd2, "chmod 777 /emmc/plugin/Aida_data/aiengine"); + pPipe2 = vpopen(cmd2, "r"); + if (pPipe2 != NULL) + vpclose(pPipe2); + + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + cJSON_ReplaceItemInObject(plugin, "port", cJSON_CreateString(port_number_char)); + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22-3\n"); + + closesocket(cli_socket); + + if (check_if_not_digit == 0) { + printf("\n[--------Set aida port successfully-------]: We will close gynet.exe with the old port. Please restart gynet.exe with the new port.\n"); + usSleep(1000); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the old port. Please restart gynet.exe with the new port."); + write_to_logs_html(temp_msg, "set new port", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "set new port", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + else if (strncmp(urlBuffer, "/setplugin?desc=", 16) == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + strcpy(Cmd, urlBuffer + 16); + + char name_char[8192*4] = { 0 }; + sprintf(name_char, "%s", Cmd); + + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + //cJSON_ReplaceItemInObject(plugin, "name", cJSON_CreateString(name_char)); //LILIN Aida Camera Plug-in + cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString(name_char)); //LILIN Aida Camera Plug-in + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22-33\n"); + + closesocket(cli_socket); + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + else if (strcmp(urlBuffer, "/getipcamsettings") == 0) //get current ipcam settings + { + //printf("\n[web process]start 13\n"); + //printf("getipcamport\n"); + + char convert_tojson1[256] = "{\"IPCAM_PORT\":\""; + /*char convert_tojson2[256] = "\","; + char convert_tojson3[256] = "\"IPCAM_MIRROR\":\""; + char convert_tojson4[256] = "\","; + char convert_tojson5[256] = "\"IPCAM_FLIP\":\""; + char convert_tojson6[256] = "\","; + char convert_tojson7[256] = "\"IPCAM_ROTATE\":\"";*/ + char convert_tojson8[256] = "\"}"; + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, g_account_port_protected); + /* + strcat(contentBuffer, convert_tojson2); + + strcat(contentBuffer, convert_tojson3); + strcat(contentBuffer, accountData[0].account_mirror); + strcat(contentBuffer, convert_tojson4); + + strcat(contentBuffer, convert_tojson5); + strcat(contentBuffer, accountData[0].account_flip); + strcat(contentBuffer, convert_tojson6); + + strcat(contentBuffer, convert_tojson7); + strcat(contentBuffer, accountData[0].account_rotate);*/ + strcat(contentBuffer, convert_tojson8); + + //printf("\n[getipcamport]return contentBuffer = %s \n", contentBuffer); + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #23\n"); + + //printf("\ngetipcamport \n"); + + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/sync_service") == 0) //get current ipcam settings + { + copy_ipcam_smtp_service_to_gynet(); + + strcpy(beforeSendBuffer, ""); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2355\n"); + + //printf("\ngetipcamport \n"); + + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/service?get=all") == 0) //get current ipcam settings + { + //printf("\n[web process]start 13\n"); + //printf("getipcamport\n"); + + char convert_tojson1[256] = "{\"EMAIL_ADDRESS1\":\""; + char convert_tojson2[256] = "\","; + char convert_tojson3[256] = "\"EMAIL_ADDRESS2\":\""; + char convert_tojson4[256] = "\","; + char convert_tojson5[256] = "\"EMAIL_ADDRESS3\":\""; + char convert_tojson6[256] = "\","; + char convert_tojson7[256] = "\"EMAIL_ADDRESS4\":\""; + char convert_tojson8[256] = "\","; + char convert_tojson9[256] = "\"EMAIL_ADDRESS5\":\""; + char convert_tojson10[256] = "\","; + char convert_tojson11[256] = "\"EMAIL_ADDRESS\":\""; + char convert_tojson12[256] = "\","; + char convert_tojson13[256] = "\"SMTP_SERVER\":\""; + char convert_tojson14[256] = "\","; + char convert_tojson15[256] = "\"SMTP_AUTH_MODE\":"; + char convert_tojson16[256] = ","; + char convert_tojson17[256] = "\"SMTP_PORT\":\""; + char convert_tojson18[256] = "\","; + char convert_tojson19[256] = "\"SMTP_AUTH\":"; + char convert_tojson20[256] = ","; + char convert_tojson21[256] = "\"AUTH_ACCOUNT\":\""; + char convert_tojson22[256] = "\"}"; + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, IPCAMService.email_address1); + strcat(contentBuffer, convert_tojson2); + + strcat(contentBuffer, convert_tojson3); + strcat(contentBuffer, IPCAMService.email_address2); + strcat(contentBuffer, convert_tojson4); + + strcat(contentBuffer, convert_tojson5); + strcat(contentBuffer, IPCAMService.email_address3); + strcat(contentBuffer, convert_tojson6); + + strcat(contentBuffer, convert_tojson7); + strcat(contentBuffer, IPCAMService.email_address4); + strcat(contentBuffer, convert_tojson8); + + strcat(contentBuffer, convert_tojson9); + strcat(contentBuffer, IPCAMService.email_address5); + strcat(contentBuffer, convert_tojson10); + + strcat(contentBuffer, convert_tojson11); + strcat(contentBuffer, IPCAMService.email_address); + strcat(contentBuffer, convert_tojson12); + + strcat(contentBuffer, convert_tojson13); + strcat(contentBuffer, IPCAMService.smtp_server); + strcat(contentBuffer, convert_tojson14); + + strcat(contentBuffer, convert_tojson15); + char temp_smtp_auth_mode[10] = { 0 }; + sprintf(temp_smtp_auth_mode,"%d", IPCAMService.smtp_auth_mode); + strcat(contentBuffer, temp_smtp_auth_mode); + strcat(contentBuffer, convert_tojson16); + + strcat(contentBuffer, convert_tojson17); + strcat(contentBuffer, IPCAMService.smtp_port); + strcat(contentBuffer, convert_tojson18); + + strcat(contentBuffer, convert_tojson19); + char temp_smtp_auth[10] = { 0 }; + sprintf(temp_smtp_auth, "%d", IPCAMService.smtp_auth); + strcat(contentBuffer, temp_smtp_auth); + strcat(contentBuffer, convert_tojson20); + + strcat(contentBuffer, convert_tojson21); + strcat(contentBuffer, IPCAMService.auth_account); + strcat(contentBuffer, convert_tojson22); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2333\n"); + + //printf("\ngetipcamport \n"); + + closesocket(cli_socket); + } +#if 0 + else if (strcmp(urlBuffer, "/set_bypass_login_on") == 0 || strcmp(urlBuffer, "/set_bypass_login_off") == 0) + { + /*printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nenable_base64: %d\n", enable_base64); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + //printf("set_bypass_login\n"); + char convert_tojson1[256] = "{\"BYPASS_LOGIN\":\""; + char convert_tojson2[256] = "\"}"; + char bypass_login_on[256] = "on"; + char bypass_login_off[256] = "off"; + + strcat(contentBuffer, convert_tojson1); + + if (strcmp(urlBuffer, "/set_bypass_login_on") == 0) + { + enable_base64 = 0; + strcat(contentBuffer, bypass_login_on); + } + else if (strcmp(urlBuffer, "/set_bypass_login_off") == 0) + { + enable_base64 = 1; + strcat(contentBuffer, bypass_login_off); + } + + strcat(contentBuffer, convert_tojson2); + //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24\n"); + + //printf("\nset_bypass_login \n"); + + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/register_session_id?id=", 24) == 0) + { + + + char c_session_id[MAX_SESSION_ID] = { 0 }; + memset(c_session_id, 0x00, sizeof(c_session_id)); + strcpy(c_session_id, urlBuffer + 24); + //printf("\n-----------register session_id:%s\n", c_session_id); + + if (strlen(c_session_id) >= 1) { + for (int i = 0; i < MAX_NUMBER_SESSION; i++) { + if (strlen(g_record_session_id[i]) == 0) { + strcpy(g_record_session_id[i], c_session_id); + break; + } + else if (strcmp(g_record_session_id[i], c_session_id)==0) { + break; + } + else if (i == MAX_NUMBER_SESSION-1) { + for (int j = 0; j < MAX_NUMBER_DELETED_SESSION; j++) { + memset(g_record_session_id[j], 0x00, sizeof(g_record_session_id[j])); + } + for (int j = 0; j < MAX_NUMBER_SESSION- MAX_NUMBER_DELETED_SESSION; j++) { + strcpy(g_record_session_id[j], g_record_session_id[j+ MAX_NUMBER_DELETED_SESSION]); + memset(g_record_session_id[j + MAX_NUMBER_DELETED_SESSION], 0x00, sizeof(g_record_session_id[j + MAX_NUMBER_DELETED_SESSION])); + } + } + } + } + + /* + for (int i = 0; i < MAX_NUMBER_SESSION; i++) { + printf("\n(%d)----session id:%s\n",i, g_record_session_id[i]); + }*/ + + strcpy(contentBuffer," "); + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #231\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/login_session_id?id=", 21) == 0) + { + char c_session_id[MAX_SESSION_ID] = { 0 }; + memset(c_session_id, 0x00, sizeof(c_session_id)); + strcpy(c_session_id, urlBuffer + 21); + //printf("\n-----------login session_id:%s\n", c_session_id); + + if (strlen(c_session_id) >= 1) { + int check_existing_session = 0; + for (int i = 0; i < MAX_NUMBER_SESSION; i++) { + if (strcmp(g_record_session_id[i], c_session_id) == 0) { + check_existing_session = 1; + break; + } + } + if (check_existing_session == 1) { + strcpy(contentBuffer, "Yes"); + } + else { + strcpy(contentBuffer, "No"); + } + } + else { + strcpy(contentBuffer, "No"); + } + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #232\n"); + + closesocket(cli_socket); + } +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/setmetadata?", 13) == 0) { + + int check_if_radar_open = 0; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + if (strncmp(viewDetectionZone[0][index_zone].enable_speed, "Yes", strlen("Yes")) == 0 /*&& + strncmp(viewDetectionZone[0][index_zone].enable_radar_speed, "Yes", strlen("Yes")) == 0*/) { + check_if_radar_open = 1; + break; + } + } + + if (check_if_radar_open == 1) { + + char Cmd[8192] = { 0 }; + strcpy(Cmd, urlBuffer + 13); + char msg[256] = { 0 }; + + if (strlen(Cmd) >= 1) { + const char *del = "&"; + char a_data_sp[MAX_SIZE_A_SP_OBJECT][STRSPLIT_SIZE]={0}; + int a_data_sp_num = 0; + + const char *del2 = "="; + char a_data_sp_pair[MAX_SIZE_A_SP_OBJECT][2][STRSPLIT_SIZE]={0}; + + float speed_sp = -1.0; //1 + char unit_sp[256] = { 0 }; //2 + float res_width_sp = -1.0; //3 + float res_height_sp = -1.0;; //4 + float x_sp = -1.0; //5 + float y_sp = -1.0; //6 + + a_data_sp_num = StrSplit(Cmd, a_data_sp, del); + //printf("\n------UU:24\n"); + if (a_data_sp_num == MAX_SIZE_A_SP_OBJECT) + { + for (int i = 0; i < a_data_sp_num; i++) + { + if (a_data_sp[i]) + { + //printf("\n%s\n", a_data_osd[i]); + StrSplit(a_data_sp[i], a_data_sp_pair[i], del2); + //printf("\n------UU:25\n"); + if (strlen(a_data_sp_pair[i][0]) >= 1 && strlen(a_data_sp_pair[i][1]) >= 1) { + + if (strcmp(a_data_sp_pair[i][0], "speed") == 0 || + strcmp(a_data_sp_pair[i][0], "Speed") == 0) { + speed_sp = atof(a_data_sp_pair[i][1]); + } + if (strcmp(a_data_sp_pair[i][0], "speed_unit") == 0 || + strcmp(a_data_sp_pair[i][0], "Speed_unit") == 0) { + strcpy(unit_sp, a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "res_width") == 0 || + strcmp(a_data_sp_pair[i][0], "res_width") == 0) { + res_width_sp = atof(a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "res_height") == 0 || + strcmp(a_data_sp_pair[i][0], "res_height") == 0) { + res_height_sp = atof(a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "x") == 0 || + strcmp(a_data_sp_pair[i][0], "X") == 0) { + x_sp = atof(a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "y") == 0 || + strcmp(a_data_sp_pair[i][0], "Y") == 0) { + y_sp = atof(a_data_sp_pair[i][1]); + } + } + } + } + } + + int check_if_sp_ok = 1; + + if (speed_sp == -1.0 || strlen(unit_sp) == 0 || res_width_sp == -1.0 || res_height_sp == -1.0 || x_sp == -1.0 || y_sp == -1.0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: Parameter"); + } + else if (speed_sp < 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: speed < 0"); + } + else if (strcmp(unit_sp, "KPH") != 0 && strcmp(unit_sp, "MPH") != 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: speed_unit should be KPH or MPH"); + } + else if (res_width_sp <= 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: res_width <= 0"); + } + else if (res_height_sp <= 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: res_height <= 0"); + } + else if (x_sp <= 0 || x_sp >= res_width_sp) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: x <= 0 || x >= res_width"); + } + else if (y_sp <= 0 || y_sp >= res_height_sp) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: y <= 0 || y >= res_height"); + } + + if (check_if_sp_ok == 1) { + //printf("\n---------%f,%s,%f,%f,%f,%f\n", speed_sp, unit_sp, res_width_sp, res_height_sp, x_sp, y_sp); + for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { + if (SpeedData[i].flag_protected == 0) { + SpeedData[i].speed = speed_sp; + strcpy(SpeedData[i].speed_unit, unit_sp); + SpeedData[i].res_width = res_width_sp; + SpeedData[i].res_height = res_height_sp; + SpeedData[i].x = x_sp; + SpeedData[i].y = y_sp; + SpeedData[i].flag_protected = 1; + } + } + strcpy(msg, "HTTP 200 OK, content: OK"); + } + } + + if (strlen(msg) == 0) { + strcpy(msg, "HTTP 200 OK, content: Error: Format"); + } + } + else { + strcpy(msg, "HTTP 200 OK, content: Error: Please enable speed"); + } + + strcpy(beforeSendBuffer_xtra, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snaphd?index=", 14) == 0) { + pthread_mutex_lock(&mutex_web); + + char snap_hd_index[50] = { 0 }; + memset(snap_hd_index, 0x00, sizeof(snap_hd_index)); + strcpy(snap_hd_index, urlBuffer + 14); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199922\n"); + + int current_hd_index = atoi(snap_hd_index); + + if (current_hd_index >= 0 && current_hd_index < MAX_SNAP_HD_LIST && + snapHDList[current_hd_index].snapshot_size >= 1) + { + if (send(cli_socket, snapHDList[current_hd_index].snapshot_addr, snapHDList[current_hd_index].snapshot_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999991\n"); + } + + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snaphd?time=", 13) == 0) { + pthread_mutex_lock(&mutex_web); + + char c_snap_hd_time[50] = { 0 }; + memset(c_snap_hd_time, 0x00, sizeof(c_snap_hd_time)); + strcpy(c_snap_hd_time, urlBuffer + 13); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199922\n"); + + if (strlen(c_snap_hd_time) == 13) { + char c_msec[10] = { 0 }; + c_msec[0] = c_snap_hd_time[10]; + c_msec[1] = c_snap_hd_time[11]; + c_msec[2] = c_snap_hd_time[12]; + c_msec[3] = '\0'; + c_snap_hd_time[10] = '\0'; + c_snap_hd_time[11] = '\0'; + c_snap_hd_time[12] = '\0'; + + time_t snap_hd_time = (time_t)atoll(c_snap_hd_time); + time_t snap_hd_msec = (time_t)atoll(c_msec); + time_t snap_hd_combine_time = snap_hd_time * 1000 + snap_hd_msec; + +#if 0 + printf("\n---------snap_hd_time:%llu\n", snap_hd_time); + printf("\n---------snap_hd_msec:%llu\n", snap_hd_msec); + + struct tm * timeinfo; + timeinfo = localtime(&snap_hd_time); + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d-%02d-%02d %02d:%02d:%02d:%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, snap_hd_msec); + + printf("\n--------buf_time_info:%s\n", buf_time_info); +#endif + int index_approaching_to_the_object = 0; + time_t combine_time_approaching_to_the_object = snapHDList[0].snapshot_time_mktime*1000 + snapHDList[0].snapshot_msecs_time; + time_t the_difference_value = combine_time_approaching_to_the_object >= snap_hd_combine_time ? + combine_time_approaching_to_the_object - snap_hd_combine_time : + snap_hd_combine_time - combine_time_approaching_to_the_object; + + for (int i = index_approaching_to_the_object + 1; i < MAX_SNAP_HD_LIST; i++) { + time_t temp_combine_time = snapHDList[i].snapshot_time_mktime * 1000 + snapHDList[i].snapshot_msecs_time; + time_t temp_the_difference_value = temp_combine_time >= snap_hd_combine_time ? + temp_combine_time - snap_hd_combine_time : + snap_hd_combine_time - temp_combine_time; + if (temp_the_difference_value < the_difference_value) { + index_approaching_to_the_object = i; + combine_time_approaching_to_the_object = temp_combine_time; + the_difference_value = temp_the_difference_value; + } + } + + int choose_hd_index = index_approaching_to_the_object; + + if (choose_hd_index >= 0 && choose_hd_index < MAX_SNAP_HD_LIST && + snapHDList[choose_hd_index].snapshot_size >= 1) + { + if (send(cli_socket, snapHDList[choose_hd_index].snapshot_addr, snapHDList[choose_hd_index].snapshot_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999992\n"); + } + } + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snaphd", 7) == 0 && strncmp(urlBuffer, "/snaphd?index=", 14) != 0 && strncmp(urlBuffer, "/snaphd?time=", 13) != 0) + { + pthread_mutex_lock(&mutex_web); + //pthread_mutex_lock(&mutex_get_canvas); + //pthread_mutex_lock(&mutex_get_network_input); + size_t snapshot_size = 0; + + //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19991\n"); + + //printf("\n------------snapshot_size:%d\n",(int)snapshot_size); + + if ((int)snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, (int)snapshot_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999993\n"); +#if 1 + for (int i = 0; i < MAX_SNAP_HD_LIST; i++) { + if (snapHDList[i].snapshot_size == 0) { + snapHDList[i].snapshot_size = (int)snapshot_size; + + memset(snapHDList[i].snapshot_addr, 0x00, MAX_IMG_SIZE); + memcpy(snapHDList[i].snapshot_addr, snapshot_addr, (int)snapshot_size); + + time_t rawtime = time(0); + snapHDList[i].snapshot_time = localtime(&rawtime); + snapHDList[i].snapshot_time_mktime = mktime(snapHDList[i].snapshot_time); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + snapHDList[i].snapshot_msecs_time = time_now.tv_usec / 1000; + + break; + } + else if (i == MAX_SNAP_HD_LIST - 1) { + + int min_time_index = 0; + time_t min_time_mktime = snapHDList[0].snapshot_time_mktime; + time_t min_time_msecs_time = snapHDList[0].snapshot_msecs_time; + + for (int index_j = min_time_index + 1; index_j < MAX_SNAP_HD_LIST; index_j++) { + if (snapHDList[index_j].snapshot_time_mktime < min_time_mktime) { + min_time_index = index_j; + min_time_mktime = snapHDList[index_j].snapshot_time_mktime; + min_time_msecs_time = snapHDList[index_j].snapshot_msecs_time; + } + else if (snapHDList[index_j].snapshot_time_mktime == min_time_mktime) { + if (snapHDList[index_j].snapshot_msecs_time < min_time_msecs_time) { + min_time_index = index_j; + min_time_mktime = snapHDList[index_j].snapshot_time_mktime; + min_time_msecs_time = snapHDList[index_j].snapshot_msecs_time; + } + } + } + + snapHDList[min_time_index].snapshot_size = (int)snapshot_size; + + memset(snapHDList[min_time_index].snapshot_addr, 0x00, MAX_IMG_SIZE); + memcpy(snapHDList[min_time_index].snapshot_addr, snapshot_addr, (int)snapshot_size); + + time_t rawtime = time(0); + snapHDList[min_time_index].snapshot_time = localtime(&rawtime); + snapHDList[min_time_index].snapshot_time_mktime = mktime(snapHDList[min_time_index].snapshot_time); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + snapHDList[min_time_index].snapshot_msecs_time = time_now.tv_usec / 1000; + } + } +#endif + } + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_get_canvas); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/switchimage", 12) == 0) { + pthread_mutex_lock(&mutex_web); + //switch_g_image_buff_ori = 1; + if (strlen(contentDescription) > 0) + { + strcpy(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2111\n"); + + //printf("\nset_bypass_login \n"); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#if 1 + //== /getimage_ori? + else if (strncmp(urlBuffer, "/getimage?", 10) == 0) { + + //pthread_mutex_lock(&mutex_web); + + char snapshot_addr[MAX_IMG_SIZE] = {0}; + int snapshot_size = 0; + + // char c_profileid[30] = { 0 }; + /// strcpy(c_profileid, urlBuffer+16); + // int i_profileid = atoi(c_profileid); + + // printf("\n----------i_profileid:%d\n", i_profileid); + + pthread_mutex_lock(&mutex_get_image); + //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) + + // 2022-11-24 Ken Move /radarsnap to here +#if 0 + if (strstr(urlBuffer, "?radar") != NULL) + { + memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + // struct timeval start; + // gettimeofday(&start, NULL); + // time_t start_msecs_time = start.tv_usec / 1000; + + snapshot_size = (int)get_radar_image(snapshot_addr); + + // struct timeval end; + // gettimeofday(&end, NULL); + // time_t end_msecs_time = end.tv_usec / 1000; + // printf("\n=== radarsnap - get radar time, ms Time = %f\n\n", difftime(end_msecs_time, start_msecs_time)); // 2022-11-01 time cost : 30 ~ 170 ms >>> 2x ~ 15x ms + + // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + // perror("send error #1999"); + } + else +#endif + { + if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1) { + memcpy(snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); + snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; + } + // snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); + // snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); + } + pthread_mutex_unlock(&mutex_get_image); + //printf("\n---------------getimage ori:snapshot_size:%d\n", snapshot_size); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19121\n"); + else { + + if (snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) + printf("\nsend error #19129\n"); + } + } + + //pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/getimage_ori?", 14) == 0) { + + //pthread_mutex_lock(&mutex_web); + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + int snapshot_size = 0; + + //char c_profileid[30] = { 0 }; + ///strcpy(c_profileid, urlBuffer+16); + //int i_profileid = atoi(c_profileid); + + //printf("\n----------i_profileid:%d\n", i_profileid); + + pthread_mutex_lock(&mutex_get_image); + //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) + + // 2022-11-24 Ken Move /radarsnap to here +#if 0 + if (strstr(urlBuffer, "?radar") != NULL) + { + memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + // struct timeval start; + // gettimeofday(&start, NULL); + // time_t start_msecs_time = start.tv_usec / 1000; + + snapshot_size = (int)get_radar_image(snapshot_addr); + + // struct timeval end; + // gettimeofday(&end, NULL); + // time_t end_msecs_time = end.tv_usec / 1000; + // printf("\n=== radarsnap - get radar time, ms Time = %f\n\n", difftime(end_msecs_time, start_msecs_time)); // 2022-11-01 time cost : 30 ~ 170 ms >>> 2x ~ 15x ms + + // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + // perror("send error #1999"); + } + else +#endif + { + if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1){ + memcpy(snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); + snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; + } + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); + //snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); + } + pthread_mutex_unlock(&mutex_get_image); + //printf("\n---------------getimage ori:snapshot_size:%d\n", snapshot_size); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19121\n"); + else { + if (snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) + printf("\nsend error #19129\n"); + } + } + + //pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#if defined GY_OS_AMBA + else if (strncmp(urlBuffer, "/getimage_HD?", 13) == 0) { + + //pthread_mutex_lock(&mutex_web); + + char snapshot_addr[MAX_IMG_SIZE_HD] = { 0 }; + int snapshot_size = 0; + + //char c_profileid[30] = { 0 }; + ///strcpy(c_profileid, urlBuffer+16); + //int i_profileid = atoi(c_profileid); + + //printf("\n----------i_profileid:%d\n", i_profileid); + + if (g_video_start_HD == 1) { + pthread_mutex_lock(&mutex_get_image_HD); + //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) + { + if (g_image_buff_size_HD[g_current_max_num_image_buff - 1] >= 1) { + memcpy(snapshot_addr, g_image_buff_HD[g_current_max_num_image_buff - 1], g_image_buff_size_HD[g_current_max_num_image_buff - 1]); + snapshot_size = g_image_buff_size_HD[g_current_max_num_image_buff - 1]; + + memcpy(g_image_buff_HD_pause, snapshot_addr, snapshot_size); + g_image_buff_size_HD_pause = snapshot_size; + } + + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); + //snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); + } + pthread_mutex_unlock(&mutex_get_image_HD); + //printf("\n---------------getimage HD:snapshot_size:%d\n", snapshot_size); + } + else if(g_image_buff_size_HD_pause >= 1) { + memcpy(snapshot_addr, g_image_buff_HD_pause, g_image_buff_size_HD_pause); + snapshot_size = g_image_buff_size_HD_pause; + } + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #1912122\n"); + else { + if (snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) + printf("\nsend error #1912922\n"); + } + } + + //pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#endif +#if 0 + else if (strncmp(urlBuffer, "/remotesnap", 11) == 0) + { + // printf("\nurlBuffer : %s\n", urlBuffer); + + if (g_check_if_remotesnap_running == 0) + { + // TODO check PTZ + g_check_if_remotesnap_running = 1; + + pthread_mutex_lock(&mutex_remotesnap_image); + + // char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + // size_t snapshot_size = 0; + + // memset(snapshot_addr, 0x00, MEMORY_SIZE); + + // snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + // snapshot_size = get_g_canvas_addr(snapshot_addr); + + g_remotesnap_snapshot_size = 0; + if ((int)g_remotesnap_snapshot_size == 0) + { + g_remotesnap_snapshot_size = PNS_Get_Snapshot_From_Remote_IPCam("remotesnap_buf.jpg", g_remotesnap_snapshot_addr, 0); + // printf("\nnormal g_remotesnap_snapshot_size %d\n", g_remotesnap_snapshot_size); + } + if ((int)g_remotesnap_snapshot_size >= 0 && (int)g_remotesnap_snapshot_size < 500) + { + g_remotesnap_snapshot_size = get_nosignal_image(g_remotesnap_snapshot_addr); + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + { + printf("\n[CGI:/remotesnap] send buffer error #1\n"); + } + + if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) + printf("\n[CGI:/remotesnap] send snapshot error #1\n"); + } + + if ((int)g_remotesnap_snapshot_size >= 500) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + { + printf("\n[CGI:/remotesnap] send buffer error #2\n"); + } + + if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) + printf("\n[CGI:/remotesnap] send snapshot error #2\n"); + } + + pthread_mutex_unlock(&mutex_remotesnap_image); + g_check_if_remotesnap_running = 0; + } + else + { + pthread_mutex_lock(&mutex_remotesnap_image); + if ((int)g_snap_snapshot_size >= 1) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + { + printf("\n[CGI:/remotesnap] send buffer error #3\n"); + } + + if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) + printf("\n[CGI:/remotesnap] send snapshot error #3\n"); + } + pthread_mutex_unlock(&mutex_remotesnap_image); + } + + // else { + // sprintf(sendBuffer, "HTTP/1.1 400 Bad Request\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + // if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + // printf("\nsend error #1991239\n"); + //} + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snap",5) == 0 && strncmp(urlBuffer, "/snaphd", 7) != 0 && strncmp(urlBuffer, "/snap?profileid=", 16) != 0) + { + if (g_check_if_snap_running == 0) { + g_check_if_snap_running = 1; + + pthread_mutex_lock(&mutex_snap_image); + + //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //size_t snapshot_size = 0; + + //memset(snapshot_addr, 0x00, MEMORY_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + //snapshot_size = get_g_canvas_addr(snapshot_addr); + + g_snap_snapshot_size = 0; + if ((int)g_snap_snapshot_size == 0){ + g_snap_snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snap_snapshot_addr, 0); + } + + + if ((int)g_snap_snapshot_size >= 1) { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) { + printf("\nsend error #199911\n"); + } + + if (send(cli_socket, g_snap_snapshot_addr, (int)g_snap_snapshot_size, MSG_MORE) == -1) + printf("\nsend error #19999994\n"); + } + + pthread_mutex_unlock(&mutex_snap_image); + g_check_if_snap_running = 0; + + + } + else { + pthread_mutex_lock(&mutex_snap_image); + if ((int)g_snap_snapshot_size >= 1) { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) { + printf("\nsend error #199912\n"); + } + + if (send(cli_socket, g_snap_snapshot_addr, (int)g_snap_snapshot_size, MSG_MORE) == -1) + printf("\nsend error #1999933\n"); + } + pthread_mutex_unlock(&mutex_snap_image); + } + + + //else { + //sprintf(sendBuffer, "HTTP/1.1 400 Bad Request\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + //if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + //printf("\nsend error #1991239\n"); + //} + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/differ_image_test") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199915\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + differ_image_test(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, get_g_ori_yuv_width(), get_g_ori_yuv_height()); + + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999997\n"); + } + } + + + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif + else if (strncmp(urlBuffer, "/set_value&",11) == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char value_buffer[256] = { 0 }; + memset(value_buffer, 0x00, sizeof(value_buffer)); + strcpy(value_buffer, urlBuffer + 11); + + //printf("\n-----------%s\n", value_buffer); + + char Msg[256] = { 0 }; + + if (strncmp(value_buffer, "day_or_night=1", 14) == 0) { + + imageDnData.color_mode = 1; + + strcpy(Msg,"OK"); + } + else if (strncmp(value_buffer, "day_or_night=0", 14) == 0){ + + imageDnData.color_mode = 2; + + strcpy(Msg, "OK"); + } + else { + strcpy(Msg, "fail"); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#if 0 + else if (strcmp(urlBuffer, "/differ_image") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199915\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + int no_tempering = 0; + differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(),0,0,&no_tempering,1); + + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999997\n"); + } + } + + + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/bgsnap", 7) == 0) + { + if (g_IsRadarDevice == 1) { + pthread_mutex_lock(&mutex_web); + char snapshot_addr_radar[MEMORY_SIZE] = { 0 }; + memset(snapshot_addr_radar, 0x00, MEMORY_SIZE); + size_t snapshot_size = 0; + snapshot_size = (size_t)get_bg_radar_image(snapshot_addr_radar); + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + perror("send error #199916"); + if ((int)snapshot_size >= 1) + { + if (send(cli_socket, snapshot_addr_radar, (int)snapshot_size, 0) == -1) + perror("send error #19999998"); + } + else + { + printf("empty radar image\n"); + } + pthread_mutex_unlock(&mutex_web); + } + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/speedbgsnap", 12) == 0) + { + pthread_mutex_lock(&mutex_web); + char radar_speed_snapshot_addr[MEMORY_SIZE] = {0}; + memset(radar_speed_snapshot_addr, 0x00, MEMORY_SIZE); + size_t speed_snapshot_size = 0; + speed_snapshot_size = (size_t)get_speed_bg_image(radar_speed_snapshot_addr); + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + perror("send error #199917"); + if ((int)speed_snapshot_size >= 1) + { + if (send(cli_socket, radar_speed_snapshot_addr, (int)speed_snapshot_size, 0) == -1) + perror("send error #19999999"); + } + else + { + printf("empty radar image\n"); + } + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } + // ======================================================================================== +#endif +#if 0 + else if (strcmp(urlBuffer, "/differ_image_short") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199918\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + + + int no_tempering = 0; + differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0, 1, &no_tempering,1); + + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #1999989\n"); + } + } + + + ///pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/differ_image_long") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199919\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + + int no_tempering = 0; + differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 1, 0, &no_tempering,1); + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #1999989\n"); + } + } + + + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/count_color", 12) == 0) + { + pthread_mutex_lock(&mutex_web); + //pthread_mutex_lock(&mutex_get_network_input); + pthread_mutex_lock(&mutex_differ_image); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199920\n"); + + if ((int)snapshot_size >= 1) { + + int color_size = 0; + char color_addr[MAX_IMG_SIZE] = { 0 }; + memset(color_addr, 0x00, MAX_IMG_SIZE); + //pNext_word->name:car,pNext_word->box_x:878.322632,pNext_word->box_y:560.714294,pNext_word->box_w:1680.456665,pNext_word->box_h:1315.334717 + detection_pos fake_pNext = { 0 }; + fake_pNext.left_x = 948; + fake_pNext.top_y = 1093; + fake_pNext.width = 1245; + fake_pNext.height = 648; + + crop_image_ivs(color_addr, &color_size, snapshot_addr, (int)snapshot_size, &fake_pNext, get_g_ori_yuv_width(), get_g_ori_yuv_height()); + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (color_size >= 1) { + if (send(cli_socket, color_addr, color_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999990\n"); + } + } + + + pthread_mutex_unlock(&mutex_differ_image); + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif + else if (strcmp(urlBuffer, "/sync_ipcam_account_setting") == 0) + { + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed\n"); + } + + + if (strlen(contentDescription) > 0) + { + strcpy(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2111\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } +#if 1 + else if (strcmp(urlBuffer, "/sync_image_rotation") == 0) + { +#if 1 + sync_image_rotation_thread(); +#endif + if (strlen(contentDescription) > 0) + { + strcpy(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2113\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/get_enable_ptz") == 0) + { + char convert_tojson1[256] = "{\"enable_PTZ\":\""; + char convert_tojson2[256] = "\"}"; + + + strcat(contentBuffer, convert_tojson1); + + char enable_PTZ_off[256] = "No"; +#ifdef GY_OS_AMBA + char enable_PTZ_on[256] = "Yes"; + + //Check PTZ device + //char ptz_curl_url[512] = { 0 }; + //char ptz_curl_sendbuf[1] = { 0 }; + //char ptz_curl_username[128] = { 0 }; + //char ptz_curl_password[128] = { 0 }; + //char *method = "GET"; + //int ptz_port = atoi(accountData[0].account_port); + + //strcpy(ptz_curl_username, accountData[0].account_username); + //strcpy(ptz_curl_password, accountData[0].account_password); + + //strcpy(ptz_curl_url, "http://"); + //strcat(ptz_curl_url, "127.0.0.1:"); + //strcat(ptz_curl_url, accountData[0].account_port); + //strcat(ptz_curl_url, "/server"); + + //if (check_ptz(ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port)) + if(g_IsPTZDevice == 1) + { + strcat(contentBuffer, enable_PTZ_on); + //strcat(contentBuffer, enable_PTZ_off); + //write_to_enable_PTZ("Yes"); //enable_PTZ |Ψ + } + else +#endif + { + strcat(contentBuffer, enable_PTZ_off); + //write_to_enable_PTZ("No"); //enable_PTZ |Ψ + } + + strcat(contentBuffer, convert_tojson2); + //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/set_only_show_metadata1_on") == 0 || strcmp(urlBuffer, "/set_only_show_metadata1_off") == 0) + { + //printf("\n[web process]start 14\n"); + /*printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nenable_base64: %d\n", enable_base64); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + //printf("set_bypass_login\n"); + char convert_tojson1[256] = "{\"ONLY_SHOW_METADATA1\":\""; + char convert_tojson2[256] = "\"}"; + + char only_show_metadata1_on[256] = "on"; + char only_show_metadata1_off[256] = "off"; + + strcat(contentBuffer, convert_tojson1); + + if (strcmp(urlBuffer, "/set_only_show_metadata1_on") == 0) + { + enable_only_show_metadata1 = 1; + strcat(contentBuffer, only_show_metadata1_on); + update_enable_only_show_metadata1(enable_only_show_metadata1); + } + else if (strcmp(urlBuffer, "/set_only_show_metadata1_off") == 0) + { + enable_only_show_metadata1 = 0; + strcat(contentBuffer, only_show_metadata1_off); + update_enable_only_show_metadata1(enable_only_show_metadata1); + } + + strcat(contentBuffer, convert_tojson2); + //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/getsmartevent?", 15) == 0 || strncmp(urlBuffer, "/setsmartevent?", 15) == 0) //oipcamevent?get=all (strncmp(urlBuffer, "/getconfig?", 11) == 0) || (strncmp(urlBuffer, "/setconfig?", 11) == 0) + { + //printf("\n[web process]start 15\n"); + char wanted[512] = { 0 }; + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(wanted, firstBuffer + 15); + + //printf("\n%s\n", accountData[0].account_username); + //printf("\n%s\n", accountData[0].account_password); + int size_psBuffer = 256; + + char psBuffer[256] = { 0 }; + char psBuffer_temp[256] = { 0 }; + char psBuffer_send[256] = { 0 }; + + if (strncmp(urlBuffer, "/getsmartevent?", 15) == 0) + { + FILE* pPipe;/*,*pPipe2*/ + printf("\ngetsmartevent\n"); + printf("\n%s\n", wanted); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + /* + char cmd_port[256] = { 0 }; + memset(cmd_port, 0x00, sizeof(cmd_port)); + */ + char cmd1[256] = "curl http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//@127.0.0.1: + char cmd4[256] = "/event?get=all | grep "; + //char cmd_port1[256] = "@localhost/network?http.port=81 | grep http.port"; + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, wanted); + //printf("\n[getallevent]cmd: %s\n",cmd); + + /*strcat(cmd_port, cmd1); + strcat(cmd_port, accountData[0].account_username); + strcat(cmd_port, cmd2); + strcat(cmd_port, accountData[0].account_password); + strcat(cmd_port, cmd_port1);*/ + + if (/*(pPipe2 = vpopen(cmd_port,"r")) == NULL ||*/ (pPipe = vpopen(cmd, "r")) == NULL) + { + printf("[Error] getsmartevent\n"); + } + else + { + printf("Run: getsmartevent\n"); + char* temp = NULL; + temp = fgets(psBuffer, size_psBuffer, pPipe); + + if (temp != NULL) + { + strncpy(psBuffer_temp, psBuffer, 256); + int c = 0, d = 0; + while (psBuffer_temp[c] != '\0') + { + if (psBuffer_temp[c] == ' ' || psBuffer_temp[c] == '\t') + { + int temp_index = c + 1; + if (psBuffer_temp[temp_index] != '\0') + { + while ((psBuffer_temp[temp_index] == ' ' || psBuffer_temp[temp_index] == '\t') && psBuffer_temp[temp_index] != '\0') + { + if (psBuffer_temp[temp_index] == ' ' || psBuffer_temp[temp_index] == '\t') + c++; + + temp_index++; + } + } + } + psBuffer_send[d] = psBuffer_temp[c]; + c++; + d++; + } + psBuffer_send[d] = '\0'; + + printf("getsmartevent psBuffer: OK\n"); + } + else + { + strcpy(psBuffer_send, "NULL"); + printf("[Error]getsmartevent psBuffer Empty\n"); + } + + if (strcmp(psBuffer_send, "NULL") == 0) + { + char convert_tojson1[256] = "{\"ALL_EVENT\":\""; + char convert_tojson2[256] = "\"}"; + printf("\n[getsmartevent] return str = %s \n", psBuffer_send); + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, psBuffer_send); + strcat(contentBuffer, convert_tojson2); + } + else + { + char convert_tojson1[256] = "{\""; + char convert_tojson2[256] = "\":\""; + char convert_tojson3[256] = "\"}"; + char myarr[2][STRSPLIT_SIZE] = { 0 }; + const char *mydel = "="; + + printf("\n[getsmartevent] return str = %s \n", psBuffer_send); + StrSplit(psBuffer_send, myarr, mydel); + + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, *(myarr)); + strcat(contentBuffer, convert_tojson2); + /* + int temp_index = 0; + while (*(myarr + 1)[temp_index] != '\0' && *(myarr + 1)[temp_index] != '\n') { + strcat(contentBuffer, *(myarr + 1)[temp_index]); + temp_index++; + }*/ + strcat(contentBuffer, *(myarr + 1)); + strcat(contentBuffer, convert_tojson3); + //name: *(myarr) //vale: *(myarr+1) + } + printf("\n[getsmartevent] contentBuffer = %s \n", contentBuffer); + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #25\n"); + + printf("\ngetsmartevent\n"); + } + if (pPipe != NULL) + vpclose(pPipe); + } + else if (strncmp(urlBuffer, "/setsmartevent?", 15) == 0) + { + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #26\n"); + + pthread_t auto_build_smart_events_thread_id; + if (pthread_create(&auto_build_smart_events_thread_id, 0, auto_build_smart_events, NULL)) + { + printf("create auto_build_smart_events thread faile \n"); + } + } + //if (pPipe2 != NULL) + // vpclose(pPipe2); + closesocket(cli_socket); + usSleep(5000); + } +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/set_divi_smartevent", 20) == 0) + { + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2556\n"); + + pthread_t auto_build_smart_events_thread_id_di_vi; + if (pthread_create(&auto_build_smart_events_thread_id_di_vi, 0, auto_build_smart_events_di_vi, NULL)) + { + printf("create auto build smart events di vi thread faile \n"); + } + + closesocket(cli_socket); + usSleep(1250); + } +#endif +#if 1 //|crash + else if (strcmp(urlBuffer, "/pns_dev_name") == 0) // Trigger command for PNS 2.0 + { + printf("[pns_dev_name] Triggered.\n"); + char returned_msg[512] = { 0 }; + PNS_Get_Device_Name(1, returned_msg); + if (returned_msg != NULL) + { + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\npns_debug sending response error.\n"); + + } + else { + printf("[web process] Warning: returned_msg is NULL.\n"); + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #34-22\n"); + } + + printf("[pns_dev_name] Finished.\n"); + closesocket(cli_socket); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_snap") == 0) + { + printf("[pns_snap] Triggered.\n"); + + char sendBuffer[BUFSIZE_V2] = { 0 }; + char img_addr[25 * 1024] = {0}; + size_t img_size = PNS_Get_Snapshot_From_IPCam("curl_saved_from_pns_buf.jpg", img_addr,1); + + if (img_size >= 1) + { + char img_info[1024]; + sprintf(img_info, "Image addr: %p\nImage size: %ld\nImage content:\n", img_addr, img_size); + + /* + for (int i = 0; i < img_size; i++) + { + char value[8]; + sprintf(value, "0x%x", img_addr[i]); + strcat(img_info, value); + } + strcat(img_info, "\n");*/ + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(img_info), img_info); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[pns_snap] sending successfully.\n"); + } + else + { + printf("[pns_snap] PNS_Get_Snapshot_From_IPCam fetching error.\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #34-23\n"); + } + + closesocket(cli_socket); + printf("[pns_snap] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_query") == 0) // Only for test. Not the official service. + { + printf("[pns query] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Query_Service_Status(returned_msg); + + const char keyword[] = "\"snap\":\""; + char* start = strstr(returned_msg, keyword); + char* end = strstr(returned_msg, "\"}"); + size_t length = (size_t)end - (size_t)start - strlen(keyword); + if (length > 0) + { + char* cloud_addr = malloc(length + 1); + strncpy(cloud_addr, start + strlen(keyword), length); + cloud_addr[length] = '\0'; + printf("Cloud addr. before ddDec: %s\n", cloud_addr); + char* dddec_cloud_addr = ddDec(cloud_addr); + printf("Cloud addr. after ddDec: %s\n", dddec_cloud_addr); + if (cloud_addr) { + free(cloud_addr); + cloud_addr = NULL; + } + if (dddec_cloud_addr) { + free(dddec_cloud_addr); + dddec_cloud_addr = NULL; + } + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[pns query] Sending response error.\n"); + closesocket(cli_socket); + printf("[pns query] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_multipart_debug") == 0) // Only for test. Not the official service. + { + printf("[pns_multipart_debug] Triggered.\n"); + char fake_desc[512] = { 0 }; + PNS_Get_Device_Name(1, fake_desc); + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Send_Multipart_POST("wtf", "", "", "", fake_desc, "vega@ddnsipcam.com", "5Wizards", "https://cloud.ddnsipcam.com/pns/", returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\npns_multipart sending response error.\n"); + closesocket(cli_socket); + printf("[pns_multipart_debug] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_multipart") == 0) // Only for test. Not the official service. + { + printf("[pns_multipart] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Send_Multipart_POST("wtf", "", "", "", "", SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/", returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\npns_multipart sending response error.\n"); + closesocket(cli_socket); + printf("[pns_multipart] Finished.\n"); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/ddns_check") == 0) // Only for test. Not the official service. + { + printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + DDNS_Communication(0, "stevehub@meritlilin.com.tw", "12345", returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/ddns_register") == 0) // Only for test. Not the official service. + { + printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + DDNS_Communication(1, SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/ddns_login") == 0) // Only for test. Not the official service. + { + printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + DDNS_Communication(2, SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/ddns_image_check") == 0) // Only for test. Not the official service. + { + //printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + PNS_check_if_to_post_image(SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg,"https://cloud.ddnsipcam.com/pns/"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + //printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/net_curl_test") == 0) // Only for test. Not the official service. + { + printf("[net curl test] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + + curl_information_smtp_t user_smtp; + + strcpy(user_smtp.receiver[0], IPCAMService.email_address1); + strcpy(user_smtp.receiver[1], IPCAMService.email_address2); + strcpy(user_smtp.receiver[2], IPCAMService.email_address3); + strcpy(user_smtp.receiver[3], IPCAMService.email_address4); + strcpy(user_smtp.receiver[4], IPCAMService.email_address5); + + + strcpy(user_smtp.address, IPCAMService.email_address); + strcpy(user_smtp.server, IPCAMService.smtp_server); + sprintf(user_smtp.auth_mode,"%d", IPCAMService.smtp_auth_mode); + strcpy(user_smtp.port, IPCAMService.smtp_port); + sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); + strcpy(user_smtp.user, IPCAMService.auth_account); + + char test_temp[10] = { 0 }; + + if (net_curl_smtp_data(&user_smtp, test_temp,0) < 0){ + strcpy(returned_msg, "SMTP Fail"); + printf("\nSMTP Fail\n"); + } + else { + strcpy(returned_msg, "SMTP OK"); + printf("\nSMTP OK\n"); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[net curl test] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[net curl test] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/reboot_my_service") == 0) // Only for test. Not the official service. + { + printf("[reboot test] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + + strcpy(returned_msg,"start to reboot"); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[reboot test] Service sending/response error.\n"); + closesocket(cli_socket); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot my service"); + write_to_logs_html(temp_msg, "reboot my service", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "reboot my service", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + + printf("[reboot test] Finished.\n"); + } +#endif + else if (strcmp(urlBuffer, "/getAnprInfo") == 0) //20201005 sophia add + { + //printf("\n[web process]start 17\n"); + ///get config info + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("read config.json.\n"); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *config_root, *view_setting, *camera; + + config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + //printf("\n[web process]start 17-2\n"); + if (config_root) + { + //printf("config.json parse OK.\n"); + int anpr_ch = 0; + { + view_setting = cJSON_GetObjectItem(config_root, "view_setting"); + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", anpr_ch + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + cJSON *root/*, *levenshtein_distance*/, *min_characters, *max_characters, *confidence, *enable_anpr,*enable_face; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + //levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + confidence = cJSON_GetObjectItem(camera, "confidence"); + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + + /*printf("\nenable_anpr:%s", enable_anpr->valuestring); + printf("\nconfidence:%s", confidence->valuestring); + printf("\nmin_characters:%s", min_characters->valuestring); + printf("\nmax_characters:%s", max_characters->valuestring);*/ + + cJSON_AddItemToObject(root, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); + cJSON_AddItemToObject(root, "enable_face", cJSON_CreateString(enable_face->valuestring)); + cJSON_AddItemToObject(root, "confidence", cJSON_CreateString(confidence->valuestring)); + cJSON_AddItemToObject(root, "min_characters", cJSON_CreateString(min_characters->valuestring)); + cJSON_AddItemToObject(root, "max_characters", cJSON_CreateString(max_characters->valuestring)); + //printf("\n[web process]start 17-3\n"); + JsonString = cJSON_PrintUnformatted(root); + //printf("\n[getAnprInfo]return json str = %s \n", JsonString); + + strcat(contentBuffer, JsonString); + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #28\n"); + //printf("\n[web process]start 17-4\n"); + //send(cli_socket, JsonString, sizeof(JsonString), 0); + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(JsonString), JsonString); + //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + //{ + // printf("\nsend error\n"); + //} + //printf("\nget apnr info \n"); + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (config_root) { + cJSON_Delete(config_root); + config_root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } + //printf("\n[web process]start 17-5\n"); + closesocket(cli_socket); + } + // ======================================================================================== + // Ken 2022-09-22 + else if (strcmp(urlBuffer, "/getradar") == 0) + { + char radarPATH[1024] = { 0 }; + strcpy(radarPATH, exePath); + strcat(radarPATH, "radar.json"); + char *filename = radarPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else + { + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) + { + cJSON *config_root; + char *JsonString = NULL; + config_root = cJSON_Parse(fileBuf); + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (config_root) + { + JsonString = cJSON_PrintUnformatted(config_root); + strcat(contentBuffer, JsonString); + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) + perror("send error #28"); + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (config_root) + { + cJSON_Delete(config_root); + config_root = NULL; + } + } + else + printf("radar.json parse FAIL.\n"); + } + } + // ======================================================================================== + // printf("\n[web process]start 17-5\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/get_search_info?",17) == 0) //claire add + { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //printf("\n[web process]start 18\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+17); + //printf("\n------beforeSendBuffer:%s\n", beforeSendBuffer); + cgi_get_search_info(cli_socket, beforeSendBuffer); + //printf("\n[web process]end 18888\n"); + pthread_mutex_unlock(&mutex_enable_lpr_db); + //printf("\n[web process]end 18\n"); + /* + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error\n"); + */ +#endif + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/set_search_info?",17) == 0) //claire add + { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //printf("\n[web process]start 19\n"); + //printf("\n-------urlBufffer:%s\n",urlBuffer); + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+17); + char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); + strcpy(beforeSendBuffer, temp_beforeSendBuffer); + + if (temp_beforeSendBuffer != NULL) { + free(temp_beforeSendBuffer); + temp_beforeSendBuffer = NULL; + } + + url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); + + //printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); + + cgi_set_search_info(cli_socket, beforeSendBuffer); + +#endif + closesocket(cli_socket); + } +#if 0 + // joy + else if (strncmp(urlBuffer, "/import_face_list", strlen("/import_face_list")) == 0) + { + printf("\n-------------import face list\n"); + g_count_lpr_insert_times = 0; + + memset(g_headerBuffer,0x00, BUFSIZE_V2); + memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); + memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); + + strcpy(g_headerBuffer, headerBuffer); + strcpy(g_multiPartBoundary, multiPartBoundary); + g_bIsMultipart = bIsMultipart; + strcpy(g_contentBuffer, contentBuffer); + g_nTotalContentLen = nTotalContentLen; + + printf("\ng_headerBuffer -------------%s\n",g_headerBuffer); + printf("\ng_contentBuffer-------------%s\n",g_contentBuffer); + printf("\ng_multiPartBoundary-------------%s\n",g_multiPartBoundary); + printf("\ng_bIsMultipart-------------%d\n",g_bIsMultipart); + printf("\ng_nTotalContentLen-------------%ld\n",g_nTotalContentLen); + + pthread_t import_face_list_file_thread_id; + // t~} thread xsɮ׸ + if (pthread_create(&import_face_list_file_thread_id, 0, import_face_list_file_thread, NULL)) + { + printf("create import_face_list_file_thread faile \n"); + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/face_list?", 11) == 0) //claire add + { + printf("face list = %s \n", urlBuffer); + + if (unlockingKeyInnoFR == 1) { + if (strstr(urlBuffer, "select=") != NULL || + strstr(urlBuffer, "flist=") != NULL || + strstr(urlBuffer, "download=") != NULL) + { + ///get_search_info_face + + pthread_mutex_lock(&mutex_enable_face_db); + //printf("select url buf: %s \n", urlBuffer); + + memset(firstBuffer, 0, sizeof(firstBuffer)); + + //printf("urlBuffer = %s \n", urlBuffer); + + + //printf("no err str \n"); + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + + printf("firstbuf = %s \n", firstBuffer); + + + //firstBuffer[strlen(urlBuffer)] = '\0'; + + strcpy(beforeSendBuffer, firstBuffer + 11); + //printf("beforeSendBuffer = %s \n", beforeSendBuffer); + cgi_get_search_info_face(cli_socket, beforeSendBuffer); + //printf("\n[web process]end 18888\n"); + pthread_mutex_unlock(&mutex_enable_face_db); + } + else if (strstr(urlBuffer, "delete=") != NULL || + strstr(urlBuffer, "clean=") != NULL || + strstr(urlBuffer, "add=") != NULL || + strstr(urlBuffer, "update=") != NULL + ) + { + ///set_search_info_face + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 11); + char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); + strcpy(beforeSendBuffer, temp_beforeSendBuffer); + + if (temp_beforeSendBuffer != NULL) { + free(temp_beforeSendBuffer); + temp_beforeSendBuffer = NULL; + } + + url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); + + printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); + //FACE_MSG_BLACKTABLE + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + } + } + + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/get_search_info_face?",22) == 0) // face - leo + { +#ifdef GY_OS_AMBA +#if 0 + if (unlockingKeyInnoFR == 1) { + pthread_mutex_lock(&mutex_enable_face_db); + //printf("select url buf: %s \n", urlBuffer); + + memset(firstBuffer, 0, sizeof(firstBuffer)); + + //printf("urlBuffer = %s \n", urlBuffer); + + + //printf("no err str \n"); + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + + //printf("firstbuf = %s \n", firstBuffer); + + //firstBuffer[strlen(urlBuffer)] = '\0'; + + strcpy(beforeSendBuffer, firstBuffer+22); + cgi_get_search_info_face(cli_socket, beforeSendBuffer); + //printf("\n[web process]end 18888\n"); + pthread_mutex_unlock(&mutex_enable_face_db); + + // sqlite_facegroup_add_list_white_face_list_fix(); + + // test_sfe_add_face_group(); + + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + // printf("\nsend error\n"); + + } +#endif +#endif + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/set_search_info_face?",22) == 0) // face - leo + { +#ifdef GY_OS_AMBA +#if 0 + if (unlockingKeyInnoFR == 1) { + //printf("\n[web process]start /set_search_info_face?\n"); + //printf("\n-------urlBufffer:%s\n",urlBuffer); + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+22); + char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); + strcpy(beforeSendBuffer, temp_beforeSendBuffer); + + if (temp_beforeSendBuffer != NULL) { + free(temp_beforeSendBuffer); + temp_beforeSendBuffer = NULL; + } + + url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); + + //printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); + //FACE_MSG_BLACKTABLE + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + } +#endif + +#endif + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/lpr_info?",10) == 0) //claire add + { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //printf("\n[web process]start 20\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + char *path = NULL; + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+10); + + char l_lpr_cgi_param[BUFSIZE_V2] = {0}; + char l_count[16] = {0}; + //char l_action_lpr[16] = {0}; + char l_compare_str[16] = {0}; + + path = &beforeSendBuffer[0]; + + //set information + sprintf(l_compare_str,"set=status&"); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + + if ((strstr(path, "LPR_FLAG")) != NULL) + { + printf("\nin LPR_FLAG \n"); + + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str, "LPR_FLAG"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if (strlen(l_count) != 0) + { + printf("set LPR_FLAG %s\n", l_count); + } + } + else if ((strstr(path, "LPR_WHITE_FLAG")) != NULL) + { + printf("\nin LPR_WHITE_FLAG \n"); + + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_count, 0, sizeof(l_count)); + sprintf(l_compare_str, "LPR_WHITE_FLAG"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if (strlen(l_count) != 0) + { + printf("set LPR_WHITE_FLAG %s\n", l_count); + + if (strcmp(l_count, "0") == 0)//disable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&whitelist=No"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if (strcmp(l_count, "1") == 0)//disable//enable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&whitelist=Yes"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + } + } + else if ((strstr(path, "LPR_BLACK_FLAG")) != NULL) + { + printf("\nin LPR_BLACK_FLAG \n"); + + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_count, 0, sizeof(l_count)); + sprintf(l_compare_str, "LPR_BLACK_FLAG"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if (strlen(l_count) != 0) + { + printf("set LPR_BLACK_FLAG %s\n", l_count); + + if (strcmp(l_count, "0") == 0)//disable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&blacklist=No"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra));; + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if (strcmp(l_count, "1") == 0)//disable//enable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&blacklist=Yes"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + } + } + } + //get information + sprintf(l_compare_str,"get=status"); + if (strncmp(path, l_compare_str, strlen(l_compare_str)) == 0) + { + //printf("get LPR_FLAG & LPR_BLACK_FLAG & LPR_WHITE_FLAG status\n"); + + if ((strstr(path, "LPR_FLAG")) != NULL) { + //printf("\nin LPR_FLAG \n"); + } + else if ((strstr(path, "LPR_WHITE_FLAG")) != NULL) + { + //printf("\nin LPR_WHITE_FLAG \n"); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&whitelist=all"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_GET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if ((strstr(path, "LPR_BLACK_FLAG")) != NULL) + { + //printf("\nin LPR_BLACK_FLAG \n"); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&blacklist=all"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_GET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + } +#endif //#ifdef GY_OS_AMBA + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #29\n"); + pthread_mutex_unlock(&mutex_enable_lpr_db); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/system?", 8) == 0) + { + //printf("\n[web process]start 21\n"); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + strcpy(Cmd, urlBuffer +8); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + + CgiCmdType type; + type = _CGICMD_GET; + + CgiCmdRtnCode rtn = cgicmd_process(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + + int default_version = 0; + if (rtn == _CGICMD_DEFAULT_NUMBER) { + + if (strncmp(urlBuffer, "/system?default=", 16) == 0) + { + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 16); + + int check_if_not_digit = 0; + for (int index_cmd = 0; index_cmd < strlen(Cmd_temp); index_cmd++) + { + if (!isdigit(Cmd_temp[index_cmd])) + { + check_if_not_digit = 1; + break; + } + } + if (strlen(Cmd_temp) == 0) { + check_if_not_digit = 1; + } + + if (check_if_not_digit == 0) { + default_version = atoi(Cmd_temp); + } + } + } + + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_DEFAULT_3 || rtn == _CGICMD_DEFAULT_ALL || (default_version >= 1 && default_version != 3)) + { + //printf("\nKKKKKKKKKKKKKKK 1\n"); + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "OK"); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #30\n"); + closesocket(cli_socket); + +#if 1 + //if (unlockingKeyInnoFR_success == 1) { + //face_engine_default(); + //usSleep(5000); + //} +#endif + + +#if 1 + char HEATMAP_DATA_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_bak.js"; + if (FileExist(HEATMAP_DATA_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_1_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_1_bak.js"; + if (FileExist(HEATMAP_DATA_1_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_1_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_1_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_1_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_2_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_2_bak.js"; + if (FileExist(HEATMAP_DATA_2_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_2_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_2_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_2_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_3_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_3_bak.js"; + if (FileExist(HEATMAP_DATA_3_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_3_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_3_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_3_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_4_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_4_bak.js"; + if (FileExist(HEATMAP_DATA_4_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_4_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_4_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_4_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_5_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_5_bak.js"; + if (FileExist(HEATMAP_DATA_5_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_5_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_5_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_5_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_6_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_6_bak.js"; + if (FileExist(HEATMAP_DATA_6_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_6_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_6_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_6_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_7_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_7_bak.js"; + if (FileExist(HEATMAP_DATA_7_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_7_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_7_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_7_BAK_PATH cannot be Deleted.\n"); + } + } +#endif + + char CONFIG_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config.json"; + char CONFIG_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_bak.json"; + char CONFIG_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_install.json"; + + if (FileExist(CONFIG_JSON_PATH)) { + int del = unlink(CONFIG_JSON_PATH); + if (!del) { + //printf("CONFIG_JSON_PATH is Deleted successfully."); + } + else { + printf("CONFIG_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(CONFIG_BAK_JSON_PATH)) { + int del = unlink(CONFIG_BAK_JSON_PATH); + if (!del) { + //printf("CONFIG_BAK_JSON_PATH is Deleted successfully."); + } + else { + printf("CONFIG_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + char CONFIG_CUSTOM_1_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_custom_1.json"; + + if (rtn == _CGICMD_DEFAULT_ALL) { + + if (FileExist(CONFIG_INSTALL_JSON_PATH)) { + int del = unlink(CONFIG_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + CopyFileTo(CONFIG_CUSTOM_1_JSON_PATH, CONFIG_INSTALL_JSON_PATH); + } + else if (default_version >= 1 && default_version != 3) { + if (FileExist(CONFIG_INSTALL_JSON_PATH)) { + int del = unlink(CONFIG_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + char CONFIG_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; + sprintf(CONFIG_CUSTOM_NUM_JSON_PATH, "/emmc/plugin/Aida_data/config_custom_%d.json", default_version); + CopyFileTo(CONFIG_CUSTOM_NUM_JSON_PATH, CONFIG_INSTALL_JSON_PATH); + } + else if (strcmp(WeightFileModeName, "mod004") == 0) { + if (FileExist(CONFIG_INSTALL_JSON_PATH)) { + int del = unlink(CONFIG_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + char CONFIG_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; + sprintf(CONFIG_CUSTOM_NUM_JSON_PATH, "/emmc/plugin/Aida_data/config_custom_%d.json", 4); + CopyFileTo(CONFIG_CUSTOM_NUM_JSON_PATH, CONFIG_INSTALL_JSON_PATH); + } + else { + //_CGICMD_DEFAULT_3 + } + + CopyFileTo(CONFIG_INSTALL_JSON_PATH, CONFIG_JSON_PATH); + + char* fileBuf = ReadAllBytes(CONFIG_JSON_PATH); + if (fileBuf) { + cJSON * about_box, *root,*system_setting; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + about_box = cJSON_GetObjectItem(root, "about_box"); + system_setting = cJSON_GetObjectItem(root, "system_setting"); + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + cJSON_ReplaceItemInObject(system_setting, "enable_cloud", cJSON_CreateString("No")); + cJSON_ReplaceItemInObject(system_setting, "enable_python", cJSON_CreateString("No")); + cJSON_ReplaceItemInObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); + cJSON_ReplaceItemInObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); + char* JsonString = cJSON_Print(root); + + FILE *f = fopen(CONFIG_JSON_PATH, "w"); + if (f == NULL) + { + + } + else { + + fprintf(f, "%s\n", JsonString); + fclose(f); + CopyFileTo(CONFIG_JSON_PATH, CONFIG_BAK_JSON_PATH); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + + char COLD_OBJECTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects.json"; + char COLD_OBJECTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects_install.json"; + if (FileExist(COLD_OBJECTS_JSON_PATH)) { + int del = unlink(COLD_OBJECTS_JSON_PATH); + if (!del) { + //printf("cold_objects is Deleted successfully."); + } + else { + printf("COLD_OBJECTS_JSON_PATH cannot be Deleted.\n"); + } + } + CopyFileTo(COLD_OBJECTS_INSTALL_JSON_PATH, COLD_OBJECTS_JSON_PATH); + + char EVENTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events.json"; + char EVENTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_install.json"; + char EVENTS_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_bak.json"; + char EVENTS_CUSTOM_1_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_custom_1.json"; + + if (FileExist(EVENTS_JSON_PATH)) { + int del = unlink(EVENTS_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(EVENTS_BAK_JSON_PATH)) { + int del = unlink(EVENTS_BAK_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + if(rtn == _CGICMD_DEFAULT_ALL){ + + if (FileExist(EVENTS_INSTALL_JSON_PATH)) { + int del = unlink(EVENTS_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + CopyFileTo(EVENTS_CUSTOM_1_JSON_PATH, EVENTS_INSTALL_JSON_PATH); + } + else if (default_version >= 1 && default_version != 3) { + if (FileExist(EVENTS_INSTALL_JSON_PATH)) { + int del = unlink(EVENTS_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + char EVENTS_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; + sprintf(EVENTS_CUSTOM_NUM_JSON_PATH,"/emmc/plugin/Aida_data/events_custom_%d.json", default_version); + CopyFileTo(EVENTS_CUSTOM_NUM_JSON_PATH, EVENTS_INSTALL_JSON_PATH); + } + else if (strcmp(WeightFileModeName, "mod004") == 0) { + if (FileExist(EVENTS_INSTALL_JSON_PATH)) { + int del = unlink(EVENTS_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + char EVENTS_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; + sprintf(EVENTS_CUSTOM_NUM_JSON_PATH, "/emmc/plugin/Aida_data/events_custom_%d.json", 4); + CopyFileTo(EVENTS_CUSTOM_NUM_JSON_PATH, EVENTS_INSTALL_JSON_PATH); + } + else { + //_CGICMD_DEFAULT_3 + } + + CopyFileTo(EVENTS_INSTALL_JSON_PATH, EVENTS_JSON_PATH); + + char EMAILS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/emails.json"; + char EMAILS_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/emails_bak.json"; + if (FileExist(EMAILS_JSON_PATH)) { + int del = unlink(EMAILS_JSON_PATH); + if (!del) { + //printf("emails is Deleted successfully."); + } + else { + printf("EMAILS_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(EMAILS_BAK_JSON_PATH)) { + int del = unlink(EMAILS_BAK_JSON_PATH); + if (!del) { + //printf("emails is Deleted successfully."); + } + else { + printf("EMAILS_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + char TOF_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof.json"; + char TOF_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof_bak.json"; + if (FileExist(TOF_JSON_PATH)) { + int del = unlink(TOF_JSON_PATH); + if (!del) { + //printf("tof is Deleted successfully."); + } + else { + printf("TOF_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(TOF_BAK_JSON_PATH)) { + int del = unlink(TOF_BAK_JSON_PATH); + if (!del) { + //printf("tof is Deleted successfully."); + } + else { + printf("TOF_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/storage"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/sfe/storage"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/playback"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + + g_write_config_file_dirty_flag = 0; + + //memset(msg, 0x00, sizeof(msg)); + //sprintf(msg, (default_dataset_for_jsonfile() > 0 ? "Default failed!" : "Default OK.")); + //printf(msg); + //strcpy(beforeSendBuffer_xtra, msg); + + + printf("\n--------------------reload 1\n"); + + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg); + strcat(beforeSendBuffer_xtra, msg); + + char db_fflprPATH[1024] = { 0 }; + char db_fflpr_installPATH[1024] = { 0 }; + char db_facePATH[1024] = { 0 }; + char db_face_installPATH[1024] = { 0 }; + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + strcpy(db_fflprPATH, exePath); + strcpy(db_fflpr_installPATH, exePath); + strcpy(db_facePATH, exePath); + strcpy(db_face_installPATH, exePath); + + strcat(db_fflprPATH, "db_fflpr.db"); + strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); + + strcat(db_facePATH, "db_face.db"); + strcat(db_face_installPATH, "db_face_install_2.db"); + +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR_success == 1) { +#if 0 + char urlBuffer_2[256] = "/set_search_info?clean=log"; + char urlBuffer_3[256] = "/set_search_info?clean=visitor"; + char urlBuffer_4[256] = "/set_search_info?clean=watch"; + char urlBuffer_5[256] = "/set_search_info?clean=vip"; + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_2, strlen(urlBuffer_2)); + firstBuffer[strlen(urlBuffer_2)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_3, strlen(urlBuffer_3)); + firstBuffer[strlen(urlBuffer_3)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); +#endif + pthread_mutex_lock(&mutex_enable_face_db); + CopyFileTo(db_face_installPATH, db_facePATH); + pthread_mutex_unlock(&mutex_enable_face_db); + } +#endif +#if 0 + char urlBuffer_2[256] = "/set_search_info?clean=log"; + char urlBuffer_3[256] = "/set_search_info?clean=customer"; + char urlBuffer_4[256] = "/set_search_info?clean=black"; + char urlBuffer_5[256] = "/set_search_info?clean=white"; + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_2, strlen(urlBuffer_2)); + firstBuffer[strlen(urlBuffer_2)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_3, strlen(urlBuffer_3)); + firstBuffer[strlen(urlBuffer_3)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); +#endif + pthread_mutex_lock(&mutex_enable_lpr_db); + CopyFileTo(db_fflpr_installPATH, db_fflprPATH); + pthread_mutex_unlock(&mutex_enable_lpr_db); + closesocket(cli_socket); + +#ifdef GY_OS_AMBA + usSleep(1000000); +#else + g_check_run_nova_detection = 0; + system("killall -15 nova_driver"); + usSleep(10000000); + + char CONFIG_SMALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_small.json"; + char CONFIG_SMALL_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_small_install.json"; + + if (FileExist(CONFIG_SMALL_JSON_PATH)) { + int del = unlink(CONFIG_SMALL_JSON_PATH); + if (!del) { + //printf("CONFIG_SMALL_JSON_PATH is Deleted successfully."); + } + else { + printf("CONFIG_SMALL_JSON_PATH cannot be Deleted.\n"); + } + } + + CopyFileTo(CONFIG_SMALL_INSTALL_JSON_PATH, CONFIG_SMALL_JSON_PATH); +#endif + + pthread_t auto_build_smart_events_thread_id; + if (pthread_create(&auto_build_smart_events_thread_id, 0, auto_build_smart_events, NULL)) + { + printf("create auto_build_smart_events thread faile \n"); + } + pthread_join(auto_build_smart_events_thread_id, NULL); + + //stop_test_nn_cavalry(); + + printf("\n[---CGICMD DEFAULT---]: reboot to release memory\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot to release memory"); + write_to_logs_html(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #30\n"); + closesocket(cli_socket); + } + } + else if ((strncmp(urlBuffer, "/getconfig?coldobjects=", 23) == 0) || (strncmp(urlBuffer, "/setconfig?coldobjects&", 23) == 0)) + { + //printf("\n[web process]start 22\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); +#endif //_DEBUG_AMBA + CgiCmdType type; + CgiCmdRtnCode rtn; + rtn = _CGICMD_FAIL; + + if (strncmp(urlBuffer, "/getconfig?coldobjects=", 23) == 0) + { + type = _CGICMD_GET; + strcpy(Cmd, urlBuffer + 11); + + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + memset(Cmd_temp, 0x00, sizeof(Cmd_temp)); + strcpy(Cmd_temp, urlBuffer + 23); + + if (strcmp(Cmd_temp, "clean") == 0) { + char COLD_OBJECTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects.json"; + char COLD_OBJECTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects_install.json"; + if (FileExist(COLD_OBJECTS_JSON_PATH)) { + int del = unlink(COLD_OBJECTS_JSON_PATH); + if (!del) { + //printf("cold_objects is Deleted successfully."); + } + else { + printf("COLD_OBJECTS_JSON_PATH cannot be Deleted.\n"); + } + } + CopyFileTo(COLD_OBJECTS_INSTALL_JSON_PATH, COLD_OBJECTS_JSON_PATH); + rtn = _CGICMD_RELOAD; + } + else + rtn = cgicmd_process_cold_objects(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if(strncmp(urlBuffer, "/setconfig?coldobjects&", 23) == 0) + { + strcpy(Cmd, urlBuffer + 23); + + int iSetColdZoneResult = 0; + + if ((int)strlen(Cmd) >= 1) + { + iSetColdZoneResult = SetColdZone(Cmd); + + if (iSetColdZoneResult == 0) + { + WriteColdZoneJsonFile(); + rtn = _CGICMD_RELOAD; + } + else + rtn = _CGICMD_FAIL; + + } + + //if (Cmd) + + /* + printf("\n----------[coldobjects]--------------\n"); + printf("\nx: %d\n", x_coldobject); + printf("\ny: %d\n", y_coldobject); + printf("\nw: %d\n", w_coldobject); + printf("\nh: %d\n", h_coldobject); + printf("\nobject: %s\n", object_coldobject); + printf("\n-------------------------------------\n"); + */ + } + else + rtn = _CGICMD_FAIL; + + + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + memset(msg, 0x00, sizeof(msg)); + printf("\n--------------------reload 2\n"); + + g_write_config_file_dirty_flag = 0; + + write_config(); + + sprintf(msg, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + //sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #31\n"); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/getconfig?detection_zone=", 26) == 0) || (strncmp(urlBuffer, "/setconfig?detection_zone&", 26) == 0)) + { + //printf("\n[web process]start 23\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + CgiCmdType type; + CgiCmdRtnCode rtn; + rtn = _CGICMD_FAIL; + if (strncmp(urlBuffer, "/getconfig?detection_zone=", 26) == 0) + { + type = _CGICMD_GET; + strcpy(Cmd, urlBuffer + 11); + rtn = cgicmd_process_detection_zone(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if (strncmp(urlBuffer, "/setconfig?detection_zone&", 26) == 0) + { + strcpy(Cmd, urlBuffer + 26); + + const char *del = "&"; + const char *del2 = "="; + char data_detection_zone[MAX_DETECTION_ZONE*(MAX_SIZE_POINT *2+1)][STRSPLIT_SIZE]={0}; + int data_detection_zone_num = 0; + + char data_detection_zone_pair[MAX_DETECTION_ZONE*(MAX_SIZE_POINT * 2 + 1)][2][STRSPLIT_SIZE]={0}; + //int data_detection_zone_pair_num[MAX_DETECTION_ZONE*(MAX_SIZE_POINT * 2 + 1)] = { 0 }; + + int zone[MAX_DETECTION_ZONE] = { 0 }; + int x1[MAX_DETECTION_ZONE] = { 0 }; + int y1[MAX_DETECTION_ZONE] = { 0 }; + int x2[MAX_DETECTION_ZONE] = { 0 }; + int y2[MAX_DETECTION_ZONE] = { 0 }; + int x3[MAX_DETECTION_ZONE] = { 0 }; + int y3[MAX_DETECTION_ZONE] = { 0 }; + int x4[MAX_DETECTION_ZONE] = { 0 }; + int y4[MAX_DETECTION_ZONE] = { 0 }; + int x5[MAX_DETECTION_ZONE] = { 0 }; + int y5[MAX_DETECTION_ZONE] = { 0 }; + int x6[MAX_DETECTION_ZONE] = { 0 }; + int y6[MAX_DETECTION_ZONE] = { 0 }; + + if ((int)strlen(Cmd)>=1) + { + data_detection_zone_num = StrSplit(Cmd, data_detection_zone, del); + //printf("\n------UU:26\n"); + int i_temp = -1; + for (int i = 0; i < data_detection_zone_num; i++) + { + printf("\n%s\n", data_detection_zone[i]); + if (data_detection_zone[i]) + { + /*data_detection_zone_pair_num[i] = */StrSplit(data_detection_zone[i], data_detection_zone_pair[i], del2); + //printf("\n------UU:27\n"); + if (strcmp(data_detection_zone_pair[i][0], "zone") == 0 || + strcmp(data_detection_zone_pair[i][0], "Zone") == 0) { + i_temp++; + zone[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + + if (i_temp >= 0) + { + if (strcmp(data_detection_zone_pair[i][0], "x1") == 0 || + strcmp(data_detection_zone_pair[i][0], "X1") == 0) { + x1[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y1") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y1") == 0) { + y1[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x2") == 0 || + strcmp(data_detection_zone_pair[i][0], "X2") == 0) { + x2[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y2") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y2") == 0) { + y2[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x3") == 0 || + strcmp(data_detection_zone_pair[i][0], "X3") == 0) { + x3[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y3") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y3") == 0) { + y3[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x4") == 0 || + strcmp(data_detection_zone_pair[i][0], "X4") == 0) { + x4[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y4") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y4") == 0) { + y4[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x5") == 0 || + strcmp(data_detection_zone_pair[i][0], "X5") == 0) { + x5[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y5") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y5") == 0) { + y5[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x6") == 0 || + strcmp(data_detection_zone_pair[i][0], "X6") == 0) { + x6[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y6") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y6") == 0) { + y6[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + } + } + } + } + /* + printf("\n----------[detection_zone]--------------\n"); + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + printf("\nzone: %d\n", zone[i]); + printf("\nx1: %d\n", x1[i]); + printf("\ny1: %d\n", y1[i]); + printf("\nx2: %d\n", x2[i]); + printf("\ny2: %d\n", y2[i]); + printf("\nx3: %d\n", x3[i]); + printf("\ny3: %d\n", y3[i]); + printf("\nx4: %d\n", x4[i]); + printf("\ny4: %d\n", y4[i]); + printf("\nx5: %d\n", x5[i]); + printf("\ny5: %d\n", y5[i]); + printf("\nx6: %d\n", x6[i]); + printf("\ny6: %d\n", y6[i]); + } + printf("\n-------------------------------------\n"); + */ + + if (data_detection_zone_num == 52 || data_detection_zone_num == 36) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + rtn = _CGICMD_FAIL; + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + + if (fileBuf_config) { + free(fileBuf_config); + fileBuf_config = NULL; + } + + if (root == NULL) + { + printf("root_config is NULL\n"); + rtn = _CGICMD_FAIL; + } + else + { + cJSON *view_setting, *camera01, *temp_detection_zone, *detect; + + view_setting = cJSON_GetObjectItem(root, "view_setting"); + camera01 = cJSON_GetObjectItem(view_setting, "camera01"); + temp_detection_zone = cJSON_GetObjectItem(camera01, "detection_zone"); + + int i = 0; + cJSON_ArrayForEach(detect, temp_detection_zone) + { + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + if ((i + 1) == zone[j]) + { + cJSON_ReplaceItemInObject(detect, "x1", cJSON_CreateNumber(x1[j])); + cJSON_ReplaceItemInObject(detect, "y1", cJSON_CreateNumber(y1[j])); + cJSON_ReplaceItemInObject(detect, "x2", cJSON_CreateNumber(x2[j])); + cJSON_ReplaceItemInObject(detect, "y2", cJSON_CreateNumber(y2[j])); + cJSON_ReplaceItemInObject(detect, "x3", cJSON_CreateNumber(x3[j])); + cJSON_ReplaceItemInObject(detect, "y3", cJSON_CreateNumber(y3[j])); + cJSON_ReplaceItemInObject(detect, "x4", cJSON_CreateNumber(x4[j])); + cJSON_ReplaceItemInObject(detect, "y4", cJSON_CreateNumber(y4[j])); + + if (data_detection_zone_num == 52) { + cJSON_ReplaceItemInObject(detect, "x5", cJSON_CreateNumber(x5[j])); + cJSON_ReplaceItemInObject(detect, "y5", cJSON_CreateNumber(y5[j])); + cJSON_ReplaceItemInObject(detect, "x6", cJSON_CreateNumber(x6[j])); + cJSON_ReplaceItemInObject(detect, "y6", cJSON_CreateNumber(y6[j])); + } + else { + cJSON_ReplaceItemInObject(detect, "x5", cJSON_CreateNumber(0)); + cJSON_ReplaceItemInObject(detect, "y5", cJSON_CreateNumber(0)); + cJSON_ReplaceItemInObject(detect, "x6", cJSON_CreateNumber(0)); + cJSON_ReplaceItemInObject(detect, "y6", cJSON_CreateNumber(0)); + } + } + } + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + rtn = _CGICMD_SUCCESS; + printf("\n--------------------reload 3\n"); + reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open config.json \n"); + rtn = _CGICMD_FAIL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + else + { + printf("Fail detection_zone numbers (data_detection_zone_num: %d)\n", data_detection_zone_num); + rtn = _CGICMD_FAIL; + } + } + else + rtn = _CGICMD_FAIL; + + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_SUCCESS) + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + //sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #31\n"); + closesocket(cli_socket); + } +#if 0 + else if (strncmp(urlBuffer, "/get_jsonclassid=", 17) == 0) + { + memset(msg, 0x00, sizeof(msg)); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + strcpy(Cmd, urlBuffer + 17); + + get_classname(atoi(Cmd), msg); + + strcpy(beforeSendBuffer, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-123\n"); + + closesocket(cli_socket); + + } +#endif + else if (strncmp(urlBuffer, "/get_cloud_statue", 17) == 0) + { + strcpy(beforeSendBuffer, ""); + strcat(beforeSendBuffer, SystemSetting.cloud_statue); + strcat(beforeSendBuffer, ",,,"); + strcat(beforeSendBuffer, SystemSetting.cloud_v2_statue); + strcat(beforeSendBuffer, ",,,"); + strcat(beforeSendBuffer, SystemSetting.cloud_record_v2_statue); + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-122\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/do_cloud_v2_statue", 19) == 0) + { + if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0) + { + //for (int count_delay = 0; count_delay < 5; count_delay++) + if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) + { + //if (QueueSize(_GETALARMMOTION) < 1) + { + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "cloud_v2"); + + if (strlen(SystemSetting.cloud_v2_content) >= 1) { + strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); + } + else + q_info.cloud_v2_aiengine[0] = '\0'; + + //strcpy(SystemSetting.cloud_v2_statue, ""); + + pthread_mutex_lock(&mutex_getalarmmotion); + QueuePush(q_info, _GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + //break; + } + //usSleep(100000); + } + } + + strcpy(beforeSendBuffer,""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-1231\n"); + + } +#if 0 + else if (strncmp(urlBuffer, "/do_cloud_record_v2_statue", 26) == 0) + { + if (strcmp(SystemSetting.enable_cloud_record_v2, "Yes") == 0) + { + //for (int count_delay = 0; count_delay < 5; count_delay++) + if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) + { + //if (QueueSize(_GETALARMMOTION) < 1) + { + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "cloud_record_v2"); + + if (strlen(SystemSetting.cloud_record_v2_content) >= 1) { + strcpy(q_info.record_cloud_v2_aiengine, SystemSetting.cloud_record_v2_content); + } + else + q_info.record_cloud_v2_aiengine[0] = '\0'; + + //strcpy(SystemSetting.cloud_record_v2_statue, ""); + pthread_mutex_lock(&mutex_getalarmmotion); + QueuePush(q_info, _GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + //break; + } + //usSleep(100000); + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-12312\n"); + + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/ptzcontrol?enable_ptz=Yes", 26) == 0) + { + memset(msg, 0x00, sizeof(msg)); + + if (IsPTZ() == 1) + { + //UpdatePTZIPcamSetting(); + + int iHomePreset = GetHomePreset(); + + if (iHomePreset >= 0 && iHomePreset <= 256) + { + if (IsPTZatHomePos() != 1) + { + GoPreset(iHomePreset); + } + + StartStopAutopan(1); + + /*int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + strcpy(viewChannelData[0].ptz_enable_tracking, "Yes"); + write_to_enable_tracking("Yes"); + + /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, + viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + UpdatePTZConfigSetting(); + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + + //if (viewChannelData[0].ptz_tracking_resume_dwell) + //SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + //else + //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); + + //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); + //StartPTZtrackingThread(); + + sprintf(msg, "Start PTZ success."); + } + else + { + sprintf(msg, "Please setup the camera at Home position and click Start button."); + } + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/ptzcontrol?enable_ptz=No", 25) == 0) + { + memset(msg, 0x00, sizeof(msg)); + + if (IsPTZ() == 1) + { + StartStopAutopan(0); + + /*int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + strcpy(viewChannelData[0].ptz_enable_tracking, "No"); + write_to_enable_tracking("No"); + + /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, + viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + UpdatePTZConfigSetting(); + + //StopPTZtrackingThread(); + + sprintf(msg, "Stop PTZ success."); + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/ptzcontrol?go_preset=", 22) == 0) + { + if (IsPTZ() == 1) + { + //Stop PTZ + StopPtz(); + + //Go Preset + char sPresetNumber[10] = { 0 }; + memset(sPresetNumber, 0x00, sizeof(sPresetNumber)); + strcpy(sPresetNumber, urlBuffer + 22); + + int iPreset_number = 0; + if (strlen(sPresetNumber) > 0) + iPreset_number = atoi(sPresetNumber); + + GoPreset(iPreset_number); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "This device is not support PTZ."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + } + else if (strncmp(urlBuffer, "/ptzcontrol?set&zone=", 21) == 0) + { + if (IsPTZ() == 1) + { + //Stop PTZ + StopPtz(); + + //Go Preset + char sZone[10] = { 0 }; + memset(sZone, 0x00, sizeof(sZone)); + strncpy(sZone, urlBuffer + 21,1); + + int index_zone = -1; + if (strlen(sZone) > 0) + index_zone = atoi(sZone); + + if (index_zone >= 0) { + ///ptzcontrol?set&zone=0&preset=1 + char sPreset[10] = { 0 }; + memset(sPreset, 0x00, sizeof(sPreset)); + strcpy(sPreset, urlBuffer + 30); + + int iPreset_number = -1; + if (strlen(sPreset) > 0) + iPreset_number = atoi(sPreset); + + if (iPreset_number >= 0) { + + g_check_if_change_preset = 1; + + strcpy(viewDetectionZone[0][index_zone].ptz_zone_to_preset, sPreset); + + /* + int zone_to_preset[4]; + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + //strcpy(viewChannelData[0].ptz_enable_tracking, "No"); + //write_to_enable_tracking("No"); + + UpdatePTZConfigSetting(); + /* + UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, + viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + GoPreset(iPreset_number); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "This device is not support PTZ."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/get_simulated_plate?lpr=", 25) == 0) + { + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + memset(Cmd_temp, 0x00, sizeof(Cmd_temp)); + strcpy(Cmd_temp, urlBuffer + 25); + + if (strlen(Cmd_temp) >= 1) { + + int total_element_size_temp = 1; + detection_pos PosInfo_temp[MAX_DETECT_OBJECTS] = { 0 }; + int index_pos = 0; + detection_pos *pNext_temp; + pNext_temp = PosInfo_temp + index_pos; + strcpy(pNext_temp->name, "L._Plate_TWN"); + pNext_temp->left_x = 200; + pNext_temp->top_y = 200; + pNext_temp->width = 600; + pNext_temp->height = 300; + pNext_temp->center_x = pNext_temp->left_x + pNext_temp->width / 2; + pNext_temp->center_y = pNext_temp->top_y + pNext_temp->height / 2; + pNext_temp->box_x = pNext_temp->left_x; + pNext_temp->box_y = pNext_temp->top_y; + pNext_temp->box_w = pNext_temp->width; + pNext_temp->box_h = pNext_temp->height; + pNext_temp->confidence = 100.0; + pNext_temp->engine_type = FEATURE_LPR_TWN;//layerFeatureType[layer_idx]; + pNext_temp->engine_type2 = FEATURE_LPR_TWN; + pNext_temp->parent_idx = -1; + pNext_temp->car_logo_idx = -1; + pNext_temp->number_row = 1; + pNext_temp->class_id = 0; + + pNext_temp->obj_type = _PLATE; + pNext_temp->test_id = 0; + pNext_temp->image_id = 0; + + //printf("\n--------Cmd_temp:%s\n", Cmd_temp); + + strcpy(pNext_temp->properties.plate, Cmd_temp); + ReplacePlateWithDB(PosInfo_temp, total_element_size_temp, featureType, tracking_channel_idx); + AddTWPlateDASH(PosInfo_temp, total_element_size_temp, featureType); + PlateFilterForParkingPlot(PosInfo_temp, total_element_size_temp, featureType, tracking_channel_idx); + //printf("\n--------pNext_temp->properties.plate:%s\n", pNext_temp->properties.plate); + + //for (int index_temp = 0; index_temp < total_element_size_temp; index_temp++) + { + int index_temp = 0; + pNext_temp = PosInfo_temp + index_temp; + //printf("\n%d plate name = %s\n", index_temp, pNext_temp->properties.plate); + sprintf(beforeSendBuffer_xtra,"LPR:%s,confidence:%d\n", pNext_temp->properties.plate, (int)pNext_temp->confidence); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3212\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getconfig?", 11) == 0) || (strncmp(urlBuffer, "/setconfig?", 11) == 0)) + { + pthread_mutex_lock(&mutex_config_json); + + //printf("\n[web process]start 24\n"); + char Cmd[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd, urlBuffer + 11); + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket,Cmd,(int)strlen(Cmd)); + #endif //_DEBUG_AMBA + CgiCmdType type; + if (strncmp(urlBuffer, "/getconfig?", 11) == 0) { + type = _CGICMD_GET; + //printf("\n[web process]start 24-2\n"); +#if 0 + GetAidaPort(); +#endif + //printf("\n[web process]start 24-2-2\n"); + + //strcpy(accountData[0].account_aida_port, "8592"); + + if(strlen(accountData[0].account_aida_port)>= 1) + strcpy(aida_port_for_cgicmd,accountData[0].account_aida_port); + if (strlen(accountData[0].account_username) >= 1) + strcpy(aida_username_for_cgicmd, accountData[0].account_username); + //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); + strcpy(aida_device_name_for_cgicmd, g_device_name); + //printf("\n[web process]start 24-3\n"); + } + else { + type = _CGICMD_SET; // /setconfig? + check_if_correct_post = 0; + } + CgiCmdRtnCode rtn = cgicmd_process(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //CgiCmdRtnCode rtn = _CGICMD_SUCCESS; + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn, beforeSendBuffer_xtra); + if (rtn == _CGICMD_RELOAD) + { + + g_write_config_file_dirty_flag = 0; + + write_config(); + + //usSleep(1000000); + printf("\n--------------------reload 4\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + + //printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + else if (rtn == _CGICMD_SUCCESS) + { + //printf("\nhellllo\n"); + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg_temp, "Success."); + //printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + //printf("\nhellllo2\n"); + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + pthread_mutex_unlock(&mutex_config_json); + closesocket(cli_socket); + //printf("\nhellllo3\n"); + + + + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/python?getfilelist=all", 23) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char sFileList[60000] = { 0 }; + + readFolderList(sFileList); + + strcpy(beforeSendBuffer_xtra, sFileList); + printf("sFileList: %s\n", sFileList); + } + else { + strcpy(beforeSendBuffer_xtra, ""); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythonget?file=", strlen("/pythonget?file=")) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char Cmd[512] = { 0 }; + char sOutput[10240]; + strcpy(Cmd, urlBuffer + 16); + + printf("get file name = %s \n", Cmd); + + readPythonFile(Cmd, sOutput); + // printf("\nfile!!!\n"); + + // 2024-09-26 switch py or refresh web need to clear buffer + for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) + { + memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); + } + // 2024-09-26 switch py or refresh web need to reset index + g_uiWebPythonCurrentBufferIndex = 0; + g_uiWebPythonLastBufferIndex = 0; + + strcpy(beforeSendBuffer_xtra, sOutput); + } + else { + + strcpy(beforeSendBuffer_xtra, ""); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythonupload?", strlen("/pythonupload?")) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + + char Cmd[PYTHON_CODE_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + strlen("/pythonupload?")); + // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 + + printf("Uploading...\n"); + char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; + urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); + strcpy(beforeSendBuffer_xtra, uploadPython(decodeCMD)); + + } + else { + strcpy(beforeSendBuffer_xtra, ""); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) { + printf("\nsend error #3552\n"); + } + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythonsave?", strlen("/pythonsave")) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + + char Cmd[PYTHON_CODE_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + strlen("/pythonsave?")); + // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 + + printf("Saving...\n"); + char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; + urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); + strcpy(beforeSendBuffer_xtra, SavePython(decodeCMD)); + + } + else { + strcpy(beforeSendBuffer_xtra, "Save python file failed !!"); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) { + printf("\nsend error #3552\n"); + } + + closesocket(cli_socket); + } + + else if (strncmp(urlBuffer, "/pythondelete?file=", 19) == 0) + { + char DeleteMessage_xtra[BUFSIZE] = { 0 }; + char SendDeleteStatus[BUFSIZE] = {0}; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char Cmd[512] = { 0 }; + strcpy(Cmd, urlBuffer + 14); + + printf("cmd = %s \n", Cmd); + + strcpy(Cmd, urlBuffer + 19); + + printf("get file name = %s \n", Cmd); + + deletePythonFile(Cmd); + if (g_cWebPythonDeleteStatus == 1) + { + sprintf(SendDeleteStatus, "%s was deleted successfully.",Cmd); + } + else + { + sprintf(SendDeleteStatus, "Failed to delete %s.",Cmd); + } + + } + else { + sprintf(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + int sendBufferSize = SetHttpResponse(DeleteMessage_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendDeleteStatus), SendDeleteStatus); + if (send(cli_socket, DeleteMessage_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(SendDeleteStatus, 0, sizeof(SendDeleteStatus)); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/python?playfile=", 17) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char Cmd[512] = { 0 }; + strcpy(Cmd, urlBuffer + 17); + + printf("cmd = %s \n", Cmd); + } + else { + strcpy(beforeSendBuffer_xtra, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + //strcpy(beforeSendBuffer_xtra, sFileList); + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/getconfigfile?ch=all", 21) == 0) + { + pthread_mutex_lock(&mutex_config_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + //char filename[] = config_bakPATH; + char *filename = configPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/getconfigfile?ch=all", 21) == 0) { + //type = _CGICMD_GET; + + cJSON *view_setting, *system_setting; + view_setting = cJSON_GetObjectItem(root, "view_setting"); + system_setting = cJSON_GetObjectItem(root, "system_setting"); + + char *JsonString_view_setting = cJSON_PrintUnformatted(view_setting); + char *JsonString_system_setting = cJSON_PrintUnformatted(system_setting); + + if (JsonString_view_setting != NULL && JsonString_system_setting != NULL) { + + //printf("\n-------JsonString_view_setting:%s\n", JsonString_view_setting); + + if (strlen(accountData[0].account_aida_port) >= 1) + strcpy(aida_port_for_cgicmd, accountData[0].account_aida_port); + if (strlen(accountData[0].account_username) >= 1) + strcpy(aida_username_for_cgicmd, accountData[0].account_username); + //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); + strcpy(aida_device_name_for_cgicmd, g_device_name); + + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"127.0.0.1"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"127.0.0.1", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"username\":\"guest\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"username\":\"guest\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"password\":\"GP12345\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"password\":\"GP12345\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"channel_id\":\"\""); + if (loc != NULL) { + char temp[256] = "\"channel_id\":\"0\""; + char *temp2 = StrReplace(JsonString_view_setting, "\"channel_id\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"camera_name\":\"\""); + if (loc != NULL) { + char temp[1024] = { 0 }; + sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "\"camera_name\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"47.176.29.11"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"47.176.29.11", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "http_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "http_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + + } + } + + { + char *loc = strstr(JsonString_view_setting, "video_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "video_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + strcpy(beforeSendBuffer_xtra, "{\"view_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_view_setting); + strcat(beforeSendBuffer_xtra, ",\"system_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_system_setting); + strcat(beforeSendBuffer_xtra, ",\"g_check_if_get_picture_not_OK\":"); + char temp_picture[10] = { 0 }; + sprintf(temp_picture, "%d", g_check_if_get_picture_not_OK); + strcat(beforeSendBuffer_xtra, temp_picture); + strcat(beforeSendBuffer_xtra, ",\"g_check_h264_gop\":"); + char temp_gop[10] = { 0 }; + sprintf(temp_gop, "%d", g_check_h264_gop); + strcat(beforeSendBuffer_xtra, temp_gop); + strcat(beforeSendBuffer_xtra, "}"); + } + + if (JsonString_view_setting) { + free(JsonString_view_setting); + JsonString_view_setting = NULL; + } + if (JsonString_system_setting) { + free(JsonString_system_setting); + JsonString_system_setting = NULL; + } + + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + pthread_mutex_unlock(&mutex_config_json); + closesocket(cli_socket); + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/getjvcconfigfile?ch=all", 24) == 0) + { + pthread_mutex_lock(&mutex_config_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "jvc_config.json"); + + //char filename[] = config_bakPATH; + char *filename = configPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/getjvcconfigfile?ch=all", 24) == 0) { + //type = _CGICMD_GET; + + cJSON *view_setting, *system_setting; + view_setting = cJSON_GetObjectItem(root, "view_setting"); + system_setting = cJSON_GetObjectItem(root, "system_setting"); + + char *JsonString_view_setting = cJSON_PrintUnformatted(view_setting); + char *JsonString_system_setting = cJSON_PrintUnformatted(system_setting); + + if (JsonString_view_setting != NULL && JsonString_system_setting != NULL) { + + //printf("\n-------JsonString_view_setting:%s\n", JsonString_view_setting); + + if (strlen(accountData[0].account_aida_port) >= 1) + strcpy(aida_port_for_cgicmd, accountData[0].account_aida_port); + if (strlen(accountData[0].account_username) >= 1) + strcpy(aida_username_for_cgicmd, accountData[0].account_username); + //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); + strcpy(aida_device_name_for_cgicmd, g_device_name); + + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"127.0.0.1"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"127.0.0.1", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"username\":\"guest\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"username\":\"guest\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"password\":\"GP12345\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"password\":\"GP12345\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"channel_id\":\"\""); + if (loc != NULL) { + char temp[256] = "\"channel_id\":\"0\""; + char *temp2 = StrReplace(JsonString_view_setting, "\"channel_id\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"camera_name\":\"\""); + if (loc != NULL) { + char temp[1024] = { 0 }; + sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "\"camera_name\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"47.176.29.11"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"47.176.29.11", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "http_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "http_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + + } + } + + { + char *loc = strstr(JsonString_view_setting, "video_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "video_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + strcpy(beforeSendBuffer_xtra, "{\"view_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_view_setting); + strcat(beforeSendBuffer_xtra, ",\"system_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_system_setting); + strcat(beforeSendBuffer_xtra, ",\"g_check_if_get_picture_not_OK\":"); + char temp_picture[10] = { 0 }; + sprintf(temp_picture, "%d", g_check_if_get_picture_not_OK); + strcat(beforeSendBuffer_xtra, temp_picture); + strcat(beforeSendBuffer_xtra, "}"); + } + + if (JsonString_view_setting) { + free(JsonString_view_setting); + JsonString_view_setting = NULL; + } + if (JsonString_system_setting) { + free(JsonString_system_setting); + JsonString_system_setting = NULL; + } + + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + pthread_mutex_unlock(&mutex_config_json); + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/getemailsfile", strlen("/getemailsfile")) == 0) { + + if (strlen(IPCAMService.auth_password) >= 8) { + strcpy(beforeSendBuffer, "1"); + } + else { + strcpy(beforeSendBuffer, "0"); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("send(Not get emails file)"); + closesocket(cli_socket); + } +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/setosd?", 8) == 0) + { + gettimeofday(&currtime_setosd, NULL); + long current_ms_setosd = (currtime_setosd.tv_sec * 1000) + (currtime_setosd.tv_usec / 1000); + + //pthread_mutex_lock(&mutex_events_json); + char Cmd[8192] = { 0 }; + strcpy(Cmd, urlBuffer + 8); + char msg[256] = { 0 }; + + if (last_ms_setosd == 0 || current_ms_setosd >= last_ms_setosd + 20) { + if (strlen(Cmd) >= 1) { + + const char *del = "&"; + char a_data_osd[MAX_SIZE_A_OSD_OBJECT][STRSPLIT_SIZE]={0}; + int a_data_osd_num = 0; + + const char *del2 = "="; + char a_data_osd_pair[MAX_SIZE_A_OSD_OBJECT][2][STRSPLIT_SIZE]={0}; + + int id_osd = -1; //1 + int x_osd = -1; //2 + int y_osd = -1; //3 + int w_osd = -1; //4 + int h_osd = -1; //5 + int color_osd = -1; //6 + int size_osd = -1; //7 + int sec_osd = -1; //8 + char text_osd[256] = { 0 }; //9 + + int bg_transparency = 0; //10 0~255 + int outline_sw = 0; //11 0:off 1:on + + + a_data_osd_num = StrSplit(Cmd, a_data_osd, del); + //printf("\n------UU:28\n"); + if (a_data_osd_num == MAX_SIZE_A_OSD_OBJECT) + { + for (int i = 0; i < a_data_osd_num; i++) + { + if (a_data_osd[i]) + { + //printf("\n%s\n", a_data_osd[i]); + StrSplit(a_data_osd[i], a_data_osd_pair[i], del2); + //printf("\n------UU:29\n"); + if (strlen(a_data_osd_pair[i][0]) >= 1 && strlen(a_data_osd_pair[i][1]) >= 1) { + + if (strcmp(a_data_osd_pair[i][0], "id") == 0 || + strcmp(a_data_osd_pair[i][0], "ID") == 0) { + id_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "x") == 0 || + strcmp(a_data_osd_pair[i][0], "X") == 0) { + x_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "y") == 0 || + strcmp(a_data_osd_pair[i][0], "Y") == 0) { + y_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "w") == 0 || + strcmp(a_data_osd_pair[i][0], "W") == 0) { + w_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "h") == 0 || + strcmp(a_data_osd_pair[i][0], "H") == 0) { + h_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "color") == 0 || + strcmp(a_data_osd_pair[i][0], "Color") == 0) { + color_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "size") == 0 || + strcmp(a_data_osd_pair[i][0], "Size") == 0) { + size_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "ms") == 0) { + sec_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "bg") == 0) { + bg_transparency = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "outline") == 0) { + outline_sw = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "text") == 0 || + strcmp(a_data_osd_pair[i][0], "Text") == 0) { + strcpy(text_osd, a_data_osd_pair[i][1]); + url_decode(text_osd, strlen(text_osd)); + } + } + } + } + + if (bg_transparency < 0) + bg_transparency = 0; + else if (bg_transparency > 255) + bg_transparency = 255; + + if (outline_sw > 0) + outline_sw = 1; + if (outline_sw < 0) + outline_sw = 0; + + int check_if_osd_ok = 1; + + int num_width = -1; + int num_height = -1; + //int max_length_text = -1; + + if (w_osd >= 1 && size_osd >= 1) + num_width = w_osd / size_osd; + if (h_osd >= 1 && size_osd >= 1) + num_height = h_osd / (size_osd * 2); + + /* + if (num_width >= 1 && num_height >= 1) + max_length_text = num_width * 4; + */ + int num_br = 0; + int check_if_line_too_long = 0; + int isTextEmpty = 0; + if (strstr(text_osd, "empty") != NULL) + { + isTextEmpty = 1; + } + + if (strlen(text_osd) >= 1 + && isTextEmpty == 0) { + //printf("=====> AAAAA \n"); + num_br = strstr_cnt(text_osd, "<BR>"); + + char temp_osd_text[256] = { 0 }; + strcpy(temp_osd_text, text_osd); + + char *p_osd; + char *read_point; + read_point = text_osd; + char current_osd_text[256] = { 0 }; + + for (int index_line = 0; index_line < 4; index_line++) { + + p_osd = strstr(read_point, "<BR>"); + + if (p_osd) { + memset(current_osd_text, 0x00, sizeof(current_osd_text)); + strncpy(current_osd_text, read_point, p_osd - read_point); + if (strlen(current_osd_text) >= 30 || strlen(current_osd_text) >= num_width + 1) { + check_if_line_too_long = 1; + break; + } + p_osd += 4; + read_point = p_osd; + + //strcpy(temp_osd_text, p_osd + 4); + } + else { + //memset(current_osd_text, 0x00, sizeof(current_osd_text)); + //strncpy(current_osd_text, read_point, strlen(read_point)); + + //if (strlen(temp_osd_text) >= 30 || strlen(temp_osd_text) >= num_width + 2) + if (strlen(read_point) >= 30 || strlen(read_point) >= num_width + 1) + { + check_if_line_too_long = 1; + } + break; + } + } + + //printf("get cgi osd info: \n %d, %d, %d, %d, %d, %d, %d, %d, %d \n", id_osd, x_osd, y_osd, w_osd, h_osd, color_osd, size_osd, sec_osd, strlen(text_osd)); + //printf("----------------------------------%d, %d \n", bg_transparency, outline_sw); + + if (id_osd == -1 || x_osd == -1 || y_osd == -1 || w_osd == -1 || h_osd == -1 || color_osd == -1 || size_osd == -1 || sec_osd == -1 || strlen(text_osd) == 0) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: Parameter"); + } + else if (x_osd <= 1 || x_osd >= SCALE_BOUNDING_BOX_WIDTH) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: x <= 1 || x >= 1920"); + } + else if (y_osd <= 1 || y_osd >= SCALE_BOUNDING_BOX_HEIGHT) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: y <= 1 || y >= 1080"); + } + else if (w_osd <= 1 || w_osd >= SCALE_BOUNDING_BOX_WIDTH || x_osd + w_osd >= SCALE_BOUNDING_BOX_WIDTH) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: w <= 1 || w >= 1920 || x + w >= 1920"); + } + else if (h_osd <= 1 || h_osd >= SCALE_BOUNDING_BOX_HEIGHT || y_osd + h_osd >= SCALE_BOUNDING_BOX_HEIGHT) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: h <= 1 || h >= 1080 || y + h >= 1080"); + } + else if (size_osd <= 9 || size_osd >= 51) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: size <= 25 || size >= 51"); + } + //else if (strlen(text_osd) <= 0 || strlen(text_osd) >= 100 || strlen(text_osd) >= max_length_text) { + // check_if_osd_ok = 0; + // strcpy(msg, "HTTP 200 OK, content: Error: strlen(text) <= 0 || strlen(text) >= 100 || strlen(text) >= w / size * 4"); + //} + else if (strlen(text_osd) >= 1 && (num_br >= 4 || num_height < (num_br + 2))) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: The number of BR >= 4 || (h / (font size * 2)) < (The number of row + 1)"); + } + else if (check_if_line_too_long == 1) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: The text line is too long (>= 30 || >= ((w / size) + 2)). Please use newline label BR."); + } + else if (num_width <= 4 || num_height <= 1 || w_osd * h_osd > 644253) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: w / size <= 4 || h / (size * 2) <= 1 || w * h > 644253"); + } + else if (sec_osd <= 0 || sec_osd >= 60000) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: ms <= 0 || ms >= 60000"); + } + else if (id_osd < 0 || id_osd >= 12) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: id_osd < 0 || id_osd >= 12"); + } + } + else if (isTextEmpty == 1) + { + //printf("=====> bbbbb \n"); + //strncpy(current_osd_text, " ", 1); + sprintf(text_osd, "%s", ""); + //sprintf(text_osd, "%s", "TESTabc123"); + } + + if (check_if_osd_ok == 1 && color_osd >= 0) { + //for (int i = 0 ; i < MAX_SIZE_OSD_ARRAY ; i++) + int i = id_osd; + if (i >= 0 && i < MAX_SIZE_OSD_ARRAY) + { + if (OSDData[i].flag_protected == 0) { + OSDData[i].id = id_osd; + OSDData[i].x = x_osd; + OSDData[i].y = y_osd; + OSDData[i].w = w_osd; + OSDData[i].h = h_osd; + OSDData[i].color = color_osd; + OSDData[i].size = size_osd; + OSDData[i].show_sec = sec_osd; + OSDData[i].bg_tran = bg_transparency; + OSDData[i].outline_sw = outline_sw; + strcpy(OSDData[i].text, text_osd); + OSDData[i].flag_protected = 1; + + //printf("----------------------------------%d, %d \n", OSDData[i].bg_tran, OSDData[i].outline_sw); + + /* + printf("\n[x,y,w,h,color,size,sec,text]:[%d,%d,%d,%d,%d,%d,%d,%s]\n", + OSDData[i].x, OSDData[i].y, OSDData[i].w, OSDData[i].h, + OSDData[i].color, OSDData[i].size, OSDData[i].sec, OSDData[i].text); + */ + strcpy(msg, "HTTP 200 OK, content: OK"); + //break; + } + } + } + } + } + + if (strlen(msg) == 0) { + strcpy(msg, "HTTP 200 OK, content: Error: Format"); + } + last_ms_setosd = current_ms_setosd; + } + else { + strcpy(msg, "HTTP 200 OK, content: Error: Busy"); + } + + strcpy(beforeSendBuffer_xtra, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + //pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/setosdtime?", 12) == 0) + { + char msg[256] = { 0 }; + + //printf("-----------------------------------\n-------------------------------------\n"); + update_system_time(); + + #if 1 + // /setosdtime?osdtime=1 + char Cmd[8192] = { 0 }; + const char *del2 = "="; + char a_data_osd_pair[1][2][STRSPLIT_SIZE]={0}; + strcpy(Cmd, urlBuffer + 12); + + if (strstr(Cmd, "osdtime=") != NULL) + { + StrSplit(Cmd, a_data_osd_pair[0], del2); + //printf("\n------UU:30\n"); + if (strlen(a_data_osd_pair[0][1]) > 0) + { + //12 0:off 1:left-top, 2:mid-top, 3:right-top, 4:left_bottom, 5:mid_bottom, 6:right:bottom + g_osdTime_sw = atoi(a_data_osd_pair[0][1]); + if (g_osdTime_sw < 0) { + g_osdTime_sw = 0; + strcpy(msg,"Please set g_osdTime_sw to 0-6."); + } + else if (g_osdTime_sw > 6) { + g_osdTime_sw = 4; //default left_bottom + strcpy(msg, "Please set g_osdTime_sw to 0-6."); + } + else { + strcpy(msg, "OK"); + } + } + else { + g_osdTime_sw = 0; + } + } + #endif + + if (strlen(msg) == 0) { + strcpy(msg,"Wrong format."); + } + + strcpy(beforeSendBuffer_xtra, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3222\n"); + + //pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/geteventsfile?ch=all", 21) == 0) + { + pthread_mutex_lock(&mutex_events_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char eventsPATH[1024] = { 0 }; + strcpy(eventsPATH, exePath); + strcat(eventsPATH, "events.json"); + + //char filename[] = config_bakPATH; + char *filename = eventsPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/geteventsfile?ch=all", 21) == 0) { + //type = _CGICMD_GET; + char *JsonString = cJSON_PrintUnformatted(root); + if (JsonString != NULL) { + strcpy(beforeSendBuffer_xtra, JsonString); + free(JsonString); + JsonString = NULL; + } + } + /* + else { + type = _CGICMD_SET; // /setconfig? + strcpy(beforeSendBuffer_xtra, Cmd); + }*/ + cJSON_Delete(root); + root = NULL; + } + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/geteventscustom?num=", 21) == 0) + { + pthread_mutex_lock(&mutex_events_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + int default_version = 0; + + { + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 21); + + int check_if_not_digit = 0; + for (int index_cmd = 0; index_cmd < strlen(Cmd_temp); index_cmd++) + { + if (!isdigit(Cmd_temp[index_cmd])) + { + check_if_not_digit = 1; + break; + } + } + if (strlen(Cmd_temp) == 0) { + check_if_not_digit = 1; + } + + if (check_if_not_digit == 0) { + default_version = atoi(Cmd_temp); + } + } + + if (default_version >= 1 && default_version != 3) { + + char eventsPATH[1024] = { 0 }; + sprintf(eventsPATH,"%sevents_custom_%d.json", exePath, default_version); + + //char filename[] = config_bakPATH; + char *filename = eventsPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/geteventscustom?num=", 21) == 0) { + //type = _CGICMD_GET; + char *JsonString = cJSON_PrintUnformatted(root); + if (JsonString != NULL) { + strcpy(beforeSendBuffer_xtra, JsonString); + free(JsonString); + JsonString = NULL; + } + } + /* + else { + type = _CGICMD_SET; // /setconfig? + strcpy(beforeSendBuffer_xtra, Cmd); + }*/ + cJSON_Delete(root); + root = NULL; + } + } + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #326\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif + // ======================================================================================== + else if ((strncmp(urlBuffer, "/getconfig?radar_position=", 26) == 0) || (strncmp(urlBuffer, "/setconfig?radar_position&", 26) == 0)) + { + } + else if ((strncmp(urlBuffer, "/getconfig?ptz_position=", 24) == 0) || (strncmp(urlBuffer, "/setconfig?ptz_position&", 24) == 0)) + { // ?i?H???U?????g + } +#if 0 + else if ((strncmp(urlBuffer, "/setradarconfig?default", 23) == 0)) + { + pthread_mutex_lock(&mutex_radar_json); + char RADAR_JSON_PATH[1024] = "/emmc/plugin/Aida_data/radar.json"; + char RADAR_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/radar_bak.json"; + + CopyFileTo(RADAR_BAK_JSON_PATH, RADAR_JSON_PATH); + + pthread_mutex_unlock(&mutex_radar_json); + update_radar_json(); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/setradarconfig?ch=1&", 21) == 0)) + { + //@TODO: cola 2022/02/23 save radar config + // kuan 2022/05/17 + pthread_mutex_lock(&mutex_radar_json); + char buf[1024] = {}; + char Cmd[8192] = {0}; + //char msg_temp[512] = {0}; + CgiCmdRtnCode rtn; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + // printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + // printf("exePath:%s\n", exePath); + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "radar.json"); + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + rtn = _CGICMD_FAIL; + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) + { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + if (fileBuf_config) + { + free(fileBuf_config); + fileBuf_config = NULL; + } + if (root == NULL) + { + printf("root_config is NULL\n"); + rtn = _CGICMD_FAIL; + } + else + { // ?g?J radar.html ???n?s?^ json ????? + strcpy(Cmd, urlBuffer + 21); + const char *del = "="; + const char *del2 = "\n"; + char name[50][STRSPLIT_SIZE]={0}; + int value = 0; + char value2[50][STRSPLIT_SIZE]={0}; + StrSplit(Cmd, name, del); // segmentation fault function work well, the reason may be the input data + //printf("\n------UU:31\n"); + cJSON *camera; + // if (*name == "enable_calibration_radar") + //{ + // printf("get enable_calibration_radar\n"); + // } + if (!(camera = cJSON_GetObjectItem(root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + } + + if (strcmp(*name, "trial_life_time") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "trial_life_time", cJSON_CreateNumber(value)); + // printf("setting radar.json trial_life_time = %d \n", value); + } + else if (strcmp(*name, "calibration_camera") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "calibration_camera", cJSON_CreateBool(inbool)); + // printf("setting radar.json calibration_camera = %d \n", inbool); + } + //@TODO cola....finish all setting + // kuan + else if (strcmp(*name, "enable_calibration_radar") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "enable_calibration_radar", cJSON_CreateBool(inbool)); + // printf("setting radar.jsonenable_calibration_radar = %d \n", inbool); + } + else if (strcmp(*name, "calibration_radar") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "calibration_radar", cJSON_CreateBool(inbool)); + // printf("setting radar.json calibration_radar = %d \n", inbool); + } + else if (strcmp(*name, "enable_camera") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_camera", cJSON_CreateBool(inbool)); + json_enable_camera_p = inbool; + // printf("setting radar.json enable_camera = %d \n", inbool); + } + else if (strcmp(*name, "world_radar_height") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "world_radar_height", cJSON_CreateNumber(value)); + // printf("setting radar.json world_radar_height = %d \n", value); + } + else if (strcmp(*name, "distance_meter") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "distance_meter", cJSON_CreateNumber(value)); + // json_distance_meter = value; // leo 09-28 + json_distance_meter_p = value; // leo 11-25 + // printf("setting radar.json distance_meter = %d \n", value); + } + else if (strcmp(*name, "distance_meter_y") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "distance_meter_y", cJSON_CreateNumber(value)); + // json_distance_meter_y = value; // steven 230111 + json_distance_meter_y_p = value; // steven 230111 + // printf("setting radar.json distance_meter = %d \n", value); + } + else if (strcmp(*name, "world_camera_height") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_height", cJSON_CreateNumber(value)); + // printf("setting radar.json world_camera_height = %d \n", value); + } + else if (strcmp(*name, "world_camera_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_degree", cJSON_CreateNumber(value)); + // printf("setting radar.json world_camera_degree = %d \n", value); + } + else if (strcmp(*name, "world_camera_degree_offset") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_degree_offset", cJSON_CreateNumber(value)); + json_world_camera_degree_offset_p = value; + // printf("setting radar.json world_camera_degree_offset = %d \n", value); + } + else if (strcmp(*name, "world_camera_home_point_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_home_point_degree", cJSON_CreateNumber(value)); + json_world_camera_home_point_degree_p = value; + // printf("setting radar.json world_camera_home_point_degree = %d \n", value); + } + else if (strcmp(*name, "world_camera_x_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_x_axis", cJSON_CreateNumber(value)); + json_world_camera_x_axis_p = value; // + // printf("setting radar.json world_camera_x_axis = %d \n", value); + } + else if (strcmp(*name, "world_camera_y_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_y_axis", cJSON_CreateNumber(value)); + json_world_camera_y_axis_p = value; // + // printf("setting radar.json world_camera_y_axis = %d \n", value); + } + else if (strcmp(*name, "world_radar_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "world_radar_degree", cJSON_CreateNumber(value)); + // printf("setting radar.json world_radar_degree = %d \n", value); + } + else if (strcmp(*name, "enable_camera_tracking") == 0) + { + ; + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "enable_camera_tracking", cJSON_CreateBool(inbool)); + // printf("setting radar.json enable_camera_tracking = %d \n", inbool); + } + else if (strcmp(*name, "distance_format") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_format", cJSON_CreateString(*value2)); + // printf("setting radar.json distance_format = %s \n", *value2); + } + else if (strcmp(*name, "radar_section_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "radar_section_degree", cJSON_CreateNumber(value)); + json_radar_section_degree = value; // leo 09-28 + // printf("setting radar.json radar_section_degree = %d \n", value); + } + else if (strcmp(*name, "target_x_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "target_x_axis", cJSON_CreateNumber(value)); + json_target_x_axis = value; // leo 09-28 + json_target_x_axis_p = value; // leo 11-25 + // printf("setting radar.json target_x_axis = %d \n", value); + } + else if (strcmp(*name, "target_y_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "target_y_axis", cJSON_CreateNumber(value)); + json_target_y_axis = value; // leo 09-28 + json_target_y_axis_p = value; // leo 11-25 + // printf("setting radar.json target_y_axis = %d \n", value); + } + else if (strcmp(*name, "radar_x_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "radar_x_axis", cJSON_CreateNumber(value)); + json_radar_x_axis = value; // leo 09-28 + json_radar_x_axis_p = value; // leo 11-25 + // printf("setting radar.json radar_x_axis = %d \n", value); + } + else if (strcmp(*name, "radar_y_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "radar_y_axis", cJSON_CreateNumber(value)); + json_radar_y_axis = value; // leo 09-28 + json_radar_y_axis_p = value; // leo 11-25 + // printf("setting radar.json radar_y_axis = %d \n", value); + } + else if (strcmp(*name, "ip_setting") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "ip_setting", cJSON_CreateBool(inbool)); + printf("setting radar.json ip_setting = %d \n", inbool); + } + else if (strcmp(*name, "camera_ip") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_ip", cJSON_CreateString(*value2)); + sprintf(json_ptz_ip_p, "%s", *value2); + printf("setting radar.json camera_ip = %s \n", *value2); + } + else if (strcmp(*name, "camera_port") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_port", cJSON_CreateString(*value2)); + sprintf(json_ptz_port_num_p, "%s", *value2); + printf("setting radar.json camera_port = %s \n", *value2); + } + else if (strcmp(*name, "camera_username") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_username", cJSON_CreateString(*value2)); + sprintf(json_ptz_username_p, "%s", *value2); + printf("setting radar.json camera_username = %s \n", *value2); + } + else if (strcmp(*name, "camera_password") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_password", cJSON_CreateString(*value2)); + sprintf(json_ptz_password_p, "%s", *value2); + printf("setting radar.json camera_password = %s \n", *value2); + } + // kuan + char *JsonString = cJSON_Print(root); + FILE *fp; + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn = _CGICMD_SUCCESS; + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open radar.json \n"); + rtn = _CGICMD_FAIL; + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (rtn == _CGICMD_SUCCESS) + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + // sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + char sendBuffer_xtra[BUFSIZE * 8] = {0}; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) + perror("send error radar.json"); + // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE + if (root) + { + cJSON_Delete(root); + root = NULL; + } + } + } + pthread_mutex_unlock(&mutex_radar_json); + closesocket(cli_socket); + } +#endif + // ======================================================================================== +#ifdef GY_OS_AMBA +#if 0 + else if ((strncmp(urlBuffer, "/is_send_pcl", strlen("/is_send_pcl")) == 0)) + { + char Msg[256] = {0}; + g_bIsSendTofPCD = !g_bIsSendTofPCD; + sprintf(Msg, "%d", g_bIsSendTofPCD); + printf("[nweb.c] /is_send_pcl CGI - json str : %s\n\n", Msg); + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/is_send_pcl] send error\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/gettof3dpcd", strlen("/gettof3dpcd")) == 0) + { + char* contentBuffer_pcd = NULL; + int contentSize_pcd = 0; + int check_if_send_OK = 0; + int check_if_send_480 = 0; + + // Get the "res" parameter from the URL + char* resParam = strstr(urlBuffer, "res="); + if (resParam == NULL) { + // No "res" parameter, return an error message + pthread_mutex_lock(&mutex_write_pcd_data_S); + contentBuffer_pcd = tof_pcd_buffer_S; + contentSize_pcd = strlen(tof_pcd_buffer_S); + pthread_mutex_unlock(&mutex_write_pcd_data_S); + } + else { + // Extract the value of the "res" parameter + int resolution = atoi(resParam + strlen("res=")); + + // Return the appropriate PCD buffer based on the resolution + if (resolution == 60) { + pthread_mutex_lock(&mutex_write_pcd_data_S); + contentBuffer_pcd = tof_pcd_buffer_S; + contentSize_pcd = strlen(tof_pcd_buffer_S); + pthread_mutex_unlock(&mutex_write_pcd_data_S); + } + else if (resolution == 120) { + pthread_mutex_lock(&mutex_write_pcd_data_M); + contentBuffer_pcd = tof_pcd_buffer_M; + contentSize_pcd = strlen(tof_pcd_buffer_M); + pthread_mutex_unlock(&mutex_write_pcd_data_M); + } + else if (resolution == 480) { + pthread_mutex_lock(&mutex_write_pcd_data_L); + + FILE *fp = fopen("/emmc/plugin/Aida/pcl/pcd/tof_pcd_data_L.txt", "r"); + + // T{ɮ׬O_\} + if (fp == NULL) { + printf("File open failed."); + } + else { + // NƤǿ + int totalSent = 0; + int remaining = 0; + int check_if_error = 0; + while (!feof(fp)) { + // Ūƶ + char chunk[CHUNK_SIZE]; + int bytesRead = fread(chunk, 1, CHUNK_SIZE, fp); + remaining = bytesRead; + + // gJ socket + while (remaining > 0) { + int chunkSize = (remaining < CHUNK_SIZE) ? remaining : CHUNK_SIZE; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", chunkSize, chunk + (bytesRead - remaining)); + if (sendBufferSize == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + check_if_error = 1; + break; + } + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + check_if_error = 1; + break; + } + totalSent += chunkSize; + remaining -= chunkSize; + } + + if (check_if_error == 1) + break; + } + } + // O + if (fp != NULL) { + fclose(fp); + fp = NULL; + } + + pthread_mutex_unlock(&mutex_write_pcd_data_L); + bTofDataFileStart = 0; + check_if_send_480 = 1; + } + else { + // Invalid resolution parameter, return an error message + contentBuffer_pcd = "Invalid resolution parameter."; + contentSize_pcd = strlen(contentBuffer_pcd); + } + + if (check_if_send_480 == 0) { + if (contentBuffer_pcd == NULL) { + // The requested PCD buffer is not available, return an error message + contentBuffer_pcd = "PCD buffer not available."; + contentSize_pcd = strlen(contentBuffer_pcd); + + } + else if (g_bIsWritingPCD) { + // The PCD file is currently being written, return a message to try again later + contentBuffer_pcd = "File is currently being written. Please wait and try again later."; + contentSize_pcd = strlen(contentBuffer_pcd); + + } + else { + + check_if_send_OK = 1; + } + } + } + + if (check_if_send_OK == 1) { + // Lock the mutex to prevent other threads from accessing the PCD buffer while we send the response + pthread_mutex_lock(&mutex_write_pcd_data); + + // Mark the PCD file as being written to prevent other threads from accessing it + g_bIsWritingPCD = 1; + + // Send the PCD buffer as the response + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", contentSize_pcd, contentBuffer_pcd); + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + } + g_bIsWritingPCD = 0; + // Unlock the mutex to allow other threads to access the PCD buffer again + pthread_mutex_unlock(&mutex_write_pcd_data); + } + else if (check_if_send_480 == 1) { + + } + else{ + g_bIsWritingPCD = 1; + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", contentSize_pcd, contentBuffer_pcd); + + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + } + g_bIsWritingPCD = 0; + } + + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/gettofpixel?", strlen("/gettofpixel?")) == 0)) + { + // printf("urlBuffer : %s\n", urlBuffer); // URL Ex : /gettofpixel?x=1&y=2 + + float depth = 0.0; + + char Cmd[8192] = {0}; + strcpy(Cmd, urlBuffer + strlen("/gettofpixel?")); + + //int init_size = strlen(Cmd); + char delimAnd[] = "&"; + char delimEqu[] = "="; + //char delimNewLine[] = "\n"; + + char *params = strtok(Cmd, delimAnd); + + int pixelX = 0; + int pixelY = 0; + + int installAngle = 0; + int settofheight = 0; + int y_diff = 0; + double angle_diff = 0.0; + double pixelDegree = 0.0; + double pointHeight = 0.0; + + double height = 0.0; + double distance = 0.0; + + // Compare each parameter with pre-defined key, and get the value for specific application + while(params != NULL) + { + char keyValPair[2][100]={0}; + StrSplit(params, keyValPair, delimEqu); + // printf("key:%s\n", keyValPair[0]); + // printf("value:%s\n", keyValPair[1]); + + if (strstr(keyValPair[0], "x")) + { + pixelX = atoi(keyValPair[1]); + } + else if (strstr(keyValPair[0], "y")) + { + pixelY = atoi(keyValPair[1]); + } + else if (strstr(keyValPair[0], "angle")) + { + installAngle = atoi(keyValPair[1]); + } + else if (strstr(keyValPair[0], "settofheight")) + { + settofheight = atoi(keyValPair[1]); + } + + params = strtok(NULL, delimAnd); + } + + // depth = getToFDepthByPixel(pixelX, pixelY); // send request to tof driver + depth = getDepth(pixelX, pixelY); + + // calculate distance and height by depth and install angel + // --------------------------------------------------------------------- + // printf("depth (M) : %lf\n", depth); // c + + y_diff = 240 - pixelY; + // printf("pixelY : %d , y_diff : %d\n", pixelY, y_diff); + + // angle_diff = ( FoV vertical angle / 2 ) * ( y_diff / ( res_h / 2 ) ) + // FoV vertical angle : 47.2 | Resolution Height : 480 + if (y_diff != 0) + { + angle_diff = 23.6 * ( (double)y_diff / 240.0 ); + } + + pixelDegree = ((double)installAngle) - angle_diff; + + // printf("install degree : %d\n", installAngle); // theta + // printf("angle_diff : %lf\n", angle_diff); + // printf("pixelDegree : %lf\n", pixelDegree); + + pointHeight = sin( pixelDegree * (double)(PI / 180) ) * depth; // sin(theta) = a / c ( depth ) + + // printf("object to tof height (M) : %lf\n", pointHeight); + + if (settofheight) + { + g_tof_device_height = pointHeight; + height = pointHeight; + } else { + height = g_tof_device_height - pointHeight; + } + + distance = fabs(cos( pixelDegree * (double)(PI / 180) )) * depth; // cos(theta) = b / c ( depth ) + + printf("height (M) : %lf\n", height); + printf("distance (M) : %lf\n", distance); + printf("-------------------\n"); + + char Msg[256] = {0}; + sprintf(Msg, "{\"x\":\"%d\", \"y\":\"%d\", \"depth\":\"%f\", \"height\":\"%f\", \"distance\":\"%f\"}", pixelX, pixelY, depth, height, distance); // converted X, Y + printf("[nweb.c] /gettofpixel CGI - json str : %s\n\n", Msg); + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/gettofpixel] send error\n"); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/settofrange?", strlen("/settofrange?")) == 0)) + { + char Cmd[8192] = {0}; + strcpy(Cmd, urlBuffer + strlen("/settofrange?")); + //printf("[nweb.c] /settofrange CGI - URL params : %s\n", Cmd); // URL params Ex : min=0.1&max=0.5 + + //int init_size = strlen(Cmd); + //char delimAnd[] = "&"; + //char delimEqu[] = "="; + //char delimNewLine[] = "\n"; + + //char *params = strtok(Cmd, delimAnd); + + // Compare each parameter with pre-defined key, and get the value for specific application + // while(params != NULL) + // { + // char *keyValPair[2]; + // StrSplit(params, keyValPair, delimEqu); + // // printf("key:%s\n", keyValPair[0]); + // // printf("value:%s\n", keyValPair[1]); + + // if ((strncmp(keyValPair[0], "minX", strlen("minX")) == 0)) + // { + // g_min_tof_range_x = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite min x\n"); + // } + // else if ((strncmp(keyValPair[0], "minY", strlen("minY")) == 0)) + // { + // g_min_tof_range_y = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite min y\n"); + // } + // else if ((strncmp(keyValPair[0], "min", strlen("min")) == 0)) + // { + // g_min_tof_range = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite min\n"); + // } + // else if ((strncmp(keyValPair[0], "maxX", strlen("maxX")) == 0)) + // { + // g_max_tof_range_x = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite max x\n"); + // } + // else if ((strncmp(keyValPair[0], "maxY", strlen("maxY")) == 0)) + // { + // g_max_tof_range_y = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite max y\n"); + // } + // else if ((strncmp(keyValPair[0], "max", strlen("max")) == 0)) + // { + // g_max_tof_range = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite max\n"); + // } + // // other parameters ... + + // params = strtok(NULL, delimAnd); + // } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/settofrange] send error\n"); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/gettofrange") == 0) + { + char Msg[256] = {0}; + sprintf(Msg, "{\"min_tof_range\":\"%f\", \"max_tof_range\":\"%f\", \"unit\":\"M\"}", g_min_tof_range, g_max_tof_range); + // printf("\n[nweb.c] /gettofrange CGI - json str : %s\n\n", Msg); + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/gettofrange] send error\n"); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/gettof") == 0) + { + char tofPATH[1024] = { 0 }; + strcpy(tofPATH, exePath); + strcat(tofPATH, "tof.json"); + char *filename = tofPATH; + if (!FileExist(filename)) + printf("[CGI:/gettof] %s doesn't exist.\n", filename); + else + { + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) + { + cJSON *config_root; + char *JsonString = NULL; + config_root = cJSON_Parse(fileBuf); + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (config_root) + { + JsonString = cJSON_PrintUnformatted(config_root); + strcat(contentBuffer, JsonString); + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) + perror("[CGI:/gettof] send json string error"); + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (config_root) + { + cJSON_Delete(config_root); + config_root = NULL; + } + } + else + printf("[CGI:/gettof] tof.json parse FAIL.\n"); + } + } + // ======================================================================================== + // printf("\n[web process]start 17-5\n"); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/settofconfig?default", 21) == 0)) + { + pthread_mutex_lock(&mutex_tof_json); + char TOF_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof.json"; + char TOF_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof_install.json"; + + CopyFileTo(TOF_INSTALL_JSON_PATH, TOF_JSON_PATH); + + pthread_mutex_unlock(&mutex_tof_json); + // update_radar_json(); // TODO + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/settofconfig?ch=1&", 19) == 0)) + { + // 01-31 + pthread_mutex_lock(&mutex_tof_json); + char buf[1024] = {}; + char Cmd[8192] = {0}; + //char msg_temp[512] = {0}; + CgiCmdRtnCode rtn; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcat(configPATH, "tof.json"); + strcat(config_bakPATH, "tof_bak.json"); + + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + rtn = _CGICMD_FAIL; + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) + { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + + if (fileBuf_config) + { + free(fileBuf_config); + fileBuf_config = NULL; + } + if (root == NULL) + { + printf("root_config is NULL\n"); + rtn = _CGICMD_FAIL; + } + else + { + strcpy(Cmd, urlBuffer + 19); + const char *del = "="; + const char *del2 = "\n"; + char name[50][100]={0}; + int value = 0; + char value2[50][100]={0}; + StrSplit(Cmd, name, del); + + cJSON *camera; + if (!(camera = cJSON_GetObjectItem(root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + } + + if (strcmp(*name, "install_angle") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "install_angle", cJSON_CreateNumber(value)); + tofData.tof_install_angle = value; + // printf("setting tof.json install_angle = %d \n", value); + } + else if (strcmp(*name, "enable_camera") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_camera", cJSON_CreateBool(inbool)); + json_enable_camera_p = inbool; + tofData.tof_enable_camera = inbool; + // printf("setting tof.json enable_camera = %d \n", inbool); + } + else if (strcmp(*name, "ip_setting") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "ip_setting", cJSON_CreateBool(inbool)); + tofData.tof_ip_setting = inbool; + // printf("setting tof.json ip_setting = %d \n", inbool); + } + else if (strcmp(*name, "camera_ip") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_ip", cJSON_CreateString(*value2)); + sprintf(json_ptz_ip_p, "%s", *value2); + sprintf(tofData.tof_camera_ip, "%s", *value2); + // printf("setting tof.json camera_ip = %s \n", *value2); + } + else if (strcmp(*name, "camera_port") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_port", cJSON_CreateString(*value2)); + sprintf(json_ptz_port_num_p, "%s", *value2); + sprintf(tofData.tof_camera_port, "%s", *value2); + // printf("setting tof.json camera_port = %s \n", *value2); + } + else if (strcmp(*name, "camera_username") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_username", cJSON_CreateString(*value2)); + sprintf(json_ptz_username_p, "%s", *value2); + //sprintf(tofData.tof_camera_username, "%s", *value2); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)*value2, strlen(*value2), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); + tofData.tof_camera_username[strlen(temp_account)] = '\0'; + + // printf("setting tof.json camera_username = %s \n", *value2); + } + else if (strcmp(*name, "camera_password") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_password", cJSON_CreateString(*value2)); + sprintf(json_ptz_password_p, "%s", *value2); + sprintf(tofData.tof_camera_password, "%s", *value2); + // printf("setting tof.json camera_password = %s \n", *value2); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)*value2, strlen(*value2), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); + tofData.tof_camera_password[strlen(temp_account)] = '\0'; + + } + else if (strcmp(*name, "enable_tof_ground") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_tof_ground", cJSON_CreateBool(inbool)); + tofData.enable_tof_ground = inbool; + printf("setting tof.json enable_tof_ground = %d \n", inbool); + } + else if (strcmp(*name, "enable_tof_wall") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_tof_wall", cJSON_CreateBool(inbool)); + tofData.enable_tof_wall = inbool; + printf("setting tof.json enable_tof_wall = %d \n", inbool); + } + else if (strcmp(*name, "distance_options") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_options", cJSON_CreateString(*value2)); + sprintf(tofData.distance_options, "%s", *value2); + //printf("setting tof.json distance_options = %s \n", *value2); + } + else if (strcmp(*name, "distance_min_max") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_min_max", cJSON_CreateString(*value2)); + sprintf(tofData.distance_min_max, "%s", *value2); + //printf("setting tof.json distance_options = %s \n", *value2); + } + else if (strcmp(*name, "distance_threshold") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_threshold", cJSON_CreateString(*value2)); + sprintf(tofData.distance_threshold, "%s", *value2); + //printf("setting tof.json distance_threshold = %s \n", *value2); + } + else if (strcmp(*name, "height_options") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "height_options", cJSON_CreateString(*value2)); + sprintf(tofData.height_options, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + } + else if (strcmp(*name, "height_min_max") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "height_min_max", cJSON_CreateString(*value2)); + sprintf(tofData.height_min_max, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + } + else if (strcmp(*name, "height_threshold") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "height_threshold", cJSON_CreateString(*value2)); + sprintf(tofData.height_threshold, "%s", *value2); + //printf("setting tof.json height_threshold = %s \n", *value2); + } + else if (strcmp(*name, "ground_x") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "ground_x", cJSON_CreateString(*value2)); + sprintf(tofData.ground_x, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); +#ifdef GY_OS_AMBA + g_ground_tof_range = (float)getDepth(pixelX, pixelY); +#else + g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); +#endif + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + else if (strcmp(*name, "ground_y") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "ground_y", cJSON_CreateString(*value2)); + sprintf(tofData.ground_y, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); +#ifdef GY_OS_AMBA + g_ground_tof_range = (float)getDepth(pixelX, pixelY); +#else + g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); +#endif + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + + + + char *JsonString = cJSON_Print(root); + FILE *fp; + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn = _CGICMD_SUCCESS; + + CopyFileTo(filename_config, config_bakPATH); + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open tof.json \n"); + rtn = _CGICMD_FAIL; + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (rtn == _CGICMD_SUCCESS) + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + // sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + char sendBuffer_xtra[BUFSIZE * 8] = {0}; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) + perror("send error tof.json"); + // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE + if (root) + { + cJSON_Delete(root); + root = NULL; + } + } + } + pthread_mutex_unlock(&mutex_tof_json); + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/stoppython", strlen("/stoppython")) == 0) //ming add 2024/08/26 + { + char response[256]; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) + { + stopPython(); + strcpy(response, "Python has been signaled to stop."); + } + else + { + strcpy(response, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html; charset=utf-8", strlen(response), response); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) { + printf("\nsend error #32\n"); + } + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythongetstatus", strlen("/pythongetstatus")) == 0) //2024/08/28 + { + g_cWebPythonStatus = 0; + // Definition + // 0: SETTING TAB python check box S + // 1: buffersize Ѽƥ` + // 2: gJMŪbP@ Row AåB Buffer + // 3: buffersize ѼƲ` + // 4: gJMŪbP@ Row ALk + // 5: b檺 python ɿXwo + unsigned int uiCMDBufferRowSize = MAX_GET_PYTHON_BUFFER_ROW_SIZE; + size_t bufferContentSize = 0; + char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 512A̦h 8 A̤jؤoY 4096 + char SendBufferStatus[BUFSIZE * 8] = {0}; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) + { + char *buffersize_ptr = strstr(urlBuffer, "buffersize="); + if (buffersize_ptr != NULL) + { + char *buffersize_value = buffersize_ptr + strlen("buffersize="); + sscanf(buffersize_value, "%d", &uiCMDBufferRowSize); + // printf("Buffersize value: %d\n", uiCMDBufferRowSize); + g_cWebPythonStatus = 1; + } + else + { + g_cWebPythonStatus = 3; + } + printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + + // C Buffer N Row + for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) + { + bufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); + // printf("[/pythongetstatus] for loop index(i) : %d , Reading g_aWebPythonBuffer2D[%d] , bufferContentSize: %zu\n", i, g_uiWebPythonLastBufferIndex, bufferContentSize); + + if (bufferContentSize > 0) + { + if (g_uiWebPythonLastBufferIndex != ((int)g_uiWebPythonCurrentBufferIndex) ) + { + g_cWebPythonStatus = 2; // gJMŪbP@ Row AåB Buffer + + } + else + { + g_cWebPythonStatus = 4; // gJMŪbP@ Row + printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); + continue; + } + } + else + { + // No data in the buffer + // printf("[/pythongetstatus] Python buffer is empty.\n"); + g_cWebPythonStatus = 5; + continue; + } + } + } + else + { + g_cWebPythonStatus = 0; + // strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + sprintf(SendBufferStatus, "{\"status\":\"%d\",\"bufferSignal\":\"%d\"}", g_cWebPythonStatus, g_cWebPythonBufferSignal); + + // printf("[/pythongetstatus] Send Data To Web : %s\n\n\n",SendBufferStatus); + printf("!!! [/pythongetstatus] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendBufferStatus), SendBufferStatus); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(SendBufferStatus, 0, sizeof(SendBufferStatus)); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythongetbuffer?buffersize=", strlen("/pythongetbuffer?buffersize=")) == 0) //2024/08/28 + { + + unsigned int uiCMDBufferRowSize = MAX_GET_PYTHON_BUFFER_ROW_SIZE; + size_t bufferContentSize = 0; + + char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 512A̦h 8 A̤jؤoY 4096 + char beforeSendBuffer[BUFSIZE * 8] = {0}; + + if (strcmp(SystemSetting.enable_python, "Yes") == 0) + { + char *buffersize_ptr = strstr(urlBuffer, "buffersize="); + if (buffersize_ptr != NULL) + { + char *buffersize_value = buffersize_ptr + strlen("buffersize="); + sscanf(buffersize_value, "%d", &uiCMDBufferRowSize); + // printf("Buffersize value: %d\n", uiCMDBufferRowSize); + } + else + { + // printf("Invalid URL uiCMDBufferRowSize\n"); + } + + // printf("[/pythongetbuffer] check g_cWebPythonBufferSignal:%d & uiCMDBufferRowSize:%u\n", g_cWebPythonBufferSignal, uiCMDBufferRowSize); + + // C Buffer N Row + for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) + { + bufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); + // printf("[/pythongetbuffer] for loop index(i) : %d , Reading g_aWebPythonBuffer2D[%d] , bufferContentSize: %zu\n", i, g_uiWebPythonLastBufferIndex, bufferContentSize); + + if (g_uiWebPythonLastBufferIndex >= (WEBPYTHONBUFFER_LENSIZE-1)) + { + printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n"); + g_uiWebPythonLastBufferIndex = 0; + } + if (bufferContentSize > 0) + { + if (g_uiWebPythonLastBufferIndex != ((int)g_uiWebPythonCurrentBufferIndex)) + { + // Ūbg + // printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + pthread_mutex_lock(&mutex_buffer); + // python X + printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); + strcat(sPythonBufferTemp, g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); + // MŮL row + memset(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex], 0, WEBPYTHONBUFFER_ROWSIZE); + pthread_mutex_unlock(&mutex_buffer); // + // sŪm + g_uiWebPythonLastBufferIndex++; + } + else + { + printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n"); + continue; + } + + } + else + { + // No data in the buffer + // printf("[/pythongetbuffer] Python buffer is empty.\n"); + continue; + } + + } + } + else + { + strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + printf("\n\nsPythonBufferTemp : %s\n\n",sPythonBufferTemp); + sprintf(beforeSendBuffer , sPythonBufferTemp); + // printf("[/pythongetbuffer] Send Data To Web : %s\n\n\n",beforeSendBuffer); + printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(beforeSendBuffer, 0, sizeof(beforeSendBuffer)); + closesocket(cli_socket); + } + // ======================================================================================== +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getevents?", 11) == 0) || (strncmp(urlBuffer, "/setevents?", 11) == 0)) + { + pthread_mutex_lock(&mutex_events_json); + + //printf("\n[web process]start 25\n"); + + //printf("\n--------------urlBuffer:%s\n", urlBuffer); + + char Cmd[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd, urlBuffer + 11); +#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); +#endif + CgiCmdType type; + if (strncmp(urlBuffer, "/getevents?", 11) == 0) type = _CGICMD_GET; + else { + type = _CGICMD_SET; + check_if_correct_post = 0; + } + //printf("\n[web process]start cgi 25\n"); + CgiCmdRtnCode rtn = cgicmd_process_events(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //printf("\n[web process]end cgi 25\n"); + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + g_write_config_file_dirty_flag = 0; + + write_config(); + + printf("\n--------------------reload 5\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg, "Success."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33\n"); + //printf("\n[web process]end 25\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + + + } +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getcounters?", 13) == 0) || (strncmp(urlBuffer, "/setcounters?", 13) == 0)) + { + pthread_mutex_lock(&mutex_events_json); + + + //printf("\n[web process]start 2555\n"); + //printf("\n--------set counters:%s\n", urlBuffer); + + char Cmd_temp[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 13); + char Cmd[8192] = { 0 }; + int Cmd_index = 0; + for (int i = 0; i < (int)strlen(Cmd_temp); i++) { + if (i< (int)strlen(Cmd_temp)-2) { + if (!(Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '2' && Cmd_temp[i + 2] == '0')) { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + else { + Cmd[Cmd_index] = ' '; + Cmd_index++; + i += 2; + } + } + else { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + } + Cmd[Cmd_index] = '\0'; + //printf("\n--------Cmd:%s\n", Cmd); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + CgiCmdType type; + if (strncmp(urlBuffer, "/getcounters?", 13) == 0) type = _CGICMD_GET; + else type = _CGICMD_SET; + //printf("\n[web process]start cgi 25\n"); + CgiCmdRtnCode rtn = cgicmd_process_event_counters(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //printf("\n[web process]end cgi 25\n"); + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + g_write_config_file_dirty_flag = 0; + + write_config(); + + printf("\n--------------------reload 6\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg, "Success."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33--2\n"); + //printf("\n[web process]end 25\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getemail?", 10) == 0) || (strncmp(urlBuffer, "/setemail?", 10) == 0)) + { + pthread_mutex_lock(&mutex_events_json); + + + //printf("\n[web process]start 2555\n"); + //printf("\n--------set email:%s\n", urlBuffer); + + char Cmd_temp[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 10); + char Cmd[8192] = { 0 }; + int Cmd_index = 0; + for (int i = 0; i < (int)strlen(Cmd_temp); i++) { + if (i < (int)strlen(Cmd_temp) - 2) { + if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '2' && Cmd_temp[i + 2] == '0') { + Cmd[Cmd_index] = ' '; + Cmd_index++; + i += 2; + } + else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '3' && Cmd_temp[i + 2] == 'C') { + Cmd[Cmd_index] = '<'; + Cmd_index++; + i += 2; + } + else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '3' && Cmd_temp[i + 2] == 'E') { + Cmd[Cmd_index] = '>'; + Cmd_index++; + i += 2; + } + else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '7' && Cmd_temp[i + 2] == 'C') { + Cmd[Cmd_index] = '|'; + Cmd_index++; + i += 2; + } + else { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + } + else { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + } + Cmd[Cmd_index] = '\0'; + //printf("\n--------Cmd:%s\n", Cmd); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + CgiCmdType type; + if (strncmp(urlBuffer, "/getemail?", 10) == 0) type = _CGICMD_GET; + else type = _CGICMD_SET; + //printf("\n[web process]start cgi 25\n"); + CgiCmdRtnCode rtn = cgicmd_process_email_setting(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //printf("\n[web process]end cgi 25\n"); + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + g_write_config_file_dirty_flag = 0; + + write_config(); + + printf("\n--------------------reload 66\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg, "Success."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33--22\n"); + //printf("\n[web process]end 25\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/get_replace_email") == 0){ + pthread_mutex_lock(&mutex_events_json); + + char *replacement_t = NULL; + + replacement_t = StrReplace(emailData.email_content, "An apple", "A banana"); + strcpy(beforeSendBuffer_xtra, replacement_t); + free(replacement_t); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33--2211\n"); + closesocket(cli_socket); + + pthread_mutex_unlock(&mutex_events_json); + } +#endif +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/aiautotracking_json") == 0) + { + //printf("\n[web process]start 7\n"); + + char Msg[256] = { 0 }; + strcpy(beforeSendBuffer_xtra, "{\"DeviceName\":\"GYNet\","); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "\"Version\":\"%s\",", APP_VERSION); +#endif + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"Thread_Running\":%d,", g_stPTZ_Handle.iThreadRunningFlag); + strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"iTimer_send_count\":%d,", g_stPTZ_Handle.iTimer_send_count); + //strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"iPTZ_sensitivity\":%d,", g_stPTZ_Handle.iPTZ_sensitivity); + //strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"Lose_Running\":%d,", g_stPTZ_Handle.LostTime); + //strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"Resume_Running\":%d,", g_stPTZ_Handle.ResumTime); + //strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iEnable_tracking\":%d,", g_stPTZ_Handle.iEnable_tracking); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsAtHomePOS\":%d,", g_stPTZ_Handle.iIsAtHomePOS); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsInPreset\":%d,", g_stPTZ_Handle.iIsInPreset); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsInAutopan\":%d,", g_stPTZ_Handle.iIsInAutopan); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsInAutoTracking\":%d,", g_stPTZ_Handle.iIsInAutoTracking); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iHomePreset\":%d,", g_stPTZ_Handle.iHomePreset); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iRunPTZUpdateStatusThread_flag\":%d,", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iRunPTZTrackingThread_flag\":%d,", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iCandidateBoxCount\":%d,", g_stPTZ_Handle.iCandidateBoxCount); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsGetLockTrackingBox\":%d,", g_stPTZ_Handle.iIsGetLockTrackingBox); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iLockBoxIdx\":%d,", g_stPTZ_Handle.iLockBoxIdx); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"stPTZLockTrackingBox.stPTZLockTrackingBox.obj_tracking_id\":%d", g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id); + strcat(beforeSendBuffer_xtra, Msg); + + strcat(beforeSendBuffer_xtra, "}"); + + //strcat(beforeSendBuffer_xtra, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #188\n"); + //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/aiautotracking_info") == 0) + { + //printf("\n[web process]start 7\n"); + + char Msg[256] = { 0 }; + strcpy(contentBuffer, "DeviceName=GYNet\r\n<br/>"); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "Version=%s\r\n<br/>", APP_VERSION); +#endif + strcat(contentBuffer, Msg); + + sprintf(Msg, "Thread Running = %d\r\n<br/>", g_stPTZ_Handle.iThreadRunningFlag); + strcat(contentBuffer, Msg); + + //sprintf(Msg, "iTimer_send_count = %d\r\n<br/>", g_stPTZ_Handle.iTimer_send_count); + //strcat(contentBuffer, Msg); + + //sprintf(Msg, "iPTZ_sensitivity = %d\r\n<br/>", g_stPTZ_Handle.iPTZ_sensitivity); + //strcat(contentBuffer, Msg); + + //sprintf(Msg, "Lose Running = %d\r\n<br/>", g_stPTZ_Handle.LostTime); + //strcat(contentBuffer, Msg); + + //sprintf(Msg, "Resume Running = %d\r\n<br/>", g_stPTZ_Handle.ResumTime); + //strcat(contentBuffer, Msg); + + sprintf(Msg, "iEnable_tracking=%d\r\n<br/>", g_stPTZ_Handle.iEnable_tracking); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsAtHomePOS=%d\r\n<br/>", g_stPTZ_Handle.iIsAtHomePOS); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsInPreset=%d\r\n<br/>", g_stPTZ_Handle.iIsInPreset); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsInAutopan=%d\r\n<br/>", g_stPTZ_Handle.iIsInAutopan); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsInAutoTracking=%d\r\n<br/>", g_stPTZ_Handle.iIsInAutoTracking); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iHomePreset=%d\r\n<br/>", g_stPTZ_Handle.iHomePreset); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iRunPTZUpdateStatusThread_flag=%d\r\n<br/>", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iRunPTZTrackingThread_flag=%d\r\n<br/>", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iCandidateBoxCount=%d\r\n<br/>", g_stPTZ_Handle.iCandidateBoxCount); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsGetLockTrackingBox=%d\r\n<br/>", g_stPTZ_Handle.iIsGetLockTrackingBox); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iLockBoxIdx=%d\r\n<br/>", g_stPTZ_Handle.iLockBoxIdx); + strcat(contentBuffer, Msg); + + sprintf(Msg, "stPTZLockTrackingBox=%ld\r\n<br/>", sizeof(g_stPTZ_Handle.stPTZLockTrackingBox)); + strcat(contentBuffer, Msg); + + strcat(contentBuffer, "\r\n<br/>"); + + + + strcpy(beforeSendBuffer, contentBuffer); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_server(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18\n"); + //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/ptzpreset?camid=1&ai_goto_preset=", 34) == 0) + { + if (IsPTZ() == 1) + { + //Stop Autopan + //StartStopAutopan(0); + + //Go Preset + char sPresetNumber[10] = { 0 }; + memset(sPresetNumber, 0x00, sizeof(sPresetNumber)); + strcpy(sPresetNumber, urlBuffer + 34); + + int iPreset_number = 1; + if (strlen(sPresetNumber) > 0) + iPreset_number = atoi(sPresetNumber); + + GoPreset(iPreset_number); + + //usSleep(2000000); + + //Start Autopan + //StartStopAutopan(1); + + //Response + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "go preset success."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "This device is not support PTZ."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + } + else if (strncmp(urlBuffer, "/ptz_move_direction?", 20) == 0) + { + memset(msg, 0x00, sizeof(msg)); + if (IsPTZ() == 1) + { + char sCmd[256] = { 0 }; + memset(sCmd, 0x00, sizeof(sCmd)); + strcpy(sCmd, urlBuffer + 20); + + char spilt_move[2][STRSPLIT_SIZE]={0}; + const char *del = "&"; + int num_move = 0; + num_move = StrSplit(sCmd, spilt_move, del); + //printf("\n------UU:32\n"); + int iPan = 0; + int iTilt = 0; + + for (int i = 0; i < num_move; i++) { + char a_spilt_move[2][STRSPLIT_SIZE]={0}; + const char *del2 = "="; + int a_num_move = 0; + a_num_move = StrSplit(spilt_move[i], a_spilt_move, del2); + //printf("\n------UU:33\n"); + for (int j = 0; j < a_num_move; j++) { + if (strcmp(a_spilt_move[0], "pan") == 0) { + iPan = atoi(a_spilt_move[1]) * atoi(viewChannelData[0].ptz_speed); + } + else if (strcmp(a_spilt_move[0], "tilt") == 0) { + iTilt = atoi(a_spilt_move[1]) * atoi(viewChannelData[0].ptz_speed); //קKӧ + } + } + } + + if (iPan != 0 || iTilt != 0){ + StopPtz(); + move_PTZ_in_the_direction(iPan, iTilt); + pthread_t ptz_stop_thread_id; + if (pthread_create(&ptz_stop_thread_id, 0, ptz_stop_thread, NULL)) + { + printf("\ncreate ptz stop thread faile \n"); + } + sprintf(msg, "Move direction success."); + } + else { + sprintf(msg, "Move direction fail."); + } + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #328\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/ptz_stop", 9) == 0) + { + memset(msg, 0x00, sizeof(msg)); + if (IsPTZ() == 1) + { + StopPtz(); + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3128\n"); + + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/", 1) == 0) + { + //printf("\n[web process]start 26\n"); + char * pch; + pch = strstr(urlBuffer, "jpg"); + + if (pch == NULL) + { + //syslog(NW_SORRY, "file type not supported", firstBuffer, cli_socket); + //memset(msg, 0x00, sizeof(msg)); + + char msg_temp[512] = { 0 }; + sprintf(msg_temp, "Unknown Url"); + //printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg_temp); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #34\n"); + + /*printf("\n[web process]-A-1:free(contentBuffer)\n"); + free(contentBuffer); //double free + */ + //printf("\n[web process]-A-1: closesocket(client_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + else + { + //printf("\n[nweb.c]urlBuffer:\n"); + //printf(urlBuffer); + //printf("\n"); + /* convert no filename to index file */ + + if (!strncmp(&firstBuffer[0], "GET /\0", 6) || !strncmp(&firstBuffer[0], "get /\0", 6)) + strcpy(firstBuffer, "GET /example.htm"); + else + { + strcpy(firstBuffer, "GET "); + strcat(firstBuffer, urlBuffer); + firstBuffer[strlen("GET ") + strlen(urlBuffer)] = '\0'; + } + + /* work out the file type and check if we support it */ + buflen = strlen(firstBuffer); + fstr = NULL; + for (idx = 0; extensions[idx].ext != 0; idx++) + { + len = strlen(extensions[idx].ext); + //printf(extensions[idx].ext); + if (!strncmp(&firstBuffer[buflen - len], extensions[idx].ext, len)) + { + fstr = extensions[idx].filetype; + break; + } + } + + if (fstr == NULL) + { + //syslog(NW_SORRY, "file type not supported", firstBuffer, cli_socket); + char msg_temp[512] = { 0 }; + //memset(msg, 0x00, sizeof(msg)); + sprintf(msg_temp, "[0]The file %s has unknown file extension.", &firstBuffer[5]); + //printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg_temp); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #35\n"); + } + else + { + /* execute the send command, but first check if the browser */ + /* has requested the default icon file, favicon.ico. */ + if (!strncmp(firstBuffer + 5, "/favicon.ico", 12)) + { + /* Send a null file to satisfy a request for favicon.ico */ + sprintf(tempBuffer, "HTTP/1.1 204 No Content\r\n\r\n"); + send(cli_socket, tempBuffer, strlen(tempBuffer), 0); + } + else + { + ///* open the file for reading */ + //if ((fp = fopen(&firstBuffer[5], "rb")) == NULL) + //{ + // syslog(NW_SORRY, "failed to open file", &firstBuffer[5], cli_socket); + //} + + int file_fd; + if ((file_fd = open(&firstBuffer[5], O_RDONLY)) == -1) + { + printf("Failed to open file : %s\n", &firstBuffer[5]);//ɮצSQŪ + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19-52\n"); + } + else { + int iFileLength = 0; + char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; + iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); + close(file_fd); + + /* work out the file type and check if we support it */ + buflen = strlen(urlBuffer); + fstr = NULL; + for (idx = 0; extensions[idx].ext != 0; idx++) + { + len = strlen(extensions[idx].ext); + if (!strncmp(&urlBuffer[buflen - len], extensions[idx].ext, len)) + { + fstr = extensions[idx].filetype; + break; + } + } + + if (fstr == NULL) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19554\n"); + } + else + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: %s;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n", fstr); /*\r\nCache - Control: max - age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #20221\n"); + } + + int iSentLeft = 0; + int iSentLength = 0; + int iHaveSentLength = 0; + int iRetryCount = 5; + + + + iSentLeft = iFileLength; + + while (iSentLeft >= 1) { + iSentLength = send(cli_socket, sendBuffer_superlarge + iHaveSentLength, iSentLeft, MSG_MORE); + + if (iSentLength <= 0) + break; + + iHaveSentLength = iHaveSentLength + iSentLength; + iSentLeft = iSentLeft - iSentLength; + iRetryCount--; + + if (iSentLeft >= 1) { + //printf("\n[web process]iSentLeft: %d\n", iSentLeft); + } + + if (iRetryCount <= 0) + break; + //usSleep(100); + } + } + } + } + closesocket(cli_socket); + } + } + } + else if (strcmp(httpCommand, "POST ") == 0) + { + if (strncmp(urlBuffer, "/sendjpeg", strlen("/sendjpeg")) == 0) + { + //printf("\n[web process]start 27\n"); + char *image_buff = NULL; + int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + char httpVariables[BUFSIZE_V2] = { 0 }; + char *QuestionMarK = strstr(urlBuffer, "?"); + + if (QuestionMarK) + { + strcpy(httpVariables, QuestionMarK + 1); + //char *start = httpVariables; + char *pch; + char *pDelim = "&"; + char *pLeft = NULL; + // pch = strtok_r(httpVariables, pDelim, &pLeft); + // BUG9 : strtok_modified + pch = strtok_modified(httpVariables, pDelim, &pLeft); + while (pch != NULL) { + // string between start and delim (or end of string if delim is NULL). + if (pch) + { + char attribute[512] = { 0 };//512 + strcpy(attribute, pch); + //attribute[pDelim - start] = 0; + char att_var[10][STRSPLIT_SIZE]={0}; + char *del = "="; + //int att_var_num = 0; + //if (attribute) + { + /*att_var_num = */StrSplit(attribute, att_var, del); + //printf("\n------UU:34\n"); + if (strcmp(att_var[0], "channel") == 0) + { + tracking_channel = atoi(att_var[1]); + tracking_channel_idx = tracking_channel - 1; + } + } + //start = pDelim + 1; // Use length of your b string. + } + pch = strtok_modified(NULL, pDelim, &pLeft); + } + } + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + + } + char* pJpegStart = NULL; + char* pJpegEnd = NULL; + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) + { + pJpegStart = image_buff + i; + break; + } + } + + for (int i = nTotalBytes; i > 0; i--) + { + if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) + { + pJpegEnd = image_buff + i + 2; + break; + } + } + + //printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); + + if (!pJpegStart || !pJpegEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format(Multipart)."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not JPEG format)\n"); + + + //printf("\n[web process]-A-3: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); + closesocket(cli_socket); + + return; + } + else + { + image_buff_size = pJpegEnd - pJpegStart; + memmove(image_buff, pJpegStart, image_buff_size); + +#if 0 + printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); +#endif + + memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); + } + } + else + { + image_buff_size = nTotalContentLen; + memcpy(image_buff, contentBuffer, image_buff_size); + //DumpHex(image_buff + image_buff_size - 10, 10); + } + + if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) + { + //DumpHex(image_buff, 2); + //DumpHex(image_buff + image_buff_size - 2, 2); + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + //printf("\n[web process]-A-4: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + + /*if (layer_count == 0) + { + printf("Invalid layer count %d\n", cli_socket); + //int sendBufferSize = SetHttpResponse(sendBuffer, "HTTP/1.1 403 Forbidden", "text/html;", strlen("Invalid license key"), "Invalid license key");//20201028 sophia mark + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_403, "text/html;", strlen("Invalid license key"), "Invalid license key");//20201028 sophia add + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #37\n"); + //printf("\n[web process]-A-5: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-5: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + }*/ + +#if defined GY_OS_AMBA + GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); + + //int nNeedUpdateTrafficLightZone = 0; + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\njpeg_width: %d\n", jpeg_width); + printf("\ntab_view_width: %d\n", viewChannelData[tracking_channel_idx].tab_view_width); + printf("\ntab_view_height: %d\n", viewChannelData[tracking_channel_idx].tab_view_height); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + if (AIImage_width > 0) + { + //if (abs(viewChannelData[tracking_channel_idx].tab_view_width_ratio * viewChannelData[tracking_channel_idx].tab_view_width - AIImage_width) > 5) + //nNeedUpdateTrafficLightZone = 1; + // + viewChannelData[tracking_channel_idx].tab_view_width_ratio = (float)AIImage_width / viewChannelData[tracking_channel_idx].tab_view_width; + viewChannelData[tracking_channel_idx].tab_view_height_ratio = (float)AIImage_width / viewChannelData[tracking_channel_idx].tab_view_height; +//#ifdef GY_OS_WIN + //if (nNeedUpdateTrafficLightZone) + //UpdateTrafficLightZone(tracking_channel_idx); +//#endif + } +#endif + socketRecords[sock_info_idx].channel_id = tracking_channel; + + //double recv_clock = clock(); + //double diff = ((double)(recv_clock - begin_clock) / CLOCKS_PER_SEC); + //sprintf(msg, "log/sock-%05d_sec_%f %s.jpg", cli_socket, diff, contentDescription); + //FILE *f = fopen(msg, "wb"); + //if (f == NULL) + //{ + // printf("Error opening file!\n"); + // //exit(1); + //} + //fwrite(image_buff, image_buff_size, 1, f); + //fclose(f); + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + /* + + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nweb process: %d\n",1); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time %d:%f\n", cli_socket, dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + } + else if (strncmp(urlBuffer, "/setemailsfile", strlen("/setemailsfile")) == 0) { + //printf("\n----------urlBuffer:%s\n", urlBuffer); + + //pthread_mutex_lock(&mutex_config_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + +#if 1 + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char emails_importPATH[1024]; + strcpy(emails_importPATH, exePath); + strcat(emails_importPATH, "emails_import.json"); + + char emails_PATH[1024]; + char emails_bakPATH[1024]; + strcpy(emails_PATH, exePath); + strcpy(emails_bakPATH, exePath); + strcat(emails_PATH, "emails.json"); + strcat(emails_bakPATH, "emails_bak.json"); + + FILE *pFile; + + if ((pFile = fopen(emails_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(emails_importPATH); + char* fileBuf2 = ReadAllBytes(emails_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + if (root && s_root) + { + cJSON *auth_password; + //cJSON *s_auth_password; + auth_password = cJSON_GetObjectItem(root, "auth_password"); + //s_auth_password = cJSON_GetObjectItem(s_root, "auth_password"); + + if (auth_password) + { + size_t base64_decode_length = 0; + char EncryptKeyData[256]; + //char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + //memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + char temp_auth_password[256] = { 0 }; + memcpy(temp_auth_password,auth_password->valuestring,strlen(auth_password->valuestring)); + + base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //KeyExpansion(key_email, expandedKey_email); + //unsigned char EncryptData[1 * 1024]; + //memset(EncryptData, 0x00, sizeof(EncryptData)); + //int encryptSize = AESEncryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, EncryptData, sizeof(EncryptData)); + + //EncryptData[encryptSize] = '\0'; + //int decryptSize = AESDecryptArrayToArray(EncryptData, strlen(EncryptData), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); + + strcpy(IPCAMService.auth_password, EncryptKeyData); + cJSON_ReplaceItemInObject(s_root, "auth_password", cJSON_CreateString(temp_auth_password)); + + //printf("\n----------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); + //printf("\n----------temp_auth_password:%s\n", temp_auth_password); + //printf("\n----------EncryptData:%s\n", EncryptData); + } + + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(emails_PATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(emails_PATH, emails_bakPATH); + check_if_setfile_OK = 1; + //g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read config_import.json or config.json\n"); + } + } + +#endif + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("send(Not set emails file)"); + } + else { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("send(Not set emails file#2)"); + } + + //pthread_mutex_unlock(&mutex_config_json); + + closesocket(cli_socket); + } +#if 0 + else if (strncmp(urlBuffer, "/settoffile", strlen("/settoffile")) == 0) + { + pthread_mutex_lock(&mutex_tof_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char tof_importPATH[1024]; + strcpy(tof_importPATH, exePath); + strcat(tof_importPATH, "tof_import.json"); + + char tof_PATH[1024]; + strcpy(tof_PATH, exePath); + strcat(tof_PATH, "tof.json"); + + char tof_bakPATH[1024]; + strcpy(tof_bakPATH, exePath); + strcat(tof_bakPATH, "tof_bak.json"); + + FILE *pFile; + + if ((pFile = fopen(tof_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(tof_importPATH); + char* fileBuf2 = ReadAllBytes(tof_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (root && s_root) + { + cJSON *tof_version, *tof_debug, *tof_install_angle, *tof_enable_camera, *enable_tof_ground, *enable_tof_wall, *tof_camera; + cJSON *tof_camera_ip, *tof_camera_port, *tof_camera_sub_url, *tof_auth_key, *tof_ip_setting, *tof_camera_username, *tof_camera_password; + cJSON *distance_options, *distance_threshold, *height_options, *height_threshold, *distance_min_max, *height_min_max; + cJSON *ground_x, *ground_y; + + cJSON *s_tof_camera; + + tof_version = cJSON_GetObjectItem(root, "version"); + tof_debug = cJSON_GetObjectItem(root, "debug"); + tof_install_angle = cJSON_GetObjectItem(root, "install_angle"); + tof_enable_camera = cJSON_GetObjectItem(root, "enable_camera"); + enable_tof_ground = cJSON_GetObjectItem(root, "enable_tof_ground"); + enable_tof_wall = cJSON_GetObjectItem(root, "enable_tof_wall"); + distance_options = cJSON_GetObjectItem(root, "distance_options"); + distance_threshold = cJSON_GetObjectItem(root, "distance_threshold"); + height_options = cJSON_GetObjectItem(root, "height_options"); + height_threshold = cJSON_GetObjectItem(root, "height_threshold"); + distance_min_max = cJSON_GetObjectItem(root, "distance_min_max"); + height_min_max = cJSON_GetObjectItem(root, "height_min_max"); + + ground_x = cJSON_GetObjectItem(root, "ground_x"); + ground_y = cJSON_GetObjectItem(root, "ground_y"); + + tof_camera = cJSON_GetObjectItem(root, "camera"); + s_tof_camera = cJSON_GetObjectItem(s_root, "camera"); + + if (tof_version) + { + tofData.tof_version = tof_version->valueint; + cJSON_ReplaceItemInObject(s_root, "version", cJSON_CreateNumber(tofData.tof_version)); + } + + if (tof_debug) + { + if (cJSON_IsTrue(tof_debug)) + { + tofData.tof_debug = true; + } + else + { + tofData.tof_debug = false; + } + cJSON_ReplaceItemInObject(s_root, "debug", cJSON_CreateBool(tofData.tof_debug)); + } + + if (tof_install_angle) { + tofData.tof_install_angle = tof_install_angle->valueint; + cJSON_ReplaceItemInObject(s_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); + } + + if (tof_enable_camera) { + if (cJSON_IsTrue(tof_enable_camera)) + { + tofData.tof_enable_camera = true; + } + else + { + tofData.tof_enable_camera = false; + } + cJSON_ReplaceItemInObject(s_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); + } + + if (enable_tof_ground) { + if (cJSON_IsTrue(enable_tof_ground)) + { + tofData.enable_tof_ground = true; + } + else + { + tofData.enable_tof_ground = false; + } + cJSON_ReplaceItemInObject(s_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); + } + + if (enable_tof_wall) { + if (cJSON_IsTrue(enable_tof_wall)) + { + tofData.enable_tof_wall = true; + } + else + { + tofData.enable_tof_wall = false; + } + cJSON_ReplaceItemInObject(s_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); + } + + if (distance_options) + { + strcpy(tofData.distance_options, distance_options->valuestring); + cJSON_ReplaceItemInObject(s_root, "distance_options", cJSON_CreateString(tofData.distance_options)); + } + + if (distance_min_max) { + strcpy(tofData.distance_min_max, distance_min_max->valuestring); + cJSON_ReplaceItemInObject(s_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); + } + + if (distance_threshold) { + strcpy(tofData.distance_threshold, distance_threshold->valuestring); + cJSON_ReplaceItemInObject(s_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); + } + + if (height_options) { + strcpy(tofData.height_options, height_options->valuestring); + cJSON_ReplaceItemInObject(s_root, "height_options", cJSON_CreateString(tofData.height_options)); + } + + if (height_min_max) { + strcpy(tofData.height_min_max, height_min_max->valuestring); + cJSON_ReplaceItemInObject(s_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); + } + + + if (ground_x) { + strcpy(tofData.ground_x, ground_x->valuestring); + cJSON_ReplaceItemInObject(s_root, "ground_x", cJSON_CreateString(tofData.ground_x)); + } + + if (ground_y) { + strcpy(tofData.ground_y, ground_y->valuestring); + cJSON_ReplaceItemInObject(s_root, "ground_y", cJSON_CreateString(tofData.ground_y)); + } + + if (ground_x || ground_y) { + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); +#ifdef GY_OS_AMBA + g_ground_tof_range = (float)getDepth(pixelX, pixelY); +#else + g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); +#endif + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + + if (height_threshold) { + strcpy(tofData.height_threshold, height_threshold->valuestring); + cJSON_ReplaceItemInObject(s_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); + } + + if (tof_camera) { + tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); + tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); + tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); + tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); + tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); + tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); + tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); + + if (tof_camera_ip) { + strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); + } + + if (tof_camera_port) { + strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); + } + + if (tof_camera_sub_url) { + strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); + } + + if (tof_auth_key) { + strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); + } + + if (tof_ip_setting) { + if (cJSON_IsTrue(tof_ip_setting)) + { + tofData.tof_ip_setting = true; + } + else + { + tofData.tof_ip_setting = false; + } + cJSON_ReplaceItemInObject(s_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); + } + + if (tof_camera_username) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); + tofData.tof_camera_username[strlen(temp_account)] = '\0'; + + cJSON_ReplaceItemInObject(s_tof_camera, "camera_username", cJSON_CreateString(tof_camera_username->valuestring)); + } + + if (tof_camera_password) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); + tofData.tof_camera_password[strlen(temp_account)] = '\0'; + + cJSON_ReplaceItemInObject(s_tof_camera, "camera_password", cJSON_CreateString(tof_camera_password->valuestring)); + } + } + + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(tof_PATH, "w"); + if (f != NULL) + { + + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(tof_PATH, tof_bakPATH); + + check_if_setfile_OK = 1; + //g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read tof_import.json or tof.json\n"); + } + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not settoffile)\n"); + } + else { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not settoffile#2)\n"); + } + + pthread_mutex_unlock(&mutex_tof_json); + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/setconfigfile", strlen("/setconfigfile")) == 0) { + //printf("\n----------urlBuffer:%s\n", urlBuffer); + + pthread_mutex_lock(&mutex_config_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer+ recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char config_importPATH[1024]; + strcpy(config_importPATH, exePath); + strcat(config_importPATH, "config_import.json"); + + char config_PATH[1024]; +#ifdef GY_OS_NOVA + char config_smallPATH[1024]; +#endif + char config_bakPATH[1024]; + strcpy(config_PATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_smallPATH, exePath); +#endif + strcpy(config_bakPATH, exePath); + strcat(config_PATH, "config.json"); +#ifdef GY_OS_NOVA + strcat(config_smallPATH, "config_small.json"); +#endif + strcat(config_bakPATH, "config_bak.json"); + + FILE *pFile; + + if ((pFile = fopen(config_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(config_importPATH); + char* fileBuf2 = ReadAllBytes(config_PATH); +#ifdef GY_OS_NOVA + char* fileBuf3 = ReadAllBytes(config_smallPATH); +#endif + +#ifdef GY_OS_NOVA + if (fileBuf && fileBuf2 && fileBuf3) { +#else + if (fileBuf && fileBuf2) { +#endif + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); +#ifdef GY_OS_NOVA + cJSON *root_small = cJSON_Parse(fileBuf3); +#endif + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } +#ifdef GY_OS_NOVA + if (fileBuf3) { + free(fileBuf3); + fileBuf3 = NULL; + } +#endif + +#ifdef GY_OS_NOVA + if (root && s_root && root_small) +#else + if (root && s_root) +#endif + { + cJSON *view_setting,*camera,*camera_name,*levenshtein_distance,*min_characters,*max_characters,*obj_min_proportion,*obj_max_proportion, + *confidence,*confidence2,*confidence3, *confidence4,*count_zone,*enable_lpr_db,*enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, // joy add + *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking,*ptz_tracking_mode,*ptz_tracking_by_enter_zone, + *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, + *enable_unknown_object, *ivs_mode, *enable_ivs_person_detection, *assign_ivs_object_to, *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, + *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*ptz_sensitivity,*ptz_tracking_resume_dwell,*cJSON_enable_only_show_metadata1,*getnetwork_buffer_id, + *tab_view_size,*enable_anpr,*enable_face,*enable_traffic,*enable_logo, + *temp_detection_zone,*detect,*enable_traffic_light,*detection_time,*metadata1,*metadata2, *metadata_stop,*link_to_counter,*enable_direction1, + *enable_direction2, *direction1,*direction2,*no_parking_time,*no_parking_time_in_minute,*queuing_count,*ptz_zone_to_preset,*enable_speed,*enable_radar_speed, *enable_ivs_zone, + *set_distance,*world_distance_unit,*world_distance_side1, *world_distance_side2,*world_time_unit,*parking_space, *parking_line, + *point_number,*x1,*y1,*x2,*y2,*x3,*y3, *x4, *y4, *x5, *y5, *x6, *y6, + *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; + cJSON *trigger_events_0, *trigger_events_1, *trigger_events_2,*trigger_events_3, *trigger_events_4, *trigger_events_5, *trigger_events_6, *trigger_events_7,*checked,*detect_event_name,*post_event_name, + *counter_name/*,*counter_cust_name*/,*counter_increment; + cJSON *s_view_setting, *s_camera, *s_detection_zone, *s_detect,*s_trigger_events_0, *s_trigger_events_1, *s_trigger_events_2, *s_trigger_events_3, *s_trigger_events_4, *s_trigger_events_5, *s_trigger_events_6, *s_trigger_events_7; + + cJSON *trigger_events_temp, *s_trigger_events_temp; +#ifdef GY_OS_NOVA + cJSON *view_setting_small, *system_setting_small, *camera_small/*, *count_zone_small*/, *detection_zone_small, *detect_small/*, *point_number_small*/, + *x1_small, *y1_small, *x2_small, *y2_small, *x3_small, *y3_small, *x4_small, *y4_small, *x5_small, *y5_small, *x6_small, *y6_small; +#endif + view_setting = cJSON_GetObjectItem(root, "view_setting"); + s_view_setting = cJSON_GetObjectItem(s_root, "view_setting"); +#ifdef GY_OS_NOVA + view_setting_small = cJSON_GetObjectItem(root_small, "view_setting"); +#endif + if (view_setting) { + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + s_camera = cJSON_GetObjectItem(s_view_setting, CameraID); +#ifdef GY_OS_NOVA + camera_small = cJSON_GetObjectItem(view_setting_small, CameraID); +#endif + if (camera) { + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); + plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); + plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); + enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); + enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); + enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); + enable_track = cJSON_GetObjectItem(camera, "enable_track"); + ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); + ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); + ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); + ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); + ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); + enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); + ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); + ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); + ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); + ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); + ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); + enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); + enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); + assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); + enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); + enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); + enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); + enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); + enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); + enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); + enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); + dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); + unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); + unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); + confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); + confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); + dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); + dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); + person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); + getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); + red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); + no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); + no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); + no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); + no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); + ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); + ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); + cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + + ivs_mode = cJSON_GetObjectItem(camera, "ivs_mode"); + + temp_detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + s_detection_zone = cJSON_GetObjectItem(s_camera, "detection_zone"); +#ifdef GY_OS_NOVA + detection_zone_small = cJSON_GetObjectItem(camera_small, "detection_zone"); +#endif + } + + if (camera_name) { + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + cJSON_ReplaceItemInObject(s_camera, "camera_name", cJSON_CreateString(viewChannelData[n].camera_name)); + } + if (levenshtein_distance) { + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + cJSON_ReplaceItemInObject(s_camera, "levenshtein_distance", cJSON_CreateString(viewChannelData[n].levenshtein_distance)); + } + if (min_characters) { + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + cJSON_ReplaceItemInObject(s_camera, "min_characters", cJSON_CreateString(viewChannelData[n].min_characters)); + } + if (max_characters) { + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + cJSON_ReplaceItemInObject(s_camera, "max_characters", cJSON_CreateString(viewChannelData[n].max_characters)); + } + if (obj_min_proportion) { + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "obj_min_proportion", cJSON_CreateString(viewChannelData[n].obj_min_proportion)); + } + if (obj_max_proportion) { + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "obj_max_proportion", cJSON_CreateString(viewChannelData[n].obj_max_proportion)); + } + + if (plate_filter_times) { + viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); + cJSON_ReplaceItemInObject(s_camera, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); + } + + if (plate_filter_time) { + viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); + cJSON_ReplaceItemInObject(s_camera, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); + } + + if (plate_free_time) { + viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); + cJSON_ReplaceItemInObject(s_camera, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); + } + + if (confidence) { + strcpy(viewChannelData[n].confidence, confidence->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence", cJSON_CreateString(viewChannelData[n].confidence)); + } + if (confidence2) { + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence2", cJSON_CreateString(viewChannelData[n].confidence2)); + } + if (confidence3) { + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence3", cJSON_CreateString(viewChannelData[n].confidence3)); + } + if (confidence4) { + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence4", cJSON_CreateString(viewChannelData[n].confidence4)); + } + if (count_zone) { + viewChannelData[n].count_zone = count_zone->valueint; + cJSON_ReplaceItemInObject(s_camera, "count_zone", cJSON_CreateNumber(viewChannelData[n].count_zone)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "count_zone", cJSON_CreateNumber(viewChannelData[n].count_zone)); +#endif + } + if (enable_lpr_db) { + pthread_mutex_lock(&mutex_enable_lpr_db); + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_lpr_db", cJSON_CreateString(viewChannelData[n].enable_lpr_db)); + pthread_mutex_unlock(&mutex_enable_lpr_db); + } + if (enable_add_face_frequent_list) { + if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) + viewChannelData[n].enable_add_face_frequent_list = 1; + else + viewChannelData[n].enable_add_face_frequent_list = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); + } + if (enable_downsized_cropped_roi) { + set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); + cJSON_ReplaceItemInObject(s_camera, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); + } + if (enable_zone_crop_1) { + set_enable_zone_crop_1(enable_zone_crop_1->valueint); + cJSON_ReplaceItemInObject(s_camera, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); + } + if (enable_PTZ) { + strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_PTZ", cJSON_CreateString(viewChannelData[n].enable_PTZ)); + } + if (enable_track) { + strcpy(viewChannelData[n].enable_track, enable_track->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_track", cJSON_CreateString(viewChannelData[n].enable_track)); + } + if (ptz_tracking_fov_min) { + strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_fov_min", cJSON_CreateString(viewChannelData[n].ptz_tracking_fov_min)); + } + if (ptz_tracking_fov_max) { + strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_fov_max", cJSON_CreateString(viewChannelData[n].ptz_tracking_fov_max)); + } + if (ptz_enable_tracking) { + strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_enable_tracking", cJSON_CreateString(viewChannelData[n].ptz_enable_tracking)); + } + if (ptz_tracking_mode) { + viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); + } + if (ptz_tracking_by_enter_zone) { + if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + else + viewChannelData[n].ptz_tracking_by_enter_zone = 0; + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); + } + + if (enable_tracking_limits) { + strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_tracking_limits", cJSON_CreateString(viewChannelData[n].enable_tracking_limits)); + } + + if (ptz_pan_left_limit) { + strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_pan_left_limit", cJSON_CreateString(viewChannelData[n].ptz_pan_left_limit)); + } + + if (ptz_pan_right_limit) { + strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_pan_right_limit", cJSON_CreateString(viewChannelData[n].ptz_pan_right_limit)); + } + + if (ptz_tilt_up_limit) { + strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tilt_up_limit", cJSON_CreateString(viewChannelData[n].ptz_tilt_up_limit)); + } + + if (ptz_tilt_down_limit) { + strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tilt_down_limit", cJSON_CreateString(viewChannelData[n].ptz_tilt_down_limit)); + } + + if (ptz_speed) { + strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_speed", cJSON_CreateString(viewChannelData[n].ptz_speed)); + } + + if (enable_unknown_object) { + strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_unknown_object", cJSON_CreateString(viewChannelData[n].enable_unknown_object)); + +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_unknown_object", cJSON_CreateString(viewChannelData[n].enable_unknown_object)); +#endif + } + + if (enable_ivs_person_detection) { + strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ivs_person_detection", cJSON_CreateString(viewChannelData[n].enable_ivs_person_detection)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_ivs_person_detection", cJSON_CreateString(viewChannelData[n].enable_ivs_person_detection)); +#endif + } + + if (assign_ivs_object_to) { + strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); + cJSON_ReplaceItemInObject(s_camera, "assign_ivs_object_to", cJSON_CreateString(viewChannelData[n].assign_ivs_object_to)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "assign_ivs_object_to", cJSON_CreateString(viewChannelData[n].assign_ivs_object_to)); +#endif + } + + if (enable_ambulance) { + strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ambulance", cJSON_CreateString(viewChannelData[n].enable_ambulance)); + } + if (enable_blank_plate) { + strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_blank_plate", cJSON_CreateString(viewChannelData[n].enable_blank_plate)); + } + if (enable_stop_sign) { + strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_stop_sign", cJSON_CreateString(viewChannelData[n].enable_stop_sign)); + } + if (enable_show_unknown_object) { + strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_show_unknown_object", cJSON_CreateString(viewChannelData[n].enable_show_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_show_unknown_object", cJSON_CreateString(viewChannelData[n].enable_show_unknown_object)); +#endif + } + + if (enable_ivs_fix_mode) { + strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ivs_fix_mode", cJSON_CreateString(viewChannelData[n].enable_ivs_fix_mode)); + } + + if (enable_ivs_and_ai) { + strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ivs_and_ai", cJSON_CreateString(viewChannelData[n].enable_ivs_and_ai)); + } + + if (enable_lpr_upon_triggered) { + strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_lpr_upon_triggered", cJSON_CreateString(viewChannelData[n].enable_lpr_upon_triggered)); + } + if (dwell_lpr_upon_triggered) { + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); + cJSON_ReplaceItemInObject(s_camera, "dwell_lpr_upon_triggered", cJSON_CreateString(viewChannelData[n].dwell_lpr_upon_triggered)); + } + if (unknown_object_max_proportion) { + strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "unknown_object_max_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_max_proportion)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "unknown_object_max_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_max_proportion)); +#endif + } + if (unknown_object_min_proportion) { + strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "unknown_object_min_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_min_proportion)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "unknown_object_min_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_min_proportion)); +#endif + } + if (confidence_unknown_object) { + strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence_unknown_object", cJSON_CreateString(viewChannelData[n].confidence_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "confidence_unknown_object", cJSON_CreateString(viewChannelData[n].confidence_unknown_object)); +#endif + } + if (confidence2_unknown_object) { + strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence2_unknown_object", cJSON_CreateString(viewChannelData[n].confidence2_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "confidence2_unknown_object", cJSON_CreateString(viewChannelData[n].confidence2_unknown_object)); +#endif + } + if (dwell_unknown_object) { + strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "dwell_unknown_object", cJSON_CreateString(viewChannelData[n].dwell_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "dwell_unknown_object", cJSON_CreateString(viewChannelData[n].dwell_unknown_object)); +#endif + } + + if (dwell_minute_focus_on) { + strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); + cJSON_ReplaceItemInObject(s_camera, "dwell_minute_focus_on", cJSON_CreateString(viewChannelData[n].dwell_minute_focus_on)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "dwell_minute_focus_on", cJSON_CreateString(viewChannelData[n].dwell_minute_focus_on)); +#endif + } + + if (person_obj_fov) { + strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); + cJSON_ReplaceItemInObject(s_camera, "person_obj_fov", cJSON_CreateString(viewChannelData[n].person_obj_fov)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "person_obj_fov", cJSON_CreateString(viewChannelData[n].person_obj_fov)); +#endif + } + if (getnetwork_buffer_id) { + if (strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) + { + g_change_getnetwork_buffer_id = 1; + } + + strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); + cJSON_ReplaceItemInObject(s_camera, "getnetwork_buffer_id", cJSON_CreateString(viewChannelData[n].getnetwork_buffer_id)); + } + if (red_light_zone) { + strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); + cJSON_ReplaceItemInObject(s_camera, "red_light_zone", cJSON_CreateString(viewChannelData[n].red_light_zone)); + } + if (no_give_way_zone_to_protect) { + strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_protect", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_protect)); + } + if (no_give_way_zone_to_keep_away) { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_keep_away", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_keep_away)); + } + if (no_give_way_zone_to_protect_2) { + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_protect_2", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_protect_2)); + } + if (no_give_way_zone_to_keep_away_2) { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_keep_away_2)); + } + if (ptz_sensitivity) { + viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); + } + if (ptz_tracking_resume_dwell) { + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_resume_dwell", cJSON_CreateString(viewChannelData[n].ptz_tracking_resume_dwell)); + } + if (cJSON_enable_only_show_metadata1) { + enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; + cJSON_ReplaceItemInObject(s_camera, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); + } + + if (ivs_mode) { + strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ivs_mode", cJSON_CreateString(viewChannelData[n].ivs_mode)); + } + + viewChannelData[n].channel_idx = n; + + if (tab_view_size) { + char temp_tab[50] = { 0 }; + strcpy(temp_tab, tab_view_size->valuestring); + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(temp_tab, outArray, "x"); + //printf("\n------UU:35\n"); + if (strlen(outArray[0]) >= 1) + viewChannelData[n].tab_view_width = atoi(outArray[0]); + if (strlen(outArray[0]) >= 1) + viewChannelData[n].tab_view_height = atoi(outArray[1]); + if (strlen(outArray[0]) >= 1 && strlen(outArray[0]) >= 1) { + cJSON_ReplaceItemInObject(s_camera, "tab_view_size", cJSON_CreateString(tab_view_size->valuestring)); + } + } + if (enable_anpr) { + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); +#endif + } + if (enable_face) { + if (strcmp(enable_face->valuestring, "Yes") == 0) + viewChannelData[n].enable_face = 1; + else + viewChannelData[n].enable_face = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_face", cJSON_CreateString(enable_face->valuestring)); + } + if (enable_traffic) { + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); +#endif + } + if (enable_logo) { + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_logo", cJSON_CreateString(enable_logo->valuestring)); + } + + viewChannelData[n].enable_traffic_light_zone = 0; + if (temp_detection_zone && s_detection_zone) { + //printf("\nTTTTTTTTTTTTTTT: 1\n"); + { + int i = 0; + cJSON_ArrayForEach(detect, temp_detection_zone) + { + if (detect) + { + int j = 0; + cJSON_ArrayForEach(s_detect, s_detection_zone) + { + if (i == j) + { + + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); + obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); + obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); + + enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); + enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); + enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); + parking_space = cJSON_GetObjectItem(detect, "parking_space"); + parking_line = cJSON_GetObjectItem(detect, "parking_line"); + set_distance = cJSON_GetObjectItem(detect, "set_distance"); + world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); + world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); + world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); + world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); + + if (i == 0) { + trigger_events_0 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_0 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 1) { + + trigger_events_1 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_1 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 2) { + + trigger_events_2 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_2 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 3) { + + trigger_events_3 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_3 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 4) { + + trigger_events_4 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_4 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 5) { + + trigger_events_5 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_5 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 6) { + + trigger_events_6 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_6 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 7) { + + trigger_events_7 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_7 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + + point_number = cJSON_GetObjectItem(detect, "point_number"); + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + if (obj_max_proportion_in_zone) + { + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); + cJSON_ReplaceItemInObject(s_detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[n][i].obj_max_proportion_in_zone)); + } + if (obj_min_proportion_in_zone) + { + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); + cJSON_ReplaceItemInObject(s_detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[n][i].obj_min_proportion_in_zone)); + } + if (ptz_zone_to_preset) + { + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); + cJSON_ReplaceItemInObject(s_detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[n][i].ptz_zone_to_preset)); + } + if (enable_speed) + { + strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_speed", cJSON_CreateString(viewDetectionZone[n][i].enable_speed)); + } + if (enable_radar_speed) + { + strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[n][i].enable_radar_speed)); + } + if (enable_ivs_zone) + { + strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[n][i].enable_ivs_zone)); + } + if (parking_space) + { + viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); + cJSON_ReplaceItemInObject(s_detect, "parking_space", cJSON_CreateString(parking_space->valuestring)); + } + if (parking_line) + { + viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); + cJSON_ReplaceItemInObject(s_detect, "parking_line", cJSON_CreateString(parking_line->valuestring)); + } + if (set_distance) + { + viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); + cJSON_ReplaceItemInObject(s_detect, "set_distance", cJSON_CreateString(set_distance->valuestring)); + } + if (world_distance_unit) + { + strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_distance_unit", cJSON_CreateString(world_distance_unit->valuestring)); + } + if (world_distance_side1) + { + viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_distance_side1", cJSON_CreateString(world_distance_side1->valuestring)); + viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; + viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; + } + if (world_distance_side2) + { + viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_distance_side2", cJSON_CreateString(world_distance_side2->valuestring)); + viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; + viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; + } + if (world_time_unit) + { + strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[n][i].world_time_unit)); + } + if (detection_time) + { + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + cJSON_ReplaceItemInObject(s_detect, "detection_time", cJSON_CreateString(viewDetectionZone[n][i].detection_time)); + } + if (metadata1) + { + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "metadata1", cJSON_CreateString(viewDetectionZone[n][i].metadata1)); + } + if (metadata2) + { + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "metadata2", cJSON_CreateString(viewDetectionZone[n][i].metadata2)); + } + if (metadata_stop) + { + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + cJSON_ReplaceItemInObject(s_detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[n][i].metadata_stop)); + } + if (link_to_counter) + { + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + cJSON_ReplaceItemInObject(s_detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[n][i].link_to_counter)); + } + if (enable_direction1) + { + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[n][i].enable_direction1)); + } + if (enable_direction2) + { + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_direction2", cJSON_CreateString(viewDetectionZone[n][i].enable_direction2)); + } + if (direction1) + { + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "direction1", cJSON_CreateString(viewDetectionZone[n][i].direction1)); + } + if (direction2) + { + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "direction2", cJSON_CreateString(viewDetectionZone[n][i].direction2)); + } + if (no_parking_time) + { + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + cJSON_ReplaceItemInObject(s_detect, "no_parking_time", cJSON_CreateString(no_parking_time->valuestring)); + } + if (no_parking_time_in_minute) + { + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + cJSON_ReplaceItemInObject(s_detect, "no_parking_time_in_minute", cJSON_CreateString(no_parking_time_in_minute->valuestring)); + } + if (queuing_count && strlen(queuing_count->valuestring) >= 1) + { + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + cJSON_ReplaceItemInObject(s_detect, "queuing_count", cJSON_CreateString(queuing_count->valuestring)); + } + + if (point_number) { + viewDetectionZone[n][i].point_num = point_number->valueint; + cJSON_ReplaceItemInObject(s_detect, "point_number", cJSON_CreateNumber(viewDetectionZone[n][i].point_num)); + } + if (x1) { + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].x)); + } + if (y1) { + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].y)); + } + if (x2) { + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].x)); + } + if (y2) { + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].y)); + } + if (x3) { + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].x)); + } + if (y3) { + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].y)); + } + if (x4) { + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].x)); + } + if (y4) { + viewDetectionZone[n][i].Points[3].y = y4->valueint; + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].y)); + } + if (x5) { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].x)); + } + if (y5) { + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].y)); + } + if (x6) { + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].x)); + } + if (y6) { + viewDetectionZone[n][i].Points[5].y = y6->valueint; + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].y)); + } + if (enable_traffic_light) { + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; + //UpdateTrafficLightZone(n); + } + cJSON_ReplaceItemInObject(s_detect, "enable_traffic_light", cJSON_CreateString(enable_traffic_light->valuestring)); + } + break; + } + j++; + } +#ifdef GY_OS_NOVA + if (detection_zone_small) { + j = 0; + cJSON_ArrayForEach(detect_small, detection_zone_small) + { + if (i == j) { + point_number = cJSON_GetObjectItem(detect, "point_number"); + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + if (point_number) { + cJSON_ReplaceItemInObject(detect_small, "point_number", cJSON_CreateNumber(viewDetectionZone[n][i].point_num)); + } + if (x1) { + cJSON_ReplaceItemInObject(detect_small, "x1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].x)); + } + if (y1) { + cJSON_ReplaceItemInObject(detect_small, "y1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].y)); + } + if (x2) { + cJSON_ReplaceItemInObject(detect_small, "x2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].x)); + } + if (y2) { + cJSON_ReplaceItemInObject(detect_small, "y2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].y)); + } + if (x3) { + cJSON_ReplaceItemInObject(detect_small, "x3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].x)); + } + if (y3) { + cJSON_ReplaceItemInObject(detect_small, "y3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].y)); + } + if (x4) { + cJSON_ReplaceItemInObject(detect_small, "x4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].x)); + } + if (y4) { + cJSON_ReplaceItemInObject(detect_small, "y4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].y)); + } + if (x5) { + cJSON_ReplaceItemInObject(detect_small, "x5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].x)); + } + if (y5) { + cJSON_ReplaceItemInObject(detect_small, "y5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].y)); + } + if (x6) { + cJSON_ReplaceItemInObject(detect_small, "x6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].x)); + } + if (y6) { + cJSON_ReplaceItemInObject(detect_small, "y6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].y)); + } + } + j++; + } + } +#endif + } + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + } + //printf("\nTTTTTTTTTTTTTTT: 2\n"); +#if 1 + + for (int i = 0; i < viewChannelData[n].count_zone; i++) { + + if (i == 0) { + trigger_events_temp = trigger_events_0; + s_trigger_events_temp = s_trigger_events_0; + } + else if (i == 1) { + trigger_events_temp = trigger_events_1; + s_trigger_events_temp = s_trigger_events_1; + } + else if (i == 2) { + trigger_events_temp = trigger_events_2; + s_trigger_events_temp = s_trigger_events_2; + } + else if (i == 3) { + trigger_events_temp = trigger_events_3; + s_trigger_events_temp = s_trigger_events_3; + } + else if (i == 4) { + trigger_events_temp = trigger_events_4; + s_trigger_events_temp = s_trigger_events_4; + } + else if (i == 5) { + trigger_events_temp = trigger_events_5; + s_trigger_events_temp = s_trigger_events_5; + } + else if (i == 6) { + trigger_events_temp = trigger_events_6; + s_trigger_events_temp = s_trigger_events_6; + } + else if (i == 7) { + trigger_events_temp = trigger_events_7; + s_trigger_events_temp = s_trigger_events_7; + } + + if (trigger_events_temp && s_trigger_events_temp) { + int k = 0; + + cJSON_ArrayForEach(detect, trigger_events_temp) + { + if (detect) + { + int m = 0; + + cJSON_ArrayForEach(s_detect, s_trigger_events_temp) + { + if (s_detect) { + cJSON * detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + cJSON * s_detect_event_id = cJSON_GetObjectItem(s_detect, "detect_event_id"); + + if (detect_event_id && s_detect_event_id) + { + if (strcmp(detect_event_id->valuestring, s_detect_event_id->valuestring) == 0) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + if (checked) + { + viewDetectionZone[n][i].trigger_event[m].checked = checked->valueint; + cJSON_ReplaceItemInObject(s_detect, "checked", cJSON_CreateNumber(viewDetectionZone[n][i].trigger_event[m].checked)); + } + if (detect_event_id) + { + strcpy(viewDetectionZone[n][i].trigger_event[m].detect_event_id, detect_event_id->valuestring); + cJSON_ReplaceItemInObject(s_detect, "detect_event_id", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].detect_event_id)); + } + if (detect_event_name) + { + strcpy(viewDetectionZone[n][i].trigger_event[m].detect_event_name, detect_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect, "detect_event_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].detect_event_name)); + } + if (post_event_name) { + strcpy(viewDetectionZone[n][i].trigger_event[m].post_event_name, post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect, "post_event_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].post_event_name)); + } + if (counter_name) { + strcpy(viewDetectionZone[n][i].trigger_event[m].counter_name, counter_name->valuestring); + cJSON_ReplaceItemInObject(s_detect, "counter_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].counter_name)); + } + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][i].trigger_event[m].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][i].trigger_event[m].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][i].trigger_event[m].counter_increment = 0; + else + viewDetectionZone[n][i].trigger_event[m].counter_increment = -2; + cJSON_ReplaceItemInObject(s_detect, "counter_increment", cJSON_CreateString(counter_increment->valuestring)); + } + + break; + } + } + } + m++; + } + } + k++; + } + } + + } +#endif + //printf("\nTTTTTTTTTTTTTTT: 3\n"); + } + + } + } + + cJSON *system_setting,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*enable_person_independent,*enable_onvif_profile_m, *enable_crop_mode,*cloud_enable_snap, *cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue, *language, *display_properties,*display_OSD, *display_dash, + *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password,*enable_system_logs,*enable_email_jpeg, *send_counter_at_specific_hour,*enable_email_notification,*email_reset_time_interval, + *sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory, *ftp_jpeg_file_name_format, *ftp_jpeg_file_name; + cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; + + cJSON *s_system_setting; + + system_setting = cJSON_GetObjectItem(root, "system_setting"); + s_system_setting = cJSON_GetObjectItem(s_root, "system_setting"); + +#ifdef GY_OS_NOVA + system_setting_small = cJSON_GetObjectItem(root_small, "system_setting"); +#endif + + if (system_setting) { + enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); + enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); + enable_crop_mode = cJSON_GetObjectItem(system_setting, "enable_crop_mode"); + nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); + tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); + enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); + enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); + enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); + enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); + cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); + cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); + cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); + cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); + cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); + cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); + cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); + cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); + language = cJSON_GetObjectItem(system_setting, "language"); + display_properties = cJSON_GetObjectItem(system_setting, "display properties"); + display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); + display_dash = cJSON_GetObjectItem(system_setting, "display dash"); + enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); + enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); + enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); + force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); + force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); + enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); + + enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); + ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); + + enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); + cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); + cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); + enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); + cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); + cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); + + enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); + enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); + getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); + getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); + osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); + osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); + osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); + enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); + osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); + osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); + sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); + enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); + external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); + external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); + external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); + external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); + enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); + enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); + enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); + send_counter_at_specific_hour = cJSON_GetObjectItem(system_setting, "send_counter_at_specific_hour"); + email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); + + enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); + ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); + ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); + ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); + ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); + ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); + ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); + ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); + + if (enable_person_independent) + { + strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_person_independent", cJSON_CreateString(SystemSetting.enable_person_independent)); + } + + if (enable_onvif_profile_m) + { + strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_onvif_profile_m", cJSON_CreateString(SystemSetting.enable_onvif_profile_m)); + } + + if (enable_crop_mode) + { + strcpy(SystemSetting.enable_crop_mode, enable_crop_mode->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_crop_mode", cJSON_CreateString(SystemSetting.enable_crop_mode)); + } + + if (nms_thres) + { + strcpy(SystemSetting.nms_thres, nms_thres->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "nms_thres", cJSON_CreateString(SystemSetting.nms_thres)); + } + + if (tracking_id_dwell) + { + strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "tracking_id_dwell", cJSON_CreateString(SystemSetting.tracking_id_dwell)); + } + + if (cloud_enable_snap) + { + strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_enable_snap", cJSON_CreateString(SystemSetting.cloud_enable_snap)); + } + if (enable_cloud) + { + strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud", cJSON_CreateString(SystemSetting.enable_cloud)); + } + if (enable_special_edition) + { + strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_special_edition", cJSON_CreateString(SystemSetting.enable_special_edition)); + } + if (enable_python) + { + strcpy(SystemSetting.enable_python, enable_python->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_python", cJSON_CreateString(SystemSetting.enable_python)); + } + if (enable_python_file) + { + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_python_file", cJSON_CreateString(SystemSetting.enable_python_file)); + + } + if (enable_low_cpu_usage) + { + strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_low_cpu_usage", cJSON_CreateString(SystemSetting.enable_low_cpu_usage)); + } + if (cloud_enable_notification) + { + strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_enable_notification", cJSON_CreateString(SystemSetting.cloud_enable_notification)); + } + if (cloud_account) + { + strcpy(SystemSetting.cloud_account, cloud_account->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_account", cJSON_CreateString(SystemSetting.cloud_account)); + } + if (cloud_password) + { + strcpy(SystemSetting.cloud_password, cloud_password->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_password", cJSON_CreateString(SystemSetting.cloud_password)); + } + if (cloud_notification_dwell) + { + strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_notification_dwell", cJSON_CreateString(SystemSetting.cloud_notification_dwell)); + } + if (cloud_statue) + { + strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_statue", cJSON_CreateString(SystemSetting.cloud_statue)); + } + if (cloud_v2_statue) + { + strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_statue", cJSON_CreateString(SystemSetting.cloud_v2_statue)); + } + if (cloud_record_v2_statue) + { + strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_statue", cJSON_CreateString(SystemSetting.cloud_record_v2_statue)); + } + if (language) + { + strcpy(SystemSetting.language, language->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "language", cJSON_CreateString(SystemSetting.language)); + } + if (display_properties) + { + strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "display properties", cJSON_CreateString(SystemSetting.enable_display_properties)); + } +#ifdef GY_OS_AMBA + if (display_OSD) + { + pthread_mutex_lock(&mutex_run_one_net); + pthread_mutex_lock(&mutex_get_network_input); + strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + cJSON_ReplaceItemInObject(s_system_setting, "display OSD", cJSON_CreateString(SystemSetting.enable_display_OSD)); + } +#endif + + if (display_dash) + { + activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); + } + if (enable_special_char) + { + strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_special_char", cJSON_CreateString(SystemSetting.enable_special_char)); + } + if (enable_bounding_box) + { + strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_bounding_box", cJSON_CreateString(SystemSetting.enable_bounding_box)); + } + if (enable_dwell_bounding_box) + { + strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_dwell_bounding_box", cJSON_CreateString(SystemSetting.enable_dwell_bounding_box)); + } + if (force_i_to_one) + { + strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "force_i_to_one", cJSON_CreateString(SystemSetting.force_i_to_one)); + } + if (force_o_to_zero) + { + strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "force_o_to_zero", cJSON_CreateString(SystemSetting.force_o_to_zero)); + } + if (enable_plate_angle_correction) + { + strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_plate_angle_correction", cJSON_CreateString(SystemSetting.enable_plate_angle_correction)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(system_setting_small, "enable_plate_angle_correction", cJSON_CreateString(SystemSetting.enable_plate_angle_correction)); +#endif + } + if (enable_ai_mirror) + { + strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_ai_mirror", cJSON_CreateString(SystemSetting.enable_ai_mirror)); + } + if (ai_mirror_feature) + { + strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ai_mirror_feature", cJSON_CreateString(SystemSetting.ai_mirror_feature)); + } + if (enable_cloud_v2) + { + strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud_v2", cJSON_CreateString(SystemSetting.enable_cloud_v2)); + } + if (cloud_v2_notification_dwell) + { + strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(SystemSetting.cloud_v2_notification_dwell)); + } + if (cloud_v2_content) + { + strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_content", cJSON_CreateString(SystemSetting.cloud_v2_content)); + } + if (enable_cloud_record_v2) + { + strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud_record_v2", cJSON_CreateString(SystemSetting.enable_cloud_record_v2)); + } + if (cloud_record_v2_notification_dwell) + { + strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(SystemSetting.cloud_record_v2_notification_dwell)); + } + if (cloud_record_v2_content) + { + strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_content", cJSON_CreateString(SystemSetting.cloud_record_v2_content)); + } + if (enable_post_only_if_both_detected) + { + strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(SystemSetting.enable_post_only_if_both_detected)); + } + if (enable_getalarmmotion_snap) + { + strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(SystemSetting.enable_getalarmmotion_snap)); + } + if (getimage_encoder_id) + { + strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "getimage_encoder_id", cJSON_CreateString(SystemSetting.getimage_encoder_id)); + } + if (getimage_encoder_id_HD) + { + strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "getimage_encoder_id_HD", cJSON_CreateString(SystemSetting.getimage_encoder_id_HD)); + } + if (osd_encoder_id) + { + strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_encoder_id", cJSON_CreateString(SystemSetting.osd_encoder_id)); + } + if (osd_font_size) + { + strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_font_size", cJSON_CreateString(SystemSetting.osd_font_size)); + } + if (osd_outline_lilin) + { + strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_outline_lilin", cJSON_CreateString(SystemSetting.osd_outline_lilin)); + } + if (enable_osd_bottom) + { + strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_osd_bottom", cJSON_CreateString(SystemSetting.enable_osd_bottom)); + } + if (osd_bottom_bg_tran) + { + strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_bottom_bg_tran", cJSON_CreateString(SystemSetting.osd_bottom_bg_tran)); + } + if (osd_bottom_content) + { + strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_bottom_content", cJSON_CreateString(SystemSetting.osd_bottom_content)); + } + if (sensors_type) + { + strcpy(SystemSetting.sensors_type, sensors_type->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "sensors_type", cJSON_CreateString(SystemSetting.sensors_type)); + } + if (enable_sync_external_lpr_db) + { + strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(SystemSetting.enable_sync_external_lpr_db)); + } + if (external_lpr_db_IP) + { + strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_IP", cJSON_CreateString(SystemSetting.external_lpr_db_IP)); + } + if (external_lpr_db_port) + { + strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_port", cJSON_CreateString(SystemSetting.external_lpr_db_port)); + } + if (external_lpr_db_username) + { + strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_username", cJSON_CreateString(SystemSetting.external_lpr_db_username)); + } + if (external_lpr_db_password) + { + strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_password", cJSON_CreateString(SystemSetting.external_lpr_db_password)); + } + + if (enable_system_logs) + { + strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_system_logs", cJSON_CreateString(SystemSetting.enable_system_logs)); + } + + if (enable_email_jpeg) + { + strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_email_jpeg", cJSON_CreateString(SystemSetting.enable_email_jpeg)); + } + + if (send_counter_at_specific_hour) + { + strcpy(SystemSetting.send_counter_at_specific_hour, send_counter_at_specific_hour->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "send_counter_at_specific_hour", cJSON_CreateString(SystemSetting.send_counter_at_specific_hour)); + } + + if (email_reset_time_interval) + { + strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "email_reset_time_interval", cJSON_CreateString(SystemSetting.email_reset_time_interval)); + } + + if (enable_ftp) + { + strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_ftp", cJSON_CreateString(SystemSetting.enable_ftp)); + } + + if (ftp_url) + { + strcpy(SystemSetting.ftp_url, ftp_url->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_url", cJSON_CreateString(SystemSetting.ftp_url)); + } + + if (ftp_port) + { + strcpy(SystemSetting.ftp_port, ftp_port->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_port", cJSON_CreateString(SystemSetting.ftp_port)); + } + + if (ftp_username) + { + strcpy(SystemSetting.ftp_username, ftp_username->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_username", cJSON_CreateString(SystemSetting.ftp_username)); + } + + if (ftp_password) + { + strcpy(SystemSetting.ftp_password, ftp_password->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_password", cJSON_CreateString(SystemSetting.ftp_password)); + } + + if (ftp_remote_directory) + { + strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_remote_directory", cJSON_CreateString(SystemSetting.ftp_remote_directory)); + } + + if (ftp_jpeg_file_name_format) + { + strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(SystemSetting.ftp_jpeg_file_name_format)); + } + + if (ftp_jpeg_file_name) + { + strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_jpeg_file_name", cJSON_CreateString(SystemSetting.ftp_jpeg_file_name)); + } + + if (enable_email_notification) + { + strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_email_notification", cJSON_CreateString(SystemSetting.enable_email_notification)); + } + + } + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(config_PATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(config_PATH, config_bakPATH); + check_if_setfile_OK = 1; + g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + +#ifdef GY_OS_NOVA + JsonString = cJSON_Print(root_small); + + f = fopen(config_smallPATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } +#endif + +#ifdef GY_OS_AMBA + if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { + if (enable_ai_mirror && ai_mirror_feature){ + if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) + { + if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + else { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + } + } + } +#endif + + if (ftp_remote_directory) { + if (strlen(SystemSetting.ftp_remote_directory) >= 1) { + net_curl_ftp_build_folder(); + } + } + +#ifdef GY_OS_AMBA + + viewChannelData[0].speed_view_width_ratio = (float)(1920 / 889); + viewChannelData[0].speed_view_height_ratio = (float)(1080 / 500); + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + if (strncmp(viewDetectionZone[0][i].enable_speed, "Yes", strlen("Yes")) == 0) + { + int social_zone_idx = i; + if (social_zone_idx >= 0) + { + pthread_mutex_lock(&mutex_perspective_transform); + if (viewDetectionZone[0][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[0][i].PerspectiveTransformArray); + viewDetectionZone[0][i].PerspectiveTransformArray = GetPerspectiveTransformArray(0, social_zone_idx); + pthread_mutex_unlock(&mutex_perspective_transform); + } + } + } + +#endif + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + +#ifdef GY_OS_NOVA + if (root_small) { + cJSON_Delete(root_small); + root_small = NULL; + } +#endif + } + else { + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } +#ifdef GY_OS_NOVA + if (fileBuf3) { + free(fileBuf3); + fileBuf3 = NULL; + } +#endif + printf("\nFail to read config_import.json or config.json\n"); + } + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile)\n"); + } + else { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile#2)\n"); + } + + pthread_mutex_unlock(&mutex_config_json); + + closesocket(cli_socket); + +#ifdef GY_OS_AMBA + + /* + int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + + UpdatePTZConfigSetting(); + + /* + UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, + viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + +#endif + + //Reload cold zone + /*int iReadCodeZoneRet = */ ReadColdZoneJsonFile(); + + set_metadata(); + +#ifdef GY_OS_AMBA + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + if (strstr(viewDetectionZone[0][index_zone].metadata1, "qrcode") != NULL || + strstr(viewDetectionZone[0][index_zone].metadata1, "barcode") != NULL || + g_check_h264_gop != 0) + { + if (run_check_current_resolution == -1) { + run_check_current_resolution = 0; + if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) + printf("\ncheck current resolution thread failed #2\n"); + run_check_current_resolution = 1; + break; + } + } + } +#endif +#ifdef GY_OS_V_SERIES + +#else + set_counter_zone(); +#endif + check_if_correct_post = 0; + + //printf("\n------------setconfigfile end\n"); + } + else if (strncmp(urlBuffer, "/seteventsfile", strlen("/seteventsfile")) == 0) + { + pthread_mutex_lock(&mutex_events_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char events_importPATH[1024]; + strcpy(events_importPATH, exePath); + strcat(events_importPATH, "events_import.json"); + + char events_PATH[1024]; + strcpy(events_PATH, exePath); + strcat(events_PATH, "events.json"); + + FILE *pFile; + + if ((pFile = fopen(events_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(events_importPATH); + char* fileBuf2 = ReadAllBytes(events_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (root && s_root) + { + cJSON *notification, *enable_post,*events_default_version,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, + *post_customized_header; + cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max, *enable_heatmap, *heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + cJSON *s_notification, *s_http_post_events, *s_detect2; + + notification = cJSON_GetObjectItem(root, "notification"); + s_notification = cJSON_GetObjectItem(s_root, "notification"); + + if (notification) { + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + s_http_post_events = cJSON_GetObjectItem(s_notification, "http_post_events"); + + if (events_default_version) + { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + cJSON_ReplaceItemInObject(s_notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + } + + if(enable_post) + { + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_post", cJSON_CreateString(enable_post->valuestring)); + } + if (enable_snmp_post) + { + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_post", cJSON_CreateString(enable_snmp_post->valuestring)); + } + if (enable_heartbeat) + { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); + } + if (enable_snmp_heartbeat) + { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); + } + if (snmp_heartbeat_dwell) + { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); + } + if (snmp_heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); + } + if (enable_check_ptz_start_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); + } + if (enable_check_ptz_end_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); + } + if (enable_only_once_to_post) + { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); + } + if (enable_obj_once_to_post) + { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); + } + if (enable_location_once_to_post) + { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); + } + if (enable_nvr_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); + } + if (enable_8592_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); + } + if (dwell_to_the_same_location) + { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + cJSON_ReplaceItemInObject(s_notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); + } + if (heartbeat_dwell) + { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); + } + if (heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); + } + if (ptz_start_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); + } + if (ptz_end_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); + } + if (heatmap_max) + { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); + } + if (enable_heatmap) + { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); + } + if (heatmap_frequency) + { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); + } + if (lpr_title) + { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + cJSON_ReplaceItemInObject(s_notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); + } + if (enable_counter_snap) + { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); + } + if (enable_barcode_qr) + { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); + } + if (http_post_events) + { + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + if (detect2) + { + int j = 0; + cJSON_ArrayForEach(s_detect2, s_http_post_events) + { + if(i==j) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + + if (post_protocol) + { + strcpy(postEventList[j].post_protocol, post_protocol->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_protocol", cJSON_CreateString(postEventList[j].post_protocol)); + } + if (post_event_method) + { + strcpy(postEventList[j].post_event_method, post_event_method->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_method", cJSON_CreateString(postEventList[j].post_event_method)); + } + if (post_event_name2) { + strcpy(postEventList[j].post_event_name, post_event_name2->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_name", cJSON_CreateString(postEventList[j].post_event_name)); + } + if (post_host_ip) + { + strcpy(postEventList[j].post_host_ip, post_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_ip", cJSON_CreateString(postEventList[j].post_host_ip)); + } + if(post_host_port) + { + strcpy(postEventList[j].post_host_port, post_host_port->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_port", cJSON_CreateString(postEventList[j].post_host_port)); + } + if (post_url) + { + strcpy(postEventList[j].post_url, post_url->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_url", cJSON_CreateString(postEventList[j].post_url)); + } + if (post_username) + { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + //strcpy(postEventList[j].post_username, post_username->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_username", cJSON_CreateString(post_username->valuestring)); + } + if (post_password) + { + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + //strcpy(postEventList[j].post_password, post_password->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_password", cJSON_CreateString(post_password->valuestring)); + } + if (post_content) + { + strcpy(postEventList[j].post_content, post_content->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_content", cJSON_CreateString(postEventList[j].post_content)); + } + if(post_customized_header) + { + strcpy(postEventList[j].post_customized_header, post_customized_header->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_customized_header", cJSON_CreateString(postEventList[j].post_customized_header)); + } + if (post_sequence) + { + strcpy(postEventList[j].post_sequence, post_sequence->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_sequence", cJSON_CreateString(postEventList[j].post_sequence)); + } + if (post_timeout) + { + strcpy(postEventList[j].post_timeout, post_timeout->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_timeout", cJSON_CreateString(postEventList[j].post_timeout)); + } + if (post_file_format) + { + strcpy(postEventList[j].post_file_format, post_file_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_file_format", cJSON_CreateString(postEventList[j].post_file_format)); + } + if (post_jpeg_file_name_format) + { + strcpy(postEventList[j].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[j].post_jpeg_file_name_format)); + } + if (post_jpeg_file_name) + { + strcpy(postEventList[j].post_jpeg_file_name, post_jpeg_file_name->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name", cJSON_CreateString(postEventList[j].post_jpeg_file_name)); + } + break; + } + j++; + } + } + i++; + } + } + + } + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *enable_reset_only_cloud,*enable_linked_to_dwell_time;// *reset_at, *enable_time_range, *time_range_from, *time_range_to, + cJSON *link_to_post_event_name, *post_interval; + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone,*counter_b_zone,*counter_c_name, + *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + cJSON *s_event_counter_setting, *s_event_counters,*s_detect3,*s_counter_name,*s_a_report,*s_report_counters, *s_a_snmp, *s_snmp_management; + + event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); + s_event_counter_setting = cJSON_GetObjectItem(s_root, "event_counter_setting"); +#ifdef GY_OS_V_SERIES + +#else + if (event_counter_setting) + { + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + s_event_counters = cJSON_GetObjectItem(s_event_counter_setting, "event_counters"); + if (event_counters) + { + int i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + if (detect3) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + if (counter_name) { + int j = 0; + cJSON_ArrayForEach(s_detect3, s_event_counters) + { + s_counter_name = cJSON_GetObjectItem(s_detect3, "counter_name"); + if(strcmp(counter_name->valuestring, s_counter_name->valuestring)==0) + { + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + //reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + //enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + //time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + //time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + if (counter_name) + { + strcpy(eventCounterList[j].counter_name, counter_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_name", cJSON_CreateString(eventCounterList[j].counter_name)); + } + if (counter_cust_name) + { + strcpy(eventCounterList[j].counter_cust_name, counter_cust_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_cust_name", cJSON_CreateString(eventCounterList[j].counter_cust_name)); + } + if (counter_unit) + { + strcpy(eventCounterList[j].counter_unit, counter_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_unit", cJSON_CreateString(eventCounterList[j].counter_unit)); + } + if (reset_value) + { + eventCounterList[j].reset_value = atoi(reset_value->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_value", cJSON_CreateString(reset_value->valuestring)); + } + if (enable_reset_time_interval) + { + strcpy(eventCounterList[j].enable_reset_time_interval, enable_reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[j].enable_reset_time_interval)); + } + if (reset_time_interval) + { + strcpy(eventCounterList[j].reset_time_interval, reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_time_interval", cJSON_CreateString(eventCounterList[j].reset_time_interval)); + } + +#if 0 + + if (reset_at) + { + strcpy(eventCounterList[j].reset_at, reset_at->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_at", cJSON_CreateString(eventCounterList[j].reset_at)); + struct tm tm; + strptime_c(eventCounterList[j].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetResetAt = mktime(&tm); + struct tm *resetTime = localtime(&eventCounterList[j].timetResetAt); + eventCounterList[j].reset_month = resetTime->tm_mon; + eventCounterList[j].reset_month_day = resetTime->tm_mday; + eventCounterList[j].reset_week_day = resetTime->tm_wday; + eventCounterList[j].reset_hour = resetTime->tm_hour; + eventCounterList[j].reset_min = resetTime->tm_min; + eventCounterList[j].reset_sec = resetTime->tm_sec; + } + + if (enable_time_range) + { + strcpy(eventCounterList[j].enable_time_range, enable_time_range->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_time_range", cJSON_CreateString(eventCounterList[j].enable_time_range)); + } + if (time_range_from) + { + strcpy(eventCounterList[j].time_range_from, time_range_from->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_from", cJSON_CreateString(eventCounterList[j].time_range_from)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeFrom = mktime(&tm); + } + if (time_range_to) + { + strcpy(eventCounterList[j].time_range_to, time_range_to->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_to", cJSON_CreateString(eventCounterList[j].time_range_to)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeTo = mktime(&tm); + } +#endif + + if (link_to_post_event_name) + { + strcpy(eventCounterList[j].link_to_post_event_name, link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "link_to_post_event_name", cJSON_CreateString(eventCounterList[j].link_to_post_event_name)); + } + if (post_interval) + { + strcpy(eventCounterList[j].post_interval, post_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "post_interval", cJSON_CreateString(eventCounterList[j].post_interval)); + } + if (enable_reset_only_cloud) { + strcpy(eventCounterList[j].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[j].enable_reset_only_cloud)); + } + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[j].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[j].enable_linked_to_dwell_time)); + } + break; + } + j++; + } + } + } + + i++; + } + +#if 0 + if (strcmp(SystemSetting.cloud_enable_notification, "No") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } + } +#endif + } + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + s_report_counters = cJSON_GetObjectItem(s_event_counter_setting, "report_counters"); + + if (report_counters) { + int i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) + { + int j = 0; + cJSON_ArrayForEach(s_a_report, s_report_counters) + { + if (i == j) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + + if (counter_a) + { + strcpy(reportCounterList[j].counter_a, counter_a->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a", cJSON_CreateString(reportCounterList[j].counter_a)); + } + + if (counter_a_name) + { + strcpy(reportCounterList[j].counter_a_name, counter_a_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_name", cJSON_CreateString(reportCounterList[j].counter_a_name)); + } + + if (counter_a_zone) + { + strcpy(reportCounterList[j].counter_a_zone, counter_a_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[j].counter_a_zone)); + } + + if (counter_b) + { + strcpy(reportCounterList[j].counter_b, counter_b->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b", cJSON_CreateString(reportCounterList[j].counter_b)); + } + + if (counter_b_name) + { + strcpy(reportCounterList[j].counter_b_name, counter_b_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_name", cJSON_CreateString(reportCounterList[j].counter_b_name)); + } + + if (counter_b_zone) + { + strcpy(reportCounterList[j].counter_b_zone, counter_b_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[j].counter_b_zone)); + } + + if (counter_c_name) + { + strcpy(reportCounterList[j].counter_c_name, counter_c_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_c_name", cJSON_CreateString(reportCounterList[j].counter_c_name)); + } + + if (report_max_value) + { + strcpy(reportCounterList[j].report_max_value, report_max_value->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "report_max_value", cJSON_CreateString(reportCounterList[j].report_max_value)); + } + + if (enable_report) + { + strcpy(reportCounterList[j].enable_report, enable_report->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "enable_report", cJSON_CreateString(reportCounterList[j].enable_report)); + } + + if (counter_mode) + { + strcpy(reportCounterList[j].counter_mode, counter_mode->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_mode", cJSON_CreateString(reportCounterList[j].counter_mode)); + } + + if (initial_icon) + { + strcpy(reportCounterList[j].initial_icon, initial_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "initial_icon", cJSON_CreateString(reportCounterList[j].initial_icon)); + } + + if (detection_output) + { + strcpy(reportCounterList[j].detection_output, detection_output->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "detection_output", cJSON_CreateString(reportCounterList[j].detection_output)); + } + + if (output_icon) + { + strcpy(reportCounterList[j].output_icon, output_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "output_icon", cJSON_CreateString(reportCounterList[j].output_icon)); + } + + break; + } + j++; + } + } + + i++; + } + } + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + s_snmp_management = cJSON_GetObjectItem(s_event_counter_setting, "snmp_management"); + + if (snmp_management) { + int i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) + { + int j = 0; + cJSON_ArrayForEach(s_a_snmp, s_snmp_management) + { + if (i == j) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + + if (snmp_event_name) + { + strcpy(SNMPManagementList[j].snmp_event_name, snmp_event_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[j].snmp_event_name)); + } + + if (snmp_version) + { + strcpy(SNMPManagementList[j].snmp_version, snmp_version->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[j].snmp_version)); + } + + if (snmp_group_name) + { + strcpy(SNMPManagementList[j].snmp_group_name, snmp_group_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[j].snmp_group_name)); + } + + if (snmp_host_ip) + { + strcpy(SNMPManagementList[j].snmp_host_ip, snmp_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[j].snmp_host_ip)); + } + + if (snmp_host_port) + { + strcpy(SNMPManagementList[j].snmp_host_port, snmp_host_port->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[j].snmp_host_port)); + } + + if (snmp_oid) + { + strcpy(SNMPManagementList[j].snmp_oid, snmp_oid->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[j].snmp_oid)); + } + + if (snmp_value) + { + strcpy(SNMPManagementList[j].snmp_value, snmp_value->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[j].snmp_value)); + } + + if (snmp_type) + { + strcpy(SNMPManagementList[j].snmp_type, snmp_type->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[j].snmp_type)); + } + break; + } + j++; + } + } + + i++; + } + } + } +#endif + cJSON *email_setting, *email_content; + cJSON *s_email_setting; + + email_setting = cJSON_GetObjectItem(root, "email_setting"); + s_email_setting = cJSON_GetObjectItem(s_root, "email_setting"); + + if (email_setting) + { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) { + strcpy(emailData.email_content, email_content->valuestring); + cJSON_ReplaceItemInObject(s_email_setting, "email_content", cJSON_CreateString(emailData.email_content)); + } + } + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(events_PATH, "w"); + if (f != NULL) + { + + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(events_PATH, events_bakPATH); + + check_if_setfile_OK = 1; + g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read events_import.json or events.json\n"); + } + } + + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventsfile)\n"); + } + else { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventsfile#2)\n"); + } + + pthread_mutex_unlock(&mutex_events_json); + + closesocket(cli_socket); +#ifdef GY_OS_V_SERIES + +#else + set_counter_zone(); +#endif + check_if_correct_post = 0; + } + else if (strncmp(urlBuffer, "/seteventscustom2", strlen("/seteventscustom2")) == 0) + { + pthread_mutex_lock(&mutex_events_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char events_importPATH[1024]; + strcpy(events_importPATH, exePath); + strcat(events_importPATH, "events_custom_2_import.json"); + + char events_PATH[1024]; + strcpy(events_PATH, exePath); + strcat(events_PATH, "events_custom_2.json"); + + FILE *pFile; + + if ((pFile = fopen(events_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(events_importPATH); + char* fileBuf2 = ReadAllBytes(events_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (root && s_root) + { + cJSON *notification, *events_default_version,*enable_post, *enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, + *post_customized_header; + cJSON *post_sequence, *post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post, *enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion, *heatmap_max, *enable_heatmap, *heatmap_frequency, *lpr_title, *enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking, *enable_check_ptz_end_autotracking, *ptz_start_autotracking_link_to_post_event_name, *ptz_end_autotracking_link_to_post_event_name; + + cJSON *s_notification, *s_http_post_events, *s_detect2; + + notification = cJSON_GetObjectItem(root, "notification"); + s_notification = cJSON_GetObjectItem(s_root, "notification"); + + if (notification) { + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + s_http_post_events = cJSON_GetObjectItem(s_notification, "http_post_events"); + + if (events_default_version) + { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + cJSON_ReplaceItemInObject(s_notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + } + + if (enable_post) + { + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_post", cJSON_CreateString(enable_post->valuestring)); + } + if (enable_snmp_post) + { + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_post", cJSON_CreateString(enable_snmp_post->valuestring)); + } + if (enable_heartbeat) + { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); + } + if (enable_snmp_heartbeat) + { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); + } + if (snmp_heartbeat_dwell) + { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); + } + if (snmp_heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); + } + if (enable_check_ptz_start_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); + } + if (enable_check_ptz_end_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); + } + if (enable_only_once_to_post) + { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); + } + if (enable_obj_once_to_post) + { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); + } + if (enable_location_once_to_post) + { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); + } + if (enable_nvr_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); + } + if (enable_8592_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); + } + if (dwell_to_the_same_location) + { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + cJSON_ReplaceItemInObject(s_notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); + } + if (heartbeat_dwell) + { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); + } + if (heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); + } + if (ptz_start_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); + } + if (ptz_end_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); + } + if (heatmap_max) + { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); + } + if (enable_heatmap) + { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); + } + if (heatmap_frequency) + { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); + } + if (lpr_title) + { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + cJSON_ReplaceItemInObject(s_notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); + } + if (enable_counter_snap) + { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); + } + if (enable_barcode_qr) + { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); + } + if (http_post_events) + { + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + if (detect2) + { + int j = 0; + cJSON_ArrayForEach(s_detect2, s_http_post_events) + { + if (i == j) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + + if (post_protocol) + { + strcpy(postEventList[j].post_protocol, post_protocol->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_protocol", cJSON_CreateString(postEventList[j].post_protocol)); + } + if (post_event_method) + { + strcpy(postEventList[j].post_event_method, post_event_method->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_method", cJSON_CreateString(postEventList[j].post_event_method)); + } + if (post_event_name2) { + strcpy(postEventList[j].post_event_name, post_event_name2->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_name", cJSON_CreateString(postEventList[j].post_event_name)); + } + if (post_host_ip) + { + strcpy(postEventList[j].post_host_ip, post_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_ip", cJSON_CreateString(postEventList[j].post_host_ip)); + } + if (post_host_port) + { + strcpy(postEventList[j].post_host_port, post_host_port->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_port", cJSON_CreateString(postEventList[j].post_host_port)); + } + if (post_url) + { + strcpy(postEventList[j].post_url, post_url->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_url", cJSON_CreateString(postEventList[j].post_url)); + } + if (post_username) + { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + //strcpy(postEventList[j].post_username, post_username->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_username", cJSON_CreateString(post_username->valuestring)); + } + if (post_password) + { + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + //strcpy(postEventList[j].post_password, post_password->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_password", cJSON_CreateString(post_password->valuestring)); + } + if (post_content) + { + strcpy(postEventList[j].post_content, post_content->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_content", cJSON_CreateString(postEventList[j].post_content)); + } + if (post_customized_header) + { + strcpy(postEventList[j].post_customized_header, post_customized_header->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_customized_header", cJSON_CreateString(postEventList[j].post_customized_header)); + } + if (post_sequence) + { + strcpy(postEventList[j].post_sequence, post_sequence->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_sequence", cJSON_CreateString(postEventList[j].post_sequence)); + } + if (post_timeout) + { + strcpy(postEventList[j].post_timeout, post_timeout->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_timeout", cJSON_CreateString(postEventList[j].post_timeout)); + } + if (post_file_format) + { + strcpy(postEventList[j].post_file_format, post_file_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_file_format", cJSON_CreateString(postEventList[j].post_file_format)); + } + if (post_jpeg_file_name_format) + { + strcpy(postEventList[j].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[j].post_jpeg_file_name_format)); + } + if (post_jpeg_file_name) + { + strcpy(postEventList[j].post_jpeg_file_name, post_jpeg_file_name->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name", cJSON_CreateString(postEventList[j].post_jpeg_file_name)); + } + break; + } + j++; + } + } + i++; + } + } + + } + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name, *counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *enable_reset_only_cloud, *enable_linked_to_dwell_time;// *reset_at, *enable_time_range, *time_range_from, *time_range_to, + cJSON *link_to_post_event_name, *post_interval; + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, + *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon, *counter_mode; + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + cJSON *s_event_counter_setting, *s_event_counters, *s_detect3, *s_counter_name, *s_a_report, *s_report_counters, *s_a_snmp, *s_snmp_management; + + event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); + s_event_counter_setting = cJSON_GetObjectItem(s_root, "event_counter_setting"); +#ifdef GY_OS_V_SERIES + +#else + if (event_counter_setting) + { + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + s_event_counters = cJSON_GetObjectItem(s_event_counter_setting, "event_counters"); + if (event_counters) + { + int i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + if (detect3) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + if (counter_name) { + int j = 0; + cJSON_ArrayForEach(s_detect3, s_event_counters) + { + s_counter_name = cJSON_GetObjectItem(s_detect3, "counter_name"); + if (strcmp(counter_name->valuestring, s_counter_name->valuestring) == 0) + { + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + //reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + //enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + //time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + //time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + if (counter_name) + { + strcpy(eventCounterList[j].counter_name, counter_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_name", cJSON_CreateString(eventCounterList[j].counter_name)); + } + if (counter_cust_name) + { + strcpy(eventCounterList[j].counter_cust_name, counter_cust_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_cust_name", cJSON_CreateString(eventCounterList[j].counter_cust_name)); + } + if (counter_unit) + { + strcpy(eventCounterList[j].counter_unit, counter_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_unit", cJSON_CreateString(eventCounterList[j].counter_unit)); + } + if (reset_value) + { + eventCounterList[j].reset_value = atoi(reset_value->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_value", cJSON_CreateString(reset_value->valuestring)); + } + if (enable_reset_time_interval) + { + strcpy(eventCounterList[j].enable_reset_time_interval, enable_reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[j].enable_reset_time_interval)); + } + if (reset_time_interval) + { + strcpy(eventCounterList[j].reset_time_interval, reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_time_interval", cJSON_CreateString(eventCounterList[j].reset_time_interval)); + } + + #if 0 + + if (reset_at) + { + strcpy(eventCounterList[j].reset_at, reset_at->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_at", cJSON_CreateString(eventCounterList[j].reset_at)); + struct tm tm; + strptime_c(eventCounterList[j].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetResetAt = mktime(&tm); + struct tm *resetTime = localtime(&eventCounterList[j].timetResetAt); + eventCounterList[j].reset_month = resetTime->tm_mon; + eventCounterList[j].reset_month_day = resetTime->tm_mday; + eventCounterList[j].reset_week_day = resetTime->tm_wday; + eventCounterList[j].reset_hour = resetTime->tm_hour; + eventCounterList[j].reset_min = resetTime->tm_min; + eventCounterList[j].reset_sec = resetTime->tm_sec; + } + + if (enable_time_range) + { + strcpy(eventCounterList[j].enable_time_range, enable_time_range->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_time_range", cJSON_CreateString(eventCounterList[j].enable_time_range)); + } + if (time_range_from) + { + strcpy(eventCounterList[j].time_range_from, time_range_from->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_from", cJSON_CreateString(eventCounterList[j].time_range_from)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeFrom = mktime(&tm); + } + if (time_range_to) + { + strcpy(eventCounterList[j].time_range_to, time_range_to->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_to", cJSON_CreateString(eventCounterList[j].time_range_to)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeTo = mktime(&tm); + } + #endif + + if (link_to_post_event_name) + { + strcpy(eventCounterList[j].link_to_post_event_name, link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "link_to_post_event_name", cJSON_CreateString(eventCounterList[j].link_to_post_event_name)); + } + if (post_interval) + { + strcpy(eventCounterList[j].post_interval, post_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "post_interval", cJSON_CreateString(eventCounterList[j].post_interval)); + } + if (enable_reset_only_cloud) { + strcpy(eventCounterList[j].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[j].enable_reset_only_cloud)); + } + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[j].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[j].enable_linked_to_dwell_time)); + } + break; + } + j++; + } + } + } + + i++; + } + +#if 0 + if (strcmp(SystemSetting.cloud_enable_notification, "No") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + IsANPRCategory(featureType) || + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } + } +#endif + } + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + s_report_counters = cJSON_GetObjectItem(s_event_counter_setting, "report_counters"); + + if (report_counters) { + int i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) + { + int j = 0; + cJSON_ArrayForEach(s_a_report, s_report_counters) + { + if (i == j) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + + if (counter_a) + { + strcpy(reportCounterList[j].counter_a, counter_a->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a", cJSON_CreateString(reportCounterList[j].counter_a)); + } + + if (counter_a_name) + { + strcpy(reportCounterList[j].counter_a_name, counter_a_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_name", cJSON_CreateString(reportCounterList[j].counter_a_name)); + } + + if (counter_a_zone) + { + strcpy(reportCounterList[j].counter_a_zone, counter_a_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[j].counter_a_zone)); + } + + if (counter_b) + { + strcpy(reportCounterList[j].counter_b, counter_b->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b", cJSON_CreateString(reportCounterList[j].counter_b)); + } + + if (counter_b_name) + { + strcpy(reportCounterList[j].counter_b_name, counter_b_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_name", cJSON_CreateString(reportCounterList[j].counter_b_name)); + } + + if (counter_b_zone) + { + strcpy(reportCounterList[j].counter_b_zone, counter_b_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[j].counter_b_zone)); + } + + if (counter_c_name) + { + strcpy(reportCounterList[j].counter_c_name, counter_c_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_c_name", cJSON_CreateString(reportCounterList[j].counter_c_name)); + } + + if (report_max_value) + { + strcpy(reportCounterList[j].report_max_value, report_max_value->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "report_max_value", cJSON_CreateString(reportCounterList[j].report_max_value)); + } + + if (enable_report) + { + strcpy(reportCounterList[j].enable_report, enable_report->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "enable_report", cJSON_CreateString(reportCounterList[j].enable_report)); + } + + if (counter_mode) + { + strcpy(reportCounterList[j].counter_mode, counter_mode->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_mode", cJSON_CreateString(reportCounterList[j].counter_mode)); + } + + if (initial_icon) + { + strcpy(reportCounterList[j].initial_icon, initial_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "initial_icon", cJSON_CreateString(reportCounterList[j].initial_icon)); + } + + if (detection_output) + { + strcpy(reportCounterList[j].detection_output, detection_output->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "detection_output", cJSON_CreateString(reportCounterList[j].detection_output)); + } + + if (output_icon) + { + strcpy(reportCounterList[j].output_icon, output_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "output_icon", cJSON_CreateString(reportCounterList[j].output_icon)); + } + + break; + } + j++; + } + } + + i++; + } + } + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + s_snmp_management = cJSON_GetObjectItem(s_event_counter_setting, "snmp_management"); + + if (snmp_management) { + int i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) + { + int j = 0; + cJSON_ArrayForEach(s_a_snmp, s_snmp_management) + { + if (i == j) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + + if (snmp_event_name) + { + strcpy(SNMPManagementList[j].snmp_event_name, snmp_event_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[j].snmp_event_name)); + } + + if (snmp_version) + { + strcpy(SNMPManagementList[j].snmp_version, snmp_version->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[j].snmp_version)); + } + + if (snmp_group_name) + { + strcpy(SNMPManagementList[j].snmp_group_name, snmp_group_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[j].snmp_group_name)); + } + + if (snmp_host_ip) + { + strcpy(SNMPManagementList[j].snmp_host_ip, snmp_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[j].snmp_host_ip)); + } + + if (snmp_host_port) + { + strcpy(SNMPManagementList[j].snmp_host_port, snmp_host_port->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[j].snmp_host_port)); + } + + if (snmp_oid) + { + strcpy(SNMPManagementList[j].snmp_oid, snmp_oid->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[j].snmp_oid)); + } + + if (snmp_value) + { + strcpy(SNMPManagementList[j].snmp_value, snmp_value->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[j].snmp_value)); + } + + if (snmp_type) + { + strcpy(SNMPManagementList[j].snmp_type, snmp_type->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[j].snmp_type)); + } + break; + } + j++; + } + } + + i++; + } + } + } +#endif + cJSON *email_setting, *email_content; + cJSON *s_email_setting; + + email_setting = cJSON_GetObjectItem(root, "email_setting"); + s_email_setting = cJSON_GetObjectItem(s_root, "email_setting"); + + if (email_setting) + { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) { + strcpy(emailData.email_content, email_content->valuestring); + cJSON_ReplaceItemInObject(s_email_setting, "email_content", cJSON_CreateString(emailData.email_content)); + } + } + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(events_PATH, "w"); + if (f != NULL) + { + + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(events_PATH, events_bakPATH); + + check_if_setfile_OK = 1; + g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read events_import.json or events.json\n"); + } + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventscustom2)\n"); + } + else { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventscustom2#2)\n"); + } + + pthread_mutex_unlock(&mutex_events_json); + + closesocket(cli_socket); + + check_if_correct_post = 0; + } +#if 0 + else if (strncmp(urlBuffer, "/setjvcconfigfile", strlen("/setjvcconfigfile")) == 0) { + int check_if_setfile_OK = 0; + //printf("----------------------------[setjvcconfigfile]recvBuffer: %s\n", recvBuffer); + + pthread_mutex_lock(&mutex_jvc_config_json); + + check_if_setfile_OK = 1; + + int file_buff_size = nTotalContentLen; + //char msg_temp[512] = { 0 }; +#if 1 + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + jvc_setconfig(file_Content); + + + //sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + //printf("\n--------------------reload 4: %s\n", msg_temp); + } +#endif + +#if 0 + jvc_setMainSetting(); +#endif + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + //printf("jvc configfile: \n %s \n", beforeSendBuffer); + if (check_if_setfile_OK == 1) { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile)\n"); + } + else { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile#2)\n"); + } + + pthread_mutex_unlock(&mutex_jvc_config_json); + +#if 0 + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile)\n"); +#endif + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/sendyuv") == 0) + { + //printf("\n[web process]start 28\n"); + char *image_buff = NULL; + size_t image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + memset(image_buff, 0x00, CONTENT_BUFSIZE); + + char* pContent = contentBuffer; + char* pBlockEnd = contentBuffer; + //image_buff_size = nTotalContentLen; + //size_t nbytes = 0; + //size_t nTotalBytes = 0; + + int yuv_width = 0; + int yuv_height = 0; + char resolutionStr[10] = { 0 }; + char resolution[2][STRSPLIT_SIZE]={0}; + const char *del = "x"; + + char* pYUVStart = NULL; + char* pYUVEnd = NULL; + //int nNeedUpdateTrafficLightZone = 0; + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, MSG_RESOLUTION_PATTERN, strlen(MSG_RESOLUTION_PATTERN)) == 0) + { + pBlockEnd = strstr(pContent, "\r\n"); + pYUVStart = pBlockEnd + 2; + //DumpHex(pYUVStart, 320); + memcpy(resolutionStr, pContent + strlen(MSG_RESOLUTION_PATTERN), pBlockEnd - (pContent + strlen(MSG_RESOLUTION_PATTERN))); + if (strlen(resolutionStr) > 0) + { + //if (abs(viewChannelData[tracking_channel_idx].tab_view_width_ratio * viewChannelData[tracking_channel_idx].tab_view_width - AIImage_width) > 5) + //nNeedUpdateTrafficLightZone = 1; + StrSplit(resolutionStr, resolution, del); + //printf("\n------UU:36\n"); + yuv_width = atoi(resolution[0]); + yuv_height = atoi(resolution[1]); + viewChannelData[tracking_channel_idx].tab_view_width_ratio = (float)yuv_width / viewChannelData[tracking_channel_idx].tab_view_width; + viewChannelData[tracking_channel_idx].tab_view_height_ratio = (float)yuv_height / viewChannelData[tracking_channel_idx].tab_view_height; + #ifdef GY_OS_WIN + if (nNeedUpdateTrafficLightZone) + UpdateTrafficLightZone(tracking_channel_idx); + #endif + } + break; + } + /*else if (strncmp(pContent, MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0) + { + pYUVEnd = pContent; + break; + }*/ + } + + for (int i = nTotalContentLen - strlen(MSG_END_PATTERN); i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0) + { + pYUVEnd = pContent; + break; + } + } + + image_buff_size = pYUVEnd - pYUVStart; + memcpy(image_buff, pYUVStart, image_buff_size); + + if (!pYUVStart || !pYUVEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error YUV format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + //printf("\n[web process]-A-6: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-6: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + + clock_t t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("pre AI recog time: %f\n", diff); + /*int local_tracking_idx = 0; + int b_nav_channel_exist = 0; + for (int i = 0; i <= MAX_CLIENT_SOCKET; i++) + { + if (g_TrackingIDAndChannel[i][1] == nav_tracking_channel) + { + local_tracking_idx = i; + b_nav_channel_exist = 1; + break; + } + } + + if (!b_nav_channel_exist) + { + local_tracking_idx = tracking_idx; + memset(g_TrackingIDAndChannel[local_tracking_idx], 0x00, sizeof(g_TrackingIDAndChannel[local_tracking_idx])); + g_TrackingIDAndChannel[local_tracking_idx][1] = nav_tracking_channel; + }*/ + + socketRecords[sock_info_idx].channel_id = tracking_channel; + + clock_t c1 = clock(); + + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nweb process: %d\n", 2); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time %d:%f\n", cli_socket, dDiff); + + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + } +#if 0 + else if (strncmp(urlBuffer, "/user_command", strlen("/user_command")) == 0) + { + //printf("\n[web process]start 29\n"); + //char *start = NULL; + char *pDelim = NULL; + QueueInfo q_info = { 0 }; + MapClear(); + char CorrectParameter[MAX_MSG_LEN * 2] = { 0 }; + char* pContent = contentBuffer + strlen(MSG_START_PATTERN); + printf("recv /user_command : %s\n", pContent); + //start = contentBuffer + 2; + do { + pDelim = strstr(pContent, "\r\n"); + // string between start and delim (or end of string if delim is NULL). + if (pDelim) + { + char attribute[512] = { 0 };//512 + memset(attribute, 0x00, sizeof(attribute)); + //memset(OriAttribute, 0x00, sizeof(OriAttribute)); + memcpy(attribute, pContent, pDelim - pContent); + //memcpy(OriAttribute, pContent, pDelim - pContent); + memset(CorrectParameter, 0x00, sizeof(CorrectParameter)); + attribute[pDelim - pContent] = 0; + char att_var[10][STRSPLIT_SIZE]={0}; + char *del = "="; + int att_var_num = 0; + if (attribute) + { + att_var_num = StrSplit(attribute, att_var, del); + if (att_var_num == 2) + { + sprintf(CorrectParameter, "%s", att_var[1]); + } + if (att_var_num > 2) + { + for (int n = 1; n < att_var_num; n++) + { + if (n == 1) + sprintf(CorrectParameter, "%s", att_var[1]); + else + sprintf(CorrectParameter, "%s%s%s", CorrectParameter, del, att_var[n]); + } + } + int anpr_ch = -1; + + if (strcmp(att_var[0], "<ANPR_channel>") == 0) + anpr_ch = atoi(att_var[1]); + + if (anpr_ch != -1) + { + //char filename[] = "config.json"; + char *filename = configPATH; + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + cJSON* view_setting = cJSON_GetObjectItem(root, "view_setting"); + + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", anpr_ch + 1); + cJSON* camera = cJSON_GetObjectItem(view_setting, CameraID); + + if (strcmp(att_var[0], "<ANPR_enable>") == 0) + { + if (strcmp(att_var[1], "1") == 0) + { + viewChannelData[anpr_ch].channel_idx = 1; + } + if (strcmp(att_var[1], "0") == 0) + { + viewChannelData[anpr_ch].channel_idx = 0; + } + + cJSON_ReplaceItemInObject(camera, "enable_anpr", cJSON_CreateString(att_var[1])); + } + if (strcmp(att_var[0], "<ANPR_confidence>") == 0) + { + strcpy(viewChannelData[anpr_ch].confidence, att_var[1]); + cJSON_ReplaceItemInObject(camera, "confidence", cJSON_CreateString(att_var[1])); + } + if (strcmp(att_var[0], "<ANPR_min_characters>") == 0) + { + strcpy(viewChannelData[anpr_ch].min_characters, att_var[1]); + cJSON_ReplaceItemInObject(camera, "min_characters", cJSON_CreateString(att_var[1])); + } + if (strcmp(att_var[0], "<ANPR_max_characters>") == 0) + { + strcpy(viewChannelData[anpr_ch].max_characters, att_var[1]); + cJSON_ReplaceItemInObject(camera, "max_characters", cJSON_CreateString(att_var[1])); + } + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + //copy config.json to config_bak.json + CopyFileTo(filename, config_bakPATH); + } + else + printf("Fail to open Config.json \n"); + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + + if (strcmp(att_var[0], "<enable_post>") == 0) + { + activePostNotification = atoi(att_var[1]) > 0 ? _TRUE : _FALSE; + { + //char filename[] = "config.json"; + char *filename = configPATH; + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) { + //cJSON* cam_ip, * http_port, * vedio_port, * cam_username, * cam_pwd, * channel_id; + cJSON *camera, *camera_name, *obj_max_proportion, *obj_min_proportion, *tab_view_size, *enable_lpr_db, *count_zone, *enable_anpr, *enable_traffic, *enable_logo, *temp_detection_zone, *detect, + *levenshtein_distance, *min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, + *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_TRIGGER_EVENT], *checked, *detect_event_id, *detect_event_name, *post_event_name, *counter_name,*counter_cust_name, *counter_increment, + *point_num, + *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6; + cJSON* root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + + cJSON* view_setting = cJSON_GetObjectItem(root, "view_setting"); + + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + /*cam_ip = cJSON_GetObjectItem(camera, "ip"); + http_port = cJSON_GetObjectItem(camera, "http_port"); + vedio_port = cJSON_GetObjectItem(camera, "vedio_port"); + cam_username = cJSON_GetObjectItem(camera, "username"); + cam_pwd = cJSON_GetObjectItem(camera, "password"); + channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + strcpy(viewChannelData[n].confidence, confidence->valuestring); + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + viewChannelData[n].count_zone = count_zone->valueint; + + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + //printf("\n[web process]tab_view_size: %s\n", tab_view_size->valuestring); + char temp_tab[50] = { 0 }; + strcpy(temp_tab, tab_view_size->valuestring); + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(temp_tab, outArray, "x"); + //printf("\n------UU:37\n"); + viewChannelData[n].channel_idx = n; + + viewChannelData[n].tab_view_width = atoi(outArray[0]); + viewChannelData[n].tab_view_height = atoi(outArray[1]); + + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + + + temp_detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + viewChannelData[n].enable_traffic_light_zone = 0; + int i = 0; + cJSON_ArrayForEach(detect, temp_detection_zone) + { + /*levenshtein_distance = cJSON_GetObjectItem(detect, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(detect, "min_characters"); + max_characters = cJSON_GetObjectItem(detect, "max_characters"); + confidence = cJSON_GetObjectItem(detect, "confidence");*/ + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + /*confidence3 = cJSON_GetObjectItem(detect, "confidence3");*/ + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); + + point_num = cJSON_GetObjectItem(detect, "point_number"); + + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + /*strcpy(viewDetectionZone[n][i].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewDetectionZone[n][i].min_characters, min_characters->valuestring); + strcpy(viewDetectionZone[n][i].max_characters, max_characters->valuestring); + strcpy(viewDetectionZone[n][i].confidence, confidence->valuestring);*/ + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + if(metadata_stop) + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + if (no_parking_time) + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + if (no_parking_time_in_minute) + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + + if (queuing_count) + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + /*strcpy(viewDetectionZone[n][i].confidence3, confidence3->valuestring);*/ + + if (point_num) + viewDetectionZone[n][i].point_num = point_num->valueint; + + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].Points[3].y = y4->valueint; + + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + + if (x5 && x6) + { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].Points[5].y = y6->valueint; + + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + } + + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; +#ifdef GY_OS_WIN + UpdateTrafficLightZone(n); +#endif + } + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + //int arraySize = cJSON_GetArraySize(temp_detection_zone); + int k = 0; + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + k = 0; + cJSON_ArrayForEach(detect, trigger_events[j]) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + //break; + } + + if (strcmp(att_var[0], "<reload_post_events>") == 0) + { + //post events setting + //char filename2[] = "events.json"; + char *filename2 = eventsPATH; + if (!FileExist(filename2)) + { + printf("%s doesn't exist.\n", filename2); + printf("Press any key to exit...\n"); + getchar(); + //printf("\n[web process]-A-7: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + + char* fileBuf = ReadAllBytes(filename2); + if (fileBuf) { + + cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content; + cJSON *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max, *enable_heatmap, *heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + n_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (n_root) { + notification = cJSON_GetObjectItem(n_root, "notification"); + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + + strcpy(postEventList[i].post_protocol, post_protocol->valuestring); + strcpy(postEventList[i].post_event_method, post_event_method->valuestring); + strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); + strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); + strcpy(postEventList[i].post_host_port, post_host_port->valuestring); + strcpy(postEventList[i].post_url, post_url->valuestring); + strcpy(postEventList[i].post_username, post_username->valuestring); + strcpy(postEventList[i].post_password, post_password->valuestring); + strcpy(postEventList[i].post_content, post_content->valuestring); + i++; + } + + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to; + +#ifdef GY_OS_V_SERIES + +#else + event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + + i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + + strcpy(eventCounterList[i].counter_name, counter_name->valuestring); + strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); + strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); + if (reset_value->valuestring) + eventCounterList[i].reset_value = atoi(reset_value->valuestring); + else + eventCounterList[i].reset_value = 0; + strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_at, reset_at->valuestring); + strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); + strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); + strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); + struct tm tm; + strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetResetAt = mktime(&tm); + struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); + eventCounterList[i].reset_month = resetTime->tm_mon; + eventCounterList[i].reset_month_day = resetTime->tm_mday; + eventCounterList[i].reset_week_day = resetTime->tm_wday; + eventCounterList[i].reset_hour = resetTime->tm_hour; + eventCounterList[i].reset_min = resetTime->tm_min; + eventCounterList[i].reset_sec = resetTime->tm_sec; + strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeFrom = mktime(&tm); + strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeTo = mktime(&tm); + i++; + } +#endif + + if (n_root) { + cJSON_Delete(n_root); + n_root = NULL; + } + } + } + } + + if (strcmp(att_var[0], "<enable_display>") == 0) + { + if (strcmp(att_var[1], "1 dash") == 0) + activeDisplayDash = _TRUE; + + if (strcmp(att_var[1], "0 dash") == 0) + activeDisplayDash = _FALSE; + + if (strcmp(att_var[1], "1 properties") == 0) + activeDisplayProperties = _TRUE; + + if (strcmp(att_var[1], "0 properties") == 0) + activeDisplayProperties = _FALSE; + } + + //test http notification + if (strcmp(att_var[0], "<post_event_method>") == 0) + { + testPostNotification = _TRUE; + strcpy(q_info.post_method, CorrectParameter); + } + + //if (strcmp(att_var[0], "<post_event_name>") == 0) + //strcpy(q_info.post_name, CorrectParameter); + + if (strcmp(att_var[0], "<post_host_name>") == 0) + strcpy(q_info.host_name, CorrectParameter); + + if (strcmp(att_var[0], "<post_host_port>") == 0) + strcpy(q_info.host_port, CorrectParameter); + + if (strcmp(att_var[0], "<post_url>") == 0) + { + //strcpy(q_info.post_url, OriAttribute + strlen("<post_url>=")); + strcpy(q_info.post_url, CorrectParameter); + } + + if (strcmp(att_var[0], "<post_username>") == 0) + strcpy(q_info.post_username, CorrectParameter); + + if (strcmp(att_var[0], "<post_password>") == 0) + strcpy(q_info.post_password, CorrectParameter); + + if (strcmp(att_var[0], "<post_content>") == 0) + { + strcpy(q_info.content, CorrectParameter); + } + + /*char Value[MAX_MSG_LEN] = { 0 }; + MapFind("<web_kit_form_boundary>", Value); + printf("%s",Value);*/ + } + pContent = pDelim + 2; // Use length of your b string. + } + } + while (pDelim); + + if (testPostNotification) + { + //pthread_mutex_lock(&mutex_post_notification); + if (!q_info.content) + { + memset(q_info.content, 0x00, strlen(pContent) + 1); + } + q_info.image_buff = NULL; //20201105 sophia add + q_info.image_buff_size = 0; + //q_info.pNext = malloc(sizeof(detection_pos)); + if (AI_fps >= 1) + QueuePush(q_info, _POST_NOTIFICATION); + //pthread_mutex_unlock(&mutex_post_notification); + testPostNotification = _FALSE; + } + } +#endif + else if (strncmp(urlBuffer, "/import_lpr_map_list", strlen("/import_lpr_map_list")) == 0) + { +#ifdef GY_OS_AMBA + //printf("\n[web process]start 30\n"); + char *image_buff = NULL; + //int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + //char httpVariables[BUFSIZE_V2] = { 0 }; + //char boundary[255] = {0}; + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr( headerBuffer, "boundary=" )) != NULL) + { + int strlen =0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, sizeof(multiPartBoundary)); + //char endStr[] = "--"; + strncpy(multiPartBoundary, tempPtr, strlen); + //strcat(multiPartBoundary,endStr); + } + } + } + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + //image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0)//find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + }else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + + } + + } + } + if (!((image_buff[0]== 0xef) && (image_buff[1]== 0xbb) && (image_buff[2]== 0xbf))) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "file type error."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + else + { + int map_length = 0; + char *lpr_data_p = NULL; + char *lpr_line_data = NULL,*value = NULL; + int lpr_len = 0; + int nlen; + char *lpr_detect = NULL; + char *lpr_plate = NULL; + char *lpr_line_end = NULL; + callback_reset_db_map_list(); //clean mapping table + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + lpr_line_data=lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + if (lpr_line_end != NULL) + { + lpr_len = lpr_line_end - lpr_line_data; + } + + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_line_data; + + if(map_length == COUNT_MAPPING) + break; + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0]||(lpr_line_data[0]=='\r')||(lpr_line_data[0]=='\n')); lpr_line_data++); + lpr_detect = strsep(&value, ","); + if ((lpr_plate = strsep(&value, "\r\n"))==NULL) + lpr_plate = strsep(&value, "\n"); + if ((lpr_detect != NULL) && (lpr_plate != NULL)) + { + lpr_plate = rtrim(lpr_plate); + action_import_lpr_map_info( lpr_detect, lpr_plate); + map_length++; + } + + lpr_line_end = strstr(lpr_line_data, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + if (lpr_line_end != NULL) + { + lpr_len = lpr_line_end - lpr_line_data; + } + } + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "lpr map file upload ok."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nweb process: %d\n", 3); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time %d:%f\n", cli_socket, dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } +#endif //#ifdef GY_OS_AMBA + } + else if (strncmp(urlBuffer, "/import_lpr_list", strlen("/import_lpr_list")) == 0) + { + //printf("\n-------------import lpr list\n"); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + g_count_lpr_insert_times = 0; + + memset(g_headerBuffer,0x00, BUFSIZE_V2); + memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); + memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); + + strcpy(g_headerBuffer, headerBuffer); + strcpy(g_multiPartBoundary, multiPartBoundary); + g_bIsMultipart = bIsMultipart; + strcpy(g_contentBuffer, contentBuffer); + g_nTotalContentLen = nTotalContentLen; + + //printf("\n-----g_contentBuffer:%s\n", g_contentBuffer); + + pthread_t import_lpr_list_file_thread_id; + if (pthread_create(&import_lpr_list_file_thread_id, 0, import_lpr_list_file_thread, NULL)) + { + printf("create import_lpr_list_file_thread thread faile \n"); + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + +#endif + closesocket(cli_socket); + } +#if 0 + else if (strncmp(urlBuffer, "/import_radarbg", strlen("/import_radarbg")) == 0) // a113n 10/6 + { + pthread_mutex_lock(&mutex_web); + // copy from /sendjpeg + { + char *image_buff = NULL; + int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + //char httpVariables[BUFSIZE_V2] = {0}; + + int check_if_error = 0; + + if (bIsMultipart) + { + char *pContent = contentBuffer; + char *pBlockStart = contentBuffer; + image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + } + char *pJpegStart = NULL; + char *pJpegEnd = NULL; + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) + { + pJpegStart = image_buff + i; + break; + } + } + + for (int i = nTotalBytes; i > 0; i--) + { + if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) + { + pJpegEnd = image_buff + i + 2; + break; + } + } + + // printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); + + if (!pJpegStart || !pJpegEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format(Multipart)."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not JPEG format)\n"); + + // printf("\n[web process]-A-3: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + check_if_error = 1; + // printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); + } + else + { + image_buff_size = pJpegEnd - pJpegStart; + memmove(image_buff, pJpegStart, image_buff_size); + + // printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); + + memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); + } + } + else + { + image_buff_size = nTotalContentLen; + memcpy(image_buff, contentBuffer, image_buff_size); + // DumpHex(image_buff + image_buff_size - 10, 10); + } + + if (check_if_error == 0) { + if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) + { + // DumpHex(image_buff, 2); + // DumpHex(image_buff + image_buff_size - 2, 2); + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + // printf("\n[web process]-A-4: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + // printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); + } + else { + GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); + + FILE *f = fopen("/emmc/plugin/Aida_data/radar/radar_user.jpg", "wb"); + if (f == NULL) + { + printf("Error opening file!\n"); + // exit(1); + } + fwrite(image_buff, image_buff_size, 1, f); + fclose(f); + + Reread_radarbg(); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + } + } + } + closesocket(cli_socket); + pthread_mutex_unlock(&mutex_web); + } + else if (strncmp(urlBuffer, "/import_speedbg", strlen("/import_speedbg")) == 0) // 2022-11-03 Ken, thanks to a113n! + { + pthread_mutex_lock(&mutex_web); + // copy from /sendjpeg + { + char *image_buff = NULL; + int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + //char httpVariables[BUFSIZE_V2] = {0}; + + int check_if_error = 0; + + if (bIsMultipart) + { + char *pContent = contentBuffer; + char *pBlockStart = contentBuffer; + image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + } + char *pJpegStart = NULL; + char *pJpegEnd = NULL; + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) + { + pJpegStart = image_buff + i; + break; + } + } + + for (int i = nTotalBytes; i > 0; i--) + { + if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) + { + pJpegEnd = image_buff + i + 2; + break; + } + } + + // printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); + + if (!pJpegStart || !pJpegEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format(Multipart)."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not JPEG format)\n"); + + // printf("\n[web process]-A-3: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + check_if_error = 1; + // printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); + } + else + { + image_buff_size = pJpegEnd - pJpegStart; + memmove(image_buff, pJpegStart, image_buff_size); + + // printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); + + memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); + } + } + else + { + image_buff_size = nTotalContentLen; + memcpy(image_buff, contentBuffer, image_buff_size); + // DumpHex(image_buff + image_buff_size - 10, 10); + } + + if (check_if_error == 0) { + if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) + { + // DumpHex(image_buff, 2); + // DumpHex(image_buff + image_buff_size - 2, 2); + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + // printf("\n[web process]-A-4: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + // printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); + } + else { + GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); + + FILE *f = fopen("/emmc/plugin/Aida_data/radar/speed_user.jpg", "wb"); + if (f == NULL) + { + printf("Error opening file!\n"); + // exit(1); + } + fwrite(image_buff, image_buff_size, 1, f); + fclose(f); + + Reread_speedbg(); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + } + } + } + closesocket(cli_socket); + pthread_mutex_unlock(&mutex_web); + } +#endif + //printf("\n---------PP 1\n"); + } + // else if (strncmp(urlBuffer, "/import_radar_img", strlen("/import_radar_img")) == 0) // Ken 10-07 10-11 + // { + // #ifdef GY_OS_AMBA + + // memset(g_headerBuffer, 0x00, BUFSIZE_V2); + // memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); + // memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); + + // strcpy(g_headerBuffer, headerBuffer); + // strcpy(g_multiPartBoundary, multiPartBoundary); + // g_bIsMultipart = bIsMultipart; + // strcpy(g_contentBuffer, contentBuffer); + // g_nTotalContentLen = nTotalContentLen; + + // pthread_t import_lpr_list_file_thread_id; + // if (pthread_create(&import_lpr_list_file_thread_id, 0, import_lpr_list_file_thread, NULL)) + // { + // printf("create import_lpr_list_file_thread thread faile \n"); + // } + + // strcpy(beforeSendBuffer, ""); + // if (strlen(contentDescription) > 0) + // { + // strcat(beforeSendBuffer, " "); + // strcat(beforeSendBuffer, contentDescription); + // } + + // int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + // if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + // printf("\nsend\n"); + + // #endif + // closesocket(cli_socket); + // } + // } + + else + { + //printf("\n[web process]start 32\n"); + sprintf(msg, "URL not Found."); + printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_404, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + //printf("\n[web process]-6: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + //printf("\n---------PP 2\n"); + //printf("\nhellllo4\n"); +} + +/*int caculate_ftp_of_each_sockets(SOCKET sock, int *sock_record_idx) +{ + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + socketRecords[i].last_recv_time = time(0); + int idx_last_recv_time_min = 0; + time_t last_recv_time_min = 0; + *sock_record_idx = i; + //printf("last recv time=%I64d\n", socketRecords[i].last_recv_time); + for (int j = 0; j < FPS_AVG_SECS; j++) + { + if (socketRecords[i].recent_sec_data[j].recv_time == socketRecords[i].last_recv_time) + { + socketRecords[i].recent_sec_data[j].frames++; + break; + } + + if (socketRecords[i].recent_sec_data[j].recv_time <= socketRecords[i].last_recv_time - FPS_AVG_SECS) + { + socketRecords[i].recent_sec_data[j].frames = 0; + socketRecords[i].recent_sec_data[j].recv_time = 0; + } + + if (j == 0) + { + idx_last_recv_time_min = 0; + last_recv_time_min = socketRecords[i].recent_sec_data[j].recv_time; + } + else + { + if (socketRecords[i].recent_sec_data[j].recv_time < last_recv_time_min) + { + idx_last_recv_time_min = j; + last_recv_time_min = socketRecords[i].recent_sec_data[j].recv_time; + } + } + + if (j == FPS_AVG_SECS - 1) + { + socketRecords[i].recent_sec_data[idx_last_recv_time_min].frames = 1; + socketRecords[i].recent_sec_data[idx_last_recv_time_min].recv_time = socketRecords[i].last_recv_time; + } + } + return i; + } + } + } + return -1; +}*/ + +///Create this thread by run_http_server for each socket + +void sharkhand_s_connection_upgrade(int* sock,char *buffer,int* websocket_connected) { + + //if (0 == websocket_connected) + { + /*if ((*websocket_connected) == 0)*/ + { + //int count_sharkhand = 0; + int iIsWebsocketHybi00 = 0; + //while (sharkhand_s((*sock), buffer, &iIsWebsocketHybi00) < 0 && count_sharkhand < MAX_SHARKHAND_REPEAT) { + + sharkhand_s((*sock), buffer, &iIsWebsocketHybi00); + /* + while (sharkhand_s((*sock), buffer, websocket_connected) < 0 && count_sharkhand < MAX_SHARKHAND_REPEAT) { + //printf("\n[%d]build sharkhand - repeat: %d\n", sock, count_sharkhand); + count_sharkhand++; + usSleep(1000); + }*/ + + (*websocket_connected) = 1; + + /* + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //printf("rA[%d]=%d, *sock=%d \n", i, socketRecords[i].sock, *sock); + if (socketRecords[i].sock == *sock) + { + //socketRecords[i].iIsWebsocketHybi00 = iIsWebsocketHybi00; + //printf("idx[%d]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is hybi00: %d \n", i, socketRecords[i].iIsWebsocketHybi00); + } + + }*/ + } + } + +} + +static int is_authorized_run_preload_http_server = 1; +//static int is_WebsocketConnecting = 0; +#if 0 +static int is_referer_from_setup = 0; +#endif + +void *http_connection_handler(void *socket_desc) +{ + pthread_detach(pthread_self()); + setPthreadName("http_conn"); + //pthread_mutex_lock(&mutex_http_connection_handler); + //printf("\n[http_connection_handler] Pthread created and detached.\n"); + //printf("\n---------http connection handler ----------- 1\n"); + int sock = (intptr_t)socket_desc; // Get the socket descriptor + //char buffer[BUFSIZE_V2]; + char buffer[BUFSIZE * 59] = { 0 }; + + char recvbuffer[BUFSIZE * 60] = {0};//BUFSIZE * 60 + char contentBuffer[BUFSIZE * 60] = {0};//BUFSIZE * 60 + + unsigned int nTotalBytes = 0; + unsigned int nContentLength = 0; + int nbytes = 0; + clock_t t1 = clock(); + clock_t t2; + //int bIsMultipart = 0; + char sendBuffer[8196] = { 0 }; + int isGetAlarmMotion = FALSE; + //int sock_record_idx = -1; + + int websocket_connected = 0; + + //char *secWebSocketKey; + //char *data; + + //g_tracking_idx++; + + //if (g_tracking_idx >= MAX_CLIENT_SOCKET) + // g_tracking_idx = 0; + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); +#ifdef _DEBUG_AMBA + printf("(%d) [http_connection_handler] Program binary path is: %s\n", sock,buf); +#endif //_DEBUG_AMBA + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024]; + char eventsPATH[1024]; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + int header_len = 0; + //int doubleCRLF = 0; + + //printf("\n[nweb.c]-----------------------------kkkk:5\n"); + //int tracking_idx = g_tracking_idx; + //memset(g_TrackingIDAndChannel[tracking_idx], 0x00, sizeof(g_TrackingIDAndChannel[tracking_idx])); + //pthread_mutex_lock(&mutex_t); + + /* + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].sock == sock) + { + socketRecords[i].debug_type = 9; + } + }*/ + //printf("\n---------http connection handler ----------- 2\n"); + int nbytes_sec = 0; + // recv( pCli, pCli->reqFd, pCli->readBuf+pCli->header_len, 1, MSG_WAITALL ); + //while ((nbytes = recv(sock, buffer, sizeof(buffer), 0)) > 0) + //char temp_buffer[8196] = { 0 }; + + int isTcpTunnel = FALSE; + + //while ((nbytes = recv(sock, buffer, sizeof(buffer), 0)) > 0) + while (bHttpServerMainStart && ((nbytes = recv(sock, buffer + header_len, 1, 0)) > 0)) + { + //printf("\n---------http connection handler ----------- 3\n"); + /* + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].sock == sock) + { + socketRecords[i].debug_type = 5; + } + }*/ + + header_len += nbytes; + //printf("read size: %d \n", header_len); + +#if 1 + if (strstr(buffer, "User-Agent: Mozilla/5.0 ") != NULL)//User-AgentL˪AOsA{bsA|[W@ﰰˡC + { + if (strstr(buffer , "Connection: keep-alive") != NULL || + strstr(buffer , "Connection: close") != NULL || + strstr(buffer , "Connection: Keep-Alive") != NULL || + strstr(buffer , "Connection: Closed") != NULL)//@socket|hˬdOOHTTP ConnectionApGOh令@AåBUC + { + nbytes_sec = recv(sock, buffer + header_len, (sizeof(buffer) - header_len), 0); + //printf("\n-----------strlen(buffer):%d\n", strlen(buffer)); + //printf("\n--------------header_len:%d\n", header_len); + //printf("\n---------[#1]buffer:%s\n", buffer); + + //memset(temp_buffer, 0x00, header_len+ nbytes_sec); + //memcpy(temp_buffer, buffer, header_len+ nbytes_sec); + } + else if ((strstr(buffer, "Connection: Upgrade") != NULL || strstr(buffer, "Upgrade: websocket") != NULL ) + && strstr(buffer, "\r\n\r\n") != NULL) //Dsocket|hˬd\r\n\r\nA~UC + { + //printf("\n---------[websocket#2]buffer:%s\n", buffer); + //doubleCRLF = 1; + + //memset(temp_buffer, 0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + } + else { + //memset(temp_buffer,0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + continue; + } + } + else if (strstr(buffer, "setconfigfile") != NULL || + strstr(buffer, "seteventsfile") != NULL || + strstr(buffer, "seteventscustom2") != NULL || + strstr(buffer, "settoffile") != NULL || + strstr(buffer, "setemailsfile") != NULL) //[NVR]setconfigfile or seteventsfilehC + { + nbytes_sec = recv(sock, buffer + header_len, (sizeof(buffer)- header_len), 0); + //printf("\n---------[NVR#1]buffer:%s\n", buffer); + //memset(temp_buffer, 0x00, header_len + nbytes_sec); + //memcpy(temp_buffer, buffer, header_len + nbytes_sec); + } + else if (strstr(buffer, "\r\n\r\n") != NULL) //pGOWzӡAh[NVR]"\r\n\r\n"P_C + { + //printf("\n---------[NVR#2]buffer:%s\n", buffer); + //doubleCRLF = 1; + //memset(temp_buffer, 0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + } + else { + //memset(temp_buffer, 0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + continue; + } +#endif + + //printf("\n---------http connection handler ----------- 4\n"); +#if 0 + if (strstr(buffer, "\r\n\r\n")) + { + //doubleCRLF = 1; + } + else + continue; +#endif + + //printf("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK read finish \n\n\n\n"); + + nbytes = header_len + nbytes_sec; + + //printf("\n[nweb.c]-----------------------------kkkk:4\n"); + if (nTotalBytes + nbytes > MAX_IMG_BUFF_SIZE - 4) + { + printf("[ERROR] receive buffer is full %d\n", sock); + ///Steven MARK TEMP + + //fflush(stdout); + //closesocket(sock); + break; + } + + //printf("\n-------------buffer:%s\n", buffer); + + //receive client data successfully + memcpy(recvbuffer + nTotalBytes, buffer, nbytes); + //printf("\n---------http connection handler ----------- 5\n"); + + if (strstr(buffer, "airelay") != NULL) + { + isTcpTunnel = TRUE; + } + else + { + isTcpTunnel = FALSE; + } + + //printf("\n----recvbuffer:%s\n", recvbuffer); + + nTotalBytes += nbytes; + //DumpHex(recvbuffer, 300); + //memset(recvbuffer + nTotalBytes, 0x00, MAX_IMG_BUFF_SIZE - nTotalBytes); + //printf("\n[nweb.c]-----------------------------kkkk:3\n"); + if (nbytes == 0) + { + printf("Socket hung up %d\n", sock); + + //fflush(stdout); + //closesocket(sock); + break; + } + else if (nbytes == -1) + { + printf("HTTP recv failed %d\n", sock); + + //closesocket(sock); + break; + } + //printf("\n[nweb.c]-----------------------------kkkk:2\n"); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //20201028 sophia add, host not from ipcam & not authorized +#if 0 + if (enable_base64 == 1) { +#endif +#if 0 + if(is_authorized_run_preload_http_server == 0 && + strstr(recvbuffer, "/setup.htm") && + is_referer_from_setup == 0){ + is_referer_from_setup = 1; + } +#endif + //printf("\n---------http connection handler ----------- 6 --- %d\n", is_authorized_run_preload_http_server); + if (is_authorized_run_preload_http_server == 0) { + //printf("\n---------http connection handler ----------- 7\n"); +#if 0 + if (is_referer_from_setup == 0) { + + char tmp_open_file[512]; + memset(tmp_open_file, 0, sizeof(tmp_open_file)); + + { + sprintf(tmp_open_file, "./Aida/warning2.html"); + } + + + char sendBuffer[BUFSIZE * 8] = { 0 }; + + /*//#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] http get tmp_open_file:%s\n", cli_socket,tmp_open_file); + //#endif //_DEBUG_AMBA*/ + + int file_fd; + if ((file_fd = open(tmp_open_file, O_RDONLY)) == -1) + { + printf("Failed to open file : %s\n", tmp_open_file);//ɮצSQŪ + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19-2\n"); + } + else { + /* work out the file type and check if we support it */ + int iFileLength = 0; + char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; + iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); + close(file_fd); + + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19\n"); + } + + int iSentLeft = 0; + int iSentLength = 0; + int iRetryCount = 5; + + + + + + iSentLeft = iFileLength; + + while (iSentLeft >= 1) { + iSentLength = send(sock, sendBuffer_superlarge, iSentLeft, 0); + iSentLeft = iSentLeft - iSentLength; + iRetryCount--; + sendBuffer_superlarge + iSentLength; + + if (iSentLeft >= 1) { + //printf("\n[web process]iSentLeft: %d\n", iSentLeft); + } + + if (iRetryCount <= 0) + break; + } + + + } + closesocket(sock); + + break; + } +#endif + if (strncmp(recvbuffer, "GET /getalarmmotion?nvr_auth=", 29) != 0 && strncmp(recvbuffer, "GET /server HTTP/1.1", 20) != 0 && strncmp(recvbuffer, "GET /getdebugplate HTTP/1.1", 27) != 0 && strncmp(recvbuffer, "GET /getfree HTTP/1.1", 21) != 0 && strstr(recvbuffer, "GET /get_search_info?select=log&limit=1&credential=") == NULL) { + + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + if (!is_connection_authorized(recvbuffer, &sock, isTcpTunnel)) { + //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); + closesocket(sock); + break; + } + else { + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + } + } + else if (strncmp(recvbuffer, "GET /getalarmmotion?nvr_auth=", 29) == 0){ + + char *is_nvr_auth = NULL; + is_nvr_auth = strstr(recvbuffer, "nvr_auth="); + if (is_nvr_auth != NULL && strlen(is_nvr_auth) > 9){ + char auth_basic[256] = { 0 }; + strcpy(auth_basic, "Authorization: Basic "); + memcpy(auth_basic + 21, is_nvr_auth + 9, strlen(is_nvr_auth)); + //printf("\n-------------------auth_basic:%s\n", auth_basic); + + if (!is_connection_authorized(auth_basic, &sock, isTcpTunnel)) { + //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); + closesocket(sock); + break; + } + else { + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + } + } + else { + closesocket(sock); + break; + } + } + else if (strstr(recvbuffer, "GET /get_search_info?select=log&limit=1&credential=") != NULL) { + + char *is_credential_auth = NULL; + is_credential_auth = strstr(recvbuffer, "credential="); + //printf("\n-------------------is_credential_auth:%s\n", is_credential_auth); + if (is_credential_auth != NULL && strlen(is_credential_auth) > 11) { + char auth_basic[256] = { 0 }; + strcpy(auth_basic, "Authorization: Basic "); + memcpy(auth_basic + 21, is_credential_auth + 11, strlen(is_credential_auth)); + //printf("\n-------------------auth_basic:%s\n", auth_basic); + + int iSockIdx = -1; + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].sock == sock) + { + iSockIdx = i; + socketRecords[iSockIdx].isCredentialRequest = 1; + break; + } + } + + if (!is_connection_authorized(auth_basic, &sock, isTcpTunnel)) { + //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); + closesocket(sock); + break; + } + else { + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + } + } + else { + closesocket(sock); + break; + } + } + } +#if 0 + } +#endif +#endif + //printf("\n-------recvbuffer #1:%s\n", recvbuffer); + //printf("\n[nweb.c]-----------------------------kkkk:1\n"); + //printf("\n---------http connection handler ----------- 7\n"); + if (strstr(recvbuffer, "Upgrade: websocket") || strstr(recvbuffer, "Connection: Upgrade") || strstr(recvbuffer, "Upgrade: WebSocket")) + { + //printf("\n-------recvbuffer #1:%s\n", recvbuffer); + + //printf("\n[nweb.c][%d]--------sharkhand process---start:1\n", sock); + + websocket_connected = 0; + sharkhand_s_connection_upgrade(&sock,buffer,&websocket_connected); + + //printf("\n[nweb.c][%d]--------sharkhand process---end:1\n", sock); + + int sock_info_idx = -1; + //printf("\n[nweb.c][%d]--------web process---start:1\n", sock); + + web_process(&sock, recvbuffer, nTotalBytes, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 1\n"); + //printf("\n[nweb.c][%d]--------web process---end:1, getalarmmotion = %d\n", sock, isGetAlarmMotion); + break; + } + else if (memcmp(recvbuffer, "GET ", strlen("GET ")) == 0) + { + //printf("\n-------recvbuffer #2:%s\n", recvbuffer); + +//#ifdef _DEBUG_AMBA + //printf("\n(%d) [http_connection_handler] recv GET http request(%d):%sCHECK-END\n", sock, sock, recvbuffer); +//#endif + + int sock_info_idx = -1; + if (memcmp(recvbuffer + nTotalBytes - 4, "\r\n\r\n", 4) == 0) + { + t1 = clock(); + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + sock_info_idx = i; + break; + } + } + } + //printf("\n[nweb.c]--------web process---start:2\n"); + web_process(&sock, recvbuffer, nTotalBytes, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:2\n"); + //printf("\n------web_process end 2\n"); + nTotalBytes = 0; + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("(%d) web end time %d:%f\n",sock, sock, diff); + } + +#ifdef _DEBUG_AMBA + printf("\n(%d) [http_connection_handler] recv GET http request END===========\n\n", sock); +#endif + break; + } +#if 0 + else if (memcmp(recvbuffer, "POST /sendjpeg", strlen("POST /sendjpeg")) == 0) + { + //printf("recv POST http request(%d):%.30s\n", sock, recvbuffer); + + for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) + { + if (memcmp(recvbuffer + i - strlen(MULTIPART_CONTENT), MULTIPART_CONTENT, strlen(MULTIPART_CONTENT)) == 0) + bIsMultipart = 1; + + if ((memcmp(recvbuffer + i - 2, "\xFF\xD9", 2) == 0 && !bIsMultipart && (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0) ) || + (memcmp(recvbuffer + i - 4, "--\r\n", 4) == 0 && memcmp(recvbuffer + i - 5, "-", 1) != 0 && bIsMultipart) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); + //printf("\n[nweb.c]--------web process---start:3\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh,http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:3\n"); + //printf("\n------web_process end 3\n"); + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i) ); + nTotalBytes = nTotalBytes - i; + bIsMultipart = 0; + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); +#ifdef _WIN32 + usSleep(http_sleep_interval*1000); +#else + usSleep(1000); +#endif + break; + } + } + closesocket(sock); + break; + } +#endif +#if 0 + else if (memcmp(recvbuffer, "POST /sendyuv", strlen("POST /sendyuv")) == 0) + { + for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) + { + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + + if ((memcmp(recvbuffer + i - strlen(MSG_END_PATTERN), MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("recv done time: %d:%f\n", sock, diff); + + int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); + //printf("\n[nweb.c]--------web process---start:4\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:4\n"); + //printf("\n------web_process end 4\n"); + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + nTotalBytes = nTotalBytes - i; + bIsMultipart = 0; + nContentLength = 0; + + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); +#ifdef _WIN32 + usSleep(http_sleep_interval*1000); +#else + usSleep(1000); +#endif + break; + } + } + closesocket(sock); + break; + } +#endif +#if 0 + else if (memcmp(recvbuffer, "POST /user_command", strlen("POST /user_command")) == 0) + { + for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) + { + if ((memcmp(recvbuffer + i - strlen(MSG_END_PATTERN), MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); + //printf("\n[nweb.c]--------web process---start:5\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:5\n"); + //printf("\n------web_process end 5\n"); + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + nTotalBytes = nTotalBytes - i; + bIsMultipart = 0; + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); +#ifdef _WIN32 + usSleep(http_sleep_interval*1000); +#else + usSleep(1000); +#endif + break; + } + } + + closesocket(sock); + break; + } +#endif + else if (memcmp(recvbuffer, "POST /setconfigfile", strlen("POST /setconfigfile")) == 0 || + memcmp(recvbuffer, "POST /airelay/setconfigfile", strlen("POST /airelay/setconfigfile")) == 0 || + memcmp(recvbuffer, "POST /seteventsfile", strlen("POST /seteventsfile")) == 0 || + memcmp(recvbuffer, "POST /airelay/seteventsfile", strlen("POST /airelay/seteventsfile")) == 0 || + memcmp(recvbuffer, "POST /seteventscustom2", strlen("POST /seteventscustom2")) == 0 || + memcmp(recvbuffer, "POST /settoffile", strlen("POST /settoffile")) == 0 || + memcmp(recvbuffer, "POST /setemailsfile", strlen("POST /setemailsfile")) == 0 +#if 0 + || memcmp(recvbuffer, "POST /setjvcconfigfile", strlen("POST /setjvcconfigfile")) == 0 +#endif + ) + { + //printf("\n---------recvbuffer:%s\n", recvbuffer); + + char *cp = NULL; + char *cp2 = NULL; + char *cp3 = NULL; + char *tempPtr = NULL; + char boundary[BUFSIZE * 60] = { 0 }; + int strlen_boundary = 0; + + if ((cp = strstr(recvbuffer, "boundary=")) != NULL) + { + + tempPtr = cp + 9; + //printf("\n---------tempPtr:%s\n", tempPtr); + + cp = strstr(tempPtr, "\r\n\r\n"); + + if (cp != NULL) + { + //printf("\n---------cp:%s\n", cp); + cp2 = strstr(cp, "{"); + + if (cp2 != NULL) + { + //printf("\n---------cp2:%s\n", cp2); + //cp3 = strstr(cp2, "----------------"); + cp3 = strstr(cp2, "--"); + strlen_boundary = cp3 - cp2; + while (strlen_boundary >= 1 && cp2[strlen_boundary - 1] != '}') + { + strlen_boundary = strlen_boundary - 1; + } + + if(strlen_boundary >= 1) + strncpy(boundary, cp2, strlen_boundary); + } + } + } + //printf("\n---------boundary:%s\n", boundary); + + int sock_info_idx = -1; + + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + //printf("\n--------recvbuffer + i:%s\n", recvbuffer + i); + if (nTotalBytes < nContentLength) + break; + } + + if (strlen_boundary == 0) { + if (memcmp(recvbuffer + i - strlen("\r\n\r\n"), "\r\n\r\n", strlen("\r\n\r\n")) == 0) + { + //printf("\n-----bIsMultipart:%d\n", bIsMultipart); + //printf("\n-----nContentLength:%d\n", nContentLength); + + //printf("\n----6-recvbuffer:%s\n", recvbuffer); + //printf("\n-----recvbuffer+i:%s\n", recvbuffer+i); + + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 6\n"); + //bIsMultipart = 0; + nContentLength = 0; + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + + break; + } + } + else { + + if (memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0) { + + nContentLength = strlen_boundary; + recvbuffer[i] = '\0'; + //printf("\n----7-recvbuffer:%s\n", recvbuffer); + //printf("\n-----recvbuffer+i - strlen(boundary):%s\n", recvbuffer + i - strlen(boundary)); + + web_process(&sock, recvbuffer, i - strlen(boundary), contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 7\n"); + //bIsMultipart = 0; + nContentLength = 0; + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + + break; + } + } + } + + //printf("\n------web_process end 8\n"); + + break; + } +#ifdef GY_OS_AMBA + else if (memcmp(recvbuffer, "POST /sendpycode", strlen("POST /sendpycode")) == 0 ) + { + //printf("\n---------recvbuffer:%s\n", recvbuffer); + //int sock_info_idx = -1; + int strlen_boundary = 0; + char SendPython[BUFSIZE * 8] = {0}; + //char beforeSendBuffer_xtra[BUFSIZE * 60] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + + for (int i = 0; i <= nTotalBytes; i++) + { + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + if (strlen_boundary == 0) { + if (memcmp(recvbuffer + i - strlen("\r\n\r\n"), "\r\n\r\n", strlen("\r\n\r\n")) == 0) + { + char* file_Content = recvbuffer + i; + + printf("file content = %s \n", file_Content); + //printf("\nfile!!!\n"); + //runPython(file_Content, sock); + // strcpy(sendBuffer_xtra, "Send python file OK!!"); + printf("##################### file_Content : %s /n", file_Content); + runPython(file_Content); + strcpy(SendPython, "Web Buffer Run OK !!"); + } + else + { + strcpy(SendPython, "Send python file fail !!"); + } + } + + } + } + else { + strcpy(SendPython,"Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendPython), SendPython); + if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(SendPython, 0, sizeof(SendPython)); + closesocket(sock); + } +#endif + else if (memcmp(recvbuffer, "POST /keyInfo", strlen("POST /keyInfo")) == 0) + { + g_write_config_file_dirty_flag = 0; + //printf("POST KEY Info \n"); + //printf("recv= %s \n", recvbuffer); + + char* pContent = strstr(recvbuffer, "--boundary START"); + + //printf("\n---get post content=[%s]\n", pContent + 16); + + update_config(pContent + 16); +#ifdef GY_OS_NOVA + g_check_run_nova_detection = 0; + system("killall -15 nova_driver"); + usSleep(1000000); +#endif + //printf("\n--------------------reload 7\n"); + //reload_dataset_from_jsonfile(); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\n\r\n"); + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #39\n"); + closesocket(sock); + + printf("\n-----------------------keyInfo: exit-----------------------\n"); +#if 1 + stop_test_nn_cavalry("keyInfo exit"); + //stop_server(); +#endif + //exit(EXIT_SUCCESS); + } + else if (memcmp(recvbuffer, "POST /getAidaInfo", strlen("POST /getAidaInfo")) == 0) + { + // printf("POST AidaInfo \n"); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\n\r\n"); + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #40\n"); + //write(fd,buffer,strlen(buffer)); + + //int ret = 0; + /* ŪɮפeXȤs */ + + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + printf("read config.json.\n"); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* config_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (config_root) { + //printf("config.json parse OK.\n"); + //cJSON* about_box = cJSON_GetObjectItem(config_root, "about_box"); + //cJSON *nic_name = cJSON_GetObjectItem(about_box, "NIC name"); + //cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + + ///read config.json + + cJSON *jstr1, *jstr2, *jnum1, *root; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + jstr1 = cJSON_CreateString("json test1"); + jstr2 = cJSON_CreateString("json test2"); + jnum1 = cJSON_CreateNumber(4456); + + cJSON_AddItemToObject(root, "jstr1", jstr1); + cJSON_AddItemToObject(root, "jstr2", jstr2); + cJSON_AddItemToObject(root, "jnum1", jnum1); + //cJSON_AddItemToObject(root, "unlock_key", unlock_key->valuestring); + + JsonString = cJSON_PrintUnformatted(root); + + send(sock, JsonString, sizeof(JsonString), 0); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + + if (config_root) { + cJSON_Delete(config_root); + config_root = NULL; + } + //write(cli_socket, sendBuffer, ret); + } + else + printf("config.json parse FAIL.\n"); + } + } + + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_lpr_map_list", strlen("POST /import_lpr_map_list")) == 0) + ||(memcmp(recvbuffer, "POST /import_lpr_list", strlen("POST /import_lpr_list")) == 0)) + { + //printf("\n------------recvbuffer:%s\n", recvbuffer); + + char *cp = NULL; + char *tempPtr = NULL; + char boundary[255] = {0}; + if ((cp = strstr( recvbuffer, "boundary=" )) != NULL) + { + int strlen =0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + char endStr[] = "--"; + strncpy(boundary, tempPtr, strlen); + strcat(boundary,endStr); + } + } + } + + if (strlen(boundary) >= 1) { + //printf("\n--------import lpr list ---- 1 --- nTotalBytes %d\n", nTotalBytes); + int sock_info_idx = -1; + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + //printf("\n--------import lpr list ---- 2 ------ %d\n", i); + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + //printf("\n--------import lpr list ---- 3\n"); + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + //printf("\n--------import lpr list ---- 4\n"); + if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("recv done time: %d:%f\n", sock, diff); + //printf("\n[nweb.c]--------web process---start:6\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 9\n"); + //printf("\n[nweb.c]--------web process---end:6\n"); + //memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + //memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + //nTotalBytes = nTotalBytes - i; + //printf("\n[nweb.c]--------web process---end:6-------1\n"); + //memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); + //bIsMultipart = 0; + nContentLength = 0; + //printf("\n[nweb.c]--------web process---end:6-------2\n"); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("\n[nweb.c]--------web process---end:6-------2\n"); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); + // printf("\n[nweb.c]--------web process---end:6-------4\n"); + + usSleep(1000); + break; + } + //printf("\n--------import lpr list ---- 5\n"); + } + } + /* + char* cp = NULL, tempPtr = NULL; + char boundary[255]; + char contLen[20]; + int datalen = 0; + printf("POST import_lpr_map_list \n"); + printf("recv= %s \n", recvbuffer); + if (cp = strstr( recvbuffer, "Content-Length:" )) + { + datalen = atoi((char *)(cp+16)); + printf("length:%d\n",datalen); + } + if ((cp = strstr( recvbuffer, "boundary=" ))) + { + tempPtr = &cp[9]; + //strncpy(boundary, tempPtr, sizeof(boundary)-1); + //printf("boundary:%s\n",boundary); + if (datalen > 0) + do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) + } + */ + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_radarbg", strlen("POST /import_radarbg")) == 0)) // a113n 10/12 + { + char *cp = NULL; + char *tempPtr = NULL; + char boundary[255] = {0}; + if ((cp = strstr(recvbuffer, "boundary=")) != NULL) + { + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + char endStr[] = "--"; + strncpy(boundary, tempPtr, strlen); + strcat(boundary, endStr); + } + } + } + int sock_info_idx = -1; + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + + if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/)) + { + // DumpHex(recvbuffer, 320); + // printf("\n"); + // DumpHex(recvbuffer + i, 320); + // DumpHex(recvbuffer + i - 2 , 16); + // caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("recv done time: %d:%f\n", sock, diff); + // printf("\n[nweb.c]--------web process---start:6\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 10\n"); + // printf("\n[nweb.c]--------web process---end:6\n"); + // memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + // memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + // nTotalBytes = nTotalBytes - i; + // printf("\n[nweb.c]--------web process---end:6-------1\n"); + // memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); + //bIsMultipart = 0; + nContentLength = 0; + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + // printf("web end time %d:%f\n", sock, diff); + t1 = clock(); + // printf("\n[nweb.c]--------web process---end:6-------4\n"); + + usSleep(1000); + break; + } + } + /* + char* cp = NULL, tempPtr = NULL; + char boundary[255]; + char contLen[20]; + int datalen = 0; + printf("POST import_lpr_map_list \n"); + printf("recv= %s \n", recvbuffer); + if (cp = strstr( recvbuffer, "Content-Length:" )) + { + datalen = atoi((char *)(cp+16)); + printf("length:%d\n",datalen); + } + if ((cp = strstr( recvbuffer, "boundary=" ))) + { + tempPtr = &cp[9]; + //strncpy(boundary, tempPtr, sizeof(boundary)-1); + //printf("boundary:%s\n",boundary); + if (datalen > 0) + do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) + } + */ + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_speedbg", strlen("POST /import_speedbg")) == 0)) // 2022-11-03 Ken + { + char *cp = NULL; + char *tempPtr = NULL; + char boundary[255] = {0}; + if ((cp = strstr(recvbuffer, "boundary=")) != NULL) + { + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + char endStr[] = "--"; + strncpy(boundary, tempPtr, strlen); + strcat(boundary, endStr); + } + } + } + int sock_info_idx = -1; + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + + if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/)) + { + // DumpHex(recvbuffer, 320); + // printf("\n"); + // DumpHex(recvbuffer + i, 320); + // DumpHex(recvbuffer + i - 2 , 16); + // caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("recv done time: %d:%f\n", sock, diff); + // printf("\n[nweb.c]--------web process---start:6\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 11\n"); + // printf("\n[nweb.c]--------web process---end:6\n"); + // memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + // memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + // nTotalBytes = nTotalBytes - i; + // printf("\n[nweb.c]--------web process---end:6-------1\n"); + // memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); + //bIsMultipart = 0; + nContentLength = 0; + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + // printf("web end time %d:%f\n", sock, diff); + t1 = clock(); + // printf("\n[nweb.c]--------web process---end:6-------4\n"); + + usSleep(1000); + break; + } + } + /* + char* cp = NULL, tempPtr = NULL; + char boundary[255]; + char contLen[20]; + int datalen = 0; + printf("POST import_lpr_map_list \n"); + printf("recv= %s \n", recvbuffer); + if (cp = strstr( recvbuffer, "Content-Length:" )) + { + datalen = atoi((char *)(cp+16)); + printf("length:%d\n",datalen); + } + if ((cp = strstr( recvbuffer, "boundary=" ))) + { + tempPtr = &cp[9]; + //strncpy(boundary, tempPtr, sizeof(boundary)-1); + //printf("boundary:%s\n",boundary); + if (datalen > 0) + do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) + } + */ + closesocket(sock); + break; + } +#if 0 + else + { + char msg[MAX_MSG_LEN] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + sprintf(msg, "The URL is not correct(%d)\n", sock /*,recvbuffer*/); + printf("%s\n", msg); + + /*printf("\n"); + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + + char sendBuffer[BUFSIZE] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(sock, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error\n");*/ + + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(recvbuffer + i, "POST /sendjpeg", strlen("POST /sendjpeg")) == 0) + { + //DumpHex(recvbuffer + i, 256); + sprintf(msg, "The URL is not correct(%d)\n", sock /*,recvbuffer*/); + printf("%s\n", msg); + + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + nTotalBytes = nTotalBytes - i; + break; + } + } + + /*if (nTotalBytes >= MAX_IMG_BUFF_SIZE - 8*BUFSIZE) + { + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + nTotalBytes = 0; + break; + }*/ + closesocket(sock); + break; + } +#endif +#if 0 + else if ((memcmp(recvbuffer, "POST /upload_face_img", strlen("POST /upload_face_img")) == 0)) // 2023-12-12 Steven + { + //printf("\n\n\n--------------------------------UPLOAD FACE IMG \n"); + + //int image_buff_size = 0; + + //char *image_buff = NULL; + //image_buff = malloc(MAX_IMG_SIZE_HD); + //memset(image_buff, 0, MAX_IMG_SIZE_HD); + + //char *decrypt_buff = NULL; + //decrypt_buff = malloc(MAX_IMG_SIZE_HD); + //memset(decrypt_buff, 0, MAX_IMG_SIZE_HD); + + char *cp = NULL; + char *dataEnd = NULL; + char *tempPtr = NULL; + int base64_len = 0; + + //printf("--------------------------------UPLOAD FACE IMG 2\n"); + + //printf("\n\n\n%s\n", recvbuffer); + + if ((cp = strstr(recvbuffer, "base64,")) != NULL) + { + //printf("\n\n\n ============================= JPEG SIZE = %d \n\n", strlen(cp)); + tempPtr = cp + 7; + //printf("find data start: 0x%x\n", tempPtr); + } + + //printf("--------------------------------UPLOAD FACE IMG 3\n"); + + if ((dataEnd = strstr(tempPtr, "------WebKit")) != NULL) + { + //printf("find data end: 0x%x\n", dataEnd); + } + + //printf("--------------------------------UPLOAD FACE IMG 4\n"); + + if (tempPtr != NULL && dataEnd != NULL) + { + base64_len = (dataEnd - tempPtr) - 2; + //printf("\n\ndata len = %d \n", base64_len); + } + + //printf("--------------------------------UPLOAD FACE IMG 5\n"); +#if 1 + if (base64_len > 0) + { + memcpy(g_image_buff, tempPtr, base64_len); + + size_t base64_decode_length = 0; + + //printf("55555555555555555555555555 \n\n\n %d \n\n\n", base64_len); + + //printf(" 666666666666666666666666666666666666 \n\n\n %s \n\n\n", image_buff); + + int encode_len = strlen(g_image_buff) - (strlen(g_image_buff) % 4); + + //printf("55555555555555555555555555 enc len\n\n\n %d \n\n\n", encode_len); + + base64_decode(g_image_buff, encode_len, &base64_decode_length, g_decrypt_buff); + + //printf("666666666666666666666666666666 \n\n\n %d \n\n\n", base64_decode_length); + printf("--------------------------------UPLOAD FACE IMG 6\n"); + //writeImageFromBuffer("/emmc/plugin/Aida_data/tmp/crop.jpg", g_decrypt_buff, base64_decode_length); +#if 1 + // deal with face data + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + if (get_ff_face_name_max_num() > g_face_frame_uid) { + g_face_frame_uid = get_ff_face_name_max_num() + 1; + printf("g_face_frame_uid = %d\n", g_face_frame_uid); + } + else { + printf("get_ff_face_name_max_num < g_face_frame_uid, get_ff_face_name_max_num = %d\n", get_ff_face_name_max_num()); + } + + if (g_face_frame_uid >= 0) { + // deal with register + char visitor_tmp[14] = "Visitor"; + char face_uid_tmp[10]; + sprintf(face_uid_tmp, "%05d", g_face_frame_uid); + strcat(visitor_tmp, face_uid_tmp); + + char base64_image_filename[60] = { 0 }; + sprintf(base64_image_filename, "%d_%d_%d_%d_%d_%d_%ld_%05d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time, g_face_frame_uid); + + char base64_image_filename_path[128] = { 0 }; + sprintf(base64_image_filename_path, "/tmp/face/%s.jpg", base64_image_filename); + //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_image_filename_path); + writeImageFromBuffer(base64_image_filename_path, g_decrypt_buff, base64_decode_length); + + char base64_image_filename_path_2[128] = { 0 }; + sprintf(base64_image_filename_path_2, "/emmc/plugin/Aida_data/storage/vip/%s.jpg", base64_image_filename); + //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_image_filename_path_2); + writeImageFromBuffer(base64_image_filename_path_2, g_decrypt_buff, base64_decode_length); + + char base64_tmplate_filename_path[128] = { 0 }; + sprintf(base64_tmplate_filename_path, "/emmc/plugin/Aida_data/storage/template/%s.tpl", face_uid_tmp); + //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_tmplate_filename_path); + writeImageFromBuffer(base64_tmplate_filename_path, g_decrypt_buff, base64_decode_length); + test_sfe_add_face_group(face_uid_tmp, base64_tmplate_filename_path); + + //if (viewChannelData[0].enable_add_face_frequent_list) + { + sqlite_facegroup_add_face_list(face_uid_tmp, visitor_tmp, "", "9964094f-df62-41a0-a666-134b3dbc9123", "100.0", base64_image_filename, "9964094f-df62-41a0-a666-134b3dbc9123", "", "", "vip", "00:00", "23:59", "2200-12-30_23:59"); + } + + //face_get_watchlist_members(); + + g_face_frame_uid++; + } +#endif + } +#endif + //free(image_buff); + //free(decrypt_buff); + + memset(g_image_buff, 0, MAX_IMG_SIZE_HD); + memset(g_decrypt_buff, 0, MAX_IMG_SIZE_HD); + + + char beforeSendBuffer[64]; + strcpy(beforeSendBuffer, "ok"); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(sock, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_face_list", strlen("POST /import_face_list")) == 0)) // 2023-12-19 Joy + { + printf("\n import_face_list \n"); + printf("recvbuffer: %s\n",recvbuffer); + + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /upload_face_licensekey", strlen("POST /upload_face_licensekey")) == 0)) // 2023-12-19 Joy + { + char *dataStart = strchr(recvbuffer, '{'); + if (dataStart != NULL) + { + char *dataEnd = strrchr(recvbuffer, '}'); + if (dataEnd != NULL) + { + size_t dataLength = dataEnd - dataStart + 1; + char jsonData[dataLength + 1]; + strncpy(jsonData, dataStart, dataLength); + jsonData[dataLength] = '\0'; + + char *customerStart = strstr(jsonData, "\"customer\":"); + if (customerStart != NULL) + { + char *customerEnd = strchr(customerStart, ','); + if (customerEnd != NULL) + { + char customerValue[100]; + int customerLength = customerEnd - (customerStart + 12); + strncpy(customerValue, customerStart + 12, customerLength); + customerValue[customerLength] = '\0'; + + if (strcmp(customerValue, "\"MERITLILIN_REST integration\"") == 0) + { + char *saveFilePath = "/emmc/plugin/Aida_data/sfe/iengine.lic"; + FILE *file = fopen(saveFilePath, "w"); + if (file != NULL) + { + fputs(jsonData, file); + fclose(file); + + char successResponse[] = "Please press the 'Apply' button to restart the device."; + int successResponseSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(successResponse), successResponse); + if (send(sock, sendBuffer, successResponseSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + else + { + char fileWriteError[] = "Failed to save the file."; + int fileWriteErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(fileWriteError), fileWriteError); + if (send(sock, sendBuffer, fileWriteErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + else + { + char invalidCustomerError[] = "Invalid customer value."; + int invalidCustomerErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(invalidCustomerError), invalidCustomerError); + if (send(sock, sendBuffer, invalidCustomerErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + } + else + { + char customerNotFoundError[] = "Customer not found in the request."; + int customerNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(customerNotFoundError), customerNotFoundError); + if (send(sock, sendBuffer, customerNotFoundErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + else + { + char dataEndNotFoundError[] = "End of data not found in the request."; + int dataEndNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(dataEndNotFoundError), dataEndNotFoundError); + if (send(sock, sendBuffer, dataEndNotFoundErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + else + { + char jsonDataNotFoundError[] = "JSON data not found in the request."; + int jsonDataNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(jsonDataNotFoundError), jsonDataNotFoundError); + if (send(sock, sendBuffer, jsonDataNotFoundErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + + closesocket(sock); + + memset(g_image_buff, 0, MAX_IMG_SIZE_HD); + memset(g_decrypt_buff, 0, MAX_IMG_SIZE_HD); + memset(buffer, 0x00, sizeof(buffer)); + + printf("\n-----------------------upload face licensekey: exit-----------------------\n"); +#if 1 + stop_test_nn_cavalry("upload face licensekey exit"); + //stop_server(); +#endif + //exit(EXIT_SUCCESS); + } +#endif + //usSleep(1000); + memset(buffer, 0x00, sizeof(buffer)); + } + + //printf("\n(%d) [http connection fun] isGetAlarmMotion: %d ", sock, isGetAlarmMotion); + //printf("\nweb process-----double free---2\n"); + if (isGetAlarmMotion) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 0 && socketRecords[j].sock == -1) + { + socketRecords[j].sock = sock; + + //memset(&(socketRecords[j].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[j].thread_id = 0; + socketRecords[j].channel_id = -1; + //socketRecords[j].last_recv_time = time(0); + //socketRecords[j].recent_sec_data[0].recv_time = socketRecords[j].last_recv_time; + socketRecords[j].isGetAlarmMotion = TRUE; + //socketRecords[j].isFirstAlarmMotion = FALSE; + if (websocket_connected) + { + //printf("Set sock:%d isWebSocketConnect: TRUE \n",sock); + socketRecords[j].isWebSocketConnect = TRUE; + } + else + { + //printf("Set sock:%d isWebSocketConnect: FALSE \n", sock); + socketRecords[j].isWebSocketConnect = FALSE; + } + socketRecords[j].isUdpSocket = FALSE; + socketRecords[j].isNvrRequest = 0; + socketRecords[j].isCredentialRequest = 0; + socketRecords[j].debug_type = 1; +#if defined GY_OS_AMBA + //socketRecords[j].iIsAIRelay = 0; +#endif + socketRecords[j].used = 1; + break; + } + } + } + + //printf("\n---------http connection handler ----------- 8\n"); + if (nbytes == SOCKET_ERROR) + { + printf("Unable to connect to server: %d\n", errno); + //printf("\n-----------temp_buffer:%s\n", temp_buffer); + //printf("Unable to connect to server: %d\n", WSAGetLastError()); + //usSleep(2000000); + //WSACleanup(); + //closesocket(sock); + } + + if (isGetAlarmMotion && websocket_connected) + { + //printf("\n(%d) [http connection fun] Sophia isGetAlarmMotion\n", sock); + + ///nreuse + int reuse = 0; + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int sock_err_hold_times = 0; + //int alarm_send_count = 0; + + while (bHttpServerMainStart) + { + python_check_webstatus = 1; // Ming add + if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) { + //printf("\n------------websocket break 1\n"); + break; + } + + int sock_idx = -1; + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //if (socketRecord_ALM[i].sock == sock) + //sock_idx = i; + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + sock_idx = i; + + socketRecords[i].debug_type = 6; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + break; + } + } + } + + if (sock_idx >= 0) + { + if (socketRecords[sock_idx].isGetAlarmMotion == FALSE || socketRecords[sock_idx].isWebSocketConnect == FALSE) { + //printf("\n------------websocket break 2\n"); + break; + } + pthread_mutex_lock(&mutex_alm); + int len = ALMQueueSize(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\n--------len:%d\n",len); + if (len > 0) + { + int ret = 1; + + for (int index_len = 0; index_len < len; index_len++) { + pthread_mutex_lock(&mutex_alm); + ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); + char dupstr[ALMBUFSIZE] = { 0 }; + //strcpy(dupstr, alm_q_info.websocket_content); + strcpy(dupstr, alm_q_info.pszContent); + //int dupstr_len = strlen(dupstr); + + ALMQueuePop(sock_idx); + pthread_mutex_unlock(&mutex_alm); + + //printf("\n---------strlen(dupstr):%d\n", strlen(dupstr)); + if (strlen(dupstr) >= 1) + { +#if 1 + //printf("\n---------%s\n", dupstr); + + //int iAlarm_send_delay_fps = 0; + + //if (socketRecord_ALM[sock_idx].iIsWebsockethybi00 == 1) + //iAlarm_send_delay_fps = WEBSOCKET_SEND_DELAY_B; //6 + //else + //iAlarm_send_delay_fps = WEBSOCKET_SEND_DELAY_A; //0 + + //if (alarm_send_count == iAlarm_send_delay_fps) + { + ret = websocket_response(sock, dupstr); + //alarm_send_count = 0; + } + //else + { + //ret = 1; + //alarm_send_count++; + } + + //ALMQueueClear(sock_idx); //᭱[F + if (ret <= 0) + { + printf("\n(%d) [http connection fun]#1 printf(send error) and close socket\n", sock); + break; + } + else + { + //printf("\n(%d) [http connection fun]Send successfully.\n", sock); + } +#endif + sock_err_hold_times = 0; + } + else + { + sock_err_hold_times++; + //printf("\n------sock_err_hold_times# A : %d\n", sock_err_hold_times); + } + + if (index_len < len - 1) { + usSleep(25000); + } + } + + + if (ret <= 0) { + break; + } + //printf("\n[http connection fun]-2-1: closesocket:%d\n", sock); + } + else { + sock_err_hold_times++; + //printf("\n------sock_err_hold_times# B : %d\n", sock_err_hold_times); + } + } + else + { + //printf("\n(%d) [http connection fun] there is no correct sock in socketRecord_ALM\n", sock); + sock_err_hold_times++; + //printf("\n------sock_err_hold_times# C : %d\n", sock_err_hold_times); + } +#ifdef GY_OS_AMBA + usSleep(25000); +#elif defined GY_OS_V_SERIES + usSleep(110000); +#else + usSleep(60000); +#endif + + } + + //printf("\n----------------------[http connection fun]Websocket: closesocket:%d\n",sock); + + closesocket(sock); + websocket_connected = 0; + } + else if (isGetAlarmMotion && !(websocket_connected)) + { + //printf("\n(%d) [http connection fun] Sophia isGetAlarmMotion\n", sock); + + int reuse = 1; + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int sock_err_hold_times = 0; + //int alarm_send_count = 0; + + while (bHttpServerMainStart) + { + if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) + break; + + int sock_idx = -1; + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //if (socketRecord_ALM[i].sock == sock) + //sock_idx = i; + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + sock_idx = i; + + socketRecords[i].debug_type = 7; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + break; + } + } + } + + if (sock_idx >= 0) + { + if (socketRecords[sock_idx].isGetAlarmMotion == FALSE) { + //set_record_process_note("getalarm_8592_end_1"); + break; + } + pthread_mutex_lock(&mutex_alm); + int len = ALMQueueSize(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\n(%d) [http connection fun] queue_len:%d\n", sock, len); + + if (len > 0) + { + int rtn_s = 1; + set_record_process_note("getalarm_8592_start"); + for (int index_len = 0; index_len < len; index_len++) { + pthread_mutex_lock(&mutex_alm); + ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); + //char *dupstr = strdup(alm_q_info.pszContent); + char dupstr[ALMBUFSIZE] = { 0 }; + strcpy(dupstr, alm_q_info.pszContent); + int dupstr_len = strlen(dupstr); + //int dupstr_len = alm_q_info.nSize; + + //printf("\n(%d) [http connection fun] (before send)dupstr_len:%d\n", sock, dupstr_len); + //printf("\nstrlen(dupstr): %d\n", strlen(dupstr)); + + ALMQueuePop(sock_idx); + pthread_mutex_unlock(&mutex_alm); + + if (strlen(dupstr) >= 1) + { +#if 1 + + //printf("\n[nweb.c]restful: %d\n", sock); + //int rtn_s = send(sock, alm_q_info_copy.szContent, alm_q_info_copy.nSize, MSG_NOSIGNAL); + //printf("\n-------------[http connection fun]Http: send:%d\n", sock); + rtn_s = send(sock, dupstr, dupstr_len, MSG_NOSIGNAL); + + //printf("\n(%d) [http connection fun](after send) ALMQueueClear",sock); + //ALMQueueClear(sock_idx); //᭱[F + //dupstr_len = alm_q_info.nSize; + + //printf("\nrtn_s: %d\n", rtn_s); + if (rtn_s <= 0 /*&& rtn_s2 <= 0 && rtn_s3 <= 0*/) + { + break; + } + else { + } + sock_err_hold_times = 0; +#endif + } + else { + sock_err_hold_times++; + } + + if (index_len < len - 1) { + usSleep(25000); + } + } + + if (rtn_s <= 0) { + set_record_process_note("getalarm_8592_end_2"); + break; + } + else { + set_record_process_note("getalarm_8592_end_3"); + } + //-------------------------------jim add 2021/04/15 CegetalarmmotionA|socket + //printf("\n[http connection fun]-2-1: closesocket:%d\n", sock); + //closesocket(sock); + } + else { + //set_record_process_note("getalarm_8592_end_4"); + sock_err_hold_times++; + } + } + else { + //set_record_process_note("getalarm_8592_end_5"); + //printf("\n(%d) [http connection fun] there is no correct sock in socketRecord_ALM\n", sock); + //closesocket(sock);//̥~hw + //break; + sock_err_hold_times++; + } + +#ifdef GY_OS_AMBA + usSleep(25000); +#elif defined GY_OS_V_SERIES + usSleep(110000); +#else + usSleep(60000); +#endif + } + + //printf("\n-------------[http connection fun]Http: closesocket:%d\n", sock); + closesocket(sock); + } + + if (isGetAlarmMotion) { + //printf("\n---------http connection handler ----------- 9\n"); + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == sock) + { + socketRecords[i].sock = -1; + //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + closesocket(sock); + + pthread_mutex_lock(&mutex_alm); + ALMQueueClear(i); + pthread_mutex_unlock(&mutex_alm); + + socketRecords[i].used = 0; + + break; + } + } + } + + //printf("\n---------http connection handler ----------- 11\n"); + //pthread_mutex_unlock(&mutex_http_connection_handler); + pthread_exit(NULL); +} + +int run_preload_http_server(int http_port) +{ + if (isGYNetReady == FALSE) + { + int socket_desc, client_sock; + struct sockaddr_in server, client; + socklen_t client_length = sizeof(client); + + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + if (socket_desc == -1) + { + printf("[run preload http server] Could not create a socket!\n"); + return 1; + } + //puts("Socket created"); + + //Prepare the sockaddr_in structure + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(http_port); + + struct timeval timeout; + timeout.tv_sec = 5; + timeout.tv_usec = 0; + + setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + int tcpnodelay = 1; + setsockopt(socket_desc, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + + int reuse = 1; + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(socket_desc, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) { + printf("\n[run preload http server] Could not bind a socket!\n"); + closesocket(socket_desc); + return 1; + } + + //puts("bind done"); + + if (listen(socket_desc, 256)) { + printf("\n[run preload http server] Could not listen from a socket!\n"); + closesocket(socket_desc); + return 1; + } + + //pthread_t thread_id; + + int count = 5; + fd_set active_fd_set, read_fds; + FD_ZERO(&active_fd_set); + FD_SET(socket_desc, &active_fd_set); + + struct timeval tvSelect; + tvSelect.tv_sec = 1; + tvSelect.tv_usec = 0; + int retval = 0; + is_authorized_run_preload_http_server = 1; + while (bPreloadHttpServerMainStart && (isGYNetReady == FALSE)) + { + for (int countloop = 0; bPreloadHttpServerMainStart && (isGYNetReady == FALSE) && countloop < count; countloop++) + { + read_fds = active_fd_set; + retval = select(socket_desc + 1, &read_fds, NULL, NULL, &tvSelect); + + if (retval == -1) { + printf("\nselect() error #1\n");//perror is strange in nova + break; + } + else if (retval == 0) + { + //printf("\nselect timeout\n"); + } + else + { + //for (int i = 0; i < 256; i++) + { + //if (FD_ISSET(i, &read_fds)) + if (FD_ISSET(socket_desc, &read_fds)) + { + //if (i == socket_desc) + { + client_sock = accept(socket_desc, (struct sockaddr *)&client, &client_length); + + if (client_sock < 0) + { + + } + else + { + timeout.tv_sec = 5; + timeout.tv_usec = 0; + + setsockopt(client_sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + //20210714 ADD + int reuse = 1; + setsockopt(client_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(client_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(client_sock, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + //if (check_if_socket_ok == 1) + //{ + pthread_t thread_id; + pthread_create(&thread_id, 0, http_connection_handler, (void*)(intptr_t)client_sock); + //} + //else { + //closesocket(client_sock); + //} + } + + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + //usSleep(1000); + //break; + } + } + //else { + //usSleep(50); + //} + } + } + + usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); + //usSleep(1000); + } + + if (retval == -1) { + break; + } + } + + is_authorized_run_preload_http_server = 0; + //bPreloadHttpServerMainStart = 0; + FD_CLR(socket_desc, &active_fd_set); + closesocket(socket_desc); + } + + return 0; +} + +int run_http_server(char *option, void* _zc, CNNType cnn_type/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, + char *mac_address, char *ip_address, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType) +{ + http_cnn_type = cnn_type; + for (int n = 0; n < MAX_LAYER_NUM; n++) + { + //http_nets[n] = nets[n]; + //http_names[n] = names[n]; + //http_nms[n] = nms[n]; + http_layerFeatureType[n] = layerFeatureType[n]; + } + //http_layer_count = layer_count; + //http_alphabet = alphabet; + http_thresh = thresh; + http_hier_thresh = hier_thresh; + http_dont_show = dont_show; + http_ext_output = ext_output; + http_save_labels = save_labels; + //http_mac_address = mac_address; + //http_ip_address = ip_address; + http_http_port = http_port; + http_licenseType = licenseType; + http_afsCode = afsCode; + http_featureType = featureType; + http_strLicenseType = strLicenseType; + //http_strLicenseStatus = strLicenseStatus; + //http_strUnlockingKey = strUnlockingKey; + http_advLicenseType = advLicenseType; + + if (unlockingKeyInnoFR == 1||g_IsToFDevice == 1 || g_IsRadarDevice == 1 || td_weight_num >= 1 || check_if_fe_fail == 1 || licenseType == _PERMANENT_LICENSE_MULTI || licenseType == _TRIAL_LICENSE_MULTI || licenseType == _PERMANENT_LICENSE_MULTI_POST || + licenseType == _LICENSE_FPS06 || licenseType == _LICENSE_FPS12 || licenseType == _LICENSE_FPS18 || licenseType == _LICENSE_FPS24 || licenseType == _LICENSE_FPS30 || + licenseType == _LICENSE_FPS36 || licenseType == _LICENSE_FPS42 || licenseType == _LICENSE_FPS48 || licenseType == _LICENSE_FPS54 || licenseType == _LICENSE_FPS60 || + licenseType == _TRIAL_LICENSE_FPS06 || licenseType == _TRIAL_LICENSE_FPS12 || licenseType == _TRIAL_LICENSE_FPS18 || licenseType == _TRIAL_LICENSE_FPS24 || licenseType == _TRIAL_LICENSE_FPS30 || + licenseType == _TRIAL_LICENSE_FPS36 || licenseType == _TRIAL_LICENSE_FPS42 || licenseType == _TRIAL_LICENSE_FPS48 || licenseType == _TRIAL_LICENSE_FPS54 || licenseType == _TRIAL_LICENSE_FPS60) //multi-thread server + { + int socket_desc = 0; + + //Web + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + if (socket_desc == -1) + { + printf("[run http server] Could not create a socket!\n"); + usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//קKsockإѫASW߰ݡC + return 1; + } + + struct sockaddr_in server; + bzero(&server, sizeof(server)); + + //Prepare the sockaddr_in structure + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(http_port); + + struct timeval timeout; + timeout.tv_sec = 5; + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + int priority = 2; + + setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socket_desc, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(socket_desc, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + setsockopt(socket_desc, SOL_SOCKET, SO_PRIORITY, (const char*)&priority, sizeof(priority)); + + if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) + { + printf("\n[run http server] Could not bind a socket!\n"); + closesocket(socket_desc); + usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//קKsockإѫASW߰ݡC + return 1; + } + //puts("bind done"); + + if (listen(socket_desc, 256) < 0)//MAX_CLIENT_SOCKET + { + printf("\n[run http server] Could not listen from a socket!\n"); + closesocket(socket_desc); + usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//קKsockإѫASW߰ݡC + return 1; + } + + int maxfd = 0; + fd_set active_fd_set, read_fds; + FD_ZERO(&active_fd_set); + FD_SET(socket_desc, &active_fd_set); + + struct timeval tvSelect; + tvSelect.tv_sec = 1; + tvSelect.tv_usec = 0; + int retval = 0; + + //pthread_t thread_id_for_sock[FD_SETSIZE] = { 0 }; + + //first_is_connection_authorized = 0; + while (bHttpServerMainStart) + { + //printf("\n[run http server] while start\n"); + //for (int countloop = 0; bHttpServerMainStart && countloop < count; countloop++) + { + maxfd = socket_desc; + //maxfd = socket_desc > sockfd ? socket_desc : sockfd; + //printf("\n----#1-----maxfd:%d\n", maxfd); + + read_fds = active_fd_set; + retval = select(maxfd + 1, &read_fds, NULL, NULL, &tvSelect); + //printf("\n [[[run http server] retval:%d]]\n", retval); + + if (retval == -1) { + printf("\nselect()\n"); + break; + } + else if (retval == 0) + { + //printf("\nselect timeout\n"); + } + else + { + //for (int i = 0; i < 256; i++)//FD_SETSIZE + { + //printf("\n [[[run http server] i:%d]]\n", i); + + //if (FD_ISSET(i, &read_fds)) + if (FD_ISSET(socket_desc, &read_fds)) + { + //if (i == socket_desc) + { + //printf("\n [[[run http server] i=socket_desc:%d]]\n", socket_desc); + struct sockaddr_in client; + socklen_t client_length = sizeof(client); + int client_sock = accept(socket_desc, (struct sockaddr *)&client, &client_length); + //#ifdef _DEBUG_AMBA + //printf("\n(%d) [[[run http server] while start ======================]]\n", client_sock); + //#endif + + if (client_sock < 0) + { + //printf("[[[run http server] invalid socket]]\n"); + } + else + { + + //printf("\n[[[run http server] while start 1======================]]\n"); + timeout.tv_sec = 5;//3 + timeout.tv_usec = 0; + //reuse = 1; + //qlen = 5; + + setsockopt(client_sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + //20210714 ADD + setsockopt(client_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(client_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(client_sock, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + setsockopt(client_sock, SOL_SOCKET, SO_PRIORITY, (const char*)&priority, sizeof(priority)); + + //printf("\n[[[run http server] while start 2======================]]\n"); + + + //if (check_if_socket_ok == 1) { + pthread_t thread_id; + pthread_create(&thread_id, 0, http_connection_handler, (void*)(intptr_t)client_sock); + //} + //else { + //closesocket(client_sock); + //} + } + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + //break; + } + //usSleep(1000); + //printf("\n[run http server] double free - 1\n"); + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); + } + //else { + //usSleep(50); + //} + //printf("\n[run http server] double free - 2\n"); + } + //printf("\n[run http server] double free - 3\n"); + } + //printf("\n[run http server] double free - 4\n"); + } + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + //printf("\n[run http server] while end\n"); + usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); + //usSleep(1000); + } + + FD_CLR(socket_desc, &active_fd_set); + //printf("\n\n(%d)[[[run http server] while end ======================]]\n\n", client_sock); + closesocket(socket_desc); + + } + else if (licenseType == _PERMANENT_LICENSE_SINGLE || licenseType == _TRIAL_LICENSE_SINGLE || licenseType == _PERMANENT_LICENSE_SINGLE_POST) //single thread version + { + + } + + //printf("\n[[[run http server] end ======================]]\n\n"); + return 0; +} + + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void import_lpr_list_file(char *headerBuffer,char *multiPartBoundary,int bIsMultipart,char *contentBuffer,long nTotalContentLen) { + //printf("\n---------------import lpr list:%d\n",1); + char *image_buff = NULL; + image_buff = malloc(CONTENT_BUFSIZE); + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr(headerBuffer, "boundary=")) != NULL) + { + //printf("\n---------------import lpr list:%d\n", 2); + + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, MAX_MSG_LEN); + //char endStr[] = "--"; + strncpy(multiPartBoundary, tempPtr, strlen); + //strcat(multiPartBoundary,endStr); + } + + } + } + //printf("\n---------------import lpr list:%d\n", 3); + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + //printf("\n---------------import lpr list:%d\n", 4); + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0)//find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + } + else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + } + } + } + + //printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); + //printf("\n---------------import lpr list:%d\n", 5); + //printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); + //printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); + //printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); + //printf("\n--------------contentBuffer:%s\n", contentBuffer); + +#if 1 + if (start_to_import_file == 0 && !((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) + { + printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); + } + else +#endif + { + start_to_import_file = 1; + + +#if 1 + char *lpr_data_p = NULL; + int rule_reject = 0; + int lpr_max_length = 0; + int lpr_b_length = 0; + int lpr_w_length = 0; + int _max_len = COUNT_BLACK + COUNT_WHITE - 200; + char *lpr_line_data = NULL, *name = NULL, *value = NULL; + int lpr_len = 0; + int nlen; + char *lpr_list_type = NULL; + char *lpr_name = NULL; + char *lpr_usrname = NULL; + char *lpr_other = NULL; + char *lpr_schedule_start = NULL; + char *lpr_schedule_end = NULL; + char *lpr_endtime = NULL; + char *lpr_detect_level = NULL; + //printf("\n---------------import lpr list:%d\n", 61101); + //printf("\n---------------import lpr list:%d\n", 61111); + //printf("\n---------------import lpr list:%d\n", 61121); + //printf("\n---------------import lpr list:%d\n", 9); + char *lpr_line_end = NULL; + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + lpr_data_p = image_buff + 2; + } + + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + //printf("\n---------------import lpr list:%d\n", 7); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + + //Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = value; + lpr_name = strstr(value, ",") + 1; + value = lpr_name; + lpr_usrname = strstr(value, ",") + 1; + //name = strsep(&value, ","); + //lpr_name = strsep(&value, ","); + //lpr_usrname = strsep(&value, ","); + + if (lpr_name == NULL || lpr_list_type == NULL || lpr_usrname == NULL) + break; + + if (lpr_max_length == _max_len) + { + //printf("\n---------------import lpr list:%d\n", 71); + rule_reject = 1; + break; + } + + if ((strncmp(name, ACT_PARAM_BKLISTNAME, strlen(ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_BKLISTNAME, strlen(S_ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, BKLISTNAME, strlen(BKLISTNAME)) == 0)) + lpr_b_length++; + else if ((strncmp(name, ACT_PARAM_WTLISTNAME, strlen(ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_WTLISTNAME, strlen(S_ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, WTLISTNAME, strlen(WTLISTNAME)) == 0)) + lpr_w_length++; + else + { + //printf("\n---------------import lpr list:%d\n", 72); + continue; + //rule_reject = 1; + //break; + } + + if (lpr_b_length > COUNT_BLACK - 100) + { + //printf("\n---------------import lpr list:%d\n", 73); + rule_reject = 1; + break; + } + + if (lpr_w_length > COUNT_WHITE - 100) + { + //printf("\n---------------import lpr list:%d\n", 74); + rule_reject = 1; + break; + } + + lpr_max_length++; + + lpr_line_end = strstr(lpr_line_data, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + //printf("\n---------------import lpr list:%d\n", 8); + if (rule_reject != 1) + { + //printf("\n---------------import lpr list:%d\n", 88); + //callback_reset_db_list(); //clean black&white + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + //printf("\n--------------image_buff:%s\n", image_buff + 2); + lpr_data_p = image_buff + 2; + } + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + /* Skip to next assignment */ + //fprintf(stderr, "[string] : %s\n", lpr_line_data); + //fprintf(stderr, "[string len] : %d\n", strlen(lpr_line_data)); + + //Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = strsep(&value, ","); + lpr_name = strsep(&value, ","); + lpr_usrname = strsep(&value, ","); + lpr_other = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + lpr_schedule_start = strsep(&value, ","); + lpr_schedule_end = strsep(&value, ","); + lpr_endtime = strsep(&value, ","); + if ((lpr_detect_level = strsep(&value, "\r\n")) == NULL) + lpr_detect_level = strsep(&value, "\n"); + lpr_detect_level = rtrim(lpr_detect_level); + + //lpr_exist= strsep(&value, ","); + //lpr_paystatus = strsep(&value, ","); + //lpr_paystatus =rtrim(lpr_paystatus); + + for (int try_counts = 0; try_counts < 5; try_counts++) { + int ret_action = action_lpr_import_infomation(lpr_name, lpr_list_type, lpr_usrname, lpr_other, lpr_schedule_start, lpr_schedule_end, lpr_endtime, lpr_detect_level); //lpr_other); + if (ret_action) + break; + usSleep(10000); + } + + g_count_lpr_insert_times++; + lpr_line_end = strstr(lpr_line_data, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + } +#endif + printf("lpr list file upload ok.\n"); + } + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + //printf("\n---------------import lpr list:%d\n", 11); + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time: %f\n", dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } +} + +void *import_lpr_list_file_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("import_lpr"); + //printf("\n--------------import lpr list file thread\n"); + import_lpr_list_file(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); + g_count_lpr_insert_times = -1; + pthread_exit(NULL); +} +#ifdef GY_OS_AMBA +void import_face_list_file(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen) { + //printf("\n---------------import lpr list:%d\n",1); + char *image_buff = NULL; + image_buff = malloc(CONTENT_BUFSIZE); + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr(headerBuffer, "boundary=")) != NULL) + { + //printf("\n---------------import lpr list:%d\n", 2); + + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, MAX_MSG_LEN); + strncpy(multiPartBoundary, tempPtr, strlen); + } + + } + } + //printf("\n---------------import lpr list:%d\n", 3); + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + //printf("\n---------------import lpr list:%d\n", 4); + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0)//find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + } + else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + } + } + } + + //printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); + //printf("\n---------------import lpr list:%d\n", 5); + //printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); + //printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); + //printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); + //printf("\n--------------contentBuffer:%s\n", contentBuffer); + + if (start_to_import_file == 0 && !((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) + { + printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); + } + else + { + start_to_import_file = 1; + + char *lpr_data_p = NULL; + int rule_reject = 0; + int lpr_max_length = 0; + int lpr_b_length = 0; + int lpr_w_length = 0; + int _max_len = COUNT_BLACK + COUNT_WHITE - 200; + char *lpr_line_data = NULL, *name = NULL, *value = NULL; + int lpr_len = 0; + int nlen; + char *lpr_list_type = NULL; + char *lpr_name = NULL; + char *lpr_usrname = NULL; + char *lpr_other = NULL; + char *lpr_schedule_start = NULL; + char *lpr_schedule_end = NULL; + char *lpr_endtime = NULL; + char *lpr_detect_level = NULL; + //printf("\n---------------import lpr list:%d\n", 61101); + //printf("\n---------------import lpr list:%d\n", 61111); + //printf("\n---------------import lpr list:%d\n", 61121); + //printf("\n---------------import lpr list:%d\n", 9); + char *lpr_line_end = NULL; + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + lpr_data_p = image_buff + 2; + } + + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + //printf("\n---------------import lpr list:%d\n", 7); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + + // Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = value; + lpr_name = strstr(value, ",") + 1; + value = lpr_name; + lpr_usrname = strstr(value, ",") + 1; + + if (lpr_name == NULL || lpr_list_type == NULL || lpr_usrname == NULL) + break; + + if (lpr_max_length == _max_len) + { + //printf("\n---------------import lpr list:%d\n", 71); + rule_reject = 1; + break; + } + + if ((strncmp(name, ACT_PARAM_BKLISTNAME, strlen(ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_BKLISTNAME, strlen(S_ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, BKLISTNAME, strlen(BKLISTNAME)) == 0)) + lpr_b_length++; + else if ((strncmp(name, ACT_PARAM_WTLISTNAME, strlen(ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_WTLISTNAME, strlen(S_ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, WTLISTNAME, strlen(WTLISTNAME)) == 0)) + lpr_w_length++; + else + { + continue; + } + + if (lpr_b_length > COUNT_BLACK - 100) + { + rule_reject = 1; + break; + } + + if (lpr_w_length > COUNT_WHITE - 100) + { + rule_reject = 1; + break; + } + + lpr_max_length++; + + lpr_line_end = strstr(lpr_line_data, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + //printf("\n---------------import lpr list:%d\n", 8); + if (rule_reject != 1) + { + //printf("\n---------------import lpr list:%d\n", 88); + //callback_reset_db_list(); //clean black&white + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + //printf("\n--------------image_buff:%s\n", image_buff + 2); + lpr_data_p = image_buff + 2; + } + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + /* Skip to next assignment */ + //fprintf(stderr, "[string] : %s\n", lpr_line_data); + //fprintf(stderr, "[string len] : %d\n", strlen(lpr_line_data)); + + //Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = strsep(&value, ","); + lpr_name = strsep(&value, ","); + lpr_usrname = strsep(&value, ","); + lpr_other = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + lpr_schedule_start = strsep(&value, ","); + lpr_schedule_end = strsep(&value, ","); + lpr_endtime = strsep(&value, ","); + if ((lpr_detect_level = strsep(&value, "\r\n")) == NULL) + lpr_detect_level = strsep(&value, "\n"); + lpr_detect_level = rtrim(lpr_detect_level); + + //lpr_exist= strsep(&value, ","); + //lpr_paystatus = strsep(&value, ","); + //lpr_paystatus =rtrim(lpr_paystatus); + + for (int try_counts = 0; try_counts < 5; try_counts++) { + int ret_action = action_lpr_import_infomation(lpr_name, lpr_list_type, lpr_usrname, lpr_other, lpr_schedule_start, lpr_schedule_end, lpr_endtime, lpr_detect_level); //lpr_other); + if (ret_action) + break; + usSleep(10000); + } + + g_count_lpr_insert_times++; + lpr_line_end = strstr(lpr_line_data, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + } + printf("lpr list file upload ok.\n"); + } + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + //printf("\n---------------import lpr list:%d\n", 11); + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time: %f\n", dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } +} + +void *import_face_list_file_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("import_lpr"); + import_face_list_file(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); + g_count_lpr_insert_times = -1; + pthread_exit(NULL); +} + +int get_g_check_if_change_preset() { + return g_check_if_change_preset; +} + +void set_g_check_if_change_preset_to_zero() { + g_check_if_change_preset = 0; +} +#endif +#endif + +#ifdef GY_OS_AMBA +// a113n radarbg + +void import_radarbg(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen) +{ + // printf("\n---------------import lpr list:%d\n",1); + printf("[import_radarbg] Enter\n"); + char *image_buff = NULL; + image_buff = malloc(CONTENT_BUFSIZE); + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr(headerBuffer, "boundary=")) != NULL) // ڲqoONӦ http request header }, ]ɮ׸b᭱ + { + // printf("\n---------------import lpr list:%d\n", 2); + + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, MAX_MSG_LEN); + // char endStr[] = "--"; + strncpy(multiPartBoundary, tempPtr, strlen); + // strcat(multiPartBoundary,endStr); + } + } + } + // printf("\n---------------import lpr list:%d\n", 3); + + if (bIsMultipart) // oڲqOpGɮ׳Qhʥ]Bz + { + char *pContent = contentBuffer; + char *pBlockStart = contentBuffer; + + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + // printf("\n---------------import lpr list:%d\n", 4); + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0) // find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + } + else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + } + } + } // ӬO image_buff Oɮ , oO img ӬOT}C + + // printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); + // printf("\n---------------import lpr list:%d\n", 5); + // printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); + // printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); + // printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); + // printf("\n--------------contentBuffer:%s\n", contentBuffer); + + { // img s + // Mat tempImg; + // tempImg = Mat(600, 800, CV_8UC3, image_buff); // @}Cn pitch Oԣ + // printf("[import_radarbg] tempImg init success\n"); + // imwrite("/emmc/plugin/Aida_data/radar/radar_uploadtest.jpg", tempImg); + // printf("[import_radarbg] imwrite success\n"); + // tempImg.release(); + // WO c++ code ҥHoΤU tX}Y include colordetector.cpp + printf("[import_radarbg] saverawrgbtojpg enter\n"); + SaveRawRGBToJPG("/emmc/plugin/Aida_data/radar/radar_uploadtest.jpg", image_buff, 800, 0, 600, 1); // For normal type + printf("[import_radarbg] saverawrgbtojpg end\n"); + } + +#if 0 + if (!((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) // oOɮˬd nT{@U jpg 榡ˬd + { + printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); + } + else + { // ɮ׹FUӴNs ڲq oӭnhsϤ + Mat tempImg; + tempImg = Mat(h, w, CV_8UC3, image_buff); + printf("radar back ground img file upload ok.\n"); + } +#endif + + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } +} + +void *import_radarbg_thread(void *ptr) +{ + pthread_detach(pthread_self()); + import_radarbg(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); + // g_count_lpr_insert_times = -1; + pthread_exit(NULL); +} +#endif \ No newline at end of file diff --git a/src/nweb.h b/src/nweb.h new file mode 100644 index 0000000..921d957 --- /dev/null +++ b/src/nweb.h @@ -0,0 +1,1124 @@ +#if 1 +#pragma once +#ifndef NWEB_H +#define NWEB_H +//#include "structures.h" +#include "define_inc.h" +#include "zlog.h" +#include "cv.h" +#include "utility.h" +#include "onvif_data.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +#include <sys/types.h> +#include <sys/socket.h> +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include <stdbool.h> +#endif +#ifdef GY_OS_WIN +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#endif + +#include <curl/curl.h> +#include <curl/easy.h> +#include <sys/prctl.h> + +#ifdef GY_OS_AMBA +//#include "face_parser.h" +#endif + +#ifdef __cplusplus +extern "C" { +#include <stdint.h> +#include <stdlib.h> +#endif + +#define CONTENT_BUFSIZE MAX_IMG_BUFF_SIZE +#define LOG_BUFSIZE (BUFSIZE<<1) +#define NW_ERROR 1 +#define NW_SORRY 2 +#define NW_LOG 3 +#define LINE_BUFSIZE 7*8192 //512 +#define MAX_SIZE_POINT 6 +#define MAX_NUMBER_PAGE 59 +#define HEADER_BUFSIZE 1024 + +#define WEBPYTHONBUFFER_LENSIZE 256 +#define WEBPYTHONBUFFER_ROWSIZE 256 +#define MAX_GET_PYTHON_BUFFER_ROW_SIZE 8 + +#ifdef GY_OS_NOVA +#define MEMORY_SIZE 256*1024 +#endif + +#ifdef GY_OS_AMBA +#define MEMORY_SIZE 512*1024 +#endif + +#define MAX_SERVICE_SIZE 256 + +#define MAX_SIZE_A_OSD_OBJECT 11 +#define MAX_SIZE_A_SP_OBJECT 6 + + //trigger types +#define TRIGGER_OUTSIDE_INSIDE 1 +#define TRIGGER_INSIDE_OUTSIDE 2 +#define TRIGGER_INSIDE_INSIDE 3 +#define TRIGGER_OUTSIDE_OUTSIDE 4 + + /*typedef struct + { + int x; + int y; + } Point;*/ + + /*typedef struct { + char* recvBuffer; + char* contentBuffer; + } BufferPtr;*/ + + /*typedef struct { + time_t recv_time; + int frames; + } SecData;*/ + + typedef struct + { + struct tm * snapshot_time; + time_t snapshot_time_mktime; + time_t snapshot_msecs_time; + char snapshot_addr[MAX_IMG_SIZE]; + int snapshot_size; + }SnapHDInfo; + + typedef struct + { + char weight_repository[35]; + int enable_weight_to_run; + }WeightFileInfo; + + typedef struct + { + char email_address1[50]; + char email_address2[50]; + char email_address3[50]; + char email_address4[50]; + char email_address5[50]; + + char email_address[50]; + + char smtp_server[50]; + int smtp_auth_mode; + char smtp_port[10]; + int smtp_auth; + + char auth_account[50]; + char auth_password[50]; + } IPCAMServiceInfo; + + typedef struct + { + int checked; + char detect_event_id[20]; + char detect_event_name[50]; + char post_event_name[MAX_MSG_LEN * 10]; + char counter_name[MAX_MSG_LEN * 10]; + int counter_increment; + //TriggerData [MAX_DETECT_OBJECTS]; + } TriggerEvent; + + typedef struct + { + bool isActive; + + /*char levenshtein_distance[10]; + char min_characters[10]; + char max_characters[10]; + char confidence[10];*/ + char enable_traffic_light[10]; + //char enable_social_distance[10]; +#ifdef GY_OS_AMBA + CvMat* PerspectiveTransformArray; +#endif + char detection_time[20]; + char metadata1[BUFSIZE]; + char metadata2[BUFSIZE]; + char metadata_stop[50]; + char link_to_counter[10]; + char enable_direction1[10]; + char enable_direction2[10]; + char direction1[10]; + char direction2[10]; + int no_parking_time; + int no_parking_time_in_minute; + int queuing_count; + int prev_queuing_num; + int queuing_trigger_event_idx; + char ptz_zone_to_preset[20]; + + TriggerEvent trigger_event[MAX_TRIGGER_EVENT]; + CPoint Points[6]; + int min_x_points; + int max_x_points; + int min_y_points; + int max_y_points; + + f_CPoint onvif_Points[6]; + + int parking_space; + int parking_line; + + //Social Distance + float set_distance; + char world_distance_unit[10]; + float world_distance[DETECTION_POINTS_COUNT]; + int distance_violation_count; + int prev_distance_violation_num; + time_t prev_distance_violation_time; + time_t recent_distance_violation_start_time; + int distance_trigger_event_idx; + //float LinearFormula[DETECTION_POINTS_COUNT][3]; //4 edges, each edge has it's ax+by+c =0 values + //char* MovingDirection[DETECTION_POINTS_COUNT]; + + int point_num; + + int obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; + int last_obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; + int last_two_obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; + int check_if_missing; + + char enable_speed[10]; + char enable_radar_speed[10]; + char enable_ivs_zone[10]; + float world_distance_side1; + float world_distance_side2; + char world_time_unit[20]; + + char obj_max_proportion_in_zone[10]; + char obj_min_proportion_in_zone[10]; + + //int speed_upper_bound;//Чset_distance + //int speed_lower_bound;//Чset_distance + + //char confidence3[10]; +#if defined GY_OS_AMBA + //jvc setting + int jvc_enable_detect; + int jvc_person_check; + int jvc_vehicle_check; + int jvc_person_confidence; + int jvc_vehicle_confidence; + int jvc_behavior; + int jvc_obj_size; + int jvc_detect_priority; + int jvc_detect_mode; + int jvc_detect_fov; + int jvc_trigger_delay_time; + int jvc_trigger_times; + int jvc_queuing_count; + int jvc_enable_direction1; + int jvc_direction1; + char jvc_counter_name[50]; + int jvc_counter_value; + int jvc_density_value; + + int jvc_enable_ptz; + int jvc_ptz_tracking_time; + int jvc_ptz_fov; + int jvc_ptz_auto_intercept; + int jvc_ptz_preset_intercept; + int jvc_ptz_zone_to_preset; +#endif + } DetectionZoneInfo; + + typedef struct + { + int channel_idx; + int enable_anpr; + int enable_face; + int enable_traffic; + int enable_logo; + int enable_add_face_frequent_list; + int tab_view_width; + int tab_view_height; + float tab_view_width_ratio; + float tab_view_height_ratio; + float speed_view_width_ratio; + float speed_view_height_ratio; + char camera_name[20]; + char obj_max_proportion[10]; + char obj_min_proportion[10]; + char levenshtein_distance[10]; + char min_characters[10]; + char max_characters[10]; + + int i_plate_filter_times; + int i_plate_filter_time; + int i_plate_free_time; + + char confidence[10]; //P Plate + char confidence2[10]; //q Traffic + char confidence3[10]; //SΨ None + char confidence4[10]; //SΨ None + int enable_traffic_light_zone; + //int enable_social_distance_zone; + char traffic_light_color[20]; + //CvMat* PerspectiveTransformArray; + char enable_lpr_db[10]; + char enable_PTZ[10]; + char enable_track[10]; + + char ivs_mode[10]; + + char ptz_tracking_fov_min[10]; + char ptz_tracking_fov_max[10]; + char ptz_enable_tracking[10]; + char ptz_tracking_resume_dwell[10]; + int ptz_tracking_by_enter_zone; + int ptz_tracking_mode; + int ptz_sensitivity; + int iVideo_source_w; + int iVideo_source_h; + + char enable_tracking_limits[10]; + char ptz_pan_left_limit[20]; + char ptz_pan_right_limit[20]; + char ptz_tilt_up_limit[20]; + char ptz_tilt_down_limit[20]; + char ptz_speed[20]; + + char enable_unknown_object[10]; + char enable_ivs_person_detection[10]; + + char assign_ivs_object_to[100]; + + char enable_ambulance[10]; + char enable_blank_plate[10]; + char enable_stop_sign[10]; + + char enable_ivs_fix_mode[10]; + + char enable_show_unknown_object[10]; + char enable_ivs_and_ai[10]; + char enable_lpr_upon_triggered[10]; + + char dwell_lpr_upon_triggered[10]; + + char unknown_object_max_proportion[10]; + char unknown_object_min_proportion[10]; + char confidence_unknown_object[10]; + char confidence2_unknown_object[10]; + char dwell_unknown_object[10]; + char dwell_minute_focus_on[10]; + char person_obj_fov[10]; + + char getnetwork_buffer_id[10]; + + char red_light_zone[10]; + char no_give_way_zone_to_protect[10]; + char no_give_way_zone_to_keep_away[10]; + char no_give_way_zone_to_protect_2[10]; + char no_give_way_zone_to_keep_away_2[10]; + int count_zone; + + } ChannelInfo; + + typedef struct + { + char enable_person_independent[10]; + char enable_onvif_profile_m[10]; + char enable_crop_mode[10]; + char nms_thres[10]; + char tracking_id_dwell[10]; + + char enable_cloud[10]; + char enable_special_edition[10]; + char enable_python[10]; + char enable_python_file[50]; + char enable_low_cpu_usage[10]; + char cloud_enable_snap[10]; + char cloud_enable_notification[10]; + char cloud_account[256]; + char cloud_password[256]; + char cloud_notification_dwell[10]; + char cloud_statue[MEMORY_SIZE]; + char language[50]; + + char enable_display_properties[10];//enable to show color + char enable_display_OSD[10]; + + char enable_special_char[10]; + char enable_bounding_box[10]; + + char enable_dwell_bounding_box[10]; + + char force_i_to_one[10]; + char force_o_to_zero[10]; + char enable_plate_angle_correction[10]; + + char enable_ai_mirror[10]; + char ai_mirror_feature[10]; + + char enable_cloud_v2[10]; + char cloud_v2_notification_dwell[10]; + char cloud_v2_content[BUFSIZE_V3]; + char enable_cloud_record_v2[10]; + char cloud_record_v2_notification_dwell[10]; + char cloud_record_v2_content[BUFSIZE_V3]; + + char cloud_v2_statue[MEMORY_SIZE]; + char cloud_record_v2_statue[MEMORY_SIZE]; + + char enable_post_only_if_both_detected[10]; + + char enable_getalarmmotion_snap[10]; + char getimage_encoder_id[10]; + char getimage_encoder_id_HD[10]; + + char osd_encoder_id[10]; + char osd_font_size[10]; + char osd_outline_lilin[10]; + char enable_osd_bottom[10]; + char osd_bottom_bg_tran[10]; + char osd_bottom_content[BUFSIZE_V3]; + + + char sensors_type[10]; + + char enable_sync_external_lpr_db[10]; + char external_lpr_db_IP[256]; + char external_lpr_db_port[10]; + char external_lpr_db_username[60]; + char external_lpr_db_password[60]; + + char enable_email_notification[10]; + char enable_system_logs[10]; + char enable_email_jpeg[10]; + char send_counter_at_specific_hour[10]; + char email_reset_time_interval[20]; + + char enable_ftp[10]; + char ftp_url[256]; + char ftp_port[25]; + char ftp_username[256]; + char ftp_password[256]; + char ftp_remote_directory[1024]; + char ftp_jpeg_file_name_format[10 + 1]; + char ftp_jpeg_file_name[60]; + + } SystemSettingInfo; + + typedef struct + { + char post_protocol[10 + 1]; + char post_event_method[10+1]; + char post_event_name[60]; + char post_host_ip[256]; + char post_host_port[5+1]; + char post_url[8192];//BUFSIZE_V2 + char post_username[60]; + char post_password[60]; + char post_content[MAX_IMG_SIZE]; + char post_customized_header[8192]; + + //unsigned char post_content_bin[MAX_HTTP_BUFFER]; + char post_sequence[60]; + + char post_file_format[10 + 1]; + char post_jpeg_file_name_format[10 + 1]; + char post_jpeg_file_name[60]; + + char post_timeout[10]; + + int check_if_delivering; + } PostEventInfo; + + typedef struct + { + char email_content[BUFSIZE_V3]; + //unsigned char email_content_bin[MAX_HTTP_BUFFER]; + } EmailInfo; + + typedef struct { + //int nListIndex; + char counter_name[36 + 1]; + int counter_zone; + char counter_cust_name[256]; + char counter_unit[16 + 1]; + int reset_value; + + int reset_year; + int reset_month; + int reset_month_day; + int reset_week_day; + int reset_hour; + int reset_min; + int reset_sec; + + int gmt_year; + int gmt_month; + int gmt_month_day; + int gmt_week_day; + int gmt_hour; + int gmt_min; + int gmt_sec; + + int next_year; + int next_month; + int next_month_day; + int next_week_day; + int next_hour; + int next_min; + int next_sec; + + char ReportTimeInterval[30]; + char ResetTime[50]; + + int already_reset; + int counter_count; + time_t timetResetAt; + time_t next_timetResetAt; + + char enable_reset_time_interval[10 + 1]; + char reset_time_interval[36 + 1]; + char reset_at[36 + 1]; + + char enable_time_range[10 + 1]; + char time_range_from[36 + 1]; + char time_range_to[36 + 1]; + time_t timetTimeRangeFrom; + time_t timetTimeRangeTo; + + char link_to_post_event_name[256]; + char post_interval[36 + 1]; + + int dwell_time; + char dwell_unit[10 + 1]; + + //char MetaOut1[512][50]; + //int metadata1_num; + + char enable_reset_only_cloud[10 + 1]; + char enable_linked_to_dwell_time[10 + 1]; + time_t last_post_time; + + } EventCounterInfo; + + typedef struct { + char counter_a[20]; + char counter_a_name[50]; + char counter_a_zone[10]; + char counter_b[20]; + char counter_b_name[50]; + char counter_b_zone[10]; + char counter_c_name[50]; + + char report_max_value[20]; + + char enable_report[10]; + + char counter_mode[20]; + + char initial_icon[50]; + char output_icon[50]; + + char detection_output[100]; + + } ReportCounterInfo; + + typedef struct { + char snmp_event_name[256]; + char snmp_version[10]; + char snmp_group_name[256]; + char snmp_host_ip[256]; + char snmp_host_port[10]; + char snmp_oid[256]; + char snmp_value[BUFSIZE]; + char snmp_type[20]; + + int check_if_delivering; + } SNMPManagementInfo; + + //20201027 sophia add + //read from [ipcam /usr/local/bin/nvclient -k user.password0 /usr/local/bin/nvclient -k user.account0 ...9] + //save to config.json account_setting->account_data + typedef struct { + char account_username[256]; + char account_password[256]; + char account_port[50]; + char account_mirror[20]; + char account_flip[20]; + char account_rotate[20]; + char account_aida_port[50]; + int account_type; //default ? + int account_status; //default ? + } AccountDataInfo; + + typedef struct { + //pthread_t thread_id; + SOCKET sock; + int channel_id; + double fps; + //time_t last_recv_time; + //SecData recent_sec_data[FPS_AVG_SECS]; + int isGetAlarmMotion; + //int isFirstAlarmMotion; + int isWebSocketConnect; + int isNvrRequest; + int isCredentialRequest; +#if defined GY_OS_AMBA || defined GY_OS_NOVA + int isUdpSocket; //20201112 sophia add +#endif //GY_OS_AMBA + uchar* prev_frame_data; + //int iIsWebsocketHybi00; +#if defined GY_OS_AMBA + //int iIsAIRelay; +#endif + int debug_type; + + int used; + + } SocketInfo; + + typedef struct { + char curl_url[8192]; + char curl_sendbuf[8192]; + char method[32]; + char username[64]; + char password[64]; + char port[10]; //strtol(q_info->host_port, NULL, 10) + } CURL_SEND; + + typedef struct { + int tof_version; + bool tof_debug; + int tof_install_angle; + bool tof_enable_camera; + bool enable_tof_ground; + bool enable_tof_wall; + + char tof_camera_ip[256]; + char tof_camera_port[10]; + char tof_camera_sub_url[8192]; + char tof_auth_key[8192]; + bool tof_ip_setting; + char tof_camera_username[512]; + char tof_camera_password[512]; + + char distance_options[10]; + char distance_min_max[10]; + char distance_threshold[20]; + char height_options[10]; + char height_min_max[10]; + char height_threshold[20]; + + char ground_x[10]; + char ground_y[10]; + } TofInfo; + + typedef struct { + char enable_heartbeat[10]; + char events_default_version[10]; + char heartbeat_dwell[10]; + char heartbeat_link_to_post_event_name[256]; + + char dwell_to_the_same_location[10]; + + char enable_snmp_heartbeat[10]; + char snmp_heartbeat_dwell[10]; + char snmp_heartbeat_link_to_post_event_name[256]; + + char enable_only_once_to_post[10]; + char enable_obj_once_to_post[10]; + char enable_location_once_to_post[10]; + char enable_nvr_once_to_getalarmmotion[10]; + char enable_8592_once_to_getalarmmotion[10]; + + char heatmap_max[20]; + char enable_heatmap[10]; + char heatmap_frequency[20]; + char lpr_title[256]; + + char enable_counter_snap[10]; + char enable_barcode_qr[10]; + + char enable_check_ptz_start_autotracking[10]; + char enable_check_ptz_end_autotracking[10]; + char ptz_start_autotracking_link_to_post_event_name[256]; + char ptz_end_autotracking_link_to_post_event_name[256]; + } HeartbeatInfo; + + typedef struct { + char sPlateNumber[100]; + time_t t_FirstGetTime; + time_t t_UpdateTime; + time_t t_LoopTime; + + int iGetCounter; + int iIfUse; + + float box_x; + float box_y; + float box_w; + float box_h; + + float last_box_x; + float last_box_y; + float last_box_w; + float last_box_h; + + float last_box_center_x; + float last_box_center_y; + + int iPlateZoomOutCounter; + int iPlateZoomInCounter; + + int iTrackingID; + //int iTrackingIDidx; + + int existing_dash; + + char car_type_name[20]; + int check_if_counted[MAX_DETECTION_ZONE]; + + } PlateRecoder; + + typedef struct { + //char name[30]; + //int class_id; + + time_t t_FirstGetTime; + time_t t_UpdateTime; + + int iGetCounter; + int iIfUse; + + float box_x; + float box_y; + float box_w; + float box_h; + + //float left_x; + //float top_y; + + int iTrackingID; + //int iTrackingIDidx; + + int check_if_counted[MAX_DETECTION_ZONE]; + + } ObjectRecoder; + + typedef struct { + char name[30]; + char sPlateNumber[100]; + + time_t t_FirstGetTime_total; + time_t t_FirstGetTime; + time_t t_UpdateTime; + + int iIfUse; + + float box_x; + float box_y; + float box_w; + float box_h; + + int check_if_post[MAX_DETECTION_ZONE]; + int check_if_cloud; + int check_if_cloud_v2; + int check_if_cloud_record_v2; + int check_if_email; + int check_if_ftp; + int check_if_getalarmmotion; + + int object_id; + int zone_idx; + + //int the_same_id; + + float count_trigger; + + //detection_pos ori_Data; + //int iIsInvisible; + //time_t t_InvisibleStartTime; + //time_t t_InvisibleUpdateTime; + + } PostRecoder; + + + typedef struct { + + int locked; + + int used; + float box_x; + float box_y; + float box_w; + float box_h; + + } MotionAreaInfo; + + typedef struct { + int color_mode;//image.dn.switch //0 auto mode; 1 day mode; 2 night mode; 3 schedule mode + int light_sensor_value;//image.dn.luminosity + int day_to_night_threshold;//image.dn.luminosity.dtn + int night_to_day_threshold;//image.dn.luminosity.ntd + int dwell_sec_in_auto_mode;//image.dn.switch.dwell + int day_to_night_time_of_schedule;//image.dn.schedule.day + int night_to_day_time_of_schedule;//image.dn.schedule.night + + int hour_day_to_night; + int min_day_to_night; + int total_min_day_to_night; + + int hour_night_to_day; + int min_night_to_day; + int total_min_night_to_day; + + int current_day_or_night_mode;//result // day : 1 ; night : 2 + int last_day_or_night_mode; + + int check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED]; + + //int ircut; + //int irledfar; + //int irlednear; + + int iAutoModeSwitchCount; + } ImageDn; + + typedef struct { + int id; + int flag_protected; + int x; + int y; + int w; + int h; + int color; + int size; + int show_sec; + int bg_tran; //0~255 + int outline_sw; //0:off 1:on + char text[256]; + } OSDInfo; + + typedef struct { + int flag_protected; + float speed; + char speed_unit[256]; + float res_width; + float res_height; + float x; + float y; + } SpeedInfo; + + extern char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; + extern unsigned int g_uiWebPythonCurrentBufferIndex; + extern unsigned int g_uiWebPythonLastBufferIndex; + extern unsigned int g_cWebPythonBufferSignal; + extern unsigned int g_cWebPythonDeleteStatus; + extern char g_cWebPythonName[50]; + extern unsigned int g_cWebPythonStatus; + extern unsigned int python_check_webstatus; // } plugin ɥΪ + + extern bool isGYNetReady; + +//===================== +//sophia add 2020/09/24 +#if defined GY_OS_AMBA || defined GY_OS_NOVA + +#include "alm_queue.h" + + typedef struct { + SOCKET sock; + //stALMNode *head; + //stALMNode *tail; + //int iIsWebsockethybi00; + } SocketInfo_ALM; + + //extern SocketInfo_ALM socketRecord_ALM[MAX_CLIENT_SOCKET]; + extern int bHttpServerMainStart; + extern int bPreloadHttpServerMainStart; +#endif //GY_OS_AMBA +//===================== + + extern int g_check_ping_OK; + + extern int g_sdk_version; + + extern int CheckIsExistingSpeed; + + extern SocketInfo socketRecords[MAX_CLIENT_SOCKET]; + extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; + extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; + extern SystemSettingInfo SystemSetting; + extern PostEventInfo postEventList[MAX_POST_EVENTS]; +#ifdef GY_OS_V_SERIES + +#else + extern EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS]; + extern ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS]; + extern SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT]; +#endif + + extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add + extern IPCAMServiceInfo IPCAMService; + extern SnapHDInfo snapHDList[MAX_SNAP_HD_LIST]; + extern WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST]; + extern char WeightFileModeName[35]; + extern EmailInfo emailData; + extern HeartbeatInfo heartbeatData; +#ifdef GY_OS_AMBA + extern TofInfo tofData; +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + extern PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER]; +#endif + extern ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER]; + extern PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE]; + extern PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE]; + + //extern MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA]; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + extern ImageDn imageDnData; + +#endif + +#ifdef GY_OS_AMBA + + extern OSDInfo OSDData[MAX_SIZE_OSD_ARRAY]; + extern SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY]; +#endif + extern int g_PlateFilterTimes; //Times + extern int g_PlateFilterTime; //Second + extern int g_PlateRecorderFreeTime; //Second +#ifdef GY_OS_AMBA + extern int g_face_frame_uid; +#endif + extern int g_IsRadarDevice; + extern char radar_json_data[4096]; + + extern int unlockingKeyInnoFR_success; + extern int unlockingKeyInnoFR; + + extern int g_IsSDK_3_0; + extern int g_IsToFDevice; + extern int g_IsCustomWeight; + extern int g_IsHelm_without_car; + + extern float g_min_tof_range; + extern int g_min_tof_range_x; + extern int g_min_tof_range_y; + + extern float g_max_tof_range; + extern int g_max_tof_range_x; + extern int g_max_tof_range_y; + + extern int g_bIsSendTofPCD; + extern int g_bIsWritingPCD; + + extern float g_ground_tof_range; + + extern float g_min_tof_degree; + extern float g_min_tof_height; + extern float g_min_tof_distance; + + extern float g_max_tof_degree; + extern float g_max_tof_height; + extern float g_max_tof_distance; + + extern float g_ground_tof_degree; + extern float g_ground_tof_height; + extern float g_ground_tof_distance; + + extern double g_tof_device_height; + + extern int g_ori_yuv_width; + extern int g_ori_yuv_height; + extern int g_ori_half_yuv_width; + extern int g_ori_half_yuv_height; + + //extern int sockNum[4]; + extern zlog_category_t *zc; + extern double begin_clock; + + extern float confidence_limit; + extern int AI_fps; + +#ifdef REBOOT_BY_CPU_GPU_USAGE + extern int CPU_usage_int; + extern int GPU_usage_int; +#endif + + extern char CPU_usage[256]; + extern char GPU_usage[256]; + extern char Buffer_ver[BUFSIZE]; + //extern bool enable_loop_getalarmmotion; + //extern int times_of_enable_loop_getalarmmotion; + extern int g_write_config_file_dirty_flag; + + extern int g_match_mac; + extern char g_mac_address[256]; + + extern int enable_only_show_metadata1; + extern char websocket_alarm[CONTENT_BUFSIZE]; + + extern int g_i_get_cpu_loading; + + //extern CURLM* g_multi_handle; + extern CURL* g_http_handle; + //extern int g_handle_count; + + extern int g_alter_something; + extern int g_count_alter; + + extern long g_image_HD_pasue_time; + extern int g_video_start_HD; + + extern int g_current_max_num_image_buff; + + extern int g_osdTime_sw; + extern long g_osdSysTimeStamp; + extern int g_osdSysTimeZoneInfo; + + extern int check_if_correct_post; + extern int check_if_run_post; + + extern long g_post_SysTimeStamp; + + int run_http_server(char *option, void* _zc, CNNType cnn_type/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, + char *mac_address, char *ip_address, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType); + + //int caculate_ftp_of_each_sockets(SOCKET sock, int *sock_record_idx); +#ifdef GY_OS_NOVA + size_t SetHttpRequest_sock(QueueInfo *q_info, char* sendBuffer, char* method); +#endif + size_t SetHttpRequest(QueueInfo* q_info, char* sendBuffer, char* method); + size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); + void Create_ptz_socket(); + void SetHttpRequest_ptz(char* cgi_url, char* sOutput_data, char* username, char* password); + //void SetHttpRequest_ptz(); + //size_t SetHttpRequest_ptz(QueueInfo *q_info, char* sendBuffer, char* method); + size_t SetHttpResponse_server(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); + void replace_one_line_in_a_file(char *path, int line, char *newline); +#if 0 + void GetAidaPort(); +#endif + void update_enable_only_show_metadata1(int temp_enable_only_show_metadata1); + size_t get_service_from_ipcam(char * response_from_ipcam); + size_t get_control_io_from_ipcam(char * response_from_ipcam); + void copy_ipcam_smtp_service_to_gynet(); + void copy_control_io_to_gynet(); + void sync_other_camera_lpr_db(); + + void *net_curl_https_post_push_info(void *ptr); + void *net_curl_https_post_push_info_attached_image(void *ptr); + + void net_curl_ftp_post_push_info_attached_image(char* image_buff, int image_buff_size); + void net_curl_ftp_build_folder(); +#ifdef GY_OS_AMBA + size_t SetSNMPRequest(QueueInfo *q_info); +#endif + void *net_curl_https_get_other_lpr_db(void *ptr); + + extern char id[512]; + extern char pass[512]; + + extern char strUnlockingKey[MAX_MSG_LEN]; + extern char strLicenseStatus[MAX_MSG_LEN]; + + extern char g_device_name[512]; + + extern int g_IsPTZDevice; + extern int g_check_if_no_brand; + + extern int g_check_if_OK_getfeatures; + extern int g_check_if_OK_thermal; + + void memset_snapshot_addr(); + + void build_one_smart_event(char * myname, char * myvalue); + void build_one_gpio(char * myname, char * myvalue); + + void* auto_build_smart_events(void * ptr); + void* auto_build_smart_events_di_vi(void * ptr); + void build_one_set_for_quality_basic(char * myname, char * myvalue); +#ifdef GY_OS_AMBA + void build_one_set_for_tof_basic(char * myname, char * myvalue); +#endif + void* auto_set_quality_basic(void * ptr); +#ifdef GY_OS_AMBA + void* auto_set_tof_basic(void * ptr); +#endif + + size_t build_resolution_changed(char * response_from_ipcam); + extern pthread_t resolution_changed_thread; + void* auto_resolution_changed(void * ptr); +#ifdef GY_OS_AMBA + void* check_current_resolution(void * ptr); + void set_run_check_current_resolution(int set_value); + int get_run_check_current_resolution(); +#endif + void write_to_stream_width_and_stream_height(int stream_width, int stream_height); + int get_g_check_if_different_width_or_height(); + + void build_reboot(char * myname, char * myvalue); + void ipcam_getfeatures(); + + void* auto_reboot(void * ptr); + + void build_system(char * myname, char * myvalue); + void* auto_system(void * ptr); + + void sync_image_rotation_thread(); + + int is_connection_authorized(char* recvBuffer, SOCKET *client_socket, int isTcpTunnel); + + void import_lpr_list_file(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen); + void *import_lpr_list_file_thread(void *ptr); +#ifdef GY_OS_AMBA + void *import_face_list_file_thread(void *ptr); +#endif + void get_snap_with_profile_id(int i_profileid, int enable_check_profile_id); +#ifdef GY_OS_NOVA + void *pre_connection_handler(void *socket_temp); +#endif + void *thread_getimage(void *ptr); + void *thread_getimage_hd(void *ptr); + +#ifdef GY_OS_NOVA + void *thread_get_nova_driver(void *ptr); +#endif + char *removeHTTPHeader(char *buffer, int *bodySize); + void getPicture(int socketfd, int bSize, int current_profile_id, int enable_check_profile_id); + int get_g_framesize_width(); + int get_g_framesize_height(); + + void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, char* contentBuffer/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType, int* isGetalarmMotion, int sock_info_idx); + +#ifdef GY_OS_AMBA + int get_g_check_if_change_preset(); + void set_g_check_if_change_preset_to_zero(); + void *import_radarbg_thread(void *ptr); + void import_radarbg(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen); +#endif + void update_system_time(); + + int get_g_control_alarm_gpio(); + void set_g_control_alarm_gpio_to_zero(); + void set_g_control_alarm_gpio_to_one(); +#ifdef GY_OS_NOVA + void start_nova_driver(); + void get_nova_driver(int socketfd); +#endif + +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/nweb_Ming.c b/src/nweb_Ming.c new file mode 100644 index 0000000..44d394c --- /dev/null +++ b/src/nweb_Ming.c @@ -0,0 +1,25843 @@ + + +#pragma comment(lib, "WS2_32.lib") /* program use socket library */ +#pragma warning(disable:4996) +#define _CRT_SECURE_NO_DEPRECATE + +#include "define_inc.h" +#include "url_encode.h" +#ifdef GY_OS_AMBA +#include "ptz.h" +//#include "tof.h" +//#include "radar.h" +//#include "radar_receive.h" // leo 09-28 +#endif +#include "cold_zone.h" +#include <mcheck.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <setjmp.h> +#ifdef GY_OS_AMBA +//#include "radar_parser.h" +#endif + +#ifndef TRY_CATCH +#define TRY_CATCH +#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){ +#define CATCH } else { +#define ETRY } }while(0) +#define THROW longjmp(ex_buf__, 1) +#endif + +#ifdef GY_OS_WIN +#include <direct.h> +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined GY_OS_AMBA || defined GY_OS_NOVA +#include <errno.h> +#include <netdb.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/tcp.h> + +#include <netinet/in.h> +#include <arpa/inet.h> + +#endif + +#include <fcntl.h> /* Added for the nonblocking socket */ +#include <time.h> +#include <pthread.h> + +//#include "image.h" +#include "layer.h" +#include "network.h" +#include "nweb.h" +#include "setting.h" +//#include "utility.h" +#include "cryptionPlus.h" +#include "cJSON.h" +#include "zlog.h" +#include "fflpr_plate_db.h" +#include "cgicmd.h" +#include "test_nnctrl_live.h" +#include "pns.h" +#include "net_curl.h" +#include "strptime_c.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +//#include "curl.h" + +//#include <openssl/ssl.h> +//#include "SSLClient.h" + +#include <curl/curl.h> +#include <curl/easy.h> + +#include "sha1.h" +#include "intLib.h" +#include "websocket.h" + +#include "url_encode.h" + +#ifdef GY_OS_AMBA +#include "pythonR.h" +//#include "jvc_progress.h" +#endif + +#ifdef OPENCV +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/core/types_c.h" +#include "opencv2/core/version.hpp" +#ifndef CV_VERSION_EPOCH +#include "opencv2/videoio/videoio_c.h" +#include "opencv2/imgcodecs/imgcodecs_c.h" +#endif +#endif + +#include "fork_pipe_lib.h" +#include "ivsC.h" + +#ifdef GY_OS_WIN +extern int UpdateTrafficLightZone(int tracking_channel_idx); +#endif + +#ifdef GY_OS_NOVA +extern RecvBbox g_current_bbox_list[MAX_TRACKING_NUM]; +extern int g_count_bbox_list; + +extern RecvBbox temp_current_bbox_list[MAX_TRACKING_NUM]; +extern int temp_count_bbox_list; + +extern int g_check_if_run_parse_json_data_from_bbox_receive; +#endif + +extern int reload_dataset_from_jsonfile(void); //0 fail, 1 success +//extern int default_dataset_for_jsonfile(void); //0 fail, 1 success + +pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; +extern pthread_mutex_t mutex_getalarmmotion; +extern pthread_mutex_t mutex_alm; +extern pthread_mutex_t mutex_curl; +extern pthread_mutex_t mutex_websocket; +extern pthread_mutex_t mutex_enable_lpr_db; +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_enable_face_db; +#endif +extern pthread_mutex_t mutex_username; +extern pthread_mutex_t mutex_config_json; +#if defined GY_OS_AMBA +//extern pthread_mutex_t mutex_jvc_config_json; +#endif +extern pthread_mutex_t mutex_events_json; +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 +extern pthread_mutex_t mutex_tof_json; +#endif +extern pthread_mutex_t mutex_web; +//extern pthread_mutex_t mutex_http_connection_handler; +extern pthread_mutex_t mutex_base64; +//extern pthread_mutex_t mutex_get_canvas; +extern pthread_mutex_t mutex_get_network_input; +extern pthread_mutex_t mutex_buffer; + +extern pthread_mutex_t mutex_set_http_request; +extern pthread_mutex_t mutex_reset_counter; +extern pthread_mutex_t mutex_get_image; +extern pthread_mutex_t mutex_get_image_HD; + +extern pthread_mutex_t mutex_snap_image; +#ifdef GY_OS_NOVA +extern pthread_mutex_t mutex_pre_connection; +#endif +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_remotesnap_image; +#endif +//extern pthread_mutex_t mutex_snap_hd_image; + +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_perspective_transform; +#endif + +#ifdef GY_OS_NOVA +extern pthread_mutex_t mutex_run_parse_json; +#endif + +zlog_category_t *zc=NULL; + +extern int sharkhand_s(int client_socket, char *buffer, int *iIsWebsocket_hybi_00); + +extern int websocket_response(int connfd, char* message); + +extern char* global_message_for_pns_response; + +int g_socket; +// Ken +//extern char *global_message_for_radar_response; +#ifdef GY_OS_AMBA +extern char *g_radar_image_queue; +#endif + +struct timeval currtime_setosd; +long last_ms_setosd = 0; +long current_ms_setosd = 0; + +int CheckIsExistingSpeed = 0; + +int g_dual_sensor = 0; + +int g_camera_white_LED = 0; + +int g_change_getnetwork_buffer_id = 0; + +int g_check_h264_gop = 1; + +#if defined GY_OS_AMBA +int g_isAiRelay = 0; +#endif +struct +{ + char *ext; + char *filetype; +} +extensions[] = +{ +{ "gif", "image/gif" }, +{ "jpg", "image/jpeg" }, +{ "jpeg", "image/jpeg" }, +{ "png", "image/png" }, +{ "ico", "image/ico" }, +{ "zip", "image/zip" }, +{ "gz", "image/gz" }, +{ "tar", "image/tar" }, +{ "htm", "text/html" }, +{ "html", "text/html" }, +{ "css", "text/css" }, +{ "js", "text/javascript" }, +{ "wasm", "application/wasm" }, +{ 0, 0 } +}; + + +//===================== +//sophia add 2020/09/24 +#if defined GY_OS_AMBA || defined GY_OS_NOVA +//SocketInfo_ALM socketRecord_ALM[MAX_CLIENT_SOCKET] = { 0 }; +int bHttpServerMainStart = 0; +int bPreloadHttpServerMainStart = 0; +#endif +//===================== + +CNNType http_cnn_type; +//static network http_nets[MAX_LAYER_NUM]; +//static char **http_names[MAX_LAYER_NUM]; +//static image **http_alphabet; +static float http_thresh; +static float http_hier_thresh; +//static float http_nms[MAX_LAYER_NUM]; +static int http_dont_show; +static int http_ext_output; +static int http_save_labels; +//static char *http_ip_address; +//static char *http_mac_address; +static int http_http_port; +//static int http_layer_count; +static LicenseType http_licenseType; +static AdvanceLicenseType http_advLicenseType; +static AuthFailStatusCode http_afsCode; +static size_t http_featureType; +static size_t http_layerFeatureType[MAX_LAYER_NUM]; +static char *http_strLicenseType; +//static char *http_strLicenseStatus; +//static char *http_strUnlockingKey; + +extern double http_license_fps; +extern int http_sleep_interval; +unsigned int python_check_webstatus = 0; +float confidence_limit; + +extern CPoint trafficLightPoint; +extern int traffic_light_zone_width; +extern int traffic_light_zone_height; +//extern pthread_mutex_t mutex_post_notification; + +char websocket_alarm[CONTENT_BUFSIZE] = { 0 }; + +static float diff; + +int AI_fps = -1; // ܼƩwqAåB]wl +#ifdef GY_OS_NOVA +int AI_fps2 = -1; //nova_driverfps +#endif + +static char g_account_port_protected[512] = { 0 }; + +#ifdef REBOOT_BY_CPU_GPU_USAGE +int CPU_usage_int = -1; +int GPU_usage_int = -1; +#endif + +//bool enable_loop_getalarmmotion = FALSE; //ܼƩwqAåB]wl +//int times_of_enable_loop_getalarmmotion = 1; //enIsisFirstAlarmMotionX +char CPU_usage[256] = { 0 }; +char GPU_usage[256] = { 0 }; +char Buffer_ver[BUFSIZE] = { 0 }; +int g_write_config_file_dirty_flag = 0; + +static char g_record_session_id[MAX_NUMBER_SESSION][MAX_SESSION_ID] = { 0 }; + +#if 0 +static int enable_base64 = 0; +#endif + +int enable_only_show_metadata1 = 1; + +int g_check_if_get_picture_not_OK = 0; + +int g_i_get_cpu_loading = 0; + +//CURL_SEND g_stCURL_send_data = { 0 }; + +static char g_stCURL_send_data_q_name[30] = { 0 }; +static char g_stCURL_send_data_q_plate[60] = { 0 }; + +static char g_stCURL_send_data_curl_url[8192] = { 0 }; +static char g_stCURL_send_data_curl_sendbuf[MAX_IMG_SIZE] = { 0 }; +size_t g_stCURL_send_data_curl_sendbuf_size = 0; +static char g_stCURL_send_data_method[32] = { 0 }; +static char g_stCURL_send_data_protocol[32] = { 0 }; +static char g_stCURL_send_data_username[64] = { 0 }; +static char g_stCURL_send_data_password[64] = { 0 }; +static char g_stCURL_send_data_port[10] = { 0 }; //strtol(q_info->host_port, NULL, 10) +static char g_stCURL_send_data_timeout[10] = { 0 }; +static char g_stCURL_send_data_customized_header[8192] = { 0 }; +static int g_stCURL_image_buff_size=0; +static char g_stCURL_image_buff[MAX_IMG_SIZE] = {0}; +static int g_stCURL_check_127 = 0; +static int g_stCURL_enable_attached_image = 0; +static int g_stCURL_enable_filename_fixed = 0; +static char g_stCURL_send_jpeg_file_name[60] = { 0 }; +static char g_response_net_curl[MAX_IMG_SIZE] = { 0 }; +static int g_response_post_OK = 0; + +#ifdef GY_OS_AMBA +static char g_response_snmp[8192] = { 0 }; + +static char g_stCURL_lpr_db_url[8192] = { 0 }; +static char g_stCURL_lpr_db_username[64] = { 0 }; +static char g_stCURL_lpr_db_password[64] = { 0 }; +static char g_stCURL_lpr_db_port[10] = { 0 }; +static char g_response_lpr_db[8192] = { 0 }; +#endif + +static char g_headerBuffer[BUFSIZE_V2] = { 0 }; +static char g_multiPartBoundary[MAX_MSG_LEN] = { 0 }; +static int g_bIsMultipart = 0; +static char g_contentBuffer[CONTENT_BUFSIZE] = { 0 }; +static long g_nTotalContentLen = 0; +static int g_count_lpr_insert_times = -1; //-1NSbΰF 0N}l >0NimportӼ + +//static char g_image_buff[MAX_IMG_SIZE]; +//size_t g_image_buff_size; + +int switch_g_image_buff_ori = 0; +int g_current_max_num_image_buff = 5; +char g_image_buff_ori[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE] = { 0 }; +int g_image_buff_size_ori[MAX_NUM_IMAGE_BUFF] = { 0 }; +char g_image_state_response_ori[256] = { 0 }; + +long g_post_SysTimeStamp_ori[MAX_NUM_IMAGE_BUFF] = { 0 }; + +int g_video_start_HD = 1; +#if defined GY_OS_AMBA +char g_image_buff_HD[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE_HD] = { 0 }; +int g_image_buff_size_HD[MAX_NUM_IMAGE_BUFF] = { 0 }; +char g_image_buff_HD_pause[MAX_IMG_SIZE_HD] = { 0 }; +#endif +int g_image_buff_size_HD_pause = 0; +long g_image_HD_pasue_time = 0; + +int g_framesize_width = 0; +int g_framesize_height = 0; + +int g_framesize_width_HD = 0; +int g_framesize_height_HD = 0; + +#ifdef GY_OS_AMBA +//face +char g_image_buff[MAX_IMG_SIZE_HD] = { 0 }; +char g_decrypt_buff[MAX_IMG_SIZE_HD] = { 0 }; +//face end +#endif + +#ifdef GY_OS_AMBA +int g_check_if_change_preset = 0; +#endif +static int g_check_if_snap_running = 0; +char g_snap_snapshot_addr[MAX_IMG_SIZE] = { 0 }; +#ifdef GY_OS_AMBA +//static int g_check_if_remotesnap_running = 0; +//char g_remotesnap_snapshot_addr[MAX_IMG_SIZE] = {0}; +#endif +size_t g_snap_snapshot_size = 0; +#ifdef GY_OS_AMBA +size_t g_remotesnap_snapshot_size = 0; +#endif +static int start_to_import_file = 0; +#ifdef GY_OS_AMBA +float g_min_tof_range = 0.0; +int g_min_tof_range_x = 0; +int g_min_tof_range_y = 0; + +float g_max_tof_range = 0.0; +int g_max_tof_range_x = 0; +int g_max_tof_range_y = 0; + +float g_min_tof_degree = 0.0; +float g_min_tof_height = 0.0; +float g_min_tof_distance = 0.0; + +float g_max_tof_degree = 0.0; +float g_max_tof_height = 0.0; +float g_max_tof_distance = 0.0; + +float g_ground_tof_range = 0.0; +float g_ground_tof_degree = 0.0; +float g_ground_tof_height = 0.0; +float g_ground_tof_distance = 0.0; + +double g_tof_device_height = 0.0; + +int g_bIsSendTofPCD = 1; +int g_bIsWritingPCD = 0; + +#endif + +int g_control_alarm_gpio = 0; + +int g_is_check_credential = 0; + +char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; +unsigned int g_uiWebPythonCurrentBufferIndex = 0; +unsigned int g_uiWebPythonLastBufferIndex = 0; +unsigned int g_cWebPythonBufferSignal = 0; +unsigned int g_cWebPythonDeleteStatus = 0; +unsigned int g_cWebPythonStatus = 0; +char g_cWebPythonName[50]; +struct MemoryStruct +{ + char memory[MEMORY_SIZE];//256KB + size_t size; +}; + +int get_g_control_alarm_gpio() { + return g_control_alarm_gpio; +} + +void set_g_control_alarm_gpio_to_zero() { + g_control_alarm_gpio = 0; +} + +void set_g_control_alarm_gpio_to_one() { + g_control_alarm_gpio = 1; +} + +void memset_snapshot_addr() { + for (int i = 0; i < MAX_SNAP_HD_LIST; i++) { + memset(snapHDList[i].snapshot_addr, 0x00, MAX_IMG_SIZE); + } +} + +static size_t WriteResponseString(void* contents, size_t size, size_t nmemb, void* user_ptr) +{ + size_t realsize = size * nmemb; + struct MemoryStruct* mem = (struct MemoryStruct*)user_ptr; + + /* + char* ptr = realloc(mem->memory, mem->size + realsize + 1); + if (!ptr) { + // out of memory! + printf("\nnot enough memory (realloc returned NULL)\n"); + return 0; + }*/ + + if (mem->size + realsize + 1 >= MEMORY_SIZE)//25KB + { + printf("\nover MEMORY_SIZE KB memory (returned NULL)\n"); + return 0; + } + + //mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} + +#define SOCKET_SEND_ERROR_COUNT 10 +#if 0 +void syslog(int type, char *s1, char *s2, int num) +{ + FILE *fp; + static char log_buf[LOG_BUFSIZE]; + + switch (type) + { + case NW_ERROR: + sprintf(log_buf, "ERROR: %s:%s Errno = %d", s1, s2, errno); + break; + + case NW_SORRY: + sprintf(log_buf, + "<HTML><BODY><H2>nweb Web Server: %s %s</H2></BODY></HTML>\r\n", + s1, s2); + send(num, log_buf, strlen(log_buf), 0); + sprintf(log_buf, "SORRY: %s:%s", s1, s2); + break; + + case NW_LOG: + sprintf(log_buf, " INFO: %s:%s:%d", s1, s2, num); + break; + } + + /* write event data to the log file 'nweb.syslog' */ + if ((fp = fopen("nweb.syslog", "a")) != NULL) + { + strncat(log_buf, "\n", LOG_BUFSIZE); + fprintf(fp, log_buf); + fclose(fp); + } +#ifdef GY_OS_WIN + if (type == NW_ERROR || type == NW_SORRY) + { + WSACleanup(); + exit(1); + } +#endif +} +#endif + +char* FindHttpContentStart(char* buffer) +{ + for (int i = 0; i < BUFSIZE_V2; i++) + { + //char* b = buffer + i; + + if (memcmp(buffer + i, "\r\n\r\n", strlen("\r\n\r\n")) == 0) + { + return buffer + i + strlen("\r\n\r\n"); + break; + } + } + return NULL; +} + +void DumpCharacters(char* str, int length) +{ + for (int i = 0; i < length; i++) + printf("%c", *(str + i)); + printf("\n"); +} + +char *removeHTTPHeader(char *buffer, int *bodySize) { + char *t = strstr(buffer, "\r\n\r\n"); + t = t + 4; + + for (char* it = buffer; it != t; ++it) { + ++(*bodySize); + } + + return t; +} + +void getPicture(int socketfd, int bSize,int current_profile_id,int enable_check_profile_id) { + //printf("\n----------getPicture: 1\n"); + //printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); + + char buffer_image[MAX_IMG_SIZE_HD] = { 0 }; + char buffer[MAX_IMG_SIZE_HD] = { 0 }; + size_t bReceived; + + //bReceived = recv(socketfd, buffer, bSize, 0); + + int try_gethead = 0; + while (bHttpServerMainStart) { + bReceived = recv(socketfd, buffer, bSize, 0); + + if (strlen(buffer) == 0) { + g_check_if_get_picture_not_OK = 1; + } + else { + g_check_if_get_picture_not_OK = 0; + } + + if (strstr(buffer, "HTTP") != NULL) + break; + + if (try_gethead >= 10) + break; + + printf("\n-----------get Picture try to receive buffer head:%s\n", buffer); + memset(buffer, 0, bSize); + + try_gethead++; + + usSleep(1); + if (g_check_if_get_picture_not_OK == 1) { + usSleep(1000000); + } + } + if (g_check_if_get_picture_not_OK == 1) { + usSleep(1000000); + } + + int bodySize = 0; + int content_length_image = 0; + + + //char *t = removeHTTPHeader(buffer, &bodySize); + //bodySize = 0; +#if 0 + bodySize = bReceived - bodySize; + if (bodySize >= 1 && bodySize <= bSize) { + memcpy(buffer_image, t, bodySize); + } + printf("\n--------------getPicture---5-------bodySize:%d\n", bodySize); + printf("\n--------------buffer:%s\n", buffer); +#endif + + int framesize_width = 0; + int framesize_height = 0; + + if (strstr(buffer, "framesize=") != NULL) { + char *ptr_1 = strstr(buffer, "framesize=")+10; + char *ptr_2 = strstr(ptr_1,"&"); + if (ptr_2 != NULL) { + int ptr_length = ptr_2 - ptr_1; + char buff_temp[15] = { 0 }; + memcpy(buff_temp,ptr_1, ptr_length); + //printf("\n-----------------buff_temp:%s\n", buff_temp); + + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(buff_temp, outArray, "x"); + //printf("\n------UU:19\n"); + + framesize_width = atoi(outArray[0]); + framesize_height = atoi(outArray[1]); + //printf("\n----------buff_temp:%s\n", buff_temp); + //printf("\n----------outArray[0]:%s\n", outArray[0]); + //printf("\n----------outArray[1]:%s\n", outArray[1]); + //printf("\n------------g_framesize_width:%d,g_framesize_height:%d\n", g_framesize_width, g_framesize_height); + } + } + + if (enable_check_profile_id == 1) { + g_framesize_width = framesize_width; + g_framesize_height = framesize_height; + } + else { + g_framesize_width_HD = framesize_width; + g_framesize_height_HD = framesize_height; + } + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + //printf("\n----------getPicture: 2: %s\n", buffer); + if (strstr(buffer, "HTTP/1.1 200") != NULL && strstr(buffer, "encode=jpeg") != NULL && + framesize_width >= 1 && framesize_width <= 1280 && + framesize_height >= 1 && framesize_height <= 960) + { + + //bodySize = 0; + //if (content_length_image >= 1) + { + memset(buffer, 0, bSize); + bodySize = 0; + content_length_image = 0; + //printf("\n----------getPicture: 3\n"); + + while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, bSize, 0)) > 0) { + + //printf("\n----------get Picture start\n"); + + //if (switch_g_image_buff_ori == 1) + { + //if (enable_check_profile_id == 0) + { + //printf("\n-------------------------buffer:%s\n", buffer); + //printf("\n-------------------------bReceived:%d\n", bReceived); + } + + if (bReceived >= 3) { + if (strncmp(buffer, "--myboundary", 12) == 0) { + char *ptr_1 = strstr(buffer, "Content-Length: "); + char *ptr_buffer = strstr(buffer, "--myboundary"); + if (ptr_1) { + char *ptr_2 = strstr(ptr_1, "\r\n"); + if (ptr_2) { + int strlen_ptr = ptr_2 - ptr_1 - 16; + char boundary[256] = { 0 }; + if (strlen_ptr >= 1) { + strncpy(boundary, ptr_1 + 16, strlen_ptr); + //printf("\n-----------boundary:%s\n", boundary); + content_length_image = atoi(boundary); + //printf("\n-------------content_length_image:%d\n", content_length_image); + + ptr_2 = ptr_2 + 4; + + int head_length = ptr_2 - ptr_buffer; + + memset(buffer_image, 0x00, MAX_IMG_SIZE_HD); + if (head_length >= 1 && content_length_image >= 1) { + if (bReceived == head_length + content_length_image + 2) { + memcpy(buffer_image, ptr_2, content_length_image); + bodySize = content_length_image; + content_length_image = 0; + } + else if (bReceived == head_length + content_length_image) { + memcpy(buffer_image, ptr_2, content_length_image); + bodySize = content_length_image; + content_length_image = 0; + } + else if (bReceived > head_length) { + memcpy(buffer_image, ptr_2, bReceived - head_length); + bodySize = bReceived - head_length; + content_length_image -= bodySize; + } + + //if (enable_check_profile_id == 0) + { + //printf("\n-getPicture---TTT#2-bReceived:%d\n", bReceived); + //printf("\n-------------------buffer_image#2:%s\n", buffer_image); + + //printf("\n-----------content_length_image #2:%d\n", content_length_image); + //printf("\n-----------bodySize #2:%d\n", bodySize); + } + } + } + } + } + } + else { + if (content_length_image >= 1) { + if (bReceived == content_length_image + 2) { + memcpy(buffer_image + bodySize, buffer, content_length_image); + bodySize += content_length_image; + content_length_image = 0; + } + else if (bReceived == content_length_image) { + memcpy(buffer_image + bodySize, buffer, content_length_image); + bodySize += content_length_image; + content_length_image = 0; + } + else if (bReceived < content_length_image) { + memcpy(buffer_image + bodySize, buffer, bReceived); + bodySize += bReceived; + content_length_image -= bReceived; + } + + //if (enable_check_profile_id == 0) + { + //printf("\n--------------getPicture---TTT------bReceived:%d\n", bReceived); + //printf("\n-------------------buffer_image#1:%s\n", buffer_image); + + //printf("\n-----------content_length_image #1:%d\n", content_length_image); + //printf("\n-----------bodySize #1:%d\n", bodySize); + } + } + } + } + + if (content_length_image <= 0) { + if (bodySize >= 1) { + + //printf("\n--------bodySize:%d\n", bodySize); + + if (enable_check_profile_id == 1) { + pthread_mutex_lock(&mutex_get_image); + g_post_SysTimeStamp_ori[0] = g_osdSysTimeStamp; + for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { + if (g_image_buff_size_ori[i - 1]) { + memcpy(g_image_buff_ori[i], g_image_buff_ori[i - 1], g_image_buff_size_ori[i - 1]); + g_image_buff_size_ori[i] = g_image_buff_size_ori[i - 1]; + g_post_SysTimeStamp_ori[i] = g_post_SysTimeStamp_ori[i - 1]; + } + } + memcpy(g_image_buff_ori[0], buffer_image, bodySize); + g_image_buff_size_ori[0] = bodySize; + pthread_mutex_unlock(&mutex_get_image); + +#if defined GY_OS_AMBA + if (atoi(SystemSetting.getimage_encoder_id_HD) == atoi(SystemSetting.getimage_encoder_id)) { + pthread_mutex_lock(&mutex_get_image_HD); + for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { + if (g_image_buff_size_HD[i - 1]) { + memcpy(g_image_buff_HD[i], g_image_buff_HD[i - 1], g_image_buff_size_HD[i - 1]); + g_image_buff_size_HD[i] = g_image_buff_size_HD[i - 1]; + } + } + memcpy(g_image_buff_HD[0], buffer_image, bodySize); + g_image_buff_size_HD[0] = bodySize; + pthread_mutex_unlock(&mutex_get_image_HD); + } +#endif + } + else { +#if defined GY_OS_AMBA + pthread_mutex_lock(&mutex_get_image_HD); + for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { + if (g_image_buff_size_HD[i - 1]) { + memcpy(g_image_buff_HD[i], g_image_buff_HD[i - 1], g_image_buff_size_HD[i - 1]); + g_image_buff_size_HD[i] = g_image_buff_size_HD[i - 1]; + } + } + memcpy(g_image_buff_HD[0], buffer_image, bodySize); + g_image_buff_size_HD[0] = bodySize; + pthread_mutex_unlock(&mutex_get_image_HD); +#endif + } + + if(enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "OK"); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----image fps:%lf\n",1000.0/dw_FPS_time_delta); + //last_ms = now_ms; + } + else if (bodySize == 0) { + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Encoder: The resolution is not supported."); + } + bodySize = 0; + content_length_image = 0; + memset(buffer_image, 0x00, MAX_IMG_SIZE_HD); + //break; + } + + } + + //printf("\n----------get Picture end\n"); + //printf("\n-----strlen:%d\n",strlen(buffer)); + memset(buffer, 0, bSize); + //usSleep(65000); + usSleep(10000); + + if (enable_check_profile_id == 1) + { + if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id) - 1)) + break; + } +#if defined GY_OS_AMBA + else { + if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id_HD) - 1)) + break; + } +#endif + } + } + } + else { + //printf("\n----------getPicture: 4: %s\n", buffer); + + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori,"Encoder: The profile name is not jpeg."); + } + + //printf("\n------------bodySize:%d\n", bodySize); + //printf("\n----------getPicture: 5\n"); +} +#ifdef GY_OS_NOVA +void get_nova_driver(int socketfd) { + //printf("\n----------getPicture: 1\n"); + //printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); + + char buffer[65535] = { 0 }; + size_t bReceived; + + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, 65535, 0)) > 0) { + + //printf("\n----------get Picture start\n"); + + //printf("\n---------buffer:%s\n", buffer); + //printf("\n-------strlen:%d\n", strlen(buffer)); + if (strstr(buffer, "GET /send_nova_driver") != NULL) { + + //printf("\nKKKKKKKKKKK:g_check_if_run_parse_json_data_from_bbox_receive:%d,g_count_bbox_list:%d\n", g_check_if_run_parse_json_data_from_bbox_receive, g_count_bbox_list); + if (g_check_if_run_parse_json_data_from_bbox_receive == 0 && g_count_bbox_list == 0) { + //printf("\n-------kkkkkkkkkkkk: 1\n"); + + + + char * start_mydata = strstr(buffer, "{\"AiEngine\""); + if (start_mydata != NULL) { + //printf("\n-------kkkkkkkkkkkk: 2\n"); + char * end_mydata = strstr(start_mydata, "-----end_nova_driver"); + if (end_mydata != NULL) { + //printf("\n-------kkkkkkkkkkkk: 3\n"); + int recv_len = end_mydata - start_mydata; + if (recv_len >= 1) { + //printf("\n-------kkkkkkkkkkkk: 4\n"); + char mydata[BUFSIZE * 59] = { 0 }; + memcpy(mydata, start_mydata, recv_len); + //printf("\n---------mydata:%s\n", mydata); + + cJSON *root/*, *res_height, *res_width*/, *cJSON_AI_fps2, *detect_count, *AiEngine, *detect; + cJSON *id, *confidence, *class_id, *x, *y, *w, *h, *object_score, *class_score; + cJSON *parent_idx_temp, *obj_type_temp, *featuretype_temp, *enginetype_temp, *featuretype2_temp, *enginetype2_temp, *name_temp/*, *plate_temp*/; + cJSON *id_img, *size_base64_img, *cjson_crop_w, *cjson_crop_h; + + root = cJSON_Parse(mydata); + + if (root) { + //res_height = cJSON_GetObjectItem(root, "res_height"); + //res_width = cJSON_GetObjectItem(root, "res_width"); + detect_count = cJSON_GetObjectItem(root, "Count"); + AiEngine = cJSON_GetObjectItem(root, "AiEngine"); + cJSON_AI_fps2 = cJSON_GetObjectItem(root, "AI_fps"); + + if (cJSON_AI_fps2) { + AI_fps2 = cJSON_AI_fps2->valueint; + } + + /* + if (res_height) { + g_res_height = res_height->valueint; + } + else { + g_res_height = NET_SIZE_H; + } + + if (res_width) { + g_res_width = res_width->valueint; + } + else { + g_res_width = NET_SIZE_W; + }*/ + + if (detect_count) { + if (detect_count->valueint <= MAX_TRACKING_NUM) { + temp_count_bbox_list = detect_count->valueint; + } + else { + temp_count_bbox_list = MAX_TRACKING_NUM; + } + + //printf("\n---------------temp_count_bbox_list:%d\n", temp_count_bbox_list); + } + else { + temp_count_bbox_list = 0; + } + + if (temp_count_bbox_list >= 1) + { + int i = 0; + cJSON_ArrayForEach(detect, AiEngine) + { + id = cJSON_GetObjectItem(detect, "id"); + confidence = cJSON_GetObjectItem(detect, "confidence"); + object_score = cJSON_GetObjectItem(detect, "object_score"); + class_score = cJSON_GetObjectItem(detect, "class_score"); + class_id = cJSON_GetObjectItem(detect, "class_id"); + x = cJSON_GetObjectItem(detect, "x"); + y = cJSON_GetObjectItem(detect, "y"); + w = cJSON_GetObjectItem(detect, "w"); + h = cJSON_GetObjectItem(detect, "h"); + + parent_idx_temp = cJSON_GetObjectItem(detect, "parent_idx"); + obj_type_temp = cJSON_GetObjectItem(detect, "obj_type"); + featuretype_temp = cJSON_GetObjectItem(detect, "featuretype"); + enginetype_temp = cJSON_GetObjectItem(detect, "enginetype"); + featuretype2_temp = cJSON_GetObjectItem(detect, "featuretype2"); + enginetype2_temp = cJSON_GetObjectItem(detect, "enginetype2"); + + name_temp = cJSON_GetObjectItem(detect, "name"); + //plate_temp = cJSON_GetObjectItem(detect, "plate"); + + + + size_base64_img = cJSON_GetObjectItem(detect, "cropped_size"); + id_img = cJSON_GetObjectItem(detect, "id_img"); + cjson_crop_w = cJSON_GetObjectItem(detect, "crop_w"); + cjson_crop_h = cJSON_GetObjectItem(detect, "crop_h"); + + if (id && confidence && class_id && x && y && w && h && object_score && class_score + && parent_idx_temp && obj_type_temp && featuretype_temp && enginetype_temp && featuretype2_temp && enginetype2_temp && name_temp //&& plate_temp + /*&& base64_img && size_base64_img && cjson_crop_w && cjson_crop_h*/) { + + temp_current_bbox_list[i].id = id->valueint; + temp_current_bbox_list[i].confidence = (float)confidence->valueint; + temp_current_bbox_list[i].class_id = class_id->valueint; + temp_current_bbox_list[i].x = (float)x->valueint; + temp_current_bbox_list[i].y = (float)y->valueint; + temp_current_bbox_list[i].w = (float)w->valueint; + temp_current_bbox_list[i].h = (float)h->valueint; + + temp_current_bbox_list[i].object_score = (float)object_score->valueint; + temp_current_bbox_list[i].class_score = (float)class_score->valueint; + + temp_current_bbox_list[i].parent_idx = (int)parent_idx_temp->valueint; + temp_current_bbox_list[i].obj_type = (int)obj_type_temp->valueint; + temp_current_bbox_list[i].featureType = (size_t)featuretype_temp->valueint; + temp_current_bbox_list[i].engine_type = (unsigned int)enginetype_temp->valueint; + temp_current_bbox_list[i].featureType2 = (size_t)featuretype2_temp->valueint; + temp_current_bbox_list[i].engine_type2 = (unsigned int)enginetype2_temp->valueint; + + strcpy(temp_current_bbox_list[i].name, name_temp->valuestring); + /*if (plate_temp) { + strcpy(temp_current_bbox_list[i].plate, plate_temp->valuestring); + } + else { + strcpy(temp_current_bbox_list[i].plate, ""); + }*/ + + if (size_base64_img && size_base64_img->valueint >= 1 && id_img && id_img->valueint >= 0) { + //temp_current_bbox_list[i].size_base64_cropped_img = size_base64_img->valueint; + if (cjson_crop_w) { + temp_current_bbox_list[i].crop_w = cjson_crop_w->valueint; + } + else { + temp_current_bbox_list[i].crop_w = 0; + } + + if (cjson_crop_h) { + temp_current_bbox_list[i].crop_h = cjson_crop_h->valueint; + } + else { + temp_current_bbox_list[i].crop_h = 0; + } + + //memcpy(temp_current_bbox_list[i].base64_cropped_img, base64_img->valuestring, temp_current_bbox_list[i].size_base64_cropped_img); + + if (temp_current_bbox_list[i].crop_h >= 1 && temp_current_bbox_list[i].crop_w >= 1) { + g_size_base64_cropped_img[id_img->valueint] = size_base64_img->valueint; + //memcpy(g_base64_cropped_img[g_index_base64_cropped_img], base64_img->valuestring, g_size_base64_cropped_img[g_index_base64_cropped_img]); + temp_current_bbox_list[i].image_id = id_img->valueint; + //g_index_base64_cropped_img++; + //if (g_index_base64_cropped_img >= MAX_IMAGE_YUV) { + //g_index_base64_cropped_img = 0; + //} + } + else { + temp_current_bbox_list[i].image_id = -1; + } + } + else { + //temp_current_bbox_list[i].size_base64_cropped_img = 0; + temp_current_bbox_list[i].crop_w = 0; + temp_current_bbox_list[i].crop_h = 0; + temp_current_bbox_list[i].image_id = -1; + //strcpy(temp_current_bbox_list[i].base64_cropped_img, ""); + } + + i++; + } + + /* + printf("\n----[gynet][bbox receive]After parsing received TCP json data--id:%d,confidence:%f,class_id:%d,x:%f,y:%f,w:%f,h:%f\n", + temp_current_bbox_list[i].id, + temp_current_bbox_list[i].confidence, + temp_current_bbox_list[i].class_id, + temp_current_bbox_list[i].x, + temp_current_bbox_list[i].y, + temp_current_bbox_list[i].w, + temp_current_bbox_list[i].h);*/ + + if (i >= temp_count_bbox_list) + break; + } + temp_count_bbox_list = i; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + //printf("\n-------kkkkkkkkkkkk: 5\n"); + //if (check_if_finish_thread_bbox_list == 1) + { + pthread_mutex_lock(&mutex_run_parse_json); + + if (temp_count_bbox_list >= 1) { + //printf("\nGGGGGGGGGGG:%d\n", temp_count_bbox_list); + for (int i = 0; i < temp_count_bbox_list; i++) { + g_current_bbox_list[i].id = temp_current_bbox_list[i].id; + g_current_bbox_list[i].confidence = temp_current_bbox_list[i].confidence; + g_current_bbox_list[i].class_id = temp_current_bbox_list[i].class_id; + g_current_bbox_list[i].x = temp_current_bbox_list[i].x; + g_current_bbox_list[i].y = temp_current_bbox_list[i].y; + g_current_bbox_list[i].w = temp_current_bbox_list[i].w; + g_current_bbox_list[i].h = temp_current_bbox_list[i].h; + + g_current_bbox_list[i].object_score = temp_current_bbox_list[i].object_score; + g_current_bbox_list[i].class_score = temp_current_bbox_list[i].class_score; + + g_current_bbox_list[i].parent_idx = temp_current_bbox_list[i].parent_idx; + g_current_bbox_list[i].obj_type = temp_current_bbox_list[i].obj_type; + g_current_bbox_list[i].featureType = temp_current_bbox_list[i].featureType; + g_current_bbox_list[i].engine_type = temp_current_bbox_list[i].engine_type; + g_current_bbox_list[i].featureType2 = temp_current_bbox_list[i].featureType2; + g_current_bbox_list[i].engine_type2 = temp_current_bbox_list[i].engine_type2; + + strcpy(g_current_bbox_list[i].name, temp_current_bbox_list[i].name); + //strcpy(g_current_bbox_list[i].plate, temp_current_bbox_list[i].plate); + + if (temp_current_bbox_list[i].image_id >= 0) { + //g_current_bbox_list[i].size_base64_cropped_img = temp_current_bbox_list[i].size_base64_cropped_img; + g_current_bbox_list[i].crop_w = temp_current_bbox_list[i].crop_w; + g_current_bbox_list[i].crop_h = temp_current_bbox_list[i].crop_h; + g_current_bbox_list[i].image_id = temp_current_bbox_list[i].image_id; + //memcpy(g_current_bbox_list[i].base64_cropped_img, temp_current_bbox_list[i].base64_cropped_img, g_current_bbox_list[i].size_base64_cropped_img); + } + else { + //g_current_bbox_list[i].size_base64_cropped_img = 0; + g_current_bbox_list[i].crop_w = 0; + g_current_bbox_list[i].crop_h = 0; + g_current_bbox_list[i].image_id = -1; + //strcpy(g_current_bbox_list[i].base64_cropped_img, ""); + } + + } + g_count_bbox_list = temp_count_bbox_list; + } + else { + g_count_bbox_list = 0; + } + pthread_mutex_unlock(&mutex_run_parse_json); + + //check_if_finish_thread_bbox_list = 0; + } + } + + g_check_if_run_parse_json_data_from_bbox_receive = 1; + } + } + } + //g_check_if_run_parse_json_data_from_bbox_receive = 0; + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get nova driver ms:%lf\n", dw_FPS_time_delta); + //last_ms = now_ms; + } + } + + //printf("\n----------get Picture end\n"); + + memset(buffer, 0x00, 65535); + usSleep(70000); + } +} +#endif + +int get_g_framesize_width() { + return g_framesize_width; +} + +int get_g_framesize_height() { + return g_framesize_height; +} +#ifdef GY_OS_NOVA +void start_nova_driver() { + int nova_driver_port = 4343; + + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = AF_INET; + + //localhost test + info.sin_addr.s_addr = INADDR_ANY; + info.sin_port = htons(nova_driver_port); + //socketإ TCP_PORT_IMAGE + int sockfd = 0; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + struct timeval timeout; + timeout.tv_sec = 10; + timeout.tv_usec = 0; + + setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + int tcpnodelay = 1; + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + + int reuse = 1; + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + //printf("\n------------get snap with profile id:5\n"); + if (sockfd >= 0) { + + int err = connect(sockfd, (struct sockaddr *)&info, sizeof(info)); + if (err == -1) { + //printf("Connection error #2"); + } + else { + char msg[2560] = { 0 }; + + sprintf(msg, "GET /start_nova_driver HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %d\r\nConnection: close\r\n", nova_driver_port); + + err = send(sockfd, msg, strlen(msg), 0); + if (err == -1) { + printf("\nerror sending #2\n"); + + //exit(EXIT_FAILURE); + } + else { + get_nova_driver(sockfd); + } + } + + close(sockfd); + sockfd = -1; + } + else { + printf("\nCould not create socket!\n"); + } + +} +#endif +void get_snap_with_profile_id(int i_profileid,int enable_check_profile_id) { + if (g_check_h264_gop == 0) { + //printf("\n------------get snap with profile id:1\n"); + + //int snapshot_size = 0; + + int status; + struct addrinfo host_info; + struct addrinfo *host_info_list = NULL; + + memset(&host_info, 0, sizeof(host_info)); + + host_info.ai_family = AF_INET;//AF_UNSPEC + host_info.ai_socktype = SOCK_STREAM; + host_info.ai_protocol = 0; + + status = getaddrinfo("127.0.0.1", accountData[0].account_port, &host_info, &host_info_list); + if (status != 0) { + printf("\ngetaddrinfo error: %d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: getaddrinfo error"); + } + else + { + //printf("\n------------get snap with profile id:2\n"); + int socketfd = -1;; + //socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); + struct timeval timeout; + timeout.tv_sec = 3;//3 + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + + /* + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = PF_INET; + + //localhost test + info.sin_addr.s_addr = inet_addr("127.0.0.1"); + info.sin_port = htons(accountData[0].account_port); + //socketإ TCP_PORT_IMAGE + socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ + + int err = -1; + +#if 1 + struct addrinfo *rp; + for (rp = host_info_list; rp != NULL; rp = rp->ai_next) { + + socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (socketfd == -1) { + printf("\nsocket error:%d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: socket error"); + } + else { + //printf("\n-------open getimage connected (%d)\n", socketfd); + + setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) { + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = socketfd; + + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 3; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + + socketRecords[i].used = 1; + //printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); + break; + } + else { + if (i == MAX_CLIENT_SOCKET - 1) { + closesocket(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + //printf("\n------------get snap with profile id:3\n"); + } + } + } + + if (socketfd != -1) { + break; + } + } + else { + closesocket(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + //printf("\n------------get snap with profile id:4\n"); + } + } + } +#endif + //printf("\n------------get snap with profile id:5\n"); + if (socketfd >= 0) { + char Authorization[2560] = { 0 }; + if (strlen(accountData[0].account_username) > 0) + { + //strcat(sendBuffer, "Authorization: Basic "); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + strcpy(Authorization, buf_account); + strcat(Authorization, ":"); + + if (strlen(accountData[0].account_password) > 0) { + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + strcat(Authorization, buf_account2); + } + } + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + if (strlen(Authorization) >= 1) + { + + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + } + + + char msg[2560] = { 0 }; + + sprintf(msg, "GET /getimage?profileid=%d HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", i_profileid, accountData[0].account_port); + + strcat(msg, "Authorization: Basic "); + strcat(msg, httpAuth); + strcat(msg, "\r\n"); + strcat(msg, "\r\n"); + + //printf("\n-----------msg:%s\n", msg); + //printf("\n------------get snap with profile id:6\n"); + err = send(socketfd, msg, strlen(msg), 0); + if (err == -1) { + printf("\nerror sending:%d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: error sending"); + + //exit(EXIT_FAILURE); + } + else { + getPicture(socketfd, MAX_IMG_SIZE, i_profileid, enable_check_profile_id); + } + //printf("\n------------get snap with profile id:7\n"); + closesocket(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) + { + //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + socketRecords[i].used = 0; + break; + } + } + + socketfd = -1; + //printf("\n------------get snap with profile id:8\n"); + } + else { + printf("\nCould not create socket!:%d\n", enable_check_profile_id); + if (enable_check_profile_id == 1) + strcpy(g_image_state_response_ori, "Network problem: Could not create socket!"); + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed #1\n"); + } + pthread_join(thread_id_getipcamsettings, NULL); + } + } + //printf("\n------------get snap with profile id:9\n"); + if (host_info_list != NULL) { + freeaddrinfo(host_info_list); + host_info_list = NULL; + } + //printf("\n------------get snap with profile id:10\n"); + } +} + +void *net_curl_https_post_push_info_attached_image(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("curl_attached"); + pthread_mutex_lock(&mutex_curl); + + char sUrl[8192] = { 0 }; + strcpy(sUrl, g_stCURL_send_data_curl_url); + char sData[MAX_IMG_SIZE] = { 0 }; + //size_t sData_size = g_stCURL_send_data_curl_sendbuf_size; + memcpy(sData, g_stCURL_send_data_curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); + char method[32] = { 0 }; + strcpy(method, g_stCURL_send_data_method); + char sProtocol[32] = { 0 }; + strcpy(sProtocol, g_stCURL_send_data_protocol); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, g_stCURL_send_data_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, g_stCURL_send_data_password); + int iPort = atoi(g_stCURL_send_data_port); + char sCustomizedHeader[8192] = { 0 }; + strcpy(sCustomizedHeader, g_stCURL_send_data_customized_header); + int itimeout = atoi(g_stCURL_send_data_timeout); + + char s_q_name[30] = { 0 }; + strcpy(s_q_name, g_stCURL_send_data_q_name); + char s_q_plate[60] = { 0 }; + strcpy(s_q_plate, g_stCURL_send_data_q_plate); + + size_t snapshot_size = 0; + CURLcode ret; + curl_mime *mime1; + curl_mimepart *part1; + struct curl_slist *slist1; + char g_snapshot_addr_to_net_curl[MAX_IMG_SIZE] = { 0 }; + + if (g_stCURL_image_buff_size >= 1) { + memcpy(g_snapshot_addr_to_net_curl,g_stCURL_image_buff, g_stCURL_image_buff_size); + snapshot_size = (size_t)g_stCURL_image_buff_size; + } + else { +#ifdef GY_OS_AMBA + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(g_snapshot_addr_to_net_curl); + pthread_mutex_unlock(&mutex_get_network_input); +#endif + } + + //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); + + //snapshot_size = get_snap_with_profile_id(g_snapshot_addr_to_net_curl, 1); + + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 0); + //snapshot_size = (size_t)get_ori_c_image(g_snapshot_addr_to_net_curl); + + if (g_http_handle != NULL && (int)snapshot_size >= 1) { + mime1 = NULL; + slist1 = NULL; + +#if 1 + slist1 = curl_slist_append(slist1, "charset: utf-8"); + slist1 = curl_slist_append(slist1, "Expect:"); + if (strcmp(method, "POST") == 0) + { + if ((int)strlen(sCustomizedHeader) >= 1) { + slist1 = curl_slist_append(slist1, sCustomizedHeader); + //slist1 = curl_slist_append(slist1, "CK:DKB2219EFF5PE5U3YS"); + } + curl_easy_setopt(g_http_handle, CURLOPT_CUSTOMREQUEST, "POST"); + } +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + //curl_easy_setopt(g_http_handle, CURLOPT_URL, "http://0922992430:DKB2219EFF5PE5U3YS@iot.cht.com.tw:80/iot/v1/device/28354474443/snapshot"); + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + mime1 = curl_mime_init(g_http_handle); + part1 = curl_mime_addpart(mime1); + //curl_mime_data(part1, "{\"id\":\"pedestrian\",\"lat\":22.663136,\"lon\":120.303307,\"value\":[\"silver\"]}", CURL_ZERO_TERMINATED); + curl_mime_data(part1, sData, CURL_ZERO_TERMINATED); + curl_mime_name(part1, "meta"); + part1 = curl_mime_addpart(mime1); + //curl_mime_filedata(part1, "/emmc/plugin/Aida_data/storage/snap_buf.jpg"); + curl_mime_data(part1, g_snapshot_addr_to_net_curl, snapshot_size); + curl_mime_type(part1, "image/jpg"); + curl_mime_name(part1, "image"); + + char temp_file_jpg_name[512] = { 0 }; + + if (g_stCURL_enable_filename_fixed==1) { + sprintf(temp_file_jpg_name,"%s.jpg", g_stCURL_send_jpeg_file_name); + } + else { + time_t rawtime = g_osdSysTimeStamp; + if (rawtime < 1000000000) { + rawtime = time(0); + } + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d_%02d_%02d_%02d_%02d_%02d_%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + sprintf(temp_file_jpg_name,"%s_%s.jpg", g_stCURL_send_jpeg_file_name, buf_time_info); + } + curl_mime_filename(part1, temp_file_jpg_name); + + curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, mime1); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, slist1); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + /* Here is a list of options the curl code used that cannot get generated + as source easily. You may select to either not use them or implement + them yourself. + + CURLOPT_WRITEDATA set to a objectpointer + CURLOPT_INTERLEAVEDATA set to a objectpointer + CURLOPT_WRITEFUNCTION set to a functionpointer + CURLOPT_READDATA set to a objectpointer + CURLOPT_READFUNCTION set to a functionpointer + CURLOPT_SEEKDATA set to a objectpointer + CURLOPT_SEEKFUNCTION set to a functionpointer + CURLOPT_ERRORBUFFER set to a objectpointer + CURLOPT_STDERR set to a objectpointer + CURLOPT_DEBUGFUNCTION set to a functionpointer + CURLOPT_DEBUGDATA set to a objectpointer + CURLOPT_HEADERFUNCTION set to a functionpointer + CURLOPT_HEADERDATA set to a objectpointer + + */ + + ret = curl_easy_perform(g_http_handle); + + /* Check for errors */ + if (ret != CURLE_OK) + { + /* if errors have occured, tell us wath's wrong with 'ret'*/ + sprintf(g_response_net_curl, "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(ret)); + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(ret)); + write_to_logs_html(temp_msg, "curl to post image", "ERROR", SystemSetting.enable_system_logs); + fprintf(stderr, "#1 curl_easy_perform() failed: %s\n", curl_easy_strerror(ret)); + + if (strstr(temp_msg, "Timeout was reached") != NULL || + strstr(temp_msg, "timeout was reached") != NULL) { + g_check_ping_OK = 0; + } + } + else { + if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { + sprintf(g_response_net_curl, "Notification OK:%s,%s,%s", s_q_name, s_q_plate,ptr_responded_msg->memory); + //printf("\n[net attached image]:CURLE_OK:%s\n", ptr_responded_msg->memory); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); + write_to_logs_html(temp_msg, "curl to post image", "INFO", SystemSetting.enable_system_logs); + } + else { + sprintf(g_response_net_curl, "Notification OK:%s,%s", s_q_name, s_q_plate); + //printf("\n[net attached image]:CURLE_OK\n"); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s", s_q_name, s_q_plate); + write_to_logs_html(temp_msg, "curl to post image", "INFO", SystemSetting.enable_system_logs); + } + } + + curl_easy_reset(g_http_handle); + curl_mime_free(mime1); + mime1 = NULL; + curl_slist_free_all(slist1); + slist1 = NULL; + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + } + g_response_post_OK = 1; + pthread_mutex_unlock(&mutex_curl); + pthread_exit(NULL); + //return (int)ret; +} + +//#define LOCAL_FILE "/emmc/plugin/Aida_data/snap.jpg" +#define UPLOAD_FILE_AS "myuploading.jpg" +//#define REMOTE_URL "ftp://example.com/" UPLOAD_FILE_AS +#define RENAME_FILE_TO "myname.jpg" + +/* NOTE: if you want this example to work on Windows with libcurl as a + DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION. + Failing to do so will give you a crash since a DLL may not use the + variable's memory when passed in to it from an app like this. */ +static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) +{ + unsigned long nread; + /* in real-world cases, this would probably get this data differently + as this fread() stuff is exactly what the library already would do + by default internally */ + size_t retcode = fread(ptr, size, nmemb, stream); + + if (retcode > 0) { + nread = (unsigned long)retcode; + fprintf(stderr, "*** We read %lu bytes from file\n", nread); + } + + return retcode; +} + +void net_curl_ftp_build_folder() +{ + + char sUrl[8192] = { 0 }; + strcpy(sUrl, "ftp://"); + strcat(sUrl, SystemSetting.ftp_url); + strcat(sUrl, "/"); + + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, SystemSetting.ftp_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, SystemSetting.ftp_password); + int iPort = atoi(SystemSetting.ftp_port); + + char spilt_folder[50][STRSPLIT_SIZE]={0}; + const char *del = "/"; + int num_spilt_folder = 0; + + char temp_buildfolder[1024] = { 0 }; + strcpy(temp_buildfolder,SystemSetting.ftp_remote_directory); + + if (strlen(temp_buildfolder) >= 1) { + num_spilt_folder = StrSplit(temp_buildfolder, spilt_folder, del); + //printf("\n------UU:20\n"); + for (int i = 0; i < num_spilt_folder; i++) { + char buildfolder[1024] = { 0 }; + + if (strlen(spilt_folder[i]) >= 1) { + + strcpy(buildfolder, "MKD "); + for (int j = 0; j <= i; j++) + { + strcat(buildfolder, spilt_folder[j]); + if (j < i) { + strcat(buildfolder, "/"); + } + } + + CURLcode res; + struct curl_slist *headerlist = NULL; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle) { + + headerlist = curl_slist_append(headerlist, buildfolder); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + + /* enable uploading */ + //curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + /* specify target */ + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + /* pass in that last of FTP commands to run after the transfer */ + curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); + + + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 䴩 + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + + /* Now run off and do what you have been told! */ + res = curl_easy_perform(g_http_handle); + /* Check for errors */ + if (res != CURLE_OK) { + fprintf(stderr, "#2 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + write_to_logs_html(temp_msg, "curl ftp to build folder", "ERROR", SystemSetting.enable_system_logs); + //check_if_build_new_dir = 0; + } + else { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg,"OK"); + write_to_logs_html(temp_msg, "curl ftp to build folder", "INFO", SystemSetting.enable_system_logs); + } + + /* clean up the FTP commands list */ + curl_slist_free_all(headerlist); + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + } + } + } +} + +void net_curl_ftp_delete_file() { + if (strcmp(SystemSetting.ftp_jpeg_file_name_format, "fixed") == 0) { + char sUrl[8192] = { 0 }; + strcpy(sUrl, "ftp://"); + strcat(sUrl, SystemSetting.ftp_url); + strcat(sUrl, "/"); + + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, SystemSetting.ftp_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, SystemSetting.ftp_password); + int iPort = atoi(SystemSetting.ftp_port); + + char temp_file_jpg_name[512] = { 0 }; + sprintf(temp_file_jpg_name, "%s.jpg", SystemSetting.ftp_jpeg_file_name); + + char buildfolder[2048] = { 0 }; + strcpy(buildfolder, "DELE "); + strcat(buildfolder, SystemSetting.ftp_remote_directory); + strcat(buildfolder,"/"); + strcat(buildfolder, temp_file_jpg_name); + + CURLcode res; + struct curl_slist *headerlist = NULL; + pthread_mutex_lock(&mutex_curl); + if (g_http_handle) { + + headerlist = curl_slist_append(headerlist, buildfolder); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + + /* enable uploading */ + //curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + /* specify target */ + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + /* pass in that last of FTP commands to run after the transfer */ + curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); + + + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 䴩 + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + + /* Now run off and do what you have been told! */ + res = curl_easy_perform(g_http_handle); + /* Check for errors */ + if (res != CURLE_OK) { + fprintf(stderr, "#3 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + write_to_logs_html(temp_msg, "curl ftp to delete file", "ERROR", SystemSetting.enable_system_logs); + + //check_if_build_new_dir = 0; + } + else { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg, "OK"); + write_to_logs_html(temp_msg, "curl ftp to delete image", "INFO", SystemSetting.enable_system_logs); + } + /* clean up the FTP commands list */ + curl_slist_free_all(headerlist); + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + } +} + +void net_curl_ftp_post_push_info_attached_image(char* image_buff, int image_buff_size) +{ + net_curl_ftp_delete_file(); + if (image_buff_size >= 1) { + char write_filename[256] = "/emmc/plugin/Aida_data/"; + strcat(write_filename, "snap.jpg"); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + fwrite(image_buff, sizeof(char), image_buff_size, fp); + fclose(fp); + + char sUrl[8192] = { 0 }; + strcpy(sUrl, "ftp://"); + strcat(sUrl, SystemSetting.ftp_url); + strcat(sUrl, "/"); + strcat(sUrl, UPLOAD_FILE_AS); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, SystemSetting.ftp_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, SystemSetting.ftp_password); + int iPort = atoi(SystemSetting.ftp_port); + + char temp_file_jpg_name[512] = { 0 }; + if (strcmp(SystemSetting.ftp_jpeg_file_name_format,"fixed")==0) { + sprintf(temp_file_jpg_name, "%s.jpg", SystemSetting.ftp_jpeg_file_name); + } + else { + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d_%02d_%02d_%02d_%02d_%02d_%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + sprintf(temp_file_jpg_name, "%s_%s.jpg", SystemSetting.ftp_jpeg_file_name, buf_time_info); + } + + + char sFileto[1024] = { 0 }; + strcpy(sFileto, "RNTO "); + strcat(sFileto, "../"); + if (strlen(SystemSetting.ftp_remote_directory) >= 1) { + strcat(sFileto, SystemSetting.ftp_remote_directory); + strcat(sFileto, "/"); + } + strcat(sFileto, temp_file_jpg_name);//RENAME_FILE_TO + + //printf("\n------sFileto:%s\n", sFileto); + + CURLcode res; + FILE *hd_src; + struct stat file_info; + unsigned long fsize; + + struct curl_slist *headerlist = NULL; + //MKD bbDir + static const char buf_1[] = "RNFR " UPLOAD_FILE_AS; + //static const char buf_2[] = "RNTO " RENAME_FILE_TO; + //printf("\n------buf_2:%s\n", buf_2); + + /* get the file size of the local file */ + if (stat(write_filename, &file_info)) { + printf("Couldn't open '%s': %s\n", write_filename, strerror(errno)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Couldn't open '%s': %s", write_filename, strerror(errno)); + write_to_logs_html(temp_msg, "curl ftp to post image", "ERROR", SystemSetting.enable_system_logs); + } + else { + fsize = (unsigned long)file_info.st_size; + + printf("Local file size: %lu bytes.\n", fsize); + + /* get a FILE * of the same file */ + hd_src = fopen(write_filename, "rb"); + pthread_mutex_lock(&mutex_curl); + if (g_http_handle && hd_src != NULL) { + /* build a list of commands to pass to libcurl */ + headerlist = curl_slist_append(headerlist, buf_1); + headerlist = curl_slist_append(headerlist, sFileto); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); + + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 +#endif + curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); + + /* we want to use our own read function */ + curl_easy_setopt(g_http_handle, CURLOPT_READFUNCTION, read_callback); + + /* enable uploading */ + curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); + + /* specify target */ + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + /* pass in that last of FTP commands to run after the transfer */ + curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); + + /* now specify which file to upload */ + curl_easy_setopt(g_http_handle, CURLOPT_READDATA, hd_src); + + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + curl_easy_setopt(g_http_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize); + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 䴩 + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + + /* Now run off and do what you have been told! */ + res = curl_easy_perform(g_http_handle); + /* Check for errors */ + if (res != CURLE_OK) { + fprintf(stderr, "#4 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + //check_if_build_new_dir = 0; + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); + write_to_logs_html(temp_msg, "curl ftp to post image", "ERROR", SystemSetting.enable_system_logs); + } + else { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg, "OK"); + write_to_logs_html(temp_msg, "curl ftp to post image", "INFO", SystemSetting.enable_system_logs); + } + /* clean up the FTP commands list */ + curl_slist_free_all(headerlist); + + curl_easy_reset(g_http_handle); + } + pthread_mutex_unlock(&mutex_curl); + if (hd_src != NULL) { + fclose(hd_src); /* close the local file */ + hd_src = NULL; + } + } + } + else + printf("net curl ftp] (For debugging) Error occurred when opening file I/O.\n"); + } +} + +#if 1 +void *net_curl_https_post_push_info(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("curl_post"); +#if 1 + pthread_mutex_lock(&mutex_curl); + //CURLM *multi_handle = NULL; + + //CURL_SEND *stCURL_send_data; + //stCURL_send_data = (CURL_SEND *)p_stCURL_send_data; + //memset(&stCURL_send_data, 0x00, sizeof(stCURL_send_data)); + + char sUrl[8192] = { 0 }; + strcpy(sUrl,g_stCURL_send_data_curl_url); + char sData[MAX_IMG_SIZE] = { 0 }; + size_t sData_size = g_stCURL_send_data_curl_sendbuf_size; + memcpy(sData, g_stCURL_send_data_curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); + char method[32] = { 0 }; + strcpy(method, g_stCURL_send_data_method); + char sProtocol[32] = { 0 }; + strcpy(sProtocol, g_stCURL_send_data_protocol); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, g_stCURL_send_data_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, g_stCURL_send_data_password); + int iPort = atoi(g_stCURL_send_data_port); + char sCustomizedHeader[8192] = { 0 }; + strcpy(sCustomizedHeader, g_stCURL_send_data_customized_header); + + int itimeout = atoi(g_stCURL_send_data_timeout); + + char s_q_name[30] = { 0 }; + strcpy(s_q_name, g_stCURL_send_data_q_name); + char s_q_plate[60] = { 0 }; + strcpy(s_q_plate, g_stCURL_send_data_q_plate); + + char l_smtp_capath[512] = { 0 }; + strcpy(l_smtp_capath, CURL_SMTP_CAPATH); + + //curl_mime* form = NULL; + //curl_mimepart* mimepart = NULL; + + + + //int still_running = 0; /* keep number of running handles */ + //int repeats = 0; + + //usSleep(100); + //usSleep(1000000); + + //const int timeout = 30000; + /*int timeout = 5; + if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) + timeout = 5; + else + timeout = 1;*/ + + //multi_handle = curl_multi_init(); + + //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); + //size_t snapshot_size = 0; + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 1); + + int check_reboot = 0; + + if (g_http_handle != NULL /*& multi_handle != NULL*/) + { + //form = curl_mime_init(g_http_handle); + + //struct curl_slist *pList = NULL; + // + + + struct curl_slist *pList = NULL; + //struct curl_slist *f_list = NULL; + + //pList = curl_slist_append(pList, "Accept: application/json"); + //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Content-Type: application/json"); + pList = curl_slist_append(pList, "Expect:"); + +#if 1 + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type: text/html; charset=utf-8"); + if ((int)strlen(sCustomizedHeader) >= 1) { + pList = curl_slist_append(pList, sCustomizedHeader); + } + //pList = curl_slist_append(pList, "X-Api-Key: AAAAAAAAAAA");//Tgk + //curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, "Content-Type: text/html; charset=utf-8"); + } +#endif + + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + + //printf("[%s] url: [%s]\n", __func__, "oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/4zxou-1615769161/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + /*if (g_stCURL_check_127 == 0)*/ + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + //printf("\n---------sUserNmae:%s\n", sUserNmae); + //printf("\n---------sPassWord:%s\n", sPassWord); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 +#endif + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + /* + if (strcmp(sProtocol, "HTTPS") == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); + } + else {*/ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + //} + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 +#endif + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + if (strcmp(method, "POST") == 0) + { + //printf("\nsData_size:%d\n",(int)sData_size); + //printf("\n%s\n", sData); + //fwrite(sData, 1, sData_size, stdout); + + + if (sData_size >= 1) { + + + curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, sData_size); + + //mimepart = curl_mime_addpart(form); + //curl_mime_name(mimepart, "meta"); + //curl_mime_type(mimepart, "text/plain"); + //curl_mime_data(mimepart, sData, sData_size); + } + + /* + if ((int)snapshot_size >= 1) + { + // Fill in the filename field + mimepart = curl_mime_addpart(form); + + f_list = curl_slist_append(f_list, "Content-Transfer-Encoding: 8bit"); + char temp_content_range[128] = { 0 }; + char temp_content_length[128] = { 0 }; + sprintf(temp_content_range , "Content-Range 0-%d/%d",(int)(snapshot_size-1), (int)snapshot_size); + sprintf(temp_content_length, "Content-Length %d", (int)snapshot_size); + f_list = curl_slist_append(f_list, temp_content_range); + f_list = curl_slist_append(f_list, temp_content_length); + + curl_mime_name(mimepart, "image"); + curl_mime_headers(mimepart, f_list, 1); + curl_mime_filedata(mimepart, "./storage/snap_buf.jpg"); + //curl_mime_data(mimepart, g_snapshot_addr_to_net_curl, snapshot_size); + } + curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, form); + */ + //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, outputmessage); + //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, strlen(outputmessage)); + curl_easy_setopt(g_http_handle, CURLOPT_POST, 1L); + } + CURLcode result = CURLE_FAILED_INIT; + //printf("\n-------------result:start\n"); + TRY + { + //printf("In Try Statement\n"); + result = curl_easy_perform(g_http_handle); + //THROW; + //printf("I do not appear\n"); + } + CATCH + { + result = CURLE_FAILED_INIT; + //printf("Got Exception!\n"); + } + ETRY; + //printf("\n-------------result:%d\n", (int)result); + + /* Check for errors */ + if (result != CURLE_OK) + { + /* if errors have occured, tell us wath's wrong with 'ret'*/ + sprintf(g_response_net_curl, "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(result)); + fprintf(stderr, "#5 curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(result)); + write_to_logs_html(temp_msg, "curl to post", "ERROR", SystemSetting.enable_system_logs); + + if (strstr(temp_msg, "Timeout was reached") != NULL || + strstr(temp_msg, "timeout was reached") != NULL) { + g_check_ping_OK = 0; + } + + //printf("\n--------Notification failed:%s\n", curl_easy_strerror(result)); + } + else { + if (ptr_responded_msg!=NULL && ptr_responded_msg->size >= 1) { + sprintf(g_response_net_curl, "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); + //printf("\n[net curl https]:CURLE_OK:%s\n", ptr_responded_msg->memory); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); + write_to_logs_html(temp_msg, "curl to post", "INFO", SystemSetting.enable_system_logs); + } + else { + sprintf(g_response_net_curl, "Notification OK:%s,%s", s_q_name, s_q_plate); + //printf("\n[net curl https]:CURLE_OK\n"); + + char temp_msg[MAX_IMG_SIZE] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s", s_q_name, s_q_plate); + write_to_logs_html(temp_msg, "curl to post", "INFO", SystemSetting.enable_system_logs); + + } + } + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); +#if 0 + curl_multi_add_handle(multi_handle, g_http_handle); + curl_multi_perform(multi_handle, &still_running); + + //curl_multi_add_handle(g_multi_handle, curl); + //curl_multi_perform(g_multi_handle, &g_handle_count); +#endif + //Clean curl_ease ver2 +#if 0 + int repeats = 0; + while (still_running) { + CURLMcode mc; + int numfds; + + mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); + + if (mc != CURLM_OK) { + printf("\ncurl_multi_wait() failed, code %d.\n", mc); + break; + } + + if (!numfds) { + repeats++; /* count number of repeated zero numfds */ + if (repeats > 1) { + usSleep(100000); /* sleep 100 milliseconds */ + } + } + else + repeats = 0; + + //printf("Wait repeats %d \n", repeats); + + curl_multi_perform(multi_handle, &still_running); + } +#endif + +#if 1 + if (result == CURLE_OUT_OF_MEMORY) { + printf("\n[net curl https post push info]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + + check_reboot = 1; + } +#endif + + //curl_mime_free(form); + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + } + + + //curl_multi_remove_handle(multi_handle, g_http_handle); + //curl_multi_cleanup(multi_handle); + //g_http_handle = NULL; + +#endif + g_response_post_OK = 1; + pthread_mutex_unlock(&mutex_curl); + + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "curl to post", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "curl to post", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } + + pthread_exit(NULL); +} +#endif + +#ifdef GY_OS_AMBA +void *net_curl_https_get_other_lpr_db(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("curl_lpr"); +#if 1 + pthread_mutex_lock(&mutex_curl); + //CURLM *multi_handle = NULL; + + //CURL_SEND *stCURL_send_data; + //stCURL_send_data = (CURL_SEND *)p_stCURL_send_data; + //memset(&stCURL_send_data, 0x00, sizeof(stCURL_send_data)); + + + + char sUrl[8192] = { 0 }; + strcpy(sUrl, g_stCURL_lpr_db_url); + char sUserNmae[64] = { 0 }; + strcpy(sUserNmae, g_stCURL_lpr_db_username); + char sPassWord[64] = { 0 }; + strcpy(sPassWord, g_stCURL_lpr_db_password); + int iPort = atoi(g_stCURL_lpr_db_port); + + + + //char l_smtp_capath[512] = { 0 }; + //strcpy(l_smtp_capath, CURL_SMTP_CAPATH); + + //curl_mime* form = NULL; + //curl_mimepart* mimepart = NULL; + + + + //int still_running = 0; /* keep number of running handles */ + //int repeats = 0; + + //usSleep(100); + //usSleep(1000000); + + //const int timeout = 30000; + /*int timeout = 5; + if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) + timeout = 5; + else + timeout = 1;*/ + + //multi_handle = curl_multi_init(); + + //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); + //size_t snapshot_size = 0; + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 1); + int check_reboot = 0; + if (g_http_handle != NULL /*& multi_handle != NULL*/) + { + //form = curl_mime_init(g_http_handle); + + //struct curl_slist *pList = NULL; + // + + + struct curl_slist *pList = NULL; + //struct curl_slist *f_list = NULL; + + //pList = curl_slist_append(pList, "Accept: application/json"); + //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Content-Type: application/json"); + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + + //printf("[%s] url: [%s]\n", __func__, "oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/4zxou-1615769161/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); + + curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + /*if (g_stCURL_check_127 == 0)*/ + if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) + { + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); + } + curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + /* + if (strcmp(sProtocol, "HTTPS") == 0) { + curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + //curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); + } + else {*/ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + //} + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + CURLcode result = CURLE_FAILED_INIT; + //printf("\n-------------result:start\n"); + TRY + { + //printf("In Try Statement\n"); + result = curl_easy_perform(g_http_handle); + //THROW; + //printf("I do not appear\n"); + } + CATCH + { + result = CURLE_FAILED_INIT; + //printf("Got Exception!\n"); + } + ETRY; + //printf("\n-------------result:%d\n", (int)result); + + /* Check for errors */ + if (result != CURLE_OK) + { + /* if errors have occured, tell us wath's wrong with 'ret'*/ + sprintf(g_response_lpr_db, "Notification failed:%s", curl_easy_strerror(result)); + fprintf(stderr, "#6 curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(result)); + write_to_logs_html(temp_msg, "curl to post to get lpr db", "ERROR", SystemSetting.enable_system_logs); + } + else { + if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { + sprintf(g_response_lpr_db, "Notification OK size:%ld", ptr_responded_msg->size);//ptr_responded_msg->memory + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char DB_FFLPR_IMPORT_PATH[1024]; + strcpy(DB_FFLPR_IMPORT_PATH, exePath); + strcat(DB_FFLPR_IMPORT_PATH, "db_fflpr_import.db"); + + + FILE *f = fopen(DB_FFLPR_IMPORT_PATH, "w"); + if (f != NULL) + { + fwrite(ptr_responded_msg->memory, ptr_responded_msg->size, 1, f); + fclose(f); + } + + printf("\n[net lpr db]:CURLE_OK size:%ld\n", ptr_responded_msg->size); + get_fflpr_db_import(); +#if 0 + if (unlockingKeyInnoFR == 1) { + get_face_db_import();// face - leo + } +#endif + } + else { + strcpy(g_response_lpr_db, "Notification OK"); + printf("\n[net lpr db]:CURLE_OK\n"); + } + } + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); +#if 0 + curl_multi_add_handle(multi_handle, g_http_handle); + curl_multi_perform(multi_handle, &still_running); + + //curl_multi_add_handle(g_multi_handle, curl); + //curl_multi_perform(g_multi_handle, &g_handle_count); +#endif + //Clean curl_ease ver2 +#if 0 + int repeats = 0; + while (still_running) { + CURLMcode mc; + int numfds; + + mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); + + if (mc != CURLM_OK) { + printf("\ncurl_multi_wait() failed, code %d.\n", mc); + break; + } + + if (!numfds) { + repeats++; /* count number of repeated zero numfds */ + if (repeats > 1) { + usSleep(100000); /* sleep 100 milliseconds */ + } + } + else + repeats = 0; + + //printf("Wait repeats %d \n", repeats); + + curl_multi_perform(multi_handle, &still_running); + } +#endif + +#if 1 + if (result == CURLE_OUT_OF_MEMORY) { + printf("\n[net curl https post push info]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "net curl https get other lpr db", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "net curl https get other lpr db", "CGI_REBOOT"); + + check_reboot = 1; + } +#endif + + //curl_mime_free(form); + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + } + + + //curl_multi_remove_handle(multi_handle, g_http_handle); + //curl_multi_cleanup(multi_handle); + //g_http_handle = NULL; + +#endif + g_response_post_OK = 1; + pthread_mutex_unlock(&mutex_curl); + + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "curl to post to get lpr db", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "curl to post to get lpr db", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } + + pthread_exit(NULL); +} +#endif +#ifdef GY_OS_AMBA +size_t SetSNMPRequest(QueueInfo *q_info) +{ + + if(strlen(q_info->snmp_version)>=1 && + strlen(q_info->snmp_group_name) >= 1 && + strlen(q_info->snmp_host_ip) >= 1 && + strlen(q_info->snmp_host_port) >= 1 && + strlen(q_info->snmp_oid) >= 1 && + strlen(q_info->snmp_value) >= 1 && + strlen(q_info->snmp_type) >= 1 + ) + { + FILE * pPipe; + char cmd[8192*4] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 10 /bin/snmpset -%s -c %s %s:%s %s %s %s", + q_info->snmp_version, + q_info->snmp_group_name, + q_info->snmp_host_ip, + q_info->snmp_host_port, + q_info->snmp_oid, + q_info->snmp_type, + q_info->snmp_value); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) { + char path[1024] = { 0 }; + while (fgets(path, sizeof(path), pPipe) != NULL) + { + sprintf(g_response_snmp, "free:%d,%s,SNMP OK: %s", get_free_mem_data(), cmd, path); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP OK: %s", get_free_mem_data(), cmd, path); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "INFO", SystemSetting.enable_system_logs); + + break; + } + if (strlen(path) == 0) { + sprintf(g_response_snmp, "free:%d,%s,SNMP OK: Fail, no response.", get_free_mem_data(), cmd); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP OK: Fail, no response.", get_free_mem_data(), cmd); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); + + } + vpclose(pPipe); + } + else { + sprintf(g_response_snmp, "free:%d,%s,SNMP snmpset Fail.", get_free_mem_data(), cmd); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP snmpset Fail.", get_free_mem_data(),cmd); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); + } + } + else { + printf("\n[Set SNMP Request]SNMP was set wrongly.\n"); + sprintf(g_response_snmp,"free:%d,SNMP Format Failed.", get_free_mem_data()); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,SNMP Format Failed.", get_free_mem_data()); + write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); + } + + for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) + { + if (strlen(q_info->snmp_event_name) >= 1 && strcmp(q_info->snmp_event_name, SNMPManagementList[j].snmp_event_name) == 0) + { + SNMPManagementList[j].check_if_delivering = 0; + break; + } + } + + return 0; +} +#endif +#ifdef GY_OS_NOVA +size_t SetHttpRequest_sock(QueueInfo *q_info, char* sendBuffer, char* method) +{ + char sock_sendbuf[MAX_IMG_SIZE] = { 0 }; + char sock_url[8192] = { 0 }; + //size_t content_size_sendbuf = 0; + + char sock_method[32] = { 0 }; + char sock_protocol[32] = { 0 }; + char sock_username[64] = { 0 }; + char sock_password[64] = { 0 }; + char sock_port[10] = { 0 }; + char sock_header[8192] = { 0 }; + + if (strcmp(method, "POST") == 0) + { + if ((int)q_info->content_size >= 1) { + memcpy(sock_sendbuf, q_info->content, (int)q_info->content_size); + } + } + + + if (strcmp(q_info->post_protocol, "HTTP") == 0) { + strcpy(sock_url, "http://"); + } + else { + strcpy(sock_url, "https://"); + } + + if (strcmp(q_info->host_name, "127.0.0.1") != 0 && strcmp(q_info->host_name, "localhost") != 0) { + //if (strlen(q_info->post_username) >= 1) { + //strcat(sock_url, q_info->post_username); + //strcat(sock_url, ":"); + //strcat(sock_url, q_info->post_password); + //strcat(sock_url, "@"); + //} + strcat(sock_url, q_info->host_name); + } + else { + strcpy(q_info->host_name, "127.0.0.1"); + strcat(sock_url, q_info->host_name); + } + + if (strlen(q_info->host_port) >= 1) { + strcat(sock_url, ":"); + strcat(sock_url, q_info->host_port); + } + + //strcat(sock_url, q_info->post_url); + //content_size_sendbuf = q_info->content_size; + strcpy(sock_method, method); + strcpy(sock_protocol, q_info->post_protocol); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)q_info->post_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)q_info->post_password, (unsigned char *)buf_account2); + + strcpy(sock_username, buf_account); + strcpy(sock_password, buf_account2); + strcpy(sock_port, q_info->host_port); + strcpy(sock_header, q_info->post_customized_header); + + /* + g_stCURL_enable_attached_image = 0; + g_stCURL_enable_attached_image = q_info->enable_attached_image; + g_stCURL_enable_filename_fixed = 0; + g_stCURL_enable_filename_fixed = q_info->enable_filename_fixed; + strcpy(g_stCURL_send_jpeg_file_name, q_info->post_jpeg_file_name); + + if (q_info->image_buff_size >= 1) { + memcpy(g_stCURL_image_buff, q_info->image_buff, q_info->image_buff_size); + g_stCURL_image_buff_size = q_info->image_buff_size; + } + else { + g_stCURL_image_buff_size = 0; + }*/ + + { + //int snapshot_size = 0; + + int status; + struct addrinfo host_info; + struct addrinfo *host_info_list = NULL; + + memset(&host_info, 0, sizeof(host_info)); + + host_info.ai_family = AF_INET;//AF_UNSPEC + host_info.ai_socktype = SOCK_STREAM; + host_info.ai_protocol = 0; + + status = getaddrinfo("127.0.0.1", sock_port, &host_info, &host_info_list); + if (status != 0) { + printf("\n[SetHttpRequest sock]getaddrinfo error\n"); + strcpy(g_response_net_curl,"getaddrinfo error"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else + { + + int socketfd = -1;; + //socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); + struct timeval timeout; + timeout.tv_sec = 3;//3 + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + + /* + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = PF_INET; + + //localhost test + info.sin_addr.s_addr = inet_addr("127.0.0.1"); + info.sin_port = htons(accountData[0].account_port); + //socketإ TCP_PORT_IMAGE + socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ + + int err = -1; + +#if 1 + struct addrinfo *rp; + for (rp = host_info_list; rp != NULL; rp = rp->ai_next) { + + socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (socketfd == -1) { + printf("\n[SetHttpRequest sock]socket error\n"); + strcpy(g_response_net_curl, "socket error"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else { + //printf("\n-------open getimage connected (%d)\n", socketfd); + + setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) { + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = socketfd; + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 3; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + socketRecords[i].used = 1; + //printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); + break; + } + else { + if (i == MAX_CLIENT_SOCKET - 1) { + close(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + } + } + } + + if (socketfd != -1) { + break; + } + } + else { + close(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + } + } + } +#endif + + if (socketfd >= 0) { + char Authorization[2560] = { 0 }; + if (strlen(sock_username) > 0) + { + //strcat(sendBuffer, "Authorization: Basic "); + strcpy(Authorization, sock_username); + strcat(Authorization, ":"); + + if (strlen(sock_password) > 0) + strcat(Authorization, sock_password); + } + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + if (strlen(Authorization) >= 1) + { + + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + } + + //printf("\n------httpAuth:%s\n", httpAuth); + + char msg[2560] = { 0 }; + sprintf(msg, "%s %s HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", sock_method, q_info->post_url, sock_port); + + strcat(msg, "Authorization: Basic "); + strcat(msg, httpAuth); + strcat(msg, "\r\n"); + strcat(msg, "\r\n"); + + //printf("\n-----------msg:%s\n", msg); + + err = send(socketfd, msg, strlen(msg), 0); + if (err == -1) { + printf("\n[SetHttpRequest sock]error sending\n"); + strcpy(g_response_net_curl, "error sending"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else { + char b_buffer[MAX_IMG_SIZE] = { 0 }; + //size_t bReceived; + + /*bReceived = */recv(socketfd, b_buffer, MAX_IMG_SIZE, 0); + //printf("\n[SetHttpRequest sock]------:%s\n", b_buffer); + if (strstr(b_buffer, "200") != NULL) { + strcpy(g_response_net_curl, "OK"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "INFO", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + else { + strcpy(g_response_net_curl, "error response"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + } + + close(socketfd); + //printf("\n-------close getimage connected (%d)\n", socketfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) + { + //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + socketRecords[i].used = 0; + break; + } + } + + socketfd = -1; + } + else { + printf("\n[SetHttpRequest sock]Could not create socket!\n"); + strcpy(g_response_net_curl, "Could not create socket!"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); + write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); + + g_response_post_OK = 1; + } + } + + if (host_info_list != NULL) { + freeaddrinfo(host_info_list); + host_info_list = NULL; + } + } +} +#endif + +size_t SetHttpRequest(QueueInfo *q_info, char* sendBuffer, char* method) +{ + +#if 1 + // Declare and initialize variables + //SOCKET sock; + //char* ip = NULL; + //char HostName[MAX_MSG_LEN] = { 0 }; // an IP address or a hostname, like "www.google.com" by itself + //char HostPort[10] = { 0 }; + //unsigned char Authorization[2560] = { 0 }; + //char Temp[MAX_MSG_LEN] = { 0 }; + //size_t sendLen = 0; + + //struct addrinfo* result = NULL; + //struct addrinfo* ptr = NULL; + //struct addrinfo hints = { 0 }; + //struct sockaddr_in* sockaddr_ipv4 = NULL; + + /*if (MapFind("<post_host_name>", Value)) + strcpy(HostName, Value); + + if (MapFind("<post_host_port>", Value)) + strcpy(HostPort, Value);*/ + + //hints.ai_flags = AI_NUMERICHOST; + + /* + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + */ + char curl_sendbuf[MAX_IMG_SIZE] = ""; + char curl_url[8192] = ""; + +#ifdef FOR_CC_POST +#else + //DWORD ret = getaddrinfo(HostName, "http", &hints, &result); + DWORD ret = getaddrinfo(q_info->host_name, q_info->host_port, &hints, &result); + if (ret != 0) { + printf("\ngetaddrinfo failed with error: %d\n", ret); + return 1; + } + + for (ptr = result; ptr != NULL; ptr = ptr->ai_next) + { + sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); + + /*printf("\nsock: %d\n",sock); + printf("\nptr->ai_addrlen: %d\n",ptr->ai_addrlen);*/ + + if (sock == -1) + continue; + + if (connect(sock, ptr->ai_addr, ptr->ai_addrlen) != -1) + { + break; /* Success */ + } + + close(sock); + //closesocket(sock); + } + + if (ptr == NULL) + { + // jwg list ̫ALksu + fprintf(stderr, "Failed to send POST to %s%s:%s\n", "http://", q_info->host_name, q_info->host_port); + return 1; + } + + if (ptr->ai_family == AF_INET) + { + sockaddr_ipv4 = (struct sockaddr_in *) ptr->ai_addr; + ip = inet_ntoa(sockaddr_ipv4->sin_addr); + //printf("ip address=%s\n", ip); + } + freeaddrinfo(result); // servinfo OŶ +#endif + //http first line + //if (featureType & FEATURE_LPR_TUR) + { +#if 0 + strcat(sendBuffer, method); + strcat(sendBuffer, " "); + /*if (MapFind("<post_url>", Value)) + { + if(Value[0]=='/') + strcat(sendBuffer, Value); + else + { + strcat(sendBuffer, "/"); + strcat(sendBuffer, Value); + } + } + else + strcat(sendBuffer, "/");*/ + + if (q_info->post_url[0] == '/') + strcat(sendBuffer, q_info->post_url); + else + { + strcat(sendBuffer, "/"); + strcat(sendBuffer, q_info->post_url); + } + + strcat(sendBuffer, " "); + strcat(sendBuffer, "HTTP/1.1"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Host: "); + strcat(sendBuffer, q_info->host_name); + if (strlen(q_info->host_port) > 0) + { + strcat(sendBuffer, ":"); + strcat(sendBuffer, q_info->host_port); + } + + /*strcat(sendBuffer, "Host: "); + strcat(sendBuffer, q_info->host_name); + + if (MapFind("<post_host_name>", Value)) + { + strcat(sendBuffer, Value); + if (MapFind("<post_host_port>", Value)) + { + strcat(sendBuffer, ":"); + strcat(sendBuffer, Value); + } + }*/ + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Cache-Control: no-cache"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "User-Agent: IPVideo"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Accept: */*"); + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); + strcat(sendBuffer, "\r\n"); +#endif + +#if 0 + size_t contentLen = strlen(q_info->content); + + sprintf(Temp, "%ld", contentLen); + strcat(sendBuffer, "Content-Length: "); + strcat(sendBuffer, Temp); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Connection: Closed"); + strcat(sendBuffer, "\r\n"); + + if (strlen(q_info->post_username) > 0) + { + strcat(sendBuffer, "Authorization: Basic "); + strcpy(Authorization, q_info->post_username); + strcat(Authorization, ":"); + + if (strlen(q_info->post_password) > 0) + strcat(Authorization, q_info->post_password); + } +#endif + /*strcat(sendBuffer, "Authorization: Basic "); + if (MapFind("<post_username>", Value)) + strcpy(Authorization, Value); + if (MapFind("<post_password>", Value)) + { + strcat(Authorization, ":"); + strcat(Authorization, Value); + }*/ +#if 0 + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + strcpy(httpAuth,base64_encode(Authorization, strlen(Authorization), &base64_encode_length)); + httpAuth[base64_encode_length] = '\0'; + //*(httpAuth + base64_encode_length-1) = '6'; + + strcat(sendBuffer, httpAuth); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); +#endif + +#if 0 + size_t headerLen = strlen(sendBuffer); + /*if (MapFind("<post_content>", Value)) + { + strcat(sendBuffer, Value); + contentLen = strlen(Value); + }*/ + + //printf("sendBuffer= %s\n", sendBuffer); + //size_t headerLen = strlen(sendBuffer); + size_t totalLen = headerLen; +#endif + if (strcmp(method, "POST") == 0) + { +#if 0 + contentLen = strlen(q_info->content); + + memset(curl_sendbuf, 0, sizeof(curl_sendbuf)); +#endif + if ((int)q_info->content_size >= 1) { + memcpy(curl_sendbuf, q_info->content, (int)q_info->content_size); + } + +#if 0 + memcpy(curl_sendbuf, q_info->content, strlen(q_info->content)); + memcpy(sendBuffer + headerLen, q_info->content, contentLen); + totalLen = headerLen + contentLen; +#endif + } + + //printf("send= %s\n", sendBuffer); + +#if 0 + if (strcmp(q_info->post_protocol, "HTTPS") == 0) + { + strcat(curl_url, "https://"); + strcat(curl_url, q_info->host_name); + strcat(curl_url, q_info->post_url); + + printf("Https curl_url: %s \n", curl_url); + + memset(&g_stCURL_send_data, 0, sizeof(g_stCURL_send_data)); + + strncpy(g_stCURL_send_data.curl_url, curl_url, strlen(curl_url)); + strncpy(g_stCURL_send_data.curl_sendbuf, curl_sendbuf, strlen(curl_sendbuf)); + strncpy(g_stCURL_send_data.method, method, strlen(method)); + strncpy(g_stCURL_send_data.username, q_info->post_username, strlen(q_info->post_username)); + strncpy(g_stCURL_send_data.password, q_info->post_password, strlen(q_info->post_password)); + strncpy(g_stCURL_send_data.port, q_info->host_port, strlen(q_info->host_port)); + + + pthread_t curl_thread_id; + if (pthread_create(&curl_thread_id, 0, net_curl_https_post_push_info, NULL)) + { + printf("create curl thread faile \n"); + } + + //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL); + //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL, method, + // q_info->post_username, q_info->post_password, strtol(q_info->host_port, NULL, 10)); + } + else +#endif + { + if (strcmp(q_info->post_protocol, "HTTP") == 0) { + strcat(curl_url, "http://"); + } + else { + strcat(curl_url, "https://"); + } + + if (strcmp(q_info->host_name, "127.0.0.1") != 0 && strcmp(q_info->host_name, "localhost") != 0) { + g_stCURL_check_127 = 0; + //if (strlen(q_info->post_username) >= 1 /*&& strlen(q_info->post_password) >= 1*/) { + //strcat(curl_url, q_info->post_username); + //strcat(curl_url, ":"); + //strcat(curl_url, q_info->post_password); + //strcat(curl_url, "@"); + //} + strcat(curl_url, q_info->host_name); + } + else { + g_stCURL_check_127 = 1; + strcpy(q_info->host_name, "127.0.0.1"); + strcat(curl_url, q_info->host_name); + } + + if (strlen(q_info->host_port) >= 1) { + strcat(curl_url, ":"); + strcat(curl_url, q_info->host_port); + } + + strcat(curl_url, q_info->post_url); + + if (strstr(q_info->post_url, "control?virtual.input") != NULL && strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { + g_control_alarm_gpio = 1; + } + + + //printf("Http curl_url: %s \n", curl_url); + + //memset(&g_stCURL_send_data, 0, sizeof(g_stCURL_send_data)); + + //memset(g_stCURL_send_data_curl_url, 0, 8192); + //memset(g_stCURL_send_data_curl_sendbuf, 0, 8192); + //memset(g_stCURL_send_data_method, 0, 32); + //memset(g_stCURL_send_data_username, 0, 64); + //memset(g_stCURL_send_data_password, 0, 64); + //memset(g_stCURL_send_data_port, 0, 10); + + pthread_mutex_lock(&mutex_curl); + + strcpy(g_stCURL_send_data_curl_url, curl_url); + g_stCURL_send_data_curl_sendbuf_size = 0; + g_stCURL_send_data_curl_sendbuf_size = q_info->content_size; + memcpy(g_stCURL_send_data_curl_sendbuf, curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); + strcpy(g_stCURL_send_data_method, method); + strcpy(g_stCURL_send_data_protocol, q_info->post_protocol); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)q_info->post_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)q_info->post_password, (unsigned char *)buf_account2); + + strcpy(g_stCURL_send_data_username, buf_account); + strcpy(g_stCURL_send_data_password, buf_account2); + strcpy(g_stCURL_send_data_port, q_info->host_port); + strcpy(g_stCURL_send_data_timeout, q_info->post_timeout); + strcpy(g_stCURL_send_data_customized_header, q_info->post_customized_header); + g_stCURL_enable_attached_image = 0; + g_stCURL_enable_attached_image = q_info->enable_attached_image; + g_stCURL_enable_filename_fixed = 0; + g_stCURL_enable_filename_fixed = q_info->enable_filename_fixed; + strcpy(g_stCURL_send_jpeg_file_name, q_info->post_jpeg_file_name); + + if (q_info->image_buff_size >= 1) { + memcpy(g_stCURL_image_buff, q_info->image_buff, q_info->image_buff_size); + g_stCURL_image_buff_size = q_info->image_buff_size; + } + else { + g_stCURL_image_buff_size = 0; + } + + strcpy(g_stCURL_send_data_q_name, q_info->q_name); + strcpy(g_stCURL_send_data_q_plate, q_info->q_plate); + + pthread_mutex_unlock(&mutex_curl); + + /* + printf("\n-----------g_stCURL_send_data_curl_url:%s\n", g_stCURL_send_data_curl_url); + printf("\n-----------g_stCURL_send_data_curl_sendbuf_size:%d\n", g_stCURL_send_data_curl_sendbuf_size); + printf("\n-----------g_stCURL_send_data_curl_sendbuf:%s\n", g_stCURL_send_data_curl_sendbuf); + printf("\n-----------g_stCURL_send_data_method:%s\n", g_stCURL_send_data_method); + printf("\n-----------g_stCURL_send_data_protocol:%s\n", g_stCURL_send_data_protocol); + printf("\n-----------g_stCURL_send_data_username:%s\n", g_stCURL_send_data_username); + printf("\n-----------g_stCURL_send_data_password:%s\n", g_stCURL_send_data_password); + printf("\n-----------g_stCURL_send_data_port:%s\n", g_stCURL_send_data_port); + printf("\n-----------g_stCURL_send_data_customized_header:%s\n", g_stCURL_send_data_customized_header); + printf("\n-----------g_stCURL_enable_attached_image:%d\n", g_stCURL_enable_attached_image); + printf("\n-----------g_stCURL_enable_filename_fixed:%d\n", g_stCURL_enable_filename_fixed); + printf("\n-----------g_stCURL_send_jpeg_file_name:%s\n", g_stCURL_send_jpeg_file_name); + */ +#if 1 + + //if (IsValidURL(curl_url)==true) { + + if (g_check_ping_OK == 1) { + if (g_stCURL_enable_attached_image == 0) { + pthread_t curl_thread_id; + if (pthread_create(&curl_thread_id, 0, net_curl_https_post_push_info, NULL)) + { + printf("create curl thread faile \n"); + } + } + else if (g_stCURL_enable_attached_image == 1) { + pthread_t curl_image_thread_id; + if (pthread_create(&curl_image_thread_id, 0, net_curl_https_post_push_info_attached_image, NULL)) + { + printf("create curl image thread faile \n"); + } + } + } + + + //} +#endif + + //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL, method, + // q_info->post_username, q_info->post_password, strtol(q_info->host_port, NULL, 10)); +#if 0 + if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) + printf("\nsend error(post notification) #1\n"); + else + printf("\nSuccess to send.\n"); +#endif + } + + +#ifdef FOR_CC_POST +#else + closesocket(sock); +#endif + } + +#endif + return 0; +} +#ifdef GY_OS_AMBA +void Create_ptz_socket() +{ + char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + //int cfd; // Socket ɮ״yz (File Descriptor) + int gaiStatus; // getaddrinfo AX + struct addrinfo hints; // hints ѼơA]w getaddrinfo() ^Ǥ覡 + struct addrinfo *result; // getaddrinfo() 浲G addrinfo c + + // H memset M hints c + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + + // H getaddrinfo zL DNSAo addrinfo 쵲C (Linked List) + // Hqo Host IP } + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + // OH domain, type, protocol إ socket ɮ״yz + g_socket = socket(result->ai_family, result->ai_socktype, 0); + + g_socket = socket(AF_INET, SOCK_STREAM, 0); + fcntl(g_socket, F_SETFL, O_NONBLOCK); + + // H socket ɮ״yz (cfd), addr, addrlen isu + // 䤤Aresult->ai_addr gai o q socket }c -- sockaddr + if (connect(g_socket, result->ai_addr, result->ai_addrlen) < 0) + printf("fail connect\n"); + + + // getaddrinfo (Linked List) OŶ + freeaddrinfo(result); + result = NULL; +} + +void SetHttpRequest_ptz_re(char *cgi_url, char *sOutput_data, char *sUsername, char *sPassword) +{ + //char *host = "ptsv2.com"; // ؼ URI + //char *host = "127.0.0.1"; // ؼ URI + //char *PORT_NUM = "80"; // HTTP port + + char request[0xfff], response[0xfff]; // ШD P ^T + + //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // ШD + //char *requestLine = "GET /server HTTP/1.1\r\n"; // ШD + //char *headerFmt = "Host: %s\r\n"; // Host Y + char *headerFmt = "Host: 127.0.0.1\r\n"; // Host Y + char *CRLF = "\r\n"; // Y᪺ CRLF + + // RAtmYO + //size_t bufferLen = 1024; + char buffer[1024] = { 0 }; + + //ո˽ШDCGI + char requestLine[512] = { 0 }; //"GET /server HTTP/1.1\r\n"; // ШD + strcat(requestLine, "GET"); + strcat(requestLine, " "); + + if (strlen(cgi_url) > 0) + strcat(requestLine, cgi_url); + else + strcat(requestLine, "/server"); + + strcat(requestLine, " "); + strcat(requestLine, "HTTP/1.1"); + strcat(requestLine, CRLF); + + //ո˽ШDT + strcpy(request, requestLine); + + //snprintf(buffer, bufferLen, headerFmt, host); //(tXʺAtmO) + strcat(buffer, headerFmt); + strcat(request, buffer); + + strcat(request, "Accept: */*"); + strcat(request, CRLF); + + strcat(request, "Content-Type: application/json"); + strcat(request, CRLF); + + strcat(request, "Connection: close"); + strcat(request, CRLF); + + + //ո˱bK + strcat(request, "Authorization: Basic "); + //strcpy(Authorization, q_info->post_username); + + char Authorization[2560] = { 0 }; + strcpy(Authorization, sUsername); + strcat(Authorization, ":"); + strcat(Authorization, sPassword); + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + //char original_base64_output[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + + strcat(request, httpAuth); + strcat(request, CRLF); + strcat(request, CRLF); + + // 榡ƿXШDT + printf("----------\nRequest:\n----------\n%s\n", request); + + // oeШD + if (send(g_socket, request, strlen(request), 0) < 0) + printf("Send\n"); + + + // ^ + if (recv(g_socket, response, 0xfff, 0) < 0) + { + printf("Receive fail\n"); + } + else + { + size_t iRecvLen = strlen(response); + printf("ReceiveLen: %d\n", (int)iRecvLen); + printf("Receive: \n%s\n", response); + + + snprintf(sOutput_data, iRecvLen, response); + //strcpy(sOutput_data, response); + } +} + +void SetHttpRequest_ptz(char *cgi_url, char *sOutput_data, char *sUsername, char *sPassword) +{ + //char *host = "ptsv2.com"; // ؼ URI + char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + char request[0xfff], response[0xfff]; // ШD P ^T + + //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // ШD + //char *requestLine = "GET /server HTTP/1.1\r\n"; // ШD + //char *headerFmt = "Host: %s\r\n"; // Host Y + char *headerFmt = "Host: 127.0.0.1\r\n"; // Host Y + char *CRLF = "\r\n"; // Y᪺ CRLF + + int cfd; // Socket ɮ״yz (File Descriptor) + int gaiStatus; // getaddrinfo AX + struct addrinfo hints; // hints ѼơA]w getaddrinfo() ^Ǥ覡 + struct addrinfo *result; // getaddrinfo() 浲G addrinfo c + + // ʺAtmOAHMw Ywİ (Header Buffer) + //size_t bufferLen = strlen(headerFmt) + strlen(host) + 1; + //char *buffer = (char *)malloc(bufferLen); // Ywİ + + // RAtmYO + //size_t bufferLen = 1024; + char buffer[1024] = { 0 }; + + //ո˽ШDCGI + char requestLine[512] = { 0 }; //"GET /server HTTP/1.1\r\n"; // ШD + strcat(requestLine, "GET"); + strcat(requestLine, " "); + + if (strlen(cgi_url) > 0) + strcat(requestLine, cgi_url); + else + strcat(requestLine, "/server"); + + strcat(requestLine, " "); + strcat(requestLine, "HTTP/1.1"); + strcat(requestLine, CRLF); + + //ո˽ШDT + strcpy(request, requestLine); + + //snprintf(buffer, bufferLen, headerFmt, host); //(tXʺAtmO) + strcat(buffer, headerFmt); + strcat(request, buffer); + + strcat(request, "Accept: */*"); + strcat(request, CRLF); + + strcat(request, "Content-Type: application/json"); + strcat(request, CRLF); + + strcat(request, "Connection: close"); + strcat(request, CRLF); + + + //ո˱bK + strcat(request, "Authorization: Basic "); + //strcpy(Authorization, q_info->post_username); + + char Authorization[2560] = { 0 }; + strcpy(Authorization, sUsername); + strcat(Authorization, ":"); + strcat(Authorization, sPassword); + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + //char original_base64_output[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + + strcat(request, httpAuth); + strcat(request, CRLF); + strcat(request, CRLF); + + + // wİϰO (tXʺAtmO) + //free(buffer); + //buffer = NULL; + + // H memset M hints c + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + + // H getaddrinfo zL DNSAo addrinfo 쵲C (Linked List) + // Hqo Host IP } + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + + // OH domain, type, protocol إ socket ɮ״yz + cfd = socket(result->ai_family, result->ai_socktype, 0); + + cfd = socket(AF_INET, SOCK_STREAM, 0); + fcntl(cfd, F_SETFL, O_NONBLOCK); + + // H socket ɮ״yz (cfd), addr, addrlen isu + // 䤤Aresult->ai_addr gai o q socket }c -- sockaddr + if (connect(cfd, result->ai_addr, result->ai_addrlen) < 0) + printf("fail connect\n"); + + + // getaddrinfo (Linked List) OŶ + freeaddrinfo(result); + result = NULL; + + // 榡ƿXШDT + printf("----------\nRequest:\n----------\n%s\n", request); + + // oeШD + if (send(cfd, request, strlen(request), 0) < 0) + printf("Send\n"); + + + // ^ + if (recv(cfd, response, 0xfff, 0) < 0) + { + printf("Receive fail\n"); + } + else + { + size_t iRecvLen = strlen(response); + printf("ReceiveLen: %d\n", (int)iRecvLen); + printf("Receive: \n%s\n", response); + + + snprintf(sOutput_data, iRecvLen, response); + //strcpy(sOutput_data, response); + } + + close(cfd); +} + +void SetHttpRequest_ptz_ok() +{ + //char *host = "ptsv2.com"; // ؼ URI + char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + char request[0xfff], response[0xfff]; // ШD P ^T + //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // ШD + char *requestLine = "GET /server HTTP/1.1\r\n"; // ШD + char *headerFmt = "Host: %s\r\n"; // Host Y + char *CRLF = "\r\n"; // Y᪺ CRLF + + int cfd; // Socket ɮ״yz (File Descriptor) + int gaiStatus; // getaddrinfo AX + struct addrinfo hints; // hints ѼơA]w getaddrinfo() ^Ǥ覡 + struct addrinfo *result; // getaddrinfo() 浲G addrinfo c + + // ʺAtmOAHMw Ywİ (Header Buffer) + size_t bufferLen = strlen(headerFmt) + strlen(host) + 1; + char *buffer = (char *)malloc(bufferLen); // Ywİ + + //ո˽ШDT + strcpy(request, requestLine); + snprintf(buffer, bufferLen, headerFmt, host); + strcat(request, buffer); + strcat(request, CRLF); + + // wİϰO + if (buffer != NULL) + { + free(buffer); + buffer = NULL; + } + // H memset M hints c + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + + // H getaddrinfo zL DNSAo addrinfo 쵲C (Linked List) + // Hqo Host IP } + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + + // OH domain, type, protocol إ socket ɮ״yz + cfd = socket(result->ai_family, result->ai_socktype, 0); + + // H socket ɮ״yz (cfd), addr, addrlen isu + // 䤤Aresult->ai_addr gai o q socket }c -- sockaddr + if (connect(cfd, result->ai_addr, result->ai_addrlen) < 0) + printf("fail connect\n"); + + + // getaddrinfo (Linked List) OŶ + freeaddrinfo(result); + result = NULL; + + // 榡ƿXШDT + printf("----------\nRequest:\n----------\n%s\n", request); + + // oeШD + if (send(cfd, request, strlen(request), 0) < 0) + printf("Send\n"); + + // ^ + if (recv(cfd, response, 0xfff, 0) < 0) + printf("Receive fail\n"); + else + printf("Receive: %s\n", response); + +} + +#if 0 +void SetHttpRequest_ptz() +{ + QueueInfo single_queue_node; + + strcat(single_queue_node.host_name, "ptsv2.com"); + strcat(single_queue_node.post_url, "/t/g9mu2-1639036821/post"); + strcat(single_queue_node.post_protocol, "HTTP"); + strcat(single_queue_node.content, "/t/g9mu2-1639036821/post"); + + char *host = "ptsv2.com"; // ؼ URI + //char *host = "127.0.0.1"; // ؼ URI + char *PORT_NUM = "80"; // HTTP port + + + //char sTestSendBuffer[512]; + //SetHttpRequest_ptz(&single_queue_node, sTestSendBuffer, "POST"); + + + struct addrinfo hints = { 0 }; + struct addrinfo* feed_server = NULL; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; // ϥ IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // y Socket + hints.ai_flags = AI_NUMERICSERV; // N getaddrinfo() 2 Ѽ (PORT_NUM) Ʀr + //hints.ai_family = AF_INET; + //getaddrinfo("ptsv2.com", NULL, &hints, &feed_server); + if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) + printf("fail getaddrinfo\n"); + + + SOCKET sock; + + struct addrinfo *res; + for (res = feed_server; res != NULL; res = res->ai_next) { + struct sockaddr_in* saddr = (struct sockaddr_in*)res->ai_addr; + + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + /*printf("\nsock: %d\n",sock); + printf("\nres->ai_addrlen: %d\n",res->ai_addrlen);*/ + printf("22\n"); + + if (sock == -1) + continue; + + if (connect(sock, res->ai_addr, res->ai_addrlen) != -1) + { + printf("conn sock = %d \n", sock); + printf("hostname: %s\n", inet_ntoa(saddr->sin_addr)); + break; /* Success */ + } + + //closesocket(sock); + } + + if (res == NULL) + { + // jwg list ̫ALksu + printf("Failed to send POST to %s%s:%s\n", "http://", "127.0.0.1", "80"); + return; + } + + char sendBuffer[1024]; + char Temp[MAX_MSG_LEN] = { 0 }; + + //size_t sendLen = 0; + + { + strcat(sendBuffer, "POST"); + //strcat(sendBuffer, "GET"); + strcat(sendBuffer, " "); + + if (strcmp("HTTP", "HTTP") == 0) + { + //if (q_info->post_url[0] == '/') + //{ + //strcat(sendBuffer, q_info->post_url); + //} + //else + //{ + // strcat(sendBuffer, "/"); + //strcat(sendBuffer, q_info->post_url); + //} + } + //strcat(sendBuffer, q_info->post_url); + //strcat(sendBuffer, "/server"); + strcat(sendBuffer, "/t/g9mu2-1639036821/post"); + + strcat(sendBuffer, " "); + strcat(sendBuffer, "HTTP/1.1"); + strcat(sendBuffer, "\r\n"); + int first_line_len = strlen(sendBuffer); + + strcat(sendBuffer, "Host: "); + strcat(sendBuffer, "ptsv2.com"); + //strcat(sendBuffer, q_info->host_name); + + //if (strlen(q_info->host_port) > 0) + //{ + // strcat(sendBuffer, ":"); + // strcat(sendBuffer, q_info->host_port); + //} + + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cache-Control: no-cache"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "User-Agent: IPVideo"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept: */*"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); + strcat(sendBuffer, "Content-Type: application/json"); + strcat(sendBuffer, "\r\n"); + + + + //size_t contentLen = strlen(q_info->content); + //size_t contentLen = strlen("/t/g9mu2-1639036821/post"); + size_t contentLen = 0; + + strcat(sendBuffer, "Content-Length: "); + sprintf(Temp, "%ld", contentLen); + strcat(sendBuffer, Temp); + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Connection: Closed"); + //strcat(sendBuffer, "\r\n"); + + //unsigned char Authorization[2560] = { 0 }; + + ////if (strlen(q_info->post_username) > 0) + //if (strlen("admin") > 0) + //{ + // strcat(sendBuffer, "Authorization: Basic "); + // //strcpy(Authorization, q_info->post_username); + // strcpy(Authorization, "admin"); + // strcat(Authorization, ":"); + + // //if (strlen(q_info->post_password) > 0) + // if (strlen("Pass1234") > 0) + // strcat(Authorization, "Pass1234"); + //} + + + + //size_t base64_encode_length = 0; + //char httpAuth[2560] = { 0 }; + + ////char original_base64_output[8 * 8192] = { 0 }; + //base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + //httpAuth[base64_encode_length] = '\0'; + ////*(httpAuth + base64_encode_length-1) = '6'; + + //strcat(sendBuffer, httpAuth); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "\r\n"); + + + size_t headerLen = strlen(sendBuffer); + size_t totalLen = headerLen; +#if 0 + /*if (strcmp("GET", "POST") == 0) + { + contentLen = strlen("/t/g9mu2-1639036821/post"); + + memcpy(sendBuffer + headerLen, "/t/g9mu2-1639036821/post", contentLen); + totalLen = headerLen + contentLen; + }*/ + + if (strcmp("GET", "GET") == 0) + { + contentLen = strlen("/t/g9mu2-1639036821/post"); + + memcpy(sendBuffer + headerLen, "/t/g9mu2-1639036821/post", contentLen); + totalLen = headerLen + contentLen; + } +#endif + + printf("send= \n%s\n", sendBuffer); + + if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) + printf("\nsend error(post notification) #2\n"); + else + printf("\nSuccess to send.\n"); + + closesocket(sock); + } +} + + +size_t SetHttpRequest_ptz(QueueInfo *q_info, char* sendBuffer, char* method) +{ + // Declare and initialize variables + SOCKET sock; + char* ip = NULL; + char HostName[MAX_MSG_LEN] = { 0 }; // an IP address or a hostname, like "www.google.com" by itself + char HostPort[10] = { 0 }; + unsigned char Authorization[2560] = { 0 }; + char Temp[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + struct addrinfo* result = NULL, *tmp; + struct addrinfo* ptr = NULL; + struct addrinfo hints = { 0 }; + struct sockaddr_in* sockaddr_ipv4 = NULL; + + + + //hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + char curl_sendbuf[8192] = ""; + char curl_url[8192] = ""; + char host[256]; + + + //DWORD ret = getaddrinfo(HostName, "http", &hints, &result); + //DWORD ret = getaddrinfo(q_info->host_name, q_info->host_port, &hints, &result); + + printf("00\n"); + + DWORD ret = getaddrinfo("127.0.0.1", NULL, &hints, &result); + + printf("11\n"); + + if (ret != 0) { + printf("getaddrinfo failed with error: %d\n", ret); + return 1; + } + + //for (tmp = result; tmp != NULL; tmp = tmp->ai_next) { + // getnameinfo(tmp->ai_addr, tmp->ai_addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST); + // puts(host); + //} + + freeaddrinfo(result); + + for (ptr = result; ptr != NULL; ptr = ptr->ai_next) + { + sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); + /*printf("\nsock: %d\n",sock); + printf("\nptr->ai_addrlen: %d\n",ptr->ai_addrlen);*/ + printf("22\n"); + + if (sock == -1) + continue; + + if (connect(sock, ptr->ai_addr, ptr->ai_addrlen) != -1) + { + printf("conn sock = %d \n", sock); + break; /* Success */ + } + + closesocket(sock); + } + printf("33\n"); + if (ptr == NULL) + { + // jwg list ̫ALksu + fprintf(stderr, "Failed to send POST to %s%s:%s\n", "http://", "127.0.0.1", "80"); + return 1; + } + + if (ptr->ai_family == AF_INET) + { + sockaddr_ipv4 = (struct sockaddr_in *) ptr->ai_addr; + ip = inet_ntoa(sockaddr_ipv4->sin_addr); + //printf("ip address=%s\n", ip); + } + freeaddrinfo(result); // servinfo OŶ + + printf("44\n"); + + { + strcat(sendBuffer, method); + strcat(sendBuffer, " "); + + if (strcmp(q_info->post_protocol, "HTTP") == 0) + { + if (q_info->post_url[0] == '/') + { + //strcat(sendBuffer, q_info->post_url); + } + else + { + strcat(sendBuffer, "/"); + //strcat(sendBuffer, q_info->post_url); + } + } + //strcat(sendBuffer, q_info->post_url); + strcat(sendBuffer, "/server"); + + strcat(sendBuffer, " "); + strcat(sendBuffer, "HTTP/1.1"); + strcat(sendBuffer, "\r\n"); + int first_line_len = strlen(sendBuffer); + + strcat(sendBuffer, "Host: "); + strcat(sendBuffer, "127.0.0.1"); + //strcat(sendBuffer, q_info->host_name); + + //if (strlen(q_info->host_port) > 0) + //{ + // strcat(sendBuffer, ":"); + // strcat(sendBuffer, q_info->host_port); + //} + + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Cache-Control: no-cache"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "User-Agent: IPVideo"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Accept: */*"); + strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); + //strcat(sendBuffer, "\r\n"); + + //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); + strcat(sendBuffer, "\r\n"); + + + + //size_t contentLen = strlen(q_info->content); + size_t contentLen = strlen("\server"); + + strcat(sendBuffer, "Content-Length: "); + sprintf(Temp, "%ld", contentLen); + strcat(sendBuffer, Temp); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, "Connection: Closed"); + strcat(sendBuffer, "\r\n"); + + //if (strlen(q_info->post_username) > 0) + if (strlen("admin") > 0) + { + strcat(sendBuffer, "Authorization: Basic "); + //strcpy(Authorization, q_info->post_username); + strcpy(Authorization, "admin"); + strcat(Authorization, ":"); + + //if (strlen(q_info->post_password) > 0) + if (strlen("Pass1234") > 0) + strcat(Authorization, "Pass1234"); + } + + + + size_t base64_encode_length = 0; + char httpAuth[2560] = { 0 }; + //char original_base64_output[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + //*(httpAuth + base64_encode_length-1) = '6'; + + strcat(sendBuffer, httpAuth); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + + size_t headerLen = strlen(sendBuffer); + size_t totalLen = headerLen; + + if (strcmp(method, "POST") == 0) + { + contentLen = strlen(q_info->content); + + memcpy(sendBuffer + headerLen, q_info->content, contentLen); + totalLen = headerLen + contentLen; + } + + //printf("send= %s\n", sendBuffer); + + if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) + printf("\nsend error(post notification) #3\n"); + else + printf("\nSuccess to send.\n"); + + closesocket(sock); + } +#if 0 + + + + + + + //http first line + //if (featureType & FEATURE_LPR_TUR) + +#endif + + return 0; +} +#endif +#endif //#ifdef GY_OS_AMBA +size_t SetHttpResponse_server(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(sendBuffer, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(sendBuffer, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(sendBuffer, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(sendBuffer, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(sendBuffer, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(sendBuffer, "HTTP/1.1 404 Not Found"); + break; + } + //strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + //time_t now = time(0); + //struct tm tm = *gmtime(&now); + //memset(tempStr, 0x00, sizeof(tempStr)); + //strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + //strcat(sendBuffer, "Date: "); + //strcat(sendBuffer, tempStr); + //strcat(sendBuffer, "\r\n"); + //memset(tempStr, 0x00, sizeof(tempStr)); + //snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + //strcat(sendBuffer, tempStr); + + strcat(sendBuffer, "Content-Type: "); + strcat(sendBuffer, contentType); + strcat(sendBuffer, ";charset=utf-8;"); + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Headers: content-type"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Methods: POST,GET"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Origin: *"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Credentials: true"); + strcat(sendBuffer, "\r\n"); + /* + if (httpCode == _CODE_200) + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + else + strcat(sendBuffer, "Connection: Closed\r\n");*/ + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + + return sendLen; +} + +size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(sendBuffer, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(sendBuffer, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(sendBuffer, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(sendBuffer, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(sendBuffer, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(sendBuffer, "HTTP/1.1 404 Not Found"); + break; + } + //strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + //time_t now = time(0); + //struct tm tm = *gmtime(&now); + //memset(tempStr, 0x00, sizeof(tempStr)); + //strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + //strcat(sendBuffer, "Date: "); + //strcat(sendBuffer, tempStr); + //strcat(sendBuffer, "\r\n"); + //memset(tempStr, 0x00, sizeof(tempStr)); + //snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + //strcat(sendBuffer, tempStr); + /* + if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) + { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %d", contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + }*/ + strcat(sendBuffer, "Content-Type: "); + + if (strcmp(contentType, "text/html;") == 0) { + strcat(sendBuffer, contentType); + strcat(sendBuffer, "charset=utf-8;"); + } + else if (strcmp(contentType, "text/html") == 0) { + strcat(sendBuffer, contentType); + strcat(sendBuffer, ";charset=utf-8;"); + } + else { + strcat(sendBuffer, contentType); + strcat(sendBuffer, ";charset=utf-8;"); + } + + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Headers: content-type"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Methods: POST,GET"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Origin: *"); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "Access-Control-Allow-Credentials: true"); + strcat(sendBuffer, "\r\n"); + /* + if (httpCode == _CODE_200) + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + else + strcat(sendBuffer, "Connection: Closed\r\n");*/ + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + + return sendLen; +} +//claire, response attachment +size_t SetHttpResponse_att(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(tempStr, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(tempStr, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(tempStr, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(tempStr, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(tempStr, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(tempStr, "HTTP/1.1 404 Not Found"); + break; + } + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + time_t now = time(0); + struct tm tm = *gmtime(&now); + memset(tempStr, 0x00, sizeof(tempStr)); + strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + strcat(sendBuffer, "Date: "); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + strcat(sendBuffer, tempStr); + if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) + { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + } + strcat(sendBuffer, "Content-Type: "); + strcat(sendBuffer, contentType); + //strcat(sendBuffer, "; charset=utf-8"); + strcat(sendBuffer, "\r\n"); + if (httpCode == _CODE_200) { + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + } + else { + strcat(sendBuffer, "Connection: Closed\r\n"); + } + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + + return sendLen; +} +//20201028 sophia add +size_t SetHttpResponse_authHeader(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) +{ + char tempStr[MAX_MSG_LEN] = { 0 }; + size_t sendLen = 0; + + switch (httpCode) + { + case _CODE_200: + strcpy(tempStr, "HTTP/1.1 200 OK"); + break; + case _CODE_204: + strcpy(tempStr, "HTTP/1.1 204 No Content"); + break; + case _CODE_400: + strcpy(tempStr, "HTTP/1.1 400 Bad Request"); + break; + case _CODE_401: + strcpy(tempStr, "HTTP/1.1 401 Unauthorized"); + break; + case _CODE_403: + strcpy(tempStr, "HTTP/1.1 403 Forbidden"); + break; + case _CODE_404: + strcpy(tempStr, "HTTP/1.1 404 Not Found"); + break; + } + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + + time_t now = time(0); + struct tm tm = *gmtime(&now); + memset(tempStr, 0x00, sizeof(tempStr)); + strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); + strcat(sendBuffer, "Date: "); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "WWW-Authenticate: Basic realm=\"IPVideo\""); + strcat(sendBuffer, "\r\n"); + if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) + { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); + strcat(sendBuffer, tempStr); + strcat(sendBuffer, "\r\n"); + } + strcat(sendBuffer, "Content-Type: "); + strcat(sendBuffer, contentType); + //strcat(sendBuffer, "; charset=utf-8"); + strcat(sendBuffer, "\r\n"); + if (httpCode == _CODE_200) + strcat(sendBuffer, "Connection: Keep-Alive\r\n"); + else + strcat(sendBuffer, "Connection: Closed\r\n"); + strcat(sendBuffer, "\r\n"); + + strcat(sendBuffer, content); + strcat(sendBuffer, "\r\n"); + strcat(sendBuffer, "\r\n"); + sendLen = strlen(sendBuffer); + + //char* content_utf8 = StringToUTF8(content); + //strcat(sendBuffer, content_utf8); + //sendLen += strlen(content_utf8); + //DumpHex(sendBuffer, sendLen); + #ifdef _DEBUG_AMBA + printf("\n[SetHttpResponse] sendBuffer:%s\n", sendBuffer); + #endif + return sendLen; +} + +//20201028 sophia add + +int run_connection_authorized = 0; +int is_connection_authorized(char* recvBuffer, SOCKET *client_socket, int isTcpTunnel) +{ + if (run_connection_authorized == 0) { + run_connection_authorized = 1; + //pthread_mutex_lock(&mutex_base64); + + SOCKET cli_socket = *client_socket; + + /* + printf("\n-----------------------\n"); + printf("\n%s\n",recvBuffer); + printf("\n-----------------------\n");*/ + + int check_if_data_loading_OK = 0; + + int is_authorized = 0; + if (is_authorized == 0) { + //char *is_localhost = strstr(recvBuffer, "127.0.0.1"); + //if (is_localhost == NULL) + { + //get id,pass + + char id[512] = { 0 }; + char pass[512] = { 0 }; + + //memset(id, 0x00, sizeof(id)); + //memset(pass, 0x00, sizeof(pass)); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] not localhost\n", cli_socket); + printf("\n(%d) [is_connection_authorized] recvBuffer: %s\n", cli_socket, recvBuffer); +#endif + + //is_authorized = 0; + + //check authorization process + char *start = strstr(recvBuffer, "Authorization: Basic "); + if (start != NULL) + { +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] Authorization: Basic here\n", cli_socket); +#endif + + start = start + strlen("Authorization: Basic "); + char *end = start; + int len = 0; + if (start) + { + while (*end != '\r' && *end != '\n' && *end != ' ' /*&& *end != '\r\n'*/) + { + len = len + 1; + end++; + } + + //decrypt id:pass + char EncryptIdPass[512]; + memset(EncryptIdPass, 0x00, sizeof(EncryptIdPass)); + strncpy(EncryptIdPass, start, len); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] EncryptIdPass:%s %d %d\n", cli_socket, EncryptIdPass, strlen(EncryptIdPass), len); +#endif + + size_t base64_decode_length = 0; + char DecryptData[512]; + memset(DecryptData, 0x00, sizeof(DecryptData)); + unsigned char OriEncryptData[1024] = { 0 }; + base64_decode(EncryptIdPass, strlen(EncryptIdPass), &base64_decode_length, OriEncryptData); + memcpy(DecryptData, OriEncryptData, base64_decode_length); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [is_connection_authorized] ### OriEncryptData:%s DecryptData:%s\n", cli_socket, OriEncryptData, DecryptData); +#endif //_DEBUG_AMBA + + if (strlen(DecryptData) > 1) //more than ":" + { + //printf("\n--------------DecryptData:%s\n", DecryptData); + + char *delim = ":"; + char *pch = NULL; + char *pLeft = NULL; + pch = strtok_modified(DecryptData, delim, &pLeft); + if (pch != NULL) + { + char temp_cpy[100] = { 0 }; + sprintf(temp_cpy, "%s", pch); + char temp_account[512] = { 0 }; + urlencode((unsigned char *)temp_cpy, strlen(temp_cpy), (unsigned char *)temp_account, 512); + + sprintf(id, "%s", temp_account); + //printf("\n-------------id:%s\n",id); + pch = strtok_modified(NULL, delim, &pLeft); + if (pch != NULL) + { + char temp_cpy_2[100] = { 0 }; + sprintf(temp_cpy_2, "%s", pch); + char temp_account_2[512] = { 0 }; + urlencode((unsigned char *)temp_cpy_2, strlen(temp_cpy_2), (unsigned char *)temp_account_2, 512); + sprintf(pass, "%s", temp_account_2); + //printf("\n-------------pass:%s\n", pass); + } + } + +#if 0 + printf("\n(%d) [is_connection_authorized] ### id:%s pass:%s\n", cli_socket, id, pass); +#endif + + //comapre id,pass with accountData + + //{ + //int match = 0; + //int i = 0; + //while (!is_authorized && i < MAX_ACCOUNT_DATA_NUM /*&& strlen(id) >= 1 && strlen(pass) >= 1*/) + //{ + /* + if (strlen(accountData[i].account_username) >= 1 && strlen(accountData[i].account_password) >= 1) { + */ + // if (strcmp(id, accountData[i].account_username) == 0) + // { + // if (strcmp(pass, accountData[i].account_password) == 0) + // { + // is_authorized = 1; + // break; + // } + // } + //} + // i++; + //} + //} + } + } + } + + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nid: %s; pass: %s\n",id,pass); + for(int i = 0 ; i < 10 ; i++) + printf("\n(%d)username: %s; password: %s\n",i, accountData[i].account_username, accountData[i].account_password); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + + for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) { + if (strlen(accountData[i].account_username) == 0) { + continue; + } + + if (strlen(accountData[i].account_username) >= 1 && strlen(accountData[i].account_password) >= 1) { + check_if_data_loading_OK = 1; + } + + if (strcmp(id, accountData[i].account_username) == 0) + { + if (strcmp(pass, accountData[i].account_password) == 0) + { + is_authorized = 1; + break; + } + } + } + } + } + + /* + printf("\n-----------------------AABB\n"); + printf("\n%s\n", recvBuffer); + printf("\n-----------------------AABB\n"); + */ + + int iSockIdx = -1; + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == cli_socket) + { + iSockIdx = i; + break; + } + } + } + + + char *is_NVR_client = strstr(recvBuffer, "menu_on_nvr"); + if (is_NVR_client != NULL || (iSockIdx >= 0 && socketRecords[iSockIdx].isNvrRequest == 1)) + { + //printf("pppppppppppppppppppppppppppppppppppppppppppppppp find \n"); + + if(iSockIdx >= 0) + socketRecords[iSockIdx].isNvrRequest = 1; + + is_authorized = 1; + } + + if (is_authorized == 1 && (iSockIdx >= 0 && socketRecords[iSockIdx].isCredentialRequest == 1)) { + g_is_check_credential = 1; + } + else if (is_authorized == 0 && (iSockIdx >= 0 && socketRecords[iSockIdx].isCredentialRequest == 1)) { + g_is_check_credential = 0; + } + else if (g_is_check_credential == 1 || isTcpTunnel == TRUE) { + is_authorized = 1; + } + + //is_authorized = 1; + if (is_authorized == 0 && check_if_data_loading_OK == 1) + { + + //printf("\n---------------------------------------------\n"); + //printf("\n(%d) [is_connection_authorized] recvBuffer: %s\n", cli_socket, recvBuffer); + //printf("\n----------------------------------------------\n"); + + char msg[MAX_MSG_LEN]; + char sendBuffer[BUFSIZE_V2] = { 0 }; + char beforeSendBuffer[BUFSIZE_V2] = { 0 }; + char contentDescription[MAX_MSG_LEN] = { 0 }; + + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Unauthorized."); + printf(msg); + //syslog(NW_SORRY, msg, recvBuffer, cli_socket); + strcpy(beforeSendBuffer, msg); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_authHeader(sendBuffer, _CODE_401, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #16\n"); + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed####11\n"); + } + + //return; + }/* + else { + char msg[MAX_MSG_LEN]; + char sendBuffer[BUFSIZE] = { 0 }; + char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + char contentDescription[MAX_MSG_LEN] = { 0 }; + + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "OK."); + printf(msg); + //syslog(NW_SORRY, msg, recvBuffer, cli_socket); + strcpy(beforeSendBuffer, msg); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_authHeader(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error\n"); + }*/ + + //pthread_mutex_unlock(&mutex_base64); + run_connection_authorized = 0; + return is_authorized; + } + else { + return 1; + } +} + +void update_config(char *recInfo) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("read config.json.\n"); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + + if (fileBuf) { + + cJSON* root, *about_box;//, * unlock_key, * sys_id; + cJSON *rec_json, *rec_key; + rec_json = cJSON_Parse(recInfo); + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + //static char* unlocking_key; + + if (root) + { + //printf("config.json parse OK.\n"); + about_box = cJSON_GetObjectItem(root, "about_box"); + //unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + //if (unlock_key) + // printf("unlocking_key exists.\n"); + //else + // printf("unlocking_key is NULL.\n"); + + //printf("get sys id = %s \n", fetch_mac_addr); + //printf("get jsonfile key = %s \n", unlock_key->valuestring); + + //Get MAC Address + /*printf("\ng_match_mac: %d\n", g_match_mac); + printf("\ng_mac_address: %s\n", g_mac_address);*/ + + if (g_match_mac == 1) { + cJSON_ReplaceItemInObject(about_box, "system id", cJSON_CreateString(g_mac_address)); + } + else { + char fetch_mac_addr[64] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + GetMACAddress(fetch_mac_addr); + //printf("mac addr = %s \n", fetch_mac_addr); + + char *find; + find = strchr(fetch_mac_addr, '\n'); + if (find) + *find = '\0'; + + cJSON_ReplaceItemInObject(about_box, "system id", cJSON_CreateString(fetch_mac_addr)); + } + + //sys_id = cJSON_GetObjectItem(about_box, "system id"); + //printf("show update sys id = %s \n", sys_id->valuestring); + //cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("testkey123456")); + + rec_key = cJSON_GetObjectItem(rec_json, "unlocking_key"); + //printf("get input key = %s \n", rec_key->valuestring); + + +//#ifdef GY_OS_AMBA + //if (rec_key && strlen(rec_key->valuestring)>=1) +//#else + if (rec_key) +//#endif + { + + memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); +//#ifdef GY_OS_AMBA + /*char temp_key[512] = { 0 }; + char formatted_mac[30] = { 0 }; + if (strstr(rec_key->valuestring, "face") != NULL) { + getContractSignature(temp_key, formatted_mac); + } + if (strstr(rec_key->valuestring, "face") != NULL) { + strcpy(strUnlockingKey, "face"); + strcat(strUnlockingKey, temp_key); + } + else *///{ + //strcpy(strUnlockingKey, rec_key->valuestring); + //} +//#else + if (strlen(rec_key->valuestring) >= 1) { + strcpy(strUnlockingKey, rec_key->valuestring); + } + else { + strcpy(strUnlockingKey,"auto"); + } +//#endif + + + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + + { + char buf_exe[1024] = {}; + readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); + + char exePath_temp[1024] = {}; + getFilePath(buf_exe, exePath_temp, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath_temp); + strcat(keyPATH, "key.txt"); + if (FileExist(keyPATH) == 1) { + FILE *pFile; + + if ((pFile = fopen(keyPATH, "w")) != NULL) + { + fprintf(pFile, strUnlockingKey); + fclose(pFile); + + } + else + printf("Fail to open key.txt \n"); + } + } + } + + //printf("read key = %s \n", unlock_key->valuestring); + + char* JsonString = cJSON_Print(root); + + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + CopyFileTo(configPATH, config_bakPATH); + } + else + { + printf("Fail to open Config.json \n"); + } + + if (rec_json) { + free(rec_json); + rec_json = NULL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } +} + +void update_enable_only_show_metadata1(int temp_enable_only_show_metadata1) +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("read config.json.\n"); + + char* fileBuf = ReadAllBytes(filename); + + if (fileBuf) { + + cJSON* root, *view_setting,*camera01;//, * unlock_key, * sys_id; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (root) + { + //printf("config.json parse OK.\n"); + view_setting = cJSON_GetObjectItem(root, "view_setting"); + camera01 = cJSON_GetObjectItem(view_setting, "camera01"); + + cJSON_ReplaceItemInObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(temp_enable_only_show_metadata1)); + char* JsonString = cJSON_Print(root); + + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + CopyFileTo(configPATH, config_bakPATH); + } + else + { + printf("Fail to open Config.json \n"); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } +} + +void replace_one_line_in_a_file(char *path,int line,char *newline) { + /* File pointer to hold reference of input file */ + FILE * fPtr; + FILE * fTemp; + + char buffer[BUFFER_SIZE] = { 0 }; + int count; + + /* Open all required files */ + fPtr = fopen(path, "r"); + fTemp = fopen("replace.tmp", "w+"); + + /* fopen() return NULL if unable to open file in given mode. */ + if (fPtr == NULL ) + { + /* Unable to open file hence exit */ + printf("\nUnable to open [fPtr] file.\n"); + printf("Please check whether file exists and you have read/write privilege.\n"); + exit(EXIT_SUCCESS); + } + if (fTemp == NULL) + { + /* Unable to open file hence exit */ + printf("\nUnable to open [fTemp] file.\n"); + printf("Please check whether file exists and you have read/write privilege.\n"); + exit(EXIT_SUCCESS); + } + /* + * Read line from source file and write to destination + * file after replacing given line. + */ + count = 0; + while ((fgets(buffer, BUFFER_SIZE, fPtr)) != NULL) + { + count++; + + /* If current line is line to replace */ + if (count == line) + fputs(newline, fTemp); + else + fputs(buffer, fTemp); + memset(buffer, 0x00, sizeof(buffer)); + } + + /* Close all files to release resource */ + fclose(fPtr); + fclose(fTemp); + + /* Delete original source file */ + remove(path); + + /* Rename temporary file as original file */ + rename("replace.tmp", path); + //printf("\nSuccessfully replaced '%d' line with '%s'.", line, newline); +} + +size_t get_control_io_from_ipcam(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + //printf("\n-----get_control_io_from_ipcam start\n"); + pthread_mutex_lock(&mutex_curl); + //g_curl_handle_service_from_ipcam = curl_easy_init(); // Initialization for each handler. + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/control?get=io"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[get service from ipcam]cmd: %s\n", cmd); + + if (g_http_handle) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); + if (res_service_from_ipcam != CURLE_OK) // Check for errors + { + fprintf(stderr, "[get control io from ipcam] Failed to initialize the CURL handler for service from ipcam. #1 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[get control io from ipcam] CURL failed to initialize!\n"); + } + + //curl_easy_cleanup(g_curl_handle_service_from_ipcam); + //g_curl_handle_service_from_ipcam = NULL; + //printf("\n-----get_control_io_from_ipcam end\n"); + + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); + return response_size; +} + +//CURL* g_curl_handle_service_from_ipcam = NULL; +size_t get_service_from_ipcam(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + //printf("\n-----get_service_from_ipcam start\n"); + pthread_mutex_lock(&mutex_curl); + //g_curl_handle_service_from_ipcam = curl_easy_init(); // Initialization for each handler. + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/service?get=all"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[get service from ipcam]cmd: %s\n", cmd); + + if (g_http_handle) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L); +#endif + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + + CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); + if (res_service_from_ipcam != CURLE_OK) // Check for errors + { + fprintf(stderr, "[get service from ipcam] Failed to initialize the CURL handler for service from ipcam. #1 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[get service from ipcam] CURL failed to initialize!\n"); + } + + //curl_easy_cleanup(g_curl_handle_service_from_ipcam); + //g_curl_handle_service_from_ipcam = NULL; + //printf("\n-----get_service_from_ipcam end\n"); + + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); + return response_size; +} + +CURL* g_curl_handle_set_gpio = NULL; +void build_one_gpio(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/service?post."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_gpio) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_PORT, port_num); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_CONNECTTIMEOUT, 3); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TIMEOUT, 5); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TIMEOUT, 3); +#endif + + //curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_smart_event = curl_easy_perform(g_curl_handle_set_gpio); + if (res_smart_event != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one gpio] Failed to initialize the CURL handler for gpio. Reason: %s\n", curl_easy_strerror(res_smart_event)); + } + + curl_easy_reset(g_curl_handle_set_gpio); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one gpio] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +CURL* g_curl_handle_set_smart_event = NULL; +void build_one_smart_event(char * myname,char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/event?event."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_smart_event) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_PORT, port_num); + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_CONNECTTIMEOUT, 3); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TIMEOUT, 5); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TIMEOUT, 3); +#endif + + //curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_smart_event = curl_easy_perform(g_curl_handle_set_smart_event); + if (res_smart_event != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one smart event] Failed to initialize the CURL handler for smart event. Reason: %s\n", curl_easy_strerror(res_smart_event)); + } + + curl_easy_reset(g_curl_handle_set_smart_event); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one smart event] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_build_smart_events(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("smart_event"); + pthread_mutex_lock(&mutex_curl); + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_set_smart_event = g_http_handle; // Initialization for each handler. + + build_one_smart_event("event0000", "1"); + build_one_smart_event("name0000", "Aida%20Event%201"); +#ifdef GY_OS_AMBA + build_one_smart_event("c_name00000000", "Open%20Alarm%20And%20Close%20Virtual%201"); +#else + build_one_smart_event("c_name00000000", "Close%20Virtual%201"); +#endif + + build_one_smart_event("c_time00000000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00000000", "virtual_in/0/0/0/1/1"); + build_one_smart_event("c_schedule00000000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + +#ifdef GY_OS_AMBA + build_one_smart_event("c_action00000000", "do/0/1000/active/0/0/0,virtual_in/0/0/inactive/0/0/0,"); +#else + build_one_smart_event("c_action00000000", "virtual_in/0/0/inactive/0/0/0,"); +#endif + + build_one_smart_event("event0001", "1"); + build_one_smart_event("name0001", "Aida%20Event%202%20%2F%20SD%20Recording"); + build_one_smart_event("c_name00010000", "Close%20Virtual%202%20And%20Start%20Recording"); + build_one_smart_event("c_time00010000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00010000", "virtual_in/1/0/0/1/1"); + build_one_smart_event("c_schedule00010000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00010000", "sd/0/60000/active/0/0/0,virtual_in/1/0/inactive/0/0/0,"); + +#ifdef GY_OS_NOVA + if (g_camera_white_LED == 1) { + build_one_smart_event("event0002", "1"); + build_one_smart_event("name0002", "Aida%20Event%203%20%2F%20White%20LED"); + build_one_smart_event("c_name00020000", "Close%20Virtual%203%20And%20Start%20LED"); + build_one_smart_event("c_time00020000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00020000", "virtual_in/2/0/0/1/1"); + build_one_smart_event("c_schedule00020000", "0,7/0/21600,7/64800/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00020000", "ir_led/1/60000/active/0/0/0,virtual_in/2/0/inactive/0/0/0,"); + } +#endif + + +#ifdef GY_OS_AMBA + build_one_smart_event("event0002", "1"); + build_one_smart_event("name0002", "Aida%20Event%203"); + build_one_smart_event("c_name00020000", "Open%20Alarm%20And%20Close%20Virtual%203"); + build_one_smart_event("c_time00020000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00020000", "virtual_in/2/0/0/1/1"); + build_one_smart_event("c_schedule00020000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00020000", "do/0/1000/active/0/0/0,virtual_in/2/0/inactive/0/0/0,"); + + build_one_smart_event("event0003", "1"); + build_one_smart_event("name0003", "Aida%20Event%204"); + build_one_smart_event("c_name00030000", "Open%20Alarm%20And%20Close%20Virtual%204"); + build_one_smart_event("c_time00030000", "1,5000,0,0,1"); + build_one_smart_event("c_trigger00030000", "virtual_in/3/0/0/1/1"); + build_one_smart_event("c_schedule00030000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00030000", "do/0/1000/active/0/0/0,virtual_in/3/0/inactive/0/0/0,"); +#endif + + if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { +#ifdef GY_OS_V_SERIES + +#else + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_set_smart_event = g_http_handle; + + build_one_smart_event("event0004", "1"); + build_one_smart_event("name0004", "LPR%20Digital%20Trigger%201"); + build_one_smart_event("c_name00040000", "Open%20HTTP%20Post%20Service%201"); + build_one_smart_event("c_time00040000", "1,10500,0,0,1"); + build_one_smart_event("c_trigger00040000", "digital_in/0/0/8/1/0"); + build_one_smart_event("c_schedule00040000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00040000", "post/0/0/active/0/0/0"); +#endif + + curl_easy_reset(g_curl_handle_set_smart_event); + +#ifdef GY_OS_V_SERIES + +#else + g_curl_handle_set_gpio = g_http_handle; + + build_one_gpio("name0", "Digital_Trigger_Post"); + build_one_gpio("server0", "localhost"); + build_one_gpio("server_port0", accountData[0].account_aida_port); + build_one_gpio("account0", accountData[0].account_username); + build_one_gpio("password0", accountData[0].account_password); + build_one_gpio("url0", "/control?alarm.gpio=1"); + build_one_gpio("content0", "lilinstarthttpget"); + + curl_easy_reset(g_curl_handle_set_gpio); +#endif + } + + pthread_mutex_unlock(&mutex_curl); + + pthread_exit(NULL); + +} + +void* auto_build_smart_events_di_vi(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("smart_di_vi"); + if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { +#ifdef GY_OS_V_SERIES + +#else + pthread_mutex_lock(&mutex_curl); + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_set_smart_event = g_http_handle; // Initialization for each handler. + + build_one_smart_event("event0004", "1"); + build_one_smart_event("name0004", "LPR%20Digital%20Trigger%201"); + build_one_smart_event("c_name00040000", "Open%20HTTP%20Post%20Service%201"); + build_one_smart_event("c_time00040000", "1,10500,0,0,1"); + build_one_smart_event("c_trigger00040000", "digital_in/0/0/8/1/0"); + build_one_smart_event("c_schedule00040000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); + build_one_smart_event("c_action00040000", "post/0/0/active/0/0/0"); + + curl_easy_reset(g_curl_handle_set_smart_event); + + g_curl_handle_set_gpio = g_http_handle; + + build_one_gpio("name0", "Digital_Trigger_Post"); + build_one_gpio("server0", "localhost"); + build_one_gpio("server_port0", accountData[0].account_aida_port); + build_one_gpio("account0", accountData[0].account_username); + build_one_gpio("password0", accountData[0].account_password); + build_one_gpio("url0", "/control?alarm.gpio=1"); + build_one_gpio("content0", "lilinstarthttpget"); + + curl_easy_reset(g_curl_handle_set_gpio); + pthread_mutex_unlock(&mutex_curl); +#endif + } + pthread_exit(NULL); +} + +CURL* g_curl_handle_set_tof_basic = NULL; +void build_one_set_for_tof_basic(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/tof?image."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_tof_basic) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_set_tof_basic); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + + curl_easy_reset(g_curl_handle_set_tof_basic); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_set_tof_basic(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("tof_basic"); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_set_tof_basic = g_http_handle; // Initialization for each handler. + + build_one_set_for_tof_basic("mode", "1"); + + curl_easy_reset(g_curl_handle_set_tof_basic); + //g_curl_handle_set_tof_basic = NULL; + pthread_mutex_unlock(&mutex_curl); + pthread_exit(NULL); +} + +CURL* g_curl_handle_set_quality_basic = NULL; +void build_one_set_for_quality_basic(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/image?image."; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_set_quality_basic) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_LIMIT, 1L); + + +#ifdef GY_OS_NOVA + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_set_quality_basic); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + else { + if (strcmp(myname, "flip") == 0) { + strcpy(accountData[0].account_flip, myvalue); + } + else if (strcmp(myname, "mirror") == 0) { + strcpy(accountData[0].account_mirror, myvalue); + } + else if (strcmp(myname, "rotate") == 0) { + strcpy(accountData[0].account_rotate, myvalue); + } + } + + curl_easy_reset(g_curl_handle_set_quality_basic); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_set_quality_basic(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("set_qual"); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_set_quality_basic = g_http_handle; // Initialization for each handler. + + build_one_set_for_quality_basic("3dnrday", "0"); + build_one_set_for_quality_basic("3dnrnight", "0"); + build_one_set_for_quality_basic("sharpnessday", "0"); + build_one_set_for_quality_basic("sharpnessnight", "0"); + + curl_easy_reset(g_curl_handle_set_quality_basic); + //g_curl_handle_set_quality_basic = NULL; + pthread_mutex_unlock(&mutex_curl); + pthread_exit(NULL); + +} + +void sync_image_rotation_thread() { + //pthread_detach(pthread_self()); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_set_quality_basic = g_http_handle; + + if (strcmp(accountData[0].account_flip, "1") == 0){ + build_one_set_for_quality_basic("flip", "0"); + usSleep(50000); + } + + if (strcmp(accountData[0].account_mirror, "1") == 0){ + build_one_set_for_quality_basic("mirror", "0"); + usSleep(50000); + } + + if (strcmp(accountData[0].account_rotate, "1") == 0){ + build_one_set_for_quality_basic("rotate", "0"); + usSleep(50000); + } + + curl_easy_reset(g_curl_handle_set_quality_basic); + //g_curl_handle_set_quality_basic = NULL; + pthread_mutex_unlock(&mutex_curl); + //pthread_exit(NULL); +} + +//CURL* g_curl_handle_system_time = NULL; +size_t get_system_time_from_ipcam(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + pthread_mutex_lock(&mutex_curl); + //printf("\n-----get_system_time_from_ipcam start\n"); + //g_curl_handle_system_time = curl_easy_init(); // Initialization for each handler. + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/system?get=server"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[get service from ipcam]cmd: %s\n", cmd); + + if (g_http_handle) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); +#ifdef GY_OS_NOVA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); +#endif + +#ifdef GY_OS_AMBA + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); +#endif + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); + if (res_service_from_ipcam != CURLE_OK) // Check for errors + { + fprintf(stderr, "[get service from ipcam] Failed to initialize the CURL handler for service from ipcam. #2 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_http_handle); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[get service from ipcam] CURL failed to initialize!\n"); + } + + //curl_easy_cleanup(g_curl_handle_system_time); + //g_curl_handle_system_time = NULL; + //printf("\n-----get_system_time_from_ipcam end\n"); + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); + return response_size; +} + +CURL* g_curl_handle_resolution_changed = NULL; +size_t build_resolution_changed(char * response_from_ipcam) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + size_t response_size = 0; + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/get_sencode_info"; + //char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + //strcat(cmd, myname); + //strcat(cmd, cmd5); + //strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_resolution_changed) + { + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_WRITEDATA, ptr_responded_msg); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_resolution_changed); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build resolution changed] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + else { + strcpy(response_from_ipcam, ptr_responded_msg->memory); + response_size = ptr_responded_msg->size; + } + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + curl_easy_reset(g_curl_handle_resolution_changed); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build resolution changed] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif + + return response_size; +} + +int g_check_if_different_width_or_height = 0; +void write_to_stream_width_and_stream_height(int stream_width,int stream_height) { + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char streamPATH[1024] = { 0 }; + strcpy(streamPATH, exePath); + strcat(streamPATH, "stream.json"); + + char stream_bakPATH[1024] = { 0 }; + strcpy(stream_bakPATH, exePath); + strcat(stream_bakPATH, "stream_bak.json"); + + char *filename_stream = streamPATH; + if (!FileExist(filename_stream) && !FileExist(stream_bakPATH)) + { + //printf("%s doesn't exist.\n", filename_stream); + + FILE *fp; + char JsonString[512] = { 0 }; + sprintf(JsonString,"{\"stream_width\":%d,\"stream_height\":%d}", stream_width, stream_height); + + if ((fp = fopen(filename_stream, "w+")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(streamPATH, stream_bakPATH); + } + else + { + printf("Fail to open stream.json #1\n"); + } + } + else + { + if ((!FileExist(streamPATH)) && FileExist(stream_bakPATH)) { + CopyFileTo(stream_bakPATH, streamPATH); + } + + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_stream = ReadAllBytes(filename_stream); + if (fileBuf_stream) { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_stream); + if (fileBuf_stream) { + free(fileBuf_stream); + fileBuf_stream = NULL; + } + + if (root == NULL) + { + printf("root_stream is NULL\n"); + } + else + { + cJSON *cjson_stream_width,*cjson_stream_height; + + cjson_stream_width = cJSON_GetObjectItem(root, "stream_width"); + cjson_stream_height = cJSON_GetObjectItem(root, "stream_height"); + + if (cjson_stream_width) { + if ((int)cjson_stream_width->valueint != stream_width) { + g_check_if_different_width_or_height = 1; + if (cjson_stream_width) { + cJSON_ReplaceItemInObject(root, "stream_width", cJSON_CreateNumber(stream_width)); + } + } + } + + if (cjson_stream_height) { + if ((int)cjson_stream_height->valueint != stream_height) { + g_check_if_different_width_or_height = 1; + if (cjson_stream_height) { + cJSON_ReplaceItemInObject(root, "stream_height", cJSON_CreateNumber(stream_height)); + } + } + } + + if (g_check_if_different_width_or_height == 1) { + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_stream, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + CopyFileTo(streamPATH, stream_bakPATH); + } + else + { + printf("Fail to open stream.json #2\n"); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } +} + +int get_g_check_if_different_width_or_height() { + return g_check_if_different_width_or_height; +} + +void* auto_resolution_changed(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("resolu"); + char sOutputResponse[MEMORY_SIZE] = { 0 }; + + int try_check_count = 0; + do{ + pthread_mutex_lock(&mutex_curl); + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + g_curl_handle_resolution_changed = g_http_handle; // Initialization for each handler. + + memset(sOutputResponse,0x00, MEMORY_SIZE); + int get_size = (int)build_resolution_changed(sOutputResponse); +#ifdef GY_OS_V_SERIES + int check_reboot = 0; +#endif + if (get_size >= 1) { + //printf("\n-----------sOutputResponse:%s\n", sOutputResponse); + char *stream_w = strstr(sOutputResponse, "<width>"); + char *stream_h = strstr(sOutputResponse, "<height>"); + + if (stream_w != NULL && stream_h != NULL){ + + char *stream_w_end = strstr(stream_w, "</width>"); + char *stream_h_end = strstr(stream_h, "</height>"); + if(stream_w_end != NULL && stream_w_end - stream_w - 7 >= 1 && + stream_h_end != NULL && stream_h_end - stream_h - 8 >= 1){ + char stream_width[25] = { 0 }; + memcpy(stream_width, stream_w + 7 , stream_w_end - stream_w - 7); + char stream_height[25] = { 0 }; + memcpy(stream_height, stream_h + 8, stream_h_end - stream_h - 8); + + int current_stream_width = atoi(stream_width); + int current_stream_height = atoi(stream_height); + + //printf("\n--------%d,%d\n", current_stream_width, current_stream_height); + write_to_stream_width_and_stream_height(current_stream_width, current_stream_height); + + if (g_check_if_different_width_or_height == 1) { +#ifdef GY_OS_V_SERIES + check_reboot = 1; +#endif + } + else { + try_check_count++; + } + } + } + + char *stream_encoder1 = strstr(sOutputResponse, "<stream>"); + if (stream_encoder1) { + char temp_stream_encoder1[2048] = { 0 }; + memcpy(temp_stream_encoder1, stream_encoder1 + 8, strlen(stream_encoder1) - 8); + char *stream_encoder2 = strstr(temp_stream_encoder1, "<stream>"); + if (stream_encoder2) { + char temp_stream_encoder2[2048] = { 0 }; + memcpy(temp_stream_encoder2, stream_encoder2 + 8, strlen(stream_encoder2) - 8); + char *stream_encoder3 = strstr(temp_stream_encoder2, "<stream>"); + if (stream_encoder3) { + char temp_stream_encoder3[2048] = { 0 }; + memcpy(temp_stream_encoder3, stream_encoder3 + 8, strlen(stream_encoder2) - 8); + char *stream_h264_gop = strstr(temp_stream_encoder3, "<h264_gop>"); + if (stream_h264_gop) { + char *stream_h264_gop_end = strstr(stream_h264_gop, "</h264_gop>"); + if (stream_h264_gop_end != NULL && stream_h264_gop_end - stream_h264_gop - 10 >= 1) { + char stream_gop[25] = { 0 }; + memcpy(stream_gop, stream_h264_gop + 10, stream_h264_gop_end - stream_h264_gop - 10); + int current_stream_gop = atoi(stream_gop); + g_check_h264_gop = current_stream_gop; + } + } + } + } + } + + } + curl_easy_reset(g_curl_handle_resolution_changed); + //g_curl_handle_resolution_changed = NULL; + pthread_mutex_unlock(&mutex_curl); + +#ifdef GY_OS_V_SERIES + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "different width or height"); + write_to_logs_html(temp_msg, "auto resolution changed", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "auto resolution changed", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } + } +#else + +#endif + + if (try_check_count >= 10) + break; + usSleep(10000000); + } while (bHttpServerMainStart); + + pthread_exit(NULL); + +} +#ifdef GY_OS_AMBA +int run_check_current_resolution = -1; + +void set_run_check_current_resolution(int set_value) { + run_check_current_resolution = set_value; +} + +int get_run_check_current_resolution() { + return run_check_current_resolution; +} + +void* check_current_resolution(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("check_resolu"); + set_record_process_note("resol_start"); + if (run_check_current_resolution == 0) { + run_check_current_resolution = 1; + int compared_width = 1920; + int compared_height = 1080; + + char sOutputResponse[MEMORY_SIZE] = { 0 }; + + int try_check_count = 0; + do { + pthread_mutex_lock(&mutex_curl); + g_curl_handle_resolution_changed = g_http_handle; // Initialization for each handler. + + memset(sOutputResponse, 0x00, MEMORY_SIZE); + int get_size = (int)build_resolution_changed(sOutputResponse); + if (get_size >= 1) { + //printf("\n-----------sOutputResponse:%s\n", sOutputResponse); + char *stream_w = strstr(sOutputResponse, "<width>"); + char *stream_h = strstr(sOutputResponse, "<height>"); + + if (stream_w != NULL && stream_h != NULL) { + + char *stream_w_end = strstr(stream_w, "</width>"); + char *stream_h_end = strstr(stream_h, "</height>"); + if (stream_w_end != NULL && stream_w_end - stream_w - 7 >= 1 && + stream_h_end != NULL && stream_h_end - stream_h - 8 >= 1) { + char stream_width[25] = { 0 }; + memcpy(stream_width, stream_w + 7, stream_w_end - stream_w - 7); + char stream_height[25] = { 0 }; + memcpy(stream_height, stream_h + 8, stream_h_end - stream_h - 8); + + int current_stream_width = atoi(stream_width); + int current_stream_height = atoi(stream_height); + + if (current_stream_width > compared_width || current_stream_height > compared_height) { + g_check_current_resolution = 0; + } + else { + try_check_count++; + } + } + } + + char *stream_encoder1 = strstr(sOutputResponse, "<stream>"); + if (stream_encoder1) { + char temp_stream_encoder1[2048] = { 0 }; + memcpy(temp_stream_encoder1, stream_encoder1 + 8, strlen(stream_encoder1) - 8); + char *stream_encoder2 = strstr(temp_stream_encoder1, "<stream>"); + if (stream_encoder2) { + char temp_stream_encoder2[2048] = { 0 }; + memcpy(temp_stream_encoder2, stream_encoder2 + 8, strlen(stream_encoder2) - 8); + char *stream_encoder3 = strstr(temp_stream_encoder2, "<stream>"); + if (stream_encoder3) { + char temp_stream_encoder3[2048] = { 0 }; + memcpy(temp_stream_encoder3, stream_encoder3 + 8, strlen(stream_encoder3) - 8); + char *stream_encoder4 = strstr(temp_stream_encoder3, "<stream>"); + if (stream_encoder4) { + char temp_stream_encoder4[2048] = { 0 }; + memcpy(temp_stream_encoder4, stream_encoder4 + 8, strlen(stream_encoder4) - 8); + char *stream_h264_gop = strstr(temp_stream_encoder4, "<h264_gop>"); + if (stream_h264_gop) { + char *stream_h264_gop_end = strstr(stream_h264_gop, "</h264_gop>"); + if (stream_h264_gop_end != NULL && stream_h264_gop_end - stream_h264_gop - 10 >= 1) { + char stream_gop[25] = { 0 }; + memcpy(stream_gop, stream_h264_gop + 10, stream_h264_gop_end - stream_h264_gop - 10); + int current_stream_gop = atoi(stream_gop); + g_check_h264_gop = current_stream_gop; + } + } + } + } + } + } + } + curl_easy_reset(g_curl_handle_resolution_changed); + //g_curl_handle_resolution_changed = NULL; + pthread_mutex_unlock(&mutex_curl); + + if (try_check_count >= 10) + break; + usSleep(10000000); + } while (bHttpServerMainStart); + run_check_current_resolution = -1; + } + set_record_process_note("resol_start"); + pthread_exit(NULL); +} +#endif +CURL* g_curl_handle_getfeatures = NULL; +int g_check_if_OK_getfeatures = 1; +void ipcam_getfeatures() { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/system?get=features"; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + pthread_mutex_lock(&mutex_curl); + g_curl_handle_getfeatures = g_http_handle; + if (g_curl_handle_getfeatures) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + struct MemoryStruct temp_msg; + struct MemoryStruct* ptr_responded_msg = &temp_msg; + ptr_responded_msg->size = 0; + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_WRITEDATA, ptr_responded_msg); + + CURLcode res_getfeatures = curl_easy_perform(g_curl_handle_getfeatures); + if (res_getfeatures != CURLE_OK) // Check for errors + { + fprintf(stderr, "[ipcam getfeatures] Failed to initialize the CURL handler. Reason: %s\n", curl_easy_strerror(res_getfeatures)); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "[ipcam getfeatures] Failed to initialize the CURL handler. Reason: %s", curl_easy_strerror(res_getfeatures)); + write_to_logs_html(temp_msg, "ipcam_getfeatures", "ERROR", SystemSetting.enable_system_logs); + } + else { + if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { + if (strstr(ptr_responded_msg->memory,"98529ab")!=NULL) { + char temp_msg[8192] = { 0 }; + strcpy(temp_msg, "The camera doesn't support car plate."); + write_to_logs_html(temp_msg, "ipcam_getfeatures", "INFO", SystemSetting.enable_system_logs); + g_check_if_OK_getfeatures = 0; + } + + if (strstr(ptr_responded_msg->memory, "FEATURE_SYS_CAPTURE_EFR=1") != NULL) { + //char temp_msg[8192] = { 0 }; + //strcpy(temp_msg, "The camera support thermal."); + //write_to_logs_html(temp_msg, "ipcam_getfeatures", "INFO", SystemSetting.enable_system_logs); + g_check_if_OK_thermal = 1; + } + } + } + + curl_easy_reset(g_curl_handle_getfeatures); + if (pList != NULL) + curl_slist_free_all(pList); + + ptr_responded_msg->size = 0; + } + else + { + printf("[ipcam getfeatures] CURL failed to initialize!\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", "[ipcam getfeatures] CURL failed to initialize!"); + write_to_logs_html(temp_msg, "ipcam_getfeatures", "ERROR", SystemSetting.enable_system_logs); + } + + //curl_easy_cleanup(g_curl_handle_getfeatures); + //g_curl_handle_getfeatures = NULL; + pthread_mutex_unlock(&mutex_curl); + usSleep(20000); +} + +CURL* g_curl_handle_reboot = NULL; +void build_reboot(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/maintenance?"; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_reboot) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_reboot, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_reboot, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_reboot); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + + curl_easy_reset(g_curl_handle_reboot); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_reboot(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("reboot"); + do{ + pthread_mutex_lock(&mutex_curl); + g_curl_handle_reboot = g_http_handle; // Initialization for each handler. + + build_reboot("reboot", "1"); + + curl_easy_reset(g_curl_handle_reboot); + //g_curl_handle_reboot = NULL; + pthread_mutex_unlock(&mutex_curl); + + usSleep(1000000); + } while (bHttpServerMainStart); + + pthread_exit(NULL); + +} + +CURL* g_curl_handle_system = NULL; +void build_system(char * myname, char * myvalue) { + //printf("\nname: %s\n", myname); + //printf("\nvalue: %s\n", myvalue); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + + //char cmd1[256] = "curl http://"; + char cmd1[256] = "http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" + char cmd4[256] = "/system?"; + char cmd5[256] = "="; + + //curl http://:d@192.168.3.57:81/event?event.event0000=1 + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, myname); + strcat(cmd, cmd5); + strcat(cmd, myvalue); + + + //printf("\n[setsmartevent]cmd: %s\n", cmd); + +# if 0 + FILE* pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#else + + if (g_curl_handle_system) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(g_curl_handle_system, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(g_curl_handle_system, CURLOPT_URL, cmd); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(g_curl_handle_system, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(g_curl_handle_system, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(g_curl_handle_system, CURLOPT_PORT, port_num); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(g_curl_handle_system, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(g_curl_handle_system, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_handle_system, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(g_curl_handle_system, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_handle_system, CURLOPT_LOW_SPEED_TIME, 1L); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_curl_handle_system, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_system); + if (res_quality_basic != CURLE_OK) // Check for errors + { + fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); + } + + curl_easy_reset(g_curl_handle_system); + if (pList != NULL) + curl_slist_free_all(pList); + } + else + { + printf("[build one set for quality basic] CURL failed to initialize!\n"); + } + + usSleep(20000); +#endif +} + +void* auto_system(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("osd_system"); + //do + { + pthread_mutex_lock(&mutex_curl); + g_curl_handle_system = g_http_handle; // Initialization for each handler. + + build_system("osd.font", "0"); + build_system("osd.time", "0"); + build_system("osd.status", "0"); + + curl_easy_reset(g_curl_handle_system); + //g_curl_handle_system = NULL; + pthread_mutex_unlock(&mutex_curl); + } + //while (bHttpServerMainStart); + + pthread_exit(NULL); + +} + +#if 0 +void GetAidaPort(){ + //printf("\nGetAidaPort 1\n"); + char filename[1024] = {0}; + strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("\nGetAidaPort 1-2\n"); + char* fileBuf = ReadAllBytes(filename); + + if (fileBuf) { + cJSON *plugin, *aida_port; + //printf("\nGetAidaPort 2\n"); + plugin = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + //printf("\nGetAidaPort 3\n"); + if (plugin != NULL) { + //printf("config.json parse OK.\n"); + aida_port = cJSON_GetObjectItem(plugin, "port"); + strcpy(accountData[0].account_aida_port, aida_port->valuestring); + //printf("\nKKKKKKK:%s\n", accountData[0].account_aida_port); + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } +} + +#endif + +#define TIME_ZONE_NUMBER 32 +//char g_time_zone_text[TIME_ZONE_NUMBER][10] = { "UTC","GMT","BST","IST","WET","WEST","CET","CEST","EET","EEST","MSK","MSD","AST","ADT","NST","NDT","EST","EDT","CST","CDT","MST","MDT","PST","PDT","HST","AKST","AKDT","AEST","AEDT","ACST","ACDT","AWST" }; +//float g_time_zone_number[TIME_ZONE_NUMBER] = { 0,0,1,1,0,1,1,2,2,3,3,4,-4,-3,-3.5,-2.5,-5,-4,-6,-5,-7,-6,-8,-7,-10,-9,-8,10,11,9.5,10.5,8 }; + +int get_timezone_info(char *time_zone_buf) +{ + int timeZone = 0; + + +#if 0 + char *findPos = NULL; + if (strstr(sOutputResponse, "+") != NULL) + { + } + else if (strstr(sOutputResponse, "-") != NULL) + { + } + else + { + for (int i = 0; i < TIME_ZONE_NUMBER; i++) + { + if (strcmp(sOutputResponse, g_time_zone_text[i]) != 0) + { + + break; + } + } + } +#endif + return timeZone; +} + +void update_system_time() { + char sOutputResponse[MEMORY_SIZE] = { 0 }; + char SystemTimeText[8192] = { 0 }; + //char SystemTimeText_withzone[8192] = { 0 }; + + int get_size = (int)get_system_time_from_ipcam(sOutputResponse); + + //printf("get size = %d \n, %s \n", get_size, sOutputResponse); + + if (get_size >= 1) { + sOutputResponse[get_size] = '\0'; + char *findPos = NULL; + findPos = strstr(sOutputResponse, "time="); + //char *findPosB = NULL; + //findPosB = strstr(sOutputResponse, "model="); + + if (findPos != NULL + && strlen(findPos) >= 24 + //& findPosB != NULL + ) //time=2022/12/02 14:37:23 + { + //int time_str_len = findPosB - (findPos + 5); + //memcpy(SystemTimeText_withzone, findPos + 5, time_str_len); //+19 + //printf("get sys time zone text= %s \n", SystemTimeText); + + //int iTimeZone = get_timezone_info(SystemTimeText_withzone); + + memcpy(SystemTimeText, findPos + 5, 19); //+19 + //printf("get sys time text= %s \n", SystemTimeText); + + int count_digit = 0; + for (int i = 0; i < strlen(SystemTimeText); i++) { + if (isdigit(SystemTimeText[i])) + { + count_digit++; + } + } + + if (count_digit == 14) { + struct tm tm_val; + time_t epoch = 0; + + //strptime + int r; + r = sscanf(SystemTimeText, "%d/%d/%d %d:%d:%d", &tm_val.tm_year, &tm_val.tm_mon, &tm_val.tm_mday, &tm_val.tm_hour, &tm_val.tm_min, &tm_val.tm_sec); + + if (r != 6) { + printf("expected %d numbers scanned in %s\n", r, SystemTimeText); + //char* defaultdata = "1900-01-01 01:01:01"; + } + + epoch = strptime_s(&tm_val); + //strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + //epoch = mktime(&tm_val); + //printf("get sys time stamp = %d \n", epoch); + //printf("\n-----g_osdSysTimeStamp:%ld,time(0):%ld\n", g_osdSysTimeStamp, time(0)); + + + if (epoch > time(0) && difftime(epoch, time(0)) >= 3540 && difftime(epoch, time(0)) <= 3660) { + g_osdSysTimeStamp = time(0); + } + else if (epoch < time(0) && difftime(time(0), epoch) >= 3540 && difftime(time(0), epoch) <= 3660) { + g_osdSysTimeStamp = time(0); + } + else{ + g_osdSysTimeStamp = epoch; + } + + //get gmt+0 time + time_t t, gmt_t; + struct tm *gmt; + t = time(NULL); + gmt = gmtime(&t); + gmt_t = mktime(gmt); + + int iTimeZone = 0; + + iTimeZone = epoch - gmt_t; + + g_osdSysTimeZoneInfo = iTimeZone; + + /*if (tm_val.tm_mday == gmt->tm_mday) + { + iTimeZone = tm_val.tm_hour - gmt->tm_hour; + } + else + { + if (tm_val.tm_mday > gmt->tm_mday) + { + iTimeZone = (24 + tm_val.tm_hour) - gmt->tm_hour; + } + else + { + iTimeZone = tm_val.tm_hour - (24 + gmt->tm_hour); + } + }*/ + + //printf("Time Zone info = %d \n", iTimeZone); + + + + //struct tm *tm_local; + //tm_local = localtime(&epoch); + //printf("time = %d-%d-%d %d:%d:%d \n", tm_local->tm_year+1900, tm_local->tm_mon+1, tm_local->tm_mday, tm_local->tm_hour, tm_local->tm_min, tm_local->tm_sec); + } + } + } +} + +void copy_control_io_to_gynet() { + char my_response[MEMORY_SIZE] = { 0 }; + int my_size = 0; + + int count_row = 0; + char data_service[MAX_SERVICE_SIZE][STRSPLIT_SIZE] = { 0 }; + + const char *del = "\n"; + const char *del2 = "="; + + char data_service_pair[MAX_SERVICE_SIZE][2][STRSPLIT_SIZE] = { 0 }; + //int data_service_pair_num[MAX_SERVICE_SIZE] = { 0 }; + + my_size = (int)get_control_io_from_ipcam(my_response); + + if (my_size >= 1) { + my_response[my_size] = '\0'; + + count_row = StrSplit(my_response, data_service, del); + //printf("\n------UU:21\n"); + + //int i_temp = -1; + + for (int i = 0; i < count_row; i++) + { + if (strlen(data_service[i]) >= 1) + { + /*data_service_pair_num[i] = + */ + StrSplit(data_service[i], data_service_pair[i], del2); + //printf("\n------UU:22\n"); + + + if (strcmp(data_service_pair[i][0], "alarm_input0") == 0) { + if (atoi(data_service_pair[i][1]) == 0) { + set_g_control_alarm_gpio_to_zero(); + } + else if(atoi(data_service_pair[i][1]) == 1){ + set_g_control_alarm_gpio_to_one(); + } + break; + } + } + } + } +} + +void copy_ipcam_smtp_service_to_gynet() { + char my_response[MEMORY_SIZE] = { 0 }; + int my_size = 0; + + int count_row = 0; + char data_service[MAX_SERVICE_SIZE][STRSPLIT_SIZE]={0}; + + const char *del = "\n"; + const char *del2 = "="; + + char data_service_pair[MAX_SERVICE_SIZE][2][STRSPLIT_SIZE]={0}; + //int data_service_pair_num[MAX_SERVICE_SIZE] = { 0 }; + + my_size = (int)get_service_from_ipcam(my_response); + + if (my_size >= 1) { + my_response[my_size] = '\0'; + + count_row = StrSplit(my_response, data_service, del); + //printf("\n------UU:21\n"); + + //int i_temp = -1; + + for (int i = 0; i < count_row; i++) + { + if (strlen(data_service[i]) >= 1) + { + /*data_service_pair_num[i] = + */ + StrSplit(data_service[i], data_service_pair[i], del2); + //printf("\n------UU:22\n"); + + if (strcmp(data_service_pair[i][0], "smtp.receiver0") == 0) { + strcpy(IPCAMService.email_address1, data_service_pair[i][1]); + IPCAMService.email_address1[strlen(IPCAMService.email_address1) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver1") == 0) { + strcpy(IPCAMService.email_address2, data_service_pair[i][1]); + IPCAMService.email_address2[strlen(IPCAMService.email_address2) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver2") == 0) { + strcpy(IPCAMService.email_address3, data_service_pair[i][1]); + IPCAMService.email_address3[strlen(IPCAMService.email_address3) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver3") == 0) { + strcpy(IPCAMService.email_address4, data_service_pair[i][1]); + IPCAMService.email_address4[strlen(IPCAMService.email_address4) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.receiver4") == 0) { + strcpy(IPCAMService.email_address5, data_service_pair[i][1]); + IPCAMService.email_address5[strlen(IPCAMService.email_address5) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.address") == 0) { + strcpy(IPCAMService.email_address, data_service_pair[i][1]); + IPCAMService.email_address[strlen(IPCAMService.email_address) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.server") == 0) { + strcpy(IPCAMService.smtp_server, data_service_pair[i][1]); + IPCAMService.smtp_server[strlen(IPCAMService.smtp_server) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.auth_mode") == 0) { + IPCAMService.smtp_auth_mode = atoi(data_service_pair[i][1]); + } + else if (strcmp(data_service_pair[i][0], "smtp.port") == 0) { + strcpy(IPCAMService.smtp_port, data_service_pair[i][1]); + IPCAMService.smtp_port[strlen(IPCAMService.smtp_port) - 1] = '\0'; + } + else if (strcmp(data_service_pair[i][0], "smtp.auth") == 0) { + IPCAMService.smtp_auth = atoi(data_service_pair[i][1]); + } + else if (strcmp(data_service_pair[i][0], "smtp.account") == 0) { + strcpy(IPCAMService.auth_account, data_service_pair[i][1]); + IPCAMService.auth_account[strlen(IPCAMService.auth_account) - 1] = '\0'; + } + } + } + /* + printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT start\n"); + printf("\nemail_address1:%s\n", IPCAMService.email_address1); + printf("\nemail_address2:%s\n", IPCAMService.email_address2); + printf("\nemail_address3:%s\n", IPCAMService.email_address3); + printf("\nemail_address4:%s\n", IPCAMService.email_address4); + printf("\nemail_address5:%s\n", IPCAMService.email_address5); + printf("\nemail_address:%s\n", IPCAMService.email_address); + printf("\nsmtp_server:%s\n", IPCAMService.smtp_server); + printf("\nsmtp_auth_mode:%d\n", IPCAMService.smtp_auth_mode); + printf("\nsmtp_port:%s\n", IPCAMService.smtp_port); + printf("\nsmtp_auth:%d\n", IPCAMService.smtp_auth); + printf("\nauth_account:%s\n", IPCAMService.auth_account); + + printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT end\n");*/ + } +} +#ifdef GY_OS_AMBA +void sync_other_camera_lpr_db() { + + char lpr_db_url[8192] = { 0 }; + + strcpy(lpr_db_url, "http://"); + + if (strlen(SystemSetting.external_lpr_db_username) >= 1 && strlen(SystemSetting.external_lpr_db_password) >= 1) { + strcat(lpr_db_url, SystemSetting.external_lpr_db_username); + strcat(lpr_db_url, ":"); + strcat(lpr_db_url, SystemSetting.external_lpr_db_password); + strcat(lpr_db_url, "@"); + } + + if (strcmp(SystemSetting.external_lpr_db_IP, "127.0.0.1") != 0 && strcmp(SystemSetting.external_lpr_db_IP, "localhost") != 0) { + strcat(lpr_db_url, SystemSetting.external_lpr_db_IP); + } + else { + strcpy(SystemSetting.external_lpr_db_IP, "127.0.0.1"); + strcat(lpr_db_url, SystemSetting.external_lpr_db_IP); + } + + if (strlen(SystemSetting.external_lpr_db_port) >= 1) { + strcat(lpr_db_url, ":"); + strcat(lpr_db_url, SystemSetting.external_lpr_db_port); + } + + strcat(lpr_db_url, "/Aida_data/db_fflpr.db"); + + printf("Http lpr_db_url: %s \n", lpr_db_url); + + strcpy(g_stCURL_lpr_db_url, lpr_db_url); + strcpy(g_stCURL_lpr_db_username, SystemSetting.external_lpr_db_username); + strcpy(g_stCURL_lpr_db_password, SystemSetting.external_lpr_db_password); + strcpy(g_stCURL_lpr_db_port, SystemSetting.external_lpr_db_port); + + pthread_t curl_lpr_db_thread_id; + if (pthread_create(&curl_lpr_db_thread_id, 0, net_curl_https_get_other_lpr_db, NULL)) + { + printf("create curl lpr db thread faile \n"); + } +} +#endif +void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, char* contentBuffer/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType, int* isGetalarmMotion, int sock_info_idx) +{ + + //printf("----------------------------[web process]recvBuffer: %s\n",recvBuffer); + int j = 0, buflen = 0, len = 0, /*bIsContent = 0,*/ bIsMultipart = 0; + long idx = 0, nTotalContentLen = 0; + //long nbytes = 0, nTotalBytes = 0, nContentLen = 0; + char* fstr, * ContentStart; + char msg[MAX_MSG_LEN] = {0}; + char sendBuffer[BUFSIZE_V2] = { 0 }; + char beforeSendBuffer[BUFSIZE_V2] = { 0 }; + char headerBuffer[BUFSIZE_V2] = { 0 }; + char firstBuffer[BUFSIZE_V2] = { 0 }; + char urlBuffer[BUFSIZE_V2] = { 0 }; + char httpCommand[8] = { 0 }; + + //char OriAttribute[512] = { 0 };//512 + char tempBuffer[BUFSIZE_V2] = { 0 }; + char out[MAX_MSG_LEN] = { 0 }; + char multiPartBoundary[MAX_MSG_LEN] = { 0 }; + char contentDescription[MAX_MSG_LEN] = { 0 }; + SOCKET cli_socket = *client_socket; + int tracking_channel = MAX_AI_ENGINE_VIEW; + int tracking_channel_idx = MAX_AI_ENGINE_VIEW - 1; +#if defined GY_OS_AMBA + int AIImage_width = 1920; + int AIImage_height = 1080; +#endif + /* read the web browser request through the TCP connection */ + //memset(recvBuffer, 0x00, sizeof(recvBuffer)); + //memset(sendBuffer, 0x00, sizeof(sendBuffer)); + //memset(headerBuffer, 0x00, sizeof(headerBuffer)); + //memset(httpCommand , 0x00, sizeof(httpCommand)); + //printf("\n------------recvBuffer:%s\n", recvBuffer); + + //printf("\n[web process]start\n"); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + +//#ifdef _DEBUG_AMBA + //printf("\n(%d) [web process] Program binary path is: %s\n", cli_socket,buf); + //printf("\n(%d) [web process] mac_address: %s\n", cli_socket, mac_address); +//#endif + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024]; + char config_bakPATH[1024]; + char eventsPATH[1024]; + char events_bakPATH[1024]; + + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcpy(eventsPATH, exePath); + strcpy(events_bakPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(config_bakPATH, "config_bak.json"); + strcat(eventsPATH, "events.json"); + strcat(events_bakPATH, "events_bak.json"); + + clock_t t1 = clock(); + + if (strncmp(recvBuffer, "GET ", strlen("GET ")) == 0 || strncmp(recvBuffer, "get ", strlen("get ")) == 0) + memcpy(httpCommand, recvBuffer, strlen("GET ")); + else if (strncmp(recvBuffer, "POST ", strlen("POST ")) == 0 || strncmp(recvBuffer, "post ", strlen("post ")) == 0) + memcpy(httpCommand, recvBuffer, strlen("POST ")); + else + { + sprintf(msg, "Only simple GET and POST method is supported."); + printf(msg); + //syslog(NW_SORRY, msg, recvBuffer, cli_socket); + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #17\n"); + //printf("\n[web process]-1: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + //syslog(NW_LOG, "request", httpCommand, hit); + //printf("\n[web process]start 2\n"); + if (strcmp(httpCommand, "GET ") == 0 || strcmp(httpCommand, "POST ") == 0) + { + ContentStart = FindHttpContentStart(recvBuffer); + if (ContentStart) + { + memcpy(headerBuffer, recvBuffer, ContentStart - recvBuffer); + //DumpCharacters(headerBuffer, nTotalBytes + ContentStart - recvBuffer); + memcpy(contentBuffer, ContentStart, recvBuffer + recv_buff_size - ContentStart); + //printf("contentBuffer=%s", contentBuffer); + //DumpCharacters(contentBuffer, 8192); + //nContentLen = (recvBuffer + nbytes - ContentStart); + + if (strcmp(httpCommand, "POST ") == 0) + { + //char delim[2] = "HT"; + char *start = headerBuffer; + char *pDelim; + do + { + pDelim = strstr(start, "\r\n"); + // string between start and delim (or end of string if delim is NULL). + if (pDelim) + { + char attribute[512] = { 0 };//512 + memcpy(attribute, start, pDelim - start); + attribute[pDelim - start] = 0; + char att_var[10][STRSPLIT_SIZE]={0}; + char *del = ":"; + + if ((pDelim - start) >= 1) + { + if (strstr(attribute, "Content-Length") != NULL) { + //printf("\n------UU:23-1\n"); + StrSplit(attribute, att_var, del); + if (strcmp(att_var[0], "Content-Length") == 0) + { + nTotalContentLen = atoi(att_var[1]); + //printf("Content-Length %d:%d\n", cli_socket, nTotalContentLen); + } + } + else if (strstr(attribute, "Content-Type") != NULL) { + //printf("\n------UU:23-2\n"); + StrSplit(attribute, att_var, del); + if (strcmp(att_var[0], "Content-Type") == 0) + { + TrimSpace(out, sizeof(out), att_var[1], 0); + if (strncmp(MULTIPART_CONTENT, out, strlen(MULTIPART_CONTENT)) == 0) + { + bIsMultipart = 1; + strcat(multiPartBoundary, "--"); + strcat(multiPartBoundary, out + strlen(MULTIPART_CONTENT)); + } + } + } + else if (strstr(attribute, "Content-Description") != NULL) { + //printf("\n------UU:23-3\n"); + StrSplit(attribute, att_var, del); + if (strcmp(att_var[0], "Content-Description") == 0) + { + strcpy(contentDescription, att_var[1]); + char* channelNum = strstr(contentDescription, "-CH"); + if (channelNum) + { + channelNum = channelNum + strlen("-CH"); + tracking_channel = atoi(channelNum) /*+ 16*/; //1~16 reserved for AIEngine.exe. + tracking_channel_idx = tracking_channel; + } + else + { + channelNum = strstr(contentDescription, "CHANNEL") + strlen("CHANNEL"); + if (channelNum) + { + tracking_channel = atoi(channelNum); + tracking_channel_idx = tracking_channel - 1; + } + else + { + tracking_channel = MAX_TRACKING_NUM + 1; + tracking_channel_idx = MAX_TRACKING_NUM; + } + } + + char* jpegWidthNum = strstr(contentDescription, "width="); + if (jpegWidthNum) + { + jpegWidthNum = jpegWidthNum + strlen("width="); +#if defined GY_OS_AMBA + AIImage_width = atoi(jpegWidthNum); +#endif + } + + char* jpegHeightNum = strstr(contentDescription, "height="); + if (jpegHeightNum) + { + jpegHeightNum = jpegHeightNum + strlen("height="); +#if defined GY_OS_AMBA + AIImage_height = atoi(jpegHeightNum); +#endif + } + } + } + } + start = pDelim + 2; // Use length of your b string. + } + } + while (pDelim); + } + } + else + { + //printf("\n[web process]-2: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + printf("[web process] FindHttpContentStart returned error.\n"); + return; + } + } + //printf("\n[web process]start 3\n"); + //clock_t t2 = clock(); + //diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("parsing header time:%f\n", diff); + /* null-terminate after the second space to ignore extra stuff */ + + for (idx = strlen(httpCommand); idx < LINE_BUFSIZE; idx++) + { + if (headerBuffer[idx] == ' ') + { + /* string is "GET URL " +lots of other stuff */ + memcpy(urlBuffer, headerBuffer + strlen(httpCommand), idx - strlen(httpCommand)); + urlBuffer[idx - strlen(httpCommand)] = 0; + memcpy(firstBuffer, headerBuffer, idx); + firstBuffer[idx] = 0; + break; + } + } + +#if defined GY_OS_AMBA + //check /airelay + char *pch; + int newStrLen = 0; + pch = strstr(urlBuffer, "/airelay"); + if (pch != NULL) + { + if (pch == urlBuffer) + { + newStrLen = strlen(urlBuffer) - 8; + memcpy(urlBuffer, urlBuffer + 8, newStrLen); + urlBuffer[newStrLen] = 0; + } + } +#endif + + //printf("\n[web process]start 4\n"); + /* check for illegal parent directory use .. */ + for (j = 0; j < idx - 1 - strlen(httpCommand); j++) + { + if (urlBuffer[j] == '.' && urlBuffer[j + 1] == '.') + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Parent directory(..) path names not supported."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + //syslog(NW_SORRY, "Parent directory (..) path names not supported", firstBuffer, cli_socket); + //printf("\n(%d) [web process] Parent directory (..) path names not supported \n", cli_socket); + //printf("\n[web process]-3: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + } + //printf("\n[web process]start 5\n"); + char beforeSendBuffer_xtra[BUFSIZE * 60] = { 0 }; + + if (strlen(g_account_port_protected) == 0) { + strcpy(g_account_port_protected, accountData[0].account_port); + } + else { + if (strcmp(g_account_port_protected, accountData[0].account_port) != 0) { + memset(g_account_port_protected, 0x00, sizeof(g_account_port_protected)); + strcpy(g_account_port_protected, accountData[0].account_port); + } + } + //printf("\n[web process]start 6\n"); + // Analyze all HTTP requests + //printf("\n-------httpCommand:%s\n", httpCommand); + + if (strcmp(httpCommand, "GET ") == 0) + { +#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### sophia (%d) urlBuffer:%s start \n", cli_socket, cli_socket,urlBuffer); +#endif + + //printf("\n---------urlBuffer:%s\n", urlBuffer); + if (strcmp(urlBuffer, "/server") == 0) + { + //printf("\n[web process]start 7\n"); + + char Msg[256] = { 0 }; + strcpy(contentBuffer, "DeviceName=GYNet\r\n<br/>"); +#ifdef GY_OS_WIN + sprintf(Msg, "Version=%s\r\n", ProductVersion); +#elif defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "Version=%s\r\n", APP_VERSION); +#endif + strcat(contentBuffer, Msg); + strcat(contentBuffer, "Language="); + strcat(contentBuffer, SystemSetting.language); + strcat(contentBuffer, "\r\n<br/>"); +//#ifdef GY_OS_WIN + //sprintf(Msg, "SystemID=%s\r\n<br/>", mac_address); +//#elif defined GY_OS_AMBA || defined GY_OS_NOVA + //Get MAC Address + char fetch_mac_addr[30] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + GetMACAddress(fetch_mac_addr); + sprintf(Msg, "SystemID=%s\r\n<br/>", fetch_mac_addr); +//#endif + strcat(contentBuffer, Msg); + sprintf(Msg, "LicenseType=%s\r\n<br/>", strLicenseType); + strcat(contentBuffer, Msg); + sprintf(Msg, "Default=%s\r\n<br/>", heartbeatData.events_default_version); + strcat(contentBuffer, Msg); + + int check_input_key = 0; + + { + char buf_exe[1024] = {}; + readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); + + char exePath_temp[1024] = {}; + getFilePath(buf_exe, exePath_temp, 1024); + + char keyPATH[1024] = { 0 }; + strcpy(keyPATH, exePath_temp); + strcat(keyPATH, "key.txt"); + + char key_buff[1024] = { 0 };//creating char array to store data of file + + if (FileExist(keyPATH) == 1) { + + FILE *pFile; + if ((pFile = fopen(keyPATH, "r")) != NULL) + { + fscanf(pFile, "%s", key_buff); + fclose(pFile); + } + } + + if (strcmp(key_buff, strUnlockingKey)==0) { + check_input_key = 1; + } + } + + if (check_input_key == 1) + { + sprintf(Msg, "LicenseStatus=%s\r\n<br/>", strLicenseStatus); + strcat(contentBuffer, Msg); + sprintf(Msg, "UnlockingKey=%s\r\n<br/>", strUnlockingKey); + strcat(contentBuffer, Msg); + } + else { + sprintf(Msg, "LicenseStatus=%s\r\n<br/>", ""); + strcpy(strLicenseStatus,""); + strcat(contentBuffer, Msg); + sprintf(Msg, "UnlockingKey=%s\r\n<br/>", strUnlockingKey); + strcat(contentBuffer, Msg); + } + + /*else { + sprintf(Msg, "LicenseStatus=%s\r\n<br/>", "Fail to input key."); + strcpy(strLicenseStatus,"Fail to input key."); + strcat(contentBuffer, Msg); + sprintf(Msg, "UnlockingKey=%s\r\n<br/>", strUnlockingKey); + strcat(contentBuffer, Msg); + }*/ + + sprintf(Msg, "ModeName=%s\r\n<br/>", WeightFileModeName); + strcat(contentBuffer, Msg); + +#ifdef GY_OS_WIN + if (!nIsCompatibleCPU) + { + sprintf(Msg, "SysStatus=%s\r\n<br/>", "[ERROR] The CPU doesn't meet hardware requirements for OpenVINO!"); + strcat(contentBuffer, Msg); + } + else + strcat(contentBuffer, "SysStatus=OK\r\n<br/>"); +#endif + strcpy(beforeSendBuffer, contentBuffer); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_server(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18\n"); + //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } +#if 1 + else if (strcmp(urlBuffer, "/enable_downsized_cropped_roi") == 0 || strcmp(urlBuffer, "/disable_downsized_cropped_roi") == 0) + { +#ifdef GY_OS_AMBA + if (strcmp(urlBuffer, "/enable_downsized_cropped_roi") == 0) { + set_enable_downsized_cropped_roi(1); + strcpy(beforeSendBuffer, "Enable downsized cropped roi."); + } + else { + set_enable_downsized_cropped_roi(0); + strcpy(beforeSendBuffer, "Disable downsized cropped roi."); + } +#endif //GY_OS_AMBA + + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18-2\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/enable_zone_crop") == 0 || strcmp(urlBuffer, "/disable_zone_crop") == 0) + { +#ifdef GY_OS_AMBA + if (strcmp(urlBuffer, "/enable_zone_crop") == 0) { + set_enable_zone_crop_1(1); + strcpy(beforeSendBuffer, "Enable zone crop."); + } + else { + set_enable_zone_crop_1(0); + strcpy(beforeSendBuffer, "Disable zone crop."); + } +#endif //GY_OS_AMBA + + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18-212\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_cropped_roi") == 0) + { + char Msg[256] = { 0 }; +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "{\"CROPPED_ROI\":\"%d\",\"CROPPED_ZONE_1\":\"%d\"}", get_enable_downsized_cropped_roi(), get_enable_zone_crop_1()); +#endif //GY_OS_AMBA + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18-3\n"); + closesocket(cli_socket); + } +#endif + else if (strcmp(httpCommand, "GET ") == 0 && (strcmp(urlBuffer, "/getalarmmotion") == 0 || strstr(urlBuffer, "/getalarmmotion"))) + { + //printf("******************************************* recv getalarmmotion [%d]\n", cli_socket); + //printf("\n[web process]start 8\n"); + + *isGetalarmMotion = TRUE; + } + else if ((strcmp(urlBuffer, "/Aida/index.html") == 0) || + (strcmp(urlBuffer, "/Aida/radar.html") == 0) || + (strcmp(urlBuffer, "/Aida/radar.js") == 0) || + (strcmp(urlBuffer, "/Aida/face_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/face_list.html") == 0) || + (strcmp(urlBuffer, "/Aida/face_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/face_list.js") == 0) || + (strcmp(urlBuffer, "/Aida/face.js") == 0) || + (strcmp(urlBuffer, "/Aida/sweetalert2.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/css/sweetalert2.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/upload_img.html") == 0) || + (strcmp(urlBuffer, "/Aida/anpr_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/countdown.html") == 0) || + (strcmp(urlBuffer, "/Aida/countdown_output.html") == 0) || + (strcmp(urlBuffer, "/Aida/speed_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/speed_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/radar_speed_share.js") == 0) || + (strcmp(urlBuffer, "/Aida/ptz.html") == 0) || + (strcmp(urlBuffer, "/Aida/ptz.js") == 0) || + (strcmp(urlBuffer, "/Aida/tof.html") == 0) || + (strcmp(urlBuffer, "/Aida/tof.js") == 0) || + (strcmp(urlBuffer, "/Aida/setting.html") == 0) || + (strcmp(urlBuffer, "/Aida/license.html") == 0) || + (strcmp(urlBuffer, "/Aida/alarm.html") == 0) || + (strcmp(urlBuffer, "/Aida/airelay_init.html") == 0) || + (strcmp(urlBuffer, "/Aida/alarm_on_airelay.html") == 0) || + (strcmp(urlBuffer, "/Aida/alarm_on_airelay.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit1.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit2.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit3.js") == 0) || + (strcmp(urlBuffer, "/Aida/unit3.wasm") == 0) || + (strcmp(urlBuffer, "/Aida/output.html") == 0) || + (strcmp(urlBuffer, "/Aida/logs.html") == 0) || + (strcmp(urlBuffer, "/Aida/pythonR.html") == 0) || + (strcmp(urlBuffer, "/Aida/python.html") == 0) || + //(strcmp(urlBuffer, "/Aida/logs_sample.html") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/bootstrap.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/jquery.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/bootstrap.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/geotools.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/geotools-swedish-zipcodes.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/moment.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/logs/fancyTable.js") == 0) || + (strcmp(urlBuffer, "/Aida/object_index.html") == 0) || + (strcmp(urlBuffer, "/Aida/js_3_5_1.js") == 0) || + //(strcmp(urlBuffer, "/Aida/lilinivs.js") == 0) || + (strcmp(urlBuffer, "/Aida/index.js") == 0) || + (strcmp(urlBuffer, "/Aida/config.js") == 0) || + (strcmp(urlBuffer, "/Aida/lang.js") == 0) || + (strcmp(urlBuffer, "/Aida/alarm.js") == 0) || + (strcmp(urlBuffer, "/Aida/state.js") == 0) || + (strcmp(urlBuffer, "/Aida/label_names.js") == 0) || + (strcmp(urlBuffer, "/Aida/third_party_label_names.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/setting_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/gauge.min_on_nvr.js") == 0) || + (strcmp(urlBuffer, "/Aida/css/style.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/timebar.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/timebar.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/owl.carousel.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/owl.theme.default.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/lib/owl.carousel.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/timebar.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/timebar.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lib/timebar-1.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery-ui.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.blockUI.js") == 0) || + (strcmp(urlBuffer, "/Aida/fabric.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lpr.html") == 0) || + (strcmp(urlBuffer, "/Aida/cool_counter_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_return.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_return2.png") == 0) || + (strcmp(urlBuffer, "/Aida/lpr.js") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.css") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.html") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.min.js") == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data.js",21) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_1.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_2.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_3.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_4.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_5.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_6.js", 23) == 0) || + (strncmp(urlBuffer, "/Aida/heatmap_data_7.js", 23) == 0) || + (strcmp(urlBuffer, "/Aida/heatmap_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/prism.js") == 0) || + (strcmp(urlBuffer, "/Aida/cgi.js") == 0) || + (strcmp(urlBuffer, "/Aida/icon.js") == 0) || + (strcmp(urlBuffer, "/Aida/gauge.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/chirun_min.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.form.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_mapping.htm") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_list_upload.htm") == 0) || + (strcmp(urlBuffer, "/Aida/lpr_list.html") == 0) || + (strcmp(urlBuffer, "/Aida/cool_counter.html") == 0) || + //(strcmp(urlBuffer, "/Aida/time_bar.html") == 0) || + (strcmp(urlBuffer, "/Aida/jquery-ui.css") == 0) || + (strcmp(urlBuffer, "/Aida/jqueryAll.js") == 0) || + (strcmp(urlBuffer, "/Aida/cool_counter.js") == 0) || + (strcmp(urlBuffer, "/Aida/heatmap.js") == 0) || + (strcmp(urlBuffer, "/Aida/cookie.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/fabric.js") == 0) || + (strcmp(urlBuffer, "/Aida/lang_cookie.js") == 0) || + (strcmp(urlBuffer, "/Aida/posttoken.html") == 0) || + (strcmp(urlBuffer, "/Aida/snmptoken.html") == 0) || + (strcmp(urlBuffer, "/Aida/osdtoken.html") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.easyui.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/jquery.slider.js") == 0) || + (strcmp(urlBuffer, "/Aida/aes.js") == 0) || + (strcmp(urlBuffer, "/Aida/easyui.css") == 0) || + (strcmp(urlBuffer, "/Aida/easyui_jvc.css") == 0) || + (strcmp(urlBuffer, "/Aida/object_index.js") == 0) || + (strcmp(urlBuffer, "/Aida/bootstrap.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/warning.html") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/NoParking_Red_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/Counter_Green_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/SpeedWithRim_Red_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/Icon/CarWithRim_Yellow_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/ExclamationMark_Blue_64x64px.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_alarm.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_ai_setting1.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_ai_setting2.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_anpr.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_export.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_import.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_license.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_lpr_list.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_lpr_list_upload.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_lpr_mapping.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_output.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_setting.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_radar.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_face.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_0.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_1.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_2.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_3.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/speed_bg_default_4.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_ptz.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_counter.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_stopwatch.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_tof.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/slider_handle.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/rotate.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/user_blue.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/snap_blue.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/combo_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/catalog.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/spinner_arrows_up.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/spinner_arrows_down.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/datebox_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_prevmonth.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_nextmonth.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_prevyear.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/calendar_nextyear.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_bottom.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_center.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_top.png") == 0) || + (strcmp(urlBuffer, "/Aida/draw_arrow.js") == 0) || + (strcmp(urlBuffer, "/Aida/websocket.html") == 0) || + (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_65_ffffff_1x400.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_75_e6e6e6_1x400.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_75_dadada_1x400.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/gray_background.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-1-32X32.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-1-64X64.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-2-32X32.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-2-64X64.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-3-32X32.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/info-3-64X64.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/down_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/up_arrow.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/file.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/html.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/png.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/jpg.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/js.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/py.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/json.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/zip.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/bin.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/play.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/save.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/delete.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/uploadfile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/refreshfile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/deletefile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/addfile.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/stop.png") == 0) || + (strcmp(urlBuffer, "/Aida/images/clear.png") == 0) || + (strcmp(urlBuffer, "/Aida/") == 0) || + (strcmp(urlBuffer, "/Aida/favicon.ico") == 0) || + (strcmp(urlBuffer, "/favicon.ico") == 0) || + (strcmp(urlBuffer, "/Aida/fabric_jquery.easyui.min_compressed.js") == 0) || + (strcmp(urlBuffer, "/Aida/jqueryAll_compressed.js") == 0) || + (strcmp(urlBuffer, "/Aida/main.css") == 0) || + (strcmp(urlBuffer, "/Aida_data/logs.js") == 0) || + (strcmp(urlBuffer, "/Aida_data/db_fflpr.db") == 0) || + (strcmp(urlBuffer, "/Aida/alarm_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/ai_meta.html") == 0) || + //(strcmp(urlBuffer, "/Aida/ai_meta.js") == 0) ||//|W + (strcmp(urlBuffer, "/Aida/menu_on_nvr.html") == 0) || + (strcmp(urlBuffer, "/Aida/jquery_3_2_1.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/fabric_jquery.easyui.min_compressed_on_nvr.js") == 0) || + (strcmp(urlBuffer, "/Aida/csvformat_help.html") == 0) || + (strncmp(urlBuffer, "/Aida/Icon/counter_icon/", 24) == 0) || + (strncmp(urlBuffer, "/Aida/labels/car_type/", 22) == 0) || + (strncmp(urlBuffer, "/Aida/labels/",13) == 0) || + (strcmp(urlBuffer, "/Aida/ruler/demo.js") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/ruler/ruler.js") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/ruler/ruler.min.js") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/ruler/ruler.min.css") == 0) || // a113n 2022-09-29 + (strcmp(urlBuffer, "/Aida/pcl/pcl.html") == 0) || // add pcl .js + (strcmp(urlBuffer, "/Aida/pcl/test.html") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/OrbitControls.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/PCDLoader.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/three.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/TrackballControls.js") == 0) || + (strcmp(urlBuffer, "/Aida/pcl/pcd/tof.pcd") == 0) || + (strcmp(urlBuffer, "/Aida/css/upload_img_demo.css") == 0) || + (strcmp(urlBuffer, "/Aida/css/upload_img_style.css") == 0) || + (strcmp(urlBuffer, "/Aida/lilin.png") == 0) || + (strcmp(urlBuffer, "/Aida/normalize.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/cropper.min.css") == 0) || + (strcmp(urlBuffer, "/Aida/cropper.min.js") == 0) + ) + { + + pthread_mutex_lock(&mutex_web); + + if (strcmp(urlBuffer, "/favicon.ico") == 0) { + strcpy(urlBuffer,"/Aida/favicon.ico"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data.js", 21) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_1.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_1.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_2.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_2.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_3.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_3.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_4.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_4.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_5.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_5.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_6.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_6.js"); + } + + if ((strncmp(urlBuffer, "/Aida/heatmap_data_7.js", 23) == 0)) { + strcpy(urlBuffer, "/Aida/heatmap_data_7.js"); + } + + //printf("\n[web process]start 9\n"); + + //printf("\nsock(%d):%s\n", cli_socket, urlBuffer); + char tmp_open_file[512]; + memset(tmp_open_file, 0, sizeof(tmp_open_file)); + + if (isGYNetReady == FALSE) + { + sprintf(tmp_open_file, "./Aida/wait.html"); + } + else if (g_IsPTZDevice == 0) + { + + if (strcmp(accountData[0].account_flip, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0 || + strcmp(accountData[0].account_rotate, "1") == 0) + { + sprintf(tmp_open_file, "./Aida/warning.html"); + } + else{ + sprintf(tmp_open_file, ".%s", urlBuffer); + } + } + else if (g_IsPTZDevice == 1) + { + + if (strcmp(accountData[0].account_rotate, "1") == 0 || + strcmp(accountData[0].account_mirror, "1") == 0) + { + sprintf(tmp_open_file, "./Aida/warning.html"); + } + else{ + sprintf(tmp_open_file, ".%s", urlBuffer); + } + } + + + /*//#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] http get tmp_open_file:%s\n", cli_socket,tmp_open_file); + //#endif //_DEBUG_AMBA*/ + + if ((strcmp(urlBuffer, "/Aida/cool_counter.html") != 0) || + (strcmp(urlBuffer, "/Aida/cool_counter.html") == 0 && (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) + ))) + { + int file_fd; + if ((file_fd = open(tmp_open_file, O_RDONLY)) == -1) + { + printf("Failed to open file : %s\n", tmp_open_file);//ɮצSQŪ + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19-2\n"); + } + else { + int iFileLength = 0; + char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; + iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); + close(file_fd); + + /* work out the file type and check if we support it */ + buflen = strlen(urlBuffer); + fstr = NULL; + for (idx = 0; extensions[idx].ext != 0; idx++) + { + len = strlen(extensions[idx].ext); + if (!strncmp(&urlBuffer[buflen - len], extensions[idx].ext, len)) + { + fstr = extensions[idx].filetype; + break; + } + } + + if (fstr == NULL) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19\n"); + } + else + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: %s;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n", fstr); /*\r\nCache - Control: max - age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #20\n"); + } + + int iSentLeft = 0; + int iSentLength = 0; + int iHaveSentLength = 0; + int iRetryCount = 5; + + + + iSentLeft = iFileLength; + + while (iSentLeft >= 1) { + iSentLength = send(cli_socket, sendBuffer_superlarge + iHaveSentLength, iSentLeft, MSG_MORE); + + if (iSentLength <= 0) + break; + + iHaveSentLength = iHaveSentLength + iSentLength; + iSentLeft = iSentLeft - iSentLength; + iRetryCount--; + + if (iSentLeft >= 1) { + //printf("\n[web process]iSentLeft: %d\n", iSentLeft); + } + + if (iRetryCount <= 0) + break; + //usSleep(100); + } + + + } + } + else if(strcmp(urlBuffer, "/Aida/cool_counter.html") == 0){ + strcpy(beforeSendBuffer, "The weight should support the counter function."); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + } + + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#if 1 + else if (strcmp(urlBuffer, "/getAidaInfo") == 0) + { + //printf("\n[web process]start 10\n"); + //Get MAC Address + char fetch_mac_addr[30] = { 0 }; + memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); + if (g_match_mac) + strcpy(fetch_mac_addr, g_mac_address); + else + { + GetMACAddress(fetch_mac_addr); + //printf("mac addr = %s \n", fetch_mac_addr); + int i = 0; + while (fetch_mac_addr[i] != '\0') + { + if (fetch_mac_addr[i] == '\n') + { + fetch_mac_addr[i] = '\0'; + break; + } + i++; + } + } + ///get config info + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { +#ifdef _DEBUG_AMBA + printf("read config.json.\n"); +#endif + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *config_root, *about_box, *unlock_key; + + config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (config_root) { + //printf("config.json parse OK.\n"); + about_box = cJSON_GetObjectItem(config_root, "about_box"); + //nic_name = cJSON_GetObjectItem(about_box, "NIC name"); + unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + + ///read config.json + + cJSON /**dataset_ver,*/ *root; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + /*jstr1 = cJSON_CreateString("json test1"); + jstr2 = cJSON_CreateString("json test2"); + jnum1 = cJSON_CreateNumber(4456);*/ + //sys_id = cJSON_CreateString(fetch_mac_addr); + //dataset_ver = cJSON_CreateString("1.0.0"); + //soft_ver = cJSON_CreateString("1.0.0"); + //dataset_ver = cJSON_GetObjectItem(about_box, "dataset version"); + //soft_ver = cJSON_GetObjectItem(about_box, "software version"); + /*license_type = cJSON_CreateString("licensed"); + license_status = cJSON_CreateString("test"); + license_des = cJSON_CreateString("test");*/ + + //printf("\n"); + //printf(unlock_key->valuestring); + //printf("\n"); +#ifdef GY_OS_AMBA + cJSON_AddItemToObject(root, "model_camera", cJSON_CreateNumber(get_g_PTZ_model())); +#else + cJSON_AddItemToObject(root, "model_camera", cJSON_CreateNumber(0)); +#endif + + cJSON_AddItemToObject(root, "unlock_key", cJSON_CreateString(unlock_key->valuestring)); + +#if 0 + char temp_key[512] = { 0 }; + char formatted_mac[30] = { 0 }; + if (strstr(unlock_key->valuestring, "face") != NULL) { + getContractSignature(temp_key, formatted_mac); + } +#endif + + cJSON_AddItemToObject(root, "sys_id", cJSON_CreateString(fetch_mac_addr)); + cJSON_AddItemToObject(root, "dataset_ver", cJSON_CreateString(Buffer_ver)); + char temp_soft_ver[50] = { 0 }; + strcat(temp_soft_ver, APP_VERSION); + strcat(temp_soft_ver, "-"); + strcat(temp_soft_ver, WeightFileModeName); + cJSON_AddItemToObject(root, "soft_ver", cJSON_CreateString(temp_soft_ver)); + cJSON_AddItemToObject(root, "license_type", cJSON_CreateString(http_strLicenseType)); + cJSON_AddItemToObject(root, "license_status", cJSON_CreateString(strLicenseStatus)); + +#ifdef GY_OS_V_SERIES + cJSON_AddItemToObject(root, "v_series", cJSON_CreateString("Yes")); +#else + cJSON_AddItemToObject(root, "v_series", cJSON_CreateString("No")); +#endif + + cJSON_AddItemToObject(root, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + + cJSON_AddItemToObject(root, "CheckIsExistingSpeed", cJSON_CreateNumber(CheckIsExistingSpeed)); + cJSON_AddItemToObject(root, "White_LED", cJSON_CreateNumber(g_camera_white_LED)); + cJSON_AddItemToObject(root, "No_brand", cJSON_CreateNumber(g_check_if_no_brand)); + cJSON_AddItemToObject(root, "sdk_version", cJSON_CreateNumber(g_sdk_version)); + + char licensePATH[1024] = { 0 }; + //strcpy(licensePATH, exePath); + strcpy(licensePATH, "/emmc/plugin/Aida/license.txt"); + + if (!FileExist(licensePATH)) + printf("%s doesn't exist.\n", licensePATH); + else + { + char* fileBuf = ReadAllBytes(licensePATH); + + if (fileBuf) { +#ifdef _DEBUG_AMBA + printf("licensePATH = %s \n", licensePATH); + printf("fileBuf = %s \n", fileBuf); +#endif + cJSON_AddItemToObject(root, "license_file_content", cJSON_CreateString(fileBuf)); + } + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + } + + JsonString = cJSON_PrintUnformatted(root); +#ifdef _DEBUG_AMBA + printf("return json str = %s \n", JsonString); +#endif + strcat(contentBuffer, JsonString); + + if (config_root) { + cJSON_Delete(config_root); + config_root = NULL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #21\n"); + + //send(cli_socket, JsonString, sizeof(JsonString), 0); + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(JsonString), JsonString); + //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + //{ + // printf("\nsend error\n"); + //} + //printf("get aida info \n"); + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getloading") == 0) //20201222 XCPUMGPU + { + /*if (!is_connection_authorized(recvBuffer, cli_socket, FALSE)) {} + else*/ { + //printf("\n[web process]start 11\n"); + char AI_fps_tojson[256] = { 0 }; + sprintf(AI_fps_tojson, "%d", AI_fps); + + char temp_CPU_usage[256] = { 0 }; + char temp_GPU_usage[256] = { 0 }; + char temp_AI_fps_tojson[256] = { 0 }; + + strcpy(temp_CPU_usage, CPU_usage); + strcpy(temp_GPU_usage, GPU_usage); + strcpy(temp_AI_fps_tojson, AI_fps_tojson); + + //get_loading(); + if (g_i_get_cpu_loading == 0) + { + g_i_get_cpu_loading = 1; + +#ifdef GY_OS_AMBA + pthread_t thread_id_getloading; + if (pthread_create(&thread_id_getloading, 0, get_loading, NULL)) + printf("\ngetloading thread creation failed\n"); +#endif + } + + //printf("getloading\n"); + + char convert_tojson1[256] = "{\"CPU_USAGE\":"; + char convert_tojson2[256] = ",\"GPU_USAGE\":"; + char convert_tojson3[256] = ",\"FPS\":"; + char convert_tojson4[256] = "}"; + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, temp_CPU_usage); + strcat(contentBuffer, convert_tojson2); + strcat(contentBuffer, temp_GPU_usage); + strcat(contentBuffer, convert_tojson3); + strcat(contentBuffer, temp_AI_fps_tojson); + strcat(contentBuffer, convert_tojson4); + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + } + //printf("\ngetloading \n"); + //if (pPipe != NULL) + // vpclose(pPipe); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getplayback_list") == 0) //20201222 XCPUMGPU + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[BUFSIZE_V2] = { 0 }; + + + pthread_mutex_lock(&mutex_heatmap_jpeg); + DIR *d_file; + struct dirent *dir_file; + d_file = opendir("/emmc/plugin/Aida_data/playback"); + if (d_file) { + while ((dir_file = readdir(d_file)) != NULL) { + if (strlen(dir_file->d_name) >= 17) { + strcat(Msg, dir_file->d_name); + strcat(Msg, ","); + } + } + closedir(d_file); + } + pthread_mutex_unlock(&mutex_heatmap_jpeg); + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/control?alarm.gpio=",20) == 0) //20201222 XCPUMGPU + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + char c_alarm_gpio[256] = { 0 }; + memset(c_alarm_gpio, 0x00, sizeof(c_alarm_gpio)); + strcpy(c_alarm_gpio, urlBuffer + 20); + + char Msg[256] = { 0 }; + if (strlen(c_alarm_gpio) == 1 && isdigit(c_alarm_gpio[0])) { + g_control_alarm_gpio = atoi(c_alarm_gpio); + sprintf(Msg, "%d", g_control_alarm_gpio); + } + else { + strcpy(Msg,"Fail."); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2299\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/run_osd_server") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); +#ifdef GY_OS_AMBA + //OSD server إ + pthread_t thread_id_osd; + if (pthread_create(&thread_id_osd, 0, run_osd_server_thread, NULL)) { + printf("\nrun osd server thread creation failed #22\n"); + } +#endif + strcpy(beforeSendBuffer, ""); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/getcheck_current_resolution") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", g_check_current_resolution); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2233\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getcountpost") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", get_g_counter_index_post()); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getcountlong") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", get_g_counter_index_long()); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #253\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getptztest") == 0) //20201222 XCPUMGPU + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "g_ori_yuv_height:%d,g_ori_yuv_width:%d,g_framesize_height:%d,g_framesize_width:%d", + g_ori_yuv_height, g_ori_yuv_width, g_framesize_height, g_framesize_width); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/getfree") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg,"%d", get_free_mem_data()); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/setcamera",10) == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[512] = { 0 }; + sprintf(Msg, "%s", urlBuffer + 10); + printf("\n--------[setcamera]:%s\n", Msg); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2552\n"); + + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/exit_gynet") == 0) //20201222 XCPUMGPU + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + char Msg[256] = { 0 }; + sprintf(Msg, "%d", g_change_getnetwork_buffer_id); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + + if (g_change_getnetwork_buffer_id == 1) { + usSleep(2000000); +#ifdef GY_OS_AMBA + printf("\n-----------------------get network buffer id# 2: exit-----------------------\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); + write_to_logs_html(temp_msg, "exit gynet", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "exit gynet", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("\ncreate auto reboot thread faile \n"); + } +#endif + } + } +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/get_cur_pos") == 0) //20201222 XCPUMGPU + { + //UpdatePTZCurPos(); + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[512] = { 0 }; + sprintf(Msg, "{\"pan\":\"%d\",\"tilt\":\"%d\",\"zoom\":\"%d\"}", g_stPTZ_Handle.iPanABS, g_stPTZ_Handle.iTiltABS, g_stPTZ_Handle.iZoomABS); + //strcpy(Msg,"hello"); + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2882\n"); + + closesocket(cli_socket); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/clean_face_list") == 0) //20201222 XCPUMGPU + { + start_to_import_file = 0; + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%s", "OK"); + + { + //MŶ¥զWƮw + char urlBuffer_4[256] = "/set_search_info?clean=watch"; + char urlBuffer_5[256] = "/set_search_info?clean=vip"; + char urlBuffer_6[256] = "/set_search_info?clean=log"; + char urlBuffer_7[256] = "/set_search_info?clean=visitor"; + char urlBuffer_8[256] = "/set_search_info?clean=mapping"; + + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_6, strlen(urlBuffer_6)); + firstBuffer[strlen(urlBuffer_6)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_7, strlen(urlBuffer_7)); + firstBuffer[strlen(urlBuffer_7)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_8, strlen(urlBuffer_8)); + firstBuffer[strlen(urlBuffer_8)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2fff2\n"); + + closesocket(cli_socket); + } + +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + else if (strcmp(urlBuffer, "/clean_lpr_list") == 0) //20201222 XCPUMGPU + { + start_to_import_file = 0; + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%s", "OK"); + + { + //MŶ¥զWƮw + char urlBuffer_4[256] = "/set_search_info?clean=black"; + char urlBuffer_5[256] = "/set_search_info?clean=white"; + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2fff2\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_pause_time") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + char MSG[50] = { 0 }; + sprintf(MSG,"%ld", g_image_HD_pasue_time); + strcpy(beforeSendBuffer, MSG); + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_play_video") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + if (g_video_start_HD == 1) { + strcpy(beforeSendBuffer, "Yes"); + } + else { + strcpy(beforeSendBuffer, "No"); + } + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/play_video") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + if (g_video_start_HD == 0) { + g_video_start_HD = 1; + strcpy(beforeSendBuffer, "Yes"); + } + else { + g_video_start_HD = 0; + strcpy(beforeSendBuffer, "No"); + } + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_framesize_HD") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "{\"width_HD\":\"%d\",\"height_HD\":\"%d\"}", g_framesize_width_HD, g_framesize_height_HD); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strcmp(urlBuffer, "/reset_counter") == 0) + { + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + reset_onvif(); + + pthread_mutex_unlock(&mutex_reset_counter); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2212\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/resetcounting?counter_id=",26) == 0) + { + char c_counting_index[256] = { 0 }; + memset(c_counting_index, 0x00, sizeof(c_counting_index)); + strcpy(c_counting_index, urlBuffer + 26); + + int index_counting = -1; + if (strlen(c_counting_index) >= 1) { + if (strcmp(c_counting_index, "1") == 0) { + index_counting = 0; + } + else if (strcmp(c_counting_index, "2") == 0) { + index_counting = 1; + } + else if (strcmp(c_counting_index, "3") == 0) { + index_counting = 2; + } + else if (strcmp(c_counting_index, "4") == 0) { + index_counting = 3; + } + else if (strcmp(c_counting_index, "5") == 0) { + index_counting = 4; + } + else if (strcmp(c_counting_index, "6") == 0) { + index_counting = 5; + } + else if (strcmp(c_counting_index, "7") == 0) { + index_counting = 6; + } + else if (strcmp(c_counting_index, "8") == 0) { + index_counting = 7; + } + } + + if (index_counting >= 0) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + reset_counter(index_counting, now_time); + reset_certain_counter_onvif(index_counting); + pthread_mutex_unlock(&mutex_reset_counter); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2312\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/getcounting?counter_id=", 24) == 0) + { + char c_counting_index[256] = { 0 }; + memset(c_counting_index, 0x00, sizeof(c_counting_index)); + strcpy(c_counting_index, urlBuffer + 24); + + int index_counting = -1; + if (strlen(c_counting_index) >= 1) { + if (strcmp(c_counting_index, "1") == 0) { + index_counting = 0; + } + else if (strcmp(c_counting_index, "2") == 0) { + index_counting = 1; + } + else if (strcmp(c_counting_index, "3") == 0) { + index_counting = 2; + } + else if (strcmp(c_counting_index, "4") == 0) { + index_counting = 3; + } + else if (strcmp(c_counting_index, "5") == 0) { + index_counting = 4; + } + else if (strcmp(c_counting_index, "6") == 0) { + index_counting = 5; + } + else if (strcmp(c_counting_index, "7") == 0) { + index_counting = 6; + } + else if (strcmp(c_counting_index, "8") == 0) { + index_counting = 7; + } + } + + if (index_counting >= 0) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + sprintf(beforeSendBuffer,"%d", eventCounterList[index_counting].counter_count); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2312\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strcmp(urlBuffer, "/get_counter") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + char temp_count[256] = { 0 }; + char temp_buf[256] = { 0 }; + for (int index_j = 0; index_j < MAX_EVENT_COUNTERS; index_j++) + { + sprintf(temp_count, "%d", eventCounterList[index_j].counter_count); + strcat(temp_buf, temp_count); + if(index_j < MAX_EVENT_COUNTERS - 1) + strcat(temp_buf, ","); + } + strcpy(beforeSendBuffer, temp_buf); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2312\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 +#ifdef GY_OS_V_SERIES + +#else + else if (strcmp(urlBuffer, "/get_counter_cust_name") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + char temp_count[1024] = { 0 }; + char temp_buf[1024] = { 0 }; + for (int index_j = 0; index_j < MAX_EVENT_COUNTERS; index_j++) + { + sprintf(temp_count, "%s", eventCounterList[index_j].counter_cust_name); + strcat(temp_buf, temp_count); + if (index_j < MAX_EVENT_COUNTERS - 1) + strcat(temp_buf, ","); + } + strcpy(beforeSendBuffer, temp_buf); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2382\n"); + + closesocket(cli_socket); + } +#endif +#endif +#if 1 + else if (strcmp(urlBuffer, "/get_check_if_illegal_id_or_pass") == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + + int check_if_illegal_id_or_pass = 0; + /* + if (strstr(accountData[0].account_username, "?") != NULL || + strstr(accountData[0].account_username, ":") != NULL || + strstr(accountData[0].account_username, "/") != NULL || + strstr(accountData[0].account_username, " ") != NULL || + strstr(accountData[0].account_username, "@") != NULL || + strstr(accountData[0].account_username, "#") != NULL || + strstr(accountData[0].account_password, "?") != NULL || + strstr(accountData[0].account_password, ":") != NULL || + strstr(accountData[0].account_password, "/") != NULL || + strstr(accountData[0].account_password, " ") != NULL || + strstr(accountData[0].account_password, "@") != NULL || + strstr(accountData[0].account_password, "#") != NULL) { + check_if_illegal_id_or_pass = 1; + }*/ + + char Msg[256] = { 0 }; + sprintf(Msg, "%d", check_if_illegal_id_or_pass); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/getbar") == 0) + { + + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; +#ifdef GY_OS_AMBA + if (get_g_check_if_differ_image_is_running() == 1) { + sprintf(Msg, "%d", get_g_progress_bar()); + } + else { + sprintf(Msg, "%d", -1); + } +#else + sprintf(Msg, "%d", get_g_progress_bar()); +#endif + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #213\n"); + + closesocket(cli_socket); + } +#if 1 + else if (strncmp(urlBuffer, "/do_a_test_to_post&index=",25) == 0) + { + //printf("\n[do a test to post]return contentBuffer = %s \n", contentBuffer); + long int last_do_a_test, now_do_a_test; + struct timeval currtime_do_a_test; + gettimeofday(&currtime_do_a_test, NULL); + last_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); + + char index_post[50] = { 0 }; + strcpy(index_post, urlBuffer + 25); + + int index_j = atoi(index_post); + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); + strcpy(q_info.post_method, postEventList[index_j].post_event_method); + strcpy(q_info.host_name, postEventList[index_j].post_host_ip); + strcpy(q_info.host_port, postEventList[index_j].post_host_port); + strcpy(q_info.post_url, postEventList[index_j].post_url); + strcpy(q_info.post_username, postEventList[index_j].post_username); + strcpy(q_info.post_password, postEventList[index_j].post_password); + strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); + + if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { + q_info.enable_filename_fixed = 1; + } + else { + q_info.enable_filename_fixed = 0; + } + + + if (strlen(postEventList[index_j].post_customized_header) >= 1) { + strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); + } + else + q_info.post_customized_header[0] = '\0'; + + + if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { + q_info.enable_attached_image = 0; + if (strlen(postEventList[index_j].post_content) >= 1) { + char *replacement_t = NULL; + + replacement_t = StrReplace(postEventList[index_j].post_content, "<|snap_image|>", g_current_snapshot_addr_base64); + strcpy(q_info.content, replacement_t); + + if (replacement_t != NULL) { + free(replacement_t); + replacement_t = NULL; + } + + q_info.content_size = strlen(q_info.content); + } + else + q_info.content[0] = '\0'; + } + else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { + q_info.enable_attached_image = 1; + if (strlen(postEventList[index_j].post_content) >= 1) { + strcpy(q_info.content, postEventList[index_j].post_content); + q_info.content_size = strlen(postEventList[index_j].post_content); + } + else + q_info.content[0] = '\0'; + } + else { + q_info.enable_attached_image = 0; + q_info.content[0] = '\0'; + } + + + pthread_mutex_lock(&mutex_set_http_request); + struct timeval currtime_set_http_request; + gettimeofday(&currtime_set_http_request, NULL); + long current_ms_set_http_request = (currtime_set_http_request.tv_sec * 1000) + (currtime_set_http_request.tv_usec / 1000); + long last_ms_set_http_request = current_ms_set_http_request; + + int check_if_time_is_too_long = 0; + + g_response_post_OK = 0; +#ifdef GY_OS_NOVA + + if (strcmp(q_info.host_name, "127.0.0.1") != 0 && strcmp(q_info.host_name, "localhost") != 0) { + SetHttpRequest(&q_info, sendBuffer, q_info.post_method); + } + else { + SetHttpRequest_sock(&q_info, sendBuffer, q_info.post_method); + } +#endif +#ifdef GY_OS_AMBA + SetHttpRequest(&q_info, sendBuffer, q_info.post_method); +#endif + while (g_response_post_OK == 0) { + if (current_ms_set_http_request > last_ms_set_http_request + 10000) { + check_if_time_is_too_long = 1; + break; + } + + gettimeofday(&currtime_set_http_request, NULL); + current_ms_set_http_request = (currtime_set_http_request.tv_sec * 1000) + (currtime_set_http_request.tv_usec / 1000); + usSleep(1000); + } + + gettimeofday(&currtime_do_a_test, NULL); + now_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); //쬰@ + + if (check_if_time_is_too_long == 0) { + //strcpy(beforeSendBuffer, g_response_net_curl); + sprintf(beforeSendBuffer,"%s, Time:%ld ms, Size:%ld Bytes", g_response_net_curl, (now_do_a_test- last_do_a_test), (long int)q_info.content_size); + } + else { + //strcpy(beforeSendBuffer, "The Post time is too long (> 10 secs). We cannot continue to wait it."); + sprintf(beforeSendBuffer,"%s, Time:%ld ms, Size:%ld Bytes", "The Post time is too long (> 10 secs). We cannot continue to wait it.", (now_do_a_test - last_do_a_test), (long int)q_info.content_size); + } + g_response_post_OK = 0; + pthread_mutex_unlock(&mutex_set_http_request); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2122\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/do_a_snmp_to_post&index=", 25) == 0) + { + //printf("\n[do a test to post]return contentBuffer = %s \n", contentBuffer); + char index_post[50] = { 0 }; + strcpy(index_post, urlBuffer + 25); + + int index_j = atoi(index_post); + + if (SNMPManagementList[index_j].check_if_delivering == 0) { + SNMPManagementList[index_j].check_if_delivering = 1; + + static long last_do_a_test, now_do_a_test; + struct timeval currtime_do_a_test; + gettimeofday(&currtime_do_a_test, NULL); + last_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); + + QueueInfo q_info = { 0 }; + strcpy(q_info.snmp_event_name, SNMPManagementList[index_j].snmp_event_name); + strcpy(q_info.snmp_version, SNMPManagementList[index_j].snmp_version); + strcpy(q_info.snmp_group_name, SNMPManagementList[index_j].snmp_group_name); + strcpy(q_info.snmp_host_ip, SNMPManagementList[index_j].snmp_host_ip); + strcpy(q_info.snmp_host_port, SNMPManagementList[index_j].snmp_host_port); + strcpy(q_info.snmp_oid, SNMPManagementList[index_j].snmp_oid); + strcpy(q_info.snmp_value, SNMPManagementList[index_j].snmp_value); + strcpy(q_info.snmp_type, SNMPManagementList[index_j].snmp_type); + + SetSNMPRequest(&q_info); + + gettimeofday(&currtime_do_a_test, NULL); + now_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); //쬰@ + + { + //strcpy(beforeSendBuffer, g_response_net_curl); + sprintf(beforeSendBuffer, "%s, Time:%ld ms", g_response_snmp, now_do_a_test - last_do_a_test); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #21122\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/getdebugplate") == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + pthread_mutex_lock(&mutex_run_one_net); + strcpy(beforeSendBuffer, g_debug_plate); + pthread_mutex_unlock(&mutex_run_one_net); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22\n"); + + closesocket(cli_socket); + } + +#endif +#if defined GY_OS_AMBA || defined GY_OS_NOVA + else if (strcmp(urlBuffer, "/get_g_count_lpr_insert_times") == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char Msg[256] = { 0 }; + sprintf(Msg, "%d", g_count_lpr_insert_times); + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22232\n"); + + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/getplugin") == 0) //get aida port + { + //printf("\n[web process]start 11-2\n"); + char filename[1024] = { 0 }; + strcat(filename,"/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else{ + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + + char* JsonString = NULL; + JsonString = cJSON_PrintUnformatted(plugin); + strcat(contentBuffer, JsonString); + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #21-2\n"); + + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/set_no_brand") == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + int check_if_set_no_brand = 0; + /* + char Cmd[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + 16); + int check_if_not_digit = 0; + for (int i = 0; i < strlen(Cmd); i++) + { + if (!isdigit(Cmd[i])) + { + check_if_not_digit = 1; + break; + } + }*/ + //if (check_if_not_digit == 0) + { + //printf("\nKKKK: Cmd: %s\n",Cmd); + /*int port_number = atoi(Cmd); + if (port_number < 0 && port_number > 65535) { + if (strlen(accountData[0].account_aida_port) >= 1) + port_number = atoi(accountData[0].account_aida_port); + } + //printf("\nKKKKKKKKK: port_number: %d\n",port_number); + char port_number_char[256] = { 0 }; + sprintf(port_number_char, "%d", port_number);*/ + + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + char temp_version[256] = { 0 }; + sprintf(temp_version,"%s-%s", APP_VERSION, WeightFileModeName); + + cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString("Camera Plug-in")); + cJSON_ReplaceItemInObject(plugin, "homepage", cJSON_CreateString("")); + cJSON_ReplaceItemInObject(plugin, "author", cJSON_CreateString("")); + cJSON_ReplaceItemInObject(plugin, "version", cJSON_CreateString(temp_version)); + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + strcpy(Cmd,JsonString); + check_if_set_no_brand = 1; + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + + if (strlen(Cmd) >= 1) { + strcpy(beforeSendBuffer, Cmd); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252-3\n"); + + closesocket(cli_socket); + + if (check_if_set_no_brand == 1) { + printf("\n[--------Set no brand successfully-------]: We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand.\n"); + usSleep(1000); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand."); + write_to_logs_html(temp_msg, "set no brand", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "set no brand", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + else if (strcmp(urlBuffer, "/set_lilin") == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + int check_if_set_lilin = 0; + /* + char Cmd[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + 16); + int check_if_not_digit = 0; + for (int i = 0; i < strlen(Cmd); i++) + { + if (!isdigit(Cmd[i])) + { + check_if_not_digit = 1; + break; + } + }*/ + //if (check_if_not_digit == 0) + { + //printf("\nKKKK: Cmd: %s\n",Cmd); + /*int port_number = atoi(Cmd); + if (port_number < 0 && port_number > 65535) { + if (strlen(accountData[0].account_aida_port) >= 1) + port_number = atoi(accountData[0].account_aida_port); + } + //printf("\nKKKKKKKKK: port_number: %d\n",port_number); + char port_number_char[256] = { 0 }; + sprintf(port_number_char, "%d", port_number);*/ + + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + char temp_version[256] = { 0 }; + sprintf(temp_version, "%s-%s", APP_VERSION, WeightFileModeName); + + cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString("LILIN Aida Camera Plug-in")); + cJSON_ReplaceItemInObject(plugin, "homepage", cJSON_CreateString("http://www.meritlilin.com")); + cJSON_ReplaceItemInObject(plugin, "author", cJSON_CreateString("LILIN <fae@meritlilin.com.tw>")); + cJSON_ReplaceItemInObject(plugin, "version", cJSON_CreateString(temp_version)); + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + strcpy(Cmd, JsonString); + check_if_set_lilin = 1; + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + + if (strlen(Cmd) >= 1) { + strcpy(beforeSendBuffer, Cmd); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #252-32\n"); + + closesocket(cli_socket); + + if (check_if_set_lilin == 1) { + printf("\n[--------Set lilin successfully-------]: We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand.\n"); + usSleep(1000); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand."); + write_to_logs_html(temp_msg, "set lilin", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "set lilin", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + else if (strncmp(urlBuffer, "/setplugin?port=",16) == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + 16); + int check_if_not_digit = 0; + for (int i = 0; i < strlen(Cmd); i++) + { + if (!isdigit(Cmd[i])) + { + check_if_not_digit = 1; + break; + } + } + if (check_if_not_digit == 0) + { + //printf("\nKKKK: Cmd: %s\n",Cmd); + int port_number = atoi(Cmd); + if (port_number < 0 && port_number > 65535) { + if(strlen(accountData[0].account_aida_port)>=1) + port_number = atoi(accountData[0].account_aida_port); + } + //printf("\nKKKKKKKKK: port_number: %d\n",port_number); + char port_number_char[256] = { 0 }; + sprintf(port_number_char, "%d", port_number); + + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char newline_char[BUFFER_SIZE] = { 0 }; + strcpy(newline_char, "/emmc/plugin/Aida_data/mon -s 2 \"/emmc/plugin/Aida_data/gynet server -http_port "); + strcat(newline_char, port_number_char); + strcat(newline_char, "\" &\n"); + + //printf("%s",newline_char); + + replace_one_line_in_a_file("/emmc/plugin/Aida_data/aiengine", 31, newline_char); + FILE * pPipe2; + char cmd2[256] = { 0 }; + strcpy(cmd2, "chmod 777 /emmc/plugin/Aida_data/aiengine"); + pPipe2 = vpopen(cmd2, "r"); + if (pPipe2 != NULL) + vpclose(pPipe2); + + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + cJSON_ReplaceItemInObject(plugin, "port", cJSON_CreateString(port_number_char)); + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22-3\n"); + + closesocket(cli_socket); + + if (check_if_not_digit == 0) { + printf("\n[--------Set aida port successfully-------]: We will close gynet.exe with the old port. Please restart gynet.exe with the new port.\n"); + usSleep(1000); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the old port. Please restart gynet.exe with the new port."); + write_to_logs_html(temp_msg, "set new port", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "set new port", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + else if (strncmp(urlBuffer, "/setplugin?desc=", 16) == 0) //get aida port + { + //printf("\n[web process]start 12\n"); + char filename[1024] = { 0 }; + strcat(filename, "/www/plugin/json/CameraPlug-in.json"); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + strcpy(Cmd, urlBuffer + 16); + + char name_char[8192*4] = { 0 }; + sprintf(name_char, "%s", Cmd); + + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *plugin; + + plugin = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (plugin) { + //printf("config.json parse OK.\n"); + char* JsonString = NULL; + + //cJSON_ReplaceItemInObject(plugin, "name", cJSON_CreateString(name_char)); //LILIN Aida Camera Plug-in + cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString(name_char)); //LILIN Aida Camera Plug-in + + JsonString = cJSON_Print(plugin); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + } + else + { + printf("%s cannot open.\n", filename); + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (plugin) { + cJSON_Delete(plugin); + plugin = NULL; + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #22-33\n"); + + closesocket(cli_socket); + } + else + printf("CameraPlug-in.json parse FAIL.\n"); + } + } + } + else if (strcmp(urlBuffer, "/getipcamsettings") == 0) //get current ipcam settings + { + //printf("\n[web process]start 13\n"); + //printf("getipcamport\n"); + + char convert_tojson1[256] = "{\"IPCAM_PORT\":\""; + /*char convert_tojson2[256] = "\","; + char convert_tojson3[256] = "\"IPCAM_MIRROR\":\""; + char convert_tojson4[256] = "\","; + char convert_tojson5[256] = "\"IPCAM_FLIP\":\""; + char convert_tojson6[256] = "\","; + char convert_tojson7[256] = "\"IPCAM_ROTATE\":\"";*/ + char convert_tojson8[256] = "\"}"; + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, g_account_port_protected); + /* + strcat(contentBuffer, convert_tojson2); + + strcat(contentBuffer, convert_tojson3); + strcat(contentBuffer, accountData[0].account_mirror); + strcat(contentBuffer, convert_tojson4); + + strcat(contentBuffer, convert_tojson5); + strcat(contentBuffer, accountData[0].account_flip); + strcat(contentBuffer, convert_tojson6); + + strcat(contentBuffer, convert_tojson7); + strcat(contentBuffer, accountData[0].account_rotate);*/ + strcat(contentBuffer, convert_tojson8); + + //printf("\n[getipcamport]return contentBuffer = %s \n", contentBuffer); + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #23\n"); + + //printf("\ngetipcamport \n"); + + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/sync_service") == 0) //get current ipcam settings + { + copy_ipcam_smtp_service_to_gynet(); + + strcpy(beforeSendBuffer, ""); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2355\n"); + + //printf("\ngetipcamport \n"); + + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/service?get=all") == 0) //get current ipcam settings + { + //printf("\n[web process]start 13\n"); + //printf("getipcamport\n"); + + char convert_tojson1[256] = "{\"EMAIL_ADDRESS1\":\""; + char convert_tojson2[256] = "\","; + char convert_tojson3[256] = "\"EMAIL_ADDRESS2\":\""; + char convert_tojson4[256] = "\","; + char convert_tojson5[256] = "\"EMAIL_ADDRESS3\":\""; + char convert_tojson6[256] = "\","; + char convert_tojson7[256] = "\"EMAIL_ADDRESS4\":\""; + char convert_tojson8[256] = "\","; + char convert_tojson9[256] = "\"EMAIL_ADDRESS5\":\""; + char convert_tojson10[256] = "\","; + char convert_tojson11[256] = "\"EMAIL_ADDRESS\":\""; + char convert_tojson12[256] = "\","; + char convert_tojson13[256] = "\"SMTP_SERVER\":\""; + char convert_tojson14[256] = "\","; + char convert_tojson15[256] = "\"SMTP_AUTH_MODE\":"; + char convert_tojson16[256] = ","; + char convert_tojson17[256] = "\"SMTP_PORT\":\""; + char convert_tojson18[256] = "\","; + char convert_tojson19[256] = "\"SMTP_AUTH\":"; + char convert_tojson20[256] = ","; + char convert_tojson21[256] = "\"AUTH_ACCOUNT\":\""; + char convert_tojson22[256] = "\"}"; + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, IPCAMService.email_address1); + strcat(contentBuffer, convert_tojson2); + + strcat(contentBuffer, convert_tojson3); + strcat(contentBuffer, IPCAMService.email_address2); + strcat(contentBuffer, convert_tojson4); + + strcat(contentBuffer, convert_tojson5); + strcat(contentBuffer, IPCAMService.email_address3); + strcat(contentBuffer, convert_tojson6); + + strcat(contentBuffer, convert_tojson7); + strcat(contentBuffer, IPCAMService.email_address4); + strcat(contentBuffer, convert_tojson8); + + strcat(contentBuffer, convert_tojson9); + strcat(contentBuffer, IPCAMService.email_address5); + strcat(contentBuffer, convert_tojson10); + + strcat(contentBuffer, convert_tojson11); + strcat(contentBuffer, IPCAMService.email_address); + strcat(contentBuffer, convert_tojson12); + + strcat(contentBuffer, convert_tojson13); + strcat(contentBuffer, IPCAMService.smtp_server); + strcat(contentBuffer, convert_tojson14); + + strcat(contentBuffer, convert_tojson15); + char temp_smtp_auth_mode[10] = { 0 }; + sprintf(temp_smtp_auth_mode,"%d", IPCAMService.smtp_auth_mode); + strcat(contentBuffer, temp_smtp_auth_mode); + strcat(contentBuffer, convert_tojson16); + + strcat(contentBuffer, convert_tojson17); + strcat(contentBuffer, IPCAMService.smtp_port); + strcat(contentBuffer, convert_tojson18); + + strcat(contentBuffer, convert_tojson19); + char temp_smtp_auth[10] = { 0 }; + sprintf(temp_smtp_auth, "%d", IPCAMService.smtp_auth); + strcat(contentBuffer, temp_smtp_auth); + strcat(contentBuffer, convert_tojson20); + + strcat(contentBuffer, convert_tojson21); + strcat(contentBuffer, IPCAMService.auth_account); + strcat(contentBuffer, convert_tojson22); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2333\n"); + + //printf("\ngetipcamport \n"); + + closesocket(cli_socket); + } +#if 0 + else if (strcmp(urlBuffer, "/set_bypass_login_on") == 0 || strcmp(urlBuffer, "/set_bypass_login_off") == 0) + { + /*printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nenable_base64: %d\n", enable_base64); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + //printf("set_bypass_login\n"); + char convert_tojson1[256] = "{\"BYPASS_LOGIN\":\""; + char convert_tojson2[256] = "\"}"; + char bypass_login_on[256] = "on"; + char bypass_login_off[256] = "off"; + + strcat(contentBuffer, convert_tojson1); + + if (strcmp(urlBuffer, "/set_bypass_login_on") == 0) + { + enable_base64 = 0; + strcat(contentBuffer, bypass_login_on); + } + else if (strcmp(urlBuffer, "/set_bypass_login_off") == 0) + { + enable_base64 = 1; + strcat(contentBuffer, bypass_login_off); + } + + strcat(contentBuffer, convert_tojson2); + //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24\n"); + + //printf("\nset_bypass_login \n"); + + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/register_session_id?id=", 24) == 0) + { + + + char c_session_id[MAX_SESSION_ID] = { 0 }; + memset(c_session_id, 0x00, sizeof(c_session_id)); + strcpy(c_session_id, urlBuffer + 24); + //printf("\n-----------register session_id:%s\n", c_session_id); + + if (strlen(c_session_id) >= 1) { + for (int i = 0; i < MAX_NUMBER_SESSION; i++) { + if (strlen(g_record_session_id[i]) == 0) { + strcpy(g_record_session_id[i], c_session_id); + break; + } + else if (strcmp(g_record_session_id[i], c_session_id)==0) { + break; + } + else if (i == MAX_NUMBER_SESSION-1) { + for (int j = 0; j < MAX_NUMBER_DELETED_SESSION; j++) { + memset(g_record_session_id[j], 0x00, sizeof(g_record_session_id[j])); + } + for (int j = 0; j < MAX_NUMBER_SESSION- MAX_NUMBER_DELETED_SESSION; j++) { + strcpy(g_record_session_id[j], g_record_session_id[j+ MAX_NUMBER_DELETED_SESSION]); + memset(g_record_session_id[j + MAX_NUMBER_DELETED_SESSION], 0x00, sizeof(g_record_session_id[j + MAX_NUMBER_DELETED_SESSION])); + } + } + } + } + + /* + for (int i = 0; i < MAX_NUMBER_SESSION; i++) { + printf("\n(%d)----session id:%s\n",i, g_record_session_id[i]); + }*/ + + strcpy(contentBuffer," "); + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #231\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/login_session_id?id=", 21) == 0) + { + char c_session_id[MAX_SESSION_ID] = { 0 }; + memset(c_session_id, 0x00, sizeof(c_session_id)); + strcpy(c_session_id, urlBuffer + 21); + //printf("\n-----------login session_id:%s\n", c_session_id); + + if (strlen(c_session_id) >= 1) { + int check_existing_session = 0; + for (int i = 0; i < MAX_NUMBER_SESSION; i++) { + if (strcmp(g_record_session_id[i], c_session_id) == 0) { + check_existing_session = 1; + break; + } + } + if (check_existing_session == 1) { + strcpy(contentBuffer, "Yes"); + } + else { + strcpy(contentBuffer, "No"); + } + } + else { + strcpy(contentBuffer, "No"); + } + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #232\n"); + + closesocket(cli_socket); + } +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/setmetadata?", 13) == 0) { + + int check_if_radar_open = 0; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + if (strncmp(viewDetectionZone[0][index_zone].enable_speed, "Yes", strlen("Yes")) == 0 /*&& + strncmp(viewDetectionZone[0][index_zone].enable_radar_speed, "Yes", strlen("Yes")) == 0*/) { + check_if_radar_open = 1; + break; + } + } + + if (check_if_radar_open == 1) { + + char Cmd[8192] = { 0 }; + strcpy(Cmd, urlBuffer + 13); + char msg[256] = { 0 }; + + if (strlen(Cmd) >= 1) { + const char *del = "&"; + char a_data_sp[MAX_SIZE_A_SP_OBJECT][STRSPLIT_SIZE]={0}; + int a_data_sp_num = 0; + + const char *del2 = "="; + char a_data_sp_pair[MAX_SIZE_A_SP_OBJECT][2][STRSPLIT_SIZE]={0}; + + float speed_sp = -1.0; //1 + char unit_sp[256] = { 0 }; //2 + float res_width_sp = -1.0; //3 + float res_height_sp = -1.0;; //4 + float x_sp = -1.0; //5 + float y_sp = -1.0; //6 + + a_data_sp_num = StrSplit(Cmd, a_data_sp, del); + //printf("\n------UU:24\n"); + if (a_data_sp_num == MAX_SIZE_A_SP_OBJECT) + { + for (int i = 0; i < a_data_sp_num; i++) + { + if (a_data_sp[i]) + { + //printf("\n%s\n", a_data_osd[i]); + StrSplit(a_data_sp[i], a_data_sp_pair[i], del2); + //printf("\n------UU:25\n"); + if (strlen(a_data_sp_pair[i][0]) >= 1 && strlen(a_data_sp_pair[i][1]) >= 1) { + + if (strcmp(a_data_sp_pair[i][0], "speed") == 0 || + strcmp(a_data_sp_pair[i][0], "Speed") == 0) { + speed_sp = atof(a_data_sp_pair[i][1]); + } + if (strcmp(a_data_sp_pair[i][0], "speed_unit") == 0 || + strcmp(a_data_sp_pair[i][0], "Speed_unit") == 0) { + strcpy(unit_sp, a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "res_width") == 0 || + strcmp(a_data_sp_pair[i][0], "res_width") == 0) { + res_width_sp = atof(a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "res_height") == 0 || + strcmp(a_data_sp_pair[i][0], "res_height") == 0) { + res_height_sp = atof(a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "x") == 0 || + strcmp(a_data_sp_pair[i][0], "X") == 0) { + x_sp = atof(a_data_sp_pair[i][1]); + } + else if (strcmp(a_data_sp_pair[i][0], "y") == 0 || + strcmp(a_data_sp_pair[i][0], "Y") == 0) { + y_sp = atof(a_data_sp_pair[i][1]); + } + } + } + } + } + + int check_if_sp_ok = 1; + + if (speed_sp == -1.0 || strlen(unit_sp) == 0 || res_width_sp == -1.0 || res_height_sp == -1.0 || x_sp == -1.0 || y_sp == -1.0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: Parameter"); + } + else if (speed_sp < 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: speed < 0"); + } + else if (strcmp(unit_sp, "KPH") != 0 && strcmp(unit_sp, "MPH") != 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: speed_unit should be KPH or MPH"); + } + else if (res_width_sp <= 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: res_width <= 0"); + } + else if (res_height_sp <= 0) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: res_height <= 0"); + } + else if (x_sp <= 0 || x_sp >= res_width_sp) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: x <= 0 || x >= res_width"); + } + else if (y_sp <= 0 || y_sp >= res_height_sp) { + check_if_sp_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: y <= 0 || y >= res_height"); + } + + if (check_if_sp_ok == 1) { + //printf("\n---------%f,%s,%f,%f,%f,%f\n", speed_sp, unit_sp, res_width_sp, res_height_sp, x_sp, y_sp); + for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { + if (SpeedData[i].flag_protected == 0) { + SpeedData[i].speed = speed_sp; + strcpy(SpeedData[i].speed_unit, unit_sp); + SpeedData[i].res_width = res_width_sp; + SpeedData[i].res_height = res_height_sp; + SpeedData[i].x = x_sp; + SpeedData[i].y = y_sp; + SpeedData[i].flag_protected = 1; + } + } + strcpy(msg, "HTTP 200 OK, content: OK"); + } + } + + if (strlen(msg) == 0) { + strcpy(msg, "HTTP 200 OK, content: Error: Format"); + } + } + else { + strcpy(msg, "HTTP 200 OK, content: Error: Please enable speed"); + } + + strcpy(beforeSendBuffer_xtra, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snaphd?index=", 14) == 0) { + pthread_mutex_lock(&mutex_web); + + char snap_hd_index[50] = { 0 }; + memset(snap_hd_index, 0x00, sizeof(snap_hd_index)); + strcpy(snap_hd_index, urlBuffer + 14); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199922\n"); + + int current_hd_index = atoi(snap_hd_index); + + if (current_hd_index >= 0 && current_hd_index < MAX_SNAP_HD_LIST && + snapHDList[current_hd_index].snapshot_size >= 1) + { + if (send(cli_socket, snapHDList[current_hd_index].snapshot_addr, snapHDList[current_hd_index].snapshot_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999991\n"); + } + + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snaphd?time=", 13) == 0) { + pthread_mutex_lock(&mutex_web); + + char c_snap_hd_time[50] = { 0 }; + memset(c_snap_hd_time, 0x00, sizeof(c_snap_hd_time)); + strcpy(c_snap_hd_time, urlBuffer + 13); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199922\n"); + + if (strlen(c_snap_hd_time) == 13) { + char c_msec[10] = { 0 }; + c_msec[0] = c_snap_hd_time[10]; + c_msec[1] = c_snap_hd_time[11]; + c_msec[2] = c_snap_hd_time[12]; + c_msec[3] = '\0'; + c_snap_hd_time[10] = '\0'; + c_snap_hd_time[11] = '\0'; + c_snap_hd_time[12] = '\0'; + + time_t snap_hd_time = (time_t)atoll(c_snap_hd_time); + time_t snap_hd_msec = (time_t)atoll(c_msec); + time_t snap_hd_combine_time = snap_hd_time * 1000 + snap_hd_msec; + +#if 0 + printf("\n---------snap_hd_time:%llu\n", snap_hd_time); + printf("\n---------snap_hd_msec:%llu\n", snap_hd_msec); + + struct tm * timeinfo; + timeinfo = localtime(&snap_hd_time); + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d-%02d-%02d %02d:%02d:%02d:%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, snap_hd_msec); + + printf("\n--------buf_time_info:%s\n", buf_time_info); +#endif + int index_approaching_to_the_object = 0; + time_t combine_time_approaching_to_the_object = snapHDList[0].snapshot_time_mktime*1000 + snapHDList[0].snapshot_msecs_time; + time_t the_difference_value = combine_time_approaching_to_the_object >= snap_hd_combine_time ? + combine_time_approaching_to_the_object - snap_hd_combine_time : + snap_hd_combine_time - combine_time_approaching_to_the_object; + + for (int i = index_approaching_to_the_object + 1; i < MAX_SNAP_HD_LIST; i++) { + time_t temp_combine_time = snapHDList[i].snapshot_time_mktime * 1000 + snapHDList[i].snapshot_msecs_time; + time_t temp_the_difference_value = temp_combine_time >= snap_hd_combine_time ? + temp_combine_time - snap_hd_combine_time : + snap_hd_combine_time - temp_combine_time; + if (temp_the_difference_value < the_difference_value) { + index_approaching_to_the_object = i; + combine_time_approaching_to_the_object = temp_combine_time; + the_difference_value = temp_the_difference_value; + } + } + + int choose_hd_index = index_approaching_to_the_object; + + if (choose_hd_index >= 0 && choose_hd_index < MAX_SNAP_HD_LIST && + snapHDList[choose_hd_index].snapshot_size >= 1) + { + if (send(cli_socket, snapHDList[choose_hd_index].snapshot_addr, snapHDList[choose_hd_index].snapshot_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999992\n"); + } + } + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snaphd", 7) == 0 && strncmp(urlBuffer, "/snaphd?index=", 14) != 0 && strncmp(urlBuffer, "/snaphd?time=", 13) != 0) + { + pthread_mutex_lock(&mutex_web); + //pthread_mutex_lock(&mutex_get_canvas); + //pthread_mutex_lock(&mutex_get_network_input); + size_t snapshot_size = 0; + + //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19991\n"); + + //printf("\n------------snapshot_size:%d\n",(int)snapshot_size); + + if ((int)snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, (int)snapshot_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999993\n"); +#if 1 + for (int i = 0; i < MAX_SNAP_HD_LIST; i++) { + if (snapHDList[i].snapshot_size == 0) { + snapHDList[i].snapshot_size = (int)snapshot_size; + + memset(snapHDList[i].snapshot_addr, 0x00, MAX_IMG_SIZE); + memcpy(snapHDList[i].snapshot_addr, snapshot_addr, (int)snapshot_size); + + time_t rawtime = time(0); + snapHDList[i].snapshot_time = localtime(&rawtime); + snapHDList[i].snapshot_time_mktime = mktime(snapHDList[i].snapshot_time); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + snapHDList[i].snapshot_msecs_time = time_now.tv_usec / 1000; + + break; + } + else if (i == MAX_SNAP_HD_LIST - 1) { + + int min_time_index = 0; + time_t min_time_mktime = snapHDList[0].snapshot_time_mktime; + time_t min_time_msecs_time = snapHDList[0].snapshot_msecs_time; + + for (int index_j = min_time_index + 1; index_j < MAX_SNAP_HD_LIST; index_j++) { + if (snapHDList[index_j].snapshot_time_mktime < min_time_mktime) { + min_time_index = index_j; + min_time_mktime = snapHDList[index_j].snapshot_time_mktime; + min_time_msecs_time = snapHDList[index_j].snapshot_msecs_time; + } + else if (snapHDList[index_j].snapshot_time_mktime == min_time_mktime) { + if (snapHDList[index_j].snapshot_msecs_time < min_time_msecs_time) { + min_time_index = index_j; + min_time_mktime = snapHDList[index_j].snapshot_time_mktime; + min_time_msecs_time = snapHDList[index_j].snapshot_msecs_time; + } + } + } + + snapHDList[min_time_index].snapshot_size = (int)snapshot_size; + + memset(snapHDList[min_time_index].snapshot_addr, 0x00, MAX_IMG_SIZE); + memcpy(snapHDList[min_time_index].snapshot_addr, snapshot_addr, (int)snapshot_size); + + time_t rawtime = time(0); + snapHDList[min_time_index].snapshot_time = localtime(&rawtime); + snapHDList[min_time_index].snapshot_time_mktime = mktime(snapHDList[min_time_index].snapshot_time); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + snapHDList[min_time_index].snapshot_msecs_time = time_now.tv_usec / 1000; + } + } +#endif + } + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_get_canvas); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/switchimage", 12) == 0) { + pthread_mutex_lock(&mutex_web); + //switch_g_image_buff_ori = 1; + if (strlen(contentDescription) > 0) + { + strcpy(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2111\n"); + + //printf("\nset_bypass_login \n"); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#if 1 + //== /getimage_ori? + else if (strncmp(urlBuffer, "/getimage?", 10) == 0) { + + //pthread_mutex_lock(&mutex_web); + + char snapshot_addr[MAX_IMG_SIZE] = {0}; + int snapshot_size = 0; + + // char c_profileid[30] = { 0 }; + /// strcpy(c_profileid, urlBuffer+16); + // int i_profileid = atoi(c_profileid); + + // printf("\n----------i_profileid:%d\n", i_profileid); + + pthread_mutex_lock(&mutex_get_image); + //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) + + // 2022-11-24 Ken Move /radarsnap to here +#if 0 + if (strstr(urlBuffer, "?radar") != NULL) + { + memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + // struct timeval start; + // gettimeofday(&start, NULL); + // time_t start_msecs_time = start.tv_usec / 1000; + + snapshot_size = (int)get_radar_image(snapshot_addr); + + // struct timeval end; + // gettimeofday(&end, NULL); + // time_t end_msecs_time = end.tv_usec / 1000; + // printf("\n=== radarsnap - get radar time, ms Time = %f\n\n", difftime(end_msecs_time, start_msecs_time)); // 2022-11-01 time cost : 30 ~ 170 ms >>> 2x ~ 15x ms + + // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + // perror("send error #1999"); + } + else +#endif + { + if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1) { + memcpy(snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); + snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; + } + // snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); + // snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); + } + pthread_mutex_unlock(&mutex_get_image); + //printf("\n---------------getimage ori:snapshot_size:%d\n", snapshot_size); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19121\n"); + else { + + if (snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) + printf("\nsend error #19129\n"); + } + } + + //pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/getimage_ori?", 14) == 0) { + + //pthread_mutex_lock(&mutex_web); + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + int snapshot_size = 0; + + //char c_profileid[30] = { 0 }; + ///strcpy(c_profileid, urlBuffer+16); + //int i_profileid = atoi(c_profileid); + + //printf("\n----------i_profileid:%d\n", i_profileid); + + pthread_mutex_lock(&mutex_get_image); + //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) + + // 2022-11-24 Ken Move /radarsnap to here +#if 0 + if (strstr(urlBuffer, "?radar") != NULL) + { + memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + // struct timeval start; + // gettimeofday(&start, NULL); + // time_t start_msecs_time = start.tv_usec / 1000; + + snapshot_size = (int)get_radar_image(snapshot_addr); + + // struct timeval end; + // gettimeofday(&end, NULL); + // time_t end_msecs_time = end.tv_usec / 1000; + // printf("\n=== radarsnap - get radar time, ms Time = %f\n\n", difftime(end_msecs_time, start_msecs_time)); // 2022-11-01 time cost : 30 ~ 170 ms >>> 2x ~ 15x ms + + // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + // perror("send error #1999"); + } + else +#endif + { + if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1){ + memcpy(snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); + snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; + } + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); + //snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); + } + pthread_mutex_unlock(&mutex_get_image); + //printf("\n---------------getimage ori:snapshot_size:%d\n", snapshot_size); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19121\n"); + else { + if (snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) + printf("\nsend error #19129\n"); + } + } + + //pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#if defined GY_OS_AMBA + else if (strncmp(urlBuffer, "/getimage_HD?", 13) == 0) { + + //pthread_mutex_lock(&mutex_web); + + char snapshot_addr[MAX_IMG_SIZE_HD] = { 0 }; + int snapshot_size = 0; + + //char c_profileid[30] = { 0 }; + ///strcpy(c_profileid, urlBuffer+16); + //int i_profileid = atoi(c_profileid); + + //printf("\n----------i_profileid:%d\n", i_profileid); + + if (g_video_start_HD == 1) { + pthread_mutex_lock(&mutex_get_image_HD); + //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) + { + if (g_image_buff_size_HD[g_current_max_num_image_buff - 1] >= 1) { + memcpy(snapshot_addr, g_image_buff_HD[g_current_max_num_image_buff - 1], g_image_buff_size_HD[g_current_max_num_image_buff - 1]); + snapshot_size = g_image_buff_size_HD[g_current_max_num_image_buff - 1]; + + memcpy(g_image_buff_HD_pause, snapshot_addr, snapshot_size); + g_image_buff_size_HD_pause = snapshot_size; + } + + //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); + //snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); + } + pthread_mutex_unlock(&mutex_get_image_HD); + //printf("\n---------------getimage HD:snapshot_size:%d\n", snapshot_size); + } + else if(g_image_buff_size_HD_pause >= 1) { + memcpy(snapshot_addr, g_image_buff_HD_pause, g_image_buff_size_HD_pause); + snapshot_size = g_image_buff_size_HD_pause; + } + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #1912122\n"); + else { + if (snapshot_size >= 1) { + if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) + printf("\nsend error #1912922\n"); + } + } + + //pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } +#endif +#endif +#if 0 + else if (strncmp(urlBuffer, "/remotesnap", 11) == 0) + { + // printf("\nurlBuffer : %s\n", urlBuffer); + + if (g_check_if_remotesnap_running == 0) + { + // TODO check PTZ + g_check_if_remotesnap_running = 1; + + pthread_mutex_lock(&mutex_remotesnap_image); + + // char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + // size_t snapshot_size = 0; + + // memset(snapshot_addr, 0x00, MEMORY_SIZE); + + // snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + // snapshot_size = get_g_canvas_addr(snapshot_addr); + + g_remotesnap_snapshot_size = 0; + if ((int)g_remotesnap_snapshot_size == 0) + { + g_remotesnap_snapshot_size = PNS_Get_Snapshot_From_Remote_IPCam("remotesnap_buf.jpg", g_remotesnap_snapshot_addr, 0); + // printf("\nnormal g_remotesnap_snapshot_size %d\n", g_remotesnap_snapshot_size); + } + if ((int)g_remotesnap_snapshot_size >= 0 && (int)g_remotesnap_snapshot_size < 500) + { + g_remotesnap_snapshot_size = get_nosignal_image(g_remotesnap_snapshot_addr); + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + { + printf("\n[CGI:/remotesnap] send buffer error #1\n"); + } + + if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) + printf("\n[CGI:/remotesnap] send snapshot error #1\n"); + } + + if ((int)g_remotesnap_snapshot_size >= 500) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + { + printf("\n[CGI:/remotesnap] send buffer error #2\n"); + } + + if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) + printf("\n[CGI:/remotesnap] send snapshot error #2\n"); + } + + pthread_mutex_unlock(&mutex_remotesnap_image); + g_check_if_remotesnap_running = 0; + } + else + { + pthread_mutex_lock(&mutex_remotesnap_image); + if ((int)g_snap_snapshot_size >= 1) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + { + printf("\n[CGI:/remotesnap] send buffer error #3\n"); + } + + if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) + printf("\n[CGI:/remotesnap] send snapshot error #3\n"); + } + pthread_mutex_unlock(&mutex_remotesnap_image); + } + + // else { + // sprintf(sendBuffer, "HTTP/1.1 400 Bad Request\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + // if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + // printf("\nsend error #1991239\n"); + //} + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/snap",5) == 0 && strncmp(urlBuffer, "/snaphd", 7) != 0 && strncmp(urlBuffer, "/snap?profileid=", 16) != 0) + { + if (g_check_if_snap_running == 0) { + g_check_if_snap_running = 1; + + pthread_mutex_lock(&mutex_snap_image); + + //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //size_t snapshot_size = 0; + + //memset(snapshot_addr, 0x00, MEMORY_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + //snapshot_size = get_g_canvas_addr(snapshot_addr); + + g_snap_snapshot_size = 0; + if ((int)g_snap_snapshot_size == 0){ + g_snap_snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snap_snapshot_addr, 0); + } + + + if ((int)g_snap_snapshot_size >= 1) { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) { + printf("\nsend error #199911\n"); + } + + if (send(cli_socket, g_snap_snapshot_addr, (int)g_snap_snapshot_size, MSG_MORE) == -1) + printf("\nsend error #19999994\n"); + } + + pthread_mutex_unlock(&mutex_snap_image); + g_check_if_snap_running = 0; + + + } + else { + pthread_mutex_lock(&mutex_snap_image); + if ((int)g_snap_snapshot_size >= 1) { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) { + printf("\nsend error #199912\n"); + } + + if (send(cli_socket, g_snap_snapshot_addr, (int)g_snap_snapshot_size, MSG_MORE) == -1) + printf("\nsend error #1999933\n"); + } + pthread_mutex_unlock(&mutex_snap_image); + } + + + //else { + //sprintf(sendBuffer, "HTTP/1.1 400 Bad Request\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + //if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + //printf("\nsend error #1991239\n"); + //} + closesocket(cli_socket); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/differ_image_test") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199915\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + differ_image_test(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, get_g_ori_yuv_width(), get_g_ori_yuv_height()); + + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999997\n"); + } + } + + + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif + else if (strncmp(urlBuffer, "/set_value&",11) == 0) + { + //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); + char value_buffer[256] = { 0 }; + memset(value_buffer, 0x00, sizeof(value_buffer)); + strcpy(value_buffer, urlBuffer + 11); + + //printf("\n-----------%s\n", value_buffer); + + char Msg[256] = { 0 }; + + if (strncmp(value_buffer, "day_or_night=1", 14) == 0) { + + imageDnData.color_mode = 1; + + strcpy(Msg,"OK"); + } + else if (strncmp(value_buffer, "day_or_night=0", 14) == 0){ + + imageDnData.color_mode = 2; + + strcpy(Msg, "OK"); + } + else { + strcpy(Msg, "fail"); + } + + strcpy(beforeSendBuffer, Msg); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #212\n"); + + closesocket(cli_socket); + } +#if 0 + else if (strcmp(urlBuffer, "/differ_image") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199915\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + int no_tempering = 0; + differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(),0,0,&no_tempering,1); + + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999997\n"); + } + } + + + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/bgsnap", 7) == 0) + { + if (g_IsRadarDevice == 1) { + pthread_mutex_lock(&mutex_web); + char snapshot_addr_radar[MEMORY_SIZE] = { 0 }; + memset(snapshot_addr_radar, 0x00, MEMORY_SIZE); + size_t snapshot_size = 0; + snapshot_size = (size_t)get_bg_radar_image(snapshot_addr_radar); + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + perror("send error #199916"); + if ((int)snapshot_size >= 1) + { + if (send(cli_socket, snapshot_addr_radar, (int)snapshot_size, 0) == -1) + perror("send error #19999998"); + } + else + { + printf("empty radar image\n"); + } + pthread_mutex_unlock(&mutex_web); + } + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/speedbgsnap", 12) == 0) + { + pthread_mutex_lock(&mutex_web); + char radar_speed_snapshot_addr[MEMORY_SIZE] = {0}; + memset(radar_speed_snapshot_addr, 0x00, MEMORY_SIZE); + size_t speed_snapshot_size = 0; + speed_snapshot_size = (size_t)get_speed_bg_image(radar_speed_snapshot_addr); + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) + perror("send error #199917"); + if ((int)speed_snapshot_size >= 1) + { + if (send(cli_socket, radar_speed_snapshot_addr, (int)speed_snapshot_size, 0) == -1) + perror("send error #19999999"); + } + else + { + printf("empty radar image\n"); + } + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + } + // ======================================================================================== +#endif +#if 0 + else if (strcmp(urlBuffer, "/differ_image_short") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199918\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + + + int no_tempering = 0; + differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0, 1, &no_tempering,1); + + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #1999989\n"); + } + } + + + ///pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/differ_image_long") == 0) + { + pthread_mutex_lock(&mutex_web); + pthread_mutex_lock(&mutex_run_one_net); + //pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199919\n"); + + if ((int)snapshot_size >= 1) { + + int differ_size = 0; + char differ_addr[MAX_IMG_SIZE] = { 0 }; + memset(differ_addr, 0x00, MAX_IMG_SIZE); + + int no_tempering = 0; + differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 1, 0, &no_tempering,1); + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (differ_size >= 1) { + if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #1999989\n"); + } + } + + + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/count_color", 12) == 0) + { + pthread_mutex_lock(&mutex_web); + //pthread_mutex_lock(&mutex_get_network_input); + pthread_mutex_lock(&mutex_differ_image); + + size_t snapshot_size = 0; + + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); + pthread_mutex_lock(&mutex_get_network_input); + snapshot_size = get_g_canvas_addr(snapshot_addr); + pthread_mutex_unlock(&mutex_get_network_input); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #199920\n"); + + if ((int)snapshot_size >= 1) { + + int color_size = 0; + char color_addr[MAX_IMG_SIZE] = { 0 }; + memset(color_addr, 0x00, MAX_IMG_SIZE); + //pNext_word->name:car,pNext_word->box_x:878.322632,pNext_word->box_y:560.714294,pNext_word->box_w:1680.456665,pNext_word->box_h:1315.334717 + detection_pos fake_pNext = { 0 }; + fake_pNext.left_x = 948; + fake_pNext.top_y = 1093; + fake_pNext.width = 1245; + fake_pNext.height = 648; + + crop_image_ivs(color_addr, &color_size, snapshot_addr, (int)snapshot_size, &fake_pNext, get_g_ori_yuv_width(), get_g_ori_yuv_height()); + + //printf("\n-------------------differ_size:%d\n", differ_size); + if (color_size >= 1) { + if (send(cli_socket, color_addr, color_size, MSG_NOSIGNAL) == -1) + printf("\nsend error #19999990\n"); + } + } + + + pthread_mutex_unlock(&mutex_differ_image); + //pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_web); + closesocket(cli_socket); + + } +#endif + else if (strcmp(urlBuffer, "/sync_ipcam_account_setting") == 0) + { + + pthread_t thread_id_getipcamsettings; + if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { + printf("\ngetipcamsettings thread creation failed\n"); + } + + + if (strlen(contentDescription) > 0) + { + strcpy(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2111\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } +#if 1 + else if (strcmp(urlBuffer, "/sync_image_rotation") == 0) + { +#if 1 + sync_image_rotation_thread(); +#endif + if (strlen(contentDescription) > 0) + { + strcpy(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2113\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/get_enable_ptz") == 0) + { + char convert_tojson1[256] = "{\"enable_PTZ\":\""; + char convert_tojson2[256] = "\"}"; + + + strcat(contentBuffer, convert_tojson1); + + char enable_PTZ_off[256] = "No"; +#ifdef GY_OS_AMBA + char enable_PTZ_on[256] = "Yes"; + + //Check PTZ device + //char ptz_curl_url[512] = { 0 }; + //char ptz_curl_sendbuf[1] = { 0 }; + //char ptz_curl_username[128] = { 0 }; + //char ptz_curl_password[128] = { 0 }; + //char *method = "GET"; + //int ptz_port = atoi(accountData[0].account_port); + + //strcpy(ptz_curl_username, accountData[0].account_username); + //strcpy(ptz_curl_password, accountData[0].account_password); + + //strcpy(ptz_curl_url, "http://"); + //strcat(ptz_curl_url, "127.0.0.1:"); + //strcat(ptz_curl_url, accountData[0].account_port); + //strcat(ptz_curl_url, "/server"); + + //if (check_ptz(ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port)) + if(g_IsPTZDevice == 1) + { + strcat(contentBuffer, enable_PTZ_on); + //strcat(contentBuffer, enable_PTZ_off); + //write_to_enable_PTZ("Yes"); //enable_PTZ |Ψ + } + else +#endif + { + strcat(contentBuffer, enable_PTZ_off); + //write_to_enable_PTZ("No"); //enable_PTZ |Ψ + } + + strcat(contentBuffer, convert_tojson2); + //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/set_only_show_metadata1_on") == 0 || strcmp(urlBuffer, "/set_only_show_metadata1_off") == 0) + { + //printf("\n[web process]start 14\n"); + /*printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nenable_base64: %d\n", enable_base64); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + //printf("set_bypass_login\n"); + char convert_tojson1[256] = "{\"ONLY_SHOW_METADATA1\":\""; + char convert_tojson2[256] = "\"}"; + + char only_show_metadata1_on[256] = "on"; + char only_show_metadata1_off[256] = "off"; + + strcat(contentBuffer, convert_tojson1); + + if (strcmp(urlBuffer, "/set_only_show_metadata1_on") == 0) + { + enable_only_show_metadata1 = 1; + strcat(contentBuffer, only_show_metadata1_on); + update_enable_only_show_metadata1(enable_only_show_metadata1); + } + else if (strcmp(urlBuffer, "/set_only_show_metadata1_off") == 0) + { + enable_only_show_metadata1 = 0; + strcat(contentBuffer, only_show_metadata1_off); + update_enable_only_show_metadata1(enable_only_show_metadata1); + } + + strcat(contentBuffer, convert_tojson2); + //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); + + strcpy(beforeSendBuffer, contentBuffer); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #24-2\n"); + + //printf("\nset_bypass_login \n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/getsmartevent?", 15) == 0 || strncmp(urlBuffer, "/setsmartevent?", 15) == 0) //oipcamevent?get=all (strncmp(urlBuffer, "/getconfig?", 11) == 0) || (strncmp(urlBuffer, "/setconfig?", 11) == 0) + { + //printf("\n[web process]start 15\n"); + char wanted[512] = { 0 }; + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(wanted, firstBuffer + 15); + + //printf("\n%s\n", accountData[0].account_username); + //printf("\n%s\n", accountData[0].account_password); + int size_psBuffer = 256; + + char psBuffer[256] = { 0 }; + char psBuffer_temp[256] = { 0 }; + char psBuffer_send[256] = { 0 }; + + if (strncmp(urlBuffer, "/getsmartevent?", 15) == 0) + { + FILE* pPipe;/*,*pPipe2*/ + printf("\ngetsmartevent\n"); + printf("\n%s\n", wanted); + + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + /* + char cmd_port[256] = { 0 }; + memset(cmd_port, 0x00, sizeof(cmd_port)); + */ + char cmd1[256] = "curl http://"; + //char cmd2[256] = ":"; + char cmd3[256] = "127.0.0.1:";//@127.0.0.1: + char cmd4[256] = "/event?get=all | grep "; + //char cmd_port1[256] = "@localhost/network?http.port=81 | grep http.port"; + + strcpy(cmd, cmd1); + //strcat(cmd, accountData[0].account_username); + //strcat(cmd, cmd2); + //strcat(cmd, accountData[0].account_password); + strcat(cmd, cmd3); + strcat(cmd, accountData[0].account_port); + strcat(cmd, cmd4); + strcat(cmd, wanted); + //printf("\n[getallevent]cmd: %s\n",cmd); + + /*strcat(cmd_port, cmd1); + strcat(cmd_port, accountData[0].account_username); + strcat(cmd_port, cmd2); + strcat(cmd_port, accountData[0].account_password); + strcat(cmd_port, cmd_port1);*/ + + if (/*(pPipe2 = vpopen(cmd_port,"r")) == NULL ||*/ (pPipe = vpopen(cmd, "r")) == NULL) + { + printf("[Error] getsmartevent\n"); + } + else + { + printf("Run: getsmartevent\n"); + char* temp = NULL; + temp = fgets(psBuffer, size_psBuffer, pPipe); + + if (temp != NULL) + { + strncpy(psBuffer_temp, psBuffer, 256); + int c = 0, d = 0; + while (psBuffer_temp[c] != '\0') + { + if (psBuffer_temp[c] == ' ' || psBuffer_temp[c] == '\t') + { + int temp_index = c + 1; + if (psBuffer_temp[temp_index] != '\0') + { + while ((psBuffer_temp[temp_index] == ' ' || psBuffer_temp[temp_index] == '\t') && psBuffer_temp[temp_index] != '\0') + { + if (psBuffer_temp[temp_index] == ' ' || psBuffer_temp[temp_index] == '\t') + c++; + + temp_index++; + } + } + } + psBuffer_send[d] = psBuffer_temp[c]; + c++; + d++; + } + psBuffer_send[d] = '\0'; + + printf("getsmartevent psBuffer: OK\n"); + } + else + { + strcpy(psBuffer_send, "NULL"); + printf("[Error]getsmartevent psBuffer Empty\n"); + } + + if (strcmp(psBuffer_send, "NULL") == 0) + { + char convert_tojson1[256] = "{\"ALL_EVENT\":\""; + char convert_tojson2[256] = "\"}"; + printf("\n[getsmartevent] return str = %s \n", psBuffer_send); + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, psBuffer_send); + strcat(contentBuffer, convert_tojson2); + } + else + { + char convert_tojson1[256] = "{\""; + char convert_tojson2[256] = "\":\""; + char convert_tojson3[256] = "\"}"; + char myarr[2][STRSPLIT_SIZE] = { 0 }; + const char *mydel = "="; + + printf("\n[getsmartevent] return str = %s \n", psBuffer_send); + StrSplit(psBuffer_send, myarr, mydel); + + + strcat(contentBuffer, convert_tojson1); + strcat(contentBuffer, *(myarr)); + strcat(contentBuffer, convert_tojson2); + /* + int temp_index = 0; + while (*(myarr + 1)[temp_index] != '\0' && *(myarr + 1)[temp_index] != '\n') { + strcat(contentBuffer, *(myarr + 1)[temp_index]); + temp_index++; + }*/ + strcat(contentBuffer, *(myarr + 1)); + strcat(contentBuffer, convert_tojson3); + //name: *(myarr) //vale: *(myarr+1) + } + printf("\n[getsmartevent] contentBuffer = %s \n", contentBuffer); + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #25\n"); + + printf("\ngetsmartevent\n"); + } + if (pPipe != NULL) + vpclose(pPipe); + } + else if (strncmp(urlBuffer, "/setsmartevent?", 15) == 0) + { + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #26\n"); + + pthread_t auto_build_smart_events_thread_id; + if (pthread_create(&auto_build_smart_events_thread_id, 0, auto_build_smart_events, NULL)) + { + printf("create auto_build_smart_events thread faile \n"); + } + } + //if (pPipe2 != NULL) + // vpclose(pPipe2); + closesocket(cli_socket); + usSleep(5000); + } +#ifdef GY_OS_V_SERIES + +#else + else if (strncmp(urlBuffer, "/set_divi_smartevent", 20) == 0) + { + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #2556\n"); + + pthread_t auto_build_smart_events_thread_id_di_vi; + if (pthread_create(&auto_build_smart_events_thread_id_di_vi, 0, auto_build_smart_events_di_vi, NULL)) + { + printf("create auto build smart events di vi thread faile \n"); + } + + closesocket(cli_socket); + usSleep(1250); + } +#endif +#if 1 //|crash + else if (strcmp(urlBuffer, "/pns_dev_name") == 0) // Trigger command for PNS 2.0 + { + printf("[pns_dev_name] Triggered.\n"); + char returned_msg[512] = { 0 }; + PNS_Get_Device_Name(1, returned_msg); + if (returned_msg != NULL) + { + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\npns_debug sending response error.\n"); + + } + else { + printf("[web process] Warning: returned_msg is NULL.\n"); + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #34-22\n"); + } + + printf("[pns_dev_name] Finished.\n"); + closesocket(cli_socket); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_snap") == 0) + { + printf("[pns_snap] Triggered.\n"); + + char sendBuffer[BUFSIZE_V2] = { 0 }; + char img_addr[25 * 1024] = {0}; + size_t img_size = PNS_Get_Snapshot_From_IPCam("curl_saved_from_pns_buf.jpg", img_addr,1); + + if (img_size >= 1) + { + char img_info[1024]; + sprintf(img_info, "Image addr: %p\nImage size: %ld\nImage content:\n", img_addr, img_size); + + /* + for (int i = 0; i < img_size; i++) + { + char value[8]; + sprintf(value, "0x%x", img_addr[i]); + strcat(img_info, value); + } + strcat(img_info, "\n");*/ + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(img_info), img_info); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[pns_snap] sending successfully.\n"); + } + else + { + printf("[pns_snap] PNS_Get_Snapshot_From_IPCam fetching error.\n"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #34-23\n"); + } + + closesocket(cli_socket); + printf("[pns_snap] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_query") == 0) // Only for test. Not the official service. + { + printf("[pns query] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Query_Service_Status(returned_msg); + + const char keyword[] = "\"snap\":\""; + char* start = strstr(returned_msg, keyword); + char* end = strstr(returned_msg, "\"}"); + size_t length = (size_t)end - (size_t)start - strlen(keyword); + if (length > 0) + { + char* cloud_addr = malloc(length + 1); + strncpy(cloud_addr, start + strlen(keyword), length); + cloud_addr[length] = '\0'; + printf("Cloud addr. before ddDec: %s\n", cloud_addr); + char* dddec_cloud_addr = ddDec(cloud_addr); + printf("Cloud addr. after ddDec: %s\n", dddec_cloud_addr); + if (cloud_addr) { + free(cloud_addr); + cloud_addr = NULL; + } + if (dddec_cloud_addr) { + free(dddec_cloud_addr); + dddec_cloud_addr = NULL; + } + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[pns query] Sending response error.\n"); + closesocket(cli_socket); + printf("[pns query] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_multipart_debug") == 0) // Only for test. Not the official service. + { + printf("[pns_multipart_debug] Triggered.\n"); + char fake_desc[512] = { 0 }; + PNS_Get_Device_Name(1, fake_desc); + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Send_Multipart_POST("wtf", "", "", "", fake_desc, "vega@ddnsipcam.com", "5Wizards", "https://cloud.ddnsipcam.com/pns/", returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\npns_multipart sending response error.\n"); + closesocket(cli_socket); + printf("[pns_multipart_debug] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/pns_multipart") == 0) // Only for test. Not the official service. + { + printf("[pns_multipart] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + PNS_Send_Multipart_POST("wtf", "", "", "", "", SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/", returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\npns_multipart sending response error.\n"); + closesocket(cli_socket); + printf("[pns_multipart] Finished.\n"); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/ddns_check") == 0) // Only for test. Not the official service. + { + printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + DDNS_Communication(0, "stevehub@meritlilin.com.tw", "12345", returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/ddns_register") == 0) // Only for test. Not the official service. + { + printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + DDNS_Communication(1, SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 1 + else if (strcmp(urlBuffer, "/ddns_login") == 0) // Only for test. Not the official service. + { + printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + DDNS_Communication(2, SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/ddns_image_check") == 0) // Only for test. Not the official service. + { + //printf("[ddns_check_acc] Triggered.\n"); + + char returned_msg[MEMORY_SIZE] = { 0 }; + //int result = + PNS_check_if_to_post_image(SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg,"https://cloud.ddnsipcam.com/pns/"); + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[ddns_check_acc] Service sending/response error.\n"); + closesocket(cli_socket); + //printf("[ddns_check_acc] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/net_curl_test") == 0) // Only for test. Not the official service. + { + printf("[net curl test] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + + curl_information_smtp_t user_smtp; + + strcpy(user_smtp.receiver[0], IPCAMService.email_address1); + strcpy(user_smtp.receiver[1], IPCAMService.email_address2); + strcpy(user_smtp.receiver[2], IPCAMService.email_address3); + strcpy(user_smtp.receiver[3], IPCAMService.email_address4); + strcpy(user_smtp.receiver[4], IPCAMService.email_address5); + + + strcpy(user_smtp.address, IPCAMService.email_address); + strcpy(user_smtp.server, IPCAMService.smtp_server); + sprintf(user_smtp.auth_mode,"%d", IPCAMService.smtp_auth_mode); + strcpy(user_smtp.port, IPCAMService.smtp_port); + sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); + strcpy(user_smtp.user, IPCAMService.auth_account); + + char test_temp[10] = { 0 }; + + if (net_curl_smtp_data(&user_smtp, test_temp,0) < 0){ + strcpy(returned_msg, "SMTP Fail"); + printf("\nSMTP Fail\n"); + } + else { + strcpy(returned_msg, "SMTP OK"); + printf("\nSMTP OK\n"); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[net curl test] Service sending/response error.\n"); + closesocket(cli_socket); + printf("[net curl test] Finished.\n"); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/reboot_my_service") == 0) // Only for test. Not the official service. + { + printf("[reboot test] Triggered.\n"); + char returned_msg[MEMORY_SIZE] = { 0 }; + + strcpy(returned_msg,"start to reboot"); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[reboot test] Service sending/response error.\n"); + closesocket(cli_socket); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot my service"); + write_to_logs_html(temp_msg, "reboot my service", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "reboot my service", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + + printf("[reboot test] Finished.\n"); + } +#endif + else if (strcmp(urlBuffer, "/getAnprInfo") == 0) //20201005 sophia add + { + //printf("\n[web process]start 17\n"); + ///get config info + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + //printf("read config.json.\n"); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON *config_root, *view_setting, *camera; + + config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + //printf("\n[web process]start 17-2\n"); + if (config_root) + { + //printf("config.json parse OK.\n"); + int anpr_ch = 0; + { + view_setting = cJSON_GetObjectItem(config_root, "view_setting"); + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", anpr_ch + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + cJSON *root/*, *levenshtein_distance*/, *min_characters, *max_characters, *confidence, *enable_anpr,*enable_face; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + //levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + confidence = cJSON_GetObjectItem(camera, "confidence"); + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + + /*printf("\nenable_anpr:%s", enable_anpr->valuestring); + printf("\nconfidence:%s", confidence->valuestring); + printf("\nmin_characters:%s", min_characters->valuestring); + printf("\nmax_characters:%s", max_characters->valuestring);*/ + + cJSON_AddItemToObject(root, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); + cJSON_AddItemToObject(root, "enable_face", cJSON_CreateString(enable_face->valuestring)); + cJSON_AddItemToObject(root, "confidence", cJSON_CreateString(confidence->valuestring)); + cJSON_AddItemToObject(root, "min_characters", cJSON_CreateString(min_characters->valuestring)); + cJSON_AddItemToObject(root, "max_characters", cJSON_CreateString(max_characters->valuestring)); + //printf("\n[web process]start 17-3\n"); + JsonString = cJSON_PrintUnformatted(root); + //printf("\n[getAnprInfo]return json str = %s \n", JsonString); + + strcat(contentBuffer, JsonString); + + //char Msg[256] = { 0 }; + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #28\n"); + //printf("\n[web process]start 17-4\n"); + //send(cli_socket, JsonString, sizeof(JsonString), 0); + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(JsonString), JsonString); + //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + //{ + // printf("\nsend error\n"); + //} + //printf("\nget apnr info \n"); + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (config_root) { + cJSON_Delete(config_root); + config_root = NULL; + } + } + else + printf("config.json parse FAIL.\n"); + } + } + //printf("\n[web process]start 17-5\n"); + closesocket(cli_socket); + } + // ======================================================================================== + // Ken 2022-09-22 + else if (strcmp(urlBuffer, "/getradar") == 0) + { + char radarPATH[1024] = { 0 }; + strcpy(radarPATH, exePath); + strcat(radarPATH, "radar.json"); + char *filename = radarPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else + { + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) + { + cJSON *config_root; + char *JsonString = NULL; + config_root = cJSON_Parse(fileBuf); + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (config_root) + { + JsonString = cJSON_PrintUnformatted(config_root); + strcat(contentBuffer, JsonString); + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) + perror("send error #28"); + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (config_root) + { + cJSON_Delete(config_root); + config_root = NULL; + } + } + else + printf("radar.json parse FAIL.\n"); + } + } + // ======================================================================================== + // printf("\n[web process]start 17-5\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/get_search_info?",17) == 0) //claire add + { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //printf("\n[web process]start 18\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+17); + //printf("\n------beforeSendBuffer:%s\n", beforeSendBuffer); + cgi_get_search_info(cli_socket, beforeSendBuffer); + //printf("\n[web process]end 18888\n"); + pthread_mutex_unlock(&mutex_enable_lpr_db); + //printf("\n[web process]end 18\n"); + /* + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error\n"); + */ +#endif + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/set_search_info?",17) == 0) //claire add + { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //printf("\n[web process]start 19\n"); + //printf("\n-------urlBufffer:%s\n",urlBuffer); + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+17); + char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); + strcpy(beforeSendBuffer, temp_beforeSendBuffer); + + if (temp_beforeSendBuffer != NULL) { + free(temp_beforeSendBuffer); + temp_beforeSendBuffer = NULL; + } + + url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); + + //printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); + + cgi_set_search_info(cli_socket, beforeSendBuffer); + +#endif + closesocket(cli_socket); + } +#if 0 + // joy + else if (strncmp(urlBuffer, "/import_face_list", strlen("/import_face_list")) == 0) + { + printf("\n-------------import face list\n"); + g_count_lpr_insert_times = 0; + + memset(g_headerBuffer,0x00, BUFSIZE_V2); + memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); + memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); + + strcpy(g_headerBuffer, headerBuffer); + strcpy(g_multiPartBoundary, multiPartBoundary); + g_bIsMultipart = bIsMultipart; + strcpy(g_contentBuffer, contentBuffer); + g_nTotalContentLen = nTotalContentLen; + + printf("\ng_headerBuffer -------------%s\n",g_headerBuffer); + printf("\ng_contentBuffer-------------%s\n",g_contentBuffer); + printf("\ng_multiPartBoundary-------------%s\n",g_multiPartBoundary); + printf("\ng_bIsMultipart-------------%d\n",g_bIsMultipart); + printf("\ng_nTotalContentLen-------------%ld\n",g_nTotalContentLen); + + pthread_t import_face_list_file_thread_id; + // t~} thread xsɮ׸ + if (pthread_create(&import_face_list_file_thread_id, 0, import_face_list_file_thread, NULL)) + { + printf("create import_face_list_file_thread faile \n"); + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/face_list?", 11) == 0) //claire add + { + printf("face list = %s \n", urlBuffer); + + if (unlockingKeyInnoFR == 1) { + if (strstr(urlBuffer, "select=") != NULL || + strstr(urlBuffer, "flist=") != NULL || + strstr(urlBuffer, "download=") != NULL) + { + ///get_search_info_face + + pthread_mutex_lock(&mutex_enable_face_db); + //printf("select url buf: %s \n", urlBuffer); + + memset(firstBuffer, 0, sizeof(firstBuffer)); + + //printf("urlBuffer = %s \n", urlBuffer); + + + //printf("no err str \n"); + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + + printf("firstbuf = %s \n", firstBuffer); + + + //firstBuffer[strlen(urlBuffer)] = '\0'; + + strcpy(beforeSendBuffer, firstBuffer + 11); + //printf("beforeSendBuffer = %s \n", beforeSendBuffer); + cgi_get_search_info_face(cli_socket, beforeSendBuffer); + //printf("\n[web process]end 18888\n"); + pthread_mutex_unlock(&mutex_enable_face_db); + } + else if (strstr(urlBuffer, "delete=") != NULL || + strstr(urlBuffer, "clean=") != NULL || + strstr(urlBuffer, "add=") != NULL || + strstr(urlBuffer, "update=") != NULL + ) + { + ///set_search_info_face + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 11); + char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); + strcpy(beforeSendBuffer, temp_beforeSendBuffer); + + if (temp_beforeSendBuffer != NULL) { + free(temp_beforeSendBuffer); + temp_beforeSendBuffer = NULL; + } + + url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); + + printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); + //FACE_MSG_BLACKTABLE + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + } + } + + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/get_search_info_face?",22) == 0) // face - leo + { +#ifdef GY_OS_AMBA +#if 0 + if (unlockingKeyInnoFR == 1) { + pthread_mutex_lock(&mutex_enable_face_db); + //printf("select url buf: %s \n", urlBuffer); + + memset(firstBuffer, 0, sizeof(firstBuffer)); + + //printf("urlBuffer = %s \n", urlBuffer); + + + //printf("no err str \n"); + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + + //printf("firstbuf = %s \n", firstBuffer); + + //firstBuffer[strlen(urlBuffer)] = '\0'; + + strcpy(beforeSendBuffer, firstBuffer+22); + cgi_get_search_info_face(cli_socket, beforeSendBuffer); + //printf("\n[web process]end 18888\n"); + pthread_mutex_unlock(&mutex_enable_face_db); + + // sqlite_facegroup_add_list_white_face_list_fix(); + + // test_sfe_add_face_group(); + + //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + // printf("\nsend error\n"); + + } +#endif +#endif + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/set_search_info_face?",22) == 0) // face - leo + { +#ifdef GY_OS_AMBA +#if 0 + if (unlockingKeyInnoFR == 1) { + //printf("\n[web process]start /set_search_info_face?\n"); + //printf("\n-------urlBufffer:%s\n",urlBuffer); + + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+22); + char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); + strcpy(beforeSendBuffer, temp_beforeSendBuffer); + + if (temp_beforeSendBuffer != NULL) { + free(temp_beforeSendBuffer); + temp_beforeSendBuffer = NULL; + } + + url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); + + //printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); + //FACE_MSG_BLACKTABLE + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + } +#endif + +#endif + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/lpr_info?",10) == 0) //claire add + { +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //printf("\n[web process]start 20\n"); + pthread_mutex_lock(&mutex_enable_lpr_db); + char *path = NULL; + memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); + firstBuffer[strlen(urlBuffer)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer+10); + + char l_lpr_cgi_param[BUFSIZE_V2] = {0}; + char l_count[16] = {0}; + //char l_action_lpr[16] = {0}; + char l_compare_str[16] = {0}; + + path = &beforeSendBuffer[0]; + + //set information + sprintf(l_compare_str,"set=status&"); + if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) + { + strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); + l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; + + if ((strstr(path, "LPR_FLAG")) != NULL) + { + printf("\nin LPR_FLAG \n"); + + memset(l_compare_str, 0, sizeof(l_compare_str)); + sprintf(l_compare_str, "LPR_FLAG"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if (strlen(l_count) != 0) + { + printf("set LPR_FLAG %s\n", l_count); + } + } + else if ((strstr(path, "LPR_WHITE_FLAG")) != NULL) + { + printf("\nin LPR_WHITE_FLAG \n"); + + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_count, 0, sizeof(l_count)); + sprintf(l_compare_str, "LPR_WHITE_FLAG"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if (strlen(l_count) != 0) + { + printf("set LPR_WHITE_FLAG %s\n", l_count); + + if (strcmp(l_count, "0") == 0)//disable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&whitelist=No"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if (strcmp(l_count, "1") == 0)//disable//enable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&whitelist=Yes"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + } + } + else if ((strstr(path, "LPR_BLACK_FLAG")) != NULL) + { + printf("\nin LPR_BLACK_FLAG \n"); + + memset(l_compare_str, 0, sizeof(l_compare_str)); + memset(l_count, 0, sizeof(l_count)); + sprintf(l_compare_str, "LPR_BLACK_FLAG"); + getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); + if (strlen(l_count) != 0) + { + printf("set LPR_BLACK_FLAG %s\n", l_count); + + if (strcmp(l_count, "0") == 0)//disable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&blacklist=No"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra));; + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if (strcmp(l_count, "1") == 0)//disable//enable + { + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&blacklist=Yes"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + } + } + } + //get information + sprintf(l_compare_str,"get=status"); + if (strncmp(path, l_compare_str, strlen(l_compare_str)) == 0) + { + //printf("get LPR_FLAG & LPR_BLACK_FLAG & LPR_WHITE_FLAG status\n"); + + if ((strstr(path, "LPR_FLAG")) != NULL) { + //printf("\nin LPR_FLAG \n"); + } + else if ((strstr(path, "LPR_WHITE_FLAG")) != NULL) + { + //printf("\nin LPR_WHITE_FLAG \n"); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&whitelist=all"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_GET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if ((strstr(path, "LPR_BLACK_FLAG")) != NULL) + { + //printf("\nin LPR_BLACK_FLAG \n"); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + sprintf(Cmd, "ch=system_setting&blacklist=all"); + memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); + //CgiCmdRtnCode rtn = + cgicmd_process(Cmd, _CGICMD_GET, beforeSendBuffer_xtra, BUFSIZE * 60); + } + } +#endif //#ifdef GY_OS_AMBA + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #29\n"); + pthread_mutex_unlock(&mutex_enable_lpr_db); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/system?", 8) == 0) + { + //printf("\n[web process]start 21\n"); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + strcpy(Cmd, urlBuffer +8); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + + CgiCmdType type; + type = _CGICMD_GET; + + CgiCmdRtnCode rtn = cgicmd_process(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + + int default_version = 0; + if (rtn == _CGICMD_DEFAULT_NUMBER) { + + if (strncmp(urlBuffer, "/system?default=", 16) == 0) + { + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 16); + + int check_if_not_digit = 0; + for (int index_cmd = 0; index_cmd < strlen(Cmd_temp); index_cmd++) + { + if (!isdigit(Cmd_temp[index_cmd])) + { + check_if_not_digit = 1; + break; + } + } + if (strlen(Cmd_temp) == 0) { + check_if_not_digit = 1; + } + + if (check_if_not_digit == 0) { + default_version = atoi(Cmd_temp); + } + } + } + + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_DEFAULT_3 || rtn == _CGICMD_DEFAULT_ALL || (default_version >= 1 && default_version != 3)) + { + //printf("\nKKKKKKKKKKKKKKK 1\n"); + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "OK"); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #30\n"); + closesocket(cli_socket); + +#if 1 + //if (unlockingKeyInnoFR_success == 1) { + //face_engine_default(); + //usSleep(5000); + //} +#endif + + +#if 1 + char HEATMAP_DATA_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_bak.js"; + if (FileExist(HEATMAP_DATA_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_1_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_1_bak.js"; + if (FileExist(HEATMAP_DATA_1_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_1_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_1_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_1_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_2_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_2_bak.js"; + if (FileExist(HEATMAP_DATA_2_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_2_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_2_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_2_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_3_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_3_bak.js"; + if (FileExist(HEATMAP_DATA_3_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_3_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_3_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_3_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_4_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_4_bak.js"; + if (FileExist(HEATMAP_DATA_4_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_4_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_4_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_4_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_5_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_5_bak.js"; + if (FileExist(HEATMAP_DATA_5_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_5_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_5_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_5_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_6_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_6_bak.js"; + if (FileExist(HEATMAP_DATA_6_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_6_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_6_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_6_BAK_PATH cannot be Deleted.\n"); + } + } + + char HEATMAP_DATA_7_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_7_bak.js"; + if (FileExist(HEATMAP_DATA_7_BAK_PATH)) { + int del = unlink(HEATMAP_DATA_7_BAK_PATH); + if (!del) { + //printf("HEATMAP_DATA_7_BAK_PATH is Deleted successfully."); + } + else { + printf("HEATMAP_DATA_7_BAK_PATH cannot be Deleted.\n"); + } + } +#endif + + char CONFIG_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config.json"; + char CONFIG_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_bak.json"; + char CONFIG_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_install.json"; + + if (FileExist(CONFIG_JSON_PATH)) { + int del = unlink(CONFIG_JSON_PATH); + if (!del) { + //printf("CONFIG_JSON_PATH is Deleted successfully."); + } + else { + printf("CONFIG_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(CONFIG_BAK_JSON_PATH)) { + int del = unlink(CONFIG_BAK_JSON_PATH); + if (!del) { + //printf("CONFIG_BAK_JSON_PATH is Deleted successfully."); + } + else { + printf("CONFIG_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + char CONFIG_CUSTOM_1_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_custom_1.json"; + + if (rtn == _CGICMD_DEFAULT_ALL) { + + if (FileExist(CONFIG_INSTALL_JSON_PATH)) { + int del = unlink(CONFIG_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + CopyFileTo(CONFIG_CUSTOM_1_JSON_PATH, CONFIG_INSTALL_JSON_PATH); + } + else if (default_version >= 1 && default_version != 3) { + if (FileExist(CONFIG_INSTALL_JSON_PATH)) { + int del = unlink(CONFIG_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + char CONFIG_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; + sprintf(CONFIG_CUSTOM_NUM_JSON_PATH, "/emmc/plugin/Aida_data/config_custom_%d.json", default_version); + CopyFileTo(CONFIG_CUSTOM_NUM_JSON_PATH, CONFIG_INSTALL_JSON_PATH); + } + else { + //_CGICMD_DEFAULT_3 + } + + CopyFileTo(CONFIG_INSTALL_JSON_PATH, CONFIG_JSON_PATH); + + char* fileBuf = ReadAllBytes(CONFIG_JSON_PATH); + if (fileBuf) { + cJSON * about_box, *root,*system_setting; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + about_box = cJSON_GetObjectItem(root, "about_box"); + system_setting = cJSON_GetObjectItem(root, "system_setting"); + cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); + cJSON_ReplaceItemInObject(system_setting, "enable_cloud", cJSON_CreateString("No")); + cJSON_ReplaceItemInObject(system_setting, "enable_python", cJSON_CreateString("No")); + cJSON_ReplaceItemInObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); + cJSON_ReplaceItemInObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); + char* JsonString = cJSON_Print(root); + + FILE *f = fopen(CONFIG_JSON_PATH, "w"); + if (f == NULL) + { + + } + else { + + fprintf(f, "%s\n", JsonString); + fclose(f); + CopyFileTo(CONFIG_JSON_PATH, CONFIG_BAK_JSON_PATH); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + + char COLD_OBJECTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects.json"; + char COLD_OBJECTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects_install.json"; + if (FileExist(COLD_OBJECTS_JSON_PATH)) { + int del = unlink(COLD_OBJECTS_JSON_PATH); + if (!del) { + //printf("cold_objects is Deleted successfully."); + } + else { + printf("COLD_OBJECTS_JSON_PATH cannot be Deleted.\n"); + } + } + CopyFileTo(COLD_OBJECTS_INSTALL_JSON_PATH, COLD_OBJECTS_JSON_PATH); + + char EVENTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events.json"; + char EVENTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_install.json"; + char EVENTS_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_bak.json"; + char EVENTS_CUSTOM_1_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_custom_1.json"; + + if (FileExist(EVENTS_JSON_PATH)) { + int del = unlink(EVENTS_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(EVENTS_BAK_JSON_PATH)) { + int del = unlink(EVENTS_BAK_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + if(rtn == _CGICMD_DEFAULT_ALL){ + + if (FileExist(EVENTS_INSTALL_JSON_PATH)) { + int del = unlink(EVENTS_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + CopyFileTo(EVENTS_CUSTOM_1_JSON_PATH, EVENTS_INSTALL_JSON_PATH); + } + else if (default_version >= 1 && default_version != 3) { + if (FileExist(EVENTS_INSTALL_JSON_PATH)) { + int del = unlink(EVENTS_INSTALL_JSON_PATH); + if (!del) { + //printf("events is Deleted successfully."); + } + else { + printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); + } + } + + char EVENTS_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; + sprintf(EVENTS_CUSTOM_NUM_JSON_PATH,"/emmc/plugin/Aida_data/events_custom_%d.json", default_version); + CopyFileTo(EVENTS_CUSTOM_NUM_JSON_PATH, EVENTS_INSTALL_JSON_PATH); + } + else { + //_CGICMD_DEFAULT_3 + } + + CopyFileTo(EVENTS_INSTALL_JSON_PATH, EVENTS_JSON_PATH); + + char EMAILS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/emails.json"; + char EMAILS_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/emails_bak.json"; + if (FileExist(EMAILS_JSON_PATH)) { + int del = unlink(EMAILS_JSON_PATH); + if (!del) { + //printf("emails is Deleted successfully."); + } + else { + printf("EMAILS_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(EMAILS_BAK_JSON_PATH)) { + int del = unlink(EMAILS_BAK_JSON_PATH); + if (!del) { + //printf("emails is Deleted successfully."); + } + else { + printf("EMAILS_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + char TOF_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof.json"; + char TOF_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof_bak.json"; + if (FileExist(TOF_JSON_PATH)) { + int del = unlink(TOF_JSON_PATH); + if (!del) { + //printf("tof is Deleted successfully."); + } + else { + printf("TOF_JSON_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(TOF_BAK_JSON_PATH)) { + int del = unlink(TOF_BAK_JSON_PATH); + if (!del) { + //printf("tof is Deleted successfully."); + } + else { + printf("TOF_BAK_JSON_PATH cannot be Deleted.\n"); + } + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/storage"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/sfe/storage"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/playback"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + + + g_write_config_file_dirty_flag = 0; + + //memset(msg, 0x00, sizeof(msg)); + //sprintf(msg, (default_dataset_for_jsonfile() > 0 ? "Default failed!" : "Default OK.")); + //printf(msg); + //strcpy(beforeSendBuffer_xtra, msg); + + + printf("\n--------------------reload 1\n"); + + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg); + strcat(beforeSendBuffer_xtra, msg); + + char db_fflprPATH[1024] = { 0 }; + char db_fflpr_installPATH[1024] = { 0 }; + char db_facePATH[1024] = { 0 }; + char db_face_installPATH[1024] = { 0 }; + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + strcpy(db_fflprPATH, exePath); + strcpy(db_fflpr_installPATH, exePath); + strcpy(db_facePATH, exePath); + strcpy(db_face_installPATH, exePath); + + strcat(db_fflprPATH, "db_fflpr.db"); + strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); + + strcat(db_facePATH, "db_face.db"); + strcat(db_face_installPATH, "db_face_install_2.db"); + +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR_success == 1) { +#if 0 + char urlBuffer_2[256] = "/set_search_info?clean=log"; + char urlBuffer_3[256] = "/set_search_info?clean=visitor"; + char urlBuffer_4[256] = "/set_search_info?clean=watch"; + char urlBuffer_5[256] = "/set_search_info?clean=vip"; + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_2, strlen(urlBuffer_2)); + firstBuffer[strlen(urlBuffer_2)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_3, strlen(urlBuffer_3)); + firstBuffer[strlen(urlBuffer_3)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info_face(cli_socket, beforeSendBuffer); +#endif + pthread_mutex_lock(&mutex_enable_face_db); + CopyFileTo(db_face_installPATH, db_facePATH); + pthread_mutex_unlock(&mutex_enable_face_db); + } +#endif +#if 0 + char urlBuffer_2[256] = "/set_search_info?clean=log"; + char urlBuffer_3[256] = "/set_search_info?clean=customer"; + char urlBuffer_4[256] = "/set_search_info?clean=black"; + char urlBuffer_5[256] = "/set_search_info?clean=white"; + + memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); + firstBuffer[strlen(urlBuffer_4)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); + firstBuffer[strlen(urlBuffer_5)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_2, strlen(urlBuffer_2)); + firstBuffer[strlen(urlBuffer_2)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); + + memcpy(firstBuffer, urlBuffer_3, strlen(urlBuffer_3)); + firstBuffer[strlen(urlBuffer_3)] = '\0'; + strcpy(beforeSendBuffer, firstBuffer + 17); + cgi_set_search_info(cli_socket, beforeSendBuffer); +#endif + pthread_mutex_lock(&mutex_enable_lpr_db); + CopyFileTo(db_fflpr_installPATH, db_fflprPATH); + pthread_mutex_unlock(&mutex_enable_lpr_db); + closesocket(cli_socket); + +#ifdef GY_OS_AMBA + usSleep(1000000); +#else + g_check_run_nova_detection = 0; + system("killall -15 nova_driver"); + usSleep(10000000); + + char CONFIG_SMALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_small.json"; + char CONFIG_SMALL_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_small_install.json"; + + if (FileExist(CONFIG_SMALL_JSON_PATH)) { + int del = unlink(CONFIG_SMALL_JSON_PATH); + if (!del) { + //printf("CONFIG_SMALL_JSON_PATH is Deleted successfully."); + } + else { + printf("CONFIG_SMALL_JSON_PATH cannot be Deleted.\n"); + } + } + + CopyFileTo(CONFIG_SMALL_INSTALL_JSON_PATH, CONFIG_SMALL_JSON_PATH); +#endif + + pthread_t auto_build_smart_events_thread_id; + if (pthread_create(&auto_build_smart_events_thread_id, 0, auto_build_smart_events, NULL)) + { + printf("create auto_build_smart_events thread faile \n"); + } + pthread_join(auto_build_smart_events_thread_id, NULL); + + //stop_test_nn_cavalry(); + + printf("\n[---CGICMD DEFAULT---]: reboot to release memory\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot to release memory"); + write_to_logs_html(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #30\n"); + closesocket(cli_socket); + } + } + else if ((strncmp(urlBuffer, "/getconfig?coldobjects=", 23) == 0) || (strncmp(urlBuffer, "/setconfig?coldobjects&", 23) == 0)) + { + //printf("\n[web process]start 22\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + +#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); +#endif //_DEBUG_AMBA + CgiCmdType type; + CgiCmdRtnCode rtn; + rtn = _CGICMD_FAIL; + + if (strncmp(urlBuffer, "/getconfig?coldobjects=", 23) == 0) + { + type = _CGICMD_GET; + strcpy(Cmd, urlBuffer + 11); + + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + memset(Cmd_temp, 0x00, sizeof(Cmd_temp)); + strcpy(Cmd_temp, urlBuffer + 23); + + if (strcmp(Cmd_temp, "clean") == 0) { + char COLD_OBJECTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects.json"; + char COLD_OBJECTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects_install.json"; + if (FileExist(COLD_OBJECTS_JSON_PATH)) { + int del = unlink(COLD_OBJECTS_JSON_PATH); + if (!del) { + //printf("cold_objects is Deleted successfully."); + } + else { + printf("COLD_OBJECTS_JSON_PATH cannot be Deleted.\n"); + } + } + CopyFileTo(COLD_OBJECTS_INSTALL_JSON_PATH, COLD_OBJECTS_JSON_PATH); + rtn = _CGICMD_RELOAD; + } + else + rtn = cgicmd_process_cold_objects(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if(strncmp(urlBuffer, "/setconfig?coldobjects&", 23) == 0) + { + strcpy(Cmd, urlBuffer + 23); + + int iSetColdZoneResult = 0; + + if ((int)strlen(Cmd) >= 1) + { + iSetColdZoneResult = SetColdZone(Cmd); + + if (iSetColdZoneResult == 0) + { + WriteColdZoneJsonFile(); + rtn = _CGICMD_RELOAD; + } + else + rtn = _CGICMD_FAIL; + + } + + //if (Cmd) + + /* + printf("\n----------[coldobjects]--------------\n"); + printf("\nx: %d\n", x_coldobject); + printf("\ny: %d\n", y_coldobject); + printf("\nw: %d\n", w_coldobject); + printf("\nh: %d\n", h_coldobject); + printf("\nobject: %s\n", object_coldobject); + printf("\n-------------------------------------\n"); + */ + } + else + rtn = _CGICMD_FAIL; + + + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + memset(msg, 0x00, sizeof(msg)); + printf("\n--------------------reload 2\n"); + + g_write_config_file_dirty_flag = 0; + + write_config(); + + sprintf(msg, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + //sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #31\n"); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/getconfig?detection_zone=", 26) == 0) || (strncmp(urlBuffer, "/setconfig?detection_zone&", 26) == 0)) + { + //printf("\n[web process]start 23\n"); + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + CgiCmdType type; + CgiCmdRtnCode rtn; + rtn = _CGICMD_FAIL; + if (strncmp(urlBuffer, "/getconfig?detection_zone=", 26) == 0) + { + type = _CGICMD_GET; + strcpy(Cmd, urlBuffer + 11); + rtn = cgicmd_process_detection_zone(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + } + else if (strncmp(urlBuffer, "/setconfig?detection_zone&", 26) == 0) + { + strcpy(Cmd, urlBuffer + 26); + + const char *del = "&"; + const char *del2 = "="; + char data_detection_zone[MAX_DETECTION_ZONE*(MAX_SIZE_POINT *2+1)][STRSPLIT_SIZE]={0}; + int data_detection_zone_num = 0; + + char data_detection_zone_pair[MAX_DETECTION_ZONE*(MAX_SIZE_POINT * 2 + 1)][2][STRSPLIT_SIZE]={0}; + //int data_detection_zone_pair_num[MAX_DETECTION_ZONE*(MAX_SIZE_POINT * 2 + 1)] = { 0 }; + + int zone[MAX_DETECTION_ZONE] = { 0 }; + int x1[MAX_DETECTION_ZONE] = { 0 }; + int y1[MAX_DETECTION_ZONE] = { 0 }; + int x2[MAX_DETECTION_ZONE] = { 0 }; + int y2[MAX_DETECTION_ZONE] = { 0 }; + int x3[MAX_DETECTION_ZONE] = { 0 }; + int y3[MAX_DETECTION_ZONE] = { 0 }; + int x4[MAX_DETECTION_ZONE] = { 0 }; + int y4[MAX_DETECTION_ZONE] = { 0 }; + int x5[MAX_DETECTION_ZONE] = { 0 }; + int y5[MAX_DETECTION_ZONE] = { 0 }; + int x6[MAX_DETECTION_ZONE] = { 0 }; + int y6[MAX_DETECTION_ZONE] = { 0 }; + + if ((int)strlen(Cmd)>=1) + { + data_detection_zone_num = StrSplit(Cmd, data_detection_zone, del); + //printf("\n------UU:26\n"); + int i_temp = -1; + for (int i = 0; i < data_detection_zone_num; i++) + { + printf("\n%s\n", data_detection_zone[i]); + if (data_detection_zone[i]) + { + /*data_detection_zone_pair_num[i] = */StrSplit(data_detection_zone[i], data_detection_zone_pair[i], del2); + //printf("\n------UU:27\n"); + if (strcmp(data_detection_zone_pair[i][0], "zone") == 0 || + strcmp(data_detection_zone_pair[i][0], "Zone") == 0) { + i_temp++; + zone[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + + if (i_temp >= 0) + { + if (strcmp(data_detection_zone_pair[i][0], "x1") == 0 || + strcmp(data_detection_zone_pair[i][0], "X1") == 0) { + x1[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y1") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y1") == 0) { + y1[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x2") == 0 || + strcmp(data_detection_zone_pair[i][0], "X2") == 0) { + x2[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y2") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y2") == 0) { + y2[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x3") == 0 || + strcmp(data_detection_zone_pair[i][0], "X3") == 0) { + x3[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y3") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y3") == 0) { + y3[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x4") == 0 || + strcmp(data_detection_zone_pair[i][0], "X4") == 0) { + x4[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y4") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y4") == 0) { + y4[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x5") == 0 || + strcmp(data_detection_zone_pair[i][0], "X5") == 0) { + x5[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y5") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y5") == 0) { + y5[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "x6") == 0 || + strcmp(data_detection_zone_pair[i][0], "X6") == 0) { + x6[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + else if (strcmp(data_detection_zone_pair[i][0], "y6") == 0 || + strcmp(data_detection_zone_pair[i][0], "Y6") == 0) { + y6[i_temp] = atoi(data_detection_zone_pair[i][1]); + } + } + } + } + } + /* + printf("\n----------[detection_zone]--------------\n"); + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + printf("\nzone: %d\n", zone[i]); + printf("\nx1: %d\n", x1[i]); + printf("\ny1: %d\n", y1[i]); + printf("\nx2: %d\n", x2[i]); + printf("\ny2: %d\n", y2[i]); + printf("\nx3: %d\n", x3[i]); + printf("\ny3: %d\n", y3[i]); + printf("\nx4: %d\n", x4[i]); + printf("\ny4: %d\n", y4[i]); + printf("\nx5: %d\n", x5[i]); + printf("\ny5: %d\n", y5[i]); + printf("\nx6: %d\n", x6[i]); + printf("\ny6: %d\n", y6[i]); + } + printf("\n-------------------------------------\n"); + */ + + if (data_detection_zone_num == 52 || data_detection_zone_num == 36) + { + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + rtn = _CGICMD_FAIL; + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + + if (fileBuf_config) { + free(fileBuf_config); + fileBuf_config = NULL; + } + + if (root == NULL) + { + printf("root_config is NULL\n"); + rtn = _CGICMD_FAIL; + } + else + { + cJSON *view_setting, *camera01, *temp_detection_zone, *detect; + + view_setting = cJSON_GetObjectItem(root, "view_setting"); + camera01 = cJSON_GetObjectItem(view_setting, "camera01"); + temp_detection_zone = cJSON_GetObjectItem(camera01, "detection_zone"); + + int i = 0; + cJSON_ArrayForEach(detect, temp_detection_zone) + { + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + if ((i + 1) == zone[j]) + { + cJSON_ReplaceItemInObject(detect, "x1", cJSON_CreateNumber(x1[j])); + cJSON_ReplaceItemInObject(detect, "y1", cJSON_CreateNumber(y1[j])); + cJSON_ReplaceItemInObject(detect, "x2", cJSON_CreateNumber(x2[j])); + cJSON_ReplaceItemInObject(detect, "y2", cJSON_CreateNumber(y2[j])); + cJSON_ReplaceItemInObject(detect, "x3", cJSON_CreateNumber(x3[j])); + cJSON_ReplaceItemInObject(detect, "y3", cJSON_CreateNumber(y3[j])); + cJSON_ReplaceItemInObject(detect, "x4", cJSON_CreateNumber(x4[j])); + cJSON_ReplaceItemInObject(detect, "y4", cJSON_CreateNumber(y4[j])); + + if (data_detection_zone_num == 52) { + cJSON_ReplaceItemInObject(detect, "x5", cJSON_CreateNumber(x5[j])); + cJSON_ReplaceItemInObject(detect, "y5", cJSON_CreateNumber(y5[j])); + cJSON_ReplaceItemInObject(detect, "x6", cJSON_CreateNumber(x6[j])); + cJSON_ReplaceItemInObject(detect, "y6", cJSON_CreateNumber(y6[j])); + } + else { + cJSON_ReplaceItemInObject(detect, "x5", cJSON_CreateNumber(0)); + cJSON_ReplaceItemInObject(detect, "y5", cJSON_CreateNumber(0)); + cJSON_ReplaceItemInObject(detect, "x6", cJSON_CreateNumber(0)); + cJSON_ReplaceItemInObject(detect, "y6", cJSON_CreateNumber(0)); + } + } + } + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + rtn = _CGICMD_SUCCESS; + printf("\n--------------------reload 3\n"); + reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open config.json \n"); + rtn = _CGICMD_FAIL; + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + else + { + printf("Fail detection_zone numbers (data_detection_zone_num: %d)\n", data_detection_zone_num); + rtn = _CGICMD_FAIL; + } + } + else + rtn = _CGICMD_FAIL; + + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_SUCCESS) + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + //sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #31\n"); + closesocket(cli_socket); + } +#if 0 + else if (strncmp(urlBuffer, "/get_jsonclassid=", 17) == 0) + { + memset(msg, 0x00, sizeof(msg)); + + char Cmd[MAX_CMD_SIZE] = { 0 }; + memset(Cmd, 0x00, sizeof(Cmd)); + strcpy(Cmd, urlBuffer + 17); + + get_classname(atoi(Cmd), msg); + + strcpy(beforeSendBuffer, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-123\n"); + + closesocket(cli_socket); + + } +#endif + else if (strncmp(urlBuffer, "/get_cloud_statue", 17) == 0) + { + strcpy(beforeSendBuffer, ""); + strcat(beforeSendBuffer, SystemSetting.cloud_statue); + strcat(beforeSendBuffer, ",,,"); + strcat(beforeSendBuffer, SystemSetting.cloud_v2_statue); + strcat(beforeSendBuffer, ",,,"); + strcat(beforeSendBuffer, SystemSetting.cloud_record_v2_statue); + + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-122\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/do_cloud_v2_statue", 19) == 0) + { + if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0) + { + //for (int count_delay = 0; count_delay < 5; count_delay++) + if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) + { + //if (QueueSize(_GETALARMMOTION) < 1) + { + + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "cloud_v2"); + + if (strlen(SystemSetting.cloud_v2_content) >= 1) { + strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); + } + else + q_info.cloud_v2_aiengine[0] = '\0'; + + //strcpy(SystemSetting.cloud_v2_statue, ""); + + pthread_mutex_lock(&mutex_getalarmmotion); + QueuePush(q_info, _GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + //break; + } + //usSleep(100000); + } + } + + strcpy(beforeSendBuffer,""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-1231\n"); + + } +#if 0 + else if (strncmp(urlBuffer, "/do_cloud_record_v2_statue", 26) == 0) + { + if (strcmp(SystemSetting.enable_cloud_record_v2, "Yes") == 0) + { + //for (int count_delay = 0; count_delay < 5; count_delay++) + if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) + { + //if (QueueSize(_GETALARMMOTION) < 1) + { + QueueInfo q_info = { 0 }; + strcpy(q_info.post_url, "cloud_record_v2"); + + if (strlen(SystemSetting.cloud_record_v2_content) >= 1) { + strcpy(q_info.record_cloud_v2_aiengine, SystemSetting.cloud_record_v2_content); + } + else + q_info.record_cloud_v2_aiengine[0] = '\0'; + + //strcpy(SystemSetting.cloud_record_v2_statue, ""); + pthread_mutex_lock(&mutex_getalarmmotion); + QueuePush(q_info, _GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + //break; + } + //usSleep(100000); + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38-12312\n"); + + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/ptzcontrol?enable_ptz=Yes", 26) == 0) + { + memset(msg, 0x00, sizeof(msg)); + + if (IsPTZ() == 1) + { + //UpdatePTZIPcamSetting(); + + int iHomePreset = GetHomePreset(); + + if (iHomePreset >= 0 && iHomePreset <= 256) + { + if (IsPTZatHomePos() != 1) + { + GoPreset(iHomePreset); + } + + StartStopAutopan(1); + + /*int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + strcpy(viewChannelData[0].ptz_enable_tracking, "Yes"); + write_to_enable_tracking("Yes"); + + /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, + viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + UpdatePTZConfigSetting(); + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + + //if (viewChannelData[0].ptz_tracking_resume_dwell) + //SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + //else + //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); + + //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); + //StartPTZtrackingThread(); + + sprintf(msg, "Start PTZ success."); + } + else + { + sprintf(msg, "Please setup the camera at Home position and click Start button."); + } + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/ptzcontrol?enable_ptz=No", 25) == 0) + { + memset(msg, 0x00, sizeof(msg)); + + if (IsPTZ() == 1) + { + StartStopAutopan(0); + + /*int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + strcpy(viewChannelData[0].ptz_enable_tracking, "No"); + write_to_enable_tracking("No"); + + /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, + viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + UpdatePTZConfigSetting(); + + //StopPTZtrackingThread(); + + sprintf(msg, "Stop PTZ success."); + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/ptzcontrol?go_preset=", 22) == 0) + { + if (IsPTZ() == 1) + { + //Stop PTZ + StopPtz(); + + //Go Preset + char sPresetNumber[10] = { 0 }; + memset(sPresetNumber, 0x00, sizeof(sPresetNumber)); + strcpy(sPresetNumber, urlBuffer + 22); + + int iPreset_number = 0; + if (strlen(sPresetNumber) > 0) + iPreset_number = atoi(sPresetNumber); + + GoPreset(iPreset_number); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "This device is not support PTZ."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + } + else if (strncmp(urlBuffer, "/ptzcontrol?set&zone=", 21) == 0) + { + if (IsPTZ() == 1) + { + //Stop PTZ + StopPtz(); + + //Go Preset + char sZone[10] = { 0 }; + memset(sZone, 0x00, sizeof(sZone)); + strncpy(sZone, urlBuffer + 21,1); + + int index_zone = -1; + if (strlen(sZone) > 0) + index_zone = atoi(sZone); + + if (index_zone >= 0) { + ///ptzcontrol?set&zone=0&preset=1 + char sPreset[10] = { 0 }; + memset(sPreset, 0x00, sizeof(sPreset)); + strcpy(sPreset, urlBuffer + 30); + + int iPreset_number = -1; + if (strlen(sPreset) > 0) + iPreset_number = atoi(sPreset); + + if (iPreset_number >= 0) { + + g_check_if_change_preset = 1; + + strcpy(viewDetectionZone[0][index_zone].ptz_zone_to_preset, sPreset); + + /* + int zone_to_preset[4]; + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + //strcpy(viewChannelData[0].ptz_enable_tracking, "No"); + //write_to_enable_tracking("No"); + + UpdatePTZConfigSetting(); + /* + UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, + viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + GoPreset(iPreset_number); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "This device is not support PTZ."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/get_simulated_plate?lpr=", 25) == 0) + { + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + memset(Cmd_temp, 0x00, sizeof(Cmd_temp)); + strcpy(Cmd_temp, urlBuffer + 25); + + if (strlen(Cmd_temp) >= 1) { + + int total_element_size_temp = 1; + detection_pos PosInfo_temp[MAX_DETECT_OBJECTS] = { 0 }; + int index_pos = 0; + detection_pos *pNext_temp; + pNext_temp = PosInfo_temp + index_pos; + strcpy(pNext_temp->name, "L._Plate_TWN"); + pNext_temp->left_x = 200; + pNext_temp->top_y = 200; + pNext_temp->width = 600; + pNext_temp->height = 300; + pNext_temp->center_x = pNext_temp->left_x + pNext_temp->width / 2; + pNext_temp->center_y = pNext_temp->top_y + pNext_temp->height / 2; + pNext_temp->box_x = pNext_temp->left_x; + pNext_temp->box_y = pNext_temp->top_y; + pNext_temp->box_w = pNext_temp->width; + pNext_temp->box_h = pNext_temp->height; + pNext_temp->confidence = 100.0; + pNext_temp->engine_type = FEATURE_LPR_TWN;//layerFeatureType[layer_idx]; + pNext_temp->engine_type2 = FEATURE_LPR_TWN; + pNext_temp->parent_idx = -1; + pNext_temp->car_logo_idx = -1; + pNext_temp->number_row = 1; + pNext_temp->class_id = 0; + + pNext_temp->obj_type = _PLATE; + pNext_temp->test_id = 0; + pNext_temp->image_id = 0; + + //printf("\n--------Cmd_temp:%s\n", Cmd_temp); + + strcpy(pNext_temp->properties.plate, Cmd_temp); + ReplacePlateWithDB(PosInfo_temp, total_element_size_temp, featureType, tracking_channel_idx); + AddTWPlateDASH(PosInfo_temp, total_element_size_temp, featureType); + PlateFilterForParkingPlot(PosInfo_temp, total_element_size_temp, featureType, tracking_channel_idx); + //printf("\n--------pNext_temp->properties.plate:%s\n", pNext_temp->properties.plate); + + //for (int index_temp = 0; index_temp < total_element_size_temp; index_temp++) + { + int index_temp = 0; + pNext_temp = PosInfo_temp + index_temp; + //printf("\n%d plate name = %s\n", index_temp, pNext_temp->properties.plate); + sprintf(beforeSendBuffer_xtra,"LPR:%s,confidence:%d\n", pNext_temp->properties.plate, (int)pNext_temp->confidence); + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3212\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getconfig?", 11) == 0) || (strncmp(urlBuffer, "/setconfig?", 11) == 0)) + { + pthread_mutex_lock(&mutex_config_json); + + //printf("\n[web process]start 24\n"); + char Cmd[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd, urlBuffer + 11); + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket,Cmd,(int)strlen(Cmd)); + #endif //_DEBUG_AMBA + CgiCmdType type; + if (strncmp(urlBuffer, "/getconfig?", 11) == 0) { + type = _CGICMD_GET; + //printf("\n[web process]start 24-2\n"); +#if 0 + GetAidaPort(); +#endif + //printf("\n[web process]start 24-2-2\n"); + + //strcpy(accountData[0].account_aida_port, "8592"); + + if(strlen(accountData[0].account_aida_port)>= 1) + strcpy(aida_port_for_cgicmd,accountData[0].account_aida_port); + if (strlen(accountData[0].account_username) >= 1) + strcpy(aida_username_for_cgicmd, accountData[0].account_username); + //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); + strcpy(aida_device_name_for_cgicmd, g_device_name); + //printf("\n[web process]start 24-3\n"); + } + else { + type = _CGICMD_SET; // /setconfig? + check_if_correct_post = 0; + } + CgiCmdRtnCode rtn = cgicmd_process(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //CgiCmdRtnCode rtn = _CGICMD_SUCCESS; + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn, beforeSendBuffer_xtra); + if (rtn == _CGICMD_RELOAD) + { + + g_write_config_file_dirty_flag = 0; + + write_config(); + + //usSleep(1000000); + printf("\n--------------------reload 4\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + + //printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + else if (rtn == _CGICMD_SUCCESS) + { + //printf("\nhellllo\n"); + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg_temp, "Success."); + //printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + //printf("\nhellllo2\n"); + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + pthread_mutex_unlock(&mutex_config_json); + closesocket(cli_socket); + //printf("\nhellllo3\n"); + + + + } +#endif +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/python?getfilelist=all", 23) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char sFileList[60000] = { 0 }; + + readFolderList(sFileList); + + strcpy(beforeSendBuffer_xtra, sFileList); + printf("sFileList: %s\n", sFileList); + } + else { + strcpy(beforeSendBuffer_xtra, ""); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythonget?file=", strlen("/pythonget?file=")) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char Cmd[512] = { 0 }; + char sOutput[10240]; + strcpy(Cmd, urlBuffer + 16); + + printf("get file name = %s \n", Cmd); + + readPythonFile(Cmd, sOutput); + // printf("\nfile!!!\n"); + + // 2024-09-26 switch py or refresh web need to clear buffer + for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) + { + memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); + } + // 2024-09-26 switch py or refresh web need to reset index + g_uiWebPythonCurrentBufferIndex = 0; + g_uiWebPythonLastBufferIndex = 0; + + strcpy(beforeSendBuffer_xtra, sOutput); + } + else { + + strcpy(beforeSendBuffer_xtra, ""); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythonupload?", strlen("/pythonupload?")) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + + char Cmd[PYTHON_CODE_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + strlen("/pythonupload?")); + // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 + + printf("Uploading...\n"); + char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; + urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); + strcpy(beforeSendBuffer_xtra, uploadPython(decodeCMD)); + + } + else { + strcpy(beforeSendBuffer_xtra, ""); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) { + printf("\nsend error #3552\n"); + } + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythonsave?", strlen("/pythonsave")) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + + char Cmd[PYTHON_CODE_SIZE] = { 0 }; + strcpy(Cmd, urlBuffer + strlen("/pythonsave?")); + // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 + + printf("Saving...\n"); + char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; + urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); + strcpy(beforeSendBuffer_xtra, SavePython(decodeCMD)); + + } + else { + strcpy(beforeSendBuffer_xtra, "Save python file failed !!"); + } + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) { + printf("\nsend error #3552\n"); + } + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythondelete?file=", 19) == 0) + { + char DeleteMessage_xtra[BUFSIZE] = { 0 }; + char SendDeleteStatus[BUFSIZE] = {0}; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char Cmd[512] = { 0 }; + strcpy(Cmd, urlBuffer + 14); + + printf("cmd = %s \n", Cmd); + + strcpy(Cmd, urlBuffer + 19); + + printf("get file name = %s \n", Cmd); + + deletePythonFile(Cmd); + if (g_cWebPythonDeleteStatus == 1) + { + sprintf(SendDeleteStatus, "%s was deleted successfully.",Cmd); + } + else + { + sprintf(SendDeleteStatus, "Failed to delete %s.",Cmd); + } + + } + else { + sprintf(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + int sendBufferSize = SetHttpResponse(DeleteMessage_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendDeleteStatus), SendDeleteStatus); + if (send(cli_socket, DeleteMessage_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(SendDeleteStatus, 0, sizeof(SendDeleteStatus)); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/python?playfile=", 17) == 0) + { + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + char Cmd[512] = { 0 }; + strcpy(Cmd, urlBuffer + 17); + + printf("cmd = %s \n", Cmd); + } + else { + strcpy(beforeSendBuffer_xtra, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + //strcpy(beforeSendBuffer_xtra, sFileList); + + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/getconfigfile?ch=all", 21) == 0) + { + pthread_mutex_lock(&mutex_config_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + //char filename[] = config_bakPATH; + char *filename = configPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/getconfigfile?ch=all", 21) == 0) { + //type = _CGICMD_GET; + + cJSON *view_setting, *system_setting; + view_setting = cJSON_GetObjectItem(root, "view_setting"); + system_setting = cJSON_GetObjectItem(root, "system_setting"); + + char *JsonString_view_setting = cJSON_PrintUnformatted(view_setting); + char *JsonString_system_setting = cJSON_PrintUnformatted(system_setting); + + if (JsonString_view_setting != NULL && JsonString_system_setting != NULL) { + + //printf("\n-------JsonString_view_setting:%s\n", JsonString_view_setting); + + if (strlen(accountData[0].account_aida_port) >= 1) + strcpy(aida_port_for_cgicmd, accountData[0].account_aida_port); + if (strlen(accountData[0].account_username) >= 1) + strcpy(aida_username_for_cgicmd, accountData[0].account_username); + //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); + strcpy(aida_device_name_for_cgicmd, g_device_name); + + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"127.0.0.1"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"127.0.0.1", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"username\":\"guest\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"username\":\"guest\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"password\":\"GP12345\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"password\":\"GP12345\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"channel_id\":\"\""); + if (loc != NULL) { + char temp[256] = "\"channel_id\":\"0\""; + char *temp2 = StrReplace(JsonString_view_setting, "\"channel_id\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"camera_name\":\"\""); + if (loc != NULL) { + char temp[1024] = { 0 }; + sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "\"camera_name\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"47.176.29.11"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"47.176.29.11", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "http_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "http_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + + } + } + + { + char *loc = strstr(JsonString_view_setting, "video_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "video_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + strcpy(beforeSendBuffer_xtra, "{\"view_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_view_setting); + strcat(beforeSendBuffer_xtra, ",\"system_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_system_setting); + strcat(beforeSendBuffer_xtra, ",\"g_check_if_get_picture_not_OK\":"); + char temp_picture[10] = { 0 }; + sprintf(temp_picture, "%d", g_check_if_get_picture_not_OK); + strcat(beforeSendBuffer_xtra, temp_picture); + strcat(beforeSendBuffer_xtra, ",\"g_check_h264_gop\":"); + char temp_gop[10] = { 0 }; + sprintf(temp_gop, "%d", g_check_h264_gop); + strcat(beforeSendBuffer_xtra, temp_gop); + strcat(beforeSendBuffer_xtra, "}"); + } + + if (JsonString_view_setting) { + free(JsonString_view_setting); + JsonString_view_setting = NULL; + } + if (JsonString_system_setting) { + free(JsonString_system_setting); + JsonString_system_setting = NULL; + } + + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + pthread_mutex_unlock(&mutex_config_json); + closesocket(cli_socket); + } +#endif +#if 0 + else if (strncmp(urlBuffer, "/getjvcconfigfile?ch=all", 24) == 0) + { + pthread_mutex_lock(&mutex_config_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "jvc_config.json"); + + //char filename[] = config_bakPATH; + char *filename = configPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/getjvcconfigfile?ch=all", 24) == 0) { + //type = _CGICMD_GET; + + cJSON *view_setting, *system_setting; + view_setting = cJSON_GetObjectItem(root, "view_setting"); + system_setting = cJSON_GetObjectItem(root, "system_setting"); + + char *JsonString_view_setting = cJSON_PrintUnformatted(view_setting); + char *JsonString_system_setting = cJSON_PrintUnformatted(system_setting); + + if (JsonString_view_setting != NULL && JsonString_system_setting != NULL) { + + //printf("\n-------JsonString_view_setting:%s\n", JsonString_view_setting); + + if (strlen(accountData[0].account_aida_port) >= 1) + strcpy(aida_port_for_cgicmd, accountData[0].account_aida_port); + if (strlen(accountData[0].account_username) >= 1) + strcpy(aida_username_for_cgicmd, accountData[0].account_username); + //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); + strcpy(aida_device_name_for_cgicmd, g_device_name); + + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"127.0.0.1"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"127.0.0.1", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"username\":\"guest\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"username\":\"guest\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, ",\"password\":\"GP12345\","); + if (loc != NULL) { + char temp[256] = ","; + char *temp2 = StrReplace(JsonString_view_setting, ",\"password\":\"GP12345\",", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"channel_id\":\"\""); + if (loc != NULL) { + char temp[256] = "\"channel_id\":\"0\""; + char *temp2 = StrReplace(JsonString_view_setting, "\"channel_id\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "\"camera_name\":\"\""); + if (loc != NULL) { + char temp[1024] = { 0 }; + sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "\"camera_name\":\"\"", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "ip\":\"47.176.29.11"); + if (loc != NULL) { + char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"47.176.29.11", "ip\":\"localhost"); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + { + char *loc = strstr(JsonString_view_setting, "http_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "http_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + + } + } + + { + char *loc = strstr(JsonString_view_setting, "video_port\":\"80"); + if (loc != NULL) { + char temp[1024]; + sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); + char *temp2 = StrReplace(JsonString_view_setting, "video_port\":\"80", temp); + strcpy(JsonString_view_setting, temp2); + if (temp2 != NULL) { + free(temp2); + temp2 = NULL; + } + } + } + + strcpy(beforeSendBuffer_xtra, "{\"view_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_view_setting); + strcat(beforeSendBuffer_xtra, ",\"system_setting\":"); + strcat(beforeSendBuffer_xtra, JsonString_system_setting); + strcat(beforeSendBuffer_xtra, ",\"g_check_if_get_picture_not_OK\":"); + char temp_picture[10] = { 0 }; + sprintf(temp_picture, "%d", g_check_if_get_picture_not_OK); + strcat(beforeSendBuffer_xtra, temp_picture); + strcat(beforeSendBuffer_xtra, "}"); + } + + if (JsonString_view_setting) { + free(JsonString_view_setting); + JsonString_view_setting = NULL; + } + if (JsonString_system_setting) { + free(JsonString_system_setting); + JsonString_system_setting = NULL; + } + + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + pthread_mutex_unlock(&mutex_config_json); + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/getemailsfile", strlen("/getemailsfile")) == 0) { + + if (strlen(IPCAMService.auth_password) >= 8) { + strcpy(beforeSendBuffer, "1"); + } + else { + strcpy(beforeSendBuffer, "0"); + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("send(Not get emails file)"); + closesocket(cli_socket); + } +#ifdef GY_OS_AMBA + else if (strncmp(urlBuffer, "/setosd?", 8) == 0) + { + gettimeofday(&currtime_setosd, NULL); + long current_ms_setosd = (currtime_setosd.tv_sec * 1000) + (currtime_setosd.tv_usec / 1000); + + //pthread_mutex_lock(&mutex_events_json); + char Cmd[8192] = { 0 }; + strcpy(Cmd, urlBuffer + 8); + char msg[256] = { 0 }; + + if (last_ms_setosd == 0 || current_ms_setosd >= last_ms_setosd + 20) { + if (strlen(Cmd) >= 1) { + + const char *del = "&"; + char a_data_osd[MAX_SIZE_A_OSD_OBJECT][STRSPLIT_SIZE]={0}; + int a_data_osd_num = 0; + + const char *del2 = "="; + char a_data_osd_pair[MAX_SIZE_A_OSD_OBJECT][2][STRSPLIT_SIZE]={0}; + + int id_osd = -1; //1 + int x_osd = -1; //2 + int y_osd = -1; //3 + int w_osd = -1; //4 + int h_osd = -1; //5 + int color_osd = -1; //6 + int size_osd = -1; //7 + int sec_osd = -1; //8 + char text_osd[256] = { 0 }; //9 + + int bg_transparency = 0; //10 0~255 + int outline_sw = 0; //11 0:off 1:on + + + a_data_osd_num = StrSplit(Cmd, a_data_osd, del); + //printf("\n------UU:28\n"); + if (a_data_osd_num == MAX_SIZE_A_OSD_OBJECT) + { + for (int i = 0; i < a_data_osd_num; i++) + { + if (a_data_osd[i]) + { + //printf("\n%s\n", a_data_osd[i]); + StrSplit(a_data_osd[i], a_data_osd_pair[i], del2); + //printf("\n------UU:29\n"); + if (strlen(a_data_osd_pair[i][0]) >= 1 && strlen(a_data_osd_pair[i][1]) >= 1) { + + if (strcmp(a_data_osd_pair[i][0], "id") == 0 || + strcmp(a_data_osd_pair[i][0], "ID") == 0) { + id_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "x") == 0 || + strcmp(a_data_osd_pair[i][0], "X") == 0) { + x_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "y") == 0 || + strcmp(a_data_osd_pair[i][0], "Y") == 0) { + y_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "w") == 0 || + strcmp(a_data_osd_pair[i][0], "W") == 0) { + w_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "h") == 0 || + strcmp(a_data_osd_pair[i][0], "H") == 0) { + h_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "color") == 0 || + strcmp(a_data_osd_pair[i][0], "Color") == 0) { + color_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "size") == 0 || + strcmp(a_data_osd_pair[i][0], "Size") == 0) { + size_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "ms") == 0) { + sec_osd = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "bg") == 0) { + bg_transparency = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "outline") == 0) { + outline_sw = atoi(a_data_osd_pair[i][1]); + } + else if (strcmp(a_data_osd_pair[i][0], "text") == 0 || + strcmp(a_data_osd_pair[i][0], "Text") == 0) { + strcpy(text_osd, a_data_osd_pair[i][1]); + url_decode(text_osd, strlen(text_osd)); + } + } + } + } + + if (bg_transparency < 0) + bg_transparency = 0; + else if (bg_transparency > 255) + bg_transparency = 255; + + if (outline_sw > 0) + outline_sw = 1; + if (outline_sw < 0) + outline_sw = 0; + + int check_if_osd_ok = 1; + + int num_width = -1; + int num_height = -1; + //int max_length_text = -1; + + if (w_osd >= 1 && size_osd >= 1) + num_width = w_osd / size_osd; + if (h_osd >= 1 && size_osd >= 1) + num_height = h_osd / (size_osd * 2); + + /* + if (num_width >= 1 && num_height >= 1) + max_length_text = num_width * 4; + */ + int num_br = 0; + int check_if_line_too_long = 0; + int isTextEmpty = 0; + if (strstr(text_osd, "empty") != NULL) + { + isTextEmpty = 1; + } + + if (strlen(text_osd) >= 1 + && isTextEmpty == 0) { + //printf("=====> AAAAA \n"); + num_br = strstr_cnt(text_osd, "<BR>"); + + char temp_osd_text[256] = { 0 }; + strcpy(temp_osd_text, text_osd); + + char *p_osd; + char *read_point; + read_point = text_osd; + char current_osd_text[256] = { 0 }; + + for (int index_line = 0; index_line < 4; index_line++) { + + p_osd = strstr(read_point, "<BR>"); + + if (p_osd) { + memset(current_osd_text, 0x00, sizeof(current_osd_text)); + strncpy(current_osd_text, read_point, p_osd - read_point); + if (strlen(current_osd_text) >= 30 || strlen(current_osd_text) >= num_width + 1) { + check_if_line_too_long = 1; + break; + } + p_osd += 4; + read_point = p_osd; + + //strcpy(temp_osd_text, p_osd + 4); + } + else { + //memset(current_osd_text, 0x00, sizeof(current_osd_text)); + //strncpy(current_osd_text, read_point, strlen(read_point)); + + //if (strlen(temp_osd_text) >= 30 || strlen(temp_osd_text) >= num_width + 2) + if (strlen(read_point) >= 30 || strlen(read_point) >= num_width + 1) + { + check_if_line_too_long = 1; + } + break; + } + } + + //printf("get cgi osd info: \n %d, %d, %d, %d, %d, %d, %d, %d, %d \n", id_osd, x_osd, y_osd, w_osd, h_osd, color_osd, size_osd, sec_osd, strlen(text_osd)); + //printf("----------------------------------%d, %d \n", bg_transparency, outline_sw); + + if (id_osd == -1 || x_osd == -1 || y_osd == -1 || w_osd == -1 || h_osd == -1 || color_osd == -1 || size_osd == -1 || sec_osd == -1 || strlen(text_osd) == 0) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: Parameter"); + } + else if (x_osd <= 1 || x_osd >= SCALE_BOUNDING_BOX_WIDTH) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: x <= 1 || x >= 1920"); + } + else if (y_osd <= 1 || y_osd >= SCALE_BOUNDING_BOX_HEIGHT) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: y <= 1 || y >= 1080"); + } + else if (w_osd <= 1 || w_osd >= SCALE_BOUNDING_BOX_WIDTH || x_osd + w_osd >= SCALE_BOUNDING_BOX_WIDTH) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: w <= 1 || w >= 1920 || x + w >= 1920"); + } + else if (h_osd <= 1 || h_osd >= SCALE_BOUNDING_BOX_HEIGHT || y_osd + h_osd >= SCALE_BOUNDING_BOX_HEIGHT) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: h <= 1 || h >= 1080 || y + h >= 1080"); + } + else if (size_osd <= 9 || size_osd >= 51) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: size <= 25 || size >= 51"); + } + //else if (strlen(text_osd) <= 0 || strlen(text_osd) >= 100 || strlen(text_osd) >= max_length_text) { + // check_if_osd_ok = 0; + // strcpy(msg, "HTTP 200 OK, content: Error: strlen(text) <= 0 || strlen(text) >= 100 || strlen(text) >= w / size * 4"); + //} + else if (strlen(text_osd) >= 1 && (num_br >= 4 || num_height < (num_br + 2))) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: The number of BR >= 4 || (h / (font size * 2)) < (The number of row + 1)"); + } + else if (check_if_line_too_long == 1) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: The text line is too long (>= 30 || >= ((w / size) + 2)). Please use newline label BR."); + } + else if (num_width <= 4 || num_height <= 1 || w_osd * h_osd > 644253) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: w / size <= 4 || h / (size * 2) <= 1 || w * h > 644253"); + } + else if (sec_osd <= 0 || sec_osd >= 60000) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: ms <= 0 || ms >= 60000"); + } + else if (id_osd < 0 || id_osd >= 12) { + check_if_osd_ok = 0; + strcpy(msg, "HTTP 200 OK, content: Error: id_osd < 0 || id_osd >= 12"); + } + } + else if (isTextEmpty == 1) + { + //printf("=====> bbbbb \n"); + //strncpy(current_osd_text, " ", 1); + sprintf(text_osd, "%s", ""); + //sprintf(text_osd, "%s", "TESTabc123"); + } + + if (check_if_osd_ok == 1 && color_osd >= 0) { + //for (int i = 0 ; i < MAX_SIZE_OSD_ARRAY ; i++) + int i = id_osd; + if (i >= 0 && i < MAX_SIZE_OSD_ARRAY) + { + if (OSDData[i].flag_protected == 0) { + OSDData[i].id = id_osd; + OSDData[i].x = x_osd; + OSDData[i].y = y_osd; + OSDData[i].w = w_osd; + OSDData[i].h = h_osd; + OSDData[i].color = color_osd; + OSDData[i].size = size_osd; + OSDData[i].show_sec = sec_osd; + OSDData[i].bg_tran = bg_transparency; + OSDData[i].outline_sw = outline_sw; + strcpy(OSDData[i].text, text_osd); + OSDData[i].flag_protected = 1; + + //printf("----------------------------------%d, %d \n", OSDData[i].bg_tran, OSDData[i].outline_sw); + + /* + printf("\n[x,y,w,h,color,size,sec,text]:[%d,%d,%d,%d,%d,%d,%d,%s]\n", + OSDData[i].x, OSDData[i].y, OSDData[i].w, OSDData[i].h, + OSDData[i].color, OSDData[i].size, OSDData[i].sec, OSDData[i].text); + */ + strcpy(msg, "HTTP 200 OK, content: OK"); + //break; + } + } + } + } + } + + if (strlen(msg) == 0) { + strcpy(msg, "HTTP 200 OK, content: Error: Format"); + } + last_ms_setosd = current_ms_setosd; + } + else { + strcpy(msg, "HTTP 200 OK, content: Error: Busy"); + } + + strcpy(beforeSendBuffer_xtra, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + //pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/setosdtime?", 12) == 0) + { + char msg[256] = { 0 }; + + //printf("-----------------------------------\n-------------------------------------\n"); + update_system_time(); + + #if 1 + // /setosdtime?osdtime=1 + char Cmd[8192] = { 0 }; + const char *del2 = "="; + char a_data_osd_pair[1][2][STRSPLIT_SIZE]={0}; + strcpy(Cmd, urlBuffer + 12); + + if (strstr(Cmd, "osdtime=") != NULL) + { + StrSplit(Cmd, a_data_osd_pair[0], del2); + //printf("\n------UU:30\n"); + if (strlen(a_data_osd_pair[0][1]) > 0) + { + //12 0:off 1:left-top, 2:mid-top, 3:right-top, 4:left_bottom, 5:mid_bottom, 6:right:bottom + g_osdTime_sw = atoi(a_data_osd_pair[0][1]); + if (g_osdTime_sw < 0) { + g_osdTime_sw = 0; + strcpy(msg,"Please set g_osdTime_sw to 0-6."); + } + else if (g_osdTime_sw > 6) { + g_osdTime_sw = 4; //default left_bottom + strcpy(msg, "Please set g_osdTime_sw to 0-6."); + } + else { + strcpy(msg, "OK"); + } + } + else { + g_osdTime_sw = 0; + } + } + #endif + + if (strlen(msg) == 0) { + strcpy(msg,"Wrong format."); + } + + strcpy(beforeSendBuffer_xtra, msg); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3222\n"); + + //pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/geteventsfile?ch=all", 21) == 0) + { + pthread_mutex_lock(&mutex_events_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char eventsPATH[1024] = { 0 }; + strcpy(eventsPATH, exePath); + strcat(eventsPATH, "events.json"); + + //char filename[] = config_bakPATH; + char *filename = eventsPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/geteventsfile?ch=all", 21) == 0) { + //type = _CGICMD_GET; + char *JsonString = cJSON_PrintUnformatted(root); + if (JsonString != NULL) { + strcpy(beforeSendBuffer_xtra, JsonString); + free(JsonString); + JsonString = NULL; + } + } + /* + else { + type = _CGICMD_SET; // /setconfig? + strcpy(beforeSendBuffer_xtra, Cmd); + }*/ + cJSON_Delete(root); + root = NULL; + } + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #32\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 1 + else if (strncmp(urlBuffer, "/geteventscustom?num=", 21) == 0) + { + pthread_mutex_lock(&mutex_events_json); + //char Cmd[8192] = { 0 }; + //strcpy(Cmd, urlBuffer + 15); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + int default_version = 0; + + { + char Cmd_temp[MAX_CMD_SIZE] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 21); + + int check_if_not_digit = 0; + for (int index_cmd = 0; index_cmd < strlen(Cmd_temp); index_cmd++) + { + if (!isdigit(Cmd_temp[index_cmd])) + { + check_if_not_digit = 1; + break; + } + } + if (strlen(Cmd_temp) == 0) { + check_if_not_digit = 1; + } + + if (check_if_not_digit == 0) { + default_version = atoi(Cmd_temp); + } + } + + if (default_version >= 1 && default_version != 3) { + + char eventsPATH[1024] = { 0 }; + sprintf(eventsPATH,"%sevents_custom_%d.json", exePath, default_version); + + //char filename[] = config_bakPATH; + char *filename = eventsPATH; + //char *filename = config_bakPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + + cJSON *root = cJSON_Parse(fileBuf); + //g_config_root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) + { + //CgiCmdType type; + if (strncmp(urlBuffer, "/geteventscustom?num=", 21) == 0) { + //type = _CGICMD_GET; + char *JsonString = cJSON_PrintUnformatted(root); + if (JsonString != NULL) { + strcpy(beforeSendBuffer_xtra, JsonString); + free(JsonString); + JsonString = NULL; + } + } + /* + else { + type = _CGICMD_SET; // /setconfig? + strcpy(beforeSendBuffer_xtra, Cmd); + }*/ + cJSON_Delete(root); + root = NULL; + } + } + } + } + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #326\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif + // ======================================================================================== + else if ((strncmp(urlBuffer, "/getconfig?radar_position=", 26) == 0) || (strncmp(urlBuffer, "/setconfig?radar_position&", 26) == 0)) + { + } + else if ((strncmp(urlBuffer, "/getconfig?ptz_position=", 24) == 0) || (strncmp(urlBuffer, "/setconfig?ptz_position&", 24) == 0)) + { // ?i?H???U?????g + } +#if 0 + else if ((strncmp(urlBuffer, "/setradarconfig?default", 23) == 0)) + { + pthread_mutex_lock(&mutex_radar_json); + char RADAR_JSON_PATH[1024] = "/emmc/plugin/Aida_data/radar.json"; + char RADAR_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/radar_bak.json"; + + CopyFileTo(RADAR_BAK_JSON_PATH, RADAR_JSON_PATH); + + pthread_mutex_unlock(&mutex_radar_json); + update_radar_json(); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/setradarconfig?ch=1&", 21) == 0)) + { + //@TODO: cola 2022/02/23 save radar config + // kuan 2022/05/17 + pthread_mutex_lock(&mutex_radar_json); + char buf[1024] = {}; + char Cmd[8192] = {0}; + //char msg_temp[512] = {0}; + CgiCmdRtnCode rtn; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + // printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + // printf("exePath:%s\n", exePath); + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "radar.json"); + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + rtn = _CGICMD_FAIL; + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) + { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + if (fileBuf_config) + { + free(fileBuf_config); + fileBuf_config = NULL; + } + if (root == NULL) + { + printf("root_config is NULL\n"); + rtn = _CGICMD_FAIL; + } + else + { // ?g?J radar.html ???n?s?^ json ????? + strcpy(Cmd, urlBuffer + 21); + const char *del = "="; + const char *del2 = "\n"; + char name[50][STRSPLIT_SIZE]={0}; + int value = 0; + char value2[50][STRSPLIT_SIZE]={0}; + StrSplit(Cmd, name, del); // segmentation fault function work well, the reason may be the input data + //printf("\n------UU:31\n"); + cJSON *camera; + // if (*name == "enable_calibration_radar") + //{ + // printf("get enable_calibration_radar\n"); + // } + if (!(camera = cJSON_GetObjectItem(root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + } + + if (strcmp(*name, "trial_life_time") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "trial_life_time", cJSON_CreateNumber(value)); + // printf("setting radar.json trial_life_time = %d \n", value); + } + else if (strcmp(*name, "calibration_camera") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "calibration_camera", cJSON_CreateBool(inbool)); + // printf("setting radar.json calibration_camera = %d \n", inbool); + } + //@TODO cola....finish all setting + // kuan + else if (strcmp(*name, "enable_calibration_radar") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "enable_calibration_radar", cJSON_CreateBool(inbool)); + // printf("setting radar.jsonenable_calibration_radar = %d \n", inbool); + } + else if (strcmp(*name, "calibration_radar") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "calibration_radar", cJSON_CreateBool(inbool)); + // printf("setting radar.json calibration_radar = %d \n", inbool); + } + else if (strcmp(*name, "enable_camera") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_camera", cJSON_CreateBool(inbool)); + json_enable_camera_p = inbool; + // printf("setting radar.json enable_camera = %d \n", inbool); + } + else if (strcmp(*name, "world_radar_height") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "world_radar_height", cJSON_CreateNumber(value)); + // printf("setting radar.json world_radar_height = %d \n", value); + } + else if (strcmp(*name, "distance_meter") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "distance_meter", cJSON_CreateNumber(value)); + // json_distance_meter = value; // leo 09-28 + json_distance_meter_p = value; // leo 11-25 + // printf("setting radar.json distance_meter = %d \n", value); + } + else if (strcmp(*name, "distance_meter_y") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "distance_meter_y", cJSON_CreateNumber(value)); + // json_distance_meter_y = value; // steven 230111 + json_distance_meter_y_p = value; // steven 230111 + // printf("setting radar.json distance_meter = %d \n", value); + } + else if (strcmp(*name, "world_camera_height") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_height", cJSON_CreateNumber(value)); + // printf("setting radar.json world_camera_height = %d \n", value); + } + else if (strcmp(*name, "world_camera_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_degree", cJSON_CreateNumber(value)); + // printf("setting radar.json world_camera_degree = %d \n", value); + } + else if (strcmp(*name, "world_camera_degree_offset") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_degree_offset", cJSON_CreateNumber(value)); + json_world_camera_degree_offset_p = value; + // printf("setting radar.json world_camera_degree_offset = %d \n", value); + } + else if (strcmp(*name, "world_camera_home_point_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_home_point_degree", cJSON_CreateNumber(value)); + json_world_camera_home_point_degree_p = value; + // printf("setting radar.json world_camera_home_point_degree = %d \n", value); + } + else if (strcmp(*name, "world_camera_x_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_x_axis", cJSON_CreateNumber(value)); + json_world_camera_x_axis_p = value; // + // printf("setting radar.json world_camera_x_axis = %d \n", value); + } + else if (strcmp(*name, "world_camera_y_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(camera, "world_camera_y_axis", cJSON_CreateNumber(value)); + json_world_camera_y_axis_p = value; // + // printf("setting radar.json world_camera_y_axis = %d \n", value); + } + else if (strcmp(*name, "world_radar_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "world_radar_degree", cJSON_CreateNumber(value)); + // printf("setting radar.json world_radar_degree = %d \n", value); + } + else if (strcmp(*name, "enable_camera_tracking") == 0) + { + ; + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "Yes") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "enable_camera_tracking", cJSON_CreateBool(inbool)); + // printf("setting radar.json enable_camera_tracking = %d \n", inbool); + } + else if (strcmp(*name, "distance_format") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_format", cJSON_CreateString(*value2)); + // printf("setting radar.json distance_format = %s \n", *value2); + } + else if (strcmp(*name, "radar_section_degree") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "radar_section_degree", cJSON_CreateNumber(value)); + json_radar_section_degree = value; // leo 09-28 + // printf("setting radar.json radar_section_degree = %d \n", value); + } + else if (strcmp(*name, "target_x_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "target_x_axis", cJSON_CreateNumber(value)); + json_target_x_axis = value; // leo 09-28 + json_target_x_axis_p = value; // leo 11-25 + // printf("setting radar.json target_x_axis = %d \n", value); + } + else if (strcmp(*name, "target_y_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "target_y_axis", cJSON_CreateNumber(value)); + json_target_y_axis = value; // leo 09-28 + json_target_y_axis_p = value; // leo 11-25 + // printf("setting radar.json target_y_axis = %d \n", value); + } + else if (strcmp(*name, "radar_x_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "radar_x_axis", cJSON_CreateNumber(value)); + json_radar_x_axis = value; // leo 09-28 + json_radar_x_axis_p = value; // leo 11-25 + // printf("setting radar.json radar_x_axis = %d \n", value); + } + else if (strcmp(*name, "radar_y_axis") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "radar_y_axis", cJSON_CreateNumber(value)); + json_radar_y_axis = value; // leo 09-28 + json_radar_y_axis_p = value; // leo 11-25 + // printf("setting radar.json radar_y_axis = %d \n", value); + } + else if (strcmp(*name, "ip_setting") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "ip_setting", cJSON_CreateBool(inbool)); + printf("setting radar.json ip_setting = %d \n", inbool); + } + else if (strcmp(*name, "camera_ip") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_ip", cJSON_CreateString(*value2)); + sprintf(json_ptz_ip_p, "%s", *value2); + printf("setting radar.json camera_ip = %s \n", *value2); + } + else if (strcmp(*name, "camera_port") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_port", cJSON_CreateString(*value2)); + sprintf(json_ptz_port_num_p, "%s", *value2); + printf("setting radar.json camera_port = %s \n", *value2); + } + else if (strcmp(*name, "camera_username") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_username", cJSON_CreateString(*value2)); + sprintf(json_ptz_username_p, "%s", *value2); + printf("setting radar.json camera_username = %s \n", *value2); + } + else if (strcmp(*name, "camera_password") == 0) + { + strcpy(Cmd, urlBuffer + 22 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_password", cJSON_CreateString(*value2)); + sprintf(json_ptz_password_p, "%s", *value2); + printf("setting radar.json camera_password = %s \n", *value2); + } + // kuan + char *JsonString = cJSON_Print(root); + FILE *fp; + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn = _CGICMD_SUCCESS; + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open radar.json \n"); + rtn = _CGICMD_FAIL; + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (rtn == _CGICMD_SUCCESS) + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + // sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + char sendBuffer_xtra[BUFSIZE * 8] = {0}; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) + perror("send error radar.json"); + // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE + if (root) + { + cJSON_Delete(root); + root = NULL; + } + } + } + pthread_mutex_unlock(&mutex_radar_json); + closesocket(cli_socket); + } +#endif + // ======================================================================================== +#ifdef GY_OS_AMBA +#if 0 + else if ((strncmp(urlBuffer, "/is_send_pcl", strlen("/is_send_pcl")) == 0)) + { + char Msg[256] = {0}; + g_bIsSendTofPCD = !g_bIsSendTofPCD; + sprintf(Msg, "%d", g_bIsSendTofPCD); + printf("[nweb.c] /is_send_pcl CGI - json str : %s\n\n", Msg); + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/is_send_pcl] send error\n"); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/gettof3dpcd", strlen("/gettof3dpcd")) == 0) + { + char* contentBuffer_pcd = NULL; + int contentSize_pcd = 0; + int check_if_send_OK = 0; + int check_if_send_480 = 0; + + // Get the "res" parameter from the URL + char* resParam = strstr(urlBuffer, "res="); + if (resParam == NULL) { + // No "res" parameter, return an error message + pthread_mutex_lock(&mutex_write_pcd_data_S); + contentBuffer_pcd = tof_pcd_buffer_S; + contentSize_pcd = strlen(tof_pcd_buffer_S); + pthread_mutex_unlock(&mutex_write_pcd_data_S); + } + else { + // Extract the value of the "res" parameter + int resolution = atoi(resParam + strlen("res=")); + + // Return the appropriate PCD buffer based on the resolution + if (resolution == 60) { + pthread_mutex_lock(&mutex_write_pcd_data_S); + contentBuffer_pcd = tof_pcd_buffer_S; + contentSize_pcd = strlen(tof_pcd_buffer_S); + pthread_mutex_unlock(&mutex_write_pcd_data_S); + } + else if (resolution == 120) { + pthread_mutex_lock(&mutex_write_pcd_data_M); + contentBuffer_pcd = tof_pcd_buffer_M; + contentSize_pcd = strlen(tof_pcd_buffer_M); + pthread_mutex_unlock(&mutex_write_pcd_data_M); + } + else if (resolution == 480) { + pthread_mutex_lock(&mutex_write_pcd_data_L); + + FILE *fp = fopen("/emmc/plugin/Aida/pcl/pcd/tof_pcd_data_L.txt", "r"); + + // T{ɮ׬O_\} + if (fp == NULL) { + printf("File open failed."); + } + else { + // NƤǿ + int totalSent = 0; + int remaining = 0; + int check_if_error = 0; + while (!feof(fp)) { + // Ūƶ + char chunk[CHUNK_SIZE]; + int bytesRead = fread(chunk, 1, CHUNK_SIZE, fp); + remaining = bytesRead; + + // gJ socket + while (remaining > 0) { + int chunkSize = (remaining < CHUNK_SIZE) ? remaining : CHUNK_SIZE; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", chunkSize, chunk + (bytesRead - remaining)); + if (sendBufferSize == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + check_if_error = 1; + break; + } + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + check_if_error = 1; + break; + } + totalSent += chunkSize; + remaining -= chunkSize; + } + + if (check_if_error == 1) + break; + } + } + // O + if (fp != NULL) { + fclose(fp); + fp = NULL; + } + + pthread_mutex_unlock(&mutex_write_pcd_data_L); + bTofDataFileStart = 0; + check_if_send_480 = 1; + } + else { + // Invalid resolution parameter, return an error message + contentBuffer_pcd = "Invalid resolution parameter."; + contentSize_pcd = strlen(contentBuffer_pcd); + } + + if (check_if_send_480 == 0) { + if (contentBuffer_pcd == NULL) { + // The requested PCD buffer is not available, return an error message + contentBuffer_pcd = "PCD buffer not available."; + contentSize_pcd = strlen(contentBuffer_pcd); + + } + else if (g_bIsWritingPCD) { + // The PCD file is currently being written, return a message to try again later + contentBuffer_pcd = "File is currently being written. Please wait and try again later."; + contentSize_pcd = strlen(contentBuffer_pcd); + + } + else { + + check_if_send_OK = 1; + } + } + } + + if (check_if_send_OK == 1) { + // Lock the mutex to prevent other threads from accessing the PCD buffer while we send the response + pthread_mutex_lock(&mutex_write_pcd_data); + + // Mark the PCD file as being written to prevent other threads from accessing it + g_bIsWritingPCD = 1; + + // Send the PCD buffer as the response + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", contentSize_pcd, contentBuffer_pcd); + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + } + g_bIsWritingPCD = 0; + // Unlock the mutex to allow other threads to access the PCD buffer again + pthread_mutex_unlock(&mutex_write_pcd_data); + } + else if (check_if_send_480 == 1) { + + } + else{ + g_bIsWritingPCD = 1; + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", contentSize_pcd, contentBuffer_pcd); + + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { + printf("\n[CGI:/gettof3dpcd] send error\n"); + } + g_bIsWritingPCD = 0; + } + + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/gettofpixel?", strlen("/gettofpixel?")) == 0)) + { + // printf("urlBuffer : %s\n", urlBuffer); // URL Ex : /gettofpixel?x=1&y=2 + + float depth = 0.0; + + char Cmd[8192] = {0}; + strcpy(Cmd, urlBuffer + strlen("/gettofpixel?")); + + //int init_size = strlen(Cmd); + char delimAnd[] = "&"; + char delimEqu[] = "="; + //char delimNewLine[] = "\n"; + + char *params = strtok(Cmd, delimAnd); + + int pixelX = 0; + int pixelY = 0; + + int installAngle = 0; + int settofheight = 0; + int y_diff = 0; + double angle_diff = 0.0; + double pixelDegree = 0.0; + double pointHeight = 0.0; + + double height = 0.0; + double distance = 0.0; + + // Compare each parameter with pre-defined key, and get the value for specific application + while(params != NULL) + { + char keyValPair[2][100]={0}; + StrSplit(params, keyValPair, delimEqu); + // printf("key:%s\n", keyValPair[0]); + // printf("value:%s\n", keyValPair[1]); + + if (strstr(keyValPair[0], "x")) + { + pixelX = atoi(keyValPair[1]); + } + else if (strstr(keyValPair[0], "y")) + { + pixelY = atoi(keyValPair[1]); + } + else if (strstr(keyValPair[0], "angle")) + { + installAngle = atoi(keyValPair[1]); + } + else if (strstr(keyValPair[0], "settofheight")) + { + settofheight = atoi(keyValPair[1]); + } + + params = strtok(NULL, delimAnd); + } + + // depth = getToFDepthByPixel(pixelX, pixelY); // send request to tof driver + depth = getDepth(pixelX, pixelY); + + // calculate distance and height by depth and install angel + // --------------------------------------------------------------------- + // printf("depth (M) : %lf\n", depth); // c + + y_diff = 240 - pixelY; + // printf("pixelY : %d , y_diff : %d\n", pixelY, y_diff); + + // angle_diff = ( FoV vertical angle / 2 ) * ( y_diff / ( res_h / 2 ) ) + // FoV vertical angle : 47.2 | Resolution Height : 480 + if (y_diff != 0) + { + angle_diff = 23.6 * ( (double)y_diff / 240.0 ); + } + + pixelDegree = ((double)installAngle) - angle_diff; + + // printf("install degree : %d\n", installAngle); // theta + // printf("angle_diff : %lf\n", angle_diff); + // printf("pixelDegree : %lf\n", pixelDegree); + + pointHeight = sin( pixelDegree * (double)(PI / 180) ) * depth; // sin(theta) = a / c ( depth ) + + // printf("object to tof height (M) : %lf\n", pointHeight); + + if (settofheight) + { + g_tof_device_height = pointHeight; + height = pointHeight; + } else { + height = g_tof_device_height - pointHeight; + } + + distance = fabs(cos( pixelDegree * (double)(PI / 180) )) * depth; // cos(theta) = b / c ( depth ) + + printf("height (M) : %lf\n", height); + printf("distance (M) : %lf\n", distance); + printf("-------------------\n"); + + char Msg[256] = {0}; + sprintf(Msg, "{\"x\":\"%d\", \"y\":\"%d\", \"depth\":\"%f\", \"height\":\"%f\", \"distance\":\"%f\"}", pixelX, pixelY, depth, height, distance); // converted X, Y + printf("[nweb.c] /gettofpixel CGI - json str : %s\n\n", Msg); + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/gettofpixel] send error\n"); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/settofrange?", strlen("/settofrange?")) == 0)) + { + char Cmd[8192] = {0}; + strcpy(Cmd, urlBuffer + strlen("/settofrange?")); + //printf("[nweb.c] /settofrange CGI - URL params : %s\n", Cmd); // URL params Ex : min=0.1&max=0.5 + + //int init_size = strlen(Cmd); + //char delimAnd[] = "&"; + //char delimEqu[] = "="; + //char delimNewLine[] = "\n"; + + //char *params = strtok(Cmd, delimAnd); + + // Compare each parameter with pre-defined key, and get the value for specific application + // while(params != NULL) + // { + // char *keyValPair[2]; + // StrSplit(params, keyValPair, delimEqu); + // // printf("key:%s\n", keyValPair[0]); + // // printf("value:%s\n", keyValPair[1]); + + // if ((strncmp(keyValPair[0], "minX", strlen("minX")) == 0)) + // { + // g_min_tof_range_x = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite min x\n"); + // } + // else if ((strncmp(keyValPair[0], "minY", strlen("minY")) == 0)) + // { + // g_min_tof_range_y = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite min y\n"); + // } + // else if ((strncmp(keyValPair[0], "min", strlen("min")) == 0)) + // { + // g_min_tof_range = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite min\n"); + // } + // else if ((strncmp(keyValPair[0], "maxX", strlen("maxX")) == 0)) + // { + // g_max_tof_range_x = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite max x\n"); + // } + // else if ((strncmp(keyValPair[0], "maxY", strlen("maxY")) == 0)) + // { + // g_max_tof_range_y = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite max y\n"); + // } + // else if ((strncmp(keyValPair[0], "max", strlen("max")) == 0)) + // { + // g_max_tof_range = atof(keyValPair[1]); + // // printf("[ CGI : /settofrange ] overwrite max\n"); + // } + // // other parameters ... + + // params = strtok(NULL, delimAnd); + // } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/settofrange] send error\n"); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/gettofrange") == 0) + { + char Msg[256] = {0}; + sprintf(Msg, "{\"min_tof_range\":\"%f\", \"max_tof_range\":\"%f\", \"unit\":\"M\"}", g_min_tof_range, g_max_tof_range); + // printf("\n[nweb.c] /gettofrange CGI - json str : %s\n\n", Msg); + strcpy(contentBuffer, Msg); + + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\n[CGI:/gettofrange] send error\n"); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/gettof") == 0) + { + char tofPATH[1024] = { 0 }; + strcpy(tofPATH, exePath); + strcat(tofPATH, "tof.json"); + char *filename = tofPATH; + if (!FileExist(filename)) + printf("[CGI:/gettof] %s doesn't exist.\n", filename); + else + { + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) + { + cJSON *config_root; + char *JsonString = NULL; + config_root = cJSON_Parse(fileBuf); + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (config_root) + { + JsonString = cJSON_PrintUnformatted(config_root); + strcat(contentBuffer, JsonString); + strcpy(beforeSendBuffer, contentBuffer); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) + perror("[CGI:/gettof] send json string error"); + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + if (config_root) + { + cJSON_Delete(config_root); + config_root = NULL; + } + } + else + printf("[CGI:/gettof] tof.json parse FAIL.\n"); + } + } + // ======================================================================================== + // printf("\n[web process]start 17-5\n"); + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/settofconfig?default", 21) == 0)) + { + pthread_mutex_lock(&mutex_tof_json); + char TOF_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof.json"; + char TOF_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof_install.json"; + + CopyFileTo(TOF_INSTALL_JSON_PATH, TOF_JSON_PATH); + + pthread_mutex_unlock(&mutex_tof_json); + // update_radar_json(); // TODO + closesocket(cli_socket); + } + else if ((strncmp(urlBuffer, "/settofconfig?ch=1&", 19) == 0)) + { + // 01-31 + pthread_mutex_lock(&mutex_tof_json); + char buf[1024] = {}; + char Cmd[8192] = {0}; + //char msg_temp[512] = {0}; + CgiCmdRtnCode rtn; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + char configPATH[1024] = { 0 }; + char config_bakPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcpy(config_bakPATH, exePath); + strcat(configPATH, "tof.json"); + strcat(config_bakPATH, "tof_bak.json"); + + char *filename_config = configPATH; + if (!FileExist(filename_config)) + { + printf("%s doesn't exist.\n", filename_config); + rtn = _CGICMD_FAIL; + } + else + { + //size_t nfileSize_cofnig = ReadFileSize(filename_config); + char *fileBuf_config = ReadAllBytes(filename_config); + if (fileBuf_config) + { + cJSON *root = NULL; + root = cJSON_Parse(fileBuf_config); + + if (fileBuf_config) + { + free(fileBuf_config); + fileBuf_config = NULL; + } + if (root == NULL) + { + printf("root_config is NULL\n"); + rtn = _CGICMD_FAIL; + } + else + { + strcpy(Cmd, urlBuffer + 19); + const char *del = "="; + const char *del2 = "\n"; + char name[50][100]={0}; + int value = 0; + char value2[50][100]={0}; + StrSplit(Cmd, name, del); + + cJSON *camera; + if (!(camera = cJSON_GetObjectItem(root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + } + + if (strcmp(*name, "install_angle") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + value = atoi(*value2); + cJSON_ReplaceItemInObject(root, "install_angle", cJSON_CreateNumber(value)); + tofData.tof_install_angle = value; + // printf("setting tof.json install_angle = %d \n", value); + } + else if (strcmp(*name, "enable_camera") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_camera", cJSON_CreateBool(inbool)); + json_enable_camera_p = inbool; + tofData.tof_enable_camera = inbool; + // printf("setting tof.json enable_camera = %d \n", inbool); + } + else if (strcmp(*name, "ip_setting") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(camera, "ip_setting", cJSON_CreateBool(inbool)); + tofData.tof_ip_setting = inbool; + // printf("setting tof.json ip_setting = %d \n", inbool); + } + else if (strcmp(*name, "camera_ip") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_ip", cJSON_CreateString(*value2)); + sprintf(json_ptz_ip_p, "%s", *value2); + sprintf(tofData.tof_camera_ip, "%s", *value2); + // printf("setting tof.json camera_ip = %s \n", *value2); + } + else if (strcmp(*name, "camera_port") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_port", cJSON_CreateString(*value2)); + sprintf(json_ptz_port_num_p, "%s", *value2); + sprintf(tofData.tof_camera_port, "%s", *value2); + // printf("setting tof.json camera_port = %s \n", *value2); + } + else if (strcmp(*name, "camera_username") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_username", cJSON_CreateString(*value2)); + sprintf(json_ptz_username_p, "%s", *value2); + //sprintf(tofData.tof_camera_username, "%s", *value2); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)*value2, strlen(*value2), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); + tofData.tof_camera_username[strlen(temp_account)] = '\0'; + + // printf("setting tof.json camera_username = %s \n", *value2); + } + else if (strcmp(*name, "camera_password") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(camera, "camera_password", cJSON_CreateString(*value2)); + sprintf(json_ptz_password_p, "%s", *value2); + sprintf(tofData.tof_camera_password, "%s", *value2); + // printf("setting tof.json camera_password = %s \n", *value2); + + char temp_account[512] = { 0 }; + urlencode((unsigned char *)*value2, strlen(*value2), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); + tofData.tof_camera_password[strlen(temp_account)] = '\0'; + + } + else if (strcmp(*name, "enable_tof_ground") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_tof_ground", cJSON_CreateBool(inbool)); + tofData.enable_tof_ground = inbool; + printf("setting tof.json enable_tof_ground = %d \n", inbool); + } + else if (strcmp(*name, "enable_tof_wall") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + bool inbool = false; + if (strcmp(*value2, "true") == 0) + inbool = true; + cJSON_ReplaceItemInObject(root, "enable_tof_wall", cJSON_CreateBool(inbool)); + tofData.enable_tof_wall = inbool; + printf("setting tof.json enable_tof_wall = %d \n", inbool); + } + else if (strcmp(*name, "distance_options") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_options", cJSON_CreateString(*value2)); + sprintf(tofData.distance_options, "%s", *value2); + //printf("setting tof.json distance_options = %s \n", *value2); + } + else if (strcmp(*name, "distance_min_max") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_min_max", cJSON_CreateString(*value2)); + sprintf(tofData.distance_min_max, "%s", *value2); + //printf("setting tof.json distance_options = %s \n", *value2); + } + else if (strcmp(*name, "distance_threshold") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "distance_threshold", cJSON_CreateString(*value2)); + sprintf(tofData.distance_threshold, "%s", *value2); + //printf("setting tof.json distance_threshold = %s \n", *value2); + } + else if (strcmp(*name, "height_options") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "height_options", cJSON_CreateString(*value2)); + sprintf(tofData.height_options, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + } + else if (strcmp(*name, "height_min_max") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "height_min_max", cJSON_CreateString(*value2)); + sprintf(tofData.height_min_max, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + } + else if (strcmp(*name, "height_threshold") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "height_threshold", cJSON_CreateString(*value2)); + sprintf(tofData.height_threshold, "%s", *value2); + //printf("setting tof.json height_threshold = %s \n", *value2); + } + else if (strcmp(*name, "ground_x") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "ground_x", cJSON_CreateString(*value2)); + sprintf(tofData.ground_x, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); +#ifdef GY_OS_AMBA + g_ground_tof_range = (float)getDepth(pixelX, pixelY); +#else + g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); +#endif + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + else if (strcmp(*name, "ground_y") == 0) + { + strcpy(Cmd, urlBuffer + 20 + strlen(*name)); + StrSplit(Cmd, value2, del2); + cJSON_ReplaceItemInObject(root, "ground_y", cJSON_CreateString(*value2)); + sprintf(tofData.ground_y, "%s", *value2); + //printf("setting tof.json height_options = %s \n", *value2); + + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); +#ifdef GY_OS_AMBA + g_ground_tof_range = (float)getDepth(pixelX, pixelY); +#else + g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); +#endif + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + + + + char *JsonString = cJSON_Print(root); + FILE *fp; + if ((fp = fopen(filename_config, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + rtn = _CGICMD_SUCCESS; + + CopyFileTo(filename_config, config_bakPATH); + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open tof.json \n"); + rtn = _CGICMD_FAIL; + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (rtn == _CGICMD_SUCCESS) + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + // sprintf(msg, "Success."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Invalid operation."); + printf(msg); + strcpy(beforeSendBuffer_xtra, msg); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + char sendBuffer_xtra[BUFSIZE * 8] = {0}; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) + perror("send error tof.json"); + // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE + if (root) + { + cJSON_Delete(root); + root = NULL; + } + } + } + pthread_mutex_unlock(&mutex_tof_json); + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/stoppython", strlen("/stoppython")) == 0) //ming add 2024/08/26 + { + char response[256]; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) + { + stopPython(); + strcpy(response, "Python has been signaled to stop."); + } + else + { + strcpy(response, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html; charset=utf-8", strlen(response), response); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) { + printf("\nsend error #32\n"); + } + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythongetstatus", strlen("/pythongetstatus")) == 0) //2024/08/28 + { + g_cWebPythonStatus = 0; + // Definition + // 0: SETTING TAB python check box S + // 1: buffersize Ѽƥ` + // 2: gJMŪbP@ Row AåB Buffer + // 3: buffersize ѼƲ` + // 4: gJMŪbP@ Row ALk + // 5: b檺 python ɿXwo + unsigned int uiCMDBufferRowSize = MAX_GET_PYTHON_BUFFER_ROW_SIZE; + size_t bufferContentSize = 0; + char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 512A̦h 8 A̤jؤoY 4096 + char SendBufferStatus[BUFSIZE * 8] = {0}; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) + { + char *buffersize_ptr = strstr(urlBuffer, "buffersize="); + if (buffersize_ptr != NULL) + { + char *buffersize_value = buffersize_ptr + strlen("buffersize="); + sscanf(buffersize_value, "%d", &uiCMDBufferRowSize); + // printf("Buffersize value: %d\n", uiCMDBufferRowSize); + g_cWebPythonStatus = 1; + } + else + { + g_cWebPythonStatus = 3; + } + printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + + // C Buffer N Row + for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) + { + bufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); + // printf("[/pythongetstatus] for loop index(i) : %d , Reading g_aWebPythonBuffer2D[%d] , bufferContentSize: %zu\n", i, g_uiWebPythonLastBufferIndex, bufferContentSize); + + if (bufferContentSize > 0) + { + if (g_uiWebPythonLastBufferIndex != ((int)g_uiWebPythonCurrentBufferIndex) ) + { + g_cWebPythonStatus = 2; // gJMŪbP@ Row AåB Buffer + + } + else + { + g_cWebPythonStatus = 4; // gJMŪbP@ Row + printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); + continue; + } + } + else + { + // No data in the buffer + // printf("[/pythongetstatus] Python buffer is empty.\n"); + g_cWebPythonStatus = 5; + continue; + } + } + } + else + { + g_cWebPythonStatus = 0; + // strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + sprintf(SendBufferStatus, "{\"status\":\"%d\",\"bufferSignal\":\"%d\"}", g_cWebPythonStatus, g_cWebPythonBufferSignal); + + // printf("[/pythongetstatus] Send Data To Web : %s\n\n\n",SendBufferStatus); + printf("!!! [/pythongetstatus] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendBufferStatus), SendBufferStatus); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(SendBufferStatus, 0, sizeof(SendBufferStatus)); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/pythongetbuffer?buffersize=", strlen("/pythongetbuffer?buffersize=")) == 0) //2024/08/28 + { + + unsigned int uiCMDBufferRowSize = MAX_GET_PYTHON_BUFFER_ROW_SIZE; + size_t bufferContentSize = 0; + + char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 512A̦h 8 A̤jؤoY 4096 + char beforeSendBuffer[BUFSIZE * 8] = {0}; + + if (strcmp(SystemSetting.enable_python, "Yes") == 0) + { + char *buffersize_ptr = strstr(urlBuffer, "buffersize="); + if (buffersize_ptr != NULL) + { + char *buffersize_value = buffersize_ptr + strlen("buffersize="); + sscanf(buffersize_value, "%d", &uiCMDBufferRowSize); + // printf("Buffersize value: %d\n", uiCMDBufferRowSize); + } + else + { + // printf("Invalid URL uiCMDBufferRowSize\n"); + } + + // printf("[/pythongetbuffer] check g_cWebPythonBufferSignal:%d & uiCMDBufferRowSize:%u\n", g_cWebPythonBufferSignal, uiCMDBufferRowSize); + + // C Buffer N Row + for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) + { + bufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); + // printf("[/pythongetbuffer] for loop index(i) : %d , Reading g_aWebPythonBuffer2D[%d] , bufferContentSize: %zu\n", i, g_uiWebPythonLastBufferIndex, bufferContentSize); + + if (g_uiWebPythonLastBufferIndex >= (WEBPYTHONBUFFER_LENSIZE-1)) + { + printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n"); + g_uiWebPythonLastBufferIndex = 0; + } + if (bufferContentSize > 0) + { + if (g_uiWebPythonLastBufferIndex != ((int)g_uiWebPythonCurrentBufferIndex)) + { + // Ūbg + // printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + pthread_mutex_lock(&mutex_buffer); + // python X + printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); + strcat(sPythonBufferTemp, g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); + // MŮL row + memset(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex], 0, WEBPYTHONBUFFER_ROWSIZE); + pthread_mutex_unlock(&mutex_buffer); // + // sŪm + g_uiWebPythonLastBufferIndex++; + } + else + { + printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n"); + continue; + } + + } + else + { + // No data in the buffer + // printf("[/pythongetbuffer] Python buffer is empty.\n"); + continue; + } + + } + } + else + { + strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); + } + printf("\n\nsPythonBufferTemp : %s\n\n",sPythonBufferTemp); + sprintf(beforeSendBuffer , sPythonBufferTemp); + // printf("[/pythongetbuffer] Send Data To Web : %s\n\n\n",beforeSendBuffer); + printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(beforeSendBuffer, 0, sizeof(beforeSendBuffer)); + closesocket(cli_socket); + } + // ======================================================================================== +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getevents?", 11) == 0) || (strncmp(urlBuffer, "/setevents?", 11) == 0)) + { + pthread_mutex_lock(&mutex_events_json); + + //printf("\n[web process]start 25\n"); + + //printf("\n--------------urlBuffer:%s\n", urlBuffer); + + char Cmd[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd, urlBuffer + 11); +#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); +#endif + CgiCmdType type; + if (strncmp(urlBuffer, "/getevents?", 11) == 0) type = _CGICMD_GET; + else { + type = _CGICMD_SET; + check_if_correct_post = 0; + } + //printf("\n[web process]start cgi 25\n"); + CgiCmdRtnCode rtn = cgicmd_process_events(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //printf("\n[web process]end cgi 25\n"); + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + g_write_config_file_dirty_flag = 0; + + write_config(); + + printf("\n--------------------reload 5\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg, "Success."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33\n"); + //printf("\n[web process]end 25\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + + + } +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getcounters?", 13) == 0) || (strncmp(urlBuffer, "/setcounters?", 13) == 0)) + { + pthread_mutex_lock(&mutex_events_json); + + + //printf("\n[web process]start 2555\n"); + //printf("\n--------set counters:%s\n", urlBuffer); + + char Cmd_temp[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 13); + char Cmd[8192] = { 0 }; + int Cmd_index = 0; + for (int i = 0; i < (int)strlen(Cmd_temp); i++) { + if (i< (int)strlen(Cmd_temp)-2) { + if (!(Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '2' && Cmd_temp[i + 2] == '0')) { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + else { + Cmd[Cmd_index] = ' '; + Cmd_index++; + i += 2; + } + } + else { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + } + Cmd[Cmd_index] = '\0'; + //printf("\n--------Cmd:%s\n", Cmd); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + CgiCmdType type; + if (strncmp(urlBuffer, "/getcounters?", 13) == 0) type = _CGICMD_GET; + else type = _CGICMD_SET; + //printf("\n[web process]start cgi 25\n"); + CgiCmdRtnCode rtn = cgicmd_process_event_counters(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //printf("\n[web process]end cgi 25\n"); + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + g_write_config_file_dirty_flag = 0; + + write_config(); + + printf("\n--------------------reload 6\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg, "Success."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33--2\n"); + //printf("\n[web process]end 25\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 1 + else if ((strncmp(urlBuffer, "/getemail?", 10) == 0) || (strncmp(urlBuffer, "/setemail?", 10) == 0)) + { + pthread_mutex_lock(&mutex_events_json); + + + //printf("\n[web process]start 2555\n"); + //printf("\n--------set email:%s\n", urlBuffer); + + char Cmd_temp[8192] = { 0 }; + char msg_temp[512] = { 0 }; + strcpy(Cmd_temp, urlBuffer + 10); + char Cmd[8192] = { 0 }; + int Cmd_index = 0; + for (int i = 0; i < (int)strlen(Cmd_temp); i++) { + if (i < (int)strlen(Cmd_temp) - 2) { + if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '2' && Cmd_temp[i + 2] == '0') { + Cmd[Cmd_index] = ' '; + Cmd_index++; + i += 2; + } + else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '3' && Cmd_temp[i + 2] == 'C') { + Cmd[Cmd_index] = '<'; + Cmd_index++; + i += 2; + } + else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '3' && Cmd_temp[i + 2] == 'E') { + Cmd[Cmd_index] = '>'; + Cmd_index++; + i += 2; + } + else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '7' && Cmd_temp[i + 2] == 'C') { + Cmd[Cmd_index] = '|'; + Cmd_index++; + i += 2; + } + else { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + } + else { + Cmd[Cmd_index] = Cmd_temp[i]; + Cmd_index++; + } + } + Cmd[Cmd_index] = '\0'; + //printf("\n--------Cmd:%s\n", Cmd); + + #ifdef _DEBUG_AMBA + printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); + #endif + CgiCmdType type; + if (strncmp(urlBuffer, "/getemail?", 10) == 0) type = _CGICMD_GET; + else type = _CGICMD_SET; + //printf("\n[web process]start cgi 25\n"); + CgiCmdRtnCode rtn = cgicmd_process_email_setting(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); + //printf("\n[web process]end cgi 25\n"); + //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); + if (rtn == _CGICMD_RELOAD) + { + g_write_config_file_dirty_flag = 0; + + write_config(); + + printf("\n--------------------reload 66\n"); + sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + + } + else if (rtn == _CGICMD_SUCCESS) + { + if (type == _CGICMD_SET) { + g_write_config_file_dirty_flag = 1; + } + + if (strlen(beforeSendBuffer_xtra) == 0) + { + //sprintf(msg, "Success."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + else + { + if (strlen(beforeSendBuffer_xtra) == 0) + { + sprintf(msg_temp, "Invalid operation."); + printf(msg_temp); + strcpy(beforeSendBuffer_xtra, msg_temp); + } + } + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33--22\n"); + //printf("\n[web process]end 25\n"); + + pthread_mutex_unlock(&mutex_events_json); + closesocket(cli_socket); + } +#endif +#if 0 + else if (strcmp(urlBuffer, "/get_replace_email") == 0){ + pthread_mutex_lock(&mutex_events_json); + + char *replacement_t = NULL; + + replacement_t = StrReplace(emailData.email_content, "An apple", "A banana"); + strcpy(beforeSendBuffer_xtra, replacement_t); + free(replacement_t); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #33--2211\n"); + closesocket(cli_socket); + + pthread_mutex_unlock(&mutex_events_json); + } +#endif +#ifdef GY_OS_AMBA + else if (strcmp(urlBuffer, "/aiautotracking_json") == 0) + { + //printf("\n[web process]start 7\n"); + + char Msg[256] = { 0 }; + strcpy(beforeSendBuffer_xtra, "{\"DeviceName\":\"GYNet\","); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "\"Version\":\"%s\",", APP_VERSION); +#endif + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"Thread_Running\":%d,", g_stPTZ_Handle.iThreadRunningFlag); + strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"iTimer_send_count\":%d,", g_stPTZ_Handle.iTimer_send_count); + //strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"iPTZ_sensitivity\":%d,", g_stPTZ_Handle.iPTZ_sensitivity); + //strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"Lose_Running\":%d,", g_stPTZ_Handle.LostTime); + //strcat(beforeSendBuffer_xtra, Msg); + + //sprintf(Msg, "\"Resume_Running\":%d,", g_stPTZ_Handle.ResumTime); + //strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iEnable_tracking\":%d,", g_stPTZ_Handle.iEnable_tracking); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsAtHomePOS\":%d,", g_stPTZ_Handle.iIsAtHomePOS); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsInPreset\":%d,", g_stPTZ_Handle.iIsInPreset); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsInAutopan\":%d,", g_stPTZ_Handle.iIsInAutopan); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsInAutoTracking\":%d,", g_stPTZ_Handle.iIsInAutoTracking); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iHomePreset\":%d,", g_stPTZ_Handle.iHomePreset); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iRunPTZUpdateStatusThread_flag\":%d,", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iRunPTZTrackingThread_flag\":%d,", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iCandidateBoxCount\":%d,", g_stPTZ_Handle.iCandidateBoxCount); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iIsGetLockTrackingBox\":%d,", g_stPTZ_Handle.iIsGetLockTrackingBox); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"iLockBoxIdx\":%d,", g_stPTZ_Handle.iLockBoxIdx); + strcat(beforeSendBuffer_xtra, Msg); + + sprintf(Msg, "\"stPTZLockTrackingBox.stPTZLockTrackingBox.obj_tracking_id\":%d", g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id); + strcat(beforeSendBuffer_xtra, Msg); + + strcat(beforeSendBuffer_xtra, "}"); + + //strcat(beforeSendBuffer_xtra, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer_xtra, " "); + strcat(beforeSendBuffer_xtra, contentDescription); + } + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); + if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #188\n"); + //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + else if (strcmp(urlBuffer, "/aiautotracking_info") == 0) + { + //printf("\n[web process]start 7\n"); + + char Msg[256] = { 0 }; + strcpy(contentBuffer, "DeviceName=GYNet\r\n<br/>"); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + sprintf(Msg, "Version=%s\r\n<br/>", APP_VERSION); +#endif + strcat(contentBuffer, Msg); + + sprintf(Msg, "Thread Running = %d\r\n<br/>", g_stPTZ_Handle.iThreadRunningFlag); + strcat(contentBuffer, Msg); + + //sprintf(Msg, "iTimer_send_count = %d\r\n<br/>", g_stPTZ_Handle.iTimer_send_count); + //strcat(contentBuffer, Msg); + + //sprintf(Msg, "iPTZ_sensitivity = %d\r\n<br/>", g_stPTZ_Handle.iPTZ_sensitivity); + //strcat(contentBuffer, Msg); + + //sprintf(Msg, "Lose Running = %d\r\n<br/>", g_stPTZ_Handle.LostTime); + //strcat(contentBuffer, Msg); + + //sprintf(Msg, "Resume Running = %d\r\n<br/>", g_stPTZ_Handle.ResumTime); + //strcat(contentBuffer, Msg); + + sprintf(Msg, "iEnable_tracking=%d\r\n<br/>", g_stPTZ_Handle.iEnable_tracking); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsAtHomePOS=%d\r\n<br/>", g_stPTZ_Handle.iIsAtHomePOS); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsInPreset=%d\r\n<br/>", g_stPTZ_Handle.iIsInPreset); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsInAutopan=%d\r\n<br/>", g_stPTZ_Handle.iIsInAutopan); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsInAutoTracking=%d\r\n<br/>", g_stPTZ_Handle.iIsInAutoTracking); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iHomePreset=%d\r\n<br/>", g_stPTZ_Handle.iHomePreset); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iRunPTZUpdateStatusThread_flag=%d\r\n<br/>", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iRunPTZTrackingThread_flag=%d\r\n<br/>", g_stPTZ_Handle.iRunPTZTrackingThread_flag); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iCandidateBoxCount=%d\r\n<br/>", g_stPTZ_Handle.iCandidateBoxCount); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iIsGetLockTrackingBox=%d\r\n<br/>", g_stPTZ_Handle.iIsGetLockTrackingBox); + strcat(contentBuffer, Msg); + + sprintf(Msg, "iLockBoxIdx=%d\r\n<br/>", g_stPTZ_Handle.iLockBoxIdx); + strcat(contentBuffer, Msg); + + sprintf(Msg, "stPTZLockTrackingBox=%ld\r\n<br/>", sizeof(g_stPTZ_Handle.stPTZLockTrackingBox)); + strcat(contentBuffer, Msg); + + strcat(contentBuffer, "\r\n<br/>"); + + + + strcpy(beforeSendBuffer, contentBuffer); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse_server(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #18\n"); + //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/ptzpreset?camid=1&ai_goto_preset=", 34) == 0) + { + if (IsPTZ() == 1) + { + //Stop Autopan + //StartStopAutopan(0); + + //Go Preset + char sPresetNumber[10] = { 0 }; + memset(sPresetNumber, 0x00, sizeof(sPresetNumber)); + strcpy(sPresetNumber, urlBuffer + 34); + + int iPreset_number = 1; + if (strlen(sPresetNumber) > 0) + iPreset_number = atoi(sPresetNumber); + + GoPreset(iPreset_number); + + //usSleep(2000000); + + //Start Autopan + //StartStopAutopan(1); + + //Response + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "go preset success."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + else + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "This device is not support PTZ."); + //printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + closesocket(cli_socket); + } + } + else if (strncmp(urlBuffer, "/ptz_move_direction?", 20) == 0) + { + memset(msg, 0x00, sizeof(msg)); + if (IsPTZ() == 1) + { + char sCmd[256] = { 0 }; + memset(sCmd, 0x00, sizeof(sCmd)); + strcpy(sCmd, urlBuffer + 20); + + char spilt_move[2][STRSPLIT_SIZE]={0}; + const char *del = "&"; + int num_move = 0; + num_move = StrSplit(sCmd, spilt_move, del); + //printf("\n------UU:32\n"); + int iPan = 0; + int iTilt = 0; + + for (int i = 0; i < num_move; i++) { + char a_spilt_move[2][STRSPLIT_SIZE]={0}; + const char *del2 = "="; + int a_num_move = 0; + a_num_move = StrSplit(spilt_move[i], a_spilt_move, del2); + //printf("\n------UU:33\n"); + for (int j = 0; j < a_num_move; j++) { + if (strcmp(a_spilt_move[0], "pan") == 0) { + iPan = atoi(a_spilt_move[1]) * atoi(viewChannelData[0].ptz_speed); + } + else if (strcmp(a_spilt_move[0], "tilt") == 0) { + iTilt = atoi(a_spilt_move[1]) * atoi(viewChannelData[0].ptz_speed); //קKӧ + } + } + } + + if (iPan != 0 || iTilt != 0){ + StopPtz(); + move_PTZ_in_the_direction(iPan, iTilt); + pthread_t ptz_stop_thread_id; + if (pthread_create(&ptz_stop_thread_id, 0, ptz_stop_thread, NULL)) + { + printf("\ncreate ptz stop thread faile \n"); + } + sprintf(msg, "Move direction success."); + } + else { + sprintf(msg, "Move direction fail."); + } + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #328\n"); + + closesocket(cli_socket); + } + else if (strncmp(urlBuffer, "/ptz_stop", 9) == 0) + { + memset(msg, 0x00, sizeof(msg)); + if (IsPTZ() == 1) + { + StopPtz(); + } + else + { + sprintf(msg, "This device is not support PTZ."); + } + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #3128\n"); + + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/", 1) == 0) + { + //printf("\n[web process]start 26\n"); + char * pch; + pch = strstr(urlBuffer, "jpg"); + + if (pch == NULL) + { + //syslog(NW_SORRY, "file type not supported", firstBuffer, cli_socket); + //memset(msg, 0x00, sizeof(msg)); + + char msg_temp[512] = { 0 }; + sprintf(msg_temp, "Unknown Url"); + //printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg_temp); + //strcat(beforeSendBuffer, MSG_END_PATTERN); + + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #34\n"); + + /*printf("\n[web process]-A-1:free(contentBuffer)\n"); + free(contentBuffer); //double free + */ + //printf("\n[web process]-A-1: closesocket(client_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + else + { + //printf("\n[nweb.c]urlBuffer:\n"); + //printf(urlBuffer); + //printf("\n"); + /* convert no filename to index file */ + + if (!strncmp(&firstBuffer[0], "GET /\0", 6) || !strncmp(&firstBuffer[0], "get /\0", 6)) + strcpy(firstBuffer, "GET /example.htm"); + else + { + strcpy(firstBuffer, "GET "); + strcat(firstBuffer, urlBuffer); + firstBuffer[strlen("GET ") + strlen(urlBuffer)] = '\0'; + } + + /* work out the file type and check if we support it */ + buflen = strlen(firstBuffer); + fstr = NULL; + for (idx = 0; extensions[idx].ext != 0; idx++) + { + len = strlen(extensions[idx].ext); + //printf(extensions[idx].ext); + if (!strncmp(&firstBuffer[buflen - len], extensions[idx].ext, len)) + { + fstr = extensions[idx].filetype; + break; + } + } + + if (fstr == NULL) + { + //syslog(NW_SORRY, "file type not supported", firstBuffer, cli_socket); + char msg_temp[512] = { 0 }; + //memset(msg, 0x00, sizeof(msg)); + sprintf(msg_temp, "[0]The file %s has unknown file extension.", &firstBuffer[5]); + //printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg_temp); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + char sendBuffer[BUFSIZE_V2] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #35\n"); + } + else + { + /* execute the send command, but first check if the browser */ + /* has requested the default icon file, favicon.ico. */ + if (!strncmp(firstBuffer + 5, "/favicon.ico", 12)) + { + /* Send a null file to satisfy a request for favicon.ico */ + sprintf(tempBuffer, "HTTP/1.1 204 No Content\r\n\r\n"); + send(cli_socket, tempBuffer, strlen(tempBuffer), 0); + } + else + { + ///* open the file for reading */ + //if ((fp = fopen(&firstBuffer[5], "rb")) == NULL) + //{ + // syslog(NW_SORRY, "failed to open file", &firstBuffer[5], cli_socket); + //} + + int file_fd; + if ((file_fd = open(&firstBuffer[5], O_RDONLY)) == -1) + { + printf("Failed to open file : %s\n", &firstBuffer[5]);//ɮצSQŪ + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19-52\n"); + } + else { + int iFileLength = 0; + char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; + iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); + close(file_fd); + + /* work out the file type and check if we support it */ + buflen = strlen(urlBuffer); + fstr = NULL; + for (idx = 0; extensions[idx].ext != 0; idx++) + { + len = strlen(extensions[idx].ext); + if (!strncmp(&urlBuffer[buflen - len], extensions[idx].ext, len)) + { + fstr = extensions[idx].filetype; + break; + } + } + + if (fstr == NULL) + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19554\n"); + } + else + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: %s;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n", fstr); /*\r\nCache - Control: max - age = 30*/ + if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #20221\n"); + } + + int iSentLeft = 0; + int iSentLength = 0; + int iHaveSentLength = 0; + int iRetryCount = 5; + + + + iSentLeft = iFileLength; + + while (iSentLeft >= 1) { + iSentLength = send(cli_socket, sendBuffer_superlarge + iHaveSentLength, iSentLeft, MSG_MORE); + + if (iSentLength <= 0) + break; + + iHaveSentLength = iHaveSentLength + iSentLength; + iSentLeft = iSentLeft - iSentLength; + iRetryCount--; + + if (iSentLeft >= 1) { + //printf("\n[web process]iSentLeft: %d\n", iSentLeft); + } + + if (iRetryCount <= 0) + break; + //usSleep(100); + } + } + } + } + closesocket(cli_socket); + } + } + } + else if (strcmp(httpCommand, "POST ") == 0) + { + if (strncmp(urlBuffer, "/sendjpeg", strlen("/sendjpeg")) == 0) + { + //printf("\n[web process]start 27\n"); + char *image_buff = NULL; + int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + char httpVariables[BUFSIZE_V2] = { 0 }; + char *QuestionMarK = strstr(urlBuffer, "?"); + + if (QuestionMarK) + { + strcpy(httpVariables, QuestionMarK + 1); + //char *start = httpVariables; + char *pch; + char *pDelim = "&"; + char *pLeft = NULL; + // pch = strtok_r(httpVariables, pDelim, &pLeft); + // BUG9 : strtok_modified + pch = strtok_modified(httpVariables, pDelim, &pLeft); + while (pch != NULL) { + // string between start and delim (or end of string if delim is NULL). + if (pch) + { + char attribute[512] = { 0 };//512 + strcpy(attribute, pch); + //attribute[pDelim - start] = 0; + char att_var[10][STRSPLIT_SIZE]={0}; + char *del = "="; + //int att_var_num = 0; + //if (attribute) + { + /*att_var_num = */StrSplit(attribute, att_var, del); + //printf("\n------UU:34\n"); + if (strcmp(att_var[0], "channel") == 0) + { + tracking_channel = atoi(att_var[1]); + tracking_channel_idx = tracking_channel - 1; + } + } + //start = pDelim + 1; // Use length of your b string. + } + pch = strtok_modified(NULL, pDelim, &pLeft); + } + } + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + + } + char* pJpegStart = NULL; + char* pJpegEnd = NULL; + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) + { + pJpegStart = image_buff + i; + break; + } + } + + for (int i = nTotalBytes; i > 0; i--) + { + if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) + { + pJpegEnd = image_buff + i + 2; + break; + } + } + + //printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); + + if (!pJpegStart || !pJpegEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format(Multipart)."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not JPEG format)\n"); + + + //printf("\n[web process]-A-3: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); + closesocket(cli_socket); + + return; + } + else + { + image_buff_size = pJpegEnd - pJpegStart; + memmove(image_buff, pJpegStart, image_buff_size); + +#if 0 + printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); +#endif + + memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); + } + } + else + { + image_buff_size = nTotalContentLen; + memcpy(image_buff, contentBuffer, image_buff_size); + //DumpHex(image_buff + image_buff_size - 10, 10); + } + + if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) + { + //DumpHex(image_buff, 2); + //DumpHex(image_buff + image_buff_size - 2, 2); + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + //printf("\n[web process]-A-4: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + + /*if (layer_count == 0) + { + printf("Invalid layer count %d\n", cli_socket); + //int sendBufferSize = SetHttpResponse(sendBuffer, "HTTP/1.1 403 Forbidden", "text/html;", strlen("Invalid license key"), "Invalid license key");//20201028 sophia mark + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_403, "text/html;", strlen("Invalid license key"), "Invalid license key");//20201028 sophia add + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #37\n"); + //printf("\n[web process]-A-5: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-5: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + }*/ + +#if defined GY_OS_AMBA + GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); + + //int nNeedUpdateTrafficLightZone = 0; + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\njpeg_width: %d\n", jpeg_width); + printf("\ntab_view_width: %d\n", viewChannelData[tracking_channel_idx].tab_view_width); + printf("\ntab_view_height: %d\n", viewChannelData[tracking_channel_idx].tab_view_height); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + if (AIImage_width > 0) + { + //if (abs(viewChannelData[tracking_channel_idx].tab_view_width_ratio * viewChannelData[tracking_channel_idx].tab_view_width - AIImage_width) > 5) + //nNeedUpdateTrafficLightZone = 1; + // + viewChannelData[tracking_channel_idx].tab_view_width_ratio = (float)AIImage_width / viewChannelData[tracking_channel_idx].tab_view_width; + viewChannelData[tracking_channel_idx].tab_view_height_ratio = (float)AIImage_width / viewChannelData[tracking_channel_idx].tab_view_height; +//#ifdef GY_OS_WIN + //if (nNeedUpdateTrafficLightZone) + //UpdateTrafficLightZone(tracking_channel_idx); +//#endif + } +#endif + socketRecords[sock_info_idx].channel_id = tracking_channel; + + //double recv_clock = clock(); + //double diff = ((double)(recv_clock - begin_clock) / CLOCKS_PER_SEC); + //sprintf(msg, "log/sock-%05d_sec_%f %s.jpg", cli_socket, diff, contentDescription); + //FILE *f = fopen(msg, "wb"); + //if (f == NULL) + //{ + // printf("Error opening file!\n"); + // //exit(1); + //} + //fwrite(image_buff, image_buff_size, 1, f); + //fclose(f); + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + /* + + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nweb process: %d\n",1); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time %d:%f\n", cli_socket, dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + } + else if (strncmp(urlBuffer, "/setemailsfile", strlen("/setemailsfile")) == 0) { + //printf("\n----------urlBuffer:%s\n", urlBuffer); + + //pthread_mutex_lock(&mutex_config_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + +#if 1 + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char emails_importPATH[1024]; + strcpy(emails_importPATH, exePath); + strcat(emails_importPATH, "emails_import.json"); + + char emails_PATH[1024]; + char emails_bakPATH[1024]; + strcpy(emails_PATH, exePath); + strcpy(emails_bakPATH, exePath); + strcat(emails_PATH, "emails.json"); + strcat(emails_bakPATH, "emails_bak.json"); + + FILE *pFile; + + if ((pFile = fopen(emails_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(emails_importPATH); + char* fileBuf2 = ReadAllBytes(emails_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + if (root && s_root) + { + cJSON *auth_password; + //cJSON *s_auth_password; + auth_password = cJSON_GetObjectItem(root, "auth_password"); + //s_auth_password = cJSON_GetObjectItem(s_root, "auth_password"); + + if (auth_password) + { + size_t base64_decode_length = 0; + char EncryptKeyData[256]; + //char DecryptKeyData[256]; + memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); + //memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); + unsigned char OriEncryptData[512] = { 0 }; + + char temp_auth_password[256] = { 0 }; + memcpy(temp_auth_password,auth_password->valuestring,strlen(auth_password->valuestring)); + + base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); + memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); + + //KeyExpansion(key_email, expandedKey_email); + //unsigned char EncryptData[1 * 1024]; + //memset(EncryptData, 0x00, sizeof(EncryptData)); + //int encryptSize = AESEncryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, EncryptData, sizeof(EncryptData)); + + //EncryptData[encryptSize] = '\0'; + //int decryptSize = AESDecryptArrayToArray(EncryptData, strlen(EncryptData), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); + + strcpy(IPCAMService.auth_password, EncryptKeyData); + cJSON_ReplaceItemInObject(s_root, "auth_password", cJSON_CreateString(temp_auth_password)); + + //printf("\n----------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); + //printf("\n----------temp_auth_password:%s\n", temp_auth_password); + //printf("\n----------EncryptData:%s\n", EncryptData); + } + + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(emails_PATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(emails_PATH, emails_bakPATH); + check_if_setfile_OK = 1; + //g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read config_import.json or config.json\n"); + } + } + +#endif + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("send(Not set emails file)"); + } + else { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("send(Not set emails file#2)"); + } + + //pthread_mutex_unlock(&mutex_config_json); + + closesocket(cli_socket); + } +#if 0 + else if (strncmp(urlBuffer, "/settoffile", strlen("/settoffile")) == 0) + { + pthread_mutex_lock(&mutex_tof_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char tof_importPATH[1024]; + strcpy(tof_importPATH, exePath); + strcat(tof_importPATH, "tof_import.json"); + + char tof_PATH[1024]; + strcpy(tof_PATH, exePath); + strcat(tof_PATH, "tof.json"); + + char tof_bakPATH[1024]; + strcpy(tof_bakPATH, exePath); + strcat(tof_bakPATH, "tof_bak.json"); + + FILE *pFile; + + if ((pFile = fopen(tof_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(tof_importPATH); + char* fileBuf2 = ReadAllBytes(tof_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (root && s_root) + { + cJSON *tof_version, *tof_debug, *tof_install_angle, *tof_enable_camera, *enable_tof_ground, *enable_tof_wall, *tof_camera; + cJSON *tof_camera_ip, *tof_camera_port, *tof_camera_sub_url, *tof_auth_key, *tof_ip_setting, *tof_camera_username, *tof_camera_password; + cJSON *distance_options, *distance_threshold, *height_options, *height_threshold, *distance_min_max, *height_min_max; + cJSON *ground_x, *ground_y; + + cJSON *s_tof_camera; + + tof_version = cJSON_GetObjectItem(root, "version"); + tof_debug = cJSON_GetObjectItem(root, "debug"); + tof_install_angle = cJSON_GetObjectItem(root, "install_angle"); + tof_enable_camera = cJSON_GetObjectItem(root, "enable_camera"); + enable_tof_ground = cJSON_GetObjectItem(root, "enable_tof_ground"); + enable_tof_wall = cJSON_GetObjectItem(root, "enable_tof_wall"); + distance_options = cJSON_GetObjectItem(root, "distance_options"); + distance_threshold = cJSON_GetObjectItem(root, "distance_threshold"); + height_options = cJSON_GetObjectItem(root, "height_options"); + height_threshold = cJSON_GetObjectItem(root, "height_threshold"); + distance_min_max = cJSON_GetObjectItem(root, "distance_min_max"); + height_min_max = cJSON_GetObjectItem(root, "height_min_max"); + + ground_x = cJSON_GetObjectItem(root, "ground_x"); + ground_y = cJSON_GetObjectItem(root, "ground_y"); + + tof_camera = cJSON_GetObjectItem(root, "camera"); + s_tof_camera = cJSON_GetObjectItem(s_root, "camera"); + + if (tof_version) + { + tofData.tof_version = tof_version->valueint; + cJSON_ReplaceItemInObject(s_root, "version", cJSON_CreateNumber(tofData.tof_version)); + } + + if (tof_debug) + { + if (cJSON_IsTrue(tof_debug)) + { + tofData.tof_debug = true; + } + else + { + tofData.tof_debug = false; + } + cJSON_ReplaceItemInObject(s_root, "debug", cJSON_CreateBool(tofData.tof_debug)); + } + + if (tof_install_angle) { + tofData.tof_install_angle = tof_install_angle->valueint; + cJSON_ReplaceItemInObject(s_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); + } + + if (tof_enable_camera) { + if (cJSON_IsTrue(tof_enable_camera)) + { + tofData.tof_enable_camera = true; + } + else + { + tofData.tof_enable_camera = false; + } + cJSON_ReplaceItemInObject(s_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); + } + + if (enable_tof_ground) { + if (cJSON_IsTrue(enable_tof_ground)) + { + tofData.enable_tof_ground = true; + } + else + { + tofData.enable_tof_ground = false; + } + cJSON_ReplaceItemInObject(s_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); + } + + if (enable_tof_wall) { + if (cJSON_IsTrue(enable_tof_wall)) + { + tofData.enable_tof_wall = true; + } + else + { + tofData.enable_tof_wall = false; + } + cJSON_ReplaceItemInObject(s_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); + } + + if (distance_options) + { + strcpy(tofData.distance_options, distance_options->valuestring); + cJSON_ReplaceItemInObject(s_root, "distance_options", cJSON_CreateString(tofData.distance_options)); + } + + if (distance_min_max) { + strcpy(tofData.distance_min_max, distance_min_max->valuestring); + cJSON_ReplaceItemInObject(s_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); + } + + if (distance_threshold) { + strcpy(tofData.distance_threshold, distance_threshold->valuestring); + cJSON_ReplaceItemInObject(s_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); + } + + if (height_options) { + strcpy(tofData.height_options, height_options->valuestring); + cJSON_ReplaceItemInObject(s_root, "height_options", cJSON_CreateString(tofData.height_options)); + } + + if (height_min_max) { + strcpy(tofData.height_min_max, height_min_max->valuestring); + cJSON_ReplaceItemInObject(s_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); + } + + + if (ground_x) { + strcpy(tofData.ground_x, ground_x->valuestring); + cJSON_ReplaceItemInObject(s_root, "ground_x", cJSON_CreateString(tofData.ground_x)); + } + + if (ground_y) { + strcpy(tofData.ground_y, ground_y->valuestring); + cJSON_ReplaceItemInObject(s_root, "ground_y", cJSON_CreateString(tofData.ground_y)); + } + + if (ground_x || ground_y) { + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); +#ifdef GY_OS_AMBA + g_ground_tof_range = (float)getDepth(pixelX, pixelY); +#else + g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); +#endif + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + + if (height_threshold) { + strcpy(tofData.height_threshold, height_threshold->valuestring); + cJSON_ReplaceItemInObject(s_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); + } + + if (tof_camera) { + tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); + tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); + tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); + tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); + tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); + tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); + tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); + + if (tof_camera_ip) { + strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); + } + + if (tof_camera_port) { + strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); + } + + if (tof_camera_sub_url) { + strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); + } + + if (tof_auth_key) { + strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); + cJSON_ReplaceItemInObject(s_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); + } + + if (tof_ip_setting) { + if (cJSON_IsTrue(tof_ip_setting)) + { + tofData.tof_ip_setting = true; + } + else + { + tofData.tof_ip_setting = false; + } + cJSON_ReplaceItemInObject(s_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); + } + + if (tof_camera_username) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); + tofData.tof_camera_username[strlen(temp_account)] = '\0'; + + cJSON_ReplaceItemInObject(s_tof_camera, "camera_username", cJSON_CreateString(tof_camera_username->valuestring)); + } + + if (tof_camera_password) { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); + memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); + tofData.tof_camera_password[strlen(temp_account)] = '\0'; + + cJSON_ReplaceItemInObject(s_tof_camera, "camera_password", cJSON_CreateString(tof_camera_password->valuestring)); + } + } + + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(tof_PATH, "w"); + if (f != NULL) + { + + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(tof_PATH, tof_bakPATH); + + check_if_setfile_OK = 1; + //g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read tof_import.json or tof.json\n"); + } + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not settoffile)\n"); + } + else { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not settoffile#2)\n"); + } + + pthread_mutex_unlock(&mutex_tof_json); + closesocket(cli_socket); + } +#endif + else if (strncmp(urlBuffer, "/setconfigfile", strlen("/setconfigfile")) == 0) { + //printf("\n----------urlBuffer:%s\n", urlBuffer); + + pthread_mutex_lock(&mutex_config_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer+ recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char config_importPATH[1024]; + strcpy(config_importPATH, exePath); + strcat(config_importPATH, "config_import.json"); + + char config_PATH[1024]; +#ifdef GY_OS_NOVA + char config_smallPATH[1024]; +#endif + char config_bakPATH[1024]; + strcpy(config_PATH, exePath); +#ifdef GY_OS_NOVA + strcpy(config_smallPATH, exePath); +#endif + strcpy(config_bakPATH, exePath); + strcat(config_PATH, "config.json"); +#ifdef GY_OS_NOVA + strcat(config_smallPATH, "config_small.json"); +#endif + strcat(config_bakPATH, "config_bak.json"); + + FILE *pFile; + + if ((pFile = fopen(config_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(config_importPATH); + char* fileBuf2 = ReadAllBytes(config_PATH); +#ifdef GY_OS_NOVA + char* fileBuf3 = ReadAllBytes(config_smallPATH); +#endif + +#ifdef GY_OS_NOVA + if (fileBuf && fileBuf2 && fileBuf3) { +#else + if (fileBuf && fileBuf2) { +#endif + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); +#ifdef GY_OS_NOVA + cJSON *root_small = cJSON_Parse(fileBuf3); +#endif + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } +#ifdef GY_OS_NOVA + if (fileBuf3) { + free(fileBuf3); + fileBuf3 = NULL; + } +#endif + +#ifdef GY_OS_NOVA + if (root && s_root && root_small) +#else + if (root && s_root) +#endif + { + cJSON *view_setting,*camera,*camera_name,*levenshtein_distance,*min_characters,*max_characters,*obj_min_proportion,*obj_max_proportion, + *confidence,*confidence2,*confidence3, *confidence4,*count_zone,*enable_lpr_db,*enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, // joy add + *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking,*ptz_tracking_mode,*ptz_tracking_by_enter_zone, + *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, + *enable_unknown_object, *ivs_mode, *enable_ivs_person_detection, *assign_ivs_object_to, *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, + *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*ptz_sensitivity,*ptz_tracking_resume_dwell,*cJSON_enable_only_show_metadata1,*getnetwork_buffer_id, + *tab_view_size,*enable_anpr,*enable_face,*enable_traffic,*enable_logo, + *temp_detection_zone,*detect,*enable_traffic_light,*detection_time,*metadata1,*metadata2, *metadata_stop,*link_to_counter,*enable_direction1, + *enable_direction2, *direction1,*direction2,*no_parking_time,*no_parking_time_in_minute,*queuing_count,*ptz_zone_to_preset,*enable_speed,*enable_radar_speed, *enable_ivs_zone, + *set_distance,*world_distance_unit,*world_distance_side1, *world_distance_side2,*world_time_unit,*parking_space, *parking_line, + *point_number,*x1,*y1,*x2,*y2,*x3,*y3, *x4, *y4, *x5, *y5, *x6, *y6, + *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; + cJSON *trigger_events_0, *trigger_events_1, *trigger_events_2,*trigger_events_3, *trigger_events_4, *trigger_events_5, *trigger_events_6, *trigger_events_7,*checked,*detect_event_name,*post_event_name, + *counter_name/*,*counter_cust_name*/,*counter_increment; + cJSON *s_view_setting, *s_camera, *s_detection_zone, *s_detect,*s_trigger_events_0, *s_trigger_events_1, *s_trigger_events_2, *s_trigger_events_3, *s_trigger_events_4, *s_trigger_events_5, *s_trigger_events_6, *s_trigger_events_7; + + cJSON *trigger_events_temp, *s_trigger_events_temp; +#ifdef GY_OS_NOVA + cJSON *view_setting_small, *system_setting_small, *camera_small/*, *count_zone_small*/, *detection_zone_small, *detect_small/*, *point_number_small*/, + *x1_small, *y1_small, *x2_small, *y2_small, *x3_small, *y3_small, *x4_small, *y4_small, *x5_small, *y5_small, *x6_small, *y6_small; +#endif + view_setting = cJSON_GetObjectItem(root, "view_setting"); + s_view_setting = cJSON_GetObjectItem(s_root, "view_setting"); +#ifdef GY_OS_NOVA + view_setting_small = cJSON_GetObjectItem(root_small, "view_setting"); +#endif + if (view_setting) { + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + s_camera = cJSON_GetObjectItem(s_view_setting, CameraID); +#ifdef GY_OS_NOVA + camera_small = cJSON_GetObjectItem(view_setting_small, CameraID); +#endif + if (camera) { + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); + plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); + plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); + enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); + enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); + enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); + enable_track = cJSON_GetObjectItem(camera, "enable_track"); + ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); + ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); + ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); + ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); + ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); + enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); + ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); + ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); + ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); + ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); + ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); + enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); + enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); + assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); + enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); + enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); + enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); + enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); + enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); + enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); + enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); + dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); + unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); + unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); + confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); + confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); + dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); + dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); + person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); + getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); + red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); + no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); + no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); + no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); + no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); + ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); + ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); + cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + enable_face = cJSON_GetObjectItem(camera, "enable_face"); + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + + ivs_mode = cJSON_GetObjectItem(camera, "ivs_mode"); + + temp_detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + s_detection_zone = cJSON_GetObjectItem(s_camera, "detection_zone"); +#ifdef GY_OS_NOVA + detection_zone_small = cJSON_GetObjectItem(camera_small, "detection_zone"); +#endif + } + + if (camera_name) { + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + cJSON_ReplaceItemInObject(s_camera, "camera_name", cJSON_CreateString(viewChannelData[n].camera_name)); + } + if (levenshtein_distance) { + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + cJSON_ReplaceItemInObject(s_camera, "levenshtein_distance", cJSON_CreateString(viewChannelData[n].levenshtein_distance)); + } + if (min_characters) { + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + cJSON_ReplaceItemInObject(s_camera, "min_characters", cJSON_CreateString(viewChannelData[n].min_characters)); + } + if (max_characters) { + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + cJSON_ReplaceItemInObject(s_camera, "max_characters", cJSON_CreateString(viewChannelData[n].max_characters)); + } + if (obj_min_proportion) { + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "obj_min_proportion", cJSON_CreateString(viewChannelData[n].obj_min_proportion)); + } + if (obj_max_proportion) { + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "obj_max_proportion", cJSON_CreateString(viewChannelData[n].obj_max_proportion)); + } + + if (plate_filter_times) { + viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); + cJSON_ReplaceItemInObject(s_camera, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); + } + + if (plate_filter_time) { + viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); + cJSON_ReplaceItemInObject(s_camera, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); + } + + if (plate_free_time) { + viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); + cJSON_ReplaceItemInObject(s_camera, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); + } + + if (confidence) { + strcpy(viewChannelData[n].confidence, confidence->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence", cJSON_CreateString(viewChannelData[n].confidence)); + } + if (confidence2) { + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence2", cJSON_CreateString(viewChannelData[n].confidence2)); + } + if (confidence3) { + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence3", cJSON_CreateString(viewChannelData[n].confidence3)); + } + if (confidence4) { + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence4", cJSON_CreateString(viewChannelData[n].confidence4)); + } + if (count_zone) { + viewChannelData[n].count_zone = count_zone->valueint; + cJSON_ReplaceItemInObject(s_camera, "count_zone", cJSON_CreateNumber(viewChannelData[n].count_zone)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "count_zone", cJSON_CreateNumber(viewChannelData[n].count_zone)); +#endif + } + if (enable_lpr_db) { + pthread_mutex_lock(&mutex_enable_lpr_db); + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_lpr_db", cJSON_CreateString(viewChannelData[n].enable_lpr_db)); + pthread_mutex_unlock(&mutex_enable_lpr_db); + } + if (enable_add_face_frequent_list) { + if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) + viewChannelData[n].enable_add_face_frequent_list = 1; + else + viewChannelData[n].enable_add_face_frequent_list = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); + } + if (enable_downsized_cropped_roi) { + set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); + cJSON_ReplaceItemInObject(s_camera, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); + } + if (enable_zone_crop_1) { + set_enable_zone_crop_1(enable_zone_crop_1->valueint); + cJSON_ReplaceItemInObject(s_camera, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); + } + if (enable_PTZ) { + strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_PTZ", cJSON_CreateString(viewChannelData[n].enable_PTZ)); + } + if (enable_track) { + strcpy(viewChannelData[n].enable_track, enable_track->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_track", cJSON_CreateString(viewChannelData[n].enable_track)); + } + if (ptz_tracking_fov_min) { + strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_fov_min", cJSON_CreateString(viewChannelData[n].ptz_tracking_fov_min)); + } + if (ptz_tracking_fov_max) { + strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_fov_max", cJSON_CreateString(viewChannelData[n].ptz_tracking_fov_max)); + } + if (ptz_enable_tracking) { + strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_enable_tracking", cJSON_CreateString(viewChannelData[n].ptz_enable_tracking)); + } + if (ptz_tracking_mode) { + viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); + } + if (ptz_tracking_by_enter_zone) { + if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) + viewChannelData[n].ptz_tracking_by_enter_zone = 1; + else + viewChannelData[n].ptz_tracking_by_enter_zone = 0; + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); + } + + if (enable_tracking_limits) { + strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_tracking_limits", cJSON_CreateString(viewChannelData[n].enable_tracking_limits)); + } + + if (ptz_pan_left_limit) { + strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_pan_left_limit", cJSON_CreateString(viewChannelData[n].ptz_pan_left_limit)); + } + + if (ptz_pan_right_limit) { + strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_pan_right_limit", cJSON_CreateString(viewChannelData[n].ptz_pan_right_limit)); + } + + if (ptz_tilt_up_limit) { + strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tilt_up_limit", cJSON_CreateString(viewChannelData[n].ptz_tilt_up_limit)); + } + + if (ptz_tilt_down_limit) { + strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tilt_down_limit", cJSON_CreateString(viewChannelData[n].ptz_tilt_down_limit)); + } + + if (ptz_speed) { + strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_speed", cJSON_CreateString(viewChannelData[n].ptz_speed)); + } + + if (enable_unknown_object) { + strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_unknown_object", cJSON_CreateString(viewChannelData[n].enable_unknown_object)); + +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_unknown_object", cJSON_CreateString(viewChannelData[n].enable_unknown_object)); +#endif + } + + if (enable_ivs_person_detection) { + strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ivs_person_detection", cJSON_CreateString(viewChannelData[n].enable_ivs_person_detection)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_ivs_person_detection", cJSON_CreateString(viewChannelData[n].enable_ivs_person_detection)); +#endif + } + + if (assign_ivs_object_to) { + strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); + cJSON_ReplaceItemInObject(s_camera, "assign_ivs_object_to", cJSON_CreateString(viewChannelData[n].assign_ivs_object_to)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "assign_ivs_object_to", cJSON_CreateString(viewChannelData[n].assign_ivs_object_to)); +#endif + } + + if (enable_ambulance) { + strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ambulance", cJSON_CreateString(viewChannelData[n].enable_ambulance)); + } + if (enable_blank_plate) { + strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_blank_plate", cJSON_CreateString(viewChannelData[n].enable_blank_plate)); + } + if (enable_stop_sign) { + strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_stop_sign", cJSON_CreateString(viewChannelData[n].enable_stop_sign)); + } + if (enable_show_unknown_object) { + strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_show_unknown_object", cJSON_CreateString(viewChannelData[n].enable_show_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_show_unknown_object", cJSON_CreateString(viewChannelData[n].enable_show_unknown_object)); +#endif + } + + if (enable_ivs_fix_mode) { + strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ivs_fix_mode", cJSON_CreateString(viewChannelData[n].enable_ivs_fix_mode)); + } + + if (enable_ivs_and_ai) { + strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_ivs_and_ai", cJSON_CreateString(viewChannelData[n].enable_ivs_and_ai)); + } + + if (enable_lpr_upon_triggered) { + strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); + cJSON_ReplaceItemInObject(s_camera, "enable_lpr_upon_triggered", cJSON_CreateString(viewChannelData[n].enable_lpr_upon_triggered)); + } + if (dwell_lpr_upon_triggered) { + strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); + cJSON_ReplaceItemInObject(s_camera, "dwell_lpr_upon_triggered", cJSON_CreateString(viewChannelData[n].dwell_lpr_upon_triggered)); + } + if (unknown_object_max_proportion) { + strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "unknown_object_max_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_max_proportion)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "unknown_object_max_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_max_proportion)); +#endif + } + if (unknown_object_min_proportion) { + strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); + cJSON_ReplaceItemInObject(s_camera, "unknown_object_min_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_min_proportion)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "unknown_object_min_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_min_proportion)); +#endif + } + if (confidence_unknown_object) { + strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence_unknown_object", cJSON_CreateString(viewChannelData[n].confidence_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "confidence_unknown_object", cJSON_CreateString(viewChannelData[n].confidence_unknown_object)); +#endif + } + if (confidence2_unknown_object) { + strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "confidence2_unknown_object", cJSON_CreateString(viewChannelData[n].confidence2_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "confidence2_unknown_object", cJSON_CreateString(viewChannelData[n].confidence2_unknown_object)); +#endif + } + if (dwell_unknown_object) { + strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); + cJSON_ReplaceItemInObject(s_camera, "dwell_unknown_object", cJSON_CreateString(viewChannelData[n].dwell_unknown_object)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "dwell_unknown_object", cJSON_CreateString(viewChannelData[n].dwell_unknown_object)); +#endif + } + + if (dwell_minute_focus_on) { + strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); + cJSON_ReplaceItemInObject(s_camera, "dwell_minute_focus_on", cJSON_CreateString(viewChannelData[n].dwell_minute_focus_on)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "dwell_minute_focus_on", cJSON_CreateString(viewChannelData[n].dwell_minute_focus_on)); +#endif + } + + if (person_obj_fov) { + strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); + cJSON_ReplaceItemInObject(s_camera, "person_obj_fov", cJSON_CreateString(viewChannelData[n].person_obj_fov)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "person_obj_fov", cJSON_CreateString(viewChannelData[n].person_obj_fov)); +#endif + } + if (getnetwork_buffer_id) { + if (strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) + { + g_change_getnetwork_buffer_id = 1; + } + + strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); + cJSON_ReplaceItemInObject(s_camera, "getnetwork_buffer_id", cJSON_CreateString(viewChannelData[n].getnetwork_buffer_id)); + } + if (red_light_zone) { + strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); + cJSON_ReplaceItemInObject(s_camera, "red_light_zone", cJSON_CreateString(viewChannelData[n].red_light_zone)); + } + if (no_give_way_zone_to_protect) { + strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_protect", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_protect)); + } + if (no_give_way_zone_to_keep_away) { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_keep_away", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_keep_away)); + } + if (no_give_way_zone_to_protect_2) { + strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_protect_2", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_protect_2)); + } + if (no_give_way_zone_to_keep_away_2) { + strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); + cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_keep_away_2)); + } + if (ptz_sensitivity) { + viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); + } + if (ptz_tracking_resume_dwell) { + strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_resume_dwell", cJSON_CreateString(viewChannelData[n].ptz_tracking_resume_dwell)); + } + if (cJSON_enable_only_show_metadata1) { + enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; + cJSON_ReplaceItemInObject(s_camera, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); + } + + if (ivs_mode) { + strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); + cJSON_ReplaceItemInObject(s_camera, "ivs_mode", cJSON_CreateString(viewChannelData[n].ivs_mode)); + } + + viewChannelData[n].channel_idx = n; + + if (tab_view_size) { + char temp_tab[50] = { 0 }; + strcpy(temp_tab, tab_view_size->valuestring); + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(temp_tab, outArray, "x"); + //printf("\n------UU:35\n"); + if (strlen(outArray[0]) >= 1) + viewChannelData[n].tab_view_width = atoi(outArray[0]); + if (strlen(outArray[0]) >= 1) + viewChannelData[n].tab_view_height = atoi(outArray[1]); + if (strlen(outArray[0]) >= 1 && strlen(outArray[0]) >= 1) { + cJSON_ReplaceItemInObject(s_camera, "tab_view_size", cJSON_CreateString(tab_view_size->valuestring)); + } + } + if (enable_anpr) { + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); +#endif + } + if (enable_face) { + if (strcmp(enable_face->valuestring, "Yes") == 0) + viewChannelData[n].enable_face = 1; + else + viewChannelData[n].enable_face = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_face", cJSON_CreateString(enable_face->valuestring)); + } + if (enable_traffic) { + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(camera_small, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); +#endif + } + if (enable_logo) { + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + cJSON_ReplaceItemInObject(s_camera, "enable_logo", cJSON_CreateString(enable_logo->valuestring)); + } + + viewChannelData[n].enable_traffic_light_zone = 0; + if (temp_detection_zone && s_detection_zone) { + //printf("\nTTTTTTTTTTTTTTT: 1\n"); + { + int i = 0; + cJSON_ArrayForEach(detect, temp_detection_zone) + { + if (detect) + { + int j = 0; + cJSON_ArrayForEach(s_detect, s_detection_zone) + { + if (i == j) + { + + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); + obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); + obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); + + enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); + enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); + enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); + parking_space = cJSON_GetObjectItem(detect, "parking_space"); + parking_line = cJSON_GetObjectItem(detect, "parking_line"); + set_distance = cJSON_GetObjectItem(detect, "set_distance"); + world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); + world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); + world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); + world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); + + if (i == 0) { + trigger_events_0 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_0 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 1) { + + trigger_events_1 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_1 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 2) { + + trigger_events_2 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_2 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 3) { + + trigger_events_3 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_3 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 4) { + + trigger_events_4 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_4 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 5) { + + trigger_events_5 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_5 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 6) { + + trigger_events_6 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_6 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + else if (i == 7) { + + trigger_events_7 = cJSON_GetObjectItem(detect, "trigger_events"); + s_trigger_events_7 = cJSON_GetObjectItem(s_detect, "trigger_events"); + } + + point_number = cJSON_GetObjectItem(detect, "point_number"); + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + if (obj_max_proportion_in_zone) + { + strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); + cJSON_ReplaceItemInObject(s_detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[n][i].obj_max_proportion_in_zone)); + } + if (obj_min_proportion_in_zone) + { + strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); + cJSON_ReplaceItemInObject(s_detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[n][i].obj_min_proportion_in_zone)); + } + if (ptz_zone_to_preset) + { + strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); + cJSON_ReplaceItemInObject(s_detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[n][i].ptz_zone_to_preset)); + } + if (enable_speed) + { + strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_speed", cJSON_CreateString(viewDetectionZone[n][i].enable_speed)); + } + if (enable_radar_speed) + { + strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[n][i].enable_radar_speed)); + } + if (enable_ivs_zone) + { + strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[n][i].enable_ivs_zone)); + } + if (parking_space) + { + viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); + cJSON_ReplaceItemInObject(s_detect, "parking_space", cJSON_CreateString(parking_space->valuestring)); + } + if (parking_line) + { + viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); + cJSON_ReplaceItemInObject(s_detect, "parking_line", cJSON_CreateString(parking_line->valuestring)); + } + if (set_distance) + { + viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); + cJSON_ReplaceItemInObject(s_detect, "set_distance", cJSON_CreateString(set_distance->valuestring)); + } + if (world_distance_unit) + { + strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_distance_unit", cJSON_CreateString(world_distance_unit->valuestring)); + } + if (world_distance_side1) + { + viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_distance_side1", cJSON_CreateString(world_distance_side1->valuestring)); + viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; + viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; + } + if (world_distance_side2) + { + viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_distance_side2", cJSON_CreateString(world_distance_side2->valuestring)); + viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; + viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; + } + if (world_time_unit) + { + strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[n][i].world_time_unit)); + } + if (detection_time) + { + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + cJSON_ReplaceItemInObject(s_detect, "detection_time", cJSON_CreateString(viewDetectionZone[n][i].detection_time)); + } + if (metadata1) + { + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "metadata1", cJSON_CreateString(viewDetectionZone[n][i].metadata1)); + } + if (metadata2) + { + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "metadata2", cJSON_CreateString(viewDetectionZone[n][i].metadata2)); + } + if (metadata_stop) + { + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + cJSON_ReplaceItemInObject(s_detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[n][i].metadata_stop)); + } + if (link_to_counter) + { + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + cJSON_ReplaceItemInObject(s_detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[n][i].link_to_counter)); + } + if (enable_direction1) + { + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[n][i].enable_direction1)); + } + if (enable_direction2) + { + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "enable_direction2", cJSON_CreateString(viewDetectionZone[n][i].enable_direction2)); + } + if (direction1) + { + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + cJSON_ReplaceItemInObject(s_detect, "direction1", cJSON_CreateString(viewDetectionZone[n][i].direction1)); + } + if (direction2) + { + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + cJSON_ReplaceItemInObject(s_detect, "direction2", cJSON_CreateString(viewDetectionZone[n][i].direction2)); + } + if (no_parking_time) + { + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + cJSON_ReplaceItemInObject(s_detect, "no_parking_time", cJSON_CreateString(no_parking_time->valuestring)); + } + if (no_parking_time_in_minute) + { + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + cJSON_ReplaceItemInObject(s_detect, "no_parking_time_in_minute", cJSON_CreateString(no_parking_time_in_minute->valuestring)); + } + if (queuing_count && strlen(queuing_count->valuestring) >= 1) + { + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + cJSON_ReplaceItemInObject(s_detect, "queuing_count", cJSON_CreateString(queuing_count->valuestring)); + } + + if (point_number) { + viewDetectionZone[n][i].point_num = point_number->valueint; + cJSON_ReplaceItemInObject(s_detect, "point_number", cJSON_CreateNumber(viewDetectionZone[n][i].point_num)); + } + if (x1) { + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].x)); + } + if (y1) { + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].y)); + } + if (x2) { + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].x)); + } + if (y2) { + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].y)); + } + if (x3) { + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].x)); + } + if (y3) { + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].y)); + } + if (x4) { + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].x)); + } + if (y4) { + viewDetectionZone[n][i].Points[3].y = y4->valueint; + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].y)); + } + if (x5) { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].x)); + } + if (y5) { + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].y)); + } + if (x6) { + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + cJSON_ReplaceItemInObject(s_detect, "x6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].x)); + } + if (y6) { + viewDetectionZone[n][i].Points[5].y = y6->valueint; + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + cJSON_ReplaceItemInObject(s_detect, "y6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].y)); + } + if (enable_traffic_light) { + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; + //UpdateTrafficLightZone(n); + } + cJSON_ReplaceItemInObject(s_detect, "enable_traffic_light", cJSON_CreateString(enable_traffic_light->valuestring)); + } + break; + } + j++; + } +#ifdef GY_OS_NOVA + if (detection_zone_small) { + j = 0; + cJSON_ArrayForEach(detect_small, detection_zone_small) + { + if (i == j) { + point_number = cJSON_GetObjectItem(detect, "point_number"); + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + if (point_number) { + cJSON_ReplaceItemInObject(detect_small, "point_number", cJSON_CreateNumber(viewDetectionZone[n][i].point_num)); + } + if (x1) { + cJSON_ReplaceItemInObject(detect_small, "x1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].x)); + } + if (y1) { + cJSON_ReplaceItemInObject(detect_small, "y1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].y)); + } + if (x2) { + cJSON_ReplaceItemInObject(detect_small, "x2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].x)); + } + if (y2) { + cJSON_ReplaceItemInObject(detect_small, "y2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].y)); + } + if (x3) { + cJSON_ReplaceItemInObject(detect_small, "x3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].x)); + } + if (y3) { + cJSON_ReplaceItemInObject(detect_small, "y3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].y)); + } + if (x4) { + cJSON_ReplaceItemInObject(detect_small, "x4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].x)); + } + if (y4) { + cJSON_ReplaceItemInObject(detect_small, "y4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].y)); + } + if (x5) { + cJSON_ReplaceItemInObject(detect_small, "x5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].x)); + } + if (y5) { + cJSON_ReplaceItemInObject(detect_small, "y5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].y)); + } + if (x6) { + cJSON_ReplaceItemInObject(detect_small, "x6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].x)); + } + if (y6) { + cJSON_ReplaceItemInObject(detect_small, "y6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].y)); + } + } + j++; + } + } +#endif + } + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + } + //printf("\nTTTTTTTTTTTTTTT: 2\n"); +#if 1 + + for (int i = 0; i < viewChannelData[n].count_zone; i++) { + + if (i == 0) { + trigger_events_temp = trigger_events_0; + s_trigger_events_temp = s_trigger_events_0; + } + else if (i == 1) { + trigger_events_temp = trigger_events_1; + s_trigger_events_temp = s_trigger_events_1; + } + else if (i == 2) { + trigger_events_temp = trigger_events_2; + s_trigger_events_temp = s_trigger_events_2; + } + else if (i == 3) { + trigger_events_temp = trigger_events_3; + s_trigger_events_temp = s_trigger_events_3; + } + else if (i == 4) { + trigger_events_temp = trigger_events_4; + s_trigger_events_temp = s_trigger_events_4; + } + else if (i == 5) { + trigger_events_temp = trigger_events_5; + s_trigger_events_temp = s_trigger_events_5; + } + else if (i == 6) { + trigger_events_temp = trigger_events_6; + s_trigger_events_temp = s_trigger_events_6; + } + else if (i == 7) { + trigger_events_temp = trigger_events_7; + s_trigger_events_temp = s_trigger_events_7; + } + + if (trigger_events_temp && s_trigger_events_temp) { + int k = 0; + + cJSON_ArrayForEach(detect, trigger_events_temp) + { + if (detect) + { + int m = 0; + + cJSON_ArrayForEach(s_detect, s_trigger_events_temp) + { + if (s_detect) { + cJSON * detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + cJSON * s_detect_event_id = cJSON_GetObjectItem(s_detect, "detect_event_id"); + + if (detect_event_id && s_detect_event_id) + { + if (strcmp(detect_event_id->valuestring, s_detect_event_id->valuestring) == 0) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + if (checked) + { + viewDetectionZone[n][i].trigger_event[m].checked = checked->valueint; + cJSON_ReplaceItemInObject(s_detect, "checked", cJSON_CreateNumber(viewDetectionZone[n][i].trigger_event[m].checked)); + } + if (detect_event_id) + { + strcpy(viewDetectionZone[n][i].trigger_event[m].detect_event_id, detect_event_id->valuestring); + cJSON_ReplaceItemInObject(s_detect, "detect_event_id", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].detect_event_id)); + } + if (detect_event_name) + { + strcpy(viewDetectionZone[n][i].trigger_event[m].detect_event_name, detect_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect, "detect_event_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].detect_event_name)); + } + if (post_event_name) { + strcpy(viewDetectionZone[n][i].trigger_event[m].post_event_name, post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect, "post_event_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].post_event_name)); + } + if (counter_name) { + strcpy(viewDetectionZone[n][i].trigger_event[m].counter_name, counter_name->valuestring); + cJSON_ReplaceItemInObject(s_detect, "counter_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].counter_name)); + } + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][i].trigger_event[m].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][i].trigger_event[m].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][i].trigger_event[m].counter_increment = 0; + else + viewDetectionZone[n][i].trigger_event[m].counter_increment = -2; + cJSON_ReplaceItemInObject(s_detect, "counter_increment", cJSON_CreateString(counter_increment->valuestring)); + } + + break; + } + } + } + m++; + } + } + k++; + } + } + + } +#endif + //printf("\nTTTTTTTTTTTTTTT: 3\n"); + } + + } + } + + cJSON *system_setting,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*enable_person_independent,*enable_onvif_profile_m,*cloud_enable_snap, *cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue, *language, *display_properties,*display_OSD, *display_dash, + *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password,*enable_system_logs,*enable_email_jpeg,*enable_email_notification,*email_reset_time_interval, + *sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory, *ftp_jpeg_file_name_format, *ftp_jpeg_file_name; + cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; + + cJSON *s_system_setting; + + system_setting = cJSON_GetObjectItem(root, "system_setting"); + s_system_setting = cJSON_GetObjectItem(s_root, "system_setting"); + +#ifdef GY_OS_NOVA + system_setting_small = cJSON_GetObjectItem(root_small, "system_setting"); +#endif + + if (system_setting) { + enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); + enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); + nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); + tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); + enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); + enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); + enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); + enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); + cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); + cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); + cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); + cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); + cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); + cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); + cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); + cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); + language = cJSON_GetObjectItem(system_setting, "language"); + display_properties = cJSON_GetObjectItem(system_setting, "display properties"); + display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); + display_dash = cJSON_GetObjectItem(system_setting, "display dash"); + enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); + enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); + enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); + force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); + force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); + enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); + + enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); + ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); + + enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); + cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); + cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); + enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); + cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); + cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); + + enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); + enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); + getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); + getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); + osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); + osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); + osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); + enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); + osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); + osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); + sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); + enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); + external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); + external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); + external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); + external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); + enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); + enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); + enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); + email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); + + enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); + ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); + ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); + ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); + ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); + ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); + ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); + ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); + + if (enable_person_independent) + { + strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_person_independent", cJSON_CreateString(SystemSetting.enable_person_independent)); + } + + if (enable_onvif_profile_m) + { + strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_onvif_profile_m", cJSON_CreateString(SystemSetting.enable_onvif_profile_m)); + } + + if (nms_thres) + { + strcpy(SystemSetting.nms_thres, nms_thres->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "nms_thres", cJSON_CreateString(SystemSetting.nms_thres)); + } + + if (tracking_id_dwell) + { + strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "tracking_id_dwell", cJSON_CreateString(SystemSetting.tracking_id_dwell)); + } + + if (cloud_enable_snap) + { + strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_enable_snap", cJSON_CreateString(SystemSetting.cloud_enable_snap)); + } + if (enable_cloud) + { + strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud", cJSON_CreateString(SystemSetting.enable_cloud)); + } + if (enable_special_edition) + { + strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_special_edition", cJSON_CreateString(SystemSetting.enable_special_edition)); + } + if (enable_python) + { + strcpy(SystemSetting.enable_python, enable_python->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_python", cJSON_CreateString(SystemSetting.enable_python)); + } + if (enable_python_file) + { + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_python_file", cJSON_CreateString(SystemSetting.enable_python_file)); + + } + if (enable_low_cpu_usage) + { + strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_low_cpu_usage", cJSON_CreateString(SystemSetting.enable_low_cpu_usage)); + } + if (cloud_enable_notification) + { + strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_enable_notification", cJSON_CreateString(SystemSetting.cloud_enable_notification)); + } + if (cloud_account) + { + strcpy(SystemSetting.cloud_account, cloud_account->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_account", cJSON_CreateString(SystemSetting.cloud_account)); + } + if (cloud_password) + { + strcpy(SystemSetting.cloud_password, cloud_password->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_password", cJSON_CreateString(SystemSetting.cloud_password)); + } + if (cloud_notification_dwell) + { + strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_notification_dwell", cJSON_CreateString(SystemSetting.cloud_notification_dwell)); + } + if (cloud_statue) + { + strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_statue", cJSON_CreateString(SystemSetting.cloud_statue)); + } + if (cloud_v2_statue) + { + strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_statue", cJSON_CreateString(SystemSetting.cloud_v2_statue)); + } + if (cloud_record_v2_statue) + { + strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_statue", cJSON_CreateString(SystemSetting.cloud_record_v2_statue)); + } + if (language) + { + strcpy(SystemSetting.language, language->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "language", cJSON_CreateString(SystemSetting.language)); + } + if (display_properties) + { + strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "display properties", cJSON_CreateString(SystemSetting.enable_display_properties)); + } +#ifdef GY_OS_AMBA + if (display_OSD) + { + pthread_mutex_lock(&mutex_run_one_net); + pthread_mutex_lock(&mutex_get_network_input); + strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + cJSON_ReplaceItemInObject(s_system_setting, "display OSD", cJSON_CreateString(SystemSetting.enable_display_OSD)); + } +#endif + + if (display_dash) + { + activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); + } + if (enable_special_char) + { + strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_special_char", cJSON_CreateString(SystemSetting.enable_special_char)); + } + if (enable_bounding_box) + { + strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_bounding_box", cJSON_CreateString(SystemSetting.enable_bounding_box)); + } + if (enable_dwell_bounding_box) + { + strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_dwell_bounding_box", cJSON_CreateString(SystemSetting.enable_dwell_bounding_box)); + } + if (force_i_to_one) + { + strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "force_i_to_one", cJSON_CreateString(SystemSetting.force_i_to_one)); + } + if (force_o_to_zero) + { + strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "force_o_to_zero", cJSON_CreateString(SystemSetting.force_o_to_zero)); + } + if (enable_plate_angle_correction) + { + strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_plate_angle_correction", cJSON_CreateString(SystemSetting.enable_plate_angle_correction)); +#ifdef GY_OS_NOVA + cJSON_ReplaceItemInObject(system_setting_small, "enable_plate_angle_correction", cJSON_CreateString(SystemSetting.enable_plate_angle_correction)); +#endif + } + if (enable_ai_mirror) + { + strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_ai_mirror", cJSON_CreateString(SystemSetting.enable_ai_mirror)); + } + if (ai_mirror_feature) + { + strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ai_mirror_feature", cJSON_CreateString(SystemSetting.ai_mirror_feature)); + } + if (enable_cloud_v2) + { + strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud_v2", cJSON_CreateString(SystemSetting.enable_cloud_v2)); + } + if (cloud_v2_notification_dwell) + { + strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(SystemSetting.cloud_v2_notification_dwell)); + } + if (cloud_v2_content) + { + strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_content", cJSON_CreateString(SystemSetting.cloud_v2_content)); + } + if (enable_cloud_record_v2) + { + strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud_record_v2", cJSON_CreateString(SystemSetting.enable_cloud_record_v2)); + } + if (cloud_record_v2_notification_dwell) + { + strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(SystemSetting.cloud_record_v2_notification_dwell)); + } + if (cloud_record_v2_content) + { + strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_content", cJSON_CreateString(SystemSetting.cloud_record_v2_content)); + } + if (enable_post_only_if_both_detected) + { + strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(SystemSetting.enable_post_only_if_both_detected)); + } + if (enable_getalarmmotion_snap) + { + strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(SystemSetting.enable_getalarmmotion_snap)); + } + if (getimage_encoder_id) + { + strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "getimage_encoder_id", cJSON_CreateString(SystemSetting.getimage_encoder_id)); + } + if (getimage_encoder_id_HD) + { + strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "getimage_encoder_id_HD", cJSON_CreateString(SystemSetting.getimage_encoder_id_HD)); + } + if (osd_encoder_id) + { + strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_encoder_id", cJSON_CreateString(SystemSetting.osd_encoder_id)); + } + if (osd_font_size) + { + strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_font_size", cJSON_CreateString(SystemSetting.osd_font_size)); + } + if (osd_outline_lilin) + { + strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_outline_lilin", cJSON_CreateString(SystemSetting.osd_outline_lilin)); + } + if (enable_osd_bottom) + { + strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_osd_bottom", cJSON_CreateString(SystemSetting.enable_osd_bottom)); + } + if (osd_bottom_bg_tran) + { + strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_bottom_bg_tran", cJSON_CreateString(SystemSetting.osd_bottom_bg_tran)); + } + if (osd_bottom_content) + { + strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "osd_bottom_content", cJSON_CreateString(SystemSetting.osd_bottom_content)); + } + if (sensors_type) + { + strcpy(SystemSetting.sensors_type, sensors_type->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "sensors_type", cJSON_CreateString(SystemSetting.sensors_type)); + } + if (enable_sync_external_lpr_db) + { + strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(SystemSetting.enable_sync_external_lpr_db)); + } + if (external_lpr_db_IP) + { + strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_IP", cJSON_CreateString(SystemSetting.external_lpr_db_IP)); + } + if (external_lpr_db_port) + { + strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_port", cJSON_CreateString(SystemSetting.external_lpr_db_port)); + } + if (external_lpr_db_username) + { + strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_username", cJSON_CreateString(SystemSetting.external_lpr_db_username)); + } + if (external_lpr_db_password) + { + strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_password", cJSON_CreateString(SystemSetting.external_lpr_db_password)); + } + + if (enable_system_logs) + { + strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_system_logs", cJSON_CreateString(SystemSetting.enable_system_logs)); + } + + if (enable_email_jpeg) + { + strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_email_jpeg", cJSON_CreateString(SystemSetting.enable_email_jpeg)); + } + + if (email_reset_time_interval) + { + strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "email_reset_time_interval", cJSON_CreateString(SystemSetting.email_reset_time_interval)); + } + + if (enable_ftp) + { + strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_ftp", cJSON_CreateString(SystemSetting.enable_ftp)); + } + + if (ftp_url) + { + strcpy(SystemSetting.ftp_url, ftp_url->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_url", cJSON_CreateString(SystemSetting.ftp_url)); + } + + if (ftp_port) + { + strcpy(SystemSetting.ftp_port, ftp_port->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_port", cJSON_CreateString(SystemSetting.ftp_port)); + } + + if (ftp_username) + { + strcpy(SystemSetting.ftp_username, ftp_username->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_username", cJSON_CreateString(SystemSetting.ftp_username)); + } + + if (ftp_password) + { + strcpy(SystemSetting.ftp_password, ftp_password->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_password", cJSON_CreateString(SystemSetting.ftp_password)); + } + + if (ftp_remote_directory) + { + strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_remote_directory", cJSON_CreateString(SystemSetting.ftp_remote_directory)); + } + + if (ftp_jpeg_file_name_format) + { + strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(SystemSetting.ftp_jpeg_file_name_format)); + } + + if (ftp_jpeg_file_name) + { + strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "ftp_jpeg_file_name", cJSON_CreateString(SystemSetting.ftp_jpeg_file_name)); + } + + if (enable_email_notification) + { + strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); + cJSON_ReplaceItemInObject(s_system_setting, "enable_email_notification", cJSON_CreateString(SystemSetting.enable_email_notification)); + } + + } + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(config_PATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(config_PATH, config_bakPATH); + check_if_setfile_OK = 1; + g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + +#ifdef GY_OS_NOVA + JsonString = cJSON_Print(root_small); + + f = fopen(config_smallPATH, "w"); + if (f != NULL) + { + fprintf(f, "%s\n", JsonString); + fclose(f); + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } +#endif + +#ifdef GY_OS_AMBA + if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { + if (enable_ai_mirror && ai_mirror_feature){ + if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) + { + if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) + { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + else { + FILE * pPipe; + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); + } + } + } + } +#endif + + if (ftp_remote_directory) { + if (strlen(SystemSetting.ftp_remote_directory) >= 1) { + net_curl_ftp_build_folder(); + } + } + +#ifdef GY_OS_AMBA + + viewChannelData[0].speed_view_width_ratio = (float)(1920 / 889); + viewChannelData[0].speed_view_height_ratio = (float)(1080 / 500); + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + if (strncmp(viewDetectionZone[0][i].enable_speed, "Yes", strlen("Yes")) == 0) + { + int social_zone_idx = i; + if (social_zone_idx >= 0) + { + pthread_mutex_lock(&mutex_perspective_transform); + if (viewDetectionZone[0][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[0][i].PerspectiveTransformArray); + viewDetectionZone[0][i].PerspectiveTransformArray = GetPerspectiveTransformArray(0, social_zone_idx); + pthread_mutex_unlock(&mutex_perspective_transform); + } + } + } + +#endif + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + +#ifdef GY_OS_NOVA + if (root_small) { + cJSON_Delete(root_small); + root_small = NULL; + } +#endif + } + else { + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } +#ifdef GY_OS_NOVA + if (fileBuf3) { + free(fileBuf3); + fileBuf3 = NULL; + } +#endif + printf("\nFail to read config_import.json or config.json\n"); + } + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile)\n"); + } + else { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile#2)\n"); + } + + pthread_mutex_unlock(&mutex_config_json); + + closesocket(cli_socket); + +#ifdef GY_OS_AMBA + + /* + int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //Update PTZ + + UpdatePTZConfigSetting(); + + /* + UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, + viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, + viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, + viewDetectionZone[0][0].metadata1, zone_to_preset);*/ + + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + +#endif + + //Reload cold zone + /*int iReadCodeZoneRet = */ ReadColdZoneJsonFile(); + + set_metadata(); + +#ifdef GY_OS_AMBA + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + if (strstr(viewDetectionZone[0][index_zone].metadata1, "qrcode") != NULL || + strstr(viewDetectionZone[0][index_zone].metadata1, "barcode") != NULL || + g_check_h264_gop != 0) + { + if (run_check_current_resolution == -1) { + run_check_current_resolution = 0; + if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) + printf("\ncheck current resolution thread failed #2\n"); + run_check_current_resolution = 1; + break; + } + } + } +#endif + + set_counter_zone(); + + check_if_correct_post = 0; + + clear_all_record_locked_ivs(); + + //printf("\n------------setconfigfile end\n"); + } + else if (strncmp(urlBuffer, "/seteventsfile", strlen("/seteventsfile")) == 0) + { + pthread_mutex_lock(&mutex_events_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char events_importPATH[1024]; + strcpy(events_importPATH, exePath); + strcat(events_importPATH, "events_import.json"); + + char events_PATH[1024]; + strcpy(events_PATH, exePath); + strcat(events_PATH, "events.json"); + + FILE *pFile; + + if ((pFile = fopen(events_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(events_importPATH); + char* fileBuf2 = ReadAllBytes(events_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (root && s_root) + { + cJSON *notification, *enable_post,*events_default_version,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, + *post_customized_header; + cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max, *enable_heatmap, *heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + cJSON *s_notification, *s_http_post_events, *s_detect2; + + notification = cJSON_GetObjectItem(root, "notification"); + s_notification = cJSON_GetObjectItem(s_root, "notification"); + + if (notification) { + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + s_http_post_events = cJSON_GetObjectItem(s_notification, "http_post_events"); + + if (events_default_version) + { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + cJSON_ReplaceItemInObject(s_notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + } + + if(enable_post) + { + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_post", cJSON_CreateString(enable_post->valuestring)); + } + if (enable_snmp_post) + { + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_post", cJSON_CreateString(enable_snmp_post->valuestring)); + } + if (enable_heartbeat) + { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); + } + if (enable_snmp_heartbeat) + { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); + } + if (snmp_heartbeat_dwell) + { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); + } + if (snmp_heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); + } + if (enable_check_ptz_start_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); + } + if (enable_check_ptz_end_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); + } + if (enable_only_once_to_post) + { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); + } + if (enable_obj_once_to_post) + { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); + } + if (enable_location_once_to_post) + { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); + } + if (enable_nvr_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); + } + if (enable_8592_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); + } + if (dwell_to_the_same_location) + { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + cJSON_ReplaceItemInObject(s_notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); + } + if (heartbeat_dwell) + { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); + } + if (heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); + } + if (ptz_start_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); + } + if (ptz_end_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); + } + if (heatmap_max) + { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); + } + if (enable_heatmap) + { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); + } + if (heatmap_frequency) + { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); + } + if (lpr_title) + { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + cJSON_ReplaceItemInObject(s_notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); + } + if (enable_counter_snap) + { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); + } + if (enable_barcode_qr) + { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); + } + if (http_post_events) + { + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + if (detect2) + { + int j = 0; + cJSON_ArrayForEach(s_detect2, s_http_post_events) + { + if(i==j) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + + if (post_protocol) + { + strcpy(postEventList[j].post_protocol, post_protocol->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_protocol", cJSON_CreateString(postEventList[j].post_protocol)); + } + if (post_event_method) + { + strcpy(postEventList[j].post_event_method, post_event_method->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_method", cJSON_CreateString(postEventList[j].post_event_method)); + } + if (post_event_name2) { + strcpy(postEventList[j].post_event_name, post_event_name2->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_name", cJSON_CreateString(postEventList[j].post_event_name)); + } + if (post_host_ip) + { + strcpy(postEventList[j].post_host_ip, post_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_ip", cJSON_CreateString(postEventList[j].post_host_ip)); + } + if(post_host_port) + { + strcpy(postEventList[j].post_host_port, post_host_port->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_port", cJSON_CreateString(postEventList[j].post_host_port)); + } + if (post_url) + { + strcpy(postEventList[j].post_url, post_url->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_url", cJSON_CreateString(postEventList[j].post_url)); + } + if (post_username) + { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + //strcpy(postEventList[j].post_username, post_username->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_username", cJSON_CreateString(post_username->valuestring)); + } + if (post_password) + { + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + //strcpy(postEventList[j].post_password, post_password->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_password", cJSON_CreateString(post_password->valuestring)); + } + if (post_content) + { + strcpy(postEventList[j].post_content, post_content->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_content", cJSON_CreateString(postEventList[j].post_content)); + } + if(post_customized_header) + { + strcpy(postEventList[j].post_customized_header, post_customized_header->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_customized_header", cJSON_CreateString(postEventList[j].post_customized_header)); + } + if (post_sequence) + { + strcpy(postEventList[j].post_sequence, post_sequence->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_sequence", cJSON_CreateString(postEventList[j].post_sequence)); + } + if (post_timeout) + { + strcpy(postEventList[j].post_timeout, post_timeout->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_timeout", cJSON_CreateString(postEventList[j].post_timeout)); + } + if (post_file_format) + { + strcpy(postEventList[j].post_file_format, post_file_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_file_format", cJSON_CreateString(postEventList[j].post_file_format)); + } + if (post_jpeg_file_name_format) + { + strcpy(postEventList[j].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[j].post_jpeg_file_name_format)); + } + if (post_jpeg_file_name) + { + strcpy(postEventList[j].post_jpeg_file_name, post_jpeg_file_name->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name", cJSON_CreateString(postEventList[j].post_jpeg_file_name)); + } + break; + } + j++; + } + } + i++; + } + } + + } + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *enable_reset_only_cloud,*enable_linked_to_dwell_time;// *reset_at, *enable_time_range, *time_range_from, *time_range_to, + cJSON *link_to_post_event_name, *post_interval; + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone,*counter_b_zone,*counter_c_name, + *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + cJSON *s_event_counter_setting, *s_event_counters,*s_detect3,*s_counter_name,*s_a_report,*s_report_counters, *s_a_snmp, *s_snmp_management; + + event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); + s_event_counter_setting = cJSON_GetObjectItem(s_root, "event_counter_setting"); +#ifdef GY_OS_V_SERIES + +#else + if (event_counter_setting) + { + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + s_event_counters = cJSON_GetObjectItem(s_event_counter_setting, "event_counters"); + if (event_counters) + { + int i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + if (detect3) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + if (counter_name) { + int j = 0; + cJSON_ArrayForEach(s_detect3, s_event_counters) + { + s_counter_name = cJSON_GetObjectItem(s_detect3, "counter_name"); + if(strcmp(counter_name->valuestring, s_counter_name->valuestring)==0) + { + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + //reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + //enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + //time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + //time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + if (counter_name) + { + strcpy(eventCounterList[j].counter_name, counter_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_name", cJSON_CreateString(eventCounterList[j].counter_name)); + } + if (counter_cust_name) + { + strcpy(eventCounterList[j].counter_cust_name, counter_cust_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_cust_name", cJSON_CreateString(eventCounterList[j].counter_cust_name)); + } + if (counter_unit) + { + strcpy(eventCounterList[j].counter_unit, counter_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_unit", cJSON_CreateString(eventCounterList[j].counter_unit)); + } + if (reset_value) + { + eventCounterList[j].reset_value = atoi(reset_value->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_value", cJSON_CreateString(reset_value->valuestring)); + } + if (enable_reset_time_interval) + { + strcpy(eventCounterList[j].enable_reset_time_interval, enable_reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[j].enable_reset_time_interval)); + } + if (reset_time_interval) + { + strcpy(eventCounterList[j].reset_time_interval, reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_time_interval", cJSON_CreateString(eventCounterList[j].reset_time_interval)); + } + +#if 0 + + if (reset_at) + { + strcpy(eventCounterList[j].reset_at, reset_at->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_at", cJSON_CreateString(eventCounterList[j].reset_at)); + struct tm tm; + strptime_c(eventCounterList[j].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetResetAt = mktime(&tm); + struct tm *resetTime = localtime(&eventCounterList[j].timetResetAt); + eventCounterList[j].reset_month = resetTime->tm_mon; + eventCounterList[j].reset_month_day = resetTime->tm_mday; + eventCounterList[j].reset_week_day = resetTime->tm_wday; + eventCounterList[j].reset_hour = resetTime->tm_hour; + eventCounterList[j].reset_min = resetTime->tm_min; + eventCounterList[j].reset_sec = resetTime->tm_sec; + } + + if (enable_time_range) + { + strcpy(eventCounterList[j].enable_time_range, enable_time_range->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_time_range", cJSON_CreateString(eventCounterList[j].enable_time_range)); + } + if (time_range_from) + { + strcpy(eventCounterList[j].time_range_from, time_range_from->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_from", cJSON_CreateString(eventCounterList[j].time_range_from)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeFrom = mktime(&tm); + } + if (time_range_to) + { + strcpy(eventCounterList[j].time_range_to, time_range_to->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_to", cJSON_CreateString(eventCounterList[j].time_range_to)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeTo = mktime(&tm); + } +#endif + + if (link_to_post_event_name) + { + strcpy(eventCounterList[j].link_to_post_event_name, link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "link_to_post_event_name", cJSON_CreateString(eventCounterList[j].link_to_post_event_name)); + } + if (post_interval) + { + strcpy(eventCounterList[j].post_interval, post_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "post_interval", cJSON_CreateString(eventCounterList[j].post_interval)); + } + if (enable_reset_only_cloud) { + strcpy(eventCounterList[j].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[j].enable_reset_only_cloud)); + } + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[j].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[j].enable_linked_to_dwell_time)); + } + break; + } + j++; + } + } + } + + i++; + } + +#if 0 + if (strcmp(SystemSetting.cloud_enable_notification, "No") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } + } +#endif + } + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + s_report_counters = cJSON_GetObjectItem(s_event_counter_setting, "report_counters"); + + if (report_counters) { + int i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) + { + int j = 0; + cJSON_ArrayForEach(s_a_report, s_report_counters) + { + if (i == j) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + + if (counter_a) + { + strcpy(reportCounterList[j].counter_a, counter_a->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a", cJSON_CreateString(reportCounterList[j].counter_a)); + } + + if (counter_a_name) + { + strcpy(reportCounterList[j].counter_a_name, counter_a_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_name", cJSON_CreateString(reportCounterList[j].counter_a_name)); + } + + if (counter_a_zone) + { + strcpy(reportCounterList[j].counter_a_zone, counter_a_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[j].counter_a_zone)); + } + + if (counter_b) + { + strcpy(reportCounterList[j].counter_b, counter_b->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b", cJSON_CreateString(reportCounterList[j].counter_b)); + } + + if (counter_b_name) + { + strcpy(reportCounterList[j].counter_b_name, counter_b_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_name", cJSON_CreateString(reportCounterList[j].counter_b_name)); + } + + if (counter_b_zone) + { + strcpy(reportCounterList[j].counter_b_zone, counter_b_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[j].counter_b_zone)); + } + + if (counter_c_name) + { + strcpy(reportCounterList[j].counter_c_name, counter_c_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_c_name", cJSON_CreateString(reportCounterList[j].counter_c_name)); + } + + if (report_max_value) + { + strcpy(reportCounterList[j].report_max_value, report_max_value->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "report_max_value", cJSON_CreateString(reportCounterList[j].report_max_value)); + } + + if (enable_report) + { + strcpy(reportCounterList[j].enable_report, enable_report->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "enable_report", cJSON_CreateString(reportCounterList[j].enable_report)); + } + + if (counter_mode) + { + strcpy(reportCounterList[j].counter_mode, counter_mode->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_mode", cJSON_CreateString(reportCounterList[j].counter_mode)); + } + + if (initial_icon) + { + strcpy(reportCounterList[j].initial_icon, initial_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "initial_icon", cJSON_CreateString(reportCounterList[j].initial_icon)); + } + + if (detection_output) + { + strcpy(reportCounterList[j].detection_output, detection_output->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "detection_output", cJSON_CreateString(reportCounterList[j].detection_output)); + } + + if (output_icon) + { + strcpy(reportCounterList[j].output_icon, output_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "output_icon", cJSON_CreateString(reportCounterList[j].output_icon)); + } + + break; + } + j++; + } + } + + i++; + } + } + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + s_snmp_management = cJSON_GetObjectItem(s_event_counter_setting, "snmp_management"); + + if (snmp_management) { + int i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) + { + int j = 0; + cJSON_ArrayForEach(s_a_snmp, s_snmp_management) + { + if (i == j) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + + if (snmp_event_name) + { + strcpy(SNMPManagementList[j].snmp_event_name, snmp_event_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[j].snmp_event_name)); + } + + if (snmp_version) + { + strcpy(SNMPManagementList[j].snmp_version, snmp_version->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[j].snmp_version)); + } + + if (snmp_group_name) + { + strcpy(SNMPManagementList[j].snmp_group_name, snmp_group_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[j].snmp_group_name)); + } + + if (snmp_host_ip) + { + strcpy(SNMPManagementList[j].snmp_host_ip, snmp_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[j].snmp_host_ip)); + } + + if (snmp_host_port) + { + strcpy(SNMPManagementList[j].snmp_host_port, snmp_host_port->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[j].snmp_host_port)); + } + + if (snmp_oid) + { + strcpy(SNMPManagementList[j].snmp_oid, snmp_oid->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[j].snmp_oid)); + } + + if (snmp_value) + { + strcpy(SNMPManagementList[j].snmp_value, snmp_value->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[j].snmp_value)); + } + + if (snmp_type) + { + strcpy(SNMPManagementList[j].snmp_type, snmp_type->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[j].snmp_type)); + } + break; + } + j++; + } + } + + i++; + } + } + } +#endif + cJSON *email_setting, *email_content; + cJSON *s_email_setting; + + email_setting = cJSON_GetObjectItem(root, "email_setting"); + s_email_setting = cJSON_GetObjectItem(s_root, "email_setting"); + + if (email_setting) + { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) { + strcpy(emailData.email_content, email_content->valuestring); + cJSON_ReplaceItemInObject(s_email_setting, "email_content", cJSON_CreateString(emailData.email_content)); + } + } + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(events_PATH, "w"); + if (f != NULL) + { + + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(events_PATH, events_bakPATH); + + check_if_setfile_OK = 1; + g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read events_import.json or events.json\n"); + } + } + + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventsfile)\n"); + } + else { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventsfile#2)\n"); + } + + pthread_mutex_unlock(&mutex_events_json); + + closesocket(cli_socket); + + set_counter_zone(); + + check_if_correct_post = 0; + } + else if (strncmp(urlBuffer, "/seteventscustom2", strlen("/seteventscustom2")) == 0) + { + pthread_mutex_lock(&mutex_events_json); + + int check_if_setfile_OK = 0; + + int file_buff_size = nTotalContentLen; + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char events_importPATH[1024]; + strcpy(events_importPATH, exePath); + strcat(events_importPATH, "events_custom_2_import.json"); + + char events_PATH[1024]; + strcpy(events_PATH, exePath); + strcat(events_PATH, "events_custom_2.json"); + + FILE *pFile; + + if ((pFile = fopen(events_importPATH, "w+")) != NULL) + { + fprintf(pFile, "%s", file_Content); + fclose(pFile); + + char* fileBuf = ReadAllBytes(events_importPATH); + char* fileBuf2 = ReadAllBytes(events_PATH); + + if (fileBuf && fileBuf2) { + + cJSON *root = cJSON_Parse(fileBuf); + cJSON *s_root = cJSON_Parse(fileBuf2); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + + if (root && s_root) + { + cJSON *notification, *events_default_version,*enable_post, *enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, + *post_customized_header; + cJSON *post_sequence, *post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; + cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, + *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, + *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post, *enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion, *heatmap_max, *enable_heatmap, *heatmap_frequency, *lpr_title, *enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking, *enable_check_ptz_end_autotracking, *ptz_start_autotracking_link_to_post_event_name, *ptz_end_autotracking_link_to_post_event_name; + + cJSON *s_notification, *s_http_post_events, *s_detect2; + + notification = cJSON_GetObjectItem(root, "notification"); + s_notification = cJSON_GetObjectItem(s_root, "notification"); + + if (notification) { + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); + + enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); + snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); + snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); + heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + s_http_post_events = cJSON_GetObjectItem(s_notification, "http_post_events"); + + if (events_default_version) + { + strcpy(heartbeatData.events_default_version, events_default_version->valuestring); + cJSON_ReplaceItemInObject(s_notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); + } + + if (enable_post) + { + + activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_post", cJSON_CreateString(enable_post->valuestring)); + } + if (enable_snmp_post) + { + activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_post", cJSON_CreateString(enable_snmp_post->valuestring)); + } + if (enable_heartbeat) + { + strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); + } + if (enable_snmp_heartbeat) + { + strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); + } + if (snmp_heartbeat_dwell) + { + strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); + } + if (snmp_heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); + } + if (enable_check_ptz_start_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); + } + if (enable_check_ptz_end_autotracking) + { + strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); + } + if (enable_only_once_to_post) + { + strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); + } + if (enable_obj_once_to_post) + { + strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); + } + if (enable_location_once_to_post) + { + strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); + } + if (enable_nvr_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); + } + if (enable_8592_once_to_getalarmmotion) + { + strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); + } + if (dwell_to_the_same_location) + { + strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); + cJSON_ReplaceItemInObject(s_notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); + } + if (heartbeat_dwell) + { + strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); + } + if (heartbeat_link_to_post_event_name) + { + strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); + } + if (ptz_start_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); + } + if (ptz_end_autotracking_link_to_post_event_name) + { + strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); + } + if (heatmap_max) + { + strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); + } + if (enable_heatmap) + { + strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); + } + if (heatmap_frequency) + { + strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); + cJSON_ReplaceItemInObject(s_notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); + } + if (lpr_title) + { + strcpy(heartbeatData.lpr_title, lpr_title->valuestring); + cJSON_ReplaceItemInObject(s_notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); + } + if (enable_counter_snap) + { + strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); + } + if (enable_barcode_qr) + { + strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); + cJSON_ReplaceItemInObject(s_notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); + } + if (http_post_events) + { + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + if (detect2) + { + int j = 0; + cJSON_ArrayForEach(s_detect2, s_http_post_events) + { + if (i == j) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); + post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); + post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); + post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); + post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); + post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); + + if (post_protocol) + { + strcpy(postEventList[j].post_protocol, post_protocol->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_protocol", cJSON_CreateString(postEventList[j].post_protocol)); + } + if (post_event_method) + { + strcpy(postEventList[j].post_event_method, post_event_method->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_method", cJSON_CreateString(postEventList[j].post_event_method)); + } + if (post_event_name2) { + strcpy(postEventList[j].post_event_name, post_event_name2->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_event_name", cJSON_CreateString(postEventList[j].post_event_name)); + } + if (post_host_ip) + { + strcpy(postEventList[j].post_host_ip, post_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_ip", cJSON_CreateString(postEventList[j].post_host_ip)); + } + if (post_host_port) + { + strcpy(postEventList[j].post_host_port, post_host_port->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_host_port", cJSON_CreateString(postEventList[j].post_host_port)); + } + if (post_url) + { + strcpy(postEventList[j].post_url, post_url->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_url", cJSON_CreateString(postEventList[j].post_url)); + } + if (post_username) + { + char temp_account[512] = { 0 }; + urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); + memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); + postEventList[i].post_username[strlen(temp_account)] = '\0'; + + //strcpy(postEventList[j].post_username, post_username->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_username", cJSON_CreateString(post_username->valuestring)); + } + if (post_password) + { + char temp_account2[512] = { 0 }; + urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); + memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); + postEventList[i].post_password[strlen(temp_account2)] = '\0'; + + //strcpy(postEventList[j].post_password, post_password->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_password", cJSON_CreateString(post_password->valuestring)); + } + if (post_content) + { + strcpy(postEventList[j].post_content, post_content->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_content", cJSON_CreateString(postEventList[j].post_content)); + } + if (post_customized_header) + { + strcpy(postEventList[j].post_customized_header, post_customized_header->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_customized_header", cJSON_CreateString(postEventList[j].post_customized_header)); + } + if (post_sequence) + { + strcpy(postEventList[j].post_sequence, post_sequence->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_sequence", cJSON_CreateString(postEventList[j].post_sequence)); + } + if (post_timeout) + { + strcpy(postEventList[j].post_timeout, post_timeout->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_timeout", cJSON_CreateString(postEventList[j].post_timeout)); + } + if (post_file_format) + { + strcpy(postEventList[j].post_file_format, post_file_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_file_format", cJSON_CreateString(postEventList[j].post_file_format)); + } + if (post_jpeg_file_name_format) + { + strcpy(postEventList[j].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[j].post_jpeg_file_name_format)); + } + if (post_jpeg_file_name) + { + strcpy(postEventList[j].post_jpeg_file_name, post_jpeg_file_name->valuestring); + cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name", cJSON_CreateString(postEventList[j].post_jpeg_file_name)); + } + break; + } + j++; + } + } + i++; + } + } + + } + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name, *counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *enable_reset_only_cloud, *enable_linked_to_dwell_time;// *reset_at, *enable_time_range, *time_range_from, *time_range_to, + cJSON *link_to_post_event_name, *post_interval; + cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, + *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon, *counter_mode; + cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, + *snmp_oid, *snmp_value, *snmp_type; + + cJSON *s_event_counter_setting, *s_event_counters, *s_detect3, *s_counter_name, *s_a_report, *s_report_counters, *s_a_snmp, *s_snmp_management; + + event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); + s_event_counter_setting = cJSON_GetObjectItem(s_root, "event_counter_setting"); +#ifdef GY_OS_V_SERIES + +#else + if (event_counter_setting) + { + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + s_event_counters = cJSON_GetObjectItem(s_event_counter_setting, "event_counters"); + if (event_counters) + { + int i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + if (detect3) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + if (counter_name) { + int j = 0; + cJSON_ArrayForEach(s_detect3, s_event_counters) + { + s_counter_name = cJSON_GetObjectItem(s_detect3, "counter_name"); + if (strcmp(counter_name->valuestring, s_counter_name->valuestring) == 0) + { + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + //reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + //enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + //time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + //time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); + enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); + link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); + post_interval = cJSON_GetObjectItem(detect3, "post_interval"); + + if (counter_name) + { + strcpy(eventCounterList[j].counter_name, counter_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_name", cJSON_CreateString(eventCounterList[j].counter_name)); + } + if (counter_cust_name) + { + strcpy(eventCounterList[j].counter_cust_name, counter_cust_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_cust_name", cJSON_CreateString(eventCounterList[j].counter_cust_name)); + } + if (counter_unit) + { + strcpy(eventCounterList[j].counter_unit, counter_unit->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "counter_unit", cJSON_CreateString(eventCounterList[j].counter_unit)); + } + if (reset_value) + { + eventCounterList[j].reset_value = atoi(reset_value->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_value", cJSON_CreateString(reset_value->valuestring)); + } + if (enable_reset_time_interval) + { + strcpy(eventCounterList[j].enable_reset_time_interval, enable_reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[j].enable_reset_time_interval)); + } + if (reset_time_interval) + { + strcpy(eventCounterList[j].reset_time_interval, reset_time_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_time_interval", cJSON_CreateString(eventCounterList[j].reset_time_interval)); + } + + #if 0 + + if (reset_at) + { + strcpy(eventCounterList[j].reset_at, reset_at->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "reset_at", cJSON_CreateString(eventCounterList[j].reset_at)); + struct tm tm; + strptime_c(eventCounterList[j].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetResetAt = mktime(&tm); + struct tm *resetTime = localtime(&eventCounterList[j].timetResetAt); + eventCounterList[j].reset_month = resetTime->tm_mon; + eventCounterList[j].reset_month_day = resetTime->tm_mday; + eventCounterList[j].reset_week_day = resetTime->tm_wday; + eventCounterList[j].reset_hour = resetTime->tm_hour; + eventCounterList[j].reset_min = resetTime->tm_min; + eventCounterList[j].reset_sec = resetTime->tm_sec; + } + + if (enable_time_range) + { + strcpy(eventCounterList[j].enable_time_range, enable_time_range->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_time_range", cJSON_CreateString(eventCounterList[j].enable_time_range)); + } + if (time_range_from) + { + strcpy(eventCounterList[j].time_range_from, time_range_from->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_from", cJSON_CreateString(eventCounterList[j].time_range_from)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeFrom = mktime(&tm); + } + if (time_range_to) + { + strcpy(eventCounterList[j].time_range_to, time_range_to->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "time_range_to", cJSON_CreateString(eventCounterList[j].time_range_to)); + struct tm tm; + strptime_c(eventCounterList[j].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[j].timetTimeRangeTo = mktime(&tm); + } + #endif + + if (link_to_post_event_name) + { + strcpy(eventCounterList[j].link_to_post_event_name, link_to_post_event_name->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "link_to_post_event_name", cJSON_CreateString(eventCounterList[j].link_to_post_event_name)); + } + if (post_interval) + { + strcpy(eventCounterList[j].post_interval, post_interval->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "post_interval", cJSON_CreateString(eventCounterList[j].post_interval)); + } + if (enable_reset_only_cloud) { + strcpy(eventCounterList[j].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[j].enable_reset_only_cloud)); + } + if (enable_linked_to_dwell_time) { + strcpy(eventCounterList[j].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); + cJSON_ReplaceItemInObject(s_detect3, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[j].enable_linked_to_dwell_time)); + } + break; + } + j++; + } + } + } + + i++; + } + +#if 0 + if (strcmp(SystemSetting.cloud_enable_notification, "No") == 0) + { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + IsANPRCategory(featureType) || + g_IsCustomWeight == 1) { + pthread_mutex_lock(&mutex_reset_counter); + time_t now_time = g_osdSysTimeStamp; + if (now_time < 1000000000) { + now_time = time(0); + } + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + reset_counter(j, now_time); + } + pthread_mutex_unlock(&mutex_reset_counter); + } + } +#endif + } + + report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); + s_report_counters = cJSON_GetObjectItem(s_event_counter_setting, "report_counters"); + + if (report_counters) { + int i = 0; + cJSON_ArrayForEach(a_report, report_counters) + { + if (a_report) + { + int j = 0; + cJSON_ArrayForEach(s_a_report, s_report_counters) + { + if (i == j) { + counter_a = cJSON_GetObjectItem(a_report, "counter_a"); + counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); + counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); + counter_b = cJSON_GetObjectItem(a_report, "counter_b"); + counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); + counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); + counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); + report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); + enable_report = cJSON_GetObjectItem(a_report, "enable_report"); + counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); + initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); + detection_output = cJSON_GetObjectItem(a_report, "detection_output"); + output_icon = cJSON_GetObjectItem(a_report, "output_icon"); + + + if (counter_a) + { + strcpy(reportCounterList[j].counter_a, counter_a->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a", cJSON_CreateString(reportCounterList[j].counter_a)); + } + + if (counter_a_name) + { + strcpy(reportCounterList[j].counter_a_name, counter_a_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_name", cJSON_CreateString(reportCounterList[j].counter_a_name)); + } + + if (counter_a_zone) + { + strcpy(reportCounterList[j].counter_a_zone, counter_a_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[j].counter_a_zone)); + } + + if (counter_b) + { + strcpy(reportCounterList[j].counter_b, counter_b->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b", cJSON_CreateString(reportCounterList[j].counter_b)); + } + + if (counter_b_name) + { + strcpy(reportCounterList[j].counter_b_name, counter_b_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_name", cJSON_CreateString(reportCounterList[j].counter_b_name)); + } + + if (counter_b_zone) + { + strcpy(reportCounterList[j].counter_b_zone, counter_b_zone->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[j].counter_b_zone)); + } + + if (counter_c_name) + { + strcpy(reportCounterList[j].counter_c_name, counter_c_name->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_c_name", cJSON_CreateString(reportCounterList[j].counter_c_name)); + } + + if (report_max_value) + { + strcpy(reportCounterList[j].report_max_value, report_max_value->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "report_max_value", cJSON_CreateString(reportCounterList[j].report_max_value)); + } + + if (enable_report) + { + strcpy(reportCounterList[j].enable_report, enable_report->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "enable_report", cJSON_CreateString(reportCounterList[j].enable_report)); + } + + if (counter_mode) + { + strcpy(reportCounterList[j].counter_mode, counter_mode->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "counter_mode", cJSON_CreateString(reportCounterList[j].counter_mode)); + } + + if (initial_icon) + { + strcpy(reportCounterList[j].initial_icon, initial_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "initial_icon", cJSON_CreateString(reportCounterList[j].initial_icon)); + } + + if (detection_output) + { + strcpy(reportCounterList[j].detection_output, detection_output->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "detection_output", cJSON_CreateString(reportCounterList[j].detection_output)); + } + + if (output_icon) + { + strcpy(reportCounterList[j].output_icon, output_icon->valuestring); + cJSON_ReplaceItemInObject(s_a_report, "output_icon", cJSON_CreateString(reportCounterList[j].output_icon)); + } + + break; + } + j++; + } + } + + i++; + } + } + + snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); + s_snmp_management = cJSON_GetObjectItem(s_event_counter_setting, "snmp_management"); + + if (snmp_management) { + int i = 0; + cJSON_ArrayForEach(a_snmp, snmp_management) + { + if (a_snmp) + { + int j = 0; + cJSON_ArrayForEach(s_a_snmp, s_snmp_management) + { + if (i == j) { + snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); + snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); + snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); + snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); + snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); + snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); + snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); + snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); + + + if (snmp_event_name) + { + strcpy(SNMPManagementList[j].snmp_event_name, snmp_event_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[j].snmp_event_name)); + } + + if (snmp_version) + { + strcpy(SNMPManagementList[j].snmp_version, snmp_version->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[j].snmp_version)); + } + + if (snmp_group_name) + { + strcpy(SNMPManagementList[j].snmp_group_name, snmp_group_name->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[j].snmp_group_name)); + } + + if (snmp_host_ip) + { + strcpy(SNMPManagementList[j].snmp_host_ip, snmp_host_ip->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[j].snmp_host_ip)); + } + + if (snmp_host_port) + { + strcpy(SNMPManagementList[j].snmp_host_port, snmp_host_port->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[j].snmp_host_port)); + } + + if (snmp_oid) + { + strcpy(SNMPManagementList[j].snmp_oid, snmp_oid->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[j].snmp_oid)); + } + + if (snmp_value) + { + strcpy(SNMPManagementList[j].snmp_value, snmp_value->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[j].snmp_value)); + } + + if (snmp_type) + { + strcpy(SNMPManagementList[j].snmp_type, snmp_type->valuestring); + cJSON_ReplaceItemInObject(s_a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[j].snmp_type)); + } + break; + } + j++; + } + } + + i++; + } + } + } +#endif + cJSON *email_setting, *email_content; + cJSON *s_email_setting; + + email_setting = cJSON_GetObjectItem(root, "email_setting"); + s_email_setting = cJSON_GetObjectItem(s_root, "email_setting"); + + if (email_setting) + { + email_content = cJSON_GetObjectItem(email_setting, "email_content"); + if (email_content) { + strcpy(emailData.email_content, email_content->valuestring); + cJSON_ReplaceItemInObject(s_email_setting, "email_content", cJSON_CreateString(emailData.email_content)); + } + } + + char* JsonString = cJSON_Print(s_root); + + FILE *f = fopen(events_PATH, "w"); + if (f != NULL) + { + + fprintf(f, "%s\n", JsonString); + fclose(f); + + CopyFileTo(events_PATH, events_bakPATH); + + check_if_setfile_OK = 1; + g_count_alter = 50; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + } + else { + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (fileBuf2) { + free(fileBuf2); + fileBuf2 = NULL; + } + printf("\nFail to read events_import.json or events.json\n"); + } + } + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + if (check_if_setfile_OK == 1) { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventscustom2)\n"); + } + else { + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not seteventscustom2#2)\n"); + } + + pthread_mutex_unlock(&mutex_events_json); + + closesocket(cli_socket); + + check_if_correct_post = 0; + } +#if 0 + else if (strncmp(urlBuffer, "/setjvcconfigfile", strlen("/setjvcconfigfile")) == 0) { + int check_if_setfile_OK = 0; + //printf("----------------------------[setjvcconfigfile]recvBuffer: %s\n", recvBuffer); + + pthread_mutex_lock(&mutex_jvc_config_json); + + check_if_setfile_OK = 1; + + int file_buff_size = nTotalContentLen; + //char msg_temp[512] = { 0 }; +#if 1 + if (file_buff_size >= 1) + { + char* file_Content = recvBuffer + recv_buff_size; + + //printf("\n------file_buff_size:%d\n", file_buff_size); + //printf("\n------file_Content:%s\n", file_Content); + + jvc_setconfig(file_Content); + + + //sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); + //printf("\n--------------------reload 4: %s\n", msg_temp); + } +#endif + +#if 0 + jvc_setMainSetting(); +#endif + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + //printf("jvc configfile: \n %s \n", beforeSendBuffer); + if (check_if_setfile_OK == 1) { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile)\n"); + } + else { + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile#2)\n"); + } + + pthread_mutex_unlock(&mutex_jvc_config_json); + +#if 0 + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not setconfigfile)\n"); +#endif + closesocket(cli_socket); + } +#endif + else if (strcmp(urlBuffer, "/sendyuv") == 0) + { + //printf("\n[web process]start 28\n"); + char *image_buff = NULL; + size_t image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + memset(image_buff, 0x00, CONTENT_BUFSIZE); + + char* pContent = contentBuffer; + char* pBlockEnd = contentBuffer; + //image_buff_size = nTotalContentLen; + //size_t nbytes = 0; + //size_t nTotalBytes = 0; + + int yuv_width = 0; + int yuv_height = 0; + char resolutionStr[10] = { 0 }; + char resolution[2][STRSPLIT_SIZE]={0}; + const char *del = "x"; + + char* pYUVStart = NULL; + char* pYUVEnd = NULL; + //int nNeedUpdateTrafficLightZone = 0; + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, MSG_RESOLUTION_PATTERN, strlen(MSG_RESOLUTION_PATTERN)) == 0) + { + pBlockEnd = strstr(pContent, "\r\n"); + pYUVStart = pBlockEnd + 2; + //DumpHex(pYUVStart, 320); + memcpy(resolutionStr, pContent + strlen(MSG_RESOLUTION_PATTERN), pBlockEnd - (pContent + strlen(MSG_RESOLUTION_PATTERN))); + if (strlen(resolutionStr) > 0) + { + //if (abs(viewChannelData[tracking_channel_idx].tab_view_width_ratio * viewChannelData[tracking_channel_idx].tab_view_width - AIImage_width) > 5) + //nNeedUpdateTrafficLightZone = 1; + StrSplit(resolutionStr, resolution, del); + //printf("\n------UU:36\n"); + yuv_width = atoi(resolution[0]); + yuv_height = atoi(resolution[1]); + viewChannelData[tracking_channel_idx].tab_view_width_ratio = (float)yuv_width / viewChannelData[tracking_channel_idx].tab_view_width; + viewChannelData[tracking_channel_idx].tab_view_height_ratio = (float)yuv_height / viewChannelData[tracking_channel_idx].tab_view_height; + #ifdef GY_OS_WIN + if (nNeedUpdateTrafficLightZone) + UpdateTrafficLightZone(tracking_channel_idx); + #endif + } + break; + } + /*else if (strncmp(pContent, MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0) + { + pYUVEnd = pContent; + break; + }*/ + } + + for (int i = nTotalContentLen - strlen(MSG_END_PATTERN); i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0) + { + pYUVEnd = pContent; + break; + } + } + + image_buff_size = pYUVEnd - pYUVStart; + memcpy(image_buff, pYUVStart, image_buff_size); + + if (!pYUVStart || !pYUVEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error YUV format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + //printf("\n[web process]-A-6: free(contentBuffer)\n"); + if (contentBuffer) { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + + //printf("\n[web process]-A-6: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + + clock_t t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("pre AI recog time: %f\n", diff); + /*int local_tracking_idx = 0; + int b_nav_channel_exist = 0; + for (int i = 0; i <= MAX_CLIENT_SOCKET; i++) + { + if (g_TrackingIDAndChannel[i][1] == nav_tracking_channel) + { + local_tracking_idx = i; + b_nav_channel_exist = 1; + break; + } + } + + if (!b_nav_channel_exist) + { + local_tracking_idx = tracking_idx; + memset(g_TrackingIDAndChannel[local_tracking_idx], 0x00, sizeof(g_TrackingIDAndChannel[local_tracking_idx])); + g_TrackingIDAndChannel[local_tracking_idx][1] = nav_tracking_channel; + }*/ + + socketRecords[sock_info_idx].channel_id = tracking_channel; + + clock_t c1 = clock(); + + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nweb process: %d\n", 2); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time %d:%f\n", cli_socket, dDiff); + + if (image_buff) { + free(image_buff); + image_buff = NULL; + } + } +#if 0 + else if (strncmp(urlBuffer, "/user_command", strlen("/user_command")) == 0) + { + //printf("\n[web process]start 29\n"); + //char *start = NULL; + char *pDelim = NULL; + QueueInfo q_info = { 0 }; + MapClear(); + char CorrectParameter[MAX_MSG_LEN * 2] = { 0 }; + char* pContent = contentBuffer + strlen(MSG_START_PATTERN); + printf("recv /user_command : %s\n", pContent); + //start = contentBuffer + 2; + do { + pDelim = strstr(pContent, "\r\n"); + // string between start and delim (or end of string if delim is NULL). + if (pDelim) + { + char attribute[512] = { 0 };//512 + memset(attribute, 0x00, sizeof(attribute)); + //memset(OriAttribute, 0x00, sizeof(OriAttribute)); + memcpy(attribute, pContent, pDelim - pContent); + //memcpy(OriAttribute, pContent, pDelim - pContent); + memset(CorrectParameter, 0x00, sizeof(CorrectParameter)); + attribute[pDelim - pContent] = 0; + char att_var[10][STRSPLIT_SIZE]={0}; + char *del = "="; + int att_var_num = 0; + if (attribute) + { + att_var_num = StrSplit(attribute, att_var, del); + if (att_var_num == 2) + { + sprintf(CorrectParameter, "%s", att_var[1]); + } + if (att_var_num > 2) + { + for (int n = 1; n < att_var_num; n++) + { + if (n == 1) + sprintf(CorrectParameter, "%s", att_var[1]); + else + sprintf(CorrectParameter, "%s%s%s", CorrectParameter, del, att_var[n]); + } + } + int anpr_ch = -1; + + if (strcmp(att_var[0], "<ANPR_channel>") == 0) + anpr_ch = atoi(att_var[1]); + + if (anpr_ch != -1) + { + //char filename[] = "config.json"; + char *filename = configPATH; + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + cJSON* view_setting = cJSON_GetObjectItem(root, "view_setting"); + + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", anpr_ch + 1); + cJSON* camera = cJSON_GetObjectItem(view_setting, CameraID); + + if (strcmp(att_var[0], "<ANPR_enable>") == 0) + { + if (strcmp(att_var[1], "1") == 0) + { + viewChannelData[anpr_ch].channel_idx = 1; + } + if (strcmp(att_var[1], "0") == 0) + { + viewChannelData[anpr_ch].channel_idx = 0; + } + + cJSON_ReplaceItemInObject(camera, "enable_anpr", cJSON_CreateString(att_var[1])); + } + if (strcmp(att_var[0], "<ANPR_confidence>") == 0) + { + strcpy(viewChannelData[anpr_ch].confidence, att_var[1]); + cJSON_ReplaceItemInObject(camera, "confidence", cJSON_CreateString(att_var[1])); + } + if (strcmp(att_var[0], "<ANPR_min_characters>") == 0) + { + strcpy(viewChannelData[anpr_ch].min_characters, att_var[1]); + cJSON_ReplaceItemInObject(camera, "min_characters", cJSON_CreateString(att_var[1])); + } + if (strcmp(att_var[0], "<ANPR_max_characters>") == 0) + { + strcpy(viewChannelData[anpr_ch].max_characters, att_var[1]); + cJSON_ReplaceItemInObject(camera, "max_characters", cJSON_CreateString(att_var[1])); + } + + char* JsonString = cJSON_Print(root); + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + //copy config.json to config_bak.json + CopyFileTo(filename, config_bakPATH); + } + else + printf("Fail to open Config.json \n"); + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + + if (strcmp(att_var[0], "<enable_post>") == 0) + { + activePostNotification = atoi(att_var[1]) > 0 ? _TRUE : _FALSE; + { + //char filename[] = "config.json"; + char *filename = configPATH; + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) { + //cJSON* cam_ip, * http_port, * vedio_port, * cam_username, * cam_pwd, * channel_id; + cJSON *camera, *camera_name, *obj_max_proportion, *obj_min_proportion, *tab_view_size, *enable_lpr_db, *count_zone, *enable_anpr, *enable_traffic, *enable_logo, *temp_detection_zone, *detect, + *levenshtein_distance, *min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, + *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_TRIGGER_EVENT], *checked, *detect_event_id, *detect_event_name, *post_event_name, *counter_name,*counter_cust_name, *counter_increment, + *point_num, + *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6; + cJSON* root = cJSON_Parse(fileBuf); + + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + + cJSON* view_setting = cJSON_GetObjectItem(root, "view_setting"); + + for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) + { + char CameraID[20] = { 0 }; + sprintf(CameraID, "camera%02d", n + 1); + camera = cJSON_GetObjectItem(view_setting, CameraID); + + /*cam_ip = cJSON_GetObjectItem(camera, "ip"); + http_port = cJSON_GetObjectItem(camera, "http_port"); + vedio_port = cJSON_GetObjectItem(camera, "vedio_port"); + cam_username = cJSON_GetObjectItem(camera, "username"); + cam_pwd = cJSON_GetObjectItem(camera, "password"); + channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ + camera_name = cJSON_GetObjectItem(camera, "camera_name"); + obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); + obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); + levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(camera, "min_characters"); + max_characters = cJSON_GetObjectItem(camera, "max_characters"); + confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate P + confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic q + confidence3 = cJSON_GetObjectItem(camera, "confidence3"); + confidence4 = cJSON_GetObjectItem(camera, "confidence4"); + enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); + count_zone = cJSON_GetObjectItem(camera, "count_zone"); + + strcpy(viewChannelData[n].camera_name, camera_name->valuestring); + strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); + strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); + + strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewChannelData[n].min_characters, min_characters->valuestring); + strcpy(viewChannelData[n].max_characters, max_characters->valuestring); + strcpy(viewChannelData[n].confidence, confidence->valuestring); + strcpy(viewChannelData[n].confidence2, confidence2->valuestring); + strcpy(viewChannelData[n].confidence3, confidence3->valuestring); + strcpy(viewChannelData[n].confidence4, confidence4->valuestring); + + strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); + viewChannelData[n].count_zone = count_zone->valueint; + + tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); + //printf("\n[web process]tab_view_size: %s\n", tab_view_size->valuestring); + char temp_tab[50] = { 0 }; + strcpy(temp_tab, tab_view_size->valuestring); + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(temp_tab, outArray, "x"); + //printf("\n------UU:37\n"); + viewChannelData[n].channel_idx = n; + + viewChannelData[n].tab_view_width = atoi(outArray[0]); + viewChannelData[n].tab_view_height = atoi(outArray[1]); + + enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); + if (strcmp(enable_anpr->valuestring, "Yes") == 0) + viewChannelData[n].enable_anpr = 1; + else + viewChannelData[n].enable_anpr = 0; + + enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); + if (strcmp(enable_traffic->valuestring, "Yes") == 0) + viewChannelData[n].enable_traffic = 1; + else + viewChannelData[n].enable_traffic = 0; + + enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); + if (strcmp(enable_logo->valuestring, "Yes") == 0) + viewChannelData[n].enable_logo = 1; + else + viewChannelData[n].enable_logo = 0; + + + temp_detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); + viewChannelData[n].enable_traffic_light_zone = 0; + int i = 0; + cJSON_ArrayForEach(detect, temp_detection_zone) + { + /*levenshtein_distance = cJSON_GetObjectItem(detect, "levenshtein_distance"); + min_characters = cJSON_GetObjectItem(detect, "min_characters"); + max_characters = cJSON_GetObjectItem(detect, "max_characters"); + confidence = cJSON_GetObjectItem(detect, "confidence");*/ + enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); + detection_time = cJSON_GetObjectItem(detect, "detection_time"); + metadata1 = cJSON_GetObjectItem(detect, "metadata1"); + metadata2 = cJSON_GetObjectItem(detect, "metadata2"); + metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); + link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); + enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); + enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); + direction1 = cJSON_GetObjectItem(detect, "direction1"); + direction2 = cJSON_GetObjectItem(detect, "direction2"); + /*confidence3 = cJSON_GetObjectItem(detect, "confidence3");*/ + no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); + no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); + queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); + trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); + + point_num = cJSON_GetObjectItem(detect, "point_number"); + + x1 = cJSON_GetObjectItem(detect, "x1"); + y1 = cJSON_GetObjectItem(detect, "y1"); + x2 = cJSON_GetObjectItem(detect, "x2"); + y2 = cJSON_GetObjectItem(detect, "y2"); + x3 = cJSON_GetObjectItem(detect, "x3"); + y3 = cJSON_GetObjectItem(detect, "y3"); + x4 = cJSON_GetObjectItem(detect, "x4"); + y4 = cJSON_GetObjectItem(detect, "y4"); + + x5 = cJSON_GetObjectItem(detect, "x5"); + y5 = cJSON_GetObjectItem(detect, "y5"); + x6 = cJSON_GetObjectItem(detect, "x6"); + y6 = cJSON_GetObjectItem(detect, "y6"); + + /*strcpy(viewDetectionZone[n][i].levenshtein_distance, levenshtein_distance->valuestring); + strcpy(viewDetectionZone[n][i].min_characters, min_characters->valuestring); + strcpy(viewDetectionZone[n][i].max_characters, max_characters->valuestring); + strcpy(viewDetectionZone[n][i].confidence, confidence->valuestring);*/ + strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); + strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); + strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); + if(metadata_stop) + strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); + strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); + strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); + strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); + strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); + if (no_parking_time) + viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); + if (no_parking_time_in_minute) + viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); + + if (queuing_count) + viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); + /*strcpy(viewDetectionZone[n][i].confidence3, confidence3->valuestring);*/ + + if (point_num) + viewDetectionZone[n][i].point_num = point_num->valueint; + + viewDetectionZone[n][i].Points[0].x = x1->valueint; + viewDetectionZone[n][i].Points[0].y = y1->valueint; + viewDetectionZone[n][i].Points[1].x = x2->valueint; + viewDetectionZone[n][i].Points[1].y = y2->valueint; + viewDetectionZone[n][i].Points[2].x = x3->valueint; + viewDetectionZone[n][i].Points[2].y = y3->valueint; + viewDetectionZone[n][i].Points[3].x = x4->valueint; + viewDetectionZone[n][i].Points[3].y = y4->valueint; + + viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); + + if (x5 && x6) + { + viewDetectionZone[n][i].Points[4].x = x5->valueint; + viewDetectionZone[n][i].Points[4].y = y5->valueint; + viewDetectionZone[n][i].Points[5].x = x6->valueint; + viewDetectionZone[n][i].Points[5].y = y6->valueint; + + viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); + viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); + viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); + } + + strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); + if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) + { + viewChannelData[n].enable_traffic_light_zone = i + 1; +#ifdef GY_OS_WIN + UpdateTrafficLightZone(n); +#endif + } + i++; + + if (i < MAX_DETECTION_ZONE) { + + } + else { + break; + } + } + + //int arraySize = cJSON_GetArraySize(temp_detection_zone); + int k = 0; + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + k = 0; + cJSON_ArrayForEach(detect, trigger_events[j]) + { + checked = cJSON_GetObjectItem(detect, "checked"); + detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); + detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); + post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); + counter_name = cJSON_GetObjectItem(detect, "counter_name"); + counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); + + viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); + strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); + + if (counter_increment) { + if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; + else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; + else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) + viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + } + else + viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; + k++; + } + } + } + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } + //break; + } + + if (strcmp(att_var[0], "<reload_post_events>") == 0) + { + //post events setting + //char filename2[] = "events.json"; + char *filename2 = eventsPATH; + if (!FileExist(filename2)) + { + printf("%s doesn't exist.\n", filename2); + printf("Press any key to exit...\n"); + getchar(); + //printf("\n[web process]-A-7: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + return; + } + + char* fileBuf = ReadAllBytes(filename2); + if (fileBuf) { + + cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content; + cJSON *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max, *enable_heatmap, *heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, + *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; + + n_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + + if (n_root) { + notification = cJSON_GetObjectItem(n_root, "notification"); + events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); + enable_post = cJSON_GetObjectItem(notification, "enable_post"); + enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); + + enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); + enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); + ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); + ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); + + enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); + enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); + enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); + enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); + enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); + + http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); + heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); + enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); + heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); + lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); + enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); + enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); + + int i = 0; + cJSON_ArrayForEach(detect2, http_post_events) + { + post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); + post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); + post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); + post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); + post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); + post_url = cJSON_GetObjectItem(detect2, "post_url"); + post_username = cJSON_GetObjectItem(detect2, "post_username"); + post_password = cJSON_GetObjectItem(detect2, "post_password"); + post_content = cJSON_GetObjectItem(detect2, "post_content"); + + strcpy(postEventList[i].post_protocol, post_protocol->valuestring); + strcpy(postEventList[i].post_event_method, post_event_method->valuestring); + strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); + strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); + strcpy(postEventList[i].post_host_port, post_host_port->valuestring); + strcpy(postEventList[i].post_url, post_url->valuestring); + strcpy(postEventList[i].post_username, post_username->valuestring); + strcpy(postEventList[i].post_password, post_password->valuestring); + strcpy(postEventList[i].post_content, post_content->valuestring); + i++; + } + + cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to; + +#ifdef GY_OS_V_SERIES + +#else + event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); + event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); + + i = 0; + cJSON_ArrayForEach(detect3, event_counters) + { + counter_name = cJSON_GetObjectItem(detect3, "counter_name"); + counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); + counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); + reset_value = cJSON_GetObjectItem(detect3, "reset_value"); + enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); + reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); + reset_at = cJSON_GetObjectItem(detect3, "reset_at"); + enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); + time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); + time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); + + strcpy(eventCounterList[i].counter_name, counter_name->valuestring); + strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); + strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); + if (reset_value->valuestring) + eventCounterList[i].reset_value = atoi(reset_value->valuestring); + else + eventCounterList[i].reset_value = 0; + strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); + strcpy(eventCounterList[i].reset_at, reset_at->valuestring); + strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); + strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); + strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); + struct tm tm; + strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetResetAt = mktime(&tm); + struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); + eventCounterList[i].reset_month = resetTime->tm_mon; + eventCounterList[i].reset_month_day = resetTime->tm_mday; + eventCounterList[i].reset_week_day = resetTime->tm_wday; + eventCounterList[i].reset_hour = resetTime->tm_hour; + eventCounterList[i].reset_min = resetTime->tm_min; + eventCounterList[i].reset_sec = resetTime->tm_sec; + strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeFrom = mktime(&tm); + strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); + eventCounterList[i].timetTimeRangeTo = mktime(&tm); + i++; + } +#endif + + if (n_root) { + cJSON_Delete(n_root); + n_root = NULL; + } + } + } + } + + if (strcmp(att_var[0], "<enable_display>") == 0) + { + if (strcmp(att_var[1], "1 dash") == 0) + activeDisplayDash = _TRUE; + + if (strcmp(att_var[1], "0 dash") == 0) + activeDisplayDash = _FALSE; + + if (strcmp(att_var[1], "1 properties") == 0) + activeDisplayProperties = _TRUE; + + if (strcmp(att_var[1], "0 properties") == 0) + activeDisplayProperties = _FALSE; + } + + //test http notification + if (strcmp(att_var[0], "<post_event_method>") == 0) + { + testPostNotification = _TRUE; + strcpy(q_info.post_method, CorrectParameter); + } + + //if (strcmp(att_var[0], "<post_event_name>") == 0) + //strcpy(q_info.post_name, CorrectParameter); + + if (strcmp(att_var[0], "<post_host_name>") == 0) + strcpy(q_info.host_name, CorrectParameter); + + if (strcmp(att_var[0], "<post_host_port>") == 0) + strcpy(q_info.host_port, CorrectParameter); + + if (strcmp(att_var[0], "<post_url>") == 0) + { + //strcpy(q_info.post_url, OriAttribute + strlen("<post_url>=")); + strcpy(q_info.post_url, CorrectParameter); + } + + if (strcmp(att_var[0], "<post_username>") == 0) + strcpy(q_info.post_username, CorrectParameter); + + if (strcmp(att_var[0], "<post_password>") == 0) + strcpy(q_info.post_password, CorrectParameter); + + if (strcmp(att_var[0], "<post_content>") == 0) + { + strcpy(q_info.content, CorrectParameter); + } + + /*char Value[MAX_MSG_LEN] = { 0 }; + MapFind("<web_kit_form_boundary>", Value); + printf("%s",Value);*/ + } + pContent = pDelim + 2; // Use length of your b string. + } + } + while (pDelim); + + if (testPostNotification) + { + //pthread_mutex_lock(&mutex_post_notification); + if (!q_info.content) + { + memset(q_info.content, 0x00, strlen(pContent) + 1); + } + q_info.image_buff = NULL; //20201105 sophia add + q_info.image_buff_size = 0; + //q_info.pNext = malloc(sizeof(detection_pos)); + if (AI_fps >= 1) + QueuePush(q_info, _POST_NOTIFICATION); + //pthread_mutex_unlock(&mutex_post_notification); + testPostNotification = _FALSE; + } + } +#endif + else if (strncmp(urlBuffer, "/import_lpr_map_list", strlen("/import_lpr_map_list")) == 0) + { +#ifdef GY_OS_AMBA + //printf("\n[web process]start 30\n"); + char *image_buff = NULL; + //int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + //char httpVariables[BUFSIZE_V2] = { 0 }; + //char boundary[255] = {0}; + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr( headerBuffer, "boundary=" )) != NULL) + { + int strlen =0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, sizeof(multiPartBoundary)); + //char endStr[] = "--"; + strncpy(multiPartBoundary, tempPtr, strlen); + //strcat(multiPartBoundary,endStr); + } + } + } + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + //image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0)//find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + }else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + + } + + } + } + if (!((image_buff[0]== 0xef) && (image_buff[1]== 0xbb) && (image_buff[2]== 0xbf))) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "file type error."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + else + { + int map_length = 0; + char *lpr_data_p = NULL; + char *lpr_line_data = NULL,*value = NULL; + int lpr_len = 0; + int nlen; + char *lpr_detect = NULL; + char *lpr_plate = NULL; + char *lpr_line_end = NULL; + callback_reset_db_map_list(); //clean mapping table + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + lpr_line_data=lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + if (lpr_line_end != NULL) + { + lpr_len = lpr_line_end - lpr_line_data; + } + + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_line_data; + + if(map_length == COUNT_MAPPING) + break; + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0]||(lpr_line_data[0]=='\r')||(lpr_line_data[0]=='\n')); lpr_line_data++); + lpr_detect = strsep(&value, ","); + if ((lpr_plate = strsep(&value, "\r\n"))==NULL) + lpr_plate = strsep(&value, "\n"); + if ((lpr_detect != NULL) && (lpr_plate != NULL)) + { + lpr_plate = rtrim(lpr_plate); + action_import_lpr_map_info( lpr_detect, lpr_plate); + map_length++; + } + + lpr_line_end = strstr(lpr_line_data, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + if (lpr_line_end != NULL) + { + lpr_len = lpr_line_end - lpr_line_data; + } + } + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "lpr map file upload ok."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\nweb process: %d\n", 3); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time %d:%f\n", cli_socket, dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } +#endif //#ifdef GY_OS_AMBA + } + else if (strncmp(urlBuffer, "/import_lpr_list", strlen("/import_lpr_list")) == 0) + { + //printf("\n-------------import lpr list\n"); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + g_count_lpr_insert_times = 0; + + memset(g_headerBuffer,0x00, BUFSIZE_V2); + memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); + memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); + + strcpy(g_headerBuffer, headerBuffer); + strcpy(g_multiPartBoundary, multiPartBoundary); + g_bIsMultipart = bIsMultipart; + strcpy(g_contentBuffer, contentBuffer); + g_nTotalContentLen = nTotalContentLen; + + //printf("\n-----g_contentBuffer:%s\n", g_contentBuffer); + + pthread_t import_lpr_list_file_thread_id; + if (pthread_create(&import_lpr_list_file_thread_id, 0, import_lpr_list_file_thread, NULL)) + { + printf("create import_lpr_list_file_thread thread faile \n"); + } + + strcpy(beforeSendBuffer, ""); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + +#endif + closesocket(cli_socket); + } +#if 0 + else if (strncmp(urlBuffer, "/import_radarbg", strlen("/import_radarbg")) == 0) // a113n 10/6 + { + pthread_mutex_lock(&mutex_web); + // copy from /sendjpeg + { + char *image_buff = NULL; + int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + //char httpVariables[BUFSIZE_V2] = {0}; + + int check_if_error = 0; + + if (bIsMultipart) + { + char *pContent = contentBuffer; + char *pBlockStart = contentBuffer; + image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + } + char *pJpegStart = NULL; + char *pJpegEnd = NULL; + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) + { + pJpegStart = image_buff + i; + break; + } + } + + for (int i = nTotalBytes; i > 0; i--) + { + if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) + { + pJpegEnd = image_buff + i + 2; + break; + } + } + + // printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); + + if (!pJpegStart || !pJpegEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format(Multipart)."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not JPEG format)\n"); + + // printf("\n[web process]-A-3: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + check_if_error = 1; + // printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); + } + else + { + image_buff_size = pJpegEnd - pJpegStart; + memmove(image_buff, pJpegStart, image_buff_size); + + // printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); + + memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); + } + } + else + { + image_buff_size = nTotalContentLen; + memcpy(image_buff, contentBuffer, image_buff_size); + // DumpHex(image_buff + image_buff_size - 10, 10); + } + + if (check_if_error == 0) { + if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) + { + // DumpHex(image_buff, 2); + // DumpHex(image_buff + image_buff_size - 2, 2); + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + // printf("\n[web process]-A-4: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + // printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); + } + else { + GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); + + FILE *f = fopen("/emmc/plugin/Aida_data/radar/radar_user.jpg", "wb"); + if (f == NULL) + { + printf("Error opening file!\n"); + // exit(1); + } + fwrite(image_buff, image_buff_size, 1, f); + fclose(f); + + Reread_radarbg(); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + } + } + } + closesocket(cli_socket); + pthread_mutex_unlock(&mutex_web); + } + else if (strncmp(urlBuffer, "/import_speedbg", strlen("/import_speedbg")) == 0) // 2022-11-03 Ken, thanks to a113n! + { + pthread_mutex_lock(&mutex_web); + // copy from /sendjpeg + { + char *image_buff = NULL; + int image_buff_size = 0; + image_buff = malloc(CONTENT_BUFSIZE); + //char httpVariables[BUFSIZE_V2] = {0}; + + int check_if_error = 0; + + if (bIsMultipart) + { + char *pContent = contentBuffer; + char *pBlockStart = contentBuffer; + image_buff_size = nTotalContentLen; + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + } + char *pJpegStart = NULL; + char *pJpegEnd = NULL; + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) + { + pJpegStart = image_buff + i; + break; + } + } + + for (int i = nTotalBytes; i > 0; i--) + { + if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) + { + pJpegEnd = image_buff + i + 2; + break; + } + } + + // printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); + + if (!pJpegStart || !pJpegEnd) + { + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format(Multipart)."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend(Not JPEG format)\n"); + + // printf("\n[web process]-A-3: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + check_if_error = 1; + // printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); + } + else + { + image_buff_size = pJpegEnd - pJpegStart; + memmove(image_buff, pJpegStart, image_buff_size); + + // printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); + + memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); + } + } + else + { + image_buff_size = nTotalContentLen; + memcpy(image_buff, contentBuffer, image_buff_size); + // DumpHex(image_buff + image_buff_size - 10, 10); + } + + if (check_if_error == 0) { + if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) + { + // DumpHex(image_buff, 2); + // DumpHex(image_buff + image_buff_size - 2, 2); + memset(msg, 0x00, sizeof(msg)); + sprintf(msg, "Error JPEG format."); + printf("%s\n", msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + // printf("\n[web process]-A-4: free(contentBuffer)\n"); + if (contentBuffer) + { + free(contentBuffer); + contentBuffer = NULL; + } + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + // printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); + } + else { + GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); + + FILE *f = fopen("/emmc/plugin/Aida_data/radar/speed_user.jpg", "wb"); + if (f == NULL) + { + printf("Error opening file!\n"); + // exit(1); + } + fwrite(image_buff, image_buff_size, 1, f); + fclose(f); + + Reread_speedbg(); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } + + } + } + } + closesocket(cli_socket); + pthread_mutex_unlock(&mutex_web); + } +#endif + //printf("\n---------PP 1\n"); + } + // else if (strncmp(urlBuffer, "/import_radar_img", strlen("/import_radar_img")) == 0) // Ken 10-07 10-11 + // { + // #ifdef GY_OS_AMBA + + // memset(g_headerBuffer, 0x00, BUFSIZE_V2); + // memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); + // memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); + + // strcpy(g_headerBuffer, headerBuffer); + // strcpy(g_multiPartBoundary, multiPartBoundary); + // g_bIsMultipart = bIsMultipart; + // strcpy(g_contentBuffer, contentBuffer); + // g_nTotalContentLen = nTotalContentLen; + + // pthread_t import_lpr_list_file_thread_id; + // if (pthread_create(&import_lpr_list_file_thread_id, 0, import_lpr_list_file_thread, NULL)) + // { + // printf("create import_lpr_list_file_thread thread faile \n"); + // } + + // strcpy(beforeSendBuffer, ""); + // if (strlen(contentDescription) > 0) + // { + // strcat(beforeSendBuffer, " "); + // strcat(beforeSendBuffer, contentDescription); + // } + + // int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + // if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + // printf("\nsend\n"); + + // #endif + // closesocket(cli_socket); + // } + // } + + else + { + //printf("\n[web process]start 32\n"); + sprintf(msg, "URL not Found."); + printf(msg); + + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + if (strlen(contentDescription) > 0) + { + strcat(beforeSendBuffer, " "); + strcat(beforeSendBuffer, contentDescription); + } + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_404, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error #38\n"); + + //printf("\n[web process]-6: closesocket(cli_socket): %d\n", cli_socket); + closesocket(cli_socket); + } + //printf("\n---------PP 2\n"); + //printf("\nhellllo4\n"); +} + +/*int caculate_ftp_of_each_sockets(SOCKET sock, int *sock_record_idx) +{ + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + socketRecords[i].last_recv_time = time(0); + int idx_last_recv_time_min = 0; + time_t last_recv_time_min = 0; + *sock_record_idx = i; + //printf("last recv time=%I64d\n", socketRecords[i].last_recv_time); + for (int j = 0; j < FPS_AVG_SECS; j++) + { + if (socketRecords[i].recent_sec_data[j].recv_time == socketRecords[i].last_recv_time) + { + socketRecords[i].recent_sec_data[j].frames++; + break; + } + + if (socketRecords[i].recent_sec_data[j].recv_time <= socketRecords[i].last_recv_time - FPS_AVG_SECS) + { + socketRecords[i].recent_sec_data[j].frames = 0; + socketRecords[i].recent_sec_data[j].recv_time = 0; + } + + if (j == 0) + { + idx_last_recv_time_min = 0; + last_recv_time_min = socketRecords[i].recent_sec_data[j].recv_time; + } + else + { + if (socketRecords[i].recent_sec_data[j].recv_time < last_recv_time_min) + { + idx_last_recv_time_min = j; + last_recv_time_min = socketRecords[i].recent_sec_data[j].recv_time; + } + } + + if (j == FPS_AVG_SECS - 1) + { + socketRecords[i].recent_sec_data[idx_last_recv_time_min].frames = 1; + socketRecords[i].recent_sec_data[idx_last_recv_time_min].recv_time = socketRecords[i].last_recv_time; + } + } + return i; + } + } + } + return -1; +}*/ + +///Create this thread by run_http_server for each socket + +void sharkhand_s_connection_upgrade(int* sock,char *buffer,int* websocket_connected) { + + //if (0 == websocket_connected) + { + /*if ((*websocket_connected) == 0)*/ + { + //int count_sharkhand = 0; + int iIsWebsocketHybi00 = 0; + //while (sharkhand_s((*sock), buffer, &iIsWebsocketHybi00) < 0 && count_sharkhand < MAX_SHARKHAND_REPEAT) { + + sharkhand_s((*sock), buffer, &iIsWebsocketHybi00); + /* + while (sharkhand_s((*sock), buffer, websocket_connected) < 0 && count_sharkhand < MAX_SHARKHAND_REPEAT) { + //printf("\n[%d]build sharkhand - repeat: %d\n", sock, count_sharkhand); + count_sharkhand++; + usSleep(1000); + }*/ + + (*websocket_connected) = 1; + + /* + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //printf("rA[%d]=%d, *sock=%d \n", i, socketRecords[i].sock, *sock); + if (socketRecords[i].sock == *sock) + { + //socketRecords[i].iIsWebsocketHybi00 = iIsWebsocketHybi00; + //printf("idx[%d]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is hybi00: %d \n", i, socketRecords[i].iIsWebsocketHybi00); + } + + }*/ + } + } + +} + +static int is_authorized_run_preload_http_server = 1; +//static int is_WebsocketConnecting = 0; +#if 0 +static int is_referer_from_setup = 0; +#endif + +void *http_connection_handler(void *socket_desc) +{ + pthread_detach(pthread_self()); + setPthreadName("http_conn"); + //pthread_mutex_lock(&mutex_http_connection_handler); + //printf("\n[http_connection_handler] Pthread created and detached.\n"); + //printf("\n---------http connection handler ----------- 1\n"); + int sock = (intptr_t)socket_desc; // Get the socket descriptor + //char buffer[BUFSIZE_V2]; + char buffer[BUFSIZE * 59] = { 0 }; + + char recvbuffer[BUFSIZE * 60] = {0};//BUFSIZE * 60 + char contentBuffer[BUFSIZE * 60] = {0};//BUFSIZE * 60 + + unsigned int nTotalBytes = 0; + unsigned int nContentLength = 0; + int nbytes = 0; + clock_t t1 = clock(); + clock_t t2; + //int bIsMultipart = 0; + char sendBuffer[8196] = { 0 }; + int isGetAlarmMotion = FALSE; + //int sock_record_idx = -1; + + int websocket_connected = 0; + + //char *secWebSocketKey; + //char *data; + + //g_tracking_idx++; + + //if (g_tracking_idx >= MAX_CLIENT_SOCKET) + // g_tracking_idx = 0; + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); +#ifdef _DEBUG_AMBA + printf("(%d) [http_connection_handler] Program binary path is: %s\n", sock,buf); +#endif //_DEBUG_AMBA + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char configPATH[1024]; + char eventsPATH[1024]; + + strcpy(configPATH, exePath); + strcpy(eventsPATH, exePath); + + strcat(configPATH, "config.json"); + strcat(eventsPATH, "events.json"); + + int header_len = 0; + //int doubleCRLF = 0; + + //printf("\n[nweb.c]-----------------------------kkkk:5\n"); + //int tracking_idx = g_tracking_idx; + //memset(g_TrackingIDAndChannel[tracking_idx], 0x00, sizeof(g_TrackingIDAndChannel[tracking_idx])); + //pthread_mutex_lock(&mutex_t); + + /* + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].sock == sock) + { + socketRecords[i].debug_type = 9; + } + }*/ + //printf("\n---------http connection handler ----------- 2\n"); + int nbytes_sec = 0; + // recv( pCli, pCli->reqFd, pCli->readBuf+pCli->header_len, 1, MSG_WAITALL ); + //while ((nbytes = recv(sock, buffer, sizeof(buffer), 0)) > 0) + //char temp_buffer[8196] = { 0 }; + + int isTcpTunnel = FALSE; + + //while ((nbytes = recv(sock, buffer, sizeof(buffer), 0)) > 0) + while (bHttpServerMainStart && ((nbytes = recv(sock, buffer + header_len, 1, 0)) > 0)) + { + //printf("\n---------http connection handler ----------- 3\n"); + /* + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].sock == sock) + { + socketRecords[i].debug_type = 5; + } + }*/ + + header_len += nbytes; + //printf("read size: %d \n", header_len); + +#if 1 + if (strstr(buffer, "User-Agent: Mozilla/5.0 ") != NULL)//User-AgentL˪AOsA{bsA|[W@ﰰˡC + { + if (strstr(buffer , "Connection: keep-alive") != NULL || + strstr(buffer , "Connection: close") != NULL || + strstr(buffer , "Connection: Keep-Alive") != NULL || + strstr(buffer , "Connection: Closed") != NULL)//@socket|hˬdOOHTTP ConnectionApGOh令@AåBUC + { + nbytes_sec = recv(sock, buffer + header_len, (sizeof(buffer) - header_len), 0); + //printf("\n-----------strlen(buffer):%d\n", strlen(buffer)); + //printf("\n--------------header_len:%d\n", header_len); + //printf("\n---------[#1]buffer:%s\n", buffer); + + //memset(temp_buffer, 0x00, header_len+ nbytes_sec); + //memcpy(temp_buffer, buffer, header_len+ nbytes_sec); + } + else if ((strstr(buffer, "Connection: Upgrade") != NULL || strstr(buffer, "Upgrade: websocket") != NULL ) + && strstr(buffer, "\r\n\r\n") != NULL) //Dsocket|hˬd\r\n\r\nA~UC + { + //printf("\n---------[websocket#2]buffer:%s\n", buffer); + //doubleCRLF = 1; + + //memset(temp_buffer, 0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + } + else { + //memset(temp_buffer,0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + continue; + } + } + else if (strstr(buffer, "setconfigfile") != NULL || + strstr(buffer, "seteventsfile") != NULL || + strstr(buffer, "seteventscustom2") != NULL || + strstr(buffer, "settoffile") != NULL || + strstr(buffer, "setemailsfile") != NULL) //[NVR]setconfigfile or seteventsfilehC + { + nbytes_sec = recv(sock, buffer + header_len, (sizeof(buffer)- header_len), 0); + //printf("\n---------[NVR#1]buffer:%s\n", buffer); + //memset(temp_buffer, 0x00, header_len + nbytes_sec); + //memcpy(temp_buffer, buffer, header_len + nbytes_sec); + } + else if (strstr(buffer, "\r\n\r\n") != NULL) //pGOWzӡAh[NVR]"\r\n\r\n"P_C + { + //printf("\n---------[NVR#2]buffer:%s\n", buffer); + //doubleCRLF = 1; + //memset(temp_buffer, 0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + } + else { + //memset(temp_buffer, 0x00, header_len); + //memcpy(temp_buffer, buffer, header_len); + continue; + } +#endif + + //printf("\n---------http connection handler ----------- 4\n"); +#if 0 + if (strstr(buffer, "\r\n\r\n")) + { + //doubleCRLF = 1; + } + else + continue; +#endif + + //printf("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK read finish \n\n\n\n"); + + nbytes = header_len + nbytes_sec; + + //printf("\n[nweb.c]-----------------------------kkkk:4\n"); + if (nTotalBytes + nbytes > MAX_IMG_BUFF_SIZE - 4) + { + printf("[ERROR] receive buffer is full %d\n", sock); + ///Steven MARK TEMP + + //fflush(stdout); + //closesocket(sock); + break; + } + + //printf("\n-------------buffer:%s\n", buffer); + + //receive client data successfully + memcpy(recvbuffer + nTotalBytes, buffer, nbytes); + //printf("\n---------http connection handler ----------- 5\n"); + + if (strstr(buffer, "airelay") != NULL) + { + isTcpTunnel = TRUE; + } + else + { + isTcpTunnel = FALSE; + } + + //printf("\n----recvbuffer:%s\n", recvbuffer); + + nTotalBytes += nbytes; + //DumpHex(recvbuffer, 300); + //memset(recvbuffer + nTotalBytes, 0x00, MAX_IMG_BUFF_SIZE - nTotalBytes); + //printf("\n[nweb.c]-----------------------------kkkk:3\n"); + if (nbytes == 0) + { + printf("Socket hung up %d\n", sock); + + //fflush(stdout); + //closesocket(sock); + break; + } + else if (nbytes == -1) + { + printf("HTTP recv failed %d\n", sock); + + //closesocket(sock); + break; + } + //printf("\n[nweb.c]-----------------------------kkkk:2\n"); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + //20201028 sophia add, host not from ipcam & not authorized +#if 0 + if (enable_base64 == 1) { +#endif +#if 0 + if(is_authorized_run_preload_http_server == 0 && + strstr(recvbuffer, "/setup.htm") && + is_referer_from_setup == 0){ + is_referer_from_setup = 1; + } +#endif + //printf("\n---------http connection handler ----------- 6 --- %d\n", is_authorized_run_preload_http_server); + if (is_authorized_run_preload_http_server == 0) { + //printf("\n---------http connection handler ----------- 7\n"); +#if 0 + if (is_referer_from_setup == 0) { + + char tmp_open_file[512]; + memset(tmp_open_file, 0, sizeof(tmp_open_file)); + + { + sprintf(tmp_open_file, "./Aida/warning2.html"); + } + + + char sendBuffer[BUFSIZE * 8] = { 0 }; + + /*//#ifdef _DEBUG_AMBA + printf("\n(%d) [web process] http get tmp_open_file:%s\n", cli_socket,tmp_open_file); + //#endif //_DEBUG_AMBA*/ + + int file_fd; + if ((file_fd = open(tmp_open_file, O_RDONLY)) == -1) + { + printf("Failed to open file : %s\n", tmp_open_file);//ɮצSQŪ + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19-2\n"); + } + else { + /* work out the file type and check if we support it */ + int iFileLength = 0; + char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; + iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); + close(file_fd); + + { + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #19\n"); + } + + int iSentLeft = 0; + int iSentLength = 0; + int iRetryCount = 5; + + + + + + iSentLeft = iFileLength; + + while (iSentLeft >= 1) { + iSentLength = send(sock, sendBuffer_superlarge, iSentLeft, 0); + iSentLeft = iSentLeft - iSentLength; + iRetryCount--; + sendBuffer_superlarge + iSentLength; + + if (iSentLeft >= 1) { + //printf("\n[web process]iSentLeft: %d\n", iSentLeft); + } + + if (iRetryCount <= 0) + break; + } + + + } + closesocket(sock); + + break; + } +#endif + if (strncmp(recvbuffer, "GET /getalarmmotion?nvr_auth=", 29) != 0 && strncmp(recvbuffer, "GET /server HTTP/1.1", 20) != 0 && strncmp(recvbuffer, "GET /getdebugplate HTTP/1.1", 27) != 0 && strncmp(recvbuffer, "GET /getfree HTTP/1.1", 21) != 0 && strstr(recvbuffer, "GET /get_search_info?select=log&limit=1&credential=") == NULL) { + + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + if (!is_connection_authorized(recvbuffer, &sock, isTcpTunnel)) { + //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); + closesocket(sock); + break; + } + else { + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + } + } + else if (strncmp(recvbuffer, "GET /getalarmmotion?nvr_auth=", 29) == 0){ + + char *is_nvr_auth = NULL; + is_nvr_auth = strstr(recvbuffer, "nvr_auth="); + if (is_nvr_auth != NULL && strlen(is_nvr_auth) > 9){ + char auth_basic[256] = { 0 }; + strcpy(auth_basic, "Authorization: Basic "); + memcpy(auth_basic + 21, is_nvr_auth + 9, strlen(is_nvr_auth)); + //printf("\n-------------------auth_basic:%s\n", auth_basic); + + if (!is_connection_authorized(auth_basic, &sock, isTcpTunnel)) { + //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); + closesocket(sock); + break; + } + else { + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + } + } + else { + closesocket(sock); + break; + } + } + else if (strstr(recvbuffer, "GET /get_search_info?select=log&limit=1&credential=") != NULL) { + + char *is_credential_auth = NULL; + is_credential_auth = strstr(recvbuffer, "credential="); + //printf("\n-------------------is_credential_auth:%s\n", is_credential_auth); + if (is_credential_auth != NULL && strlen(is_credential_auth) > 11) { + char auth_basic[256] = { 0 }; + strcpy(auth_basic, "Authorization: Basic "); + memcpy(auth_basic + 21, is_credential_auth + 11, strlen(is_credential_auth)); + //printf("\n-------------------auth_basic:%s\n", auth_basic); + + int iSockIdx = -1; + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].sock == sock) + { + iSockIdx = i; + socketRecords[iSockIdx].isCredentialRequest = 1; + break; + } + } + + if (!is_connection_authorized(auth_basic, &sock, isTcpTunnel)) { + //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); + closesocket(sock); + break; + } + else { + //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); + } + } + else { + closesocket(sock); + break; + } + } + } +#if 0 + } +#endif +#endif + //printf("\n-------recvbuffer #1:%s\n", recvbuffer); + //printf("\n[nweb.c]-----------------------------kkkk:1\n"); + //printf("\n---------http connection handler ----------- 7\n"); + if (strstr(recvbuffer, "Upgrade: websocket") || strstr(recvbuffer, "Connection: Upgrade") || strstr(recvbuffer, "Upgrade: WebSocket")) + { + //printf("\n-------recvbuffer #1:%s\n", recvbuffer); + + //printf("\n[nweb.c][%d]--------sharkhand process---start:1\n", sock); + + websocket_connected = 0; + sharkhand_s_connection_upgrade(&sock,buffer,&websocket_connected); + + //printf("\n[nweb.c][%d]--------sharkhand process---end:1\n", sock); + + int sock_info_idx = -1; + //printf("\n[nweb.c][%d]--------web process---start:1\n", sock); + + web_process(&sock, recvbuffer, nTotalBytes, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 1\n"); + //printf("\n[nweb.c][%d]--------web process---end:1, getalarmmotion = %d\n", sock, isGetAlarmMotion); + break; + } + else if (memcmp(recvbuffer, "GET ", strlen("GET ")) == 0) + { + //printf("\n-------recvbuffer #2:%s\n", recvbuffer); + +//#ifdef _DEBUG_AMBA + //printf("\n(%d) [http_connection_handler] recv GET http request(%d):%sCHECK-END\n", sock, sock, recvbuffer); +//#endif + + int sock_info_idx = -1; + if (memcmp(recvbuffer + nTotalBytes - 4, "\r\n\r\n", 4) == 0) + { + t1 = clock(); + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + sock_info_idx = i; + break; + } + } + } + //printf("\n[nweb.c]--------web process---start:2\n"); + web_process(&sock, recvbuffer, nTotalBytes, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:2\n"); + //printf("\n------web_process end 2\n"); + nTotalBytes = 0; + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("(%d) web end time %d:%f\n",sock, sock, diff); + } + +#ifdef _DEBUG_AMBA + printf("\n(%d) [http_connection_handler] recv GET http request END===========\n\n", sock); +#endif + break; + } +#if 0 + else if (memcmp(recvbuffer, "POST /sendjpeg", strlen("POST /sendjpeg")) == 0) + { + //printf("recv POST http request(%d):%.30s\n", sock, recvbuffer); + + for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) + { + if (memcmp(recvbuffer + i - strlen(MULTIPART_CONTENT), MULTIPART_CONTENT, strlen(MULTIPART_CONTENT)) == 0) + bIsMultipart = 1; + + if ((memcmp(recvbuffer + i - 2, "\xFF\xD9", 2) == 0 && !bIsMultipart && (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0) ) || + (memcmp(recvbuffer + i - 4, "--\r\n", 4) == 0 && memcmp(recvbuffer + i - 5, "-", 1) != 0 && bIsMultipart) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); + //printf("\n[nweb.c]--------web process---start:3\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh,http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:3\n"); + //printf("\n------web_process end 3\n"); + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i) ); + nTotalBytes = nTotalBytes - i; + bIsMultipart = 0; + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); +#ifdef _WIN32 + usSleep(http_sleep_interval*1000); +#else + usSleep(1000); +#endif + break; + } + } + closesocket(sock); + break; + } +#endif +#if 0 + else if (memcmp(recvbuffer, "POST /sendyuv", strlen("POST /sendyuv")) == 0) + { + for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) + { + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + + if ((memcmp(recvbuffer + i - strlen(MSG_END_PATTERN), MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("recv done time: %d:%f\n", sock, diff); + + int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); + //printf("\n[nweb.c]--------web process---start:4\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:4\n"); + //printf("\n------web_process end 4\n"); + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + nTotalBytes = nTotalBytes - i; + bIsMultipart = 0; + nContentLength = 0; + + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); +#ifdef _WIN32 + usSleep(http_sleep_interval*1000); +#else + usSleep(1000); +#endif + break; + } + } + closesocket(sock); + break; + } +#endif +#if 0 + else if (memcmp(recvbuffer, "POST /user_command", strlen("POST /user_command")) == 0) + { + for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) + { + if ((memcmp(recvbuffer + i - strlen(MSG_END_PATTERN), MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); + //printf("\n[nweb.c]--------web process---start:5\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n[nweb.c]--------web process---end:5\n"); + //printf("\n------web_process end 5\n"); + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + nTotalBytes = nTotalBytes - i; + bIsMultipart = 0; + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); +#ifdef _WIN32 + usSleep(http_sleep_interval*1000); +#else + usSleep(1000); +#endif + break; + } + } + + closesocket(sock); + break; + } +#endif + else if (memcmp(recvbuffer, "POST /setconfigfile", strlen("POST /setconfigfile")) == 0 || + memcmp(recvbuffer, "POST /airelay/setconfigfile", strlen("POST /airelay/setconfigfile")) == 0 || + memcmp(recvbuffer, "POST /seteventsfile", strlen("POST /seteventsfile")) == 0 || + memcmp(recvbuffer, "POST /airelay/seteventsfile", strlen("POST /airelay/seteventsfile")) == 0 || + memcmp(recvbuffer, "POST /seteventscustom2", strlen("POST /seteventscustom2")) == 0 || + memcmp(recvbuffer, "POST /settoffile", strlen("POST /settoffile")) == 0 || + memcmp(recvbuffer, "POST /setemailsfile", strlen("POST /setemailsfile")) == 0 +#if 0 + || memcmp(recvbuffer, "POST /setjvcconfigfile", strlen("POST /setjvcconfigfile")) == 0 +#endif + ) + { + //printf("\n---------recvbuffer:%s\n", recvbuffer); + + char *cp = NULL; + char *cp2 = NULL; + char *cp3 = NULL; + char *tempPtr = NULL; + char boundary[BUFSIZE * 60] = { 0 }; + int strlen_boundary = 0; + + if ((cp = strstr(recvbuffer, "boundary=")) != NULL) + { + + tempPtr = cp + 9; + //printf("\n---------tempPtr:%s\n", tempPtr); + + cp = strstr(tempPtr, "\r\n\r\n"); + + if (cp != NULL) + { + //printf("\n---------cp:%s\n", cp); + cp2 = strstr(cp, "{"); + + if (cp2 != NULL) + { + //printf("\n---------cp2:%s\n", cp2); + //cp3 = strstr(cp2, "----------------"); + cp3 = strstr(cp2, "--"); + strlen_boundary = cp3 - cp2; + while (strlen_boundary >= 1 && cp2[strlen_boundary - 1] != '}') + { + strlen_boundary = strlen_boundary - 1; + } + + if(strlen_boundary >= 1) + strncpy(boundary, cp2, strlen_boundary); + } + } + } + //printf("\n---------boundary:%s\n", boundary); + + int sock_info_idx = -1; + + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + //printf("\n--------recvbuffer + i:%s\n", recvbuffer + i); + if (nTotalBytes < nContentLength) + break; + } + + if (strlen_boundary == 0) { + if (memcmp(recvbuffer + i - strlen("\r\n\r\n"), "\r\n\r\n", strlen("\r\n\r\n")) == 0) + { + //printf("\n-----bIsMultipart:%d\n", bIsMultipart); + //printf("\n-----nContentLength:%d\n", nContentLength); + + //printf("\n----6-recvbuffer:%s\n", recvbuffer); + //printf("\n-----recvbuffer+i:%s\n", recvbuffer+i); + + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 6\n"); + //bIsMultipart = 0; + nContentLength = 0; + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + + break; + } + } + else { + + if (memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0) { + + nContentLength = strlen_boundary; + recvbuffer[i] = '\0'; + //printf("\n----7-recvbuffer:%s\n", recvbuffer); + //printf("\n-----recvbuffer+i - strlen(boundary):%s\n", recvbuffer + i - strlen(boundary)); + + web_process(&sock, recvbuffer, i - strlen(boundary), contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 7\n"); + //bIsMultipart = 0; + nContentLength = 0; + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + + break; + } + } + } + + //printf("\n------web_process end 8\n"); + + break; + } +#ifdef GY_OS_AMBA + else if (memcmp(recvbuffer, "POST /sendpycode", strlen("POST /sendpycode")) == 0 ) + { + //printf("\n---------recvbuffer:%s\n", recvbuffer); + //int sock_info_idx = -1; + int strlen_boundary = 0; + char SendPython[BUFSIZE * 8] = {0}; + //char beforeSendBuffer_xtra[BUFSIZE * 60] = { 0 }; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + + for (int i = 0; i <= nTotalBytes; i++) + { + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + if (strlen_boundary == 0) { + if (memcmp(recvbuffer + i - strlen("\r\n\r\n"), "\r\n\r\n", strlen("\r\n\r\n")) == 0) + { + char* file_Content = recvbuffer + i; + + printf("file content = %s \n", file_Content); + //printf("\nfile!!!\n"); + //runPython(file_Content, sock); + // strcpy(sendBuffer_xtra, "Send python file OK!!"); + printf("##################### file_Content : %s /n", file_Content); + runPython(file_Content); + strcpy(SendPython, "Web Buffer Run OK !!"); + } + else + { + strcpy(SendPython, "Send python file fail !!"); + } + } + + } + } + else { + strcpy(SendPython,"Please check the Enable python checkbox configuration in the SETTING TAB"); + } + + + char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendPython), SendPython); + if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + { + printf("\nsend error #32\n"); + } + memset(SendPython, 0, sizeof(SendPython)); + closesocket(sock); + } +#endif + else if (memcmp(recvbuffer, "POST /keyInfo", strlen("POST /keyInfo")) == 0) + { + g_write_config_file_dirty_flag = 0; + //printf("POST KEY Info \n"); + //printf("recv= %s \n", recvbuffer); + + char* pContent = strstr(recvbuffer, "--boundary START"); + + //printf("\n---get post content=[%s]\n", pContent + 16); + + update_config(pContent + 16); +#ifdef GY_OS_NOVA + g_check_run_nova_detection = 0; + system("killall -15 nova_driver"); + usSleep(1000000); +#endif + //printf("\n--------------------reload 7\n"); + //reload_dataset_from_jsonfile(); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\n\r\n"); + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #39\n"); + closesocket(sock); + + printf("\n-----------------------keyInfo: exit-----------------------\n"); +#if 1 + stop_test_nn_cavalry("keyInfo exit"); + //stop_server(); +#endif + //exit(EXIT_SUCCESS); + } + else if (memcmp(recvbuffer, "POST /getAidaInfo", strlen("POST /getAidaInfo")) == 0) + { + // printf("POST AidaInfo \n"); + + sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\n\r\n"); + if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) + printf("\nsend error #40\n"); + //write(fd,buffer,strlen(buffer)); + + //int ret = 0; + /* ŪɮפeXȤs */ + + //post events setting + //char filename[] = "config.json"; + char *filename = configPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else { + printf("read config.json.\n"); + + //size_t nfileSize = ReadFileSize(filename); + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* config_root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (config_root) { + //printf("config.json parse OK.\n"); + //cJSON* about_box = cJSON_GetObjectItem(config_root, "about_box"); + //cJSON *nic_name = cJSON_GetObjectItem(about_box, "NIC name"); + //cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); + + ///read config.json + + cJSON *jstr1, *jstr2, *jnum1, *root; + char* JsonString = NULL; + root = cJSON_CreateObject(); + + jstr1 = cJSON_CreateString("json test1"); + jstr2 = cJSON_CreateString("json test2"); + jnum1 = cJSON_CreateNumber(4456); + + cJSON_AddItemToObject(root, "jstr1", jstr1); + cJSON_AddItemToObject(root, "jstr2", jstr2); + cJSON_AddItemToObject(root, "jnum1", jnum1); + //cJSON_AddItemToObject(root, "unlock_key", unlock_key->valuestring); + + JsonString = cJSON_PrintUnformatted(root); + + send(sock, JsonString, sizeof(JsonString), 0); + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + + if (config_root) { + cJSON_Delete(config_root); + config_root = NULL; + } + //write(cli_socket, sendBuffer, ret); + } + else + printf("config.json parse FAIL.\n"); + } + } + + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_lpr_map_list", strlen("POST /import_lpr_map_list")) == 0) + ||(memcmp(recvbuffer, "POST /import_lpr_list", strlen("POST /import_lpr_list")) == 0)) + { + //printf("\n------------recvbuffer:%s\n", recvbuffer); + + char *cp = NULL; + char *tempPtr = NULL; + char boundary[255] = {0}; + if ((cp = strstr( recvbuffer, "boundary=" )) != NULL) + { + int strlen =0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + char endStr[] = "--"; + strncpy(boundary, tempPtr, strlen); + strcat(boundary,endStr); + } + } + } + + if (strlen(boundary) >= 1) { + //printf("\n--------import lpr list ---- 1 --- nTotalBytes %d\n", nTotalBytes); + int sock_info_idx = -1; + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + //printf("\n--------import lpr list ---- 2 ------ %d\n", i); + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + //printf("\n--------import lpr list ---- 3\n"); + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + //printf("\n--------import lpr list ---- 4\n"); + if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) + ) + { + //DumpHex(recvbuffer, 320); + //printf("\n"); + //DumpHex(recvbuffer + i, 320); + //DumpHex(recvbuffer + i - 2 , 16); + //caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("recv done time: %d:%f\n", sock, diff); + //printf("\n[nweb.c]--------web process---start:6\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 9\n"); + //printf("\n[nweb.c]--------web process---end:6\n"); + //memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + //memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + //nTotalBytes = nTotalBytes - i; + //printf("\n[nweb.c]--------web process---end:6-------1\n"); + //memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); + //bIsMultipart = 0; + nContentLength = 0; + //printf("\n[nweb.c]--------web process---end:6-------2\n"); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + //printf("\n[nweb.c]--------web process---end:6-------2\n"); + //printf("web end time %d:%f\n", sock, diff); + t1 = clock(); + // printf("\n[nweb.c]--------web process---end:6-------4\n"); + + usSleep(1000); + break; + } + //printf("\n--------import lpr list ---- 5\n"); + } + } + /* + char* cp = NULL, tempPtr = NULL; + char boundary[255]; + char contLen[20]; + int datalen = 0; + printf("POST import_lpr_map_list \n"); + printf("recv= %s \n", recvbuffer); + if (cp = strstr( recvbuffer, "Content-Length:" )) + { + datalen = atoi((char *)(cp+16)); + printf("length:%d\n",datalen); + } + if ((cp = strstr( recvbuffer, "boundary=" ))) + { + tempPtr = &cp[9]; + //strncpy(boundary, tempPtr, sizeof(boundary)-1); + //printf("boundary:%s\n",boundary); + if (datalen > 0) + do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) + } + */ + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_radarbg", strlen("POST /import_radarbg")) == 0)) // a113n 10/12 + { + char *cp = NULL; + char *tempPtr = NULL; + char boundary[255] = {0}; + if ((cp = strstr(recvbuffer, "boundary=")) != NULL) + { + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + char endStr[] = "--"; + strncpy(boundary, tempPtr, strlen); + strcat(boundary, endStr); + } + } + } + int sock_info_idx = -1; + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + + if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/)) + { + // DumpHex(recvbuffer, 320); + // printf("\n"); + // DumpHex(recvbuffer + i, 320); + // DumpHex(recvbuffer + i - 2 , 16); + // caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("recv done time: %d:%f\n", sock, diff); + // printf("\n[nweb.c]--------web process---start:6\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 10\n"); + // printf("\n[nweb.c]--------web process---end:6\n"); + // memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + // memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + // nTotalBytes = nTotalBytes - i; + // printf("\n[nweb.c]--------web process---end:6-------1\n"); + // memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); + //bIsMultipart = 0; + nContentLength = 0; + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + // printf("web end time %d:%f\n", sock, diff); + t1 = clock(); + // printf("\n[nweb.c]--------web process---end:6-------4\n"); + + usSleep(1000); + break; + } + } + /* + char* cp = NULL, tempPtr = NULL; + char boundary[255]; + char contLen[20]; + int datalen = 0; + printf("POST import_lpr_map_list \n"); + printf("recv= %s \n", recvbuffer); + if (cp = strstr( recvbuffer, "Content-Length:" )) + { + datalen = atoi((char *)(cp+16)); + printf("length:%d\n",datalen); + } + if ((cp = strstr( recvbuffer, "boundary=" ))) + { + tempPtr = &cp[9]; + //strncpy(boundary, tempPtr, sizeof(boundary)-1); + //printf("boundary:%s\n",boundary); + if (datalen > 0) + do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) + } + */ + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_speedbg", strlen("POST /import_speedbg")) == 0)) // 2022-11-03 Ken + { + char *cp = NULL; + char *tempPtr = NULL; + char boundary[255] = {0}; + if ((cp = strstr(recvbuffer, "boundary=")) != NULL) + { + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + char endStr[] = "--"; + strncpy(boundary, tempPtr, strlen); + strcat(boundary, endStr); + } + } + } + int sock_info_idx = -1; + for (int i = 0; i <= nTotalBytes; i++) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 1) { + if (socketRecords[j].sock == sock) + { + sock_info_idx = j; + break; + } + } + } + + if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) + nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); + + if (nContentLength != 0) + { + if (nTotalBytes < nContentLength) + break; + } + + if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/)) + { + // DumpHex(recvbuffer, 320); + // printf("\n"); + // DumpHex(recvbuffer + i, 320); + // DumpHex(recvbuffer + i - 2 , 16); + // caculate fps of each sockets + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("recv done time: %d:%f\n", sock, diff); + // printf("\n[nweb.c]--------web process---start:6\n"); + web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); + //printf("\n------web_process end 11\n"); + // printf("\n[nweb.c]--------web process---end:6\n"); + // memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + // memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + // nTotalBytes = nTotalBytes - i; + // printf("\n[nweb.c]--------web process---end:6-------1\n"); + // memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); + //bIsMultipart = 0; + nContentLength = 0; + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + t2 = clock(); + diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); + // printf("\n[nweb.c]--------web process---end:6-------2\n"); + // printf("web end time %d:%f\n", sock, diff); + t1 = clock(); + // printf("\n[nweb.c]--------web process---end:6-------4\n"); + + usSleep(1000); + break; + } + } + /* + char* cp = NULL, tempPtr = NULL; + char boundary[255]; + char contLen[20]; + int datalen = 0; + printf("POST import_lpr_map_list \n"); + printf("recv= %s \n", recvbuffer); + if (cp = strstr( recvbuffer, "Content-Length:" )) + { + datalen = atoi((char *)(cp+16)); + printf("length:%d\n",datalen); + } + if ((cp = strstr( recvbuffer, "boundary=" ))) + { + tempPtr = &cp[9]; + //strncpy(boundary, tempPtr, sizeof(boundary)-1); + //printf("boundary:%s\n",boundary); + if (datalen > 0) + do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) + } + */ + closesocket(sock); + break; + } +#if 0 + else + { + char msg[MAX_MSG_LEN] = { 0 }; + //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; + sprintf(msg, "The URL is not correct(%d)\n", sock /*,recvbuffer*/); + printf("%s\n", msg); + + /*printf("\n"); + strcpy(beforeSendBuffer, msg); + strcat(beforeSendBuffer, MSG_END_PATTERN); + + char sendBuffer[BUFSIZE] = { 0 }; + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(sock, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend error\n");*/ + + for (int i = 0; i < nTotalBytes; i++) + { + if (memcmp(recvbuffer + i, "POST /sendjpeg", strlen("POST /sendjpeg")) == 0) + { + //DumpHex(recvbuffer + i, 256); + sprintf(msg, "The URL is not correct(%d)\n", sock /*,recvbuffer*/); + printf("%s\n", msg); + + memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); + memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); + nTotalBytes = nTotalBytes - i; + break; + } + } + + /*if (nTotalBytes >= MAX_IMG_BUFF_SIZE - 8*BUFSIZE) + { + memset(recvbuffer, 0x00, sizeof(recvbuffer)); + nTotalBytes = 0; + break; + }*/ + closesocket(sock); + break; + } +#endif +#if 0 + else if ((memcmp(recvbuffer, "POST /upload_face_img", strlen("POST /upload_face_img")) == 0)) // 2023-12-12 Steven + { + //printf("\n\n\n--------------------------------UPLOAD FACE IMG \n"); + + //int image_buff_size = 0; + + //char *image_buff = NULL; + //image_buff = malloc(MAX_IMG_SIZE_HD); + //memset(image_buff, 0, MAX_IMG_SIZE_HD); + + //char *decrypt_buff = NULL; + //decrypt_buff = malloc(MAX_IMG_SIZE_HD); + //memset(decrypt_buff, 0, MAX_IMG_SIZE_HD); + + char *cp = NULL; + char *dataEnd = NULL; + char *tempPtr = NULL; + int base64_len = 0; + + //printf("--------------------------------UPLOAD FACE IMG 2\n"); + + //printf("\n\n\n%s\n", recvbuffer); + + if ((cp = strstr(recvbuffer, "base64,")) != NULL) + { + //printf("\n\n\n ============================= JPEG SIZE = %d \n\n", strlen(cp)); + tempPtr = cp + 7; + //printf("find data start: 0x%x\n", tempPtr); + } + + //printf("--------------------------------UPLOAD FACE IMG 3\n"); + + if ((dataEnd = strstr(tempPtr, "------WebKit")) != NULL) + { + //printf("find data end: 0x%x\n", dataEnd); + } + + //printf("--------------------------------UPLOAD FACE IMG 4\n"); + + if (tempPtr != NULL && dataEnd != NULL) + { + base64_len = (dataEnd - tempPtr) - 2; + //printf("\n\ndata len = %d \n", base64_len); + } + + //printf("--------------------------------UPLOAD FACE IMG 5\n"); +#if 1 + if (base64_len > 0) + { + memcpy(g_image_buff, tempPtr, base64_len); + + size_t base64_decode_length = 0; + + //printf("55555555555555555555555555 \n\n\n %d \n\n\n", base64_len); + + //printf(" 666666666666666666666666666666666666 \n\n\n %s \n\n\n", image_buff); + + int encode_len = strlen(g_image_buff) - (strlen(g_image_buff) % 4); + + //printf("55555555555555555555555555 enc len\n\n\n %d \n\n\n", encode_len); + + base64_decode(g_image_buff, encode_len, &base64_decode_length, g_decrypt_buff); + + //printf("666666666666666666666666666666 \n\n\n %d \n\n\n", base64_decode_length); + printf("--------------------------------UPLOAD FACE IMG 6\n"); + //writeImageFromBuffer("/emmc/plugin/Aida_data/tmp/crop.jpg", g_decrypt_buff, base64_decode_length); +#if 1 + // deal with face data + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + if (get_ff_face_name_max_num() > g_face_frame_uid) { + g_face_frame_uid = get_ff_face_name_max_num() + 1; + printf("g_face_frame_uid = %d\n", g_face_frame_uid); + } + else { + printf("get_ff_face_name_max_num < g_face_frame_uid, get_ff_face_name_max_num = %d\n", get_ff_face_name_max_num()); + } + + if (g_face_frame_uid >= 0) { + // deal with register + char visitor_tmp[14] = "Visitor"; + char face_uid_tmp[10]; + sprintf(face_uid_tmp, "%05d", g_face_frame_uid); + strcat(visitor_tmp, face_uid_tmp); + + char base64_image_filename[60] = { 0 }; + sprintf(base64_image_filename, "%d_%d_%d_%d_%d_%d_%ld_%05d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time, g_face_frame_uid); + + char base64_image_filename_path[128] = { 0 }; + sprintf(base64_image_filename_path, "/tmp/face/%s.jpg", base64_image_filename); + //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_image_filename_path); + writeImageFromBuffer(base64_image_filename_path, g_decrypt_buff, base64_decode_length); + + char base64_image_filename_path_2[128] = { 0 }; + sprintf(base64_image_filename_path_2, "/emmc/plugin/Aida_data/storage/vip/%s.jpg", base64_image_filename); + //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_image_filename_path_2); + writeImageFromBuffer(base64_image_filename_path_2, g_decrypt_buff, base64_decode_length); + + char base64_tmplate_filename_path[128] = { 0 }; + sprintf(base64_tmplate_filename_path, "/emmc/plugin/Aida_data/storage/template/%s.tpl", face_uid_tmp); + //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_tmplate_filename_path); + writeImageFromBuffer(base64_tmplate_filename_path, g_decrypt_buff, base64_decode_length); + test_sfe_add_face_group(face_uid_tmp, base64_tmplate_filename_path); + + //if (viewChannelData[0].enable_add_face_frequent_list) + { + sqlite_facegroup_add_face_list(face_uid_tmp, visitor_tmp, "", "9964094f-df62-41a0-a666-134b3dbc9123", "100.0", base64_image_filename, "9964094f-df62-41a0-a666-134b3dbc9123", "", "", "vip", "00:00", "23:59", "2200-12-30_23:59"); + } + + //face_get_watchlist_members(); + + g_face_frame_uid++; + } +#endif + } +#endif + //free(image_buff); + //free(decrypt_buff); + + memset(g_image_buff, 0, MAX_IMG_SIZE_HD); + memset(g_decrypt_buff, 0, MAX_IMG_SIZE_HD); + + + char beforeSendBuffer[64]; + strcpy(beforeSendBuffer, "ok"); + + int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); + if (send(sock, sendBuffer, sendBufferSize, MSG_MORE) == -1) + printf("\nsend\n"); + + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /import_face_list", strlen("POST /import_face_list")) == 0)) // 2023-12-19 Joy + { + printf("\n import_face_list \n"); + printf("recvbuffer: %s\n",recvbuffer); + + closesocket(sock); + break; + } + else if ((memcmp(recvbuffer, "POST /upload_face_licensekey", strlen("POST /upload_face_licensekey")) == 0)) // 2023-12-19 Joy + { + char *dataStart = strchr(recvbuffer, '{'); + if (dataStart != NULL) + { + char *dataEnd = strrchr(recvbuffer, '}'); + if (dataEnd != NULL) + { + size_t dataLength = dataEnd - dataStart + 1; + char jsonData[dataLength + 1]; + strncpy(jsonData, dataStart, dataLength); + jsonData[dataLength] = '\0'; + + char *customerStart = strstr(jsonData, "\"customer\":"); + if (customerStart != NULL) + { + char *customerEnd = strchr(customerStart, ','); + if (customerEnd != NULL) + { + char customerValue[100]; + int customerLength = customerEnd - (customerStart + 12); + strncpy(customerValue, customerStart + 12, customerLength); + customerValue[customerLength] = '\0'; + + if (strcmp(customerValue, "\"MERITLILIN_REST integration\"") == 0) + { + char *saveFilePath = "/emmc/plugin/Aida_data/sfe/iengine.lic"; + FILE *file = fopen(saveFilePath, "w"); + if (file != NULL) + { + fputs(jsonData, file); + fclose(file); + + char successResponse[] = "Please press the 'Apply' button to restart the device."; + int successResponseSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(successResponse), successResponse); + if (send(sock, sendBuffer, successResponseSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + else + { + char fileWriteError[] = "Failed to save the file."; + int fileWriteErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(fileWriteError), fileWriteError); + if (send(sock, sendBuffer, fileWriteErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + else + { + char invalidCustomerError[] = "Invalid customer value."; + int invalidCustomerErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(invalidCustomerError), invalidCustomerError); + if (send(sock, sendBuffer, invalidCustomerErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + } + else + { + char customerNotFoundError[] = "Customer not found in the request."; + int customerNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(customerNotFoundError), customerNotFoundError); + if (send(sock, sendBuffer, customerNotFoundErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + else + { + char dataEndNotFoundError[] = "End of data not found in the request."; + int dataEndNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(dataEndNotFoundError), dataEndNotFoundError); + if (send(sock, sendBuffer, dataEndNotFoundErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + } + else + { + char jsonDataNotFoundError[] = "JSON data not found in the request."; + int jsonDataNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(jsonDataNotFoundError), jsonDataNotFoundError); + if (send(sock, sendBuffer, jsonDataNotFoundErrorSize, MSG_MORE) == -1) + printf("\nsend\n"); + } + + closesocket(sock); + + memset(g_image_buff, 0, MAX_IMG_SIZE_HD); + memset(g_decrypt_buff, 0, MAX_IMG_SIZE_HD); + memset(buffer, 0x00, sizeof(buffer)); + + printf("\n-----------------------upload face licensekey: exit-----------------------\n"); +#if 1 + stop_test_nn_cavalry("upload face licensekey exit"); + //stop_server(); +#endif + //exit(EXIT_SUCCESS); + } +#endif + //usSleep(1000); + memset(buffer, 0x00, sizeof(buffer)); + } + + //printf("\n(%d) [http connection fun] isGetAlarmMotion: %d ", sock, isGetAlarmMotion); + //printf("\nweb process-----double free---2\n"); + if (isGetAlarmMotion) + { + for (int j = 0; j < MAX_CLIENT_SOCKET; j++) + { + if (socketRecords[j].used == 0 && socketRecords[j].sock == -1) + { + socketRecords[j].sock = sock; + + //memset(&(socketRecords[j].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[j].thread_id = 0; + socketRecords[j].channel_id = -1; + //socketRecords[j].last_recv_time = time(0); + //socketRecords[j].recent_sec_data[0].recv_time = socketRecords[j].last_recv_time; + socketRecords[j].isGetAlarmMotion = TRUE; + //socketRecords[j].isFirstAlarmMotion = FALSE; + if (websocket_connected) + { + //printf("Set sock:%d isWebSocketConnect: TRUE \n",sock); + socketRecords[j].isWebSocketConnect = TRUE; + } + else + { + //printf("Set sock:%d isWebSocketConnect: FALSE \n", sock); + socketRecords[j].isWebSocketConnect = FALSE; + } + socketRecords[j].isUdpSocket = FALSE; + socketRecords[j].isNvrRequest = 0; + socketRecords[j].isCredentialRequest = 0; + socketRecords[j].debug_type = 1; +#if defined GY_OS_AMBA + //socketRecords[j].iIsAIRelay = 0; +#endif + socketRecords[j].used = 1; + break; + } + } + } + + //printf("\n---------http connection handler ----------- 8\n"); + if (nbytes == SOCKET_ERROR) + { + printf("Unable to connect to server: %d\n", errno); + //printf("\n-----------temp_buffer:%s\n", temp_buffer); + //printf("Unable to connect to server: %d\n", WSAGetLastError()); + //usSleep(2000000); + //WSACleanup(); + //closesocket(sock); + } + + if (isGetAlarmMotion && websocket_connected) + { + //printf("\n(%d) [http connection fun] Sophia isGetAlarmMotion\n", sock); + + ///nreuse + int reuse = 0; + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int sock_err_hold_times = 0; + //int alarm_send_count = 0; + + while (bHttpServerMainStart) + { + if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) { + //printf("\n------------websocket break 1\n"); + break; + } + + int sock_idx = -1; + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //if (socketRecord_ALM[i].sock == sock) + //sock_idx = i; + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + sock_idx = i; + + socketRecords[i].debug_type = 6; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + break; + } + } + } + + if (sock_idx >= 0) + { + if (socketRecords[sock_idx].isGetAlarmMotion == FALSE || socketRecords[sock_idx].isWebSocketConnect == FALSE) { + //printf("\n------------websocket break 2\n"); + break; + } + pthread_mutex_lock(&mutex_alm); + int len = ALMQueueSize(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\n--------len:%d\n",len); + if (len > 0) + { + int ret = 1; + + for (int index_len = 0; index_len < len; index_len++) { + pthread_mutex_lock(&mutex_alm); + ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); + char dupstr[ALMBUFSIZE] = { 0 }; + //strcpy(dupstr, alm_q_info.websocket_content); + strcpy(dupstr, alm_q_info.pszContent); + //int dupstr_len = strlen(dupstr); + + ALMQueuePop(sock_idx); + pthread_mutex_unlock(&mutex_alm); + + //printf("\n---------strlen(dupstr):%d\n", strlen(dupstr)); + if (strlen(dupstr) >= 1) + { +#if 1 + //printf("\n---------%s\n", dupstr); + + //int iAlarm_send_delay_fps = 0; + + //if (socketRecord_ALM[sock_idx].iIsWebsockethybi00 == 1) + //iAlarm_send_delay_fps = WEBSOCKET_SEND_DELAY_B; //6 + //else + //iAlarm_send_delay_fps = WEBSOCKET_SEND_DELAY_A; //0 + + //if (alarm_send_count == iAlarm_send_delay_fps) + { + ret = websocket_response(sock, dupstr); + //alarm_send_count = 0; + } + //else + { + //ret = 1; + //alarm_send_count++; + } + + //ALMQueueClear(sock_idx); //᭱[F + if (ret <= 0) + { + printf("\n(%d) [http connection fun]#1 printf(send error) and close socket\n", sock); + break; + } + else + { + //printf("\n(%d) [http connection fun]Send successfully.\n", sock); + } +#endif + sock_err_hold_times = 0; + } + else + { + sock_err_hold_times++; + //printf("\n------sock_err_hold_times# A : %d\n", sock_err_hold_times); + } + + if (index_len < len - 1) { + usSleep(25000); + } + } + + + if (ret <= 0) { + break; + } + //printf("\n[http connection fun]-2-1: closesocket:%d\n", sock); + } + else { + sock_err_hold_times++; + //printf("\n------sock_err_hold_times# B : %d\n", sock_err_hold_times); + } + } + else + { + //printf("\n(%d) [http connection fun] there is no correct sock in socketRecord_ALM\n", sock); + sock_err_hold_times++; + //printf("\n------sock_err_hold_times# C : %d\n", sock_err_hold_times); + } +#ifdef GY_OS_AMBA + usSleep(25000); +#elif defined GY_OS_V_SERIES + usSleep(110000); +#else + usSleep(60000); +#endif + + } + + //printf("\n----------------------[http connection fun]Websocket: closesocket:%d\n",sock); + + closesocket(sock); + websocket_connected = 0; + } + else if (isGetAlarmMotion && !(websocket_connected)) + { + //printf("\n(%d) [http connection fun] Sophia isGetAlarmMotion\n", sock); + + int reuse = 1; + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int sock_err_hold_times = 0; + //int alarm_send_count = 0; + + while (bHttpServerMainStart) + { + if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) + break; + + int sock_idx = -1; + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + //if (socketRecord_ALM[i].sock == sock) + //sock_idx = i; + if (socketRecords[i].used == 1) { + if (socketRecords[i].sock == sock) + { + sock_idx = i; + + socketRecords[i].debug_type = 7; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + break; + } + } + } + + if (sock_idx >= 0) + { + if (socketRecords[sock_idx].isGetAlarmMotion == FALSE) { + //set_record_process_note("getalarm_8592_end_1"); + break; + } + pthread_mutex_lock(&mutex_alm); + int len = ALMQueueSize(sock_idx); + pthread_mutex_unlock(&mutex_alm); + //printf("\n(%d) [http connection fun] queue_len:%d\n", sock, len); + + if (len > 0) + { + int rtn_s = 1; + set_record_process_note("getalarm_8592_start"); + for (int index_len = 0; index_len < len; index_len++) { + pthread_mutex_lock(&mutex_alm); + ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); + //char *dupstr = strdup(alm_q_info.pszContent); + char dupstr[ALMBUFSIZE] = { 0 }; + strcpy(dupstr, alm_q_info.pszContent); + int dupstr_len = strlen(dupstr); + //int dupstr_len = alm_q_info.nSize; + + //printf("\n(%d) [http connection fun] (before send)dupstr_len:%d\n", sock, dupstr_len); + //printf("\nstrlen(dupstr): %d\n", strlen(dupstr)); + + ALMQueuePop(sock_idx); + pthread_mutex_unlock(&mutex_alm); + + if (strlen(dupstr) >= 1) + { +#if 1 + + //printf("\n[nweb.c]restful: %d\n", sock); + //int rtn_s = send(sock, alm_q_info_copy.szContent, alm_q_info_copy.nSize, MSG_NOSIGNAL); + //printf("\n-------------[http connection fun]Http: send:%d\n", sock); + rtn_s = send(sock, dupstr, dupstr_len, MSG_NOSIGNAL); + + //printf("\n(%d) [http connection fun](after send) ALMQueueClear",sock); + //ALMQueueClear(sock_idx); //᭱[F + //dupstr_len = alm_q_info.nSize; + + //printf("\nrtn_s: %d\n", rtn_s); + if (rtn_s <= 0 /*&& rtn_s2 <= 0 && rtn_s3 <= 0*/) + { + break; + } + else { + } + sock_err_hold_times = 0; +#endif + } + else { + sock_err_hold_times++; + } + + if (index_len < len - 1) { + usSleep(25000); + } + } + + if (rtn_s <= 0) { + set_record_process_note("getalarm_8592_end_2"); + break; + } + else { + set_record_process_note("getalarm_8592_end_3"); + } + //-------------------------------jim add 2021/04/15 CegetalarmmotionA|socket + //printf("\n[http connection fun]-2-1: closesocket:%d\n", sock); + //closesocket(sock); + } + else { + //set_record_process_note("getalarm_8592_end_4"); + sock_err_hold_times++; + } + } + else { + //set_record_process_note("getalarm_8592_end_5"); + //printf("\n(%d) [http connection fun] there is no correct sock in socketRecord_ALM\n", sock); + //closesocket(sock);//̥~hw + //break; + sock_err_hold_times++; + } + +#ifdef GY_OS_AMBA + usSleep(25000); +#elif defined GY_OS_V_SERIES + usSleep(110000); +#else + usSleep(60000); +#endif + } + + //printf("\n-------------[http connection fun]Http: closesocket:%d\n", sock); + closesocket(sock); + } + + if (isGetAlarmMotion) { + //printf("\n---------http connection handler ----------- 9\n"); + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == sock) + { + socketRecords[i].sock = -1; + //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + closesocket(sock); + + pthread_mutex_lock(&mutex_alm); + ALMQueueClear(i); + pthread_mutex_unlock(&mutex_alm); + + socketRecords[i].used = 0; + + break; + } + } + } + + //printf("\n---------http connection handler ----------- 11\n"); + //pthread_mutex_unlock(&mutex_http_connection_handler); + pthread_exit(NULL); +} + +int run_preload_http_server(int http_port) +{ + if (isGYNetReady == FALSE) + { + int socket_desc, client_sock; + struct sockaddr_in server, client; + socklen_t client_length = sizeof(client); + + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + if (socket_desc == -1) + { + printf("[run preload http server] Could not create a socket!\n"); + return 1; + } + //puts("Socket created"); + + //Prepare the sockaddr_in structure + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(http_port); + + struct timeval timeout; + timeout.tv_sec = 5; + timeout.tv_usec = 0; + + setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + int tcpnodelay = 1; + setsockopt(socket_desc, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + + int reuse = 1; + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(socket_desc, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) { + printf("\n[run preload http server] Could not bind a socket!\n"); + closesocket(socket_desc); + return 1; + } + + //puts("bind done"); + + if (listen(socket_desc, 256)) { + printf("\n[run preload http server] Could not listen from a socket!\n"); + closesocket(socket_desc); + return 1; + } + + //pthread_t thread_id; + + int count = 5; + fd_set active_fd_set, read_fds; + FD_ZERO(&active_fd_set); + FD_SET(socket_desc, &active_fd_set); + + struct timeval tvSelect; + tvSelect.tv_sec = 1; + tvSelect.tv_usec = 0; + int retval = 0; + is_authorized_run_preload_http_server = 1; + while (bPreloadHttpServerMainStart && (isGYNetReady == FALSE)) + { + for (int countloop = 0; bPreloadHttpServerMainStart && (isGYNetReady == FALSE) && countloop < count; countloop++) + { + read_fds = active_fd_set; + retval = select(socket_desc + 1, &read_fds, NULL, NULL, &tvSelect); + + if (retval == -1) { + printf("\nselect() error #1\n");//perror is strange in nova + break; + } + else if (retval == 0) + { + //printf("\nselect timeout\n"); + } + else + { + //for (int i = 0; i < 256; i++) + { + //if (FD_ISSET(i, &read_fds)) + if (FD_ISSET(socket_desc, &read_fds)) + { + //if (i == socket_desc) + { + client_sock = accept(socket_desc, (struct sockaddr *)&client, &client_length); + + if (client_sock < 0) + { + + } + else + { + timeout.tv_sec = 5; + timeout.tv_usec = 0; + + setsockopt(client_sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + //20210714 ADD + int reuse = 1; + setsockopt(client_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(client_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + int qlen = 5; + setsockopt(client_sock, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + //if (check_if_socket_ok == 1) + //{ + pthread_t thread_id; + pthread_create(&thread_id, 0, http_connection_handler, (void*)(intptr_t)client_sock); + //} + //else { + //closesocket(client_sock); + //} + } + + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + //usSleep(1000); + //break; + } + } + //else { + //usSleep(50); + //} + } + } + + usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); + //usSleep(1000); + } + + if (retval == -1) { + break; + } + } + + is_authorized_run_preload_http_server = 0; + //bPreloadHttpServerMainStart = 0; + FD_CLR(socket_desc, &active_fd_set); + closesocket(socket_desc); + } + + return 0; +} + +int run_http_server(char *option, void* _zc, CNNType cnn_type/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, + char *mac_address, char *ip_address, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType) +{ + http_cnn_type = cnn_type; + for (int n = 0; n < MAX_LAYER_NUM; n++) + { + //http_nets[n] = nets[n]; + //http_names[n] = names[n]; + //http_nms[n] = nms[n]; + http_layerFeatureType[n] = layerFeatureType[n]; + } + //http_layer_count = layer_count; + //http_alphabet = alphabet; + http_thresh = thresh; + http_hier_thresh = hier_thresh; + http_dont_show = dont_show; + http_ext_output = ext_output; + http_save_labels = save_labels; + //http_mac_address = mac_address; + //http_ip_address = ip_address; + http_http_port = http_port; + http_licenseType = licenseType; + http_afsCode = afsCode; + http_featureType = featureType; + http_strLicenseType = strLicenseType; + //http_strLicenseStatus = strLicenseStatus; + //http_strUnlockingKey = strUnlockingKey; + http_advLicenseType = advLicenseType; + + if (unlockingKeyInnoFR == 1||g_IsToFDevice == 1 || g_IsRadarDevice == 1 || td_weight_num >= 1 || check_if_fe_fail == 1 || licenseType == _PERMANENT_LICENSE_MULTI || licenseType == _TRIAL_LICENSE_MULTI || licenseType == _PERMANENT_LICENSE_MULTI_POST || + licenseType == _LICENSE_FPS06 || licenseType == _LICENSE_FPS12 || licenseType == _LICENSE_FPS18 || licenseType == _LICENSE_FPS24 || licenseType == _LICENSE_FPS30 || + licenseType == _LICENSE_FPS36 || licenseType == _LICENSE_FPS42 || licenseType == _LICENSE_FPS48 || licenseType == _LICENSE_FPS54 || licenseType == _LICENSE_FPS60 || + licenseType == _TRIAL_LICENSE_FPS06 || licenseType == _TRIAL_LICENSE_FPS12 || licenseType == _TRIAL_LICENSE_FPS18 || licenseType == _TRIAL_LICENSE_FPS24 || licenseType == _TRIAL_LICENSE_FPS30 || + licenseType == _TRIAL_LICENSE_FPS36 || licenseType == _TRIAL_LICENSE_FPS42 || licenseType == _TRIAL_LICENSE_FPS48 || licenseType == _TRIAL_LICENSE_FPS54 || licenseType == _TRIAL_LICENSE_FPS60) //multi-thread server + { + int socket_desc = 0; + + //Web + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + if (socket_desc == -1) + { + printf("[run http server] Could not create a socket!\n"); + usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//קKsockإѫASW߰ݡC + return 1; + } + + struct sockaddr_in server; + bzero(&server, sizeof(server)); + + //Prepare the sockaddr_in structure + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(http_port); + + struct timeval timeout; + timeout.tv_sec = 5; + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + int priority = 2; + + setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(socket_desc, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(socket_desc, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(socket_desc, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + setsockopt(socket_desc, SOL_SOCKET, SO_PRIORITY, (const char*)&priority, sizeof(priority)); + + if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) + { + printf("\n[run http server] Could not bind a socket!\n"); + closesocket(socket_desc); + usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//קKsockإѫASW߰ݡC + return 1; + } + //puts("bind done"); + + if (listen(socket_desc, 256) < 0)//MAX_CLIENT_SOCKET + { + printf("\n[run http server] Could not listen from a socket!\n"); + closesocket(socket_desc); + usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//קKsockإѫASW߰ݡC + return 1; + } + + int maxfd = 0; + fd_set active_fd_set, read_fds; + FD_ZERO(&active_fd_set); + FD_SET(socket_desc, &active_fd_set); + + struct timeval tvSelect; + tvSelect.tv_sec = 1; + tvSelect.tv_usec = 0; + int retval = 0; + + //pthread_t thread_id_for_sock[FD_SETSIZE] = { 0 }; + //first_is_connection_authorized = 0; + while (bHttpServerMainStart) + { + python_check_webstatus = 1; // Ming add + // printf("\n[run http server] while start\n"); + //for (int countloop = 0; bHttpServerMainStart && countloop < count; countloop++) + { + maxfd = socket_desc; + //maxfd = socket_desc > sockfd ? socket_desc : sockfd; + //printf("\n----#1-----maxfd:%d\n", maxfd); + + read_fds = active_fd_set; + retval = select(maxfd + 1, &read_fds, NULL, NULL, &tvSelect); + //printf("\n [[[run http server] retval:%d]]\n", retval); + + if (retval == -1) { + printf("\nselect()\n"); + break; + } + else if (retval == 0) + { + //printf("\nselect timeout\n"); + } + else + { + //for (int i = 0; i < 256; i++)//FD_SETSIZE + { + //printf("\n [[[run http server] i:%d]]\n", i); + + //if (FD_ISSET(i, &read_fds)) + if (FD_ISSET(socket_desc, &read_fds)) + { + //if (i == socket_desc) + { + //printf("\n [[[run http server] i=socket_desc:%d]]\n", socket_desc); + struct sockaddr_in client; + socklen_t client_length = sizeof(client); + int client_sock = accept(socket_desc, (struct sockaddr *)&client, &client_length); + //#ifdef _DEBUG_AMBA + //printf("\n(%d) [[[run http server] while start ======================]]\n", client_sock); + //#endif + + if (client_sock < 0) + { + //printf("[[[run http server] invalid socket]]\n"); + } + else + { + + //printf("\n[[[run http server] while start 1======================]]\n"); + timeout.tv_sec = 5;//3 + timeout.tv_usec = 0; + //reuse = 1; + //qlen = 5; + + setsockopt(client_sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + //20210714 ADD + setsockopt(client_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(client_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + setsockopt(client_sock, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + setsockopt(client_sock, SOL_SOCKET, SO_PRIORITY, (const char*)&priority, sizeof(priority)); + + //printf("\n[[[run http server] while start 2======================]]\n"); + + + //if (check_if_socket_ok == 1) { + pthread_t thread_id; + pthread_create(&thread_id, 0, http_connection_handler, (void*)(intptr_t)client_sock); + //} + //else { + //closesocket(client_sock); + //} + } + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + //break; + } + //usSleep(1000); + //printf("\n[run http server] double free - 1\n"); + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); + } + //else { + //usSleep(50); + //} + //printf("\n[run http server] double free - 2\n"); + } + //printf("\n[run http server] double free - 3\n"); + } + //printf("\n[run http server] double free - 4\n"); + } + + //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); + //printf("\n[run http server] while end\n"); + usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); + //usSleep(1000); + + } + + FD_CLR(socket_desc, &active_fd_set); + //printf("\n\n(%d)[[[run http server] while end ======================]]\n\n", client_sock); + closesocket(socket_desc); + + } + else if (licenseType == _PERMANENT_LICENSE_SINGLE || licenseType == _TRIAL_LICENSE_SINGLE || licenseType == _PERMANENT_LICENSE_SINGLE_POST) //single thread version + { + + } + + //printf("\n[[[run http server] end ======================]]\n\n"); + return 0; +} + + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +void import_lpr_list_file(char *headerBuffer,char *multiPartBoundary,int bIsMultipart,char *contentBuffer,long nTotalContentLen) { + //printf("\n---------------import lpr list:%d\n",1); + char *image_buff = NULL; + image_buff = malloc(CONTENT_BUFSIZE); + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr(headerBuffer, "boundary=")) != NULL) + { + //printf("\n---------------import lpr list:%d\n", 2); + + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, MAX_MSG_LEN); + //char endStr[] = "--"; + strncpy(multiPartBoundary, tempPtr, strlen); + //strcat(multiPartBoundary,endStr); + } + + } + } + //printf("\n---------------import lpr list:%d\n", 3); + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + //printf("\n---------------import lpr list:%d\n", 4); + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0)//find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + } + else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + } + } + } + + //printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); + //printf("\n---------------import lpr list:%d\n", 5); + //printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); + //printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); + //printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); + //printf("\n--------------contentBuffer:%s\n", contentBuffer); + +#if 1 + if (start_to_import_file == 0 && !((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) + { + printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); + } + else +#endif + { + start_to_import_file = 1; + + +#if 1 + char *lpr_data_p = NULL; + int rule_reject = 0; + int lpr_max_length = 0; + int lpr_b_length = 0; + int lpr_w_length = 0; + int _max_len = COUNT_BLACK + COUNT_WHITE - 200; + char *lpr_line_data = NULL, *name = NULL, *value = NULL; + int lpr_len = 0; + int nlen; + char *lpr_list_type = NULL; + char *lpr_name = NULL; + char *lpr_usrname = NULL; + char *lpr_other = NULL; + char *lpr_schedule_start = NULL; + char *lpr_schedule_end = NULL; + char *lpr_endtime = NULL; + char *lpr_detect_level = NULL; + //printf("\n---------------import lpr list:%d\n", 61101); + //printf("\n---------------import lpr list:%d\n", 61111); + //printf("\n---------------import lpr list:%d\n", 61121); + //printf("\n---------------import lpr list:%d\n", 9); + char *lpr_line_end = NULL; + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + lpr_data_p = image_buff + 2; + } + + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + //printf("\n---------------import lpr list:%d\n", 7); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + + //Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = value; + lpr_name = strstr(value, ",") + 1; + value = lpr_name; + lpr_usrname = strstr(value, ",") + 1; + //name = strsep(&value, ","); + //lpr_name = strsep(&value, ","); + //lpr_usrname = strsep(&value, ","); + + if (lpr_name == NULL || lpr_list_type == NULL || lpr_usrname == NULL) + break; + + if (lpr_max_length == _max_len) + { + //printf("\n---------------import lpr list:%d\n", 71); + rule_reject = 1; + break; + } + + if ((strncmp(name, ACT_PARAM_BKLISTNAME, strlen(ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_BKLISTNAME, strlen(S_ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, BKLISTNAME, strlen(BKLISTNAME)) == 0)) + lpr_b_length++; + else if ((strncmp(name, ACT_PARAM_WTLISTNAME, strlen(ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_WTLISTNAME, strlen(S_ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, WTLISTNAME, strlen(WTLISTNAME)) == 0)) + lpr_w_length++; + else + { + //printf("\n---------------import lpr list:%d\n", 72); + continue; + //rule_reject = 1; + //break; + } + + if (lpr_b_length > COUNT_BLACK - 100) + { + //printf("\n---------------import lpr list:%d\n", 73); + rule_reject = 1; + break; + } + + if (lpr_w_length > COUNT_WHITE - 100) + { + //printf("\n---------------import lpr list:%d\n", 74); + rule_reject = 1; + break; + } + + lpr_max_length++; + + lpr_line_end = strstr(lpr_line_data, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + //printf("\n---------------import lpr list:%d\n", 8); + if (rule_reject != 1) + { + //printf("\n---------------import lpr list:%d\n", 88); + //callback_reset_db_list(); //clean black&white + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + //printf("\n--------------image_buff:%s\n", image_buff + 2); + lpr_data_p = image_buff + 2; + } + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + /* Skip to next assignment */ + //fprintf(stderr, "[string] : %s\n", lpr_line_data); + //fprintf(stderr, "[string len] : %d\n", strlen(lpr_line_data)); + + //Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = strsep(&value, ","); + lpr_name = strsep(&value, ","); + lpr_usrname = strsep(&value, ","); + lpr_other = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + lpr_schedule_start = strsep(&value, ","); + lpr_schedule_end = strsep(&value, ","); + lpr_endtime = strsep(&value, ","); + if ((lpr_detect_level = strsep(&value, "\r\n")) == NULL) + lpr_detect_level = strsep(&value, "\n"); + lpr_detect_level = rtrim(lpr_detect_level); + + //lpr_exist= strsep(&value, ","); + //lpr_paystatus = strsep(&value, ","); + //lpr_paystatus =rtrim(lpr_paystatus); + + for (int try_counts = 0; try_counts < 5; try_counts++) { + int ret_action = action_lpr_import_infomation(lpr_name, lpr_list_type, lpr_usrname, lpr_other, lpr_schedule_start, lpr_schedule_end, lpr_endtime, lpr_detect_level); //lpr_other); + if (ret_action) + break; + usSleep(10000); + } + + g_count_lpr_insert_times++; + lpr_line_end = strstr(lpr_line_data, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + } +#endif + printf("lpr list file upload ok.\n"); + } + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + //printf("\n---------------import lpr list:%d\n", 11); + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time: %f\n", dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } +} + +void *import_lpr_list_file_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("import_lpr"); + //printf("\n--------------import lpr list file thread\n"); + import_lpr_list_file(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); + g_count_lpr_insert_times = -1; + pthread_exit(NULL); +} +#ifdef GY_OS_AMBA +void import_face_list_file(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen) { + //printf("\n---------------import lpr list:%d\n",1); + char *image_buff = NULL; + image_buff = malloc(CONTENT_BUFSIZE); + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr(headerBuffer, "boundary=")) != NULL) + { + //printf("\n---------------import lpr list:%d\n", 2); + + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, MAX_MSG_LEN); + strncpy(multiPartBoundary, tempPtr, strlen); + } + + } + } + //printf("\n---------------import lpr list:%d\n", 3); + + if (bIsMultipart) + { + char* pContent = contentBuffer; + char* pBlockStart = contentBuffer; + + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + //printf("\n---------------import lpr list:%d\n", 4); + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0)//find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + } + else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + } + } + } + + //printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); + //printf("\n---------------import lpr list:%d\n", 5); + //printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); + //printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); + //printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); + //printf("\n--------------contentBuffer:%s\n", contentBuffer); + + if (start_to_import_file == 0 && !((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) + { + printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); + } + else + { + start_to_import_file = 1; + + char *lpr_data_p = NULL; + int rule_reject = 0; + int lpr_max_length = 0; + int lpr_b_length = 0; + int lpr_w_length = 0; + int _max_len = COUNT_BLACK + COUNT_WHITE - 200; + char *lpr_line_data = NULL, *name = NULL, *value = NULL; + int lpr_len = 0; + int nlen; + char *lpr_list_type = NULL; + char *lpr_name = NULL; + char *lpr_usrname = NULL; + char *lpr_other = NULL; + char *lpr_schedule_start = NULL; + char *lpr_schedule_end = NULL; + char *lpr_endtime = NULL; + char *lpr_detect_level = NULL; + //printf("\n---------------import lpr list:%d\n", 61101); + //printf("\n---------------import lpr list:%d\n", 61111); + //printf("\n---------------import lpr list:%d\n", 61121); + //printf("\n---------------import lpr list:%d\n", 9); + char *lpr_line_end = NULL; + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + lpr_data_p = image_buff + 2; + } + + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + //printf("\n---------------import lpr list:%d\n", 7); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + + // Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = value; + lpr_name = strstr(value, ",") + 1; + value = lpr_name; + lpr_usrname = strstr(value, ",") + 1; + + if (lpr_name == NULL || lpr_list_type == NULL || lpr_usrname == NULL) + break; + + if (lpr_max_length == _max_len) + { + //printf("\n---------------import lpr list:%d\n", 71); + rule_reject = 1; + break; + } + + if ((strncmp(name, ACT_PARAM_BKLISTNAME, strlen(ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_BKLISTNAME, strlen(S_ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, BKLISTNAME, strlen(BKLISTNAME)) == 0)) + lpr_b_length++; + else if ((strncmp(name, ACT_PARAM_WTLISTNAME, strlen(ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_WTLISTNAME, strlen(S_ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, WTLISTNAME, strlen(WTLISTNAME)) == 0)) + lpr_w_length++; + else + { + continue; + } + + if (lpr_b_length > COUNT_BLACK - 100) + { + rule_reject = 1; + break; + } + + if (lpr_w_length > COUNT_WHITE - 100) + { + rule_reject = 1; + break; + } + + lpr_max_length++; + + lpr_line_end = strstr(lpr_line_data, "\r\n"); + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + //printf("\n---------------import lpr list:%d\n", 8); + if (rule_reject != 1) + { + //printf("\n---------------import lpr list:%d\n", 88); + //callback_reset_db_list(); //clean black&white + if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) + { + lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM + } + else { + //printf("\n--------------image_buff:%s\n", image_buff + 2); + lpr_data_p = image_buff + 2; + } + lpr_line_data = lpr_data_p; + nlen = strlen(lpr_data_p); + lpr_line_end = strstr(lpr_data_p, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_data_p, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + + //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); + //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); + for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) + { + value = lpr_list_type = lpr_line_data; + /* Skip to next assignment */ + //fprintf(stderr, "[string] : %s\n", lpr_line_data); + //fprintf(stderr, "[string len] : %d\n", strlen(lpr_line_data)); + + //Assign variable + for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); + + name = strsep(&value, ","); + lpr_name = strsep(&value, ","); + lpr_usrname = strsep(&value, ","); + lpr_other = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + //lpr_address = strsep(&value, ","); + lpr_schedule_start = strsep(&value, ","); + lpr_schedule_end = strsep(&value, ","); + lpr_endtime = strsep(&value, ","); + if ((lpr_detect_level = strsep(&value, "\r\n")) == NULL) + lpr_detect_level = strsep(&value, "\n"); + lpr_detect_level = rtrim(lpr_detect_level); + + //lpr_exist= strsep(&value, ","); + //lpr_paystatus = strsep(&value, ","); + //lpr_paystatus =rtrim(lpr_paystatus); + + for (int try_counts = 0; try_counts < 5; try_counts++) { + int ret_action = action_lpr_import_infomation(lpr_name, lpr_list_type, lpr_usrname, lpr_other, lpr_schedule_start, lpr_schedule_end, lpr_endtime, lpr_detect_level); //lpr_other); + if (ret_action) + break; + usSleep(10000); + } + + g_count_lpr_insert_times++; + lpr_line_end = strstr(lpr_line_data, "\r\n"); + + if (lpr_line_end == NULL) + lpr_line_end = strstr(lpr_line_data, "\n"); + + if (lpr_line_end != NULL) + lpr_len = lpr_line_end - lpr_line_data; + } + } + printf("lpr list file upload ok.\n"); + } + + //AI recognizing process + clock_t c1 = clock(); + ///Steven MARK TEMP + //printf("\n---------------import lpr list:%d\n", 11); + + clock_t c2 = clock(); + double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); + printf("recognition time: %f\n", dDiff); + if (image_buff) { + free(image_buff); + image_buff = NULL; + } +} + +void *import_face_list_file_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("import_lpr"); + import_face_list_file(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); + g_count_lpr_insert_times = -1; + pthread_exit(NULL); +} + +int get_g_check_if_change_preset() { + return g_check_if_change_preset; +} + +void set_g_check_if_change_preset_to_zero() { + g_check_if_change_preset = 0; +} +#endif +#endif + +#ifdef GY_OS_AMBA +// a113n radarbg + +void import_radarbg(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen) +{ + // printf("\n---------------import lpr list:%d\n",1); + printf("[import_radarbg] Enter\n"); + char *image_buff = NULL; + image_buff = malloc(CONTENT_BUFSIZE); + char *cp = NULL; + char *tempPtr = NULL; + if ((cp = strstr(headerBuffer, "boundary=")) != NULL) // ڲqoONӦ http request header }, ]ɮ׸b᭱ + { + // printf("\n---------------import lpr list:%d\n", 2); + + int strlen = 0; + tempPtr = cp + 9; + cp = strstr(tempPtr, "\r\n"); + if (cp != NULL) + { + strlen = cp - tempPtr; + if (strlen > 0) + { + memset(multiPartBoundary, 0, MAX_MSG_LEN); + // char endStr[] = "--"; + strncpy(multiPartBoundary, tempPtr, strlen); + // strcat(multiPartBoundary,endStr); + } + } + } + // printf("\n---------------import lpr list:%d\n", 3); + + if (bIsMultipart) // oڲqOpGɮ׳Qhʥ]Bz + { + char *pContent = contentBuffer; + char *pBlockStart = contentBuffer; + + memset(image_buff, 0x00, CONTENT_BUFSIZE); + size_t nbytes = 0; + size_t nTotalBytes = 0; + // printf("\n---------------import lpr list:%d\n", 4); + for (int i = 0; i < nTotalContentLen; i++) + { + pContent = contentBuffer + i; + if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) + { + pBlockStart = strstr(pContent, "\r\n\r\n"); + pBlockStart += 4; + i += (pBlockStart - pContent - 1); + } + else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) + { + if (pContent - pBlockStart == 0) + nbytes = pContent - pBlockStart; + else if (pContent - pBlockStart > 0) + nbytes = (pContent - pBlockStart) - strlen("\r\n"); + memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); + nTotalBytes += nbytes; + if (nbytes != 0) // find end of boundary + { + char endStr[] = "--"; + pBlockStart = strstr(pContent, endStr); + pBlockStart += 2; + } + else + { + pBlockStart = strstr(pContent, "\r\n"); + pBlockStart += 2; + } + + i += (pBlockStart - pContent - 1); + } + } + } // ӬO image_buff Oɮ , oO img ӬOT}C + + // printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); + // printf("\n---------------import lpr list:%d\n", 5); + // printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); + // printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); + // printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); + // printf("\n--------------contentBuffer:%s\n", contentBuffer); + + { // img s + // Mat tempImg; + // tempImg = Mat(600, 800, CV_8UC3, image_buff); // @}Cn pitch Oԣ + // printf("[import_radarbg] tempImg init success\n"); + // imwrite("/emmc/plugin/Aida_data/radar/radar_uploadtest.jpg", tempImg); + // printf("[import_radarbg] imwrite success\n"); + // tempImg.release(); + // WO c++ code ҥHoΤU tX}Y include colordetector.cpp + printf("[import_radarbg] saverawrgbtojpg enter\n"); + SaveRawRGBToJPG("/emmc/plugin/Aida_data/radar/radar_uploadtest.jpg", image_buff, 800, 0, 600, 1); // For normal type + printf("[import_radarbg] saverawrgbtojpg end\n"); + } + +#if 0 + if (!((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) // oOɮˬd nT{@U jpg 榡ˬd + { + printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); + } + else + { // ɮ׹FUӴNs ڲq oӭnhsϤ + Mat tempImg; + tempImg = Mat(h, w, CV_8UC3, image_buff); + printf("radar back ground img file upload ok.\n"); + } +#endif + + if (image_buff) + { + free(image_buff); + image_buff = NULL; + } +} + +void *import_radarbg_thread(void *ptr) +{ + pthread_detach(pthread_self()); + import_radarbg(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); + // g_count_lpr_insert_times = -1; + pthread_exit(NULL); +} +#endif \ No newline at end of file diff --git a/src/nweb_Ming.h b/src/nweb_Ming.h new file mode 100644 index 0000000..38d312b --- /dev/null +++ b/src/nweb_Ming.h @@ -0,0 +1,1123 @@ +#if 1 +#pragma once +#ifndef NWEB_H +#define NWEB_H +//#include "structures.h" +#include "define_inc.h" +#include "zlog.h" +#include "cv.h" +#include "utility.h" +#include "onvif_data.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +#include <sys/types.h> +#include <sys/socket.h> +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include <stdbool.h> +#endif +#ifdef GY_OS_WIN +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#endif + +#include <curl/curl.h> +#include <curl/easy.h> +#include <sys/prctl.h> + +#ifdef GY_OS_AMBA +//#include "face_parser.h" +#endif + +#ifdef __cplusplus +extern "C" { +#include <stdint.h> +#include <stdlib.h> +#endif + +#define CONTENT_BUFSIZE MAX_IMG_BUFF_SIZE +#define LOG_BUFSIZE (BUFSIZE<<1) +#define NW_ERROR 1 +#define NW_SORRY 2 +#define NW_LOG 3 +#define LINE_BUFSIZE 7*8192 //512 +#define MAX_SIZE_POINT 6 +#define MAX_NUMBER_PAGE 59 +#define HEADER_BUFSIZE 1024 + +#define WEBPYTHONBUFFER_LENSIZE 256 +#define WEBPYTHONBUFFER_ROWSIZE 256 +#define MAX_GET_PYTHON_BUFFER_ROW_SIZE 8 + +#ifdef GY_OS_NOVA +#define MEMORY_SIZE 256*1024 +#endif + +#ifdef GY_OS_AMBA +#define MEMORY_SIZE 512*1024 +#endif + +#define MAX_SERVICE_SIZE 256 + +#define MAX_SIZE_A_OSD_OBJECT 11 +#define MAX_SIZE_A_SP_OBJECT 6 + + //trigger types +#define TRIGGER_OUTSIDE_INSIDE 1 +#define TRIGGER_INSIDE_OUTSIDE 2 +#define TRIGGER_INSIDE_INSIDE 3 +#define TRIGGER_OUTSIDE_OUTSIDE 4 + + /*typedef struct + { + int x; + int y; + } Point;*/ + + /*typedef struct { + char* recvBuffer; + char* contentBuffer; + } BufferPtr;*/ + + /*typedef struct { + time_t recv_time; + int frames; + } SecData;*/ + + typedef struct + { + struct tm * snapshot_time; + time_t snapshot_time_mktime; + time_t snapshot_msecs_time; + char snapshot_addr[MAX_IMG_SIZE]; + int snapshot_size; + }SnapHDInfo; + + typedef struct + { + char weight_repository[35]; + int enable_weight_to_run; + }WeightFileInfo; + + typedef struct + { + char email_address1[50]; + char email_address2[50]; + char email_address3[50]; + char email_address4[50]; + char email_address5[50]; + + char email_address[50]; + + char smtp_server[50]; + int smtp_auth_mode; + char smtp_port[10]; + int smtp_auth; + + char auth_account[50]; + char auth_password[50]; + } IPCAMServiceInfo; + + typedef struct + { + int checked; + char detect_event_id[20]; + char detect_event_name[50]; + char post_event_name[MAX_MSG_LEN * 10]; + char counter_name[MAX_MSG_LEN * 10]; + int counter_increment; + //TriggerData [MAX_DETECT_OBJECTS]; + } TriggerEvent; + + typedef struct + { + bool isActive; + + time_t det_time; + /*char levenshtein_distance[10]; + char min_characters[10]; + char max_characters[10]; + char confidence[10];*/ + char enable_traffic_light[10]; + //char enable_social_distance[10]; +#ifdef GY_OS_AMBA + CvMat* PerspectiveTransformArray; +#endif + char detection_time[20]; + char metadata1[BUFSIZE]; + char metadata2[BUFSIZE]; + char metadata_stop[50]; + char link_to_counter[10]; + char enable_direction1[10]; + char enable_direction2[10]; + char direction1[10]; + char direction2[10]; + int no_parking_time; + int no_parking_time_in_minute; + int queuing_count; + int prev_queuing_num; + int queuing_trigger_event_idx; + char ptz_zone_to_preset[20]; + + TriggerEvent trigger_event[MAX_TRIGGER_EVENT]; + CPoint Points[6]; + int min_x_points; + int max_x_points; + int min_y_points; + int max_y_points; + + f_CPoint onvif_Points[6]; + + int parking_space; + int parking_line; + + //Social Distance + float set_distance; + char world_distance_unit[10]; + float world_distance[DETECTION_POINTS_COUNT]; + int distance_violation_count; + int prev_distance_violation_num; + time_t prev_distance_violation_time; + time_t recent_distance_violation_start_time; + int distance_trigger_event_idx; + //float LinearFormula[DETECTION_POINTS_COUNT][3]; //4 edges, each edge has it's ax+by+c =0 values + //char* MovingDirection[DETECTION_POINTS_COUNT]; + + int point_num; + + int obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; + int last_obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; + int last_two_obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; + int check_if_missing; + + char enable_speed[10]; + char enable_radar_speed[10]; + char enable_ivs_zone[10]; + float world_distance_side1; + float world_distance_side2; + char world_time_unit[20]; + + char obj_max_proportion_in_zone[10]; + char obj_min_proportion_in_zone[10]; + + //int speed_upper_bound;//Чset_distance + //int speed_lower_bound;//Чset_distance + + //char confidence3[10]; +#if defined GY_OS_AMBA + //jvc setting + int jvc_enable_detect; + int jvc_person_check; + int jvc_vehicle_check; + int jvc_person_confidence; + int jvc_vehicle_confidence; + int jvc_behavior; + int jvc_obj_size; + int jvc_detect_priority; + int jvc_detect_mode; + int jvc_detect_fov; + int jvc_trigger_delay_time; + int jvc_trigger_times; + int jvc_queuing_count; + int jvc_enable_direction1; + int jvc_direction1; + char jvc_counter_name[50]; + int jvc_counter_value; + int jvc_density_value; + + int jvc_enable_ptz; + int jvc_ptz_tracking_time; + int jvc_ptz_fov; + int jvc_ptz_auto_intercept; + int jvc_ptz_preset_intercept; + int jvc_ptz_zone_to_preset; +#endif + } DetectionZoneInfo; + + typedef struct + { + int channel_idx; + int enable_anpr; + int enable_face; + int enable_traffic; + int enable_logo; + int enable_add_face_frequent_list; + int tab_view_width; + int tab_view_height; + float tab_view_width_ratio; + float tab_view_height_ratio; + float speed_view_width_ratio; + float speed_view_height_ratio; + char camera_name[20]; + char obj_max_proportion[10]; + char obj_min_proportion[10]; + char levenshtein_distance[10]; + char min_characters[10]; + char max_characters[10]; + + int i_plate_filter_times; + int i_plate_filter_time; + int i_plate_free_time; + + char confidence[10]; //P Plate + char confidence2[10]; //q Traffic + char confidence3[10]; //SΨ None + char confidence4[10]; //SΨ None + int enable_traffic_light_zone; + //int enable_social_distance_zone; + char traffic_light_color[20]; + //CvMat* PerspectiveTransformArray; + char enable_lpr_db[10]; + char enable_PTZ[10]; + char enable_track[10]; + + char ivs_mode[10]; + + char ptz_tracking_fov_min[10]; + char ptz_tracking_fov_max[10]; + char ptz_enable_tracking[10]; + char ptz_tracking_resume_dwell[10]; + int ptz_tracking_by_enter_zone; + int ptz_tracking_mode; + int ptz_sensitivity; + int iVideo_source_w; + int iVideo_source_h; + + char enable_tracking_limits[10]; + char ptz_pan_left_limit[20]; + char ptz_pan_right_limit[20]; + char ptz_tilt_up_limit[20]; + char ptz_tilt_down_limit[20]; + char ptz_speed[20]; + + char enable_unknown_object[10]; + char enable_ivs_person_detection[10]; + + char assign_ivs_object_to[100]; + + char enable_ambulance[10]; + char enable_blank_plate[10]; + char enable_stop_sign[10]; + + char enable_ivs_fix_mode[10]; + + char enable_show_unknown_object[10]; + char enable_ivs_and_ai[10]; + char enable_lpr_upon_triggered[10]; + + char dwell_lpr_upon_triggered[10]; + + char unknown_object_max_proportion[10]; + char unknown_object_min_proportion[10]; + char confidence_unknown_object[10]; + char confidence2_unknown_object[10]; + char dwell_unknown_object[10]; + char dwell_minute_focus_on[10]; + char person_obj_fov[10]; + + char getnetwork_buffer_id[10]; + + char red_light_zone[10]; + char no_give_way_zone_to_protect[10]; + char no_give_way_zone_to_keep_away[10]; + char no_give_way_zone_to_protect_2[10]; + char no_give_way_zone_to_keep_away_2[10]; + int count_zone; + + } ChannelInfo; + + typedef struct + { + char enable_person_independent[10]; + char enable_onvif_profile_m[10]; + char nms_thres[10]; + char tracking_id_dwell[10]; + + char enable_cloud[10]; + char enable_special_edition[10]; + char enable_python[10]; + char enable_python_file[50]; + char enable_low_cpu_usage[10]; + char cloud_enable_snap[10]; + char cloud_enable_notification[10]; + char cloud_account[256]; + char cloud_password[256]; + char cloud_notification_dwell[10]; + char cloud_statue[MEMORY_SIZE]; + char language[50]; + + char enable_display_properties[10];//enable to show color + char enable_display_OSD[10]; + + char enable_special_char[10]; + char enable_bounding_box[10]; + + char enable_dwell_bounding_box[10]; + + char force_i_to_one[10]; + char force_o_to_zero[10]; + char enable_plate_angle_correction[10]; + + char enable_ai_mirror[10]; + char ai_mirror_feature[10]; + + char enable_cloud_v2[10]; + char cloud_v2_notification_dwell[10]; + char cloud_v2_content[BUFSIZE_V3]; + char enable_cloud_record_v2[10]; + char cloud_record_v2_notification_dwell[10]; + char cloud_record_v2_content[BUFSIZE_V3]; + + char cloud_v2_statue[MEMORY_SIZE]; + char cloud_record_v2_statue[MEMORY_SIZE]; + + char enable_post_only_if_both_detected[10]; + + char enable_getalarmmotion_snap[10]; + char getimage_encoder_id[10]; + char getimage_encoder_id_HD[10]; + + char osd_encoder_id[10]; + char osd_font_size[10]; + char osd_outline_lilin[10]; + char enable_osd_bottom[10]; + char osd_bottom_bg_tran[10]; + char osd_bottom_content[BUFSIZE_V3]; + + + char sensors_type[10]; + + char enable_sync_external_lpr_db[10]; + char external_lpr_db_IP[256]; + char external_lpr_db_port[10]; + char external_lpr_db_username[60]; + char external_lpr_db_password[60]; + + char enable_email_notification[10]; + char enable_system_logs[10]; + char enable_email_jpeg[10]; + char email_reset_time_interval[20]; + + char enable_ftp[10]; + char ftp_url[256]; + char ftp_port[25]; + char ftp_username[256]; + char ftp_password[256]; + char ftp_remote_directory[1024]; + char ftp_jpeg_file_name_format[10 + 1]; + char ftp_jpeg_file_name[60]; + + } SystemSettingInfo; + + typedef struct + { + char post_protocol[10 + 1]; + char post_event_method[10+1]; + char post_event_name[60]; + char post_host_ip[256]; + char post_host_port[5+1]; + char post_url[8192];//BUFSIZE_V2 + char post_username[60]; + char post_password[60]; + char post_content[MAX_IMG_SIZE]; + char post_customized_header[8192]; + + //unsigned char post_content_bin[MAX_HTTP_BUFFER]; + char post_sequence[60]; + + char post_file_format[10 + 1]; + char post_jpeg_file_name_format[10 + 1]; + char post_jpeg_file_name[60]; + + char post_timeout[10]; + + int check_if_delivering; + } PostEventInfo; + + typedef struct + { + char email_content[BUFSIZE_V3]; + //unsigned char email_content_bin[MAX_HTTP_BUFFER]; + } EmailInfo; + + typedef struct { + //int nListIndex; + char counter_name[36 + 1]; + int counter_zone; + char counter_cust_name[256]; + char counter_unit[16 + 1]; + int reset_value; + + int reset_year; + int reset_month; + int reset_month_day; + int reset_week_day; + int reset_hour; + int reset_min; + int reset_sec; + + int gmt_year; + int gmt_month; + int gmt_month_day; + int gmt_week_day; + int gmt_hour; + int gmt_min; + int gmt_sec; + + int next_year; + int next_month; + int next_month_day; + int next_week_day; + int next_hour; + int next_min; + int next_sec; + + char ReportTimeInterval[30]; + char ResetTime[50]; + + int already_reset; + int counter_count; + time_t timetResetAt; + time_t next_timetResetAt; + + char enable_reset_time_interval[10 + 1]; + char reset_time_interval[36 + 1]; + char reset_at[36 + 1]; + + char enable_time_range[10 + 1]; + char time_range_from[36 + 1]; + char time_range_to[36 + 1]; + time_t timetTimeRangeFrom; + time_t timetTimeRangeTo; + + char link_to_post_event_name[256]; + char post_interval[36 + 1]; + + int dwell_time; + char dwell_unit[10 + 1]; + + //char MetaOut1[512][50]; + //int metadata1_num; + + char enable_reset_only_cloud[10 + 1]; + char enable_linked_to_dwell_time[10 + 1]; + time_t last_post_time; + + } EventCounterInfo; + + typedef struct { + char counter_a[20]; + char counter_a_name[50]; + char counter_a_zone[10]; + char counter_b[20]; + char counter_b_name[50]; + char counter_b_zone[10]; + char counter_c_name[50]; + + char report_max_value[20]; + + char enable_report[10]; + + char counter_mode[20]; + + char initial_icon[50]; + char output_icon[50]; + + char detection_output[100]; + + } ReportCounterInfo; + + typedef struct { + char snmp_event_name[256]; + char snmp_version[10]; + char snmp_group_name[256]; + char snmp_host_ip[256]; + char snmp_host_port[10]; + char snmp_oid[256]; + char snmp_value[BUFSIZE]; + char snmp_type[20]; + + int check_if_delivering; + } SNMPManagementInfo; + + //20201027 sophia add + //read from [ipcam /usr/local/bin/nvclient -k user.password0 /usr/local/bin/nvclient -k user.account0 ...9] + //save to config.json account_setting->account_data + typedef struct { + char account_username[256]; + char account_password[256]; + char account_port[50]; + char account_mirror[20]; + char account_flip[20]; + char account_rotate[20]; + char account_aida_port[50]; + int account_type; //default ? + int account_status; //default ? + } AccountDataInfo; + + typedef struct { + //pthread_t thread_id; + SOCKET sock; + int channel_id; + double fps; + //time_t last_recv_time; + //SecData recent_sec_data[FPS_AVG_SECS]; + int isGetAlarmMotion; + //int isFirstAlarmMotion; + int isWebSocketConnect; + int isNvrRequest; + int isCredentialRequest; +#if defined GY_OS_AMBA || defined GY_OS_NOVA + int isUdpSocket; //20201112 sophia add +#endif //GY_OS_AMBA + uchar* prev_frame_data; + //int iIsWebsocketHybi00; +#if defined GY_OS_AMBA + //int iIsAIRelay; +#endif + int debug_type; + + int used; + + } SocketInfo; + + typedef struct { + char curl_url[8192]; + char curl_sendbuf[8192]; + char method[32]; + char username[64]; + char password[64]; + char port[10]; //strtol(q_info->host_port, NULL, 10) + } CURL_SEND; + + typedef struct { + int tof_version; + bool tof_debug; + int tof_install_angle; + bool tof_enable_camera; + bool enable_tof_ground; + bool enable_tof_wall; + + char tof_camera_ip[256]; + char tof_camera_port[10]; + char tof_camera_sub_url[8192]; + char tof_auth_key[8192]; + bool tof_ip_setting; + char tof_camera_username[512]; + char tof_camera_password[512]; + + char distance_options[10]; + char distance_min_max[10]; + char distance_threshold[20]; + char height_options[10]; + char height_min_max[10]; + char height_threshold[20]; + + char ground_x[10]; + char ground_y[10]; + } TofInfo; + + typedef struct { + char enable_heartbeat[10]; + char events_default_version[10]; + char heartbeat_dwell[10]; + char heartbeat_link_to_post_event_name[256]; + + char dwell_to_the_same_location[10]; + + char enable_snmp_heartbeat[10]; + char snmp_heartbeat_dwell[10]; + char snmp_heartbeat_link_to_post_event_name[256]; + + char enable_only_once_to_post[10]; + char enable_obj_once_to_post[10]; + char enable_location_once_to_post[10]; + char enable_nvr_once_to_getalarmmotion[10]; + char enable_8592_once_to_getalarmmotion[10]; + + char heatmap_max[20]; + char enable_heatmap[10]; + char heatmap_frequency[20]; + char lpr_title[256]; + + char enable_counter_snap[10]; + char enable_barcode_qr[10]; + + char enable_check_ptz_start_autotracking[10]; + char enable_check_ptz_end_autotracking[10]; + char ptz_start_autotracking_link_to_post_event_name[256]; + char ptz_end_autotracking_link_to_post_event_name[256]; + } HeartbeatInfo; + + typedef struct { + char sPlateNumber[100]; + time_t t_FirstGetTime; + time_t t_UpdateTime; + time_t t_LoopTime; + + int iGetCounter; + int iIfUse; + + float box_x; + float box_y; + float box_w; + float box_h; + + float last_box_x; + float last_box_y; + float last_box_w; + float last_box_h; + + float last_box_center_x; + float last_box_center_y; + + int iPlateZoomOutCounter; + int iPlateZoomInCounter; + + int iTrackingID; + //int iTrackingIDidx; + + int existing_dash; + + char car_type_name[20]; + int check_if_counted[MAX_DETECTION_ZONE]; + + } PlateRecoder; + + typedef struct { + //char name[30]; + //int class_id; + + time_t t_FirstGetTime; + time_t t_UpdateTime; + + int iGetCounter; + int iIfUse; + + float box_x; + float box_y; + float box_w; + float box_h; + + //float left_x; + //float top_y; + + int iTrackingID; + //int iTrackingIDidx; + + int check_if_counted[MAX_DETECTION_ZONE]; + + } ObjectRecoder; + + typedef struct { + char name[30]; + char sPlateNumber[100]; + + time_t t_FirstGetTime_total; + time_t t_FirstGetTime; + time_t t_UpdateTime; + + int iIfUse; + + float box_x; + float box_y; + float box_w; + float box_h; + + int check_if_post[MAX_DETECTION_ZONE]; + int check_if_cloud; + int check_if_cloud_v2; + int check_if_cloud_record_v2; + int check_if_email; + int check_if_ftp; + int check_if_getalarmmotion; + + int object_id; + int zone_idx; + + //int the_same_id; + + float count_trigger; + + //detection_pos ori_Data; + //int iIsInvisible; + //time_t t_InvisibleStartTime; + //time_t t_InvisibleUpdateTime; + + } PostRecoder; + + + typedef struct { + + int locked; + + int used; + float box_x; + float box_y; + float box_w; + float box_h; + + } MotionAreaInfo; + + typedef struct { + int color_mode;//image.dn.switch //0 auto mode; 1 day mode; 2 night mode; 3 schedule mode + int light_sensor_value;//image.dn.luminosity + int day_to_night_threshold;//image.dn.luminosity.dtn + int night_to_day_threshold;//image.dn.luminosity.ntd + int dwell_sec_in_auto_mode;//image.dn.switch.dwell + int day_to_night_time_of_schedule;//image.dn.schedule.day + int night_to_day_time_of_schedule;//image.dn.schedule.night + + int hour_day_to_night; + int min_day_to_night; + int total_min_day_to_night; + + int hour_night_to_day; + int min_night_to_day; + int total_min_night_to_day; + + int current_day_or_night_mode;//result // day : 1 ; night : 2 + int last_day_or_night_mode; + + int check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED]; + + //int ircut; + //int irledfar; + //int irlednear; + + int iAutoModeSwitchCount; + } ImageDn; + + typedef struct { + int id; + int flag_protected; + int x; + int y; + int w; + int h; + int color; + int size; + int show_sec; + int bg_tran; //0~255 + int outline_sw; //0:off 1:on + char text[256]; + } OSDInfo; + + typedef struct { + int flag_protected; + float speed; + char speed_unit[256]; + float res_width; + float res_height; + float x; + float y; + } SpeedInfo; + + extern char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; + extern unsigned int g_uiWebPythonCurrentBufferIndex; + extern unsigned int g_uiWebPythonLastBufferIndex; + extern unsigned int g_cWebPythonBufferSignal; + extern unsigned int g_cWebPythonDeleteStatus; + extern char g_cWebPythonName[50]; + extern unsigned int g_cWebPythonStatus; + extern unsigned int python_check_webstatus; // } plugin ɥΪ + + extern bool isGYNetReady; + +//===================== +//sophia add 2020/09/24 +#if defined GY_OS_AMBA || defined GY_OS_NOVA + +#include "alm_queue.h" + + typedef struct { + SOCKET sock; + //stALMNode *head; + //stALMNode *tail; + //int iIsWebsockethybi00; + } SocketInfo_ALM; + + //extern SocketInfo_ALM socketRecord_ALM[MAX_CLIENT_SOCKET]; + extern int bHttpServerMainStart; + extern int bPreloadHttpServerMainStart; +#endif //GY_OS_AMBA +//===================== + + extern int g_check_ping_OK; + + extern int g_sdk_version; + + extern int CheckIsExistingSpeed; + + extern SocketInfo socketRecords[MAX_CLIENT_SOCKET]; + extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; + extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; + extern SystemSettingInfo SystemSetting; + extern PostEventInfo postEventList[MAX_POST_EVENTS]; +#ifdef GY_OS_V_SERIES + +#else + extern EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS]; + extern ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS]; + extern SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT]; +#endif + + extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add + extern IPCAMServiceInfo IPCAMService; + extern SnapHDInfo snapHDList[MAX_SNAP_HD_LIST]; + extern WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST]; + extern char WeightFileModeName[35]; + extern EmailInfo emailData; + extern HeartbeatInfo heartbeatData; +#ifdef GY_OS_AMBA + extern TofInfo tofData; +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + extern PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER]; +#endif + extern ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER]; + extern PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE]; + extern PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE]; + + //extern MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA]; + +#if defined GY_OS_AMBA || defined GY_OS_NOVA + extern ImageDn imageDnData; + +#endif + +#ifdef GY_OS_AMBA + + extern OSDInfo OSDData[MAX_SIZE_OSD_ARRAY]; + extern SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY]; +#endif + extern int g_PlateFilterTimes; //Times + extern int g_PlateFilterTime; //Second + extern int g_PlateRecorderFreeTime; //Second +#ifdef GY_OS_AMBA + extern int g_face_frame_uid; +#endif + extern int g_IsRadarDevice; + extern char radar_json_data[4096]; + + extern int unlockingKeyInnoFR_success; + extern int unlockingKeyInnoFR; + + extern int g_IsSDK_3_0; + extern int g_IsToFDevice; + extern int g_IsCustomWeight; + extern int g_IsHelm_without_car; + + extern float g_min_tof_range; + extern int g_min_tof_range_x; + extern int g_min_tof_range_y; + + extern float g_max_tof_range; + extern int g_max_tof_range_x; + extern int g_max_tof_range_y; + + extern int g_bIsSendTofPCD; + extern int g_bIsWritingPCD; + + extern float g_ground_tof_range; + + extern float g_min_tof_degree; + extern float g_min_tof_height; + extern float g_min_tof_distance; + + extern float g_max_tof_degree; + extern float g_max_tof_height; + extern float g_max_tof_distance; + + extern float g_ground_tof_degree; + extern float g_ground_tof_height; + extern float g_ground_tof_distance; + + extern double g_tof_device_height; + + extern int g_ori_yuv_width; + extern int g_ori_yuv_height; + extern int g_ori_half_yuv_width; + extern int g_ori_half_yuv_height; + + //extern int sockNum[4]; + extern zlog_category_t *zc; + extern double begin_clock; + + extern float confidence_limit; + extern int AI_fps; + +#ifdef REBOOT_BY_CPU_GPU_USAGE + extern int CPU_usage_int; + extern int GPU_usage_int; +#endif + + extern char CPU_usage[256]; + extern char GPU_usage[256]; + extern char Buffer_ver[BUFSIZE]; + //extern bool enable_loop_getalarmmotion; + //extern int times_of_enable_loop_getalarmmotion; + extern int g_write_config_file_dirty_flag; + + extern int g_match_mac; + extern char g_mac_address[256]; + + extern int enable_only_show_metadata1; + extern char websocket_alarm[CONTENT_BUFSIZE]; + + extern int g_i_get_cpu_loading; + + //extern CURLM* g_multi_handle; + extern CURL* g_http_handle; + //extern int g_handle_count; + + extern int g_alter_something; + extern int g_count_alter; + + extern long g_image_HD_pasue_time; + extern int g_video_start_HD; + + extern int g_current_max_num_image_buff; + + extern int g_osdTime_sw; + extern long g_osdSysTimeStamp; + extern int g_osdSysTimeZoneInfo; + + extern int check_if_correct_post; + extern int check_if_run_post; + + extern long g_post_SysTimeStamp; + + int run_http_server(char *option, void* _zc, CNNType cnn_type/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, + char *mac_address, char *ip_address, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType); + + //int caculate_ftp_of_each_sockets(SOCKET sock, int *sock_record_idx); +#ifdef GY_OS_NOVA + size_t SetHttpRequest_sock(QueueInfo *q_info, char* sendBuffer, char* method); +#endif + size_t SetHttpRequest(QueueInfo* q_info, char* sendBuffer, char* method); + size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); + void Create_ptz_socket(); + void SetHttpRequest_ptz(char* cgi_url, char* sOutput_data, char* username, char* password); + //void SetHttpRequest_ptz(); + //size_t SetHttpRequest_ptz(QueueInfo *q_info, char* sendBuffer, char* method); + size_t SetHttpResponse_server(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); + void replace_one_line_in_a_file(char *path, int line, char *newline); +#if 0 + void GetAidaPort(); +#endif + void update_enable_only_show_metadata1(int temp_enable_only_show_metadata1); + size_t get_service_from_ipcam(char * response_from_ipcam); + size_t get_control_io_from_ipcam(char * response_from_ipcam); + void copy_ipcam_smtp_service_to_gynet(); + void copy_control_io_to_gynet(); + void sync_other_camera_lpr_db(); + + void *net_curl_https_post_push_info(void *ptr); + void *net_curl_https_post_push_info_attached_image(void *ptr); + + void net_curl_ftp_post_push_info_attached_image(char* image_buff, int image_buff_size); + void net_curl_ftp_build_folder(); +#ifdef GY_OS_AMBA + size_t SetSNMPRequest(QueueInfo *q_info); +#endif + void *net_curl_https_get_other_lpr_db(void *ptr); + + extern char id[512]; + extern char pass[512]; + + extern char strUnlockingKey[MAX_MSG_LEN]; + extern char strLicenseStatus[MAX_MSG_LEN]; + + extern char g_device_name[512]; + + extern int g_IsPTZDevice; + extern int g_check_if_no_brand; + + extern int g_check_if_OK_getfeatures; + extern int g_check_if_OK_thermal; + + void memset_snapshot_addr(); + + void build_one_smart_event(char * myname, char * myvalue); + void build_one_gpio(char * myname, char * myvalue); + + void* auto_build_smart_events(void * ptr); + void* auto_build_smart_events_di_vi(void * ptr); + void build_one_set_for_quality_basic(char * myname, char * myvalue); +#ifdef GY_OS_AMBA + void build_one_set_for_tof_basic(char * myname, char * myvalue); +#endif + void* auto_set_quality_basic(void * ptr); +#ifdef GY_OS_AMBA + void* auto_set_tof_basic(void * ptr); +#endif + + size_t build_resolution_changed(char * response_from_ipcam); + extern pthread_t resolution_changed_thread; + void* auto_resolution_changed(void * ptr); +#ifdef GY_OS_AMBA + void* check_current_resolution(void * ptr); + void set_run_check_current_resolution(int set_value); + int get_run_check_current_resolution(); +#endif + void write_to_stream_width_and_stream_height(int stream_width, int stream_height); + int get_g_check_if_different_width_or_height(); + + void build_reboot(char * myname, char * myvalue); + void ipcam_getfeatures(); + + void* auto_reboot(void * ptr); + + void build_system(char * myname, char * myvalue); + void* auto_system(void * ptr); + + void sync_image_rotation_thread(); + + int is_connection_authorized(char* recvBuffer, SOCKET *client_socket, int isTcpTunnel); + + void import_lpr_list_file(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen); + void *import_lpr_list_file_thread(void *ptr); +#ifdef GY_OS_AMBA + void *import_face_list_file_thread(void *ptr); +#endif + void get_snap_with_profile_id(int i_profileid, int enable_check_profile_id); +#ifdef GY_OS_NOVA + void *pre_connection_handler(void *socket_temp); +#endif + void *thread_getimage(void *ptr); + void *thread_getimage_hd(void *ptr); + +#ifdef GY_OS_NOVA + void *thread_get_nova_driver(void *ptr); +#endif + char *removeHTTPHeader(char *buffer, int *bodySize); + void getPicture(int socketfd, int bSize, int current_profile_id, int enable_check_profile_id); + int get_g_framesize_width(); + int get_g_framesize_height(); + + void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, char* contentBuffer/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType, int* isGetalarmMotion, int sock_info_idx); + +#ifdef GY_OS_AMBA + int get_g_check_if_change_preset(); + void set_g_check_if_change_preset_to_zero(); + void *import_radarbg_thread(void *ptr); + void import_radarbg(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen); +#endif + void update_system_time(); + + int get_g_control_alarm_gpio(); + void set_g_control_alarm_gpio_to_zero(); + void set_g_control_alarm_gpio_to_one(); +#ifdef GY_OS_NOVA + void start_nova_driver(); + void get_nova_driver(int socketfd); +#endif + +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/onvif_data.c b/src/onvif_data.c new file mode 100644 index 0000000..98371fd --- /dev/null +++ b/src/onvif_data.c @@ -0,0 +1,261 @@ + +#include "onvif_data.h" + +extern long g_osdSysTimeStamp; + +int g_record_counter_dwell_time[MAX_EVENT_COUNTERS] = { 0 }; + +void reset_onvif() { + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + g_record_counter_dwell_time[index_counter] = -1; + } +} + +void reset_certain_counter_onvif(int index_counter) { + g_record_counter_dwell_time[index_counter] = -1; +} + +void onvif_replace_type_name(char *oriInTypeName, char *repOutTypeName) +{ + char ori_name[256] = { 0 }; + strcpy(ori_name, oriInTypeName); + UpperToLower(ori_name); + + if (strcmp(ori_name, "car") == 0 || + strcmp(ori_name, "bus") == 0 || + strcmp(ori_name, "truck") == 0 || + strcmp(ori_name, "tuktuk") == 0 || + strcmp(ori_name, "trailer") == 0 || + strcmp(ori_name, "pickup") == 0 || + strcmp(ori_name, "suv") == 0 || + strcmp(ori_name, "dual_headlight") == 0 || + strcmp(ori_name, "single_headlight") == 0 || + strcmp(ori_name, "van") == 0 + ) + { + sprintf(repOutTypeName, "%s", ONVIF_TRAFFIC_TYPE); + } + else if (strcmp(ori_name, "person") == 0) + { + sprintf(repOutTypeName, "%s", ONVIF_HUMAN_TYPE); + } + else if (IsANPRCategory_L_Plate(oriInTypeName) == 1 && strstr(oriInTypeName,"L._Plate_") != NULL) + { + sprintf(repOutTypeName, "%s", ONVIF_PLATE_TYPE); + } + else + { + sprintf(repOutTypeName, "%s", oriInTypeName); + } +} + +void get_utc_time(char *psOutBuf) +{ +#if 1 + time_t rawtime = g_osdSysTimeStamp; + if (rawtime < 1000000000) + { + rawtime = time(0); + } + struct tm * gmtinfo; + gmtinfo = gmtime(&rawtime); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t usecs_time = time_now.tv_usec; + + snprintf(psOutBuf, 256, "%04d-%02d-%02dT%02d:%02d:%02d.%ldZ" + , gmtinfo->tm_year + 1900 + , gmtinfo->tm_mon + 1 + , gmtinfo->tm_mday + , gmtinfo->tm_hour + , gmtinfo->tm_min + , gmtinfo->tm_sec + , usecs_time + ); +#else + struct timespec ts; + struct tm l_current_tm; + clock_gettime(CLOCK_REALTIME, &ts); + gmtime_r(&ts.tv_sec, &l_current_tm); + snprintf(psOutBuf, 256, "%04d-%02d-%02dT%02d:%02d:%02d.%ldZ" + , l_current_tm.tm_year + 1900 + , l_current_tm.tm_mon + 1 + , l_current_tm.tm_mday + , l_current_tm.tm_hour + , l_current_tm.tm_min + , l_current_tm.tm_sec + , ts.tv_nsec / 1000L + ); +#endif + + //printf("\n--------psOutBuf:%s\n", psOutBuf); +} + +void create_onvif_packet(UNIX_MESSAGE_V1_T *Inl_unix_msg, onvif_data *InOnvifObj, int InOnvifobjNum, onvif_counter_info * InOnvifCounter) +{ + char onvifTime[256] = { 0 }; + get_utc_time(onvifTime); + + //printf("\n-------onvifTime:%s\n", onvifTime); + + //if (InOnvifobjNum <= 0) + //{ + //sprintf(Inl_unix_msg->buf, ONVIF_FRAME_DATA_START, onvifTime); + //strcat(Inl_unix_msg->buf, ONVIF_FRAME_DATA_END); + //} + //else + { + sprintf(Inl_unix_msg->buf, ONVIF_FRAME_DATA_START, onvifTime); + char tempOBJbuf[8192] = { 0 }; + + for (int i = 0; i < InOnvifobjNum; i++) + { + char sTypeName[256] = { 0 }; + onvif_replace_type_name(InOnvifObj[i].TypeName, sTypeName); + + unsigned int trigger_event_type = InOnvifObj[i].behavior_id; + + if ((trigger_event_type & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION || + (trigger_event_type & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION //|| + //(trigger_event_type & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION || + //(trigger_event_type & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED + ) + { + if (strcmp(sTypeName, ONVIF_PLATE_TYPE) == 0) + { + sprintf(tempOBJbuf, ONVIF_PLATE_CONTENT, InOnvifObj[i].iObjectID, InOnvifObj[i].left_x, InOnvifObj[i].top_y, InOnvifObj[i].right_x, InOnvifObj[i].bottom_y, InOnvifObj[i].center_x, InOnvifObj[i].center_y, InOnvifObj[i].Likelihood, InOnvifObj[i].sPlateNumber, 1.0, InOnvifObj[i].sPlateType, 1.0, InOnvifObj[i].sCountryCode, 1.0, InOnvifObj[i].sIssuingEntity); + strcat(Inl_unix_msg->buf, tempOBJbuf); + memset(tempOBJbuf, 0x00, 8192); + } + else + { + sprintf(tempOBJbuf, ONVIF_OBJ_CONTENT, InOnvifObj[i].iObjectID, InOnvifObj[i].left_x, InOnvifObj[i].top_y, InOnvifObj[i].right_x, InOnvifObj[i].bottom_y, InOnvifObj[i].center_x, InOnvifObj[i].center_y, sTypeName, InOnvifObj[i].Likelihood, InOnvifObj[i].Likelihood, sTypeName); + strcat(Inl_unix_msg->buf, tempOBJbuf); + memset(tempOBJbuf, 0x00, 8192); + } + } + + if ((trigger_event_type & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) + { + sprintf(tempOBJbuf, ONVIF_OBJECT_DETECTION_PARKING, sTypeName, sTypeName); + strcat(Inl_unix_msg->buf, tempOBJbuf); + memset(tempOBJbuf, 0x00, 8192); + } + + if ((trigger_event_type & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) + { + sprintf(tempOBJbuf, ONVIF_OBJECT_DETECTION_PROHIBIT, sTypeName, sTypeName); + strcat(Inl_unix_msg->buf, tempOBJbuf); + memset(tempOBJbuf, 0x00, 8192); + } + + //AI򥢪 + //if ((trigger_event_type & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { + + //strcat(Inl_unix_msg->buf, tempOBJbuf); + //memset(tempOBJbuf, 0x00, 8192); + //} + + //򥢪οd + //if ((trigger_event_type & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { + + //strcat(Inl_unix_msg->buf, tempOBJbuf); + //memset(tempOBJbuf, 0x00, 8192); + //} + } + +#ifdef GY_OS_V_SERIES + +#else + for (int i = 0; i < MAX_EVENT_COUNTERS; i++) + { + if (g_record_counter_dwell_time[i] == -1 || + (g_record_counter_dwell_time[i] != InOnvifCounter[i].dwell_time)) { + unsigned int trigger_event_type = InOnvifCounter[i].onvif_detect_event_id; + + if ((trigger_event_type & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { + int forward_line = InOnvifCounter[i].forward_line; + if (forward_line >= 1 && forward_line <= 4) { + float x_start = 0.0; + float y_start = 0.0; + float x_end = 0.0; + float y_end = 0.0; + + if (forward_line == 1) { + x_start = InOnvifCounter[i].onvif_Points[0].x; + y_start = InOnvifCounter[i].onvif_Points[0].y; + x_end = InOnvifCounter[i].onvif_Points[1].x; + y_end = InOnvifCounter[i].onvif_Points[1].y; + } + else if (forward_line == 2) { + x_start = InOnvifCounter[i].onvif_Points[1].x; + y_start = InOnvifCounter[i].onvif_Points[1].y; + x_end = InOnvifCounter[i].onvif_Points[2].x; + y_end = InOnvifCounter[i].onvif_Points[2].y; + } + else if (forward_line == 3) { + x_start = InOnvifCounter[i].onvif_Points[2].x; + y_start = InOnvifCounter[i].onvif_Points[2].y; + x_end = InOnvifCounter[i].onvif_Points[3].x; + y_end = InOnvifCounter[i].onvif_Points[3].y; + } + else if (forward_line == 4) { + x_start = InOnvifCounter[i].onvif_Points[3].x; + y_start = InOnvifCounter[i].onvif_Points[3].y; + x_end = InOnvifCounter[i].onvif_Points[0].x; + y_end = InOnvifCounter[i].onvif_Points[0].y; + } + + sprintf(tempOBJbuf, ONVIF_LINE_CROSSING_COUNT, + InOnvifCounter[i].onvif_ReportTimeInterval, + InOnvifCounter[i].onvif_ResetTime, + InOnvifCounter[i].onvif_Direction, + InOnvifCounter[i].onvif_PassAllPolylines, + x_start, + y_start, + x_end, + y_end, + InOnvifCounter[i].counter_count); + + //printf("\n-----%s\n", tempOBJbuf); + + strcat(Inl_unix_msg->buf, tempOBJbuf); + memset(tempOBJbuf, 0x00, 8192); + } + } + + if ((trigger_event_type & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { + sprintf(tempOBJbuf, ONVIF_OCCUPANCY_COUNTING, + InOnvifCounter[i].onvif_ReportTimeInterval, + InOnvifCounter[i].onvif_ResetTime, + InOnvifCounter[i].onvif_Points[0].x, + InOnvifCounter[i].onvif_Points[0].y, + InOnvifCounter[i].onvif_Points[1].x, + InOnvifCounter[i].onvif_Points[1].y, + InOnvifCounter[i].onvif_Points[2].x, + InOnvifCounter[i].onvif_Points[2].y, + InOnvifCounter[i].onvif_Points[3].x, + InOnvifCounter[i].onvif_Points[3].y, + InOnvifCounter[i].onvif_Points[4].x, + InOnvifCounter[i].onvif_Points[4].y, + InOnvifCounter[i].onvif_Points[5].x, + InOnvifCounter[i].onvif_Points[5].y, + InOnvifCounter[i].counter_count); + + //printf("\n-----%s\n", tempOBJbuf); + + strcat(Inl_unix_msg->buf, tempOBJbuf); + memset(tempOBJbuf, 0x00, 8192); + } + + g_record_counter_dwell_time[i] = InOnvifCounter[i].dwell_time; + } + } +#endif + + strcat(Inl_unix_msg->buf, ONVIF_FRAME_DATA_END); + + //printf("\n--------Inl_unix_msg->buf:%s\n", Inl_unix_msg->buf); + } +} \ No newline at end of file diff --git a/src/onvif_data.h b/src/onvif_data.h new file mode 100644 index 0000000..43c84e7 --- /dev/null +++ b/src/onvif_data.h @@ -0,0 +1,85 @@ +#if 1 +#pragma once +#ifndef ONVIF_DATA_H +#define ONVIF_DATA_H +#include "define_inc.h" +#include <time.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <sys/prctl.h> +#include <pthread.h> +#include <sys/time.h> +#include <arpa/inet.h> +#include <sys/types.h> +#include <sys/select.h> +#include <sys/socket.h> +#include <netinet/in.h> + +#include <sys/sendfile.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/un.h> + +#include <netinet/in.h> + +#include "utility.h" +#include "nweb.h" +#include "alm_queue.h" + +#define UNIX_MESSAGE_V1 "UMV01" +#define UNIX_MESSAGE_V2 "UMV02" + +#define ONVIF_FRAME_DATA_START "<?xml version=\"1.0\" encoding=\"UTF-8\"?><tt:MetadataStream xmlns:tt=\"http://www.onvif.org/ver10/schema\"><tt:VideoAnalytics><tt:Frame UtcTime=\"%s\" Source=\"AnalyticsSceneDescription\">" + +#define ONVIF_FRAME_DATA_END "</tt:Frame></tt:VideoAnalytics></tt:MetadataStream>" + +#define ONVIF_OBJ_CONTENT "<tt:Object ObjectId=\"%d\"><tt:Appearance><tt:Shape><tt:BoundingBox left=\"%f\" top=\"%f\" right=\"%f\" bottom=\"%f\"/><tt:CenterOfGravity x=\"%f\" y=\"%f\"/></tt:Shape><tt:Class><tt:ClassCandidate><tt:Type>%s</tt:Type><tt:Likelihood>%f</tt:Likelihood></tt:ClassCandidate><tt:Type Likelihood=\"%f\">%s</tt:Type></tt:Class></tt:Appearance></tt:Object>" +#define ONVIF_PLATE_CONTENT "<tt:Object ObjectId=\"%d\"><tt:Appearance><tt:Shape><tt:BoundingBox left=\"%f\" top=\"%f\" right=\"%f\" bottom=\"%f\"/><tt:CenterOfGravity x=\"%f\" y=\"%f\"/></tt:Shape><tt:LicensePlateInfo><tt:PlateNumber Likelihood=\"%f\">%s</tt:PlateNumber><tt:PlateType Likelihood=\"%f\">%s</tt:PlateType><tt:CountryCode Likelihood=\"%f\">%s</tt:CountryCode><tt:IssuingEntity Likelihood=\"%f\">%s</tt:IssuingEntity></tt:LicensePlateInfo></tt:Appearance></tt:Object>" +#define ONVIF_LINE_CROSSING_COUNT "<tt:Rule Name=\"LineCounting\"><tt:Parameters><tt:SimpleItem Name=\"ReportTimeInterval\" Value=\"%s\"/><tt:SimpleItem Name=\"ResetTime\" Value=\"%s\"/><tt:SimpleItem Name=\"Direction\" Value=\"%s\"/><tt:SimpleItem Name=\"PassAllPolylines\" Value=\"%s\"/><tt:ElementItem Name=\"Segments\"><tt:Polyline><tt:Point x=\"%f\" y=\"%f\"/><tt:Point x=\"%f\" y=\"%f\"/></tt:Polyline></tt:ElementItem></tt:Parameters><tt:Messages IsProperty=\"true\"><tt:Source><tt:SimpleItem Name=\"VideoSource\" Value=\"0\"/><tt:SimpleItem Name=\"AnalyticsConfiguration\" Value=\"0\"/><tt:SimpleItem Name=\"Rule\" Value=\"Tripwire\"/></tt:Source><tt:Data><tt:SimpleItem Name=\"Count\" Value=\"%d\"/></tt:Data><tt:ParentTopic>tns1:RuleEngine/CountAggregation/Counter</tt:ParentTopic></tt:Messages></tt:Rule>" +#define ONVIF_OCCUPANCY_COUNTING "<tt:Rule Name=\"OccupancyCounting\"><tt:Parameters><tt:SimpleItem Name=\"ReportTimeInterval\" Value=\"%s\"/><tt:SimpleItem Name=\"ResetTime\" Value=\"%s\"/><tt:ElementItem Name=\"Segments\"><tt:Polyline><tt:Point x=\"%f\" y=\"%f\"/><tt:Point x=\"%f\" y=\"%f\"/><tt:Point x=\"%f\" y=\"%f\"/><tt:Point x=\"%f\" y=\"%f\"/><tt:Point x=\"%f\" y=\"%f\"/><tt:Point x=\"%f\" y=\"%f\"/></tt:Polyline></tt:ElementItem></tt:Parameters><tt:Messages IsProperty=\"true\"><tt:Source><tt:SimpleItem Name=\"VideoSource\" Value=\"0\"/><tt:SimpleItem Name=\"AnalyticsConfiguration\" Value=\"0\"/><tt:SimpleItem Name=\"Rule\" Value=\"Density\"/></tt:Source><tt:Data><tt:SimpleItem Name=\"Count\" Value=\"%d\"/></tt:Data><tt:ParentTopic>tns1:RuleEngine/CountAggregation/OccupancyCounter</tt:ParentTopic></tt:Messages></tt:Rule>" +#define ONVIF_OBJECT_DETECTION_PROHIBIT "<tt:Rule Name=\"ObjectDetection\"><tt:Parameters><tt:SimpleItem Name=\"ClassFilter\" Value=\"%s\"/></tt:Parameters><tt:Messages><tt:Source><tt:SimpleItem Name=\"VideoSource\" Value=\"0\"/><tt:SimpleItem Name=\"AnalyticsConfiguration\" Value=\"0\"/><tt:SimpleItem Name=\"Rule\" Value=\"Prohibit\"/></tt:Source><tt:Data><tt:SimpleItem Name=\"ClassTypes\" Value=\"%s\"/></tt:Data><tt:ParentTopic>tns1:RuleEngine/ObjectDetection/Object</tt:ParentTopic></tt:Messages></tt:Rule>" +#define ONVIF_OBJECT_DETECTION_PARKING "<tt:Rule Name=\"ObjectDetection\"><tt:Parameters><tt:SimpleItem Name=\"ClassFilter\" Value=\"%s\"/></tt:Parameters><tt:Messages><tt:Source><tt:SimpleItem Name=\"VideoSource\" Value=\"0\"/><tt:SimpleItem Name=\"AnalyticsConfiguration\" Value=\"0\"/><tt:SimpleItem Name=\"Rule\" Value=\"Parking\"/></tt:Source><tt:Data><tt:SimpleItem Name=\"ClassTypes\" Value=\"%s\"/></tt:Data><tt:ParentTopic>tns1:RuleEngine/ObjectDetection/Object</tt:ParentTopic></tt:Messages></tt:Rule>" + +#define ONVIF_TRAFFIC_TYPE "Vehicle" +#define ONVIF_HUMAN_TYPE "Human" +#define ONVIF_PLATE_TYPE "LicensePlate" + +#define UNIX_MESSAGE "/tmp/udp_unix" + +enum +{ + UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0, + UNIX_MESSAGE_TYPE_POST_CLOUD, + UNIX_MESSAGE_TYPE_POST_RECORD_CLOUD, + UNIX_MESSAGE_TYPE_RTSP_META, + UNIX_MESSAGE_TYPE_ONVIF_EVENT +}; + +enum +{ + UNIX_MESSAGE_V2_PACKET_TYPE_START = 0, + UNIX_MESSAGE_V2_PACKET_TYPE_BODY, + UNIX_MESSAGE_V2_PACKET_TYPE_END +}; + +typedef struct UNIX_MESSAGE_V1_S +{ + unsigned int type; + unsigned int length; + char buf[40960]; + +} UNIX_MESSAGE_V1_T; + +void onvif_replace_type_name(char *oriInTypeName, char *repOutTypeName); +void get_utc_time(char *psOutpuBuf); +void create_onvif_packet(UNIX_MESSAGE_V1_T *Inl_unix_msg, onvif_data *InOnvifObj, int InOnvifobjNum, onvif_counter_info * InOnvifCounter); +void reset_onvif(); +void reset_certain_counter_onvif(int index_counter); + +#endif + +#endif \ No newline at end of file diff --git a/src/opencv/cv.h b/src/opencv/cv.h new file mode 100644 index 0000000..19a74e2 --- /dev/null +++ b/src/opencv/cv.h @@ -0,0 +1,73 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CV_H +#define OPENCV_OLD_CV_H + +#if defined(_MSC_VER) + #define CV_DO_PRAGMA(x) __pragma(x) + #define __CVSTR2__(x) #x + #define __CVSTR1__(x) __CVSTR2__(x) + #define __CVMSVCLOC__ __FILE__ "("__CVSTR1__(__LINE__)") : " + #define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (__CVMSVCLOC__ _msg)) +#elif defined(__GNUC__) + #define CV_DO_PRAGMA(x) _Pragma (#x) + #define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (_msg)) +#else + #define CV_DO_PRAGMA(x) + #define CV_MSG_PRAGMA(_msg) +#endif +#define CV_WARNING(x) CV_MSG_PRAGMA("Warning: " #x) + +//CV_WARNING("This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module") + +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" +#include "opencv2/objdetect/objdetect_c.h" + +#if !defined(CV_IMPL) +#define CV_IMPL extern "C" +#endif //CV_IMPL + +#endif // __OPENCV_OLD_CV_H_ diff --git a/src/opencv/cv.hpp b/src/opencv/cv.hpp new file mode 100644 index 0000000..8673956 --- /dev/null +++ b/src/opencv/cv.hpp @@ -0,0 +1,60 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CV_HPP +#define OPENCV_OLD_CV_HPP + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "cv.h" +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/photo.hpp" +#include "opencv2/video.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/calib3d.hpp" +#include "opencv2/objdetect.hpp" + +#endif diff --git a/src/opencv/cvaux.h b/src/opencv/cvaux.h new file mode 100644 index 0000000..c0367cc --- /dev/null +++ b/src/opencv/cvaux.h @@ -0,0 +1,57 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_AUX_H +#define OPENCV_OLD_AUX_H + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" +#include "opencv2/objdetect/objdetect_c.h" + +#endif + +/* End of file. */ diff --git a/src/opencv/cvaux.hpp b/src/opencv/cvaux.hpp new file mode 100644 index 0000000..7365b72 --- /dev/null +++ b/src/opencv/cvaux.hpp @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_AUX_HPP +#define OPENCV_OLD_AUX_HPP + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "cvaux.h" +#include "opencv2/core/utility.h" + +#endif diff --git a/src/opencv/cvwimage.h b/src/opencv/cvwimage.h new file mode 100644 index 0000000..ec0ab14 --- /dev/null +++ b/src/opencv/cvwimage.h @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////////// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2008, Google, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation or contributors may not 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 the Intel Corporation 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. + + +#ifndef OPENCV_OLD_WIMAGE_HPP +#define OPENCV_OLD_WIMAGE_HPP + +#include "opencv2/core/wimage.hpp" + +#endif diff --git a/src/opencv/cxcore.h b/src/opencv/cxcore.h new file mode 100644 index 0000000..dc070c7 --- /dev/null +++ b/src/opencv/cxcore.h @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CXCORE_H +#define OPENCV_OLD_CXCORE_H + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "opencv2/core/core_c.h" + +#endif diff --git a/src/opencv/cxcore.hpp b/src/opencv/cxcore.hpp new file mode 100644 index 0000000..c371677 --- /dev/null +++ b/src/opencv/cxcore.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_CXCORE_HPP +#define OPENCV_OLD_CXCORE_HPP + +//#if defined(__GNUC__) +//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" +//#endif + +#include "cxcore.h" +#include "opencv2/core.hpp" + +#endif diff --git a/src/opencv/cxeigen.hpp b/src/opencv/cxeigen.hpp new file mode 100644 index 0000000..1d3df91 --- /dev/null +++ b/src/opencv/cxeigen.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_EIGEN_HPP +#define OPENCV_OLD_EIGEN_HPP + +#include "opencv2/core/eigen.hpp" + +#endif diff --git a/src/opencv/cxmisc.h b/src/opencv/cxmisc.h new file mode 100644 index 0000000..f6026e9 --- /dev/null +++ b/src/opencv/cxmisc.h @@ -0,0 +1,8 @@ +#ifndef OPENCV_OLD_CXMISC_H +#define OPENCV_OLD_CXMISC_H + +#ifdef __cplusplus +# include "opencv2/core/utility.h" +#endif + +#endif diff --git a/src/opencv/highgui.h b/src/opencv/highgui.h new file mode 100644 index 0000000..69b394e --- /dev/null +++ b/src/opencv/highgui.h @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_HIGHGUI_H +#define OPENCV_OLD_HIGHGUI_H + +#include "opencv2/core/core_c.h" +#include "opencv2/highgui/highgui_c.h" + +#endif diff --git a/src/opencv/ml.h b/src/opencv/ml.h new file mode 100644 index 0000000..0c376ba --- /dev/null +++ b/src/opencv/ml.h @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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. +// +// +// Intel License Agreement +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of Intel Corporation may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_OLD_ML_H +#define OPENCV_OLD_ML_H + +#include "opencv2/core/core_c.h" +#include "opencv2/ml.hpp" + +#endif diff --git a/src/opencv2/opencv.hpp b/src/opencv2/opencv.hpp new file mode 100644 index 0000000..4048158 --- /dev/null +++ b/src/opencv2/opencv.hpp @@ -0,0 +1,139 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's 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. +// +// * The name of the copyright holders may not 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 the Intel Corporation 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. +// +//M*/ + +#ifndef OPENCV_ALL_HPP +#define OPENCV_ALL_HPP + +// File that defines what modules where included during the build of OpenCV +// These are purely the defines of the correct HAVE_OPENCV_modulename values +#include "opencv2/opencv_modules.hpp" + +// Then the list of defines is checked to include the correct headers +// Core library is always included --> without no OpenCV functionality available +#include "opencv2/core.hpp" + +// Then the optional modules are checked +#ifdef HAVE_OPENCV_CALIB3D +#include "opencv2/calib3d.hpp" +#endif +#ifdef HAVE_OPENCV_FEATURES2D +#include "opencv2/features2d.hpp" +#endif +#ifdef HAVE_OPENCV_DNN +#include "opencv2/dnn.hpp" +#endif +#ifdef HAVE_OPENCV_FLANN +#include "opencv2/flann.hpp" +#endif +#ifdef HAVE_OPENCV_HIGHGUI +#include "opencv2/highgui.hpp" +#endif +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_IMGPROC +#include "opencv2/imgproc.hpp" +#endif +#ifdef HAVE_OPENCV_ML +#include "opencv2/ml.hpp" +#endif +#ifdef HAVE_OPENCV_OBJDETECT +#include "opencv2/objdetect.hpp" +#endif +#ifdef HAVE_OPENCV_PHOTO +#include "opencv2/photo.hpp" +#endif +#ifdef HAVE_OPENCV_SHAPE +#include "opencv2/shape.hpp" +#endif +#ifdef HAVE_OPENCV_STITCHING +#include "opencv2/stitching.hpp" +#endif +#ifdef HAVE_OPENCV_SUPERRES +#include "opencv2/superres.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEO +#include "opencv2/video.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOSTAB +#include "opencv2/videostab.hpp" +#endif +#ifdef HAVE_OPENCV_VIZ +#include "opencv2/viz.hpp" +#endif + +// Finally CUDA specific entries are checked and added +#ifdef HAVE_OPENCV_CUDAARITHM +#include "opencv2/cudaarithm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDABGSEGM +#include "opencv2/cudabgsegm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDACODEC +#include "opencv2/cudacodec.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFEATURES2D +#include "opencv2/cudafeatures2d.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFILTERS +#include "opencv2/cudafilters.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAIMGPROC +#include "opencv2/cudaimgproc.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOBJDETECT +#include "opencv2/cudaobjdetect.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOPTFLOW +#include "opencv2/cudaoptflow.hpp" +#endif +#ifdef HAVE_OPENCV_CUDASTEREO +#include "opencv2/cudastereo.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAWARPING +#include "opencv2/cudawarping.hpp" +#endif + +#endif diff --git a/src/option_list.c b/src/option_list.c new file mode 100644 index 0000000..eccd4f6 --- /dev/null +++ b/src/option_list.c @@ -0,0 +1,147 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "option_list.h" +#include "utils.h" +#include "box.h" + +list *read_data_cfg(char *filename) +{ + FILE *file = fopen(filename, "r"); + if(file == 0) file_error(filename); + char *line; + int nu = 0; + list *options = make_list(); + while((line=fgetl(file)) != 0){ + ++ nu; + strip(line); + switch(line[0]){ + case '\0': + case '#': + case ';': + if (line) { + free(line); + line = NULL; + } + break; + default: + if(!read_option(line, options)){ + fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line); + if (line) { + free(line); + line = NULL; + } + } + break; + } + } + fclose(file); + return options; +} + +metadata get_metadata(char *file) +{ + metadata m = {0}; + list *options = read_data_cfg(file); + + char *name_list = option_find_str(options, "names", 0); + if(!name_list) name_list = option_find_str(options, "labels", 0); + if(!name_list) { + fprintf(stderr, "No names or labels found\n"); + } else { + m.names = get_labels(name_list); + } + m.classes = option_find_int(options, "classes", 2); + free_list(options); + return m; +} + +int read_option(char *s, list *options) +{ + size_t i; + size_t len = strlen(s); + char *val = 0; + for(i = 0; i < len; ++i){ + if(s[i] == '='){ + s[i] = '\0'; + val = s+i+1; + break; + } + } + if(i == len-1) return 0; + char *key = s; + option_insert(options, key, val); + return 1; +} + +void option_insert(list *l, char *key, char *val) +{ + kvp *p = malloc(sizeof(kvp)); + p->key = key; + p->val = val; + p->used = 0; + list_insert(l, p); +} + +void option_unused(list *l) +{ + node *n = l->front; + while(n){ + kvp *p = (kvp *)n->val; + if(!p->used){ + fprintf(stderr, "Unused field: '%s = %s'\n", p->key, p->val); + } + n = n->next; + } +} + +char *option_find(list *l, char *key) +{ + node *n = l->front; + while(n){ + kvp *p = (kvp *)n->val; + if(strcmp(p->key, key) == 0){ + p->used = 1; + return p->val; + } + n = n->next; + } + return 0; +} +char *option_find_str(list *l, char *key, char *def) +{ + char *v = option_find(l, key); + if(v) return v; + if(def) fprintf(stderr, "%s: Using default '%s'\n", key, def); + return def; +} + +int option_find_int(list *l, char *key, int def) +{ + char *v = option_find(l, key); + if(v) return atoi(v); + fprintf(stderr, "%s: Using default '%d'\n", key, def); + return def; +} + +int option_find_int_quiet(list *l, char *key, int def) +{ + char *v = option_find(l, key); + if(v) return atoi(v); + return def; +} + +float option_find_float_quiet(list *l, char *key, float def) +{ + char *v = option_find(l, key); + if(v) return atof(v); + return def; +} + +float option_find_float(list *l, char *key, float def) +{ + char *v = option_find(l, key); + if(v) return atof(v); + fprintf(stderr, "%s: Using default '%lf'\n", key, def); + return def; +} diff --git a/src/option_list.h b/src/option_list.h new file mode 100644 index 0000000..769fe98 --- /dev/null +++ b/src/option_list.h @@ -0,0 +1,41 @@ +#pragma once +#ifndef OPTION_LIST_H +#define OPTION_LIST_H +#include "define_inc.h" +#include "list.h" + +#ifdef YOLODLL_EXPORTS +#if defined(_MSC_VER) +#define YOLODLL_API __declspec(dllexport) +#else +#define YOLODLL_API __attribute__((visibility("default"))) +#endif +#else +#if defined(_MSC_VER) +#define YOLODLL_API +#else +#define YOLODLL_API +#endif +#endif + +typedef struct{ + char *key; + char *val; + int used; +} kvp; + +int read_option(char *s, list *options); +void option_insert(list *l, char *key, char *val); +char *option_find(list *l, char *key); +float option_find_float(list *l, char *key, float def); +float option_find_float_quiet(list *l, char *key, float def); +void option_unused(list *l); + +typedef struct { + int classes; + char **names; +} metadata; + +YOLODLL_API metadata get_metadata(char *file); + +#endif diff --git a/src/parking_method.cpp b/src/parking_method.cpp new file mode 100644 index 0000000..7274c7e --- /dev/null +++ b/src/parking_method.cpp @@ -0,0 +1,123 @@ + +#include <opencv2/opencv.hpp> +#include <opencv2/video.hpp> + +#include "parking_method.h" +#include "utility.h" +#include <sys/time.h> +#include <iostream> +#include <random> + +using namespace cv; +using namespace std; + +// Hc +struct VehicleInfo { + Rect bbox; + time_t firstSeen; // ɶ + time_t lastSeen; // ̫@sɶ + int isParked; // O_w +}; + +vector<vector<VehicleInfo>> putting_vehicles(MAX_DETECTION_ZONE); + +// WɲMzɶH (10sNMz) +const int timeoutThreshold = 10; + +// time_t now = time(0); +void push_back_to_track_vehicle(detection_pos* pNext, int detection_zone_idx) { + + if (putting_vehicles[detection_zone_idx].size() < MAX_QUEUE_VEHICLEINFO_SIZE) + { + VehicleInfo newVehicle; + newVehicle.bbox.x = pNext->left_x; + newVehicle.bbox.y = pNext->top_y; + newVehicle.bbox.width = pNext->width; + newVehicle.bbox.height = pNext->height; + + time_t current_time = time(0); + newVehicle.firstSeen = current_time; + newVehicle.lastSeen = current_time; + + newVehicle.isParked = 0; + + putting_vehicles[detection_zone_idx].push_back(newVehicle); + } +} + +void pop_not_to_track_vehicles(int detection_zone_idx, time_t current_time) { + // for jˬdO_ݭnM + if (putting_vehicles[detection_zone_idx].size() >= 1) { + for (int j = putting_vehicles[detection_zone_idx].size() - 1; j >= 0; --j) { // q᩹eMAקKRɼvT + double unseenDuration = difftime(current_time, putting_vehicles[detection_zone_idx][j].lastSeen); + if (unseenDuration > timeoutThreshold) + { + putting_vehicles[detection_zone_idx].erase(putting_vehicles[detection_zone_idx].begin() + j); // RŦX󪺨 + } + } + if (putting_vehicles[detection_zone_idx].empty()) { + putting_vehicles[detection_zone_idx].clear(); // MҦ + putting_vehicles[detection_zone_idx].shrink_to_fit(); // 񥼨ϥΪO + } + } +} + +void clear_putting_vehicles() { + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + putting_vehicles[i].clear(); // MҦ + putting_vehicles[i].shrink_to_fit(); // 񥼨ϥΪO + } + putting_vehicles.clear(); +} + +int isVehicleStatic(const Rect& prev_bbox, const Rect& curr_bbox, int threshold = 8) { + int deltaX = abs((prev_bbox.x + prev_bbox.width / 2) - (curr_bbox.x + curr_bbox.width / 2)); + int deltaY = abs((prev_bbox.y + prev_bbox.height / 2) - (curr_bbox.y + curr_bbox.height / 2)); + + // ˬdשMe׬O_b@wd + int deltaWidth = abs(prev_bbox.width - curr_bbox.width); + int deltaHeight = abs(prev_bbox.height - curr_bbox.height); + + if (deltaX <= threshold && deltaY <= threshold && deltaWidth <= threshold * 2 && deltaHeight <= threshold * 2) + return 1; + else + return 0; +} + +int check_vehicle_over_time(detection_pos* pNext,int detection_zone_idx,double parkingTimeThreshold) { + int check_if_over_time = 0; + if (pNext->center_stability == (float)DIRECTION_DEFAULT) + { + int foundMatch = 0; + time_t current_time = time(0); + + Rect bbox(pNext->left_x, pNext->top_y, pNext->width, pNext->height); + // զbwlܪۦm + for (auto& vInfo : putting_vehicles[detection_zone_idx]) { + // pGmۦAhsӨH + if (isVehicleStatic(vInfo.bbox, bbox)) { + foundMatch = 1; + double duration = difftime(current_time, vInfo.firstSeen); + + // P_O_ + if (duration > parkingTimeThreshold) { + vInfo.isParked = 1; + check_if_over_time = 1; + } + + // sةM̫@ݨ쪺ɶ + vInfo.bbox = bbox; + vInfo.lastSeen = current_time; + break; + } + } + + // pGSǰtAsWoӨlܲM + if (!foundMatch) { + push_back_to_track_vehicle(pNext, detection_zone_idx); + } + } + return check_if_over_time; +} + + diff --git a/src/parking_method.h b/src/parking_method.h new file mode 100644 index 0000000..0ff4417 --- /dev/null +++ b/src/parking_method.h @@ -0,0 +1,37 @@ + +#if 1 +#pragma once +#ifndef IVSC_H_ +#define IVSC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "define_inc.h" +#include "opencv2/highgui/highgui_c.h" +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" +#include "test_nnctrl_live.h" +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <pthread.h> +#include "nweb.h" +#include "utility.h" + +#define MAX_QUEUE_VEHICLEINFO_SIZE 128 + +int isVehicleStatic(detection_pos* pNext); +int check_vehicle_over_time(detection_pos* pNext, int detection_zone_idx, double parkingTimeThreshold); +void clear_putting_vehicles(); + +void push_back_to_track_vehicle(detection_pos* pNext, int detection_zone_idx); +void pop_not_to_track_vehicles(int detection_zone_idx, time_t current_time); + +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..0c49218 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,1799 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <assert.h> + +#include "activation_layer.h" +#include "logistic_layer.h" +#include "l2norm_layer.h" +#include "activations.h" +#include "avgpool_layer.h" +#include "batchnorm_layer.h" +#include "blas.h" +#include "connected_layer.h" +#include "deconvolutional_layer.h" +#include "convolutional_layer.h" +#include "cost_layer.h" +#include "crnn_layer.h" +#include "crop_layer.h" +#include "detection_layer.h" +#include "dropout_layer.h" +#include "gru_layer.h" +#include "list.h" +#include "local_layer.h" +#include "maxpool_layer.h" +#include "normalization_layer.h" +#include "option_list.h" +#include "parser.h" +#include "region_layer.h" +#include "yolo_layer.h" +#include "iseg_layer.h" +#include "reorg_layer.h" +#include "rnn_layer.h" +#include "route_layer.h" +#include "upsample_layer.h" +#include "shortcut_layer.h" +#include "softmax_layer.h" +#include "lstm_layer.h" +#include "utils.h" + +#include "cryptionPlus.h" +#include "test_nnctrl_live.h" +#include "structures.h" + +#include "setting.h" + +/* +#ifdef GY_OS_AMBA +typedef unsigned long long int uint64_t; +#endif*/ + +typedef struct{ + char *type; + list *options; +}section; + +list *read_cfg(char *filename); + +list *read_cfg_mem(char *filename, char* dataset_version) +{ + KeyExpansion(key, expandedKey); + char DecryptFileData[MAX_SMALL_FILE_SIZE] = { 0 }; + /*size_t descrypt_size = */AESDecryptFileToArray(filename, expandedKey, DecryptFileData, sizeof(DecryptFileData)); + + //printf("DecryptFileData=%s\n", DecryptFileData); + + char *token; + char *line; + int nu = 0; + list *sections = make_list(); + section *current = 0; + char delim[] = "\n"; + char *pLeft = NULL; + + token = strtok_modified(DecryptFileData, delim, &pLeft); + + //while ((line = fgetl(file)) != 0) + while (token != NULL) + { + line = malloc(strlen(token) + 1); + strcpy(line, token); + ++nu; + strip(line); + switch (line[0]) { + case '[': + current = malloc(sizeof(section)); + list_insert(sections, current); + current->options = make_list(); + current->type = line; + break; + case '#': + if (strncmp(line, "#Version=", strlen("#Version=")) == 0) + { + strcpy(dataset_version, line + strlen("#Version=")); + if (line) { + free(line); + line = NULL; + } + } + else + if (line) { + free(line); + line = NULL; + } + break; + case '\0': + case ';': + if (line) { + free(line); + line = NULL; + } + break; + default: + if (!read_option(line, current->options)) { + fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line); + if (line) { + free(line); + line = NULL; + } + } + break; + } + token = strtok_modified(NULL, delim, &pLeft); + } + //fclose(file); + return sections; +} + +LAYER_TYPE string_to_layer_type(char * type) +{ + + if (strcmp(type, "[shortcut]")==0) return SHORTCUT; + if (strcmp(type, "[crop]")==0) return CROP; + if (strcmp(type, "[cost]")==0) return COST; + if (strcmp(type, "[detection]")==0) return DETECTION; + if (strcmp(type, "[region]")==0) return REGION; + if (strcmp(type, "[yolo]")==0) return YOLO; + if (strcmp(type, "[iseg]")==0) return ISEG; + if (strcmp(type, "[local]")==0) return LOCAL; + if (strcmp(type, "[conv]")==0 + || strcmp(type, "[convolutional]")==0) return CONVOLUTIONAL; + if (strcmp(type, "[deconv]")==0 + || strcmp(type, "[deconvolutional]")==0) return DECONVOLUTIONAL; + if (strcmp(type, "[activation]")==0) return ACTIVE; + if (strcmp(type, "[logistic]")==0) return LOGXENT; + if (strcmp(type, "[l2norm]")==0) return L2NORM; + if (strcmp(type, "[net]")==0 + || strcmp(type, "[network]")==0) return NETWORK; + if (strcmp(type, "[crnn]")==0) return CRNN; + if (strcmp(type, "[gru]")==0) return GRU; + if (strcmp(type, "[lstm]") == 0) return LSTM; + if (strcmp(type, "[rnn]")==0) return RNN; + if (strcmp(type, "[conn]")==0 + || strcmp(type, "[connected]")==0) return CONNECTED; + if (strcmp(type, "[max]")==0 + || strcmp(type, "[maxpool]")==0) return MAXPOOL; + if (strcmp(type, "[reorg]")==0) return REORG; + if (strcmp(type, "[avg]")==0 + || strcmp(type, "[avgpool]")==0) return AVGPOOL; + if (strcmp(type, "[dropout]")==0) return DROPOUT; + if (strcmp(type, "[lrn]")==0 + || strcmp(type, "[normalization]")==0) return NORMALIZATION; + if (strcmp(type, "[batchnorm]")==0) return BATCHNORM; + if (strcmp(type, "[soft]")==0 + || strcmp(type, "[softmax]")==0) return SOFTMAX; + if (strcmp(type, "[route]")==0) return ROUTE; + if (strcmp(type, "[upsample]")==0) return UPSAMPLE; + return BLANK; +} + +void free_section(section *s) +{ + if (s->type) { + free(s->type); + s->type = NULL; + } + node *n = s->options->front; + while(n){ + kvp *pair = (kvp *)n->val; + if (pair->key) { + free(pair->key); + pair->key = NULL; + } + if (pair) { + free(pair); + pair = NULL; + } + node *next = n->next; + if (n) { + free(n); + n = NULL; + } + n = next; + } + if (s->options) { + free(s->options); + s->options = NULL; + } + if (s) { + free(s); + s = NULL; + } +} + +void parse_data(char *data, float *a, int n) +{ + int i; + if(!data) return; + char *curr = data; + char *next = data; + int done = 0; + for(i = 0; i < n && !done; ++i){ + while(*++next !='\0' && *next != ','); + if(*next == '\0') done = 1; + *next = '\0'; + sscanf(curr, "%g", &a[i]); + curr = next+1; + } +} + +typedef struct size_params{ + int batch; + int inputs; + int h; + int w; + int c; + int index; + int time_steps; + network *net; +} size_params; + +local_layer parse_local(list *options, size_params params) +{ + int n = option_find_int(options, "filters",1); + int size = option_find_int(options, "size",1); + int stride = option_find_int(options, "stride",1); + int pad = option_find_int(options, "pad",0); + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + + int batch,h,w,c; + h = params.h; + w = params.w; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before local layer must output image."); + + local_layer layer = make_local_layer(batch,h,w,c,n,size,stride,pad,activation); + + return layer; +} + +layer parse_deconvolutional(list *options, size_params params) +{ + int n = option_find_int(options, "filters",1); + int size = option_find_int(options, "size",1); + int stride = option_find_int(options, "stride",1); + + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + + int batch,h,w,c; + h = params.h; + w = params.w; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before deconvolutional layer must output image."); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + int pad = option_find_int_quiet(options, "pad",0); + int padding = option_find_int_quiet(options, "padding",0); + if(pad) padding = size/2; + + layer l = make_deconvolutional_layer(batch,h,w,c,n,size,stride,padding, activation, batch_normalize, params.net->adam); + + return l; +} + + +convolutional_layer parse_convolutional(list *options, size_params params) +{ + int n = option_find_int(options, "filters",1); + int size = option_find_int(options, "size",1); + int stride = option_find_int(options, "stride",1); + int pad = option_find_int_quiet(options, "pad",0); + int padding = option_find_int_quiet(options, "padding",0); + int groups = option_find_int_quiet(options, "groups", 1); + if(pad) padding = size/2; + + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + + int batch,h,w,c; + h = params.h; + w = params.w; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before convolutional layer must output image."); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + int binary = option_find_int_quiet(options, "binary", 0); + int xnor = option_find_int_quiet(options, "xnor", 0); + + convolutional_layer layer = make_convolutional_layer(batch,h,w,c,n,groups,size,stride,padding,activation, batch_normalize, binary, xnor, params.net->adam); + layer.flipped = option_find_int_quiet(options, "flipped", 0); + layer.dot = option_find_float_quiet(options, "dot", 0); + + if(params.net->adam) { + layer.B1 = params.net->B1; + layer.B2 = params.net->B2; + layer.eps = params.net->eps; + } + + return layer; +} + +layer parse_crnn(list *options, size_params params) +{ + int output_filters = option_find_int(options, "output_filters",1); + int hidden_filters = option_find_int(options, "hidden_filters",1); + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + + layer l = make_crnn_layer(params.batch, params.w, params.h, params.c, hidden_filters, output_filters, params.time_steps, activation, batch_normalize); + + l.shortcut = option_find_int_quiet(options, "shortcut", 0); + + return l; +} + +layer parse_rnn(list *options, size_params params) +{ + int output = option_find_int(options, "output",1); + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + + layer l = make_rnn_layer(params.batch, params.inputs, output, params.time_steps, activation, batch_normalize, params.net->adam); + + l.shortcut = option_find_int_quiet(options, "shortcut", 0); + + return l; +} + +layer parse_gru(list *options, size_params params) +{ + int output = option_find_int(options, "output",1); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + + layer l = make_gru_layer(params.batch, params.inputs, output, params.time_steps, batch_normalize, params.net->adam); + l.tanh = option_find_int_quiet(options, "tanh", 0); + + return l; +} + +layer parse_lstm(list *options, size_params params) +{ + int output = option_find_int(options, "output", 1); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + + layer l = make_lstm_layer(params.batch, params.inputs, output, params.time_steps, batch_normalize, params.net->adam); + + return l; +} + +layer parse_connected(list *options, size_params params) +{ + int output = option_find_int(options, "output",1); + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + + layer l = make_connected_layer(params.batch, params.inputs, output, activation, batch_normalize, params.net->adam); + return l; +} + +layer parse_softmax(list *options, size_params params) +{ + int groups = option_find_int_quiet(options, "groups",1); + layer l = make_softmax_layer(params.batch, params.inputs, groups); + l.temperature = option_find_float_quiet(options, "temperature", 1); + char *tree_file = option_find_str(options, "tree", 0); + if (tree_file) l.softmax_tree = read_tree(tree_file); + l.w = params.w; + l.h = params.h; + l.c = params.c; + l.spatial = option_find_float_quiet(options, "spatial", 0); + l.noloss = option_find_int_quiet(options, "noloss", 0); + return l; +} + +int *parse_yolo_mask(char *a, int *num) +{ + int *mask = 0; + if(a){ + int len = strlen(a); + int n = 1; + int i; + for(i = 0; i < len; ++i){ + if (a[i] == ',') ++n; + } + mask = calloc(n, sizeof(int)); + for(i = 0; i < n; ++i){ + int val = atoi(a); + mask[i] = val; + a = strchr(a, ',')+1; + } + *num = n; + } + return mask; +} + +layer parse_yolo(list *options, size_params params) +{ + int classes = option_find_int(options, "classes", 20); + int total = option_find_int(options, "num", 1); + int num = total; + + char *a = option_find_str(options, "mask", 0); + int *mask = parse_yolo_mask(a, &num); + layer l = make_yolo_layer(params.batch, params.w, params.h, num, total, mask, classes); + assert(l.outputs == params.inputs); + + l.max_boxes = option_find_int_quiet(options, "max",90); + l.jitter = option_find_float(options, "jitter", .2); + + l.ignore_thresh = option_find_float(options, "ignore_thresh", .5); + l.truth_thresh = option_find_float(options, "truth_thresh", 1); + l.random = option_find_int_quiet(options, "random", 0); + + char *map_file = option_find_str(options, "map", 0); + if (map_file) l.map = read_map(map_file); + + a = option_find_str(options, "anchors", 0); + if(a){ + int len = strlen(a); + int n = 1; + int i; + for(i = 0; i < len; ++i){ + if (a[i] == ',') ++n; + } + for(i = 0; i < n; ++i){ + float bias = atof(a); + l.biases[i] = bias; + a = strchr(a, ',')+1; + } + } + return l; +} + +layer parse_iseg(list *options, size_params params) +{ + int classes = option_find_int(options, "classes", 20); + int ids = option_find_int(options, "ids", 32); + layer l = make_iseg_layer(params.batch, params.w, params.h, classes, ids); + assert(l.outputs == params.inputs); + return l; +} + +layer parse_region(list *options, size_params params) +{ + int coords = option_find_int(options, "coords", 4); + int classes = option_find_int(options, "classes", 20); + int num = option_find_int(options, "num", 1); + + layer l = make_region_layer(params.batch, params.w, params.h, num, classes, coords); + assert(l.outputs == params.inputs); + + l.log = option_find_int_quiet(options, "log", 0); + l.sqrt = option_find_int_quiet(options, "sqrt", 0); + + l.softmax = option_find_int(options, "softmax", 0); + l.background = option_find_int_quiet(options, "background", 0); + l.max_boxes = option_find_int_quiet(options, "max",30); + l.jitter = option_find_float(options, "jitter", .2); + l.rescore = option_find_int_quiet(options, "rescore",0); + + l.thresh = option_find_float(options, "thresh", .5); + l.classfix = option_find_int_quiet(options, "classfix", 0); + l.absolute = option_find_int_quiet(options, "absolute", 0); + l.random = option_find_int_quiet(options, "random", 0); + + l.coord_scale = option_find_float(options, "coord_scale", 1); + l.object_scale = option_find_float(options, "object_scale", 1); + l.noobject_scale = option_find_float(options, "noobject_scale", 1); + l.mask_scale = option_find_float(options, "mask_scale", 1); + l.class_scale = option_find_float(options, "class_scale", 1); + l.bias_match = option_find_int_quiet(options, "bias_match",0); + + char *tree_file = option_find_str(options, "tree", 0); + if (tree_file) l.softmax_tree = read_tree(tree_file); + char *map_file = option_find_str(options, "map", 0); + if (map_file) l.map = read_map(map_file); + + char *a = option_find_str(options, "anchors", 0); + if(a){ + int len = strlen(a); + int n = 1; + int i; + for(i = 0; i < len; ++i){ + if (a[i] == ',') ++n; + } + for(i = 0; i < n; ++i){ + float bias = atof(a); + l.biases[i] = bias; + a = strchr(a, ',')+1; + } + } + return l; +} + +detection_layer parse_detection(list *options, size_params params) +{ + int coords = option_find_int(options, "coords", 1); + int classes = option_find_int(options, "classes", 1); + int rescore = option_find_int(options, "rescore", 0); + int num = option_find_int(options, "num", 1); + int side = option_find_int(options, "side", 7); + detection_layer layer = make_detection_layer(params.batch, params.inputs, num, side, classes, coords, rescore); + + layer.softmax = option_find_int(options, "softmax", 0); + layer.sqrt = option_find_int(options, "sqrt", 0); + + layer.max_boxes = option_find_int_quiet(options, "max",90); + layer.coord_scale = option_find_float(options, "coord_scale", 1); + layer.forced = option_find_int(options, "forced", 0); + layer.object_scale = option_find_float(options, "object_scale", 1); + layer.noobject_scale = option_find_float(options, "noobject_scale", 1); + layer.class_scale = option_find_float(options, "class_scale", 1); + layer.jitter = option_find_float(options, "jitter", .2); + layer.random = option_find_int_quiet(options, "random", 0); + layer.reorg = option_find_int_quiet(options, "reorg", 0); + return layer; +} + +cost_layer parse_cost(list *options, size_params params) +{ + char *type_s = option_find_str(options, "type", "sse"); + COST_TYPE type = get_cost_type(type_s); + float scale = option_find_float_quiet(options, "scale",1); + cost_layer layer = make_cost_layer(params.batch, params.inputs, type, scale); + layer.ratio = option_find_float_quiet(options, "ratio",0); + layer.noobject_scale = option_find_float_quiet(options, "noobj", 1); + layer.thresh = option_find_float_quiet(options, "thresh",0); + return layer; +} + +crop_layer parse_crop(list *options, size_params params) +{ + int crop_height = option_find_int(options, "crop_height",1); + int crop_width = option_find_int(options, "crop_width",1); + int flip = option_find_int(options, "flip",0); + float angle = option_find_float(options, "angle",0); + float saturation = option_find_float(options, "saturation",1); + float exposure = option_find_float(options, "exposure",1); + + int batch,h,w,c; + h = params.h; + w = params.w; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before crop layer must output image."); + + int noadjust = option_find_int_quiet(options, "noadjust",0); + + crop_layer l = make_crop_layer(batch,h,w,c,crop_height,crop_width,flip, angle, saturation, exposure); + l.shift = option_find_float(options, "shift", 0); + l.noadjust = noadjust; + return l; +} + +layer parse_reorg(list *options, size_params params) +{ + int stride = option_find_int(options, "stride",1); + int reverse = option_find_int_quiet(options, "reverse",0); + int flatten = option_find_int_quiet(options, "flatten",0); + int extra = option_find_int_quiet(options, "extra",0); + + int batch,h,w,c; + h = params.h; + w = params.w; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before reorg layer must output image."); + + layer layer = make_reorg_layer(batch,w,h,c,stride,reverse, flatten, extra); + return layer; +} + +maxpool_layer parse_maxpool(list *options, size_params params) +{ + int stride = option_find_int(options, "stride",1); + int size = option_find_int(options, "size",stride); + int padding = option_find_int_quiet(options, "padding", size-1); + + int batch,h,w,c; + h = params.h; + w = params.w; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before maxpool layer must output image."); + + maxpool_layer layer = make_maxpool_layer(batch,h,w,c,size,stride,padding); + return layer; +} + +avgpool_layer parse_avgpool(list *options, size_params params) +{ + int batch,w,h,c; + w = params.w; + h = params.h; + c = params.c; + batch=params.batch; + if(!(h && w && c)) error("Layer before avgpool layer must output image."); + + avgpool_layer layer = make_avgpool_layer(batch,w,h,c); + return layer; +} + +dropout_layer parse_dropout(list *options, size_params params) +{ + float probability = option_find_float(options, "probability", .5); + dropout_layer layer = make_dropout_layer(params.batch, params.inputs, probability); + layer.out_w = params.w; + layer.out_h = params.h; + layer.out_c = params.c; + return layer; +} + +layer parse_normalization(list *options, size_params params) +{ + float alpha = option_find_float(options, "alpha", .0001); + float beta = option_find_float(options, "beta" , .75); + float kappa = option_find_float(options, "kappa", 1); + int size = option_find_int(options, "size", 5); + layer l = make_normalization_layer(params.batch, params.w, params.h, params.c, size, alpha, beta, kappa); + return l; +} + +layer parse_batchnorm(list *options, size_params params) +{ + layer l = make_batchnorm_layer(params.batch, params.w, params.h, params.c); + return l; +} + +layer parse_shortcut(list *options, size_params params, network *net) +{ + char *l = option_find(options, "from"); + int index = atoi(l); + if(index < 0) index = params.index + index; + + int batch = params.batch; + layer from = net->layers[index]; + + layer s = make_shortcut_layer(batch, index, params.w, params.h, params.c, from.out_w, from.out_h, from.out_c); + + char *activation_s = option_find_str(options, "activation", "linear"); + ACTIVATION activation = get_activation(activation_s); + s.activation = activation; + s.alpha = option_find_float_quiet(options, "alpha", 1); + s.beta = option_find_float_quiet(options, "beta", 1); + return s; +} + + +layer parse_l2norm(list *options, size_params params) +{ + layer l = make_l2norm_layer(params.batch, params.inputs); + l.h = l.out_h = params.h; + l.w = l.out_w = params.w; + l.c = l.out_c = params.c; + return l; +} + + +layer parse_logistic(list *options, size_params params) +{ + layer l = make_logistic_layer(params.batch, params.inputs); + l.h = l.out_h = params.h; + l.w = l.out_w = params.w; + l.c = l.out_c = params.c; + return l; +} + +layer parse_activation(list *options, size_params params) +{ + char *activation_s = option_find_str(options, "activation", "linear"); + ACTIVATION activation = get_activation(activation_s); + + layer l = make_activation_layer(params.batch, params.inputs, activation); + + l.h = l.out_h = params.h; + l.w = l.out_w = params.w; + l.c = l.out_c = params.c; + + return l; +} + +layer parse_upsample(list *options, size_params params, network *net) +{ + + int stride = option_find_int(options, "stride",2); + layer l = make_upsample_layer(params.batch, params.w, params.h, params.c, stride); + l.scale = option_find_float_quiet(options, "scale", 1); + return l; +} + +route_layer parse_route(list *options, size_params params, network *net) +{ + char *l = option_find(options, "layers"); + int len = strlen(l); + if(!l) error("Route Layer must specify input layers"); + int n = 1; + int i; + for(i = 0; i < len; ++i){ + if (l[i] == ',') ++n; + } + + int *layers = calloc(n, sizeof(int)); + int *sizes = calloc(n, sizeof(int)); + for(i = 0; i < n; ++i){ + int index = atoi(l); + l = strchr(l, ',')+1; + if(index < 0) index = params.index + index; + layers[i] = index; + sizes[i] = net->layers[index].outputs; + } + int batch = params.batch; + + route_layer layer = make_route_layer(batch, n, layers, sizes); + + convolutional_layer first = net->layers[layers[0]]; + layer.out_w = first.out_w; + layer.out_h = first.out_h; + layer.out_c = first.out_c; + for(i = 1; i < n; ++i){ + int index = layers[i]; + convolutional_layer next = net->layers[index]; + if(next.out_w == first.out_w && next.out_h == first.out_h){ + layer.out_c += next.out_c; + }else{ + layer.out_h = layer.out_w = layer.out_c = 0; + } + } + + return layer; +} + +learning_rate_policy get_policy(char *s) +{ + if (strcmp(s, "random")==0) return RANDOM; + if (strcmp(s, "poly")==0) return POLY; + if (strcmp(s, "constant")==0) return CONSTANT; + if (strcmp(s, "step")==0) return STEP; + if (strcmp(s, "exp")==0) return EXP; + if (strcmp(s, "sigmoid")==0) return SIG; + if (strcmp(s, "steps")==0) return STEPS; + fprintf(stderr, "Couldn't find policy %s, going with constant\n", s); + return CONSTANT; +} + +void parse_net_options(list *options, network *net) +{ + net->batch = option_find_int(options, "batch",1); + net->learning_rate = option_find_float(options, "learning_rate", .001); + net->momentum = option_find_float(options, "momentum", .9); + net->decay = option_find_float(options, "decay", .0001); + int subdivs = option_find_int(options, "subdivisions",1); + net->time_steps = option_find_int_quiet(options, "time_steps",1); + net->notruth = option_find_int_quiet(options, "notruth",0); + net->batch /= subdivs; + net->batch *= net->time_steps; + net->subdivisions = subdivs; + net->random = option_find_int_quiet(options, "random", 0); + + net->adam = option_find_int_quiet(options, "adam", 0); + if(net->adam){ + net->B1 = option_find_float(options, "B1", .9); + net->B2 = option_find_float(options, "B2", .999); + net->eps = option_find_float(options, "eps", .0000001); + } + + net->h = option_find_int_quiet(options, "height",0); + net->w = option_find_int_quiet(options, "width",0); + net->c = option_find_int_quiet(options, "channels",0); + net->inputs = option_find_int_quiet(options, "inputs", net->h * net->w * net->c); + net->max_crop = option_find_int_quiet(options, "max_crop",net->w*2); + net->min_crop = option_find_int_quiet(options, "min_crop",net->w); + net->max_ratio = option_find_float_quiet(options, "max_ratio", (float) net->max_crop / net->w); + net->min_ratio = option_find_float_quiet(options, "min_ratio", (float) net->min_crop / net->w); + net->center = option_find_int_quiet(options, "center",0); + net->clip = option_find_float_quiet(options, "clip", 0); + + net->angle = option_find_float_quiet(options, "angle", 0); + net->aspect = option_find_float_quiet(options, "aspect", 1); + net->saturation = option_find_float_quiet(options, "saturation", 1); + net->exposure = option_find_float_quiet(options, "exposure", 1); + net->hue = option_find_float_quiet(options, "hue", 0); + + if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied"); + + char *policy_s = option_find_str(options, "policy", "constant"); + net->policy = get_policy(policy_s); + net->burn_in = option_find_int_quiet(options, "burn_in", 0); + net->power = option_find_float_quiet(options, "power", 4); + if(net->policy == STEP){ + net->step = option_find_int(options, "step", 1); + net->scale = option_find_float(options, "scale", 1); + } else if (net->policy == STEPS){ + char *l = option_find(options, "steps"); + char *p = option_find(options, "scales"); + if(!l || !p) error("STEPS policy must have steps and scales in cfg file"); + + int len = strlen(l); + int n = 1; + int i; + for(i = 0; i < len; ++i){ + if (l[i] == ',') ++n; + } + int *steps = calloc(n, sizeof(int)); + float *scales = calloc(n, sizeof(float)); + for(i = 0; i < n; ++i){ + int step = atoi(l); + float scale = atof(p); + l = strchr(l, ',')+1; + p = strchr(p, ',')+1; + steps[i] = step; + scales[i] = scale; + } + net->scales = scales; + net->steps = steps; + net->num_steps = n; + } else if (net->policy == EXP){ + net->gamma = option_find_float(options, "gamma", 1); + } else if (net->policy == SIG){ + net->gamma = option_find_float(options, "gamma", 1); + net->step = option_find_int(options, "step", 1); + } else if (net->policy == POLY || net->policy == RANDOM){ + } + net->max_batches = option_find_int(options, "max_batches", 0); +} + +int is_network(section *s) +{ + return (strcmp(s->type, "[net]")==0 + || strcmp(s->type, "[network]")==0); +} + +network *parse_network_cfg(char *filename) +{ + list *sections = read_cfg(filename); + node *n = sections->front; + if(!n) error("Config file has no sections"); + network *net = make_network(sections->size - 1); + net->gpu_index = gpu_index; + size_params params; + + section *s = (section *)n->val; + list *options = s->options; + if(!is_network(s)) error("First section must be [net] or [network]"); + parse_net_options(options, net); + + params.h = net->h; + params.w = net->w; + params.c = net->c; + params.inputs = net->inputs; + params.batch = net->batch; + params.time_steps = net->time_steps; + params.net = net; + + size_t workspace_size = 0; + n = n->next; + int count = 0; + free_section(s); + fprintf(stderr, "layer filters size input output\n"); + while(n){ + params.index = count; + fprintf(stderr, "%5d ", count); + s = (section *)n->val; + options = s->options; + layer l = {0}; + LAYER_TYPE lt = string_to_layer_type(s->type); + if(lt == CONVOLUTIONAL){ + l = parse_convolutional(options, params); + }else if(lt == DECONVOLUTIONAL){ + l = parse_deconvolutional(options, params); + }else if(lt == LOCAL){ + l = parse_local(options, params); + }else if(lt == ACTIVE){ + l = parse_activation(options, params); + }else if(lt == LOGXENT){ + l = parse_logistic(options, params); + }else if(lt == L2NORM){ + l = parse_l2norm(options, params); + }else if(lt == RNN){ + l = parse_rnn(options, params); + }else if(lt == GRU){ + l = parse_gru(options, params); + }else if (lt == LSTM) { + l = parse_lstm(options, params); + }else if(lt == CRNN){ + l = parse_crnn(options, params); + }else if(lt == CONNECTED){ + l = parse_connected(options, params); + }else if(lt == CROP){ + l = parse_crop(options, params); + }else if(lt == COST){ + l = parse_cost(options, params); + }else if(lt == REGION){ + l = parse_region(options, params); + }else if(lt == YOLO){ + l = parse_yolo(options, params); + }else if(lt == ISEG){ + l = parse_iseg(options, params); + }else if(lt == DETECTION){ + l = parse_detection(options, params); + }else if(lt == SOFTMAX){ + l = parse_softmax(options, params); + net->hierarchy = l.softmax_tree; + }else if(lt == NORMALIZATION){ + l = parse_normalization(options, params); + }else if(lt == BATCHNORM){ + l = parse_batchnorm(options, params); + }else if(lt == MAXPOOL){ + l = parse_maxpool(options, params); + }else if(lt == REORG){ + l = parse_reorg(options, params); + }else if(lt == AVGPOOL){ + l = parse_avgpool(options, params); + }else if(lt == ROUTE){ + l = parse_route(options, params, net); + }else if(lt == UPSAMPLE){ + l = parse_upsample(options, params, net); + }else if(lt == SHORTCUT){ + l = parse_shortcut(options, params, net); + }else if(lt == DROPOUT){ + l = parse_dropout(options, params); + l.output = net->layers[count-1].output; + l.delta = net->layers[count-1].delta; +#ifdef GPU + l.output_gpu = net->layers[count-1].output_gpu; + l.delta_gpu = net->layers[count-1].delta_gpu; +#endif + }else{ + fprintf(stderr, "Type not recognized: %s\n", s->type); + } + l.clip = net->clip; + l.truth = option_find_int_quiet(options, "truth", 0); + l.onlyforward = option_find_int_quiet(options, "onlyforward", 0); + l.stopbackward = option_find_int_quiet(options, "stopbackward", 0); + l.dontsave = option_find_int_quiet(options, "dontsave", 0); + l.dontload = option_find_int_quiet(options, "dontload", 0); + l.numload = option_find_int_quiet(options, "numload", 0); + l.dontloadscales = option_find_int_quiet(options, "dontloadscales", 0); + l.learning_rate_scale = option_find_float_quiet(options, "learning_rate", 1); + l.smooth = option_find_float_quiet(options, "smooth", 0); + option_unused(options); + net->layers[count] = l; + if (l.workspace_size > workspace_size) workspace_size = l.workspace_size; + free_section(s); + n = n->next; + ++count; + if(n){ + params.h = l.out_h; + params.w = l.out_w; + params.c = l.out_c; + params.inputs = l.outputs; + } + } + free_list(sections); + layer out = get_network_output_layer(net); + net->outputs = out.outputs; + net->truths = out.outputs; + if(net->layers[net->n-1].truths) net->truths = net->layers[net->n-1].truths; + net->output = out.output; + net->input = calloc(net->inputs*net->batch, sizeof(float)); + net->truth = calloc(net->truths*net->batch, sizeof(float)); +#ifdef GPU + net->output_gpu = out.output_gpu; + net->input_gpu = cuda_make_array(net->input, net->inputs*net->batch); + net->truth_gpu = cuda_make_array(net->truth, net->truths*net->batch); +#endif + if(workspace_size){ + //printf("%ld\n", workspace_size); +#ifdef GPU + if(gpu_index >= 0){ + net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1); + }else { + net->workspace = calloc(1, workspace_size); + } +#else + net->workspace = calloc(1, workspace_size); +#endif + } + return net; +} + +list *read_cfg(char *filename) +{ + FILE *file = fopen(filename, "r"); + if(file == 0) file_error(filename); + char *line; + int nu = 0; + list *options = make_list(); + section *current = 0; + while((line=fgetl(file)) != 0){ + ++ nu; + strip(line); + switch(line[0]){ + case '[': + current = malloc(sizeof(section)); + list_insert(options, current); + current->options = make_list(); + current->type = line; + break; + case '\0': + case '#': + case ';': + if (line) { + free(line); + line = NULL; + } + break; + default: + if(!read_option(line, current->options)){ + fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line); + if (line) { + free(line); + line = NULL; + } + } + break; + } + } + fclose(file); + return options; +} + +void save_convolutional_weights_binary(layer l, FILE *fp) +{ +#ifdef GPU + if(gpu_index >= 0){ + pull_convolutional_layer(l); + } +#endif + binarize_weights(l.weights, l.n, l.c*l.size*l.size, l.binary_weights); + int size = l.c*l.size*l.size; + int i, j, k; + fwrite(l.biases, sizeof(float), l.n, fp); + if (l.batch_normalize){ + fwrite(l.scales, sizeof(float), l.n, fp); + fwrite(l.rolling_mean, sizeof(float), l.n, fp); + fwrite(l.rolling_variance, sizeof(float), l.n, fp); + } + for(i = 0; i < l.n; ++i){ + float mean = l.binary_weights[i*size]; + if(mean < 0) mean = -mean; + fwrite(&mean, sizeof(float), 1, fp); + for(j = 0; j < size/8; ++j){ + int index = i*size + j*8; + unsigned char c = 0; + for(k = 0; k < 8; ++k){ + if (j*8 + k >= size) break; + if (l.binary_weights[index + k] > 0) c = (c | 1<<k); + } + fwrite(&c, sizeof(char), 1, fp); + } + } +} + +void save_convolutional_weights(layer l, FILE *fp) +{ + if(l.binary){ + //save_convolutional_weights_binary(l, fp); + //return; + } +#ifdef GPU + if(gpu_index >= 0){ + pull_convolutional_layer(l); + } +#endif + int num = l.nweights; + fwrite(l.biases, sizeof(float), l.n, fp); + if (l.batch_normalize){ + fwrite(l.scales, sizeof(float), l.n, fp); + fwrite(l.rolling_mean, sizeof(float), l.n, fp); + fwrite(l.rolling_variance, sizeof(float), l.n, fp); + } + fwrite(l.weights, sizeof(float), num, fp); +} + +void save_batchnorm_weights(layer l, FILE *fp) +{ +#ifdef GPU + if(gpu_index >= 0){ + pull_batchnorm_layer(l); + } +#endif + fwrite(l.scales, sizeof(float), l.c, fp); + fwrite(l.rolling_mean, sizeof(float), l.c, fp); + fwrite(l.rolling_variance, sizeof(float), l.c, fp); +} + +void save_connected_weights(layer l, FILE *fp) +{ +#ifdef GPU + if(gpu_index >= 0){ + pull_connected_layer(l); + } +#endif + fwrite(l.biases, sizeof(float), l.outputs, fp); + fwrite(l.weights, sizeof(float), l.outputs*l.inputs, fp); + if (l.batch_normalize){ + fwrite(l.scales, sizeof(float), l.outputs, fp); + fwrite(l.rolling_mean, sizeof(float), l.outputs, fp); + fwrite(l.rolling_variance, sizeof(float), l.outputs, fp); + } +} + +void save_weights_upto(network *net, char *filename, int cutoff) +{ +#ifdef GPU + if(net->gpu_index >= 0){ + cuda_set_device(net->gpu_index); + } +#endif + fprintf(stderr, "Saving weights to %s\n", filename); + FILE *fp = fopen(filename, "wb"); + if(!fp) file_error(filename); + + int major = 0; + int minor = 2; + int revision = 0; + fwrite(&major, sizeof(int), 1, fp); + fwrite(&minor, sizeof(int), 1, fp); + fwrite(&revision, sizeof(int), 1, fp); + fwrite(net->seen, sizeof(size_t), 1, fp); + + int i; + for(i = 0; i < net->n && i < cutoff; ++i){ + layer l = net->layers[i]; + if (l.dontsave) continue; + if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ + save_convolutional_weights(l, fp); + } if(l.type == CONNECTED){ + save_connected_weights(l, fp); + } if(l.type == BATCHNORM){ + save_batchnorm_weights(l, fp); + } if(l.type == RNN){ + save_connected_weights(*(l.input_layer), fp); + save_connected_weights(*(l.self_layer), fp); + save_connected_weights(*(l.output_layer), fp); + } if (l.type == LSTM) { + save_connected_weights(*(l.wi), fp); + save_connected_weights(*(l.wf), fp); + save_connected_weights(*(l.wo), fp); + save_connected_weights(*(l.wg), fp); + save_connected_weights(*(l.ui), fp); + save_connected_weights(*(l.uf), fp); + save_connected_weights(*(l.uo), fp); + save_connected_weights(*(l.ug), fp); + } if (l.type == GRU) { + if(1){ + save_connected_weights(*(l.wz), fp); + save_connected_weights(*(l.wr), fp); + save_connected_weights(*(l.wh), fp); + save_connected_weights(*(l.uz), fp); + save_connected_weights(*(l.ur), fp); + save_connected_weights(*(l.uh), fp); + }else{ + save_connected_weights(*(l.reset_layer), fp); + save_connected_weights(*(l.update_layer), fp); + save_connected_weights(*(l.state_layer), fp); + } + } if(l.type == CRNN){ + save_convolutional_weights(*(l.input_layer), fp); + save_convolutional_weights(*(l.self_layer), fp); + save_convolutional_weights(*(l.output_layer), fp); + } if(l.type == LOCAL){ +#ifdef GPU + if(gpu_index >= 0){ + pull_local_layer(l); + } +#endif + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + fwrite(l.biases, sizeof(float), l.outputs, fp); + fwrite(l.weights, sizeof(float), size, fp); + } + } + fclose(fp); +} +void save_weights(network *net, char *filename) +{ + save_weights_upto(net, filename, net->n); +} + +void transpose_matrix(float *a, int rows, int cols) +{ + float *transpose = calloc(rows*cols, sizeof(float)); + int x, y; + for(x = 0; x < rows; ++x){ + for(y = 0; y < cols; ++y){ + transpose[y*rows + x] = a[x*cols + y]; + } + } + memcpy(a, transpose, rows*cols*sizeof(float)); + if (transpose) { + free(transpose); + transpose = NULL; + } +} + +void load_connected_weights(layer l, FILE *fp, int transpose) +{ + fread(l.biases, sizeof(float), l.outputs, fp); + fread(l.weights, sizeof(float), l.outputs*l.inputs, fp); + if(transpose){ + transpose_matrix(l.weights, l.inputs, l.outputs); + } + //printf("Biases: %f mean %f variance\n", mean_array(l.biases, l.outputs), variance_array(l.biases, l.outputs)); + //printf("Weights: %f mean %f variance\n", mean_array(l.weights, l.outputs*l.inputs), variance_array(l.weights, l.outputs*l.inputs)); + if (l.batch_normalize && (!l.dontloadscales)){ + fread(l.scales, sizeof(float), l.outputs, fp); + fread(l.rolling_mean, sizeof(float), l.outputs, fp); + fread(l.rolling_variance, sizeof(float), l.outputs, fp); + //printf("Scales: %f mean %f variance\n", mean_array(l.scales, l.outputs), variance_array(l.scales, l.outputs)); + //printf("rolling_mean: %f mean %f variance\n", mean_array(l.rolling_mean, l.outputs), variance_array(l.rolling_mean, l.outputs)); + //printf("rolling_variance: %f mean %f variance\n", mean_array(l.rolling_variance, l.outputs), variance_array(l.rolling_variance, l.outputs)); + } +#ifdef GPU + if(gpu_index >= 0){ + push_connected_layer(l); + } +#endif +} + +void load_batchnorm_weights(layer l, FILE *fp) +{ + fread(l.scales, sizeof(float), l.c, fp); + fread(l.rolling_mean, sizeof(float), l.c, fp); + fread(l.rolling_variance, sizeof(float), l.c, fp); +#ifdef GPU + if(gpu_index >= 0){ + push_batchnorm_layer(l); + } +#endif +} + +void load_convolutional_weights_binary(layer l, FILE *fp) +{ + fread(l.biases, sizeof(float), l.n, fp); + if (l.batch_normalize && (!l.dontloadscales)){ + fread(l.scales, sizeof(float), l.n, fp); + fread(l.rolling_mean, sizeof(float), l.n, fp); + fread(l.rolling_variance, sizeof(float), l.n, fp); + } + int size = l.c*l.size*l.size; + int i, j, k; + for(i = 0; i < l.n; ++i){ + float mean = 0; + fread(&mean, sizeof(float), 1, fp); + for(j = 0; j < size/8; ++j){ + int index = i*size + j*8; + unsigned char c = 0; + fread(&c, sizeof(char), 1, fp); + for(k = 0; k < 8; ++k){ + if (j*8 + k >= size) break; + l.weights[index + k] = (c & 1<<k) ? mean : -mean; + } + } + } +#ifdef GPU + if(gpu_index >= 0){ + push_convolutional_layer(l); + } +#endif +} + +void load_convolutional_weights(layer l, FILE *fp) +{ + if(l.binary){ + //load_convolutional_weights_binary(l, fp); + //return; + } + if(l.numload) l.n = l.numload; + int num = l.c/l.groups*l.n*l.size*l.size; + fread(l.biases, sizeof(float), l.n, fp); + if (l.batch_normalize && (!l.dontloadscales)){ + fread(l.scales, sizeof(float), l.n, fp); + fread(l.rolling_mean, sizeof(float), l.n, fp); + fread(l.rolling_variance, sizeof(float), l.n, fp); + if(0){ + int i; + for(i = 0; i < l.n; ++i){ + printf("%g, ", l.rolling_mean[i]); + } + printf("\n"); + for(i = 0; i < l.n; ++i){ + printf("%g, ", l.rolling_variance[i]); + } + printf("\n"); + } + if(0){ + fill_cpu(l.n, 0, l.rolling_mean, 1); + fill_cpu(l.n, 0, l.rolling_variance, 1); + } + if(0){ + int i; + for(i = 0; i < l.n; ++i){ + printf("%g, ", l.rolling_mean[i]); + } + printf("\n"); + for(i = 0; i < l.n; ++i){ + printf("%g, ", l.rolling_variance[i]); + } + printf("\n"); + } + } + fread(l.weights, sizeof(float), num, fp); + //if(l.c == 3) scal_cpu(num, 1./256, l.weights, 1); + if (l.flipped) { + transpose_matrix(l.weights, l.c*l.size*l.size, l.n); + } + //if (l.binary) binarize_weights(l.weights, l.n, l.c*l.size*l.size, l.weights); +#ifdef GPU + if(gpu_index >= 0){ + push_convolutional_layer(l); + } +#endif +} + + +void load_weights_upto(network *net, char *filename, int start, int cutoff) +{ +#ifdef GPU + if(net->gpu_index >= 0){ + cuda_set_device(net->gpu_index); + } +#endif + fprintf(stderr, "Loading weights from %s...", filename); + fflush(stdout); + FILE *fp = fopen(filename, "rb"); + if(!fp) file_error(filename); + + int major; + int minor; + int revision; + fread(&major, sizeof(int), 1, fp); + fread(&minor, sizeof(int), 1, fp); + fread(&revision, sizeof(int), 1, fp); + if ((major*10 + minor) >= 2 && major < 1000 && minor < 1000){ + fread(net->seen, sizeof(size_t), 1, fp); + } else { + int iseen = 0; + fread(&iseen, sizeof(int), 1, fp); + *net->seen = iseen; + } + int transpose = (major > 1000) || (minor > 1000); + + int i; + for(i = start; i < net->n && i < cutoff; ++i){ + layer l = net->layers[i]; + if (l.dontload) continue; + if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){ + load_convolutional_weights(l, fp); + } + if(l.type == CONNECTED){ + load_connected_weights(l, fp, transpose); + } + if(l.type == BATCHNORM){ + load_batchnorm_weights(l, fp); + } + if(l.type == CRNN){ + load_convolutional_weights(*(l.input_layer), fp); + load_convolutional_weights(*(l.self_layer), fp); + load_convolutional_weights(*(l.output_layer), fp); + } + if(l.type == RNN){ + load_connected_weights(*(l.input_layer), fp, transpose); + load_connected_weights(*(l.self_layer), fp, transpose); + load_connected_weights(*(l.output_layer), fp, transpose); + } + if (l.type == LSTM) { + load_connected_weights(*(l.wi), fp, transpose); + load_connected_weights(*(l.wf), fp, transpose); + load_connected_weights(*(l.wo), fp, transpose); + load_connected_weights(*(l.wg), fp, transpose); + load_connected_weights(*(l.ui), fp, transpose); + load_connected_weights(*(l.uf), fp, transpose); + load_connected_weights(*(l.uo), fp, transpose); + load_connected_weights(*(l.ug), fp, transpose); + } + if (l.type == GRU) { + if(1){ + load_connected_weights(*(l.wz), fp, transpose); + load_connected_weights(*(l.wr), fp, transpose); + load_connected_weights(*(l.wh), fp, transpose); + load_connected_weights(*(l.uz), fp, transpose); + load_connected_weights(*(l.ur), fp, transpose); + load_connected_weights(*(l.uh), fp, transpose); + }else{ + load_connected_weights(*(l.reset_layer), fp, transpose); + load_connected_weights(*(l.update_layer), fp, transpose); + load_connected_weights(*(l.state_layer), fp, transpose); + } + } + if(l.type == LOCAL){ + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + fread(l.biases, sizeof(float), l.outputs, fp); + fread(l.weights, sizeof(float), size, fp); +#ifdef GPU + if(gpu_index >= 0){ + push_local_layer(l); + } +#endif + } + } + fprintf(stderr, "Done!\n"); + fclose(fp); +} + +void load_weights(network *net, char *filename) +{ + load_weights_upto(net, filename, 0, net->n); +} + +///#ifdef ALLEN_MODIFIED + +char* load_connected_weights_mem(layer l, char *curPtr, int transpose) +{ + //fread(l.biases, sizeof(float), l.outputs, fp); + //fread(l.weights, sizeof(float), l.outputs*l.inputs, fp); + memcpy(l.biases, curPtr, sizeof(float)*l.outputs); + curPtr += sizeof(float)*l.outputs; + memcpy(l.weights, curPtr, sizeof(float)*l.outputs*l.inputs); + curPtr += sizeof(float)*l.outputs*l.inputs; + + if (transpose) { + transpose_matrix(l.weights, l.inputs, l.outputs); + } + //printf("Biases: %f mean %f variance\n", mean_array(l.biases, l.outputs), variance_array(l.biases, l.outputs)); + //printf("Weights: %f mean %f variance\n", mean_array(l.weights, l.outputs*l.inputs), variance_array(l.weights, l.outputs*l.inputs)); + if (l.batch_normalize && (!l.dontloadscales)) { + //fread(l.scales, sizeof(float), l.outputs, fp); + //fread(l.rolling_mean, sizeof(float), l.outputs, fp); + //fread(l.rolling_variance, sizeof(float), l.outputs, fp); + memcpy(l.scales, curPtr, sizeof(float)*l.outputs); + curPtr += sizeof(float)*l.outputs; + memcpy(l.rolling_mean, curPtr, sizeof(float)*l.outputs); + curPtr += sizeof(float)*l.outputs; + memcpy(l.rolling_variance, curPtr, sizeof(float)*l.outputs); + curPtr += sizeof(float)*l.outputs; + + printf("Scales: %f mean %f variance\n", mean_array(l.scales, l.outputs), variance_array(l.scales, l.outputs)); + printf("rolling_mean: %f mean %f variance\n", mean_array(l.rolling_mean, l.outputs), variance_array(l.rolling_mean, l.outputs)); + printf("rolling_variance: %f mean %f variance\n", mean_array(l.rolling_variance, l.outputs), variance_array(l.rolling_variance, l.outputs)); + } +#ifdef GPU + if (gpu_index >= 0) { + push_connected_layer(l); + } +#endif + return curPtr; +} + +char* load_batchnorm_weights_mem(layer l, char *curPtr) +{ + //fread(l.scales, sizeof(float), l.c, fp); + //fread(l.rolling_mean, sizeof(float), l.c, fp); + //fread(l.rolling_variance, sizeof(float), l.c, fp); + memcpy(l.scales, curPtr, sizeof(float)*l.c); + curPtr += sizeof(float)*l.c; + memcpy(l.rolling_mean, curPtr, sizeof(float)*l.c); + curPtr += sizeof(float)*l.c; + memcpy(l.rolling_variance, curPtr, sizeof(float)*l.c); + curPtr += sizeof(float)*l.c; + +#ifdef GPU + if (gpu_index >= 0) { + push_batchnorm_layer(l); + } +#endif + return curPtr; +} + +char* load_convolutional_weights_mem(layer l, unsigned char *curPtr) +{ + if (l.binary) { + //load_convolutional_weights_binary(l, fp); + //return; + } + int num = l.n*l.c*l.size*l.size; + //fread(l.biases, sizeof(float), l.n, fp); + /*for (int i = 0; i < sizeof(float)*l.n; i++) { + printf(" %02X", *(curPtr + i)); + }putchar('\n');*/ + memcpy(l.biases, curPtr, sizeof(float)*l.n); + curPtr += sizeof(float)*l.n; + + if (l.batch_normalize && (!l.dontloadscales)) { + //fread(l.scales, sizeof(float), l.n, fp); + //fread(l.rolling_mean, sizeof(float), l.n, fp); + //fread(l.rolling_variance, sizeof(float), l.n, fp); + memcpy(l.scales, curPtr, sizeof(float)*l.n); + curPtr += sizeof(float)*l.n; + memcpy(l.rolling_mean, curPtr, sizeof(float)*l.n); + curPtr += sizeof(float)*l.n; + memcpy(l.rolling_variance, curPtr, sizeof(float)*l.n); + curPtr += sizeof(float)*l.n; + + if (0) { + int i; + for (i = 0; i < l.n; ++i) { + printf("%g, ", l.rolling_mean[i]); + } + printf("\n"); + for (i = 0; i < l.n; ++i) { + printf("%g, ", l.rolling_variance[i]); + } + printf("\n"); + } + if (0) { + fill_cpu(l.n, 0, l.rolling_mean, 1); + fill_cpu(l.n, 0, l.rolling_variance, 1); + } + } + //fread(l.weights, sizeof(float), num, fp); + /*for (int i = 0; i < sizeof(float)*num; i++) { + printf(" %02X", *(curPtr + i)); + }putchar('\n');*/ + memcpy(l.weights, curPtr, sizeof(float)*num); + curPtr += sizeof(float)*num; + + if (l.adam) { + //fread(l.m, sizeof(float), num, fp); + //fread(l.v, sizeof(float), num, fp); + memcpy(l.m, curPtr, sizeof(float)*num); + curPtr += sizeof(float)*num; + memcpy(l.v, curPtr, sizeof(float)*num); + curPtr += sizeof(float)*num; + } + //if(l.c == 3) scal_cpu(num, 1./256, l.weights, 1); + if (l.flipped) { + transpose_matrix(l.weights, l.c*l.size*l.size, l.n); + } + //if (l.binary) binarize_weights(l.weights, l.n, l.c*l.size*l.size, l.weights); +#ifdef GPU + if (gpu_index >= 0) { + push_convolutional_layer(l); + } +#endif + return (char *)curPtr; +} + +void load_weights_mem(network *net, char *filename) +{ + load_weights_upto_mem(net, filename, net->n); +} + + + +void load_weights_upto_mem(network *net, char *filename, int cutoff) +{ +#ifdef GPU + if (net->gpu_index >= 0) { + cuda_set_device(net->gpu_index); + } +#endif + fprintf(stderr, "Loading weights from %s...%d%%", filename, 0); + fflush(stdout); + + KeyExpansion(key, expandedKey); + unsigned char *DecryptFileData = malloc((sizeof(char) * MAX_WEIGHT_FILE_SIZE)); + /*size_t descrypt_size = */AESDecryptFileToArrayPercent(filename, expandedKey, (char *)DecryptFileData, MAX_WEIGHT_FILE_SIZE, WEIGHT_ENCRYPT_SIZE); + unsigned char* curPtr = DecryptFileData; + + //FILE *f = fopen("GYNet_pok_weight.des", "wb"); + //if (f == NULL) + //{ + // printf("Error opening file!\n"); + // //exit(1); + //} + //fwrite(DecryptFileData, descrypt_size, 1, f); + //fclose(f); + + int major; + int minor; + int revision; + //fread(&major, sizeof(int), 1, fp); + //fread(&minor, sizeof(int), 1, fp); + //fread(&revision, sizeof(int), 1, fp); + memcpy(&major, curPtr, sizeof(int)); + curPtr += sizeof(int); + memcpy(&minor, curPtr, sizeof(int)); + curPtr += sizeof(int); + memcpy(&revision, curPtr, sizeof(int)); + curPtr += sizeof(int); + + if ((major * 10 + minor) >= 2) { + //printf("\n seen 64 \n"); + uint64_t iseen = 0; + //fread(&iseen, sizeof(uint64_t), 1, fp); + memcpy(&iseen, curPtr, sizeof(uint64_t)); + curPtr += sizeof(uint64_t); + + *net->seen = iseen; + } + else { + //printf("\n seen 32 \n"); + //fread(net->seen, sizeof(int), 1, fp); + memcpy(net->seen, curPtr, sizeof(int)); + curPtr += sizeof(int); + } + int transpose = (major > 1000) || (minor > 1000); + + int i; + for (i = 0; i < net->n && i < cutoff; ++i) { + layer l = net->layers[i]; + if (l.dontload) continue; + if (l.type == CONVOLUTIONAL) { + curPtr = (unsigned char *)load_convolutional_weights_mem(l, curPtr); + } + if (l.type == CONNECTED) { + curPtr = (unsigned char *)load_connected_weights_mem(l, (char *)curPtr, transpose); + } + if (l.type == BATCHNORM) { + curPtr = (unsigned char *)load_batchnorm_weights_mem(l, (char *)curPtr); + } + if (l.type == CRNN) { + curPtr = (unsigned char *)load_convolutional_weights_mem(*(l.input_layer), curPtr); + curPtr = (unsigned char *)load_convolutional_weights_mem(*(l.self_layer), curPtr); + curPtr = (unsigned char *)load_convolutional_weights_mem(*(l.output_layer), curPtr); + } + if (l.type == RNN) { + curPtr = (unsigned char *)load_connected_weights_mem(*(l.input_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.self_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.output_layer), (char *)curPtr, transpose); + } + if (l.type == GRU) { + curPtr = (unsigned char *)load_connected_weights_mem(*(l.input_z_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.input_r_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.input_h_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.state_z_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.state_r_layer), (char *)curPtr, transpose); + curPtr = (unsigned char *)load_connected_weights_mem(*(l.state_h_layer), (char *)curPtr, transpose); + } + if (l.type == LOCAL) { + int locations = l.out_w*l.out_h; + int size = l.size*l.size*l.c*l.n*locations; + //fread(l.biases, sizeof(float), l.outputs, fp); + //fread(l.weights, sizeof(float), size, fp); + memcpy(l.biases, curPtr, sizeof(float)*l.outputs); + curPtr += sizeof(float)*l.outputs; + memcpy(l.weights, curPtr, sizeof(float)*size); + curPtr += sizeof(float)*l.size; + +#ifdef GPU + if (gpu_index >= 0) { + push_local_layer(l); + } +#endif + } + } + fprintf(stderr, "\nDone!\n"); + if (DecryptFileData) { + free(DecryptFileData); + DecryptFileData = NULL; + } +} + +convolutional_layer parse_convolutional_mem(list *options, size_params params) +{ + int n = option_find_int(options, "filters", 1); + int size = option_find_int(options, "size", 1); + int stride = option_find_int(options, "stride", 1); + int pad = option_find_int_quiet(options, "pad", 0); + int padding = option_find_int_quiet(options, "padding", 0); + if (pad) padding = size / 2; + + char *activation_s = option_find_str(options, "activation", "logistic"); + ACTIVATION activation = get_activation(activation_s); + + int batch, h, w, c; + h = params.h; + w = params.w; + c = params.c; + batch = params.batch; + if (!(h && w && c)) error("Layer before convolutional layer must output image."); + int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); + int binary = option_find_int_quiet(options, "binary", 0); + int xnor = option_find_int_quiet(options, "xnor", 0); + int use_bin_output = option_find_int_quiet(options, "bin_output", 0); + + convolutional_layer layer = make_convolutional_layer_mem(batch, h, w, c, n, size, stride, padding, activation, batch_normalize, binary, xnor, params.net->adam, use_bin_output); + layer.flipped = option_find_int_quiet(options, "flipped", 0); + layer.dot = option_find_float_quiet(options, "dot", 0); + + if (params.net->adam) { + layer.B1 = params.net->B1; + layer.B2 = params.net->B2; + layer.eps = params.net->eps; + } + + return layer; +} + +layer parse_yolo_mem(list *options, size_params params) +{ + int classes = option_find_int(options, "classes", 20); + int total = option_find_int(options, "num", 1); + int num = total; + + char *a = option_find_str(options, "mask", 0); + int *mask = parse_yolo_mask(a, &num); + int max_boxes = option_find_int_quiet(options, "max", 90); + layer l = make_yolo_layer_mem(params.batch, params.w, params.h, num, total, mask, classes, max_boxes); + if (l.outputs != params.inputs) { + printf("Error: l.outputs == params.inputs \n"); + printf("filters= in the [convolutional]-layer doesn't correspond to classes= or mask= in [yolo]-layer \n"); +#if 1 + stop_test_nn_cavalry("Error: l.outputs == params.inputs"); + //stop_server(); + +#endif + exit(EXIT_FAILURE); + } + //assert(l.outputs == params.inputs); + + //l.max_boxes = option_find_int_quiet(options, "max", 90); + l.jitter = option_find_float(options, "jitter", .2); + l.focal_loss = option_find_int_quiet(options, "focal_loss", 0); + + l.ignore_thresh = option_find_float(options, "ignore_thresh", .5); + l.truth_thresh = option_find_float(options, "truth_thresh", 1); + l.random = option_find_int_quiet(options, "random", 0); + + char *map_file = option_find_str(options, "map", 0); + if (map_file) l.map = read_map(map_file); + + a = option_find_str(options, "anchors", 0); + if (a) { + int len = strlen(a); + int n = 1; + int i; + for (i = 0; i < len; ++i) { + if (a[i] == ',') ++n; + } + for (i = 0; i < n && i < total * 2; ++i) { + float bias = atof(a); + l.biases[i] = bias; + a = strchr(a, ',') + 1; + } + } + return l; +} + +maxpool_layer parse_maxpool_mem(list *options, size_params params) +{ + int stride = option_find_int(options, "stride", 1); + int size = option_find_int(options, "size", stride); + int padding = option_find_int_quiet(options, "padding", size - 1); + + int batch, h, w, c; + h = params.h; + w = params.w; + c = params.c; + batch = params.batch; + if (!(h && w && c)) error("Layer before maxpool layer must output image."); + + maxpool_layer layer = make_maxpool_layer_mem(batch, h, w, c, size, stride, padding); + return layer; +} + +layer parse_upsample_mem(list *options, size_params params, network net) +{ + + int stride = option_find_int(options, "stride", 2); + layer l = make_upsample_layer_mem(params.batch, params.w, params.h, params.c, stride); + l.scale = option_find_float_quiet(options, "scale", 1); + return l; +} + +layer parse_shortcut_mem(list *options, size_params params, network net) +{ + char *l = option_find(options, "from"); + int index = atoi(l); + if (index < 0) index = params.index + index; + + int batch = params.batch; + layer from = net.layers[index]; + + layer s = make_shortcut_layer_mem(batch, index, params.w, params.h, params.c, from.out_w, from.out_h, from.out_c); + + char *activation_s = option_find_str(options, "activation", "linear"); + ACTIVATION activation = get_activation(activation_s); + s.activation = activation; + return s; +} + diff --git a/src/parser.h b/src/parser.h new file mode 100644 index 0000000..f615d71 --- /dev/null +++ b/src/parser.h @@ -0,0 +1,20 @@ +#pragma once +#ifndef PARSER_H +#define PARSER_H +#include "define_inc.h" +#include "darknet.h" +#include "network.h" + +network *parse_network_cfg(char *filename); +network parse_network_cfg_custom(char *filename, int batch); +network parse_network_cfg_custom_mem(char *filename, int batch); +void save_network(network net, char *filename); +void save_weights(network *net, char *filename); +void save_weights_upto(network *net, char *filename, int cutoff); +void save_weights_double(network *net, char *filename); +void load_weights(network *net, char *filename); +void load_weights_mem(network *net, char *filename); +void load_weights_upto(network *net, char *filename, int start, int cutoff); +void load_weights_upto_mem(network *net, char *filename, int cutoff); + +#endif diff --git a/src/pns.c b/src/pns.c new file mode 100644 index 0000000..36e8b6c --- /dev/null +++ b/src/pns.c @@ -0,0 +1,2232 @@ +#if 1 + +#include "pns.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +#ifdef GY_OS_AMBA +// #include "radar_receive.h" +//#include "radar_parser.h" +#endif + +struct MemoryStruct +{ + char memory[MEMORY_SIZE];//256KB + size_t size; +}; + +struct data { + char trace_ascii; /* 1 or 0 */ +}; + +extern pthread_mutex_t mutex_pns; +extern pthread_mutex_t mutex_snap; +//extern pthread_mutex_t mutex_get_canvas; + +const char* key_for_ddEnc_ddDec = "qazwsxmeritlilin22988988"; +//char global_url_for_pns[64] = "http://cloud.ddnsipcam.com/pns/snapshot.php"; +char global_url_for_pns[64] = "https://cloud.ddnsipcam.com/pns/"; +char Global_URL_for_DDNS[128] = "https://www.ddnsipcam.com/tool/ddns-acc-chk.php"; + +#ifdef GY_OS_AMBA +static char g_canvas_addr[MAX_NUM_SNAP_IMAGES][MAX_IMG_SIZE] = { 0 }; +static size_t g_canvas_size[MAX_NUM_SNAP_IMAGES] = { 0 }; +#endif +static int g_start_to_store_canvas = 0; +#ifdef GY_OS_AMBA +static size_t g_current_index_canvas_images = 0; +static size_t g_cache_canvas_size = 0; +#endif +static int canvas_live_mode_flag = 1; + +CURL* curl_handle_for_snapshot = NULL; + +#if 1 +void ddDec(char* input_str,char *restored_str) +{ + size_t decoded_scram_str_len = 0; + unsigned char temp_str[8 * 8192] = { 0 }; + base64_decode(input_str, strlen(input_str), &decoded_scram_str_len, temp_str); + char decoded_scrambled_str[8 * 8192] = {0}; + strncpy(decoded_scrambled_str, (char *)temp_str, decoded_scram_str_len); + decoded_scrambled_str[decoded_scram_str_len] = '\0'; + //printf("[dd Dec] Scrambled string decoded from base64: %s\n", decoded_scrambled_str); + size_t scrambled_str_len = strlen(decoded_scrambled_str); + //printf("---------------[dd Dec] Length: %ld\n", scrambled_str_len); + + // Generate processed key string by MD5 function. + unsigned char key_by_md5[16] = { 0 }; + md5String((char*)key_for_ddEnc_ddDec, (uint8_t*)key_by_md5); + char key_by_md5_in_char[DEF_MD5_LENGTH + 1] = { 0 }; + for (int i = 0; i < 16; i++) + sprintf(&key_by_md5_in_char[i * 2], "%02x", key_by_md5[i]); + //key_by_md5_in_char[DEF_MD5_LENGTH] = '\0'; + //printf("[dd Dec] MD5 string from hex code: %s\n", key_by_md5_in_char); + + /*if (key_by_md5) { + free(key_by_md5); + key_by_md5 = NULL; + }*/ + + //char* restored_str = malloc(scrambled_str_len + 1); + for (int i = 0; i < scrambled_str_len; i++) + { + //printf("input_str[%d]=%c --> %d\n", i, input_str[i], (int)input_str[i]); + //printf("extract_md5_char[%d]=%c --> %d\n", i, extract_md5_char[i], (int)extract_md5_char[i]); + //int value = ((int)input_str[i] + (int)extract_md5_char[i]) % 256; + int value = (256 + (int)decoded_scrambled_str[i] - (int)key_by_md5_in_char[i % DEF_MD5_LENGTH]) % 256; + restored_str[i] = (char)value; + //printf("value=%d\n", value); + } + restored_str[scrambled_str_len] = '\0'; + //printf("[dd Dec] Restored string: %s\n", restored_str); + /*if (decoded_scrambled_str) { + free(decoded_scrambled_str); + decoded_scrambled_str = NULL; + }*/ +} +#endif +// External callers need to release the returned string. +void ddEnc(char* input_str, char * output_str) +{ + int input_str_len = strlen(input_str); + //printf("[dd Enc] Input string: %s\n", input_str); + //printf("[dd Enc] Length: %d\n", input_str_len); + + // Generate processed key string by MD5 function. + unsigned char key_by_md5[16] = { 0 }; + md5String((char*)key_for_ddEnc_ddDec, (uint8_t*)key_by_md5); + char key_by_md5_in_char[DEF_MD5_LENGTH + 1] = { 0 }; + for (int i = 0; i < (DEF_MD5_LENGTH/2); i++) + sprintf(&key_by_md5_in_char[i * 2], "%02x", key_by_md5[i]); + //key_by_md5_in_char[DEF_MD5_LENGTH] = '\0'; + //printf("[dd Enc] MD5 string (hex code): %s\n", key_by_md5_in_char); + + /*if (key_by_md5) { + free(key_by_md5); + key_by_md5 = NULL; + }*/ + + // Scramble original string by MD5 key string. + unsigned char scrambled_values[8 * 8192] = { 0 }; + for (int i = 0; i < input_str_len; i++) + { + int value = ((int)input_str[i] + (int)key_by_md5_in_char[i % DEF_MD5_LENGTH]) % 256; + scrambled_values[i] = (unsigned char)value; + //printf("value=%d\n", value); + } + //scrambled_values[input_str_len] = '\0'; + //printf("[dd Enc] Scrambled string (ASCII): %s\n", scrambled_values); + + size_t base64_encode_len = 0; + char original_base64_output[8*8192] = { 0 }; + base64_encode(scrambled_values, input_str_len, &base64_encode_len, original_base64_output); + //printf("sizeof(original_base64_output)=%ld\n", sizeof(original_base64_output)); + //printf("[dd Enc] Base64 encoded length: %ld\n", base64_encode_len); + + strncpy(output_str, original_base64_output, base64_encode_len); + output_str[base64_encode_len] = '\0'; + //printf("[dd Enc] Base64 encoded scrambled string: %s\n", output_str); + + +#if 0 + // Simply test ddDec from the end of the ddEnc. + // Should be removed before the project is released. + char* test_str = ddDec(output_str); + if (test_str) { + free(test_str); + test_str = NULL; + } +#endif + +} + +#ifdef CURL_SAVE_JPG_TO_BUFF + +static size_t WriteMemoryCallback(void* contents, size_t size, size_t nmemb, void* user_ptr) +{ + size_t realsize = size * nmemb; + struct MemoryStruct* mem = (struct MemoryStruct*)user_ptr; + + /* + char* ptr = realloc(mem->memory, mem->size + realsize + 1); + if (!ptr) { + // out of memory! + printf("not enough memory (realloc returned NULL)\n"); + return 0; + } + */ + + if (mem->size + realsize + 1 >= MEMORY_SIZE) { + // out of memory! + printf("memory is over MEMORY_SIZE size (returned NULL)\n"); + return 0; + } + + //mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} +#else +#if 0 +struct FtpFile +{ + const char* filename; + FILE* stream; +}; + +static size_t WriteToFileCallback(void* buffer, size_t size, size_t nmemb, void* user_ptr) +{ + struct FtpFile* out = (struct FtpFile*)user_ptr; + if (!out->stream) { + /* open file for writing */ + out->stream = fopen(out->filename, "wb"); + if (!out->stream) + return -1; /* failure, can't open file to write */ + } + return fwrite(buffer, size, nmemb, out->stream); +} +#endif +#endif + +static size_t WriteResponseString(void* contents, size_t size, size_t nmemb, void* user_ptr) +{ + size_t realsize = size * nmemb; + struct MemoryStruct* mem = (struct MemoryStruct*)user_ptr; + + /* + char* ptr = realloc(mem->memory, mem->size + realsize + 1); + if (!ptr) { + // out of memory! + printf("not enough memory (realloc returned NULL)\n"); + return 0; + }*/ + + if (mem->size + realsize + 1 >= MEMORY_SIZE)//25KB + { + printf("over MEMORY_SIZE KB memory (returned NULL)\n"); + return 0; + } + + //mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} + +#if 0 +static void dump(const char* text, FILE* stream, unsigned char* ptr, size_t size, char nohex) +{ + size_t i; + size_t c; + + unsigned int width = 0x10; + + if (nohex) + /* without the hex output, we can fit more on screen */ + width = 0x40; + + fprintf(stream, "%s, %10.10lu bytes (0x%8.8lx)\n", + text, (unsigned long)size, (unsigned long)size); + + for (i = 0; i < size; i += width) { + + fprintf(stream, "%4.4lx: ", (unsigned long)i); + + if (!nohex) { + /* hex not disabled, show it */ + for (c = 0; c < width; c++) + if (i + c < size) + fprintf(stream, "%02x ", ptr[i + c]); + else + fputs(" ", stream); + } + + for (c = 0; (c < width) && (i + c < size); c++) { + /* check for 0D0A; if found, skip past and start a new line of output */ + if (nohex && (i + c + 1 < size) && ptr[i + c] == 0x0D && + ptr[i + c + 1] == 0x0A) { + i += (c + 2 - width); + break; + } + fprintf(stream, "%c", + (ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.'); + /* check again for 0D0A, to avoid an extra \n if it's at width */ + if (nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D && + ptr[i + c + 2] == 0x0A) { + i += (c + 3 - width); + break; + } + } + fputc('\n', stream); /* newline */ + } + fflush(stream); +} +#endif +#if 0 +static int my_trace(CURL* handle, curl_infotype type, char* data, size_t size, void* userp) +{ + struct data* debug_data = (struct data*)userp; + const char* text; + (void)handle; /* prevent compiler warning */ + + switch (type) { + case CURLINFO_TEXT: + fprintf(stderr, "== Info: %s", data); + /* FALLTHROUGH */ + default: /* in case a new one is introduced to shock us */ + return 0; + + case CURLINFO_HEADER_OUT: + text = "=> Send header"; + break; + case CURLINFO_DATA_OUT: + text = "=> Send data"; + break; + case CURLINFO_SSL_DATA_OUT: + text = "=> Send SSL data"; + break; + case CURLINFO_HEADER_IN: + text = "<= Recv header"; + break; + case CURLINFO_DATA_IN: + text = "<= Recv data"; + break; + case CURLINFO_SSL_DATA_IN: + text = "<= Recv SSL data"; + break; + } + + dump(text, stderr, (unsigned char*)data, size, debug_data->trace_ascii); + return 0; +} +#endif +int PNS_Get_Device_Name(int arg_url_encoded_or_not,char *returned_msg) +{ + int get_OK = 0; + pthread_mutex_lock(&mutex_curl); + + /*if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + }*/ + + //pthread_mutex_lock(&mutex_pns); + //char error_msg[CURL_ERROR_SIZE]; + CURLcode result = 0; + CURL* curl_handle_for_dev_name = g_http_handle; // Initialization for current handler. + + if (curl_handle_for_dev_name) { + + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_HTTPHEADER, pList); + + // Specify URL for getting the snapshot. + char url_for_dev_name[50] = "http://"; + //strcat(url_for_dev_name, accountData[0].account_username); + //strcat(url_for_dev_name, ":"); + //strcat(url_for_dev_name, accountData[0].account_password); + strcat(url_for_dev_name, "127.0.0.1:");//@127.0.0.1: + strcat(url_for_dev_name, accountData[0].account_port); + strcat(url_for_dev_name, "/server"); + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_URL, url_for_dev_name); // Invoke "server" command from localhost address. + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_PORT, port_num); + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_CONNECTTIMEOUT, 5); // ]wsuWɡA + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_TIMEOUT, 10); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_NOSIGNAL, 1); + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_SSL_VERIFYPEER, 0); //ҮѨ + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_SSL_VERIFYHOST, 0); //ҮѨ + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_LOW_SPEED_TIME, 5L); + + //printf("[PNS Get Device Name] CURLOPT_URL: %s\n", curl_easy_strerror(result)); + //curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_ERRORBUFFER, error_msg); + //printf("[PNS Get Device Name] CURLOPT_ERRORBUFFER: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_WRITEFUNCTION, WriteResponseString); + //printf("[PNS Get Device Name] CURLOPT_WRITEFUNCTION: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_TCP_FASTOPEN, 1L); + + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_responded_msg = &memory_temp_msg; + //ptr_responded_msg->memory = NULL; + ptr_responded_msg->size = 0; + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_WRITEDATA, ptr_responded_msg); + //printf("[PNS Get Device Name] CURLOPT_WRITEDATA: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(curl_handle_for_dev_name, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + result = curl_easy_perform(curl_handle_for_dev_name); + + //printf("[PNS Get Device Name] curl_easy_perform: %s\n", curl_easy_strerror(result)); + char dev_name[512] = { 0 }; + //char* returned_msg = NULL; + if (result != CURLE_OK) // Check for errors + { + char* err_msg = (char*)curl_easy_strerror(result); + strcpy(returned_msg, err_msg); + write_to_logs_html(returned_msg, "PNS Get Device Name", "ERROR", SystemSetting.enable_system_logs); + fprintf(stderr, "[PNS Get Device Name] Failed to initialize the CURL handler for curl_handle_for_dev_name. Reason: %s\n", err_msg); + //printf("[PNS Get Device Name] Failed to initialize the CURL for curl_handle_for_dev_name. Reason: %s\n", error_msg); + } + else + { + //printf("[PNS Get Device Name] ptr_responded_msg->size = %ld\n", ptr_responded_msg->size); + //printf("[PNS Get Device Name] ptr_responded_msg->memory = %s\n", ptr_responded_msg->memory); + + char *sFindStr_Start = NULL; + char *sFindStr_End = NULL; + + sFindStr_Start = strstr(ptr_responded_msg->memory, "device name="); + + if (sFindStr_Start) { + sFindStr_Start = sFindStr_Start + strlen("device name="); + sFindStr_End = strstr(sFindStr_Start, "\n"); + } + + if (sFindStr_End) { + + if ((sFindStr_End - sFindStr_Start) > 0) { + memcpy(dev_name, sFindStr_Start, (sFindStr_End - sFindStr_Start)); + +#ifdef GY_OS_AMBA + check_ptz(ptr_responded_msg->memory); +#endif + + char *sFindStr_Start_svn = NULL; + char *sFindStr_End_svn = NULL; + + sFindStr_Start_svn = strstr(ptr_responded_msg->memory, "SVN_VERSION="); + + if (sFindStr_Start_svn) { + sFindStr_Start_svn = sFindStr_Start_svn + strlen("SVN_VERSION="); + sFindStr_End_svn = strstr(sFindStr_Start_svn, "\n"); + } + + if (sFindStr_End_svn) { + if ((sFindStr_End_svn - sFindStr_Start_svn) > 0) { + char svn_version_name[512] = { 0 }; + char temp_svn_version_name[512] = { 0 }; + + memcpy(svn_version_name, sFindStr_Start_svn, (sFindStr_End_svn - sFindStr_Start_svn)); + + int check_sdk_ok = 0; + int index_temp = 0; + //printf("\n------svn_version_name:%sEND\n", svn_version_name); + for (int index_c = 0; index_c < (int)strlen(svn_version_name); index_c++) { + if (isdigit(svn_version_name[index_c])) { + check_sdk_ok = 1; + temp_svn_version_name[index_temp] = svn_version_name[index_c]; + index_temp++; + } + } + + if (check_sdk_ok == 1) { + temp_svn_version_name[index_temp] = '\0'; + g_sdk_version = atoi(temp_svn_version_name); + //printf("\n----------g_sdk_version:%d\n", g_sdk_version); + } + } + } + + } + else + { + //pthread_mutex_unlock(&mutex_pns); + static const char err_msg[] = "(Device name fetching error)"; + strcpy(returned_msg, err_msg); + write_to_logs_html(returned_msg, "PNS Get Device Name", "ERROR", SystemSetting.enable_system_logs); + printf("[PNS Get Device Name] Device name fetching error.\n"); + } + } + else { + //pthread_mutex_unlock(&mutex_pns); + static const char err_msg[] = "(Device name is empty or too long)\n"; + strcpy(returned_msg, err_msg); + write_to_logs_html(returned_msg, "PNS Get Device Name", "ERROR", SystemSetting.enable_system_logs); + printf("[PNS Get Device Name] Device name is empty or too long.\n"); + } + } + curl_easy_reset(curl_handle_for_dev_name); + if (pList != NULL) + curl_slist_free_all(pList); + + ptr_responded_msg->size = 0; + + if (arg_url_encoded_or_not == 1 && strlen(dev_name) >= 1) + { + CURL* curl_for_url_encode = g_http_handle; + char* url_encoded_str = curl_easy_escape(curl_for_url_encode, dev_name, 0); // 0: Uses strlen() on the input string to find out the size. + strcpy(returned_msg, url_encoded_str); + //printf("[PNS Get Device Name] URL encoded device name: %s", returned_msg); + curl_free(url_encoded_str); + curl_easy_reset(curl_for_url_encode); + get_OK = 1; + } + + + /*if (ptr_responded_msg != NULL) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + } + pthread_mutex_unlock(&mutex_curl); + + return get_OK; +} + +// Based on the definitions from Vega's document "PNS2_API-1.pdf", part 2-1. +void PNS_Query_Service_Status(char* returned_msg) +{ + CURL* curl_handle_for_pns; + CURLcode res_pns; // For starting PNS and connections to the cloud. + //struct data debug_data_for_query; + pthread_mutex_lock(&mutex_curl); + curl_handle_for_pns = g_http_handle; // Initialization for each handler. + + + // cat: Category, pns/others + // act: Actions, such as check, send or list. + // vend: Vendor, 0 for LILIN, 1, 2, 3, 4, 5, 6, 7, and etc. + // ver: 2.1 + // prd: Production ready (keyword: prd) or development (keyword: dev) + // cno: Random check num. Server will add 1 in response. + // dt: Device type, 0:IPCam, 1:NVR, 2:NAV + // et: event type (no need in 2-1) + // eid: event ID (no need in 2-1) + // mac: MAC addr. (Done) + // msg: (no need in 2-1) + // tp: describe what kind of alarm motion event. For AI team, it's always 8 (or shown "ag==" after ddEnc). + // dt: date + // tm: time + // cu: camera URL + // cp: camera port + // vu: video URL of the event + // im: information + // ch: in which channel of the event + // de: device type + // mc: which MAC addr. detects the event + // dn: device name (URL encoded) + // es: event type string (AI event title in locale) + // en: event type ID + // ds: event description (AI event description in locale) + + const char* data0 = "{ \"cat\": \"oqPU\", \"act\" : \"lZ3GmJs=\", \"vend\" : \"Yg==\", \"ver\" : \"ZGOS\", \"prd\" : \"oqfF\", \"cno\" : \""; + + const char* data1 = "\", \"dt\" : \"Yg==\", \"et\" : \"\", \"eid\" : \"\", \"mac\" : \""; + + const char* data2 = "\" }"; + + /*const char* data2 = "\", \"msg\" : [ {\ + \"tp\" : \"ag==\",\ + \"dt\" : \"ZGWSbl1hZWJjlA==\",\ + \"tm\" : \"Y2ebZ2NqZmk=\",\ + \"cu\" : \"mqnVpWpfYmZelWZnlGQ=\",\ + \"cp\" : \"amWZZQ==\",\ + \"vu\" : \"mqnVpWpfYmZelWZnlGRm3M+ZnNNfmKHP0V+TlWVq\",\ + \"im\" : \"l66rZpNiia55zaedyp2N1L+Kec+KfGrgwoikzYuNZ9qLZ5qpeZmqnpOqfq7JqYCcr5+NvJGNpc7EnbTde6Rnog==\",\ + \"ch\" : \"Yg==\",\ + \"de\" : \""; + + const char* data3 = "\",\ + \"mc\" : \"YmWRe3ZzbG5mmWhn\",\ + \"dn\" : \"V3qWWmlgWG10iH1ri3Fvi6hm\",\ + \"es\" : \"\",\ + \"en\" : \"\",\ + \"ds\" : \"V3qVWnJxWG1yiH1oi3J5i6hr\" } ] }";*/ + + //-------------------------------------------------- + // Random number 0-999 for 'cno' field. + int rand_for_cno = rand() % 1000; + char str_rand_for_cno[8] = { 0 }; + snprintf(str_rand_for_cno, 5, "%d", rand_for_cno); + + char ddenc_str_rand_for_cno[8] = { 0 }; + ddEnc(str_rand_for_cno, ddenc_str_rand_for_cno); + //-------------------------------------------------- + + // MAC address + + char mac_addr[32] = { 0 }; + char mac_addr_temp[32] = { 0 }; + + memset(mac_addr_temp, 0x00, sizeof(mac_addr_temp)); + if (strlen(g_mac_address) >= 1) { + strcpy(mac_addr_temp,g_mac_address); + } + else { + GetMACAddress(mac_addr_temp); // Can use another function "GetMACAddress_WithoutDash" to reduce codes but need to verify after changing. + } + int index_mac_addr = 0; + for (int i = 0; i < (int)strlen(mac_addr_temp); i++) { + if (mac_addr_temp[i] == '-' || mac_addr_temp[i] == '\n') { + + } + else { + mac_addr[index_mac_addr] = mac_addr_temp[i]; + index_mac_addr++; + } + } + mac_addr[index_mac_addr] = '\0'; + + char ddenc_mac[32] = { 0 }; + ddEnc(mac_addr, ddenc_mac); + + //-------------------------------------------------- + // Calculate the total length of the data + //size_t total_len = strlen(data0) + strlen(ddenc_str_rand_for_cno) + strlen(data1) + strlen(ddenc_mac) + strlen(data2) + strlen(ddenc_device_name) + strlen(data3); + //size_t total_len = strlen(data0) + strlen(ddenc_str_rand_for_cno) + strlen(data1) + strlen(ddenc_mac) + strlen(data2); + + //-------------------------------------------------- + // Assemble the string for sending + char send_data[8 * 8192] = { 0 }; + strcpy(send_data, data0); + strcat(send_data, ddenc_str_rand_for_cno); + strcat(send_data, data1); + strcat(send_data, ddenc_mac); + strcat(send_data, data2); + //strcat(send_data, ddenc_device_name); + //strcat(send_data, data3); + //send_data[total_len] = '\0'; + //printf("[PNS Query Service Status] JSON string for querying: %s\n", send_data); + + //-------------------------------------------------- + // CURL section + struct curl_slist* headers = NULL; + headers = curl_slist_append(headers, "Accept: application/json"); + headers = curl_slist_append(headers, "Content-Type: application/json"); + headers = curl_slist_append(headers, "charset: utf-8"); + headers = curl_slist_append(headers, "Connection: close"); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_HTTPHEADER, headers); + + // Specify URL to send POST data + //CURLcode result = 0; + curl_easy_setopt(curl_handle_for_pns, CURLOPT_URL, global_url_for_pns); + //printf("[PNS Query Service Status] CURLOPT_URL: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_USE_SSL, CURLUSESSL_ALL); + //printf("[PNS] CURLOPT_USE_SSL: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_SSL_VERIFYPEER, 1L); + //printf("[PNS Query Service Status] CURLOPT_SSL_VERIFYPEER: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_SSL_VERIFYHOST, 2L); + //printf("[PNS Query Service Status] CURLOPT_SSL_VERIFYHOST: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_USERAGENT, "curl/7.64.1"); + //printf("[PNS] CURLOPT_USERAGENT: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(curl_handle_for_pns, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_LOW_SPEED_TIME, 10L); + + //result = curl_easy_setopt(http_handle, CURLOPT_USERNAME, ""); + //printf("[PNS] CURLOPT_USERNAME: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(http_handle, CURLOPT_PASSWORD, ""); + //printf("[PNS] CURLOPT_PASSWORD: %s\n", curl_easy_strerror(result)); + + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + //printf("[PNS] CURLOPT_SSLVERSION: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_CAINFO, "/emmc/plugin/Aida_data/cacert.pem"); + + curl_easy_setopt(curl_handle_for_pns, CURLOPT_SSL_VERIFYPEER, 0); //ҮѨ + curl_easy_setopt(curl_handle_for_pns, CURLOPT_SSL_VERIFYHOST, 0); //ҮѨ + //printf("[PNS Query Service Status] CURLOPT_CAINFO: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_SSL_CIPHER_LIST, "TLSv1.2"); // No need. + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_TLS13_CIPHERS, NULL); // No need. + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_USERNAME, "xxx"); // No need. + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_PASSWORD, "yyy"); // No need. + //char error_for_pns[CURL_ERROR_SIZE]; + //curl_easy_setopt(curl_handle_for_pns, CURLOPT_ERRORBUFFER, error_for_pns); + //printf("[PNS Query Service Status] CURLOPT_ERRORBUFFER: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_POST, 1L); // Switch on full protocol/debug output + //printf("[PNS Query Service Status] CURLOPT_POST: %s\n", curl_easy_strerror(result)); + + //curl_easy_setopt(curl_handle_for_pns, CURLOPT_READFUNCTION, read_callback); + //curl_easy_setopt(curl_handle_for_pns, CURLOPT_READDATA, &payload); + + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_responded_msg = &memory_temp_msg; + //ptr_responded_msg->memory = NULL; + ptr_responded_msg->size = 0; + + curl_easy_setopt(curl_handle_for_pns, CURLOPT_WRITEFUNCTION, WriteResponseString); + //printf("[PNS Query Service Status] CURLOPT_WRITEFUNCTION: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_WRITEDATA, ptr_responded_msg); + //printf("[PNS Query Service Status] CURLOPT_WRITEDATA: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(curl_handle_for_pns, CURLOPT_POSTFIELDSIZE, strlen(send_data)); + //printf("[PNS Query Service Status] CURLOPT_POSTFIELDSIZE: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_POSTFIELDS, send_data); + //printf("[PNS Query Service Status] CURLOPT_POSTFIELDS: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_DEBUGFUNCTION, my_trace); + //printf("[PNS] CURLOPT_DEBUGFUNCTION: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handle_for_pns, CURLOPT_DEBUGDATA, &debug_data_for_query); + //printf("[PNS] CURLOPT_DEBUGDATA: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_VERBOSE, 1L); // Switch on full protocol/debug output + //printf("[PNS Query Service Status] CURLOPT_VERBOSE: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(curl_handle_for_pns, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(curl_handle_for_pns, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + res_pns = curl_easy_perform(curl_handle_for_pns); + if (res_pns != CURLE_OK) + { + char* err_msg = (char*)curl_easy_strerror(res_pns); + strcpy(returned_msg, err_msg); + fprintf(stderr, "[PNS Query Service Status] Failed to initialize the CURL handler for PNS. Reason: %s\n", returned_msg); + //printf("[PNS Query Service Status] Failed to initialize the CURL for PNS Query. Reason: %s\n", error_for_pns); + } + else + { + strcpy(returned_msg, ptr_responded_msg->memory); + //printf("[PNS Query Service Status] curl_easy_perform(curl_handle_for_pns) succeeded.\n"); + } + + // Should return: + // {"err":"Yg==","msg":"oaA=","ut":"Y2uTZmhjaWVolw==","cat":"oqPU","act":"paPCpaOYoqk=","mac":"YmWRe3ZzZWlmpG54","cno":"Y2eV","vend":"Yg==","prd":"oqfF","dt":"Yg==","et":"Yg==","eid":"a24=","task":"Yg=="} + + + curl_slist_free_all(headers); + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + curl_easy_reset(curl_handle_for_pns); + + pthread_mutex_unlock(&mutex_curl); +} + + +int count_snap_curl = -1; +size_t PNS_Get_Snapshot_From_IPCam(char* file_name, char* img_addr, int enable_to_save_file)//remoteݰ_ӵ{XOեΪAoN +{ + pthread_mutex_lock(&mutex_curl); + /*if (count_snap_curl == -1) { + count_snap_curl = 0; + initial_curl_handle_for_snapshot(); + } + else if(curl_handle_for_snapshot == NULL)*/{ + //count_snap_curl = 0; + initial_curl_handle_for_snapshot(); + } + + //count_snap_curl++; + + int returned_size = 0; + + // Specify URL for getting the snapshot. + char url_for_snapshot[50] = "http://"; + //strcat(url_for_snapshot, accountData[0].account_username); + //strcat(url_for_snapshot, ":"); + //strcat(url_for_snapshot, accountData[0].account_password); + strcat(url_for_snapshot, "127.0.0.1:");//@127.0.0.1: + strcat(url_for_snapshot, accountData[0].account_port); + strcat(url_for_snapshot, "/snap"); + + //char error_for_snapshot[CURL_ERROR_SIZE]; + int check_reboot = 0; + + if (curl_handle_for_snapshot) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_URL, url_for_snapshot); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)accountData[0].account_port); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_PORT, port_num); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_LOW_SPEED_TIME, 1L); + + //curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_ERRORBUFFER, error_for_snapshot); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_TCP_FASTOPEN, 1L); + + //printf("[PNS] Start to fetch the snapshot from IP Cam.\n"); + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_received_img = &memory_temp_msg; + //ptr_received_img->memory = NULL; /* will be grown as needed by the realloc above */ + ptr_received_img->size = 0; /* no data at this point */ + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); // Send all data to this function + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_WRITEDATA, ptr_received_img); // Pass 'chunk' struct to the callback function + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + CURLcode res_snapshot = curl_easy_perform(curl_handle_for_snapshot); + if (res_snapshot != CURLE_OK) // Check for errors + { + fprintf(stderr, "[PNS Get Snapshot From IPCam] Failed to initialize the CURL handler for snapshot. Reason: %s\n", curl_easy_strerror(res_snapshot)); + //printf("[PNS : Query For Service] Failed to initialize the CURL for snapshot. Reason: %s\n", error_for_snapshot); + + if (res_snapshot == CURLE_OUT_OF_MEMORY) { + printf("[PNS Get Snapshot From IPCam]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + check_reboot = 1; + + + } + } + else + { + //printf("[PNS Get Snapshot From IPCam] ptr_received_img->memory addr. = %p\n", ptr_received_img->memory); + //printf("[PNS Get Snapshot From IPCam] ptr_received_img->size = %lu (bytes retrieved)\n", (unsigned long)ptr_received_img->size); +#if 1 + + memcpy(img_addr, &ptr_received_img->memory, ptr_received_img->size); + returned_size = ptr_received_img->size; + + if (enable_to_save_file == 1) { + pthread_mutex_lock(&mutex_snap); // Protect the file I/O. + + char write_filename[256] = "/emmc/plugin/Aida_data/storage/"; + strcat(write_filename, file_name); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + fwrite(ptr_received_img->memory, sizeof(char), ptr_received_img->size, fp); + //printf("[PNS Get Snapshot From IPCam] Wrote to the file: %s.\n", write_filename); + fclose(fp); + } + else + printf("[PNS Get Snapshot From IPCam] (For debugging) Error occurred when opening file I/O.\n"); + pthread_mutex_unlock(&mutex_snap); // Protect the file I/O. + } +#endif + } + if (pList != NULL) + curl_slist_free_all(pList); + ptr_received_img->size = 0; + /*if (ptr_received_img != NULL) { + free(ptr_received_img); + ptr_received_img = NULL; + }*/ + curl_easy_reset(curl_handle_for_snapshot); + } + else + printf("[PNS Get Snapshot From IPCam] CURL failed to initialize!\n"); + + + pthread_mutex_unlock(&mutex_curl); + + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "PNS Get Snapshot", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "PNS Get Snapshot", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + + return returned_size; +} +#ifdef GY_OS_AMBA +int count_remote_snap_curl = -1; +size_t PNS_Get_Snapshot_From_Remote_IPCam(char* file_name, char* img_addr, int enable_to_save_file) // N remote su覡gb functionAקKvT쥻 PNS_Get_Snapshot_From_IPCam +{ + pthread_mutex_lock(&mutex_curl); + /*if (count_remote_snap_curl == -1) { + count_remote_snap_curl = 0; + initial_curl_handle_for_snapshot(); + } + else if(curl_handle_for_snapshot == NULL)*/{ + //count_remote_snap_curl = 0; + initial_curl_handle_for_snapshot(); + } + + count_remote_snap_curl++; + + int returned_size = 0; + + // Specify URL for getting the snapshot. + char url_for_snapshot[50] = "http://"; + // q setting 쪺 IP M Port إ߳su + strcat(url_for_snapshot, tofData.tof_camera_ip); + strcat(url_for_snapshot, ":"); + strcat(url_for_snapshot, tofData.tof_camera_port); + strcat(url_for_snapshot, "/snap"); + + //char error_for_snapshot[CURL_ERROR_SIZE]; + int check_reboot = 0; + + if (curl_handle_for_snapshot) + { + struct curl_slist *pList = NULL; + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "charset: utf-8"); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_URL, url_for_snapshot); + // curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_USERNAME, accountData[0].account_username); + // curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_PASSWORD, accountData[0].account_password); + // long port_num = atoi((const char*)accountData[0].account_port); + // curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_PORT, port_num); + + // q setting 쪺 user & password & port number إ߳su + char buf_account[512] = { 0 }; + urldecode((unsigned char *)tofData.tof_camera_username, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)tofData.tof_camera_password, (unsigned char *)buf_account2); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_PASSWORD, buf_account2); + long port_num = atoi((const char*)tofData.tof_camera_port); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_PORT, port_num); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_CONNECTTIMEOUT, 1); // ]wsuWɡA + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_TIMEOUT, 3); + //curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_ACCEPT_ENCODING, "gzip"); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_LOW_SPEED_TIME, 1L); + + //curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_ERRORBUFFER, error_for_snapshot); + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_TCP_FASTOPEN, 1L); + + //printf("[PNS] Start to fetch the snapshot from IP Cam.\n"); + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_received_img = &memory_temp_msg; + //ptr_received_img->memory = NULL; /* will be grown as needed by the realloc above */ + ptr_received_img->size = 0; /* no data at this point */ + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); // Send all data to this function + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_WRITEDATA, ptr_received_img); // Pass 'chunk' struct to the callback function + + curl_easy_setopt(curl_handle_for_snapshot, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + CURLcode res_snapshot = curl_easy_perform(curl_handle_for_snapshot); + if (res_snapshot != CURLE_OK) // Check for errors + { + fprintf(stderr, "[PNS Get Snapshot From Remote IPCam] Failed to initialize the CURL handler for snapshot. Reason: %s\n", curl_easy_strerror(res_snapshot)); + //printf("[PNS : Query For Service] Failed to initialize the CURL for snapshot. Reason: %s\n", error_for_snapshot); + + if (res_snapshot == CURLE_OUT_OF_MEMORY) { + printf("[PNS Get Snapshot From Remote IPCam]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + check_reboot = 1; + + + } + } + else + { + //printf("[PNS Get Snapshot From Remote IPCam] ptr_received_img->memory addr. = %p\n", ptr_received_img->memory); + //printf("[PNS Get Snapshot From Remote IPCam] ptr_received_img->size = %lu (bytes retrieved)\n", (unsigned long)ptr_received_img->size); +#if 1 + + memcpy(img_addr, &ptr_received_img->memory, ptr_received_img->size); + returned_size = ptr_received_img->size; + + if (enable_to_save_file == 1) { + pthread_mutex_lock(&mutex_snap); // Protect the file I/O. + + char write_filename[256] = "/emmc/plugin/Aida_data/storage/"; + strcat(write_filename, file_name); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + fwrite(ptr_received_img->memory, sizeof(char), ptr_received_img->size, fp); + //printf("[PNS Get Snapshot From Remote IPCam] Wrote to the file: %s.\n", write_filename); + fclose(fp); + } + else + printf("[PNS Get Snapshot From Remote IPCam] (For debugging) Error occurred when opening file I/O.\n"); + pthread_mutex_unlock(&mutex_snap); // Protect the file I/O. + } +#endif + } + if (pList != NULL) + curl_slist_free_all(pList); + ptr_received_img->size = 0; + /*if (ptr_received_img != NULL) { + free(ptr_received_img); + ptr_received_img = NULL; + }*/ + curl_easy_reset(curl_handle_for_snapshot); + } + else + printf("[PNS Get Snapshot From Remote IPCam] CURL failed to initialize!\n"); + + pthread_mutex_unlock(&mutex_curl); + + if (check_reboot == 1) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); + write_to_logs_html(temp_msg, "PNS Get Snapshot remote", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "PNS Get Snapshot remote", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + + return returned_size; +} +#endif + +void initial_curl_handle_for_snapshot() { + //curl_handle_for_snapshot = curl_easy_init(); // Initialization for each handler. + curl_handle_for_snapshot = g_http_handle; +} + +void clean_curl_handle_for_snapshot() { + //curl_easy_cleanup(curl_handle_for_snapshot); + //curl_handle_for_snapshot = NULL; + curl_easy_reset(curl_handle_for_snapshot); +} + +void *Get_canvas_From_IPCam_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("get_canvas"); + //int count_snap = 0; +#ifdef GY_OS_AMBA + char g_cache_canvas_addr[MAX_IMG_SIZE] = { 0 }; + while (canvas_live_mode_flag) { +#if 1 + if ((viewChannelData[0].enable_traffic /*|| viewChannelData[0].enable_anpr*/) /*&& + (strcmp(SystemSetting.enable_display_properties, "Yes") == 0 || strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 || + (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0))*/ + && AI_fps >= 1) //uPɡAh䴩get_g_canvas_addrAfpsC + { + /*if (g_osdSysTimeStamp < 1000000000) { + usSleep(3000000); + continue; + }*/ + set_record_process_note("get_canvas_start"); + //pthread_mutex_lock(&mutex_get_canvas); + pthread_mutex_lock(&mutex_get_network_input); + //memset(g_canvas_addr, 0x00, MAX_IMG_SIZE); + //g_cache_canvas_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_cache_canvas_addr, 0); + memset(g_cache_canvas_addr,0x00,sizeof(g_cache_canvas_addr)); + g_cache_canvas_size = (size_t)get_ori_c_image(g_cache_canvas_addr); + + //printf("\n------MAX_IMG_SIZE:%d,g_cache_canvas_size:%d\n", MAX_IMG_SIZE, g_cache_canvas_size); + + if (g_cache_canvas_size >= 1) { + memcpy(g_canvas_addr[g_current_index_canvas_images], g_cache_canvas_addr, g_cache_canvas_size); + g_canvas_size[g_current_index_canvas_images] = g_cache_canvas_size; + + g_current_index_canvas_images++; + if (g_current_index_canvas_images >= MAX_NUM_SNAP_IMAGES) { + g_current_index_canvas_images = 0; + } + + if (g_start_to_store_canvas < MAX_NUM_SNAP_IMAGES) { + g_start_to_store_canvas++; + } + } + + /* + if (count_snap >= 5) { + count_snap = 0; + clean_curl_handle_for_snapshot(); + initial_curl_handle_for_snapshot(); + }*/ + + pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_get_canvas); + set_record_process_note("get_canvas_end"); + } +#endif + if (viewChannelData[0].enable_traffic || viewChannelData[0].enable_anpr) { + usSleep(USLEEP_PNS_SNAP_THREAD); + } + else { + usSleep(5000000); + } + //count_snap++; + } +#endif + pthread_exit(NULL); +} + +size_t get_g_canvas_addr(char * output_canvas_addr) { + if (g_start_to_store_canvas >= MAX_NUM_SNAP_IMAGES) { +#ifdef GY_OS_AMBA + //pthread_mutex_lock(&mutex_get_canvas); + int index_snap = g_current_index_canvas_images + 1 >= MAX_NUM_SNAP_IMAGES ? 0 : g_current_index_canvas_images + 1; + if (g_canvas_size[index_snap] >= 1) { + memcpy(output_canvas_addr, g_canvas_addr[index_snap], g_canvas_size[index_snap]); + } + //pthread_mutex_unlock(&mutex_get_canvas); + return g_canvas_size[index_snap]; +#else + return 0; +#endif + + } + else { + return 0; + } +} + +void stop_canvas_live_mode_flag() { + canvas_live_mode_flag = 0; +} + +// Based on the definitions from Vega's document "PNS2_API-1.pdf", part 2-5. +int g_pns_account_OK = 0; +int g_pns_access_level = -1; +int g_check_noapplink = 0; +char g_last_cloud_account[256] = { 0 }; +char g_last_cloud_password[256] = { 0 }; +struct timeval g_currtime_pns_post; +long g_last_s_pns_post = 0; +void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, char* arg_event_id, char* arg_event_id_16, char* arg_event_desc, char* user_account, char* user_password, char* region_cloud_addr, char *returned_msg, char* image_buff, int image_buff_size, time_t rawtime) +{ + //printf("\n---------------[PNS Send Multipart POST]:%d\n",1); + gettimeofday(&g_currtime_pns_post, NULL); + long current_s_pns_post = g_currtime_pns_post.tv_sec; + + if (g_check_noapplink == 0) { + g_last_s_pns_post = current_s_pns_post; + } + else{ + if (g_check_ping_OK == 1) { + if (g_pns_access_level <= 0 && (current_s_pns_post - g_last_s_pns_post) >= 3600) { + g_check_noapplink = 0; + g_pns_account_OK = 0; + g_last_s_pns_post = current_s_pns_post; + } + else if (g_pns_access_level >= 1 && (current_s_pns_post - g_last_s_pns_post) >= 600) { + g_check_noapplink = 0; + g_pns_account_OK = 0; + g_last_s_pns_post = current_s_pns_post; + } + } + } + + int check_reboot = 0; + + if (g_check_ping_OK == 1 && g_check_noapplink == 0) { + if (strlen(user_account) >= 1 && strlen(user_password) >= 1 && strcmp(user_account,"myaccount@mail.com") != 0){ + + if (strlen(g_last_cloud_account) >= 1 && strlen(g_last_cloud_password) >= 1) { + if (strcmp(user_account, g_last_cloud_account) != 0 || + strcmp(user_password, g_last_cloud_password) != 0) { + g_pns_account_OK = 0; + } + } + + if (g_pns_account_OK == 0) { + memset(g_last_cloud_account, 0x00, sizeof(g_last_cloud_account)); + memset(g_last_cloud_password, 0x00, sizeof(g_last_cloud_password)); + strcpy(g_last_cloud_account, user_account); + strcpy(g_last_cloud_password, user_password); + char returned_msg_temp[MEMORY_SIZE] = { 0 }; + PNS_check_if_to_post_image(user_account, user_password, returned_msg_temp, region_cloud_addr); + + if (strstr(returned_msg_temp, "\"msg\":\"oaA=\"") != NULL) { + g_pns_account_OK = 1; + } + + if (g_pns_account_OK == 1) { + if (strstr(returned_msg_temp, "\"eid\":\"Yg==\"") != NULL) { + g_pns_access_level = 0; + } + else if (strstr(returned_msg_temp, "\"eid\":\"Yw==\"") != NULL) { + g_pns_access_level = 1; + } + else if (strstr(returned_msg_temp, "\"eid\":\"ZQ==\"") != NULL) { + g_pns_access_level = 3; + } + else if (strstr(returned_msg_temp, "\"eid\":{\"err\":\"Yw==\",\"msg\":\"p6PFmpaZoZqU\"}") != NULL) { + g_pns_access_level = -2; + } + } + } + } + else { + g_pns_account_OK = 1; + g_pns_access_level = 0; + } + + //CURL* curl = curl_easy_init(); + curl_mime* form = NULL; + curl_mimepart* mimepart = NULL; + struct curl_slist* headerlist = NULL; + static const char buf[] = "Expect:"; + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + size_t snapshot_size = 0; + + //struct data debug_data_for_multipart; + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 2); + + //memset(g_canvas_addr, 0x00, MAX_IMG_SIZE); + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 21); + //size_t snapshot_size = (size_t)get_ori_c_image(g_canvas_addr); + //size_t snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_canvas_addr, 0); + //snapshot_size = get_g_canvas_addr(snapshot_addr); + + if (image_buff_size >= 1) { + snapshot_size = (size_t)image_buff_size; + memcpy(snapshot_addr, image_buff, snapshot_size); + } + + //printf("\n---------------[PNS Send Multipart POST]:%d-----snapshot_size%d\n", 22,(int)snapshot_size); + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 23); + + + char device_name[512] = { 0 }; + if (strlen(g_device_name) >= 1) { + strcpy(device_name, g_device_name); + } + //printf("\n---------------[PNS Send Multipart POST]:%d,strlen(device_name):%d,account_OK:%d,snapshot_size:%d\n", 3, strlen(device_name), account_OK, snapshot_size); + + pthread_mutex_lock(&mutex_curl); + + /*if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + }*/ + + if (strlen(device_name) >= 1 && g_pns_account_OK == 1 && g_pns_access_level >= 0 && g_http_handle && snapshot_size >= 1) + { + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 4); + CURL* curl_for_url_encode = g_http_handle; + char* url_encoded_str = curl_easy_escape(curl_for_url_encode, arg_event_desc, 0); // 0: Uses strlen() on the input string to find out the size. + char ddenc_event_desc[256] = { 0 }; + ddEnc(url_encoded_str, ddenc_event_desc); + + curl_free(url_encoded_str); + curl_easy_reset(curl_for_url_encode); + + //char *snapshot_addr = malloc(MAX_IMG_SIZE); + //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); + + + //char snapshot_addr[MEMORY_SIZE] = { 0 }; + //size_t snapshot_size = PNS_Get_Snapshot_From_IPCam("curl_saved_from_pns_buf.jpg", snapshot_addr, 0); + + + //printf("[PNS Send Multipart POST] CURL handler initialization for multipart/form-data.\n"); + form = curl_mime_init(g_http_handle); // Create the form + + // cat: Category, pns/others (Using pns) + // act: Action, check/send/list/snapshot (Using snapshot for 2-5) + // vend: Vendor, 0 for LILIN, 1, 2, 3, 4, 5, 6, 7, and etc. (Using 0 for 2-5) + // ver: 2.1 (Default) + // prd: Production ready "prd" or under development "dev". (Using prd for 2-5) + // cno: Random check num. Server will add 1 in response. + // dt: Device type, 0:IPCam, 1:NVR, 2:NAV (Using 0) + // et: Event type (from arguments) + // eid: Event ID (from arguments) + // mac: MAC addr. (Done) + // msg: + // tp: Describe what kind of alarm motion event. For AI team, it's always 8 (always shown as "ag==" after ddEnc). + // dt: Date. (Done) + // tm: Time. (Done) + // cu: Camera URL + // cp: Camera port + // vu: Video URL of the event + // im: Information to interpret + // ch: Which channel of the event + // de: Device type + // mc: Which MAC addr. detects the event + // dn: Device name (URL encoded) + // es: Event type string (AI event title in locale) + // en: Event type ID + // ds: Event description (AI event description in locale) + + /*const char* complete_string_for_debug = "\",\ + \"msg\" : [ {\ + \"tp\" : \"Yg==\",\ + \"dt\" : \"ZGWSbl1hZWJjlA==\",\ + \"tm\" : \"Y2ebZ2NqZmk=\",\ + \"cu\" : \"mqnVpWpfYmZelWZnlGQ=\",\ + \"cp\" : \"amWZZQ==\",\ + \"vu\" : \"mqnVpWpfYmZelWZnlGRm3M+ZnNNfmKHP0V+TlWVq\",\ + \"im\" : \"l66rZpNiia55zaedyp2N1L+Kec+KfGrgwoikzYuNZ9qLZ5qpeZmqnpOqfq7JqYCcr5+NvJGNpc7EnbTde6Rnog==\",\ + \"ch\" : \"Yg==\",\ + \"de\" : \"Yg==\",\ + \"mc\" : \"YmWRe3ZzbG5mmWhn\",\ + \"dn\" : \"V3qWWmlgWG10iH1ri3Fvi6hm\",\ + \"es\" : \"\",\ + \"en\" : \"\",\ + \"ds\" : \"V3qVWnJxWG1yiH1oi3J5i6hr\"\ + } ] }";*/ + + //-------------------------------------------------- + // Random number 0-999 for 'cno' field. + int rand_for_cno = rand() % 1000; + char str_rand_for_cno[8] = { 0 }; + snprintf(str_rand_for_cno, 5, "%d", rand_for_cno); + char ddenc_str_rand_for_cno[8] = { 0 }; + ddEnc(str_rand_for_cno, ddenc_str_rand_for_cno); + + const char* data1 = "{ \"cat\":\"oqPU\", \"act\":\""; + + const char *msg_act_snap = "paPCpaOYoqk="; + const char *msg_act_text = "pZrPmQ=="; + + const char* data1_2 = "\", \"vend\":\"Yg==\", \"ver\":\"ZGOS\", \"prd\":\"oqfF\", \"cno\":\""; + const char* data2 = "\", \"dt\":\"Yg==\", \"et\":\"a24=\", \"eid\":\""; + const char* data3 = "\", \"mac\":\""; + const char* msg_section1 = "\", \"msg\" : [ { \"tp\":\"ag==\", \"dt\":\""; + const char* msg_section2 = "\", \"tm\":\""; + const char* msg_section3 = "\", \"cu\":\"mqnVpWpfYmZelWZnlGQ=\", \"cp\":\"amWZZQ==\", \"vu\":\"mqnVpWpfYmZelWZnlGRm3M+ZnNNfmKHP0V+TlWVq\", \"im\":\""; + const char* msg_section4_mac = "\", \"ch\":\"Yg==\", \"de\":\"Yg==\", \"mc\":\""; + const char* msg_dev_name = "\", \"dn\":\""; + const char* msg_evn_str = "\", \"es\":\""; + const char* msg_evn_id = "\", \"en\":\""; + const char* msg_evn_id_16 = "\", \"ti\":\""; + const char* msg_evn_desc = "\", \"ds\":\""; + const char* msg_end = "\" } ] }"; + + //-------------------------------------------------- + // System local time of the date and the time strings. + char str_date[16] = { 0 }; + char str_time[16] = { 0 }; + //time_t rawtime; + //time(&rawtime); + struct tm* timeinfo = localtime(&rawtime); + strftime(str_date, sizeof(str_date) - 1, "%Y-%m-%d", timeinfo); + strftime(str_time, sizeof(str_time) - 1, "%H:%M:%S", timeinfo); + char ddenc_str_date[32] = { 0 }; + char ddenc_str_time[32] = { 0 }; + ddEnc(str_date, ddenc_str_date); + ddEnc(str_time, ddenc_str_time); + + //-------------------------------------------------- + // MAC address + char mac_addr[32] = { 0 }; + char mac_addr_temp[32] = { 0 }; + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 3); + memset(mac_addr_temp, 0x00, sizeof(mac_addr_temp)); + if (strlen(g_mac_address) >= 1) { + strcpy(mac_addr_temp, g_mac_address); + } + else { + GetMACAddress(mac_addr_temp); // Can use another function "GetMACAddress_WithoutDash" to reduce codes but need to verify after changing. + } + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 31); + int index_mac_addr = 0; + for (int i = 0; i < (int)strlen(mac_addr_temp); i++) { + if (mac_addr_temp[i] == '-' || mac_addr_temp[i] == '\n') { + + } + else { + mac_addr[index_mac_addr] = mac_addr_temp[i]; + index_mac_addr++; + } + } + mac_addr[index_mac_addr] = '\0'; + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 32); + char ddenc_mac[32] = { 0 }; + ddEnc(mac_addr, ddenc_mac); + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 4); + //-------------------------------------------------- + // Device name (Needed in procedure 2-5. Enable URL-encoded) + + char ddenc_device_name[512] = { 0 }; + ddEnc(device_name, ddenc_device_name); + + //-------------------------------------------------- + // Prepare basic strings for "im" field + const char* im_msg1 = "{ \"uid\":\""; + const char* im_msg2 = "\", \"pid\":\""; + const char* im_msg3 = "\", \"desc\":\""; + const char* im_msg4 = "\" }"; + + ////////////////////// + char Authorization_user_account[512] = { 0 }; + char Authorization_user_password[512] = { 0 }; + + //size_t base64_encode_length_user_account = 0; + //size_t base64_encode_length_user_password = 0; + + //char httpAuth_user_account[1280] = { 0 }; + //char httpAuth_user_password[1280] = { 0 }; + + char ddenc_user_account[1280] = { 0 }; + char ddenc_user_password[1280] = { 0 }; + + if (strlen(user_account) > 0 && g_pns_access_level >= 1) + { + char buf_account[512] = { 0 }; + urldecode((unsigned char *)user_account, (unsigned char *)buf_account); + strcpy(Authorization_user_account, buf_account); + + if (strlen(Authorization_user_account) >= 1) + { + //base64_encode((const unsigned char*)Authorization_user_account, strlen(Authorization_user_account), &base64_encode_length_user_account, httpAuth_user_account); + //httpAuth_user_account[base64_encode_length_user_account] = '\0'; + //if(base64_encode_length_user_account >= 1) + //ddEnc(httpAuth_user_account, ddenc_user_account); + ddEnc(Authorization_user_account, ddenc_user_account); + } + } + + + if (strlen(user_password) > 0 && g_pns_access_level >= 1) { + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)user_password, (unsigned char *)buf_account2); + strcat(Authorization_user_password, buf_account2); + + if (strlen(Authorization_user_password) >= 1) + { + //base64_encode((const unsigned char*)Authorization_user_password, strlen(Authorization_user_password), &base64_encode_length_user_password, httpAuth_user_password); + //httpAuth_user_password[base64_encode_length_user_password] = '\0'; + //if(base64_encode_length_user_password >= 1) + //ddEnc(httpAuth_user_password, ddenc_user_password); + ddEnc(Authorization_user_password, ddenc_user_password); + } + } + + int len_arg_json_string_for_im = strlen(arg_json_string_for_im); + + //-------------------------------------------------- + // Prepare base64 encoded desc in "im" field + size_t len_desc_by_base64 = 0; + char str_temp[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)arg_json_string_for_im, strlen(arg_json_string_for_im), &len_desc_by_base64, str_temp); + char str_desc_by_base64[8 * 8192] = { 0 }; + strncpy(str_desc_by_base64, str_temp, len_desc_by_base64); + str_desc_by_base64[len_desc_by_base64] = '\0'; + char ddenc_str_desc_by_base64[8 * 8192] = { 0 }; + ddEnc(str_desc_by_base64, ddenc_str_desc_by_base64); + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 5); + //-------------------------------------------------- + // Concatenate the whole im string. + size_t im_len_total = strlen(im_msg1) + strlen(ddenc_user_account) + strlen(im_msg2) + strlen(ddenc_user_password) + strlen(im_msg3) + strlen(ddenc_str_desc_by_base64) + strlen(im_msg4); + char im_string[im_len_total + 1]; + strcpy(im_string, im_msg1); + if(strlen(ddenc_user_account) >= 1) + strcat(im_string, ddenc_user_account); + strcat(im_string, im_msg2); + if (strlen(ddenc_user_password) >= 1) + strcat(im_string, ddenc_user_password); + strcat(im_string, im_msg3); + strcat(im_string, ddenc_str_desc_by_base64); + strcat(im_string, im_msg4); + im_string[im_len_total] = '\0'; + //printf("[PNS Send Multipart POST] im_string = %s\n", im_string); + //-------------------------------------------------- + // Encode the whole im string by base64 again. + size_t len_im_by_base64 = 0; + char str_temp_2[8 * 8192] = { 0 }; + base64_encode((const unsigned char*)im_string, strlen(im_string), &len_im_by_base64, str_temp_2); + char str_im_by_base64[8 * 8192] = { 0 }; + strncpy(str_im_by_base64, str_temp_2, len_im_by_base64); + str_im_by_base64[len_im_by_base64] = '\0'; + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 6); + //-------------------------------------------------- + // ddEncode on im string + char ddenc_json_str_for_im[8 * 8192] = { 0 }; + ddEnc(str_im_by_base64, ddenc_json_str_for_im); + //-------------------------------------------------- + // ddEncode on Event string, event ID from the arguments + char ddenc_event_str[50] = { 0 }; + ddEnc(arg_event_str, ddenc_event_str); + + char ddenc_event_id[30] = { 0 }; + ddEnc(arg_event_id, ddenc_event_id); + + + char ddenc_event_id_16[50] = { 0 }; + ddEnc(arg_event_id_16, ddenc_event_id_16); + + //-------------------------------------------------- + // URL-encoded and then ddEncode for event description from the arguments + + //printf("[PNS Send Multipart POST] Event desc: %s", url_encoded_str); + + int len_ddenc_json_str_for_im = strlen(ddenc_json_str_for_im); + + //printf("[PNS Send Multipart POST] URL encoded event desc: %s", ddenc_event_desc); + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 7); + //-------------------------------------------------- + // Calculate the total length of the data + //size_t total_len = strlen(data1) + strlen(data1_2) + strlen(ddenc_str_rand_for_cno) + strlen(data2) + strlen(ddenc_event_id_16) + strlen(data3) + strlen(ddenc_mac) + //+ strlen(msg_section1) + strlen(ddenc_str_date) + strlen(msg_section2) + strlen(ddenc_str_time) + strlen(msg_section3) + strlen(ddenc_json_str_for_im) + //+ strlen(msg_section4_mac) + strlen(ddenc_mac) + strlen(msg_dev_name) + strlen(ddenc_device_name) + //+ strlen(msg_evn_str) + strlen(ddenc_event_str) + strlen(msg_evn_id) + strlen(ddenc_event_id) + strlen(msg_evn_id_16) + strlen(ddenc_event_id_16) + strlen(msg_evn_desc) + strlen(ddenc_event_desc) + strlen(msg_end); + //-------------------------------------------------- + // Concatenate total length of the data + + //if (g_pns_access_level >= 1 && strcmp(SystemSetting.cloud_enable_snap, "Yes") == 0) { + //total_len += strlen(msg_act_snap); + //} + //else { + //total_len += strlen(msg_act_text); + //} + + char send_data[8 * 8192] = { 0 }; + strcpy(send_data, data1); + if (g_pns_access_level >= 1 && strcmp(SystemSetting.cloud_enable_snap, "Yes") == 0) { + strcat(send_data, msg_act_snap); + } + else { + strcat(send_data, msg_act_text); + } + strcat(send_data, data1_2); + strcat(send_data, ddenc_str_rand_for_cno); + strcat(send_data, data2); + strcat(send_data, ddenc_event_id_16); + strcat(send_data, data3); + strcat(send_data, ddenc_mac); + strcat(send_data, msg_section1); + strcat(send_data, ddenc_str_date); + strcat(send_data, msg_section2); + strcat(send_data, ddenc_str_time); + strcat(send_data, msg_section3); + strcat(send_data, ddenc_json_str_for_im); + strcat(send_data, msg_section4_mac); + strcat(send_data, ddenc_mac); + strcat(send_data, msg_dev_name); + strcat(send_data, ddenc_device_name); + strcat(send_data, msg_evn_str); + strcat(send_data, ddenc_event_str); + strcat(send_data, msg_evn_id); + strcat(send_data, ddenc_event_id); + strcat(send_data, msg_evn_id_16); + strcat(send_data, ddenc_event_id_16); + strcat(send_data, msg_evn_desc); + strcat(send_data, ddenc_event_desc); + strcat(send_data, msg_end); + //send_data[total_len] = '\0'; + + //printf("[PNS Send Multipart POST] JSON string for multipart section 1: %s\n", send_data); + + //printf("\n---------------------------send_data:total_len:%d\n", (int)total_len); + //printf("\n---------------------------send_data:snapshot_size:%d\n", (int)snapshot_size); + + // Fill in the submit field + mimepart = curl_mime_addpart(form); + curl_mime_name(mimepart, "data"); + curl_mime_type(mimepart, "application/json"); + curl_mime_data(mimepart, send_data, CURL_ZERO_TERMINATED); + + //printf("[PNS Send Multipart POST] g_canvas_addr = %p\n", g_canvas_addr); + //printf("[PNS Send Multipart POST] snapshot_size = %lu (bytes retrieved)\n", snapshot_size); + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 8); + if (g_pns_access_level >= 1 && snapshot_size >= 1 && strcmp(SystemSetting.cloud_enable_snap, "Yes") == 0) + { + // Fill in the filename field + mimepart = curl_mime_addpart(form); + curl_mime_type(mimepart, "image/jpg"); + curl_mime_data(mimepart, snapshot_addr, snapshot_size); + curl_mime_filename(mimepart, "cayman_test.jpg"); + curl_mime_name(mimepart, "file1"); + } + + // initialize custom header list (stating that Expect: 100-continue is not wanted + //headerlist = curl_slist_append(headers, "Accept: application/json"); + + headerlist = curl_slist_append(headerlist, "Accept: application/json"); + headerlist = curl_slist_append(headerlist, "Content-Type: multipart/form-data"); + headerlist = curl_slist_append(headerlist, "Connection: close"); + + //char* content_length_str = calloc(content_length + 17, 1); + //sprintf(content_length_str, "Content-Length: %ld", content_length); + //headerlist = curl_slist_append(headerlist, content_length_str); + //headerlist = curl_slist_append(headerlist, "charset: utf-8"); + headerlist = curl_slist_append(headerlist, buf); + + //CURLcode result = 0; + // what URL that receives this POST + curl_easy_setopt(g_http_handle, CURLOPT_URL, region_cloud_addr); + ///printf("[PNS Send Multipart POST] CURLOPT_URL: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); + //printf("[PNS Send Multipart POST] CURLOPT_SSL_VERIFYPEER: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 2L); + //printf("[PNS Send Multipart POST] CURLOPT_SSL_VERIFYHOST: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10); + //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + + //result = curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, "/emmc/plugin/Aida_data/cacert.pem"); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0); //ҮѨ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0); //ҮѨ + + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + //printf("[PNS Send Multipart POST] CURLOPT_CAINFO: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(g_http_handle, CURLOPT_DEBUGFUNCTION, my_trace); + //printf("[PNS Send Multipart POST] CURLOPT_DEBUGFUNCTION: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(g_http_handle, CURLOPT_DEBUGDATA, &debug_data_for_multipart); + //printf("[PNS Send Multipart POST] CURLOPT_DEBUGDATA: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); + //printf("[PNS Send Multipart POST] CURLOPT_VERBOSE: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(g_http_handle, CURLOPT_POST, 1L); // Switch on full protocol/debug output + //printf("[PNS Send Multipart POST] CURLOPT_POST: %s\n", curl_easy_strerror(result)); + + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L); + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 9); + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_responded_msg = &memory_temp_msg; + //ptr_responded_msg->memory = NULL; + ptr_responded_msg->size = 0; + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + //printf("[PNS Send Multipart POST] CURLOPT_WRITEFUNCTION: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + //printf("[PNS Send Multipart POST] CURLOPT_WRITEDATA: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, headerlist); + //printf("[PNS Send Multipart POST] CURLOPT_HTTPHEADER: %s\n", curl_easy_strerror(result)); + curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, form); + //printf("[PNS Send Multipart POST] CURLOPT_MIMEPOST: %s\n", curl_easy_strerror(result)); + + // Perform the request, res will get the return code + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 10); + CURLcode res = curl_easy_perform(g_http_handle); + check_if_correct_post = 1; + // Check for errors + if (res != CURLE_OK) + { + check_if_run_post = 0; + + //curl_easy_cleanup(g_http_handle); // always cleanup + //curl_mime_free(mimepart); // then cleanup the form + curl_mime_free(form); // then cleanup the form + char* err_msg = (char*)curl_easy_strerror(res); + +#if 1 + if (res == CURLE_OUT_OF_MEMORY) { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,access: %d (only text, not support JPEG),len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + else { + sprintf(c_access_level, "free:%d,access: %d,len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + strcpy(returned_msg, c_access_level); + strcat(returned_msg, "CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined"); + printf("[PNS Send Multipart POST]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); + + write_to_logs_html(returned_msg, "curl to post pns", "CGI_REBOOT", "Yes"); + write_to_log_if_error(returned_msg, "curl to post pns", "CGI_REBOOT"); + + check_reboot = 1; + + } + else { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,access: %d (only text, not support JPEG),len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + else { + sprintf(c_access_level, "free:%d,access: %d,len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + strcpy(returned_msg, c_access_level); + strcat(returned_msg, err_msg); + write_to_log_if_error_post_pns(returned_msg); + write_to_logs_html(returned_msg, "curl to post pns", "ERROR", SystemSetting.enable_system_logs); + } +#endif + + + fprintf(stderr, "[PNS Send Multipart POST] curl_easy_perform() failed: %s\n", returned_msg); + } + else + { + check_if_run_post = 1; + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 11); + //curl_easy_cleanup(g_http_handle); // always cleanup + //curl_mime_free(mimepart); // then cleanup the form + curl_mime_free(form); // then cleanup the form + //printf("[PNS Send Multipart POST] Multipart/form-data command finished.\n"); + + + char *loc = strstr(ptr_responded_msg->memory, "msg\":\""); + char *loc_end = NULL; + if (loc != NULL) { + loc_end = strstr(loc, "\",\""); + if (loc_end == NULL) { + loc_end = strstr(loc, "\"}"); + } + } + + //printf("\n--------ptr_responded_msg->memory:%s\n", ptr_responded_msg->memory); + + char temp_memory[8 * 8192] = { 0 }; + char temp_msg[512] = { 0 }; + int index_temp_memory = 0; + + if (loc != NULL && loc_end != NULL) + { + for (int index_msg = 6; index_msg < strlen(loc) - strlen(loc_end); index_msg++) { + temp_memory[index_temp_memory] = loc[index_msg]; + index_temp_memory++; + } + temp_memory[index_temp_memory] = '\0'; + + ddDec(temp_memory, temp_msg); + + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,access: %d (only text, not support JPEG),len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + else { + sprintf(c_access_level, "free:%d,access: %d,len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + strcpy(returned_msg, "Regular service: "); + strcat(returned_msg, c_access_level); + strcat(returned_msg, temp_msg); + write_to_logs_html(returned_msg, "curl to post pns", "INFO", SystemSetting.enable_system_logs); + + if (strcmp(temp_msg,"noAppLink")==0 || strstr(temp_msg, "\"msg\":\"oKSipaB8nKOb\"") != NULL) { + g_check_noapplink = 1; + } + } + else { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,access: %d (only text, not support JPEG),len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + else { + sprintf(c_access_level, "free:%d,access: %d,len_desc:%d,len_ddenc:%d,", get_free_mem_data(), g_pns_access_level, len_arg_json_string_for_im, len_ddenc_json_str_for_im); + } + strcpy(returned_msg, "Regular service: "); + strcat(returned_msg, c_access_level); + strcat(returned_msg, ptr_responded_msg->memory); + write_to_logs_html(returned_msg, "curl to post pns", "ERROR", SystemSetting.enable_system_logs); + + if (strstr(ptr_responded_msg->memory, "\"msg\":\"oKSipaB8nKOb\"") != NULL) { + g_check_noapplink = 1; + } + } + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 12); + } + + snapshot_size = 0; + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 13); + curl_slist_free_all(headerlist); // free slist + + + ptr_responded_msg->size = 0; + /*if (ptr_responded_msg != NULL) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 14); + curl_easy_reset(g_http_handle); + } + else + { + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 5); + if (strlen(device_name) == 0) { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + else { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + strcpy(returned_msg, c_access_level); + strcat(returned_msg, "Device name empty."); + printf("[PNS Send Multipart POST] Device name empty.\n"); + write_to_logs_html(returned_msg, "curl to post pns", "ERROR", SystemSetting.enable_system_logs); + } + else if (snapshot_size == 0) { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + else { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + strcpy(returned_msg, c_access_level); + strcat(returned_msg, "Image empty."); + printf("[PNS Send Multipart POST] Image empty.\n"); + write_to_logs_html(returned_msg, "curl to post pns", "ERROR", SystemSetting.enable_system_logs); + } + else if (g_http_handle == NULL) { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + else { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + strcpy(returned_msg, c_access_level); + strcat(returned_msg, "CURL initialization failed."); + printf("[PNS Send Multipart POST] CURL initialization failed.\n"); + write_to_logs_html(returned_msg, "curl to post pns", "ERROR", SystemSetting.enable_system_logs); + } + else if (g_pns_access_level == -2) { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + else { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + + strcpy(returned_msg, c_access_level); + strcat(returned_msg, "Wrong account."); + printf("[PNS Send Multipart POST] Wrong account.\n"); + write_to_logs_html(returned_msg, "PNS check", "ERROR", SystemSetting.enable_system_logs); + } + else { + char c_access_level[50] = { 0 }; + if (g_pns_access_level == 0) { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + else { + sprintf(c_access_level, "free:%d,", get_free_mem_data()); + } + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 15); + strcpy(returned_msg, c_access_level); + //strcat(returned_msg, returned_msg_temp); + printf("[PNS Send Multipart POST] pns check error.\n"); + write_to_logs_html(returned_msg, "PNS check", "ERROR", SystemSetting.enable_system_logs); + } + } + + if (strstr(returned_msg, "Timeout was reached") != NULL || + strstr(returned_msg, "timeout was reached") != NULL || + strstr(returned_msg, "Couldn't resolve host name") != NULL || + strstr(returned_msg, "couldn't resolve host name") != NULL) { + g_check_ping_OK = 0; + } + + pthread_mutex_unlock(&mutex_curl); + } + /* + if (snapshot_addr != NULL) { + free(snapshot_addr); + snapshot_addr = NULL; + }*/ + + if (check_reboot == 1) { + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + + //printf("\n---------------[PNS Send Multipart POST]:%d\n", 6); + //curl_easy_cleanup(curl); // always cleanup +} + +int DDNS_Communication(int operation, char* arg_email_addr, char* arg_password, char* returned_msg) +{ + pthread_mutex_lock(&mutex_curl); + CURL* curl_handler = g_http_handle; // Initialization for each handler. + CURLcode result = 0; // For starting PNS and connections to the cloud. + + //-------------------------------------------------- + // CURL section + struct curl_slist* headers = NULL; + headers = curl_slist_append(headers, "Accept: application/json"); + headers = curl_slist_append(headers, "Content-Type: application/json"); + headers = curl_slist_append(headers, "charset: utf-8"); + headers = curl_slist_append(headers, "Connection: close"); + curl_easy_setopt(curl_handler, CURLOPT_HTTPHEADER, headers); + + // CURL error handling + //char error_string[CURL_ERROR_SIZE]; + //result = curl_easy_setopt(curl_handler, CURLOPT_ERRORBUFFER, error_string); + //printf("[DDNS Communication] CURLOPT_ERRORBUFFER: %s\n", curl_easy_strerror(result)); + result = curl_easy_setopt(curl_handler, CURLOPT_POST, 1L); // Switch on full protocol/debug output + //printf("[DDNS Communication] CURLOPT_POST: %s\n", curl_easy_strerror(result)); + + // Specify URL to send POST data + result = curl_easy_setopt(curl_handler, CURLOPT_URL, Global_URL_for_DDNS); + //printf("[DDNS Communication] CURLOPT_URL: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handler, CURLOPT_USE_SSL, CURLUSESSL_ALL); + //printf("[PNS] CURLOPT_USE_SSL: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handler, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + //printf("[PNS] CURLOPT_SSLVERSION: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handler, CURLOPT_SSL_VERIFYPEER, 1L); + //printf("[DDNS Communication] CURLOPT_SSL_VERIFYPEER: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handler, CURLOPT_SSL_VERIFYHOST, 2L); + //printf("[DDNS Communication] CURLOPT_SSL_VERIFYHOST: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl, CURLOPT_CAINFO, "/emmc/plugin/Aida_data/cacert.pem"); + + curl_easy_setopt(curl_handler, CURLOPT_SSL_VERIFYPEER, 0); //ҮѨ + curl_easy_setopt(curl_handler, CURLOPT_SSL_VERIFYHOST, 0); //ҮѨ + //printf("[DDNS Communication] CURLOPT_CAINFO: %s\n", curl_easy_strerror(result)); + + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_responded_msg = &memory_temp_msg; + //ptr_responded_msg->memory = NULL; + ptr_responded_msg->size = 0; + + + result = curl_easy_setopt(curl_handler, CURLOPT_WRITEFUNCTION, WriteResponseString); + //printf("[DDNS Communication] CURLOPT_WRITEFUNCTION: %s\n", curl_easy_strerror(result)); + result = curl_easy_setopt(curl_handler, CURLOPT_WRITEDATA, ptr_responded_msg); + //printf("[DDNS Communication] CURLOPT_WRITEDATA: %s\n", curl_easy_strerror(result)); + + //-------------------------------------------------- + // Assemble the string for sending + const char* json_check = "{ \"act\":\"lZ3GmJs=\", \"email\":\""; // ddEnc("check") = "lZ3GmJs=" + const char* json_regis = "{ \"act\":\"pJrInqOk\", \"email\":\""; // ddEnc("regist") = "pJrInqOk" + const char* json_login = "{ \"act\":\"nqTInp4=\", \"email\":\""; // ddEnc("login") = "nqTInp4=" + const char* json_pass = "\", \"pass\":\""; + const char* json_end = "\" }"; + + // Prepare the command field + char json_cmd[MEMORY_SIZE] = {0}; + if (operation == 0) + strcpy(json_cmd, json_check); + else if (operation == 1) + strcpy(json_cmd, json_regis); + else + strcpy(json_cmd, json_login); + + // Prepare the email field + char ddenc_email[50] = { 0 }; + ddEnc(arg_email_addr, ddenc_email); + // Prepare the password field + char ddenc_password[50] = { 0 }; + ddEnc(arg_password, ddenc_password); + // Calculate the total length of the JSON string + //size_t total_len = strlen(json_cmd) + strlen(ddenc_email) + strlen(json_pass) + strlen(ddenc_password) + strlen(json_end); + // Construct the JSON string + char send_data[8 * 8192] = { 0 }; + strcpy(send_data, json_cmd); + strcat(send_data, ddenc_email); + strcat(send_data, json_pass); + strcat(send_data, ddenc_password); + strcat(send_data, json_end); + //send_data[total_len] = '\0'; + //printf("[DDNS Communication] JSON string for this DDNS operation: %s\n", send_data); + + //-------------------------------------------------- + result = curl_easy_setopt(curl_handler, CURLOPT_POSTFIELDSIZE, strlen(send_data)); + //printf("[DDNS Communication] CURLOPT_POSTFIELDSIZE: %s\n", curl_easy_strerror(result)); + result = curl_easy_setopt(curl_handler, CURLOPT_POSTFIELDS, send_data); + //printf("[DDNS Communication] CURLOPT_POSTFIELDS: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handler, CURLOPT_DEBUGFUNCTION, my_trace); + //printf("[PNS] CURLOPT_DEBUGFUNCTION: %s\n", curl_easy_strerror(result)); + //result = curl_easy_setopt(curl_handler, CURLOPT_DEBUGDATA, &debug_data_for_query); + //printf("[PNS] CURLOPT_DEBUGDATA: %s\n", curl_easy_strerror(result)); + result = curl_easy_setopt(curl_handler, CURLOPT_VERBOSE, 1L); // Switch on full protocol/debug output + //printf("[DDNS Communication] CURLOPT_VERBOSE: %s\n", curl_easy_strerror(result)); + + curl_easy_setopt(curl_handler, CURLOPT_TCP_FASTOPEN, 1L); + + curl_easy_setopt(curl_handler, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + result = curl_easy_perform(curl_handler); + int ret = 0; + if (result != CURLE_OK) + { + char* err_msg = (char*)curl_easy_strerror(result); + strcpy(returned_msg, err_msg); + printf("[DDNS Communication] CURL perform failed: %s\n", err_msg); + //printf("[DDNS Communication] Reason: %s\n", error_string); + curl_slist_free_all(headers); + curl_easy_reset(curl_handler); + + + ptr_responded_msg->size = 0; + + /*if (ptr_responded_msg != NULL) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + + ret = 0; + } + else + { + + char *loc = strstr(ptr_responded_msg->memory, "msg\":\""); + char *loc_end = strstr(ptr_responded_msg->memory, "\"}"); + + + char temp_memory[8 * 8192] = { 0 }; + char temp_msg[512] = { 0 }; + int index_temp_memory = 0; + + + if (loc != NULL && loc_end != NULL) { + for (int index_msg = 6; index_msg < strlen(loc) - strlen(loc_end); index_msg++) { + temp_memory[index_temp_memory] = loc[index_msg]; + index_temp_memory++; + } + temp_memory[index_temp_memory] = '\0'; + + ddDec(temp_memory, temp_msg); + + strcat(returned_msg, temp_msg); + } + else { + strcpy(returned_msg, ""); + } + + //strcpy(returned_msg, ptr_responded_msg->memory); + + //printf("[DDNS Communication] curl_easy_perform succeeded.\n"); + curl_slist_free_all(headers); + curl_easy_reset(curl_handler); + + + ptr_responded_msg->size = 0; + + /*if (ptr_responded_msg != NULL) { + free(ptr_responded_msg); + ptr_responded_msg = NULL; + }*/ + ret = 1; + } + pthread_mutex_unlock(&mutex_curl); + return ret; +} + +void PNS_check_if_to_post_image(char* arg_email_addr, char* arg_password,char* returned_msg,char *region_cloud_addr) +{ + pthread_mutex_lock(&mutex_curl); + + /*if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + }*/ + + //CURL* curl_handle_for_pns; + curl_mime* form = NULL; + curl_mimepart* mimepart = NULL; + struct curl_slist* headerlist = NULL; + static const char buf[] = "Expect:"; + + if (g_http_handle != NULL) { + + form = curl_mime_init(g_http_handle); // Create the form + + //curl_handle_for_pns = curl_easy_init(); // Initialization for each handler. + + const char* data0 = "{ \"cat\": \"oqPU\", \"act\" : \"lZ3GmJs=\", \"prd\" : \"\", \"cno\" : \""; + + const char* data1 = "\", \"dt\" : \"Yg==\", \"et\" : \"\", \"eid\" : \""; + + const char* data1_2 = "\", \"mac\" : \""; + + const char* data2 = "\"}"; + + //-------------------------------------------------- + // Random number 0-9999 for 'cno' field. + int rand_for_cno = rand() % 10000; + char str_rand_for_cno[256] = { 0 }; + sprintf(str_rand_for_cno, "%d", rand_for_cno); + + char ddenc_str_rand_for_cno[256] = { 0 }; + ddEnc(str_rand_for_cno, ddenc_str_rand_for_cno); + //printf("\n----str_rand_for_cno:%s\n", str_rand_for_cno); + //printf("\n----ddenc_str_rand_for_cno #1:%s\n", ddenc_str_rand_for_cno); + //-------------------------------------------------- + + // MAC address + + char mac_addr[256] = { 0 }; + char mac_addr_temp[256] = { 0 }; + + if (strlen(g_mac_address) >= 1) { + strcpy(mac_addr_temp, g_mac_address); + } + else { + GetMACAddress(mac_addr_temp); // Can use another function "GetMACAddress_WithoutDash" to reduce codes but need to verify after changing. + } + + //printf("\n----ddenc_str_rand_for_cno #2:%s\n", ddenc_str_rand_for_cno); + //printf("\n------(int)strlen(mac_addr_temp):%d\n", (int)strlen(mac_addr_temp)); + + int index_mac_addr = 0; + for (int i = 0; i < (int)strlen(mac_addr_temp); i++) { + if (mac_addr_temp[i] == '-' || mac_addr_temp[i] == '\n') { + + } + else { + mac_addr[index_mac_addr] = mac_addr_temp[i]; + index_mac_addr++; + } + } + //mac_addr[index_mac_addr] = '\0'; + //printf("\n----ddenc_str_rand_for_cno #3:%s\n", ddenc_str_rand_for_cno); + char ddenc_mac[256] = { 0 }; + ddEnc(mac_addr, ddenc_mac); + //printf("\n----ddenc_str_rand_for_cno #4:%s\n", ddenc_str_rand_for_cno); + char ddenc_email[256] = { 0 }; + ddEnc(arg_email_addr, ddenc_email); + //printf("\n----ddenc_str_rand_for_cno #5:%s\n", ddenc_str_rand_for_cno); + //-------------------------------------------------- + // Calculate the total length of the data + //size_t total_len = strlen(data0) + strlen(ddenc_str_rand_for_cno) + strlen(data1) + strlen(ddenc_mac) + strlen(data2) + strlen(ddenc_device_name) + strlen(data3); + //size_t total_len = strlen(data0) + strlen(ddenc_str_rand_for_cno) + strlen(data1) + strlen(ddenc_email) + strlen(data1_2) + strlen(ddenc_mac) + strlen(data2); + + //-------------------------------------------------- + // Assemble the string for sending + char send_data[8192*8] = { 0 }; + strcpy(send_data, data0); + strcat(send_data, ddenc_str_rand_for_cno); + strcat(send_data, data1); + strcat(send_data, ddenc_email); + strcat(send_data, data1_2); + strcat(send_data, ddenc_mac); + strcat(send_data, data2); + //strcat(send_data, ddenc_device_name); + //strcat(send_data, data3); + //send_data[total_len] = '\0'; + //printf("[PNS Check] JSON string before sending: %s\n", send_data); + //printf("\n----ddenc_str_rand_for_cno #6:%s\n", ddenc_str_rand_for_cno); + + //write_to_logs_html(send_data, "PNS check send data", "Info", SystemSetting.enable_system_logs); + + mimepart = curl_mime_addpart(form); + curl_mime_name(mimepart, "data"); + curl_mime_type(mimepart, "application/json"); + curl_mime_data(mimepart, send_data, CURL_ZERO_TERMINATED); + + //-------------------------------------------------- + // CURL section + headerlist = curl_slist_append(headerlist, "Accept: application/json"); + headerlist = curl_slist_append(headerlist, "Content-Type: multipart/form-data"); + headerlist = curl_slist_append(headerlist, "Connection: close"); + headerlist = curl_slist_append(headerlist, buf); + + // Specify URL to send POST data + //CURLcode result = 0; + curl_easy_setopt(g_http_handle, CURLOPT_URL, region_cloud_addr); + + + curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); // ]wsuWɡA + curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10); + curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); + + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0); //ҮѨ + curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0); //ҮѨ + curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output + + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L); + + struct MemoryStruct memory_temp_msg; + struct MemoryStruct* ptr_responded_msg = &memory_temp_msg; + //ptr_responded_msg->memory = NULL; + ptr_responded_msg->size = 0; + + curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); + curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); + + + curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); + + + curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, headerlist); + curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, form); + + curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + CURLcode res = curl_easy_perform(g_http_handle); + if (res != CURLE_OK) + { + curl_mime_free(form); + char* err_msg = (char*)curl_easy_strerror(res); + strcpy(returned_msg, err_msg); + fprintf(stderr, "[PNS check if to post image] Failed to initialize the CURL handler for PNS. Reason: %s\n", returned_msg); + + write_to_logs_html(returned_msg, "PNS check", "ERROR", SystemSetting.enable_system_logs); + } + else + { + curl_mime_free(form); + strcpy(returned_msg, ptr_responded_msg->memory); + //write_to_logs_html(returned_msg, "PNS check", "Info", SystemSetting.enable_system_logs); + //printf("\n--------response msg:%s\n", returned_msg); + } + + curl_slist_free_all(headerlist); + + ptr_responded_msg->size = 0; + + curl_easy_reset(g_http_handle); + } + else { + static const char err_msg[] = "(CURL initialization failed.)\n"; + strcpy(returned_msg, err_msg); + printf("[PNS check if to post image] CURL initialization failed.\n"); + write_to_logs_html(returned_msg, "PNS check", "ERROR", SystemSetting.enable_system_logs); + } + + if (strstr(returned_msg,"Timeout was reached") != NULL || + strstr(returned_msg, "timeout was reached") != NULL || + strstr(returned_msg, "Couldn't resolve host name") != NULL || + strstr(returned_msg, "couldn't resolve host name") != NULL) { + g_check_ping_OK = 0; + } + + pthread_mutex_unlock(&mutex_curl); +} + +#endif diff --git a/src/pns.h b/src/pns.h new file mode 100644 index 0000000..f40972c --- /dev/null +++ b/src/pns.h @@ -0,0 +1,68 @@ +#if 1 +#pragma once +#ifndef PNS_H +#define PNS_H +#include "define_inc.h" +#include "layer.h" +#include "nweb.h" +#include "md5.h" +#include "stdlib.h" +#include "cryptionPlus.h" +#include "darknet.h" +#include <pthread.h> +#include <curl/curl.h> +#include <curl/easy.h> +#include <unistd.h> +#include "test_nnctrl_live.h" +#include "cgicmd.h" +#include "ptz.h" + +#define CURL_SAVE_JPG_TO_BUFF // Save the snapshots from the IPCam and save them into the files or the buffer. +#define CURL_RECV_JPG_BUFF_SIZE 4 // Decide the buffer size for snapshot history. Buffer index was cycled. +//#define CURL_SAVE_BUFF_TO_FILE // Save the byte stream from the buffer into a file to make sure JPG was received correctly. +#define DEF_MD5_LENGTH 32 + +extern pthread_mutex_t mutex_get_network_input; +extern pthread_mutex_t mutex_curl; + +extern CURL* g_http_handle; + +extern char g_device_name[512]; + +extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; +extern SystemSettingInfo SystemSetting; +extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add +#ifdef GY_OS_AMBA +extern TofInfo tofData; +#endif +extern long g_osdSysTimeStamp; +extern int check_if_correct_post; +extern int check_if_run_post; + +extern int g_check_ping_OK; + +extern int g_sdk_version; + +void PNS_Query_Service_Status(char* returned_msg); +void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, char* arg_event_id, char* arg_event_id_16, char* arg_event_desc, char* user_account, char* user_password, char* region_cloud_addr,char *returned_msg, char* image_buff, int image_buff_size, time_t rawtime); +int PNS_Get_Device_Name(int arg_url_encoded_or_not, char *returned_msg); +size_t PNS_Get_Snapshot_From_IPCam(char* file_name, char* img_addr,int enable_to_save_file); +#ifdef GY_OS_AMBA +size_t PNS_Get_Snapshot_From_Remote_IPCam(char* file_name, char* img_addr,int enable_to_save_file); +#endif +void ddDec(char* input_str, char *restored_str); +int DDNS_Communication(int operation, char* arg_email_addr, char* arg_password, char* returned_msg); +void stop_canvas_live_mode_flag(); +void *Get_canvas_From_IPCam_thread(void *ptr); +size_t get_g_canvas_addr(char * output_canvas_addr); + +void initial_curl_handle_for_snapshot(); +void clean_curl_handle_for_snapshot(); + +void PNS_check_if_to_post_image(char* arg_email_addr, char* arg_password, char* returned_msg, char *region_cloud_addr); + +extern int g_match_mac; +extern char g_mac_address[256]; + +#endif +#endif diff --git a/src/ptz.c b/src/ptz.c new file mode 100644 index 0000000..cdaae7d --- /dev/null +++ b/src/ptz.c @@ -0,0 +1,4992 @@ + + +//#include <curl/curl.h> +//#include <curl/easy.h> + +#include "setting.h" +#include "ptz.h" +#include "network.h" +#include <math.h> +#include <pthread.h> +#include "cgicmd.h" +#ifdef GY_OS_AMBA + +#ifdef GY_OS_WIN +#include "curl.h" +#include "easy.h" +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include "curl/curl.h" +#include "curl/easy.h" +#endif + +#define USE_CURL +#define USE_SOCKET + + +//PTZ_HANDLE g_stPTZSetting; +pthread_t ptz_status_thread; +pthread_t ptz_tracking_thread; + +pthread_t ptz_zoom_thread; + +PTZ_HANDLE g_stPTZ_Handle; +PTZ_ZONE_INFO g_stPTZ_Zone_info[MAX_DETECTION_ZONE]; + +//CURL *g_curl_Handle; +//struct curl_slist *g_pList = NULL; + +int g_IsShipTracking; + +int g_PTZ_model = -1; + + +//PTZ_HANDLE *CreatePTZHandle() +//{ +// PTZ_HANDLE *p_ptzHandle = (struct PTZ_HANDLE *) malloc(sizeof(struct PTZ_HANDLE)); + +// return p_ptzHandle; +//} + +//void DeletePTZHandle(PTZ_HANDLE *pInPTZHandle) +//{ +// if (pInPTZHandle) +// free(pInPTZHandle); +//} + +#ifndef pmax +#define pmax(a,b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef pmin +#define pmin(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +/*float object_iou(PTZ_VIRTUAL_BOX *box1, PTZ_VIRTUAL_BOX *box2) +{ + if (box1->left_x > box2->left_x + box2->width) { return 0.0; } + if (box1->top_y > box2->top_y + box2->height) { return 0.0; } + if (box1->left_x + box1->width < box2->left_x) { return 0.0; } + if (box1->top_y + box1->height < box2->top_y) { return 0.0; } + float colInt = abs(pmin(box1->left_x + box1->width, box2->left_x + box2->width) - pmax(box1->left_x, box2->left_x)); + float rowInt = abs(pmin(box1->top_y + box1->height, box2->top_y + box2->height) - pmax(box1->top_y, box2->top_y)); + float overlapArea = colInt * rowInt; //相交處面積 + float area1 = box1->width * box1->height; + float area2 = box2->width * box2->height; + float smallerArea = (area1 > area2) ? area2 : area1; + return overlapArea / smallerArea; //相交處面積占較小物件比例 + //return overlapArea / (area1 + area2 - overlapArea); //相交處面積比例占大小物件加總比例 +}*/ + +void SetPtzWaitDwellTime(int iDwellTime) +{ + g_stPTZ_Handle.iTracking_resume_dwell = iDwellTime; +} + +void SetPtzSensitivity(int iSensitivity) +{ + //g_stPTZ_Handle.iTimer_send_count = 0; + + g_stPTZ_Handle.iPTZ_speed = iSensitivity; + + g_stPTZ_Handle.iZoomFreqCount = 1; + g_stPTZ_Handle.iGoCenterFreqFrame = 1; + g_stPTZ_Handle.iGoCenterFreqCount = 1; + +#if 0 + if (iSensitivity >= 1 + && iSensitivity <= 6) + g_stPTZ_Handle.iPTZ_sensitivity = 6 - iSensitivity + 1; + else + g_stPTZ_Handle.iPTZ_sensitivity = PTZ_DEFAULT_SENSITIVITY; + + if (g_stPTZ_Handle.iPTZ_sensitivity < 0) + g_stPTZ_Handle.iPTZ_sensitivity = 0; +#endif +} + + + + +int MirrorBondingBox(int x, int w) +{ + int dwMirror_X = 0; + + if (w > 0 && x >= 0 && x < w) + { + dwMirror_X = 0 + w - (x + 1); + } + else + { + if (x > 0) + dwMirror_X = x; + else + dwMirror_X = 0; + } + + //g_iScaledBoundingBoxWidth, g_iScaledBoundingBoxHeight, + + return dwMirror_X; +} + +int FlipBondingBox(int y, int h) +{ + int dwFlip_Y = 0; + + if (h > 0 && y >= 0 && y < h) + { + dwFlip_Y = 0 + h - (y + 1); + } + else + { + if (y > 0) + dwFlip_Y = y; + else + dwFlip_Y = 0; + } + + //g_iScaledBoundingBoxWidth, g_iScaledBoundingBoxHeight, + + return dwFlip_Y; +} + +void Mirror_Flip_posInfo(detection_pos *PosInfo, int iTotalElementSize, int iIm_width, int iIm_height, int iMirrorFlag, int iFlipFlag) +{ + detection_pos *pNext = NULL; + + if (iMirrorFlag == 1 || iFlipFlag == 1) + { + for (int i = 0; i < iTotalElementSize; i++) + { + pNext = PosInfo + i; + + if (iMirrorFlag == 1) + { + pNext->left_x = MirrorBondingBox((int)pNext->left_x, iIm_width) - pNext->width; + pNext->center_x = MirrorBondingBox((int)pNext->center_x, iIm_width); + //pNext->box_x = selected_detections[i].det.bbox.x; + } + + if (iFlipFlag == 1) + { + pNext->top_y = FlipBondingBox((int)pNext->top_y, iIm_height) - pNext->height; + pNext->center_y = FlipBondingBox((int)pNext->center_y, iIm_height); + //pNext->box_y = selected_detections[i].det.bbox.y; + } + } + } +} + +size_t ptz_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream) { + /* + time_t timep; + struct tm * timeinfo; + time(&timep); + timeinfo = localtime(&timep); + */ + size_t realsize = size * nmemb; + //cJSON *r_root, *r_tstamp; + + //time_t r_timep; + //struct tm * r_timeinfo; + //time(&timep); + if (stream) + { + //printf("Magic: %s \n", (char *)stream); + //free(stream); + + sprintf((char *)stream, "%s", (char *)ptr); + return realsize; + } + else + { + return 0; + } + + //printf(">>>>>>>>>>>>> Get PTZ Curl resp:\n %s \n", (char *)ptr); + //printf(">>>>>>>>>>>>> Response Time: %d-%02d-%02d ", (1900 + timeinfo->tm_year), (1 + timeinfo->tm_mon), timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + +} +#if 0 +int net_socket_ptz_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) +{ + int l_ret = 0; + pthread_mutex_lock(&mutex_send_cgi); + SetHttpRequest_ptz(sUrl, sOutputData, sUserNmae, sPassWord); + //SetHttpRequest_ptz_re(sUrl, sOutputData, sUserNmae, sPassWord); + pthread_mutex_unlock(&mutex_send_cgi); + return l_ret; +} +#endif +//extern CURLM* g_multi_handle; +//extern int g_handle_count; +extern amba_content stAMBAcontent; + +#if 0 +int net_curl_ptz_cmd_multi_interface(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) +{ + pthread_mutex_lock(&mutex_curl); + CURL *curl = g_http_handle; + CURLcode l_res; + int l_ret = -1; + //const int timeout = 30000; + const int timeout = 100; + //char *sBuffer; + char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + curl = curl_easy_init(); + + //char response_data[512] = { 0 }; + //char *response_data; + //response_data = malloc(512); + //strcat(response_data, "mmmmmmmmmmmmmmagic"); + + if (curl != NULL) + { + struct curl_slist *pList = NULL; + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type:application/json"); + pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //Connection: close + } + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Connection: close"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); + + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3); + + time_t s_timep = time(0); + struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + char test_countent[25] = { 0 }; + strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + + curl_easy_setopt(curl, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); + curl_easy_setopt(curl, CURLOPT_PORT, iPort); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, sOutputData); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + + curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); + + if (strcmp(method, "POST") == 0) + { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); + curl_easy_setopt(curl, CURLOPT_POST, 1L); + } + + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1000); + + curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + +#if 0 + l_res = curl_easy_perform(curl); + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + l_ret = -1; + } + else + l_ret = 0; +#else + curl_multi_add_handle(g_multi_handle, curl); + curl_multi_perform(g_multi_handle, &g_handle_count); +#endif + curl_easy_reset(curl); + if (pList != NULL) + curl_slist_free_all(pList); + } + + pthread_mutex_unlock(&mutex_curl); + + return l_ret; +} +#endif + +int net_curl_ptz_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id) +{ +#if 1 + if (stAMBAcontent.licenseType != _NO_LICENSE && stAMBAcontent.afsCode == _LICENSED) + { + } + else + { + printf("Trial has expired or mismatch the system ID."); + return -1; + } +#endif + + //pthread_mutex_lock(&mutex_send_cgi); + pthread_mutex_lock(&mutex_curl); + CURL *curl = NULL; + CURLcode l_res; + int l_ret = -1; + //const int timeout = 30000; + //const int timeout = 100; + //char *sBuffer; + //char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + + if (g_http_handle == NULL) { + g_http_handle = curl_easy_init(); + } + + curl = g_http_handle; + + struct curl_slist *pList = NULL; + + //char response_data[512] = { 0 }; + //char *response_data; + //response_data = malloc(512); + //strcat(response_data, "mmmmmmmmmmmmmmagic"); + + char temp_sOutputData[60000] = { 0 }; + + if (curl != NULL) + { + + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type:application/json"); + pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //Connection: close + } + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "Content-Type: application/json"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + + //time_t s_timep = time(0); + //struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + //char test_countent[25] = { 0 }; + //strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + + curl_easy_setopt(curl, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + if ((int)strlen(buf_account) >= 1 && (int)strlen(buf_account2) >= 1) + { + curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); + } + curl_easy_setopt(curl, CURLOPT_PORT, iPort); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, temp_sOutputData); + + //為了在UpdateRecoveryTimer 中拿到所有的資料(>57000) + curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 60000); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + + curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); + + if (strcmp(method, "POST") == 0) + { + if (strlen(sData) >= 1) { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); + } + curl_easy_setopt(curl, CURLOPT_POST, 1L); + } + + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//1000 + + curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); + + l_res = CURLE_FAILED_INIT; + + TRY + { + l_res = curl_easy_perform(curl); + } + CATCH + { + l_res = CURLE_FAILED_INIT; + } + ETRY; + + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s:%s", curl_easy_strerror(l_res), function_id); + write_to_logs_html(temp_msg, "curl to ptz", "ERROR", SystemSetting.enable_system_logs); + l_ret = -1; + } + else { + strcpy(sOutputData, temp_sOutputData); + //char temp_msg[8192] = { 0 }; + //snprintf(temp_msg,sizeof(temp_msg), "%s:%s","OK", function_id); + //write_to_logs_html(temp_msg, "curl to ptz", "DEBUG", SystemSetting.enable_system_logs); + l_ret = 0; + } + + curl_easy_reset(curl); + if (pList != NULL) + curl_slist_free_all(pList); + pList = NULL; + } + + + pthread_mutex_unlock(&mutex_curl); + //pthread_mutex_unlock(&mutex_send_cgi); + + return l_ret; +} + +int net_curl_status_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id) +{ + //pthread_mutex_lock(&mutex_send_cgi); + pthread_mutex_lock(&mutex_curl); + CURL *curl = NULL; + CURLcode l_res; + int l_ret = -1; + //const int timeout = 30000; + //const int timeout = 100; + //char *sBuffer; + //char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + + if (g_http_handle != NULL) { + curl_easy_cleanup(g_http_handle); + curl_global_cleanup(); + curl_global_init(CURL_GLOBAL_SSL); + g_http_handle = NULL; + g_http_handle = curl_easy_init(); + } + + curl = g_http_handle; + + struct curl_slist *pList = NULL; + + //char response_data[512] = { 0 }; + //char *response_data; + //response_data = malloc(512); + //strcat(response_data, "mmmmmmmmmmmmmmagic"); + + char temp_sOutputData[60000] = { 0 }; + + if (curl != NULL) + { + + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type:application/json"); + pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //Connection: close + } + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Connection: close"); + pList = curl_slist_append(pList, "Content-Type: application/json"); + pList = curl_slist_append(pList, "Expect:"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + + //time_t s_timep = time(0); + //struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + //char test_countent[25] = { 0 }; + //strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + + curl_easy_setopt(curl, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + if ((int)strlen(buf_account) >= 1 && (int)strlen(buf_account2) >= 1) + { + curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); + } + curl_easy_setopt(curl, CURLOPT_PORT, iPort); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, temp_sOutputData); + + curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 60000); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + + curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); + + if (strcmp(method, "POST") == 0) + { + if (strlen(sData) >= 1) { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); + } + curl_easy_setopt(curl, CURLOPT_POST, 1L); + } + + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//1000 + + curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); + + l_res = CURLE_FAILED_INIT; + + TRY + { + l_res = curl_easy_perform(curl); + } + CATCH + { + l_res = CURLE_FAILED_INIT; + } + ETRY; + + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s:%s", curl_easy_strerror(l_res), function_id); + write_to_logs_html(temp_msg, "curl to ptz status", "ERROR", SystemSetting.enable_system_logs); + l_ret = -1; + } + else { + strcpy(sOutputData, temp_sOutputData); + //char temp_msg[8192] = { 0 }; + //snprintf(temp_msg,sizeof(temp_msg), "%s:%s", "OK", function_id); + //write_to_logs_html(temp_msg, "curl to ptz status", "DEBUG", SystemSetting.enable_system_logs); + l_ret = 0; + } + + curl_easy_reset(curl); + if (pList != NULL) + curl_slist_free_all(pList); + pList = NULL; + } + + + pthread_mutex_unlock(&mutex_curl); + //pthread_mutex_unlock(&mutex_send_cgi); + + return l_ret; +} + +#if 0 +void create_g_curl_connect() +{ + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + //int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + /*CURLcode l_res; + const int timeout = 100; + char ptz_curl_sendbuf[1] = { 0 }; + char sOutputData[1024]; + + + + char *method = "POST";*/ + + g_curl_Handle = g_http_handle; + + if (g_curl_Handle != NULL) + { + //if (strcmp(method, "POST") == 0) + if (1) + { + //pList = curl_slist_append(pList, "Content-Type:application/json"); + //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //Connection: close + } + + g_pList = curl_slist_append(g_pList, "Connection: Keep-Alive"); + //pList = curl_slist_append(pList, "Connection: close"); + curl_easy_setopt(g_curl_Handle, CURLOPT_HTTPHEADER, g_pList); + + // //time_t s_timep = time(0); + // //struct tm *s_timeinfo = localtime(&s_timep); + + // //curl_easy_setopt(curl, CURLOPT_URL, sUrl); + // curl_easy_setopt(g_curl_Handle, CURLOPT_URL, "http://127.0.0.1/server"); + // //strcat(ptz_curl_url, "http://127.0.0.1/server"); + + //printf("%s, %s, %d \n", ptz_curl_username, ptz_curl_password, ptz_port); + //curl_easy_setopt(g_curl_Handle, CURLOPT_USERNAME, ptz_curl_username); + //curl_easy_setopt(g_curl_Handle, CURLOPT_PASSWORD, ptz_curl_password); + //curl_easy_setopt(g_curl_Handle, CURLOPT_PORT, ptz_port); + + // curl_easy_setopt(g_curl_Handle, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); + // curl_easy_setopt(g_curl_Handle, CURLOPT_WRITEDATA, sOutputData); + + curl_easy_setopt(g_curl_Handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(g_curl_Handle, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(g_curl_Handle, CURLOPT_USERAGENT, "IPVideo"); + + curl_easy_setopt(g_curl_Handle, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(g_curl_Handle, CURLOPT_LOW_SPEED_TIME, 10L); + + curl_easy_setopt(g_curl_Handle, CURLOPT_TCP_FASTOPEN, 1L); + + //if (strcmp(method, "POST") == 0) + //if (1) + //{ + // curl_easy_setopt(g_curl_Handle, CURLOPT_POSTFIELDS, ptz_curl_sendbuf); + // curl_easy_setopt(g_curl_Handle, CURLOPT_POSTFIELDSIZE, strlen(ptz_curl_sendbuf)); + // curl_easy_setopt(g_curl_Handle, CURLOPT_POST, 1L); + //} + + curl_easy_setopt(g_curl_Handle, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 + curl_easy_setopt(g_curl_Handle, CURLOPT_TIMEOUT, 1000); + + curl_easy_setopt(g_curl_Handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + // printf("11111 \n"); + + // l_res = curl_easy_perform(g_curl_Handle); + // if (l_res != CURLE_OK) + // { + // //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + // //l_ret = -1; + // } + // else + // { + // //l_ret = 0; + // } + + // printf("22222 \n"); + + // curl_easy_reset(g_curl_Handle); + } +} + +void Free_PTZ_g_curl_connect() { + curl_easy_reset(g_curl_Handle); + curl_slist_free_all(g_pList); + g_pList = NULL; +} +#endif + +#if 0 +int net_curl_ptz_cmd_ghandle(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) +{ + CURL *curl = NULL; + CURLcode l_res; + int l_ret = -1; + //const int timeout = 30000; + //const int timeout = 100; + //char *sBuffer; + //char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + //curl = curl_easy_init(); + curl = g_curl_Handle; + //char sOutputTEST[1024]; + + //struct curl_slist *pList = NULL; + + if (g_curl_Handle != NULL) + { + + //if (strcmp(method, "POST") == 0) + //{ + // //pList = curl_slist_append(pList, "Content-Type:application/json"); + // pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + // //Connection: close + //} + //pList = curl_slist_append(pList, "Connection: close"); + //curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); + + //time_t s_timep = time(0); + //struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + //char test_countent[25] = { 0 }; + //strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + + curl_easy_setopt(curl, CURLOPT_URL, sUrl); + + //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); + curl_easy_setopt(curl, CURLOPT_PORT, iPort); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, sOutputData); + + //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); + + //curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + //curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + + //curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); + + //if (strcmp(method, "POST") == 0) + //{ + // curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); + // curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); + // curl_easy_setopt(curl, CURLOPT_POST, 1L); + //} + + //curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 + //curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1000); + + //curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + l_res = curl_easy_perform(curl); + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", curl_easy_strerror(l_res)); + write_to_logs_html(temp_msg, "curl to ptz ghandle", "ERROR", SystemSetting.enable_system_logs); + l_ret = -1; + } + else + l_ret = 0; + } + + //curl_easy_cleanup(curl); + curl_easy_reset(curl); + //if (pList != NULL) + //curl_slist_free_all(pList); + //pList = NULL; + + return l_ret; +} +#endif + +void UpdatePTZsourceWH(int iVideo_source_w, int iVideo_source_h) +{ + if (iVideo_source_w != 0 && iVideo_source_h != 0) + { + g_stPTZ_Handle.iIMG_source_w = iVideo_source_w; + g_stPTZ_Handle.iIMG_source_h = iVideo_source_h; + } +} + +//void UpdatePTZConfigSetting(char *sEnable_ptz, char *sEnable_tracking, char *sTracking_fov_min, +// char *sTracking_fov_max, char *sConfidence2, int iPTZMode, int iIsTrackingEnterZone, char *sTracking_resume_dwell, +// char *sInMetadata1, int iZoneToPreset[]) +void UpdatePTZConfigSetting() +{ + ///initial setting storege + g_stPTZ_Handle.iIsAtHomePOS = 0; + g_stPTZ_Handle.iIsFlip = 0; + g_stPTZ_Handle.iIsMirror = 0; + g_stPTZ_Handle.iIsInAutopan = 0; + g_stPTZ_Handle.iIsInAutoTracking = 1; + g_stPTZ_Handle.iIsInPreset = 0; + g_stPTZ_Handle.iHomePreset = 0; + + //g_stPTZ_Handle.iIsStayHomePos = 0; + //g_stPTZ_Handle.iSwitchTrackOnOff = 0; + + g_stPTZ_Handle.iRunPTZTrackingThread_flag = 0; + g_stPTZ_Handle.iRunPTZZoomThread_flag = 0; + + + //g_stPTZ_Handle.iIs_enable_alarm = 0; + + g_stPTZ_Handle.iTraffic_cnfidence = 0; + + g_stPTZ_Handle.iEnable_PTZ = 0; + g_stPTZ_Handle.iTracking_fov_min = 0; + g_stPTZ_Handle.iTracking_fov_max = 0; + g_stPTZ_Handle.iEnable_tracking = 0; + g_stPTZ_Handle.iTracking_mode = 1; //Default 1 + g_stPTZ_Handle.iTracking_entering_zone = 1; //Default 1 + //g_stPTZ_Handle.iTracking_resume_dwell = 5; //Default 5 + g_stPTZ_Handle.iIMG_source_w = 0; + g_stPTZ_Handle.iIMG_source_h = 0; + + g_stPTZ_Handle.iPanABS = 0; + g_stPTZ_Handle.iTiltABS = 0; + g_stPTZ_Handle.iZoomABS = 0; + + g_stPTZ_Handle.iRT_min = 0; + g_stPTZ_Handle.iRT_sec = 0; + + + //ptz_zone_to_preset + //printf("===============================================> %d, %d, %d, %d \n", iZoneToPreset[0], iZoneToPreset[1], iZoneToPreset[2], iZoneToPreset[3]); + + /*if (viewDetectionZone[0][0].ptz_zone_to_preset == 0 + && viewDetectionZone[0][1].ptz_zone_to_preset == 0 + && viewDetectionZone[0][2].ptz_zone_to_preset == 0 + && viewDetectionZone[0][3].ptz_zone_to_preset == 0) + { + g_stPTZ_Handle.iZoneToPresetAnyOne = 0; + } + else + { + g_stPTZ_Handle.iZoneToPresetAnyOne = 1; + + for (int i = 0; i < MAX_DETECTION_ZONE; i++) + { + g_stPTZ_Handle.iZoneToPreset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + g_stPTZ_Handle.iZoneToPreset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + } + }*/ + + printf("\n------------------------------->%d \n", g_stPTZ_Handle.iZoneToPresetAnyOne); + + + + //Update PTZ config setting + if (viewChannelData[0].confidence2) //confidece2 = for Traffic + g_stPTZ_Handle.iTraffic_cnfidence = atoi(viewChannelData[0].confidence2); + + //viewChannelData[0].enable_PTZ + if (viewChannelData[0].enable_PTZ) + { + if (strcmp(viewChannelData[0].enable_PTZ, "Yes") == 0) + g_stPTZ_Handle.iEnable_PTZ = 1; + else + g_stPTZ_Handle.iEnable_PTZ = 0; + } + + //viewChannelData[0].ptz_tracking_fov_min + if (viewChannelData[0].ptz_tracking_fov_min) + { + g_stPTZ_Handle.iTracking_fov_min = atoi(viewChannelData[0].ptz_tracking_fov_min); + } + + //viewChannelData[0].ptz_tracking_fov_max + if (viewChannelData[0].ptz_tracking_fov_max) + { + g_stPTZ_Handle.iTracking_fov_max = atoi(viewChannelData[0].ptz_tracking_fov_max); + } + + //viewChannelData[0].ptz_enable_tracking + if (viewChannelData[0].ptz_enable_tracking) + { + if (strcmp(viewChannelData[0].ptz_enable_tracking, "Yes") == 0) + g_stPTZ_Handle.iEnable_tracking = 1; + else + g_stPTZ_Handle.iEnable_tracking = 0; + } + + if (viewChannelData[0].ptz_tracking_mode) + { + g_stPTZ_Handle.iTracking_mode = viewChannelData[0].ptz_tracking_mode; + } + + if (viewChannelData[0].ptz_tracking_by_enter_zone) + { + g_stPTZ_Handle.iTracking_entering_zone = viewChannelData[0].ptz_tracking_by_enter_zone; + } + + if (viewChannelData[0].ptz_tracking_resume_dwell + && strlen(viewChannelData[0].ptz_tracking_resume_dwell) > 0) + { + g_stPTZ_Handle.iTracking_resume_dwell = atoi(viewChannelData[0].ptz_tracking_resume_dwell); + } + else + { + g_stPTZ_Handle.iTracking_resume_dwell = 5; + } + + { + //char msg_temp[512] = { 0 }; + //sprintf(msg_temp, "UpdatePTZConfigSetting g_stPTZ_Handle.iTracking_resume_dwell:%d,,,%s", g_stPTZ_Handle.iTracking_resume_dwell, viewChannelData[0].ptz_tracking_resume_dwell); + //write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); + } + + //Parse Metadata + + //char MetaOut1[20][50] = { 0 }; + //memset(&(g_stPTZ_Handle.sMetaOut1), 0x00, sizeof(SecData)); + + g_stPTZ_Handle.iZoneToPresetAnyOne = 0; + + for (int j = 0; j < viewChannelData[0].count_zone; j++) + { + char MetaData1[BUFSIZE] = { 0 }; + char s_metadata1[512][STRSPLIT_SIZE] = { 0 }; //for filter + for (int i = 0; i < PTZ_TRACKING_OBJ_NUMBER; i++) + { + //memset(&(g_stPTZ_Handle.sMetaOut1[i]), 0x00, sizeof(g_stPTZ_Handle.sMetaOut1[i])); + memset(g_stPTZ_Zone_info[j].sMetaOut1[i], 0x00, 50); //目前未用到, 以防萬一 + } + + g_stPTZ_Zone_info[j].iMetadata1_num = 0; + + int iZoneIdx = j; + if (viewDetectionZone[0][iZoneIdx].metadata1 + && strlen(viewDetectionZone[0][iZoneIdx].metadata1) > 0) + { + //strcpy(MetaData1, viewDetectionZone[0][iZoneIdx].metadata1); + strcpy(MetaData1, viewDetectionZone[0][iZoneIdx].metadata1); + + //g_stPTZ_Handle.iMetadata1_num = StrSplit(MetaData1, s_metadata1, ","); + g_stPTZ_Zone_info[iZoneIdx].iMetadata1_num = StrSplit(MetaData1, s_metadata1, ","); //strsplit = (strtok_r): replace ","->"\0" + + int count_num = 0; + for (int k = 0; k < g_stPTZ_Zone_info[iZoneIdx].iMetadata1_num; k++) + { + int iMetadataIdx = k; + UpperToLower(s_metadata1[iMetadataIdx]); + + if (k == 0 && strcmp(s_metadata1[iMetadataIdx], "null") == 0) { + break; + } + else { + TrimSpace(g_stPTZ_Zone_info[iZoneIdx].sMetaOut1[iMetadataIdx], sizeof(g_stPTZ_Zone_info[iZoneIdx].sMetaOut1[iMetadataIdx]), s_metadata1[iMetadataIdx], 0); + printf("[%d][%d] metadata: %s\n", iZoneIdx, iMetadataIdx, g_stPTZ_Zone_info[iZoneIdx].sMetaOut1[iMetadataIdx]); + count_num++; + } + } + g_stPTZ_Zone_info[iZoneIdx].iMetadata1_num = count_num; + } + + //get zone to preset point + g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset = 0; + + if (viewDetectionZone[0][iZoneIdx].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][iZoneIdx].ptz_zone_to_preset) > 0) + { + g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset = atoi(viewDetectionZone[0][iZoneIdx].ptz_zone_to_preset); + + if (g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset > 0) + g_stPTZ_Handle.iZoneToPresetAnyOne = 1; + } + } + + //g_stPTZ_Handle.iMetadata1_num = 0; + + //Zone 0 + //不可跟上面共用參數 + char MetaData1_temp[BUFSIZE] = { 0 }; + char s_metadata1_temp[512][STRSPLIT_SIZE] = { 0 }; //for filter + + if (viewDetectionZone[0][0].metadata1 + && strlen(viewDetectionZone[0][0].metadata1) > 0) + { + strcpy(MetaData1_temp, viewDetectionZone[0][0].metadata1); + + g_stPTZ_Handle.iMetadata1_num = StrSplit(MetaData1_temp, s_metadata1_temp, ","); + for (int i = 0; i < g_stPTZ_Handle.iMetadata1_num; i++) + { + UpperToLower(s_metadata1_temp[i]); + + TrimSpace(g_stPTZ_Handle.sMetaOut1[i], sizeof(g_stPTZ_Handle.sMetaOut1[i]), s_metadata1_temp[i], 0); + //printf("[%d] metadata: %s \n", i, MetaOut1[i]); + } + } + //printf("\n------UpdatePTZConfigSetting end\n"); +} + + +void* ptz_stop_thread(void * ptr) { + pthread_detach(pthread_self()); + setPthreadName("ptz_stop"); + usSleep(2000000); + StopPtz(); + pthread_exit(NULL); + +} + +int move_PTZ_in_the_direction(int new_pan,int new_tilt) +{ + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = 80; + int curl_ret = 0; + + //strcat(ptz_curl_url, "http://192.168.8.151/server"); + //strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); + + + if (g_stPTZ_Handle.iIsPTZ == 1) { + if (new_pan != 0 && new_tilt != 0) { + sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rpan=%d&rtilt=%d", new_pan, new_tilt); + } + else if (new_pan == 0 && new_tilt != 0) { + sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rtilt=%d", new_tilt); + } + else if (new_pan != 0 && new_tilt == 0) { + sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rpan=%d", new_pan); + } + else { + curl_ret = -1; + } + } + else { + curl_ret = -1; + } + + if (curl_ret >= 0) { + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + //Update PTZ Ipcam info + //int ret = 0; + + char outputData[60000] = { 0 }; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //int iPTZInfoCount = 0; + //char *del = ","; + //float iGetValue = 0; + + curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData, "move PTZ in the direction"); + } + return curl_ret; +} + +int SetPTZNewTilt(int new_tilt) +{ + int curl_ret = -1; + if (g_stPTZ_Handle.iIsPTZ == 1) { + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = 80; + + //strcat(ptz_curl_url, "http://192.168.8.151/server"); + //strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); + sprintf(ptz_curl_url, "http://127.0.0.1/control?tiltposdegree=%d", new_tilt); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + //Update PTZ Ipcam info + //int ret = 0; + + char outputData[60000] = { 0 }; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //int iPTZInfoCount = 0; + //char *del = ","; + //float iGetValue = 0; + + curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData, "Set PTZ new tilt"); + } + return curl_ret; +} + +int SetPTZNewPan(int new_pan) +{ + int curl_ret = -1; + if (g_stPTZ_Handle.iIsPTZ == 1) { + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = 80; + + //strcat(ptz_curl_url, "http://192.168.8.151/server"); + //strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); + sprintf(ptz_curl_url, "http://127.0.0.1/control?panposdegree=%d", new_pan); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + //Update PTZ Ipcam info + //int ret = 0; + + char outputData[60000] = { 0 }; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //int iPTZInfoCount = 0; + //char *del = ","; + //float iGetValue = 0; + + curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData, "Set PTZ new pan"); + } + return curl_ret; +} + +//CGI http://127.0.0.1/control?getcurpos=1 +//Get pan, tilt and zoom absolute value +int UpdatePTZCurPos() +{ + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = 80; + + //strcat(ptz_curl_url, "http://192.168.8.151/server"); + //strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); + strcat(ptz_curl_url, "http://127.0.0.1/control?getcurpos=1"); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + //Update PTZ Ipcam info + //int ret = 0; + + char outputData[60000] = { 0 }; + + char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; + int iPTZInfoCount = 0; + char *del = ","; + float iGetValue = 0; + + int curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Update PTZ CurPos"); + + if (strlen(outputData) > 0) + { + //printf("getcurpos=%s \n", outputData); + iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); + if (iPTZInfoCount >= 3) { + if (arr_sOutputDataList[0]) + { + iGetValue = atof(arr_sOutputDataList[0]); + g_stPTZ_Handle.iPanABS = (int)iGetValue; + //printf("Pan ABS = %d \n", iGetValue); + } + + if (arr_sOutputDataList[1]) + { + iGetValue = atof(arr_sOutputDataList[1]); + g_stPTZ_Handle.iTiltABS = (int)iGetValue; + //printf("Tilt ABS = %d \n", iGetValue); + } + + if (arr_sOutputDataList[2]) + { + iGetValue = atof(arr_sOutputDataList[2]); + g_stPTZ_Handle.iZoomABS = (int)iGetValue; + //printf("Zoom ABS = %d \n", iGetValue); + } + } + } + + return curl_ret; +} + +//CGI http://127.0.0.1/control?getcurpos=1 +//Get pan, tilt and zoom absolute value +int StoreHomePresetPos() +{ + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = 80; + + //strcat(ptz_curl_url, "http://192.168.8.151/server"); + //strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); + strcat(ptz_curl_url, "http://127.0.0.1/control?getcurpos=1"); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + //Update PTZ Ipcam info + //int ret = 0; + + char outputData[60000] = { 0 }; + + char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE] = { 0 }; + int iPTZInfoCount = 0; + char *del = ","; + int iGetValue = 0; + + int curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Store Home PresetPos"); + + if (strlen(outputData) > 0) + { + //printf("getcurpos=%s \n", outputData); + iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); + if (iPTZInfoCount >= 3) { + if (arr_sOutputDataList[0]) + { + iGetValue = atoi(arr_sOutputDataList[0]); + g_stPTZ_Handle.iHomePanABS = iGetValue; + //printf("Pan ABS = %d \n", iGetValue); + } + + if (arr_sOutputDataList[1]) + { + iGetValue = atoi(arr_sOutputDataList[1]); + g_stPTZ_Handle.iHomeTiltABS = iGetValue; + //printf("Tilt ABS = %d \n", iGetValue); + } + + if (arr_sOutputDataList[2]) + { + iGetValue = atoi(arr_sOutputDataList[2]); + g_stPTZ_Handle.iHomeZoomABS = iGetValue; + //printf("Zoom ABS = %d \n", iGetValue); + } + } + } + + return curl_ret; +} + + +int ParseReadLine(char* allbuf, int level, char* linebuf) +{ + int len = strlen(allbuf); + for (; level < len; ++level) + { + if (allbuf[level] == '\r' && allbuf[level + 1] == '\n') + return level + 2; + else + *(linebuf++) = allbuf[level]; + } + return -1; +} + +//CGI http://127.0.0.1/ptzcamera?get=all +//Get Recovery Time +int UpdateRecoveryTime() +{ + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = atoi(accountData[0].account_port); + + strcpy(ptz_curl_username, accountData[0].account_username); + strcpy(ptz_curl_password, accountData[0].account_password); + + strcpy(ptz_curl_url, "http://"); + strcat(ptz_curl_url, "127.0.0.1:"); + strcat(ptz_curl_url, accountData[0].account_port); + strcat(ptz_curl_url, "/ptzcamera?get=all"); + + int ret = 0; + + //recv buffer + char outputData[60000] = { 0 }; //>57000 + //a line data + char sParselinebuf[256] = { 0 }; + //next line's point num + int iParselevel = 0; + char *field; + + char sRTmin[32] = { 0 }; + char sRTsec[32] = { 0 }; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //int iPTZInfoCount = 0; + //char *del = ","; + //int iGetValue = 0; + + /*int curl_ret = */net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Update Recovery Time"); + + if (strlen(outputData) > 0) + { + //printf("size of getall=%d \n", strlen(outputData)); + + do { + memset(sParselinebuf, 0, 256); + iParselevel = ParseReadLine(outputData, iParselevel, sParselinebuf); + + if (strncasecmp(sParselinebuf, "SELF_RT=", 8) == 0) + { + field = (sParselinebuf + 8); + field += strspn(field, " \t"); + memcpy(sRTmin, (sParselinebuf + 8), strlen(sParselinebuf + 8)); + + if (strlen(sRTmin) > 0) + g_stPTZ_Handle.iRT_min = atoi(sRTmin); + } + else if (strncasecmp(sParselinebuf, "SELF_RT_SEC=", 12) == 0) + { + field = (sParselinebuf + 12); + field += strspn(field, " \t"); + memcpy(sRTsec, (sParselinebuf + 12), strlen(sParselinebuf + 12)); + + if (strlen(sRTsec) > 0) + g_stPTZ_Handle.iRT_sec = atoi(sRTsec); + + break; + } + + } while ((outputData[iParselevel] != '\r' || outputData[iParselevel + 1] != '\n') && iParselevel != -1); + } + + return ret; +} + +//CGI http://127.0.0.1/control?get=aiptz +//Response的部份是 +//status = success +//image.mirror = 0 +//image.flip = 0 +//ptz.athomepos = 0 +//ptz.inpreset = 0 +//ptz.inautopan = 0 +//ptz.isautotracking = 0 +int UpdatePTZIPcamSetting() +{ + //printf("iEnable_PTZ: %d \n", g_stPTZ_Handle.iEnable_PTZ); + //printf("iTracking_fov_min: %d \n", g_stPTZ_Handle.iTracking_fov_min); + //printf("iTracking_fov_max: %d \n", g_stPTZ_Handle.iTracking_fov_max); + //printf("iEnable_tracking: %d \n", g_stPTZ_Handle.iEnable_tracking); + //printf("iTracking_resume_dwell: %d \n", g_stPTZ_Handle.iTracking_resume_dwell); + //printf("iIMG_source_w: %d \n", g_stPTZ_Handle.iIMG_source_w); + //printf("iIMG_source_h: %d --------------------------------\n", g_stPTZ_Handle.iIMG_source_h); + + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + //int ptz_port = 80; + + //strcat(ptz_curl_url, "http://192.168.8.151/server"); + //strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); + strcat(ptz_curl_url, "http://127.0.0.1/control?get=aiptz"); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + //Update PTZ Ipcam info + int ret = 0; + + char outputData[60000] = { 0 }; + + char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; + //char **arr_sOutputDataList; + int iPTZInfoCount = 0; + char *del = "\r\n"; + +#if 0 + /*int curl_ret = */net_curl_ptz_cmd_ghandle(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + accountData[0].account_username, accountData[0].account_password, atoi(accountData[0].account_port), outputData); +#endif + +#if 1 + /*int curl_ret = */net_curl_status_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Update PTZ IPcam Setting"); + //int curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, + // ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData); +#endif + +#if 0 + /*int curl_ret =*/ net_socket_ptz_cmd(ptz_url, ptz_curl_sendbuf, NULL, method, + ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData); +#endif + +#if 1 + if (strlen(outputData) > 0 && strstr(outputData,"image.mirror")!=NULL + && strstr(outputData, "image.flip") != NULL + && strstr(outputData, "ptz.athomepos") != NULL + && strstr(outputData, "ptz.inpreset") != NULL + && strstr(outputData, "ptz.inautopan") != NULL + && strstr(outputData, "ptz.isautotracking") != NULL + && strstr(outputData, "ptz.homepreset") != NULL) + { + //printf("Get curl size: %d, content: %s \n", strlen(outputData), outputData); + + iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); + + for (int i = 0; i < iPTZInfoCount; i++) + { + if (arr_sOutputDataList[i]) + { + //printf("[%d]: %s \n", i, arr_sOutputDataList[i]); + + char outArray[2][STRSPLIT_SIZE]={0}; + StrSplit(arr_sOutputDataList[i], outArray, "="); + + int iGetValue = 0; + if (outArray[0] && outArray[1]) + { + if (strstr(outArray[0], "image.mirror")) + { + iGetValue = atoi(outArray[1]); + //printf("mirror= %d \n", iGetValue); + sprintf(accountData[0].account_mirror, "%d", iGetValue); + g_stPTZ_Handle.iIsMirror = iGetValue; + } + else if (strstr(outArray[0], "image.flip")) + { + iGetValue = atoi(outArray[1]); + //printf("flip= %d \n", iGetValue); + sprintf(accountData[0].account_flip, "%d", iGetValue); + g_stPTZ_Handle.iIsFlip = iGetValue; + } + else if (strstr(outArray[0], "ptz.athomepos")) + { + iGetValue = atoi(outArray[1]); + //printf("athomepos= %d \n", iGetValue); + g_stPTZ_Handle.iIsAtHomePOS = iGetValue; + g_stPTZ_Handle.iPauseTrackFlag = 0; + } + else if (strstr(outArray[0], "ptz.inpreset")) + { + iGetValue = atoi(outArray[1]); + //printf("inpreset= %d \n", iGetValue); + g_stPTZ_Handle.iIsInPreset = iGetValue; + } + else if (strstr(outArray[0], "ptz.inautopan")) + { + iGetValue = atoi(outArray[1]); + //printf("inautopan= %d \n", iGetValue); + g_stPTZ_Handle.iIsInAutopan = iGetValue; + } + else if (strstr(outArray[0], "ptz.isautotracking")) + { + iGetValue = atoi(outArray[1]); + //printf("isautotracking= %d \n", iGetValue); + g_stPTZ_Handle.iIsInAutoTracking = iGetValue; + } + else if (strstr(outArray[0], "ptz.homepreset")) + { + iGetValue = atoi(outArray[1]); + if (iGetValue >= 0 && iGetValue <= 256) + g_stPTZ_Handle.iHomePreset = iGetValue; + else + g_stPTZ_Handle.iHomePreset = 0; + } + }//if (outArray[0] && outArray[1]) + }//if (arr_sOutputDataList[i]) + }//for (int i = 0; i < iPTZInfoCount; i++) + //free(arr_sOutputDataList); + + //"ptz.athomepos" 不可信 20220113, 使用此法解套 + if (g_stPTZ_Handle.iIsInPreset == g_stPTZ_Handle.iHomePreset) + { + g_stPTZ_Handle.iIsAtHomePOS = 1; + } + else + { + g_stPTZ_Handle.iIsAtHomePOS = 0; + } + }//if (strlen(outputData) > 0) +#endif + +#if 0 //TEMP TEST + g_stPTZ_Handle.iIsMirror = 0; + g_stPTZ_Handle.iIsFlip = 0; + //g_stPTZ_Handle.iIsAtHomePOS = 1; + //g_stPTZ_Handle.iIsInPreset = 1; + g_stPTZ_Handle.iIsInAutopan = 1; + g_stPTZ_Handle.iIsInAutoTracking = 1; + g_stPTZ_Handle.iHomePreset = 1; +#endif +#if 0 + g_stPTZ_Handle.iIsMirror = 0; + g_stPTZ_Handle.iIsFlip = 0; + g_stPTZ_Handle.iIsInAutopan = 1; + g_stPTZ_Handle.iIsInAutoTracking = 1; +#endif + + //printf("flip, mirror = %s, %s \n", accountData[0].account_flip, accountData[0].account_mirror); + + return ret; +} + +//0 = not ptz, 1 = ptz +int IsPTZ() +{ + return g_stPTZ_Handle.iIsPTZ; +} + +int get_g_PTZ_model() { + return g_PTZ_model; +} + +// CGI http://127.0.0.1/server +// 判斷 SysFeature = 0x4000000 check_ptz +int check_ptz(char *outputData/*char* sUrl, char* sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort*/) +{ + int ret = 0; + + //char outputData[60000] = { 0 }; + + //int curl_ret = net_curl_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, + //sUsername, sPassword, iPort, outputData); + + /*int curl_ret = *///net_curl_status_cmd(sUrl, sSendbuf, NULL, sMethod, sUsername, sPassword, iPort, outputData, "check ptz"); + + char *sFindStr_Start = NULL; + char *sFindStr_End = NULL; + char sSysFeature[128] = { '\0' }; + //int iSysFeature = 0; + + char *sFindModel_Start = NULL; + char *sFindModel_End = NULL; + char sModel[128] = { '\0' }; + //int iModel = 0; + //printf("\nTTTTTTTTTTTT\n"); + + /*{ + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "%s", outputData); + write_to_logs_html(temp_msg, "check ptz", "INFO", "Yes"); + write_to_log_if_error(temp_msg, "check ptz", "INFO"); + }*/ + + if (strlen(outputData) > 0 && g_IsPTZDevice != 1) + { + //printf("Get curl size: %d, content: %s \n", strlen(outputData), outputData); + sFindStr_Start = strstr(outputData, "SysFeature="); + sFindModel_Start = strstr(outputData, "Model="); + + if (sFindStr_Start && sFindModel_Start) + { + sFindStr_Start = sFindStr_Start + strlen("SysFeature="); + sFindModel_Start = sFindModel_Start + strlen("Model="); + //printf("start: 0x%x \n", sFindStr_Start); + + sFindStr_End = strstr(sFindStr_Start, "\n"); + sFindModel_End = strstr(sFindModel_Start, "\n"); + + if (sFindStr_End && sFindModel_End) + { + //printf("start: 0x%x \n", sFindStr_End); + + if ((sFindStr_End - sFindStr_Start) > 0 && (sFindModel_End - sFindModel_Start) > 0) + { + memcpy(sSysFeature, sFindStr_Start, (sFindStr_End - sFindStr_Start)); + memcpy(sModel, sFindModel_Start, (sFindModel_End - sFindModel_Start)); + + unsigned long long int val = strtoull(sSysFeature, NULL, 10); + unsigned long long int iModel = strtoull(sModel, NULL, 10); + g_PTZ_model = (int)iModel; + + //printf("\n-------iModel:%d\n", iModel); + if ((val & SYS_FEATURE_PTZ) == SYS_FEATURE_PTZ && iModel != 659 && iModel != 715 && iModel != 714 && iModel != 731 && iModel != 716) + { + //printf("Is ptz 1\n"); + g_IsPTZDevice = 1; + ret = 1; + } + else + { + //printf("Is ptz 2\n"); + //printf("\n-------sSysFeature: %s, 0x%x\n", sSysFeature, val); + ret = 0; + } + } + } + } + } + + return ret; +} + +void DefaultFocusSetting() +{ + //TEMP TEST 20211122 + //return; + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + char outputData[1024] = { 0 }; + + //sprintf(ptz_curl_url, "/control?airzoom=%d", 7); + + sprintf(ptz_curl_url, "http://127.0.0.1/camera?lensfocus=3&focussen=2&autofocussearch=0&nearlimit=1&ptmovefocusmode=0"); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Default Focus Setting"); +} + +//CGI http://127.0.0.1/image?get=image.mirror +//Response的部份是 +//status=success +//image.mirror=1 +//int IsPTZMirror(char* sUrl, char* sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort) +int IsPTZMirror() +{ + int ret = -1; + + ret = g_stPTZ_Handle.iIsMirror; + + return ret; +} + +//CGI http://127.0.0.1/image?get=image.flip +//Response的部份是 +//status=success +//image.flip=1 +int IsPTZFlip() +{ + int ret = -1; + + ret = g_stPTZ_Handle.iIsFlip; + + return ret; +} + +int IsPTZMirrowFlip() +{ + int ret = -1; + + if (g_stPTZ_Handle.iIsMirror == 1 && g_stPTZ_Handle.iIsFlip == 1) + ret = 1; + else + ret = 0; + + return ret; +} + +//檢查是否在Home點cgi為 /check_home_position +//回覆為Check Home Position = 0,表示不在Home點 +//回覆為Check Home Position = 1,表示在Home點 +int IsPTZatHomePos() +{ + int ret = -1; + + ret = g_stPTZ_Handle.iIsAtHomePOS; + + if (ret == 0 || ret == -1) + { + ret = 0; + } + + //double check + if (ret == 1) + { + //Get cur pos + //UpdatePTZCurPos(); + if (g_stPTZ_Handle.iPanABS != g_stPTZ_Handle.iHomePanABS + || g_stPTZ_Handle.iTiltABS != g_stPTZ_Handle.iHomeTiltABS + || g_stPTZ_Handle.iZoomABS != g_stPTZ_Handle.iHomeZoomABS) + { + ret = 0; + } + } + + return ret; +} + +//Home Preset >= 0 && <= 256 +int GetHomePreset() +{ + int ret = 0; + + ret = g_stPTZ_Handle.iHomePreset; + + return ret; +} + +//檢查是否在預設點cgi為 /check_preset_position +//回覆為Preset Position = 0,表示目前不在任何預設點 +//回覆為Preset Position = 1,表示目前在預設點1,最多到255 +int IsPTZinPreset() +{ + int ret = -1; + + ret = g_stPTZ_Handle.iIsInPreset; + + return ret; +} + + +//檢查是否在預設點cgi為 /ptzcamera ? get = AUTO_MODE_STATUS +//回覆為AUTO_MODE_STATUS=0,表示目前 不在AutoPan 模式. +//回覆為AUTO_MODE_STATUS=1,表示目前 開啟AutoPan 模式. +int IsPTZinAutoPan() +{ + int ret = -1; + + ret = g_stPTZ_Handle.iIsInAutopan; + + return ret; +} + +//回覆為AUTO_MODE_STATUS=0,表示目前 不在AutoPan 模式. +//回覆為AUTO_MODE_STATUS=1,表示目前 開啟AutoPan 模式. +int IsPTZinAutoTracking() +{ + int ret = -1; + + ret = g_stPTZ_Handle.iIsInAutoTracking; + + return ret; +} + +//0 = Not in tracking mode, 1 = In tracking mode +int IsTracking() +{ + int ret = -1; + + //time_t tCheckAutoTrackingTimeStart = time(0); + //time_t tCheckAutoTrackingTimeCurrent = time(0); + //double dwDeltaCheckTime = 0.0; + + //int diffOperatSecs = difftime(tCheckAutoTrackingTimeCurrent, g_stPTZ_Handle.tChangAutoPanTime); + + + //if (dwDeltaCheckTime ) + if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) + { + //g_stPTZ_Handle.tChangAutoPanTime = time(0); + ret = 1; + } + else if (g_stPTZ_Handle.iIsInAutopan == 0 && g_stPTZ_Handle.iIsInAutoTracking == 0) + { + //dwDeltaCheckTime = difftime(tCheckAutoTrackingTimeCurrent, g_stPTZ_Handle.tChangAutoPanTime); + //if (dwDeltaCheckTime >= PTZ_IS_TRACKING_TIMER) + //{ + ret = 0; + //} + //else + //{ + // ret = 1; + //} + } + else if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 0) + { + ret = 0; + } + + return ret; +} + + +int GetPTZActionState() +{ + int ret = 0; + + return ret; +} + +int StartTracking() +{ + int ret = 0; + + return ret; +} + +int StopTracking() +{ + int ret = 0; + + return ret; +} + +int EnableAlarmQuaue() +{ + int ret = 0; + + + + return ret; +} + +int DisableAlarmQueue() +{ + int ret = 0; + + return ret; +} + +int GetPTZStatus() +{ + int ret = 0; + + return ret; +} + +typedef struct point { double x, y; } point; + +double getAngleBetween(point p1, point p2) +{ + double x = p2.x - p1.x, y = p2.y - p1.y; + double angle = asin(y / sqrt(x * x + y * y)) * (180 / MATH_PI); + angle = x < 0 ? angle - 90 : 90 - angle; + return angle < 0 ? angle + 360 : angle; +} + +void send_request(char *szIP, char *sUrl, char *sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort, char *sOutputData, char* function_id) +{ + //int ret = 0; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //int iPTZInfoCount = 0; + //char *del = "\r\n"; + +#if 0 + FILE * pPipe; + char cmd[512] = { 0 }; + //memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "curl %s", sUrl); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#endif + + //strcat(ptz_curl_username, accountData[0].account_username); + //strcat(ptz_curl_password, accountData[0].account_password); + +#if 0 + /*int curl_ret = */net_curl_ptz_cmd_ghandle(sUrl, sSendbuf, NULL, sMethod, + accountData[0].account_username, accountData[0].account_password, iPort, sOutputData); +#endif + +#if 1 + /*int curl_ret = */net_curl_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, + sUsername, sPassword, iPort, sOutputData, function_id); +#endif + +#if 0 + /*int curl_ret = */net_socket_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, + sUsername, sPassword, iPort, sOutputData); +#endif + +#if 0 + /*int curl_ret = */net_curl_ptz_cmd_multi_interface(sUrl, sSendbuf, NULL, sMethod, + sUsername, sPassword, iPort, sOutputData); +#endif + +#if 0 + SendCGIHighSpeed_B(sUsername, sPassword, szIP, iPort, sUrl); + //SendCGIHighSpeed(sUsername, sPassword, szIP, iPort, sUrl); +#endif + +} + +void GetLockObjFOV(int iResW, int iResH) +{ + int OutBox_w = g_stPTZ_Handle.stPTZOutsideBox.width; + int OutBox_h = g_stPTZ_Handle.stPTZOutsideBox.height; + int OutBox_Scale_w = 0, OutBox_Scale_h = 0; + + int iLimitW = (int)(iResW * PTZ_ZOOMIN_LIMIT) / 100; + int iLimitH = (int)(iResH * PTZ_ZOOMIN_LIMIT) / 100; + + g_stPTZ_Handle.iLockObjFOV = 0; + + if ((OutBox_w > 0 && OutBox_w < iResW) + && (OutBox_h > 0 && OutBox_h < iResH) + ) + { + //printf("rw, rh: %d, %d \n", iResW, iResH); + //printf("O_w, O_h: %d, %d \n", OutBox_w, OutBox_h); + + OutBox_Scale_w = ((OutBox_w * 1000) / iLimitW) / 10; + OutBox_Scale_h = ((OutBox_h * 1000) / iLimitH) / 10; + + + if (OutBox_Scale_w > OutBox_Scale_h) + g_stPTZ_Handle.iLockObjFOV = OutBox_Scale_w; + else + g_stPTZ_Handle.iLockObjFOV = OutBox_Scale_h; + + //printf("s_w / s_h: %d, %d, %d \n", OutBox_Scale_w, OutBox_Scale_h, g_stPTZ_Handle.iLockObjFOV); + } + + //return g_stPTZ_Handle.iLockObjFOV; +} + +int IfDoZoom(int iResW, int iResH, int iInZoomScale) +{ + int iZoomScale = 0; + + if (g_stPTZ_Handle.iLockObjFOV != 0) + { + + if (g_stPTZ_Handle.iLockObjFOV > (g_stPTZ_Handle.iTracking_fov_max + 5)) + { + iZoomScale = g_stPTZ_Handle.iLockObjFOV; + } + else if (g_stPTZ_Handle.iLockObjFOV < (g_stPTZ_Handle.iTracking_fov_max - 5)) + { + iZoomScale = g_stPTZ_Handle.iLockObjFOV; + } + } + else + iZoomScale = 0; + + +#if 0 + int iZoomScale = 0; + + int OutBox_w = g_stPTZ_Handle.stPTZOutsideBox.width; + int OutBox_h = g_stPTZ_Handle.stPTZOutsideBox.height; + int OutBox_Scale_w = 0, OutBox_Scale_h = 0; + int MINZoomScale = g_stPTZ_Handle.iTracking_fov_min; //iInZoomScale + int MAXZoomScale = g_stPTZ_Handle.iTracking_fov_max; + + int iLimitW = (int)(iResW * PTZ_ZOOMIN_LIMIT) / 100; + int iLimitH = (int)(iResH * PTZ_ZOOMIN_LIMIT) / 100; + + //Check Outbox avaliable + if ((OutBox_w > 0 && OutBox_w < iResW) + && (OutBox_h > 0 && OutBox_h < iResH) + ) + { + //printf("rw, rh: %d, %d \n", iResW, iResH); + //printf("O_w, O_h: %d, %d \n", OutBox_w, OutBox_h); + + OutBox_Scale_w = ((OutBox_w * 1000) / iLimitW) / 10; + OutBox_Scale_h = ((OutBox_h * 1000) / iLimitH) / 10; + + //printf("s_w / s_h: %d, %d, %d \n", OutBox_Scale_w, OutBox_Scale_h, iInZoomScale); + //printf("iInZoomScale = %d \n", iInZoomScale); + + if (OutBox_Scale_w > OutBox_Scale_h) + iZoomScale = OutBox_Scale_w; + else + iZoomScale = OutBox_Scale_h; + +#if 0 + if ((OutBox_Scale_w > (iInZoomScale + 10)) + || (OutBox_Scale_h > (iInZoomScale + 10)) + ) + { + //Zoom out + iZoomScale = 2; + //printf("Scale 3: %d \n", iZoomScale); + } + else if ( (OutBox_Scale_w < (iInZoomScale-10)) + && (OutBox_Scale_h < (iInZoomScale-10)) ) + { + //Zoom in + iZoomScale = -2; + + //printf("Scale 3: %d \n", iZoomScale); + } + else + { + iZoomScale = 0; + } +#endif + } + else + iZoomScale = 0; + +#endif + + return iZoomScale; +} + +int IfStopZoom() +{ + int ret = 0; + + if (g_stPTZ_Handle.stPTZOutsideBox.center_x == 0 + && g_stPTZ_Handle.stPTZOutsideBox.center_y == 0) + { + ret = 1; + } + + return ret; +} + +int GetOutsideAllBox() +{ + int ret = 1; + float left_x = 999999, top_y = 999999; + float right_x = -1, bottom_y = -1; + //float iCenter_x = 0, iCenter_y = 0; + + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + if (g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y <= top_y) + top_y = g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y; + + if (g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x <= left_x) + left_x = g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x; + + if ((g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y + g_stPTZ_Handle.stPTZCandidateBoxTable[i].height) >= bottom_y) + bottom_y = (g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y + g_stPTZ_Handle.stPTZCandidateBoxTable[i].height); + + if ((g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x + g_stPTZ_Handle.stPTZCandidateBoxTable[i].width) >= right_x) + right_x = (g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x + g_stPTZ_Handle.stPTZCandidateBoxTable[i].width); + } + + //printf("-------------> x, y, x, y = %f, %f, %f, %f \n", left_x, top_y, right_x, bottom_y); + + if (left_x < 999999 && top_y < 999999 && right_x > -1 && bottom_y > -1) + { + g_stPTZ_Handle.stPTZOutsideBox.left_x = left_x; + g_stPTZ_Handle.stPTZOutsideBox.top_y = top_y; + + g_stPTZ_Handle.stPTZOutsideBox.width = right_x - left_x; + g_stPTZ_Handle.stPTZOutsideBox.center_x = g_stPTZ_Handle.stPTZOutsideBox.left_x + ((right_x - left_x) / 2); + + g_stPTZ_Handle.stPTZOutsideBox.height = bottom_y - top_y; + g_stPTZ_Handle.stPTZOutsideBox.center_y = g_stPTZ_Handle.stPTZOutsideBox.top_y + ((bottom_y - top_y) / 2); + + g_stPTZ_Handle.stPTZOutsideBox.class_id = 9999; + } + + return ret; +} + +//int GetOutsideBox(detection_pos *posInfo, int iTotalElementSize, int iResW, int iResH) +//{ +// detection_pos *pNext = NULL; +// //point p1, p2; +// //char *sTrackClass = "bus"; +// //1920 / 1080 +// int ret = 1; +// +// float left_x = 999999, top_y = 999999; +// float right_x = -1, bottom_y = -1; +// //float iCenter_x = 0, iCenter_y = 0; +// //int diff_x = 0, diff_y = 0; +// +// //int iPercentage_W = 50, iPercentage_H = 50; +// +// int iFilter_confidence = 0; +// +// if (g_stPTZ_Handle.iTraffic_cnfidence != 0) +// iFilter_confidence = g_stPTZ_Handle.iTraffic_cnfidence; +// //printf("PTZ TRAFFIC CONFIDENCE: %d \n", iFilter_confidence); +// +// for (int i = 0; i < iTotalElementSize; i++) +// { +// pNext = posInfo + i; +// +// if (pNext->confidence >= iFilter_confidence) +// { +// for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) + //{ +// if (strcmp(pNext->name, g_stPTZ_Handle.sMetaOut1[j]) == 0) +// { +// //printf("[%d]ori x/y, w/h = %f, %f, %f, %f \n", i, pNext->left_x, pNext->top_y, pNext->width, pNext->height); +// +// if (pNext->top_y <= top_y) +// top_y = pNext->top_y; +// +// if (pNext->left_x <= left_x) +// left_x = pNext->left_x; +// +// if ((pNext->top_y + pNext->height) >= bottom_y) +// bottom_y = (pNext->top_y + pNext->height); +// +// if ((pNext->left_x + pNext->width) >= right_x) +// right_x = (pNext->left_x + pNext->width); +// +// //printf("outside box_x/y/ x/y: %f, %f, %f, %f \n\n", left_x, top_y, right_x, bottom_y); + //} +// } +// } +// } +// +// //printf("outside box_x/y/ x/y: %f, %f, %f, %f \n\n", left_x, top_y, right_x, bottom_y); +// +// if (left_x < 999999 && top_y < 99999 && right_x > -1 && bottom_y > -1) +// { +// if (g_stPTZ_Handle.stPTZOutsideBox.left_x == -1 +// && g_stPTZ_Handle.stPTZOutsideBox.top_y == -1) + //{ +// g_stPTZ_Handle.stPTZOutsideBox.iFirstTrackingFlag = 3; +// g_stPTZ_Handle.iZoomFreqCount -= 10; + //} +// +// g_stPTZ_Handle.stPTZOutsideBox.left_x = left_x; +// g_stPTZ_Handle.stPTZOutsideBox.top_y = top_y; +// +// if (right_x > left_x) + //{ +// g_stPTZ_Handle.stPTZOutsideBox.width = right_x - left_x; +// g_stPTZ_Handle.stPTZOutsideBox.center_x = g_stPTZ_Handle.stPTZOutsideBox.left_x + ((right_x - left_x) / 2); +// +// //加入預測提前量 +// //{ +// //} +// } +// else +// { +// ret = -1; +// } +// +// if (bottom_y > top_y) +// { +// g_stPTZ_Handle.stPTZOutsideBox.height = bottom_y - top_y; +// g_stPTZ_Handle.stPTZOutsideBox.center_y = g_stPTZ_Handle.stPTZOutsideBox.top_y + ((bottom_y - top_y) / 2); +// +// //加入預測提前量 +// //{ +// //} +// } +// else +// { +// ret = -1; +// } +// +//#if 0 +// //計算角度位置 +// diff_x = g_stPTZ_Handle.stPTZOutsideBox.center_x - (iResW / 2); +// diff_y = (iResH / 2) - g_stPTZ_Handle.stPTZOutsideBox.center_y; +// +// p1.x = 0; +// p1.y = 0; +// p2.x = diff_x; +// p2.y = diff_y; +// +// g_stPTZ_Handle.dwMoveAngel = getAngleBetween(p1, p2); +// +// //計算移動速度 +// g_stPTZ_Handle.iMoveSpeed_x = diff_x / (iResW / 14); +// g_stPTZ_Handle.iMoveSpeed_y = diff_y / (iResH / 14); +// +// //if (g_stPTZ_Handle.iMoveSpeed_y < 0) +// //{ +// // g_stPTZ_Handle.iMoveSpeed_y = (g_stPTZ_Handle.iMoveSpeed_y * 2) % 7; +// //} +// +// if (g_stPTZ_Handle.iMoveSpeed_x > 7) +// g_stPTZ_Handle.iMoveSpeed_x = 7; +// +// if (g_stPTZ_Handle.iMoveSpeed_x < -7) +// g_stPTZ_Handle.iMoveSpeed_x = -7; +// +// if (g_stPTZ_Handle.iMoveSpeed_y > 7) +// g_stPTZ_Handle.iMoveSpeed_y = 7; +// +// if (g_stPTZ_Handle.iMoveSpeed_y < -7) +// g_stPTZ_Handle.iMoveSpeed_y = -7; +// +// //if (g_stPTZ_Handle.iMoveSpeed_x > 7 || g_stPTZ_Handle.iMoveSpeed_x < -7) +// // g_stPTZ_Handle.iMoveSpeed_x = 0; +// +// //if (g_stPTZ_Handle.iMoveSpeed_y > 7 || g_stPTZ_Handle.iMoveSpeed_y < -7) +// // g_stPTZ_Handle.iMoveSpeed_y = 0; +//#endif +// } +// else +// { +// g_stPTZ_Handle.stPTZOutsideBox.center_x = 0; +// g_stPTZ_Handle.stPTZOutsideBox.center_y = 0; +// g_stPTZ_Handle.stPTZOutsideBox.width = -1; +// g_stPTZ_Handle.stPTZOutsideBox.height = -1; +// //g_stPTZ_Handle.iTimer_send_count = 0; +// //g_stPTZ_Handle.dwMoveAngel = 0; +// //g_stPTZ_Handle.iMoveSpeed_x = 0; +// //g_stPTZ_Handle.iMoveSpeed_y = 0; +// g_stPTZ_Handle.stPTZOutsideBox.iFirstTrackingFlag = 0; +// +// ret = -1; +// } +// +// return ret; + //} + +int GetOutsideLockBox(int iResW, int iResH) +{ + int ret = 1; + + //1: 只追第一次鎖定的物件, 遺失後改追範圍內最接近的 + //2: 追較大的物件 + //3: 追第一次鎖定的物件, 遺失後改追周遭同類型最大的 + + //if (g_stPTZ_Handle.iTracking_mode == 1 || g_stPTZ_Handle.iTracking_mode == 2) + //{ + g_stPTZ_Handle.stPTZOutsideBox.left_x = g_stPTZ_Handle.stPTZLockTrackingBox.left_x; + g_stPTZ_Handle.stPTZOutsideBox.top_y = g_stPTZ_Handle.stPTZLockTrackingBox.top_y; + + g_stPTZ_Handle.stPTZOutsideBox.center_x = g_stPTZ_Handle.stPTZLockTrackingBox.left_x + (g_stPTZ_Handle.stPTZLockTrackingBox.width / 2); + g_stPTZ_Handle.stPTZOutsideBox.center_y = g_stPTZ_Handle.stPTZLockTrackingBox.top_y + (g_stPTZ_Handle.stPTZLockTrackingBox.height / 2); + + g_stPTZ_Handle.stPTZOutsideBox.width = g_stPTZ_Handle.stPTZLockTrackingBox.width; + g_stPTZ_Handle.stPTZOutsideBox.height = g_stPTZ_Handle.stPTZLockTrackingBox.height; + + g_stPTZ_Handle.stPTZOutsideBox.class_id = g_stPTZ_Handle.stPTZLockTrackingBox.class_id; + //} + //else if (g_stPTZ_Handle.iTracking_mode == 3) + //{ + // ret = GetOutsideAllBox(); + //printf("outside box_x/y/ x/y: %d, %fd, %d, %d \n\n", g_stPTZ_Handle.stPTZOutsideBox.left_x, g_stPTZ_Handle.stPTZOutsideBox.top_y, g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); + //} + + + + return ret; +} + +int OutsideBoxChange() + { + int ret = 0; + int iRecordCount; + + iRecordCount = g_stPTZ_Handle.iRecordOldOutsideBoxCount; + + //If same with last one + if (iRecordCount > 0) + { + if (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x == g_stPTZ_Handle.stPTZOutsideBox.center_x + && g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y == g_stPTZ_Handle.stPTZOutsideBox.center_y) + { + ret = 0; + } + else + { + ret = 1; + } + } + else + { + ret = 1; + } + + //Store record + iRecordCount++; + + if (iRecordCount > MAX_RECORD_BOX_SIZE) + { + iRecordCount = MAX_RECORD_BOX_SIZE; + g_stPTZ_Handle.iRecordOldOutsideBoxCount = iRecordCount; + + for (int n = 0; n < iRecordCount - 1; n++) + { + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].left_x = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].left_x; + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].top_y = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].top_y; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].center_x = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].center_x; + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].center_y = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].center_y; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].width = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].width; + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].height = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].height; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].class_id = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].class_id; + + } + } + else + { + g_stPTZ_Handle.iRecordOldOutsideBoxCount = iRecordCount; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].left_x = g_stPTZ_Handle.stPTZOutsideBox.left_x; + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].top_y = g_stPTZ_Handle.stPTZOutsideBox.top_y; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x = g_stPTZ_Handle.stPTZOutsideBox.center_x; + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y = g_stPTZ_Handle.stPTZOutsideBox.center_y; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].width = g_stPTZ_Handle.stPTZOutsideBox.width; + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].height = g_stPTZ_Handle.stPTZOutsideBox.height; + + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].class_id = g_stPTZ_Handle.stPTZOutsideBox.class_id; + } + + return ret; +} + + +int IfGoCenter(int iResW, int iResH) +{ + int ret = 1; + + ret = OutsideBoxChange(); + //printf("If Outside Box Change = %d \n", ret); + + //Outside box not change + if (ret == 0) + { + return -1; + } +#if 1 + int iPercentage_W = ((g_stPTZ_Handle.stPTZOutsideBox.center_x * 1000 / (g_stPTZ_Handle.iIMG_source_w)) / 10); + int iPercentage_H = ((g_stPTZ_Handle.stPTZOutsideBox.center_y * 1000 / (g_stPTZ_Handle.iIMG_source_h)) / 10); + + //printf("CKW / CKH: %d, %d \n", iPercentage_W, iPercentage_H); + if (iPercentage_W > PTZ_CENTER_AREA_X2_MIN + && iPercentage_W < PTZ_CENTER_AREA_X2_MAX + && iPercentage_H > PTZ_CENTER_AREA_X2_MIN + && iPercentage_H < PTZ_CENTER_AREA_X2_MAX) + { + ret = -1; + } + else + { + ret = 1; + } + +//中心3%太靈敏, 會晃 +#if 0 + if (g_stPTZ_Handle.iPTZ_speed == 1) + { + if (iPercentage_W > 49 + && iPercentage_W < 51 + && iPercentage_H > 49 + && iPercentage_H < 51) + { + ret = -1; + } + else + { + ret = 1; + } + } +#endif + +#endif + +//避免擺盪 去提前量 取中心點 +#if 0 + int iRecordCount = g_stPTZ_Handle.iRecordOldOutsideBoxCount; + + if (iRecordCount >= 2) + { + if (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 2].obj_tracking_id == g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].obj_tracking_id) + { + //X + float iMidCenter_X = (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 2].center_x + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x) / 2; + int iPercentage_X = ((iMidCenter_X * 1000 / (g_stPTZ_Handle.iIMG_source_w)) / 10); + + if (iPercentage_X > PTZ_FILTER_AREA_MIN + && iPercentage_X < PTZ_FILTER_AREA_MAX) + { + g_stPTZ_Handle.stPTZOutsideBox.center_x = iMidCenter_X; + //g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x = iMidCenter_X; + + //g_stPTZ_Handle.stPTZOutsideBox.left_x = iMidCenter_X - (g_stPTZ_Handle.stPTZOutsideBox.width / 2); + //g_stPTZ_Handle.stPTZOutsideBox.right_x = iMidCenter_X + (g_stPTZ_Handle.stPTZOutsideBox.width / 2); + + //if (g_stPTZ_Handle.stPTZOutsideBox.left_x < 0) + //{ + // g_stPTZ_Handle.stPTZOutsideBox.left_x = 0; + //} + //else if (g_stPTZ_Handle.stPTZOutsideBox.right_x > g_stPTZ_Handle.iIMG_source_w) + //{ + // g_stPTZ_Handle.stPTZOutsideBox.right_x = g_stPTZ_Handle.iIMG_source_w; + //} + + //g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].right_x = g_stPTZ_Handle.stPTZOutsideBox.right_x; + //g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].right_x = g_stPTZ_Handle.stPTZOutsideBox.right_x; + } + + //Y + float iMidCenter_Y = (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 2].center_y + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y) / 2; + int iPercentage_Y = ((iMidCenter_Y * 1000 / (g_stPTZ_Handle.iIMG_source_h)) / 10); + + if (iPercentage_Y > PTZ_FILTER_AREA_MIN + && iPercentage_Y < PTZ_FILTER_AREA_MAX) + { + g_stPTZ_Handle.stPTZOutsideBox.center_y = iMidCenter_Y; + //g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y = iMidCenter_Y; + + //g_stPTZ_Handle.stPTZOutsideBox.top_y = iMidCenter_Y - (g_stPTZ_Handle.stPTZOutsideBox.height / 2); + //g_stPTZ_Handle.stPTZOutsideBox.bottom_y = iMidCenter_Y + (g_stPTZ_Handle.stPTZOutsideBox.height / 2); + + //if (g_stPTZ_Handle.stPTZOutsideBox.top_y < 0) + //{ + // g_stPTZ_Handle.stPTZOutsideBox.top_y = 0; + //} + //else if (g_stPTZ_Handle.stPTZOutsideBox.bottom_y > g_stPTZ_Handle.iIMG_source_h) + //{ + // g_stPTZ_Handle.stPTZOutsideBox.bottom_y = g_stPTZ_Handle.iIMG_source_h; + //} + + //g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].top_y = g_stPTZ_Handle.stPTZOutsideBox.top_y; + //g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].bottom_y = g_stPTZ_Handle.stPTZOutsideBox.bottom_y; + } + } + } +#endif + +#if 0 + int iKeepArea_left_x, iKeepArea_top_y; + int iKeepArea_right_x, iKeepArea_bottom_y; + int iKeepArea_w, iKeepArea_h; + + //PTZ_CENTER_AREA % + if (g_stPTZ_Handle.iZoomABS >= 10) + { + iKeepArea_w = iResW * PTZ_CENTER_AREA_X8 / 100; + iKeepArea_h = iResH * PTZ_CENTER_AREA_X8 / 100; + } + else if (g_stPTZ_Handle.iZoomABS >= 5 && g_stPTZ_Handle.iZoomABS < 10) + { + iKeepArea_w = iResW * PTZ_CENTER_AREA_X5 / 100; + iKeepArea_h = iResH * PTZ_CENTER_AREA_X5 / 100; + } + else if (g_stPTZ_Handle.iZoomABS < 5) + { + iKeepArea_w = iResW * PTZ_CENTER_AREA_X2 / 100; + iKeepArea_h = iResH * PTZ_CENTER_AREA_X2 / 100; + } + + iKeepArea_left_x = (iResW / 2) - (iKeepArea_w / 2); + iKeepArea_top_y = (iResH / 2) - (iKeepArea_h / 2); + + iKeepArea_right_x = (iResW / 2) + (iKeepArea_w / 2); + iKeepArea_bottom_y = (iResH / 2) + (iKeepArea_h / 2); + + //printf("k_x, k_x2, k_y, k_y2: %d, %d, %d, %d \n", iKeepArea_left_x, iKeepArea_right_x, iKeepArea_top_y, iKeepArea_bottom_y); + //printf("o_cx, o_cy: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); + + if (g_stPTZ_Handle.stPTZOutsideBox.center_x != 0 && g_stPTZ_Handle.stPTZOutsideBox.center_y != 0) + { + if (g_stPTZ_Handle.stPTZOutsideBox.center_x >= iKeepArea_left_x + && g_stPTZ_Handle.stPTZOutsideBox.center_x <= iKeepArea_right_x + && g_stPTZ_Handle.stPTZOutsideBox.center_y >= iKeepArea_top_y + && g_stPTZ_Handle.stPTZOutsideBox.center_y <= iKeepArea_bottom_y + ) + { + //printf("k_x, k_x2, k_y, k_y2: %d, %d, %d, %d \n", iKeepArea_left_x, iKeepArea_right_x, iKeepArea_top_y, iKeepArea_bottom_y); + //printf("AAA o_cx, o_cy: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); + + ret = -1; + } + else + { + //printf("BBB o_cx, o_cy: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); + ret = 1; + } + } + else + ret = -1; +#endif + + return ret; +} + +int IfGetLockBox() +{ + int ret = 0; + + ret = g_stPTZ_Handle.iIsGetLockTrackingBox; + + return ret; +} + +int FindNearestBox() +{ + int iNearestDis = 9999; + int iNearestIdx = -1; + float fDist = 0; + + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + fDist = FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_x, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_y); + + if (fDist < iNearestDis) + { + iNearestDis = fDist; + iNearestIdx = i; + } + } + + return iNearestIdx; +} + +int FindBiggestBox() +{ + //int iResult = 0; + int iMax_area = 0; + int iBox_area = 0; + int iMaxAreaIdx = -1; + int iBoxW = 0; + int iBoxH = 0; + + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + iBoxW = g_stPTZ_Handle.stPTZCandidateBoxTable[i].width; + iBoxH = g_stPTZ_Handle.stPTZCandidateBoxTable[i].height; + iBox_area = iBoxW * iBoxH; + + if (iBox_area > iMax_area) + { + iMax_area = iBox_area; + iMaxAreaIdx = i; + } + } + + return iMaxAreaIdx; +} + +int GetSingleLockTrackingBox(int iResW, int iResH) +{ + int iLockBoxIdx = -1; + //time_t tCurrentTime = time(0); + + + //AI_fps: 根據目前FPS, 決定當鎖定物件消失時, 要等多久才放棄. + + pthread_mutex_lock(&mutex_update_candidate); + + { + //char msg_temp[512] = { 0 }; + //sprintf(msg_temp, "g_stPTZ_Handle.iCandidateBoxCount:%d", g_stPTZ_Handle.iCandidateBoxCount); + //write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); + } + +#if 1 + if (g_stPTZ_Handle.iCandidateBoxCount > 0) + { + if (g_stPTZ_Handle.iTracking_mode == 3) + { + if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0) + { + if (g_stPTZ_Handle.iCandidateBoxCount == 1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = 0; + } + else if (g_stPTZ_Handle.iCandidateBoxCount > 1)//Find biggest box + { + int iBiggestBoxIdx = FindBiggestBox(); + if (iBiggestBoxIdx != -1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = iBiggestBoxIdx; + } + } + } + else if (g_stPTZ_Handle.iIsGetLockTrackingBox == 1) + { + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + if (g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id == g_stPTZ_Handle.stPTZCandidateBoxTable[i].obj_tracking_id + /*&& strcmp(g_stPTZ_Handle.stPTZLockTrackingBox.name, pNext1->name) == 0*/) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = i; + break; + } + } + +#if 1 + //Lose lock obj => fine nearst obj (半徑範圍內尋找) + if (iLockBoxIdx == -1) + { + //容許遺失次數, 暫時不動作 + + + int iClosestBoxIDX = -1; + float fClosestDistense = 999999; + float fCurDist = 0.0; + float fRadius = 0.0; + + fRadius = (float)(3 * FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZLockTrackingBox.left_x, g_stPTZ_Handle.stPTZLockTrackingBox.top_y)); + + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + fCurDist = FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_x, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_y); + + if (fCurDist < fClosestDistense && fCurDist <= fRadius) + { + fClosestDistense = fCurDist; + iClosestBoxIDX = i; + } + + if (iClosestBoxIDX != -1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = iClosestBoxIDX; + } + } + } +#endif + //iLockBoxIdx = 2; + } + } + else if (g_stPTZ_Handle.iTracking_mode == 2) + { + int iBiggestBoxIdx = FindBiggestBox(); + if (iBiggestBoxIdx != -1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = iBiggestBoxIdx; + } + } + else if (g_stPTZ_Handle.iTracking_mode == 1) + { + if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0) //first + { + g_stPTZ_Handle.iMissObjMomnentCount = 0; + if (g_stPTZ_Handle.iCandidateBoxCount == 1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = 0; + } + else if (g_stPTZ_Handle.iCandidateBoxCount > 1)//Find Biggest box + { +#if 1 + int iBiggestBoxIdx = FindBiggestBox(); + if (iBiggestBoxIdx != -1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = iBiggestBoxIdx; + } + else + { + //強制給予第一個 + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = 0; + } +#endif + } + } + else if (g_stPTZ_Handle.iIsGetLockTrackingBox == 1) //have been lock + { + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + if (g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id == g_stPTZ_Handle.stPTZCandidateBoxTable[i].obj_tracking_id + && strcmp(g_stPTZ_Handle.stPTZLockTrackingBox.name, g_stPTZ_Handle.stPTZCandidateBoxTable[i].name) == 0) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = i; + break; + } + } + +#if 1 + //Lose lock obj => fine nearst obj (半徑範圍內尋找) + if (iLockBoxIdx == -1) + { + //容許遺失次數, 暫時不動作 + //若小於遺失次數限制 && 不再原點, 則暫時不指定ClosestBox + int iMissingTimeLimit = 0; + if (g_IsShipTracking) + iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_LONG; + else + iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_SHORT; + + if (g_stPTZ_Handle.iLoseLockObjCount < iMissingTimeLimit) + { + iLockBoxIdx = PTZ_MISS_OBJ_MAGIC_FLAG; + if (g_IsShipTracking) + usSleep(100000); + } + else + { + int iClosestBoxIDX = -1; + float fClosestDistense = 999999; + float fCurDist = 0.0; + float fRadius = 0.0; + + fRadius = (float)(3 * FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZLockTrackingBox.left_x, g_stPTZ_Handle.stPTZLockTrackingBox.top_y)); + + for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) + { + fCurDist = FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_x, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_y); + + if (fCurDist < fClosestDistense && fCurDist <= fRadius) + { + fClosestDistense = fCurDist; + iClosestBoxIDX = i; + } + + if (iClosestBoxIDX != -1) + { + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = iClosestBoxIDX; + break; + } + } + } //if (g_stPTZ_Handle.iLoseLockObjCount < 7) + } + + //Still = -1 //取消, 外部會判斷錯誤 + //if (iLockBoxIdx == -1) + //{ + // g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + // iLockBoxIdx = 0; + //} +#endif + } + } + } // iCandidateBoxCount > 0 + else + { + int iMissingTimeLimit = 0; + if (g_IsShipTracking) + iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_LONG; + else + iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_SHORT; + + if (g_stPTZ_Handle.iLoseLockObjCount < iMissingTimeLimit) + { + iLockBoxIdx = PTZ_MISS_OBJ_MAGIC_FLAG; + } + else + { + iLockBoxIdx = -1; + } + } + + //g_stPTZ_Handle.iCandidateBoxCount = 0; //Reset every time parse end + + pthread_mutex_unlock(&mutex_update_candidate); + +#if 0 + printf("lockbox id = %d \n", iLockBoxIdx); + printf("lock box %s, x, y, w, h = %d, %d, %d, %d \n", + g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name, + g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].left_x, + g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].top_y, + g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].width, + g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].height); +#endif + +#if 1 + //Assign lock box data + if (iLockBoxIdx >= 0 && iLockBoxIdx != PTZ_MISS_OBJ_MAGIC_FLAG) + { + g_stPTZ_Handle.stPTZLockTrackingBox.left_x = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].left_x; + g_stPTZ_Handle.stPTZLockTrackingBox.top_y = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].top_y; + g_stPTZ_Handle.stPTZLockTrackingBox.width = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].width; + g_stPTZ_Handle.stPTZLockTrackingBox.height = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].height; + + if (g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name) + { + snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, + sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name); + } + + g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_tracking_id; + g_stPTZ_Handle.stPTZLockTrackingBox.class_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].class_id; + g_stPTZ_Handle.stPTZLockTrackingBox.obj_type = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_type; + +#if 0 + printf("lockbox id = %d \n", iLockBoxIdx); + printf("lock box %s, x, y, w, h = %d, %d, %d, %d \n", + g_stPTZ_Handle.stPTZLockTrackingBox.name, + g_stPTZ_Handle.stPTZLockTrackingBox.left_x, + g_stPTZ_Handle.stPTZLockTrackingBox.top_y, + g_stPTZ_Handle.stPTZLockTrackingBox.width, + g_stPTZ_Handle.stPTZLockTrackingBox.height); +#endif + } +#endif + + + +#endif + +#if 0 + if (g_stPTZ_Handle.iCandidateBoxCount == 1) + { + g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = 0; + } + else if (g_stPTZ_Handle.iCandidateBoxCount > 1)//Find biggest box + { + int iBiggestBoxIdx = FindBiggestBox(); + if (iBiggestBoxIdx != -1) + { + g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 1; + iLockBoxIdx = iBiggestBoxIdx; + } + } + + //Assign lock box data + if (iLockBoxIdx >= 0) + { + g_stPTZ_Handle.stPTZLockTrackingBox.left_x = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].left_x; + g_stPTZ_Handle.stPTZLockTrackingBox.top_y = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].top_y; + g_stPTZ_Handle.stPTZLockTrackingBox.width = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].width; + g_stPTZ_Handle.stPTZLockTrackingBox.height = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].height; + + g_stPTZ_Handle.stPTZLockTrackingBox.center_x = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].center_x; + g_stPTZ_Handle.stPTZLockTrackingBox.center_y = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].center_y; + + if (g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name) + { + snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, + sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name); + } + + g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_tracking_id; + g_stPTZ_Handle.stPTZLockTrackingBox.class_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].class_id; + g_stPTZ_Handle.stPTZLockTrackingBox.obj_type = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_type; + } + else + { + g_stPTZ_Handle.stPTZLockTrackingBox.left_x = 99999; + g_stPTZ_Handle.stPTZLockTrackingBox.top_y = 99999; + g_stPTZ_Handle.stPTZLockTrackingBox.width = -1; + g_stPTZ_Handle.stPTZLockTrackingBox.height = -1; + g_stPTZ_Handle.stPTZLockTrackingBox.center_x = 0; + g_stPTZ_Handle.stPTZLockTrackingBox.center_y = 0; + + g_stPTZ_Handle.iLoseLockObjCount = 0; //Reset lock obj lose count + } +#endif + +#if 0 + //沒有物件時等待時間 iTracking_resume_dwell + if (g_stPTZ_Handle.iCandidateBoxCount <= 0) + { + int dwNotUpdateLockBoxSecs = difftime(tCurrentTime, g_stPTZ_Handle.tUpdateLockBoxTime); + //printf("currTime: %d, lastUpdateTime: %d \n", tCurrentTime, g_stPTZ_Handle.tUpdateLockBoxTime); + //printf("Not alive time: %d sec \n", dwNotUpdateLockBoxSecs); + //Wait time out. + if (dwNotUpdateLockBoxSecs > g_stPTZ_Handle.iTracking_resume_dwell) + { + + g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + tCurrentTime = time(0); + g_stPTZ_Handle.iIsGetLockTrackingBox = 0; + + snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, + sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", "\0"); + + g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = -1; + + if (IsPTZatHomePos() == 0 + || IsPTZinPreset() != GetHomePreset() + ) + { + int iHomePos = GetHomePreset(); + GoPreset(iHomePos); + //usSleep(3000000); + } + + //Go home position at out side level. + } + } +#endif + + //printf("[%d]Lock box name: %s, tracking_id: %d \n", iLockBoxIdx, g_stPTZ_Handle.stPTZLockTrackingBox.name, g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id); + + + + return iLockBoxIdx; +} + +float FindPointDistance(int x1, int y1, int x2, int y2) +{ + float fDist = 0; + + fDist = sqrt(pow( (x1 - x2) , 2) + pow( (y1 - y2), 2)); + + return fDist; +} + +#if 1 +int IsShipObj() +{ + if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) + { + return 1; + } + else + return 0; +} + +void GetCandidateBoxTable(detection_pos *posInfo, int iTotalElementSize) +{ + detection_pos* pNext1; + int iCandidateBoxTableIdx = 0; + + int iFilter_confidence = 0; + if (g_stPTZ_Handle.iTraffic_cnfidence != 0) + iFilter_confidence = g_stPTZ_Handle.iTraffic_cnfidence; + + pthread_mutex_lock(&mutex_update_candidate); + + g_stPTZ_Handle.iCandidateBoxCount = 0; + + //if (g_stPTZ_Handle.iPauseTrackFlag == 0) + if (1) + { + // 是否有設定zone to preset - Yes + if (g_stPTZ_Handle.iZoneToPresetAnyOne == 1) + { + //是否在Preset點 + //是否該Preset點有設定 Map to zone //先不做, 未來看看 + + //在home preset點時, 就看zone to preset所對應的zone的metadata + if ((g_stPTZ_Handle.iIsInPreset != 0) + && (g_stPTZ_Handle.iTracking_entering_zone == 1) + && g_stPTZ_Handle.iIsInPreset == g_stPTZ_Handle.iHomePreset) + { + //根據preset點, 找到對應的zone info, //通常都是zone[0] + //此時, preset點應該為home點. + //iZoneToPreset = g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset + int iMapZoneIdx = 0; + int ifAddTable = 0; + + //等待追蹤, 收集在zone內 + for (int i = 0; i < iTotalElementSize; i++) + { + iMapZoneIdx = 0; + ifAddTable = 0; + + pNext1 = posInfo + i; + if ((int)pNext1->confidence >= iFilter_confidence) + { + for (int k = 0; k < viewChannelData[0].count_zone; k++) + { + if (ifAddTable == 1) + break; + + if (g_stPTZ_Handle.iIsInPreset == g_stPTZ_Zone_info[k].iZoneToPreset) + { + iMapZoneIdx = k; + } + else + continue; + + //if (pNext1->IsInsideZone[0] == 1) + if (pNext1->IsInsideZone[iMapZoneIdx] != 0) + { + //for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) + for (int j = 0; j < g_stPTZ_Zone_info[iMapZoneIdx].iMetadata1_num; j++) + { + //if (strcmp(pNext1->name, g_stPTZ_Handle.sMetaOut1[j]) == 0) + if (strcmp(pNext1->name, g_stPTZ_Zone_info[iMapZoneIdx].sMetaOut1[j]) == 0 && iCandidateBoxTableIdx < MAX_DETECT_OBJECTS) + { + ifAddTable = 1; + + //printf("Step 666 [%d]_ \n", i); + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x = (int)pNext1->left_x; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y = (int)pNext1->top_y; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].width = (int)pNext1->width; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].height = (int)pNext1->height; + + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_x = pNext1->left_x + (pNext1->width / 2); + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_y = pNext1->top_y + (pNext1->height / 2); + + //printf("can[%d] x/y = %d, %d \n", iCandidateBoxTableIdx, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y); + + if (strlen(pNext1->name)>=1) + { + snprintf(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name, + sizeof(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name), "%s", pNext1->name); + } + + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_tracking_id = pNext1->obj_tracking_id; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].class_id = pNext1->class_id; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_type = pNext1->obj_type; + + iCandidateBoxTableIdx++; + //printf("Step 555 [%d]_ count: %d\n", i, iCandidateBoxTableIdx); + break; // box只計算一次, 當出現在多個zone內. + } //add to stPTZCandidateBoxTable + } //cmp each metadata + } //is inside zone + }// scan each zone + } + } + } + else + { + //該preset點 沒有Map到任何zone + //或 該preset點 不是home點 + //追蹤中, 收集全畫面的 + for (int i = 0; i < iTotalElementSize; i++) + { + pNext1 = posInfo + i; + + if ((int)pNext1->confidence >= iFilter_confidence) + { + for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) + { + if (strcmp(pNext1->name, g_stPTZ_Handle.sMetaOut1[j]) == 0 && iCandidateBoxTableIdx < MAX_DETECT_OBJECTS) + { + //printf("Step 666 [%d]_ \n", i); + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x = (int)pNext1->left_x; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y = (int)pNext1->top_y; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].width = (int)pNext1->width; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].height = pNext1->height; + + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_x = pNext1->left_x + (pNext1->width / 2); + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_y = pNext1->top_y + (pNext1->height / 2); + + //printf("can[%d] x/y = %d, %d \n", iCandidateBoxTableIdx, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y); + + if (strlen(pNext1->name)>=1) + { + snprintf(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name, + sizeof(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name), "%s", pNext1->name); + } + + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_tracking_id = pNext1->obj_tracking_id; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].class_id = pNext1->class_id; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_type = pNext1->obj_type; + + iCandidateBoxTableIdx++; + + break; + } + } + } + } + } + } + else // Check if set zone to preset - No + { + //沒設定任何Map to zone + //參考全畫面object + //依據第一個zone設定的metadata為主 + + int iIfInAnyZone = 0; + + //等待追蹤, 收集在任何zone內 + for (int i = 0; i < iTotalElementSize; i++) + { + pNext1 = posInfo + i; + if ((int)pNext1->confidence >= iFilter_confidence) + { + /*iIfInAnyZone = 0; + for (int k = 0; k < MAX_DETECTION_ZONE; k++) + { + if (pNext1->IsInsideZone[k] != 0) + { + iIfInAnyZone = 1; + break; + } + }*/ + + //參考全畫面object + iIfInAnyZone = 1; + + //if (pNext1->IsInsideZone[0] == 1) + //if (pNext1->IsInsideZone[0] != 0) + if (iIfInAnyZone == 1) + { + for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) + { + if (strcmp(pNext1->name, g_stPTZ_Handle.sMetaOut1[j]) == 0 && iCandidateBoxTableIdx < MAX_DETECT_OBJECTS) + { + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x = (int)pNext1->left_x; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y = (int)pNext1->top_y; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].width = (int)pNext1->width; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].height = (int)pNext1->height; + + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_x = pNext1->left_x + (pNext1->width / 2); + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_y = pNext1->top_y + (pNext1->height / 2); + + //printf("can[%d] x/y = %d, %d \n", iCandidateBoxTableIdx, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y); + + if (strlen(pNext1->name)>=1) + { + snprintf(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name, + sizeof(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name), "%s", pNext1->name); + } + + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_tracking_id = pNext1->obj_tracking_id; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].class_id = pNext1->class_id; + g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_type = pNext1->obj_type; + + iCandidateBoxTableIdx++; + //printf("Step 555 [%d]_ count: %d\n", i, iCandidateBoxTableIdx); + break; // box只計算一次, 當出現在多個zone內. + } + } + } + } + } + }// Check if set zone to preset + } // Track Pause = 0 + + + g_stPTZ_Handle.iCandidateBoxCount = iCandidateBoxTableIdx; + + //printf("iCandidateBoxCount = %d / %d \n", iCandidateBoxTableIdx, iTotalElementSize); + + //g_stPTZ_Handle.tUpdateCandidateTableTime = time(0); + + pthread_mutex_unlock(&mutex_update_candidate); +} +#endif + + +void PTZUpdateTrackingInfo(detection_pos *posInfo, int iTotalElementSize, int iResW, int iResH) +{ + //g_stPTZ_Handle.iUpdateOutsideBox = 0; + + //判斷有無lock obj的時間不可在這個function做 + //這個function只有當有辨識到obj時, 才會進來 + +#if 0 + if (g_stPTZ_Handle.iEnable_tracking != 1 + || !IsPTZinAutoTracking() + ) + { + return; + } +#endif + + //This hardcold for TEST + //g_stPTZ_Handle.iTracking_mode = 3; + + //Check tracking MODE + //int iTrackingMODE = g_stPTZ_Handle.iTracking_mode; + + //int iLockBoxIdxRet = -1; + + //Tracking MODE + //1: First in First out + //2: Bigger first + //3: All + + //if (iTrackingMODE == 1 || iTrackingMODE == 2) + //{ + if (IsTracking() == 1) + { + GetCandidateBoxTable(posInfo, iTotalElementSize); + } + + //iLockBoxIdxRet = GetSingleLockTrackingBox(iResW, iResH); + + //int ret = GetOutsideLockBox(iResW, iResH); + //g_stPTZ_Handle.iUpdateOutsideBox = 1; + //} + //else if (iTrackingMODE == 3) + //{ + //Get Outside Box + // int ret = GetOutsideBox(posInfo, iTotalElementSize, iResW, iResH); + //g_stPTZ_Handle.iUpdateOutsideBox = 1; + //} +} + +int IsPTZEnableAlarm(int iInZoneToPreset) +{ + int ret = 0; + + if (IsPTZ() == 1) + { + if (IsPTZinPreset() != 0) + { + //printf("***** IsPTZinPreset() = %d \n", IsPTZinPreset()); + if (IsPTZinPreset() == iInZoneToPreset) + ret = 1; + else + ret = 0; //not trigger + } + else + { + ret = 0; //not trigger + } + } + else + { + ret = 1; + } + + return ret; +} + +//void PerformDetection() +//{ +// g_stPTZ_Handle.iIs_enable_alarm = 1; +//} + + +/* +void *ptz_do_zoom_thread(char *url) +{ + pthread_detach(pthread_self()); + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + char outputData[1024] = { 0 }; + + + //sprintf(ptz_curl_url, "/control?airzoom=%d", 7); + + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", 7); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + usSleep(1000000); + sprintf(ptz_curl_url, "http://127.0.0.1/control?stop=1"); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + + //exit thread + pthread_exit(NULL); +} +*/ + +void *ptz_do_zoom_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("ptz_zoom"); + char outputData[1024] = { 0 }; + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + int iZoom_number = 0; + int iZoom_value = 0; + g_stPTZ_Handle.iZoomRunning = 0; + g_stPTZ_Handle.iZoomFreqMod = 4; + + int iObjMoveDirection_y = 0; + int iObjMoveDirection_x = 0; + + int iPtzTiltZoomOut = 0; + + while (g_stPTZ_Handle.iRunPTZTrackingThread_flag == 1) + { + if (g_stPTZ_Handle.iIsGoingHome == 1) + { + usSleep(1000000); + continue; + } + + iPtzTiltZoomOut = 0; + +#if 1 + ///Check Tilt + if (g_stPTZ_Handle.iTiltABS <= 135 + && g_stPTZ_Handle.iTiltABS >= 45 + && (strcmp(g_stPTZ_Handle.stPTZLockTrackingBox.name, "person") == 0)) + { + iPtzTiltZoomOut = 1; + } + //else if (g_stPTZ_Handle.iTiltABS <= 160 + // && g_stPTZ_Handle.iTiltABS >= 20) + //{ + // + //} +#endif + + //if (g_stPTZ_Handle.) + // g_stPTZ_Handle.iZoomRunning = 0; + //if (g_stPTZ_Handle.iPauseTrackFlag) + // g_stPTZ_Handle.iZoomRunning = 0; + + //printf("Zoom chlockid = %d \n", g_stPTZ_Handle.iLockBoxIdx); + if (iPtzTiltZoomOut == 1) + { + if (g_stPTZ_Handle.iZoomRunning == 0) + { + if (g_stPTZ_Handle.iZoomFreqCount >= 0 + && g_stPTZ_Handle.iZoomFreqCount % 4 == 0) + { + iZoom_value = 7; + + //Zoom out + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"ptz do zoom thread 1"); + + g_stPTZ_Handle.iZoomFreqCount = 1; + } + else + { + g_stPTZ_Handle.iZoomFreqCount++; + } + } + } + else if (g_stPTZ_Handle.iLockBoxIdx != -1 + && g_stPTZ_Handle.iLockBoxIdx != PTZ_MISS_OBJ_MAGIC_FLAG + && g_stPTZ_Handle.iTracking_fov_max > 0 + && g_stPTZ_Handle.iIsGetLockTrackingBox > 0 + && g_stPTZ_Handle.iCandidateBoxCount > 0 + && iPtzTiltZoomOut == 0) + { + iZoom_number = IfDoZoom(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h, g_stPTZ_Handle.iTracking_fov_max); + + if (g_stPTZ_Handle.iRecordOldOutsideBoxCount > 2) + { + iObjMoveDirection_y = g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 1].center_y - g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 2].center_y; + iObjMoveDirection_x = g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 1].center_x - g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 2].center_x; + } + + if (iObjMoveDirection_y > (g_stPTZ_Handle.iIMG_source_h / 20) + || iObjMoveDirection_x > (g_stPTZ_Handle.iIMG_source_w / 20)) + { + if (g_stPTZ_Handle.iZoomRunning == 0) + { + iZoom_value = 7; + + if (g_stPTZ_Handle.iZoomFreqCount >= 0 + && g_stPTZ_Handle.iZoomFreqCount % g_stPTZ_Handle.iZoomFreqMod == 0) + { + g_stPTZ_Handle.iZoomFreqCount = 1; + + //Zoom out + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do zoom thread 2"); + + //usSleep(500000); + + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + // usSleep(300000); + + // sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + // send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + } + else + { + g_stPTZ_Handle.iZoomFreqCount++; + } + + //g_stPTZ_Handle.iZoomRunning = 1; + } + } + else if (g_stPTZ_Handle.iZoomRunning == 0 && iZoom_number != 0) + { + if (iZoom_number < (g_stPTZ_Handle.iTracking_fov_max - 5)) + { + iZoom_value = -3; + + if (g_stPTZ_Handle.iZoomFreqCount >= 0 + && g_stPTZ_Handle.iZoomFreqCount % g_stPTZ_Handle.iZoomFreqMod == 0) + { + g_stPTZ_Handle.iZoomFreqCount = 1; + //Zoom in + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do zoom thread 3"); + + //usSleep(500000); + + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + // usSleep(300000); + + // sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + // send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + } + else + { + g_stPTZ_Handle.iZoomFreqCount++; + } + + //g_stPTZ_Handle.iZoomRunning = 1; + } + else if (iZoom_number > (g_stPTZ_Handle.iTracking_fov_max + 5)) + { + iZoom_value = 3; + + if (g_stPTZ_Handle.iZoomFreqCount >= 0 + && g_stPTZ_Handle.iZoomFreqCount % g_stPTZ_Handle.iZoomFreqMod == 0) + { + g_stPTZ_Handle.iZoomFreqCount = 1; + //Zoom out + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do zoom thread 4"); + + //usSleep(500000); + + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + // usSleep(300000); + + // sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + // send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + } + else + { + g_stPTZ_Handle.iZoomFreqCount++; + } + //g_stPTZ_Handle.iZoomRunning = 1; + } + } + else if (g_stPTZ_Handle.iZoomRunning == 1) + { + if ((iZoom_number >= 58 && iZoom_number <= 62) + || iZoom_number == 0) + { + //Stop + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + //usSleep(300000); + + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + g_stPTZ_Handle.iZoomRunning = 0; + } + } + } + else if ((g_stPTZ_Handle.iLockBoxIdx == -1) + //|| (g_stPTZ_Handle.iPauseTrackFlag == 1) + ) + { + //Stop + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + g_stPTZ_Handle.iZoomRunning = 0; + } + + usSleep(300000); + //printf("[%d] Zoom num = %d \n", g_stPTZ_Handle.iZoomRunning, iZoom_number); + } + + pthread_exit(NULL); +} + +int AdaptedGoCenterSpeed(int iSpeedBase, int obj_class_id) +{ + int iAdaptedSpeed = iSpeedBase; + + if (g_stPTZ_Handle.iZoomABS <= 10) + { + g_stPTZ_Handle.iZoomFreqMod = 4; + //FOV大, 速度要快 + //FOV小, 不可太快 + if (g_stPTZ_Handle.iLockObjFOV <= 20) + { + } + else if (g_stPTZ_Handle.iLockObjFOV > 20 && g_stPTZ_Handle.iLockObjFOV <= 40) + { + iAdaptedSpeed += 3; + } + else if (g_stPTZ_Handle.iLockObjFOV > 40) + { + iAdaptedSpeed += 4; + } + } + else if (g_stPTZ_Handle.iZoomABS > 10 && g_stPTZ_Handle.iZoomABS <= 15) + { + g_stPTZ_Handle.iZoomFreqMod = 6; + + //根據中心點距離與FOV, 適度加快 + if (g_stPTZ_Handle.iLockObjFOV <= 15) + { + } + else if (g_stPTZ_Handle.iLockObjFOV > 15 && g_stPTZ_Handle.iLockObjFOV <= 30) + { + iAdaptedSpeed += 2; + } + else if (g_stPTZ_Handle.iLockObjFOV > 30) + { + iAdaptedSpeed += 1; + } + } + else if (g_stPTZ_Handle.iZoomABS > 15) + { + g_stPTZ_Handle.iZoomFreqMod = 8; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + + //g_stPTZ_Handle.iLockBoxArea_min = 35; + //g_stPTZ_Handle.iLockBoxArea_max = 65; + + //不考慮FOV, + //速度需放慢, + if (g_stPTZ_Handle.iLockObjFOV <= 10) //OBJ過小, 暫時不改變速度 + { + iAdaptedSpeed = 3; + } + else if (g_stPTZ_Handle.iLockObjFOV > 15 && g_stPTZ_Handle.iLockObjFOV <= 50) + { + iAdaptedSpeed = 3; + } + else if (g_stPTZ_Handle.iLockObjFOV > 50) + { + iAdaptedSpeed = 3; + } + } + + + if (g_stPTZ_Handle.iTiltABS >= 30 && g_stPTZ_Handle.iTiltABS <= 120) + { + iAdaptedSpeed += 3; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + } + else if (g_stPTZ_Handle.iTiltABS >= 45 && g_stPTZ_Handle.iTiltABS <= 135) + { + iAdaptedSpeed += 10; + g_stPTZ_Handle.iGoCenterFreqFrame = 1; + } + + if (iAdaptedSpeed <= 0) + iAdaptedSpeed = 1; + + //printf("classid = %d \n", obj_class_id); + + if (obj_class_id == 0) + { + + iAdaptedSpeed = 25; + } + + //printf("iAdaptedSpeed = %d \n", iAdaptedSpeed); + + return iAdaptedSpeed; +} + +void *ptz_do_tracking_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("ptz_track"); + char outputData[1024] = { 0 }; + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[1024] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + g_stPTZ_Handle.iIsGetLockTrackingBox = 0; + g_stPTZ_Handle.iCandidateBoxCount = 0; + + g_stPTZ_Handle.stPTZOutsideBox.center_x = 0; + g_stPTZ_Handle.stPTZOutsideBox.center_y = 0; + g_stPTZ_Handle.stPTZOutsideBox.width = -1; + g_stPTZ_Handle.stPTZOutsideBox.height = -1; + //g_stPTZ_Handle.dwMoveAngel = 0; + + //g_stPTZ_Handle.iTimer_send_count = 0; + //g_stPTZ_Handle.iIs_enable_alarm = 0; + + g_stPTZ_Handle.iRecordOldOutsideBoxCount = 0; + + + //int iDisPercent_W = 50, iDisPercent_H = 50; + int iPercentage_W = 50, iPercentage_H = 50; + //int iZoomActiveFlag = 0; + //int iGoCenterFlag = 0; + //int iZoomCheckTimerCount = 0; + //int iZoomStopPerMSEC = 100; + //int iZoomStopTimerCount = 0; + //int iZoomStopTimerDefineSet = 20; //2 sec + int iGoCenterSpeed = 2; + + time_t tCurrentTrackingTime = time(0); + time_t tCheckResumeTime = time(0); + time_t tLoseTrackingTime = time(0); + time_t tOldTrackingTime = time(0); + //time_t tCurrentZoomTime = time(0); + //int tDiffTrackingSecond = 0; + g_stPTZ_Handle.tDiffTrackingSecond = 0; + //int tDiffZoomSecond = 0; + //double dwNotUpdateLockBoxSecs = 0.0; + + //g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + g_stPTZ_Handle.iPauseTrackFlag = 0; + + //g_stPTZ_Handle.iLockBoxArea_min = PTZ_CENTER_AREA_X2_MIN; + //g_stPTZ_Handle.iLockBoxArea_max = PTZ_CENTER_AREA_X2_MAX; + + //double dwDiffUpdateCandiDateTableSecs = 0.0; + //g_stPTZ_Handle.tUpdateCandidateTableTime = time(0); //Init + + //g_stPTZ_Handle.tOperatTime = time(0); + //g_stPTZ_Handle.tChangAutoPanTime = time(0); + //g_stPTZ_Handle.tOperatZoomTime = time(0); + + int iHomePos = 0; + int iRunningFlag = 0; + + //int iMoveFlag = 0; + //int iMoveCounter = 0; + + int iLockBoxIdxRet = -1; + + int iIfGoCenter_ret = 0; + + //init store of ptz home preset pos + g_stPTZ_Handle.iHomePanABS = -1; + g_stPTZ_Handle.iHomeTiltABS = -1; + g_stPTZ_Handle.iHomeZoomABS = -1; + + + if (IsPTZatHomePos() == 0 + && g_stPTZ_Handle.iZoneToPresetAnyOne == 1 + && IsPTZinAutoTracking() + && g_stPTZ_Handle.iRunPTZTrackingThread_flag == 1 + ) + { + g_stPTZ_Handle.iIsGoingHome = 1; + iHomePos = GetHomePreset(); + GoPreset(iHomePos); + //usSleep(GO_HOME_SLEEP*1000); + } + + usSleep(GO_HOME_SLEEP*1000); + + //Store Home preset x, y, zoom pos + StoreHomePresetPos(); + //UpdatePTZCurPos(); + + usSleep(GO_HOME_SLEEP*1000); + + g_stPTZ_Handle.iIsGoingHome = 0; + + //PTZ zoom + if (pthread_create(&ptz_zoom_thread, 0, ptz_do_zoom_thread, NULL)) + printf("\nPTZ zoom thread creation failed\n"); + + int iOldPresetPoint = 0; + int iCurrentPresetPoint = 0; + + while (g_stPTZ_Handle.iRunPTZTrackingThread_flag == 1) + { + if (g_stPTZ_Handle.iIsGoingHome == 1) + { + usSleep(1000000); + continue; + } + + //Test cgi freq +#if 0 + if (1) + { + iMoveCounter++; + + if (iMoveCounter >= 20) + { + if (iMoveFlag == 0) + { + iMoveFlag = 1; + //printf("1111111111 \n"); + sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", 55, 55, 2); + //sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + //g_stPTZ_Handle.tOperatTime = time(0); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + } + else if (iMoveFlag == 1) + { + iMoveFlag = 0; + //printf("2222222222222 \n"); + sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", 55, 45, 2); + //sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + //g_stPTZ_Handle.tOperatTime = time(0); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + } + + iMoveCounter = 0; + } + + usSleep(10000); + } +#endif + + //檢查AutoPan & AutoTracking flag + if (!IsPTZinAutoTracking()) + { + usSleep(1000000); + continue; + } + + iLockBoxIdxRet = GetSingleLockTrackingBox(999, 999); //1: found lock, -1: not lock + + + { + //char msg_temp[512] = { 0 }; + //sprintf(msg_temp, "iLockBoxIdxRet:%d", iLockBoxIdxRet); + //write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); + } + //g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; + + iPercentage_W = 49; + iPercentage_H = 49; + + if (iLockBoxIdxRet < 0) + { + //write_to_logs_html("3-1", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); + g_stPTZ_Handle.iLockObjFOV = 0; + + g_stPTZ_Handle.iLoseLockObjCount++; + if (g_stPTZ_Handle.iLoseLockObjCount > PTZ_LOSE_OBJ_LIMIT) + { + //write_to_logs_html("3-1-1", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); + g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; + } + else + { + //write_to_logs_html("3-1-2", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); + tOldTrackingTime = time(0); + tCurrentTrackingTime = time(0); + //g_stPTZ_Handle.iLockBoxIdx = -1; + continue; + } +#if 0 + //檢查Candidate Table 更新時間 + //比較tCurrentTrackingTime 與 g_stPTZ_Handle.tUpdateCandidateTableTime + tCurrentTrackingTime = time(0); + + int dwNotUpdateLockBoxSecs = difftime(tCurrentTrackingTime, g_stPTZ_Handle.tUpdateLockBoxTime); + + if (dwNotUpdateLockBoxSecs > g_stPTZ_Handle.iTracking_resume_dwell) + { + g_stPTZ_Handle.iIsGetLockTrackingBox = 0; + + snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, + sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", "\0"); + + g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = -1; + + if (IsPTZatHomePos() == 0 + || IsPTZinPreset() != GetHomePreset() + ) + { + int iHomePos = GetHomePreset(); + GoPreset(iHomePos); + usSleep(3000000); + } + + g_stPTZ_Handle.tUpdateLockBoxTime = time(0); + } + + usSleep(300000); + continue; +#endif + } + else if (iLockBoxIdxRet == PTZ_MISS_OBJ_MAGIC_FLAG) + { + //write_to_logs_html("3-2", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); + g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; + //針對Miss lock box容許狀況 + g_stPTZ_Handle.iLoseLockObjCount++; //if iLoseLockObjCount < 10 + + //tOldTrackingTime = time(0); + tCurrentTrackingTime = time(0); + + //g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + //if (g_stPTZ_Handle.iGoCenterFreqCount >= g_stPTZ_Handle.iGoCenterFreqFrame) + //{ + // g_stPTZ_Handle.iGoCenterFreqCount = 0; + + // //Center + // sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", 50, 50, 1); + // //sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + // //g_stPTZ_Handle.tOperatTime = time(0); + // send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + //} + //else + //{ + // g_stPTZ_Handle.iGoCenterFreqCount++; + //} + + } + else if (iLockBoxIdxRet > -1) + { + //write_to_logs_html("3-3", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); + g_stPTZ_Handle.iLoseLockObjCount = 0; + g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; + + /*int ret = */GetOutsideLockBox(999, 999); + + GetLockObjFOV(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h); + + //ret = OutsideBoxChange(); + + //IF BACK TO HOMEPOS, sleep 2 sec. + + /*if (g_stPTZ_Handle.iIsStayHomePos == 0 + && IsPTZatHomePos() == 1) + { + g_stPTZ_Handle.iIsStayHomePos = IsPTZatHomePos(); + usSleep(1000000); + }*/ + + + + + //Check: If go home pos. after 6 second + //tCurrentTrackingTime = time(0); + //tDiffTrackingSecond = 0.0; + //tDiffTrackingSecond = difftime(tCurrentTrackingTime, g_stPTZ_Handle.tOperatTime); + + //printf("tDiffTrackingSecond = %f \n", tDiffTrackingSecond); + + //if (tDiffTrackingSecond >= 5) + //{ + // //Go Home and wait ipcam recovery function turn on "autopen" & "autotracking" + // GoPreset(iHomePos); + // g_stPTZ_Handle.tOperatTime = time(0); + //} + + + iIfGoCenter_ret = IfGoCenter(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h); + //printf("ck ret = %d \n", iIfGoCenter_ret); + + + + //printf("%d / %d \n", g_stPTZ_Handle.iTimer_send_count, g_stPTZ_Handle.iPTZ_sensitivity); + + //int iZoom_number = IfDoZoom(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h, g_stPTZ_Handle.g_ptz_zoom_iou); + + //int iZoom_number = IfDoZoom(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h, g_stPTZ_Handle.iTracking_fov_max); + //int iZoom_number = 0; + + //g_stPTZ_Handle.iPTZ_sensitivity = 0; + +#if 0 + //if (g_stPTZ_Handle.iTimer_send_count < g_stPTZ_Handle.iPTZ_sensitivity) + if (1) + { + g_stPTZ_Handle.iTimer_send_count++; + } + else +#endif + if (1) + { + //g_stPTZ_Handle.iTimer_send_count = 0; + + if (iRunningFlag > 99999) + iRunningFlag = 0; + else + iRunningFlag++; + g_stPTZ_Handle.iThreadRunningFlag = iRunningFlag; + + //if (g_stPTZ_Handle.iTracking_mode == 3) + // g_stPTZ_Handle.iCandidateBoxCount = 1; + + if (iIfGoCenter_ret == 1 + /*&& g_stPTZ_Handle.iCandidateBoxCount != 0*/ + ) + { + /* + if (g_stPTZ_Handle.iMoveSpeed_x >= 4 + || g_stPTZ_Handle.iMoveSpeed_x <= -4 + || g_stPTZ_Handle.iMoveSpeed_y >= 4 + || g_stPTZ_Handle.iMoveSpeed_y <= -4)*/ + if (1) + { +#if 1 + iPercentage_W = ((g_stPTZ_Handle.stPTZOutsideBox.center_x * 1000 / (g_stPTZ_Handle.iIMG_source_w)) / 10); + + iPercentage_H = ((g_stPTZ_Handle.stPTZOutsideBox.center_y * 1000 / (g_stPTZ_Handle.iIMG_source_h)) / 10); + + ///Lock box distance + //int iDisPercent_W = 50, iDisPercent_H = 50; + + //iDisPercent_W = abs(g_stPTZ_Handle.stPTZOutsideBox.center_x - ((g_stPTZ_Handle.iIMG_source_w) / 2)); + //iDisPercent_H = abs(g_stPTZ_Handle.stPTZOutsideBox.center_y - ((g_stPTZ_Handle.iIMG_source_h) / 2)); + + //iDisPercent_W = ((iDisPercent_W * 1000 / ((g_stPTZ_Handle.iIMG_source_w) / 2)) / 10); + //iDisPercent_H = ((iDisPercent_H * 1000 / ((g_stPTZ_Handle.iIMG_source_h) / 2)) / 10); + + //printf("percent W, H = %d, %d \n", iDisPercent_W, iDisPercent_H); + + //dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + 1); + + + ///Lock box iou + /* + PTZ_VIRTUAL_BOX Lock_area_box; + + int iLockBox_left_x, iLockBox_right_x; + iLockBox_left_x = g_stPTZ_Handle.iIMG_source_w * PTZ_CENTER_AREA_X2_MIN / 100; + iLockBox_right_x = g_stPTZ_Handle.iIMG_source_w * PTZ_CENTER_AREA_X2_MAX / 100; + + Lock_area_box.left_x = iLockBox_left_x; + Lock_area_box.right_x = iLockBox_right_x; + Lock_area_box.width = iLockBox_right_x - iLockBox_left_x; + + int iLockBox_top_y, iLockBox_bottom_y; + iLockBox_top_y = g_stPTZ_Handle.iIMG_source_h * PTZ_CENTER_AREA_X2_MIN / 100; + iLockBox_bottom_y = g_stPTZ_Handle.iIMG_source_h * PTZ_CENTER_AREA_X2_MAX / 100; + + Lock_area_box.top_y = iLockBox_top_y; + Lock_area_box.bottom_y = iLockBox_bottom_y; + Lock_area_box.height = iLockBox_bottom_y - iLockBox_top_y; + + printf("lockbox: [%d, %d], [%d, %d] \n", iLockBox_left_x, iLockBox_top_y, Lock_area_box.width, Lock_area_box.height); + //printf("outsidebox: [%d, %d], [%d, %d] \n", g_stPTZ_Handle.stPTZOutsideBox.left_x, g_stPTZ_Handle.stPTZOutsideBox.top_y, g_stPTZ_Handle.stPTZOutsideBox.right_x, g_stPTZ_Handle.stPTZOutsideBox.bottom_y); + + float fIOU_tmp; + fIOU_tmp = object_iou(&g_stPTZ_Handle.stPTZOutsideBox, &Lock_area_box); + */ + + + +#if 1 ///Define MOVE SPEED + switch (g_stPTZ_Handle.iPTZ_speed) + { + case 0: + iGoCenterSpeed = 3; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + case 1: + iGoCenterSpeed = 2; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + //12 frame + break; + case 2: + iGoCenterSpeed = 2; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + //10 frame + break; + case 3: + iGoCenterSpeed = 2; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + //8 frame + break; + case 4: + iGoCenterSpeed = 6; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + //6 frame + break; + case 5: + iGoCenterSpeed = 8; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + //4 frame + break; + case 6: + iGoCenterSpeed = 2; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + case 7: + iGoCenterSpeed = 3; + + //if (g_stPTZ_Handle.iLockObjFOV ) + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + break; + case 8: + iGoCenterSpeed = 4; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + case 9: + iGoCenterSpeed = 5; + g_stPTZ_Handle.iGoCenterFreqFrame = 3; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + case 10: + iGoCenterSpeed = 6; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + case 11: + iGoCenterSpeed = 7; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + case 12: + iGoCenterSpeed = 8; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + default: + iGoCenterSpeed = 3; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + + iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); + + break; + } + +#endif +#if 0 ///Define MOVE SPEED + if (g_stPTZ_Handle.iLockObjFOV != 0) + { + if (g_stPTZ_Handle.iLockObjFOV > 50) + { + iGoCenterSpeed = 2; + } + else if (g_stPTZ_Handle.iLockObjFOV < 25) + { + iGoCenterSpeed = 2; + } + else + { + iGoCenterSpeed = 2; + } + } + else + iGoCenterSpeed = 2; +#endif + +#if 0 + int iDoubleGoCenterFlag = 0; + + if (g_stPTZ_Handle.iZoomABS >= 1 && g_stPTZ_Handle.iZoomABS <= 4) + { + iGoCenterSpeed = 4; + } + else if (g_stPTZ_Handle.iZoomABS >= 5 && g_stPTZ_Handle.iZoomABS <= 7) + { + iGoCenterSpeed = 4; + } + else if (g_stPTZ_Handle.iZoomABS >= 8 && g_stPTZ_Handle.iZoomABS <= 10) + { + iGoCenterSpeed = 4; + } + else if (g_stPTZ_Handle.iZoomABS >= 11) + { + iGoCenterSpeed = 2; + } + else + iGoCenterSpeed = 5; +#endif + + + + //printf("CenX / CenY: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); + //printf("PerW / PerH: %d, %d \n", iPercentage_W, iPercentage_H); + +#if 0 + if (g_stPTZ_Handle.iTiltABS <= 140 + && g_stPTZ_Handle.iTiltABS >= 20) + { + iGoCenterSpeed = 255; + //iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 2); + if (iPercentage_W >= 50) + iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 3); + else if (iPercentage_W < 50) + iPercentage_W = iPercentage_W - ((iPercentage_W) / 3); + + iPercentage_H = iPercentage_H + ((100 - iPercentage_H) / 3); + } + else if (g_stPTZ_Handle.iTiltABS <= 160 + && g_stPTZ_Handle.iTiltABS >= 20) + { + iGoCenterSpeed = 125; + //iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 2); + if (iPercentage_W >= 50) + iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 3); + else if (iPercentage_W < 50) + iPercentage_W = iPercentage_W - ((iPercentage_W) / 3); + + iPercentage_H = iPercentage_H + ((100 - iPercentage_H) / 3); + } +#endif + + if (iPercentage_W == 50) + iPercentage_W = 49; + + if (iPercentage_H == 50) + iPercentage_H = 49; + + //if engine type = AISHIP + //g_stPTZ_Handle.iGoCenterFreqCount = g_stPTZ_Handle.iGoCenterFreqFrame + //iGoCenterSpeed = 1 + if (g_stPTZ_Handle.iPTZ_speed == 1) + { + iGoCenterSpeed = 1; + g_stPTZ_Handle.iGoCenterFreqFrame = 2; + } + + + if (g_stPTZ_Handle.iGoCenterFreqCount >= g_stPTZ_Handle.iGoCenterFreqFrame) + { + g_stPTZ_Handle.iGoCenterFreqCount = 1; + + //Center + sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + //sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + //g_stPTZ_Handle.tOperatTime = time(0); + send_request(ptz_ip ,ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"ptz do tracking thread 1"); + } + else + { + g_stPTZ_Handle.iGoCenterFreqCount++; + } + + + //printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx GO Center \n"); + +#if 0 + //會造成由右往左的交錯速度太快 + //if (iDoubleGoCenterFlag) + { + //iPercentage_H = (int)((iPercentage_H + 50) / 2); + //iPercentage_W = (int)((iPercentage_W + 50) / 2); + + if (iPercentage_H <= 10) + iPercentage_H = (int)(50 - ((50 - iPercentage_H) / 3)); + + if (iPercentage_H >= 90) + iPercentage_H = (int)(50 + ((iPercentage_H - 50) / 3)); + + if (iPercentage_W <= 10) + iPercentage_W = (int)(50 - ((50 - iPercentage_W) / 3)); + + if (iPercentage_W >= 90) + iPercentage_W = (int)(50 + ((iPercentage_W - 50) / 3)); + + + //iGoCenterSpeed = 3; + + sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + //sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); + usSleep(150000); + //g_stPTZ_Handle.tOperatTime = time(0); + send_request(ptz_ip ,ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do tracking thread 2"); + } +#endif +#endif + } + else + { +#if 0 + g_stPTZ_Handle.iMoveSpeed_y = (g_stPTZ_Handle.iMoveSpeed_y * 2) % 8; + g_stPTZ_Handle.iMoveSpeed_x = (g_stPTZ_Handle.iMoveSpeed_x * 2) % 8; + + sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rtilt=%d&rpan=%d", g_stPTZ_Handle.iMoveSpeed_y, g_stPTZ_Handle.iMoveSpeed_x); + //sprintf(ptz_curl_url, "/control?camid=1&rtilt=%d&rpan=%d", g_stPTZ_Handle.iMoveSpeed_y, g_stPTZ_Handle.iMoveSpeed_x); + + //Set operat time stamp + g_stPTZ_Handle.tOperatTime = time(0); + + send_request(ptz_ip ,ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + usSleep(200000); + sprintf(ptz_curl_url, "http://127.0.0.1/control?stop=1"); + //sprintf(ptz_curl_url, "/control?stop=1"); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); +#endif + } + //if (iZoom_number < 0 || iZoom_number > 0) + //{ + // usSleep(120000); + //} + } + + /* + if (g_stPTZ_Handle.iMoveSpeed_x != 0 + && g_stPTZ_Handle.iMoveSpeed_y != 0 + && (g_stPTZ_Handle.iMoveSpeed_y <= 2 || g_stPTZ_Handle.iMoveSpeed_y >= -2) + && (g_stPTZ_Handle.iMoveSpeed_x <= 2 || g_stPTZ_Handle.iMoveSpeed_x >= -2) + && (iZoom_number < 0 || iZoom_number > 0)) + */ + //if (iGoCenterSpeed == 2 + // && (iZoom_number < 0 || iZoom_number > 0)) + + //if (g_stPTZ_Handle.iTracking_mode == 3) + // g_stPTZ_Handle.iCandidateBoxCount = 1; +#if 0 + if ((iPercentage_H >= 20 && iPercentage_H <= 80) + && (iPercentage_W >= 20 && iPercentage_W <= 80) + /*&& (g_stPTZ_Handle.iCandidateBoxCount != 0)*/ + ) + { + + if (iZoom_number < 0 || iZoom_number > 0) + { + //tCurrentZoomTime = time(0); + //tDiffZoomSecond = difftime(tCurrentZoomTime, g_stPTZ_Handle.tOperatZoomTime); + + //if (tDiffZoomSecond >= 2) + //{ + //printf("=======================================> do zoom %d \n", iZoom_number); + +#if 0 + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_number); + //sprintf(ptz_curl_url, "/control?airzoom=%d", iZoom_number); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + //g_stPTZ_Handle.tOperatTime = time(0); + //g_stPTZ_Handle.tOperatZoomTime = time(0); + + usSleep(200000); + + //printf("=======================================> do stop\n"); + sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); +#endif + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //sprintf(ptz_curl_url, "/control?stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + //} + } + + } + else if(g_stPTZ_Handle.iZoomABS > 6) + { +#if 0 + g_stPTZ_Handle.tOperatTime = time(0); + g_stPTZ_Handle.tOperatZoomTime = time(0); + + sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", 7); + //sprintf(ptz_curl_url, "/control?airzoom=%d", iZoom_number); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + usSleep(200000); + + sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); + + //usSleep(100000); + + //sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); + //send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); +#endif + } +#endif + } + + }// if(iFindLockObj) + else + { + g_stPTZ_Handle.iLockBoxIdx = -1; + g_stPTZ_Handle.iLockObjFOV = 0; + iLockBoxIdxRet = -1; + }// if(iFindLockObj) + +#if 1 + g_stPTZ_Handle.iCandidateBoxCount = 0; + //printf("%d, %d, %d\n", iPercentage_H, iPercentage_W, g_stPTZ_Handle.iCandidateBoxCount); + //Check if object (car, traffic, etc....) stay long time (300 sec). + //The range of box center point change keep in 5%, at center of window. + if ((iPercentage_H > 45 + && iPercentage_H < 65 + && iPercentage_W > 45 + && iPercentage_W < 65 + && iLockBoxIdxRet > -1 + ) + ) + { + //物體幾乎是原地狀態 + //進入"看太久計時"階段 + + tCurrentTrackingTime = time(0); + //printf("iCandidateBoxCount > 0, T_cur = %ld \n", tCurrentTrackingTime); + + } + else + { + //追蹤有大幅移動, 更新計時器tOldTrackingTime + + tOldTrackingTime = time(0); + tCurrentTrackingTime = time(0); + //printf("iCandidateBoxCount = 0, T_cur = %ld, T_old = %ld \n", tCurrentTrackingTime, tOldTrackingTime); + } + + iCurrentPresetPoint = IsPTZinPreset(); + + //if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0) + if (iLockBoxIdxRet == -1 + && g_stPTZ_Handle.iZoneToPresetAnyOne == 1 + && (IsPTZinPreset() != GetHomePreset()) + && iOldPresetPoint == iCurrentPresetPoint) + { + //遺失追蹤物件, 進入遺失計時階段 + tLoseTrackingTime = time(0); + } + else + { + //有追蹤物建, 更新遺失計時器tCheckResumeTime + + iOldPresetPoint = iCurrentPresetPoint; + tLoseTrackingTime = time(0); + tCheckResumeTime = time(0); + } + + //printf("iIsGetLockTrackingBox = %d \n", g_stPTZ_Handle.iIsGetLockTrackingBox); + + g_stPTZ_Handle.tDiffTrackingSecond = 0; + //tDiffTrackingSecond = difftime(tCurrentTrackingTime, tOldTrackingTime); + + + //printf("diff track sec = %f \n", tDiffTrackingSecond); + //g_stPTZ_Handle.ResumTime = tDiffTrackingSecond; + + //printf("iPauseTrackFlag = %d \n", g_stPTZ_Handle.iPauseTrackFlag); + + if (g_stPTZ_Handle.iLockBoxIdx != -1 + //&& g_stPTZ_Handle.iPauseTrackFlag == 0 + ) + { + g_stPTZ_Handle.tDiffTrackingSecond = tCurrentTrackingTime - tOldTrackingTime; + } + //else if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0 + else if (iLockBoxIdxRet == -1 + && g_stPTZ_Handle.iZoneToPresetAnyOne == 1 + && (IsPTZinPreset() != GetHomePreset())) + { + //遺失追蹤物 + //有任何zone設定了link preset點 + //目前不在home點上 + + //從遺失那刻起開始計算時間 + g_stPTZ_Handle.tDiffTrackingSecond = tLoseTrackingTime - tCheckResumeTime; + } + + //printf("tDiffTrackingSecond = %d \n", tDiffTrackingSecond); + + int iTryGoHomeCount = 0; + + int iPTZRecoveryTimeSec = 300; + + + iPTZRecoveryTimeSec = g_stPTZ_Handle.iRT_sec + (g_stPTZ_Handle.iRT_min * 60); + + if (iPTZRecoveryTimeSec <= 0) + iPTZRecoveryTimeSec = 300;//300 + + /* + if (viewChannelData[0].ptz_tracking_resume_dwell + && strlen(viewChannelData[0].ptz_tracking_resume_dwell) > 0) + { + g_stPTZ_Handle.iTracking_resume_dwell = atoi(viewChannelData[0].ptz_tracking_resume_dwell); + }*/ + + + { + //char msg_temp[512] = { 0 }; + //sprintf(msg_temp, "tDiffTrackingSecond:%d,iTracking_resume_dwell:%d,iLockBoxIdx:%d,iZoneToPresetAnyOne:%d,iPTZRecoveryTimeSec:%d", + //g_stPTZ_Handle.tDiffTrackingSecond, + //g_stPTZ_Handle.iTracking_resume_dwell, + //g_stPTZ_Handle.iLockBoxIdx, + //g_stPTZ_Handle.iZoneToPresetAnyOne, + //iPTZRecoveryTimeSec); + //write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); + } + + { + //char msg_temp[512] = { 0 }; + //sprintf(msg_temp, "iTraffic_cnfidence:%d,iEnable_PTZ:%d,iTracking_fov_min:%d,iTracking_fov_max:%d,iEnable_tracking:%d,iTracking_mode:%d,iTracking_entering_zone:%d", + //g_stPTZ_Handle.iTraffic_cnfidence, + //g_stPTZ_Handle.iEnable_PTZ, + //g_stPTZ_Handle.iTracking_fov_min, + //g_stPTZ_Handle.iTracking_fov_max, + //g_stPTZ_Handle.iEnable_tracking, + //g_stPTZ_Handle.iTracking_mode, + //g_stPTZ_Handle.iTracking_entering_zone); + //write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); + } + + //printf("[%d][%d]>>>>>>>>>>>>>>>>>> %d, %d \n", g_stPTZ_Handle.iLockBoxIdx, g_stPTZ_Handle.iPauseTrackFlag, g_stPTZ_Handle.tDiffTrackingSecond, iPTZRecoveryTimeSec); + + if (g_stPTZ_Handle.tDiffTrackingSecond > iPTZRecoveryTimeSec //看太久, 要回去 300s + && g_stPTZ_Handle.iLockBoxIdx != -1 + //&& g_stPTZ_Handle.iPauseTrackFlag == 0 + && g_stPTZ_Handle.iZoneToPresetAnyOne == 1) + { + tOldTrackingTime = time(0); + tCurrentTrackingTime = time(0); + + //Set Pause Flag + g_stPTZ_Handle.iPauseTrackFlag = 1; + + //if (!IsPTZatHomePos()) + //{ +#if 0 + g_stPTZ_Handle.iIsGetLockTrackingBox = 0; + iHomePos = GetHomePreset(); + GoPreset(iHomePos); + usSleep(GO_HOME_SLEEP*1000); +#endif + +#if 1 + iHomePos = GetHomePreset(); + g_stPTZ_Handle.iIsGoingHome = 1; + while (IsPTZatHomePos() == 0) + { + GoPreset(iHomePos); + usSleep(1000000); + + if (iTryGoHomeCount >= 5) + break; + else + iTryGoHomeCount++; + } + g_stPTZ_Handle.iIsGoingHome = 0; +#endif + //} + } + else if (g_stPTZ_Handle.tDiffTrackingSecond > g_stPTZ_Handle.iTracking_resume_dwell //PTZ_IS_TRACKING_TIMER //g_stPTZ_Handle.iTracking_resume_dwell + && g_stPTZ_Handle.iLockBoxIdx == -1 + //&& g_stPTZ_Handle.iPauseTrackFlag == 0 + ) + { + tLoseTrackingTime = time(0); + tCheckResumeTime = time(0); + + //Set Pause Flag + g_stPTZ_Handle.iPauseTrackFlag = 1; + + + g_stPTZ_Handle.iIsGetLockTrackingBox = 0; + +#if 0 + if (g_stPTZ_Handle.iIsAtHomePOS == 0) + { + iHomePos = GetHomePreset(); + GoPreset(iHomePos); + usSleep(GO_HOME_SLEEP*1000); + } +#endif +#if 1 + iHomePos = GetHomePreset(); + g_stPTZ_Handle.iIsGoingHome = 1; + while (IsPTZatHomePos() == 0 + && g_stPTZ_Handle.iZoneToPresetAnyOne == 1) + { + GoPreset(iHomePos); + usSleep(1000000); + + if (iTryGoHomeCount >= 5) + break; + else + iTryGoHomeCount++; + } + g_stPTZ_Handle.iIsGoingHome = 0; +#endif + } + //if (g_stPTZ_Handle.iIsAtHomePOS == 1) + else if (g_stPTZ_Handle.iIsInPreset != 0) + { + if (g_stPTZ_Handle.iLockBoxIdx == -1) + { + g_stPTZ_Handle.tDiffTrackingSecond = 0; + g_stPTZ_Handle.iIsGetLockTrackingBox = 0; + + tLoseTrackingTime = time(0); + } + //tCheckResumeTime = time(0); + + tOldTrackingTime = time(0); + tCurrentTrackingTime = time(0); + } + + /*tDiffTrackingSecond = 0.0; + tDiffTrackingSecond = difftime(tLoseTrackingTime, tCheckResumeTime); + + g_stPTZ_Handle.LostTime = tDiffTrackingSecond; + + if (tDiffTrackingSecond >= 6) + { + tCheckResumeTime = time(0); + tLoseTrackingTime = time(0); + + iHomePos = GetHomePreset(); + GoPreset(iHomePos); + }*/ +#endif + + //g_stPTZ_Handle.iIsStayHomePos = IsPTZatHomePos(); + usSleep(200000); + } //while (1) + + g_stPTZ_Handle.iRunPTZTrackingThread_flag = 0; + + //exit thread + pthread_exit(NULL); +} + +void SwitchRecoveryMode(int iSwitch) +{ + char outputData[1024] = { 0 }; + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + //char ptz_curl_url_sec[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + if (iSwitch == 1) + { + sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?returntime_flag=1&returntime_min=0&returntime_sec=5"); + } + else if (iSwitch == 0) + { + sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?returntime_flag=0&returntime_min=0&returntime_sec=0"); + } + + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Switch Recovery Mode 1"); + usSleep(100000); + + + if (iSwitch == 1) + { + memset(ptz_curl_url, 0, sizeof(ptz_curl_url)); + sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?returnmode_flag=1&returnmode_mode=51"); + + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "Switch Recovery Mode 2"); + usSleep(100000); + } +} + +void StartPTZtrackingThread() +{ + //Set recovery mode = on + //SwitchRecoveryMode(1); + + g_IsShipTracking = IsShipObj(); + + if (g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag == 1 + && g_stPTZ_Handle.iRunPTZTrackingThread_flag == 0) + { + g_stPTZ_Handle.iRunPTZTrackingThread_flag = 1; + g_stPTZ_Handle.iIsGoingHome = 0; + + //if (IsPTZatHomePos() == 1) + //{ + + //Get PTZ Info + if (pthread_create(&ptz_tracking_thread, 0, ptz_do_tracking_thread, NULL)) + printf("\nPTZ info thread creation failed\n"); + + //} + //else + //{ + //Go home + + + //while(IsPTZatHomePos()) + //Get PTZ Info + // if (pthread_create(&ptz_tracking_thread, 0, ptz_do_tracking_thread, NULL)) + // printf("\nPTZ info thread creation failed\n"); + //} + } +} + +void StopPTZtrackingThread() +{ + //Set recovery mode = off + //SwitchRecoveryMode(0); + + g_stPTZ_Handle.iRunPTZTrackingThread_flag = 0; +} + +void update_PTZ_limits() { + if (strcmp(viewChannelData[0].enable_tracking_limits, "Yes") == 0) { + int check_if_set_new_pos = 0; + if ((int)atof(viewChannelData[0].ptz_pan_left_limit) <= (int)atof(viewChannelData[0].ptz_pan_right_limit)) { + if (g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); + check_if_set_new_pos = 1; + } + + if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit)) { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); + check_if_set_new_pos = 1; + } + } + else { + if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit) && g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { + int differ_temp_right = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_right_limit); + int differ_temp_left = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_left_limit); + + if (differ_temp_right <= differ_temp_left) { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); + check_if_set_new_pos = 1; + } + else { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); + check_if_set_new_pos = 1; + } + } + } + if ((int)atof(viewChannelData[0].ptz_tilt_up_limit) <= (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { + if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); + check_if_set_new_pos = 1; + } + + if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); + check_if_set_new_pos = 1; + } + } + else { + if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); + check_if_set_new_pos = 1; + } + + if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); + check_if_set_new_pos = 1; + } + } + + if (check_if_set_new_pos == 1) + { + UpdatePTZCurPos(); + } + } +} + +void *ptz_update_status_thread(void *str) +{ + pthread_detach(pthread_self()); + setPthreadName("ptz_status"); + //int iUpdate_PTZ_setting_times_count = TIMER_UPDATE_PTZ_SETTING; + int iGoHomeSecTimer = 0; + int iHomePreset = -1; + + while (g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag) + { + //printf("get w/h = %d, %d \n", stChannelInfo->iVideo_source_w, stChannelInfo->iVideo_source_h); + //Update PTZ status + //if (iUpdate_PTZ_setting_times_count >= TIMER_UPDATE_PTZ_SETTING) + { + //UpdatePTZIPcamSetting(); + //UpdatePTZCurPos(); + /*if (strcmp(viewChannelData[0].enable_tracking_limits, "Yes") == 0) { + + int check_if_set_new_pos = 0; + if ((int)atof(viewChannelData[0].ptz_pan_left_limit) <= (int)atof(viewChannelData[0].ptz_pan_right_limit)) { + if (g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); + check_if_set_new_pos = 1; + } + + if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit)) { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); + check_if_set_new_pos = 1; + } + } + else { + if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit) && g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { + int differ_temp_right = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_right_limit); + int differ_temp_left = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_left_limit); + + if (differ_temp_right <= differ_temp_left) { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); + check_if_set_new_pos = 1; + } + else { + SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); + check_if_set_new_pos = 1; + } + } + } + if ((int)atof(viewChannelData[0].ptz_tilt_up_limit) <= (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { + if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); + check_if_set_new_pos = 1; + } + + if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); + check_if_set_new_pos = 1; + } + } + else { + if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); + check_if_set_new_pos = 1; + } + + if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { + SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); + check_if_set_new_pos = 1; + } + } + + if (check_if_set_new_pos == 1) + { + //UpdatePTZCurPos(); + } + + }*/ + + //UpdateRecoveryTime(); + + //printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> min:sec= %d, %d \n", g_stPTZ_Handle.iRT_min, g_stPTZ_Handle.iRT_sec); + //iUpdate_PTZ_setting_times_count = 0; + } + + //iUpdate_PTZ_setting_times_count++; + + if (g_stPTZ_Handle.iEnable_tracking != 1) + { + //usSleep(2000000); + usSleep(3000000); + continue; + } + + //Check PerformDetection, + //-1 = error, 0 = not in preset, 1~255 = in x preset point + if (IsTracking() == 1) + { + StartPTZtrackingThread(); + } + else if (IsTracking() != 1) + { + StopPTZtrackingThread(); + } + + //for test + //StartPTZtrackingThread(); + + //Go Home Preset Every 10 min, when position at home. + if (IsPTZatHomePos() == 1)////Start check + { + iGoHomeSecTimer++; + + //check + if (iGoHomeSecTimer > TIMER_GO_HOME_PRESET) + { + //go home preset + iHomePreset = GetHomePreset(); + GoPreset(iHomePreset); + + //reset timer + iGoHomeSecTimer = 0; + } + } + else + { + //reset timer + iGoHomeSecTimer = 0; + } + + + //usSleep(PTZ_UPDATE_STATUS_TIMER*1000); + usSleep(1000000); + } + //exit thread + pthread_exit(NULL); +} + +int StartPTZupdateStatusThread() +{ + g_stPTZ_Handle.iIsPTZ = 0; + g_stPTZ_Handle.iLoseLockObjCount = 0; + + usSleep(100000); + + //Init curl handle; + //g_curl_Handle = curl_easy_init(); + //create_g_curl_connect(); + + //Create_ptz_socket(); + + //Check if ptz device. + + if (g_IsPTZDevice == 1) + { + //printf("This is PTZ device. \n"); + g_stPTZ_Handle.iIsPTZ = 1; //for IsPTZ() callback. + + DefaultFocusSetting(); + +#if 1 + g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag = 1; + //Get PTZ Info + if (pthread_create(&ptz_status_thread, 0, ptz_update_status_thread, NULL)) + { + //printf("\nPTZ update status thread creation failed\n"); + return 0; + } +#endif + return 1; + } + else + { + //printf("This is not PTZ device. \n"); + return 0; + } +} + +void StopPTZupdateStatusThread() +{ + g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag = 0; + StopPTZtrackingThread(); +} + +void GoPreset(int iPresetNumber) +{ + //if (g_stPTZ_Handle.iIsPTZ == 1) + if (1) + { + if (MIN_PRESET_NUMBER <= iPresetNumber + && iPresetNumber <= MAX_PRESET_NUMBER) + { + char outputData[1024] = { 0 }; + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?ai_goto_preset=%d", iPresetNumber); + //sprintf(ptz_curl_url, "/ptzpreset?camid=1&goto_preset=%d", iPresetNumber); + //http://192.168.8.151/ptzpreset?camid=1&goto_preset=1 + + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "Go Preset"); + usSleep(100000); + } + else + { + //printf("Can only support 0~16 preset number \n"); + } + } + else + { + //printf("Device not support PTZ CMD #1\n"); + } +} + +void StopPtz() +{ + if (g_stPTZ_Handle.iIsPTZ == 1) + { + char outputData[1024] = { 0 }; + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + sprintf(ptz_curl_url, "http://127.0.0.1/control?stop=1"); + //sprintf(ptz_curl_url, "/control?stop=1"); + //http://192.168.8.151/ptzpreset?camid=1&goto_preset=1 + + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Stop Ptz"); + } + else + { + //printf("Device not support PTZ CMD #2\n"); + } +} + +void StartStopAutopan(int iStartStopFlag) +{ + if (g_stPTZ_Handle.iIsPTZ == 1) + { + char outputData[1024] = { 0 }; + + char *ptz_ip = "http://127.0.0.1"; + char ptz_curl_url[512] = { 0 }; + char ptz_curl_sendbuf[1] = { 0 }; + char ptz_curl_username[128] = { 0 }; + char ptz_curl_password[128] = { 0 }; + char *method = "GET"; + int ptz_port = atoi(accountData[0].account_port); + strcat(ptz_curl_username, accountData[0].account_username); + strcat(ptz_curl_password, accountData[0].account_password); + + int iOpenFlag = 0; + if (iStartStopFlag == 1) + iOpenFlag = 1; + + sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?autopan=%d", iOpenFlag); + //sprintf(ptz_curl_url, "/ptzpreset?autopan=%d", iOpenFlag); + //http://192.168.8.151/ptzpreset?camid=1&goto_preset=1 + + send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Start Stop Autopan"); + } + else + { + //printf("Device not support PTZ CMD #3\n"); + } +} + +#endif \ No newline at end of file diff --git a/src/ptz.h b/src/ptz.h new file mode 100644 index 0000000..535cbdf --- /dev/null +++ b/src/ptz.h @@ -0,0 +1,307 @@ +#ifdef GY_OS_AMBA +#pragma once +#ifndef PTZ_H +#define PTZ_H +#include "define_inc.h" +#include "utility.h" +#include "nweb.h" +#include <setjmp.h> + +#ifndef TRY_CATCH +#define TRY_CATCH +#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){ +#define CATCH } else { +#define ETRY } }while(0) +#define THROW longjmp(ex_buf__, 1) +#endif + +#define SYS_FEATURE_PTZ 0x4000000 +#define SYS_FEATURE_LDC 0x8000000 +#define SYS_FEATURE_LPR 0x10000000 + +#define MIN_PRESET_NUMBER 0 +#define MAX_PRESET_NUMBER 256 + +#define MAX_RECORD_BOX_SIZE 5 + +#define GO_HOME_SLEEP 3000 + +//#define MATH_PI 3.14 Ʃwq + +#define MAX_PTZ_INFO 100 +#define TIMER_TEN_SEC 10 +#define TIMER_ONE_SEC 1 +#define TIMER_UPDATE_PTZ_SETTING 1 //Second +#define TIMER_GO_HOME_PRESET 600 //Second + +#define PTZ_DEFAULT_SENSITIVITY 0 +#define PTZ_CENTER_AREA_X2_MIN 45//2 //zoom in 10x define center area X%, don't move +#define PTZ_CENTER_AREA_X2_MAX 55//2 //zoom in 10x define center area X%, don't move +#define PTZ_CENTER_AREA_X5_MIN 40//5 //zoom in 5x +#define PTZ_CENTER_AREA_X5_MAX 60//5 //zoom in 5x +#define PTZ_CENTER_AREA_X8_MIN 35//8 //zoom in 1x +#define PTZ_CENTER_AREA_X8_MAX 65//8 //zoom in 1x +#define PTZ_TRACKING_OBJ_NUMBER 512 +#define PTZ_ZOOMIN_LIMIT 100 //70% W&H +#define PTZ_LOSE_OBJ_LIMIT 25 //max lose times +#define PTZ_MISSING_OBJ_LIMIT_LONG 15 //max lose times +#define PTZ_MISSING_OBJ_LIMIT_SHORT 9 //max lose times + +#define PTZ_FILTER_AREA_MIN 45 +#define PTZ_FILTER_AREA_MAX 55 + +//TIMER +#define PTZ_UPDATE_STATUS_TIMER 100 //100ms +#define PTZ_TRACKING_RESUME_TIME 50 // 300 sec +#define PTZ_IS_TRACKING_TIMER 5 // 10 second + +#define PTZ_ZOOM_FREQUENCE_MOD 6 + +#define PTZ_MISS_OBJ_MAGIC_FLAG 987654321 + +//#define PTZ_TEST +/* +typedef struct { + char sUrl[512]; + char sContent[512]; + char sUsername[128]; + char sPassword[128]; + char sMethod[32]; + int iPort; +} PTZconnectInfo;*/ + +typedef struct PTZ_VIRTUAL_BOX { + int left_x; + int top_y; + int right_x; + int bottom_y; + int center_x; + int center_y; + int width; + int height; + + char name[50]; + float confidence; + int obj_type; + int class_id; + int obj_tracking_id; + double obj_dwell_time; + + int iFirstTrackingFlag; +} PTZ_VIRTUAL_BOX; + +typedef struct PTZ_ZONE_INFO { + int iMetadata1_num; + char sMetaOut1[PTZ_TRACKING_OBJ_NUMBER][50]; + //char sMetaOut1[MAX_MSG_LEN * 10]; + int iZoneToPreset; +} PTZ_ZONE_INFO; + +typedef struct PTZ_HANDLE { + int iIsMirror; + int iIsFlip; + int iIsAtHomePOS; + int iIsInPreset; + int iIsInAutopan; + int iIsInAutoTracking; + int iHomePreset; + int iIsGoingHome; + + //int iIsStayHomePos; + //int iSwitchTrackOnOff; + + int iIsPTZ; + int iRunPTZUpdateStatusThread_flag; + int iRunPTZTrackingThread_flag; + int iRunPTZZoomThread_flag; + + //Home preset pos. + int iHomePanABS; + int iHomeTiltABS; + int iHomeZoomABS; + + //pan, tilt and zoom absolute value + int iPanABS; + int iTiltABS; + int iZoomABS; + + //Recovery Timer + int iRT_min; + int iRT_sec; + + int iZoomRunning; + + //PTZ_VIRTUAL_BOX stPTZlockTrackingBox; + PTZ_VIRTUAL_BOX stPTZCandidateBoxTable[MAX_DETECT_OBJECTS]; + int iCandidateBoxCount; + int iIsGetLockTrackingBox; + PTZ_VIRTUAL_BOX stPTZLockTrackingBox; + + PTZ_VIRTUAL_BOX stPTZOutsideBox; + + PTZ_VIRTUAL_BOX stPTZRecordOldOutsideBox[MAX_RECORD_BOX_SIZE]; + int iRecordOldOutsideBoxCount; + + //int iLockBoxArea_min; + //int iLockBoxArea_max; + + //double dwMoveAngel; + //int iMoveSpeed_x; + //int iMoveSpeed_y; + + + //int iIs_enable_alarm; + //time_t tOperatTime; + //time_t tChangAutoPanTime; + //time_t tOperatZoomTime; + //time_t tTrackingTotalTime; + //time_t tUpdateLockBoxTime; + time_t tUpdateCandidateTableTime; + + + //int LostTime; + //int ResumTime; + + //PTZ_VIRTUAL_BOX stRecordCenterPoint[5]; + //int iRecordCenterPointNumber; + + // iPTZ_sensitivity; + int iPTZ_speed; + + //int iTimer_send_count; + //int g_ptz_zoom_iou; + int iLockObjFOV; + + int iTraffic_cnfidence; + //char MetaData1[MAX_MSG_LEN * 10]; + //char *metadata1[MAX_MSG_LEN * 10]; //for filter + int iMetadata1_num; + char sMetaOut1[PTZ_TRACKING_OBJ_NUMBER][50]; + + int iEnable_PTZ; + int iTracking_fov_min; + int iTracking_fov_max; + int iEnable_tracking; + int iTracking_mode; + int iTracking_entering_zone; + int iTracking_resume_dwell; + int iIMG_source_w; + int iIMG_source_h; + + int iLockBoxIdx; + int iLoseLockObjCount; + int iPauseTrackFlag; + int iMissObjMomnentCount; + + int iThreadRunningFlag; + + int iUpdateOutsideBox; + + int tDiffTrackingSecond; + + int iZoomFreqMod; + int iZoomFreqCount; + int iGoCenterFreqFrame; + int iGoCenterFreqCount; + int iZoneToPresetAnyOne; + //int iZoneToPreset[MAX_DETECTION_ZONE]; + +} PTZ_HANDLE; + +extern CURL* g_http_handle; + +extern pthread_mutex_t mutex_curl; + +extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; +extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; +extern SystemSettingInfo SystemSetting; +extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add + + +extern PTZ_HANDLE g_stPTZ_Handle; +extern pthread_mutex_t mutex_update_candidate; +extern pthread_mutex_t mutex_send_cgi; +//extern CURLM* g_multi_handle; +//extern int g_handle_count; +extern amba_content stAMBAcontent; + +//PTZ_HANDLE *CreatePTZHandle(); +//void DeletePTZHandle(PTZ_HANDLE *pInPTZHandle); + +void SetPtzSensitivity(int iSensitivity); +int UpdatePTZIPcamSetting(); +int UpdatePTZCurPos(); + +int SetPTZNewPan(int new_pan); +int SetPTZNewTilt(int new_tilt); +int move_PTZ_in_the_direction(int new_pan, int new_tilt); +void* ptz_stop_thread(void * ptr); + +void Mirror_Flip_posInfo(detection_pos *PosInfo, int iTotalElementSize, int iIm_width, int iIm_height, int iMirrorFlag, int iFlipFlag); +int MirrorBondingBox(int x, int w); +int FlipBondingBox(int y, int h); + +extern int g_IsPTZDevice; +extern int g_check_if_OK_thermal; + +int StartPTZupdateStatusThread(); +void StopPTZupdateStatusThread(); +//void Free_PTZ_g_curl_connect(); + +void StartPTZtrackingThread(); +void StopPTZtrackingThread(); + +void *ptz_update_status_thread(void *ptr); +void *ptz_do_tracking_thread(void *ptr); +void *ptz_do_zoom_thread(void *ptr); + +void UpdatePTZsourceWH(int iVideo_source_w, int iVideo_source_h); +//void UpdatePTZConfigSetting(char *sEnable_ptz, char *sEnable_tracking, char *sTracking_fov_min, +// char *sTracking_fov_max, char *sConfidence2, int iPTZMode, int iIsTrackingEnterZone, char *sTracking_resume_dwell, +// char *sInMetadata1, int iZoneToPreset[]); +void UpdatePTZConfigSetting(); +void PTZUpdateTrackingInfo(detection_pos *posInfo, int iTotalElementSize, int iResW, int iResH); + +int IsPTZ(); +int IsPTZMirror(); +int IsPTZFlip(); +int IsPTZMirrowFlip(); +int IsPTZatHomePos(); +int IsPTZinPreset(); +int IsPTZinAutoPan(); +int IsPTZinAutoTracking(); +int IsPTZEnableAlarm(int iInZone_idx); +int IsTracking(); + +int GetHomePreset(); +int GetPTZActionState(); +int StartTracking(); +int StopTracking(); +int EnableAlarmQuaue(); +int DisableAlarmQueue(); +//void PerformDetection(); +int GetPTZStatus(); +void StopPtz(); +void GoPreset(int iPresetNumber); +void StartStopAutopan(int iStartStopFlag); +//int check_ptz(char* sUrl, char* sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort); +int check_ptz(char *outputData); + +float FindPointDistance(int x1, int y1, int x2, int y2); +void send_request(char *szIP, char *sUrl, char *sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort, char *sOutputData, char* function_id); + +int net_curl_ptz_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id); + +int get_g_PTZ_model(); + +int net_curl_status_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData,char* function_id); + +size_t ptz_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream); + +int UpdateRecoveryTime(); +void update_PTZ_limits(); + +#endif +#endif \ No newline at end of file diff --git a/src/pythonR.c b/src/pythonR.c new file mode 100644 index 0000000..8e555fd --- /dev/null +++ b/src/pythonR.c @@ -0,0 +1,417 @@ + +#include "pythonR.h" +#include <pthread.h> +#define MAX_BUFFER_LINES 1024 +char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; +char sFileName[PTYHON_FILE_NAME] = { 0 }; +//char sPythonFilename[PTYHON_FILE_NAME]; +pthread_mutex_t buffer_mutex = PTHREAD_MUTEX_INITIALIZER; + +int check_count = 0; + +void IfFolderExist() +{ + if (access(PYTHON_FOLDER, 0) == 0) + { + printf("FOLDER EXISTS. \n"); + } + else + { + printf("FOLDER DOESN'T EXISTS! \n"); + //int ret; + /*ret = */mkdir(PYTHON_FOLDER, S_IRWXU | S_IRWXG | S_IRWXO); + + check_count++; + if (check_count < 10) + { + IfFolderExist(); + } + } +} + +void readPythonFile(char *sINFileName, char *sOutput) +{ + memset(sPythonCode, 0, PYTHON_CODE_SIZE); + memset(sFileName, 0, PTYHON_FILE_NAME); + + int lSize = 0; + + //check folder exist + check_count = 0; + IfFolderExist(); + + //python file name + //sprintf(sFileName, "%s/%s.py", PYTHON_FOLDER, sINFileName); + sprintf(sFileName, "%s/%s", PYTHON_FOLDER, sINFileName); + + // printf("python name path = \n%s \n", sFileName); + + chmod(sFileName, 0777); + + FILE *f = fopen(sFileName, "r"); + + if (f != NULL) + { + fseek(f, 0, SEEK_END); + lSize = ftell(f); + + rewind(f); //set read point to start + /*size_t read_result = */fread(sOutput, 1, lSize, f); + + fclose(f); + } + else { + } +} + +// T{Ƨsb +int ensureFolderExists(const char *folderPath) { + struct stat st = { 0 }; + if (stat(folderPath, &st) == -1) { + mkdir(folderPath, 0777); + if (stat(folderPath, &st) == -1) { + return -1; // LkЫظƧ + } + } + + return 0; // +} + +int saveFile(char *pythonData, char *filename) { + if (ensureFolderExists(PYTHON_FOLDER) == -1) { + return -1; // Ƨsb + } + chmod(filename, 0777); + printf("[pythonR.html saveFile()] filename = %s\n", filename); + FILE *f = fopen(filename, "w"); + if (f != NULL) { + fprintf(f, "%s\n", pythonData); + fclose(f); + return 0; // \ + } else { + return -2; // LkgJ + } +} + +#if 1 +void deletePythonFile(char *sINFileName) +{ + // Define + // g_cWebPythonDeleteStatus = 0 deleted successfully + // g_cWebPythonDeleteStatus = 1 deleted failed + g_cWebPythonDeleteStatus = 0; + memset(sFileName, 0, PTYHON_FILE_NAME); + + //check folder exist + check_count = 0; + IfFolderExist(); + + //python file name + //sprintf(sFileName, "%s/%s.py", PYTHON_FOLDER, sINFileName); + sprintf(sFileName, "%s/%s", PYTHON_FOLDER, sINFileName); + + printf("[pythonR.html deletePythonFile()] filename = %s\n", sFileName); + if (remove(sFileName) == 0) { + printf("The file is deleted successfully. \n"); + g_cWebPythonDeleteStatus = 1; + } + else { + printf("The file is not deleted. \n"); + g_cWebPythonDeleteStatus = 0; + } + +} +#endif + +int checkDuplicateFile(const char *filename) { // check file name duplicate + char fullPath[1024]; + snprintf(fullPath, sizeof(fullPath), "%s/%s", PYTHON_FOLDER, filename); + + if (access(fullPath, F_OK) != -1) { + // file exists + return 1; + } + // file not exists + return 0; +} + +const char* SavePython(char *urlData) { + char *substr1 = "file="; + char *substr2 = "&code="; + char *result_1 = strstr(urlData, substr1); + char *result_2 = strstr(urlData, substr2); + + if (result_1 != NULL && result_2 != NULL) { + char sPythonFileName[1024] = {0}; + char sPythonFilePath[1024] = {0}; + char sPythonCode[PYTHON_CODE_SIZE] = {0}; + + memcpy(sPythonFileName, result_1 + strlen(substr1) , (result_2)-(result_1 + strlen(substr1))); + memcpy(sPythonCode, result_2 + strlen(substr2), (strlen(urlData) - ((result_2 + strlen(substr2)) - urlData))); + sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName); + + int saveResult = saveFile(sPythonCode, sPythonFilePath); + if(saveResult==0){ + return "File save successfully"; + }else{ + return "File save failed"; + } + + } + return "Invalid URL parameters"; +} + +const char* uploadPython(char *urlData) { + char *substr1 = "file="; + char *substr2 = "&code="; + char *result_1 = strstr(urlData, substr1); + char *result_2 = strstr(urlData, substr2); + + if (result_1 != NULL && result_2 != NULL) { + char sPythonFileName[1024] = {0}; + char sPythonFilePath[1024] = {0}; + char sPythonCode[PYTHON_CODE_SIZE] = {0}; + + memcpy(sPythonFileName, result_1 + strlen(substr1) , (result_2)-(result_1 + strlen(substr1))); + memcpy(sPythonCode, result_2 + strlen(substr2), (strlen(urlData) - ((result_2 + strlen(substr2)) - urlData))); + sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName); + printf("[uploadPython] sPythonFileName = %s : ", sPythonFileName); + if (strlen(sPythonFileName) == 0) { + printf("######################## No File name \n "); + return "Invalid file name"; + } + else if (checkDuplicateFile(sPythonFileName) == 1) + { + return "File already exists, please choose a different file name"; + } + int saveResult = saveFile(sPythonCode, sPythonFilePath); + if(saveResult==0){ + return "File uploaded successfully"; + }else{ + return "File upload failed"; + } + + } + return "Invalid URL parameters"; +} + +void stopPython() { + g_cWebPythonBufferSignal = 0; + for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) + { + memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); // 2024-09-09 sure buffer clear + } + g_uiWebPythonCurrentBufferIndex = 0; + g_uiWebPythonLastBufferIndex = 0; + g_cWebPythonStatus = 0; + printf("\n\n\n\n\n\n\nPython has been signaled to stop.\n\n\n\n\n\n\n"); +} + + +void runPython(char *pythonData) //2024/02/27 run button action +{ + // ------------------------------------------------- + // Bz ajax ǨӪrAѦɦWPɮפe + char *substr1 = "lifile_liname="; + char *result_1 = NULL; + char sPythonFileName[1024] = {0}; + result_1 = strstr(pythonData, substr1); //2024/02/27, search str and return str pointer position + memset(sPythonFileName, 0, PTYHON_FILE_NAME); //2024/02/27 name limit 1024 (use set mem value) + memset(sPythonCode, 0, PYTHON_CODE_SIZE); //2024/02/27 code size limit 20KB (use set mem value) + for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) // 2024-09-13 sure buffer clear + { + memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); + } + memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData)); + // if (g_cWebPythonName != NULL) { + + // memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData)); + + // } else { + // // pG json ɧ g_cWebPythonName + // strncpy(sPythonFileName, g_cWebPythonName, sizeof(sPythonFileName) - 1); + // memset(g_cWebPythonName, 0, sizeof(g_cWebPythonName)); + // } + + // if need read python content, use cat command + // char result_3[PYTHON_CODE_SIZE] = {0}; + // char cat_cmd[1024] = {0}; + // FILE *fp; + // snprintf(cat_cmd, sizeof(cat_cmd), "cat %s/%s", PYTHON_FOLDER, sPythonFileName); + // fp = popen(cat_cmd, "r"); + // if (fp == NULL) { + // printf("can't use cat command \n"); + // } else { + // size_t bytes_read = fread(result_3, 1, sizeof(result_3) - 1, fp); + // if (bytes_read > 0) { + // result_3[bytes_read] = '\0'; // TOr굲 + // } else { + // printf("read file content failed \n"); + // } + // pclose(fp); + // } + // ------------------------------------------------- + // إ virtual pipeline o python X + int size_psBuffer = BUFSIZE_V3; + char psBuffer[WEBPYTHONBUFFER_ROWSIZE] = {0}; + char sendBuffer_xtra[BUFSIZE * 8] = {0}; + //char psRunPythonStatusMessage[80] = {0}; + char psBufferTemp[WEBPYTHONBUFFER_ROWSIZE] = { 0 }; + FILE *pPipe; + char cmd[256] = {0}; + memset(cmd, 0x00, sizeof(cmd)); + size_t psbufferContentSize = 0; + size_t psBufferTempSize = 0; + g_uiWebPythonCurrentBufferIndex = 0; + g_uiWebPythonLastBufferIndex = 0; + // sprintf(cmd, "python3 %s", sPythonFilePath); + sprintf(cmd, "python3 %s/%s 2>&1", PYTHON_FOLDER, sPythonFileName); // sW 2>&1 + printf("run python cmd = \n%s \n", cmd); + pPipe = vpopen(cmd, "r"); + if (pPipe == NULL) + { + // virtual pipeline إߥѡA^ǵ Web ~T + printf("\n-------------------------------------\n"); + printf("Failed to run command\n"); + printf("pPipe is None!!\n"); + printf("\n-------------------------------------\n"); + // sprintf(psRunPythonStatusMessage, "Failed to run command. pPipe is None!!"); + } + else + { + // sprintf(psRunPythonStatusMessage, "Web Buffer Run OK"); + // \} virtual pipeline ~hŪ python X + g_cWebPythonBufferSignal = 1; // Signal to start reading + // g_uiWebPythonCurrentBufferIndex = 0; + while ((fgets(psBuffer, sizeof(psBuffer), pPipe) != NULL) && (g_cWebPythonBufferSignal != 0)) { //Ming 2024-09-01 + + printf("[runPython] PYTHON OUTPUT: %s", psBuffer); + // printf("[runPython] Before writing: g_uiWebPythonCurrentBufferIndex[%d]\n", g_uiWebPythonCurrentBufferIndex); + + psbufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]); + // printf("\npsbufferContentSize len : %zu\n", psbufferContentSize); + if (psbufferContentSize == 0) { + printf("\n\n\n\n Writing !!!!!\n\n\n\n"); + pthread_mutex_lock(&buffer_mutex); + + size_t len = strlen(psBuffer); + + if (psBufferTempSize + len < sizeof(psBufferTemp)) { + strcat(psBufferTemp, psBuffer); // K[e psBufferTemp + psBufferTempSize += len; // spƾ + } else { + // psBufferTemp ɡA g_aWebPythonBuffer2D ím + strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); + memset(psBufferTemp, 0, sizeof(psBufferTemp)); // M psBufferTemp + strcat(psBufferTemp, psBuffer); // m~J + psBufferTempSize = 0; // mpƾ + psBufferTempSize += len; // m~p + // printf("\n\n\n\n [runPython] Moved data to buffer : %s\n\n\n\n", g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]); + g_uiWebPythonCurrentBufferIndex++; + + } + + pthread_mutex_unlock(&buffer_mutex); + + if (g_uiWebPythonCurrentBufferIndex >= (WEBPYTHONBUFFER_LENSIZE - 1)) { + printf("!!! [runPython] Reset buffer index\n"); + g_uiWebPythonCurrentBufferIndex = 0; + } + } else { + printf("[runPython] buffer is not empty, psbufferContentSize:%zu\n", psbufferContentSize); + continue; + } + } + // Row neJ Buffer + if (psBufferTempSize > 0 ) + { + strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); + memset(psBufferTemp, 0, sizeof(psBufferTemp)); // M psBufferTemp + g_uiWebPythonCurrentBufferIndex++; + + } + + g_cWebPythonBufferSignal = 0; // ݦb python ]ɡA^ 0Apythongetbuffer CGI ~TD python 檬A + // + pclose(pPipe); // Close the pipe after reading all outputs + + } + // int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(psRunPythonStatusMessage), psRunPythonStatusMessage); + // if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + // { + // printf("\nsend error #32\n"); + // } + + +} + +void readFolderList(char *output) +{ + DIR *d; + struct dirent *dir; + char sfileList[200][256] = { 0 }; + int file_number = 0; + char *testsarr[100] = { "a","b","c" }; + + //Create JSON + cJSON *s_root = cJSON_CreateObject(); + + cJSON *s_file_name; + cJSON *file_list = cJSON_CreateArray(); + + if (ensureFolderExists(PYTHON_FOLDER) == -1) { + return -1; // Ƨsb + } + + + d = opendir(PYTHON_FOLDER); + if (d) { + while ((dir = readdir(d)) != NULL) { + if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) + { + // do nothing (straight logic) + } + else { + //printf("%s\n", dir->d_name); + //sprintf(&sfileList[file_number], "%s", dir->d_name); + //printf("%s\n", sfileList[file_number]); + //file_number++; + + s_file_name = cJSON_CreateString(dir->d_name); + + cJSON_AddItemToArray(file_list, s_file_name); + } + } + //printf("file num: %d \n", file_number); + + for (int j = 0; j < file_number; j++) + { + printf("%s\n", sfileList[j]); + } + + cJSON_AddItemToObject(s_root, "file_list", file_list); + + char* JsonString = cJSON_Print(s_root); + + sprintf(output, "%s", JsonString); + + //printf("jstring = \n%s\n", JsonString); + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + + closedir(d); + } + + + + return 0; +} + diff --git a/src/pythonR.h b/src/pythonR.h new file mode 100644 index 0000000..afdef51 --- /dev/null +++ b/src/pythonR.h @@ -0,0 +1,39 @@ + +#pragma once +#ifndef PYTHON_R_H +#define PYTHON_R_H + +#include <dirent.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <setjmp.h> +#include <sys/stat.h> +#include "cJSON.h" +#include <unistd.h> +#include "fork_pipe_lib.h" +#include "utility.h" +#include "nweb.h" + +//#define STRSPLIT_SIZE 256 +#define PYTHON_FOLDER "/emmc/plugin/Aida_data/python_code" +//#define INI_FILE_PATH "/emmc/plugin/Aida_data/trans.names" +#define PY_SHELL "sh /emmc/plugin/Aida_data/python_code/run_python.sh" +#define PYTHON_LOG "python_log.txt" +#define PYTHON_CODE_SIZE 1024*20 +#define PTYHON_FILE_NAME 1024 + +#define DEBUG_COMPORT_PRINT_FGET 1 + +void deletePythonFile(char *sINFileName); +void readPythonFile(char *sINFileName, char *sOutput); +void readFolderList(char *output); +//int runPython(char *pythonData, int sock); //2024/03/08 +void runPython(char *pythonData); // 2024-10-14 +//void runPython(char *pythonData); +//void uploadPython(char *urlData); +const char* uploadPython(char *urlData); +void parseContent(char *recvBuffer); + + +#endif \ No newline at end of file diff --git a/src/radar.cpp b/src/radar.cpp new file mode 100644 index 0000000..cb9588c --- /dev/null +++ b/src/radar.cpp @@ -0,0 +1,1078 @@ +/** + * @file radar.cpp + * @author cola (cola.yang@meritlilin.com.tw) + * @brief radar fusion with the ptz and ai plugin + * @version 0.2 + * @date 2022-01-11 + * build some function + * + * @version 1.0 + * @date 2022-01-24 + * queue is broken waiting for fix + * @copyright Copyright (c) 2022 + * /getradar ok Read config from radar.json + + /radar_info ///not used + /Thread_render_radar ok ///UI render + /Thread_receive_radar_to_amb ok ///to getalarmmotion + global_message_for_radar_response -> global radar data string + g_radar_queue ->radar data json string + g_radar_image_queue ->radar render image + */ +#include <string.h> +#include <iostream> +#include <fstream> +#include <vector> +#include <utility> // std::pair +#include <stdexcept> // std::runtime_error +#include <sstream> // std::stringstream +#include "radar.h" +// #include "radar_driver.h" // Ken 09-28 +#include "setting.h" +#include <pthread.h> +//#include <cmath> +#include <queue> +#include <opencv2/highgui.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/opencv.hpp> +#include <opencv2/imgcodecs.hpp> +#include "cJSON.h" +#include <math.h> +#include "utility.h" + +// Ken 09-30 +#include <string> +using namespace std; + +// Ken 11-01 +#include <sys/time.h> + +// #include "ptz.h" + +std::ifstream radar_fake; +pthread_mutex_t mutex_radar; +pthread_mutex_t mutex_speedbg; +pthread_t radardata; +pthread_t radarrender; +std::vector<std::string> colname{}; +std::queue<char *> g_radar_queue; +std::queue<cv::Mat> g_radar_image_queue; +std::string str_nosignal; +char *img_file; +char *speed_bg_path = (char *)"/emmc/plugin/Aida_data/radar/speed_user.jpg"; +cv::Mat bg; +cv::Mat speed_bg; +cv::Mat temp_img; + +// int sig_radarrender_thread = 0; +//char *global_message_for_radar_response = (char *)malloc(256);//`NOSfree +// char *global_radar_response = (char *)malloc(256); + +char global_radar_response[BUFSIZE_V3] = {0}; + +// Ken 2022-10-28 radar image w & h settings +float g_radar_img_width = 800.0; +float g_radar_img_height = 600.0; + +#ifdef WIN32 +#include <Windows.h> +#include <stdio.h> +#else +#include <unistd.h> +#endif + +// #define A113n_PTZ +// #define MAX_PTZ_INFO 100 +// #define A113n + +// #ifdef A113n +// #include "net_curl.h" +// #endif + +#define PI 3.1415926 + +//-------------------------column name---------------------------- +// Time,FrameNum,tid,posX,posY,posZ,velX,velY,velZ,accX,accY,accZ +//---------------------------------------------------------------- +/** + * @brief read csv not used + * + * @param filename + * @return std::vector<std::pair<std::string, std::vector<double>>> + */ +std::vector<std::pair<std::string, std::vector<double>>> read_csv(std::string filename) +{ + // Reads a CSV file into a vector of <string, vector<int>> pairs where + // each pair represents <column name, column values> + + // Create a vector of <string, int vector> pairs to store the result + std::vector<std::pair<std::string, std::vector<double>>> result; + + // Create an input filestream + std::ifstream myFile(filename); + + // Make sure the file is open + if (!myFile.is_open()) + throw std::runtime_error("Could not open file\n"); + + // Helper vars + std::string line, colname; + double val; + + // Read the column names + if (myFile.good()) + { + // Extract the first line in the file + std::getline(myFile, line); + + // Create a stringstream from line + std::stringstream ss(line); + + // Extract each column name + while (std::getline(ss, colname, ',')) + { + + // Initialize and add <colname, int vector> pairs to result + result.push_back({colname, std::vector<double>{}}); + } + } + + // Read data, line by line + while (std::getline(myFile, line)) + { + // Create a stringstream of the current line + std::stringstream ss(line); + // Keep track of the current column index + int colIdx = 0; + + // Extract each integer + while (ss >> val) + { + + // Add the current integer to the 'colIdx' column's values vector + + result.at(colIdx).second.push_back(val); + + // If the next token is a comma, ignore it and move ondd + if (ss.peek() == ',') + ss.ignore(); + + // Increment the column index + colIdx++; + } + } + + // Close file + myFile.close(); + + return result; +} + +/** + * @brief read csv file + * @version 1.0 + * column count:12 + * @param radar_fake + * @return std::vector<std::string> column name + */ +std::vector<std::string> read_colname(std::ifstream &radar_fake) +{ + // Make sure the file is open + if (!radar_fake.is_open()) + { + radar_fake.open("/emmc/plugin/Aida_data/radar/v7radar_12_16-17-43.csv"); + // printf("open v7radar\n"); + } + // Helper vars + std::string line, col; + std::vector<std::string> colnamel; + // Read the column names + if (radar_fake.good()) + { + // Extract the first line in the file + std::getline(radar_fake, line); + + // Create a stringstream from line + std::stringstream ss(line); + + // Extract each column name + for (int i = 0; i < 12; i++) + { + std::getline(ss, col, ','); + printf("%s", col.c_str()); + colnamel.push_back(col); + } + } + + return colnamel; +} + +/** + * @brief build json from line + * + * @param line + * @return std::string + */ +std::string read_json(std::string line) +{ + pthread_mutex_lock(&mutex_radar); + double val; + std::string json_result = "{\"Radar\":\"v1\","; // cola 22/01/10 + std::stringstream ss(line); + int colIdx = 0; + while (ss >> val) + { + json_result += "\""; + json_result += colname[colIdx]; + json_result += "\":"; + json_result += std::to_string(val); + json_result += ","; + // If the next token is a comma, ignore it and move on + if (ss.peek() == ',') + ss.ignore(); + colIdx++; + } + json_result.erase(json_result.end() - 1); + json_result += "}"; + pthread_mutex_unlock(&mutex_radar); + return json_result; +} + + +/** + * @brief stop the radar rendering thread + * + */ +// void radar_render_thread_stop() +// { +// printf("radar render thread stop\n"); +// // sig_radarrender_thread = 0; +// bg.release(); +// } + +bool fileExists(const std::string &path) +{ + bool ret = false; + if ((access(path.c_str(), F_OK)) != -1) + { + ret = true; + } + return ret; +} + +/** + * @brief get background image path + * + * @return char* + */ +char *radar_bg_path() +{ + char *userpath = (char *)"/emmc/plugin/Aida_data/radar/radar_user.jpg"; + char *defaultpath = (char *)"/emmc/plugin/Aida_data/radar/radar_default.png"; + if (fileExists(userpath)) + return userpath; + else + return defaultpath; +} + +/** + * @brief initialize the thread and param + * + */ +void Radar_init() +{ + printf("Radar_init() start\n"); + img_file = radar_bg_path(); + // printf("imagge file : %s\n", img_file); + pthread_mutex_lock(&mutex_get_image); + // sig_radarrender_thread = 0; + cv::Mat nosignal = cv::imread("/emmc/plugin/Aida_data/radar/radar_503.jpg"); + // cv::Mat nosignal = cv::imread("/emmc/plugin/Aida_data/radar/radar_nosignal.png"); + std::vector<uchar> data_encode; + cv::imencode(".jpg", nosignal, data_encode); + std::string str_encode(data_encode.begin(), data_encode.end()); + str_nosignal = str_encode; + pthread_mutex_unlock(&mutex_get_image); + printf("Radar_init() end\n"); +} + + +/** + * @brief fusion the data on the image + * read meta parfse to json and fusion image by opencv + * @param ptr not used + * @return void* + */ +// void *radardraw(void *ptr) +void *thread_render_radar_img(void *ptr) +{ + pthread_detach(pthread_self()); + Radar_init(); + Reread_radarbg(); + // sig_radarrender_thread = 1; + int cont_render = 0; + + while (get_bHttpServerThreadStart()) + { + // // ------------------------------------- + // struct timeval t1; + // gettimeofday(&t1, NULL); + // time_t t1_ms = t1.tv_usec / 1000; + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + cont_render++; + + + // if (g_switch_radar_data_json == 0) + { + pthread_mutex_lock(&mutex_get_image); + temp_img = bg.clone(); + + // // ------------------------------------- + // struct timeval t2; + // gettimeofday(&t2, NULL); + // time_t t2_ms = t2.tv_usec / 1000; + // printf("radardraw - temp_img = bg.clone(), ms Time = %f\n", difftime(t2_ms, t1_ms)); // 2022-11-02 time cost : 2 ~ 2x ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + cJSON *root = NULL; + + // 2022-11-25 Ken + if (g_IsRadarFake == 1) + { + root = cJSON_Parse(g_radar_data_json); + } + else + { + root = cJSON_Parse(global_radar_response); + } + + + + // 10-03 Radar point info + // int FrameNum = 0; + // int tid = 0; + + int world_radar_x = 0; + int world_radar_y = 0; + int R, G, B = 0; + char *plot = {0}; + char *type = {0}; + + // // ------------------------------------- + // struct timeval t3; + // gettimeofday(&t3, NULL); + // time_t t3_ms = t3.tv_usec / 1000; + // printf("radardraw - cJSON_Parse(global_radar_response), ms Time = %f\n", difftime(t3_ms, t2_ms)); // 2022-11-02 time cost : 1 ~ 2x ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + if (cJSON_HasObjectItem(root, "AiRadar")) + { + // printf("radar.cpp - AiRadar JSON:\n%s\n",cJSON_Print(root)); + + cJSON *AiRadar_json, *RadarArray_json; + + AiRadar_json = cJSON_GetObjectItem(root, "AiRadar"); + + // FrameNum = stoi(cJSON_GetObjectItem(AiRadar_json, "FrameNum")->valuestring); + + RadarArray_json = cJSON_GetObjectItem(AiRadar_json, "RadarArray"); + + cJSON *radar_point = NULL; + + // // ------------------------------------- + // struct timeval t4; + // gettimeofday(&t4, NULL); + // time_t t4_ms = t4.tv_usec / 1000; + // printf("radardraw - cJSON_GetObjectItem from AiRadar_json, ms Time = %f\n", difftime(t4_ms, t3_ms)); // 2022-11-02 time cost : 0 ~ 1 ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + cJSON_ArrayForEach(radar_point, RadarArray_json) + { + type = cJSON_GetObjectItem(radar_point, "Type")->valuestring; + // tid = stoi(cJSON_GetObjectItem(radar_point, "tid")->valuestring); + world_radar_x = stoi(cJSON_GetObjectItem(radar_point, "world_radar_x")->valuestring); + world_radar_y = stoi(cJSON_GetObjectItem(radar_point, "world_radar_y")->valuestring); + plot = cJSON_GetObjectItem(radar_point, "plot")->valuestring; + + // printf("\ndraw radar FrameNum, tid, x, y, plot: %d, %d, %d, %d, %s\n", FrameNum, tid, world_radar_x, world_radar_y, plot); + + if (world_radar_x < 0 || world_radar_y < 0 || world_radar_x > (int)g_radar_img_width || world_radar_y > (int)g_radar_img_height) + continue; + + if (strcmp(plot, "Yes") == 0) + { + if (strcmp(type, "3") == 0) + { + R = 108; + G = 135; + B = 212; + } + else if (strcmp(type, "2") == 0) + { + R = 253; + G = 150; + B = 0; + } + else + { + R = G = B = 92; + } + cv::circle(temp_img, cv::Point(world_radar_x, world_radar_y), 10, cv::Scalar(B, G, R), -1, 8); + } + } + + // // ------------------------------------- + // struct timeval t5; + // gettimeofday(&t5, NULL); + // time_t t5_ms = t5.tv_usec / 1000; + // printf("radardraw - cJSON_ArrayForEach(), ms Time = %f\n", difftime(t5_ms, t4_ms)); // 2022-11-02 time cost : 0 ~ 1 ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + } + + pthread_mutex_unlock(&mutex_get_image); + + // // ------------------------------------- + // struct timeval t6; + // gettimeofday(&t6, NULL); + // time_t t6_ms = t6.tv_usec / 1000; + // printf("radardraw - if (cJSON_HasObjectItem(root, 'AiRadar')), ms Time = %f\n", difftime(t6_ms, t2_ms)); // 2022-11-02 time cost : 0 ~ 1 ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + if (root) + { + cJSON_Delete(root); + root = NULL; + } + + // // ------------------------------------- + // struct timeval t7; + // gettimeofday(&t7, NULL); + // time_t t7_ms = t7.tv_usec / 1000; + // printf("radardraw - cJSON_Delete(), ms Time = %f\n", difftime(t7_ms, t6_ms)); // 2022-11-02 time cost : 0 ~ 1 ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + // for testing + // cv::imwrite("/emmc/plugin/Aida_data/radar/radar_save.jpg", temp_img); // 2022-11-01 time cost : 0.02 ~ 0.1 s + + // g_radar_image_queue.push(temp_img.clone()); // 2022-11-01 time cost : 2 ~ 3x ms + // printf("g_radar_image_queue !!! push !!! size:%lu\n", g_radar_image_queue.size()); + + // // ------------------------------------- + // struct timeval t8; + // gettimeofday(&t8, NULL); + // time_t t8_ms = t8.tv_usec / 1000; + // printf("radardraw - g_radar_image_queue.push(temp_img.clone()), ms Time = %f\n", difftime(t8_ms, t7_ms)); // 2022-11-02 time cost : 2 ~ 2x ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + // temp_img.release(); // 0 ~ 4 ms + // printf("release temp image \n"); + + + // // ------------------------------------- + // struct timeval t9; + // gettimeofday(&t9, NULL); + // time_t t9_ms = t9.tv_usec / 1000; + // printf("radardraw - temp_img.release(), ms Time = %f\n", difftime(t9_ms, t8_ms)); // 2022-11-02 time cost : 0 ~ 1 ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + + // // 2022-11-01 time cost - start + // if (g_radar_image_queue.size() > 2) + // { + // for (int i = 0; i <= (int)g_radar_image_queue.size(); i++) + // { + // g_radar_image_queue.front().release(); + // g_radar_image_queue.pop(); + // // printf("radar image !!! pop #%d !!! suze:%lu\n", i, g_radar_image_queue.size()); + // } + // } + // // 2022-11-01 time cost - end : 0 ~ 1 ms + + + // // ------------------------------------- + // struct timeval t10; + // gettimeofday(&t10, NULL); + // time_t t10_ms = t10.tv_usec / 1000; + // printf("radardraw - if (g_radar_image_queue.size() > 2), ms Time = %f\n", difftime(t10_ms, t9_ms)); // 2022-11-02 time cost : 0 ~ 1 ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + } + + // struct timeval end; + // gettimeofday(&end, NULL); + // time_t end_msecs_time = end.tv_usec / 1000; + // double diff_tmp = difftime(end_msecs_time, t1_ms); + // if (diff_tmp > 0.0) + // { + // printf("radardraw - while loop, ms Time = %f\n", diff_tmp); + // printf("----------------------------------------\n"); + // } + } + + printf("thread_render_radar_img release start\n"); + + temp_img.release(); // 0 ~ 4 ms + bg.release(); + + printf("thread_render_radar_img release end\n"); + pthread_exit(NULL); +} + +void Reread_radarbg() +{ + printf("Reread_radarbg() start\n"); + bg = cv::imread(img_file); + + if (bg.empty()) + { + printf("read cv error\n"); + return; + } + // else + // { + // printf("image size %d\n", bg.cols); + // } + + // bg.size().width + // bg.size().height + + // printf("resize bg start\n"); + + float scale_bg = 1.0; + if ((g_radar_img_width / (float)bg.size().width) >= (g_radar_img_height / (float)bg.size().height)) + { + scale_bg = (g_radar_img_height / (float)bg.size().height); + } + else + { + scale_bg = (g_radar_img_width / (float)bg.size().width); + } + int n_width = (int)(bg.size().width * scale_bg); + int n_height = (int)(bg.size().height * scale_bg); + cv::resize(bg, bg, cv::Size(n_width, n_height), 0, 0, cv::INTER_CUBIC); + + cv::Mat bg2(cv::Size((int)g_radar_img_width, (int)g_radar_img_height), CV_16UC3, cv::Scalar(255, 255, 255)); + // printf("bg2 size (%d , %d) \n", n_width, n_height); // 481,600 + if ((g_radar_img_width / (float)bg.size().width) >= (g_radar_img_height / (float)bg.size().height)) + { + // printf("inside 1\n"); + // scale_bg = ((float) bg.size().height /g_radar_img_height); + cv::Rect roi_rect = cv::Rect((int)(((int)g_radar_img_width - n_width) / 2), 0, bg.size().width, bg.size().height); + bg.copyTo(bg2(roi_rect)); + bg = bg2.clone(); + } + else + { + // printf("inside 2\n"); + // scale_bg = ((float)bg.size().width/g_radar_img_width); + cv::Rect roi_rect = cv::Rect(0, (int)(((int)g_radar_img_height - n_height) / 2), bg.size().width, bg.size().height); + bg.copyTo(bg2(roi_rect)); + bg = bg2.clone(); + } + // printf("resize bg store\n"); + // cv::imwrite("/emmc/plugin/Aida_data/radar/radar_resize.jpg", bg); + + // cv::resize(bg, bg, cv::Size((int)g_radar_img_width, (int)g_radar_img_height), 0, 0, cv::INTER_LINEAR); + printf("Reread_radarbg() end\n"); +} + +void Reread_speedbg() +{ + pthread_mutex_lock(&mutex_speedbg); + speed_bg = cv::imread(speed_bg_path); + + if (speed_bg.empty()) + { + printf("read speed bg error\n"); + return; + } + // else + // { + // printf("image size %d\n", bg.cols); + // } + + // printf("resize bg start\n"); + + // int img_w = speed_bg.size().width; + // int img_h = speed_bg.size().height; + + // float scale_speed_bg = 1.0; + // if ((g_radar_img_width / (float)img_w) >= (g_radar_img_height / (float)img_h)) + // { + // scale_speed_bg = (g_radar_img_height / (float)img_h); + // } + // else + // { + // scale_speed_bg = (g_radar_img_width / (float)img_w); + // } + + // int n_width = (int)(img_w * scale_speed_bg); + // int n_height = (int)(img_h * scale_speed_bg); + + // cv::resize(speed_bg, speed_bg, cv::Size(n_width, n_height), 0, 0, cv::INTER_CUBIC); + // cv::Mat speed_bg2(cv::Size((int)g_radar_img_width, (int)g_radar_img_height), CV_16UC3, cv::Scalar(255, 255, 255)); + // // printf("speed_bg2 size (%d , %d) \n", n_width, n_height); + + // if ((g_radar_img_width / (float)img_w) >= (g_radar_img_height / (float)img_h)) + // { + // // printf("inside 1\n"); + // cv::Rect roi_rect = cv::Rect((int)(((int)g_radar_img_width - n_width) / 2), 0, img_w, img_h); + // speed_bg.copyTo(speed_bg2(roi_rect)); + // speed_bg = speed_bg2.clone(); + // } + // else + // { + // // printf("inside 2\n"); + // cv::Rect roi_rect = cv::Rect(0, (int)(((int)g_radar_img_height - n_height) / 2), img_w, img_h); + // speed_bg.copyTo(speed_bg2(roi_rect)); + // speed_bg = speed_bg2.clone(); + // } + + float scale_speed_bg = 1.0; + if ((g_radar_img_width / (float)speed_bg.size().width) >= (g_radar_img_height / (float)speed_bg.size().height)) + { + scale_speed_bg = (g_radar_img_height / (float)speed_bg.size().height); + } + else + { + scale_speed_bg = (g_radar_img_width / (float)speed_bg.size().width); + } + int n_width = (int)(speed_bg.size().width * scale_speed_bg); + int n_height = (int)(speed_bg.size().height * scale_speed_bg); + cv::resize(speed_bg, speed_bg, cv::Size(n_width, n_height), 0, 0, cv::INTER_CUBIC); + + cv::Mat speed_bg2(cv::Size((int)g_radar_img_width, (int)g_radar_img_height), CV_16UC3, cv::Scalar(255, 255, 255)); + // printf("speed_bg2 size (%d , %d) \n", n_width, n_height); // 481,600 + if ((g_radar_img_width / (float)speed_bg.size().width) >= (g_radar_img_height / (float)speed_bg.size().height)) + { + // printf("inside 1\n"); + // scale_speed_bg = ((float) bg.size().height /g_radar_img_height); + cv::Rect roi_rect = cv::Rect((int)(((int)g_radar_img_width - n_width) / 2), 0, speed_bg.size().width, speed_bg.size().height); + speed_bg.copyTo(speed_bg2(roi_rect)); + speed_bg = speed_bg2.clone(); + } + else + { + // printf("inside 2\n"); + // scale_speed_bg = ((float)bg.size().width/g_radar_img_width); + cv::Rect roi_rect = cv::Rect(0, (int)(((int)g_radar_img_height - n_height) / 2), speed_bg.size().width, speed_bg.size().height); + speed_bg.copyTo(speed_bg2(roi_rect)); + speed_bg = speed_bg2.clone(); + } + + printf("resize speed_bg store\n"); + cv::imwrite("/emmc/plugin/Aida_data/radar/speed_resize.jpg", speed_bg); + pthread_mutex_unlock(&mutex_speedbg); + +} + +/** + * @brief start the rendering + * @version 1.0 + * @property sig_radarrender_thread use in stop thread + */ +// void Thread_render_radar() +// { +// // snap +// /** +// * @brief anpr_index.html +// get_anpr +// Test nn control ->view +// comm /snap +// Pns.c +// resize 800x600 +// Pns.get_snapshot +// 80-8592 port +// Get_ori_c_image +// * +// */ +// Radar_init(); + +// sig_radarrender_thread = 1; +// // bg = cv::imread("/emmc/plugin/Aida_data/radar/radar_user.jpg"); + +// Reread_radarbg(); +// // bg = cv::imread(img_file); + +// // if (bg.empty()) + // // { +// // printf("read cv error\n"); +// // return; + // // } +// // // else +// // // { +// // // printf("image size %d\n", bg.cols); +// // // } + +// // cv::resize(bg, bg, cv::Size((int)g_radar_img_width, (int)g_radar_img_height), 0, 0, cv::INTER_LINEAR); + +// pthread_create(&radarrender, NULL, radardraw, NULL); +// pthread_detach(radarrender); +// } + +/** + * @brief Get the radar data object + * if queue is enable read radar meta data from queue. + * else return from global string + * + * @return char* for meta json string + */ +// char *get_radar_data() +// { +// pthread_mutex_lock(&mutex_radar); +// pthread_mutex_unlock(&mutex_radar); +// return global_message_for_radar_response; // queue + +// if (g_radar_queue.size() > 0) +// { +// char *res = g_radar_queue.front(); +// if (g_radar_queue.size() > 1) +// g_radar_queue.pop(); +// pthread_mutex_unlock(&mutex_radar); +// return res; +// } +// else +// { +// char *rs = "no radar data in queue\n"; +// pthread_mutex_unlock(&mutex_radar); +// return rs; +// } +// } + +/** + * @brief Get the radar image + * for fusion radar data on the background image + * read data from queue or global string + * @param img_addr ptr of image to retrieve + * @return unsigned long return image size + */ +unsigned long get_radar_image(char *img_addr) +{ +#ifndef GY_OS_RADAR_NO_SIGNAL + + int length = 0; + // if (g_radar_image_queue.size() > 0) + + if ( temp_img.cols>0 ) + { + // // cv::Mat image = g_radar_image_queue.front(); + // // cv::Mat image = temp_img; + + // // ------------------------------------- + // struct timeval t1; + // gettimeofday(&t1, NULL); + // time_t t1_ms = t1.tv_usec / 1000; + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + std::vector<uchar> data_encode; + // cv::imencode(".jpg", image, data_encode); + cv::imencode(".jpg", temp_img, data_encode); + std::string str_encode(data_encode.begin(), data_encode.end()); + + // // ------------------------------------- + // struct timeval t2; + // gettimeofday(&t2, NULL); + // time_t t2_ms = t2.tv_usec / 1000; + // printf("get_radar_image - imencode, ms Time = %f\n", difftime(t2_ms, t1_ms)); // 2022-11-02 time cost : 2x ~ 3x ms + // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + length = (int)str_encode.length(); + memcpy(img_addr, str_encode.c_str(), length); // 2022-11-01 time cost : 0.02 ~ 0.14 s + // image.release(); + } + else +#endif // !1 + { + length = (int)str_nosignal.length(); + if (length == 0) + { + Radar_init(); + } + memcpy(img_addr, str_nosignal.c_str(), length); + // printf("Empty get radar snap\n"); + } + + // printf("[radar.cpp] get_radar_image() - length: %d\n", length); + + return (unsigned long)length; +} + +/** + * @brief Get the background radar image + * only return background image not include radar data + * @param img_addr of image to retrieve + * @return unsigned long for image size + */ +unsigned long get_bg_radar_image(char *img_addr) +{ + if (bg.empty()) + { + Radar_init(); + bg = cv::imread(img_file); + } + + cv::Mat image = bg.clone(); + std::vector<uchar> data_encode; + cv::imencode(".jpg", image, data_encode); + std::string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + if (length == 0) + { + Radar_init(); + } + memcpy(img_addr, str_encode.c_str(), length); + return (unsigned long)length; +} + +unsigned long get_speed_bg_image(char *speed_img_addr) +{ + if (speed_bg.empty()) + { + Reread_speedbg(); + } + pthread_mutex_lock(&mutex_speedbg); + cv::Mat image = speed_bg.clone(); + pthread_mutex_unlock(&mutex_speedbg); + std::vector<uchar> data_encode; + cv::imencode(".jpg", image, data_encode); + std::string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + + memcpy(speed_img_addr, str_encode.c_str(), length); + return (unsigned long)length; +} + +/** + * @brief Get the nosignal image + * only return nosignal image + * @param img_addr of image to retrieve + * @return unsigned long for image size + */ +unsigned long get_nosignal_image(char *img_addr) +{ + char *nosignalpath = (char *)"/emmc/plugin/Aida_data/radar/radar_nosignal.png"; + // if (fileExists(nosignalpath)) + + cv::Mat image = cv::imread(nosignalpath); + if (image.empty()) + { + printf("read cv error\n"); + return 0; + } + std::vector<uchar> data_encode; + cv::imencode(".jpg", image, data_encode); + std::string str_encode(data_encode.begin(), data_encode.end()); + int length = (int)str_encode.length(); + + memcpy(img_addr, str_encode.c_str(), length); + return (unsigned long)length; +} + +/** + * @brief test_ptz + * + * + * + * + * + */ +// void test_ptz() +// { + +// // int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +// // GetRemotePTZCruPos("admin", "pass", "192.168.50.200", "80", p, t, z) +// // char *username = "admin"; +// // char *password = "pass"; +// // char *ip = "192.168.50.200"; +// // GetRemotePTZCruPos() +// char *p; +// char *t; +// char *z; +// int tmp; +// tmp = GetRemotePTZCruPos("admin", "pass", "192.168.50.200", "80", p, t, z); +// printf("p: %s, t: %s, z: %s\n", p, t, z); + +// // int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +// } + +#ifdef A113n_PTZ + +int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +{ + + char ptz_curl_url[512] = {0}; + char ptz_curl_sendbuf[1] = {0}; + char ptz_curl_username[128] = {0}; + char ptz_curl_password[128] = {0}; + + strcat(ptz_curl_url, "http://"); + strcat(ptz_curl_url, sIP); + + // set p + strcat(ptz_curl_url, "/control?panposdegree="); + strcat(ptz_curl_url, p); + + // set t + strcat(ptz_curl_url, "&tiltposdegree="); + strcat(ptz_curl_url, t); + + // set z + strcat(ptz_curl_url, "&zoomposdegree="); + strcat(ptz_curl_url, z); + + strcat(ptz_curl_username, sUsername); + strcat(ptz_curl_password, sPassword); + + char outputData[1024]; + char *arr_sOutputDataList[MAX_PTZ_INFO]; + // int iPTZInfoCount = 0; + int curl_ret = -1; + + printf("[Update Remote PTZ]: url = %s\n", ptz_curl_url); + curl_ret = net_curl_http_get(ptz_curl_url, 1, ptz_curl_username, ptz_curl_password, 60, outputData, 1024); + // printf("curl_ret after net curl ptz cmd = %d\n", curl_ret); + + return curl_ret; +} + +int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +{ + int cam_version = 0; + int curl_ret = -1; + char ptz_curl_url[512] = {0}; + char ptz_curl_sendbuf[1] = {0}; + char ptz_curl_username[128] = {0}; + char ptz_curl_password[128] = {0}; + char *method = "GET"; + + strcat(ptz_curl_url, "http://"); + strcat(ptz_curl_url, sIP); + strcat(ptz_curl_url, ":"); + strcat(ptz_curl_url, sPort); + + strcat(ptz_curl_username, sUsername); + strcat(ptz_curl_password, sPassword); + + char outputData[1024] = {0}; + char ptz_server[512] = {0}; + + strcat(ptz_server, "http://"); + strcat(ptz_server, sIP); + strcat(ptz_server, ":"); + strcat(ptz_server, sPort); + strcat(ptz_server, "/server"); + + // printf("[Remote PTZ]: url = %s\n", ptz_server); + + curl_ret = net_curl_http_get(ptz_server, 1, ptz_curl_username, ptz_curl_password, 60, outputData, 1024); + + char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; + // int iPTZInfoCount = 0; + int iGetValue = 0; + + if (strlen(outputData) > 0) // check version + { + // printf("getcurpos=%s \n", outputData); + // iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); + int split_num = StrSplit(outputData, arr_sOutputDataList, "\n"); + // printf("[Remote PTZ strsplit] num = %d\n", split_num); + char arr_sOutputDataSplit[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; + + for (int i = 0; i < split_num; i++) + { + if (strstr(arr_sOutputDataList[i], "Software Version")) + { + // printf("[Get pos] string = %s\n", arr_sOutputDataList[i]); + + // compare the version if <3.0 + + StrSplit(arr_sOutputDataList[i], arr_sOutputDataSplit, "="); + + // printf("[Get pos]: = split = [%s]\n", arr_sOutputDataSplit[1]); + + cam_version = atoi(arr_sOutputDataSplit[1]); // atof if floating point is needed. Remember to change cam_version to float above + // printf("version = %d\n", cam_version); + + if (cam_version < 3) + { + strcat(ptz_curl_url, "/control?cmd=getallposdegree"); + } + else + { + strcat(ptz_curl_url, "/control?getcurpos=1"); + } + + break; + } + } + } + + // get pos + memset(outputData, 0, 1024); + // printf("[Remote PTZ]: url = %s\n", ptz_curl_url); + + curl_ret = net_curl_http_get(ptz_curl_url, 1, ptz_curl_username, ptz_curl_password, 60, outputData, 1024); + + // printf("[Remote get PTZ pos] outputData = %s\n", outputData); + + if (cam_version < 3) + { + int split_num = StrSplit(outputData, arr_sOutputDataList, "\n"); + // printf("[Remote PTZ strsplit] num = %d\n", split_num); + + char temp[10][STRSPLIT_SIZE]={0}; + // printf("before strsplit\n"); + StrSplit(arr_sOutputDataList[0], temp, "="); + // printf("[PTZ pos split] p= %s\n", temp[1]); + strcpy(p, temp[1]); + StrSplit(arr_sOutputDataList[1], temp, "="); + // printf("[PTZ pos split] t= %s\n", temp[1]); + strcpy(t, temp[1]); + StrSplit(arr_sOutputDataList[2], temp, "="); + // printf("[PTZ pos split] z= %s\n", temp[1]); + strcpy(z, temp[1]); + } + else + { + int split_num = StrSplit(outputData, arr_sOutputDataList, ","); + // printf("[Remote PTZ strsplit] num = %d\n", split_num); + + strcpy(p, arr_sOutputDataList[0]); + strcpy(t, arr_sOutputDataList[1]); + strcpy(z, arr_sOutputDataList[2]); + + // printf("[PTZ] = [%s, %s, %s]\n", p, t, z); + } + + return curl_ret; +} + +#endif + +/** + * @brief test_ptz + * + * + * + * + * + */ +// void test_ptz() +// { + +// // int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +// // GetRemotePTZCruPos("admin", "pass", "192.168.50.200", "80", p, t, z) +// // char *username = "admin"; +// // char *password = "pass"; +// // char *ip = "192.168.50.200"; +// // GetRemotePTZCruPos() +// char *p; +// char *t; +// char *z; +// int tmp; +// tmp = GetRemotePTZCruPos("admin", "pass", "192.168.50.200", "80", p, t, z); +// printf("p: %s, t: %s, z: %s\n", p, t, z); + +// // int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +// } diff --git a/src/radar.h b/src/radar.h new file mode 100644 index 0000000..1f278e0 --- /dev/null +++ b/src/radar.h @@ -0,0 +1,51 @@ +#ifndef RADAR +#define RADAR + +#include "define_inc.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + // void Thread_receive_radar_to_amb(); + // void radar_meta_thread_stop(); + void radar_render_thread_stop(); + + char *radar_bg_path(); + // void Thread_render_radar(); + void *thread_render_radar_img(void *ptr); + void Radar_init(); + unsigned long get_radar_image(char *img_addr); + unsigned long get_speed_bg_image(char *speed_img_addr); + unsigned long get_bg_radar_image(char *img_addr); + unsigned long get_nosignal_image(char *img_addr); + // char *get_radar_data(); + + void Reread_radarbg(); + void Reread_speedbg(); + +#ifdef __cplusplus +} +#endif + +#endif + +#include "setting.h" + +extern int json_radar_x_axis; +extern int json_radar_y_axis; +extern int json_target_x_axis; +extern int json_target_y_axis; +extern int json_radar_section_degree; + +extern pthread_mutex_t mutex_get_image; +extern pthread_mutex_t mutex_web; +extern pthread_mutex_t mutex_speedbg; + +extern int g_switch_radar_data_json; +extern char global_radar_response[BUFSIZE_V3]; +extern char g_radar_data_json[BUFSIZE_V3]; +extern int g_IsRadarFake; +// Ken 10-28 +extern float g_radar_img_width; +extern float g_radar_img_height; \ No newline at end of file diff --git a/src/radar_driver.c b/src/radar_driver.c new file mode 100644 index 0000000..2aa0c0c --- /dev/null +++ b/src/radar_driver.c @@ -0,0 +1,1443 @@ + +#include "radar_driver.h" +#include "dbscan.c" // Ken 2022-10-24 +#include "radar_parser.h" +#include "cryptionPlus.h" + +char g_stream_state_response[256] = {0}; +radarconvert union_radar_convert; + +RadarServiceInfo radar_service_data; +RadarDataInfo radar_data_array[MAX_SIZE_RADAR_DATA] = {0}; + +RadarDataInfo world_radar_data_array[MAX_SIZE_RADAR_DATA] = {0}; // leo 09-29 +int g_current_radar_data_index = 0; + +int g_check_if_radar_start = 0; +int g_check_if_is_correct_ttype = 0; + +int g_switch_radar_data_json = 0; +char g_radar_data_json[BUFSIZE_V3] = {0}; +#ifdef RADAR_LOG +int start_radar_log_header = 1; // 10-19 leo +int radar_log = 0; // 10-19 leo +char radar_csv_name[128]; +#endif // DEBUG + +// 10-24 Ken DBSCAN param +int radar_dbscan = 0; +int radar_type_1_points_num = 0; +double epsilon = 2; +unsigned int minpts = 1; +point_t *points = NULL; + +int g_old_magic_num; + +void run_general_ttype(char *buffer_stream, int buffer_size) +{ + printf(">>>>>>>>>>>>>>>>>>>>>>>> run_general_ttype_P :%d, %d\n", buffer_size, (READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P)); + printf(">>>>>>>>>>>>>>>>>>>>>>>> type = %ld \n", radar_data_array[g_current_radar_data_index].ttype); + printf(">>>>>>>>>>>>>>>>>>>>>>>> [%d] TLVLen = %ld - %ld\n", g_current_radar_data_index, radar_data_array[g_current_radar_data_index].TLVLength, radar_service_data.totalPacketLen); + if (buffer_size >= READ_OBJ_AND_VUNIT * INT_BYTE_SIZE && + radar_data_array[g_current_radar_data_index].ttype >= 1 && + radar_data_array[g_current_radar_data_index].ttype <= 3 && + // radar_data_array[g_current_radar_data_index].ttype <= 4 && + radar_data_array[g_current_radar_data_index].TLVLength < radar_service_data.totalPacketLen && + radar_data_array[g_current_radar_data_index].TLVLength >= 1) + { + int objs = 0; + float vUnit = 0.0; + + for (int i = 0; i < READ_OBJ_AND_VUNIT; i++) + { + memcpy(union_radar_convert.hexarray, (unsigned char *)buffer_stream + i * 2, 2); + if (i == 0) + objs = (int)union_radar_convert.int16; + else if (i == 1) + vUnit = 1.0 / (float)pow(2.0, (double)(int)union_radar_convert.int16); + } + printf("\n--objs:%d,vunit:%f\n", objs, vUnit); + + //printf("-------------------------------------------------------- radar objs: %d \n", objs); + + radar_type_1_points_num = 0; // 10-24 Ken + // printf("radar_type_1_points_num : %d\n", radar_type_1_points_num); + + if (objs >= 1 && vUnit > 0.0) + { + int ori_g_current_radar_data_index = g_current_radar_data_index; + + if (radar_data_array[g_current_radar_data_index].ttype == 1) + { + if (buffer_size == (READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + objs * TTYPE_1_OBJ_FORMAT_SIZE * INT_BYTE_SIZE)) + { + + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index != ori_g_current_radar_data_index) + { + radar_data_array[g_current_radar_data_index].ttype = radar_data_array[ori_g_current_radar_data_index].ttype; + radar_data_array[g_current_radar_data_index].TLVLength = radar_data_array[ori_g_current_radar_data_index].TLVLength; + } + + float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; // for V1 + // float ccX = 0.0, ccY = 0.0, csX = 0.0, csY = 0.0; //for V2 + // float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; //for V3 + + for (int j = 0; j < TTYPE_1_OBJ_FORMAT_SIZE; j++) + { + memcpy(union_radar_convert.hexarray, (unsigned char *)buffer_stream + READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + i * TTYPE_1_OBJ_FORMAT_SIZE + j * 2, 2); + if (j == 0) + doppler = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 1) + PeakValue = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 2) + X = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 3) + Y = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 4) + Z = vUnit * (float)(int)union_radar_convert.int16; + } + + // printf("\n---value:%f,%f,%f,%f,%f\n", doppler, PeakValue, X, Y, Z); + + radar_data_array[g_current_radar_data_index].doppler = doppler; + radar_data_array[g_current_radar_data_index].PeakValue = PeakValue; + radar_data_array[g_current_radar_data_index].X = X; + radar_data_array[g_current_radar_data_index].Y = Y; + radar_data_array[g_current_radar_data_index].Z = Z; + + g_current_radar_data_index++; + radar_type_1_points_num++; + // printf("--- radar_type_1_points_num : %d\n", radar_type_1_points_num); + } + } + } + else if (radar_data_array[g_current_radar_data_index].ttype == 2) + { + + if (buffer_size == (READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + objs * TTYPE_2_OBJ_FORMAT_SIZE * INT_BYTE_SIZE)) + { + + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index != ori_g_current_radar_data_index) + { + radar_data_array[g_current_radar_data_index].ttype = radar_data_array[ori_g_current_radar_data_index].ttype; + radar_data_array[g_current_radar_data_index].TLVLength = radar_data_array[ori_g_current_radar_data_index].TLVLength; + } + + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + float ccX = 0.0, ccY = 0.0, csX = 0.0, csY = 0.0; // for V2 + // float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; //for V3 + + for (int j = 0; j < TTYPE_2_OBJ_FORMAT_SIZE; j++) + { + memcpy(union_radar_convert.hexarray, (unsigned char *)buffer_stream + READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + i * TTYPE_2_OBJ_FORMAT_SIZE + j * 2, 2); + if (j == 0) + ccX = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 1) + ccY = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 2) + csX = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 3) + csY = vUnit * (float)(int)union_radar_convert.int16; + } + + // printf("\n---value:%f,%f,%f,%f\n", ccX, ccY, csX, csY); + + radar_data_array[g_current_radar_data_index].ccX = ccX; + radar_data_array[g_current_radar_data_index].ccY = ccY; + radar_data_array[g_current_radar_data_index].csX = csX; + radar_data_array[g_current_radar_data_index].csY = csY; + + g_current_radar_data_index++; + } + } + } + else if (radar_data_array[g_current_radar_data_index].ttype == 3) + { + if (buffer_size == (READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + objs * TTYPE_3_OBJ_FORMAT_SIZE * INT_BYTE_SIZE)) + { + + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index != ori_g_current_radar_data_index) + { + radar_data_array[g_current_radar_data_index].ttype = radar_data_array[ori_g_current_radar_data_index].ttype; + radar_data_array[g_current_radar_data_index].TLVLength = radar_data_array[ori_g_current_radar_data_index].TLVLength; + } + + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + /*/float ccX = 0.0, ccY = 0.0,*/ float csX = 0.0, csY = 0.0; // for V2 + float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; // for V3 + + for (int j = 0; j < TTYPE_3_OBJ_FORMAT_SIZE; j++) + { + memcpy(union_radar_convert.hexarray, (unsigned char *)buffer_stream + READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + i * TTYPE_3_OBJ_FORMAT_SIZE + j * 2, 2); + if (j == 0) + tX = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 1) + tY = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 2) + velX = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 3) + velY = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 4) + csX = vUnit * (float)(int)union_radar_convert.int16; + else if (j == 5) + csY = vUnit * (float)(int)union_radar_convert.int16; + } + + // printf("\n---value:%f,%f,%f,%f,%f,%f\n", tX, tY, velX, velY, csX,csY); + + radar_data_array[g_current_radar_data_index].tX = tX; + radar_data_array[g_current_radar_data_index].tY = tY; + radar_data_array[g_current_radar_data_index].velX = velX; + radar_data_array[g_current_radar_data_index].velY = velY; + radar_data_array[g_current_radar_data_index].csX = csX; + radar_data_array[g_current_radar_data_index].csY = csY; + + if (tX != 0 && tY != 0) + radar_data_array[g_current_radar_data_index].Speed = ((tX * velX + tY * velY) / sqrt((tX * tX + tY * tY))) * 3.6; + + g_current_radar_data_index++; + } + } + } +#if 0 + else if (radar_data_array[g_current_radar_data_index].ttype == 4) { + if (buffer_size == (READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + objs * TTYPE_4_OBJ_FORMAT_SIZE * INT_BYTE_SIZE)) { + + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index != ori_g_current_radar_data_index) { + radar_data_array[g_current_radar_data_index].ttype = radar_data_array[ori_g_current_radar_data_index].ttype; + radar_data_array[g_current_radar_data_index].TLVLength = radar_data_array[ori_g_current_radar_data_index].TLVLength; + } + + for (int j = 0; j < TTYPE_4_OBJ_FORMAT_SIZE; j++) { + memcpy(union_radar_convert.hexarray, (unsigned char*)buffer_stream + READ_OBJ_AND_VUNIT * INT_BYTE_SIZE + i * TTYPE_4_OBJ_FORMAT_SIZE + j * 2, 2); + //printf("\n----ast[%d] = %d\n", i, union_radar_convert.int16); + } + + g_current_radar_data_index++; + } + } + } +#endif + +#if 1 // leo 09-29 + if (g_current_radar_data_index >= 1) + { + // Ken 10-24 DBSCAN + if (radar_data_array[g_current_radar_data_index-1].ttype == 1 && radar_dbscan == 0) + { + // printf("run_general_ttype - g_current_radar_data_index>=1, if type ==1, if (radar_dbscan == 0)\n"); + points = (point_t *)calloc(radar_type_1_points_num, sizeof(point_t)); + + for (int j = 0; j < g_current_radar_data_index; j++) + { + points[j].x = radar_data_array[j].X; + points[j].y = radar_data_array[j].Y; + points[j].z = radar_data_array[j].Z; + points[j].cluster_id = UNCLASSIFIED; + points[j].nop = 1; + } + + // printf("=== DBSCAN Settings ===\n"); + // printf("Epsilon: %lf\n", epsilon); + // printf("Minimum points: %u\n", minpts); + dbscan(points, radar_type_1_points_num, epsilon, minpts, euclidean_dist); + + // printf("=== update nop START ===\n"); + // TODO update nop ( number of cluster points ) + int max_cluster_id = 0; + + for (int j = 0; j < g_current_radar_data_index; j++) + { + if (points[j].cluster_id > max_cluster_id) + { + max_cluster_id = points[j].cluster_id; + } + } + + for (int cluster_id_index = 0; cluster_id_index <= max_cluster_id; cluster_id_index++) + { + int counter = 0; + for (int j = 0; j < g_current_radar_data_index; j++) + { + if (points[j].cluster_id == cluster_id_index) + { + ++counter; + } + } + + for (int j = 0; j < g_current_radar_data_index; j++) + { + if (points[j].cluster_id == cluster_id_index) + { + points[j].nop = counter; + } + // printf("points[%d].cluster_id : %d, .nop : %d\n", j, points[j].cluster_id, points[j].nop); + } + } + // printf("=== update nop END ===\n"); + + radar_dbscan = 1; + } + + for (int i = 0; i < g_current_radar_data_index; i++) + { + radar_axis_covert_world(&radar_data_array[i], &world_radar_data_array[i]); + + // printf("Type %ld origin(x,y): (%f,%f) transfer(x,y): (%f,%f) \n", temp_current_radar_list[i].ttype, temp_current_radar_list[i].X, temp_current_radar_list[i].Y, g_current_radar_list[i].X, g_current_radar_list[i].Y); + } + } +#endif + } + } +} + +int Is_radar_data_empty(char *buffer_stream, int buffer_size) +{ + char temp_char = buffer_stream[0]; + int ret = 0; + + for (int i = 1; i < buffer_size; i++) + { + if (buffer_stream[i] != temp_char) + break; + else if (i == buffer_size - 1) + { + ret = 1; + } + } + return ret; +} + +int Is_correct_ttype(char *buffer_stream, int buffer_size) +{ + int ret = 0; + if (buffer_size == MAX_SIZE_LILIN_TTYPE * 4) // if buffer_size = 8 byte + { + + long temp_ttype = 0; + long temp_TLVLength = 0; + + for (int i = 0; i < MAX_SIZE_LILIN_TTYPE; i++) + { + memcpy(union_radar_convert.hexarray, (unsigned char *)buffer_stream + i * 4, 4); + if (i == 0) + temp_ttype = (long)union_radar_convert.int32; + else if (i == 1) + temp_TLVLength = (long)union_radar_convert.int32; + } + + if (temp_ttype >= 1 && temp_ttype <= 4 && temp_TLVLength < radar_service_data.totalPacketLen && temp_TLVLength >= 1) + { + radar_data_array[g_current_radar_data_index].ttype = temp_ttype; + radar_data_array[g_current_radar_data_index].TLVLength = temp_TLVLength; + + ret = 1; + } + } + return ret; +} + +// 2022-10-26 Ken +int rule_based_classifier(point_t *p, int p_ind, float doppler, int class_id) +{ + // GYNet_Radar_Tiny_Label: + // 0 : person + // 1 : bicycle + // 2 : car + // 3 : motorbike + // 4 : _s + // 5 : bus + // 6 : _s + // 7 : truck + + float speed = -doppler*3600.0/1000.0; + + float distance = euclidean_dist_to_op(&p[p_ind]); + + int nop = p[p_ind].nop; + + // rules + if (speed >= 82.8) + { + class_id = -1; + } + else if (distance < 40 && distance >= 1 && nop <= 15 && nop >= 1) + { + class_id = 0; // person + } + // ... + + + // printf("--- p_ind: %d, distance:%f, speed:%f, class_id:%f\n", p_ind, distance, speed, class_id); + + + return class_id; +} + +void build_radar_data_json() +{ + FILE *fp = NULL; +#ifdef RADAR_LOG + // 10-19 leo + if (start_radar_log_header == 1 && radar_log == 1) + { + start_radar_log_header = 0; + time_t t = time(NULL); + struct tm tm = *localtime(&t); + printf("now: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + + sprintf(radar_csv_name, "/emmc/plugin/Aida_data/radar/radar_log_%d%02d%02d_%02d%02d.csv", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min); + printf("%s\n", radar_csv_name); + fp = fopen(radar_csv_name, "w+"); + if (fp == NULL) + { + fprintf(stderr, "fopen() failed.\n"); + radar_log = 0; + } + // fprintf(fp, "FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak\n"); + fprintf(fp, "FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak, cluster_id\n"); + } + else if (start_radar_log_header == 0 && radar_log == 1) + { + fp = fopen(radar_csv_name, "a"); + if (fp == NULL) + { + fprintf(stderr, "fopen() failed.\n"); + radar_log = 0; + } + } +#endif // RADAR_LOG + cJSON *root = NULL; + cJSON *AiRadar, *detectArrayRadar, *detectRadar; + + /* + cJSON *FrameNum, *tid, *posX, *posY, *posZ, *velX, *velY, *velZ, + *accX, *accY, *accZ, *ccX, *ccY, *csX, *csY, *tX, *tY, *Doppler; + */ + + root = cJSON_CreateObject(); + + AiRadar = cJSON_CreateObject(); + cJSON_AddItemToObject(root, "AiRadar", AiRadar); + + time_t current_time = time(0); + char c_current_time[20] = {0}; + sprintf(c_current_time, "%ld", current_time); + cJSON_AddItemToObject(AiRadar, "Time", cJSON_CreateString(c_current_time)); + + char c_framenum[20] = {0}; + sprintf(c_framenum, "%ld", radar_service_data.frameNumber); + cJSON_AddItemToObject(AiRadar, "FrameNum", cJSON_CreateString(c_framenum)); + + char c_radar_x_axis[20] = {0}; + sprintf(c_radar_x_axis, "%d", json_radar_x_axis); + cJSON_AddItemToObject(AiRadar, "radar_x_axis", cJSON_CreateString(c_radar_x_axis)); + + char c_radar_y_axis[20] = {0}; + sprintf(c_radar_y_axis, "%d", json_radar_y_axis); + cJSON_AddItemToObject(AiRadar, "radar_y_axis", cJSON_CreateString(c_radar_y_axis)); + + char c_target_x_axis[20] = {0}; + sprintf(c_target_x_axis, "%d", json_target_x_axis); + cJSON_AddItemToObject(AiRadar, "target_x_axis", cJSON_CreateString(c_target_x_axis)); + + char c_target_y_axis[20] = {0}; + sprintf(c_target_y_axis, "%d", json_target_y_axis); + cJSON_AddItemToObject(AiRadar, "target_y_axis", cJSON_CreateString(c_target_y_axis)); + + char c_distance_meter[20] = {0}; + sprintf(c_distance_meter, "%d", json_distance_meter); + cJSON_AddItemToObject(AiRadar, "distance_meter", cJSON_CreateString(c_distance_meter)); + + char c_distance_meter_y[20] = {0}; + sprintf(c_distance_meter_y, "%d", json_distance_meter_y); + cJSON_AddItemToObject(AiRadar, "distance_meter_y", cJSON_CreateString(c_distance_meter_y)); + + detectArrayRadar = cJSON_CreateArray(); + cJSON_AddItemToObject(AiRadar, "RadarArray", detectArrayRadar); + + for (int i = 0; i < g_current_radar_data_index; i++) + { + // printf("build_radar_data_json - g_current_radar_data_index : %d, V%ld point\n", i, radar_data_array[i].ttype); + + detectRadar = cJSON_CreateObject(); + cJSON_AddItemToArray(detectArrayRadar, detectRadar); + + char c_tid[10] = {0}; + sprintf(c_tid, "%d", i); + cJSON_AddItemToObject(detectRadar, "tid", cJSON_CreateString(c_tid)); + + char c_ttype[10] = {0}; + sprintf(c_ttype, "%ld", radar_data_array[i].ttype); + cJSON_AddItemToObject(detectRadar, "Type", cJSON_CreateString(c_ttype)); + + if (radar_data_array[i].ttype == 1) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", radar_data_array[i].X); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", radar_data_array[i].Y); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + char c_posZ[20] = {0}; + sprintf(c_posZ, "%f", radar_data_array[i].Z); + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString(c_posZ)); + + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + + char c_doppler[20] = {0}; + sprintf(c_doppler, "%f", radar_data_array[i].doppler); + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString(c_doppler)); + + char c_PeakValue[20] = {0}; + sprintf(c_PeakValue, "%f", radar_data_array[i].PeakValue); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString(c_PeakValue)); + + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)world_radar_data_array[i].X); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> x: %d \n", (int)world_radar_data_array[i].X); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)world_radar_data_array[i].Y); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (world_radar_data_array[i].X >= 0 && world_radar_data_array[i].X < RADAR_BG_WIDTH) + { + if (world_radar_data_array[i].Y >= 0 && world_radar_data_array[i].Y < RADAR_BG_HEIGHT) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#ifdef RADAR_LOG + if (radar_log == 1) + { // 10-19 leo + // fprintf(fp, "%s,%s,%s,%s,%s,,,,,%s,%s\n", c_framenum, c_ttype, c_posX, c_posY, c_posZ, c_doppler, c_PeakValue); //"FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak + fprintf(fp, "%s,%s,%s,%s,%s,,,,,%s,%s,%d\n", c_framenum, c_ttype, c_posX, c_posY, c_posZ, c_doppler, c_PeakValue, points[i].cluster_id); //"FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak, cluster_id + } +#endif // RADAR_LOG +#endif + // 10-26 pass class_id to client + int class_id = -1; // default : not object + + // 10-25 Ken apply DBSCAN algorithm + if (radar_dbscan == 1) + { + class_id = rule_based_classifier(points, i, radar_data_array[i].doppler, class_id); + + // printf("V1 DBSCAN - X:%5lf, Y:%5lf, Z:%5lf, cluster_id: %d, class_id: %d\n\n", points[i].x, points[i].y, points[i].z, points[i].cluster_id, class_id); + } + + cJSON_AddItemToObject(detectRadar, "class_id", cJSON_CreateNumber(class_id)); + } + else if (radar_data_array[i].ttype == 2) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", radar_data_array[i].ccX); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", radar_data_array[i].ccY); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString(c_posX)); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString(c_posY)); + + char c_csX[20] = {0}; + sprintf(c_csX, "%f", radar_data_array[i].csX); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + + char c_csY[20] = {0}; + sprintf(c_csY, "%f", radar_data_array[i].csY); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)world_radar_data_array[i].ccX); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)world_radar_data_array[i].ccY); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (world_radar_data_array[i].ccX >= 0 && world_radar_data_array[i].ccX < RADAR_BG_WIDTH) + { + if (world_radar_data_array[i].ccY >= 0 && world_radar_data_array[i].ccY < RADAR_BG_HEIGHT) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#ifdef RADAR_LOG + if (radar_log == 1) + { // 10-19 leo + // fprintf(fp, "%s,%s,%s,%s,,,,%s,%s,,\n", c_framenum, c_ttype, c_posX, c_posY, c_csX, c_csY); //"FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak + fprintf(fp, "%s,%s,%s,%s,,,,%s,%s,,,\n", c_framenum, c_ttype, c_posX, c_posY, c_csX, c_csY); //"FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak, cluster_id + } +#endif +#endif + cJSON_AddItemToObject(detectRadar, "class_id", cJSON_CreateNumber(-2)); + } + else if (radar_data_array[i].ttype == 3) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", radar_data_array[i].tX); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", radar_data_array[i].tY); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + + char c_velX[20] = {0}; + sprintf(c_velX, "%f", radar_data_array[i].velX); + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString(c_velX)); + + char c_velY[20] = {0}; + sprintf(c_velY, "%f", radar_data_array[i].velY); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString(c_velY)); + + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + + char c_csX[20] = {0}; + sprintf(c_csX, "%f", radar_data_array[i].csX); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + + char c_csY[20] = {0}; + sprintf(c_csY, "%f", radar_data_array[i].csY); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + + char c_tX[20] = {0}; + sprintf(c_tX, "%f", radar_data_array[i].tX); + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString(c_tX)); + + char c_tY[20] = {0}; + sprintf(c_tY, "%f", radar_data_array[i].tY); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString(c_tY)); + + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + + char c_Speed[20] = {0}; + sprintf(c_Speed, "%f", radar_data_array[i].Speed); + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString(c_Speed)); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)world_radar_data_array[i].tX); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)world_radar_data_array[i].tY); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (world_radar_data_array[i].tX >= 0 && world_radar_data_array[i].tX < RADAR_BG_WIDTH) + { + if (world_radar_data_array[i].tY >= 0 && world_radar_data_array[i].tY < RADAR_BG_HEIGHT) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#ifdef RADAR_LOG + if (radar_log == 1) + { // 10-19 leo + // fprintf(fp, "%s,%s,%s,%s,,%s,%s,%s,%s,,\n", c_framenum, c_ttype, c_posX, c_posY, c_velX, c_velY, c_csX, c_csY); //"FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak + fprintf(fp, "%s,%s,%s,%s,,%s,%s,%s,%s,,,\n", c_framenum, c_ttype, c_posX, c_posY, c_velX, c_velY, c_csX, c_csY); //"FrameNum, Type, PosX, PosY, PosZ, velX, velY, csX, csY, Doppler, Peak, cluster_id + } +#endif +#endif + cJSON_AddItemToObject(detectRadar, "class_id", cJSON_CreateNumber(-3)); + } + } +#ifdef RADAR_LOG + + if(fp) + { // 10-19 leo + fclose(fp); + fp = NULL; + } +#endif + char *JsonString = NULL; + + if (root) + { + JsonString = cJSON_PrintUnformatted(root); + + if (g_switch_radar_data_json == 0) + { + strcpy(g_radar_data_json, JsonString); + // printf("\nradar_driver - g_radar_data_json:%s\n", g_radar_data_json); + g_switch_radar_data_json = 1; + } + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (root) + { + cJSON_Delete(root); + root = NULL; + } + + // 10-25 Ken + if (radar_dbscan == 1) + { + free(points); + radar_dbscan = 0; + } + // printf("---------------- build_radar_data_json end\n"); +} + +int radar_start_status(char *buffer_stream, int buffer_size) +{ + int ret = 0; + if (buffer_size >= LILIN_SHIFT) + { + if (buffer_stream[0] == 0x01 && + buffer_stream[1] == 0x02 && + buffer_stream[2] == 0x03 && + buffer_stream[3] == 0x04 && + buffer_stream[4] == 0x05 && + buffer_stream[5] == 0x06 && + buffer_stream[6] == 0x07 && + buffer_stream[7] == 0x08) + { + // printf("magic num: %d-%d-%d-%d-%d-%d-%d-%d \n", buffer_stream[0], buffer_stream[1], buffer_stream[2], buffer_stream[3], buffer_stream[4], buffer_stream[5], buffer_stream[6], buffer_stream[7]); + + if (g_current_radar_data_index >= 1) + { + build_radar_data_json(); + } + + memset(&radar_service_data, 0x00, sizeof(RadarServiceInfo)); + memset(&radar_data_array, 0x00, MAX_SIZE_RADAR_DATA * sizeof(RadarDataInfo)); + g_current_radar_data_index = 0; + + if (buffer_size == LILIN_SHIFT + MAX_SIZE_LILIN_START * 4) //=40 =header + { + // printf("\n-------radar start status\n"); + for (int i = 0; i < MAX_SIZE_LILIN_START; i++) + { + memcpy(union_radar_convert.hexarray, (unsigned char *)buffer_stream + LILIN_SHIFT + i * 4, 4); + if (i == 0) + radar_service_data.version = (long)union_radar_convert.int32; + else if (i == 1) + radar_service_data.totalPacketLen = (long)union_radar_convert.int32; + else if (i == 2) + radar_service_data.platform = (long)union_radar_convert.int32; + else if (i == 3) + radar_service_data.frameNumber = (long)union_radar_convert.int32; + else if (i == 4) + radar_service_data.cpuProcessTime = (long)union_radar_convert.int32; + else if (i == 5) + radar_service_data.numOBJs = (long)union_radar_convert.int32; + else if (i == 6) + radar_service_data.numTLVs = (long)union_radar_convert.int32; + else if (i == 7) + radar_service_data.subFrameNumber = (long)union_radar_convert.int32; + } + + /* + printf("\n----version:%ld\n", radar_service_data.version); + printf("\n----totalPacketLen:%ld\n", radar_service_data.totalPacketLen); + printf("\n----platform:%ld\n", radar_service_data.platform); + printf("\n----frameNumber:%ld\n", radar_service_data.frameNumber); + printf("\n----cpuProcessTime:%ld\n", radar_service_data.cpuProcessTime); + printf("\n----numOBJs:%ld\n", radar_service_data.numOBJs); + printf("\n----numTLVs:%ld\n", radar_service_data.numTLVs); + printf("\n----subFrameNumber:%ld\n", radar_service_data.subFrameNumber);*/ + + // printf("\n----frameNumber:%ld\n", radar_service_data.frameNumber); + // printf("\n----subFrameNumber:%ld\n", radar_service_data.subFrameNumber); + // printf("\n----totalPacketLen:%ld\n", radar_service_data.totalPacketLen); + + // if (radar_service_data.frameNumber - g_old_magic_num > 1) + // printf("lose frame: [%d] -> [%d] \n", g_old_magic_num, radar_service_data.frameNumber); + + g_old_magic_num = radar_service_data.frameNumber; + } + + ret = 1; + } + else + { + // printf("magic num err: %d-%d-%d-%d-%d-%d-%d-%d \n", + // buffer_stream[0], buffer_stream[1], buffer_stream[2], buffer_stream[3], + // buffer_stream[4], buffer_stream[5], buffer_stream[6], buffer_stream[7]); + } + } + return ret; +} + +void getStream_b(int socketfd, int bSize) +{ + int nbytes; + //char buffer_stream[MAX_IMG_SIZE] = { 0 }; + char buffer[MAX_IMG_SIZE] = { 0 }; + // char boundary[256] = { 0 }; + + //int bodySize = 0; + // int content_length_image = 0; + // int strlen_ptr = 0; + // char *ptr_1, *ptr_2; + + //int ret = 0; + + + //while ((nbytes = recv(socketfd, buffer, bSize, 0)) > 0) + while (bHttpServerMainStart) + { + nbytes = recv(socketfd, buffer, bSize, 0); + + if (nbytes > 0) + { + //printf("================================\n"); + //printf("------- recv size = %d \n", nbytes); + //printf("%s \n", buffer); + radar_data_get(buffer, nbytes); + + // if (strstr(buffer, "--myboundary") != NULL) //LILIN package + //{ + // }//recv first package - LILIN package + // else + //{ + // + + // recv sec package - Radar package +#if 0 + if (content_length_image >= nbytes) + { + if (buffer[0] == 0xf && buffer[1] == 0xf && buffer[2] == 0xf) + printf("----recv end data\n"); + + + memcpy(buffer_stream + bodySize, buffer, content_length_image); + bodySize += nbytes; + content_length_image -= nbytes; + + if (content_length_image <= -1) + { + //this case should be drop + content_length_image = 0; + } + + if (content_length_image == 0) + { + ret = Is_radar_data_empty(buffer_stream, bodySize); + if (ret == 0) + { + //ret = radar_start_status(buffer_stream, bodySize); + //if (ret == 1) + //{ + + //} + + if (radar_start_status(buffer_stream, bodySize) == 1) //radar header + { + // printf("\n----------decode_stage #1: radar start status\n"); + g_check_if_radar_start = 1; + g_check_if_is_correct_ttype = 0; + } + else //radar data + { + if (g_check_if_radar_start == 1) + { + if (Is_correct_ttype(buffer_stream, bodySize) == 1) + { + // printf("\n----------decode_stage #2: find correct ttype\n"); + g_check_if_is_correct_ttype = 1; + } + else if (g_check_if_is_correct_ttype == 1) + { + + run_general_ttype(buffer_stream, bodySize); //radar_data_array ----> 取得並分析雷達資料 + // printf("\n----------decode_stage #3 #4: run general ttype\n"); + g_check_if_is_correct_ttype = 0; + } + else + { + // printf("\n----------decode_stage #0: incorrect format\n"); + g_check_if_radar_start = 0; + g_check_if_is_correct_ttype = 0; + } + } + } + }// if empty + else + { + //the end of radar data + //reset + + // printf("\n----------decode_stage #0: empty data\n"); + g_check_if_radar_start = 0; + g_check_if_is_correct_ttype = 0; + }// if empty + } + } + else if (nbytes > content_length_image) + { + //get size error, drop this frame data + //out case: 48 (40+8) + + } +#endif + //}//recv sec package + + // memset(buffer, 0, MAX_IMG_SIZE); + + usSleep(1); + } + } +} + +// static int current_profile_id = 1; +void getStream(int socketfd, int bSize) +{ + + // printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); + char buffer_stream[MAX_IMG_SIZE] = {0}; + char buffer[MAX_IMG_SIZE] = {0}; + size_t bReceived; + + bReceived = recv(socketfd, buffer, bSize, 0); + int bodySize = 0; + int content_length_image = 0; + + /*char *t = */removeHTTPHeader(buffer, &bodySize); + bodySize = 0; + + // if (strstr(buffer, "HTTP/1.1 200") != NULL && strstr(buffer, "encode=jpeg") != NULL && g_framesize_width >= 1 && g_framesize_height >= 1) + { + // bodySize = 0; + // if (content_length_image >= 1) + { + memset(buffer, 0, bSize); + bodySize = 0; + content_length_image = 0; + while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, bSize, 0)) > 0) + { + + // if (switch_g_image_buff_hd == 1) + { + memset(buffer_stream, 0x00, MAX_IMG_SIZE); + + // printf("\n-------------------------buffer:%s\n", buffer); + // printf("\n-------------------------bReceived:%d\n", bReceived); + + if (strstr(buffer, "--myboundary") != NULL) + { + char *ptr_1 = strstr(buffer, "Content-Length: "); + if (ptr_1) + { + char *ptr_2 = strstr(ptr_1, "Stamp"); + if (ptr_2) + { + int strlen_ptr = ptr_2 - ptr_1 - 16; //16 = "Content-Length: " + char boundary[256] = {0}; + if (strlen_ptr >= 1) + { + strncpy(boundary, ptr_1 + 16, strlen_ptr); + // printf("\n-----------boundary:%s\n", boundary); + content_length_image = atoi(boundary); + bodySize = 0; + // printf("\n-------------content_length_image:%d\n", content_length_image); + } + } + } + } + else + { + if (content_length_image >= 1) + { + memcpy(buffer_stream + bodySize, buffer, content_length_image); + bodySize += bReceived; + content_length_image -= bReceived; + + if (content_length_image <= -1) + { + bodySize += content_length_image; + content_length_image = 0; + } + + if (content_length_image == 0) + { + // printf("\n--------------getStream---TTT------bReceived:%d\n", bReceived); + // printf("\n-------------------buffer_stream#1:%s\n", buffer_stream); + + if (Is_radar_data_empty(buffer_stream, bodySize) == 0) // 0: not empty //data = 0x0f 0x0f 0x0f ..... + { + + if (radar_start_status(buffer_stream, bodySize) == 1) // is get radar header + { + // printf("\n----------decode_stage #1: radar start status\n"); + g_check_if_radar_start = 1; + g_check_if_is_correct_ttype = 0; + } + else + { + if (g_check_if_radar_start == 1) + { + if (Is_correct_ttype(buffer_stream, bodySize) == 1) + { + //printf("\n----------decode_stage #2: find correct ttype\n"); + g_check_if_is_correct_ttype = 1; // get 8byte data + } + else if (g_check_if_is_correct_ttype == 1) + { + + run_general_ttype(buffer_stream, bodySize); //radar_data_array ----> 取得並分析雷達資料 + // printf("\n----------decode_stage #3 #4: run general ttype\n"); + g_check_if_is_correct_ttype = 0; + } + else + { + // printf("\n----------decode_stage #0: incorrect format\n"); + g_check_if_radar_start = 0; + g_check_if_is_correct_ttype = 0; + } + } + } + } + else + { + // printf("\n----------decode_stage #0: empty data\n"); + g_check_if_radar_start = 0; + g_check_if_is_correct_ttype = 0; + } + + /* + else if (bodySize == LILIN_SHIFT + MAX_SIZE_LILIN_START * 4) { + + + }*/ + + /* + printf("\n---start---\n"); + for (int i = 0; i < bodySize; i++) { + printf("%x,", buffer_stream[i]); + } + printf("\n---end---\n");*/ + } + } + } + } + + memset(buffer, 0, bSize); + usSleep(1); + + /* + if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id) - 1)) + break;*/ + } + } + } + /* + else { + strcpy(g_stream_state_response, "Encoder: The profile name is not jpeg."); + }*/ + + // printf("\n------------bodySize:%d\n", bodySize); +} + +void get_stream_with_device() +{ + g_old_magic_num = 0; + + //int snapshot_size = 0; + + int status; + struct addrinfo host_info; + struct addrinfo *host_info_list = NULL; + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run thread_getstream CCC\n"); + memset(&host_info, 0, sizeof(host_info)); + + host_info.ai_family = AF_INET; // AF_UNSPEC + host_info.ai_socktype = SOCK_STREAM; + host_info.ai_protocol = 0; + + status = getaddrinfo("127.0.0.1", accountData[0].account_port, &host_info, &host_info_list); + if (status != 0) + { + printf("\ngetaddrinfo error\n"); + strcpy(g_stream_state_response, "Network problem: getaddrinfo error"); + } + else + { + + int socketfd = -1; + ; + // socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); + struct timeval timeout; + timeout.tv_sec = 3; // 3 + timeout.tv_usec = 0; + int tcpnodelay = 1; + int reuse = 1; + int qlen = 5; + + /* + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = PF_INET; + + //localhost test + info.sin_addr.s_addr = inet_addr("127.0.0.1"); + info.sin_port = htons(accountData[0].account_port); + //socket的建立 TCP_PORT_IMAGE + socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ + + int err = -1; + +#if 1 + struct addrinfo *rp; + for (rp = host_info_list; rp != NULL; rp = rp->ai_next) + { + + socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (socketfd == -1) + { + printf("\nsocket error\n"); + strcpy(g_stream_state_response, "Network problem: socket error"); + } + else + { + // printf("\n-------open getimage connected (%d)\n", socketfd); + + setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char *)&timeout, sizeof(timeout)); + setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)); + setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char *)&tcpnodelay, sizeof(tcpnodelay)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char *)&reuse, sizeof(reuse)); + setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char *)&qlen, sizeof(qlen)); + + if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) + { + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) + { + socketRecords[i].sock = socketfd; + + //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 3; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + // printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); + socketRecords[i].used = 1; + break; + } + else + { + if (i == MAX_CLIENT_SOCKET - 1) + { + close(socketfd); + // printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + } + } + } + + if (socketfd != -1) + { + break; + } + } + else + { + close(socketfd); + // printf("\n-------close getimage connected (%d)\n", socketfd); + socketfd = -1; + } + } + } +#endif + + if (socketfd >= 0) + { + char Authorization[2560] = {0}; + if (strlen(accountData[0].account_username) > 0) + { + //strcat(sendBuffer, "Authorization: Basic "); + char buf_account[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); + strcpy(Authorization, buf_account); + strcat(Authorization, ":"); + + if (strlen(accountData[0].account_password) > 0) { + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); + strcat(Authorization, buf_account2); + } + } + + size_t base64_encode_length = 0; + char httpAuth[2560] = {0}; + if (strlen(Authorization) >= 1) + { + + base64_encode((const unsigned char *)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); + httpAuth[base64_encode_length] = '\0'; + } + + char msg[2560] = {0}; + + // current_profile_id = i_profileid; + sprintf(msg, "GET /getstream?device=ds164 HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", accountData[0].account_port); + + strcat(msg, "Authorization: Basic "); + strcat(msg, httpAuth); + strcat(msg, "\r\n"); + strcat(msg, "\r\n"); + + // printf("\n-----------msg:%s\n", msg); + + err = send(socketfd, msg, strlen(msg), 0); + if (err == -1) + { + printf("\nerror sending\n"); + strcpy(g_stream_state_response, "Network problem: error sending"); + + // exit(EXIT_FAILURE); + } + else + { + init_radar_parser(); + init_axis_covert_world(); + // getStream(socketfd, MAX_IMG_SIZE); + getStream_b(socketfd, MAX_IMG_SIZE); + } + + close(socketfd); + return; + // printf("\n-------close getimage connected (%d)\n", socketfd); + + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) + { + // printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); + + socketRecords[i].sock = -1; + //socketRecords[i].thread_id = 0; + socketRecords[i].channel_id = -1; + //socketRecords[i].last_recv_time = time(0); + //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; + socketRecords[i].isGetAlarmMotion = FALSE; + //socketRecords[i].isFirstAlarmMotion = FALSE; + socketRecords[i].isWebSocketConnect = FALSE; + socketRecords[i].isUdpSocket = FALSE; + socketRecords[i].isNvrRequest = 0; + socketRecords[i].isCredentialRequest = 0; + socketRecords[i].debug_type = 0; +#if defined GY_OS_AMBA + //socketRecords[i].iIsAIRelay = 0; +#endif + + socketRecords[i].used = 0; + break; + } + } + + socketfd = -1; + } + else + { + printf("\nCould not create socket!\n"); + strcpy(g_stream_state_response, "Network problem: Could not create socket!"); + } + } + + if (host_info_list != NULL) + { + freeaddrinfo(host_info_list); + host_info_list = NULL; + } +} + +#if 0 +void radar_data_parser() + { + int iBlockDataSize; + char *sBlockDataBuffer; + int iCurrentRead = 0; + + while (1) + { + if (RadarQueueSize() > 0) + { + //printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< queue size: %d \n", RadarQueueSize()); + + RadarFrameData qPopRadarData = { 0 }; + + qPopRadarData = RadarQueueFront(); + RadarQueuePop(); + + iCurrentRead = 0; + iBlockDataSize = 0; + + //radar_start_status + //printf("<<<<<<<<<<<< pop queue, data size = %d, blocknum: %d \n", qPopRadarData.iDataSize, qPopRadarData.iDataBlockNumber); + + if (qPopRadarData.iDataBlockNumber > 0) + { + for (int i = 0; i < qPopRadarData.iDataBlockNumber; i++) + { + iBlockDataSize = qPopRadarData.iDataBlockArray[i]; + //printf("-%d ", qPopRadarData.iDataBlockArray[i]); + + if (i == 0 && iBlockDataSize != 40) + { + break; + } + else if (i == 0 && iBlockDataSize == 40) + { + iCurrentRead = 40; + continue; + } + + sBlockDataBuffer = qPopRadarData.frame_buffer + iCurrentRead; + iCurrentRead += iBlockDataSize; + printf("this correct_ttype a: %d \n", iBlockDataSize); + if (Is_correct_ttype(sBlockDataBuffer, iBlockDataSize) == 1) + { + // printf("\n----------decode_stage #2: find correct ttype\n"); + printf("this correct_ttype b: %d \n", iBlockDataSize); + g_check_if_is_correct_ttype = 1; //get 8byte data + } + else if (g_check_if_is_correct_ttype == 1) + { + run_general_ttype(sBlockDataBuffer, iBlockDataSize); //radar_data_array_p ----> 取得並分析雷達資料 + g_check_if_is_correct_ttype = 0; + } + } + //printf("\n"); + } + + //printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> %d \n", g_current_radar_data_index); + + if (g_current_radar_data_index >= 1) + { + build_radar_data_json(); + } + + memset(&radar_service_data, 0x00, sizeof(RadarServiceInfo)); + memset(&radar_data_array, 0x00, MAX_SIZE_RADAR_DATA * sizeof(RadarDataInfo)); + g_current_radar_data_index = 0; + } + + usSleep(10); + } +} +#endif + +void *thread_getstream(void *ptr) +{ + pthread_detach(pthread_self()); + // update_radar_json(); // leo 09-29 + update_radar_json_p(); // leo 11-25 + // while (get_bHttpServerThreadStart()) + //{ + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run thread_getstream\n"); + get_stream_with_device(); + usSleep(80000); + //} + pthread_exit(NULL); + } + +void *thread_parse_radar(void *ptr) + { + pthread_detach(pthread_self()); + + // while (get_bHttpServerThreadStart()) + // while (1) + //{ + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run thread radar parser\n"); + radar_data_parser(); + + // usSleep(80000); + //} + + pthread_exit(NULL); +} diff --git a/src/radar_driver.h b/src/radar_driver.h new file mode 100644 index 0000000..b2c7e46 --- /dev/null +++ b/src/radar_driver.h @@ -0,0 +1,161 @@ +#pragma once +#ifndef RADAR_DRIVER_H +#define RADAR_DRIVER_H +#include "define_inc.h" +#include <sys/time.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <termios.h> +#include <errno.h> +#include <fcntl.h> +#include <unistd.h> +#include <math.h> +#include <cJSON.h> +#include <netdb.h> +#include <netinet/tcp.h> + +// copy from nova driver +#include <sys/time.h> +#include <signal.h> +#include <arpa/inet.h> +#include <sys/socket.h> +#include "setting.h" +#include "nweb.h" +#include "utility.h" + +#include "cgicmd.h" + +#include "radar_receive.h" //leo 09-28 +#define RADAR_LOG + +#define LILIN_SHIFT 8 +#define MAX_SIZE_LILIN_START 8 +#define MAX_SIZE_LILIN_TTYPE 2 +#define READ_OBJ_AND_VUNIT 2 +#define MAX_SIZE_RADAR_DATA 35 +#define INT_BYTE_SIZE 2 + +#define TTYPE_1_OBJ_FORMAT_SIZE 5 +#define TTYPE_2_OBJ_FORMAT_SIZE 4 +#define TTYPE_3_OBJ_FORMAT_SIZE 6 +#define TTYPE_4_OBJ_FORMAT_SIZE 1 + +typedef union { + unsigned char hexarray[8]; + int64_t int64; + int32_t int32; + int16_t int16; + + float float32; +} radarconvert; + +typedef struct +{ + long ttype; + long TLVLength; + + // v1 + float doppler; + float PeakValue; + float X; + float Y; + float Z; + + // v2 + float ccX; + float ccY; + float csX; // v2 v3 + float csY; // v2 v3 + + // v3 + float tX; + float tY; + float velX; + float velY; + + float velZ; + float accX; + float accY; + float accZ; + + float Speed; + +} RadarDataInfo; + +typedef struct +{ + long version; + long totalPacketLen; + long platform; + long frameNumber; + long cpuProcessTime; + long numOBJs; + long numTLVs; + long subFrameNumber; + +} RadarServiceInfo; + +void radar_axis_covert_world(RadarDataInfo *local_radar_list, RadarDataInfo *world_radar_list); + + +extern RadarServiceInfo radar_service_data; +extern RadarDataInfo radar_data_array[MAX_SIZE_RADAR_DATA]; + +extern int g_switch_radar_data_json; +extern char g_radar_data_json[BUFSIZE_V3]; + +extern char global_radar_response[BUFSIZE_V3]; +#ifdef RADAR_LOG +extern int radar_log; // 10-19 leo +#endif // RADAR_LOG +// + +//#include "net_curl.h" +//#include "ptz.c" + +//#define MAGICWORDLENGTH 8 + +//#define SERVER "127.0.0.1" +//#define BUFLEN 512 //Max length of buffer +//#define UDP_PORT 7778 //The port to send + +// FILE *radar_JSON = NULL; +// char RADAR_FILE_PATH[100]; +// char json_out[4096]; +// char *json_temp = NULL; +// int RUN_DRIVER = 1; +// int SAVE_JSON = 0; + +// cannot connect radar to IPCam now, so use raw data txt file instead +//#define IS_READ_FILE +/* +#ifdef IS_READ_FILE +int READ_FILE = 1; +FILE *fd = NULL; +#endif +#ifndef IS_READ_FILE +int READ_FILE = 0; +#endif +*/ +//#define DEBUG_MSG //show debug message + +// radar data frame +// FrameNum Type PosX PosY PosZ velX velY csX csY Doppler Peak Speed + +//#define USE_OBJ + +int radar_start_status(char *buffer_stream, int buffer_size); +int Is_radar_data_empty(char *buffer_stream, int buffer_size); +int Is_correct_ttype(char *buffer_stream, int buffer_size); +void run_general_ttype(char *buffer_stream, int buffer_size); + +void build_radar_data_json(); + +void get_stream_with_device(); +void *thread_getstream(void *ptr); +void *thread_parse_radar(void *ptr); +void getStream(int socketfd, int bSize); + +#endif \ No newline at end of file diff --git a/src/radar_parser.cpp b/src/radar_parser.cpp new file mode 100644 index 0000000..3a064d3 --- /dev/null +++ b/src/radar_parser.cpp @@ -0,0 +1,1636 @@ +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +#include <deque> +#include <string.h> +#include <list> +#include <sys/stat.h> +#include <unistd.h> +#include <math.h> +#include <cJSON.h> + +#include "dbscan.c" // Ken 2022-10-24 +#include "radar_parser.h" +#include "setting.h" +#include "radar.h" +// #include "ptz.h" +#include "radar_receive.h" + +#ifdef GY_OS_PTZ +// #include "ptz.h" +// void get_ptz_degree(); +// void *thread_run_get_ptz_degree(void *ptr); +int radar_to_ptz_control(float radar_x, float radar_y); +// int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); +// int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); +// void write_ptz_to_json(); +// void detect_radar_to_ptz_control(cJSON *AiRadar); +#endif + +// #include "setting.h" + +static std::deque<RadarFrameData> g_RadarFrameQueue; + +RadarFrameData gstNewRadarFrame; +RadarConvert_P union_radar_convert_p; +RadarServiceInfo_P radar_service_data_p; + +RadarDataInfo_P radar_data_array_p[MAX_SIZE_RADAR_DATA_P] = {0}; + +RadarDataInfo_P world_radar_data_array_p[MAX_SIZE_RADAR_DATA_P] = {0}; // leo 09-29 +int g_current_radar_data_index_P = 0; +int g_check_if_is_correct_ttype_P = 0; +int g_switch_radar_data_json_p = 0; +char g_radar_data_json_p[BUFSIZE_V3] = {0}; +// RadarFrameData gstRadarFrame; +// g_RadarFrameQueue.push_back(gstRadarFrame); +#define PI 3.1415926 + +int get_radar_total_size(char *buffer, int buffer_size) +{ + int ret = 0; + if (buffer_size >= LILIN_SHIFT_P) + { + if (buffer[0] == 0x01 && + buffer[1] == 0x02 && + buffer[2] == 0x03 && + buffer[3] == 0x04 && + buffer[4] == 0x05 && + buffer[5] == 0x06 && + buffer[6] == 0x07 && + buffer[7] == 0x08) + { + // printf("magic num: %d-%d-%d-%d-%d-%d-%d-%d \n", buffer_stream[0], buffer_stream[1], buffer_stream[2], buffer_stream[3], buffer_stream[4], buffer_stream[5], buffer_stream[6], buffer_stream[7]); + + // if (g_current_radar_data_index_P >= 1) + //{ + // build_radar_data_json(); + // } + + memset(&radar_service_data_p, 0x00, sizeof(RadarServiceInfo_P)); + // memset(&radar_data_array_p, 0x00, MAX_SIZE_RADAR_DATA * sizeof(RadarDataInfo)); + g_current_radar_data_index_P = 0; + + if (buffer_size == LILIN_SHIFT_P + MAX_SIZE_LILIN_START_P * 4) + { + // printf("\n-------radar start status\n"); + for (int i = 0; i < MAX_SIZE_LILIN_START_P; i++) + { + memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer + LILIN_SHIFT_P + i * 4, 4); + if (i == 0) + radar_service_data_p.version = (long)union_radar_convert_p.int32; + else if (i == 1) + radar_service_data_p.totalPacketLen = (long)union_radar_convert_p.int32; + else if (i == 2) + radar_service_data_p.platform = (long)union_radar_convert_p.int32; + else if (i == 3) + radar_service_data_p.frameNumber = (long)union_radar_convert_p.int32; + else if (i == 4) + radar_service_data_p.cpuProcessTime = (long)union_radar_convert_p.int32; + else if (i == 5) + radar_service_data_p.numOBJs = (long)union_radar_convert_p.int32; + else if (i == 6) + radar_service_data_p.numTLVs = (long)union_radar_convert_p.int32; + else if (i == 7) + radar_service_data_p.subFrameNumber = (long)union_radar_convert_p.int32; + } + + /* + printf("\n----version:%ld\n", radar_service_data_p.version); + printf("\n----totalPacketLen:%ld\n", radar_service_data_p.totalPacketLen); + printf("\n----platform:%ld\n", radar_service_data_p.platform); + printf("\n----frameNumber:%ld\n", radar_service_data_p.frameNumber); + printf("\n----cpuProcessTime:%ld\n", radar_service_data_p.cpuProcessTime); + printf("\n----numOBJs:%ld\n", radar_service_data_p.numOBJs); + printf("\n----numTLVs:%ld\n", radar_service_data_p.numTLVs); + printf("\n----subFrameNumber:%ld\n", radar_service_data_p.subFrameNumber);*/ + + // printf("\n----frameNumber:%ld\n", radar_service_data_p.frameNumber); + // printf("\n----subFrameNumber:%ld\n", radar_service_data_p.subFrameNumber); + // printf("\n----totalPacketLen:%ld\n", radar_service_data_p.totalPacketLen); + + // if (radar_service_data_p.frameNumber - g_old_magic_num > 1) + // printf("lose frame: [%d] -> [%d] \n", g_old_magic_num, radar_service_data_p.frameNumber); + + // g_old_magic_num = radar_service_data_p.frameNumber; + } + + if (radar_service_data_p.totalPacketLen > 0) + ret = radar_service_data_p.totalPacketLen; + else + ret = 0; + } + else + { + ret = 0; + // printf("magic num err: %d-%d-%d-%d-%d-%d-%d-%d \n", + // buffer_stream[0], buffer_stream[1], buffer_stream[2], buffer_stream[3], + // buffer_stream[4], buffer_stream[5], buffer_stream[6], buffer_stream[7]); + } + } + return ret; +} + +// Ken +int json_radar_x_axis_p = 400; +int json_radar_y_axis_p = 500; +int json_target_x_axis_p = 400; +int json_target_y_axis_p = 100; + +int json_world_camera_x_axis_p = 100; +int json_world_camera_y_axis_p = 300; + +int json_radar_section_degree_p = 90; // Ken + +int json_world_camera_degree_p = 0; +int json_world_camera_home_point_degree_p = 0; +int json_world_camera_degree_offset_p = 0; +int json_distance_meter_p = 10; +int json_distance_meter_y_p = 10; + +bool json_enable_camera_p = FALSE; + +char json_ptz_ip_p[128] = {0}; +char json_ptz_port_num_p[64] = {0}; +char json_ptz_username_p[64] = {0}; +char json_ptz_password_p[64] = {0}; + +int json_ptz_p_degree_p = 0; +int json_ptz_t_degree_p = 0; +int json_ptz_z_degree_p = 0; + +float PI_p = 3.1415926; + +float ab_len = 0; +float scalex = 0; +float scaley = 0; +float rotate_theta = 0; +float rotate_y_theta = 0; + +void init_axis_covert_world() +{ + // ab_len = sqrt((float)((json_radar_x_axis_p - json_target_x_axis_p) * (json_radar_x_axis_p - json_target_x_axis_p)) + (float)((json_radar_y_axis_p - json_target_y_axis_p) * (json_radar_y_axis_p - json_target_y_axis_p))); + // scalex = ab_len / (float)json_distance_meter_p; + scalex = 800.0 / (float)json_distance_meter_p; + rotate_theta = (atan((float)(json_target_y_axis_p - json_radar_y_axis_p) / (float)(json_target_x_axis_p - json_radar_x_axis_p + 0.001)) * 180 / PI_p) - 90; + + scaley = 600.0 / (float)json_distance_meter_y_p; + rotate_y_theta = (atan((float)(json_target_y_axis_p - json_radar_y_axis_p) / (float)(json_target_x_axis_p - json_radar_x_axis_p + 0.001)) * 180 / PI_p) - 90; + + +} +float local_radar_x, local_radar_y; +float world_radar_x, world_radar_y; + +void radar_axis_covert_world_P(RadarDataInfo_P *local_radar_list, RadarDataInfo_P *world_radar_list) +{ + // document->getElementById("world_radar_degree")->innerHTML = 360 + round(rotate_theta); + // var test_x = round(cos((-rotate_theta) * PI_p / 180) * (local_radar_list->X * scalex) - sin((-rotate_theta) * PI_p / 180) * (local_radar_list->Y * scalex)) + json_radar_x_axis_p; + // var test_y = json_radar_y_axis_p - round(sin((-rotate_theta) * PI_p / 180) * (local_radar_list->X * scalex) + cos((-rotate_theta) * PI_p / 180) * (local_radar_list->Y * scalex)); + + if (local_radar_list->ttype == 1) + { + local_radar_x = local_radar_list->X; + local_radar_y = local_radar_list->Y; + } + else if (local_radar_list->ttype == 2) + { + local_radar_x = local_radar_list->ccX; + local_radar_y = local_radar_list->ccY; + } + else if (local_radar_list->ttype == 3) + { + local_radar_x = local_radar_list->tX; + local_radar_y = local_radar_list->tY; + } + if (json_target_x_axis_p >= json_radar_x_axis_p) + { + world_radar_x = round(cos((-rotate_theta + 180) * PI_p / 180) * (local_radar_x * scalex) - sin((-rotate_theta + 180) * PI_p / 180) * (local_radar_y * scaley)) + json_radar_x_axis_p; + world_radar_y = json_radar_y_axis_p - round(sin((-rotate_theta + 180) * PI_p / 180) * (local_radar_x * scalex) + cos((-rotate_theta + 180) * PI_p / 180) * (local_radar_y * scaley)); + } + else + { + world_radar_x = round(cos((-rotate_theta) * PI_p / 180) * (local_radar_x * scalex) - sin((-rotate_theta) * PI_p / 180) * (local_radar_y * scaley)) + json_radar_x_axis_p; + world_radar_y = json_radar_y_axis_p - round(sin((-rotate_theta) * PI_p / 180) * (local_radar_x * scalex) + cos((-rotate_theta) * PI_p / 180) * (local_radar_y * scaley)); + } + + // printf("local origin(x,y): (%f,%f) transfer(x,y): (%f,%f) \n", local_radar_list->X, local_radar_list->Y, world_radar_x, world_radar_y); + + if (local_radar_list->ttype == 1) + { + world_radar_list->X = world_radar_x; + world_radar_list->Y = world_radar_y; + world_radar_list->ccX = local_radar_list->ccX; + world_radar_list->ccY = local_radar_list->ccY; + world_radar_list->tX = local_radar_list->tX; + world_radar_list->tY = local_radar_list->tY; + } + else if (local_radar_list->ttype == 2) + { + world_radar_list->X = local_radar_list->X; + world_radar_list->Y = local_radar_list->Y; + world_radar_list->ccX = world_radar_x; + world_radar_list->ccY = world_radar_y; + world_radar_list->tX = local_radar_list->tX; + world_radar_list->tY = local_radar_list->tY; + } + else if (local_radar_list->ttype == 3) + { + world_radar_list->X = local_radar_list->X; + world_radar_list->Y = local_radar_list->Y; + world_radar_list->ccX = local_radar_list->ccX; + world_radar_list->ccY = local_radar_list->ccY; + world_radar_list->tX = world_radar_x; + world_radar_list->tY = world_radar_y; + } + + world_radar_list->ttype = local_radar_list->ttype; + world_radar_list->TLVLength = local_radar_list->TLVLength; + world_radar_list->doppler = local_radar_list->doppler; + world_radar_list->PeakValue = local_radar_list->PeakValue; + // world_radar_list->X = local_radar_list->X; + // world_radar_list->Y = local_radar_list->Y; + world_radar_list->Z = local_radar_list->Z; + // world_radar_list->ccX = local_radar_list->ccX; + // world_radar_list->ccY = local_radar_list->ccY; + world_radar_list->csX = local_radar_list->csX; + world_radar_list->csY = local_radar_list->csY; + // world_radar_list->tX = local_radar_list->tX; + // world_radar_list->tY = local_radar_list->tY; + world_radar_list->velX = local_radar_list->velX; + world_radar_list->velY = local_radar_list->velY; + world_radar_list->velZ = local_radar_list->velZ; + world_radar_list->accX = local_radar_list->accX; + world_radar_list->accY = local_radar_list->accY; + world_radar_list->accZ = local_radar_list->accZ; + world_radar_list->Speed = local_radar_list->Speed; +} + +// 0: not empty //data = 0x0f 0x0f 0x0f ..... +int Is_radar_data_end(char *buffer_stream, int buffer_size) +{ + char temp_char = buffer_stream[0]; + int ret = 0; + + for (int i = 1; i < buffer_size; i++) + { + if (buffer_stream[i] != temp_char) + break; + else if (i == buffer_size - 1) + { + ret = 1; + } + } + return ret; +} + +int Is_correct_ttype_P(char *buffer_stream, int buffer_size) +{ + int ret = 0; + if (buffer_size == 8) // MAX_SIZE_LILIN_TTYPE_P * 4 //if buffer_size = 8 byte + { + long temp_ttype = 0; + long temp_TLVLength = 0; + + for (int i = 0; i < MAX_SIZE_LILIN_TTYPE_P; i++) + { + memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + i * 4, 4); + if (i == 0) + temp_ttype = (long)union_radar_convert_p.int32; + else if (i == 1) + temp_TLVLength = (long)union_radar_convert_p.int32; + } + + if (temp_ttype >= 1 && temp_ttype <= 4 && temp_TLVLength < radar_service_data_p.totalPacketLen && temp_TLVLength >= 1) + { + radar_data_array_p[g_current_radar_data_index_P].ttype = temp_ttype; + radar_data_array_p[g_current_radar_data_index_P].TLVLength = temp_TLVLength; + + // printf(">>> [%d] type-TLVlen = %d, %d \n", g_current_radar_data_index_P, temp_ttype, temp_TLVLength); + + ret = 1; + } + } + return ret; +} + +// 10-24 Ken DBSCAN param +int radar_dbscan_p = 0; +int radar_type_1_points_num_p = 0; +double epsilon_p = 2; +unsigned int minpts_p = 1; +point_t *points_p = NULL; + +//int g_old_magic_num; + +void run_general_ttype_P(char *buffer_stream, int buffer_size) +{ + // printf(">>>>>>>>>>>>>>>>>>>>>>>> run_general_ttype_P :%d, %d\n", buffer_size, (READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P)); + // printf(">>>>>>>>>>>>>>>>>>>>>>>> type = %d \n", radar_data_array_p[g_current_radar_data_index_P].ttype); + // printf(">>>>>>>>>>>>>>>>>>>>>>>> [%d] TLVLen = %ld - %ld\n", g_current_radar_data_index_P, radar_data_array_p[g_current_radar_data_index_P].TLVLength, radar_service_data_p.totalPacketLen); + if (buffer_size >= 4 && // READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + radar_data_array_p[g_current_radar_data_index_P].ttype >= 1 && + radar_data_array_p[g_current_radar_data_index_P].ttype <= 3 && + // radar_data_array_p[g_current_radar_data_index_P].ttype <= 4 && + radar_data_array_p[g_current_radar_data_index_P].TLVLength < radar_service_data_p.totalPacketLen && + radar_data_array_p[g_current_radar_data_index_P].TLVLength >= 1) + { + int objs = 0; + float vUnit = 0.0; + + for (int i = 0; i < READ_OBJ_AND_VUNIT_P; i++) + { + memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + i * 2, 2); + if (i == 0) + objs = (int)union_radar_convert_p.int16; + else if (i == 1) + vUnit = 1.0 / (float)pow(2.0, (double)(int)union_radar_convert_p.int16); + } + // printf("\n--objs:%d,vunit:%f\n",objs,vUnit); + + // printf("-------------------------------------------------------- radar objs: %d \n", objs); + + radar_type_1_points_num_p = 0; // 10-24 Ken + // printf("radar_type_1_points_num : %d\n", radar_type_1_points_num); + + if (objs >= 1 && vUnit > 0.0) + { + int ori_g_current_radar_data_index = g_current_radar_data_index_P; + + if (radar_data_array_p[g_current_radar_data_index_P].ttype == 1) + { + // printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TYPE 111 \n"); + // if (buffer_size == (READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + objs * TTYPE_1_OBJ_FORMAT_SIZE_P * INT_BYTE_SIZE_P)) + if (buffer_size == (4 + objs * 10)) + { + + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index_P != ori_g_current_radar_data_index) + { + radar_data_array_p[g_current_radar_data_index_P].ttype = radar_data_array_p[ori_g_current_radar_data_index].ttype; + radar_data_array_p[g_current_radar_data_index_P].TLVLength = radar_data_array_p[ori_g_current_radar_data_index].TLVLength; + } + + float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; // for V1 + // float ccX = 0.0, ccY = 0.0, csX = 0.0, csY = 0.0; //for V2 + // float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; //for V3 + + for (int j = 0; j < TTYPE_1_OBJ_FORMAT_SIZE_P; j++) + { + // memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + i * TTYPE_1_OBJ_FORMAT_SIZE_P + j * 2, 2); + memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + 4 + i * TTYPE_1_OBJ_FORMAT_SIZE_P + j * 2, 2); + if (j == 0) + doppler = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 1) + PeakValue = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 2) + X = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 3) + Y = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 4) + Z = vUnit * (float)(int)union_radar_convert_p.int16; + } + + // printf("\n---value:%f,%f,%f,%f,%f\n", doppler, PeakValue, X, Y, Z); + + radar_data_array_p[g_current_radar_data_index_P].doppler = doppler; + radar_data_array_p[g_current_radar_data_index_P].PeakValue = PeakValue; + radar_data_array_p[g_current_radar_data_index_P].X = X; + radar_data_array_p[g_current_radar_data_index_P].Y = Y; + radar_data_array_p[g_current_radar_data_index_P].Z = Z; + + g_current_radar_data_index_P++; + radar_type_1_points_num_p++; + // printf("--- radar_type_1_points_num : %d\n", radar_type_1_points_num); + } + } + } + else if (radar_data_array_p[g_current_radar_data_index_P].ttype == 2) + { + // printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TYPE 222 \n"); + // if (buffer_size == (READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + objs * TTYPE_2_OBJ_FORMAT_SIZE_P * INT_BYTE_SIZE_P)) + if (buffer_size == (4 + objs * 8)) + { + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index_P != ori_g_current_radar_data_index) + { + radar_data_array_p[g_current_radar_data_index_P].ttype = radar_data_array_p[ori_g_current_radar_data_index].ttype; + radar_data_array_p[g_current_radar_data_index_P].TLVLength = radar_data_array_p[ori_g_current_radar_data_index].TLVLength; + } + + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + float ccX = 0.0, ccY = 0.0, csX = 0.0, csY = 0.0; // for V2 + // float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; //for V3 + + for (int j = 0; j < TTYPE_2_OBJ_FORMAT_SIZE_P; j++) + { + // memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + i * TTYPE_2_OBJ_FORMAT_SIZE_P + j * 2, 2); + memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + 4 + i * TTYPE_2_OBJ_FORMAT_SIZE_P + j * 2, 2); + + if (j == 0) + ccX = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 1) + ccY = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 2) + csX = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 3) + csY = vUnit * (float)(int)union_radar_convert_p.int16; + } + + // printf("\n---value:%f, %f, %f, %f\n", ccX, ccY, csX, csY); + + radar_data_array_p[g_current_radar_data_index_P].ccX = ccX; + radar_data_array_p[g_current_radar_data_index_P].ccY = ccY; + radar_data_array_p[g_current_radar_data_index_P].csX = csX; + radar_data_array_p[g_current_radar_data_index_P].csY = csY; + + g_current_radar_data_index_P++; + } + } + } + else if (radar_data_array_p[g_current_radar_data_index_P].ttype == 3) + { + // printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TYPE 333 \n"); + + // if (buffer_size == (READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + objs * TTYPE_3_OBJ_FORMAT_SIZE_P * INT_BYTE_SIZE_P)) + if (buffer_size == (4 + objs * 12)) + { + + for (int i = 0; i < objs; i++) + { + if (g_current_radar_data_index_P != ori_g_current_radar_data_index) + { + radar_data_array_p[g_current_radar_data_index_P].ttype = radar_data_array_p[ori_g_current_radar_data_index].ttype; + radar_data_array_p[g_current_radar_data_index_P].TLVLength = radar_data_array_p[ori_g_current_radar_data_index].TLVLength; + } + + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + /*/float ccX = 0.0, ccY = 0.0,*/ float csX = 0.0, csY = 0.0; // for V2 + float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; // for V3 + + for (int j = 0; j < TTYPE_3_OBJ_FORMAT_SIZE_P; j++) + { + // memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + READ_OBJ_AND_VUNIT_P * INT_BYTE_SIZE_P + i * TTYPE_3_OBJ_FORMAT_SIZE_P + j * 2, 2); + memcpy(union_radar_convert_p.hexarray, (unsigned char *)buffer_stream + 4 + i * TTYPE_3_OBJ_FORMAT_SIZE_P + j * 2, 2); + + if (j == 0) + tX = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 1) + tY = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 2) + velX = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 3) + velY = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 4) + csX = vUnit * (float)(int)union_radar_convert_p.int16; + else if (j == 5) + csY = vUnit * (float)(int)union_radar_convert_p.int16; + } + + // printf("\n---value:%f,%f,%f,%f,%f,%f\n", tX, tY, velX, velY, csX,csY); + + radar_data_array_p[g_current_radar_data_index_P].tX = tX; + radar_data_array_p[g_current_radar_data_index_P].tY = tY; + radar_data_array_p[g_current_radar_data_index_P].velX = velX; + radar_data_array_p[g_current_radar_data_index_P].velY = velY; + radar_data_array_p[g_current_radar_data_index_P].csX = csX; + radar_data_array_p[g_current_radar_data_index_P].csY = csY; + + if (tX != 0 && tY != 0) + radar_data_array_p[g_current_radar_data_index_P].Speed = ((tX * velX + tY * velY) / sqrt((tX * tX + tY * tY))) * 3.6; + + g_current_radar_data_index_P++; + } + } + } + +#if 1 // leo 09-29 + if (g_current_radar_data_index_P >= 1) + { + // Ken 10-24 DBSCAN + if (radar_data_array_p[g_current_radar_data_index_P - 1].ttype == 1 && radar_dbscan_p == 0) + { + // printf("run_general_ttype - g_current_radar_data_index_P>=1, if type ==1, if (radar_dbscan_p == 0)\n"); + points_p = (point_t *)calloc(radar_type_1_points_num_p, sizeof(point_t)); + + for (int j = 0; j < g_current_radar_data_index_P; j++) + { + points_p[j].x = radar_data_array_p[j].X; + points_p[j].y = radar_data_array_p[j].Y; + points_p[j].z = radar_data_array_p[j].Z; + points_p[j].cluster_id = UNCLASSIFIED; + points_p[j].nop = 1; + } + + // printf("=== DBSCAN Settings ===\n"); + // printf("Epsilon: %lf\n", epsilon); + // printf("Minimum points: %u\n", minpts); + dbscan(points_p, radar_type_1_points_num_p, epsilon_p, minpts_p, euclidean_dist); + + // printf("=== update nop START ===\n"); + // TODO update nop ( number of cluster points ) + int max_cluster_id = 0; + + for (int j = 0; j < g_current_radar_data_index_P; j++) + { + if (points_p[j].cluster_id > max_cluster_id) + { + max_cluster_id = points_p[j].cluster_id; + } + } + + for (int cluster_id_index = 0; cluster_id_index <= max_cluster_id; cluster_id_index++) + { + int counter = 0; + for (int j = 0; j < g_current_radar_data_index_P; j++) + { + if (points_p[j].cluster_id == cluster_id_index) + { + ++counter; + } + } + + for (int j = 0; j < g_current_radar_data_index_P; j++) + { + if (points_p[j].cluster_id == cluster_id_index) + { + points_p[j].nop = counter; + } + // printf("points[%d].cluster_id : %d, .nop : %d\n", j, points[j].cluster_id, points[j].nop); + } + } + // printf("=== update nop END ===\n"); + + radar_dbscan_p = 1; + } + init_axis_covert_world(); + for (int i = 0; i < g_current_radar_data_index_P; i++) + { + radar_axis_covert_world_P(&radar_data_array_p[i], &world_radar_data_array_p[i]); + + // printf("Type %ld origin(x,y): (%f,%f) transfer(x,y): (%f,%f) \n", temp_current_radar_list[i].ttype, temp_current_radar_list[i].X, temp_current_radar_list[i].Y, g_current_radar_list[i].X, g_current_radar_list[i].Y); + } + } +#endif + } + } +} + +int get_radar_package_size(char *buffer) +{ + char *ptr_1, *ptr_2; + int strlen_ptr = 0; + char boundary[256] = {0}; + int content_length_image = 0; + + ptr_1 = strstr(buffer, "Content-Length: "); + if (ptr_1) + { + ptr_2 = strstr(ptr_1, "Stamp"); + if (ptr_2) + { + strlen_ptr = ptr_2 - ptr_1 - 16; // 16 = "Content-Length: " + memset(boundary, 0, sizeof(boundary)); + if (strlen_ptr >= 1) + { + strncpy(boundary, ptr_1 + 16, strlen_ptr); + // printf("\n-----------boundary:%s\n", boundary); + content_length_image = atoi(boundary); + // bodySize = 0; + // printf("\n-------------next content_length_image:%d\n", content_length_image); + } + } + } + + return content_length_image; +} + +void parse() +{ + + // for (int i = 0; i < recv_len; i++) + //{ + // if (recv_data[i + 0] == 0x0f && recv_data[i + 1] == 0x0f && recv_data[i + 2] == 0x0f) + // { + // //the end of radar data + + // RadarFrameData radar_q_info = { 0 }; + // //Queue push + // } + // else + // { + // } + //} +} + +int g_iLastDataSize; +int g_iGetDataSize; +int g_iNextPackageSize; + +void init_radar_parser() +{ + g_iLastDataSize = 0; + g_iGetDataSize = 0; + g_iNextPackageSize = 0; + + memset(gstNewRadarFrame.frame_buffer, 0x00, MAX_RADAR_DATA_SIZE); + gstNewRadarFrame.iDataSize = 0; + gstNewRadarFrame.iDataBlockNumber = 0; + for (int i = 0; i < RADAR_DATA_BLOCK_NUM; i++) + { + gstNewRadarFrame.iDataBlockArray[i] = -1; + } +} + +void radar_data_get(char *recv_data, int recv_len) +{ + if (recv_len <= 0 || strlen(recv_data) <= 0) + return; + + int radar_total_size = 0; + int iIsEnd = 0; + + // radar data + if (strstr(recv_data, "--myboundary") != NULL) + { + g_iNextPackageSize = get_radar_package_size(recv_data); + + // g_iLastDataSize = get_radar_package_size(recv_data); + // gstNewRadarFrame.iDataSize = g_iLastDataSize; + // printf("----------------------------> size: %d \n", gstNewRadarFrame.iDataSize); + } + else + { + if (recv_len >= g_iNextPackageSize) + { + if (recv_len >= 40) + radar_total_size = get_radar_total_size(recv_data, recv_len); // ret > 0: radar header package = total radar data size, ret = 0: not radar header + + if (radar_total_size > 0) + { + // printf("************************************* total size: %d \n", radar_total_size); + + init_radar_parser(); + + g_iLastDataSize = radar_total_size; + } + + // printf("-----get size: %d \n", recv_len); + + // if (totalsize != 0) + // printf("bbbbbbb: total size: %d \n", totalsize); + if (g_iLastDataSize > 0) + { + // recive all radar data + memcpy(gstNewRadarFrame.frame_buffer + g_iGetDataSize, recv_data, recv_len); + g_iGetDataSize += recv_len; + g_iLastDataSize -= recv_len; + + gstNewRadarFrame.iDataBlockArray[gstNewRadarFrame.iDataBlockNumber] = recv_len; + gstNewRadarFrame.iDataBlockNumber++; + + // check if end data + iIsEnd = Is_radar_data_end(recv_data, recv_len); + + if (g_iLastDataSize == 0 && iIsEnd == 1) + { + // Queu push + if (g_RadarFrameQueue.size() < RADAR_QUEUE_SIZE) + { + RadarFrameData qNewRadarData = {0}; + memcpy(qNewRadarData.frame_buffer, gstNewRadarFrame.frame_buffer, g_iGetDataSize); + qNewRadarData.iDataSize = g_iGetDataSize; + qNewRadarData.iDataBlockNumber = gstNewRadarFrame.iDataBlockNumber; + + for (int j = 0; j < gstNewRadarFrame.iDataBlockNumber; j++) + qNewRadarData.iDataBlockArray[j] = gstNewRadarFrame.iDataBlockArray[j]; + + g_RadarFrameQueue.push_back(qNewRadarData); + // printf("-----push queue size = %d \n", g_RadarFrameQueue.size()); + } + + // printf("-----queue size = %d \n", g_RadarFrameQueue.size()); + } + else if (g_iLastDataSize < 0 || (g_iLastDataSize > 0 && iIsEnd == 1)) + { + // printf("get data error, drop!!!!!\n"); + // printf("%d - %d \n", g_iLastDataSize, iIsEnd); + // reset, drop data + g_iLastDataSize = 0; + g_iGetDataSize = 0; + gstNewRadarFrame.iDataBlockNumber = 0; + } + } + else + { + // nothning to do + } + } + else + { + // if (recv_len < g_iNextPackageSize) + // reset, drop data + g_iLastDataSize = 0; + g_iGetDataSize = 0; + } + } +} + +void RadarQueuePush(RadarFrameData q_info) +{ + g_RadarFrameQueue.push_back(q_info); +} + +RadarFrameData RadarQueueFront() +{ + return g_RadarFrameQueue.front(); +} + +void RadarQueuePop() +{ + + //RadarFrameData q_info = RadarQueueFront(); + + g_RadarFrameQueue.pop_front(); + g_RadarFrameQueue.shrink_to_fit(); +} + +int RadarQueueSize() +{ + return g_RadarFrameQueue.size(); +} + +int RadarQueueIsEmpty() +{ + return RadarQueueSize() <= 0 ? 1 : 0; +} + +void RadarQueueClear() +{ + + while (!RadarQueueIsEmpty()) + { + RadarQueuePop(); + } + + if (!RadarQueueIsEmpty()) + { + g_RadarFrameQueue.clear(); + g_RadarFrameQueue.shrink_to_fit(); + } +} + +int rule_based_classifier_p(point_t *p, int p_ind, float doppler, int class_id) +{ + // GYNet_Radar_Tiny_Label: + // 0 : person + // 1 : bicycle + // 2 : car + // 3 : motorbike + // 4 : _s + // 5 : bus + // 6 : _s + // 7 : truck + + float speed = -doppler * 3600.0 / 1000.0; + + float distance = euclidean_dist_to_op(&p[p_ind]); + + int nop = p[p_ind].nop; + + // rules + if (speed >= 82.8) + { + class_id = -1; + } + else if (distance < 40 && distance >= 1 && nop <= 15 && nop >= 1) + { + class_id = 0; // person + } + // ... + + // printf("--- p_ind: %d, distance:%f, speed:%f, class_id:%f\n", p_ind, distance, speed, class_id); + + return class_id; +} + +int RADAR_BG_WIDTH_P = 800; +int RADAR_BG_HEIGHT_P = 600; +int FrameNum_tmp; +int theta_tmp; +void build_radar_data_json_p() +{ + // Ken + // int json_radar_x_axis = 400; + // int json_radar_y_axis = 500; + // int json_target_x_axis = 400; + // int json_target_y_axis = 100; + + // int json_world_camera_x_axis = 100; + // int json_world_camera_y_axis = 300; + + // int json_radar_section_degree = 90; // Ken + + // int json_world_camera_degree = 0; + // int json_world_camera_home_point_degree = 0; + // int json_world_camera_degree_offset = 0; + // int json_distance_meter = 10; + // float PI = 3.1415926; + + cJSON *root = NULL; + cJSON *AiRadar, *detectArrayRadar, *detectRadar; + + /* + cJSON *FrameNum, *tid, *posX, *posY, *posZ, *velX, *velY, *velZ, + *accX, *accY, *accZ, *ccX, *ccY, *csX, *csY, *tX, *tY, *Doppler; + */ + + root = cJSON_CreateObject(); + + AiRadar = cJSON_CreateObject(); + cJSON_AddItemToObject(root, "AiRadar", AiRadar); + + time_t current_time = time(0); + char c_current_time[20] = {0}; + sprintf(c_current_time, "%ld", current_time); + cJSON_AddItemToObject(AiRadar, "Time", cJSON_CreateString(c_current_time)); + + char c_framenum[20] = {0}; + sprintf(c_framenum, "%ld", radar_service_data_p.frameNumber); + cJSON_AddItemToObject(AiRadar, "FrameNum", cJSON_CreateString(c_framenum)); + + char c_radar_x_axis[20] = {0}; + sprintf(c_radar_x_axis, "%d", json_radar_x_axis_p); + cJSON_AddItemToObject(AiRadar, "radar_x_axis", cJSON_CreateString(c_radar_x_axis)); + + char c_radar_y_axis[20] = {0}; + sprintf(c_radar_y_axis, "%d", json_radar_y_axis_p); + cJSON_AddItemToObject(AiRadar, "radar_y_axis", cJSON_CreateString(c_radar_y_axis)); + + char c_target_x_axis[20] = {0}; + sprintf(c_target_x_axis, "%d", json_target_x_axis_p); + cJSON_AddItemToObject(AiRadar, "target_x_axis", cJSON_CreateString(c_target_x_axis)); + + char c_target_y_axis[20] = {0}; + sprintf(c_target_y_axis, "%d", json_target_y_axis_p); + cJSON_AddItemToObject(AiRadar, "target_y_axis", cJSON_CreateString(c_target_y_axis)); + + char c_distance_meter[20] = {0}; + sprintf(c_distance_meter, "%d", json_distance_meter_p); + cJSON_AddItemToObject(AiRadar, "distance_meter", cJSON_CreateString(c_distance_meter)); + + char c_distance_meter_y[20] = { 0 }; + sprintf(c_distance_meter_y, "%d", json_distance_meter_y_p); + cJSON_AddItemToObject(AiRadar, "distance_meter_y", cJSON_CreateString(c_distance_meter_y)); + +#ifdef GY_OS_PTZ + char c_ptz_p_degree[20] = {0}; + sprintf(c_ptz_p_degree, "%d", json_ptz_p_degree_p); + cJSON_AddItemToObject(AiRadar, "ptz_p_degree", cJSON_CreateString(c_ptz_p_degree)); +#endif + detectArrayRadar = cJSON_CreateArray(); + cJSON_AddItemToObject(AiRadar, "RadarArray", detectArrayRadar); + + for (int i = 0; i < g_current_radar_data_index_P; i++) + { + // printf("build_radar_data_json - g_current_radar_data_index_p : %d, V%ld point\n", i, radar_data_array[i].ttype); + + detectRadar = cJSON_CreateObject(); + cJSON_AddItemToArray(detectArrayRadar, detectRadar); + + char c_tid[10] = {0}; + sprintf(c_tid, "%d", i); + cJSON_AddItemToObject(detectRadar, "tid", cJSON_CreateString(c_tid)); + + char c_ttype[10] = {0}; + sprintf(c_ttype, "%ld", radar_data_array_p[i].ttype); + cJSON_AddItemToObject(detectRadar, "Type", cJSON_CreateString(c_ttype)); + + if (radar_data_array_p[i].ttype == 1) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", radar_data_array_p[i].X); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", radar_data_array_p[i].Y); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + char c_posZ[20] = {0}; + sprintf(c_posZ, "%f", radar_data_array_p[i].Z); + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString(c_posZ)); + + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + + char c_doppler[20] = {0}; + sprintf(c_doppler, "%f", radar_data_array_p[i].doppler); + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString(c_doppler)); + + char c_PeakValue[20] = {0}; + sprintf(c_PeakValue, "%f", radar_data_array_p[i].PeakValue); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString(c_PeakValue)); + + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)world_radar_data_array_p[i].X); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + // printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> x: %d \n", (int)world_radar_data_array_p[i].X); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)world_radar_data_array_p[i].Y); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (world_radar_data_array_p[i].X >= 0 && world_radar_data_array_p[i].X < RADAR_BG_WIDTH_P) + { + if (world_radar_data_array_p[i].Y >= 0 && world_radar_data_array_p[i].Y < RADAR_BG_HEIGHT_P) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#endif + // 10-26 pass class_id to client + int class_id = -1; // default : not object + + // 10-25 Ken apply DBSCAN algorithm + if (radar_dbscan_p == 1) + { + class_id = rule_based_classifier_p(points_p, i, radar_data_array_p[i].doppler, class_id); + + // printf("V1 DBSCAN - X:%5lf, Y:%5lf, Z:%5lf, cluster_id: %d, class_id: %d\n\n", points_p[i].x, points_p[i].y, points_p[i].z, points_p[i].cluster_id, class_id); + } + + cJSON_AddItemToObject(detectRadar, "class_id", cJSON_CreateNumber(class_id)); + } + else if (radar_data_array_p[i].ttype == 2) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", radar_data_array_p[i].ccX); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", radar_data_array_p[i].ccY); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString(c_posX)); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString(c_posY)); + + char c_csX[20] = {0}; + sprintf(c_csX, "%f", radar_data_array_p[i].csX); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + + char c_csY[20] = {0}; + sprintf(c_csY, "%f", radar_data_array_p[i].csY); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)world_radar_data_array_p[i].ccX); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)world_radar_data_array_p[i].ccY); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (world_radar_data_array_p[i].ccX >= 0 && world_radar_data_array_p[i].ccX < RADAR_BG_WIDTH_P) + { + if (world_radar_data_array_p[i].ccY >= 0 && world_radar_data_array_p[i].ccY < RADAR_BG_HEIGHT_P) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#endif + cJSON_AddItemToObject(detectRadar, "class_id", cJSON_CreateNumber(-2)); + } + else if (radar_data_array_p[i].ttype == 3) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", radar_data_array_p[i].tX); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", radar_data_array_p[i].tY); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + + char c_velX[20] = {0}; + sprintf(c_velX, "%f", radar_data_array_p[i].velX); + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString(c_velX)); + + char c_velY[20] = {0}; + sprintf(c_velY, "%f", radar_data_array_p[i].velY); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString(c_velY)); + + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + + char c_csX[20] = {0}; + sprintf(c_csX, "%f", radar_data_array_p[i].csX); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + + char c_csY[20] = {0}; + sprintf(c_csY, "%f", radar_data_array_p[i].csY); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + + char c_tX[20] = {0}; + sprintf(c_tX, "%f", radar_data_array_p[i].tX); + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString(c_tX)); + + char c_tY[20] = {0}; + sprintf(c_tY, "%f", radar_data_array_p[i].tY); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString(c_tY)); + + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + + char c_Speed[20] = {0}; + sprintf(c_Speed, "%f", radar_data_array_p[i].Speed); + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString(c_Speed)); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)world_radar_data_array_p[i].tX); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)world_radar_data_array_p[i].tY); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (world_radar_data_array_p[i].tX >= 0 && world_radar_data_array_p[i].tX < RADAR_BG_WIDTH_P) + { + if (world_radar_data_array_p[i].tY >= 0 && world_radar_data_array_p[i].tY < RADAR_BG_HEIGHT_P) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#endif + cJSON_AddItemToObject(detectRadar, "class_id", cJSON_CreateNumber(-3)); + } + } + char *JsonString = NULL; + + if (root) + { + JsonString = cJSON_PrintUnformatted(root); + // printf("\nradar_driver - g_radar_data_json_p:%s\n", JsonString); + + if (g_switch_radar_data_json_p == 0) + { + // printf("FrameNum = %d \n", radar_service_data_p.frameNumber); + // memset(g_radar_data_json_p, 0x00, sizeof(g_radar_data_json_p)); + // strcpy(g_radar_data_json_p, JsonString); + strcpy(global_radar_response, JsonString); + + // printf("\n1. -----------------------------------------------\n"); + printf("\nglobal_radar_response:%s\n", global_radar_response); + + g_switch_radar_data_json_p = 1; + } + +#if 0 // radar ptz control 12/20 temporarily close the function - leo + char *TempString = NULL; + TempString = cJSON_PrintUnformatted(root); + // printf("TempString : %s\n", TempString); + + // cJSON *FrameNum, *Type, *posX, *posY; + int FrameNum, Type; + float Speed, posX, posY; + char *plot; + FrameNum = atoi(cJSON_GetObjectItem(AiRadar, "FrameNum")->valuestring); + // printf("FrameNum : %d \n", FrameNum); + cJSON_ArrayForEach(detectArrayRadar, AiRadar) + { + cJSON_ArrayForEach(detectRadar, detectArrayRadar) + { + Type = atoi(cJSON_GetObjectItem(detectRadar, "Type")->valuestring); + + // printf("FrameNum_tmp : %d Type: %d\n", FrameNum, Type); + if (Type == 3) + { + if (FrameNum_tmp == FrameNum) + { + break; + } + + theta_tmp = 0; + posX = atof(cJSON_GetObjectItem(detectRadar, "posX")->valuestring); + posY = atof(cJSON_GetObjectItem(detectRadar, "posY")->valuestring); + Speed = atof(cJSON_GetObjectItem(detectRadar, "Speed")->valuestring); + plot = cJSON_GetObjectItem(detectRadar, "plot")->valuestring; + printf("AiRadar FrameNum : %d (x,y):(%f , %f) Speed: %f plot : %s\n", FrameNum, posX, posY, Speed, plot); + if ((Speed > 0.1 || Speed < -0.1) & (strcmp(plot, "Yes") == 0)) + { + + printf("!!!!!!!Detect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + theta_tmp = radar_to_ptz_control(posX, posY); + FrameNum_tmp = FrameNum; + // printf("AiRadar theta A : %f \n", theta_tmp); + printf(" AiRadarradar target in PTZ degree : %d \n", theta_tmp); + + if (theta_tmp < 0) + { + theta_tmp = (int)theta_tmp + 360; + } + if (theta_tmp > 360) + { + theta_tmp = (int)theta_tmp % 360; + } + + char ptz_intput_theta[10]; + sprintf(ptz_intput_theta, "%d", theta_tmp); + // UpdateRemotePTZCurPos("admin", "Pass1234", "192.168.50.139", "80", ptz_intput_theta, "20", "2"); + UpdateRemotePTZCurPos(json_ptz_username_p, json_ptz_password_p, json_ptz_ip_p, json_ptz_port_num_p, ptz_intput_theta, "0", "1"); + usSleep(100); + break; + } + else + { + printf("!!!!!!!Detect speed < 0.1 !!!!\n"); + } + } + } + } +#endif // GY_OS_PTZ + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (root) + { + cJSON_Delete(root); + root = NULL; + } + + // 10-25 Ken + if (radar_dbscan_p == 1) + { + free(points_p); + radar_dbscan_p = 0; + } + // printf("---------------- build_radar_data_json end\n"); +} + +#if 1 +void radar_data_parser() +{ + int iBlockDataSize; + char *sBlockDataBuffer; + int iCurrentRead = 0; + int iDoCreateJson = 0; + + while (1) + { + if (RadarQueueSize() > 0) + { + // printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< queue size: %d \n", RadarQueueSize()); + + RadarFrameData qPopRadarData = {0}; + + qPopRadarData = RadarQueueFront(); + RadarQueuePop(); + + iCurrentRead = 0; + iBlockDataSize = 0; + + // radar_start_status + // printf("<<<<<<<<<<<< pop queue, data size = %d, blocknum: %d \n", qPopRadarData.iDataSize, qPopRadarData.iDataBlockNumber); + + if (qPopRadarData.iDataBlockNumber > 0) + { + for (int i = 0; i < qPopRadarData.iDataBlockNumber; i++) + { + iBlockDataSize = qPopRadarData.iDataBlockArray[i]; + // printf("-%d ", qPopRadarData.iDataBlockArray[i]); + + if (i == 0 && iBlockDataSize != 40) + { + printf("=======================> break 40 byte! \n"); + break; + } + else if (i == 0 && iBlockDataSize == 40) + { + iCurrentRead = 40; + continue; + } + + sBlockDataBuffer = qPopRadarData.frame_buffer + iCurrentRead; + iCurrentRead += iBlockDataSize; + // printf("this correct_ttype a: %d \n", iBlockDataSize); + if (Is_correct_ttype_P(sBlockDataBuffer, iBlockDataSize) == 1) + { + // printf("\n----------decode_stage #2: find correct ttype\n"); + // printf("this correct_ttype b: %d \n", iBlockDataSize); + g_check_if_is_correct_ttype_P = 1; // get 8byte data + } + else if (g_check_if_is_correct_ttype_P == 1) + { + run_general_ttype_P(sBlockDataBuffer, iBlockDataSize); // radar_data_array_p ----> ???o?a??R?p?F??? + g_check_if_is_correct_ttype_P = 0; + iDoCreateJson = 1; + } + } + // printf("\n"); + } + + // printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> %d \n", g_current_radar_data_index); + + if (g_current_radar_data_index_P >= 1) + { + // build_radar_data_json_p(); + } + + if (iDoCreateJson == 1) + { + printf("FrameNum = %ld \n", radar_service_data_p.frameNumber); + build_radar_data_json_p(); + iDoCreateJson = 0; + } + + memset(&radar_service_data_p, 0x00, sizeof(RadarServiceInfo_P)); + memset(&radar_data_array_p, 0x00, MAX_SIZE_RADAR_DATA_P * sizeof(RadarDataInfo_P)); + g_current_radar_data_index_P = 0; + } + + usSleep(1); + } +} +#endif + +// update radar json leo 11-25 +extern pthread_mutex_t mutex_radar_json; +void update_radar_json_p() +{ + // pthread_detach(pthread_self()); + char buf[1024] = {}; + + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + // printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + // printf("exePath:%s\n", exePath); + char radarPATH[1024]; + strcpy(radarPATH, exePath); + strcat(radarPATH, "radar.json"); + char *filename = radarPATH; + pthread_mutex_lock(&mutex_radar_json); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else + { + + char *fileBuf = ReadAllBytes(filename); + pthread_mutex_unlock(&mutex_radar_json); + if (fileBuf) + { + + cJSON *radar_root; + radar_root = cJSON_Parse(fileBuf); + cJSON *camera, *tmp_root; + //int value = 0; + + if (radar_root) + { + if (cJSON_HasObjectItem(radar_root, "radar_x_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "radar_x_axis"); + json_radar_x_axis_p = tmp_root->valueint; + } + else + { + printf("get radar.json radar_x_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "radar_y_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "radar_y_axis"); + json_radar_y_axis_p = tmp_root->valueint; + } + else + { + printf("get radar.json radar_y_axis_p error \n"); + } + if (cJSON_HasObjectItem(radar_root, "target_x_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "target_x_axis"); + json_target_x_axis_p = tmp_root->valueint; + } + else + { + printf("get radar.json target_x_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "target_y_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "target_y_axis"); + json_target_y_axis_p = tmp_root->valueint; + } + else + { + printf("get radar.json target_y_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "radar_section_degree")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "radar_section_degree"); + json_radar_section_degree_p = tmp_root->valueint; + } + else + { + printf("get radar.json radar_section_degree error \n"); + } + + if (cJSON_HasObjectItem(radar_root, "distance_meter")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "distance_meter"); + json_distance_meter_p = tmp_root->valueint; + } + else + { + printf("get radar.json distance_meter error \n"); + } + + if (cJSON_HasObjectItem(radar_root, "distance_meter_y")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "distance_meter_y"); + json_distance_meter_y_p = tmp_root->valueint; + } + else + { + printf("get radar.json distance_meter_y error \n"); + } + + if (cJSON_HasObjectItem(radar_root, "enable_camera")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "enable_camera"); + if (cJSON_IsTrue(tmp_root)) + { + // printf("enable_camera is True"); + json_enable_camera_p = true; + } + else + { + // printf("enable_camera is False"); + json_enable_camera_p = false; + } + } + else + { + printf("get radar.json enable_camera error \n"); + } + + if (!(camera = cJSON_GetObjectItem(radar_root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + } + else + { + if (cJSON_HasObjectItem(camera, "world_camera_x_axis")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_x_axis"); + json_world_camera_x_axis_p = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_x_axis error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_y_axis")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_y_axis"); + json_world_camera_y_axis_p = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_y_axis error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_degree")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_degree"); + json_world_camera_degree_p = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_degree error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_home_point_degree")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_home_point_degree"); + json_world_camera_home_point_degree_p = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_home_point_degree error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_degree_offset")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_degree_offset"); + json_world_camera_degree_offset_p = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_degree_offset error \n"); + } + + if (cJSON_HasObjectItem(camera, "camera_ip")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_ip"); + sprintf(json_ptz_ip_p, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_ip error \n"); + } + + if (cJSON_HasObjectItem(camera, "camera_port")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_port"); + sprintf(json_ptz_port_num_p, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_port error \n"); + } + if (cJSON_HasObjectItem(camera, "camera_username")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_username"); + sprintf(json_ptz_username_p, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_username error \n"); + } + if (cJSON_HasObjectItem(camera, "camera_password")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_password"); + sprintf(json_ptz_password_p, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_password error \n"); + } + + printf("update radar.json \n"); + char *JsonString = cJSON_Print(radar_root); + // printf("JsonString: %s\n", JsonString); + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open radar.json \n"); + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (radar_root) + { + free(radar_root); + radar_root = NULL; + } + } + } + + usSleep(1000); + + // pthread_exit(NULL); + } +} + +int radar_to_ptz_control(float radar_x, float radar_y) +{ + // int json_radar_x_axis = 400; + // int json_radar_y_axis = 500; + // int json_target_x_axis = 400; + // int json_target_y_axis = 100; + // int json_camera_x_axis = 100; + // int json_camera_y_axis = 300; + // int json_distance_meter = 50; + printf("para: r(%d,%d) t(%d,%d) p(%d,%d) meter(%d) degree&offset:(%d,%d) \n", json_radar_x_axis_p, json_radar_y_axis_p, json_target_x_axis_p, json_target_y_axis_p, json_world_camera_x_axis_p, json_world_camera_y_axis_p, json_distance_meter_p, json_world_camera_degree_p, json_world_camera_degree_offset_p); + printf("radar_to_ptz_control() input radar: (%f, %f) \n", radar_x, radar_y); + + // float ab_len = sqrt((float)((json_radar_x_axis - json_target_x_axis) * (json_radar_x_axis - json_target_x_axis)) + (float)((json_radar_y_axis - json_target_y_axis) * (json_radar_y_axis - json_target_y_axis))); + float local_a_x = 0; + float local_a_y = 0; + float local_e_x = (float)(json_world_camera_x_axis_p - json_radar_x_axis_p) / (800 / (float)json_distance_meter_p); + float local_e_y = -(float)(json_world_camera_y_axis_p - json_radar_y_axis_p) / (600 / (float)json_distance_meter_y_p); + float x_offset = local_e_x; + float y_offset = local_e_y; + + // printf("radar_to_ptz_control() ptz : (%d, %d) \n", local_e_x, local_e_y); + + local_a_x = local_a_x - x_offset; + local_a_y = local_a_y - y_offset; + float local_radar_x = radar_x - x_offset; + float local_radar_y = radar_y - y_offset; + local_e_x = local_e_x - x_offset; + local_e_y = local_e_y - y_offset; + + // cos theta = vector a dot vector b / |vector a| * |vector b| + float theta = acos(((local_radar_x * local_a_x) + (local_radar_y * (local_a_y))) / (sqrt((local_radar_x * local_radar_x) + (local_radar_y * local_radar_y)) * sqrt((local_a_x * local_a_x) + (local_a_y * local_a_y)))) * 180 / PI; + + printf("radar_to_ptz_control() theta A : %f \n", theta); + printf("radar_to_ptz_control() home point degree : %d \n", json_world_camera_home_point_degree_p); + printf("radar_to_ptz_control() theta offset : %d \n", json_world_camera_degree_offset_p); + printf("radar_to_ptz_control() radar target in PTZ degree : %f \n", json_world_camera_home_point_degree_p - theta); + + if (json_world_camera_x_axis_p - json_radar_x_axis_p < 0) + { + + if (json_world_camera_home_point_degree_p - theta < 0) + { + return (int)(json_world_camera_home_point_degree_p - theta) + 360; + } + if (json_world_camera_home_point_degree_p - theta > 360) + { + return (int)(json_world_camera_home_point_degree_p - theta) % 360; + } + } + else + { + if (json_world_camera_home_point_degree_p + theta < 0) + { + return (int)(json_world_camera_home_point_degree_p + theta) + 360; + } + if (json_world_camera_home_point_degree_p + theta > 360) + { + return (int)(json_world_camera_home_point_degree_p + theta) % 360; + } + } + + // return json_world_camera_home_point_degree - theta; + // return theta; + return 0; +} \ No newline at end of file diff --git a/src/radar_parser.h b/src/radar_parser.h new file mode 100644 index 0000000..1af1b51 --- /dev/null +++ b/src/radar_parser.h @@ -0,0 +1,154 @@ +#pragma once +#ifndef RADAR_PARSER_H +#define RADAR_PARSER_H +#include "define_inc.h" +#include "setting.h" +#include "utility.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define MAX_RADAR_DATA_SIZE 1920 * 1080 / 4 //= MAX_IMG_SIZE +#define RADAR_DATA_BLOCK_NUM 20 +#define RADAR_QUEUE_SIZE 10 +#define LILIN_SHIFT_P 8 +#define MAX_SIZE_LILIN_START_P 8 +#define MAX_SIZE_LILIN_TTYPE_P 2 +#define READ_OBJ_AND_VUNIT_P 2 +#define MAX_SIZE_RADAR_DATA_P 35 +#define INT_BYTE_SIZE_P 2 + +#define TTYPE_1_OBJ_FORMAT_SIZE_P 5 +#define TTYPE_2_OBJ_FORMAT_SIZE_P 4 +#define TTYPE_3_OBJ_FORMAT_SIZE_P 6 +#define TTYPE_4_OBJ_FORMAT_SIZE_P 1 + + typedef struct + { + double x, y, z; + int cluster_id, nop; // Ken 2022-10-26 add nop ( number of cluster points ) variable for rule-based classifier + } RADAR_POINT; + + typedef struct + { + long ttype; + long TLVLength; + + // v1 + float doppler; + float PeakValue; + float X; + float Y; + float Z; + + // v2 + float ccX; + float ccY; + float csX; // v2 v3 + float csY; // v2 v3 + + // v3 + float tX; + float tY; + float velX; + float velY; + + float velZ; + float accX; + float accY; + float accZ; + + float Speed; + + } RadarDataInfo_P; + + typedef union + { + unsigned char hexarray[8]; + int64_t int64; + int32_t int32; + int16_t int16; + + float float32; + } RadarConvert_P; + + typedef struct + { + long version; + long totalPacketLen; + long platform; + long frameNumber; + long cpuProcessTime; + long numOBJs; + long numTLVs; + long subFrameNumber; + + } RadarServiceInfo_P; + + typedef struct + { + char frame_buffer[MAX_RADAR_DATA_SIZE]; + int iDataSize; + + int iDataBlockArray[RADAR_DATA_BLOCK_NUM]; + int iDataBlockNumber; + + } RadarFrameData; + + extern int g_switch_radar_data_json_p; + extern char g_radar_data_json_p[BUFSIZE_V3]; + + void init_radar_parser(); + void init_axis_covert_world(); + void radar_data_get(char *recv_data, int recv_len); + void radar_data_parser(); +#ifdef GY_OS_PTZ + // void get_ptz_degree(); + // void *thread_run_get_ptz_degree(void *ptr); + // float radar_to_ptz_control(float radar_x, float radar_y); + // int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); + // int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); +#endif + + void RadarQueuePush(RadarFrameData q_info); + RadarFrameData RadarQueueFront(); + void RadarQueuePop(); + int RadarQueueSize(); + int RadarQueueIsEmpty(); + void RadarQueueClear(); + // leo 11-25 + void update_radar_json_p(); + extern int json_radar_x_axis_p; + extern int json_radar_y_axis_p; + extern int json_target_x_axis_p; + extern int json_target_y_axis_p; + + extern int json_world_camera_x_axis_p; + extern int json_world_camera_y_axis_p; + + extern int json_radar_section_degree_p; // Ken + + extern int json_world_camera_degree_p; + extern int json_world_camera_home_point_degree_p; + extern int json_world_camera_degree_offset_p; + extern int json_distance_meter_p; + extern int json_distance_meter_y_p; + + extern bool json_enable_camera_p; + + extern char json_ptz_ip_p[128]; + extern char json_ptz_port_num_p[64]; + extern char json_ptz_username_p[64]; + extern char json_ptz_password_p[64]; + + extern int json_ptz_p_degree_p; + extern int json_ptz_t_degree_p; + extern int json_ptz_z_degree_p; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/radar_receive.c b/src/radar_receive.c new file mode 100644 index 0000000..b8c1341 --- /dev/null +++ b/src/radar_receive.c @@ -0,0 +1,1807 @@ +/** + * @file radar_receive.c + * @author Leo.Huang (leo.huang@meritlilin.com.tw) + * @brief + * @version 0.1 + * @date 2022-09-28 + * + * @copyright Copyright (c) 2022 + * + */ + +#include <string.h> +#include "radar_receive.h" +#include "radar_parser.h" +#include "setting.h" +#include <pthread.h> +// #include <cmath> + + + +#ifdef GY_OS_PTZ +#include "ptz.h" +void get_ptz_degree(); +void *thread_run_get_ptz_degree(void *ptr); +// float radar_to_ptz_control(float radar_x, float radar_y); +// int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); +// int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); +void write_ptz_to_json(); +// void detect_radar_to_ptz_control(cJSON *AiRadar); +#endif + +RadarDataInfo g_current_radar_list[MAX_SIZE_RADAR_DATA] = {0}; +int g_count_radar_list = 0; + +RadarDataInfo temp_current_radar_list[MAX_SIZE_RADAR_DATA] = {0}; +int temp_count_radar_list = MAX_SIZE_RADAR_DATA; + +//RadarServiceInfo radar_service_data; + +// radar.json data tmp +int json_res_height = (int)RADAR_BG_HEIGHT; +int json_res_width = (int)RADAR_BG_WIDTH; + +// Ken +int json_radar_x_axis = 400; +int json_radar_y_axis = 500; +int json_target_x_axis = 400; +int json_target_y_axis = 100; + +int json_world_camera_x_axis = 100; +int json_world_camera_y_axis = 300; + +int json_radar_section_degree = 90; // Ken + +int json_world_camera_degree = 0; +int json_world_camera_home_point_degree = 0; +int json_world_camera_degree_offset = 0; +int json_distance_meter = 10; +int json_distance_meter_y = 10; + +char json_ptz_ip[128] = {0}; +char json_ptz_port_num[64] = {0}; +char json_ptz_username[64] = {0}; +char json_ptz_password[64] = {0}; + +#define PI 3.1415926 + +#ifdef RADAR_DRIVER + +pthread_mutex_t radar_driver_mutex; +// int g_switch_radar_receive = 0; +// char g_radar_json_data[4096]; + +void *run_radar_driver(void *arg) // a113n +{ + system("/emmc/plugin/radar_driver -f ./JBV2_record.txt"); + pthread_exit(NULL); +} + +void *RADAR_recieve(void *jsonstr) // a113n +{ + struct sockaddr_in info; + bzero(&info, sizeof(info)); + info.sin_family = AF_INET; + + // localhost test + info.sin_addr.s_addr = inet_addr("127.0.0.1"); + info.sin_port = htons(7778); + // socket���إ� TCP_PORT_IMAGE + int sockfd = 0; + // sockfd = socket(AF_INET, SOCK_STREAM, 0); + sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if (sockfd == -1) + { + printf("Fail to create a socket."); + } /* + else { + int err = connect(sockfd, (struct sockaddr *)&info, sizeof(info)); + if (err == -1) { + printf("Connection error"); + } + + }*/ + + if (bind(sockfd, (const struct sockaddr *)&info, sizeof(info)) < 0) + { + perror("error bind failed\n"); + close(sockfd); + } + + /* + if(listen(sockfd, 512) == -1){ + perror("error listen failed\n"); + close(sockfd); + }*/ + + char json_string[4096]; + + while (1) + { + + int recv_num = 0; + // int lennn = sizeof(info); + memset(json_string, 0, strlen(json_string)); + recv_num = recv(sockfd, &json_string, sizeof(json_string), 0); + + // printf("recv num = %d \n", recv_num); + + // memcpy(jsonstr, json_string, sizeof(json_string)); + + if (recv_num > 0) + { + // printf("RADAR_DRIVER recv>0\n"); + // strcat(json_string, "\r"); + // printf("RADAR_DRIVER after strcat \n"); + + // pthread_mutex_lock(&radar_driver_mutex); + // memset(jsonstr, 0, strlen(jsonstr)); + memcpy(jsonstr, json_string, 4096); + radar_receive_to_json(json_string); + // pthread_mutex_unlock(&radar_driver_mutex); + + // printf("RADAR_DRIVER after memcpy\n"); + // printf("recieved = %s\n", json_string); + } + else + { + // printf("radar recv_num <=0\n"); + } + + usSleep(80 * 1000); + + // printf("recv_num = %ld\n", recv_num); + } + + shutdown(sockfd, SHUT_RDWR); + close(sockfd); + printf("RADAR_recieve end\n"); + pthread_exit(NULL); +} + +#endif + +#ifdef RADAR_RECEIVE +// void build_radar_data_json(); +pthread_mutex_t radar_receive_mutex; + +void radar_receive_to_json(void *radar_json_data) +{ + // pthread_detach(pthread_self()); + //char json_tmp[4096]; + + // detection_pos *radar_word = NULL; + //int FrameNum_tmp = 0; + + // while (1) + // { + // pthread_mutex_lock(&radar_receive_mutex); + // memcpy(json_tmp, radar_json_data, 4096); + // pthread_mutex_unlock(&radar_receive_mutex); + // read json + // printf("radar_json_data : %s\n", radar_json_data); + cJSON *root = NULL; + + root = cJSON_Parse(radar_json_data); + if (radar_json_data == NULL) + { + printf("radar_json_data : NULL"); + // continue; + } + if (root) + { + // printf("\n========================================\n"); + // printf("radar_json_data : %s\n", radar_json_data); + + cJSON *AiRadar = NULL; + + cJSON *radar_detect, *FrameNum, *Type, *posX, *posY, *posZ, *velX, *velY, *csX, *csY, *Doppler, *Peak, *Speed; + + AiRadar = cJSON_GetObjectItem(root, "AiRadar"); + + int i = 0; + //int j = 0; + //float theta_tmp = 0; + temp_count_radar_list = MAX_SIZE_RADAR_DATA; + + if (AiRadar) + { + + cJSON_ArrayForEach(radar_detect, AiRadar) + { + + FrameNum = cJSON_GetObjectItem(radar_detect, "FrameNum"); + Type = cJSON_GetObjectItem(radar_detect, "Type"); + // printf("FrameNum : %d\n", FrameNum->valueint); + // printf("FrameNum_tmp : %d\n", FrameNum_tmp); + if (Type->valueint == 1) + { + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + // float ccX = 0.0, ccY = 0.0, csX = 0.0, csY = 0.0; //for V2 + // float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; //for V3 + posX = cJSON_GetObjectItem(radar_detect, "posX"); + posY = cJSON_GetObjectItem(radar_detect, "posY"); + posZ = cJSON_GetObjectItem(radar_detect, "posZ"); + Doppler = cJSON_GetObjectItem(radar_detect, "Doppler"); + Peak = cJSON_GetObjectItem(radar_detect, "Peak"); + Speed = cJSON_GetObjectItem(radar_detect, "Speed"); + + if (posX && posY && posZ && Doppler && Peak) + { + + temp_current_radar_list[i].ttype = (long)Type->valueint; + temp_current_radar_list[i].doppler = (float)Doppler->valuedouble; + temp_current_radar_list[i].PeakValue = (float)Peak->valuedouble; + temp_current_radar_list[i].X = (float)posX->valuedouble; + temp_current_radar_list[i].Y = (float)posY->valuedouble; + temp_current_radar_list[i].Z = (float)posZ->valuedouble; + temp_current_radar_list[i].Speed = (float)Speed->valuedouble; + // printf("V1!! ttype: %d X:%f Y:%f Z:%f\n", temp_current_radar_list[i].ttype, temp_current_radar_list[i].X, temp_current_radar_list[i].Y, temp_current_radar_list[i].Z); + i++; + } + + if (i >= temp_count_radar_list) + break; + } + else if (Type->valueint == 2) + { + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + // float ccX = 0.0, ccY = 0.0, csX = 0.0, csY = 0.0; //for V2 + // float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; //for V3 + posX = cJSON_GetObjectItem(radar_detect, "posX"); + posY = cJSON_GetObjectItem(radar_detect, "posY"); + csX = cJSON_GetObjectItem(radar_detect, "csX"); + csY = cJSON_GetObjectItem(radar_detect, "csY"); + Speed = cJSON_GetObjectItem(radar_detect, "Speed"); + + if (posX && posY && csX && csY) + { + + temp_current_radar_list[i].ttype = (long)Type->valueint; + temp_current_radar_list[i].ccX = (float)posX->valuedouble; + temp_current_radar_list[i].ccY = (float)posY->valuedouble; + temp_current_radar_list[i].X = (float)posX->valuedouble; + temp_current_radar_list[i].Y = (float)posY->valuedouble; + temp_current_radar_list[i].csX = (float)csX->valuedouble; + temp_current_radar_list[i].csY = (float)csY->valuedouble; + temp_current_radar_list[i].Speed = (float)Speed->valuedouble; + // printf("V2!! ttype: %d X:%f Y:%f Z:%f\n", temp_current_radar_list[i].ttype, temp_current_radar_list[i].X, temp_current_radar_list[i].Y, temp_current_radar_list[i].Z); + i++; + } + + if (i >= temp_count_radar_list) + break; + } + else if (Type->valueint == 3) + { + // float doppler = 0.0, PeakValue = 0.0, X = 0.0, Y = 0.0, Z = 0.0; //for V1 + // /*/float ccX = 0.0, ccY = 0.0,*/ float csX = 0.0, csY = 0.0; // for V2 + //float tX = 0.0, tY = 0.0, velX = 0.0, velY = 0.0; // for V3 + posX = cJSON_GetObjectItem(radar_detect, "posX"); + posY = cJSON_GetObjectItem(radar_detect, "posY"); + csX = cJSON_GetObjectItem(radar_detect, "csX"); + csY = cJSON_GetObjectItem(radar_detect, "csY"); + velX = cJSON_GetObjectItem(radar_detect, "velX"); + velY = cJSON_GetObjectItem(radar_detect, "velY"); + Speed = cJSON_GetObjectItem(radar_detect, "Speed"); + +// #ifdef GY_OS_PTZ +#if 0 + + if (j < MAX_RADAR_RECEIVE_NUM) + { + + theta_tmp = 0; + printf("AiRadar FrameNum : %d (x,y):(%f , %f)\n", FrameNum->valueint, posX->valuedouble, posY->valuedouble); + printf("!!!!!!!Detect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + theta_tmp = radar_to_ptz_control(posX->valuedouble, posY->valuedouble); + FrameNum_tmp = FrameNum->valueint; + // printf("AiRadar theta A : %f \n", theta_tmp); + printf(" AiRadarradar target in PTZ degree : %f \n", theta_tmp); + + if (theta_tmp < 0) + { + theta_tmp = (int)theta_tmp + 360; + } + if (theta_tmp > 360) + { + theta_tmp = (int)theta_tmp % 360; + } + + char ptz_intput_theta[10]; + sprintf(ptz_intput_theta, "%d", (int)theta_tmp); + + UpdateRemotePTZCurPos("admin", "pass", "192.168.50.200", "80", ptz_intput_theta, "20", "2"); + } +#endif + + if (posX && posY && csX && csY) + { + + temp_current_radar_list[i].ttype = (long)Type->valueint; + temp_current_radar_list[i].tX = (float)posX->valuedouble; + temp_current_radar_list[i].tY = (float)posY->valuedouble; + temp_current_radar_list[i].X = (float)posX->valuedouble; + temp_current_radar_list[i].Y = (float)posY->valuedouble; + temp_current_radar_list[i].csX = (float)csX->valuedouble; + temp_current_radar_list[i].csY = (float)csY->valuedouble; + temp_current_radar_list[i].velX = (float)velX->valuedouble; + temp_current_radar_list[i].velY = (float)velY->valuedouble; + temp_current_radar_list[i].Speed = (float)Speed->valuedouble; + // printf("V3!! ttype: %d X:%f Y:%f Z:%f\n", temp_current_radar_list[i].ttype, temp_current_radar_list[i].X, temp_current_radar_list[i].Y, temp_current_radar_list[i].Z); + + i++; + } + + if (i >= temp_count_radar_list) + break; + } + // allen's getalarmmotion FrameNum inside every token, but Jim's getalarmmotion FrameNum only one time in array + radar_service_data.frameNumber = FrameNum->valueint; + } + } + + temp_count_radar_list = i; + g_count_radar_list = temp_count_radar_list; + +#if 1 + + // if (check_if_finish_thread_bbox_list == 1) { + + if (temp_count_radar_list >= 1) + { + + // printf("\nGGGGGGGGGGG:%d\n", temp_count_bbox_list); + for (int i = 0; i < temp_count_radar_list; i++) + { + + radar_axis_covert_world(&temp_current_radar_list[i], &g_current_radar_list[i]); + + // printf("Type %ld origin(x,y): (%f,%f) transfer(x,y): (%f,%f) \n", temp_current_radar_list[i].ttype, temp_current_radar_list[i].X, temp_current_radar_list[i].Y, g_current_radar_list[i].X, g_current_radar_list[i].Y); + // g_current_radar_list[i].ttype = temp_current_radar_list[i].ttype; + // g_current_radar_list[i].TLVLength = temp_current_radar_list[i].TLVLength; + // g_current_radar_list[i].doppler = temp_current_radar_list[i].doppler; + // g_current_radar_list[i].PeakValue = temp_current_radar_list[i].PeakValue; + // g_current_radar_list[i].X = temp_current_radar_list[i].X; + // g_current_radar_list[i].Y = temp_current_radar_list[i].Y; + // g_current_radar_list[i].Z = temp_current_radar_list[i].Z; + // g_current_radar_list[i].ccX = temp_current_radar_list[i].ccX; + // g_current_radar_list[i].ccY = temp_current_radar_list[i].ccY; + // g_current_radar_list[i].csX = temp_current_radar_list[i].csX; + // g_current_radar_list[i].csY = temp_current_radar_list[i].csY; + // g_current_radar_list[i].tX = temp_current_radar_list[i].tX; + // g_current_radar_list[i].tY = temp_current_radar_list[i].tY; + // g_current_radar_list[i].velX = temp_current_radar_list[i].velX; + // g_current_radar_list[i].velY = temp_current_radar_list[i].velY; + // g_current_radar_list[i].velZ = temp_current_radar_list[i].velZ; + // g_current_radar_list[i].accX = temp_current_radar_list[i].accX; + // g_current_radar_list[i].accY = temp_current_radar_list[i].accY; + // g_current_radar_list[i].accZ = temp_current_radar_list[i].accZ; + // g_current_radar_list[i].Speed = temp_current_radar_list[i].Speed; + } + // g_count_radar_list = temp_count_radar_list; + } + else + { + g_count_radar_list = 0; + } + + if (root) + { + cJSON_Delete(root); + root = NULL; + } + + build_fake_radar_data_json(); + +#endif + + // cJSON_ArrayForEach(radar_detect, AiRadar) + // { + // FrameNum = cJSON_GetObjectItem(radar_detect, "FrameNum"); + // Type = cJSON_GetObjectItem(radar_detect, "Type"); + // printf("FrameNum_tmp : %d\n", FrameNum_tmp); + // if (Type->valueint == 3) + // { + // if (FrameNum_tmp == FrameNum->valueint) + // { + // break; + // } + // theta_tmp = 0; + // posX = cJSON_GetObjectItem(radar_detect, "posX"); + // posY = cJSON_GetObjectItem(radar_detect, "posY"); + // printf("AiRadar FrameNum : %d (x,y):(%f , %f)\n", FrameNum->valueint, posX->valuedouble, posY->valuedouble); + // printf("!!!!!!!Detect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + // theta_tmp = radar_to_ptz_control(posX->valuedouble, posY->valuedouble); + // FrameNum_tmp = FrameNum->valueint; + // // printf("AiRadar theta A : %f \n", theta_tmp); + // printf(" AiRadarradar target in PTZ degree : %f \n", theta_tmp); + + // if (theta_tmp < 0) + // { + // theta_tmp = (int)theta_tmp + 360; + // } + // if (theta_tmp > 360) + // { + // theta_tmp = (int)theta_tmp % 360; + // } + + // char ptz_intput_theta[10]; + // sprintf(ptz_intput_theta, "%d", (int)theta_tmp); + // #ifdef GY_OS_PTZ + // // UpdateRemotePTZCurPos("admin", "pass", "192.168.50.200", "80", ptz_intput_theta, "20", "2"); + // #endif + // } + // } + + usSleep(1 * 1000); + } + // pthread_exit(NULL); +} +#endif + +extern pthread_mutex_t mutex_radar_json; + +#ifdef GY_OS_PTZ +void write_ptz_to_json(char *p, char *t, char *z) +{ + // char *p[10]; + // char *t[10]; + // char *z[10]; + // int tmp; + // printf("ptz\n"); + // // UpdateRemotePTZCurPos("admin", "pass", "192.168.50.200", "80", "2", "20", "2"); + + // tmp = GetRemotePTZCruPos("admin", "pass", "192.168.50.200", "80", p, t, z); + + // printf("p: %s, t: %s, z: %s\n", p, t, z); + + // printf("end ptz\n"); + + pthread_mutex_lock(&mutex_radar_json); + char buf[1024] = {}; + + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + // printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + // printf("exePath:%s\n", exePath); + char radarPATH[1024]; + strcpy(radarPATH, exePath); + strcat(radarPATH, "radar.json"); + char *filename = radarPATH; + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else + { + + char *fileBuf = ReadAllBytes(filename); + if (fileBuf) + { + + cJSON *radar_root; + radar_root = cJSON_Parse(fileBuf); + cJSON *camera; + int value = 0; + if (!(camera = cJSON_GetObjectItem(radar_root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + // char *JsonString = "{ \" version \": 1, \" mode \": \" 50m \", " debug ": false, " trial_life_time ": 5, " calibration_radar ": false, " scale_factor ": 200, " enable_camera ": true, " distance_meter ": 10, " distance_format ": " meter ", " camera ": { " calibration_camera ": true, " world_camera_degree ": 17, " world_camera_distance ": 4, " world_camera_height ": 2, " camera_ip ": " 140.118.120.52 ", " camera_port ": " 80 ", " camera_sub_url ": " / stream0 ", " auth_key ": " Basic YWRtaW46bXNwbHNpZ25hbA == ", " auto_zoom ": true, " zoom_max ": 20, " use_camera_object_detection ": true, " enable_camera_tracking ": false, " enable_calibration_radar ": false, " ip_setting ": false, " camera_username ": " admin ", " camera_password ": " Pass1234 " }, " world_radar_degree ": 100, " world_radar_height ": 20, " radar_show_point_cloud ": true, " radar_show_target ": true, " radar_section_degree ": 60, " target_x_axis ": 408, " target_y_axis ": 74, " radar_x_axis ": 334, " radar_y_axis ": 514}"; + // char *JsonString = "{ \" version \": 1, \" mode \": \" 50m \"} "; + // FILE *fp; + // if ((fp = fopen(filename, "w")) != NULL) + // { + // fprintf(fp, JsonString); + // fclose(fp); + + // } + // else + // { + // printf("Fail to open radar.json \n"); + // } + // if (JsonString != NULL) + // { + // free(JsonString); + // JsonString = NULL; + // } + } + else + { + if (cJSON_HasObjectItem(camera, "world_camera_degree")) + { + printf("detect fileBuf \n"); + value = atoi(p); + printf("detect fileBuf \n"); + cJSON_ReplaceItemInObject(camera, "world_camera_degree", cJSON_CreateNumber(value)); + printf("setting radar.json world_camera_degree = %d \n", value); + } + else + { + printf("setting radar.json world_camera_degree error \n"); + } + + char *JsonString = cJSON_Print(radar_root); + // printf("JsonString: %s\n", JsonString); + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open radar.json \n"); + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (radar_root) + { + free(radar_root); + radar_root = NULL; + } + } + } + pthread_mutex_unlock(&mutex_radar_json); + // usSleep(100 * 1000); +} +#endif + +// float radar_to_ptz_control(float radar_x, float radar_y) +// { +// // int json_radar_x_axis = 400; +// // int json_radar_y_axis = 500; +// // int json_target_x_axis = 400; +// // int json_target_y_axis = 100; +// // int json_camera_x_axis = 100; +// // int json_camera_y_axis = 300; +// // int json_distance_meter = 50; +// printf("para: r(%d,%d) t(%d,%d) p(%d,%d) meter(%d) degree&offset:(%d,%d) \n", json_radar_x_axis_p, json_radar_y_axis_p, json_target_x_axis_p, json_target_y_axis_p, json_world_camera_x_axis_p, json_world_camera_y_axis_p, json_distance_meter_p, json_world_camera_degree_p, json_world_camera_degree_offset_p); +// printf("radar_to_ptz_control() input radar: (%f, %f) \n", radar_x, radar_y); + +// // float ab_len = sqrt((float)((json_radar_x_axis - json_target_x_axis) * (json_radar_x_axis - json_target_x_axis)) + (float)((json_radar_y_axis - json_target_y_axis) * (json_radar_y_axis - json_target_y_axis))); +// float local_a_x = 0; +// float local_a_y = 0; +// float local_e_x = (float)(json_world_camera_x_axis_p - json_radar_x_axis_p) / (800 / (float)json_distance_meter_p); +// float local_e_y = -(float)(json_world_camera_y_axis_p - json_radar_y_axis_p) / (800 / (float)json_distance_meter_p); +// float x_offset = local_e_x; +// float y_offset = local_e_y; + +// // printf("radar_to_ptz_control() ptz : (%d, %d) \n", local_e_x, local_e_y); + +// local_a_x = local_a_x - x_offset; +// local_a_y = local_a_y - y_offset; +// float local_radar_x = radar_x - x_offset; +// float local_radar_y = radar_y - y_offset; +// local_e_x = local_e_x - x_offset; +// local_e_y = local_e_y - y_offset; + +// // cos theta = vector a dot vector b / |vector a| * |vector b| +// float theta = acos(((local_radar_x * local_a_x) + (local_radar_y * (local_a_y))) / (sqrt((local_radar_x * local_radar_x) + (local_radar_y * local_radar_y)) * sqrt((local_a_x * local_a_x) + (local_a_y * local_a_y)))) * 180 / PI; + +// printf("radar_to_ptz_control() theta A : %f \n", theta); +// printf("radar_to_ptz_control() home point degree : %d \n", json_world_camera_home_point_degree_p); +// printf("radar_to_ptz_control() theta offset : %d \n", json_world_camera_degree_offset_p); +// printf("radar_to_ptz_control() radar target in PTZ degree : %f \n", json_world_camera_home_point_degree_p - theta); + +// if (json_world_camera_home_point_degree_p - theta < 0) +// { +// return (int)(json_world_camera_home_point_degree_p - theta) + 360; +// } +// if (json_world_camera_home_point_degree_p - theta > 360) +// { +// return (int)(json_world_camera_home_point_degree_p - theta) % 360; +// } + +// // return json_world_camera_home_point_degree - theta; +// // return theta; +// } + +void radar_axis_covert_world(RadarDataInfo *local_radar_list, RadarDataInfo *world_radar_list) +{ + // 紅灰點距離 + float ab_len = sqrt((float)((json_radar_x_axis - json_target_x_axis) * (json_radar_x_axis - json_target_x_axis)) + (float)((json_radar_y_axis - json_target_y_axis) * (json_radar_y_axis - json_target_y_axis))); + float scalex = ab_len / (float)json_distance_meter; + //float scaley = ab_len / (float)json_distance_meter_y; + float rotate_theta = (atan((float)(json_target_y_axis - json_radar_y_axis) / (float)(json_target_x_axis - json_radar_x_axis + 0.001)) * 180 / PI) - 90; + float world_radar_x, world_radar_y; + // document->getElementById("world_radar_degree")->innerHTML = 360 + round(rotate_theta); + // var test_x = round(cos((-rotate_theta) * PI / 180) * (local_radar_list->X * scalex) - sin((-rotate_theta) * PI / 180) * (local_radar_list->Y * scalex)) + json_radar_x_axis; + // var test_y = json_radar_y_axis - round(sin((-rotate_theta) * PI / 180) * (local_radar_list->X * scalex) + cos((-rotate_theta) * PI / 180) * (local_radar_list->Y * scalex)); + + if (json_target_x_axis >= json_radar_x_axis) + { + world_radar_x = round(cos((-rotate_theta + 180) * PI / 180) * (local_radar_list->X * scalex) - sin((-rotate_theta + 180) * PI / 180) * (local_radar_list->Y * scalex)) + json_radar_x_axis; + world_radar_y = json_radar_y_axis - round(sin((-rotate_theta + 180) * PI / 180) * (local_radar_list->X * scalex) + cos((-rotate_theta + 180) * PI / 180) * (local_radar_list->Y * scalex)); + } + else + { + world_radar_x = round(cos((-rotate_theta) * PI / 180) * (local_radar_list->X * scalex) - sin((-rotate_theta) * PI / 180) * (local_radar_list->Y * scalex)) + json_radar_x_axis; + world_radar_y = json_radar_y_axis - round(sin((-rotate_theta) * PI / 180) * (local_radar_list->X * scalex) + cos((-rotate_theta) * PI / 180) * (local_radar_list->Y * scalex)); + } + + // printf("local origin(x,y): (%f,%f) transfer(x,y): (%f,%f) \n", local_radar_list->X, local_radar_list->Y, world_radar_x, world_radar_y); + + if (local_radar_list->ttype == 1) + { + world_radar_list->X = world_radar_x; + world_radar_list->Y = world_radar_y; + world_radar_list->ccX = local_radar_list->ccX; + world_radar_list->ccY = local_radar_list->ccY; + world_radar_list->tX = local_radar_list->tX; + world_radar_list->tY = local_radar_list->tY; + } + else if (local_radar_list->ttype == 2) + { + world_radar_list->X = local_radar_list->X; + world_radar_list->Y = local_radar_list->Y; + world_radar_list->ccX = world_radar_x; + world_radar_list->ccY = world_radar_y; + world_radar_list->tX = local_radar_list->tX; + world_radar_list->tY = local_radar_list->tY; + } + else if (local_radar_list->ttype == 3) + { + world_radar_list->X = local_radar_list->X; + world_radar_list->Y = local_radar_list->Y; + world_radar_list->ccX = local_radar_list->ccX; + world_radar_list->ccY = local_radar_list->ccY; + world_radar_list->tX = world_radar_x; + world_radar_list->tY = world_radar_y; + } + + world_radar_list->ttype = local_radar_list->ttype; + world_radar_list->TLVLength = local_radar_list->TLVLength; + world_radar_list->doppler = local_radar_list->doppler; + world_radar_list->PeakValue = local_radar_list->PeakValue; + // world_radar_list->X = local_radar_list->X; + // world_radar_list->Y = local_radar_list->Y; + world_radar_list->Z = local_radar_list->Z; + // world_radar_list->ccX = local_radar_list->ccX; + // world_radar_list->ccY = local_radar_list->ccY; + world_radar_list->csX = local_radar_list->csX; + world_radar_list->csY = local_radar_list->csY; + // world_radar_list->tX = local_radar_list->tX; + // world_radar_list->tY = local_radar_list->tY; + world_radar_list->velX = local_radar_list->velX; + world_radar_list->velY = local_radar_list->velY; + world_radar_list->velZ = local_radar_list->velZ; + world_radar_list->accX = local_radar_list->accX; + world_radar_list->accY = local_radar_list->accY; + world_radar_list->accZ = local_radar_list->accZ; + world_radar_list->Speed = local_radar_list->Speed; +} + +// void build_fake_radar_data_json() +// { +// cJSON *root = NULL; +// cJSON *AiRadar, *detectArrayRadar, *detectRadar; + +// /* +// cJSON *FrameNum, *tid, *posX, *posY, *posZ, *velX, *velY, *velZ, +// *accX, *accY, *accZ, *ccX, *ccY, *csX, *csY, *tX, *tY, *Doppler; +// */ + +// root = cJSON_CreateObject(); + +// AiRadar = cJSON_CreateObject(); +// cJSON_AddItemToObject(root, "AiRadar", AiRadar); + +// time_t current_time = time(0); +// char c_current_time[20] = {0}; +// sprintf(c_current_time, "%ld", current_time); +// cJSON_AddItemToObject(AiRadar, "Time", cJSON_CreateString(c_current_time)); + +// // if (current_time_tmp != current_time) +// // { +// // printf("current_time_tmp %d FPS: %d\n", current_time, current_time_count); +// // current_time_tmp = current_time; +// // current_time_count = 0; +// // } +// // else +// // { +// // current_time_count++; +// // } + +// char c_framenum[20] = {0}; +// sprintf(c_framenum, "%ld", radar_service_data.frameNumber); +// cJSON_AddItemToObject(AiRadar, "FrameNum", cJSON_CreateString(c_framenum)); + +// char c_radar_x_axis[20] = {0}; +// sprintf(c_radar_x_axis, "%ld", json_radar_x_axis); +// cJSON_AddItemToObject(AiRadar, "radar_x_axis", cJSON_CreateString(c_radar_x_axis)); + +// char c_radar_y_axis[20] = {0}; +// sprintf(c_radar_y_axis, "%ld", json_radar_y_axis); +// cJSON_AddItemToObject(AiRadar, "radar_y_axis", cJSON_CreateString(c_radar_y_axis)); + +// char c_target_x_axis[20] = {0}; +// sprintf(c_target_x_axis, "%ld", json_target_x_axis); +// cJSON_AddItemToObject(AiRadar, "target_x_axis", cJSON_CreateString(c_target_x_axis)); + +// char c_target_y_axis[20] = {0}; +// sprintf(c_target_y_axis, "%ld", json_target_y_axis); +// cJSON_AddItemToObject(AiRadar, "target_y_axis", cJSON_CreateString(c_target_y_axis)); + +// char c_distance_meter[20] = {0}; +// sprintf(c_distance_meter, "%ld", json_distance_meter); +// cJSON_AddItemToObject(AiRadar, "distance_meter", cJSON_CreateString(c_distance_meter)); + +// detectArrayRadar = cJSON_CreateArray(); +// cJSON_AddItemToObject(AiRadar, "RadarArray", detectArrayRadar); + +// for (int i = 0; i < g_current_radar_data_index; i++) +// { +// detectRadar = cJSON_CreateObject(); +// cJSON_AddItemToArray(detectArrayRadar, detectRadar); + +// char c_tid[10] = {0}; +// sprintf(c_tid, "%d", i); +// cJSON_AddItemToObject(detectRadar, "tid", cJSON_CreateString(c_tid)); + +// char c_ttype[10] = {0}; +// sprintf(c_ttype, "%ld", radar_data_array[i].ttype); +// cJSON_AddItemToObject(detectRadar, "Type", cJSON_CreateString(c_ttype)); + +// if (radar_data_array[i].ttype == 1) +// { +// char c_posX[20] = {0}; +// sprintf(c_posX, "%f", temp_current_radar_list[i].X); +// cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + +// char c_posY[20] = {0}; +// sprintf(c_posY, "%f", temp_current_radar_list[i].Y); +// cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + +// char c_posZ[20] = {0}; +// sprintf(c_posZ, "%f", radar_data_array[i].Z); +// cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString(c_posZ)); + +// cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + +// char c_doppler[20] = {0}; +// sprintf(c_doppler, "%f", radar_data_array[i].doppler); +// cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString(c_doppler)); + +// char c_PeakValue[20] = {0}; +// sprintf(c_PeakValue, "%f", radar_data_array[i].PeakValue); +// cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString(c_PeakValue)); + +// cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +// #if 1 // leo 09-29 +// char c_local_radar_x[20] = {0}; +// sprintf(c_local_radar_x, "%d", (int)world_radar_data_array[i].X); +// cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + +// char c_local_radar_y[20] = {0}; +// sprintf(c_local_radar_y, "%d", (int)world_radar_data_array[i].Y); +// cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + +// if (world_radar_data_array[i].X >= 0 && world_radar_data_array[i].X < RADAR_BG_WIDTH) +// { +// if (world_radar_data_array[i].Y >= 0 && world_radar_data_array[i].Y < RADAR_BG_HEIGHT) +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); +// } +// else +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); +// } +// } +// else +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); +// } +// #endif +// } +// else if (radar_data_array[i].ttype == 2) +// { +// char c_posX[20] = {0}; +// sprintf(c_posX, "%f", radar_data_array[i].ccX); +// cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + +// char c_posY[20] = {0}; +// sprintf(c_posY, "%f", radar_data_array[i].ccY); +// cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + +// cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString(c_posX)); +// cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString(c_posY)); + +// char c_csX[20] = {0}; +// sprintf(c_csX, "%f", radar_data_array[i].csX); +// cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + +// char c_csY[20] = {0}; +// sprintf(c_csY, "%f", radar_data_array[i].csY); +// cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + +// cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +// #if 1 // leo 09-29 +// char c_local_radar_x[20] = {0}; +// sprintf(c_local_radar_x, "%d", (int)world_radar_data_array[i].ccX); +// cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + +// char c_local_radar_y[20] = {0}; +// sprintf(c_local_radar_y, "%d", (int)world_radar_data_array[i].ccY); +// cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + +// if (world_radar_data_array[i].ccX >= 0 && world_radar_data_array[i].ccX < RADAR_BG_WIDTH) +// { +// if (world_radar_data_array[i].ccY >= 0 && world_radar_data_array[i].ccY < RADAR_BG_HEIGHT) +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); +// } +// else +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); +// } +// } +// else +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); +// } + +// #endif +// } +// else if (radar_data_array[i].ttype == 3) +// { +// char c_posX[20] = {0}; +// sprintf(c_posX, "%f", radar_data_array[i].tX); +// cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + +// char c_posY[20] = {0}; +// sprintf(c_posY, "%f", radar_data_array[i].tY); +// cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + +// cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + +// char c_velX[20] = {0}; +// sprintf(c_velX, "%f", radar_data_array[i].velX); +// cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString(c_velX)); + +// char c_velY[20] = {0}; +// sprintf(c_velY, "%f", radar_data_array[i].velY); +// cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString(c_velY)); + +// cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + +// char c_csX[20] = {0}; +// sprintf(c_csX, "%f", radar_data_array[i].csX); +// cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + +// char c_csY[20] = {0}; +// sprintf(c_csY, "%f", radar_data_array[i].csY); +// cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + +// char c_tX[20] = {0}; +// sprintf(c_tX, "%f", radar_data_array[i].tX); +// cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString(c_tX)); + +// char c_tY[20] = {0}; +// sprintf(c_tY, "%f", radar_data_array[i].tY); +// cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString(c_tY)); + +// cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); +// cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + +// char c_Speed[20] = {0}; +// sprintf(c_Speed, "%f", radar_data_array[i].Speed); +// cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString(c_Speed)); + +// #if 1 // leo 09-29 +// char c_local_radar_x[20] = {0}; +// sprintf(c_local_radar_x, "%d", (int)world_radar_data_array[i].tX); +// cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + +// char c_local_radar_y[20] = {0}; +// sprintf(c_local_radar_y, "%d", (int)world_radar_data_array[i].tY); +// cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + +// if (world_radar_data_array[i].tX >= 0 && world_radar_data_array[i].tX < RADAR_BG_WIDTH) +// { +// if (world_radar_data_array[i].tY >= 0 && world_radar_data_array[i].tY < RADAR_BG_HEIGHT) +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); +// } +// else +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); +// } +// } +// else +// { +// cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); +// } + +// #endif +// } +// } + +// char *JsonString = NULL; + +// if (root) +// { +// JsonString = cJSON_PrintUnformatted(root); + +// // if (time_i % 2 == 0) +// // { +// // c1 = clock(); +// // // printf("getStream start time_i %d c1 %d\n", time_i, c1); +// // } +// // else if (time_i % 2 == 1) +// // { +// // c2 = clock(); +// // double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); +// // double dfps = (1 / dDiff); +// // // printf(" c2 - c1 %d time_i %d recognition time: %f FPS: %f.2 c2 %d \n", (c2 - c1), time_i, dDiff, dfps, c2); +// // printf("receive time: %f FPS: %f.2 \n", dDiff, dfps); +// // c1 = 0; +// // c2 = 0; +// // } + +// if (g_switch_radar_data_json == 0) +// { +// strcpy(g_radar_data_json, JsonString); +// // printf("\n--------g_radar_data_json:%s\n", g_radar_data_json); +// g_switch_radar_data_json = 1; +// } +// // time_i++; +// } + +// if (JsonString != NULL) +// { +// free(JsonString); +// JsonString = NULL; +// } + +// if (root) +// { +// cJSON_Delete(root); +// root = NULL; +// } +// } + +void build_fake_radar_data_json() +{ + cJSON *root = NULL; + cJSON *AiRadar, *detectArrayRadar, *detectRadar; + + /* + cJSON *FrameNum, *tid, *posX, *posY, *posZ, *velX, *velY, *velZ, + *accX, *accY, *accZ, *ccX, *ccY, *csX, *csY, *tX, *tY, *Doppler; + */ + + root = cJSON_CreateObject(); + + AiRadar = cJSON_CreateObject(); + cJSON_AddItemToObject(root, "AiRadar", AiRadar); + + time_t current_time = time(0); + char c_current_time[20] = {0}; + sprintf(c_current_time, "%ld", current_time); + cJSON_AddItemToObject(AiRadar, "Time", cJSON_CreateString(c_current_time)); + + char c_framenum[20] = {0}; + sprintf(c_framenum, "%ld", radar_service_data.frameNumber); + cJSON_AddItemToObject(AiRadar, "FrameNum", cJSON_CreateString(c_framenum)); + + char c_radar_x_axis[20] = {0}; + sprintf(c_radar_x_axis, "%d", json_radar_x_axis); + cJSON_AddItemToObject(AiRadar, "radar_x_axis", cJSON_CreateString(c_radar_x_axis)); + + char c_radar_y_axis[20] = {0}; + sprintf(c_radar_y_axis, "%d", json_radar_y_axis); + cJSON_AddItemToObject(AiRadar, "radar_y_axis", cJSON_CreateString(c_radar_y_axis)); + + char c_target_x_axis[20] = {0}; + sprintf(c_target_x_axis, "%d", json_target_x_axis); + cJSON_AddItemToObject(AiRadar, "target_x_axis", cJSON_CreateString(c_target_x_axis)); + + char c_target_y_axis[20] = {0}; + sprintf(c_target_y_axis, "%d", json_target_y_axis); + cJSON_AddItemToObject(AiRadar, "target_y_axis", cJSON_CreateString(c_target_y_axis)); + + char c_distance_meter[20] = {0}; + sprintf(c_distance_meter, "%d", json_distance_meter); + cJSON_AddItemToObject(AiRadar, "distance_meter", cJSON_CreateString(c_distance_meter)); + + detectArrayRadar = cJSON_CreateArray(); + cJSON_AddItemToObject(AiRadar, "RadarArray", detectArrayRadar); + + for (int i = 0; i < g_count_radar_list; i++) + { + detectRadar = cJSON_CreateObject(); + cJSON_AddItemToArray(detectArrayRadar, detectRadar); + + char c_tid[10] = {0}; + sprintf(c_tid, "%d", i); + cJSON_AddItemToObject(detectRadar, "tid", cJSON_CreateString(c_tid)); + + char c_ttype[10] = {0}; + sprintf(c_ttype, "%ld", g_current_radar_list[i].ttype); + cJSON_AddItemToObject(detectRadar, "Type", cJSON_CreateString(c_ttype)); + + if (g_current_radar_list[i].ttype == 1) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", temp_current_radar_list[i].X); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", temp_current_radar_list[i].Y); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + char c_posZ[20] = {0}; + sprintf(c_posZ, "%f", g_current_radar_list[i].Z); + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString(c_posZ)); + + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + + char c_doppler[20] = {0}; + sprintf(c_doppler, "%f", g_current_radar_list[i].doppler); + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString(c_doppler)); + + char c_PeakValue[20] = {0}; + sprintf(c_PeakValue, "%f", g_current_radar_list[i].PeakValue); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString(c_PeakValue)); + + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)g_current_radar_list[i].X); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)g_current_radar_list[i].Y); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (g_current_radar_list[i].X >= 0 && g_current_radar_list[i].X < RADAR_BG_WIDTH) + { + if (g_current_radar_list[i].Y >= 0 && g_current_radar_list[i].Y < RADAR_BG_HEIGHT) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#endif + } + else if (g_current_radar_list[i].ttype == 2) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", temp_current_radar_list[i].ccX); + // sprintf(c_posX, "%f", g_current_radar_list[i].X); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", temp_current_radar_list[i].ccY); + // sprintf(c_posY, "%f", g_current_radar_list[i].Y); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString(c_posX)); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString(c_posY)); + + char c_csX[20] = {0}; + sprintf(c_csX, "%f", g_current_radar_list[i].csX); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + + char c_csY[20] = {0}; + sprintf(c_csY, "%f", g_current_radar_list[i].csY); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString("")); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)g_current_radar_list[i].X); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)g_current_radar_list[i].Y); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (g_current_radar_list[i].X >= 0 && g_current_radar_list[i].X < RADAR_BG_WIDTH) + { + if (g_current_radar_list[i].Y >= 0 && g_current_radar_list[i].Y < RADAR_BG_HEIGHT) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#endif + } + else if (g_current_radar_list[i].ttype == 3) + { + char c_posX[20] = {0}; + sprintf(c_posX, "%f", temp_current_radar_list[i].tX); + // sprintf(c_posX, "%f", g_current_radar_list[i].X); + cJSON_AddItemToObject(detectRadar, "PosX", cJSON_CreateString(c_posX)); + + char c_posY[20] = {0}; + sprintf(c_posY, "%f", temp_current_radar_list[i].tY); + // sprintf(c_posY, "%f", g_current_radar_list[i].Y); + cJSON_AddItemToObject(detectRadar, "PosY", cJSON_CreateString(c_posY)); + + cJSON_AddItemToObject(detectRadar, "PosZ", cJSON_CreateString("")); + + char c_velX[20] = {0}; + sprintf(c_velX, "%f", g_current_radar_list[i].velX); + cJSON_AddItemToObject(detectRadar, "velX", cJSON_CreateString(c_velX)); + + char c_velY[20] = {0}; + sprintf(c_velY, "%f", g_current_radar_list[i].velY); + cJSON_AddItemToObject(detectRadar, "velY", cJSON_CreateString(c_velY)); + + cJSON_AddItemToObject(detectRadar, "velZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accY", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "accZ", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccX", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "ccY", cJSON_CreateString("")); + + char c_csX[20] = {0}; + sprintf(c_csX, "%f", g_current_radar_list[i].csX); + cJSON_AddItemToObject(detectRadar, "csX", cJSON_CreateString(c_csX)); + + char c_csY[20] = {0}; + sprintf(c_csY, "%f", g_current_radar_list[i].csY); + cJSON_AddItemToObject(detectRadar, "csY", cJSON_CreateString(c_csY)); + + char c_tX[20] = {0}; + sprintf(c_tX, "%f", g_current_radar_list[i].tX); + cJSON_AddItemToObject(detectRadar, "tX", cJSON_CreateString(c_tX)); + + char c_tY[20] = {0}; + sprintf(c_tY, "%f", g_current_radar_list[i].tY); + cJSON_AddItemToObject(detectRadar, "tY", cJSON_CreateString(c_tY)); + + cJSON_AddItemToObject(detectRadar, "Doppler", cJSON_CreateString("")); + cJSON_AddItemToObject(detectRadar, "Peak", cJSON_CreateString("")); + + char c_Speed[20] = {0}; + sprintf(c_Speed, "%f", g_current_radar_list[i].Speed); + cJSON_AddItemToObject(detectRadar, "Speed", cJSON_CreateString(c_Speed)); + +#if 1 // leo 09-29 + char c_local_radar_x[20] = {0}; + sprintf(c_local_radar_x, "%d", (int)g_current_radar_list[i].X); + cJSON_AddItemToObject(detectRadar, "world_radar_x", cJSON_CreateString(c_local_radar_x)); + + char c_local_radar_y[20] = {0}; + sprintf(c_local_radar_y, "%d", (int)g_current_radar_list[i].Y); + cJSON_AddItemToObject(detectRadar, "world_radar_y", cJSON_CreateString(c_local_radar_y)); + + if (g_current_radar_list[i].X >= 0 && g_current_radar_list[i].X < RADAR_BG_WIDTH) + { + if (g_current_radar_list[i].Y >= 0 && g_current_radar_list[i].Y < RADAR_BG_HEIGHT) + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("Yes")); + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } + } + else + { + cJSON_AddItemToObject(detectRadar, "plot", cJSON_CreateString("No")); + } +#endif + } + } + + char *JsonString = NULL; + + if (root) + { + JsonString = cJSON_PrintUnformatted(root); + + if (g_switch_radar_data_json_p == 0) + { + strcpy(g_radar_data_json, JsonString); + // printf("\n--------g_radar_data_json:%s\n", g_radar_data_json); + g_switch_radar_data_json_p = 1; + } + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (root) + { + cJSON_Delete(root); + root = NULL; + } +} + +void *thread_update_radar_json() +{ + // pthread_t radar_json_id; + // pthread_create(&radar_json_id, NULL, update_radar_json, NULL); + pthread_detach(pthread_self()); + while (get_bHttpServerThreadStart()) + { + update_radar_json(); + usSleep(1000000); + } + pthread_exit(NULL); +} + +void update_radar_json() +{ + // pthread_detach(pthread_self()); + char buf[1024] = {}; + + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + // printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + // printf("exePath:%s\n", exePath); + char radarPATH[1024]; + strcpy(radarPATH, exePath); + strcat(radarPATH, "radar.json"); + char *filename = radarPATH; + pthread_mutex_lock(&mutex_radar_json); + if (!FileExist(filename)) + printf("%s doesn't exist.\n", filename); + else + { + + char *fileBuf = ReadAllBytes(filename); + pthread_mutex_unlock(&mutex_radar_json); + if (fileBuf) + { + + cJSON *radar_root; + radar_root = cJSON_Parse(fileBuf); + cJSON *camera, *tmp_root; + //int value = 0; + + if (radar_root) + { + if (cJSON_HasObjectItem(radar_root, "radar_x_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "radar_x_axis"); + json_radar_x_axis = tmp_root->valueint; + } + else + { + printf("get radar.json radar_x_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "radar_y_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "radar_y_axis"); + json_radar_y_axis = tmp_root->valueint; + } + else + { + printf("get radar.json radar_y_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "target_x_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "target_x_axis"); + json_target_x_axis = tmp_root->valueint; + } + else + { + printf("get radar.json target_x_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "target_y_axis")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "target_y_axis"); + json_target_y_axis = tmp_root->valueint; + } + else + { + printf("get radar.json target_y_axis error \n"); + } + if (cJSON_HasObjectItem(radar_root, "radar_section_degree")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "radar_section_degree"); + json_radar_section_degree = tmp_root->valueint; + } + else + { + printf("get radar.json radar_section_degree error \n"); + } + + if (cJSON_HasObjectItem(radar_root, "distance_meter")) + { + tmp_root = cJSON_GetObjectItem(radar_root, "distance_meter"); + json_distance_meter = tmp_root->valueint; + } + else + { + printf("get radar.json distance_meter error \n"); + } + + if (!(camera = cJSON_GetObjectItem(radar_root, "camera"))) + { + printf("cJSON_GetObjectItem error \n"); + } + else + { + if (cJSON_HasObjectItem(camera, "world_camera_x_axis")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_x_axis"); + json_world_camera_x_axis = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_x_axis error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_y_axis")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_y_axis"); + json_world_camera_y_axis = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_y_axis error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_degree")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_degree"); + json_world_camera_degree = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_degree error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_home_point_degree")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_home_point_degree"); + json_world_camera_home_point_degree = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_home_point_degree error \n"); + } + if (cJSON_HasObjectItem(camera, "world_camera_degree_offset")) + { + tmp_root = cJSON_GetObjectItem(camera, "world_camera_degree_offset"); + json_world_camera_degree_offset = tmp_root->valueint; + } + else + { + printf("get radar.json world_camera_degree_offset error \n"); + } + + if (cJSON_HasObjectItem(camera, "camera_ip")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_ip"); + sprintf(json_ptz_ip, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_ip error \n"); + } + + if (cJSON_HasObjectItem(camera, "camera_port")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_port"); + sprintf(json_ptz_port_num, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_port error \n"); + } + if (cJSON_HasObjectItem(camera, "camera_username")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_username"); + sprintf(json_ptz_username, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_username error \n"); + } + if (cJSON_HasObjectItem(camera, "camera_password")) + { + tmp_root = cJSON_GetObjectItem(camera, "camera_password"); + sprintf(json_ptz_password, "%s", tmp_root->valuestring); + } + else + { + printf("get radar.json camera_password error \n"); + } + + printf("update radar.json \n"); + char *JsonString = cJSON_Print(radar_root); + // printf("JsonString: %s\n", JsonString); + FILE *fp; + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + + // printf("\n--------------------reload 3\n"); + // reload_dataset_from_jsonfile(); + } + else + { + printf("Fail to open radar.json \n"); + } + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + } + } + + if (fileBuf) + { + free(fileBuf); + fileBuf = NULL; + } + if (radar_root) + { + free(radar_root); + radar_root = NULL; + } + } + } + + usSleep(1000); + + // pthread_exit(NULL); +} + +#ifdef GY_OS_PTZ +// update ptz degree +void get_ptz_degree() +{ + + if (json_enable_camera_p) + { + char *p[10]; + char *t[10]; + char *z[10]; + int tmp; + int value = 0; + // printf("ptz\n"); + + // if (GetRemotePTZCruPos("admin", "Pass1234", "192.168.50.140", "80", p, t, z) != -1) + if (GetRemotePTZCruPos(json_ptz_username_p, json_ptz_password_p, json_ptz_ip_p, json_ptz_port_num_p, p, t, z) != -1) + { + // printf("p: %s, t: %s, z: %s\n", p, t, z); + + // printf("end ptz\n"); + // write_ptz_to_json(p, t, z); + value = atoi(p); + json_ptz_p_degree_p = value; + value = atoi(t); + json_ptz_t_degree_p = value; + value = atoi(z); + json_ptz_z_degree_p = value; + } + } +} + +void *thread_run_get_ptz_degree(void *ptr) +{ + + pthread_detach(pthread_self()); + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run thread get_ptz_degree\n"); + while (1) + { + // printf("get_ptz_degree\n"); + get_ptz_degree(); + + usSleep(1000000); + } + pthread_exit(NULL); +} + +#endif + +#ifdef GY_OS_PTZ + +int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +{ + + char ptz_curl_url[512] = {0}; + char ptz_curl_sendbuf[1] = {0}; + char ptz_curl_username[128] = {0}; + char ptz_curl_password[128] = {0}; + + strcat(ptz_curl_url, "http://"); + strcat(ptz_curl_url, sIP); + + // set p + strcat(ptz_curl_url, "/control?panposdegree="); + strcat(ptz_curl_url, p); + + // set t + strcat(ptz_curl_url, "&tiltposdegree="); + strcat(ptz_curl_url, t); + + // set z + strcat(ptz_curl_url, "&zoomposdegree="); + strcat(ptz_curl_url, z); + + strcat(ptz_curl_username, sUsername); + strcat(ptz_curl_password, sPassword); + + char outputData[1024]; + char *arr_sOutputDataList[MAX_PTZ_INFO]; + // int iPTZInfoCount = 0; + int curl_ret = -1; + + printf("[Update Remote PTZ]: url = %s\n", ptz_curl_url); + printf("START UpdateRemotePTZCurPos\n"); + curl_ret = net_curl_http_get(ptz_curl_url, 1, ptz_curl_username, ptz_curl_password, 60, outputData, 1024); + printf("END UpdateRemotePTZCurPos\n"); + if (curl_ret == -1) + { + // printf("net_curl_http_get ERROR\n"); + return curl_ret; + } + // printf("curl_ret after net curl ptz cmd = %d\n", curl_ret); + + return curl_ret; +} + +int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z) +{ + int cam_version = 0; + int curl_ret = -1; + char ptz_curl_url[512] = {0}; + char ptz_curl_sendbuf[1] = {0}; + char ptz_curl_username[128] = {0}; + char ptz_curl_password[128] = {0}; + char *method = "GET"; + + strcat(ptz_curl_url, "http://"); + strcat(ptz_curl_url, sIP); + strcat(ptz_curl_url, ":"); + strcat(ptz_curl_url, sPort); + + strcat(ptz_curl_username, sUsername); + strcat(ptz_curl_password, sPassword); + + char outputData[1024] = {0}; + char ptz_server[512] = {0}; + + strcat(ptz_server, "http://"); + strcat(ptz_server, sIP); + strcat(ptz_server, ":"); + strcat(ptz_server, sPort); + strcat(ptz_server, "/server"); + + // printf("[Remote PTZ]: url = %s\n", ptz_server); + // printf("START GetRemotePTZCruPos1\n"); + curl_ret = net_curl_http_get(ptz_server, 1, ptz_curl_username, ptz_curl_password, 60, outputData, 1024); + // printf("END GetRemotePTZCruPos1\n"); + if (curl_ret == -1) + { + // printf("net_curl_http_get ERROR\n"); + return curl_ret; + } + + char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; + // int iPTZInfoCount = 0; + int iGetValue = 0; + + if (strlen(outputData) > 0) // check version + { + // printf("getcurpos=%s \n", outputData); + // iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); + int split_num = StrSplit(outputData, arr_sOutputDataList, "\n"); + // printf("[Remote PTZ strsplit] num = %d\n", split_num); + char arr_sOutputDataSplit[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; + + for (int i = 0; i < split_num; i++) + { + if (strstr(arr_sOutputDataList[i], "Software Version")) + { + // printf("[Get pos] string = %s\n", arr_sOutputDataList[i]); + + // compare the version if <3.0 + + StrSplit(arr_sOutputDataList[i], arr_sOutputDataSplit, "="); + + // printf("[Get pos]: = split = [%s]\n", arr_sOutputDataSplit[1]); + + cam_version = atoi(arr_sOutputDataSplit[1]); // atof if floating point is needed. Remember to change cam_version to float above + // printf("version = %d\n", cam_version); + + if (cam_version < 3) + { + strcat(ptz_curl_url, "/control?cmd=getallposdegree"); + } + else + { + strcat(ptz_curl_url, "/control?getcurpos=1"); + } + + break; + } + } + } + + // get pos + memset(outputData, 0, 1024); + // printf("[Remote PTZ]: url = %s\n", ptz_curl_url); + // printf("START GetRemotePTZCruPos2\n"); + curl_ret = net_curl_http_get(ptz_curl_url, 1, ptz_curl_username, ptz_curl_password, 60, outputData, 1024); + // printf("END GetRemotePTZCruPos2\n"); + if (curl_ret == -1) + { + // printf("net_curl_http_get ERROR\n"); + return curl_ret; + } + + // printf("[Remote get PTZ pos] outputData = %s\n", outputData); + + if (cam_version < 3) + { + int split_num = StrSplit(outputData, arr_sOutputDataList, "\n"); + // printf("[Remote PTZ strsplit] num = %d\n", split_num); + + char temp[10][STRSPLIT_SIZE]={0}; + // printf("before strsplit\n"); + StrSplit(arr_sOutputDataList[0], temp, "="); + // printf("[PTZ pos split] p= %s\n", temp[1]); + strcpy(p, temp[1]); + StrSplit(arr_sOutputDataList[1], temp, "="); + // printf("[PTZ pos split] t= %s\n", temp[1]); + strcpy(t, temp[1]); + StrSplit(arr_sOutputDataList[2], temp, "="); + // printf("[PTZ pos split] z= %s\n", temp[1]); + strcpy(z, temp[1]); + } + else + { + int split_num = StrSplit(outputData, arr_sOutputDataList, ","); + // printf("[Remote PTZ strsplit] num = %d\n", split_num); + + strcpy(p, arr_sOutputDataList[0]); + strcpy(t, arr_sOutputDataList[1]); + strcpy(z, arr_sOutputDataList[2]); + + // printf("[PTZ] = [%s, %s, %s]\n", p, t, z); + } + + return curl_ret; +} + +#endif +// int FrameNum_tmp; +// int theta_tmp; +// void detect_radar_to_ptz_control(cJSON *AiRadar) +// { +// char *TempString = NULL; +// TempString = cJSON_PrintUnformatted(AiRadar); +// printf("TempString : %s\n", TempString); + +// // cJSON *FrameNum, *Type, *posX, *posY; +// int FrameNum, Type, posX, posY; +// FrameNum = atoi(cJSON_GetObjectItem(AiRadar, "FrameNum")->valuestring); +// printf("FrameNum : %d \n", FrameNum); +// // cJSON_ArrayForEach(detectArrayRadar, AiRadar) +// cJSON *detectArrayRadar = cJSON_GetObjectItem(AiRadar, "detectArrayRadar"); +// cJSON *detectRadar = cJSON_GetObjectItem(detectArrayRadar, "detectRadar"); +// cJSON_ArrayForEach(detectArrayRadar, AiRadar) +// { +// cJSON_ArrayForEach(detectRadar, detectArrayRadar) +// { +// Type = atoi(cJSON_GetObjectItem(detectRadar, "Type")->valuestring); + +// printf("FrameNum_tmp : %d Type: %d\n", FrameNum, Type); +// if (Type == 3) +// { +// if (FrameNum_tmp == FrameNum) +// { +// break; +// } +// theta_tmp = 0; +// posX = atof(cJSON_GetObjectItem(detectRadar, "posX")->valuestring); +// posY = atof(cJSON_GetObjectItem(detectRadar, "posY")->valuestring); +// printf("AiRadar FrameNum : %d (x,y):(%f , %f)\n", FrameNum, posX, posY); +// printf("!!!!!!!Detect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); +// theta_tmp = radar_to_ptz_control(posX, posY); +// FrameNum_tmp = FrameNum; +// // printf("AiRadar theta A : %f \n", theta_tmp); +// printf(" AiRadarradar target in PTZ degree : %d \n", theta_tmp); + +// if (theta_tmp < 0) +// { +// theta_tmp = (int)theta_tmp + 360; +// } +// if (theta_tmp > 360) +// { +// theta_tmp = (int)theta_tmp % 360; +// } + +// char ptz_intput_theta[10]; +// sprintf(ptz_intput_theta, "%d", theta_tmp); +// // UpdateRemotePTZCurPos("admin", "pass", "192.168.50.200", "80", ptz_intput_theta, "20", "2"); +// usSleep(100); +// break; +// } +// } +// } +// } diff --git a/src/radar_receive.h b/src/radar_receive.h new file mode 100644 index 0000000..219a946 --- /dev/null +++ b/src/radar_receive.h @@ -0,0 +1,144 @@ +/** + * @file radar_receive.h + * @author Leo.Huang (leo.huang@meritlilin.com.tw) + * @brief + * @version 0.1 + * @date 2022-09-28 + * + * @copyright Copyright (c) 2022 + * + */ + +#ifndef RADAR_RECIEVE_H +#define RADAR_RECIEVE_H + +#include "define_inc.h" +#include "radar_driver.h" +#include <math.h> +#include "utility.h" + +#ifndef RADAR_RECEIVE +#define RADAR_RECEIVE + +#endif + +void *run_radar_driver(void *arg); +void *RADAR_recieve(void *jsonstr); + +void update_radar_json(); +void *thread_update_radar_json(); +extern char g_radar_json_data[4096]; +extern int g_switch_radar_receive; + +extern int json_res_height; +extern int json_res_width; +extern int json_radar_x_axis; +extern int json_radar_y_axis; +extern int json_target_x_axis; +extern int json_target_y_axis; +extern int json_world_camera_x_axis; +extern int json_world_camera_y_axis; +extern int json_radar_section_degree; +extern int json_world_camera_degree; +extern int json_world_camera_home_point_degree; +extern int json_world_camera_degree_offset; +extern int json_distance_meter; +extern int json_distance_meter_y; + +extern char json_ptz_ip[128]; +extern char json_ptz_port_num[64]; +extern char json_ptz_username[64]; +extern char json_ptz_password[64]; + +#define RADAR_BG_WIDTH 800 +#define RADAR_BG_HEIGHT 600 + +// #ifdef RADAR_RECEIVE +#define MAX_RADAR_RECEIVE_NUM 1 +#define MAX_SIZE_RADAR_DATA 35 +void radar_receive_to_json(void *radar_json_data); +void build_fake_radar_data_json(); + +// typedef struct +// { +// long ttype; +// long TLVLength; + +// // v1 +// float doppler; +// float PeakValue; +// float X; +// float Y; +// float Z; + +// // v2 +// float ccX; +// float ccY; +// float csX; // v2 v3 +// float csY; // v2 v3 + +// // v3 +// float tX; +// float tY; +// float velX; +// float velY; + +// float velZ; +// float accX; +// float accY; +// float accZ; + +// float Speed; + +// } RadarDataInfo; +// typedef struct +// { +// long version; +// long totalPacketLen; +// long platform; +// long frameNumber; +// long cpuProcessTime; +// long numOBJs; +// long numTLVs; +// long subFrameNumber; + +// } RadarServiceInfo; + +//extern RadarServiceInfo radar_service_data; +// extern RadarDataInfo radar_data_array[MAX_SIZE_RADAR_DATA]; + +// #endif +#ifndef RADAR_DRIVER +#define RADAR_DRIVER + +// #ifdef RADAR_DRIVER +// #include <arpa/inet.h> +// #include <netinet/in.h> +// #include "cJSON.h" +// #endif + +// #ifndef GY_OS_PTZ +// #define GY_OS_PTZ + +#ifdef GY_OS_PTZ +void get_ptz_degree(); +void *thread_run_get_ptz_degree(void *ptr); +// float radar_to_ptz_control(float radar_x, float radar_y); +void write_ptz_to_json(); +// void detect_radar_to_ptz_control(cJSON *AiRadar); +#ifdef __cplusplus +extern "C" +{ +#endif + + extern int GetRemotePTZCruPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); + extern int UpdateRemotePTZCurPos(char *sUsername, char *sPassword, char *sIP, char *sPort, char *p, char *t, char *z); + +#ifdef __cplusplus +} +#endif +#endif + +#endif + +#endif \ No newline at end of file diff --git a/src/region_layer.c b/src/region_layer.c new file mode 100644 index 0000000..179f5e3 --- /dev/null +++ b/src/region_layer.c @@ -0,0 +1,507 @@ +#include "region_layer.h" +#include "activations.h" +#include "blas.h" +#include "box.h" +#include "cuda.h" +#include "utils.h" + +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +layer make_region_layer(int batch, int w, int h, int n, int classes, int coords) +{ + layer l = {0}; + l.type = REGION; + + l.n = n; + l.batch = batch; + l.h = h; + l.w = w; + l.c = n*(classes + coords + 1); + l.out_w = l.w; + l.out_h = l.h; + l.out_c = l.c; + l.classes = classes; + l.coords = coords; + l.cost = calloc(1, sizeof(float)); + l.biases = calloc(n*2, sizeof(float)); + l.bias_updates = calloc(n*2, sizeof(float)); + l.outputs = h*w*n*(classes + coords + 1); + l.inputs = l.outputs; + l.truths = 30*(l.coords + 1); + l.delta = calloc(batch*l.outputs, sizeof(float)); + l.output = calloc(batch*l.outputs, sizeof(float)); + int i; + for(i = 0; i < n*2; ++i){ + l.biases[i] = .5; + } + + l.forward = forward_region_layer; + l.backward = backward_region_layer; +#ifdef GPU + l.forward_gpu = forward_region_layer_gpu; + l.backward_gpu = backward_region_layer_gpu; + l.output_gpu = cuda_make_array(l.output, batch*l.outputs); + l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs); +#endif + + fprintf(stderr, "detection\n"); + srand(0); + + return l; +} + +void resize_region_layer(layer *l, int w, int h) +{ + l->w = w; + l->h = h; + + l->outputs = h*w*l->n*(l->classes + l->coords + 1); + l->inputs = l->outputs; + + l->output = realloc(l->output, l->batch*l->outputs*sizeof(float)); + l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float)); + +#ifdef GPU + cuda_free(l->delta_gpu); + cuda_free(l->output_gpu); + + l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs); + l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs); +#endif +} + +box get_region_box(float *x, float *biases, int n, int index, int i, int j, int w, int h, int stride) +{ + box b; + b.x = (i + x[index + 0*stride]) / w; + b.y = (j + x[index + 1*stride]) / h; + b.w = exp(x[index + 2*stride]) * biases[2*n] / w; + b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; + return b; +} + +float delta_region_box(box truth, float *x, float *biases, int n, int index, int i, int j, int w, int h, float *delta, float scale, int stride) +{ + box pred = get_region_box(x, biases, n, index, i, j, w, h, stride); + float iou = box_iou(pred, truth); + + float tx = (truth.x*w - i); + float ty = (truth.y*h - j); + float tw = log(truth.w*w / biases[2*n]); + float th = log(truth.h*h / biases[2*n + 1]); + + delta[index + 0*stride] = scale * (tx - x[index + 0*stride]); + delta[index + 1*stride] = scale * (ty - x[index + 1*stride]); + delta[index + 2*stride] = scale * (tw - x[index + 2*stride]); + delta[index + 3*stride] = scale * (th - x[index + 3*stride]); + return iou; +} + +void delta_region_mask(float *truth, float *x, int n, int index, float *delta, int stride, int scale) +{ + int i; + for(i = 0; i < n; ++i){ + delta[index + i*stride] = scale*(truth[i] - x[index + i*stride]); + } +} + + +void delta_region_class(float *output, float *delta, int index, int class, int classes, tree *hier, float scale, int stride, float *avg_cat, int tag) +{ + int i, n; + if(hier){ + float pred = 1; + while(class >= 0){ + pred *= output[index + stride*class]; + int g = hier->group[class]; + int offset = hier->group_offset[g]; + for(i = 0; i < hier->group_size[g]; ++i){ + delta[index + stride*(offset + i)] = scale * (0 - output[index + stride*(offset + i)]); + } + delta[index + stride*class] = scale * (1 - output[index + stride*class]); + + class = hier->parent[class]; + } + *avg_cat += pred; + } else { + if (delta[index] && tag){ + delta[index + stride*class] = scale * (1 - output[index + stride*class]); + return; + } + for(n = 0; n < classes; ++n){ + delta[index + stride*n] = scale * (((n == class)?1 : 0) - output[index + stride*n]); + if(n == class) *avg_cat += output[index + stride*n]; + } + } +} + +float logit(float x) +{ + return log(x/(1.-x)); +} + +float tisnan(float x) +{ + return (x != x); +} + +int entry_index(layer l, int batch, int location, int entry) +{ + int n = location / (l.w*l.h); + int loc = location % (l.w*l.h); + return batch*l.outputs + n*l.w*l.h*(l.coords+l.classes+1) + entry*l.w*l.h + loc; +} + +void forward_region_layer(const layer l, network net) +{ + int i,j,b,t,n; + memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); + +#ifndef GPU + for (b = 0; b < l.batch; ++b){ + for(n = 0; n < l.n; ++n){ + int index = entry_index(l, b, n*l.w*l.h, 0); + activate_array(l.output + index, 2*l.w*l.h, LOGISTIC); + index = entry_index(l, b, n*l.w*l.h, l.coords); + if(!l.background) activate_array(l.output + index, l.w*l.h, LOGISTIC); + index = entry_index(l, b, n*l.w*l.h, l.coords + 1); + if(!l.softmax && !l.softmax_tree) activate_array(l.output + index, l.classes*l.w*l.h, LOGISTIC); + } + } + if (l.softmax_tree){ + int i; + int count = l.coords + 1; + for (i = 0; i < l.softmax_tree->groups; ++i) { + int group_size = l.softmax_tree->group_size[i]; + softmax_cpu(net.input + count, group_size, l.batch, l.inputs, l.n*l.w*l.h, 1, l.n*l.w*l.h, l.temperature, l.output + count); + count += group_size; + } + } else if (l.softmax){ + int index = entry_index(l, 0, 0, l.coords + !l.background); + softmax_cpu(net.input + index, l.classes + l.background, l.batch*l.n, l.inputs/l.n, l.w*l.h, 1, l.w*l.h, 1, l.output + index); + } +#endif + + memset(l.delta, 0, l.outputs * l.batch * sizeof(float)); + if(!net.train) return; + float avg_iou = 0; + float recall = 0; + float avg_cat = 0; + float avg_obj = 0; + float avg_anyobj = 0; + int count = 0; + int class_count = 0; + *(l.cost) = 0; + for (b = 0; b < l.batch; ++b) { + if(l.softmax_tree){ + int onlyclass = 0; + for(t = 0; t < 30; ++t){ + box truth = float_to_box(net.truth + t*(l.coords + 1) + b*l.truths, 1); + if(!truth.x) break; + int class = net.truth[t*(l.coords + 1) + b*l.truths + l.coords]; + float maxp = 0; + int maxi = 0; + if(truth.x > 100000 && truth.y > 100000){ + for(n = 0; n < l.n*l.w*l.h; ++n){ + int class_index = entry_index(l, b, n, l.coords + 1); + int obj_index = entry_index(l, b, n, l.coords); + float scale = l.output[obj_index]; + l.delta[obj_index] = l.noobject_scale * (0 - l.output[obj_index]); + float p = scale*get_hierarchy_probability(l.output + class_index, l.softmax_tree, class, l.w*l.h); + if(p > maxp){ + maxp = p; + maxi = n; + } + } + int class_index = entry_index(l, b, maxi, l.coords + 1); + int obj_index = entry_index(l, b, maxi, l.coords); + delta_region_class(l.output, l.delta, class_index, class, l.classes, l.softmax_tree, l.class_scale, l.w*l.h, &avg_cat, !l.softmax); + if(l.output[obj_index] < .3) l.delta[obj_index] = l.object_scale * (.3 - l.output[obj_index]); + else l.delta[obj_index] = 0; + l.delta[obj_index] = 0; + ++class_count; + onlyclass = 1; + break; + } + } + if(onlyclass) continue; + } + for (j = 0; j < l.h; ++j) { + for (i = 0; i < l.w; ++i) { + for (n = 0; n < l.n; ++n) { + int box_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, 0); + box pred = get_region_box(l.output, l.biases, n, box_index, i, j, l.w, l.h, l.w*l.h); + float best_iou = 0; + for(t = 0; t < 30; ++t){ + box truth = float_to_box(net.truth + t*(l.coords + 1) + b*l.truths, 1); + if(!truth.x) break; + float iou = box_iou(pred, truth); + if (iou > best_iou) { + best_iou = iou; + } + } + int obj_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, l.coords); + avg_anyobj += l.output[obj_index]; + l.delta[obj_index] = l.noobject_scale * (0 - l.output[obj_index]); + if(l.background) l.delta[obj_index] = l.noobject_scale * (1 - l.output[obj_index]); + if (best_iou > l.thresh) { + l.delta[obj_index] = 0; + } + + if(*(net.seen) < 12800){ + box truth = {0}; + truth.x = (i + .5)/l.w; + truth.y = (j + .5)/l.h; + truth.w = l.biases[2*n]/l.w; + truth.h = l.biases[2*n+1]/l.h; + delta_region_box(truth, l.output, l.biases, n, box_index, i, j, l.w, l.h, l.delta, .01, l.w*l.h); + } + } + } + } + for(t = 0; t < 30; ++t){ + box truth = float_to_box(net.truth + t*(l.coords + 1) + b*l.truths, 1); + + if(!truth.x) break; + float best_iou = 0; + int best_n = 0; + i = (truth.x * l.w); + j = (truth.y * l.h); + box truth_shift = truth; + truth_shift.x = 0; + truth_shift.y = 0; + for(n = 0; n < l.n; ++n){ + int box_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, 0); + box pred = get_region_box(l.output, l.biases, n, box_index, i, j, l.w, l.h, l.w*l.h); + if(l.bias_match){ + pred.w = l.biases[2*n]/l.w; + pred.h = l.biases[2*n+1]/l.h; + } + pred.x = 0; + pred.y = 0; + float iou = box_iou(pred, truth_shift); + if (iou > best_iou){ + best_iou = iou; + best_n = n; + } + } + + int box_index = entry_index(l, b, best_n*l.w*l.h + j*l.w + i, 0); + float iou = delta_region_box(truth, l.output, l.biases, best_n, box_index, i, j, l.w, l.h, l.delta, l.coord_scale * (2 - truth.w*truth.h), l.w*l.h); + if(l.coords > 4){ + int mask_index = entry_index(l, b, best_n*l.w*l.h + j*l.w + i, 4); + delta_region_mask(net.truth + t*(l.coords + 1) + b*l.truths + 5, l.output, l.coords - 4, mask_index, l.delta, l.w*l.h, l.mask_scale); + } + if(iou > .5) recall += 1; + avg_iou += iou; + + int obj_index = entry_index(l, b, best_n*l.w*l.h + j*l.w + i, l.coords); + avg_obj += l.output[obj_index]; + l.delta[obj_index] = l.object_scale * (1 - l.output[obj_index]); + if (l.rescore) { + l.delta[obj_index] = l.object_scale * (iou - l.output[obj_index]); + } + if(l.background){ + l.delta[obj_index] = l.object_scale * (0 - l.output[obj_index]); + } + + int class = net.truth[t*(l.coords + 1) + b*l.truths + l.coords]; + if (l.map) class = l.map[class]; + int class_index = entry_index(l, b, best_n*l.w*l.h + j*l.w + i, l.coords + 1); + delta_region_class(l.output, l.delta, class_index, class, l.classes, l.softmax_tree, l.class_scale, l.w*l.h, &avg_cat, !l.softmax); + ++count; + ++class_count; + } + } + *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2); + printf("Region Avg IOU: %f, Class: %f, Obj: %f, No Obj: %f, Avg Recall: %f, count: %d\n", avg_iou/count, avg_cat/class_count, avg_obj/count, avg_anyobj/(l.w*l.h*l.n*l.batch), recall/count, count); +} + +void backward_region_layer(const layer l, network net) +{ + /* + int b; + int size = l.coords + l.classes + 1; + for (b = 0; b < l.batch*l.n; ++b){ + int index = (b*size + 4)*l.w*l.h; + gradient_array(l.output + index, l.w*l.h, LOGISTIC, l.delta + index); + } + axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); + */ +} + +void correct_region_boxes(detection *dets, int n, int w, int h, int netw, int neth, int relative) +{ + int i; + int new_w=0; + int new_h=0; + if (((float)netw/w) < ((float)neth/h)) { + new_w = netw; + new_h = (h * netw)/w; + } else { + new_h = neth; + new_w = (w * neth)/h; + } + for (i = 0; i < n; ++i){ + box b = dets[i].bbox; + b.x = (b.x - (netw - new_w)/2./netw) / ((float)new_w/netw); + b.y = (b.y - (neth - new_h)/2./neth) / ((float)new_h/neth); + b.w *= (float)netw/new_w; + b.h *= (float)neth/new_h; + if(!relative){ + b.x *= w; + b.w *= w; + b.y *= h; + b.h *= h; + } + dets[i].bbox = b; + } +} + +void get_region_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets) +{ + int i,j,n,z; + float *predictions = l.output; + if (l.batch == 2) { + float *flip = l.output + l.outputs; + for (j = 0; j < l.h; ++j) { + for (i = 0; i < l.w/2; ++i) { + for (n = 0; n < l.n; ++n) { + for(z = 0; z < l.classes + l.coords + 1; ++z){ + int i1 = z*l.w*l.h*l.n + n*l.w*l.h + j*l.w + i; + int i2 = z*l.w*l.h*l.n + n*l.w*l.h + j*l.w + (l.w - i - 1); + float swap = flip[i1]; + flip[i1] = flip[i2]; + flip[i2] = swap; + if(z == 0){ + flip[i1] = -flip[i1]; + flip[i2] = -flip[i2]; + } + } + } + } + } + for(i = 0; i < l.outputs; ++i){ + l.output[i] = (l.output[i] + flip[i])/2.; + } + } + for (i = 0; i < l.w*l.h; ++i){ + int row = i / l.w; + int col = i % l.w; + for(n = 0; n < l.n; ++n){ + int index = n*l.w*l.h + i; + for(j = 0; j < l.classes; ++j){ + dets[index].prob[j] = 0; + } + int obj_index = entry_index(l, 0, n*l.w*l.h + i, l.coords); + int box_index = entry_index(l, 0, n*l.w*l.h + i, 0); + int mask_index = entry_index(l, 0, n*l.w*l.h + i, 4); + float scale = l.background ? 1 : predictions[obj_index]; + dets[index].bbox = get_region_box(predictions, l.biases, n, box_index, col, row, l.w, l.h, l.w*l.h); + dets[index].objectness = scale > thresh ? scale : 0; + if(dets[index].mask){ + for(j = 0; j < l.coords - 4; ++j){ + dets[index].mask[j] = l.output[mask_index + j*l.w*l.h]; + } + } + + int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + !l.background); + if(l.softmax_tree){ + + hierarchy_predictions(predictions + class_index, l.classes, l.softmax_tree, 0, l.w*l.h); + if(map){ + for(j = 0; j < 200; ++j){ + int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + 1 + map[j]); + float prob = scale*predictions[class_index]; + dets[index].prob[j] = (prob > thresh) ? prob : 0; + } + } else { + int j = hierarchy_top_prediction(predictions + class_index, l.softmax_tree, tree_thresh, l.w*l.h); + dets[index].prob[j] = (scale > thresh) ? scale : 0; + } + } else { + if(dets[index].objectness){ + for(j = 0; j < l.classes; ++j){ + int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + 1 + j); + float prob = scale*predictions[class_index]; + dets[index].prob[j] = (prob > thresh) ? prob : 0; + } + } + } + } + } + correct_region_boxes(dets, l.w*l.h*l.n, w, h, netw, neth, relative); +} + +#ifdef GPU + +void forward_region_layer_gpu(const layer l, network net) +{ + copy_gpu(l.batch*l.inputs, net.input_gpu, 1, l.output_gpu, 1); + int b, n; + for (b = 0; b < l.batch; ++b){ + for(n = 0; n < l.n; ++n){ + int index = entry_index(l, b, n*l.w*l.h, 0); + activate_array_gpu(l.output_gpu + index, 2*l.w*l.h, LOGISTIC); + if(l.coords > 4){ + index = entry_index(l, b, n*l.w*l.h, 4); + activate_array_gpu(l.output_gpu + index, (l.coords - 4)*l.w*l.h, LOGISTIC); + } + index = entry_index(l, b, n*l.w*l.h, l.coords); + if(!l.background) activate_array_gpu(l.output_gpu + index, l.w*l.h, LOGISTIC); + index = entry_index(l, b, n*l.w*l.h, l.coords + 1); + if(!l.softmax && !l.softmax_tree) activate_array_gpu(l.output_gpu + index, l.classes*l.w*l.h, LOGISTIC); + } + } + if (l.softmax_tree){ + int index = entry_index(l, 0, 0, l.coords + 1); + softmax_tree(net.input_gpu + index, l.w*l.h, l.batch*l.n, l.inputs/l.n, 1, l.output_gpu + index, *l.softmax_tree); + } else if (l.softmax) { + int index = entry_index(l, 0, 0, l.coords + !l.background); + softmax_gpu(net.input_gpu + index, l.classes + l.background, l.batch*l.n, l.inputs/l.n, l.w*l.h, 1, l.w*l.h, 1, l.output_gpu + index); + } + if(!net.train || l.onlyforward){ + cuda_pull_array(l.output_gpu, l.output, l.batch*l.outputs); + return; + } + + cuda_pull_array(l.output_gpu, net.input, l.batch*l.inputs); + forward_region_layer(l, net); + //cuda_push_array(l.output_gpu, l.output, l.batch*l.outputs); + if(!net.train) return; + cuda_push_array(l.delta_gpu, l.delta, l.batch*l.outputs); +} + +void backward_region_layer_gpu(const layer l, network net) +{ + int b, n; + for (b = 0; b < l.batch; ++b){ + for(n = 0; n < l.n; ++n){ + int index = entry_index(l, b, n*l.w*l.h, 0); + gradient_array_gpu(l.output_gpu + index, 2*l.w*l.h, LOGISTIC, l.delta_gpu + index); + if(l.coords > 4){ + index = entry_index(l, b, n*l.w*l.h, 4); + gradient_array_gpu(l.output_gpu + index, (l.coords - 4)*l.w*l.h, LOGISTIC, l.delta_gpu + index); + } + index = entry_index(l, b, n*l.w*l.h, l.coords); + if(!l.background) gradient_array_gpu(l.output_gpu + index, l.w*l.h, LOGISTIC, l.delta_gpu + index); + } + } + axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif + +void zero_objectness(layer l) +{ + int i, n; + for (i = 0; i < l.w*l.h; ++i){ + for(n = 0; n < l.n; ++n){ + int obj_index = entry_index(l, 0, n*l.w*l.h + i, l.coords); + l.output[obj_index] = 0; + } + } +} + diff --git a/src/region_layer.h b/src/region_layer.h new file mode 100644 index 0000000..c1ae29e --- /dev/null +++ b/src/region_layer.h @@ -0,0 +1,19 @@ +#pragma once +#ifndef REGION_LAYER_H +#define REGION_LAYER_H +#include "define_inc.h" +#include "darknet.h" +#include "layer.h" +#include "network.h" + +layer make_region_layer(int batch, int w, int h, int n, int classes, int coords); +void forward_region_layer(const layer l, network net); +void backward_region_layer(const layer l, network net); +void resize_region_layer(layer *l, int w, int h); + +#ifdef GPU +void forward_region_layer_gpu(const layer l, network net); +void backward_region_layer_gpu(layer l, network net); +#endif + +#endif diff --git a/src/reorg_layer.c b/src/reorg_layer.c new file mode 100644 index 0000000..31d6b84 --- /dev/null +++ b/src/reorg_layer.c @@ -0,0 +1,173 @@ +#include "reorg_layer.h" +#include "cuda.h" +#include "blas.h" + +#include <stdio.h> + + +layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra) +{ + layer l = {0}; + l.type = REORG; + l.batch = batch; + l.stride = stride; + l.extra = extra; + l.h = h; + l.w = w; + l.c = c; + l.flatten = flatten; + if(reverse){ + l.out_w = w*stride; + l.out_h = h*stride; + l.out_c = c/(stride*stride); + }else{ + l.out_w = w/stride; + l.out_h = h/stride; + l.out_c = c*(stride*stride); + } + l.reverse = reverse; + + l.outputs = l.out_h * l.out_w * l.out_c; + l.inputs = h*w*c; + if(l.extra){ + l.out_w = l.out_h = l.out_c = 0; + l.outputs = l.inputs + l.extra; + } + + if(extra){ + fprintf(stderr, "reorg %4d -> %4d\n", l.inputs, l.outputs); + } else { + fprintf(stderr, "reorg /%2d %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + } + int output_size = l.outputs * batch; + l.output = calloc(output_size, sizeof(float)); + l.delta = calloc(output_size, sizeof(float)); + + l.forward = forward_reorg_layer; + l.backward = backward_reorg_layer; +#ifdef GPU + l.forward_gpu = forward_reorg_layer_gpu; + l.backward_gpu = backward_reorg_layer_gpu; + + l.output_gpu = cuda_make_array(l.output, output_size); + l.delta_gpu = cuda_make_array(l.delta, output_size); +#endif + return l; +} + +void resize_reorg_layer(layer *l, int w, int h) +{ + int stride = l->stride; + int c = l->c; + + l->h = h; + l->w = w; + + if(l->reverse){ + l->out_w = w*stride; + l->out_h = h*stride; + l->out_c = c/(stride*stride); + }else{ + l->out_w = w/stride; + l->out_h = h/stride; + l->out_c = c*(stride*stride); + } + + l->outputs = l->out_h * l->out_w * l->out_c; + l->inputs = l->outputs; + int output_size = l->outputs * l->batch; + + l->output = realloc(l->output, output_size * sizeof(float)); + l->delta = realloc(l->delta, output_size * sizeof(float)); + +#ifdef GPU + cuda_free(l->output_gpu); + cuda_free(l->delta_gpu); + l->output_gpu = cuda_make_array(l->output, output_size); + l->delta_gpu = cuda_make_array(l->delta, output_size); +#endif +} + +void forward_reorg_layer(const layer l, network net) +{ + int i; + if(l.flatten){ + memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); + if(l.reverse){ + flatten(l.output, l.w*l.h, l.c, l.batch, 0); + }else{ + flatten(l.output, l.w*l.h, l.c, l.batch, 1); + } + } else if (l.extra) { + for(i = 0; i < l.batch; ++i){ + copy_cpu(l.inputs, net.input + i*l.inputs, 1, l.output + i*l.outputs, 1); + } + } else if (l.reverse){ + reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output); + } else { + reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 0, l.output); + } +} + +void backward_reorg_layer(const layer l, network net) +{ + int i; + if(l.flatten){ + memcpy(net.delta, l.delta, l.outputs*l.batch*sizeof(float)); + if(l.reverse){ + flatten(net.delta, l.w*l.h, l.c, l.batch, 1); + }else{ + flatten(net.delta, l.w*l.h, l.c, l.batch, 0); + } + } else if(l.reverse){ + reorg_cpu(l.delta, l.w, l.h, l.c, l.batch, l.stride, 0, net.delta); + } else if (l.extra) { + for(i = 0; i < l.batch; ++i){ + copy_cpu(l.inputs, l.delta + i*l.outputs, 1, net.delta + i*l.inputs, 1); + } + }else{ + reorg_cpu(l.delta, l.w, l.h, l.c, l.batch, l.stride, 1, net.delta); + } +} + +#ifdef GPU +void forward_reorg_layer_gpu(layer l, network net) +{ + int i; + if(l.flatten){ + if(l.reverse){ + flatten_gpu(net.input_gpu, l.w*l.h, l.c, l.batch, 0, l.output_gpu); + }else{ + flatten_gpu(net.input_gpu, l.w*l.h, l.c, l.batch, 1, l.output_gpu); + } + } else if (l.extra) { + for(i = 0; i < l.batch; ++i){ + copy_gpu(l.inputs, net.input_gpu + i*l.inputs, 1, l.output_gpu + i*l.outputs, 1); + } + } else if (l.reverse) { + reorg_gpu(net.input_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, l.output_gpu); + }else { + reorg_gpu(net.input_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, l.output_gpu); + } +} + +void backward_reorg_layer_gpu(layer l, network net) +{ + if(l.flatten){ + if(l.reverse){ + flatten_gpu(l.delta_gpu, l.w*l.h, l.c, l.batch, 1, net.delta_gpu); + }else{ + flatten_gpu(l.delta_gpu, l.w*l.h, l.c, l.batch, 0, net.delta_gpu); + } + } else if (l.extra) { + int i; + for(i = 0; i < l.batch; ++i){ + copy_gpu(l.inputs, l.delta_gpu + i*l.outputs, 1, net.delta_gpu + i*l.inputs, 1); + } + } else if(l.reverse){ + reorg_gpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, net.delta_gpu); + } else { + reorg_gpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, net.delta_gpu); + } +} +#endif diff --git a/src/reorg_layer.h b/src/reorg_layer.h new file mode 100644 index 0000000..5adb670 --- /dev/null +++ b/src/reorg_layer.h @@ -0,0 +1,21 @@ +#pragma once +#ifndef REORG_LAYER_H +#define REORG_LAYER_H +#include "define_inc.h" +#include "image.h" +#include "cuda.h" +#include "layer.h" +#include "network.h" + +layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra); +void resize_reorg_layer(layer *l, int w, int h); +void forward_reorg_layer(const layer l, network net); +void backward_reorg_layer(const layer l, network net); + +#ifdef GPU +void forward_reorg_layer_gpu(layer l, network net); +void backward_reorg_layer_gpu(layer l, network net); +#endif + +#endif + diff --git a/src/rnn_layer.c b/src/rnn_layer.c new file mode 100644 index 0000000..8c9b457 --- /dev/null +++ b/src/rnn_layer.c @@ -0,0 +1,292 @@ +#include "rnn_layer.h" +#include "connected_layer.h" +#include "utils.h" +#include "cuda.h" +#include "blas.h" +#include "gemm.h" + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void increment_layer(layer *l, int steps) +{ + int num = l->outputs*l->batch*steps; + l->output += num; + l->delta += num; + l->x += num; + l->x_norm += num; + +#ifdef GPU + l->output_gpu += num; + l->delta_gpu += num; + l->x_gpu += num; + l->x_norm_gpu += num; +#endif +} + +layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam) +{ + fprintf(stderr, "RNN Layer: %d inputs, %d outputs\n", inputs, outputs); + batch = batch / steps; + layer l = {0}; + l.batch = batch; + l.type = RNN; + l.steps = steps; + l.inputs = inputs; + + l.state = calloc(batch*outputs, sizeof(float)); + l.prev_state = calloc(batch*outputs, sizeof(float)); + + l.input_layer = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.input_layer) = make_connected_layer(batch*steps, inputs, outputs, activation, batch_normalize, adam); + l.input_layer->batch = batch; + + l.self_layer = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.self_layer) = make_connected_layer(batch*steps, outputs, outputs, activation, batch_normalize, adam); + l.self_layer->batch = batch; + + l.output_layer = malloc(sizeof(layer)); + fprintf(stderr, "\t\t"); + *(l.output_layer) = make_connected_layer(batch*steps, outputs, outputs, activation, batch_normalize, adam); + l.output_layer->batch = batch; + + l.outputs = outputs; + l.output = l.output_layer->output; + l.delta = l.output_layer->delta; + + l.forward = forward_rnn_layer; + l.backward = backward_rnn_layer; + l.update = update_rnn_layer; +#ifdef GPU + l.forward_gpu = forward_rnn_layer_gpu; + l.backward_gpu = backward_rnn_layer_gpu; + l.update_gpu = update_rnn_layer_gpu; + l.state_gpu = cuda_make_array(0, batch*outputs); + l.prev_state_gpu = cuda_make_array(0, batch*outputs); + l.output_gpu = l.output_layer->output_gpu; + l.delta_gpu = l.output_layer->delta_gpu; +#ifdef CUDNN + cudnnSetTensor4dDescriptor(l.input_layer->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.input_layer->out_c, l.input_layer->out_h, l.input_layer->out_w); + cudnnSetTensor4dDescriptor(l.self_layer->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.self_layer->out_c, l.self_layer->out_h, l.self_layer->out_w); + cudnnSetTensor4dDescriptor(l.output_layer->dstTensorDesc, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, batch, l.output_layer->out_c, l.output_layer->out_h, l.output_layer->out_w); +#endif +#endif + + return l; +} + +void update_rnn_layer(layer l, update_args a) +{ + update_connected_layer(*(l.input_layer), a); + update_connected_layer(*(l.self_layer), a); + update_connected_layer(*(l.output_layer), a); +} + +void forward_rnn_layer(layer l, network net) +{ + network s = net; + s.train = net.train; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + + fill_cpu(l.outputs * l.batch * l.steps, 0, output_layer.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, self_layer.delta, 1); + fill_cpu(l.outputs * l.batch * l.steps, 0, input_layer.delta, 1); + if(net.train) fill_cpu(l.outputs * l.batch, 0, l.state, 1); + + for (i = 0; i < l.steps; ++i) { + s.input = net.input; + forward_connected_layer(input_layer, s); + + s.input = l.state; + forward_connected_layer(self_layer, s); + + float *old_state = l.state; + if(net.train) l.state += l.outputs*l.batch; + if(l.shortcut){ + copy_cpu(l.outputs * l.batch, old_state, 1, l.state, 1); + }else{ + fill_cpu(l.outputs * l.batch, 0, l.state, 1); + } + axpy_cpu(l.outputs * l.batch, 1, input_layer.output, 1, l.state, 1); + axpy_cpu(l.outputs * l.batch, 1, self_layer.output, 1, l.state, 1); + + s.input = l.state; + forward_connected_layer(output_layer, s); + + net.input += l.inputs*l.batch; + increment_layer(&input_layer, 1); + increment_layer(&self_layer, 1); + increment_layer(&output_layer, 1); + } +} + +void backward_rnn_layer(layer l, network net) +{ + network s = net; + s.train = net.train; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + + increment_layer(&input_layer, l.steps-1); + increment_layer(&self_layer, l.steps-1); + increment_layer(&output_layer, l.steps-1); + + l.state += l.outputs*l.batch*l.steps; + for (i = l.steps-1; i >= 0; --i) { + copy_cpu(l.outputs * l.batch, input_layer.output, 1, l.state, 1); + axpy_cpu(l.outputs * l.batch, 1, self_layer.output, 1, l.state, 1); + + s.input = l.state; + s.delta = self_layer.delta; + backward_connected_layer(output_layer, s); + + l.state -= l.outputs*l.batch; + /* + if(i > 0){ + copy_cpu(l.outputs * l.batch, input_layer.output - l.outputs*l.batch, 1, l.state, 1); + axpy_cpu(l.outputs * l.batch, 1, self_layer.output - l.outputs*l.batch, 1, l.state, 1); + }else{ + fill_cpu(l.outputs * l.batch, 0, l.state, 1); + } + */ + + s.input = l.state; + s.delta = self_layer.delta - l.outputs*l.batch; + if (i == 0) s.delta = 0; + backward_connected_layer(self_layer, s); + + copy_cpu(l.outputs*l.batch, self_layer.delta, 1, input_layer.delta, 1); + if (i > 0 && l.shortcut) axpy_cpu(l.outputs*l.batch, 1, self_layer.delta, 1, self_layer.delta - l.outputs*l.batch, 1); + s.input = net.input + i*l.inputs*l.batch; + if(net.delta) s.delta = net.delta + i*l.inputs*l.batch; + else s.delta = 0; + backward_connected_layer(input_layer, s); + + increment_layer(&input_layer, -1); + increment_layer(&self_layer, -1); + increment_layer(&output_layer, -1); + } +} + +#ifdef GPU + +void pull_rnn_layer(layer l) +{ + pull_connected_layer(*(l.input_layer)); + pull_connected_layer(*(l.self_layer)); + pull_connected_layer(*(l.output_layer)); +} + +void push_rnn_layer(layer l) +{ + push_connected_layer(*(l.input_layer)); + push_connected_layer(*(l.self_layer)); + push_connected_layer(*(l.output_layer)); +} + +void update_rnn_layer_gpu(layer l, update_args a) +{ + update_connected_layer_gpu(*(l.input_layer), a); + update_connected_layer_gpu(*(l.self_layer), a); + update_connected_layer_gpu(*(l.output_layer), a); +} + +void forward_rnn_layer_gpu(layer l, network net) +{ + network s = {0}; + s.train = net.train; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + + fill_gpu(l.outputs * l.batch * l.steps, 0, output_layer.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, self_layer.delta_gpu, 1); + fill_gpu(l.outputs * l.batch * l.steps, 0, input_layer.delta_gpu, 1); + + if(net.train) { + fill_gpu(l.outputs * l.batch * l.steps, 0, l.delta_gpu, 1); + copy_gpu(l.outputs*l.batch, l.state_gpu, 1, l.prev_state_gpu, 1); + } + + for (i = 0; i < l.steps; ++i) { + s.input_gpu = net.input_gpu; + forward_connected_layer_gpu(input_layer, s); + + s.input_gpu = l.state_gpu; + forward_connected_layer_gpu(self_layer, s); + + fill_gpu(l.outputs * l.batch, 0, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, input_layer.output_gpu, 1, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, self_layer.output_gpu, 1, l.state_gpu, 1); + + s.input_gpu = l.state_gpu; + forward_connected_layer_gpu(output_layer, s); + + net.input_gpu += l.inputs*l.batch; + increment_layer(&input_layer, 1); + increment_layer(&self_layer, 1); + increment_layer(&output_layer, 1); + } +} + +void backward_rnn_layer_gpu(layer l, network net) +{ + network s = {0}; + s.train = net.train; + int i; + layer input_layer = *(l.input_layer); + layer self_layer = *(l.self_layer); + layer output_layer = *(l.output_layer); + increment_layer(&input_layer, l.steps - 1); + increment_layer(&self_layer, l.steps - 1); + increment_layer(&output_layer, l.steps - 1); + float *last_input = input_layer.output_gpu; + float *last_self = self_layer.output_gpu; + for (i = l.steps-1; i >= 0; --i) { + fill_gpu(l.outputs * l.batch, 0, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, input_layer.output_gpu, 1, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, self_layer.output_gpu, 1, l.state_gpu, 1); + + s.input_gpu = l.state_gpu; + s.delta_gpu = self_layer.delta_gpu; + backward_connected_layer_gpu(output_layer, s); + + if(i != 0) { + fill_gpu(l.outputs * l.batch, 0, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, input_layer.output_gpu - l.outputs*l.batch, 1, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, self_layer.output_gpu - l.outputs*l.batch, 1, l.state_gpu, 1); + }else { + copy_gpu(l.outputs*l.batch, l.prev_state_gpu, 1, l.state_gpu, 1); + } + + copy_gpu(l.outputs*l.batch, self_layer.delta_gpu, 1, input_layer.delta_gpu, 1); + + s.input_gpu = l.state_gpu; + s.delta_gpu = (i > 0) ? self_layer.delta_gpu - l.outputs*l.batch : 0; + if (i == 0) s.delta_gpu = 0; + backward_connected_layer_gpu(self_layer, s); + + s.input_gpu = net.input_gpu + i*l.inputs*l.batch; + if(net.delta_gpu) s.delta_gpu = net.delta_gpu + i*l.inputs*l.batch; + else s.delta_gpu = 0; + backward_connected_layer_gpu(input_layer, s); + + increment_layer(&input_layer, -1); + increment_layer(&self_layer, -1); + increment_layer(&output_layer, -1); + } + fill_gpu(l.outputs * l.batch, 0, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, last_input, 1, l.state_gpu, 1); + axpy_gpu(l.outputs * l.batch, 1, last_self, 1, l.state_gpu, 1); +} +#endif diff --git a/src/rnn_layer.h b/src/rnn_layer.h new file mode 100644 index 0000000..366856a --- /dev/null +++ b/src/rnn_layer.h @@ -0,0 +1,25 @@ +#pragma once +#ifndef RNN_LAYER_H +#define RNN_LAYER_H +#include "define_inc.h" +#include "activations.h" +#include "layer.h" +#include "network.h" +#define USET + +layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam); + +void forward_rnn_layer(layer l, network net); +void backward_rnn_layer(layer l, network net); +void update_rnn_layer(layer l, update_args a); + +#ifdef GPU +void forward_rnn_layer_gpu(layer l, network net); +void backward_rnn_layer_gpu(layer l, network net); +void update_rnn_layer_gpu(layer l, update_args a); +void push_rnn_layer(layer l); +void pull_rnn_layer(layer l); +#endif + +#endif + diff --git a/src/route_layer.c b/src/route_layer.c new file mode 100644 index 0000000..f3e501c --- /dev/null +++ b/src/route_layer.c @@ -0,0 +1,169 @@ +#include "route_layer.h" +#include "cuda.h" +#include "blas.h" + +#include <stdio.h> + +route_layer make_route_layer(int batch, int n, int *input_layers, int *input_sizes) +{ + fprintf(stderr,"route "); + route_layer l = {0}; + l.type = ROUTE; + l.batch = batch; + l.n = n; + l.input_layers = input_layers; + l.input_sizes = input_sizes; + int i; + int outputs = 0; + for(i = 0; i < n; ++i){ + fprintf(stderr," %d", input_layers[i]); + outputs += input_sizes[i]; + } + fprintf(stderr, "\n"); + l.outputs = outputs; + l.inputs = outputs; + l.delta = calloc(outputs*batch, sizeof(float)); + l.output = calloc(outputs*batch, sizeof(float));; + + l.forward = forward_route_layer; + l.backward = backward_route_layer; + #ifdef GPU + l.forward_gpu = forward_route_layer_gpu; + l.backward_gpu = backward_route_layer_gpu; + + l.delta_gpu = cuda_make_array(l.delta, outputs*batch); + l.output_gpu = cuda_make_array(l.output, outputs*batch); + #endif + return l; +} + +void resize_route_layer(route_layer *l, network *net) +{ + int i; + layer first = net->layers[l->input_layers[0]]; + l->out_w = first.out_w; + l->out_h = first.out_h; + l->out_c = first.out_c; + l->outputs = first.outputs; + l->input_sizes[0] = first.outputs; + for(i = 1; i < l->n; ++i){ + int index = l->input_layers[i]; + layer next = net->layers[index]; + l->outputs += next.outputs; + l->input_sizes[i] = next.outputs; + if(next.out_w == first.out_w && next.out_h == first.out_h){ + l->out_c += next.out_c; + }else{ + printf("%d %d, %d %d\n", next.out_w, next.out_h, first.out_w, first.out_h); + l->out_h = l->out_w = l->out_c = 0; + } + } + l->inputs = l->outputs; + l->delta = realloc(l->delta, l->outputs*l->batch*sizeof(float)); + l->output = realloc(l->output, l->outputs*l->batch*sizeof(float)); + +#ifdef GPU + cuda_free(l->output_gpu); + cuda_free(l->delta_gpu); + l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); + l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch); +#endif + +} + +void forward_route_layer(const route_layer l, network net) +{ + int i, j; + int offset = 0; + for(i = 0; i < l.n; ++i){ + int index = l.input_layers[i]; + float *input = net.layers[index].output; + int input_size = l.input_sizes[i]; + for(j = 0; j < l.batch; ++j){ + copy_cpu(input_size, input + j*input_size, 1, l.output + offset + j*l.outputs, 1); + } + offset += input_size; + } +} + +void backward_route_layer(const route_layer l, network net) +{ + int i, j; + int offset = 0; + for(i = 0; i < l.n; ++i){ + int index = l.input_layers[i]; + float *delta = net.layers[index].delta; + int input_size = l.input_sizes[i]; + for(j = 0; j < l.batch; ++j){ + axpy_cpu(input_size, 1, l.delta + offset + j*l.outputs, 1, delta + j*input_size, 1); + } + offset += input_size; + } +} + +#ifdef GPU +void forward_route_layer_gpu(const route_layer l, network net) +{ + int i, j; + int offset = 0; + for(i = 0; i < l.n; ++i){ + int index = l.input_layers[i]; + float *input = net.layers[index].output_gpu; + int input_size = l.input_sizes[i]; + for(j = 0; j < l.batch; ++j){ + copy_gpu(input_size, input + j*input_size, 1, l.output_gpu + offset + j*l.outputs, 1); + } + offset += input_size; + } +} + +void backward_route_layer_gpu(const route_layer l, network net) +{ + int i, j; + int offset = 0; + for(i = 0; i < l.n; ++i){ + int index = l.input_layers[i]; + float *delta = net.layers[index].delta_gpu; + int input_size = l.input_sizes[i]; + for(j = 0; j < l.batch; ++j){ + axpy_gpu(input_size, 1, l.delta_gpu + offset + j*l.outputs, 1, delta + j*input_size, 1); + } + offset += input_size; + } +} +#endif + +#ifdef ALLEN_MODIFIED +route_layer make_route_layer_mem(int batch, int n, int *input_layers, int *input_sizes) +{ + //fprintf(stderr, "route "); + route_layer l = { 0 }; + l.type = ROUTE; + l.batch = batch; + l.n = n; + l.input_layers = input_layers; + l.input_sizes = input_sizes; + int i; + int outputs = 0; + for (i = 0; i < n; ++i) { + //fprintf(stderr, " %d", input_layers[i]); + outputs += input_sizes[i]; + } + //fprintf(stderr, "\n"); + l.outputs = outputs; + l.inputs = outputs; + l.delta = calloc(outputs*batch, sizeof(float)); + l.output = calloc(outputs*batch, sizeof(float));; + + l.forward = forward_route_layer; + l.backward = backward_route_layer; +#ifdef GPU + l.forward_gpu = forward_route_layer_gpu; + l.backward_gpu = backward_route_layer_gpu; + + l.delta_gpu = cuda_make_array(l.delta, outputs*batch); + l.output_gpu = cuda_make_array(l.output, outputs*batch); +#endif + return l; +} +#endif \ No newline at end of file diff --git a/src/route_layer.h b/src/route_layer.h new file mode 100644 index 0000000..85bbce8 --- /dev/null +++ b/src/route_layer.h @@ -0,0 +1,23 @@ +#pragma once +#ifndef ROUTE_LAYER_H +#define ROUTE_LAYER_H +#include "define_inc.h" +#include "network.h" +#include "layer.h" +#define ALLEN_MODIFY + +typedef layer route_layer; + +route_layer make_route_layer(int batch, int n, int *input_layers, int *input_size); +void forward_route_layer(const route_layer l, network net); +void backward_route_layer(const route_layer l, network net); +void resize_route_layer(route_layer *l, network *net); + +#ifdef GPU +void forward_route_layer_gpu(const route_layer l, network net); +void backward_route_layer_gpu(const route_layer l, network net); +#endif +#ifdef ALLEN_MODIFIED +route_layer make_route_layer_mem(int batch, int n, int *input_layers, int *input_size); +#endif +#endif diff --git a/src/send_osd_data.c b/src/send_osd_data.c new file mode 100644 index 0000000..e40d92e --- /dev/null +++ b/src/send_osd_data.c @@ -0,0 +1,125 @@ + +#include "send_osd_data.h" + +int udp_sockfd = -1; +struct sockaddr_in dest_addr = { 0 }; + +int init_udp_socket() +{ + udp_sockfd = socket(AF_INET, SOCK_DGRAM, 0); + + if (udp_sockfd == -1) { + printf("Fail to create a socket."); + return 1; + } + + + bzero(&dest_addr, sizeof(dest_addr)); + //dest_addr.sin_family = PF_INET; + + //localhost test + //dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); + dest_addr.sin_family = AF_INET; + dest_addr.sin_addr.s_addr = INADDR_ANY; + + dest_addr.sin_port = htons(OSD_UDP_PORT); + //socketإ TCP_PORT_IMAGE + //int sockfd = 0; + + struct timeval timeout; + timeout.tv_sec = 3;//3 + timeout.tv_usec = 0; + + setsockopt(udp_sockfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(udp_sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + //int tcpnodelay = 1; + //setsockopt(udp_sockfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + + int reuse = 1; + setsockopt(udp_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(udp_sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + //int qlen = 5; + //setsockopt(udp_sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + bool bBroadcast = true; + setsockopt(udp_sockfd, SOL_SOCKET, SO_BROADCAST, (const char*)&bBroadcast, sizeof(bBroadcast)); + + // wİ + int nZero = BUFSIZE_V3;//]m32K + setsockopt(udp_sockfd, SOL_SOCKET, SO_SNDBUF, (const char *)&nZero, sizeof(nZero)); + setsockopt(udp_sockfd, SOL_SOCKET, SO_RCVBUF, (const char *)&nZero, sizeof(nZero)); + + return 0; +} + +void close_udp_socket() +{ + if (udp_sockfd != -1) { + close(udp_sockfd); + } +} + +#if 1 +void send_udp_data(char *send_data) +{ + int err = connect(udp_sockfd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); + if (err == -1) { + printf("Connection error"); + close_udp_socket(); + init_udp_socket(); + } + else { + //if (write(sockfd, &image_data, sizeof(image_data)) <= 0) + int send_len = 0; + send_len = send(udp_sockfd, send_data, strlen(send_data), MSG_NOSIGNAL); + if (send_len <= 0) + { + //printf("Error: %s (%d)\n", strerror(errno), errno); + //printf("\n------------nn thread api #3\n"); + //die("send()"); + //printf("die send #311()\n"); + } + } +} +#endif + +#if 0 +void send_udp_data(char *send_data) +{ + struct sockaddr_in dest_addr; + bzero(&dest_addr, sizeof(dest_addr)); + dest_addr.sin_family = PF_INET; + + //localhost test + dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); + dest_addr.sin_port = htons(OSD_UDP_PORT); + //socketإ TCP_PORT_IMAGE + int sockfd = 0; + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + + if (sockfd == -1) { + printf("Fail to create a socket."); + } + else { + int err = connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); + if (err == -1) { + printf("Connection error"); + } + else { + //if (write(sockfd, &image_data, sizeof(image_data)) <= 0) + int send_len = 0; + send_len = send(sockfd, send_data, strlen(send_data), MSG_NOSIGNAL); + if (send_len <= 0) + { + printf("Error: %s (%d)\n", strerror(errno), errno); + //printf("\n------------nn thread api #3\n"); + //die("send()"); + printf("die send #312()\n"); + } + } + } + close(sockfd); +} +#endif \ No newline at end of file diff --git a/src/send_osd_data.h b/src/send_osd_data.h new file mode 100644 index 0000000..08ab01b --- /dev/null +++ b/src/send_osd_data.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef SEND_OSD_DATA_H +#define SEND_OSD_DATA_H +#include "define_inc.h" +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#include <stdbool.h> +#include <stdio.h> +#include <unistd.h> + +#include "setting.h" + +#define OSD_UDP_PORT 5621 + +void send_udp_data(char *send_data); +int init_udp_socket(); +void close_udp_socket(); +#endif \ No newline at end of file diff --git a/src/setting.h b/src/setting.h new file mode 100644 index 0000000..90ac2f9 --- /dev/null +++ b/src/setting.h @@ -0,0 +1,507 @@ +#pragma once +#ifndef SETTING_H +#define SETTING_H + +//#define GY_OS_WIN +//#define GY_OS_AMBA +#include "define_inc.h" +#include <stdlib.h> + +#define FOR_CC_POST + +//general difinition +#ifdef GY_OS_AMBA +#define APP_VERSION "2.0.7.60" //AMBALPKG.jsonn@P +#else +#define APP_VERSION "1.4.3.2" //NOVALPKG.jsonn@P +#endif + + +#ifdef GY_OS_AMBA +#define MAX_IMG_BUFF_SIZE 1024*1024*20 //max image size is 20MB +//#define MAX_IMG_BUFF_SIZE 8192*13 +#define MAX_CLIENT_NUMBER 32 //max client socket +#elif defined GY_OS_NOVA +#define MAX_IMG_BUFF_SIZE 1024*100*1 //max image size is 20MB +#define MAX_CLIENT_NUMBER 32 //max client socket +#endif + +#define MAX_FACES 30 // xsHyT̤j + +#define UDP_IMAGE_WIDTH 176 +#define UDP_IMAGE_HEIGHT 120 + +#define UDP_IMAGE_WIDTH_NORMAL 352 +#define UDP_IMAGE_HEIGHT_NORMAL 240 + +#define MAX_IMG_SIZE 1920*1080/4 //1920*1080/4 //1920*1080/4 //1920*1080/2 +#define MAX_IMG_SIZE_1280_720 1280*720 +#define MAX_IMG_SIZE_HD 1920*1080/4 //1920*1080/4 //1920*1080/2 +#define MAX_VPOUT_LENGTH 8*1024*1024 +#define MAX_NUM_SNAP_IMAGES 1 +#define MAX_NUM_IMAGE_BUFF 9 //16 + +#define MAX_NUM_BRING_WITH_OBJECT 16 + +#define MAX_SUB_PLATE 30 // 128 + +#ifdef GY_OS_AMBA +#define MAX_TRACKING_NUM 64 // 128 +#else +#define MAX_TRACKING_NUM 25 //A11en changed from 128 to 1 for preventing segmentation fault //50 10 // 20 14 //1 30 +#endif +//#define MAX_CLIENT_SOCKET 1 //max client socket +#if defined GY_OS_V_SERIES +#define MAX_CLIENT_SOCKET 20 //steve, max client socket //20 +#else +#define MAX_CLIENT_SOCKET 20 //steve, max client socket +#endif + +#ifdef GY_OS_AMBA +#define MAX_SOCK_ERR_HOLD_TIMES 125 +#else +#define MAX_SOCK_ERR_HOLD_TIMES 100 +#endif + +#define MIN_TIME_GAP 3 // minimum for time gap +#define HSVIMAGE_ROWS 1 +#define HSVIMAGE_COLS 1 +#define MAX_WEIGHT_FILE_LIST 31 + +//#define MAX_HTTP_BUFFER 1024*1024 +#define MAX_SMALL_FILE_SIZE 256*1024 //max config file size is 256KB +#ifdef GY_OS_AMBA +#define MAX_WEIGHT_FILE_SIZE 8*1024*1024 //max weight file size is 8MB +#define WEIGHT_ENCRYPT_SIZE 8*1024*1024 //weight encryption size is 8MB +#else +#define MAX_WEIGHT_FILE_SIZE 1*1024*1024 //max weight file size is 8MB +#define WEIGHT_ENCRYPT_SIZE 1*1024*1024 //weight encryption size is 8MB +#endif + +#define MAX_MSG_LEN 512 //max printed message length +#define MAX_PATH 256 //max path length +#ifdef GY_OS_AMBA +#define MAX_DETECT_OBJECTS 256 //max detected object number +#else +#define MAX_DETECT_OBJECTS MAX_TRACKING_NUM //max detected object number +#endif +#define MAX_SELECTED_FILES 50 //max selected files from CFileDialog +#define MAX_NETWORK_POOL_NUM 16 //max selected files from CFileDialog +#define MAX_PLATE_NUMBER 32 +#define MATH_PI 3.14159265358979323846 +#define BUFSIZE 8192 +#define BUFSIZE_V2 8192*8 +#define BUFSIZE_V3 8192*13 +#define MAX_QUEUE_SIZE 10 +#ifdef GY_OS_AMBA +#define MAX_REPEAT_PUSH_THE_FORCED 5 +#else +#define MAX_REPEAT_PUSH_THE_FORCED 1 +#endif +#define MAX_SESSION_ID 512 +#define MAX_NUMBER_SESSION 50 +#define MAX_NUMBER_DELETED_SESSION 10 + +#define THRESHOLD_POLYGON_AREA 0.1 +#define EXPAND_AREA 2 + +#define MAX_SIZE_SWITCH_HAPPENED 5 +#define GAP_SWITCH_HAPPENED 3 + +#define PI 3.1415926 +#define DIRECTION_DEFAULT 404 +#define DIFF_ANGLE_TO_DROP_OUT 150 + + +#define MAX_AI_ENGINE_VIEW 1 +#define MAX_ACCOUNT_DATA_NUM 10 //20201027 sophia add +#define ACCOUNT_DATA_BUFF_SIZE 256 //20201027 sophia add +#define MAX_ACCOUNT_DATA_BUFF_SIZE (MAX_ACCOUNT_DATA_NUM*ACCOUNT_DATA_BUFF_SIZE) //20201027 sophia add +#define RATIO_ADJUSTED_TO_WIDTH_AND_HEIGHT 0.46 + + +//קKܼƨSŧi +#ifndef TCP_FASTOPEN +#define TCP_FASTOPEN 15 +#endif +//קKܼƨSŧi +#ifndef SOL_TCP +#define SOL_TCP 6 //TCP level +#endif +//קKܼƨSŧi +#ifndef TCP_NODELAY +#define TCP_NODELAY 0x01 //don't delay send to coalesce packets +#endif + +#define MAX_ERROR_COUNT 10 +#define MAX_COUNT_TO_REFRESH_CHECK_LICENSE 10 +#define MAX_COUNT_TO_REFRESH_SMTP_SERVICE 10 + +#define MAX_COUNT_TO_REFRESH_LPR_DB 10*60//10*60 + +#define MAX_OBJ_DWELL_TIME 21474835 + +#define USLEEP_PLATE 25 + +#ifdef GY_OS_AMBA +#define SLEEP_HTTP_CONNECTION_HANDLER 45 //75 35 //45 +#else +#define SLEEP_HTTP_CONNECTION_HANDLER 100 //60 //35 //75 +#endif +#define SLEEP_RUN_HTTP_SERVER_THREAD 10 + +#ifdef GY_OS_AMBA +#define USLEEP_RUN_ONE_NET_THREAD 100 //10000 +#elif defined GY_OS_V_SERIES +#define USLEEP_RUN_ONE_NET_THREAD 60000 //50000 //80000 +#else +#define USLEEP_RUN_ONE_NET_THREAD 60000 //50000 //70000 +#endif + +#define USLEEP_PNS_SNAP_THREAD 100000 //250000 // 100000 + +#define USLEEP_IMAGE_DSP 100000 + +#define USLEEP_QUEUE_PUSH_ALARM_AND_POST 1000 // 1000 +#define USLEEP_QUEUE_PUSH_ALARM_AND_POST_ELSE 1000 // 1000 +#define SLEEP_QUEUE_PUSH_ALARM_AND_POST_LPR 28 + +#define SLEEP_QUEUE_POP_POST 300 + +#define USLEEP_QUEUE_POP_ALMQUEUE_PUSH_ALARM 600 //50 +#define USLEEP_QUEUE_POP_ALMQUEUE_PUSH_ALARM_ELSE 1200 // 1200 + +#define SLEEP_QUEUE_POP_ALMQUEUE_PUSH_ALARM_LPR 26 +#define USLEEP_ALMQUEUE_POP_ALARM 1000 //1000 +#define USLEEP_ALMQUEUE_POP_ALARM_ELSE 24000 //24000 +#define SLEEP_ALMQUEUE_POP_ALARM_LPR 24 + +#define SLEEP_RADAR_ALARM 100 + +#define MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_0 300 +#define MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_1 250 +#define MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_2 200 +#define MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_3 150 //240 + +//#define MAX_VOTE_VALUE_SECOND_OBJECT_TRACKING 320 +//#define MAX_VOTE_VALUE_SECOND_OBJECT_TRACKING_OTHER 320 + +//#define MAX_VOTE_VALUE_SECOND_OBJECT_TRACKING_LOW 240 +//#define MAX_VOTE_VALUE_SECOND_OBJECT_TRACKING_OTHER_LOW 240 + +#define MAX_SIZE_OSD_ARRAY 12 +#define MAX_SIZE_SP_ARRAY 64 +#define MAX_OBJ_TRACKING_ID_IN_ZONE 128 + +#ifdef GY_OS_AMBA +//#define MAX_SENSOR_TYPE0 111*51//111*51 3*37 3*17 3*13 3*7 39*21 +#define MAX_SENSOR_TYPE0 19*11//111*51 3*37 3*17 3*13 3*7 39*21 ///19 11 +#else +#define MAX_SENSOR_TYPE0 19*11//111*51 3*37 3*17 3*13 3*7 39*21 ///19 11 +#endif + +#define MAX_SENSOR_TYPE1 19*11 //39*21 +#define MAX_SENSOR_OTHERS 9 +#define MAX_POST_EVENTS 9 +#define MAX_EVENT_COUNTERS 8//64 +#define MAX_REPORT_COUNTERS 4 +#define MAX_SNMP_MANAGEMENT 5 +#define MAX_PLATE_RECORDER 256//64 +#define MAX_LOCKED_IVS_RECORD 256 +#define MAX_OBJECT_RECORDER 1024//64 //1024 + +#define MAX_POST_RECODER_SIZE 128//64 //1024 + +#define MAX_RECORD_PROCESS 50 +#define MAX_PROCESS_LENGTH 64 + +#define MAX_MOTION_AREA 128 +#define MAX_SNAP_HD_LIST 6 +#define DETECTION_POINTS_COUNT 4 +#ifdef GY_OS_NOVA +#define MAX_DETECTION_ZONE 4 +#else +#define MAX_DETECTION_ZONE 8 +#endif +#define MAX_SPIDER_ZONE 16 +#define MAX_SIZE_PARKING_SPACE 30 +#define MAX_TRIGGER_EVENT 23 +#define FPS_AVG_SECS 5 +#define TRACKING_BUFFER_SIZE 3 +#ifdef GY_OS_NOVA +#define MAX_LAYER_NUM 2 +#else +#define MAX_LAYER_NUM 4 +#endif +#define MAX_LAYER_NUM_FOR_WEAK_FPS 4 +#define MAX_LAYER_NUM_FOR_WORST_FPS 3 +#define MAX_GPU_NUM 16 +#define TRIGGER_INTERVAL 2 +#define MAX_CAVALRY_REPEAT_FREE 15 +#define MAX_SHARKHAND_REPEAT 2 +#define MSG_START_PATTERN "--boundary START\r\n" +#define MSG_RESOLUTION_PATTERN "resolution:" //resolution:1920x1080\r\n +#define MSG_END_PATTERN "\r\n--boundary END" +#define MULTIPART_CONTENT "multipart/form-data; boundary=" +#define MOVE_FORWARD_PREFIX "c_" +#ifdef GY_OS_WIN +#define TLT_FILE_PATH_WIN "C:\\Users\\Default\\AppData\\Local\\Microsoft\\WindowsTLT\\gysetting.json" +#else +#define TLT_FILE_NAME "/emmc/plugin/Aida_data/gysetting.json" //20201203 sophia add +#endif +#define LOGO_PREFIX "l_" +#define NO_OUTPUT_PREFIX "n_" +#define MULTIPART_BOUNDARY "--------------------------WebKitFormBoundary7MA4YWxkTrZu0gW" +#define MULTITHREAD_SERVER +#define SINGLE_MYRIAD_MULTIPLE_NETWORKS +#define FACE_CROP_IMG_STORAGE "/emmc/plugin" + +//definition +typedef enum { _JPEG, _I420, _YV12 }ImgType; +typedef enum { _FALSE, _TRUE } MYBOOL; +typedef enum{ _NO_LICENSE, +_PERMANENT_LICENSE_MULTI, _PERMANENT_LICENSE_SINGLE, _TRIAL_LICENSE_MULTI, _TRIAL_LICENSE_SINGLE, _PERMANENT_LICENSE_MULTI_POST, _LICENSE_FPS06,_PERMANENT_LICENSE_SINGLE_POST, _LICENSE_08, _LICENSE_09, _LICENSE_10, +_LICENSE_11, _LICENSE_FPS12, _LICENSE_13, _LICENSE_14, _LICENSE_15, _LICENSE_16, _LICENSE_17, _LICENSE_FPS18, _LICENSE_19, _LICENSE_20, +_LICENSE_21, _LICENSE_22, _LICENSE_23, _LICENSE_FPS24, _LICENSE_25, _LICENSE_26, _LICENSE_27, _LICENSE_28, _LICENSE_29, _LICENSE_FPS30, +_LICENSE_31, _LICENSE_32, _LICENSE_33, _LICENSE_34, _LICENSE_35, _LICENSE_FPS36, _LICENSE_37, _LICENSE_38, _LICENSE_39, _LICENSE_40, +_LICENSE_41, _LICENSE_FPS42, _LICENSE_43, _LICENSE_44, _LICENSE_45, _LICENSE_46, _LICENSE_47, _LICENSE_FPS48, _LICENSE_49, _LICENSE_50, +_LICENSE_51, _LICENSE_52, _LICENSE_53, _LICENSE_FPS54, _LICENSE_55, _LICENSE_56, _LICENSE_57, _LICENSE_58, _LICENSE_59, _LICENSE_FPS60, +_TRIAL_LICENSE_01, _TRIAL_LICENSE_02, _TRIAL_LICENSE_03, _TRIAL_LICENSE_04, _TRIAL_LICENSE_05, _TRIAL_LICENSE_FPS06, _TRIAL_LICENSE_07, _TRIAL_LICENSE_FPS08, _TRIAL_LICENSE_09, _TRIAL_LICENSE_10, +_TRIAL_LICENSE_11, _TRIAL_LICENSE_FPS12, _TRIAL_LICENSE_13, _TRIAL_LICENSE_14, _TRIAL_LICENSE_15, _TRIAL_LICENSE_16, _TRIAL_LICENSE_17, _TRIAL_LICENSE_FPS18, _TRIAL_LICENSE_19, _TRIAL_LICENSE_20, +_TRIAL_LICENSE_21, _TRIAL_LICENSE_22, _TRIAL_LICENSE_23, _TRIAL_LICENSE_FPS24, _TRIAL_LICENSE_25, _TRIAL_LICENSE_26, _TRIAL_LICENSE_27, _TRIAL_LICENSE_28, _TRIAL_LICENSE_29, _TRIAL_LICENSE_FPS30, +_TRIAL_LICENSE_31, _TRIAL_LICENSE_32, _TRIAL_LICENSE_33, _TRIAL_LICENSE_34, _TRIAL_LICENSE_35, _TRIAL_LICENSE_FPS36, _TRIAL_LICENSE_37, _TRIAL_LICENSE_38, _TRIAL_LICENSE_39, _TRIAL_LICENSE_40, +_TRIAL_LICENSE_41, _TRIAL_LICENSE_FPS42, _TRIAL_LICENSE_43, _TRIAL_LICENSE_44, _TRIAL_LICENSE_45, _TRIAL_LICENSE_46, _TRIAL_LICENSE_47, _TRIAL_LICENSE_FPS48, _TRIAL_LICENSE_49, _TRIAL_LICENSE_50, +_TRIAL_LICENSE_51, _TRIAL_LICENSE_52, _TRIAL_LICENSE_53, _TRIAL_LICENSE_FPS54, _TRIAL_LICENSE_55, _TRIAL_LICENSE_56, _TRIAL_LICENSE_57, _TRIAL_LICENSE_58, _TRIAL_LICENSE_59, _TRIAL_LICENSE_FPS60 +} LicenseType; +typedef enum { + _AD_LICENSE_BASIC, _AD_LICENSE_01 +} AdvanceLicenseType; +typedef enum { _LICENSED, _NOT_LICENSED, _EXPIRED, _UNINITIALIZED, _MAC_MISMATCH}AuthFailStatusCode; +typedef enum { _CODE_200, _CODE_204, _CODE_400, _CODE_401, _CODE_403, _CODE_404, _CODE_503}HttpCode; +typedef enum { _TCP_SERVER, _HTTP_SERVER }ServerType; +typedef enum { _PLATE, _LOGO, _PREFIX, _NUMBER, _DASH, _MISTAKE, _TRAFFIC_LIGHT, _COUNTER}ObjectType; +typedef enum { _PERSON, _NOSE, _NECK, _RIGHT_SHOULDER, _RIGHT_ELBOW, _RIGHT_WRIST, _LEFT_SHOULDER, _LEFT_ELBOW, _LEFT_WRIST, _RIGHT_HIP, _RIGHT_KNEE, +_RIGHT_ANKLE, _LEFT_HIP, _LEFT_KNEE, _LEFT_ANKLE, _RIGHT_EYE, _LEFT_EYE, _RIGHT_EAR, _LEFT_EAR} HumanPoseObjectType; +typedef enum { _OPENVINO, _CUDA, _AMBA }CNNType; +typedef enum { _O, _0 } AmbiguousChar0; +typedef enum { _I, _1 } AmbiguousChar1; +typedef enum { _POST_NOTIFICATION, _GETALARMMOTION } QueueType; +typedef enum { _DEFAULT_COLOR, _NORMAL_COLOR, _TRAFFIC_COLOR, _PLATE_COLOR, _TRAFFIC_LIGHT_COLOR } ColorDetectionType; + + +/*static char *HumanPoseObjectNames[] = { "person", "nose", "neck","right shoulder","right elbow","right wrist","left shoulder","left elbow","left wrist", +"right hip","right knee","right ankle","left hip","left knee","left ankle","right eye","left eye","right ear","left ear" };*/ + +extern LicenseType licenseType; +extern AdvanceLicenseType advLicenseType; +extern AuthFailStatusCode afsCode; +extern HttpCode httpCode; +extern MYBOOL activeDisplayDash; +extern MYBOOL activeDisplayProperties; +extern MYBOOL activePostNotification; +extern MYBOOL activeSNMPPost; +extern MYBOOL testPostNotification; +extern int api_format_ver; + + +extern int nIsCompatibleCPU; +extern int nIsCompatibleGPU; +extern int nIsCompatibleVPU; +extern size_t advancedType; +//feature type +extern size_t featureType; +#define FEATURE_TRAF_DET 0x0001 +#define FEATURE_ACCESS_CTRL 0x0002 +#define FEATURE_HUM_DET 0x0004 +#define FEATURE_HUM_POS 0x0008 +#define FEATURE_LED_DGT 0x0010 +#define FEATURE_SHOES_DET 0x0020 +#define FEATURE_POK_DET 0x0040 +#define FEATURE_LPR_LOGO 0x0080 + +#define FEATURE_LPR_TWN 0x0100 +#define FEATURE_LPR_EUR 0x0200 +#define FEATURE_LPR_SEA 0x0400 +#define FEATURE_LPR_IND 0x0800 +#define FEATURE_LPR_MEA 0x1000 +#define FEATURE_LPR_USA 0x2000 +#define FEATURE_LPR_AUS 0x4000 +#define FEATURE_LPR_GBR 0x8000 +#define FEATURE_LPR_IDN 0x10000 +#define FEATURE_LPR_JPN 0x20000 +#define FEATURE_LPR_NPL 0x40000 +#define FEATURE_LPR_THA 0x80000 +#define FEATURE_LPR_LAO 0x100000 +#define FEATURE_LPR_BGD 0x200000 +#define FEATURE_LPR_VNM 0x800000 +#define FEATURE_LPR_PHL 0x04000000 +#define FEATURE_LPR_CNT 0x08000000 + +#define FEATURE_PRESERVE22 0x400000 +#define FEATURE_PRESERVE23 0x800000 + +#define FEATURE_OTHER_ITEMS 0x800000 + +#define FEATURE_AIRAIL 0x10000000 +#define FEATURE_AIFIRE 0x20000000 +#define FEATURE_AIFISHTRAF 0x40000000 +//#define FEATURE_AIRADAR 0x80000000 + +//if contains feature +#define HUM_POS_ESTIMATOR + +//feature type2 +extern size_t featureType2; +#define FEATURE_EMPTY 0x0000 +#define FEATURE_AIFLOW 0x0001 +#define FEATURE_AIAREA 0x0002 +#define FEATURE_AIVIO 0x0004 +#define FEATURE_AISPC 0x0008 +#define FEATURE_AIFISHANPR 0x0010 +#define FEATURE_AICAP 0x0020 +#define FEATURE_PRESERVE01 0x0040 +#define FEATURE_AISPORTS 0x0080 +#define FEATURE_AIMASK 0x0100 +#define FEATURE_AIGARBAGE 0x0100 +#define FEATURE_AIAREO 0x0200 //FEATURE_AIDIS +#define FEATURE_AIHELM 0x0400 +#define FEATURE_AIPRODUCTION 0x0080 +#define FEATURE_AIAML 0x1000 +#define FEATURE_AISHIP 0x2000 +#define FEATURE_AIRADAR 0x4000 // Ken 2022-10-13 +#define FEATURE_AITOF 0x8000 // Ken 2022-12-08 +//#define FEATURE_AIFACE 0x0800 // leo 2023-09-01 + +#define FEATURE_DET_AIFISHTRAF 0x0001 +#define FEATURE_DET_AIRAIL 0x0001 +#define FEATURE_DET_AIFIRE 0x0001 + +//trigger events +#define TRIGGER_ZONE_VIOLATION 0x00000001 +#define TRIGGER_PARKING 0x00000002 +#define TRIGGER_PARKING_VIOLATION 0x00000004 +#define TRIGGER_GO_STRAIGHT 0x00000008 +#define TRIGGER_TURN_LEFT 0x00000010 +#define TRIGGER_TURN_RIGHT 0x00000020 +#define TRIGGER_WRONG_WAY 0x00000040 +#define TRIGGER_TURN_LEFT_VIOLATION 0x00000080 +#define TRIGGER_TURN_RIGHT_VIOLATION 0x00000100 +#define TRIGGER_U_TURN_VIOLATION 0x00000200 +#define TRIGGER_GO_STRAIGHT_RED_LIGHT 0x00000400 +#define TRIGGER_TURN_LEFT_RED_LIGHT 0x00000800 +#define TRIGGER_TURN_RIGHT_RED_LIGHT 0x00001000 +#define TRIGGER_SPEED_HIGH 0x00002000 +#define TRIGGER_SPEED_LOW 0x00004000 +#define TRIGGER_FORGET_TO_GIVE_WAY 0x00008000 + +#define TRIGGER_DISTANCE_VIOLATION 0x00040000 + +#define TRIGGER_ALLOW_LIST 0x00200000 +#define TRIGGER_BLOCK_LIST 0x00400000 +#define TRIGGER_GUEST_LIST 0x00800000 +#define TRIGGER_MISSING_UNATTENDED 0x01000000 +#define TRIGGER_BG_LEARNING 0x02000000 +#define TRIGGER_TAMPERING 0x04000000 + +#define TRIGGER_HIGH_VIOLATION 0x08000000 + +#define TRIGGER_QUEUING_VIOLATION 0x10000000 +#define TRIGGER_MISSING_OBJECT_DETECTION 0x20000000 +#define TRIGGER_ALL_OBJECTS 0x40000000 +#define TRIGGER_LACK_OF_ANY_OBJECT 0x80000000 + +//vehicles plate pattern +//Australia +#define REGEX_LPR_AUS_ACT_VEH "^Y[A-Z]{2}-[0-9]{2}[A-Z]{1}$" +#define REGEX_LPR_AUS_ACT_MOT "^A-[0-9]{4}$" +#define REGEX_LPR_AUS_ACT_TRA "^T-[0-9]{4}-[A-Z]{1}$" +#define REGEX_LPR_AUS_ACT_PER "^[A-Z]{2}-[0-9]{3}$" +#define REGEX_LPR_AUS_ACT_VEH_PRE "^Y[A-Z]{2}-[0-9]{3}$" +#define REGEX_LPR_AUS_NSW_VEH "^[A-Z]{2}-[0-9]{2}-[A-Z]{2}$" +#define REGEX_LPR_AUS_NSW_SLI "^[A-Z]{3}-[0-9]{2}[A-Z]{1}$" +#define REGEX_LPR_AUS_NSW_TRA "^T[A-Z]{1}-[0-9]{2}-[A-Z]{2}$" +#define REGEX_LPR_AUS_NSW_TRA2 "^TR-[0-9]{2}-[A-Z]{2}$" +#define REGEX_LPR_AUS_NSW_MOT "^[A-Z]{3}-[0-9]{2}$" +#define REGEX_LPR_AUS_NSW_VEH_PRE "^[A-Z]{3}-[0-9]{3}$" +#define REGEX_LPR_AUS_NSW_TRA_PRE "^[A-Z]{1}-[0-9]{5}$" +#define REGEX_LPR_AUS_NSW_MOT_PRE "^[A-Z]{2}-[0-9]{3}$" +#define REGEX_LPR_AUS_NTE_VEH "^C[A-Z]{1}-[0-9]{2}-[A-Z]{2}$" +#define REGEX_LPR_AUS_NTE_MOT "^[A-Z]{1}-[0-9]{4}$" +#define REGEX_LPR_AUS_NTE_TRA "^T[A-Z]{1}-[0-9]{4}$" +#define REGEX_LPR_AUS_QUE_VEH "^[0-9]{3}-[A-Z]{3}$" +#define REGEX_LPR_AUS_SAU_VEH "^S[0-9]{3}-[A-Z]{3}$" +#define REGEX_LPR_AUS_TAS_VEH "^[A-Z]{1}-[0-9]{2}-[A-Z]{2}$" +#define REGEX_LPR_AUS_VIC_VEH "^[0-9]{1}[A-Z]{2}-[0-9]{1}[A-Z]{2}$" +#define REGEX_LPR_AUS_WAU_VEH "^[0-9]{1}[A-Z]{3}-[0-9]{1}$" + +//GBR +#define REGEX_LPR_GBR_CUR_VEH "^[A-Z]{2}[0-9]{2}-[A-Z]{3}$" +#define REGEX_LPR_GBR_OLD_VEH "^[A-Z]{1}[0-9]{3}-[A-Z]{3}$" +#define REGEX_LPR_GBR_OLD_VEH2 "^[A-Z]{3}-[0-9]{3}[A-Z]{1}$" +#define REGEX_LPR_GBR_CUR_VEH_ "^[A-Z]{2}[0-9]{2}[A-Z]{3}$" +#define REGEX_LPR_GBR_OLD_VEH_ "^[A-Z]{1}[0-9]{3}[A-Z]{3}$" +#define REGEX_LPR_GBR_OLD_VEH2_ "^[A-Z]{3}[0-9]{3}[A-Z]{1}$" + +//indonesia +#define REGEX_LPR_IDN_BANT_VEH "^A([0-9]+).*$" +#define REGEX_LPR_IDN_CJA1_VEH "^AA([0-9]+).*$" +#define REGEX_LPR_IDN_YOG1_VEH "^AB([0-9]+).*$" +#define REGEX_LPR_IDN_CJA2_VEH "^AD([0-9]+).*$" +#define REGEX_LPR_IDN_EJA1_VEH "^AE([0-9]+).*$" +#define REGEX_LPR_IDN_EJA2_VEH "^AG([0-9]+).*$" +#define REGEX_LPR_IDN_JAKA_VEH "^B([0-9]+).*$" +#define REGEX_LPR_IDN_WSUM_VEH "^BA([0-9]+).*$" +#define REGEX_LPR_IDN_WCNS_VEH "^BB([0-9]+).*$" +#define REGEX_LPR_IDN_BENG_VEH "^BD([0-9]+).*$" +#define REGEX_LPR_IDN_LAMP_VEH "^BE([0-9]+).*$" +#define REGEX_LPR_IDN_SSUM_VEH "^BG([0-9]+).*$" +#define REGEX_LPR_IDN_JAMB_VEH "^BH([0-9]+).*$" +#define REGEX_LPR_IDN_ECNS_VEH "^BK([0-9]+).*$" +#define REGEX_LPR_IDN_ACEH_VEH "^BL([0-9]+).*$" +#define REGEX_LPR_IDN_RIAU_VEH "^BM([0-9]+).*$" +#define REGEX_LPR_IDN_BBEL_VEH "^BN([0-9]+).*$" +#define REGEX_LPR_IDN_RISL_VEH "^BP([0-9]+).*$" +#define REGEX_LPR_IDN_WJA1_VEH "^D([0-9]+).*$" +#define REGEX_LPR_IDN_SKAL_VEH "^DA([0-9]+).*$" +#define REGEX_LPR_IDN_NSU1_VEH "^DB([0-9]+).*$" +#define REGEX_LPR_IDN_WSUL_VEH "^DC([0-9]+).*$" +#define REGEX_LPR_IDN_SSU1_VEH "^DD([0-9]+).*$" +#define REGEX_LPR_IDN_MALU_VEH "^DE([0-9]+).*$" +#define REGEX_LPR_IDN_NMAL_VEH "^DG([0-9]+).*$" +#define REGEX_LPR_IDN_ENTT_VEH "^DH([0-9]+).*$" +#define REGEX_LPR_IDN_BALI_VEH "^DK([0-9]+).*$" +#define REGEX_LPR_IDN_NSU2_VEH "^DL([0-9]+).*$" +#define REGEX_LPR_IDN_GORO_VEH "^DM([0-9]+).*$" +#define REGEX_LPR_IDN_CSUL_VEH "^DN([0-9]+).*$" +#define REGEX_LPR_IDN_SSU2_VEH "^DP([0-9]+).*$" +#define REGEX_LPR_IDN_WNTL_VEH "^DR([0-9]+).*$" +#define REGEX_LPR_IDN_SESU_VEH "^DT([0-9]+).*$" +#define REGEX_LPR_IDN_SSU3_VEH "^DW([0-9]+).*$" +#define REGEX_LPR_IDN_WJA2_VEH "^E([0-9]+).*$" +#define REGEX_LPR_IDN_WNTS_VEH "^EA([0-9]+).*$" +#define REGEX_LPR_IDN_ENTF_VEH "^EB([0-9]+).*$" +#define REGEX_LPR_IDN_ENTS_VEH "^ED([0-9]+).*$" +#define REGEX_LPR_IDN_WJA3_VEH "^F([0-9]+).*$" +#define REGEX_LPR_IDN_CJA3_VEH "^G([0-9]+).*$" +#define REGEX_LPR_IDN_CJA4_VEH "^H([0-9]+).*$" +#define REGEX_LPR_IDN_CJA5_VEH "^K([0-9]+).*$" +#define REGEX_LPR_IDN_WKAL_VEH "^KB([0-9]+).*$" +#define REGEX_LPR_IDN_CKAL_VEH "^KH([0-9]+).*$" +#define REGEX_LPR_IDN_EKAL_VEH "^KT([0-9]+).*$" +#define REGEX_LPR_IDN_NKAL_VEH "^KU([0-9]+).*$" +#define REGEX_LPR_IDN_EJA3_VEH "^L([0-9]+).*$" +#define REGEX_LPR_IDN_EJA4_VEH "^M([0-9]+).*$" +#define REGEX_LPR_IDN_EJA5_VEH "^N([0-9]+).*$" +#define REGEX_LPR_IDN_EJA6_VEH "^P([0-9]+).*$" +#define REGEX_LPR_IDN_PAPU_VEH "^PA([0-9]+).*$" +#define REGEX_LPR_IDN_WPAP_VEH "^PB([0-9]+).*$" +#define REGEX_LPR_IDN_CJA6_VEH "^R([0-9]+).*$" +#define REGEX_LPR_IDN_EJA7_VEH "^S([0-9]+).*$" +#define REGEX_LPR_IDN_SURA_VEH "^SKB([0-9]+).*$" +#define REGEX_LPR_IDN_WJA4_VEH "^T([0-9]+).*$" +#define REGEX_LPR_IDN_EJA8_VEH "^W([0-9]+).*$" +#define REGEX_LPR_IDN_YOG2_VEH "^YB([0-9]+).*$" +#define REGEX_LPR_IDN_YOG3_VEH "^YK([0-9]+).*$" +#define REGEX_LPR_IDN_WJA5_VEH "^Z([0-9]+).*$" + +#endif diff --git a/src/sha1.c b/src/sha1.c new file mode 100644 index 0000000..77be843 --- /dev/null +++ b/src/sha1.c @@ -0,0 +1,195 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "base64.h" +#include "intLib.h" +#include "sha1.h" +#include <ctype.h> + +void SHA1Reset(SHA1Context *); +int SHA1Result(SHA1Context *); +void SHA1Input(SHA1Context *, char *, unsigned); + +#define SHA1CircularShift(bits,word) ((((word) << (bits)) & 0xFFFFFFFF) | ((word) >> (32-(bits)))) + +void SHA1ProcessMessageBlock(SHA1Context *); +void SHA1PadMessage(SHA1Context *); + +void SHA1Reset(SHA1Context *context) { + context->Length_Low = 0; + context->Length_High = 0; + context->Message_Block_Index = 0; + + context->Message_Digest[0] = 0x67452301; + context->Message_Digest[1] = 0xEFCDAB89; + context->Message_Digest[2] = 0x98BADCFE; + context->Message_Digest[3] = 0x10325476; + context->Message_Digest[4] = 0xC3D2E1F0; + + context->Computed = 0; + context->Corrupted = 0; +} + + +int SHA1Result(SHA1Context *context) { + if (context->Corrupted) { + return 0; + } + if (!context->Computed) { + SHA1PadMessage(context); + context->Computed = 1; + } + return 1; +} + + +void SHA1Input(SHA1Context *context, char *message_array, unsigned length) { + if (!length) {} + else { + if (context->Computed || context->Corrupted) { + context->Corrupted = 1; + } + else { + while (length-- && !context->Corrupted) { + context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); + + context->Length_Low += 8; + + context->Length_Low &= 0xFFFFFFFF; + if (context->Length_Low == 0) { + context->Length_High++; + context->Length_High &= 0xFFFFFFFF; + if (context->Length_High == 0) context->Corrupted = 1; + } + + if (context->Message_Block_Index == 64) { + SHA1ProcessMessageBlock(context); + } + message_array++; + } + } + } +} + +void SHA1ProcessMessageBlock(SHA1Context *context) { + unsigned K[] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 }; + int t; + unsigned temp; + unsigned W[80]; + unsigned A, B, C, D, E; + + for (t = 0; t < 16; t++) { + W[t] = ((unsigned)context->Message_Block[t * 4]) << 24; + W[t] |= ((unsigned)context->Message_Block[t * 4 + 1]) << 16; + W[t] |= ((unsigned)context->Message_Block[t * 4 + 2]) << 8; + W[t] |= ((unsigned)context->Message_Block[t * 4 + 3]); + } + + for (t = 16; t < 80; t++) W[t] = SHA1CircularShift(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]); + + A = context->Message_Digest[0]; + B = context->Message_Digest[1]; + C = context->Message_Digest[2]; + D = context->Message_Digest[3]; + E = context->Message_Digest[4]; + + for (t = 0; t < 20; t++) { + temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + for (t = 20; t < 40; t++) { + temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[1]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + for (t = 40; t < 60; t++) { + temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + for (t = 60; t < 80; t++) { + temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[3]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + context->Message_Digest[0] = (context->Message_Digest[0] + A) & 0xFFFFFFFF; + context->Message_Digest[1] = (context->Message_Digest[1] + B) & 0xFFFFFFFF; + context->Message_Digest[2] = (context->Message_Digest[2] + C) & 0xFFFFFFFF; + context->Message_Digest[3] = (context->Message_Digest[3] + D) & 0xFFFFFFFF; + context->Message_Digest[4] = (context->Message_Digest[4] + E) & 0xFFFFFFFF; + context->Message_Block_Index = 0; +} + +void SHA1PadMessage(SHA1Context *context) { + if (context->Message_Block_Index > 55) { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while (context->Message_Block_Index < 64) context->Message_Block[context->Message_Block_Index++] = 0; + SHA1ProcessMessageBlock(context); + while (context->Message_Block_Index < 56) context->Message_Block[context->Message_Block_Index++] = 0; + } + else { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while (context->Message_Block_Index < 56) context->Message_Block[context->Message_Block_Index++] = 0; + } + context->Message_Block[56] = (context->Length_High >> 24) & 0xFF; + context->Message_Block[57] = (context->Length_High >> 16) & 0xFF; + context->Message_Block[58] = (context->Length_High >> 8) & 0xFF; + context->Message_Block[59] = (context->Length_High) & 0xFF; + context->Message_Block[60] = (context->Length_Low >> 24) & 0xFF; + context->Message_Block[61] = (context->Length_Low >> 16) & 0xFF; + context->Message_Block[62] = (context->Length_Low >> 8) & 0xFF; + context->Message_Block[63] = (context->Length_Low) & 0xFF; + + SHA1ProcessMessageBlock(context); +} + +void sha1_hash(char *source, char *outBuffer) {// Main + SHA1Context sha; + //char *buf;//[128]; + + //printf("111 \n"); + + SHA1Reset(&sha); + //printf("222 \n"); + + SHA1Input(&sha, source, strlen(source)); + //printf("333 \n"); + + if (!SHA1Result(&sha)) { + printf("SHA1 ERROR: Could not compute message digest"); + } + else { + //printf("444 \n"); + //buf = (char *)malloc(128); + //memset(buf, 0, sizeof(buf)); + //sprintf(buf, "%08X%08X%08X%08X%08X", sha.Message_Digest[0], sha.Message_Digest[1], + // sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]); + sprintf(outBuffer, "%08X%08X%08X%08X%08X", sha.Message_Digest[0], sha.Message_Digest[1], + sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]); + + //printf("555 \n %s \n", outBuffer); + //lr_save_string(buf, lrvar); + + //return strlen(buf); + //return buf; + + } +} + diff --git a/src/sha1.h b/src/sha1.h new file mode 100644 index 0000000..b5fa22d --- /dev/null +++ b/src/sha1.h @@ -0,0 +1,29 @@ +#pragma once +#ifndef _SHA1_H_ +#define _SHA1_H_ + +#include "define_inc.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "base64.h" +#include "intLib.h" +#define SHA1_DATA_SIZE 20 + +typedef struct SHA1Context { + unsigned Message_Digest[5]; + unsigned Length_Low; + unsigned Length_High; + unsigned char Message_Block[64]; + int Message_Block_Index; + int Computed; + int Corrupted; +} SHA1Context; + +void sha1_hash(char *source, char *outBuffer); +#endif + + + + + diff --git a/src/shortcut_layer.c b/src/shortcut_layer.c new file mode 100644 index 0000000..586d776 --- /dev/null +++ b/src/shortcut_layer.c @@ -0,0 +1,125 @@ +#include "shortcut_layer.h" +#include "cuda.h" +#include "blas.h" +#include "activations.h" + +#include <stdio.h> +#include <assert.h> + +layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2) +{ + fprintf(stderr, "res %3d %4d x%4d x%4d -> %4d x%4d x%4d\n",index, w2,h2,c2, w,h,c); + layer l = {0}; + l.type = SHORTCUT; + l.batch = batch; + l.w = w2; + l.h = h2; + l.c = c2; + l.out_w = w; + l.out_h = h; + l.out_c = c; + l.outputs = w*h*c; + l.inputs = l.outputs; + + l.index = index; + + l.delta = calloc(l.outputs*batch, sizeof(float)); + l.output = calloc(l.outputs*batch, sizeof(float));; + + l.forward = forward_shortcut_layer; + l.backward = backward_shortcut_layer; + #ifdef GPU + l.forward_gpu = forward_shortcut_layer_gpu; + l.backward_gpu = backward_shortcut_layer_gpu; + + l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch); + l.output_gpu = cuda_make_array(l.output, l.outputs*batch); + #endif + return l; +} + +void resize_shortcut_layer(layer *l, int w, int h) +{ + assert(l->w == l->out_w); + assert(l->h == l->out_h); + l->w = l->out_w = w; + l->h = l->out_h = h; + l->outputs = w*h*l->out_c; + l->inputs = l->outputs; + l->delta = realloc(l->delta, l->outputs*l->batch*sizeof(float)); + l->output = realloc(l->output, l->outputs*l->batch*sizeof(float)); + +#ifdef GPU + cuda_free(l->output_gpu); + cuda_free(l->delta_gpu); + l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); + l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch); +#endif + +} + + +void forward_shortcut_layer(const layer l, network net) +{ + copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1); + shortcut_cpu(l.batch, l.w, l.h, l.c, net.layers[l.index].output, l.out_w, l.out_h, l.out_c, l.alpha, l.beta, l.output); + activate_array(l.output, l.outputs*l.batch, l.activation); +} + +void backward_shortcut_layer(const layer l, network net) +{ + gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); + axpy_cpu(l.outputs*l.batch, l.alpha, l.delta, 1, net.delta, 1); + shortcut_cpu(l.batch, l.out_w, l.out_h, l.out_c, l.delta, l.w, l.h, l.c, 1, l.beta, net.layers[l.index].delta); +} + +#ifdef GPU +void forward_shortcut_layer_gpu(const layer l, network net) +{ + copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1); + shortcut_gpu(l.batch, l.w, l.h, l.c, net.layers[l.index].output_gpu, l.out_w, l.out_h, l.out_c, l.alpha, l.beta, l.output_gpu); + activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation); +} + +void backward_shortcut_layer_gpu(const layer l, network net) +{ + gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); + axpy_gpu(l.outputs*l.batch, l.alpha, l.delta_gpu, 1, net.delta_gpu, 1); + shortcut_gpu(l.batch, l.out_w, l.out_h, l.out_c, l.delta_gpu, l.w, l.h, l.c, 1, l.beta, net.layers[l.index].delta_gpu); +} +#endif + +#ifdef ALLEN_MODIFY +layer make_shortcut_layer_mem(int batch, int index, int w, int h, int c, int w2, int h2, int c2) +{ + //fprintf(stderr, "Shortcut Layer: %d\n", index); + layer l = { 0 }; + l.type = SHORTCUT; + l.batch = batch; + l.w = w2; + l.h = h2; + l.c = c2; + l.out_w = w; + l.out_h = h; + l.out_c = c; + l.outputs = w * h*c; + l.inputs = l.outputs; + + l.index = index; + + l.delta = calloc(l.outputs*batch, sizeof(float)); + l.output = calloc(l.outputs*batch, sizeof(float));; + + l.forward = forward_shortcut_layer; + l.backward = backward_shortcut_layer; +#ifdef GPU + l.forward_gpu = forward_shortcut_layer_gpu; + l.backward_gpu = backward_shortcut_layer_gpu; + + l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch); + l.output_gpu = cuda_make_array(l.output, l.outputs*batch); +#endif + return l; +} + +#endif \ No newline at end of file diff --git a/src/shortcut_layer.h b/src/shortcut_layer.h new file mode 100644 index 0000000..26a9695 --- /dev/null +++ b/src/shortcut_layer.h @@ -0,0 +1,22 @@ + +#pragma once +#ifndef SHORTCUT_LAYER_H +#define SHORTCUT_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" +#define ALLEN_MODIFY +layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2); +void forward_shortcut_layer(const layer l, network net); +void backward_shortcut_layer(const layer l, network net); +void resize_shortcut_layer(layer *l, int w, int h); + +#ifdef GPU +void forward_shortcut_layer_gpu(const layer l, network net); +void backward_shortcut_layer_gpu(const layer l, network net); +#endif +#ifdef ALLEN_MODIFY +layer make_shortcut_layer_mem(int batch, int index, int w, int h, int c, int w2, int h2, int c2); +#endif + +#endif diff --git a/src/signal_test.c b/src/signal_test.c new file mode 100644 index 0000000..a0c4ea0 --- /dev/null +++ b/src/signal_test.c @@ -0,0 +1,203 @@ + +#include <signal.h> +#include <unistd.h> +#include <stdio.h> +#include <unistd.h> +#include <dirent.h> +#include <sys/types.h> // for opendir(), readdir(), closedir() +#include <sys/stat.h> // for stat() +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#define PROC_DIRECTORY "/proc/" +#define CASE_SENSITIVE 1 +#define CASE_INSENSITIVE 0 +#define EXACT_MATCH 1 +#define INEXACT_MATCH 0 + +//是不是數字 +int IsNumeric(const char* ccharptr_CharacterList) +{ + for ( ; *ccharptr_CharacterList; ccharptr_CharacterList++) + if (*ccharptr_CharacterList < '0' || *ccharptr_CharacterList > '9') + return 0; // false + return 1; // true +} + +//intCaseSensitive=0大小寫不敏感 +int strcmp_Wrapper(const char *s1, const char *s2, int intCaseSensitive) +{ + if (intCaseSensitive) + return !strcmp(s1, s2); + else + return !strcasecmp(s1, s2); +} +//intCaseSensitive=0大小寫不敏感 +int strstr_Wrapper(const char* haystack, const char* needle, int intCaseSensitive) +{ + //if (intCaseSensitive) + { + if (strstr(haystack, needle) != NULL) { + return 1; + } + else { + return 0; + } + } + /* + else { + if (strcasestr(haystack, needle) != NULL) { + return 1; + } + else { + return 0; + } + }*/ +} +pid_t GetPIDbyName_implements(char* cchrptr_ProcessName, int intCaseSensitiveness, int intExactMatch, int start_server) +{ + char chrarry_CommandLinePath[100] = { 0 }; + char chrarry_NameOfProcess[300] = { 0 }; + char* chrptr_StringToCompare = NULL ; + char* cchrptr_ProcessName2 = NULL ; + pid_t pid_ProcessIdentifier = (pid_t) -1 ; + struct dirent* de_DirEntity = NULL ; + DIR* dir_proc = NULL ; + int (*CompareFunction) (const char*, const char*, int) ; + if (intExactMatch) + CompareFunction = &strcmp_Wrapper; + else + CompareFunction = &strstr_Wrapper; + if (strrchr(cchrptr_ProcessName, '/')) + cchrptr_ProcessName2 = strrchr(cchrptr_ProcessName, '/') ; + else + cchrptr_ProcessName2 = cchrptr_ProcessName ; + dir_proc = opendir(PROC_DIRECTORY) ; + if (dir_proc == NULL) + { + printf("\nCouldn't open the %s directory\n", PROC_DIRECTORY) ; + return (pid_t) -2 ; + } + + int count_the_same_name = 0; + + // Loop while not NULL + while ( (de_DirEntity = readdir(dir_proc)) ) + { + if (de_DirEntity->d_type == DT_DIR) + { + if (IsNumeric(de_DirEntity->d_name)) + { + strcpy(chrarry_CommandLinePath, PROC_DIRECTORY) ; + strcat(chrarry_CommandLinePath, de_DirEntity->d_name) ; + strcat(chrarry_CommandLinePath, "/cmdline") ; + + //printf("\n--------chrarry_CommandLinePath:%s\n", chrarry_CommandLinePath); + + FILE* fd_CmdLineFile = fopen (chrarry_CommandLinePath, "rt") ; //open the file for reading text + if (fd_CmdLineFile) + { + fscanf(fd_CmdLineFile, "%s", chrarry_NameOfProcess) ; //read from /proc/<NR>/cmdline + fclose(fd_CmdLineFile); //close the file prior to exiting the routine + + char temp_chrarry_NameOfProcess[300] = { 0 }; + strcpy(temp_chrarry_NameOfProcess, chrarry_NameOfProcess); + + //printf("Pure Process name: %s\n", temp_chrarry_NameOfProcess); + + if (strrchr(chrarry_NameOfProcess, '/')) + chrptr_StringToCompare = strrchr(chrarry_NameOfProcess, '/'); + else + chrptr_StringToCompare = chrarry_NameOfProcess; + //printf("Process name: %s\n", chrarry_NameOfProcess); + //這個是全路徑,比如/bin/ls + + //這個是純程序名,比如ls + //這裡可以比較全路徑名,設定為chrarry_NameOfProcess即可 + if ( CompareFunction(chrptr_StringToCompare, cchrptr_ProcessName2, intCaseSensitiveness) && strstr(temp_chrarry_NameOfProcess,"mon")==NULL +#ifdef GY_OS_NOVA + && strstr(temp_chrarry_NameOfProcess, "sh -c") == NULL +#endif + ) + { + count_the_same_name++; + if (count_the_same_name == 1) { + pid_ProcessIdentifier = (pid_t)atoi(de_DirEntity->d_name); + if (start_server == 0) + break; + } + else if (count_the_same_name >= 2) { + pid_ProcessIdentifier = (pid_t)-3; + break; + } + + //closedir(dir_proc) ; + //return pid_ProcessIdentifier; + } + } + } + } + } + closedir(dir_proc) ; + return pid_ProcessIdentifier; +} +//找pid +pid_t GetPIDbyName_Wrapper(char* cchrptr_ProcessName, int start_server) +{ + return GetPIDbyName_implements(cchrptr_ProcessName, 0,0, start_server);//大小寫不敏感 +} + +//int main2() +//{ +// pid_t pid = GetPIDbyName_Wrapper("bash") ; // If -1 = not found, if -2 = proc fs access error +// printf("PID %d\n", pid); +// return EXIT_SUCCESS ; +//} +//====================================================== +/*void sigroutine(int dunno) +{ // 信號處理常式,其中dunno將會得到信號的值 + printf("sigroutine %d process id is %d SIGUSR1 (%d)\n", dunno, getpid(), SIGUSR1); + if (dunno == SIGUSR1)//收到SIGUSR1 + { + //========================= + printf("restart GYNET\n"); + + //========================= + } +}*/ + + +/*int main(int argc, char *argv[]) { + printf("parent process id is %d \n",getpid()); + printf("argc %d argv[0] %s\n", argc, argv[0]); + if (argc >= 2) + { + // ./GYNET stop 叫已執行的gynet重啓 + if (strcasecmp(argv[1], "stop") == 0) + { + //找 GYNET 是否已執行 + pid_t pid = GetPIDbyName_Wrapper(argv[0]) ; +// pid = 75255; + printf("pid %d\n", pid); + if (pid != -1 && pid != -2) + { + //對已執行的GYNET 發重啓signal + printf("kill pid %d SIGUSR1\n", pid); + kill(pid, SIGUSR1);//向child 1 子進程發送SIGUSR1中斷 + //目前的 第二個GYNET結束 + printf("exit(0)\n"); + exit(0); + } + } + } + + signal(SIGUSR1, sigroutine);//設置信號SIGUSR1的處理方法 + //========================= + while(1) + { + usSleep(1000); + } + //========================= + return 0; +}*/ diff --git a/src/signal_test.h b/src/signal_test.h new file mode 100644 index 0000000..f4c293f --- /dev/null +++ b/src/signal_test.h @@ -0,0 +1,19 @@ +#pragma once +#ifndef SIGNAL_H +#define SIGNAL_H +#include "define_inc.h" +#include <signal.h> +#include <unistd.h> +#include <stdio.h> +#include <unistd.h> +#include <dirent.h> +#include <sys/types.h> // for opendir(), readdir(), closedir() +#include <sys/stat.h> // for stat() +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> + +pid_t GetPIDbyName_Wrapper(char* cchrptr_ProcessName,int start_server); + +#endif \ No newline at end of file diff --git a/src/softmax_layer.c b/src/softmax_layer.c new file mode 100644 index 0000000..bf0bcc1 --- /dev/null +++ b/src/softmax_layer.c @@ -0,0 +1,108 @@ +#include "softmax_layer.h" +#include "utils.h" +#include "blas.h" +#include "cuda.h" + +#include <float.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> + +softmax_layer make_softmax_layer(int batch, int inputs, int groups) +{ + assert(inputs%groups == 0); + fprintf(stderr, "softmax %4d\n", inputs); + softmax_layer l = {0}; + l.type = SOFTMAX; + l.batch = batch; + l.groups = groups; + l.inputs = inputs; + l.outputs = inputs; + l.loss = calloc(inputs*batch, sizeof(float)); + l.output = calloc(inputs*batch, sizeof(float)); + l.delta = calloc(inputs*batch, sizeof(float)); + l.cost = calloc(1, sizeof(float)); + + l.forward = forward_softmax_layer; + l.backward = backward_softmax_layer; + #ifdef GPU + l.forward_gpu = forward_softmax_layer_gpu; + l.backward_gpu = backward_softmax_layer_gpu; + + l.output_gpu = cuda_make_array(l.output, inputs*batch); + l.loss_gpu = cuda_make_array(l.loss, inputs*batch); + l.delta_gpu = cuda_make_array(l.delta, inputs*batch); + #endif + return l; +} + +void forward_softmax_layer(const softmax_layer l, network net) +{ + if(l.softmax_tree){ + int i; + int count = 0; + for (i = 0; i < l.softmax_tree->groups; ++i) { + int group_size = l.softmax_tree->group_size[i]; + softmax_cpu(net.input + count, group_size, l.batch, l.inputs, 1, 0, 1, l.temperature, l.output + count); + count += group_size; + } + } else { + softmax_cpu(net.input, l.inputs/l.groups, l.batch, l.inputs, l.groups, l.inputs/l.groups, 1, l.temperature, l.output); + } + + if(net.truth && !l.noloss){ + softmax_x_ent_cpu(l.batch*l.inputs, l.output, net.truth, l.delta, l.loss); + l.cost[0] = sum_array(l.loss, l.batch*l.inputs); + } +} + +void backward_softmax_layer(const softmax_layer l, network net) +{ + axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1); +} + +#ifdef GPU + +void pull_softmax_layer_output(const softmax_layer layer) +{ + cuda_pull_array(layer.output_gpu, layer.output, layer.inputs*layer.batch); +} + +void forward_softmax_layer_gpu(const softmax_layer l, network net) +{ + if(l.softmax_tree){ + softmax_tree(net.input_gpu, 1, l.batch, l.inputs, l.temperature, l.output_gpu, *l.softmax_tree); + /* + int i; + int count = 0; + for (i = 0; i < l.softmax_tree->groups; ++i) { + int group_size = l.softmax_tree->group_size[i]; + softmax_gpu(net.input_gpu + count, group_size, l.batch, l.inputs, 1, 0, 1, l.temperature, l.output_gpu + count); + count += group_size; + } + */ + } else { + if(l.spatial){ + softmax_gpu(net.input_gpu, l.c, l.batch*l.c, l.inputs/l.c, l.w*l.h, 1, l.w*l.h, 1, l.output_gpu); + }else{ + softmax_gpu(net.input_gpu, l.inputs/l.groups, l.batch, l.inputs, l.groups, l.inputs/l.groups, 1, l.temperature, l.output_gpu); + } + } + if(net.truth && !l.noloss){ + softmax_x_ent_gpu(l.batch*l.inputs, l.output_gpu, net.truth_gpu, l.delta_gpu, l.loss_gpu); + if(l.softmax_tree){ + mask_gpu(l.batch*l.inputs, l.delta_gpu, SECRET_NUM, net.truth_gpu, 0); + mask_gpu(l.batch*l.inputs, l.loss_gpu, SECRET_NUM, net.truth_gpu, 0); + } + cuda_pull_array(l.loss_gpu, l.loss, l.batch*l.inputs); + l.cost[0] = sum_array(l.loss, l.batch*l.inputs); + } +} + +void backward_softmax_layer_gpu(const softmax_layer layer, network net) +{ + axpy_gpu(layer.batch*layer.inputs, 1, layer.delta_gpu, 1, net.delta_gpu, 1); +} + +#endif diff --git a/src/softmax_layer.h b/src/softmax_layer.h new file mode 100644 index 0000000..96ef2aa --- /dev/null +++ b/src/softmax_layer.h @@ -0,0 +1,22 @@ + +#pragma once +#ifndef SOFTMAX_LAYER_H +#define SOFTMAX_LAYER_H +#include "define_inc.h" +#include "layer.h" +#include "network.h" + +typedef layer softmax_layer; + +void softmax_array(float *input, int n, float temp, float *output); +softmax_layer make_softmax_layer(int batch, int inputs, int groups); +void forward_softmax_layer(const softmax_layer l, network net); +void backward_softmax_layer(const softmax_layer l, network net); + +#ifdef GPU +void pull_softmax_layer_output(const softmax_layer l); +void forward_softmax_layer_gpu(const softmax_layer l, network net); +void backward_softmax_layer_gpu(const softmax_layer l, network net); +#endif + +#endif diff --git a/src/sqlite3.h b/src/sqlite3.h new file mode 100644 index 0000000..c82d201 --- /dev/null +++ b/src/sqlite3.h @@ -0,0 +1,11755 @@ +/* +** 2001-09-15 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This header file defines the interface that the SQLite library +** presents to client programs. If a C-function, structure, datatype, +** or constant definition does not appear in this file, then it is +** not a published API of SQLite, is subject to change without +** notice, and should not be referenced by programs that use SQLite. +** +** Some of the definitions that are in this file are marked as +** "experimental". Experimental interfaces are normally new +** features recently added to SQLite. We do not anticipate changes +** to experimental interfaces but reserve the right to make minor changes +** if experience from use "in the wild" suggest such changes are prudent. +** +** The official C-language API documentation for SQLite is derived +** from comments in this file. This file is the authoritative source +** on how SQLite interfaces are supposed to operate. +** +** The name of this file under configuration management is "sqlite.h.in". +** The makefile makes some minor changes to this file (such as inserting +** the version number) and changes its name to "sqlite3.h" as +** part of the build process. +*/ +#pragma once +#ifndef SQLITE3_H +#define SQLITE3_H +#include "define_inc.h" +#include <stdarg.h> /* Needed for the definition of va_list */ + +/* +** Make sure we can call this stuff from C++. +*/ +#ifdef __cplusplus +extern "C" { +#endif + + +/* +** Provide the ability to override linkage features of the interface. +*/ +#ifndef SQLITE_EXTERN +# define SQLITE_EXTERN extern +#endif +#ifndef SQLITE_API +# define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_APICALL +# define SQLITE_APICALL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL SQLITE_APICALL +#endif +#ifndef SQLITE_CALLBACK +# define SQLITE_CALLBACK +#endif +#ifndef SQLITE_SYSAPI +# define SQLITE_SYSAPI +#endif + +/* +** These no-op macros are used in front of interfaces to mark those +** interfaces as either deprecated or experimental. New applications +** should not use deprecated interfaces - they are supported for backwards +** compatibility only. Application writers should be aware that +** experimental interfaces are subject to change in point releases. +** +** These macros used to resolve to various kinds of compiler magic that +** would generate warning messages when they were used. But that +** compiler magic ended up generating such a flurry of bug reports +** that we have taken it all out and gone back to using simple +** noop macros. +*/ +#define SQLITE_DEPRECATED +#define SQLITE_EXPERIMENTAL + +/* +** Ensure these symbols were not defined by some previous header file. +*/ +#ifdef SQLITE_VERSION +# undef SQLITE_VERSION +#endif +#ifdef SQLITE_VERSION_NUMBER +# undef SQLITE_VERSION_NUMBER +#endif + +/* +** CAPI3REF: Compile-Time Library Version Numbers +** +** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header +** evaluates to a string literal that is the SQLite version in the +** format "X.Y.Z" where X is the major version number (always 3 for +** SQLite3) and Y is the minor version number and Z is the release number.)^ +** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer +** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same +** numbers used in [SQLITE_VERSION].)^ +** The SQLITE_VERSION_NUMBER for any given release of SQLite will also +** be larger than the release from which it is derived. Either Y will +** be held constant and Z will be incremented or else Y will be incremented +** and Z will be reset to zero. +** +** Since [version 3.6.18] ([dateof:3.6.18]), +** SQLite source code has been stored in the +** <a href="http://www.fossil-scm.org/">Fossil configuration management +** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to +** a string which identifies a particular check-in of SQLite +** within its configuration management system. ^The SQLITE_SOURCE_ID +** string contains the date and time of the check-in (UTC) and a SHA1 +** or SHA3-256 hash of the entire source tree. If the source code has +** been edited in any way since it was last checked in, then the last +** four hexadecimal digits of the hash may be modified. +** +** See also: [sqlite3_libversion()], +** [sqlite3_libversion_number()], [sqlite3_sourceid()], +** [sqlite_version()] and [sqlite_source_id()]. +*/ +#define SQLITE_VERSION "3.28.0" +#define SQLITE_VERSION_NUMBER 3028000 +#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50" + +/* +** CAPI3REF: Run-Time Library Version Numbers +** KEYWORDS: sqlite3_version sqlite3_sourceid +** +** These interfaces provide the same information as the [SQLITE_VERSION], +** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros +** but are associated with the library instead of the header file. ^(Cautious +** programmers might include assert() statements in their application to +** verify that values returned by these interfaces match the macros in +** the header, and thus ensure that the application is +** compiled with matching library and header files. +** +** <blockquote><pre> +** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); +** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 ); +** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); +** </pre></blockquote>)^ +** +** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] +** macro. ^The sqlite3_libversion() function returns a pointer to the +** to the sqlite3_version[] string constant. The sqlite3_libversion() +** function is provided for use in DLLs since DLL users usually do not have +** direct access to string constants within the DLL. ^The +** sqlite3_libversion_number() function returns an integer equal to +** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns +** a pointer to a string constant whose value is the same as the +** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built +** using an edited copy of [the amalgamation], then the last four characters +** of the hash might be different from [SQLITE_SOURCE_ID].)^ +** +** See also: [sqlite_version()] and [sqlite_source_id()]. +*/ +SQLITE_API SQLITE_EXTERN const char sqlite3_version[]; +SQLITE_API const char *sqlite3_libversion(void); +SQLITE_API const char *sqlite3_sourceid(void); +SQLITE_API int sqlite3_libversion_number(void); + +/* +** CAPI3REF: Run-Time Library Compilation Options Diagnostics +** +** ^The sqlite3_compileoption_used() function returns 0 or 1 +** indicating whether the specified option was defined at +** compile time. ^The SQLITE_ prefix may be omitted from the +** option name passed to sqlite3_compileoption_used(). +** +** ^The sqlite3_compileoption_get() function allows iterating +** over the list of options that were defined at compile time by +** returning the N-th compile time option string. ^If N is out of range, +** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ +** prefix is omitted from any strings returned by +** sqlite3_compileoption_get(). +** +** ^Support for the diagnostic functions sqlite3_compileoption_used() +** and sqlite3_compileoption_get() may be omitted by specifying the +** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. +** +** See also: SQL functions [sqlite_compileoption_used()] and +** [sqlite_compileoption_get()] and the [compile_options pragma]. +*/ +#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS +SQLITE_API int sqlite3_compileoption_used(const char *zOptName); +SQLITE_API const char *sqlite3_compileoption_get(int N); +#else +# define sqlite3_compileoption_used(X) 0 +# define sqlite3_compileoption_get(X) ((void*)0) +#endif + +/* +** CAPI3REF: Test To See If The Library Is Threadsafe +** +** ^The sqlite3_threadsafe() function returns zero if and only if +** SQLite was compiled with mutexing code omitted due to the +** [SQLITE_THREADSAFE] compile-time option being set to 0. +** +** SQLite can be compiled with or without mutexes. When +** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes +** are enabled and SQLite is threadsafe. When the +** [SQLITE_THREADSAFE] macro is 0, +** the mutexes are omitted. Without the mutexes, it is not safe +** to use SQLite concurrently from more than one thread. +** +** Enabling mutexes incurs a measurable performance penalty. +** So if speed is of utmost importance, it makes sense to disable +** the mutexes. But for maximum safety, mutexes should be enabled. +** ^The default behavior is for mutexes to be enabled. +** +** This interface can be used by an application to make sure that the +** version of SQLite that it is linking against was compiled with +** the desired setting of the [SQLITE_THREADSAFE] macro. +** +** This interface only reports on the compile-time mutex setting +** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with +** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but +** can be fully or partially disabled using a call to [sqlite3_config()] +** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], +** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the +** sqlite3_threadsafe() function shows only the compile-time setting of +** thread safety, not any run-time changes to that setting made by +** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() +** is unchanged by calls to sqlite3_config().)^ +** +** See the [threading mode] documentation for additional information. +*/ +SQLITE_API int sqlite3_threadsafe(void); + +/* +** CAPI3REF: Database Connection Handle +** KEYWORDS: {database connection} {database connections} +** +** Each open SQLite database is represented by a pointer to an instance of +** the opaque structure named "sqlite3". It is useful to think of an sqlite3 +** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and +** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] +** and [sqlite3_close_v2()] are its destructors. There are many other +** interfaces (such as +** [sqlite3_prepare_v2()], [sqlite3_create_function()], and +** [sqlite3_busy_timeout()] to name but three) that are methods on an +** sqlite3 object. +*/ +typedef struct sqlite3 sqlite3; + +/* +** CAPI3REF: 64-Bit Integer Types +** KEYWORDS: sqlite_int64 sqlite_uint64 +** +** Because there is no cross-platform way to specify 64-bit integer types +** SQLite includes typedefs for 64-bit signed and unsigned integers. +** +** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. +** The sqlite_int64 and sqlite_uint64 types are supported for backwards +** compatibility only. +** +** ^The sqlite3_int64 and sqlite_int64 types can store integer values +** between -9223372036854775808 and +9223372036854775807 inclusive. ^The +** sqlite3_uint64 and sqlite_uint64 types can store integer values +** between 0 and +18446744073709551615 inclusive. +*/ +#ifdef SQLITE_INT64_TYPE + typedef SQLITE_INT64_TYPE sqlite_int64; +# ifdef SQLITE_UINT64_TYPE + typedef SQLITE_UINT64_TYPE sqlite_uint64; +# else + typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; +# endif +#elif defined(_MSC_VER) || defined(__BORLANDC__) + typedef __int64 sqlite_int64; + typedef unsigned __int64 sqlite_uint64; +#else + typedef long long int sqlite_int64; + typedef unsigned long long int sqlite_uint64; +#endif +typedef sqlite_int64 sqlite3_int64; +typedef sqlite_uint64 sqlite3_uint64; + +/* +** If compiling for a processor that lacks floating point support, +** substitute integer for floating-point. +*/ +#ifdef SQLITE_OMIT_FLOATING_POINT +# define double sqlite3_int64 +#endif + +/* +** CAPI3REF: Closing A Database Connection +** DESTRUCTOR: sqlite3 +** +** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors +** for the [sqlite3] object. +** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if +** the [sqlite3] object is successfully destroyed and all associated +** resources are deallocated. +** +** ^If the database connection is associated with unfinalized prepared +** statements or unfinished sqlite3_backup objects then sqlite3_close() +** will leave the database connection open and return [SQLITE_BUSY]. +** ^If sqlite3_close_v2() is called with unfinalized prepared statements +** and/or unfinished sqlite3_backups, then the database connection becomes +** an unusable "zombie" which will automatically be deallocated when the +** last prepared statement is finalized or the last sqlite3_backup is +** finished. The sqlite3_close_v2() interface is intended for use with +** host languages that are garbage collected, and where the order in which +** destructors are called is arbitrary. +** +** Applications should [sqlite3_finalize | finalize] all [prepared statements], +** [sqlite3_blob_close | close] all [BLOB handles], and +** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated +** with the [sqlite3] object prior to attempting to close the object. ^If +** sqlite3_close_v2() is called on a [database connection] that still has +** outstanding [prepared statements], [BLOB handles], and/or +** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation +** of resources is deferred until all [prepared statements], [BLOB handles], +** and [sqlite3_backup] objects are also destroyed. +** +** ^If an [sqlite3] object is destroyed while a transaction is open, +** the transaction is automatically rolled back. +** +** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] +** must be either a NULL +** pointer or an [sqlite3] object pointer obtained +** from [sqlite3_open()], [sqlite3_open16()], or +** [sqlite3_open_v2()], and not previously closed. +** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer +** argument is a harmless no-op. +*/ +SQLITE_API int sqlite3_close(sqlite3*); +SQLITE_API int sqlite3_close_v2(sqlite3*); + +/* +** The type for a callback function. +** This is legacy and deprecated. It is included for historical +** compatibility and is not documented. +*/ +typedef int (*sqlite3_callback)(void*,int,char**, char**); + +/* +** CAPI3REF: One-Step Query Execution Interface +** METHOD: sqlite3 +** +** The sqlite3_exec() interface is a convenience wrapper around +** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], +** that allows an application to run multiple statements of SQL +** without having to use a lot of C code. +** +** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, +** semicolon-separate SQL statements passed into its 2nd argument, +** in the context of the [database connection] passed in as its 1st +** argument. ^If the callback function of the 3rd argument to +** sqlite3_exec() is not NULL, then it is invoked for each result row +** coming out of the evaluated SQL statements. ^The 4th argument to +** sqlite3_exec() is relayed through to the 1st argument of each +** callback invocation. ^If the callback pointer to sqlite3_exec() +** is NULL, then no callback is ever invoked and result rows are +** ignored. +** +** ^If an error occurs while evaluating the SQL statements passed into +** sqlite3_exec(), then execution of the current statement stops and +** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() +** is not NULL then any error message is written into memory obtained +** from [sqlite3_malloc()] and passed back through the 5th parameter. +** To avoid memory leaks, the application should invoke [sqlite3_free()] +** on error message strings returned through the 5th parameter of +** sqlite3_exec() after the error message string is no longer needed. +** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors +** occur, then sqlite3_exec() sets the pointer in its 5th parameter to +** NULL before returning. +** +** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() +** routine returns SQLITE_ABORT without invoking the callback again and +** without running any subsequent SQL statements. +** +** ^The 2nd argument to the sqlite3_exec() callback function is the +** number of columns in the result. ^The 3rd argument to the sqlite3_exec() +** callback is an array of pointers to strings obtained as if from +** [sqlite3_column_text()], one for each column. ^If an element of a +** result row is NULL then the corresponding string pointer for the +** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the +** sqlite3_exec() callback is an array of pointers to strings where each +** entry represents the name of corresponding result column as obtained +** from [sqlite3_column_name()]. +** +** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer +** to an empty string, or a pointer that contains only whitespace and/or +** SQL comments, then no SQL statements are evaluated and the database +** is not changed. +** +** Restrictions: +** +** <ul> +** <li> The application must ensure that the 1st parameter to sqlite3_exec() +** is a valid and open [database connection]. +** <li> The application must not close the [database connection] specified by +** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. +** <li> The application must not modify the SQL statement text passed into +** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. +** </ul> +*/ +SQLITE_API int sqlite3_exec( + sqlite3*, /* An open database */ + const char *sql, /* SQL to be evaluated */ + int (*callback)(void*,int,char**,char**), /* Callback function */ + void *, /* 1st argument to callback */ + char **errmsg /* Error msg written here */ +); + +/* +** CAPI3REF: Result Codes +** KEYWORDS: {result code definitions} +** +** Many SQLite functions return an integer result code from the set shown +** here in order to indicate success or failure. +** +** New error codes may be added in future versions of SQLite. +** +** See also: [extended result code definitions] +*/ +#define SQLITE_OK 0 /* Successful result */ +/* beginning-of-error-codes */ +#define SQLITE_ERROR 1 /* Generic error */ +#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ +#define SQLITE_PERM 3 /* Access permission denied */ +#define SQLITE_ABORT 4 /* Callback routine requested an abort */ +#define SQLITE_BUSY 5 /* The database file is locked */ +#define SQLITE_LOCKED 6 /* A table in the database is locked */ +#define SQLITE_NOMEM 7 /* A malloc() failed */ +#define SQLITE_READONLY 8 /* Attempt to write a readonly database */ +#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ +#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ +#define SQLITE_CORRUPT 11 /* The database disk image is malformed */ +#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ +#define SQLITE_FULL 13 /* Insertion failed because database is full */ +#define SQLITE_CANTOPEN 14 /* Unable to open the database file */ +#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ +#define SQLITE_EMPTY 16 /* Internal use only */ +#define SQLITE_SCHEMA 17 /* The database schema changed */ +#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ +#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ +#define SQLITE_MISMATCH 20 /* Data type mismatch */ +#define SQLITE_MISUSE 21 /* Library used incorrectly */ +#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ +#define SQLITE_AUTH 23 /* Authorization denied */ +#define SQLITE_FORMAT 24 /* Not used */ +#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ +#define SQLITE_NOTADB 26 /* File opened that is not a database file */ +#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ +#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ +#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ +#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ +/* end-of-error-codes */ + +/* +** CAPI3REF: Extended Result Codes +** KEYWORDS: {extended result code definitions} +** +** In its default configuration, SQLite API routines return one of 30 integer +** [result codes]. However, experience has shown that many of +** these result codes are too coarse-grained. They do not provide as +** much information about problems as programmers might like. In an effort to +** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8] +** and later) include +** support for additional result codes that provide more detailed information +** about errors. These [extended result codes] are enabled or disabled +** on a per database connection basis using the +** [sqlite3_extended_result_codes()] API. Or, the extended code for +** the most recent error can be obtained using +** [sqlite3_extended_errcode()]. +*/ +#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) +#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) +#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8)) +#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) +#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) +#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) +#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) +#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) +#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) +#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) +#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) +#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) +#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) +#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) +#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) +#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) +#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) +#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) +#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) +#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) +#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) +#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) +#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) +#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) +#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) +#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) +#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) +#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) +#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) +#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) +#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) +#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) +#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) +#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) +#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) +#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) +#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) +#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) +#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) +#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) +#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) +#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) +#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ +#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) +#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) +#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) +#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) +#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) +#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) +#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) +#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) +#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) +#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) +#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) +#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) +#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) +#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) +#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) +#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) +#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) +#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) +#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) +#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) +#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) +#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) +#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) +#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) + +/* +** CAPI3REF: Flags For File Open Operations +** +** These bit values are intended for use in the +** 3rd parameter to the [sqlite3_open_v2()] interface and +** in the 4th parameter to the [sqlite3_vfs.xOpen] method. +*/ +#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ +#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ +#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ +#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ +#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ +#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ +#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ +#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ +#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ +#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ +#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ + +/* Reserved: 0x00F00000 */ + +/* +** CAPI3REF: Device Characteristics +** +** The xDeviceCharacteristics method of the [sqlite3_io_methods] +** object returns an integer which is a vector of these +** bit values expressing I/O characteristics of the mass storage +** device that holds the file that the [sqlite3_io_methods] +** refers to. +** +** The SQLITE_IOCAP_ATOMIC property means that all writes of +** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values +** mean that writes of blocks that are nnn bytes in size and +** are aligned to an address which is an integer multiple of +** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means +** that when data is appended to a file, the data is appended +** first then the size of the file is extended, never the other +** way around. The SQLITE_IOCAP_SEQUENTIAL property means that +** information is written to disk in the same order as calls +** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that +** after reboot following a crash or power loss, the only bytes in a +** file that were written at the application level might have changed +** and that adjacent bytes, even bytes within the same sector are +** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN +** flag indicates that a file cannot be deleted when open. The +** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on +** read-only media and cannot be changed even by processes with +** elevated privileges. +** +** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying +** filesystem supports doing multiple write operations atomically when those +** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and +** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. +*/ +#define SQLITE_IOCAP_ATOMIC 0x00000001 +#define SQLITE_IOCAP_ATOMIC512 0x00000002 +#define SQLITE_IOCAP_ATOMIC1K 0x00000004 +#define SQLITE_IOCAP_ATOMIC2K 0x00000008 +#define SQLITE_IOCAP_ATOMIC4K 0x00000010 +#define SQLITE_IOCAP_ATOMIC8K 0x00000020 +#define SQLITE_IOCAP_ATOMIC16K 0x00000040 +#define SQLITE_IOCAP_ATOMIC32K 0x00000080 +#define SQLITE_IOCAP_ATOMIC64K 0x00000100 +#define SQLITE_IOCAP_SAFE_APPEND 0x00000200 +#define SQLITE_IOCAP_SEQUENTIAL 0x00000400 +#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 +#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 +#define SQLITE_IOCAP_IMMUTABLE 0x00002000 +#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 + +/* +** CAPI3REF: File Locking Levels +** +** SQLite uses one of these integer values as the second +** argument to calls it makes to the xLock() and xUnlock() methods +** of an [sqlite3_io_methods] object. +*/ +#define SQLITE_LOCK_NONE 0 +#define SQLITE_LOCK_SHARED 1 +#define SQLITE_LOCK_RESERVED 2 +#define SQLITE_LOCK_PENDING 3 +#define SQLITE_LOCK_EXCLUSIVE 4 + +/* +** CAPI3REF: Synchronization Type Flags +** +** When SQLite invokes the xSync() method of an +** [sqlite3_io_methods] object it uses a combination of +** these integer values as the second argument. +** +** When the SQLITE_SYNC_DATAONLY flag is used, it means that the +** sync operation only needs to flush data to mass storage. Inode +** information need not be flushed. If the lower four bits of the flag +** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. +** If the lower four bits equal SQLITE_SYNC_FULL, that means +** to use Mac OS X style fullsync instead of fsync(). +** +** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags +** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL +** settings. The [synchronous pragma] determines when calls to the +** xSync VFS method occur and applies uniformly across all platforms. +** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how +** energetic or rigorous or forceful the sync operations are and +** only make a difference on Mac OSX for the default SQLite code. +** (Third-party VFS implementations might also make the distinction +** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the +** operating systems natively supported by SQLite, only Mac OSX +** cares about the difference.) +*/ +#define SQLITE_SYNC_NORMAL 0x00002 +#define SQLITE_SYNC_FULL 0x00003 +#define SQLITE_SYNC_DATAONLY 0x00010 + +/* +** CAPI3REF: OS Interface Open File Handle +** +** An [sqlite3_file] object represents an open file in the +** [sqlite3_vfs | OS interface layer]. Individual OS interface +** implementations will +** want to subclass this object by appending additional fields +** for their own use. The pMethods entry is a pointer to an +** [sqlite3_io_methods] object that defines methods for performing +** I/O operations on the open file. +*/ +typedef struct sqlite3_file sqlite3_file; +struct sqlite3_file { + const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ +}; + +/* +** CAPI3REF: OS Interface File Virtual Methods Object +** +** Every file opened by the [sqlite3_vfs.xOpen] method populates an +** [sqlite3_file] object (or, more commonly, a subclass of the +** [sqlite3_file] object) with a pointer to an instance of this object. +** This object defines the methods used to perform various operations +** against the open file represented by the [sqlite3_file] object. +** +** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element +** to a non-NULL pointer, then the sqlite3_io_methods.xClose method +** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The +** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] +** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element +** to NULL. +** +** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or +** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). +** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] +** flag may be ORed in to indicate that only the data of the file +** and not its inode needs to be synced. +** +** The integer values to xLock() and xUnlock() are one of +** <ul> +** <li> [SQLITE_LOCK_NONE], +** <li> [SQLITE_LOCK_SHARED], +** <li> [SQLITE_LOCK_RESERVED], +** <li> [SQLITE_LOCK_PENDING], or +** <li> [SQLITE_LOCK_EXCLUSIVE]. +** </ul> +** xLock() increases the lock. xUnlock() decreases the lock. +** The xCheckReservedLock() method checks whether any database connection, +** either in this process or in some other process, is holding a RESERVED, +** PENDING, or EXCLUSIVE lock on the file. It returns true +** if such a lock exists and false otherwise. +** +** The xFileControl() method is a generic interface that allows custom +** VFS implementations to directly control an open file using the +** [sqlite3_file_control()] interface. The second "op" argument is an +** integer opcode. The third argument is a generic pointer intended to +** point to a structure that may contain arguments or space in which to +** write return values. Potential uses for xFileControl() might be +** functions to enable blocking locks with timeouts, to change the +** locking strategy (for example to use dot-file locks), to inquire +** about the status of a lock, or to break stale locks. The SQLite +** core reserves all opcodes less than 100 for its own use. +** A [file control opcodes | list of opcodes] less than 100 is available. +** Applications that define a custom xFileControl method should use opcodes +** greater than 100 to avoid conflicts. VFS implementations should +** return [SQLITE_NOTFOUND] for file control opcodes that they do not +** recognize. +** +** The xSectorSize() method returns the sector size of the +** device that underlies the file. The sector size is the +** minimum write that can be performed without disturbing +** other bytes in the file. The xDeviceCharacteristics() +** method returns a bit vector describing behaviors of the +** underlying device: +** +** <ul> +** <li> [SQLITE_IOCAP_ATOMIC] +** <li> [SQLITE_IOCAP_ATOMIC512] +** <li> [SQLITE_IOCAP_ATOMIC1K] +** <li> [SQLITE_IOCAP_ATOMIC2K] +** <li> [SQLITE_IOCAP_ATOMIC4K] +** <li> [SQLITE_IOCAP_ATOMIC8K] +** <li> [SQLITE_IOCAP_ATOMIC16K] +** <li> [SQLITE_IOCAP_ATOMIC32K] +** <li> [SQLITE_IOCAP_ATOMIC64K] +** <li> [SQLITE_IOCAP_SAFE_APPEND] +** <li> [SQLITE_IOCAP_SEQUENTIAL] +** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] +** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] +** <li> [SQLITE_IOCAP_IMMUTABLE] +** <li> [SQLITE_IOCAP_BATCH_ATOMIC] +** </ul> +** +** The SQLITE_IOCAP_ATOMIC property means that all writes of +** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values +** mean that writes of blocks that are nnn bytes in size and +** are aligned to an address which is an integer multiple of +** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means +** that when data is appended to a file, the data is appended +** first then the size of the file is extended, never the other +** way around. The SQLITE_IOCAP_SEQUENTIAL property means that +** information is written to disk in the same order as calls +** to xWrite(). +** +** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill +** in the unread portions of the buffer with zeros. A VFS that +** fails to zero-fill short reads might seem to work. However, +** failure to zero-fill short reads will eventually lead to +** database corruption. +*/ +typedef struct sqlite3_io_methods sqlite3_io_methods; +struct sqlite3_io_methods { + int iVersion; + int (*xClose)(sqlite3_file*); + int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); + int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); + int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); + int (*xSync)(sqlite3_file*, int flags); + int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); + int (*xLock)(sqlite3_file*, int); + int (*xUnlock)(sqlite3_file*, int); + int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); + int (*xFileControl)(sqlite3_file*, int op, void *pArg); + int (*xSectorSize)(sqlite3_file*); + int (*xDeviceCharacteristics)(sqlite3_file*); + /* Methods above are valid for version 1 */ + int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); + int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); + void (*xShmBarrier)(sqlite3_file*); + int (*xShmUnmap)(sqlite3_file*, int deleteFlag); + /* Methods above are valid for version 2 */ + int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); + int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); + /* Methods above are valid for version 3 */ + /* Additional methods may be added in future releases */ +}; + +/* +** CAPI3REF: Standard File Control Opcodes +** KEYWORDS: {file control opcodes} {file control opcode} +** +** These integer constants are opcodes for the xFileControl method +** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] +** interface. +** +** <ul> +** <li>[[SQLITE_FCNTL_LOCKSTATE]] +** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This +** opcode causes the xFileControl method to write the current state of +** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], +** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) +** into an integer that the pArg argument points to. This capability +** is used during testing and is only available when the SQLITE_TEST +** compile-time option is used. +** +** <li>[[SQLITE_FCNTL_SIZE_HINT]] +** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS +** layer a hint of how large the database file will grow to be during the +** current transaction. This hint is not guaranteed to be accurate but it +** is often close. The underlying VFS might choose to preallocate database +** file space based on this hint in order to help writes to the database +** file run faster. +** +** <li>[[SQLITE_FCNTL_SIZE_LIMIT]] +** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that +** implements [sqlite3_deserialize()] to set an upper bound on the size +** of the in-memory database. The argument is a pointer to a [sqlite3_int64]. +** If the integer pointed to is negative, then it is filled in with the +** current limit. Otherwise the limit is set to the larger of the value +** of the integer pointed to and the current database size. The integer +** pointed to is set to the new limit. +** +** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] +** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS +** extends and truncates the database file in chunks of a size specified +** by the user. The fourth argument to [sqlite3_file_control()] should +** point to an integer (type int) containing the new chunk-size to use +** for the nominated database. Allocating database file space in large +** chunks (say 1MB at a time), may reduce file-system fragmentation and +** improve performance on some systems. +** +** <li>[[SQLITE_FCNTL_FILE_POINTER]] +** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer +** to the [sqlite3_file] object associated with a particular database +** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER]. +** +** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]] +** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer +** to the [sqlite3_file] object associated with the journal file (either +** the [rollback journal] or the [write-ahead log]) for a particular database +** connection. See also [SQLITE_FCNTL_FILE_POINTER]. +** +** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] +** No longer in use. +** +** <li>[[SQLITE_FCNTL_SYNC]] +** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and +** sent to the VFS immediately before the xSync method is invoked on a +** database file descriptor. Or, if the xSync method is not invoked +** because the user has configured SQLite with +** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place +** of the xSync method. In most cases, the pointer argument passed with +** this file-control is NULL. However, if the database file is being synced +** as part of a multi-database commit, the argument points to a nul-terminated +** string containing the transactions master-journal file name. VFSes that +** do not need this signal should silently ignore this opcode. Applications +** should not call [sqlite3_file_control()] with this opcode as doing so may +** disrupt the operation of the specialized VFSes that do require it. +** +** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] +** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite +** and sent to the VFS after a transaction has been committed immediately +** but before the database is unlocked. VFSes that do not need this signal +** should silently ignore this opcode. Applications should not call +** [sqlite3_file_control()] with this opcode as doing so may disrupt the +** operation of the specialized VFSes that do require it. +** +** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] +** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic +** retry counts and intervals for certain disk I/O operations for the +** windows [VFS] in order to provide robustness in the presence of +** anti-virus programs. By default, the windows VFS will retry file read, +** file write, and file delete operations up to 10 times, with a delay +** of 25 milliseconds before the first retry and with the delay increasing +** by an additional 25 milliseconds with each subsequent retry. This +** opcode allows these two values (10 retries and 25 milliseconds of delay) +** to be adjusted. The values are changed for all database connections +** within the same process. The argument is a pointer to an array of two +** integers where the first integer is the new retry count and the second +** integer is the delay. If either integer is negative, then the setting +** is not changed but instead the prior value of that setting is written +** into the array entry, allowing the current retry settings to be +** interrogated. The zDbName parameter is ignored. +** +** <li>[[SQLITE_FCNTL_PERSIST_WAL]] +** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the +** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary +** write ahead log ([WAL file]) and shared memory +** files used for transaction control +** are automatically deleted when the latest connection to the database +** closes. Setting persistent WAL mode causes those files to persist after +** close. Persisting the files is useful when other processes that do not +** have write permission on the directory containing the database file want +** to read the database file, as the WAL and shared memory files must exist +** in order for the database to be readable. The fourth parameter to +** [sqlite3_file_control()] for this opcode should be a pointer to an integer. +** That integer is 0 to disable persistent WAL mode or 1 to enable persistent +** WAL mode. If the integer is -1, then it is overwritten with the current +** WAL persistence setting. +** +** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] +** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the +** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting +** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the +** xDeviceCharacteristics methods. The fourth parameter to +** [sqlite3_file_control()] for this opcode should be a pointer to an integer. +** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage +** mode. If the integer is -1, then it is overwritten with the current +** zero-damage mode setting. +** +** <li>[[SQLITE_FCNTL_OVERWRITE]] +** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening +** a write transaction to indicate that, unless it is rolled back for some +** reason, the entire database file will be overwritten by the current +** transaction. This is used by VACUUM operations. +** +** <li>[[SQLITE_FCNTL_VFSNAME]] +** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of +** all [VFSes] in the VFS stack. The names are of all VFS shims and the +** final bottom-level VFS are written into memory obtained from +** [sqlite3_malloc()] and the result is stored in the char* variable +** that the fourth parameter of [sqlite3_file_control()] points to. +** The caller is responsible for freeing the memory when done. As with +** all file-control actions, there is no guarantee that this will actually +** do anything. Callers should initialize the char* variable to a NULL +** pointer in case this file-control is not implemented. This file-control +** is intended for diagnostic use only. +** +** <li>[[SQLITE_FCNTL_VFS_POINTER]] +** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level +** [VFSes] currently in use. ^(The argument X in +** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be +** of type "[sqlite3_vfs] **". This opcodes will set *X +** to a pointer to the top-level VFS.)^ +** ^When there are multiple VFS shims in the stack, this opcode finds the +** upper-most shim only. +** +** <li>[[SQLITE_FCNTL_PRAGMA]] +** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] +** file control is sent to the open [sqlite3_file] object corresponding +** to the database file to which the pragma statement refers. ^The argument +** to the [SQLITE_FCNTL_PRAGMA] file control is an array of +** pointers to strings (char**) in which the second element of the array +** is the name of the pragma and the third element is the argument to the +** pragma or NULL if the pragma has no argument. ^The handler for an +** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element +** of the char** argument point to a string obtained from [sqlite3_mprintf()] +** or the equivalent and that string will become the result of the pragma or +** the error message if the pragma fails. ^If the +** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal +** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] +** file control returns [SQLITE_OK], then the parser assumes that the +** VFS has handled the PRAGMA itself and the parser generates a no-op +** prepared statement if result string is NULL, or that returns a copy +** of the result string if the string is non-NULL. +** ^If the [SQLITE_FCNTL_PRAGMA] file control returns +** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means +** that the VFS encountered an error while handling the [PRAGMA] and the +** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] +** file control occurs at the beginning of pragma statement analysis and so +** it is able to override built-in [PRAGMA] statements. +** +** <li>[[SQLITE_FCNTL_BUSYHANDLER]] +** ^The [SQLITE_FCNTL_BUSYHANDLER] +** file-control may be invoked by SQLite on the database file handle +** shortly after it is opened in order to provide a custom VFS with access +** to the connections busy-handler callback. The argument is of type (void **) +** - an array of two (void *) values. The first (void *) actually points +** to a function of type (int (*)(void *)). In order to invoke the connections +** busy-handler, this function should be invoked with the second (void *) in +** the array as the only argument. If it returns non-zero, then the operation +** should be retried. If it returns zero, the custom VFS should abandon the +** current operation. +** +** <li>[[SQLITE_FCNTL_TEMPFILENAME]] +** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control +** to have SQLite generate a +** temporary filename using the same algorithm that is followed to generate +** temporary filenames for TEMP tables and other internal uses. The +** argument should be a char** which will be filled with the filename +** written into memory obtained from [sqlite3_malloc()]. The caller should +** invoke [sqlite3_free()] on the result to avoid a memory leak. +** +** <li>[[SQLITE_FCNTL_MMAP_SIZE]] +** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the +** maximum number of bytes that will be used for memory-mapped I/O. +** The argument is a pointer to a value of type sqlite3_int64 that +** is an advisory maximum number of bytes in the file to memory map. The +** pointer is overwritten with the old value. The limit is not changed if +** the value originally pointed to is negative, and so the current limit +** can be queried by passing in a pointer to a negative number. This +** file-control is used internally to implement [PRAGMA mmap_size]. +** +** <li>[[SQLITE_FCNTL_TRACE]] +** The [SQLITE_FCNTL_TRACE] file control provides advisory information +** to the VFS about what the higher layers of the SQLite stack are doing. +** This file control is used by some VFS activity tracing [shims]. +** The argument is a zero-terminated string. Higher layers in the +** SQLite stack may generate instances of this file control if +** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. +** +** <li>[[SQLITE_FCNTL_HAS_MOVED]] +** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a +** pointer to an integer and it writes a boolean into that integer depending +** on whether or not the file has been renamed, moved, or deleted since it +** was first opened. +** +** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]] +** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the +** underlying native file handle associated with a file handle. This file +** control interprets its argument as a pointer to a native file handle and +** writes the resulting value there. +** +** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]] +** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This +** opcode causes the xFileControl method to swap the file handle with the one +** pointed to by the pArg argument. This capability is used during testing +** and only needs to be supported when SQLITE_TEST is defined. +** +** <li>[[SQLITE_FCNTL_WAL_BLOCK]] +** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might +** be advantageous to block on the next WAL lock if the lock is not immediately +** available. The WAL subsystem issues this signal during rare +** circumstances in order to fix a problem with priority inversion. +** Applications should <em>not</em> use this file-control. +** +** <li>[[SQLITE_FCNTL_ZIPVFS]] +** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other +** VFS should return SQLITE_NOTFOUND for this opcode. +** +** <li>[[SQLITE_FCNTL_RBU]] +** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by +** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for +** this opcode. +** +** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]] +** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then +** the file descriptor is placed in "batch write mode", which +** means all subsequent write operations will be deferred and done +** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems +** that do not support batch atomic writes will return SQLITE_NOTFOUND. +** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to +** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or +** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make +** no VFS interface calls on the same [sqlite3_file] file descriptor +** except for calls to the xWrite method and the xFileControl method +** with [SQLITE_FCNTL_SIZE_HINT]. +** +** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]] +** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write +** operations since the previous successful call to +** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically. +** This file control returns [SQLITE_OK] if and only if the writes were +** all performed successfully and have been committed to persistent storage. +** ^Regardless of whether or not it is successful, this file control takes +** the file descriptor out of batch write mode so that all subsequent +** write operations are independent. +** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without +** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. +** +** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]] +** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write +** operations since the previous successful call to +** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back. +** ^This file control takes the file descriptor out of batch write mode +** so that all subsequent write operations are independent. +** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without +** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. +** +** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]] +** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain +** a file lock using the xLock or xShmLock methods of the VFS to wait +** for up to M milliseconds before failing, where M is the single +** unsigned integer parameter. +** +** <li>[[SQLITE_FCNTL_DATA_VERSION]] +** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to +** a database file. The argument is a pointer to a 32-bit unsigned integer. +** The "data version" for the pager is written into the pointer. The +** "data version" changes whenever any change occurs to the corresponding +** database file, either through SQL statements on the same database +** connection or through transactions committed by separate database +** connections possibly in other processes. The [sqlite3_total_changes()] +** interface can be used to find if any database on the connection has changed, +** but that interface responds to changes on TEMP as well as MAIN and does +** not provide a mechanism to detect changes to MAIN only. Also, the +** [sqlite3_total_changes()] interface responds to internal changes only and +** omits changes made by other database connections. The +** [PRAGMA data_version] command provide a mechanism to detect changes to +** a single attached database that occur due to other database connections, +** but omits changes implemented by the database connection on which it is +** called. This file control is the only mechanism to detect changes that +** happen either internally or externally and that are associated with +** a particular attached database. +** </ul> +*/ +#define SQLITE_FCNTL_LOCKSTATE 1 +#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 +#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 +#define SQLITE_FCNTL_LAST_ERRNO 4 +#define SQLITE_FCNTL_SIZE_HINT 5 +#define SQLITE_FCNTL_CHUNK_SIZE 6 +#define SQLITE_FCNTL_FILE_POINTER 7 +#define SQLITE_FCNTL_SYNC_OMITTED 8 +#define SQLITE_FCNTL_WIN32_AV_RETRY 9 +#define SQLITE_FCNTL_PERSIST_WAL 10 +#define SQLITE_FCNTL_OVERWRITE 11 +#define SQLITE_FCNTL_VFSNAME 12 +#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 +#define SQLITE_FCNTL_PRAGMA 14 +#define SQLITE_FCNTL_BUSYHANDLER 15 +#define SQLITE_FCNTL_TEMPFILENAME 16 +#define SQLITE_FCNTL_MMAP_SIZE 18 +#define SQLITE_FCNTL_TRACE 19 +#define SQLITE_FCNTL_HAS_MOVED 20 +#define SQLITE_FCNTL_SYNC 21 +#define SQLITE_FCNTL_COMMIT_PHASETWO 22 +#define SQLITE_FCNTL_WIN32_SET_HANDLE 23 +#define SQLITE_FCNTL_WAL_BLOCK 24 +#define SQLITE_FCNTL_ZIPVFS 25 +#define SQLITE_FCNTL_RBU 26 +#define SQLITE_FCNTL_VFS_POINTER 27 +#define SQLITE_FCNTL_JOURNAL_POINTER 28 +#define SQLITE_FCNTL_WIN32_GET_HANDLE 29 +#define SQLITE_FCNTL_PDB 30 +#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 +#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 +#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 +#define SQLITE_FCNTL_LOCK_TIMEOUT 34 +#define SQLITE_FCNTL_DATA_VERSION 35 +#define SQLITE_FCNTL_SIZE_LIMIT 36 + +/* deprecated names */ +#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE +#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE +#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO + + +/* +** CAPI3REF: Mutex Handle +** +** The mutex module within SQLite defines [sqlite3_mutex] to be an +** abstract type for a mutex object. The SQLite core never looks +** at the internal representation of an [sqlite3_mutex]. It only +** deals with pointers to the [sqlite3_mutex] object. +** +** Mutexes are created using [sqlite3_mutex_alloc()]. +*/ +typedef struct sqlite3_mutex sqlite3_mutex; + +/* +** CAPI3REF: Loadable Extension Thunk +** +** A pointer to the opaque sqlite3_api_routines structure is passed as +** the third parameter to entry points of [loadable extensions]. This +** structure must be typedefed in order to work around compiler warnings +** on some platforms. +*/ +typedef struct sqlite3_api_routines sqlite3_api_routines; + +/* +** CAPI3REF: OS Interface Object +** +** An instance of the sqlite3_vfs object defines the interface between +** the SQLite core and the underlying operating system. The "vfs" +** in the name of the object stands for "virtual file system". See +** the [VFS | VFS documentation] for further information. +** +** The VFS interface is sometimes extended by adding new methods onto +** the end. Each time such an extension occurs, the iVersion field +** is incremented. The iVersion value started out as 1 in +** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2 +** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased +** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields +** may be appended to the sqlite3_vfs object and the iVersion value +** may increase again in future versions of SQLite. +** Note that the structure +** of the sqlite3_vfs object changes in the transition from +** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0] +** and yet the iVersion field was not modified. +** +** The szOsFile field is the size of the subclassed [sqlite3_file] +** structure used by this VFS. mxPathname is the maximum length of +** a pathname in this VFS. +** +** Registered sqlite3_vfs objects are kept on a linked list formed by +** the pNext pointer. The [sqlite3_vfs_register()] +** and [sqlite3_vfs_unregister()] interfaces manage this list +** in a thread-safe way. The [sqlite3_vfs_find()] interface +** searches the list. Neither the application code nor the VFS +** implementation should use the pNext pointer. +** +** The pNext field is the only field in the sqlite3_vfs +** structure that SQLite will ever modify. SQLite will only access +** or modify this field while holding a particular static mutex. +** The application should never modify anything within the sqlite3_vfs +** object once the object has been registered. +** +** The zName field holds the name of the VFS module. The name must +** be unique across all VFS modules. +** +** [[sqlite3_vfs.xOpen]] +** ^SQLite guarantees that the zFilename parameter to xOpen +** is either a NULL pointer or string obtained +** from xFullPathname() with an optional suffix added. +** ^If a suffix is added to the zFilename parameter, it will +** consist of a single "-" character followed by no more than +** 11 alphanumeric and/or "-" characters. +** ^SQLite further guarantees that +** the string will be valid and unchanged until xClose() is +** called. Because of the previous sentence, +** the [sqlite3_file] can safely store a pointer to the +** filename if it needs to remember the filename for some reason. +** If the zFilename parameter to xOpen is a NULL pointer then xOpen +** must invent its own temporary name for the file. ^Whenever the +** xFilename parameter is NULL it will also be the case that the +** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. +** +** The flags argument to xOpen() includes all bits set in +** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] +** or [sqlite3_open16()] is used, then flags includes at least +** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. +** If xOpen() opens a file read-only then it sets *pOutFlags to +** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. +** +** ^(SQLite will also add one of the following flags to the xOpen() +** call, depending on the object being opened: +** +** <ul> +** <li> [SQLITE_OPEN_MAIN_DB] +** <li> [SQLITE_OPEN_MAIN_JOURNAL] +** <li> [SQLITE_OPEN_TEMP_DB] +** <li> [SQLITE_OPEN_TEMP_JOURNAL] +** <li> [SQLITE_OPEN_TRANSIENT_DB] +** <li> [SQLITE_OPEN_SUBJOURNAL] +** <li> [SQLITE_OPEN_MASTER_JOURNAL] +** <li> [SQLITE_OPEN_WAL] +** </ul>)^ +** +** The file I/O implementation can use the object type flags to +** change the way it deals with files. For example, an application +** that does not care about crash recovery or rollback might make +** the open of a journal file a no-op. Writes to this journal would +** also be no-ops, and any attempt to read the journal would return +** SQLITE_IOERR. Or the implementation might recognize that a database +** file will be doing page-aligned sector reads and writes in a random +** order and set up its I/O subsystem accordingly. +** +** SQLite might also add one of the following flags to the xOpen method: +** +** <ul> +** <li> [SQLITE_OPEN_DELETEONCLOSE] +** <li> [SQLITE_OPEN_EXCLUSIVE] +** </ul> +** +** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be +** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] +** will be set for TEMP databases and their journals, transient +** databases, and subjournals. +** +** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction +** with the [SQLITE_OPEN_CREATE] flag, which are both directly +** analogous to the O_EXCL and O_CREAT flags of the POSIX open() +** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the +** SQLITE_OPEN_CREATE, is used to indicate that file should always +** be created, and that it is an error if it already exists. +** It is <i>not</i> used to indicate the file should be opened +** for exclusive access. +** +** ^At least szOsFile bytes of memory are allocated by SQLite +** to hold the [sqlite3_file] structure passed as the third +** argument to xOpen. The xOpen method does not have to +** allocate the structure; it should just fill it in. Note that +** the xOpen method must set the sqlite3_file.pMethods to either +** a valid [sqlite3_io_methods] object or to NULL. xOpen must do +** this even if the open fails. SQLite expects that the sqlite3_file.pMethods +** element will be valid after xOpen returns regardless of the success +** or failure of the xOpen call. +** +** [[sqlite3_vfs.xAccess]] +** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] +** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to +** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] +** to test whether a file is at least readable. The file can be a +** directory. +** +** ^SQLite will always allocate at least mxPathname+1 bytes for the +** output buffer xFullPathname. The exact size of the output buffer +** is also passed as a parameter to both methods. If the output buffer +** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is +** handled as a fatal error by SQLite, vfs implementations should endeavor +** to prevent this by setting mxPathname to a sufficiently large value. +** +** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() +** interfaces are not strictly a part of the filesystem, but they are +** included in the VFS structure for completeness. +** The xRandomness() function attempts to return nBytes bytes +** of good-quality randomness into zOut. The return value is +** the actual number of bytes of randomness obtained. +** The xSleep() method causes the calling thread to sleep for at +** least the number of microseconds given. ^The xCurrentTime() +** method returns a Julian Day Number for the current date and time as +** a floating point value. +** ^The xCurrentTimeInt64() method returns, as an integer, the Julian +** Day Number multiplied by 86400000 (the number of milliseconds in +** a 24-hour day). +** ^SQLite will use the xCurrentTimeInt64() method to get the current +** date and time if that method is available (if iVersion is 2 or +** greater and the function pointer is not NULL) and will fall back +** to xCurrentTime() if xCurrentTimeInt64() is unavailable. +** +** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces +** are not used by the SQLite core. These optional interfaces are provided +** by some VFSes to facilitate testing of the VFS code. By overriding +** system calls with functions under its control, a test program can +** simulate faults and error conditions that would otherwise be difficult +** or impossible to induce. The set of system calls that can be overridden +** varies from one VFS to another, and from one version of the same VFS to the +** next. Applications that use these interfaces must be prepared for any +** or all of these interfaces to be NULL or for their behavior to change +** from one release to the next. Applications must not attempt to access +** any of these methods if the iVersion of the VFS is less than 3. +*/ +typedef struct sqlite3_vfs sqlite3_vfs; +typedef void (*sqlite3_syscall_ptr)(void); +struct sqlite3_vfs { + int iVersion; /* Structure version number (currently 3) */ + int szOsFile; /* Size of subclassed sqlite3_file */ + int mxPathname; /* Maximum file pathname length */ + sqlite3_vfs *pNext; /* Next registered VFS */ + const char *zName; /* Name of this virtual file system */ + void *pAppData; /* Pointer to application-specific data */ + int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, + int flags, int *pOutFlags); + int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); + int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); + int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); + void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); + void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); + void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); + void (*xDlClose)(sqlite3_vfs*, void*); + int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); + int (*xSleep)(sqlite3_vfs*, int microseconds); + int (*xCurrentTime)(sqlite3_vfs*, double*); + int (*xGetLastError)(sqlite3_vfs*, int, char *); + /* + ** The methods above are in version 1 of the sqlite_vfs object + ** definition. Those that follow are added in version 2 or later + */ + int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); + /* + ** The methods above are in versions 1 and 2 of the sqlite_vfs object. + ** Those below are for version 3 and greater. + */ + int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); + sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); + const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); + /* + ** The methods above are in versions 1 through 3 of the sqlite_vfs object. + ** New fields may be appended in future versions. The iVersion + ** value will increment whenever this happens. + */ +}; + +/* +** CAPI3REF: Flags for the xAccess VFS method +** +** These integer constants can be used as the third parameter to +** the xAccess method of an [sqlite3_vfs] object. They determine +** what kind of permissions the xAccess method is looking for. +** With SQLITE_ACCESS_EXISTS, the xAccess method +** simply checks whether the file exists. +** With SQLITE_ACCESS_READWRITE, the xAccess method +** checks whether the named directory is both readable and writable +** (in other words, if files can be added, removed, and renamed within +** the directory). +** The SQLITE_ACCESS_READWRITE constant is currently used only by the +** [temp_store_directory pragma], though this could change in a future +** release of SQLite. +** With SQLITE_ACCESS_READ, the xAccess method +** checks whether the file is readable. The SQLITE_ACCESS_READ constant is +** currently unused, though it might be used in a future release of +** SQLite. +*/ +#define SQLITE_ACCESS_EXISTS 0 +#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ +#define SQLITE_ACCESS_READ 2 /* Unused */ + +/* +** CAPI3REF: Flags for the xShmLock VFS method +** +** These integer constants define the various locking operations +** allowed by the xShmLock method of [sqlite3_io_methods]. The +** following are the only legal combinations of flags to the +** xShmLock method: +** +** <ul> +** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED +** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE +** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED +** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE +** </ul> +** +** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as +** was given on the corresponding lock. +** +** The xShmLock method can transition between unlocked and SHARED or +** between unlocked and EXCLUSIVE. It cannot transition between SHARED +** and EXCLUSIVE. +*/ +#define SQLITE_SHM_UNLOCK 1 +#define SQLITE_SHM_LOCK 2 +#define SQLITE_SHM_SHARED 4 +#define SQLITE_SHM_EXCLUSIVE 8 + +/* +** CAPI3REF: Maximum xShmLock index +** +** The xShmLock method on [sqlite3_io_methods] may use values +** between 0 and this upper bound as its "offset" argument. +** The SQLite core will never attempt to acquire or release a +** lock outside of this range +*/ +#define SQLITE_SHM_NLOCK 8 + + +/* +** CAPI3REF: Initialize The SQLite Library +** +** ^The sqlite3_initialize() routine initializes the +** SQLite library. ^The sqlite3_shutdown() routine +** deallocates any resources that were allocated by sqlite3_initialize(). +** These routines are designed to aid in process initialization and +** shutdown on embedded systems. Workstation applications using +** SQLite normally do not need to invoke either of these routines. +** +** A call to sqlite3_initialize() is an "effective" call if it is +** the first time sqlite3_initialize() is invoked during the lifetime of +** the process, or if it is the first time sqlite3_initialize() is invoked +** following a call to sqlite3_shutdown(). ^(Only an effective call +** of sqlite3_initialize() does any initialization. All other calls +** are harmless no-ops.)^ +** +** A call to sqlite3_shutdown() is an "effective" call if it is the first +** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only +** an effective call to sqlite3_shutdown() does any deinitialization. +** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ +** +** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() +** is not. The sqlite3_shutdown() interface must only be called from a +** single thread. All open [database connections] must be closed and all +** other SQLite resources must be deallocated prior to invoking +** sqlite3_shutdown(). +** +** Among other things, ^sqlite3_initialize() will invoke +** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() +** will invoke sqlite3_os_end(). +** +** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. +** ^If for some reason, sqlite3_initialize() is unable to initialize +** the library (perhaps it is unable to allocate a needed resource such +** as a mutex) it returns an [error code] other than [SQLITE_OK]. +** +** ^The sqlite3_initialize() routine is called internally by many other +** SQLite interfaces so that an application usually does not need to +** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] +** calls sqlite3_initialize() so the SQLite library will be automatically +** initialized when [sqlite3_open()] is called if it has not be initialized +** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] +** compile-time option, then the automatic calls to sqlite3_initialize() +** are omitted and the application must call sqlite3_initialize() directly +** prior to using any other SQLite interface. For maximum portability, +** it is recommended that applications always invoke sqlite3_initialize() +** directly prior to using any other SQLite interface. Future releases +** of SQLite may require this. In other words, the behavior exhibited +** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the +** default behavior in some future release of SQLite. +** +** The sqlite3_os_init() routine does operating-system specific +** initialization of the SQLite library. The sqlite3_os_end() +** routine undoes the effect of sqlite3_os_init(). Typical tasks +** performed by these routines include allocation or deallocation +** of static resources, initialization of global variables, +** setting up a default [sqlite3_vfs] module, or setting up +** a default configuration using [sqlite3_config()]. +** +** The application should never invoke either sqlite3_os_init() +** or sqlite3_os_end() directly. The application should only invoke +** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() +** interface is called automatically by sqlite3_initialize() and +** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate +** implementations for sqlite3_os_init() and sqlite3_os_end() +** are built into SQLite when it is compiled for Unix, Windows, or OS/2. +** When [custom builds | built for other platforms] +** (using the [SQLITE_OS_OTHER=1] compile-time +** option) the application must supply a suitable implementation for +** sqlite3_os_init() and sqlite3_os_end(). An application-supplied +** implementation of sqlite3_os_init() or sqlite3_os_end() +** must return [SQLITE_OK] on success and some other [error code] upon +** failure. +*/ +SQLITE_API int sqlite3_initialize(void); +SQLITE_API int sqlite3_shutdown(void); +SQLITE_API int sqlite3_os_init(void); +SQLITE_API int sqlite3_os_end(void); + +/* +** CAPI3REF: Configuring The SQLite Library +** +** The sqlite3_config() interface is used to make global configuration +** changes to SQLite in order to tune SQLite to the specific needs of +** the application. The default configuration is recommended for most +** applications and so this routine is usually not necessary. It is +** provided to support rare applications with unusual needs. +** +** <b>The sqlite3_config() interface is not threadsafe. The application +** must ensure that no other SQLite interfaces are invoked by other +** threads while sqlite3_config() is running.</b> +** +** The sqlite3_config() interface +** may only be invoked prior to library initialization using +** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. +** ^If sqlite3_config() is called after [sqlite3_initialize()] and before +** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. +** Note, however, that ^sqlite3_config() can be called as part of the +** implementation of an application-defined [sqlite3_os_init()]. +** +** The first argument to sqlite3_config() is an integer +** [configuration option] that determines +** what property of SQLite is to be configured. Subsequent arguments +** vary depending on the [configuration option] +** in the first argument. +** +** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. +** ^If the option is unknown or SQLite is unable to set the option +** then this routine returns a non-zero [error code]. +*/ +SQLITE_API int sqlite3_config(int, ...); + +/* +** CAPI3REF: Configure database connections +** METHOD: sqlite3 +** +** The sqlite3_db_config() interface is used to make configuration +** changes to a [database connection]. The interface is similar to +** [sqlite3_config()] except that the changes apply to a single +** [database connection] (specified in the first argument). +** +** The second argument to sqlite3_db_config(D,V,...) is the +** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code +** that indicates what aspect of the [database connection] is being configured. +** Subsequent arguments vary depending on the configuration verb. +** +** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if +** the call is considered successful. +*/ +SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); + +/* +** CAPI3REF: Memory Allocation Routines +** +** An instance of this object defines the interface between SQLite +** and low-level memory allocation routines. +** +** This object is used in only one place in the SQLite interface. +** A pointer to an instance of this object is the argument to +** [sqlite3_config()] when the configuration option is +** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. +** By creating an instance of this object +** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) +** during configuration, an application can specify an alternative +** memory allocation subsystem for SQLite to use for all of its +** dynamic memory needs. +** +** Note that SQLite comes with several [built-in memory allocators] +** that are perfectly adequate for the overwhelming majority of applications +** and that this object is only useful to a tiny minority of applications +** with specialized memory allocation requirements. This object is +** also used during testing of SQLite in order to specify an alternative +** memory allocator that simulates memory out-of-memory conditions in +** order to verify that SQLite recovers gracefully from such +** conditions. +** +** The xMalloc, xRealloc, and xFree methods must work like the +** malloc(), realloc() and free() functions from the standard C library. +** ^SQLite guarantees that the second argument to +** xRealloc is always a value returned by a prior call to xRoundup. +** +** xSize should return the allocated size of a memory allocation +** previously obtained from xMalloc or xRealloc. The allocated size +** is always at least as big as the requested size but may be larger. +** +** The xRoundup method returns what would be the allocated size of +** a memory allocation given a particular requested size. Most memory +** allocators round up memory allocations at least to the next multiple +** of 8. Some allocators round up to a larger multiple or to a power of 2. +** Every memory allocation request coming in through [sqlite3_malloc()] +** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, +** that causes the corresponding memory allocation to fail. +** +** The xInit method initializes the memory allocator. For example, +** it might allocate any require mutexes or initialize internal data +** structures. The xShutdown method is invoked (indirectly) by +** [sqlite3_shutdown()] and should deallocate any resources acquired +** by xInit. The pAppData pointer is used as the only parameter to +** xInit and xShutdown. +** +** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes +** the xInit method, so the xInit method need not be threadsafe. The +** xShutdown method is only called from [sqlite3_shutdown()] so it does +** not need to be threadsafe either. For all other methods, SQLite +** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the +** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which +** it is by default) and so the methods are automatically serialized. +** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other +** methods must be threadsafe or else make their own arrangements for +** serialization. +** +** SQLite will never invoke xInit() more than once without an intervening +** call to xShutdown(). +*/ +typedef struct sqlite3_mem_methods sqlite3_mem_methods; +struct sqlite3_mem_methods { + void *(*xMalloc)(int); /* Memory allocation function */ + void (*xFree)(void*); /* Free a prior allocation */ + void *(*xRealloc)(void*,int); /* Resize an allocation */ + int (*xSize)(void*); /* Return the size of an allocation */ + int (*xRoundup)(int); /* Round up request size to allocation size */ + int (*xInit)(void*); /* Initialize the memory allocator */ + void (*xShutdown)(void*); /* Deinitialize the memory allocator */ + void *pAppData; /* Argument to xInit() and xShutdown() */ +}; + +/* +** CAPI3REF: Configuration Options +** KEYWORDS: {configuration option} +** +** These constants are the available integer configuration options that +** can be passed as the first argument to the [sqlite3_config()] interface. +** +** New configuration options may be added in future releases of SQLite. +** Existing configuration options might be discontinued. Applications +** should check the return code from [sqlite3_config()] to make sure that +** the call worked. The [sqlite3_config()] interface will return a +** non-zero [error code] if a discontinued or unsupported configuration option +** is invoked. +** +** <dl> +** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> +** <dd>There are no arguments to this option. ^This option sets the +** [threading mode] to Single-thread. In other words, it disables +** all mutexing and puts SQLite into a mode where it can only be used +** by a single thread. ^If SQLite is compiled with +** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then +** it is not possible to change the [threading mode] from its default +** value of Single-thread and so [sqlite3_config()] will return +** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD +** configuration option.</dd> +** +** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> +** <dd>There are no arguments to this option. ^This option sets the +** [threading mode] to Multi-thread. In other words, it disables +** mutexing on [database connection] and [prepared statement] objects. +** The application is responsible for serializing access to +** [database connections] and [prepared statements]. But other mutexes +** are enabled so that SQLite will be safe to use in a multi-threaded +** environment as long as no two threads attempt to use the same +** [database connection] at the same time. ^If SQLite is compiled with +** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then +** it is not possible to set the Multi-thread [threading mode] and +** [sqlite3_config()] will return [SQLITE_ERROR] if called with the +** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> +** +** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> +** <dd>There are no arguments to this option. ^This option sets the +** [threading mode] to Serialized. In other words, this option enables +** all mutexes including the recursive +** mutexes on [database connection] and [prepared statement] objects. +** In this mode (which is the default when SQLite is compiled with +** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access +** to [database connections] and [prepared statements] so that the +** application is free to use the same [database connection] or the +** same [prepared statement] in different threads at the same time. +** ^If SQLite is compiled with +** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then +** it is not possible to set the Serialized [threading mode] and +** [sqlite3_config()] will return [SQLITE_ERROR] if called with the +** SQLITE_CONFIG_SERIALIZED configuration option.</dd> +** +** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> +** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is +** a pointer to an instance of the [sqlite3_mem_methods] structure. +** The argument specifies +** alternative low-level memory allocation routines to be used in place of +** the memory allocation routines built into SQLite.)^ ^SQLite makes +** its own private copy of the content of the [sqlite3_mem_methods] structure +** before the [sqlite3_config()] call returns.</dd> +** +** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> +** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which +** is a pointer to an instance of the [sqlite3_mem_methods] structure. +** The [sqlite3_mem_methods] +** structure is filled with the currently defined memory allocation routines.)^ +** This option can be used to overload the default memory allocation +** routines with a wrapper that simulations memory allocation failure or +** tracks memory usage, for example. </dd> +** +** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt> +** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of +** type int, interpreted as a boolean, which if true provides a hint to +** SQLite that it should avoid large memory allocations if possible. +** SQLite will run faster if it is free to make large memory allocations, +** but some application might prefer to run slower in exchange for +** guarantees about memory fragmentation that are possible if large +** allocations are avoided. This hint is normally off. +** </dd> +** +** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> +** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, +** interpreted as a boolean, which enables or disables the collection of +** memory allocation statistics. ^(When memory allocation statistics are +** disabled, the following SQLite interfaces become non-operational: +** <ul> +** <li> [sqlite3_memory_used()] +** <li> [sqlite3_memory_highwater()] +** <li> [sqlite3_soft_heap_limit64()] +** <li> [sqlite3_status64()] +** </ul>)^ +** ^Memory allocation statistics are enabled by default unless SQLite is +** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory +** allocation statistics are disabled by default. +** </dd> +** +** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> +** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used. +** </dd> +** +** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> +** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool +** that SQLite can use for the database page cache with the default page +** cache implementation. +** This configuration option is a no-op if an application-define page +** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. +** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to +** 8-byte aligned memory (pMem), the size of each page cache line (sz), +** and the number of cache lines (N). +** The sz argument should be the size of the largest database page +** (a power of two between 512 and 65536) plus some extra bytes for each +** page header. ^The number of extra bytes needed by the page header +** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. +** ^It is harmless, apart from the wasted memory, +** for the sz parameter to be larger than necessary. The pMem +** argument must be either a NULL pointer or a pointer to an 8-byte +** aligned block of memory of at least sz*N bytes, otherwise +** subsequent behavior is undefined. +** ^When pMem is not NULL, SQLite will strive to use the memory provided +** to satisfy page cache needs, falling back to [sqlite3_malloc()] if +** a page cache line is larger than sz bytes or if all of the pMem buffer +** is exhausted. +** ^If pMem is NULL and N is non-zero, then each database connection +** does an initial bulk allocation for page cache memory +** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or +** of -1024*N bytes if N is negative, . ^If additional +** page cache memory is needed beyond what is provided by the initial +** allocation, then SQLite goes to [sqlite3_malloc()] separately for each +** additional cache line. </dd> +** +** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> +** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer +** that SQLite will use for all of its dynamic memory allocation needs +** beyond those provided for by [SQLITE_CONFIG_PAGECACHE]. +** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled +** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns +** [SQLITE_ERROR] if invoked otherwise. +** ^There are three arguments to SQLITE_CONFIG_HEAP: +** An 8-byte aligned pointer to the memory, +** the number of bytes in the memory buffer, and the minimum allocation size. +** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts +** to using its default memory allocator (the system malloc() implementation), +** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the +** memory pointer is not NULL then the alternative memory +** allocator is engaged to handle all of SQLites memory allocation needs. +** The first pointer (the memory pointer) must be aligned to an 8-byte +** boundary or subsequent behavior of SQLite will be undefined. +** The minimum allocation size is capped at 2**12. Reasonable values +** for the minimum allocation size are 2**5 through 2**8.</dd> +** +** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> +** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a +** pointer to an instance of the [sqlite3_mutex_methods] structure. +** The argument specifies alternative low-level mutex routines to be used +** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of +** the content of the [sqlite3_mutex_methods] structure before the call to +** [sqlite3_config()] returns. ^If SQLite is compiled with +** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then +** the entire mutexing subsystem is omitted from the build and hence calls to +** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will +** return [SQLITE_ERROR].</dd> +** +** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> +** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which +** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The +** [sqlite3_mutex_methods] +** structure is filled with the currently defined mutex routines.)^ +** This option can be used to overload the default mutex allocation +** routines with a wrapper used to track mutex usage for performance +** profiling or testing, for example. ^If SQLite is compiled with +** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then +** the entire mutexing subsystem is omitted from the build and hence calls to +** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will +** return [SQLITE_ERROR].</dd> +** +** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> +** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine +** the default size of lookaside memory on each [database connection]. +** The first argument is the +** size of each lookaside buffer slot and the second is the number of +** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE +** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] +** option to [sqlite3_db_config()] can be used to change the lookaside +** configuration on individual connections.)^ </dd> +** +** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> +** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is +** a pointer to an [sqlite3_pcache_methods2] object. This object specifies +** the interface to a custom page cache implementation.)^ +** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> +** +** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> +** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which +** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of +** the current page cache implementation into that object.)^ </dd> +** +** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> +** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite +** global [error log]. +** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a +** function with a call signature of void(*)(void*,int,const char*), +** and a pointer to void. ^If the function pointer is not NULL, it is +** invoked by [sqlite3_log()] to process each logging event. ^If the +** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. +** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is +** passed through as the first parameter to the application-defined logger +** function whenever that function is invoked. ^The second parameter to +** the logger function is a copy of the first parameter to the corresponding +** [sqlite3_log()] call and is intended to be a [result code] or an +** [extended result code]. ^The third parameter passed to the logger is +** log message after formatting via [sqlite3_snprintf()]. +** The SQLite logging interface is not reentrant; the logger function +** supplied by the application must not invoke any SQLite interface. +** In a multi-threaded application, the application-defined logger +** function must be threadsafe. </dd> +** +** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI +** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. +** If non-zero, then URI handling is globally enabled. If the parameter is zero, +** then URI handling is globally disabled.)^ ^If URI handling is globally +** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], +** [sqlite3_open16()] or +** specified as part of [ATTACH] commands are interpreted as URIs, regardless +** of whether or not the [SQLITE_OPEN_URI] flag is set when the database +** connection is opened. ^If it is globally disabled, filenames are +** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the +** database connection is opened. ^(By default, URI handling is globally +** disabled. The default value may be changed by compiling with the +** [SQLITE_USE_URI] symbol defined.)^ +** +** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN +** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer +** argument which is interpreted as a boolean in order to enable or disable +** the use of covering indices for full table scans in the query optimizer. +** ^The default setting is determined +** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" +** if that compile-time option is omitted. +** The ability to disable the use of covering indices for full table scans +** is because some incorrectly coded legacy applications might malfunction +** when the optimization is enabled. Providing the ability to +** disable the optimization allows the older, buggy application code to work +** without change even with newer versions of SQLite. +** +** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] +** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE +** <dd> These options are obsolete and should not be used by new code. +** They are retained for backwards compatibility but are now no-ops. +** </dd> +** +** [[SQLITE_CONFIG_SQLLOG]] +** <dt>SQLITE_CONFIG_SQLLOG +** <dd>This option is only available if sqlite is compiled with the +** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should +** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). +** The second should be of type (void*). The callback is invoked by the library +** in three separate circumstances, identified by the value passed as the +** fourth parameter. If the fourth parameter is 0, then the database connection +** passed as the second argument has just been opened. The third argument +** points to a buffer containing the name of the main database file. If the +** fourth parameter is 1, then the SQL statement that the third parameter +** points to has just been executed. Or, if the fourth parameter is 2, then +** the connection being passed as the second parameter is being closed. The +** third parameter is passed NULL In this case. An example of using this +** configuration option can be seen in the "test_sqllog.c" source file in +** the canonical SQLite source tree.</dd> +** +** [[SQLITE_CONFIG_MMAP_SIZE]] +** <dt>SQLITE_CONFIG_MMAP_SIZE +** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values +** that are the default mmap size limit (the default setting for +** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. +** ^The default setting can be overridden by each database connection using +** either the [PRAGMA mmap_size] command, or by using the +** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size +** will be silently truncated if necessary so that it does not exceed the +** compile-time maximum mmap size set by the +** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ +** ^If either argument to this option is negative, then that argument is +** changed to its compile-time default. +** +** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] +** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE +** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is +** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro +** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value +** that specifies the maximum size of the created heap. +** +** [[SQLITE_CONFIG_PCACHE_HDRSZ]] +** <dt>SQLITE_CONFIG_PCACHE_HDRSZ +** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which +** is a pointer to an integer and writes into that integer the number of extra +** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. +** The amount of extra space required can change depending on the compiler, +** target platform, and SQLite version. +** +** [[SQLITE_CONFIG_PMASZ]] +** <dt>SQLITE_CONFIG_PMASZ +** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which +** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded +** sorter to that integer. The default minimum PMA Size is set by the +** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched +** to help with sort operations when multithreaded sorting +** is enabled (using the [PRAGMA threads] command) and the amount of content +** to be sorted exceeds the page size times the minimum of the +** [PRAGMA cache_size] setting and this value. +** +** [[SQLITE_CONFIG_STMTJRNL_SPILL]] +** <dt>SQLITE_CONFIG_STMTJRNL_SPILL +** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which +** becomes the [statement journal] spill-to-disk threshold. +** [Statement journals] are held in memory until their size (in bytes) +** exceeds this threshold, at which point they are written to disk. +** Or if the threshold is -1, statement journals are always held +** exclusively in memory. +** Since many statement journals never become large, setting the spill +** threshold to a value such as 64KiB can greatly reduce the amount of +** I/O required to support statement rollback. +** The default value for this setting is controlled by the +** [SQLITE_STMTJRNL_SPILL] compile-time option. +** +** [[SQLITE_CONFIG_SORTERREF_SIZE]] +** <dt>SQLITE_CONFIG_SORTERREF_SIZE +** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter +** of type (int) - the new value of the sorter-reference size threshold. +** Usually, when SQLite uses an external sort to order records according +** to an ORDER BY clause, all fields required by the caller are present in the +** sorted records. However, if SQLite determines based on the declared type +** of a table column that its values are likely to be very large - larger +** than the configured sorter-reference size threshold - then a reference +** is stored in each sorted record and the required column values loaded +** from the database as records are returned in sorted order. The default +** value for this option is to never use this optimization. Specifying a +** negative value for this option restores the default behaviour. +** This option is only available if SQLite is compiled with the +** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. +** +** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] +** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE +** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter +** [sqlite3_int64] parameter which is the default maximum size for an in-memory +** database created using [sqlite3_deserialize()]. This default maximum +** size can be adjusted up or down for individual databases using the +** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this +** configuration setting is never used, then the default maximum is determined +** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that +** compile-time option is not set, then the default maximum is 1073741824. +** </dl> +*/ +#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ +#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ +#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ +#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ +#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ +#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ +#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ +#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ +#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ +#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ +#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ +/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ +#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ +#define SQLITE_CONFIG_PCACHE 14 /* no-op */ +#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ +#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ +#define SQLITE_CONFIG_URI 17 /* int */ +#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ +#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ +#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ +#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ +#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ +#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ +#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ +#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ +#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ +#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ +#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ +#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ + +/* +** CAPI3REF: Database Connection Configuration Options +** +** These constants are the available integer configuration options that +** can be passed as the second argument to the [sqlite3_db_config()] interface. +** +** New configuration options may be added in future releases of SQLite. +** Existing configuration options might be discontinued. Applications +** should check the return code from [sqlite3_db_config()] to make sure that +** the call worked. ^The [sqlite3_db_config()] interface will return a +** non-zero [error code] if a discontinued or unsupported configuration option +** is invoked. +** +** <dl> +** [[SQLITE_DBCONFIG_LOOKASIDE]] +** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> +** <dd> ^This option takes three additional arguments that determine the +** [lookaside memory allocator] configuration for the [database connection]. +** ^The first argument (the third parameter to [sqlite3_db_config()] is a +** pointer to a memory buffer to use for lookaside memory. +** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb +** may be NULL in which case SQLite will allocate the +** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the +** size of each lookaside buffer slot. ^The third argument is the number of +** slots. The size of the buffer in the first argument must be greater than +** or equal to the product of the second and third arguments. The buffer +** must be aligned to an 8-byte boundary. ^If the second argument to +** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally +** rounded down to the next smaller multiple of 8. ^(The lookaside memory +** configuration for a database connection can only be changed when that +** connection is not currently using lookaside memory, or in other words +** when the "current value" returned by +** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. +** Any attempt to change the lookaside memory configuration when lookaside +** memory is in use leaves the configuration unchanged and returns +** [SQLITE_BUSY].)^</dd> +** +** [[SQLITE_DBCONFIG_ENABLE_FKEY]] +** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> +** <dd> ^This option is used to enable or disable the enforcement of +** [foreign key constraints]. There should be two additional arguments. +** The first argument is an integer which is 0 to disable FK enforcement, +** positive to enable FK enforcement or negative to leave FK enforcement +** unchanged. The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether FK enforcement is off or on +** following this call. The second parameter may be a NULL pointer, in +** which case the FK enforcement setting is not reported back. </dd> +** +** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]] +** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> +** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. +** There should be two additional arguments. +** The first argument is an integer which is 0 to disable triggers, +** positive to enable triggers or negative to leave the setting unchanged. +** The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether triggers are disabled or enabled +** following this call. The second parameter may be a NULL pointer, in +** which case the trigger setting is not reported back. </dd> +** +** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] +** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> +** <dd> ^This option is used to enable or disable the +** [fts3_tokenizer()] function which is part of the +** [FTS3] full-text search engine extension. +** There should be two additional arguments. +** The first argument is an integer which is 0 to disable fts3_tokenizer() or +** positive to enable fts3_tokenizer() or negative to leave the setting +** unchanged. +** The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled +** following this call. The second parameter may be a NULL pointer, in +** which case the new setting is not reported back. </dd> +** +** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]] +** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> +** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] +** interface independently of the [load_extension()] SQL function. +** The [sqlite3_enable_load_extension()] API enables or disables both the +** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. +** There should be two additional arguments. +** When the first argument to this interface is 1, then only the C-API is +** enabled and the SQL function remains disabled. If the first argument to +** this interface is 0, then both the C-API and the SQL function are disabled. +** If the first argument is -1, then no changes are made to state of either the +** C-API or the SQL function. +** The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface +** is disabled or enabled following this call. The second parameter may +** be a NULL pointer, in which case the new setting is not reported back. +** </dd> +** +** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> +** <dd> ^This option is used to change the name of the "main" database +** schema. ^The sole argument is a pointer to a constant UTF8 string +** which will become the new schema name in place of "main". ^SQLite +** does not make a copy of the new main schema name string, so the application +** must ensure that the argument passed into this DBCONFIG option is unchanged +** until after the database connection closes. +** </dd> +** +** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] +** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> +** <dd> Usually, when a database in wal mode is closed or detached from a +** database handle, SQLite checks if this will mean that there are now no +** connections at all to the database. If so, it performs a checkpoint +** operation before closing the connection. This option may be used to +** override this behaviour. The first parameter passed to this operation +** is an integer - positive to disable checkpoints-on-close, or zero (the +** default) to enable them, and negative to leave the setting unchanged. +** The second parameter is a pointer to an integer +** into which is written 0 or 1 to indicate whether checkpoints-on-close +** have been disabled - 0 if they are not disabled, 1 if they are. +** </dd> +** +** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt> +** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates +** the [query planner stability guarantee] (QPSG). When the QPSG is active, +** a single SQL query statement will always use the same algorithm regardless +** of values of [bound parameters].)^ The QPSG disables some query optimizations +** that look at the values of bound parameters, which can make some queries +** slower. But the QPSG has the advantage of more predictable behavior. With +** the QPSG active, SQLite will always use the same query plan in the field as +** was used during testing in the lab. +** The first argument to this setting is an integer which is 0 to disable +** the QPSG, positive to enable QPSG, or negative to leave the setting +** unchanged. The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether the QPSG is disabled or enabled +** following this call. +** </dd> +** +** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt> +** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not +** include output for any operations performed by trigger programs. This +** option is used to set or clear (the default) a flag that governs this +** behavior. The first parameter passed to this operation is an integer - +** positive to enable output for trigger programs, or zero to disable it, +** or negative to leave the setting unchanged. +** The second parameter is a pointer to an integer into which is written +** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if +** it is not disabled, 1 if it is. +** </dd> +** +** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt> +** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run +** [VACUUM] in order to reset a database back to an empty database +** with no schema and no content. The following process works even for +** a badly corrupted database file: +** <ol> +** <li> If the database connection is newly opened, make sure it has read the +** database schema by preparing then discarding some query against the +** database, or calling sqlite3_table_column_metadata(), ignoring any +** errors. This step is only necessary if the application desires to keep +** the database in WAL mode after the reset if it was in WAL mode before +** the reset. +** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); +** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0); +** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0); +** </ol> +** Because resetting a database is destructive and irreversible, the +** process requires the use of this obscure API and multiple steps to help +** ensure that it does not happen by accident. +** +** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt> +** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the +** "defensive" flag for a database connection. When the defensive +** flag is enabled, language features that allow ordinary SQL to +** deliberately corrupt the database file are disabled. The disabled +** features include but are not limited to the following: +** <ul> +** <li> The [PRAGMA writable_schema=ON] statement. +** <li> Writes to the [sqlite_dbpage] virtual table. +** <li> Direct writes to [shadow tables]. +** </ul> +** </dd> +** +** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt> +** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the +** "writable_schema" flag. This has the same effect and is logically equivalent +** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF]. +** The first argument to this setting is an integer which is 0 to disable +** the writable_schema, positive to enable writable_schema, or negative to +** leave the setting unchanged. The second parameter is a pointer to an +** integer into which is written 0 or 1 to indicate whether the writable_schema +** is enabled or disabled following this call. +** </dd> +** </dl> +*/ +#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ +#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ +#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ +#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ +#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ +#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ +#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ +#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ +#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ +#define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */ +#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */ +#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */ +#define SQLITE_DBCONFIG_MAX 1011 /* Largest DBCONFIG */ + +/* +** CAPI3REF: Enable Or Disable Extended Result Codes +** METHOD: sqlite3 +** +** ^The sqlite3_extended_result_codes() routine enables or disables the +** [extended result codes] feature of SQLite. ^The extended result +** codes are disabled by default for historical compatibility. +*/ +SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); + +/* +** CAPI3REF: Last Insert Rowid +** METHOD: sqlite3 +** +** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) +** has a unique 64-bit signed +** integer key called the [ROWID | "rowid"]. ^The rowid is always available +** as an undeclared column named ROWID, OID, or _ROWID_ as long as those +** names are not also used by explicitly declared columns. ^If +** the table has a column of type [INTEGER PRIMARY KEY] then that column +** is another alias for the rowid. +** +** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of +** the most recent successful [INSERT] into a rowid table or [virtual table] +** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not +** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred +** on the database connection D, then sqlite3_last_insert_rowid(D) returns +** zero. +** +** As well as being set automatically as rows are inserted into database +** tables, the value returned by this function may be set explicitly by +** [sqlite3_set_last_insert_rowid()] +** +** Some virtual table implementations may INSERT rows into rowid tables as +** part of committing a transaction (e.g. to flush data accumulated in memory +** to disk). In this case subsequent calls to this function return the rowid +** associated with these internal INSERT operations, which leads to +** unintuitive results. Virtual table implementations that do write to rowid +** tables in this way can avoid this problem by restoring the original +** rowid value using [sqlite3_set_last_insert_rowid()] before returning +** control to the user. +** +** ^(If an [INSERT] occurs within a trigger then this routine will +** return the [rowid] of the inserted row as long as the trigger is +** running. Once the trigger program ends, the value returned +** by this routine reverts to what it was before the trigger was fired.)^ +** +** ^An [INSERT] that fails due to a constraint violation is not a +** successful [INSERT] and does not change the value returned by this +** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, +** and INSERT OR ABORT make no changes to the return value of this +** routine when their insertion fails. ^(When INSERT OR REPLACE +** encounters a constraint violation, it does not fail. The +** INSERT continues to completion after deleting rows that caused +** the constraint problem so INSERT OR REPLACE will always change +** the return value of this interface.)^ +** +** ^For the purposes of this routine, an [INSERT] is considered to +** be successful even if it is subsequently rolled back. +** +** This function is accessible to SQL statements via the +** [last_insert_rowid() SQL function]. +** +** If a separate thread performs a new [INSERT] on the same +** database connection while the [sqlite3_last_insert_rowid()] +** function is running and thus changes the last insert [rowid], +** then the value returned by [sqlite3_last_insert_rowid()] is +** unpredictable and might not equal either the old or the new +** last insert [rowid]. +*/ +SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); + +/* +** CAPI3REF: Set the Last Insert Rowid value. +** METHOD: sqlite3 +** +** The sqlite3_set_last_insert_rowid(D, R) method allows the application to +** set the value returned by calling sqlite3_last_insert_rowid(D) to R +** without inserting a row into the database. +*/ +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); + +/* +** CAPI3REF: Count The Number Of Rows Modified +** METHOD: sqlite3 +** +** ^This function returns the number of rows modified, inserted or +** deleted by the most recently completed INSERT, UPDATE or DELETE +** statement on the database connection specified by the only parameter. +** ^Executing any other type of SQL statement does not modify the value +** returned by this function. +** +** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are +** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], +** [foreign key actions] or [REPLACE] constraint resolution are not counted. +** +** Changes to a view that are intercepted by +** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value +** returned by sqlite3_changes() immediately after an INSERT, UPDATE or +** DELETE statement run on a view is always zero. Only changes made to real +** tables are counted. +** +** Things are more complicated if the sqlite3_changes() function is +** executed while a trigger program is running. This may happen if the +** program uses the [changes() SQL function], or if some other callback +** function invokes sqlite3_changes() directly. Essentially: +** +** <ul> +** <li> ^(Before entering a trigger program the value returned by +** sqlite3_changes() function is saved. After the trigger program +** has finished, the original value is restored.)^ +** +** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE +** statement sets the value returned by sqlite3_changes() +** upon completion as normal. Of course, this value will not include +** any changes performed by sub-triggers, as the sqlite3_changes() +** value will be saved and restored after each sub-trigger has run.)^ +** </ul> +** +** ^This means that if the changes() SQL function (or similar) is used +** by the first INSERT, UPDATE or DELETE statement within a trigger, it +** returns the value as set when the calling statement began executing. +** ^If it is used by the second or subsequent such statement within a trigger +** program, the value returned reflects the number of rows modified by the +** previous INSERT, UPDATE or DELETE statement within the same trigger. +** +** If a separate thread makes changes on the same database connection +** while [sqlite3_changes()] is running then the value returned +** is unpredictable and not meaningful. +** +** See also: +** <ul> +** <li> the [sqlite3_total_changes()] interface +** <li> the [count_changes pragma] +** <li> the [changes() SQL function] +** <li> the [data_version pragma] +** </ul> +*/ +SQLITE_API int sqlite3_changes(sqlite3*); + +/* +** CAPI3REF: Total Number Of Rows Modified +** METHOD: sqlite3 +** +** ^This function returns the total number of rows inserted, modified or +** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed +** since the database connection was opened, including those executed as +** part of trigger programs. ^Executing any other type of SQL statement +** does not affect the value returned by sqlite3_total_changes(). +** +** ^Changes made as part of [foreign key actions] are included in the +** count, but those made as part of REPLACE constraint resolution are +** not. ^Changes to a view that are intercepted by INSTEAD OF triggers +** are not counted. +** +** The [sqlite3_total_changes(D)] interface only reports the number +** of rows that changed due to SQL statement run against database +** connection D. Any changes by other database connections are ignored. +** To detect changes against a database file from other database +** connections use the [PRAGMA data_version] command or the +** [SQLITE_FCNTL_DATA_VERSION] [file control]. +** +** If a separate thread makes changes on the same database connection +** while [sqlite3_total_changes()] is running then the value +** returned is unpredictable and not meaningful. +** +** See also: +** <ul> +** <li> the [sqlite3_changes()] interface +** <li> the [count_changes pragma] +** <li> the [changes() SQL function] +** <li> the [data_version pragma] +** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control] +** </ul> +*/ +SQLITE_API int sqlite3_total_changes(sqlite3*); + +/* +** CAPI3REF: Interrupt A Long-Running Query +** METHOD: sqlite3 +** +** ^This function causes any pending database operation to abort and +** return at its earliest opportunity. This routine is typically +** called in response to a user action such as pressing "Cancel" +** or Ctrl-C where the user wants a long query operation to halt +** immediately. +** +** ^It is safe to call this routine from a thread different from the +** thread that is currently running the database operation. But it +** is not safe to call this routine with a [database connection] that +** is closed or might close before sqlite3_interrupt() returns. +** +** ^If an SQL operation is very nearly finished at the time when +** sqlite3_interrupt() is called, then it might not have an opportunity +** to be interrupted and might continue to completion. +** +** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. +** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE +** that is inside an explicit transaction, then the entire transaction +** will be rolled back automatically. +** +** ^The sqlite3_interrupt(D) call is in effect until all currently running +** SQL statements on [database connection] D complete. ^Any new SQL statements +** that are started after the sqlite3_interrupt() call and before the +** running statements reaches zero are interrupted as if they had been +** running prior to the sqlite3_interrupt() call. ^New SQL statements +** that are started after the running statement count reaches zero are +** not effected by the sqlite3_interrupt(). +** ^A call to sqlite3_interrupt(D) that occurs when there are no running +** SQL statements is a no-op and has no effect on SQL statements +** that are started after the sqlite3_interrupt() call returns. +*/ +SQLITE_API void sqlite3_interrupt(sqlite3*); + +/* +** CAPI3REF: Determine If An SQL Statement Is Complete +** +** These routines are useful during command-line input to determine if the +** currently entered text seems to form a complete SQL statement or +** if additional input is needed before sending the text into +** SQLite for parsing. ^These routines return 1 if the input string +** appears to be a complete SQL statement. ^A statement is judged to be +** complete if it ends with a semicolon token and is not a prefix of a +** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within +** string literals or quoted identifier names or comments are not +** independent tokens (they are part of the token in which they are +** embedded) and thus do not count as a statement terminator. ^Whitespace +** and comments that follow the final semicolon are ignored. +** +** ^These routines return 0 if the statement is incomplete. ^If a +** memory allocation fails, then SQLITE_NOMEM is returned. +** +** ^These routines do not parse the SQL statements thus +** will not detect syntactically incorrect SQL. +** +** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior +** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked +** automatically by sqlite3_complete16(). If that initialization fails, +** then the return value from sqlite3_complete16() will be non-zero +** regardless of whether or not the input SQL is complete.)^ +** +** The input to [sqlite3_complete()] must be a zero-terminated +** UTF-8 string. +** +** The input to [sqlite3_complete16()] must be a zero-terminated +** UTF-16 string in native byte order. +*/ +SQLITE_API int sqlite3_complete(const char *sql); +SQLITE_API int sqlite3_complete16(const void *sql); + +/* +** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors +** KEYWORDS: {busy-handler callback} {busy handler} +** METHOD: sqlite3 +** +** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X +** that might be invoked with argument P whenever +** an attempt is made to access a database table associated with +** [database connection] D when another thread +** or process has the table locked. +** The sqlite3_busy_handler() interface is used to implement +** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. +** +** ^If the busy callback is NULL, then [SQLITE_BUSY] +** is returned immediately upon encountering the lock. ^If the busy callback +** is not NULL, then the callback might be invoked with two arguments. +** +** ^The first argument to the busy handler is a copy of the void* pointer which +** is the third argument to sqlite3_busy_handler(). ^The second argument to +** the busy handler callback is the number of times that the busy handler has +** been invoked previously for the same locking event. ^If the +** busy callback returns 0, then no additional attempts are made to +** access the database and [SQLITE_BUSY] is returned +** to the application. +** ^If the callback returns non-zero, then another attempt +** is made to access the database and the cycle repeats. +** +** The presence of a busy handler does not guarantee that it will be invoked +** when there is lock contention. ^If SQLite determines that invoking the busy +** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] +** to the application instead of invoking the +** busy handler. +** Consider a scenario where one process is holding a read lock that +** it is trying to promote to a reserved lock and +** a second process is holding a reserved lock that it is trying +** to promote to an exclusive lock. The first process cannot proceed +** because it is blocked by the second and the second process cannot +** proceed because it is blocked by the first. If both processes +** invoke the busy handlers, neither will make any progress. Therefore, +** SQLite returns [SQLITE_BUSY] for the first process, hoping that this +** will induce the first process to release its read lock and allow +** the second process to proceed. +** +** ^The default busy callback is NULL. +** +** ^(There can only be a single busy handler defined for each +** [database connection]. Setting a new busy handler clears any +** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] +** or evaluating [PRAGMA busy_timeout=N] will change the +** busy handler and thus clear any previously set busy handler. +** +** The busy callback should not take any actions which modify the +** database connection that invoked the busy handler. In other words, +** the busy handler is not reentrant. Any such actions +** result in undefined behavior. +** +** A busy handler must not close the database connection +** or [prepared statement] that invoked the busy handler. +*/ +SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); + +/* +** CAPI3REF: Set A Busy Timeout +** METHOD: sqlite3 +** +** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps +** for a specified amount of time when a table is locked. ^The handler +** will sleep multiple times until at least "ms" milliseconds of sleeping +** have accumulated. ^After at least "ms" milliseconds of sleeping, +** the handler returns 0 which causes [sqlite3_step()] to return +** [SQLITE_BUSY]. +** +** ^Calling this routine with an argument less than or equal to zero +** turns off all busy handlers. +** +** ^(There can only be a single busy handler for a particular +** [database connection] at any given moment. If another busy handler +** was defined (using [sqlite3_busy_handler()]) prior to calling +** this routine, that other busy handler is cleared.)^ +** +** See also: [PRAGMA busy_timeout] +*/ +SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); + +/* +** CAPI3REF: Convenience Routines For Running Queries +** METHOD: sqlite3 +** +** This is a legacy interface that is preserved for backwards compatibility. +** Use of this interface is not recommended. +** +** Definition: A <b>result table</b> is memory data structure created by the +** [sqlite3_get_table()] interface. A result table records the +** complete query results from one or more queries. +** +** The table conceptually has a number of rows and columns. But +** these numbers are not part of the result table itself. These +** numbers are obtained separately. Let N be the number of rows +** and M be the number of columns. +** +** A result table is an array of pointers to zero-terminated UTF-8 strings. +** There are (N+1)*M elements in the array. The first M pointers point +** to zero-terminated strings that contain the names of the columns. +** The remaining entries all point to query results. NULL values result +** in NULL pointers. All other values are in their UTF-8 zero-terminated +** string representation as returned by [sqlite3_column_text()]. +** +** A result table might consist of one or more memory allocations. +** It is not safe to pass a result table directly to [sqlite3_free()]. +** A result table should be deallocated using [sqlite3_free_table()]. +** +** ^(As an example of the result table format, suppose a query result +** is as follows: +** +** <blockquote><pre> +** Name | Age +** ----------------------- +** Alice | 43 +** Bob | 28 +** Cindy | 21 +** </pre></blockquote> +** +** There are two column (M==2) and three rows (N==3). Thus the +** result table has 8 entries. Suppose the result table is stored +** in an array names azResult. Then azResult holds this content: +** +** <blockquote><pre> +** azResult[0] = "Name"; +** azResult[1] = "Age"; +** azResult[2] = "Alice"; +** azResult[3] = "43"; +** azResult[4] = "Bob"; +** azResult[5] = "28"; +** azResult[6] = "Cindy"; +** azResult[7] = "21"; +** </pre></blockquote>)^ +** +** ^The sqlite3_get_table() function evaluates one or more +** semicolon-separated SQL statements in the zero-terminated UTF-8 +** string of its 2nd parameter and returns a result table to the +** pointer given in its 3rd parameter. +** +** After the application has finished with the result from sqlite3_get_table(), +** it must pass the result table pointer to sqlite3_free_table() in order to +** release the memory that was malloced. Because of the way the +** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling +** function must not try to call [sqlite3_free()] directly. Only +** [sqlite3_free_table()] is able to release the memory properly and safely. +** +** The sqlite3_get_table() interface is implemented as a wrapper around +** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access +** to any internal data structures of SQLite. It uses only the public +** interface defined here. As a consequence, errors that occur in the +** wrapper layer outside of the internal [sqlite3_exec()] call are not +** reflected in subsequent calls to [sqlite3_errcode()] or +** [sqlite3_errmsg()]. +*/ +SQLITE_API int sqlite3_get_table( + sqlite3 *db, /* An open database */ + const char *zSql, /* SQL to be evaluated */ + char ***pazResult, /* Results of the query */ + int *pnRow, /* Number of result rows written here */ + int *pnColumn, /* Number of result columns written here */ + char **pzErrmsg /* Error msg written here */ +); +SQLITE_API void sqlite3_free_table(char **result); + +/* +** CAPI3REF: Formatted String Printing Functions +** +** These routines are work-alikes of the "printf()" family of functions +** from the standard C library. +** These routines understand most of the common formatting options from +** the standard library printf() +** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). +** See the [built-in printf()] documentation for details. +** +** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their +** results into memory obtained from [sqlite3_malloc64()]. +** The strings returned by these two routines should be +** released by [sqlite3_free()]. ^Both routines return a +** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough +** memory to hold the resulting string. +** +** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from +** the standard C library. The result is written into the +** buffer supplied as the second parameter whose size is given by +** the first parameter. Note that the order of the +** first two parameters is reversed from snprintf().)^ This is an +** historical accident that cannot be fixed without breaking +** backwards compatibility. ^(Note also that sqlite3_snprintf() +** returns a pointer to its buffer instead of the number of +** characters actually written into the buffer.)^ We admit that +** the number of characters written would be a more useful return +** value but we cannot change the implementation of sqlite3_snprintf() +** now without breaking compatibility. +** +** ^As long as the buffer size is greater than zero, sqlite3_snprintf() +** guarantees that the buffer is always zero-terminated. ^The first +** parameter "n" is the total size of the buffer, including space for +** the zero terminator. So the longest string that can be completely +** written will be n-1 characters. +** +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). +** +** See also: [built-in printf()], [printf() SQL function] +*/ +SQLITE_API char *sqlite3_mprintf(const char*,...); +SQLITE_API char *sqlite3_vmprintf(const char*, va_list); +SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); + +/* +** CAPI3REF: Memory Allocation Subsystem +** +** The SQLite core uses these three routines for all of its own +** internal memory allocation needs. "Core" in the previous sentence +** does not include operating-system specific VFS implementation. The +** Windows VFS uses native malloc() and free() for some operations. +** +** ^The sqlite3_malloc() routine returns a pointer to a block +** of memory at least N bytes in length, where N is the parameter. +** ^If sqlite3_malloc() is unable to obtain sufficient free +** memory, it returns a NULL pointer. ^If the parameter N to +** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns +** a NULL pointer. +** +** ^The sqlite3_malloc64(N) routine works just like +** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead +** of a signed 32-bit integer. +** +** ^Calling sqlite3_free() with a pointer previously returned +** by sqlite3_malloc() or sqlite3_realloc() releases that memory so +** that it might be reused. ^The sqlite3_free() routine is +** a no-op if is called with a NULL pointer. Passing a NULL pointer +** to sqlite3_free() is harmless. After being freed, memory +** should neither be read nor written. Even reading previously freed +** memory might result in a segmentation fault or other severe error. +** Memory corruption, a segmentation fault, or other severe error +** might result if sqlite3_free() is called with a non-NULL pointer that +** was not obtained from sqlite3_malloc() or sqlite3_realloc(). +** +** ^The sqlite3_realloc(X,N) interface attempts to resize a +** prior memory allocation X to be at least N bytes. +** ^If the X parameter to sqlite3_realloc(X,N) +** is a NULL pointer then its behavior is identical to calling +** sqlite3_malloc(N). +** ^If the N parameter to sqlite3_realloc(X,N) is zero or +** negative then the behavior is exactly the same as calling +** sqlite3_free(X). +** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation +** of at least N bytes in size or NULL if insufficient memory is available. +** ^If M is the size of the prior allocation, then min(N,M) bytes +** of the prior allocation are copied into the beginning of buffer returned +** by sqlite3_realloc(X,N) and the prior allocation is freed. +** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the +** prior allocation is not freed. +** +** ^The sqlite3_realloc64(X,N) interfaces works the same as +** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead +** of a 32-bit signed integer. +** +** ^If X is a memory allocation previously obtained from sqlite3_malloc(), +** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then +** sqlite3_msize(X) returns the size of that memory allocation in bytes. +** ^The value returned by sqlite3_msize(X) might be larger than the number +** of bytes requested when X was allocated. ^If X is a NULL pointer then +** sqlite3_msize(X) returns zero. If X points to something that is not +** the beginning of memory allocation, or if it points to a formerly +** valid memory allocation that has now been freed, then the behavior +** of sqlite3_msize(X) is undefined and possibly harmful. +** +** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(), +** sqlite3_malloc64(), and sqlite3_realloc64() +** is always aligned to at least an 8 byte boundary, or to a +** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time +** option is used. +** +** In SQLite version 3.5.0 and 3.5.1, it was possible to define +** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in +** implementation of these routines to be omitted. That capability +** is no longer provided. Only built-in memory allocators can be used. +** +** Prior to SQLite version 3.7.10, the Windows OS interface layer called +** the system malloc() and free() directly when converting +** filenames between the UTF-8 encoding used by SQLite +** and whatever filename encoding is used by the particular Windows +** installation. Memory allocation errors were detected, but +** they were reported back as [SQLITE_CANTOPEN] or +** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. +** +** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] +** must be either NULL or else pointers obtained from a prior +** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have +** not yet been released. +** +** The application must not read or write any part of +** a block of memory after it has been released using +** [sqlite3_free()] or [sqlite3_realloc()]. +*/ +SQLITE_API void *sqlite3_malloc(int); +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); +SQLITE_API void *sqlite3_realloc(void*, int); +SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); +SQLITE_API void sqlite3_free(void*); +SQLITE_API sqlite3_uint64 sqlite3_msize(void*); + +/* +** CAPI3REF: Memory Allocator Statistics +** +** SQLite provides these two interfaces for reporting on the status +** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] +** routines, which form the built-in memory allocation subsystem. +** +** ^The [sqlite3_memory_used()] routine returns the number of bytes +** of memory currently outstanding (malloced but not freed). +** ^The [sqlite3_memory_highwater()] routine returns the maximum +** value of [sqlite3_memory_used()] since the high-water mark +** was last reset. ^The values returned by [sqlite3_memory_used()] and +** [sqlite3_memory_highwater()] include any overhead +** added by SQLite in its implementation of [sqlite3_malloc()], +** but not overhead added by the any underlying system library +** routines that [sqlite3_malloc()] may call. +** +** ^The memory high-water mark is reset to the current value of +** [sqlite3_memory_used()] if and only if the parameter to +** [sqlite3_memory_highwater()] is true. ^The value returned +** by [sqlite3_memory_highwater(1)] is the high-water mark +** prior to the reset. +*/ +SQLITE_API sqlite3_int64 sqlite3_memory_used(void); +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); + +/* +** CAPI3REF: Pseudo-Random Number Generator +** +** SQLite contains a high-quality pseudo-random number generator (PRNG) used to +** select random [ROWID | ROWIDs] when inserting new records into a table that +** already uses the largest possible [ROWID]. The PRNG is also used for +** the build-in random() and randomblob() SQL functions. This interface allows +** applications to access the same PRNG for other purposes. +** +** ^A call to this routine stores N bytes of randomness into buffer P. +** ^The P parameter can be a NULL pointer. +** +** ^If this routine has not been previously called or if the previous +** call had N less than one or a NULL pointer for P, then the PRNG is +** seeded using randomness obtained from the xRandomness method of +** the default [sqlite3_vfs] object. +** ^If the previous call to this routine had an N of 1 or more and a +** non-NULL P then the pseudo-randomness is generated +** internally and without recourse to the [sqlite3_vfs] xRandomness +** method. +*/ +SQLITE_API void sqlite3_randomness(int N, void *P); + +/* +** CAPI3REF: Compile-Time Authorization Callbacks +** METHOD: sqlite3 +** KEYWORDS: {authorizer callback} +** +** ^This routine registers an authorizer callback with a particular +** [database connection], supplied in the first argument. +** ^The authorizer callback is invoked as SQL statements are being compiled +** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], +** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()], +** and [sqlite3_prepare16_v3()]. ^At various +** points during the compilation process, as logic is being created +** to perform various actions, the authorizer callback is invoked to +** see if those actions are allowed. ^The authorizer callback should +** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the +** specific action but allow the SQL statement to continue to be +** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be +** rejected with an error. ^If the authorizer callback returns +** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] +** then the [sqlite3_prepare_v2()] or equivalent call that triggered +** the authorizer will fail with an error message. +** +** When the callback returns [SQLITE_OK], that means the operation +** requested is ok. ^When the callback returns [SQLITE_DENY], the +** [sqlite3_prepare_v2()] or equivalent call that triggered the +** authorizer will fail with an error message explaining that +** access is denied. +** +** ^The first parameter to the authorizer callback is a copy of the third +** parameter to the sqlite3_set_authorizer() interface. ^The second parameter +** to the callback is an integer [SQLITE_COPY | action code] that specifies +** the particular action to be authorized. ^The third through sixth parameters +** to the callback are either NULL pointers or zero-terminated strings +** that contain additional details about the action to be authorized. +** Applications must always be prepared to encounter a NULL pointer in any +** of the third through the sixth parameters of the authorization callback. +** +** ^If the action code is [SQLITE_READ] +** and the callback returns [SQLITE_IGNORE] then the +** [prepared statement] statement is constructed to substitute +** a NULL value in place of the table column that would have +** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] +** return can be used to deny an untrusted user access to individual +** columns of a table. +** ^When a table is referenced by a [SELECT] but no column values are +** extracted from that table (for example in a query like +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback +** is invoked once for that table with a column name that is an empty string. +** ^If the action code is [SQLITE_DELETE] and the callback returns +** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the +** [truncate optimization] is disabled and all rows are deleted individually. +** +** An authorizer is used when [sqlite3_prepare | preparing] +** SQL statements from an untrusted source, to ensure that the SQL statements +** do not try to access data they are not allowed to see, or that they do not +** try to execute malicious statements that damage the database. For +** example, an application may allow a user to enter arbitrary +** SQL queries for evaluation by a database. But the application does +** not want the user to be able to make arbitrary changes to the +** database. An authorizer could then be put in place while the +** user-entered SQL is being [sqlite3_prepare | prepared] that +** disallows everything except [SELECT] statements. +** +** Applications that need to process SQL from untrusted sources +** might also consider lowering resource limits using [sqlite3_limit()] +** and limiting database size using the [max_page_count] [PRAGMA] +** in addition to using an authorizer. +** +** ^(Only a single authorizer can be in place on a database connection +** at a time. Each call to sqlite3_set_authorizer overrides the +** previous call.)^ ^Disable the authorizer by installing a NULL callback. +** The authorizer is disabled by default. +** +** The authorizer callback must not do anything that will modify +** the database connection that invoked the authorizer callback. +** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their +** database connections for the meaning of "modify" in this paragraph. +** +** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the +** statement might be re-prepared during [sqlite3_step()] due to a +** schema change. Hence, the application should ensure that the +** correct authorizer callback remains in place during the [sqlite3_step()]. +** +** ^Note that the authorizer callback is invoked only during +** [sqlite3_prepare()] or its variants. Authorization is not +** performed during statement evaluation in [sqlite3_step()], unless +** as stated in the previous paragraph, sqlite3_step() invokes +** sqlite3_prepare_v2() to reprepare a statement after a schema change. +*/ +SQLITE_API int sqlite3_set_authorizer( + sqlite3*, + int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), + void *pUserData +); + +/* +** CAPI3REF: Authorizer Return Codes +** +** The [sqlite3_set_authorizer | authorizer callback function] must +** return either [SQLITE_OK] or one of these two constants in order +** to signal SQLite whether or not the action is permitted. See the +** [sqlite3_set_authorizer | authorizer documentation] for additional +** information. +** +** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] +** returned from the [sqlite3_vtab_on_conflict()] interface. +*/ +#define SQLITE_DENY 1 /* Abort the SQL statement with an error */ +#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ + +/* +** CAPI3REF: Authorizer Action Codes +** +** The [sqlite3_set_authorizer()] interface registers a callback function +** that is invoked to authorize certain SQL statement actions. The +** second parameter to the callback is an integer code that specifies +** what action is being authorized. These are the integer action codes that +** the authorizer callback may be passed. +** +** These action code values signify what kind of operation is to be +** authorized. The 3rd and 4th parameters to the authorization +** callback function will be parameters or NULL depending on which of these +** codes is used as the second parameter. ^(The 5th parameter to the +** authorizer callback is the name of the database ("main", "temp", +** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback +** is the name of the inner-most trigger or view that is responsible for +** the access attempt or NULL if this access attempt is directly from +** top-level SQL code. +*/ +/******************************************* 3rd ************ 4th ***********/ +#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ +#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ +#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ +#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ +#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ +#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ +#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ +#define SQLITE_CREATE_VIEW 8 /* View Name NULL */ +#define SQLITE_DELETE 9 /* Table Name NULL */ +#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ +#define SQLITE_DROP_TABLE 11 /* Table Name NULL */ +#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ +#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ +#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ +#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ +#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ +#define SQLITE_DROP_VIEW 17 /* View Name NULL */ +#define SQLITE_INSERT 18 /* Table Name NULL */ +#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ +#define SQLITE_READ 20 /* Table Name Column Name */ +#define SQLITE_SELECT 21 /* NULL NULL */ +#define SQLITE_TRANSACTION 22 /* Operation NULL */ +#define SQLITE_UPDATE 23 /* Table Name Column Name */ +#define SQLITE_ATTACH 24 /* Filename NULL */ +#define SQLITE_DETACH 25 /* Database Name NULL */ +#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ +#define SQLITE_REINDEX 27 /* Index Name NULL */ +#define SQLITE_ANALYZE 28 /* Table Name NULL */ +#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ +#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ +#define SQLITE_FUNCTION 31 /* NULL Function Name */ +#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ +#define SQLITE_COPY 0 /* No longer used */ +#define SQLITE_RECURSIVE 33 /* NULL NULL */ + +/* +** CAPI3REF: Tracing And Profiling Functions +** METHOD: sqlite3 +** +** These routines are deprecated. Use the [sqlite3_trace_v2()] interface +** instead of the routines described here. +** +** These routines register callback functions that can be used for +** tracing and profiling the execution of SQL statements. +** +** ^The callback function registered by sqlite3_trace() is invoked at +** various times when an SQL statement is being run by [sqlite3_step()]. +** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the +** SQL statement text as the statement first begins executing. +** ^(Additional sqlite3_trace() callbacks might occur +** as each triggered subprogram is entered. The callbacks for triggers +** contain a UTF-8 SQL comment that identifies the trigger.)^ +** +** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit +** the length of [bound parameter] expansion in the output of sqlite3_trace(). +** +** ^The callback function registered by sqlite3_profile() is invoked +** as each SQL statement finishes. ^The profile callback contains +** the original statement text and an estimate of wall-clock time +** of how long that statement took to run. ^The profile callback +** time is in units of nanoseconds, however the current implementation +** is only capable of millisecond resolution so the six least significant +** digits in the time are meaningless. Future versions of SQLite +** might provide greater resolution on the profiler callback. Invoking +** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the +** profile callback. +*/ +SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*, + void(*xTrace)(void*,const char*), void*); +SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, + void(*xProfile)(void*,const char*,sqlite3_uint64), void*); + +/* +** CAPI3REF: SQL Trace Event Codes +** KEYWORDS: SQLITE_TRACE +** +** These constants identify classes of events that can be monitored +** using the [sqlite3_trace_v2()] tracing logic. The M argument +** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of +** the following constants. ^The first argument to the trace callback +** is one of the following constants. +** +** New tracing constants may be added in future releases. +** +** ^A trace callback has four arguments: xCallback(T,C,P,X). +** ^The T argument is one of the integer type codes above. +** ^The C argument is a copy of the context pointer passed in as the +** fourth argument to [sqlite3_trace_v2()]. +** The P and X arguments are pointers whose meanings depend on T. +** +** <dl> +** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt> +** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement +** first begins running and possibly at other times during the +** execution of the prepared statement, such as at the start of each +** trigger subprogram. ^The P argument is a pointer to the +** [prepared statement]. ^The X argument is a pointer to a string which +** is the unexpanded SQL text of the prepared statement or an SQL comment +** that indicates the invocation of a trigger. ^The callback can compute +** the same text that would have been returned by the legacy [sqlite3_trace()] +** interface by using the X argument when X begins with "--" and invoking +** [sqlite3_expanded_sql(P)] otherwise. +** +** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt> +** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same +** information as is provided by the [sqlite3_profile()] callback. +** ^The P argument is a pointer to the [prepared statement] and the +** X argument points to a 64-bit integer which is the estimated of +** the number of nanosecond that the prepared statement took to run. +** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes. +** +** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt> +** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared +** statement generates a single row of result. +** ^The P argument is a pointer to the [prepared statement] and the +** X argument is unused. +** +** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt> +** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database +** connection closes. +** ^The P argument is a pointer to the [database connection] object +** and the X argument is unused. +** </dl> +*/ +#define SQLITE_TRACE_STMT 0x01 +#define SQLITE_TRACE_PROFILE 0x02 +#define SQLITE_TRACE_ROW 0x04 +#define SQLITE_TRACE_CLOSE 0x08 + +/* +** CAPI3REF: SQL Trace Hook +** METHOD: sqlite3 +** +** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback +** function X against [database connection] D, using property mask M +** and context pointer P. ^If the X callback is +** NULL or if the M mask is zero, then tracing is disabled. The +** M argument should be the bitwise OR-ed combination of +** zero or more [SQLITE_TRACE] constants. +** +** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides +** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). +** +** ^The X callback is invoked whenever any of the events identified by +** mask M occur. ^The integer return value from the callback is currently +** ignored, though this may change in future releases. Callback +** implementations should return zero to ensure future compatibility. +** +** ^A trace callback is invoked with four arguments: callback(T,C,P,X). +** ^The T argument is one of the [SQLITE_TRACE] +** constants to indicate why the callback was invoked. +** ^The C argument is a copy of the context pointer. +** The P and X arguments are pointers whose meanings depend on T. +** +** The sqlite3_trace_v2() interface is intended to replace the legacy +** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which +** are deprecated. +*/ +SQLITE_API int sqlite3_trace_v2( + sqlite3*, + unsigned uMask, + int(*xCallback)(unsigned,void*,void*,void*), + void *pCtx +); + +/* +** CAPI3REF: Query Progress Callbacks +** METHOD: sqlite3 +** +** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback +** function X to be invoked periodically during long running calls to +** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for +** database connection D. An example use for this +** interface is to keep a GUI updated during a large query. +** +** ^The parameter P is passed through as the only parameter to the +** callback function X. ^The parameter N is the approximate number of +** [virtual machine instructions] that are evaluated between successive +** invocations of the callback X. ^If N is less than one then the progress +** handler is disabled. +** +** ^Only a single progress handler may be defined at one time per +** [database connection]; setting a new progress handler cancels the +** old one. ^Setting parameter X to NULL disables the progress handler. +** ^The progress handler is also disabled by setting N to a value less +** than 1. +** +** ^If the progress callback returns non-zero, the operation is +** interrupted. This feature can be used to implement a +** "Cancel" button on a GUI progress dialog box. +** +** The progress handler callback must not do anything that will modify +** the database connection that invoked the progress handler. +** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their +** database connections for the meaning of "modify" in this paragraph. +** +*/ +SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); + +/* +** CAPI3REF: Opening A New Database Connection +** CONSTRUCTOR: sqlite3 +** +** ^These routines open an SQLite database file as specified by the +** filename argument. ^The filename argument is interpreted as UTF-8 for +** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte +** order for sqlite3_open16(). ^(A [database connection] handle is usually +** returned in *ppDb, even if an error occurs. The only exception is that +** if SQLite is unable to allocate memory to hold the [sqlite3] object, +** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] +** object.)^ ^(If the database is opened (and/or created) successfully, then +** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The +** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain +** an English language description of the error following a failure of any +** of the sqlite3_open() routines. +** +** ^The default encoding will be UTF-8 for databases created using +** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases +** created using sqlite3_open16() will be UTF-16 in the native byte order. +** +** Whether or not an error occurs when it is opened, resources +** associated with the [database connection] handle should be released by +** passing it to [sqlite3_close()] when it is no longer required. +** +** The sqlite3_open_v2() interface works like sqlite3_open() +** except that it accepts two additional parameters for additional control +** over the new database connection. ^(The flags parameter to +** sqlite3_open_v2() can take one of +** the following three values, optionally combined with the +** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], +** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ +** +** <dl> +** ^(<dt>[SQLITE_OPEN_READONLY]</dt> +** <dd>The database is opened in read-only mode. If the database does not +** already exist, an error is returned.</dd>)^ +** +** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> +** <dd>The database is opened for reading and writing if possible, or reading +** only if the file is write protected by the operating system. In either +** case the database must already exist, otherwise an error is returned.</dd>)^ +** +** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> +** <dd>The database is opened for reading and writing, and is created if +** it does not already exist. This is the behavior that is always used for +** sqlite3_open() and sqlite3_open16().</dd>)^ +** </dl> +** +** If the 3rd parameter to sqlite3_open_v2() is not one of the +** combinations shown above optionally combined with other +** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] +** then the behavior is undefined. +** +** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection +** opens in the multi-thread [threading mode] as long as the single-thread +** mode has not been set at compile-time or start-time. ^If the +** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens +** in the serialized [threading mode] unless single-thread was +** previously selected at compile-time or start-time. +** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be +** eligible to use [shared cache mode], regardless of whether or not shared +** cache is enabled using [sqlite3_enable_shared_cache()]. ^The +** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not +** participate in [shared cache mode] even if it is enabled. +** +** ^The fourth parameter to sqlite3_open_v2() is the name of the +** [sqlite3_vfs] object that defines the operating system interface that +** the new database connection should use. ^If the fourth parameter is +** a NULL pointer then the default [sqlite3_vfs] object is used. +** +** ^If the filename is ":memory:", then a private, temporary in-memory database +** is created for the connection. ^This in-memory database will vanish when +** the database connection is closed. Future versions of SQLite might +** make use of additional special filenames that begin with the ":" character. +** It is recommended that when a database filename actually does begin with +** a ":" character you should prefix the filename with a pathname such as +** "./" to avoid ambiguity. +** +** ^If the filename is an empty string, then a private, temporary +** on-disk database will be created. ^This private database will be +** automatically deleted as soon as the database connection is closed. +** +** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> +** +** ^If [URI filename] interpretation is enabled, and the filename argument +** begins with "file:", then the filename is interpreted as a URI. ^URI +** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is +** set in the third argument to sqlite3_open_v2(), or if it has +** been enabled globally using the [SQLITE_CONFIG_URI] option with the +** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. +** URI filename interpretation is turned off +** by default, but future releases of SQLite might enable URI filename +** interpretation by default. See "[URI filenames]" for additional +** information. +** +** URI filenames are parsed according to RFC 3986. ^If the URI contains an +** authority, then it must be either an empty string or the string +** "localhost". ^If the authority is not an empty string or "localhost", an +** error is returned to the caller. ^The fragment component of a URI, if +** present, is ignored. +** +** ^SQLite uses the path component of the URI as the name of the disk file +** which contains the database. ^If the path begins with a '/' character, +** then it is interpreted as an absolute path. ^If the path does not begin +** with a '/' (meaning that the authority section is omitted from the URI) +** then the path is interpreted as a relative path. +** ^(On windows, the first component of an absolute path +** is a drive specification (e.g. "C:").)^ +** +** [[core URI query parameters]] +** The query component of a URI may contain parameters that are interpreted +** either by SQLite itself, or by a [VFS | custom VFS implementation]. +** SQLite and its built-in [VFSes] interpret the +** following query parameters: +** +** <ul> +** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of +** a VFS object that provides the operating system interface that should +** be used to access the database file on disk. ^If this option is set to +** an empty string the default VFS object is used. ^Specifying an unknown +** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is +** present, then the VFS specified by the option takes precedence over +** the value passed as the fourth parameter to sqlite3_open_v2(). +** +** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", +** "rwc", or "memory". Attempting to set it to any other value is +** an error)^. +** ^If "ro" is specified, then the database is opened for read-only +** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the +** third argument to sqlite3_open_v2(). ^If the mode option is set to +** "rw", then the database is opened for read-write (but not create) +** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had +** been set. ^Value "rwc" is equivalent to setting both +** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is +** set to "memory" then a pure [in-memory database] that never reads +** or writes from disk is used. ^It is an error to specify a value for +** the mode parameter that is less restrictive than that specified by +** the flags passed in the third parameter to sqlite3_open_v2(). +** +** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or +** "private". ^Setting it to "shared" is equivalent to setting the +** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to +** sqlite3_open_v2(). ^Setting the cache parameter to "private" is +** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. +** ^If sqlite3_open_v2() is used and the "cache" parameter is present in +** a URI filename, its value overrides any behavior requested by setting +** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. +** +** <li> <b>psow</b>: ^The psow parameter indicates whether or not the +** [powersafe overwrite] property does or does not apply to the +** storage media on which the database file resides. +** +** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter +** which if set disables file locking in rollback journal modes. This +** is useful for accessing a database on a filesystem that does not +** support locking. Caution: Database corruption might result if two +** or more processes write to the same database and any one of those +** processes uses nolock=1. +** +** <li> <b>immutable</b>: ^The immutable parameter is a boolean query +** parameter that indicates that the database file is stored on +** read-only media. ^When immutable is set, SQLite assumes that the +** database file cannot be changed, even by a process with higher +** privilege, and so the database is opened read-only and all locking +** and change detection is disabled. Caution: Setting the immutable +** property on a database file that does in fact change can result +** in incorrect query results and/or [SQLITE_CORRUPT] errors. +** See also: [SQLITE_IOCAP_IMMUTABLE]. +** +** </ul> +** +** ^Specifying an unknown parameter in the query component of a URI is not an +** error. Future versions of SQLite might understand additional query +** parameters. See "[query parameters with special meaning to SQLite]" for +** additional information. +** +** [[URI filename examples]] <h3>URI filename examples</h3> +** +** <table border="1" align=center cellpadding=5> +** <tr><th> URI filenames <th> Results +** <tr><td> file:data.db <td> +** Open the file "data.db" in the current directory. +** <tr><td> file:/home/fred/data.db<br> +** file:///home/fred/data.db <br> +** file://localhost/home/fred/data.db <br> <td> +** Open the database file "/home/fred/data.db". +** <tr><td> file://darkstar/home/fred/data.db <td> +** An error. "darkstar" is not a recognized authority. +** <tr><td style="white-space:nowrap"> +** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db +** <td> Windows only: Open the file "data.db" on fred's desktop on drive +** C:. Note that the %20 escaping in this example is not strictly +** necessary - space characters can be used literally +** in URI filenames. +** <tr><td> file:data.db?mode=ro&cache=private <td> +** Open file "data.db" in the current directory for read-only access. +** Regardless of whether or not shared-cache mode is enabled by +** default, use a private cache. +** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td> +** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile" +** that uses dot-files in place of posix advisory locking. +** <tr><td> file:data.db?mode=readonly <td> +** An error. "readonly" is not a valid option for the "mode" parameter. +** </table> +** +** ^URI hexadecimal escape sequences (%HH) are supported within the path and +** query components of a URI. A hexadecimal escape sequence consists of a +** percent sign - "%" - followed by exactly two hexadecimal digits +** specifying an octet value. ^Before the path or query components of a +** URI filename are interpreted, they are encoded using UTF-8 and all +** hexadecimal escape sequences replaced by a single byte containing the +** corresponding octet. If this process generates an invalid UTF-8 encoding, +** the results are undefined. +** +** <b>Note to Windows users:</b> The encoding used for the filename argument +** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever +** codepage is currently defined. Filenames containing international +** characters must be converted to UTF-8 prior to passing them into +** sqlite3_open() or sqlite3_open_v2(). +** +** <b>Note to Windows Runtime users:</b> The temporary directory must be set +** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various +** features that require the use of temporary files may fail. +** +** See also: [sqlite3_temp_directory] +*/ +SQLITE_API int sqlite3_open( + const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb /* OUT: SQLite db handle */ +); +SQLITE_API int sqlite3_open16( + const void *filename, /* Database filename (UTF-16) */ + sqlite3 **ppDb /* OUT: SQLite db handle */ +); +SQLITE_API int sqlite3_open_v2( + const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb, /* OUT: SQLite db handle */ + int flags, /* Flags */ + const char *zVfs /* Name of VFS module to use */ +); + +/* +** CAPI3REF: Obtain Values For URI Parameters +** +** These are utility routines, useful to VFS implementations, that check +** to see if a database file was a URI that contained a specific query +** parameter, and if so obtains the value of that query parameter. +** +** If F is the database filename pointer passed into the xOpen() method of +** a VFS implementation when the flags parameter to xOpen() has one or +** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and +** P is the name of the query parameter, then +** sqlite3_uri_parameter(F,P) returns the value of the P +** parameter if it exists or a NULL pointer if P does not appear as a +** query parameter on F. If P is a query parameter of F +** has no explicit value, then sqlite3_uri_parameter(F,P) returns +** a pointer to an empty string. +** +** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean +** parameter and returns true (1) or false (0) according to the value +** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the +** value of query parameter P is one of "yes", "true", or "on" in any +** case or if the value begins with a non-zero number. The +** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of +** query parameter P is one of "no", "false", or "off" in any case or +** if the value begins with a numeric zero. If P is not a query +** parameter on F or if the value of P is does not match any of the +** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). +** +** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a +** 64-bit signed integer and returns that integer, or D if P does not +** exist. If the value of P is something other than an integer, then +** zero is returned. +** +** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and +** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and +** is not a database file pathname pointer that SQLite passed into the xOpen +** VFS method, then the behavior of this routine is undefined and probably +** undesirable. +** +** See the [URI filename] documentation for additional information. +*/ +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); +SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); +SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); + + +/* +** CAPI3REF: Error Codes And Messages +** METHOD: sqlite3 +** +** ^If the most recent sqlite3_* API call associated with +** [database connection] D failed, then the sqlite3_errcode(D) interface +** returns the numeric [result code] or [extended result code] for that +** API call. +** ^The sqlite3_extended_errcode() +** interface is the same except that it always returns the +** [extended result code] even when extended result codes are +** disabled. +** +** The values returned by sqlite3_errcode() and/or +** sqlite3_extended_errcode() might change with each API call. +** Except, there are some interfaces that are guaranteed to never +** change the value of the error code. The error-code preserving +** interfaces are: +** +** <ul> +** <li> sqlite3_errcode() +** <li> sqlite3_extended_errcode() +** <li> sqlite3_errmsg() +** <li> sqlite3_errmsg16() +** </ul> +** +** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language +** text that describes the error, as either UTF-8 or UTF-16 respectively. +** ^(Memory to hold the error message string is managed internally. +** The application does not need to worry about freeing the result. +** However, the error string might be overwritten or deallocated by +** subsequent calls to other SQLite interface functions.)^ +** +** ^The sqlite3_errstr() interface returns the English-language text +** that describes the [result code], as UTF-8. +** ^(Memory to hold the error message string is managed internally +** and must not be freed by the application)^. +** +** When the serialized [threading mode] is in use, it might be the +** case that a second error occurs on a separate thread in between +** the time of the first error and the call to these interfaces. +** When that happens, the second error will be reported since these +** interfaces always report the most recent result. To avoid +** this, each thread can obtain exclusive use of the [database connection] D +** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning +** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after +** all calls to the interfaces listed here are completed. +** +** If an interface fails with SQLITE_MISUSE, that means the interface +** was invoked incorrectly by the application. In that case, the +** error code and message may or may not be set. +*/ +SQLITE_API int sqlite3_errcode(sqlite3 *db); +SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); +SQLITE_API const char *sqlite3_errmsg(sqlite3*); +SQLITE_API const void *sqlite3_errmsg16(sqlite3*); +SQLITE_API const char *sqlite3_errstr(int); + +/* +** CAPI3REF: Prepared Statement Object +** KEYWORDS: {prepared statement} {prepared statements} +** +** An instance of this object represents a single SQL statement that +** has been compiled into binary form and is ready to be evaluated. +** +** Think of each SQL statement as a separate computer program. The +** original SQL text is source code. A prepared statement object +** is the compiled object code. All SQL must be converted into a +** prepared statement before it can be run. +** +** The life-cycle of a prepared statement object usually goes like this: +** +** <ol> +** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. +** <li> Bind values to [parameters] using the sqlite3_bind_*() +** interfaces. +** <li> Run the SQL by calling [sqlite3_step()] one or more times. +** <li> Reset the prepared statement using [sqlite3_reset()] then go back +** to step 2. Do this zero or more times. +** <li> Destroy the object using [sqlite3_finalize()]. +** </ol> +*/ +typedef struct sqlite3_stmt sqlite3_stmt; + +/* +** CAPI3REF: Run-time Limits +** METHOD: sqlite3 +** +** ^(This interface allows the size of various constructs to be limited +** on a connection by connection basis. The first parameter is the +** [database connection] whose limit is to be set or queried. The +** second parameter is one of the [limit categories] that define a +** class of constructs to be size limited. The third parameter is the +** new limit for that construct.)^ +** +** ^If the new limit is a negative number, the limit is unchanged. +** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a +** [limits | hard upper bound] +** set at compile-time by a C preprocessor macro called +** [limits | SQLITE_MAX_<i>NAME</i>]. +** (The "_LIMIT_" in the name is changed to "_MAX_".))^ +** ^Attempts to increase a limit above its hard upper bound are +** silently truncated to the hard upper bound. +** +** ^Regardless of whether or not the limit was changed, the +** [sqlite3_limit()] interface returns the prior value of the limit. +** ^Hence, to find the current value of a limit without changing it, +** simply invoke this interface with the third parameter set to -1. +** +** Run-time limits are intended for use in applications that manage +** both their own internal database and also databases that are controlled +** by untrusted external sources. An example application might be a +** web browser that has its own databases for storing history and +** separate databases controlled by JavaScript applications downloaded +** off the Internet. The internal databases can be given the +** large, default limits. Databases managed by external sources can +** be given much smaller limits designed to prevent a denial of service +** attack. Developers might also want to use the [sqlite3_set_authorizer()] +** interface to further control untrusted SQL. The size of the database +** created by an untrusted script can be contained using the +** [max_page_count] [PRAGMA]. +** +** New run-time limit categories may be added in future releases. +*/ +SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); + +/* +** CAPI3REF: Run-Time Limit Categories +** KEYWORDS: {limit category} {*limit categories} +** +** These constants define various performance limits +** that can be lowered at run-time using [sqlite3_limit()]. +** The synopsis of the meanings of the various limits is shown below. +** Additional information is available at [limits | Limits in SQLite]. +** +** <dl> +** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> +** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ +** +** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> +** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ +** +** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> +** <dd>The maximum number of columns in a table definition or in the +** result set of a [SELECT] or the maximum number of columns in an index +** or in an ORDER BY or GROUP BY clause.</dd>)^ +** +** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> +** <dd>The maximum depth of the parse tree on any expression.</dd>)^ +** +** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> +** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ +** +** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> +** <dd>The maximum number of instructions in a virtual machine program +** used to implement an SQL statement. If [sqlite3_prepare_v2()] or +** the equivalent tries to allocate space for more than this many opcodes +** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^ +** +** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> +** <dd>The maximum number of arguments on a function.</dd>)^ +** +** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> +** <dd>The maximum number of [ATTACH | attached databases].)^</dd> +** +** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] +** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> +** <dd>The maximum length of the pattern argument to the [LIKE] or +** [GLOB] operators.</dd>)^ +** +** [[SQLITE_LIMIT_VARIABLE_NUMBER]] +** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> +** <dd>The maximum index number of any [parameter] in an SQL statement.)^ +** +** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> +** <dd>The maximum depth of recursion for triggers.</dd>)^ +** +** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> +** <dd>The maximum number of auxiliary worker threads that a single +** [prepared statement] may start.</dd>)^ +** </dl> +*/ +#define SQLITE_LIMIT_LENGTH 0 +#define SQLITE_LIMIT_SQL_LENGTH 1 +#define SQLITE_LIMIT_COLUMN 2 +#define SQLITE_LIMIT_EXPR_DEPTH 3 +#define SQLITE_LIMIT_COMPOUND_SELECT 4 +#define SQLITE_LIMIT_VDBE_OP 5 +#define SQLITE_LIMIT_FUNCTION_ARG 6 +#define SQLITE_LIMIT_ATTACHED 7 +#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 +#define SQLITE_LIMIT_VARIABLE_NUMBER 9 +#define SQLITE_LIMIT_TRIGGER_DEPTH 10 +#define SQLITE_LIMIT_WORKER_THREADS 11 + +/* +** CAPI3REF: Prepare Flags +** +** These constants define various flags that can be passed into +** "prepFlags" parameter of the [sqlite3_prepare_v3()] and +** [sqlite3_prepare16_v3()] interfaces. +** +** New flags may be added in future releases of SQLite. +** +** <dl> +** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt> +** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner +** that the prepared statement will be retained for a long time and +** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()] +** and [sqlite3_prepare16_v3()] assume that the prepared statement will +** be used just once or at most a few times and then destroyed using +** [sqlite3_finalize()] relatively soon. The current implementation acts +** on this hint by avoiding the use of [lookaside memory] so as not to +** deplete the limited store of lookaside memory. Future versions of +** SQLite may act on this hint differently. +** +** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt> +** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used +** to be required for any prepared statement that wanted to use the +** [sqlite3_normalized_sql()] interface. However, the +** [sqlite3_normalized_sql()] interface is now available to all +** prepared statements, regardless of whether or not they use this +** flag. +** +** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt> +** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler +** to return an error (error code SQLITE_ERROR) if the statement uses +** any virtual tables. +** </dl> +*/ +#define SQLITE_PREPARE_PERSISTENT 0x01 +#define SQLITE_PREPARE_NORMALIZE 0x02 +#define SQLITE_PREPARE_NO_VTAB 0x04 + +/* +** CAPI3REF: Compiling An SQL Statement +** KEYWORDS: {SQL statement compiler} +** METHOD: sqlite3 +** CONSTRUCTOR: sqlite3_stmt +** +** To execute an SQL statement, it must first be compiled into a byte-code +** program using one of these routines. Or, in other words, these routines +** are constructors for the [prepared statement] object. +** +** The preferred routine to use is [sqlite3_prepare_v2()]. The +** [sqlite3_prepare()] interface is legacy and should be avoided. +** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used +** for special purposes. +** +** The use of the UTF-8 interfaces is preferred, as SQLite currently +** does all parsing using UTF-8. The UTF-16 interfaces are provided +** as a convenience. The UTF-16 interfaces work by converting the +** input text into UTF-8, then invoking the corresponding UTF-8 interface. +** +** The first argument, "db", is a [database connection] obtained from a +** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or +** [sqlite3_open16()]. The database connection must not have been closed. +** +** The second argument, "zSql", is the statement to be compiled, encoded +** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(), +** and sqlite3_prepare_v3() +** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(), +** and sqlite3_prepare16_v3() use UTF-16. +** +** ^If the nByte argument is negative, then zSql is read up to the +** first zero terminator. ^If nByte is positive, then it is the +** number of bytes read from zSql. ^If nByte is zero, then no prepared +** statement is generated. +** If the caller knows that the supplied string is nul-terminated, then +** there is a small performance advantage to passing an nByte parameter that +** is the number of bytes in the input string <i>including</i> +** the nul-terminator. +** +** ^If pzTail is not NULL then *pzTail is made to point to the first byte +** past the end of the first SQL statement in zSql. These routines only +** compile the first statement in zSql, so *pzTail is left pointing to +** what remains uncompiled. +** +** ^*ppStmt is left pointing to a compiled [prepared statement] that can be +** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set +** to NULL. ^If the input text contains no SQL (if the input is an empty +** string or a comment) then *ppStmt is set to NULL. +** The calling procedure is responsible for deleting the compiled +** SQL statement using [sqlite3_finalize()] after it has finished with it. +** ppStmt may not be NULL. +** +** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; +** otherwise an [error code] is returned. +** +** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(), +** and sqlite3_prepare16_v3() interfaces are recommended for all new programs. +** The older interfaces (sqlite3_prepare() and sqlite3_prepare16()) +** are retained for backwards compatibility, but their use is discouraged. +** ^In the "vX" interfaces, the prepared statement +** that is returned (the [sqlite3_stmt] object) contains a copy of the +** original SQL text. This causes the [sqlite3_step()] interface to +** behave differently in three ways: +** +** <ol> +** <li> +** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it +** always used to do, [sqlite3_step()] will automatically recompile the SQL +** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY] +** retries will occur before sqlite3_step() gives up and returns an error. +** </li> +** +** <li> +** ^When an error occurs, [sqlite3_step()] will return one of the detailed +** [error codes] or [extended error codes]. ^The legacy behavior was that +** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code +** and the application would have to make a second call to [sqlite3_reset()] +** in order to find the underlying cause of the problem. With the "v2" prepare +** interfaces, the underlying reason for the error is returned immediately. +** </li> +** +** <li> +** ^If the specific value bound to [parameter | host parameter] in the +** WHERE clause might influence the choice of query plan for a statement, +** then the statement will be automatically recompiled, as if there had been +** a schema change, on the first [sqlite3_step()] call following any change +** to the [sqlite3_bind_text | bindings] of that [parameter]. +** ^The specific value of WHERE-clause [parameter] might influence the +** choice of query plan if the parameter is the left-hand side of a [LIKE] +** or [GLOB] operator or if the parameter is compared to an indexed column +** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. +** </li> +** </ol> +** +** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having +** the extra prepFlags parameter, which is a bit array consisting of zero or +** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The +** sqlite3_prepare_v2() interface works exactly the same as +** sqlite3_prepare_v3() with a zero prepFlags parameter. +*/ +SQLITE_API int sqlite3_prepare( + sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ +); +SQLITE_API int sqlite3_prepare_v2( + sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ +); +SQLITE_API int sqlite3_prepare_v3( + sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ +); +SQLITE_API int sqlite3_prepare16( + sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ +); +SQLITE_API int sqlite3_prepare16_v2( + sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ +); +SQLITE_API int sqlite3_prepare16_v3( + sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ +); + +/* +** CAPI3REF: Retrieving Statement SQL +** METHOD: sqlite3_stmt +** +** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8 +** SQL text used to create [prepared statement] P if P was +** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], +** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. +** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8 +** string containing the SQL text of prepared statement P with +** [bound parameters] expanded. +** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8 +** string containing the normalized SQL text of prepared statement P. The +** semantics used to normalize a SQL statement are unspecified and subject +** to change. At a minimum, literal values will be replaced with suitable +** placeholders. +** +** ^(For example, if a prepared statement is created using the SQL +** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 +** and parameter :xyz is unbound, then sqlite3_sql() will return +** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() +** will return "SELECT 2345,NULL".)^ +** +** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory +** is available to hold the result, or if the result would exceed the +** the maximum string length determined by the [SQLITE_LIMIT_LENGTH]. +** +** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of +** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time +** option causes sqlite3_expanded_sql() to always return NULL. +** +** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P) +** are managed by SQLite and are automatically freed when the prepared +** statement is finalized. +** ^The string returned by sqlite3_expanded_sql(P), on the other hand, +** is obtained from [sqlite3_malloc()] and must be free by the application +** by passing it to [sqlite3_free()]. +*/ +SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); +SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); +SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Determine If An SQL Statement Writes The Database +** METHOD: sqlite3_stmt +** +** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if +** and only if the [prepared statement] X makes no direct changes to +** the content of the database file. +** +** Note that [application-defined SQL functions] or +** [virtual tables] might change the database indirectly as a side effect. +** ^(For example, if an application defines a function "eval()" that +** calls [sqlite3_exec()], then the following SQL statement would +** change the database file through side-effects: +** +** <blockquote><pre> +** SELECT eval('DELETE FROM t1') FROM t2; +** </pre></blockquote> +** +** But because the [SELECT] statement does not change the database file +** directly, sqlite3_stmt_readonly() would still return true.)^ +** +** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], +** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, +** since the statements themselves do not actually modify the database but +** rather they control the timing of when other statements modify the +** database. ^The [ATTACH] and [DETACH] statements also cause +** sqlite3_stmt_readonly() to return true since, while those statements +** change the configuration of a database connection, they do not make +** changes to the content of the database files on disk. +** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since +** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and +** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so +** sqlite3_stmt_readonly() returns false for those commands. +*/ +SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement +** METHOD: sqlite3_stmt +** +** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the +** prepared statement S is an EXPLAIN statement, or 2 if the +** statement S is an EXPLAIN QUERY PLAN. +** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is +** an ordinary statement or a NULL pointer. +*/ +SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Determine If A Prepared Statement Has Been Reset +** METHOD: sqlite3_stmt +** +** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the +** [prepared statement] S has been stepped at least once using +** [sqlite3_step(S)] but has neither run to completion (returned +** [SQLITE_DONE] from [sqlite3_step(S)]) nor +** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) +** interface returns false if S is a NULL pointer. If S is not a +** NULL pointer and is not a pointer to a valid [prepared statement] +** object, then the behavior is undefined and probably undesirable. +** +** This interface can be used in combination [sqlite3_next_stmt()] +** to locate all prepared statements associated with a database +** connection that are in need of being reset. This can be used, +** for example, in diagnostic routines to search for prepared +** statements that are holding a transaction open. +*/ +SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); + +/* +** CAPI3REF: Dynamically Typed Value Object +** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} +** +** SQLite uses the sqlite3_value object to represent all values +** that can be stored in a database table. SQLite uses dynamic typing +** for the values it stores. ^Values stored in sqlite3_value objects +** can be integers, floating point values, strings, BLOBs, or NULL. +** +** An sqlite3_value object may be either "protected" or "unprotected". +** Some interfaces require a protected sqlite3_value. Other interfaces +** will accept either a protected or an unprotected sqlite3_value. +** Every interface that accepts sqlite3_value arguments specifies +** whether or not it requires a protected sqlite3_value. The +** [sqlite3_value_dup()] interface can be used to construct a new +** protected sqlite3_value from an unprotected sqlite3_value. +** +** The terms "protected" and "unprotected" refer to whether or not +** a mutex is held. An internal mutex is held for a protected +** sqlite3_value object but no mutex is held for an unprotected +** sqlite3_value object. If SQLite is compiled to be single-threaded +** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) +** or if SQLite is run in one of reduced mutex modes +** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] +** then there is no distinction between protected and unprotected +** sqlite3_value objects and they can be used interchangeably. However, +** for maximum code portability it is recommended that applications +** still make the distinction between protected and unprotected +** sqlite3_value objects even when not strictly required. +** +** ^The sqlite3_value objects that are passed as parameters into the +** implementation of [application-defined SQL functions] are protected. +** ^The sqlite3_value object returned by +** [sqlite3_column_value()] is unprotected. +** Unprotected sqlite3_value objects may only be used as arguments +** to [sqlite3_result_value()], [sqlite3_bind_value()], and +** [sqlite3_value_dup()]. +** The [sqlite3_value_blob | sqlite3_value_type()] family of +** interfaces require protected sqlite3_value objects. +*/ +typedef struct sqlite3_value sqlite3_value; + +/* +** CAPI3REF: SQL Function Context Object +** +** The context in which an SQL function executes is stored in an +** sqlite3_context object. ^A pointer to an sqlite3_context object +** is always first parameter to [application-defined SQL functions]. +** The application-defined SQL function implementation will pass this +** pointer through into calls to [sqlite3_result_int | sqlite3_result()], +** [sqlite3_aggregate_context()], [sqlite3_user_data()], +** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], +** and/or [sqlite3_set_auxdata()]. +*/ +typedef struct sqlite3_context sqlite3_context; + +/* +** CAPI3REF: Binding Values To Prepared Statements +** KEYWORDS: {host parameter} {host parameters} {host parameter name} +** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} +** METHOD: sqlite3_stmt +** +** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, +** literals may be replaced by a [parameter] that matches one of following +** templates: +** +** <ul> +** <li> ? +** <li> ?NNN +** <li> :VVV +** <li> @VVV +** <li> $VVV +** </ul> +** +** In the templates above, NNN represents an integer literal, +** and VVV represents an alphanumeric identifier.)^ ^The values of these +** parameters (also called "host parameter names" or "SQL parameters") +** can be set using the sqlite3_bind_*() routines defined here. +** +** ^The first argument to the sqlite3_bind_*() routines is always +** a pointer to the [sqlite3_stmt] object returned from +** [sqlite3_prepare_v2()] or its variants. +** +** ^The second argument is the index of the SQL parameter to be set. +** ^The leftmost SQL parameter has an index of 1. ^When the same named +** SQL parameter is used more than once, second and subsequent +** occurrences have the same index as the first occurrence. +** ^The index for named parameters can be looked up using the +** [sqlite3_bind_parameter_index()] API if desired. ^The index +** for "?NNN" parameters is the value of NNN. +** ^The NNN value must be between 1 and the [sqlite3_limit()] +** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). +** +** ^The third argument is the value to bind to the parameter. +** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() +** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter +** is ignored and the end result is the same as sqlite3_bind_null(). +** +** ^(In those routines that have a fourth argument, its value is the +** number of bytes in the parameter. To be clear: the value is the +** number of <u>bytes</u> in the value, not the number of characters.)^ +** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() +** is negative, then the length of the string is +** the number of bytes up to the first zero terminator. +** If the fourth parameter to sqlite3_bind_blob() is negative, then +** the behavior is undefined. +** If a non-negative fourth parameter is provided to sqlite3_bind_text() +** or sqlite3_bind_text16() or sqlite3_bind_text64() then +** that parameter must be the byte offset +** where the NUL terminator would occur assuming the string were NUL +** terminated. If any NUL characters occur at byte offsets less than +** the value of the fourth parameter then the resulting string value will +** contain embedded NULs. The result of expressions involving strings +** with embedded NULs is undefined. +** +** ^The fifth argument to the BLOB and string binding interfaces +** is a destructor used to dispose of the BLOB or +** string after SQLite has finished with it. ^The destructor is called +** to dispose of the BLOB or string even if the call to the bind API fails, +** except the destructor is not called if the third parameter is a NULL +** pointer or the fourth parameter is negative. +** ^If the fifth argument is +** the special value [SQLITE_STATIC], then SQLite assumes that the +** information is in static, unmanaged space and does not need to be freed. +** ^If the fifth argument has the value [SQLITE_TRANSIENT], then +** SQLite makes its own private copy of the data immediately, before +** the sqlite3_bind_*() routine returns. +** +** ^The sixth argument to sqlite3_bind_text64() must be one of +** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE] +** to specify the encoding of the text in the third parameter. If +** the sixth argument to sqlite3_bind_text64() is not one of the +** allowed values shown above, or if the text encoding is different +** from the encoding specified by the sixth parameter, then the behavior +** is undefined. +** +** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that +** is filled with zeroes. ^A zeroblob uses a fixed amount of memory +** (just an integer to hold its size) while it is being processed. +** Zeroblobs are intended to serve as placeholders for BLOBs whose +** content is later written using +** [sqlite3_blob_open | incremental BLOB I/O] routines. +** ^A negative value for the zeroblob results in a zero-length BLOB. +** +** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in +** [prepared statement] S to have an SQL value of NULL, but to also be +** associated with the pointer P of type T. ^D is either a NULL pointer or +** a pointer to a destructor function for P. ^SQLite will invoke the +** destructor D with a single argument of P when it is finished using +** P. The T parameter should be a static string, preferably a string +** literal. The sqlite3_bind_pointer() routine is part of the +** [pointer passing interface] added for SQLite 3.20.0. +** +** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer +** for the [prepared statement] or with a prepared statement for which +** [sqlite3_step()] has been called more recently than [sqlite3_reset()], +** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() +** routine is passed a [prepared statement] that has been finalized, the +** result is undefined and probably harmful. +** +** ^Bindings are not cleared by the [sqlite3_reset()] routine. +** ^Unbound parameters are interpreted as NULL. +** +** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an +** [error code] if anything goes wrong. +** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB +** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or +** [SQLITE_MAX_LENGTH]. +** ^[SQLITE_RANGE] is returned if the parameter +** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. +** +** See also: [sqlite3_bind_parameter_count()], +** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. +*/ +SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); +SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, + void(*)(void*)); +SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); +SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); +SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); +SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); +SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); +SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, + void(*)(void*), unsigned char encoding); +SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); +SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*)); +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); +SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); + +/* +** CAPI3REF: Number Of SQL Parameters +** METHOD: sqlite3_stmt +** +** ^This routine can be used to find the number of [SQL parameters] +** in a [prepared statement]. SQL parameters are tokens of the +** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as +** placeholders for values that are [sqlite3_bind_blob | bound] +** to the parameters at a later time. +** +** ^(This routine actually returns the index of the largest (rightmost) +** parameter. For all forms except ?NNN, this will correspond to the +** number of unique parameters. If parameters of the ?NNN form are used, +** there may be gaps in the list.)^ +** +** See also: [sqlite3_bind_blob|sqlite3_bind()], +** [sqlite3_bind_parameter_name()], and +** [sqlite3_bind_parameter_index()]. +*/ +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); + +/* +** CAPI3REF: Name Of A Host Parameter +** METHOD: sqlite3_stmt +** +** ^The sqlite3_bind_parameter_name(P,N) interface returns +** the name of the N-th [SQL parameter] in the [prepared statement] P. +** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" +** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" +** respectively. +** In other words, the initial ":" or "$" or "@" or "?" +** is included as part of the name.)^ +** ^Parameters of the form "?" without a following integer have no name +** and are referred to as "nameless" or "anonymous parameters". +** +** ^The first host parameter has an index of 1, not 0. +** +** ^If the value N is out of range or if the N-th parameter is +** nameless, then NULL is returned. ^The returned string is +** always in UTF-8 encoding even if the named parameter was +** originally specified as UTF-16 in [sqlite3_prepare16()], +** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. +** +** See also: [sqlite3_bind_blob|sqlite3_bind()], +** [sqlite3_bind_parameter_count()], and +** [sqlite3_bind_parameter_index()]. +*/ +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); + +/* +** CAPI3REF: Index Of A Parameter With A Given Name +** METHOD: sqlite3_stmt +** +** ^Return the index of an SQL parameter given its name. ^The +** index value returned is suitable for use as the second +** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero +** is returned if no matching parameter is found. ^The parameter +** name must be given in UTF-8 even if the original statement +** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or +** [sqlite3_prepare16_v3()]. +** +** See also: [sqlite3_bind_blob|sqlite3_bind()], +** [sqlite3_bind_parameter_count()], and +** [sqlite3_bind_parameter_name()]. +*/ +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); + +/* +** CAPI3REF: Reset All Bindings On A Prepared Statement +** METHOD: sqlite3_stmt +** +** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset +** the [sqlite3_bind_blob | bindings] on a [prepared statement]. +** ^Use this routine to reset all host parameters to NULL. +*/ +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); + +/* +** CAPI3REF: Number Of Columns In A Result Set +** METHOD: sqlite3_stmt +** +** ^Return the number of columns in the result set returned by the +** [prepared statement]. ^If this routine returns 0, that means the +** [prepared statement] returns no data (for example an [UPDATE]). +** ^However, just because this routine returns a positive number does not +** mean that one or more rows of data will be returned. ^A SELECT statement +** will always have a positive sqlite3_column_count() but depending on the +** WHERE clause constraints and the table content, it might return no rows. +** +** See also: [sqlite3_data_count()] +*/ +SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Column Names In A Result Set +** METHOD: sqlite3_stmt +** +** ^These routines return the name assigned to a particular column +** in the result set of a [SELECT] statement. ^The sqlite3_column_name() +** interface returns a pointer to a zero-terminated UTF-8 string +** and sqlite3_column_name16() returns a pointer to a zero-terminated +** UTF-16 string. ^The first parameter is the [prepared statement] +** that implements the [SELECT] statement. ^The second parameter is the +** column number. ^The leftmost column is number 0. +** +** ^The returned string pointer is valid until either the [prepared statement] +** is destroyed by [sqlite3_finalize()] or until the statement is automatically +** reprepared by the first call to [sqlite3_step()] for a particular run +** or until the next call to +** sqlite3_column_name() or sqlite3_column_name16() on the same column. +** +** ^If sqlite3_malloc() fails during the processing of either routine +** (for example during a conversion from UTF-8 to UTF-16) then a +** NULL pointer is returned. +** +** ^The name of a result column is the value of the "AS" clause for +** that column, if there is an AS clause. If there is no AS clause +** then the name of the column is unspecified and may change from +** one release of SQLite to the next. +*/ +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); + +/* +** CAPI3REF: Source Of Data In A Query Result +** METHOD: sqlite3_stmt +** +** ^These routines provide a means to determine the database, table, and +** table column that is the origin of a particular result column in +** [SELECT] statement. +** ^The name of the database or table or column can be returned as +** either a UTF-8 or UTF-16 string. ^The _database_ routines return +** the database name, the _table_ routines return the table name, and +** the origin_ routines return the column name. +** ^The returned string is valid until the [prepared statement] is destroyed +** using [sqlite3_finalize()] or until the statement is automatically +** reprepared by the first call to [sqlite3_step()] for a particular run +** or until the same information is requested +** again in a different encoding. +** +** ^The names returned are the original un-aliased names of the +** database, table, and column. +** +** ^The first argument to these interfaces is a [prepared statement]. +** ^These functions return information about the Nth result column returned by +** the statement, where N is the second function argument. +** ^The left-most column is column 0 for these routines. +** +** ^If the Nth column returned by the statement is an expression or +** subquery and is not a column value, then all of these functions return +** NULL. ^These routine might also return NULL if a memory allocation error +** occurs. ^Otherwise, they return the name of the attached database, table, +** or column that query result column was extracted from. +** +** ^As with all other SQLite APIs, those whose names end with "16" return +** UTF-16 encoded strings and the other functions return UTF-8. +** +** ^These APIs are only available if the library was compiled with the +** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. +** +** If two or more threads call one or more of these routines against the same +** prepared statement and column at the same time then the results are +** undefined. +** +** If two or more threads call one or more +** [sqlite3_column_database_name | column metadata interfaces] +** for the same [prepared statement] and result column +** at the same time then the results are undefined. +*/ +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); + +/* +** CAPI3REF: Declared Datatype Of A Query Result +** METHOD: sqlite3_stmt +** +** ^(The first parameter is a [prepared statement]. +** If this statement is a [SELECT] statement and the Nth column of the +** returned result set of that [SELECT] is a table column (not an +** expression or subquery) then the declared type of the table +** column is returned.)^ ^If the Nth column of the result set is an +** expression or subquery, then a NULL pointer is returned. +** ^The returned string is always UTF-8 encoded. +** +** ^(For example, given the database schema: +** +** CREATE TABLE t1(c1 VARIANT); +** +** and the following statement to be compiled: +** +** SELECT c1 + 1, c1 FROM t1; +** +** this routine would return the string "VARIANT" for the second result +** column (i==1), and a NULL pointer for the first result column (i==0).)^ +** +** ^SQLite uses dynamic run-time typing. ^So just because a column +** is declared to contain a particular type does not mean that the +** data stored in that column is of the declared type. SQLite is +** strongly typed, but the typing is dynamic not static. ^Type +** is associated with individual values, not with the containers +** used to hold those values. +*/ +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); + +/* +** CAPI3REF: Evaluate An SQL Statement +** METHOD: sqlite3_stmt +** +** After a [prepared statement] has been prepared using any of +** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()], +** or [sqlite3_prepare16_v3()] or one of the legacy +** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function +** must be called one or more times to evaluate the statement. +** +** The details of the behavior of the sqlite3_step() interface depend +** on whether the statement was prepared using the newer "vX" interfaces +** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()], +** [sqlite3_prepare16_v2()] or the older legacy +** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the +** new "vX" interface is recommended for new applications but the legacy +** interface will continue to be supported. +** +** ^In the legacy interface, the return value will be either [SQLITE_BUSY], +** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. +** ^With the "v2" interface, any of the other [result codes] or +** [extended result codes] might be returned as well. +** +** ^[SQLITE_BUSY] means that the database engine was unable to acquire the +** database locks it needs to do its job. ^If the statement is a [COMMIT] +** or occurs outside of an explicit transaction, then you can retry the +** statement. If the statement is not a [COMMIT] and occurs within an +** explicit transaction then you should rollback the transaction before +** continuing. +** +** ^[SQLITE_DONE] means that the statement has finished executing +** successfully. sqlite3_step() should not be called again on this virtual +** machine without first calling [sqlite3_reset()] to reset the virtual +** machine back to its initial state. +** +** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] +** is returned each time a new row of data is ready for processing by the +** caller. The values may be accessed using the [column access functions]. +** sqlite3_step() is called again to retrieve the next row of data. +** +** ^[SQLITE_ERROR] means that a run-time error (such as a constraint +** violation) has occurred. sqlite3_step() should not be called again on +** the VM. More information may be found by calling [sqlite3_errmsg()]. +** ^With the legacy interface, a more specific error code (for example, +** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) +** can be obtained by calling [sqlite3_reset()] on the +** [prepared statement]. ^In the "v2" interface, +** the more specific error code is returned directly by sqlite3_step(). +** +** [SQLITE_MISUSE] means that the this routine was called inappropriately. +** Perhaps it was called on a [prepared statement] that has +** already been [sqlite3_finalize | finalized] or on one that had +** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could +** be the case that the same database connection is being used by two or +** more threads at the same moment in time. +** +** For all versions of SQLite up to and including 3.6.23.1, a call to +** [sqlite3_reset()] was required after sqlite3_step() returned anything +** other than [SQLITE_ROW] before any subsequent invocation of +** sqlite3_step(). Failure to reset the prepared statement using +** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from +** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1], +** sqlite3_step() began +** calling [sqlite3_reset()] automatically in this circumstance rather +** than returning [SQLITE_MISUSE]. This is not considered a compatibility +** break because any application that ever receives an SQLITE_MISUSE error +** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option +** can be used to restore the legacy behavior. +** +** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() +** API always returns a generic error code, [SQLITE_ERROR], following any +** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call +** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the +** specific [error codes] that better describes the error. +** We admit that this is a goofy design. The problem has been fixed +** with the "v2" interface. If you prepare all of your SQL statements +** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()] +** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead +** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, +** then the more specific [error codes] are returned directly +** by sqlite3_step(). The use of the "vX" interfaces is recommended. +*/ +SQLITE_API int sqlite3_step(sqlite3_stmt*); + +/* +** CAPI3REF: Number of columns in a result set +** METHOD: sqlite3_stmt +** +** ^The sqlite3_data_count(P) interface returns the number of columns in the +** current row of the result set of [prepared statement] P. +** ^If prepared statement P does not have results ready to return +** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of +** interfaces) then sqlite3_data_count(P) returns 0. +** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. +** ^The sqlite3_data_count(P) routine returns 0 if the previous call to +** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) +** will return non-zero if previous call to [sqlite3_step](P) returned +** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] +** where it always returns zero since each step of that multi-step +** pragma returns 0 columns of data. +** +** See also: [sqlite3_column_count()] +*/ +SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Fundamental Datatypes +** KEYWORDS: SQLITE_TEXT +** +** ^(Every value in SQLite has one of five fundamental datatypes: +** +** <ul> +** <li> 64-bit signed integer +** <li> 64-bit IEEE floating point number +** <li> string +** <li> BLOB +** <li> NULL +** </ul>)^ +** +** These constants are codes for each of those types. +** +** Note that the SQLITE_TEXT constant was also used in SQLite version 2 +** for a completely different meaning. Software that links against both +** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not +** SQLITE_TEXT. +*/ +#define SQLITE_INTEGER 1 +#define SQLITE_FLOAT 2 +#define SQLITE_BLOB 4 +#define SQLITE_NULL 5 +#ifdef SQLITE_TEXT +# undef SQLITE_TEXT +#else +# define SQLITE_TEXT 3 +#endif +#define SQLITE3_TEXT 3 + +/* +** CAPI3REF: Result Values From A Query +** KEYWORDS: {column access functions} +** METHOD: sqlite3_stmt +** +** <b>Summary:</b> +** <blockquote><table border=0 cellpadding=0 cellspacing=0> +** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result +** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result +** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result +** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result +** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result +** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result +** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an +** [sqlite3_value|unprotected sqlite3_value] object. +** <tr><td> <td> <td>  +** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB +** or a UTF-8 TEXT result in bytes +** <tr><td><b>sqlite3_column_bytes16  </b> +** <td>→  <td>Size of UTF-16 +** TEXT in bytes +** <tr><td><b>sqlite3_column_type</b><td>→<td>Default +** datatype of the result +** </table></blockquote> +** +** <b>Details:</b> +** +** ^These routines return information about a single column of the current +** result row of a query. ^In every case the first argument is a pointer +** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] +** that was returned from [sqlite3_prepare_v2()] or one of its variants) +** and the second argument is the index of the column for which information +** should be returned. ^The leftmost column of the result set has the index 0. +** ^The number of columns in the result can be determined using +** [sqlite3_column_count()]. +** +** If the SQL statement does not currently point to a valid row, or if the +** column index is out of range, the result is undefined. +** These routines may only be called when the most recent call to +** [sqlite3_step()] has returned [SQLITE_ROW] and neither +** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. +** If any of these routines are called after [sqlite3_reset()] or +** [sqlite3_finalize()] or after [sqlite3_step()] has returned +** something other than [SQLITE_ROW], the results are undefined. +** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] +** are called from a different thread while any of these routines +** are pending, then the results are undefined. +** +** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16) +** each return the value of a result column in a specific data format. If +** the result column is not initially in the requested format (for example, +** if the query returns an integer but the sqlite3_column_text() interface +** is used to extract the value) then an automatic type conversion is performed. +** +** ^The sqlite3_column_type() routine returns the +** [SQLITE_INTEGER | datatype code] for the initial data type +** of the result column. ^The returned value is one of [SQLITE_INTEGER], +** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. +** The return value of sqlite3_column_type() can be used to decide which +** of the first six interface should be used to extract the column value. +** The value returned by sqlite3_column_type() is only meaningful if no +** automatic type conversions have occurred for the value in question. +** After a type conversion, the result of calling sqlite3_column_type() +** is undefined, though harmless. Future +** versions of SQLite may change the behavior of sqlite3_column_type() +** following a type conversion. +** +** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes() +** or sqlite3_column_bytes16() interfaces can be used to determine the size +** of that BLOB or string. +** +** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() +** routine returns the number of bytes in that BLOB or string. +** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts +** the string to UTF-8 and then returns the number of bytes. +** ^If the result is a numeric value then sqlite3_column_bytes() uses +** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns +** the number of bytes in that string. +** ^If the result is NULL, then sqlite3_column_bytes() returns zero. +** +** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() +** routine returns the number of bytes in that BLOB or string. +** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts +** the string to UTF-16 and then returns the number of bytes. +** ^If the result is a numeric value then sqlite3_column_bytes16() uses +** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns +** the number of bytes in that string. +** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. +** +** ^The values returned by [sqlite3_column_bytes()] and +** [sqlite3_column_bytes16()] do not include the zero terminators at the end +** of the string. ^For clarity: the values returned by +** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of +** bytes in the string, not the number of characters. +** +** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), +** even empty strings, are always zero-terminated. ^The return +** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. +** +** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an +** [unprotected sqlite3_value] object. In a multithreaded environment, +** an unprotected sqlite3_value object may only be used safely with +** [sqlite3_bind_value()] and [sqlite3_result_value()]. +** If the [unprotected sqlite3_value] object returned by +** [sqlite3_column_value()] is used in any other way, including calls +** to routines like [sqlite3_value_int()], [sqlite3_value_text()], +** or [sqlite3_value_bytes()], the behavior is not threadsafe. +** Hence, the sqlite3_column_value() interface +** is normally only useful within the implementation of +** [application-defined SQL functions] or [virtual tables], not within +** top-level application code. +** +** The these routines may attempt to convert the datatype of the result. +** ^For example, if the internal representation is FLOAT and a text result +** is requested, [sqlite3_snprintf()] is used internally to perform the +** conversion automatically. ^(The following table details the conversions +** that are applied: +** +** <blockquote> +** <table border="1"> +** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion +** +** <tr><td> NULL <td> INTEGER <td> Result is 0 +** <tr><td> NULL <td> FLOAT <td> Result is 0.0 +** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer +** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer +** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float +** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer +** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT +** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER +** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float +** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB +** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER +** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL +** <tr><td> TEXT <td> BLOB <td> No change +** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER +** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL +** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed +** </table> +** </blockquote>)^ +** +** Note that when type conversions occur, pointers returned by prior +** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or +** sqlite3_column_text16() may be invalidated. +** Type conversions and pointer invalidations might occur +** in the following cases: +** +** <ul> +** <li> The initial content is a BLOB and sqlite3_column_text() or +** sqlite3_column_text16() is called. A zero-terminator might +** need to be added to the string.</li> +** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or +** sqlite3_column_text16() is called. The content must be converted +** to UTF-16.</li> +** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or +** sqlite3_column_text() is called. The content must be converted +** to UTF-8.</li> +** </ul> +** +** ^Conversions between UTF-16be and UTF-16le are always done in place and do +** not invalidate a prior pointer, though of course the content of the buffer +** that the prior pointer references will have been modified. Other kinds +** of conversion are done in place when it is possible, but sometimes they +** are not possible and in those cases prior pointers are invalidated. +** +** The safest policy is to invoke these routines +** in one of the following ways: +** +** <ul> +** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> +** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> +** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> +** </ul> +** +** In other words, you should call sqlite3_column_text(), +** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result +** into the desired format, then invoke sqlite3_column_bytes() or +** sqlite3_column_bytes16() to find the size of the result. Do not mix calls +** to sqlite3_column_text() or sqlite3_column_blob() with calls to +** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() +** with calls to sqlite3_column_bytes(). +** +** ^The pointers returned are valid until a type conversion occurs as +** described above, or until [sqlite3_step()] or [sqlite3_reset()] or +** [sqlite3_finalize()] is called. ^The memory space used to hold strings +** and BLOBs is freed automatically. Do not pass the pointers returned +** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into +** [sqlite3_free()]. +** +** As long as the input parameters are correct, these routines will only +** fail if an out-of-memory error occurs during a format conversion. +** Only the following subset of interfaces are subject to out-of-memory +** errors: +** +** <ul> +** <li> sqlite3_column_blob() +** <li> sqlite3_column_text() +** <li> sqlite3_column_text16() +** <li> sqlite3_column_bytes() +** <li> sqlite3_column_bytes16() +** </ul> +** +** If an out-of-memory error occurs, then the return value from these +** routines is the same as if the column had contained an SQL NULL value. +** Valid SQL NULL returns can be distinguished from out-of-memory errors +** by invoking the [sqlite3_errcode()] immediately after the suspect +** return value is obtained and before any +** other SQLite interface is called on the same [database connection]. +*/ +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); +SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); +SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); +SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); +SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); + +/* +** CAPI3REF: Destroy A Prepared Statement Object +** DESTRUCTOR: sqlite3_stmt +** +** ^The sqlite3_finalize() function is called to delete a [prepared statement]. +** ^If the most recent evaluation of the statement encountered no errors +** or if the statement is never been evaluated, then sqlite3_finalize() returns +** SQLITE_OK. ^If the most recent evaluation of statement S failed, then +** sqlite3_finalize(S) returns the appropriate [error code] or +** [extended error code]. +** +** ^The sqlite3_finalize(S) routine can be called at any point during +** the life cycle of [prepared statement] S: +** before statement S is ever evaluated, after +** one or more calls to [sqlite3_reset()], or after any call +** to [sqlite3_step()] regardless of whether or not the statement has +** completed execution. +** +** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. +** +** The application must finalize every [prepared statement] in order to avoid +** resource leaks. It is a grievous error for the application to try to use +** a prepared statement after it has been finalized. Any use of a prepared +** statement after it has been finalized can result in undefined and +** undesirable behavior such as segfaults and heap corruption. +*/ +SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Reset A Prepared Statement Object +** METHOD: sqlite3_stmt +** +** The sqlite3_reset() function is called to reset a [prepared statement] +** object back to its initial state, ready to be re-executed. +** ^Any SQL statement variables that had values bound to them using +** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. +** Use [sqlite3_clear_bindings()] to reset the bindings. +** +** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S +** back to the beginning of its program. +** +** ^If the most recent call to [sqlite3_step(S)] for the +** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], +** or if [sqlite3_step(S)] has never before been called on S, +** then [sqlite3_reset(S)] returns [SQLITE_OK]. +** +** ^If the most recent call to [sqlite3_step(S)] for the +** [prepared statement] S indicated an error, then +** [sqlite3_reset(S)] returns an appropriate [error code]. +** +** ^The [sqlite3_reset(S)] interface does not change the values +** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. +*/ +SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Create Or Redefine SQL Functions +** KEYWORDS: {function creation routines} +** KEYWORDS: {application-defined SQL function} +** KEYWORDS: {application-defined SQL functions} +** METHOD: sqlite3 +** +** ^These functions (collectively known as "function creation routines") +** are used to add SQL functions or aggregates or to redefine the behavior +** of existing SQL functions or aggregates. The only differences between +** the three "sqlite3_create_function*" routines are the text encoding +** expected for the second parameter (the name of the function being +** created) and the presence or absence of a destructor callback for +** the application data pointer. Function sqlite3_create_window_function() +** is similar, but allows the user to supply the extra callback functions +** needed by [aggregate window functions]. +** +** ^The first parameter is the [database connection] to which the SQL +** function is to be added. ^If an application uses more than one database +** connection then application-defined SQL functions must be added +** to each database connection separately. +** +** ^The second parameter is the name of the SQL function to be created or +** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 +** representation, exclusive of the zero-terminator. ^Note that the name +** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. +** ^Any attempt to create a function with a longer name +** will result in [SQLITE_MISUSE] being returned. +** +** ^The third parameter (nArg) +** is the number of arguments that the SQL function or +** aggregate takes. ^If this parameter is -1, then the SQL function or +** aggregate may take any number of arguments between 0 and the limit +** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third +** parameter is less than -1 or greater than 127 then the behavior is +** undefined. +** +** ^The fourth parameter, eTextRep, specifies what +** [SQLITE_UTF8 | text encoding] this SQL function prefers for +** its parameters. The application should set this parameter to +** [SQLITE_UTF16LE] if the function implementation invokes +** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the +** implementation invokes [sqlite3_value_text16be()] on an input, or +** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] +** otherwise. ^The same SQL function may be registered multiple times using +** different preferred text encodings, with different implementations for +** each encoding. +** ^When multiple implementations of the same function are available, SQLite +** will pick the one that involves the least amount of data conversion. +** +** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] +** to signal that the function will always return the same result given +** the same inputs within a single SQL statement. Most SQL functions are +** deterministic. The built-in [random()] SQL function is an example of a +** function that is not deterministic. The SQLite query planner is able to +** perform additional optimizations on deterministic functions, so use +** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. +** +** ^(The fifth parameter is an arbitrary pointer. The implementation of the +** function can gain access to this pointer using [sqlite3_user_data()].)^ +** +** ^The sixth, seventh and eighth parameters passed to the three +** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are +** pointers to C-language functions that implement the SQL function or +** aggregate. ^A scalar SQL function requires an implementation of the xFunc +** callback only; NULL pointers must be passed as the xStep and xFinal +** parameters. ^An aggregate SQL function requires an implementation of xStep +** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing +** SQL function or aggregate, pass NULL pointers for all three function +** callbacks. +** +** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue +** and xInverse) passed to sqlite3_create_window_function are pointers to +** C-language callbacks that implement the new function. xStep and xFinal +** must both be non-NULL. xValue and xInverse may either both be NULL, in +** which case a regular aggregate function is created, or must both be +** non-NULL, in which case the new function may be used as either an aggregate +** or aggregate window function. More details regarding the implementation +** of aggregate window functions are +** [user-defined window functions|available here]. +** +** ^(If the final parameter to sqlite3_create_function_v2() or +** sqlite3_create_window_function() is not NULL, then it is destructor for +** the application data pointer. The destructor is invoked when the function +** is deleted, either by being overloaded or when the database connection +** closes.)^ ^The destructor is also invoked if the call to +** sqlite3_create_function_v2() fails. ^When the destructor callback is +** invoked, it is passed a single argument which is a copy of the application +** data pointer which was the fifth parameter to sqlite3_create_function_v2(). +** +** ^It is permitted to register multiple implementations of the same +** functions with the same name but with either differing numbers of +** arguments or differing preferred text encodings. ^SQLite will use +** the implementation that most closely matches the way in which the +** SQL function is used. ^A function implementation with a non-negative +** nArg parameter is a better match than a function implementation with +** a negative nArg. ^A function where the preferred text encoding +** matches the database encoding is a better +** match than a function where the encoding is different. +** ^A function where the encoding difference is between UTF16le and UTF16be +** is a closer match than a function where the encoding difference is +** between UTF8 and UTF16. +** +** ^Built-in functions may be overloaded by new application-defined functions. +** +** ^An application-defined function is permitted to call other +** SQLite interfaces. However, such calls must not +** close the database connection nor finalize or reset the prepared +** statement in which the function is running. +*/ +SQLITE_API int sqlite3_create_function( + sqlite3 *db, + const char *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*) +); +SQLITE_API int sqlite3_create_function16( + sqlite3 *db, + const void *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*) +); +SQLITE_API int sqlite3_create_function_v2( + sqlite3 *db, + const char *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*), + void(*xDestroy)(void*) +); +SQLITE_API int sqlite3_create_window_function( + sqlite3 *db, + const char *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*), + void (*xValue)(sqlite3_context*), + void (*xInverse)(sqlite3_context*,int,sqlite3_value**), + void(*xDestroy)(void*) +); + +/* +** CAPI3REF: Text Encodings +** +** These constant define integer codes that represent the various +** text encodings supported by SQLite. +*/ +#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ +#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ +#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ +#define SQLITE_UTF16 4 /* Use native byte order */ +#define SQLITE_ANY 5 /* Deprecated */ +#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ + +/* +** CAPI3REF: Function Flags +** +** These constants may be ORed together with the +** [SQLITE_UTF8 | preferred text encoding] as the fourth argument +** to [sqlite3_create_function()], [sqlite3_create_function16()], or +** [sqlite3_create_function_v2()]. +*/ +#define SQLITE_DETERMINISTIC 0x800 + +/* +** CAPI3REF: Deprecated Functions +** DEPRECATED +** +** These functions are [deprecated]. In order to maintain +** backwards compatibility with older code, these functions continue +** to be supported. However, new applications should avoid +** the use of these functions. To encourage programmers to avoid +** these functions, we will not explain what they do. +*/ +#ifndef SQLITE_OMIT_DEPRECATED +SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); +SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); +SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); +SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); +SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); +SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), + void*,sqlite3_int64); +#endif + +/* +** CAPI3REF: Obtaining SQL Values +** METHOD: sqlite3_value +** +** <b>Summary:</b> +** <blockquote><table border=0 cellpadding=0 cellspacing=0> +** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value +** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value +** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value +** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value +** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value +** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value +** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in +** the native byteorder +** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value +** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value +** <tr><td> <td> <td>  +** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB +** or a UTF-8 TEXT in bytes +** <tr><td><b>sqlite3_value_bytes16  </b> +** <td>→  <td>Size of UTF-16 +** TEXT in bytes +** <tr><td><b>sqlite3_value_type</b><td>→<td>Default +** datatype of the value +** <tr><td><b>sqlite3_value_numeric_type  </b> +** <td>→  <td>Best numeric datatype of the value +** <tr><td><b>sqlite3_value_nochange  </b> +** <td>→  <td>True if the column is unchanged in an UPDATE +** against a virtual table. +** <tr><td><b>sqlite3_value_frombind  </b> +** <td>→  <td>True if value originated from a [bound parameter] +** </table></blockquote> +** +** <b>Details:</b> +** +** These routines extract type, size, and content information from +** [protected sqlite3_value] objects. Protected sqlite3_value objects +** are used to pass parameter information into implementation of +** [application-defined SQL functions] and [virtual tables]. +** +** These routines work only with [protected sqlite3_value] objects. +** Any attempt to use these routines on an [unprotected sqlite3_value] +** is not threadsafe. +** +** ^These routines work just like the corresponding [column access functions] +** except that these routines take a single [protected sqlite3_value] object +** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. +** +** ^The sqlite3_value_text16() interface extracts a UTF-16 string +** in the native byte-order of the host machine. ^The +** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces +** extract UTF-16 strings as big-endian and little-endian respectively. +** +** ^If [sqlite3_value] object V was initialized +** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)] +** and if X and Y are strings that compare equal according to strcmp(X,Y), +** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise, +** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer() +** routine is part of the [pointer passing interface] added for SQLite 3.20.0. +** +** ^(The sqlite3_value_type(V) interface returns the +** [SQLITE_INTEGER | datatype code] for the initial datatype of the +** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER], +** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^ +** Other interfaces might change the datatype for an sqlite3_value object. +** For example, if the datatype is initially SQLITE_INTEGER and +** sqlite3_value_text(V) is called to extract a text value for that +** integer, then subsequent calls to sqlite3_value_type(V) might return +** SQLITE_TEXT. Whether or not a persistent internal datatype conversion +** occurs is undefined and may change from one release of SQLite to the next. +** +** ^(The sqlite3_value_numeric_type() interface attempts to apply +** numeric affinity to the value. This means that an attempt is +** made to convert the value to an integer or floating point. If +** such a conversion is possible without loss of information (in other +** words, if the value is a string that looks like a number) +** then the conversion is performed. Otherwise no conversion occurs. +** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ +** +** ^Within the [xUpdate] method of a [virtual table], the +** sqlite3_value_nochange(X) interface returns true if and only if +** the column corresponding to X is unchanged by the UPDATE operation +** that the xUpdate method call was invoked to implement and if +** and the prior [xColumn] method call that was invoked to extracted +** the value for that column returned without setting a result (probably +** because it queried [sqlite3_vtab_nochange()] and found that the column +** was unchanging). ^Within an [xUpdate] method, any value for which +** sqlite3_value_nochange(X) is true will in all other respects appear +** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other +** than within an [xUpdate] method call for an UPDATE statement, then +** the return value is arbitrary and meaningless. +** +** ^The sqlite3_value_frombind(X) interface returns non-zero if the +** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()] +** interfaces. ^If X comes from an SQL literal value, or a table column, +** and expression, then sqlite3_value_frombind(X) returns zero. +** +** Please pay particular attention to the fact that the pointer returned +** from [sqlite3_value_blob()], [sqlite3_value_text()], or +** [sqlite3_value_text16()] can be invalidated by a subsequent call to +** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], +** or [sqlite3_value_text16()]. +** +** These routines must be called from the same thread as +** the SQL function that supplied the [sqlite3_value*] parameters. +** +** As long as the input parameter is correct, these routines can only +** fail if an out-of-memory error occurs during a format conversion. +** Only the following subset of interfaces are subject to out-of-memory +** errors: +** +** <ul> +** <li> sqlite3_value_blob() +** <li> sqlite3_value_text() +** <li> sqlite3_value_text16() +** <li> sqlite3_value_text16le() +** <li> sqlite3_value_text16be() +** <li> sqlite3_value_bytes() +** <li> sqlite3_value_bytes16() +** </ul> +** +** If an out-of-memory error occurs, then the return value from these +** routines is the same as if the column had contained an SQL NULL value. +** Valid SQL NULL returns can be distinguished from out-of-memory errors +** by invoking the [sqlite3_errcode()] immediately after the suspect +** return value is obtained and before any +** other SQLite interface is called on the same [database connection]. +*/ +SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); +SQLITE_API double sqlite3_value_double(sqlite3_value*); +SQLITE_API int sqlite3_value_int(sqlite3_value*); +SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); +SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*); +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); +SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); +SQLITE_API int sqlite3_value_bytes(sqlite3_value*); +SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); +SQLITE_API int sqlite3_value_type(sqlite3_value*); +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); +SQLITE_API int sqlite3_value_nochange(sqlite3_value*); +SQLITE_API int sqlite3_value_frombind(sqlite3_value*); + +/* +** CAPI3REF: Finding The Subtype Of SQL Values +** METHOD: sqlite3_value +** +** The sqlite3_value_subtype(V) function returns the subtype for +** an [application-defined SQL function] argument V. The subtype +** information can be used to pass a limited amount of context from +** one SQL function to another. Use the [sqlite3_result_subtype()] +** routine to set the subtype for the return value of an SQL function. +*/ +SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); + +/* +** CAPI3REF: Copy And Free SQL Values +** METHOD: sqlite3_value +** +** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] +** object D and returns a pointer to that copy. ^The [sqlite3_value] returned +** is a [protected sqlite3_value] object even if the input is not. +** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a +** memory allocation fails. +** +** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object +** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer +** then sqlite3_value_free(V) is a harmless no-op. +*/ +SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*); +SQLITE_API void sqlite3_value_free(sqlite3_value*); + +/* +** CAPI3REF: Obtain Aggregate Function Context +** METHOD: sqlite3_context +** +** Implementations of aggregate SQL functions use this +** routine to allocate memory for storing their state. +** +** ^The first time the sqlite3_aggregate_context(C,N) routine is called +** for a particular aggregate function, SQLite +** allocates N of memory, zeroes out that memory, and returns a pointer +** to the new memory. ^On second and subsequent calls to +** sqlite3_aggregate_context() for the same aggregate function instance, +** the same buffer is returned. Sqlite3_aggregate_context() is normally +** called once for each invocation of the xStep callback and then one +** last time when the xFinal callback is invoked. ^(When no rows match +** an aggregate query, the xStep() callback of the aggregate function +** implementation is never called and xFinal() is called exactly once. +** In those cases, sqlite3_aggregate_context() might be called for the +** first time from within xFinal().)^ +** +** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer +** when first called if N is less than or equal to zero or if a memory +** allocate error occurs. +** +** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is +** determined by the N parameter on first successful call. Changing the +** value of N in subsequent call to sqlite3_aggregate_context() within +** the same aggregate function instance will not resize the memory +** allocation.)^ Within the xFinal callback, it is customary to set +** N=0 in calls to sqlite3_aggregate_context(C,N) so that no +** pointless memory allocations occur. +** +** ^SQLite automatically frees the memory allocated by +** sqlite3_aggregate_context() when the aggregate query concludes. +** +** The first parameter must be a copy of the +** [sqlite3_context | SQL function context] that is the first parameter +** to the xStep or xFinal callback routine that implements the aggregate +** function. +** +** This routine must be called from the same thread in which +** the aggregate SQL function is running. +*/ +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); + +/* +** CAPI3REF: User Data For Functions +** METHOD: sqlite3_context +** +** ^The sqlite3_user_data() interface returns a copy of +** the pointer that was the pUserData parameter (the 5th parameter) +** of the [sqlite3_create_function()] +** and [sqlite3_create_function16()] routines that originally +** registered the application defined function. +** +** This routine must be called from the same thread in which +** the application-defined function is running. +*/ +SQLITE_API void *sqlite3_user_data(sqlite3_context*); + +/* +** CAPI3REF: Database Connection For Functions +** METHOD: sqlite3_context +** +** ^The sqlite3_context_db_handle() interface returns a copy of +** the pointer to the [database connection] (the 1st parameter) +** of the [sqlite3_create_function()] +** and [sqlite3_create_function16()] routines that originally +** registered the application defined function. +*/ +SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); + +/* +** CAPI3REF: Function Auxiliary Data +** METHOD: sqlite3_context +** +** These functions may be used by (non-aggregate) SQL functions to +** associate metadata with argument values. If the same value is passed to +** multiple invocations of the same SQL function during query execution, under +** some circumstances the associated metadata may be preserved. An example +** of where this might be useful is in a regular-expression matching +** function. The compiled version of the regular expression can be stored as +** metadata associated with the pattern string. +** Then as long as the pattern string remains the same, +** the compiled regular expression can be reused on multiple +** invocations of the same function. +** +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument +** value to the application-defined function. ^N is zero for the left-most +** function argument. ^If there is no metadata +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface +** returns a NULL pointer. +** +** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th +** argument of the application-defined function. ^Subsequent +** calls to sqlite3_get_auxdata(C,N) return P from the most recent +** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or +** NULL if the metadata has been discarded. +** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL, +** SQLite will invoke the destructor function X with parameter P exactly +** once, when the metadata is discarded. +** SQLite is free to discard the metadata at any time, including: <ul> +** <li> ^(when the corresponding function parameter changes)^, or +** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the +** SQL statement)^, or +** <li> ^(when sqlite3_set_auxdata() is invoked again on the same +** parameter)^, or +** <li> ^(during the original sqlite3_set_auxdata() call when a memory +** allocation error occurs.)^ </ul> +** +** Note the last bullet in particular. The destructor X in +** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the +** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata() +** should be called near the end of the function implementation and the +** function implementation should not make any use of P after +** sqlite3_set_auxdata() has been called. +** +** ^(In practice, metadata is preserved between function calls for +** function parameters that are compile-time constants, including literal +** values and [parameters] and expressions composed from the same.)^ +** +** The value of the N parameter to these interfaces should be non-negative. +** Future enhancements may make use of negative N values to define new +** kinds of function caching behavior. +** +** These routines must be called from the same thread in which +** the SQL function is running. +*/ +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); +SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); + + +/* +** CAPI3REF: Constants Defining Special Destructor Behavior +** +** These are special values for the destructor that is passed in as the +** final argument to routines like [sqlite3_result_blob()]. ^If the destructor +** argument is SQLITE_STATIC, it means that the content pointer is constant +** and will never change. It does not need to be destroyed. ^The +** SQLITE_TRANSIENT value means that the content will likely change in +** the near future and that SQLite should make its own private copy of +** the content before returning. +** +** The typedef is necessary to work around problems in certain +** C++ compilers. +*/ +typedef void (*sqlite3_destructor_type)(void*); +#define SQLITE_STATIC ((sqlite3_destructor_type)0) +#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) + +/* +** CAPI3REF: Setting The Result Of An SQL Function +** METHOD: sqlite3_context +** +** These routines are used by the xFunc or xFinal callbacks that +** implement SQL functions and aggregates. See +** [sqlite3_create_function()] and [sqlite3_create_function16()] +** for additional information. +** +** These functions work very much like the [parameter binding] family of +** functions used to bind values to host parameters in prepared statements. +** Refer to the [SQL parameter] documentation for additional information. +** +** ^The sqlite3_result_blob() interface sets the result from +** an application-defined function to be the BLOB whose content is pointed +** to by the second parameter and which is N bytes long where N is the +** third parameter. +** +** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N) +** interfaces set the result of the application-defined function to be +** a BLOB containing all zero bytes and N bytes in size. +** +** ^The sqlite3_result_double() interface sets the result from +** an application-defined function to be a floating point value specified +** by its 2nd argument. +** +** ^The sqlite3_result_error() and sqlite3_result_error16() functions +** cause the implemented SQL function to throw an exception. +** ^SQLite uses the string pointed to by the +** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() +** as the text of an error message. ^SQLite interprets the error +** message string from sqlite3_result_error() as UTF-8. ^SQLite +** interprets the string from sqlite3_result_error16() as UTF-16 in native +** byte order. ^If the third parameter to sqlite3_result_error() +** or sqlite3_result_error16() is negative then SQLite takes as the error +** message all text up through the first zero character. +** ^If the third parameter to sqlite3_result_error() or +** sqlite3_result_error16() is non-negative then SQLite takes that many +** bytes (not characters) from the 2nd parameter as the error message. +** ^The sqlite3_result_error() and sqlite3_result_error16() +** routines make a private copy of the error message text before +** they return. Hence, the calling function can deallocate or +** modify the text after they return without harm. +** ^The sqlite3_result_error_code() function changes the error code +** returned by SQLite as a result of an error in a function. ^By default, +** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() +** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. +** +** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an +** error indicating that a string or BLOB is too long to represent. +** +** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an +** error indicating that a memory allocation failed. +** +** ^The sqlite3_result_int() interface sets the return value +** of the application-defined function to be the 32-bit signed integer +** value given in the 2nd argument. +** ^The sqlite3_result_int64() interface sets the return value +** of the application-defined function to be the 64-bit signed integer +** value given in the 2nd argument. +** +** ^The sqlite3_result_null() interface sets the return value +** of the application-defined function to be NULL. +** +** ^The sqlite3_result_text(), sqlite3_result_text16(), +** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces +** set the return value of the application-defined function to be +** a text string which is represented as UTF-8, UTF-16 native byte order, +** UTF-16 little endian, or UTF-16 big endian, respectively. +** ^The sqlite3_result_text64() interface sets the return value of an +** application-defined function to be a text string in an encoding +** specified by the fifth (and last) parameter, which must be one +** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]. +** ^SQLite takes the text result from the application from +** the 2nd parameter of the sqlite3_result_text* interfaces. +** ^If the 3rd parameter to the sqlite3_result_text* interfaces +** is negative, then SQLite takes result text from the 2nd parameter +** through the first zero character. +** ^If the 3rd parameter to the sqlite3_result_text* interfaces +** is non-negative, then as many bytes (not characters) of the text +** pointed to by the 2nd parameter are taken as the application-defined +** function result. If the 3rd parameter is non-negative, then it +** must be the byte offset into the string where the NUL terminator would +** appear if the string where NUL terminated. If any NUL characters occur +** in the string at a byte offset that is less than the value of the 3rd +** parameter, then the resulting string will contain embedded NULs and the +** result of expressions operating on strings with embedded NULs is undefined. +** ^If the 4th parameter to the sqlite3_result_text* interfaces +** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that +** function as the destructor on the text or BLOB result when it has +** finished using that result. +** ^If the 4th parameter to the sqlite3_result_text* interfaces or to +** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite +** assumes that the text or BLOB result is in constant space and does not +** copy the content of the parameter nor call a destructor on the content +** when it has finished using that result. +** ^If the 4th parameter to the sqlite3_result_text* interfaces +** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT +** then SQLite makes a copy of the result into space obtained +** from [sqlite3_malloc()] before it returns. +** +** ^The sqlite3_result_value() interface sets the result of +** the application-defined function to be a copy of the +** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The +** sqlite3_result_value() interface makes a copy of the [sqlite3_value] +** so that the [sqlite3_value] specified in the parameter may change or +** be deallocated after sqlite3_result_value() returns without harm. +** ^A [protected sqlite3_value] object may always be used where an +** [unprotected sqlite3_value] object is required, so either +** kind of [sqlite3_value] object can be used with this interface. +** +** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an +** SQL NULL value, just like [sqlite3_result_null(C)], except that it +** also associates the host-language pointer P or type T with that +** NULL value such that the pointer can be retrieved within an +** [application-defined SQL function] using [sqlite3_value_pointer()]. +** ^If the D parameter is not NULL, then it is a pointer to a destructor +** for the P parameter. ^SQLite invokes D with P as its only argument +** when SQLite is finished with P. The T parameter should be a static +** string and preferably a string literal. The sqlite3_result_pointer() +** routine is part of the [pointer passing interface] added for SQLite 3.20.0. +** +** If these routines are called from within the different thread +** than the one containing the application-defined function that received +** the [sqlite3_context] pointer, the results are undefined. +*/ +SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, + sqlite3_uint64,void(*)(void*)); +SQLITE_API void sqlite3_result_double(sqlite3_context*, double); +SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); +SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); +SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); +SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); +SQLITE_API void sqlite3_result_int(sqlite3_context*, int); +SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); +SQLITE_API void sqlite3_result_null(sqlite3_context*); +SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); +SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, + void(*)(void*), unsigned char encoding); +SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); +SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); +SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); +SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); +SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*)); +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); +SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); + + +/* +** CAPI3REF: Setting The Subtype Of An SQL Function +** METHOD: sqlite3_context +** +** The sqlite3_result_subtype(C,T) function causes the subtype of +** the result from the [application-defined SQL function] with +** [sqlite3_context] C to be the value T. Only the lower 8 bits +** of the subtype T are preserved in current versions of SQLite; +** higher order bits are discarded. +** The number of subtype bytes preserved by SQLite might increase +** in future releases of SQLite. +*/ +SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); + +/* +** CAPI3REF: Define New Collating Sequences +** METHOD: sqlite3 +** +** ^These functions add, remove, or modify a [collation] associated +** with the [database connection] specified as the first argument. +** +** ^The name of the collation is a UTF-8 string +** for sqlite3_create_collation() and sqlite3_create_collation_v2() +** and a UTF-16 string in native byte order for sqlite3_create_collation16(). +** ^Collation names that compare equal according to [sqlite3_strnicmp()] are +** considered to be the same name. +** +** ^(The third argument (eTextRep) must be one of the constants: +** <ul> +** <li> [SQLITE_UTF8], +** <li> [SQLITE_UTF16LE], +** <li> [SQLITE_UTF16BE], +** <li> [SQLITE_UTF16], or +** <li> [SQLITE_UTF16_ALIGNED]. +** </ul>)^ +** ^The eTextRep argument determines the encoding of strings passed +** to the collating function callback, xCallback. +** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep +** force strings to be UTF16 with native byte order. +** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin +** on an even byte address. +** +** ^The fourth argument, pArg, is an application data pointer that is passed +** through as the first argument to the collating function callback. +** +** ^The fifth argument, xCallback, is a pointer to the collating function. +** ^Multiple collating functions can be registered using the same name but +** with different eTextRep parameters and SQLite will use whichever +** function requires the least amount of data transformation. +** ^If the xCallback argument is NULL then the collating function is +** deleted. ^When all collating functions having the same name are deleted, +** that collation is no longer usable. +** +** ^The collating function callback is invoked with a copy of the pArg +** application data pointer and with two strings in the encoding specified +** by the eTextRep argument. The collating function must return an +** integer that is negative, zero, or positive +** if the first string is less than, equal to, or greater than the second, +** respectively. A collating function must always return the same answer +** given the same inputs. If two or more collating functions are registered +** to the same collation name (using different eTextRep values) then all +** must give an equivalent answer when invoked with equivalent strings. +** The collating function must obey the following properties for all +** strings A, B, and C: +** +** <ol> +** <li> If A==B then B==A. +** <li> If A==B and B==C then A==C. +** <li> If A<B THEN B>A. +** <li> If A<B and B<C then A<C. +** </ol> +** +** If a collating function fails any of the above constraints and that +** collating function is registered and used, then the behavior of SQLite +** is undefined. +** +** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() +** with the addition that the xDestroy callback is invoked on pArg when +** the collating function is deleted. +** ^Collating functions are deleted when they are overridden by later +** calls to the collation creation functions or when the +** [database connection] is closed using [sqlite3_close()]. +** +** ^The xDestroy callback is <u>not</u> called if the +** sqlite3_create_collation_v2() function fails. Applications that invoke +** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should +** check the return code and dispose of the application data pointer +** themselves rather than expecting SQLite to deal with it for them. +** This is different from every other SQLite interface. The inconsistency +** is unfortunate but cannot be changed without breaking backwards +** compatibility. +** +** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. +*/ +SQLITE_API int sqlite3_create_collation( + sqlite3*, + const char *zName, + int eTextRep, + void *pArg, + int(*xCompare)(void*,int,const void*,int,const void*) +); +SQLITE_API int sqlite3_create_collation_v2( + sqlite3*, + const char *zName, + int eTextRep, + void *pArg, + int(*xCompare)(void*,int,const void*,int,const void*), + void(*xDestroy)(void*) +); +SQLITE_API int sqlite3_create_collation16( + sqlite3*, + const void *zName, + int eTextRep, + void *pArg, + int(*xCompare)(void*,int,const void*,int,const void*) +); + +/* +** CAPI3REF: Collation Needed Callbacks +** METHOD: sqlite3 +** +** ^To avoid having to register all collation sequences before a database +** can be used, a single callback function may be registered with the +** [database connection] to be invoked whenever an undefined collation +** sequence is required. +** +** ^If the function is registered using the sqlite3_collation_needed() API, +** then it is passed the names of undefined collation sequences as strings +** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, +** the names are passed as UTF-16 in machine native byte order. +** ^A call to either function replaces the existing collation-needed callback. +** +** ^(When the callback is invoked, the first argument passed is a copy +** of the second argument to sqlite3_collation_needed() or +** sqlite3_collation_needed16(). The second argument is the database +** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], +** or [SQLITE_UTF16LE], indicating the most desirable form of the collation +** sequence function required. The fourth parameter is the name of the +** required collation sequence.)^ +** +** The callback function should register the desired collation using +** [sqlite3_create_collation()], [sqlite3_create_collation16()], or +** [sqlite3_create_collation_v2()]. +*/ +SQLITE_API int sqlite3_collation_needed( + sqlite3*, + void*, + void(*)(void*,sqlite3*,int eTextRep,const char*) +); +SQLITE_API int sqlite3_collation_needed16( + sqlite3*, + void*, + void(*)(void*,sqlite3*,int eTextRep,const void*) +); + +#ifdef SQLITE_HAS_CODEC +/* +** Specify the key for an encrypted database. This routine should be +** called right after sqlite3_open(). +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +SQLITE_API int sqlite3_key( + sqlite3 *db, /* Database to be rekeyed */ + const void *pKey, int nKey /* The key */ +); +SQLITE_API int sqlite3_key_v2( + sqlite3 *db, /* Database to be rekeyed */ + const char *zDbName, /* Name of the database */ + const void *pKey, int nKey /* The key */ +); + +/* +** Change the key on an open database. If the current database is not +** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the +** database is decrypted. +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +SQLITE_API int sqlite3_rekey( + sqlite3 *db, /* Database to be rekeyed */ + const void *pKey, int nKey /* The new key */ +); +SQLITE_API int sqlite3_rekey_v2( + sqlite3 *db, /* Database to be rekeyed */ + const char *zDbName, /* Name of the database */ + const void *pKey, int nKey /* The new key */ +); + +/* +** Specify the activation key for a SEE database. Unless +** activated, none of the SEE routines will work. +*/ +SQLITE_API void sqlite3_activate_see( + const char *zPassPhrase /* Activation phrase */ +); +#endif + +#ifdef SQLITE_ENABLE_CEROD +/* +** Specify the activation key for a CEROD database. Unless +** activated, none of the CEROD routines will work. +*/ +SQLITE_API void sqlite3_activate_cerod( + const char *zPassPhrase /* Activation phrase */ +); +#endif + +/* +** CAPI3REF: Suspend Execution For A Short Time +** +** The sqlite3_sleep() function causes the current thread to suspend execution +** for at least a number of milliseconds specified in its parameter. +** +** If the operating system does not support sleep requests with +** millisecond time resolution, then the time will be rounded up to +** the nearest second. The number of milliseconds of sleep actually +** requested from the operating system is returned. +** +** ^SQLite implements this interface by calling the xSleep() +** method of the default [sqlite3_vfs] object. If the xSleep() method +** of the default VFS is not implemented correctly, or not implemented at +** all, then the behavior of sqlite3_sleep() may deviate from the description +** in the previous paragraphs. +*/ +SQLITE_API int sqlite3_sleep(int); + +/* +** CAPI3REF: Name Of The Folder Holding Temporary Files +** +** ^(If this global variable is made to point to a string which is +** the name of a folder (a.k.a. directory), then all temporary files +** created by SQLite when using a built-in [sqlite3_vfs | VFS] +** will be placed in that directory.)^ ^If this variable +** is a NULL pointer, then SQLite performs a search for an appropriate +** temporary file directory. +** +** Applications are strongly discouraged from using this global variable. +** It is required to set a temporary folder on Windows Runtime (WinRT). +** But for all other platforms, it is highly recommended that applications +** neither read nor write this variable. This global variable is a relic +** that exists for backwards compatibility of legacy applications and should +** be avoided in new projects. +** +** It is not safe to read or modify this variable in more than one +** thread at a time. It is not safe to read or modify this variable +** if a [database connection] is being used at the same time in a separate +** thread. +** It is intended that this variable be set once +** as part of process initialization and before any SQLite interface +** routines have been called and that this variable remain unchanged +** thereafter. +** +** ^The [temp_store_directory pragma] may modify this variable and cause +** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, +** the [temp_store_directory pragma] always assumes that any string +** that this variable points to is held in memory obtained from +** [sqlite3_malloc] and the pragma may attempt to free that memory +** using [sqlite3_free]. +** Hence, if this variable is modified directly, either it should be +** made NULL or made to point to memory obtained from [sqlite3_malloc] +** or else the use of the [temp_store_directory pragma] should be avoided. +** Except when requested by the [temp_store_directory pragma], SQLite +** does not free the memory that sqlite3_temp_directory points to. If +** the application wants that memory to be freed, it must do +** so itself, taking care to only do so after all [database connection] +** objects have been destroyed. +** +** <b>Note to Windows Runtime users:</b> The temporary directory must be set +** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various +** features that require the use of temporary files may fail. Here is an +** example of how to do this using C++ with the Windows Runtime: +** +** <blockquote><pre> +** LPCWSTR zPath = Windows::Storage::ApplicationData::Current-> +**   TemporaryFolder->Path->Data(); +** char zPathBuf[MAX_PATH + 1]; +** memset(zPathBuf, 0, sizeof(zPathBuf)); +** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), +**   NULL, NULL); +** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf); +** </pre></blockquote> +*/ +SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; + +/* +** CAPI3REF: Name Of The Folder Holding Database Files +** +** ^(If this global variable is made to point to a string which is +** the name of a folder (a.k.a. directory), then all database files +** specified with a relative pathname and created or accessed by +** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed +** to be relative to that directory.)^ ^If this variable is a NULL +** pointer, then SQLite assumes that all database files specified +** with a relative pathname are relative to the current directory +** for the process. Only the windows VFS makes use of this global +** variable; it is ignored by the unix VFS. +** +** Changing the value of this variable while a database connection is +** open can result in a corrupt database. +** +** It is not safe to read or modify this variable in more than one +** thread at a time. It is not safe to read or modify this variable +** if a [database connection] is being used at the same time in a separate +** thread. +** It is intended that this variable be set once +** as part of process initialization and before any SQLite interface +** routines have been called and that this variable remain unchanged +** thereafter. +** +** ^The [data_store_directory pragma] may modify this variable and cause +** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, +** the [data_store_directory pragma] always assumes that any string +** that this variable points to is held in memory obtained from +** [sqlite3_malloc] and the pragma may attempt to free that memory +** using [sqlite3_free]. +** Hence, if this variable is modified directly, either it should be +** made NULL or made to point to memory obtained from [sqlite3_malloc] +** or else the use of the [data_store_directory pragma] should be avoided. +*/ +SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; + +/* +** CAPI3REF: Win32 Specific Interface +** +** These interfaces are available only on Windows. The +** [sqlite3_win32_set_directory] interface is used to set the value associated +** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to +** zValue, depending on the value of the type parameter. The zValue parameter +** should be NULL to cause the previous value to be freed via [sqlite3_free]; +** a non-NULL value will be copied into memory obtained from [sqlite3_malloc] +** prior to being used. The [sqlite3_win32_set_directory] interface returns +** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported, +** or [SQLITE_NOMEM] if memory could not be allocated. The value of the +** [sqlite3_data_directory] variable is intended to act as a replacement for +** the current directory on the sub-platforms of Win32 where that concept is +** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and +** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the +** sqlite3_win32_set_directory interface except the string parameter must be +** UTF-8 or UTF-16, respectively. +*/ +SQLITE_API int sqlite3_win32_set_directory( + unsigned long type, /* Identifier for directory being set or reset */ + void *zValue /* New value for directory being set or reset */ +); +SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue); +SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue); + +/* +** CAPI3REF: Win32 Directory Types +** +** These macros are only available on Windows. They define the allowed values +** for the type argument to the [sqlite3_win32_set_directory] interface. +*/ +#define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1 +#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2 + +/* +** CAPI3REF: Test For Auto-Commit Mode +** KEYWORDS: {autocommit mode} +** METHOD: sqlite3 +** +** ^The sqlite3_get_autocommit() interface returns non-zero or +** zero if the given database connection is or is not in autocommit mode, +** respectively. ^Autocommit mode is on by default. +** ^Autocommit mode is disabled by a [BEGIN] statement. +** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. +** +** If certain kinds of errors occur on a statement within a multi-statement +** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], +** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the +** transaction might be rolled back automatically. The only way to +** find out whether SQLite automatically rolled back the transaction after +** an error is to use this function. +** +** If another thread changes the autocommit status of the database +** connection while this routine is running, then the return value +** is undefined. +*/ +SQLITE_API int sqlite3_get_autocommit(sqlite3*); + +/* +** CAPI3REF: Find The Database Handle Of A Prepared Statement +** METHOD: sqlite3_stmt +** +** ^The sqlite3_db_handle interface returns the [database connection] handle +** to which a [prepared statement] belongs. ^The [database connection] +** returned by sqlite3_db_handle is the same [database connection] +** that was the first argument +** to the [sqlite3_prepare_v2()] call (or its variants) that was used to +** create the statement in the first place. +*/ +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); + +/* +** CAPI3REF: Return The Filename For A Database Connection +** METHOD: sqlite3 +** +** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename +** associated with database N of connection D. ^The main database file +** has the name "main". If there is no attached database N on the database +** connection D, or if database N is a temporary or in-memory database, then +** this function will return either a NULL pointer or an empty string. +** +** ^The filename returned by this function is the output of the +** xFullPathname method of the [VFS]. ^In other words, the filename +** will be an absolute pathname, even if the filename used +** to open the database originally was a URI or relative pathname. +*/ +SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); + +/* +** CAPI3REF: Determine if a database is read-only +** METHOD: sqlite3 +** +** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N +** of connection D is read-only, 0 if it is read/write, or -1 if N is not +** the name of a database on connection D. +*/ +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); + +/* +** CAPI3REF: Find the next prepared statement +** METHOD: sqlite3 +** +** ^This interface returns a pointer to the next [prepared statement] after +** pStmt associated with the [database connection] pDb. ^If pStmt is NULL +** then this interface returns a pointer to the first prepared statement +** associated with the database connection pDb. ^If no prepared statement +** satisfies the conditions of this routine, it returns NULL. +** +** The [database connection] pointer D in a call to +** [sqlite3_next_stmt(D,S)] must refer to an open database +** connection and in particular must not be a NULL pointer. +*/ +SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Commit And Rollback Notification Callbacks +** METHOD: sqlite3 +** +** ^The sqlite3_commit_hook() interface registers a callback +** function to be invoked whenever a transaction is [COMMIT | committed]. +** ^Any callback set by a previous call to sqlite3_commit_hook() +** for the same database connection is overridden. +** ^The sqlite3_rollback_hook() interface registers a callback +** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. +** ^Any callback set by a previous call to sqlite3_rollback_hook() +** for the same database connection is overridden. +** ^The pArg argument is passed through to the callback. +** ^If the callback on a commit hook function returns non-zero, +** then the commit is converted into a rollback. +** +** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions +** return the P argument from the previous call of the same function +** on the same [database connection] D, or NULL for +** the first call for each function on D. +** +** The commit and rollback hook callbacks are not reentrant. +** The callback implementation must not do anything that will modify +** the database connection that invoked the callback. Any actions +** to modify the database connection must be deferred until after the +** completion of the [sqlite3_step()] call that triggered the commit +** or rollback hook in the first place. +** Note that running any other SQL statements, including SELECT statements, +** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify +** the database connections for the meaning of "modify" in this paragraph. +** +** ^Registering a NULL function disables the callback. +** +** ^When the commit hook callback routine returns zero, the [COMMIT] +** operation is allowed to continue normally. ^If the commit hook +** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. +** ^The rollback hook is invoked on a rollback that results from a commit +** hook returning non-zero, just as it would be with any other rollback. +** +** ^For the purposes of this API, a transaction is said to have been +** rolled back if an explicit "ROLLBACK" statement is executed, or +** an error or constraint causes an implicit rollback to occur. +** ^The rollback callback is not invoked if a transaction is +** automatically rolled back because the database connection is closed. +** +** See also the [sqlite3_update_hook()] interface. +*/ +SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); +SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); + +/* +** CAPI3REF: Data Change Notification Callbacks +** METHOD: sqlite3 +** +** ^The sqlite3_update_hook() interface registers a callback function +** with the [database connection] identified by the first argument +** to be invoked whenever a row is updated, inserted or deleted in +** a [rowid table]. +** ^Any callback set by a previous call to this function +** for the same database connection is overridden. +** +** ^The second argument is a pointer to the function to invoke when a +** row is updated, inserted or deleted in a rowid table. +** ^The first argument to the callback is a copy of the third argument +** to sqlite3_update_hook(). +** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], +** or [SQLITE_UPDATE], depending on the operation that caused the callback +** to be invoked. +** ^The third and fourth arguments to the callback contain pointers to the +** database and table name containing the affected row. +** ^The final callback parameter is the [rowid] of the row. +** ^In the case of an update, this is the [rowid] after the update takes place. +** +** ^(The update hook is not invoked when internal system tables are +** modified (i.e. sqlite_master and sqlite_sequence).)^ +** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. +** +** ^In the current implementation, the update hook +** is not invoked when conflicting rows are deleted because of an +** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook +** invoked when rows are deleted using the [truncate optimization]. +** The exceptions defined in this paragraph might change in a future +** release of SQLite. +** +** The update hook implementation must not do anything that will modify +** the database connection that invoked the update hook. Any actions +** to modify the database connection must be deferred until after the +** completion of the [sqlite3_step()] call that triggered the update hook. +** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their +** database connections for the meaning of "modify" in this paragraph. +** +** ^The sqlite3_update_hook(D,C,P) function +** returns the P argument from the previous call +** on the same [database connection] D, or NULL for +** the first call on D. +** +** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()], +** and [sqlite3_preupdate_hook()] interfaces. +*/ +SQLITE_API void *sqlite3_update_hook( + sqlite3*, + void(*)(void *,int ,char const *,char const *,sqlite3_int64), + void* +); + +/* +** CAPI3REF: Enable Or Disable Shared Pager Cache +** +** ^(This routine enables or disables the sharing of the database cache +** and schema data structures between [database connection | connections] +** to the same database. Sharing is enabled if the argument is true +** and disabled if the argument is false.)^ +** +** ^Cache sharing is enabled and disabled for an entire process. +** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). +** In prior versions of SQLite, +** sharing was enabled or disabled for each thread separately. +** +** ^(The cache sharing mode set by this interface effects all subsequent +** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. +** Existing database connections continue use the sharing mode +** that was in effect at the time they were opened.)^ +** +** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled +** successfully. An [error code] is returned otherwise.)^ +** +** ^Shared cache is disabled by default. But this might change in +** future releases of SQLite. Applications that care about shared +** cache setting should set it explicitly. +** +** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 +** and will always return SQLITE_MISUSE. On those systems, +** shared cache mode should be enabled per-database connection via +** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE]. +** +** This interface is threadsafe on processors where writing a +** 32-bit integer is atomic. +** +** See Also: [SQLite Shared-Cache Mode] +*/ +SQLITE_API int sqlite3_enable_shared_cache(int); + +/* +** CAPI3REF: Attempt To Free Heap Memory +** +** ^The sqlite3_release_memory() interface attempts to free N bytes +** of heap memory by deallocating non-essential memory allocations +** held by the database library. Memory used to cache database +** pages to improve performance is an example of non-essential memory. +** ^sqlite3_release_memory() returns the number of bytes actually freed, +** which might be more or less than the amount requested. +** ^The sqlite3_release_memory() routine is a no-op returning zero +** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. +** +** See also: [sqlite3_db_release_memory()] +*/ +SQLITE_API int sqlite3_release_memory(int); + +/* +** CAPI3REF: Free Memory Used By A Database Connection +** METHOD: sqlite3 +** +** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap +** memory as possible from database connection D. Unlike the +** [sqlite3_release_memory()] interface, this interface is in effect even +** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is +** omitted. +** +** See also: [sqlite3_release_memory()] +*/ +SQLITE_API int sqlite3_db_release_memory(sqlite3*); + +/* +** CAPI3REF: Impose A Limit On Heap Size +** +** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the +** soft limit on the amount of heap memory that may be allocated by SQLite. +** ^SQLite strives to keep heap memory utilization below the soft heap +** limit by reducing the number of pages held in the page cache +** as heap memory usages approaches the limit. +** ^The soft heap limit is "soft" because even though SQLite strives to stay +** below the limit, it will exceed the limit rather than generate +** an [SQLITE_NOMEM] error. In other words, the soft heap limit +** is advisory only. +** +** ^The return value from sqlite3_soft_heap_limit64() is the size of +** the soft heap limit prior to the call, or negative in the case of an +** error. ^If the argument N is negative +** then no change is made to the soft heap limit. Hence, the current +** size of the soft heap limit can be determined by invoking +** sqlite3_soft_heap_limit64() with a negative argument. +** +** ^If the argument N is zero then the soft heap limit is disabled. +** +** ^(The soft heap limit is not enforced in the current implementation +** if one or more of following conditions are true: +** +** <ul> +** <li> The soft heap limit is set to zero. +** <li> Memory accounting is disabled using a combination of the +** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and +** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. +** <li> An alternative page cache implementation is specified using +** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). +** <li> The page cache allocates from its own memory pool supplied +** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than +** from the heap. +** </ul>)^ +** +** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), +** the soft heap limit is enforced +** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] +** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], +** the soft heap limit is enforced on every memory allocation. Without +** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced +** when memory is allocated by the page cache. Testing suggests that because +** the page cache is the predominate memory user in SQLite, most +** applications will achieve adequate soft heap limit enforcement without +** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. +** +** The circumstances under which SQLite will enforce the soft heap limit may +** changes in future releases of SQLite. +*/ +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); + +/* +** CAPI3REF: Deprecated Soft Heap Limit Interface +** DEPRECATED +** +** This is a deprecated version of the [sqlite3_soft_heap_limit64()] +** interface. This routine is provided for historical compatibility +** only. All new applications should use the +** [sqlite3_soft_heap_limit64()] interface rather than this one. +*/ +SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); + + +/* +** CAPI3REF: Extract Metadata About A Column Of A Table +** METHOD: sqlite3 +** +** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns +** information about column C of table T in database D +** on [database connection] X.)^ ^The sqlite3_table_column_metadata() +** interface returns SQLITE_OK and fills in the non-NULL pointers in +** the final five arguments with appropriate values if the specified +** column exists. ^The sqlite3_table_column_metadata() interface returns +** SQLITE_ERROR and if the specified column does not exist. +** ^If the column-name parameter to sqlite3_table_column_metadata() is a +** NULL pointer, then this routine simply checks for the existence of the +** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it +** does not. If the table name parameter T in a call to +** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is +** undefined behavior. +** +** ^The column is identified by the second, third and fourth parameters to +** this function. ^(The second parameter is either the name of the database +** (i.e. "main", "temp", or an attached database) containing the specified +** table or NULL.)^ ^If it is NULL, then all attached databases are searched +** for the table using the same algorithm used by the database engine to +** resolve unqualified table references. +** +** ^The third and fourth parameters to this function are the table and column +** name of the desired column, respectively. +** +** ^Metadata is returned by writing to the memory locations passed as the 5th +** and subsequent parameters to this function. ^Any of these arguments may be +** NULL, in which case the corresponding element of metadata is omitted. +** +** ^(<blockquote> +** <table border="1"> +** <tr><th> Parameter <th> Output<br>Type <th> Description +** +** <tr><td> 5th <td> const char* <td> Data type +** <tr><td> 6th <td> const char* <td> Name of default collation sequence +** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint +** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY +** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] +** </table> +** </blockquote>)^ +** +** ^The memory pointed to by the character pointers returned for the +** declaration type and collation sequence is valid until the next +** call to any SQLite API function. +** +** ^If the specified table is actually a view, an [error code] is returned. +** +** ^If the specified column is "rowid", "oid" or "_rowid_" and the table +** is not a [WITHOUT ROWID] table and an +** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output +** parameters are set for the explicitly declared column. ^(If there is no +** [INTEGER PRIMARY KEY] column, then the outputs +** for the [rowid] are set as follows: +** +** <pre> +** data type: "INTEGER" +** collation sequence: "BINARY" +** not null: 0 +** primary key: 1 +** auto increment: 0 +** </pre>)^ +** +** ^This function causes all database schemas to be read from disk and +** parsed, if that has not already been done, and returns an error if +** any errors are encountered while loading the schema. +*/ +SQLITE_API int sqlite3_table_column_metadata( + sqlite3 *db, /* Connection handle */ + const char *zDbName, /* Database name or NULL */ + const char *zTableName, /* Table name */ + const char *zColumnName, /* Column name */ + char const **pzDataType, /* OUTPUT: Declared data type */ + char const **pzCollSeq, /* OUTPUT: Collation sequence name */ + int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ + int *pPrimaryKey, /* OUTPUT: True if column part of PK */ + int *pAutoinc /* OUTPUT: True if column is auto-increment */ +); + +/* +** CAPI3REF: Load An Extension +** METHOD: sqlite3 +** +** ^This interface loads an SQLite extension library from the named file. +** +** ^The sqlite3_load_extension() interface attempts to load an +** [SQLite extension] library contained in the file zFile. If +** the file cannot be loaded directly, attempts are made to load +** with various operating-system specific extensions added. +** So for example, if "samplelib" cannot be loaded, then names like +** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might +** be tried also. +** +** ^The entry point is zProc. +** ^(zProc may be 0, in which case SQLite will try to come up with an +** entry point name on its own. It first tries "sqlite3_extension_init". +** If that does not work, it constructs a name "sqlite3_X_init" where the +** X is consists of the lower-case equivalent of all ASCII alphabetic +** characters in the filename from the last "/" to the first following +** "." and omitting any initial "lib".)^ +** ^The sqlite3_load_extension() interface returns +** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. +** ^If an error occurs and pzErrMsg is not 0, then the +** [sqlite3_load_extension()] interface shall attempt to +** fill *pzErrMsg with error message text stored in memory +** obtained from [sqlite3_malloc()]. The calling function +** should free this memory by calling [sqlite3_free()]. +** +** ^Extension loading must be enabled using +** [sqlite3_enable_load_extension()] or +** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL) +** prior to calling this API, +** otherwise an error will be returned. +** +** <b>Security warning:</b> It is recommended that the +** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this +** interface. The use of the [sqlite3_enable_load_extension()] interface +** should be avoided. This will keep the SQL function [load_extension()] +** disabled and prevent SQL injections from giving attackers +** access to extension loading capabilities. +** +** See also the [load_extension() SQL function]. +*/ +SQLITE_API int sqlite3_load_extension( + sqlite3 *db, /* Load the extension into this database connection */ + const char *zFile, /* Name of the shared library containing extension */ + const char *zProc, /* Entry point. Derived from zFile if 0 */ + char **pzErrMsg /* Put error message here if not 0 */ +); + +/* +** CAPI3REF: Enable Or Disable Extension Loading +** METHOD: sqlite3 +** +** ^So as not to open security holes in older applications that are +** unprepared to deal with [extension loading], and as a means of disabling +** [extension loading] while evaluating user-entered SQL, the following API +** is provided to turn the [sqlite3_load_extension()] mechanism on and off. +** +** ^Extension loading is off by default. +** ^Call the sqlite3_enable_load_extension() routine with onoff==1 +** to turn extension loading on and call it with onoff==0 to turn +** it back off again. +** +** ^This interface enables or disables both the C-API +** [sqlite3_load_extension()] and the SQL function [load_extension()]. +** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..) +** to enable or disable only the C-API.)^ +** +** <b>Security warning:</b> It is recommended that extension loading +** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method +** rather than this interface, so the [load_extension()] SQL function +** remains disabled. This will prevent SQL injections from giving attackers +** access to extension loading capabilities. +*/ +SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); + +/* +** CAPI3REF: Automatically Load Statically Linked Extensions +** +** ^This interface causes the xEntryPoint() function to be invoked for +** each new [database connection] that is created. The idea here is that +** xEntryPoint() is the entry point for a statically linked [SQLite extension] +** that is to be automatically loaded into all new database connections. +** +** ^(Even though the function prototype shows that xEntryPoint() takes +** no arguments and returns void, SQLite invokes xEntryPoint() with three +** arguments and expects an integer result as if the signature of the +** entry point where as follows: +** +** <blockquote><pre> +**   int xEntryPoint( +**   sqlite3 *db, +**   const char **pzErrMsg, +**   const struct sqlite3_api_routines *pThunk +**   ); +** </pre></blockquote>)^ +** +** If the xEntryPoint routine encounters an error, it should make *pzErrMsg +** point to an appropriate error message (obtained from [sqlite3_mprintf()]) +** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg +** is NULL before calling the xEntryPoint(). ^SQLite will invoke +** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any +** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], +** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. +** +** ^Calling sqlite3_auto_extension(X) with an entry point X that is already +** on the list of automatic extensions is a harmless no-op. ^No entry point +** will be called more than once for each database connection that is opened. +** +** See also: [sqlite3_reset_auto_extension()] +** and [sqlite3_cancel_auto_extension()] +*/ +SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); + +/* +** CAPI3REF: Cancel Automatic Extension Loading +** +** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the +** initialization routine X that was registered using a prior call to +** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] +** routine returns 1 if initialization routine X was successfully +** unregistered and it returns 0 if X was not on the list of initialization +** routines. +*/ +SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); + +/* +** CAPI3REF: Reset Automatic Extension Loading +** +** ^This interface disables all automatic extensions previously +** registered using [sqlite3_auto_extension()]. +*/ +SQLITE_API void sqlite3_reset_auto_extension(void); + +/* +** The interface to the virtual-table mechanism is currently considered +** to be experimental. The interface might change in incompatible ways. +** If this is a problem for you, do not use the interface at this time. +** +** When the virtual-table mechanism stabilizes, we will declare the +** interface fixed, support it indefinitely, and remove this comment. +*/ + +/* +** Structures used by the virtual table interface +*/ +typedef struct sqlite3_vtab sqlite3_vtab; +typedef struct sqlite3_index_info sqlite3_index_info; +typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; +typedef struct sqlite3_module sqlite3_module; + +/* +** CAPI3REF: Virtual Table Object +** KEYWORDS: sqlite3_module {virtual table module} +** +** This structure, sometimes called a "virtual table module", +** defines the implementation of a [virtual tables]. +** This structure consists mostly of methods for the module. +** +** ^A virtual table module is created by filling in a persistent +** instance of this structure and passing a pointer to that instance +** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. +** ^The registration remains valid until it is replaced by a different +** module or until the [database connection] closes. The content +** of this structure must not change while it is registered with +** any database connection. +*/ +struct sqlite3_module { + int iVersion; + int (*xCreate)(sqlite3*, void *pAux, + int argc, const char *const*argv, + sqlite3_vtab **ppVTab, char**); + int (*xConnect)(sqlite3*, void *pAux, + int argc, const char *const*argv, + sqlite3_vtab **ppVTab, char**); + int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); + int (*xDisconnect)(sqlite3_vtab *pVTab); + int (*xDestroy)(sqlite3_vtab *pVTab); + int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); + int (*xClose)(sqlite3_vtab_cursor*); + int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, + int argc, sqlite3_value **argv); + int (*xNext)(sqlite3_vtab_cursor*); + int (*xEof)(sqlite3_vtab_cursor*); + int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); + int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); + int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); + int (*xBegin)(sqlite3_vtab *pVTab); + int (*xSync)(sqlite3_vtab *pVTab); + int (*xCommit)(sqlite3_vtab *pVTab); + int (*xRollback)(sqlite3_vtab *pVTab); + int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, + void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), + void **ppArg); + int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); + /* The methods above are in version 1 of the sqlite_module object. Those + ** below are for version 2 and greater. */ + int (*xSavepoint)(sqlite3_vtab *pVTab, int); + int (*xRelease)(sqlite3_vtab *pVTab, int); + int (*xRollbackTo)(sqlite3_vtab *pVTab, int); + /* The methods above are in versions 1 and 2 of the sqlite_module object. + ** Those below are for version 3 and greater. */ + int (*xShadowName)(const char*); +}; + +/* +** CAPI3REF: Virtual Table Indexing Information +** KEYWORDS: sqlite3_index_info +** +** The sqlite3_index_info structure and its substructures is used as part +** of the [virtual table] interface to +** pass information into and receive the reply from the [xBestIndex] +** method of a [virtual table module]. The fields under **Inputs** are the +** inputs to xBestIndex and are read-only. xBestIndex inserts its +** results into the **Outputs** fields. +** +** ^(The aConstraint[] array records WHERE clause constraints of the form: +** +** <blockquote>column OP expr</blockquote> +** +** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is +** stored in aConstraint[].op using one of the +** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ +** ^(The index of the column is stored in +** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the +** expr on the right-hand side can be evaluated (and thus the constraint +** is usable) and false if it cannot.)^ +** +** ^The optimizer automatically inverts terms of the form "expr OP column" +** and makes other simplifications to the WHERE clause in an attempt to +** get as many WHERE clause terms into the form shown above as possible. +** ^The aConstraint[] array only reports WHERE clause terms that are +** relevant to the particular virtual table being queried. +** +** ^Information about the ORDER BY clause is stored in aOrderBy[]. +** ^Each term of aOrderBy records a column of the ORDER BY clause. +** +** The colUsed field indicates which columns of the virtual table may be +** required by the current scan. Virtual table columns are numbered from +** zero in the order in which they appear within the CREATE TABLE statement +** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), +** the corresponding bit is set within the colUsed mask if the column may be +** required by SQLite. If the table has at least 64 columns and any column +** to the right of the first 63 is required, then bit 63 of colUsed is also +** set. In other words, column iCol may be required if the expression +** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to +** non-zero. +** +** The [xBestIndex] method must fill aConstraintUsage[] with information +** about what parameters to pass to xFilter. ^If argvIndex>0 then +** the right-hand side of the corresponding aConstraint[] is evaluated +** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit +** is true, then the constraint is assumed to be fully handled by the +** virtual table and is not checked again by SQLite.)^ +** +** ^The idxNum and idxPtr values are recorded and passed into the +** [xFilter] method. +** ^[sqlite3_free()] is used to free idxPtr if and only if +** needToFreeIdxPtr is true. +** +** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in +** the correct order to satisfy the ORDER BY clause so that no separate +** sorting step is required. +** +** ^The estimatedCost value is an estimate of the cost of a particular +** strategy. A cost of N indicates that the cost of the strategy is similar +** to a linear scan of an SQLite table with N rows. A cost of log(N) +** indicates that the expense of the operation is similar to that of a +** binary search on a unique indexed field of an SQLite table with N rows. +** +** ^The estimatedRows value is an estimate of the number of rows that +** will be returned by the strategy. +** +** The xBestIndex method may optionally populate the idxFlags field with a +** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag - +** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite +** assumes that the strategy may visit at most one row. +** +** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then +** SQLite also assumes that if a call to the xUpdate() method is made as +** part of the same statement to delete or update a virtual table row and the +** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback +** any database changes. In other words, if the xUpdate() returns +** SQLITE_CONSTRAINT, the database contents must be exactly as they were +** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not +** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by +** the xUpdate method are automatically rolled back by SQLite. +** +** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info +** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). +** If a virtual table extension is +** used with an SQLite version earlier than 3.8.2, the results of attempting +** to read or write the estimatedRows field are undefined (but are likely +** to included crashing the application). The estimatedRows field should +** therefore only be used if [sqlite3_libversion_number()] returns a +** value greater than or equal to 3008002. Similarly, the idxFlags field +** was added for [version 3.9.0] ([dateof:3.9.0]). +** It may therefore only be used if +** sqlite3_libversion_number() returns a value greater than or equal to +** 3009000. +*/ +struct sqlite3_index_info { + /* Inputs */ + int nConstraint; /* Number of entries in aConstraint */ + struct sqlite3_index_constraint { + int iColumn; /* Column constrained. -1 for ROWID */ + unsigned char op; /* Constraint operator */ + unsigned char usable; /* True if this constraint is usable */ + int iTermOffset; /* Used internally - xBestIndex should ignore */ + } *aConstraint; /* Table of WHERE clause constraints */ + int nOrderBy; /* Number of terms in the ORDER BY clause */ + struct sqlite3_index_orderby { + int iColumn; /* Column number */ + unsigned char desc; /* True for DESC. False for ASC. */ + } *aOrderBy; /* The ORDER BY clause */ + /* Outputs */ + struct sqlite3_index_constraint_usage { + int argvIndex; /* if >0, constraint is part of argv to xFilter */ + unsigned char omit; /* Do not code a test for this constraint */ + } *aConstraintUsage; + int idxNum; /* Number used to identify the index */ + char *idxStr; /* String, possibly obtained from sqlite3_malloc */ + int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ + int orderByConsumed; /* True if output is already ordered */ + double estimatedCost; /* Estimated cost of using this index */ + /* Fields below are only available in SQLite 3.8.2 and later */ + sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ + /* Fields below are only available in SQLite 3.9.0 and later */ + int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ + /* Fields below are only available in SQLite 3.10.0 and later */ + sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ +}; + +/* +** CAPI3REF: Virtual Table Scan Flags +** +** Virtual table implementations are allowed to set the +** [sqlite3_index_info].idxFlags field to some combination of +** these bits. +*/ +#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ + +/* +** CAPI3REF: Virtual Table Constraint Operator Codes +** +** These macros defined the allowed values for the +** [sqlite3_index_info].aConstraint[].op field. Each value represents +** an operator that is part of a constraint term in the wHERE clause of +** a query that uses a [virtual table]. +*/ +#define SQLITE_INDEX_CONSTRAINT_EQ 2 +#define SQLITE_INDEX_CONSTRAINT_GT 4 +#define SQLITE_INDEX_CONSTRAINT_LE 8 +#define SQLITE_INDEX_CONSTRAINT_LT 16 +#define SQLITE_INDEX_CONSTRAINT_GE 32 +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 +#define SQLITE_INDEX_CONSTRAINT_NE 68 +#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 +#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 +#define SQLITE_INDEX_CONSTRAINT_IS 72 +#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 + +/* +** CAPI3REF: Register A Virtual Table Implementation +** METHOD: sqlite3 +** +** ^These routines are used to register a new [virtual table module] name. +** ^Module names must be registered before +** creating a new [virtual table] using the module and before using a +** preexisting [virtual table] for the module. +** +** ^The module name is registered on the [database connection] specified +** by the first parameter. ^The name of the module is given by the +** second parameter. ^The third parameter is a pointer to +** the implementation of the [virtual table module]. ^The fourth +** parameter is an arbitrary client data pointer that is passed through +** into the [xCreate] and [xConnect] methods of the virtual table module +** when a new virtual table is be being created or reinitialized. +** +** ^The sqlite3_create_module_v2() interface has a fifth parameter which +** is a pointer to a destructor for the pClientData. ^SQLite will +** invoke the destructor function (if it is not NULL) when SQLite +** no longer needs the pClientData pointer. ^The destructor will also +** be invoked if the call to sqlite3_create_module_v2() fails. +** ^The sqlite3_create_module() +** interface is equivalent to sqlite3_create_module_v2() with a NULL +** destructor. +*/ +SQLITE_API int sqlite3_create_module( + sqlite3 *db, /* SQLite connection to register module with */ + const char *zName, /* Name of the module */ + const sqlite3_module *p, /* Methods for the module */ + void *pClientData /* Client data for xCreate/xConnect */ +); +SQLITE_API int sqlite3_create_module_v2( + sqlite3 *db, /* SQLite connection to register module with */ + const char *zName, /* Name of the module */ + const sqlite3_module *p, /* Methods for the module */ + void *pClientData, /* Client data for xCreate/xConnect */ + void(*xDestroy)(void*) /* Module destructor function */ +); + +/* +** CAPI3REF: Virtual Table Instance Object +** KEYWORDS: sqlite3_vtab +** +** Every [virtual table module] implementation uses a subclass +** of this object to describe a particular instance +** of the [virtual table]. Each subclass will +** be tailored to the specific needs of the module implementation. +** The purpose of this superclass is to define certain fields that are +** common to all module implementations. +** +** ^Virtual tables methods can set an error message by assigning a +** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should +** take care that any prior string is freed by a call to [sqlite3_free()] +** prior to assigning a new string to zErrMsg. ^After the error message +** is delivered up to the client application, the string will be automatically +** freed by sqlite3_free() and the zErrMsg field will be zeroed. +*/ +struct sqlite3_vtab { + const sqlite3_module *pModule; /* The module for this virtual table */ + int nRef; /* Number of open cursors */ + char *zErrMsg; /* Error message from sqlite3_mprintf() */ + /* Virtual table implementations will typically add additional fields */ +}; + +/* +** CAPI3REF: Virtual Table Cursor Object +** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} +** +** Every [virtual table module] implementation uses a subclass of the +** following structure to describe cursors that point into the +** [virtual table] and are used +** to loop through the virtual table. Cursors are created using the +** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed +** by the [sqlite3_module.xClose | xClose] method. Cursors are used +** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods +** of the module. Each module implementation will define +** the content of a cursor structure to suit its own needs. +** +** This superclass exists in order to define fields of the cursor that +** are common to all implementations. +*/ +struct sqlite3_vtab_cursor { + sqlite3_vtab *pVtab; /* Virtual table of this cursor */ + /* Virtual table implementations will typically add additional fields */ +}; + +/* +** CAPI3REF: Declare The Schema Of A Virtual Table +** +** ^The [xCreate] and [xConnect] methods of a +** [virtual table module] call this interface +** to declare the format (the names and datatypes of the columns) of +** the virtual tables they implement. +*/ +SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); + +/* +** CAPI3REF: Overload A Function For A Virtual Table +** METHOD: sqlite3 +** +** ^(Virtual tables can provide alternative implementations of functions +** using the [xFindFunction] method of the [virtual table module]. +** But global versions of those functions +** must exist in order to be overloaded.)^ +** +** ^(This API makes sure a global version of a function with a particular +** name and number of parameters exists. If no such function exists +** before this API is called, a new function is created.)^ ^The implementation +** of the new function always causes an exception to be thrown. So +** the new function is not good for anything by itself. Its only +** purpose is to be a placeholder function that can be overloaded +** by a [virtual table]. +*/ +SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); + +/* +** The interface to the virtual-table mechanism defined above (back up +** to a comment remarkably similar to this one) is currently considered +** to be experimental. The interface might change in incompatible ways. +** If this is a problem for you, do not use the interface at this time. +** +** When the virtual-table mechanism stabilizes, we will declare the +** interface fixed, support it indefinitely, and remove this comment. +*/ + +/* +** CAPI3REF: A Handle To An Open BLOB +** KEYWORDS: {BLOB handle} {BLOB handles} +** +** An instance of this object represents an open BLOB on which +** [sqlite3_blob_open | incremental BLOB I/O] can be performed. +** ^Objects of this type are created by [sqlite3_blob_open()] +** and destroyed by [sqlite3_blob_close()]. +** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces +** can be used to read or write small subsections of the BLOB. +** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. +*/ +typedef struct sqlite3_blob sqlite3_blob; + +/* +** CAPI3REF: Open A BLOB For Incremental I/O +** METHOD: sqlite3 +** CONSTRUCTOR: sqlite3_blob +** +** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located +** in row iRow, column zColumn, table zTable in database zDb; +** in other words, the same BLOB that would be selected by: +** +** <pre> +** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; +** </pre>)^ +** +** ^(Parameter zDb is not the filename that contains the database, but +** rather the symbolic name of the database. For attached databases, this is +** the name that appears after the AS keyword in the [ATTACH] statement. +** For the main database file, the database name is "main". For TEMP +** tables, the database name is "temp".)^ +** +** ^If the flags parameter is non-zero, then the BLOB is opened for read +** and write access. ^If the flags parameter is zero, the BLOB is opened for +** read-only access. +** +** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored +** in *ppBlob. Otherwise an [error code] is returned and, unless the error +** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided +** the API is not misused, it is always safe to call [sqlite3_blob_close()] +** on *ppBlob after this function it returns. +** +** This function fails with SQLITE_ERROR if any of the following are true: +** <ul> +** <li> ^(Database zDb does not exist)^, +** <li> ^(Table zTable does not exist within database zDb)^, +** <li> ^(Table zTable is a WITHOUT ROWID table)^, +** <li> ^(Column zColumn does not exist)^, +** <li> ^(Row iRow is not present in the table)^, +** <li> ^(The specified column of row iRow contains a value that is not +** a TEXT or BLOB value)^, +** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE +** constraint and the blob is being opened for read/write access)^, +** <li> ^([foreign key constraints | Foreign key constraints] are enabled, +** column zColumn is part of a [child key] definition and the blob is +** being opened for read/write access)^. +** </ul> +** +** ^Unless it returns SQLITE_MISUSE, this function sets the +** [database connection] error code and message accessible via +** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. +** +** A BLOB referenced by sqlite3_blob_open() may be read using the +** [sqlite3_blob_read()] interface and modified by using +** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a +** different row of the same table using the [sqlite3_blob_reopen()] +** interface. However, the column, table, or database of a [BLOB handle] +** cannot be changed after the [BLOB handle] is opened. +** +** ^(If the row that a BLOB handle points to is modified by an +** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects +** then the BLOB handle is marked as "expired". +** This is true if any column of the row is changed, even a column +** other than the one the BLOB handle is open on.)^ +** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for +** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. +** ^(Changes written into a BLOB prior to the BLOB expiring are not +** rolled back by the expiration of the BLOB. Such changes will eventually +** commit if the transaction continues to completion.)^ +** +** ^Use the [sqlite3_blob_bytes()] interface to determine the size of +** the opened blob. ^The size of a blob may not be changed by this +** interface. Use the [UPDATE] SQL command to change the size of a +** blob. +** +** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces +** and the built-in [zeroblob] SQL function may be used to create a +** zero-filled blob to read or write using the incremental-blob interface. +** +** To avoid a resource leak, every open [BLOB handle] should eventually +** be released by a call to [sqlite3_blob_close()]. +** +** See also: [sqlite3_blob_close()], +** [sqlite3_blob_reopen()], [sqlite3_blob_read()], +** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. +*/ +SQLITE_API int sqlite3_blob_open( + sqlite3*, + const char *zDb, + const char *zTable, + const char *zColumn, + sqlite3_int64 iRow, + int flags, + sqlite3_blob **ppBlob +); + +/* +** CAPI3REF: Move a BLOB Handle to a New Row +** METHOD: sqlite3_blob +** +** ^This function is used to move an existing [BLOB handle] so that it points +** to a different row of the same database table. ^The new row is identified +** by the rowid value passed as the second argument. Only the row can be +** changed. ^The database, table and column on which the blob handle is open +** remain the same. Moving an existing [BLOB handle] to a new row is +** faster than closing the existing handle and opening a new one. +** +** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - +** it must exist and there must be either a blob or text value stored in +** the nominated column.)^ ^If the new row is not present in the table, or if +** it does not contain a blob or text value, or if another error occurs, an +** SQLite error code is returned and the blob handle is considered aborted. +** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or +** [sqlite3_blob_reopen()] on an aborted blob handle immediately return +** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle +** always returns zero. +** +** ^This function sets the database handle error code and message. +*/ +SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); + +/* +** CAPI3REF: Close A BLOB Handle +** DESTRUCTOR: sqlite3_blob +** +** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed +** unconditionally. Even if this routine returns an error code, the +** handle is still closed.)^ +** +** ^If the blob handle being closed was opened for read-write access, and if +** the database is in auto-commit mode and there are no other open read-write +** blob handles or active write statements, the current transaction is +** committed. ^If an error occurs while committing the transaction, an error +** code is returned and the transaction rolled back. +** +** Calling this function with an argument that is not a NULL pointer or an +** open blob handle results in undefined behaviour. ^Calling this routine +** with a null pointer (such as would be returned by a failed call to +** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function +** is passed a valid open blob handle, the values returned by the +** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. +*/ +SQLITE_API int sqlite3_blob_close(sqlite3_blob *); + +/* +** CAPI3REF: Return The Size Of An Open BLOB +** METHOD: sqlite3_blob +** +** ^Returns the size in bytes of the BLOB accessible via the +** successfully opened [BLOB handle] in its only argument. ^The +** incremental blob I/O routines can only read or overwriting existing +** blob content; they cannot change the size of a blob. +** +** This routine only works on a [BLOB handle] which has been created +** by a prior successful call to [sqlite3_blob_open()] and which has not +** been closed by [sqlite3_blob_close()]. Passing any other pointer in +** to this routine results in undefined and probably undesirable behavior. +*/ +SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); + +/* +** CAPI3REF: Read Data From A BLOB Incrementally +** METHOD: sqlite3_blob +** +** ^(This function is used to read data from an open [BLOB handle] into a +** caller-supplied buffer. N bytes of data are copied into buffer Z +** from the open BLOB, starting at offset iOffset.)^ +** +** ^If offset iOffset is less than N bytes from the end of the BLOB, +** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is +** less than zero, [SQLITE_ERROR] is returned and no data is read. +** ^The size of the blob (and hence the maximum value of N+iOffset) +** can be determined using the [sqlite3_blob_bytes()] interface. +** +** ^An attempt to read from an expired [BLOB handle] fails with an +** error code of [SQLITE_ABORT]. +** +** ^(On success, sqlite3_blob_read() returns SQLITE_OK. +** Otherwise, an [error code] or an [extended error code] is returned.)^ +** +** This routine only works on a [BLOB handle] which has been created +** by a prior successful call to [sqlite3_blob_open()] and which has not +** been closed by [sqlite3_blob_close()]. Passing any other pointer in +** to this routine results in undefined and probably undesirable behavior. +** +** See also: [sqlite3_blob_write()]. +*/ +SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); + +/* +** CAPI3REF: Write Data Into A BLOB Incrementally +** METHOD: sqlite3_blob +** +** ^(This function is used to write data into an open [BLOB handle] from a +** caller-supplied buffer. N bytes of data are copied from the buffer Z +** into the open BLOB, starting at offset iOffset.)^ +** +** ^(On success, sqlite3_blob_write() returns SQLITE_OK. +** Otherwise, an [error code] or an [extended error code] is returned.)^ +** ^Unless SQLITE_MISUSE is returned, this function sets the +** [database connection] error code and message accessible via +** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. +** +** ^If the [BLOB handle] passed as the first argument was not opened for +** writing (the flags parameter to [sqlite3_blob_open()] was zero), +** this function returns [SQLITE_READONLY]. +** +** This function may only modify the contents of the BLOB; it is +** not possible to increase the size of a BLOB using this API. +** ^If offset iOffset is less than N bytes from the end of the BLOB, +** [SQLITE_ERROR] is returned and no data is written. The size of the +** BLOB (and hence the maximum value of N+iOffset) can be determined +** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less +** than zero [SQLITE_ERROR] is returned and no data is written. +** +** ^An attempt to write to an expired [BLOB handle] fails with an +** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred +** before the [BLOB handle] expired are not rolled back by the +** expiration of the handle, though of course those changes might +** have been overwritten by the statement that expired the BLOB handle +** or by other independent statements. +** +** This routine only works on a [BLOB handle] which has been created +** by a prior successful call to [sqlite3_blob_open()] and which has not +** been closed by [sqlite3_blob_close()]. Passing any other pointer in +** to this routine results in undefined and probably undesirable behavior. +** +** See also: [sqlite3_blob_read()]. +*/ +SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); + +/* +** CAPI3REF: Virtual File System Objects +** +** A virtual filesystem (VFS) is an [sqlite3_vfs] object +** that SQLite uses to interact +** with the underlying operating system. Most SQLite builds come with a +** single default VFS that is appropriate for the host computer. +** New VFSes can be registered and existing VFSes can be unregistered. +** The following interfaces are provided. +** +** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. +** ^Names are case sensitive. +** ^Names are zero-terminated UTF-8 strings. +** ^If there is no match, a NULL pointer is returned. +** ^If zVfsName is NULL then the default VFS is returned. +** +** ^New VFSes are registered with sqlite3_vfs_register(). +** ^Each new VFS becomes the default VFS if the makeDflt flag is set. +** ^The same VFS can be registered multiple times without injury. +** ^To make an existing VFS into the default VFS, register it again +** with the makeDflt flag set. If two different VFSes with the +** same name are registered, the behavior is undefined. If a +** VFS is registered with a name that is NULL or an empty string, +** then the behavior is undefined. +** +** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. +** ^(If the default VFS is unregistered, another VFS is chosen as +** the default. The choice for the new VFS is arbitrary.)^ +*/ +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); + +/* +** CAPI3REF: Mutexes +** +** The SQLite core uses these routines for thread +** synchronization. Though they are intended for internal +** use by SQLite, code that links against SQLite is +** permitted to use any of these routines. +** +** The SQLite source code contains multiple implementations +** of these mutex routines. An appropriate implementation +** is selected automatically at compile-time. The following +** implementations are available in the SQLite core: +** +** <ul> +** <li> SQLITE_MUTEX_PTHREADS +** <li> SQLITE_MUTEX_W32 +** <li> SQLITE_MUTEX_NOOP +** </ul> +** +** The SQLITE_MUTEX_NOOP implementation is a set of routines +** that does no real locking and is appropriate for use in +** a single-threaded application. The SQLITE_MUTEX_PTHREADS and +** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix +** and Windows. +** +** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor +** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex +** implementation is included with the library. In this case the +** application must supply a custom mutex implementation using the +** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function +** before calling sqlite3_initialize() or any other public sqlite3_ +** function that calls sqlite3_initialize(). +** +** ^The sqlite3_mutex_alloc() routine allocates a new +** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc() +** routine returns NULL if it is unable to allocate the requested +** mutex. The argument to sqlite3_mutex_alloc() must one of these +** integer constants: +** +** <ul> +** <li> SQLITE_MUTEX_FAST +** <li> SQLITE_MUTEX_RECURSIVE +** <li> SQLITE_MUTEX_STATIC_MASTER +** <li> SQLITE_MUTEX_STATIC_MEM +** <li> SQLITE_MUTEX_STATIC_OPEN +** <li> SQLITE_MUTEX_STATIC_PRNG +** <li> SQLITE_MUTEX_STATIC_LRU +** <li> SQLITE_MUTEX_STATIC_PMEM +** <li> SQLITE_MUTEX_STATIC_APP1 +** <li> SQLITE_MUTEX_STATIC_APP2 +** <li> SQLITE_MUTEX_STATIC_APP3 +** <li> SQLITE_MUTEX_STATIC_VFS1 +** <li> SQLITE_MUTEX_STATIC_VFS2 +** <li> SQLITE_MUTEX_STATIC_VFS3 +** </ul> +** +** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) +** cause sqlite3_mutex_alloc() to create +** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE +** is used but not necessarily so when SQLITE_MUTEX_FAST is used. +** The mutex implementation does not need to make a distinction +** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does +** not want to. SQLite will only request a recursive mutex in +** cases where it really needs one. If a faster non-recursive mutex +** implementation is available on the host platform, the mutex subsystem +** might return such a mutex in response to SQLITE_MUTEX_FAST. +** +** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other +** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return +** a pointer to a static preexisting mutex. ^Nine static mutexes are +** used by the current version of SQLite. Future versions of SQLite +** may add additional static mutexes. Static mutexes are for internal +** use by SQLite only. Applications that use SQLite mutexes should +** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or +** SQLITE_MUTEX_RECURSIVE. +** +** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST +** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() +** returns a different mutex on every call. ^For the static +** mutex types, the same mutex is returned on every call that has +** the same type number. +** +** ^The sqlite3_mutex_free() routine deallocates a previously +** allocated dynamic mutex. Attempting to deallocate a static +** mutex results in undefined behavior. +** +** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt +** to enter a mutex. ^If another thread is already within the mutex, +** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return +** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] +** upon successful entry. ^(Mutexes created using +** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. +** In such cases, the +** mutex must be exited an equal number of times before another thread +** can enter.)^ If the same thread tries to enter any mutex other +** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined. +** +** ^(Some systems (for example, Windows 95) do not support the operation +** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() +** will always return SQLITE_BUSY. The SQLite core only ever uses +** sqlite3_mutex_try() as an optimization so this is acceptable +** behavior.)^ +** +** ^The sqlite3_mutex_leave() routine exits a mutex that was +** previously entered by the same thread. The behavior +** is undefined if the mutex is not currently entered by the +** calling thread or is not currently allocated. +** +** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or +** sqlite3_mutex_leave() is a NULL pointer, then all three routines +** behave as no-ops. +** +** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. +*/ +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); + +/* +** CAPI3REF: Mutex Methods Object +** +** An instance of this structure defines the low-level routines +** used to allocate and use mutexes. +** +** Usually, the default mutex implementations provided by SQLite are +** sufficient, however the application has the option of substituting a custom +** implementation for specialized deployments or systems for which SQLite +** does not provide a suitable implementation. In this case, the application +** creates and populates an instance of this structure to pass +** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. +** Additionally, an instance of this structure can be used as an +** output variable when querying the system for the current mutex +** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. +** +** ^The xMutexInit method defined by this structure is invoked as +** part of system initialization by the sqlite3_initialize() function. +** ^The xMutexInit routine is called by SQLite exactly once for each +** effective call to [sqlite3_initialize()]. +** +** ^The xMutexEnd method defined by this structure is invoked as +** part of system shutdown by the sqlite3_shutdown() function. The +** implementation of this method is expected to release all outstanding +** resources obtained by the mutex methods implementation, especially +** those obtained by the xMutexInit method. ^The xMutexEnd() +** interface is invoked exactly once for each call to [sqlite3_shutdown()]. +** +** ^(The remaining seven methods defined by this structure (xMutexAlloc, +** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and +** xMutexNotheld) implement the following interfaces (respectively): +** +** <ul> +** <li> [sqlite3_mutex_alloc()] </li> +** <li> [sqlite3_mutex_free()] </li> +** <li> [sqlite3_mutex_enter()] </li> +** <li> [sqlite3_mutex_try()] </li> +** <li> [sqlite3_mutex_leave()] </li> +** <li> [sqlite3_mutex_held()] </li> +** <li> [sqlite3_mutex_notheld()] </li> +** </ul>)^ +** +** The only difference is that the public sqlite3_XXX functions enumerated +** above silently ignore any invocations that pass a NULL pointer instead +** of a valid mutex handle. The implementations of the methods defined +** by this structure are not required to handle this case, the results +** of passing a NULL pointer instead of a valid mutex handle are undefined +** (i.e. it is acceptable to provide an implementation that segfaults if +** it is passed a NULL pointer). +** +** The xMutexInit() method must be threadsafe. It must be harmless to +** invoke xMutexInit() multiple times within the same process and without +** intervening calls to xMutexEnd(). Second and subsequent calls to +** xMutexInit() must be no-ops. +** +** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] +** and its associates). Similarly, xMutexAlloc() must not use SQLite memory +** allocation for a static mutex. ^However xMutexAlloc() may use SQLite +** memory allocation for a fast or recursive mutex. +** +** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is +** called, but only if the prior call to xMutexInit returned SQLITE_OK. +** If xMutexInit fails in any way, it is expected to clean up after itself +** prior to returning. +*/ +typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; +struct sqlite3_mutex_methods { + int (*xMutexInit)(void); + int (*xMutexEnd)(void); + sqlite3_mutex *(*xMutexAlloc)(int); + void (*xMutexFree)(sqlite3_mutex *); + void (*xMutexEnter)(sqlite3_mutex *); + int (*xMutexTry)(sqlite3_mutex *); + void (*xMutexLeave)(sqlite3_mutex *); + int (*xMutexHeld)(sqlite3_mutex *); + int (*xMutexNotheld)(sqlite3_mutex *); +}; + +/* +** CAPI3REF: Mutex Verification Routines +** +** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines +** are intended for use inside assert() statements. The SQLite core +** never uses these routines except inside an assert() and applications +** are advised to follow the lead of the core. The SQLite core only +** provides implementations for these routines when it is compiled +** with the SQLITE_DEBUG flag. External mutex implementations +** are only required to provide these routines if SQLITE_DEBUG is +** defined and if NDEBUG is not defined. +** +** These routines should return true if the mutex in their argument +** is held or not held, respectively, by the calling thread. +** +** The implementation is not required to provide versions of these +** routines that actually work. If the implementation does not provide working +** versions of these routines, it should at least provide stubs that always +** return true so that one does not get spurious assertion failures. +** +** If the argument to sqlite3_mutex_held() is a NULL pointer then +** the routine should return 1. This seems counter-intuitive since +** clearly the mutex cannot be held if it does not exist. But +** the reason the mutex does not exist is because the build is not +** using mutexes. And we do not want the assert() containing the +** call to sqlite3_mutex_held() to fail, so a non-zero return is +** the appropriate thing to do. The sqlite3_mutex_notheld() +** interface should also return 1 when given a NULL pointer. +*/ +#ifndef NDEBUG +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); +#endif + +/* +** CAPI3REF: Mutex Types +** +** The [sqlite3_mutex_alloc()] interface takes a single argument +** which is one of these integer constants. +** +** The set of static mutexes may change from one SQLite release to the +** next. Applications that override the built-in mutex logic must be +** prepared to accommodate additional static mutexes. +*/ +#define SQLITE_MUTEX_FAST 0 +#define SQLITE_MUTEX_RECURSIVE 1 +#define SQLITE_MUTEX_STATIC_MASTER 2 +#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ +#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ +#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ +#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ +#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ +#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ +#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ +#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ +#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ +#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ +#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ +#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ +#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ + +/* +** CAPI3REF: Retrieve the mutex for a database connection +** METHOD: sqlite3 +** +** ^This interface returns a pointer the [sqlite3_mutex] object that +** serializes access to the [database connection] given in the argument +** when the [threading mode] is Serialized. +** ^If the [threading mode] is Single-thread or Multi-thread then this +** routine returns a NULL pointer. +*/ +SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); + +/* +** CAPI3REF: Low-Level Control Of Database Files +** METHOD: sqlite3 +** KEYWORDS: {file control} +** +** ^The [sqlite3_file_control()] interface makes a direct call to the +** xFileControl method for the [sqlite3_io_methods] object associated +** with a particular database identified by the second argument. ^The +** name of the database is "main" for the main database or "temp" for the +** TEMP database, or the name that appears after the AS keyword for +** databases that are added using the [ATTACH] SQL command. +** ^A NULL pointer can be used in place of "main" to refer to the +** main database file. +** ^The third and fourth parameters to this routine +** are passed directly through to the second and third parameters of +** the xFileControl method. ^The return value of the xFileControl +** method becomes the return value of this routine. +** +** A few opcodes for [sqlite3_file_control()] are handled directly +** by the SQLite core and never invoke the +** sqlite3_io_methods.xFileControl method. +** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes +** a pointer to the underlying [sqlite3_file] object to be written into +** the space pointed to by the 4th parameter. The +** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns +** the [sqlite3_file] object associated with the journal file instead of +** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns +** a pointer to the underlying [sqlite3_vfs] object for the file. +** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter +** from the pager. +** +** ^If the second parameter (zDbName) does not match the name of any +** open database file, then SQLITE_ERROR is returned. ^This error +** code is not remembered and will not be recalled by [sqlite3_errcode()] +** or [sqlite3_errmsg()]. The underlying xFileControl method might +** also return SQLITE_ERROR. There is no way to distinguish between +** an incorrect zDbName and an SQLITE_ERROR return from the underlying +** xFileControl method. +** +** See also: [file control opcodes] +*/ +SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); + +/* +** CAPI3REF: Testing Interface +** +** ^The sqlite3_test_control() interface is used to read out internal +** state of SQLite and to inject faults into SQLite for testing +** purposes. ^The first parameter is an operation code that determines +** the number, meaning, and operation of all subsequent parameters. +** +** This interface is not for use by applications. It exists solely +** for verifying the correct operation of the SQLite library. Depending +** on how the SQLite library is compiled, this interface might not exist. +** +** The details of the operation codes, their meanings, the parameters +** they take, and what they do are all subject to change without notice. +** Unlike most of the SQLite API, this function is not guaranteed to +** operate consistently from one release to the next. +*/ +SQLITE_API int sqlite3_test_control(int op, ...); + +/* +** CAPI3REF: Testing Interface Operation Codes +** +** These constants are the valid operation code parameters used +** as the first argument to [sqlite3_test_control()]. +** +** These parameters and their meanings are subject to change +** without notice. These values are for testing purposes only. +** Applications should not use any of these parameters or the +** [sqlite3_test_control()] interface. +*/ +#define SQLITE_TESTCTRL_FIRST 5 +#define SQLITE_TESTCTRL_PRNG_SAVE 5 +#define SQLITE_TESTCTRL_PRNG_RESTORE 6 +#define SQLITE_TESTCTRL_PRNG_RESET 7 +#define SQLITE_TESTCTRL_BITVEC_TEST 8 +#define SQLITE_TESTCTRL_FAULT_INSTALL 9 +#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 +#define SQLITE_TESTCTRL_PENDING_BYTE 11 +#define SQLITE_TESTCTRL_ASSERT 12 +#define SQLITE_TESTCTRL_ALWAYS 13 +#define SQLITE_TESTCTRL_RESERVE 14 +#define SQLITE_TESTCTRL_OPTIMIZATIONS 15 +#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ +#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ +#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 +#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 +#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ +#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 +#define SQLITE_TESTCTRL_NEVER_CORRUPT 20 +#define SQLITE_TESTCTRL_VDBE_COVERAGE 21 +#define SQLITE_TESTCTRL_BYTEORDER 22 +#define SQLITE_TESTCTRL_ISINIT 23 +#define SQLITE_TESTCTRL_SORTER_MMAP 24 +#define SQLITE_TESTCTRL_IMPOSTER 25 +#define SQLITE_TESTCTRL_PARSER_COVERAGE 26 +#define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */ + +/* +** CAPI3REF: SQL Keyword Checking +** +** These routines provide access to the set of SQL language keywords +** recognized by SQLite. Applications can uses these routines to determine +** whether or not a specific identifier needs to be escaped (for example, +** by enclosing in double-quotes) so as not to confuse the parser. +** +** The sqlite3_keyword_count() interface returns the number of distinct +** keywords understood by SQLite. +** +** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and +** makes *Z point to that keyword expressed as UTF8 and writes the number +** of bytes in the keyword into *L. The string that *Z points to is not +** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns +** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z +** or L are NULL or invalid pointers then calls to +** sqlite3_keyword_name(N,Z,L) result in undefined behavior. +** +** The sqlite3_keyword_check(Z,L) interface checks to see whether or not +** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero +** if it is and zero if not. +** +** The parser used by SQLite is forgiving. It is often possible to use +** a keyword as an identifier as long as such use does not result in a +** parsing ambiguity. For example, the statement +** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and +** creates a new table named "BEGIN" with three columns named +** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid +** using keywords as identifiers. Common techniques used to avoid keyword +** name collisions include: +** <ul> +** <li> Put all identifier names inside double-quotes. This is the official +** SQL way to escape identifier names. +** <li> Put identifier names inside [...]. This is not standard SQL, +** but it is what SQL Server does and so lots of programmers use this +** technique. +** <li> Begin every identifier with the letter "Z" as no SQL keywords start +** with "Z". +** <li> Include a digit somewhere in every identifier name. +** </ul> +** +** Note that the number of keywords understood by SQLite can depend on +** compile-time options. For example, "VACUUM" is not a keyword if +** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also, +** new keywords may be added to future releases of SQLite. +*/ +SQLITE_API int sqlite3_keyword_count(void); +SQLITE_API int sqlite3_keyword_name(int,const char**,int*); +SQLITE_API int sqlite3_keyword_check(const char*,int); + +/* +** CAPI3REF: Dynamic String Object +** KEYWORDS: {dynamic string} +** +** An instance of the sqlite3_str object contains a dynamically-sized +** string under construction. +** +** The lifecycle of an sqlite3_str object is as follows: +** <ol> +** <li> ^The sqlite3_str object is created using [sqlite3_str_new()]. +** <li> ^Text is appended to the sqlite3_str object using various +** methods, such as [sqlite3_str_appendf()]. +** <li> ^The sqlite3_str object is destroyed and the string it created +** is returned using the [sqlite3_str_finish()] interface. +** </ol> +*/ +typedef struct sqlite3_str sqlite3_str; + +/* +** CAPI3REF: Create A New Dynamic String Object +** CONSTRUCTOR: sqlite3_str +** +** ^The [sqlite3_str_new(D)] interface allocates and initializes +** a new [sqlite3_str] object. To avoid memory leaks, the object returned by +** [sqlite3_str_new()] must be freed by a subsequent call to +** [sqlite3_str_finish(X)]. +** +** ^The [sqlite3_str_new(D)] interface always returns a pointer to a +** valid [sqlite3_str] object, though in the event of an out-of-memory +** error the returned object might be a special singleton that will +** silently reject new text, always return SQLITE_NOMEM from +** [sqlite3_str_errcode()], always return 0 for +** [sqlite3_str_length()], and always return NULL from +** [sqlite3_str_finish(X)]. It is always safe to use the value +** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter +** to any of the other [sqlite3_str] methods. +** +** The D parameter to [sqlite3_str_new(D)] may be NULL. If the +** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum +** length of the string contained in the [sqlite3_str] object will be +** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead +** of [SQLITE_MAX_LENGTH]. +*/ +SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*); + +/* +** CAPI3REF: Finalize A Dynamic String +** DESTRUCTOR: sqlite3_str +** +** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X +** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()] +** that contains the constructed string. The calling application should +** pass the returned value to [sqlite3_free()] to avoid a memory leak. +** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any +** errors were encountered during construction of the string. ^The +** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the +** string in [sqlite3_str] object X is zero bytes long. +*/ +SQLITE_API char *sqlite3_str_finish(sqlite3_str*); + +/* +** CAPI3REF: Add Content To A Dynamic String +** METHOD: sqlite3_str +** +** These interfaces add content to an sqlite3_str object previously obtained +** from [sqlite3_str_new()]. +** +** ^The [sqlite3_str_appendf(X,F,...)] and +** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf] +** functionality of SQLite to append formatted text onto the end of +** [sqlite3_str] object X. +** +** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S +** onto the end of the [sqlite3_str] object X. N must be non-negative. +** S must contain at least N non-zero bytes of content. To append a +** zero-terminated string in its entirety, use the [sqlite3_str_appendall()] +** method instead. +** +** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of +** zero-terminated string S onto the end of [sqlite3_str] object X. +** +** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the +** single-byte character C onto the end of [sqlite3_str] object X. +** ^This method can be used, for example, to add whitespace indentation. +** +** ^The [sqlite3_str_reset(X)] method resets the string under construction +** inside [sqlite3_str] object X back to zero bytes in length. +** +** These methods do not return a result code. ^If an error occurs, that fact +** is recorded in the [sqlite3_str] object and can be recovered by a +** subsequent call to [sqlite3_str_errcode(X)]. +*/ +SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...); +SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list); +SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N); +SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn); +SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C); +SQLITE_API void sqlite3_str_reset(sqlite3_str*); + +/* +** CAPI3REF: Status Of A Dynamic String +** METHOD: sqlite3_str +** +** These interfaces return the current status of an [sqlite3_str] object. +** +** ^If any prior errors have occurred while constructing the dynamic string +** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return +** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns +** [SQLITE_NOMEM] following any out-of-memory error, or +** [SQLITE_TOOBIG] if the size of the dynamic string exceeds +** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors. +** +** ^The [sqlite3_str_length(X)] method returns the current length, in bytes, +** of the dynamic string under construction in [sqlite3_str] object X. +** ^The length returned by [sqlite3_str_length(X)] does not include the +** zero-termination byte. +** +** ^The [sqlite3_str_value(X)] method returns a pointer to the current +** content of the dynamic string under construction in X. The value +** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X +** and might be freed or altered by any subsequent method on the same +** [sqlite3_str] object. Applications must not used the pointer returned +** [sqlite3_str_value(X)] after any subsequent method call on the same +** object. ^Applications may change the content of the string returned +** by [sqlite3_str_value(X)] as long as they do not write into any bytes +** outside the range of 0 to [sqlite3_str_length(X)] and do not read or +** write any byte after any subsequent sqlite3_str method call. +*/ +SQLITE_API int sqlite3_str_errcode(sqlite3_str*); +SQLITE_API int sqlite3_str_length(sqlite3_str*); +SQLITE_API char *sqlite3_str_value(sqlite3_str*); + +/* +** CAPI3REF: SQLite Runtime Status +** +** ^These interfaces are used to retrieve runtime status information +** about the performance of SQLite, and optionally to reset various +** highwater marks. ^The first argument is an integer code for +** the specific parameter to measure. ^(Recognized integer codes +** are of the form [status parameters | SQLITE_STATUS_...].)^ +** ^The current value of the parameter is returned into *pCurrent. +** ^The highest recorded value is returned in *pHighwater. ^If the +** resetFlag is true, then the highest record value is reset after +** *pHighwater is written. ^(Some parameters do not record the highest +** value. For those parameters +** nothing is written into *pHighwater and the resetFlag is ignored.)^ +** ^(Other parameters record only the highwater mark and not the current +** value. For these latter parameters nothing is written into *pCurrent.)^ +** +** ^The sqlite3_status() and sqlite3_status64() routines return +** SQLITE_OK on success and a non-zero [error code] on failure. +** +** If either the current value or the highwater mark is too large to +** be represented by a 32-bit integer, then the values returned by +** sqlite3_status() are undefined. +** +** See also: [sqlite3_db_status()] +*/ +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); +SQLITE_API int sqlite3_status64( + int op, + sqlite3_int64 *pCurrent, + sqlite3_int64 *pHighwater, + int resetFlag +); + + +/* +** CAPI3REF: Status Parameters +** KEYWORDS: {status parameters} +** +** These integer constants designate various run-time status parameters +** that can be returned by [sqlite3_status()]. +** +** <dl> +** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> +** <dd>This parameter is the current amount of memory checked out +** using [sqlite3_malloc()], either directly or indirectly. The +** figure includes calls made to [sqlite3_malloc()] by the application +** and internal memory usage by the SQLite library. Auxiliary page-cache +** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in +** this parameter. The amount returned is the sum of the allocation +** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ +** +** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> +** <dd>This parameter records the largest memory allocation request +** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their +** internal equivalents). Only the value returned in the +** *pHighwater parameter to [sqlite3_status()] is of interest. +** The value written into the *pCurrent parameter is undefined.</dd>)^ +** +** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> +** <dd>This parameter records the number of separate memory allocations +** currently checked out.</dd>)^ +** +** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> +** <dd>This parameter returns the number of pages used out of the +** [pagecache memory allocator] that was configured using +** [SQLITE_CONFIG_PAGECACHE]. The +** value returned is in pages, not in bytes.</dd>)^ +** +** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] +** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> +** <dd>This parameter returns the number of bytes of page cache +** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] +** buffer and where forced to overflow to [sqlite3_malloc()]. The +** returned value includes allocations that overflowed because they +** where too large (they were larger than the "sz" parameter to +** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because +** no space was left in the page cache.</dd>)^ +** +** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> +** <dd>This parameter records the largest memory allocation request +** handed to [pagecache memory allocator]. Only the value returned in the +** *pHighwater parameter to [sqlite3_status()] is of interest. +** The value written into the *pCurrent parameter is undefined.</dd>)^ +** +** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt> +** <dd>No longer used.</dd> +** +** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> +** <dd>No longer used.</dd> +** +** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt> +** <dd>No longer used.</dd> +** +** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> +** <dd>The *pHighwater parameter records the deepest parser stack. +** The *pCurrent value is undefined. The *pHighwater value is only +** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ +** </dl> +** +** New status parameters may be added from time to time. +*/ +#define SQLITE_STATUS_MEMORY_USED 0 +#define SQLITE_STATUS_PAGECACHE_USED 1 +#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 +#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */ +#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */ +#define SQLITE_STATUS_MALLOC_SIZE 5 +#define SQLITE_STATUS_PARSER_STACK 6 +#define SQLITE_STATUS_PAGECACHE_SIZE 7 +#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */ +#define SQLITE_STATUS_MALLOC_COUNT 9 + +/* +** CAPI3REF: Database Connection Status +** METHOD: sqlite3 +** +** ^This interface is used to retrieve runtime status information +** about a single [database connection]. ^The first argument is the +** database connection object to be interrogated. ^The second argument +** is an integer constant, taken from the set of +** [SQLITE_DBSTATUS options], that +** determines the parameter to interrogate. The set of +** [SQLITE_DBSTATUS options] is likely +** to grow in future releases of SQLite. +** +** ^The current value of the requested parameter is written into *pCur +** and the highest instantaneous value is written into *pHiwtr. ^If +** the resetFlg is true, then the highest instantaneous value is +** reset back down to the current value. +** +** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a +** non-zero [error code] on failure. +** +** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. +*/ +SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); + +/* +** CAPI3REF: Status Parameters for database connections +** KEYWORDS: {SQLITE_DBSTATUS options} +** +** These constants are the available integer "verbs" that can be passed as +** the second argument to the [sqlite3_db_status()] interface. +** +** New verbs may be added in future releases of SQLite. Existing verbs +** might be discontinued. Applications should check the return code from +** [sqlite3_db_status()] to make sure that the call worked. +** The [sqlite3_db_status()] interface will return a non-zero error code +** if a discontinued or unsupported verb is invoked. +** +** <dl> +** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> +** <dd>This parameter returns the number of lookaside memory slots currently +** checked out.</dd>)^ +** +** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> +** <dd>This parameter returns the number malloc attempts that were +** satisfied using lookaside memory. Only the high-water value is meaningful; +** the current value is always zero.)^ +** +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> +** <dd>This parameter returns the number malloc attempts that might have +** been satisfied using lookaside memory but failed due to the amount of +** memory requested being larger than the lookaside slot size. +** Only the high-water value is meaningful; +** the current value is always zero.)^ +** +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> +** <dd>This parameter returns the number malloc attempts that might have +** been satisfied using lookaside memory but failed due to all lookaside +** memory already being in use. +** Only the high-water value is meaningful; +** the current value is always zero.)^ +** +** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> +** <dd>This parameter returns the approximate number of bytes of heap +** memory used by all pager caches associated with the database connection.)^ +** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. +** +** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] +** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt> +** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a +** pager cache is shared between two or more connections the bytes of heap +** memory used by that pager cache is divided evenly between the attached +** connections.)^ In other words, if none of the pager caches associated +** with the database connection are shared, this request returns the same +** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are +** shared, the value returned by this call will be smaller than that returned +** by DBSTATUS_CACHE_USED. ^The highwater mark associated with +** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0. +** +** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> +** <dd>This parameter returns the approximate number of bytes of heap +** memory used to store the schema for all databases associated +** with the connection - main, temp, and any [ATTACH]-ed databases.)^ +** ^The full amount of memory used by the schemas is reported, even if the +** schema memory is shared with other database connections due to +** [shared cache mode] being enabled. +** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. +** +** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> +** <dd>This parameter returns the approximate number of bytes of heap +** and lookaside memory used by all prepared statements associated with +** the database connection.)^ +** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. +** </dd> +** +** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt> +** <dd>This parameter returns the number of pager cache hits that have +** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT +** is always 0. +** </dd> +** +** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> +** <dd>This parameter returns the number of pager cache misses that have +** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS +** is always 0. +** </dd> +** +** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> +** <dd>This parameter returns the number of dirty cache entries that have +** been written to disk. Specifically, the number of pages written to the +** wal file in wal mode databases, or the number of pages written to the +** database file in rollback mode databases. Any pages written as part of +** transaction rollback or database recovery operations are not included. +** If an IO or other error occurs while writing a page to disk, the effect +** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The +** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. +** </dd> +** +** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt> +** <dd>This parameter returns the number of dirty cache entries that have +** been written to disk in the middle of a transaction due to the page +** cache overflowing. Transactions are more efficient if they are written +** to disk all at once. When pages spill mid-transaction, that introduces +** additional overhead. This parameter can be used help identify +** inefficiencies that can be resolve by increasing the cache size. +** </dd> +** +** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt> +** <dd>This parameter returns zero for the current value if and only if +** all foreign key constraints (deferred or immediate) have been +** resolved.)^ ^The highwater mark is always 0. +** </dd> +** </dl> +*/ +#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 +#define SQLITE_DBSTATUS_CACHE_USED 1 +#define SQLITE_DBSTATUS_SCHEMA_USED 2 +#define SQLITE_DBSTATUS_STMT_USED 3 +#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 +#define SQLITE_DBSTATUS_CACHE_HIT 7 +#define SQLITE_DBSTATUS_CACHE_MISS 8 +#define SQLITE_DBSTATUS_CACHE_WRITE 9 +#define SQLITE_DBSTATUS_DEFERRED_FKS 10 +#define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 +#define SQLITE_DBSTATUS_CACHE_SPILL 12 +#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ + + +/* +** CAPI3REF: Prepared Statement Status +** METHOD: sqlite3_stmt +** +** ^(Each prepared statement maintains various +** [SQLITE_STMTSTATUS counters] that measure the number +** of times it has performed specific operations.)^ These counters can +** be used to monitor the performance characteristics of the prepared +** statements. For example, if the number of table steps greatly exceeds +** the number of table searches or result rows, that would tend to indicate +** that the prepared statement is using a full table scan rather than +** an index. +** +** ^(This interface is used to retrieve and reset counter values from +** a [prepared statement]. The first argument is the prepared statement +** object to be interrogated. The second argument +** is an integer code for a specific [SQLITE_STMTSTATUS counter] +** to be interrogated.)^ +** ^The current value of the requested counter is returned. +** ^If the resetFlg is true, then the counter is reset to zero after this +** interface call returns. +** +** See also: [sqlite3_status()] and [sqlite3_db_status()]. +*/ +SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); + +/* +** CAPI3REF: Status Parameters for prepared statements +** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} +** +** These preprocessor macros define integer codes that name counter +** values associated with the [sqlite3_stmt_status()] interface. +** The meanings of the various counters are as follows: +** +** <dl> +** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> +** <dd>^This is the number of times that SQLite has stepped forward in +** a table as part of a full table scan. Large numbers for this counter +** may indicate opportunities for performance improvement through +** careful use of indices.</dd> +** +** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> +** <dd>^This is the number of sort operations that have occurred. +** A non-zero value in this counter may indicate an opportunity to +** improvement performance through careful use of indices.</dd> +** +** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> +** <dd>^This is the number of rows inserted into transient indices that +** were created automatically in order to help joins run faster. +** A non-zero value in this counter may indicate an opportunity to +** improvement performance by adding permanent indices that do not +** need to be reinitialized each time the statement is run.</dd> +** +** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt> +** <dd>^This is the number of virtual machine operations executed +** by the prepared statement if that number is less than or equal +** to 2147483647. The number of virtual machine operations can be +** used as a proxy for the total work done by the prepared statement. +** If the number of virtual machine operations exceeds 2147483647 +** then the value returned by this statement status code is undefined. +** +** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt> +** <dd>^This is the number of times that the prepare statement has been +** automatically regenerated due to schema changes or change to +** [bound parameters] that might affect the query plan. +** +** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt> +** <dd>^This is the number of times that the prepared statement has +** been run. A single "run" for the purposes of this counter is one +** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()]. +** The counter is incremented on the first [sqlite3_step()] call of each +** cycle. +** +** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt> +** <dd>^This is the approximate number of bytes of heap memory +** used to store the prepared statement. ^This value is not actually +** a counter, and so the resetFlg parameter to sqlite3_stmt_status() +** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED. +** </dd> +** </dl> +*/ +#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 +#define SQLITE_STMTSTATUS_SORT 2 +#define SQLITE_STMTSTATUS_AUTOINDEX 3 +#define SQLITE_STMTSTATUS_VM_STEP 4 +#define SQLITE_STMTSTATUS_REPREPARE 5 +#define SQLITE_STMTSTATUS_RUN 6 +#define SQLITE_STMTSTATUS_MEMUSED 99 + +/* +** CAPI3REF: Custom Page Cache Object +** +** The sqlite3_pcache type is opaque. It is implemented by +** the pluggable module. The SQLite core has no knowledge of +** its size or internal structure and never deals with the +** sqlite3_pcache object except by holding and passing pointers +** to the object. +** +** See [sqlite3_pcache_methods2] for additional information. +*/ +typedef struct sqlite3_pcache sqlite3_pcache; + +/* +** CAPI3REF: Custom Page Cache Object +** +** The sqlite3_pcache_page object represents a single page in the +** page cache. The page cache will allocate instances of this +** object. Various methods of the page cache use pointers to instances +** of this object as parameters or as their return value. +** +** See [sqlite3_pcache_methods2] for additional information. +*/ +typedef struct sqlite3_pcache_page sqlite3_pcache_page; +struct sqlite3_pcache_page { + void *pBuf; /* The content of the page */ + void *pExtra; /* Extra information associated with the page */ +}; + +/* +** CAPI3REF: Application Defined Page Cache. +** KEYWORDS: {page cache} +** +** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can +** register an alternative page cache implementation by passing in an +** instance of the sqlite3_pcache_methods2 structure.)^ +** In many applications, most of the heap memory allocated by +** SQLite is used for the page cache. +** By implementing a +** custom page cache using this API, an application can better control +** the amount of memory consumed by SQLite, the way in which +** that memory is allocated and released, and the policies used to +** determine exactly which parts of a database file are cached and for +** how long. +** +** The alternative page cache mechanism is an +** extreme measure that is only needed by the most demanding applications. +** The built-in page cache is recommended for most uses. +** +** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an +** internal buffer by SQLite within the call to [sqlite3_config]. Hence +** the application may discard the parameter after the call to +** [sqlite3_config()] returns.)^ +** +** [[the xInit() page cache method]] +** ^(The xInit() method is called once for each effective +** call to [sqlite3_initialize()])^ +** (usually only once during the lifetime of the process). ^(The xInit() +** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^ +** The intent of the xInit() method is to set up global data structures +** required by the custom page cache implementation. +** ^(If the xInit() method is NULL, then the +** built-in default page cache is used instead of the application defined +** page cache.)^ +** +** [[the xShutdown() page cache method]] +** ^The xShutdown() method is called by [sqlite3_shutdown()]. +** It can be used to clean up +** any outstanding resources before process shutdown, if required. +** ^The xShutdown() method may be NULL. +** +** ^SQLite automatically serializes calls to the xInit method, +** so the xInit method need not be threadsafe. ^The +** xShutdown method is only called from [sqlite3_shutdown()] so it does +** not need to be threadsafe either. All other methods must be threadsafe +** in multithreaded applications. +** +** ^SQLite will never invoke xInit() more than once without an intervening +** call to xShutdown(). +** +** [[the xCreate() page cache methods]] +** ^SQLite invokes the xCreate() method to construct a new cache instance. +** SQLite will typically create one cache instance for each open database file, +** though this is not guaranteed. ^The +** first parameter, szPage, is the size in bytes of the pages that must +** be allocated by the cache. ^szPage will always a power of two. ^The +** second parameter szExtra is a number of bytes of extra storage +** associated with each page cache entry. ^The szExtra parameter will +** a number less than 250. SQLite will use the +** extra szExtra bytes on each page to store metadata about the underlying +** database page on disk. The value passed into szExtra depends +** on the SQLite version, the target platform, and how SQLite was compiled. +** ^The third argument to xCreate(), bPurgeable, is true if the cache being +** created will be used to cache database pages of a file stored on disk, or +** false if it is used for an in-memory database. The cache implementation +** does not have to do anything special based with the value of bPurgeable; +** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will +** never invoke xUnpin() except to deliberately delete a page. +** ^In other words, calls to xUnpin() on a cache with bPurgeable set to +** false will always have the "discard" flag set to true. +** ^Hence, a cache created with bPurgeable false will +** never contain any unpinned pages. +** +** [[the xCachesize() page cache method]] +** ^(The xCachesize() method may be called at any time by SQLite to set the +** suggested maximum cache-size (number of pages stored by) the cache +** instance passed as the first argument. This is the value configured using +** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable +** parameter, the implementation is not required to do anything with this +** value; it is advisory only. +** +** [[the xPagecount() page cache methods]] +** The xPagecount() method must return the number of pages currently +** stored in the cache, both pinned and unpinned. +** +** [[the xFetch() page cache methods]] +** The xFetch() method locates a page in the cache and returns a pointer to +** an sqlite3_pcache_page object associated with that page, or a NULL pointer. +** The pBuf element of the returned sqlite3_pcache_page object will be a +** pointer to a buffer of szPage bytes used to store the content of a +** single database page. The pExtra element of sqlite3_pcache_page will be +** a pointer to the szExtra bytes of extra storage that SQLite has requested +** for each entry in the page cache. +** +** The page to be fetched is determined by the key. ^The minimum key value +** is 1. After it has been retrieved using xFetch, the page is considered +** to be "pinned". +** +** If the requested page is already in the page cache, then the page cache +** implementation must return a pointer to the page buffer with its content +** intact. If the requested page is not already in the cache, then the +** cache implementation should use the value of the createFlag +** parameter to help it determined what action to take: +** +** <table border=1 width=85% align=center> +** <tr><th> createFlag <th> Behavior when page is not already in cache +** <tr><td> 0 <td> Do not allocate a new page. Return NULL. +** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. +** Otherwise return NULL. +** <tr><td> 2 <td> Make every effort to allocate a new page. Only return +** NULL if allocating a new page is effectively impossible. +** </table> +** +** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite +** will only use a createFlag of 2 after a prior call with a createFlag of 1 +** failed.)^ In between the to xFetch() calls, SQLite may +** attempt to unpin one or more cache pages by spilling the content of +** pinned pages to disk and synching the operating system disk cache. +** +** [[the xUnpin() page cache method]] +** ^xUnpin() is called by SQLite with a pointer to a currently pinned page +** as its second argument. If the third parameter, discard, is non-zero, +** then the page must be evicted from the cache. +** ^If the discard parameter is +** zero, then the page may be discarded or retained at the discretion of +** page cache implementation. ^The page cache implementation +** may choose to evict unpinned pages at any time. +** +** The cache must not perform any reference counting. A single +** call to xUnpin() unpins the page regardless of the number of prior calls +** to xFetch(). +** +** [[the xRekey() page cache methods]] +** The xRekey() method is used to change the key value associated with the +** page passed as the second argument. If the cache +** previously contains an entry associated with newKey, it must be +** discarded. ^Any prior cache entry associated with newKey is guaranteed not +** to be pinned. +** +** When SQLite calls the xTruncate() method, the cache must discard all +** existing cache entries with page numbers (keys) greater than or equal +** to the value of the iLimit parameter passed to xTruncate(). If any +** of these pages are pinned, they are implicitly unpinned, meaning that +** they can be safely discarded. +** +** [[the xDestroy() page cache method]] +** ^The xDestroy() method is used to delete a cache allocated by xCreate(). +** All resources associated with the specified cache should be freed. ^After +** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] +** handle invalid, and will not use it with any other sqlite3_pcache_methods2 +** functions. +** +** [[the xShrink() page cache method]] +** ^SQLite invokes the xShrink() method when it wants the page cache to +** free up as much of heap memory as possible. The page cache implementation +** is not obligated to free any memory, but well-behaved implementations should +** do their best. +*/ +typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2; +struct sqlite3_pcache_methods2 { + int iVersion; + void *pArg; + int (*xInit)(void*); + void (*xShutdown)(void*); + sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); + void (*xCachesize)(sqlite3_pcache*, int nCachesize); + int (*xPagecount)(sqlite3_pcache*); + sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); + void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard); + void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, + unsigned oldKey, unsigned newKey); + void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); + void (*xDestroy)(sqlite3_pcache*); + void (*xShrink)(sqlite3_pcache*); +}; + +/* +** This is the obsolete pcache_methods object that has now been replaced +** by sqlite3_pcache_methods2. This object is not used by SQLite. It is +** retained in the header file for backwards compatibility only. +*/ +typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; +struct sqlite3_pcache_methods { + void *pArg; + int (*xInit)(void*); + void (*xShutdown)(void*); + sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); + void (*xCachesize)(sqlite3_pcache*, int nCachesize); + int (*xPagecount)(sqlite3_pcache*); + void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); + void (*xUnpin)(sqlite3_pcache*, void*, int discard); + void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); + void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); + void (*xDestroy)(sqlite3_pcache*); +}; + + +/* +** CAPI3REF: Online Backup Object +** +** The sqlite3_backup object records state information about an ongoing +** online backup operation. ^The sqlite3_backup object is created by +** a call to [sqlite3_backup_init()] and is destroyed by a call to +** [sqlite3_backup_finish()]. +** +** See Also: [Using the SQLite Online Backup API] +*/ +typedef struct sqlite3_backup sqlite3_backup; + +/* +** CAPI3REF: Online Backup API. +** +** The backup API copies the content of one database into another. +** It is useful either for creating backups of databases or +** for copying in-memory databases to or from persistent files. +** +** See Also: [Using the SQLite Online Backup API] +** +** ^SQLite holds a write transaction open on the destination database file +** for the duration of the backup operation. +** ^The source database is read-locked only while it is being read; +** it is not locked continuously for the entire backup operation. +** ^Thus, the backup may be performed on a live source database without +** preventing other database connections from +** reading or writing to the source database while the backup is underway. +** +** ^(To perform a backup operation: +** <ol> +** <li><b>sqlite3_backup_init()</b> is called once to initialize the +** backup, +** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer +** the data between the two databases, and finally +** <li><b>sqlite3_backup_finish()</b> is called to release all resources +** associated with the backup operation. +** </ol>)^ +** There should be exactly one call to sqlite3_backup_finish() for each +** successful call to sqlite3_backup_init(). +** +** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> +** +** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the +** [database connection] associated with the destination database +** and the database name, respectively. +** ^The database name is "main" for the main database, "temp" for the +** temporary database, or the name specified after the AS keyword in +** an [ATTACH] statement for an attached database. +** ^The S and M arguments passed to +** sqlite3_backup_init(D,N,S,M) identify the [database connection] +** and database name of the source database, respectively. +** ^The source and destination [database connections] (parameters S and D) +** must be different or else sqlite3_backup_init(D,N,S,M) will fail with +** an error. +** +** ^A call to sqlite3_backup_init() will fail, returning NULL, if +** there is already a read or read-write transaction open on the +** destination database. +** +** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is +** returned and an error code and error message are stored in the +** destination [database connection] D. +** ^The error code and message for the failed call to sqlite3_backup_init() +** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or +** [sqlite3_errmsg16()] functions. +** ^A successful call to sqlite3_backup_init() returns a pointer to an +** [sqlite3_backup] object. +** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and +** sqlite3_backup_finish() functions to perform the specified backup +** operation. +** +** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> +** +** ^Function sqlite3_backup_step(B,N) will copy up to N pages between +** the source and destination databases specified by [sqlite3_backup] object B. +** ^If N is negative, all remaining source pages are copied. +** ^If sqlite3_backup_step(B,N) successfully copies N pages and there +** are still more pages to be copied, then the function returns [SQLITE_OK]. +** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages +** from source to destination, then it returns [SQLITE_DONE]. +** ^If an error occurs while running sqlite3_backup_step(B,N), +** then an [error code] is returned. ^As well as [SQLITE_OK] and +** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], +** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an +** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. +** +** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if +** <ol> +** <li> the destination database was opened read-only, or +** <li> the destination database is using write-ahead-log journaling +** and the destination and source page sizes differ, or +** <li> the destination database is an in-memory database and the +** destination and source page sizes differ. +** </ol>)^ +** +** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then +** the [sqlite3_busy_handler | busy-handler function] +** is invoked (if one is specified). ^If the +** busy-handler returns non-zero before the lock is available, then +** [SQLITE_BUSY] is returned to the caller. ^In this case the call to +** sqlite3_backup_step() can be retried later. ^If the source +** [database connection] +** is being used to write to the source database when sqlite3_backup_step() +** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this +** case the call to sqlite3_backup_step() can be retried later on. ^(If +** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or +** [SQLITE_READONLY] is returned, then +** there is no point in retrying the call to sqlite3_backup_step(). These +** errors are considered fatal.)^ The application must accept +** that the backup operation has failed and pass the backup operation handle +** to the sqlite3_backup_finish() to release associated resources. +** +** ^The first call to sqlite3_backup_step() obtains an exclusive lock +** on the destination file. ^The exclusive lock is not released until either +** sqlite3_backup_finish() is called or the backup operation is complete +** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to +** sqlite3_backup_step() obtains a [shared lock] on the source database that +** lasts for the duration of the sqlite3_backup_step() call. +** ^Because the source database is not locked between calls to +** sqlite3_backup_step(), the source database may be modified mid-way +** through the backup process. ^If the source database is modified by an +** external process or via a database connection other than the one being +** used by the backup operation, then the backup will be automatically +** restarted by the next call to sqlite3_backup_step(). ^If the source +** database is modified by the using the same database connection as is used +** by the backup operation, then the backup database is automatically +** updated at the same time. +** +** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> +** +** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the +** application wishes to abandon the backup operation, the application +** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). +** ^The sqlite3_backup_finish() interfaces releases all +** resources associated with the [sqlite3_backup] object. +** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any +** active write-transaction on the destination database is rolled back. +** The [sqlite3_backup] object is invalid +** and may not be used following a call to sqlite3_backup_finish(). +** +** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no +** sqlite3_backup_step() errors occurred, regardless or whether or not +** sqlite3_backup_step() completed. +** ^If an out-of-memory condition or IO error occurred during any prior +** sqlite3_backup_step() call on the same [sqlite3_backup] object, then +** sqlite3_backup_finish() returns the corresponding [error code]. +** +** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() +** is not a permanent error and does not affect the return value of +** sqlite3_backup_finish(). +** +** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]] +** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> +** +** ^The sqlite3_backup_remaining() routine returns the number of pages still +** to be backed up at the conclusion of the most recent sqlite3_backup_step(). +** ^The sqlite3_backup_pagecount() routine returns the total number of pages +** in the source database at the conclusion of the most recent +** sqlite3_backup_step(). +** ^(The values returned by these functions are only updated by +** sqlite3_backup_step(). If the source database is modified in a way that +** changes the size of the source database or the number of pages remaining, +** those changes are not reflected in the output of sqlite3_backup_pagecount() +** and sqlite3_backup_remaining() until after the next +** sqlite3_backup_step().)^ +** +** <b>Concurrent Usage of Database Handles</b> +** +** ^The source [database connection] may be used by the application for other +** purposes while a backup operation is underway or being initialized. +** ^If SQLite is compiled and configured to support threadsafe database +** connections, then the source database connection may be used concurrently +** from within other threads. +** +** However, the application must guarantee that the destination +** [database connection] is not passed to any other API (by any thread) after +** sqlite3_backup_init() is called and before the corresponding call to +** sqlite3_backup_finish(). SQLite does not currently check to see +** if the application incorrectly accesses the destination [database connection] +** and so no error code is reported, but the operations may malfunction +** nevertheless. Use of the destination database connection while a +** backup is in progress might also also cause a mutex deadlock. +** +** If running in [shared cache mode], the application must +** guarantee that the shared cache used by the destination database +** is not accessed while the backup is running. In practice this means +** that the application must guarantee that the disk file being +** backed up to is not accessed by any connection within the process, +** not just the specific connection that was passed to sqlite3_backup_init(). +** +** The [sqlite3_backup] object itself is partially threadsafe. Multiple +** threads may safely make multiple concurrent calls to sqlite3_backup_step(). +** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() +** APIs are not strictly speaking threadsafe. If they are invoked at the +** same time as another thread is invoking sqlite3_backup_step() it is +** possible that they return invalid values. +*/ +SQLITE_API sqlite3_backup *sqlite3_backup_init( + sqlite3 *pDest, /* Destination database handle */ + const char *zDestName, /* Destination database name */ + sqlite3 *pSource, /* Source database handle */ + const char *zSourceName /* Source database name */ +); +SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); +SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); +SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); +SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); + +/* +** CAPI3REF: Unlock Notification +** METHOD: sqlite3 +** +** ^When running in shared-cache mode, a database operation may fail with +** an [SQLITE_LOCKED] error if the required locks on the shared-cache or +** individual tables within the shared-cache cannot be obtained. See +** [SQLite Shared-Cache Mode] for a description of shared-cache locking. +** ^This API may be used to register a callback that SQLite will invoke +** when the connection currently holding the required lock relinquishes it. +** ^This API is only available if the library was compiled with the +** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. +** +** See Also: [Using the SQLite Unlock Notification Feature]. +** +** ^Shared-cache locks are released when a database connection concludes +** its current transaction, either by committing it or rolling it back. +** +** ^When a connection (known as the blocked connection) fails to obtain a +** shared-cache lock and SQLITE_LOCKED is returned to the caller, the +** identity of the database connection (the blocking connection) that +** has locked the required resource is stored internally. ^After an +** application receives an SQLITE_LOCKED error, it may call the +** sqlite3_unlock_notify() method with the blocked connection handle as +** the first argument to register for a callback that will be invoked +** when the blocking connections current transaction is concluded. ^The +** callback is invoked from within the [sqlite3_step] or [sqlite3_close] +** call that concludes the blocking connections transaction. +** +** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, +** there is a chance that the blocking connection will have already +** concluded its transaction by the time sqlite3_unlock_notify() is invoked. +** If this happens, then the specified callback is invoked immediately, +** from within the call to sqlite3_unlock_notify().)^ +** +** ^If the blocked connection is attempting to obtain a write-lock on a +** shared-cache table, and more than one other connection currently holds +** a read-lock on the same table, then SQLite arbitrarily selects one of +** the other connections to use as the blocking connection. +** +** ^(There may be at most one unlock-notify callback registered by a +** blocked connection. If sqlite3_unlock_notify() is called when the +** blocked connection already has a registered unlock-notify callback, +** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is +** called with a NULL pointer as its second argument, then any existing +** unlock-notify callback is canceled. ^The blocked connections +** unlock-notify callback may also be canceled by closing the blocked +** connection using [sqlite3_close()]. +** +** The unlock-notify callback is not reentrant. If an application invokes +** any sqlite3_xxx API functions from within an unlock-notify callback, a +** crash or deadlock may be the result. +** +** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always +** returns SQLITE_OK. +** +** <b>Callback Invocation Details</b> +** +** When an unlock-notify callback is registered, the application provides a +** single void* pointer that is passed to the callback when it is invoked. +** However, the signature of the callback function allows SQLite to pass +** it an array of void* context pointers. The first argument passed to +** an unlock-notify callback is a pointer to an array of void* pointers, +** and the second is the number of entries in the array. +** +** When a blocking connections transaction is concluded, there may be +** more than one blocked connection that has registered for an unlock-notify +** callback. ^If two or more such blocked connections have specified the +** same callback function, then instead of invoking the callback function +** multiple times, it is invoked once with the set of void* context pointers +** specified by the blocked connections bundled together into an array. +** This gives the application an opportunity to prioritize any actions +** related to the set of unblocked database connections. +** +** <b>Deadlock Detection</b> +** +** Assuming that after registering for an unlock-notify callback a +** database waits for the callback to be issued before taking any further +** action (a reasonable assumption), then using this API may cause the +** application to deadlock. For example, if connection X is waiting for +** connection Y's transaction to be concluded, and similarly connection +** Y is waiting on connection X's transaction, then neither connection +** will proceed and the system may remain deadlocked indefinitely. +** +** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock +** detection. ^If a given call to sqlite3_unlock_notify() would put the +** system in a deadlocked state, then SQLITE_LOCKED is returned and no +** unlock-notify callback is registered. The system is said to be in +** a deadlocked state if connection A has registered for an unlock-notify +** callback on the conclusion of connection B's transaction, and connection +** B has itself registered for an unlock-notify callback when connection +** A's transaction is concluded. ^Indirect deadlock is also detected, so +** the system is also considered to be deadlocked if connection B has +** registered for an unlock-notify callback on the conclusion of connection +** C's transaction, where connection C is waiting on connection A. ^Any +** number of levels of indirection are allowed. +** +** <b>The "DROP TABLE" Exception</b> +** +** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost +** always appropriate to call sqlite3_unlock_notify(). There is however, +** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, +** SQLite checks if there are any currently executing SELECT statements +** that belong to the same connection. If there are, SQLITE_LOCKED is +** returned. In this case there is no "blocking connection", so invoking +** sqlite3_unlock_notify() results in the unlock-notify callback being +** invoked immediately. If the application then re-attempts the "DROP TABLE" +** or "DROP INDEX" query, an infinite loop might be the result. +** +** One way around this problem is to check the extended error code returned +** by an sqlite3_step() call. ^(If there is a blocking connection, then the +** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in +** the special "DROP TABLE/INDEX" case, the extended error code is just +** SQLITE_LOCKED.)^ +*/ +SQLITE_API int sqlite3_unlock_notify( + sqlite3 *pBlocked, /* Waiting connection */ + void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ + void *pNotifyArg /* Argument to pass to xNotify */ +); + + +/* +** CAPI3REF: String Comparison +** +** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications +** and extensions to compare the contents of two buffers containing UTF-8 +** strings in a case-independent fashion, using the same definition of "case +** independence" that SQLite uses internally when comparing identifiers. +*/ +SQLITE_API int sqlite3_stricmp(const char *, const char *); +SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); + +/* +** CAPI3REF: String Globbing +* +** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if +** string X matches the [GLOB] pattern P. +** ^The definition of [GLOB] pattern matching used in +** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the +** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function +** is case sensitive. +** +** Note that this routine returns zero on a match and non-zero if the strings +** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. +** +** See also: [sqlite3_strlike()]. +*/ +SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr); + +/* +** CAPI3REF: String LIKE Matching +* +** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if +** string X matches the [LIKE] pattern P with escape character E. +** ^The definition of [LIKE] pattern matching used in +** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E" +** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without +** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0. +** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case +** insensitive - equivalent upper and lower case ASCII characters match +** one another. +** +** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though +** only ASCII characters are case folded. +** +** Note that this routine returns zero on a match and non-zero if the strings +** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. +** +** See also: [sqlite3_strglob()]. +*/ +SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc); + +/* +** CAPI3REF: Error Logging Interface +** +** ^The [sqlite3_log()] interface writes a message into the [error log] +** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. +** ^If logging is enabled, the zFormat string and subsequent arguments are +** used with [sqlite3_snprintf()] to generate the final output string. +** +** The sqlite3_log() interface is intended for use by extensions such as +** virtual tables, collating functions, and SQL functions. While there is +** nothing to prevent an application from calling sqlite3_log(), doing so +** is considered bad form. +** +** The zFormat string must not be NULL. +** +** To avoid deadlocks and other threading problems, the sqlite3_log() routine +** will not use dynamically allocated memory. The log message is stored in +** a fixed-length buffer on the stack. If the log message is longer than +** a few hundred characters, it will be truncated to the length of the +** buffer. +*/ +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); + +/* +** CAPI3REF: Write-Ahead Log Commit Hook +** METHOD: sqlite3 +** +** ^The [sqlite3_wal_hook()] function is used to register a callback that +** is invoked each time data is committed to a database in wal mode. +** +** ^(The callback is invoked by SQLite after the commit has taken place and +** the associated write-lock on the database released)^, so the implementation +** may read, write or [checkpoint] the database as required. +** +** ^The first parameter passed to the callback function when it is invoked +** is a copy of the third parameter passed to sqlite3_wal_hook() when +** registering the callback. ^The second is a copy of the database handle. +** ^The third parameter is the name of the database that was written to - +** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter +** is the number of pages currently in the write-ahead log file, +** including those that were just committed. +** +** The callback function should normally return [SQLITE_OK]. ^If an error +** code is returned, that error will propagate back up through the +** SQLite code base to cause the statement that provoked the callback +** to report an error, though the commit will have still occurred. If the +** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value +** that does not correspond to any valid SQLite error code, the results +** are undefined. +** +** A single database handle may have at most a single write-ahead log callback +** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any +** previously registered write-ahead log callback. ^Note that the +** [sqlite3_wal_autocheckpoint()] interface and the +** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will +** overwrite any prior [sqlite3_wal_hook()] settings. +*/ +SQLITE_API void *sqlite3_wal_hook( + sqlite3*, + int(*)(void *,sqlite3*,const char*,int), + void* +); + +/* +** CAPI3REF: Configure an auto-checkpoint +** METHOD: sqlite3 +** +** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around +** [sqlite3_wal_hook()] that causes any database on [database connection] D +** to automatically [checkpoint] +** after committing a transaction if there are N or +** more frames in the [write-ahead log] file. ^Passing zero or +** a negative value as the nFrame parameter disables automatic +** checkpoints entirely. +** +** ^The callback registered by this function replaces any existing callback +** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback +** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism +** configured by this function. +** +** ^The [wal_autocheckpoint pragma] can be used to invoke this interface +** from SQL. +** +** ^Checkpoints initiated by this mechanism are +** [sqlite3_wal_checkpoint_v2|PASSIVE]. +** +** ^Every new [database connection] defaults to having the auto-checkpoint +** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] +** pages. The use of this interface +** is only necessary if the default setting is found to be suboptimal +** for a particular application. +*/ +SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); + +/* +** CAPI3REF: Checkpoint a database +** METHOD: sqlite3 +** +** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to +** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ +** +** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the +** [write-ahead log] for database X on [database connection] D to be +** transferred into the database file and for the write-ahead log to +** be reset. See the [checkpointing] documentation for addition +** information. +** +** This interface used to be the only way to cause a checkpoint to +** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] +** interface was added. This interface is retained for backwards +** compatibility and as a convenience for applications that need to manually +** start a callback but which do not need the full power (and corresponding +** complication) of [sqlite3_wal_checkpoint_v2()]. +*/ +SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); + +/* +** CAPI3REF: Checkpoint a database +** METHOD: sqlite3 +** +** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint +** operation on database X of [database connection] D in mode M. Status +** information is written back into integers pointed to by L and C.)^ +** ^(The M parameter must be a valid [checkpoint mode]:)^ +** +** <dl> +** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> +** ^Checkpoint as many frames as possible without waiting for any database +** readers or writers to finish, then sync the database file if all frames +** in the log were checkpointed. ^The [busy-handler callback] +** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. +** ^On the other hand, passive mode might leave the checkpoint unfinished +** if there are concurrent readers or writers. +** +** <dt>SQLITE_CHECKPOINT_FULL<dd> +** ^This mode blocks (it invokes the +** [sqlite3_busy_handler|busy-handler callback]) until there is no +** database writer and all readers are reading from the most recent database +** snapshot. ^It then checkpoints all frames in the log file and syncs the +** database file. ^This mode blocks new database writers while it is pending, +** but new database readers are allowed to continue unimpeded. +** +** <dt>SQLITE_CHECKPOINT_RESTART<dd> +** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition +** that after checkpointing the log file it blocks (calls the +** [busy-handler callback]) +** until all readers are reading from the database file only. ^This ensures +** that the next writer will restart the log file from the beginning. +** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new +** database writer attempts while it is pending, but does not impede readers. +** +** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> +** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the +** addition that it also truncates the log file to zero bytes just prior +** to a successful return. +** </dl> +** +** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in +** the log file or to -1 if the checkpoint could not run because +** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not +** NULL,then *pnCkpt is set to the total number of checkpointed frames in the +** log file (including any that were already checkpointed before the function +** was called) or to -1 if the checkpoint could not run due to an error or +** because the database is not in WAL mode. ^Note that upon successful +** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been +** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. +** +** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If +** any other process is running a checkpoint operation at the same time, the +** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a +** busy-handler configured, it will not be invoked in this case. +** +** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the +** exclusive "writer" lock on the database file. ^If the writer lock cannot be +** obtained immediately, and a busy-handler is configured, it is invoked and +** the writer lock retried until either the busy-handler returns 0 or the lock +** is successfully obtained. ^The busy-handler is also invoked while waiting for +** database readers as described above. ^If the busy-handler returns 0 before +** the writer lock is obtained or while waiting for database readers, the +** checkpoint operation proceeds from that point in the same way as +** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible +** without blocking any further. ^SQLITE_BUSY is returned in this case. +** +** ^If parameter zDb is NULL or points to a zero length string, then the +** specified operation is attempted on all WAL databases [attached] to +** [database connection] db. In this case the +** values written to output parameters *pnLog and *pnCkpt are undefined. ^If +** an SQLITE_BUSY error is encountered when processing one or more of the +** attached WAL databases, the operation is still attempted on any remaining +** attached databases and SQLITE_BUSY is returned at the end. ^If any other +** error occurs while processing an attached database, processing is abandoned +** and the error code is returned to the caller immediately. ^If no error +** (SQLITE_BUSY or otherwise) is encountered while processing the attached +** databases, SQLITE_OK is returned. +** +** ^If database zDb is the name of an attached database that is not in WAL +** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If +** zDb is not NULL (or a zero length string) and is not the name of any +** attached database, SQLITE_ERROR is returned to the caller. +** +** ^Unless it returns SQLITE_MISUSE, +** the sqlite3_wal_checkpoint_v2() interface +** sets the error information that is queried by +** [sqlite3_errcode()] and [sqlite3_errmsg()]. +** +** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface +** from SQL. +*/ +SQLITE_API int sqlite3_wal_checkpoint_v2( + sqlite3 *db, /* Database handle */ + const char *zDb, /* Name of attached database (or NULL) */ + int eMode, /* SQLITE_CHECKPOINT_* value */ + int *pnLog, /* OUT: Size of WAL log in frames */ + int *pnCkpt /* OUT: Total number of frames checkpointed */ +); + +/* +** CAPI3REF: Checkpoint Mode Values +** KEYWORDS: {checkpoint mode} +** +** These constants define all valid values for the "checkpoint mode" passed +** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. +** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the +** meaning of each of these checkpoint modes. +*/ +#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ +#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ +#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ +#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ + +/* +** CAPI3REF: Virtual Table Interface Configuration +** +** This function may be called by either the [xConnect] or [xCreate] method +** of a [virtual table] implementation to configure +** various facets of the virtual table interface. +** +** If this interface is invoked outside the context of an xConnect or +** xCreate virtual table method then the behavior is undefined. +** +** At present, there is only one option that may be configured using +** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options +** may be added in the future. +*/ +SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); + +/* +** CAPI3REF: Virtual Table Configuration Options +** +** These macros define the various options to the +** [sqlite3_vtab_config()] interface that [virtual table] implementations +** can use to customize and optimize their behavior. +** +** <dl> +** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]] +** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT +** <dd>Calls of the form +** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, +** where X is an integer. If X is zero, then the [virtual table] whose +** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not +** support constraints. In this configuration (which is the default) if +** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire +** statement is rolled back as if [ON CONFLICT | OR ABORT] had been +** specified as part of the users SQL statement, regardless of the actual +** ON CONFLICT mode specified. +** +** If X is non-zero, then the virtual table implementation guarantees +** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before +** any modifications to internal or persistent data structures have been made. +** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite +** is able to roll back a statement or database transaction, and abandon +** or continue processing the current SQL statement as appropriate. +** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns +** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode +** had been ABORT. +** +** Virtual table implementations that are required to handle OR REPLACE +** must do so within the [xUpdate] method. If a call to the +** [sqlite3_vtab_on_conflict()] function indicates that the current ON +** CONFLICT policy is REPLACE, the virtual table implementation should +** silently replace the appropriate rows within the xUpdate callback and +** return SQLITE_OK. Or, if this is not possible, it may return +** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT +** constraint handling. +** </dl> +*/ +#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 + +/* +** CAPI3REF: Determine The Virtual Table Conflict Policy +** +** This function may only be called from within a call to the [xUpdate] method +** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The +** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], +** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode +** of the SQL statement that triggered the call to the [xUpdate] method of the +** [virtual table]. +*/ +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); + +/* +** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE +** +** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn] +** method of a [virtual table], then it returns true if and only if the +** column is being fetched as part of an UPDATE operation during which the +** column value will not change. Applications might use this to substitute +** a return value that is less expensive to compute and that the corresponding +** [xUpdate] method understands as a "no-change" value. +** +** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that +** the column is not changed by the UPDATE statement, then the xColumn +** method can optionally return without setting a result, without calling +** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces]. +** In that case, [sqlite3_value_nochange(X)] will return true for the +** same column in the [xUpdate] method. +*/ +SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); + +/* +** CAPI3REF: Determine The Collation For a Virtual Table Constraint +** +** This function may only be called from within a call to the [xBestIndex] +** method of a [virtual table]. +** +** The first argument must be the sqlite3_index_info object that is the +** first parameter to the xBestIndex() method. The second argument must be +** an index into the aConstraint[] array belonging to the sqlite3_index_info +** structure passed to xBestIndex. This function returns a pointer to a buffer +** containing the name of the collation sequence for the corresponding +** constraint. +*/ +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); + +/* +** CAPI3REF: Conflict resolution modes +** KEYWORDS: {conflict resolution mode} +** +** These constants are returned by [sqlite3_vtab_on_conflict()] to +** inform a [virtual table] implementation what the [ON CONFLICT] mode +** is for the SQL statement being evaluated. +** +** Note that the [SQLITE_IGNORE] constant is also used as a potential +** return value from the [sqlite3_set_authorizer()] callback and that +** [SQLITE_ABORT] is also a [result code]. +*/ +#define SQLITE_ROLLBACK 1 +/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ +#define SQLITE_FAIL 3 +/* #define SQLITE_ABORT 4 // Also an error code */ +#define SQLITE_REPLACE 5 + +/* +** CAPI3REF: Prepared Statement Scan Status Opcodes +** KEYWORDS: {scanstatus options} +** +** The following constants can be used for the T parameter to the +** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a +** different metric for sqlite3_stmt_scanstatus() to return. +** +** When the value returned to V is a string, space to hold that string is +** managed by the prepared statement S and will be automatically freed when +** S is finalized. +** +** <dl> +** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> +** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be +** set to the total number of times that the X-th loop has run.</dd> +** +** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> +** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set +** to the total number of rows examined by all iterations of the X-th loop.</dd> +** +** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> +** <dd>^The "double" variable pointed to by the T parameter will be set to the +** query planner's estimate for the average number of rows output from each +** iteration of the X-th loop. If the query planner's estimates was accurate, +** then this value will approximate the quotient NVISIT/NLOOP and the +** product of this value for all prior loops with the same SELECTID will +** be the NLOOP value for the current loop. +** +** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> +** <dd>^The "const char *" variable pointed to by the T parameter will be set +** to a zero-terminated UTF-8 string containing the name of the index or table +** used for the X-th loop. +** +** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> +** <dd>^The "const char *" variable pointed to by the T parameter will be set +** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] +** description for the X-th loop. +** +** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> +** <dd>^The "int" variable pointed to by the T parameter will be set to the +** "select-id" for the X-th loop. The select-id identifies which query or +** subquery the loop is part of. The main query has a select-id of zero. +** The select-id is the same value as is output in the first column +** of an [EXPLAIN QUERY PLAN] query. +** </dl> +*/ +#define SQLITE_SCANSTAT_NLOOP 0 +#define SQLITE_SCANSTAT_NVISIT 1 +#define SQLITE_SCANSTAT_EST 2 +#define SQLITE_SCANSTAT_NAME 3 +#define SQLITE_SCANSTAT_EXPLAIN 4 +#define SQLITE_SCANSTAT_SELECTID 5 + +/* +** CAPI3REF: Prepared Statement Scan Status +** METHOD: sqlite3_stmt +** +** This interface returns information about the predicted and measured +** performance for pStmt. Advanced applications can use this +** interface to compare the predicted and the measured performance and +** issue warnings and/or rerun [ANALYZE] if discrepancies are found. +** +** Since this interface is expected to be rarely used, it is only +** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS] +** compile-time option. +** +** The "iScanStatusOp" parameter determines which status information to return. +** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior +** of this interface is undefined. +** ^The requested measurement is written into a variable pointed to by +** the "pOut" parameter. +** Parameter "idx" identifies the specific loop to retrieve statistics for. +** Loops are numbered starting from zero. ^If idx is out of range - less than +** zero or greater than or equal to the total number of loops used to implement +** the statement - a non-zero value is returned and the variable that pOut +** points to is unchanged. +** +** ^Statistics might not be available for all loops in all statements. ^In cases +** where there exist loops with no available statistics, this function behaves +** as if the loop did not exist - it returns non-zero and leave the variable +** that pOut points to unchanged. +** +** See also: [sqlite3_stmt_scanstatus_reset()] +*/ +SQLITE_API int sqlite3_stmt_scanstatus( + sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ + int idx, /* Index of loop to report on */ + int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ + void *pOut /* Result written here */ +); + +/* +** CAPI3REF: Zero Scan-Status Counters +** METHOD: sqlite3_stmt +** +** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. +** +** This API is only available if the library is built with pre-processor +** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. +*/ +SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); + +/* +** CAPI3REF: Flush caches to disk mid-transaction +** +** ^If a write-transaction is open on [database connection] D when the +** [sqlite3_db_cacheflush(D)] interface invoked, any dirty +** pages in the pager-cache that are not currently in use are written out +** to disk. A dirty page may be in use if a database cursor created by an +** active SQL statement is reading from it, or if it is page 1 of a database +** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)] +** interface flushes caches for all schemas - "main", "temp", and +** any [attached] databases. +** +** ^If this function needs to obtain extra database locks before dirty pages +** can be flushed to disk, it does so. ^If those locks cannot be obtained +** immediately and there is a busy-handler callback configured, it is invoked +** in the usual manner. ^If the required lock still cannot be obtained, then +** the database is skipped and an attempt made to flush any dirty pages +** belonging to the next (if any) database. ^If any databases are skipped +** because locks cannot be obtained, but no other error occurs, this +** function returns SQLITE_BUSY. +** +** ^If any other error occurs while flushing dirty pages to disk (for +** example an IO error or out-of-memory condition), then processing is +** abandoned and an SQLite [error code] is returned to the caller immediately. +** +** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK. +** +** ^This function does not set the database handle error code or message +** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions. +*/ +SQLITE_API int sqlite3_db_cacheflush(sqlite3*); + +/* +** CAPI3REF: The pre-update hook. +** +** ^These interfaces are only available if SQLite is compiled using the +** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. +** +** ^The [sqlite3_preupdate_hook()] interface registers a callback function +** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation +** on a database table. +** ^At most one preupdate hook may be registered at a time on a single +** [database connection]; each call to [sqlite3_preupdate_hook()] overrides +** the previous setting. +** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] +** with a NULL pointer as the second parameter. +** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as +** the first parameter to callbacks. +** +** ^The preupdate hook only fires for changes to real database tables; the +** preupdate hook is not invoked for changes to [virtual tables] or to +** system tables like sqlite_master or sqlite_stat1. +** +** ^The second parameter to the preupdate callback is a pointer to +** the [database connection] that registered the preupdate hook. +** ^The third parameter to the preupdate callback is one of the constants +** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the +** kind of update operation that is about to occur. +** ^(The fourth parameter to the preupdate callback is the name of the +** database within the database connection that is being modified. This +** will be "main" for the main database or "temp" for TEMP tables or +** the name given after the AS keyword in the [ATTACH] statement for attached +** databases.)^ +** ^The fifth parameter to the preupdate callback is the name of the +** table that is being modified. +** +** For an UPDATE or DELETE operation on a [rowid table], the sixth +** parameter passed to the preupdate callback is the initial [rowid] of the +** row being modified or deleted. For an INSERT operation on a rowid table, +** or any operation on a WITHOUT ROWID table, the value of the sixth +** parameter is undefined. For an INSERT or UPDATE on a rowid table the +** seventh parameter is the final rowid value of the row being inserted +** or updated. The value of the seventh parameter passed to the callback +** function is not defined for operations on WITHOUT ROWID tables, or for +** INSERT operations on rowid tables. +** +** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], +** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces +** provide additional information about a preupdate event. These routines +** may only be called from within a preupdate callback. Invoking any of +** these routines from outside of a preupdate callback or with a +** [database connection] pointer that is different from the one supplied +** to the preupdate callback results in undefined and probably undesirable +** behavior. +** +** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns +** in the row that is being inserted, updated, or deleted. +** +** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to +** a [protected sqlite3_value] that contains the value of the Nth column of +** the table row before it is updated. The N parameter must be between 0 +** and one less than the number of columns or the behavior will be +** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE +** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the +** behavior is undefined. The [sqlite3_value] that P points to +** will be destroyed when the preupdate callback returns. +** +** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to +** a [protected sqlite3_value] that contains the value of the Nth column of +** the table row after it is updated. The N parameter must be between 0 +** and one less than the number of columns or the behavior will be +** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE +** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the +** behavior is undefined. The [sqlite3_value] that P points to +** will be destroyed when the preupdate callback returns. +** +** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate +** callback was invoked as a result of a direct insert, update, or delete +** operation; or 1 for inserts, updates, or deletes invoked by top-level +** triggers; or 2 for changes resulting from triggers called by top-level +** triggers; and so forth. +** +** See also: [sqlite3_update_hook()] +*/ +#if defined(SQLITE_ENABLE_PREUPDATE_HOOK) +SQLITE_API void *sqlite3_preupdate_hook( + sqlite3 *db, + void(*xPreUpdate)( + void *pCtx, /* Copy of third arg to preupdate_hook() */ + sqlite3 *db, /* Database handle */ + int op, /* SQLITE_UPDATE, DELETE or INSERT */ + char const *zDb, /* Database name */ + char const *zName, /* Table name */ + sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */ + sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */ + ), + void* +); +SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **); +SQLITE_API int sqlite3_preupdate_count(sqlite3 *); +SQLITE_API int sqlite3_preupdate_depth(sqlite3 *); +SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **); +#endif + +/* +** CAPI3REF: Low-level system error code +** +** ^Attempt to return the underlying operating system error code or error +** number that caused the most recent I/O error or failure to open a file. +** The return value is OS-dependent. For example, on unix systems, after +** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be +** called to get back the underlying "errno" that caused the problem, such +** as ENOSPC, EAUTH, EISDIR, and so forth. +*/ +SQLITE_API int sqlite3_system_errno(sqlite3*); + +/* +** CAPI3REF: Database Snapshot +** KEYWORDS: {snapshot} {sqlite3_snapshot} +** +** An instance of the snapshot object records the state of a [WAL mode] +** database for some specific point in history. +** +** In [WAL mode], multiple [database connections] that are open on the +** same database file can each be reading a different historical version +** of the database file. When a [database connection] begins a read +** transaction, that connection sees an unchanging copy of the database +** as it existed for the point in time when the transaction first started. +** Subsequent changes to the database from other connections are not seen +** by the reader until a new read transaction is started. +** +** The sqlite3_snapshot object records state information about an historical +** version of the database file so that it is possible to later open a new read +** transaction that sees that historical version of the database rather than +** the most recent version. +*/ +typedef struct sqlite3_snapshot { + unsigned char hidden[48]; +} sqlite3_snapshot; + +/* +** CAPI3REF: Record A Database Snapshot +** CONSTRUCTOR: sqlite3_snapshot +** +** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a +** new [sqlite3_snapshot] object that records the current state of +** schema S in database connection D. ^On success, the +** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly +** created [sqlite3_snapshot] object into *P and returns SQLITE_OK. +** If there is not already a read-transaction open on schema S when +** this function is called, one is opened automatically. +** +** The following must be true for this function to succeed. If any of +** the following statements are false when sqlite3_snapshot_get() is +** called, SQLITE_ERROR is returned. The final value of *P is undefined +** in this case. +** +** <ul> +** <li> The database handle must not be in [autocommit mode]. +** +** <li> Schema S of [database connection] D must be a [WAL mode] database. +** +** <li> There must not be a write transaction open on schema S of database +** connection D. +** +** <li> One or more transactions must have been written to the current wal +** file since it was created on disk (by any connection). This means +** that a snapshot cannot be taken on a wal mode database with no wal +** file immediately after it is first opened. At least one transaction +** must be written to it first. +** </ul> +** +** This function may also return SQLITE_NOMEM. If it is called with the +** database handle in autocommit mode but fails for some other reason, +** whether or not a read transaction is opened on schema S is undefined. +** +** The [sqlite3_snapshot] object returned from a successful call to +** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()] +** to avoid a memory leak. +** +** The [sqlite3_snapshot_get()] interface is only available when the +** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. +*/ +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get( + sqlite3 *db, + const char *zSchema, + sqlite3_snapshot **ppSnapshot +); + +/* +** CAPI3REF: Start a read transaction on an historical snapshot +** METHOD: sqlite3_snapshot +** +** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read +** transaction or upgrades an existing one for schema S of +** [database connection] D such that the read transaction refers to +** historical [snapshot] P, rather than the most recent change to the +** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK +** on success or an appropriate [error code] if it fails. +** +** ^In order to succeed, the database connection must not be in +** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there +** is already a read transaction open on schema S, then the database handle +** must have no active statements (SELECT statements that have been passed +** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()). +** SQLITE_ERROR is returned if either of these conditions is violated, or +** if schema S does not exist, or if the snapshot object is invalid. +** +** ^A call to sqlite3_snapshot_open() will fail to open if the specified +** snapshot has been overwritten by a [checkpoint]. In this case +** SQLITE_ERROR_SNAPSHOT is returned. +** +** If there is already a read transaction open when this function is +** invoked, then the same read transaction remains open (on the same +** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT +** is returned. If another error code - for example SQLITE_PROTOCOL or an +** SQLITE_IOERR error code - is returned, then the final state of the +** read transaction is undefined. If SQLITE_OK is returned, then the +** read transaction is now open on database snapshot P. +** +** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the +** database connection D does not know that the database file for +** schema S is in [WAL mode]. A database connection might not know +** that the database file is in [WAL mode] if there has been no prior +** I/O on that database connection, or if the database entered [WAL mode] +** after the most recent I/O on the database connection.)^ +** (Hint: Run "[PRAGMA application_id]" against a newly opened +** database connection in order to make it ready to use snapshots.) +** +** The [sqlite3_snapshot_open()] interface is only available when the +** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. +*/ +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open( + sqlite3 *db, + const char *zSchema, + sqlite3_snapshot *pSnapshot +); + +/* +** CAPI3REF: Destroy a snapshot +** DESTRUCTOR: sqlite3_snapshot +** +** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P. +** The application must eventually free every [sqlite3_snapshot] object +** using this routine to avoid a memory leak. +** +** The [sqlite3_snapshot_free()] interface is only available when the +** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. +*/ +SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*); + +/* +** CAPI3REF: Compare the ages of two snapshot handles. +** METHOD: sqlite3_snapshot +** +** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages +** of two valid snapshot handles. +** +** If the two snapshot handles are not associated with the same database +** file, the result of the comparison is undefined. +** +** Additionally, the result of the comparison is only valid if both of the +** snapshot handles were obtained by calling sqlite3_snapshot_get() since the +** last time the wal file was deleted. The wal file is deleted when the +** database is changed back to rollback mode or when the number of database +** clients drops to zero. If either snapshot handle was obtained before the +** wal file was last deleted, the value returned by this function +** is undefined. +** +** Otherwise, this API returns a negative value if P1 refers to an older +** snapshot than P2, zero if the two handles refer to the same database +** snapshot, and a positive value if P1 is a newer snapshot than P2. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_SNAPSHOT] option. +*/ +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( + sqlite3_snapshot *p1, + sqlite3_snapshot *p2 +); + +/* +** CAPI3REF: Recover snapshots from a wal file +** METHOD: sqlite3_snapshot +** +** If a [WAL file] remains on disk after all database connections close +** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control] +** or because the last process to have the database opened exited without +** calling [sqlite3_close()]) and a new connection is subsequently opened +** on that database and [WAL file], the [sqlite3_snapshot_open()] interface +** will only be able to open the last transaction added to the WAL file +** even though the WAL file contains other valid transactions. +** +** This function attempts to scan the WAL file associated with database zDb +** of database handle db and make all valid snapshots available to +** sqlite3_snapshot_open(). It is an error if there is already a read +** transaction open on the database, or if the database is not a WAL mode +** database. +** +** SQLITE_OK is returned if successful, or an SQLite error code otherwise. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_SNAPSHOT] option. +*/ +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); + +/* +** CAPI3REF: Serialize a database +** +** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory +** that is a serialization of the S database on [database connection] D. +** If P is not a NULL pointer, then the size of the database in bytes +** is written into *P. +** +** For an ordinary on-disk database file, the serialization is just a +** copy of the disk file. For an in-memory database or a "TEMP" database, +** the serialization is the same sequence of bytes which would be written +** to disk if that database where backed up to disk. +** +** The usual case is that sqlite3_serialize() copies the serialization of +** the database into memory obtained from [sqlite3_malloc64()] and returns +** a pointer to that memory. The caller is responsible for freeing the +** returned value to avoid a memory leak. However, if the F argument +** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations +** are made, and the sqlite3_serialize() function will return a pointer +** to the contiguous memory representation of the database that SQLite +** is currently using for that database, or NULL if the no such contiguous +** memory representation of the database exists. A contiguous memory +** representation of the database will usually only exist if there has +** been a prior call to [sqlite3_deserialize(D,S,...)] with the same +** values of D and S. +** The size of the database is written into *P even if the +** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy +** of the database exists. +** +** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the +** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory +** allocation error occurs. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +SQLITE_API unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_serialize +** +** Zero or more of the following constants can be OR-ed together for +** the F argument to [sqlite3_serialize(D,S,P,F)]. +** +** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return +** a pointer to contiguous in-memory database that it is currently using, +** without making a copy of the database. If SQLite is not currently using +** a contiguous in-memory database, then this option causes +** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be +** using a contiguous in-memory database if it has been initialized by a +** prior call to [sqlite3_deserialize()]. +*/ +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ + +/* +** CAPI3REF: Deserialize a database +** +** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the +** [database connection] D to disconnect from database S and then +** reopen S as an in-memory database based on the serialization contained +** in P. The serialized database P is N bytes in size. M is the size of +** the buffer P, which might be larger than N. If M is larger than N, and +** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is +** permitted to add content to the in-memory database as long as the total +** size does not exceed M bytes. +** +** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will +** invoke sqlite3_free() on the serialization buffer when the database +** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then +** SQLite will try to increase the buffer size using sqlite3_realloc64() +** if writes on the database cause it to grow larger than M bytes. +** +** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the +** database is currently in a read transaction or is involved in a backup +** operation. +** +** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the +** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then +** [sqlite3_free()] is invoked on argument P prior to returning. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +SQLITE_API int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_deserialize() +** +** The following are allowed values for 6th argument (the F argument) to +** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. +** +** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization +** in the P argument is held in memory obtained from [sqlite3_malloc64()] +** and that SQLite should take ownership of this memory and automatically +** free it when it has finished using it. Without this flag, the caller +** is responsible for freeing any dynamically allocated memory. +** +** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to +** grow the size of the database using calls to [sqlite3_realloc64()]. This +** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. +** Without this flag, the deserialized database cannot increase in size beyond +** the number of bytes specified by the M parameter. +** +** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database +** should be treated as read-only. +*/ +#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ +#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ +#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ + +/* +** Undo the hack that converts floating point types to integer for +** builds on processors without floating point support. +*/ +#ifdef SQLITE_OMIT_FLOATING_POINT +# undef double +#endif + +#ifdef __cplusplus +} /* End of the 'extern "C"' block */ +#endif +#endif /* SQLITE3_H */ + +/******** Begin file sqlite3rtree.h *********/ +/* +** 2010 August 30 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +*/ + +#ifndef _SQLITE3RTREE_H_ +#define _SQLITE3RTREE_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; +typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info; + +/* The double-precision datatype used by RTree depends on the +** SQLITE_RTREE_INT_ONLY compile-time option. +*/ +#ifdef SQLITE_RTREE_INT_ONLY + typedef sqlite3_int64 sqlite3_rtree_dbl; +#else + typedef double sqlite3_rtree_dbl; +#endif + +/* +** Register a geometry callback named zGeom that can be used as part of an +** R-Tree geometry query as follows: +** +** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) +*/ +SQLITE_API int sqlite3_rtree_geometry_callback( + sqlite3 *db, + const char *zGeom, + int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*), + void *pContext +); + + +/* +** A pointer to a structure of the following type is passed as the first +** argument to callbacks registered using rtree_geometry_callback(). +*/ +struct sqlite3_rtree_geometry { + void *pContext; /* Copy of pContext passed to s_r_g_c() */ + int nParam; /* Size of array aParam[] */ + sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */ + void *pUser; /* Callback implementation user data */ + void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ +}; + +/* +** Register a 2nd-generation geometry callback named zScore that can be +** used as part of an R-Tree geometry query as follows: +** +** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...) +*/ +SQLITE_API int sqlite3_rtree_query_callback( + sqlite3 *db, + const char *zQueryFunc, + int (*xQueryFunc)(sqlite3_rtree_query_info*), + void *pContext, + void (*xDestructor)(void*) +); + + +/* +** A pointer to a structure of the following type is passed as the +** argument to scored geometry callback registered using +** sqlite3_rtree_query_callback(). +** +** Note that the first 5 fields of this structure are identical to +** sqlite3_rtree_geometry. This structure is a subclass of +** sqlite3_rtree_geometry. +*/ +struct sqlite3_rtree_query_info { + void *pContext; /* pContext from when function registered */ + int nParam; /* Number of function parameters */ + sqlite3_rtree_dbl *aParam; /* value of function parameters */ + void *pUser; /* callback can use this, if desired */ + void (*xDelUser)(void*); /* function to free pUser */ + sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */ + unsigned int *anQueue; /* Number of pending entries in the queue */ + int nCoord; /* Number of coordinates */ + int iLevel; /* Level of current node or entry */ + int mxLevel; /* The largest iLevel value in the tree */ + sqlite3_int64 iRowid; /* Rowid for current entry */ + sqlite3_rtree_dbl rParentScore; /* Score of parent node */ + int eParentWithin; /* Visibility of parent node */ + int eWithin; /* OUT: Visibility */ + sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ + /* The following fields are only available in 3.8.11 and later */ + sqlite3_value **apSqlParam; /* Original SQL values of parameters */ +}; + +/* +** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin. +*/ +#define NOT_WITHIN 0 /* Object completely outside of query region */ +#define PARTLY_WITHIN 1 /* Object partially overlaps query region */ +#define FULLY_WITHIN 2 /* Object fully contained within query region */ + + +#ifdef __cplusplus +} /* end of the 'extern "C"' block */ +#endif + +#endif /* ifndef _SQLITE3RTREE_H_ */ + +/******** End of sqlite3rtree.h *********/ +/******** Begin file sqlite3session.h *********/ + +#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) +#define __SQLITESESSION_H_ 1 + +/* +** Make sure we can call this stuff from C++. +*/ +#ifdef __cplusplus +extern "C" { +#endif + + +/* +** CAPI3REF: Session Object Handle +** +** An instance of this object is a [session] that can be used to +** record changes to a database. +*/ +typedef struct sqlite3_session sqlite3_session; + +/* +** CAPI3REF: Changeset Iterator Handle +** +** An instance of this object acts as a cursor for iterating +** over the elements of a [changeset] or [patchset]. +*/ +typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; + +/* +** CAPI3REF: Create A New Session Object +** CONSTRUCTOR: sqlite3_session +** +** Create a new session object attached to database handle db. If successful, +** a pointer to the new object is written to *ppSession and SQLITE_OK is +** returned. If an error occurs, *ppSession is set to NULL and an SQLite +** error code (e.g. SQLITE_NOMEM) is returned. +** +** It is possible to create multiple session objects attached to a single +** database handle. +** +** Session objects created using this function should be deleted using the +** [sqlite3session_delete()] function before the database handle that they +** are attached to is itself closed. If the database handle is closed before +** the session object is deleted, then the results of calling any session +** module function, including [sqlite3session_delete()] on the session object +** are undefined. +** +** Because the session module uses the [sqlite3_preupdate_hook()] API, it +** is not possible for an application to register a pre-update hook on a +** database handle that has one or more session objects attached. Nor is +** it possible to create a session object attached to a database handle for +** which a pre-update hook is already defined. The results of attempting +** either of these things are undefined. +** +** The session object will be used to create changesets for tables in +** database zDb, where zDb is either "main", or "temp", or the name of an +** attached database. It is not an error if database zDb is not attached +** to the database when the session object is created. +*/ +SQLITE_API int sqlite3session_create( + sqlite3 *db, /* Database handle */ + const char *zDb, /* Name of db (e.g. "main") */ + sqlite3_session **ppSession /* OUT: New session object */ +); + +/* +** CAPI3REF: Delete A Session Object +** DESTRUCTOR: sqlite3_session +** +** Delete a session object previously allocated using +** [sqlite3session_create()]. Once a session object has been deleted, the +** results of attempting to use pSession with any other session module +** function are undefined. +** +** Session objects must be deleted before the database handle to which they +** are attached is closed. Refer to the documentation for +** [sqlite3session_create()] for details. +*/ +SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); + + +/* +** CAPI3REF: Enable Or Disable A Session Object +** METHOD: sqlite3_session +** +** Enable or disable the recording of changes by a session object. When +** enabled, a session object records changes made to the database. When +** disabled - it does not. A newly created session object is enabled. +** Refer to the documentation for [sqlite3session_changeset()] for further +** details regarding how enabling and disabling a session object affects +** the eventual changesets. +** +** Passing zero to this function disables the session. Passing a value +** greater than zero enables it. Passing a value less than zero is a +** no-op, and may be used to query the current state of the session. +** +** The return value indicates the final state of the session object: 0 if +** the session is disabled, or 1 if it is enabled. +*/ +SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable); + +/* +** CAPI3REF: Set Or Clear the Indirect Change Flag +** METHOD: sqlite3_session +** +** Each change recorded by a session object is marked as either direct or +** indirect. A change is marked as indirect if either: +** +** <ul> +** <li> The session object "indirect" flag is set when the change is +** made, or +** <li> The change is made by an SQL trigger or foreign key action +** instead of directly as a result of a users SQL statement. +** </ul> +** +** If a single row is affected by more than one operation within a session, +** then the change is considered indirect if all operations meet the criteria +** for an indirect change above, or direct otherwise. +** +** This function is used to set, clear or query the session object indirect +** flag. If the second argument passed to this function is zero, then the +** indirect flag is cleared. If it is greater than zero, the indirect flag +** is set. Passing a value less than zero does not modify the current value +** of the indirect flag, and may be used to query the current state of the +** indirect flag for the specified session object. +** +** The return value indicates the final state of the indirect flag: 0 if +** it is clear, or 1 if it is set. +*/ +SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect); + +/* +** CAPI3REF: Attach A Table To A Session Object +** METHOD: sqlite3_session +** +** If argument zTab is not NULL, then it is the name of a table to attach +** to the session object passed as the first argument. All subsequent changes +** made to the table while the session object is enabled will be recorded. See +** documentation for [sqlite3session_changeset()] for further details. +** +** Or, if argument zTab is NULL, then changes are recorded for all tables +** in the database. If additional tables are added to the database (by +** executing "CREATE TABLE" statements) after this call is made, changes for +** the new tables are also recorded. +** +** Changes can only be recorded for tables that have a PRIMARY KEY explicitly +** defined as part of their CREATE TABLE statement. It does not matter if the +** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY +** KEY may consist of a single column, or may be a composite key. +** +** It is not an error if the named table does not exist in the database. Nor +** is it an error if the named table does not have a PRIMARY KEY. However, +** no changes will be recorded in either of these scenarios. +** +** Changes are not recorded for individual rows that have NULL values stored +** in one or more of their PRIMARY KEY columns. +** +** SQLITE_OK is returned if the call completes without error. Or, if an error +** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned. +** +** <h3>Special sqlite_stat1 Handling</h3> +** +** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to +** some of the rules above. In SQLite, the schema of sqlite_stat1 is: +** <pre> +**   CREATE TABLE sqlite_stat1(tbl,idx,stat) +** </pre> +** +** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are +** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes +** are recorded for rows for which (idx IS NULL) is true. However, for such +** rows a zero-length blob (SQL value X'') is stored in the changeset or +** patchset instead of a NULL value. This allows such changesets to be +** manipulated by legacy implementations of sqlite3changeset_invert(), +** concat() and similar. +** +** The sqlite3changeset_apply() function automatically converts the +** zero-length blob back to a NULL value when updating the sqlite_stat1 +** table. However, if the application calls sqlite3changeset_new(), +** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset +** iterator directly (including on a changeset iterator passed to a +** conflict-handler callback) then the X'' value is returned. The application +** must translate X'' to NULL itself if required. +** +** Legacy (older than 3.22.0) versions of the sessions module cannot capture +** changes made to the sqlite_stat1 table. Legacy versions of the +** sqlite3changeset_apply() function silently ignore any modifications to the +** sqlite_stat1 table that are part of a changeset or patchset. +*/ +SQLITE_API int sqlite3session_attach( + sqlite3_session *pSession, /* Session object */ + const char *zTab /* Table name */ +); + +/* +** CAPI3REF: Set a table filter on a Session Object. +** METHOD: sqlite3_session +** +** The second argument (xFilter) is the "filter callback". For changes to rows +** in tables that are not attached to the Session object, the filter is called +** to determine whether changes to the table's rows should be tracked or not. +** If xFilter returns 0, changes is not tracked. Note that once a table is +** attached, xFilter will not be called again. +*/ +SQLITE_API void sqlite3session_table_filter( + sqlite3_session *pSession, /* Session object */ + int(*xFilter)( + void *pCtx, /* Copy of third arg to _filter_table() */ + const char *zTab /* Table name */ + ), + void *pCtx /* First argument passed to xFilter */ +); + +/* +** CAPI3REF: Generate A Changeset From A Session Object +** METHOD: sqlite3_session +** +** Obtain a changeset containing changes to the tables attached to the +** session object passed as the first argument. If successful, +** set *ppChangeset to point to a buffer containing the changeset +** and *pnChangeset to the size of the changeset in bytes before returning +** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to +** zero and return an SQLite error code. +** +** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes, +** each representing a change to a single row of an attached table. An INSERT +** change contains the values of each field of a new database row. A DELETE +** contains the original values of each field of a deleted database row. An +** UPDATE change contains the original values of each field of an updated +** database row along with the updated values for each updated non-primary-key +** column. It is not possible for an UPDATE change to represent a change that +** modifies the values of primary key columns. If such a change is made, it +** is represented in a changeset as a DELETE followed by an INSERT. +** +** Changes are not recorded for rows that have NULL values stored in one or +** more of their PRIMARY KEY columns. If such a row is inserted or deleted, +** no corresponding change is present in the changesets returned by this +** function. If an existing row with one or more NULL values stored in +** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL, +** only an INSERT is appears in the changeset. Similarly, if an existing row +** with non-NULL PRIMARY KEY values is updated so that one or more of its +** PRIMARY KEY columns are set to NULL, the resulting changeset contains a +** DELETE change only. +** +** The contents of a changeset may be traversed using an iterator created +** using the [sqlite3changeset_start()] API. A changeset may be applied to +** a database with a compatible schema using the [sqlite3changeset_apply()] +** API. +** +** Within a changeset generated by this function, all changes related to a +** single table are grouped together. In other words, when iterating through +** a changeset or when applying a changeset to a database, all changes related +** to a single table are processed before moving on to the next table. Tables +** are sorted in the same order in which they were attached (or auto-attached) +** to the sqlite3_session object. The order in which the changes related to +** a single table are stored is undefined. +** +** Following a successful call to this function, it is the responsibility of +** the caller to eventually free the buffer that *ppChangeset points to using +** [sqlite3_free()]. +** +** <h3>Changeset Generation</h3> +** +** Once a table has been attached to a session object, the session object +** records the primary key values of all new rows inserted into the table. +** It also records the original primary key and other column values of any +** deleted or updated rows. For each unique primary key value, data is only +** recorded once - the first time a row with said primary key is inserted, +** updated or deleted in the lifetime of the session. +** +** There is one exception to the previous paragraph: when a row is inserted, +** updated or deleted, if one or more of its primary key columns contain a +** NULL value, no record of the change is made. +** +** The session object therefore accumulates two types of records - those +** that consist of primary key values only (created when the user inserts +** a new record) and those that consist of the primary key values and the +** original values of other table columns (created when the users deletes +** or updates a record). +** +** When this function is called, the requested changeset is created using +** both the accumulated records and the current contents of the database +** file. Specifically: +** +** <ul> +** <li> For each record generated by an insert, the database is queried +** for a row with a matching primary key. If one is found, an INSERT +** change is added to the changeset. If no such row is found, no change +** is added to the changeset. +** +** <li> For each record generated by an update or delete, the database is +** queried for a row with a matching primary key. If such a row is +** found and one or more of the non-primary key fields have been +** modified from their original values, an UPDATE change is added to +** the changeset. Or, if no such row is found in the table, a DELETE +** change is added to the changeset. If there is a row with a matching +** primary key in the database, but all fields contain their original +** values, no change is added to the changeset. +** </ul> +** +** This means, amongst other things, that if a row is inserted and then later +** deleted while a session object is active, neither the insert nor the delete +** will be present in the changeset. Or if a row is deleted and then later a +** row with the same primary key values inserted while a session object is +** active, the resulting changeset will contain an UPDATE change instead of +** a DELETE and an INSERT. +** +** When a session object is disabled (see the [sqlite3session_enable()] API), +** it does not accumulate records when rows are inserted, updated or deleted. +** This may appear to have some counter-intuitive effects if a single row +** is written to more than once during a session. For example, if a row +** is inserted while a session object is enabled, then later deleted while +** the same session object is disabled, no INSERT record will appear in the +** changeset, even though the delete took place while the session was disabled. +** Or, if one field of a row is updated while a session is disabled, and +** another field of the same row is updated while the session is enabled, the +** resulting changeset will contain an UPDATE change that updates both fields. +*/ +SQLITE_API int sqlite3session_changeset( + sqlite3_session *pSession, /* Session object */ + int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ + void **ppChangeset /* OUT: Buffer containing changeset */ +); + +/* +** CAPI3REF: Load The Difference Between Tables Into A Session +** METHOD: sqlite3_session +** +** If it is not already attached to the session object passed as the first +** argument, this function attaches table zTbl in the same manner as the +** [sqlite3session_attach()] function. If zTbl does not exist, or if it +** does not have a primary key, this function is a no-op (but does not return +** an error). +** +** Argument zFromDb must be the name of a database ("main", "temp" etc.) +** attached to the same database handle as the session object that contains +** a table compatible with the table attached to the session by this function. +** A table is considered compatible if it: +** +** <ul> +** <li> Has the same name, +** <li> Has the same set of columns declared in the same order, and +** <li> Has the same PRIMARY KEY definition. +** </ul> +** +** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables +** are compatible but do not have any PRIMARY KEY columns, it is not an error +** but no changes are added to the session object. As with other session +** APIs, tables without PRIMARY KEYs are simply ignored. +** +** This function adds a set of changes to the session object that could be +** used to update the table in database zFrom (call this the "from-table") +** so that its content is the same as the table attached to the session +** object (call this the "to-table"). Specifically: +** +** <ul> +** <li> For each row (primary key) that exists in the to-table but not in +** the from-table, an INSERT record is added to the session object. +** +** <li> For each row (primary key) that exists in the to-table but not in +** the from-table, a DELETE record is added to the session object. +** +** <li> For each row (primary key) that exists in both tables, but features +** different non-PK values in each, an UPDATE record is added to the +** session. +** </ul> +** +** To clarify, if this function is called and then a changeset constructed +** using [sqlite3session_changeset()], then after applying that changeset to +** database zFrom the contents of the two compatible tables would be +** identical. +** +** It an error if database zFrom does not exist or does not contain the +** required compatible table. +** +** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite +** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg +** may be set to point to a buffer containing an English language error +** message. It is the responsibility of the caller to free this buffer using +** sqlite3_free(). +*/ +SQLITE_API int sqlite3session_diff( + sqlite3_session *pSession, + const char *zFromDb, + const char *zTbl, + char **pzErrMsg +); + + +/* +** CAPI3REF: Generate A Patchset From A Session Object +** METHOD: sqlite3_session +** +** The differences between a patchset and a changeset are that: +** +** <ul> +** <li> DELETE records consist of the primary key fields only. The +** original values of other fields are omitted. +** <li> The original values of any modified fields are omitted from +** UPDATE records. +** </ul> +** +** A patchset blob may be used with up to date versions of all +** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(), +** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly, +** attempting to use a patchset blob with old versions of the +** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error. +** +** Because the non-primary key "old.*" fields are omitted, no +** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset +** is passed to the sqlite3changeset_apply() API. Other conflict types work +** in the same way as for changesets. +** +** Changes within a patchset are ordered in the same way as for changesets +** generated by the sqlite3session_changeset() function (i.e. all changes for +** a single table are grouped together, tables appear in the order in which +** they were attached to the session object). +*/ +SQLITE_API int sqlite3session_patchset( + sqlite3_session *pSession, /* Session object */ + int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */ + void **ppPatchset /* OUT: Buffer containing patchset */ +); + +/* +** CAPI3REF: Test if a changeset has recorded any changes. +** +** Return non-zero if no changes to attached tables have been recorded by +** the session object passed as the first argument. Otherwise, if one or +** more changes have been recorded, return zero. +** +** Even if this function returns zero, it is possible that calling +** [sqlite3session_changeset()] on the session handle may still return a +** changeset that contains no changes. This can happen when a row in +** an attached table is modified and then later on the original values +** are restored. However, if this function returns non-zero, then it is +** guaranteed that a call to sqlite3session_changeset() will return a +** changeset containing zero changes. +*/ +SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession); + +/* +** CAPI3REF: Create An Iterator To Traverse A Changeset +** CONSTRUCTOR: sqlite3_changeset_iter +** +** Create an iterator used to iterate through the contents of a changeset. +** If successful, *pp is set to point to the iterator handle and SQLITE_OK +** is returned. Otherwise, if an error occurs, *pp is set to zero and an +** SQLite error code is returned. +** +** The following functions can be used to advance and query a changeset +** iterator created by this function: +** +** <ul> +** <li> [sqlite3changeset_next()] +** <li> [sqlite3changeset_op()] +** <li> [sqlite3changeset_new()] +** <li> [sqlite3changeset_old()] +** </ul> +** +** It is the responsibility of the caller to eventually destroy the iterator +** by passing it to [sqlite3changeset_finalize()]. The buffer containing the +** changeset (pChangeset) must remain valid until after the iterator is +** destroyed. +** +** Assuming the changeset blob was created by one of the +** [sqlite3session_changeset()], [sqlite3changeset_concat()] or +** [sqlite3changeset_invert()] functions, all changes within the changeset +** that apply to a single table are grouped together. This means that when +** an application iterates through a changeset using an iterator created by +** this function, all changes that relate to a single table are visited +** consecutively. There is no chance that the iterator will visit a change +** the applies to table X, then one for table Y, and then later on visit +** another change for table X. +** +** The behavior of sqlite3changeset_start_v2() and its streaming equivalent +** may be modified by passing a combination of +** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter. +** +** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b> +** and therefore subject to change. +*/ +SQLITE_API int sqlite3changeset_start( + sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ + int nChangeset, /* Size of changeset blob in bytes */ + void *pChangeset /* Pointer to blob containing changeset */ +); +SQLITE_API int sqlite3changeset_start_v2( + sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ + int nChangeset, /* Size of changeset blob in bytes */ + void *pChangeset, /* Pointer to blob containing changeset */ + int flags /* SESSION_CHANGESETSTART_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3changeset_start_v2 +** +** The following flags may passed via the 4th parameter to +** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]: +** +** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd> +** Invert the changeset while iterating through it. This is equivalent to +** inverting a changeset using sqlite3changeset_invert() before applying it. +** It is an error to specify this flag with a patchset. +*/ +#define SQLITE_CHANGESETSTART_INVERT 0x0002 + + +/* +** CAPI3REF: Advance A Changeset Iterator +** METHOD: sqlite3_changeset_iter +** +** This function may only be used with iterators created by function +** [sqlite3changeset_start()]. If it is called on an iterator passed to +** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE +** is returned and the call has no effect. +** +** Immediately after an iterator is created by sqlite3changeset_start(), it +** does not point to any change in the changeset. Assuming the changeset +** is not empty, the first call to this function advances the iterator to +** point to the first change in the changeset. Each subsequent call advances +** the iterator to point to the next change in the changeset (if any). If +** no error occurs and the iterator points to a valid change after a call +** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned. +** Otherwise, if all changes in the changeset have already been visited, +** SQLITE_DONE is returned. +** +** If an error occurs, an SQLite error code is returned. Possible error +** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or +** SQLITE_NOMEM. +*/ +SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); + +/* +** CAPI3REF: Obtain The Current Operation From A Changeset Iterator +** METHOD: sqlite3_changeset_iter +** +** The pIter argument passed to this function may either be an iterator +** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator +** created by [sqlite3changeset_start()]. In the latter case, the most recent +** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this +** is not the case, this function returns [SQLITE_MISUSE]. +** +** If argument pzTab is not NULL, then *pzTab is set to point to a +** nul-terminated utf-8 encoded string containing the name of the table +** affected by the current change. The buffer remains valid until either +** sqlite3changeset_next() is called on the iterator or until the +** conflict-handler function returns. If pnCol is not NULL, then *pnCol is +** set to the number of columns in the table affected by the change. If +** pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change +** is an indirect change, or false (0) otherwise. See the documentation for +** [sqlite3session_indirect()] for a description of direct and indirect +** changes. Finally, if pOp is not NULL, then *pOp is set to one of +** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the +** type of change that the iterator currently points to. +** +** If no error occurs, SQLITE_OK is returned. If an error does occur, an +** SQLite error code is returned. The values of the output variables may not +** be trusted in this case. +*/ +SQLITE_API int sqlite3changeset_op( + sqlite3_changeset_iter *pIter, /* Iterator object */ + const char **pzTab, /* OUT: Pointer to table name */ + int *pnCol, /* OUT: Number of columns in table */ + int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */ + int *pbIndirect /* OUT: True for an 'indirect' change */ +); + +/* +** CAPI3REF: Obtain The Primary Key Definition Of A Table +** METHOD: sqlite3_changeset_iter +** +** For each modified table, a changeset includes the following: +** +** <ul> +** <li> The number of columns in the table, and +** <li> Which of those columns make up the tables PRIMARY KEY. +** </ul> +** +** This function is used to find which columns comprise the PRIMARY KEY of +** the table modified by the change that iterator pIter currently points to. +** If successful, *pabPK is set to point to an array of nCol entries, where +** nCol is the number of columns in the table. Elements of *pabPK are set to +** 0x01 if the corresponding column is part of the tables primary key, or +** 0x00 if it is not. +** +** If argument pnCol is not NULL, then *pnCol is set to the number of columns +** in the table. +** +** If this function is called when the iterator does not point to a valid +** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise, +** SQLITE_OK is returned and the output variables populated as described +** above. +*/ +SQLITE_API int sqlite3changeset_pk( + sqlite3_changeset_iter *pIter, /* Iterator object */ + unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */ + int *pnCol /* OUT: Number of entries in output array */ +); + +/* +** CAPI3REF: Obtain old.* Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter +** +** The pIter argument passed to this function may either be an iterator +** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator +** created by [sqlite3changeset_start()]. In the latter case, the most recent +** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. +** Furthermore, it may only be called if the type of change that the iterator +** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise, +** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL. +** +** Argument iVal must be greater than or equal to 0, and less than the number +** of columns in the table affected by the current change. Otherwise, +** [SQLITE_RANGE] is returned and *ppValue is set to NULL. +** +** If successful, this function sets *ppValue to point to a protected +** sqlite3_value object containing the iVal'th value from the vector of +** original row values stored as part of the UPDATE or DELETE change and +** returns SQLITE_OK. The name of the function comes from the fact that this +** is similar to the "old.*" columns available to update or delete triggers. +** +** If some other error occurs (e.g. an OOM condition), an SQLite error code +** is returned and *ppValue is set to NULL. +*/ +SQLITE_API int sqlite3changeset_old( + sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int iVal, /* Column number */ + sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ +); + +/* +** CAPI3REF: Obtain new.* Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter +** +** The pIter argument passed to this function may either be an iterator +** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator +** created by [sqlite3changeset_start()]. In the latter case, the most recent +** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. +** Furthermore, it may only be called if the type of change that the iterator +** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise, +** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL. +** +** Argument iVal must be greater than or equal to 0, and less than the number +** of columns in the table affected by the current change. Otherwise, +** [SQLITE_RANGE] is returned and *ppValue is set to NULL. +** +** If successful, this function sets *ppValue to point to a protected +** sqlite3_value object containing the iVal'th value from the vector of +** new row values stored as part of the UPDATE or INSERT change and +** returns SQLITE_OK. If the change is an UPDATE and does not include +** a new value for the requested column, *ppValue is set to NULL and +** SQLITE_OK returned. The name of the function comes from the fact that +** this is similar to the "new.*" columns available to update or delete +** triggers. +** +** If some other error occurs (e.g. an OOM condition), an SQLite error code +** is returned and *ppValue is set to NULL. +*/ +SQLITE_API int sqlite3changeset_new( + sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int iVal, /* Column number */ + sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ +); + +/* +** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter +** +** This function should only be used with iterator objects passed to a +** conflict-handler callback by [sqlite3changeset_apply()] with either +** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function +** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue +** is set to NULL. +** +** Argument iVal must be greater than or equal to 0, and less than the number +** of columns in the table affected by the current change. Otherwise, +** [SQLITE_RANGE] is returned and *ppValue is set to NULL. +** +** If successful, this function sets *ppValue to point to a protected +** sqlite3_value object containing the iVal'th value from the +** "conflicting row" associated with the current conflict-handler callback +** and returns SQLITE_OK. +** +** If some other error occurs (e.g. an OOM condition), an SQLite error code +** is returned and *ppValue is set to NULL. +*/ +SQLITE_API int sqlite3changeset_conflict( + sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int iVal, /* Column number */ + sqlite3_value **ppValue /* OUT: Value from conflicting row */ +); + +/* +** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations +** METHOD: sqlite3_changeset_iter +** +** This function may only be called with an iterator passed to an +** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case +** it sets the output variable to the total number of known foreign key +** violations in the destination database and returns SQLITE_OK. +** +** In all other cases this function returns SQLITE_MISUSE. +*/ +SQLITE_API int sqlite3changeset_fk_conflicts( + sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int *pnOut /* OUT: Number of FK violations */ +); + + +/* +** CAPI3REF: Finalize A Changeset Iterator +** METHOD: sqlite3_changeset_iter +** +** This function is used to finalize an iterator allocated with +** [sqlite3changeset_start()]. +** +** This function should only be called on iterators created using the +** [sqlite3changeset_start()] function. If an application calls this +** function with an iterator passed to a conflict-handler by +** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the +** call has no effect. +** +** If an error was encountered within a call to an sqlite3changeset_xxx() +** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an +** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding +** to that error is returned by this function. Otherwise, SQLITE_OK is +** returned. This is to allow the following pattern (pseudo-code): +** +** <pre> +** sqlite3changeset_start(); +** while( SQLITE_ROW==sqlite3changeset_next() ){ +** // Do something with change. +** } +** rc = sqlite3changeset_finalize(); +** if( rc!=SQLITE_OK ){ +** // An error has occurred +** } +** </pre> +*/ +SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); + +/* +** CAPI3REF: Invert A Changeset +** +** This function is used to "invert" a changeset object. Applying an inverted +** changeset to a database reverses the effects of applying the uninverted +** changeset. Specifically: +** +** <ul> +** <li> Each DELETE change is changed to an INSERT, and +** <li> Each INSERT change is changed to a DELETE, and +** <li> For each UPDATE change, the old.* and new.* values are exchanged. +** </ul> +** +** This function does not change the order in which changes appear within +** the changeset. It merely reverses the sense of each individual change. +** +** If successful, a pointer to a buffer containing the inverted changeset +** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and +** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are +** zeroed and an SQLite error code returned. +** +** It is the responsibility of the caller to eventually call sqlite3_free() +** on the *ppOut pointer to free the buffer allocation following a successful +** call to this function. +** +** WARNING/TODO: This function currently assumes that the input is a valid +** changeset. If it is not, the results are undefined. +*/ +SQLITE_API int sqlite3changeset_invert( + int nIn, const void *pIn, /* Input changeset */ + int *pnOut, void **ppOut /* OUT: Inverse of input */ +); + +/* +** CAPI3REF: Concatenate Two Changeset Objects +** +** This function is used to concatenate two changesets, A and B, into a +** single changeset. The result is a changeset equivalent to applying +** changeset A followed by changeset B. +** +** This function combines the two input changesets using an +** sqlite3_changegroup object. Calling it produces similar results as the +** following code fragment: +** +** <pre> +** sqlite3_changegroup *pGrp; +** rc = sqlite3_changegroup_new(&pGrp); +** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA); +** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB); +** if( rc==SQLITE_OK ){ +** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut); +** }else{ +** *ppOut = 0; +** *pnOut = 0; +** } +** </pre> +** +** Refer to the sqlite3_changegroup documentation below for details. +*/ +SQLITE_API int sqlite3changeset_concat( + int nA, /* Number of bytes in buffer pA */ + void *pA, /* Pointer to buffer containing changeset A */ + int nB, /* Number of bytes in buffer pB */ + void *pB, /* Pointer to buffer containing changeset B */ + int *pnOut, /* OUT: Number of bytes in output changeset */ + void **ppOut /* OUT: Buffer containing output changeset */ +); + + +/* +** CAPI3REF: Changegroup Handle +** +** A changegroup is an object used to combine two or more +** [changesets] or [patchsets] +*/ +typedef struct sqlite3_changegroup sqlite3_changegroup; + +/* +** CAPI3REF: Create A New Changegroup Object +** CONSTRUCTOR: sqlite3_changegroup +** +** An sqlite3_changegroup object is used to combine two or more changesets +** (or patchsets) into a single changeset (or patchset). A single changegroup +** object may combine changesets or patchsets, but not both. The output is +** always in the same format as the input. +** +** If successful, this function returns SQLITE_OK and populates (*pp) with +** a pointer to a new sqlite3_changegroup object before returning. The caller +** should eventually free the returned object using a call to +** sqlite3changegroup_delete(). If an error occurs, an SQLite error code +** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL. +** +** The usual usage pattern for an sqlite3_changegroup object is as follows: +** +** <ul> +** <li> It is created using a call to sqlite3changegroup_new(). +** +** <li> Zero or more changesets (or patchsets) are added to the object +** by calling sqlite3changegroup_add(). +** +** <li> The result of combining all input changesets together is obtained +** by the application via a call to sqlite3changegroup_output(). +** +** <li> The object is deleted using a call to sqlite3changegroup_delete(). +** </ul> +** +** Any number of calls to add() and output() may be made between the calls to +** new() and delete(), and in any order. +** +** As well as the regular sqlite3changegroup_add() and +** sqlite3changegroup_output() functions, also available are the streaming +** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm(). +*/ +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp); + +/* +** CAPI3REF: Add A Changeset To A Changegroup +** METHOD: sqlite3_changegroup +** +** Add all changes within the changeset (or patchset) in buffer pData (size +** nData bytes) to the changegroup. +** +** If the buffer contains a patchset, then all prior calls to this function +** on the same changegroup object must also have specified patchsets. Or, if +** the buffer contains a changeset, so must have the earlier calls to this +** function. Otherwise, SQLITE_ERROR is returned and no changes are added +** to the changegroup. +** +** Rows within the changeset and changegroup are identified by the values in +** their PRIMARY KEY columns. A change in the changeset is considered to +** apply to the same row as a change already present in the changegroup if +** the two rows have the same primary key. +** +** Changes to rows that do not already appear in the changegroup are +** simply copied into it. Or, if both the new changeset and the changegroup +** contain changes that apply to a single row, the final contents of the +** changegroup depends on the type of each change, as follows: +** +** <table border=1 style="margin-left:8ex;margin-right:8ex"> +** <tr><th style="white-space:pre">Existing Change </th> +** <th style="white-space:pre">New Change </th> +** <th>Output Change +** <tr><td>INSERT <td>INSERT <td> +** The new change is ignored. This case does not occur if the new +** changeset was recorded immediately after the changesets already +** added to the changegroup. +** <tr><td>INSERT <td>UPDATE <td> +** The INSERT change remains in the changegroup. The values in the +** INSERT change are modified as if the row was inserted by the +** existing change and then updated according to the new change. +** <tr><td>INSERT <td>DELETE <td> +** The existing INSERT is removed from the changegroup. The DELETE is +** not added. +** <tr><td>UPDATE <td>INSERT <td> +** The new change is ignored. This case does not occur if the new +** changeset was recorded immediately after the changesets already +** added to the changegroup. +** <tr><td>UPDATE <td>UPDATE <td> +** The existing UPDATE remains within the changegroup. It is amended +** so that the accompanying values are as if the row was updated once +** by the existing change and then again by the new change. +** <tr><td>UPDATE <td>DELETE <td> +** The existing UPDATE is replaced by the new DELETE within the +** changegroup. +** <tr><td>DELETE <td>INSERT <td> +** If one or more of the column values in the row inserted by the +** new change differ from those in the row deleted by the existing +** change, the existing DELETE is replaced by an UPDATE within the +** changegroup. Otherwise, if the inserted row is exactly the same +** as the deleted row, the existing DELETE is simply discarded. +** <tr><td>DELETE <td>UPDATE <td> +** The new change is ignored. This case does not occur if the new +** changeset was recorded immediately after the changesets already +** added to the changegroup. +** <tr><td>DELETE <td>DELETE <td> +** The new change is ignored. This case does not occur if the new +** changeset was recorded immediately after the changesets already +** added to the changegroup. +** </table> +** +** If the new changeset contains changes to a table that is already present +** in the changegroup, then the number of columns and the position of the +** primary key columns for the table must be consistent. If this is not the +** case, this function fails with SQLITE_SCHEMA. If the input changeset +** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is +** returned. Or, if an out-of-memory condition occurs during processing, this +** function returns SQLITE_NOMEM. In all cases, if an error occurs the +** final contents of the changegroup is undefined. +** +** If no error occurs, SQLITE_OK is returned. +*/ +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); + +/* +** CAPI3REF: Obtain A Composite Changeset From A Changegroup +** METHOD: sqlite3_changegroup +** +** Obtain a buffer containing a changeset (or patchset) representing the +** current contents of the changegroup. If the inputs to the changegroup +** were themselves changesets, the output is a changeset. Or, if the +** inputs were patchsets, the output is also a patchset. +** +** As with the output of the sqlite3session_changeset() and +** sqlite3session_patchset() functions, all changes related to a single +** table are grouped together in the output of this function. Tables appear +** in the same order as for the very first changeset added to the changegroup. +** If the second or subsequent changesets added to the changegroup contain +** changes for tables that do not appear in the first changeset, they are +** appended onto the end of the output changeset, again in the order in +** which they are first encountered. +** +** If an error occurs, an SQLite error code is returned and the output +** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK +** is returned and the output variables are set to the size of and a +** pointer to the output buffer, respectively. In this case it is the +** responsibility of the caller to eventually free the buffer using a +** call to sqlite3_free(). +*/ +SQLITE_API int sqlite3changegroup_output( + sqlite3_changegroup*, + int *pnData, /* OUT: Size of output buffer in bytes */ + void **ppData /* OUT: Pointer to output buffer */ +); + +/* +** CAPI3REF: Delete A Changegroup Object +** DESTRUCTOR: sqlite3_changegroup +*/ +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); + +/* +** CAPI3REF: Apply A Changeset To A Database +** +** Apply a changeset or patchset to a database. These functions attempt to +** update the "main" database attached to handle db with the changes found in +** the changeset passed via the second and third arguments. +** +** The fourth argument (xFilter) passed to these functions is the "filter +** callback". If it is not NULL, then for each table affected by at least one +** change in the changeset, the filter callback is invoked with +** the table name as the second argument, and a copy of the context pointer +** passed as the sixth argument as the first. If the "filter callback" +** returns zero, then no attempt is made to apply any changes to the table. +** Otherwise, if the return value is non-zero or the xFilter argument to +** is NULL, all changes related to the table are attempted. +** +** For each table that is not excluded by the filter callback, this function +** tests that the target database contains a compatible table. A table is +** considered compatible if all of the following are true: +** +** <ul> +** <li> The table has the same name as the name recorded in the +** changeset, and +** <li> The table has at least as many columns as recorded in the +** changeset, and +** <li> The table has primary key columns in the same position as +** recorded in the changeset. +** </ul> +** +** If there is no compatible table, it is not an error, but none of the +** changes associated with the table are applied. A warning message is issued +** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most +** one such warning is issued for each table in the changeset. +** +** For each change for which there is a compatible table, an attempt is made +** to modify the table contents according to the UPDATE, INSERT or DELETE +** change. If a change cannot be applied cleanly, the conflict handler +** function passed as the fifth argument to sqlite3changeset_apply() may be +** invoked. A description of exactly when the conflict handler is invoked for +** each type of change is below. +** +** Unlike the xFilter argument, xConflict may not be passed NULL. The results +** of passing anything other than a valid function pointer as the xConflict +** argument are undefined. +** +** Each time the conflict handler function is invoked, it must return one +** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or +** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned +** if the second argument passed to the conflict handler is either +** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler +** returns an illegal value, any changes already made are rolled back and +** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different +** actions are taken by sqlite3changeset_apply() depending on the value +** returned by each invocation of the conflict-handler function. Refer to +** the documentation for the three +** [SQLITE_CHANGESET_OMIT|available return values] for details. +** +** <dl> +** <dt>DELETE Changes<dd> +** For each DELETE change, the function checks if the target database +** contains a row with the same primary key value (or values) as the +** original row values stored in the changeset. If it does, and the values +** stored in all non-primary key columns also match the values stored in +** the changeset the row is deleted from the target database. +** +** If a row with matching primary key values is found, but one or more of +** the non-primary key fields contains a value different from the original +** row value stored in the changeset, the conflict-handler function is +** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the +** database table has more columns than are recorded in the changeset, +** only the values of those non-primary key fields are compared against +** the current database contents - any trailing database table columns +** are ignored. +** +** If no row with matching primary key values is found in the database, +** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] +** passed as the second argument. +** +** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT +** (which can only happen if a foreign key constraint is violated), the +** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT] +** passed as the second argument. This includes the case where the DELETE +** operation is attempted because an earlier call to the conflict handler +** function returned [SQLITE_CHANGESET_REPLACE]. +** +** <dt>INSERT Changes<dd> +** For each INSERT change, an attempt is made to insert the new row into +** the database. If the changeset row contains fewer fields than the +** database table, the trailing fields are populated with their default +** values. +** +** If the attempt to insert the row fails because the database already +** contains a row with the same primary key values, the conflict handler +** function is invoked with the second argument set to +** [SQLITE_CHANGESET_CONFLICT]. +** +** If the attempt to insert the row fails because of some other constraint +** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is +** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT]. +** This includes the case where the INSERT operation is re-attempted because +** an earlier call to the conflict handler function returned +** [SQLITE_CHANGESET_REPLACE]. +** +** <dt>UPDATE Changes<dd> +** For each UPDATE change, the function checks if the target database +** contains a row with the same primary key value (or values) as the +** original row values stored in the changeset. If it does, and the values +** stored in all modified non-primary key columns also match the values +** stored in the changeset the row is updated within the target database. +** +** If a row with matching primary key values is found, but one or more of +** the modified non-primary key fields contains a value different from an +** original row value stored in the changeset, the conflict-handler function +** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since +** UPDATE changes only contain values for non-primary key fields that are +** to be modified, only those fields need to match the original values to +** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. +** +** If no row with matching primary key values is found in the database, +** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] +** passed as the second argument. +** +** If the UPDATE operation is attempted, but SQLite returns +** SQLITE_CONSTRAINT, the conflict-handler function is invoked with +** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument. +** This includes the case where the UPDATE operation is attempted after +** an earlier call to the conflict handler function returned +** [SQLITE_CHANGESET_REPLACE]. +** </dl> +** +** It is safe to execute SQL statements, including those that write to the +** table that the callback related to, from within the xConflict callback. +** This can be used to further customize the applications conflict +** resolution strategy. +** +** All changes made by these functions are enclosed in a savepoint transaction. +** If any other error (aside from a constraint failure when attempting to +** write to the target database) occurs, then the savepoint transaction is +** rolled back, restoring the target database to its original state, and an +** SQLite error code returned. +** +** If the output parameters (ppRebase) and (pnRebase) are non-NULL and +** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2() +** may set (*ppRebase) to point to a "rebase" that may be used with the +** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase) +** is set to the size of the buffer in bytes. It is the responsibility of the +** caller to eventually free any such buffer using sqlite3_free(). The buffer +** is only allocated and populated if one or more conflicts were encountered +** while applying the patchset. See comments surrounding the sqlite3_rebaser +** APIs for further details. +** +** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent +** may be modified by passing a combination of +** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter. +** +** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b> +** and therefore subject to change. +*/ +SQLITE_API int sqlite3changeset_apply( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx /* First argument passed to xConflict */ +); +SQLITE_API int sqlite3changeset_apply_v2( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, /* OUT: Rebase data */ + int flags /* SESSION_CHANGESETAPPLY_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3changeset_apply_v2 +** +** The following flags may passed via the 9th parameter to +** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]: +** +** <dl> +** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd> +** Usually, the sessions module encloses all operations performed by +** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The +** SAVEPOINT is committed if the changeset or patchset is successfully +** applied, or rolled back if an error occurs. Specifying this flag +** causes the sessions module to omit this savepoint. In this case, if the +** caller has an open transaction or savepoint when apply_v2() is called, +** it may revert the partially applied changeset by rolling it back. +** +** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd> +** Invert the changeset before applying it. This is equivalent to inverting +** a changeset using sqlite3changeset_invert() before applying it. It is +** an error to specify this flag with a patchset. +*/ +#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 +#define SQLITE_CHANGESETAPPLY_INVERT 0x0002 + +/* +** CAPI3REF: Constants Passed To The Conflict Handler +** +** Values that may be passed as the second argument to a conflict-handler. +** +** <dl> +** <dt>SQLITE_CHANGESET_DATA<dd> +** The conflict handler is invoked with CHANGESET_DATA as the second argument +** when processing a DELETE or UPDATE change if a row with the required +** PRIMARY KEY fields is present in the database, but one or more other +** (non primary-key) fields modified by the update do not contain the +** expected "before" values. +** +** The conflicting row, in this case, is the database row with the matching +** primary key. +** +** <dt>SQLITE_CHANGESET_NOTFOUND<dd> +** The conflict handler is invoked with CHANGESET_NOTFOUND as the second +** argument when processing a DELETE or UPDATE change if a row with the +** required PRIMARY KEY fields is not present in the database. +** +** There is no conflicting row in this case. The results of invoking the +** sqlite3changeset_conflict() API are undefined. +** +** <dt>SQLITE_CHANGESET_CONFLICT<dd> +** CHANGESET_CONFLICT is passed as the second argument to the conflict +** handler while processing an INSERT change if the operation would result +** in duplicate primary key values. +** +** The conflicting row in this case is the database row with the matching +** primary key. +** +** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd> +** If foreign key handling is enabled, and applying a changeset leaves the +** database in a state containing foreign key violations, the conflict +** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument +** exactly once before the changeset is committed. If the conflict handler +** returns CHANGESET_OMIT, the changes, including those that caused the +** foreign key constraint violation, are committed. Or, if it returns +** CHANGESET_ABORT, the changeset is rolled back. +** +** No current or conflicting row information is provided. The only function +** it is possible to call on the supplied sqlite3_changeset_iter handle +** is sqlite3changeset_fk_conflicts(). +** +** <dt>SQLITE_CHANGESET_CONSTRAINT<dd> +** If any other constraint violation occurs while applying a change (i.e. +** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is +** invoked with CHANGESET_CONSTRAINT as the second argument. +** +** There is no conflicting row in this case. The results of invoking the +** sqlite3changeset_conflict() API are undefined. +** +** </dl> +*/ +#define SQLITE_CHANGESET_DATA 1 +#define SQLITE_CHANGESET_NOTFOUND 2 +#define SQLITE_CHANGESET_CONFLICT 3 +#define SQLITE_CHANGESET_CONSTRAINT 4 +#define SQLITE_CHANGESET_FOREIGN_KEY 5 + +/* +** CAPI3REF: Constants Returned By The Conflict Handler +** +** A conflict handler callback must return one of the following three values. +** +** <dl> +** <dt>SQLITE_CHANGESET_OMIT<dd> +** If a conflict handler returns this value no special action is taken. The +** change that caused the conflict is not applied. The session module +** continues to the next change in the changeset. +** +** <dt>SQLITE_CHANGESET_REPLACE<dd> +** This value may only be returned if the second argument to the conflict +** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this +** is not the case, any changes applied so far are rolled back and the +** call to sqlite3changeset_apply() returns SQLITE_MISUSE. +** +** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict +** handler, then the conflicting row is either updated or deleted, depending +** on the type of change. +** +** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict +** handler, then the conflicting row is removed from the database and a +** second attempt to apply the change is made. If this second attempt fails, +** the original row is restored to the database before continuing. +** +** <dt>SQLITE_CHANGESET_ABORT<dd> +** If this value is returned, any changes applied so far are rolled back +** and the call to sqlite3changeset_apply() returns SQLITE_ABORT. +** </dl> +*/ +#define SQLITE_CHANGESET_OMIT 0 +#define SQLITE_CHANGESET_REPLACE 1 +#define SQLITE_CHANGESET_ABORT 2 + +/* +** CAPI3REF: Rebasing changesets +** EXPERIMENTAL +** +** Suppose there is a site hosting a database in state S0. And that +** modifications are made that move that database to state S1 and a +** changeset recorded (the "local" changeset). Then, a changeset based +** on S0 is received from another site (the "remote" changeset) and +** applied to the database. The database is then in state +** (S1+"remote"), where the exact state depends on any conflict +** resolution decisions (OMIT or REPLACE) made while applying "remote". +** Rebasing a changeset is to update it to take those conflict +** resolution decisions into account, so that the same conflicts +** do not have to be resolved elsewhere in the network. +** +** For example, if both the local and remote changesets contain an +** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)": +** +** local: INSERT INTO t1 VALUES(1, 'v1'); +** remote: INSERT INTO t1 VALUES(1, 'v2'); +** +** and the conflict resolution is REPLACE, then the INSERT change is +** removed from the local changeset (it was overridden). Or, if the +** conflict resolution was "OMIT", then the local changeset is modified +** to instead contain: +** +** UPDATE t1 SET b = 'v2' WHERE a=1; +** +** Changes within the local changeset are rebased as follows: +** +** <dl> +** <dt>Local INSERT<dd> +** This may only conflict with a remote INSERT. If the conflict +** resolution was OMIT, then add an UPDATE change to the rebased +** changeset. Or, if the conflict resolution was REPLACE, add +** nothing to the rebased changeset. +** +** <dt>Local DELETE<dd> +** This may conflict with a remote UPDATE or DELETE. In both cases the +** only possible resolution is OMIT. If the remote operation was a +** DELETE, then add no change to the rebased changeset. If the remote +** operation was an UPDATE, then the old.* fields of change are updated +** to reflect the new.* values in the UPDATE. +** +** <dt>Local UPDATE<dd> +** This may conflict with a remote UPDATE or DELETE. If it conflicts +** with a DELETE, and the conflict resolution was OMIT, then the update +** is changed into an INSERT. Any undefined values in the new.* record +** from the update change are filled in using the old.* values from +** the conflicting DELETE. Or, if the conflict resolution was REPLACE, +** the UPDATE change is simply omitted from the rebased changeset. +** +** If conflict is with a remote UPDATE and the resolution is OMIT, then +** the old.* values are rebased using the new.* values in the remote +** change. Or, if the resolution is REPLACE, then the change is copied +** into the rebased changeset with updates to columns also updated by +** the conflicting remote UPDATE removed. If this means no columns would +** be updated, the change is omitted. +** </dl> +** +** A local change may be rebased against multiple remote changes +** simultaneously. If a single key is modified by multiple remote +** changesets, they are combined as follows before the local changeset +** is rebased: +** +** <ul> +** <li> If there has been one or more REPLACE resolutions on a +** key, it is rebased according to a REPLACE. +** +** <li> If there have been no REPLACE resolutions on a key, then +** the local changeset is rebased according to the most recent +** of the OMIT resolutions. +** </ul> +** +** Note that conflict resolutions from multiple remote changesets are +** combined on a per-field basis, not per-row. This means that in the +** case of multiple remote UPDATE operations, some fields of a single +** local change may be rebased for REPLACE while others are rebased for +** OMIT. +** +** In order to rebase a local changeset, the remote changeset must first +** be applied to the local database using sqlite3changeset_apply_v2() and +** the buffer of rebase information captured. Then: +** +** <ol> +** <li> An sqlite3_rebaser object is created by calling +** sqlite3rebaser_create(). +** <li> The new object is configured with the rebase buffer obtained from +** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure(). +** If the local changeset is to be rebased against multiple remote +** changesets, then sqlite3rebaser_configure() should be called +** multiple times, in the same order that the multiple +** sqlite3changeset_apply_v2() calls were made. +** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase(). +** <li> The sqlite3_rebaser object is deleted by calling +** sqlite3rebaser_delete(). +** </ol> +*/ +typedef struct sqlite3_rebaser sqlite3_rebaser; + +/* +** CAPI3REF: Create a changeset rebaser object. +** EXPERIMENTAL +** +** Allocate a new changeset rebaser object. If successful, set (*ppNew) to +** point to the new object and return SQLITE_OK. Otherwise, if an error +** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew) +** to NULL. +*/ +SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew); + +/* +** CAPI3REF: Configure a changeset rebaser object. +** EXPERIMENTAL +** +** Configure the changeset rebaser object to rebase changesets according +** to the conflict resolutions described by buffer pRebase (size nRebase +** bytes), which must have been obtained from a previous call to +** sqlite3changeset_apply_v2(). +*/ +SQLITE_API int sqlite3rebaser_configure( + sqlite3_rebaser*, + int nRebase, const void *pRebase +); + +/* +** CAPI3REF: Rebase a changeset +** EXPERIMENTAL +** +** Argument pIn must point to a buffer containing a changeset nIn bytes +** in size. This function allocates and populates a buffer with a copy +** of the changeset rebased rebased according to the configuration of the +** rebaser object passed as the first argument. If successful, (*ppOut) +** is set to point to the new buffer containing the rebased changeset and +** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the +** responsibility of the caller to eventually free the new buffer using +** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut) +** are set to zero and an SQLite error code returned. +*/ +SQLITE_API int sqlite3rebaser_rebase( + sqlite3_rebaser*, + int nIn, const void *pIn, + int *pnOut, void **ppOut +); + +/* +** CAPI3REF: Delete a changeset rebaser object. +** EXPERIMENTAL +** +** Delete the changeset rebaser object and all associated resources. There +** should be one call to this function for each successful invocation +** of sqlite3rebaser_create(). +*/ +SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p); + +/* +** CAPI3REF: Streaming Versions of API functions. +** +** The six streaming API xxx_strm() functions serve similar purposes to the +** corresponding non-streaming API functions: +** +** <table border=1 style="margin-left:8ex;margin-right:8ex"> +** <tr><th>Streaming function<th>Non-streaming equivalent</th> +** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply] +** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2] +** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat] +** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert] +** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start] +** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset] +** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset] +** </table> +** +** Non-streaming functions that accept changesets (or patchsets) as input +** require that the entire changeset be stored in a single buffer in memory. +** Similarly, those that return a changeset or patchset do so by returning +** a pointer to a single large buffer allocated using sqlite3_malloc(). +** Normally this is convenient. However, if an application running in a +** low-memory environment is required to handle very large changesets, the +** large contiguous memory allocations required can become onerous. +** +** In order to avoid this problem, instead of a single large buffer, input +** is passed to a streaming API functions by way of a callback function that +** the sessions module invokes to incrementally request input data as it is +** required. In all cases, a pair of API function parameters such as +** +** <pre> +**   int nChangeset, +**   void *pChangeset, +** </pre> +** +** Is replaced by: +** +** <pre> +**   int (*xInput)(void *pIn, void *pData, int *pnData), +**   void *pIn, +** </pre> +** +** Each time the xInput callback is invoked by the sessions module, the first +** argument passed is a copy of the supplied pIn context pointer. The second +** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no +** error occurs the xInput method should copy up to (*pnData) bytes of data +** into the buffer and set (*pnData) to the actual number of bytes copied +** before returning SQLITE_OK. If the input is completely exhausted, (*pnData) +** should be set to zero to indicate this. Or, if an error occurs, an SQLite +** error code should be returned. In all cases, if an xInput callback returns +** an error, all processing is abandoned and the streaming API function +** returns a copy of the error code to the caller. +** +** In the case of sqlite3changeset_start_strm(), the xInput callback may be +** invoked by the sessions module at any point during the lifetime of the +** iterator. If such an xInput callback returns an error, the iterator enters +** an error state, whereby all subsequent calls to iterator functions +** immediately fail with the same error code as returned by xInput. +** +** Similarly, streaming API functions that return changesets (or patchsets) +** return them in chunks by way of a callback function instead of via a +** pointer to a single large buffer. In this case, a pair of parameters such +** as: +** +** <pre> +**   int *pnChangeset, +**   void **ppChangeset, +** </pre> +** +** Is replaced by: +** +** <pre> +**   int (*xOutput)(void *pOut, const void *pData, int nData), +**   void *pOut +** </pre> +** +** The xOutput callback is invoked zero or more times to return data to +** the application. The first parameter passed to each call is a copy of the +** pOut pointer supplied by the application. The second parameter, pData, +** points to a buffer nData bytes in size containing the chunk of output +** data being returned. If the xOutput callback successfully processes the +** supplied data, it should return SQLITE_OK to indicate success. Otherwise, +** it should return some other SQLite error code. In this case processing +** is immediately abandoned and the streaming API function returns a copy +** of the xOutput error code to the application. +** +** The sessions module never invokes an xOutput callback with the third +** parameter set to a value less than or equal to zero. Other than this, +** no guarantees are made as to the size of the chunks of data returned. +*/ +SQLITE_API int sqlite3changeset_apply_strm( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx /* First argument passed to xConflict */ +); +SQLITE_API int sqlite3changeset_apply_v2_strm( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, + int flags +); +SQLITE_API int sqlite3changeset_concat_strm( + int (*xInputA)(void *pIn, void *pData, int *pnData), + void *pInA, + int (*xInputB)(void *pIn, void *pData, int *pnData), + void *pInB, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); +SQLITE_API int sqlite3changeset_invert_strm( + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); +SQLITE_API int sqlite3changeset_start_strm( + sqlite3_changeset_iter **pp, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn +); +SQLITE_API int sqlite3changeset_start_v2_strm( + sqlite3_changeset_iter **pp, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int flags +); +SQLITE_API int sqlite3session_changeset_strm( + sqlite3_session *pSession, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); +SQLITE_API int sqlite3session_patchset_strm( + sqlite3_session *pSession, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn +); +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); +SQLITE_API int sqlite3rebaser_rebase_strm( + sqlite3_rebaser *pRebaser, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); + +/* +** CAPI3REF: Configure global parameters +** +** The sqlite3session_config() interface is used to make global configuration +** changes to the sessions module in order to tune it to the specific needs +** of the application. +** +** The sqlite3session_config() interface is not threadsafe. If it is invoked +** while any other thread is inside any other sessions method then the +** results are undefined. Furthermore, if it is invoked after any sessions +** related objects have been created, the results are also undefined. +** +** The first argument to the sqlite3session_config() function must be one +** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The +** interpretation of the (void*) value passed as the second parameter and +** the effect of calling this function depends on the value of the first +** parameter. +** +** <dl> +** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd> +** By default, the sessions module streaming interfaces attempt to input +** and output data in approximately 1 KiB chunks. This operand may be used +** to set and query the value of this configuration setting. The pointer +** passed as the second argument must point to a value of type (int). +** If this value is greater than 0, it is used as the new streaming data +** chunk size for both input and output. Before returning, the (int) value +** pointed to by pArg is set to the final value of the streaming interface +** chunk size. +** </dl> +** +** This function returns SQLITE_OK if successful, or an SQLite error code +** otherwise. +*/ +SQLITE_API int sqlite3session_config(int op, void *pArg); + +/* +** CAPI3REF: Values for sqlite3session_config(). +*/ +#define SQLITE_SESSION_CONFIG_STRMSIZE 1 + +/* +** Make sure we can call this stuff from C++. +*/ +#ifdef __cplusplus +} +#endif + +#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */ + +/******** End of sqlite3session.h *********/ +/******** Begin file fts5.h *********/ +/* +** 2014 May 31 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +****************************************************************************** +** +** Interfaces to extend FTS5. Using the interfaces defined in this file, +** FTS5 may be extended with: +** +** * custom tokenizers, and +** * custom auxiliary functions. +*/ + + +#ifndef _FTS5_H +#define _FTS5_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************* +** CUSTOM AUXILIARY FUNCTIONS +** +** Virtual table implementations may overload SQL functions by implementing +** the sqlite3_module.xFindFunction() method. +*/ + +typedef struct Fts5ExtensionApi Fts5ExtensionApi; +typedef struct Fts5Context Fts5Context; +typedef struct Fts5PhraseIter Fts5PhraseIter; + +typedef void (*fts5_extension_function)( + const Fts5ExtensionApi *pApi, /* API offered by current FTS version */ + Fts5Context *pFts, /* First arg to pass to pApi functions */ + sqlite3_context *pCtx, /* Context for returning result/error */ + int nVal, /* Number of values in apVal[] array */ + sqlite3_value **apVal /* Array of trailing arguments */ +); + +struct Fts5PhraseIter { + const unsigned char *a; + const unsigned char *b; +}; + +/* +** EXTENSION API FUNCTIONS +** +** xUserData(pFts): +** Return a copy of the context pointer the extension function was +** registered with. +** +** xColumnTotalSize(pFts, iCol, pnToken): +** If parameter iCol is less than zero, set output variable *pnToken +** to the total number of tokens in the FTS5 table. Or, if iCol is +** non-negative but less than the number of columns in the table, return +** the total number of tokens in column iCol, considering all rows in +** the FTS5 table. +** +** If parameter iCol is greater than or equal to the number of columns +** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. +** an OOM condition or IO error), an appropriate SQLite error code is +** returned. +** +** xColumnCount(pFts): +** Return the number of columns in the table. +** +** xColumnSize(pFts, iCol, pnToken): +** If parameter iCol is less than zero, set output variable *pnToken +** to the total number of tokens in the current row. Or, if iCol is +** non-negative but less than the number of columns in the table, set +** *pnToken to the number of tokens in column iCol of the current row. +** +** If parameter iCol is greater than or equal to the number of columns +** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. +** an OOM condition or IO error), an appropriate SQLite error code is +** returned. +** +** This function may be quite inefficient if used with an FTS5 table +** created with the "columnsize=0" option. +** +** xColumnText: +** This function attempts to retrieve the text of column iCol of the +** current document. If successful, (*pz) is set to point to a buffer +** containing the text in utf-8 encoding, (*pn) is set to the size in bytes +** (not characters) of the buffer and SQLITE_OK is returned. Otherwise, +** if an error occurs, an SQLite error code is returned and the final values +** of (*pz) and (*pn) are undefined. +** +** xPhraseCount: +** Returns the number of phrases in the current query expression. +** +** xPhraseSize: +** Returns the number of tokens in phrase iPhrase of the query. Phrases +** are numbered starting from zero. +** +** xInstCount: +** Set *pnInst to the total number of occurrences of all phrases within +** the query within the current row. Return SQLITE_OK if successful, or +** an error code (i.e. SQLITE_NOMEM) if an error occurs. +** +** This API can be quite slow if used with an FTS5 table created with the +** "detail=none" or "detail=column" option. If the FTS5 table is created +** with either "detail=none" or "detail=column" and "content=" option +** (i.e. if it is a contentless table), then this API always returns 0. +** +** xInst: +** Query for the details of phrase match iIdx within the current row. +** Phrase matches are numbered starting from zero, so the iIdx argument +** should be greater than or equal to zero and smaller than the value +** output by xInstCount(). +** +** Usually, output parameter *piPhrase is set to the phrase number, *piCol +** to the column in which it occurs and *piOff the token offset of the +** first token of the phrase. Returns SQLITE_OK if successful, or an error +** code (i.e. SQLITE_NOMEM) if an error occurs. +** +** This API can be quite slow if used with an FTS5 table created with the +** "detail=none" or "detail=column" option. +** +** xRowid: +** Returns the rowid of the current row. +** +** xTokenize: +** Tokenize text using the tokenizer belonging to the FTS5 table. +** +** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback): +** This API function is used to query the FTS table for phrase iPhrase +** of the current query. Specifically, a query equivalent to: +** +** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid +** +** with $p set to a phrase equivalent to the phrase iPhrase of the +** current query is executed. Any column filter that applies to +** phrase iPhrase of the current query is included in $p. For each +** row visited, the callback function passed as the fourth argument +** is invoked. The context and API objects passed to the callback +** function may be used to access the properties of each matched row. +** Invoking Api.xUserData() returns a copy of the pointer passed as +** the third argument to pUserData. +** +** If the callback function returns any value other than SQLITE_OK, the +** query is abandoned and the xQueryPhrase function returns immediately. +** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK. +** Otherwise, the error code is propagated upwards. +** +** If the query runs to completion without incident, SQLITE_OK is returned. +** Or, if some error occurs before the query completes or is aborted by +** the callback, an SQLite error code is returned. +** +** +** xSetAuxdata(pFts5, pAux, xDelete) +** +** Save the pointer passed as the second argument as the extension functions +** "auxiliary data". The pointer may then be retrieved by the current or any +** future invocation of the same fts5 extension function made as part of +** the same MATCH query using the xGetAuxdata() API. +** +** Each extension function is allocated a single auxiliary data slot for +** each FTS query (MATCH expression). If the extension function is invoked +** more than once for a single FTS query, then all invocations share a +** single auxiliary data context. +** +** If there is already an auxiliary data pointer when this function is +** invoked, then it is replaced by the new pointer. If an xDelete callback +** was specified along with the original pointer, it is invoked at this +** point. +** +** The xDelete callback, if one is specified, is also invoked on the +** auxiliary data pointer after the FTS5 query has finished. +** +** If an error (e.g. an OOM condition) occurs within this function, +** the auxiliary data is set to NULL and an error code returned. If the +** xDelete parameter was not NULL, it is invoked on the auxiliary data +** pointer before returning. +** +** +** xGetAuxdata(pFts5, bClear) +** +** Returns the current auxiliary data pointer for the fts5 extension +** function. See the xSetAuxdata() method for details. +** +** If the bClear argument is non-zero, then the auxiliary data is cleared +** (set to NULL) before this function returns. In this case the xDelete, +** if any, is not invoked. +** +** +** xRowCount(pFts5, pnRow) +** +** This function is used to retrieve the total number of rows in the table. +** In other words, the same value that would be returned by: +** +** SELECT count(*) FROM ftstable; +** +** xPhraseFirst() +** This function is used, along with type Fts5PhraseIter and the xPhraseNext +** method, to iterate through all instances of a single query phrase within +** the current row. This is the same information as is accessible via the +** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient +** to use, this API may be faster under some circumstances. To iterate +** through instances of phrase iPhrase, use the following code: +** +** Fts5PhraseIter iter; +** int iCol, iOff; +** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff); +** iCol>=0; +** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff) +** ){ +** // An instance of phrase iPhrase at offset iOff of column iCol +** } +** +** The Fts5PhraseIter structure is defined above. Applications should not +** modify this structure directly - it should only be used as shown above +** with the xPhraseFirst() and xPhraseNext() API methods (and by +** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below). +** +** This API can be quite slow if used with an FTS5 table created with the +** "detail=none" or "detail=column" option. If the FTS5 table is created +** with either "detail=none" or "detail=column" and "content=" option +** (i.e. if it is a contentless table), then this API always iterates +** through an empty set (all calls to xPhraseFirst() set iCol to -1). +** +** xPhraseNext() +** See xPhraseFirst above. +** +** xPhraseFirstColumn() +** This function and xPhraseNextColumn() are similar to the xPhraseFirst() +** and xPhraseNext() APIs described above. The difference is that instead +** of iterating through all instances of a phrase in the current row, these +** APIs are used to iterate through the set of columns in the current row +** that contain one or more instances of a specified phrase. For example: +** +** Fts5PhraseIter iter; +** int iCol; +** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol); +** iCol>=0; +** pApi->xPhraseNextColumn(pFts, &iter, &iCol) +** ){ +** // Column iCol contains at least one instance of phrase iPhrase +** } +** +** This API can be quite slow if used with an FTS5 table created with the +** "detail=none" option. If the FTS5 table is created with either +** "detail=none" "content=" option (i.e. if it is a contentless table), +** then this API always iterates through an empty set (all calls to +** xPhraseFirstColumn() set iCol to -1). +** +** The information accessed using this API and its companion +** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext +** (or xInst/xInstCount). The chief advantage of this API is that it is +** significantly more efficient than those alternatives when used with +** "detail=column" tables. +** +** xPhraseNextColumn() +** See xPhraseFirstColumn above. +*/ +struct Fts5ExtensionApi { + int iVersion; /* Currently always set to 3 */ + + void *(*xUserData)(Fts5Context*); + + int (*xColumnCount)(Fts5Context*); + int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow); + int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken); + + int (*xTokenize)(Fts5Context*, + const char *pText, int nText, /* Text to tokenize */ + void *pCtx, /* Context passed to xToken() */ + int (*xToken)(void*, int, const char*, int, int, int) /* Callback */ + ); + + int (*xPhraseCount)(Fts5Context*); + int (*xPhraseSize)(Fts5Context*, int iPhrase); + + int (*xInstCount)(Fts5Context*, int *pnInst); + int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff); + + sqlite3_int64 (*xRowid)(Fts5Context*); + int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn); + int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken); + + int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData, + int(*)(const Fts5ExtensionApi*,Fts5Context*,void*) + ); + int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*)); + void *(*xGetAuxdata)(Fts5Context*, int bClear); + + int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*); + void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff); + + int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*); + void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol); +}; + +/* +** CUSTOM AUXILIARY FUNCTIONS +*************************************************************************/ + +/************************************************************************* +** CUSTOM TOKENIZERS +** +** Applications may also register custom tokenizer types. A tokenizer +** is registered by providing fts5 with a populated instance of the +** following structure. All structure methods must be defined, setting +** any member of the fts5_tokenizer struct to NULL leads to undefined +** behaviour. The structure methods are expected to function as follows: +** +** xCreate: +** This function is used to allocate and initialize a tokenizer instance. +** A tokenizer instance is required to actually tokenize text. +** +** The first argument passed to this function is a copy of the (void*) +** pointer provided by the application when the fts5_tokenizer object +** was registered with FTS5 (the third argument to xCreateTokenizer()). +** The second and third arguments are an array of nul-terminated strings +** containing the tokenizer arguments, if any, specified following the +** tokenizer name as part of the CREATE VIRTUAL TABLE statement used +** to create the FTS5 table. +** +** The final argument is an output variable. If successful, (*ppOut) +** should be set to point to the new tokenizer handle and SQLITE_OK +** returned. If an error occurs, some value other than SQLITE_OK should +** be returned. In this case, fts5 assumes that the final value of *ppOut +** is undefined. +** +** xDelete: +** This function is invoked to delete a tokenizer handle previously +** allocated using xCreate(). Fts5 guarantees that this function will +** be invoked exactly once for each successful call to xCreate(). +** +** xTokenize: +** This function is expected to tokenize the nText byte string indicated +** by argument pText. pText may or may not be nul-terminated. The first +** argument passed to this function is a pointer to an Fts5Tokenizer object +** returned by an earlier call to xCreate(). +** +** The second argument indicates the reason that FTS5 is requesting +** tokenization of the supplied text. This is always one of the following +** four values: +** +** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into +** or removed from the FTS table. The tokenizer is being invoked to +** determine the set of tokens to add to (or delete from) the +** FTS index. +** +** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed +** against the FTS index. The tokenizer is being called to tokenize +** a bareword or quoted string specified as part of the query. +** +** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as +** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is +** followed by a "*" character, indicating that the last token +** returned by the tokenizer will be treated as a token prefix. +** +** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to +** satisfy an fts5_api.xTokenize() request made by an auxiliary +** function. Or an fts5_api.xColumnSize() request made by the same +** on a columnsize=0 database. +** </ul> +** +** For each token in the input string, the supplied callback xToken() must +** be invoked. The first argument to it should be a copy of the pointer +** passed as the second argument to xTokenize(). The third and fourth +** arguments are a pointer to a buffer containing the token text, and the +** size of the token in bytes. The 4th and 5th arguments are the byte offsets +** of the first byte of and first byte immediately following the text from +** which the token is derived within the input. +** +** The second argument passed to the xToken() callback ("tflags") should +** normally be set to 0. The exception is if the tokenizer supports +** synonyms. In this case see the discussion below for details. +** +** FTS5 assumes the xToken() callback is invoked for each token in the +** order that they occur within the input text. +** +** If an xToken() callback returns any value other than SQLITE_OK, then +** the tokenization should be abandoned and the xTokenize() method should +** immediately return a copy of the xToken() return value. Or, if the +** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally, +** if an error occurs with the xTokenize() implementation itself, it +** may abandon the tokenization and return any error code other than +** SQLITE_OK or SQLITE_DONE. +** +** SYNONYM SUPPORT +** +** Custom tokenizers may also support synonyms. Consider a case in which a +** user wishes to query for a phrase such as "first place". Using the +** built-in tokenizers, the FTS5 query 'first + place' will match instances +** of "first place" within the document set, but not alternative forms +** such as "1st place". In some applications, it would be better to match +** all instances of "first place" or "1st place" regardless of which form +** the user specified in the MATCH query text. +** +** There are several ways to approach this in FTS5: +** +** <ol><li> By mapping all synonyms to a single token. In this case, the +** In the above example, this means that the tokenizer returns the +** same token for inputs "first" and "1st". Say that token is in +** fact "first", so that when the user inserts the document "I won +** 1st place" entries are added to the index for tokens "i", "won", +** "first" and "place". If the user then queries for '1st + place', +** the tokenizer substitutes "first" for "1st" and the query works +** as expected. +** +** <li> By querying the index for all synonyms of each query term +** separately. In this case, when tokenizing query text, the +** tokenizer may provide multiple synonyms for a single term +** within the document. FTS5 then queries the index for each +** synonym individually. For example, faced with the query: +** +** <codeblock> +** ... MATCH 'first place'</codeblock> +** +** the tokenizer offers both "1st" and "first" as synonyms for the +** first token in the MATCH query and FTS5 effectively runs a query +** similar to: +** +** <codeblock> +** ... MATCH '(first OR 1st) place'</codeblock> +** +** except that, for the purposes of auxiliary functions, the query +** still appears to contain just two phrases - "(first OR 1st)" +** being treated as a single phrase. +** +** <li> By adding multiple synonyms for a single term to the FTS index. +** Using this method, when tokenizing document text, the tokenizer +** provides multiple synonyms for each token. So that when a +** document such as "I won first place" is tokenized, entries are +** added to the FTS index for "i", "won", "first", "1st" and +** "place". +** +** This way, even if the tokenizer does not provide synonyms +** when tokenizing query text (it should not - to do so would be +** inefficient), it doesn't matter if the user queries for +** 'first + place' or '1st + place', as there are entries in the +** FTS index corresponding to both forms of the first token. +** </ol> +** +** Whether it is parsing document or query text, any call to xToken that +** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit +** is considered to supply a synonym for the previous token. For example, +** when parsing the document "I won first place", a tokenizer that supports +** synonyms would call xToken() 5 times, as follows: +** +** <codeblock> +** xToken(pCtx, 0, "i", 1, 0, 1); +** xToken(pCtx, 0, "won", 3, 2, 5); +** xToken(pCtx, 0, "first", 5, 6, 11); +** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11); +** xToken(pCtx, 0, "place", 5, 12, 17); +**</codeblock> +** +** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time +** xToken() is called. Multiple synonyms may be specified for a single token +** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence. +** There is no limit to the number of synonyms that may be provided for a +** single token. +** +** In many cases, method (1) above is the best approach. It does not add +** extra data to the FTS index or require FTS5 to query for multiple terms, +** so it is efficient in terms of disk space and query speed. However, it +** does not support prefix queries very well. If, as suggested above, the +** token "first" is substituted for "1st" by the tokenizer, then the query: +** +** <codeblock> +** ... MATCH '1s*'</codeblock> +** +** will not match documents that contain the token "1st" (as the tokenizer +** will probably not map "1s" to any prefix of "first"). +** +** For full prefix support, method (3) may be preferred. In this case, +** because the index contains entries for both "first" and "1st", prefix +** queries such as 'fi*' or '1s*' will match correctly. However, because +** extra entries are added to the FTS index, this method uses more space +** within the database. +** +** Method (2) offers a midpoint between (1) and (3). Using this method, +** a query such as '1s*' will match documents that contain the literal +** token "1st", but not "first" (assuming the tokenizer is not able to +** provide synonyms for prefixes). However, a non-prefix query like '1st' +** will match against "1st" and "first". This method does not require +** extra disk space, as no extra entries are added to the FTS index. +** On the other hand, it may require more CPU cycles to run MATCH queries, +** as separate queries of the FTS index are required for each synonym. +** +** When using methods (2) or (3), it is important that the tokenizer only +** provide synonyms when tokenizing document text (method (2)) or query +** text (method (3)), not both. Doing so will not cause any errors, but is +** inefficient. +*/ +typedef struct Fts5Tokenizer Fts5Tokenizer; +typedef struct fts5_tokenizer fts5_tokenizer; +struct fts5_tokenizer { + int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut); + void (*xDelete)(Fts5Tokenizer*); + int (*xTokenize)(Fts5Tokenizer*, + void *pCtx, + int flags, /* Mask of FTS5_TOKENIZE_* flags */ + const char *pText, int nText, + int (*xToken)( + void *pCtx, /* Copy of 2nd argument to xTokenize() */ + int tflags, /* Mask of FTS5_TOKEN_* flags */ + const char *pToken, /* Pointer to buffer containing token */ + int nToken, /* Size of token in bytes */ + int iStart, /* Byte offset of token within input text */ + int iEnd /* Byte offset of end of token within input text */ + ) + ); +}; + +/* Flags that may be passed as the third argument to xTokenize() */ +#define FTS5_TOKENIZE_QUERY 0x0001 +#define FTS5_TOKENIZE_PREFIX 0x0002 +#define FTS5_TOKENIZE_DOCUMENT 0x0004 +#define FTS5_TOKENIZE_AUX 0x0008 + +/* Flags that may be passed by the tokenizer implementation back to FTS5 +** as the third argument to the supplied xToken callback. */ +#define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */ + +/* +** END OF CUSTOM TOKENIZERS +*************************************************************************/ + +/************************************************************************* +** FTS5 EXTENSION REGISTRATION API +*/ +typedef struct fts5_api fts5_api; +struct fts5_api { + int iVersion; /* Currently always set to 2 */ + + /* Create a new tokenizer */ + int (*xCreateTokenizer)( + fts5_api *pApi, + const char *zName, + void *pContext, + fts5_tokenizer *pTokenizer, + void (*xDestroy)(void*) + ); + + /* Find an existing tokenizer */ + int (*xFindTokenizer)( + fts5_api *pApi, + const char *zName, + void **ppContext, + fts5_tokenizer *pTokenizer + ); + + /* Create a new auxiliary function */ + int (*xCreateFunction)( + fts5_api *pApi, + const char *zName, + void *pContext, + fts5_extension_function xFunction, + void (*xDestroy)(void*) + ); +}; + +/* +** END OF REGISTRATION API +*************************************************************************/ + +#ifdef __cplusplus +} /* end of the 'extern "C"' block */ +#endif + +#endif /* _FTS5_H */ + +/******** End of fts5.h *********/ diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h new file mode 100644 index 0000000..87c3e85 --- /dev/null +++ b/src/sqlite3ext.h @@ -0,0 +1,636 @@ +/* +** 2006 June 7 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This header file defines the SQLite interface for use by +** shared libraries that want to be imported as extensions into +** an SQLite instance. Shared libraries that intend to be loaded +** as extensions by SQLite should #include this file instead of +** sqlite3.h. +*/ +#pragma once +#ifndef SQLITE3EXT_H +#define SQLITE3EXT_H +#include "define_inc.h" +#include "sqlite3.h" + +/* +** The following structure holds pointers to all of the SQLite API +** routines. +** +** WARNING: In order to maintain backwards compatibility, add new +** interfaces to the end of this structure only. If you insert new +** interfaces in the middle of this structure, then older different +** versions of SQLite will not be able to load each other's shared +** libraries! +*/ +struct sqlite3_api_routines { + void * (*aggregate_context)(sqlite3_context*,int nBytes); + int (*aggregate_count)(sqlite3_context*); + int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); + int (*bind_double)(sqlite3_stmt*,int,double); + int (*bind_int)(sqlite3_stmt*,int,int); + int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); + int (*bind_null)(sqlite3_stmt*,int); + int (*bind_parameter_count)(sqlite3_stmt*); + int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); + const char * (*bind_parameter_name)(sqlite3_stmt*,int); + int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); + int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); + int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); + int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); + int (*busy_timeout)(sqlite3*,int ms); + int (*changes)(sqlite3*); + int (*close)(sqlite3*); + int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*, + int eTextRep,const char*)); + int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*, + int eTextRep,const void*)); + const void * (*column_blob)(sqlite3_stmt*,int iCol); + int (*column_bytes)(sqlite3_stmt*,int iCol); + int (*column_bytes16)(sqlite3_stmt*,int iCol); + int (*column_count)(sqlite3_stmt*pStmt); + const char * (*column_database_name)(sqlite3_stmt*,int); + const void * (*column_database_name16)(sqlite3_stmt*,int); + const char * (*column_decltype)(sqlite3_stmt*,int i); + const void * (*column_decltype16)(sqlite3_stmt*,int); + double (*column_double)(sqlite3_stmt*,int iCol); + int (*column_int)(sqlite3_stmt*,int iCol); + sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); + const char * (*column_name)(sqlite3_stmt*,int); + const void * (*column_name16)(sqlite3_stmt*,int); + const char * (*column_origin_name)(sqlite3_stmt*,int); + const void * (*column_origin_name16)(sqlite3_stmt*,int); + const char * (*column_table_name)(sqlite3_stmt*,int); + const void * (*column_table_name16)(sqlite3_stmt*,int); + const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); + const void * (*column_text16)(sqlite3_stmt*,int iCol); + int (*column_type)(sqlite3_stmt*,int iCol); + sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); + void * (*commit_hook)(sqlite3*,int(*)(void*),void*); + int (*complete)(const char*sql); + int (*complete16)(const void*sql); + int (*create_collation)(sqlite3*,const char*,int,void*, + int(*)(void*,int,const void*,int,const void*)); + int (*create_collation16)(sqlite3*,const void*,int,void*, + int(*)(void*,int,const void*,int,const void*)); + int (*create_function)(sqlite3*,const char*,int,int,void*, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*)); + int (*create_function16)(sqlite3*,const void*,int,int,void*, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*)); + int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); + int (*data_count)(sqlite3_stmt*pStmt); + sqlite3 * (*db_handle)(sqlite3_stmt*); + int (*declare_vtab)(sqlite3*,const char*); + int (*enable_shared_cache)(int); + int (*errcode)(sqlite3*db); + const char * (*errmsg)(sqlite3*); + const void * (*errmsg16)(sqlite3*); + int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); + int (*expired)(sqlite3_stmt*); + int (*finalize)(sqlite3_stmt*pStmt); + void (*free)(void*); + void (*free_table)(char**result); + int (*get_autocommit)(sqlite3*); + void * (*get_auxdata)(sqlite3_context*,int); + int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); + int (*global_recover)(void); + void (*interruptx)(sqlite3*); + sqlite_int64 (*last_insert_rowid)(sqlite3*); + const char * (*libversion)(void); + int (*libversion_number)(void); + void *(*malloc)(int); + char * (*mprintf)(const char*,...); + int (*open)(const char*,sqlite3**); + int (*open16)(const void*,sqlite3**); + int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); + int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); + void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); + void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); + void *(*realloc)(void*,int); + int (*reset)(sqlite3_stmt*pStmt); + void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); + void (*result_double)(sqlite3_context*,double); + void (*result_error)(sqlite3_context*,const char*,int); + void (*result_error16)(sqlite3_context*,const void*,int); + void (*result_int)(sqlite3_context*,int); + void (*result_int64)(sqlite3_context*,sqlite_int64); + void (*result_null)(sqlite3_context*); + void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); + void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); + void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); + void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); + void (*result_value)(sqlite3_context*,sqlite3_value*); + void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); + int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*, + const char*,const char*),void*); + void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); + char * (*xsnprintf)(int,char*,const char*,...); + int (*step)(sqlite3_stmt*); + int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*, + char const**,char const**,int*,int*,int*); + void (*thread_cleanup)(void); + int (*total_changes)(sqlite3*); + void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); + int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); + void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, + sqlite_int64),void*); + void * (*user_data)(sqlite3_context*); + const void * (*value_blob)(sqlite3_value*); + int (*value_bytes)(sqlite3_value*); + int (*value_bytes16)(sqlite3_value*); + double (*value_double)(sqlite3_value*); + int (*value_int)(sqlite3_value*); + sqlite_int64 (*value_int64)(sqlite3_value*); + int (*value_numeric_type)(sqlite3_value*); + const unsigned char * (*value_text)(sqlite3_value*); + const void * (*value_text16)(sqlite3_value*); + const void * (*value_text16be)(sqlite3_value*); + const void * (*value_text16le)(sqlite3_value*); + int (*value_type)(sqlite3_value*); + char *(*vmprintf)(const char*,va_list); + /* Added ??? */ + int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); + /* Added by 3.3.13 */ + int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); + int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); + int (*clear_bindings)(sqlite3_stmt*); + /* Added by 3.4.1 */ + int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*, + void (*xDestroy)(void *)); + /* Added by 3.5.0 */ + int (*bind_zeroblob)(sqlite3_stmt*,int,int); + int (*blob_bytes)(sqlite3_blob*); + int (*blob_close)(sqlite3_blob*); + int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64, + int,sqlite3_blob**); + int (*blob_read)(sqlite3_blob*,void*,int,int); + int (*blob_write)(sqlite3_blob*,const void*,int,int); + int (*create_collation_v2)(sqlite3*,const char*,int,void*, + int(*)(void*,int,const void*,int,const void*), + void(*)(void*)); + int (*file_control)(sqlite3*,const char*,int,void*); + sqlite3_int64 (*memory_highwater)(int); + sqlite3_int64 (*memory_used)(void); + sqlite3_mutex *(*mutex_alloc)(int); + void (*mutex_enter)(sqlite3_mutex*); + void (*mutex_free)(sqlite3_mutex*); + void (*mutex_leave)(sqlite3_mutex*); + int (*mutex_try)(sqlite3_mutex*); + int (*open_v2)(const char*,sqlite3**,int,const char*); + int (*release_memory)(int); + void (*result_error_nomem)(sqlite3_context*); + void (*result_error_toobig)(sqlite3_context*); + int (*sleep)(int); + void (*soft_heap_limit)(int); + sqlite3_vfs *(*vfs_find)(const char*); + int (*vfs_register)(sqlite3_vfs*,int); + int (*vfs_unregister)(sqlite3_vfs*); + int (*xthreadsafe)(void); + void (*result_zeroblob)(sqlite3_context*,int); + void (*result_error_code)(sqlite3_context*,int); + int (*test_control)(int, ...); + void (*randomness)(int,void*); + sqlite3 *(*context_db_handle)(sqlite3_context*); + int (*extended_result_codes)(sqlite3*,int); + int (*limit)(sqlite3*,int,int); + sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); + const char *(*sql)(sqlite3_stmt*); + int (*status)(int,int*,int*,int); + int (*backup_finish)(sqlite3_backup*); + sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*); + int (*backup_pagecount)(sqlite3_backup*); + int (*backup_remaining)(sqlite3_backup*); + int (*backup_step)(sqlite3_backup*,int); + const char *(*compileoption_get)(int); + int (*compileoption_used)(const char*); + int (*create_function_v2)(sqlite3*,const char*,int,int,void*, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*), + void(*xDestroy)(void*)); + int (*db_config)(sqlite3*,int,...); + sqlite3_mutex *(*db_mutex)(sqlite3*); + int (*db_status)(sqlite3*,int,int*,int*,int); + int (*extended_errcode)(sqlite3*); + void (*log)(int,const char*,...); + sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); + const char *(*sourceid)(void); + int (*stmt_status)(sqlite3_stmt*,int,int); + int (*strnicmp)(const char*,const char*,int); + int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*); + int (*wal_autocheckpoint)(sqlite3*,int); + int (*wal_checkpoint)(sqlite3*,const char*); + void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); + int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); + int (*vtab_config)(sqlite3*,int op,...); + int (*vtab_on_conflict)(sqlite3*); + /* Version 3.7.16 and later */ + int (*close_v2)(sqlite3*); + const char *(*db_filename)(sqlite3*,const char*); + int (*db_readonly)(sqlite3*,const char*); + int (*db_release_memory)(sqlite3*); + const char *(*errstr)(int); + int (*stmt_busy)(sqlite3_stmt*); + int (*stmt_readonly)(sqlite3_stmt*); + int (*stricmp)(const char*,const char*); + int (*uri_boolean)(const char*,const char*,int); + sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); + const char *(*uri_parameter)(const char*,const char*); + char *(*xvsnprintf)(int,char*,const char*,va_list); + int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); + /* Version 3.8.7 and later */ + int (*auto_extension)(void(*)(void)); + int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64, + void(*)(void*)); + int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64, + void(*)(void*),unsigned char); + int (*cancel_auto_extension)(void(*)(void)); + int (*load_extension)(sqlite3*,const char*,const char*,char**); + void *(*malloc64)(sqlite3_uint64); + sqlite3_uint64 (*msize)(void*); + void *(*realloc64)(void*,sqlite3_uint64); + void (*reset_auto_extension)(void); + void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64, + void(*)(void*)); + void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64, + void(*)(void*), unsigned char); + int (*strglob)(const char*,const char*); + /* Version 3.8.11 and later */ + sqlite3_value *(*value_dup)(const sqlite3_value*); + void (*value_free)(sqlite3_value*); + int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64); + int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64); + /* Version 3.9.0 and later */ + unsigned int (*value_subtype)(sqlite3_value*); + void (*result_subtype)(sqlite3_context*,unsigned int); + /* Version 3.10.0 and later */ + int (*status64)(int,sqlite3_int64*,sqlite3_int64*,int); + int (*strlike)(const char*,const char*,unsigned int); + int (*db_cacheflush)(sqlite3*); + /* Version 3.12.0 and later */ + int (*system_errno)(sqlite3*); + /* Version 3.14.0 and later */ + int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*); + char *(*expanded_sql)(sqlite3_stmt*); + /* Version 3.18.0 and later */ + void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64); + /* Version 3.20.0 and later */ + int (*prepare_v3)(sqlite3*,const char*,int,unsigned int, + sqlite3_stmt**,const char**); + int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int, + sqlite3_stmt**,const void**); + int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*)); + void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*)); + void *(*value_pointer)(sqlite3_value*,const char*); + int (*vtab_nochange)(sqlite3_context*); + int (*value_nochange)(sqlite3_value*); + const char *(*vtab_collation)(sqlite3_index_info*,int); + /* Version 3.24.0 and later */ + int (*keyword_count)(void); + int (*keyword_name)(int,const char**,int*); + int (*keyword_check)(const char*,int); + sqlite3_str *(*str_new)(sqlite3*); + char *(*str_finish)(sqlite3_str*); + void (*str_appendf)(sqlite3_str*, const char *zFormat, ...); + void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list); + void (*str_append)(sqlite3_str*, const char *zIn, int N); + void (*str_appendall)(sqlite3_str*, const char *zIn); + void (*str_appendchar)(sqlite3_str*, int N, char C); + void (*str_reset)(sqlite3_str*); + int (*str_errcode)(sqlite3_str*); + int (*str_length)(sqlite3_str*); + char *(*str_value)(sqlite3_str*); + /* Version 3.25.0 and later */ + int (*create_window_function)(sqlite3*,const char*,int,int,void*, + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*), + void (*xValue)(sqlite3_context*), + void (*xInv)(sqlite3_context*,int,sqlite3_value**), + void(*xDestroy)(void*)); + /* Version 3.26.0 and later */ + const char *(*normalized_sql)(sqlite3_stmt*); + /* Version 3.28.0 and later */ + int (*stmt_isexplain)(sqlite3_stmt*); + int (*value_frombind)(sqlite3_value*); +}; + +/* +** This is the function signature used for all extension entry points. It +** is also defined in the file "loadext.c". +*/ +typedef int (*sqlite3_loadext_entry)( + sqlite3 *db, /* Handle to the database. */ + char **pzErrMsg, /* Used to set error string on failure. */ + const sqlite3_api_routines *pThunk /* Extension API function pointers. */ +); + +/* +** The following macros redefine the API routines so that they are +** redirected through the global sqlite3_api structure. +** +** This header file is also used by the loadext.c source file +** (part of the main SQLite library - not an extension) so that +** it can get access to the sqlite3_api_routines structure +** definition. But the main library does not want to redefine +** the API. So the redefinition macros are only valid if the +** SQLITE_CORE macros is undefined. +*/ +#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) +#define sqlite3_aggregate_context sqlite3_api->aggregate_context +#ifndef SQLITE_OMIT_DEPRECATED +#define sqlite3_aggregate_count sqlite3_api->aggregate_count +#endif +#define sqlite3_bind_blob sqlite3_api->bind_blob +#define sqlite3_bind_double sqlite3_api->bind_double +#define sqlite3_bind_int sqlite3_api->bind_int +#define sqlite3_bind_int64 sqlite3_api->bind_int64 +#define sqlite3_bind_null sqlite3_api->bind_null +#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count +#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index +#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name +#define sqlite3_bind_text sqlite3_api->bind_text +#define sqlite3_bind_text16 sqlite3_api->bind_text16 +#define sqlite3_bind_value sqlite3_api->bind_value +#define sqlite3_busy_handler sqlite3_api->busy_handler +#define sqlite3_busy_timeout sqlite3_api->busy_timeout +#define sqlite3_changes sqlite3_api->changes +#define sqlite3_close sqlite3_api->close +#define sqlite3_collation_needed sqlite3_api->collation_needed +#define sqlite3_collation_needed16 sqlite3_api->collation_needed16 +#define sqlite3_column_blob sqlite3_api->column_blob +#define sqlite3_column_bytes sqlite3_api->column_bytes +#define sqlite3_column_bytes16 sqlite3_api->column_bytes16 +#define sqlite3_column_count sqlite3_api->column_count +#define sqlite3_column_database_name sqlite3_api->column_database_name +#define sqlite3_column_database_name16 sqlite3_api->column_database_name16 +#define sqlite3_column_decltype sqlite3_api->column_decltype +#define sqlite3_column_decltype16 sqlite3_api->column_decltype16 +#define sqlite3_column_double sqlite3_api->column_double +#define sqlite3_column_int sqlite3_api->column_int +#define sqlite3_column_int64 sqlite3_api->column_int64 +#define sqlite3_column_name sqlite3_api->column_name +#define sqlite3_column_name16 sqlite3_api->column_name16 +#define sqlite3_column_origin_name sqlite3_api->column_origin_name +#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16 +#define sqlite3_column_table_name sqlite3_api->column_table_name +#define sqlite3_column_table_name16 sqlite3_api->column_table_name16 +#define sqlite3_column_text sqlite3_api->column_text +#define sqlite3_column_text16 sqlite3_api->column_text16 +#define sqlite3_column_type sqlite3_api->column_type +#define sqlite3_column_value sqlite3_api->column_value +#define sqlite3_commit_hook sqlite3_api->commit_hook +#define sqlite3_complete sqlite3_api->complete +#define sqlite3_complete16 sqlite3_api->complete16 +#define sqlite3_create_collation sqlite3_api->create_collation +#define sqlite3_create_collation16 sqlite3_api->create_collation16 +#define sqlite3_create_function sqlite3_api->create_function +#define sqlite3_create_function16 sqlite3_api->create_function16 +#define sqlite3_create_module sqlite3_api->create_module +#define sqlite3_create_module_v2 sqlite3_api->create_module_v2 +#define sqlite3_data_count sqlite3_api->data_count +#define sqlite3_db_handle sqlite3_api->db_handle +#define sqlite3_declare_vtab sqlite3_api->declare_vtab +#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache +#define sqlite3_errcode sqlite3_api->errcode +#define sqlite3_errmsg sqlite3_api->errmsg +#define sqlite3_errmsg16 sqlite3_api->errmsg16 +#define sqlite3_exec sqlite3_api->exec +#ifndef SQLITE_OMIT_DEPRECATED +#define sqlite3_expired sqlite3_api->expired +#endif +#define sqlite3_finalize sqlite3_api->finalize +#define sqlite3_free sqlite3_api->free +#define sqlite3_free_table sqlite3_api->free_table +#define sqlite3_get_autocommit sqlite3_api->get_autocommit +#define sqlite3_get_auxdata sqlite3_api->get_auxdata +#define sqlite3_get_table sqlite3_api->get_table +#ifndef SQLITE_OMIT_DEPRECATED +#define sqlite3_global_recover sqlite3_api->global_recover +#endif +#define sqlite3_interrupt sqlite3_api->interruptx +#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid +#define sqlite3_libversion sqlite3_api->libversion +#define sqlite3_libversion_number sqlite3_api->libversion_number +#define sqlite3_malloc sqlite3_api->malloc +#define sqlite3_mprintf sqlite3_api->mprintf +#define sqlite3_open sqlite3_api->open +#define sqlite3_open16 sqlite3_api->open16 +#define sqlite3_prepare sqlite3_api->prepare +#define sqlite3_prepare16 sqlite3_api->prepare16 +#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 +#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 +#define sqlite3_profile sqlite3_api->profile +#define sqlite3_progress_handler sqlite3_api->progress_handler +#define sqlite3_realloc sqlite3_api->realloc +#define sqlite3_reset sqlite3_api->reset +#define sqlite3_result_blob sqlite3_api->result_blob +#define sqlite3_result_double sqlite3_api->result_double +#define sqlite3_result_error sqlite3_api->result_error +#define sqlite3_result_error16 sqlite3_api->result_error16 +#define sqlite3_result_int sqlite3_api->result_int +#define sqlite3_result_int64 sqlite3_api->result_int64 +#define sqlite3_result_null sqlite3_api->result_null +#define sqlite3_result_text sqlite3_api->result_text +#define sqlite3_result_text16 sqlite3_api->result_text16 +#define sqlite3_result_text16be sqlite3_api->result_text16be +#define sqlite3_result_text16le sqlite3_api->result_text16le +#define sqlite3_result_value sqlite3_api->result_value +#define sqlite3_rollback_hook sqlite3_api->rollback_hook +#define sqlite3_set_authorizer sqlite3_api->set_authorizer +#define sqlite3_set_auxdata sqlite3_api->set_auxdata +#define sqlite3_snprintf sqlite3_api->xsnprintf +#define sqlite3_step sqlite3_api->step +#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata +#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup +#define sqlite3_total_changes sqlite3_api->total_changes +#define sqlite3_trace sqlite3_api->trace +#ifndef SQLITE_OMIT_DEPRECATED +#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings +#endif +#define sqlite3_update_hook sqlite3_api->update_hook +#define sqlite3_user_data sqlite3_api->user_data +#define sqlite3_value_blob sqlite3_api->value_blob +#define sqlite3_value_bytes sqlite3_api->value_bytes +#define sqlite3_value_bytes16 sqlite3_api->value_bytes16 +#define sqlite3_value_double sqlite3_api->value_double +#define sqlite3_value_int sqlite3_api->value_int +#define sqlite3_value_int64 sqlite3_api->value_int64 +#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type +#define sqlite3_value_text sqlite3_api->value_text +#define sqlite3_value_text16 sqlite3_api->value_text16 +#define sqlite3_value_text16be sqlite3_api->value_text16be +#define sqlite3_value_text16le sqlite3_api->value_text16le +#define sqlite3_value_type sqlite3_api->value_type +#define sqlite3_vmprintf sqlite3_api->vmprintf +#define sqlite3_vsnprintf sqlite3_api->xvsnprintf +#define sqlite3_overload_function sqlite3_api->overload_function +#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 +#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 +#define sqlite3_clear_bindings sqlite3_api->clear_bindings +#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob +#define sqlite3_blob_bytes sqlite3_api->blob_bytes +#define sqlite3_blob_close sqlite3_api->blob_close +#define sqlite3_blob_open sqlite3_api->blob_open +#define sqlite3_blob_read sqlite3_api->blob_read +#define sqlite3_blob_write sqlite3_api->blob_write +#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 +#define sqlite3_file_control sqlite3_api->file_control +#define sqlite3_memory_highwater sqlite3_api->memory_highwater +#define sqlite3_memory_used sqlite3_api->memory_used +#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc +#define sqlite3_mutex_enter sqlite3_api->mutex_enter +#define sqlite3_mutex_free sqlite3_api->mutex_free +#define sqlite3_mutex_leave sqlite3_api->mutex_leave +#define sqlite3_mutex_try sqlite3_api->mutex_try +#define sqlite3_open_v2 sqlite3_api->open_v2 +#define sqlite3_release_memory sqlite3_api->release_memory +#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem +#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig +#define sqlite3_sleep sqlite3_api->sleep +#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit +#define sqlite3_vfs_find sqlite3_api->vfs_find +#define sqlite3_vfs_register sqlite3_api->vfs_register +#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister +#define sqlite3_threadsafe sqlite3_api->xthreadsafe +#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob +#define sqlite3_result_error_code sqlite3_api->result_error_code +#define sqlite3_test_control sqlite3_api->test_control +#define sqlite3_randomness sqlite3_api->randomness +#define sqlite3_context_db_handle sqlite3_api->context_db_handle +#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes +#define sqlite3_limit sqlite3_api->limit +#define sqlite3_next_stmt sqlite3_api->next_stmt +#define sqlite3_sql sqlite3_api->sql +#define sqlite3_status sqlite3_api->status +#define sqlite3_backup_finish sqlite3_api->backup_finish +#define sqlite3_backup_init sqlite3_api->backup_init +#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount +#define sqlite3_backup_remaining sqlite3_api->backup_remaining +#define sqlite3_backup_step sqlite3_api->backup_step +#define sqlite3_compileoption_get sqlite3_api->compileoption_get +#define sqlite3_compileoption_used sqlite3_api->compileoption_used +#define sqlite3_create_function_v2 sqlite3_api->create_function_v2 +#define sqlite3_db_config sqlite3_api->db_config +#define sqlite3_db_mutex sqlite3_api->db_mutex +#define sqlite3_db_status sqlite3_api->db_status +#define sqlite3_extended_errcode sqlite3_api->extended_errcode +#define sqlite3_log sqlite3_api->log +#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 +#define sqlite3_sourceid sqlite3_api->sourceid +#define sqlite3_stmt_status sqlite3_api->stmt_status +#define sqlite3_strnicmp sqlite3_api->strnicmp +#define sqlite3_unlock_notify sqlite3_api->unlock_notify +#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint +#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint +#define sqlite3_wal_hook sqlite3_api->wal_hook +#define sqlite3_blob_reopen sqlite3_api->blob_reopen +#define sqlite3_vtab_config sqlite3_api->vtab_config +#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict +/* Version 3.7.16 and later */ +#define sqlite3_close_v2 sqlite3_api->close_v2 +#define sqlite3_db_filename sqlite3_api->db_filename +#define sqlite3_db_readonly sqlite3_api->db_readonly +#define sqlite3_db_release_memory sqlite3_api->db_release_memory +#define sqlite3_errstr sqlite3_api->errstr +#define sqlite3_stmt_busy sqlite3_api->stmt_busy +#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly +#define sqlite3_stricmp sqlite3_api->stricmp +#define sqlite3_uri_boolean sqlite3_api->uri_boolean +#define sqlite3_uri_int64 sqlite3_api->uri_int64 +#define sqlite3_uri_parameter sqlite3_api->uri_parameter +#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf +#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 +/* Version 3.8.7 and later */ +#define sqlite3_auto_extension sqlite3_api->auto_extension +#define sqlite3_bind_blob64 sqlite3_api->bind_blob64 +#define sqlite3_bind_text64 sqlite3_api->bind_text64 +#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension +#define sqlite3_load_extension sqlite3_api->load_extension +#define sqlite3_malloc64 sqlite3_api->malloc64 +#define sqlite3_msize sqlite3_api->msize +#define sqlite3_realloc64 sqlite3_api->realloc64 +#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension +#define sqlite3_result_blob64 sqlite3_api->result_blob64 +#define sqlite3_result_text64 sqlite3_api->result_text64 +#define sqlite3_strglob sqlite3_api->strglob +/* Version 3.8.11 and later */ +#define sqlite3_value_dup sqlite3_api->value_dup +#define sqlite3_value_free sqlite3_api->value_free +#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64 +#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64 +/* Version 3.9.0 and later */ +#define sqlite3_value_subtype sqlite3_api->value_subtype +#define sqlite3_result_subtype sqlite3_api->result_subtype +/* Version 3.10.0 and later */ +#define sqlite3_status64 sqlite3_api->status64 +#define sqlite3_strlike sqlite3_api->strlike +#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush +/* Version 3.12.0 and later */ +#define sqlite3_system_errno sqlite3_api->system_errno +/* Version 3.14.0 and later */ +#define sqlite3_trace_v2 sqlite3_api->trace_v2 +#define sqlite3_expanded_sql sqlite3_api->expanded_sql +/* Version 3.18.0 and later */ +#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid +/* Version 3.20.0 and later */ +#define sqlite3_prepare_v3 sqlite3_api->prepare_v3 +#define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3 +#define sqlite3_bind_pointer sqlite3_api->bind_pointer +#define sqlite3_result_pointer sqlite3_api->result_pointer +#define sqlite3_value_pointer sqlite3_api->value_pointer +/* Version 3.22.0 and later */ +#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange +#define sqlite3_value_nochange sqlite3_api->value_nochange +#define sqlite3_vtab_collation sqlite3_api->vtab_collation +/* Version 3.24.0 and later */ +#define sqlite3_keyword_count sqlite3_api->keyword_count +#define sqlite3_keyword_name sqlite3_api->keyword_name +#define sqlite3_keyword_check sqlite3_api->keyword_check +#define sqlite3_str_new sqlite3_api->str_new +#define sqlite3_str_finish sqlite3_api->str_finish +#define sqlite3_str_appendf sqlite3_api->str_appendf +#define sqlite3_str_vappendf sqlite3_api->str_vappendf +#define sqlite3_str_append sqlite3_api->str_append +#define sqlite3_str_appendall sqlite3_api->str_appendall +#define sqlite3_str_appendchar sqlite3_api->str_appendchar +#define sqlite3_str_reset sqlite3_api->str_reset +#define sqlite3_str_errcode sqlite3_api->str_errcode +#define sqlite3_str_length sqlite3_api->str_length +#define sqlite3_str_value sqlite3_api->str_value +/* Version 3.25.0 and later */ +#define sqlite3_create_window_function sqlite3_api->create_window_function +/* Version 3.26.0 and later */ +#define sqlite3_normalized_sql sqlite3_api->normalized_sql +/* Version 3.28.0 and later */ +#define sqlite3_stmt_isexplain sqlite3_api->isexplain +#define sqlite3_value_frombind sqlite3_api->frombind +#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ + +#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) + /* This case when the file really is being compiled as a loadable + ** extension */ +# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0; +# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v; +# define SQLITE_EXTENSION_INIT3 \ + extern const sqlite3_api_routines *sqlite3_api; +#else + /* This case when the file is being statically linked into the + ** application */ +# define SQLITE_EXTENSION_INIT1 /*no-op*/ +# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */ +# define SQLITE_EXTENSION_INIT3 /*no-op*/ +#endif + +#endif /* SQLITE3EXT_H */ diff --git a/src/sqlite_db.c b/src/sqlite_db.c new file mode 100644 index 0000000..aa046f9 --- /dev/null +++ b/src/sqlite_db.c @@ -0,0 +1,1392 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <unistd.h> +#include <time.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/time.h> +//#include "httpd.h" +#include "sqlite_db.h" + +#define SQLTM_COUNT 200 /** -> SQLTM_COUNT*SQLTM_TIME ms timeout **/ +#define SQLTM_TIME 25 + +void db_lock(sqlite3 *pdb) +{ + + sqlite3_mutex_enter(sqlite3_db_mutex(pdb)); +} + +void db_unlock(sqlite3 *pdb) +{ + sqlite3_mutex_leave(sqlite3_db_mutex(pdb)); + +} + +long long db_get_column_value_int64(sqlite3_stmt *pstmt, int index) +{ + if(!pstmt || index < 0) + { + return 0; + } + return (long long)sqlite3_column_int64(pstmt, index); +} + +int db_get_column_value_int(sqlite3_stmt *pstmt, int index) +{ + if(!pstmt || index < 0) + { + return 0; + } + return sqlite3_column_int(pstmt, index); +} + +const char *db_get_column_value_str(sqlite3_stmt *pstmt, int index) +{ + if(!pstmt || index < 0) + { + return (char *)0; + } + return (const char *)sqlite3_column_text(pstmt, index); +} + +const char *db_get_cloumn_name(sqlite3_stmt *pstmt, int index) +{ + if(!pstmt || index < 0) + { + return (char *)0; + } + return sqlite3_column_name(pstmt, index); +} + +int db_get_column_counts(sqlite3_stmt *pstmt) +{ + if(!pstmt) + { + return 0; + } + return sqlite3_column_count(pstmt); +} + +int db_move_next_record(sqlite3_stmt *pstmt) +{ + int rc; + rc = db_step_sql(pstmt); + //PRINT_INFO_LOG(">>>>>>rc=%d\n" , rc); + if(rc == SQLITE_ROW || rc == SQLITE_DONE) + return 1; + return 0; +} + +#if 0 +int db_get_record_counts(sqlite3 *pdb, char *sql) +{ + char *errmsg; + char **azResult; + int nRows = 0, nColumns = 0; + + sqlite3_get_table(pdb, sql, &azResult , &nRows , &nColumns , &errmsg); + if(errmsg != NULL) + { + PRINT_INFO_LOG("%s [Error: %s]\n", sql, errmsg); + sqlite3_free(errmsg); + return 0; + } + +// PRINT_INFO_LOG(">>>>>>row:%d column=%d\n" , nRows , nColumns); + sqlite3_free_table(azResult); + + return nRows; +} +#else +int db_get_record_counts(sqlite3 *pdb, char *table_name) +{ + //printf("\n[db_get_record_counts]-----start\n"); + int nRows = -1, l_ret; + char sql_buf[8192] = {0}; + sqlite3_stmt * sqlite_stmt = NULL; + + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s;", table_name); + //printf("\n[db_get_record_counts]-----start-2\n"); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf,-1,&sqlite_stmt,NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED ) + { + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt ); + sqlite_stmt = NULL; + } + //usSleep((1 + ( 1 + (int) (10 * (rand() / (RAND_MAX + 1.0)))) ) * 1000 ); + usSleep(10); + continue; + } + else + { + if (l_ret == SQLITE_OK) + { + if (sqlite_stmt) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + } + break; + } + } + while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db_get_record_counts]-----end\n"); + return nRows; +} + +int db_get_record_counts_check_ff_lpr(sqlite3 *pdb, char *table_name ,char *ff_lpr_to_check,int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_lpr = '%s';", table_name,ff_lpr_to_check); + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(levenshtein(ff_lpr)) FROM %s;", table_name); + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(levenshtein(ff_lpr,'%s',1)) FROM %s;", table_name, ff_lpr_to_check); + //sqlite3_extension_init(pdb, NULL, NULL); + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_user_name = '%s';", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_lpr = '%s';", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE levenshtein(ff_lpr,'%s',%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //.load /emmc/plugin/Aida_data/lib/liblevenshtein.so\n + //snprintf(sql_buf, sizeof(sql_buf), "SELECT levenshtein('New-York', 'Paris')"); + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + //printf("\n-----------hello\n"); + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + else { + //printf("\n[db get record counts check ff lpr] Error:%d\n", l_ret); + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); + return nRows; +} + +void db_get_record_plate_check_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance, char *replaced_plate) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_lpr = '%s';", table_name,ff_lpr_to_check); + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(levenshtein(ff_lpr)) FROM %s;", table_name); + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(levenshtein(ff_lpr,'%s',1)) FROM %s;", table_name, ff_lpr_to_check); + //sqlite3_extension_init(pdb, NULL, NULL); + if (unlockingKeyInnoFR_success == 1) { + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_user_name = '%s';", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE ff_lpr = '%s';", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT ff_lpr FROM %s WHERE levenshtein(ff_lpr,'%s',%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //.load /emmc/plugin/Aida_data/lib/liblevenshtein.so\n + //snprintf(sql_buf, sizeof(sql_buf), "SELECT levenshtein('New-York', 'Paris')"); + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + //printf("\n-----------hello\n"); + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + snprintf(replaced_plate, 99, db_get_column_value_str(sqlite_stmt, 0)); + } + } + else { + //printf("\n[db get record counts check ff lpr] Error:%d\n", l_ret); + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); +} + + +int db_get_record_counts_check_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_user_name = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_lpr = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND levenshtein(ff_lpr,'%s',%d);", table_name, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + } + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); + return nRows; +} + +void db_get_record_plate_check_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, int levenshtein_distance, char *replaced_plate) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_user_name = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_lpr = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT ff_lpr FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND levenshtein(ff_lpr,'%s',%d);", table_name, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + } + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + snprintf(replaced_plate, 99, db_get_column_value_str(sqlite_stmt, 0)); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); +} + + +int db_get_record_counts_check_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int nRows = -1, l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE UPPER(ff_user_name) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE UPPER(ff_lpr) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE levenshtein(UPPER(ff_lpr), UPPER('%s'),%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int(sqlite_stmt, 0); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); + return nRows; +} + +void db_get_record_plate_check_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance, char *replaced_plate) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE UPPER(ff_user_name) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + //snprintf(sql_buf, sizeof(sql_buf), "SELECT COUNT(*) FROM %s WHERE UPPER(ff_lpr) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT ff_lpr FROM %s WHERE levenshtein(UPPER(ff_lpr), UPPER('%s'),%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + snprintf(replaced_plate, 99, db_get_column_value_str(sqlite_stmt, 0)); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //printf("\n[db get record counts check ff lpr]:%d\n", 5); +} + + +#endif + +void db_get_schedule_start_where_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check,char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE ff_user_name = '%s';", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE ff_lpr = '%s';", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE levenshtein(ff_lpr,'%s',%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + + //printf("\n---------sql_buf:%s\n", sql_buf); + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_TIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_schedule_start_where_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_user_name = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_lpr = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND levenshtein(ff_lpr,'%s',%d);", table_name, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_TIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_schedule_start_where_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE UPPER(ff_user_name) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE UPPER(ff_lpr) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_start FROM %s WHERE levenshtein(UPPER(ff_lpr),UPPER('%s'),%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_TIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + + +void db_get_schedule_end_where_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE ff_user_name = '%s';", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE ff_lpr = '%s';", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE levenshtein(ff_lpr,'%s',%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_TIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_schedule_end_where_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_user_name = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_lpr = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND levenshtein(ff_lpr,'%s',%d);", table_name, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_TIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_schedule_end_where_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE UPPER(ff_user_name) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE UPPER(ff_lpr) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_schedule_end FROM %s WHERE levenshtein(UPPER(ff_lpr),UPPER('%s'),%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_TIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_detect_endtime_where_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE ff_user_name = '%s';", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE ff_lpr = '%s';", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE levenshtein(ff_lpr,'%s',%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_DETECT_ENDTIME-1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_detect_endtime_where_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_user_name = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND ff_lpr = '%s';", table_name, in_other_to_check, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE (in_other = '%s' OR in_other IS NULL OR in_other = '') AND levenshtein(ff_lpr,'%s',%d);", table_name, in_other_to_check, ff_lpr_to_check, levenshtein_distance); + } + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_DETECT_ENDTIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +void db_get_detect_endtime_where_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + if (unlockingKeyInnoFR_success == 1) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE UPPER(ff_user_name) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + if (levenshtein_distance == 0) { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE UPPER(ff_lpr) = UPPER('%s');", table_name, ff_lpr_to_check); + } + else { + snprintf(sql_buf, sizeof(sql_buf), "SELECT in_detect_endtime FROM %s WHERE levenshtein(UPPER(ff_lpr),UPPER('%s'),%d);", table_name, ff_lpr_to_check, levenshtein_distance); + } + } + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, MAX_DETECT_ENDTIME - 1, db_get_column_value_str(sqlite_stmt, 0)); + //printf("\n------------c_column_value: %s\n", c_column_value); + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + + +int db_check_table_exist(sqlite3 *pdb, char *table_name) +{ + int nRows = 0, l_ret = 0; + char l_sql[512] = {0}; + sqlite3_stmt * sqlite_stmt = NULL; + int l_table_exist = 0; + + snprintf(l_sql, sizeof(l_sql)-1, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%s';", table_name); + + do + { + l_ret = sqlite3_prepare_v2(pdb, l_sql,-1,&sqlite_stmt,NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED ) + { + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt ); + sqlite_stmt = NULL; + } + //usSleep( (1 + ( 1 + (int) (10 * (rand() / (RAND_MAX + 1.0)))) ) * 1000 ); + usSleep(10); + continue; + } + else + { + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + nRows = sqlite3_column_int (sqlite_stmt,0); + //PRINT_INFO_LOG("###### [nRows: %d]\n", nRows); + } + } + break; + } + } + while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + + if(nRows) l_table_exist = 1; + + return l_table_exist; +} + +/******************************************************/ +/** PrepareSql: **/ +/** This encapsulates sqlite prepare call to handle **/ +/** timeout condition. **/ +/******************************************************/ + +int db_prepare_sql(sqlite3 *pdb, sqlite3_stmt **pstmt, char *sql) +{ + int l_nRetry = 0, l_rc; + + if(!pdb) return -1; + + do + { + l_rc = sqlite3_prepare_v2(pdb, sql, -1, pstmt, 0); + if( (l_rc == SQLITE_BUSY) || (l_rc == SQLITE_LOCKED) ) + { + l_nRetry++; + usSleep(SQLTM_TIME); + } + } + while((l_nRetry < SQLTM_COUNT) && ((l_rc == SQLITE_BUSY) || (l_rc == SQLITE_LOCKED))); + + return (l_rc == SQLITE_OK) ? 0 : -1; +} + +/******************************************************/ +/** StepSql: **/ +/** This encapsulates sqlite step call to handle **/ +/** timeout condition. **/ +/******************************************************/ +int db_step_sql(sqlite3_stmt *pstmt) +{ + int l_nRetry = 0, l_rc; + + do + { + l_rc = sqlite3_step(pstmt); + if( l_rc == SQLITE_LOCKED ) + { + l_rc = sqlite3_reset(pstmt); /** Note: This will return SQLITE_LOCKED as well... **/ + l_nRetry++; + usSleep(SQLTM_TIME); + } + else + { + if( (l_rc == SQLITE_BUSY) ) + { + usSleep(SQLTM_TIME); + l_nRetry++; + } + } + } + while( (l_nRetry < SQLTM_COUNT) && ((l_rc == SQLITE_BUSY) || (l_rc == SQLITE_LOCKED))); + + if( l_nRetry == SQLTM_COUNT ) + { + fprintf(stderr, "SqlStep Timeout (rc = %d)\n",l_rc); + } + + if( l_nRetry > 2 ) + { + fprintf(stderr, "SqlStep retries %d\n", l_nRetry); + } + + if( l_rc == SQLITE_MISUSE ) + { + fprintf(stderr, "sqlite3_step missuse\n"); + } + + return (l_rc == SQLITE_ROW || l_rc == SQLITE_DONE) ? 0 : -1; +} + +int db_free_sql_stmt(sqlite3_stmt *pstmt) +{ + if (pstmt) + { + int l_ret = sqlite3_finalize(pstmt); + return (l_ret == SQLITE_OK) ? 0 : -1; + + } + return 0; +} + + +int check_if_db_is_malformed = 0; +int db_exec_sql(sqlite3 *pdb, char *sql) +{ + char *l_errmsg = NULL; + int l_ret = SQLITE_ERROR; + + if (pdb) { + l_ret = sqlite3_exec(pdb, sql, NULL, NULL, &l_errmsg); + if (l_ret != SQLITE_OK) + { + //PRINT_INFO_LOG("###### %s [Error: %s]\n", sql, l_errmsg); + printf("\n[db_exec_sql] %s [Error: %s] %d\n", sql, l_errmsg, l_ret); + + if (strstr(l_errmsg, "database disk image is malformed") != NULL) { + check_if_db_is_malformed = 1; + } + } + } + + if (l_errmsg != NULL) { + sqlite3_free(l_errmsg); + l_errmsg = NULL; + } + + return (l_ret == SQLITE_DONE || l_ret == SQLITE_ROW || l_ret == SQLITE_OK) ? 0 : -1; +} + + + +int db_back_up(sqlite3 *pInMemory, const char *zFilename, int isSavePath){ + int l_rc; /* Function return code */ + sqlite3 *pFile; /* Database connection opened on zFilename */ + sqlite3_backup *pBackup; /* Backup object used to copy data */ + sqlite3 *pTo; /* Database to copy to (pFile or pInMemory) */ + sqlite3 *pFrom; /* Database to copy from (pFile or pInMemory) */ + + l_rc = sqlite3_open(zFilename, &pFile); + if( l_rc == SQLITE_OK ) + { + pFrom = (isSavePath ? pInMemory : pFile); + pTo = (isSavePath ? pFile : pInMemory); + + pBackup = sqlite3_backup_init(pTo, "main", pFrom, "main"); + if( pBackup ) + { + (void)sqlite3_backup_step(pBackup, -1); + (void)sqlite3_backup_finish(pBackup); + } + l_rc = sqlite3_errcode(pTo); + } + + if(pFile) (void)sqlite3_close(pFile); + + return l_rc; +} + +#ifdef GY_OS_AMBA +// Callback function to handle SQL query results +static int db_callback(void *data, int argc, char **argv, char **azColName) { + // In this example, we assume the query only returns one column (MAX(ff_face_uid) as an integer) + // and one row. So, we directly copy the result to the buffer pointed by data. + if (argc > 0 && argv[0]) { + int *result = (int *)data; + *result = atoi(argv[0]); + } + return 0; +} + +// Function to execute SQL query and get the result (as an integer) +int db_search_max_ff_face_name(sqlite3 *pdb, const char *table_name) { + char *errMessage = 0; + int result = -1; // Default result in case of an error + + // Build the SQL query with the provided table name + char sql[256]; + snprintf(sql, sizeof(sql), "SELECT MAX(CAST(ff_face_name AS INTEGER)) FROM %s WHERE ff_face_name NOT LIKE '%%[^0-9]%%';", table_name); + + // Execute SQL query + int rc = sqlite3_exec(pdb, sql, db_callback, &result, &errMessage); + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", errMessage); + sqlite3_free(errMessage); + } + + return result; // Return the integer result +} + +// Function to execute SQL query and get the result (as an integer) +int db_search_max_ff_face_name_union_two(sqlite3 *pdb, const char *column_name, const char *table_name_a, const char *table_name_b) { + char *errMessage = 0; + int result = -1; // Default result in case of an error + + // Build the SQL query with the provided table name + char sql[512]; + snprintf(sql, sizeof(sql), CMD_SELECT_MAX); + + // printf("ggggggggggggggggggggggggggggggggggggg \n sql cmd: %s \n", sql); + + // Execute SQL query + int rc = sqlite3_exec(pdb, sql, db_callback, &result, &errMessage); + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", errMessage); + sqlite3_free(errMessage); + } + + return result; // Return the integer result +} + + +void db_search_ff_user_name(sqlite3 *pdb, char *table_name, const char *ff_lpr_to_check, char* c_column_value) +{ + //printf("\n[db get record counts check ff lpr]:%d\n",1); + int /*nRows = -1,*/ l_ret; + char sql_buf[512] = { 0 }; + sqlite3_stmt * sqlite_stmt = NULL; + + + snprintf(sql_buf, sizeof(sql_buf), "SELECT ff_user_name FROM %s WHERE ff_face_name = '%s';", table_name, ff_lpr_to_check); + + + //printf("\n[db get record counts check ff lpr]:%d\n", 2); + do + { + l_ret = sqlite3_prepare_v2(pdb, sql_buf, -1, &sqlite_stmt, NULL); + if (l_ret == SQLITE_BUSY || l_ret == SQLITE_LOCKED) + { + //printf("\n[db get record counts check ff lpr]:%d\n", 3); + if (sqlite_stmt) + { + sqlite3_finalize(sqlite_stmt); + sqlite_stmt = NULL; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 32); + //usSleep((1 + (1 + (int)(10 * (rand() / (RAND_MAX + 1.0))))) * 1000); + usSleep(10); + continue; + } + else + { + //printf("\n[db get record counts check ff lpr]:%d\n", 33); + if (l_ret == SQLITE_OK) + { + l_ret = db_step_sql(sqlite_stmt); + + if (l_ret == 0) + { + //nRows = sqlite3_column_int(sqlite_stmt, 0); + snprintf(c_column_value, 50-1, db_get_column_value_str(sqlite_stmt, 0)); +#ifdef FACE_AMBA_DEBUG + printf("\n------------c_column_value ff_user_name: %s\n", c_column_value); +#endif + } + } + //printf("\n[db get record counts check ff lpr]:%d\n", 34); + break; + } + //printf("\n[db get record counts check ff lpr]:%d\n", 4); + } while (1); + + if (sqlite_stmt) sqlite3_finalize(sqlite_stmt); + //intf("\n[db get record counts check ff lpr]:%d\n", 5); + //return c_column_value; +} + +// Function to execute SQL UPDATE query to increment ff_face_count by 1 +int db_increment_ff_face_count(sqlite3 *pdb, const char *table_name, const char *ff_face_name) { + char *errMessage = 0; + + // Build the SQL query to update ff_face_count + char sql[256]; + snprintf(sql, sizeof(sql), + "UPDATE %s " + "SET ff_face_count = ff_face_count + 1 " + "WHERE ff_face_name = '%s';", table_name, ff_face_name); + + // Execute SQL query + int rc = sqlite3_exec(pdb, sql, 0, 0, &errMessage); + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", errMessage); + sqlite3_free(errMessage); + return -1; // Return an error code + } + + return 1; // Return 0 on success +} +#endif \ No newline at end of file diff --git a/src/sqlite_db.h b/src/sqlite_db.h new file mode 100644 index 0000000..acf1bf5 --- /dev/null +++ b/src/sqlite_db.h @@ -0,0 +1,81 @@ +#pragma once +#ifndef _SQLITE_DB_H_ +#define _SQLITE_DB_H_ +#include "define_inc.h" +#include <sqlite3.h> +#include "utility.h" + + +#define CMD_SELECT_MAX "SELECT MAX(CAST(ff_face_name AS INTEGER)) "\ + "FROM ( "\ + "SELECT ff_face_name FROM face_db_white_tb WHERE ff_face_name NOT LIKE '%%[^0-9]%%'"\ + "UNION SELECT ff_face_name FROM face_db_black_tb WHERE ff_face_name NOT LIKE '%%[^0-9]%%') ;" + +#define MAX_DETECT_ENDTIME 50 +#define MAX_TIME 10 + +typedef struct database_info_t +{ +// char db_path[256]; + char db_name[256]; + char db_alias[256]; + char db_version[256]; + sqlite3 *pdb; + sqlite3_stmt *pstmt; + //int dbFlags; + //pthread_mutex_t dbMutex; + //char **dbTable; +} database_info_t; + +void db_lock(sqlite3 *pDb); +void db_unlock(sqlite3 *pDb); + +extern int check_if_db_is_malformed; +extern int unlockingKeyInnoFR_success; + +int db_exec_sql(sqlite3 *pDb, char *sql); +int db_prepare_sql(sqlite3 *pdb, sqlite3_stmt **pstmt, char *sql); +int db_step_sql(sqlite3_stmt *pstmt); +int db_free_sql_stmt(sqlite3_stmt *pstmt); + +int db_check_table_exist(sqlite3 *pdb, char *table_name); +int db_get_column_value_int(sqlite3_stmt *pstmt, int index); +int db_get_column_counts(sqlite3_stmt *pstmt); +int db_get_record_counts(sqlite3 *pdb, char *sql); +int db_move_next_record(sqlite3_stmt *pstmt); + +long long db_get_column_value_int64(sqlite3_stmt *pstmt, int index); + +const char *db_get_column_value_str(sqlite3_stmt *pstmt, int index); +const char *db_get_cloumn_name(sqlite3_stmt *pstmt, int index); + + +int db_back_up(sqlite3 *pInMemory, const char *zFilename, int isSavePath); + +int db_get_record_counts_check_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance); +int db_get_record_counts_check_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, int levenshtein_distance); +int db_get_record_counts_check_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance); + +void db_get_record_plate_check_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance, char *replaced_plate); +void db_get_record_plate_check_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, int levenshtein_distance, char *replaced_plate); +void db_get_record_plate_check_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, int levenshtein_distance, char *replaced_plate); + +void db_get_schedule_start_where_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +void db_get_schedule_start_where_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +void db_get_schedule_start_where_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); + +void db_get_schedule_end_where_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +void db_get_schedule_end_where_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +void db_get_schedule_end_where_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); + +void db_get_detect_endtime_where_ff_lpr(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +void db_get_detect_endtime_where_in_other_and_ff_lpr(sqlite3 *pdb, char *table_name, char *in_other_to_check, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +void db_get_detect_endtime_where_ff_lpr_upper(sqlite3 *pdb, char *table_name, char *ff_lpr_to_check, char* c_column_value, int levenshtein_distance); +#ifdef GY_OS_AMBA +void db_search_ff_user_name(sqlite3 *pdb, char *table_name, const char *ff_lpr_to_check, char* c_column_value); +int db_increment_ff_face_count(sqlite3 *pdb, const char *table_name, const char *ff_face_name); +int db_search_max_ff_face_name(sqlite3 *pdb, const char *table_name); +#endif + +#endif + diff --git a/src/stb_image.h b/src/stb_image.h new file mode 100644 index 0000000..361ddeb --- /dev/null +++ b/src/stb_image.h @@ -0,0 +1,7462 @@ +/* stb_image - v2.19 - public domain image loader - http://nothings.org/stb + no warranty implied; use at your own risk + + Do this: + #define STB_IMAGE_IMPLEMENTATION + before you include this file in *one* C or C++ file to create the implementation. + + // i.e. it should look like this: + #include ... + #include ... + #include ... + #define STB_IMAGE_IMPLEMENTATION + #include "stb_image.h" + + You can #define STBI_ASSERT(x) before the #include to avoid using assert.h. + And #define STBI_MALLOC, STBI_REALLOC, and STBI_FREE to avoid using malloc,realloc,free + + + QUICK NOTES: + Primarily of interest to game developers and other people who can + avoid problematic images and only need the trivial interface + + JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib) + PNG 1/2/4/8/16-bit-per-channel + + TGA (not sure what subset, if a subset) + BMP non-1bpp, non-RLE + PSD (composited view only, no extra channels, 8/16 bit-per-channel) + + GIF (*comp always reports as 4-channel) + HDR (radiance rgbE format) + PIC (Softimage PIC) + PNM (PPM and PGM binary only) + + Animated GIF still needs a proper API, but here's one way to do it: + http://gist.github.com/urraka/685d9a6340b26b830d49 + + - decode from memory or through FILE (define STBI_NO_STDIO to remove code) + - decode from arbitrary I/O callbacks + - SIMD acceleration on x86/x64 (SSE2) and ARM (NEON) + + Full documentation under "DOCUMENTATION" below. + + +LICENSE + + See end of file for license information. + +RECENT REVISION HISTORY: + + 2.19 (2018-02-11) fix warning + 2.18 (2018-01-30) fix warnings + 2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings + 2.16 (2017-07-23) all functions have 16-bit variants; optimizations; bugfixes + 2.15 (2017-03-18) fix png-1,2,4; all Imagenet JPGs; no runtime SSE detection on GCC + 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs + 2.13 (2016-12-04) experimental 16-bit API, only for PNG so far; fixes + 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes + 2.11 (2016-04-02) 16-bit PNGS; enable SSE2 in non-gcc x64 + RGB-format JPEG; remove white matting in PSD; + allocate large structures on the stack; + correct channel count for PNG & BMP + 2.10 (2016-01-22) avoid warning introduced in 2.09 + 2.09 (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED + + See end of file for full revision history. + + + ============================ Contributors ========================= + + Image formats Extensions, features + Sean Barrett (jpeg, png, bmp) Jetro Lauha (stbi_info) + Nicolas Schulz (hdr, psd) Martin "SpartanJ" Golini (stbi_info) + Jonathan Dummer (tga) James "moose2000" Brown (iPhone PNG) + Jean-Marc Lienher (gif) Ben "Disch" Wenger (io callbacks) + Tom Seddon (pic) Omar Cornut (1/2/4-bit PNG) + Thatcher Ulrich (psd) Nicolas Guillemot (vertical flip) + Ken Miller (pgm, ppm) Richard Mitton (16-bit PSD) + github:urraka (animated gif) Junggon Kim (PNM comments) + Christopher Forseth (animated gif) Daniel Gibson (16-bit TGA) + socks-the-fox (16-bit PNG) + Jeremy Sawicki (handle all ImageNet JPGs) + Optimizations & bugfixes Mikhail Morozov (1-bit BMP) + Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query) + Arseny Kapoulkine + John-Mark Allen + + Bug & warning fixes + Marc LeBlanc David Woo Guillaume George Martins Mozeiko + Christpher Lloyd Jerry Jansson Joseph Thomson Phil Jordan + Dave Moore Roy Eltham Hayaki Saito Nathan Reed + Won Chun Luke Graham Johan Duparc Nick Verigakis + the Horde3D community Thomas Ruf Ronny Chevalier github:rlyeh + Janez Zemva John Bartholomew Michal Cichon github:romigrou + Jonathan Blow Ken Hamada Tero Hanninen github:svdijk + Laurent Gomila Cort Stratton Sergio Gonzalez github:snagar + Aruelien Pocheville Thibault Reuille Cass Everitt github:Zelex + Ryamond Barbiero Paul Du Bois Engin Manap github:grim210 + Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw + Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus + Julian Raschke Gregory Mullen Baldur Karlsson github:poppolopoppo + Christian Floisand Kevin Schmidt github:darealshinji + Blazej Dariusz Roszkowski github:Michaelangel007 +*/ +#pragma once +#ifndef STBI_INCLUDE_STB_IMAGE_H +#define STBI_INCLUDE_STB_IMAGE_H +#include "define_inc.h" +// DOCUMENTATION +// +// Limitations: +// - no 12-bit-per-channel JPEG +// - no JPEGs with arithmetic coding +// - GIF always returns *comp=4 +// +// Basic usage (see HDR discussion below for HDR usage): +// int x,y,n; +// unsigned char *data = stbi_load(filename, &x, &y, &n, 0); +// // ... process data if not NULL ... +// // ... x = width, y = height, n = # 8-bit components per pixel ... +// // ... replace '0' with '1'..'4' to force that many components per pixel +// // ... but 'n' will always be the number that it would have been if you said 0 +// stbi_image_free(data) +// +// Standard parameters: +// int *x -- outputs image width in pixels +// int *y -- outputs image height in pixels +// int *channels_in_file -- outputs # of image components in image file +// int desired_channels -- if non-zero, # of image components requested in result +// +// The return value from an image loader is an 'unsigned char *' which points +// to the pixel data, or NULL on an allocation failure or if the image is +// corrupt or invalid. The pixel data consists of *y scanlines of *x pixels, +// with each pixel consisting of N interleaved 8-bit components; the first +// pixel pointed to is top-left-most in the image. There is no padding between +// image scanlines or between pixels, regardless of format. The number of +// components N is 'desired_channels' if desired_channels is non-zero, or +// *channels_in_file otherwise. If desired_channels is non-zero, +// *channels_in_file has the number of components that _would_ have been +// output otherwise. E.g. if you set desired_channels to 4, you will always +// get RGBA output, but you can check *channels_in_file to see if it's trivially +// opaque because e.g. there were only 3 channels in the source image. +// +// An output image with N components has the following components interleaved +// in this order in each pixel: +// +// N=#comp components +// 1 grey +// 2 grey, alpha +// 3 red, green, blue +// 4 red, green, blue, alpha +// +// If image loading fails for any reason, the return value will be NULL, +// and *x, *y, *channels_in_file will be unchanged. The function +// stbi_failure_reason() can be queried for an extremely brief, end-user +// unfriendly explanation of why the load failed. Define STBI_NO_FAILURE_STRINGS +// to avoid compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly +// more user-friendly ones. +// +// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized. +// +// =========================================================================== +// +// Philosophy +// +// stb libraries are designed with the following priorities: +// +// 1. easy to use +// 2. easy to maintain +// 3. good performance +// +// Sometimes I let "good performance" creep up in priority over "easy to maintain", +// and for best performance I may provide less-easy-to-use APIs that give higher +// performance, in addition to the easy to use ones. Nevertheless, it's important +// to keep in mind that from the standpoint of you, a client of this library, +// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all. +// +// Some secondary priorities arise directly from the first two, some of which +// make more explicit reasons why performance can't be emphasized. +// +// - Portable ("ease of use") +// - Small source code footprint ("easy to maintain") +// - No dependencies ("ease of use") +// +// =========================================================================== +// +// I/O callbacks +// +// I/O callbacks allow you to read from arbitrary sources, like packaged +// files or some other source. Data read from callbacks are processed +// through a small internal buffer (currently 128 bytes) to try to reduce +// overhead. +// +// The three functions you must define are "read" (reads some bytes of data), +// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end). +// +// =========================================================================== +// +// SIMD support +// +// The JPEG decoder will try to automatically use SIMD kernels on x86 when +// supported by the compiler. For ARM Neon support, you must explicitly +// request it. +// +// (The old do-it-yourself SIMD API is no longer supported in the current +// code.) +// +// On x86, SSE2 will automatically be used when available based on a run-time +// test; if not, the generic C versions are used as a fall-back. On ARM targets, +// the typical path is to have separate builds for NEON and non-NEON devices +// (at least this is true for iOS and Android). Therefore, the NEON support is +// toggled by a build flag: define STBI_NEON to get NEON loops. +// +// If for some reason you do not want to use any of SIMD code, or if +// you have issues compiling it, you can disable it entirely by +// defining STBI_NO_SIMD. +// +// =========================================================================== +// +// HDR image support (disable by defining STBI_NO_HDR) +// +// stb_image now supports loading HDR images in general, and currently +// the Radiance .HDR file format, although the support is provided +// generically. You can still load any file through the existing interface; +// if you attempt to load an HDR file, it will be automatically remapped to +// LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1; +// both of these constants can be reconfigured through this interface: +// +// stbi_hdr_to_ldr_gamma(2.2f); +// stbi_hdr_to_ldr_scale(1.0f); +// +// (note, do not use _inverse_ constants; stbi_image will invert them +// appropriately). +// +// Additionally, there is a new, parallel interface for loading files as +// (linear) floats to preserve the full dynamic range: +// +// float *data = stbi_loadf(filename, &x, &y, &n, 0); +// +// If you load LDR images through this interface, those images will +// be promoted to floating point values, run through the inverse of +// constants corresponding to the above: +// +// stbi_ldr_to_hdr_scale(1.0f); +// stbi_ldr_to_hdr_gamma(2.2f); +// +// Finally, given a filename (or an open file or memory block--see header +// file for details) containing image data, you can query for the "most +// appropriate" interface to use (that is, whether the image is HDR or +// not), using: +// +// stbi_is_hdr(char *filename); +// +// =========================================================================== +// +// iPhone PNG support: +// +// By default we convert iphone-formatted PNGs back to RGB, even though +// they are internally encoded differently. You can disable this conversion +// by by calling stbi_convert_iphone_png_to_rgb(0), in which case +// you will always just get the native iphone "format" through (which +// is BGR stored in RGB). +// +// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per +// pixel to remove any premultiplied alpha *only* if the image file explicitly +// says there's premultiplied data (currently only happens in iPhone images, +// and only if iPhone convert-to-rgb processing is on). +// +// =========================================================================== +// +// ADDITIONAL CONFIGURATION +// +// - You can suppress implementation of any of the decoders to reduce +// your code footprint by #defining one or more of the following +// symbols before creating the implementation. +// +// STBI_NO_JPEG +// STBI_NO_PNG +// STBI_NO_BMP +// STBI_NO_PSD +// STBI_NO_TGA +// STBI_NO_GIF +// STBI_NO_HDR +// STBI_NO_PIC +// STBI_NO_PNM (.ppm and .pgm) +// +// - You can request *only* certain decoders and suppress all other ones +// (this will be more forward-compatible, as addition of new decoders +// doesn't require you to disable them explicitly): +// +// STBI_ONLY_JPEG +// STBI_ONLY_PNG +// STBI_ONLY_BMP +// STBI_ONLY_PSD +// STBI_ONLY_TGA +// STBI_ONLY_GIF +// STBI_ONLY_HDR +// STBI_ONLY_PIC +// STBI_ONLY_PNM (.ppm and .pgm) +// +// - If you use STBI_NO_PNG (or _ONLY_ without PNG), and you still +// want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB +// + + +#ifndef STBI_NO_STDIO +#include <stdio.h> +#endif // STBI_NO_STDIO + +#define STBI_VERSION 1 + +enum +{ + STBI_default = 0, // only used for desired_channels + + STBI_grey = 1, + STBI_grey_alpha = 2, + STBI_rgb = 3, + STBI_rgb_alpha = 4 +}; + +typedef unsigned char stbi_uc; +typedef unsigned short stbi_us; + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef STB_IMAGE_STATIC +#define STBIDEF static +#else +#define STBIDEF extern +#endif + +////////////////////////////////////////////////////////////////////////////// +// +// PRIMARY API - works on images of any type +// + +// +// load image by filename, open file, or memory buffer +// + +typedef struct +{ + int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read + void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative + int (*eof) (void *user); // returns nonzero if we are at end of file/data +} stbi_io_callbacks; + +//////////////////////////////////// +// +// 8-bits-per-channel interface +// + +STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels); +STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels); +#ifndef STBI_NO_GIF +STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp); +#endif + + +#ifndef STBI_NO_STDIO +STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); +STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); +// for stbi_load_from_file, file pointer is left pointing immediately after image +#endif + +//////////////////////////////////// +// +// 16-bits-per-channel interface +// + +STBIDEF stbi_us *stbi_load_16_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); +STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels); + +#ifndef STBI_NO_STDIO +STBIDEF stbi_us *stbi_load_16 (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); +STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); +#endif + +//////////////////////////////////// +// +// float-per-channel interface +// +#ifndef STBI_NO_LINEAR + STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels); + + #ifndef STBI_NO_STDIO + STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels); + STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *channels_in_file, int desired_channels); + #endif +#endif + +#ifndef STBI_NO_HDR + STBIDEF void stbi_hdr_to_ldr_gamma(float gamma); + STBIDEF void stbi_hdr_to_ldr_scale(float scale); +#endif // STBI_NO_HDR + +#ifndef STBI_NO_LINEAR + STBIDEF void stbi_ldr_to_hdr_gamma(float gamma); + STBIDEF void stbi_ldr_to_hdr_scale(float scale); +#endif // STBI_NO_LINEAR + +// stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR +STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user); +STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len); +#ifndef STBI_NO_STDIO +STBIDEF int stbi_is_hdr (char const *filename); +STBIDEF int stbi_is_hdr_from_file(FILE *f); +#endif // STBI_NO_STDIO + + +// get a VERY brief reason for failure +// NOT THREADSAFE +STBIDEF const char *stbi_failure_reason (void); + +// free the loaded image -- this is just free() +STBIDEF void stbi_image_free (void *retval_from_stbi_load); + +// get image dimensions & components without fully decoding +STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); +STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp); +STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len); +STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user); + +#ifndef STBI_NO_STDIO +STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp); +STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp); +STBIDEF int stbi_is_16_bit (char const *filename); +STBIDEF int stbi_is_16_bit_from_file(FILE *f); +#endif + + + +// for image formats that explicitly notate that they have premultiplied alpha, +// we just return the colors as stored in the file. set this flag to force +// unpremultiplication. results are undefined if the unpremultiply overflow. +STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); + +// indicate whether we should process iphone images back to canonical format, +// or just pass them through "as-is" +STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert); + +// flip the image vertically, so the first pixel in the output array is the bottom left +STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip); + +// ZLIB client - used by PNG, available for other purposes + +STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen); +STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header); +STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen); +STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); + +STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen); +STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); + + +#ifdef __cplusplus +} +#endif + +// +// +//// end header file ///////////////////////////////////////////////////// +#endif // STBI_INCLUDE_STB_IMAGE_H + +#ifdef STB_IMAGE_IMPLEMENTATION + +#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) \ + || defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) \ + || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) \ + || defined(STBI_ONLY_ZLIB) + #ifndef STBI_ONLY_JPEG + #define STBI_NO_JPEG + #endif + #ifndef STBI_ONLY_PNG + #define STBI_NO_PNG + #endif + #ifndef STBI_ONLY_BMP + #define STBI_NO_BMP + #endif + #ifndef STBI_ONLY_PSD + #define STBI_NO_PSD + #endif + #ifndef STBI_ONLY_TGA + #define STBI_NO_TGA + #endif + #ifndef STBI_ONLY_GIF + #define STBI_NO_GIF + #endif + #ifndef STBI_ONLY_HDR + #define STBI_NO_HDR + #endif + #ifndef STBI_ONLY_PIC + #define STBI_NO_PIC + #endif + #ifndef STBI_ONLY_PNM + #define STBI_NO_PNM + #endif +#endif + +#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB) +#define STBI_NO_ZLIB +#endif + + +#include <stdarg.h> +#include <stddef.h> // ptrdiff_t on osx +#include <stdlib.h> +#include <string.h> +#include <limits.h> + +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) +#include <math.h> // ldexp, pow +#endif + +#ifndef STBI_NO_STDIO +#include <stdio.h> +#endif + +#ifndef STBI_ASSERT +#include <assert.h> +#define STBI_ASSERT(x) assert(x) +#endif + + +#ifndef _MSC_VER + #ifdef __cplusplus + #define stbi_inline inline + #else + #define stbi_inline + #endif +#else + #define stbi_inline __forceinline +#endif + + +#ifdef _MSC_VER +typedef unsigned short stbi__uint16; +typedef signed short stbi__int16; +typedef unsigned int stbi__uint32; +typedef signed int stbi__int32; +#else +#include <stdint.h> +typedef uint16_t stbi__uint16; +typedef int16_t stbi__int16; +typedef uint32_t stbi__uint32; +typedef int32_t stbi__int32; +#endif + +// should produce compiler error if size is wrong +typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; + +#ifdef _MSC_VER +#define STBI_NOTUSED(v) (void)(v) +#else +#define STBI_NOTUSED(v) (void)sizeof(v) +#endif + +#ifdef _MSC_VER +#define STBI_HAS_LROTL +#endif + +#ifdef STBI_HAS_LROTL + #define stbi_lrot(x,y) _lrotl(x,y) +#else + #define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) +#endif + +#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED)) +// ok +#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) && !defined(STBI_REALLOC_SIZED) +// ok +#else +#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC (or STBI_REALLOC_SIZED)." +#endif + +#ifndef STBI_MALLOC +#define STBI_MALLOC(sz) malloc(sz) +#define STBI_REALLOC(p,newsz) realloc(p,newsz) +#define STBI_FREE(p) free(p) +#endif + +#ifndef STBI_REALLOC_SIZED +#define STBI_REALLOC_SIZED(p,oldsz,newsz) STBI_REALLOC(p,newsz) +#endif + +// x86/x64 detection +#if defined(__x86_64__) || defined(_M_X64) +#define STBI__X64_TARGET +#elif defined(__i386) || defined(_M_IX86) +#define STBI__X86_TARGET +#endif + +#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) +// gcc doesn't support sse2 intrinsics unless you compile with -msse2, +// which in turn means it gets to use SSE2 everywhere. This is unfortunate, +// but previous attempts to provide the SSE2 functions with runtime +// detection caused numerous issues. The way architecture extensions are +// exposed in GCC/Clang is, sadly, not really suited for one-file libs. +// New behavior: if compiled with -msse2, we use SSE2 without any +// detection; if not, we don't use it at all. +#define STBI_NO_SIMD +#endif + +#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD) +// Note that __MINGW32__ doesn't actually mean 32-bit, so we have to avoid STBI__X64_TARGET +// +// 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the +// Windows ABI and VC++ as well as Windows DLLs don't maintain that invariant. +// As a result, enabling SSE2 on 32-bit MinGW is dangerous when not +// simultaneously enabling "-mstackrealign". +// +// See https://github.com/nothings/stb/issues/81 for more information. +// +// So default to no SSE2 on 32-bit MinGW. If you've read this far and added +// -mstackrealign to your build settings, feel free to #define STBI_MINGW_ENABLE_SSE2. +#define STBI_NO_SIMD +#endif + +#if !defined(STBI_NO_SIMD) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) +#define STBI_SSE2 +#include <emmintrin.h> + +#ifdef _MSC_VER + +#if _MSC_VER >= 1400 // not VC6 +#include <intrin.h> // __cpuid +static int stbi__cpuid3(void) +{ + int info[4]; + __cpuid(info,1); + return info[3]; +} +#else +static int stbi__cpuid3(void) +{ + int res; + __asm { + mov eax,1 + cpuid + mov res,edx + } + return res; +} +#endif + +#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name + +static int stbi__sse2_available(void) +{ + int info3 = stbi__cpuid3(); + return ((info3 >> 26) & 1) != 0; +} +#else // assume GCC-style if not VC++ +#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) + +static int stbi__sse2_available(void) +{ + // If we're even attempting to compile this on GCC/Clang, that means + // -msse2 is on, which means the compiler is allowed to use SSE2 + // instructions at will, and so are we. + return 1; +} +#endif +#endif + +// ARM NEON +#if defined(STBI_NO_SIMD) && defined(STBI_NEON) +#undef STBI_NEON +#endif + +#ifdef STBI_NEON +#include <arm_neon.h> +// assume GCC or Clang on ARM targets +#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16))) +#endif + +#ifndef STBI_SIMD_ALIGN +#define STBI_SIMD_ALIGN(type, name) type name +#endif + +/////////////////////////////////////////////// +// +// stbi__context struct and start_xxx functions + +// stbi__context structure is our basic context used by all images, so it +// contains all the IO context, plus some basic image information +typedef struct +{ + stbi__uint32 img_x, img_y; + int img_n, img_out_n; + + stbi_io_callbacks io; + void *io_user_data; + + int read_from_callbacks; + int buflen; + stbi_uc buffer_start[128]; + + stbi_uc *img_buffer, *img_buffer_end; + stbi_uc *img_buffer_original, *img_buffer_original_end; +} stbi__context; + + +static void stbi__refill_buffer(stbi__context *s); + +// initialize a memory-decode context +static void stbi__start_mem(stbi__context *s, stbi_uc const *buffer, int len) +{ + s->io.read = NULL; + s->read_from_callbacks = 0; + s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer; + s->img_buffer_end = s->img_buffer_original_end = (stbi_uc *) buffer+len; +} + +// initialize a callback-based context +static void stbi__start_callbacks(stbi__context *s, stbi_io_callbacks *c, void *user) +{ + s->io = *c; + s->io_user_data = user; + s->buflen = sizeof(s->buffer_start); + s->read_from_callbacks = 1; + s->img_buffer_original = s->buffer_start; + stbi__refill_buffer(s); + s->img_buffer_original_end = s->img_buffer_end; +} + +#ifndef STBI_NO_STDIO + +static int stbi__stdio_read(void *user, char *data, int size) +{ + return (int) fread(data,1,size,(FILE*) user); +} + +static void stbi__stdio_skip(void *user, int n) +{ + fseek((FILE*) user, n, SEEK_CUR); +} + +static int stbi__stdio_eof(void *user) +{ + return feof((FILE*) user); +} + +static stbi_io_callbacks stbi__stdio_callbacks = +{ + stbi__stdio_read, + stbi__stdio_skip, + stbi__stdio_eof, +}; + +static void stbi__start_file(stbi__context *s, FILE *f) +{ + stbi__start_callbacks(s, &stbi__stdio_callbacks, (void *) f); +} + +//static void stop_file(stbi__context *s) { } + +#endif // !STBI_NO_STDIO + +static void stbi__rewind(stbi__context *s) +{ + // conceptually rewind SHOULD rewind to the beginning of the stream, + // but we just rewind to the beginning of the initial buffer, because + // we only use it after doing 'test', which only ever looks at at most 92 bytes + s->img_buffer = s->img_buffer_original; + s->img_buffer_end = s->img_buffer_original_end; +} + +enum +{ + STBI_ORDER_RGB, + STBI_ORDER_BGR +}; + +typedef struct +{ + int bits_per_channel; + int num_channels; + int channel_order; +} stbi__result_info; + +#ifndef STBI_NO_JPEG +static int stbi__jpeg_test(stbi__context *s); +static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PNG +static int stbi__png_test(stbi__context *s); +static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp); +static int stbi__png_is16(stbi__context *s); +#endif + +#ifndef STBI_NO_BMP +static int stbi__bmp_test(stbi__context *s); +static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_TGA +static int stbi__tga_test(stbi__context *s); +static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PSD +static int stbi__psd_test(stbi__context *s); +static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc); +static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp); +static int stbi__psd_is16(stbi__context *s); +#endif + +#ifndef STBI_NO_HDR +static int stbi__hdr_test(stbi__context *s); +static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PIC +static int stbi__pic_test(stbi__context *s); +static void *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_GIF +static int stbi__gif_test(stbi__context *s); +static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp); +static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +#ifndef STBI_NO_PNM +static int stbi__pnm_test(stbi__context *s); +static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri); +static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp); +#endif + +// this is not threadsafe +static const char *stbi__g_failure_reason; + +STBIDEF const char *stbi_failure_reason(void) +{ + return stbi__g_failure_reason; +} + +static int stbi__err(const char *str) +{ + stbi__g_failure_reason = str; + return 0; +} + +static void *stbi__malloc(size_t size) +{ + return STBI_MALLOC(size); +} + +// stb_image uses ints pervasively, including for offset calculations. +// therefore the largest decoded image size we can support with the +// current code, even on 64-bit targets, is INT_MAX. this is not a +// significant limitation for the intended use case. +// +// we do, however, need to make sure our size calculations don't +// overflow. hence a few helper functions for size calculations that +// multiply integers together, making sure that they're non-negative +// and no overflow occurs. + +// return 1 if the sum is valid, 0 on overflow. +// negative terms are considered invalid. +static int stbi__addsizes_valid(int a, int b) +{ + if (b < 0) return 0; + // now 0 <= b <= INT_MAX, hence also + // 0 <= INT_MAX - b <= INTMAX. + // And "a + b <= INT_MAX" (which might overflow) is the + // same as a <= INT_MAX - b (no overflow) + return a <= INT_MAX - b; +} + +// returns 1 if the product is valid, 0 on overflow. +// negative factors are considered invalid. +static int stbi__mul2sizes_valid(int a, int b) +{ + if (a < 0 || b < 0) return 0; + if (b == 0) return 1; // mul-by-0 is always safe + // portable way to check for no overflows in a*b + return a <= INT_MAX/b; +} + +// returns 1 if "a*b + add" has no negative terms/factors and doesn't overflow +static int stbi__mad2sizes_valid(int a, int b, int add) +{ + return stbi__mul2sizes_valid(a, b) && stbi__addsizes_valid(a*b, add); +} + +// returns 1 if "a*b*c + add" has no negative terms/factors and doesn't overflow +static int stbi__mad3sizes_valid(int a, int b, int c, int add) +{ + return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && + stbi__addsizes_valid(a*b*c, add); +} + +// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) +static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add) +{ + return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && + stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add); +} +#endif + +// mallocs with size overflow checking +static void *stbi__malloc_mad2(int a, int b, int add) +{ + if (!stbi__mad2sizes_valid(a, b, add)) return NULL; + return stbi__malloc(a*b + add); +} + +static void *stbi__malloc_mad3(int a, int b, int c, int add) +{ + if (!stbi__mad3sizes_valid(a, b, c, add)) return NULL; + return stbi__malloc(a*b*c + add); +} + +#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) +static void *stbi__malloc_mad4(int a, int b, int c, int d, int add) +{ + if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL; + return stbi__malloc(a*b*c*d + add); +} +#endif + +// stbi__err - error +// stbi__errpf - error returning pointer to float +// stbi__errpuc - error returning pointer to unsigned char + +#ifdef STBI_NO_FAILURE_STRINGS + #define stbi__err(x,y) 0 +#elif defined(STBI_FAILURE_USERMSG) + #define stbi__err(x,y) stbi__err(y) +#else + #define stbi__err(x,y) stbi__err(x) +#endif + +#define stbi__errpf(x,y) ((float *)(size_t) (stbi__err(x,y)?NULL:NULL)) +#define stbi__errpuc(x,y) ((unsigned char *)(size_t) (stbi__err(x,y)?NULL:NULL)) + +STBIDEF void stbi_image_free(void *retval_from_stbi_load) +{ + STBI_FREE(retval_from_stbi_load); +} + +#ifndef STBI_NO_LINEAR +static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp); +#endif + +#ifndef STBI_NO_HDR +static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp); +#endif + +static int stbi__vertically_flip_on_load = 0; + +STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip) +{ + stbi__vertically_flip_on_load = flag_true_if_should_flip; +} + +static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) +{ + memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields + ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed + ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order + ri->num_channels = 0; + + #ifndef STBI_NO_JPEG + if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri); + #endif + #ifndef STBI_NO_PNG + if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp, ri); + #endif + #ifndef STBI_NO_BMP + if (stbi__bmp_test(s)) return stbi__bmp_load(s,x,y,comp,req_comp, ri); + #endif + #ifndef STBI_NO_GIF + if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp, ri); + #endif + #ifndef STBI_NO_PSD + if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp, ri, bpc); + #endif + #ifndef STBI_NO_PIC + if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp, ri); + #endif + #ifndef STBI_NO_PNM + if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp, ri); + #endif + + #ifndef STBI_NO_HDR + if (stbi__hdr_test(s)) { + float *hdr = stbi__hdr_load(s, x,y,comp,req_comp, ri); + return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp); + } + #endif + + #ifndef STBI_NO_TGA + // test tga last because it's a crappy test! + if (stbi__tga_test(s)) + return stbi__tga_load(s,x,y,comp,req_comp, ri); + #endif + + return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt"); +} + +static stbi_uc *stbi__convert_16_to_8(stbi__uint16 *orig, int w, int h, int channels) +{ + int i; + int img_len = w * h * channels; + stbi_uc *reduced; + + reduced = (stbi_uc *) stbi__malloc(img_len); + if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory"); + + for (i = 0; i < img_len; ++i) + reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling + + STBI_FREE(orig); + return reduced; +} + +static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int channels) +{ + int i; + int img_len = w * h * channels; + stbi__uint16 *enlarged; + + enlarged = (stbi__uint16 *) stbi__malloc(img_len*2); + if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); + + for (i = 0; i < img_len; ++i) + enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff + + STBI_FREE(orig); + return enlarged; +} + +static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel) +{ + int row; + size_t bytes_per_row = (size_t)w * bytes_per_pixel; + stbi_uc temp[2048]; + stbi_uc *bytes = (stbi_uc *)image; + + for (row = 0; row < (h>>1); row++) { + stbi_uc *row0 = bytes + row*bytes_per_row; + stbi_uc *row1 = bytes + (h - row - 1)*bytes_per_row; + // swap row0 with row1 + size_t bytes_left = bytes_per_row; + while (bytes_left) { + size_t bytes_copy = (bytes_left < sizeof(temp)) ? bytes_left : sizeof(temp); + memcpy(temp, row0, bytes_copy); + memcpy(row0, row1, bytes_copy); + memcpy(row1, temp, bytes_copy); + row0 += bytes_copy; + row1 += bytes_copy; + bytes_left -= bytes_copy; + } + } +} + +static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel) +{ + int slice; + int slice_size = w * h * bytes_per_pixel; + + stbi_uc *bytes = (stbi_uc *)image; + for (slice = 0; slice < z; ++slice) { + stbi__vertical_flip(bytes, w, h, bytes_per_pixel); + bytes += slice_size; + } +} + +static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp) +{ + stbi__result_info ri; + void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8); + + if (result == NULL) + return NULL; + + if (ri.bits_per_channel != 8) { + STBI_ASSERT(ri.bits_per_channel == 16); + result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp); + ri.bits_per_channel = 8; + } + + // @TODO: move stbi__convert_format to here + + if (stbi__vertically_flip_on_load) { + int channels = req_comp ? req_comp : *comp; + stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi_uc)); + } + + return (unsigned char *) result; +} + +static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x, int *y, int *comp, int req_comp) +{ + stbi__result_info ri; + void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16); + + if (result == NULL) + return NULL; + + if (ri.bits_per_channel != 16) { + STBI_ASSERT(ri.bits_per_channel == 8); + result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp); + ri.bits_per_channel = 16; + } + + // @TODO: move stbi__convert_format16 to here + // @TODO: special case RGB-to-Y (and RGBA-to-YA) for 8-bit-to-16-bit case to keep more precision + + if (stbi__vertically_flip_on_load) { + int channels = req_comp ? req_comp : *comp; + stbi__vertical_flip(result, *x, *y, channels * sizeof(stbi__uint16)); + } + + return (stbi__uint16 *) result; +} + +#if !defined(STBI_NO_HDR) || !defined(STBI_NO_LINEAR) +static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp) +{ + if (stbi__vertically_flip_on_load && result != NULL) { + int channels = req_comp ? req_comp : *comp; + stbi__vertical_flip(result, *x, *y, channels * sizeof(float)); + } +} +#endif + +#ifndef STBI_NO_STDIO + +static FILE *stbi__fopen(char const *filename, char const *mode) +{ + FILE *f; +#if defined(_MSC_VER) && _MSC_VER >= 1400 + if (0 != fopen_s(&f, filename, mode)) + f=0; +#else + f = fopen(filename, mode); +#endif + return f; +} + + +STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp) +{ + FILE *f = stbi__fopen(filename, "rb"); + unsigned char *result; + if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); + result = stbi_load_from_file(f,x,y,comp,req_comp); + fclose(f); + return result; +} + +STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) +{ + unsigned char *result; + stbi__context s; + stbi__start_file(&s,f); + result = stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); + if (result) { + // need to 'unget' all the characters in the IO buffer + fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR); + } + return result; +} + +STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, int req_comp) +{ + stbi__uint16 *result; + stbi__context s; + stbi__start_file(&s,f); + result = stbi__load_and_postprocess_16bit(&s,x,y,comp,req_comp); + if (result) { + // need to 'unget' all the characters in the IO buffer + fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR); + } + return result; +} + +STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, int req_comp) +{ + FILE *f = stbi__fopen(filename, "rb"); + stbi__uint16 *result; + if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file"); + result = stbi_load_from_file_16(f,x,y,comp,req_comp); + fclose(f); + return result; +} + + +#endif //!STBI_NO_STDIO + +STBIDEF stbi_us *stbi_load_16_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels); +} + +STBIDEF stbi_us *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *channels_in_file, int desired_channels) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *)clbk, user); + return stbi__load_and_postprocess_16bit(&s,x,y,channels_in_file,desired_channels); +} + +STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); +} + +STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); + return stbi__load_and_postprocess_8bit(&s,x,y,comp,req_comp); +} + +#ifndef STBI_NO_GIF +STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp) +{ + unsigned char *result; + stbi__context s; + stbi__start_mem(&s,buffer,len); + + result = (unsigned char*) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp); + if (stbi__vertically_flip_on_load) { + stbi__vertical_flip_slices( result, *x, *y, *z, *comp ); + } + + return result; +} +#endif + +#ifndef STBI_NO_LINEAR +static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp) +{ + unsigned char *data; + #ifndef STBI_NO_HDR + if (stbi__hdr_test(s)) { + stbi__result_info ri; + float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp, &ri); + if (hdr_data) + stbi__float_postprocess(hdr_data,x,y,comp,req_comp); + return hdr_data; + } + #endif + data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp); + if (data) + return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp); + return stbi__errpf("unknown image type", "Image not of any known type, or corrupt"); +} + +STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__loadf_main(&s,x,y,comp,req_comp); +} + +STBIDEF float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); + return stbi__loadf_main(&s,x,y,comp,req_comp); +} + +#ifndef STBI_NO_STDIO +STBIDEF float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp) +{ + float *result; + FILE *f = stbi__fopen(filename, "rb"); + if (!f) return stbi__errpf("can't fopen", "Unable to open file"); + result = stbi_loadf_from_file(f,x,y,comp,req_comp); + fclose(f); + return result; +} + +STBIDEF float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) +{ + stbi__context s; + stbi__start_file(&s,f); + return stbi__loadf_main(&s,x,y,comp,req_comp); +} +#endif // !STBI_NO_STDIO + +#endif // !STBI_NO_LINEAR + +// these is-hdr-or-not is defined independent of whether STBI_NO_LINEAR is +// defined, for API simplicity; if STBI_NO_LINEAR is defined, it always +// reports false! + +STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len) +{ + #ifndef STBI_NO_HDR + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__hdr_test(&s); + #else + STBI_NOTUSED(buffer); + STBI_NOTUSED(len); + return 0; + #endif +} + +#ifndef STBI_NO_STDIO +STBIDEF int stbi_is_hdr (char const *filename) +{ + FILE *f = stbi__fopen(filename, "rb"); + int result=0; + if (f) { + result = stbi_is_hdr_from_file(f); + fclose(f); + } + return result; +} + +STBIDEF int stbi_is_hdr_from_file(FILE *f) +{ + #ifndef STBI_NO_HDR + long pos = ftell(f); + int res; + stbi__context s; + stbi__start_file(&s,f); + res = stbi__hdr_test(&s); + fseek(f, pos, SEEK_SET); + return res; + #else + STBI_NOTUSED(f); + return 0; + #endif +} +#endif // !STBI_NO_STDIO + +STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user) +{ + #ifndef STBI_NO_HDR + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); + return stbi__hdr_test(&s); + #else + STBI_NOTUSED(clbk); + STBI_NOTUSED(user); + return 0; + #endif +} + +#ifndef STBI_NO_LINEAR +static float stbi__l2h_gamma=2.2f, stbi__l2h_scale=1.0f; + +STBIDEF void stbi_ldr_to_hdr_gamma(float gamma) { stbi__l2h_gamma = gamma; } +STBIDEF void stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; } +#endif + +static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f; + +STBIDEF void stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1/gamma; } +STBIDEF void stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1/scale; } + + +////////////////////////////////////////////////////////////////////////////// +// +// Common code used by all image loaders +// + +enum +{ + STBI__SCAN_load=0, + STBI__SCAN_type, + STBI__SCAN_header +}; + +static void stbi__refill_buffer(stbi__context *s) +{ + int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen); + if (n == 0) { + // at end of file, treat same as if from memory, but need to handle case + // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file + s->read_from_callbacks = 0; + s->img_buffer = s->buffer_start; + s->img_buffer_end = s->buffer_start+1; + *s->img_buffer = 0; + } else { + s->img_buffer = s->buffer_start; + s->img_buffer_end = s->buffer_start + n; + } +} + +stbi_inline static stbi_uc stbi__get8(stbi__context *s) +{ + if (s->img_buffer < s->img_buffer_end) + return *s->img_buffer++; + if (s->read_from_callbacks) { + stbi__refill_buffer(s); + return *s->img_buffer++; + } + return 0; +} + +stbi_inline static int stbi__at_eof(stbi__context *s) +{ + if (s->io.read) { + if (!(s->io.eof)(s->io_user_data)) return 0; + // if feof() is true, check if buffer = end + // special case: we've only got the special 0 character at the end + if (s->read_from_callbacks == 0) return 1; + } + + return s->img_buffer >= s->img_buffer_end; +} + +static void stbi__skip(stbi__context *s, int n) +{ + if (n < 0) { + s->img_buffer = s->img_buffer_end; + return; + } + if (s->io.read) { + int blen = (int) (s->img_buffer_end - s->img_buffer); + if (blen < n) { + s->img_buffer = s->img_buffer_end; + (s->io.skip)(s->io_user_data, n - blen); + return; + } + } + s->img_buffer += n; +} + +static int stbi__getn(stbi__context *s, stbi_uc *buffer, int n) +{ + if (s->io.read) { + int blen = (int) (s->img_buffer_end - s->img_buffer); + if (blen < n) { + int res, count; + + memcpy(buffer, s->img_buffer, blen); + + count = (s->io.read)(s->io_user_data, (char*) buffer + blen, n - blen); + res = (count == (n-blen)); + s->img_buffer = s->img_buffer_end; + return res; + } + } + + if (s->img_buffer+n <= s->img_buffer_end) { + memcpy(buffer, s->img_buffer, n); + s->img_buffer += n; + return 1; + } else + return 0; +} + +static int stbi__get16be(stbi__context *s) +{ + int z = stbi__get8(s); + return (z << 8) + stbi__get8(s); +} + +static stbi__uint32 stbi__get32be(stbi__context *s) +{ + stbi__uint32 z = stbi__get16be(s); + return (z << 16) + stbi__get16be(s); +} + +#if defined(STBI_NO_BMP) && defined(STBI_NO_TGA) && defined(STBI_NO_GIF) +// nothing +#else +static int stbi__get16le(stbi__context *s) +{ + int z = stbi__get8(s); + return z + (stbi__get8(s) << 8); +} +#endif + +#ifndef STBI_NO_BMP +static stbi__uint32 stbi__get32le(stbi__context *s) +{ + stbi__uint32 z = stbi__get16le(s); + return z + (stbi__get16le(s) << 16); +} +#endif + +#define STBI__BYTECAST(x) ((stbi_uc) ((x) & 255)) // truncate int to byte without warnings + + +////////////////////////////////////////////////////////////////////////////// +// +// generic converter from built-in img_n to req_comp +// individual types do this automatically as much as possible (e.g. jpeg +// does all cases internally since it needs to colorspace convert anyway, +// and it never has alpha, so very few cases ). png can automatically +// interleave an alpha=255 channel, but falls back to this for other cases +// +// assume data buffer is malloced, so malloc a new one and free that one +// only failure mode is malloc failing + +static stbi_uc stbi__compute_y(int r, int g, int b) +{ + return (stbi_uc) (((r*77) + (g*150) + (29*b)) >> 8); +} + +static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y) +{ + int i,j; + unsigned char *good; + + if (req_comp == img_n) return data; + STBI_ASSERT(req_comp >= 1 && req_comp <= 4); + + good = (unsigned char *) stbi__malloc_mad3(req_comp, x, y, 0); + if (good == NULL) { + STBI_FREE(data); + return stbi__errpuc("outofmem", "Out of memory"); + } + + for (j=0; j < (int) y; ++j) { + unsigned char *src = data + j * x * img_n ; + unsigned char *dest = good + j * x * req_comp; + + #define STBI__COMBO(a,b) ((a)*8+(b)) + #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) + // convert source image with img_n components to one with req_comp components; + // avoid switch per pixel, so use switch per scanline and massive macros + switch (STBI__COMBO(img_n, req_comp)) { + STBI__CASE(1,2) { dest[0]=src[0], dest[1]=255; } break; + STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; } break; + STBI__CASE(2,1) { dest[0]=src[0]; } break; + STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break; + STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; } break; + STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break; + STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; } break; + STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break; + STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; } break; + STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break; + default: STBI_ASSERT(0); + } + #undef STBI__CASE + } + + STBI_FREE(data); + return good; +} + +static stbi__uint16 stbi__compute_y_16(int r, int g, int b) +{ + return (stbi__uint16) (((r*77) + (g*150) + (29*b)) >> 8); +} + +static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y) +{ + int i,j; + stbi__uint16 *good; + + if (req_comp == img_n) return data; + STBI_ASSERT(req_comp >= 1 && req_comp <= 4); + + good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2); + if (good == NULL) { + STBI_FREE(data); + return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); + } + + for (j=0; j < (int) y; ++j) { + stbi__uint16 *src = data + j * x * img_n ; + stbi__uint16 *dest = good + j * x * req_comp; + + #define STBI__COMBO(a,b) ((a)*8+(b)) + #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) + // convert source image with img_n components to one with req_comp components; + // avoid switch per pixel, so use switch per scanline and massive macros + switch (STBI__COMBO(img_n, req_comp)) { + STBI__CASE(1,2) { dest[0]=src[0], dest[1]=0xffff; } break; + STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=0xffff; } break; + STBI__CASE(2,1) { dest[0]=src[0]; } break; + STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; + STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break; + STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=0xffff; } break; + STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break; + STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = 0xffff; } break; + STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break; + STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = src[3]; } break; + STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break; + default: STBI_ASSERT(0); + } + #undef STBI__CASE + } + + STBI_FREE(data); + return good; +} + +#ifndef STBI_NO_LINEAR +static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp) +{ + int i,k,n; + float *output; + if (!data) return NULL; + output = (float *) stbi__malloc_mad4(x, y, comp, sizeof(float), 0); + if (output == NULL) { STBI_FREE(data); return stbi__errpf("outofmem", "Out of memory"); } + // compute number of non-alpha components + if (comp & 1) n = comp; else n = comp-1; + for (i=0; i < x*y; ++i) { + for (k=0; k < n; ++k) { + output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale); + } + if (k < comp) output[i*comp + k] = data[i*comp+k]/255.0f; + } + STBI_FREE(data); + return output; +} +#endif + +#ifndef STBI_NO_HDR +#define stbi__float2int(x) ((int) (x)) +static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp) +{ + int i,k,n; + stbi_uc *output; + if (!data) return NULL; + output = (stbi_uc *) stbi__malloc_mad3(x, y, comp, 0); + if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); } + // compute number of non-alpha components + if (comp & 1) n = comp; else n = comp-1; + for (i=0; i < x*y; ++i) { + for (k=0; k < n; ++k) { + float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f; + if (z < 0) z = 0; + if (z > 255) z = 255; + output[i*comp + k] = (stbi_uc) stbi__float2int(z); + } + if (k < comp) { + float z = data[i*comp+k] * 255 + 0.5f; + if (z < 0) z = 0; + if (z > 255) z = 255; + output[i*comp + k] = (stbi_uc) stbi__float2int(z); + } + } + STBI_FREE(data); + return output; +} +#endif + +////////////////////////////////////////////////////////////////////////////// +// +// "baseline" JPEG/JFIF decoder +// +// simple implementation +// - doesn't support delayed output of y-dimension +// - simple interface (only one output format: 8-bit interleaved RGB) +// - doesn't try to recover corrupt jpegs +// - doesn't allow partial loading, loading multiple at once +// - still fast on x86 (copying globals into locals doesn't help x86) +// - allocates lots of intermediate memory (full size of all components) +// - non-interleaved case requires this anyway +// - allows good upsampling (see next) +// high-quality +// - upsampled channels are bilinearly interpolated, even across blocks +// - quality integer IDCT derived from IJG's 'slow' +// performance +// - fast huffman; reasonable integer IDCT +// - some SIMD kernels for common paths on targets with SSE2/NEON +// - uses a lot of intermediate memory, could cache poorly + +#ifndef STBI_NO_JPEG + +// huffman decoding acceleration +#define FAST_BITS 9 // larger handles more cases; smaller stomps less cache + +typedef struct +{ + stbi_uc fast[1 << FAST_BITS]; + // weirdly, repacking this into AoS is a 10% speed loss, instead of a win + stbi__uint16 code[256]; + stbi_uc values[256]; + stbi_uc size[257]; + unsigned int maxcode[18]; + int delta[17]; // old 'firstsymbol' - old 'firstcode' +} stbi__huffman; + +typedef struct +{ + stbi__context *s; + stbi__huffman huff_dc[4]; + stbi__huffman huff_ac[4]; + stbi__uint16 dequant[4][64]; + stbi__int16 fast_ac[4][1 << FAST_BITS]; + +// sizes for components, interleaved MCUs + int img_h_max, img_v_max; + int img_mcu_x, img_mcu_y; + int img_mcu_w, img_mcu_h; + +// definition of jpeg image component + struct + { + int id; + int h,v; + int tq; + int hd,ha; + int dc_pred; + + int x,y,w2,h2; + stbi_uc *data; + void *raw_data, *raw_coeff; + stbi_uc *linebuf; + short *coeff; // progressive only + int coeff_w, coeff_h; // number of 8x8 coefficient blocks + } img_comp[4]; + + stbi__uint32 code_buffer; // jpeg entropy-coded buffer + int code_bits; // number of valid bits + unsigned char marker; // marker seen while filling entropy buffer + int nomore; // flag if we saw a marker so must stop + + int progressive; + int spec_start; + int spec_end; + int succ_high; + int succ_low; + int eob_run; + int jfif; + int app14_color_transform; // Adobe APP14 tag + int rgb; + + int scan_n, order[4]; + int restart_interval, todo; + +// kernels + void (*idct_block_kernel)(stbi_uc *out, int out_stride, short data[64]); + void (*YCbCr_to_RGB_kernel)(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step); + stbi_uc *(*resample_row_hv_2_kernel)(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs); +} stbi__jpeg; + +static int stbi__build_huffman(stbi__huffman *h, int *count) +{ + int i,j,k=0; + unsigned int code; + // build size list for each symbol (from JPEG spec) + for (i=0; i < 16; ++i) + for (j=0; j < count[i]; ++j) + h->size[k++] = (stbi_uc) (i+1); + h->size[k] = 0; + + // compute actual symbols (from jpeg spec) + code = 0; + k = 0; + for(j=1; j <= 16; ++j) { + // compute delta to add to code to compute symbol id + h->delta[j] = k - code; + if (h->size[k] == j) { + while (h->size[k] == j) + h->code[k++] = (stbi__uint16) (code++); + if (code-1 >= (1u << j)) return stbi__err("bad code lengths","Corrupt JPEG"); + } + // compute largest code + 1 for this size, preshifted as needed later + h->maxcode[j] = code << (16-j); + code <<= 1; + } + h->maxcode[j] = 0xffffffff; + + // build non-spec acceleration table; 255 is flag for not-accelerated + memset(h->fast, 255, 1 << FAST_BITS); + for (i=0; i < k; ++i) { + int s = h->size[i]; + if (s <= FAST_BITS) { + int c = h->code[i] << (FAST_BITS-s); + int m = 1 << (FAST_BITS-s); + for (j=0; j < m; ++j) { + h->fast[c+j] = (stbi_uc) i; + } + } + } + return 1; +} + +// build a table that decodes both magnitude and value of small ACs in +// one go. +static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h) +{ + int i; + for (i=0; i < (1 << FAST_BITS); ++i) { + stbi_uc fast = h->fast[i]; + fast_ac[i] = 0; + if (fast < 255) { + int rs = h->values[fast]; + int run = (rs >> 4) & 15; + int magbits = rs & 15; + int len = h->size[fast]; + + if (magbits && len + magbits <= FAST_BITS) { + // magnitude code followed by receive_extend code + int k = ((i << len) & ((1 << FAST_BITS) - 1)) >> (FAST_BITS - magbits); + int m = 1 << (magbits - 1); + if (k < m) k += (~0U << magbits) + 1; + // if the result is small enough, we can fit it in fast_ac table + if (k >= -128 && k <= 127) + fast_ac[i] = (stbi__int16) ((k * 256) + (run * 16) + (len + magbits)); + } + } + } +} + +static void stbi__grow_buffer_unsafe(stbi__jpeg *j) +{ + do { + unsigned int b = j->nomore ? 0 : stbi__get8(j->s); + if (b == 0xff) { + int c = stbi__get8(j->s); + while (c == 0xff) c = stbi__get8(j->s); // consume fill bytes + if (c != 0) { + j->marker = (unsigned char) c; + j->nomore = 1; + return; + } + } + j->code_buffer |= b << (24 - j->code_bits); + j->code_bits += 8; + } while (j->code_bits <= 24); +} + +// (1 << n) - 1 +static const stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; + +// decode a jpeg huffman value from the bitstream +stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) +{ + unsigned int temp; + int c,k; + + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + + // look at the top FAST_BITS and determine what symbol ID it is, + // if the code is <= FAST_BITS + c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); + k = h->fast[c]; + if (k < 255) { + int s = h->size[k]; + if (s > j->code_bits) + return -1; + j->code_buffer <<= s; + j->code_bits -= s; + return h->values[k]; + } + + // naive test is to shift the code_buffer down so k bits are + // valid, then test against maxcode. To speed this up, we've + // preshifted maxcode left so that it has (16-k) 0s at the + // end; in other words, regardless of the number of bits, it + // wants to be compared against something shifted to have 16; + // that way we don't need to shift inside the loop. + temp = j->code_buffer >> 16; + for (k=FAST_BITS+1 ; ; ++k) + if (temp < h->maxcode[k]) + break; + if (k == 17) { + // error! code not found + j->code_bits -= 16; + return -1; + } + + if (k > j->code_bits) + return -1; + + // convert the huffman code to the symbol id + c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k]; + STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]); + + // convert the id to a symbol + j->code_bits -= k; + j->code_buffer <<= k; + return h->values[c]; +} + +// bias[n] = (-1<<n) + 1 +static const int stbi__jbias[16] = {0,-1,-3,-7,-15,-31,-63,-127,-255,-511,-1023,-2047,-4095,-8191,-16383,-32767}; + +// combined JPEG 'receive' and JPEG 'extend', since baseline +// always extends everything it receives. +stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n) +{ + unsigned int k; + int sgn; + if (j->code_bits < n) stbi__grow_buffer_unsafe(j); + + sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB + k = stbi_lrot(j->code_buffer, n); + STBI_ASSERT(n >= 0 && n < (int) (sizeof(stbi__bmask)/sizeof(*stbi__bmask))); + j->code_buffer = k & ~stbi__bmask[n]; + k &= stbi__bmask[n]; + j->code_bits -= n; + return k + (stbi__jbias[n] & ~sgn); +} + +// get some unsigned bits +stbi_inline static int stbi__jpeg_get_bits(stbi__jpeg *j, int n) +{ + unsigned int k; + if (j->code_bits < n) stbi__grow_buffer_unsafe(j); + k = stbi_lrot(j->code_buffer, n); + j->code_buffer = k & ~stbi__bmask[n]; + k &= stbi__bmask[n]; + j->code_bits -= n; + return k; +} + +stbi_inline static int stbi__jpeg_get_bit(stbi__jpeg *j) +{ + unsigned int k; + if (j->code_bits < 1) stbi__grow_buffer_unsafe(j); + k = j->code_buffer; + j->code_buffer <<= 1; + --j->code_bits; + return k & 0x80000000; +} + +// given a value that's at position X in the zigzag stream, +// where does it appear in the 8x8 matrix coded as row-major? +static const stbi_uc stbi__jpeg_dezigzag[64+15] = +{ + 0, 1, 8, 16, 9, 2, 3, 10, + 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, + 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, + 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, + 53, 60, 61, 54, 47, 55, 62, 63, + // let corrupt input sample past end + 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63 +}; + +// decode one 64-entry block-- +static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi__uint16 *dequant) +{ + int diff,dc,k; + int t; + + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + t = stbi__jpeg_huff_decode(j, hdc); + if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + + // 0 all the ac values now so we can do it 32-bits at a time + memset(data,0,64*sizeof(data[0])); + + diff = t ? stbi__extend_receive(j, t) : 0; + dc = j->img_comp[b].dc_pred + diff; + j->img_comp[b].dc_pred = dc; + data[0] = (short) (dc * dequant[0]); + + // decode AC components, see JPEG spec + k = 1; + do { + unsigned int zig; + int c,r,s; + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); + r = fac[c]; + if (r) { // fast-AC path + k += (r >> 4) & 15; // run + s = r & 15; // combined length + j->code_buffer <<= s; + j->code_bits -= s; + // decode into unzigzag'd location + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) ((r >> 8) * dequant[zig]); + } else { + int rs = stbi__jpeg_huff_decode(j, hac); + if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + s = rs & 15; + r = rs >> 4; + if (s == 0) { + if (rs != 0xf0) break; // end block + k += 16; + } else { + k += r; + // decode into unzigzag'd location + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) (stbi__extend_receive(j,s) * dequant[zig]); + } + } + } while (k < 64); + return 1; +} + +static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__huffman *hdc, int b) +{ + int diff,dc; + int t; + if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + + if (j->succ_high == 0) { + // first scan for DC coefficient, must be first + memset(data,0,64*sizeof(data[0])); // 0 all the ac values now + t = stbi__jpeg_huff_decode(j, hdc); + diff = t ? stbi__extend_receive(j, t) : 0; + + dc = j->img_comp[b].dc_pred + diff; + j->img_comp[b].dc_pred = dc; + data[0] = (short) (dc << j->succ_low); + } else { + // refinement scan for DC coefficient + if (stbi__jpeg_get_bit(j)) + data[0] += (short) (1 << j->succ_low); + } + return 1; +} + +// @OPTIMIZE: store non-zigzagged during the decode passes, +// and only de-zigzag when dequantizing +static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac) +{ + int k; + if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); + + if (j->succ_high == 0) { + int shift = j->succ_low; + + if (j->eob_run) { + --j->eob_run; + return 1; + } + + k = j->spec_start; + do { + unsigned int zig; + int c,r,s; + if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); + c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1); + r = fac[c]; + if (r) { // fast-AC path + k += (r >> 4) & 15; // run + s = r & 15; // combined length + j->code_buffer <<= s; + j->code_bits -= s; + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) ((r >> 8) << shift); + } else { + int rs = stbi__jpeg_huff_decode(j, hac); + if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + s = rs & 15; + r = rs >> 4; + if (s == 0) { + if (r < 15) { + j->eob_run = (1 << r); + if (r) + j->eob_run += stbi__jpeg_get_bits(j, r); + --j->eob_run; + break; + } + k += 16; + } else { + k += r; + zig = stbi__jpeg_dezigzag[k++]; + data[zig] = (short) (stbi__extend_receive(j,s) << shift); + } + } + } while (k <= j->spec_end); + } else { + // refinement scan for these AC coefficients + + short bit = (short) (1 << j->succ_low); + + if (j->eob_run) { + --j->eob_run; + for (k = j->spec_start; k <= j->spec_end; ++k) { + short *p = &data[stbi__jpeg_dezigzag[k]]; + if (*p != 0) + if (stbi__jpeg_get_bit(j)) + if ((*p & bit)==0) { + if (*p > 0) + *p += bit; + else + *p -= bit; + } + } + } else { + k = j->spec_start; + do { + int r,s; + int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh + if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG"); + s = rs & 15; + r = rs >> 4; + if (s == 0) { + if (r < 15) { + j->eob_run = (1 << r) - 1; + if (r) + j->eob_run += stbi__jpeg_get_bits(j, r); + r = 64; // force end of block + } else { + // r=15 s=0 should write 16 0s, so we just do + // a run of 15 0s and then write s (which is 0), + // so we don't have to do anything special here + } + } else { + if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG"); + // sign bit + if (stbi__jpeg_get_bit(j)) + s = bit; + else + s = -bit; + } + + // advance by r + while (k <= j->spec_end) { + short *p = &data[stbi__jpeg_dezigzag[k++]]; + if (*p != 0) { + if (stbi__jpeg_get_bit(j)) + if ((*p & bit)==0) { + if (*p > 0) + *p += bit; + else + *p -= bit; + } + } else { + if (r == 0) { + *p = (short) s; + break; + } + --r; + } + } + } while (k <= j->spec_end); + } + } + return 1; +} + +// take a -128..127 value and stbi__clamp it and convert to 0..255 +stbi_inline static stbi_uc stbi__clamp(int x) +{ + // trick to use a single test to catch both cases + if ((unsigned int) x > 255) { + if (x < 0) return 0; + if (x > 255) return 255; + } + return (stbi_uc) x; +} + +#define stbi__f2f(x) ((int) (((x) * 4096 + 0.5))) +#define stbi__fsh(x) ((x) * 4096) + +// derived from jidctint -- DCT_ISLOW +#define STBI__IDCT_1D(s0,s1,s2,s3,s4,s5,s6,s7) \ + int t0,t1,t2,t3,p1,p2,p3,p4,p5,x0,x1,x2,x3; \ + p2 = s2; \ + p3 = s6; \ + p1 = (p2+p3) * stbi__f2f(0.5411961f); \ + t2 = p1 + p3*stbi__f2f(-1.847759065f); \ + t3 = p1 + p2*stbi__f2f( 0.765366865f); \ + p2 = s0; \ + p3 = s4; \ + t0 = stbi__fsh(p2+p3); \ + t1 = stbi__fsh(p2-p3); \ + x0 = t0+t3; \ + x3 = t0-t3; \ + x1 = t1+t2; \ + x2 = t1-t2; \ + t0 = s7; \ + t1 = s5; \ + t2 = s3; \ + t3 = s1; \ + p3 = t0+t2; \ + p4 = t1+t3; \ + p1 = t0+t3; \ + p2 = t1+t2; \ + p5 = (p3+p4)*stbi__f2f( 1.175875602f); \ + t0 = t0*stbi__f2f( 0.298631336f); \ + t1 = t1*stbi__f2f( 2.053119869f); \ + t2 = t2*stbi__f2f( 3.072711026f); \ + t3 = t3*stbi__f2f( 1.501321110f); \ + p1 = p5 + p1*stbi__f2f(-0.899976223f); \ + p2 = p5 + p2*stbi__f2f(-2.562915447f); \ + p3 = p3*stbi__f2f(-1.961570560f); \ + p4 = p4*stbi__f2f(-0.390180644f); \ + t3 += p1+p4; \ + t2 += p2+p3; \ + t1 += p2+p4; \ + t0 += p1+p3; + +static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64]) +{ + int i,val[64],*v=val; + stbi_uc *o; + short *d = data; + + // columns + for (i=0; i < 8; ++i,++d, ++v) { + // if all zeroes, shortcut -- this avoids dequantizing 0s and IDCTing + if (d[ 8]==0 && d[16]==0 && d[24]==0 && d[32]==0 + && d[40]==0 && d[48]==0 && d[56]==0) { + // no shortcut 0 seconds + // (1|2|3|4|5|6|7)==0 0 seconds + // all separate -0.047 seconds + // 1 && 2|3 && 4|5 && 6|7: -0.047 seconds + int dcterm = d[0]*4; + v[0] = v[8] = v[16] = v[24] = v[32] = v[40] = v[48] = v[56] = dcterm; + } else { + STBI__IDCT_1D(d[ 0],d[ 8],d[16],d[24],d[32],d[40],d[48],d[56]) + // constants scaled things up by 1<<12; let's bring them back + // down, but keep 2 extra bits of precision + x0 += 512; x1 += 512; x2 += 512; x3 += 512; + v[ 0] = (x0+t3) >> 10; + v[56] = (x0-t3) >> 10; + v[ 8] = (x1+t2) >> 10; + v[48] = (x1-t2) >> 10; + v[16] = (x2+t1) >> 10; + v[40] = (x2-t1) >> 10; + v[24] = (x3+t0) >> 10; + v[32] = (x3-t0) >> 10; + } + } + + for (i=0, v=val, o=out; i < 8; ++i,v+=8,o+=out_stride) { + // no fast case since the first 1D IDCT spread components out + STBI__IDCT_1D(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]) + // constants scaled things up by 1<<12, plus we had 1<<2 from first + // loop, plus horizontal and vertical each scale by sqrt(8) so together + // we've got an extra 1<<3, so 1<<17 total we need to remove. + // so we want to round that, which means adding 0.5 * 1<<17, + // aka 65536. Also, we'll end up with -128 to 127 that we want + // to encode as 0..255 by adding 128, so we'll add that before the shift + x0 += 65536 + (128<<17); + x1 += 65536 + (128<<17); + x2 += 65536 + (128<<17); + x3 += 65536 + (128<<17); + // tried computing the shifts into temps, or'ing the temps to see + // if any were out of range, but that was slower + o[0] = stbi__clamp((x0+t3) >> 17); + o[7] = stbi__clamp((x0-t3) >> 17); + o[1] = stbi__clamp((x1+t2) >> 17); + o[6] = stbi__clamp((x1-t2) >> 17); + o[2] = stbi__clamp((x2+t1) >> 17); + o[5] = stbi__clamp((x2-t1) >> 17); + o[3] = stbi__clamp((x3+t0) >> 17); + o[4] = stbi__clamp((x3-t0) >> 17); + } +} + +#ifdef STBI_SSE2 +// sse2 integer IDCT. not the fastest possible implementation but it +// produces bit-identical results to the generic C version so it's +// fully "transparent". +static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) +{ + // This is constructed to match our regular (generic) integer IDCT exactly. + __m128i row0, row1, row2, row3, row4, row5, row6, row7; + __m128i tmp; + + // dot product constant: even elems=x, odd elems=y + #define dct_const(x,y) _mm_setr_epi16((x),(y),(x),(y),(x),(y),(x),(y)) + + // out(0) = c0[even]*x + c0[odd]*y (c0, x, y 16-bit, out 32-bit) + // out(1) = c1[even]*x + c1[odd]*y + #define dct_rot(out0,out1, x,y,c0,c1) \ + __m128i c0##lo = _mm_unpacklo_epi16((x),(y)); \ + __m128i c0##hi = _mm_unpackhi_epi16((x),(y)); \ + __m128i out0##_l = _mm_madd_epi16(c0##lo, c0); \ + __m128i out0##_h = _mm_madd_epi16(c0##hi, c0); \ + __m128i out1##_l = _mm_madd_epi16(c0##lo, c1); \ + __m128i out1##_h = _mm_madd_epi16(c0##hi, c1) + + // out = in << 12 (in 16-bit, out 32-bit) + #define dct_widen(out, in) \ + __m128i out##_l = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), (in)), 4); \ + __m128i out##_h = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), (in)), 4) + + // wide add + #define dct_wadd(out, a, b) \ + __m128i out##_l = _mm_add_epi32(a##_l, b##_l); \ + __m128i out##_h = _mm_add_epi32(a##_h, b##_h) + + // wide sub + #define dct_wsub(out, a, b) \ + __m128i out##_l = _mm_sub_epi32(a##_l, b##_l); \ + __m128i out##_h = _mm_sub_epi32(a##_h, b##_h) + + // butterfly a/b, add bias, then shift by "s" and pack + #define dct_bfly32o(out0, out1, a,b,bias,s) \ + { \ + __m128i abiased_l = _mm_add_epi32(a##_l, bias); \ + __m128i abiased_h = _mm_add_epi32(a##_h, bias); \ + dct_wadd(sum, abiased, b); \ + dct_wsub(dif, abiased, b); \ + out0 = _mm_packs_epi32(_mm_srai_epi32(sum_l, s), _mm_srai_epi32(sum_h, s)); \ + out1 = _mm_packs_epi32(_mm_srai_epi32(dif_l, s), _mm_srai_epi32(dif_h, s)); \ + } + + // 8-bit interleave step (for transposes) + #define dct_interleave8(a, b) \ + tmp = a; \ + a = _mm_unpacklo_epi8(a, b); \ + b = _mm_unpackhi_epi8(tmp, b) + + // 16-bit interleave step (for transposes) + #define dct_interleave16(a, b) \ + tmp = a; \ + a = _mm_unpacklo_epi16(a, b); \ + b = _mm_unpackhi_epi16(tmp, b) + + #define dct_pass(bias,shift) \ + { \ + /* even part */ \ + dct_rot(t2e,t3e, row2,row6, rot0_0,rot0_1); \ + __m128i sum04 = _mm_add_epi16(row0, row4); \ + __m128i dif04 = _mm_sub_epi16(row0, row4); \ + dct_widen(t0e, sum04); \ + dct_widen(t1e, dif04); \ + dct_wadd(x0, t0e, t3e); \ + dct_wsub(x3, t0e, t3e); \ + dct_wadd(x1, t1e, t2e); \ + dct_wsub(x2, t1e, t2e); \ + /* odd part */ \ + dct_rot(y0o,y2o, row7,row3, rot2_0,rot2_1); \ + dct_rot(y1o,y3o, row5,row1, rot3_0,rot3_1); \ + __m128i sum17 = _mm_add_epi16(row1, row7); \ + __m128i sum35 = _mm_add_epi16(row3, row5); \ + dct_rot(y4o,y5o, sum17,sum35, rot1_0,rot1_1); \ + dct_wadd(x4, y0o, y4o); \ + dct_wadd(x5, y1o, y5o); \ + dct_wadd(x6, y2o, y5o); \ + dct_wadd(x7, y3o, y4o); \ + dct_bfly32o(row0,row7, x0,x7,bias,shift); \ + dct_bfly32o(row1,row6, x1,x6,bias,shift); \ + dct_bfly32o(row2,row5, x2,x5,bias,shift); \ + dct_bfly32o(row3,row4, x3,x4,bias,shift); \ + } + + __m128i rot0_0 = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f)); + __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f( 0.765366865f), stbi__f2f(0.5411961f)); + __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f)); + __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f)); + __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f( 0.298631336f), stbi__f2f(-1.961570560f)); + __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f( 3.072711026f)); + __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f( 2.053119869f), stbi__f2f(-0.390180644f)); + __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f( 1.501321110f)); + + // rounding biases in column/row passes, see stbi__idct_block for explanation. + __m128i bias_0 = _mm_set1_epi32(512); + __m128i bias_1 = _mm_set1_epi32(65536 + (128<<17)); + + // load + row0 = _mm_load_si128((const __m128i *) (data + 0*8)); + row1 = _mm_load_si128((const __m128i *) (data + 1*8)); + row2 = _mm_load_si128((const __m128i *) (data + 2*8)); + row3 = _mm_load_si128((const __m128i *) (data + 3*8)); + row4 = _mm_load_si128((const __m128i *) (data + 4*8)); + row5 = _mm_load_si128((const __m128i *) (data + 5*8)); + row6 = _mm_load_si128((const __m128i *) (data + 6*8)); + row7 = _mm_load_si128((const __m128i *) (data + 7*8)); + + // column pass + dct_pass(bias_0, 10); + + { + // 16bit 8x8 transpose pass 1 + dct_interleave16(row0, row4); + dct_interleave16(row1, row5); + dct_interleave16(row2, row6); + dct_interleave16(row3, row7); + + // transpose pass 2 + dct_interleave16(row0, row2); + dct_interleave16(row1, row3); + dct_interleave16(row4, row6); + dct_interleave16(row5, row7); + + // transpose pass 3 + dct_interleave16(row0, row1); + dct_interleave16(row2, row3); + dct_interleave16(row4, row5); + dct_interleave16(row6, row7); + } + + // row pass + dct_pass(bias_1, 17); + + { + // pack + __m128i p0 = _mm_packus_epi16(row0, row1); // a0a1a2a3...a7b0b1b2b3...b7 + __m128i p1 = _mm_packus_epi16(row2, row3); + __m128i p2 = _mm_packus_epi16(row4, row5); + __m128i p3 = _mm_packus_epi16(row6, row7); + + // 8bit 8x8 transpose pass 1 + dct_interleave8(p0, p2); // a0e0a1e1... + dct_interleave8(p1, p3); // c0g0c1g1... + + // transpose pass 2 + dct_interleave8(p0, p1); // a0c0e0g0... + dct_interleave8(p2, p3); // b0d0f0h0... + + // transpose pass 3 + dct_interleave8(p0, p2); // a0b0c0d0... + dct_interleave8(p1, p3); // a4b4c4d4... + + // store + _mm_storel_epi64((__m128i *) out, p0); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p0, 0x4e)); out += out_stride; + _mm_storel_epi64((__m128i *) out, p2); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p2, 0x4e)); out += out_stride; + _mm_storel_epi64((__m128i *) out, p1); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p1, 0x4e)); out += out_stride; + _mm_storel_epi64((__m128i *) out, p3); out += out_stride; + _mm_storel_epi64((__m128i *) out, _mm_shuffle_epi32(p3, 0x4e)); + } + +#undef dct_const +#undef dct_rot +#undef dct_widen +#undef dct_wadd +#undef dct_wsub +#undef dct_bfly32o +#undef dct_interleave8 +#undef dct_interleave16 +#undef dct_pass +} + +#endif // STBI_SSE2 + +#ifdef STBI_NEON + +// NEON integer IDCT. should produce bit-identical +// results to the generic C version. +static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) +{ + int16x8_t row0, row1, row2, row3, row4, row5, row6, row7; + + int16x4_t rot0_0 = vdup_n_s16(stbi__f2f(0.5411961f)); + int16x4_t rot0_1 = vdup_n_s16(stbi__f2f(-1.847759065f)); + int16x4_t rot0_2 = vdup_n_s16(stbi__f2f( 0.765366865f)); + int16x4_t rot1_0 = vdup_n_s16(stbi__f2f( 1.175875602f)); + int16x4_t rot1_1 = vdup_n_s16(stbi__f2f(-0.899976223f)); + int16x4_t rot1_2 = vdup_n_s16(stbi__f2f(-2.562915447f)); + int16x4_t rot2_0 = vdup_n_s16(stbi__f2f(-1.961570560f)); + int16x4_t rot2_1 = vdup_n_s16(stbi__f2f(-0.390180644f)); + int16x4_t rot3_0 = vdup_n_s16(stbi__f2f( 0.298631336f)); + int16x4_t rot3_1 = vdup_n_s16(stbi__f2f( 2.053119869f)); + int16x4_t rot3_2 = vdup_n_s16(stbi__f2f( 3.072711026f)); + int16x4_t rot3_3 = vdup_n_s16(stbi__f2f( 1.501321110f)); + +#define dct_long_mul(out, inq, coeff) \ + int32x4_t out##_l = vmull_s16(vget_low_s16(inq), coeff); \ + int32x4_t out##_h = vmull_s16(vget_high_s16(inq), coeff) + +#define dct_long_mac(out, acc, inq, coeff) \ + int32x4_t out##_l = vmlal_s16(acc##_l, vget_low_s16(inq), coeff); \ + int32x4_t out##_h = vmlal_s16(acc##_h, vget_high_s16(inq), coeff) + +#define dct_widen(out, inq) \ + int32x4_t out##_l = vshll_n_s16(vget_low_s16(inq), 12); \ + int32x4_t out##_h = vshll_n_s16(vget_high_s16(inq), 12) + +// wide add +#define dct_wadd(out, a, b) \ + int32x4_t out##_l = vaddq_s32(a##_l, b##_l); \ + int32x4_t out##_h = vaddq_s32(a##_h, b##_h) + +// wide sub +#define dct_wsub(out, a, b) \ + int32x4_t out##_l = vsubq_s32(a##_l, b##_l); \ + int32x4_t out##_h = vsubq_s32(a##_h, b##_h) + +// butterfly a/b, then shift using "shiftop" by "s" and pack +#define dct_bfly32o(out0,out1, a,b,shiftop,s) \ + { \ + dct_wadd(sum, a, b); \ + dct_wsub(dif, a, b); \ + out0 = vcombine_s16(shiftop(sum_l, s), shiftop(sum_h, s)); \ + out1 = vcombine_s16(shiftop(dif_l, s), shiftop(dif_h, s)); \ + } + +#define dct_pass(shiftop, shift) \ + { \ + /* even part */ \ + int16x8_t sum26 = vaddq_s16(row2, row6); \ + dct_long_mul(p1e, sum26, rot0_0); \ + dct_long_mac(t2e, p1e, row6, rot0_1); \ + dct_long_mac(t3e, p1e, row2, rot0_2); \ + int16x8_t sum04 = vaddq_s16(row0, row4); \ + int16x8_t dif04 = vsubq_s16(row0, row4); \ + dct_widen(t0e, sum04); \ + dct_widen(t1e, dif04); \ + dct_wadd(x0, t0e, t3e); \ + dct_wsub(x3, t0e, t3e); \ + dct_wadd(x1, t1e, t2e); \ + dct_wsub(x2, t1e, t2e); \ + /* odd part */ \ + int16x8_t sum15 = vaddq_s16(row1, row5); \ + int16x8_t sum17 = vaddq_s16(row1, row7); \ + int16x8_t sum35 = vaddq_s16(row3, row5); \ + int16x8_t sum37 = vaddq_s16(row3, row7); \ + int16x8_t sumodd = vaddq_s16(sum17, sum35); \ + dct_long_mul(p5o, sumodd, rot1_0); \ + dct_long_mac(p1o, p5o, sum17, rot1_1); \ + dct_long_mac(p2o, p5o, sum35, rot1_2); \ + dct_long_mul(p3o, sum37, rot2_0); \ + dct_long_mul(p4o, sum15, rot2_1); \ + dct_wadd(sump13o, p1o, p3o); \ + dct_wadd(sump24o, p2o, p4o); \ + dct_wadd(sump23o, p2o, p3o); \ + dct_wadd(sump14o, p1o, p4o); \ + dct_long_mac(x4, sump13o, row7, rot3_0); \ + dct_long_mac(x5, sump24o, row5, rot3_1); \ + dct_long_mac(x6, sump23o, row3, rot3_2); \ + dct_long_mac(x7, sump14o, row1, rot3_3); \ + dct_bfly32o(row0,row7, x0,x7,shiftop,shift); \ + dct_bfly32o(row1,row6, x1,x6,shiftop,shift); \ + dct_bfly32o(row2,row5, x2,x5,shiftop,shift); \ + dct_bfly32o(row3,row4, x3,x4,shiftop,shift); \ + } + + // load + row0 = vld1q_s16(data + 0*8); + row1 = vld1q_s16(data + 1*8); + row2 = vld1q_s16(data + 2*8); + row3 = vld1q_s16(data + 3*8); + row4 = vld1q_s16(data + 4*8); + row5 = vld1q_s16(data + 5*8); + row6 = vld1q_s16(data + 6*8); + row7 = vld1q_s16(data + 7*8); + + // add DC bias + row0 = vaddq_s16(row0, vsetq_lane_s16(1024, vdupq_n_s16(0), 0)); + + // column pass + dct_pass(vrshrn_n_s32, 10); + + // 16bit 8x8 transpose + { +// these three map to a single VTRN.16, VTRN.32, and VSWP, respectively. +// whether compilers actually get this is another story, sadly. +#define dct_trn16(x, y) { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; } +#define dct_trn32(x, y) { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); } +#define dct_trn64(x, y) { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); } + + // pass 1 + dct_trn16(row0, row1); // a0b0a2b2a4b4a6b6 + dct_trn16(row2, row3); + dct_trn16(row4, row5); + dct_trn16(row6, row7); + + // pass 2 + dct_trn32(row0, row2); // a0b0c0d0a4b4c4d4 + dct_trn32(row1, row3); + dct_trn32(row4, row6); + dct_trn32(row5, row7); + + // pass 3 + dct_trn64(row0, row4); // a0b0c0d0e0f0g0h0 + dct_trn64(row1, row5); + dct_trn64(row2, row6); + dct_trn64(row3, row7); + +#undef dct_trn16 +#undef dct_trn32 +#undef dct_trn64 + } + + // row pass + // vrshrn_n_s32 only supports shifts up to 16, we need + // 17. so do a non-rounding shift of 16 first then follow + // up with a rounding shift by 1. + dct_pass(vshrn_n_s32, 16); + + { + // pack and round + uint8x8_t p0 = vqrshrun_n_s16(row0, 1); + uint8x8_t p1 = vqrshrun_n_s16(row1, 1); + uint8x8_t p2 = vqrshrun_n_s16(row2, 1); + uint8x8_t p3 = vqrshrun_n_s16(row3, 1); + uint8x8_t p4 = vqrshrun_n_s16(row4, 1); + uint8x8_t p5 = vqrshrun_n_s16(row5, 1); + uint8x8_t p6 = vqrshrun_n_s16(row6, 1); + uint8x8_t p7 = vqrshrun_n_s16(row7, 1); + + // again, these can translate into one instruction, but often don't. +#define dct_trn8_8(x, y) { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; } +#define dct_trn8_16(x, y) { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); } +#define dct_trn8_32(x, y) { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); } + + // sadly can't use interleaved stores here since we only write + // 8 bytes to each scan line! + + // 8x8 8-bit transpose pass 1 + dct_trn8_8(p0, p1); + dct_trn8_8(p2, p3); + dct_trn8_8(p4, p5); + dct_trn8_8(p6, p7); + + // pass 2 + dct_trn8_16(p0, p2); + dct_trn8_16(p1, p3); + dct_trn8_16(p4, p6); + dct_trn8_16(p5, p7); + + // pass 3 + dct_trn8_32(p0, p4); + dct_trn8_32(p1, p5); + dct_trn8_32(p2, p6); + dct_trn8_32(p3, p7); + + // store + vst1_u8(out, p0); out += out_stride; + vst1_u8(out, p1); out += out_stride; + vst1_u8(out, p2); out += out_stride; + vst1_u8(out, p3); out += out_stride; + vst1_u8(out, p4); out += out_stride; + vst1_u8(out, p5); out += out_stride; + vst1_u8(out, p6); out += out_stride; + vst1_u8(out, p7); + +#undef dct_trn8_8 +#undef dct_trn8_16 +#undef dct_trn8_32 + } + +#undef dct_long_mul +#undef dct_long_mac +#undef dct_widen +#undef dct_wadd +#undef dct_wsub +#undef dct_bfly32o +#undef dct_pass +} + +#endif // STBI_NEON + +#define STBI__MARKER_none 0xff +// if there's a pending marker from the entropy stream, return that +// otherwise, fetch from the stream and get a marker. if there's no +// marker, return 0xff, which is never a valid marker value +static stbi_uc stbi__get_marker(stbi__jpeg *j) +{ + stbi_uc x; + if (j->marker != STBI__MARKER_none) { x = j->marker; j->marker = STBI__MARKER_none; return x; } + x = stbi__get8(j->s); + if (x != 0xff) return STBI__MARKER_none; + while (x == 0xff) + x = stbi__get8(j->s); // consume repeated 0xff fill bytes + return x; +} + +// in each scan, we'll have scan_n components, and the order +// of the components is specified by order[] +#define STBI__RESTART(x) ((x) >= 0xd0 && (x) <= 0xd7) + +// after a restart interval, stbi__jpeg_reset the entropy decoder and +// the dc prediction +static void stbi__jpeg_reset(stbi__jpeg *j) +{ + j->code_bits = 0; + j->code_buffer = 0; + j->nomore = 0; + j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = j->img_comp[3].dc_pred = 0; + j->marker = STBI__MARKER_none; + j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff; + j->eob_run = 0; + // no more than 1<<31 MCUs if no restart_interal? that's plenty safe, + // since we don't even allow 1<<30 pixels +} + +static int stbi__parse_entropy_coded_data(stbi__jpeg *z) +{ + stbi__jpeg_reset(z); + if (!z->progressive) { + if (z->scan_n == 1) { + int i,j; + STBI_SIMD_ALIGN(short, data[64]); + int n = z->order[0]; + // non-interleaved data, we just need to process one block at a time, + // in trivial scanline order + // number of blocks to do just depends on how many actual "pixels" this + // component has, independent of interleaved MCU blocking and such + int w = (z->img_comp[n].x+7) >> 3; + int h = (z->img_comp[n].y+7) >> 3; + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) { + int ha = z->img_comp[n].ha; + if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; + z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data); + // every data block is an MCU, so countdown the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + // if it's NOT a restart, then just bail, so we get corrupt data + // rather than no data + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } else { // interleaved + int i,j,k,x,y; + STBI_SIMD_ALIGN(short, data[64]); + for (j=0; j < z->img_mcu_y; ++j) { + for (i=0; i < z->img_mcu_x; ++i) { + // scan an interleaved mcu... process scan_n components in order + for (k=0; k < z->scan_n; ++k) { + int n = z->order[k]; + // scan out an mcu's worth of this component; that's just determined + // by the basic H and V specified for the component + for (y=0; y < z->img_comp[n].v; ++y) { + for (x=0; x < z->img_comp[n].h; ++x) { + int x2 = (i*z->img_comp[n].h + x)*8; + int y2 = (j*z->img_comp[n].v + y)*8; + int ha = z->img_comp[n].ha; + if (!stbi__jpeg_decode_block(z, data, z->huff_dc+z->img_comp[n].hd, z->huff_ac+ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; + z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*y2+x2, z->img_comp[n].w2, data); + } + } + } + // after all interleaved components, that's an interleaved MCU, + // so now count down the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } + } else { + if (z->scan_n == 1) { + int i,j; + int n = z->order[0]; + // non-interleaved data, we just need to process one block at a time, + // in trivial scanline order + // number of blocks to do just depends on how many actual "pixels" this + // component has, independent of interleaved MCU blocking and such + int w = (z->img_comp[n].x+7) >> 3; + int h = (z->img_comp[n].y+7) >> 3; + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) { + short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); + if (z->spec_start == 0) { + if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n)) + return 0; + } else { + int ha = z->img_comp[n].ha; + if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], z->fast_ac[ha])) + return 0; + } + // every data block is an MCU, so countdown the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } else { // interleaved + int i,j,k,x,y; + for (j=0; j < z->img_mcu_y; ++j) { + for (i=0; i < z->img_mcu_x; ++i) { + // scan an interleaved mcu... process scan_n components in order + for (k=0; k < z->scan_n; ++k) { + int n = z->order[k]; + // scan out an mcu's worth of this component; that's just determined + // by the basic H and V specified for the component + for (y=0; y < z->img_comp[n].v; ++y) { + for (x=0; x < z->img_comp[n].h; ++x) { + int x2 = (i*z->img_comp[n].h + x); + int y2 = (j*z->img_comp[n].v + y); + short *data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w); + if (!stbi__jpeg_decode_block_prog_dc(z, data, &z->huff_dc[z->img_comp[n].hd], n)) + return 0; + } + } + } + // after all interleaved components, that's an interleaved MCU, + // so now count down the restart interval + if (--z->todo <= 0) { + if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); + if (!STBI__RESTART(z->marker)) return 1; + stbi__jpeg_reset(z); + } + } + } + return 1; + } + } +} + +static void stbi__jpeg_dequantize(short *data, stbi__uint16 *dequant) +{ + int i; + for (i=0; i < 64; ++i) + data[i] *= dequant[i]; +} + +static void stbi__jpeg_finish(stbi__jpeg *z) +{ + if (z->progressive) { + // dequantize and idct the data + int i,j,n; + for (n=0; n < z->s->img_n; ++n) { + int w = (z->img_comp[n].x+7) >> 3; + int h = (z->img_comp[n].y+7) >> 3; + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) { + short *data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); + stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); + z->idct_block_kernel(z->img_comp[n].data+z->img_comp[n].w2*j*8+i*8, z->img_comp[n].w2, data); + } + } + } + } +} + +static int stbi__process_marker(stbi__jpeg *z, int m) +{ + int L; + switch (m) { + case STBI__MARKER_none: // no marker found + return stbi__err("expected marker","Corrupt JPEG"); + + case 0xDD: // DRI - specify restart interval + if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len","Corrupt JPEG"); + z->restart_interval = stbi__get16be(z->s); + return 1; + + case 0xDB: // DQT - define quantization table + L = stbi__get16be(z->s)-2; + while (L > 0) { + int q = stbi__get8(z->s); + int p = q >> 4, sixteen = (p != 0); + int t = q & 15,i; + if (p != 0 && p != 1) return stbi__err("bad DQT type","Corrupt JPEG"); + if (t > 3) return stbi__err("bad DQT table","Corrupt JPEG"); + + for (i=0; i < 64; ++i) + z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s)); + L -= (sixteen ? 129 : 65); + } + return L==0; + + case 0xC4: // DHT - define huffman table + L = stbi__get16be(z->s)-2; + while (L > 0) { + stbi_uc *v; + int sizes[16],i,n=0; + int q = stbi__get8(z->s); + int tc = q >> 4; + int th = q & 15; + if (tc > 1 || th > 3) return stbi__err("bad DHT header","Corrupt JPEG"); + for (i=0; i < 16; ++i) { + sizes[i] = stbi__get8(z->s); + n += sizes[i]; + } + L -= 17; + if (tc == 0) { + if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0; + v = z->huff_dc[th].values; + } else { + if (!stbi__build_huffman(z->huff_ac+th, sizes)) return 0; + v = z->huff_ac[th].values; + } + for (i=0; i < n; ++i) + v[i] = stbi__get8(z->s); + if (tc != 0) + stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th); + L -= n; + } + return L==0; + } + + // check for comment block or APP blocks + if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) { + L = stbi__get16be(z->s); + if (L < 2) { + if (m == 0xFE) + return stbi__err("bad COM len","Corrupt JPEG"); + else + return stbi__err("bad APP len","Corrupt JPEG"); + } + L -= 2; + + if (m == 0xE0 && L >= 5) { // JFIF APP0 segment + static const unsigned char tag[5] = {'J','F','I','F','\0'}; + int ok = 1; + int i; + for (i=0; i < 5; ++i) + if (stbi__get8(z->s) != tag[i]) + ok = 0; + L -= 5; + if (ok) + z->jfif = 1; + } else if (m == 0xEE && L >= 12) { // Adobe APP14 segment + static const unsigned char tag[6] = {'A','d','o','b','e','\0'}; + int ok = 1; + int i; + for (i=0; i < 6; ++i) + if (stbi__get8(z->s) != tag[i]) + ok = 0; + L -= 6; + if (ok) { + stbi__get8(z->s); // version + stbi__get16be(z->s); // flags0 + stbi__get16be(z->s); // flags1 + z->app14_color_transform = stbi__get8(z->s); // color transform + L -= 6; + } + } + + stbi__skip(z->s, L); + return 1; + } + + return stbi__err("unknown marker","Corrupt JPEG"); +} + +// after we see SOS +static int stbi__process_scan_header(stbi__jpeg *z) +{ + int i; + int Ls = stbi__get16be(z->s); + z->scan_n = stbi__get8(z->s); + if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n) return stbi__err("bad SOS component count","Corrupt JPEG"); + if (Ls != 6+2*z->scan_n) return stbi__err("bad SOS len","Corrupt JPEG"); + for (i=0; i < z->scan_n; ++i) { + int id = stbi__get8(z->s), which; + int q = stbi__get8(z->s); + for (which = 0; which < z->s->img_n; ++which) + if (z->img_comp[which].id == id) + break; + if (which == z->s->img_n) return 0; // no match + z->img_comp[which].hd = q >> 4; if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff","Corrupt JPEG"); + z->img_comp[which].ha = q & 15; if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff","Corrupt JPEG"); + z->order[i] = which; + } + + { + int aa; + z->spec_start = stbi__get8(z->s); + z->spec_end = stbi__get8(z->s); // should be 63, but might be 0 + aa = stbi__get8(z->s); + z->succ_high = (aa >> 4); + z->succ_low = (aa & 15); + if (z->progressive) { + if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13) + return stbi__err("bad SOS", "Corrupt JPEG"); + } else { + if (z->spec_start != 0) return stbi__err("bad SOS","Corrupt JPEG"); + if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS","Corrupt JPEG"); + z->spec_end = 63; + } + } + + return 1; +} + +static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why) +{ + int i; + for (i=0; i < ncomp; ++i) { + if (z->img_comp[i].raw_data) { + STBI_FREE(z->img_comp[i].raw_data); + z->img_comp[i].raw_data = NULL; + z->img_comp[i].data = NULL; + } + if (z->img_comp[i].raw_coeff) { + STBI_FREE(z->img_comp[i].raw_coeff); + z->img_comp[i].raw_coeff = 0; + z->img_comp[i].coeff = 0; + } + if (z->img_comp[i].linebuf) { + STBI_FREE(z->img_comp[i].linebuf); + z->img_comp[i].linebuf = NULL; + } + } + return why; +} + +static int stbi__process_frame_header(stbi__jpeg *z, int scan) +{ + stbi__context *s = z->s; + int Lf,p,i,q, h_max=1,v_max=1,c; + Lf = stbi__get16be(s); if (Lf < 11) return stbi__err("bad SOF len","Corrupt JPEG"); // JPEG + p = stbi__get8(s); if (p != 8) return stbi__err("only 8-bit","JPEG format not supported: 8-bit only"); // JPEG baseline + s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG + s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width","Corrupt JPEG"); // JPEG requires + c = stbi__get8(s); + if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count","Corrupt JPEG"); + s->img_n = c; + for (i=0; i < c; ++i) { + z->img_comp[i].data = NULL; + z->img_comp[i].linebuf = NULL; + } + + if (Lf != 8+3*s->img_n) return stbi__err("bad SOF len","Corrupt JPEG"); + + z->rgb = 0; + for (i=0; i < s->img_n; ++i) { + static const unsigned char rgb[3] = { 'R', 'G', 'B' }; + z->img_comp[i].id = stbi__get8(s); + if (s->img_n == 3 && z->img_comp[i].id == rgb[i]) + ++z->rgb; + q = stbi__get8(s); + z->img_comp[i].h = (q >> 4); if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H","Corrupt JPEG"); + z->img_comp[i].v = q & 15; if (!z->img_comp[i].v || z->img_comp[i].v > 4) return stbi__err("bad V","Corrupt JPEG"); + z->img_comp[i].tq = stbi__get8(s); if (z->img_comp[i].tq > 3) return stbi__err("bad TQ","Corrupt JPEG"); + } + + if (scan != STBI__SCAN_load) return 1; + + if (!stbi__mad3sizes_valid(s->img_x, s->img_y, s->img_n, 0)) return stbi__err("too large", "Image too large to decode"); + + for (i=0; i < s->img_n; ++i) { + if (z->img_comp[i].h > h_max) h_max = z->img_comp[i].h; + if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v; + } + + // compute interleaved mcu info + z->img_h_max = h_max; + z->img_v_max = v_max; + z->img_mcu_w = h_max * 8; + z->img_mcu_h = v_max * 8; + // these sizes can't be more than 17 bits + z->img_mcu_x = (s->img_x + z->img_mcu_w-1) / z->img_mcu_w; + z->img_mcu_y = (s->img_y + z->img_mcu_h-1) / z->img_mcu_h; + + for (i=0; i < s->img_n; ++i) { + // number of effective pixels (e.g. for non-interleaved MCU) + z->img_comp[i].x = (s->img_x * z->img_comp[i].h + h_max-1) / h_max; + z->img_comp[i].y = (s->img_y * z->img_comp[i].v + v_max-1) / v_max; + // to simplify generation, we'll allocate enough memory to decode + // the bogus oversized data from using interleaved MCUs and their + // big blocks (e.g. a 16x16 iMCU on an image of width 33); we won't + // discard the extra data until colorspace conversion + // + // img_mcu_x, img_mcu_y: <=17 bits; comp[i].h and .v are <=4 (checked earlier) + // so these muls can't overflow with 32-bit ints (which we require) + z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8; + z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8; + z->img_comp[i].coeff = 0; + z->img_comp[i].raw_coeff = 0; + z->img_comp[i].linebuf = NULL; + z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15); + if (z->img_comp[i].raw_data == NULL) + return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory")); + // align blocks for idct using mmx/sse + z->img_comp[i].data = (stbi_uc*) (((size_t) z->img_comp[i].raw_data + 15) & ~15); + if (z->progressive) { + // w2, h2 are multiples of 8 (see above) + z->img_comp[i].coeff_w = z->img_comp[i].w2 / 8; + z->img_comp[i].coeff_h = z->img_comp[i].h2 / 8; + z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15); + if (z->img_comp[i].raw_coeff == NULL) + return stbi__free_jpeg_components(z, i+1, stbi__err("outofmem", "Out of memory")); + z->img_comp[i].coeff = (short*) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15); + } + } + + return 1; +} + +// use comparisons since in some cases we handle more than one case (e.g. SOF) +#define stbi__DNL(x) ((x) == 0xdc) +#define stbi__SOI(x) ((x) == 0xd8) +#define stbi__EOI(x) ((x) == 0xd9) +#define stbi__SOF(x) ((x) == 0xc0 || (x) == 0xc1 || (x) == 0xc2) +#define stbi__SOS(x) ((x) == 0xda) + +#define stbi__SOF_progressive(x) ((x) == 0xc2) + +static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan) +{ + int m; + z->jfif = 0; + z->app14_color_transform = -1; // valid values are 0,1,2 + z->marker = STBI__MARKER_none; // initialize cached marker to empty + m = stbi__get_marker(z); + if (!stbi__SOI(m)) return stbi__err("no SOI","Corrupt JPEG"); + if (scan == STBI__SCAN_type) return 1; + m = stbi__get_marker(z); + while (!stbi__SOF(m)) { + if (!stbi__process_marker(z,m)) return 0; + m = stbi__get_marker(z); + while (m == STBI__MARKER_none) { + // some files have extra padding after their blocks, so ok, we'll scan + if (stbi__at_eof(z->s)) return stbi__err("no SOF", "Corrupt JPEG"); + m = stbi__get_marker(z); + } + } + z->progressive = stbi__SOF_progressive(m); + if (!stbi__process_frame_header(z, scan)) return 0; + return 1; +} + +// decode image to YCbCr format +static int stbi__decode_jpeg_image(stbi__jpeg *j) +{ + int m; + for (m = 0; m < 4; m++) { + j->img_comp[m].raw_data = NULL; + j->img_comp[m].raw_coeff = NULL; + } + j->restart_interval = 0; + if (!stbi__decode_jpeg_header(j, STBI__SCAN_load)) return 0; + m = stbi__get_marker(j); + while (!stbi__EOI(m)) { + if (stbi__SOS(m)) { + if (!stbi__process_scan_header(j)) return 0; + if (!stbi__parse_entropy_coded_data(j)) return 0; + if (j->marker == STBI__MARKER_none ) { + // handle 0s at the end of image data from IP Kamera 9060 + while (!stbi__at_eof(j->s)) { + int x = stbi__get8(j->s); + if (x == 255) { + j->marker = stbi__get8(j->s); + break; + } + } + // if we reach eof without hitting a marker, stbi__get_marker() below will fail and we'll eventually return 0 + } + } else if (stbi__DNL(m)) { + int Ld = stbi__get16be(j->s); + stbi__uint32 NL = stbi__get16be(j->s); + if (Ld != 4) return stbi__err("bad DNL len", "Corrupt JPEG"); + if (NL != j->s->img_y) return stbi__err("bad DNL height", "Corrupt JPEG"); + } else { + if (!stbi__process_marker(j, m)) return 0; + } + m = stbi__get_marker(j); + } + if (j->progressive) + stbi__jpeg_finish(j); + return 1; +} + +// static jfif-centered resampling (across block boundaries) + +typedef stbi_uc *(*resample_row_func)(stbi_uc *out, stbi_uc *in0, stbi_uc *in1, + int w, int hs); + +#define stbi__div4(x) ((stbi_uc) ((x) >> 2)) + +static stbi_uc *resample_row_1(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + STBI_NOTUSED(out); + STBI_NOTUSED(in_far); + STBI_NOTUSED(w); + STBI_NOTUSED(hs); + return in_near; +} + +static stbi_uc* stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate two samples vertically for every one in input + int i; + STBI_NOTUSED(hs); + for (i=0; i < w; ++i) + out[i] = stbi__div4(3*in_near[i] + in_far[i] + 2); + return out; +} + +static stbi_uc* stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate two samples horizontally for every one in input + int i; + stbi_uc *input = in_near; + + if (w == 1) { + // if only one sample, can't do any interpolation + out[0] = out[1] = input[0]; + return out; + } + + out[0] = input[0]; + out[1] = stbi__div4(input[0]*3 + input[1] + 2); + for (i=1; i < w-1; ++i) { + int n = 3*input[i]+2; + out[i*2+0] = stbi__div4(n+input[i-1]); + out[i*2+1] = stbi__div4(n+input[i+1]); + } + out[i*2+0] = stbi__div4(input[w-2]*3 + input[w-1] + 2); + out[i*2+1] = input[w-1]; + + STBI_NOTUSED(in_far); + STBI_NOTUSED(hs); + + return out; +} + +#define stbi__div16(x) ((stbi_uc) ((x) >> 4)) + +static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate 2x2 samples for every one in input + int i,t0,t1; + if (w == 1) { + out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2); + return out; + } + + t1 = 3*in_near[0] + in_far[0]; + out[0] = stbi__div4(t1+2); + for (i=1; i < w; ++i) { + t0 = t1; + t1 = 3*in_near[i]+in_far[i]; + out[i*2-1] = stbi__div16(3*t0 + t1 + 8); + out[i*2 ] = stbi__div16(3*t1 + t0 + 8); + } + out[w*2-1] = stbi__div4(t1+2); + + STBI_NOTUSED(hs); + + return out; +} + +#if defined(STBI_SSE2) || defined(STBI_NEON) +static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // need to generate 2x2 samples for every one in input + int i=0,t0,t1; + + if (w == 1) { + out[0] = out[1] = stbi__div4(3*in_near[0] + in_far[0] + 2); + return out; + } + + t1 = 3*in_near[0] + in_far[0]; + // process groups of 8 pixels for as long as we can. + // note we can't handle the last pixel in a row in this loop + // because we need to handle the filter boundary conditions. + for (; i < ((w-1) & ~7); i += 8) { +#if defined(STBI_SSE2) + // load and perform the vertical filtering pass + // this uses 3*x + y = 4*x + (y - x) + __m128i zero = _mm_setzero_si128(); + __m128i farb = _mm_loadl_epi64((__m128i *) (in_far + i)); + __m128i nearb = _mm_loadl_epi64((__m128i *) (in_near + i)); + __m128i farw = _mm_unpacklo_epi8(farb, zero); + __m128i nearw = _mm_unpacklo_epi8(nearb, zero); + __m128i diff = _mm_sub_epi16(farw, nearw); + __m128i nears = _mm_slli_epi16(nearw, 2); + __m128i curr = _mm_add_epi16(nears, diff); // current row + + // horizontal filter works the same based on shifted vers of current + // row. "prev" is current row shifted right by 1 pixel; we need to + // insert the previous pixel value (from t1). + // "next" is current row shifted left by 1 pixel, with first pixel + // of next block of 8 pixels added in. + __m128i prv0 = _mm_slli_si128(curr, 2); + __m128i nxt0 = _mm_srli_si128(curr, 2); + __m128i prev = _mm_insert_epi16(prv0, t1, 0); + __m128i next = _mm_insert_epi16(nxt0, 3*in_near[i+8] + in_far[i+8], 7); + + // horizontal filter, polyphase implementation since it's convenient: + // even pixels = 3*cur + prev = cur*4 + (prev - cur) + // odd pixels = 3*cur + next = cur*4 + (next - cur) + // note the shared term. + __m128i bias = _mm_set1_epi16(8); + __m128i curs = _mm_slli_epi16(curr, 2); + __m128i prvd = _mm_sub_epi16(prev, curr); + __m128i nxtd = _mm_sub_epi16(next, curr); + __m128i curb = _mm_add_epi16(curs, bias); + __m128i even = _mm_add_epi16(prvd, curb); + __m128i odd = _mm_add_epi16(nxtd, curb); + + // interleave even and odd pixels, then undo scaling. + __m128i int0 = _mm_unpacklo_epi16(even, odd); + __m128i int1 = _mm_unpackhi_epi16(even, odd); + __m128i de0 = _mm_srli_epi16(int0, 4); + __m128i de1 = _mm_srli_epi16(int1, 4); + + // pack and write output + __m128i outv = _mm_packus_epi16(de0, de1); + _mm_storeu_si128((__m128i *) (out + i*2), outv); +#elif defined(STBI_NEON) + // load and perform the vertical filtering pass + // this uses 3*x + y = 4*x + (y - x) + uint8x8_t farb = vld1_u8(in_far + i); + uint8x8_t nearb = vld1_u8(in_near + i); + int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(farb, nearb)); + int16x8_t nears = vreinterpretq_s16_u16(vshll_n_u8(nearb, 2)); + int16x8_t curr = vaddq_s16(nears, diff); // current row + + // horizontal filter works the same based on shifted vers of current + // row. "prev" is current row shifted right by 1 pixel; we need to + // insert the previous pixel value (from t1). + // "next" is current row shifted left by 1 pixel, with first pixel + // of next block of 8 pixels added in. + int16x8_t prv0 = vextq_s16(curr, curr, 7); + int16x8_t nxt0 = vextq_s16(curr, curr, 1); + int16x8_t prev = vsetq_lane_s16(t1, prv0, 0); + int16x8_t next = vsetq_lane_s16(3*in_near[i+8] + in_far[i+8], nxt0, 7); + + // horizontal filter, polyphase implementation since it's convenient: + // even pixels = 3*cur + prev = cur*4 + (prev - cur) + // odd pixels = 3*cur + next = cur*4 + (next - cur) + // note the shared term. + int16x8_t curs = vshlq_n_s16(curr, 2); + int16x8_t prvd = vsubq_s16(prev, curr); + int16x8_t nxtd = vsubq_s16(next, curr); + int16x8_t even = vaddq_s16(curs, prvd); + int16x8_t odd = vaddq_s16(curs, nxtd); + + // undo scaling and round, then store with even/odd phases interleaved + uint8x8x2_t o; + o.val[0] = vqrshrun_n_s16(even, 4); + o.val[1] = vqrshrun_n_s16(odd, 4); + vst2_u8(out + i*2, o); +#endif + + // "previous" value for next iter + t1 = 3*in_near[i+7] + in_far[i+7]; + } + + t0 = t1; + t1 = 3*in_near[i] + in_far[i]; + out[i*2] = stbi__div16(3*t1 + t0 + 8); + + for (++i; i < w; ++i) { + t0 = t1; + t1 = 3*in_near[i]+in_far[i]; + out[i*2-1] = stbi__div16(3*t0 + t1 + 8); + out[i*2 ] = stbi__div16(3*t1 + t0 + 8); + } + out[w*2-1] = stbi__div4(t1+2); + + STBI_NOTUSED(hs); + + return out; +} +#endif + +static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs) +{ + // resample with nearest-neighbor + int i,j; + STBI_NOTUSED(in_far); + for (i=0; i < w; ++i) + for (j=0; j < hs; ++j) + out[i*hs+j] = in_near[i]; + return out; +} + +// this is a reduced-precision calculation of YCbCr-to-RGB introduced +// to make sure the code produces the same results in both SIMD and scalar +#define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8) +static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step) +{ + int i; + for (i=0; i < count; ++i) { + int y_fixed = (y[i] << 20) + (1<<19); // rounding + int r,g,b; + int cr = pcr[i] - 128; + int cb = pcb[i] - 128; + r = y_fixed + cr* stbi__float2fixed(1.40200f); + g = y_fixed + (cr*-stbi__float2fixed(0.71414f)) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000); + b = y_fixed + cb* stbi__float2fixed(1.77200f); + r >>= 20; + g >>= 20; + b >>= 20; + if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } + if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } + if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } + out[0] = (stbi_uc)r; + out[1] = (stbi_uc)g; + out[2] = (stbi_uc)b; + out[3] = 255; + out += step; + } +} + +#if defined(STBI_SSE2) || defined(STBI_NEON) +static void stbi__YCbCr_to_RGB_simd(stbi_uc *out, stbi_uc const *y, stbi_uc const *pcb, stbi_uc const *pcr, int count, int step) +{ + int i = 0; + +#ifdef STBI_SSE2 + // step == 3 is pretty ugly on the final interleave, and i'm not convinced + // it's useful in practice (you wouldn't use it for textures, for example). + // so just accelerate step == 4 case. + if (step == 4) { + // this is a fairly straightforward implementation and not super-optimized. + __m128i signflip = _mm_set1_epi8(-0x80); + __m128i cr_const0 = _mm_set1_epi16( (short) ( 1.40200f*4096.0f+0.5f)); + __m128i cr_const1 = _mm_set1_epi16( - (short) ( 0.71414f*4096.0f+0.5f)); + __m128i cb_const0 = _mm_set1_epi16( - (short) ( 0.34414f*4096.0f+0.5f)); + __m128i cb_const1 = _mm_set1_epi16( (short) ( 1.77200f*4096.0f+0.5f)); + __m128i y_bias = _mm_set1_epi8((char) (unsigned char) 128); + __m128i xw = _mm_set1_epi16(255); // alpha channel + + for (; i+7 < count; i += 8) { + // load + __m128i y_bytes = _mm_loadl_epi64((__m128i *) (y+i)); + __m128i cr_bytes = _mm_loadl_epi64((__m128i *) (pcr+i)); + __m128i cb_bytes = _mm_loadl_epi64((__m128i *) (pcb+i)); + __m128i cr_biased = _mm_xor_si128(cr_bytes, signflip); // -128 + __m128i cb_biased = _mm_xor_si128(cb_bytes, signflip); // -128 + + // unpack to short (and left-shift cr, cb by 8) + __m128i yw = _mm_unpacklo_epi8(y_bias, y_bytes); + __m128i crw = _mm_unpacklo_epi8(_mm_setzero_si128(), cr_biased); + __m128i cbw = _mm_unpacklo_epi8(_mm_setzero_si128(), cb_biased); + + // color transform + __m128i yws = _mm_srli_epi16(yw, 4); + __m128i cr0 = _mm_mulhi_epi16(cr_const0, crw); + __m128i cb0 = _mm_mulhi_epi16(cb_const0, cbw); + __m128i cb1 = _mm_mulhi_epi16(cbw, cb_const1); + __m128i cr1 = _mm_mulhi_epi16(crw, cr_const1); + __m128i rws = _mm_add_epi16(cr0, yws); + __m128i gwt = _mm_add_epi16(cb0, yws); + __m128i bws = _mm_add_epi16(yws, cb1); + __m128i gws = _mm_add_epi16(gwt, cr1); + + // descale + __m128i rw = _mm_srai_epi16(rws, 4); + __m128i bw = _mm_srai_epi16(bws, 4); + __m128i gw = _mm_srai_epi16(gws, 4); + + // back to byte, set up for transpose + __m128i brb = _mm_packus_epi16(rw, bw); + __m128i gxb = _mm_packus_epi16(gw, xw); + + // transpose to interleave channels + __m128i t0 = _mm_unpacklo_epi8(brb, gxb); + __m128i t1 = _mm_unpackhi_epi8(brb, gxb); + __m128i o0 = _mm_unpacklo_epi16(t0, t1); + __m128i o1 = _mm_unpackhi_epi16(t0, t1); + + // store + _mm_storeu_si128((__m128i *) (out + 0), o0); + _mm_storeu_si128((__m128i *) (out + 16), o1); + out += 32; + } + } +#endif + +#ifdef STBI_NEON + // in this version, step=3 support would be easy to add. but is there demand? + if (step == 4) { + // this is a fairly straightforward implementation and not super-optimized. + uint8x8_t signflip = vdup_n_u8(0x80); + int16x8_t cr_const0 = vdupq_n_s16( (short) ( 1.40200f*4096.0f+0.5f)); + int16x8_t cr_const1 = vdupq_n_s16( - (short) ( 0.71414f*4096.0f+0.5f)); + int16x8_t cb_const0 = vdupq_n_s16( - (short) ( 0.34414f*4096.0f+0.5f)); + int16x8_t cb_const1 = vdupq_n_s16( (short) ( 1.77200f*4096.0f+0.5f)); + + for (; i+7 < count; i += 8) { + // load + uint8x8_t y_bytes = vld1_u8(y + i); + uint8x8_t cr_bytes = vld1_u8(pcr + i); + uint8x8_t cb_bytes = vld1_u8(pcb + i); + int8x8_t cr_biased = vreinterpret_s8_u8(vsub_u8(cr_bytes, signflip)); + int8x8_t cb_biased = vreinterpret_s8_u8(vsub_u8(cb_bytes, signflip)); + + // expand to s16 + int16x8_t yws = vreinterpretq_s16_u16(vshll_n_u8(y_bytes, 4)); + int16x8_t crw = vshll_n_s8(cr_biased, 7); + int16x8_t cbw = vshll_n_s8(cb_biased, 7); + + // color transform + int16x8_t cr0 = vqdmulhq_s16(crw, cr_const0); + int16x8_t cb0 = vqdmulhq_s16(cbw, cb_const0); + int16x8_t cr1 = vqdmulhq_s16(crw, cr_const1); + int16x8_t cb1 = vqdmulhq_s16(cbw, cb_const1); + int16x8_t rws = vaddq_s16(yws, cr0); + int16x8_t gws = vaddq_s16(vaddq_s16(yws, cb0), cr1); + int16x8_t bws = vaddq_s16(yws, cb1); + + // undo scaling, round, convert to byte + uint8x8x4_t o; + o.val[0] = vqrshrun_n_s16(rws, 4); + o.val[1] = vqrshrun_n_s16(gws, 4); + o.val[2] = vqrshrun_n_s16(bws, 4); + o.val[3] = vdup_n_u8(255); + + // store, interleaving r/g/b/a + vst4_u8(out, o); + out += 8*4; + } + } +#endif + + for (; i < count; ++i) { + int y_fixed = (y[i] << 20) + (1<<19); // rounding + int r,g,b; + int cr = pcr[i] - 128; + int cb = pcb[i] - 128; + r = y_fixed + cr* stbi__float2fixed(1.40200f); + g = y_fixed + cr*-stbi__float2fixed(0.71414f) + ((cb*-stbi__float2fixed(0.34414f)) & 0xffff0000); + b = y_fixed + cb* stbi__float2fixed(1.77200f); + r >>= 20; + g >>= 20; + b >>= 20; + if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; } + if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; } + if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; } + out[0] = (stbi_uc)r; + out[1] = (stbi_uc)g; + out[2] = (stbi_uc)b; + out[3] = 255; + out += step; + } +} +#endif + +// set up the kernels +static void stbi__setup_jpeg(stbi__jpeg *j) +{ + j->idct_block_kernel = stbi__idct_block; + j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_row; + j->resample_row_hv_2_kernel = stbi__resample_row_hv_2; + +#ifdef STBI_SSE2 + if (stbi__sse2_available()) { + j->idct_block_kernel = stbi__idct_simd; + j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd; + j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd; + } +#endif + +#ifdef STBI_NEON + j->idct_block_kernel = stbi__idct_simd; + j->YCbCr_to_RGB_kernel = stbi__YCbCr_to_RGB_simd; + j->resample_row_hv_2_kernel = stbi__resample_row_hv_2_simd; +#endif +} + +// clean up the temporary component buffers +static void stbi__cleanup_jpeg(stbi__jpeg *j) +{ + stbi__free_jpeg_components(j, j->s->img_n, 0); +} + +typedef struct +{ + resample_row_func resample; + stbi_uc *line0,*line1; + int hs,vs; // expansion factor in each axis + int w_lores; // horizontal pixels pre-expansion + int ystep; // how far through vertical expansion we are + int ypos; // which pre-expansion row we're on +} stbi__resample; + +// fast 0..255 * 0..255 => 0..255 rounded multiplication +static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) +{ + unsigned int t = x*y + 128; + return (stbi_uc) ((t + (t >>8)) >> 8); +} + +static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp) +{ + int n, decode_n, is_rgb; + z->s->img_n = 0; // make stbi__cleanup_jpeg safe + + // validate req_comp + if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); + + // load a jpeg image from whichever source, but leave in YCbCr format + if (!stbi__decode_jpeg_image(z)) { stbi__cleanup_jpeg(z); return NULL; } + + // determine actual number of components to generate + n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1; + + is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif)); + + if (z->s->img_n == 3 && n < 3 && !is_rgb) + decode_n = 1; + else + decode_n = z->s->img_n; + + // resample and color-convert + { + int k; + unsigned int i,j; + stbi_uc *output; + stbi_uc *coutput[4]; + + stbi__resample res_comp[4]; + + for (k=0; k < decode_n; ++k) { + stbi__resample *r = &res_comp[k]; + + // allocate line buffer big enough for upsampling off the edges + // with upsample factor of 4 + z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3); + if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); } + + r->hs = z->img_h_max / z->img_comp[k].h; + r->vs = z->img_v_max / z->img_comp[k].v; + r->ystep = r->vs >> 1; + r->w_lores = (z->s->img_x + r->hs-1) / r->hs; + r->ypos = 0; + r->line0 = r->line1 = z->img_comp[k].data; + + if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1; + else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2; + else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2; + else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel; + else r->resample = stbi__resample_row_generic; + } + + // can't error after this so, this is safe + output = (stbi_uc *) stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1); + if (!output) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); } + + // now go ahead and resample + for (j=0; j < z->s->img_y; ++j) { + stbi_uc *out = output + n * z->s->img_x * j; + for (k=0; k < decode_n; ++k) { + stbi__resample *r = &res_comp[k]; + int y_bot = r->ystep >= (r->vs >> 1); + coutput[k] = r->resample(z->img_comp[k].linebuf, + y_bot ? r->line1 : r->line0, + y_bot ? r->line0 : r->line1, + r->w_lores, r->hs); + if (++r->ystep >= r->vs) { + r->ystep = 0; + r->line0 = r->line1; + if (++r->ypos < z->img_comp[k].y) + r->line1 += z->img_comp[k].w2; + } + } + if (n >= 3) { + stbi_uc *y = coutput[0]; + if (z->s->img_n == 3) { + if (is_rgb) { + for (i=0; i < z->s->img_x; ++i) { + out[0] = y[i]; + out[1] = coutput[1][i]; + out[2] = coutput[2][i]; + out[3] = 255; + out += n; + } + } else { + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + } + } else if (z->s->img_n == 4) { + if (z->app14_color_transform == 0) { // CMYK + for (i=0; i < z->s->img_x; ++i) { + stbi_uc m = coutput[3][i]; + out[0] = stbi__blinn_8x8(coutput[0][i], m); + out[1] = stbi__blinn_8x8(coutput[1][i], m); + out[2] = stbi__blinn_8x8(coutput[2][i], m); + out[3] = 255; + out += n; + } + } else if (z->app14_color_transform == 2) { // YCCK + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + for (i=0; i < z->s->img_x; ++i) { + stbi_uc m = coutput[3][i]; + out[0] = stbi__blinn_8x8(255 - out[0], m); + out[1] = stbi__blinn_8x8(255 - out[1], m); + out[2] = stbi__blinn_8x8(255 - out[2], m); + out += n; + } + } else { // YCbCr + alpha? Ignore the fourth channel for now + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + } + } else + for (i=0; i < z->s->img_x; ++i) { + out[0] = out[1] = out[2] = y[i]; + out[3] = 255; // not used if n==3 + out += n; + } + } else { + if (is_rgb) { + if (n == 1) + for (i=0; i < z->s->img_x; ++i) + *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); + else { + for (i=0; i < z->s->img_x; ++i, out += 2) { + out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); + out[1] = 255; + } + } + } else if (z->s->img_n == 4 && z->app14_color_transform == 0) { + for (i=0; i < z->s->img_x; ++i) { + stbi_uc m = coutput[3][i]; + stbi_uc r = stbi__blinn_8x8(coutput[0][i], m); + stbi_uc g = stbi__blinn_8x8(coutput[1][i], m); + stbi_uc b = stbi__blinn_8x8(coutput[2][i], m); + out[0] = stbi__compute_y(r, g, b); + out[1] = 255; + out += n; + } + } else if (z->s->img_n == 4 && z->app14_color_transform == 2) { + for (i=0; i < z->s->img_x; ++i) { + out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]); + out[1] = 255; + out += n; + } + } else { + stbi_uc *y = coutput[0]; + if (n == 1) + for (i=0; i < z->s->img_x; ++i) out[i] = y[i]; + else + for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255; + } + } + } + stbi__cleanup_jpeg(z); + *out_x = z->s->img_x; + *out_y = z->s->img_y; + if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output + return output; + } +} + +static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + unsigned char* result; + stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg)); + STBI_NOTUSED(ri); + j->s = s; + stbi__setup_jpeg(j); + result = load_jpeg_image(j, x,y,comp,req_comp); + STBI_FREE(j); + return result; +} + +static int stbi__jpeg_test(stbi__context *s) +{ + int r; + stbi__jpeg* j = (stbi__jpeg*)stbi__malloc(sizeof(stbi__jpeg)); + j->s = s; + stbi__setup_jpeg(j); + r = stbi__decode_jpeg_header(j, STBI__SCAN_type); + stbi__rewind(s); + STBI_FREE(j); + return r; +} + +static int stbi__jpeg_info_raw(stbi__jpeg *j, int *x, int *y, int *comp) +{ + if (!stbi__decode_jpeg_header(j, STBI__SCAN_header)) { + stbi__rewind( j->s ); + return 0; + } + if (x) *x = j->s->img_x; + if (y) *y = j->s->img_y; + if (comp) *comp = j->s->img_n >= 3 ? 3 : 1; + return 1; +} + +static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp) +{ + int result; + stbi__jpeg* j = (stbi__jpeg*) (stbi__malloc(sizeof(stbi__jpeg))); + j->s = s; + result = stbi__jpeg_info_raw(j, x, y, comp); + STBI_FREE(j); + return result; +} +#endif + +// public domain zlib decode v0.2 Sean Barrett 2006-11-18 +// simple implementation +// - all input must be provided in an upfront buffer +// - all output is written to a single output buffer (can malloc/realloc) +// performance +// - fast huffman + +#ifndef STBI_NO_ZLIB + +// fast-way is faster to check than jpeg huffman, but slow way is slower +#define STBI__ZFAST_BITS 9 // accelerate all cases in default tables +#define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1) + +// zlib-style huffman encoding +// (jpegs packs from left, zlib from right, so can't share code) +typedef struct +{ + stbi__uint16 fast[1 << STBI__ZFAST_BITS]; + stbi__uint16 firstcode[16]; + int maxcode[17]; + stbi__uint16 firstsymbol[16]; + stbi_uc size[288]; + stbi__uint16 value[288]; +} stbi__zhuffman; + +stbi_inline static int stbi__bitreverse16(int n) +{ + n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); + n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2); + n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4); + n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8); + return n; +} + +stbi_inline static int stbi__bit_reverse(int v, int bits) +{ + STBI_ASSERT(bits <= 16); + // to bit reverse n bits, reverse 16 and shift + // e.g. 11 bits, bit reverse and shift away 5 + return stbi__bitreverse16(v) >> (16-bits); +} + +static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num) +{ + int i,k=0; + int code, next_code[16], sizes[17]; + + // DEFLATE spec for generating codes + memset(sizes, 0, sizeof(sizes)); + memset(z->fast, 0, sizeof(z->fast)); + for (i=0; i < num; ++i) + ++sizes[sizelist[i]]; + sizes[0] = 0; + for (i=1; i < 16; ++i) + if (sizes[i] > (1 << i)) + return stbi__err("bad sizes", "Corrupt PNG"); + code = 0; + for (i=1; i < 16; ++i) { + next_code[i] = code; + z->firstcode[i] = (stbi__uint16) code; + z->firstsymbol[i] = (stbi__uint16) k; + code = (code + sizes[i]); + if (sizes[i]) + if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG"); + z->maxcode[i] = code << (16-i); // preshift for inner loop + code <<= 1; + k += sizes[i]; + } + z->maxcode[16] = 0x10000; // sentinel + for (i=0; i < num; ++i) { + int s = sizelist[i]; + if (s) { + int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s]; + stbi__uint16 fastv = (stbi__uint16) ((s << 9) | i); + z->size [c] = (stbi_uc ) s; + z->value[c] = (stbi__uint16) i; + if (s <= STBI__ZFAST_BITS) { + int j = stbi__bit_reverse(next_code[s],s); + while (j < (1 << STBI__ZFAST_BITS)) { + z->fast[j] = fastv; + j += (1 << s); + } + } + ++next_code[s]; + } + } + return 1; +} + +// zlib-from-memory implementation for PNG reading +// because PNG allows splitting the zlib stream arbitrarily, +// and it's annoying structurally to have PNG call ZLIB call PNG, +// we require PNG read all the IDATs and combine them into a single +// memory buffer + +typedef struct +{ + stbi_uc *zbuffer, *zbuffer_end; + int num_bits; + stbi__uint32 code_buffer; + + char *zout; + char *zout_start; + char *zout_end; + int z_expandable; + + stbi__zhuffman z_length, z_distance; +} stbi__zbuf; + +stbi_inline static stbi_uc stbi__zget8(stbi__zbuf *z) +{ + if (z->zbuffer >= z->zbuffer_end) return 0; + return *z->zbuffer++; +} + +static void stbi__fill_bits(stbi__zbuf *z) +{ + do { + STBI_ASSERT(z->code_buffer < (1U << z->num_bits)); + z->code_buffer |= (unsigned int) stbi__zget8(z) << z->num_bits; + z->num_bits += 8; + } while (z->num_bits <= 24); +} + +stbi_inline static unsigned int stbi__zreceive(stbi__zbuf *z, int n) +{ + unsigned int k; + if (z->num_bits < n) stbi__fill_bits(z); + k = z->code_buffer & ((1 << n) - 1); + z->code_buffer >>= n; + z->num_bits -= n; + return k; +} + +static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z) +{ + int b,s,k; + // not resolved by fast table, so compute it the slow way + // use jpeg approach, which requires MSbits at top + k = stbi__bit_reverse(a->code_buffer, 16); + for (s=STBI__ZFAST_BITS+1; ; ++s) + if (k < z->maxcode[s]) + break; + if (s == 16) return -1; // invalid code! + // code size is s, so: + b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; + STBI_ASSERT(z->size[b] == s); + a->code_buffer >>= s; + a->num_bits -= s; + return z->value[b]; +} + +stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) +{ + int b,s; + if (a->num_bits < 16) stbi__fill_bits(a); + b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; + if (b) { + s = b >> 9; + a->code_buffer >>= s; + a->num_bits -= s; + return b & 511; + } + return stbi__zhuffman_decode_slowpath(a, z); +} + +static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes +{ + char *q; + int cur, limit, old_limit; + z->zout = zout; + if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG"); + cur = (int) (z->zout - z->zout_start); + limit = old_limit = (int) (z->zout_end - z->zout_start); + while (cur + n > limit) + limit *= 2; + q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); + STBI_NOTUSED(old_limit); + if (q == NULL) return stbi__err("outofmem", "Out of memory"); + z->zout_start = q; + z->zout = q + cur; + z->zout_end = q + limit; + return 1; +} + +static const int stbi__zlength_base[31] = { + 3,4,5,6,7,8,9,10,11,13, + 15,17,19,23,27,31,35,43,51,59, + 67,83,99,115,131,163,195,227,258,0,0 }; + +static const int stbi__zlength_extra[31]= +{ 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; + +static const int stbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, +257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; + +static const int stbi__zdist_extra[32] = +{ 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +static int stbi__parse_huffman_block(stbi__zbuf *a) +{ + char *zout = a->zout; + for(;;) { + int z = stbi__zhuffman_decode(a, &a->z_length); + if (z < 256) { + if (z < 0) return stbi__err("bad huffman code","Corrupt PNG"); // error in huffman codes + if (zout >= a->zout_end) { + if (!stbi__zexpand(a, zout, 1)) return 0; + zout = a->zout; + } + *zout++ = (char) z; + } else { + stbi_uc *p; + int len,dist; + if (z == 256) { + a->zout = zout; + return 1; + } + z -= 257; + len = stbi__zlength_base[z]; + if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); + z = stbi__zhuffman_decode(a, &a->z_distance); + if (z < 0) return stbi__err("bad huffman code","Corrupt PNG"); + dist = stbi__zdist_base[z]; + if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); + if (zout - a->zout_start < dist) return stbi__err("bad dist","Corrupt PNG"); + if (zout + len > a->zout_end) { + if (!stbi__zexpand(a, zout, len)) return 0; + zout = a->zout; + } + p = (stbi_uc *) (zout - dist); + if (dist == 1) { // run of one byte; common in images. + stbi_uc v = *p; + if (len) { do *zout++ = v; while (--len); } + } else { + if (len) { do *zout++ = *p++; while (--len); } + } + } + } +} + +static int stbi__compute_huffman_codes(stbi__zbuf *a) +{ + static const stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; + stbi__zhuffman z_codelength; + stbi_uc lencodes[286+32+137];//padding for maximum single op + stbi_uc codelength_sizes[19]; + int i,n; + + int hlit = stbi__zreceive(a,5) + 257; + int hdist = stbi__zreceive(a,5) + 1; + int hclen = stbi__zreceive(a,4) + 4; + int ntot = hlit + hdist; + + memset(codelength_sizes, 0, sizeof(codelength_sizes)); + for (i=0; i < hclen; ++i) { + int s = stbi__zreceive(a,3); + codelength_sizes[length_dezigzag[i]] = (stbi_uc) s; + } + if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0; + + n = 0; + while (n < ntot) { + int c = stbi__zhuffman_decode(a, &z_codelength); + if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG"); + if (c < 16) + lencodes[n++] = (stbi_uc) c; + else { + stbi_uc fill = 0; + if (c == 16) { + c = stbi__zreceive(a,2)+3; + if (n == 0) return stbi__err("bad codelengths", "Corrupt PNG"); + fill = lencodes[n-1]; + } else if (c == 17) + c = stbi__zreceive(a,3)+3; + else { + STBI_ASSERT(c == 18); + c = stbi__zreceive(a,7)+11; + } + if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG"); + memset(lencodes+n, fill, c); + n += c; + } + } + if (n != ntot) return stbi__err("bad codelengths","Corrupt PNG"); + if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0; + if (!stbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0; + return 1; +} + +static int stbi__parse_uncompressed_block(stbi__zbuf *a) +{ + stbi_uc header[4]; + int len,nlen,k; + if (a->num_bits & 7) + stbi__zreceive(a, a->num_bits & 7); // discard + // drain the bit-packed data into header + k = 0; + while (a->num_bits > 0) { + header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check + a->code_buffer >>= 8; + a->num_bits -= 8; + } + STBI_ASSERT(a->num_bits == 0); + // now fill header the normal way + while (k < 4) + header[k++] = stbi__zget8(a); + len = header[1] * 256 + header[0]; + nlen = header[3] * 256 + header[2]; + if (nlen != (len ^ 0xffff)) return stbi__err("zlib corrupt","Corrupt PNG"); + if (a->zbuffer + len > a->zbuffer_end) return stbi__err("read past buffer","Corrupt PNG"); + if (a->zout + len > a->zout_end) + if (!stbi__zexpand(a, a->zout, len)) return 0; + memcpy(a->zout, a->zbuffer, len); + a->zbuffer += len; + a->zout += len; + return 1; +} + +static int stbi__parse_zlib_header(stbi__zbuf *a) +{ + int cmf = stbi__zget8(a); + int cm = cmf & 15; + /* int cinfo = cmf >> 4; */ + int flg = stbi__zget8(a); + if ((cmf*256+flg) % 31 != 0) return stbi__err("bad zlib header","Corrupt PNG"); // zlib spec + if (flg & 32) return stbi__err("no preset dict","Corrupt PNG"); // preset dictionary not allowed in png + if (cm != 8) return stbi__err("bad compression","Corrupt PNG"); // DEFLATE required for png + // window = 1 << (8 + cinfo)... but who cares, we fully buffer output + return 1; +} + +static const stbi_uc stbi__zdefault_length[288] = +{ + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8 +}; +static const stbi_uc stbi__zdefault_distance[32] = +{ + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 +}; +/* +Init algorithm: +{ + int i; // use <= to match clearly with spec + for (i=0; i <= 143; ++i) stbi__zdefault_length[i] = 8; + for ( ; i <= 255; ++i) stbi__zdefault_length[i] = 9; + for ( ; i <= 279; ++i) stbi__zdefault_length[i] = 7; + for ( ; i <= 287; ++i) stbi__zdefault_length[i] = 8; + + for (i=0; i <= 31; ++i) stbi__zdefault_distance[i] = 5; +} +*/ + +static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) +{ + int final, type; + if (parse_header) + if (!stbi__parse_zlib_header(a)) return 0; + a->num_bits = 0; + a->code_buffer = 0; + do { + final = stbi__zreceive(a,1); + type = stbi__zreceive(a,2); + if (type == 0) { + if (!stbi__parse_uncompressed_block(a)) return 0; + } else if (type == 3) { + return 0; + } else { + if (type == 1) { + // use fixed code lengths + if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , 288)) return 0; + if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0; + } else { + if (!stbi__compute_huffman_codes(a)) return 0; + } + if (!stbi__parse_huffman_block(a)) return 0; + } + } while (!final); + return 1; +} + +static int stbi__do_zlib(stbi__zbuf *a, char *obuf, int olen, int exp, int parse_header) +{ + a->zout_start = obuf; + a->zout = obuf; + a->zout_end = obuf + olen; + a->z_expandable = exp; + + return stbi__parse_zlib(a, parse_header); +} + +STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen) +{ + stbi__zbuf a; + char *p = (char *) stbi__malloc(initial_size); + if (p == NULL) return NULL; + a.zbuffer = (stbi_uc *) buffer; + a.zbuffer_end = (stbi_uc *) buffer + len; + if (stbi__do_zlib(&a, p, initial_size, 1, 1)) { + if (outlen) *outlen = (int) (a.zout - a.zout_start); + return a.zout_start; + } else { + STBI_FREE(a.zout_start); + return NULL; + } +} + +STBIDEF char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen) +{ + return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); +} + +STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header) +{ + stbi__zbuf a; + char *p = (char *) stbi__malloc(initial_size); + if (p == NULL) return NULL; + a.zbuffer = (stbi_uc *) buffer; + a.zbuffer_end = (stbi_uc *) buffer + len; + if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) { + if (outlen) *outlen = (int) (a.zout - a.zout_start); + return a.zout_start; + } else { + STBI_FREE(a.zout_start); + return NULL; + } +} + +STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen) +{ + stbi__zbuf a; + a.zbuffer = (stbi_uc *) ibuffer; + a.zbuffer_end = (stbi_uc *) ibuffer + ilen; + if (stbi__do_zlib(&a, obuffer, olen, 0, 1)) + return (int) (a.zout - a.zout_start); + else + return -1; +} + +STBIDEF char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen) +{ + stbi__zbuf a; + char *p = (char *) stbi__malloc(16384); + if (p == NULL) return NULL; + a.zbuffer = (stbi_uc *) buffer; + a.zbuffer_end = (stbi_uc *) buffer+len; + if (stbi__do_zlib(&a, p, 16384, 1, 0)) { + if (outlen) *outlen = (int) (a.zout - a.zout_start); + return a.zout_start; + } else { + STBI_FREE(a.zout_start); + return NULL; + } +} + +STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen) +{ + stbi__zbuf a; + a.zbuffer = (stbi_uc *) ibuffer; + a.zbuffer_end = (stbi_uc *) ibuffer + ilen; + if (stbi__do_zlib(&a, obuffer, olen, 0, 0)) + return (int) (a.zout - a.zout_start); + else + return -1; +} +#endif + +// public domain "baseline" PNG decoder v0.10 Sean Barrett 2006-11-18 +// simple implementation +// - only 8-bit samples +// - no CRC checking +// - allocates lots of intermediate memory +// - avoids problem of streaming data between subsystems +// - avoids explicit window management +// performance +// - uses stb_zlib, a PD zlib implementation with fast huffman decoding + +#ifndef STBI_NO_PNG +typedef struct +{ + stbi__uint32 length; + stbi__uint32 type; +} stbi__pngchunk; + +static stbi__pngchunk stbi__get_chunk_header(stbi__context *s) +{ + stbi__pngchunk c; + c.length = stbi__get32be(s); + c.type = stbi__get32be(s); + return c; +} + +static int stbi__check_png_header(stbi__context *s) +{ + static const stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 }; + int i; + for (i=0; i < 8; ++i) + if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig","Not a PNG"); + return 1; +} + +typedef struct +{ + stbi__context *s; + stbi_uc *idata, *expanded, *out; + int depth; +} stbi__png; + + +enum { + STBI__F_none=0, + STBI__F_sub=1, + STBI__F_up=2, + STBI__F_avg=3, + STBI__F_paeth=4, + // synthetic filters used for first scanline to avoid needing a dummy row of 0s + STBI__F_avg_first, + STBI__F_paeth_first +}; + +static stbi_uc first_row_filter[5] = +{ + STBI__F_none, + STBI__F_sub, + STBI__F_none, + STBI__F_avg_first, + STBI__F_paeth_first +}; + +static int stbi__paeth(int a, int b, int c) +{ + int p = a + b - c; + int pa = abs(p-a); + int pb = abs(p-b); + int pc = abs(p-c); + if (pa <= pb && pa <= pc) return a; + if (pb <= pc) return b; + return c; +} + +static const stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 }; + +// create the png data from post-deflated data +static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) +{ + int bytes = (depth == 16? 2 : 1); + stbi__context *s = a->s; + stbi__uint32 i,j,stride = x*out_n*bytes; + stbi__uint32 img_len, img_width_bytes; + int k; + int img_n = s->img_n; // copy it into a local for later + + int output_bytes = out_n*bytes; + int filter_bytes = img_n*bytes; + int width = x; + + STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1); + a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, 0); // extra bytes to write off the end into + if (!a->out) return stbi__err("outofmem", "Out of memory"); + + if (!stbi__mad3sizes_valid(img_n, x, depth, 7)) return stbi__err("too large", "Corrupt PNG"); + img_width_bytes = (((img_n * x * depth) + 7) >> 3); + img_len = (img_width_bytes + 1) * y; + + // we used to check for exact match between raw_len and img_len on non-interlaced PNGs, + // but issue #276 reported a PNG in the wild that had extra data at the end (all zeros), + // so just check for raw_len < img_len always. + if (raw_len < img_len) return stbi__err("not enough pixels","Corrupt PNG"); + + for (j=0; j < y; ++j) { + stbi_uc *cur = a->out + stride*j; + stbi_uc *prior; + int filter = *raw++; + + if (filter > 4) + return stbi__err("invalid filter","Corrupt PNG"); + + if (depth < 8) { + STBI_ASSERT(img_width_bytes <= x); + cur += x*out_n - img_width_bytes; // store output to the rightmost img_len bytes, so we can decode in place + filter_bytes = 1; + width = img_width_bytes; + } + prior = cur - stride; // bugfix: need to compute this after 'cur +=' computation above + + // if first row, use special filter that doesn't sample previous row + if (j == 0) filter = first_row_filter[filter]; + + // handle first byte explicitly + for (k=0; k < filter_bytes; ++k) { + switch (filter) { + case STBI__F_none : cur[k] = raw[k]; break; + case STBI__F_sub : cur[k] = raw[k]; break; + case STBI__F_up : cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break; + case STBI__F_avg : cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); break; + case STBI__F_paeth : cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(0,prior[k],0)); break; + case STBI__F_avg_first : cur[k] = raw[k]; break; + case STBI__F_paeth_first: cur[k] = raw[k]; break; + } + } + + if (depth == 8) { + if (img_n != out_n) + cur[img_n] = 255; // first pixel + raw += img_n; + cur += out_n; + prior += out_n; + } else if (depth == 16) { + if (img_n != out_n) { + cur[filter_bytes] = 255; // first pixel top byte + cur[filter_bytes+1] = 255; // first pixel bottom byte + } + raw += filter_bytes; + cur += output_bytes; + prior += output_bytes; + } else { + raw += 1; + cur += 1; + prior += 1; + } + + // this is a little gross, so that we don't switch per-pixel or per-component + if (depth < 8 || img_n == out_n) { + int nk = (width - 1)*filter_bytes; + #define STBI__CASE(f) \ + case f: \ + for (k=0; k < nk; ++k) + switch (filter) { + // "none" filter turns into a memcpy here; make that explicit. + case STBI__F_none: memcpy(cur, raw, nk); break; + STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); } break; + STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; + STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); } break; + STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],prior[k],prior[k-filter_bytes])); } break; + STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); } break; + STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],0,0)); } break; + } + #undef STBI__CASE + raw += nk; + } else { + STBI_ASSERT(img_n+1 == out_n); + #define STBI__CASE(f) \ + case f: \ + for (i=x-1; i >= 1; --i, cur[filter_bytes]=255,raw+=filter_bytes,cur+=output_bytes,prior+=output_bytes) \ + for (k=0; k < filter_bytes; ++k) + switch (filter) { + STBI__CASE(STBI__F_none) { cur[k] = raw[k]; } break; + STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k- output_bytes]); } break; + STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; + STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k- output_bytes])>>1)); } break; + STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],prior[k],prior[k- output_bytes])); } break; + STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k- output_bytes] >> 1)); } break; + STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],0,0)); } break; + } + #undef STBI__CASE + + // the loop above sets the high byte of the pixels' alpha, but for + // 16 bit png files we also need the low byte set. we'll do that here. + if (depth == 16) { + cur = a->out + stride*j; // start at the beginning of the row again + for (i=0; i < x; ++i,cur+=output_bytes) { + cur[filter_bytes+1] = 255; + } + } + } + } + + // we make a separate pass to expand bits to pixels; for performance, + // this could run two scanlines behind the above code, so it won't + // intefere with filtering but will still be in the cache. + if (depth < 8) { + for (j=0; j < y; ++j) { + stbi_uc *cur = a->out + stride*j; + stbi_uc *in = a->out + stride*j + x*out_n - img_width_bytes; + // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit + // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop + stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range + + // note that the final byte might overshoot and write more data than desired. + // we can allocate enough data that this never writes out of memory, but it + // could also overwrite the next scanline. can it overwrite non-empty data + // on the next scanline? yes, consider 1-pixel-wide scanlines with 1-bit-per-pixel. + // so we need to explicitly clamp the final ones + + if (depth == 4) { + for (k=x*img_n; k >= 2; k-=2, ++in) { + *cur++ = scale * ((*in >> 4) ); + *cur++ = scale * ((*in ) & 0x0f); + } + if (k > 0) *cur++ = scale * ((*in >> 4) ); + } else if (depth == 2) { + for (k=x*img_n; k >= 4; k-=4, ++in) { + *cur++ = scale * ((*in >> 6) ); + *cur++ = scale * ((*in >> 4) & 0x03); + *cur++ = scale * ((*in >> 2) & 0x03); + *cur++ = scale * ((*in ) & 0x03); + } + if (k > 0) *cur++ = scale * ((*in >> 6) ); + if (k > 1) *cur++ = scale * ((*in >> 4) & 0x03); + if (k > 2) *cur++ = scale * ((*in >> 2) & 0x03); + } else if (depth == 1) { + for (k=x*img_n; k >= 8; k-=8, ++in) { + *cur++ = scale * ((*in >> 7) ); + *cur++ = scale * ((*in >> 6) & 0x01); + *cur++ = scale * ((*in >> 5) & 0x01); + *cur++ = scale * ((*in >> 4) & 0x01); + *cur++ = scale * ((*in >> 3) & 0x01); + *cur++ = scale * ((*in >> 2) & 0x01); + *cur++ = scale * ((*in >> 1) & 0x01); + *cur++ = scale * ((*in ) & 0x01); + } + if (k > 0) *cur++ = scale * ((*in >> 7) ); + if (k > 1) *cur++ = scale * ((*in >> 6) & 0x01); + if (k > 2) *cur++ = scale * ((*in >> 5) & 0x01); + if (k > 3) *cur++ = scale * ((*in >> 4) & 0x01); + if (k > 4) *cur++ = scale * ((*in >> 3) & 0x01); + if (k > 5) *cur++ = scale * ((*in >> 2) & 0x01); + if (k > 6) *cur++ = scale * ((*in >> 1) & 0x01); + } + if (img_n != out_n) { + int q; + // insert alpha = 255 + cur = a->out + stride*j; + if (img_n == 1) { + for (q=x-1; q >= 0; --q) { + cur[q*2+1] = 255; + cur[q*2+0] = cur[q]; + } + } else { + STBI_ASSERT(img_n == 3); + for (q=x-1; q >= 0; --q) { + cur[q*4+3] = 255; + cur[q*4+2] = cur[q*3+2]; + cur[q*4+1] = cur[q*3+1]; + cur[q*4+0] = cur[q*3+0]; + } + } + } + } + } else if (depth == 16) { + // force the image data from big-endian to platform-native. + // this is done in a separate pass due to the decoding relying + // on the data being untouched, but could probably be done + // per-line during decode if care is taken. + stbi_uc *cur = a->out; + stbi__uint16 *cur16 = (stbi__uint16*)cur; + + for(i=0; i < x*y*out_n; ++i,cur16++,cur+=2) { + *cur16 = (cur[0] << 8) | cur[1]; + } + } + + return 1; +} + +static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) +{ + int bytes = (depth == 16 ? 2 : 1); + int out_bytes = out_n * bytes; + stbi_uc *final; + int p; + if (!interlaced) + return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color); + + // de-interlacing + final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); + for (p=0; p < 7; ++p) { + int xorig[] = { 0,4,0,2,0,1,0 }; + int yorig[] = { 0,0,4,0,2,0,1 }; + int xspc[] = { 8,8,4,4,2,2,1 }; + int yspc[] = { 8,8,8,4,4,2,2 }; + int i,j,x,y; + // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1 + x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p]; + y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p]; + if (x && y) { + stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; + if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) { + STBI_FREE(final); + return 0; + } + for (j=0; j < y; ++j) { + for (i=0; i < x; ++i) { + int out_y = j*yspc[p]+yorig[p]; + int out_x = i*xspc[p]+xorig[p]; + memcpy(final + out_y*a->s->img_x*out_bytes + out_x*out_bytes, + a->out + (j*x+i)*out_bytes, out_bytes); + } + } + STBI_FREE(a->out); + image_data += img_len; + image_data_len -= img_len; + } + } + a->out = final; + + return 1; +} + +static int stbi__compute_transparency(stbi__png *z, stbi_uc tc[3], int out_n) +{ + stbi__context *s = z->s; + stbi__uint32 i, pixel_count = s->img_x * s->img_y; + stbi_uc *p = z->out; + + // compute color-based transparency, assuming we've + // already got 255 as the alpha value in the output + STBI_ASSERT(out_n == 2 || out_n == 4); + + if (out_n == 2) { + for (i=0; i < pixel_count; ++i) { + p[1] = (p[0] == tc[0] ? 0 : 255); + p += 2; + } + } else { + for (i=0; i < pixel_count; ++i) { + if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) + p[3] = 0; + p += 4; + } + } + return 1; +} + +static int stbi__compute_transparency16(stbi__png *z, stbi__uint16 tc[3], int out_n) +{ + stbi__context *s = z->s; + stbi__uint32 i, pixel_count = s->img_x * s->img_y; + stbi__uint16 *p = (stbi__uint16*) z->out; + + // compute color-based transparency, assuming we've + // already got 65535 as the alpha value in the output + STBI_ASSERT(out_n == 2 || out_n == 4); + + if (out_n == 2) { + for (i = 0; i < pixel_count; ++i) { + p[1] = (p[0] == tc[0] ? 0 : 65535); + p += 2; + } + } else { + for (i = 0; i < pixel_count; ++i) { + if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) + p[3] = 0; + p += 4; + } + } + return 1; +} + +static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n) +{ + stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y; + stbi_uc *p, *temp_out, *orig = a->out; + + p = (stbi_uc *) stbi__malloc_mad2(pixel_count, pal_img_n, 0); + if (p == NULL) return stbi__err("outofmem", "Out of memory"); + + // between here and free(out) below, exitting would leak + temp_out = p; + + if (pal_img_n == 3) { + for (i=0; i < pixel_count; ++i) { + int n = orig[i]*4; + p[0] = palette[n ]; + p[1] = palette[n+1]; + p[2] = palette[n+2]; + p += 3; + } + } else { + for (i=0; i < pixel_count; ++i) { + int n = orig[i]*4; + p[0] = palette[n ]; + p[1] = palette[n+1]; + p[2] = palette[n+2]; + p[3] = palette[n+3]; + p += 4; + } + } + STBI_FREE(a->out); + a->out = temp_out; + + STBI_NOTUSED(len); + + return 1; +} + +static int stbi__unpremultiply_on_load = 0; +static int stbi__de_iphone_flag = 0; + +STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply) +{ + stbi__unpremultiply_on_load = flag_true_if_should_unpremultiply; +} + +STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert) +{ + stbi__de_iphone_flag = flag_true_if_should_convert; +} + +static void stbi__de_iphone(stbi__png *z) +{ + stbi__context *s = z->s; + stbi__uint32 i, pixel_count = s->img_x * s->img_y; + stbi_uc *p = z->out; + + if (s->img_out_n == 3) { // convert bgr to rgb + for (i=0; i < pixel_count; ++i) { + stbi_uc t = p[0]; + p[0] = p[2]; + p[2] = t; + p += 3; + } + } else { + STBI_ASSERT(s->img_out_n == 4); + if (stbi__unpremultiply_on_load) { + // convert bgr to rgb and unpremultiply + for (i=0; i < pixel_count; ++i) { + stbi_uc a = p[3]; + stbi_uc t = p[0]; + if (a) { + stbi_uc half = a / 2; + p[0] = (p[2] * 255 + half) / a; + p[1] = (p[1] * 255 + half) / a; + p[2] = ( t * 255 + half) / a; + } else { + p[0] = p[2]; + p[2] = t; + } + p += 4; + } + } else { + // convert bgr to rgb + for (i=0; i < pixel_count; ++i) { + stbi_uc t = p[0]; + p[0] = p[2]; + p[2] = t; + p += 4; + } + } + } +} + +#define STBI__PNG_TYPE(a,b,c,d) (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d)) + +static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) +{ + stbi_uc palette[1024], pal_img_n=0; + stbi_uc has_trans=0, tc[3]; + stbi__uint16 tc16[3]; + stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0; + int first=1,k,interlace=0, color=0, is_iphone=0; + stbi__context *s = z->s; + + z->expanded = NULL; + z->idata = NULL; + z->out = NULL; + + if (!stbi__check_png_header(s)) return 0; + + if (scan == STBI__SCAN_type) return 1; + + for (;;) { + stbi__pngchunk c = stbi__get_chunk_header(s); + switch (c.type) { + case STBI__PNG_TYPE('C','g','B','I'): + is_iphone = 1; + stbi__skip(s, c.length); + break; + case STBI__PNG_TYPE('I','H','D','R'): { + int comp,filter; + if (!first) return stbi__err("multiple IHDR","Corrupt PNG"); + first = 0; + if (c.length != 13) return stbi__err("bad IHDR len","Corrupt PNG"); + s->img_x = stbi__get32be(s); if (s->img_x > (1 << 24)) return stbi__err("too large","Very large image (corrupt?)"); + s->img_y = stbi__get32be(s); if (s->img_y > (1 << 24)) return stbi__err("too large","Very large image (corrupt?)"); + z->depth = stbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return stbi__err("1/2/4/8/16-bit only","PNG not supported: 1/2/4/8/16-bit only"); + color = stbi__get8(s); if (color > 6) return stbi__err("bad ctype","Corrupt PNG"); + if (color == 3 && z->depth == 16) return stbi__err("bad ctype","Corrupt PNG"); + if (color == 3) pal_img_n = 3; else if (color & 1) return stbi__err("bad ctype","Corrupt PNG"); + comp = stbi__get8(s); if (comp) return stbi__err("bad comp method","Corrupt PNG"); + filter= stbi__get8(s); if (filter) return stbi__err("bad filter method","Corrupt PNG"); + interlace = stbi__get8(s); if (interlace>1) return stbi__err("bad interlace method","Corrupt PNG"); + if (!s->img_x || !s->img_y) return stbi__err("0-pixel image","Corrupt PNG"); + if (!pal_img_n) { + s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); + if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode"); + if (scan == STBI__SCAN_header) return 1; + } else { + // if paletted, then pal_n is our final components, and + // img_n is # components to decompress/filter. + s->img_n = 1; + if ((1 << 30) / s->img_x / 4 < s->img_y) return stbi__err("too large","Corrupt PNG"); + // if SCAN_header, have to scan to see if we have a tRNS + } + break; + } + + case STBI__PNG_TYPE('P','L','T','E'): { + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (c.length > 256*3) return stbi__err("invalid PLTE","Corrupt PNG"); + pal_len = c.length / 3; + if (pal_len * 3 != c.length) return stbi__err("invalid PLTE","Corrupt PNG"); + for (i=0; i < pal_len; ++i) { + palette[i*4+0] = stbi__get8(s); + palette[i*4+1] = stbi__get8(s); + palette[i*4+2] = stbi__get8(s); + palette[i*4+3] = 255; + } + break; + } + + case STBI__PNG_TYPE('t','R','N','S'): { + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (z->idata) return stbi__err("tRNS after IDAT","Corrupt PNG"); + if (pal_img_n) { + if (scan == STBI__SCAN_header) { s->img_n = 4; return 1; } + if (pal_len == 0) return stbi__err("tRNS before PLTE","Corrupt PNG"); + if (c.length > pal_len) return stbi__err("bad tRNS len","Corrupt PNG"); + pal_img_n = 4; + for (i=0; i < c.length; ++i) + palette[i*4+3] = stbi__get8(s); + } else { + if (!(s->img_n & 1)) return stbi__err("tRNS with alpha","Corrupt PNG"); + if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG"); + has_trans = 1; + if (z->depth == 16) { + for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is + } else { + for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger + } + } + break; + } + + case STBI__PNG_TYPE('I','D','A','T'): { + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG"); + if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; } + if ((int)(ioff + c.length) < (int)ioff) return 0; + if (ioff + c.length > idata_limit) { + stbi__uint32 idata_limit_old = idata_limit; + stbi_uc *p; + if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; + while (ioff + c.length > idata_limit) + idata_limit *= 2; + STBI_NOTUSED(idata_limit_old); + p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); + z->idata = p; + } + if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG"); + ioff += c.length; + break; + } + + case STBI__PNG_TYPE('I','E','N','D'): { + stbi__uint32 raw_len, bpl; + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if (scan != STBI__SCAN_load) return 1; + if (z->idata == NULL) return stbi__err("no IDAT","Corrupt PNG"); + // initial guess for decoded data size to avoid unnecessary reallocs + bpl = (s->img_x * z->depth + 7) / 8; // bytes per line, per component + raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; + z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone); + if (z->expanded == NULL) return 0; // zlib should set error + STBI_FREE(z->idata); z->idata = NULL; + if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) + s->img_out_n = s->img_n+1; + else + s->img_out_n = s->img_n; + if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0; + if (has_trans) { + if (z->depth == 16) { + if (!stbi__compute_transparency16(z, tc16, s->img_out_n)) return 0; + } else { + if (!stbi__compute_transparency(z, tc, s->img_out_n)) return 0; + } + } + if (is_iphone && stbi__de_iphone_flag && s->img_out_n > 2) + stbi__de_iphone(z); + if (pal_img_n) { + // pal_img_n == 3 or 4 + s->img_n = pal_img_n; // record the actual colors we had + s->img_out_n = pal_img_n; + if (req_comp >= 3) s->img_out_n = req_comp; + if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) + return 0; + } else if (has_trans) { + // non-paletted image with tRNS -> source image has (constant) alpha + ++s->img_n; + } + STBI_FREE(z->expanded); z->expanded = NULL; + return 1; + } + + default: + // if critical, fail + if (first) return stbi__err("first not IHDR", "Corrupt PNG"); + if ((c.type & (1 << 29)) == 0) { + #ifndef STBI_NO_FAILURE_STRINGS + // not threadsafe + static char invalid_chunk[] = "XXXX PNG chunk not known"; + invalid_chunk[0] = STBI__BYTECAST(c.type >> 24); + invalid_chunk[1] = STBI__BYTECAST(c.type >> 16); + invalid_chunk[2] = STBI__BYTECAST(c.type >> 8); + invalid_chunk[3] = STBI__BYTECAST(c.type >> 0); + #endif + return stbi__err(invalid_chunk, "PNG not supported: unknown PNG chunk type"); + } + stbi__skip(s, c.length); + break; + } + // end of PNG chunk, read and skip CRC + stbi__get32be(s); + } +} + +static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, stbi__result_info *ri) +{ + void *result=NULL; + if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); + if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { + if (p->depth < 8) + ri->bits_per_channel = 8; + else + ri->bits_per_channel = p->depth; + result = p->out; + p->out = NULL; + if (req_comp && req_comp != p->s->img_out_n) { + if (ri->bits_per_channel == 8) + result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); + else + result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); + p->s->img_out_n = req_comp; + if (result == NULL) return result; + } + *x = p->s->img_x; + *y = p->s->img_y; + if (n) *n = p->s->img_n; + } + STBI_FREE(p->out); p->out = NULL; + STBI_FREE(p->expanded); p->expanded = NULL; + STBI_FREE(p->idata); p->idata = NULL; + + return result; +} + +static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi__png p; + p.s = s; + return stbi__do_png(&p, x,y,comp,req_comp, ri); +} + +static int stbi__png_test(stbi__context *s) +{ + int r; + r = stbi__check_png_header(s); + stbi__rewind(s); + return r; +} + +static int stbi__png_info_raw(stbi__png *p, int *x, int *y, int *comp) +{ + if (!stbi__parse_png_file(p, STBI__SCAN_header, 0)) { + stbi__rewind( p->s ); + return 0; + } + if (x) *x = p->s->img_x; + if (y) *y = p->s->img_y; + if (comp) *comp = p->s->img_n; + return 1; +} + +static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp) +{ + stbi__png p; + p.s = s; + return stbi__png_info_raw(&p, x, y, comp); +} + +static int stbi__png_is16(stbi__context *s) +{ + stbi__png p; + p.s = s; + if (!stbi__png_info_raw(&p, NULL, NULL, NULL)) + return 0; + if (p.depth != 16) { + stbi__rewind(p.s); + return 0; + } + return 1; +} +#endif + +// Microsoft/Windows BMP image + +#ifndef STBI_NO_BMP +static int stbi__bmp_test_raw(stbi__context *s) +{ + int r; + int sz; + if (stbi__get8(s) != 'B') return 0; + if (stbi__get8(s) != 'M') return 0; + stbi__get32le(s); // discard filesize + stbi__get16le(s); // discard reserved + stbi__get16le(s); // discard reserved + stbi__get32le(s); // discard data offset + sz = stbi__get32le(s); + r = (sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124); + return r; +} + +static int stbi__bmp_test(stbi__context *s) +{ + int r = stbi__bmp_test_raw(s); + stbi__rewind(s); + return r; +} + + +// returns 0..31 for the highest set bit +static int stbi__high_bit(unsigned int z) +{ + int n=0; + if (z == 0) return -1; + if (z >= 0x10000) n += 16, z >>= 16; + if (z >= 0x00100) n += 8, z >>= 8; + if (z >= 0x00010) n += 4, z >>= 4; + if (z >= 0x00004) n += 2, z >>= 2; + if (z >= 0x00002) n += 1, z >>= 1; + return n; +} + +static int stbi__bitcount(unsigned int a) +{ + a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2 + a = (a & 0x33333333) + ((a >> 2) & 0x33333333); // max 4 + a = (a + (a >> 4)) & 0x0f0f0f0f; // max 8 per 4, now 8 bits + a = (a + (a >> 8)); // max 16 per 8 bits + a = (a + (a >> 16)); // max 32 per 8 bits + return a & 0xff; +} + +// extract an arbitrarily-aligned N-bit value (N=bits) +// from v, and then make it 8-bits long and fractionally +// extend it to full full range. +static int stbi__shiftsigned(int v, int shift, int bits) +{ + static unsigned int mul_table[9] = { + 0, + 0xff/*0b11111111*/, 0x55/*0b01010101*/, 0x49/*0b01001001*/, 0x11/*0b00010001*/, + 0x21/*0b00100001*/, 0x41/*0b01000001*/, 0x81/*0b10000001*/, 0x01/*0b00000001*/, + }; + static unsigned int shift_table[9] = { + 0, 0,0,1,0,2,4,6,0, + }; + if (shift < 0) + v <<= -shift; + else + v >>= shift; + STBI_ASSERT(v >= 0 && v < 256); + v >>= (8-bits); + STBI_ASSERT(bits >= 0 && bits <= 8); + return (int) ((unsigned) v * mul_table[bits]) >> shift_table[bits]; +} + +typedef struct +{ + int bpp, offset, hsz; + unsigned int mr,mg,mb,ma, all_a; +} stbi__bmp_data; + +static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info) +{ + int hsz; + if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP"); + stbi__get32le(s); // discard filesize + stbi__get16le(s); // discard reserved + stbi__get16le(s); // discard reserved + info->offset = stbi__get32le(s); + info->hsz = hsz = stbi__get32le(s); + info->mr = info->mg = info->mb = info->ma = 0; + + if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown"); + if (hsz == 12) { + s->img_x = stbi__get16le(s); + s->img_y = stbi__get16le(s); + } else { + s->img_x = stbi__get32le(s); + s->img_y = stbi__get32le(s); + } + if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP"); + info->bpp = stbi__get16le(s); + if (hsz != 12) { + int compress = stbi__get32le(s); + if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE"); + stbi__get32le(s); // discard sizeof + stbi__get32le(s); // discard hres + stbi__get32le(s); // discard vres + stbi__get32le(s); // discard colorsused + stbi__get32le(s); // discard max important + if (hsz == 40 || hsz == 56) { + if (hsz == 56) { + stbi__get32le(s); + stbi__get32le(s); + stbi__get32le(s); + stbi__get32le(s); + } + if (info->bpp == 16 || info->bpp == 32) { + if (compress == 0) { + if (info->bpp == 32) { + info->mr = 0xffu << 16; + info->mg = 0xffu << 8; + info->mb = 0xffu << 0; + info->ma = 0xffu << 24; + info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0 + } else { + info->mr = 31u << 10; + info->mg = 31u << 5; + info->mb = 31u << 0; + } + } else if (compress == 3) { + info->mr = stbi__get32le(s); + info->mg = stbi__get32le(s); + info->mb = stbi__get32le(s); + // not documented, but generated by photoshop and handled by mspaint + if (info->mr == info->mg && info->mg == info->mb) { + // ?!?!? + return stbi__errpuc("bad BMP", "bad BMP"); + } + } else + return stbi__errpuc("bad BMP", "bad BMP"); + } + } else { + int i; + if (hsz != 108 && hsz != 124) + return stbi__errpuc("bad BMP", "bad BMP"); + info->mr = stbi__get32le(s); + info->mg = stbi__get32le(s); + info->mb = stbi__get32le(s); + info->ma = stbi__get32le(s); + stbi__get32le(s); // discard color space + for (i=0; i < 12; ++i) + stbi__get32le(s); // discard color space parameters + if (hsz == 124) { + stbi__get32le(s); // discard rendering intent + stbi__get32le(s); // discard offset of profile data + stbi__get32le(s); // discard size of profile data + stbi__get32le(s); // discard reserved + } + } + } + return (void *) 1; +} + + +static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi_uc *out; + unsigned int mr=0,mg=0,mb=0,ma=0, all_a; + stbi_uc pal[256][4]; + int psize=0,i,j,width; + int flip_vertically, pad, target; + stbi__bmp_data info; + STBI_NOTUSED(ri); + + info.all_a = 255; + if (stbi__bmp_parse_header(s, &info) == NULL) + return NULL; // error code already set + + flip_vertically = ((int) s->img_y) > 0; + s->img_y = abs((int) s->img_y); + + mr = info.mr; + mg = info.mg; + mb = info.mb; + ma = info.ma; + all_a = info.all_a; + + if (info.hsz == 12) { + if (info.bpp < 24) + psize = (info.offset - 14 - 24) / 3; + } else { + if (info.bpp < 16) + psize = (info.offset - 14 - info.hsz) >> 2; + } + + s->img_n = ma ? 4 : 3; + if (req_comp && req_comp >= 3) // we can directly decode 3 or 4 + target = req_comp; + else + target = s->img_n; // if they want monochrome, we'll post-convert + + // sanity-check size + if (!stbi__mad3sizes_valid(target, s->img_x, s->img_y, 0)) + return stbi__errpuc("too large", "Corrupt BMP"); + + out = (stbi_uc *) stbi__malloc_mad3(target, s->img_x, s->img_y, 0); + if (!out) return stbi__errpuc("outofmem", "Out of memory"); + if (info.bpp < 16) { + int z=0; + if (psize == 0 || psize > 256) { STBI_FREE(out); return stbi__errpuc("invalid", "Corrupt BMP"); } + for (i=0; i < psize; ++i) { + pal[i][2] = stbi__get8(s); + pal[i][1] = stbi__get8(s); + pal[i][0] = stbi__get8(s); + if (info.hsz != 12) stbi__get8(s); + pal[i][3] = 255; + } + stbi__skip(s, info.offset - 14 - info.hsz - psize * (info.hsz == 12 ? 3 : 4)); + if (info.bpp == 1) width = (s->img_x + 7) >> 3; + else if (info.bpp == 4) width = (s->img_x + 1) >> 1; + else if (info.bpp == 8) width = s->img_x; + else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); } + pad = (-width)&3; + if (info.bpp == 1) { + for (j=0; j < (int) s->img_y; ++j) { + int bit_offset = 7, v = stbi__get8(s); + for (i=0; i < (int) s->img_x; ++i) { + int color = (v>>bit_offset)&0x1; + out[z++] = pal[color][0]; + out[z++] = pal[color][1]; + out[z++] = pal[color][2]; + if((--bit_offset) < 0) { + bit_offset = 7; + v = stbi__get8(s); + } + } + stbi__skip(s, pad); + } + } else { + for (j=0; j < (int) s->img_y; ++j) { + for (i=0; i < (int) s->img_x; i += 2) { + int v=stbi__get8(s),v2=0; + if (info.bpp == 4) { + v2 = v & 15; + v >>= 4; + } + out[z++] = pal[v][0]; + out[z++] = pal[v][1]; + out[z++] = pal[v][2]; + if (target == 4) out[z++] = 255; + if (i+1 == (int) s->img_x) break; + v = (info.bpp == 8) ? stbi__get8(s) : v2; + out[z++] = pal[v][0]; + out[z++] = pal[v][1]; + out[z++] = pal[v][2]; + if (target == 4) out[z++] = 255; + } + stbi__skip(s, pad); + } + } + } else { + int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0; + int z = 0; + int easy=0; + stbi__skip(s, info.offset - 14 - info.hsz); + if (info.bpp == 24) width = 3 * s->img_x; + else if (info.bpp == 16) width = 2*s->img_x; + else /* bpp = 32 and pad = 0 */ width=0; + pad = (-width) & 3; + if (info.bpp == 24) { + easy = 1; + } else if (info.bpp == 32) { + if (mb == 0xff && mg == 0xff00 && mr == 0x00ff0000 && ma == 0xff000000) + easy = 2; + } + if (!easy) { + if (!mr || !mg || !mb) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } + // right shift amt to put high bit in position #7 + rshift = stbi__high_bit(mr)-7; rcount = stbi__bitcount(mr); + gshift = stbi__high_bit(mg)-7; gcount = stbi__bitcount(mg); + bshift = stbi__high_bit(mb)-7; bcount = stbi__bitcount(mb); + ashift = stbi__high_bit(ma)-7; acount = stbi__bitcount(ma); + } + for (j=0; j < (int) s->img_y; ++j) { + if (easy) { + for (i=0; i < (int) s->img_x; ++i) { + unsigned char a; + out[z+2] = stbi__get8(s); + out[z+1] = stbi__get8(s); + out[z+0] = stbi__get8(s); + z += 3; + a = (easy == 2 ? stbi__get8(s) : 255); + all_a |= a; + if (target == 4) out[z++] = a; + } + } else { + int bpp = info.bpp; + for (i=0; i < (int) s->img_x; ++i) { + stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s)); + unsigned int a; + out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount)); + out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount)); + out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount)); + a = (ma ? stbi__shiftsigned(v & ma, ashift, acount) : 255); + all_a |= a; + if (target == 4) out[z++] = STBI__BYTECAST(a); + } + } + stbi__skip(s, pad); + } + } + + // if alpha channel is all 0s, replace with all 255s + if (target == 4 && all_a == 0) + for (i=4*s->img_x*s->img_y-1; i >= 0; i -= 4) + out[i] = 255; + + if (flip_vertically) { + stbi_uc t; + for (j=0; j < (int) s->img_y>>1; ++j) { + stbi_uc *p1 = out + j *s->img_x*target; + stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target; + for (i=0; i < (int) s->img_x*target; ++i) { + t = p1[i], p1[i] = p2[i], p2[i] = t; + } + } + } + + if (req_comp && req_comp != target) { + out = stbi__convert_format(out, target, req_comp, s->img_x, s->img_y); + if (out == NULL) return out; // stbi__convert_format frees input on failure + } + + *x = s->img_x; + *y = s->img_y; + if (comp) *comp = s->img_n; + return out; +} +#endif + +// Targa Truevision - TGA +// by Jonathan Dummer +#ifndef STBI_NO_TGA +// returns STBI_rgb or whatever, 0 on error +static int stbi__tga_get_comp(int bits_per_pixel, int is_grey, int* is_rgb16) +{ + // only RGB or RGBA (incl. 16bit) or grey allowed + if (is_rgb16) *is_rgb16 = 0; + switch(bits_per_pixel) { + case 8: return STBI_grey; + case 16: if(is_grey) return STBI_grey_alpha; + // fallthrough + case 15: if(is_rgb16) *is_rgb16 = 1; + return STBI_rgb; + case 24: // fallthrough + case 32: return bits_per_pixel/8; + default: return 0; + } +} + +static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp) +{ + int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp; + int sz, tga_colormap_type; + stbi__get8(s); // discard Offset + tga_colormap_type = stbi__get8(s); // colormap type + if( tga_colormap_type > 1 ) { + stbi__rewind(s); + return 0; // only RGB or indexed allowed + } + tga_image_type = stbi__get8(s); // image type + if ( tga_colormap_type == 1 ) { // colormapped (paletted) image + if (tga_image_type != 1 && tga_image_type != 9) { + stbi__rewind(s); + return 0; + } + stbi__skip(s,4); // skip index of first colormap entry and number of entries + sz = stbi__get8(s); // check bits per palette color entry + if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) { + stbi__rewind(s); + return 0; + } + stbi__skip(s,4); // skip image x and y origin + tga_colormap_bpp = sz; + } else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE + if ( (tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11) ) { + stbi__rewind(s); + return 0; // only RGB or grey allowed, +/- RLE + } + stbi__skip(s,9); // skip colormap specification and image x/y origin + tga_colormap_bpp = 0; + } + tga_w = stbi__get16le(s); + if( tga_w < 1 ) { + stbi__rewind(s); + return 0; // test width + } + tga_h = stbi__get16le(s); + if( tga_h < 1 ) { + stbi__rewind(s); + return 0; // test height + } + tga_bits_per_pixel = stbi__get8(s); // bits per pixel + stbi__get8(s); // ignore alpha bits + if (tga_colormap_bpp != 0) { + if((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16)) { + // when using a colormap, tga_bits_per_pixel is the size of the indexes + // I don't think anything but 8 or 16bit indexes makes sense + stbi__rewind(s); + return 0; + } + tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL); + } else { + tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL); + } + if(!tga_comp) { + stbi__rewind(s); + return 0; + } + if (x) *x = tga_w; + if (y) *y = tga_h; + if (comp) *comp = tga_comp; + return 1; // seems to have passed everything +} + +static int stbi__tga_test(stbi__context *s) +{ + int res = 0; + int sz, tga_color_type; + stbi__get8(s); // discard Offset + tga_color_type = stbi__get8(s); // color type + if ( tga_color_type > 1 ) goto errorEnd; // only RGB or indexed allowed + sz = stbi__get8(s); // image type + if ( tga_color_type == 1 ) { // colormapped (paletted) image + if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9 + stbi__skip(s,4); // skip index of first colormap entry and number of entries + sz = stbi__get8(s); // check bits per palette color entry + if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; + stbi__skip(s,4); // skip image x and y origin + } else { // "normal" image w/o colormap + if ( (sz != 2) && (sz != 3) && (sz != 10) && (sz != 11) ) goto errorEnd; // only RGB or grey allowed, +/- RLE + stbi__skip(s,9); // skip colormap specification and image x/y origin + } + if ( stbi__get16le(s) < 1 ) goto errorEnd; // test width + if ( stbi__get16le(s) < 1 ) goto errorEnd; // test height + sz = stbi__get8(s); // bits per pixel + if ( (tga_color_type == 1) && (sz != 8) && (sz != 16) ) goto errorEnd; // for colormapped images, bpp is size of an index + if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; + + res = 1; // if we got this far, everything's good and we can return 1 instead of 0 + +errorEnd: + stbi__rewind(s); + return res; +} + +// read 16bit value and convert to 24bit RGB +static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out) +{ + stbi__uint16 px = (stbi__uint16)stbi__get16le(s); + stbi__uint16 fiveBitMask = 31; + // we have 3 channels with 5bits each + int r = (px >> 10) & fiveBitMask; + int g = (px >> 5) & fiveBitMask; + int b = px & fiveBitMask; + // Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later + out[0] = (stbi_uc)((r * 255)/31); + out[1] = (stbi_uc)((g * 255)/31); + out[2] = (stbi_uc)((b * 255)/31); + + // some people claim that the most significant bit might be used for alpha + // (possibly if an alpha-bit is set in the "image descriptor byte") + // but that only made 16bit test images completely translucent.. + // so let's treat all 15 and 16bit TGAs as RGB with no alpha. +} + +static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + // read in the TGA header stuff + int tga_offset = stbi__get8(s); + int tga_indexed = stbi__get8(s); + int tga_image_type = stbi__get8(s); + int tga_is_RLE = 0; + int tga_palette_start = stbi__get16le(s); + int tga_palette_len = stbi__get16le(s); + int tga_palette_bits = stbi__get8(s); + int tga_x_origin = stbi__get16le(s); + int tga_y_origin = stbi__get16le(s); + int tga_width = stbi__get16le(s); + int tga_height = stbi__get16le(s); + int tga_bits_per_pixel = stbi__get8(s); + int tga_comp, tga_rgb16=0; + int tga_inverted = stbi__get8(s); + // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?) + // image data + unsigned char *tga_data; + unsigned char *tga_palette = NULL; + int i, j; + unsigned char raw_data[4] = {0}; + int RLE_count = 0; + int RLE_repeating = 0; + int read_next_pixel = 1; + STBI_NOTUSED(ri); + + // do a tiny bit of precessing + if ( tga_image_type >= 8 ) + { + tga_image_type -= 8; + tga_is_RLE = 1; + } + tga_inverted = 1 - ((tga_inverted >> 5) & 1); + + // If I'm paletted, then I'll use the number of bits from the palette + if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16); + else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16); + + if(!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency + return stbi__errpuc("bad format", "Can't find out TGA pixelformat"); + + // tga info + *x = tga_width; + *y = tga_height; + if (comp) *comp = tga_comp; + + if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0)) + return stbi__errpuc("too large", "Corrupt TGA"); + + tga_data = (unsigned char*)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0); + if (!tga_data) return stbi__errpuc("outofmem", "Out of memory"); + + // skip to the data's starting position (offset usually = 0) + stbi__skip(s, tga_offset ); + + if ( !tga_indexed && !tga_is_RLE && !tga_rgb16 ) { + for (i=0; i < tga_height; ++i) { + int row = tga_inverted ? tga_height -i - 1 : i; + stbi_uc *tga_row = tga_data + row*tga_width*tga_comp; + stbi__getn(s, tga_row, tga_width * tga_comp); + } + } else { + // do I need to load a palette? + if ( tga_indexed) + { + // any data to skip? (offset usually = 0) + stbi__skip(s, tga_palette_start ); + // load the palette + tga_palette = (unsigned char*)stbi__malloc_mad2(tga_palette_len, tga_comp, 0); + if (!tga_palette) { + STBI_FREE(tga_data); + return stbi__errpuc("outofmem", "Out of memory"); + } + if (tga_rgb16) { + stbi_uc *pal_entry = tga_palette; + STBI_ASSERT(tga_comp == STBI_rgb); + for (i=0; i < tga_palette_len; ++i) { + stbi__tga_read_rgb16(s, pal_entry); + pal_entry += tga_comp; + } + } else if (!stbi__getn(s, tga_palette, tga_palette_len * tga_comp)) { + STBI_FREE(tga_data); + STBI_FREE(tga_palette); + return stbi__errpuc("bad palette", "Corrupt TGA"); + } + } + // load the data + for (i=0; i < tga_width * tga_height; ++i) + { + // if I'm in RLE mode, do I need to get a RLE stbi__pngchunk? + if ( tga_is_RLE ) + { + if ( RLE_count == 0 ) + { + // yep, get the next byte as a RLE command + int RLE_cmd = stbi__get8(s); + RLE_count = 1 + (RLE_cmd & 127); + RLE_repeating = RLE_cmd >> 7; + read_next_pixel = 1; + } else if ( !RLE_repeating ) + { + read_next_pixel = 1; + } + } else + { + read_next_pixel = 1; + } + // OK, if I need to read a pixel, do it now + if ( read_next_pixel ) + { + // load however much data we did have + if ( tga_indexed ) + { + // read in index, then perform the lookup + int pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s); + if ( pal_idx >= tga_palette_len ) { + // invalid index + pal_idx = 0; + } + pal_idx *= tga_comp; + for (j = 0; j < tga_comp; ++j) { + raw_data[j] = tga_palette[pal_idx+j]; + } + } else if(tga_rgb16) { + STBI_ASSERT(tga_comp == STBI_rgb); + stbi__tga_read_rgb16(s, raw_data); + } else { + // read in the data raw + for (j = 0; j < tga_comp; ++j) { + raw_data[j] = stbi__get8(s); + } + } + // clear the reading flag for the next pixel + read_next_pixel = 0; + } // end of reading a pixel + + // copy data + for (j = 0; j < tga_comp; ++j) + tga_data[i*tga_comp+j] = raw_data[j]; + + // in case we're in RLE mode, keep counting down + --RLE_count; + } + // do I need to invert the image? + if ( tga_inverted ) + { + for (j = 0; j*2 < tga_height; ++j) + { + int index1 = j * tga_width * tga_comp; + int index2 = (tga_height - 1 - j) * tga_width * tga_comp; + for (i = tga_width * tga_comp; i > 0; --i) + { + unsigned char temp = tga_data[index1]; + tga_data[index1] = tga_data[index2]; + tga_data[index2] = temp; + ++index1; + ++index2; + } + } + } + // clear my palette, if I had one + if ( tga_palette != NULL ) + { + STBI_FREE( tga_palette ); + } + } + + // swap RGB - if the source data was RGB16, it already is in the right order + if (tga_comp >= 3 && !tga_rgb16) + { + unsigned char* tga_pixel = tga_data; + for (i=0; i < tga_width * tga_height; ++i) + { + unsigned char temp = tga_pixel[0]; + tga_pixel[0] = tga_pixel[2]; + tga_pixel[2] = temp; + tga_pixel += tga_comp; + } + } + + // convert to target component count + if (req_comp && req_comp != tga_comp) + tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height); + + // the things I do to get rid of an error message, and yet keep + // Microsoft's C compilers happy... [8^( + tga_palette_start = tga_palette_len = tga_palette_bits = + tga_x_origin = tga_y_origin = 0; + // OK, done + return tga_data; +} +#endif + +// ************************************************************************************************* +// Photoshop PSD loader -- PD by Thatcher Ulrich, integration by Nicolas Schulz, tweaked by STB + +#ifndef STBI_NO_PSD +static int stbi__psd_test(stbi__context *s) +{ + int r = (stbi__get32be(s) == 0x38425053); + stbi__rewind(s); + return r; +} + +static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount) +{ + int count, nleft, len; + + count = 0; + while ((nleft = pixelCount - count) > 0) { + len = stbi__get8(s); + if (len == 128) { + // No-op. + } else if (len < 128) { + // Copy next len+1 bytes literally. + len++; + if (len > nleft) return 0; // corrupt data + count += len; + while (len) { + *p = stbi__get8(s); + p += 4; + len--; + } + } else if (len > 128) { + stbi_uc val; + // Next -len+1 bytes in the dest are replicated from next source byte. + // (Interpret len as a negative 8-bit int.) + len = 257 - len; + if (len > nleft) return 0; // corrupt data + val = stbi__get8(s); + count += len; + while (len) { + *p = val; + p += 4; + len--; + } + } + } + + return 1; +} + +static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) +{ + int pixelCount; + int channelCount, compression; + int channel, i; + int bitdepth; + int w,h; + stbi_uc *out; + STBI_NOTUSED(ri); + + // Check identifier + if (stbi__get32be(s) != 0x38425053) // "8BPS" + return stbi__errpuc("not PSD", "Corrupt PSD image"); + + // Check file type version. + if (stbi__get16be(s) != 1) + return stbi__errpuc("wrong version", "Unsupported version of PSD image"); + + // Skip 6 reserved bytes. + stbi__skip(s, 6 ); + + // Read the number of channels (R, G, B, A, etc). + channelCount = stbi__get16be(s); + if (channelCount < 0 || channelCount > 16) + return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image"); + + // Read the rows and columns of the image. + h = stbi__get32be(s); + w = stbi__get32be(s); + + // Make sure the depth is 8 bits. + bitdepth = stbi__get16be(s); + if (bitdepth != 8 && bitdepth != 16) + return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit"); + + // Make sure the color mode is RGB. + // Valid options are: + // 0: Bitmap + // 1: Grayscale + // 2: Indexed color + // 3: RGB color + // 4: CMYK color + // 7: Multichannel + // 8: Duotone + // 9: Lab color + if (stbi__get16be(s) != 3) + return stbi__errpuc("wrong color format", "PSD is not in RGB color format"); + + // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.) + stbi__skip(s,stbi__get32be(s) ); + + // Skip the image resources. (resolution, pen tool paths, etc) + stbi__skip(s, stbi__get32be(s) ); + + // Skip the reserved data. + stbi__skip(s, stbi__get32be(s) ); + + // Find out if the data is compressed. + // Known values: + // 0: no compression + // 1: RLE compressed + compression = stbi__get16be(s); + if (compression > 1) + return stbi__errpuc("bad compression", "PSD has an unknown compression format"); + + // Check size + if (!stbi__mad3sizes_valid(4, w, h, 0)) + return stbi__errpuc("too large", "Corrupt PSD"); + + // Create the destination image. + + if (!compression && bitdepth == 16 && bpc == 16) { + out = (stbi_uc *) stbi__malloc_mad3(8, w, h, 0); + ri->bits_per_channel = 16; + } else + out = (stbi_uc *) stbi__malloc(4 * w*h); + + if (!out) return stbi__errpuc("outofmem", "Out of memory"); + pixelCount = w*h; + + // Initialize the data to zero. + //memset( out, 0, pixelCount * 4 ); + + // Finally, the image data. + if (compression) { + // RLE as used by .PSD and .TIFF + // Loop until you get the number of unpacked bytes you are expecting: + // Read the next source byte into n. + // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally. + // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times. + // Else if n is 128, noop. + // Endloop + + // The RLE-compressed data is preceeded by a 2-byte data count for each row in the data, + // which we're going to just skip. + stbi__skip(s, h * channelCount * 2 ); + + // Read the RLE data by channel. + for (channel = 0; channel < 4; channel++) { + stbi_uc *p; + + p = out+channel; + if (channel >= channelCount) { + // Fill this channel with default data. + for (i = 0; i < pixelCount; i++, p += 4) + *p = (channel == 3 ? 255 : 0); + } else { + // Read the RLE data. + if (!stbi__psd_decode_rle(s, p, pixelCount)) { + STBI_FREE(out); + return stbi__errpuc("corrupt", "bad RLE data"); + } + } + } + + } else { + // We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...) + // where each channel consists of an 8-bit (or 16-bit) value for each pixel in the image. + + // Read the data by channel. + for (channel = 0; channel < 4; channel++) { + if (channel >= channelCount) { + // Fill this channel with default data. + if (bitdepth == 16 && bpc == 16) { + stbi__uint16 *q = ((stbi__uint16 *) out) + channel; + stbi__uint16 val = channel == 3 ? 65535 : 0; + for (i = 0; i < pixelCount; i++, q += 4) + *q = val; + } else { + stbi_uc *p = out+channel; + stbi_uc val = channel == 3 ? 255 : 0; + for (i = 0; i < pixelCount; i++, p += 4) + *p = val; + } + } else { + if (ri->bits_per_channel == 16) { // output bpc + stbi__uint16 *q = ((stbi__uint16 *) out) + channel; + for (i = 0; i < pixelCount; i++, q += 4) + *q = (stbi__uint16) stbi__get16be(s); + } else { + stbi_uc *p = out+channel; + if (bitdepth == 16) { // input bpc + for (i = 0; i < pixelCount; i++, p += 4) + *p = (stbi_uc) (stbi__get16be(s) >> 8); + } else { + for (i = 0; i < pixelCount; i++, p += 4) + *p = stbi__get8(s); + } + } + } + } + } + + // remove weird white matte from PSD + if (channelCount >= 4) { + if (ri->bits_per_channel == 16) { + for (i=0; i < w*h; ++i) { + stbi__uint16 *pixel = (stbi__uint16 *) out + 4*i; + if (pixel[3] != 0 && pixel[3] != 65535) { + float a = pixel[3] / 65535.0f; + float ra = 1.0f / a; + float inv_a = 65535.0f * (1 - ra); + pixel[0] = (stbi__uint16) (pixel[0]*ra + inv_a); + pixel[1] = (stbi__uint16) (pixel[1]*ra + inv_a); + pixel[2] = (stbi__uint16) (pixel[2]*ra + inv_a); + } + } + } else { + for (i=0; i < w*h; ++i) { + unsigned char *pixel = out + 4*i; + if (pixel[3] != 0 && pixel[3] != 255) { + float a = pixel[3] / 255.0f; + float ra = 1.0f / a; + float inv_a = 255.0f * (1 - ra); + pixel[0] = (unsigned char) (pixel[0]*ra + inv_a); + pixel[1] = (unsigned char) (pixel[1]*ra + inv_a); + pixel[2] = (unsigned char) (pixel[2]*ra + inv_a); + } + } + } + } + + // convert to desired output format + if (req_comp && req_comp != 4) { + if (ri->bits_per_channel == 16) + out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4, req_comp, w, h); + else + out = stbi__convert_format(out, 4, req_comp, w, h); + if (out == NULL) return out; // stbi__convert_format frees input on failure + } + + if (comp) *comp = 4; + *y = h; + *x = w; + + return out; +} +#endif + +// ************************************************************************************************* +// Softimage PIC loader +// by Tom Seddon +// +// See http://softimage.wiki.softimage.com/index.php/INFO:_PIC_file_format +// See http://ozviz.wasp.uwa.edu.au/~pbourke/dataformats/softimagepic/ + +#ifndef STBI_NO_PIC +static int stbi__pic_is4(stbi__context *s,const char *str) +{ + int i; + for (i=0; i<4; ++i) + if (stbi__get8(s) != (stbi_uc)str[i]) + return 0; + + return 1; +} + +static int stbi__pic_test_core(stbi__context *s) +{ + int i; + + if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) + return 0; + + for(i=0;i<84;++i) + stbi__get8(s); + + if (!stbi__pic_is4(s,"PICT")) + return 0; + + return 1; +} + +typedef struct +{ + stbi_uc size,type,channel; +} stbi__pic_packet; + +static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest) +{ + int mask=0x80, i; + + for (i=0; i<4; ++i, mask>>=1) { + if (channel & mask) { + if (stbi__at_eof(s)) return stbi__errpuc("bad file","PIC file too short"); + dest[i]=stbi__get8(s); + } + } + + return dest; +} + +static void stbi__copyval(int channel,stbi_uc *dest,const stbi_uc *src) +{ + int mask=0x80,i; + + for (i=0;i<4; ++i, mask>>=1) + if (channel&mask) + dest[i]=src[i]; +} + +static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, stbi_uc *result) +{ + int act_comp=0,num_packets=0,y,chained; + stbi__pic_packet packets[10]; + + // this will (should...) cater for even some bizarre stuff like having data + // for the same channel in multiple packets. + do { + stbi__pic_packet *packet; + + if (num_packets==sizeof(packets)/sizeof(packets[0])) + return stbi__errpuc("bad format","too many packets"); + + packet = &packets[num_packets++]; + + chained = stbi__get8(s); + packet->size = stbi__get8(s); + packet->type = stbi__get8(s); + packet->channel = stbi__get8(s); + + act_comp |= packet->channel; + + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (reading packets)"); + if (packet->size != 8) return stbi__errpuc("bad format","packet isn't 8bpp"); + } while (chained); + + *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel? + + for(y=0; y<height; ++y) { + int packet_idx; + + for(packet_idx=0; packet_idx < num_packets; ++packet_idx) { + stbi__pic_packet *packet = &packets[packet_idx]; + stbi_uc *dest = result+y*width*4; + + switch (packet->type) { + default: + return stbi__errpuc("bad format","packet has bad compression type"); + + case 0: {//uncompressed + int x; + + for(x=0;x<width;++x, dest+=4) + if (!stbi__readval(s,packet->channel,dest)) + return 0; + break; + } + + case 1://Pure RLE + { + int left=width, i; + + while (left>0) { + stbi_uc count,value[4]; + + count=stbi__get8(s); + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pure read count)"); + + if (count > left) + count = (stbi_uc) left; + + if (!stbi__readval(s,packet->channel,value)) return 0; + + for(i=0; i<count; ++i,dest+=4) + stbi__copyval(packet->channel,dest,value); + left -= count; + } + } + break; + + case 2: {//Mixed RLE + int left=width; + while (left>0) { + int count = stbi__get8(s), i; + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (mixed read count)"); + + if (count >= 128) { // Repeated + stbi_uc value[4]; + + if (count==128) + count = stbi__get16be(s); + else + count -= 127; + if (count > left) + return stbi__errpuc("bad file","scanline overrun"); + + if (!stbi__readval(s,packet->channel,value)) + return 0; + + for(i=0;i<count;++i, dest += 4) + stbi__copyval(packet->channel,dest,value); + } else { // Raw + ++count; + if (count>left) return stbi__errpuc("bad file","scanline overrun"); + + for(i=0;i<count;++i, dest+=4) + if (!stbi__readval(s,packet->channel,dest)) + return 0; + } + left-=count; + } + break; + } + } + } + } + + return result; +} + +static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp, stbi__result_info *ri) +{ + stbi_uc *result; + int i, x,y, internal_comp; + STBI_NOTUSED(ri); + + if (!comp) comp = &internal_comp; + + for (i=0; i<92; ++i) + stbi__get8(s); + + x = stbi__get16be(s); + y = stbi__get16be(s); + if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pic header)"); + if (!stbi__mad3sizes_valid(x, y, 4, 0)) return stbi__errpuc("too large", "PIC image too large to decode"); + + stbi__get32be(s); //skip `ratio' + stbi__get16be(s); //skip `fields' + stbi__get16be(s); //skip `pad' + + // intermediate buffer is RGBA + result = (stbi_uc *) stbi__malloc_mad3(x, y, 4, 0); + memset(result, 0xff, x*y*4); + + if (!stbi__pic_load_core(s,x,y,comp, result)) { + STBI_FREE(result); + result=0; + } + *px = x; + *py = y; + if (req_comp == 0) req_comp = *comp; + result=stbi__convert_format(result,4,req_comp,x,y); + + return result; +} + +static int stbi__pic_test(stbi__context *s) +{ + int r = stbi__pic_test_core(s); + stbi__rewind(s); + return r; +} +#endif + +// ************************************************************************************************* +// GIF loader -- public domain by Jean-Marc Lienher -- simplified/shrunk by stb + +#ifndef STBI_NO_GIF +typedef struct +{ + stbi__int16 prefix; + stbi_uc first; + stbi_uc suffix; +} stbi__gif_lzw; + +typedef struct +{ + int w,h; + stbi_uc *out; // output buffer (always 4 components) + stbi_uc *background; // The current "background" as far as a gif is concerned + stbi_uc *history; + int flags, bgindex, ratio, transparent, eflags; + stbi_uc pal[256][4]; + stbi_uc lpal[256][4]; + stbi__gif_lzw codes[8192]; + stbi_uc *color_table; + int parse, step; + int lflags; + int start_x, start_y; + int max_x, max_y; + int cur_x, cur_y; + int line_size; + int delay; +} stbi__gif; + +static int stbi__gif_test_raw(stbi__context *s) +{ + int sz; + if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') return 0; + sz = stbi__get8(s); + if (sz != '9' && sz != '7') return 0; + if (stbi__get8(s) != 'a') return 0; + return 1; +} + +static int stbi__gif_test(stbi__context *s) +{ + int r = stbi__gif_test_raw(s); + stbi__rewind(s); + return r; +} + +static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], int num_entries, int transp) +{ + int i; + for (i=0; i < num_entries; ++i) { + pal[i][2] = stbi__get8(s); + pal[i][1] = stbi__get8(s); + pal[i][0] = stbi__get8(s); + pal[i][3] = transp == i ? 0 : 255; + } +} + +static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_info) +{ + stbi_uc version; + if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8') + return stbi__err("not GIF", "Corrupt GIF"); + + version = stbi__get8(s); + if (version != '7' && version != '9') return stbi__err("not GIF", "Corrupt GIF"); + if (stbi__get8(s) != 'a') return stbi__err("not GIF", "Corrupt GIF"); + + stbi__g_failure_reason = ""; + g->w = stbi__get16le(s); + g->h = stbi__get16le(s); + g->flags = stbi__get8(s); + g->bgindex = stbi__get8(s); + g->ratio = stbi__get8(s); + g->transparent = -1; + + if (comp != 0) *comp = 4; // can't actually tell whether it's 3 or 4 until we parse the comments + + if (is_info) return 1; + + if (g->flags & 0x80) + stbi__gif_parse_colortable(s,g->pal, 2 << (g->flags & 7), -1); + + return 1; +} + +static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp) +{ + stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif)); + if (!stbi__gif_header(s, g, comp, 1)) { + STBI_FREE(g); + stbi__rewind( s ); + return 0; + } + if (x) *x = g->w; + if (y) *y = g->h; + STBI_FREE(g); + return 1; +} + +static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code) +{ + stbi_uc *p, *c; + int idx; + + // recurse to decode the prefixes, since the linked-list is backwards, + // and working backwards through an interleaved image would be nasty + if (g->codes[code].prefix >= 0) + stbi__out_gif_code(g, g->codes[code].prefix); + + if (g->cur_y >= g->max_y) return; + + idx = g->cur_x + g->cur_y; + p = &g->out[idx]; + g->history[idx / 4] = 1; + + c = &g->color_table[g->codes[code].suffix * 4]; + if (c[3] > 128) { // don't render transparent pixels; + p[0] = c[2]; + p[1] = c[1]; + p[2] = c[0]; + p[3] = c[3]; + } + g->cur_x += 4; + + if (g->cur_x >= g->max_x) { + g->cur_x = g->start_x; + g->cur_y += g->step; + + while (g->cur_y >= g->max_y && g->parse > 0) { + g->step = (1 << g->parse) * g->line_size; + g->cur_y = g->start_y + (g->step >> 1); + --g->parse; + } + } +} + +static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g) +{ + stbi_uc lzw_cs; + stbi__int32 len, init_code; + stbi__uint32 first; + stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear; + stbi__gif_lzw *p; + + lzw_cs = stbi__get8(s); + if (lzw_cs > 12) return NULL; + clear = 1 << lzw_cs; + first = 1; + codesize = lzw_cs + 1; + codemask = (1 << codesize) - 1; + bits = 0; + valid_bits = 0; + for (init_code = 0; init_code < clear; init_code++) { + g->codes[init_code].prefix = -1; + g->codes[init_code].first = (stbi_uc) init_code; + g->codes[init_code].suffix = (stbi_uc) init_code; + } + + // support no starting clear code + avail = clear+2; + oldcode = -1; + + len = 0; + for(;;) { + if (valid_bits < codesize) { + if (len == 0) { + len = stbi__get8(s); // start new block + if (len == 0) + return g->out; + } + --len; + bits |= (stbi__int32) stbi__get8(s) << valid_bits; + valid_bits += 8; + } else { + stbi__int32 code = bits & codemask; + bits >>= codesize; + valid_bits -= codesize; + // @OPTIMIZE: is there some way we can accelerate the non-clear path? + if (code == clear) { // clear code + codesize = lzw_cs + 1; + codemask = (1 << codesize) - 1; + avail = clear + 2; + oldcode = -1; + first = 0; + } else if (code == clear + 1) { // end of stream code + stbi__skip(s, len); + while ((len = stbi__get8(s)) > 0) + stbi__skip(s,len); + return g->out; + } else if (code <= avail) { + if (first) { + return stbi__errpuc("no clear code", "Corrupt GIF"); + } + + if (oldcode >= 0) { + p = &g->codes[avail++]; + if (avail > 8192) { + return stbi__errpuc("too many codes", "Corrupt GIF"); + } + + p->prefix = (stbi__int16) oldcode; + p->first = g->codes[oldcode].first; + p->suffix = (code == avail) ? p->first : g->codes[code].first; + } else if (code == avail) + return stbi__errpuc("illegal code in raster", "Corrupt GIF"); + + stbi__out_gif_code(g, (stbi__uint16) code); + + if ((avail & codemask) == 0 && avail <= 0x0FFF) { + codesize++; + codemask = (1 << codesize) - 1; + } + + oldcode = code; + } else { + return stbi__errpuc("illegal code in raster", "Corrupt GIF"); + } + } + } +} + +// this function is designed to support animated gifs, although stb_image doesn't support it +// two back is the image from two frames ago, used for a very specific disposal format +static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp, stbi_uc *two_back) +{ + int dispose; + int first_frame; + int pi; + int pcount; + + // on first frame, any non-written pixels get the background colour (non-transparent) + first_frame = 0; + if (g->out == 0) { + if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header + g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h); + g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h); + g->history = (stbi_uc *) stbi__malloc(g->w * g->h); + if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory"); + + // image is treated as "tranparent" at the start - ie, nothing overwrites the current background; + // background colour is only used for pixels that are not rendered first frame, after that "background" + // color refers to teh color that was there the previous frame. + memset( g->out, 0x00, 4 * g->w * g->h ); + memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent) + memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame + first_frame = 1; + } else { + // second frame - how do we dispoase of the previous one? + dispose = (g->eflags & 0x1C) >> 2; + pcount = g->w * g->h; + + if ((dispose == 3) && (two_back == 0)) { + dispose = 2; // if I don't have an image to revert back to, default to the old background + } + + if (dispose == 3) { // use previous graphic + for (pi = 0; pi < pcount; ++pi) { + if (g->history[pi]) { + memcpy( &g->out[pi * 4], &two_back[pi * 4], 4 ); + } + } + } else if (dispose == 2) { + // restore what was changed last frame to background before that frame; + for (pi = 0; pi < pcount; ++pi) { + if (g->history[pi]) { + memcpy( &g->out[pi * 4], &g->background[pi * 4], 4 ); + } + } + } else { + // This is a non-disposal case eithe way, so just + // leave the pixels as is, and they will become the new background + // 1: do not dispose + // 0: not specified. + } + + // background is what out is after the undoing of the previou frame; + memcpy( g->background, g->out, 4 * g->w * g->h ); + } + + // clear my history; + memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame + + for (;;) { + int tag = stbi__get8(s); + switch (tag) { + case 0x2C: /* Image Descriptor */ + { + stbi__int32 x, y, w, h; + stbi_uc *o; + + x = stbi__get16le(s); + y = stbi__get16le(s); + w = stbi__get16le(s); + h = stbi__get16le(s); + if (((x + w) > (g->w)) || ((y + h) > (g->h))) + return stbi__errpuc("bad Image Descriptor", "Corrupt GIF"); + + g->line_size = g->w * 4; + g->start_x = x * 4; + g->start_y = y * g->line_size; + g->max_x = g->start_x + w * 4; + g->max_y = g->start_y + h * g->line_size; + g->cur_x = g->start_x; + g->cur_y = g->start_y; + + g->lflags = stbi__get8(s); + + if (g->lflags & 0x40) { + g->step = 8 * g->line_size; // first interlaced spacing + g->parse = 3; + } else { + g->step = g->line_size; + g->parse = 0; + } + + if (g->lflags & 0x80) { + stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1); + g->color_table = (stbi_uc *) g->lpal; + } else if (g->flags & 0x80) { + g->color_table = (stbi_uc *) g->pal; + } else + return stbi__errpuc("missing color table", "Corrupt GIF"); + + o = stbi__process_gif_raster(s, g); + if (o == NULL) return NULL; + + // if this was the first frame, + pcount = g->w * g->h; + if (first_frame && (g->bgindex > 0)) { + // if first frame, any pixel not drawn to gets the background color + for (pi = 0; pi < pcount; ++pi) { + if (g->history[pi] == 0) { + g->pal[g->bgindex][3] = 255; // just in case it was made transparent, undo that; It will be reset next frame if need be; + memcpy( &g->out[pi * 4], &g->pal[g->bgindex], 4 ); + } + } + } + + return o; + } + + case 0x21: // Comment Extension. + { + int len; + int ext = stbi__get8(s); + if (ext == 0xF9) { // Graphic Control Extension. + len = stbi__get8(s); + if (len == 4) { + g->eflags = stbi__get8(s); + g->delay = 10 * stbi__get16le(s); // delay - 1/100th of a second, saving as 1/1000ths. + + // unset old transparent + if (g->transparent >= 0) { + g->pal[g->transparent][3] = 255; + } + if (g->eflags & 0x01) { + g->transparent = stbi__get8(s); + if (g->transparent >= 0) { + g->pal[g->transparent][3] = 0; + } + } else { + // don't need transparent + stbi__skip(s, 1); + g->transparent = -1; + } + } else { + stbi__skip(s, len); + break; + } + } + while ((len = stbi__get8(s)) != 0) { + stbi__skip(s, len); + } + break; + } + + case 0x3B: // gif stream termination code + return (stbi_uc *) s; // using '1' causes warning on some compilers + + default: + return stbi__errpuc("unknown code", "Corrupt GIF"); + } + } +} + +static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp) +{ + if (stbi__gif_test(s)) { + int layers = 0; + stbi_uc *u = 0; + stbi_uc *out = 0; + stbi_uc *two_back = 0; + stbi__gif g; + int stride; + memset(&g, 0, sizeof(g)); + if (delays) { + *delays = 0; + } + + do { + u = stbi__gif_load_next(s, &g, comp, req_comp, two_back); + if (u == (stbi_uc *) s) u = 0; // end of animated gif marker + + if (u) { + *x = g.w; + *y = g.h; + ++layers; + stride = g.w * g.h * 4; + + if (out) { + out = (stbi_uc*) STBI_REALLOC( out, layers * stride ); + if (delays) { + *delays = (int*) STBI_REALLOC( *delays, sizeof(int) * layers ); + } + } else { + out = (stbi_uc*)stbi__malloc( layers * stride ); + if (delays) { + *delays = (int*) stbi__malloc( layers * sizeof(int) ); + } + } + memcpy( out + ((layers - 1) * stride), u, stride ); + if (layers >= 2) { + two_back = out - 2 * stride; + } + + if (delays) { + (*delays)[layers - 1U] = g.delay; + } + } + } while (u != 0); + + // free temp buffer; + STBI_FREE(g.out); + STBI_FREE(g.history); + STBI_FREE(g.background); + + // do the final conversion after loading everything; + if (req_comp && req_comp != 4) + out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h); + + *z = layers; + return out; + } else { + return stbi__errpuc("not GIF", "Image was not as a gif type."); + } +} + +static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi_uc *u = 0; + stbi__gif g; + memset(&g, 0, sizeof(g)); + + u = stbi__gif_load_next(s, &g, comp, req_comp, 0); + if (u == (stbi_uc *) s) u = 0; // end of animated gif marker + if (u) { + *x = g.w; + *y = g.h; + + // moved conversion to after successful load so that the same + // can be done for multiple frames. + if (req_comp && req_comp != 4) + u = stbi__convert_format(u, 4, req_comp, g.w, g.h); + } + + // free buffers needed for multiple frame loading; + STBI_FREE(g.history); + STBI_FREE(g.background); + + return u; +} + +static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp) +{ + return stbi__gif_info_raw(s,x,y,comp); +} +#endif + +// ************************************************************************************************* +// Radiance RGBE HDR loader +// originally by Nicolas Schulz +#ifndef STBI_NO_HDR +static int stbi__hdr_test_core(stbi__context *s, const char *signature) +{ + int i; + for (i=0; signature[i]; ++i) + if (stbi__get8(s) != signature[i]) + return 0; + stbi__rewind(s); + return 1; +} + +static int stbi__hdr_test(stbi__context* s) +{ + int r = stbi__hdr_test_core(s, "#?RADIANCE\n"); + stbi__rewind(s); + if(!r) { + r = stbi__hdr_test_core(s, "#?RGBE\n"); + stbi__rewind(s); + } + return r; +} + +#define STBI__HDR_BUFLEN 1024 +static char *stbi__hdr_gettoken(stbi__context *z, char *buffer) +{ + int len=0; + char c = '\0'; + + c = (char) stbi__get8(z); + + while (!stbi__at_eof(z) && c != '\n') { + buffer[len++] = c; + if (len == STBI__HDR_BUFLEN-1) { + // flush to end of line + while (!stbi__at_eof(z) && stbi__get8(z) != '\n') + ; + break; + } + c = (char) stbi__get8(z); + } + + buffer[len] = 0; + return buffer; +} + +static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp) +{ + if ( input[3] != 0 ) { + float f1; + // Exponent + f1 = (float) ldexp(1.0f, input[3] - (int)(128 + 8)); + if (req_comp <= 2) + output[0] = (input[0] + input[1] + input[2]) * f1 / 3; + else { + output[0] = input[0] * f1; + output[1] = input[1] * f1; + output[2] = input[2] * f1; + } + if (req_comp == 2) output[1] = 1; + if (req_comp == 4) output[3] = 1; + } else { + switch (req_comp) { + case 4: output[3] = 1; /* fallthrough */ + case 3: output[0] = output[1] = output[2] = 0; + break; + case 2: output[1] = 1; /* fallthrough */ + case 1: output[0] = 0; + break; + } + } +} + +static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + char buffer[STBI__HDR_BUFLEN]; + char *token; + int valid = 0; + int width, height; + stbi_uc *scanline; + float *hdr_data; + int len; + unsigned char count, value; + int i, j, k, c1,c2, z; + const char *headerToken; + STBI_NOTUSED(ri); + + // Check identifier + headerToken = stbi__hdr_gettoken(s,buffer); + if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0) + return stbi__errpf("not HDR", "Corrupt HDR image"); + + // Parse header + for(;;) { + token = stbi__hdr_gettoken(s,buffer); + if (token[0] == 0) break; + if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; + } + + if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format"); + + // Parse width and height + // can't use sscanf() if we're not using stdio! + token = stbi__hdr_gettoken(s,buffer); + if (strncmp(token, "-Y ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format"); + token += 3; + height = (int) strtol(token, &token, 10); + while (*token == ' ') ++token; + if (strncmp(token, "+X ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format"); + token += 3; + width = (int) strtol(token, NULL, 10); + + *x = width; + *y = height; + + if (comp) *comp = 3; + if (req_comp == 0) req_comp = 3; + + if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0)) + return stbi__errpf("too large", "HDR image is too large"); + + // Read data + hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0); + if (!hdr_data) + return stbi__errpf("outofmem", "Out of memory"); + + // Load image data + // image data is stored as some number of sca + if ( width < 8 || width >= 32768) { + // Read flat data + for (j=0; j < height; ++j) { + for (i=0; i < width; ++i) { + stbi_uc rgbe[4]; + main_decode_loop: + stbi__getn(s, rgbe, 4); + stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp); + } + } + } else { + // Read RLE-encoded data + scanline = NULL; + + for (j = 0; j < height; ++j) { + c1 = stbi__get8(s); + c2 = stbi__get8(s); + len = stbi__get8(s); + if (c1 != 2 || c2 != 2 || (len & 0x80)) { + // not run-length encoded, so we have to actually use THIS data as a decoded + // pixel (note this can't be a valid pixel--one of RGB must be >= 128) + stbi_uc rgbe[4]; + rgbe[0] = (stbi_uc) c1; + rgbe[1] = (stbi_uc) c2; + rgbe[2] = (stbi_uc) len; + rgbe[3] = (stbi_uc) stbi__get8(s); + stbi__hdr_convert(hdr_data, rgbe, req_comp); + i = 1; + j = 0; + STBI_FREE(scanline); + goto main_decode_loop; // yes, this makes no sense + } + len <<= 8; + len |= stbi__get8(s); + if (len != width) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); } + if (scanline == NULL) { + scanline = (stbi_uc *) stbi__malloc_mad2(width, 4, 0); + if (!scanline) { + STBI_FREE(hdr_data); + return stbi__errpf("outofmem", "Out of memory"); + } + } + + for (k = 0; k < 4; ++k) { + int nleft; + i = 0; + while ((nleft = width - i) > 0) { + count = stbi__get8(s); + if (count > 128) { + // Run + value = stbi__get8(s); + count -= 128; + if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); } + for (z = 0; z < count; ++z) + scanline[i++ * 4 + k] = value; + } else { + // Dump + if (count > nleft) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("corrupt", "bad RLE data in HDR"); } + for (z = 0; z < count; ++z) + scanline[i++ * 4 + k] = stbi__get8(s); + } + } + } + for (i=0; i < width; ++i) + stbi__hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp); + } + if (scanline) + STBI_FREE(scanline); + } + + return hdr_data; +} + +static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp) +{ + char buffer[STBI__HDR_BUFLEN]; + char *token; + int valid = 0; + int dummy; + + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + + if (stbi__hdr_test(s) == 0) { + stbi__rewind( s ); + return 0; + } + + for(;;) { + token = stbi__hdr_gettoken(s,buffer); + if (token[0] == 0) break; + if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; + } + + if (!valid) { + stbi__rewind( s ); + return 0; + } + token = stbi__hdr_gettoken(s,buffer); + if (strncmp(token, "-Y ", 3)) { + stbi__rewind( s ); + return 0; + } + token += 3; + *y = (int) strtol(token, &token, 10); + while (*token == ' ') ++token; + if (strncmp(token, "+X ", 3)) { + stbi__rewind( s ); + return 0; + } + token += 3; + *x = (int) strtol(token, NULL, 10); + *comp = 3; + return 1; +} +#endif // STBI_NO_HDR + +#ifndef STBI_NO_BMP +static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp) +{ + void *p; + stbi__bmp_data info; + + info.all_a = 255; + p = stbi__bmp_parse_header(s, &info); + stbi__rewind( s ); + if (p == NULL) + return 0; + if (x) *x = s->img_x; + if (y) *y = s->img_y; + if (comp) *comp = info.ma ? 4 : 3; + return 1; +} +#endif + +#ifndef STBI_NO_PSD +static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp) +{ + int channelCount, dummy, depth; + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + if (stbi__get32be(s) != 0x38425053) { + stbi__rewind( s ); + return 0; + } + if (stbi__get16be(s) != 1) { + stbi__rewind( s ); + return 0; + } + stbi__skip(s, 6); + channelCount = stbi__get16be(s); + if (channelCount < 0 || channelCount > 16) { + stbi__rewind( s ); + return 0; + } + *y = stbi__get32be(s); + *x = stbi__get32be(s); + depth = stbi__get16be(s); + if (depth != 8 && depth != 16) { + stbi__rewind( s ); + return 0; + } + if (stbi__get16be(s) != 3) { + stbi__rewind( s ); + return 0; + } + *comp = 4; + return 1; +} + +static int stbi__psd_is16(stbi__context *s) +{ + int channelCount, depth; + if (stbi__get32be(s) != 0x38425053) { + stbi__rewind( s ); + return 0; + } + if (stbi__get16be(s) != 1) { + stbi__rewind( s ); + return 0; + } + stbi__skip(s, 6); + channelCount = stbi__get16be(s); + if (channelCount < 0 || channelCount > 16) { + stbi__rewind( s ); + return 0; + } + (void) stbi__get32be(s); + (void) stbi__get32be(s); + depth = stbi__get16be(s); + if (depth != 16) { + stbi__rewind( s ); + return 0; + } + return 1; +} +#endif + +#ifndef STBI_NO_PIC +static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp) +{ + int act_comp=0,num_packets=0,chained,dummy; + stbi__pic_packet packets[10]; + + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + + if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) { + stbi__rewind(s); + return 0; + } + + stbi__skip(s, 88); + + *x = stbi__get16be(s); + *y = stbi__get16be(s); + if (stbi__at_eof(s)) { + stbi__rewind( s); + return 0; + } + if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) { + stbi__rewind( s ); + return 0; + } + + stbi__skip(s, 8); + + do { + stbi__pic_packet *packet; + + if (num_packets==sizeof(packets)/sizeof(packets[0])) + return 0; + + packet = &packets[num_packets++]; + chained = stbi__get8(s); + packet->size = stbi__get8(s); + packet->type = stbi__get8(s); + packet->channel = stbi__get8(s); + act_comp |= packet->channel; + + if (stbi__at_eof(s)) { + stbi__rewind( s ); + return 0; + } + if (packet->size != 8) { + stbi__rewind( s ); + return 0; + } + } while (chained); + + *comp = (act_comp & 0x10 ? 4 : 3); + + return 1; +} +#endif + +// ************************************************************************************************* +// Portable Gray Map and Portable Pixel Map loader +// by Ken Miller +// +// PGM: http://netpbm.sourceforge.net/doc/pgm.html +// PPM: http://netpbm.sourceforge.net/doc/ppm.html +// +// Known limitations: +// Does not support comments in the header section +// Does not support ASCII image data (formats P2 and P3) +// Does not support 16-bit-per-channel + +#ifndef STBI_NO_PNM + +static int stbi__pnm_test(stbi__context *s) +{ + char p, t; + p = (char) stbi__get8(s); + t = (char) stbi__get8(s); + if (p != 'P' || (t != '5' && t != '6')) { + stbi__rewind( s ); + return 0; + } + return 1; +} + +static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) +{ + stbi_uc *out; + STBI_NOTUSED(ri); + + if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n)) + return 0; + + *x = s->img_x; + *y = s->img_y; + if (comp) *comp = s->img_n; + + if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0)) + return stbi__errpuc("too large", "PNM too large"); + + out = (stbi_uc *) stbi__malloc_mad3(s->img_n, s->img_x, s->img_y, 0); + if (!out) return stbi__errpuc("outofmem", "Out of memory"); + stbi__getn(s, out, s->img_n * s->img_x * s->img_y); + + if (req_comp && req_comp != s->img_n) { + out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y); + if (out == NULL) return out; // stbi__convert_format frees input on failure + } + return out; +} + +static int stbi__pnm_isspace(char c) +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; +} + +static void stbi__pnm_skip_whitespace(stbi__context *s, char *c) +{ + for (;;) { + while (!stbi__at_eof(s) && stbi__pnm_isspace(*c)) + *c = (char) stbi__get8(s); + + if (stbi__at_eof(s) || *c != '#') + break; + + while (!stbi__at_eof(s) && *c != '\n' && *c != '\r' ) + *c = (char) stbi__get8(s); + } +} + +static int stbi__pnm_isdigit(char c) +{ + return c >= '0' && c <= '9'; +} + +static int stbi__pnm_getinteger(stbi__context *s, char *c) +{ + int value = 0; + + while (!stbi__at_eof(s) && stbi__pnm_isdigit(*c)) { + value = value*10 + (*c - '0'); + *c = (char) stbi__get8(s); + } + + return value; +} + +static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp) +{ + int maxv, dummy; + char c, p, t; + + if (!x) x = &dummy; + if (!y) y = &dummy; + if (!comp) comp = &dummy; + + stbi__rewind(s); + + // Get identifier + p = (char) stbi__get8(s); + t = (char) stbi__get8(s); + if (p != 'P' || (t != '5' && t != '6')) { + stbi__rewind(s); + return 0; + } + + *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm + + c = (char) stbi__get8(s); + stbi__pnm_skip_whitespace(s, &c); + + *x = stbi__pnm_getinteger(s, &c); // read width + stbi__pnm_skip_whitespace(s, &c); + + *y = stbi__pnm_getinteger(s, &c); // read height + stbi__pnm_skip_whitespace(s, &c); + + maxv = stbi__pnm_getinteger(s, &c); // read max value + + if (maxv > 255) + return stbi__err("max value > 255", "PPM image not 8-bit"); + else + return 1; +} +#endif + +static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp) +{ + #ifndef STBI_NO_JPEG + if (stbi__jpeg_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_PNG + if (stbi__png_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_GIF + if (stbi__gif_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_BMP + if (stbi__bmp_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_PSD + if (stbi__psd_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_PIC + if (stbi__pic_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_PNM + if (stbi__pnm_info(s, x, y, comp)) return 1; + #endif + + #ifndef STBI_NO_HDR + if (stbi__hdr_info(s, x, y, comp)) return 1; + #endif + + // test tga last because it's a crappy test! + #ifndef STBI_NO_TGA + if (stbi__tga_info(s, x, y, comp)) + return 1; + #endif + return stbi__err("unknown image type", "Image not of any known type, or corrupt"); +} + +static int stbi__is_16_main(stbi__context *s) +{ + #ifndef STBI_NO_PNG + if (stbi__png_is16(s)) return 1; + #endif + + #ifndef STBI_NO_PSD + if (stbi__psd_is16(s)) return 1; + #endif + + return 0; +} + +#ifndef STBI_NO_STDIO +STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp) +{ + FILE *f = stbi__fopen(filename, "rb"); + int result; + if (!f) return stbi__err("can't fopen", "Unable to open file"); + result = stbi_info_from_file(f, x, y, comp); + fclose(f); + return result; +} + +STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) +{ + int r; + stbi__context s; + long pos = ftell(f); + stbi__start_file(&s, f); + r = stbi__info_main(&s,x,y,comp); + fseek(f,pos,SEEK_SET); + return r; +} + +STBIDEF int stbi_is_16_bit(char const *filename) +{ + FILE *f = stbi__fopen(filename, "rb"); + int result; + if (!f) return stbi__err("can't fopen", "Unable to open file"); + result = stbi_is_16_bit_from_file(f); + fclose(f); + return result; +} + +STBIDEF int stbi_is_16_bit_from_file(FILE *f) +{ + int r; + stbi__context s; + long pos = ftell(f); + stbi__start_file(&s, f); + r = stbi__is_16_main(&s); + fseek(f,pos,SEEK_SET); + return r; +} +#endif // !STBI_NO_STDIO + +STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__info_main(&s,x,y,comp); +} + +STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int *x, int *y, int *comp) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); + return stbi__info_main(&s,x,y,comp); +} + +STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const *buffer, int len) +{ + stbi__context s; + stbi__start_mem(&s,buffer,len); + return stbi__is_16_main(&s); +} + +STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user) +{ + stbi__context s; + stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); + return stbi__is_16_main(&s); +} + +#endif // STB_IMAGE_IMPLEMENTATION + +/* + revision history: + 2.19 (2018-02-11) fix warning + 2.18 (2018-01-30) fix warnings + 2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug + 1-bit BMP + *_is_16_bit api + avoid warnings + 2.16 (2017-07-23) all functions have 16-bit variants; + STBI_NO_STDIO works again; + compilation fixes; + fix rounding in unpremultiply; + optimize vertical flip; + disable raw_len validation; + documentation fixes + 2.15 (2017-03-18) fix png-1,2,4 bug; now all Imagenet JPGs decode; + warning fixes; disable run-time SSE detection on gcc; + uniform handling of optional "return" values; + thread-safe initialization of zlib tables + 2.14 (2017-03-03) remove deprecated STBI_JPEG_OLD; fixes for Imagenet JPGs + 2.13 (2016-11-29) add 16-bit API, only supported for PNG right now + 2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes + 2.11 (2016-04-02) allocate large structures on the stack + remove white matting for transparent PSD + fix reported channel count for PNG & BMP + re-enable SSE2 in non-gcc 64-bit + support RGB-formatted JPEG + read 16-bit PNGs (only as 8-bit) + 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED + 2.09 (2016-01-16) allow comments in PNM files + 16-bit-per-pixel TGA (not bit-per-component) + info() for TGA could break due to .hdr handling + info() for BMP to shares code instead of sloppy parse + can use STBI_REALLOC_SIZED if allocator doesn't support realloc + code cleanup + 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA + 2.07 (2015-09-13) fix compiler warnings + partial animated GIF support + limited 16-bpc PSD support + #ifdef unused functions + bug with < 92 byte PIC,PNM,HDR,TGA + 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value + 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning + 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit + 2.03 (2015-04-12) extra corruption checking (mmozeiko) + stbi_set_flip_vertically_on_load (nguillemot) + fix NEON support; fix mingw support + 2.02 (2015-01-19) fix incorrect assert, fix warning + 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse2 + 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG + 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg) + progressive JPEG (stb) + PGM/PPM support (Ken Miller) + STBI_MALLOC,STBI_REALLOC,STBI_FREE + GIF bugfix -- seemingly never worked + STBI_NO_*, STBI_ONLY_* + 1.48 (2014-12-14) fix incorrectly-named assert() + 1.47 (2014-12-14) 1/2/4-bit PNG support, both direct and paletted (Omar Cornut & stb) + optimize PNG (ryg) + fix bug in interlaced PNG with user-specified channel count (stb) + 1.46 (2014-08-26) + fix broken tRNS chunk (colorkey-style transparency) in non-paletted PNG + 1.45 (2014-08-16) + fix MSVC-ARM internal compiler error by wrapping malloc + 1.44 (2014-08-07) + various warning fixes from Ronny Chevalier + 1.43 (2014-07-15) + fix MSVC-only compiler problem in code changed in 1.42 + 1.42 (2014-07-09) + don't define _CRT_SECURE_NO_WARNINGS (affects user code) + fixes to stbi__cleanup_jpeg path + added STBI_ASSERT to avoid requiring assert.h + 1.41 (2014-06-25) + fix search&replace from 1.36 that messed up comments/error messages + 1.40 (2014-06-22) + fix gcc struct-initialization warning + 1.39 (2014-06-15) + fix to TGA optimization when req_comp != number of components in TGA; + fix to GIF loading because BMP wasn't rewinding (whoops, no GIFs in my test suite) + add support for BMP version 5 (more ignored fields) + 1.38 (2014-06-06) + suppress MSVC warnings on integer casts truncating values + fix accidental rename of 'skip' field of I/O + 1.37 (2014-06-04) + remove duplicate typedef + 1.36 (2014-06-03) + convert to header file single-file library + if de-iphone isn't set, load iphone images color-swapped instead of returning NULL + 1.35 (2014-05-27) + various warnings + fix broken STBI_SIMD path + fix bug where stbi_load_from_file no longer left file pointer in correct place + fix broken non-easy path for 32-bit BMP (possibly never used) + TGA optimization by Arseny Kapoulkine + 1.34 (unknown) + use STBI_NOTUSED in stbi__resample_row_generic(), fix one more leak in tga failure case + 1.33 (2011-07-14) + make stbi_is_hdr work in STBI_NO_HDR (as specified), minor compiler-friendly improvements + 1.32 (2011-07-13) + support for "info" function for all supported filetypes (SpartanJ) + 1.31 (2011-06-20) + a few more leak fixes, bug in PNG handling (SpartanJ) + 1.30 (2011-06-11) + added ability to load files via callbacks to accomidate custom input streams (Ben Wenger) + removed deprecated format-specific test/load functions + removed support for installable file formats (stbi_loader) -- would have been broken for IO callbacks anyway + error cases in bmp and tga give messages and don't leak (Raymond Barbiero, grisha) + fix inefficiency in decoding 32-bit BMP (David Woo) + 1.29 (2010-08-16) + various warning fixes from Aurelien Pocheville + 1.28 (2010-08-01) + fix bug in GIF palette transparency (SpartanJ) + 1.27 (2010-08-01) + cast-to-stbi_uc to fix warnings + 1.26 (2010-07-24) + fix bug in file buffering for PNG reported by SpartanJ + 1.25 (2010-07-17) + refix trans_data warning (Won Chun) + 1.24 (2010-07-12) + perf improvements reading from files on platforms with lock-heavy fgetc() + minor perf improvements for jpeg + deprecated type-specific functions so we'll get feedback if they're needed + attempt to fix trans_data warning (Won Chun) + 1.23 fixed bug in iPhone support + 1.22 (2010-07-10) + removed image *writing* support + stbi_info support from Jetro Lauha + GIF support from Jean-Marc Lienher + iPhone PNG-extensions from James Brown + warning-fixes from Nicolas Schulz and Janez Zemva (i.stbi__err. Janez (U+017D)emva) + 1.21 fix use of 'stbi_uc' in header (reported by jon blow) + 1.20 added support for Softimage PIC, by Tom Seddon + 1.19 bug in interlaced PNG corruption check (found by ryg) + 1.18 (2008-08-02) + fix a threading bug (local mutable static) + 1.17 support interlaced PNG + 1.16 major bugfix - stbi__convert_format converted one too many pixels + 1.15 initialize some fields for thread safety + 1.14 fix threadsafe conversion bug + header-file-only version (#define STBI_HEADER_FILE_ONLY before including) + 1.13 threadsafe + 1.12 const qualifiers in the API + 1.11 Support installable IDCT, colorspace conversion routines + 1.10 Fixes for 64-bit (don't use "unsigned long") + optimized upsampling by Fabian "ryg" Giesen + 1.09 Fix format-conversion for PSD code (bad global variables!) + 1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz + 1.07 attempt to fix C++ warning/errors again + 1.06 attempt to fix C++ warning/errors again + 1.05 fix TGA loading to return correct *comp and use good luminance calc + 1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free + 1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR + 1.02 support for (subset of) HDR files, float interface for preferred access to them + 1.01 fix bug: possible bug in handling right-side up bmps... not sure + fix bug: the stbi__bmp_load() and stbi__tga_load() functions didn't work at all + 1.00 interface to zlib that skips zlib header + 0.99 correct handling of alpha in palette + 0.98 TGA loader by lonesock; dynamically add loaders (untested) + 0.97 jpeg errors on too large a file; also catch another malloc failure + 0.96 fix detection of invalid v value - particleman@mollyrocket forum + 0.95 during header scan, seek to markers in case of padding + 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same + 0.93 handle jpegtran output; verbose errors + 0.92 read 4,8,16,24,32-bit BMP files of several formats + 0.91 output 24-bit Windows 3.0 BMP files + 0.90 fix a few more warnings; bump version number to approach 1.0 + 0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd + 0.60 fix compiling as c++ + 0.59 fix warnings: merge Dave Moore's -Wall fixes + 0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian + 0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less than 16 available + 0.56 fix bug: zlib uncompressed mode len vs. nlen + 0.55 fix bug: restart_interval not initialized to 0 + 0.54 allow NULL for 'int *comp' + 0.53 fix bug in png 3->4; speedup png decoding + 0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments + 0.51 obey req_comp requests, 1-component jpegs return as 1-component, + on 'test' only check type, not whether we support this variant + 0.50 (2006-11-19) + first released version +*/ + + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ diff --git a/src/stb_image_write.h b/src/stb_image_write.h new file mode 100644 index 0000000..0ad7300 --- /dev/null +++ b/src/stb_image_write.h @@ -0,0 +1,1568 @@ +/* stb_image_write - v1.09 - public domain - http://nothings.org/stb/stb_image_write.h + writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015 + no warranty implied; use at your own risk + + Before #including, + + #define STB_IMAGE_WRITE_IMPLEMENTATION + + in the file that you want to have the implementation. + + Will probably not work correctly with strict-aliasing optimizations. + + If using a modern Microsoft Compiler, non-safe versions of CRT calls may cause + compilation warnings or even errors. To avoid this, also before #including, + + #define STBI_MSC_SECURE_CRT + +ABOUT: + + This header file is a library for writing images to C stdio. It could be + adapted to write to memory or a general streaming interface; let me know. + + The PNG output is not optimal; it is 20-50% larger than the file + written by a decent optimizing implementation; though providing a custom + zlib compress function (see STBIW_ZLIB_COMPRESS) can mitigate that. + This library is designed for source code compactness and simplicity, + not optimal image file size or run-time performance. + +BUILDING: + + You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h. + You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace + malloc,realloc,free. + You can #define STBIW_MEMMOVE() to replace memmove() + You can #define STBIW_ZLIB_COMPRESS to use a custom zlib-style compress function + for PNG compression (instead of the builtin one), it must have the following signature: + unsigned char * my_compress(unsigned char *data, int data_len, int *out_len, int quality); + The returned data will be freed with STBIW_FREE() (free() by default), + so it must be heap allocated with STBIW_MALLOC() (malloc() by default), + +USAGE: + + There are five functions, one for each image file format: + + int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); + int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); + int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); + int stbi_write_jpg(char const *filename, int w, int h, int comp, const void *data, int quality); + int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); + + void stbi_flip_vertically_on_write(int flag); // flag is non-zero to flip data vertically + + There are also five equivalent functions that use an arbitrary write function. You are + expected to open/close your file-equivalent before and after calling these: + + int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes); + int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); + int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); + int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data); + int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality); + + where the callback is: + void stbi_write_func(void *context, void *data, int size); + + You can configure it with these global variables: + int stbi_write_tga_with_rle; // defaults to true; set to 0 to disable RLE + int stbi_write_png_compression_level; // defaults to 8; set to higher for more compression + int stbi_write_force_png_filter; // defaults to -1; set to 0..5 to force a filter mode + + + You can define STBI_WRITE_NO_STDIO to disable the file variant of these + functions, so the library will not use stdio.h at all. However, this will + also disable HDR writing, because it requires stdio for formatted output. + + Each function returns 0 on failure and non-0 on success. + + The functions create an image file defined by the parameters. The image + is a rectangle of pixels stored from left-to-right, top-to-bottom. + Each pixel contains 'comp' channels of data stored interleaved with 8-bits + per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is + monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall. + The *data pointer points to the first byte of the top-left-most pixel. + For PNG, "stride_in_bytes" is the distance in bytes from the first byte of + a row of pixels to the first byte of the next row of pixels. + + PNG creates output files with the same number of components as the input. + The BMP format expands Y to RGB in the file format and does not + output alpha. + + PNG supports writing rectangles of data even when the bytes storing rows of + data are not consecutive in memory (e.g. sub-rectangles of a larger image), + by supplying the stride between the beginning of adjacent rows. The other + formats do not. (Thus you cannot write a native-format BMP through the BMP + writer, both because it is in BGR order and because it may have padding + at the end of the line.) + + PNG allows you to set the deflate compression level by setting the global + variable 'stbi_write_png_compression_level' (it defaults to 8). + + HDR expects linear float data. Since the format is always 32-bit rgb(e) + data, alpha (if provided) is discarded, and for monochrome data it is + replicated across all three channels. + + TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed + data, set the global variable 'stbi_write_tga_with_rle' to 0. + + JPEG does ignore alpha channels in input data; quality is between 1 and 100. + Higher quality looks better but results in a bigger image. + JPEG baseline (no JPEG progressive). + +CREDITS: + + + Sean Barrett - PNG/BMP/TGA + Baldur Karlsson - HDR + Jean-Sebastien Guay - TGA monochrome + Tim Kelsey - misc enhancements + Alan Hickman - TGA RLE + Emmanuel Julien - initial file IO callback implementation + Jon Olick - original jo_jpeg.cpp code + Daniel Gibson - integrate JPEG, allow external zlib + Aarni Koskela - allow choosing PNG filter + + bugfixes: + github:Chribba + Guillaume Chereau + github:jry2 + github:romigrou + Sergio Gonzalez + Jonas Karlsson + Filip Wasil + Thatcher Ulrich + github:poppolopoppo + Patrick Boettcher + github:xeekworx + Cap Petschulat + Simon Rodriguez + Ivan Tikhonov + github:ignotion + Adam Schackart + +LICENSE + + See end of file for license information. + +*/ +#pragma once +#ifndef INCLUDE_STB_IMAGE_WRITE_H +#define INCLUDE_STB_IMAGE_WRITE_H +#include "define_inc.h" +// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline' +#ifndef STBIWDEF +#ifdef STB_IMAGE_WRITE_STATIC +#define STBIWDEF static +#else +#ifdef __cplusplus +#define STBIWDEF extern "C" +#else +#define STBIWDEF extern +#endif +#endif +#endif + +#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations +extern int stbi_write_tga_with_rle; +extern int stbi_write_png_compression_level; +extern int stbi_write_force_png_filter; +#endif + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); +STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); +STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality); +#endif + +typedef void stbi_write_func(void *context, void *data, int size); + +STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes); +STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data); +STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality); + +STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean); + +#endif//INCLUDE_STB_IMAGE_WRITE_H + +#ifdef STB_IMAGE_WRITE_IMPLEMENTATION + +#ifdef _WIN32 + #ifndef _CRT_SECURE_NO_WARNINGS + #define _CRT_SECURE_NO_WARNINGS + #endif + #ifndef _CRT_NONSTDC_NO_DEPRECATE + #define _CRT_NONSTDC_NO_DEPRECATE + #endif +#endif + +#ifndef STBI_WRITE_NO_STDIO +#include <stdio.h> +#endif // STBI_WRITE_NO_STDIO + +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#if defined(STBIW_MALLOC) && defined(STBIW_FREE) && (defined(STBIW_REALLOC) || defined(STBIW_REALLOC_SIZED)) +// ok +#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC) && !defined(STBIW_REALLOC_SIZED) +// ok +#else +#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC (or STBIW_REALLOC_SIZED)." +#endif + +#ifndef STBIW_MALLOC +#define STBIW_MALLOC(sz) malloc(sz) +#define STBIW_REALLOC(p,newsz) realloc(p,newsz) +#define STBIW_FREE(p) free(p) +#endif + +#ifndef STBIW_REALLOC_SIZED +#define STBIW_REALLOC_SIZED(p,oldsz,newsz) STBIW_REALLOC(p,newsz) +#endif + + +#ifndef STBIW_MEMMOVE +#define STBIW_MEMMOVE(a,b,sz) memmove(a,b,sz) +#endif + + +#ifndef STBIW_ASSERT +#include <assert.h> +#define STBIW_ASSERT(x) assert(x) +#endif + +#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff) + +#ifdef STB_IMAGE_WRITE_STATIC +static int stbi__flip_vertically_on_write=0; +static int stbi_write_png_compression_level = 8; +static int stbi_write_tga_with_rle = 1; +static int stbi_write_force_png_filter = -1; +#else +int stbi_write_png_compression_level = 8; +int stbi__flip_vertically_on_write=0; +int stbi_write_tga_with_rle = 1; +int stbi_write_force_png_filter = -1; +#endif + +STBIWDEF void stbi_flip_vertically_on_write(int flag) +{ + stbi__flip_vertically_on_write = flag; +} + +typedef struct +{ + stbi_write_func *func; + void *context; +} stbi__write_context; + +// initialize a callback-based context +static void stbi__start_write_callbacks(stbi__write_context *s, stbi_write_func *c, void *context) +{ + s->func = c; + s->context = context; +} + +#ifndef STBI_WRITE_NO_STDIO + +static void stbi__stdio_write(void *context, void *data, int size) +{ + fwrite(data,1,size,(FILE*) context); +} + +static int stbi__start_write_file(stbi__write_context *s, const char *filename) +{ + FILE *f; +#ifdef STBI_MSC_SECURE_CRT + if (fopen_s(&f, filename, "wb")) + f = NULL; +#else + f = fopen(filename, "wb"); +#endif + stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f); + return f != NULL; +} + +static void stbi__end_write_file(stbi__write_context *s) +{ + fclose((FILE *)s->context); +} + +#endif // !STBI_WRITE_NO_STDIO + +typedef unsigned int stbiw_uint32; +typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1]; + +static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v) +{ + while (*fmt) { + switch (*fmt++) { + case ' ': break; + case '1': { unsigned char x = STBIW_UCHAR(va_arg(v, int)); + s->func(s->context,&x,1); + break; } + case '2': { int x = va_arg(v,int); + unsigned char b[2]; + b[0] = STBIW_UCHAR(x); + b[1] = STBIW_UCHAR(x>>8); + s->func(s->context,b,2); + break; } + case '4': { stbiw_uint32 x = va_arg(v,int); + unsigned char b[4]; + b[0]=STBIW_UCHAR(x); + b[1]=STBIW_UCHAR(x>>8); + b[2]=STBIW_UCHAR(x>>16); + b[3]=STBIW_UCHAR(x>>24); + s->func(s->context,b,4); + break; } + default: + STBIW_ASSERT(0); + return; + } + } +} + +static void stbiw__writef(stbi__write_context *s, const char *fmt, ...) +{ + va_list v; + va_start(v, fmt); + stbiw__writefv(s, fmt, v); + va_end(v); +} + +static void stbiw__putc(stbi__write_context *s, unsigned char c) +{ + s->func(s->context, &c, 1); +} + +static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c) +{ + unsigned char arr[3]; + arr[0] = a, arr[1] = b, arr[2] = c; + s->func(s->context, arr, 3); +} + +static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d) +{ + unsigned char bg[3] = { 255, 0, 255}, px[3]; + int k; + + if (write_alpha < 0) + s->func(s->context, &d[comp - 1], 1); + + switch (comp) { + case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case + case 1: + if (expand_mono) + stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp + else + s->func(s->context, d, 1); // monochrome TGA + break; + case 4: + if (!write_alpha) { + // composite against pink background + for (k = 0; k < 3; ++k) + px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255; + stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); + break; + } + /* FALLTHROUGH */ + case 3: + stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]); + break; + } + if (write_alpha > 0) + s->func(s->context, &d[comp - 1], 1); +} + +static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono) +{ + stbiw_uint32 zero = 0; + int i,j, j_end; + + if (y <= 0) + return; + + if (stbi__flip_vertically_on_write) + vdir *= -1; + + if (vdir < 0) + j_end = -1, j = y-1; + else + j_end = y, j = 0; + + for (; j != j_end; j += vdir) { + for (i=0; i < x; ++i) { + unsigned char *d = (unsigned char *) data + (j*x+i)*comp; + stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d); + } + s->func(s->context, &zero, scanline_pad); + } +} + +static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...) +{ + if (y < 0 || x < 0) { + return 0; + } else { + va_list v; + va_start(v, fmt); + stbiw__writefv(s, fmt, v); + va_end(v); + stbiw__write_pixels(s,rgb_dir,vdir,x,y,comp,data,alpha,pad, expand_mono); + return 1; + } +} + +static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data) +{ + int pad = (-x*3) & 3; + return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad, + "11 4 22 4" "4 44 22 444444", + 'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header + 40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header +} + +STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data) +{ + stbi__write_context s; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_bmp_core(&s, x, y, comp, data); +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data) +{ + stbi__write_context s; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_bmp_core(&s, x, y, comp, data); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif //!STBI_WRITE_NO_STDIO + +static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data) +{ + int has_alpha = (comp == 2 || comp == 4); + int colorbytes = has_alpha ? comp-1 : comp; + int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3 + + if (y < 0 || x < 0) + return 0; + + if (!stbi_write_tga_with_rle) { + return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0, + "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8); + } else { + int i,j,k; + int jend, jdir; + + stbiw__writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8); + + if (stbi__flip_vertically_on_write) { + j = 0; + jend = y; + jdir = 1; + } else { + j = y-1; + jend = -1; + jdir = -1; + } + for (; j != jend; j += jdir) { + unsigned char *row = (unsigned char *) data + j * x * comp; + int len; + + for (i = 0; i < x; i += len) { + unsigned char *begin = row + i * comp; + int diff = 1; + len = 1; + + if (i < x - 1) { + ++len; + diff = memcmp(begin, row + (i + 1) * comp, comp); + if (diff) { + const unsigned char *prev = begin; + for (k = i + 2; k < x && len < 128; ++k) { + if (memcmp(prev, row + k * comp, comp)) { + prev += comp; + ++len; + } else { + --len; + break; + } + } + } else { + for (k = i + 2; k < x && len < 128; ++k) { + if (!memcmp(begin, row + k * comp, comp)) { + ++len; + } else { + break; + } + } + } + } + + if (diff) { + unsigned char header = STBIW_UCHAR(len - 1); + s->func(s->context, &header, 1); + for (k = 0; k < len; ++k) { + stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp); + } + } else { + unsigned char header = STBIW_UCHAR(len - 129); + s->func(s->context, &header, 1); + stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin); + } + } + } + } + return 1; +} + +STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data) +{ + stbi__write_context s; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_tga_core(&s, x, y, comp, (void *) data); +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data) +{ + stbi__write_context s; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_tga_core(&s, x, y, comp, (void *) data); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif + +// ************************************************************************************************* +// Radiance RGBE HDR writer +// by Baldur Karlsson + +#define stbiw__max(a, b) ((a) > (b) ? (a) : (b)) + +void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear) +{ + int exponent; + float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2])); + + if (maxcomp < 1e-32f) { + rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0; + } else { + float normalize = (float) frexp(maxcomp, &exponent) * 256.0f/maxcomp; + + rgbe[0] = (unsigned char)(linear[0] * normalize); + rgbe[1] = (unsigned char)(linear[1] * normalize); + rgbe[2] = (unsigned char)(linear[2] * normalize); + rgbe[3] = (unsigned char)(exponent + 128); + } +} + +void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte) +{ + unsigned char lengthbyte = STBIW_UCHAR(length+128); + STBIW_ASSERT(length+128 <= 255); + s->func(s->context, &lengthbyte, 1); + s->func(s->context, &databyte, 1); +} + +void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data) +{ + unsigned char lengthbyte = STBIW_UCHAR(length); + STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code + s->func(s->context, &lengthbyte, 1); + s->func(s->context, data, length); +} + +void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline) +{ + unsigned char scanlineheader[4] = { 2, 2, 0, 0 }; + unsigned char rgbe[4]; + float linear[3]; + int x; + + scanlineheader[2] = (width&0xff00)>>8; + scanlineheader[3] = (width&0x00ff); + + /* skip RLE for images too small or large */ + if (width < 8 || width >= 32768) { + for (x=0; x < width; x++) { + switch (ncomp) { + case 4: /* fallthrough */ + case 3: linear[2] = scanline[x*ncomp + 2]; + linear[1] = scanline[x*ncomp + 1]; + linear[0] = scanline[x*ncomp + 0]; + break; + default: + linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0]; + break; + } + stbiw__linear_to_rgbe(rgbe, linear); + s->func(s->context, rgbe, 4); + } + } else { + int c,r; + /* encode into scratch buffer */ + for (x=0; x < width; x++) { + switch(ncomp) { + case 4: /* fallthrough */ + case 3: linear[2] = scanline[x*ncomp + 2]; + linear[1] = scanline[x*ncomp + 1]; + linear[0] = scanline[x*ncomp + 0]; + break; + default: + linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0]; + break; + } + stbiw__linear_to_rgbe(rgbe, linear); + scratch[x + width*0] = rgbe[0]; + scratch[x + width*1] = rgbe[1]; + scratch[x + width*2] = rgbe[2]; + scratch[x + width*3] = rgbe[3]; + } + + s->func(s->context, scanlineheader, 4); + + /* RLE each component separately */ + for (c=0; c < 4; c++) { + unsigned char *comp = &scratch[width*c]; + + x = 0; + while (x < width) { + // find first run + r = x; + while (r+2 < width) { + if (comp[r] == comp[r+1] && comp[r] == comp[r+2]) + break; + ++r; + } + if (r+2 >= width) + r = width; + // dump up to first run + while (x < r) { + int len = r-x; + if (len > 128) len = 128; + stbiw__write_dump_data(s, len, &comp[x]); + x += len; + } + // if there's a run, output it + if (r+2 < width) { // same test as what we break out of in search loop, so only true if we break'd + // find next byte after run + while (r < width && comp[r] == comp[x]) + ++r; + // output run up to r + while (x < r) { + int len = r-x; + if (len > 127) len = 127; + stbiw__write_run_data(s, len, comp[x]); + x += len; + } + } + } + } + } +} + +static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, float *data) +{ + if (y <= 0 || x <= 0 || data == NULL) + return 0; + else { + // Each component is stored separately. Allocate scratch space for full output scanline. + unsigned char *scratch = (unsigned char *) STBIW_MALLOC(x*4); + int i, len; + char buffer[128]; + char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; + s->func(s->context, header, sizeof(header)-1); + +#ifdef STBI_MSC_SECURE_CRT + len = sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); +#else + len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); +#endif + s->func(s->context, buffer, len); + + for(i=0; i < y; i++) + stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i)*x); + STBIW_FREE(scratch); + return 1; + } +} + +STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const float *data) +{ + stbi__write_context s; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_hdr_core(&s, x, y, comp, (float *) data); +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data) +{ + stbi__write_context s; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_hdr_core(&s, x, y, comp, (float *) data); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif // STBI_WRITE_NO_STDIO + + +////////////////////////////////////////////////////////////////////////////// +// +// PNG writer +// + +#ifndef STBIW_ZLIB_COMPRESS +// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size() +#define stbiw__sbraw(a) ((int *) (a) - 2) +#define stbiw__sbm(a) stbiw__sbraw(a)[0] +#define stbiw__sbn(a) stbiw__sbraw(a)[1] + +#define stbiw__sbneedgrow(a,n) ((a)==0 || stbiw__sbn(a)+n >= stbiw__sbm(a)) +#define stbiw__sbmaybegrow(a,n) (stbiw__sbneedgrow(a,(n)) ? stbiw__sbgrow(a,n) : 0) +#define stbiw__sbgrow(a,n) stbiw__sbgrowf((void **) &(a), (n), sizeof(*(a))) + +#define stbiw__sbpush(a, v) (stbiw__sbmaybegrow(a,1), (a)[stbiw__sbn(a)++] = (v)) +#define stbiw__sbcount(a) ((a) ? stbiw__sbn(a) : 0) +#define stbiw__sbfree(a) ((a) ? STBIW_FREE(stbiw__sbraw(a)),0 : 0) + +static void *stbiw__sbgrowf(void **arr, int increment, int itemsize) +{ + int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1; + void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2); + STBIW_ASSERT(p); + if (p) { + if (!*arr) ((int *) p)[1] = 0; + *arr = (void *) ((int *) p + 2); + stbiw__sbm(*arr) = m; + } + return *arr; +} + +static unsigned char *stbiw__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount) +{ + while (*bitcount >= 8) { + stbiw__sbpush(data, STBIW_UCHAR(*bitbuffer)); + *bitbuffer >>= 8; + *bitcount -= 8; + } + return data; +} + +static int stbiw__zlib_bitrev(int code, int codebits) +{ + int res=0; + while (codebits--) { + res = (res << 1) | (code & 1); + code >>= 1; + } + return res; +} + +static unsigned int stbiw__zlib_countm(unsigned char *a, unsigned char *b, int limit) +{ + int i; + for (i=0; i < limit && i < 258; ++i) + if (a[i] != b[i]) break; + return i; +} + +static unsigned int stbiw__zhash(unsigned char *data) +{ + stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16); + hash ^= hash << 3; + hash += hash >> 5; + hash ^= hash << 4; + hash += hash >> 17; + hash ^= hash << 25; + hash += hash >> 6; + return hash; +} + +#define stbiw__zlib_flush() (out = stbiw__zlib_flushf(out, &bitbuf, &bitcount)) +#define stbiw__zlib_add(code,codebits) \ + (bitbuf |= (code) << bitcount, bitcount += (codebits), stbiw__zlib_flush()) +#define stbiw__zlib_huffa(b,c) stbiw__zlib_add(stbiw__zlib_bitrev(b,c),c) +// default huffman tables +#define stbiw__zlib_huff1(n) stbiw__zlib_huffa(0x30 + (n), 8) +#define stbiw__zlib_huff2(n) stbiw__zlib_huffa(0x190 + (n)-144, 9) +#define stbiw__zlib_huff3(n) stbiw__zlib_huffa(0 + (n)-256,7) +#define stbiw__zlib_huff4(n) stbiw__zlib_huffa(0xc0 + (n)-280,8) +#define stbiw__zlib_huff(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : (n) <= 255 ? stbiw__zlib_huff2(n) : (n) <= 279 ? stbiw__zlib_huff3(n) : stbiw__zlib_huff4(n)) +#define stbiw__zlib_huffb(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : stbiw__zlib_huff2(n)) + +#define stbiw__ZHASH 16384 + +#endif // STBIW_ZLIB_COMPRESS + +unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality) +{ +#ifdef STBIW_ZLIB_COMPRESS + // user provided a zlib compress implementation, use that + return STBIW_ZLIB_COMPRESS(data, data_len, out_len, quality); +#else // use builtin + static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 }; + static unsigned char lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; + static unsigned short distc[] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 }; + static unsigned char disteb[] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 }; + unsigned int bitbuf=0; + int i,j, bitcount=0; + unsigned char *out = NULL; + unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(char**)); + if (hash_table == NULL) + return NULL; + if (quality < 5) quality = 5; + + stbiw__sbpush(out, 0x78); // DEFLATE 32K window + stbiw__sbpush(out, 0x5e); // FLEVEL = 1 + stbiw__zlib_add(1,1); // BFINAL = 1 + stbiw__zlib_add(1,2); // BTYPE = 1 -- fixed huffman + + for (i=0; i < stbiw__ZHASH; ++i) + hash_table[i] = NULL; + + i=0; + while (i < data_len-3) { + // hash next 3 bytes of data to be compressed + int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3; + unsigned char *bestloc = 0; + unsigned char **hlist = hash_table[h]; + int n = stbiw__sbcount(hlist); + for (j=0; j < n; ++j) { + if (hlist[j]-data > i-32768) { // if entry lies within window + int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i); + if (d >= best) best=d,bestloc=hlist[j]; + } + } + // when hash table entry is too long, delete half the entries + if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) { + STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality); + stbiw__sbn(hash_table[h]) = quality; + } + stbiw__sbpush(hash_table[h],data+i); + + if (bestloc) { + // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal + h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1); + hlist = hash_table[h]; + n = stbiw__sbcount(hlist); + for (j=0; j < n; ++j) { + if (hlist[j]-data > i-32767) { + int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1); + if (e > best) { // if next match is better, bail on current match + bestloc = NULL; + break; + } + } + } + } + + if (bestloc) { + int d = (int) (data+i - bestloc); // distance back + STBIW_ASSERT(d <= 32767 && best <= 258); + for (j=0; best > lengthc[j+1]-1; ++j); + stbiw__zlib_huff(j+257); + if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]); + for (j=0; d > distc[j+1]-1; ++j); + stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5); + if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]); + i += best; + } else { + stbiw__zlib_huffb(data[i]); + ++i; + } + } + // write out final bytes + for (;i < data_len; ++i) + stbiw__zlib_huffb(data[i]); + stbiw__zlib_huff(256); // end of block + // pad with 0 bits to byte boundary + while (bitcount) + stbiw__zlib_add(0,1); + + for (i=0; i < stbiw__ZHASH; ++i) + (void) stbiw__sbfree(hash_table[i]); + STBIW_FREE(hash_table); + + { + // compute adler32 on input + unsigned int s1=1, s2=0; + int blocklen = (int) (data_len % 5552); + j=0; + while (j < data_len) { + for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1; + s1 %= 65521, s2 %= 65521; + j += blocklen; + blocklen = 5552; + } + stbiw__sbpush(out, STBIW_UCHAR(s2 >> 8)); + stbiw__sbpush(out, STBIW_UCHAR(s2)); + stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8)); + stbiw__sbpush(out, STBIW_UCHAR(s1)); + } + *out_len = stbiw__sbn(out); + // make returned pointer freeable + STBIW_MEMMOVE(stbiw__sbraw(out), out, *out_len); + return (unsigned char *) stbiw__sbraw(out); +#endif // STBIW_ZLIB_COMPRESS +} + +static unsigned int stbiw__crc32(unsigned char *buffer, int len) +{ + static unsigned int crc_table[256] = + { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0eDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D + }; + + unsigned int crc = ~0u; + int i; + for (i=0; i < len; ++i) + crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)]; + return ~crc; +} + +#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4) +#define stbiw__wp32(data,v) stbiw__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v)); +#define stbiw__wptag(data,s) stbiw__wpng4(data, s[0],s[1],s[2],s[3]) + +static void stbiw__wpcrc(unsigned char **data, int len) +{ + unsigned int crc = stbiw__crc32(*data - len - 4, len+4); + stbiw__wp32(*data, crc); +} + +static unsigned char stbiw__paeth(int a, int b, int c) +{ + int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c); + if (pa <= pb && pa <= pc) return STBIW_UCHAR(a); + if (pb <= pc) return STBIW_UCHAR(b); + return STBIW_UCHAR(c); +} + +// @OPTIMIZE: provide an option that always forces left-predict or paeth predict +static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int width, int height, int y, int n, int filter_type, signed char *line_buffer) +{ + static int mapping[] = { 0,1,2,3,4 }; + static int firstmap[] = { 0,1,0,5,6 }; + int *mymap = (y != 0) ? mapping : firstmap; + int i; + int type = mymap[filter_type]; + unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y); + int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes; + for (i = 0; i < n; ++i) { + switch (type) { + case 0: line_buffer[i] = z[i]; break; + case 1: line_buffer[i] = z[i]; break; + case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break; + case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break; + case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-signed_stride],0)); break; + case 5: line_buffer[i] = z[i]; break; + case 6: line_buffer[i] = z[i]; break; + } + } + for (i=n; i < width*n; ++i) { + switch (type) { + case 0: line_buffer[i] = z[i]; break; + case 1: line_buffer[i] = z[i] - z[i-n]; break; + case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break; + case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break; + case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break; + case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break; + case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break; + } + } +} + +unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len) +{ + int force_filter = stbi_write_force_png_filter; + int ctype[5] = { -1, 0, 4, 2, 6 }; + unsigned char sig[8] = { 137,80,78,71,13,10,26,10 }; + unsigned char *out,*o, *filt, *zlib; + signed char *line_buffer; + int j,zlen; + + if (stride_bytes == 0) + stride_bytes = x * n; + + if (force_filter >= 5) { + force_filter = -1; + } + + filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0; + line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; } + for (j=0; j < y; ++j) { + int filter_type; + if (force_filter > -1) { + filter_type = force_filter; + stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, force_filter, line_buffer); + } else { // Estimate the best filter by running through all of them: + int best_filter = 0, best_filter_val = 0x7fffffff, est, i; + for (filter_type = 0; filter_type < 5; filter_type++) { + stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer); + + // Estimate the entropy of the line using this filter; the less, the better. + est = 0; + for (i = 0; i < x*n; ++i) { + est += abs((signed char) line_buffer[i]); + } + if (est < best_filter_val) { + best_filter_val = est; + best_filter = filter_type; + } + } + if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it + stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, best_filter, line_buffer); + filter_type = best_filter; + } + } + // when we get here, filter_type contains the filter type, and line_buffer contains the data + filt[j*(x*n+1)] = (unsigned char) filter_type; + STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n); + } + STBIW_FREE(line_buffer); + zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level); + STBIW_FREE(filt); + if (!zlib) return 0; + + // each tag requires 12 bytes of overhead + out = (unsigned char *) STBIW_MALLOC(8 + 12+13 + 12+zlen + 12); + if (!out) return 0; + *out_len = 8 + 12+13 + 12+zlen + 12; + + o=out; + STBIW_MEMMOVE(o,sig,8); o+= 8; + stbiw__wp32(o, 13); // header length + stbiw__wptag(o, "IHDR"); + stbiw__wp32(o, x); + stbiw__wp32(o, y); + *o++ = 8; + *o++ = STBIW_UCHAR(ctype[n]); + *o++ = 0; + *o++ = 0; + *o++ = 0; + stbiw__wpcrc(&o,13); + + stbiw__wp32(o, zlen); + stbiw__wptag(o, "IDAT"); + STBIW_MEMMOVE(o, zlib, zlen); + o += zlen; + STBIW_FREE(zlib); + stbiw__wpcrc(&o, zlen); + + stbiw__wp32(o,0); + stbiw__wptag(o, "IEND"); + stbiw__wpcrc(&o,0); + + STBIW_ASSERT(o == out + *out_len); + + return out; +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes) +{ + FILE *f; + int len; + unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len); + if (png == NULL) return 0; +#ifdef STBI_MSC_SECURE_CRT + if (fopen_s(&f, filename, "wb")) + f = NULL; +#else + f = fopen(filename, "wb"); +#endif + if (!f) { STBIW_FREE(png); return 0; } + fwrite(png, 1, len, f); + fclose(f); + STBIW_FREE(png); + return 1; +} +#endif + +STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes) +{ + int len; + unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len); + if (png == NULL) return 0; + func(context, png, len); + STBIW_FREE(png); + return 1; +} + + +/* *************************************************************************** + * + * JPEG writer + * + * This is based on Jon Olick's jo_jpeg.cpp: + * public domain Simple, Minimalistic JPEG writer - http://www.jonolick.com/code.html + */ + +static const unsigned char stbiw__jpg_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18, + 24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63 }; + +static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitCntP, const unsigned short *bs) { + int bitBuf = *bitBufP, bitCnt = *bitCntP; + bitCnt += bs[1]; + bitBuf |= bs[0] << (24 - bitCnt); + while(bitCnt >= 8) { + unsigned char c = (bitBuf >> 16) & 255; + stbiw__putc(s, c); + if(c == 255) { + stbiw__putc(s, 0); + } + bitBuf <<= 8; + bitCnt -= 8; + } + *bitBufP = bitBuf; + *bitCntP = bitCnt; +} + +static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float *d4p, float *d5p, float *d6p, float *d7p) { + float d0 = *d0p, d1 = *d1p, d2 = *d2p, d3 = *d3p, d4 = *d4p, d5 = *d5p, d6 = *d6p, d7 = *d7p; + float z1, z2, z3, z4, z5, z11, z13; + + float tmp0 = d0 + d7; + float tmp7 = d0 - d7; + float tmp1 = d1 + d6; + float tmp6 = d1 - d6; + float tmp2 = d2 + d5; + float tmp5 = d2 - d5; + float tmp3 = d3 + d4; + float tmp4 = d3 - d4; + + // Even part + float tmp10 = tmp0 + tmp3; // phase 2 + float tmp13 = tmp0 - tmp3; + float tmp11 = tmp1 + tmp2; + float tmp12 = tmp1 - tmp2; + + d0 = tmp10 + tmp11; // phase 3 + d4 = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * 0.707106781f; // c4 + d2 = tmp13 + z1; // phase 5 + d6 = tmp13 - z1; + + // Odd part + tmp10 = tmp4 + tmp5; // phase 2 + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + // The rotator is modified from fig 4-8 to avoid extra negations. + z5 = (tmp10 - tmp12) * 0.382683433f; // c6 + z2 = tmp10 * 0.541196100f + z5; // c2-c6 + z4 = tmp12 * 1.306562965f + z5; // c2+c6 + z3 = tmp11 * 0.707106781f; // c4 + + z11 = tmp7 + z3; // phase 5 + z13 = tmp7 - z3; + + *d5p = z13 + z2; // phase 6 + *d3p = z13 - z2; + *d1p = z11 + z4; + *d7p = z11 - z4; + + *d0p = d0; *d2p = d2; *d4p = d4; *d6p = d6; +} + +static void stbiw__jpg_calcBits(int val, unsigned short bits[2]) { + int tmp1 = val < 0 ? -val : val; + val = val < 0 ? val-1 : val; + bits[1] = 1; + while(tmp1 >>= 1) { + ++bits[1]; + } + bits[0] = val & ((1<<bits[1])-1); +} + +static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt, float *CDU, float *fdtbl, int DC, const unsigned short HTDC[256][2], const unsigned short HTAC[256][2]) { + const unsigned short EOB[2] = { HTAC[0x00][0], HTAC[0x00][1] }; + const unsigned short M16zeroes[2] = { HTAC[0xF0][0], HTAC[0xF0][1] }; + int dataOff, i, diff, end0pos; + int DU[64]; + + // DCT rows + for(dataOff=0; dataOff<64; dataOff+=8) { + stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+1], &CDU[dataOff+2], &CDU[dataOff+3], &CDU[dataOff+4], &CDU[dataOff+5], &CDU[dataOff+6], &CDU[dataOff+7]); + } + // DCT columns + for(dataOff=0; dataOff<8; ++dataOff) { + stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+8], &CDU[dataOff+16], &CDU[dataOff+24], &CDU[dataOff+32], &CDU[dataOff+40], &CDU[dataOff+48], &CDU[dataOff+56]); + } + // Quantize/descale/zigzag the coefficients + for(i=0; i<64; ++i) { + float v = CDU[i]*fdtbl[i]; + // DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f)); + // ceilf() and floorf() are C99, not C89, but I /think/ they're not needed here anyway? + DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? v - 0.5f : v + 0.5f); + } + + // Encode DC + diff = DU[0] - DC; + if (diff == 0) { + stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[0]); + } else { + unsigned short bits[2]; + stbiw__jpg_calcBits(diff, bits); + stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[bits[1]]); + stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits); + } + // Encode ACs + end0pos = 63; + for(; (end0pos>0)&&(DU[end0pos]==0); --end0pos) { + } + // end0pos = first element in reverse order !=0 + if(end0pos == 0) { + stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB); + return DU[0]; + } + for(i = 1; i <= end0pos; ++i) { + int startpos = i; + int nrzeroes; + unsigned short bits[2]; + for (; DU[i]==0 && i<=end0pos; ++i) { + } + nrzeroes = i-startpos; + if ( nrzeroes >= 16 ) { + int lng = nrzeroes>>4; + int nrmarker; + for (nrmarker=1; nrmarker <= lng; ++nrmarker) + stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes); + nrzeroes &= 15; + } + stbiw__jpg_calcBits(DU[i], bits); + stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTAC[(nrzeroes<<4)+bits[1]]); + stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits); + } + if(end0pos != 63) { + stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB); + } + return DU[0]; +} + +static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, int comp, const void* data, int quality) { + // Constants that don't pollute global namespace + static const unsigned char std_dc_luminance_nrcodes[] = {0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0}; + static const unsigned char std_dc_luminance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; + static const unsigned char std_ac_luminance_nrcodes[] = {0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d}; + static const unsigned char std_ac_luminance_values[] = { + 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08, + 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28, + 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59, + 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89, + 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6, + 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2, + 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa + }; + static const unsigned char std_dc_chrominance_nrcodes[] = {0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; + static const unsigned char std_dc_chrominance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; + static const unsigned char std_ac_chrominance_nrcodes[] = {0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77}; + static const unsigned char std_ac_chrominance_values[] = { + 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91, + 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26, + 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58, + 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87, + 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4, + 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda, + 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa + }; + // Huffman tables + static const unsigned short YDC_HT[256][2] = { {0,2},{2,3},{3,3},{4,3},{5,3},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9}}; + static const unsigned short UVDC_HT[256][2] = { {0,2},{1,2},{2,2},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9},{1022,10},{2046,11}}; + static const unsigned short YAC_HT[256][2] = { + {10,4},{0,2},{1,2},{4,3},{11,4},{26,5},{120,7},{248,8},{1014,10},{65410,16},{65411,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {12,4},{27,5},{121,7},{502,9},{2038,11},{65412,16},{65413,16},{65414,16},{65415,16},{65416,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {28,5},{249,8},{1015,10},{4084,12},{65417,16},{65418,16},{65419,16},{65420,16},{65421,16},{65422,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {58,6},{503,9},{4085,12},{65423,16},{65424,16},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {59,6},{1016,10},{65430,16},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {122,7},{2039,11},{65438,16},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {123,7},{4086,12},{65446,16},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {250,8},{4087,12},{65454,16},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {504,9},{32704,15},{65462,16},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {505,9},{65470,16},{65471,16},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {506,9},{65479,16},{65480,16},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {1017,10},{65488,16},{65489,16},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {1018,10},{65497,16},{65498,16},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {2040,11},{65506,16},{65507,16},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {65515,16},{65516,16},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{0,0},{0,0},{0,0},{0,0},{0,0}, + {2041,11},{65525,16},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0} + }; + static const unsigned short UVAC_HT[256][2] = { + {0,2},{1,2},{4,3},{10,4},{24,5},{25,5},{56,6},{120,7},{500,9},{1014,10},{4084,12},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {11,4},{57,6},{246,8},{501,9},{2038,11},{4085,12},{65416,16},{65417,16},{65418,16},{65419,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {26,5},{247,8},{1015,10},{4086,12},{32706,15},{65420,16},{65421,16},{65422,16},{65423,16},{65424,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {27,5},{248,8},{1016,10},{4087,12},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{65430,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {58,6},{502,9},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{65438,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {59,6},{1017,10},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{65446,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {121,7},{2039,11},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{65454,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {122,7},{2040,11},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{65462,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {249,8},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{65470,16},{65471,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {503,9},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{65479,16},{65480,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {504,9},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{65488,16},{65489,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {505,9},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{65497,16},{65498,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {506,9},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{65506,16},{65507,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {2041,11},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{65515,16},{65516,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {16352,14},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{65525,16},{0,0},{0,0},{0,0},{0,0},{0,0}, + {1018,10},{32707,15},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0} + }; + static const int YQT[] = {16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22, + 37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99}; + static const int UVQT[] = {17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99, + 99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; + static const float aasf[] = { 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f, + 1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f }; + + int row, col, i, k; + float fdtbl_Y[64], fdtbl_UV[64]; + unsigned char YTable[64], UVTable[64]; + + if(!data || !width || !height || comp > 4 || comp < 1) { + return 0; + } + + quality = quality ? quality : 90; + quality = quality < 1 ? 1 : quality > 100 ? 100 : quality; + quality = quality < 50 ? 5000 / quality : 200 - quality * 2; + + for(i = 0; i < 64; ++i) { + int uvti, yti = (YQT[i]*quality+50)/100; + YTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (yti < 1 ? 1 : yti > 255 ? 255 : yti); + uvti = (UVQT[i]*quality+50)/100; + UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (uvti < 1 ? 1 : uvti > 255 ? 255 : uvti); + } + + for(row = 0, k = 0; row < 8; ++row) { + for(col = 0; col < 8; ++col, ++k) { + fdtbl_Y[k] = 1 / (YTable [stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]); + fdtbl_UV[k] = 1 / (UVTable[stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]); + } + } + + // Write Headers + { + static const unsigned char head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 }; + static const unsigned char head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 }; + const unsigned char head1[] = { 0xFF,0xC0,0,0x11,8,(unsigned char)(height>>8),STBIW_UCHAR(height),(unsigned char)(width>>8),STBIW_UCHAR(width), + 3,1,0x11,0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 }; + s->func(s->context, (void*)head0, sizeof(head0)); + s->func(s->context, (void*)YTable, sizeof(YTable)); + stbiw__putc(s, 1); + s->func(s->context, UVTable, sizeof(UVTable)); + s->func(s->context, (void*)head1, sizeof(head1)); + s->func(s->context, (void*)(std_dc_luminance_nrcodes+1), sizeof(std_dc_luminance_nrcodes)-1); + s->func(s->context, (void*)std_dc_luminance_values, sizeof(std_dc_luminance_values)); + stbiw__putc(s, 0x10); // HTYACinfo + s->func(s->context, (void*)(std_ac_luminance_nrcodes+1), sizeof(std_ac_luminance_nrcodes)-1); + s->func(s->context, (void*)std_ac_luminance_values, sizeof(std_ac_luminance_values)); + stbiw__putc(s, 1); // HTUDCinfo + s->func(s->context, (void*)(std_dc_chrominance_nrcodes+1), sizeof(std_dc_chrominance_nrcodes)-1); + s->func(s->context, (void*)std_dc_chrominance_values, sizeof(std_dc_chrominance_values)); + stbiw__putc(s, 0x11); // HTUACinfo + s->func(s->context, (void*)(std_ac_chrominance_nrcodes+1), sizeof(std_ac_chrominance_nrcodes)-1); + s->func(s->context, (void*)std_ac_chrominance_values, sizeof(std_ac_chrominance_values)); + s->func(s->context, (void*)head2, sizeof(head2)); + } + + // Encode 8x8 macroblocks + { + static const unsigned short fillBits[] = {0x7F, 7}; + const unsigned char *imageData = (const unsigned char *)data; + int DCY=0, DCU=0, DCV=0; + int bitBuf=0, bitCnt=0; + // comp == 2 is grey+alpha (alpha is ignored) + int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0; + int x, y, pos; + for(y = 0; y < height; y += 8) { + for(x = 0; x < width; x += 8) { + float YDU[64], UDU[64], VDU[64]; + for(row = y, pos = 0; row < y+8; ++row) { + for(col = x; col < x+8; ++col, ++pos) { + int p = (stbi__flip_vertically_on_write ? height-1-row : row)*width*comp + col*comp; + float r, g, b; + if(row >= height) { + p -= width*comp*(row+1 - height); + } + if(col >= width) { + p -= comp*(col+1 - width); + } + + r = imageData[p+0]; + g = imageData[p+ofsG]; + b = imageData[p+ofsB]; + YDU[pos]=+0.29900f*r+0.58700f*g+0.11400f*b-128; + UDU[pos]=-0.16874f*r-0.33126f*g+0.50000f*b; + VDU[pos]=+0.50000f*r-0.41869f*g-0.08131f*b; + } + } + + DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); + DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); + } + } + + // Do the bit alignment of the EOI marker + stbiw__jpg_writeBits(s, &bitBuf, &bitCnt, fillBits); + } + + // EOI + stbiw__putc(s, 0xFF); + stbiw__putc(s, 0xD9); + + return 1; +} + +STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality) +{ + stbi__write_context s; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality); +} + + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality) +{ + stbi__write_context s; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_jpg_core(&s, x, y, comp, data, quality); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif + +#endif // STB_IMAGE_WRITE_IMPLEMENTATION + +/* Revision history + 1.09 (2018-02-11) + fix typo in zlib quality API, improve STB_I_W_STATIC in C++ + 1.08 (2018-01-29) + add stbi__flip_vertically_on_write, external zlib, zlib quality, choose PNG filter + 1.07 (2017-07-24) + doc fix + 1.06 (2017-07-23) + writing JPEG (using Jon Olick's code) + 1.05 ??? + 1.04 (2017-03-03) + monochrome BMP expansion + 1.03 ??? + 1.02 (2016-04-02) + avoid allocating large structures on the stack + 1.01 (2016-01-16) + STBIW_REALLOC_SIZED: support allocators with no realloc support + avoid race-condition in crc initialization + minor compile issues + 1.00 (2015-09-14) + installable file IO function + 0.99 (2015-09-13) + warning fixes; TGA rle support + 0.98 (2015-04-08) + added STBIW_MALLOC, STBIW_ASSERT etc + 0.97 (2015-01-18) + fixed HDR asserts, rewrote HDR rle logic + 0.96 (2015-01-17) + add HDR output + fix monochrome BMP + 0.95 (2014-08-17) + add monochrome TGA output + 0.94 (2014-05-31) + rename private functions to avoid conflicts with stb_image.h + 0.93 (2014-05-27) + warning fixes + 0.92 (2010-08-01) + casts to unsigned char to fix warnings + 0.91 (2010-07-17) + first public release + 0.90 first internal release +*/ + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ diff --git a/src/strptime_c.cpp b/src/strptime_c.cpp new file mode 100644 index 0000000..0d32c1f --- /dev/null +++ b/src/strptime_c.cpp @@ -0,0 +1,428 @@ +#include <ctype.h> +#include <string.h> +#include <time.h> +#include "strptime_c.h" +#include <stdio.h> + +/* + * We do not implement alternate representations. However, we always + * check whether a given modifier is allowed for a certain conversion. + */ +#define ALT_E 0x01 +#define ALT_O 0x02 + //#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); } +#define LEGAL_ALT(x) { ; } +#define TM_YEAR_BASE (1900) + +static int conv_num(const char **, int *, int, int); +static int strncasecmp(char *s1, char *s2, size_t n); + +static const char *day[7] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", + "Friday", "Saturday" +}; +static const char *abday[7] = { + "Sun","Mon","Tue","Wed","Thu","Fri","Sat" +}; +static const char *mon[12] = { + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December" +}; +static const char *abmon[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +/* +static const char *am_pm[2] = { + "AM", "PM" +};*/ + + +char * strptime_c(const char *buf, const char *fmt, struct tm *tm) +{ + char c; + const char *bp; + size_t len = 0; + int alt_format, i, split_year = 0; + + bp = buf; + + while ((c = *fmt) != '\0') { + /* Clear `alternate' modifier prior to new conversion. */ + alt_format = 0; + + /* Eat up white-space. */ + if (isspace(c)) { + while (isspace(*bp)) + bp++; + + fmt++; + continue; + } + + if ((c = *fmt++) != '%') + goto literal; + + + again: switch (c = *fmt++) { + case '%': /* "%%" is converted to "%". */ + literal : + if (c != *bp++) + return (0); + break; + + /* + * "Alternative" modifiers. Just set the appropriate flag + * and start over again. + */ + case 'E': /* "%E?" alternative conversion modifier. */ + LEGAL_ALT(0); + alt_format |= ALT_E; + goto again; + + case 'O': /* "%O?" alternative conversion modifier. */ + LEGAL_ALT(0); + alt_format |= ALT_O; + goto again; + + /* + * "Complex" conversion rules, implemented through recursion. + */ + case 'c': /* Date and time, using the locale's format. */ + LEGAL_ALT(ALT_E); + if (!(bp = strptime_c(bp, "%x %X", tm))) + return (0); + break; + + case 'D': /* The date as "%m/%d/%y". */ + LEGAL_ALT(0); + if (!(bp = strptime_c(bp, "%m/%d/%y", tm))) + return (0); + break; + + case 'R': /* The time as "%H:%M". */ + LEGAL_ALT(0); + if (!(bp = strptime_c(bp, "%H:%M", tm))) + return (0); + break; + + case 'r': /* The time in 12-hour clock representation. */ + LEGAL_ALT(0); + if (!(bp = strptime_c(bp, "%I:%M:%S %p", tm))) + return (0); + break; + + case 'T': /* The time as "%H:%M:%S". */ + LEGAL_ALT(0); + if (!(bp = strptime_c(bp, "%H:%M:%S", tm))) + return (0); + break; + + case 'X': /* The time, using the locale's format. */ + LEGAL_ALT(ALT_E); + if (!(bp = strptime_c(bp, "%H:%M:%S", tm))) + return (0); + break; + + case 'x': /* The date, using the locale's format. */ + LEGAL_ALT(ALT_E); + if (!(bp = strptime_c(bp, "%m/%d/%y", tm))) + return (0); + break; + + /* + * "Elementary" conversion rules. + */ + case 'A': /* The day of week, using the locale's form. */ + case 'a': + LEGAL_ALT(0); + for (i = 0; i < 7; i++) { + /* Full name. */ + len = strlen(day[i]); + if (strncasecmp((char *)(day[i]), (char *)bp, len) == 0) + break; + + /* Abbreviated name. */ + len = strlen(abday[i]); + if (strncasecmp((char *)(abday[i]), (char *)bp, len) == 0) + break; + } + + /* Nothing matched. */ + if (i == 7) + return (0); + + tm->tm_wday = i; + bp += len; + break; + + case 'B': /* The month, using the locale's form. */ + case 'b': + case 'h': + LEGAL_ALT(0); + for (i = 0; i < 12; i++) { + /* Full name. */ + len = strlen(mon[i]); + if (strncasecmp((char *)(mon[i]), (char *)bp, len) == 0) + break; + + /* Abbreviated name. */ + len = strlen(abmon[i]); + if (strncasecmp((char *)(abmon[i]), (char *)bp, len) == 0) + break; + } + + /* Nothing matched. */ + if (i == 12) + return (0); + + tm->tm_mon = i; + bp += len; + break; + + case 'C': /* The century number. */ + LEGAL_ALT(ALT_E); + if (!(conv_num(&bp, &i, 0, 99))) + return (0); + + if (split_year) { + tm->tm_year = (tm->tm_year % 100) + (i * 100); + } + else { + tm->tm_year = i * 100; + split_year = 1; + } + break; + + case 'd': /* The day of month. */ + case 'e': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) + return (0); + break; + + case 'k': /* The hour (24-hour clock representation). */ + LEGAL_ALT(0); + /* FALLTHROUGH */ + case 'H': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) + return (0); + break; + + case 'l': /* The hour (12-hour clock representation). */ + LEGAL_ALT(0); + /* FALLTHROUGH */ + case 'I': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) + return (0); + if (tm->tm_hour == 12) + tm->tm_hour = 0; + break; + + case 'j': /* The day of year. */ + LEGAL_ALT(0); + if (!(conv_num(&bp, &i, 1, 366))) + return (0); + tm->tm_yday = i - 1; + break; + + case 'M': /* The minute. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_min, 0, 59))) + return (0); + break; + + case 'm': /* The month. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &i, 1, 12))) + return (0); + tm->tm_mon = i - 1; + break; + + // case 'p': /* The locale's equivalent of AM/PM. */ + // LEGAL_ALT(0); + // /* AM? */ + // if (strcasecmp(am_pm[0], bp) == 0) { + // if (tm->tm_hour > 11) + // return (0); + // + // bp += strlen(am_pm[0]); + // break; + // } + // /* PM? */ + // else if (strcasecmp(am_pm[1], bp) == 0) { + // if (tm->tm_hour > 11) + // return (0); + // + // tm->tm_hour += 12; + // bp += strlen(am_pm[1]); + // break; + // } + // + // /* Nothing matched. */ + // return (0); + + case 'S': /* The seconds. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) + return (0); + break; + + case 'U': /* The week of year, beginning on sunday. */ + case 'W': /* The week of year, beginning on monday. */ + LEGAL_ALT(ALT_O); + /* + * XXX This is bogus, as we can not assume any valid + * information present in the tm structure at this + * point to calculate a real value, so just check the + * range for now. + */ + if (!(conv_num(&bp, &i, 0, 53))) + return (0); + break; + + case 'w': /* The day of week, beginning on sunday. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) + return (0); + break; + + case 'Y': /* The year. */ + LEGAL_ALT(ALT_E); + if (!(conv_num(&bp, &i, 0, 9999))) + return (0); + + tm->tm_year = i - TM_YEAR_BASE; + break; + + case 'y': /* The year within 100 years of the epoch. */ + LEGAL_ALT(ALT_E | ALT_O); + if (!(conv_num(&bp, &i, 0, 99))) + return (0); + + if (split_year) { + tm->tm_year = ((tm->tm_year / 100) * 100) + i; + break; + } + split_year = 1; + if (i <= 68) + tm->tm_year = i + 2000 - TM_YEAR_BASE; + else + tm->tm_year = i + 1900 - TM_YEAR_BASE; + break; + + /* + * Miscellaneous conversions. + */ + case 'n': /* Any kind of white-space. */ + case 't': + LEGAL_ALT(0); + while (isspace(*bp)) + bp++; + break; + + + default: /* Unknown/unsupported conversion. */ + return (0); + } + + + } + + /* LINTED functional specification */ + return ((char *)bp); +} + +//input time str format: "%d-%d-%d %d:%d:%d" +//output: time_t +int strptime_s(struct tm *tm) +{ + //struct tm tm; + time_t seconds; + //int r; + + //if (time_str == NULL) { + // printf("null argument 1: time str\n"); + // return (time_t)-1; + //} + //r = sscanf(time_str, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec); + //if (r != 6) { + // printf("expected %d numbers scanned in %s\n", r, time_str); + // return (time_t)-1; + //} + + //printf("Input: %d - %d - %d %d : %d : %d \n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + + tm->tm_year -= 1900; + tm->tm_mon -= 1; + tm->tm_isdst = 0; + //seconds = mktime(&tm); + seconds = mktime(tm); + + if (seconds == (time_t)-1) { + printf("mktime failed\n"); + } + else { + //printf("timestamps = %d \n", seconds); + } + return seconds; +} + +static int +conv_num(const char **buf, int *dest, int llim, int ulim) +{ + int result = 0; + + /* The limit also determines the number of valid digits. */ + int rulim = ulim; + + if (**buf < '0' || **buf > '9') + { + return (0); + } + + do { + result *= 10; + result += *(*buf)++ - '0'; + rulim /= 10; + } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); + + if (result < llim || result > ulim) + return (0); + + *dest = result; + return (1); +} + +int strncasecmp(char *s1, char *s2, size_t n) +{ + if (n == 0) + return 0; + + while (n-- != 0 && tolower(*s1) == tolower(*s2)) + { + if (n == 0 || *s1 == '\0' || *s2 == '\0') + break; + s1++; + s2++; + } + + return tolower(*(unsigned char *)s1) - tolower(*(unsigned char *)s2); +} + + +//#include <conio.h> +//void main() +//{ +// struct tm newtime; +// memset(&newtime, 0x00, sizeof(struct tm)); +// +// strptime("Tue, 27 Nov 2007 05:35:53", "%a, %d %b %Y %H:%M:%S", &newtime); +// // strptime("03/10/2004 15:54:19","%d/%m/%Y %H:%M:%S",&newtime); +// +// getch(); +// +//} diff --git a/src/strptime_c.h b/src/strptime_c.h new file mode 100644 index 0000000..e643b17 --- /dev/null +++ b/src/strptime_c.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef STRPTIME_C_H +#define STRPTIME_C_H +#include "define_inc.h" +#ifdef GY_OS_WIN +#include <tchar.h> +#else +#include "auto_tchar.h" +#endif +#include <time.h> + +#ifdef __cplusplus +extern "C" { +#endif + + char *strptime_c(const char *buf, const char *fmt, struct tm *tm); + int strptime_s(struct tm *tm); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/structures.c b/src/structures.c new file mode 100644 index 0000000..84b85ed --- /dev/null +++ b/src/structures.c @@ -0,0 +1,59 @@ + +#include "structures.h" + +// Auxiliary function for KeyExpansion +void KeyExpansionCore(unsigned char * in, unsigned char i) { + // Rotate left by one byte: shift left + unsigned char t = in[0]; + in[0] = in[1]; + in[1] = in[2]; + in[2] = in[3]; + in[3] = t; + + // S-box 4 bytes + in[0] = s[in[0]]; + in[1] = s[in[1]]; + in[2] = s[in[2]]; + in[3] = s[in[3]]; + + // RCon + in[0] ^= rcon[i]; +} + +/* The main KeyExpansion function + * Generates additional keys using the original key + * Total of 11 128-bit keys generated, including the original + * Keys are stored one after the other in expandedKeys + */ + +void KeyExpansion(unsigned char* inputKey, unsigned char* expandedKeys) { + // The first 128 bits are the original key + for (int i = 0; i < 16; i++) { + expandedKeys[i] = inputKey[i]; + } + + int bytesGenerated = 16; // Bytes we've generated so far + int rconIteration = 1; // Keeps track of rcon value + unsigned char tmpCore[4]; // Temp storage for core + + while (bytesGenerated < 176) { + /* Read 4 bytes for the core + * They are the previously generated 4 bytes + * Initially, these will be the final 4 bytes of the original key + */ + for (int i = 0; i < 4; i++) { + tmpCore[i] = expandedKeys[i + bytesGenerated - 4]; + } + + // Perform the core once for each 16 byte key + if (bytesGenerated % 16 == 0) { + KeyExpansionCore(tmpCore, rconIteration++); + } + + for (unsigned char a = 0; a < 4; a++) { + expandedKeys[bytesGenerated] = expandedKeys[bytesGenerated - 16] ^ tmpCore[a]; + bytesGenerated++; + } + + } +} \ No newline at end of file diff --git a/src/structures.h b/src/structures.h new file mode 100644 index 0000000..b8971d0 --- /dev/null +++ b/src/structures.h @@ -0,0 +1,199 @@ +/* "structures.h" defines the look-up tables and KeyExpansion function + * used in encrypt.cpp and decrypt.cpp + */ +#pragma once +#ifndef STRUCTURES_H +#define STRUCTURES_H +#include "define_inc.h" + +// Encryption: Forward Rijndael S-box +static const unsigned char s[256] = +{ + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, + 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, + 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, + 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, + 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, + 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, + 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, + 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, + 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, + 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, + 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 +}; + +// Encryption: Multiply by 2 for MixColumns +static const unsigned char mul2[] = +{ + 0x00,0x02,0x04,0x06,0x08,0x0a,0x0c,0x0e,0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e, + 0x20,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3a,0x3c,0x3e, + 0x40,0x42,0x44,0x46,0x48,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,0x5e, + 0x60,0x62,0x64,0x66,0x68,0x6a,0x6c,0x6e,0x70,0x72,0x74,0x76,0x78,0x7a,0x7c,0x7e, + 0x80,0x82,0x84,0x86,0x88,0x8a,0x8c,0x8e,0x90,0x92,0x94,0x96,0x98,0x9a,0x9c,0x9e, + 0xa0,0xa2,0xa4,0xa6,0xa8,0xaa,0xac,0xae,0xb0,0xb2,0xb4,0xb6,0xb8,0xba,0xbc,0xbe, + 0xc0,0xc2,0xc4,0xc6,0xc8,0xca,0xcc,0xce,0xd0,0xd2,0xd4,0xd6,0xd8,0xda,0xdc,0xde, + 0xe0,0xe2,0xe4,0xe6,0xe8,0xea,0xec,0xee,0xf0,0xf2,0xf4,0xf6,0xf8,0xfa,0xfc,0xfe, + 0x1b,0x19,0x1f,0x1d,0x13,0x11,0x17,0x15,0x0b,0x09,0x0f,0x0d,0x03,0x01,0x07,0x05, + 0x3b,0x39,0x3f,0x3d,0x33,0x31,0x37,0x35,0x2b,0x29,0x2f,0x2d,0x23,0x21,0x27,0x25, + 0x5b,0x59,0x5f,0x5d,0x53,0x51,0x57,0x55,0x4b,0x49,0x4f,0x4d,0x43,0x41,0x47,0x45, + 0x7b,0x79,0x7f,0x7d,0x73,0x71,0x77,0x75,0x6b,0x69,0x6f,0x6d,0x63,0x61,0x67,0x65, + 0x9b,0x99,0x9f,0x9d,0x93,0x91,0x97,0x95,0x8b,0x89,0x8f,0x8d,0x83,0x81,0x87,0x85, + 0xbb,0xb9,0xbf,0xbd,0xb3,0xb1,0xb7,0xb5,0xab,0xa9,0xaf,0xad,0xa3,0xa1,0xa7,0xa5, + 0xdb,0xd9,0xdf,0xdd,0xd3,0xd1,0xd7,0xd5,0xcb,0xc9,0xcf,0xcd,0xc3,0xc1,0xc7,0xc5, + 0xfb,0xf9,0xff,0xfd,0xf3,0xf1,0xf7,0xf5,0xeb,0xe9,0xef,0xed,0xe3,0xe1,0xe7,0xe5 +}; + +// Encryption: Multiply by 3 for MixColumns +static const unsigned char mul3[] = +{ + 0x00,0x03,0x06,0x05,0x0c,0x0f,0x0a,0x09,0x18,0x1b,0x1e,0x1d,0x14,0x17,0x12,0x11, + 0x30,0x33,0x36,0x35,0x3c,0x3f,0x3a,0x39,0x28,0x2b,0x2e,0x2d,0x24,0x27,0x22,0x21, + 0x60,0x63,0x66,0x65,0x6c,0x6f,0x6a,0x69,0x78,0x7b,0x7e,0x7d,0x74,0x77,0x72,0x71, + 0x50,0x53,0x56,0x55,0x5c,0x5f,0x5a,0x59,0x48,0x4b,0x4e,0x4d,0x44,0x47,0x42,0x41, + 0xc0,0xc3,0xc6,0xc5,0xcc,0xcf,0xca,0xc9,0xd8,0xdb,0xde,0xdd,0xd4,0xd7,0xd2,0xd1, + 0xf0,0xf3,0xf6,0xf5,0xfc,0xff,0xfa,0xf9,0xe8,0xeb,0xee,0xed,0xe4,0xe7,0xe2,0xe1, + 0xa0,0xa3,0xa6,0xa5,0xac,0xaf,0xaa,0xa9,0xb8,0xbb,0xbe,0xbd,0xb4,0xb7,0xb2,0xb1, + 0x90,0x93,0x96,0x95,0x9c,0x9f,0x9a,0x99,0x88,0x8b,0x8e,0x8d,0x84,0x87,0x82,0x81, + 0x9b,0x98,0x9d,0x9e,0x97,0x94,0x91,0x92,0x83,0x80,0x85,0x86,0x8f,0x8c,0x89,0x8a, + 0xab,0xa8,0xad,0xae,0xa7,0xa4,0xa1,0xa2,0xb3,0xb0,0xb5,0xb6,0xbf,0xbc,0xb9,0xba, + 0xfb,0xf8,0xfd,0xfe,0xf7,0xf4,0xf1,0xf2,0xe3,0xe0,0xe5,0xe6,0xef,0xec,0xe9,0xea, + 0xcb,0xc8,0xcd,0xce,0xc7,0xc4,0xc1,0xc2,0xd3,0xd0,0xd5,0xd6,0xdf,0xdc,0xd9,0xda, + 0x5b,0x58,0x5d,0x5e,0x57,0x54,0x51,0x52,0x43,0x40,0x45,0x46,0x4f,0x4c,0x49,0x4a, + 0x6b,0x68,0x6d,0x6e,0x67,0x64,0x61,0x62,0x73,0x70,0x75,0x76,0x7f,0x7c,0x79,0x7a, + 0x3b,0x38,0x3d,0x3e,0x37,0x34,0x31,0x32,0x23,0x20,0x25,0x26,0x2f,0x2c,0x29,0x2a, + 0x0b,0x08,0x0d,0x0e,0x07,0x04,0x01,0x02,0x13,0x10,0x15,0x16,0x1f,0x1c,0x19,0x1a +}; + +// Used in KeyExpansion +static const unsigned char rcon[256] = { + 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, + 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, + 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, + 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, + 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, + 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, + 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, + 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, + 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, + 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, + 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, + 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, + 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, + 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, + 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, + 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d +}; + +// Decryption: Inverse Rijndael S-box +static const unsigned char inv_s[256] = +{ + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, + 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, + 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, + 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, + 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, + 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, + 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, + 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, + 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, + 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, + 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D +}; + +// Decryption: Multiply by 9 for InverseMixColumns +static const unsigned char mul9[256] = +{ + 0x00,0x09,0x12,0x1b,0x24,0x2d,0x36,0x3f,0x48,0x41,0x5a,0x53,0x6c,0x65,0x7e,0x77, + 0x90,0x99,0x82,0x8b,0xb4,0xbd,0xa6,0xaf,0xd8,0xd1,0xca,0xc3,0xfc,0xf5,0xee,0xe7, + 0x3b,0x32,0x29,0x20,0x1f,0x16,0x0d,0x04,0x73,0x7a,0x61,0x68,0x57,0x5e,0x45,0x4c, + 0xab,0xa2,0xb9,0xb0,0x8f,0x86,0x9d,0x94,0xe3,0xea,0xf1,0xf8,0xc7,0xce,0xd5,0xdc, + 0x76,0x7f,0x64,0x6d,0x52,0x5b,0x40,0x49,0x3e,0x37,0x2c,0x25,0x1a,0x13,0x08,0x01, + 0xe6,0xef,0xf4,0xfd,0xc2,0xcb,0xd0,0xd9,0xae,0xa7,0xbc,0xb5,0x8a,0x83,0x98,0x91, + 0x4d,0x44,0x5f,0x56,0x69,0x60,0x7b,0x72,0x05,0x0c,0x17,0x1e,0x21,0x28,0x33,0x3a, + 0xdd,0xd4,0xcf,0xc6,0xf9,0xf0,0xeb,0xe2,0x95,0x9c,0x87,0x8e,0xb1,0xb8,0xa3,0xaa, + 0xec,0xe5,0xfe,0xf7,0xc8,0xc1,0xda,0xd3,0xa4,0xad,0xb6,0xbf,0x80,0x89,0x92,0x9b, + 0x7c,0x75,0x6e,0x67,0x58,0x51,0x4a,0x43,0x34,0x3d,0x26,0x2f,0x10,0x19,0x02,0x0b, + 0xd7,0xde,0xc5,0xcc,0xf3,0xfa,0xe1,0xe8,0x9f,0x96,0x8d,0x84,0xbb,0xb2,0xa9,0xa0, + 0x47,0x4e,0x55,0x5c,0x63,0x6a,0x71,0x78,0x0f,0x06,0x1d,0x14,0x2b,0x22,0x39,0x30, + 0x9a,0x93,0x88,0x81,0xbe,0xb7,0xac,0xa5,0xd2,0xdb,0xc0,0xc9,0xf6,0xff,0xe4,0xed, + 0x0a,0x03,0x18,0x11,0x2e,0x27,0x3c,0x35,0x42,0x4b,0x50,0x59,0x66,0x6f,0x74,0x7d, + 0xa1,0xa8,0xb3,0xba,0x85,0x8c,0x97,0x9e,0xe9,0xe0,0xfb,0xf2,0xcd,0xc4,0xdf,0xd6, + 0x31,0x38,0x23,0x2a,0x15,0x1c,0x07,0x0e,0x79,0x70,0x6b,0x62,0x5d,0x54,0x4f,0x46 +}; + +// Decryption: Multiply by 11 for InverseMixColumns +static const unsigned char mul11[256] = +{ + 0x00,0x0b,0x16,0x1d,0x2c,0x27,0x3a,0x31,0x58,0x53,0x4e,0x45,0x74,0x7f,0x62,0x69, + 0xb0,0xbb,0xa6,0xad,0x9c,0x97,0x8a,0x81,0xe8,0xe3,0xfe,0xf5,0xc4,0xcf,0xd2,0xd9, + 0x7b,0x70,0x6d,0x66,0x57,0x5c,0x41,0x4a,0x23,0x28,0x35,0x3e,0x0f,0x04,0x19,0x12, + 0xcb,0xc0,0xdd,0xd6,0xe7,0xec,0xf1,0xfa,0x93,0x98,0x85,0x8e,0xbf,0xb4,0xa9,0xa2, + 0xf6,0xfd,0xe0,0xeb,0xda,0xd1,0xcc,0xc7,0xae,0xa5,0xb8,0xb3,0x82,0x89,0x94,0x9f, + 0x46,0x4d,0x50,0x5b,0x6a,0x61,0x7c,0x77,0x1e,0x15,0x08,0x03,0x32,0x39,0x24,0x2f, + 0x8d,0x86,0x9b,0x90,0xa1,0xaa,0xb7,0xbc,0xd5,0xde,0xc3,0xc8,0xf9,0xf2,0xef,0xe4, + 0x3d,0x36,0x2b,0x20,0x11,0x1a,0x07,0x0c,0x65,0x6e,0x73,0x78,0x49,0x42,0x5f,0x54, + 0xf7,0xfc,0xe1,0xea,0xdb,0xd0,0xcd,0xc6,0xaf,0xa4,0xb9,0xb2,0x83,0x88,0x95,0x9e, + 0x47,0x4c,0x51,0x5a,0x6b,0x60,0x7d,0x76,0x1f,0x14,0x09,0x02,0x33,0x38,0x25,0x2e, + 0x8c,0x87,0x9a,0x91,0xa0,0xab,0xb6,0xbd,0xd4,0xdf,0xc2,0xc9,0xf8,0xf3,0xee,0xe5, + 0x3c,0x37,0x2a,0x21,0x10,0x1b,0x06,0x0d,0x64,0x6f,0x72,0x79,0x48,0x43,0x5e,0x55, + 0x01,0x0a,0x17,0x1c,0x2d,0x26,0x3b,0x30,0x59,0x52,0x4f,0x44,0x75,0x7e,0x63,0x68, + 0xb1,0xba,0xa7,0xac,0x9d,0x96,0x8b,0x80,0xe9,0xe2,0xff,0xf4,0xc5,0xce,0xd3,0xd8, + 0x7a,0x71,0x6c,0x67,0x56,0x5d,0x40,0x4b,0x22,0x29,0x34,0x3f,0x0e,0x05,0x18,0x13, + 0xca,0xc1,0xdc,0xd7,0xe6,0xed,0xf0,0xfb,0x92,0x99,0x84,0x8f,0xbe,0xb5,0xa8,0xa3 +}; + +// Decryption: Multiply by 13 for InverseMixColumns +static const unsigned char mul13[256] = +{ + 0x00,0x0d,0x1a,0x17,0x34,0x39,0x2e,0x23,0x68,0x65,0x72,0x7f,0x5c,0x51,0x46,0x4b, + 0xd0,0xdd,0xca,0xc7,0xe4,0xe9,0xfe,0xf3,0xb8,0xb5,0xa2,0xaf,0x8c,0x81,0x96,0x9b, + 0xbb,0xb6,0xa1,0xac,0x8f,0x82,0x95,0x98,0xd3,0xde,0xc9,0xc4,0xe7,0xea,0xfd,0xf0, + 0x6b,0x66,0x71,0x7c,0x5f,0x52,0x45,0x48,0x03,0x0e,0x19,0x14,0x37,0x3a,0x2d,0x20, + 0x6d,0x60,0x77,0x7a,0x59,0x54,0x43,0x4e,0x05,0x08,0x1f,0x12,0x31,0x3c,0x2b,0x26, + 0xbd,0xb0,0xa7,0xaa,0x89,0x84,0x93,0x9e,0xd5,0xd8,0xcf,0xc2,0xe1,0xec,0xfb,0xf6, + 0xd6,0xdb,0xcc,0xc1,0xe2,0xef,0xf8,0xf5,0xbe,0xb3,0xa4,0xa9,0x8a,0x87,0x90,0x9d, + 0x06,0x0b,0x1c,0x11,0x32,0x3f,0x28,0x25,0x6e,0x63,0x74,0x79,0x5a,0x57,0x40,0x4d, + 0xda,0xd7,0xc0,0xcd,0xee,0xe3,0xf4,0xf9,0xb2,0xbf,0xa8,0xa5,0x86,0x8b,0x9c,0x91, + 0x0a,0x07,0x10,0x1d,0x3e,0x33,0x24,0x29,0x62,0x6f,0x78,0x75,0x56,0x5b,0x4c,0x41, + 0x61,0x6c,0x7b,0x76,0x55,0x58,0x4f,0x42,0x09,0x04,0x13,0x1e,0x3d,0x30,0x27,0x2a, + 0xb1,0xbc,0xab,0xa6,0x85,0x88,0x9f,0x92,0xd9,0xd4,0xc3,0xce,0xed,0xe0,0xf7,0xfa, + 0xb7,0xba,0xad,0xa0,0x83,0x8e,0x99,0x94,0xdf,0xd2,0xc5,0xc8,0xeb,0xe6,0xf1,0xfc, + 0x67,0x6a,0x7d,0x70,0x53,0x5e,0x49,0x44,0x0f,0x02,0x15,0x18,0x3b,0x36,0x21,0x2c, + 0x0c,0x01,0x16,0x1b,0x38,0x35,0x22,0x2f,0x64,0x69,0x7e,0x73,0x50,0x5d,0x4a,0x47, + 0xdc,0xd1,0xc6,0xcb,0xe8,0xe5,0xf2,0xff,0xb4,0xb9,0xae,0xa3,0x80,0x8d,0x9a,0x97 +}; + +// Decryption: Multiply by 14 for InverseMixColumns +static const unsigned char mul14[256] = +{ + 0x00,0x0e,0x1c,0x12,0x38,0x36,0x24,0x2a,0x70,0x7e,0x6c,0x62,0x48,0x46,0x54,0x5a, + 0xe0,0xee,0xfc,0xf2,0xd8,0xd6,0xc4,0xca,0x90,0x9e,0x8c,0x82,0xa8,0xa6,0xb4,0xba, + 0xdb,0xd5,0xc7,0xc9,0xe3,0xed,0xff,0xf1,0xab,0xa5,0xb7,0xb9,0x93,0x9d,0x8f,0x81, + 0x3b,0x35,0x27,0x29,0x03,0x0d,0x1f,0x11,0x4b,0x45,0x57,0x59,0x73,0x7d,0x6f,0x61, + 0xad,0xa3,0xb1,0xbf,0x95,0x9b,0x89,0x87,0xdd,0xd3,0xc1,0xcf,0xe5,0xeb,0xf9,0xf7, + 0x4d,0x43,0x51,0x5f,0x75,0x7b,0x69,0x67,0x3d,0x33,0x21,0x2f,0x05,0x0b,0x19,0x17, + 0x76,0x78,0x6a,0x64,0x4e,0x40,0x52,0x5c,0x06,0x08,0x1a,0x14,0x3e,0x30,0x22,0x2c, + 0x96,0x98,0x8a,0x84,0xae,0xa0,0xb2,0xbc,0xe6,0xe8,0xfa,0xf4,0xde,0xd0,0xc2,0xcc, + 0x41,0x4f,0x5d,0x53,0x79,0x77,0x65,0x6b,0x31,0x3f,0x2d,0x23,0x09,0x07,0x15,0x1b, + 0xa1,0xaf,0xbd,0xb3,0x99,0x97,0x85,0x8b,0xd1,0xdf,0xcd,0xc3,0xe9,0xe7,0xf5,0xfb, + 0x9a,0x94,0x86,0x88,0xa2,0xac,0xbe,0xb0,0xea,0xe4,0xf6,0xf8,0xd2,0xdc,0xce,0xc0, + 0x7a,0x74,0x66,0x68,0x42,0x4c,0x5e,0x50,0x0a,0x04,0x16,0x18,0x32,0x3c,0x2e,0x20, + 0xec,0xe2,0xf0,0xfe,0xd4,0xda,0xc8,0xc6,0x9c,0x92,0x80,0x8e,0xa4,0xaa,0xb8,0xb6, + 0x0c,0x02,0x10,0x1e,0x34,0x3a,0x28,0x26,0x7c,0x72,0x60,0x6e,0x44,0x4a,0x58,0x56, + 0x37,0x39,0x2b,0x25,0x0f,0x01,0x13,0x1d,0x47,0x49,0x5b,0x55,0x7f,0x71,0x63,0x6d, + 0xd7,0xd9,0xcb,0xc5,0xef,0xe1,0xf3,0xfd,0xa7,0xa9,0xbb,0xb5,0x9f,0x91,0x83,0x8d +}; + +void KeyExpansionCore(unsigned char * in, unsigned char i); +void KeyExpansion(unsigned char* inputKey, unsigned char* expandedKeys); +#endif /* STRUCTURES_H */ diff --git a/src/test_nnctrl_live.c b/src/test_nnctrl_live.c new file mode 100644 index 0000000..ed42548 --- /dev/null +++ b/src/test_nnctrl_live.c @@ -0,0 +1,18365 @@ + +#include "test_nnctrl_live.h" + +#include "ivs_detection.h" + +#include "url_encode.h" +#if defined GY_OS_AMBA +#include "ir_control.h" +#endif + +#ifdef GY_OS_AMBA +//#include "radar_driver.h" +//#include "radar_parser.h" +//#include "face_parser.h" +//#include "tof.h" + +#include "barcode.h" +#include "test_yuv_rgb.h" +// #include "dbscan.c" // Ken 2022-10-21 +#endif +#include <setjmp.h> +#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){ +#define CATCH } else { +#define ETRY } }while(0) +#define THROW longjmp(ex_buf__, 1) + +int g_li, g_ad; +int g_bMacMatch = 0; +time_t g_start_time, g_end_time; +char g_filename_TLT[1024] = { 0 }; + +int live_mode_flag = 1; +struct nnctrl_param G_nnctrl; +#ifdef GY_OS_AMBA +static float g_f_socket_data[MAX_VPOUT_LENGTH] = { 0 }; + +static char g_parse_buffer[MAX_VPOUT_LENGTH] = { 0 }; + +struct cv_mem lib_mem; +struct cv_mem yuv2rgb_out_mem; +//struct cv_mem rsz_out_mem; +//struct cv_mem dtcvt_out_mem; +//struct cv_mem submean_mean_mem; +//struct cv_mem submean_out_mem; + +struct cv_mem downsized_cropped_mem; + +struct cv_mem snap_hd_mem; + +struct cv_mem rgb_2K_mem; + +struct cv_mem tof_img_mem; + +struct cv_mem barcode_img_mem; +int count_frame = 0; +int tof_shmid = -1; +//frameimage_yuv *tof_yuv_arr = NULL; +//long tof_yuv_size = TOF_WIDTH * TOF_HEIGHT * sizeof(unsigned int); + +#endif + +int g_alter_something = 0;//0 S]w // 1 u䴩setconfigfileseteventsfile]wܡFpGOsetconfigseteventsAh䴩]wܡCثe]wOsetconfigfileseteventsfileC +int g_count_alter = 0; ////]wA|delay8-10kAóseܤ34ܳ]wTAAsC + +int iFeature_lpr_layer_index = -1; +int iFeature_traf_det_layer_index = -1; +int iFeature_traf_det_layer_index_2 = -1; +int iFeature_access_ctrl_det_layer_index[MAX_LAYER_NUM] = {-1}; +int index_access = 0; +int iFeature_aifire_det_layer_index = -1; +int iFeature_aero_det_layer_index = -1; +int iFeature_tof_det_layer_index = -1; +int iFeature_mask_layer_index = -1; +int iFeature_safety_layer_index = -1; +int iFeature_rail_layer_index = -1; +int iFeature_sports_layer_index = -1; +int iFeature_garbage_layer_index = -1; +int iFeature_ship_layer_index = -1; +int iFeature_production_layer_index = -1; +int iFeature_animal_layer_index = -1; +int iFeature_logo_layer_index = -1; +int iFeature_finial_index = -1; + +int g_counter_index_post = 0; +int g_counter_index_long = 0; + +int check_stop_test_nn_cavalry = 0; + +#ifdef GY_OS_AMBA +static char mean_name[FILENAME_LENGTH] = { 0 }; +static int fd_iav; + +unsigned int g_last_dsp_pts = 0; +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int g_check_sync_anpr = 0; +//int g_face_frame_number_tmp = 0; //face recognition global sync -leo +#endif + +int g_check_sync_traffic = 0; +int g_check_sync_differ = 0; +//int g_extra_check_differ_run = 0; + +static int switch_traffic = 0; +static int switch_anpr = 0; +static int switch_differ = 0; +#ifdef GY_OS_AMBA +//static int switch_face = 0;//face recognition switch -leo +#endif +int check_if_enable_trigger_go_straight_temp = 0; +int check_if_enable_trigger_go_straight = 0; + +#ifdef GY_OS_AMBA +static int G_socket_id; +#endif +static int G_port = 27182; + +#ifdef GY_OS_AMBA +static int dsp_state; +static uint8_t *dsp_mem = NULL; +static uint32_t dsp_phy_addr; +static uint32_t dsp_size = 0; +//static int submean_flag = 0; +static int yuv2rgb_resize_only_flag = 0; +//static float scale_factor = 1; +#endif +static int buffer_id = 0; +static int buffer_type = 0; +static int rgb_type = 1; +unsigned int frame_id = 0; + +#ifdef GY_OS_AMBA +static int send_desc_flag = 1; +#endif + +//static int protected_deinit_amba_yolov3 = 0; +//static int protected_nnctrl_exit_net = 0; + +/*//int tiny_enable = 1; +int tiny_enable = 0; +int input_bin_num = AMBA_YOLOV3_FEATURE_NUM; //none_tiny +//int input_bin_num = AMBA_YOLOV3_FEATURE_MAP_8; //tiny*/ + +#ifdef GY_OS_AMBA +int g_ori_yuv_width = 0; +int g_ori_yuv_height = 0; +int g_ori_half_yuv_width = 0; +int g_ori_half_yuv_height = 0; +#endif + +#ifdef GY_OS_NOVA +int g_ori_yuv_width = NET_SIZE_W; +int g_ori_yuv_height = NET_SIZE_H; +int g_ori_half_yuv_width = NET_SIZE_W / 2; +int g_ori_half_yuv_height = NET_SIZE_H / 2; +#endif + +#ifdef GY_OS_AMBA +int g_img_width = 416; +int g_img_height = 416; + +int g_total_cls = 1; +int g_total_cls_sec = 36; +float g_threshold = 0.1;//0.2 +#endif +//float nms_threshold = 0.1;//0.3 + +uint32_t classNum = 0, ratio = 0; +#ifdef GY_OS_AMBA +float anchors[YOLOV3_ANCHOR_NUM] = { 10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326 }; +float anchors_sec[YOLOV3_ANCHOR_NUM] = { 10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326 }; +char label_file[FILENAME_LENGTH] = { 0 }; +char anchor_file[FILENAME_LENGTH] = { 0 }; +#endif +int g_verbose = 0; + +int live_flag = 1; +int xoff = 0; +int yoff = 0; +int rwd = 0; +int rht = 0; +#ifdef GY_OS_AMBA +float magnification_ratio = 0.02; +float magnification_ratio_height = 0.01; +#endif + +///init parse bbox +#ifdef GY_OS_AMBA +int init_yolov3_flag[MAX_NET_NUM] = { 0 }; +#endif +int ai_frame_counter = 0; + +int current_image_id_for_anpr = 0; +#ifdef GY_OS_AMBA +int current_image_id_for_face = 0; +#endif +int current_image_id_for_object = 0; + +#ifdef GY_OS_AMBA +static char g_img_buf[MAX_PLATE_BUF_NUM][MAX_IMG_SIZE] = { 0 }; +static char g_cropped_img_buf[MAX_PLATE_BUF_NUM][MAX_IMG_SIZE] = { 0 }; +static int g_cropped_length_image[MAX_PLATE_BUF_NUM] = { 0 }; +static int g_downsized_cropped_shape_w[MAX_PLATE_BUF_NUM] = { 0 }; +static int g_downsized_cropped_pitch[MAX_PLATE_BUF_NUM] = { 0 }; +static int g_downsized_cropped_shape_h[MAX_PLATE_BUF_NUM] = { 0 }; + +static char g_img_buf_for_barode[MAX_PLATE_BUF_NUM][MAX_IMG_SIZE] = { 0 }; +static int g_shape_w_for_barode = 0; +static int g_pitch_for_barode = 0; +static int g_shape_h_for_barode = 0; + +#endif + +static char g_cropped_img_buf_base64[MAX_PLATE_BUF_NUM][MAX_IMG_SIZE] = { 0 }; +static int g_cropped_length_image_base64[MAX_PLATE_BUF_NUM] = { 0 }; + +int g_total_element_size = 0; +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int g_element_size[MAX_LAYER_NUM][MAX_PLATE_BUF_NUM] = { 0 }; +#endif + +#ifdef GY_OS_AMBA +static char g_img_buf_for_snaphd[MAX_IMG_SIZE] = { 0 }; +static int g_snap_hd_shape_w_for_snaphd = 0; +static int g_snap_hd_pitch_for_snaphd = 0; +static int g_snap_hd_shape_h_for_snaphd = 0; +#endif +int g_total_element_size_traffic = 0; +int g_element_size_traffic[MAX_LAYER_NUM][MAX_OBJECT_NUM] = { 0 }; + +int g_total_element_size_differ = 0; +int g_total_element_size_ivs = 0; + +static int enable_downsized_cropped_roi = 0; +static int enable_zone_crop_1 = 0; + +static int check_first_downsized_cropped_roi = 0; + +static int check_first_downsized_cropped_roi_for_object = 0; + +static char g_MetaOut1[MAX_DETECTION_ZONE][512][50] = { 0 }; +static int g_Meta_If_Existing[MAX_DETECTION_ZONE][512] = { 0 }; +static int g_check_if_all_existing[MAX_DETECTION_ZONE] = { 0 }; +static int g_last_check_if_all_existing[MAX_DETECTION_ZONE] = { 0 }; +static int g_metadata1_num_for_zone[MAX_DETECTION_ZONE] = { 0 }; + +static int g_Meta_If_Existing_for_NAND[MAX_DETECTION_ZONE][512] = { 0 }; +static int g_check_if_NAND[MAX_DETECTION_ZONE] = { 0 }; + +static int count_fps_for_NAND[MAX_DETECTION_ZONE] = { 0 }; + +char g_buf_image_id[128] = { 0 }; + +char g_debug_plate[BUFSIZE_V2] = { 0 }; + +int g_check_if_show_parking = 0; + +struct nnctrl_param *g_pctrl = NULL; +struct nnctrl_param *g_pctrl_run_one_net = NULL; +struct nnctrl_param *g_pctrl_run_one_net_anpr = NULL; + +int g_check_if_differ_image_is_running = 0; + +//int g_rval = 0; + +struct amba_content g_stAMBAcontent = {0}; +int g_bbox_ret = 0; +#if 1 +detection_pos g_PosInfo[MAX_DETECT_OBJECTS] = { 0 }; +#endif + +detection_pos g_PosInfo_traffic[MAX_DETECT_OBJECTS] = {0}; + +#if defined GY_OS_AMBA +detection_pos g_PosInfo_differ[MAX_DETECT_OBJECTS] = { 0 }; +detection_pos g_PosInfo_ivs[MAX_DETECT_OBJECTS] = { 0 }; +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +ffgroup_db_tb l_ff_insert_data; +#endif +#ifdef GY_OS_AMBA +//facegroup_db_tb l_face_insert_data; +//int add_white_face_flag = 0; +#endif +int g_b_ZoneExist[MAX_DETECTION_ZONE] = { 0 }; +CPoint g_zone_polygon[MAX_DETECTION_ZONE][6] = { 0 }; +int g_side_number = 6; + +int g_last_check_if_something_vanish_in_zone_Yes[MAX_DETECTION_ZONE] = { 0 }; + +char g_current_snapshot_addr[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size = 0; +#ifdef GY_OS_AMBA +char g_current_snapshot_addr_HD[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_HD = 0; +#endif +char g_current_snapshot_addr_crop_zone[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_crop_zone = 0; + +char g_current_snapshot_addr_base64[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_base64 = 0; + +char g_current_snapshot_addr_udp[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_udp = 0; +char g_current_snapshot_addr_udp_base64[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_udp_base64 = 0; + +char g_current_snapshot_addr_8592[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_8592 = 0; +char g_current_snapshot_addr_8592_base64[MAX_IMG_SIZE] = { 0 }; +int g_current_snapshot_size_8592_base64 = 0; + +char g_current_image_state_response[256] = { 0 }; + +int g_check_if_metadata_stop_happened[MAX_DETECTION_ZONE] = {0}; +static long s_last_t_metadata_stop[MAX_DETECTION_ZONE] = { 0 }; +static long s_now_t_metadata_stop = 0; +struct timeval now_t_metadata_stop; + +int g_osdTime_sw = 1; + +int g_osdSysTimeZoneInfo = 0; +long g_post_SysTimeStamp = 0; + +int g_check_if_current_light_is_red = 0; + +#ifdef GY_OS_AMBA +//#define MAX_REUSE_MEM_SZ (2 << 20) +#define MAX_REUSE_MEM_SZ (500000) +//char G_reuse_mem[MAX_REUSE_MEM_SZ] = { 0 }; //1048576 +int firstRead = 0; +#endif + +//static int crapped_roi_times = 0; + +#define NO_ARG 0 +#define HAS_ARG 1 + +int get_g_check_if_show_parking() { + return g_check_if_show_parking; +} + +int get_g_check_if_current_light_is_red() { + return g_check_if_current_light_is_red; +} + +#ifdef GY_OS_AMBA +unsigned long get_ori_c_image(char *c_image) { + //printf("\n-------start:A:2\n"); + + //image_virt = g_img_buf[0]; + //memcpy(g_img_buf[pNext_plate->image_id], downsized_cropped_mem.virt, downsized_cropped_mem.size); + + + //SaveRawRGBToJPG("/emmc/plugin/Aida_data/hello.jpg", g_img_buf_for_snaphd, g_snap_hd_shape_w_for_snaphd, g_snap_hd_pitch_for_snaphd, g_snap_hd_shape_h_for_snaphd, 0); + //printf("\n-------start:B:2\n"); + int length_image = 0; + + if (g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + //pthread_mutex_lock(&mutex_snap_hd_image); + memset(g_img_buf_for_snaphd, 0x00, MAX_IMG_SIZE); + g_snap_hd_shape_w_for_snaphd = 0; + g_snap_hd_pitch_for_snaphd = 0; + g_snap_hd_shape_h_for_snaphd = 0; + + snap_hd_image(); + if (g_snap_hd_shape_w_for_snaphd >= 1) { + length_image = SaveRawRGBToChar(c_image, g_img_buf_for_snaphd, g_snap_hd_shape_w_for_snaphd, g_snap_hd_pitch_for_snaphd, g_snap_hd_shape_h_for_snaphd, 0); + } + + //pthread_mutex_unlock(&mutex_snap_hd_image); + //printf("\n-------end:AB:2\n"); + } + return (unsigned long)(length_image); +} + + +static int set_io_pair(char *in_opt, struct io_match(*io_pair)[], uint32_t count) +{ + + if (count >= MAX_IO_NUM) { + printf("IO pair number [%u] exceeds max IO number limits [%u].\n", count, MAX_IO_NUM); + return -1; + } + + if (strlen(in_opt) > CAVALRY_IO_NAME_MAX) { + printf("io port name [%s] is too long, max[%u]\n", in_opt, CAVALRY_IO_NAME_MAX); + return -1; + } + strncpy((*io_pair)[count].port_name, in_opt, sizeof((*io_pair)[count].port_name) - 1); + + return 0; +} +#endif + +static int init_label_file_lilin(char *label_file, char array[MAX_CLASS_NUM][CLASSNAME_LENGTH]) +{ + FILE *file = NULL; + unsigned char temp_ch=0; + unsigned char buf_ch[CLASSNAME_LENGTH] = { 0 }; + unsigned char end_ch = 0xFF; + int i = 0, j = 0; + + file = fopen(label_file, "r"); + if (file) + { + //printf("Start to load specified label file:\n"); + + while (!feof(file) && (i < MAX_CLASS_NUM)) + { + temp_ch = fgetc(file); + + if (j < CLASSNAME_LENGTH - 1) + { + if ((temp_ch == '\n') || (temp_ch == end_ch)) + { + //20201023 sophia add + sprintf(array[i], "\%s", buf_ch); + sprintf(array[i + 1], "\%s", buf_ch); + //printf(" object %d, %s len:%d\n", i, array[i], strlen(array[i])); + //printf(" object %d, %s len:%d\n", i + 1, array[i + 1], strlen(array[i + 1])); + memset(buf_ch, 0, CLASSNAME_LENGTH); + j = 0; + i = i + 2; + + //printf(" object %d, %s len:%d\n", i, array[i], strlen(array[i])); + + //20201023 sophia mark + /*strncpy(array[i], buf_ch, CLASSNAME_LENGTH); + printf(" object %d, %s len:%d\n", i, array[i],strlen(array[i])); + memset(buf_ch, 0, CLASSNAME_LENGTH); + j = 0; + i++;*/ + } + else if (temp_ch != '\n' && temp_ch != '\r') + { + buf_ch[j] = temp_ch; + j++; + } + } + else + { + //20201023 sophia add + printf(" maximum class name reached, "); + sprintf(array[i], "\%s", buf_ch); + sprintf(array[i + 1], "\%s", buf_ch); + //printf(" object %d, %s len:%d\n", i, array[i], strlen(array[i])); + //printf(" object %d, %s len:%d\n", i + 1, array[i + 1], strlen(array[i + 1])); + memset(buf_ch, 0, CLASSNAME_LENGTH); + j = 0; + i = i + 2; + + //20201023 sophia mark + /*strncpy(array[i], buf_ch, CLASSNAME_LENGTH); + printf("object %d, %s\n", i, array[i]); + memset(buf_ch, 0, CLASSNAME_LENGTH); + j = 0; + i++;*/ + } + } + //printf("\nKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\n"); + //printf("\n[init_label_file_lilin]array[0]: %s\n", array[0]); + //printf("\n[init_label_file_lilin]array[1]: %s\n", array[1]); + + fclose(file); + return i; + } + else + { + printf("Open label file failed. Will use default COCO label list! \n"); + return -1; + } +} + +static int init_ver_file(char *ver_file, char array[CLASSNAME_LENGTH]) +{ + FILE *file = NULL; + char temp_ch; + char buf_ch[CLASSNAME_LENGTH] = { 0 }; + int i = 0,j=0; + int rval = 0; + + file = fopen(ver_file, "r"); + if (file) { + //printf("Reload classes with ver file!\n"); + while (!feof(file)) { + temp_ch = fgetc(file); + if ((temp_ch >= '0' && temp_ch <= '9') || temp_ch == '.') { + if (j < (CLASSNAME_LENGTH - 1)) { + buf_ch[j] = temp_ch; + j++; + } + } + } + + if (j == 0) { + printf("Wrong Format with null ver name!\n"); + rval = -1; + } + else { + strncpy(array, buf_ch, CLASSNAME_LENGTH); + j = 0; + i++; + memset(buf_ch, 0, CLASSNAME_LENGTH); + } + + if (rval == 0) { + if (i == 0) { + printf("Wrong Format which is not support!\n"); + rval = -1; + } + else { + rval = i; + //printf("Initial %d ver successfully~\n", i); + } + } + + fclose(file); + } + else { + printf("Open ver file fail! \n"); + rval = -1; + } + + return rval; +} + +float get_nms_thres(float nms_threshold) { + if (strcmp(SystemSetting.enable_cloud, "Yes") == 0) { + return ((float)(atoi(SystemSetting.nms_thres))) / 100.0; + } + else { + return nms_threshold; + } +} + +static int alloc_cv_mem(uint32_t *psize, uint32_t *pphys, uint8_t **pvirt) +{ + void *virt = 0; + unsigned long phys = 0, size = 0; + + size = *psize; + if (cavalry_mem_alloc(&size, &phys, &virt, 1,1) < 0) { + printf("cavalry_mem_alloc err #1\n"); + + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "cavalry_mem_alloc err #1"); + write_to_logs_html(temp_msg, "alloc cv mem", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "alloc cv mem", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + return -1; + } + *psize = size; + *pphys = phys; + *pvirt = virt; + + return 0; +} + +static int set_net_io_cfg(struct net_match *pnet, + struct net_input_cfg *net_in, struct net_output_cfg *net_out) +{ + uint32_t i = 0; + + net_in->in_num = pnet->in_num; + net_out->out_num = pnet->out_num; + for (i = 0; i < net_in->in_num; i++) { + //printf("in num = %d \n", net_in->in_num); + if (i > MAX_IO_NUM) { + printf("Overflow input num: %u, max: %u", i, MAX_IO_NUM); + return -1; + } + net_in->in_desc[i].name = pnet->in_pair[i].port_name; + if (pnet->in_pair[i].no_mem) { + net_in->in_desc[i].no_mem = 1; + net_in->in_desc[i].addr = pnet->in_pair[i].dram_addr; + net_in->in_desc[i].size = pnet->in_pair[i].dram_size; + } + } + for (i = 0; i < net_out->out_num; i++) { + if (i > MAX_IO_NUM) { + printf("Overflow output num: %u, max: %u", i, MAX_IO_NUM); + return -1; + } + net_out->out_desc[i].name = pnet->out_pair[i].port_name; + } + + return 0; +} + +static int get_net_io_cfg(struct net_match *pnet, + struct net_input_cfg *net_in, struct net_output_cfg *net_out) +{ + uint32_t i = 0; + int rval = 0; + + for (i = 0; i < net_in->in_num; i++) { + if (pnet->in_pair[i].no_mem == 0) { + pnet->in_pair[i].dram_addr = net_in->in_desc[i].addr; + pnet->in_pair[i].dram_size = net_in->in_desc[i].size; + if ((net_in->in_desc[i].addr == 0) || (net_in->in_desc[i].size == 0)) { + printf("Input [%u] [%s] get invalid addr: 0x%x, size: 0x%x\n", + i, + net_in->in_desc[i].name, + net_in->in_desc[i].addr, + net_in->in_desc[i].size); + rval = -1; + break; + } + } + printf("Input [%u] [%s] dimension: %u, %u, %u, %u, pitch: %u, " + "dram_format: %u, data_format: %u, %u, %u, %u\n", + i, + net_in->in_desc[i].name, + net_in->in_desc[i].dim.plane, + net_in->in_desc[i].dim.depth, + net_in->in_desc[i].dim.height, + net_in->in_desc[i].dim.width, + net_in->in_desc[i].dim.pitch, + net_in->in_desc[i].dim.dram_fmt, + net_in->in_desc[i].data_fmt.sign, + net_in->in_desc[i].data_fmt.size, + net_in->in_desc[i].data_fmt.expoffset, + net_in->in_desc[i].data_fmt.expbits); + + } + + for (i = 0; i < net_out->out_num; i++) { + if ((net_out->out_desc[i].addr == 0) || (net_out->out_desc[i].size == 0)) { + printf("Output [%u] [%s] get invalid addr: 0x%x, size: 0x%x\n", + i, + net_out->out_desc[i].name, + net_out->out_desc[i].addr, + net_out->out_desc[i].size); + rval = -1; + break; + } + pnet->out_pair[i].dram_addr = net_out->out_desc[i].addr; + pnet->out_pair[i].dram_size = net_out->out_desc[i].size; + printf("Output [%u] [%s] dimension: %u, %u, %u, %u, pitch: %u, " + "dram_format: %u, data_format: %u, %u, %u, %u\n", + i, + net_out->out_desc[i].name, + net_out->out_desc[i].dim.plane, + net_out->out_desc[i].dim.depth, + net_out->out_desc[i].dim.height, + net_out->out_desc[i].dim.width, + net_out->out_desc[i].dim.pitch, + net_out->out_desc[i].dim.dram_fmt, + net_out->out_desc[i].data_fmt.sign, + net_out->out_desc[i].data_fmt.size, + net_out->out_desc[i].data_fmt.expoffset, + net_out->out_desc[i].data_fmt.expbits); + } + + return rval; +} + +/*static int load_mean_binary(char *file, void *dst_addr, vect_desc_t *mean_file, unsigned long *size) +{ + FILE *fp = NULL; + int rval = 0; + int i, datasize; + uint32_t plane, depth, height, width, pitch; + unsigned long file_length; + + do { + if ((fp = fopen(file, "rb")) == NULL) { + printf("\n%s\n",file); + rval = -1; + break; + } + + if (fseek(fp, 0, SEEK_END) < 0) { + printf("\nSEEK_END\n"); + rval = -1; + break; + } + file_length = ftell(fp); + + if (fseek(fp, 0, SEEK_SET) < 0) { + printf("\nSEEK_SET\n"); + rval = -1; + break; + } + plane = mean_file->shape.p; + depth = mean_file->shape.d; + height = mean_file->shape.h; + width = mean_file->shape.w; + pitch = mean_file->pitch; + datasize = 1 << mean_file->data_format.datasize; + printf("\nload sub_mean mean file, file size = %ld, expect size = %d\n", + file_length, plane * depth * height * ROUND_UP(datasize * width, 32)); + + if (file_length == *size) { + if (fread(dst_addr, 1, file_length, fp) != file_length) { + printf("file size mismatch, should be fp16, %d bytes!\n", + plane * depth * height * ROUND_UP(datasize * width, 32)); + rval = -1; + break; + } + } + else if (file_length == plane * depth * height * width * datasize) { + if (pitch - width * datasize > 0) { + printf("Pitch(%d) != width * datasize(%d), add pitch %d automatically\n", + pitch, width * datasize, pitch - width * datasize); + for (i = 0; i < plane * depth * height; i++) { + if (fread(dst_addr + i * pitch, datasize, width, fp) != width) { + printf("file size mismatch, should be fp16, %d bytes!\n", + plane * depth * height * ROUND_UP(datasize * width, 32)); + rval = -1; + break; + } + memset(dst_addr + i * pitch + width * datasize, + 0, pitch - width * datasize); + } + } + else { + printf("Pitch < width * datasize, load mean file error\n"); + rval = -1; + break; + } + } + else { + printf("file size mismatch, should be fp16, %d bytes, " + "please check the mean file and input data format!\n", + plane * depth * height * ROUND_UP(datasize * width, 32)); + rval = -1; + break; + } + fclose(fp); + fp = NULL; + } while (0); + + if (fp) { + fclose(fp); + fp = NULL; + } + + return rval; +}*/ + +//load_no_padding_mem(G_reuse_mem, tof_img_mem.virt, +// y.shape.w, y.pitch, y.shape.h * 3 / 2); + +void load_no_padding_mem(uint8_t *virt_src, uint8_t *virt_dst, + uint32_t width_sz, uint32_t pitch_sz, uint32_t column) +{ + uint8_t *dst = NULL, *src = NULL; + uint32_t c = 0; + + src = virt_src; + dst = virt_dst; + for (c = 0; c < column; c++) { + memcpy(dst, src, width_sz); + src += width_sz; + dst += pitch_sz; + } +} + + +static vect_desc_t *y_p, *uv_p, *rgb_p; +static yuv2rgb_mat_t *yuv2rgb_mat_p; +static yuv2rgb_mat_t yuv2rgb_mat; +//static vect_desc_t submean_in, submean_mean, submean_out; +//static vect_desc_t scale_in, scale_out; +//static int get_network_input(struct net_input_cfg *net_in) +struct iav_yuv_cap *data_cap; + +static int vproc_init_flag = 1; +static vect_desc_t rgb; +static vect_desc_t rgb_2K; + +//static int Table_fv1[256] = { -180, -179, -177, -176, -174, -173, -172, -170, -169, -167, -166, -165, -163, -162, -160, -159, -158, -156, -155, -153, -152, -151, -149, -148, -146, -145, -144, -142, -141, -139, -138, -137, -135, -134, -132, -131, -130, -128, -127, -125, -124, -123, -121, -120, -118, -117, -115, -114, -113, -111, -110, -108, -107, -106, -104, -103, -101, -100, -99, -97, -96, -94, -93, -92, -90, -89, -87, -86, -85, -83, -82, -80, -79, -78, -76, -75, -73, -72, -71, -69, -68, -66, -65, -64,-62, -61, -59, -58, -57, -55, -54, -52, -51, -50, -48, -47, -45, -44, -43, -41, -40, -38, -37, -36, -34, -33, -31, -30, -29, -27, -26, -24, -23, -22, -20, -19, -17, -16, -15, -13, -12, -10, -9, -8, -6, -5, -3, -2, 0, 1, 2, 4, 5, 7, 8, 9, 11, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25, 26, 28, 29, 30, 32, 33, 35, 36, 37, 39, 40, 42, 43, 44, 46, 47, 49, 50, 51, 53, 54, 56, 57, 58, 60, 61, 63, 64, 65, 67, 68, 70, 71, 72, 74, 75, 77, 78, 79, 81, 82, 84, 85, 86, 88, 89, 91, 92, 93, 95, 96, 98, 99, 100, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 124, 126, 127, 129, 130, 131, 133, 134, 136, 137, 138, 140, 141, 143, 144, 145, 147, 148, 150, 151, 152, 154, 155, 157, 158, 159, 161, 162, 164, 165, 166, 168, 169, 171, 172, 173, 175, 176, 178 }; +//static int Table_fv2[256] = { -92, -91, -91, -90, -89, -88, -88, -87, -86, -86, -85, -84, -83, -83, -82, -81, -81, -80, -79, -78, -78, -77, -76, -76, -75, -74, -73, -73, -72, -71, -71, -70, -69, -68, -68, -67, -66, -66, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55, -54, -53, -53, -52, -51, -51, -50, -49, -48, -48, -47, -46, -46, -45, -44, -43, -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, -33, -32, -31, -31, -30, -29, -28, -28, -27, -26, -26, -25, -24, -23, -23, -22, -21, -21, -20, -19, -18, -18, -17, -16, -16, -15, -14, -13, -13, -12, -11, -11, -10, -9, -8, -8, -7, -6, -6, -5, -4, -3, -3, -2, -1, 0, 0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 22, 23, 24, 25, 25, 26, 27, 27, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 37, 38, 39, 40, 40, 41, 42, 42, 43, 44, 45, 45, 46, 47, 47, 48, 49, 50, 50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 62, 63, 64, 65, 65, 66, 67, 67, 68, 69, 70, 70, 71, 72, 72, 73, 74, 75, 75, 76, 77, 77, 78, 79, 80, 80, 81, 82, 82, 83, 84, 85, 85, 86, 87, 87, 88, 89, 90, 90 }; +//static int Table_fu1[256] = { -44, -44, -44, -43, -43, -43, -42, -42, -42, -41, -41, -41, -40, -40, -40, -39, -39, -39, -38, -38, -38, -37, -37, -37, -36, -36, -36, -35, -35, -35, -34, -34, -33, -33, -33, -32, -32, -32, -31, -31, -31, -30, -30, -30, -29, -29, -29, -28, -28, -28, -27, -27, -27, -26, -26, -26, -25, -25, -25, -24, -24, -24, -23, -23, -22, -22, -22, -21, -21, -21, -20, -20, -20, -19, -19, -19, -18, -18, -18, -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -11, -11, -11, -10, -10, -10, -9, -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -6, -5, -5, -5, -4, -4, -4, -3, -3, -3, -2, -2, -2, -1, -1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, 43, 43 }; +//static int Table_fu2[256] = { -227, -226, -224, -222, -220, -219, -217, -215, -213, -212, -210, -208, -206, -204, -203, -201, -199, -197, -196, -194, -192, -190, -188, -187, -185, -183, -181, -180, -178, -176, -174, -173, -171, -169, -167, -165, -164, -162, -160, -158, -157, -155, -153, -151, -149, -148, -146, -144, -142, -141, -139, -137, -135, -134, -132, -130, -128, -126, -125, -123, -121, -119, -118, -116, -114, -112, -110, -109, -107, -105, -103, -102, -100, -98, -96, -94, -93, -91, -89, -87, -86, -84, -82, -80, -79, -77, -75, -73, -71, -70, -68, -66, -64, -63, -61, -59, -57, -55, -54, -52, -50, -48, -47, -45, -43, -41, -40, -38, -36, -34, -32, -31, -29, -27, -25, -24, -22, -20, -18, -16, -15, -13, -11, -9, -8, -6, -4, -2, 0, 1, 3, 5, 7, 8, 10, 12, 14, 15, 17, 19, 21, 23, 24, 26, 28, 30, 31, 33, 35, 37, 39, 40, 42, 44, 46, 47, 49, 51, 53, 54, 56, 58, 60, 62, 63, 65, 67, 69, 70, 72, 74, 76, 78, 79, 81, 83, 85, 86, 88, 90, 92, 93, 95, 97, 99, 101, 102, 104, 106, 108, 109, 111, 113, 115, 117, 118, 120, 122, 124, 125, 127, 129, 131, 133, 134, 136, 138, 140, 141, 143, 145, 147, 148, 150, 152, 154, 156, 157, 159, 161, 163, 164, 166, 168, 170, 172, 173, 175, 177, 179, 180, 182, 184, 186, 187, 189, 191, 193, 195, 196, 198, 200, 202, 203, 205, 207, 209, 211, 212, 214, 216, 218, 219, 221, 223, 225 }; + + +//uint8_t uint8_tof_yuv_arr[TOF_WIDTH * TOF_HEIGHT*3/2] = { 0 }; + +//uint8_t uint8_tof_rgb_arr[TOF_WIDTH * TOF_HEIGHT * 3] = { 0 }; + +//uint32_t uint32_tof_rgb_arr[TOF_WIDTH * TOF_HEIGHT] = { 0 }; + +//uint32_t uint32_tof_yuv_arr[TOF_WIDTH * TOF_HEIGHT * 3 / 2 / 4] = { 0 }; +//uint32_t offset_unit8_tof_yuv = TOF_WIDTH * TOF_HEIGHT; +//uint32_t offset_unit32_tof_yuv = TOF_WIDTH * TOF_HEIGHT / 4; + +//int count_yuv = 0; +static int get_network_input(struct nnctrl_param *pctrl) +{ + //printf("\n get_network_input start-----------\n"); + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + //uint8_t *tof_YUV = NULL; + //uint32_t *tof_YUV = NULL; + //uint32_t tof_YUV_width = TOF_WIDTH; + //uint32_t tof_YUV_height = TOF_HEIGHT; + //uint32_t tof_YUV_pitch = ROUND_UP(tof_YUV_width * (1 << 0), 32); + + struct net_input_cfg *net_in; + net_in = &pctrl->net_pair[0].net_in; + + //static int buf = 0; + //static int non_block_read = 1; + + struct iav_querydesc query_desc; + + static vect_desc_t y, uv; + static vect_desc_t rsz_in, rsz_out; + //static vect_desc_t dtcvt_in, dtcvt_out; + + if (vproc_init_flag) + { + memset(&y, 0, sizeof(y)); + memset(&uv, 0, sizeof(uv)); + memset(&rgb, 0, sizeof(rgb)); + memset(&yuv2rgb_mat, 0, sizeof(yuv2rgb_mat)); + memset(&yuv2rgb_out_mem, 0, sizeof(yuv2rgb_out_mem)); + //memset(&rsz_out_mem, 0, sizeof(rsz_out_mem)); + //memset(&dtcvt_out_mem, 0, sizeof(dtcvt_out_mem)); + //memset(&submean_mean_mem, 0, sizeof(submean_mean_mem)); + //memset(&submean_out_mem, 0, sizeof(submean_out_mem)); + memset(&rsz_in, 0, sizeof(rsz_in)); + memset(&rsz_out, 0, sizeof(rsz_out)); + //memset(&dtcvt_in, 0, sizeof(dtcvt_in)); + //memset(&dtcvt_out, 0, sizeof(dtcvt_out)); + //memset(&submean_in, 0, sizeof(submean_in)); + //memset(&submean_mean, 0, sizeof(submean_mean)); + //memset(&submean_out, 0, sizeof(submean_out)); + //memset(&scale_in, 0, sizeof(scale_in)); + //memset(&scale_out, 0, sizeof(scale_out)); + memset(&query_desc, 0, sizeof(query_desc)); + memset(&downsized_cropped_mem, 0, sizeof(downsized_cropped_mem)); + memset(&snap_hd_mem, 0, sizeof(snap_hd_mem)); + memset(&rgb_2K, 0, sizeof(rgb_2K)); + memset(&rgb_2K_mem, 0, sizeof(rgb_2K_mem)); + + memset(&tof_img_mem, 0, sizeof(tof_img_mem)); + memset(&barcode_img_mem, 0, sizeof(barcode_img_mem)); + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get network input #1:%lf ms\n", dw_FPS_time_delta); + + if (g_IsToFDevice == 0) { ///Steven MARK, tof no need + if (buffer_type == 0) + { + if (strlen(viewChannelData[0].getnetwork_buffer_id) >= 1) { + buffer_id = atoi(viewChannelData[0].getnetwork_buffer_id); + if (g_dual_sensor == 1/*strcmp(WeightFileModeName, "mod004") == 0*//*g_check_if_OK_thermal == 1 && g_IsPTZDevice == 1*/) + { + if (buffer_id == 0) { + buffer_id = 0; + } + else if (buffer_id == 1) { + buffer_id = 1; + } + else if (buffer_id == 2) { + buffer_id = 2; + } + else if (buffer_id == 3) { + buffer_id = 3; + } + } + else { + if (buffer_id == 0) { + buffer_id = 0; + } + else if (buffer_id == 1) { + buffer_id = 3; + } + else if (buffer_id == 2) { + buffer_id = 2; + } + else if (buffer_id == 3) { + buffer_id = 1; + } + } + } + else { + buffer_id = 0; + } + + query_desc.qid = IAV_DESC_CANVAS; //IAV_DESC_CANVAS + query_desc.arg.canvas.canvas_id = buffer_id; + //if (!non_block_read) { + //query_desc.arg.canvas.non_block_flag &= ~IAV_BUFCAP_NONBLOCK; + //} + //else { + query_desc.arg.canvas.non_block_flag |= IAV_BUFCAP_NONBLOCK; + //} + //int try_times = 0; + //while (live_mode_flag) + { + if (ioctl(fd_iav, IAV_IOC_QUERY_DESC, &query_desc) < 0) { + if (errno != EINTR) { + printf("\n-------------------------------IAV_IOC_QUERY_DESC:1-------------------------------\n"); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "IAV_IOC_QUERY_DESC:1"); + write_to_logs_html(temp_msg, "get network input", "ERROR", "Yes"); + } + + return -1; + } + } + data_cap = &query_desc.arg.canvas.yuv; + } + +#if 0 + if (last_dsp_pts == data_cap->dsp_pts) { + query_desc.arg.canvas.non_block_flag &= ~IAV_BUFCAP_NONBLOCK; //return next new frame + if (ioctl(fd_iav, IAV_IOC_QUERY_DESC, &query_desc) < 0) { + if (errno != EINTR && errno != EAGAIN) { + printf("\n-------------------------------IAV_IOC_QUERY_DESC:2-------------------------------\n"); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "IAV_IOC_QUERY_DESC:2"); + write_to_logs_html(temp_msg, "get network input", "ERROR", "Yes"); + } + + return -1; + } + } + data_cap = &query_desc.arg.canvas.yuv; + } +#endif + } + /*else if (buffer_type == 1) + { + query_desc.qid = IAV_DESC_PYRAMID; + query_desc.arg.pyramid.chan_id = 0; + if (!non_block_read) { + query_desc.arg.pyramid.non_block_flag &= ~IAV_BUFCAP_NONBLOCK; + } + else { + query_desc.arg.pyramid.non_block_flag |= IAV_BUFCAP_NONBLOCK; + } + + if (ioctl(fd_iav, IAV_IOC_QUERY_DESC, &query_desc) < 0) + { + if (errno != EINTR) { + printf("\n-------------------------------IAV_IOC_QUERY_DESC:3-------------------------------\n"); + return -1; + } + } + data_cap = &query_desc.arg.pyramid.layers[buffer_id]; + if (last_dsp_pts == data_cap->dsp_pts) + { + query_desc.arg.pyramid.non_block_flag &= ~IAV_BUFCAP_NONBLOCK; //return next new frame + if (ioctl(fd_iav, IAV_IOC_QUERY_DESC, &query_desc) < 0) { + if (errno != EINTR && errno != EAGAIN) { + printf("\n-------------------------------IAV_IOC_QUERY_DESC:4-------------------------------\n"); + return -1; + } + } + data_cap = &query_desc.arg.pyramid.layers[buffer_id]; + } + } + else + { + printf("Unknown buffer type, should be 0/1\n"); + return -1; + }*/ + + + if (data_cap == NULL || ((dsp_state != IAV_STATE_DECODING) && ((data_cap->y_addr_offset == 0) || (data_cap->uv_addr_offset == 0)))) + { + //printf("Data buffer [%d] address is NULL!\n", buf); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,Data address is NULL!", get_free_mem_data()); + write_to_logs_html(temp_msg, "get network input", "ERROR", "Yes"); + } + + return -1; + } + + //printf("\n----%d,%d\n", data_cap->width, data_cap->height); + + if (data_cap->width % 2 == 1) + { + printf("image width should be even!\n"); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "image width should be even!"); + write_to_logs_html(temp_msg, "get network input", "ERROR", "Yes"); + } + + return -1; + } + + if (data_cap->width == 0 || data_cap->height == 0) + { + printf("image width or height should be postive!\n"); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "image width or height should be postive!"); + write_to_logs_html(temp_msg, "get network input", "ERROR", "Yes"); + } + + return -1; + } + + unsigned int temp_pts = (unsigned int)data_cap->dsp_pts; + g_last_dsp_pts = temp_pts; + + //printf("\n-----pts:%u\n", g_last_dsp_pts); + + + } ///Steven MARK, tof no need + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get network input #2:%lf ms\n", dw_FPS_time_delta); + + //////////// + +#if 0 + if (g_IsToFDevice == 1) { + if (tof_shmid == -1) + { + //oO@ ID + tof_shmid = Initial_ShareMemory(tof_yuv_size, 555); + if (tof_shmid == -1) { + printf("\n------------------Create shared memory failed!\n"); + } + else { + // MO@ɰ + tof_yuv_arr = Correspond_Memory_YUV(tof_shmid); + if (tof_yuv_arr == (void *)-1) { + perror("Mapping shared memory failed!\n"); + } + } + } + + if (tof_shmid != -1) { + //Ū + //printf("\n-----------tof_yuv_arr->index:%d\n", tof_yuv_arr->index); + //Receive_Data_ShareMemory(tof_yuv_arr); + + /* + for (int i = 0; i < 20; i++) { + printf("# The index for reading shared memory is[%d]: %d,%d,%d\n", i, (uint8_t)tof_yuv_arr->yuv_data[i].y, (uint8_t)tof_yuv_arr->yuv_data[i].u, (uint8_t)tof_yuv_arr->yuv_data[i].v); + }*/ + + //int count_uv_index = 0; + for (int i = 0; i < TOF_WIDTH * TOF_HEIGHT; i++) { + int index_x = i % (TOF_WIDTH); + int index_y = i / (TOF_WIDTH); + + int r_data = 0; + if (index_x % 2 == 0 && index_y % 2 == 0) + { + r_data = (int)tof_yuv_arr->yuv_data[i].y + Table_fv1[(int)tof_yuv_arr->yuv_data[i].v]; + } + else { + int temp_i = (index_y - index_y % 2) * TOF_WIDTH + (index_x - index_x % 2); + r_data = (int)tof_yuv_arr->yuv_data[i].y + Table_fv1[(int)tof_yuv_arr->yuv_data[temp_i].v]; + } + + if (r_data < 0) + r_data = 0; + else if (r_data >= 256) + r_data = 255; + + //uint8_tof_yuv_arr[i] = (uint8_t)r_data; + uint8_tof_rgb_arr[i] = (uint8_t)r_data; + + if (index_x % 2 == 0 && index_y % 2 == 0) + { + //uint8_tof_yuv_arr[count_uv_index + offset_unit8_tof_yuv] = (uint8_t)tof_yuv_arr->yuv_data[i].u; + //uint8_tof_yuv_arr[count_uv_index + 1 + offset_unit8_tof_yuv] = (uint8_t)tof_yuv_arr->yuv_data[i].v; + + int g_data = (int)tof_yuv_arr->yuv_data[i].y - Table_fu1[(int)tof_yuv_arr->yuv_data[i].u] - Table_fv2[(int)tof_yuv_arr->yuv_data[i].v]; + int b_data = (int)tof_yuv_arr->yuv_data[i].y + Table_fu2[(int)tof_yuv_arr->yuv_data[i].u]; + + if (g_data < 0) + g_data = 0; + else if (g_data >= 256) + g_data = 255; + + if (b_data < 0) + b_data = 0; + else if (b_data >= 256) + b_data = 255; + + /* + if (index_x == 618 && index_y == 10) { + printf("\n-------color-----%d,%d,%d\n",r_data,g_data,b_data); + }*/ + + //uint8_tof_yuv_arr[count_uv_index + offset_unit8_tof_yuv] = (uint8_t)g_data; + //uint8_tof_yuv_arr[count_uv_index + 1 + offset_unit8_tof_yuv] = (uint8_t)b_data; + //count_uv_index += 2; + + + uint8_tof_rgb_arr[i + TOF_WIDTH * TOF_HEIGHT] = (uint8_t)g_data; + uint8_tof_rgb_arr[i + TOF_WIDTH * TOF_HEIGHT * 2] = (uint8_t)b_data; + } + else { + int temp_i = (index_y - index_y % 2) * TOF_WIDTH + (index_x - index_x % 2); + + int g_data = (int)tof_yuv_arr->yuv_data[i].y - Table_fu1[(int)tof_yuv_arr->yuv_data[temp_i].u] - Table_fv2[(int)tof_yuv_arr->yuv_data[temp_i].v]; + int b_data = (int)tof_yuv_arr->yuv_data[i].y + Table_fu2[(int)tof_yuv_arr->yuv_data[temp_i].u]; + + if (g_data < 0) + g_data = 0; + else if (g_data >= 256) + g_data = 255; + + if (b_data < 0) + b_data = 0; + else if (b_data >= 256) + b_data = 255; + + uint8_tof_rgb_arr[i + TOF_WIDTH * TOF_HEIGHT] = (uint8_t)g_data; + uint8_tof_rgb_arr[i + TOF_WIDTH * TOF_HEIGHT * 2] = (uint8_t)b_data; + } + + + } + + //tof_YUV = uint8_tof_yuv_arr; + tof_YUV = uint8_tof_rgb_arr; + + ///YUVVshare memory + //tof_YUV = uint8_tof_yuv_arr; + + + //char YUV_out[512] = { 0 }; + //sprintf(YUV_out, "/emmc/plugin/Aida_data/storage/result_%d.yuv", count_yuv); + //sprintf(YUV_out, "/emmc/plugin/Aida_data/storage/result_%d.rgb", count_yuv); + //count_yuv++; + //if (count_yuv >= 10) { + //count_yuv = 0; + //} + //saveRawYUV(YUV_out, tof_YUV_width, tof_YUV_height, tof_YUV, tof_YUV_width, (tof_YUV_width + 1) / 2); + //savePPM(YUV_out, tof_YUV_width, tof_YUV_height, uint8_tof_rgb_arr, tof_YUV_width*3); + } + } +#endif + + ////////////////////////////////////////////////////////////////////////////////// + + /*if (g_IsToFDevice == 1 && tof_shmid != -1 && tof_YUV != NULL) { + g_ori_yuv_width = TOF_WIDTH; + g_ori_yuv_height = TOF_HEIGHT; + g_ori_half_yuv_width = TOF_WIDTH / 2; + g_ori_half_yuv_height = TOF_HEIGHT / 2; + } + else*/ + { + g_ori_yuv_width = (int)data_cap->width; + g_ori_yuv_height = (int)data_cap->height; + g_ori_half_yuv_width = (int)data_cap->width / 2; + g_ori_half_yuv_height = (int)data_cap->height / 2; + } + + //printf("\n-----------g_ori_yuv_width:%d,g_ori_yuv_height:%d\n", g_ori_yuv_width, g_ori_yuv_height); + + y.shape.p = 1; + y.shape.d = 1; + y.shape.h = g_ori_yuv_height; + y.shape.w = g_ori_yuv_width; + y.data_format.sign = 0; // yuv2rgb only support Fix8 as input/output + y.data_format.datasize = 0; + y.data_format.exp_offset = 0; + y.data_format.exp_bits = 0; + + /*if (g_IsToFDevice == 1 && tof_shmid != -1 && tof_YUV != NULL) + { + y.data_addr = tof_YUV; + y.pitch = tof_YUV_pitch; + } + else*/ + { + y.data_addr = dsp_phy_addr + data_cap->y_addr_offset; + y.pitch = data_cap->pitch; + } + + y.color_space = CS_NV12; + + y.roi.width = g_ori_yuv_width; + y.roi.height = g_ori_yuv_height; + y.roi.xoffset = 0; + y.roi.yoffset = 0; + + y_p = &y; + /////////////////////////////HU20211007s[ + + uv.shape.p = 1; + uv.shape.d = 2; + uv.shape.h = g_ori_yuv_height / 2; + uv.shape.w = g_ori_yuv_width / 2; + uv.data_format.sign = 0; + uv.data_format.datasize = 0; + uv.data_format.exp_offset = 0; + uv.data_format.exp_bits = 0; + + /*if (g_IsToFDevice == 1 && tof_shmid != -1 && tof_YUV != NULL) + { + uv.data_addr = tof_YUV + offset_unit8_tof_yuv; + uv.pitch = tof_YUV_pitch; + } + else*/ + { + uv.data_addr = dsp_phy_addr + data_cap->uv_addr_offset; + uv.pitch = data_cap->pitch; + } + + uv.color_space = CS_NV12; + + uv.roi.width = g_ori_yuv_width / 2; + uv.roi.height = g_ori_yuv_height / 2; + uv.roi.xoffset = 0 / 2; // YUV 422 format, half UV sizes + uv.roi.yoffset = 0 / 2; + + uv_p = &uv; + + //printf("\n---rgb_type:%d\n",rgb_type); + + //printf("\n-------data_cap->pitch:%d\n", data_cap->pitch); + + ////////////////////////////////////HU20211007s[ + + //uv_p->roi.xoffset = 960; // YUV 422 format, half UV sizes + //uv_p->roi.yoffset = 540; + //uv_p->roi.width = 640; + //uv_p->roi.height = 320; + /////////////////////////////////// + + //uint32_t tof_YUV_p = 1; + //uint32_t tof_YUV_d = 3; + //printf("\ng_ori_yuv_width_height:%d,%d\n",g_ori_yuv_width, g_ori_yuv_height); + if (vproc_init_flag) + { + /*printf("===================================================\n"); + printf("Neural Network data pre-processing init...\n" + "YUV data size = %d x %d, pitch = %d\n", + data_cap->width, data_cap->height, data_cap->pitch);*/ + + rgb.shape.p = 1; + rgb.shape.d = 3; + rgb.shape.h = g_ori_yuv_height; + rgb.shape.w = g_ori_yuv_width; + rgb.data_format.sign = 0; + rgb.data_format.datasize = 0; + rgb.data_format.exp_offset = 0; + rgb.data_format.exp_bits = 0; + rgb.pitch = ROUND_UP(rgb.shape.w * (1 << rgb.data_format.datasize), 32); + + rgb_p = &rgb; + + if (rgb_type) { + rgb.color_space = CS_BGR; + } + else { + rgb.color_space = CS_RGB; + } + /*printf("RGB data dimension: %d, %d, %d, %d, pitch: %d, data_format: " + "%d, %d, %d, %d, color space: %s\n", + rgb.shape.p, + rgb.shape.d, + rgb.shape.h, + rgb.shape.w, + rgb.pitch, + rgb.data_format.sign, + rgb.data_format.datasize, + rgb.data_format.exp_offset, + rgb.data_format.exp_bits, + rgb.color_space == CS_BGR ? "BGR" : "RGB");*/ + yuv2rgb_mat.yc = 1; + yuv2rgb_mat.rv = 1.402; + yuv2rgb_mat.gu = 0.344136; + yuv2rgb_mat.gv = 0.714136; + yuv2rgb_mat.bu = 1.772; + yuv2rgb_mat.yb = 0; + + yuv2rgb_mat_p = &yuv2rgb_mat; + yuv2rgb_out_mem.size = rgb.shape.p * rgb.shape.d * rgb.shape.h * rgb.pitch; + if (cavalry_mem_alloc(&yuv2rgb_out_mem.size, &yuv2rgb_out_mem.phys, &yuv2rgb_out_mem.virt, 1,1) < 0) + { + printf("cavalry_mem_alloc err #2\n"); + return -1; + } + + rgb.data_addr = yuv2rgb_out_mem.phys; + downsized_cropped_mem.size = yuv2rgb_out_mem.size; + if (cavalry_mem_alloc(&downsized_cropped_mem.size, &downsized_cropped_mem.phys, &downsized_cropped_mem.virt, 1, 1) < 0) + { + printf("[get network input]cavalry_mem_alloc err downsized_cropped_mem\n"); + return -1; + } + tof_img_mem.size = yuv2rgb_out_mem.size; + if (cavalry_mem_alloc(&tof_img_mem.size, &tof_img_mem.phys, &tof_img_mem.virt, 1, 1) < 0) + { + printf("[get network input]cavalry_mem_alloc err tof_img_mem\n"); + return -1; + } + snap_hd_mem.size = yuv2rgb_out_mem.size; + if (cavalry_mem_alloc(&snap_hd_mem.size, &snap_hd_mem.phys, &snap_hd_mem.virt, 1, 1) < 0) + { + printf("[get network input]cavalry_mem_alloc err snap_hd_mem\n"); + return -1; + } + + barcode_img_mem.size = yuv2rgb_out_mem.size; + if (cavalry_mem_alloc(&barcode_img_mem.size, &barcode_img_mem.phys, &barcode_img_mem.virt, 1, 1) < 0) + { + printf("[get network input]cavalry_mem_alloc err barcode_img_mem\n"); + return -1; + } +#if 0 + rgb_2K_mem.size = yuv2rgb_out_mem.size; + if (cavalry_mem_alloc(&rgb_2K_mem.size, &rgb_2K_mem.phys, &rgb_2K_mem.virt, 1, 1) < 0) + { + printf("[get network input]cavalry_mem_alloc err rgb_2K_mem\n"); + return -1; + } +#endif +#if 0 + if (g_IsToFDevice == 1 && tof_shmid != -1 && tof_YUV != NULL) { + //load_no_padding_mem(tof_YUV, tof_img_mem.virt, y.shape.w, y.pitch, y.shape.h * 3 / 2); + //tof_img_mem.size = tof_YUV_p * tof_YUV_d * tof_YUV_height * tof_YUV_pitch / 2; + tof_img_mem.size = tof_YUV_p * tof_YUV_d * tof_YUV_height * tof_YUV_pitch; + yuv2rgb_out_mem.size = tof_img_mem.size; + downsized_cropped_mem.size = tof_img_mem.size; + snap_hd_mem.size = tof_img_mem.size; + + rgb.data_addr = tof_img_mem.phys; + rgb.shape.p = 1; + rgb.shape.d = 3; + rgb.shape.h = tof_YUV_height; + rgb.shape.w = tof_YUV_width; + rgb.data_format.sign = 0; + rgb.data_format.datasize = 0; + rgb.data_format.exp_offset = 0; + rgb.data_format.exp_bits = 0; + rgb.pitch = ROUND_UP(rgb.shape.w * (1 << rgb.data_format.datasize), 32); + + rgb_p = &rgb; + + if (rgb_type) { + rgb.color_space = CS_BGR; + } + else { + rgb.color_space = CS_RGB; + } + + y.shape.h = tof_YUV_height; + y.shape.w = tof_YUV_width; + y.data_addr = tof_YUV; + y.pitch = tof_YUV_pitch;//tof_YUV_pitch + y.roi.width = tof_YUV_width; + y.roi.height = tof_YUV_height; + + uv.shape.h = tof_YUV_height / 2; + uv.shape.w = tof_YUV_width / 2; + uv.data_addr = tof_YUV + offset_unit8_tof_yuv; + uv.pitch = tof_YUV_pitch;//tof_YUV_pitch + uv.roi.width = tof_YUV_width / 2; + uv.roi.height = tof_YUV_height / 2; + + } +#endif + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get network input #3:%lf ms\n", dw_FPS_time_delta); + + /*if (g_IsToFDevice == 1 && tof_shmid != -1 && tof_YUV != NULL) { +#if 1 + + //load_no_padding_mem(tof_YUV, tof_img_mem.virt, tof_YUV_width, tof_YUV_pitch, tof_YUV_height * 3 / 2); + //load_no_padding_mem(tof_YUV, yuv2rgb_out_mem.virt, tof_YUV_width, tof_YUV_pitch, tof_YUV_height * 3 / 2); + //load_no_padding_mem(tof_YUV, downsized_cropped_mem.virt, tof_YUV_width, tof_YUV_pitch, tof_YUV_height * 3 / 2); + //load_no_padding_mem(tof_YUV, snap_hd_mem.virt, tof_YUV_width, tof_YUV_pitch, tof_YUV_height * 3 / 2); + + load_no_padding_mem(tof_YUV, tof_img_mem.virt, tof_YUV_width*3, tof_YUV_pitch*3, tof_YUV_height); + load_no_padding_mem(tof_YUV, yuv2rgb_out_mem.virt, tof_YUV_width*3, tof_YUV_pitch*3, tof_YUV_height); + load_no_padding_mem(tof_YUV, downsized_cropped_mem.virt, tof_YUV_width*3, tof_YUV_pitch*3, tof_YUV_height); + load_no_padding_mem(tof_YUV, snap_hd_mem.virt, tof_YUV_width*3, tof_YUV_pitch*3, tof_YUV_height); + + g_snap_hd_shape_w_for_snaphd = tof_YUV_width; + g_snap_hd_pitch_for_snaphd = tof_YUV_pitch; + g_snap_hd_shape_h_for_snaphd = tof_YUV_height; + +#if 0 + printf("\n------/emmc/plugin/Aida_data/storage/tof_\n"); + char img_name[512] = { 0 }; + sprintf(img_name, "/emmc/plugin/Aida_data/storage/tof_1w_%d_h_%d.bin", tof_YUV_width, tof_YUV_height); + store_bin(img_name, tof_img_mem.size, tof_img_mem.virt); + printf("store_bin(...) for output_name finished.\n"); +#endif +#endif + } + else */{ + //printf("\n get_network_input start-----------1\n"); + vproc_yuv2rgb_420(&y, &uv, &rgb, &yuv2rgb_mat); + //printf("\n get_network_input start-----------2\n"); + } + + int yu2rg_result = vproc_yuv2rgb_420(&y, &uv, &rgb, &yuv2rgb_mat); + //printf("\n--------snap hd:----------3--------2\n"); + if (yu2rg_result < 0) + { + printf("[get network input] vproc_yuv2rgb_420(...) failure!\n"); + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "vproc_yuv2rgb_420(...) failure!"); + write_to_logs_html(temp_msg, "get network input", "ERROR", "Yes"); + } + + return -1; + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get network input #4:%lf ms\n", dw_FPS_time_delta); + +#if 0 + { + printf("\n------/emmc/plugin/Aida_data/storage/rgb_\n"); + char img_name[512] = { 0 }; + sprintf(img_name, "/emmc/plugin/Aida_data/storage/tof_2w_%d_h_%d.bin", tof_YUV_width, tof_YUV_height); + store_bin(img_name, tof_img_mem.size, tof_img_mem.virt); + printf("store_bin(...) for output_name finished.\n"); + } +#endif + +#if 0 + if (g_ori_yuv_width > SCALE_BOUNDING_BOX_WIDTH || g_ori_yuv_height > SCALE_BOUNDING_BOX_HEIGHT) { + + rgb_2K.shape.p = 1; + rgb_2K.shape.d = 3; + + rgb_2K.shape.h = (int)SCALE_BOUNDING_BOX_HEIGHT; + rgb_2K.shape.w = (int)SCALE_BOUNDING_BOX_WIDTH; + + rgb_2K.data_format.sign = rgb.data_format.sign; + rgb_2K.data_format.datasize = rgb.data_format.datasize; + rgb_2K.data_format.exp_offset = rgb.data_format.exp_offset; + rgb_2K.data_format.exp_bits = rgb.data_format.exp_bits; + rgb_2K.pitch = ROUND_UP(rgb_2K.shape.w * (1 << rgb_2K.data_format.datasize), 32); + rgb_2K.color_space = rgb.color_space; + + rgb_2K.data_addr = rgb_2K_mem.phys; + vproc_memcpy(rgb_2K.data_addr, rgb.data_addr, rgb_2K_mem.size); + rgb_2K_mem.size = rgb_2K.shape.p * rgb_2K.shape.d * rgb_2K.shape.h * rgb_2K.pitch; + vproc_resize(&rgb, &rgb_2K); + } +#endif + //printf("\n---------rgb.shape.h:%d\n", (int)rgb.shape.h); + //printf("\n---------rgb.shape.w:%d\n", (int)rgb.shape.w); + + if (vproc_init_flag) + { +#if 0 + if (g_ori_yuv_width > SCALE_BOUNDING_BOX_WIDTH || g_ori_yuv_height > SCALE_BOUNDING_BOX_HEIGHT) { + rsz_in.shape.p = rgb_2K.shape.p; + rsz_in.shape.d = rgb_2K.shape.d; + rsz_in.shape.h = rgb_2K.shape.h; + rsz_in.shape.w = rgb_2K.shape.w; + rsz_in.data_format.sign = rgb_2K.data_format.sign; // Resize only support Fix8 as input/output + rsz_in.data_format.datasize = rgb_2K.data_format.datasize; + rsz_in.data_format.exp_offset = rgb_2K.data_format.exp_offset; + rsz_in.data_format.exp_bits = rgb_2K.data_format.exp_bits; + rsz_in.pitch = rgb_2K.pitch; + rsz_in.data_addr = rgb_2K.data_addr; + } + else +#endif + { + rsz_in.shape.p = rgb.shape.p; + rsz_in.shape.d = rgb.shape.d; + rsz_in.shape.h = rgb.shape.h; + rsz_in.shape.w = rgb.shape.w; + rsz_in.data_format.sign = rgb.data_format.sign; // Resize only support Fix8 as input/output + rsz_in.data_format.datasize = rgb.data_format.datasize; + rsz_in.data_format.exp_offset = rgb.data_format.exp_offset; + rsz_in.data_format.exp_bits = rgb.data_format.exp_bits; + rsz_in.pitch = rgb.pitch; + rsz_in.data_addr = rgb.data_addr; + } + + rsz_in.color_space = CS_RGB; + + rsz_out.shape.p = net_in->in_desc[0].dim.plane; + rsz_out.shape.d = net_in->in_desc[0].dim.depth; + rsz_out.shape.h = net_in->in_desc[0].dim.height; + rsz_out.shape.w = net_in->in_desc[0].dim.width; + + rsz_out.data_format.sign = rsz_in.data_format.sign; + rsz_out.data_format.datasize = rsz_in.data_format.datasize; + rsz_out.data_format.exp_offset = rsz_in.data_format.exp_offset; + rsz_out.data_format.exp_bits = rsz_in.data_format.exp_bits; + rsz_out.pitch = ROUND_UP(rsz_out.shape.w * (1 << rsz_out.data_format.datasize), 32); + rsz_out.color_space = CS_RGB; + /*printf("resize output data dimension: %d, %d, %d, %d, pitch: %d, data_format: " + "%d, %d, %d, %d\n", + rsz_out.shape.p, + rsz_out.shape.d, + rsz_out.shape.h, + rsz_out.shape.w, + rsz_out.pitch, + rsz_out.data_format.sign, + rsz_out.data_format.datasize, + rsz_out.data_format.exp_offset, + rsz_out.data_format.exp_bits);*/ + //if (submean_flag == 0 && + //net_in->in_desc[0].data_fmt.sign == 0 && + //net_in->in_desc[0].data_fmt.size == 0 && + //net_in->in_desc[0].data_fmt.expbits == 0 && + //fabs((1 << net_in->in_desc[0].data_fmt.expoffset) * scale_factor - 1) <= FIX8_MIN_ACCURACY && + //rsz_out.pitch == net_in->in_desc[0].dim.pitch) + //{ + yuv2rgb_resize_only_flag = 1; + //} + + + //if (yuv2rgb_resize_only_flag) //only first time + //{ + rsz_out.data_addr = net_in->in_desc[0].addr; + printf("===================================================aadr = 0x%x\n", net_in->in_desc[0].addr); + //printf("\n----------rsz_out.size:%d\n", rsz_out.shape.p * rsz_out.shape.d * rsz_out.shape.h * rsz_out.pitch); + //} + //else + //{ + //rsz_out_mem.size = rsz_out.shape.p * rsz_out.shape.d * rsz_out.shape.h * rsz_out.pitch; + //if (cavalry_mem_alloc(&rsz_out_mem.size, &rsz_out_mem.phys, &rsz_out_mem.virt, 1, 1) < 0) { + //printf("cavalry_mem_alloc rsz_out_mem err\n"); + //return -1; + //} + //rsz_out.data_addr = rsz_out_mem.phys; + //} + } + + +#if 0 + if (count_frame <= 10) { + printf("\n------/emmc/plugin/Aida_data/storage/rgb_\n"); + { + char img_name[512] = { 0 }; + sprintf(img_name, "/emmc/plugin/Aida_data/storage/hello_%d.bin", count_frame); + store_bin(img_name, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt); + printf("store_bin(...) for output_name finished.\n"); + } + count_frame++; + } + else { + count_frame = 0; + } +#endif + +#if 0 + printf("\n------/emmc/plugin/Aida_data/storage/rgb_\n"); + char img_name[512] = { 0 }; + sprintf(img_name, "/emmc/plugin/Aida_data/storage/tof_3-3w_%d_h_%d.bin", rsz_out.shape.h, rsz_out.shape.w); + store_bin(img_name, net_in->in_desc[0].size, net_in->in_desc[0].virt); + printf("store_bin(...) for output_name finished.\n"); +#endif + //give data to each net + if (strlen(viewChannelData[0].getnetwork_buffer_id) >= 1) { + int buffer_id = atoi(viewChannelData[0].getnetwork_buffer_id); + for (int m = 0 ; m < pctrl->net_num ; m++) + { + if (vproc_init_flag || + (viewChannelData[0].enable_traffic && ( + (m == iFeature_traf_det_layer_index && strcmp(WeightFileModeName, "mod004") != 0) || + (m == iFeature_traf_det_layer_index && strcmp(WeightFileModeName, "mod004") == 0 && -1 == iFeature_traf_det_layer_index_2) || + (m == iFeature_traf_det_layer_index && strcmp(WeightFileModeName, "mod004") == 0 && (buffer_id == 2 || buffer_id == 3)) || + (m == iFeature_traf_det_layer_index_2 && strcmp(WeightFileModeName, "mod004") == 0 && (buffer_id == 0 || buffer_id == 1)) || + m == iFeature_access_ctrl_det_layer_index[0] || + m == iFeature_access_ctrl_det_layer_index[1] || + m == iFeature_access_ctrl_det_layer_index[2] || + m == iFeature_access_ctrl_det_layer_index[3] || + m == iFeature_aifire_det_layer_index || + m == iFeature_aero_det_layer_index || + (m == iFeature_mask_layer_index && strcmp(WeightFileModeName, "mod003") != 0) || + m == iFeature_safety_layer_index || + m == iFeature_rail_layer_index || + m == iFeature_sports_layer_index || + m == iFeature_animal_layer_index || + m == iFeature_tof_det_layer_index || + m == iFeature_garbage_layer_index || + m == iFeature_production_layer_index || + m == iFeature_ship_layer_index) && strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0) || + (viewChannelData[0].enable_anpr && m == iFeature_lpr_layer_index) + ) { + + net_in = &pctrl->net_pair[m].net_in; + rsz_out.data_addr = net_in->in_desc[0].addr; + + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + //printf("\n get_network_input start-----------3\n"); + vproc_resize(&rsz_in, &rsz_out); + //printf("\n get_network_input start-----------4\n"); + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----vproc_resize:%lf ms\n", dw_FPS_time_delta); + } + } + } +#if 0 + printf("\n------/emmc/plugin/Aida_data/storage/rgb_\n"); + char img_name[512] = { 0 }; + sprintf(img_name, "/emmc/plugin/Aida_data/storage/tof_3-2w_%d_h_%d.bin", rsz_out.shape.h, rsz_out.shape.w); + store_bin(img_name, net_in->in_desc[0].size, net_in->in_desc[0].virt); + printf("store_bin(...) for output_name finished.\n"); +#endif + + //printf("\n[get network input] 8 yuv2rgb_resize_only_flag:%d\n", yuv2rgb_resize_only_flag); +#if 0 + if (yuv2rgb_resize_only_flag == 0) + { + if (vproc_init_flag) + { + dtcvt_in.shape.p = rsz_out.shape.p; + dtcvt_in.shape.d = rsz_out.shape.d; + dtcvt_in.shape.h = rsz_out.shape.h; + dtcvt_in.shape.w = rsz_out.shape.w; + dtcvt_in.data_addr = rsz_out.data_addr; + dtcvt_in.data_format.sign = rsz_out.data_format.sign; + dtcvt_in.data_format.datasize = rsz_out.data_format.datasize; + dtcvt_in.data_format.exp_offset = rsz_out.data_format.exp_offset; + dtcvt_in.data_format.exp_bits = rsz_out.data_format.exp_bits; + dtcvt_in.pitch = rsz_out.pitch; + + dtcvt_out.shape.p = dtcvt_in.shape.p; + dtcvt_out.shape.d = dtcvt_in.shape.d; + dtcvt_out.shape.h = dtcvt_in.shape.h; + dtcvt_out.shape.w = dtcvt_in.shape.w; + dtcvt_out.data_format.sign = 1; // Convert fix8 to fp16 + dtcvt_out.data_format.datasize = 1; + dtcvt_out.data_format.exp_offset = 0; + dtcvt_out.data_format.exp_bits = 4; + dtcvt_out.pitch = ROUND_UP((dtcvt_out.shape.w * + (1 << dtcvt_out.data_format.datasize)), 32); + /*printf("scale1 output data dimension: %d, %d, %d, %d, pitch: %d, data_format: " + "%d, %d, %d, %d\n", + dtcvt_out.shape.p, + dtcvt_out.shape.d, + dtcvt_out.shape.h, + dtcvt_out.shape.w, + dtcvt_out.pitch, + dtcvt_out.data_format.sign, + dtcvt_out.data_format.datasize, + dtcvt_out.data_format.exp_offset, + dtcvt_out.data_format.exp_bits);*/ + dtcvt_out_mem.size = dtcvt_out.shape.p * dtcvt_out.shape.d * dtcvt_out.shape.h * dtcvt_out.pitch; + if (cavalry_mem_alloc(&dtcvt_out_mem.size, &dtcvt_out_mem.phys, + &dtcvt_out_mem.virt, 1,1) < 0) { + printf("cavalry_mem_alloc dtcvt_out_mem err\n"); + return -1; + } + dtcvt_out.data_addr = dtcvt_out_mem.phys; + } + + vproc_dtcvt(&dtcvt_in, &dtcvt_out); // Convert fix8 to fp16 for submean + + ////////////////////////////////////////////////////////////////////////////////// + if (vproc_init_flag) { + submean_in.shape.p = dtcvt_out.shape.p; + submean_in.shape.d = dtcvt_out.shape.d; + submean_in.shape.h = dtcvt_out.shape.h; + submean_in.shape.w = dtcvt_out.shape.w; + submean_in.data_format.sign = dtcvt_out.data_format.sign; + submean_in.data_format.datasize = dtcvt_out.data_format.datasize; + submean_in.data_format.exp_offset = dtcvt_out.data_format.exp_offset; + submean_in.data_format.exp_bits = dtcvt_out.data_format.exp_bits; + submean_in.pitch = dtcvt_out.pitch; + submean_in.data_addr = dtcvt_out.data_addr; + + submean_mean.shape.p = submean_in.shape.p; + submean_mean.shape.d = submean_in.shape.d; + submean_mean.shape.h = submean_in.shape.h; + submean_mean.shape.w = submean_in.shape.w; + submean_mean.data_format.sign = 1; + submean_mean.data_format.datasize = 1; + submean_mean.data_format.exp_offset = 0; + submean_mean.data_format.exp_bits = 4; + submean_mean.pitch = submean_in.pitch; + submean_mean_mem.size = submean_mean.shape.p * submean_mean.shape.d * submean_mean.shape.h * submean_mean.pitch; + /*printf("submean mean data dimension: %d, %d, %d, %d, pitch: %d, data_format: " + "%d, %d, %d, %d\n", + submean_mean.shape.p, + submean_mean.shape.d, + submean_mean.shape.h, + submean_mean.shape.w, + submean_mean.pitch, + submean_mean.data_format.sign, + submean_mean.data_format.datasize, + submean_mean.data_format.exp_offset, + submean_mean.data_format.exp_bits);*/ + + if (cavalry_mem_alloc(&submean_mean_mem.size, + &submean_mean_mem.phys, &submean_mean_mem.virt, 1,1) < 0) { + printf("cavalry_mem_alloc err #3\n"); + return -1; + } + submean_mean.data_addr = submean_mean_mem.phys; + if (strlen(mean_name) != 0) { + if (load_mean_binary(mean_name, submean_mean_mem.virt, + &submean_mean, &submean_mean_mem.size) < 0) { + printf("load submean_mean input fails!\n"); + return -1; + } + } + submean_out.shape.p = submean_in.shape.p; + submean_out.shape.d = submean_in.shape.d; + submean_out.shape.h = submean_in.shape.h; + submean_out.shape.w = submean_in.shape.w; + submean_out.data_format.sign = submean_in.data_format.sign; + submean_out.data_format.datasize = submean_in.data_format.datasize; + submean_out.data_format.exp_offset = submean_in.data_format.exp_offset; + submean_out.data_format.exp_bits = submean_in.data_format.exp_bits; + submean_out.pitch = submean_in.pitch; + /*printf("submean output data dimension: %d, %d, %d, %d, pitch: %d, data_format: " + "%d, %d, %d, %d\n", + submean_out.shape.p, + submean_out.shape.d, + submean_out.shape.h, + submean_out.shape.w, + submean_out.pitch, + submean_out.data_format.sign, + submean_out.data_format.datasize, + submean_out.data_format.exp_offset, + submean_out.data_format.exp_bits);*/ + + submean_out_mem.size = submean_out.shape.p * submean_out.shape.d * submean_out.shape.h * submean_out.pitch; + if (cavalry_mem_alloc(&submean_out_mem.size, + &submean_out_mem.phys, &submean_out_mem.virt, 1,1) < 0) { + printf("cavalry_mem_alloc err #4\n"); + return -1; + } + submean_out.data_addr = submean_out_mem.phys; + } + vproc_submean(&submean_in, &submean_mean, &submean_out); + + + ////////////////////////////////////////////////////////////////////////////////// + if (vproc_init_flag) + { + scale_in.shape.p = submean_out.shape.p; + scale_in.shape.d = submean_out.shape.d; + scale_in.shape.h = submean_out.shape.h; + scale_in.shape.w = submean_out.shape.w; + scale_in.data_format.sign = submean_out.data_format.sign; + scale_in.data_format.datasize = submean_out.data_format.datasize; + scale_in.data_format.exp_offset = submean_out.data_format.exp_offset; + scale_in.data_format.exp_bits = submean_out.data_format.exp_bits; + scale_in.pitch = submean_out.pitch; + scale_in.data_addr = submean_out.data_addr; + + scale_out.shape.p = scale_in.shape.p; + scale_out.shape.d = scale_in.shape.d; + scale_out.shape.h = scale_in.shape.h; + scale_out.shape.w = scale_in.shape.w; + scale_out.data_format.sign = net_in->in_desc[0].data_fmt.sign; + scale_out.data_format.datasize = net_in->in_desc[0].data_fmt.size; + scale_out.data_format.exp_offset = net_in->in_desc[0].data_fmt.expoffset; + scale_out.data_format.exp_bits = net_in->in_desc[0].data_fmt.expbits; + scale_out.pitch = ROUND_UP(scale_out.shape.w * + (1 << scale_out.data_format.datasize), 32); + scale_out.data_addr = net_in->in_desc[0].addr; + /*printf("scale output data dimension: %d, %d, %d, %d, pitch: %d, data_format: " + "%d, %d, %d, %d\n", + scale_out.shape.p, + scale_out.shape.d, + scale_out.shape.h, + scale_out.shape.w, + scale_out.pitch, + scale_out.data_format.sign, + scale_out.data_format.datasize, + scale_out.data_format.exp_offset, + scale_out.data_format.exp_bits);*/ + if (scale_out.pitch != net_in->in_desc[0].dim.pitch) { + printf("Error: Pitch(%d) != %d, please check cavalry binary input dim!\n", + scale_out.pitch, net_in->in_desc[0].dim.pitch); + return -1; + } + + printf("===================================================\n"); + } + vproc_scale_ext(&scale_in, &scale_out, scale_factor); + + } +#endif + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----get network input #5:%lf ms\n", dw_FPS_time_delta); + + vproc_init_flag = 0; + //printf("\n--------------end get network input\n"); + return 0; +} + +///OSD SERVER +#if 1 +int run_amba_yolov3(dproc_run_param_t *run_yolov3_param, dproc_yolov3_output_result_t *amba_yolov3_result, int dproc_idx,float nms_threshold) +{ + uint32_t ssd_det_num; + int rval = 0; + dproc_result_t yolov3_result; + //arg.yolov3_result + yolov3_result.arg.yolov3_result = amba_yolov3_result; + ssd_det_num = dproc_run(run_yolov3_param, &yolov3_result, dproc_idx, nms_threshold); + + if (ssd_det_num < 0) { + printf("dproc run fail!\n"); + rval = -1; + } + else { + rval = ssd_det_num; + } + + return rval; +} + +int init_amba_yolov3(dproc_yolov3_output_result_t **amba_yolov3_result, uint32_t net_idx, uint32_t total_cls, float *panchors, int tiny_enable) +{ + int rval = 0, max_objects = 0; + uint32_t size_of_yolov3_result = 0; + dproc_config_t yolov3_config; + dproc_yolov3_output_config_t *amba_yolov3_config; + + memset(&yolov3_config, 0, sizeof(dproc_config_t)); + yolov3_config.layer_type = DPROC_YOLOV3_OUT; + amba_yolov3_config = &(yolov3_config.arg.yolov3_config); + amba_yolov3_config->img_width = g_img_width; + amba_yolov3_config->img_height = g_img_height; + amba_yolov3_config->num_classes = total_cls; + amba_yolov3_config->conf_threshold = g_threshold; + amba_yolov3_config->nms_threshold = 0.3; + amba_yolov3_config->anchors = panchors; + amba_yolov3_config->tiny_enable = tiny_enable; + amba_yolov3_config->unnormalized = 0; + + max_objects = dproc_init(&yolov3_config, net_idx); + + if (max_objects < 0) { + printf("dproc_init first error ! \n"); + rval = -1; + return rval; + } + //printf("dproc_init first success ! max_objects:%d \n", max_objects); + + size_of_yolov3_result = max_objects * sizeof(dproc_yolov3_output_result_t); + + *amba_yolov3_result = (dproc_yolov3_output_result_t *)malloc(size_of_yolov3_result); + if (*amba_yolov3_result == NULL) { + printf("failed to malloc amba_yolov3_result\n"); + rval = -1; + return rval; + } + memset((void*)(*amba_yolov3_result), 0, size_of_yolov3_result); + + + return rval; +} + +void deinit_amba_yolov3(dproc_yolov3_output_result_t *amba_yolov3_result, int dproc_ctx_id) +{ + if (amba_yolov3_result != NULL) { + free(amba_yolov3_result); + amba_yolov3_result = NULL; + } + + dproc_deinit(DPROC_YOLOV3_OUT, dproc_ctx_id); +} + +int init_anchor_file(char *anchor_file, float *anchor, uint32_t tiny_enable) +{ + int rval = 0; + FILE *file = NULL; + char temp_ch; + char temp_str[MAX_FLOAT_VALUE_NUM]; + uint32_t i = 0, n = 0, not_file_end = 1; + uint32_t anchor_num = tiny_enable ? TINY_YOLOV3_ANCHOR_NUM : YOLOV3_ANCHOR_NUM; + + file = fopen(anchor_file, "r"); + if (file) { + //printf("Reload anchor value with anchor file!\n"); + //printf("\nanchor_num:%d", anchor_num); + memset(anchor, 0, sizeof(float) * anchor_num); + while (not_file_end) { + temp_ch = fgetc(file); + if (temp_ch == ',' || feof(file)) { + //printf("\ntemp_ch:%c",temp_ch); + if (i > 0 && n < anchor_num) { + temp_str[i++] = '\0'; + //printf("\nn:%d temp_str:%s",n,temp_str); + anchor[n] = atof(temp_str); + memset(temp_str, 0, MAX_FLOAT_VALUE_NUM); + i = 0; + n++; + + if (n > anchor_num) { + printf("The anchor num > %d which should be wrong!\n", YOLOV3_ANCHOR_NUM); + not_file_end = 1; + break; + } + + if (feof(file)) { + not_file_end = 1; + break; + } + } + else { + printf("Skip invalid digital!\n"); + } + } + else { + if (i < MAX_FLOAT_VALUE_NUM) { + temp_str[i++] = temp_ch; + } + else { + printf("The valid float value > %d which is not supported!\n", MAX_FLOAT_VALUE_NUM); + not_file_end = 1; + break; + } + } + } + //printf("[test_nnctrl_live.c]n:%d\n",n); + if (n == anchor_num) { + //printf("Anchor Value is: "); + for (i = 0; i < (n - 1); i++) { + //printf("%f, ", anchor[i]); + } + //printf("%f!\n", anchor[n - 1]); + + } + else { + printf("Fail to init anchor value!\n"); + rval = -1; + } + + fclose(file); + } + else { + printf("Open anchor file fail, use default VOC! \n"); + rval = -1; + printf("-----------------------error rval: %d-----------------------\n", rval); + + stop_test_nn_cavalry("Open anchor file fail, use default VOC!"); + //stop_server(); + + //exit(EXIT_FAILURE); + } + + return rval; +} +#endif + +//smartfb_box_t fb_box; +//smartfb_textbox_t fb_textbox; + +/*static int smartfb_draw_rectangle(int x1, int y1, int x2, int y2, int thickness, int color) +{ + smartfb_obj_t *fb_obj; + fb_obj = &fb_box.obj; + if (x2 > x1) { + fb_box.width = x2 - x1; + fb_obj->offset_x = x1; + } + else { + fb_box.width = x1 - x2; + fb_obj->offset_x = x2; + } + if (y2 > y1) { + fb_box.height = y2 - y1; + fb_obj->offset_y = y1; + } + else { + fb_box.height = y1 - y2; + fb_obj->offset_y = y2; + } + fb_box.line_thickness = thickness; + fb_obj->color = color; + smartfb_draw_box(&fb_box); + return 0; +} + +static int frame_buffer_init(uint8_t vout_id, int *width, int *height) +{ + smartfb_init_t fb_type; + struct fb_var_screeninfo varx; + fb_type.vout = vout_id; + memset(&fb_box, 0, sizeof(smartfb_box_t)); + memset(&fb_textbox, 0, sizeof(smartfb_textbox_t)); + + if (smartfb_init(&fb_type) < 0) { + return -1; + } + + smartfb_get_var(&varx); + *width = varx.xres; + *height = varx.yres; + return 0; +}*/ + +int store_bin(char *file, int size, void *addr) +{ + FILE *fp = NULL; + int rval = 0; + + do { + if ((fp = fopen(file, "wb")) == NULL) { + printf("\n%s\n",file); + rval = -1; + break; + } + + if (fwrite(addr, 1, size, fp) != size) { + printf("\nfwrite]n"); + rval = -1; + break; + } + + fclose(fp); + fp = NULL; + + } while (0); + + if (fp) { + fclose(fp); + fp = NULL; + } + + return rval; +} + +int parse_bbox_data(detection_pos *pNext_obj,struct nnctrl_param *pctrl, uint32_t net_idx, uint32_t frame_idx,float nms_threshold) +{ + //printf("\n[parse bbox data] begin\n"); + //DESE + //pthread_mutex_lock(&mutex_parse_bbox); + + uint32_t name_len; + uint32_t rval = 0; + uint32_t i, k; + + +#if 0 + memset(g_f_socket_data, 0, sizeof(g_f_socket_data)); + memset(g_parse_buffer, 0, sizeof(g_parse_buffer)); +#endif + + if (pctrl != NULL && + check_stop_test_nn_cavalry == 0) { + + struct net_output_cfg *net_out; + + pctrl->net_pair[net_idx].valid_result_num = 0; + + net_out = &pctrl->net_pair[net_idx].net_out; + + //uint32_t label_name_idx = 0; + + //printf("\n[parse bbox data] frame_idx:%d send_desc_flag:%d net_idx:%d\n", frame_idx, send_desc_flag, net_idx); + //if (frame_idx == 0 && send_desc_flag) //sophia mark 20201021 + if (pctrl->net_pair[net_idx].is_netoutbindesc_initial == 0 && send_desc_flag) //sophia add 20201021 + { + + //receive_bin_desc + pctrl->net_pair[net_idx].out_bin.bin_num = net_out->out_num; + if (pctrl->net_pair[net_idx].out_bin.bin_num > MAX_IO_NUM) { + printf("Output binary number too much, please increase MAX_IO_NUM\n"); + } + + //printf("\n[parse bbox data] net_out->out_num:%d\n", net_out->out_num); + + for (k = 0; k < net_out->out_num; k++) + { + //printf("\n[parse bbox data] k:%d\n", k); + + if (net_out->out_desc[k].size == 0) + { + printf("Not found addr for output port [%s]\n", net_out->out_desc[k].name); + rval = -1; + break; + } + + name_len = strlen(net_out->out_desc[k].name); + if (name_len > 512) + { + printf("Warning: Output Port name too long, length = %d!\n", name_len); + } + + pctrl->net_pair[net_idx].out_bin.port_name_length[k] = name_len; + + strncpy(pctrl->net_pair[net_idx].out_bin.port_name[k], net_out->out_desc[k].name, pctrl->net_pair[net_idx].out_bin.port_name_length[k]); + pctrl->net_pair[net_idx].out_bin.port_name[k][pctrl->net_pair[net_idx].out_bin.port_name_length[k]] = '\0'; + //printf("\n[parse bbox data] name = %s\n ", pctrl->net_pair[net_idx].out_bin.port_name[k]); + + pctrl->net_pair[net_idx].out_bin.data_desc[k].sign = net_out->out_desc[k].data_fmt.sign; + pctrl->net_pair[net_idx].out_bin.data_desc[k].size = net_out->out_desc[k].data_fmt.size; + pctrl->net_pair[net_idx].out_bin.data_desc[k].expoffset = net_out->out_desc[k].data_fmt.expoffset; + pctrl->net_pair[net_idx].out_bin.data_desc[k].expbits = net_out->out_desc[k].data_fmt.expbits; + pctrl->net_pair[net_idx].out_bin.data_desc[k].plane = net_out->out_desc[k].dim.plane; + pctrl->net_pair[net_idx].out_bin.data_desc[k].depth = net_out->out_desc[k].dim.depth; + pctrl->net_pair[net_idx].out_bin.data_desc[k].height = net_out->out_desc[k].dim.height; + pctrl->net_pair[net_idx].out_bin.data_desc[k].width = net_out->out_desc[k].dim.width; + pctrl->net_pair[net_idx].out_bin.data_desc[k].pitch = net_out->out_desc[k].dim.pitch; + } + + //sophia add 20201021 + pctrl->net_pair[net_idx].is_netoutbindesc_initial = 1; + } + + for (i = 0; i < AMBA_YOLOV3_FEATURE_NUM; i++) + { + pctrl->net_pair[net_idx].feature_map_size[i] = 0; + } + + for (i = 0; i < pctrl->net_pair[net_idx].out_bin.bin_num; i++) { + pctrl->net_pair[net_idx].feature_map_size[i] = pctrl->net_pair[net_idx].out_bin.data_desc[i].plane * pctrl->net_pair[net_idx].out_bin.data_desc[i].depth + * pctrl->net_pair[net_idx].out_bin.data_desc[i].height * pctrl->net_pair[net_idx].out_bin.data_desc[i].pitch; + } + + //for (i = 0; i < input_bin_num; i++) + for (i = 0; i < pctrl->net_pair[net_idx].input_bin_num; i++) + { + //printf("\n[parse bbox data] i:%d sign:%d size:%d expoffset:%d expbits:%d\n", i, pctrl->net_pair[net_idx].out_bin.data_desc[i].sign, pctrl->net_pair[net_idx].out_bin.data_desc[i].size, pctrl->net_pair[net_idx].out_bin.data_desc[i].expoffset, pctrl->net_pair[net_idx].out_bin.data_desc[i].expbits); + //if (pctrl->net_pair[net_idx].out_bin.data_desc[i].sign != 1 || pctrl->net_pair[net_idx].out_bin.data_desc[i].size != 2 + // || pctrl->net_pair[net_idx].out_bin.data_desc[i].expoffset != 0 + // || pctrl->net_pair[net_idx].out_bin.data_desc[i].expbits != 7) { + // printf("Binary %d data format is not fp32, Exit!\n", i); + // rval = -1; + // break; + //} + if (pctrl->net_pair[net_idx].out_bin.data_desc[i].sign != 1) + { + printf("parse [%d] bbox err 1 \n", i); + rval = -1; + } + if (pctrl->net_pair[net_idx].out_bin.data_desc[i].size != 2) + { + printf("parse [%d] bbox err 2 \n", i); + rval = -1; + } + if (pctrl->net_pair[net_idx].out_bin.data_desc[i].expoffset != 0) + { + printf("parse [%d] bbox err 3 \n", i); + rval = -1; + } + if (pctrl->net_pair[net_idx].out_bin.data_desc[i].expbits != 7) + { + printf("parse [%d] bbox err 4 \n", i); + rval = -1; + } + if (rval == -1) { + //pthread_mutex_unlock(&mutex_parse_bbox); + return rval; + + } + + //break; + } + + //printf("\n[parse bbox data] i for out\n"); + + //OUTPUT + //uint32_t k = 0; + /* Send output blob */ + int read_idx = 0; + //printf("\n------------net_idx:%d\n",(int)net_idx); + for (k = 0; k < net_out->out_num; k++) { + if (net_out->out_desc[k].size == 0) { + printf("Not found addr for output port [%s]\n", net_out->out_desc[k].name); + break; + } + +#if 1 + //printf("\n[parse bbox data] k for out111\n"); + if ((int)net_out->out_desc[k].size>=1) { + if (cavalry_mem_sync_cache(net_out->out_desc[k].size, + net_out->out_desc[k].addr, 0, 1) < 0) { + printf("cavalry_mem_sync_cache err # 1\n"); + } + } +#endif + //printf("\n[parse bbox data] k for out111222\n"); + if (net_out->out_desc[k].virt != NULL) { +#if 1 + + memcpy(g_parse_buffer + read_idx, net_out->out_desc[k].virt, net_out->out_desc[k].size); + +#else + memcpy(pctrl->net_pair[net_idx].parse_buffer + read_idx, net_out->out_desc[k].virt, net_out->out_desc[k].size); +#endif + read_idx += net_out->out_desc[k].size; + } + } + //printf("\n[parse bbox data] k for out\n"); +#if 1 + //printf("\n-----------read_idx:%d\n", read_idx); + memcpy((char *)g_f_socket_data, g_parse_buffer, read_idx); + + //printf("\n[parse bbox data] 1\n"); + pctrl->net_pair[net_idx].yolov3_result_num = 0; + + // Call API in lib_data_process to get valid objects + pctrl->net_pair[net_idx].run_yolov3_param.layer_type = DPROC_YOLOV3_OUT; + pctrl->net_pair[net_idx].yolov3_param = &(pctrl->net_pair[net_idx].run_yolov3_param.arg.yolov3_param); +#if 1 + + pctrl->net_pair[net_idx].yolov3_param->feature_map[0] = g_f_socket_data; + +#else + pctrl->net_pair[net_idx].yolov3_param->feature_map[0] = pctrl->net_pair[net_idx].f_socket_data; + +#endif + + pctrl->net_pair[net_idx].feature_map_offset = 0; + //printf("\n[parse bbox data] 222--------------net_idx:%d\n", (int)net_idx); + // for (i = 1; i < input_bin_num; i++) { + for (i = 1; i < pctrl->net_pair[net_idx].input_bin_num; i++) { + pctrl->net_pair[net_idx].feature_map_offset += (pctrl->net_pair[net_idx].feature_map_size[i - 1] >> pctrl->net_pair[net_idx].out_bin.data_desc[i - 1].size); +#if 1 + + pctrl->net_pair[net_idx].yolov3_param->feature_map[i] = g_f_socket_data + pctrl->net_pair[net_idx].feature_map_offset; + +#else + pctrl->net_pair[net_idx].yolov3_param->feature_map[i] = pctrl->net_pair[net_idx].f_socket_data + pctrl->net_pair[net_idx].feature_map_offset; +#endif + } + //printf("\n[parse bbox data] 2--------------net_idx:%d\n",(int)net_idx); + + pctrl->net_pair[net_idx].yolov3_result_num = run_amba_yolov3(&pctrl->net_pair[net_idx].run_yolov3_param, pctrl->net_pair[net_idx].amba_yolov3_result, net_idx, nms_threshold); + + //printf("\n[parse bbox data] 2 end--------------net_idx:%d\n", (int)net_idx); + + + if (pctrl->net_pair[net_idx].yolov3_result_num < 0) { + printf("Failt to run_amba_yolov3!\n"); + //pthread_mutex_unlock(&mutex_parse_bbox); + return -1; + } + //printf("\n[parse bbox data] 4\n"); + //----------------------------------------------------- + //printf("rsult num = %d \n", pctrl->net_pair[net_idx].yolov3_result_num); + // Find the largest area in the same label_id + //printf("\n[parse bbox data] 3--------------net_idx:%d\n", (int)net_idx); + + float temp_framsize_height = (float)g_framesize_height; + float temp_framsize_width = (float)g_framesize_width; + float temp_g_ori_yuv_height = (float)g_ori_yuv_height; + float temp_g_ori_yuv_width = (float)g_ori_yuv_width; + float temp_standard_height = 9.0; + float temp_standard_width = 16.0; + + float ratio_height_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_height / temp_framsize_height; + float ratio_width_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_width / temp_framsize_width; + + float ratio_height_standard_to_g_ori_yuv = temp_standard_height / temp_g_ori_yuv_height; + float ratio_width_standard_to_g_ori_yuv = temp_standard_width / temp_g_ori_yuv_width; + + float ratio_height_standard_to_framsize = temp_standard_height / temp_framsize_height; + float ratio_width_standard_to_framsize = temp_standard_width / temp_framsize_width; + + for (i = 0; i < pctrl->net_pair[net_idx].yolov3_result_num; i++) { + if (!pctrl->net_pair[net_idx].amba_yolov3_result[i].valid) { + continue; + } + + //printf("w= %d, h= %d \n", width, height); + pctrl->net_pair[net_idx].objects = &(pctrl->net_pair[net_idx].amba_yolov3_result[i].bbox); + + //if (net_idx == iFeature_lpr_layer_index) + //{ + //printf("\nx_min:%f,x_max:%f,y_min:%f,y_max:%f\n", pctrl->net_pair[net_idx].objects->x_min, pctrl->net_pair[net_idx].objects->x_max, pctrl->net_pair[net_idx].objects->y_min, pctrl->net_pair[net_idx].objects->y_max); + //} + + pctrl->net_pair[net_idx].objects_id[i] = pctrl->net_pair[net_idx].amba_yolov3_result[i].label; + + if (pNext_obj != NULL) { + pctrl->net_pair[net_idx].objects->x_min = (pNext_obj->left_x + pctrl->net_pair[net_idx].objects->x_min * pNext_obj->width) / temp_g_ori_yuv_width; + pctrl->net_pair[net_idx].objects->x_max = (pNext_obj->left_x + pctrl->net_pair[net_idx].objects->x_max * pNext_obj->width) / temp_g_ori_yuv_width; + pctrl->net_pair[net_idx].objects->y_min = (pNext_obj->top_y + pctrl->net_pair[net_idx].objects->y_min * pNext_obj->height) / temp_g_ori_yuv_height; + pctrl->net_pair[net_idx].objects->y_max = (pNext_obj->top_y + pctrl->net_pair[net_idx].objects->y_max * pNext_obj->height) / temp_g_ori_yuv_height; + } + + if (g_check_if_OK_thermal == 0 && g_IsPTZDevice == 1 && strcmp(SystemSetting.enable_crop_mode, "Yes") == 0 && g_ori_yuv_height >= 1 && g_ori_yuv_width >= 1 && g_framesize_height >= 1 && g_framesize_width >= 1) { + float thres_x_min = 0.0; + float thres_x_max = 1.0; + float thres_y_min = 0.0; + float thres_y_max = 1.0; + + float cut_thres_ratio_x = 1.0; + float cut_thres_ratio_y = 1.0; + + float cut_thres_ratio_g_ori_yuv_x = 1.0; + float cut_thres_ratio_g_ori_yuv_y = 1.0; + + float cut_thres_ratio_framsize_x = 1.0; + float cut_thres_ratio_framsize_y = 1.0; + + if (!(iFeature_lpr_layer_index >= 0 && net_idx == iFeature_lpr_layer_index + 1)) { + + if (ratio_height_g_ori_yuv_to_ai_webpage == ratio_width_g_ori_yuv_to_ai_webpage) { + + } + else if (ratio_height_standard_to_g_ori_yuv == ratio_width_standard_to_g_ori_yuv) { + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio_x = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + thres_x_min += ((1.0 - cut_thres_ratio_x) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio_x) / 2.0); + } + else if (ratio_width_g_ori_yuv_to_ai_webpage < ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio_y = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + thres_y_min += ((1.0 - cut_thres_ratio_y) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio_y) / 2.0); + } + } + else + { + float thres_x_min_g_ori_yuv = 0.0; + float thres_x_max_g_ori_yuv = 1.0; + float thres_y_min_g_ori_yuv = 0.0; + float thres_y_max_g_ori_yuv = 1.0; + + float thres_x_min_framsize = 0.0; + float thres_x_max_framsize = 1.0; + float thres_y_min_framsize = 0.0; + float thres_y_max_framsize = 1.0; + + if (ratio_width_standard_to_g_ori_yuv > ratio_height_standard_to_g_ori_yuv) { + cut_thres_ratio_g_ori_yuv_x = (temp_standard_height * temp_g_ori_yuv_width) / (temp_g_ori_yuv_height*temp_standard_width); + thres_x_min_g_ori_yuv += ((1.0 - cut_thres_ratio_g_ori_yuv_x) / 2.0); + thres_x_max_g_ori_yuv -= ((1.0 - cut_thres_ratio_g_ori_yuv_x) / 2.0); + } + else if (ratio_width_standard_to_g_ori_yuv < ratio_height_standard_to_g_ori_yuv) { + cut_thres_ratio_g_ori_yuv_y = (temp_standard_width * temp_g_ori_yuv_height) / (temp_g_ori_yuv_width*temp_standard_height); + thres_y_min_g_ori_yuv += ((1.0 - cut_thres_ratio_g_ori_yuv_y) / 2.0); + thres_y_max_g_ori_yuv -= ((1.0 - cut_thres_ratio_g_ori_yuv_y) / 2.0); + } + + if (ratio_width_standard_to_framsize > ratio_height_standard_to_framsize) { + cut_thres_ratio_framsize_x = (temp_standard_height * temp_framsize_width) / (temp_framsize_height*temp_standard_width); + thres_x_min_framsize += ((1.0 - cut_thres_ratio_framsize_x) / 2.0); + thres_x_max_framsize -= ((1.0 - cut_thres_ratio_framsize_x) / 2.0); + } + else if (ratio_width_standard_to_framsize < ratio_height_standard_to_framsize) { + cut_thres_ratio_framsize_y = (temp_standard_width * temp_framsize_height) / (temp_framsize_width*temp_standard_height); + thres_y_min_framsize += ((1.0 - cut_thres_ratio_framsize_y) / 2.0); + thres_y_max_framsize -= ((1.0 - cut_thres_ratio_framsize_y) / 2.0); + } + + if (cut_thres_ratio_g_ori_yuv_x > cut_thres_ratio_framsize_x) + { + //cut_thres_ratio_x = cut_thres_ratio_framsize_x / cut_thres_ratio_g_ori_yuv_x; + //thres_x_min += (1.0 - cut_thres_ratio_x) / 2.0; + //thres_x_max -= (1.0 - cut_thres_ratio_x) / 2.0; + + cut_thres_ratio_x = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + //thres_x_min += thres_x_min_g_ori_yuv - thres_x_min_framsize; + //thres_x_max -= thres_x_max_framsize - thres_x_max_g_ori_yuv; + thres_x_min += ((1.0 - cut_thres_ratio_x) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio_x) / 2.0); + } + else if(cut_thres_ratio_g_ori_yuv_x < cut_thres_ratio_framsize_x){ + //cut_thres_ratio_x = cut_thres_ratio_g_ori_yuv_x / cut_thres_ratio_framsize_x; + //thres_x_min += (1.0 - cut_thres_ratio_x) / 2.0; + //thres_x_max -= (1.0 - cut_thres_ratio_x) / 2.0; + + //cut_thres_ratio_x = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + //thres_x_min += thres_x_min_framsize - thres_x_min_g_ori_yuv; + //thres_x_max -= thres_x_max_g_ori_yuv - thres_x_max_framsize; + //thres_x_min += ((1.0 - cut_thres_ratio_x) / 2.0); + //thres_x_max -= ((1.0 - cut_thres_ratio_x) / 2.0); + } + + if (cut_thres_ratio_g_ori_yuv_y > cut_thres_ratio_framsize_y) + { + //cut_thres_ratio_y = cut_thres_ratio_framsize_y / cut_thres_ratio_g_ori_yuv_y; + //thres_y_min += (1.0 - cut_thres_ratio_y) / 2.0; + //thres_y_max -= (1.0 - cut_thres_ratio_y) / 2.0; + + cut_thres_ratio_y = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + //thres_y_min += thres_y_min_g_ori_yuv - thres_y_min_framsize; + //thres_y_max -= thres_y_max_framsize - thres_y_max_g_ori_yuv; + thres_y_min += ((1.0 - cut_thres_ratio_y) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio_y) / 2.0); + } + else if(cut_thres_ratio_g_ori_yuv_y < cut_thres_ratio_framsize_y){ + //cut_thres_ratio_y = cut_thres_ratio_g_ori_yuv_y / cut_thres_ratio_framsize_y; + //thres_y_min += (1.0 - cut_thres_ratio_y) / 2.0; + //thres_y_max -= (1.0 - cut_thres_ratio_y) / 2.0; + + //cut_thres_ratio_y = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + //thres_y_min += thres_y_min_framsize - thres_y_min_g_ori_yuv; + //thres_y_max -= thres_y_max_g_ori_yuv - thres_y_max_framsize; + //thres_y_min += ((1.0 - cut_thres_ratio_y) / 2.0); + //thres_y_max -= ((1.0 - cut_thres_ratio_y) / 2.0); + } + } + } + + if (ratio_height_g_ori_yuv_to_ai_webpage == ratio_width_g_ori_yuv_to_ai_webpage || //ѩMvOۦP + (iFeature_lpr_layer_index >= 0 && net_idx == iFeature_lpr_layer_index + 1)//Pr + ) {//쥻ҥNihp⪫m + pctrl->net_pair[net_idx].objects->x_min = pctrl->net_pair[net_idx].objects->x_min * (float)g_ori_yuv_width; //1920 + pctrl->net_pair[net_idx].objects->x_max = pctrl->net_pair[net_idx].objects->x_max * (float)g_ori_yuv_width; //1920 + pctrl->net_pair[net_idx].objects->y_min = pctrl->net_pair[net_idx].objects->y_min * (float)g_ori_yuv_height; //1080 + pctrl->net_pair[net_idx].objects->y_max = pctrl->net_pair[net_idx].objects->y_max * (float)g_ori_yuv_height; //1080 + } + else { + if (pctrl->net_pair[net_idx].objects->x_max <= thres_x_min || + pctrl->net_pair[net_idx].objects->x_min >= thres_x_max || + pctrl->net_pair[net_idx].objects->y_max <= thres_y_min || + pctrl->net_pair[net_idx].objects->y_min >= thres_y_max || + thres_x_min < 0.0 || thres_x_min > 1.0 || + thres_x_max < 0.0 || thres_x_max > 1.0 || + thres_y_min < 0.0 || thres_y_min > 1.0 || + thres_y_max < 0.0 || thres_y_max > 1.0 || + (thres_x_max - thres_x_min) <= 0.0 || + (thres_y_max - thres_y_min) <= 0.0) + { + pctrl->net_pair[net_idx].amba_yolov3_result[i].score = 0.0; + pctrl->net_pair[net_idx].amba_yolov3_result[i].valid = 0; + continue; + } + else { + if (pctrl->net_pair[net_idx].objects->x_min < thres_x_min) { + pctrl->net_pair[net_idx].objects->x_min = thres_x_min; + } + + if (pctrl->net_pair[net_idx].objects->x_max > thres_x_max) { + pctrl->net_pair[net_idx].objects->x_max = thres_x_max; + } + + if (pctrl->net_pair[net_idx].objects->y_min < thres_y_min) { + pctrl->net_pair[net_idx].objects->y_min = thres_y_min; + } + + if (pctrl->net_pair[net_idx].objects->y_max > thres_y_max) { + pctrl->net_pair[net_idx].objects->y_max = thres_y_max; + } + + if(cut_thres_ratio_x < 1.0) + { + float obj_center_x = (pctrl->net_pair[net_idx].objects->x_min + pctrl->net_pair[net_idx].objects->x_max) / 2.0; + float obj_width = (pctrl->net_pair[net_idx].objects->x_max - pctrl->net_pair[net_idx].objects->x_min); + + obj_center_x = (obj_center_x - 0.5) * (1.0 / cut_thres_ratio_x) + 0.5; + obj_width = obj_width * (1.0 / cut_thres_ratio_x); + + pctrl->net_pair[net_idx].objects->x_min = obj_center_x - obj_width / 2.0; + pctrl->net_pair[net_idx].objects->x_max = obj_center_x + obj_width / 2.0; + + } + else if (cut_thres_ratio_g_ori_yuv_x < cut_thres_ratio_framsize_x) { + float obj_center_x = (pctrl->net_pair[net_idx].objects->x_min + pctrl->net_pair[net_idx].objects->x_max) / 2.0; + float obj_width = (pctrl->net_pair[net_idx].objects->x_max - pctrl->net_pair[net_idx].objects->x_min); + + obj_center_x = (obj_center_x - 0.5) * (cut_thres_ratio_g_ori_yuv_x / cut_thres_ratio_framsize_x) + 0.5; + obj_width = obj_width * (cut_thres_ratio_g_ori_yuv_x / cut_thres_ratio_framsize_x); + + pctrl->net_pair[net_idx].objects->x_min = obj_center_x - obj_width / 2.0; + pctrl->net_pair[net_idx].objects->x_max = obj_center_x + obj_width / 2.0; + } + + if(cut_thres_ratio_y < 1.0) + { + float obj_center_y = (pctrl->net_pair[net_idx].objects->y_min + pctrl->net_pair[net_idx].objects->y_max) / 2.0; + float obj_height = (pctrl->net_pair[net_idx].objects->y_max - pctrl->net_pair[net_idx].objects->y_min); + + obj_center_y = (obj_center_y - 0.5) * (1.0 / cut_thres_ratio_y) + 0.5; + obj_height = obj_height * (1.0 / cut_thres_ratio_y); + + pctrl->net_pair[net_idx].objects->y_min = obj_center_y - obj_height / 2.0; + pctrl->net_pair[net_idx].objects->y_max = obj_center_y + obj_height / 2.0; + } + else if (cut_thres_ratio_g_ori_yuv_y < cut_thres_ratio_framsize_y) { + float obj_center_y = (pctrl->net_pair[net_idx].objects->y_min + pctrl->net_pair[net_idx].objects->y_max) / 2.0; + float obj_height = (pctrl->net_pair[net_idx].objects->y_max - pctrl->net_pair[net_idx].objects->y_min); + + obj_center_y = (obj_center_y - 0.5) * (cut_thres_ratio_g_ori_yuv_y / cut_thres_ratio_framsize_y) + 0.5; + obj_height = obj_height * (cut_thres_ratio_g_ori_yuv_y / cut_thres_ratio_framsize_y); + + pctrl->net_pair[net_idx].objects->y_min = obj_center_y - obj_height / 2.0; + pctrl->net_pair[net_idx].objects->y_max = obj_center_y + obj_height / 2.0; + } + + if (pctrl->net_pair[net_idx].objects->x_min < 0.0) + pctrl->net_pair[net_idx].objects->x_min = 0.0; + + if (pctrl->net_pair[net_idx].objects->x_max > 1.0) + pctrl->net_pair[net_idx].objects->x_max = 1.0; + + if (pctrl->net_pair[net_idx].objects->y_min < 0.0) + pctrl->net_pair[net_idx].objects->y_min = 0.0; + + if (pctrl->net_pair[net_idx].objects->y_max > 1.0) + pctrl->net_pair[net_idx].objects->y_max = 1.0; + + pctrl->net_pair[net_idx].objects->x_min = pctrl->net_pair[net_idx].objects->x_min * (float)g_ori_yuv_width; //1920 + pctrl->net_pair[net_idx].objects->x_max = pctrl->net_pair[net_idx].objects->x_max * (float)g_ori_yuv_width; //1920 + pctrl->net_pair[net_idx].objects->y_min = pctrl->net_pair[net_idx].objects->y_min * (float)g_ori_yuv_height; //1080 + pctrl->net_pair[net_idx].objects->y_max = pctrl->net_pair[net_idx].objects->y_max * (float)g_ori_yuv_height; //1080 + } + } + } + else { + pctrl->net_pair[net_idx].objects->x_min = pctrl->net_pair[net_idx].objects->x_min * (float)g_ori_yuv_width; //1920 + pctrl->net_pair[net_idx].objects->x_max = pctrl->net_pair[net_idx].objects->x_max * (float)g_ori_yuv_width; //1920 + pctrl->net_pair[net_idx].objects->y_min = pctrl->net_pair[net_idx].objects->y_min * (float)g_ori_yuv_height; //1080 + pctrl->net_pair[net_idx].objects->y_max = pctrl->net_pair[net_idx].objects->y_max * (float)g_ori_yuv_height; //1080 + } + + if (!pctrl->net_pair[net_idx].amba_yolov3_result[i].valid) { + continue; + } + else { + pctrl->net_pair[net_idx].valid_result_num++; + } + + //if (frame_idx % 5 == 0) + //{ + //if (net_idx == 0) + //{ + //printf("box[%d]: x=%f, y=%f qusize= %d confidense = %f\n", i, pctrl->net_pair[net_idx].objects->x_min, pctrl->net_pair[net_idx].objects->y_min, QueueSize(_GETALARMMOTION), pctrl->net_pair[net_idx].amba_yolov3_result[i].score); + //} + //else if (net_idx == 1) + //{ + //label_name_idx = pctrl->net_pair[net_idx].objects_id[i]; + //printf("'%s' - ", pctrl->net_pair[net_idx].classNames[label_name_idx*2]); + //printf("'%s' [%f] - \n", pctrl->net_pair[net_idx].classNames[label_name_idx * 2], pctrl->net_pair[net_idx].objects->x_min); + //} + //} + } + + //printf("\n---------%d\n", pctrl->net_pair[net_idx].valid_result_num); + //printf("\n[parse bbox data] 4--------------net_idx:%d\n", (int)net_idx); + //printf("\n[parse bbox data] end\n"); + //if (frame_idx % 5 == 0) + //{ + // if (net_idx == 1) + // printf("===== \n"); + //} + } + //pthread_mutex_unlock(&mutex_parse_bbox); + return rval; + +#endif +} + + +#if 1 +int load_no_padding_file(FILE *in, uint8_t *virt_addr, struct io_dim *dim, struct io_data_fmt *data_fmt) +{ + uint8_t *virt = NULL; + uint32_t one_line = 0; + uint32_t p = 0, d = 0, h = 0; + int rval = 0; + + virt = virt_addr; + one_line = dim->width * (1 << data_fmt->size); + for (p = 0; p < dim->plane; p++) { + for (d = 0; d < dim->depth; d++) { + for (h = 0; h < dim->height; h++) { + if (fread(virt, 1, one_line, in) != one_line) { + perror("fread input file"); + rval = -1; + break; + } + virt += dim->pitch; + } + } + } + + return rval; +} + +int load_file(const char *file_name, uint8_t *virt_addr, uint32_t size,struct io_dim *dim, struct io_data_fmt *data_fmt) +{ + FILE *in = NULL; + uint32_t file_size = 0; + uint32_t no_padding_size = 0; + int rval = 0; + + do { + if ((in = fopen(file_name, "rb")) == NULL) { + perror(file_name); + rval = -1; + break; + } + if (fseek(in, 0, SEEK_END) < 0) { + perror("fseek input file"); + rval = -1; + break; + } + file_size = ftell(in); + if (fseek(in, 0, SEEK_SET) < 0) { + perror("fseek input file"); + rval = -1; + break; + } + + if (file_size == size) { + if (fread(virt_addr, 1, size, in) != size) { + perror("fread input file"); + rval = -1; + break; + } + } + else { + no_padding_size = dim->plane * dim->depth * dim->height * + dim->width * (1 << data_fmt->size); + if (file_size == no_padding_size) { + printf("Load no-padding file [%s] size [%u]. Width: %u, Pitch: %u\n", + file_name, file_size, dim->width, dim->pitch); + rval = load_no_padding_file(in, virt_addr, dim, data_fmt); + } + else { + printf("File [%s] size [%u] mismatch input size [%u] " + "or no_padding size [%u]\n", + file_name, file_size, size, no_padding_size); + rval = -1; + break; + } + } + } while (0); + + if (in) { + fclose(in); + in = NULL; + } + + return rval; +} + +/* Return value: -1: err; 0: ok; 1: ok, input has set no_mem */ +int load_input_io(struct net_match *pnet) +{ + struct io_match *io = NULL; + uint32_t k = 0; + int rval = 0; + + for (k = 0; k < pnet->in_num; k++) { + io = &pnet->in_pair[k]; + if (io->virt_addr == NULL) { + printf("Not found addr for input port [%s]\n", io->port_name); + rval = -1; + break; + } + if (strlen(io->file_name) > 0) { + printf("\n-----------[%d]io->file_name:%s\n", k, io->file_name); + if (load_file(io->file_name, io->virt_addr, io->data_size, + &io->dim, &io->data_fmt) < 0) { + printf("Load input port [%s] with file [%s] failed!\n", + io->port_name, io->file_name); + rval = -1; + break; + } + sync_cache_mem(io->data_size, io->dram_addr, 1, 0); + } + else { + printf("\n-----------[%d]zero:io->file_name:%s\n", k, io->file_name); + } + + pnet->have_no_mem_io = 1; + rval = 1; /* input has set no_mem */ + } + + return rval; +} +#endif + + + +//static char output_name[FILENAME_LENGTH] = "/emmc/plugin/crop/rgb_original.bin"; +//static char output_name_cropped[FILENAME_LENGTH] = "/emmc/plugin/crop/rgb_cropped.bin"; + +static int init_one_net(struct net_match *pnet) +{ + //struct net_match *pnet; + struct net_cfg *net_cf; + struct net_input_cfg *net_in; + struct net_output_cfg *net_out; + struct net_result *net_ret; + + net_cf = &pnet->net_cf; + net_in = &pnet->net_in; + net_out = &pnet->net_out; + net_ret = &pnet->net_ret; + + for (int i = 0; i < MAX_NET_NUM; i++) + { + memset((void *)net_cf, 0, sizeof(struct net_cfg)); + memset((void *)net_in, 0, sizeof(struct net_input_cfg)); + memset((void *)net_out, 0, sizeof(struct net_output_cfg)); + memset((void *)net_ret, 0, sizeof(struct net_result)); + } + + int net_id = 0; + int rval = 0; + + //pnet = &pctl->net_pair[0]; //steven: 0 = first net + net_cf->net_file = pnet->net_name; + net_cf->verbose = pnet->verbose; + net_cf->reuse_mem = pnet->reuse_mem; + //printf("net name = %s \n", net_cf->net_file); + + if (set_net_io_cfg(pnet, net_in, net_out) < 0) { + printf("init set_net_io_cfg err \n"); + rval = -1; + } + net_id = nnctrl_init_net(net_cf, net_in, NULL); + //net_id = nnctrl_init_net(net_cf, net_in, net_out); //sophia 20201021 add + if (net_id < 0) { + printf("nnctrl_init_net err\n"); + rval = -1; + } + else { + if (net_cf->net_mem_total == 0) { + printf("nnctrl_init_net get total size is zero\n"); + rval = -1; + } + else { + pnet->net_id = net_id; + } + } + pnet->net_m.mem_size = net_cf->net_mem_total; + + if (alloc_cv_mem(&pnet->net_m.mem_size, + &pnet->net_m.phy_addr, &pnet->net_m.virt_addr) < 0) { + printf("alloc_cv_mem err\n"); + rval = -1; + } + else { + if (pnet->net_m.virt_addr == NULL) { + printf("alloc_cv_mem is NULL\n"); + rval = -1; + } + } + + if (nnctrl_load_net(net_id, &pnet->net_m, net_in, net_out) < 0) { + printf("nnctrl_load_net err\n"); + rval = -1; + } + + if (cavalry_mem_sync_cache(pnet->net_m.mem_size, pnet->net_m.phy_addr, 1, 0) < 0) { + printf("cavalry_mem_sync_cache err # 2\n"); + } + + if (get_net_io_cfg(pnet, net_in, net_out) < 0) { + printf("get_net_io_cfg err\n"); + rval = -1; + } + + //sophia add 20201021 + pnet->is_netoutbindesc_initial = 0; + + return rval; +} + +void sync_cache_mem(unsigned long size, unsigned long phys, uint8_t clean, uint8_t invalid) +{ + if (check_stop_test_nn_cavalry == 0) { + //struct nnctrl_param *pctrl = &G_nnctrl; + + //if (pctrl->all_cache_en) + { + if (cavalry_mem_sync_cache(size, phys, clean, invalid) < 0) { + printf("cavalry_mem_sync_cache err # 3\n"); + } + } + } +} + +void clean_output_mem(struct net_match* pnet) +{ + struct io_match* io = NULL; + uint32_t k = 0; + + + for (k = 0; k < pnet->out_num; k++) { + io = &pnet->out_pair[k]; + memset(io->virt_addr, 0, io->data_size); + sync_cache_mem(io->data_size, io->dram_addr, 1, 0); + } +} +void invalid_output_mem(struct net_match *pnet) +{ + struct io_match *io = NULL; + uint32_t k = 0; + + + for (k = 0; k < pnet->out_num; k++) { + io = &pnet->out_pair[k]; + sync_cache_mem(io->data_size, io->dram_addr, 0, 1); + } +} + +void clean_output_padding(struct net_match *pnet) +{ + struct io_match *io = NULL; + uint8_t *virt = NULL; + uint32_t k = 0, p = 0, d = 0, h = 0, i = 0; + uint32_t padding_size = 0, one_line = 0; + uint8_t bit_num = 0, bit_gap = 0, bit_mask = 0; + + for (k = 0; k < pnet->out_num; k++) { + io = &pnet->out_pair[k]; + if ((io->data_fmt.size == DATASIZE_INVALID) || (io->dim.dram_fmt)) { + continue; + } + virt = io->virt_addr; + + if (!io->dim.bitvector) { + one_line = io->dim.width * (1 << io->data_fmt.size); + virt += one_line; + padding_size = io->dim.pitch - one_line; + if (padding_size > 0) { + for (p = 0; p < io->dim.plane; p++) { + for (d = 0; d < io->dim.depth; d++) { + for (h = 0; h < io->dim.height; h++) { + memset(virt, 0, padding_size); + virt += io->dim.pitch; + } + } + } + + sync_cache_mem(io->data_size, io->dram_addr, 1, 0); + } + } + else { + one_line = io->dim.width / 8; + bit_num = io->dim.width - one_line * 8; + for (i = 0; i < bit_num; i++) { + bit_mask = bit_mask | (1 << (7 - i)); + } + virt += one_line; + bit_gap = bit_num ? 1 : 0; + padding_size = io->dim.pitch - one_line - bit_gap; + printf("clean_padding for bitvector, " + "bit_num: %u, bit_mask: 0x%x, one_bit: %u, padding_size: %u\n", + bit_num, bit_mask, bit_gap, padding_size); + if (padding_size > 0) { + for (p = 0; p < io->dim.plane; p++) { + for (d = 0; d < io->dim.depth; d++) { + for (h = 0; h < io->dim.height; h++) { + if (bit_gap) { + *virt = (*virt) & bit_mask; + } + memset(virt + bit_gap, 0, padding_size); + virt += io->dim.pitch; + } + } + } + + sync_cache_mem(io->data_size, io->dram_addr, 1, 0); + } + } + } +} +const uint32_t crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +static uint32_t crc32(const void *buf, uint32_t size) +{ + const uint8_t *p = NULL; + uint32_t crc = 0; + + p = (const uint8_t *)buf; + crc = ~0U; + + while (size > 0) { + crc = crc32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8); + size--; + } + + return crc ^ ~0U; +} + +static int store_file(const char *file_name, uint8_t *virt_addr, uint32_t size) +{ + FILE *out = NULL; + int rval = 0; + + do { + if ((out = fopen(file_name, "w+b")) == NULL) { + printf("\n%s\n",file_name); + rval = -1; + break; + } + if (fwrite(virt_addr, 1, size, out) != size) { + printf("\n%s\n",file_name); + rval = -1; + break; + } + } while (0); + + if (out) { + fclose(out); + out = NULL; + } + + return rval; +} + +int process_output_mem(struct net_match *pnet) +{ +#define EXT_LEN (32) + int rval = 0; + + if (check_stop_test_nn_cavalry == 0) { + + struct nnctrl_param *pctrl = &G_nnctrl; + struct io_match *io = NULL; + char file_bad[FILENAME_LENGTH + EXT_LEN] = { 0 }; + uint32_t cksum = 0; + uint32_t k = 0; + + for (k = 0; k < pnet->out_num; k++) { + io = &pnet->out_pair[k]; + + /* CRC check */ + if (pctrl->all_check_md5) { + + /*if (io->data_size >= 1)*/ { + cksum = crc32(io->virt_addr, io->data_size); + + if (io->crc_inited == 0) { + io->crc_result = cksum; + io->crc_inited = 1; + printf("Port [%s] CRC: %08x\n", io->port_name, io->crc_result); + } + else { + if (cksum != io->crc_result) { + printf("Check [%s] CRC err, real: %08x, expect: %08x\n", + io->port_name, cksum, io->crc_result); + rval = -1; + if (strlen(io->file_name) > 0) { + snprintf(file_bad, sizeof(file_bad), "%s_%08x_crc", + io->file_name, cksum); + if (store_file(file_bad, io->virt_addr, io->data_size) < 0) { + printf("Store output port [%s] to file [%s] failed\n", + io->port_name, file_bad); + rval = -1; + } + printf("Store output %s for CRC check\n", file_bad); + } + } + } + } + /* + else + rval = -1;*/ + } + + /* STORE output blob */ + if (strlen(io->file_name) > 0) { + if (io->out_stored == 0) { + + /*if (io->data_size >= 1)*/ { + if (store_file(io->file_name, io->virt_addr, io->data_size) < 0) { + printf("Store output port [%s] to file [%s] failed\n", + io->port_name, io->file_name); + rval = -1; + } + io->out_stored = 1; + } + /* + else + rval = -1;*/ + } + } + } + } + return rval; +} + +//static void *run_one_net(void *arg) //20201019 sophia mark +static int run_one_net(void *arg) +{ + //printf("\n[run_one_net] start\n"); + struct net_match *pnet = (struct net_match *)arg; + //struct net_cfg *net_cf; + struct net_input_cfg *net_in; + //struct net_output_cfg *net_out; + struct net_result *net_ret; + + //net_cf = &pnet->net_cf; + net_in = &pnet->net_in; + //net_out = &pnet->net_out; + net_ret = &pnet->net_ret; + + int rval = 0, result = 0; + + //memset((void *)&net_ret, 0, sizeof(struct net_result)); //sophia mark 20201019 + memset((void *)net_ret, 0, sizeof(struct net_result)); + + do + { +#if 1 + //printf("\n----------1\n"); + //clean_output_mem(pnet); +#endif + //while (live_mode_flag) { + /* Always use the same input/output addr */ + //result = nnctrl_run_net(pnet->net_id, net_ret, &pnet->net_rev, NULL, NULL); + //printf("\n----------2\n"); +#if 1 + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + result = nnctrl_run_net(pnet->net_id, net_ret, NULL, net_in, NULL); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----nnctrl_run_net ms:%lf\n", dw_FPS_time_delta); + + //last_ms = now_ms; +#endif + //result = nnctrl_run_net(pnet->net_id, net_ret, &pnet->net_rev, net_in, net_out); //sophia add 20201021 + //printf("\n----------3\n"); +#if 1 + if (result < 0) { + if (result == -EAGAIN) { + do { + result = nnctrl_resume_net(pnet->net_id, net_ret); + if (result == -EINTR) { + printf("interrupt by signal in resume\n"); + break; + } + } while (result == -EAGAIN); + } + else if (result == -EINTR) { + printf("interrupt by signal in run\n"); + break; + } + else { + rval = -1; + break; + } + } + + //} + //printf("\n----------4\n"); + //invalid_output_mem(pnet); + //printf("\n----------5\n"); + //clean_output_padding(pnet); + //printf("\n----------6\n"); + + //if (process_output_mem(pnet) < 0) { + + //printf("process output mem err at iteration\n"); + //rval = -1; + //break; + //} + + if (pnet->dump_en) { + if (nnctrl_dump_net(pnet->net_id, pnet->path_dump) < 0) { + printf("dump blob and dvi err\n"); + rval = -1; + break; + } + } + + if (rval < 0) { + printf("nnctrl_run_net err\n"); + rval = -1; + break; + } + //printf("\n----------7\n"); +#endif + } while (0); + + //printf("\n[run_one_net] end\n"); + + return rval; +} + +int get_enable_downsized_cropped_roi() { + return enable_downsized_cropped_roi; +} + +int get_enable_zone_crop_1() { + return enable_zone_crop_1; +} + +int get_check_first_downsized_cropped_roi_for_object() { + return check_first_downsized_cropped_roi_for_object; +} + +void set_enable_downsized_cropped_roi(int temp_enable_downsized_cropped_roi) { + enable_downsized_cropped_roi = temp_enable_downsized_cropped_roi; +} + +void set_enable_zone_crop_1(int temp_enable_zone_crop_1) { + enable_zone_crop_1 = temp_enable_zone_crop_1; +} + +void snap_hd_image() +{ +#ifdef GY_OS_AMBA + vect_desc_t cropped; + memset(&cropped, 0, sizeof(cropped)); + + y_p->roi.width = g_ori_yuv_width; + y_p->roi.height = g_ori_yuv_height; + y_p->roi.xoffset = 0; + y_p->roi.yoffset = 0; + + uv_p->roi.width = g_ori_yuv_width / 2; + uv_p->roi.height = g_ori_yuv_height / 2; + uv_p->roi.xoffset = 0 / 2; // YUV 422 format, half UV sizes + uv_p->roi.yoffset = 0 / 2; + + cropped.shape.p = 1; + cropped.shape.d = 3; // RGB + cropped.shape.w = g_ori_yuv_width; + cropped.shape.h = g_ori_yuv_height; + + cropped.data_format.sign = 0; + cropped.data_format.datasize = 0; + cropped.data_format.exp_offset = 0; + cropped.data_format.exp_bits = 0; + cropped.pitch = ROUND_UP(cropped.shape.w * (1 << cropped.data_format.datasize), 32); // Alignment for hardware 32-bit bus + cropped.color_space = rgb_type ? CS_BGR : CS_RGB; // Default set to RGB + + //printf("\n[snap hd] snap hd dim.: %d, %d, %d, %d, pitch: %d, data_format: %d, %d, %d, %d, color space: %s\n", cropped.shape.p, cropped.shape.d, cropped.shape.h, cropped.shape.w, cropped.pitch, cropped.data_format.sign, cropped.data_format.datasize, cropped.data_format.exp_offset, cropped.data_format.exp_bits, cropped.color_space == CS_BGR ? "BGR" : "RGB"); + //printf("\n--------snap hd:----------3--------1\n"); + + { + + //pthread_mutex_lock(&mutex_get_network_input); + + cropped.data_addr = yuv2rgb_out_mem.phys; + + int yu2rg_result = vproc_yuv2rgb_420(y_p, uv_p, &cropped, yuv2rgb_mat_p); // THIS API CONVERTS YUV (422) FORMAT TO RGB. + //printf("\n--------snap hd:----------3--------2\n"); + if (yu2rg_result < 0) + { + printf("[snap hd] vproc_yuv2rgb_420(...) failure!\n"); + //pthread_mutex_unlock(&mutex_get_network_input); + return; + } + + + y_p->roi.xoffset = 0; + y_p->roi.yoffset = 0; + y_p->roi.width = 0; + y_p->roi.height = 0; + + uv_p->roi.xoffset = 0; + uv_p->roi.yoffset = 0; + uv_p->roi.width = 0; + uv_p->roi.height = 0; + //printf("\n--------snap hd:----------3--------3\n"); + { + vect_desc_t snap_hd_full; + memset(&snap_hd_full, 0, sizeof(snap_hd_full)); + + snap_hd_full.shape.p = 1; + snap_hd_full.shape.d = 3; + + int object_hegiht = VIEW_WEB_HEIGHT_HD; + int object_width = VIEW_WEB_WIDTH_HD; + + + snap_hd_full.shape.h = object_hegiht; + snap_hd_full.shape.w = object_width; + //printf("\n--------snap hd:----------3--------4\n"); + snap_hd_full.data_format.sign = cropped.data_format.sign; + snap_hd_full.data_format.datasize = cropped.data_format.datasize; + snap_hd_full.data_format.exp_offset = cropped.data_format.exp_offset; + snap_hd_full.data_format.exp_bits = cropped.data_format.exp_bits; + snap_hd_full.pitch = ROUND_UP(snap_hd_full.shape.w * (1 << snap_hd_full.data_format.datasize), 32); + snap_hd_full.color_space = cropped.color_space; + + snap_hd_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; + + + snap_hd_full.data_addr = snap_hd_mem.phys; + vproc_memcpy(snap_hd_full.data_addr, cropped.data_addr, snap_hd_mem.size); + //printf("\n--------snap hd:----------3--------5\n"); + snap_hd_mem.size = snap_hd_full.shape.p * snap_hd_full.shape.d * snap_hd_full.shape.h * snap_hd_full.pitch; + if (vproc_resize(&cropped, &snap_hd_full) < 0) + printf("[snap hd] vproc_resize(&cropped, &snap_hd_full) failed.\n"); + else + { + if (snap_hd_mem.size >= 1) + { + //printf("\n------------MAX_IMG_SIZE:%d,snap_hd_mem.size:%d\n", MAX_IMG_SIZE, snap_hd_mem.size); + memcpy(g_img_buf_for_snaphd, snap_hd_mem.virt, snap_hd_mem.size); + g_snap_hd_shape_w_for_snaphd = snap_hd_full.shape.w; + g_snap_hd_pitch_for_snaphd = snap_hd_full.pitch; + g_snap_hd_shape_h_for_snaphd = snap_hd_full.shape.h; + } + //printf("\n------------SaveRawRGBToJPG\n"); + //SaveRawRGBToJPG("/emmc/plugin/Aida_data/hello.jpg", g_img_buf_for_snaphd, g_snap_hd_shape_w_for_snaphd, g_snap_hd_pitch_for_snaphd, g_snap_hd_shape_h_for_snaphd, 0); + } + } + //printf("\n--------snap hd:----------3--------6\n"); + //pthread_mutex_unlock(&mutex_get_network_input); + //printf("\n[snap hdi] end\n"); + } +#endif //ALL +} + +int testsstoreYUV(char *file, int size, void *addr) +{ + FILE *fp = NULL; + int rval = 0; + + do { + if ((fp = fopen(file, "wb")) == NULL) { + printf("\n%s\n", file); + rval = -1; + break; + } + + + + if (fwrite(addr, 1, size, fp) != size) { + printf("\nfwrite]n"); + rval = -1; + break; + } + + fclose(fp); + fp = NULL; + + } while (0); + + if (fp) { + fclose(fp); + fp = NULL; + } + + return rval; +} + +int testbbinfile(char *filename, char *buffer) +{ + printf("file name: %s \n", filename); + + int lSize = 0; + + FILE *fp = NULL; + + fp = fopen(filename, "r"); + + fseek(fp, 0, SEEK_END); + lSize = ftell(fp); + + rewind(fp); //set read point to start + /*size_t read_result = */fread(buffer, 1, lSize, fp); + + fclose(fp); + + return lSize; +} + +//unsigned char* croppedImageData; +int croppedImageWidth; +int croppedImageHeight; +int croppedImagePitch; +void cropped_roi(detection_pos *pNext_plate, struct net_match *net_pair_orc, int current_index, char* snapshot_addr,size_t snapshot_size)//detection_pos +{ + + vect_desc_t cropped, cropped_2K; + memset(&cropped, 0, sizeof(cropped)); + memset(&cropped_2K, 0, sizeof(cropped_2K)); + + int obj_w, obj_h, obj_x, obj_y; + + /* objects = &(net_pair_plate->amba_yolov3_result[bbox_idx].bbox); + obj_w = (int)(objects->x_max - objects->x_min) * (3840 / 1920); + obj_h = (int)(objects->y_max - objects->y_min) * (2160 / 1080); + obj_x = (int)objects->x_min * (3840 / 1920); + obj_y = (int)objects->y_min * (2160 / 1080); + HWO~k, ]pctrl->net_pair[idx - 1].yolov3_result_num eOƧǪ*/ + + //printf("\n[cropped ROI] oim w, h = %d, %d \n", g_ori_yuv_width, g_ori_yuv_height); + + //printf("\n--------cropped roi:----------1\n"); + + float delta_resize; + + if (g_ori_yuv_width > 0.0) + { + delta_resize = pNext_plate->width * magnification_ratio; + + if ((pNext_plate->left_x - (delta_resize / 2.0)) <= 0.0) + { + obj_x = 1; + obj_w = (int)(pNext_plate->width + (delta_resize / 2.0) + pNext_plate->left_x); + } + else + { + obj_x = (int)(pNext_plate->left_x - (delta_resize / 2.0)); + + if (((float)obj_x + (pNext_plate->width + delta_resize)) >= g_ori_yuv_width) + obj_w = (int)(g_ori_yuv_width - (float)obj_x - 1.0); + else + obj_w = (int)(pNext_plate->width + delta_resize); + } + } + else + { + obj_w = (int)pNext_plate->width; + obj_x = (int)pNext_plate->left_x; + } + +#if 1 + if (g_ori_yuv_height > 0.0) + { + delta_resize = pNext_plate->height * magnification_ratio_height; + + if ((pNext_plate->top_y - (delta_resize / 2.0)) <= 0.0) + { + obj_y = 1; + obj_h = (int)(pNext_plate->height + (delta_resize / 2.0) + (pNext_plate->top_y)); + } + else + { + obj_y = (int)(pNext_plate->top_y - (delta_resize / 2.0)); + + if (((float)obj_y + (pNext_plate->height + delta_resize)) >= g_ori_yuv_height) + obj_h = (int)(g_ori_yuv_height - (float)obj_y - 1.0); + else + obj_h = (int)(pNext_plate->height + delta_resize); + } + } + else +#endif + { + obj_h = (int)pNext_plate->height; + obj_y = (int)pNext_plate->top_y; + } + //printf("\n--------cropped roi:----------2\n"); + //Image size shoule be even!! + + + if (obj_w >= g_ori_yuv_width) + obj_w = g_ori_yuv_width - 20; + + if (obj_h >= g_ori_yuv_height) + obj_h = g_ori_yuv_height - 20; + + obj_x += (obj_x % 2); + obj_y += (obj_y % 2); + obj_w += (obj_w % 2); + obj_h += (obj_h % 2); + + //printf("\n--------------[cropped roi] roi w, h, x, y = %d, %d, %d, %d \n", obj_w, obj_h, obj_x, obj_y); + + y_p->roi.xoffset = obj_x; + y_p->roi.yoffset = obj_y; + y_p->roi.width = obj_w; + y_p->roi.height = obj_h; + + uv_p->roi.xoffset = obj_x / 2; // YUV 422 format, half UV sizes + uv_p->roi.yoffset = obj_y / 2; + uv_p->roi.width = obj_w / 2; + uv_p->roi.height = obj_h / 2; + + + + + //net_in = &net_pair_orc->net_in; + + cropped.shape.p = 1; + cropped.shape.d = 3; // RGB + cropped.shape.w = obj_w; + cropped.shape.h = obj_h; + + cropped.data_format.sign = 0; + cropped.data_format.datasize = 0; + cropped.data_format.exp_offset = 0; + cropped.data_format.exp_bits = 0; + cropped.pitch = ROUND_UP(cropped.shape.w * (1 << cropped.data_format.datasize), 32); // Alignment for hardware 32-bit bus + cropped.color_space = rgb_type ? CS_BGR : CS_RGB; // Default set to RGB + + //printf("\n[cropped roi] Cropped data dim.: %d, %d, %d, %d, pitch: %d, data_format: %d, %d, %d, %d, color space: %s\n", cropped.shape.p, cropped.shape.d, cropped.shape.h, cropped.shape.w, cropped.pitch, cropped.data_format.sign, cropped.data_format.datasize, cropped.data_format.exp_offset, cropped.data_format.exp_bits, cropped.color_space == CS_BGR ? "BGR" : "RGB"); + + //pthread_mutex_lock(&mutex_cropped_roi); + + //printf("\n--------cropped roi:----------3\n"); + { + + ///Cropped End + ///Resize Start + struct net_input_cfg *net_in; + vect_desc_t rsz_sec_in, rsz_sec_out; + memset(&rsz_sec_in, 0, sizeof(rsz_sec_in)); + memset(&rsz_sec_out, 0, sizeof(rsz_sec_out)); + + net_in = &net_pair_orc->net_in; + + //pthread_mutex_lock(&mutex_get_network_input); + //printf("\n--------cropped roi:----------3--------1\n"); + + cropped.data_addr = yuv2rgb_out_mem.phys; + + //printf("\n--------cropped roi:----------3--------2\n"); + + //printf("\n[cropped roi] cropped.data_addr:%lu\n", cropped.data_addr); +#if 1 + int yu2rg_result = vproc_yuv2rgb_420(y_p, uv_p, &cropped, yuv2rgb_mat_p); // THIS API CONVERTS YUV (422) FORMAT TO RGB. + //printf("\n--------cropped roi:----------3--------3\n"); + if (yu2rg_result < 0) + { + printf("[cropped roi] vproc_yuv2rgb_420(...) failure!\n"); + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_cropped_roi); + + return; + } +#endif +#if 0 + if (g_ori_yuv_width > SCALE_BOUNDING_BOX_WIDTH || g_ori_yuv_height > SCALE_BOUNDING_BOX_HEIGHT) { + cropped_2K.shape.p = 1; + cropped_2K.shape.d = 3; + + cropped_2K.shape.h = (int)SCALE_BOUNDING_BOX_HEIGHT; + cropped_2K.shape.w = (int)SCALE_BOUNDING_BOX_WIDTH; + + cropped_2K.data_format.sign = cropped.data_format.sign; + cropped_2K.data_format.datasize = cropped.data_format.datasize; + cropped_2K.data_format.exp_offset = cropped.data_format.exp_offset; + cropped_2K.data_format.exp_bits = cropped.data_format.exp_bits; + cropped_2K.pitch = ROUND_UP(cropped_2K.shape.w * (1 << cropped_2K.data_format.datasize), 32); + cropped_2K.color_space = cropped.color_space; + + cropped_2K.data_addr = rgb_2K_mem.phys; + vproc_memcpy(cropped_2K.data_addr, cropped.data_addr, rgb_2K_mem.size); + rgb_2K_mem.size = cropped_2K.shape.p * cropped_2K.shape.d * cropped_2K.shape.h * cropped_2K.pitch; + + vproc_resize(&cropped, &cropped_2K); + } +#endif + //printf("\n--------cropped roi:----------4\n"); + + if (1) + { +#if 0 + if (g_ori_yuv_width > SCALE_BOUNDING_BOX_WIDTH || g_ori_yuv_height > SCALE_BOUNDING_BOX_HEIGHT) { + rsz_sec_in.shape.p = cropped_2K.shape.p; + rsz_sec_in.shape.d = cropped_2K.shape.d; + rsz_sec_in.shape.h = cropped_2K.shape.h; + rsz_sec_in.shape.w = cropped_2K.shape.w; + rsz_sec_in.data_format.sign = cropped_2K.data_format.sign; // Resize only support Fix8 as input/output + rsz_sec_in.data_format.datasize = cropped_2K.data_format.datasize; + rsz_sec_in.data_format.exp_offset = cropped_2K.data_format.exp_offset; + rsz_sec_in.data_format.exp_bits = cropped_2K.data_format.exp_bits; + rsz_sec_in.pitch = cropped_2K.pitch; + rsz_sec_in.data_addr = cropped_2K.data_addr; + } + else +#endif + { + rsz_sec_in.shape.p = cropped.shape.p; + rsz_sec_in.shape.d = cropped.shape.d; + rsz_sec_in.shape.h = cropped.shape.h; + rsz_sec_in.shape.w = cropped.shape.w; + rsz_sec_in.data_format.sign = cropped.data_format.sign; // Resize only support Fix8 as input/output + rsz_sec_in.data_format.datasize = cropped.data_format.datasize; + rsz_sec_in.data_format.exp_offset = cropped.data_format.exp_offset; + rsz_sec_in.data_format.exp_bits = cropped.data_format.exp_bits; + rsz_sec_in.pitch = cropped.pitch; + rsz_sec_in.data_addr = cropped.data_addr; + } + rsz_sec_in.color_space = CS_RGB; + + rsz_sec_out.shape.p = net_in->in_desc[0].dim.plane; + rsz_sec_out.shape.d = net_in->in_desc[0].dim.depth; + rsz_sec_out.shape.h = net_in->in_desc[0].dim.height; + rsz_sec_out.shape.w = net_in->in_desc[0].dim.width; + rsz_sec_out.data_format.sign = rsz_sec_in.data_format.sign; + rsz_sec_out.data_format.datasize = rsz_sec_in.data_format.datasize; + rsz_sec_out.data_format.exp_offset = rsz_sec_in.data_format.exp_offset; + rsz_sec_out.data_format.exp_bits = rsz_sec_in.data_format.exp_bits; + rsz_sec_out.pitch = ROUND_UP(rsz_sec_out.shape.w * (1 << rsz_sec_out.data_format.datasize), 32); + rsz_sec_out.color_space = CS_RGB; + rsz_sec_out.data_addr = net_in->in_desc[0].addr; + + // printf("\n---------rsz_sec_in.shape.h:%d\n", (int)rsz_sec_in.shape.h); + // printf("\n---------rsz_sec_in.shape.w:%d\n", (int)rsz_sec_in.shape.w); + + // printf("\n---------rsz_sec_out.shape.h:%d\n", (int)rsz_sec_out.shape.h); + // printf("\n---------rsz_sec_out.shape.w:%d\n", (int)rsz_sec_out.shape.w); + } + //printf("\n--------cropped roi:----------5\n"); + + + int resize_result = vproc_resize(&rsz_sec_in, &rsz_sec_out); + + //printf("\n[cropped roi] resize_result:%d\n", resize_result); + if (resize_result < 0) + { + //Free_Snapshot(); + printf("[cropped roi] vproc_resize(...) failure!\n"); + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_cropped_roi); + return; + } + + //joy + if (IsProductionCategory(pNext_plate) && pNext_plate->image_id >= 0) + { + vect_desc_t barcode; + memset(&barcode, 0, sizeof(barcode)); + + barcode.shape.p = 1; + barcode.shape.d = 3; + + int object_hegiht = cropped.shape.h; + int object_width = cropped.shape.w; + + + barcode.shape.h = object_hegiht; + barcode.shape.w = object_width; + //printf("\n--------barcode:----------3--------4\n"); + barcode.data_format.sign = cropped.data_format.sign; + barcode.data_format.datasize = cropped.data_format.datasize; + barcode.data_format.exp_offset = cropped.data_format.exp_offset; + barcode.data_format.exp_bits = cropped.data_format.exp_bits; + barcode.pitch = ROUND_UP(barcode.shape.w * (1 << barcode.data_format.datasize), 32); + barcode.color_space = cropped.color_space; + + barcode_img_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; + + + barcode.data_addr = barcode_img_mem.phys; + vproc_memcpy(barcode.data_addr, cropped.data_addr, barcode_img_mem.size); + // printf("\n--------barcode:----------3--------5\n"); + barcode_img_mem.size = barcode.shape.p * barcode.shape.d * barcode.shape.h * barcode.pitch; + if (vproc_resize(&cropped, &barcode) < 0) + printf("[barcode] vproc_resize(&cropped, &barcode) failed.\n"); + else + { + memset(g_img_buf_for_barode[pNext_plate->image_id], 0x00, MAX_IMG_SIZE); + + if (barcode_img_mem.size != 0) + memcpy(g_img_buf_for_barode[pNext_plate->image_id], barcode_img_mem.virt, barcode_img_mem.size); + + g_shape_w_for_barode = barcode.shape.w; + g_pitch_for_barode = barcode.pitch; + g_shape_h_for_barode = barcode.shape.h; + + //char fileName[100]; + //char dateTimeStr[32]; + + //e~ɤ + //time_t now; + //struct tm *timeinfo; + //time(&now); + //timeinfo = localtime(&now); + //strftime(dateTimeStr, sizeof(dateTimeStr), "%Y_%m_%d_%H_%M_%S", timeinfo); + + //ϥsprintfNɶJɮצW٤ + //sprintf(fileName, "/emmc/plugin/Aida_data/storage/QRcode_%s.jpg", dateTimeStr); + + //croppedImageData = ; + croppedImageWidth = cropped.shape.w; + croppedImageHeight = cropped.shape.h; + croppedImagePitch = barcode.pitch; + //printf("------------SaveRawRGBToJPG\n"); + //SaveRawRGBToJPG(fileName, g_img_buf_for_barode[pNext_plate->image_id], g_shape_w_for_barode, g_pitch_for_barode, g_shape_h_for_barode, 0); + } + } + + + + + + if (AI_fps >= 1) { + if (IsANPRCategory(pNext_plate->engine_type) && + pNext_plate->obj_type == _PLATE) { + if (enable_downsized_cropped_roi == 1) { + pthread_mutex_lock(&mutex_enable_lpr_db); + if (strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0 && viewChannelData[0].enable_anpr > 0) + { + // Color Detection from 416x416 CNN size - Added by LILIN Cayman - 2021.4.15 - Start + vect_desc_t downsized_cropped; + + memset(&downsized_cropped, 0, sizeof(downsized_cropped)); + + downsized_cropped.shape.p = 1; + downsized_cropped.shape.d = 3; + if (obj_h <= VIEW_WEB_HEIGHT && obj_w <= VIEW_WEB_WIDTH) { + double temp_ratio_h = (double)VIEW_WEB_HEIGHT / (double)obj_h; + double temp_ratio_w = (double)VIEW_WEB_WIDTH / (double)obj_w; + double small_temp_ratio = temp_ratio_h <= temp_ratio_w ? temp_ratio_h : temp_ratio_w; + + downsized_cropped.shape.h = (int)(((double)obj_h) * small_temp_ratio); + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = (int)(((double)obj_w) * small_temp_ratio); + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + else if (obj_h > VIEW_WEB_HEIGHT && obj_w <= VIEW_WEB_WIDTH) { + downsized_cropped.shape.h = VIEW_WEB_HEIGHT; + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = obj_w * VIEW_WEB_HEIGHT / obj_h; + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + else if (obj_h <= VIEW_WEB_HEIGHT && obj_w > VIEW_WEB_WIDTH) { + downsized_cropped.shape.h = obj_h * VIEW_WEB_WIDTH / obj_w; + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = VIEW_WEB_WIDTH; + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + else { + double temp_ratio_h = (double)VIEW_WEB_HEIGHT / (double)obj_h; + double temp_ratio_w = (double)VIEW_WEB_WIDTH / (double)obj_w; + double small_temp_ratio = temp_ratio_h <= temp_ratio_w ? temp_ratio_h : temp_ratio_w; + + downsized_cropped.shape.h = (int)(((double)obj_h) * small_temp_ratio); + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = (int)(((double)obj_w) * small_temp_ratio); + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + + downsized_cropped.data_format.sign = cropped.data_format.sign; + downsized_cropped.data_format.datasize = cropped.data_format.datasize; + downsized_cropped.data_format.exp_offset = cropped.data_format.exp_offset; + downsized_cropped.data_format.exp_bits = cropped.data_format.exp_bits; + downsized_cropped.pitch = ROUND_UP(downsized_cropped.shape.w * (1 << downsized_cropped.data_format.datasize), 32); + downsized_cropped.color_space = cropped.color_space; + + downsized_cropped_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; + + { + downsized_cropped.data_addr = downsized_cropped_mem.phys; + // vproc_memcpy(downsized_cropped.data_addr, cropped.data_addr, downsized_cropped_mem.size); + + downsized_cropped_mem.size = downsized_cropped.shape.p * downsized_cropped.shape.d * downsized_cropped.shape.h * downsized_cropped.pitch; + + if (vproc_resize(&cropped, &downsized_cropped) < 0) { + printf("[cropped roi] vproc_resize(&cropped, &downsized_cropped) failed.\n"); + if(pNext_plate->image_id >= 0){ + pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); + g_downsized_cropped_shape_w[pNext_plate->image_id] = 0; + g_downsized_cropped_pitch[pNext_plate->image_id] = 0; + g_downsized_cropped_shape_h[pNext_plate->image_id] = 0; + pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); + } + } + else + { + pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); + //printf("[cropped roi] Copying resized cropped image from the memory...\n"); + //printf("\n-----------downsized_cropped_mem.size: %d\n", (int)downsized_cropped_mem.size); + + + //memset(g_img_buf[pNext_plate->image_id], 0x00, MAX_IMG_SIZE); + + if (downsized_cropped_mem.size != 0 && pNext_plate->image_id >= 0) { + memcpy(g_img_buf[pNext_plate->image_id], downsized_cropped_mem.virt, downsized_cropped_mem.size); + + g_downsized_cropped_shape_w[pNext_plate->image_id] = downsized_cropped.shape.w; + g_downsized_cropped_pitch[pNext_plate->image_id] = downsized_cropped.pitch; + g_downsized_cropped_shape_h[pNext_plate->image_id] = downsized_cropped.shape.h; + + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0 && g_IsPTZDevice == 0) { + int color_size = -1; //convert_to_general_image_for_lprmemcpyC + pNext_plate->color_id = convert_to_general_image_for_lpr(NULL, &color_size, g_img_buf[pNext_plate->image_id], g_downsized_cropped_shape_w[pNext_plate->image_id], g_downsized_cropped_pitch[pNext_plate->image_id], g_downsized_cropped_shape_h[pNext_plate->image_id], 0,&pNext_plate->sec_color_id); + } + else { + pNext_plate->color_id = 0; + pNext_plate->sec_color_id = 0; + } + + downsized_cropped_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; + check_first_downsized_cropped_roi = 1; + + } + else { + if(pNext_plate->image_id >= 0){ + g_downsized_cropped_shape_w[pNext_plate->image_id] = 0; + g_downsized_cropped_pitch[pNext_plate->image_id] = 0; + g_downsized_cropped_shape_h[pNext_plate->image_id] = 0; + } + } + + + pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); + } + } + // Color Detection from 416x416 CNN size - Added by LILIN Cayman - 2021.4.15 - End + } + pthread_mutex_unlock(&mutex_enable_lpr_db); + } + } + else if (!IsANPRCategory(pNext_plate->engine_type) && + strcmp(SystemSetting.enable_display_properties, "Yes") == 0 && + //iFeature_logo_layer_index == -1 && + g_IsPTZDevice == 0) + { + + pthread_mutex_lock(&mutex_differ_image); + + if ((int)snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + int color_size = -1; //crop_image_ivsmemcpyC + pNext_plate->color_id = crop_image_ivs(NULL, &color_size, snapshot_addr, (int)snapshot_size, pNext_plate, g_ori_yuv_width, g_ori_yuv_height); + pNext_plate->sec_color_id = 0; + } + else { + pNext_plate->color_id = 0; + pNext_plate->sec_color_id = 0; + } + + pthread_mutex_unlock(&mutex_differ_image); + + check_first_downsized_cropped_roi_for_object = 1; + } + // else if () + // { + + // } + else + { + pNext_plate->color_id = 0; + pNext_plate->sec_color_id = 0; + } + } + + //printf("\n--------cropped roi:----------7\n"); +#if 0 + //store_bin(path_temp, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt);//submean_out_mem //yuv2rgb_out_mem + //SaveRawRGBToJPG(path_temp, (char)yuv2rgb_out_mem.virt, data_cap->width, 1, data_cap->height, 0); +#endif + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_cropped_roi); + //printf("\n--------cropped roi:----------8\n"); + //printf("\n[cropped roi] end\n"); + } +} + +void cropped_roi_ivs(detection_pos *pNext_plate, struct net_match *net_pair_orc, int current_index, char* snapshot_addr, size_t snapshot_size)//detection_pos +{ + //float magnification_ratio_ivs = 0.02; + //float magnification_ratio_height_ivs = 0.02; + + vect_desc_t cropped, cropped_2K; + memset(&cropped, 0, sizeof(cropped)); + memset(&cropped_2K, 0, sizeof(cropped_2K)); + + int obj_w, obj_h, obj_x, obj_y; + + /* objects = &(net_pair_plate->amba_yolov3_result[bbox_idx].bbox); + obj_w = (int)(objects->x_max - objects->x_min) * (3840 / 1920); + obj_h = (int)(objects->y_max - objects->y_min) * (2160 / 1080); + obj_x = (int)objects->x_min * (3840 / 1920); + obj_y = (int)objects->y_min * (2160 / 1080); + HWO~k, ]pctrl->net_pair[idx - 1].yolov3_result_num eOƧǪ*/ + + //printf("\n[cropped ROI] oim w, h = %d, %d \n", g_ori_yuv_width, g_ori_yuv_height); + + //printf("\n--------cropped roi:----------1\n"); + + //float delta_resize; + +#if 0 + if (g_ori_yuv_width > 0.0) + { + delta_resize = pNext_plate->width * magnification_ratio_ivs; + + if ((pNext_plate->left_x - (delta_resize / 2.0)) <= 0.0) + { + obj_x = 1; + obj_w = (int)(pNext_plate->width + (delta_resize / 2.0) + pNext_plate->left_x); + } + else + { + obj_x = (int)(pNext_plate->left_x - (delta_resize / 2.0)); + + if (((float)obj_x + (pNext_plate->width + delta_resize)) >= g_ori_yuv_width) + obj_w = (int)(g_ori_yuv_width - (float)obj_x - 1.0); + else + obj_w = (int)(pNext_plate->width + delta_resize); + } + } + else +#endif + { + obj_w = (int)pNext_plate->width; + obj_x = (int)pNext_plate->left_x; + } + +#if 0 + if (g_ori_yuv_height > 0.0) + { + delta_resize = pNext_plate->height * magnification_ratio_height_ivs; + + if ((pNext_plate->top_y - (delta_resize / 2.0)) <= 0.0) + { + obj_y = 1; + obj_h = (int)(pNext_plate->height + (delta_resize / 2.0) + (pNext_plate->top_y)); + } + else + { + obj_y = (int)(pNext_plate->top_y - (delta_resize / 2.0)); + + if (((float)obj_y + (pNext_plate->height + delta_resize)) >= g_ori_yuv_height) + obj_h = (int)(g_ori_yuv_height - (float)obj_y - 1.0); + else + obj_h = (int)(pNext_plate->height + delta_resize); + } + } + else +#endif + { + obj_h = (int)pNext_plate->height; + obj_y = (int)pNext_plate->top_y; + } + //printf("\n--------cropped roi:----------2\n"); + //Image size shoule be even!! + + + if (obj_w >= g_ori_yuv_width) + obj_w = g_ori_yuv_width - 1; + + if (obj_h >= g_ori_yuv_height) + obj_h = g_ori_yuv_height - 1; + + obj_x += (obj_x % 2); + obj_y += (obj_y % 2); + obj_w += (obj_w % 2); + obj_h += (obj_h % 2); + + //printf("\n--------------[cropped roi ivs] roi w, h, x, y = %d, %d, %d, %d \n", obj_w, obj_h, obj_x, obj_y); + + y_p->roi.xoffset = obj_x; + y_p->roi.yoffset = obj_y; + y_p->roi.width = obj_w; + y_p->roi.height = obj_h; + + uv_p->roi.xoffset = obj_x / 2; // YUV 422 format, half UV sizes + uv_p->roi.yoffset = obj_y / 2; + uv_p->roi.width = obj_w / 2; + uv_p->roi.height = obj_h / 2; + + + + + //net_in = &net_pair_orc->net_in; + + cropped.shape.p = 1; + cropped.shape.d = 3; // RGB + cropped.shape.w = obj_w; + cropped.shape.h = obj_h; + + cropped.data_format.sign = 0; + cropped.data_format.datasize = 0; + cropped.data_format.exp_offset = 0; + cropped.data_format.exp_bits = 0; + cropped.pitch = ROUND_UP(cropped.shape.w * (1 << cropped.data_format.datasize), 32); // Alignment for hardware 32-bit bus + cropped.color_space = rgb_type ? CS_BGR : CS_RGB; // Default set to RGB + + //printf("\n[cropped roi] Cropped data dim.: %d, %d, %d, %d, pitch: %d, data_format: %d, %d, %d, %d, color space: %s\n", cropped.shape.p, cropped.shape.d, cropped.shape.h, cropped.shape.w, cropped.pitch, cropped.data_format.sign, cropped.data_format.datasize, cropped.data_format.exp_offset, cropped.data_format.exp_bits, cropped.color_space == CS_BGR ? "BGR" : "RGB"); + + //pthread_mutex_lock(&mutex_cropped_roi); + + //printf("\n--------cropped roi:----------3\n"); + { + + ///Cropped End + ///Resize Start + struct net_input_cfg *net_in; + vect_desc_t rsz_sec_in, rsz_sec_out; + memset(&rsz_sec_in, 0, sizeof(rsz_sec_in)); + memset(&rsz_sec_out, 0, sizeof(rsz_sec_out)); + + net_in = &net_pair_orc->net_in; + + //pthread_mutex_lock(&mutex_get_network_input); + //printf("\n--------cropped roi:----------3--------1\n"); + + cropped.data_addr = yuv2rgb_out_mem.phys; + + //printf("\n--------cropped roi:----------3--------2\n"); + + //printf("\n[cropped roi] cropped.data_addr:%lu\n", cropped.data_addr); +#if 1 + int yu2rg_result = vproc_yuv2rgb_420(y_p, uv_p, &cropped, yuv2rgb_mat_p); // THIS API CONVERTS YUV (422) FORMAT TO RGB. + //printf("\n--------cropped roi:----------3--------3\n"); + if (yu2rg_result < 0) + { + printf("[cropped roi ivs] vproc_yuv2rgb_420(...) failure!\n"); + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_cropped_roi); + + return; + } +#endif + + //printf("\n--------cropped roi:----------4\n"); + + rsz_sec_in.shape.p = cropped.shape.p; + rsz_sec_in.shape.d = cropped.shape.d; + rsz_sec_in.shape.h = cropped.shape.h; + rsz_sec_in.shape.w = cropped.shape.w; + rsz_sec_in.data_format.sign = cropped.data_format.sign; // Resize only support Fix8 as input/output + rsz_sec_in.data_format.datasize = cropped.data_format.datasize; + rsz_sec_in.data_format.exp_offset = cropped.data_format.exp_offset; + rsz_sec_in.data_format.exp_bits = cropped.data_format.exp_bits; + rsz_sec_in.pitch = cropped.pitch; + rsz_sec_in.data_addr = cropped.data_addr; + rsz_sec_in.color_space = CS_RGB; + + rsz_sec_out.shape.p = net_in->in_desc[0].dim.plane; + rsz_sec_out.shape.d = net_in->in_desc[0].dim.depth; + rsz_sec_out.shape.h = net_in->in_desc[0].dim.height; + rsz_sec_out.shape.w = net_in->in_desc[0].dim.width; + rsz_sec_out.data_format.sign = rsz_sec_in.data_format.sign; + rsz_sec_out.data_format.datasize = rsz_sec_in.data_format.datasize; + rsz_sec_out.data_format.exp_offset = rsz_sec_in.data_format.exp_offset; + rsz_sec_out.data_format.exp_bits = rsz_sec_in.data_format.exp_bits; + rsz_sec_out.pitch = ROUND_UP(rsz_sec_out.shape.w * (1 << rsz_sec_out.data_format.datasize), 32); + rsz_sec_out.color_space = CS_RGB; + rsz_sec_out.data_addr = net_in->in_desc[0].addr; + + //printf("\n---------rsz_sec_in.shape.h:%d\n", (int)rsz_sec_in.shape.h); + //printf("\n---------rsz_sec_in.shape.w:%d\n", (int)rsz_sec_in.shape.w); + //printf("\n---------rsz_sec_out.shape.h:%d\n", (int)rsz_sec_out.shape.h); + //printf("\n---------rsz_sec_out.shape.w:%d\n", (int)rsz_sec_out.shape.w); + + int resize_result = vproc_resize(&rsz_sec_in, &rsz_sec_out); + + //printf("\n[cropped roi] resize_result:%d\n", resize_result); + if (resize_result < 0) + { + //Free_Snapshot(); + printf("[cropped roi ivs] vproc_resize(...) failure!\n"); + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_cropped_roi); + return; + } + +#if 0 + if (AI_fps >= 1) { + if (IsANPRCategory(pNext_plate->engine_type) && + pNext_plate->obj_type == _PLATE) { + if (enable_downsized_cropped_roi == 1) { + pthread_mutex_lock(&mutex_enable_lpr_db); + if (strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0 && viewChannelData[0].enable_anpr > 0) + { + // Color Detection from 416x416 CNN size - Added by LILIN Cayman - 2021.4.15 - Start + vect_desc_t downsized_cropped; + + memset(&downsized_cropped, 0, sizeof(downsized_cropped)); + + downsized_cropped.shape.p = 1; + downsized_cropped.shape.d = 3; + if (obj_h <= VIEW_WEB_HEIGHT && obj_w <= VIEW_WEB_WIDTH) { + double temp_ratio_h = (double)VIEW_WEB_HEIGHT / (double)obj_h; + double temp_ratio_w = (double)VIEW_WEB_WIDTH / (double)obj_w; + double small_temp_ratio = temp_ratio_h <= temp_ratio_w ? temp_ratio_h : temp_ratio_w; + + downsized_cropped.shape.h = (int)(((double)obj_h) * small_temp_ratio); + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = (int)(((double)obj_w) * small_temp_ratio); + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + else if (obj_h > VIEW_WEB_HEIGHT && obj_w <= VIEW_WEB_WIDTH) { + downsized_cropped.shape.h = VIEW_WEB_HEIGHT; + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = obj_w * VIEW_WEB_HEIGHT / obj_h; + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + else if (obj_h <= VIEW_WEB_HEIGHT && obj_w > VIEW_WEB_WIDTH) { + downsized_cropped.shape.h = obj_h * VIEW_WEB_WIDTH / obj_w; + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = VIEW_WEB_WIDTH; + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + else { + double temp_ratio_h = (double)VIEW_WEB_HEIGHT / (double)obj_h; + double temp_ratio_w = (double)VIEW_WEB_WIDTH / (double)obj_w; + double small_temp_ratio = temp_ratio_h <= temp_ratio_w ? temp_ratio_h : temp_ratio_w; + + downsized_cropped.shape.h = (int)(((double)obj_h) * small_temp_ratio); + downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; + downsized_cropped.shape.w = (int)(((double)obj_w) * small_temp_ratio); + downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; + } + + downsized_cropped.data_format.sign = cropped.data_format.sign; + downsized_cropped.data_format.datasize = cropped.data_format.datasize; + downsized_cropped.data_format.exp_offset = cropped.data_format.exp_offset; + downsized_cropped.data_format.exp_bits = cropped.data_format.exp_bits; + downsized_cropped.pitch = ROUND_UP(downsized_cropped.shape.w * (1 << downsized_cropped.data_format.datasize), 32); + downsized_cropped.color_space = cropped.color_space; + + downsized_cropped_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; + + { + downsized_cropped.data_addr = downsized_cropped_mem.phys; + // vproc_memcpy(downsized_cropped.data_addr, cropped.data_addr, downsized_cropped_mem.size); + + downsized_cropped_mem.size = downsized_cropped.shape.p * downsized_cropped.shape.d * downsized_cropped.shape.h * downsized_cropped.pitch; + + if (vproc_resize(&cropped, &downsized_cropped) < 0) { + printf("[cropped roi ivs] vproc_resize(&cropped, &downsized_cropped) failed.\n"); + if (pNext_plate->image_id >= 0) { + pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); + g_downsized_cropped_shape_w[pNext_plate->image_id] = 0; + g_downsized_cropped_pitch[pNext_plate->image_id] = 0; + g_downsized_cropped_shape_h[pNext_plate->image_id] = 0; + pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); + } + } + else + { + pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); + //printf("[cropped roi] Copying resized cropped image from the memory...\n"); + //printf("\n-----------downsized_cropped_mem.size: %d\n", (int)downsized_cropped_mem.size); + + + //memset(g_img_buf[pNext_plate->image_id], 0x00, MAX_IMG_SIZE); + + if (downsized_cropped_mem.size != 0 && pNext_plate->image_id >= 0) { + memcpy(g_img_buf[pNext_plate->image_id], downsized_cropped_mem.virt, downsized_cropped_mem.size); + + g_downsized_cropped_shape_w[pNext_plate->image_id] = downsized_cropped.shape.w; + g_downsized_cropped_pitch[pNext_plate->image_id] = downsized_cropped.pitch; + g_downsized_cropped_shape_h[pNext_plate->image_id] = downsized_cropped.shape.h; + + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0 && g_IsPTZDevice == 0) { + int color_size = -1; //convert_to_general_image_for_lprmemcpyC + pNext_plate->color_id = convert_to_general_image_for_lpr(NULL, &color_size, g_img_buf[pNext_plate->image_id], g_downsized_cropped_shape_w[pNext_plate->image_id], g_downsized_cropped_pitch[pNext_plate->image_id], g_downsized_cropped_shape_h[pNext_plate->image_id], 0, &pNext_plate->sec_color_id); + } + else { + pNext_plate->color_id = 0; + pNext_plate->sec_color_id = 0; + } + + downsized_cropped_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; + check_first_downsized_cropped_roi = 1; + + } + else { + if (pNext_plate->image_id >= 0) { + g_downsized_cropped_shape_w[pNext_plate->image_id] = 0; + g_downsized_cropped_pitch[pNext_plate->image_id] = 0; + g_downsized_cropped_shape_h[pNext_plate->image_id] = 0; + } + } + + + pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); + } + } + // Color Detection from 416x416 CNN size - Added by LILIN Cayman - 2021.4.15 - End + } + pthread_mutex_unlock(&mutex_enable_lpr_db); + } + } + else if (!IsANPRCategory(pNext_plate->engine_type) && + strcmp(SystemSetting.enable_display_properties, "Yes") == 0 && + //iFeature_logo_layer_index == -1 && + g_IsPTZDevice == 0) + { + + pthread_mutex_lock(&mutex_differ_image); + + if ((int)snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + int color_size = -1; //crop_image_ivsmemcpyC + pNext_plate->color_id = crop_image_ivs(NULL, &color_size, snapshot_addr, (int)snapshot_size, pNext_plate, g_ori_yuv_width, g_ori_yuv_height); + pNext_plate->sec_color_id = 0; + } + else { + pNext_plate->color_id = 0; + pNext_plate->sec_color_id = 0; + } + + pthread_mutex_unlock(&mutex_differ_image); + + check_first_downsized_cropped_roi_for_object = 1; + } + else + { + pNext_plate->color_id = 0; + pNext_plate->sec_color_id = 0; + } + } +#endif + //printf("\n--------cropped roi:----------7\n"); + } +} + + +void *run_one_net_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("run_one_net"); + + uint32_t net_num = g_pctrl_run_one_net->net_num; + uint32_t label_name_idx = 0; + uint32_t valid_bbox_idx = 0; + detection_pos *pNext_word = NULL; + detection_pos *pNext_ivs = NULL; + +#ifdef GY_OS_AMBA + int ret = 0; + int bbox_ret = 0; + uint32_t valid_bbox_idx_alphabet = 0; + detection_pos *pNext_alphabet = NULL; +#endif + for (int idx = 0; idx < net_num; idx++) + { + if (g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_TRAF_DET && ( + g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIFLOW || + g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIAREA || + g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AICAP + )) { + if (iFeature_traf_det_layer_index == -1) { + iFeature_traf_det_layer_index = idx; + iFeature_finial_index = idx; + } + else { + if (strcmp(WeightFileModeName, "mod004") == 0) { + iFeature_traf_det_layer_index_2 = idx; + iFeature_finial_index = idx; + } + } + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_TRAF_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) { + iFeature_garbage_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_TRAF_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIAREO)) { + iFeature_aero_det_layer_index = idx; + iFeature_finial_index = idx; + } + else if (g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_ACCESS_CTRL) { + iFeature_access_ctrl_det_layer_index[index_access] = idx; + index_access++; + iFeature_finial_index = idx; + } + else if (g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_AIFIRE) { + iFeature_aifire_det_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_HUM_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AITOF)) { + iFeature_tof_det_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_HUM_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIMASK)) { + iFeature_mask_layer_index = idx; + if (strcmp(WeightFileModeName, "mod003") == 0) { + + } + else { + iFeature_finial_index = idx; + } + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_HUM_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIHELM)) { + iFeature_safety_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_AIRAIL) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIFLOW)) { + iFeature_rail_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_TRAF_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AISPORTS) && strcmp(WeightFileModeName, "mod002") == 0) { + iFeature_sports_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_HUM_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AISHIP)) { + iFeature_ship_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_HUM_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIPRODUCTION)) { + iFeature_production_layer_index = idx; + iFeature_finial_index = idx; + } + else if ((g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_HUM_DET) && + (g_stAMBAcontent.i_amba_LayerFeatureType2[idx] & FEATURE_AIAML)) { + iFeature_animal_layer_index = idx; + iFeature_finial_index = idx; + } + else if (g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_LPR_LOGO) { + iFeature_logo_layer_index = idx; + } + } + //printf("\n----------run one net thread: %d\n", 22); + + int count_check_dn = 0; + + struct timeval currtime_switch_day_or_night; + static long last_ms_switch_day_or_night = 0; + int check_if_switch_day_or_night = 0; + + /*float record_avg_spider_zone[MAX_SPIDER_ZONE] = { 0.0 }; + int count_num_spider_zone[MAX_SPIDER_ZONE] = { 0}; + int check_if_clear_spider_zone = 0; + + for (int index_spider = 0; index_spider < MAX_SPIDER_ZONE; index_spider++) { + record_avg_spider_zone[index_spider] = 0.0; + count_num_spider_zone[index_spider] = 0; + }*/ + + struct timeval currtime; + gettimeofday(&currtime, NULL); + long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + long last_ms = now_ms; + + while (live_mode_flag && + (iFeature_traf_det_layer_index >= 0 || + iFeature_traf_det_layer_index_2 >= 0 || + index_access >= 1 || + iFeature_aifire_det_layer_index >= 0 || + iFeature_aero_det_layer_index >= 0 || + iFeature_mask_layer_index >= 0 || + iFeature_safety_layer_index >= 0 || + iFeature_rail_layer_index >= 0 || + iFeature_sports_layer_index >= 0 || + iFeature_animal_layer_index >= 0 || + iFeature_tof_det_layer_index >= 0 || + iFeature_garbage_layer_index >= 0 || + iFeature_production_layer_index >= 0 || + iFeature_ship_layer_index >= 0)) { + //gettimeofday(&currtime, NULL); + //printf("\n------------------run_one_net start 11\n"); + //run_one_netj61@ + + //int check_if_wait_differ = 0; + + int condition_number = 0; + if (viewChannelData[0].enable_traffic && g_pctrl_run_one_net != NULL){ + + gettimeofday(&currtime, NULL); + now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + double dw_FPS_time_delta = (double)(now_ms - last_ms); + dw_FPS_time_delta = fabs(dw_FPS_time_delta); + + long temp_last_ms = now_ms; + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && g_check_sync_differ == 0) + { + condition_number = 1; + //check_if_wait_differ = 1; + } + else if (g_check_sync_traffic == 0 && dw_FPS_time_delta < 333.0/*&& switch_traffic == 1*/ && strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) + { + condition_number = 2; + set_record_process_note("traffic_start_2"); + pthread_mutex_lock(&mutex_run_one_net); + //memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + //g_total_element_size_traffic = 0; +#if 0 + if(dw_FPS_time_delta >= 250.0) + { + for (int i = 0; i < g_total_element_size_traffic; i++) { + pNext_word = g_PosInfo_traffic + i; + int check_if_center = check_if_object_in_ivs_zone(pNext_word->center_x, pNext_word->center_y, pNext_word->width, pNext_word->height, g_ori_yuv_width, g_ori_yuv_height, 1); + if (check_if_center == 1) { + for (int j = i; j < g_total_element_size_traffic; j++) { + if (j < g_total_element_size_traffic - 1) { + g_PosInfo_traffic[j] = g_PosInfo_traffic[j + 1]; + } + } + i--; + g_total_element_size_traffic--; + } + } + } +#endif + + memset(&g_PosInfo_ivs, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_ivs = 0; + pthread_mutex_unlock(&mutex_run_one_net); + + switch_traffic = 0; + g_check_sync_traffic = 1; + set_record_process_note("traffic_end_2"); + } + else if (g_check_sync_traffic == 0 /*&& switch_traffic == 1*/) + { + condition_number = 3; + set_record_process_note("traffic_start"); + last_ms = now_ms; + if (strlen(viewChannelData[0].getnetwork_buffer_id) >= 1) { + int buffer_id = atoi(viewChannelData[0].getnetwork_buffer_id); + + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + pthread_mutex_lock(&mutex_run_one_net); + pthread_mutex_lock(&mutex_get_network_input); + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + size_t snapshot_size = 0; + snapshot_size = get_g_canvas_addr(snapshot_addr); + + memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_traffic = 0; + + gettimeofday(&currtime_switch_day_or_night, NULL); + long current_ms_switch_day_or_night = (currtime_switch_day_or_night.tv_sec * 1000) + (currtime_switch_day_or_night.tv_usec / 1000); + + count_check_dn++; + if (count_check_dn >= 10) { + count_check_dn = 0; + get_image_dn(); + } + + for (int i = 0; i < MAX_SIZE_SWITCH_HAPPENED; i++) { + if (imageDnData.check_if_switch_happened[i] == 1) { + check_if_switch_day_or_night = 1; + last_ms_switch_day_or_night = current_ms_switch_day_or_night; + break; + } + } + + if (last_ms_switch_day_or_night == 0 || (check_if_switch_day_or_night == 1 && (current_ms_switch_day_or_night - last_ms_switch_day_or_night) > 5000)) { + check_if_switch_day_or_night = 0; + last_ms_switch_day_or_night = current_ms_switch_day_or_night; + } + + for (int idx = 0; idx < net_num && check_if_switch_day_or_night == 0; idx++) + { + + if ((idx == iFeature_traf_det_layer_index && strcmp(WeightFileModeName, "mod004") != 0) || + (idx == iFeature_traf_det_layer_index && strcmp(WeightFileModeName, "mod004") == 0 && iFeature_traf_det_layer_index_2 == -1) || + (idx == iFeature_traf_det_layer_index && strcmp(WeightFileModeName, "mod004") == 0 && (buffer_id == 2 || buffer_id == 3)) || + (idx == iFeature_traf_det_layer_index_2 && strcmp(WeightFileModeName, "mod004") == 0 && (buffer_id == 0 || buffer_id == 1)) || + idx == iFeature_access_ctrl_det_layer_index[0] || + idx == iFeature_access_ctrl_det_layer_index[1] || + idx == iFeature_access_ctrl_det_layer_index[2] || + idx == iFeature_access_ctrl_det_layer_index[3] || + idx == iFeature_aifire_det_layer_index || + idx == iFeature_aero_det_layer_index || + (idx == iFeature_mask_layer_index && strcmp(WeightFileModeName, "mod003") != 0) || + idx == iFeature_safety_layer_index || + idx == iFeature_rail_layer_index || + idx == iFeature_sports_layer_index || + idx == iFeature_animal_layer_index || + idx == iFeature_tof_det_layer_index || + idx == iFeature_garbage_layer_index || + idx == iFeature_production_layer_index || + idx == iFeature_ship_layer_index) + { + g_element_size_traffic[idx][0] = 0; + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0){ + //printf("\n-------g_total_element_size_ivs:%d\n", g_total_element_size_ivs); + + //if (g_check_sync_differ == 1) + { + int index_ivs = 0; + detection_pos temp_PosInfo_ivs = { 0 }; + + //if (strcmp(viewChannelData[0].enable_ivs_and_ai, "Yes") != 0) + { + index_ivs = -1; + } + + for (; index_ivs < 0 && index_ivs < g_total_element_size_ivs && snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1; index_ivs++) + { + if (index_ivs >= 0) { + pNext_ivs = g_PosInfo_ivs + index_ivs; + } + else { + pNext_ivs = &temp_PosInfo_ivs; + } + + if (index_ivs >= 0) { + if (pNext_ivs->number_row == 1) { + continue; + } + + if (pNext_ivs->width * pNext_ivs->height / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.001 || + pNext_ivs->width * pNext_ivs->height / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) > 0.94) { + continue; + } + } + else { + pNext_ivs->left_x = g_ori_yuv_width * 0.025; + pNext_ivs->top_y = g_ori_yuv_height * 0.225; + pNext_ivs->width = g_ori_yuv_width * 0.95; + pNext_ivs->height = g_ori_yuv_height * 0.775; + } + + //printf("\n--------%f\n", pNext_ivs->width * pNext_ivs->height / ((float)g_ori_yuv_width * (float)g_ori_yuv_height)); + + cropped_roi_ivs(pNext_ivs, &g_pctrl_run_one_net->net_pair[idx], 0, snapshot_addr, snapshot_size); + ret = run_one_net(&g_pctrl_run_one_net->net_pair[idx]); + if (ret < 0) { + live_mode_flag = 0; + printf("serial run one net idx #1: %d err\n", idx); + break; + } + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_ivs,g_pctrl_run_one_net, idx, frame_id, 0.1); + if (bbox_ret < 0) + { + printf("parse bbox err idx #2: %d \n", idx); + break; + } + g_element_size_traffic[idx][0] += g_pctrl_run_one_net->net_pair[idx].valid_result_num; + g_total_element_size_traffic += g_pctrl_run_one_net->net_pair[idx].valid_result_num; + + //printf("\n------left_x:%f,top_y:%f,width:%f,height:%f\n", pNext_ivs->left_x, pNext_ivs->top_y, pNext_ivs->width, pNext_ivs->height); + + //printf("\n-----KK#1-------g_element_size_traffic[idx][0]:%d\n", g_element_size_traffic[idx][0]); + //printf("\n-----#1---------g_pctrl_run_one_net->net_pair[idx].yolov3_result_num:%d\n", g_pctrl_run_one_net->net_pair[idx].yolov3_result_num); + + valid_bbox_idx = 0; + for (int i = 0; i < g_pctrl_run_one_net->net_pair[idx].yolov3_result_num; i++) { + if (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min) > 0 + + ) + { + + #ifdef GY_OS_AMBA + pNext_word = g_PosInfo_traffic + valid_bbox_idx + (g_total_element_size_traffic - g_pctrl_run_one_net->net_pair[idx].valid_result_num); + pNext_word->class_id = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].label; + label_name_idx = g_pctrl_run_one_net->net_pair[idx].objects_id[i]; + #else + pNext_word = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx; + pNext_word->class_id = g_current_bbox_list[i].class_id; + label_name_idx = pNext_word->class_id; + #endif + + memset(pNext_word->name, 0x00, sizeof(pNext_word->name)); + + + #ifdef GY_OS_AMBA + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", g_pctrl_run_one_net->net_pair[idx].classNames[label_name_idx * 2]); + pNext_word->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0; + + pNext_word->left_x = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min; + pNext_word->top_y = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min; + pNext_word->width = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min); + pNext_word->height = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min); + + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2; + #else + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", G_nnctrl.net_pair[idx].classNames[(label_name_idx * 2)]); + pNext_word->confidence = g_current_bbox_list[i].confidence; + pNext_word->class_score = g_current_bbox_list[i].class_score; + pNext_word->object_score = g_current_bbox_list[i].object_score; + pNext_word->left_x = g_current_bbox_list[i].x; + pNext_word->top_y = g_current_bbox_list[i].y; + pNext_word->width = g_current_bbox_list[i].w; + pNext_word->height = g_current_bbox_list[i].h; + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2.0; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2.0; + #endif + pNext_word->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[idx];//layerFeatureType[layer_idx]; + pNext_word->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[idx]; + + pNext_word->parent_idx = -1; + pNext_word->car_logo_idx = -1; + pNext_word->number_row = 1; + + pNext_word->box_x = pNext_word->left_x; + pNext_word->box_y = pNext_word->top_y; + pNext_word->box_w = pNext_word->width; + pNext_word->box_h = pNext_word->height; + pNext_word->obj_type = _PLATE; + pNext_word->test_id = i; + + #if 1 + if ((((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < 0.0001) || + (((pNext_word->width) / ((float)g_ori_yuv_width)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->width) / ((float)g_ori_yuv_width)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext_word->height) / ((float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->height) / ((float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + strlen(pNext_word->name) == 0 || + strncmp(pNext_word->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_word->name, "_s", strlen("_s")) == 0 || + //pNext_word->center_y / (float)g_ori_yuv_height < 0.053 || + ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && strcmp(pNext_word->name, "person") != 0 && g_IsHelm_without_car == 1) || + strcmp(pNext_word->name, "male") == 0 || strcmp(pNext_word->name, "female") == 0 || strcmp(pNext_word->name, "third_gender") == 0 || + (strcmp(SystemSetting.enable_cloud, "No") == 0 && (strcmp(pNext_word->name, "camera") == 0 || strcmp(pNext_word->name, "nvr") == 0 || + strcmp(pNext_word->name, "smog") == 0 || strcmp(pNext_word->name, "robber_mask") == 0 + || strcmp(pNext_word->name, "coat_shirt") == 0 || strcmp(pNext_word->name, "shorts") == 0 || strcmp(pNext_word->name, "dress_skirt") == 0 || strcmp(pNext_word->name, "trousers") == 0 || strcmp(pNext_word->name, "golf_cart") == 0 + || strcmp(pNext_word->name, "stroller") == 0 || strcmp(pNext_word->name, "snow") == 0 || strcmp(pNext_word->name, "backpack") == 0 || strcmp(pNext_word->name, "handbag") == 0 + || strcmp(pNext_word->name, "suitcase") == 0 || strcmp(pNext_word->name, "knife") == 0 + || (strcmp(pNext_word->name, "glasses") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + || strcmp(pNext_word->name, "gun") == 0)) || + pNext_word->width / pNext_word->height > 5.0 || + pNext_word->height / pNext_word->width > 5.0 || + (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "cat") == 0 || strcmp(pNext_word->name, "dog") == 0)) + ) + { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } + #endif + + if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bus") == 0 || strcmp(pNext_word->name, "train") == 0 || strcmp(pNext_word->name, "truck") == 0)) { + strcpy(pNext_word->name,"car"); + pNext_word->class_id = 2; + } + + if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bicycle") == 0 || strcmp(pNext_word->name, "motorbike") == 0)) { + if (g_check_if_OK_thermal == 1) { + strcpy(pNext_word->name, "person"); + pNext_word->class_id = 0; + } + else { + if (strcmp(pNext_word->name, "motorbike") == 0){ + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } + } + } + + if (pNext_word->height / pNext_word->width < 1.25 && strcmp(pNext_word->name, "person") == 0) { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } + + /*if (imageDnData.color_mode == 2 && strcmp(pNext_word->name, "person") == 0) { + check_if_clear_spider_zone = 1; + + int ratio_width = (int)((pNext_word->left_x + pNext_word->width / 2.0) * 4.0 / (float)g_ori_yuv_width); + int ratio_height = (int)((pNext_word->top_y + pNext_word->height / 2.0) * 4.0 / (float)g_ori_yuv_height); + + if (ratio_width > 3) + ratio_width = 3; + if (ratio_height > 3) + ratio_height = 3; + + int index_spider_zone = ratio_width + 4 * ratio_height; + + float temp_record_avg_spider_zone = (record_avg_spider_zone[index_spider_zone] * count_num_spider_zone[index_spider_zone] + pNext_word->width * pNext_word->height) / (count_num_spider_zone[index_spider_zone] + 1); + + record_avg_spider_zone[index_spider_zone] = temp_record_avg_spider_zone; + count_num_spider_zone[index_spider_zone]++; + if (count_num_spider_zone[index_spider_zone] > 33) { + count_num_spider_zone[index_spider_zone] = 33; + } + if (record_avg_spider_zone[index_spider_zone] > 0.0) { + float ratio_area_threshold = fabs((pNext_word->width * pNext_word->height) / record_avg_spider_zone[index_spider_zone] - 1.0); + + if (ratio_area_threshold < 0.4 && ratio_area_threshold >= 0.1) { + pNext_word->confidence -= (ratio_area_threshold * 100.0); + } + else if (ratio_area_threshold >= 0.4) { + pNext_word->confidence -= 40.0; + } + } + } + else if (imageDnData.color_mode != 2) { + if (check_if_clear_spider_zone == 1) { + check_if_clear_spider_zone = 0; + for (int index_spider_zone = 0; index_spider_zone < MAX_SPIDER_ZONE; index_spider_zone++) { + count_num_spider_zone[index_spider_zone] = 0; + record_avg_spider_zone[index_spider_zone] = 0.0; + } + } + }*/ + + if (strcmp(pNext_word->name, "barcode") == 0 || strcmp(pNext_word->name, "qrcode") == 0) { + current_image_id_for_anpr++; + if (current_image_id_for_anpr >= MAX_PLATE_BUF_NUM) { + current_image_id_for_anpr = 0; + } + pNext_word->image_id = current_image_id_for_anpr; + } + else { + + current_image_id_for_object++; + if (current_image_id_for_object >= MAX_OBJECT_NUM) { + current_image_id_for_object = 0; + } + pNext_word->image_id = current_image_id_for_object; + } + + #if 0 + printf("\n[run one net thread]-------------pNext_word->name:%s,pNext_word->box_x:%f,pNext_word->box_y:%f,pNext_word->box_w:%f,pNext_word->box_h:%f\n", pNext_word->name, pNext_word->box_x, pNext_word->box_y, pNext_word->box_w, pNext_word->box_h); + #endif + + if (idx == iFeature_traf_det_layer_index && iFeature_logo_layer_index >= 0) { + if (IsVehicleCategory(pNext_word)) + { + #if 1 + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index]); + + if (ret < 0) { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("serial run one net iFeature_logo_layer_index #2: %d err\n", iFeature_logo_layer_index); + memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_traffic = 0; + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; + + //stop_test_nn_cavalry(); + //stop_server(); + + //printf("=======>>>>> 33333 \n"); + //g_rval = -2; + + //live_mode_flag = 0; + break; + + //exit(EXIT_FAILURE); + } + + //printf("\n-----------------------------parse bbox data: #2\n"); + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_logo_layer_index, frame_id, 0.3); + //printf("\n-----------------------------parse bbox data end: #2\n"); + + if (bbox_ret < 0) + { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_logo_layer_index #222: %d \n", iFeature_logo_layer_index); + + continue; + } + + valid_bbox_idx_alphabet = 0; + for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].yolov3_result_num; j++) + { + + if (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 + + ) + { + pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; + label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].objects_id[j]; + memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark + + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; + + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_logo_layer_index];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_logo_layer_index]; + + pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; + pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; + + pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min); + pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min); + pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; + pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; + pNext_alphabet->car_logo_idx = valid_bbox_idx; + pNext_alphabet->parent_idx = -1; + pNext_alphabet->number_row = 1; + pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].label; + + pNext_alphabet->box_x = pNext_alphabet->left_x; + + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + pNext_alphabet->obj_type = _PLATE; + + pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); + + #if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); + #endif + + if ( + strlen(pNext_alphabet->name) == 0 || + strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 + ) + { + memset(pNext_alphabet, 0x00, sizeof(detection_pos)); + continue; + } + + valid_bbox_idx_alphabet++; + } + + } + + //g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].valid_result_num; + //g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; + g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + #endif + + } + } + else if (idx == iFeature_production_layer_index && IsProductionCategory(pNext_word)) + { + // class_id : 1 , name : barcode + // class_id : 6 , name : qrcode + //printf("======================================\n"); + //printf("========== class_id: %d \n", pNext_word->class_id); + //printf("========== name: %s \n", pNext_word->name); + //joy + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_production_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + // ǤJ qrcode barcode + unsigned char* imageDataPtr = (const unsigned char*)g_img_buf_for_barode[pNext_word->image_id]; + //printf("========== imageDataPtr: %p \n", imageDataPtr); + //printf("========== croppedImageWidth: %d \n", croppedImageWidth); + //printf("========== croppedImageHeight: %d \n", croppedImageHeight); + //printf("========== croppedImagePitch: %d \n", croppedImagePitch); + if (strcmp(pNext_word->name, "qrcode") == 0) { + char qrcodeResult[512] = { 0 }; + readQRCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, qrcodeResult); + //printf("========== qrcodeResult: %s \n", qrcodeResult); + if (strlen(qrcodeResult)>=1) { + strcpy(pNext_word->code_content, qrcodeResult); + strcpy(pNext_word->properties.plate, qrcodeResult); + } + else { + strcpy(pNext_word->code_content, ""); + strcpy(pNext_word->properties.plate, ""); + } + } + else if (strcmp(pNext_word->name, "barcode") == 0) { + char barcodeResult[512] = { 0 }; + readBarCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, barcodeResult); + //printf("========== barcodeResult: %s \n", barcodeResult); + if (strlen(barcodeResult)>=1) { + strcpy(pNext_word->code_content, barcodeResult); + strcpy(pNext_word->properties.plate, barcodeResult); + } + else { + strcpy(pNext_word->code_content, ""); + strcpy(pNext_word->properties.plate, ""); + } + } + + + } + else if (strcmp(WeightFileModeName, "mod003") == 0 && idx == iFeature_traf_det_layer_index && iFeature_mask_layer_index >= 0 && strcmp(pNext_word->name, "person") == 0) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index]); + + if (ret < 0) { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("serial run one net iFeature_mask_layer_index #2: %d err\n", iFeature_mask_layer_index); + memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_traffic = 0; + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; + + //stop_test_nn_cavalry(); + //stop_server(); + + //printf("=======>>>>> 33333 \n"); + //g_rval = -2; + + //live_mode_flag = 0; + break; + + //exit(EXIT_FAILURE); + } + + //printf("\n-----------------------------parse bbox data: #2\n"); + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_mask_layer_index, frame_id, 0.3); + //printf("\n-----------------------------parse bbox data end: #2\n"); + + if (bbox_ret < 0) + { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_mask_layer_index #222: %d \n", iFeature_mask_layer_index); + + continue; + } + + valid_bbox_idx_alphabet = 0; + for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].yolov3_result_num; j++) + { + + if (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 + + ) + { + pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; + label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].objects_id[j]; + memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark + + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; + + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_mask_layer_index];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_mask_layer_index]; + + pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; + pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; + + pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) / g_ori_yuv_width * pNext_word->width; + pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) / g_ori_yuv_height * pNext_word->height; + pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; + pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; + pNext_alphabet->car_logo_idx = valid_bbox_idx; + pNext_alphabet->parent_idx = -1; + pNext_alphabet->number_row = 1; + pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].label; + + pNext_alphabet->box_x = pNext_alphabet->left_x; + + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + pNext_alphabet->obj_type = _PLATE; + + pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); + + #if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); + #endif + + if ( + strlen(pNext_alphabet->name) == 0 || + strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 + ) + { + memset(pNext_alphabet, 0x00, sizeof(detection_pos)); + continue; + } + + valid_bbox_idx_alphabet++; + } + + } + + //g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].valid_result_num; + //g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; + g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; + g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; + } + else if ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && iFeature_logo_layer_index == -1) { + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[idx], valid_bbox_idx, snapshot_addr, snapshot_size); + } + } + + valid_bbox_idx++; + } + } + } + memset(&g_PosInfo_ivs, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_ivs = 0; + if (ret < 0) { + break; + } + if (bbox_ret < 0) + { + continue; + } + } + } + else { + + ret = run_one_net(&g_pctrl_run_one_net->net_pair[idx]); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----run one net thread #3:%lf ms\n", dw_FPS_time_delta); + + if (ret < 0) { + live_mode_flag = 0; + printf("serial run one net idx #3: %d err\n", idx); + break; + } + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(NULL,g_pctrl_run_one_net, idx, frame_id, 0.1); + + if (bbox_ret < 0) + { + printf("parse bbox err idx #4: %d \n", idx); + continue; + } + g_element_size_traffic[idx][0] = g_pctrl_run_one_net->net_pair[idx].valid_result_num; + g_total_element_size_traffic += g_element_size_traffic[idx][0]; + + //printf("\n-----KK#2-------g_element_size_traffic[idx][0]:%d\n", g_element_size_traffic[idx][0]); + //printf("\n-----#2---------g_pctrl_run_one_net->net_pair[idx].yolov3_result_num:%d\n", g_pctrl_run_one_net->net_pair[idx].yolov3_result_num); + + valid_bbox_idx = 0; + for (int i = 0; i < g_pctrl_run_one_net->net_pair[idx].yolov3_result_num; i++) { + if (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min) > 0 + + ) + { + +#ifdef GY_OS_AMBA + pNext_word = g_PosInfo_traffic + valid_bbox_idx + (g_total_element_size_traffic - g_element_size_traffic[idx][0]); + pNext_word->class_id = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].label; + label_name_idx = g_pctrl_run_one_net->net_pair[idx].objects_id[i]; +#else + pNext_word = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx; + pNext_word->class_id = g_current_bbox_list[i].class_id; + label_name_idx = pNext_word->class_id; +#endif + + memset(pNext_word->name, 0x00, sizeof(pNext_word->name)); + +#ifdef GY_OS_AMBA + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", g_pctrl_run_one_net->net_pair[idx].classNames[label_name_idx * 2]); + pNext_word->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0; + + pNext_word->left_x = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min; + pNext_word->top_y = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min; + pNext_word->width = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min); + pNext_word->height = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min); + + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2; +#else + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", G_nnctrl.net_pair[idx].classNames[(label_name_idx * 2)]); + pNext_word->confidence = g_current_bbox_list[i].confidence; + pNext_word->class_score = g_current_bbox_list[i].class_score; + pNext_word->object_score = g_current_bbox_list[i].object_score; + pNext_word->left_x = g_current_bbox_list[i].x; + pNext_word->top_y = g_current_bbox_list[i].y; + pNext_word->width = g_current_bbox_list[i].w; + pNext_word->height = g_current_bbox_list[i].h; + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2.0; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2.0; +#endif + pNext_word->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[idx];//layerFeatureType[layer_idx]; + pNext_word->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[idx]; + + pNext_word->parent_idx = -1; + pNext_word->car_logo_idx = -1; + pNext_word->number_row = 1; + + pNext_word->box_x = pNext_word->left_x; + pNext_word->box_y = pNext_word->top_y; + pNext_word->box_w = pNext_word->width; + pNext_word->box_h = pNext_word->height; + pNext_word->obj_type = _PLATE; + pNext_word->test_id = i; + +#if 1 + if ((((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext_word->width) / ((float)g_ori_yuv_width)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->width) / ((float)g_ori_yuv_width)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext_word->height) / ((float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->height) / ((float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + strlen(pNext_word->name) == 0 || + strncmp(pNext_word->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_word->name, "_s", strlen("_s")) == 0 || + //pNext_word->center_y / (float)g_ori_yuv_height < 0.053 || + ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && strcmp(pNext_word->name, "person") != 0 && g_IsHelm_without_car == 1) || + strcmp(pNext_word->name, "male") == 0 || strcmp(pNext_word->name, "female") == 0 || strcmp(pNext_word->name, "third_gender") == 0 || + (strcmp(SystemSetting.enable_cloud, "No") == 0 && (strcmp(pNext_word->name, "camera") == 0 || strcmp(pNext_word->name, "nvr") == 0 || + strcmp(pNext_word->name, "smog") == 0 || strcmp(pNext_word->name, "robber_mask") == 0 + || strcmp(pNext_word->name, "coat_shirt") == 0 || strcmp(pNext_word->name, "shorts") == 0 || strcmp(pNext_word->name, "dress_skirt") == 0 || strcmp(pNext_word->name, "trousers") == 0 || strcmp(pNext_word->name, "golf_cart") == 0 + || strcmp(pNext_word->name, "stroller") == 0 || strcmp(pNext_word->name, "snow") == 0 || strcmp(pNext_word->name, "backpack") == 0 || strcmp(pNext_word->name, "handbag") == 0 + || strcmp(pNext_word->name, "suitcase") == 0 || strcmp(pNext_word->name, "knife") == 0 + || (strcmp(pNext_word->name, "glasses") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + || strcmp(pNext_word->name, "gun") == 0)) || + (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "cat") == 0 || strcmp(pNext_word->name, "dog") == 0)) + ) + { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } +#endif + + if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bus") == 0 || strcmp(pNext_word->name, "train") == 0 || strcmp(pNext_word->name, "truck") == 0)) { + strcpy(pNext_word->name, "car"); + pNext_word->class_id = 2; + } + + if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bicycle") == 0 || strcmp(pNext_word->name, "motorbike") == 0)) { + if (g_check_if_OK_thermal == 1) { + strcpy(pNext_word->name, "person"); + pNext_word->class_id = 0; + } + else { + if (strcmp(pNext_word->name, "motorbike") == 0) { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } + } + } + + if (pNext_word->height / pNext_word->width < 1.25 && strcmp(pNext_word->name, "person") == 0) { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } + + /*if (imageDnData.color_mode == 2 && strcmp(pNext_word->name, "person") == 0) { + check_if_clear_spider_zone = 1; + + int ratio_width = (int)((pNext_word->left_x + pNext_word->width / 2.0) * 4.0 / (float)g_ori_yuv_width); + int ratio_height = (int)((pNext_word->top_y + pNext_word->height / 2.0) * 4.0 / (float)g_ori_yuv_height); + + if (ratio_width > 3) + ratio_width = 3; + if (ratio_height > 3) + ratio_height = 3; + + int index_spider_zone = ratio_width + 4 * ratio_height; + + float temp_record_avg_spider_zone = (record_avg_spider_zone[index_spider_zone] * count_num_spider_zone[index_spider_zone] + pNext_word->width * pNext_word->height) / (count_num_spider_zone[index_spider_zone] + 1); + + record_avg_spider_zone[index_spider_zone] = temp_record_avg_spider_zone; + count_num_spider_zone[index_spider_zone]++; + if (count_num_spider_zone[index_spider_zone] > 33) { + count_num_spider_zone[index_spider_zone] = 33; + } + if (record_avg_spider_zone[index_spider_zone] > 0.0) { + float ratio_area_threshold = fabs((pNext_word->width * pNext_word->height) / record_avg_spider_zone[index_spider_zone] - 1.0); + + if (ratio_area_threshold < 0.4 && ratio_area_threshold >= 0.1) { + pNext_word->confidence -= (ratio_area_threshold * 100.0); + } + else if (ratio_area_threshold >= 0.4) { + pNext_word->confidence -= 40.0; + } + } + } + else if (imageDnData.color_mode != 2) { + if (check_if_clear_spider_zone == 1) { + check_if_clear_spider_zone = 0; + for (int index_spider_zone = 0; index_spider_zone < MAX_SPIDER_ZONE; index_spider_zone++) { + count_num_spider_zone[index_spider_zone] = 0; + record_avg_spider_zone[index_spider_zone] = 0.0; + } + } + }*/ + + if (strcmp(pNext_word->name, "barcode") == 0 || strcmp(pNext_word->name, "qrcode") == 0) { + current_image_id_for_anpr++; + if (current_image_id_for_anpr >= MAX_PLATE_BUF_NUM) { + current_image_id_for_anpr = 0; + } + pNext_word->image_id = current_image_id_for_anpr; + } + else { + + current_image_id_for_object++; + if (current_image_id_for_object >= MAX_OBJECT_NUM) { + current_image_id_for_object = 0; + } + pNext_word->image_id = current_image_id_for_object; + } + + #if 0 + printf("\n[run one net thread]-------------pNext_word->name:%s,pNext_word->box_x:%f,pNext_word->box_y:%f,pNext_word->box_w:%f,pNext_word->box_h:%f\n", pNext_word->name, pNext_word->box_x, pNext_word->box_y, pNext_word->box_w, pNext_word->box_h); + #endif + + /*if (idx == iFeature_tof_det_layer_index) { + float bbox_distance = 0.0; + float bbox_height = 0.0; + get_bbox_distance_and_height(pNext_word->left_x, pNext_word->top_y, pNext_word->width, pNext_word->height, &bbox_distance, &bbox_height); + + pNext_word->bbox_distance = bbox_distance; + pNext_word->bbox_height = bbox_height; + + //printf("\nTTTTTTTTTTTTTTTTT: %f,%f\n", pNext_word->bbox_distance, pNext_word->bbox_height); + + } + else */if (idx == iFeature_traf_det_layer_index && iFeature_logo_layer_index >= 0) { + if (IsVehicleCategory(pNext_word)) + { + #if 1 + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index]); + + if (ret < 0) { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("serial run one net iFeature_logo_layer_index #2: %d err\n", iFeature_logo_layer_index); + memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_traffic = 0; + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; + + //stop_test_nn_cavalry(); + //stop_server(); + + //printf("=======>>>>> 33333 \n"); + //g_rval = -2; + + //live_mode_flag = 0; + break; + + //exit(EXIT_FAILURE); + } + + //printf("\n-----------------------------parse bbox data: #2\n"); + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_logo_layer_index, frame_id, 0.3); + //printf("\n-----------------------------parse bbox data end: #2\n"); + + if (bbox_ret < 0) + { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_logo_layer_index #222: %d \n", iFeature_logo_layer_index); + + continue; + } + + valid_bbox_idx_alphabet = 0; + for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].yolov3_result_num; j++) + { + + if (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 + + ) + { + pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; + label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].objects_id[j]; + memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark + + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; + + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_logo_layer_index];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_logo_layer_index]; + + pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; + pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; + + pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min); + pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min); + pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; + pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; + pNext_alphabet->car_logo_idx = valid_bbox_idx; + pNext_alphabet->parent_idx = -1; + pNext_alphabet->number_row = 1; + pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].label; + + pNext_alphabet->box_x = pNext_alphabet->left_x; + + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + pNext_alphabet->obj_type = _PLATE; + + pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); + + #if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); + #endif + + if ( + strlen(pNext_alphabet->name) == 0 || + strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 + ) + { + memset(pNext_alphabet, 0x00, sizeof(detection_pos)); + continue; + } + + valid_bbox_idx_alphabet++; + } + + } + + //g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].valid_result_num; + //g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; + g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + } + #endif + + } + } + else if (idx == iFeature_production_layer_index && IsProductionCategory(pNext_word)) + { + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + // class_id : 1 , name : barcode + // class_id : 6 , name : qrcode + //printf("======================================\n"); + //printf("========== class_id: %d \n", pNext_word->class_id); + //printf("========== name: %s \n", pNext_word->name); + //joy + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_production_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + // ǤJ qrcode barcode + unsigned char* imageDataPtr = (const unsigned char*)g_img_buf_for_barode[pNext_word->image_id]; + //printf("========== imageDataPtr: %p \n", imageDataPtr); + //printf("========== croppedImageWidth: %d \n", croppedImageWidth); + //printf("========== croppedImageHeight: %d \n", croppedImageHeight); + //printf("========== croppedImagePitch: %d \n", croppedImagePitch); + if (strcmp(pNext_word->name, "qrcode") == 0) { + char qrcodeResult[512] = { 0 }; + readQRCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, qrcodeResult); + //printf("========== qrcodeResult: %s \n", qrcodeResult); + if (strlen(qrcodeResult)>=1) { + strcpy(pNext_word->code_content, qrcodeResult); + strcpy(pNext_word->properties.plate, qrcodeResult); + } + else { + strcpy(pNext_word->code_content, ""); + strcpy(pNext_word->properties.plate, ""); + } + } + else if (strcmp(pNext_word->name, "barcode") == 0) { + char barcodeResult[512] = { 0 }; + readBarCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, barcodeResult); + //printf("========== barcodeResult: %s \n", barcodeResult); + if (strlen(barcodeResult)>=1) { + strcpy(pNext_word->code_content, barcodeResult); + strcpy(pNext_word->properties.plate, barcodeResult); + } + else { + strcpy(pNext_word->code_content, ""); + strcpy(pNext_word->properties.plate, ""); + } + } + + } + } + else if (strcmp(WeightFileModeName, "mod003") == 0 && idx == iFeature_traf_det_layer_index && iFeature_mask_layer_index >= 0 && strcmp(pNext_word->name, "person") == 0) { + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index]); + + if (ret < 0) { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("serial run one net iFeature_mask_layer_index #2: %d err\n", iFeature_mask_layer_index); + memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_traffic = 0; + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; + + //stop_test_nn_cavalry(); + //stop_server(); + + //printf("=======>>>>> 33333 \n"); + //g_rval = -2; + + //live_mode_flag = 0; + break; + + //exit(EXIT_FAILURE); + } + + //printf("\n-----------------------------parse bbox data: #2\n"); + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_mask_layer_index, frame_id, 0.3); + //printf("\n-----------------------------parse bbox data end: #2\n"); + + if (bbox_ret < 0) + { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_mask_layer_index #222: %d \n", iFeature_mask_layer_index); + + continue; + } + + valid_bbox_idx_alphabet = 0; + for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].yolov3_result_num; j++) + { + + if (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 + + ) + { + pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; + label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].objects_id[j]; + memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark + + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; + + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_mask_layer_index];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_mask_layer_index]; + + pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; + pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; + + pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) / g_ori_yuv_width * pNext_word->width; + pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) / g_ori_yuv_height * pNext_word->height; + pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; + pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; + pNext_alphabet->car_logo_idx = valid_bbox_idx; + pNext_alphabet->parent_idx = -1; + pNext_alphabet->number_row = 1; + pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].label; + + pNext_alphabet->box_x = pNext_alphabet->left_x; + + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + pNext_alphabet->obj_type = _PLATE; + + pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); + + #if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); + #endif + + if ( + strlen(pNext_alphabet->name) == 0 || + strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 + ) + { + memset(pNext_alphabet, 0x00, sizeof(detection_pos)); + continue; + } + + valid_bbox_idx_alphabet++; + } + + } + + //g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].valid_result_num; + //g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; + g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; + g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; + } + } + else if ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && iFeature_logo_layer_index == -1) { + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[idx], valid_bbox_idx, snapshot_addr, snapshot_size); + } + } + } + + valid_bbox_idx++; + } + } + } + + //printf("\n--------------valid_bbox_idx:%d\n", valid_bbox_idx); + + //printf("\n---------g_element_size_traffic[idx][0]:%d\n", g_element_size_traffic[idx][0]); + + if (g_total_element_size_traffic >= 1) + g_pctrl_run_one_net->net_pair[idx].valid_result_num = g_element_size_traffic[idx][0]; + else + g_pctrl_run_one_net->net_pair[idx].valid_result_num = 0; + } + } + + //printf("=======>>>>> 44444 \n"); + //printf("total size = %d \n", g_total_element_size_traffic); + + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + + switch_traffic = 0; + g_check_sync_traffic = 1; + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----run one net thread:%lf ms\n", dw_FPS_time_delta); + //last_ms = now_ms; + } + set_record_process_note("traffic_end"); + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - temp_last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + + //if(condition_number == 2 || condition_number == 3) + //printf("\n-----run one net thread end:num:%d,time:%lf ms\n", condition_number, dw_FPS_time_delta); + } + + //gettimeofday(&currtime, NULL); + //printf("\n------------------run_one_net end:%d usecs\n", (int)currtime.tv_usec); + if (viewChannelData[0].enable_traffic){ + //if (check_if_wait_differ == 1) { + //usSleep(100); + //} + if (condition_number == 0) { + usSleep(30000); + } + else if (condition_number == 1) { + usSleep(40000); + } + else if (condition_number == 2) { + usSleep(100); + } + else if (condition_number == 3) { + usSleep(100); + } + else { + usSleep(USLEEP_RUN_ONE_NET_THREAD); + } + } + else + usSleep(5000000); + } + + //if (g_rval == -2) + //{ + //ʧ@ + //} + //printf("=======>>>>> 66666 \n"); + + pthread_exit(NULL); +} + +//struct timeval currtime_control_alarm_gpio; +//static long last_ms_control_alarm_gpio = 0; + +void *run_one_net_thread_anpr(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("run_one_anpr"); + //printf("\n----------run one net thread anpr: %d\n", 1); + + + uint32_t label_name_idx = 0; + uint32_t valid_bbox_idx = 0; + uint32_t valid_bbox_idx_alphabet = 0; + detection_pos *pNext_word = NULL; + detection_pos *pNext_alphabet = NULL; + uint32_t net_num = g_pctrl_run_one_net_anpr->net_num; +#ifdef GY_OS_AMBA + int ret = 0; + detection_pos *pNext_alphabet_temp = NULL; +#endif + for (int idx = 0; idx < net_num; idx++) + { + if (IsANPRCategory_notcode(g_stAMBAcontent.i_amba_LayerFeatureType[idx])) { +#ifdef GY_OS_AMBA + if (g_stAMBAcontent.i_amba_LayerFeatureType[idx] & FEATURE_LPR_AUS) { + magnification_ratio = 0.04; + } + else { + magnification_ratio = 0.02; + } +#endif + iFeature_lpr_layer_index = idx; + break; + } + } + + int tracking_channel_idx = 0; + + int first_loop = 0; +#ifdef GY_OS_AMBA + int check_set_quality_basic = 0; +#endif + //printf("\n----------run one net thread anpr: %d\n", 2); + int check_if_control_alarm_gpio_OK = 1; + + while (live_mode_flag && iFeature_lpr_layer_index >= 0) { + +#ifdef GY_OS_AMBA + if (iFeature_lpr_layer_index >= 0 && viewChannelData[0].enable_anpr && check_set_quality_basic == 0) { + pthread_t auto_set_quality_basic_thread_id; + if (pthread_create(&auto_set_quality_basic_thread_id, 0, auto_set_quality_basic, NULL)) + { + printf("create auto_set_quality_basic thread faile \n"); + } + check_set_quality_basic = 1; + } + else if (iFeature_lpr_layer_index >= 0 && !(viewChannelData[0].enable_anpr)) { + check_set_quality_basic = 0; + } +#endif + + +#if 1 + //gettimeofday(&currtime_control_alarm_gpio, NULL); + //long current_ms_control_alarm_gpio = (currtime_control_alarm_gpio.tv_sec * 1000) + (currtime_control_alarm_gpio.tv_usec / 1000); + + + //if (last_ms_control_alarm_gpio == 0) { + //last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + //} + +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR == 0) +#endif + { + + if(strcmp(viewChannelData[tracking_channel_idx].enable_lpr_upon_triggered, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + //gettimeofday(&currtime_control_alarm_gpio, NULL); + //long current_ms_control_alarm_gpio = (currtime_control_alarm_gpio.tv_sec * 1000) + (currtime_control_alarm_gpio.tv_usec / 1000); + + if (get_g_control_alarm_gpio() == 1) { + //if (current_ms_control_alarm_gpio >= last_ms_control_alarm_gpio + atoi(viewChannelData[tracking_channel_idx].dwell_lpr_upon_triggered) * 1000) + { + //set_g_control_alarm_gpio_to_zero(); + check_if_control_alarm_gpio_OK = 1; + //last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + //else { + //check_if_control_alarm_gpio_OK = 0; + //} + } + else if(get_g_control_alarm_gpio() == 0){ + check_if_control_alarm_gpio_OK = 0; + //last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + } + else if (strcmp(viewChannelData[tracking_channel_idx].enable_lpr_upon_triggered, "No") == 0) { + check_if_control_alarm_gpio_OK = 1; + //last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; + } + } +#endif + + //gettimeofday(&currtime, NULL); + //printf("\n------------------run_one_net 2 start:%d usecs\n", (int)currtime.tv_usec); + //printf("\n----------run one net thread anpr: %d\n", 3); + if (iFeature_lpr_layer_index >= 0 && viewChannelData[0].enable_anpr && g_pctrl_run_one_net_anpr != NULL) { + if (g_check_sync_anpr == 0 && switch_anpr == 1) { + //printf("\n----------run one net thread anpr: %d\n", 4); + //printf("\nyuv2rgb_out_mem.size:%d\n", yuv2rgb_out_mem.size); + set_record_process_note("anpr_start"); + pthread_mutex_lock(&mutex_run_one_net); + pthread_mutex_lock(&mutex_get_network_input); + + //sync_cache_mem(yuv2rgb_out_mem.size, yuv2rgb_out_mem.phys, 1, 0);//clean + //sync_cache_mem(downsized_cropped_mem.size, downsized_cropped_mem.phys, 1, 0);//clean + //sync_cache_mem(tof_img_mem.size, tof_img_mem.phys, 1, 0);//clean + //sync_cache_mem(snap_hd_mem.size, snap_hd_mem.phys, 1, 0);//clean + //sync_cache_mem(barcode_img_mem.size, barcode_img_mem.phys, 1, 0);//clean + + //printf("\n----------run one net thread anpr: %d\n", 4441); + + memset(&g_PosInfo, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size = 0; + + //printf("\n----------run one net thread anpr: %d\n", 4443); + ret = run_one_net(&g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index]); + //printf("\n----------run one net thread anpr: %d\n", 41); + +#if 1 + if (ret < 0) { + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + + live_mode_flag = 0; + + printf("serial run one net iFeature_lpr_layer_index #1: %d err\n", iFeature_lpr_layer_index); + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; + + //stop_test_nn_cavalry(); + //stop_server(); + + //exit(EXIT_FAILURE); + break; + } + + //printf("\n-----------------------------parse bbox data: #1\n"); + if(g_pctrl_run_one_net_anpr != NULL) + g_bbox_ret = parse_bbox_data(NULL,g_pctrl_run_one_net_anpr, iFeature_lpr_layer_index, frame_id,0.3); + //printf("\n-----------------------------parse bbox data end: #1\n"); + if (g_bbox_ret < 0) + { + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_lpr_layer_index #2: %d \n", iFeature_lpr_layer_index); + continue; + } + //printf("\n----------run one net thread anpr: %d\n", 42); + g_element_size[iFeature_lpr_layer_index][0] = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].valid_result_num; + g_total_element_size += g_element_size[iFeature_lpr_layer_index][0]; + + valid_bbox_idx = 0; + + /* + float temp_left_x = 0; + float temp_top_y = 0; + float temp_width = 0; + float temp_height = 0; + */ + + for (int i = 0; i < g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].yolov3_result_num; i++) { + if (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].valid && + (float)sqrt((double)g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].score * (double)100)*10.0 > g_stAMBAcontent.confidence_plate && + g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.y_min > 0 && + g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.x_min > 0 && + (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.x_min) > 0 && + (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.y_min) > 0 + ) + { + //printf("\n----------run one net thread anpr: %d\n", 4211); + pNext_word = g_PosInfo + valid_bbox_idx; + //printf("\n----------run one net thread anpr: %d\n", 4212); + label_name_idx = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].objects_id[i]; + memset(pNext_word->name, 0x00, sizeof(pNext_word->name)); + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].classNames[label_name_idx * 2]); + + pNext_word->confidence = (float)sqrt((double)g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].score * (double)100)*10.0; + + pNext_word->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_lpr_layer_index];//layerFeatureType[layer_idx]; + pNext_word->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_lpr_layer_index]; + + pNext_word->left_x = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.x_min; + pNext_word->top_y = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.y_min; + pNext_word->width = (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.x_min); + pNext_word->height = (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].bbox.y_min); + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2; + pNext_word->parent_idx = -1; + pNext_word->car_logo_idx = -1; + pNext_word->number_row = 1; + pNext_word->class_id = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].amba_yolov3_result[i].label; + + /* + temp_left_x = pNext_word->left_x; + temp_top_y = pNext_word->top_y; + temp_width = pNext_word->width; + temp_height = pNext_word->height;*/ + + pNext_word->box_x = pNext_word->left_x; + pNext_word->box_y = pNext_word->top_y; + pNext_word->box_w = pNext_word->width; + pNext_word->box_h = pNext_word->height; + pNext_word->obj_type = _PLATE; + pNext_word->test_id = i; + + current_image_id_for_anpr++; + if (current_image_id_for_anpr >= MAX_PLATE_BUF_NUM) { + current_image_id_for_anpr = 0; + } + + + //printf("\n----------run one net thread anpr: %d\n", 4213); + if ( + strlen(pNext_word->name) == 0 || + strncmp(pNext_word->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_word->name, "_s", strlen("_s")) == 0 || + pNext_word->center_y / (float)g_ori_yuv_height < 0.053 || + (strcmp(SystemSetting.enable_cloud, "No") == 0 && (strcmp(pNext_word->name, "stop_sign") == 0)) + ) + { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } + + pNext_word->image_id = current_image_id_for_anpr; + + //printf("\n----------run one net thread anpr: %d\n", 4214); + int checkisInside = check_if_object_in_zone(pNext_word->center_x, pNext_word->center_y, pNext_word->width, pNext_word->height, g_ori_yuv_width, g_ori_yuv_height, 1); + + //printf("\n--------checkisInside:%d\n", checkisInside); + //printf("\n----------run one net thread anpr: %d\n", 4215); + if (checkisInside == 1 || first_loop == 0 || viewChannelData[tracking_channel_idx].count_zone == 0) { + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "[Time]%04d-%02d-%02d %02d:%02d:%02d:%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + + memset(g_debug_plate, 0x00, sizeof(g_debug_plate)); + sprintf(g_debug_plate,"%s[Plate]%s,x:%f,y:%f,w:%f,h:%f", buf_time_info, pNext_word->name, pNext_word->box_x, + pNext_word->box_y, pNext_word->box_w, pNext_word->box_h); + +#if 0 + printf("\n-------------pNext_word->name:%s,pNext_word->box_x:%f,pNext_word->box_y:%f,pNext_word->box_w:%f,pNext_word->box_h:%f,pNext_word->confidence:%f\n", pNext_word->name, pNext_word->box_x, + pNext_word->box_y, pNext_word->box_w, pNext_word->box_h, pNext_word->confidence); +#endif + + + if (strcmp(viewChannelData[tracking_channel_idx].enable_blank_plate, "No") == 0) { + if (strcmp(pNext_word->name, "ambulance") != 0 && strcmp(pNext_word->name, "stop_sign") != 0 && check_if_control_alarm_gpio_OK == 1) { + + //printf("\n----------run one net thread anpr: %d\n", 43); + size_t snapshot_size = 0; + char snapshot_addr[10] = { 0 }; + cropped_roi(pNext_word, &g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1], valid_bbox_idx, snapshot_addr, snapshot_size); + //printf("\n----------run one net thread anpr: %d\n", 44); + ret = run_one_net(&g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1]); + //printf("\n----------run one net thread anpr: %d\n", 45); + if (ret < 0) { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("serial run one net iFeature_lpr_layer_index+1 #2: %d err\n", iFeature_lpr_layer_index + 1); + memset(&g_PosInfo, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size = 0; + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; + //stop_test_nn_cavalry(); + //stop_server(); + + //exit(EXIT_FAILURE); + break; + } + + //parent_index = total_element_size - element_size[idx - 1]; + //for (int k = 0; k < g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].valid_result_num; k++) { + //pNext1 = pNext_t + k; + //pNext2 = PosInfo + total_element_size; + //printf("\n-----------------------------parse bbox data: #2\n"); + //printf("\n----------run one net thread anpr: %d\n", 46); + if (g_pctrl_run_one_net_anpr != NULL) + g_bbox_ret = parse_bbox_data(pNext_word,g_pctrl_run_one_net_anpr, iFeature_lpr_layer_index + 1, frame_id,0.1); + //printf("\n-----------------------------parse bbox data end: #2\n"); + //printf("\n----------run one net thread anpr: %d\n", 47); + if (g_bbox_ret < 0) + { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_lpr_layer_index+1 #222: %d \n", iFeature_lpr_layer_index + 1); + + continue; + } + //printf("\n----------run one net thread anpr: %d\n", 48); + valid_bbox_idx_alphabet = 0; + + float sum_confidence_for_pNext_word = 0; + float count_alphabet = 0; + float count_wrong_alphabet = 0; + char char_plate[BUFSIZE_V2]; + for (int j = 0; j < g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].yolov3_result_num; j++) + { + if (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].valid) + { + + if ((float)sqrt((double)g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].score * (double)100)*10.0 <= g_stAMBAcontent.confidence_plate) { + count_wrong_alphabet++; + continue; + } + + pNext_alphabet = g_PosInfo + g_total_element_size + valid_bbox_idx_alphabet; + + label_name_idx = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].objects_id[j]; + memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].classNames[label_name_idx * 2]); //20201022 sophia mark + + if (strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 || + strlen(pNext_alphabet->name) == 0 || + strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0) { + continue; + } + + pNext_alphabet->left_x = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.x_min; + pNext_alphabet->top_y = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.y_min; + pNext_alphabet->width = (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.x_min); + pNext_alphabet->height = (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.y_min); + + pNext_alphabet->box_x = pNext_alphabet->left_x; + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].score * (double)100)*10.0; + + + for (int index_alphabet = 0; index_alphabet < valid_bbox_idx_alphabet; index_alphabet++) { + pNext_alphabet_temp = g_PosInfo + g_total_element_size + index_alphabet; + if (detection_overlap_ratio(pNext_alphabet, pNext_alphabet_temp) > (90.0 / 100.0)) { + + for (int index_alphabet_temp = index_alphabet; index_alphabet_temp < valid_bbox_idx_alphabet - 1; index_alphabet_temp++) { + pNext_alphabet_temp = g_PosInfo + g_total_element_size + index_alphabet_temp; + + sum_confidence_for_pNext_word -= pNext_alphabet_temp->confidence; + pNext_alphabet_temp->confidence = (pNext_alphabet_temp + 1)->confidence; + pNext_alphabet_temp->left_x = (pNext_alphabet_temp + 1)->left_x; + pNext_alphabet_temp->top_y = (pNext_alphabet_temp + 1)->top_y; + pNext_alphabet_temp->width = (pNext_alphabet_temp + 1)->width; + pNext_alphabet_temp->height = (pNext_alphabet_temp + 1)->height; + pNext_alphabet_temp->box_x = (pNext_alphabet_temp + 1)->box_x; + pNext_alphabet_temp->box_y = (pNext_alphabet_temp + 1)->box_y; + pNext_alphabet_temp->box_w = (pNext_alphabet_temp + 1)->box_w; + pNext_alphabet_temp->box_h = (pNext_alphabet_temp + 1)->box_h; + + memset(pNext_alphabet_temp->name, 0x00, sizeof(pNext_alphabet_temp->name)); + strcpy(pNext_alphabet_temp->name, (pNext_alphabet_temp + 1)->name); + + + pNext_alphabet_temp->engine_type = (pNext_alphabet_temp + 1)->engine_type; + pNext_alphabet_temp->engine_type2 = (pNext_alphabet_temp + 1)->engine_type2; + pNext_alphabet_temp->center_x = (pNext_alphabet_temp + 1)->center_x; + pNext_alphabet_temp->center_y = (pNext_alphabet_temp + 1)->center_y; + pNext_alphabet_temp->parent_idx = (pNext_alphabet_temp + 1)->parent_idx; + pNext_alphabet_temp->number_row = (pNext_alphabet_temp + 1)->number_row; + pNext_alphabet_temp->class_id = (pNext_alphabet_temp + 1)->class_id; + pNext_alphabet_temp->obj_type = (pNext_alphabet_temp + 1)->obj_type; + } + + valid_bbox_idx_alphabet--; + count_alphabet--; + + pNext_alphabet = g_PosInfo + g_total_element_size + valid_bbox_idx_alphabet; + pNext_alphabet->left_x = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.x_min; + pNext_alphabet->top_y = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.y_min; + pNext_alphabet->width = (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.x_min); + pNext_alphabet->height = (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].bbox.y_min); + + pNext_alphabet->box_x = pNext_alphabet->left_x; + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + + + count_wrong_alphabet++; + } + + break; + + } + + + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_lpr_layer_index + 1];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_lpr_layer_index + 1]; + + pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; + pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; + pNext_alphabet->parent_idx = -1; + pNext_alphabet->number_row = 1; + pNext_alphabet->class_id = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].amba_yolov3_result[j].label; + + pNext_alphabet->obj_type = _PLATE; + + memset(char_plate, 0x00, sizeof(char_plate)); + sprintf(char_plate, "[Alphabet]%s,x:%f,y:%f,w:%f,h:%f", pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->top_y, pNext_alphabet->width, pNext_alphabet->height); + strcat(g_debug_plate, char_plate); + +#if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f,pNext_alphabet->class_id:%d\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence, pNext_alphabet->class_id); +#endif + + + sum_confidence_for_pNext_word += pNext_alphabet->confidence; + /*if (sum_confidence_for_pNext_word == 0 || sum_confidence_for_pNext_word > pNext_alphabet->confidence) { + sum_confidence_for_pNext_word = pNext_alphabet->confidence; + }*/ + + +#if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f,pNext_alphabet->class_id:%d\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence, pNext_alphabet->class_id); +#endif + + valid_bbox_idx_alphabet++; + count_alphabet++; + } + } + + if (count_alphabet >= 1) { + pNext_word->confidence = sum_confidence_for_pNext_word / (count_alphabet + count_wrong_alphabet * 0.5); + //pNext_word->confidence = sum_confidence_for_pNext_word; + + g_element_size[iFeature_lpr_layer_index + 1][valid_bbox_idx] = g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].valid_result_num; + g_total_element_size += g_element_size[iFeature_lpr_layer_index + 1][valid_bbox_idx]; + //printf("\n----------run one net thread anpr: %d\n", 49); + //assign_row_number(PosInfo, pNext1, pNext2, total_element_size, element_size[idx], parent_index + i, &arc); + //if (g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index + 1].valid_result_num >= 1) { + valid_bbox_idx++; + first_loop = 1; + //} + } + } + else if (strcmp(pNext_word->name, "ambulance") == 0 || strcmp(pNext_word->name, "stop_sign") == 0) { + g_element_size[iFeature_lpr_layer_index + 1][valid_bbox_idx] = 0; + g_total_element_size += g_element_size[iFeature_lpr_layer_index + 1][valid_bbox_idx]; + valid_bbox_idx++; + first_loop = 1; + } + } + else { + strcpy(pNext_word->name,"blank"); + strcpy(pNext_word->properties.plate, "blank"); + g_element_size[iFeature_lpr_layer_index + 1][valid_bbox_idx] = 0; + g_total_element_size += g_element_size[iFeature_lpr_layer_index + 1][valid_bbox_idx]; + valid_bbox_idx++; + first_loop = 1; + } + } + } + } + + if (g_total_element_size >= 1) + g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].valid_result_num = valid_bbox_idx; + else + g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].valid_result_num = 0; + +#if 0 + if (g_total_element_size <= 6 && g_total_element_size >= 1) { + printf("\n------/emmc/plugin/Aida_data/storage/rgb_\n"); + { + char img_name[512] = { 0 }; + sprintf(img_name, "/emmc/plugin/Aida_data/storage/rgb_x_%f_y_%f_w_%f_h_%f.bin", temp_left_x, temp_top_y, temp_width, temp_height); + store_bin(img_name, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt); + printf("store_bin(...) for output_name finished.\n"); + } + } +#endif +#endif + + //sync_cache_mem(yuv2rgb_out_mem.size, yuv2rgb_out_mem.phys, 0, 1);//invalid + //sync_cache_mem(downsized_cropped_mem.size, downsized_cropped_mem.phys, 0, 1);//invalid + //sync_cache_mem(tof_img_mem.size, tof_img_mem.phys, 0, 1);//invalid + //sync_cache_mem(snap_hd_mem.size, snap_hd_mem.phys, 0, 1);//invalid + //sync_cache_mem(barcode_img_mem.size, barcode_img_mem.phys, 0, 1);//invalid + + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + + switch_anpr = 0; + g_check_sync_anpr = 1; + set_record_process_note("anpr_end"); + } + } + //gettimeofday(&currtime, NULL); + //printf("\n------------------run_one_net 2 end:%d usecs\n", (int)currtime.tv_usec); + //printf("\n----------run one net thread anpr: %d\n", 5); + + if (iFeature_lpr_layer_index >= 0 && viewChannelData[0].enable_anpr) + usSleep(USLEEP_RUN_ONE_NET_THREAD); + else + usSleep(5000000); + } + + //printf("\n----------run one net thread anpr: %d\n", 7); + pthread_exit(NULL); +} + +#if defined GY_OS_AMBA +void *differ_image_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("differ_image"); + + int change_status_for_not_AutoTracking = 0; + int tracking_channel_idx = 0; + + detection_pos *pNext_word = NULL; + detection_pos *pNext_word_temp = NULL; + + int count_check = 0; + int count_check_dn = 0; + + while (live_mode_flag) { + if (iFeature_traf_det_layer_index >= 0 || + iFeature_traf_det_layer_index_2 >= 0 || + index_access >= 1 || + iFeature_aifire_det_layer_index >= 0 || + iFeature_aero_det_layer_index >= 0 || + iFeature_mask_layer_index >= 0 || + iFeature_safety_layer_index >= 0 || + iFeature_rail_layer_index >= 0 || + iFeature_sports_layer_index >= 0 || + iFeature_animal_layer_index >= 0 || + iFeature_ship_layer_index >= 0 || + iFeature_production_layer_index >= 0 || + iFeature_garbage_layer_index >= 0 || + iFeature_lpr_layer_index >= 0) { + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && viewChannelData[0].enable_traffic) + { + g_check_if_differ_image_is_running = 1; + + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + int condition_number = 0; + if (g_check_sync_differ == 0 && switch_differ == 1) { + set_record_process_note("differ_start_1"); + //printf("\n--------------differ image 1\n"); + + pthread_mutex_lock(&mutex_run_one_net); + pthread_mutex_lock(&mutex_get_network_input); + + size_t snapshot_size = 0; + char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + snapshot_size = get_g_canvas_addr(snapshot_addr); + + //printf("\n--------------differ image 11\n"); + + //printf("\n--------------differ image 12\n"); + memset(&g_PosInfo_differ, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_differ = 0; + //printf("\n--------------differ image 2\n"); + + if ((int)snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + + int not_to_show_tempering = 1; + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + for (int m = 0; m < MAX_TRIGGER_EVENT; m++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); + + if (trigger_event_type == TRIGGER_TAMPERING) + { + not_to_show_tempering = 0; + } + } + } + } + + if (not_to_show_tempering == 0) { + count_check_dn++; + if (count_check_dn >= 50) { + count_check_dn = 0; + //get_image_dn(); + } + } + + int size_output = -1; + //printf("\n----------change_status_for_not_AutoTracking:start:%d,not_to_show_tempering:%d\n", change_status_for_not_AutoTracking, not_to_show_tempering); + int temp_g_total_element_size_differ = 0; + + if (strcmp(viewChannelData[0].ivs_mode, "3") == 0) { + temp_g_total_element_size_differ = mog2_image(NULL, &size_output, snapshot_addr, (int)snapshot_size, g_PosInfo_differ, g_ori_yuv_width, g_ori_yuv_height, 0, 0, &change_status_for_not_AutoTracking, not_to_show_tempering); + } + else { + pthread_mutex_lock(&mutex_compute_median); + temp_g_total_element_size_differ = differ_image(NULL, &size_output, snapshot_addr, (int)snapshot_size, g_PosInfo_differ, g_ori_yuv_width, g_ori_yuv_height, 0, 0, &change_status_for_not_AutoTracking, not_to_show_tempering); + pthread_mutex_unlock(&mutex_compute_median); + } + //printf("\n----------change_status_for_not_AutoTracking:end:%d,not_to_show_tempering:%d\n", change_status_for_not_AutoTracking, not_to_show_tempering); + +#if 1 + for (int i = 0; i < temp_g_total_element_size_differ; i++) + { + for (int j = 0; j < temp_g_total_element_size_differ; j++) + { + if (i == j) { + continue; + } + else { + + pNext_word = g_PosInfo_differ + i; + pNext_word_temp = g_PosInfo_differ + j; + + if (pNext_word->width == 0 || + pNext_word->height == 0 || + pNext_word_temp->width == 0 || + pNext_word_temp->height == 0 || + pNext_word->number_row == 1 || + pNext_word_temp->number_row == 1) + continue; + else { + if (detection_overlap_ratio(pNext_word, pNext_word_temp) > 0.0) { + float left_x_a = pNext_word->left_x; + float top_y_a = pNext_word->top_y; + float right_x_a = pNext_word->left_x + pNext_word->width; + float bottom_y_a = pNext_word->top_y + pNext_word->height; + + float left_x_b = pNext_word_temp->left_x; + float top_y_b = pNext_word_temp->top_y; + float right_x_b = pNext_word_temp->left_x + pNext_word_temp->width; + float bottom_y_b = pNext_word_temp->top_y + pNext_word_temp->height; + + float left_x_new = 0.0; + float top_y_new = 0.0; + float right_x_new = 0.0; + float bottom_y_new = 0.0; + + if (left_x_a < left_x_b) { + left_x_new = left_x_a; + } + else { + left_x_new = left_x_b; + } + + if (top_y_a < top_y_b) { + top_y_new = top_y_a; + } + else { + top_y_new = top_y_b; + } + + if (right_x_a > right_x_b) { + right_x_new = right_x_a; + } + else { + right_x_new = right_x_b; + } + + if (bottom_y_a > bottom_y_b) { + bottom_y_new = bottom_y_a; + } + else { + bottom_y_new = bottom_y_b; + } + + pNext_word->left_x = left_x_new; + pNext_word->top_y = top_y_new; + pNext_word->width = right_x_new - left_x_new; + pNext_word->height = bottom_y_new - top_y_new; + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2.0; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2.0; + + pNext_word_temp->width = 0; + pNext_word_temp->height = 0; + } + } + } + } + } +#endif + + for (int i = 0; i < temp_g_total_element_size_differ; i++) + { + pNext_word = g_PosInfo_differ + i; + if (pNext_word->width <= 0 || pNext_word->height <= 0) { + for (int j = i; j < temp_g_total_element_size_differ - 1; j++) { + g_PosInfo_differ[j] = g_PosInfo_differ[j + 1]; + } + i--; + temp_g_total_element_size_differ--; + } + } + + //if (temp_g_total_element_size_differ > 25) { + //temp_g_total_element_size_differ = 25; + //} + + int check_if_given_value_ivs = 0; + if (g_total_element_size_ivs == 0) { + for (int i = 0; i < temp_g_total_element_size_differ; i++) { + pNext_word = g_PosInfo_differ + i; + pNext_word_temp = g_PosInfo_ivs + i; + pNext_word_temp->left_x = pNext_word->left_x;//1.0 + pNext_word_temp->top_y = pNext_word->top_y;//1000.0 + pNext_word_temp->width = pNext_word->width;//1900.0 + pNext_word_temp->height = pNext_word->height;//1000.0 + pNext_word_temp->center_x = pNext_word->center_x; + pNext_word_temp->center_y = pNext_word->center_y; + pNext_word_temp->number_row = pNext_word->number_row; + } + check_if_given_value_ivs = 1; + } + + if (g_check_if_OK_thermal == 0 && g_IsPTZDevice == 1 && strcmp(SystemSetting.enable_crop_mode, "Yes") == 0 && g_ori_yuv_height >= 1 && g_ori_yuv_width >= 1 && g_framesize_height >= 1 && g_framesize_width >= 1) { + for (int i = 0; i < temp_g_total_element_size_differ; i++) { + pNext_word = g_PosInfo_differ + i; + pNext_word_temp = g_PosInfo_ivs + i; + float temp_framsize_height = (float)g_framesize_height; + float temp_framsize_width = (float)g_framesize_width; + float temp_g_ori_yuv_height = (float)g_ori_yuv_height; + float temp_g_ori_yuv_width = (float)g_ori_yuv_width; + float temp_standard_height = 9.0; + float temp_standard_width = 16.0; + + float ratio_height_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_height / temp_framsize_height; + float ratio_width_g_ori_yuv_to_ai_webpage = temp_g_ori_yuv_width / temp_framsize_width; + + float ratio_height_standard_to_g_ori_yuv = temp_standard_height / temp_g_ori_yuv_height; + float ratio_width_standard_to_g_ori_yuv = temp_standard_width / temp_g_ori_yuv_width; + + float ratio_height_standard_to_framsize = temp_standard_height / temp_framsize_height; + float ratio_width_standard_to_framsize = temp_standard_width / temp_framsize_width; + + float thres_x_min = 0.0; + float thres_x_max = 1.0; + float thres_y_min = 0.0; + float thres_y_max = 1.0; + + float obj_x_max = (pNext_word->left_x + pNext_word->width) / temp_g_ori_yuv_width; + float obj_x_min = pNext_word->left_x / temp_g_ori_yuv_width; + + float obj_y_max = (pNext_word->top_y + pNext_word->height) / temp_g_ori_yuv_height; + float obj_y_min = pNext_word->top_y / temp_g_ori_yuv_height; + + float cut_thres_ratio_x = 1.0; + float cut_thres_ratio_y = 1.0; + + float cut_thres_ratio_g_ori_yuv_x = 1.0; + float cut_thres_ratio_g_ori_yuv_y = 1.0; + + float cut_thres_ratio_framsize_x = 1.0; + float cut_thres_ratio_framsize_y = 1.0; + + if (ratio_height_g_ori_yuv_to_ai_webpage == ratio_width_g_ori_yuv_to_ai_webpage) { + + } + else if (ratio_height_standard_to_g_ori_yuv == ratio_width_standard_to_g_ori_yuv) { + if (ratio_width_g_ori_yuv_to_ai_webpage > ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio_x = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + thres_x_min += ((1.0 - cut_thres_ratio_x) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio_x) / 2.0); + } + else if (ratio_width_g_ori_yuv_to_ai_webpage < ratio_height_g_ori_yuv_to_ai_webpage) { + cut_thres_ratio_y = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + thres_y_min += ((1.0 - cut_thres_ratio_y) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio_y) / 2.0); + } + } + else + { + float thres_x_min_g_ori_yuv = 0.0; + float thres_x_max_g_ori_yuv = 1.0; + float thres_y_min_g_ori_yuv = 0.0; + float thres_y_max_g_ori_yuv = 1.0; + + float thres_x_min_framsize = 0.0; + float thres_x_max_framsize = 1.0; + float thres_y_min_framsize = 0.0; + float thres_y_max_framsize = 1.0; + + if (ratio_width_standard_to_g_ori_yuv > ratio_height_standard_to_g_ori_yuv) { + cut_thres_ratio_g_ori_yuv_x = (temp_standard_height * temp_g_ori_yuv_width) / (temp_g_ori_yuv_height*temp_standard_width); + thres_x_min_g_ori_yuv += ((1.0 - cut_thres_ratio_g_ori_yuv_x) / 2.0); + thres_x_max_g_ori_yuv -= ((1.0 - cut_thres_ratio_g_ori_yuv_x) / 2.0); + } + else if (ratio_width_standard_to_g_ori_yuv < ratio_height_standard_to_g_ori_yuv) { + cut_thres_ratio_g_ori_yuv_y = (temp_standard_width * temp_g_ori_yuv_height) / (temp_g_ori_yuv_width*temp_standard_height); + thres_y_min_g_ori_yuv += ((1.0 - cut_thres_ratio_g_ori_yuv_y) / 2.0); + thres_y_max_g_ori_yuv -= ((1.0 - cut_thres_ratio_g_ori_yuv_y) / 2.0); + } + + if (ratio_width_standard_to_framsize > ratio_height_standard_to_framsize) { + cut_thres_ratio_framsize_x = (temp_standard_height * temp_framsize_width) / (temp_framsize_height*temp_standard_width); + thres_x_min_framsize += ((1.0 - cut_thres_ratio_framsize_x) / 2.0); + thres_x_max_framsize -= ((1.0 - cut_thres_ratio_framsize_x) / 2.0); + } + else if (ratio_width_standard_to_framsize < ratio_height_standard_to_framsize) { + cut_thres_ratio_framsize_y = (temp_standard_width * temp_framsize_height) / (temp_framsize_width*temp_standard_height); + thres_y_min_framsize += ((1.0 - cut_thres_ratio_framsize_y) / 2.0); + thres_y_max_framsize -= ((1.0 - cut_thres_ratio_framsize_y) / 2.0); + } + + if (cut_thres_ratio_g_ori_yuv_x > cut_thres_ratio_framsize_x) + { + cut_thres_ratio_x = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + thres_x_min += ((1.0 - cut_thres_ratio_x) / 2.0); + thres_x_max -= ((1.0 - cut_thres_ratio_x) / 2.0); + } + else if (cut_thres_ratio_g_ori_yuv_x < cut_thres_ratio_framsize_x) { + //cut_thres_ratio_x = (temp_g_ori_yuv_height * temp_framsize_width) / (temp_framsize_height*temp_g_ori_yuv_width); + //thres_x_min += ((1.0 - cut_thres_ratio_x) / 2.0); + //thres_x_max -= ((1.0 - cut_thres_ratio_x) / 2.0); + } + + if (cut_thres_ratio_g_ori_yuv_y > cut_thres_ratio_framsize_y) + { + cut_thres_ratio_y = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + thres_y_min += ((1.0 - cut_thres_ratio_y) / 2.0); + thres_y_max -= ((1.0 - cut_thres_ratio_y) / 2.0); + } + else if (cut_thres_ratio_g_ori_yuv_y < cut_thres_ratio_framsize_y) { + //cut_thres_ratio_y = (temp_g_ori_yuv_width * temp_framsize_height) / (temp_framsize_width*temp_g_ori_yuv_height); + //thres_y_min += ((1.0 - cut_thres_ratio_y) / 2.0); + //thres_y_max -= ((1.0 - cut_thres_ratio_y) / 2.0); + } + } + + if (ratio_height_g_ori_yuv_to_ai_webpage == ratio_width_g_ori_yuv_to_ai_webpage) { + //for (int i = 0; i < temp_g_total_element_size_differ; i++) { + //pNext_word = g_PosInfo_differ + i; + //pNext_word_temp = g_PosInfo_ivs + i; + + //int checkisInside = check_if_object_in_zone(pNext_word->center_x, pNext_word->center_y, pNext_word->width, pNext_word->height, g_ori_yuv_width, g_ori_yuv_height, 0); + + //printf("\n----------checkisInside:%d\n", checkisInside); + + //if (checkisInside == 0) { + //pNext_word_temp->width = 0.0; + //pNext_word_temp->height = 0.0; + //} + //} + } + else { + if (obj_x_max <= thres_x_min || + obj_x_min >= thres_x_max || + obj_y_max <= thres_y_min || + obj_y_min >= thres_y_max || + thres_x_min < 0.0 || thres_x_min > 1.0 || + thres_x_max < 0.0 || thres_x_max > 1.0 || + thres_y_min < 0.0 || thres_y_min > 1.0 || + thres_y_max < 0.0 || thres_y_max > 1.0 || + (thres_x_max - thres_x_min) <= 0.0 || + (thres_y_max - thres_y_min) <= 0.0) + { + pNext_word->width = 0.0; + pNext_word->height = 0.0; + pNext_word_temp->width = 0.0; + pNext_word_temp->height = 0.0; + continue; + } + else { + if (obj_x_min < thres_x_min) { + obj_x_min = thres_x_min; + } + + if (obj_x_max > thres_x_max) { + obj_x_max = thres_x_max; + } + + if (obj_y_min < thres_y_min) { + obj_y_min = thres_y_min; + } + + if (obj_y_max > thres_y_max) { + obj_y_max = thres_y_max; + } + + if (cut_thres_ratio_x < 1.0) + { + float obj_center_x = (obj_x_min + obj_x_max) / 2.0; + float obj_width = (obj_x_max - obj_x_min); + + obj_center_x = (obj_center_x - 0.5) * (1.0 / cut_thres_ratio_x) + 0.5; + obj_width = obj_width * (1.0 / cut_thres_ratio_x); + + obj_x_min = obj_center_x - obj_width / 2.0; + obj_x_max = obj_center_x + obj_width / 2.0; + } + else if (cut_thres_ratio_g_ori_yuv_x < cut_thres_ratio_framsize_x) { + float obj_center_x = (obj_x_min + obj_x_max) / 2.0; + float obj_width = (obj_x_max - obj_x_min); + + obj_center_x = (obj_center_x - 0.5) * (cut_thres_ratio_g_ori_yuv_x / cut_thres_ratio_framsize_x) + 0.5; + obj_width = obj_width * (cut_thres_ratio_g_ori_yuv_x / cut_thres_ratio_framsize_x); + + obj_x_min = obj_center_x - obj_width / 2.0; + obj_x_max = obj_center_x + obj_width / 2.0; + } + + if (cut_thres_ratio_y < 1.0) + { + float obj_center_y = (obj_y_min + obj_y_max) / 2.0; + float obj_height = (obj_y_max - obj_y_min); + + obj_center_y = (obj_center_y - 0.5) * (1.0 / cut_thres_ratio_y) + 0.5; + obj_height = obj_height * (1.0 / cut_thres_ratio_y); + + obj_y_min = obj_center_y - obj_height / 2.0; + obj_y_max = obj_center_y + obj_height / 2.0; + } + else if (cut_thres_ratio_g_ori_yuv_y < cut_thres_ratio_framsize_y) { + float obj_center_y = (obj_y_min + obj_y_max) / 2.0; + float obj_height = (obj_y_max - obj_y_min); + + obj_center_y = (obj_center_y - 0.5) * (cut_thres_ratio_g_ori_yuv_y / cut_thres_ratio_framsize_y) + 0.5; + obj_height = obj_height * (cut_thres_ratio_g_ori_yuv_y / cut_thres_ratio_framsize_y); + + obj_y_min = obj_center_y - obj_height / 2.0; + obj_y_max = obj_center_y + obj_height / 2.0; + } + + if (obj_x_min < 0.0) + obj_x_min = 0.0; + + if (obj_x_max > 1.0) + obj_x_max = 1.0; + + if (obj_y_min < 0.0) + obj_y_min = 0.0; + + if (obj_y_max > 1.0) + obj_y_max = 1.0; + + obj_x_min = obj_x_min * (float)g_ori_yuv_width; //1920 + obj_x_max = obj_x_max * (float)g_ori_yuv_width; //1920 + obj_y_min = obj_y_min * (float)g_ori_yuv_height; //1080 + obj_y_max = obj_y_max * (float)g_ori_yuv_height; //1080 + + pNext_word->left_x = obj_x_min; + pNext_word->top_y = obj_y_min; + pNext_word->width = (obj_x_max - obj_x_min); + pNext_word->height = (obj_y_max - obj_y_min); + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2.0; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2.0; + + //int checkisInside = check_if_object_in_zone(pNext_word->center_x, pNext_word->center_y, pNext_word->width, pNext_word->height, g_ori_yuv_width, g_ori_yuv_height, 0); + + //printf("\n----------checkisInside:%d\n", checkisInside); + + //if (checkisInside == 0) { + //pNext_word_temp->width = 0.0; + //pNext_word_temp->height = 0.0; + //} + } + } + } + } + else{ + //for (int i = 0; i < temp_g_total_element_size_differ; i++) { + //pNext_word = g_PosInfo_differ + i; + //pNext_word_temp = g_PosInfo_ivs + i; + + //int checkisInside = check_if_object_in_zone(pNext_word->center_x, pNext_word->center_y, pNext_word->width, pNext_word->height, g_ori_yuv_width, g_ori_yuv_height, 0); + + //printf("\n----------checkisInside:%d\n", checkisInside); + + //if (checkisInside == 0) { + //pNext_word_temp->width = 0.0; + //pNext_word_temp->height = 0.0; + //} + //} + } + + if (check_if_given_value_ivs == 1) { + g_total_element_size_ivs = temp_g_total_element_size_differ; + } + + g_total_element_size_differ = temp_g_total_element_size_differ; + +#ifdef GY_OS_AMBA + if (get_g_check_if_change_preset() == 1) { + count_check++; + if (count_check >= 50) { + count_check = 0; + set_g_check_if_change_preset_to_zero(); + } + } +#endif + +#if 0 + for (int i = 0; i < g_total_element_size_differ; i++) { + pNext_word = g_PosInfo_differ + i; + printf("\n-----------A--pNext_word->name:%s,pNext_word->box_x:%f,pNext_word->box_y:%f\n", pNext_word->name, pNext_word->box_x, pNext_word->box_y); + } +#endif + } + //printf("\n--------------differ image 3\n"); + + pthread_mutex_unlock(&mutex_get_network_input); + pthread_mutex_unlock(&mutex_run_one_net); + + switch_differ = 0; + g_check_sync_differ = 1; + + //printf("\n--------------differ image 4\n"); + set_record_process_note("differ_end_1"); + if (strcmp(viewChannelData[0].ivs_mode, "3") == 0) { + condition_number = 1; + } + else { + condition_number = 2; + } + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + + //if (condition_number == 1) + //printf("\n-----differ image thread end:num:%d,time:%lf ms\n", condition_number, dw_FPS_time_delta); + + if (condition_number == 0) { + usSleep(30000); + } + else if (condition_number == 1) { + usSleep(100); + } + else if (condition_number == 2) { + usSleep(70000); + } + } + else { + g_check_if_differ_image_is_running = 0; + usSleep(5000000); + } + } + else { + g_check_if_differ_image_is_running = 0; + usSleep(5000000); + } + } + + pthread_exit(NULL); +} +#endif + +#if defined GY_OS_AMBA +void *compute_median_thread(void *ptr) { + pthread_detach(pthread_self()); + setPthreadName("com_median"); + + while (live_mode_flag) { + if (iFeature_traf_det_layer_index >= 0 || + iFeature_traf_det_layer_index_2 >= 0 || + index_access >= 1 || + iFeature_aifire_det_layer_index >= 0 || + iFeature_aero_det_layer_index >= 0 || + iFeature_mask_layer_index >= 0 || + iFeature_safety_layer_index >= 0 || + iFeature_rail_layer_index >= 0 || + iFeature_sports_layer_index >= 0 || + iFeature_animal_layer_index >= 0 || + iFeature_tof_det_layer_index >= 0 || + iFeature_garbage_layer_index >= 0 || + iFeature_ship_layer_index >= 0 || + iFeature_production_layer_index >= 0 || + iFeature_lpr_layer_index >= 0) { + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && viewChannelData[0].enable_traffic) + { + //set_record_process_note("median_start"); + //struct timeval currtime; + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + if (strcmp(viewChannelData[0].ivs_mode, "3") == 0) { + + } + else { + if (g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + run_compute_median(); + } + } + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----compute median thread:%lf ms\n", dw_FPS_time_delta); + //last_ms = now_ms; + + //set_record_process_note("median_end"); + + //ɶӵuAקK귽@Qcompute_median_threadmC + if (strcmp(viewChannelData[0].ivs_mode, "3") == 0) { + usSleep(10000000); + } + else { + usSleep(5000000); + } + } + else + usSleep(5000000); + } + else + usSleep(5000000); + } + + pthread_exit(NULL); +} + +#endif + + +int get_g_check_if_all_existing(size_t index_zone) { + return g_check_if_all_existing[index_zone]; +} + +int get_g_check_if_NAND(size_t index_zone) { + int tracking_channel_idx = 0; + if (count_fps_for_NAND[index_zone] > AI_fps * viewDetectionZone[tracking_channel_idx][index_zone].no_parking_time) { + return g_check_if_NAND[index_zone]; + } + else { + return 0; + } +} + +void reset_g_Meta_If_Existing_for_NAND(size_t index_zone) { + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[index_zone]; index_meta++) + { + g_Meta_If_Existing_for_NAND[index_zone][index_meta] = 0; + } +} + +CPoint segmentsIntr(CPoint a, CPoint b, CPoint c, CPoint d) { + + if ((a.x == c.x && a.y == c.y) || + (a.x == d.x && a.y == d.y)) { + return a; + } + else if ((b.x == c.x && b.y == c.y) || + (b.x == d.x && b.y == d.y)) { + return b; + } + + + float area_abc = (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x); + float area_abd = (a.x - d.x) * (b.y - d.y) - (a.y - d.y) * (b.x - d.x); + + if (area_abc == 0) { + return c; + } + else if (area_abd == 0) { + return d; + } + + // + /*if (area_abc * area_abd >= 0) { + return false; + }*/ + + // + float area_cda = (c.x - a.x) * (d.y - a.y) - (c.y - a.y) * (d.x - a.x); + // + // + float area_cdb = area_cda + area_abc - area_abd; + + if (area_cdb == 0) { + return b; + } + else if (area_cda == 0) { + return a; + } + + /* + if (area_cda * area_cdb >= 0) { + return false; + }*/ + + // + + CPoint ret; + ret.x = 0; + ret.y = 0; + if (area_abd != area_abc) { + + float t = area_cda / (area_abd - area_abc); + float dx = t * (b.x - a.x), + dy = t * (b.y - a.y); + + ret.x = (a.x + dx); + ret.y = (a.y + dy); + } + return ret; +} + +void build_g_parking_space_recording(int tracking_channel_idx,int index_zone) { + + //printf("\n------g_osdSysTimeStamp:%ld\n", g_osdSysTimeStamp); + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0)) { + if (g_b_ZoneExist[index_zone]) { + if (viewDetectionZone[tracking_channel_idx][index_zone].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][index_zone].parking_line >= 1) { + int num_row = viewDetectionZone[tracking_channel_idx][index_zone].parking_line; + int num_col = (int)ceil((double)viewDetectionZone[tracking_channel_idx][index_zone].parking_space / (double)viewDetectionZone[tracking_channel_idx][index_zone].parking_line); + + int count_lot = 0; + + float s_row_x = 0; + float s_row_y = 0; + float e_row_x = 0; + float e_row_y = 0; + + float last_s_row_x = 0; + float last_s_row_y = 0; + float last_e_row_x = 0; + float last_e_row_y = 0; + + float s_col_x = 0; + float s_col_y = 0; + float e_col_x = 0; + float e_col_y = 0; + + float last_s_col_x = 0; + float last_s_col_y = 0; + float last_e_col_x = 0; + float last_e_col_y = 0; + + long d_no_parking_time = (long)viewDetectionZone[tracking_channel_idx][index_zone].no_parking_time; + + if (viewDetectionZone[tracking_channel_idx][index_zone].no_parking_time_in_minute >= 1) { + d_no_parking_time = (long)(viewDetectionZone[tracking_channel_idx][index_zone].no_parking_time_in_minute * 60); + } + + for (int index_row = 0; index_row < num_row; index_row++) { + + if (index_row == 0) { + last_s_row_x = g_zone_polygon[index_zone][1].x; + last_s_row_y = g_zone_polygon[index_zone][1].y; + last_e_row_x = g_zone_polygon[index_zone][2].x; + last_e_row_y = g_zone_polygon[index_zone][2].y; + + s_row_x = (g_zone_polygon[index_zone][1].x * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][0].x * ((float)index_row + 1)) / (float)num_row; + s_row_y = (g_zone_polygon[index_zone][1].y * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][0].y * ((float)index_row + 1)) / (float)num_row; + e_row_x = (g_zone_polygon[index_zone][2].x * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][3].x * ((float)index_row + 1)) / (float)num_row; + e_row_y = (g_zone_polygon[index_zone][2].y * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][3].y * ((float)index_row + 1)) / (float)num_row; + } + else if (index_row == num_row - 1) { + last_s_row_x = s_row_x; + last_s_row_y = s_row_y; + last_e_row_x = e_row_x; + last_e_row_y = e_row_y; + + s_row_x = g_zone_polygon[index_zone][0].x; + s_row_y = g_zone_polygon[index_zone][0].y; + e_row_x = g_zone_polygon[index_zone][3].x; + e_row_y = g_zone_polygon[index_zone][3].y; + } + else { + last_s_row_x = s_row_x; + last_s_row_y = s_row_y; + last_e_row_x = e_row_x; + last_e_row_y = e_row_y; + + s_row_x = (g_zone_polygon[index_zone][1].x * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][0].x * ((float)index_row + 1)) / (float)num_row; + s_row_y = (g_zone_polygon[index_zone][1].y * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][0].y * ((float)index_row + 1)) / (float)num_row; + e_row_x = (g_zone_polygon[index_zone][2].x * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][3].x * ((float)index_row + 1)) / (float)num_row; + e_row_y = (g_zone_polygon[index_zone][2].y * ((float)num_row - ((float)index_row + 1)) + g_zone_polygon[index_zone][3].y * ((float)index_row + 1)) / (float)num_row; + } + + for (int index_col = 0; index_col < num_col; index_col++) { + if (count_lot < viewDetectionZone[tracking_channel_idx][index_zone].parking_space) { + + if (index_col == 0) { + last_s_col_x = g_zone_polygon[index_zone][1].x; + last_s_col_y = g_zone_polygon[index_zone][1].y; + last_e_col_x = g_zone_polygon[index_zone][0].x; + last_e_col_y = g_zone_polygon[index_zone][0].y; + + s_col_x = (g_zone_polygon[index_zone][1].x * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][2].x * ((float)index_col + 1)) / (float)num_col; + s_col_y = (g_zone_polygon[index_zone][1].y * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][2].y * ((float)index_col + 1)) / (float)num_col; + e_col_x = (g_zone_polygon[index_zone][0].x * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][3].x * ((float)index_col + 1)) / (float)num_col; + e_col_y = (g_zone_polygon[index_zone][0].y * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][3].y * ((float)index_col + 1)) / (float)num_col; + } + else if (index_col == num_col - 1) { + last_s_col_x = s_col_x; + last_s_col_y = s_col_y; + last_e_col_x = e_col_x; + last_e_col_y = e_col_y; + + s_col_x = g_zone_polygon[index_zone][2].x; + s_col_y = g_zone_polygon[index_zone][2].y; + e_col_x = g_zone_polygon[index_zone][3].x; + e_col_y = g_zone_polygon[index_zone][3].y; + } + else { + last_s_col_x = s_col_x; + last_s_col_y = s_col_y; + last_e_col_x = e_col_x; + last_e_col_y = e_col_y; + + s_col_x = (g_zone_polygon[index_zone][1].x * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][2].x * ((float)index_col + 1)) / (float)num_col; + s_col_y = (g_zone_polygon[index_zone][1].y * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][2].y * ((float)index_col + 1)) / (float)num_col; + e_col_x = (g_zone_polygon[index_zone][0].x * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][3].x * ((float)index_col + 1)) / (float)num_col; + e_col_y = (g_zone_polygon[index_zone][0].y * ((float)num_col - ((float)index_col + 1)) + g_zone_polygon[index_zone][3].y * ((float)index_col + 1)) / (float)num_col; + } + + CPoint obj0 = { last_s_row_x, last_s_row_y }; + CPoint obj1 = { last_e_row_x, last_e_row_y }; + CPoint obj2 = { last_s_col_x, last_s_col_y }; + CPoint obj3 = { last_e_col_x, last_e_col_y }; + CPoint obj4 = { s_row_x, s_row_y }; + CPoint obj5 = { e_row_x, e_row_y }; + CPoint obj6 = { s_col_x, s_col_y }; + CPoint obj7 = { e_col_x, e_col_y }; + + CPoint obj_point_0 = segmentsIntr(obj0, obj1, obj2, obj3); + CPoint obj_point_1 = segmentsIntr(obj0, obj1, obj6, obj7); + CPoint obj_point_2 = segmentsIntr(obj4, obj5, obj2, obj3); + CPoint obj_point_3 = segmentsIntr(obj4, obj5, obj6, obj7); + + if (obj_point_0.x != 0 && obj_point_0.y != 0 && + obj_point_1.x != 0 && obj_point_1.y != 0 && + obj_point_2.x != 0 && obj_point_2.y != 0 && + obj_point_3.x != 0 && obj_point_3.y != 0) { + + if (g_parking_space_update_time[index_zone][count_lot] == 0) { + g_parking_space_update_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_status_change_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_check_table[index_zone][count_lot] = 0; + } + else if (g_parking_space_check_table[index_zone][count_lot] == 0 && g_temp_parking_space_check_table[index_zone][count_lot] == 1) { + g_parking_space_update_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_status_change_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_check_table[index_zone][count_lot] = 1; + } + else if (g_parking_space_check_table[index_zone][count_lot] == 1 && g_temp_parking_space_check_table[index_zone][count_lot] == 0 && + difftime(g_osdSysTimeStamp, g_parking_space_update_time[index_zone][count_lot]) >= d_no_parking_time) { + g_parking_space_update_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_status_change_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_check_table[index_zone][count_lot] = 0; + } + else if (g_parking_space_check_table[index_zone][count_lot] == 1 && g_temp_parking_space_check_table[index_zone][count_lot] == 1) { + g_parking_space_update_time[index_zone][count_lot] = g_osdSysTimeStamp; + g_parking_space_check_table[index_zone][count_lot] = 1; + } + + g_temp_parking_space_check_table[index_zone][count_lot] = 0; + + g_parking_space_recording_x[index_zone][count_lot] = (float)(obj_point_0.x + obj_point_1.x + obj_point_2.x + obj_point_3.x) / 4; + g_parking_space_recording_y[index_zone][count_lot] = (float)(obj_point_0.y + obj_point_1.y + obj_point_2.y + obj_point_3.y) / 4; + + g_parking_space_recording_x[index_zone][count_lot] = g_parking_space_recording_x[index_zone][count_lot] * (float)g_ori_yuv_width / (float)CANVAS_WIDTH; + g_parking_space_recording_y[index_zone][count_lot] = g_parking_space_recording_y[index_zone][count_lot] * (float)g_ori_yuv_height / (float)CANVAS_HEIGHT; + + count_lot++; + } + } + } + } + + for (int index_lot = count_lot; index_lot < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_lot++) { + g_parking_space_update_time[index_zone][index_lot] = g_osdSysTimeStamp; + g_parking_space_status_change_time[index_zone][index_lot] = g_osdSysTimeStamp; + g_parking_space_check_table[index_zone][index_lot] = 0; + g_temp_parking_space_check_table[index_zone][index_lot] = 0; + + g_parking_space_recording_x[index_zone][index_lot] = 0.0; + g_parking_space_recording_y[index_zone][index_lot] = 0.0; + } + + /* + printf("\n-------------start count lot\n"); + for (int index_lot = 0; index_lot < count_lot; index_lot++) { + printf("[%d],%d,%d,",index_lot, g_parking_space_recording_x[index_zone][index_lot], g_parking_space_recording_y[index_zone][index_lot]); + } + printf("\n-------------end count lot\n");*/ + } + } + } +} + +char* get_meta_class(int index_meta, int index_zone) { + return g_MetaOut1[index_zone][index_meta]; +} + +void set_metadata() { + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + char MetaData1[BUFSIZE] = { 0 }; + char metadata1[512][STRSPLIT_SIZE] = { 0 }; + strcpy(MetaData1, viewDetectionZone[0][index_zone].metadata1); + g_metadata1_num_for_zone[index_zone] = StrSplit(MetaData1, metadata1, ","); + + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[index_zone]; index_meta++) + { + UpperToLower(metadata1[index_meta]); + TrimSpace(g_MetaOut1[index_zone][index_meta], sizeof(g_MetaOut1[index_zone][index_meta]), metadata1[index_meta], 0); + + if (index_meta == 0) { + if (strcmp(g_MetaOut1[index_zone][index_meta], "null") == 0) { + g_metadata1_num_for_zone[index_zone] = 0; + break; + } + } + } + } +} + +int check_if_existing_in_metaout(char *object_name,int index_zone) { + //char ObjectName[30] = { 0 }; + //sprintf(ObjectName, "%s", object_name); + //UpperToLower(ObjectName); + + int check_existing_in_metaout = 0; + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[index_zone]; index_meta++) + { + if (strcmp(g_MetaOut1[index_zone][index_meta], object_name) == 0 || + (strstr(g_MetaOut1[index_zone][index_meta],"plate")!=NULL && strstr(object_name, "plate") != NULL)) { + check_existing_in_metaout = 1; + break; + } + } + + return check_existing_in_metaout; +} + + +int check_if_existing_in_metaout_not_plate(char *object_name, int index_zone) { + //char ObjectName[30] = { 0 }; + //sprintf(ObjectName, "%s", object_name); + //UpperToLower(ObjectName); + + int check_existing_in_metaout = 0; + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[index_zone]; index_meta++) + { + if (strcmp(g_MetaOut1[index_zone][index_meta], object_name) == 0) { + check_existing_in_metaout = 1; + break; + } + } + + return check_existing_in_metaout; +} + +int person_if_existing_in_metaout(int index_zone) { + + int check_existing_in_metaout = 0; + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[index_zone]; index_meta++) + { + if (strcmp(g_MetaOut1[index_zone][index_meta], "person") == 0) { + check_existing_in_metaout = 1; + break; + } + } + + return check_existing_in_metaout; +} + +int get_metadata1_num(int index_zone) { + return g_metadata1_num_for_zone[index_zone]; +} + +int check_if_object_in_ivs_zone(float obj_center_x, float obj_center_y, float obj_width, float obj_height, int image_width, int image_height, int enable_only_center) { + + int checkisInside = 0; + + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + + //if (strcmp(viewDetectionZone[0][index_zone].enable_ivs_zone,"Yes") == 0) + { + if (g_b_ZoneExist[index_zone]) { + CPoint p_word[9]; + + if (enable_only_center == 1) { + p_word[0].x = (int)(obj_center_x* CANVAS_WIDTH / image_width); + p_word[0].y = (int)(obj_center_y* CANVAS_HEIGHT / image_height); + + if (p_word[0].x < 0) + p_word[0].x = 0; + + if (p_word[0].y < 0) + p_word[0].y = 0; + + if (p_word[0].x > CANVAS_WIDTH) + p_word[0].x = CANVAS_WIDTH; + + if (p_word[0].y > CANVAS_HEIGHT) + p_word[0].y = CANVAS_HEIGHT; + + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[0])) { + checkisInside = 1; + } + } + else { + for (int index_j = 0; index_j < 9; index_j++) { + p_word[index_j].x = (int)((obj_center_x - obj_width * ((float)(1 - 1 * ((int)index_j % 3))) / 2)* CANVAS_WIDTH / image_width); + p_word[index_j].y = (int)((obj_center_y - obj_height * ((float)(1 - 1 * ((int)index_j / 3))) / 2)* CANVAS_HEIGHT / image_height); + + if (p_word[index_j].x < 0) + p_word[index_j].x = 0; + + if (p_word[index_j].y < 0) + p_word[index_j].y = 0; + + if (p_word[index_j].x > CANVAS_WIDTH) + p_word[index_j].x = CANVAS_WIDTH; + + if (p_word[index_j].y > CANVAS_HEIGHT) + p_word[index_j].y = CANVAS_HEIGHT; + + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[index_j])) { + checkisInside = 1; + break; + } + } + } + } + } + + if (checkisInside == 1) + break; + } + + return checkisInside; +} + +int check_if_object_in_zone(float obj_center_x, float obj_center_y, float obj_width, float obj_height, int image_width, int image_height, int enable_only_center) { + + int checkisInside = 0; + + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + if (g_b_ZoneExist[index_zone]) { + CPoint p_word[9]; + + if (enable_only_center == 1) { + p_word[0].x = (int)(obj_center_x* CANVAS_WIDTH / image_width); + p_word[0].y = (int)(obj_center_y* CANVAS_HEIGHT / image_height); + + if (p_word[0].x < 0) + p_word[0].x = 0; + + if (p_word[0].y < 0) + p_word[0].y = 0; + + if (p_word[0].x > CANVAS_WIDTH) + p_word[0].x = CANVAS_WIDTH; + + if (p_word[0].y > CANVAS_HEIGHT) + p_word[0].y = CANVAS_HEIGHT; + + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[0])) { + checkisInside = 1; + } + } + else { + for (int index_j = 0; index_j < 9; index_j++) { + p_word[index_j].x = (int)((obj_center_x - obj_width * ((float)(1 - 1 * ((int)index_j % 3))) / 2)* CANVAS_WIDTH / image_width); + p_word[index_j].y = (int)((obj_center_y - obj_height * ((float)(1 - 1 * ((int)index_j / 3))) / 2)* CANVAS_HEIGHT / image_height); + + if (p_word[index_j].x < 0) + p_word[index_j].x = 0; + + if (p_word[index_j].y < 0) + p_word[index_j].y = 0; + + if (p_word[index_j].x > CANVAS_WIDTH) + p_word[index_j].x = CANVAS_WIDTH; + + if (p_word[index_j].y > CANVAS_HEIGHT) + p_word[index_j].y = CANVAS_HEIGHT; + + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[index_j])) { + checkisInside = 1; + break; + } + } + } + } + + if (checkisInside == 1) + break; + } + + return checkisInside; +} + +int check_if_object_in_zone_width_zone(float obj_center_x, float obj_center_y, float obj_width, float obj_height, int image_width, int image_height, int enable_only_center, int index_zone) { + int checkisInside = 0; + + if (g_b_ZoneExist[index_zone]) { + CPoint p_word[9]; + + if (enable_only_center == 1) { + p_word[0].x = (int)(obj_center_x* CANVAS_WIDTH / image_width); + p_word[0].y = (int)(obj_center_y* CANVAS_HEIGHT / image_height); + + if (p_word[0].x < 0) + p_word[0].x = 0; + + if (p_word[0].y < 0) + p_word[0].y = 0; + + if (p_word[0].x > CANVAS_WIDTH) + p_word[0].x = CANVAS_WIDTH; + + if (p_word[0].y > CANVAS_HEIGHT) + p_word[0].y = CANVAS_HEIGHT; + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[0])) { + checkisInside = 1; + } + } + else { + for (int index_j = 0; index_j < 9; index_j++) { + p_word[index_j].x = (int)((obj_center_x - obj_width * ((float)(1 - 1 * ((int)index_j % 3))) / 2)* CANVAS_WIDTH / image_width); + p_word[index_j].y = (int)((obj_center_y - obj_height * ((float)(1 - 1 * ((int)index_j / 3))) / 2)* CANVAS_HEIGHT / image_height); + + if (p_word[index_j].x < 0) + p_word[index_j].x = 0; + + if (p_word[index_j].y < 0) + p_word[index_j].y = 0; + + if (p_word[index_j].x > CANVAS_WIDTH) + p_word[index_j].x = CANVAS_WIDTH; + + if (p_word[index_j].y > CANVAS_HEIGHT) + p_word[index_j].y = CANVAS_HEIGHT; + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[index_j])) { + checkisInside = 1; + break; + } + } + } + } + + return checkisInside; +} + +int check_if_object_in_zone_simple_version(detection_pos* pNext,int index_zone) { + + int tracking_channel_idx = 0; + //int if_filter = 1; + int checkisInside = 0; + + if (strlen(viewDetectionZone[tracking_channel_idx][index_zone].metadata1) > 0) + { + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + if (check_if_existing_in_metaout(ObjectName, index_zone)) { + + + //printf("\n----pNext->center_x:%f,pNext->width:%f,pNext->center_y:%f,pNext->height:%f\n", pNext->center_x, pNext->width, pNext->center_y, pNext->height); + if (g_b_ZoneExist[index_zone]) { + CPoint p_word[9]; + + for (int index_j = 0; index_j < 9; index_j++) { + p_word[index_j].x = (int)((pNext->center_x - pNext->width * ((float)(1 - 1 * ((int)index_j % 3))) / 2)* CANVAS_WIDTH / g_ori_yuv_width); + p_word[index_j].y = (int)((pNext->center_y - pNext->height * ((float)(1 - 1 * ((int)index_j / 3))) / 2)* CANVAS_HEIGHT / g_ori_yuv_height); + + if (p_word[index_j].x < 0) + p_word[index_j].x = 0; + + if (p_word[index_j].y < 0) + p_word[index_j].y = 0; + + if (p_word[index_j].x > CANVAS_WIDTH) + p_word[index_j].x = CANVAS_WIDTH; + + if (p_word[index_j].y > CANVAS_HEIGHT) + p_word[index_j].y = CANVAS_HEIGHT; + + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[index_j])) { + checkisInside = 1; + } + } + } + } + } + + return checkisInside; +} + + +int check_if_object_in_zone_simple_version_not_plate(detection_pos* pNext, int index_zone) { + int tracking_channel_idx = 0; + //int if_filter = 1; + int checkisInside = 0; + + if (strlen(viewDetectionZone[tracking_channel_idx][index_zone].metadata1) > 0) + { + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + if (check_if_existing_in_metaout_not_plate(ObjectName, index_zone)) { + + + //printf("\n----pNext->center_x:%f,pNext->width:%f,pNext->center_y:%f,pNext->height:%f\n", pNext->center_x, pNext->width, pNext->center_y, pNext->height); + if (g_b_ZoneExist[index_zone]) { + CPoint p_word[9]; + + for (int index_j = 0; index_j < 9; index_j++) { + p_word[index_j].x = (int)((pNext->center_x - pNext->width * ((float)(1 - 1 * ((int)index_j % 3))) / 2)* CANVAS_WIDTH / g_ori_yuv_width); + p_word[index_j].y = (int)((pNext->center_y - pNext->height * ((float)(1 - 1 * ((int)index_j / 3))) / 2)* CANVAS_HEIGHT / g_ori_yuv_height); + + if (p_word[index_j].x < 0) + p_word[index_j].x = 0; + + if (p_word[index_j].y < 0) + p_word[index_j].y = 0; + + if (p_word[index_j].x > CANVAS_WIDTH) + p_word[index_j].x = CANVAS_WIDTH; + + if (p_word[index_j].y > CANVAS_HEIGHT) + p_word[index_j].y = CANVAS_HEIGHT; + + + if (isInside(g_zone_polygon[index_zone], g_side_number, p_word[index_j])) { + checkisInside = 1; + } + } + } + } + } + + return checkisInside; +} + +void clear_PostRecorderList() { + + int counter_index_post = 0; + int counter_index_long = 0; + + time_t now_time = time(0); + double max_iDiffSec[MAX_DETECTION_ZONE] = { 0 }; + int index_max_iDiffSec[MAX_DETECTION_ZONE] = { 0 }; + int clear_count_long[MAX_DETECTION_ZONE] = { 0 }; + + double max_iDiffSec_not_zone = 0; + int index_max_iDiffSec_not_zone = -1; + int clear_count_long_not_zone = 0; + + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + max_iDiffSec[index_zone] = 0.0; + index_max_iDiffSec[index_zone] = -1; + clear_count_long[index_zone] = 0; + } + + for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) + { + if (g_PostRecorderList[index_post].iIfUse == 0 && g_longterm_PostRecorderList[index_post].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[index_post].iIfUse == 1) + { + counter_index_post++; + if (g_PostRecorderList[index_post].count_trigger >= 10) { + g_PostRecorderList[index_post].count_trigger = 10; + } + + double thres_dwell_to_the_same_location = (double)atoi(heartbeatData.dwell_to_the_same_location); + if (g_PostRecorderList[index_post].count_trigger <= 2) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location; + } + else if (g_PostRecorderList[index_post].count_trigger == 3) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 2.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 4) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 3.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 5) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 5.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 6) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 8.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 7) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 13.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 8) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 21.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 9) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 34.0; + } + else if (g_PostRecorderList[index_post].count_trigger == 10) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 55.0; + } + + //if (g_PostRecorderList[index_post].the_same_id == 1) { + //thres_dwell_to_the_same_location = thres_dwell_to_the_same_location / 2.0; + //} + + double iDiffSec = difftime(now_time, g_PostRecorderList[index_post].t_UpdateTime); + //printf("\n------------iDiffSec:%d\n", iDiffSec); + if ((iDiffSec > thres_dwell_to_the_same_location && strlen(g_PostRecorderList[index_post].sPlateNumber) == 0) || + (iDiffSec > 60.0 && strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1)) + { + counter_index_post--; + g_PostRecorderList[index_post].iIfUse = 0; + g_PostRecorderList[index_post].t_FirstGetTime = 0; + g_PostRecorderList[index_post].t_FirstGetTime_total = 0; + g_PostRecorderList[index_post].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[index_post].check_if_post[m] = 0; + } + g_PostRecorderList[index_post].check_if_cloud = 0; + g_PostRecorderList[index_post].check_if_cloud_v2 = 0; + g_PostRecorderList[index_post].check_if_cloud_record_v2 = 0; + g_PostRecorderList[index_post].check_if_email = 0; + g_PostRecorderList[index_post].check_if_ftp = 0; + g_PostRecorderList[index_post].check_if_getalarmmotion = 0; + + g_PostRecorderList[index_post].box_x = 0; + g_PostRecorderList[index_post].box_y = 0; + g_PostRecorderList[index_post].box_w = 0; + g_PostRecorderList[index_post].box_h = 0; + + g_PostRecorderList[index_post].object_id = 0; + g_PostRecorderList[index_post].zone_idx = 0; + strcpy(g_PostRecorderList[index_post].sPlateNumber, ""); + strcpy(g_PostRecorderList[index_post].name, ""); + + g_PostRecorderList[index_post].count_trigger = 0; + //g_PostRecorderList[index_post].the_same_id = 0; + } + } + + if (g_longterm_PostRecorderList[index_post].iIfUse == 1) + { + counter_index_long++; + if (g_longterm_PostRecorderList[index_post].count_trigger >= 10) { + g_longterm_PostRecorderList[index_post].count_trigger = 10; + } + + double thres_dwell_to_the_same_location = (double)atoi(heartbeatData.dwell_to_the_same_location); + + detection_pos temp_B = { 0 }; + temp_B.left_x = g_longterm_PostRecorderList[index_post].box_x; + temp_B.top_y = g_longterm_PostRecorderList[index_post].box_y; + temp_B.width = g_longterm_PostRecorderList[index_post].box_w; + temp_B.height = g_longterm_PostRecorderList[index_post].box_h; + strcpy(temp_B.name, g_longterm_PostRecorderList[index_post].name); + + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 30.0; + + if (g_longterm_PostRecorderList[index_post].count_trigger <= 2) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 3) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 2.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 4) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 3.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 5) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 5.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 6) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 8.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 7) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 13.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 8) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 21.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 9) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 34.0; + } + else if (g_longterm_PostRecorderList[index_post].count_trigger == 10) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location * 55.0; + } + + double iDiffSec = difftime(now_time, g_longterm_PostRecorderList[index_post].t_UpdateTime); + + if (g_longterm_PostRecorderList[index_post].zone_idx >= 0) { + int zone_idx = g_longterm_PostRecorderList[index_post].zone_idx; + clear_count_long[zone_idx]++; + if (iDiffSec > max_iDiffSec[zone_idx]) + { + max_iDiffSec[zone_idx] = iDiffSec; + index_max_iDiffSec[zone_idx] = index_post; + } + } + else { + clear_count_long_not_zone++; + if (iDiffSec > max_iDiffSec_not_zone) + { + max_iDiffSec_not_zone = iDiffSec; + index_max_iDiffSec_not_zone = index_post; + } + } + + //printf("\n------------iDiffSec:%d\n", iDiffSec); + + if ((iDiffSec > thres_dwell_to_the_same_location && strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) == 0) || + (iDiffSec > 60.0 && strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1)) + { + counter_index_long--; + g_longterm_PostRecorderList[index_post].iIfUse = 0; + g_longterm_PostRecorderList[index_post].t_FirstGetTime = 0; + g_longterm_PostRecorderList[index_post].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[index_post].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[index_post].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[index_post].check_if_cloud = 0; + g_longterm_PostRecorderList[index_post].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[index_post].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[index_post].check_if_email = 0; + g_longterm_PostRecorderList[index_post].check_if_ftp = 0; + g_longterm_PostRecorderList[index_post].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[index_post].box_x = 0; + g_longterm_PostRecorderList[index_post].box_y = 0; + g_longterm_PostRecorderList[index_post].box_w = 0; + g_longterm_PostRecorderList[index_post].box_h = 0; + + g_longterm_PostRecorderList[index_post].object_id = 0; + g_longterm_PostRecorderList[index_post].zone_idx = 0; + strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); + strcpy(g_longterm_PostRecorderList[index_post].name, ""); + + g_longterm_PostRecorderList[index_post].count_trigger = 0; + //g_longterm_PostRecorderList[index_post].the_same_id = 0; + } + } + } + + if (clear_count_long_not_zone >= 50) { + if (index_max_iDiffSec_not_zone >= 0) { + counter_index_long--; + int index_post = index_max_iDiffSec_not_zone; + g_longterm_PostRecorderList[index_post].iIfUse = 0; + g_longterm_PostRecorderList[index_post].t_FirstGetTime = 0; + g_longterm_PostRecorderList[index_post].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[index_post].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[index_post].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[index_post].check_if_cloud = 0; + g_longterm_PostRecorderList[index_post].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[index_post].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[index_post].check_if_email = 0; + g_longterm_PostRecorderList[index_post].check_if_ftp = 0; + g_longterm_PostRecorderList[index_post].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[index_post].box_x = 0; + g_longterm_PostRecorderList[index_post].box_y = 0; + g_longterm_PostRecorderList[index_post].box_w = 0; + g_longterm_PostRecorderList[index_post].box_h = 0; + + g_longterm_PostRecorderList[index_post].object_id = 0; + g_longterm_PostRecorderList[index_post].zone_idx = 0; + strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); + strcpy(g_longterm_PostRecorderList[index_post].name, ""); + + g_longterm_PostRecorderList[index_post].count_trigger = 0; + //g_longterm_PostRecorderList[index_post].the_same_id = 0; + } + } + + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { + if (clear_count_long[index_zone] >= 15) { + if (index_max_iDiffSec[index_zone] >= 0) { + counter_index_long--; + int index_post = index_max_iDiffSec[index_zone]; + g_longterm_PostRecorderList[index_post].iIfUse = 0; + g_longterm_PostRecorderList[index_post].t_FirstGetTime = 0; + g_longterm_PostRecorderList[index_post].t_FirstGetTime_total = 0; + g_longterm_PostRecorderList[index_post].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[index_post].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[index_post].check_if_cloud = 0; + g_longterm_PostRecorderList[index_post].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[index_post].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[index_post].check_if_email = 0; + g_longterm_PostRecorderList[index_post].check_if_ftp = 0; + g_longterm_PostRecorderList[index_post].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[index_post].box_x = 0; + g_longterm_PostRecorderList[index_post].box_y = 0; + g_longterm_PostRecorderList[index_post].box_w = 0; + g_longterm_PostRecorderList[index_post].box_h = 0; + + g_longterm_PostRecorderList[index_post].object_id = 0; + g_longterm_PostRecorderList[index_post].zone_idx = 0; + strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); + strcpy(g_longterm_PostRecorderList[index_post].name, ""); + + g_longterm_PostRecorderList[index_post].count_trigger = 0; + //g_longterm_PostRecorderList[index_post].the_same_id = 0; + } + } + } + + g_counter_index_post = counter_index_post; + g_counter_index_long = counter_index_long; + + qsort(&g_PostRecorderList, MAX_POST_RECODER_SIZE, sizeof(PostRecoder), sort_record_post); + qsort(&g_longterm_PostRecorderList, MAX_POST_RECODER_SIZE, sizeof(PostRecoder), sort_record_post); +} + +void minus_count_trigger() { + time_t now_time = time(0); + double iDiffSec_temp2 = 0.0; + + for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) + { + if (g_PostRecorderList[index_post].iIfUse == 0 && g_longterm_PostRecorderList[index_post].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[index_post].iIfUse == 1) { + iDiffSec_temp2 = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + + if (iDiffSec_temp2 >= 2.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger--; + if (g_PostRecorderList[index_post].count_trigger < 1.0) { + g_PostRecorderList[index_post].count_trigger = 1.0; + } + } + } + + + detection_pos temp_B = { 0 }; + temp_B.left_x = g_longterm_PostRecorderList[index_post].box_x; + temp_B.top_y = g_longterm_PostRecorderList[index_post].box_y; + temp_B.width = g_longterm_PostRecorderList[index_post].box_w; + temp_B.height = g_longterm_PostRecorderList[index_post].box_h; + strcpy(temp_B.name, g_longterm_PostRecorderList[index_post].name); + + { + if (g_longterm_PostRecorderList[index_post].iIfUse == 1) { + iDiffSec_temp2 = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp2 >= 60.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger--; + if (g_longterm_PostRecorderList[index_post].count_trigger < 1.0) { + g_longterm_PostRecorderList[index_post].count_trigger = 1.0; + } + } + } + } + } +} + +pthread_t g_run_one_net_thread_id; +pthread_t g_run_one_net_thread_anpr_id; +#if defined GY_OS_AMBA +pthread_t g_differ_image_thread_id; +pthread_t g_compute_median_thread_id; +#endif +pthread_t g_get_canvas_thread_id; + + +int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAcontent) +{ + //printf("\n-----------start all nets:start\n"); + + uint32_t net_num = 0; + int idx = 0, rval = 0; + int /*ret = 0,*/ i = 0, j = 0/*, bbox_ret = 0*/; + + static long counter_ms; + struct timeval currtime; + long now; + + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (stAMBAcontent != NULL) { + g_stAMBAcontent = (*stAMBAcontent); +#ifdef GY_OS_AMBA + if (pctrl != NULL) { + + net_num = pctrl->net_num; + + for (idx = 0; idx < net_num; idx++) { + if (init_one_net(&pctrl->net_pair[idx]) < 0) { + printf("start one net idx [%u] err\n", idx); + rval = -1; + break; + } + } + + unlink_lilin_weight(); + } + else { + rval = -1; + } +#endif + + } + else { + rval = -1; + } + } + +#ifdef GY_OS_AMBA + // 2022-10-31 Read Radar label file + char radarClassNames[MAX_CLASS_NUM][CLASSNAME_LENGTH]; + char radar_label_file_names[MAX_SELECTED_FILES][STRSPLIT_SIZE] = { 0 }; + + if (g_IsRadarDevice == 1) { + if (stAMBAcontent->sz_amba_label_fileNames) + { + StrSplit(stAMBAcontent->sz_amba_label_fileNames, radar_label_file_names, ","); + + classNum = init_label_file_lilin(radar_label_file_names[0], radarClassNames); + + // printf("Label file loaded: %s. classNum = %d\n", radar_label_file_names[0], classNum); + // for (int i = 0; i < classNum; i++) + // { + // printf("radarClassNames[%d]:%s\n", i, radarClassNames[i]); + // } + } + } +#endif + if(rval != -1){ + + for (i = 0; i < MAX_LAYER_NUM; i++) { + iFeature_access_ctrl_det_layer_index[i] = -1; + } + + frame_id = 0; +#if 1 + detection_pos *pNext = NULL; + detection_pos *pNext_t = NULL; + detection_pos *pNext1 = NULL; + detection_pos *pNext2 = NULL; + detection_pos *pNext_temp = NULL; + detection_pos PosInfo[MAX_DETECT_OBJECTS] = { 0 }; + +#endif + + int total_element_size = 0; + int element_size[MAX_LAYER_NUM] = { 0 }; + + //float arc = 0; + uint32_t parent_index = 0; + //uint32_t parent_count_index = 0; + uint32_t valid_bbox_idx = 0; + + gettimeofday(&currtime, NULL); + counter_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); + //int check_count = 0; + //printf("\n[start all nets]------2\n"); + ai_frame_counter = 0; + int fps_sec_count = 0; + + double dw_FPS_time_delta = 0; + + ///Read test tof img +#if 0 + //char G_reuse_mem[310000]; //1048576 + char tofYUVPATH[1024]; + strcpy(tofYUVPATH, "/emmc/plugin/Aida_data/"); + strcat(tofYUVPATH, "result_665.yuv"); + //strcat(tofYUVPATH, "480pNV12.yuv"); + + + //const char *infile = "C:480PNV12.YUV"; + //const char *infile = "C:result_542.yuv"; + + int size = 0, exp_size = 0; + + printf("read tof path = %s \n", tofYUVPATH); + + //size = load_file_to_mem(infile, G_reuse_mem); + //size = load_file_to_mem(tofYUVPATH, G_reuse_mem); + //size = read_bin(tofYUVPATH, G_reuse_mem); + size = testbbinfile(tofYUVPATH, G_reuse_mem); + + printf("read size = %d \n", size); +#endif + +#if 1 + if (pctrl != NULL) { + g_pctrl = pctrl; + g_pctrl_run_one_net = pctrl; + g_pctrl_run_one_net_anpr = pctrl; + + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + + if (unlockingKeyInnoFR == 0) { + if (pthread_create(&g_run_one_net_thread_id, 0, run_one_net_thread, NULL)) + { + printf("create run_one_net_thread thread faile \n"); + } + } + + +#ifdef GY_OS_V_SERIES + +#else + if (g_IsToFDevice == 0 && unlockingKeyInnoFR == 0) + { + if (pthread_create(&g_run_one_net_thread_anpr_id, 0, run_one_net_thread_anpr, NULL)) + { + printf("create run_one_net_thread_anpr thread faile \n"); + } + } +#endif + +#if 1 +#if defined GY_OS_AMBA + if (g_IsToFDevice == 0 && unlockingKeyInnoFR == 0) + { + if (pthread_create(&g_differ_image_thread_id, 0, differ_image_thread, NULL)) + { + printf("create differ_image_thread thread faile \n"); + } + } + + if (g_IsToFDevice == 0 && unlockingKeyInnoFR == 0) + { + if (pthread_create(&g_compute_median_thread_id, 0, compute_median_thread, NULL)) + { + printf("create compute_median_thread thread faile \n"); + } + } +#endif +#endif + +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR == 0) { + if (pthread_create(&g_get_canvas_thread_id, 0, Get_canvas_From_IPCam_thread, NULL)) + { + printf("create Get_canvas_From_IPCam_thread thread faile \n"); + } + } +#endif + + } + } +#endif + + int tracking_channel_idx = 0; + viewChannelData[tracking_channel_idx].tab_view_width_ratio = 1; + viewChannelData[tracking_channel_idx].tab_view_height_ratio = 1; + +#ifdef GY_OS_AMBA + static long last_heatmap, now_heatmap; + struct timeval currtime_heatmap; + gettimeofday(&currtime_heatmap, NULL); + last_heatmap = (currtime_heatmap.tv_sec * 1000) + (currtime_heatmap.tv_usec / 1000); + int last_wday = -1; + int count_heatmap_time = -1; + //int check_set_tof_basic = 0; +#endif + + /* + double dur; + clock_t start, end; + start = clock();*/ + + int check_first_start_all_nets = 0; + usSleep(5000000); + bool hasGetAlarmMotion = FALSE; + int check_if_hasgetalarm = 0; +#if 1 + while (live_mode_flag && (pctrl != NULL || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || unlockingKeyInnoFR == 1)) + { + set_record_process_note("startallnets_start"); + //gettimeofday(&currtime, NULL); + //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //long last_ms = now_ms; + + g_stAMBAcontent.confidence_plate = (float)(atoi(viewChannelData[tracking_channel_idx].confidence)); //P + g_stAMBAcontent.confidence_traffic = (float)(atoi(viewChannelData[tracking_channel_idx].confidence2)); //q + stAMBAcontent->confidence_plate = (float)(atoi(viewChannelData[tracking_channel_idx].confidence)); //P + stAMBAcontent->confidence_traffic = (float)(atoi(viewChannelData[tracking_channel_idx].confidence2)); //q + + if (g_count_alter >= 1) { + if (g_count_alter >= 2) {//5// + + } + else { + g_alter_something = 1; + } + g_count_alter--; + } + else { + g_alter_something = 0; + } + + int min_x = 10000; + int min_y = 10000; + int max_x = 0; + int max_y = 0; + + + int min_x_red = 10000; + int min_y_red = 10000; + int max_x_red = 0; + int max_y_red = 0; + + for (int m = 0; m < viewChannelData[tracking_channel_idx].count_zone; m++) { + + int temp_g_b_ZoneExist = 0; + + int min_x_points = 10000; + int min_y_points = 10000; + int max_x_points = 0; + int max_y_points = 0; + + for (int k = 0; k < 6; k++) + { + if (viewDetectionZone[tracking_channel_idx][m].Points[k].x > 0 || viewDetectionZone[tracking_channel_idx][m].Points[k].y > 0) + temp_g_b_ZoneExist = 1; + + g_zone_polygon[m][k].x = (int)((float)viewDetectionZone[tracking_channel_idx][m].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); + g_zone_polygon[m][k].y = (int)((float)viewDetectionZone[tracking_channel_idx][m].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); + + if (m == 0 && g_zone_polygon[m][k].x >= 1 && g_zone_polygon[m][k].y >= 1) { + + if (g_zone_polygon[m][k].x < min_x) { + min_x = g_zone_polygon[m][k].x; + } + + if (g_zone_polygon[m][k].x > max_x) { + max_x = g_zone_polygon[m][k].x; + } + + if (g_zone_polygon[m][k].y < min_y) { + min_y = g_zone_polygon[m][k].y; + } + + if (g_zone_polygon[m][k].y > max_y) { + max_y = g_zone_polygon[m][k].y; + } + } + + if (strlen(viewChannelData[tracking_channel_idx].red_light_zone) >= 1 && strcmp(viewChannelData[tracking_channel_idx].red_light_zone, "NULL") != 0) { + if (m == atoi(viewChannelData[tracking_channel_idx].red_light_zone)) { + if (g_zone_polygon[m][k].x < min_x_red) { + min_x_red = g_zone_polygon[m][k].x; + } + + if (g_zone_polygon[m][k].x > max_x_red) { + max_x_red = g_zone_polygon[m][k].x; + } + + if (g_zone_polygon[m][k].y < min_y_red) { + min_y_red = g_zone_polygon[m][k].y; + } + + if (g_zone_polygon[m][k].y > max_y_red) { + max_y_red = g_zone_polygon[m][k].y; + } + } + } + + if (g_zone_polygon[m][k].x < min_x_points) { + min_x_points = g_zone_polygon[m][k].x; + } + + if (g_zone_polygon[m][k].x > max_x_points) { + max_x_points = g_zone_polygon[m][k].x; + } + + if (g_zone_polygon[m][k].y < min_y_points) { + min_y_points = g_zone_polygon[m][k].y; + } + + if (g_zone_polygon[m][k].y > max_y_points) { + max_y_points = g_zone_polygon[m][k].y; + } + } + + viewDetectionZone[tracking_channel_idx][m].min_x_points = min_x_points; + viewDetectionZone[tracking_channel_idx][m].max_x_points = max_x_points; + viewDetectionZone[tracking_channel_idx][m].min_y_points = min_y_points; + viewDetectionZone[tracking_channel_idx][m].max_y_points = max_y_points; + + g_b_ZoneExist[m] = temp_g_b_ZoneExist; + + build_g_parking_space_recording(tracking_channel_idx,m); + } + + //int temp_g_check_if_set_no_preset_no_autopan = 1; + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + g_check_if_all_existing[index_zone] = 0; + g_check_if_NAND[index_zone] = 0; + + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[index_zone]; index_meta++) + { + g_Meta_If_Existing[index_zone][index_meta] = 0; + } + +#if 0 + if (IsPTZ() == 1) + { + if (IsPTZinAutoTracking() == 0 && IsPTZinAutoPan() == 0) { + if (viewDetectionZone[tracking_channel_idx][index_zone].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[tracking_channel_idx][index_zone].ptz_zone_to_preset) != 0) + { + + if (atoi(viewDetectionZone[tracking_channel_idx][index_zone].ptz_zone_to_preset) != 0) { + temp_g_check_if_set_no_preset_no_autopan = 0; + } + } + } + else { + temp_g_check_if_set_no_preset_no_autopan = 0; + } + } + else { + temp_g_check_if_set_no_preset_no_autopan = 0; + } +#endif + } + //g_check_if_set_no_preset_no_autopan = temp_g_check_if_set_no_preset_no_autopan; + //printf("\n[start all nets]------411111111\n"); + + g_current_snapshot_size_base64 = 0; + for (int i = 0; i < MAX_PLATE_BUF_NUM; i++) { + g_cropped_length_image_base64[i] = 0; + } + + g_check_if_current_light_is_red = 0; + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #1:%lf ms\n", dw_FPS_time_delta); + +#if 1 + if ((g_IsRadarDevice == 0 || g_IsToFDevice == 1) && unlockingKeyInnoFR == 0) + { + //printf("\n[start all nets]------411111111AAA\n"); + pthread_mutex_lock(&mutex_get_network_input); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #1 #1:%lf ms\n", dw_FPS_time_delta); + + //printf("\n[start all nets]------411111111BBBB\n"); + + //printf("\n[start all nets]------4111111122\n"); +#ifdef GY_OS_AMBA + if (check_stop_test_nn_cavalry == 0) { + if (get_network_input(g_pctrl) < 0) { + printf("get_network_input err\n"); + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "get_network_input(g_pctrl) < 0"); + write_to_logs_html(temp_msg, "start all nets", "ERROR", "Yes"); + } + + rval = -1; + //g_rval = -1; + + pthread_mutex_unlock(&mutex_get_network_input); + break; + } + } + + //printf("\n[start all nets]------41111113333\n"); + //if (g_rval < 0) { + //rval = g_rval; + //pthread_mutex_unlock(&mutex_get_network_input); + //break; + //} +#endif + //printf("\n[start all nets]------411111133331\n"); + if (check_stop_test_nn_cavalry == 0){ + pctrl = g_pctrl; + + if (check_first_start_all_nets == 0) { + /*if (switch_traffic == 0)*/ { + g_pctrl_run_one_net = pctrl; + switch_traffic = 1; + } + /*if (switch_anpr == 0)*/ { + g_pctrl_run_one_net_anpr = pctrl; + switch_anpr = 1; + } + + switch_differ = 1; + + check_first_start_all_nets = 1; + } + } + else { + g_pctrl_run_one_net = NULL; + g_pctrl_run_one_net_anpr = NULL; + } + //printf("\n[start all nets]------411111133332\n"); + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #1 #2:%lf ms\n", dw_FPS_time_delta); + pthread_mutex_unlock(&mutex_get_network_input); + } +#endif + + if (check_first_start_all_nets == 1) { + if (check_stop_test_nn_cavalry == 0) { + if (switch_traffic == 1 && g_check_sync_traffic == 1) { + g_check_sync_traffic = 0; + g_pctrl_run_one_net = pctrl; + } + + if (switch_anpr == 1 && g_check_sync_anpr == 1) { + g_check_sync_anpr = 0; + g_pctrl_run_one_net_anpr = pctrl; + } + + if (switch_differ == 1 && g_check_sync_differ == 1) { + g_check_sync_differ = 0; + } + } + else { + g_pctrl_run_one_net = NULL; + g_pctrl_run_one_net_anpr = NULL; + } + set_record_process_note("use_sleep_start"); + use_sleep_to_adjust_sync_or_async(tracking_channel_idx); + set_record_process_note("use_sleep_end"); + } + else { + usSleep(50000); + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #2:%lf ms\n", dw_FPS_time_delta); + +#if 1 + int check_if_needed_to_support_image = 0; + for (int j = 0; j < MAX_POST_EVENTS; j++) + { + if (strcmp(postEventList[j].post_file_format, "text") == 0) { + if (strlen(postEventList[j].post_content) >= 1) { + if (strstr(postEventList[j].post_content, "<|snap_image|>") != NULL) { + check_if_needed_to_support_image = 1; + break; + } + } + } + else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { + check_if_needed_to_support_image = 1; + break; + } + } + + if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 || + strcmp(SystemSetting.enable_email_notification, "Yes") == 0 || + strcmp(SystemSetting.enable_ftp, "Yes") == 0 || + strcmp(SystemSetting.enable_getalarmmotion_snap, "Yes") == 0 || + check_if_needed_to_support_image == 1) + { + if (check_stop_test_nn_cavalry == 0 && (g_IsRadarDevice == 0 || g_IsToFDevice == 1)) { + + pthread_mutex_lock(&mutex_get_image); + + if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1) { + g_post_SysTimeStamp = g_post_SysTimeStamp_ori[g_current_max_num_image_buff - 1]; + memcpy(g_current_snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); + g_current_snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; + } + //switch_g_image_buff_ori = 0; + pthread_mutex_unlock(&mutex_get_image); +#ifdef GY_OS_AMBA + pthread_mutex_lock(&mutex_get_image_HD); + if (g_image_buff_size_HD[g_current_max_num_image_buff - 1] >= 1) { + memcpy(g_current_snapshot_addr_HD, g_image_buff_HD[g_current_max_num_image_buff - 1], g_image_buff_size_HD[g_current_max_num_image_buff - 1]); + g_current_snapshot_size_HD = g_image_buff_size_HD[g_current_max_num_image_buff - 1]; + } + //switch_g_image_buff_ori = 0; + pthread_mutex_unlock(&mutex_get_image_HD); +#endif + + strcpy(g_current_image_state_response, g_image_state_response_ori); + + if (g_current_snapshot_size >= 1) + { +#ifdef GY_OS_AMBA + if (strlen(viewChannelData[tracking_channel_idx].red_light_zone) >= 1 && strcmp(viewChannelData[tracking_channel_idx].red_light_zone, "NULL") != 0) { + if (atoi(viewChannelData[tracking_channel_idx].red_light_zone) < viewChannelData[tracking_channel_idx].count_zone) { + //printf("\n--------:red light start:%d\n", g_check_if_current_light_is_red); + g_check_if_current_light_is_red = find_zone_color(g_current_snapshot_addr, g_current_snapshot_size, get_g_framesize_width(), get_g_framesize_height(), min_x_red, min_y_red, max_x_red, max_y_red); + //printf("\n--------:red light end:%d\n", g_check_if_current_light_is_red); + } + } + + if (enable_zone_crop_1 == 1) + { + + int check_ret = crop_zone_image_ivs(g_current_snapshot_addr_crop_zone, &g_current_snapshot_size_crop_zone, g_current_snapshot_addr, g_current_snapshot_size, get_g_framesize_width(), get_g_framesize_height(), min_x, min_y, max_x, max_y); + + if (check_ret == 1 && g_current_snapshot_size_crop_zone >= 1) { + base64_encode((const unsigned char*)g_current_snapshot_addr_crop_zone, g_current_snapshot_size_crop_zone, (size_t *)&g_current_snapshot_size_base64, g_current_snapshot_addr_base64); + g_current_snapshot_addr_base64[g_current_snapshot_size_base64] = '\0'; + } + else + { + base64_encode((const unsigned char*)g_current_snapshot_addr, g_current_snapshot_size, (size_t *)&g_current_snapshot_size_base64, g_current_snapshot_addr_base64); + g_current_snapshot_addr_base64[g_current_snapshot_size_base64] = '\0'; + } + } + else +#endif + { + base64_encode((const unsigned char*)g_current_snapshot_addr, g_current_snapshot_size, (size_t *)&g_current_snapshot_size_base64, g_current_snapshot_addr_base64); + g_current_snapshot_addr_base64[g_current_snapshot_size_base64] = '\0'; + } + + //if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) + { + /*int check_ret = */resize_image_ivs(g_current_snapshot_addr_8592, &g_current_snapshot_size_8592, g_current_snapshot_addr, g_current_snapshot_size, get_g_framesize_width(), get_g_framesize_height(), UDP_IMAGE_WIDTH_NORMAL, UDP_IMAGE_HEIGHT_NORMAL); + base64_encode((const unsigned char*)g_current_snapshot_addr_8592, g_current_snapshot_size_8592, (size_t *)&g_current_snapshot_size_8592_base64, g_current_snapshot_addr_8592_base64); + g_current_snapshot_addr_8592_base64[g_current_snapshot_size_8592_base64] = '\0'; + } + //else + { + /*int check_ret = */resize_image_ivs(g_current_snapshot_addr_udp, &g_current_snapshot_size_udp, g_current_snapshot_addr, g_current_snapshot_size, get_g_framesize_width(), get_g_framesize_height(), UDP_IMAGE_WIDTH, UDP_IMAGE_HEIGHT); + base64_encode((const unsigned char*)g_current_snapshot_addr_udp, g_current_snapshot_size_udp, (size_t *)&g_current_snapshot_size_udp_base64, g_current_snapshot_addr_udp_base64); + g_current_snapshot_addr_udp_base64[g_current_snapshot_size_udp_base64] = '\0'; + } + } + //printf("\n---------------g_current_snapshot_size:%d\n", g_current_snapshot_size); + //printf("\n---------------g_current_snapshot_size_base64:%d\n", g_current_snapshot_size_base64); + //printf("\n---------------g_current_snapshot_size_8592:%d\n", g_current_snapshot_size_8592); + //printf("\n---------------g_current_snapshot_size_8592_base64:%d\n", g_current_snapshot_size_8592_base64); + //printf("\n---------------g_current_snapshot_size_udp:%d\n", g_current_snapshot_size_udp); + //printf("\n---------------g_current_snapshot_size_udp_base64:%d\n", g_current_snapshot_size_udp_base64); + //printf("\n---------------g_current_snapshot_size_crop_zone:%d\n", g_current_snapshot_size_crop_zone); + } + } +#endif + + if (fps_sec_count >= GET_AI_FPS_SEC) + { + gettimeofday(&currtime, NULL); + now = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + + if (ai_frame_counter > 0) { + dw_FPS_time_delta = (double)(now - counter_ms); + if (dw_FPS_time_delta < 0) + dw_FPS_time_delta = (double)fabs((float)dw_FPS_time_delta); + + AI_fps = (int)ceil(((double)(ai_frame_counter)) * 1000.0 / dw_FPS_time_delta); + //printf("\n[start all nets]ai_frame_counter*1000: %d; now - counter_ms: %d; AI_fps: %d \n",ai_frame_counter*1000,(now-counter_ms),AI_fps); + } + else + AI_fps = 0; + + counter_ms = now; + fps_sec_count = 0; + ai_frame_counter = 0; + } + + float dwell_time_secs = (float)atoi(SystemSetting.tracking_id_dwell) + 0.5; //viewDetectionZone[tracking_channel_idx][0].no_parking_time + if (AI_fps >= 1) { + set_DISAPPEAR_FRAME_MAX((int)(((float)AI_fps)*dwell_time_secs)); + } + + //printf("\n-----------g_check_if_current_light_is_red:%d\n", g_check_if_current_light_is_red); + + //arc = 0; + parent_index = 0; + //parent_count_index = 0; + total_element_size = 0; + memset(&PosInfo, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + + viewChannelData[0].iVideo_source_w = g_ori_yuv_width; + viewChannelData[0].iVideo_source_h = g_ori_yuv_height; +#ifdef GY_OS_AMBA + if (g_IsPTZDevice == 1) { + UpdatePTZsourceWH(g_ori_yuv_width, g_ori_yuv_height); + } +#endif + if(pctrl != NULL) + net_num = pctrl->net_num; + else { + net_num = 0; + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #3:%lf ms\n", dw_FPS_time_delta); + + //printf("\n[start all nets]------6\n"); + if ((g_IsRadarDevice == 0 || g_IsToFDevice == 1) && unlockingKeyInnoFR == 0) { + //printf("\n[start all nets]------6---123\n"); + //if (g_IsRadarDevice == 0 && g_IsToFDevice == 0) { + if (check_first_start_all_nets == 1) { + /* + end = clock(); + dur = (double)(end - start); + printf("\n[2]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + //printf("\n[start all nets]------6111111\n"); + // + int temp_total_element_size_traffic = 0; + for (idx = 0; idx < net_num; idx++) + { + //printf("\n[start all nets] idx:%d\n", idx); + if (idx == iFeature_lpr_layer_index) { +#if 1 + if (iFeature_lpr_layer_index >= 0) { + if (viewChannelData[0].enable_anpr){ + if (g_check_sync_anpr == 1) { + /*if (g_total_element_size > 0)*/ {//1ӨP+1Ӧr + //printf("\n[start all nets]------61\n"); + pthread_mutex_lock(&mutex_run_one_net); + pctrl = g_pctrl_run_one_net_anpr; + pNext_t = g_PosInfo; + parent_index = total_element_size; + + valid_bbox_idx = 0; + for (i = 0; i < pctrl->net_pair[iFeature_lpr_layer_index].valid_result_num; i++) { + //printf("\n[start all nets]------62\n"); + pNext = PosInfo + total_element_size + valid_bbox_idx; + pNext2 = g_PosInfo + i; + + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, pNext2->name); + +#if 1 + if (strlen(pNext->name) == 0) { + continue; + } +#endif + + pNext->confidence = pNext2->confidence; + + pNext->engine_type = pNext2->engine_type; + pNext->engine_type2 = pNext2->engine_type2; + pNext->left_x = pNext2->left_x; + pNext->top_y = pNext2->top_y; + pNext->width = pNext2->width; + pNext->height = pNext2->height; + pNext->center_x = pNext2->center_x; + pNext->center_y = pNext2->center_y; + pNext->center_direction = (float)DIRECTION_DEFAULT; + pNext->center_stability = (float)DIRECTION_DEFAULT; + +#if 1 + if (enable_only_show_metadata1 == 1) { + //int if_filter = 1; + + for (int z = 0; z < viewChannelData[tracking_channel_idx].count_zone; z++) + { + if (strlen(viewDetectionZone[tracking_channel_idx][z].metadata1) > 0) + { + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + for (int k = 0; k < g_metadata1_num_for_zone[z]; k++) { + if (strcmp(ObjectName, g_MetaOut1[z][k]) == 0 || + (strstr(g_MetaOut1[z][k], "plate") != NULL && strstr(ObjectName, "plate") != NULL)) { + + int checkisInside = check_if_object_in_zone_simple_version_not_plate(pNext, z); + + //printf("\n----pNext->center_x:%f,pNext->width:%f,pNext->center_y:%f,pNext->height:%f\n", pNext->center_x, pNext->width, pNext->center_y, pNext->height); + //printf("\n--------checkisInside:%d\n", checkisInside); + if (checkisInside) { + if ((((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewDetectionZone[tracking_channel_idx][z].obj_max_proportion_in_zone) / 100.0)) || + (((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewDetectionZone[tracking_channel_idx][z].obj_min_proportion_in_zone) / 100.0)) + ) + { + + } + else { + g_Meta_If_Existing[z][k]++; + g_Meta_If_Existing_for_NAND[z][k] = 1; + } + } + + //if_filter = 0; + break; + } + } + } + } + + } +#endif + for (int z = 0; z < viewChannelData[tracking_channel_idx].count_zone; z++) + { + if (strlen(viewDetectionZone[tracking_channel_idx][z].metadata1) > 0) + { + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + + if (strstr(viewDetectionZone[tracking_channel_idx][z].metadata_stop, "plate") != NULL) { + g_check_if_metadata_stop_happened[z] = 1; + + gettimeofday(&now_t_metadata_stop, NULL); + s_now_t_metadata_stop = now_t_metadata_stop.tv_sec; //쬰 + s_last_t_metadata_stop[z] = s_now_t_metadata_stop; + } + + if (g_check_if_metadata_stop_happened[z] == 1) { + gettimeofday(&now_t_metadata_stop, NULL); + s_now_t_metadata_stop = now_t_metadata_stop.tv_sec; //쬰 + + + if ((s_now_t_metadata_stop - s_last_t_metadata_stop[z]) >= 2) { + s_last_t_metadata_stop[z] = s_now_t_metadata_stop; + g_check_if_metadata_stop_happened[z] = 0; + } + } + } + } + + + + pNext->parent_idx = pNext2->parent_idx; + + pNext->car_logo_idx = pNext2->car_logo_idx; + + pNext->number_row = pNext2->number_row; + pNext->class_id = pNext2->class_id; + + pNext->box_x = pNext2->box_x; + pNext->box_y = pNext2->box_y; + pNext->box_w = pNext2->box_w; + pNext->box_h = pNext2->box_h; + pNext->obj_type = pNext2->obj_type; + pNext->test_id = pNext2->test_id; + pNext->image_id = pNext2->image_id; + //pNext->id_g_sub_PlateRecords = valid_bbox_idx; + + pNext->color_id = pNext2->color_id; + pNext->sec_color_id = pNext2->sec_color_id; +#if 0 + printf("\npNext->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence); +#endif + //printf("\n[start all nets]------63\n"); + valid_bbox_idx++; + } + element_size[iFeature_lpr_layer_index] = pctrl->net_pair[iFeature_lpr_layer_index].valid_result_num; + total_element_size += element_size[iFeature_lpr_layer_index]; + + int temp_total_element_size = 0; + //printf("\n[start all nets]------64\n"); + for (i = 0; i < pctrl->net_pair[iFeature_lpr_layer_index].valid_result_num; i++) { + + //printf("\n[start all nets]------65\n"); + pNext1 = pNext_t + i; + pNext2 = PosInfo + total_element_size; + + + valid_bbox_idx = 0; + for (j = 0; j < g_element_size[iFeature_lpr_layer_index + 1][i]; j++) + { + pNext = PosInfo + total_element_size + valid_bbox_idx; + + pNext_temp = g_PosInfo + g_element_size[iFeature_lpr_layer_index][0] + temp_total_element_size + j; + + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, pNext_temp->name); + + pNext->confidence = pNext_temp->confidence; + + pNext->engine_type = pNext_temp->engine_type; + pNext->engine_type2 = pNext_temp->engine_type2; + pNext->left_x = pNext_temp->left_x; + + pNext->top_y = pNext_temp->top_y; + pNext->width = pNext_temp->width; + pNext->height = pNext_temp->height; + pNext->center_x = pNext_temp->center_x; + pNext->center_y = pNext_temp->center_y; + pNext->center_direction = (float)DIRECTION_DEFAULT; + pNext->center_stability = (float)DIRECTION_DEFAULT; + pNext->parent_idx = pNext_temp->parent_idx; + pNext->number_row = pNext_temp->number_row; + pNext->class_id = pNext_temp->class_id; + //pNext->id_g_sub_PlateRecords = -1; + + pNext->box_x = pNext_temp->box_x; + + pNext->box_y = pNext_temp->box_y; + pNext->box_w = pNext_temp->box_w; + pNext->box_h = pNext_temp->box_h; + pNext->obj_type = pNext_temp->obj_type; + +#if 0 + printf("\n[jjjjj]pNext->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->number_row:%d\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->number_row); +#endif + + valid_bbox_idx++; + //printf("\n[start all nets]------66\n"); + } + + pNext1->arc = 0; + assign_row_number(PosInfo, pNext1, pNext2, total_element_size, g_element_size[iFeature_lpr_layer_index + 1][i], parent_index + i, &(pNext1->arc)); + + //printf("\n-----------arc %f\n", pNext1->arc); + + total_element_size += g_element_size[iFeature_lpr_layer_index + 1][i]; + temp_total_element_size += g_element_size[iFeature_lpr_layer_index + 1][i]; + + if (featureType & FEATURE_LPR_CNT) { + if (strcmp(pNext1->name, "L._Plate_CNT_VERTICAL") == 0) { + SortObjects(PosInfo + total_element_size - g_element_size[iFeature_lpr_layer_index + 1][i], g_element_size[iFeature_lpr_layer_index + 1][i]); + qsort(PosInfo + total_element_size - g_element_size[iFeature_lpr_layer_index + 1][i], g_element_size[iFeature_lpr_layer_index + 1][i], sizeof(detection_pos), sort_detection_pos_CNT); + } + else { + SortObjects(PosInfo + total_element_size - g_element_size[iFeature_lpr_layer_index + 1][i], g_element_size[iFeature_lpr_layer_index + 1][i]); + qsort(PosInfo + total_element_size - g_element_size[iFeature_lpr_layer_index + 1][i], g_element_size[iFeature_lpr_layer_index + 1][i], sizeof(detection_pos), sort_detection_pos); + } + } + //g_element_size[iFeature_lpr_layer_index + 1][i] = 0; + } + //printf("\n[start all nets]------67\n"); +#if 1 + + if (!(featureType & FEATURE_LPR_CNT)) + { + if (featureType & FEATURE_LPR_USA) { + SortObjects(PosInfo + total_element_size - temp_total_element_size, temp_total_element_size); + qsort(PosInfo + total_element_size - temp_total_element_size, temp_total_element_size, sizeof(detection_pos), sort_detection_pos_USA); + } + else { + SortObjects(PosInfo + total_element_size - temp_total_element_size, temp_total_element_size); + qsort(PosInfo + total_element_size - temp_total_element_size, temp_total_element_size, sizeof(detection_pos), sort_detection_pos); + } + } +#endif + pthread_mutex_unlock(&mutex_run_one_net); + + //g_pctrl_run_one_net_anpr->net_pair[iFeature_lpr_layer_index].valid_result_num = 0; + + //g_check_sync_anpr = 0; + //g_pctrl_run_one_net_anpr = pctrl; + switch_anpr = 1; + //g_check_sync_traffic = 0; + + + //printf("\n[start all nets]------68\n"); + } + } + } + } +#endif + } + else if (iFeature_lpr_layer_index >= 0 && idx == iFeature_lpr_layer_index + 1) { + continue; + } + else + { +#if 1 + //printf("\n-----------iFeature_traf_det_layer_index:%d\n", iFeature_traf_det_layer_index); + if (viewChannelData[0].enable_traffic) { + if (idx == iFeature_traf_det_layer_index || + idx == iFeature_traf_det_layer_index_2 || + idx == iFeature_access_ctrl_det_layer_index[0] || + idx == iFeature_access_ctrl_det_layer_index[1] || + idx == iFeature_access_ctrl_det_layer_index[2] || + idx == iFeature_access_ctrl_det_layer_index[3] || + idx == iFeature_aifire_det_layer_index || + idx == iFeature_aero_det_layer_index || + idx == iFeature_tof_det_layer_index || + (strcmp(WeightFileModeName, "mod003") != 0 && idx == iFeature_mask_layer_index) || + idx == iFeature_safety_layer_index || + idx == iFeature_rail_layer_index || + idx == iFeature_sports_layer_index || + idx == iFeature_animal_layer_index || + idx == iFeature_garbage_layer_index || + idx == iFeature_production_layer_index || + idx == iFeature_ship_layer_index) { + + //printf("\n-----------g_check_sync_traffic:%d\n", g_check_sync_traffic); + if (g_check_sync_traffic == 1) { + pthread_mutex_lock(&mutex_run_one_net); + + pctrl = g_pctrl_run_one_net; + pNext_t = g_PosInfo_traffic; + parent_index = 0; + + valid_bbox_idx = 0; + + //printf("\n-----------g_element_size_traffic[idx][0]:%d\n", g_element_size_traffic[idx][0]); + //printf("\n-------- pctrl->net_pair[idx].valid_result_num:%d\n", pctrl->net_pair[idx].valid_result_num); + + for (i = 0; i < g_element_size_traffic[idx][0]; i++) + { + + pNext = PosInfo + total_element_size + valid_bbox_idx; + pNext2 = g_PosInfo_traffic + temp_total_element_size_traffic + i; + + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, pNext2->name); +#if 1 + if (strlen(pNext->name) == 0) { + continue; + } +#endif + + pNext->width = pNext2->width; + pNext->height = pNext2->height; + pNext->center_x = pNext2->center_x; + pNext->center_y = pNext2->center_y; + pNext->center_direction = (float)DIRECTION_DEFAULT; + pNext->center_stability = (float)DIRECTION_DEFAULT; + + //printf("\n[start all nets]--------------5\n"); +#if 1 + if (enable_only_show_metadata1 == 1) { + int if_filter = 1; + + for (int z = 0; z < viewChannelData[tracking_channel_idx].count_zone; z++) + { + if (strlen(viewDetectionZone[tracking_channel_idx][z].metadata1) > 0) + { + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + for (int k = 0; k < g_metadata1_num_for_zone[z]; k++) { + if (strcmp(ObjectName, g_MetaOut1[z][k]) == 0 || + (strstr(g_MetaOut1[z][k], "plate") != NULL && strstr(ObjectName, "plate") != NULL)) { + int checkisInside = check_if_object_in_zone_simple_version_not_plate(pNext, z); + + //printf("\n----pNext->center_x:%f,pNext->width:%f,pNext->center_y:%f,pNext->height:%f\n", pNext->center_x, pNext->width, pNext->center_y, pNext->height); + //printf("\n--------checkisInside:%d\n", checkisInside); + if (checkisInside) { + if ((((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewDetectionZone[tracking_channel_idx][z].obj_max_proportion_in_zone) / 100.0)) || + (((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewDetectionZone[tracking_channel_idx][z].obj_min_proportion_in_zone) / 100.0)) + ) + { + + } + else { + g_Meta_If_Existing[z][k]++; + g_Meta_If_Existing_for_NAND[z][k] = 1; + } + } + + if_filter = 0; + break; + } + } + } + } + if (strstr("Traffic light color", pNext->name) || + strstr("counter count", pNext->name) + ) + { + if_filter = 1; + break; + } + if (if_filter) + { + //printf("filter name = %s \n", pNext->name); + continue; + } + } +#endif + + for (int z = 0; z < viewChannelData[tracking_channel_idx].count_zone; z++) + { + if (strlen(viewDetectionZone[tracking_channel_idx][z].metadata1) > 0) + { + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + + if (strcmp(viewDetectionZone[tracking_channel_idx][z].metadata_stop, ObjectName) == 0) { + g_check_if_metadata_stop_happened[z] = 1; + + gettimeofday(&now_t_metadata_stop, NULL); + s_now_t_metadata_stop = now_t_metadata_stop.tv_sec; //쬰 + s_last_t_metadata_stop[z] = s_now_t_metadata_stop; + } + + if (g_check_if_metadata_stop_happened[z] == 1) { + gettimeofday(&now_t_metadata_stop, NULL); + s_now_t_metadata_stop = now_t_metadata_stop.tv_sec; //쬰 + + + if ((s_now_t_metadata_stop - s_last_t_metadata_stop[z]) >= 2) { + s_last_t_metadata_stop[z] = s_now_t_metadata_stop; + g_check_if_metadata_stop_happened[z] = 0; + } + } + } + } + + //printf("\n[start all nets]--------------6\n"); + pNext->confidence = pNext2->confidence; + + pNext->engine_type = pNext2->engine_type;//layerFeatureType[layer_idx]; + pNext->engine_type2 = pNext2->engine_type2; + pNext->parent_idx = pNext2->parent_idx; + pNext->car_logo_idx = pNext2->car_logo_idx; + pNext->number_row = pNext2->number_row; + pNext->class_id = pNext2->class_id; + + pNext->left_x = pNext2->left_x; + pNext->top_y = pNext2->top_y; + + pNext->box_x = pNext2->box_x; + pNext->box_y = pNext2->box_y; + pNext->box_w = pNext2->box_w; + pNext->box_h = pNext2->box_h; + pNext->obj_type = pNext2->obj_type; + pNext->test_id = pNext2->test_id; + + pNext->image_id = pNext2->image_id; + //pNext->id_g_sub_PlateRecords = -1; + + pNext->color_id = pNext2->color_id; + pNext->sec_color_id = pNext2->sec_color_id; + +#ifdef GY_OS_AMBA + pNext->bbox_distance = pNext2->bbox_distance; + pNext->bbox_height = pNext2->bbox_height; +#endif + + strcpy(pNext->code_content,pNext2->code_content); + strcpy(pNext->properties.plate, pNext2->properties.plate); +#if 0 + printf("\npNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->code_content:%s\n", pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->code_content); +#endif + + //printf("\n[start all nets]--------------7\n"); + valid_bbox_idx++; + } + temp_total_element_size_traffic += g_element_size_traffic[idx][0]; + //printf("\n--------valid_bbox_idx:%d\n", valid_bbox_idx); + + //element_size[idx] = pctrl->net_pair[idx].valid_result_num; + //total_element_size += element_size[idx]; + + //element_size[idx] = valid_bbox_idx; + total_element_size += valid_bbox_idx; + + //printf("\n[start all nets]--------------8\n"); + + if (idx == iFeature_traf_det_layer_index && iFeature_logo_layer_index >= 0) + { + int temp_total_element_size = 0; + for (i = 0; i < g_element_size_traffic[iFeature_traf_det_layer_index][0]; i++) { + + + pNext1 = pNext_t + i; + pNext2 = PosInfo + total_element_size; + + + valid_bbox_idx = 0; + for (j = 0; j < g_element_size_traffic[iFeature_logo_layer_index][i]; j++) + { + pNext = PosInfo + total_element_size + valid_bbox_idx; + pNext_temp = g_PosInfo_traffic + g_element_size_traffic[iFeature_traf_det_layer_index][0] + temp_total_element_size + j; + + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, pNext_temp->name); + +#if 1 + if (strlen(pNext->name) == 0) { + continue; + } +#endif + + pNext->confidence = pNext_temp->confidence; + + pNext->engine_type = pNext_temp->engine_type; + pNext->engine_type2 = pNext_temp->engine_type2; + pNext->left_x = pNext_temp->left_x; + + pNext->top_y = pNext_temp->top_y; + pNext->width = pNext_temp->width; + pNext->height = pNext_temp->height; + pNext->center_x = pNext_temp->center_x; + pNext->center_y = pNext_temp->center_y; + pNext->center_direction = (float)DIRECTION_DEFAULT; + pNext->center_stability = (float)DIRECTION_DEFAULT; + pNext->parent_idx = pNext_temp->parent_idx; + pNext->number_row = pNext_temp->number_row; + pNext->class_id = pNext_temp->class_id; + //pNext->id_g_sub_PlateRecords = -1; + + pNext->box_x = pNext_temp->box_x; + + pNext->box_y = pNext_temp->box_y; + pNext->box_w = pNext_temp->box_w; + pNext->box_h = pNext_temp->box_h; + pNext->obj_type = pNext_temp->obj_type; + +#if 0 + printf("\npNext->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence); +#endif + valid_bbox_idx++; + + } + + //assign_row_number(PosInfo, pNext1, pNext2, total_element_size, g_element_size[iFeature_lpr_layer_index + 1][i], parent_index + i, &arc); + total_element_size += valid_bbox_idx; + temp_total_element_size += g_element_size_traffic[iFeature_logo_layer_index][i]; + + //g_element_size_traffic[iFeature_logo_layer_index][i] = 0; + } + } + else if (strcmp(WeightFileModeName, "mod003") == 0 && idx == iFeature_traf_det_layer_index && iFeature_mask_layer_index >= 0 ) + { + int temp_total_element_size = 0; + for (i = 0; i < pctrl->net_pair[iFeature_traf_det_layer_index].valid_result_num; i++) { + + + pNext1 = pNext_t + i; + pNext2 = PosInfo + total_element_size; + + + valid_bbox_idx = 0; + for (j = 0; j < g_element_size_traffic[iFeature_mask_layer_index][i]; j++) + { + pNext = PosInfo + total_element_size + valid_bbox_idx; + pNext_temp = g_PosInfo_traffic + g_element_size_traffic[iFeature_traf_det_layer_index][0] + temp_total_element_size + j; + + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, pNext_temp->name); + +#if 1 + if (strlen(pNext->name) == 0) { + continue; + } +#endif + + pNext->confidence = pNext_temp->confidence; + + pNext->engine_type = pNext_temp->engine_type; + pNext->engine_type2 = pNext_temp->engine_type2; + pNext->left_x = pNext_temp->left_x; + + pNext->top_y = pNext_temp->top_y; + pNext->width = pNext_temp->width; + pNext->height = pNext_temp->height; + pNext->center_x = pNext_temp->center_x; + pNext->center_y = pNext_temp->center_y; + pNext->center_direction = (float)DIRECTION_DEFAULT; + pNext->center_stability = (float)DIRECTION_DEFAULT; + pNext->parent_idx = pNext_temp->parent_idx; + pNext->number_row = pNext_temp->number_row; + pNext->class_id = pNext_temp->class_id; + //pNext->id_g_sub_PlateRecords = -1; + + pNext->box_x = pNext_temp->box_x; + + pNext->box_y = pNext_temp->box_y; + pNext->box_w = pNext_temp->box_w; + pNext->box_h = pNext_temp->box_h; + pNext->obj_type = pNext_temp->obj_type; + +#if 0 + printf("\npNext->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence); +#endif + valid_bbox_idx++; + + } + + //assign_row_number(PosInfo, pNext1, pNext2, total_element_size, g_element_size[iFeature_lpr_layer_index + 1][i], parent_index + i, &arc); + total_element_size += valid_bbox_idx; + temp_total_element_size += g_element_size_traffic[iFeature_mask_layer_index][i]; + + //g_element_size_traffic[iFeature_mask_layer_index][i] = 0; + } + } + + pthread_mutex_unlock(&mutex_run_one_net); + + //g_pctrl_run_one_net->net_pair[idx].valid_result_num = 0; + + //if (idx == iFeature_finial_index) + //{ + //g_check_sync_traffic = 0; + //g_pctrl_run_one_net = pctrl; + switch_traffic = 1; + //} + } + } + } +#endif + } + } + } + } + //else + //{ + //usSleep(SLEEP_RADAR_ALARM*1000); + //usSleep(1); + //if (unlockingKeyInnoFR == 0) { + //usSleep(50000); + //} + //} + //printf("\n[start all nets]------6---2\n"); + + /* + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + printf("\n end total element size:Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->number_row:%d,pNext->obj_type:%d,pNext->parent_idx:%d\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->number_row, pNext->obj_type, pNext->parent_idx); + }*/ + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #4:%lf ms\n", dw_FPS_time_delta); + + //printf("\n[start all nets]------6---3\n"); + if (enable_only_show_metadata1 == 1) { + for (int z = 0; z < viewChannelData[tracking_channel_idx].count_zone; z++) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[z]) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + + + } + else { + if (g_metadata1_num_for_zone[z] >= 1) { + + int temp_count = 0; + int temp_count_NAND = 0; + for (int k = 0; k < g_metadata1_num_for_zone[z]; k++) { + if (g_Meta_If_Existing[z][k] >= 1) { + temp_count++; + } + + if (g_Meta_If_Existing_for_NAND[z][k] == 1) { + temp_count_NAND++; + } + } + + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][z].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][z].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_ALL_OBJECTS) { + //printf("\n-----%d,%d\n", temp_count, g_metadata1_num_for_zone[z]); + if (temp_count == g_metadata1_num_for_zone[z] && g_metadata1_num_for_zone[z] >= 2) { + g_check_if_all_existing[z] = 1; + } + } + + if (trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) { + if (temp_count_NAND < g_metadata1_num_for_zone[z] && temp_count_NAND >= 1) { + g_check_if_NAND[z] = 1; + } + else { + g_check_if_NAND[z] = 0; + } + } + } + } + } + } + } + } + + //printf("\n[start all nets]------6111112\n"); + +#if defined GY_OS_AMBA + + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && viewChannelData[0].enable_traffic + && ( g_IsRadarDevice == 0 + || g_IsToFDevice == 1) && unlockingKeyInnoFR == 0) { + if (g_check_sync_differ == 1) { + + pNext_t = g_PosInfo_differ; + parent_index = 0; + + valid_bbox_idx = 0; + for (i = 0; i < g_total_element_size_differ; i++) + { + pNext = PosInfo + total_element_size + valid_bbox_idx; + pNext2 = g_PosInfo_differ + i; + + if (((((pNext2->width * pNext2->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext2->width * pNext2->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + strlen(pNext2->name) == 0 || + strncmp(pNext2->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext2->name, "_s", strlen("_s")) == 0 /*|| + pNext2->center_y / (float)g_ori_yuv_height < 0.053*/ + ) && pNext2->number_row != 2) + { + continue; + } + + pNext->confidence = pNext2->confidence; + pNext->confidence2 = pNext2->confidence2; + + memset(pNext->name, 0x00, sizeof(pNext->name)); + //strcpy(pNext->name, pNext2->name); + +#if defined GY_OS_AMBA + + if ((pNext->confidence < (double)atoi(viewChannelData[0].confidence_unknown_object) || + pNext->confidence2 < (double)atoi(viewChannelData[0].confidence2_unknown_object)) && pNext2->number_row != 2) + continue; +#else + if (pNext->confidence < (double)atoi(viewChannelData[0].confidence_unknown_object) || + pNext->confidence2 < (double)atoi(viewChannelData[0].confidence2_unknown_object)) + continue; + +#endif + strcpy(pNext->name, pNext2->name); +#if 0 + if (pNext2->height > 0 && pNext2->width > 0 && pNext2->number_row != 2) { + for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) + { + if (g_PostRecorderList[index_post].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[index_post].iIfUse == 1 && strcmp(g_PostRecorderList[index_post].name, "person") == 0) + { + if (g_PostRecorderList[index_post].box_w > 0 && g_PostRecorderList[index_post].box_h > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_PostRecorderList[index_post].box_x; + temp_A.top_y = g_PostRecorderList[index_post].box_y; + temp_A.width = g_PostRecorderList[index_post].box_w; + temp_A.height = g_PostRecorderList[index_post].box_h; + strcpy(temp_A.name, g_PostRecorderList[index_post].name); + + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext2); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext2->height / pNext2->width); + float compare_height_ratio = pNext2->height / temp_A.height; + float compare_width_ratio = pNext2->width / temp_A.width; + + if (pNext2->height / pNext2->width >= 1.25) { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + if (temp_A_iou > 0.15) { + memset(pNext->name, 0x00, sizeof(pNext->name)); + strcpy(pNext->name, "person"); + pNext->confidence = 80; + pNext->confidence2 = 80; + } + } + } + } + } + } + } +#endif + //printf("\n[start all nets]--------------5\n"); + + pNext->progress_bar = pNext2->progress_bar; + + pNext->engine_type = pNext2->engine_type;//layerFeatureType[layer_idx]; + pNext->engine_type2 = pNext2->engine_type2; + pNext->left_x = pNext2->left_x; + pNext->top_y = pNext2->top_y; + pNext->width = pNext2->width; + pNext->height = pNext2->height; + pNext->center_x = pNext2->center_x; + pNext->center_y = pNext2->center_y; + pNext->center_direction = (float)DIRECTION_DEFAULT; + pNext->center_stability = (float)DIRECTION_DEFAULT; + pNext->parent_idx = pNext2->parent_idx; + pNext->car_logo_idx = pNext2->car_logo_idx; + pNext->number_row = pNext2->number_row; + pNext->class_id = pNext2->class_id; + + pNext->box_x = pNext2->box_x; + pNext->box_y = pNext2->box_y; + pNext->box_w = pNext2->box_w; + pNext->box_h = pNext2->box_h; + pNext->obj_type = pNext2->obj_type; + pNext->test_id = pNext2->test_id; + + pNext->image_id = pNext2->image_id; + + pNext->color_id = pNext2->color_id; + pNext->sec_color_id = pNext2->sec_color_id; + +#if 0 + printf("\n---pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f\n", pNext->name, pNext->left_x, pNext->width, pNext->confidence); +#endif + + //printf("\n[start all nets]--------------7\n"); + valid_bbox_idx++; + } + + total_element_size += valid_bbox_idx; + //g_check_sync_differ = 0; + switch_differ = 1; + } + } + else if (strcmp(viewChannelData[0].enable_unknown_object, "No") == 0 && viewChannelData[0].enable_traffic) { + if (g_check_sync_differ == 1) { + //g_check_sync_differ = 0; + switch_differ = 1; + } + } + + +#endif + //printf("\n[start all nets]------777\n"); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #5:%lf ms\n", dw_FPS_time_delta); + + ai_frame_counter++; + + cJSON *root, *ai_engine, *detect_count, *detect, *id, *detection_zone_id, *detection_zone_id2, *detection_zone_id3, *detection_zone_id4, *detection_zone_id5, *detection_zone_id6, *detection_zone_id7, *detection_zone_id8, + *channel_id, *camera_name, *res_height, *res_width, *code_content,*number_row_temp, + *confidence, *confidence2, *engine_type, *class_id, *obj_tracking_id, + *obj_dwell_time, *color_id, *color, *sec_color_id, *sec_color, *trigger_type, *obj_type, *name_coco, *linked_plate, *x, *y, *w, *h, *parent_idx,*center_direction, *center_stability, + *properties, *plate, *country, *area, *area_id, *logo/*, *pose*/, *counter_count, *counter_zone,*counter_reset_value, *counter_operand,*something_vanish_in_zone,*progress_bar/*, *bbox_distance,*bbox_height, + *face_json_image, *face_json_name, *face_json_score, *face_json_tracking_uuid, *face_json_trackingId, *face_json_detection_confidence, *face_json_trackingState, *face_json_user, *face_json_group, *face_json_imagepath*/; + cJSON *base64_snapshot_size,*base64_snapshot, *base64_snapshot_response; + + cJSON *root_cloud, *ai_engine_cloud, *detect_count_cloud, *detect_cloud, *id_cloud, *detection_zone_id_cloud, *detection_zone_id2_cloud, *detection_zone_id3_cloud, *detection_zone_id4_cloud, *detection_zone_id5_cloud, *detection_zone_id6_cloud, *detection_zone_id7_cloud, *detection_zone_id8_cloud, + *channel_id_cloud, *camera_name_cloud, *res_height_cloud, *res_width_cloud, *code_content_cloud, *number_row_temp_cloud, + *confidence_cloud, *confidence2_cloud, *engine_type_cloud, *class_id_cloud, *obj_tracking_id_cloud, + *obj_dwell_time_cloud, *color_id_cloud, *color_cloud, *sec_color_id_cloud, *sec_color_cloud, *trigger_type_cloud, *obj_type_cloud, *name_coco_cloud, *linked_plate_cloud, *x_cloud, *y_cloud, *w_cloud, *h_cloud, *parent_idx_cloud, *center_direction_cloud, *center_stability_cloud, + *properties_cloud, *plate_cloud, *country_cloud, *area_cloud, *area_id_cloud, *logo_cloud/*, *pose_cloud*/, *counter_count_cloud, *counter_zone_cloud, *counter_reset_value_cloud, *counter_operand_cloud, *something_vanish_in_zone_cloud,*progress_bar_cloud/*, *bbox_distance_cloud, *bbox_height_cloud*/; + cJSON *trigger_type_name_cloud, *trigger_type_desc_cloud; + cJSON *cJSON_viewDetectionZone, *cJSON_a_zone, *cJSON_pts; + + cJSON *cJSON_counters/*, *cJSON_a_counter,*cJSON_objects_for_metadata,*cJSON_a_object_for_metadata*/; + cJSON *cJSON_counters_cloud/*, *cJSON_a_counter_cloud, *cJSON_objects_for_metadata_cloud, *cJSON_a_object_for_metadata_cloud*/; + cJSON *cJSON_alter_something, *cJSON_AI_fps/*,*cJSON_AI_fps2*/, *cJSON_ready_to_reboot, *cJSON_red_light; + + cJSON *car_type_name, *car_type_name_udp, *car_type_name_8592; + + cJSON *osd_array, *osd_color, *osd_size, *osd_sec, *osd_text, *osd_detect, *osd_encoder_id, *osd_font_size, *osd_outline_lilin, *enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content; + cJSON *outline_sw, *bg_tran, *osd_Time_sw, *osd_TimeStamp, *osd_TimeZoneInfo; + + cJSON *parking_space_check_table,*a_parking_space_check_table; + + cJSON *root_udp, *ai_engine_udp, *detect_count_udp, *detect_udp, *id_udp, /**detection_zone_id_udp, *detection_zone_id2_udp, *detection_zone_id3_udp, *detection_zone_id4_udp,*/ + *channel_id_udp, /**camera_name_udp,*/ *res_height_udp, *res_width_udp, *code_content_udp, *number_row_temp_udp, + *confidence_udp, /**confidence2_udp,*/ *engine_type_udp, *class_id_udp, *obj_tracking_id_udp, + *obj_dwell_time_udp, *color_id_udp, *color_udp,/* *sec_color_id_udp, *sec_color_udp, *trigger_type_udp,*/ *obj_type_udp, *name_coco_udp, *linked_plate_udp, *x_udp, *y_udp, *w_udp, *h_udp,/* *parent_idx_udp,*/ *center_direction_udp, + *properties_udp, *plate_udp, *country_udp, *area_udp, *area_id_udp, *logo_udp/*, *pose_udp*/, *counter_count_udp, *counter_zone_udp, *counter_reset_value_udp, *counter_operand_udp, *something_vanish_in_zone_udp/*, *progress_bar_udp*/; + + cJSON *cJSON_viewDetectionZone_udp, *cJSON_a_zone_udp, *cJSON_pts_udp,*cJSON_alter_something_udp/*,*cJSON_AI_fps_udp*/,*cJSON_ready_to_reboot_udp,*cJSON_red_light_udp, + *parking_space_check_table_udp,*a_parking_space_check_table_udp; + + cJSON *cJSON_counters_udp/*, *cJSON_a_counter_udp, *cJSON_objects_for_metadata_udp, *cJSON_a_object_for_metadata_udp*/; + cJSON *base64_snapshot_size_udp, *base64_snapshot_udp,*base64_snapshot_time_udp;//*base64_snapshot_response_udp + + cJSON *root_8592, *ai_engine_8592, *detect_count_8592, *detect_8592, *id_8592, *detection_zone_id_8592, *detection_zone_id2_8592, *detection_zone_id3_8592, *detection_zone_id4_8592, *detection_zone_id5_8592, *detection_zone_id6_8592, *detection_zone_id7_8592, *detection_zone_id8_8592, + *channel_id_8592, *camera_name_8592, *res_height_8592, *res_width_8592, *code_content_8592, *number_row_temp_8592, + *confidence_8592, *confidence2_8592, *engine_type_8592, *class_id_8592, *obj_tracking_id_8592, + *obj_dwell_time_8592, *color_id_8592, *color_8592, *sec_color_id_8592, *sec_color_8592/*, *trigger_type_8592*/, *obj_type_8592, *name_coco_8592, *linked_plate_8592, *x_8592, *y_8592, *w_8592, *h_8592, *parent_idx_8592, *center_direction_8592, *center_stability_8592, + *properties_8592, *plate_8592, *country_8592, *area_8592, *area_id_8592, *logo_8592/*, *pose_8592*/, *counter_count_8592, *counter_zone_8592, *counter_reset_value_8592, *counter_operand_8592, *something_vanish_in_zone_8592, *progress_bar_8592/*, *bbox_distance_8592, *bbox_height_8592*/; + + cJSON *cJSON_viewDetectionZone_8592, *cJSON_a_zone_8592, *cJSON_pts_8592, *cJSON_alter_something_8592, *cJSON_AI_fps_8592, *cJSON_ready_to_reboot_8592, *cJSON_red_light_8592, + *parking_space_check_table_8592, *a_parking_space_check_table_8592; + + cJSON *cJSON_counters_8592/*, *cJSON_a_counter_8592, *cJSON_objects_for_metadata_8592, *cJSON_a_object_for_metadata_8592*/; + cJSON *base64_snapshot_size_8592, /**base64_snapshot_response_8592,*/ *base64_snapshot_8592, *base64_snapshot_time_8592; + + cJSON *root_post, *ai_engine_post, *detect_count_post, *detect_post, *i_post, *idx_post, *zone_idx_post, *box_x_post, *box_y_post, *box_w_post, *box_h_post, *name_post, *id_post, *updatetime_post, *firstgettime_post, *count_trigger_post, *firstgettime_total_post; + + cJSON *root_long, *ai_engine_long, *detect_count_long, *detect_long, *i_long, *idx_long, *zone_idx_long, *box_x_long, *box_y_long, *box_w_long, *box_h_long, *name_long, *id_long, *updatetime_long, *firstgettime_long,*count_trigger_long, *firstgettime_total_long; + + char* JsonString = NULL; + char* JsonString_to_osd = NULL; + char* JsonString_to_udp = NULL; + char* JsonString_to_8592 = NULL; + char* JsonString_to_8592_no_image = NULL; + char JsonString_to_ipcam[BUFSIZE_V2] = { 0 }; + char *JsonString_cloud = NULL; + + char *JsonString_post = NULL; + char *JsonString_long = NULL; + + int Count_LPR = 0; + + + root = cJSON_CreateObject(); + root_cloud = cJSON_CreateObject(); + root_udp = cJSON_CreateObject(); + root_8592 = cJSON_CreateObject(); + + int check_if_something_vanish_in_zone_Yes[MAX_DETECTION_ZONE] = { 0 }; + + //printf("\n--------total_element_size #1: %d\n", total_element_size); + + /*end = clock(); + dur = (double)(end - start); + printf("\n[6]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + if (total_element_size > 0) + { +#if defined GY_OS_AMBA + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->width == 0 || + pNext->height == 0 || + IsANPRCategory(pNext->engine_type) || + IsANPRCategory_L_Plate(pNext->name) == 1) + continue; + + int count_overlap_ivs = 0; + //int count_overlap_big = 0; + //int count_overlap_big_so_far = 0; + + float last_max_iou = 0.0; + int last_j = -1; + + for (int j = 0; j < total_element_size; j++) + { + if (i != j) { + pNext_temp = PosInfo + j; + + if (pNext_temp->width == 0 || + pNext_temp->height == 0 || + IsANPRCategory(pNext_temp->engine_type) || + IsANPRCategory_L_Plate(pNext_temp->name) == 1) + continue; + + if (strcmp(pNext->name, "object") != 0 && strcmp(pNext_temp->name, "object") == 0 && pNext_temp->number_row != 2) + { + if (strcmp(pNext->name,"person") == 0 && detection_overlap_ratio(pNext, pNext_temp) > 0.45) + { + count_overlap_ivs++; + } +#if 0 + else if(strcmp(pNext->name, "car") == 0 && detection_overlap_ratio(pNext, pNext_temp) > 0.05) + { + count_overlap_big++; + count_overlap_big_so_far++; + } + else if (strcmp(pNext->name, "car") == 0 && detection_overlap_ratio(pNext, pNext_temp) > 0.0) + { + count_overlap_big_so_far++; + } +#endif + } + else if (strcmp(pNext->name, "object") == 0 && pNext->number_row != 2 && strcmp(pNext_temp->name, "object") != 0) { + + if (strcmp(pNext_temp->name,"person") == 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.45 && detection_overlap_ratio(pNext, pNext_temp) > last_max_iou) + { + if (last_j == -1) { + last_max_iou = detection_overlap_ratio(pNext, pNext_temp); + last_j = j; + } + else { + (PosInfo + last_j)->width = 0; + (PosInfo + last_j)->height = 0; + last_max_iou = detection_overlap_ratio(pNext, pNext_temp); + last_j = j; + } + } + } +#if 0 + else if (strcmp(pNext_temp->name, "car") == 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.05 && detection_overlap_ratio(pNext, pNext_temp) > last_max_iou) { + if (last_j == -1) { + last_max_iou = detection_overlap_ratio(pNext, pNext_temp); + last_j = j; + } + else { + (PosInfo + last_j)->width = 0; + (PosInfo + last_j)->height = 0; + last_max_iou = detection_overlap_ratio(pNext, pNext_temp); + last_j = j; + } + } + } +#endif + } + } + } + + if (strcmp(pNext->name, "object") != 0) { + if (strcmp(pNext->name, "person") == 0 && count_overlap_ivs == 0 && pNext->center_y <= g_ori_yuv_height * 2 / 3) { + pNext->width = 0; + pNext->height = 0; + } +#if 0 + else if (strcmp(pNext->name, "car") == 0 && count_overlap_big == 0 && pNext->center_y <= g_ori_yuv_height * 2 / 3 && pNext->center_y > g_ori_yuv_height * 1 / 3) { + pNext->width = 0; + pNext->height = 0; + } + else if (strcmp(pNext->name, "car") == 0 && count_overlap_big_so_far == 0 && pNext->center_y <= g_ori_yuv_height * 1 / 3) { + pNext->width = 0; + pNext->height = 0; + } +#endif + } + } + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->width == 0 || + pNext->height == 0 || + IsANPRCategory(pNext->engine_type) || + IsANPRCategory_L_Plate(pNext->name) == 1) + continue; + + if (strcmp(pNext->name, "object") == 0) { + if (pNext->center_y > g_ori_yuv_height * 3 / 4) { + pNext->width = 0; + pNext->height = 0; + continue; + } + } + + for (int j = 0; j < total_element_size; j++) + { + if (i != j) { + pNext_temp = PosInfo + j; + + if (pNext_temp->width == 0 || + pNext_temp->height == 0 || + IsANPRCategory(pNext_temp->engine_type) || + IsANPRCategory_L_Plate(pNext_temp->name) == 1) + continue; + + if (strcmp(pNext->name, "object") == 0 && pNext->number_row != 2 && strcmp(pNext_temp->name, "object") != 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + pNext->width = 0; + pNext->height = 0; + } + } + else if (strcmp(pNext->name, "object") == 0 && pNext->number_row != 2 && strcmp(pNext_temp->name, "object") == 0 && pNext_temp->number_row != 2){ + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { + pNext->width = 0; + pNext->height = 0; + } + else { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + } + } + else if (strcmp(pNext->name, "person") == 0 && strcmp(pNext_temp->name, "person") == 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { + pNext->width = 0; + pNext->height = 0; + } + else { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + } + } +#if 0 + else if (strcmp(pNext->name, "car") == 0 && strcmp(pNext_temp->name, "car") == 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.7){ + if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { + pNext->width = 0; + pNext->height = 0; + } + else { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + } + } +#endif + } + } + } +#if 0 + for (int i = 0; i < total_element_size; i++) + { + for (int j = 0; j < total_element_size; j++) + { + if (i != j) { + pNext = PosInfo + i; + pNext_temp = PosInfo + j; + + if (pNext->width == 0 || + pNext->height == 0 || + pNext_temp->width == 0 || + pNext_temp->height == 0 || + IsANPRCategory(pNext->engine_type) || + IsANPRCategory(pNext_temp->engine_type)) + continue; + + int check_if_combine = 0; + + if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, pNext_temp->name) == 0) { + if ((!IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name) == 0) + && (!IsANPRCategory(pNext_temp->engine_type) && IsANPRCategory_L_Plate(pNext_temp->name) == 0)) { + + if (pNext->engine_type == pNext_temp->engine_type && + pNext->engine_type2 == pNext_temp->engine_type2) { + + float iou_compare = detection_overlap_ratio(pNext, pNext_temp); + if (iou_compare > 0.7) { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + else if (iou_compare > 0.0) { + if (strcmp(pNext->name, "person") == 0) { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + else { + check_if_combine = 1; + } + } + } + } + } + else if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, pNext_temp->name) != 0 && strcmp(pNext_temp->name, "object") != 0 && (strcmp(pNext->name, "person") == 0 || strcmp(pNext_temp->name, "person") == 0)) { + if ((!IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name) == 0) + && (!IsANPRCategory(pNext_temp->engine_type) && IsANPRCategory_L_Plate(pNext_temp->name) == 0)) { + + if (pNext->engine_type == pNext_temp->engine_type && + pNext->engine_type2 == pNext_temp->engine_type2) { + + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + //check_if_combine = 1; + //lX{ + if (strcmp(pNext->name, "person") == 0) { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + else if (strcmp(pNext_temp->name, "person") == 0) { + pNext->width = 0; + pNext->height = 0; + } + } + } + } + } + else if (strcmp(pNext->name, "object") == 0 && pNext->number_row != 2 && strcmp(pNext_temp->name, "object") != 0) { + if (!IsANPRCategory(pNext_temp->engine_type) && IsANPRCategory_L_Plate(pNext_temp->name) == 0) + { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + pNext->width = 0; + pNext->height = 0; + } + } + } + else if (strcmp(pNext->name, "object") == 0 && pNext->number_row != 2 && strcmp(pNext_temp->name, "object") == 0 && pNext_temp->number_row != 2) { + if (!IsANPRCategory(pNext_temp->engine_type) && IsANPRCategory_L_Plate(pNext_temp->name) == 0) + { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + check_if_combine = 1; + } + } + } + + if (pNext->width == 0 || + pNext->height == 0 || + pNext_temp->width == 0 || + pNext_temp->height == 0) + { + + } + else { + + // 08-23 +#if 0 + if (check_if_combine == 1 && strcmp(pNext_temp->name, "object") != 0 && strcmp(pNext->name, "object") != 0) + { + // AT{O_Pv| + + int check_if_pNext_overlap_recorder = 0; + int check_if_pNext_temp_overlap_recorder = 0; + + for (int index_recoder = 0; index_recoder < MAX_POST_RECODER_SIZE; index_recoder++) + { + if (g_PostRecorderList[index_recoder].iIfUse == 0 && g_longterm_PostRecorderList[index_recoder].iIfUse == 0) { + break; + } + + if (g_longterm_PostRecorderList[index_recoder].iIfUse == 1) { + if (g_longterm_PostRecorderList[index_recoder].box_w > 0 && g_longterm_PostRecorderList[index_recoder].box_h > 0) + { + if (strcmp(pNext->name, g_longterm_PostRecorderList[index_recoder].name) == 0) + { + detection_pos PostRecoderTemp = { 0 }; + PostRecoderTemp.left_x = g_longterm_PostRecorderList[index_recoder].box_x; + PostRecoderTemp.top_y = g_longterm_PostRecorderList[index_recoder].box_y; + PostRecoderTemp.width = g_longterm_PostRecorderList[index_recoder].box_w; + PostRecoderTemp.height = g_longterm_PostRecorderList[index_recoder].box_h; + strcpy(PostRecoderTemp.name, g_longterm_PostRecorderList[index_recoder].name); + + float compare_height_ratio = pNext->height / PostRecoderTemp.height; + float compare_width_ratio = pNext->width / PostRecoderTemp.width; + + float fPostRecoderTempIou = detection_overlap_ratio(pNext, &PostRecoderTemp); + if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + check_if_pNext_overlap_recorder = 1; + } + } + + if (strcmp(pNext_temp->name, g_longterm_PostRecorderList[index_recoder].name) == 0) + { + detection_pos PostRecoderTemp = { 0 }; + PostRecoderTemp.left_x = g_longterm_PostRecorderList[index_recoder].box_x; + PostRecoderTemp.top_y = g_longterm_PostRecorderList[index_recoder].box_y; + PostRecoderTemp.width = g_longterm_PostRecorderList[index_recoder].box_w; + PostRecoderTemp.height = g_longterm_PostRecorderList[index_recoder].box_h; + strcpy(PostRecoderTemp.name, g_longterm_PostRecorderList[index_recoder].name); + + float compare_height_ratio = pNext_temp->height / PostRecoderTemp.height; + float compare_width_ratio = pNext_temp->width / PostRecoderTemp.width; + + float fPostRecoderTempIou = detection_overlap_ratio(pNext_temp, &PostRecoderTemp); + if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + check_if_pNext_temp_overlap_recorder = 1; + } + } + } + } + + if (g_PostRecorderList[index_recoder].iIfUse == 1) { + if (g_PostRecorderList[index_recoder].box_w > 0 && g_PostRecorderList[index_recoder].box_h > 0) + { + if (strcmp(pNext->name, g_PostRecorderList[index_recoder].name) == 0) + { + detection_pos PostRecoderTemp = { 0 }; + PostRecoderTemp.left_x = g_PostRecorderList[index_recoder].box_x; + PostRecoderTemp.top_y = g_PostRecorderList[index_recoder].box_y; + PostRecoderTemp.width = g_PostRecorderList[index_recoder].box_w; + PostRecoderTemp.height = g_PostRecorderList[index_recoder].box_h; + strcpy(PostRecoderTemp.name, g_PostRecorderList[index_recoder].name); + + float compare_height_ratio = pNext->height / PostRecoderTemp.height; + float compare_width_ratio = pNext->width / PostRecoderTemp.width; + + float fPostRecoderTempIou = detection_overlap_ratio(pNext, &PostRecoderTemp); + if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + check_if_pNext_overlap_recorder = 1; + } + } + + if (strcmp(pNext_temp->name, g_PostRecorderList[index_recoder].name) == 0) + { + detection_pos PostRecoderTemp = { 0 }; + PostRecoderTemp.left_x = g_PostRecorderList[index_recoder].box_x; + PostRecoderTemp.top_y = g_PostRecorderList[index_recoder].box_y; + PostRecoderTemp.width = g_PostRecorderList[index_recoder].box_w; + PostRecoderTemp.height = g_PostRecorderList[index_recoder].box_h; + strcpy(PostRecoderTemp.name, g_PostRecorderList[index_recoder].name); + + float compare_height_ratio = pNext_temp->height / PostRecoderTemp.height; + float compare_width_ratio = pNext_temp->width / PostRecoderTemp.width; + + float fPostRecoderTempIou = detection_overlap_ratio(pNext_temp, &PostRecoderTemp); + if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + check_if_pNext_temp_overlap_recorder = 1; + } + } + + } + } + + if (check_if_pNext_overlap_recorder == 1 && check_if_pNext_temp_overlap_recorder == 1) { + check_if_combine = 0; + break; + } + } + } +#endif + + if (check_if_combine == 1) { + float min_x_1 = pNext->left_x; + float min_y_1 = pNext->top_y; + float max_x_1 = pNext->left_x + pNext->width; + float max_y_1 = pNext->top_y + pNext->height; + + float min_x_2 = pNext_temp->left_x; + float min_y_2 = pNext_temp->top_y; + float max_x_2 = pNext_temp->left_x + pNext_temp->width; + float max_y_2 = pNext_temp->top_y + pNext_temp->height; + + float min_x_combine = min_x_1 <= min_x_2 ? min_x_1 : min_x_2; + float min_y_combine = min_y_1 <= min_y_2 ? min_y_1 : min_y_2; + float max_x_combine = max_x_1 >= max_x_2 ? max_x_1 : max_x_2; + float max_y_combine = max_y_1 >= max_y_2 ? max_y_1 : max_y_2; + + pNext->left_x = min_x_combine; + pNext->top_y = min_y_combine; + pNext->width = (max_x_combine - min_x_combine); + pNext->height = (max_y_combine - min_y_combine); + + pNext->center_x = pNext->left_x + pNext->width / 2.0; + pNext->center_y = pNext->top_y + pNext->height / 2.0; + + pNext->box_x = pNext->left_x; + pNext->box_y = pNext->top_y; + pNext->box_w = pNext->width; + pNext->box_h = pNext->height; + + pNext->confidence = (pNext->confidence + pNext_temp->confidence) / 2.0; + + if ((((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext->width * pNext->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < 0.0001) || + (((pNext->width) / ((float)g_ori_yuv_width)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext->width) / ((float)g_ori_yuv_width)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext->height) / ((float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext->height) / ((float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0))) + { + pNext->width = 0; + pNext->height = 0; + } + else { + if (strcmp(pNext->name, "object") == 0) { + float width_object_ratio = pNext->width / (float)g_ori_yuv_width; + float height_object_ratio = pNext->height / (float)g_ori_yuv_height; + + if (width_object_ratio > (float)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + height_object_ratio > (float)atoi(viewChannelData[0].unknown_object_max_proportion) / 100.0 || + width_object_ratio <= (float)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 || + height_object_ratio <= (float)atoi(viewChannelData[0].unknown_object_min_proportion) / 100.0 + ) + { + pNext->width = 0; + pNext->height = 0; + } + } + //else if (strcmp(pNext_temp->name, "person") == 0) { + //memset(pNext->name, 0x00, sizeof(pNext->name)); + //strcpy(pNext->name, "person"); + //} + } + + pNext_temp->width = 0; + pNext_temp->height = 0; + } + } + } + } + } +#endif + } + else +#endif + { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->width == 0 || + pNext->height == 0 || + IsANPRCategory(pNext->engine_type) || + IsANPRCategory_L_Plate(pNext->name) == 1) + continue; + + if (strcmp(pNext->name, "person") == 0) { + + for (int j = 0; j < total_element_size; j++) + { + if (i != j) { + pNext_temp = PosInfo + j; + + if (pNext_temp->width == 0 || + pNext_temp->height == 0 || + IsANPRCategory(pNext_temp->engine_type) || + IsANPRCategory_L_Plate(pNext_temp->name) == 1) + continue; + + if (strcmp(pNext->name, pNext_temp->name) == 0) { + if (pNext->engine_type == pNext_temp->engine_type && + pNext->engine_type2 == pNext_temp->engine_type2) { + + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + //check_if_combine = 1; + //if (strcmp(pNext->name, "person") == 0) + { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + } + } + } + } + } + } + } + } + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (pNext->width <= 0 || pNext->height <= 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + } + + /*for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + printf("\n end total element size:Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->number_row:%d,pNext->obj_type:%d,pNext->parent_idx:%d\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->number_row, pNext->obj_type, pNext->parent_idx); + }*/ + + + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + { + //Check Flip & mirror + //Mirror & Flip + Mirror_Flip_posInfo(PosInfo, total_element_size, g_ori_yuv_width, g_ori_yuv_height, IsPTZMirror(), IsPTZFlip()); + //printf("\n[start all nets] 55\n"); + //sort the objects by different variables + + ////HUwheACӨPWߥhsortC + //int sortLogicUSA = 0; + //if (IsANPRCategory(featureType)) + //sortLogicUSA = SortObjects(PosInfo, total_element_size); + //SortObjects(PosInfo, total_element_size); + + //sort the detection by parent_idx and obj_type and number_row and left_x + //if (sortLogicUSA) + //qsort(PosInfo, total_element_size, sizeof(detection_pos), sort_detection_pos_USA); + //else + //qsort(PosInfo, total_element_size, sizeof(detection_pos), sort_detection_pos); + + + + //lƨP + for (i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) + { + memset(pNext->properties.plate, 0x00, sizeof(pNext->properties.plate)); + memset(pNext->properties.country, 0x00, sizeof(pNext->properties.country)); + memset(pNext->properties.area, 0x00, sizeof(pNext->properties.area)); + memset(pNext->properties.logo, 0x00, sizeof(pNext->properties.logo)); + + if (strcmp(pNext->name, "ambulance") == 0 + || strcmp(pNext->name, "blank") == 0 + || strcmp(pNext->name, "stop_sign") == 0) { + strcpy(pNext->properties.plate, pNext->name); + } + else if (strcmp(pNext->name, "qrcode") == 0 + || strcmp(pNext->name, "barcode") == 0) { + strcpy(pNext->properties.plate, pNext->code_content); + } + else if (strcmp(pNext->name, "face") == 0) { +#if 0 + strcpy(pNext->properties.plate, pNext->FDFR.user_name); +#endif + } + + } + //printf("[%d] p_name 9 = %s ,id(%d)\n", i, pNext->name,pNext->class_id); + //printf("%s poddd = %f \n", pNext->name, pNext->left_x); + //printf("%s,%s poddd = %f \n", pNext->name, pNext->properties.plate, pNext->left_x); + } +#if 1 + + if (g_IsCustomWeight == 0) { + SetCorrectClassID(PosInfo, total_element_size, 0); + } + + //ambiguous plate number parsing, reqular expression, and unicode locale lanquage + if (IsANPRCategory(featureType)) + PlatePatternParser(PosInfo, total_element_size, stAMBAcontent->featureType/*, arc*/); +#endif +#if 1 + //replace ASCII strings with UTF8 strings in trans.names + ReplaceWithUTF8(PosInfo, total_element_size); + + //add number to plate object + if (IsANPRCategory(featureType)) { + /*for (int i = 0; i < total_element_size; i++) + { + printf("\n end total element size:Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->number_row:%d,pNext->obj_type:%d, pNext->properties.plate:%s\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->number_row, pNext->obj_type, pNext->properties.plate); + }*/ + AssignPlateNumber(PosInfo, total_element_size, stAMBAcontent->featureType); + ReplacePlateWithDB(PosInfo, total_element_size, featureType, tracking_channel_idx); + AddTWPlateDASH(PosInfo, total_element_size, featureType); + + if (featureType & FEATURE_LPR_MEA) { + MEAPlateRule(PosInfo, total_element_size); + } + + PlateFilterForParkingPlot(PosInfo, total_element_size, featureType, tracking_channel_idx); + ReplacePlateWithDB(PosInfo, total_element_size, featureType, tracking_channel_idx); + + /*for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + //if (IsANPRCategory(pNext->engine_type)) + //{ + //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + //} + + //if (IsANPRCategory_L_Plate(pNext->name)) { + //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, pNext->properties.plate, (int)pNext->top_y, pNext->confidence); + //} + }*/ + /* + for (int i = 0; i < total_element_size; i++) + { + printf("\n end total element size:Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->number_row:%d,pNext->obj_type:%d, pNext->properties.plate:%s\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->number_row, pNext->obj_type, pNext->properties.plate); + } + */ + } +#endif + }//if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + + //Check Cold Zone +#if 0 + int iZontToPreset = 0; + if (g_IsPTZDevice == 1) { + if (viewDetectionZone[0][0].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][0].ptz_zone_to_preset) > 0) + { + iZontToPreset = atoi(viewDetectionZone[0][0].ptz_zone_to_preset); + } + } +#endif + + if (IsEnableColdZone() && (g_IsRadarDevice == 0)) + { +#if 0 + if (g_IsPTZDevice == 1 && viewChannelData[0].enable_traffic == 1) //don't merge vvvvv + { + //ptz_zone_to_preset : viewDetectionZone[n][i].ptz_zone_to_preset + if (IsPTZinPreset() != 0 + && IsPTZinPreset() == iZontToPreset) + + { + ColdObjectCheck(PosInfo, total_element_size, g_ori_yuv_width, g_ori_yuv_height); + } + } + else +#endif + { + ColdObjectCheck(PosInfo, total_element_size, g_ori_yuv_width, g_ori_yuv_height); + } + } + + //for (int i = 0; i < total_element_size; i++) + //{ + //pNext = PosInfo + i; + //if (IsANPRCategory_L_Plate(pNext->name)) + //{ + //printf("%d plate %d name = %s - %s - %d ; confidence: %f\n", i, pNext->parent_idx, pNext->properties.plate, pNext->name, (int)pNext->top_y, pNext->confidence); + //} + //} + + //printf("\nstart total element size : %d\n", (int)total_element_size); + + //Remove object that the FOV is too big. + +//#if 0 + //StripDetectedObjects(PosInfo, &total_element_size, g_ori_yuv_width, g_ori_yuv_height, atoi(viewChannelData[tracking_channel_idx].obj_min_proportion), atoi(viewChannelData[tracking_channel_idx].obj_max_proportion), atoi(viewChannelData[tracking_channel_idx].min_characters), atoi(viewChannelData[tracking_channel_idx].max_characters), atoi(viewChannelData[tracking_channel_idx].confidence), atoi(viewChannelData[tracking_channel_idx].confidence2), atoi(viewChannelData[tracking_channel_idx].confidence3), atoi(viewChannelData[tracking_channel_idx].confidence4)); +//#endif + //printf("== AFT ANPR \n"); + + + //printf("\nend total element size : %d\n", (int)total_element_size); + + //zPosInfoARPLTAҦp@ӦrABBBCB5B6B7B8C + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + if (strlen(pNext->name) == 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (pNext->width <= 0 || pNext->height <= 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (pNext->confidence <= stAMBAcontent->confidence_plate && IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name) == 1 && + strcmp(pNext->name, "face") != 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (pNext->confidence <= stAMBAcontent->confidence_plate && unlockingKeyInnoFR == 1 && viewChannelData[0].enable_face == 1) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (strcmp(ObjectName, "object") != 0 && + strcmp(ObjectName, "tampering") != 0 && + strcmp(ObjectName, "face") != 0 && + pNext->confidence <= stAMBAcontent->confidence_traffic && + (!IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name) == 0)) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (strcmp(ObjectName, "object") == 0 && (pNext->confidence < (double)atoi(viewChannelData[0].confidence_unknown_object) || pNext->confidence2 < (double)atoi(viewChannelData[0].confidence2_unknown_object))) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (pNext->obj_type == _NUMBER) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (IsANPRCategory(pNext->engine_type)) { + if (IsANPRCategory_L_Plate(pNext->name)) { + //printf("\n end total element size:pNext->engine_type:%d,Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,plate:%s\n", pNext->engine_type, pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->properties.plate); + } + else { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + } + } + } //if (g_IsRadarDevice == 0 && g_IsRadarDevice == 0) + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #6:%lf ms\n", dw_FPS_time_delta); + + //printf("\n--------total_element_size #2: %d\n", total_element_size); + int count_behavior_id = 0; + int count_behavior_id_larger_zero = 0; + int count_behavior_id_larger_zero_udp = 0; + + //Onvif data format + onvif_data onvif_object[50] = { 0 }; + onvif_counter_info onvif_counter[MAX_EVENT_COUNTERS] = { 0 }; + + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + onvif_counter[index_counter].onvif_detect_event_id = 0; + } + + int onvif_obj_number = 0; + + clear_PostRecorderList(); + + int index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + int size_g_PostRecorderList = 0; + + int index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; + int size_g_PostRecorderList_longterm = 0; + + int check_if_show_parking = 0; + + if (total_element_size > 0) + { + time_t now_time = time(0); + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (IsANPRCategory(pNext->engine_type)) + continue; + + double iDiffSec_temp = 0.0; + + if (strcmp(pNext->name, "object") != 0 && pNext->width > 0 && pNext->height > 0) + { + int temp_index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + int temp_size_g_PostRecorderList = 0; + + int temp_index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; + int temp_size_g_PostRecorderList_longterm = 0; + + for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) + { + if (g_PostRecorderList[index_post].iIfUse == 0 && g_longterm_PostRecorderList[index_post].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[index_post].iIfUse == 1 && strcmp(g_PostRecorderList[index_post].name, "object") != 0 /*&& pNext->zone_violation_idx[g_PostRecorderList[index_post].zone_idx] == 1*/) + { + if (g_PostRecorderList[index_post].box_w > 0 && g_PostRecorderList[index_post].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_PostRecorderList[index_post].box_x; + temp_A.top_y = g_PostRecorderList[index_post].box_y; + temp_A.width = g_PostRecorderList[index_post].box_w; + temp_A.height = g_PostRecorderList[index_post].box_h; + strcpy(temp_A.name, g_PostRecorderList[index_post].name); + + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + g_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + g_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + if (strcmp(g_PostRecorderList[index_post].name, pNext->name) == 0) + { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + } + else { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + } + else { + if (strcmp(pNext->name, "person") == 0) { + //uɶs + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + //if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + //index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + //size_g_PostRecorderList++; + //} + } + + //if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + //temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + //temp_size_g_PostRecorderList++; + //} + } + } + } + } + } + } + } + + if (/*strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && */g_longterm_PostRecorderList[index_post].iIfUse == 1 && strcmp(g_PostRecorderList[index_post].name, "object") != 0 /*&& pNext->zone_violation_idx[g_longterm_PostRecorderList[index_post].zone_idx] == 1*/) + { + if (g_longterm_PostRecorderList[index_post].box_w > 0 && g_longterm_PostRecorderList[index_post].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_longterm_PostRecorderList[index_post].box_x; + temp_A.top_y = g_longterm_PostRecorderList[index_post].box_y; + temp_A.width = g_longterm_PostRecorderList[index_post].box_w; + temp_A.height = g_longterm_PostRecorderList[index_post].box_h; + strcpy(temp_A.name, g_longterm_PostRecorderList[index_post].name); + + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + if (strcmp(g_longterm_PostRecorderList[index_post].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + } + else { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + } + else { + if (strcmp(pNext->name, "person") == 0) { + //uɶs + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + //if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + //index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + //size_g_PostRecorderList_longterm++; + //} + } + + //if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + //temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + //temp_size_g_PostRecorderList_longterm++; + //} + } + } + } + } + } + } + } + } + + + if (pNext->width == 0 || (strcmp(pNext->name, "person") == 0 && pNext->height / pNext->width < 1.25)) + { + pNext->width = 0; + pNext->height = 0; + } + else { +#if 1 + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) + { + int check_if_object_in_parking_zone = 0; + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + for (int index_trigger = 0; index_trigger < MAX_TRIGGER_EVENT; index_trigger++) + { + if (viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[index_trigger].checked >= 1) + { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[index_trigger].detect_event_id); + if (trigger_event_type == (unsigned int)TRIGGER_PARKING_VIOLATION || + trigger_event_type == (unsigned int)TRIGGER_MISSING_UNATTENDED || + trigger_event_type == (unsigned int)TRIGGER_TAMPERING || + trigger_event_type == (unsigned int)TRIGGER_QUEUING_VIOLATION || + trigger_event_type == (unsigned int)TRIGGER_MISSING_OBJECT_DETECTION || + trigger_event_type == (unsigned int)TRIGGER_ALL_OBJECTS || + trigger_event_type == (unsigned int)TRIGGER_LACK_OF_ANY_OBJECT || + trigger_event_type == (unsigned int)TRIGGER_FORGET_TO_GIVE_WAY) + { + check_if_show_parking = 1; + + int temp_check_if_object_in_parking_zone = check_if_object_in_zone_simple_version(pNext, index_zone); + if (temp_check_if_object_in_parking_zone == 1) { + check_if_object_in_parking_zone = 1; + } + } + break; + } + } + + if (check_if_object_in_parking_zone == 1) { + break; + } + } + + + g_check_if_show_parking = check_if_show_parking; + + if (check_if_object_in_parking_zone == 0) { + double dTime = -1.0, dTime_long = -1.0; + + //int count_trigger_post = 0; + //int count_trigger_long = 0; + + //if (store_post_ok >= 0) + { + for (int index_post = 0; index_post < temp_size_g_PostRecorderList; index_post++) + { + double temp_dTime = difftime(now_time, g_PostRecorderList[temp_index_g_PostRecorderList[index_post]].t_FirstGetTime_total); + if (temp_dTime > dTime) { + dTime = temp_dTime; + } + + //if (g_PostRecorderList[temp_index_g_PostRecorderList[index_post]].count_trigger > count_trigger_post) { + //count_trigger_post++; + //} + } + } + + //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) + { + //if (store_long_ok >= 0) + { + for (int index_post = 0; index_post < temp_size_g_PostRecorderList_longterm; index_post++) + { + double temp_dTime = difftime(now_time, g_longterm_PostRecorderList[temp_index_g_PostRecorderList_longterm[index_post]].t_FirstGetTime_total); + if (temp_dTime > dTime_long) { + dTime_long = temp_dTime; + } + + //if (g_longterm_PostRecorderList[temp_index_g_PostRecorderList_longterm[index_post]].count_trigger > count_trigger_long) { + //count_trigger_long++; + //} + } + } + } + + double thres_dwell_to_the_same_location = (double)atoi(heartbeatData.dwell_to_the_same_location); + if (strcmp(SystemSetting.enable_dwell_bounding_box, "Yes") == 0) { + if (((/*((int)(pNext->center_stability) == DIRECTION_DEFAULT) ||*/ (dTime > 3.0/*&& count_trigger_post >= 3*/) || (dTime_long > 3.0 /*&& count_trigger_long >= 2*/)) && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext) || strcmp(pNext->name, "person") == 0) + ) /*|| (strcmp(pNext->name, "person") == 0 && dTime > 300.0)*/) + { + pNext->width = 0; + pNext->height = 0; + } + } + else { + if (((/*((int)(pNext->center_stability) == DIRECTION_DEFAULT) ||*/ (dTime >= (double)atoi(heartbeatData.dwell_to_the_same_location) /*&& count_trigger_post >= 3*/) || (dTime_long >= thres_dwell_to_the_same_location /*&& count_trigger_long >= 2*/)) && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext) || strcmp(pNext->name, "person") == 0) + ) /*|| (strcmp(pNext->name, "person") == 0 && dTime > 300.0)*/) { + pNext->width = 0; + pNext->height = 0; + } + } + } + } +#endif + } + } + + if (pNext->width > 0 && pNext->height > 0) { + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + if (index_zone < viewChannelData[0].count_zone) { + pNext->check_if_within_zone[index_zone] = check_if_object_in_zone_width_zone(pNext->center_x, pNext->center_y, pNext->width, pNext->height, g_ori_yuv_width, g_ori_yuv_height, 0, index_zone); + } + else { + pNext->check_if_within_zone[index_zone] = 0; + } + } + } + } + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (pNext->width <= 0 || pNext->height <= 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + } + } + + if (total_element_size > 0) + { + + /*for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + printf("\n end total element size:Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f,pNext->number_row:%d,pNext->obj_type:%d,pNext->parent_idx:%d\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence, pNext->number_row, pNext->obj_type, pNext->parent_idx); + }*/ + + //-------------------------------------------------------------------------------------------------------------------------- + //trigger iJI Jim 20210219 + + /*end = clock(); + dur = (double)(end - start); + printf("\n[6-2]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ +#if 1 + if (g_IsRadarDevice == 0) { + time_t now_time = time(0); + GetObjectTrackingIDNew(PosInfo, &total_element_size, tracking_channel_idx, now_time, g_ori_yuv_width, g_ori_yuv_height); + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #6 #1:%lf ms\n", dw_FPS_time_delta); + +#if 0 + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (IsANPRCategory(pNext->engine_type)) + continue; + + if (strcmp(pNext->name, "object") != 0 && pNext->width > 0 && pNext->height > 0 && pNext->trigger_type == 0) + { + int check_if_within_zone = 0; + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + if (index_zone < viewChannelData[0].count_zone) { + if (pNext->check_if_within_zone[index_zone]) { + check_if_within_zone = 1; + break; + } + } + } + if (check_if_within_zone == 0) { + if (pNext->center_stability == (float)DIRECTION_DEFAULT) { + pNext->width = 0; + pNext->height = 0; + } + } + } + } + } +#endif + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_tracking_id_idx < 0 || pNext->obj_tracking_id <= 0 || strlen(pNext->name)==0 || + pNext->width <= 0 || pNext->height <= 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + } + + + ObjectFilterForParkingPlot(PosInfo, total_element_size, featureType, tracking_channel_idx); + } + else + { + //GetObjectTrackingIDRadar(PosInfo, total_element_size, tracking_channel_idx, now_time, g_radar_img_width, g_radar_img_height); + } +#endif + if (iFeature_logo_layer_index >= 0) + { + set_logo_to_plate_or_vehicle(PosInfo, total_element_size); + } + + MissingObjectDetection_VanishInZone(tracking_channel_idx); + + //#if 0 + //-------------------------------------------------------------------------------------------------------------------------- + //IplImage* ipl_img = load_IplImage_mem(image_buff, &image_buff_size, nets[0].w, nets[0].h, nets[0].c, &ratio_w, &ratio_h, imageType, yuv_width, yuv_height, yuv_height, yuv_width); + //float test_h = 700, test_w = 1500; //true distance + //Get object soceal distance + //GetObjectSocialDistance(PosInfo, total_element_size, tracking_channel_idx, ipl_img, test_h, test_w); + //---------------------------------------------------------------------------------------------------- + //#endif + //printf("\nend total element size #1: %d\n", (int)total_element_size); + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) + { + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + if (pNext->obj_tracking_id_idx < 0 || pNext->obj_tracking_id <= 0) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + else if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && + (strcmp(pNext->name, "ambulance") != 0) && (strcmp(pNext->name, "blank") != 0) && (strcmp(pNext->name, "stop_sign") != 0) + && (strcmp(pNext->name, "face") != 0) && !(strlen(pNext->properties.logo) >= 1 && strcmp(pNext->name, pNext->properties.logo) == 0)) + { + if (pNext->properties.plate_length < atoi(viewChannelData[0].min_characters) || + pNext->properties.plate_length > atoi(viewChannelData[0].max_characters)) + { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + } + else if (enable_only_show_metadata1 == 1 && IsANPRCategory_L_Plate(pNext->name) == 0 && !(strlen(pNext->properties.logo) >= 1 && strcmp(pNext->name, pNext->properties.logo) == 0)) { + int if_filter = 1; + + if (strcmp(ObjectName, "object") == 0 || strcmp(ObjectName, "bg_learning") == 0 || strcmp(ObjectName, "tampering") == 0 || strcmp(ObjectName, "tof_point") == 0 || strcmp(ObjectName, "face") == 0) + if_filter = 0; + else if (strstr("Traffic light color", pNext->name) || strstr("counter count", pNext->name)) + if_filter = 0; + else if (strcmp(ObjectName, "radar") == 0) + if_filter = 0; + else { + for (int z = 0; z < viewChannelData[tracking_channel_idx].count_zone; z++) + { + if (strlen(viewDetectionZone[tracking_channel_idx][z].metadata1) > 0) + { + for (int k = 0; k < g_metadata1_num_for_zone[z]; k++) { + if (strcmp(ObjectName, g_MetaOut1[z][k]) == 0 || + (strstr(g_MetaOut1[z][k], "plate") != NULL && strstr(ObjectName, "plate") != NULL)) { + if_filter = 0; + break; + } + } + } + } + } + + if (if_filter) { + for (int j = i; j < total_element_size; j++) { + if (j < total_element_size - 1) { + PosInfo[j] = PosInfo[j + 1]; + } + } + i--; + total_element_size--; + } + } + } + } + } + +#ifdef GY_OS_AMBA + if (g_IsPTZDevice == 1 && viewChannelData[0].enable_traffic == 1) { + PTZUpdateTrackingInfo(PosInfo, total_element_size, g_ori_yuv_width, g_ori_yuv_height); + } +#endif + //printf("\nend total element size : %d\n", (int)total_element_size); + if (total_element_size > 0) + { + //printf("\nend total element size : %d\n", (int)total_element_size); + + + /*for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + if (IsANPRCategory(pNext->engine_type)) + { + printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); + //printf("\n end total element size:Next->top_y:%f,pNext->name:%s,pNext->left_x:%f,pNext->width:%f,pNext->confidence:%f\n", pNext->top_y, pNext->name, pNext->left_x, pNext->width, pNext->confidence); + } + }*/ + + /*end = clock(); + dur = (double)(end - start); + printf("\n[6-5]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + + ///getalarmmotion + + ai_engine = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "AiEngine", ai_engine); + + ai_engine_cloud = cJSON_CreateArray(); + cJSON_AddItemToObject(root_cloud, "AiEngine", ai_engine_cloud); + + ai_engine_udp = cJSON_CreateArray(); + cJSON_AddItemToObject(root_udp, "AiEngine", ai_engine_udp); + + ai_engine_8592 = cJSON_CreateArray(); + cJSON_AddItemToObject(root_8592, "AiEngine", ai_engine_8592); + +#ifdef GY_OS_AMBA + int heatmap_center_x[MAX_TRACKING_NUM] = { 0 }; + int heatmap_center_y[MAX_TRACKING_NUM] = { 0 }; +#endif + +#if 1 + int check_if_send_udp_jpeg = 0; + + for (int i = 0; i < total_element_size /*&& unlockingKeyInnoFR == 0*/; i++) + { + //printf("\n[start all nets] while 10-1\n"); + pNext = PosInfo + i; /** sizeof(detection_pos)*/ + + int check_if_cloud_have_been_post = 0; + int store_post_ok = -1; + int store_long_ok = 0; + + int temp_index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; + int temp_size_g_PostRecorderList = 0; + + int temp_index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; + int temp_size_g_PostRecorderList_longterm = 0; + + int check_if_object_OK = 0; + int index_object = -1; + int index_plate = -1; + + if (strcmp(heartbeatData.enable_obj_once_to_post, "Yes") == 0) { + if (IsANPRCategory(pNext->engine_type)) { + for (int m = 0; m < MAX_PLATE_RECORDER; m++) + { + if (g_PlateRecorderList[m].iIfUse == 1) { + if (strlen(g_PlateRecorderList[m].sPlateNumber) > 0 + //&& strcmp(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) + && LevenshteinDistance(pNext->properties.plate, g_PlateRecorderList[m].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) + { + index_plate = m; + break; + } + } + } + } + else { + for (int m = 0; m < MAX_OBJECT_RECORDER; m++) + { + if (g_ObjectRecorderList[m].iIfUse == 1) { + if (g_ObjectRecorderList[m].iTrackingID == pNext->obj_tracking_id) { + index_object = m; + break; + } + } + } + } + } + + { + time_t now_time = time(0); + double iDiffSec_temp = 0.0; + + double max_dwell_short = 0.0; + + if (strcmp(pNext->name, "object") != 0 && pNext->width > 0 && pNext->height > 0) + { + for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) + { + if (g_PostRecorderList[index_post].iIfUse == 0 && g_longterm_PostRecorderList[index_post].iIfUse == 0) { + break; + } + + if (g_PostRecorderList[index_post].iIfUse == 1 /*&& pNext->zone_violation_idx[g_PostRecorderList[index_post].zone_idx] == 1*/) + { + if (g_PostRecorderList[index_post].box_w > 0 && g_PostRecorderList[index_post].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_PostRecorderList[index_post].box_x; + temp_A.top_y = g_PostRecorderList[index_post].box_y; + temp_A.width = g_PostRecorderList[index_post].box_w; + temp_A.height = g_PostRecorderList[index_post].box_h; + strcpy(temp_A.name, g_PostRecorderList[index_post].name); + + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + + double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + g_PostRecorderList[index_post].t_UpdateTime = now_time; + g_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + g_PostRecorderList[index_post].t_UpdateTime = now_time; + g_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + { + if (strcmp(g_PostRecorderList[index_post].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + + g_PostRecorderList[index_post].t_UpdateTime = now_time; + g_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + } + else { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); + if (temp_dTime > max_dwell_short) { + max_dwell_short = temp_dTime; + } + g_PostRecorderList[index_post].t_UpdateTime = now_time; + g_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList; index_check++) { + if (index_g_PostRecorderList[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 1.0) { + g_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = index_post; + size_g_PostRecorderList++; + } + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = index_post; + temp_size_g_PostRecorderList++; + } + } + } + } + } + } + } + } + + if (g_longterm_PostRecorderList[index_post].iIfUse == 1 /*&& pNext->zone_violation_idx[g_longterm_PostRecorderList[index_post].zone_idx] == 1*/) + { + if (g_longterm_PostRecorderList[index_post].box_w > 0 && g_longterm_PostRecorderList[index_post].box_h > 0 && pNext->width > 0 && pNext->height > 0) { + detection_pos temp_A = { 0 }; + temp_A.left_x = g_longterm_PostRecorderList[index_post].box_x; + temp_A.top_y = g_longterm_PostRecorderList[index_post].box_y; + temp_A.width = g_longterm_PostRecorderList[index_post].box_w; + temp_A.height = g_longterm_PostRecorderList[index_post].box_h; + strcpy(temp_A.name, g_longterm_PostRecorderList[index_post].name); + + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext); + //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); + float compare_height_ratio = pNext->height / temp_A.height; + float compare_width_ratio = pNext->width / temp_A.width; + + if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) + { + if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) + { + if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + else { + if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + { + if (strcmp(g_longterm_PostRecorderList[index_post].name, pNext->name) == 0) { + if (strcmp(pNext->name, "person") == 0) { + //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) + { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + } + else { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; + g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; + + int check_if_existing_in_post = 0; + for (int index_check = 0; index_check < size_g_PostRecorderList_longterm; index_check++) { + if (index_g_PostRecorderList_longterm[index_check] == index_post) { + check_if_existing_in_post = 1; + break; + } + } + if (check_if_existing_in_post == 0) { + iDiffSec_temp = difftime(now_time, g_longterm_PostRecorderList[index_post].t_FirstGetTime); + if (iDiffSec_temp >= 30.0 * (double)atoi(heartbeatData.dwell_to_the_same_location)) { + g_longterm_PostRecorderList[index_post].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[index_post].count_trigger++; + } + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = index_post; + size_g_PostRecorderList_longterm++; + } + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = index_post; + temp_size_g_PostRecorderList_longterm++; + } + } + } + } + } + } + } + } + } + } + + int record_zone_id = -1; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + if (pNext->zone_violation_idx[index_zone] == 1) { + record_zone_id = index_zone; + break; + } + } + + if (pNext->trigger_type >= 1 && temp_size_g_PostRecorderList_longterm == 0 && strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { + for (int j = 0; j < MAX_POST_RECODER_SIZE; j++) + { + if (g_longterm_PostRecorderList[j].iIfUse == 0) + { + g_longterm_PostRecorderList[j].iIfUse = 1; + g_longterm_PostRecorderList[j].t_FirstGetTime = now_time; + g_longterm_PostRecorderList[j].t_FirstGetTime_total = now_time; + g_longterm_PostRecorderList[j].t_UpdateTime = now_time; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_longterm_PostRecorderList[j].check_if_post[m] = 0; + } + g_longterm_PostRecorderList[j].check_if_cloud = 0; + g_longterm_PostRecorderList[j].check_if_cloud_v2 = 0; + g_longterm_PostRecorderList[j].check_if_cloud_record_v2 = 0; + g_longterm_PostRecorderList[j].check_if_email = 0; + g_longterm_PostRecorderList[j].check_if_ftp = 0; + g_longterm_PostRecorderList[j].check_if_getalarmmotion = 0; + + g_longterm_PostRecorderList[j].box_x = pNext->left_x + pNext->width / 3.0; + g_longterm_PostRecorderList[j].box_y = pNext->top_y + pNext->height / 3.0; + g_longterm_PostRecorderList[j].box_w = pNext->width / 3.0; + g_longterm_PostRecorderList[j].box_h = pNext->height / 3.0; + + g_longterm_PostRecorderList[j].object_id = pNext->obj_tracking_id; + g_longterm_PostRecorderList[j].zone_idx = record_zone_id; + if (IsANPRCategory_L_Plate(pNext->name)) { + strcpy(g_longterm_PostRecorderList[j].sPlateNumber, pNext->properties.plate); + } + else { + strcpy(g_longterm_PostRecorderList[j].sPlateNumber, ""); + } + strcpy(g_longterm_PostRecorderList[j].name, pNext->name); + + g_longterm_PostRecorderList[j].count_trigger = 1; + //g_longterm_PostRecorderList[j].the_same_id = 0; + + if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = j; + size_g_PostRecorderList_longterm++; + } + + if (temp_size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList_longterm[temp_size_g_PostRecorderList_longterm] = j; + temp_size_g_PostRecorderList_longterm++; + } + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + //pNext->check_if_having_been_counted[index_zone] = 0; + //if (pNext->obj_tracking_id_idx >= 0) { + //g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[index_zone] = 0; + //} + if (index_object >= 0) { + g_ObjectRecorderList[index_object].check_if_counted[index_zone] = 0; + } + if (index_plate >= 0) { + g_PlateRecorderList[index_plate].check_if_counted[index_zone] = 0; + } + } + break; + } + } + } + + if (temp_size_g_PostRecorderList == 0 && strcmp(pNext->name, "object") != 0) { + for (int j = 0; j < MAX_POST_RECODER_SIZE; j++) + { + if (g_PostRecorderList[j].iIfUse == 0) + { + g_PostRecorderList[j].iIfUse = 1; + g_PostRecorderList[j].t_FirstGetTime = now_time; + g_PostRecorderList[j].t_FirstGetTime_total = now_time; + g_PostRecorderList[j].t_UpdateTime = now_time; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[j].check_if_post[m] = 0; + } + g_PostRecorderList[j].check_if_cloud = 0; + g_PostRecorderList[j].check_if_cloud_v2 = 0; + g_PostRecorderList[j].check_if_cloud_record_v2 = 0; + g_PostRecorderList[j].check_if_email = 0; + g_PostRecorderList[j].check_if_ftp = 0; + g_PostRecorderList[j].check_if_getalarmmotion = 0; + + g_PostRecorderList[j].box_x = pNext->left_x + pNext->width / 3.0; + g_PostRecorderList[j].box_y = pNext->top_y + pNext->height / 3.0; + g_PostRecorderList[j].box_w = pNext->width / 3.0; + g_PostRecorderList[j].box_h = pNext->height / 3.0; + + g_PostRecorderList[j].object_id = pNext->obj_tracking_id; + g_PostRecorderList[j].zone_idx = record_zone_id; + + //memcpy(&g_PostRecorderList[j].ori_Data, pNext, sizeof(detection_pos)); + + if (IsANPRCategory_L_Plate(pNext->name)) { + strcpy(g_PostRecorderList[j].sPlateNumber, pNext->properties.plate); + } + else { + strcpy(g_PostRecorderList[j].sPlateNumber, ""); + } + strcpy(g_PostRecorderList[j].name, pNext->name); + + g_PostRecorderList[j].count_trigger = 1; + //g_PostRecorderList[j].the_same_id = 0; + + if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + index_g_PostRecorderList[size_g_PostRecorderList] = j; + size_g_PostRecorderList++; + } + + if (temp_size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { + temp_index_g_PostRecorderList[temp_size_g_PostRecorderList] = j; + temp_size_g_PostRecorderList++; + } + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + //pNext->check_if_having_been_counted[index_zone] = 0; + //if (pNext->obj_tracking_id_idx >= 0) { + //g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[index_zone] = 0; + //} + if (index_object >= 0) { + g_ObjectRecorderList[index_object].check_if_counted[index_zone] = 0; + } + if (index_plate >= 0) { + g_PlateRecorderList[index_plate].check_if_counted[index_zone] = 0; + } + } + break; + } + } + } + + for (int index_post = 0; index_post < temp_size_g_PostRecorderList; index_post++) + { + if (g_PostRecorderList[temp_index_g_PostRecorderList[index_post]].check_if_getalarmmotion == 1 /*&& g_PostRecorderList[temp_index_g_PostRecorderList[index_post]].count_trigger >= 3*/) { + store_post_ok = -1; + break; + } + else { + store_post_ok = 0; + } + } + + for (int index_post = 0; index_post < temp_size_g_PostRecorderList_longterm; index_post++) + { + if (g_longterm_PostRecorderList[temp_index_g_PostRecorderList_longterm[index_post]].check_if_getalarmmotion == 1 /*&& g_longterm_PostRecorderList[temp_index_g_PostRecorderList_longterm[index_post]].count_trigger >= 2*/) { + store_long_ok = -1; + break; + } + else { + store_long_ok = 0; + } + } + + for (int index_post = 0; index_post < temp_size_g_PostRecorderList; index_post++) + { + if (g_PostRecorderList[temp_index_g_PostRecorderList[index_post]].check_if_cloud == 1) { + check_if_cloud_have_been_post = 1; + break; + } + } + + for (int index_post = 0; index_post < temp_size_g_PostRecorderList_longterm; index_post++) + { + if (g_longterm_PostRecorderList[temp_index_g_PostRecorderList_longterm[index_post]].check_if_cloud == 1) { + check_if_cloud_have_been_post = 1; + break; + } + } + } + //printf("\n[start all nets] while 10-2\n"); + if (pNext->trigger_type >= 1) { + if (strcmp(heartbeatData.enable_obj_once_to_post, "Yes") == 0) { + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { + //if (index_object == -1) { + //printf("\nerror---------index_object:%d\n", index_object); + //break; + //} + + if (pNext->obj_tracking_id_idx < 0) { + //printf("\n[start all nets]pNext->obj_tracking_id_idx could not be -1:%s\n", pNext->name); + break; + } + + if (strcmp(pNext->name, "object") != 0) { + if (pNext->zone_violation_idx[index_zone] == 0) { + pNext->check_if_having_been_counted[index_zone] = 0; + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[index_zone] = 0; + } + } + + if (index_object >= 0) { + if (g_ObjectRecorderList[index_object].check_if_counted[index_zone] == 0 && + pNext->check_if_having_been_counted[index_zone] != 1 && + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[index_zone] != 1) + { + if (pNext->zone_violation_idx[index_zone] == 1) { + check_if_object_OK = 1; + } + } + } + + if (index_plate >= 0) { + if (g_PlateRecorderList[index_plate].check_if_counted[index_zone] == 0 && + pNext->check_if_having_been_counted[index_zone] != 1 && + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[index_zone] != 1) + { + if (pNext->zone_violation_idx[index_zone] == 1) { + check_if_object_OK = 1; + } + } + } + } + } + } + //printf("\n[start all nets] while 10-3\n"); + + ////////////////////////////uˬdƦrMrCӤW٨ϥΡC + char plate_only_number_and_alphabet[100] = { 0 }; + memset(plate_only_number_and_alphabet, 0x00, sizeof(plate_only_number_and_alphabet)); + if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && + (strcmp(pNext->name, "ambulance") != 0) && (strcmp(pNext->name, "blank") != 0) && (strcmp(pNext->name, "stop_sign") != 0) + && (strcmp(pNext->name, "face") != 0) && !(strlen(pNext->properties.logo) >= 1 && strcmp(pNext->name, pNext->properties.logo) == 0)) + { + char buf[64] = { 0 }; + memset(buf, 0x00, sizeof(buf)); + strcpy(buf, pNext->properties.plate); + + int k_only = 0; + + for (int m = 0; m < strlen(buf); m++) + { + //printf("[%x]",buf[m]); + if (buf[m] >= 65 && buf[m] <= 90) { + plate_only_number_and_alphabet[k_only] = pNext->properties.plate[m]; + k_only++; + } + else if (buf[m] >= 97 && buf[m] <= 122) { + if ((pNext->engine_type & FEATURE_LPR_TWN) <= 0) { + //alphabets++; + plate_only_number_and_alphabet[k_only] = pNext->properties.plate[m]; + k_only++; + } + } + else if (buf[m] >= 48 && buf[m] <= 57) { + //digits++; + plate_only_number_and_alphabet[k_only] = pNext->properties.plate[m]; + k_only++; + } + else { + //specialcharacters++; + if ((pNext->engine_type & FEATURE_LPR_TWN) > 0) { + //xWP䴩 + if (buf[m] == 45) { + plate_only_number_and_alphabet[k_only] = pNext->properties.plate[m]; + k_only++; + } + } + } + } + plate_only_number_and_alphabet[k_only] = '\0'; + memset(&l_ff_insert_data, 0x00, sizeof(ffgroup_db_tb)); + } + else if (strcmp(pNext->name, "ambulance") == 0 || + strcmp(pNext->name, "blank") == 0 || + strcmp(pNext->name, "stop_sign") == 0 || + strcmp(pNext->name, "face") == 0) { + strcpy(plate_only_number_and_alphabet, pNext->name); + memset(&l_ff_insert_data, 0x00, sizeof(ffgroup_db_tb)); + } + + /* + printf("\n---------------------------------\n"); + printf("\npNext->properties.plate: %s\n", pNext->properties.plate); + printf("\npNext->obj_type: %d\n", pNext->obj_type); + //printf("\n-------------pNext->linked_plate:%s\n", pNext->linked_plate); + //printf("\n--------pNext->name:%s,logo:%s\n", pNext->name, pNext->logo); + //printf("\n---------------pNext->obj_tracking_id:%d---pNext->image_id:%d\n", pNext->obj_tracking_id, pNext->image_id); + printf("\n---------------------------------\n");*/ + //printf("\n[start all nets] while 10-4\n"); + char mycolor[20] = { 0 }; + char myseccolor[20] = { 0 }; + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { + if ((pNext->image_id != -1 && check_first_downsized_cropped_roi_for_object == 1) || IsANPRCategory(pNext->engine_type)) { + if (pNext->color_id == 1) + strcpy(mycolor, "Red"); + else if (pNext->color_id == 2) + strcpy(mycolor, "Orange"); + else if (pNext->color_id == 3) + strcpy(mycolor, "Yellow"); + else if (pNext->color_id == 4) + strcpy(mycolor, "Green"); + else if (pNext->color_id == 5) + strcpy(mycolor, "Blue"); + else if (pNext->color_id == 6) + strcpy(mycolor, "Cyan"); + else if (pNext->color_id == 7) + strcpy(mycolor, "Purple"); + else if (pNext->color_id == 8) + strcpy(mycolor, "Black"); + else if (pNext->color_id == 9) + strcpy(mycolor, "White"); + else if (pNext->color_id == 11) + strcpy(mycolor, "Darkgray"); + else if (pNext->color_id == 10) + strcpy(mycolor, "Gray");//Silver + + if (pNext->sec_color_id == 1) + strcpy(myseccolor, "Red"); + else if (pNext->sec_color_id == 2) + strcpy(myseccolor, "Orange"); + else if (pNext->sec_color_id == 3) + strcpy(myseccolor, "Yellow"); + else if (pNext->sec_color_id == 4) + strcpy(myseccolor, "Green"); + else if (pNext->sec_color_id == 5) + strcpy(myseccolor, "Blue"); + else if (pNext->sec_color_id == 6) + strcpy(myseccolor, "Cyan"); + else if (pNext->sec_color_id == 7) + strcpy(myseccolor, "Purple"); + else if (pNext->sec_color_id == 8) + strcpy(myseccolor, "Black"); + else if (pNext->sec_color_id == 9) + strcpy(myseccolor, "White"); + else if (pNext->sec_color_id == 11) + strcpy(myseccolor, "Darkgray"); + else if (pNext->sec_color_id == 10) + strcpy(myseccolor, "Gray");//Silver + } + } + //printf("\n[start all nets] while 10-5\n"); + if(!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0)) + { + //getalarmmotion data + detect = cJSON_CreateObject(); + cJSON_AddItemToArray(ai_engine, detect); + id = cJSON_CreateNumber(count_behavior_id); + + cJSON_AddItemToObject(detect, "id", id); + + channel_id = cJSON_CreateNumber((int)1); + cJSON_AddItemToObject(detect, "channel_id", channel_id); + camera_name = cJSON_CreateString(g_device_name); + cJSON_AddItemToObject(detect, "camera_name", camera_name); + res_height = cJSON_CreateNumber((int)SCALE_BOUNDING_BOX_HEIGHT); + cJSON_AddItemToObject(detect, "res_height", res_height); + res_width = cJSON_CreateNumber((int)SCALE_BOUNDING_BOX_WIDTH); + cJSON_AddItemToObject(detect, "res_width", res_width); + + code_content = cJSON_CreateString(pNext->code_content); + cJSON_AddItemToObject(detect, "code_content", code_content); + + number_row_temp = cJSON_CreateNumber(pNext->number_row); + cJSON_AddItemToObject(detect, "number_row", number_row_temp); + + confidence = cJSON_CreateNumber((int)pNext->confidence); + cJSON_AddItemToObject(detect, "confidence", confidence); + confidence2 = cJSON_CreateNumber((int)pNext->confidence2); + cJSON_AddItemToObject(detect, "confidence2", confidence2); + progress_bar = cJSON_CreateNumber((int)pNext->progress_bar); + cJSON_AddItemToObject(detect, "progress_bar", progress_bar); + engine_type = cJSON_CreateNumber(pNext->engine_type); + cJSON_AddItemToObject(detect, "engine_type", engine_type); + + name_coco = cJSON_CreateString(pNext->name); + cJSON_AddItemToObject(detect, "label_name", name_coco); + //printf("\n[start all nets] coco pNext->name:%s\n", pNext->name); + class_id = cJSON_CreateNumber(pNext->class_id); + cJSON_AddItemToObject(detect, "class_id", class_id); + obj_type = cJSON_CreateNumber(pNext->obj_type); + cJSON_AddItemToObject(detect, "obj_type", obj_type); + obj_tracking_id = cJSON_CreateNumber(pNext->obj_tracking_id); + cJSON_AddItemToObject(detect, "obj_tracking_id", obj_tracking_id); + obj_dwell_time = cJSON_CreateNumber((int)(pNext->obj_dwell_time * 100) / 100); + cJSON_AddItemToObject(detect, "obj_dwell_time", obj_dwell_time); + color_id = cJSON_CreateNumber(pNext->color_id); + cJSON_AddItemToObject(detect, "color_id", color_id); + color = cJSON_CreateString(mycolor); + cJSON_AddItemToObject(detect, "color", color); + + sec_color_id = cJSON_CreateNumber(pNext->sec_color_id); + cJSON_AddItemToObject(detect, "sec_color_id", sec_color_id); + sec_color = cJSON_CreateString(myseccolor); + cJSON_AddItemToObject(detect, "sec_color", sec_color); + + //bbox_distance = cJSON_CreateNumber(pNext->bbox_distance); + //cJSON_AddItemToObject(detect, "tof_distance", bbox_distance); + + //bbox_height = cJSON_CreateNumber(pNext->bbox_height); + //cJSON_AddItemToObject(detect, "tof_height", bbox_height); + + car_type_name = cJSON_CreateString(pNext->car_type_name); + cJSON_AddItemToObject(detect, "car_type_name", car_type_name); + + logo = cJSON_CreateString(pNext->logo); + cJSON_AddItemToObject(detect, "logo", logo); +#if 0 + if (unlockingKeyInnoFR == 1) { + // joy Add 2023.11.03 + face_json_name = cJSON_CreateString(face_name[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_name", face_json_name); + + face_json_score = cJSON_CreateNumber(face_score[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_score", face_json_score); + + face_json_image = cJSON_CreateString(face_image[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_image", face_json_image); + + face_json_tracking_uuid = cJSON_CreateString(face_tracking_uuid[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_uuid", face_json_tracking_uuid); + + face_json_trackingId = cJSON_CreateNumber(face_trackingId[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_trackingId", face_json_trackingId); + + face_json_trackingState = cJSON_CreateNumber(face_tracking_state[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_tracking_state", face_json_trackingState); + + face_json_detection_confidence = cJSON_CreateNumber(face_detection_confidence[count_behavior_id]); + cJSON_AddItemToObject(detect, "face_detection_confidence", face_json_detection_confidence); + + // face_json_imagepath = cJSON_CreateString(face_imagepath_bak[count_behavior_id]); + // cJSON_AddItemToObject(detect, "face_imagepath_bak", face_json_imagepath); + + // face_json_user = cJSON_CreateString(face_user[count_behavior_id]); + // cJSON_AddItemToObject(detect, "face_user", face_json_user); + + // face_json_group = cJSON_CreateString(face_group[count_behavior_id]); + // cJSON_AddItemToObject(detect, "face_group", face_json_group); + + // printf("Face Name: %s\n", face_name[count_behavior_id]); + // printf("Face Score: %f\n", face_score[count_behavior_id]); + // // printf("Face Image: %s\n", face_image[count_behavior_id]); + // printf("Face Tracking UUID: %s\n", face_tracking_uuid[count_behavior_id]); + // printf("Face Tracking ID: %d\n", face_trackingId[count_behavior_id]); + // printf("Face Tracking State: %d\n", face_tracking_state[count_behavior_id]); + // printf("Face Detection Confidence: %f\n", face_detection_confidence[count_behavior_id]); + // // printf("Face User: %s\n", face_user[count_behavior_id]); + // // printf("Face Group: %s\n", face_group[count_behavior_id]); + // // printf("Face Image Path Bak: %s\n", face_imagepath_bak[count_behavior_id]); + // printf("================================================ \n"); + } +#endif + + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) + linked_plate = cJSON_CreateString(pNext->linked_plate); + else + linked_plate = cJSON_CreateString(""); + + cJSON_AddItemToObject(detect, "linked_plate", linked_plate); + + x = cJSON_CreateNumber((int)(pNext->left_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + cJSON_AddItemToObject(detect, "x", x); + y = cJSON_CreateNumber((int)(pNext->top_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + cJSON_AddItemToObject(detect, "y", y); + w = cJSON_CreateNumber((int)(pNext->width * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + cJSON_AddItemToObject(detect, "w", w); + h = cJSON_CreateNumber((int)(pNext->height * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + cJSON_AddItemToObject(detect, "h", h); + + char msg_center_direction[35] = { 0 }; + if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { + sprintf(msg_center_direction, "%d", (int)(pNext->center_direction)); + } + center_direction = cJSON_CreateString(msg_center_direction); + cJSON_AddItemToObject(detect, "center_direction", center_direction); + + char msg_center_stability[35] = { 0 }; + if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { + sprintf(msg_center_stability, "%d", (int)(pNext->center_stability * 100.0)); + } + center_stability = cJSON_CreateString(msg_center_stability); + cJSON_AddItemToObject(detect, "center_stability", center_stability); + + char msg_center_speed[35] = { 0 }; + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { + sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); + + if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { + strcat(msg_center_speed, " km/h"); + } + else { + strcat(msg_center_speed, " mi/h"); + } + } + else { + strcpy(msg_center_speed, ""); + } + cJSON_AddItemToObject(detect, "center_speed", cJSON_CreateString(msg_center_speed)); + + parent_idx = cJSON_CreateNumber((int)pNext->parent_idx); + cJSON_AddItemToObject(detect, "parent_idx", parent_idx); +#ifdef GY_OS_AMBA + //cJSON_AddItemToObject(detect, "min_distance", cJSON_CreateNumber((int)(pNext->min_distance))); + //cJSON_AddItemToObject(detect, "max_distance", cJSON_CreateNumber((int)(pNext->max_distance))); + //cJSON_AddItemToObject(detect, "min_height", cJSON_CreateNumber((int)(pNext->min_height))); + //cJSON_AddItemToObject(detect, "max_height", cJSON_CreateNumber((int)(pNext->max_height))); + + heatmap_center_x[count_behavior_id] = (int)(pNext->left_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width) + (int)(pNext->width * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width) / 2; + heatmap_center_y[count_behavior_id] = (int)(pNext->top_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height) + (int)(pNext->height * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height) / 2; +#endif + count_behavior_id++; + + } + + if (pNext->trigger_type >= 1) + { + //printf("\nEEEEEEEEEEEEE ; 1\n"); + + if ((check_if_object_OK == 1 && + (check_if_cloud_have_been_post == 0 || + (store_post_ok >= 0 && store_long_ok >= 0)) + && strcmp(heartbeatData.enable_obj_once_to_post, "Yes") == 0) || strcmp(heartbeatData.enable_obj_once_to_post, "No") == 0) + { + if (check_if_cloud_have_been_post == 0) { + //cloud data + detect_cloud = cJSON_CreateObject(); + + cJSON_AddItemToArray(ai_engine_cloud, detect_cloud); + + id_cloud = cJSON_CreateNumber(count_behavior_id_larger_zero); + cJSON_AddItemToObject(detect_cloud, "id", id_cloud); + count_behavior_id_larger_zero++; + + channel_id_cloud = cJSON_CreateNumber((int)1); + cJSON_AddItemToObject(detect_cloud, "channel_id", channel_id_cloud); + camera_name_cloud = cJSON_CreateString(g_device_name); + cJSON_AddItemToObject(detect_cloud, "camera_name", camera_name_cloud); + res_height_cloud = cJSON_CreateNumber(get_g_framesize_height()); + cJSON_AddItemToObject(detect_cloud, "res_height", res_height_cloud); + res_width_cloud = cJSON_CreateNumber(get_g_framesize_width()); + cJSON_AddItemToObject(detect_cloud, "res_width", res_width_cloud); + + code_content_cloud = cJSON_CreateString(pNext->code_content); + cJSON_AddItemToObject(detect_cloud, "code_content", code_content_cloud); + + number_row_temp_cloud = cJSON_CreateNumber(pNext->number_row); + cJSON_AddItemToObject(detect_cloud, "number_row", number_row_temp_cloud); + + confidence_cloud = cJSON_CreateNumber((int)pNext->confidence); + cJSON_AddItemToObject(detect_cloud, "confidence", confidence_cloud); + confidence2_cloud = cJSON_CreateNumber((int)pNext->confidence2); + cJSON_AddItemToObject(detect_cloud, "confidence2", confidence2_cloud); + progress_bar_cloud = cJSON_CreateNumber((int)pNext->progress_bar); + cJSON_AddItemToObject(detect_cloud, "progress_bar", progress_bar_cloud); + engine_type_cloud = cJSON_CreateNumber(pNext->engine_type); + cJSON_AddItemToObject(detect_cloud, "engine_type", engine_type_cloud); + + name_coco_cloud = cJSON_CreateString(pNext->name); + cJSON_AddItemToObject(detect_cloud, "label_name", name_coco_cloud); + + //printf("\n[start all nets] coco pNext->name:%s\n", pNext->name); + class_id_cloud = cJSON_CreateNumber(pNext->class_id); + cJSON_AddItemToObject(detect_cloud, "class_id", class_id_cloud); + + obj_type_cloud = cJSON_CreateNumber(pNext->obj_type); + cJSON_AddItemToObject(detect_cloud, "obj_type", obj_type_cloud); + obj_tracking_id_cloud = cJSON_CreateNumber(pNext->obj_tracking_id); + cJSON_AddItemToObject(detect_cloud, "obj_tracking_id", obj_tracking_id_cloud); + obj_dwell_time_cloud = cJSON_CreateNumber((int)(pNext->obj_dwell_time * 100) / 100); + cJSON_AddItemToObject(detect_cloud, "obj_dwell_time", obj_dwell_time_cloud); + color_id_cloud = cJSON_CreateNumber(pNext->color_id); + cJSON_AddItemToObject(detect_cloud, "color_id", color_id_cloud); + color_cloud = cJSON_CreateString(mycolor); + cJSON_AddItemToObject(detect_cloud, "color", color_cloud); + + sec_color_id_cloud = cJSON_CreateNumber(pNext->sec_color_id); + cJSON_AddItemToObject(detect_cloud, "sec_color_id", sec_color_id_cloud); + sec_color_cloud = cJSON_CreateString(myseccolor); + cJSON_AddItemToObject(detect_cloud, "sec_color", sec_color_cloud); + + //car_type_name = cJSON_CreateString(pNext->car_type_name); + //cJSON_AddItemToObject(detect_cloud, "car_type_name", car_type_name); + + //logo = cJSON_CreateString(pNext->logo); + //cJSON_AddItemToObject(detect_cloud, "logo", logo); + + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + linked_plate_cloud = cJSON_CreateString(pNext->linked_plate); + } + else { + linked_plate_cloud = cJSON_CreateString(""); + } + cJSON_AddItemToObject(detect_cloud, "linked_plate", linked_plate_cloud); + + x_cloud = cJSON_CreateNumber((int)((pNext->left_x - pNext->width / 3.0) * get_g_framesize_width() / g_ori_yuv_width)); + cJSON_AddItemToObject(detect_cloud, "x", x_cloud); + y_cloud = cJSON_CreateNumber((int)((pNext->top_y - pNext->height / 3.0) * get_g_framesize_height() / g_ori_yuv_height)); + cJSON_AddItemToObject(detect_cloud, "y", y_cloud); + w_cloud = cJSON_CreateNumber((int)(pNext->width * 5.0 * get_g_framesize_width() / (g_ori_yuv_width * 3.0))); + cJSON_AddItemToObject(detect_cloud, "w", w_cloud); + h_cloud = cJSON_CreateNumber((int)(pNext->height * 5.0 * get_g_framesize_height() / (g_ori_yuv_height * 3.0))); + cJSON_AddItemToObject(detect_cloud, "h", h_cloud); + + char msg_center_direction[35] = { 0 }; + if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { + sprintf(msg_center_direction, "%d", (int)(pNext->center_direction)); + } + center_direction_cloud = cJSON_CreateString(msg_center_direction); + cJSON_AddItemToObject(detect_cloud, "center_direction", center_direction_cloud); + + char msg_center_stability[35] = { 0 }; + if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { + sprintf(msg_center_stability, "%d", (int)(pNext->center_stability * 100.0)); + } + center_stability_cloud = cJSON_CreateString(msg_center_stability); + cJSON_AddItemToObject(detect_cloud, "center_stability", center_stability_cloud); + + char msg_center_speed[35] = { 0 }; + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { + sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); + if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { + strcat(msg_center_speed, " km/h"); + } + else { + strcat(msg_center_speed, " mi/h"); + } + } + else { + strcpy(msg_center_speed, ""); + } + cJSON_AddItemToObject(detect_cloud, "center_speed", cJSON_CreateString(msg_center_speed)); + + parent_idx_cloud = cJSON_CreateNumber((int)pNext->parent_idx); + cJSON_AddItemToObject(detect_cloud, "parent_idx", parent_idx_cloud); + + } + } + } + + //printf("\nKKKKKKKKKKK pNext->trigger_type:%d\n", pNext->trigger_type); + + if ((strcmp(pNext->name, "object") == 0 && pNext->number_row == 2 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0)){} + else if (pNext->trigger_type >= 1 || IsANPRCategory(pNext->engine_type) || (strcmp(pNext->name, "object") == 0 && strcmp(viewChannelData[0].enable_show_unknown_object, "Yes") == 0) || + (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0) || + (strcmp(pNext->name, "object") != 0 && strcmp(SystemSetting.enable_bounding_box, "Yes") == 0) || + (strcmp(pNext->name, "object") != 0 && strcmp(SystemSetting.enable_bounding_box, "No") == 0 && strcmp(heartbeatData.events_default_version, "4") == 0 && check_if_show_parking == 1)) + { + { + char msg_center_direction[35] = { 0 }; + if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { + sprintf(msg_center_direction, "%d", (int)(pNext->center_direction)); + } + + char msg_center_stability[35] = { 0 }; + if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { + sprintf(msg_center_stability, "%d", (int)(pNext->center_stability * 100.0)); + } + + char msg_center_speed[35] = { 0 }; + if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { + sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); + + if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { + strcat(msg_center_speed, " km/h"); + } + else { + strcat(msg_center_speed, " mi/h"); + } + } + else { + strcpy(msg_center_speed, ""); + } + + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + detect_udp = cJSON_CreateObject(); + cJSON_AddItemToArray(ai_engine_udp, detect_udp); + + id_udp = cJSON_CreateNumber(count_behavior_id_larger_zero_udp); + cJSON_AddItemToObject(detect_udp, "id", id_udp); + + channel_id_udp = cJSON_CreateNumber((int)1); + cJSON_AddItemToObject(detect_udp, "channel_id", channel_id_udp); + + res_height_udp = cJSON_CreateNumber(SCALE_BOUNDING_BOX_HEIGHT); + res_width_udp = cJSON_CreateNumber(SCALE_BOUNDING_BOX_WIDTH); + + x_udp = cJSON_CreateNumber((int)(pNext->left_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + y_udp = cJSON_CreateNumber((int)(pNext->top_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + w_udp = cJSON_CreateNumber((int)(pNext->width * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + h_udp = cJSON_CreateNumber((int)(pNext->height * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + + cJSON_AddItemToObject(detect_udp, "res_height", res_height_udp); + cJSON_AddItemToObject(detect_udp, "res_width", res_width_udp); + + code_content_udp = cJSON_CreateString(pNext->code_content); + cJSON_AddItemToObject(detect_udp, "code_content", code_content_udp); + + number_row_temp_udp = cJSON_CreateNumber(pNext->number_row); + cJSON_AddItemToObject(detect_udp, "number_row", number_row_temp_udp); + + confidence_udp = cJSON_CreateNumber((int)pNext->confidence); + cJSON_AddItemToObject(detect_udp, "confidence", confidence_udp); + engine_type_udp = cJSON_CreateNumber(pNext->engine_type); + cJSON_AddItemToObject(detect_udp, "engine_type", engine_type_udp); + + name_coco_udp = cJSON_CreateString(pNext->name); + cJSON_AddItemToObject(detect_udp, "label_name", name_coco_udp); + + class_id_udp = cJSON_CreateNumber(pNext->class_id); + cJSON_AddItemToObject(detect_udp, "class_id", class_id_udp); + + obj_type_udp = cJSON_CreateNumber(pNext->obj_type); + cJSON_AddItemToObject(detect_udp, "obj_type", obj_type_udp); + obj_tracking_id_udp = cJSON_CreateNumber(pNext->obj_tracking_id); + cJSON_AddItemToObject(detect_udp, "obj_tracking_id", obj_tracking_id_udp); + obj_dwell_time_udp = cJSON_CreateNumber((int)(pNext->obj_dwell_time * 100) / 100); + cJSON_AddItemToObject(detect_udp, "obj_dwell_time", obj_dwell_time_udp); + color_id_udp = cJSON_CreateNumber(pNext->color_id); + cJSON_AddItemToObject(detect_udp, "color_id", color_id_udp); + color_udp = cJSON_CreateString(mycolor); + cJSON_AddItemToObject(detect_udp, "color", color_udp); + + car_type_name_udp = cJSON_CreateString(pNext->car_type_name); + cJSON_AddItemToObject(detect_udp, "car_type_name", car_type_name_udp); + + logo_udp = cJSON_CreateString(pNext->logo); + cJSON_AddItemToObject(detect_udp, "logo", logo_udp); + + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + linked_plate_udp = cJSON_CreateString(pNext->linked_plate); + } + else { + linked_plate_udp = cJSON_CreateString(""); + } + cJSON_AddItemToObject(detect_udp, "linked_plate", linked_plate_udp); + + cJSON_AddItemToObject(detect_udp, "x", x_udp); + cJSON_AddItemToObject(detect_udp, "y", y_udp); + cJSON_AddItemToObject(detect_udp, "w", w_udp); + cJSON_AddItemToObject(detect_udp, "h", h_udp); + + center_direction_udp = cJSON_CreateString(msg_center_direction); + cJSON_AddItemToObject(detect_udp, "center_direction", center_direction_udp); + } + + detect_8592 = cJSON_CreateObject(); + cJSON_AddItemToArray(ai_engine_8592, detect_8592); + + id_8592 = cJSON_CreateNumber(count_behavior_id_larger_zero_udp); + cJSON_AddItemToObject(detect_8592, "id", id_8592); + + channel_id_8592 = cJSON_CreateNumber((int)1); + cJSON_AddItemToObject(detect_8592, "channel_id", channel_id_8592); + camera_name_8592 = cJSON_CreateString(g_device_name); + cJSON_AddItemToObject(detect_8592, "camera_name", camera_name_8592); + + res_height_8592 = cJSON_CreateNumber(SCALE_BOUNDING_BOX_HEIGHT); + res_width_8592 = cJSON_CreateNumber(SCALE_BOUNDING_BOX_WIDTH); + + x_8592 = cJSON_CreateNumber((int)(pNext->left_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + y_8592 = cJSON_CreateNumber((int)(pNext->top_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + w_8592 = cJSON_CreateNumber((int)(pNext->width * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + h_8592 = cJSON_CreateNumber((int)(pNext->height * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + + cJSON_AddItemToObject(detect_8592, "res_height", res_height_8592); + cJSON_AddItemToObject(detect_8592, "res_width", res_width_8592); + + code_content_8592 = cJSON_CreateString(pNext->code_content); + cJSON_AddItemToObject(detect_8592, "code_content", code_content_8592); + + number_row_temp_8592 = cJSON_CreateNumber(pNext->number_row); + cJSON_AddItemToObject(detect_8592, "number_row", number_row_temp_8592); + + confidence_8592 = cJSON_CreateNumber((int)pNext->confidence); + cJSON_AddItemToObject(detect_8592, "confidence", confidence_8592); + confidence2_8592 = cJSON_CreateNumber((int)pNext->confidence2); + cJSON_AddItemToObject(detect_8592, "confidence2", confidence2_8592); + progress_bar_8592 = cJSON_CreateNumber((int)pNext->progress_bar); + cJSON_AddItemToObject(detect_8592, "progress_bar", progress_bar_8592); + engine_type_8592 = cJSON_CreateNumber(pNext->engine_type); + cJSON_AddItemToObject(detect_8592, "engine_type", engine_type_8592); + + name_coco_8592 = cJSON_CreateString(pNext->name); + cJSON_AddItemToObject(detect_8592, "label_name", name_coco_8592); + + class_id_8592 = cJSON_CreateNumber(pNext->class_id); + cJSON_AddItemToObject(detect_8592, "class_id", class_id_8592); + + obj_type_8592 = cJSON_CreateNumber(pNext->obj_type); + cJSON_AddItemToObject(detect_8592, "obj_type", obj_type_8592); + obj_tracking_id_8592 = cJSON_CreateNumber(pNext->obj_tracking_id); + cJSON_AddItemToObject(detect_8592, "obj_tracking_id", obj_tracking_id_8592); + obj_dwell_time_8592 = cJSON_CreateNumber((int)(pNext->obj_dwell_time * 100) / 100); + cJSON_AddItemToObject(detect_8592, "obj_dwell_time", obj_dwell_time_8592); + color_id_8592 = cJSON_CreateNumber(pNext->color_id); + cJSON_AddItemToObject(detect_8592, "color_id", color_id_8592); + color_8592 = cJSON_CreateString(mycolor); + cJSON_AddItemToObject(detect_8592, "color", color_8592); + + sec_color_id_8592 = cJSON_CreateNumber(pNext->sec_color_id); + cJSON_AddItemToObject(detect_8592, "sec_color_id", sec_color_id_8592); + sec_color_8592 = cJSON_CreateString(myseccolor); + cJSON_AddItemToObject(detect_8592, "sec_color", sec_color_8592); + + car_type_name_8592 = cJSON_CreateString(pNext->car_type_name); + cJSON_AddItemToObject(detect_8592, "car_type_name", car_type_name_8592); + + logo_8592 = cJSON_CreateString(pNext->logo); + cJSON_AddItemToObject(detect_8592, "logo", logo_8592); + + if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { + linked_plate_8592 = cJSON_CreateString(pNext->linked_plate); + } + else { + linked_plate_8592 = cJSON_CreateString(""); + } + cJSON_AddItemToObject(detect_8592, "linked_plate", linked_plate_8592); + + cJSON_AddItemToObject(detect_8592, "x", x_8592); + cJSON_AddItemToObject(detect_8592, "y", y_8592); + cJSON_AddItemToObject(detect_8592, "w", w_8592); + cJSON_AddItemToObject(detect_8592, "h", h_8592); + + center_direction_8592 = cJSON_CreateString(msg_center_direction); + cJSON_AddItemToObject(detect_8592, "center_direction", center_direction_8592); + + center_stability_8592 = cJSON_CreateString(msg_center_stability); + cJSON_AddItemToObject(detect_8592, "center_stability", center_stability_8592); + + cJSON_AddItemToObject(detect_8592, "center_speed", cJSON_CreateString(msg_center_speed)); + + parent_idx_8592 = cJSON_CreateNumber((int)pNext->parent_idx); + cJSON_AddItemToObject(detect_8592, "parent_idx", parent_idx_8592); + + count_behavior_id_larger_zero_udp++; + } + + //onvif data + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + onvif_object[onvif_obj_number].Likelihood = (float)pNext->confidence / 100.0; + sprintf(onvif_object[onvif_obj_number].TypeName, "%s", pNext->name); + onvif_object[onvif_obj_number].iObjectID = pNext->obj_tracking_id; + + //printf("ori w, h: %d, %d, scal w, h: %d, %d \n", g_ori_yuv_width, g_ori_yuv_height, SCALE_BOUNDING_BOX_WIDTH, SCALE_BOUNDING_BOX_HEIGHT); + //printf("x, y, w, h = %f, %f, %f, %f \n", pNext->left_x, pNext->top_y, pNext->width, pNext->height); + + float onvif_left_x = X_Tranform_To_Onvif_Space(pNext->left_x, g_ori_half_yuv_width); + float onvif_top_y = Y_Tranform_To_Onvif_Space(pNext->top_y, g_ori_half_yuv_height); + + float onvif_center_x = X_Tranform_To_Onvif_Space(pNext->left_x + pNext->width / 2.0, g_ori_half_yuv_width); + float onvif_center_y = Y_Tranform_To_Onvif_Space(pNext->top_y + pNext->height / 2.0, g_ori_half_yuv_height); + + float onvif_right_x = X_Tranform_To_Onvif_Space(pNext->left_x + pNext->width, g_ori_half_yuv_width); + float onvif_bottom_y = Y_Tranform_To_Onvif_Space(pNext->top_y + pNext->height, g_ori_half_yuv_height); + + onvif_object[onvif_obj_number].center_x = onvif_center_x; + onvif_object[onvif_obj_number].center_y = onvif_center_y; + onvif_object[onvif_obj_number].left_x = onvif_left_x; + onvif_object[onvif_obj_number].top_y = onvif_top_y; + onvif_object[onvif_obj_number].right_x = onvif_right_x; + onvif_object[onvif_obj_number].bottom_y = onvif_bottom_y; + } + } + + if (((IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && + pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters) && + strlen(pNext->properties.plate)>=1 + ) || strcmp(pNext->name,"ambulance")==0 + || strcmp(pNext->name, "blank") == 0 || strcmp(pNext->name, "stop_sign") == 0 + || strcmp(pNext->name, "face") == 0)) + { + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + sprintf(onvif_object[onvif_obj_number].sPlateNumber, "%s", pNext->properties.plate); + sprintf(onvif_object[onvif_obj_number].sCountryCode, "%s", pNext->properties.country); + sprintf(onvif_object[onvif_obj_number].sIssuingEntity, "%s", pNext->properties.area); + } + + //char count_plate[256] = { 0 }; + { + /* + sprintf(count_plate, "%s9%d", pNext->properties.plate, my_count_lpr); + my_count_lpr++; + if (my_count_lpr >= 99) { + my_count_lpr = 0; + }*/ + //getalarmmotion data + properties = cJSON_CreateObject(); + cJSON_AddItemToObject(detect, "properties", properties); + plate = cJSON_CreateString(pNext->properties.plate); + //plate = cJSON_CreateString(count_plate); + cJSON_AddItemToObject(properties, "plate", plate); + country = cJSON_CreateString(pNext->properties.country); + cJSON_AddItemToObject(properties, "country", country); + area = cJSON_CreateString(pNext->properties.area); + cJSON_AddItemToObject(properties, "area", area); + area_id = cJSON_CreateNumber(pNext->properties.area_id); + cJSON_AddItemToObject(properties, "area_id", area_id); + logo = cJSON_CreateString(pNext->properties.logo); + cJSON_AddItemToObject(properties, "logo", logo); + } + + if (pNext->trigger_type >= 1) + { + //cloud data + + if ((check_if_object_OK == 1 && + (check_if_cloud_have_been_post == 0 || + (store_post_ok >= 0 && store_long_ok >= 0)) + && strcmp(heartbeatData.enable_obj_once_to_post, "Yes") == 0) || strcmp(heartbeatData.enable_obj_once_to_post, "No") == 0) + { + if (check_if_cloud_have_been_post == 0){ + properties_cloud = cJSON_CreateObject(); + cJSON_AddItemToObject(detect_cloud, "properties", properties_cloud); + plate_cloud = cJSON_CreateString(pNext->properties.plate); + cJSON_AddItemToObject(properties_cloud, "plate", plate_cloud); + country_cloud = cJSON_CreateString(pNext->properties.country); + cJSON_AddItemToObject(properties_cloud, "country", country_cloud); + area_cloud = cJSON_CreateString(pNext->properties.area); + cJSON_AddItemToObject(properties_cloud, "area", area_cloud); + area_id_cloud = cJSON_CreateNumber(pNext->properties.area_id); + cJSON_AddItemToObject(properties_cloud, "area_id", area_id_cloud); + logo_cloud = cJSON_CreateString(pNext->properties.logo); + cJSON_AddItemToObject(properties_cloud, "logo", logo_cloud); + } + } + } + + if (pNext->trigger_type >= 1 || IsANPRCategory(pNext->engine_type)) + { + { + properties_udp = cJSON_CreateObject(); + cJSON_AddItemToObject(detect_udp, "properties", properties_udp); + plate_udp = cJSON_CreateString(pNext->properties.plate); + cJSON_AddItemToObject(properties_udp, "plate", plate_udp); + country_udp = cJSON_CreateString(pNext->properties.country); + cJSON_AddItemToObject(properties_udp, "country", country_udp); + area_udp = cJSON_CreateString(pNext->properties.area); + cJSON_AddItemToObject(properties_udp, "area", area_udp); + area_id_udp = cJSON_CreateNumber(pNext->properties.area_id); + cJSON_AddItemToObject(properties_udp, "area_id", area_id_udp); + logo_udp = cJSON_CreateString(pNext->properties.logo); + cJSON_AddItemToObject(properties_udp, "logo", logo_udp); + + properties_8592 = cJSON_CreateObject(); + cJSON_AddItemToObject(detect_8592, "properties", properties_8592); + plate_8592 = cJSON_CreateString(pNext->properties.plate); + cJSON_AddItemToObject(properties_8592, "plate", plate_8592); + country_8592 = cJSON_CreateString(pNext->properties.country); + cJSON_AddItemToObject(properties_8592, "country", country_8592); + area_8592 = cJSON_CreateString(pNext->properties.area); + cJSON_AddItemToObject(properties_8592, "area", area_8592); + area_id_8592 = cJSON_CreateNumber(pNext->properties.area_id); + cJSON_AddItemToObject(properties_8592, "area_id", area_id_8592); + logo_8592 = cJSON_CreateString(pNext->properties.logo); + cJSON_AddItemToObject(properties_8592, "logo", logo_8592); + } + } + + //char afterBuf[64] = { 0 }; + //strcpy(afterBuf, pNext->properties.plate); + + strcpy(pNext->properties.plate_list, ""); + + if(strcmp(pNext->name, "face") != 0) + { + //clock_t now_t = clock(); + //if (now_t % 5 == 0) + { + //printf("XXX insert1\n"); + + //strcpy(l_ff_insert_data.LPR, count_plate); + strcpy(l_ff_insert_data.LPR, pNext->properties.plate); + + + /* + printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + printf("\n(%d)afterBuf: %s\n",pNext->obj_tracking_id,afterBuf); + printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + */ + //strcpy(l_ff_insert_data.COUNTRY, pNext->properties.area); + + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + //printf("Current local time and date: %s", asctime(timeinfo)); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = {0}; + sprintf(buf_time_info, "%04d-%02d-%02d %02d:%02d:%02d:%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + strcpy(l_ff_insert_data.MOD_TS, buf_time_info); + + char num_area_id[15]; + sprintf(num_area_id, "%d", pNext->properties.area_id); + + //sprintf(num_color_id, "%s", pNext->color); + + char buf_country[64] = {}; + memset(buf_country, 0x00, sizeof(buf_country)); + strcpy(buf_country, pNext->properties.country); + + char afterBuf_country[64] = { 0 }; + for (int index_buf_country = 0, temp_index = 0; index_buf_country < strlen(buf_country); index_buf_country++) { + if (buf_country[index_buf_country] != ' ') { + afterBuf_country[temp_index] = buf_country[index_buf_country]; + temp_index++; + } + } + + //sprintf(l_ff_insert_data.LPR, "%s", pNext->properties.plate); + //printf("XXX insert2\n"); + strcpy(l_ff_insert_data.COUNTRY, afterBuf_country); + strcpy(l_ff_insert_data.ACT_PARAM, num_area_id); + strcpy(l_ff_insert_data.ACTION, "0"); + strcpy(l_ff_insert_data.sec_color_id, "0"); + + sprintf(l_ff_insert_data.THRESHOLD, "%d", (int)pNext->confidence); + sprintf(l_ff_insert_data.ROI_X, "%d", (int)(min_x * SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + sprintf(l_ff_insert_data.ROI_Y, "%d", (int)(min_y * SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + sprintf(l_ff_insert_data.ROI_W, "%d", (int)((max_x - min_x) * SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + sprintf(l_ff_insert_data.ROI_H, "%d", (int)((max_y - min_y) * SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + sprintf(l_ff_insert_data.LP_X, "%d", (int)(pNext->left_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + sprintf(l_ff_insert_data.LP_Y, "%d", (int)(pNext->top_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + sprintf(l_ff_insert_data.LP_W, "%d", (int)(pNext->width * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + sprintf(l_ff_insert_data.LP_H, "%d", (int)(pNext->height * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + +#if defined GY_OS_AMBA + sprintf(l_ff_insert_data.CAR_ID, "%s", pNext->car_type_name); + sprintf(l_ff_insert_data.IN_OTHER, "%s", pNext->properties.logo); +#endif + //printf("printf IN_OTHER 1 = %s \n", l_ff_insert_data.IN_OTHER); + //printf("\nenable_lpr_db-----2\n"); + + int check_if_ok_import_lpr = 1; + if (strcmp(heartbeatData.enable_only_once_to_post, "Yes") == 0) { + if (pNext->trigger_type >= 1) { + if ((check_if_object_OK == 1 && + (check_if_cloud_have_been_post == 0 || + (store_post_ok >= 0 && store_long_ok >= 0)) + && strcmp(heartbeatData.enable_obj_once_to_post, "Yes") == 0) || strcmp(heartbeatData.enable_obj_once_to_post, "No") == 0) { + + } + else { + check_if_ok_import_lpr = 0; + } + } + else { + check_if_ok_import_lpr = 0; + } + } + pNext->check_if_ok_import_lpr = check_if_ok_import_lpr; + + if (check_if_ok_import_lpr == 1 && strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0) { + char buf_image_id[512] = { 0 }; + + /*if (pNext->image_id == 0) { + sprintf(buf_image_id, "default"); + } + else*/ { + + //YYYYMMDDhhmmssms_ABC123_1.jpg + sprintf(buf_image_id, "%d_%d_%d_%d_%d_%d_%ld_%s_%ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time, plate_only_number_and_alphabet, pNext->image_id); + } + + strcpy(l_ff_insert_data.LP_BMP, buf_image_id); + strcpy(g_buf_image_id, buf_image_id); + + //printf("\n--------g_buf_image_id:%s\n", g_buf_image_id); + + char temp_buf_image_id[768] = { 0 }; + + if (AI_fps >= 1) + { +#if defined GY_OS_AMBA + if ((enable_downsized_cropped_roi == 1 && check_first_downsized_cropped_roi == 1) + || strcmp(pNext->name, "ambulance") == 0 + || strcmp(pNext->name, "blank") == 0 + || strcmp(pNext->name, "stop_sign") == 0) + { + + if (pNext->image_id != -1) { + + sprintf(temp_buf_image_id, "/emmc/plugin/Aida_data/storage/%s.jpg", g_buf_image_id); + pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); + if (g_downsized_cropped_shape_w[pNext->image_id] != 0 && g_downsized_cropped_shape_h[pNext->image_id] != 0 + && strcmp(pNext->name, "ambulance") != 0 && strcmp(pNext->name, "blank") != 0 && + strcmp(pNext->name, "stop_sign") != 0) { + SaveRawRGBToJPG(temp_buf_image_id, g_img_buf[pNext->image_id], g_downsized_cropped_shape_w[pNext->image_id], g_downsized_cropped_pitch[pNext->image_id], g_downsized_cropped_shape_h[pNext->image_id], 0); + + //郞PIϥhbase64 + + { + g_cropped_length_image[pNext->image_id] = SaveRawRGBToChar(g_cropped_img_buf[pNext->image_id], g_img_buf[pNext->image_id], g_downsized_cropped_shape_w[pNext->image_id], g_downsized_cropped_pitch[pNext->image_id], g_downsized_cropped_shape_h[pNext->image_id], 0); + base64_encode((const unsigned char*)g_cropped_img_buf[pNext->image_id], g_cropped_length_image[pNext->image_id], (size_t *)&g_cropped_length_image_base64[pNext->image_id], g_cropped_img_buf_base64[pNext->image_id]); + g_cropped_img_buf_base64[pNext->image_id][g_cropped_length_image_base64[pNext->image_id]] = '\0'; + + //printf("\n----------------rgb_char length: %d, base64 length: %d\n", g_cropped_length_image[pNext->image_id], g_cropped_length_image_base64[pNext->image_id]); + } + } + else { + strcpy(l_ff_insert_data.LP_BMP, "default"); + } + + memset(g_img_buf[pNext->image_id], 0x00, MAX_IMG_SIZE); + g_downsized_cropped_shape_w[pNext->image_id] = 0; + g_downsized_cropped_pitch[pNext->image_id] = 0; + g_downsized_cropped_shape_h[pNext->image_id] = 0; + pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); + } + } +#else + if (enable_downsized_cropped_roi == 1) { + + sprintf(temp_buf_image_id, "/emmc/plugin/Aida_data/storage/%s.jpg", g_buf_image_id); + + if (pNext->test_id >= 0 && g_current_bbox_list[pNext->test_id].image_id >= 0 && g_size_base64_cropped_img[g_current_bbox_list[pNext->test_id].image_id] >= 1) { + + size_t base64_decode_length = g_size_base64_cropped_img[g_current_bbox_list[pNext->test_id].image_id]; + //char DecryptData[1280 * 720 * 3 / 2] = { 0 }; + + char temp2_buf_image_id[768] = { 0 }; + //sprintf(temp_buf_image_id, "aaaaa11111_%dx%d.bin", 150, 70); + sprintf(temp2_buf_image_id, "yuvImg_%d.bin", g_current_bbox_list[pNext->test_id].image_id); + + //char write_filename[256] = "/emmc/plugin/Aida_data/storage/"; + char read_filename[256] = "/tmp/"; + strcat(read_filename, temp2_buf_image_id); + + + //char *fileBuf = ReadAllBytes(write_filename); + + + + //base64_decode(g_base64_cropped_img[g_current_bbox_list[pNext->test_id].image_id], g_size_base64_cropped_img[g_current_bbox_list[pNext->test_id].image_id], &base64_decode_length, DecryptData); + + //printf("\n------%d,%d,%d,%d\n", strlen(fileBuf),base64_decode_length, g_current_bbox_list[pNext->test_id].crop_w, g_current_bbox_list[pNext->test_id].crop_h); + + if (g_current_bbox_list[pNext->test_id].crop_w >= 1 && g_current_bbox_list[pNext->test_id].crop_h >= 1) + { + pthread_mutex_lock(&mutex_send_jpeg); + SaveRawYUVToRGB_JPG(read_filename, temp_buf_image_id, base64_decode_length, g_current_bbox_list[pNext->test_id].crop_w, g_current_bbox_list[pNext->test_id].crop_h); + pthread_mutex_unlock(&mutex_send_jpeg); + } + else + { + strcpy(l_ff_insert_data.LP_BMP, "default"); + } + + /*if (fileBuf == NULL) { + free(fileBuf); + fileBuf = NULL; + }*/ + } + else { + strcpy(l_ff_insert_data.LP_BMP, "default"); + } + + } + +#endif + else + { + sprintf(temp_buf_image_id, "%s.jpg", g_buf_image_id); + + //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; + //size_t snapshot_size = 0; + //snapshot_size = get_g_canvas_addr(snapshot_addr); + + if (g_current_snapshot_size >= 1) { + pthread_mutex_lock(&mutex_send_jpeg); + + char write_filename[256] = "/emmc/plugin/Aida_data/storage/"; + strcat(write_filename, temp_buf_image_id); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + if (enable_zone_crop_1 == 1 && g_current_snapshot_size_crop_zone >= 1) { + fwrite(g_current_snapshot_addr_crop_zone, sizeof(char), g_current_snapshot_size_crop_zone, fp); + } + else { + fwrite(g_current_snapshot_addr, sizeof(char), g_current_snapshot_size, fp); + } + //printf("[PNS Get Snapshot From IPCam] Wrote to the file: %s.\n", write_filename); + fclose(fp); + } + else + printf("[start all nets] (For debugging) Error occurred when opening file I/O.\n"); + + + pthread_mutex_unlock(&mutex_send_jpeg); + } + } + } + } + else + { + strcpy(l_ff_insert_data.LP_BMP, "default"); + } + + + if (check_if_ok_import_lpr == 1 && ( strcmp(l_ff_insert_data.LP_BMP, "default") != 0 || strcmp(pNext->name, "ambulance") == 0 + || strcmp(pNext->name, "blank") == 0 || strcmp(pNext->name, "stop_sign") == 0)) + { + char Count_LPR_char[256] = { 0 }; + sprintf(Count_LPR_char, "LPR%d=%s,", Count_LPR, pNext->properties.plate); + strcat(JsonString_to_ipcam, Count_LPR_char); + + char ACT_PARAM_char[256] = { 0 }; + int bool_check_if_not_in_black_and_white = 0; + + if (check_if_in_black(pNext->properties.plate, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { + sprintf(ACT_PARAM_char, "ACT_PARAM%d=denial,", Count_LPR); + sprintf(l_ff_insert_data.RTIME, "%s", "denial"); + strcpy(pNext->properties.plate_list, "denial"); + } + else if (check_if_in_white(pNext->properties.plate, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { + sprintf(ACT_PARAM_char, "ACT_PARAM%d=allowed,", Count_LPR); + sprintf(l_ff_insert_data.RTIME, "%s", "allowed"); + strcpy(pNext->properties.plate_list, "allowed"); + } + else { + bool_check_if_not_in_black_and_white = 1; + sprintf(ACT_PARAM_char, "ACT_PARAM%d=visitor,", Count_LPR); + sprintf(l_ff_insert_data.RTIME, "%s", "visitor"); + strcpy(pNext->properties.plate_list, "visitor"); + } + strcat(JsonString_to_ipcam, ACT_PARAM_char); + + char ROI_char[256] = { 0 }; + sprintf(ROI_char, "ROI_X%d=%d,ROI_Y%d=%d,ROI_W%d=%d,ROI_H%d=%d,", Count_LPR,(int)(min_x * SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH), + Count_LPR, (int)(min_y * SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT), Count_LPR, (int)((max_x - min_x) * SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH), Count_LPR, (int)((max_y - min_y) * SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + strcat(JsonString_to_ipcam, ROI_char); + + char LP_char[256] = { 0 }; + sprintf(LP_char, "LP_X%d=%d,LP_Y%d=%d,LP_W%d=%d,LP_H%d=%d,", Count_LPR, (int)(pNext->left_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width), + Count_LPR, (int)(pNext->top_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height), Count_LPR, (int)(pNext->width * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width), Count_LPR, (int)(pNext->height * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + strcat(JsonString_to_ipcam, LP_char); + + char LPR_TIME_char[256] = { 0 }; + sprintf(LPR_TIME_char, "LPR_TIME%d=%d-%d-%d %d:%d:%d,", Count_LPR, 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, + timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + strcat(JsonString_to_ipcam, LPR_TIME_char); + + + char LPR_BMP_char[256] = { 0 }; + if (strlen(l_ff_insert_data.LP_BMP) >= 1) + sprintf(LPR_BMP_char, "LPR_BMP%d=/emmc/plugin/Aida_data/storage/%s.jpg", Count_LPR, l_ff_insert_data.LP_BMP); + else + sprintf(LPR_BMP_char, "LPR_BMP%d=", Count_LPR); + strcat(JsonString_to_ipcam, LPR_BMP_char); + + //printf("XXX insert3\n"); + strcat(JsonString_to_ipcam, "\n"); + + char LPR_BMP_char_2[256] = { 0 }; + if (strlen(l_ff_insert_data.LP_BMP) >= 1) + sprintf(LPR_BMP_char_2, "/emmc/plugin/Aida_data/storage/%s.jpg", l_ff_insert_data.LP_BMP); + cJSON_AddItemToObject(detect, "LPR_BMP", cJSON_CreateString(LPR_BMP_char_2)); + cJSON_AddItemToObject(detect_udp, "LPR_BMP", cJSON_CreateString(LPR_BMP_char_2)); // 08-14 + cJSON_AddItemToObject(detect_8592, "LPR_BMP", cJSON_CreateString(LPR_BMP_char_2)); + + //if (now_t % 5 == 0 && strcmp(viewChannelData[0].enable_lpr_db,"Yes")==0) + //printf("\nenable_lpr_db-----3\n"); + + if (strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0 && strcmp(l_ff_insert_data.LP_BMP, "default") != 0) + { + + if (enable_downsized_cropped_roi == 1 && check_first_downsized_cropped_roi == 1) { + char num_color_id[15]; + sprintf(num_color_id, "%d", pNext->color_id); + strcpy(l_ff_insert_data.ACTION, num_color_id); + + char num_sec_color_id[15]; + sprintf(num_sec_color_id, "%d", pNext->sec_color_id); + strcpy(l_ff_insert_data.sec_color_id, num_sec_color_id); + } + else { + char num_color_id[15]; + sprintf(num_color_id, "%d", 0); + + strcpy(l_ff_insert_data.ACTION, num_color_id); + strcpy(l_ff_insert_data.sec_color_id, num_color_id); + } + + strcpy(l_ff_insert_data.sql_tbname, LPR_MSG_TABLE); + if (g_check_if_OK_to_start_osd_server == 0) { + pthread_mutex_lock(&mutex_enable_lpr_db); + sqlite_ffgroup_insert(&l_ff_insert_data, LOGLISTNAME); + pthread_mutex_unlock(&mutex_enable_lpr_db); + } + } + + //visitor list table--------------------------------------------------------- + //printf("XXX insert2-1\n"); + + //if (check_if_not_in_black_and_white(afterBuf)) + if (bool_check_if_not_in_black_and_white == 1 && strcmp(l_ff_insert_data.LP_BMP, "default") != 0) + { + //printf("\nenable_lpr_db-----4\n"); + //if (now_t % 5 == 0 && strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0) + if (strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0) + { + //printf("XXX insert2-2\n"); + strcpy(l_ff_insert_data.sql_tbname, LPR_MSG_CUSTOMERTABLE); + if (g_check_if_OK_to_start_osd_server == 0) { + pthread_mutex_lock(&mutex_enable_lpr_db); + sqlite_ffgroup_insert(&l_ff_insert_data, CUSTLISTNAME); + pthread_mutex_unlock(&mutex_enable_lpr_db); + } + + } + } + + Count_LPR++; + //printf("\nenable_lpr_db-----5\n"); + + } + } + + } + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + sprintf(onvif_object[onvif_obj_number].sPlateType, "%s", pNext->properties.plate_list); + } + + } // IsANPRCategory && pNext->obj_type = _DASH + + + //printf("\n[start all nets] while 10-7\n"); + + //jim-----------------------------------20210528 let trigger_survive live a long time + + /*end = clock(); + dur = (double)(end - start); + printf("\n[6-5-8]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + + //int check_trigger_exist = 0; + + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + if (pNext->zone_violation_idx[index_zone] == 1 && index_zone < viewChannelData[0].count_zone) { + + } + else { + pNext->zone_violation_idx[index_zone] = 0; + pNext->zone_check_giveway[index_zone] = 0; + } + } + + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0)) { + detection_zone_id = cJSON_CreateNumber(pNext->zone_violation_idx[0]); + cJSON_AddItemToObject(detect, "dz1", detection_zone_id); + detection_zone_id2 = cJSON_CreateNumber(pNext->zone_violation_idx[1]); + cJSON_AddItemToObject(detect, "dz2", detection_zone_id2); + detection_zone_id3 = cJSON_CreateNumber(pNext->zone_violation_idx[2]); + cJSON_AddItemToObject(detect, "dz3", detection_zone_id3); + detection_zone_id4 = cJSON_CreateNumber(pNext->zone_violation_idx[3]); + cJSON_AddItemToObject(detect, "dz4", detection_zone_id4); + detection_zone_id5 = cJSON_CreateNumber(pNext->zone_violation_idx[4]); + cJSON_AddItemToObject(detect, "dz5", detection_zone_id5); + detection_zone_id6 = cJSON_CreateNumber(pNext->zone_violation_idx[5]); + cJSON_AddItemToObject(detect, "dz6", detection_zone_id6); + detection_zone_id7 = cJSON_CreateNumber(pNext->zone_violation_idx[6]); + cJSON_AddItemToObject(detect, "dz7", detection_zone_id7); + detection_zone_id8 = cJSON_CreateNumber(pNext->zone_violation_idx[7]); + cJSON_AddItemToObject(detect, "dz8", detection_zone_id8); + trigger_type = cJSON_CreateNumber(pNext->trigger_type); + cJSON_AddItemToObject(detect, "behavior_id", trigger_type); + } + + if((strcmp(pNext->name, "object") == 0 && pNext->number_row == 2 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0)){} + else if (pNext->trigger_type >= 1) + { + if (((check_if_object_OK == 1 && + (check_if_cloud_have_been_post == 0 || + (store_post_ok >= 0 && store_long_ok >= 0)) + && strcmp(heartbeatData.enable_obj_once_to_post, "Yes") == 0) || strcmp(heartbeatData.enable_obj_once_to_post, "No") == 0)) + { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + cJSON_AddItemToObject(detect_udp, "behavior_id", cJSON_CreateNumber(pNext->trigger_type)); + } + + detection_zone_id_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[0]); + cJSON_AddItemToObject(detect_8592, "dz1", detection_zone_id_8592); + detection_zone_id2_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[1]); + cJSON_AddItemToObject(detect_8592, "dz2", detection_zone_id2_8592); + detection_zone_id3_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[2]); + cJSON_AddItemToObject(detect_8592, "dz3", detection_zone_id3_8592); + detection_zone_id4_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[3]); + cJSON_AddItemToObject(detect_8592, "dz4", detection_zone_id4_8592); + detection_zone_id5_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[4]); + cJSON_AddItemToObject(detect_8592, "dz5", detection_zone_id5_8592); + detection_zone_id6_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[5]); + cJSON_AddItemToObject(detect_8592, "dz6", detection_zone_id6_8592); + detection_zone_id7_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[6]); + cJSON_AddItemToObject(detect_8592, "dz7", detection_zone_id7_8592); + detection_zone_id8_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[7]); + cJSON_AddItemToObject(detect_8592, "dz8", detection_zone_id8_8592); + cJSON_AddItemToObject(detect_8592, "behavior_id", cJSON_CreateNumber(pNext->trigger_type)); + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + onvif_object[onvif_obj_number].behavior_id = pNext->trigger_type; + } + + check_if_send_udp_jpeg = 1; + + if (check_if_cloud_have_been_post == 0) { + + char temp_desc_cloud[1024] = { 0 }; + char temp_name_cloud[1024] = { 0 }; + + set_desc_and_name_for_cloud(pNext->trigger_type, temp_desc_cloud, temp_name_cloud); + + detection_zone_id_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[0]); + cJSON_AddItemToObject(detect_cloud, "dz1", detection_zone_id_cloud); + detection_zone_id2_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[1]); + cJSON_AddItemToObject(detect_cloud, "dz2", detection_zone_id2_cloud); + detection_zone_id3_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[2]); + cJSON_AddItemToObject(detect_cloud, "dz3", detection_zone_id3_cloud); + detection_zone_id4_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[3]); + cJSON_AddItemToObject(detect_cloud, "dz4", detection_zone_id4_cloud); + detection_zone_id5_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[4]); + cJSON_AddItemToObject(detect_cloud, "dz5", detection_zone_id5_cloud); + detection_zone_id6_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[5]); + cJSON_AddItemToObject(detect_cloud, "dz6", detection_zone_id6_cloud); + detection_zone_id7_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[6]); + cJSON_AddItemToObject(detect_cloud, "dz7", detection_zone_id7_cloud); + detection_zone_id8_cloud = cJSON_CreateNumber(pNext->zone_violation_idx[7]); + cJSON_AddItemToObject(detect_cloud, "dz8", detection_zone_id8_cloud); + trigger_type_cloud = cJSON_CreateNumber(pNext->trigger_type); + cJSON_AddItemToObject(detect_cloud, "behavior_id", trigger_type_cloud); + trigger_type_name_cloud = cJSON_CreateString(temp_name_cloud); + cJSON_AddItemToObject(detect_cloud, "behavior_name", trigger_type_name_cloud); + trigger_type_desc_cloud = cJSON_CreateString(temp_desc_cloud);//Tϰ UTF8 Encoder + cJSON_AddItemToObject(detect_cloud, "behavior_desc", trigger_type_desc_cloud); + } + } + else { + detection_zone_id_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[0]); + cJSON_AddItemToObject(detect_8592, "dz1", detection_zone_id_8592); + detection_zone_id2_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[1]); + cJSON_AddItemToObject(detect_8592, "dz2", detection_zone_id2_8592); + detection_zone_id3_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[2]); + cJSON_AddItemToObject(detect_8592, "dz3", detection_zone_id3_8592); + detection_zone_id4_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[3]); + cJSON_AddItemToObject(detect_8592, "dz4", detection_zone_id4_8592); + detection_zone_id5_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[4]); + cJSON_AddItemToObject(detect_8592, "dz5", detection_zone_id5_8592); + detection_zone_id6_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[5]); + cJSON_AddItemToObject(detect_8592, "dz6", detection_zone_id6_8592); + detection_zone_id7_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[6]); + cJSON_AddItemToObject(detect_8592, "dz7", detection_zone_id7_8592); + detection_zone_id8_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[7]); + cJSON_AddItemToObject(detect_8592, "dz8", detection_zone_id8_8592); + + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + cJSON_AddItemToObject(detect_udp, "behavior_id", cJSON_CreateNumber(pNext->trigger_type)); + } + cJSON_AddItemToObject(detect_8592, "behavior_id", cJSON_CreateNumber(pNext->trigger_type)); + } + else { + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + cJSON_AddItemToObject(detect_udp, "behavior_id", cJSON_CreateNumber(0)); + } + cJSON_AddItemToObject(detect_8592, "behavior_id", cJSON_CreateNumber(0)); + } + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + onvif_object[onvif_obj_number].behavior_id = 0; + } + } + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + onvif_obj_number++; + } + } + else if((strcmp(pNext->name, "object") != 0 && strcmp(SystemSetting.enable_bounding_box, "Yes") == 0) || IsANPRCategory(pNext->engine_type) || (strcmp(pNext->name, "object") == 0 && strcmp(viewChannelData[0].enable_show_unknown_object, "Yes") == 0) || + (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0) || + (strcmp(pNext->name, "object") != 0 && strcmp(SystemSetting.enable_bounding_box, "No") == 0 && strcmp(heartbeatData.events_default_version, "4") == 0 && check_if_show_parking == 1)){ + if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) + { + cJSON_AddItemToObject(detect_udp, "behavior_id", cJSON_CreateNumber(0)); + } + + detection_zone_id_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[0]); + cJSON_AddItemToObject(detect_8592, "dz1", detection_zone_id_8592); + detection_zone_id2_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[1]); + cJSON_AddItemToObject(detect_8592, "dz2", detection_zone_id2_8592); + detection_zone_id3_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[2]); + cJSON_AddItemToObject(detect_8592, "dz3", detection_zone_id3_8592); + detection_zone_id4_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[3]); + cJSON_AddItemToObject(detect_8592, "dz4", detection_zone_id4_8592); + detection_zone_id5_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[4]); + cJSON_AddItemToObject(detect_8592, "dz5", detection_zone_id5_8592); + detection_zone_id6_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[5]); + cJSON_AddItemToObject(detect_8592, "dz6", detection_zone_id6_8592); + detection_zone_id7_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[6]); + cJSON_AddItemToObject(detect_8592, "dz7", detection_zone_id7_8592); + detection_zone_id8_8592 = cJSON_CreateNumber(pNext->zone_violation_idx[7]); + cJSON_AddItemToObject(detect_8592, "dz8", detection_zone_id8_8592); + cJSON_AddItemToObject(detect_8592, "behavior_id", cJSON_CreateNumber(0)); + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && onvif_obj_number < 50 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + onvif_object[onvif_obj_number].behavior_id = 0; + onvif_obj_number++; + } + } + } + +#ifdef GY_OS_AMBA + //face total element size = leo + // char face_name[100]; + // int face_uuid; + // float identification_score; + // int face_trackingID + // pnext info g DB log list +#if 0 + if (unlockingKeyInnoFR == 1 && viewChannelData[0].enable_face == 1 && strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0) + { + pthread_mutex_lock(&mutex_enable_face_db); +#ifdef FACE_AMBA_DEBUG + printf("\n[start all nets]------15 total_element_size: %d\n", total_element_size); +#endif + for (int i = 0; i < total_element_size; i++) { + pNext = PosInfo + i; /** sizeof(detection_pos)*/ + + //char s_face_name[20]; + char s_face_uuid[20]; + char s_identification_score[20]; + char s_face_trackingID[20]; + + // sprintf(s_face_uuid, "%d", 123); + // sprintf(s_identification_score, "%.2f", 80.12); + // sprintf(s_face_trackingID, "%d", 32); + sprintf(s_face_uuid, "%s", pNext->FDFR.face_uuid); + // sprintf(s_identification_score, "%.2f", pNext->FDFR.identification_score); + sprintf(s_identification_score, "%.0f", pNext->FDFR.identification_score); + sprintf(s_face_trackingID, "%d", pNext->FDFR.face_trackingID); +#ifdef FACE_AMBA_DEBUG + printf("\n[start all nets]------66 pNext addr: %p\n", pNext); + printf("[start all nets] face_uuid=%s, identification_score=%.2f, face_trackingID=%d\n", pNext->FDFR.face_uuid, pNext->FDFR.identification_score, pNext->FDFR.face_trackingID); +#endif + time_t rawtime = time(0); + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + //printf("Current local time and date: %s", asctime(timeinfo)); + + struct timeval time_now; + gettimeofday(&time_now, NULL); + time_t msecs_time = time_now.tv_usec / 1000; + + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "%04d-%02d-%02d %02d:%02d:%02d:%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, + timeinfo->tm_min, timeinfo->tm_sec, msecs_time); + + strcpy(l_face_insert_data.MOD_TS, buf_time_info); + + // strcpy(l_face_insert_data.TS,l_ff_insert_data.TS); + // // strcpy(l_face_insert_data.MOD_TS,l_ff_insert_data.MOD_TS); + // strcpy(l_face_insert_data.CAR_ID,l_ff_insert_data.CAR_ID); + // strcpy(l_face_insert_data.LPR,l_ff_insert_data.LPR); + // strcpy(l_face_insert_data.RTIME,l_ff_insert_data.RTIME); + // strcpy(l_face_insert_data.ACTION,l_ff_insert_data.ACTION); + // strcpy(l_face_insert_data.sec_color_id,l_ff_insert_data.sec_color_id); + // strcpy(l_face_insert_data.ACT_PARAM,l_ff_insert_data.ACT_PARAM); + // strcpy(l_face_insert_data.THRESHOLD,l_ff_insert_data.THRESHOLD); + // strcpy(l_face_insert_data.ROI_X,l_ff_insert_data.ROI_X); + // strcpy(l_face_insert_data.ROI_Y,l_ff_insert_data.ROI_Y); + // strcpy(l_face_insert_data.ROI_W,l_ff_insert_data.ROI_W); + // strcpy(l_face_insert_data.ROI_H,l_ff_insert_data.ROI_H); + // strcpy(l_face_insert_data.LP_X,l_ff_insert_data.LP_X); + // strcpy(l_face_insert_data.LP_Y,l_ff_insert_data.LP_Y); + // strcpy(l_face_insert_data.LP_W,l_ff_insert_data.LP_W); + // strcpy(l_face_insert_data.LP_H,l_ff_insert_data.LP_H); + // strcpy(l_face_insert_data.LP_BMP,l_ff_insert_data.LP_BMP); + // strcpy(l_face_insert_data.ROI_BMP,l_ff_insert_data.ROI_BMP); + // strcpy(l_face_insert_data.COUNTRY,l_ff_insert_data.COUNTRY); + // strcpy(l_face_insert_data.IN_USER,l_ff_insert_data.IN_USER); + // strcpy(l_face_insert_data.IN_PHONE,l_ff_insert_data.IN_PHONE); + // strcpy(l_face_insert_data.IN_ADDRESS,l_ff_insert_data.IN_ADDRESS); + // strcpy(l_face_insert_data.IN_PAYSTATUS,l_ff_insert_data.IN_PAYSTATUS); + // strcpy(l_face_insert_data.IN_EXIST,l_ff_insert_data.IN_EXIST); + // strcpy(l_face_insert_data.IN_SCHEDULE_START,l_ff_insert_data.IN_SCHEDULE_START); + // strcpy(l_face_insert_data.IN_SCHEDULE_END,l_ff_insert_data.IN_SCHEDULE_END); + // strcpy(l_face_insert_data.IN_OTHER,l_ff_insert_data.IN_OTHER); + + strcpy(l_face_insert_data.LP_BMP, pNext->FDFR.face_bmp); + strcpy(l_face_insert_data.face_name, pNext->FDFR.face_name); + strcpy(l_face_insert_data.user_name, pNext->FDFR.user_name); + strcpy(l_face_insert_data.face_uuid, pNext->FDFR.face_uuid); + // strcpy(l_face_insert_data.face_uuid,s_face_uuid); + strcpy(l_face_insert_data.identification_score, s_identification_score); + strcpy(l_face_insert_data.face_trackingID, s_face_trackingID); + strcpy(l_face_insert_data.sql_tbname, FACE_MSG_TABLE); //should change table name +#ifdef FACE_AMBA_DEBUG + if (strlen(l_face_insert_data.face_name) == 0) { + printf("face_name is null\n"); + continue; + } + else { + printf("face_name is %s\n", l_face_insert_data.face_name); + } +#endif + + + int bool_check_if_not_in_black_and_white_face = 0; + + if (check_if_in_white_face(l_face_insert_data.face_name)) { + sprintf(l_face_insert_data.RTIME, "%s", "vip"); + } else if (check_if_in_black_face(l_face_insert_data.face_name)) { + sprintf(l_face_insert_data.RTIME, "%s", "watch"); + } else { + bool_check_if_not_in_black_and_white_face = 1; + sprintf(l_face_insert_data.RTIME, "%s", "visitor"); // now comment visitor -> watch + } +#ifdef FACE_AMBA_DEBUG + printf("\n[start all nets] === insert face DB log list (pNext)face_name=%s, face_uuid=%d, identification_score=%.2f, face_trackingID=%d face_bmp=%s \n", pNext->FDFR.face_name, pNext->FDFR.face_uuid, pNext->FDFR.identification_score, pNext->FDFR.face_trackingID, pNext->FDFR.face_bmp); + printf("\n[start all nets] (l_face_insert_data) RTIME: %s, ACT_PARAM: %s, LP_BMP: %s, sql_tbname: %s, face_name: %s, user_name: %s, face_uuid: %s\n", + l_face_insert_data.RTIME, + l_face_insert_data.ACT_PARAM, + l_face_insert_data.LP_BMP, + l_face_insert_data.sql_tbname, + l_face_insert_data.face_name, + l_face_insert_data.user_name, + l_face_insert_data.face_uuid); +#endif + sqlite_facegroup_insert(&l_face_insert_data, LOGLISTNAME); // face write in DB list 'log' - leo + // strcpy(l_ff_insert_data.sql_tbname, FACE_MSG_TABLE); //should change table name + // sqlite_facegroup_insert(&l_ff_insert_data, LOGLISTNAME); // face write in DB list 'log' - leo + + { // && check_if_not_in_black_and_white_face() - check_if_not_in_black_and_white_face() need to be added face condition -leo + // strcpy(l_ff_insert_data.sql_tbname, FACE_MSG_CUSTOMERTABLE); + // sqlite_facegroup_insert(&l_ff_insert_data, CUSTLISTNAME); //face write in DB list 'customer' - leo + // strcpy(l_face_insert_data.sql_tbname, FACE_MSG_CUSTOMERTABLE); + // sqlite_facegroup_insert(&l_face_insert_data, CUSTLISTNAME); //face write in DB list 'customer' - leo + // printf("=== insert face DB customer list\n"); + } + } + pthread_mutex_unlock(&mutex_enable_face_db); + } +#endif +#endif + +#ifdef GY_OS_AMBA + if (strcmp(heartbeatData.enable_heatmap, "Yes") == 0) { + gettimeofday(&currtime_heatmap, NULL); + now_heatmap = (currtime_heatmap.tv_sec * 1000) + (currtime_heatmap.tv_usec / 1000); //쬰@ + + if (abs((double)(now_heatmap - last_heatmap)) >= (double)(atoi(heartbeatData.heatmap_frequency)*1000)) + { + int check_the_time_is_image = 0; + //printf("\n-------AA:%d\n", count_heatmap_time * atoi(heartbeatData.heatmap_frequency)); + if (g_current_snapshot_size >= 1 && (count_heatmap_time == -1 || count_heatmap_time * atoi(heartbeatData.heatmap_frequency) >= 600)) { + //pthread_mutex_lock(&mutex_send_jpeg); + pthread_mutex_lock(&mutex_heatmap_jpeg); + char write_filename[256] = { 0 }; + sprintf(write_filename, "/emmc/plugin/Aida_data/playback/%ld.jpg", (now_heatmap / 1000) * 1000); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + /*if (enable_zone_crop_1 == 1 && g_current_snapshot_size_crop_zone >= 1) { + fwrite(g_current_snapshot_addr_crop_zone, sizeof(char), g_current_snapshot_size_crop_zone, fp); + } + else */ + { +#ifdef GY_OS_AMBA + fwrite(g_current_snapshot_addr_HD, sizeof(char), g_current_snapshot_size_HD, fp); +#else + fwrite(g_current_snapshot_addr, sizeof(char), g_current_snapshot_size, fp); +#endif + + check_the_time_is_image = 1; + count_heatmap_time = 0; + } + //printf("[PNS Get Snapshot From IPCam] Wrote to the file: %s.\n", write_filename); + fclose(fp); + } + else { + count_heatmap_time = -1; + printf("[start all nets] #2 (For debugging) Error occurred when opening file I/O.\n"); + } + pthread_mutex_unlock(&mutex_heatmap_jpeg); + //pthread_mutex_unlock(&mutex_send_jpeg); + } + else if (/*g_current_snapshot_size >= 1 &&*/ count_heatmap_time != -1 && count_heatmap_time * atoi(heartbeatData.heatmap_frequency) < 600) { + count_heatmap_time++; + } + + last_heatmap = now_heatmap; + //printf("\n----------now_heatmap:%ld\n", now_heatmap); + + g_image_HD_pasue_time = now_heatmap/1000*1000; + + struct tm *info_heatmap; + info_heatmap = localtime(&currtime_heatmap.tv_sec); + int current_wday = info_heatmap->tm_wday == 0 ? 7 : info_heatmap->tm_wday; + /* + char buf_time_info[256] = { 0 }; + sprintf(buf_time_info, "[Heat]%04d-%02d-%02d %02d:%02d:%02d", 1900 + info_heatmap->tm_year, 1 + info_heatmap->tm_mon, info_heatmap->tm_mday, info_heatmap->tm_hour, + info_heatmap->tm_min, info_heatmap->tm_sec); + //info_heatmap->tm_wday PX[0-6] + printf("\n----------now_heatmap:%s", buf_time_info);*/ + + if (last_wday != -1 && current_wday != last_wday) { + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", "/emmc/plugin/Aida/heatmap_data.js"); + last_wday = current_wday; + } + + FILE *fp_read, *fp_write; + + int check_if_file_correct = 0; + int check_if_OK_to_open = 0; + + if ((fp_read = fopen("/emmc/plugin/Aida/heatmap_data.js", "r")) != NULL) + { + check_if_OK_to_open = 1; + fp_write = fopen("/emmc/plugin/Aida/heatmap_data_import.js", "w+"); + + if (fp_write != NULL) { + int count_line = 0; + while (feof(fp_read) == 0) + { + char line_fp[256] = { 0 }; + fscanf(fp_read, "%s ", line_fp); + + if (strstr(line_fp, "var") != NULL || + strstr(line_fp, "mSdata") != NULL || + strstr(line_fp, "=") != NULL || + strstr(line_fp, "hereDoc") != NULL + ) { + fprintf(fp_write, "%s ", line_fp); + check_if_file_correct++; + } + else if (strstr(line_fp, "{") != NULL) { + fprintf(fp_write, "%s\r\n", line_fp); + check_if_file_correct++; + } + else if (strstr(line_fp, "}") != NULL) { + //fprintf(fp_write, "%s", line_fp); + } + else { + if (count_line < 40000 && strlen(line_fp)>=19) { + int check_if_all_digit = 1; + for (int index_line = 0; index_line < 13; index_line++) { + if (!isdigit(line_fp[index_line])) { + check_if_all_digit = 0; + break; + } + } + if (check_if_all_digit == 1 && line_fp[13] == ',') { + char c_time_line[25] = { 0 }; + memcpy(c_time_line, line_fp,13); + + long time_line = atol(c_time_line); + + + if (((now_heatmap / 1000) * 1000 - time_line) / 1000 <= 24 * 60 * 60) { + fprintf(fp_write, "%s\r\n", line_fp); + count_line++; + } + } + } + } + } + + for (int j = 0; j < count_behavior_id && count_line < 40000; j++) { + + fprintf(fp_write, "%ld,%d,%d,%d\r\n", (now_heatmap / 1000) * 1000, heatmap_center_x[j], heatmap_center_y[j], check_the_time_is_image); + count_line++; + } + + fprintf(fp_write, "%s", "*/});"); + check_if_file_correct++; + + fclose(fp_write); + } + fclose(fp_read); + } + + if (check_if_file_correct == 6) { + CopyFileTo("/emmc/plugin/Aida/heatmap_data_import.js", "/emmc/plugin/Aida/heatmap_data.js"); + CopyFileTo("/emmc/plugin/Aida/heatmap_data_import.js", "/emmc/plugin/Aida_data/heatmap_data_bak.js"); + + char buf_file[256] = { 0 }; + sprintf(buf_file, "/emmc/plugin/Aida/heatmap_data_%d.js", current_wday); + CopyFileTo("/emmc/plugin/Aida/heatmap_data_import.js", buf_file); + + char buf_file_bak[256] = { 0 }; + sprintf(buf_file_bak, "/emmc/plugin/Aida_data/heatmap_data_%d_bak.js", current_wday); + CopyFileTo("/emmc/plugin/Aida/heatmap_data_import.js", buf_file_bak); + + } + else if (check_if_file_correct <= 5) { + if (!FileExist("/emmc/plugin/Aida_data/heatmap_data_bak.js") || ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_bak.js") == 0) { + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", "/emmc/plugin/Aida/heatmap_data.js"); + } + else { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_bak.js", "/emmc/plugin/Aida/heatmap_data.js"); + } + } + else if (check_if_OK_to_open == 1) { + if (!FileExist("/emmc/plugin/Aida_data/heatmap_data_bak.js") || ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_bak.js") == 0) { + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", "/emmc/plugin/Aida/heatmap_data.js"); + } + else { + CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_bak.js", "/emmc/plugin/Aida/heatmap_data.js"); + } + } + } + } +#endif + + parking_space_check_table = cJSON_CreateArray(); + //parking_space_check_table_udp = cJSON_CreateArray(); + parking_space_check_table_8592 = cJSON_CreateArray(); + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + a_parking_space_check_table = cJSON_CreateArray(); + //a_parking_space_check_table_udp = cJSON_CreateArray(); + a_parking_space_check_table_8592 = cJSON_CreateArray(); + for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][j].parking_space; index_plot++) + { + cJSON_AddItemToArray(a_parking_space_check_table, cJSON_CreateNumber(g_parking_space_check_table[j][index_plot])); + //cJSON_AddItemToArray(a_parking_space_check_table_udp, cJSON_CreateNumber(g_parking_space_check_table[j][index_plot])); + cJSON_AddItemToArray(a_parking_space_check_table_8592, cJSON_CreateNumber(g_parking_space_check_table[j][index_plot])); + } + cJSON_AddItemToArray(parking_space_check_table, a_parking_space_check_table); + //cJSON_AddItemToArray(parking_space_check_table_udp, a_parking_space_check_table_udp); + cJSON_AddItemToArray(parking_space_check_table_8592, a_parking_space_check_table_8592); + } + cJSON_AddItemToObject(root, "parking_space_check_table", parking_space_check_table); + //cJSON_AddItemToObject(root_udp, "parking_space_check_table", parking_space_check_table_udp); + cJSON_AddItemToObject(root_8592, "parking_space_check_table", parking_space_check_table_8592); + + /*end = clock(); + dur = (double)(end - start); + printf("\n[6-6]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + //printf("\n[start all nets] while 17\n"); + +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + g_IsCustomWeight == 1 || +#ifdef GY_OS_AMBA + unlockingKeyInnoFR_success == 1 +#else + IsANPRCategory(featureType) +#endif + ) { + + counter_count = cJSON_CreateArray(); + counter_count_cloud = cJSON_CreateArray(); + counter_count_udp = cJSON_CreateArray(); + counter_count_8592 = cJSON_CreateArray(); + counter_zone = cJSON_CreateArray(); + counter_zone_cloud = cJSON_CreateArray(); + counter_zone_udp = cJSON_CreateArray(); + counter_zone_8592 = cJSON_CreateArray(); + counter_reset_value = cJSON_CreateArray(); + counter_reset_value_cloud = cJSON_CreateArray(); + //counter_reset_value_udp = cJSON_CreateArray(); + counter_reset_value_8592 = cJSON_CreateArray(); + counter_operand = cJSON_CreateArray(); + counter_operand_cloud = cJSON_CreateArray(); + counter_operand_udp = cJSON_CreateArray(); + counter_operand_8592 = cJSON_CreateArray(); + + char temp_counter_operand[MAX_EVENT_COUNTERS][10] = { 0 }; + + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + for (int k_index = 0; k_index < MAX_TRIGGER_EVENT; k_index++) { + if (viewDetectionZone[0][j].trigger_event[k_index].checked) { + int index_counter = -1; + if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter01") == 0) { + index_counter = 0; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter02") == 0) { + index_counter = 1; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter03") == 0) { + index_counter = 2; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter04") == 0) { + index_counter = 3; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter05") == 0) { + index_counter = 4; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter06") == 0) { + index_counter = 5; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter07") == 0) { + index_counter = 6; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter08") == 0) { + index_counter = 7; + } + else { + break; + } + + if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == 1) + { + strcpy(temp_counter_operand[index_counter], "+1"); + } + else if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == -1) + { + strcpy(temp_counter_operand[index_counter], "-1"); + } + else if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == 0) + { + strcpy(temp_counter_operand[index_counter], "="); + } + else if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == -2) + { + strcpy(temp_counter_operand[index_counter], "NULL"); + } + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + strcpy(onvif_counter[index_counter].onvif_counter_name, viewDetectionZone[0][j].trigger_event[k_index].counter_name); + onvif_counter[index_counter].onvif_detect_event_id = onvif_counter[index_counter].onvif_detect_event_id | HexStringToInt(viewDetectionZone[0][j].trigger_event[k_index].detect_event_id); + onvif_counter[index_counter].forward_line = atoi(viewDetectionZone[0][j].direction1); + strcpy(onvif_counter[index_counter].onvif_ReportTimeInterval, eventCounterList[index_counter].ReportTimeInterval); + strcpy(onvif_counter[index_counter].onvif_ResetTime, eventCounterList[index_counter].ResetTime); + strcpy(onvif_counter[index_counter].onvif_Direction, "Right"); + strcpy(onvif_counter[index_counter].onvif_PassAllPolylines, "false"); + + for (int index_point = 0; index_point < 6; index_point++) { + onvif_counter[index_counter].onvif_Points[index_point].x = viewDetectionZone[0][j].onvif_Points[index_point].x; + onvif_counter[index_counter].onvif_Points[index_point].y = viewDetectionZone[0][j].onvif_Points[index_point].y; + } + + onvif_counter[index_counter].counter_count = eventCounterList[index_counter].counter_count; + onvif_counter[index_counter].dwell_time = eventCounterList[index_counter].dwell_time; + } + + break; + } + } + } + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + + cJSON_AddItemToArray(counter_count, cJSON_CreateNumber(eventCounterList[j].counter_count)); + cJSON_AddItemToArray(counter_count_cloud, cJSON_CreateNumber(eventCounterList[j].counter_count)); + cJSON_AddItemToArray(counter_count_udp, cJSON_CreateNumber(eventCounterList[j].counter_count)); + cJSON_AddItemToArray(counter_count_8592, cJSON_CreateNumber(eventCounterList[j].counter_count)); + + cJSON_AddItemToArray(counter_zone, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + cJSON_AddItemToArray(counter_zone_cloud, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + cJSON_AddItemToArray(counter_zone_udp, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + cJSON_AddItemToArray(counter_zone_8592, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + + cJSON_AddItemToArray(counter_reset_value, cJSON_CreateNumber(eventCounterList[j].reset_value)); + cJSON_AddItemToArray(counter_reset_value_cloud, cJSON_CreateNumber(eventCounterList[j].reset_value)); + //cJSON_AddItemToArray(counter_reset_value_udp, cJSON_CreateNumber(eventCounterList[j].reset_value)); + cJSON_AddItemToArray(counter_reset_value_8592, cJSON_CreateNumber(eventCounterList[j].reset_value)); + + if (strlen(temp_counter_operand[j]) == 0) { + strcpy(temp_counter_operand[j], "NULL"); + } + cJSON_AddItemToArray(counter_operand, cJSON_CreateString(temp_counter_operand[j])); + cJSON_AddItemToArray(counter_operand_cloud, cJSON_CreateString(temp_counter_operand[j])); + //cJSON_AddItemToArray(counter_operand_udp, cJSON_CreateString(temp_counter_operand[j])); + cJSON_AddItemToArray(counter_operand_8592, cJSON_CreateString(temp_counter_operand[j])); + } + + cJSON_AddItemToObject(root, "counter_count", counter_count); + cJSON_AddItemToObject(root_cloud, "counter_count", counter_count_cloud); + cJSON_AddItemToObject(root_udp, "counter_count", counter_count_udp); + cJSON_AddItemToObject(root_8592, "counter_count", counter_count_8592); + + cJSON_AddItemToObject(root, "counter_zone", counter_zone); + cJSON_AddItemToObject(root_cloud, "counter_zone", counter_zone_cloud); + cJSON_AddItemToObject(root_udp, "counter_zone", counter_zone_udp); + cJSON_AddItemToObject(root_8592, "counter_zone", counter_zone_8592); + + cJSON_AddItemToObject(root, "counter_reset_value", counter_reset_value); + cJSON_AddItemToObject(root_cloud, "counter_reset_value", counter_reset_value_cloud); + //cJSON_AddItemToObject(root_udp, "counter_reset_value", counter_reset_value_udp); + cJSON_AddItemToObject(root_8592, "counter_reset_value", counter_reset_value_8592); + cJSON_AddItemToObject(root, "counter_operand", counter_operand); + cJSON_AddItemToObject(root_cloud, "counter_operand", counter_operand_cloud); + //cJSON_AddItemToObject(root_udp, "counter_operand", counter_operand_udp); + cJSON_AddItemToObject(root_8592, "counter_operand", counter_operand_8592); + + cJSON_counters = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "counters", cJSON_counters); + + cJSON_counters_cloud = cJSON_CreateArray(); + cJSON_AddItemToObject(root_cloud, "counters", cJSON_counters_cloud); + + cJSON_counters_udp = cJSON_CreateArray(); + cJSON_AddItemToObject(root_udp, "counters", cJSON_counters_udp); + + cJSON_counters_8592 = cJSON_CreateArray(); + cJSON_AddItemToObject(root_8592, "counters", cJSON_counters_8592); + + } + + if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0) { + for (int index_post = 0; index_post < size_g_PostRecorderList; index_post++) { + g_PostRecorderList[index_g_PostRecorderList[index_post]].check_if_getalarmmotion = 1; + } + + for (int index_post = 0; index_post < size_g_PostRecorderList_longterm; index_post++) { + g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[index_post]].check_if_getalarmmotion = 1; + } + } + +#endif + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + char c_something_vanish_in_zone[50] = { 0 }; + sprintf(c_something_vanish_in_zone, "vz%d", (j + 1)); + + if ((viewDetectionZone[tracking_channel_idx][j].check_if_missing == 1 || get_g_check_if_NAND(j) == 1 || get_g_check_if_all_existing(j) == 1) + && j < viewChannelData[tracking_channel_idx].count_zone) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || + trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || + trigger_event_type == TRIGGER_ALL_OBJECTS) { + //CheckEventCounterCondition(pNext, tracking_channel_idx, j, k,1); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + check_if_something_vanish_in_zone_Yes[j] = 1; + } + } + } + if (check_if_something_vanish_in_zone_Yes[j] == 1) { + something_vanish_in_zone = cJSON_CreateString("Yes"); + cJSON_AddItemToObject(root, c_something_vanish_in_zone, something_vanish_in_zone); + + something_vanish_in_zone_cloud = cJSON_CreateString("Yes"); + cJSON_AddItemToObject(root_cloud, c_something_vanish_in_zone, something_vanish_in_zone_cloud); + + //something_vanish_in_zone_udp = cJSON_CreateString("Yes"); + //cJSON_AddItemToObject(root_udp, c_something_vanish_in_zone, something_vanish_in_zone_udp); + + something_vanish_in_zone_8592 = cJSON_CreateString("Yes"); + cJSON_AddItemToObject(root_8592, c_something_vanish_in_zone, something_vanish_in_zone_8592); + } + else { + something_vanish_in_zone = cJSON_CreateString("No"); + cJSON_AddItemToObject(root, c_something_vanish_in_zone, something_vanish_in_zone); + + something_vanish_in_zone_cloud = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_cloud, c_something_vanish_in_zone, something_vanish_in_zone_cloud); + + //something_vanish_in_zone_udp = cJSON_CreateString("No"); + //cJSON_AddItemToObject(root_udp, c_something_vanish_in_zone, something_vanish_in_zone_udp); + + something_vanish_in_zone_8592 = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_8592, c_something_vanish_in_zone, something_vanish_in_zone_8592); + } + } + else { + something_vanish_in_zone = cJSON_CreateString("No"); + cJSON_AddItemToObject(root, c_something_vanish_in_zone, something_vanish_in_zone); + + something_vanish_in_zone_cloud = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_cloud, c_something_vanish_in_zone, something_vanish_in_zone_cloud); + + //something_vanish_in_zone_udp = cJSON_CreateString("No"); + //cJSON_AddItemToObject(root_udp, c_something_vanish_in_zone, something_vanish_in_zone_udp); + + something_vanish_in_zone_8592 = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_8592, c_something_vanish_in_zone, something_vanish_in_zone_8592); + } + } + + time_t rawtime_temp = time(0); + struct tm * timeinfo_temp; + timeinfo_temp = localtime(&rawtime_temp); + if (timeinfo_temp->tm_sec % 60 == 0) { + + cJSON_viewDetectionZone = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "detection_zone", cJSON_viewDetectionZone); + + cJSON_viewDetectionZone_udp = cJSON_CreateArray(); + cJSON_AddItemToObject(root_udp, "detection_zone", cJSON_viewDetectionZone_udp); + + cJSON_viewDetectionZone_8592 = cJSON_CreateArray(); + cJSON_AddItemToObject(root_8592, "detection_zone", cJSON_viewDetectionZone_8592); + + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + cJSON_a_zone = cJSON_CreateObject(); + cJSON_AddItemToArray(cJSON_viewDetectionZone, cJSON_a_zone); + + cJSON_a_zone_udp = cJSON_CreateObject(); + cJSON_AddItemToArray(cJSON_viewDetectionZone_udp, cJSON_a_zone_udp); + + cJSON_a_zone_8592 = cJSON_CreateObject(); + cJSON_AddItemToArray(cJSON_viewDetectionZone_8592, cJSON_a_zone_8592); + + cJSON_AddItemToObject(cJSON_a_zone, "x1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + + cJSON_AddItemToObject(cJSON_a_zone_udp, "x1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + + cJSON_AddItemToObject(cJSON_a_zone_8592, "x1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + } + } + + detect_count = cJSON_CreateNumber(count_behavior_id); + cJSON_AddItemToObject(root, "Count", detect_count); + + detect_count_udp = cJSON_CreateNumber(count_behavior_id_larger_zero_udp); + cJSON_AddItemToObject(root_udp, "Count", detect_count_udp); + + detect_count_8592 = cJSON_CreateNumber(count_behavior_id_larger_zero_udp); + cJSON_AddItemToObject(root_8592, "Count", detect_count_8592); +#ifdef GY_OS_AMBA + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + + //osd cgi object + osd_array = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "osd_array", osd_array); + + //char *JsonString_array; + for (int i = 0; i < MAX_SIZE_OSD_ARRAY; i++) + { + if (OSDData[i].flag_protected == 1) { + + osd_detect = cJSON_CreateObject(); + cJSON_AddItemToArray(osd_array, osd_detect); + id = cJSON_CreateNumber(OSDData[i].id); + cJSON_AddItemToObject(osd_detect, "id", id); + x = cJSON_CreateNumber(OSDData[i].x); + cJSON_AddItemToObject(osd_detect, "x", x); + y = cJSON_CreateNumber(OSDData[i].y); + cJSON_AddItemToObject(osd_detect, "y", y); + w = cJSON_CreateNumber(OSDData[i].w); + cJSON_AddItemToObject(osd_detect, "w", w); + h = cJSON_CreateNumber(OSDData[i].h); + cJSON_AddItemToObject(osd_detect, "h", h); + osd_color = cJSON_CreateNumber(OSDData[i].color); + cJSON_AddItemToObject(osd_detect, "color", osd_color); + + osd_size = cJSON_CreateNumber(OSDData[i].size); + cJSON_AddItemToObject(osd_detect, "size", osd_size); + osd_sec = cJSON_CreateNumber(OSDData[i].show_sec); + cJSON_AddItemToObject(osd_detect, "ms", osd_sec); + osd_text = cJSON_CreateString(OSDData[i].text); + + outline_sw = cJSON_CreateNumber(OSDData[i].outline_sw); + cJSON_AddItemToObject(osd_detect, "ol_sw", outline_sw); + bg_tran = cJSON_CreateNumber(OSDData[i].bg_tran); + cJSON_AddItemToObject(osd_detect, "bg_tran", bg_tran); + + //printf("[%d]----------------------------------%d, %d \n", i, bg_tran->valueint, outline_sw->valueint); + + cJSON_AddItemToObject(osd_detect, "text", osd_text); + OSDData[i].flag_protected = 0; + } + //JsonString_array = cJSON_PrintUnformatted(osd_array); + //printf("[%d]osd_array----%s \n", i, JsonString_array); + } + osd_Time_sw = cJSON_CreateNumber(g_osdTime_sw); + cJSON_AddItemToObject(root, "osd_Time_sw", osd_Time_sw); + + osd_TimeStamp = cJSON_CreateNumber(g_osdSysTimeStamp); + cJSON_AddItemToObject(root, "osd_TimeStamp", osd_TimeStamp); + + osd_TimeZoneInfo = cJSON_CreateNumber(g_osdSysTimeZoneInfo); + cJSON_AddItemToObject(root, "osd_TimeZoneInfo", osd_TimeZoneInfo); + + + osd_encoder_id = cJSON_CreateNumber(atoi(SystemSetting.osd_encoder_id)); + cJSON_AddItemToObject(root, "osd_encoder_id", osd_encoder_id); + + osd_font_size = cJSON_CreateNumber(atoi(SystemSetting.osd_font_size)); + cJSON_AddItemToObject(root, "osd_font_size", osd_font_size); + + osd_outline_lilin = cJSON_CreateNumber(atoi(SystemSetting.osd_outline_lilin)); + cJSON_AddItemToObject(root, "osd_outline_lilin", osd_outline_lilin); + + enable_osd_bottom = cJSON_CreateString(SystemSetting.enable_osd_bottom); + cJSON_AddItemToObject(root, "enable_osd_bottom", enable_osd_bottom); + + osd_bottom_bg_tran = cJSON_CreateNumber(atoi(SystemSetting.osd_bottom_bg_tran)); + cJSON_AddItemToObject(root, "osd_bottom_bg_tran", osd_bottom_bg_tran); + + char output_osd_bottom_content[BUFSIZE_V3] = { 0 }; + char empty_image[10] = { 0 }; + detection_pos *pNext_word = NULL; + + for (int index_pos = 0; index_pos < total_element_size; index_pos++) { + detection_pos *pNext_word_temp = PosInfo + index_pos; + if (pNext_word_temp->trigger_type != 0) { + pNext_word = pNext_word_temp; + break; + } + } + if (pNext_word == NULL) { + pNext_word = PosInfo; + } + + int trigger_zone_id = 0; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + if (pNext_word->zone_violation_idx[index_zone] == 1) { + trigger_zone_id = index_zone + 1; + break; + } + } + + + if (pNext_word->trigger_type != 0 && trigger_zone_id >= 1 && pNext_word->trigger_idx[trigger_zone_id-1] >= 0) { + ReplaceKeyWords(pNext_word, -1, -1,SystemSetting.osd_bottom_content, output_osd_bottom_content, 0, trigger_zone_id-1, pNext_word->trigger_idx[trigger_zone_id - 1], empty_image, 0, 0, g_cropped_img_buf_base64, g_cropped_length_image_base64,0); + } + else { + ReplaceKeyWords(pNext_word, -1, -1,SystemSetting.osd_bottom_content, output_osd_bottom_content, 0, -1, -1, empty_image, 0, 0, g_cropped_img_buf_base64, g_cropped_length_image_base64,0); + } + + + osd_bottom_content = cJSON_CreateString(output_osd_bottom_content); + cJSON_AddItemToObject(root, "osd_bottom_content", osd_bottom_content); + + } +#endif + cJSON_alter_something = cJSON_CreateNumber(g_alter_something); + cJSON_AddItemToObject(root, "configdirty", cJSON_alter_something); + + cJSON_alter_something_udp = cJSON_CreateNumber(g_alter_something); + cJSON_AddItemToObject(root_udp, "configdirty", cJSON_alter_something_udp); + + cJSON_alter_something_8592 = cJSON_CreateNumber(g_alter_something); + cJSON_AddItemToObject(root_8592, "configdirty", cJSON_alter_something_8592); + +#ifdef GY_OS_AMBA + cJSON_pts_udp = cJSON_CreateNumber(g_last_dsp_pts); + cJSON_AddItemToObject(root_udp, "pts", cJSON_pts_udp); + cJSON_pts = cJSON_CreateNumber(g_last_dsp_pts); + cJSON_AddItemToObject(root, "pts", cJSON_pts); + cJSON_pts_8592 = cJSON_CreateNumber(g_last_dsp_pts); + cJSON_AddItemToObject(root_8592, "pts", cJSON_pts_8592); +#endif + + cJSON_AI_fps = cJSON_CreateNumber(AI_fps); + cJSON_AddItemToObject(root, "AI_fps", cJSON_AI_fps); +#ifdef GY_OS_NOVA + cJSON_AI_fps2 = cJSON_CreateNumber(AI_fps2); + cJSON_AddItemToObject(root, "AI_fps2", cJSON_AI_fps2); +#endif + + //cJSON_AI_fps_udp = cJSON_CreateNumber(AI_fps); + //cJSON_AddItemToObject(root_udp, "AI_fps", cJSON_AI_fps_udp); +//#ifdef GY_OS_NOVA + //cJSON_AI_fps2_udp = cJSON_CreateNumber(AI_fps2); + //cJSON_AddItemToObject(root, "AI_fps2", cJSON_AI_fps2_udp); +//#endif + + cJSON_AI_fps_8592 = cJSON_CreateNumber(AI_fps); + cJSON_AddItemToObject(root_8592, "AI_fps", cJSON_AI_fps_8592); +#ifdef GY_OS_NOVA + cJSON_AI_fps2_8592 = cJSON_CreateNumber(AI_fps2); + cJSON_AddItemToObject(root_8592, "AI_fps2", cJSON_AI_fps2_8592); +#endif + + cJSON_ready_to_reboot = cJSON_CreateNumber(get_g_check_if_different_width_or_height()); + cJSON_AddItemToObject(root, "v_series_ready_reboot", cJSON_ready_to_reboot); + + //cJSON_ready_to_reboot_udp = cJSON_CreateNumber(get_g_check_if_different_width_or_height()); + //cJSON_AddItemToObject(root_udp, "v_series_ready_reboot", cJSON_ready_to_reboot_udp); + + cJSON_ready_to_reboot_8592 = cJSON_CreateNumber(get_g_check_if_different_width_or_height()); + cJSON_AddItemToObject(root_8592, "v_series_ready_reboot", cJSON_ready_to_reboot_8592); + + cJSON_red_light = cJSON_CreateNumber(get_g_check_if_current_light_is_red()); + cJSON_AddItemToObject(root, "red_light", cJSON_red_light); + + //cJSON_red_light_udp = cJSON_CreateNumber(get_g_check_if_current_light_is_red()); + //cJSON_AddItemToObject(root_udp, "red_light", cJSON_red_light_udp); + + cJSON_red_light_8592 = cJSON_CreateNumber(get_g_check_if_current_light_is_red()); + cJSON_AddItemToObject(root_8592, "red_light", cJSON_red_light_8592); + + JsonString_to_osd = cJSON_PrintUnformatted(root); + JsonString_to_8592_no_image = cJSON_PrintUnformatted(root_8592); + + if (count_behavior_id_larger_zero_udp >= 1) { + if ((check_if_send_udp_jpeg == 1 && strcmp(heartbeatData.enable_obj_once_to_post,"Yes")==0) || strcmp(heartbeatData.enable_obj_once_to_post, "No") == 0) + { + if (g_current_snapshot_size_8592_base64 >= 1) { + // System local time of the date and the time strings. + char str_time[32] = { 0 }; + struct tm* timeinfo_post = localtime(&g_post_SysTimeStamp); + strftime(str_time, sizeof(str_time) - 1, "%Y-%m-%d %H:%M:%S", timeinfo_post); + + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + + } + else { + base64_snapshot_time_udp = cJSON_CreateString(str_time); + cJSON_AddItemToObject(root_udp, "snap_time", base64_snapshot_time_udp); + + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) { + base64_snapshot_size_udp = cJSON_CreateNumber(g_current_snapshot_size_8592_base64); + cJSON_AddItemToObject(root_udp, "snap_size", base64_snapshot_size_udp); + } + else { + base64_snapshot_size_udp = cJSON_CreateNumber(g_current_snapshot_size_udp_base64); + cJSON_AddItemToObject(root_udp, "snap_size", base64_snapshot_size_udp); + } + + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) { + base64_snapshot_udp = cJSON_CreateString(g_current_snapshot_addr_8592_base64); + cJSON_AddItemToObject(root_udp, "snap_image", base64_snapshot_udp); + } + else { + base64_snapshot_udp = cJSON_CreateString(g_current_snapshot_addr_udp_base64); + cJSON_AddItemToObject(root_udp, "snap_image", base64_snapshot_udp); + } + } + + if (strcmp(SystemSetting.enable_getalarmmotion_snap, "Yes") == 0) { + base64_snapshot_time_8592 = cJSON_CreateString(str_time); + cJSON_AddItemToObject(root_8592, "snap_time", base64_snapshot_time_8592); + + base64_snapshot_size_8592 = cJSON_CreateNumber(g_current_snapshot_size_8592_base64); + cJSON_AddItemToObject(root_8592, "snap_size", base64_snapshot_size_8592); + + base64_snapshot_8592 = cJSON_CreateString(g_current_snapshot_addr_8592_base64); + cJSON_AddItemToObject(root_8592, "snap_image", base64_snapshot_8592); + } + } + } + + JsonString_to_udp = cJSON_PrintUnformatted(root_udp); + JsonString_to_8592 = cJSON_PrintUnformatted(root_8592); + + } + else { + JsonString_to_8592 = cJSON_PrintUnformatted(root_8592); + } + + if (g_current_snapshot_size_base64 >= 1 && strcmp(SystemSetting.enable_getalarmmotion_snap, "Yes") == 0) { + base64_snapshot_size = cJSON_CreateNumber(g_current_snapshot_size_base64); + cJSON_AddItemToObject(root, "snap_size", base64_snapshot_size); + + base64_snapshot_response = cJSON_CreateString(g_current_image_state_response); + cJSON_AddItemToObject(root, "snap_response", base64_snapshot_response); + + base64_snapshot = cJSON_CreateString(g_current_snapshot_addr_base64); + cJSON_AddItemToObject(root, "snap_image", base64_snapshot); + } + else { + base64_snapshot_size = cJSON_CreateNumber(0); + cJSON_AddItemToObject(root, "snap_size", base64_snapshot_size); + + if (strcmp(SystemSetting.enable_getalarmmotion_snap, "Yes") == 0) { + base64_snapshot_response = cJSON_CreateString(g_current_image_state_response); + cJSON_AddItemToObject(root, "snap_response", base64_snapshot_response); + } + else { + base64_snapshot_response = cJSON_CreateString("Disable"); + cJSON_AddItemToObject(root, "snap_response", base64_snapshot_response); + } + + base64_snapshot = cJSON_CreateString(""); + cJSON_AddItemToObject(root, "snap_image", base64_snapshot); + } + + JsonString = cJSON_PrintUnformatted(root); + + detect_count_cloud = cJSON_CreateNumber(count_behavior_id_larger_zero); + cJSON_AddItemToObject(root_cloud, "Count", detect_count_cloud); + + if (count_behavior_id_larger_zero >= 1) + { + JsonString_cloud = cJSON_PrintUnformatted(root_cloud); + } + + //printf("\nEEEEEEEEEEEEE ; 2: count_behavior_id_larger_zero:%d\n", count_behavior_id_larger_zero); +#endif + ///getalarmmotion + } + else + { + ai_engine = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "AiEngine", ai_engine); + + //ai_engine_cloud = cJSON_CreateArray(); + //cJSON_AddItemToObject(root_cloud, "AiEngine", ai_engine_cloud); + + ai_engine_udp = cJSON_CreateArray(); + cJSON_AddItemToObject(root_udp, "AiEngine", ai_engine_udp); + + ai_engine_8592 = cJSON_CreateArray(); + cJSON_AddItemToObject(root_8592, "AiEngine", ai_engine_8592); + + int tracking_channel_idx = 0; + for (int i = 0; i < MAX_TRACKING_NUM; i++) + { + g_TrackingRecords[tracking_channel_idx][i].disappear_count++; + int det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; + if (det_count >= 1) { + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].disappear_count++; + } + reset_id_obj(tracking_channel_idx, i); + } + + MissingObjectDetection_VanishInZone(tracking_channel_idx); + +#ifdef GY_OS_AMBA + if (strcmp(heartbeatData.enable_heatmap, "Yes") == 0) { + gettimeofday(&currtime_heatmap, NULL); + now_heatmap = (currtime_heatmap.tv_sec * 1000) + (currtime_heatmap.tv_usec / 1000); //쬰@ + + if (abs((double)(now_heatmap - last_heatmap)) >= (double)(atoi(heartbeatData.heatmap_frequency) * 1000)) + { + //int check_the_time_is_image = 0; + //printf("\n-------AA:%d\n", count_heatmap_time * atoi(heartbeatData.heatmap_frequency)); + if (g_current_snapshot_size >= 1 && (count_heatmap_time == -1 || count_heatmap_time * atoi(heartbeatData.heatmap_frequency) >= 600)) { + //pthread_mutex_lock(&mutex_send_jpeg); + pthread_mutex_lock(&mutex_heatmap_jpeg); + char write_filename[256] = { 0 }; + sprintf(write_filename, "/emmc/plugin/Aida_data/playback/%ld.jpg", (now_heatmap / 1000) * 1000); + FILE* fp = fopen(write_filename, "w+"); + if (fp != NULL) + { + /*if (enable_zone_crop_1 == 1 && g_current_snapshot_size_crop_zone >= 1) { + fwrite(g_current_snapshot_addr_crop_zone, sizeof(char), g_current_snapshot_size_crop_zone, fp); + } + else */ + { + #ifdef GY_OS_AMBA + fwrite(g_current_snapshot_addr_HD, sizeof(char), g_current_snapshot_size_HD, fp); + #else + fwrite(g_current_snapshot_addr, sizeof(char), g_current_snapshot_size, fp); + #endif + + //check_the_time_is_image = 1; + count_heatmap_time = 0; + } + //printf("[PNS Get Snapshot From IPCam] Wrote to the file: %s.\n", write_filename); + fclose(fp); + } + else { + count_heatmap_time = -1; + printf("[start all nets] #2 (For debugging) Error occurred when opening file I/O.\n"); + } + pthread_mutex_unlock(&mutex_heatmap_jpeg); + //pthread_mutex_unlock(&mutex_send_jpeg); + } + else if (/*g_current_snapshot_size >= 1 &&*/ count_heatmap_time != -1 && count_heatmap_time * atoi(heartbeatData.heatmap_frequency) < 600) { + count_heatmap_time++; + } + + last_heatmap = now_heatmap; + //printf("\n----------now_heatmap:%ld\n", now_heatmap); + + g_image_HD_pasue_time = now_heatmap / 1000 * 1000; + + struct tm *info_heatmap; + info_heatmap = localtime(&currtime_heatmap.tv_sec); + int current_wday = info_heatmap->tm_wday == 0 ? 7 : info_heatmap->tm_wday; + + if (last_wday != -1 && current_wday != last_wday) { + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", "/emmc/plugin/Aida/heatmap_data.js"); + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", "/emmc/plugin/Aida_data/heatmap_data_bak.js"); + + char buf_file[256] = { 0 }; + sprintf(buf_file, "/emmc/plugin/Aida/heatmap_data_%d.js", current_wday); + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", buf_file); + + char buf_file_bak[256] = { 0 }; + sprintf(buf_file_bak, "/emmc/plugin/Aida_data/heatmap_data_%d_bak.js", current_wday); + CopyFileTo("/emmc/plugin/Aida/heatmap_data_install.js", buf_file_bak); + last_wday = current_wday; + } + } + } +#endif + parking_space_check_table = cJSON_CreateArray(); + parking_space_check_table_udp = cJSON_CreateArray(); + parking_space_check_table_8592 = cJSON_CreateArray(); + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + a_parking_space_check_table = cJSON_CreateArray(); + a_parking_space_check_table_udp = cJSON_CreateArray(); + a_parking_space_check_table_8592 = cJSON_CreateArray(); + for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][j].parking_space; index_plot++) + { + cJSON_AddItemToArray(a_parking_space_check_table, cJSON_CreateNumber(g_parking_space_check_table[j][index_plot])); + cJSON_AddItemToArray(a_parking_space_check_table_udp, cJSON_CreateNumber(g_parking_space_check_table[j][index_plot])); + cJSON_AddItemToArray(a_parking_space_check_table_8592, cJSON_CreateNumber(g_parking_space_check_table[j][index_plot])); + } + cJSON_AddItemToArray(parking_space_check_table, a_parking_space_check_table); + cJSON_AddItemToArray(parking_space_check_table_udp, a_parking_space_check_table_udp); + cJSON_AddItemToArray(parking_space_check_table_8592, a_parking_space_check_table_8592); + } + cJSON_AddItemToObject(root, "parking_space_check_table", parking_space_check_table); + cJSON_AddItemToObject(root_udp, "parking_space_check_table", parking_space_check_table_udp); + cJSON_AddItemToObject(root_8592, "parking_space_check_table", parking_space_check_table_8592); + +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + g_IsCustomWeight == 1 || +#ifdef GY_OS_AMBA + unlockingKeyInnoFR_success == 1 +#else + IsANPRCategory(featureType) +#endif + ) { + + counter_count = cJSON_CreateArray(); + //counter_count_cloud = cJSON_CreateArray(); + counter_count_udp = cJSON_CreateArray(); + counter_count_8592 = cJSON_CreateArray(); + + counter_zone = cJSON_CreateArray(); + //counter_zone_cloud = cJSON_CreateArray(); + counter_zone_udp = cJSON_CreateArray(); + counter_zone_8592 = cJSON_CreateArray(); + + counter_reset_value = cJSON_CreateArray(); + //counter_reset_value_cloud = cJSON_CreateArray(); + counter_reset_value_udp = cJSON_CreateArray(); + counter_reset_value_8592 = cJSON_CreateArray(); + counter_operand = cJSON_CreateArray(); + //counter_operand_cloud = cJSON_CreateArray(); + counter_operand_udp = cJSON_CreateArray(); + counter_operand_8592 = cJSON_CreateArray(); + + char temp_counter_operand[MAX_EVENT_COUNTERS][10] = { 0 }; + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + for (int k_index = 0; k_index < MAX_TRIGGER_EVENT; k_index++) { + if (viewDetectionZone[0][j].trigger_event[k_index].checked) { + int index_counter = -1; + if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter01") == 0) { + index_counter = 0; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter02") == 0) { + index_counter = 1; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter03") == 0) { + index_counter = 2; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter04") == 0) { + index_counter = 3; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter05") == 0) { + index_counter = 4; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter06") == 0) { + index_counter = 5; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter07") == 0) { + index_counter = 6; + } + else if (strcmp(viewDetectionZone[0][j].trigger_event[k_index].counter_name, "Counter08") == 0) { + index_counter = 7; + } + else { + break; + } + + if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == 1) + { + strcpy(temp_counter_operand[index_counter], "+1"); + } + else if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == -1) + { + strcpy(temp_counter_operand[index_counter], "-1"); + } + else if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == 0) + { + strcpy(temp_counter_operand[index_counter], "="); + } + else if (viewDetectionZone[0][j].trigger_event[k_index].counter_increment == -2) + { + strcpy(temp_counter_operand[index_counter], "NULL"); + } + + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + strcpy(onvif_counter[index_counter].onvif_counter_name, viewDetectionZone[0][j].trigger_event[k_index].counter_name); + onvif_counter[index_counter].onvif_detect_event_id = onvif_counter[index_counter].onvif_detect_event_id | HexStringToInt(viewDetectionZone[0][j].trigger_event[k_index].detect_event_id); + onvif_counter[index_counter].forward_line = atoi(viewDetectionZone[0][j].direction1); + strcpy(onvif_counter[index_counter].onvif_ReportTimeInterval, eventCounterList[index_counter].ReportTimeInterval); + strcpy(onvif_counter[index_counter].onvif_ResetTime, eventCounterList[index_counter].ResetTime); + strcpy(onvif_counter[index_counter].onvif_Direction, "Right"); + strcpy(onvif_counter[index_counter].onvif_PassAllPolylines, "false"); + + for (int index_point = 0; index_point < 6; index_point++) { + onvif_counter[index_counter].onvif_Points[index_point].x = viewDetectionZone[0][j].onvif_Points[index_point].x; + onvif_counter[index_counter].onvif_Points[index_point].y = viewDetectionZone[0][j].onvif_Points[index_point].y; + } + + onvif_counter[index_counter].counter_count = eventCounterList[index_counter].counter_count; + onvif_counter[index_counter].dwell_time = eventCounterList[index_counter].dwell_time; + } + + break; + } + } + } + + for (int j = 0; j < MAX_EVENT_COUNTERS; j++) + { + cJSON_AddItemToArray(counter_count, cJSON_CreateNumber(eventCounterList[j].counter_count)); + //cJSON_AddItemToArray(counter_count_cloud, cJSON_CreateNumber(eventCounterList[j].counter_count)); + cJSON_AddItemToArray(counter_count_udp, cJSON_CreateNumber(eventCounterList[j].counter_count)); + cJSON_AddItemToArray(counter_count_8592, cJSON_CreateNumber(eventCounterList[j].counter_count)); + + cJSON_AddItemToArray(counter_zone, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + //cJSON_AddItemToArray(counter_zone_cloud, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + cJSON_AddItemToArray(counter_zone_udp, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + cJSON_AddItemToArray(counter_zone_8592, cJSON_CreateNumber(eventCounterList[j].counter_zone)); + + cJSON_AddItemToArray(counter_reset_value, cJSON_CreateNumber(eventCounterList[j].reset_value)); + //cJSON_AddItemToArray(counter_reset_value_cloud, cJSON_CreateNumber(eventCounterList[j].reset_value)); + cJSON_AddItemToArray(counter_reset_value_udp, cJSON_CreateNumber(eventCounterList[j].reset_value)); + cJSON_AddItemToArray(counter_reset_value_8592, cJSON_CreateNumber(eventCounterList[j].reset_value)); + + if (strlen(temp_counter_operand[j]) == 0) { + strcpy(temp_counter_operand[j], "NULL"); + } + cJSON_AddItemToArray(counter_operand, cJSON_CreateString(temp_counter_operand[j])); + //cJSON_AddItemToArray(counter_operand_cloud, cJSON_CreateString(temp_counter_operand[j])); + cJSON_AddItemToArray(counter_operand_udp, cJSON_CreateString(temp_counter_operand[j])); + cJSON_AddItemToArray(counter_operand_8592, cJSON_CreateString(temp_counter_operand[j])); + } + + + cJSON_AddItemToObject(root, "counter_count", counter_count); + //cJSON_AddItemToObject(root_cloud, "counter_count", counter_count_cloud); + cJSON_AddItemToObject(root_udp, "counter_count", counter_count_udp); + cJSON_AddItemToObject(root_8592, "counter_count", counter_count_8592); + + cJSON_AddItemToObject(root, "counter_zone", counter_zone); + //cJSON_AddItemToObject(root_cloud, "counter_zone", counter_zone_cloud); + cJSON_AddItemToObject(root_udp, "counter_zone", counter_zone_udp); + cJSON_AddItemToObject(root_8592, "counter_zone", counter_zone_8592); + + cJSON_AddItemToObject(root, "reset_value", counter_reset_value); + //cJSON_AddItemToObject(root_cloud, "reset_value", counter_reset_value_cloud); + cJSON_AddItemToObject(root_udp, "reset_value", counter_reset_value_udp); + cJSON_AddItemToObject(root_8592, "reset_value", counter_reset_value_8592); + cJSON_AddItemToObject(root, "counter_operand", counter_operand); + //cJSON_AddItemToObject(root_cloud, "counter_operand", counter_operand_cloud); + cJSON_AddItemToObject(root_udp, "counter_operand", counter_operand_udp); + cJSON_AddItemToObject(root_8592, "counter_operand", counter_operand_8592); + + } +#endif + + for (int j = 0; j < MAX_DETECTION_ZONE; j++) + { + char c_something_vanish_in_zone[50] = { 0 }; + sprintf(c_something_vanish_in_zone, "vz%d", (j + 1)); + + if ((viewDetectionZone[tracking_channel_idx][j].check_if_missing == 1 || get_g_check_if_NAND(j) == 1) + && j < viewChannelData[tracking_channel_idx].count_zone) { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || + trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) { + //CheckEventCounterCondition(pNext, tracking_channel_idx, j, k,1); + //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; + check_if_something_vanish_in_zone_Yes[j] = 1; + } + } + } + if (check_if_something_vanish_in_zone_Yes[j] == 1) { + something_vanish_in_zone = cJSON_CreateString("Yes"); + cJSON_AddItemToObject(root, c_something_vanish_in_zone, something_vanish_in_zone); + + //something_vanish_in_zone_cloud = cJSON_CreateString("Yes"); + //cJSON_AddItemToObject(root_cloud, c_something_vanish_in_zone, something_vanish_in_zone_cloud); + + something_vanish_in_zone_udp = cJSON_CreateString("Yes"); + cJSON_AddItemToObject(root_udp, c_something_vanish_in_zone, something_vanish_in_zone_udp); + + something_vanish_in_zone_8592 = cJSON_CreateString("Yes"); + cJSON_AddItemToObject(root_8592, c_something_vanish_in_zone, something_vanish_in_zone_8592); + } + else { + something_vanish_in_zone = cJSON_CreateString("No"); + cJSON_AddItemToObject(root, c_something_vanish_in_zone, something_vanish_in_zone); + + //something_vanish_in_zone_cloud = cJSON_CreateString("No"); + //cJSON_AddItemToObject(root_cloud, c_something_vanish_in_zone, something_vanish_in_zone_cloud); + + something_vanish_in_zone_udp = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_udp, c_something_vanish_in_zone, something_vanish_in_zone_udp); + + something_vanish_in_zone_8592 = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_8592, c_something_vanish_in_zone, something_vanish_in_zone_8592); + } + + } + else { + something_vanish_in_zone = cJSON_CreateString("No"); + cJSON_AddItemToObject(root, c_something_vanish_in_zone, something_vanish_in_zone); + + //something_vanish_in_zone_cloud = cJSON_CreateString("No"); + //cJSON_AddItemToObject(root_cloud, c_something_vanish_in_zone, something_vanish_in_zone_cloud); + + something_vanish_in_zone_udp = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_udp, c_something_vanish_in_zone, something_vanish_in_zone_udp); + + something_vanish_in_zone_8592 = cJSON_CreateString("No"); + cJSON_AddItemToObject(root_8592, c_something_vanish_in_zone, something_vanish_in_zone_8592); + } + } + + time_t rawtime_temp = time(0); + struct tm * timeinfo_temp; + timeinfo_temp = localtime(&rawtime_temp); + if (timeinfo_temp->tm_sec % 60 == 0) { + cJSON_viewDetectionZone = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "detection_zone", cJSON_viewDetectionZone); + + cJSON_viewDetectionZone_udp = cJSON_CreateArray(); + cJSON_viewDetectionZone_8592 = cJSON_CreateArray(); + cJSON_AddItemToObject(root_udp, "detection_zone", cJSON_viewDetectionZone_udp); + cJSON_AddItemToObject(root_8592, "detection_zone", cJSON_viewDetectionZone_8592); + + for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) + { + cJSON_a_zone = cJSON_CreateObject(); + cJSON_AddItemToArray(cJSON_viewDetectionZone, cJSON_a_zone); + + cJSON_a_zone_udp = cJSON_CreateObject(); + cJSON_AddItemToArray(cJSON_viewDetectionZone_udp, cJSON_a_zone_udp); + + cJSON_a_zone_8592 = cJSON_CreateObject(); + cJSON_AddItemToArray(cJSON_viewDetectionZone_8592, cJSON_a_zone_8592); + + cJSON_AddItemToObject(cJSON_a_zone, "x1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone, "x6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone, "y6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + + cJSON_AddItemToObject(cJSON_a_zone_udp, "x1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "x6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_udp, "y6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + + cJSON_AddItemToObject(cJSON_a_zone_8592, "x1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y1", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[0].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y2", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[1].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y3", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[2].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y4", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[3].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y5", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[4].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "x6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].x* SCALE_BOUNDING_BOX_WIDTH / CANVAS_WIDTH)); + cJSON_AddItemToObject(cJSON_a_zone_8592, "y6", cJSON_CreateNumber(viewDetectionZone[tracking_channel_idx][index_zone].Points[5].y* SCALE_BOUNDING_BOX_HEIGHT / CANVAS_HEIGHT)); + } + } + + detect_count = cJSON_CreateNumber(0); + cJSON_AddItemToObject(root, "Count", detect_count); + + detect_count_udp = cJSON_CreateNumber(0); + cJSON_AddItemToObject(root_udp, "Count", detect_count_udp); + + detect_count_8592 = cJSON_CreateNumber(0); + cJSON_AddItemToObject(root_8592, "Count", detect_count_8592); +#ifdef GY_OS_AMBA + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + + //osd cgi object + osd_array = cJSON_CreateArray(); + cJSON_AddItemToObject(root, "osd_array", osd_array); + + //char *JsonString_array; + for (int i = 0; i < MAX_SIZE_OSD_ARRAY; i++) + { + if (OSDData[i].flag_protected == 1) { + + osd_detect = cJSON_CreateObject(); + cJSON_AddItemToArray(osd_array, osd_detect); + id = cJSON_CreateNumber(OSDData[i].id); + cJSON_AddItemToObject(osd_detect, "id", id); + x = cJSON_CreateNumber(OSDData[i].x); + cJSON_AddItemToObject(osd_detect, "x", x); + y = cJSON_CreateNumber(OSDData[i].y); + cJSON_AddItemToObject(osd_detect, "y", y); + w = cJSON_CreateNumber(OSDData[i].w); + cJSON_AddItemToObject(osd_detect, "w", w); + h = cJSON_CreateNumber(OSDData[i].h); + cJSON_AddItemToObject(osd_detect, "h", h); + osd_color = cJSON_CreateNumber(OSDData[i].color); + cJSON_AddItemToObject(osd_detect, "color", osd_color); + + osd_size = cJSON_CreateNumber(OSDData[i].size); + cJSON_AddItemToObject(osd_detect, "size", osd_size); + osd_sec = cJSON_CreateNumber(OSDData[i].show_sec); + cJSON_AddItemToObject(osd_detect, "ms", osd_sec); + osd_text = cJSON_CreateString(OSDData[i].text); + + outline_sw = cJSON_CreateNumber(OSDData[i].outline_sw); + cJSON_AddItemToObject(osd_detect, "ol_sw", outline_sw); + bg_tran = cJSON_CreateNumber(OSDData[i].bg_tran); + cJSON_AddItemToObject(osd_detect, "bg_tran", bg_tran); + + //printf("[%d]----------------------------------%d, %d \n", i, bg_tran->valueint, outline_sw->valueint); + + cJSON_AddItemToObject(osd_detect, "text", osd_text); + OSDData[i].flag_protected = 0; + } + //JsonString_array = cJSON_PrintUnformatted(osd_array); + //printf("[%d]osd_array----%s \n", i, JsonString_array); + } + osd_Time_sw = cJSON_CreateNumber(g_osdTime_sw); + cJSON_AddItemToObject(root, "osd_Time_sw", osd_Time_sw); + + osd_TimeStamp = cJSON_CreateNumber(g_osdSysTimeStamp); + cJSON_AddItemToObject(root, "osd_TimeStamp", osd_TimeStamp); + + osd_TimeZoneInfo = cJSON_CreateNumber(g_osdSysTimeZoneInfo); + cJSON_AddItemToObject(root, "osd_TimeZoneInfo", osd_TimeZoneInfo); + + + osd_encoder_id = cJSON_CreateNumber(atoi(SystemSetting.osd_encoder_id)); + cJSON_AddItemToObject(root, "osd_encoder_id", osd_encoder_id); + + osd_font_size = cJSON_CreateNumber(atoi(SystemSetting.osd_font_size)); + cJSON_AddItemToObject(root, "osd_font_size", osd_font_size); + + osd_outline_lilin = cJSON_CreateNumber(atoi(SystemSetting.osd_outline_lilin)); + cJSON_AddItemToObject(root, "osd_outline_lilin", osd_outline_lilin); + + enable_osd_bottom = cJSON_CreateString(SystemSetting.enable_osd_bottom); + cJSON_AddItemToObject(root, "enable_osd_bottom", enable_osd_bottom); + + osd_bottom_bg_tran = cJSON_CreateNumber(atoi(SystemSetting.osd_bottom_bg_tran)); + cJSON_AddItemToObject(root, "osd_bottom_bg_tran", osd_bottom_bg_tran); + + char output_osd_bottom_content[BUFSIZE_V3] = { 0 }; + char empty_image[10] = { 0 }; + + { + ReplaceKeyWords(NULL,-1,-1,SystemSetting.osd_bottom_content, output_osd_bottom_content, 0, -1, -1, empty_image, 0, 0, g_cropped_img_buf_base64, g_cropped_length_image_base64,0); + } + + + osd_bottom_content = cJSON_CreateString(output_osd_bottom_content); + cJSON_AddItemToObject(root, "osd_bottom_content", osd_bottom_content); + } +#endif + cJSON_alter_something = cJSON_CreateNumber(g_alter_something); + cJSON_AddItemToObject(root, "configdirty", cJSON_alter_something); + + cJSON_alter_something_udp = cJSON_CreateNumber(g_alter_something); + cJSON_AddItemToObject(root_udp, "configdirty", cJSON_alter_something_udp); + + cJSON_alter_something_8592 = cJSON_CreateNumber(g_alter_something); + cJSON_AddItemToObject(root_8592, "configdirty", cJSON_alter_something_8592); + +#ifdef GY_OS_AMBA + cJSON_pts_udp = cJSON_CreateNumber(g_last_dsp_pts); + cJSON_AddItemToObject(root_udp, "pts", cJSON_pts_udp); + cJSON_pts = cJSON_CreateNumber(g_last_dsp_pts); + cJSON_AddItemToObject(root, "pts", cJSON_pts); + cJSON_pts_8592 = cJSON_CreateNumber(g_last_dsp_pts); + cJSON_AddItemToObject(root_8592, "pts", cJSON_pts_8592); +#endif + + cJSON_AI_fps = cJSON_CreateNumber(AI_fps); + cJSON_AddItemToObject(root, "AI_fps", cJSON_AI_fps); +#ifdef GY_OS_NOVA + cJSON_AI_fps2 = cJSON_CreateNumber(AI_fps2); + cJSON_AddItemToObject(root, "AI_fps2", cJSON_AI_fps2); +#endif + //cJSON_AI_fps_udp = cJSON_CreateNumber(AI_fps); + //cJSON_AddItemToObject(root_udp, "AI_fps", cJSON_AI_fps_udp); +//#ifdef GY_OS_NOVA + //cJSON_AI_fps2_udp = cJSON_CreateNumber(AI_fps2); + //cJSON_AddItemToObject(root, "AI_fps2", cJSON_AI_fps2_udp); +//#endif + cJSON_AI_fps_8592 = cJSON_CreateNumber(AI_fps); + cJSON_AddItemToObject(root_8592, "AI_fps", cJSON_AI_fps_8592); +#ifdef GY_OS_NOVA + cJSON_AI_fps2_8592 = cJSON_CreateNumber(AI_fps2); + cJSON_AddItemToObject(root_8592, "AI_fps2", cJSON_AI_fps2_8592); +#endif + cJSON_ready_to_reboot = cJSON_CreateNumber(get_g_check_if_different_width_or_height()); + cJSON_AddItemToObject(root, "v_series_ready_reboot", cJSON_ready_to_reboot); + + cJSON_ready_to_reboot_udp = cJSON_CreateNumber(get_g_check_if_different_width_or_height()); + cJSON_AddItemToObject(root_udp, "v_series_ready_reboot", cJSON_ready_to_reboot_udp); + + cJSON_ready_to_reboot_8592 = cJSON_CreateNumber(get_g_check_if_different_width_or_height()); + cJSON_AddItemToObject(root_8592, "v_series_ready_reboot", cJSON_ready_to_reboot_8592); + + cJSON_red_light = cJSON_CreateNumber(get_g_check_if_current_light_is_red()); + cJSON_AddItemToObject(root, "red_light", cJSON_red_light); + + cJSON_red_light_udp = cJSON_CreateNumber(get_g_check_if_current_light_is_red()); + cJSON_AddItemToObject(root_udp, "red_light", cJSON_red_light_udp); + + cJSON_red_light_8592 = cJSON_CreateNumber(get_g_check_if_current_light_is_red()); + cJSON_AddItemToObject(root_8592, "red_light", cJSON_red_light_8592); + + JsonString_to_osd = cJSON_PrintUnformatted(root); + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + JsonString_to_udp = cJSON_PrintUnformatted(root_udp); + } + JsonString_to_8592 = cJSON_PrintUnformatted(root_8592); + JsonString_to_8592_no_image = cJSON_PrintUnformatted(root_8592); + + if (g_current_snapshot_size_base64 >= 1 && strcmp(SystemSetting.enable_getalarmmotion_snap, "Yes") == 0) { + base64_snapshot_size = cJSON_CreateNumber(g_current_snapshot_size_base64); + cJSON_AddItemToObject(root, "snap_size", base64_snapshot_size); + + base64_snapshot_response = cJSON_CreateString(g_current_image_state_response); + cJSON_AddItemToObject(root, "snap_response", base64_snapshot_response); + + base64_snapshot = cJSON_CreateString(g_current_snapshot_addr_base64); + cJSON_AddItemToObject(root, "snap_image", base64_snapshot); + } + else { + base64_snapshot_size = cJSON_CreateNumber(0); + cJSON_AddItemToObject(root, "snap_size", base64_snapshot_size); + + if (strcmp(SystemSetting.enable_getalarmmotion_snap, "Yes") == 0) { + base64_snapshot_response = cJSON_CreateString(g_current_image_state_response); + cJSON_AddItemToObject(root, "snap_response", base64_snapshot_response); + } + else { + base64_snapshot_response = cJSON_CreateString("Disable"); + cJSON_AddItemToObject(root, "snap_response", base64_snapshot_response); + } + + base64_snapshot = cJSON_CreateString(""); + cJSON_AddItemToObject(root, "snap_image", base64_snapshot); + } + + JsonString = cJSON_PrintUnformatted(root); + + //detect_count_cloud = cJSON_CreateNumber(0); + //cJSON_AddItemToObject(root_cloud, "Count", detect_count_cloud); + //JsonString_cloud = cJSON_PrintUnformatted(root_cloud); + + //printf("\nEEEEEEEEEEEEE ; 3\n"); + + + + } // is total bbox num != 0 + + minus_count_trigger(); + + //إlong termMshort termcJSON + if (strcmp(viewChannelData[0].enable_track, "Yes") == 0) + { + root_post = cJSON_CreateObject(); + root_long = cJSON_CreateObject(); + + int count_post = 0; + int count_long = 0; + + time_t now_time = time(0); + double dTime = 0.0; + + ai_engine_post = cJSON_CreateArray(); + cJSON_AddItemToObject(root_post, "ShortPostRecorder", ai_engine_post); + + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) { + if (g_PostRecorderList[i].iIfUse == 1 && strcmp(g_PostRecorderList[i].name,"object") != 0 && g_PostRecorderList[i].box_w > 0 && g_PostRecorderList[i].box_h > 0/*&& g_PostRecorderList[i].count_trigger >= 3*/) { + double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); + //if (temp_dTime >= (double)atoi(heartbeatData.dwell_to_the_same_location)) + { + detect_post = cJSON_CreateObject(); + cJSON_AddItemToArray(ai_engine_post, detect_post); + idx_post = cJSON_CreateNumber(count_post); + cJSON_AddItemToObject(detect_post, "idx", idx_post); + i_post = cJSON_CreateNumber(i); + cJSON_AddItemToObject(detect_post, "i", i_post); + zone_idx_post = cJSON_CreateNumber(g_PostRecorderList[i].zone_idx); + cJSON_AddItemToObject(detect_post, "zone_idx", zone_idx_post); + + box_x_post = cJSON_CreateNumber((int)(g_PostRecorderList[i].box_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + cJSON_AddItemToObject(detect_post, "x", box_x_post); + box_y_post = cJSON_CreateNumber((int)(g_PostRecorderList[i].box_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + cJSON_AddItemToObject(detect_post, "y", box_y_post); + box_w_post = cJSON_CreateNumber((int)(g_PostRecorderList[i].box_w * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + cJSON_AddItemToObject(detect_post, "w", box_w_post); + box_h_post = cJSON_CreateNumber((int)(g_PostRecorderList[i].box_h * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + cJSON_AddItemToObject(detect_post, "h", box_h_post); + + name_post = cJSON_CreateString(g_PostRecorderList[i].name); + cJSON_AddItemToObject(detect_post, "name", name_post); + id_post = cJSON_CreateNumber(g_PostRecorderList[i].object_id); + cJSON_AddItemToObject(detect_post, "obj_tracking_id", id_post); + dTime = difftime(now_time, g_PostRecorderList[i].t_UpdateTime); + updatetime_post = cJSON_CreateNumber(dTime); + cJSON_AddItemToObject(detect_post, "updatetime", updatetime_post); + dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime); + firstgettime_post = cJSON_CreateNumber(dTime); + cJSON_AddItemToObject(detect_post, "firstgettime", firstgettime_post); + count_trigger_post = cJSON_CreateNumber(g_PostRecorderList[i].count_trigger); + cJSON_AddItemToObject(detect_post, "count_interval", count_trigger_post); + + firstgettime_total_post = cJSON_CreateNumber(temp_dTime); + cJSON_AddItemToObject(detect_post, "totaltime", firstgettime_total_post); + + count_post++; + } + } + else { + if (g_PostRecorderList[i].iIfUse == 0) { + break; + } + } + } + + detect_count_post = cJSON_CreateNumber(count_post); + cJSON_AddItemToObject(root_post, "count_short", detect_count_post); + + JsonString_post = cJSON_PrintUnformatted(root_post); + + ai_engine_long = cJSON_CreateArray(); + cJSON_AddItemToObject(root_long, "LongPostRecorder", ai_engine_long); + + for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) { + if (g_longterm_PostRecorderList[i].iIfUse == 1 && strcmp(g_longterm_PostRecorderList[i].name, "object") != 0 && g_longterm_PostRecorderList[i].box_w > 0 && g_longterm_PostRecorderList[i].box_h > 0 /*&& g_longterm_PostRecorderList[i].count_trigger >= 2*/) { + double temp_dTime = difftime(now_time, g_longterm_PostRecorderList[i].t_FirstGetTime_total); + if (temp_dTime >= (double)atoi(heartbeatData.dwell_to_the_same_location)) { + detect_long = cJSON_CreateObject(); + cJSON_AddItemToArray(ai_engine_long, detect_long); + idx_long = cJSON_CreateNumber(count_long); + cJSON_AddItemToObject(detect_long, "idx", idx_long); + i_long = cJSON_CreateNumber(i); + cJSON_AddItemToObject(detect_long, "i", i_long); + zone_idx_long = cJSON_CreateNumber(g_longterm_PostRecorderList[i].zone_idx); + cJSON_AddItemToObject(detect_long, "zone_idx", zone_idx_long); + + box_x_long = cJSON_CreateNumber((int)(g_longterm_PostRecorderList[i].box_x * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + cJSON_AddItemToObject(detect_long, "x", box_x_long); + box_y_long = cJSON_CreateNumber((int)(g_longterm_PostRecorderList[i].box_y * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + cJSON_AddItemToObject(detect_long, "y", box_y_long); + box_w_long = cJSON_CreateNumber((int)(g_longterm_PostRecorderList[i].box_w * SCALE_BOUNDING_BOX_WIDTH / g_ori_yuv_width)); + cJSON_AddItemToObject(detect_long, "w", box_w_long); + box_h_long = cJSON_CreateNumber((int)(g_longterm_PostRecorderList[i].box_h * SCALE_BOUNDING_BOX_HEIGHT / g_ori_yuv_height)); + cJSON_AddItemToObject(detect_long, "h", box_h_long); + + name_long = cJSON_CreateString(g_longterm_PostRecorderList[i].name); + cJSON_AddItemToObject(detect_long, "name", name_long); + id_long = cJSON_CreateNumber(g_longterm_PostRecorderList[i].object_id); + cJSON_AddItemToObject(detect_long, "obj_tracking_id", id_long); + dTime = difftime(now_time, g_longterm_PostRecorderList[i].t_UpdateTime); + updatetime_long = cJSON_CreateNumber(dTime); + cJSON_AddItemToObject(detect_long, "updatetime", updatetime_long); + dTime = difftime(now_time, g_longterm_PostRecorderList[i].t_FirstGetTime); + firstgettime_long = cJSON_CreateNumber(dTime); + cJSON_AddItemToObject(detect_long, "firstgettime", firstgettime_long); + count_trigger_long = cJSON_CreateNumber(g_longterm_PostRecorderList[i].count_trigger); + cJSON_AddItemToObject(detect_long, "count_interval", count_trigger_long); + + firstgettime_total_long = cJSON_CreateNumber(temp_dTime); + cJSON_AddItemToObject(detect_long, "totaltime", firstgettime_total_long); + + count_long++; + } + } + else { + if (g_longterm_PostRecorderList[i].iIfUse == 0) { + break; + } + } + } + + detect_count_long = cJSON_CreateNumber(count_long); + cJSON_AddItemToObject(root_long, "count_long", detect_count_long); + + JsonString_long = cJSON_PrintUnformatted(root_long); + } + + if (frame_id >= 4294967295) { + frame_id = 0; + } + else { + frame_id++; + } + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #7:%lf ms\n", dw_FPS_time_delta); + + /*end = clock(); + dur = (double)(end - start); + printf("\n[7]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + //printf("\n[start all nets] while 19\n"); + check_if_enable_trigger_go_straight_temp = 0; + + // TODO : g_IsToFDevice == 1 || + if (unlockingKeyInnoFR == 1 || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || td_weight_num >= 1 || check_if_fe_fail == 1 || (stAMBAcontent->licenseType != _NO_LICENSE && stAMBAcontent->afsCode == _LICENSED )) //v\, vѽXwv + { + //printf("\n[start all nets] while 20\n"); + + //if feather is legal + //printf("\nFEATURE_HUM_DET---15\n"); + // TODO : g_IsToFDevice == 1 || + if ( + unlockingKeyInnoFR == 1 + || g_IsRadarDevice == 1 + || g_IsToFDevice == 1 + || (stAMBAcontent->featureType & FEATURE_TRAF_DET) + || IsANPRCategory(stAMBAcontent->featureType) + || g_IsCustomWeight == 1 + || (stAMBAcontent->featureType & FEATURE_AIFIRE) + || (stAMBAcontent->featureType & FEATURE_AIRAIL) + || (stAMBAcontent->featureType & FEATURE_LPR_LOGO) + || (stAMBAcontent->featureType & FEATURE_HUM_DET)) + { + { + + /*if (check_if_hasgetalarm == 1 && hasGetAlarmMotion) + { + while (live_mode_flag && (pctrl != NULL || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || unlockingKeyInnoFR == 1)) + { + if (QueueIsEmpty(_GETALARMMOTION) && QueueIsEmpty(_POST_NOTIFICATION)) { + break; + } + else { + usSleep(500); + } + } + }*/ + + hasGetAlarmMotion = FALSE; + check_if_hasgetalarm = 0; + + //getalarmmotion + for (int i = 0; i < MAX_CLIENT_SOCKET; i++) + { + if (socketRecords[i].used == 1 && socketRecords[i].sock != -1) { + if (socketRecords[i].isGetAlarmMotion) + { + hasGetAlarmMotion = TRUE; + break; + } + } + } + + //printf("\nFEATURE_HUM_DET---16\n"); + + if (hasGetAlarmMotion) + { + if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) + { + QueueInfo q_info = { 0 }; + + //ץg_IsRadarDeviceMg_IsToFDevice䴩contentMcontent_no_base64_imageA]websocketgetalarmmotionnno_base64_imageC + //Ӥ@getalarmmotionAhOϥcontentC +#if 0 + char temp_global_radar_response[BUFSIZE_V3] = { 0 }; + char temp_g_tof_data_json[BUFSIZE_V3] = { 0 }; + + if (g_IsRadarDevice == 1) { + if (g_switch_radar_data_json_p == 1) { + + if (g_IsRadarFake == 1) + { + strcpy(temp_global_radar_response, g_radar_data_json); + } + else + { + strcpy(temp_global_radar_response, global_radar_response); + } + + g_switch_radar_data_json_p = 0; + } + } + + if (g_IsToFDevice == 1) { + build_tof_data_json(); // copy json string to g_tof_data_json + strcpy(temp_g_tof_data_json, g_tof_data_json); + } +#endif + + //if (strcmp(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes") == 0 && strcmp(SystemSetting.enable_cloud, "Yes") == 0) + if(strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) + { + if (JsonString_to_8592 != NULL) { + //printf("\n--------%d\n",strlen(JsonString_to_8592)); + strcpy(q_info.content, JsonString_to_8592); + } + } + else { + if (JsonString != NULL) { + //printf("\n--------%d\n", strlen(JsonString)); + strcpy(q_info.content, JsonString); + } + } + + if (JsonString != NULL) { + //strcpy(q_info.content, "{\"AiEngine\":[{\"id\":0,\"channel_id\":1,\"camera_name\":\"Z6R8982X3\",\"res_height\":1080,\"res_width\":1920,\"confidence\":57,\"confidence2\":0,\"class_score\":100,\"object_score\":15,\"progress_bar\":0,\"engine_type\":1,\"label_name\":\"person\",\"class_id\":0,\"obj_type\":0,\"obj_tracking_id\":441,\"obj_dwell_time\":21,\"color_id\":0,\"color\":\"\",\"sec_color_id\":0,\"sec_color\":\"\",\"car_type_name\":\"\",\"logo\":\"\",\"linked_plate\":\"\",\"x\":1231,\"y\":244,\"w\":133,\"h\":226,\"center_direction\":\"\",\"center_speed\":\"\",\"parent_idx\":-1,\"detection_zone_id\":1,\"detection_zone_id2\":0,\"detection_zone_id3\":0,\"detection_zone_id4\":0,\"behavior_id\":1},{\"id\":1,\"channel_id\":1,\"camera_name\":\"Z6R8982X3\",\"res_height\":1080,\"res_width\":1920,\"confidence\":50,\"confidence2\":0,\"class_score\":82,\"object_score\":19,\"progress_bar\":0,\"engine_type\":1,\"label_name\":\"car\",\"class_id\":2,\"obj_type\":0,\"obj_tracking_id\":443,\"obj_dwell_time\":19,\"color_id\":0,\"color\":\"\",\"sec_color_id\":0,\"sec_color\":\"\",\"car_type_name\":\"\",\"logo\":\"\",\"linked_plate\":\"\",\"x\":370,\"y\":22,\"w\":607,\"h\":222,\"center_direction\":\"\",\"center_speed\":\"\",\"parent_idx\":-1,\"detection_zone_id\":1,\"detection_zone_id2\":0,\"detection_zone_id3\":0,\"detection_zone_id4\":0,\"behavior_id\":1}],\"parking_space_check_table\":[[],[],[],[]],\"counter_count\":[462,0,0,0,0,0,0,0],\"counter_reset_value\":[0,0,0,0,0,0,0,0],\"counter_operand\":[\" + 1\",\"NULL\",\"NULL\",\"NULL\",\"NULL\",\"NULL\",\"NULL\",\"NULL\"],\"counters\":[],\"something_vanish_in_zone1\":\"No\",\"something_vanish_in_zone2\":\"No\",\"something_vanish_in_zone3\":\"No\",\"something_vanish_in_zone4\":\"No\",\"Count\":2,\"configdirty\":0,\"AI_fps\":10,\"red_light\":0,\"snap_size\":0,\"snap_response\":\"Disable\",\"snap_image\":\"\"}"); +#if 0 + if (strlen(temp_global_radar_response) >= 1) { + strcat(q_info.content, temp_global_radar_response); + char *temp_content = StrReplace(q_info.content, "}{", ","); + strcpy(q_info.content, temp_content); + if (temp_content != NULL) { + free(temp_content); + temp_content = NULL; + } + } + + // 2023-01-17 Ken add ToF info + if (strlen(temp_g_tof_data_json) >= 1) { + strcat(q_info.content, temp_g_tof_data_json); + char *temp_content = StrReplace(q_info.content, "}{", ","); + strcpy(q_info.content, temp_content); + if (temp_content != NULL) { + free(temp_content); + temp_content = NULL; + } + } +#endif + //printf("\n----------q_info.content:%s\n", q_info.content); + //strcat(JsonString_to_ipcam, JsonString); + //strcpy(q_info.content_to_ipcam, JsonString_to_ipcam); + /* + printf("\n------------------\n"); + printf("\nq_info.content_to_ipcam:%s\n", q_info.content_to_ipcam); + printf("\n------------------\n");*/ + } + + if (JsonString_cloud != NULL) { + strcpy(q_info.cloud_aiengine, JsonString_cloud); + //strcpy(q_info.cloud_v2_aiengine, JsonString_cloud); + //strcpy(q_info.record_cloud_v2_aiengine, JsonString_cloud); + } + + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) { + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) + { + if (JsonString_to_8592 != NULL) { + //printf("\n--------%d\n",strlen(JsonString_to_8592)); + strcpy(q_info.udp_aiengine, JsonString_to_8592); + } + } + else { + if (JsonString != NULL) { + //printf("\n--------%d\n", strlen(JsonString)); + strcpy(q_info.udp_aiengine, JsonString); + } + } + } + else { + strcpy(q_info.udp_aiengine, JsonString_to_ipcam); + memset(JsonString_to_ipcam, 0, sizeof(JsonString_to_ipcam)); + if (JsonString_to_udp != NULL) { + strcat(q_info.udp_aiengine, JsonString_to_udp); + } + } + } + else { + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) + { + if (JsonString_to_8592 != NULL) { + //printf("\n--------%d\n",strlen(JsonString_to_8592)); + strcpy(q_info.udp_aiengine, JsonString_to_8592); + } + } + else { + if (JsonString != NULL) { + //printf("\n--------%d\n", strlen(JsonString)); + strcpy(q_info.udp_aiengine, JsonString); + } + } + } + else { + strcpy(q_info.udp_aiengine, JsonString_to_ipcam); + memset(JsonString_to_ipcam, 0, sizeof(JsonString_to_ipcam)); + if (JsonString_to_udp != NULL) { + strcat(q_info.udp_aiengine, JsonString_to_udp); + } + } + } + + //getalarmmotion ONVIF format + if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) + { + for (int io = 0; io < onvif_obj_number; io++) + { + q_info.onvif_object[io].center_x = onvif_object[io].center_x; + q_info.onvif_object[io].center_y = onvif_object[io].center_y; + q_info.onvif_object[io].left_x = onvif_object[io].left_x; + q_info.onvif_object[io].top_y = onvif_object[io].top_y; + q_info.onvif_object[io].right_x = onvif_object[io].right_x; + q_info.onvif_object[io].bottom_y = onvif_object[io].bottom_y; + q_info.onvif_object[io].Likelihood = onvif_object[io].Likelihood; + q_info.onvif_object[io].iObjectID = onvif_object[io].iObjectID; + q_info.onvif_object[io].behavior_id = onvif_object[io].behavior_id; + + sprintf(q_info.onvif_object[io].TypeName, "%s", onvif_object[io].TypeName); + + sprintf(q_info.onvif_object[io].sPlateNumber, "%s", onvif_object[io].sPlateNumber); + sprintf(q_info.onvif_object[io].sCountryCode, "%s", onvif_object[io].sCountryCode); + sprintf(q_info.onvif_object[io].sIssuingEntity, "%s", onvif_object[io].sIssuingEntity); + sprintf(q_info.onvif_object[io].sPlateType, "%s", onvif_object[io].sPlateType); + } + + q_info.onvif_object_num = onvif_obj_number; +#ifdef GY_OS_V_SERIES + +#else + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { + sprintf(q_info.onvif_counter[index_counter].onvif_counter_name, "%s", onvif_counter[index_counter].onvif_counter_name); + q_info.onvif_counter[index_counter].onvif_detect_event_id = onvif_counter[index_counter].onvif_detect_event_id; + q_info.onvif_counter[index_counter].forward_line = onvif_counter[index_counter].forward_line; + sprintf(q_info.onvif_counter[index_counter].onvif_ReportTimeInterval, "%s", onvif_counter[index_counter].onvif_ReportTimeInterval); + sprintf(q_info.onvif_counter[index_counter].onvif_ResetTime, "%s", onvif_counter[index_counter].onvif_ResetTime); + sprintf(q_info.onvif_counter[index_counter].onvif_Direction, "%s", onvif_counter[index_counter].onvif_Direction); + sprintf(q_info.onvif_counter[index_counter].onvif_PassAllPolylines, "%s", onvif_counter[index_counter].onvif_PassAllPolylines); + + for (int index_point = 0; index_point < 6; index_point++) { + q_info.onvif_counter[index_counter].onvif_Points[index_point].x = onvif_counter[index_counter].onvif_Points[index_point].x; + q_info.onvif_counter[index_counter].onvif_Points[index_point].y = onvif_counter[index_counter].onvif_Points[index_point].y; + } + + q_info.onvif_counter[index_counter].counter_count = onvif_counter[index_counter].counter_count; + q_info.onvif_counter[index_counter].dwell_time = onvif_counter[index_counter].dwell_time; + } +#endif + + //strcpy(q_info.rtsp_meta_aiengine, ""); + //if (JsonString_to_udp != NULL) { + // strcat(q_info.rtsp_meta_aiengine, ""); + //} + } + else { + q_info.onvif_object_num = 0; + } + + /* + else { + strcpy(q_info.udp_aiengine, JsonString_to_ipcam); + if (JsonString_to_osd != NULL) { + strcat(q_info.udp_aiengine, JsonString_to_osd); + } + }*/ + //printf("\n-------:%s\n", q_info.udp_aiengine); + + if (JsonString_to_osd != NULL) { + + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) + { + if (JsonString_to_8592_no_image != NULL) { + //printf("\n--------%d\n",strlen(JsonString_to_8592_no_image)); + strcpy(q_info.content_no_base64_image, JsonString_to_8592_no_image); + //printf("\n-----%s\n", q_info.content_no_base64_image); + } + + } + else { + //printf("\n--------%d\n", strlen(JsonString)); + strcpy(q_info.content_no_base64_image, JsonString_to_osd); + } + + if (strcmp(viewChannelData[0].enable_track, "Yes") == 0) { + if (JsonString_post != NULL && JsonString_long != NULL) { + //strcat(q_info.content_no_base64_image, temp_global_radar_response); + q_info.content_no_base64_image[strlen(q_info.content_no_base64_image) - 1] = '\0'; + + strcat(q_info.content_no_base64_image, ",\"short\":"); + strcat(q_info.content_no_base64_image, JsonString_post); + strcat(q_info.content_no_base64_image, ",\"long\":"); + strcat(q_info.content_no_base64_image, JsonString_long); + strcat(q_info.content_no_base64_image, "}"); + + //printf("\n-----%s\n", q_info.content_no_base64_image); + if (strcmp(heartbeatData.events_default_version, "4") == 0) { + if (strlen(q_info.udp_aiengine) >= 1) { + q_info.udp_aiengine[strlen(q_info.udp_aiengine) - 1] = '\0'; + + strcat(q_info.udp_aiengine, ",\"short\":"); + strcat(q_info.udp_aiengine, JsonString_post); + strcat(q_info.udp_aiengine, ",\"long\":"); + strcat(q_info.udp_aiengine, JsonString_long); + strcat(q_info.udp_aiengine, "}"); + } + } + } + } + + //strcpy(q_info.content_no_base64_image, "{\"AiEngine\":[{\"id\":0,\"channel_id\":1,\"camera_name\":\"Z6R8982X3\",\"res_height\":1080,\"res_width\":1920,\"confidence\":57,\"confidence2\":0,\"class_score\":100,\"object_score\":15,\"progress_bar\":0,\"engine_type\":1,\"label_name\":\"person\",\"class_id\":0,\"obj_type\":0,\"obj_tracking_id\":441,\"obj_dwell_time\":21,\"color_id\":0,\"color\":\"\",\"sec_color_id\":0,\"sec_color\":\"\",\"car_type_name\":\"\",\"logo\":\"\",\"linked_plate\":\"\",\"x\":1231,\"y\":244,\"w\":133,\"h\":226,\"center_direction\":\"\",\"center_speed\":\"\",\"parent_idx\":-1,\"detection_zone_id\":1,\"detection_zone_id2\":0,\"detection_zone_id3\":0,\"detection_zone_id4\":0,\"behavior_id\":1},{\"id\":1,\"channel_id\":1,\"camera_name\":\"Z6R8982X3\",\"res_height\":1080,\"res_width\":1920,\"confidence\":50,\"confidence2\":0,\"class_score\":82,\"object_score\":19,\"progress_bar\":0,\"engine_type\":1,\"label_name\":\"car\",\"class_id\":2,\"obj_type\":0,\"obj_tracking_id\":443,\"obj_dwell_time\":19,\"color_id\":0,\"color\":\"\",\"sec_color_id\":0,\"sec_color\":\"\",\"car_type_name\":\"\",\"logo\":\"\",\"linked_plate\":\"\",\"x\":370,\"y\":22,\"w\":607,\"h\":222,\"center_direction\":\"\",\"center_speed\":\"\",\"parent_idx\":-1,\"detection_zone_id\":1,\"detection_zone_id2\":0,\"detection_zone_id3\":0,\"detection_zone_id4\":0,\"behavior_id\":1}],\"parking_space_check_table\":[[],[],[],[]],\"counter_count\":[462,0,0,0,0,0,0,0],\"counter_reset_value\":[0,0,0,0,0,0,0,0],\"counter_operand\":[\" + 1\",\"NULL\",\"NULL\",\"NULL\",\"NULL\",\"NULL\",\"NULL\",\"NULL\"],\"counters\":[],\"something_vanish_in_zone1\":\"No\",\"something_vanish_in_zone2\":\"No\",\"something_vanish_in_zone3\":\"No\",\"something_vanish_in_zone4\":\"No\",\"Count\":2,\"configdirty\":0,\"AI_fps\":10,\"red_light\":0,\"snap_size\":0,\"snap_response\":\"Disable\",\"snap_image\":\"\"}"); +#ifdef GY_OS_AMBA + if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { + pthread_mutex_lock(&mutex_run_osd); + send_udp_data(JsonString_to_osd); + pthread_mutex_unlock(&mutex_run_osd); + } +#if 0 + if (strlen(temp_global_radar_response) >= 1) { + strcat(q_info.content_no_base64_image, temp_global_radar_response); + char *temp_content = StrReplace(q_info.content_no_base64_image, "}{", ","); + strcpy(q_info.content_no_base64_image, temp_content); + if (temp_content != NULL) { + free(temp_content); + temp_content = NULL; + } + } + + // 2023-01-17 Ken add ToF info + if (strlen(temp_g_tof_data_json) >= 1) { + strcat(q_info.content_no_base64_image, temp_g_tof_data_json); + char *temp_content = StrReplace(q_info.content_no_base64_image, "}{", ","); + strcpy(q_info.content_no_base64_image, temp_content); + if (temp_content != NULL) { + free(temp_content); + temp_content = NULL; + } + } +#endif +#endif + } + + if (AI_fps >= 1) { + check_if_hasgetalarm = 1; + if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) + { + pthread_mutex_lock(&mutex_getalarmmotion); + if(bHttpServerThreadStart) + QueuePush(q_info, _GETALARMMOTION); + pthread_mutex_unlock(&mutex_getalarmmotion); + } + } + } + else { + printf("\n----------QueueSize(_GETALARMMOTION):%d\n", QueueSize(_GETALARMMOTION)); + } + } + } + +#if 1 + if (AI_fps >= 1){ + //pƾsA@ + int ZoneQueuingCount[MAX_DETECTION_ZONE] = { 0 }; + for (int i = 0; i < MAX_DETECTION_ZONE; i++) + ZoneQueuingCount[i] = 0; + + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) + { + for (int j = 0; j < total_element_size; j++) + { + pNext = PosInfo + j; + if (pNext->zone_violation_idx[i] == 1) + { + ZoneQueuingCount[i]++; + } + } + } + + for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) { + int check_if_enable_linked_to_dwell_time = 0; +#ifdef GY_OS_V_SERIES + +#else +#if 1 + if (viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx >= 0) { + int k = viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx; + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1) + { + char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; + char Temp[MAX_MSG_LEN * 10] = { 0 }; + strcpy(Temp, viewDetectionZone[tracking_channel_idx][i].trigger_event[k].counter_name); + int event_counter_num = StrSplit(Temp, eachEventCounter, ","); + + for (int w = 0; w < event_counter_num; w++) + { + for (int m = 0; m < MAX_EVENT_COUNTERS; m++) + { + if (strlen(eachEventCounter[w]) >= 1 && strcmp(eachEventCounter[w], eventCounterList[m].counter_name) == 0) + { + if (strcmp(eventCounterList[m].enable_linked_to_dwell_time, "Yes") == 0) { + check_if_enable_linked_to_dwell_time = 1; + break; + } + } + } + if (check_if_enable_linked_to_dwell_time == 1) + break; + } + } + } +#endif +#endif + + if (viewDetectionZone[tracking_channel_idx][i].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][i].parking_line >= 1) { + if (viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx >= 0) { + int k = viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx; + if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1) { + int count_plot = 0; + for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][i].parking_space; index_plot++) + { + if (g_parking_space_check_table[i][index_plot] == 1) { + count_plot++; + } + } + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = count_plot; + } + } + } + else { + if(check_if_enable_linked_to_dwell_time == 0) + viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; + } + } + + + //CheckPostEventCondition + //if (QueueSize(_POST_NOTIFICATION) == 0) + { + int check_if_do_once[MAX_DETECTION_ZONE] = { 0 }; + + if (total_element_size == 0) { + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment != 1 && + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment != -1 && + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment != -2) { + //viewDetectionZone[tracking_channel_idx][j].prev_queuing_num = 0; + CheckEventCounterCondition(NULL, tracking_channel_idx, j, k, 0, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + + break; + } + } + } + } + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + + if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION) { + if (check_if_something_vanish_in_zone_Yes[j] == 1 && g_last_check_if_something_vanish_in_zone_Yes[j]==0) { + //printf("\n-------------Post TRIGGER_MISSING_OBJECT_DETECTION: OK------------\n"); + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == 1 || + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == -1) + CheckEventCounterCondition(NULL, tracking_channel_idx, j, k,1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + if (JsonString_cloud != NULL) + CheckPostEventCondition(NULL, tracking_channel_idx, j, k, 0, JsonString_cloud, -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckPostEventCondition(NULL, tracking_channel_idx, j, k, 0, "", -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + g_last_check_if_something_vanish_in_zone_Yes[j] = check_if_something_vanish_in_zone_Yes[j]; + } + + if (trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[j]) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + + + + } + else { + if (get_g_check_if_NAND(j) == 1) { + + //printf("\n--------count_fps_for_NAND:%d\n", count_fps_for_NAND[j]); + + //printf("\n-------------Post TRIGGER_LACK_OF_ANY_OBJECT: OK------------\n"); + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == 1 || + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == -1) + CheckEventCounterCondition(NULL, tracking_channel_idx, j, k, 0, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + if (JsonString_cloud != NULL) + CheckPostEventCondition(NULL, tracking_channel_idx, j, k, 0, JsonString_cloud, -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckPostEventCondition(NULL, tracking_channel_idx, j, k, 0, "", -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + + count_fps_for_NAND[j] = 0; + reset_g_Meta_If_Existing_for_NAND(j); + } + } + } + + if (trigger_event_type == TRIGGER_ALL_OBJECTS) { + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[j]) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) { + //printf("\nAAAAAAAAAAAA 1\n"); + + + } + else { + if (get_g_check_if_all_existing(j) == 1) { + //printf("\n-------------Post TRIGGER_ALL_OBJECTS: OK------------\n"); + if (g_last_check_if_all_existing[j] == 0) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == 1 || + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == -1) + CheckEventCounterCondition(NULL, tracking_channel_idx, j, k, 1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + + } + + { + if (JsonString_cloud != NULL) + CheckPostEventCondition(NULL, tracking_channel_idx, j, k, 0, JsonString_cloud, -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckPostEventCondition(NULL, tracking_channel_idx, j, k, 0, "", -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + } + g_last_check_if_all_existing[j] = get_g_check_if_all_existing(j); + } + } + + break; + } + } + } + + for (int i = 0; i < total_element_size; i++) + { + pNext = PosInfo + i; + + if (pNext->obj_tracking_id_idx < 0) { + printf("\n[start all nets]pNext->obj_tracking_id_idx could not be -1:%s\n",pNext->name); + continue; + } + + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) { + if ((int)(pNext->center_stability) == DIRECTION_DEFAULT && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext))) { + //printf("\n[start all nets]center_stability == DIRECTION_DEFAULT && IsVehicleCategory:%s\n", pNext->name); + continue; + } + } + + for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) + { + for (int k = 0; k < MAX_TRIGGER_EVENT; k++) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { + unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); + //᭱w䴩TRIGGER_SPEED_LOWMTRIGGER_SPEED_HIGH + + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment != 1 && + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment != -1 && + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment != -2) + CheckEventCounterCondition(pNext, tracking_channel_idx, j, k,0, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + + char ObjectName[30] = { 0 }; + sprintf(ObjectName, "%s", pNext->name); + UpperToLower(ObjectName); + + if ((strcmp(ObjectName, "object") == 0 && pNext->number_row == 2 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0)) {} + else if (strlen(viewDetectionZone[tracking_channel_idx][j].metadata1) > 0 || (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) || + (strcmp(ObjectName, "object") == 0 && strcmp(viewChannelData[0].enable_show_unknown_object, "Yes") == 0) || + (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(viewChannelData[0].enable_show_unknown_object, "No") == 0) + || strcmp(ObjectName, "tampering") == 0 || strcmp(ObjectName, "tof_point") == 0 || strcmp(ObjectName, "face") == 0) + { + + int check_if_metadata_OK = 0; + + for (int index_meta = 0; index_meta < g_metadata1_num_for_zone[j]; index_meta++) { + if (strcmp(ObjectName, g_MetaOut1[j][index_meta]) == 0 || + (strstr(g_MetaOut1[j][index_meta], "plate") != NULL && strstr(ObjectName, "plate") != NULL)) { + check_if_metadata_OK = 1; + break; + } + } + + if (strcmp(ObjectName, "object") == 0 || strcmp(ObjectName, "tampering") == 0 || strcmp(ObjectName, "tof_point") == 0 || strcmp(ObjectName, "face") == 0) { + check_if_metadata_OK = 1; + } + + if (IsANPRCategory(pNext->engine_type) || (IsANPRCategory_L_Plate(pNext->name) == 1 && strcmp(ObjectName, "face") == 0 && pNext->obj_type == _PLATE)) { + + int index_plate = -1; + for (int m = 0; m < MAX_PLATE_RECORDER; m++) + { + + if (g_PlateRecorderList[m].iIfUse == 1) { + + //printf("\n--------%s,%s,%s\n", g_PlateRecorderList[m].sPlateNumber, pNext->properties.plate, pNext->name); + + if (LevenshteinDistance(g_PlateRecorderList[m].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { /*strcmp(g_PlateRecorderList[m].sPlateNumber, pNext->properties.plate) == 0*/ + index_plate = m; + break; + } + else if (LevenshteinDistance(g_PlateRecorderList[m].sPlateNumber, pNext->name, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { /*strcmp(g_PlateRecorderList[m].sPlateNumber, pNext->name) == 0*/ + index_plate = m; + break; + } + } + } + +#if 0 + if (((IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && + pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && + pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || strcmp(pNext->name, "ambulance") == 0 + || strcmp(pNext->name, "blank") == 0 || strcmp(pNext->name, "stop_sign") == 0 || strcmp(pNext->name, "face") == 0) && + strcmp(heartbeatData.enable_only_once_to_post, "Yes") == 0) + { + if (index_plate >= 1 && g_PlateRecorderList[index_plate].iGetCounter >= 2) { + break; + } + } +#endif + + if (((IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && + (pNext->properties.plate_length < atoi(viewChannelData[0].min_characters) || + pNext->properties.plate_length > atoi(viewChannelData[0].max_characters))) && strcmp(pNext->name, "ambulance") != 0 + && strcmp(pNext->name, "blank") != 0 && strcmp(pNext->name, "stop_sign") != 0 && strcmp(pNext->name, "face") != 0)) { + break; + } + + if (index_plate == -1) { + printf("\nerror---------index_plate:%d\n", index_plate); + break; + } + + + /* + if (g_PlateRecorderList[index_plate].iGetCounter <= 1) { + break; + }*/ + + //if (pNext->zone_violation_idx[j] == 0) + { + //pNext->check_if_having_been_counted[j] = 0; + //g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] = 0; + } + + unsigned int trigger_event_type_dest = 0; + for (int index_trigger = 0; index_trigger < 11; index_trigger++) { + + if (index_trigger == 0) + trigger_event_type_dest = TRIGGER_GO_STRAIGHT; + else if (index_trigger == 1) + trigger_event_type_dest = TRIGGER_GO_STRAIGHT_RED_LIGHT; + else if (index_trigger == 2) + trigger_event_type_dest = TRIGGER_TURN_LEFT_RED_LIGHT; + else if (index_trigger == 3) + trigger_event_type_dest = TRIGGER_TURN_RIGHT_RED_LIGHT; + else if (index_trigger == 4) + trigger_event_type_dest = TRIGGER_ALLOW_LIST; + else if (index_trigger == 5) + trigger_event_type_dest = TRIGGER_BLOCK_LIST; + else if (index_trigger == 6) + trigger_event_type_dest = TRIGGER_GUEST_LIST; + else if (index_trigger == 7) + trigger_event_type_dest = TRIGGER_ZONE_VIOLATION; + else if (index_trigger == 8) + trigger_event_type_dest = TRIGGER_PARKING_VIOLATION; + else if (index_trigger == 9) + trigger_event_type_dest = TRIGGER_SPEED_HIGH; + else if (index_trigger == 10) + trigger_event_type_dest = TRIGGER_SPEED_LOW; + + if (pNext->zone_violation_idx[j] == 1) { + if (trigger_event_type == trigger_event_type_dest) { + + if (trigger_event_type_dest == TRIGGER_GO_STRAIGHT || + trigger_event_type_dest == TRIGGER_GO_STRAIGHT_RED_LIGHT || + trigger_event_type_dest == TRIGGER_TURN_LEFT_RED_LIGHT || + trigger_event_type_dest == TRIGGER_TURN_RIGHT_RED_LIGHT) { + check_if_enable_trigger_go_straight_temp = 1; + } + + if ((pNext->trigger_type & trigger_event_type_dest) == trigger_event_type_dest) { + + //printf("\nKKKKKKKKKKK 1: %d,%d,%d\n", g_PlateRecorderList[index_plate].check_if_counted[j], pNext->check_if_having_been_counted[j], g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j]); + + if (g_PlateRecorderList[index_plate].check_if_counted[j] == 0 && + pNext->check_if_having_been_counted[j] != 1 && + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] != 1) + { + + //printf("\nKKKKKKKKKKK 2\n"); + + //printf("\n-----BBTTTTTTTTTT:%d\n", pNext->obj_tracking_id_idx); + //printf("\n-----CCTTTTTTTTTT:%d\n", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j]); + + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == 1 || + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == -1) + { + if (enable_zone_crop_1 == 1) + CheckEventCounterCondition(pNext, tracking_channel_idx, j, k, 1, g_current_snapshot_addr_crop_zone, g_current_snapshot_size_crop_zone, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckEventCounterCondition(pNext, tracking_channel_idx, j, k, 1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + + pNext->check_if_having_been_counted[j] = 1; + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] = 1; + + g_PlateRecorderList[index_plate].check_if_counted[j] = 1; + + { + if (JsonString_cloud != NULL) { + if (enable_zone_crop_1 == 1) + CheckPostEventCondition(pNext, tracking_channel_idx, j, k, 0, JsonString_cloud, -1, g_current_snapshot_addr_crop_zone, g_current_snapshot_size_crop_zone, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckPostEventCondition(pNext, tracking_channel_idx, j, k, 0, JsonString_cloud, -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + else { + if (enable_zone_crop_1 == 1) + CheckPostEventCondition(pNext, tracking_channel_idx, j, k, 0, "", -1, g_current_snapshot_addr_crop_zone, g_current_snapshot_size_crop_zone, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckPostEventCondition(pNext, tracking_channel_idx, j, k, 0, "", -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + } + } + } + else { + //pNext->check_if_having_been_counted[j] = 0; + //g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] = 0; + } + } + } + } + } + else if ((check_if_metadata_OK == 1 /*&& strcmp(ObjectName,"barcode") != 0 && strcmp(ObjectName, "qrcode") != 0*/) || + strstr("Traffic light color", pNext->name) || + strstr("counter count", pNext->name) + ) + { + int index_object = -1; + for (int m = 0; m < MAX_OBJECT_RECORDER; m++) + { + if (g_ObjectRecorderList[m].iIfUse == 1) { + if (g_ObjectRecorderList[m].iTrackingID == pNext->obj_tracking_id) { + index_object = m; + break; + } + } + } + + if (index_object == -1) { + printf("\nerror---------index_object:%d\n", index_object); + break; + } + + /*if (pNext->zone_violation_idx[j] == 0) { + pNext->check_if_having_been_counted[j] = 0; + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] = 0; + }*/ + + unsigned int trigger_event_type_dest = 0; + for (int index_trigger = 0; index_trigger < 16; index_trigger++) { + + if (index_trigger == 0) + trigger_event_type_dest = TRIGGER_LACK_OF_ANY_OBJECT; + else if (index_trigger == 1) + trigger_event_type_dest = TRIGGER_ALL_OBJECTS; + else if (index_trigger == 2) + trigger_event_type_dest = TRIGGER_ZONE_VIOLATION; + else if (index_trigger == 3) + trigger_event_type_dest = TRIGGER_DISTANCE_VIOLATION; + else if (index_trigger == 4) + trigger_event_type_dest = TRIGGER_HIGH_VIOLATION; + else if (index_trigger == 5) + trigger_event_type_dest = TRIGGER_FORGET_TO_GIVE_WAY; + else if (index_trigger == 6) + trigger_event_type_dest = TRIGGER_SPEED_HIGH; + else if (index_trigger == 7) + trigger_event_type_dest = TRIGGER_SPEED_LOW; + else if (index_trigger == 8) + trigger_event_type_dest = TRIGGER_TAMPERING; + else if (index_trigger == 9) + trigger_event_type_dest = TRIGGER_PARKING_VIOLATION; + else if (index_trigger == 10) + trigger_event_type_dest = TRIGGER_MISSING_UNATTENDED; + else if (index_trigger == 11) + trigger_event_type_dest = TRIGGER_QUEUING_VIOLATION; + else if (index_trigger == 12) + trigger_event_type_dest = TRIGGER_GO_STRAIGHT; + else if (index_trigger == 13) + trigger_event_type_dest = TRIGGER_GO_STRAIGHT_RED_LIGHT; + else if (index_trigger == 14) + trigger_event_type_dest = TRIGGER_TURN_LEFT_RED_LIGHT; + else if (index_trigger == 15) + trigger_event_type_dest = TRIGGER_TURN_RIGHT_RED_LIGHT; + + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && + ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP + )) && + ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[j]) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) + ) + { + + } + else { + if (trigger_event_type_dest == TRIGGER_LACK_OF_ANY_OBJECT || + trigger_event_type_dest == TRIGGER_ALL_OBJECTS) { + //continue; + } + } + + if (pNext->zone_violation_idx[j] == 1) { + if (trigger_event_type == trigger_event_type_dest) { + + if (trigger_event_type_dest == TRIGGER_GO_STRAIGHT || + trigger_event_type_dest == TRIGGER_GO_STRAIGHT_RED_LIGHT || + trigger_event_type_dest == TRIGGER_TURN_LEFT_RED_LIGHT || + trigger_event_type_dest == TRIGGER_TURN_RIGHT_RED_LIGHT) { + check_if_enable_trigger_go_straight_temp = 1; + } + + if ((pNext->trigger_type & trigger_event_type_dest) == trigger_event_type_dest) { + if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") != 0 || (g_ObjectRecorderList[index_object].check_if_counted[j] == 0 && + pNext->check_if_having_been_counted[j] != 1 && + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] != 1)) + { + //printf("\n-----BBTTTTTTTTTT:%d\n", pNext->obj_tracking_id_idx); + //printf("\n-----CCTTTTTTTTTT:%d\n", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j]); + + + if (trigger_event_type_dest != TRIGGER_QUEUING_VIOLATION || + (check_if_do_once[j] == 0 && trigger_event_type_dest == TRIGGER_QUEUING_VIOLATION)) + { + if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == 1 || + viewDetectionZone[tracking_channel_idx][j].trigger_event[k].counter_increment == -1) + { + CheckEventCounterCondition(pNext, tracking_channel_idx, j, k, 1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + + check_if_do_once[j]++; + } + + + pNext->check_if_having_been_counted[j] = 1; + g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] = 1; + if (trigger_event_type_dest != TRIGGER_QUEUING_VIOLATION) { + g_ObjectRecorderList[index_object].check_if_counted[j] = 1; + } + else { + g_ObjectRecorderList[index_object].check_if_counted[j] = 0; + } + + if (JsonString_cloud != NULL) + CheckPostEventCondition(pNext, tracking_channel_idx, j, k, 0, JsonString_cloud, -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + else + CheckPostEventCondition(pNext, tracking_channel_idx, j, k, 0, "", -1, g_current_snapshot_addr, g_current_snapshot_size, g_current_snapshot_addr_base64, g_current_snapshot_size_base64, g_cropped_img_buf_base64, g_cropped_length_image_base64); + } + } + else { + //pNext->check_if_having_been_counted[j] = 0; + //g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].check_if_having_been_counted[j] = 0; + } + } + } + } + } + } + + break; + } + } + } + } + + HeartbeatPost(); +#ifdef GY_OS_AMBA + if (g_IsPTZDevice == 1) { + if (strcmp(heartbeatData.enable_check_ptz_start_autotracking, "Yes") == 0) + check_start_PTZ_autotracking_Post(); + + if (strcmp(heartbeatData.enable_check_ptz_end_autotracking, "Yes") == 0) + check_end_PTZ_autotracking_Post(); + } +#endif + +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) + { + + char mail_content[256] = { 0 }; + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) + { + char temp_msg[256] = { 0 }; + if (index_counter == 0) { + snprintf(temp_msg, sizeof(temp_msg), "[%d,", eventCounterList[index_counter].counter_count); + strcpy(mail_content, temp_msg); + } + else if (index_counter < MAX_EVENT_COUNTERS - 1) { + snprintf(temp_msg, sizeof(temp_msg), "%d,", eventCounterList[index_counter].counter_count); + strcat(mail_content, temp_msg); + } + else { + snprintf(temp_msg, sizeof(temp_msg), "%d]", eventCounterList[index_counter].counter_count); + strcat(mail_content, temp_msg); + } + } + + run_counter_mail(mail_content,strlen(mail_content)); + } +#endif + + ResetCheckIfDelivering(); + check_if_enable_trigger_go_straight = check_if_enable_trigger_go_straight_temp; + } + } +#endif + + } + else + printf("License's feature is not available.\n"); + } + else if (stAMBAcontent->licenseType == _NO_LICENSE) //vO + { + + } + else if (stAMBAcontent->licenseType == _PERMANENT_LICENSE_MULTI || stAMBAcontent->licenseType == _PERMANENT_LICENSE_SINGLE || stAMBAcontent->licenseType == _PERMANENT_LICENSE_MULTI_POST || + stAMBAcontent->licenseType == _LICENSE_FPS06 || stAMBAcontent->licenseType == _LICENSE_FPS12 || + stAMBAcontent->licenseType == _LICENSE_FPS18 || stAMBAcontent->licenseType == _LICENSE_FPS24 || + stAMBAcontent->licenseType == _LICENSE_FPS30 || stAMBAcontent->licenseType == _LICENSE_FPS36 || + stAMBAcontent->licenseType == _LICENSE_FPS42 || stAMBAcontent->licenseType == _LICENSE_FPS48 || + stAMBAcontent->licenseType == _LICENSE_FPS54 || stAMBAcontent->licenseType == _LICENSE_FPS60) //vOä[v + { + if (stAMBAcontent->afsCode == _MAC_MISMATCH) //vѽXMAC} + printf("Wrong MAC address.\n"); + } + else if (stAMBAcontent->licenseType == _TRIAL_LICENSE_MULTI || stAMBAcontent->licenseType == _TRIAL_LICENSE_SINGLE || + stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS06 || stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS12 || + stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS18 || stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS24 || + stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS30 || stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS36 || + stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS42 || stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS48 || + stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS54 || stAMBAcontent->licenseType == _TRIAL_LICENSE_FPS60) //vOեαv + { + if (stAMBAcontent->afsCode == _MAC_MISMATCH) //vѽXMAC} + printf("Wrong MAC address.\n"); + else if (stAMBAcontent->afsCode == _UNINITIALIZED) //vѽXեαv|_l + printf("Trial has expired\n"); //Trial not initialized + else if (stAMBAcontent->afsCode == _EXPIRED) //vѽXեαvwgL + printf("Trial has expired.\n"); + } + + if (JsonString_post != NULL) { + free(JsonString_post); + JsonString_post = NULL; + } + + if (JsonString_long != NULL) { + free(JsonString_long); + JsonString_long = NULL; + } + + if (JsonString != NULL) { + free(JsonString); + JsonString = NULL; + } + if (JsonString_cloud != NULL) { + free(JsonString_cloud); + JsonString_cloud = NULL; + } + if (JsonString_to_osd != NULL) { + free(JsonString_to_osd); + JsonString_to_osd = NULL; + } + if (JsonString_to_udp != NULL) { + free(JsonString_to_udp); + JsonString_to_udp = NULL; + } + if (JsonString_to_8592 != NULL) { + free(JsonString_to_8592); + JsonString_to_8592 = NULL; + } + if (JsonString_to_8592_no_image != NULL) { + free(JsonString_to_8592_no_image); + JsonString_to_8592_no_image = NULL; + } + + if (root_post) { + cJSON_Delete(root_post); + root_post = NULL; + } + + if (root_long) { + cJSON_Delete(root_long); + root_long = NULL; + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + + if (root_cloud) { + cJSON_Delete(root_cloud); + root_cloud = NULL; + } + + if (root_udp) { + cJSON_Delete(root_udp); + root_udp = NULL; + } + + if (root_8592) { + cJSON_Delete(root_8592); + root_8592 = NULL; + } + + for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) + { + if (count_fps_for_NAND[index_zone] > AI_fps * (viewDetectionZone[tracking_channel_idx][index_zone].no_parking_time)) { + count_fps_for_NAND[index_zone] = 0; + reset_g_Meta_If_Existing_for_NAND(index_zone); + } + count_fps_for_NAND[index_zone]++; + } + + fps_sec_count++; + /* + end = clock(); + dur = (double)(end - start); + printf("\n[8]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); + start = clock();*/ + + set_record_process_note("startallnets_end"); + //QueueIsEmpty(_POST_NOTIFICATION) + + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //쬰@ + //dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = fabs(dw_FPS_time_delta); + //printf("\n-----start all nets #8:%lf ms\n", dw_FPS_time_delta); + + if (check_stop_test_nn_cavalry == 0 && strcmp(SystemSetting.enable_low_cpu_usage, "Yes") == 0) { + usSleep(200000); + } + else { + usSleep(100); + } + } +#endif + + //printf("\n[start all nets] while 21-3\n"); + + //pthread_join(g_run_one_net_thread_id, NULL); + //pthread_join(g_run_one_net_thread_anpr_id, NULL); + + } + + //printf("\n-----[start all nets] end\n"); + return rval;//쥻Oo +} + +void stop_test_nn_cavalry(char* note_stop) { + + check_if_start_run_server = 0; + + { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), note_stop); + write_to_logs_html(temp_msg, "stop gynet", "INFO", "Yes"); + write_to_log_for_start(temp_msg, "stop gynet", "INFO"); + } + + printf("\nstart stop test nn cavalry\n"); + bHttpServerThreadStart = 0; + bHttpServerMainStart = 0; + +#ifdef GY_OS_AMBA + if (g_IsToFDevice == 0) { + usSleep(2500000); + } + +#if 0 + if (g_IsToFDevice == 1) + { + if (tof_shmid != -1) { + // @ɰOM + Free_ShareMemory_YUV(tof_yuv_arr); + } + } + + if (g_IsToFDevice == 1) { + share_memory_stop(); + } +#endif +#else + usSleep(2500000); +#endif + + //printf("\nstop test nn cavalry------01\n"); + stop_canvas_live_mode_flag(); + live_mode_flag = 0; + + check_stop_test_nn_cavalry = 1; +#ifdef GY_OS_AMBA + close_udp_socket(); +#endif + +#if defined GY_OS_AMBA || defined GY_OS_V_SERIES + release_img_background(); +#endif + + clear_g_ivs_hash_record(); + clear_putting_vehicles(); + + //printf("\nstop test nn cavalry------02\n"); + for (int i = 0; i < MAX_DETECTION_ZONE; i++) { + if (viewDetectionZone[0][i].PerspectiveTransformArray != NULL) + cvReleaseMat(&viewDetectionZone[0][i].PerspectiveTransformArray); + } + + + struct nnctrl_param *pctrl = &G_nnctrl; + free_all_cv_mem(pctrl); +#if 1 + + //printf("\nstop test nn cavalry------1\n"); + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (yuv2rgb_out_mem.virt && yuv2rgb_out_mem.size) + { + if (cavalry_mem_free(yuv2rgb_out_mem.size, yuv2rgb_out_mem.phys, yuv2rgb_out_mem.virt) < 0) + printf("cavalry_mem_free yuv2rgb_out_mem err\n"); + } + } +#if 1 + //printf("\nstop test nn cavalry------2\n"); + TRY + { + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (downsized_cropped_mem.virt && downsized_cropped_mem.size) + { + if (cavalry_mem_free(downsized_cropped_mem.size, downsized_cropped_mem.phys, downsized_cropped_mem.virt) < 0) + printf("cavalry_mem_free downsized_cropped_mem err3\n"); + } + } + } + CATCH + { + + } + ETRY; +#endif +#if 1 + //printf("\nstop test nn cavalry------3\n"); + TRY + { + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (tof_img_mem.virt && tof_img_mem.size) + { + if (cavalry_mem_free(tof_img_mem.size, tof_img_mem.phys, tof_img_mem.virt) < 0) + printf("cavalry_mem_free tof_img_mem err3\n"); + } + } + } + CATCH + { + + } + ETRY; +#endif +#if 1 + //printf("\nstop test nn cavalry------4\n"); + TRY + { + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (snap_hd_mem.virt && snap_hd_mem.size) + { + if (cavalry_mem_free(snap_hd_mem.size, snap_hd_mem.phys, snap_hd_mem.virt) < 0) + printf("cavalry_mem_free snap_hd_mem err3\n"); + } + } + } + CATCH + { + + } + ETRY; +#endif +#if 0 + //printf("\nstop test nn cavalry------3\n"); + if (rgb_2K_mem.virt && rgb_2K_mem.size) + { + if (cavalry_mem_free(rgb_2K_mem.size, rgb_2K_mem.phys, rgb_2K_mem.virt) < 0) + printf("cavalry_mem_free rgb_2K_mem err3\n"); + } +#endif + + //printf("\nstop test nn cavalry------5\n"); + //if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + //if (rsz_out_mem.virt && rsz_out_mem.size) + //{ + //if (cavalry_mem_free(rsz_out_mem.size, rsz_out_mem.phys, rsz_out_mem.virt) < 0) + //printf("cavalry_mem_free rsz_out_mem err\n"); + //} + //} + //printf("\nstop test nn cavalry------5\n"); + //if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + //if (submean_mean_mem.virt && submean_mean_mem.size) + //{ + //if (cavalry_mem_free(submean_mean_mem.size, submean_mean_mem.phys, submean_mean_mem.virt) < 0) + //printf("cavalry_mem_free submean_mean_mem err\n"); + //} + //} + //printf("\nstop test nn cavalry------6\n"); + //if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + //if (submean_out_mem.virt && submean_out_mem.size) + //{ + //if (cavalry_mem_free(submean_out_mem.size, submean_out_mem.phys, submean_out_mem.virt) < 0) + //printf("cavalry_mem_free submean_out_mem err\n"); + //} + //} + //printf("\nstop test nn cavalry------7\n"); + //if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + //if (dtcvt_out_mem.virt && dtcvt_out_mem.size) + //{ + //if (cavalry_mem_free(dtcvt_out_mem.size, dtcvt_out_mem.phys, dtcvt_out_mem.virt) < 0) + //printf("cavalry_mem_free dtcvt_out_mem err\n"); + //} + //} + //printf("\nstop test nn cavalry------8\n"); + + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + vproc_exit(); + } + //printf("\nstop test nn cavalry------6\n"); +#if 1 + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (lib_mem.virt && lib_mem.size) + { + if (cavalry_mem_free(lib_mem.size, lib_mem.phys, lib_mem.virt) < 0) + printf("cavalry_mem_free lib_mem err\n"); + } + } +#endif + //printf("\nstop test nn cavalry------7\n"); + + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + if (barcode_img_mem.virt && barcode_img_mem.size) + { + if (cavalry_mem_free(barcode_img_mem.size, barcode_img_mem.phys, barcode_img_mem.virt) < 0) + printf("cavalry_mem_free barcode_img_mem err\n"); + } + } + if (pctrl->fd_cav >= 0) + { + close(pctrl->fd_cav); + pctrl->fd_cav = -1; + } + + //printf("\nstop test nn cavalry------8\n"); + if (fd_iav) + { + close(fd_iav); + fd_iav = -1; + } + //printf("\nstop test nn cavalry------9\n"); + if (G_socket_id) + { + close(G_socket_id); + } + + +#endif + printf("\nend stop test nn cavalry\n"); +} + +void free_all_cv_mem(struct nnctrl_param *pctrl) +{ + struct net_match *pnet = NULL; + struct net_mem *pmem = NULL; + struct io_match *io = NULL; + uint32_t i = 0, j = 0; + + //printf("\n--------free all cv mem #1 ---- %d\n", pctrl->net_num); + for (i = 0; i < pctrl->net_num; i++) { + pnet = &pctrl->net_pair[i]; + pmem = &pnet->net_m; + if (pmem->virt_addr && pmem->mem_size) { + if (cavalry_mem_free(pmem->mem_size, + pmem->phy_addr, pmem->virt_addr) < 0) { + printf("cavalry_mem_free err #1\n"); + } + } + //printf("\n--------free all cv mem #2\n"); + for (j = 0; j < pnet->in_num; j++) { + io = &pnet->in_pair[j]; + if (io->no_mem) { + if (cavalry_mem_free(io->dram_size, + io->dram_addr, io->virt_addr) < 0) { + printf("cavalry_mem_free err #2\n"); + } + } + } + //printf("\n--------free all cv mem #3\n"); + for (j = 0; j < pnet->out_num; j++) { + io = &pnet->out_pair[j]; + if (io->no_mem) { + if (cavalry_mem_free(io->dram_size, + io->dram_addr, io->virt_addr) < 0) { + printf("cavalry_mem_free err #3\n"); + } + } + } + //printf("\n--------free all cv mem #4\n"); + } +} + +#if 1 +void *get_loading() +{ + pthread_detach(pthread_self()); + + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 4); + int size_psBuffer = 256; + + FILE *pPipe = NULL; + char psBuffer[256] = { 0 }; + char psBuffer_temp[256] = { 0 }; + char psBuffer_send[256] = { 0 }; + + + FILE *pPipe2 = NULL; + char psBuffer2[256] = { 0 }; + char psBuffer_temp2[256] = { 0 }; + char psBuffer_temp3[256] = { 0 }; + char psBuffer_send2[256] = { 0 }; + + pPipe = vpopen("timeout 3s mpstat -P ALL 1 1 | grep all | grep Average &", "r"); + pPipe2 = vpopen("timeout 3s /usr/local/bin/cavalry_top -u 100 -c 10000 | grep IDLE | awk '{print}' ORS=';' | cut -c -80 &", "r"); + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 41); + if (pPipe == NULL || pPipe2 == NULL) { + printf("[Error] getloading\n"); + if (pPipe != NULL) + vpclose(pPipe); + if (pPipe2 != NULL) + vpclose(pPipe2); + } + else { + //printf("Run: getloading\n"); + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 411); + char *temp = NULL; + char *temp2 = NULL; + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 412); + temp = fgets(psBuffer, size_psBuffer, pPipe); + temp2 = fgets(psBuffer2, size_psBuffer, pPipe2); + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 413); + if (pPipe != NULL) + vpclose(pPipe); + if (pPipe2 != NULL) + vpclose(pPipe2); + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 42); + if (temp != NULL) { + strncpy(psBuffer_temp, psBuffer + 16, 12); + int c = 0, d = 0; + while (psBuffer_temp[c] != '\0') { + if (psBuffer_temp[c] == ' ' || psBuffer_temp[c] == '\t') { + int _temp = c + 1; + if (psBuffer_temp[_temp] != '\0') { + while ((psBuffer_temp[_temp] == ' ' || psBuffer_temp[_temp] == '\t') && psBuffer_temp[_temp] != '\0') { + if (psBuffer_temp[_temp] == ' ' || psBuffer_temp[_temp] == '\t') { + c++; + } + _temp++; + } + } + } + psBuffer_send[d] = psBuffer_temp[c]; + c++; + d++; + } + psBuffer_send[d] = '\0'; + + //printf("cpu psBuffer: OK\n"); + } + else { + strcpy(psBuffer_send, "NULL"); + printf("[Error]cpu psBuffer Empty\n"); + } + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 43); + if (temp2 != NULL) { + strcpy(psBuffer_temp2, psBuffer2); + int c = 0, d = 0; + while (psBuffer_temp2[c] != '\0') { + if (psBuffer_temp2[c] == ' ' || psBuffer_temp2[c] == '\t' || psBuffer_temp2[c] == 'V' || psBuffer_temp2[c] == 'P' + || psBuffer_temp2[c] == 'I' || psBuffer_temp2[c] == 'D' || psBuffer_temp2[c] == 'L' || psBuffer_temp2[c] == 'E' + || psBuffer_temp2[c] == '%') { + int _temp = c + 1; + if (psBuffer_temp2[_temp] != '\0') { + while ((psBuffer_temp2[_temp] == ' ' || psBuffer_temp2[_temp] == '\t' || psBuffer_temp2[_temp] == 'V' + || psBuffer_temp2[_temp] == 'P' || psBuffer_temp2[_temp] == 'I' || psBuffer_temp2[_temp] == 'D' + || psBuffer_temp2[_temp] == 'L' || psBuffer_temp2[_temp] == 'E' || psBuffer_temp2[_temp] == '%') + && psBuffer_temp2[_temp] != '\0') { + + if (psBuffer_temp2[_temp] == ' ' || psBuffer_temp2[_temp] == '\t' || psBuffer_temp2[_temp] == 'V' + || psBuffer_temp2[_temp] == 'P' || psBuffer_temp2[_temp] == 'I' || psBuffer_temp2[_temp] == 'D' + || psBuffer_temp2[_temp] == 'L' || psBuffer_temp2[_temp] == 'E' || psBuffer_temp2[_temp] == '%') { + + c++; + } + + _temp++; + } + } + } + psBuffer_temp3[d] = psBuffer_temp2[c]; + c++; + d++; + } + psBuffer_temp3[6] = '\0'; + int itemp1 = (int)((100.0 - atof(psBuffer_temp3))*100.0) / 100; + int itemp2 = (int)((100.0 - atof(psBuffer_temp3))*100.0) % 100; + sprintf(psBuffer_send2, "%d.%d", itemp1, itemp2); + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 44); + //printf("gpg psBuffer: %s\n", psBuffer_send2); + //strcpy(psBuffer_send2, ftemp_char); + //printf("gpu psBuffer: OK\n"); + } + else { + strcpy(psBuffer_send2, "NULL"); + printf("[Error]gpu psBuffer Empty\n"); + } + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 45); + //char AI_fps_tojson[256]; + //sprintf(AI_fps_tojson, "%d", AI_fps); + + printf("\n[getloading]cpu return str = %s \n", psBuffer_send); + printf("\n[getloading]gpu return str = %s \n", psBuffer_send2); + printf("\n[getloading]fps return str = %d \n", AI_fps); + + + sprintf(CPU_usage, "%s", psBuffer_send); + sprintf(GPU_usage, "%s", psBuffer_send2); + +#ifdef REBOOT_BY_CPU_GPU_USAGE + CPU_usage_int = atoi(CPU_usage); + GPU_usage_int = atoi(GPU_usage); +#endif + } + + g_i_get_cpu_loading = 0; + //printf("\nOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKK:%d\n", 5); + pthread_exit(NULL); +} +#endif + + +int get_free_mem_data() { + char *temp = NULL; + int size_psBuffer = 512; + char psBuffer[512] = { 0 }; + + { + char cmd[256] = { 0 }; + memset(cmd, 0x00, sizeof(cmd)); +#ifdef GY_OS_AMBA + sprintf(cmd, "timeout 3s free | grep Mem | awk '{print $4}'"); +#else + sprintf(cmd, "free | grep Mem | awk '{print $4}'"); +#endif + + FILE * pPipe; + pPipe = vpopen(cmd, "r"); + + if (pPipe != NULL) { + temp = fgets(psBuffer, size_psBuffer, pPipe); + if (pPipe != NULL) + vpclose(pPipe); + } + } + if (temp != NULL && (int)strlen(psBuffer)>=1) { + /* + printf("\n-------------------------------\n"); + printf("\psBuffer: %d\n", atoi(psBuffer)); + printf("\n-------------------------------\n"); + */ + return atoi(psBuffer); + } + + return -1; +} + +void *run_fps_loading_thread(void *ptr) +{ + pthread_detach(pthread_self()); + setPthreadName("run_fps"); + //printf("\n[run_fps_loading_thread]pthread create\n"); + //printf("\n[run_fps_loading_thread]no new address\n"); + + unsigned int count_to_ping = 0; + + //unsigned int write_config_sec_count = 0; + + unsigned int count_to_refresh_check_license = 0; + + unsigned int punish_sec = 60; + + int count_post = 0; +#ifdef GY_OS_AMBA + int index_ai_engine_view = 0; +#endif + + int g_try_times_device = 0; + + //unsigned int count_to_refresh_smtp_service = 0; + + //unsigned int count_to_refresh_lpr_db = 0; + //Preprocessing + + while (live_mode_flag) + { + set_record_process_note("run_fps_start"); + //printf("\n-------run fps start\n"); + g_osdSysTimeStamp++; +#if 1 + + if (count_post >= 28800) { + count_post = 0; + if (check_if_correct_post == 1) { + if (check_if_run_post == 1) { + + } + else if (check_if_run_post == 0) { + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "There is cloud post error existing for 8 hours. Reboot the camera to restart gynet."); + write_to_logs_html(temp_msg, "run osd time sync thread", "CGI_REBOOT", "Yes"); + //printf("\n-----------------------There is no post for 4 hours.: exit-----------------------\n"); + write_to_log_if_error(temp_msg, "run osd time sync thread", "CGI_REBOOT"); + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + } + } + else { + if (check_if_run_post != 0) { + count_post = 0; + } + + count_post++; + } +#endif + +#if 0 + ///Write config database to file + if (write_config_sec_count % WRITE_CONFIG_FILE == 0) + { + write_config_sec_count = 0; + if (g_write_config_file_dirty_flag == 1) + { + write_config(); + g_write_config_file_dirty_flag = 0; + } + } + write_config_sec_count++; +#endif + + + if (count_to_ping % punish_sec == 0) { + count_to_ping = 0; + + if (g_check_ping_OK == 1) { + punish_sec -= 60; + if (punish_sec < 60) { + punish_sec = 60; + } + } + else { + punish_sec += 60; + if (punish_sec > 3600) { + punish_sec = 3600; + } + + g_check_ping_OK = 1; + } + } + count_to_ping++; + + + if (count_to_refresh_check_license % MAX_COUNT_TO_REFRESH_CHECK_LICENSE == 0) { + count_to_refresh_check_license = 0; + if (td_weight_num == 0 && get_check_if_correct_mail()==0) { + + if (g_li > 0) { + if (g_ad) + check_license(g_li, g_ad, g_bMacMatch, g_start_time, g_end_time, g_filename_TLT); + else + check_license(g_li, 0, g_bMacMatch, g_start_time, g_end_time, g_filename_TLT); + } + else if(check_if_fe_fail == 1){ + check_license(0, 0, g_bMacMatch, g_start_time, g_end_time, g_filename_TLT); + } + } + } + count_to_refresh_check_license++; + + //count_to_refresh_smtp_service++; + //if (count_to_refresh_smtp_service >= MAX_COUNT_TO_REFRESH_SMTP_SERVICE) { + //count_to_refresh_smtp_service = 0; + //copy_ipcam_smtp_service_to_gynet(); + //} + +#if 0 + + if (count_to_refresh_lpr_db % MAX_COUNT_TO_REFRESH_LPR_DB == 0) { + count_to_refresh_lpr_db = 0; + if (strcmp(SystemSetting.enable_sync_external_lpr_db, "Yes") == 0) { + sync_other_camera_lpr_db(); + } + } + count_to_refresh_lpr_db++; +#endif + + if (g_try_times_device % 10 == 0) { + g_try_times_device = 0; + if (g_IsSDK_3_0 == 0) { + pthread_mutex_lock(&mutex_read_ipcam); + int device_name_ok = 0; + char temp_device_name[512] = { 0 }; + + device_name_ok = PNS_Get_Device_Name(1, temp_device_name); + if (device_name_ok >= 1) { + url_decode(temp_device_name, strlen(temp_device_name)); + strcpy(g_device_name, temp_device_name); + } + pthread_mutex_unlock(&mutex_read_ipcam); + } +#ifdef GY_OS_AMBA + run_ptz_server(); +#endif + } + g_try_times_device++; + + +#ifdef GY_OS_AMBA //GET AI FPS + //printf("\n[run_fps_loading_thread]fps return str = %d \n", AI_fps); + + if (viewChannelData[index_ai_engine_view].enable_anpr == 1 + || viewChannelData[index_ai_engine_view].enable_traffic == 1) { + if (AI_fps == 0) { //iH<=0F]w]-1 + printf("\n-----------------------[AI_fps]: exit-----------------------\n"); + + stop_test_nn_cavalry("AI_fps == 0"); + //stop_server(); + + //exit(EXIT_FAILURE); + } + } +#endif + set_record_process_note("run_fps_end"); + usSleep(1000000); + } + + //printf("\n[run_fps_loading_thread]no free address\n"); + //printf("\n[run_fps_loading_thread]pthread exit\n"); + + pthread_exit(NULL); +} + +int try_once_ptz = 0; + +int get_try_once_ptz() { + return try_once_ptz; +} + +void run_ptz_server() { +#ifdef GY_OS_AMBA + if (g_IsPTZDevice == 1 && try_once_ptz == 0) { + //int index_ai_engine_view = 0; + /*int zone_to_preset[4]; + + for (int i = 0; i < 4; i++) + { + zone_to_preset[i] = 0; + + if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL + && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) + { + zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); + } + }*/ + + //InitPTZ enable_PTZ |Ψ + //UpdatePTZConfigSetting(viewChannelData[index_ai_engine_view].enable_PTZ, viewChannelData[index_ai_engine_view].ptz_enable_tracking, + // viewChannelData[index_ai_engine_view].ptz_tracking_fov_min, viewChannelData[index_ai_engine_view].ptz_tracking_fov_max, + // viewChannelData[index_ai_engine_view].confidence2, viewChannelData[index_ai_engine_view].ptz_tracking_mode, viewChannelData[index_ai_engine_view].ptz_tracking_by_enter_zone, + // viewChannelData[index_ai_engine_view].ptz_tracking_resume_dwell, viewDetectionZone[index_ai_engine_view][0].metadata1, zone_to_preset); + UpdatePTZConfigSetting(); + SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + //if (viewChannelData[index_ai_engine_view].ptz_tracking_resume_dwell) + //SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); + //else + //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); + + //Start PTZ update status thread - viewChannelData + StartPTZupdateStatusThread(); + + //Start check ir status + run_ir_status_thread(); + try_once_ptz = 1; + } +#endif +} + +#if 1 +void* test_nn_main(void *ptr) +{ +#ifdef GY_OS_AMBA + ///קKTofӧָJ +#if 0 + if (g_IsToFDevice == 1) { + usSleep(5000000); + } +#endif +#endif + + //printf("\ntest nn main start\n"); + + //HUSO鬪|20210804 + int index_ai_engine_view = 0; + viewChannelData[index_ai_engine_view].iVideo_source_w = 0; + viewChannelData[index_ai_engine_view].iVideo_source_h = 0; + + struct nnctrl_param *pctrl = &G_nnctrl; + //printf("\n[test_nn_main] pctrl:%x\n", pctrl); + //struct vproc_version ver; +#ifdef GY_OS_AMBA + uint32_t size = 0; // Memory size of VProc library + int state = 0; + memset(&lib_mem, 0, sizeof(lib_mem)); + memset(mean_name, '\0', FILENAME_LENGTH * sizeof(char)); +#endif + + memset((void *)pctrl, 0, sizeof(struct nnctrl_param)); // Clean the memory space of the data structure of the nnctrl parameters. + + // Initialize all parameters in the data structure of the nnctrl + // by reading input arguments from the linux command line + // (including network bin file, input/output node settings, color region, buffer id, and etc). + + if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { + + if (init_param(ptr) < 0) { + //pthread_exit(NULL); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "init_param(ptr) < 0"); + write_to_logs_html(temp_msg, "init_param", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "init_param", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + + // Start the driver of the cavalry library. + pctrl->fd_cav = open(CAVALRY_DEV_NODE, O_RDWR, 0); // Assign the file descriptor of the cavalry device and set R/W rights. + if (pctrl->fd_cav < 0) // Make sure the file descriptor of the cavalry device is opened successfully. + { + printf("\n%s\n", CAVALRY_DEV_NODE); + printf("testnn error!!! \n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "pctrl->fd_cav < 0"); + write_to_logs_html(temp_msg, "pctrl->fd_cav", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "pctrl->fd_cav", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + + //HWSO鬪|20210804 + + /*printf("============================================================\n"); + printf("THIS IS LILIN VERSION (2020.06.04 by Cayman).\n"); + printf("============================================================\n");*/ + + // Assign the file descriptor of the cavalry device. Request page size from the system for cavalry device. + if (cavalry_mem_init(pctrl->fd_cav, (uint8_t)pctrl->verbose) < 0) + { + printf("cavalry_mem_init err\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "cavalry_mem_init(pctrl->fd_cav, (uint8_t)pctrl->verbose) < 0"); + write_to_logs_html(temp_msg, "cavalry_mem_init", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "cavalry_mem_init", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + +#if 0 + // Get the version of the processing library of the CVFlow vector processor + if (vproc_get_version(&ver) < 0) + { + printf("vproc get version err\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "vproc_get_version(&ver) < 0"); + write_to_logs_html(temp_msg, "vproc_get_version", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "vproc_get_version", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + printf("%s: %u.%u.%u, mod-time: 0x%x\n", ver.description, ver.major, ver.minor, ver.patch, ver.mod_time); +#endif + + // Initialize vproc library and write the size into the size addr + if (vproc_init("/usr/local/vproc/vproc.bin", &size) < 0) + { + printf("vproc_init err, can not init /usr/local/vproc/vproc.bin\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "vproc_init(/usr/local/vproc/vproc.bin, &size) < 0"); + write_to_logs_html(temp_msg, "vproc_init", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "vproc_init", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + lib_mem.size = size; + + // Get the memory mapping to the cavalry library + if (cavalry_mem_alloc(&lib_mem.size, &lib_mem.phys, &lib_mem.virt, 1, 1) < 0) + { + printf("cavalry_mem_alloc err #5\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "cavalry_mem_alloc(&lib_mem.size, &lib_mem.phys, &lib_mem.virt, 1, 1) < 0"); + write_to_logs_html(temp_msg, "cavalry_mem_alloc", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "cavalry_mem_alloc", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + + // Load the cavalry library from the mapping of the virtual memory addr. to the physical addr. + // Arguments: + // - File descriptor of /dev/cavalry + // - User space virtual addr. of the CV user mem. allocated by the app. + // - User space physical addr. of the CV user mem. allocated by the app. + // - CV user memory size for CV allocated by the app. + vproc_load(pctrl->fd_cav, lib_mem.virt, lib_mem.phys, size); + + // IAV driver: Make sure the file descriptor is r/w available (for CV2x DSP device). + + if ((fd_iav = open("/dev/iav", O_RDWR, 0)) < 0) + { + printf("/dev/iav"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "(fd_iav = open(/dev/iav, O_RDWR, 0)) < 0"); + write_to_logs_html(temp_msg, "/dev/iav", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "/dev/iav", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } + +#if 1 + state = check_dsp_state(); // READ FILE DESCRIPTOR AND CHECK IAV STATE (FOR DSP DEVICE). + + if (state < 0) { + + //pthread_exit(NULL); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "state < 0"); + write_to_logs_html(temp_msg, "state < 0", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "state < 0", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } +#endif +#if 1 + if (map_dsp_buffer(state) < 0) { // GET THE POINTER OF THE MEM. MAPPING TO DSP BUFFER HW (FOR ///Start AI) + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "map_dsp_buffer(state) < 0"); + write_to_logs_html(temp_msg, "map dsp buffer", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "map dsp buffer", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } +#endif + +#if 1 ///Start AI + if (nnctrl_init(pctrl->fd_cav, pctrl->verbose) < 0) + { + printf("nnctrl_init err\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "init_param(ptr) < 0"); + write_to_logs_html(temp_msg, "nnctrl main", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "nnctrl main", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } + } +#endif + + } + +#if 1 + if (start_all_nets(pctrl,ptr) < 0) + { +#ifdef GY_OS_AMBA + printf("start all nets err\n"); + + char temp_msg[8192] = { 0 }; + snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "start all nets err"); + write_to_logs_html(temp_msg, "nnctrl main", "CGI_REBOOT", "Yes"); + write_to_log_if_error(temp_msg, "nnctrl main", "CGI_REBOOT"); + + pthread_t auto_reboot_thread_id; + if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) + { + printf("create auto reboot thread faile \n"); + } +#endif + } +#endif + + //printf("\n-----[test nn main thread] end\n"); + + pthread_exit(NULL); +} +#endif + +void use_sleep_to_adjust_sync_or_async(int tracking_channel_idx) { + + //printf("\n----------- use sleep to adjust sync start\n"); + + if (check_stop_test_nn_cavalry == 0 && (g_IsRadarDevice == 0 || g_IsToFDevice == 1)) { + if (AI_fps >= 18) { + g_current_max_num_image_buff = 9; + usSleep(50000); + } + else if (AI_fps >= 17) { + g_current_max_num_image_buff = 9; + usSleep(30000); + } + else if (AI_fps >= 16) { + g_current_max_num_image_buff = 9; + usSleep(18000); + } + else if (AI_fps >= 15) { + g_current_max_num_image_buff = 9; + usSleep(13000); + } + else if (AI_fps >= 14) { + g_current_max_num_image_buff = 9; + usSleep(10000); + } + else if (AI_fps >= 13) { + g_current_max_num_image_buff = 9; + usSleep(8000); + } + else if (AI_fps >= 12) { + g_current_max_num_image_buff = 9; + usSleep(7000); + } + else if (AI_fps >= 11) { + g_current_max_num_image_buff = 6; + } + else if (AI_fps >= 10) { + g_current_max_num_image_buff = 5; + } + else if (AI_fps >= 9) { + g_current_max_num_image_buff = 4; + } + else if (AI_fps >= 8) { + g_current_max_num_image_buff = 4; + } + else if (AI_fps >= 6 && AI_fps <= 7) { + g_current_max_num_image_buff = 13 - AI_fps; + } + else { + g_current_max_num_image_buff = 9; + } + } + + { + //if (strcmp(viewChannelData[tracking_channel_idx].enable_lpr_upon_triggered, "No") == 0) + { + if (iFeature_lpr_layer_index >= 0) { + while (check_stop_test_nn_cavalry == 0 && live_mode_flag && viewChannelData[0].enable_anpr && g_check_sync_anpr == 0) { +#ifdef GY_OS_AMBA + usSleep(100); +#elif defined GY_OS_V_SERIES + usSleep(10000); +#else + usSleep(10000); +#endif + } + } + } + + if (iFeature_traf_det_layer_index >= 0 || + iFeature_traf_det_layer_index_2 >= 0 || + index_access >= 1 || + iFeature_aifire_det_layer_index >= 0 || + iFeature_aero_det_layer_index >= 0 || + iFeature_mask_layer_index >= 0 || + iFeature_safety_layer_index >= 0 || + iFeature_rail_layer_index >= 0 || + iFeature_sports_layer_index >= 0 || + iFeature_animal_layer_index >= 0 || + iFeature_tof_det_layer_index >= 0 || + iFeature_garbage_layer_index >= 0 || + iFeature_production_layer_index >= 0 || + iFeature_ship_layer_index >= 0) + { +#ifdef GY_OS_AMBA + if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) { + while (check_stop_test_nn_cavalry == 0 && strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && live_mode_flag && viewChannelData[0].enable_traffic && g_check_sync_differ == 0) { +#ifdef GY_OS_AMBA + usSleep(100); +#elif defined GY_OS_V_SERIES + usSleep(10000); +#else + usSleep(10000); +#endif + } + + while (check_stop_test_nn_cavalry == 0 && strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0 && live_mode_flag && viewChannelData[0].enable_traffic && g_check_sync_traffic == 0) { +#ifdef GY_OS_AMBA + usSleep(100); +#elif defined GY_OS_V_SERIES + usSleep(10000); +#else + usSleep(10000); +#endif + } + } + else +#endif + { +#ifdef GY_OS_AMBA + while (check_stop_test_nn_cavalry == 0 && strcmp(viewChannelData[0].enable_unknown_object, "No") == 0 && live_mode_flag && viewChannelData[0].enable_traffic && g_check_sync_traffic == 0) +#else + while (check_stop_test_nn_cavalry == 0 && live_mode_flag && viewChannelData[0].enable_traffic && g_check_sync_traffic == 0) +#endif + { +#ifdef GY_OS_AMBA + usSleep(100); +#elif defined GY_OS_V_SERIES + usSleep(10000); +#else + usSleep(10000); +#endif + } + } + } + +#if 0 + if (unlockingKeyInnoFR == 1) { + while (live_mode_flag && viewChannelData[0].enable_face && g_check_sync_face == 0) { + usSleep(1000); + } + } +#endif + } + + if (check_stop_test_nn_cavalry == 0 && !(viewChannelData[0].enable_anpr && iFeature_lpr_layer_index >= 0) && !(viewChannelData[0].enable_traffic && (iFeature_traf_det_layer_index >= 0 || + index_access >= 1 || + iFeature_aifire_det_layer_index >= 0 || + iFeature_aero_det_layer_index >= 0 || + iFeature_mask_layer_index >= 0 || + iFeature_safety_layer_index >= 0 || + iFeature_rail_layer_index >= 0 || + iFeature_sports_layer_index >= 0 || + iFeature_animal_layer_index >= 0 || + iFeature_tof_det_layer_index >= 0 || + iFeature_garbage_layer_index >= 0 || + iFeature_production_layer_index >= 0 || + iFeature_ship_layer_index >= 0))) + { + usSleep(1000000); + } + + //printf("\n----------- use sleep to adjust sync end\n"); +} + +void unlink_lilin_weight() { + char AMB_GYNet_Traffic_Tiny_WGT_PATH[256] = "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"; + char AMB_GYNet_Traffic_Tiny_ANC_PATH[256] = "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt"; + + char AMB_GYNet_AITHERMAL_WGT_PATH[256] = "/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin"; + char AMB_GYNet_AITHERMAL_ANC_PATH[256] = "/emmc/plugin/Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt"; + + char AMB_GYNet_LOGO_WGT_PATH[256] = "/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin"; + char AMB_GYNet_LOGO_ANC_PATH[256] = "/emmc/plugin/Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt"; + + char AMB_GYNet_AIFIRE_WGT_PATH[256] = "/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin"; + char AMB_GYNet_AIFIRE_ANC_PATH[256] = "/emmc/plugin/Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt"; + + char AMB_GYNet_AITOF_WGT_PATH[256] = "/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin"; + char AMB_GYNet_AITOF_ANC_PATH[256] = "/emmc/plugin/Aida/AITOF/anchors_GYNet_AITOF_ANC.txt"; + + char AMB_GYNet_AIGARBAGE_WGT_PATH[256] = "/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin"; + char AMB_GYNet_AIGARBAGE_ANC_PATH[256] = "/emmc/plugin/Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt"; + + char AMB_GYNet_Human_WGT_PATH[256] = "/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin"; + char AMB_GYNet_Human_ANC_PATH[256] = "/emmc/plugin/Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt"; + + char AMB_GYNet_AIGENDER_WGT_PATH[256] = "/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin"; + char AMB_GYNet_AIGENDER_ANC_PATH[256] = "/emmc/plugin/Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt"; + + char AMB_GYNet_AISAFTY_WGT_PATH[256] = "/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin"; + char AMB_GYNet_AISAFTY_ANC_PATH[256] = "/emmc/plugin/Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt"; + + char AMB_GYNet_AIRAILWAY_WGT_PATH[256] = "/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin"; + char AMB_GYNet_AIRAILWAY_ANC_PATH[256] = "/emmc/plugin/Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt"; + + char AMB_GYNet_AISPORTS_WGT_PATH[256] = "/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin"; + char AMB_GYNet_AISPORTS_ANC_PATH[256] = "/emmc/plugin/Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt"; + + char AMB_GYNet_AISHIP_WGT_PATH[256] = "/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin"; + char AMB_GYNet_AISHIP_ANC_PATH[256] = "/emmc/plugin/Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt"; + + char AMB_GYNet_AIPRODUCTION_WGT_PATH[256] = "/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin"; + char AMB_GYNet_AIPRODUCTION_ANC_PATH[256] = "/emmc/plugin/Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt"; + + char AMB_GYNet_AIAML_WGT_PATH[256] = "/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin"; + char AMB_GYNet_AIAML_ANC_PATH[256] = "/emmc/plugin/Aida/AIAML/anchors_GYNet_AIAML_ANC.txt"; + + char AMB_GYNet_AIFRONTBACK_WGT_PATH[256] = "/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin"; + char AMB_GYNet_AIFRONTBACK_ANC_PATH[256] = "/emmc/plugin/Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt"; + + char AMB_GYNet_AIAERO_WGT_PATH[256] = "/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin"; + char AMB_GYNet_AIAERO_ANC_PATH[256] = "/emmc/plugin/Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt"; + + char AMB_GYNet_LPD_TWN_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin"; + char AMB_GYNet_OCR_TWN_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin"; + char AMB_GYNet_LPD_TWN_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt"; + char AMB_GYNet_OCR_TWN_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt"; + + char AMB_GYNet_LPD_EUR_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin"; + char AMB_GYNet_OCR_EUR_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin"; + char AMB_GYNet_LPD_EUR_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt"; + char AMB_GYNet_OCR_EUR_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt"; + + char AMB_GYNet_LPD_GBR_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin"; + char AMB_GYNet_OCR_GBR_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin"; + char AMB_GYNet_LPD_GBR_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt"; + char AMB_GYNet_OCR_GBR_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt"; + + char AMB_GYNet_LPD_USA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin"; + char AMB_GYNet_OCR_USA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin"; + char AMB_GYNet_LPD_USA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt"; + char AMB_GYNet_OCR_USA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt"; + + char AMB_GYNet_LPD_SEA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin"; + char AMB_GYNet_OCR_SEA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin"; + char AMB_GYNet_LPD_SEA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt"; + char AMB_GYNet_OCR_SEA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt"; + + char AMB_GYNet_LPD_JPN_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin"; + char AMB_GYNet_OCR_JPN_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin"; + char AMB_GYNet_LPD_JPN_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt"; + char AMB_GYNet_OCR_JPN_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt"; + + char AMB_GYNet_LPD_THA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin"; + char AMB_GYNet_OCR_THA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin"; + char AMB_GYNet_LPD_THA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt"; + char AMB_GYNet_OCR_THA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt"; + + char AMB_GYNet_LPD_PHL_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin"; + char AMB_GYNet_OCR_PHL_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin"; + char AMB_GYNet_LPD_PHL_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt"; + char AMB_GYNet_OCR_PHL_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt"; + + char AMB_GYNet_LPD_VNM_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRVNM/cavalry_GYNet_LPD_WGT_VNM.bin"; + char AMB_GYNet_OCR_VNM_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRVNM/cavalry_GYNet_OCR_WGT_VNM.bin"; + char AMB_GYNet_LPD_VNM_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRVNM/anchors_GYNet_LPD_ANC_VNM.txt"; + char AMB_GYNet_OCR_VNM_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRVNM/anchors_GYNet_OCR_ANC_VNM.txt"; + + char AMB_GYNet_LPD_BGD_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin"; + char AMB_GYNet_OCR_BGD_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin"; + char AMB_GYNet_LPD_BGD_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt"; + char AMB_GYNet_OCR_BGD_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt"; + + char AMB_GYNet_LPD_MEA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin"; + char AMB_GYNet_OCR_MEA_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin"; + char AMB_GYNet_LPD_MEA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt"; + char AMB_GYNet_OCR_MEA_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt"; + + char AMB_GYNet_LPD_AUS_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin"; + char AMB_GYNet_OCR_AUS_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin"; + char AMB_GYNet_LPD_AUS_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt"; + char AMB_GYNet_OCR_AUS_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt"; + + char AMB_GYNet_LPD_CNT_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin"; + char AMB_GYNet_OCR_CNT_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin"; + char AMB_GYNet_LPD_CNT_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt"; + char AMB_GYNet_OCR_CNT_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt"; + + char AMB_GYNet_LPD_IDN_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRIDN/cavalry_GYNet_LPD_WGT_IDN.bin"; + char AMB_GYNet_OCR_IDN_WGT_PATH[256] = "/emmc/plugin/Aida/AIANPRIDN/cavalry_GYNet_OCR_WGT_IDN.bin"; + char AMB_GYNet_LPD_IDN_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRIDN/anchors_GYNet_LPD_ANC_IDN.txt"; + char AMB_GYNet_OCR_IDN_ANC_PATH[256] = "/emmc/plugin/Aida/AIANPRIDN/anchors_GYNet_OCR_ANC_IDN.txt"; + /////////////////////////////////////////////////////////////////Delete not decryed data + + if (FileExist(AMB_GYNet_Traffic_Tiny_ANC_PATH)) { + int del = unlink(AMB_GYNet_Traffic_Tiny_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_Traffic_Tiny_ANC_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_Traffic_Tiny_WGT_PATH)) { + int del = unlink(AMB_GYNet_Traffic_Tiny_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_Traffic_Tiny_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AITHERMAL_ANC_PATH)) { + int del = unlink(AMB_GYNet_AITHERMAL_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AITHERMAL_ANC_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AITHERMAL_WGT_PATH)) { + int del = unlink(AMB_GYNet_AITHERMAL_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AITHERMAL_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LOGO_ANC_PATH)) { + int del = unlink(AMB_GYNet_LOGO_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LOGO_ANC_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_LOGO_WGT_PATH)) { + int del = unlink(AMB_GYNet_LOGO_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LOGO_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AIFIRE_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIFIRE_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIFIRE_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIFIRE_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIFIRE_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIFIRE_ANC_PATH cannot be Deleted.\n"); + } + } +#if 1 + if (FileExist(AMB_GYNet_AITOF_WGT_PATH)) { + int del = unlink(AMB_GYNet_AITOF_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AITOF_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AITOF_ANC_PATH)) { + int del = unlink(AMB_GYNet_AITOF_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AITOF_ANC_PATH cannot be Deleted.\n"); + } + } +#endif + + if (FileExist(AMB_GYNet_AIGARBAGE_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIGARBAGE_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIGARBAGE_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIGARBAGE_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIGARBAGE_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIGARBAGE_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_Human_WGT_PATH)) { + int del = unlink(AMB_GYNet_Human_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_Human_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_Human_ANC_PATH)) { + int del = unlink(AMB_GYNet_Human_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_Human_ANC_PATH cannot be Deleted.\n"); + } + } + + + if (FileExist(AMB_GYNet_AIGENDER_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIGENDER_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIGENDER_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIGENDER_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIGENDER_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIGENDER_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AISAFTY_WGT_PATH)) { + int del = unlink(AMB_GYNet_AISAFTY_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AISAFTY_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AISAFTY_ANC_PATH)) { + int del = unlink(AMB_GYNet_AISAFTY_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AISAFTY_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AIRAILWAY_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIRAILWAY_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIRAILWAY_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIRAILWAY_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIRAILWAY_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIRAILWAY_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AISPORTS_WGT_PATH)) { + int del = unlink(AMB_GYNet_AISPORTS_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AISPORTS_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AISPORTS_ANC_PATH)) { + int del = unlink(AMB_GYNet_AISPORTS_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AISPORTS_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AISHIP_WGT_PATH)) { + int del = unlink(AMB_GYNet_AISHIP_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AISHIP_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AISHIP_ANC_PATH)) { + int del = unlink(AMB_GYNet_AISHIP_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AISHIP_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AIPRODUCTION_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIPRODUCTION_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIPRODUCTION_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIPRODUCTION_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIPRODUCTION_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIPRODUCTION_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AIAML_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIAML_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIAML_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIAML_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIAML_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIAML_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AIFRONTBACK_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIFRONTBACK_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIFRONTBACK_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIFRONTBACK_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIFRONTBACK_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIFRONTBACK_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_AIAERO_WGT_PATH)) { + int del = unlink(AMB_GYNet_AIAERO_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIAERO_WGT_PATH cannot be Deleted.\n"); + } + } + if (FileExist(AMB_GYNet_AIAERO_ANC_PATH)) { + int del = unlink(AMB_GYNet_AIAERO_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_AIAERO_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_TWN_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_TWN_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_TWN_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_TWN_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_TWN_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_TWN_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_TWN_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_TWN_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_TWN_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_TWN_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_TWN_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_TWN_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_EUR_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_EUR_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_EUR_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_EUR_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_EUR_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_EUR_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_EUR_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_EUR_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_EUR_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_EUR_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_EUR_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_EUR_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_GBR_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_GBR_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_GBR_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_GBR_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_GBR_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_GBR_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_GBR_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_GBR_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_GBR_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_GBR_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_GBR_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_GBR_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_USA_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_USA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_USA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_USA_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_USA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_USA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_USA_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_USA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_USA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_USA_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_USA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_USA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_SEA_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_SEA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_SEA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_SEA_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_SEA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_SEA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_SEA_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_SEA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_SEA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_SEA_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_SEA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_SEA_ANC_PATH cannot be Deleted.\n"); + } + } + + + if (FileExist(AMB_GYNet_LPD_JPN_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_JPN_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_JPN_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_JPN_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_JPN_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_JPN_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_JPN_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_JPN_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_JPN_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_JPN_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_JPN_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_JPN_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_THA_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_THA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_THA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_THA_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_THA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_THA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_THA_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_THA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_THA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_THA_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_THA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_THA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_PHL_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_PHL_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_PHL_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_PHL_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_PHL_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_PHL_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_PHL_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_PHL_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_PHL_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_PHL_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_PHL_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_PHL_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_VNM_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_VNM_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_VNM_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_VNM_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_VNM_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_VNM_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_VNM_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_VNM_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_VNM_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_VNM_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_VNM_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_VNM_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_BGD_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_BGD_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_BGD_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_BGD_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_BGD_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_BGD_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_BGD_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_BGD_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_BGD_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_BGD_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_BGD_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_BGD_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_MEA_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_MEA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_MEA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_MEA_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_MEA_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_MEA_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_MEA_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_MEA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_MEA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_MEA_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_MEA_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_MEA_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_AUS_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_AUS_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_AUS_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_AUS_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_AUS_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_AUS_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_AUS_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_AUS_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_AUS_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_AUS_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_AUS_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_AUS_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_CNT_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_CNT_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_CNT_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_CNT_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_CNT_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_CNT_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_CNT_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_CNT_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_CNT_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_CNT_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_CNT_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_CNT_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_IDN_WGT_PATH)) { + int del = unlink(AMB_GYNet_LPD_IDN_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_IDN_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_IDN_WGT_PATH)) { + int del = unlink(AMB_GYNet_OCR_IDN_WGT_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_IDN_WGT_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_LPD_IDN_ANC_PATH)) { + int del = unlink(AMB_GYNet_LPD_IDN_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_LPD_IDN_ANC_PATH cannot be Deleted.\n"); + } + } + + if (FileExist(AMB_GYNet_OCR_IDN_ANC_PATH)) { + int del = unlink(AMB_GYNet_OCR_IDN_ANC_PATH); + if (!del) { + //printf("config_bak is Deleted successfully."); + } + else { + printf("AMB_GYNet_OCR_IDN_ANC_PATH cannot be Deleted.\n"); + } + } + +} + +// INITIALIZE THE PARAMETER OF THE NNCTRL STRUCTURE BY READING THE INPUT ARGUMENTS FROM THE LINUX COMMAND LINE (INCLUDING NETWORK BIN FILE, INPUT/OUTPUT NODES SETTINGS, COLOR REGION, BUFFER ID, AND ETC) +int init_param(void *ptr) +{ + struct nnctrl_param *pctl = &G_nnctrl; // G_nnctrl: A global structure for the NN Control Parameters. pctl: A pointer to the address of G_nnctrl. + uint32_t net_idx = 0; + + //uint32_t net_idx_sec = 0; + //uint32_t in_idx_sec = 0; + //uint32_t out_idx_sec = 0; + + //tiny + //char **argv = "-p 27182 -b cavalry_GYNet_Human_WGT_1.0.3.bin -s 0 -i 0 --in Placeholder --out yolov3_tiny/conv2d_9/BiasAdd --out yolov3_tiny/conv2d_12/BiasAdd -t 0"; + //none_tiny + //char **argv = "- p 27182 - b <JvɦW> -s 0 - i 0 --in Placeholder --out yolov3 / conv2d_58 / BiasAdd --out yolov3 / conv2d_66 / BiasAdd --out yolov3 / conv2d_74 / BiasAdd - t 0 + + //for parse cfg name + struct amba_content *p_amba_content; + p_amba_content = (amba_content*)ptr; + const char *del = ","; + char amba_cfg_file_names[MAX_SELECTED_FILES][STRSPLIT_SIZE] = { 0 }; + int amba_cfg_file_names_num = 0; + + //int amba_anchor_file_names_num = 0; + char amba_label_file_names[MAX_SELECTED_FILES][STRSPLIT_SIZE] = { 0 }; + //int amba_label_file_names_num = 0; + char amba_ver_file_names[MAX_SELECTED_FILES][STRSPLIT_SIZE] = { 0 }; + int amba_ver_file_names_num = 0; + int layer_count = 0; +#ifdef GY_OS_AMBA + uint32_t in_idx = 0; + uint32_t out_idx = 0; + int value = 0; + char opt_buf[CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH] = { 0 }; + char amba_anchor_file_names[MAX_SELECTED_FILES][STRSPLIT_SIZE] = { 0 }; + int tiny_enable_local = 0; +#endif + //printf("total net name = %s \n", p_amba_content->sz_amba_NetworkNames); + //printf("total anchor name = %s \n", p_amba_content->sz_amba_anchor_fileNames); + //printf("total label name = %s \n", p_amba_content->sz_amba_label_fileNames); + + if (p_amba_content->sz_amba_NetworkNames) + amba_cfg_file_names_num = StrSplit(p_amba_content->sz_amba_NetworkNames, amba_cfg_file_names, del); +#ifdef GY_OS_AMBA + if (p_amba_content->sz_amba_anchor_fileNames) + //amba_anchor_file_names_num = StrSplit(p_amba_content->sz_amba_anchor_fileNames, amba_anchor_file_names, del); + StrSplit(p_amba_content->sz_amba_anchor_fileNames, amba_anchor_file_names, del); +#endif + + if (p_amba_content->sz_amba_label_fileNames) + //amba_label_file_names_num = StrSplit(p_amba_content->sz_amba_label_fileNames, amba_label_file_names, del); + StrSplit(p_amba_content->sz_amba_label_fileNames, amba_label_file_names, del); +#if 1 + + //printf("\n%s\n", p_amba_content->sz_amba_ver_fileNames); + if (p_amba_content->sz_amba_ver_fileNames) + amba_ver_file_names_num = StrSplit(p_amba_content->sz_amba_ver_fileNames, amba_ver_file_names, del); +#endif + + + //memset(Buffer_ver, 0x00, BUFSIZE); + strcpy(Buffer_ver, ""); + char cmd1[256] = ","; +#ifdef GY_OS_AMBA + if (unlockingKeyInnoFR_success == 1) { + char buf_temp[CLASSNAME_LENGTH] = { 0 }; + char buf_temp2[CLASSNAME_LENGTH] = { 0 }; + + sprintf(buf_temp, "2.2.1"); + sprintf(buf_temp2, "AIFACE"); + + strcat(Buffer_ver, buf_temp2); + strcat(Buffer_ver, cmd1); + strcat(Buffer_ver, buf_temp); + } +#endif + for (int i = 0; i < amba_ver_file_names_num; i++) { + //printf("\n%s\n", amba_ver_file_names[i]); + char buf_temp[CLASSNAME_LENGTH] = { 0 }; + //printf("\n%s\n", amba_ver_file_names[i]); + init_ver_file(amba_ver_file_names[i], buf_temp); + + char myarr[PATH_COUNT_SLASH][STRSPLIT_SIZE] = { 0 }; + char buf_temp2[CLASSNAME_LENGTH] = { 0 }; + const char *mydel = "/"; + StrSplit(amba_ver_file_names[i], myarr, mydel); + + if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_Traffic_Tiny_VER.txt", 24) == 0) { + sprintf(buf_temp2, "TRAFFIC"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AITHERMAL_VER.txt", 21) == 0) { + sprintf(buf_temp2, "TRAFFIC"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIFIRE_VER.txt", 18) == 0) { + sprintf(buf_temp2, "AIFIRE"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AITOF_VER.txt", 17) == 0) { + sprintf(buf_temp2, "AITOF"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIGARBAGE_VER.txt", 21) == 0) { + sprintf(buf_temp2, "AIGARBAGE"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_Human_VER.txt", 17) == 0) { + sprintf(buf_temp2, "HUMAN"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AISAFTY_VER.txt", 19) == 0) { + sprintf(buf_temp2, "AISAFTY"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIRAILWAY_VER.txt", 21) == 0) { + sprintf(buf_temp2, "AIRAILWAY"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AISPORTS_VER.txt", 20) == 0) { + sprintf(buf_temp2, "AISPORTS"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AISHIP_VER.txt", 18) == 0) { + sprintf(buf_temp2, "AISHIP"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIAML_VER.txt", 17) == 0) { + sprintf(buf_temp2, "AIAML"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIFRONTBACK_VER.txt", 23) == 0) { + sprintf(buf_temp2, "AIFRONTBACK"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_USA_VER.txt", 20) == 0) { + sprintf(buf_temp2, "USA"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_EUR_VER.txt", 20) == 0) { + sprintf(buf_temp2, "EUR"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_GBR_VER.txt", 20) == 0) { + sprintf(buf_temp2, "GBR"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_TWN_VER.txt", 20) == 0) { + sprintf(buf_temp2, "TWN"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_SEA_VER.txt", 20) == 0) { + sprintf(buf_temp2, "SEA"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_JPN_VER.txt", 20) == 0) { + sprintf(buf_temp2, "JPN"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_THA_VER.txt", 20) == 0) { + sprintf(buf_temp2, "THA"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_IDN_VER.txt", 20) == 0) { + sprintf(buf_temp2, "IDN"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_PHL_VER.txt", 20) == 0) { + sprintf(buf_temp2, "PHL"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_VNM_VER.txt", 20) == 0) { + sprintf(buf_temp2, "VNM"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_BGD_VER.txt", 20) == 0) { + sprintf(buf_temp2, "BGD"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_MEA_VER.txt", 20) == 0) { + sprintf(buf_temp2, "MEA"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_CNT_VER.txt", 20) == 0) { + sprintf(buf_temp2, "CNT"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_ANPR_AUS_VER.txt", 20) == 0) { + sprintf(buf_temp2, "AUS"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_LOGO_VER.txt", 16) == 0) { + sprintf(buf_temp2, "LOGO"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIRADAR_VER.txt", 19) == 0) { // Ken 2022-10-13 + sprintf(buf_temp2, "AIRADAR"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIGENDER_VER.txt", 20) == 0) { // Ken 2022-10-13 + sprintf(buf_temp2, "AIGENDER"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIPRODUCTION_VER.txt", 24) == 0) { + sprintf(buf_temp2, "AIPRODUCTION"); + } + else if (strncmp(myarr[PATH_COUNT_SLASH - 1], "AMB_AIAERO_VER.txt", 18) == 0) { + sprintf(buf_temp2, "AIAERO"); + } + + if (i == 0) { + strcat(Buffer_ver, buf_temp2); + strcat(Buffer_ver, cmd1); + strcat(Buffer_ver, buf_temp); + } + else { + strcat(Buffer_ver, cmd1); + strcat(Buffer_ver, buf_temp2); + strcat(Buffer_ver, cmd1); + strcat(Buffer_ver, buf_temp); + } + } + //printf("\n%s\n",Buffer_ver); + + //20201126 sophia add + if (amba_cfg_file_names_num > 0) + { + layer_count = amba_cfg_file_names_num; + + if (amba_cfg_file_names_num > MAX_LAYER_NUM) + { + layer_count = MAX_LAYER_NUM; + } + } + //printf("\n[init_param] layer_count:%d\n",layer_count); + + //for parse cfg name + + ///p + G_port = 27182; + + ///s + buffer_type = 0; + //printf("Input buffer type = %d\n", buffer_type); + + ///i + buffer_id = 0; + //printf("Input buffer id = %d\n", buffer_id); + + ///t + rgb_type = 0; + //printf("RGB data color space type = %d\n", rgb_type); + + for (int n = 0; n < layer_count; n++) + { + ///read label name to mem + + + + ///b + net_idx = pctl->net_num; // Get previously registered number of the network quantities. + + + //printf("init idx %d netIdx %d ================ \n", n, net_idx); + + pctl->net_pair[net_idx].reuse_mem = 1; // Enable reusing memory by default. + strncpy(pctl->net_pair[net_idx].net_name, amba_cfg_file_names[net_idx], sizeof(pctl->net_pair[net_idx].net_name) - 1); ///Steven amba_cfg_file_name = 2, is for Test, Hard code. + //printf("Cavalry Bin: [%u][%s]\n", net_idx, pctl->net_pair[net_idx].net_name); + pctl->net_num++; // Register the number of the network quantities. +#ifdef GY_OS_AMBA + ///IN + value = strlen("Placeholder"); + if (value > CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH) + { + //printf("io pair [%s] is too long [%u] (>%u).\n", "Placeholder", value, CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH); + //return -1; + } + strncpy(opt_buf, "Placeholder", sizeof(opt_buf) - 1); + //printf("INPUT: [%s]\n", opt_buf); + in_idx = pctl->net_pair[net_idx].in_num; // Get previously registered number of the input quantities. + if (set_io_pair(opt_buf, &pctl->net_pair[net_idx].in_pair, in_idx) < 0) + { + //printf("parse io pair [%s] failed, discard.\n", opt_buf); + //break; + } + pctl->net_pair[net_idx].in_pair[in_idx].load_input = 1; + pctl->net_pair[net_idx].in_num++; // Register the number of the input quantities. + + tiny_enable_local = p_amba_content->tiny_enable[net_idx]; + if (tiny_enable_local == 1) + pctl->net_pair[net_idx].input_bin_num = AMBA_YOLOV3_FEATURE_MAP_8; + else + pctl->net_pair[net_idx].input_bin_num = AMBA_YOLOV3_FEATURE_NUM; + + if (tiny_enable_local) //20201126 sophia add + { + ///OUT 1 + value = strlen("yolov3_tiny/conv2d_9/BiasAdd"); + if (value > CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH) + { + printf("io pair [%s] is too long [%u] (>%u).\n", "yolov3_tiny/conv2d_9/BiasAdd", value, CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH); + //return -1; + } + strncpy(opt_buf, "yolov3_tiny/conv2d_9/BiasAdd", sizeof(opt_buf) - 1); + //printf("OUTPUT: [%s]\n", opt_buf); + out_idx = pctl->net_pair[net_idx].out_num; // Get previously registered number of the output quantities. + if (set_io_pair(opt_buf, &pctl->net_pair[net_idx].out_pair, out_idx) < 0) // If setting the data structure (pair) is failed + { + printf("parse io pair [%s] failed, discard.\n", opt_buf); + //break; + } + pctl->net_pair[net_idx].out_num++; // Register the number of the output quantities. + + ///OUT 2 + value = strlen("yolov3_tiny/conv2d_12/BiasAdd"); + if (value > CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH) + { + printf("io pair [%s] is too long [%u] (>%u).\n", "yolov3_tiny/conv2d_12/BiasAdd", value, CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH); + //return -1; + } + strncpy(opt_buf, "yolov3_tiny/conv2d_12/BiasAdd", sizeof(opt_buf) - 1); + //printf("OUTPUT: [%s]\n", opt_buf); + out_idx = pctl->net_pair[net_idx].out_num; // Get previously registered number of the output quantities. + if (set_io_pair(opt_buf, &pctl->net_pair[net_idx].out_pair, out_idx) < 0) // If setting the data structure (pair) is failed + { + printf("parse io pair [%s] failed, discard.\n", opt_buf); + //break; + } + pctl->net_pair[net_idx].out_num++; // Register the number of the output quantities. + } + else//20201126 sophia add + { + ///OUT 1 + value = strlen("yolov3/conv2d_58/BiasAdd"); + if (value > CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH) + { + printf("io pair [%s] is too long [%u] (>%u).\n", "yolov3/conv2d_58/BiasAdd", value, CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH); + //return -1; + } + strncpy(opt_buf, "yolov3/conv2d_58/BiasAdd", sizeof(opt_buf) - 1); + //printf("OUTPUT: [%s]\n", opt_buf); + out_idx = pctl->net_pair[net_idx].out_num; // Get previously registered number of the output quantities. + if (set_io_pair(opt_buf, &pctl->net_pair[net_idx].out_pair, out_idx) < 0) // If setting the data structure (pair) is failed + { + printf("parse io pair [%s] failed, discard.\n", opt_buf); + //break; + } + pctl->net_pair[net_idx].out_num++; // Register the number of the output quantities. + + ///OUT 2 + value = strlen("yolov3/conv2d_66/BiasAdd"); + if (value > CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH) + { + printf("io pair [%s] is too long [%u] (>%u).\n", "yolov3/conv2d_66/BiasAdd", value, CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH); + //return -1; + } + strncpy(opt_buf, "yolov3/conv2d_66/BiasAdd", sizeof(opt_buf) - 1); + //printf("OUTPUT: [%s]\n", opt_buf); + out_idx = pctl->net_pair[net_idx].out_num; // Get previously registered number of the output quantities. + if (set_io_pair(opt_buf, &pctl->net_pair[net_idx].out_pair, out_idx) < 0) // If setting the data structure (pair) is failed + { + printf("parse io pair [%s] failed, discard.\n", opt_buf); + //break; + } + pctl->net_pair[net_idx].out_num++; // Register the number of the output quantities. + + ///OUT 3 + value = strlen("yolov3/conv2d_74/BiasAdd"); + if (value > CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH) + { + printf("io pair [%s] is too long [%u] (>%u).\n", "yolov3/conv2d_74/BiasAdd", value, CAVALRY_IO_NAME_MAX + 1 + FILENAME_LENGTH); + //return -1; + } + strncpy(opt_buf, "yolov3/conv2d_74/BiasAdd", sizeof(opt_buf) - 1); + //printf("OUTPUT: [%s]\n", opt_buf); + out_idx = pctl->net_pair[net_idx].out_num; // Get previously registered number of the output quantities. + if (set_io_pair(opt_buf, &pctl->net_pair[net_idx].out_pair, out_idx) < 0) // If setting the data structure (pair) is failed + { + printf("parse io pair [%s] failed, discard.\n", opt_buf); + //break; + } + pctl->net_pair[net_idx].out_num++; // Register the number of the output quantities. + } +#endif + +#ifdef GY_OS_AMBA + uint32_t width = 0, height = 0, pitch = 0; + uint32_t total_vpout_length = 0; + uint32_t ratio = 0, anchorNum = -1; +#endif + uint32_t obj_num = 0; + + //20201126 sophia mark, use global define + //input_bin_num = AMBA_YOLOV3_FEATURE_MAP_8; + //input_bin_num = AMBA_YOLOV3_FEATURE_NUM; + + //printf("\n------amba_label_file_names[net_idx]:%s\n", amba_label_file_names[net_idx]); + classNum = init_label_file_lilin(amba_label_file_names[net_idx], pctl->net_pair[net_idx].classNames); // LOAD THE NAMES AND IDS OF THE LABELS INTO "classNames" STRUCTURE + /*if (net_idx == 0) + classNum = init_label_file_lilin("/emmc/plugin/AIANPRTWN/GYNet_LPD_Label_TWN_d.names", pctl->net_pair[net_idx].classNames); // LOAD THE NAMES AND IDS OF THE LABELS INTO "classNames" STRUCTURE + else if (net_idx == 1) + classNum = init_label_file_lilin("/emmc/plugin/AIANPRTWN/GYNet_OCR_Label_TWN_d.names", pctl->net_pair[net_idx].classNames); // LOAD THE NAMES AND IDS OF THE LABELS INTO "classNames" STRUCTURE*/ + + + if (classNum >= 0) + { + obj_num = classNum / 2; + } + + //printf("Label file loaded: %s. classNum = %d\n", amba_label_file_names[net_idx], classNum); + + //pctl->net_pair[net_idx].total_cls = g_total_cls; + pctl->net_pair[net_idx].total_cls = obj_num; + //if (net_idx == 0) + // pctl->net_pair[net_idx].total_cls = obj_num; + //else if (net_idx == 1) + // pctl->net_pair[net_idx].total_cls = obj_num; + + //printf("total cls = %d \n", pctl->net_pair[net_idx].total_cls); + +#ifdef GY_OS_AMBA + //for (int i = 0; i < input_bin_num; i++) { + for (int i = 0; i < pctl->net_pair[net_idx].input_bin_num; i++) { + ratio = 32 >> i; + width = g_img_width / ratio; + height = g_img_height / ratio; + pitch = (ROUND_UP_32(sizeof(float) * width)) / sizeof(float); + //total_vpout_length += (height * pitch) * ((g_total_cls + 5) * 3); + total_vpout_length += (height * pitch) * ((obj_num + 5) * 3); + //if (net_idx == 0) + // total_vpout_length += (height * pitch) * ((obj_num + 5) * 3); + //else if (net_idx == 1) + // total_vpout_length += (height * pitch) * ((obj_num + 5) * 3); + } + + total_vpout_length = total_vpout_length * sizeof(float); + //printf("\n--------------total_vpout_length: %u\n", total_vpout_length); + + memset(g_f_socket_data, 0x00, sizeof(g_f_socket_data)); + memset(g_parse_buffer, 0x00, sizeof(g_parse_buffer)); + + //printf("anchor_file name = %s \n", amba_anchor_file_names[net_idx]); + + // Init anchor file, default value is from Public Yolov3 + if (strlen(amba_anchor_file_names[net_idx]) > 0) { + //printf("\n------amba_anchor_file_names[net_idx]:%s\n", amba_anchor_file_names[net_idx]); + anchorNum = init_anchor_file(amba_anchor_file_names[net_idx], pctl->net_pair[net_idx].anchors, tiny_enable_local); + //if(net_idx == 0) + // anchorNum = init_anchor_file(amba_anchor_file_names[net_idx], anchors, tiny_enable_local); + //else if(net_idx == 1) + // anchorNum = init_anchor_file(amba_anchor_file_names[net_idx], anchors_sec, tiny_enable_local); + + if (anchorNum < 0) { + printf("Init [%d] anchor file fail!\n", net_idx); + //ret = -1; + } + } + + init_yolov3_flag[net_idx] = init_amba_yolov3(&pctl->net_pair[net_idx].amba_yolov3_result, net_idx, obj_num, pctl->net_pair[net_idx].anchors, tiny_enable_local); + + if (init_yolov3_flag[net_idx] < 0) { + printf("init [%d] amba yolov3 fail!\n", net_idx); + //ret = -1; + } +#endif + } + + return 0; +} + +int check_dsp_state(void) +{ + int state; + if (ioctl(fd_iav, IAV_IOC_GET_IAV_STATE, &state) < 0) { + //perror("IAV_IOC_GET_IAV_STATE"); + printf("IAV_IOC_GET_IAV_STATE"); + exit(2); + } + + if ((state != IAV_STATE_PREVIEW) && (state != IAV_STATE_ENCODING) + && (state != IAV_STATE_DECODING)) { + printf("IAV is not in preview / encoding / decoding state, cannot get yuv buf!\n"); + return -1; + } + dsp_state = state; + return state; +} + +int map_dsp_buffer(int state) +{ + struct iav_querymem query_mem; + struct iav_mem_part_info *part_info; + u32 pid; + + switch (state) { + case IAV_STATE_PREVIEW: + case IAV_STATE_ENCODING: + pid = IAV_PART_DSP; + break; + case IAV_STATE_DECODING: + pid = IAV_PART_PYRAMID_POOL; + break; + default: + printf("state type error!!!\n"); + return -1; + } + + memset(&query_mem, 0, sizeof(query_mem)); + query_mem.mid = IAV_MEM_PARTITION; + part_info = &query_mem.arg.partition; + part_info->pid = pid; + if (ioctl(fd_iav, IAV_IOC_QUERY_MEMBLOCK, &query_mem) < 0) { + printf("IAV_IOC_QUERY_MEMBLOCK"); + return -1; + } + + dsp_size = part_info->mem.length; + dsp_mem = mmap(NULL, dsp_size, PROT_READ, MAP_SHARED, fd_iav, part_info->mem.addr); + if (dsp_mem == MAP_FAILED) { + printf("mmap failed !!!\n"); + return -1; + } + dsp_phy_addr = part_info->mem.addr; + + return 0; +} + +int sort_detection_pos(const void *a, const void *b) +{ + detection_pos *c = (detection_pos *)a; + detection_pos *d = (detection_pos *)b; + + if (c->engine_type != d->engine_type) + { + return c->engine_type > d->engine_type ? 1:-1; + } + else + { + if (c->engine_type2 != d->engine_type2) + { + return c->engine_type2 > d->engine_type2 ? 1:-1; + } + else { + if (c->parent_idx != d->parent_idx) + return c->parent_idx - d->parent_idx; + else + { + if (c->obj_type != d->obj_type) + return c->obj_type - d->obj_type; + else + { + //if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA || (featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) { + if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) { + return c->left_x > d->left_x ? 1 : -1; + } + else { + if (c->number_row != d->number_row) + return c->number_row - d->number_row; + else + { + return c->left_x > d->left_x ? 1 : -1; + } + } + } + } + } + } +} + +int sort_detection_pos_CNT(const void *a, const void *b) +{ + detection_pos *c = (detection_pos *)a; + detection_pos *d = (detection_pos *)b; + + if (c->engine_type != d->engine_type) + { + return c->engine_type > d->engine_type ? 1 : -1; + } + else + { + if (c->engine_type2 != d->engine_type2) + { + return c->engine_type2 > d->engine_type2 ? 1 : -1; + } + else { + if (c->parent_idx != d->parent_idx) + return c->parent_idx - d->parent_idx; + else + { + if (c->obj_type != d->obj_type) + return c->obj_type - d->obj_type; + else + { + if (c->number_row != d->number_row) + return c->number_row - d->number_row; + else + { + return c->top_y > d->top_y ? 1 : -1; + } + } + } + } + } +} +#if 0 +int sort_detection_pos_USA(const void *a, const void *b) +{ + detection_pos *c = (detection_pos *)a; + detection_pos *d = (detection_pos *)b; + + if (c->engine_type != d->engine_type) + return c->engine_type > d->engine_type ? 1 : -1; + else + { + if (c->engine_type2 != d->engine_type2) + { + return c->engine_type2 > d->engine_type2 ? 1 : -1; + } + else { + if (c->parent_idx != d->parent_idx) + return c->parent_idx - d->parent_idx; + else + { + if (c->obj_type != d->obj_type) + return c->obj_type - d->obj_type; + else + { + //if (c->number_row != d->number_row) + // return c->number_row - d->number_row; + //else + //{ + if (c->visual_left_x != d->visual_left_x) + return c->visual_left_x - d->visual_left_x; + else + { + return c->left_x > d->left_x ? 1 : -1; + } + //} + } + } + } + } +} +#else +int sort_detection_pos_USA(const void *a, const void *b) +{ + detection_pos *c = (detection_pos *)a; + detection_pos *d = (detection_pos *)b; + + if (c->engine_type != d->engine_type) + return c->engine_type > d->engine_type ? 1 : -1; + else + { + if (c->engine_type2 != d->engine_type2) + { + return c->engine_type2 > d->engine_type2 ? 1 : -1; + } + else { + if (c->parent_idx != d->parent_idx) + return c->parent_idx - d->parent_idx; + else + { + if (c->obj_type != d->obj_type) + return c->obj_type - d->obj_type; + else + { + //if (c->number_row != d->number_row) + // return c->number_row - d->number_row; + //else + //{ +#if 0 + if (c->visual_left_x != d->visual_left_x) + return c->visual_left_x - d->visual_left_x; + else + { + return c->left_x > d->left_x ? 1 : -1; + } +#endif + +#if 1 + ///sort x & y + if (c->visual_left_x != d->visual_left_x) + return c->visual_left_x - d->visual_left_x; + else + { + //if delta(X_c,X_d) > W_c or W_d + if (abs(c->visual_left_x - d->visual_left_x) > c->width) + { + return c->left_x > d->left_x ? 1 : -1; + } + else + { + return c->top_y > d->top_y ? 1 : -1; + } + } +#endif + //} + } + } + } + } +} +#endif + +int sort_record_plate(const void *a, const void *b) +{ + PlateRecoder *c = (PlateRecoder *)a; + PlateRecoder *d = (PlateRecoder *)b; + + if (c->iIfUse != d->iIfUse) + return c->iIfUse > d->iIfUse ? -1 : 1; + else if (c->iIfUse == 1) + return -1; + else + { + return c->existing_dash > d->existing_dash ? -1 : 1; + } +} + +int sort_record_object(const void *a, const void *b) +{ + ObjectRecoder *c = (ObjectRecoder *)a; + ObjectRecoder *d = (ObjectRecoder *)b; + + if (c->iIfUse != d->iIfUse) + return c->iIfUse > d->iIfUse ? -1 : 1; + else if (c->iIfUse == 1) + return -1; + else + return 1; + +} + +int sort_record_post(const void *a, const void *b) +{ + PostRecoder *c = (PostRecoder *)a; + PostRecoder *d = (PostRecoder *)b; + + if (c->iIfUse != d->iIfUse) + return c->iIfUse > d->iIfUse ? -1 : 1; + else if (c->iIfUse == 1) + return -1; + else + return 1; + +} + +int get_g_ori_yuv_width() { + return g_ori_yuv_width; +} +int get_g_ori_yuv_height() { + return g_ori_yuv_height; +} + +unsigned int get_frame_id() { + return frame_id; +} +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int get_g_check_if_differ_image_is_running() { + return g_check_if_differ_image_is_running; +} +#endif +int get_live_mode_flag() { + return live_mode_flag; +} + +int get_g_counter_index_post() { + return g_counter_index_post; +} + +int get_g_counter_index_long() { + return g_counter_index_long; +} + +void set_desc_and_name_for_cloud(unsigned int trigger_type_int,char *temp_desc_cloud,char *temp_name_cloud) +{ + if ((trigger_type_int & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\xa6\x81\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac\x2c");//Tϰ UTF8 Encoder + else//en_gb + strcat(temp_desc_cloud, "Prohibit zone,");//Tϰ UTF8 Encoder + strcat(temp_name_cloud, "TRIGGER_ZONE_VIOLATION,"); + } + + if ((trigger_type_int & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe8\xb7\x9d\xe9\x9b\xa2\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\xb5\xe6\xb8\xac\x2c");//ZHW UTF8 Encoder + else//en_gb + strcat(temp_desc_cloud, "Distance violation,");//ZHW UTF8 Encoder + strcat(temp_name_cloud, "TRIGGER_DISTANCE_VIOLATION,"); + } + + if ((trigger_type_int & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe9\xab\x98\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac\x2c");//װ UTF8 Encoder + else//en_gb + strcat(temp_desc_cloud, "Height detection,");//װ UTF8 Encoder + strcat(temp_name_cloud, "TRIGGER_HIGH_VIOLATION,"); + } + + if ((trigger_type_int & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe4\xb8\x8d\xe7\xa6\xae\xe8\xae\x93\xe5\x81\xb5\xe6\xb8\xac\x2c");//§ UTF8 Encoder + else//en_gb + strcat(temp_desc_cloud, "Forget to give way detection,");//§ UTF8 Encoder + strcat(temp_name_cloud, "TRIGGER_FORGET_TO_GIVE_WAY,"); + } + + + if ((trigger_type_int & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe6\x9c\x80\xe5\xa4\xa7\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac\x2c");//̤jtװ UTF8 Encoder + else//en_gb + strcat(temp_desc_cloud, "Max speed detection,");//̤jtװ UTF8 Encoder + strcpy(temp_name_cloud, "TRIGGER_SPEED_HIGH,"); + } + + if ((trigger_type_int & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe6\x9c\x80\xe4\xbd\x8e\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac\x2c");//̧Ctװ UTF8 Encoder + else//en_gb + strcat(temp_desc_cloud, "Min speed detection,");//̧Ctװ UTF8 Encoder + strcpy(temp_name_cloud, "TRIGGER_SPEED_LOW,"); + } + + if ((trigger_type_int & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\xa6\x81\xe5\x8d\x80\xe9\x99\x90\xe6\x99\x82\xe5\x81\xb5\xe6\xb8\xac\x20\x2f\x20\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\x9c\xe8\xbb\x8a\x2c");//Tϭɰ / HW + else//en_gb + strcat(temp_desc_cloud, "Zone with dwell / Parking violation,");//Tϭɰ / HW + strcat(temp_name_cloud, "TRIGGER_PARKING_VIOLATION,"); + } + if ((trigger_type_int & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\x9b\xb4\xe8\xa1\x8c\xe5\x81\xb5\xe6\xb8\xac\x2c");//ĵٽu / 氻 + else//en_gb + strcat(temp_desc_cloud, "Tripwire / Traffic flow,");//ĵٽu / 氻 + strcat(temp_name_cloud, "TRIGGER_GO_STRAIGHT,"); + } + if ((trigger_type_int & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\xb4\x85\xe7\x87\x88\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\xb4\x85\xe7\x87\x88\xe7\x9b\xb4\xe8\xa1\x8c\x2c");//Oĵٽu / O + else//en_gb + strcat(temp_desc_cloud, "Tripwire on red / Running red lights,");//Oĵٽu / O + strcat(temp_name_cloud, "TRIGGER_GO_STRAIGHT_RED_LIGHT,"); + } + if ((trigger_type_int & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\xb4\x85\xe7\x87\x88\xe5\xb7\xa6\xe8\xbd\x89\x2c");//O + else//en_gb + strcat(temp_desc_cloud, "Turning left on red,");//O + strcat(temp_name_cloud, "TRIGGER_TURN_LEFT_RED_LIGHT,"); + } + if ((trigger_type_int & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\xb4\x85\xe7\x87\x88\xe5\x8f\xb3\xe8\xbd\x89\x2c");//Ok + else//en_gb + strcat(temp_desc_cloud, "Turning right on red,");//Ok + strcat(temp_name_cloud, "TRIGGER_TURN_RIGHT_RED_LIGHT,"); + } + if ((trigger_type_int & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe5\xb7\xa6\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac\x2c");//఻ + else//en_gb + strcat(temp_desc_cloud, "Turn left,");//఻ + strcat(temp_name_cloud, "TRIGGER_TURN_LEFT,"); + } + if ((trigger_type_int & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe5\x8f\xb3\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac\x2c");//k఻ + else//en_gb + strcat(temp_desc_cloud, "Turn right,");//k఻ + strcat(temp_name_cloud, "TRIGGER_TURN_RIGHT,"); + } + if ((trigger_type_int & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\x99\xbd\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac\x2c");//զWĵٰϰ + else//en_gb + strcat(temp_desc_cloud, "LPR allowed list detection in zone,");//զWĵٰϰ + strcat(temp_name_cloud, "TRIGGER_ALLOW_LIST,"); + } + if ((trigger_type_int & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe9\xbb\x91\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac\x2c");//¦Wĵٰϰ + else//en_gb + strcat(temp_desc_cloud, "LPR denial list detection in zone,");//¦Wĵٰϰ + strcat(temp_name_cloud, "TRIGGER_BLOCK_LIST,"); + } + if ((trigger_type_int & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe8\xa8\xaa\xe5\xae\xa2\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac\x2c");//XȦWĵٰϰ + else//en_gb + strcat(temp_desc_cloud, "LPR visitor list detection in zone,");//XȦWĵٰϰ + strcat(temp_name_cloud, "TRIGGER_GUEST_LIST,"); + } + if ((trigger_type_int & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe5\xaf\x86\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac\x2c");//Kװ + else//en_gb + strcat(temp_desc_cloud, "Density detection,");//Kװ + strcat(temp_name_cloud, "TRIGGER_QUEUING_VIOLATION,"); + } + if ((trigger_type_int & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\x41\x49\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac\x2c");//AI򥢪 + else//en_gb + strcat(temp_desc_cloud, "AI missing object detection,");//AI򥢪 + strcat(temp_name_cloud, "TRIGGER_MISSING_OBJECT_DETECTION,"); + } + if ((trigger_type_int & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x8f\x8a\xe9\x81\xba\xe7\x95\x99\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac\x2c");//򥢪οd + else//en_gb + strcat(temp_desc_cloud, "Unattended or missing object,");//򥢪οd + strcat(temp_name_cloud, "TRIGGER_MISSING_UNATTENDED,"); + } + if ((trigger_type_int & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe9\x98\xb2\xe7\xa0\xb4\xe5\xa3\x9e\xe5\x81\xb5\xe6\xb8\xac\x2c");//}a + else//en_gb + strcat(temp_desc_cloud, "Tampering detection,");//}a + strcat(temp_name_cloud, "TRIGGER_TAMPERING,"); + } + if ((trigger_type_int & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x41\x4e\x44\x29\x2c");//ئPɦsb (AND) + else//en_gb + strcat(temp_desc_cloud, "All objects detection (AND),");//ئPɦsb (AND) + strcat(temp_name_cloud, "TRIGGER_ALL_OBJECTS,"); + } + if ((trigger_type_int & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe7\xbc\xba\xe5\xb0\x91\xe4\xbb\xbb\xe4\xb8\x80\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x4e\x41\x4e\x44\x29\x2c");//ʤ֥@ئPɦsb (NAND) + else//en_gb + strcat(temp_desc_cloud, "Lack of any object detection (NAND),");//ʤ֥@ئPɦsb (NAND) + strcat(temp_name_cloud, "TRIGGER_LACK_OF_ANY_OBJECT,"); + } + /* + else if (trigger_type_int & TRIGGER_BG_LEARNING) { + if (strcmp(SystemSetting.language, "zh_tw") == 0) + strcat(temp_desc_cloud, "\xe5\xad\xb8\xe7\xbf\x92\xe8\x83\x8c\xe6\x99\xaf\xe4\xb8\xad");//Dz߭I + else//en_gb + strcat(temp_desc_cloud, "BG learning");//Dz߭I + strcat(temp_name_cloud, "TRIGGER_BG_LEARNING"); + }*/ + + //h̫@ӳrI + if (trigger_type_int >= 1) { + temp_desc_cloud[strlen(temp_desc_cloud) - 1] = '\0'; + temp_name_cloud[strlen(temp_name_cloud) - 1] = '\0'; + } +} diff --git a/src/test_nnctrl_live.h b/src/test_nnctrl_live.h new file mode 100644 index 0000000..81bcfe4 --- /dev/null +++ b/src/test_nnctrl_live.h @@ -0,0 +1,570 @@ +#pragma once +#ifndef TEST_NNCTRL_LIVE_H +#define TEST_NNCTRL_LIVE_H + +#include "define_inc.h" +#include "network.h" +#include "cryptionPlus.h" +#include "nweb.h" +#include "lib_data_process.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> +#include <getopt.h> +#include <sched.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <sys/prctl.h> +#include <time.h> +#include <arpa/inet.h> +#include <assert.h> +#include <netdb.h> +#include <netinet/in.h> +#include <signal.h> +#include <stdint.h> +#include <math.h> + +#include <dirent.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifdef GY_OS_AMBA +#include "iav_ioctl.h" +#include "cavalry_gen.h" +#include "cavalry_ioctl.h" +#include "cavalry_mem.h" +#endif +#include "nnctrl.h" +#ifdef GY_OS_AMBA +#include "vproc.h" +#endif +#include "nnctrl_live_utils.h" + +//#include "lib_smartfb.h" +#include "utility.h" +#include "cJSON.h" +#include "ColorDetectorC.h" + +#include "darknet.h" + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include "fflpr_plate_db.h" +#endif +#ifdef GY_OS_AMBA +//#include "face_parser.h" +//#include "face_db.h" + +#include "ptz.h" +#endif +#include "cold_zone.h" +#include "pns.h" + +#include <linux/fb.h> + +#include "opencv2/core/core_c.h" +#include "fork_pipe_lib.h" +#include "ivsC.h" + +#include "cv_point_transform.hpp" +#ifdef GY_OS_AMBA +#include "send_osd_data.h" +#endif +#include "levenshtein.h" +#ifdef GY_OS_AMBA +//#include "tof.h" +#endif +#include "onvif_data.h" +#ifdef GY_OS_NOVA +#include "bbox_receive.h" +#endif +#define MAX_NET_NUM (4) //16 +#define MAX_PLATE_BUF_NUM (15) //MAX_PLATE_BUF_NUM + +#ifdef GY_OS_AMBA +#define MAX_OBJECT_NUM (36) //MAX_OBJECT_NUM +#define MAX_FACE_NUM (20) //MAX_FACE_NUM // max face num need to be confirmed - leo +#else +#define MAX_OBJECT_NUM (25) //MAX_OBJECT_NUM 36 +#endif + +#define FILENAME_LENGTH (256) + +#ifndef ROUND_UP +#define ROUND_UP(size, align) (((size) + ((align)-1)) & ~((align)-1)) +#endif +#define FIX8_MIN_ACCURACY 0.00390625f + +//#define LILIN_SHOW_FPS +#define MAX_CLASS_NUM (1024) +#define ROUND_UP_32(x) ((x)&0x1f ? (((x)&0xffffffe0) + 32) : (x)) + +#define CLASSNAME_LENGTH (256) +#define PATH_COUNT_SLASH (7) +#define MAX_FLOAT_VALUE_NUM (32) + +//#define ROUND_UP_32(x) ((x)&0x1f ? (((x)&0xffffffe0) + 32) : (x)) + +#define GET_AI_FPS_SEC (5) +#define GET_AI_FRAME_COUNTER (21) +#define GET_CPU_LOADING_SEC (10) +#define WRITE_CONFIG_FILE (10) + +struct cv_mem { + void *virt; + unsigned long phys; + unsigned long size; +}; + +struct io_match { + uint32_t load_input : 1; + uint32_t store_output : 1; + uint32_t no_mem : 1; + uint32_t crc_inited : 1; + uint32_t out_stored : 1; + uint32_t rotate_flip_bitmap : 5; + uint32_t reserved_0 : 29; + + uint32_t crc_result; + + uint8_t *virt_addr; + uint32_t dram_addr; + uint32_t dram_size; + uint32_t data_size; + + struct io_dim dim; + struct io_data_fmt data_fmt; + + char port_name[CAVALRY_IO_NAME_MAX]; + char file_name[FILENAME_LENGTH]; +}; + +struct net_match{ + uint32_t verbose : 1; /* nerual network verbose */ + uint32_t reuse_mem : 1; + uint32_t query_dvi : 1; + uint32_t dump_en : 1; + uint32_t print_time : 1; + uint32_t have_no_mem_io : 1; + uint32_t reserved_0 : 29; + + uint32_t net_id; + int iter_num; + uint32_t query_dvi_id; + char net_name[FILENAME_LENGTH]; + char path_dump[FILENAME_LENGTH]; + + struct net_run_cfg net_rev; + + uint32_t net_bw_sz; /* Total size */ + uint32_t net_bw_us; /* VP time, unit: us */ + struct net_mem net_m; // uint8_t* virt_addr, uint32_t phy_addr, uint32_t mem_size + + uint32_t in_num; + uint32_t out_num; + struct io_match in_pair[MAX_IO_NUM]; + struct io_match out_pair[MAX_IO_NUM]; + + struct net_cfg net_cf; + struct net_input_cfg net_in; + struct net_output_cfg net_out; + struct net_result net_ret; + + + ///dproc + dproc_run_yolov3_output_param_t *yolov3_param; + dproc_run_param_t run_yolov3_param; + uint32_t yolov3_result_num; + uint32_t feature_map_size[AMBA_YOLOV3_FEATURE_NUM]; + dproc_yolov3_output_result_t *amba_yolov3_result; + dproc_bbox_param_t *objects; + struct net_out_bin_desc out_bin; + //float *f_socket_data; //w~ + //char *parse_buffer; //w~ + uint32_t objects_id[MAX_DETECT_OBJECTS]; + uint32_t feature_map_offset; + + uint32_t valid_result_num; + + int total_cls; + + float anchors[YOLOV3_ANCHOR_NUM]; + char classNames[MAX_CLASS_NUM][CLASSNAME_LENGTH]; + + int is_netoutbindesc_initial; //sophia add 20201021 + int input_bin_num; //sophia add 20201127 each net has own input_bin_num, depends on weight is tiny or none tiny. +}; + +struct nnctrl_param { + int fd_cav; + + uint32_t verbose : 1; /* nnctrl library verbose */ + uint32_t all_cache_en : 1; /* 0: nocached; 1: cached */ + uint32_t all_check_md5 : 1; + uint32_t all_print_time : 1; + uint32_t all_early_quit : 1; + uint32_t all_run_loop : 1; + uint32_t all_single_run_dag : 1; + uint32_t reserved_0 : 25; + + uint32_t show_version_flag : 1; + uint32_t early_quit_flag : 1; + uint32_t ck_bw_flag : 1; + uint32_t reserved_1 : 29; + + uint32_t cache_en : 1; /* 0: nocached; 1: cached */ + + //enum run_mode mode; + uint32_t all_inter_num; + + uint32_t net_num; + struct net_match net_pair[MAX_NET_NUM]; + struct net_mem ext_mem[MAX_NET_NUM]; + uint32_t valid_net[MAX_NET_NUM]; //check if net name is null; + +}; + +enum numeric_short_options { + INPUT, + OUTPUT, +}; + +typedef struct +{ + int left; + int right; + int low; + int high; + int id; + float prob; +} object_t; + +extern int unlockingKeyInnoFR_success; +extern int unlockingKeyInnoFR; + +extern int g_framesize_width; +extern int g_framesize_height; + +//extern struct amba_content stAMBAcontent; + +extern float confidence_limit; +#ifdef GY_OS_NOVA +extern pthread_mutex_t mutex_parse_bbox; +#endif +extern pthread_mutex_t mutex_getalarmmotion; +extern pthread_mutex_t mutex_alm; +//extern pthread_mutex_t mutex_alarm_queue; //getalarmmotion|D +extern pthread_mutex_t mutex_enable_lpr_db; +extern pthread_mutex_t mutex_run_one_net; +#ifdef GY_OS_NOVA +//extern pthread_mutex_t mutex_run_parse_json; +#endif +//extern pthread_mutex_t mutex_cropped_roi; +extern pthread_mutex_t mutex_if_enable_lpr_db_is_Yes; +extern pthread_mutex_t mutex_get_network_input; +extern pthread_mutex_t mutex_differ_image; +extern pthread_mutex_t mutex_run_one_net_anpr; +//extern pthread_mutex_t mutex_snap_hd_image; +extern pthread_mutex_t mutex_get_image; +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_get_image_HD; +extern pthread_mutex_t mutex_enable_face_db; // face - leo + +extern pthread_mutex_t mutex_send_jpeg; +//extern pthread_mutex_t mutex_get_canvas; +#endif +extern pthread_mutex_t mutex_heatmap_jpeg; +#ifdef GY_OS_AMBA +extern pthread_mutex_t mutex_run_osd; +#endif + +extern pthread_mutex_t mutex_read_ipcam; +extern pthread_mutex_t mutex_compute_median; + +extern int switch_g_image_buff_ori; +extern char g_image_buff_ori[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE]; +extern int g_image_buff_size_ori[MAX_NUM_IMAGE_BUFF]; +extern char g_image_state_response_ori[256]; +extern long g_post_SysTimeStamp_ori[MAX_NUM_IMAGE_BUFF]; +#ifdef GY_OS_AMBA +extern char g_image_buff_HD[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE_HD]; +extern int g_image_buff_size_HD[MAX_NUM_IMAGE_BUFF]; +extern char g_image_state_response[256]; +#endif +extern char g_current_snapshot_addr_base64[MAX_IMG_SIZE]; +extern int g_current_snapshot_size_base64; + +extern long g_image_HD_pasue_time; +extern int g_video_start_HD; + +extern int g_dual_sensor; + +extern SocketInfo socketRecords[MAX_CLIENT_SOCKET]; +extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; +extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; +extern SystemSettingInfo SystemSetting; +extern PostEventInfo postEventList[MAX_POST_EVENTS]; +#ifdef GY_OS_V_SERIES +#else +extern EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS]; +extern ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS]; +extern SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT]; +#endif +extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add +extern IPCAMServiceInfo IPCAMService; +#ifdef GY_OS_AMBA +extern SnapHDInfo snapHDList[MAX_SNAP_HD_LIST]; +extern WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST]; +#endif +extern char WeightFileModeName[35]; +//extern EmailInfo emailData; +extern HeartbeatInfo heartbeatData; +#ifdef GY_OS_AMBA +extern TofInfo tofData; +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +extern PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER]; +#endif +extern ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER]; +extern PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE]; +extern PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE]; + +//extern MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA]; + +extern ImageDn imageDnData; + +extern int g_check_if_metadata_stop_happened[MAX_DETECTION_ZONE]; +#ifdef GY_OS_NOVA +extern RecvBbox g_current_bbox_list[MAX_TRACKING_NUM]; +extern int g_res_height; +extern int g_res_width; +extern int g_count_bbox_list; +#endif +extern int g_bMacMatch; +extern time_t g_start_time, g_end_time; +extern char g_filename_TLT[1024]; +extern int g_li, g_ad; + +void stop_test_nn_cavalry(char* note_stop); +#ifdef GY_OS_NOVA +void* nnctrl_main(void *ptr); +#endif + +#ifdef GY_OS_NOVA +extern int AI_fps2; +#endif + +#ifdef GY_OS_AMBA +extern int g_check_if_OK_to_start_osd_server; + +extern int g_current_max_num_image_buff; + +extern char g_debug_plate[BUFSIZE_V2]; +extern char global_radar_response[BUFSIZE_V3]; + +// Ken 10-28 +extern float g_radar_img_width; +extern float g_radar_img_height; + +// Ken 11-01 +extern pthread_mutex_t mutex_radar_render; + +extern char global_radar_response[BUFSIZE_V3]; +// Ken 10-28 +extern float g_radar_img_width; +extern float g_radar_img_height; + +// Ken 11-01 +extern pthread_mutex_t mutex_radar_render; +extern int g_IsRadarFake; +#endif + +//extern int g_check_if_set_no_preset_no_autopan; +#ifdef GY_OS_AMBA +void *get_loading(); + +void free_all_cv_mem(struct nnctrl_param *pctrl); + +void* test_nn_main(void *ptr); +int init_anchor_file(char* anchor_file, float* anchor, uint32_t tiny_enable); +int init_amba_yolov3(dproc_yolov3_output_result_t** amba_yolov3_result, uint32_t net_idx, uint32_t total_cls, float* panchors, int tiny_enable); +#endif +void assign_row_number(detection_pos* PosInfo, detection_pos* pNext1, detection_pos* pNext2, int total_element_size, int element_size2, int parent_idx, float* arc); +void linear_regression(detection_pos** p, int pointCount, double* a, double* b); +extern int SortObjects(detection_pos* PosInfo, int total_element_size); +void SetCorrectClassID(detection_pos *PosInfo, int total_element_size, int element_size1); +int IsMatchAUSPattern(char* PlatePattern, char* area); +int IsMatchGBRPattern(char* PlatePattern, char* area); +int IsMatchIDNPattern(char* PlatePattern, char* area); +int PlatePatternParser(detection_pos* PosInfo, int total_element_size, size_t featureType/*, float arc*/); + +void set_enable_downsized_cropped_roi(int temp_enable_downsized_cropped_roi); +int get_enable_downsized_cropped_roi(); +void set_enable_zone_crop_1(int temp_enable_zone_crop_1); +int get_enable_zone_crop_1(); + +extern void AssignPlateNumber(detection_pos* PosInfo, int total_element_size, int featureType); +extern void ReplaceWithUTF8(detection_pos* PosInfo, int total_element_size); + +extern int check_if_enable_trigger_go_straight; + +extern int g_enable_person_for_metadata[MAX_DETECTION_ZONE]; + +int get_free_mem_data(); +//int get_total_mem_data(); + +int get_g_check_if_show_parking(); + +void *run_fps_loading_thread(void *ptr); + +void *run_one_net_thread(void *ptr); +#ifdef GY_OS_V_SERIES + +#else +void *run_one_net_thread_anpr(void *ptr); +#endif + + +void *differ_image_thread(void *ptr); +#if defined GY_OS_AMBA +void *compute_median_thread(void *ptr); +#endif +#ifdef GY_OS_AMBA +unsigned long get_ori_c_image(char *c_image); +#endif +//void *get_network_input_thread(void *ptr); + +#if 1 +void use_sleep_to_adjust_sync_or_async(int tracking_channel_idx); +#endif +#ifdef GY_OS_AMBA +void unlink_lilin_weight(); +#endif +int init_param(void *ptr); +#ifdef GY_OS_AMBA +int check_dsp_state(void); +int map_dsp_buffer(int state); +#endif +#if 1 +int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAcontent); +#endif + +void clear_PostRecorderList(); +void minus_count_trigger(); + +#if 1 +int sort_detection_pos(const void *a, const void *b); +int sort_detection_pos_CNT(const void *a, const void *b); +int sort_detection_pos_USA(const void *a, const void *b); + +int sort_record_plate(const void *a, const void *b); +int sort_record_object(const void *a, const void *b); +int sort_record_post(const void *a, const void *b); +void snap_hd_image(); + +int get_g_ori_yuv_width(); +int get_g_ori_yuv_height(); + +void sync_cache_mem(unsigned long size, unsigned long phys, uint8_t clean, uint8_t invalid); + +void clean_output_mem(struct net_match* pnet); +void invalid_output_mem(struct net_match *pnet); +void clean_output_padding(struct net_match *pnet); +#ifdef GY_OS_AMBA +int process_output_mem(struct net_match *pnet); +#endif +int get_check_first_downsized_cropped_roi_for_object(); +int get_g_check_if_all_existing(size_t index_zone); + +int get_g_check_if_NAND(size_t index_zone); +void reset_g_Meta_If_Existing_for_NAND(size_t index_zone); +unsigned int get_frame_id(); + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +int get_g_check_if_differ_image_is_running(); +#endif +#ifdef GY_OS_AMBA +void set_change_status_for_not_AutoTracking_to_zero(); +#endif +int get_live_mode_flag(); + +int get_g_check_if_current_light_is_red(); + +#ifdef GY_OS_AMBA +//int read_bin(char *fileDir, unsigned char *addr); +int store_bin(char *file, int size, void *addr); +#endif + +extern int bHttpServerMainStart; +extern int bHttpServerThreadStart; + +extern int check_if_start_run_server; + +extern char g_device_name[512]; + +CPoint segmentsIntr(CPoint a, CPoint b, CPoint c, CPoint d); +void build_g_parking_space_recording(int tracking_channel_idx, int index_zone); + +extern int g_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE]; +extern int g_temp_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE]; +extern float g_parking_space_recording_x[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE]; +extern float g_parking_space_recording_y[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE]; +extern time_t g_parking_space_update_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE]; +extern time_t g_parking_space_status_change_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE]; + +extern float g_thres_bbox_stability; + +extern int g_IsPTZDevice; +extern long g_osdSysTimeStamp; +extern int g_check_if_OK_thermal; + +#ifdef GY_OS_NOVA +extern int g_check_if_run_parse_json_data_from_bbox_receive; +#endif + + +#ifdef GY_OS_AMBA +//extern frameimage *tof_raw_arr; +#endif + +float get_nms_thres(float nms_threshold); +void set_metadata(); +int check_if_existing_in_metaout(char *object_name, int index_zone); +int check_if_existing_in_metaout_not_plate(char *object_name, int index_zone); +int get_metadata1_num(int index_zone); +int person_if_existing_in_metaout(int index_zone); +char* get_meta_class(int index_meta, int index_zone); + +int check_if_object_in_ivs_zone(float obj_center_x, float obj_center_y, float obj_width, float obj_height, int image_width, int image_height, int enable_only_center); +int check_if_object_in_zone(float obj_center_x, float obj_center_y, float obj_width, float obj_height, int image_width, int image_height, int enable_only_center); +int check_if_object_in_zone_simple_version(detection_pos* pNext, int index_zone); +int check_if_object_in_zone_simple_version_not_plate(detection_pos* pNext, int index_zone); +int check_if_object_in_zone_width_zone(float obj_center_x, float obj_center_y, float obj_width, float obj_height, int image_width, int image_height, int enable_only_center, int index_zone); + +void set_desc_and_name_for_cloud(unsigned int trigger_type_int, char *temp_desc_cloud, char *temp_name_cloud); + +#ifdef GY_OS_AMBA +void cropped_roi(detection_pos *pNext_plate, struct net_match *net_pair_orc, int current_index, char* snapshot_addr, size_t snapshot_size); +void cropped_roi_ivs(detection_pos *pNext_plate, struct net_match *net_pair_orc, int current_index, char* snapshot_addr, size_t snapshot_size); +#endif + +void run_ptz_server(); + +int get_g_counter_index_post(); +int get_g_counter_index_long(); + +int get_try_once_ptz(); + +#endif +#endif \ No newline at end of file diff --git a/src/test_yuv_rgb.c b/src/test_yuv_rgb.c new file mode 100644 index 0000000..8601be2 --- /dev/null +++ b/src/test_yuv_rgb.c @@ -0,0 +1,625 @@ +// Copyright 2016 Adrien Descamps +// Distributed under BSD 3-Clause License + +// This program demonstrate how to convert a YUV420p image (raw format) to RGB (ppm format), and the reverse operation + +#include "yuv_rgb.h" +#include "test_yuv_rgb.h" + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +//#include <x86intrin.h> + +#if USE_FFMPEG +#include <libswscale/swscale.h> +#endif +#if USE_IPP +#include <ippcc.h> +#endif + +// read a raw yuv image file +// raw yuv files can be generated by ffmpeg, for example, using : +// ffmpeg -i test.png -c:v rawvideo -pix_fmt yuv420p test.yuv +// the returned image channels are contiguous, and Y stride=width, U and V stride=width/2 +// memory must be freed with free +int readRawYUV(const char *filename, uint32_t width, uint32_t height, uint8_t **YUV) +{ + FILE *fp = fopen(filename, "rb"); + if(!fp) + { + perror("Error opening yuv image for read"); + return 1; + } + + // check file size + fseek(fp, 0, SEEK_END); + uint32_t size = ftell(fp); + if(size!=(width*height + 2*((width+1)/2)*((height+1)/2))) + { + fprintf(stderr, "Wrong size of yuv image : %d bytes, expected %d bytes\n", size, (width*height + 2*((width+1)/2)*((height+1)/2))); + fclose(fp); + return 2; + } + fseek(fp, 0, SEEK_SET); + + *YUV = malloc(size); + size_t result = fread(*YUV, 1, size, fp); + if (result != size) { + perror("Error reading yuv image"); + fclose(fp); + return 3; + } + fclose(fp); + return 0; +} + +// write a raw yuv image file +int saveRawYUV(const char *filename, uint32_t width, uint32_t height, const uint8_t *YUV, size_t y_stride, size_t uv_stride) +{ + FILE *fp = fopen(filename, "wb"); + if(!fp) + { + perror("Error opening yuv image for write"); + return 1; + } + + if(y_stride==width) + { + fwrite(YUV, 1, width*height, fp); + YUV+=width*height; + } + else + { + for(uint32_t y=0; y<height; ++y) + { + fwrite(YUV, 1, width, fp); + YUV+=y_stride; + } + } + + + if(uv_stride==(width+1/2)) + { + fwrite(YUV, 1, ((width+1)/2)*((height+1)/2)*2, fp); + } + else + { + for(uint32_t y=0; y<((height+1)/2); ++y) + { + fwrite(YUV, 1, ((width+1)/2), fp); + YUV+=uv_stride; + } + + for(uint32_t y=0; y<((height+1)/2); ++y) + { + fwrite(YUV, 1, ((width+1)/2), fp); + YUV+=uv_stride; + } + } + + fclose(fp); + return 0; +} + +// read a ppm binary image file +// memory must be freed with free +int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **RGB) +{ + FILE *fp = fopen(filename, "rb"); + if(!fp) + { + perror("Error opening rgb image for read"); + return 1; + } + + char magic[3]; + size_t result = fread(magic, 1, 2, fp); + magic[2]='\0'; + if(result!=2 || strcmp(magic,"P6")!=0) + { + perror("Error reading rgb image header, or invalid format"); + fclose(fp); + return 3; + } + + uint32_t max; + result = fscanf(fp, " %u %u %u ", width, height, &max); + if(result!=3 || max>255) + { + perror("Error reading rgb image header, or invalid values"); + fclose(fp); + return 3; + } + + size_t size = 3*(*width)*(*height); + *RGB = malloc(size); + if(!*RGB) + { + perror("Error allocating rgb image memory"); + fclose(fp); + return 2; + } + + result = fread(*RGB, 1, size, fp); + if(result != size) + { + perror("Error reading rgb image"); + fclose(fp); + return 3; + } + + fclose(fp); + return 0; +} + +// save a rgb image to ppm binary format +int savePPM(const char* filename, uint32_t width, uint32_t height, const uint8_t *RGB, size_t stride) +{ + FILE *fp = fopen(filename, "wb"); + if(!fp) + { + perror("Error opening rgb image for write"); + return 1; + } + + fprintf(fp, "P6 %u %u 255\n", width, height); + if(stride==(3*width)) + { + fwrite(RGB, 1, 3*width*height, fp); + } + else + { + for(uint32_t i=0; i<height; ++i) + { + fwrite(RGB+i*stride, 1, 3*width, fp); + } + } + fclose(fp); + + return 0; +} + +void convert_rgb_to_rgba(const uint8_t *RGB, uint32_t width, uint32_t height, uint8_t **RGBA) +{ + *RGBA = malloc(4*width*height); + for(uint32_t y=0; y<height; ++y) + { + for(uint32_t x=0; x<width; ++x) + { + (*RGBA)[(y*width+x)*4] = RGB[(y*width+x)*3]; + (*RGBA)[(y*width+x)*4+1] = RGB[(y*width+x)*3+1]; + (*RGBA)[(y*width+x)*4+2] = RGB[(y*width+x)*3+2]; + (*RGBA)[(y*width+x)*4+3] = 0; + } + } +} + +typedef enum +{ + RGB2YUV, + YUV2RGB, + YUV2RGB_NV12, + YUV2RGB_NV21, + RGBA2YUV +} Mode; + +typedef void (*yuv2rgb_ptr)( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +typedef void (*yuvsp2rgb_ptr)( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +typedef void (*rgb2yuv_ptr)( + uint32_t width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + + +// call yuv2rgb conversion function, time it and save result +void test_yuv2rgb(uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type, + const char *file, const char *name, uint32_t iteration_number, const yuv2rgb_ptr yuv2rgb_fun) +{ + clock_t t = clock(); + for(uint32_t i=0;i<iteration_number; ++i) + yuv2rgb_fun(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type); + t = clock()-t; + printf("Processing time (%s) : %f sec\n", name, ((float)t)/CLOCKS_PER_SEC); + + char *out_filename = malloc(strlen(file)+strlen(name)+6); + strcpy(out_filename, file); + strcat(out_filename, "_"); + strcat(out_filename, name); + strcat(out_filename, ".ppm"); + savePPM(out_filename, width, height, rgb, rgb_stride); + free(out_filename); +} + +// call yuv2rgb semi planar conversion function, time it and save result +void test_yuvsp2rgb(uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, YCbCrType yuv_type, + const char *file, const char *name, uint32_t iteration_number, const yuvsp2rgb_ptr yuv2rgb_fun) +{ + clock_t t = clock(); + for(uint32_t i=0;i<iteration_number; ++i) + yuv2rgb_fun(width, height, y, uv, y_stride, uv_stride, rgb, rgb_stride, yuv_type); + t = clock()-t; + printf("Processing time (%s) : %f sec\n", name, ((float)t)/CLOCKS_PER_SEC); + + char *out_filename = malloc(strlen(file)+strlen(name)+6); + strcpy(out_filename, file); + strcat(out_filename, "_"); + strcat(out_filename, name); + strcat(out_filename, ".ppm"); + savePPM(out_filename, width, height, rgb, rgb_stride); + free(out_filename); +} + + +// call rgb2yuv conversion function, time it and save result +void test_rgb2yuv(uint32_t width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, YCbCrType yuv_type, + const char *file, const char *name, uint32_t iteration_number, const rgb2yuv_ptr rgb2yuv_fun) +{ + clock_t t = clock(); + for(uint32_t i=0;i<iteration_number; ++i) + rgb2yuv_fun(width, height, rgb, rgb_stride, y, u, v, y_stride, uv_stride, yuv_type); + t = clock()-t; + printf("Processing time (%s) : %f sec\n", name, ((float)t)/CLOCKS_PER_SEC); + + char *out_filename = malloc(strlen(file)+strlen(name)+6); + strcpy(out_filename, file); + strcat(out_filename, "_"); + strcat(out_filename, name); + strcat(out_filename, ".yuv"); + saveRawYUV(out_filename, width, height, y, y_stride, uv_stride); + free(out_filename); +} + +// equivalent conversion functions for external libraries + +#if USE_FFMPEG +static struct SwsContext *yuv2rgb_swscale_ctx = NULL; +static struct SwsContext *rgb2yuv_swscale_ctx = NULL; + +void yuv420_rgb24_ffmpeg(uint32_t __attribute__ ((unused)) width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType __attribute__ ((unused)) yuv_type) +{ + const uint8_t *const inData[3] = {y, u, v}; + int inLinesize[3] = {y_stride, uv_stride, uv_stride}; + int outLinesize[1] = {rgb_stride}; + sws_scale(yuv2rgb_swscale_ctx, inData, inLinesize, 0, height, &rgb, outLinesize); +} + +void rgb24_yuv420_ffmpeg(uint32_t __attribute__ ((unused)) width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType __attribute__ ((unused)) yuv_type) +{ + int inLineSize[1] = {rgb_stride}; + int outLineSize[3] = {y_stride, uv_stride, uv_stride}; + uint8_t *const outData[3] = {y, u, v}; + sws_scale(rgb2yuv_swscale_ctx, &rgb, inLineSize, 0, height, outData, outLineSize); +} +#endif + +#if USE_IPP +void yuv420_rgb24_ipp(uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType __attribute__ ((unused)) yuv_type) +{ + const Ipp8u* pSrc[3] = {y, u, v}; + int srcStep[3] = {y_stride, uv_stride, uv_stride}; + Ipp8u* pDst = rgb; + int dstStep = rgb_stride; + IppiSize imgSize = {.width=width, .height=height}; + ippiYCbCr420ToRGB_8u_P3C3R(pSrc, srcStep, pDst, dstStep, imgSize); +} + +void rgb24_yuv420_ipp(uint32_t width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType __attribute__ ((unused)) yuv_type) +{ + const Ipp8u* pSrc = rgb; + int srcStep = rgb_stride; + Ipp8u* pDst[3] = {y, u, v}; + int dstStep[3] = {y_stride, uv_stride, uv_stride}; + IppiSize imgSize = {.width=width, .height=height}; + ippiRGBToYCbCr420_8u_C3P3R(pSrc, srcStep, pDst, dstStep, imgSize); +} + +#endif + +#if 0 +int main(int argc, char **argv) +{ + if(argc<4) + { + printf("Usage : test yuv2rgb <yuv image file> <image width> <image height> <output template filename>\n"); + printf("Or : test yuv2rgb_nv12 <yuv image file> <image width> <image height> <output template filename>\n"); + printf("Or : test yuv2rgb_nv21 <yuv image file> <image width> <image height> <output template filename>\n"); + printf("Or : test rgb2yuv <rgb24 binary ppm image file> <output template filename>\n"); + printf("Or : test rgba2yuv <rgb24 binary ppm image file> <output template filename>\n"); + return 1; + } + + const int iteration_number = 100; + printf("Time will be measured in each configuration for %d iterations...\n", iteration_number); + const YCbCrType yuv_format = YCBCR_601; + //const YCbCrType yuv_format = YCBCR_709; + //const YCbCrType yuv_format = YCBCR_JPEG; + + Mode mode; + if(strcmp(argv[1], "yuv2rgb")==0) + { + mode=YUV2RGB; + if(argc<6) + { + printf("Invalid argument number for yuv2rgb mode, call without argument to see usage.\n"); + return 1; + } + } + else if(strcmp(argv[1], "yuv2rgb_nv12")==0) + { + mode=YUV2RGB_NV12; + } + else if(strcmp(argv[1], "yuv2rgb_nv21")==0) + { + mode=YUV2RGB_NV21; + } + else if(strcmp(argv[1], "rgb2yuv")==0) + { + mode=RGB2YUV; + } + else if(strcmp(argv[1], "rgba2yuv")==0) + { + mode=RGBA2YUV; + } + else + { + printf("Invalid mode, call without argument to see usage.\n"); + return 1; + } + + const char *filename = argv[2]; + uint32_t width, height; + const char *out; + uint8_t *YUV=NULL, *RGB=NULL, *Y=NULL, *U=NULL, *V=NULL, *RGBa=NULL, *YUVa=NULL, *Ya=NULL, *Ua=NULL, *Va=NULL; + + if(mode==YUV2RGB || mode==YUV2RGB_NV12 || mode==YUV2RGB_NV21) + { + //parse argument line + width = atoi(argv[3]); + height = atoi(argv[4]); + out = argv[5]; + + // read input data and allocate output data + if(readRawYUV(filename, width, height, &YUV)!=0) + { + printf("Error reading image file, check that the file exists and has the correct format and resolution.\n"); + return 1; + } + +#if USE_FFMPEG + yuv2rgb_swscale_ctx = sws_getContext(width, height, AV_PIX_FMT_YUV420P, width, height, AV_PIX_FMT_RGB24, 0, 0, 0, 0); +#endif + + RGB = malloc(3*width*height); + + Y = YUV; + U = YUV+width*height; + V = YUV+width*height+((width+1)/2)*((height+1)/2); + + // allocate aligned data + const size_t y_stride = width + (16-width%16)%16; + const size_t uv_stride = (mode==YUV2RGB) ? (width+1)/2 + (16-((width+1)/2)%16)%16 : y_stride; + const size_t rgb_stride = width*3 +(16-(3*width)%16)%16; + + const size_t y_size = y_stride*height, uv_size = uv_stride*((height+1)/2); + YUVa = _mm_malloc(y_size+2*uv_size, 16); + Ya = YUVa; + Ua = YUVa+y_size; + Va = YUVa+y_size+uv_size; + for(unsigned int i=0; i<height; ++i) + { + memcpy(Ya+i*y_stride, Y+i*width, width); + if((i%2)==0) + { + if(mode==YUV2RGB) + { + memcpy(Ua+(i/2)*uv_stride, U+(i/2)*((width+1)/2), (width+1)/2); + memcpy(Va+(i/2)*uv_stride, V+(i/2)*((width+1)/2), (width+1)/2); + } + else + { + memcpy(Ua+(i/2)*uv_stride, U+(i/2)*width, width); + } + } + } + + RGBa = _mm_malloc(rgb_stride*height, 16); + + // test all versions + if(mode==YUV2RGB) + { + test_yuv2rgb(width, height, Y, U, V, width, (width+1)/2, RGB, width*3, yuv_format, + out, "std", iteration_number, yuv420_rgb24_std); + test_yuv2rgb(width, height, Y, U, V, width, (width+1)/2, RGB, width*3, yuv_format, + out, "sse2_unaligned", iteration_number, yuv420_rgb24_sseu); +#if USE_FFMPEG + test_yuv2rgb(width, height, Y, U, V, width, (width+1)/2, RGB, width*3, yuv_format, + out, "ffmpeg_unaligned", iteration_number, yuv420_rgb24_ffmpeg); +#endif +#if USE_IPP + test_yuv2rgb(width, height, Y, U, V, width, (width+1)/2, RGB, width*3, yuv_format, + out, "ipp_unaligned", iteration_number, yuv420_rgb24_ipp); +#endif + test_yuv2rgb(width, height, Ya, Ua, Va, y_stride, uv_stride, RGBa, rgb_stride, yuv_format, + out, "sse2_aligned", iteration_number, yuv420_rgb24_sse); +#if USE_FFMPEG + test_yuv2rgb(width, height, Ya, Ua, Va, y_stride, uv_stride, RGBa, rgb_stride, yuv_format, + out, "ffmpeg_aligned", iteration_number, yuv420_rgb24_ffmpeg); +#endif +#if USE_IPP + test_yuv2rgb(width, height, Ya, Ua, Va, y_stride, uv_stride, RGBa, rgb_stride, yuv_format, + out, "ipp_aligned", iteration_number, yuv420_rgb24_ipp); +#endif + } + else if(mode==YUV2RGB_NV12) + { + test_yuvsp2rgb(width, height, Y, U, width, width, RGB, width*3, yuv_format, + out, "std", iteration_number, nv12_rgb24_std); + test_yuvsp2rgb(width, height, Y, U, width, width, RGB, width*3, yuv_format, + out, "sse2_unaligned", iteration_number, nv12_rgb24_sseu); + test_yuvsp2rgb(width, height, Ya, Ua, y_stride, uv_stride, RGBa, rgb_stride, yuv_format, + out, "sse2_aligned", iteration_number, nv12_rgb24_sse); + } + else if(mode==YUV2RGB_NV21) + { + test_yuvsp2rgb(width, height, Y, U, width, width, RGB, width*3, yuv_format, + out, "std", iteration_number, nv21_rgb24_std); + test_yuvsp2rgb(width, height, Y, U, width, width, RGB, width*3, yuv_format, + out, "sse2_unaligned", iteration_number, nv21_rgb24_sseu); + test_yuvsp2rgb(width, height, Ya, Ua, y_stride, uv_stride, RGBa, rgb_stride, yuv_format, + out, "sse2_aligned", iteration_number, nv21_rgb24_sse); + } + } + else if(mode==RGB2YUV) + { + //parse argument line + out = argv[3]; + + // read input data and allocate output data + if(readPPM(filename, &width, &height, &RGB)!=0) + { + printf("Error reading image file, check that the file exists and has the correct format.\n"); + return 1; + } + +#if USE_FFMPEG + rgb2yuv_swscale_ctx = sws_getContext(width, height, AV_PIX_FMT_RGB24, width, height, AV_PIX_FMT_YUV420P, 0, 0, 0, 0); +#endif + + YUV = malloc(width*height*3/2); + + Y = YUV; + U = YUV+width*height; + V = YUV+width*height+((width+1)/2)*((height+1)/2); + + // allocate aligned data + const size_t y_stride = width + (16-width%16)%16, + uv_stride = (width+1)/2 + (16-((width+1)/2)%16)%16, + rgb_stride = width*3 +(16-(3*width)%16)%16; + + RGBa = _mm_malloc(rgb_stride*height, 16); + for(unsigned int i=0; i<height; ++i) + { + memcpy(RGBa+i*rgb_stride, RGB+i*width*3, width*3); + } + + const size_t y_size = y_stride*height, uv_size = uv_stride*((height+1)/2); + YUVa = _mm_malloc(y_size+2*uv_size, 16); + Ya = YUVa; + Ua = YUVa+y_size; + Va = YUVa+y_size+uv_size; + + + // test all versions + test_rgb2yuv(width, height, RGB, width*3, Y, U, V, width, (width+1)/2, yuv_format, + out, "std", iteration_number, rgb24_yuv420_std); + test_rgb2yuv(width, height, RGB, width*3, Y, U, V, width, (width+1)/2, yuv_format, + out, "sse2_unaligned", iteration_number, rgb24_yuv420_sseu); +#if USE_FFMPEG + test_rgb2yuv(width, height, RGB, width*3, Y, U, V, width, (width+1)/2, yuv_format, + out, "ffmpeg_unaligned", iteration_number, rgb24_yuv420_ffmpeg); +#endif +#if USE_IPP + test_rgb2yuv(width, height, RGB, width*3, Y, U, V, width, (width+1)/2, yuv_format, + out, "ipp_unaligned", iteration_number, rgb24_yuv420_ipp); +#endif + test_rgb2yuv(width, height, RGBa, rgb_stride, Ya, Ua, Va, y_stride, uv_stride, yuv_format, + out, "sse2_aligned", iteration_number, rgb24_yuv420_sse); +#if USE_FFMPEG + test_rgb2yuv(width, height, RGBa, rgb_stride, Ya, Ua, Va, y_stride, uv_stride, yuv_format, + out, "ffmpeg_aligned", iteration_number, rgb24_yuv420_ffmpeg); +#endif +#if USE_IPP + test_rgb2yuv(width, height, RGBa, rgb_stride, Ya, Ua, Va, y_stride, uv_stride, yuv_format, + out, "ipp_aligned", iteration_number, rgb24_yuv420_ipp); +#endif + } + else if(mode==RGBA2YUV) + { + //parse argument line + out = argv[3]; + + // read input data and allocate output data + if(readPPM(filename, &width, &height, &RGB)!=0) + { + printf("Error reading image file, check that the file exists and has the correct format.\n"); + return 1; + } + // convert rgb to rgba + uint8_t *RGBA = NULL; + convert_rgb_to_rgba(RGB, width, height, &RGBA); + + YUV = malloc(width*height*3/2); + + Y = YUV; + U = YUV+width*height; + V = YUV+width*height+((width+1)/2)*((height+1)/2); + + // allocate aligned data + const size_t y_stride = width + (16-width%16)%16, + uv_stride = (width+1)/2 + (16-((width+1)/2)%16)%16, + rgba_stride = width*4 +(16-(4*width)%16)%16; + + RGBa = _mm_malloc(rgba_stride*height, 16); + for(unsigned int i=0; i<height; ++i) + { + memcpy(RGBa+i*rgba_stride, RGBA+i*width*4, width*4); + } + + const size_t y_size = y_stride*height, uv_size = uv_stride*((height+1)/2); + YUVa = _mm_malloc(y_size+2*uv_size, 16); + Ya = YUVa; + Ua = YUVa+y_size; + Va = YUVa+y_size+uv_size; + + // test all versions + test_rgb2yuv(width, height, RGBA, width*4, Y, U, V, width, (width+1)/2, yuv_format, + out, "std", iteration_number, rgb32_yuv420_std); + test_rgb2yuv(width, height, RGBA, width*4, Y, U, V, width, (width+1)/2, yuv_format, + out, "sse2_unaligned", iteration_number, rgb32_yuv420_sseu); + test_rgb2yuv(width, height, RGBa, rgba_stride, Ya, Ua, Va, y_stride, uv_stride, yuv_format, + out, "sse2_aligned", iteration_number, rgb32_yuv420_sse); + + free(RGBA); + } + + _mm_free(RGBa); + _mm_free(YUVa); + free(RGB); + free(YUV); + + return 0; +} +#endif diff --git a/src/test_yuv_rgb.h b/src/test_yuv_rgb.h new file mode 100644 index 0000000..1ab5f29 --- /dev/null +++ b/src/test_yuv_rgb.h @@ -0,0 +1,9 @@ +#pragma once +#ifndef TEST_YUV_RGB_H +#define TEST_YUV_RGB_H +#include "define_inc.h" +int readRawYUV(const char *filename, uint32_t width, uint32_t height, uint8_t **YUV); +int saveRawYUV(const char *filename, uint32_t width, uint32_t height, const uint8_t *YUV, size_t y_stride, size_t uv_stride); + + +#endif \ No newline at end of file diff --git a/src/text_insert.c b/src/text_insert.c new file mode 100644 index 0000000..6ea1545 --- /dev/null +++ b/src/text_insert.c @@ -0,0 +1,782 @@ +/******************************************************************************* + * text_insert.c + * + * History: + * 2011/02/25 - [Qian Shen] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include "ft2build.h" +#include "text_insert.h" + +#include FT_FREETYPE_H +#include FT_TRIGONOMETRY_H +#include FT_BITMAP_H +#include FT_STROKER_H + +#define FT_INTEGER_BIT (6) + +#ifndef FT_PIX_FLOOR +#define FT_PIX_FLOOR(x) ((x) & ~((1 << FT_INTEGER_BIT) - 1)) +#endif + +#ifndef FT_PIX_INT +#define FT_PIX_INT(x) ((x) >> FT_INTEGER_BIT) +#endif + +#ifndef MIN +#define MIN(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y);\ + _x < _y ? _x : _y; }) +#endif + +#ifndef MAX +#define MAX(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y);\ + _x > _y ? _x : _y; }) +#endif + +static font_attribute_t cfg_font; +static FT_Library library; +static FT_Face face; + +static int flag_init = 0; +static int flag_face = 0; +static pixel_type_t default_pixel_type = { + .pixel_background = 0, + .pixel_outline = 1, + .pixel_font = 255 +}; +pixel_type_t pixel_type; + +typedef struct span_s { + int x; + int y; + int width; + int coverage; +} span_t; + +typedef struct spans_s { + span_t span; + struct spans_s* next; +} spans_t; + +typedef struct rect_s { + int xmin; + int xmax; + int ymin; + int ymax; +} rect_t; + +static version_t G_text2bitmap_version = { + .major = 1, + .minor = 0, + .patch = 0, + .mod_time = 0x20130924, + .description = "Ambarella S2 text-to-bitmap Library", +}; + +/* + * ******************************************************** + * Set itatlic. + * ******************************************************** + */ + +static inline void set_italic(FT_GlyphSlot slot, const int italic) +{ + // Matrix fields are all in 16.16 format. + FT_Matrix matrix; + matrix.xx = 0x10000L; + matrix.xy = italic * 0x10000L / 100; + matrix.yx = 0; + matrix.yy = 0x10000L; + FT_Set_Transform(slot->face, &matrix, 0); +} + +/* + ********************************************************************************** + * Set bold in horizontal and vertical direction. + * + * + * FT_Error Hori_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) + * FT_Error Vert_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) + * FT_Error New_FT_Outline_Embolden(FT_Outline *outline, FT_Pos str_h, FT_Pos str_v) + * int set_bold(FT_GlyphSlot slot, int v_str, int h_str) + * + ********************************************************************************** + */ +// Embold in horizon +static FT_Error Hori_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) +{ + FT_Vector *points; + FT_Vector v_prev, v_first, v_next, v_cur; + FT_Angle rotate, angle_in, angle_out; + FT_Int c, n, first; + FT_Int orientation; + + int last = 0; + FT_Vector in, out; + FT_Angle angle_diff; + FT_Pos d; + FT_Fixed scale; + + if (!outline) + return FT_Err_Invalid_Argument; + + strength /= 2; + if (strength == 0) + return FT_Err_Ok; + + orientation = FT_Outline_Get_Orientation(outline); + if (orientation == FT_ORIENTATION_NONE) { + if (outline->n_contours) + return FT_Err_Invalid_Argument; + else + return FT_Err_Ok; + } + + if (orientation == FT_ORIENTATION_TRUETYPE) + rotate = -FT_ANGLE_PI2; + else + rotate = FT_ANGLE_PI2; + + points = outline->points; + + first = 0; + for (c = 0; c < outline->n_contours; c++) { + last = outline->contours[c]; + + v_first = points[first]; + v_prev = points[last]; + v_cur = v_first; + + for (n = first; n <= last; n++) { + if (n < last) + v_next = points[n+1]; + else + v_next = v_first; + + // compute the in and out vectors + in.x = v_cur.x - v_prev.x; + in.y = v_cur.y - v_prev.y; + + out.x = v_next.x - v_cur.x; + out.y = v_next.y - v_cur.y; + + angle_in = FT_Atan2(in.x, in.y); + angle_out = FT_Atan2(out.x, out.y); + angle_diff = FT_Angle_Diff(angle_in, angle_out); + scale = FT_Cos(angle_diff / 2); + + if (scale < 0x4000L && scale > -0x4000L) { + in.x = in.y = 0; + } else { + d = FT_DivFix(strength, scale); + FT_Vector_From_Polar(&in, d, angle_in + angle_diff/2 - rotate); + } + + outline->points[n].x = v_cur.x + strength + in.x; + + v_prev = v_cur; + v_cur = v_next; + } + + first = last + 1; + } + + return FT_Err_Ok; +} + +// Embold in vertical +static FT_Error Vert_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) +{ + FT_Vector *points; + FT_Vector v_prev, v_first, v_next, v_cur; + FT_Angle rotate, angle_in, angle_out; + FT_Int c, n, first; + FT_Int orientation; + + int last = 0; + FT_Vector in, out; + FT_Angle angle_diff; + FT_Pos d; + FT_Fixed scale; + + if (!outline) + return FT_Err_Invalid_Argument; + + strength /= 2; + if (strength == 0) + return FT_Err_Ok; + + orientation = FT_Outline_Get_Orientation(outline); + if (orientation == FT_ORIENTATION_NONE) { + if (outline->n_contours) + return FT_Err_Invalid_Argument; + else + return FT_Err_Ok; + } + + if (orientation == FT_ORIENTATION_TRUETYPE) + rotate = -FT_ANGLE_PI2; + else + rotate = FT_ANGLE_PI2; + + points = outline->points; + + first = 0; + for (c = 0; c < outline->n_contours; c++) { + last = outline->contours[c]; + + v_first = points[first]; + v_prev = points[last]; + v_cur = v_first; + + for (n = first; n <= last; n++) { + + if (n < last) + v_next = points[n+1]; + else + v_next = v_first; + + // compute the in and out vectors + in.x = v_cur.x - v_prev.x; + in.y = v_cur.y - v_prev.y; + + out.x = v_next.x - v_cur.x; + out.y = v_next.y - v_cur.y; + + angle_in = FT_Atan2(in.x, in.y); + angle_out = FT_Atan2(out.x, out.y); + angle_diff = FT_Angle_Diff(angle_in, angle_out); + scale = FT_Cos(angle_diff / 2); + + if (scale < 0x4000L && scale > -0x4000L) { + in.x = in.y = 0; + } else { + d = FT_DivFix(strength, scale); + FT_Vector_From_Polar(&in, d, angle_in + angle_diff/2 - rotate); + } + + outline->points[n].y = v_cur.y + strength + in.y; + + v_prev = v_cur; + v_cur = v_next; + } + + first = last + 1; + } + + return FT_Err_Ok; +} + +static FT_Error New_FT_Outline_Embolden(FT_Outline *outline, FT_Pos str_h, FT_Pos str_v) +{ + if (!outline) + return FT_Err_Invalid_Argument; + int orientation = FT_Outline_Get_Orientation(outline); + if ((orientation == FT_ORIENTATION_NONE) && + (outline->n_contours)) + return FT_Err_Invalid_Argument; + Vert_FT_Outline_Embolden(outline, str_v); + Hori_FT_Outline_Embolden(outline, str_h); + return FT_Err_Ok; +} + + +/* + * Return 0 if bold is set successfully, FT_Error otherwise. + */ +static int set_bold(FT_GlyphSlot slot, int v_str, int h_str) +{ + if (v_str == 0 && h_str == 0) + return 0; + FT_Library ft_library = slot->library; + FT_Error ft_error; + FT_Pos xstr = v_str, ystr = h_str; + + if (slot->format != FT_GLYPH_FORMAT_OUTLINE && + slot->format != FT_GLYPH_FORMAT_BITMAP) + return -1; + if (slot->format == FT_GLYPH_FORMAT_OUTLINE) { + FT_BBox old_box; + FT_Outline_Get_CBox(&slot->outline, &old_box); + ft_error = New_FT_Outline_Embolden(&slot->outline, xstr, ystr); + if (ft_error) + return ft_error; + + FT_BBox new_box; + FT_Outline_Get_CBox(&slot->outline, &new_box); + xstr = (new_box.xMax - new_box.xMin) - (old_box.xMax - old_box.xMin); + ystr = (new_box.yMax - new_box.yMin) - (old_box.yMax - old_box.yMin); + } else if (slot->format == FT_GLYPH_FORMAT_BITMAP) { + xstr = FT_PIX_FLOOR(xstr); + if (xstr == 0) + xstr = 1 << 6; + ystr = FT_PIX_FLOOR(ystr); + + ft_error = FT_Bitmap_Embolden(ft_library, &slot->bitmap, xstr, ystr); + if (ft_error) + return ft_error; + } + + if (slot->advance.x) + slot->advance.x += xstr; + + if (slot->advance.y) + slot->advance.y += ystr; + + slot->metrics.width += xstr; + slot->metrics.height += ystr; + slot->metrics.horiBearingY += ystr; + slot->metrics.horiAdvance += xstr; + slot->metrics.vertBearingX -= xstr/2; + slot->metrics.vertBearingY += ystr; + slot->metrics.vertAdvance += ystr; + + if (slot->format == FT_GLYPH_FORMAT_BITMAP) + slot->bitmap_top += FT_PIX_INT(ystr); + + return 0; +} + +/* + ******************************************************************************************************** + * Set outline. + * + * The method is to generate a bigger bitmap as background, and put the original bitmap on the top. + * + * void rect_include(rect_t *rect, int a, int b) + * void raster_callback(const int y, const int count, const FT_Span *spans, void* const user) + * void render_spans(FT_Library *library, FT_Outline *outline, spans_t *spans) + * void free_spans(spans_t *spans) + * u8* set_outline(const u32 outline_width, int* width, int* height) + * + ******************************************************************************************************** + */ +static inline void rect_include(rect_t *rect, int a, int b) +{ + rect->xmin = MIN(rect->xmin, a); + rect->ymin = MIN(rect->ymin, b); + rect->xmax = MAX(rect->xmax, a); + rect->ymax = MAX(rect->ymax, b); +} + +void raster_callback(const int y, const int count, const FT_Span *spans, void* const user) +{ + int i; + spans_t *sptr = (spans_t *)user, *sp = NULL; + while (sptr->next != NULL) { + sptr = sptr->next; + } + for (i = 0; i < count; i++) { + sp = (spans_t *)malloc(sizeof(spans_t)); + sp->span.x = spans[i].x; + sp->span.y = y; + sp->span.width = spans[i].len; + sp->span.coverage = spans[i].coverage; + sp->next = NULL; + + sptr->next = sp; + sptr = sptr->next; + } +} + +static void render_spans(FT_Library *library, FT_Outline *outline, spans_t *spans) +{ + FT_Raster_Params params; + memset(¶ms, 0, sizeof(params)); + params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT; + params.gray_spans = raster_callback; + params.user = spans; + + FT_Outline_Render(*library, outline, ¶ms); +} + +static void free_spans(spans_t *spans) +{ + spans_t *iter = spans, *tmp = NULL; + while (iter != NULL) { + tmp = iter; + iter = iter->next; + if (tmp) { + free(tmp); + tmp = NULL; + } + } +} + +/* + * Return the font bitmap buffer address. NULL if failed. + */ +static u8* set_outline(const u32 outline_width, int* width, int* height) +{ + u32 linesize = outline_width * cfg_font.size; + FT_GlyphSlot slot = face->glyph; + u8 *pixel = NULL; + spans_t *spans = NULL, *outlinespans = NULL; + + // Render the basic glyph to a span list. + spans = (spans_t *)malloc(sizeof(spans_t)); + if (spans == NULL) { + printf("spans malloc error\n"); + return NULL; + } + spans->span.x = 0; + spans->span.y = 0; + spans->span.width = 0; + spans->span.coverage = 0; + spans->next = NULL; + render_spans(&library, &(slot->outline), spans); + + // spans for the outline + outlinespans = (spans_t *)malloc(sizeof(spans_t)); + if (outlinespans == NULL) { + printf("outlinespans malloc error\n"); + return NULL; + } + outlinespans->span.x = 0; + outlinespans->span.y = 0; + outlinespans->span.width = 0; + outlinespans->span.coverage = 0; + outlinespans->next = NULL; + + // Set up a stroker + FT_Stroker stroker; + FT_Stroker_New(library, &stroker); + FT_Stroker_Set(stroker, + linesize, + FT_STROKER_LINECAP_ROUND, + FT_STROKER_LINEJOIN_ROUND, + 0); + + FT_Glyph glyph; + if (FT_Get_Glyph(slot, &glyph) == 0) { + FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1); // outside border. Destroyed on success. + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { + // Render the outline spans to the span list + FT_Outline *ol = &(((FT_OutlineGlyph)glyph)->outline); + render_spans(&library, ol, outlinespans); + } + + // Clean up afterwards. + FT_Stroker_Done(stroker); + FT_Done_Glyph(glyph); + + // Put them together + if (outlinespans->next != NULL) { + rect_t rect; + rect.xmin = spans->span.x; + rect.xmax = spans->span.x; + rect.ymin = spans->span.y; + rect.ymax = spans->span.y; + + spans_t *iter = NULL; + for (iter = spans; iter != NULL; iter = iter->next) { + rect_include(&rect, iter->span.x, iter->span.y); + rect_include(&rect, iter->span.x+iter->span.width-1, iter->span.y); + } + + for (iter = outlinespans; iter != NULL; iter = iter->next) { + rect_include(&rect, iter->span.x, iter->span.y); + rect_include(&rect, iter->span.x+iter->span.width-1, iter->span.y); + } + int pwidth = rect.xmax - rect.xmin + 1; + int pheight = rect.ymax - rect.ymin + 1; + int w = 0; + pixel = (u8 *)malloc(pwidth * pheight * sizeof(u8)); + if (pixel == NULL) { + printf("Mem alloc error. Strings may be too long.\n"); + return NULL; + } + memset(pixel, pixel_type.pixel_background, pwidth * pheight *sizeof(u8)); + + for (iter = outlinespans; iter != NULL; iter = iter->next) { + for (w = 0; w < (iter->span.width); w++) + pixel[(int)((pheight-1-(iter->span.y-rect.ymin)) * pwidth + iter->span.x-rect.xmin+w)] = pixel_type.pixel_outline; + } + for (iter = spans; iter != NULL; iter = iter->next) { + for (w = 0; w < (iter->span.width); w++) + pixel[(int)((pheight-1-(iter->span.y-rect.ymin)) * pwidth + iter->span.x-rect.xmin+w)] = MAX(iter->span.coverage, pixel_type.pixel_outline+1) ; + } + + *width = pwidth; + *height = pheight; + } + } + free_spans(outlinespans); + free_spans(spans); + + return pixel; +} + +/* + * Return 0 if initializing the freetype library successfully, -1 otherwise. + * The handle library is set to a new instatnce of FreeType library, which loads + * each module that FreeType knows about in the library. + * + */ +int text2bitmap_lib_init(pixel_type_t *type) +{ + if (flag_init == 1) { + printf("text2bitmap_lib_init has been called.\n"); + return 0; + } + + FT_Error ft_error = FT_Init_FreeType(&library); + if (ft_error) { + printf("An error occurred during library initilization!\n"); + return -1; + } + if (type == NULL) { + memcpy(&pixel_type, &default_pixel_type, sizeof(pixel_type_t)); + } else { + memcpy(&pixel_type, type, sizeof(pixel_type_t)); + } + + flag_init = 1; + return 0; +} + +/* + * Return 0 if font attribute is set successfully, -1 otherwise. + */ +int text2bitmap_set_font_attribute(const font_attribute_t *font_attr) +{ + FT_Error ft_error; + + if (font_attr == NULL) { + printf("[text2bitmap_set_font_attribute] NULL pointer !\n"); + return -1; + } + if (flag_face == 1) { + if ((ft_error = FT_Done_Face(face)) != 0) { + printf("Error! Destroy old attribute failed.\n"); + return -1; + } + flag_face = 0; + } + + ft_error = FT_New_Face(library, font_attr->type, 0, &face); + + if (ft_error == FT_Err_Unknown_File_Format) { + printf("Error! The font format in %s is unsupported.", font_attr->type); + return -1; + } else if (ft_error) { + printf("Error %d! The font file %s could not be opened or read, or it is broken.\n", ft_error, font_attr->type); + return -1; + } + snprintf(cfg_font.type, sizeof(cfg_font.type), "%s", font_attr->type); + cfg_font.size = font_attr->size; + cfg_font.outline_width = font_attr->outline_width; + cfg_font.hori_bold = font_attr->hori_bold; + cfg_font.vert_bold = font_attr->vert_bold; + cfg_font.italic = font_attr->italic; + cfg_font.disable_anti_alias = font_attr->disable_anti_alias; + ft_error = FT_Set_Pixel_Sizes(face, cfg_font.size, 0); + if (ft_error) { + printf("Error! Set font size to pixel %d*%d failed.\n", cfg_font.size, cfg_font.size); + return -1; + } + flag_face = 1; + // printf("Set font size to pixel %d*%d.\n", cfg_font.size, cfg_font.size); + + return 0; +} + +int text2bitmap_get_font_attribute(font_attribute_t * font_attr) +{ + if (font_attr == NULL) { + printf("[text2bitmap_get_font_attribute] NULL pointer !\n"); + return -1; + } + if (flag_face == 0) { + printf("None font attribute is set.\n"); + return 0; + } + strncpy(font_attr->type, cfg_font.type, sizeof(font_attr->type)); + font_attr->size = cfg_font.size; + font_attr->outline_width = cfg_font.outline_width; + font_attr->hori_bold = cfg_font.hori_bold; + font_attr->vert_bold = cfg_font.vert_bold; + font_attr->italic = cfg_font.italic; + font_attr->disable_anti_alias = cfg_font.disable_anti_alias; + return 0; +} + +/* + * Return 0 if font bitmap buffer is filled successfully, -1 otherwise. + * + * bmp_addr is the buffer bitmap data is to write. + * buf_height and buf_pitch for bitmap alignment with the buffer. + * offset_x is to set horizontal offset of the character bitmap to the buffer. + * The bitmap info including height and width will be given out in + * bitmap_info_t *bmp_info. + */ +int text2bitmap_convert_character(u32 ui_char_code, + u8 *bmp_addr, + u16 buf_height, + u16 buf_pitch, + int offset_x, + bitmap_info_t *bmp_info) +{ + int ft_error; + int width, height, left, top, advance_x,advance_y, bmp_pitch = 0; + u8 *mapped_pixel = NULL; + int rtn_val = 0; + FT_GlyphSlot slot = face->glyph; + + if (buf_height < cfg_font.size) { + printf("The height of the buffer to be filled with bitmap data is smaller than the font size.\n"); + return -1; + } + if (bmp_info == NULL) { + printf("[text2bitmap_convert_character] NULL pointer!\n"); + return -1; + } + + FT_UInt ui_glyph_index = FT_Get_Char_Index(face, ui_char_code); + if (cfg_font.italic) { + set_italic(slot, cfg_font.italic); + } + + ft_error = FT_Load_Glyph(face, ui_glyph_index, FT_LOAD_NO_BITMAP); + if (ft_error != 0) { + printf("Load Glyph error!\n"); + return -1; + } + +/* + printf("width=%d, height=%d, horiX=%d, horiY=%d, horiA=%d,vertX=%d,vertY=%d,vertA=%d\n", + width, height, FT_PIX_INT(slot->metrics.horiBearingX), FT_PIX_INT(slot->metrics.vertBearingY), + FT_PIX_INT(slot->metrics.horiAdvance), FT_PIX_INT(slot->metrics.vertBearingX), + FT_PIX_INT(slot->metrics.vertBearingY), FT_PIX_INT(slot->metrics.vertAdvance)); + + printf("bitmap: width = %d, rows = %d, pitch = %d, top=%d,left=%d, advance.x=%d, advance.y=%d\n", + slot->bitmap.width, slot->bitmap.rows, slot->bitmap.pitch, + slot->bitmap_top, slot->bitmap_left, + FT_PIX_INT(slot->advance.x), FT_PIX_INT(slot->advance.y)); +*/ + + if (cfg_font.hori_bold || cfg_font.vert_bold) { + set_bold(slot, cfg_font.vert_bold * cfg_font.size, cfg_font.hori_bold * cfg_font.size); + } + + width = FT_PIX_INT(slot->metrics.width); + height = FT_PIX_INT(slot->metrics.height); + left = FT_PIX_INT(slot->metrics.horiBearingX); + top = FT_PIX_INT(slot->metrics.horiBearingY); + advance_x = FT_PIX_INT(slot->metrics.horiAdvance); + advance_y = FT_PIX_INT(slot->metrics.vertAdvance); + if (!cfg_font.disable_anti_alias + &&(cfg_font.outline_width) + && (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE)) { + mapped_pixel = set_outline(cfg_font.outline_width, &bmp_pitch, &height); + } else { + FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); + mapped_pixel = slot->bitmap.buffer; + bmp_pitch = slot->bitmap.pitch; + } + + if (height > buf_height) { + printf("Error: converted bitmap height [%d] exceeds the buffer height [%d]\n", + height, buf_height); + rtn_val = -1; + goto ERROR_QUIT; + } + + width = MAX(width, bmp_pitch); + width = MIN(width, buf_pitch - offset_x - left); + + if ((bmp_pitch > 0) && (bmp_addr != NULL)) { + int row = 0, col = 0, dst_index = 0, src_index = 0; + u8 * ptr = NULL; + u32 font_gap = cfg_font.size - top; + // printf("\n\n"); + if ((font_gap + height) > buf_height) + font_gap = buf_height - height; + for (row = 0; row < height; row++) { + dst_index = buf_pitch * (row + font_gap) + offset_x; + src_index = row * bmp_pitch; + for (col = 0; col < width; col++, dst_index++, src_index++) { + if (dst_index < 0) + continue; + if ((mapped_pixel[src_index]) == 0) { + // printf("-\t"); + continue; + } + ptr = bmp_addr + dst_index; + if (cfg_font.disable_anti_alias) + *ptr = pixel_type.pixel_font; + else + *ptr = mapped_pixel[src_index]; + // printf("%d\t", *ptr); + } + // printf("\n"); + } + } + + bmp_info->width = MAX(width + left, advance_x); + bmp_info->height = MAX(height + top, advance_y); + +ERROR_QUIT: + if (cfg_font.outline_width && (mapped_pixel != NULL)) { + if (mapped_pixel) { + free(mapped_pixel); + mapped_pixel = NULL; + } + } + return rtn_val; +} + +/* + * Return 0 if the library is closed. + */ +int text2bitmap_lib_deinit() +{ + if (flag_init == 1) { + FT_Done_Face(face); + FT_Done_FreeType(library); + flag_init = 0; + flag_face = 0; + } + return 0; +} + +int text2bitmap_get_version(version_t* version) +{ + memcpy(version, &G_text2bitmap_version, sizeof(version_t)); + return 0; +} + diff --git a/src/text_insert.h b/src/text_insert.h new file mode 100644 index 0000000..ab56f26 --- /dev/null +++ b/src/text_insert.h @@ -0,0 +1,95 @@ +/******************************************************************************* + * text_insert.h + * + * History: + * 2011/02/25 - [Qian Shen] created file + * + * Copyright (c) 2016 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ +#pragma once +#ifndef _TEXT2BITMAP_LIB_H +#define _TEXT2BITMAP_LIB_H + +#include "define_inc.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_BYTE_SIZE 128 + +#ifndef _BASE_TYPES_H_ +typedef unsigned char u8; /**< UNSIGNED 8-bit data type */ +typedef unsigned short u16;/**< UNSIGNED 16-bit data type */ +typedef unsigned int u32; /**< UNSIGNED 32-bit data type */ +typedef unsigned long long u64; /**< UNSIGNED 64-bit data type */ +typedef signed char s8; /**< SIGNED 8-bit data type */ +typedef signed short s16; /**< SIGNED 16-bit data type */ +typedef signed int s32; /**< SIGNED 32-bit data type */ +#endif + +typedef struct { + int major; + int minor; + int patch; + unsigned int mod_time; + char description[64]; +} version_t; + +typedef struct font_attribute_s { + char type[MAX_BYTE_SIZE]; + u32 size; + u32 outline_width; // 0: no outline + s32 hori_bold; // 0: no bold at all; positive is bold, negetive is thin in horizontal + s32 vert_bold; // 0: no bold at all; positive is bold, negetive is thin in vertical + u32 italic; // 0 is normal (no italic), 100 is 100% italic + u32 disable_anti_alias; // 0: anti-alias is enabled, 1: disable anti-alias. Default is 0. +} font_attribute_t; + +typedef struct bitmap_info_s { + int width; + int height; +} bitmap_info_t; + +typedef struct pixel_type_s { + u8 pixel_background; + u8 pixel_font; + u8 pixel_outline; + u8 reserved; +} pixel_type_t; + +int text2bitmap_lib_init(pixel_type_t *type); +int text2bitmap_set_font_attribute(const font_attribute_t *font_attr); +int text2bitmap_get_font_attribute(font_attribute_t *font_attr); +int text2bitmap_convert_character(u32 ui_char_code, u8 *bmp_addr, u16 buf_height, u16 buf_pitch, int offset_x, bitmap_info_t *bmp_info); +int text2bitmap_lib_deinit(void); +int text2bitmap_get_version(version_t* version); + +#ifdef __cplusplus +} +#endif + +#endif //_TEXT2BITMAP_LIB_H + diff --git a/src/text_insert_v2.c b/src/text_insert_v2.c new file mode 100644 index 0000000..c40b2cb --- /dev/null +++ b/src/text_insert_v2.c @@ -0,0 +1,805 @@ +/******************************************************************************* + * text_insert_v2.c + * + * History: + * 2018/08/07 - [Huaiqing Wang] created file + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ + +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <ft2build.h> +#include "text_insert_v2.h" + +#include FT_FREETYPE_H +#include FT_TRIGONOMETRY_H +#include FT_BITMAP_H +#include FT_STROKER_H + +#define FT_INTEGER_BIT (6) + +#ifndef FT_PIX_FLOOR +#define FT_PIX_FLOOR(x) ((x) & ~((1 << FT_INTEGER_BIT) - 1)) +#endif + +#ifndef FT_PIX_INT +#define FT_PIX_INT(x) ((x) >> FT_INTEGER_BIT) +#endif + +#ifndef MIN +#define MIN(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y);\ + _x < _y ? _x : _y; }) +#endif + +#ifndef MAX +#define MAX(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y);\ + _x > _y ? _x : _y; }) +#endif + +static pixel_type_t default_pixel_type = { + .pixel_background = 0, + .pixel_outline = 1, + .pixel_font = 255 +}; + +typedef struct span_s { + int x; + int y; + int width; + int coverage; +} span_t; + +typedef struct spans_s { + span_t span; + struct spans_s* next; +} spans_t; + +typedef struct rect_s { + int xmin; + int xmax; + int ymin; + int ymax; +} rect_t; + +static version_t G_text2bitmap_version = { + .major = 2, + .minor = 0, + .patch = 0, + .mod_time = 0x20180807, + .description = "Ambarella text-to-bitmap Dynamic Library", +}; + +/* + * ******************************************************** + * Set itatlic. + * ******************************************************** + */ + +static inline void set_italic(FT_GlyphSlot slot, const int italic) +{ + // Matrix fields are all in 16.16 format. + FT_Matrix matrix; + matrix.xx = 0x10000L; + matrix.xy = italic * 0x10000L / 100; + matrix.yx = 0; + matrix.yy = 0x10000L; + FT_Set_Transform(slot->face, &matrix, 0); +} + +/* + ********************************************************************************** + * Set bold in horizontal and vertical direction. + * + * + * FT_Error Hori_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) + * FT_Error Vert_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) + * FT_Error New_FT_Outline_Embolden(FT_Outline *outline, FT_Pos str_h, FT_Pos str_v) + * int set_bold(FT_GlyphSlot slot, int v_str, int h_str) + * + ********************************************************************************** + */ +// Embold in horizon +static FT_Error Hori_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) +{ + FT_Vector *points; + FT_Vector v_prev, v_first, v_next, v_cur; + FT_Angle rotate, angle_in, angle_out; + FT_Int c, n, first; + FT_Int orientation; + + int last = 0; + FT_Vector in, out; + FT_Angle angle_diff; + FT_Pos d; + FT_Fixed scale; + + if (!outline) + return FT_Err_Invalid_Argument; + + strength /= 2; + if (strength == 0) + return FT_Err_Ok; + + orientation = FT_Outline_Get_Orientation(outline); + if (orientation == FT_ORIENTATION_NONE) { + if (outline->n_contours) + return FT_Err_Invalid_Argument; + else + return FT_Err_Ok; + } + + if (orientation == FT_ORIENTATION_TRUETYPE) + rotate = -FT_ANGLE_PI2; + else + rotate = FT_ANGLE_PI2; + + points = outline->points; + + first = 0; + for (c = 0; c < outline->n_contours; c++) { + last = outline->contours[c]; + + v_first = points[first]; + v_prev = points[last]; + v_cur = v_first; + + for (n = first; n <= last; n++) { + if (n < last) + v_next = points[n+1]; + else + v_next = v_first; + + // compute the in and out vectors + in.x = v_cur.x - v_prev.x; + in.y = v_cur.y - v_prev.y; + + out.x = v_next.x - v_cur.x; + out.y = v_next.y - v_cur.y; + + angle_in = FT_Atan2(in.x, in.y); + angle_out = FT_Atan2(out.x, out.y); + angle_diff = FT_Angle_Diff(angle_in, angle_out); + scale = FT_Cos(angle_diff / 2); + + if (scale < 0x4000L && scale > -0x4000L) { + in.x = in.y = 0; + } else { + d = FT_DivFix(strength, scale); + FT_Vector_From_Polar(&in, d, angle_in + angle_diff/2 - rotate); + } + + outline->points[n].x = v_cur.x + strength + in.x; + + v_prev = v_cur; + v_cur = v_next; + } + + first = last + 1; + } + + return FT_Err_Ok; +} + +// Embold in vertical +static FT_Error Vert_FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength) +{ + FT_Vector *points; + FT_Vector v_prev, v_first, v_next, v_cur; + FT_Angle rotate, angle_in, angle_out; + FT_Int c, n, first; + FT_Int orientation; + + int last = 0; + FT_Vector in, out; + FT_Angle angle_diff; + FT_Pos d; + FT_Fixed scale; + + if (!outline) + return FT_Err_Invalid_Argument; + + strength /= 2; + if (strength == 0) + return FT_Err_Ok; + + orientation = FT_Outline_Get_Orientation(outline); + if (orientation == FT_ORIENTATION_NONE) { + if (outline->n_contours) + return FT_Err_Invalid_Argument; + else + return FT_Err_Ok; + } + + if (orientation == FT_ORIENTATION_TRUETYPE) + rotate = -FT_ANGLE_PI2; + else + rotate = FT_ANGLE_PI2; + + points = outline->points; + + first = 0; + for (c = 0; c < outline->n_contours; c++) { + last = outline->contours[c]; + + v_first = points[first]; + v_prev = points[last]; + v_cur = v_first; + + for (n = first; n <= last; n++) { + + if (n < last) + v_next = points[n+1]; + else + v_next = v_first; + + // compute the in and out vectors + in.x = v_cur.x - v_prev.x; + in.y = v_cur.y - v_prev.y; + + out.x = v_next.x - v_cur.x; + out.y = v_next.y - v_cur.y; + + angle_in = FT_Atan2(in.x, in.y); + angle_out = FT_Atan2(out.x, out.y); + angle_diff = FT_Angle_Diff(angle_in, angle_out); + scale = FT_Cos(angle_diff / 2); + + if (scale < 0x4000L && scale > -0x4000L) { + in.x = in.y = 0; + } else { + d = FT_DivFix(strength, scale); + FT_Vector_From_Polar(&in, d, angle_in + angle_diff/2 - rotate); + } + + outline->points[n].y = v_cur.y + strength + in.y; + + v_prev = v_cur; + v_cur = v_next; + } + + first = last + 1; + } + + return FT_Err_Ok; +} + +static FT_Error New_FT_Outline_Embolden(FT_Outline *outline, FT_Pos str_h, FT_Pos str_v) +{ + if (!outline) + return FT_Err_Invalid_Argument; + int orientation = FT_Outline_Get_Orientation(outline); + if ((orientation == FT_ORIENTATION_NONE) && + (outline->n_contours)) + return FT_Err_Invalid_Argument; + Vert_FT_Outline_Embolden(outline, str_v); + Hori_FT_Outline_Embolden(outline, str_h); + return FT_Err_Ok; +} + + +/* + * Return 0 if bold is set successfully, FT_Error otherwise. + */ +static int set_bold(FT_GlyphSlot slot, int v_str, int h_str) +{ + if (v_str == 0 && h_str == 0) + return 0; + FT_Library ft_library = slot->library; + FT_Error ft_error; + FT_Pos xstr = v_str, ystr = h_str; + + if (slot->format != FT_GLYPH_FORMAT_OUTLINE && + slot->format != FT_GLYPH_FORMAT_BITMAP) + return -1; + if (slot->format == FT_GLYPH_FORMAT_OUTLINE) { + FT_BBox old_box; + FT_Outline_Get_CBox(&slot->outline, &old_box); + ft_error = New_FT_Outline_Embolden(&slot->outline, xstr, ystr); + if (ft_error) + return ft_error; + + FT_BBox new_box; + FT_Outline_Get_CBox(&slot->outline, &new_box); + xstr = (new_box.xMax - new_box.xMin) - (old_box.xMax - old_box.xMin); + ystr = (new_box.yMax - new_box.yMin) - (old_box.yMax - old_box.yMin); + } else if (slot->format == FT_GLYPH_FORMAT_BITMAP) { + xstr = FT_PIX_FLOOR(xstr); + if (xstr == 0) + xstr = 1 << 6; + ystr = FT_PIX_FLOOR(ystr); + + ft_error = FT_Bitmap_Embolden(ft_library, &slot->bitmap, xstr, ystr); + if (ft_error) + return ft_error; + } + + if (slot->advance.x) + slot->advance.x += xstr; + + if (slot->advance.y) + slot->advance.y += ystr; + + slot->metrics.width += xstr; + slot->metrics.height += ystr; + slot->metrics.horiBearingY += ystr; + slot->metrics.horiAdvance += xstr; + slot->metrics.vertBearingX -= xstr/2; + slot->metrics.vertBearingY += ystr; + slot->metrics.vertAdvance += ystr; + + if (slot->format == FT_GLYPH_FORMAT_BITMAP) + slot->bitmap_top += FT_PIX_INT(ystr); + + return 0; +} + +/* + ******************************************************************************************************** + * Set outline. + * + * The method is to generate a bigger bitmap as background, and put the original bitmap on the top. + * + * void rect_include(rect_t *rect, int a, int b) + * void raster_callback(const int y, const int count, const FT_Span *spans, void* const user) + * void render_spans(FT_Library *library, FT_Outline *outline, spans_t *spans) + * void free_spans(spans_t *spans) + * u8* set_outline(const u32 outline_width, int* width, int* height) + * + ******************************************************************************************************** + */ +static inline void rect_include(rect_t *rect, int a, int b) +{ + rect->xmin = MIN(rect->xmin, a); + rect->ymin = MIN(rect->ymin, b); + rect->xmax = MAX(rect->xmax, a); + rect->ymax = MAX(rect->ymax, b); +} + +void raster_callback(const int y, const int count, const FT_Span *spans, void* const user) +{ + int i; + spans_t *sptr = (spans_t *)user, *sp = NULL; + while (sptr->next != NULL) { + sptr = sptr->next; + } + for (i = 0; i < count; i++) { + sp = (spans_t *)malloc(sizeof(spans_t)); + sp->span.x = spans[i].x; + sp->span.y = y; + sp->span.width = spans[i].len; + sp->span.coverage = spans[i].coverage; + sp->next = NULL; + + sptr->next = sp; + sptr = sptr->next; + } +} + +static void render_spans(FT_Library *library, FT_Outline *outline, spans_t *spans) +{ + FT_Raster_Params params; + memset(¶ms, 0, sizeof(params)); + params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT; + params.gray_spans = raster_callback; + params.user = spans; + + FT_Outline_Render(*library, outline, ¶ms); +} + +static void free_spans(spans_t *spans) +{ + spans_t *iter = spans, *tmp = NULL; + while (iter != NULL) { + tmp = iter; + iter = iter->next; + if (tmp) { + free(tmp); + tmp = NULL; + } + } +} + +/* + * Return the font bitmap buffer address. NULL if failed. + */ +static u8* set_outline(const u32 outline_width, int* width, int* height, text2bitmap_t *text) +{ + u32 linesize = outline_width * text->font.size; + FT_Library *library = (FT_Library*)(text->library); + FT_Face *face = (FT_Face*)(text->face); + FT_GlyphSlot slot = (*face)->glyph; + u8 *pixel = NULL; + spans_t *spans = NULL, *outlinespans = NULL; + + // Render the basic glyph to a span list. + spans = (spans_t *)malloc(sizeof(spans_t)); + if (spans == NULL) { + printf("spans malloc error\n"); + return NULL; + } + spans->span.x = 0; + spans->span.y = 0; + spans->span.width = 0; + spans->span.coverage = 0; + spans->next = NULL; + render_spans(library, &(slot->outline), spans); + + // spans for the outline + outlinespans = (spans_t *)malloc(sizeof(spans_t)); + if (outlinespans == NULL) { + printf("outlinespans malloc error\n"); + return NULL; + } + outlinespans->span.x = 0; + outlinespans->span.y = 0; + outlinespans->span.width = 0; + outlinespans->span.coverage = 0; + outlinespans->next = NULL; + + // Set up a stroker + FT_Stroker stroker; + FT_Stroker_New(*library, &stroker); + FT_Stroker_Set(stroker, + linesize, + FT_STROKER_LINECAP_ROUND, + FT_STROKER_LINEJOIN_ROUND, + 0); + + FT_Glyph glyph; + if (FT_Get_Glyph(slot, &glyph) == 0) { + FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1); // outside border. Destroyed on success. + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { + // Render the outline spans to the span list + FT_Outline *ol = &(((FT_OutlineGlyph)glyph)->outline); + render_spans(library, ol, outlinespans); + } + + // Clean up afterwards. + FT_Stroker_Done(stroker); + FT_Done_Glyph(glyph); + + // Put them together + if (outlinespans->next != NULL) { + rect_t rect; + rect.xmin = spans->span.x; + rect.xmax = spans->span.x; + rect.ymin = spans->span.y; + rect.ymax = spans->span.y; + + spans_t *iter = NULL; + for (iter = spans; iter != NULL; iter = iter->next) { + rect_include(&rect, iter->span.x, iter->span.y); + rect_include(&rect, iter->span.x+iter->span.width-1, iter->span.y); + } + + for (iter = outlinespans; iter != NULL; iter = iter->next) { + rect_include(&rect, iter->span.x, iter->span.y); + rect_include(&rect, iter->span.x+iter->span.width-1, iter->span.y); + } + int pwidth = rect.xmax - rect.xmin + 1; + int pheight = rect.ymax - rect.ymin + 1; + int w = 0; + pixel = (u8 *)malloc(pwidth * pheight * sizeof(u8)); + if (pixel == NULL) { + printf("Mem alloc error. Strings may be too long.\n"); + return NULL; + } + + memset(pixel, text->pixel.pixel_background, pwidth * pheight *sizeof(u8)); + + for (iter = outlinespans; iter != NULL; iter = iter->next) { + for (w = 0; w < (iter->span.width); w++) + pixel[(int)((pheight-1-(iter->span.y-rect.ymin)) * pwidth + iter->span.x-rect.xmin+w)] = text->pixel.pixel_outline; + } + for (iter = spans; iter != NULL; iter = iter->next) { + for (w = 0; w < (iter->span.width); w++) + pixel[(int)((pheight-1-(iter->span.y-rect.ymin)) * pwidth + iter->span.x-rect.xmin+w)] = MAX(iter->span.coverage, text->pixel.pixel_outline+1) ; + } + + *width = pwidth; + *height = pheight; + } + } + free_spans(outlinespans); + free_spans(spans); + + return pixel; +} + +/* + * Return 0 if initializing the freetype library successfully, -1 otherwise. + * The handle library is set to a new instatnce of FreeType library, which loads + * each module that FreeType knows about in the library. + * + */ +int text2bitmap_lib_init(text2bitmap_t *text) +{ + if (text == NULL) { + printf("NULL pointer!"); + return -1; + } + if (text->library == NULL) { + printf("Library is NULL\n"); + return -1; + } + if (text->face == NULL) { + printf("Face is NULL\n"); + return -1; + } + + if (text->library_size < sizeof(FT_Library)) { + printf("library_size(%d) is too small, it should > %d\n",text->library_size, (u32)sizeof(FT_Library)); + return -1; + } + if (text->face_size < sizeof(FT_Face)) { + printf("face_size(%d) is too small, it should > %d\n",text->face_size, (u32)sizeof(FT_Face)); + return -1; + } + + FT_Library *library = (FT_Library*)(text->library); + FT_Face *face = (FT_Face*)(text->face); + FT_Error ft_error = FT_Init_FreeType(library); + if (ft_error) { + printf("An error occurred during library initilization!\n"); + return -1; + } + + ft_error = FT_New_Face(*library, text->font.type, 0, face); + if (ft_error == FT_Err_Unknown_File_Format) { + printf("Error! The font format in %s is unsupported.", text->font.type); + FT_Done_FreeType(*((FT_Library*)(text->library))); + return -1; + } else if (ft_error) { + printf("Error %d! The font file %s could not be opened or read, or it is broken.\n", ft_error, text->font.type); + FT_Done_FreeType(*((FT_Library*)(text->library))); + return -1; + } + + ft_error = FT_Set_Pixel_Sizes(*face, text->font.size, 0); + if (ft_error) { + printf("Error! Set font size to pixel %d*%d failed.\n", text->font.size, text->font.size); + FT_Done_Face(*((FT_Face*)(text->face))); + FT_Done_FreeType(*((FT_Library*)(text->library))); + return -1; + } + + if (text->pixel.pixel_background == 0 && + text->pixel.pixel_font == 0 && + text->pixel.pixel_outline == 0) { + text->pixel = default_pixel_type; + } + + return 0; +} + +/* + * Return 0 if font attribute is update successfully, -1 otherwise. + */ +int text2bitmap_update_font_attribute(const font_attribute_t *font_attr, text2bitmap_t *text) +{ + FT_Error ft_error; + + if (font_attr == NULL || text == NULL) { + printf("[text2bitmap_update_font_attribute] NULL pointer !\n"); + return -1; + } + if (text->face == NULL || text->library == NULL) { + printf("[text2bitmap_update_font_attribute] NULL pointer !\n"); + return -1; + } + + FT_Face *face = (FT_Face*)(text->face); + if ((ft_error = FT_Done_Face(*face)) != 0) { + printf("Error! Destroy old attribute failed.\n"); + return -1; + } + + FT_Library *library = (FT_Library*)(text->library); + ft_error = FT_New_Face(*library, font_attr->type, 0, face); + + if (ft_error == FT_Err_Unknown_File_Format) { + printf("Error! The font format in %s is unsupported.", font_attr->type); + return -1; + } else if (ft_error) { + printf("Error %d! The font file %s could not be opened or read, or it is broken.\n", ft_error, font_attr->type); + return -1; + } + + ft_error = FT_Set_Pixel_Sizes(*face, font_attr->size, 0); + if (ft_error) { + printf("Error! Set font size to pixel %d*%d failed.\n", font_attr->size, font_attr->size); + return -1; + } + + memcpy(&(text->font), font_attr, sizeof(font_attribute_t)); + // printf("Set font size to pixel %d*%d.\n", cfg_font.size, cfg_font.size); + + return 0; +} + +/* + * Return 0 if font bitmap buffer is filled successfully, -1 otherwise. + * + * bmp_addr is the buffer bitmap data is to write. + * buf_height and buf_pitch for bitmap alignment with the buffer. + * offset_x is to set horizontal offset of the character bitmap to the buffer. + * The bitmap info including height and width will be given out in + * bitmap_info_t *bmp_info. + */ +int text2bitmap_convert_character(u32 ui_char_code, + u8 *bmp_addr, + u16 buf_height, + u16 buf_pitch, + int offset_x, + bitmap_info_t *bmp_info, + text2bitmap_t *text) +{ + if (!bmp_addr || !bmp_info || !text) { + printf("NULL pointer!\n"); + return -1; + } + if (!(text->library) || !(text->face)) { + printf("NULL pointer!\n"); + return -1; + } + int ft_error; + int width, height, left, top, advance_x,advance_y, bmp_pitch = 0; + u8 *mapped_pixel = NULL; + int rtn_val = 0; + FT_Face *face = (FT_Face*)(text->face); + FT_GlyphSlot slot = (*face)->glyph; + + if (buf_height < text->font.size) { + printf("The height of the buffer to be filled with bitmap data is smaller than the font size.\n"); + return -1; + } + + FT_UInt ui_glyph_index = FT_Get_Char_Index(*face, ui_char_code); + if (text->font.italic) { + set_italic(slot, text->font.italic); + } + + ft_error = FT_Load_Glyph(*face, ui_glyph_index, FT_LOAD_NO_BITMAP); + if (ft_error != 0) { + printf("Load Glyph error!\n"); + return -1; + } + +/* + printf("width=%d, height=%d, horiX=%d, horiY=%d, horiA=%d,vertX=%d,vertY=%d,vertA=%d\n", + width, height, FT_PIX_INT(slot->metrics.horiBearingX), FT_PIX_INT(slot->metrics.vertBearingY), + FT_PIX_INT(slot->metrics.horiAdvance), FT_PIX_INT(slot->metrics.vertBearingX), + FT_PIX_INT(slot->metrics.vertBearingY), FT_PIX_INT(slot->metrics.vertAdvance)); + + printf("bitmap: width = %d, rows = %d, pitch = %d, top=%d,left=%d, advance.x=%d, advance.y=%d\n", + slot->bitmap.width, slot->bitmap.rows, slot->bitmap.pitch, + slot->bitmap_top, slot->bitmap_left, + FT_PIX_INT(slot->advance.x), FT_PIX_INT(slot->advance.y)); +*/ + + if (text->font.hori_bold || text->font.vert_bold) { + set_bold(slot, text->font.vert_bold * text->font.size, text->font.hori_bold * text->font.size); + } + + width = FT_PIX_INT(slot->metrics.width); + height = FT_PIX_INT(slot->metrics.height); + left = FT_PIX_INT(slot->metrics.horiBearingX); + top = FT_PIX_INT(slot->metrics.horiBearingY); + advance_x = FT_PIX_INT(slot->metrics.horiAdvance); + advance_y = FT_PIX_INT(slot->metrics.vertAdvance); + if (!text->font.disable_anti_alias + &&(text->font.outline_width) + && ((*face)->glyph->format == FT_GLYPH_FORMAT_OUTLINE)) { + mapped_pixel = set_outline(text->font.outline_width, &bmp_pitch, &height, text); + } else { + FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); + mapped_pixel = slot->bitmap.buffer; + bmp_pitch = slot->bitmap.pitch; + } + + if (height > buf_height) { + printf("Error: converted bitmap height [%d] exceeds the buffer height [%d]\n", + height, buf_height); + rtn_val = -1; + goto ERROR_QUIT; + } + + width = MAX(width, bmp_pitch); + width = MIN(width, buf_pitch - offset_x - left); + + if ((bmp_pitch > 0) && (bmp_addr != NULL)) { + int row = 0, col = 0, dst_index = 0, src_index = 0; + u8 * ptr = NULL; + u32 font_gap = text->font.size - top; + // printf("\n\n"); + if ((font_gap + height) > buf_height) + font_gap = buf_height - height; + for (row = 0; row < height; row++) { + dst_index = buf_pitch * (row + font_gap) + offset_x; + src_index = row * bmp_pitch; + for (col = 0; col < width; col++, dst_index++, src_index++) { + if (dst_index < 0) + continue; + if ((mapped_pixel[src_index]) == 0) { + // printf("-\t"); + continue; + } + ptr = bmp_addr + dst_index; + if (text->font.disable_anti_alias) + *ptr = text->pixel.pixel_font; + else + *ptr = mapped_pixel[src_index]; + // printf("%d\t", *ptr); + } + // printf("\n"); + } + } + + bmp_info->width = MAX(width + left, advance_x); + bmp_info->height = MAX(height + top, advance_y); + +ERROR_QUIT: + if (text->font.outline_width && (mapped_pixel != NULL)) { + if (mapped_pixel) { + free(mapped_pixel); + mapped_pixel = NULL; + } + } + + return rtn_val; +} + +/* + * Return 0 if the library is closed. + */ +int text2bitmap_lib_deinit(text2bitmap_t *text) +{ + if (text) { + if (text->face) { + FT_Done_Face(*((FT_Face*)(text->face))); + } + if (text->library) { + FT_Done_FreeType(*((FT_Library*)(text->library))); + } + } + + return 0; +} + +int text2bitmap_get_version(version_t* version) +{ + memcpy(version, &G_text2bitmap_version, sizeof(version_t)); + return 0; +} + diff --git a/src/text_insert_v2.h b/src/text_insert_v2.h new file mode 100644 index 0000000..2972466 --- /dev/null +++ b/src/text_insert_v2.h @@ -0,0 +1,106 @@ +/******************************************************************************* + * text_insert.h + * + * History: + * 2018/08/07 - [Huaiqing Wang] created file + * + * Copyright (c) 2018 Ambarella, Inc. + * + * This file and its contents ( "Software" ) are protected by intellectual + * property rights including, without limitation, U.S. and/or foreign + * copyrights. This Software is also the confidential and proprietary + * information of Ambarella, Inc. and its licensors. You may not use, reproduce, + * disclose, distribute, modify, or otherwise prepare derivative works of this + * Software or any portion thereof except pursuant to a signed license agreement + * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. + * In the absence of such an agreement, you agree to promptly notify and return + * this Software to Ambarella, Inc. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES 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; COMPUTER FAILURE OR MALFUNCTION; 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. + * + ******************************************************************************/ +#pragma once +#ifndef _TEXT2BITMAP_V2_LIB_H +#define _TEXT2BITMAP_V2_LIB_H +#include "define_inc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_BYTE_SIZE 128 + +#ifndef _BASE_TYPES_H_ +typedef unsigned char u8; /**< UNSIGNED 8-bit data type */ +typedef unsigned short u16;/**< UNSIGNED 16-bit data type */ +typedef unsigned int u32; /**< UNSIGNED 32-bit data type */ +typedef unsigned long long u64; /**< UNSIGNED 64-bit data type */ +typedef signed char s8; /**< SIGNED 8-bit data type */ +typedef signed short s16; /**< SIGNED 16-bit data type */ +typedef signed int s32; /**< SIGNED 32-bit data type */ +#endif + +typedef struct { + int major; + int minor; + int patch; + unsigned int mod_time; + char description[64]; +} version_t; + +typedef struct font_attribute_s { + char type[MAX_BYTE_SIZE]; + u32 size; + u32 outline_width; // 0: no outline + s32 hori_bold; // 0: no bold at all; positive is bold, negetive is thin in horizontal + s32 vert_bold; // 0: no bold at all; positive is bold, negetive is thin in vertical + u32 italic; // 0 is normal (no italic), 100 is 100% italic + u32 disable_anti_alias; // 0: anti-alias is enabled, 1: disable anti-alias. Default is 0. +} font_attribute_t; + +typedef struct bitmap_info_s { + int width; + int height; +} bitmap_info_t; + +typedef struct pixel_type_s { + u8 pixel_background; + u8 pixel_font; + u8 pixel_outline; + u8 reserved; +} pixel_type_t; + +typedef struct text2bitmap_s { + font_attribute_t font; + pixel_type_t pixel; + void *library; + void *face; + u32 library_size; + u32 face_size; +} text2bitmap_t; + + +int text2bitmap_lib_init(text2bitmap_t *text); +int text2bitmap_update_font_attribute(const font_attribute_t *font_attr, text2bitmap_t *text); +int text2bitmap_convert_character(u32 ui_char_code, u8 *bmp_addr, + u16 buf_height, u16 buf_pitch, int offset_x, + bitmap_info_t *bmp_info, text2bitmap_t *text); +int text2bitmap_lib_deinit(text2bitmap_t *text); +int text2bitmap_get_version(version_t* version); + +#ifdef __cplusplus +} +#endif + +#endif //_TEXT2BITMAP_V2_LIB_H + diff --git a/src/tof.c b/src/tof.c new file mode 100644 index 0000000..16ce40f --- /dev/null +++ b/src/tof.c @@ -0,0 +1,920 @@ + +#include "tof.h" + +#include "setting.h" +#include "network.h" + +#include <time.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <pthread.h> +#include <sys/shm.h> +#include <sys/time.h> + +#ifdef GY_OS_WIN +#include "curl.h" +#include "easy.h" +#endif + +#if defined GY_OS_AMBA || defined GY_OS_NOVA +#include "curl/curl.h" +#include "curl/easy.h" +#endif + +int g_switch_tof_data_json = 0; +char g_tof_data_json[BUFSIZE_V3] = {0}; + +CURL *g_curl_Handle_tof; +struct curl_slist *g_pList_tof = NULL; + +// ShareMemory +frameimage *tof_raw_arr; +frameimage *tof_raw_arr_tmp; +frameimage *tof_raw_arr_pcd; +frameimage *tof_raw_arr_pcd_L; +// frameimage_yuv *tof_yuv_arr; +// frameimage_yuv *tof_yuv_arr_tmp; + +pthread_t tof_pcd_thread_id; +char* tof_pcd_buffer_L; +char* tof_pcd_buffer_M; +char* tof_pcd_buffer_S; +int bTofDataStart; +int bTofDataFileStart = 0; +int tof_depth_shmid = -1; +// int tof_yuv_shmid; +rbuf_t tof_ring_buffer; + +size_t tof_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream) { + /* + time_t timep; + struct tm * timeinfo; + time(&timep); + timeinfo = localtime(&timep); + */ + size_t realsize = size * nmemb; + //cJSON *r_root, *r_tstamp; + + //time_t r_timep; + //struct tm * r_timeinfo; + //time(&timep); + if (stream) + { + //printf("Magic: %s \n", (char *)stream); + //free(stream); + + sprintf((char *)stream, "%s", (char *)ptr); + return realsize; + } + else + { + return 0; + } + + //printf(">>>>>>>>>>>>> Get PTZ Curl resp:\n %s \n", (char *)ptr); + //printf(">>>>>>>>>>>>> Response Time: %d-%02d-%02d ", (1900 + timeinfo->tm_year), (1 + timeinfo->tm_mon), timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); +} + +int net_curl_tof_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, + char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) +{ + pthread_mutex_lock(&mutex_send_cgi); + pthread_mutex_lock(&mutex_curl); + + CURL *curl = NULL; + CURLcode l_res; + int l_ret = -1; + //const int timeout = 30000; + //const int timeout = 100; + //char *sBuffer; + //char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; + curl = g_http_handle; + + struct curl_slist *pList = NULL; + + //char response_data[512] = { 0 }; + //char *response_data; + //response_data = malloc(512); + //strcat(response_data, "mmmmmmmmmmmmmmagic"); + + if (curl != NULL) + { + + if (strcmp(method, "POST") == 0) + { + //pList = curl_slist_append(pList, "Content-Type:application/json"); + pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); + //Connection: close + } + pList = curl_slist_append(pList, "charset: utf-8"); + pList = curl_slist_append(pList, "Connection: close"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); + + //time_t s_timep = time(0); + //struct tm *s_timeinfo = localtime(&s_timep); + //printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); + //printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); + + //char test_countent[25] = { 0 }; + //strncpy(test_countent, sData, 20); + //printf("Curl send content: \n %s\n", test_countent); + + curl_easy_setopt(curl, CURLOPT_URL, sUrl); + + char buf_account[512] = { 0 }; + urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); + char buf_account2[512] = { 0 }; + urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); + curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); + curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); + curl_easy_setopt(curl, CURLOPT_PORT, iPort); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, tof_cmd_curl_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, sOutputData); + + // 為了在UpdateRecoveryTimer 中拿到所有的資料(>57000) + curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 60000); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + //curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "LILIN"); + + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); + + curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); + + if (strcmp(method, "POST") == 0) + { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); + curl_easy_setopt(curl, CURLOPT_POST, 1L); + } + + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1000); + + curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). + + curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); // 1 : show log + + l_res = curl_easy_perform(curl); + if (l_res != CURLE_OK) + { + //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); + l_ret = -1; + } + else + l_ret = 0; + + curl_easy_reset(curl); + if (pList != NULL) + curl_slist_free_all(pList); + pList = NULL; + } + + pthread_mutex_unlock(&mutex_curl); + pthread_mutex_unlock(&mutex_send_cgi); + + return l_ret; +} + +void send_request_to_tof(char *szIP, char *sUrl, char *sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort, char *sOutputData) +{ + //int ret = 0; + + //char *arr_sOutputDataList[MAX_PTZ_INFO]; + //int iPTZInfoCount = 0; + //char *del = "\r\n"; + +#if 0 + FILE * pPipe; + char cmd[512] = { 0 }; + //memset(cmd, 0x00, sizeof(cmd)); + sprintf(cmd, "curl %s", sUrl); + pPipe = vpopen(cmd, "r"); + if (pPipe != NULL) + vpclose(pPipe); +#endif + + //strcat(ptz_curl_username, accountData[0].account_username); + //strcat(ptz_curl_password, accountData[0].account_password); + +#if 0 + /*int curl_ret = */net_curl_ptz_cmd_ghandle(sUrl, sSendbuf, NULL, sMethod, + accountData[0].account_username, accountData[0].account_password, iPort, sOutputData); +#endif + +#if 1 + /*int curl_ret = */net_curl_tof_cmd(sUrl, sSendbuf, NULL, sMethod, + sUsername, sPassword, iPort, sOutputData); +#endif + +#if 0 + /*int curl_ret = */net_socket_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, + sUsername, sPassword, iPort, sOutputData); +#endif + +#if 0 + /*int curl_ret = */net_curl_ptz_cmd_multi_interface(sUrl, sSendbuf, NULL, sMethod, + sUsername, sPassword, iPort, sOutputData); +#endif + + + +} + +double getDepth(int depthMapX, int depthMapY) { + double depth = 0.0; + + int ind = depthMapY * (TOF_WIDTH) + depthMapX; + + //printf("\n----depthMapX : %d,depthMapY : %d\n", depthMapX,depthMapY); + + // printf("access index ( %d (depthMapY) * 640 + %d (depthMapX) ) : %d\n", depthMapY, depthMapX, ind); + + // printf("arr->data[ind]:%f\n", tof_raw_arr_tmp->data[ind]); + pthread_mutex_lock(&mutex_get_depth); + depth = (double)tof_raw_arr_tmp->data[ind]; // get arr and compare the index : (Y * width + X) + pthread_mutex_unlock(&mutex_get_depth); + + // printf("[getDepth()] depth:%f\n", depth); + + return depth; +} + +void get_bbox_distance_and_height(float box_left_x, float box_top_y,float box_width,float box_height,float *get_bbox_distance, float *get_bbox_height) { + + if (box_left_x < 0 || box_left_x >= TOF_WIDTH || box_top_y < 0 || box_top_y >= TOF_HEIGHT || + (box_left_x + box_width) >= TOF_WIDTH || (box_top_y + box_height) >= TOF_WIDTH || + box_width <= 0 || box_height <= 0) { + + } + else { + double depth = 0.0; + + int count_depth[30] = { 0 }; + int max_index = -1; + int max_count = 0; + + float box_focus_y = box_top_y + box_height / 2.0; + + pthread_mutex_lock(&mutex_get_depth); + for (int i = (int)(box_left_x + box_width / 3.0); i < (int)(box_left_x + box_width * 2.0 / 3.0); i+=5) { + for (int j = (int)(box_top_y + box_height / 3.0); j < (int)(box_top_y + box_height * 2.0 / 3.0); j+=5) { + int ind = j * (TOF_WIDTH) + i; + + int index_depth = (int)(((double)tof_raw_arr_tmp->data[ind]) / 0.3); + + if (index_depth <= 29) { + count_depth[index_depth]++; + if (count_depth[index_depth] > max_count) { + max_count = count_depth[index_depth]; + max_index = index_depth; + } + } + } + } + pthread_mutex_unlock(&mutex_get_depth); + + if (max_index >= 0) { + depth = ((double)max_index) * 0.3; + + int y_diff = 0; + double angle_diff = 0.0; + y_diff = 240 - (int)box_focus_y; + + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + + float tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + float temp_height = (float)sin((double)tof_degree * (double)(PI / 180)) * depth; + + float tof_height = 0.0; + if (tofData.enable_tof_ground) { + tof_height = temp_height - g_ground_tof_height; + } + else { + tof_height = temp_height; + } + + float tof_distance = (float)fabs(cos((double)tof_degree * (double)(PI / 180))) * depth; + + (*get_bbox_distance) = (float)(((float)(int)(tof_distance * 1000.0))/1000.0); + (*get_bbox_height) = (float)(((float)(int)(tof_height * 1000.0))/1000.0); + } + else { + + } + } +} + +float getToFDepthByPixel(int x, int y) +{ + char *tof_ip = "http://127.0.0.1"; + // char *tof_ip = "http://localhost"; + char tof_curl_url[512] = { 0 }; + char tof_curl_sendbuf[1] = { 0 }; + char tof_curl_username[128] = { 0 }; + char tof_curl_password[128] = { 0 }; + char *method = "GET"; + // int tof_port = atoi(accountData[0].account_port); + int tof_port = 5621; + strcat(tof_curl_username, accountData[0].account_username); + strcat(tof_curl_password, accountData[0].account_password); + + char outputData[1024] = { 0 }; + + sprintf(tof_curl_url, "http://127.0.0.1:5621/getdepth?x=%d&y=%d", x, y); + + //printf("[tof.c] curl URL : %s\n", tof_curl_url); + + send_request_to_tof(tof_ip, tof_curl_url, tof_curl_sendbuf, tof_curl_username, tof_curl_password, method, tof_port, outputData); + + //printf("[tof.c] tof driver response (depth): %s\n", outputData); + + float depth = atof(outputData); + + return depth; +} + +void build_tof_data_json() +{ + cJSON *root = NULL; + cJSON *AIToF; + + root = cJSON_CreateObject(); + + AIToF = cJSON_CreateObject(); + cJSON_AddItemToObject(root, "AIToF", AIToF); + + time_t current_time = time(0); + char c_current_time[20] = {0}; + sprintf(c_current_time, "%ld", current_time); + cJSON_AddItemToObject(AIToF, "Time", cJSON_CreateString(c_current_time)); + + // ------------------------------------------------------------------------------ + char c_global_min[20] = {0}; + sprintf(c_global_min, "%f", g_min_tof_range); + cJSON_AddItemToObject(AIToF, "min_tof_range", cJSON_CreateString(c_global_min)); + + char c_global_min_x[20] = {0}; + sprintf(c_global_min_x, "%d", g_min_tof_range_x); + cJSON_AddItemToObject(AIToF, "global_min_x", cJSON_CreateString(c_global_min_x)); + + char c_global_min_y[20] = {0}; + sprintf(c_global_min_y, "%d", g_min_tof_range_y); + cJSON_AddItemToObject(AIToF, "global_min_y", cJSON_CreateString(c_global_min_y)); + // ------------------------------------------------------------------------------ + char c_global_max[20] = {0}; + sprintf(c_global_max, "%f", g_max_tof_range); + cJSON_AddItemToObject(AIToF, "max_tof_range", cJSON_CreateString(c_global_max)); + + char c_global_max_x[20] = {0}; + sprintf(c_global_max_x, "%d", g_max_tof_range_x); + cJSON_AddItemToObject(AIToF, "global_max_x", cJSON_CreateString(c_global_max_x)); + + char c_global_max_y[20] = {0}; + sprintf(c_global_max_y, "%d", g_max_tof_range_y); + cJSON_AddItemToObject(AIToF, "global_max_y", cJSON_CreateString(c_global_max_y)); + // ------------------------------------------------------------------------------ + + char c_unit[20] = {0}; + sprintf(c_unit, "%s", "m"); + cJSON_AddItemToObject(AIToF, "unit", cJSON_CreateString(c_unit)); + + char *JsonString = NULL; + + if (root) + { + JsonString = cJSON_PrintUnformatted(root); + // printf("\n[tof.c] JsonString:%s\n", JsonString); + + // if (g_switch_tof_data_json == 0) + // { + strcpy(g_tof_data_json, JsonString); + // g_switch_tof_data_json = 1; + // } + } + + if (JsonString != NULL) + { + free(JsonString); + JsonString = NULL; + } + + if (root) + { + cJSON_Delete(root); + root = NULL; + } + +} + +float min = 0; +float max = 0; +int minX, minY, maxX, maxY; + +void YUV420toRGB(pixel_yuv * yuv, unsigned char * rgb) +{ + int y, u, v; + int r, g, b; + + y = yuv->y; + u = yuv->u - 128; + v = yuv->v - 128; + + r = (int)(y + 1.13983*v); + g = (int)(y - 0.39465*u - 0.58060*v); + b = (int)(y + 2.03211*u); + + // Clamp RGB values to 0-255 range + unsigned char red = (unsigned char)(r < 0 ? 0 : (r > 255 ? 255 : r)); + unsigned char green = (unsigned char)(g < 0 ? 0 : (g > 255 ? 255 : g)); + unsigned char blue = (unsigned char)(b < 0 ? 0 : (b > 255 ? 255 : b)); + + // Combine RGB values into a 32-bit integer + int rgb_int = (red << 16) + (green << 8) + blue; + + // Store the 32-bit integer in the output array + *((int*)rgb) = rgb_int; +} + + +char* pcd_str(int buffer_size, int width, int height) { + char* pcd_buffer = malloc(buffer_size); + sprintf(pcd_buffer, "# .PCD v.7 - Point Cloud Data file format\n" + "VERSION .7\n" + "FIELDS x y z\n" + "SIZE 4 4 4\n" + "TYPE F F F\n" + "COUNT 1 1 1\n" + "WIDTH %d\n" + "HEIGHT %d\n" + "POINTS %d\n" + "VIEWPOINT 0 0 0 1 0 0 0\n" + "DATA ascii\n", + width, height, width*height); + return pcd_buffer; +} + +// 取得 ToF PCD Data +void *thread_getTofPCDData(void *ptr){ + pthread_detach(pthread_self()); + char buffer_L[256] = { 0 }; + char buffer_M[256] = { 0 }; + char buffer_S[256] = { 0 }; + + tof_pcd_buffer_L = (char*)malloc(TOF_BUFFER_SIZE_L); + tof_pcd_buffer_M = (char*)malloc(TOF_BUFFER_SIZE_M); + tof_pcd_buffer_S = (char*)malloc(TOF_BUFFER_SIZE_S); + + while (bTofDataStart) { + if( !g_bIsWritingPCD ){ + //pthread_mutex_lock(&mutex_tof_data); + + //============================================================================ + char* pcd_buffer_M = pcd_str(TOF_BUFFER_SIZE_M, NEW_WIDTH_160, NEW_HEIGHT_120); + + // 將 640*480 縮小為 160*120 的 PCD Data + for (int i = 0; i < NEW_HEIGHT_120; i++){ + for (int j = 0; j < NEW_WIDTH_160; j++){ + // 計算要取的像素點的索引 + int x = i * ORI_HEIGHT / NEW_HEIGHT_120; + int y = j * ORI_WIDTH / NEW_WIDTH_160; + int original_index = x * ORI_WIDTH + y; + + memset(buffer_M, 0, sizeof(buffer_M)); + sprintf(buffer_M, "%d %d %f\n", i+1, j+1, tof_raw_arr_pcd->data[original_index]*100); + strcat(pcd_buffer_M, buffer_M); + } + } + // 將 PCD 的字串放入記憶體 + pthread_mutex_lock(&mutex_write_pcd_data_M); + memcpy(tof_pcd_buffer_M, pcd_buffer_M, strlen(pcd_buffer_M)); + pthread_mutex_unlock(&mutex_write_pcd_data_M); + + if (pcd_buffer_M) { + free(pcd_buffer_M); + pcd_buffer_M = NULL; + } + + //============================================================================ + char* pcd_buffer_S = pcd_str(TOF_BUFFER_SIZE_S, NEW_WIDTH_80, NEW_HEIGHT_60); + + // 將 640*480 縮小為 80*60 的 PCD Data + for (int i = 0; i < NEW_HEIGHT_60; i++){ + for (int j = 0; j < NEW_WIDTH_80; j++){ + // 計算要取的像素點的索引 + int x = i * ORI_HEIGHT / NEW_HEIGHT_60; + int y = j * ORI_WIDTH / NEW_WIDTH_80; + int original_index = x * ORI_WIDTH + y; + + memset(buffer_S, 0, sizeof(buffer_S)); + sprintf(buffer_S, "%d %d %f\n", i+1, j+1, tof_raw_arr_pcd->data[original_index]*100); + strcat(pcd_buffer_S, buffer_S); + } + } + + // 將 PCD 的字串放入記憶體 + pthread_mutex_lock(&mutex_write_pcd_data_S); + memcpy(tof_pcd_buffer_S, pcd_buffer_S, strlen(pcd_buffer_S)); + pthread_mutex_unlock(&mutex_write_pcd_data_S); + + if (pcd_buffer_S) { + free(pcd_buffer_S); + pcd_buffer_S = NULL; + } + + //pthread_mutex_unlock(&mutex_tof_data); + g_bIsWritingPCD = 0; + } + + if(bTofDataFileStart == 0){ + pthread_mutex_lock(&mutex_write_pcd_data_L); + FILE *file = fopen("/emmc/plugin/Aida/pcl/pcd/tof_pcd_data_L.txt", "w+"); + if (file == NULL) { + printf("Error creating file!\n"); + } + else { + + // Header + fprintf(file, "# .PCD v.7 - Point Cloud Data file format\n"); + fprintf(file, "VERSION .7\n"); + fprintf(file, "FIELDS x y z\n"); + fprintf(file, "SIZE 4 4 4\n"); + fprintf(file, "TYPE F F F\n"); + fprintf(file, "COUNT 1 1 1\n"); + fprintf(file, "WIDTH 640\n"); + fprintf(file, "HEIGHT 480\n"); + fprintf(file, "POINTS 307200\n"); + fprintf(file, "VIEWPOINT 0 0 0 1 0 0 0\n"); + fprintf(file, "DATA ascii1\n"); + + for (int i = 0; i < ORI_HEIGHT; i++) { + for (int j = 0; j < ORI_WIDTH; j++) { + fprintf(file, "%d %d %f\n", i + 1, j + 1, tof_raw_arr_pcd_L->data[i*ORI_WIDTH + j] * 100); + // 關於RGB 上色的部分 + // int idx = i * ORI_WIDTH + j; + // pixel_yuv yuv = tof_yuv_arr_tmp->yuv_data[idx]; + // unsigned char rgb[3]; + // YUV420toRGB(&yuv, rgb); + // uint32_t rgb_uint32 = ((uint32_t)rgb[0] << 16) | ((uint32_t)rgb[1] << 8) | (uint32_t)rgb[2]; + // fprintf(file, "%d %d %f %u\n", i+1, j+1, tof_raw_arr_pcd_L->data[idx] * 100, rgb_uint32); + } + + + } + + } + + if (file != NULL) { + fclose(file); + file = NULL; + } + + pthread_mutex_unlock(&mutex_write_pcd_data_L); + + bTofDataFileStart = 1; + } + + // printf("[tof_driver] tof_pcd_buffer: %s\n ", tof_pcd_buffer_L); + usSleep(3000); + + } + if (tof_pcd_buffer_L != NULL) { + free(tof_pcd_buffer_L); + tof_pcd_buffer_L = NULL; + } + if (tof_pcd_buffer_M != NULL) { + free(tof_pcd_buffer_M); + tof_pcd_buffer_M = NULL; + } + if (tof_pcd_buffer_S != NULL) { + free(tof_pcd_buffer_S); + tof_pcd_buffer_S = NULL; + } + pthread_exit(NULL); +} + +// 取得 ToF Data +void *thread_getTofData(void *ptr) { + pthread_detach(pthread_self()); + + // 分配記憶體空間 + tof_raw_arr_tmp = malloc( sizeof *tof_raw_arr ); + tof_raw_arr_pcd = malloc( sizeof *tof_raw_arr ); + tof_raw_arr_pcd_L = malloc( sizeof *tof_raw_arr ); + // tof_yuv_arr_tmp = malloc( sizeof *tof_yuv_arr ); + // send PCD to gynet + if (pthread_create(&tof_pcd_thread_id, NULL, thread_getTofPCDData, NULL)) + printf(" [tof.c] Create send tof PCD thread failed !\n"); + + // 判斷是否跳出 + int is_duplicate = 0; + + while(bTofDataStart){ + //pthread_mutex_lock(&mutex_tof_data); + + // 對映記憶體共享區 + tof_raw_arr = Correspond_Memory(tof_depth_shmid); + if (tof_raw_arr == (void *)-1) { + perror(" [tof.c] Mapping RAW shared memory failed !\n"); + break; + } + else { + // tof_yuv_arr = Correspond_Memory_YUV(tof_yuv_shmid); + // if (tof_yuv_arr == (void *)-1) { + // perror(" [tof.c] Mapping YUV shared memory failed !\n"); + // } + + // 先檢查相同的 frame 之前有沒有進來過 + for (long i = 0; i < RBUF_SIZE; i++) { + // 比對 index 有一樣的 index 就不要這個 data + if ((long long)(tof_ring_buffer.buf[i]) == (long long)(tof_raw_arr->index)) { + is_duplicate = 1; + break; + } + } + + if (is_duplicate == 0) { + // 緩衝區已滿,嘗試插入會失敗 + if (ringbuf_full(&tof_ring_buffer)) { + // 從緩衝區中刪除一些 index + (void)ringbuf_get(&tof_ring_buffer); + } + // 再次插入 + ringbuf_put(&tof_ring_buffer, tof_raw_arr->index); + + pthread_mutex_lock(&mutex_get_depth); + memcpy(tof_raw_arr_tmp, tof_raw_arr, sizeof *tof_raw_arr); + memcpy(tof_raw_arr_pcd, tof_raw_arr, sizeof *tof_raw_arr); + memcpy(tof_raw_arr_pcd_L, tof_raw_arr, sizeof *tof_raw_arr); + // memcpy(tof_yuv_arr_tmp , tof_yuv_arr, sizeof *tof_yuv_arr ); + pthread_mutex_unlock(&mutex_get_depth); + + + // Find min max + min = 7.4; + max = 0.0; + int max_i = 0; + int min_i = 0; + + for (int i = 0; i < ORI_WIDTH*ORI_HEIGHT; i++) { + if (tof_raw_arr->data[i] > max) { + max = tof_raw_arr->data[i]; + max_i = i; + } + if (tof_raw_arr->data[i] < min && tof_raw_arr->data[i] > 0.01) { + min = tof_raw_arr->data[i]; + min_i = i; + } + } + + maxX = max_i % ORI_WIDTH; + maxY = max_i / ORI_WIDTH; + minX = min_i % ORI_WIDTH; + minY = min_i / ORI_WIDTH; + + if (maxX < 1) { + maxX = 1; + } + + if (maxY < 1) { + maxY = 1; + } + + if (minX < 1) { + minX = 1; + } + + if (minY < 1) { + minY = 1; + } + + g_min_tof_range_x = minX; + g_min_tof_range_y = minY; + g_min_tof_range = min; + g_max_tof_range_x = maxX; + g_max_tof_range_y = maxY; + g_max_tof_range = max; + + if (tofData.enable_tof_ground) { + int pixelX = atoi(tofData.ground_x); + int pixelY = atoi(tofData.ground_y); + //g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); + g_ground_tof_range = (float)getDepth(pixelX, pixelY); + + int y_diff = 240 - pixelY; + double angle_diff = 0.0; + if (y_diff != 0) + { + angle_diff = 23.6 * ((double)y_diff / 240.0); + } + g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); + g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); + g_tof_device_height = g_ground_tof_height; + } + } + else { + is_duplicate = 0; + } + // 移除共享記憶體對映 + if (tof_raw_arr != (void *)-1) { + Free_ShareMemory(tof_raw_arr); + } + //pthread_mutex_unlock(&mutex_tof_data); + } + usSleep(1000); + } + + //share_memory_stop(); + pthread_exit(NULL); +} + +void share_memory_stop(){ + bTofDataStart = 0; + // 移除共享記憶體 + printf("\nshare_memory_stop 1\n"); + if (tof_depth_shmid == -1) { + printf("\nshare_memory_stop 2\n"); + Delete_ShareMemory(tof_depth_shmid); + printf("\nshare_memory_stop 3\n"); + } + // 重置緩衝區計數或完全清除內容 + ringbuf_flush(&tof_ring_buffer, RBUF_CLEAR); + printf("\nshare_memory_stop 4\n"); + // Delete_ShareMemory(tof_yuv_shmid); + if (tof_raw_arr_tmp) { + free(tof_raw_arr_tmp); + tof_raw_arr_tmp = NULL; + } + printf("\nshare_memory_stop 5\n"); + if (tof_raw_arr_pcd) { + free(tof_raw_arr_pcd); + tof_raw_arr_pcd = NULL; + } + printf("\nshare_memory_stop 6\n"); + if (tof_raw_arr_pcd_L) { + free(tof_raw_arr_pcd_L); + tof_raw_arr_pcd_L = NULL; + } + printf("\nshare_memory_stop 7\n"); +} + +// 初始化記憶體共享區 +int Initial_ShareMemory(long data_size, int gibberish ){ + // 1. 建立記憶體共享區 + /* shmget(key_t key, size_t size, int shmflg) + key: 一個非零整數,兩個程序需保持一致,即兩個程序之間通訊的鑰匙 + size: 申請的共享區的大小,單位是位元組。需要是記憶體頁大小的整數倍 + shmflg: 設定檔案訪問許可權(IPC_CREAT 表示共享區不存在則建立) + */ + int key = ftok("/tmp", gibberish); + int shmid = shmget(key, data_size, 0666 | IPC_CREAT); + return shmid; + +} +// 對映記憶體共享區(for depth values) +frameimage* Correspond_Memory (int shmid){ + // 2. 對映記憶體共享區 + /* *shmat(int shmid, const void *shmaddr, int shmflg) + shmid: 建立時候返回的 id 值 + shmaddr: 將共享記憶體對映到指定地址,可以為 NULL,此時系統將自動分配地址 + shmflg: 同 shmget 函式中的引數,通常為 0 + */ + return (frameimage *) shmat(shmid, NULL, 0); +} +// 對映記憶體共享區(for YUV values) +frameimage_yuv* Correspond_Memory_YUV (int shmid){ + // 2. 對映記憶體共享區 + /* *shmat(int shmid, const void *shmaddr, int shmflg) + shmid: 建立時候返回的 id 值 + shmaddr: 將共享記憶體對映到指定地址,可以為 NULL,此時系統將自動分配地址 + shmflg: 同 shmget 函式中的引數,通常為 0 + */ + return (frameimage_yuv *) shmat(shmid, NULL, 0); +} + +// 讀取資料(測試用) +void Receive_Data_ShareMemory(frameimage_yuv *arr){ + for(int i = 0 ; i < 20 ; i++){ + printf("The index for reading shared memory is[%d]: %d,%d,%d\n",i, arr->yuv_data[i].y , arr->yuv_data[i].u, arr->yuv_data[i].v); + } +} +// 釋放記憶體共享區(for depth values) +char Free_ShareMemory(frameimage *arr){ + if (shmdt((void *) arr) == -1) { + perror(" [tof.c] Free depth shared memory failed !\n"); + return -1; + } + return 0; +} +// 釋放記憶體共享區(for YUV values) +char Free_ShareMemory_YUV(frameimage_yuv *arr){ + if (shmdt((void *) arr) == -1) { + perror(" [tof.c] Free YUV shared memory failed!\n"); + return -1; + } + return 0; +} +// 移除記憶體共享區 +char Delete_ShareMemory(int shmid){ + if (shmctl(shmid, IPC_RMID, 0) == -1) { + perror(" [tof.c] Remove shared memory failed!\n"); + return -1; + } + return 0; +} +// 生成影像編號 +long long Number_generator(){ + clock_t tv; + tv = clock(); + return tv; +} +// 初始化 +void ringbuf_init(rbuf_t* _this){ + // clear the _thisfer and init the values + // and sets head = tail in one go + memset( _this, 0, sizeof(*_this) ); +} +// 判斷是否為空 +bool ringbuf_empty(rbuf_t* _this){ + // test if the queue is empty + // 0 returns true + // nonzero false + return (0 == _this->count); +} +// 判斷是否已滿 +bool ringbuf_full(rbuf_t* _this){ + // full when no of elements exceed the max size + return (_this->count >= RBUF_SIZE); +} +// 從列表後端獲取一個字節 +long long ringbuf_get(rbuf_t* _this){ + long long item; + if (_this->count > 0){ + // get item element + item = _this->buf[_this->tail]; + // advance the tail + _this->tail = ringbuf_adv(_this->tail, RBUF_SIZE); + // reduce the total count + --_this->count; + }else { + // the queue is empty + item = RBUF_EMPTY; + } + return item; +} +// 向列表最前端插入一個字節 +void ringbuf_put(rbuf_t* _this, long long item){ + if (_this->count < RBUF_SIZE){ + // set the item at head position + _this->buf[_this->head] = item; + // advance the head + _this->head = ringbuf_adv(_this->head, RBUF_SIZE); + // increase the total count + ++_this->count; + } +} +// 查看隊列中的第一個元素 +long long ringbuf_peek(rbuf_t* _this){ + if (_this->count != 0){ + return _this->buf[_this->tail]; + } + return 0; +} +// 印出資料 +void ringbuf_print(rbuf_t* _this){ + for (int i = 0; i < RBUF_SIZE; i++){ + printf(",%lld ", _this->buf[i]); + } + printf("\n"); +} +// 刷新列表並清除緩衝區 +void ringbuf_flush(rbuf_t* _this, rbuf_opt_e clear){ + _this->count = 0; + _this->head = 0; + _this->tail = 0; + + // optionally clear + if (RBUF_CLEAR == clear){ + memset(_this->buf, 0, sizeof(_this->buf)); + } +} +// 推進緩衝區的 index +unsigned int ringbuf_adv(const unsigned int value, const unsigned int max){ + unsigned int index = value + 1; + if (index >= max){ + index = 0; + } + return index; +} \ No newline at end of file diff --git a/src/tof.h b/src/tof.h new file mode 100644 index 0000000..200e28c --- /dev/null +++ b/src/tof.h @@ -0,0 +1,164 @@ + +#pragma once +#ifndef _TOF_H_ +#define _TOF_H_ +#include "define_inc.h" +#include "utility.h" +#include "nweb.h" +#include <stdbool.h> +#include "cgicmd.h" + +#define TOF_WIDTH 640 +#define TOF_HEIGHT 480 +//#define TOF_SIZE TOF_WIDTH * TOF_HEIGHT * 4 +#define ORI_WIDTH 640 +#define ORI_HEIGHT 480 +#define NEW_WIDTH_320 320 +#define NEW_HEIGHT_240 240 +#define NEW_WIDTH_160 160 +#define NEW_HEIGHT_120 120 +#define NEW_WIDTH_80 80 +#define NEW_HEIGHT_60 60 +#define TOF_BUFFER_SIZE_L 6000000 +#define TOF_BUFFER_SIZE_M 400000 +#define TOF_BUFFER_SIZE_S 400000 +#define CHUNK_SIZE 1024*5 + +// 緩衝區大小 +#define RBUF_SIZE 10 + +// 影像深度值結構 +typedef struct frame +{ + long long index; + float data[TOF_WIDTH*TOF_HEIGHT]; + +} frameimage; + +// 像素 YUV 結構 +typedef struct yuv +{ + unsigned char y; + unsigned char u; + unsigned char v; +} pixel_yuv; + +// 影像 YUV 結構 +typedef struct frame_yuv +{ + long long index; + pixel_yuv yuv_data[TOF_WIDTH*TOF_HEIGHT]; +} frameimage_yuv; + +// 緩衝區結構 +typedef struct ring_buf_s +{ + long long buf[RBUF_SIZE]; + long count; // 隊列中的元素總數 <= RBUF_SIZE + long head; // 新數據寫入緩衝區的這個位置 + long tail; // 從緩衝區中的這個位置讀取數據 +} rbuf_t; + +// 緩衝區操作 +typedef enum +{ + RBUF_CLEAR, + RBUF_NO_CLEAR +} rbuf_opt_e; + +// 緩衝區狀態 +typedef enum +{ + RBUF_EMPTY = -1, + RBUF_FULL +} rbuf_msg_e; + +extern int g_switch_tof_data_json; +extern char g_tof_data_json[BUFSIZE_V3]; +extern pthread_mutex_t mutex_send_cgi; +extern pthread_mutex_t mutex_get_depth; +//extern pthread_mutex_t mutex_tof_data; +extern pthread_mutex_t mutex_write_pcd_data; +extern pthread_mutex_t mutex_write_pcd_data_L; +extern pthread_mutex_t mutex_write_pcd_data_M; +extern pthread_mutex_t mutex_write_pcd_data_S; + + +extern CURL* g_http_handle; +extern pthread_mutex_t mutex_curl; + +extern char* tof_pcd_buffer_L; +extern char* tof_pcd_buffer_M; +extern char* tof_pcd_buffer_S; +extern int bTofDataStart; +extern int bTofDataFileStart; +extern int tof_depth_shmid; +extern int tof_yuv_shmid; + +extern rbuf_t tof_ring_buffer; + +extern TofInfo tofData; + +extern float g_ground_tof_range; + +extern float g_ground_tof_degree; +extern float g_ground_tof_height; +extern float g_ground_tof_distance; + +extern double g_tof_device_height; + + +// 取得某點的深度值 +double getDepth(int depthMapX, int depthMapY); +void get_bbox_distance_and_height(float box_left_x, float box_top_y, float box_width, float box_height, float *get_bbox_distance, float *get_bbox_height); +// 取得某點的深度值(for old ToF driver) +float getToFDepthByPixel(int x, int y); + +// 初始化記憶體共享區 +int Initial_ShareMemory(long data_size, int gibberish); +// 對映記憶體共享區(for depth values) +frameimage* Correspond_Memory (int shmid); +// 對映記憶體共享區(for YUV values) +frameimage_yuv* Correspond_Memory_YUV (int shmid); +// 寫入資料(測試用) +void Send_Data_ShareMemory(frameimage *arr, frameimage* oneFrame); +// 讀取資料(測試用) +void Receive_Data_ShareMemory(frameimage_yuv *arr); +// 釋放記憶體共享區(for depth values) +char Free_ShareMemory(frameimage *arr); +// 釋放記憶體共享區(for YUV values) +char Free_ShareMemory_YUV(frameimage_yuv *arr); +// 移除記憶體共享區 +char Delete_ShareMemory(int shmid); +// 生成影像編號 +long long Number_generator(); + +// 取得 ToF Data +void *thread_getTofData(void *ptr); +// 取得 ToF PCD Data +void *thread_getTofPCDData(void *ptr); + +// 初始化 +void ringbuf_init(rbuf_t* _this); +// 判斷是否為空 +bool ringbuf_empty(rbuf_t* _this); +// 判斷是否已滿 +bool ringbuf_full(rbuf_t* _this); +// 從列表後端獲取一個字節 +long long ringbuf_get(rbuf_t* _this); +// 向列表最前端插入一個字節 +void ringbuf_put(rbuf_t* _this, long long item); +// 查看隊列中的第一個元素 +long long ringbuf_peek(rbuf_t* _this); +// 刷新列表並清除緩衝區 +void ringbuf_flush(rbuf_t* _this, rbuf_opt_e clear); +// 印出緩衝區的資料 +void ringbuf_print(rbuf_t* _this); +// 推進緩衝區的 index +unsigned int ringbuf_adv (const unsigned int value, const unsigned int max_val); + +void share_memory_stop(); + +void build_tof_data_json(); + +#endif \ No newline at end of file diff --git a/src/tree.c b/src/tree.c new file mode 100644 index 0000000..67b6d43 --- /dev/null +++ b/src/tree.c @@ -0,0 +1,139 @@ +#include <stdio.h> +#include <stdlib.h> +#include "tree.h" +#include "utils.h" +#include "data.h" + +void change_leaves(tree *t, char *leaf_list) +{ + list *llist = get_paths(leaf_list); + char **leaves = (char **)list_to_array(llist); + int n = llist->size; + int i,j; + int found = 0; + for(i = 0; i < t->n; ++i){ + t->leaf[i] = 0; + for(j = 0; j < n; ++j){ + if (0==strcmp(t->name[i], leaves[j])){ + t->leaf[i] = 1; + ++found; + break; + } + } + } + fprintf(stderr, "Found %d leaves.\n", found); +} + +float get_hierarchy_probability(float *x, tree *hier, int c, int stride) +{ + float p = 1; + while(c >= 0){ + p = p * x[c*stride]; + c = hier->parent[c]; + } + return p; +} + +void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves, int stride) +{ + int j; + for(j = 0; j < n; ++j){ + int parent = hier->parent[j]; + if(parent >= 0){ + predictions[j*stride] *= predictions[parent*stride]; + } + } + if(only_leaves){ + for(j = 0; j < n; ++j){ + if(!hier->leaf[j]) predictions[j*stride] = 0; + } + } +} + +int hierarchy_top_prediction(float *predictions, tree *hier, float thresh, int stride) +{ + float p = 1; + int group = 0; + int i; + while(1){ + float max = 0; + int max_i = 0; + + for(i = 0; i < hier->group_size[group]; ++i){ + int index = i + hier->group_offset[group]; + float val = predictions[(i + hier->group_offset[group])*stride]; + if(val > max){ + max_i = index; + max = val; + } + } + if(p*max > thresh){ + p = p*max; + group = hier->child[max_i]; + if(hier->child[max_i] < 0) return max_i; + } else if (group == 0){ + return max_i; + } else { + return hier->parent[hier->group_offset[group]]; + } + } + return 0; +} + +tree *read_tree(char *filename) +{ + tree t = {0}; + FILE *fp = fopen(filename, "r"); + + char *line; + int last_parent = -1; + int group_size = 0; + int groups = 0; + int n = 0; + while((line=fgetl(fp)) != 0){ + char *id = calloc(256, sizeof(char)); + int parent = -1; + sscanf(line, "%s %d", id, &parent); + t.parent = realloc(t.parent, (n+1)*sizeof(int)); + t.parent[n] = parent; + + t.child = realloc(t.child, (n+1)*sizeof(int)); + t.child[n] = -1; + + t.name = realloc(t.name, (n+1)*sizeof(char *)); + t.name[n] = id; + if(parent != last_parent){ + ++groups; + t.group_offset = realloc(t.group_offset, groups * sizeof(int)); + t.group_offset[groups - 1] = n - group_size; + t.group_size = realloc(t.group_size, groups * sizeof(int)); + t.group_size[groups - 1] = group_size; + group_size = 0; + last_parent = parent; + } + t.group = realloc(t.group, (n+1)*sizeof(int)); + t.group[n] = groups; + if (parent >= 0) { + t.child[parent] = groups; + } + ++n; + ++group_size; + } + ++groups; + t.group_offset = realloc(t.group_offset, groups * sizeof(int)); + t.group_offset[groups - 1] = n - group_size; + t.group_size = realloc(t.group_size, groups * sizeof(int)); + t.group_size[groups - 1] = group_size; + t.n = n; + t.groups = groups; + t.leaf = calloc(n, sizeof(int)); + int i; + for(i = 0; i < n; ++i) t.leaf[i] = 1; + for(i = 0; i < n; ++i) if(t.parent[i] >= 0) t.leaf[t.parent[i]] = 0; + + fclose(fp); + tree *tree_ptr = calloc(1, sizeof(tree)); + *tree_ptr = t; + //error(0); + return tree_ptr; +} diff --git a/src/tree.h b/src/tree.h new file mode 100644 index 0000000..667dbc7 --- /dev/null +++ b/src/tree.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef TREE_H +#define TREE_H +#include "define_inc.h" +typedef struct { + int *leaf; + int n; + int *parent; + int *child; + int *group; + char **name; + + int groups; + int *group_size; + int *group_offset; +} tree; +tree *read_tree(char *filename); +int hierarchy_top_prediction(float *predictions, tree *hier, float thresh, int stride); +float get_hierarchy_probability(float *x, tree *hier, int c, int stride); + +void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves, int stride); +void change_leaves(tree *t, char *leaf_list); + +#endif diff --git a/src/udp_bbox.h b/src/udp_bbox.h new file mode 100644 index 0000000..ac64988 --- /dev/null +++ b/src/udp_bbox.h @@ -0,0 +1,7 @@ +#pragma once +#ifndef UDP_BBOX_H +#define UDP_BBOX_H +#include "define_inc.h" + + +#endif //ifdef UDP_BBOX_H \ No newline at end of file diff --git a/src/upsample_layer.c b/src/upsample_layer.c new file mode 100644 index 0000000..d17bf59 --- /dev/null +++ b/src/upsample_layer.c @@ -0,0 +1,145 @@ +#include "upsample_layer.h" +#include "cuda.h" +#include "blas.h" + +#include <stdio.h> + +layer make_upsample_layer(int batch, int w, int h, int c, int stride) +{ + layer l = {0}; + l.type = UPSAMPLE; + l.batch = batch; + l.w = w; + l.h = h; + l.c = c; + l.out_w = w*stride; + l.out_h = h*stride; + l.out_c = c; + if(stride < 0){ + stride = -stride; + l.reverse=1; + l.out_w = w/stride; + l.out_h = h/stride; + } + l.stride = stride; + l.outputs = l.out_w*l.out_h*l.out_c; + l.inputs = l.w*l.h*l.c; + l.delta = calloc(l.outputs*batch, sizeof(float)); + l.output = calloc(l.outputs*batch, sizeof(float));; + + l.forward = forward_upsample_layer; + l.backward = backward_upsample_layer; + #ifdef GPU + l.forward_gpu = forward_upsample_layer_gpu; + l.backward_gpu = backward_upsample_layer_gpu; + + l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch); + l.output_gpu = cuda_make_array(l.output, l.outputs*batch); + #endif + if(l.reverse) fprintf(stderr, "downsample %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + else fprintf(stderr, "upsample %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + return l; +} + +void resize_upsample_layer(layer *l, int w, int h) +{ + l->w = w; + l->h = h; + l->out_w = w*l->stride; + l->out_h = h*l->stride; + if(l->reverse){ + l->out_w = w/l->stride; + l->out_h = h/l->stride; + } + l->outputs = l->out_w*l->out_h*l->out_c; + l->inputs = l->h*l->w*l->c; + l->delta = realloc(l->delta, l->outputs*l->batch*sizeof(float)); + l->output = realloc(l->output, l->outputs*l->batch*sizeof(float)); + +#ifdef GPU + cuda_free(l->output_gpu); + cuda_free(l->delta_gpu); + l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); + l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch); +#endif + +} + +void forward_upsample_layer(const layer l, network net) +{ + fill_cpu(l.outputs*l.batch, 0, l.output, 1); + if(l.reverse){ + upsample_cpu(l.output, l.out_w, l.out_h, l.c, l.batch, l.stride, 0, l.scale, net.input); + }else{ + upsample_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.scale, l.output); + } +} + +void backward_upsample_layer(const layer l, network net) +{ + if(l.reverse){ + upsample_cpu(l.delta, l.out_w, l.out_h, l.c, l.batch, l.stride, 1, l.scale, net.delta); + }else{ + upsample_cpu(net.delta, l.w, l.h, l.c, l.batch, l.stride, 0, l.scale, l.delta); + } +} + +#ifdef GPU +void forward_upsample_layer_gpu(const layer l, network net) +{ + fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1); + if(l.reverse){ + upsample_gpu(l.output_gpu, l.out_w, l.out_h, l.c, l.batch, l.stride, 0, l.scale, net.input_gpu); + }else{ + upsample_gpu(net.input_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, l.scale, l.output_gpu); + } +} + +void backward_upsample_layer_gpu(const layer l, network net) +{ + if(l.reverse){ + upsample_gpu(l.delta_gpu, l.out_w, l.out_h, l.c, l.batch, l.stride, 1, l.scale, net.delta_gpu); + }else{ + upsample_gpu(net.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, l.scale, l.delta_gpu); + } +} +#endif + +#ifdef ALLEN_MODIFIED +layer make_upsample_layer_mem(int batch, int w, int h, int c, int stride) +{ + layer l = { 0 }; + l.type = UPSAMPLE; + l.batch = batch; + l.w = w; + l.h = h; + l.c = c; + l.out_w = w * stride; + l.out_h = h * stride; + l.out_c = c; + if (stride < 0) { + stride = -stride; + l.reverse = 1; + l.out_w = w / stride; + l.out_h = h / stride; + } + l.stride = stride; + l.outputs = l.out_w*l.out_h*l.out_c; + l.inputs = l.w*l.h*l.c; + l.delta = calloc(l.outputs*batch, sizeof(float)); + l.output = calloc(l.outputs*batch, sizeof(float));; + + l.forward = forward_upsample_layer; + l.backward = backward_upsample_layer; +#ifdef GPU + l.forward_gpu = forward_upsample_layer_gpu; + l.backward_gpu = backward_upsample_layer_gpu; + + l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch); + l.output_gpu = cuda_make_array(l.output, l.outputs*batch); +#endif + //if (l.reverse) fprintf(stderr, "downsample %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + //else fprintf(stderr, "upsample %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + return l; +} +#endif \ No newline at end of file diff --git a/src/upsample_layer.h b/src/upsample_layer.h new file mode 100644 index 0000000..63cb8e5 --- /dev/null +++ b/src/upsample_layer.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef UPSAMPLE_LAYER_H +#define UPSAMPLE_LAYER_H +//#include "darknet.h" +#include "define_inc.h" +#include "layer.h" +#include "network.h" +#include "option_list.h" + +layer make_upsample_layer(int batch, int w, int h, int c, int stride); +void forward_upsample_layer(const layer l, network net); +void backward_upsample_layer(const layer l, network net); +void resize_upsample_layer(layer *l, int w, int h); + +#ifdef GPU +void forward_upsample_layer_gpu(const layer l, network net); +void backward_upsample_layer_gpu(const layer l, network net); +#endif + +#ifdef ALLEN_MODIFIED +layer make_upsample_layer_mem(int batch, int w, int h, int c, int stride); +#endif + +#endif diff --git a/src/url_encode.c b/src/url_encode.c new file mode 100644 index 0000000..7de9fd2 --- /dev/null +++ b/src/url_encode.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <sys/types.h> + +static unsigned char hexchars[] = "0123456789ABCDEF"; +/** + * 16iഫ10i + * pG0xE4=14*16+4=228 + */ +static int c_htoi(char *s) +{ + int value; + int c; + + c = ((unsigned char *)s)[0]; + if (isupper(c)) + c = tolower(c); + value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; + + c = ((unsigned char *)s)[1]; + if (isupper(c)) + c = tolower(c); + value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; + + return (value); +} + + +char *url_encode(char const *s, int len, int *new_length) +{ + register unsigned char c; + unsigned char *to, *start; + unsigned char const *from, *end; + + from = (unsigned char *)s; + end = (unsigned char *)s + len; + start = to = (unsigned char *)calloc(1, 3 * len + 1); + + while (from < end) + { + c = *from++; + + if (c == ' ') + { + *to++ = '+'; + } + else if ((c < '0' && c != '-' && c != '.') || + (c < 'A' && c > '9') || + (c > 'Z' && c < 'a' && c != '_') || + (c > 'z')) + { + to[0] = '%'; + to[1] = hexchars[c >> 4];//N2iഫ16is + to[2] = hexchars[c & 15];//N2iഫ16is + to += 3; + } + else + { + *to++ = c; + } + } + *to = 0; + if (new_length) + { + *new_length = to - start; + } + return (char *)start; +} + + +int url_decode(char *str, int len) +{ + char *dest = str; + char *data = str; + + while (len--) + { + if (*data == '+') + { + *dest = ' '; + } + else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) + { + *dest = (char)c_htoi(data + 1); + data += 2; + len -= 2; + } + else + { + *dest = *data; + } + data++; + dest++; + } + *dest = '\0'; + return dest - str; +} \ No newline at end of file diff --git a/src/url_encode.h b/src/url_encode.h new file mode 100644 index 0000000..08a9a35 --- /dev/null +++ b/src/url_encode.h @@ -0,0 +1,11 @@ +#pragma once +#ifndef URL_ENCODE +#define URL_ENCODE +#include "define_inc.h" +//return decode string length +int url_decode(char *str, int len); + +//return new string, have to free +char *url_encode(char const *s, int len, int *new_length); + +#endif \ No newline at end of file diff --git a/src/utility.cpp b/src/utility.cpp new file mode 100644 index 0000000..628d2b9 --- /dev/null +++ b/src/utility.cpp @@ -0,0 +1,2064 @@ +#if 1 +//#include "stdafx.h" +//#pragma pack(push,8) +//#include <tlhelp32.h> +//#pragma pack(pop) +#include <iostream> +#include <fstream> +#include "utility.h" +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <string.h> + +#include <string> +#include <regex> +#include "setting.h" +#include <list> +#include <algorithm> + +//#include <filesystem> +#include <experimental/filesystem> + +#include <sstream> +#include "exif.h" + +#include "network.h" +#include <map> +#include <deque> + +#include <unistd.h> +#include "fork_pipe_lib.h" + +#ifdef OPENCV +#include "opencv2/core/mat.hpp" +#include "cuda.h" +#endif + +#ifdef GY_OS_WIN +#include <sys\timeb.h> +#ifdef _WIN32 +#include <winsock2.h> +#include <iphlpapi.h> +#include <io.h> +#include <windows.h> +#include <process.h> +#include <winbase.h> +#include <comdef.h> +#include <tchar.h> +#include <time.h> +#ifdef _MSC_VER +#include <intrin.h> +#endif +#pragma comment(lib, "IPHLPAPI.lib") +#pragma comment(lib, "version.lib") +#else +#include <unistd.h> +#include <X11/Xlib.h> +#endif +#endif + +#include <sys/timeb.h> +#ifdef GY_OS_AMBA +#include <sys/stat.h> +#include "utils.h" +#endif + +using namespace std; + +#define WORKING_BUFFER_SIZE 15000 // Allocate a 15 KB buffer to start with. +#define MAX_TRIES 3 + + +ObjectTracking g_TrackingRecords[MAX_AI_ENGINE_VIEW][MAX_TRACKING_NUM] = { 0 }; //32*8 256 + +//ObjectTracking g_TrackingRecords[256][50] = { 0 }; + +//#ifdef GY_OS_AMBA +//ObjTrackingIDCheckItem stTrackIDCheckItem[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +//ObjTrackingIDVote stTrackingObjVote[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; +//#endif + +unsigned int g_TrackingIDAndChannel[MAX_AI_ENGINE_VIEW] = { 0 }; +static map<string, string> mapVariables; +static std::deque <QueueInfo> g_PostNotificationQueue; +static std::deque <QueueInfo> g_GetAlarmMotionQueue; + +extern int g_write_config_file_dirty_flag; + +int FileExist(char *filename) +{ +//#ifdef _WIN32 +#ifdef GY_OS_WIN + if ((_access(filename, 0)) != -1) + { + // file exists + return 1; + // Check for write permission. + // Assume file is read-only. + //if ((_access(filename, 2)) == -1) + // printf_s("File crt_ACCESS.C does not have write permission.\n"); + } + else { + // file doesn't exist + return 0; + } +#elif defined GY_OS_AMBA || defined GY_OS_NOVA + if (access(filename, F_OK) != -1) { + // file exists + return 1; + } + else { + // file doesn't exist + return 0; + } +#endif +} + +void CopyFileTo(char* src_file, char* dst_file) +{ +#ifdef GY_OS_WIN + std::ifstream src(src_file, std::ios::binary); + std::ofstream dst(dst_file, std::ios::binary); + dst << src.rdbuf(); +#endif + + FILE *fsrc = NULL, *fdst = NULL; + int nByteRead = 0; + char szBuffer[MAX_PATH]; + + if ((fsrc = fopen(src_file, "r")) != NULL) { + if ((fdst = fopen(dst_file, "w+")) != NULL) { + + while ((nByteRead = fread(szBuffer, sizeof(char), MAX_PATH, fsrc)) > 0) + { + fwrite(szBuffer, sizeof(char), nByteRead, fdst); + //printf("write size = %d \n", nByteRead); + } + } + else + goto err_out; + } + else + goto err_out; + +err_out: + + fclose(fsrc); + fclose(fdst); + + +} + +size_t ReadFileSize(const char *fileName) +{ + std::ifstream fl(fileName); + fl.seekg(0, std::ios::end); + size_t len = fl.tellg(); + return len; +} + +char* ReadAllBytes(const char *fileName) //You must free the result +{ + std::ifstream fl(fileName); + fl.seekg(0, std::ios::end); + size_t len = fl.tellg(); + char *ret = (char*)malloc(len + 1); + memset(ret, 0x00, len + 1); //20201203 sophia add + fl.seekg(0, std::ios::beg); + fl.read(ret, len); + fl.close(); + return ret; +} + +float detection_overlap_ratio(detection_pos* det1, detection_pos* det2) +{ + if (det1->left_x > det2->left_x + det2->width) { return 0.0; } + if (det1->top_y > det2->top_y + det2->height) { return 0.0; } + if (det1->left_x + det1->width < det2->left_x) { return 0.0; } + if (det1->top_y + det1->height < det2->top_y) { return 0.0; } + float colInt = abs(std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x)); + float rowInt = abs(std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y)); + float overlapArea = colInt * rowInt; //ۥBn + float area1 = det1->width * det1->height; + float area2 = det2->width * det2->height; + float smallerArea = (area1 > area2) ? area2 : area1; + return overlapArea / smallerArea; //ۥBnep + //return overlapArea / (area1 + area2 - overlapArea); //ۥBnҥejp[` +} + +float detection_overlap_ratio_union(detection_pos* det1, detection_pos* det2) +{ + if (det1->left_x > det2->left_x + det2->width) { return 0.0; } + if (det1->top_y > det2->top_y + det2->height) { return 0.0; } + if (det1->left_x + det1->width < det2->left_x) { return 0.0; } + if (det1->top_y + det1->height < det2->top_y) { return 0.0; } + float colInt = abs(std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x)); + float rowInt = abs(std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y)); + float overlapArea = colInt * rowInt; //ۥBn + float area1 = det1->width * det1->height; + float area2 = det2->width * det2->height; + //float smallerArea = (area1 > area2) ? area2 : area1; + //return overlapArea / smallerArea; //ۥBnep + return overlapArea / (area1 + area2 - overlapArea); //ۥBnҥejp[` +} + +void PrintMACaddress(char* MACAddress, unsigned char MACData[]) +{ + sprintf(MACAddress, "%02X-%02X-%02X-%02X-%02X-%02X", + MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]); +} + +void GetMACAddress(char *out_macaddr_buf) +{ + FILE *fpRead; + //char* command = (char*)"/sbin/ifconfig enp0s3 | grep 'ether' | sed 's/[:]/-/g'" ; + //AMBA: + +#ifdef GY_OS_AMBA + char* command = (char*)"timeout 3s ifconfig eth0 | grep -Eo '([[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}' | sed 's/[:]/-/g'"; +#else + char* command = (char*)"ifconfig eth0 | grep -Eo '([[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}' | sed 's/[:]/-/g'"; +#endif + + //NOVA: + //char command[512] = { 0 }; + //sprintf(command, "curl -sS -k -X GET --max-time 5 http://%s:%s@127.0.0.1:%s/server | grep -Eo '([[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}' | sed 's/[:]/-/g'", accountData[0].account_username, accountData[0].account_password, accountData[0].account_port); + + //char command[512] = { 0 }; + //sprintf(command, "curl -sS -k -X GET --max-time 5 http://%s:%s@127.0.0.1:%s/server | grep -Eo '([[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}' | sed 's/[:]/-/g'", accountData[0].account_username, accountData[0].account_password, accountData[0].account_port); + + + fpRead = vpopen(command, "r"); + + char MyIpBuf[64] = { 0 }; + char fetch_mac_addr[64] = { 0 }; + + if (fpRead != NULL) { + while (fgets(MyIpBuf, 64, fpRead) != NULL) + { + sprintf(fetch_mac_addr, "%s", MyIpBuf); + //printf("\n[utility] get_mac_addr() ==:%s %s\n", MyIpBuf,fetch_mac_addr); + } + + LowerToUpper(fetch_mac_addr); + + char* new_mac_addr_dash = StrReplace(fetch_mac_addr, "-", NULL); + char* new_mac_addr_nextline = StrReplace(fetch_mac_addr, "\n", NULL); + + sprintf(out_macaddr_buf, "%s", fetch_mac_addr); + + if (new_mac_addr_dash != NULL) { + free(new_mac_addr_dash); + new_mac_addr_dash = NULL; + } + + if (new_mac_addr_nextline != NULL) { + free(new_mac_addr_nextline); + new_mac_addr_nextline = NULL; + } + + if (fpRead != NULL) + vpclose(fpRead); + } +} + +void GetMACAddress_WithoutDash(char* out_macaddr_buf) +{ +#ifdef GY_OS_AMBA + char* command = (char*)"timeout 3s ifconfig eth0 | grep -Eo '([[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}' | sed 's/[:]/-/g'"; +#else + char* command = (char*)"ifconfig eth0 | grep -Eo '([[:xdigit:]]{1,2}[-:]){5}[[:xdigit:]]{1,2}' | sed 's/[:]/-/g'"; +#endif + + FILE* fpRead = vpopen(command, "r"); + char MyIpBuf[64] = { 0 }; + char fetch_mac_addr[64] = { 0 }; + + if (fpRead != NULL) { + while (fgets(MyIpBuf, 64, fpRead) != NULL) + { + sprintf(fetch_mac_addr, "%s", MyIpBuf); + } + + char* new_mac_addr = StrReplace(fetch_mac_addr, "-", NULL); + new_mac_addr = StrReplace(fetch_mac_addr, "\n", NULL); + sprintf(out_macaddr_buf, "%s", new_mac_addr); + + if (new_mac_addr != NULL) + { + free(new_mac_addr); + new_mac_addr = NULL; + } + + if (fpRead != NULL) + vpclose(fpRead); + } +} + +char *StrReplace(char *origion, const char *replace, const char *with) // You must free the result if result is non-NULL. +{ + char *result; // the return string + char *ins; // the next insert point + char *tmp; // varies + int len_rep; // length of rep (the string to remove) + int len_with; // length of with (the string to replace rep with) + int len_front; // distance between rep and end of last rep + int count; // number of replacements + + // sanity checks and initialization + if (!origion || !replace) + return NULL; + len_rep = strlen(replace); + if (len_rep == 0) + return NULL; // empty rep causes infinite loop during count + if (!with) + with = ""; + len_with = strlen(with); + + // count the number of replacements needed + ins = origion; + for (count = 0; (tmp = strstr(ins, replace)); ++count) { + ins = tmp + len_rep; + } + + tmp = result = (char*)malloc(strlen(origion) + (len_with - len_rep) * count + 1); + + if (!result) + return NULL; + + // first time through the loop, all the variable are set correctly + // from here on, + // tmp points to the end of the result string + // ins points to the next occurrence of rep in orig + // orig points to the remainder of orig after "end of rep" + while (count--) { + ins = strstr(origion, replace); + len_front = ins - origion; + tmp = strncpy(tmp, origion, len_front) + len_front; + tmp = strcpy(tmp, with) + len_with; + origion += len_front + len_rep; // move to next "end of rep" + } + strcpy(tmp, origion); + return result; +} + +void str_replace_all(char *target, const char *needle, const char *replacement) +{ + char buffer[1024] = { 0 }; + char *insert_point = &buffer[0]; + const char *tmp = target; + size_t needle_len = strlen(needle); + size_t repl_len = strlen(replacement); + + while (1) { + const char *p = strstr(tmp, needle); + + // walked past last occurrence of needle; copy remaining part + if (p == NULL) { + strcpy(insert_point, tmp); + break; + } + + // copy part before needle + memcpy(insert_point, tmp, p - tmp); + insert_point += p - tmp; + + // copy replacement string + memcpy(insert_point, replacement, repl_len); + insert_point += repl_len; + + // adjust pointers, move on + tmp = p + needle_len; + } + + // write altered string back to target + strcpy(target, buffer); +} + +size_t TrimSpace(char *out, size_t len, const char *str, int trim_type) +{ + if (len == 0) + return 0; + + const char *end = NULL; + size_t out_size; + + if (trim_type == 0 || trim_type == 1) + { + // Trim leading space + while (isspace((unsigned char)*str)) str++; + } + + if (*str == 0) // All characters are spaces + { + *out = 0; + return 1; + } + + if (trim_type == 0 || trim_type == 2) + { + // Trim trailing space + end = str + strlen(str) - 1; + while (end > str && isspace((unsigned char)*end)) end--; + end++; + } + + // Set output size to minimum of trimmed string length and buffer size minus 1 + out_size = (size_t)(end - str) < len - 1 ? (size_t)(end - str) : len - 1; + + // Copy trimmed string and add null terminator + memcpy(out, str, out_size); + out[out_size] = 0; + + return out_size; +} + +//int check_if_person = 0; +char *strtok_modified(char *str, const char *delim, char **saveptr) { + + + char *token = NULL; + + if (str == NULL) { + str = *saveptr; + } + + //printf("\n--------str:%s,*saveptr:%s\n",str,*saveptr); + + if (str != NULL) { + int index_to_start = 0; + int check_if_the_same = 0; + for (int i = 0; i < (int)strlen(str); i++) { + check_if_the_same = 0; + for (int j = 0; j < (int)strlen(delim); j++) { + if (str[i] == delim[j]) { + check_if_the_same = 1; + break; + } + } + if (check_if_the_same == 0) { + break; + } + else { + index_to_start++; + } + } + + + str = str + index_to_start; + //str += strspn(str, delim); + + if (*str == '\0') { + return NULL; + } + + + token = str; + + int index_to_end = 0; + int check_if_the_different = 1; + for (int i = 0; i < (int)strlen(token); i++) { + check_if_the_different = 1; + for (int j = 0; j < (int)strlen(delim); j++) { + if (token[i] == delim[j]) { + check_if_the_different = 0; + break; + } + } + if (check_if_the_different == 0) { + break; + } + else { + index_to_end++; + } + } + + str = token + index_to_end; + //str = strpbrk(token, delim); + + if (str == NULL) { + //*saveptr = token + strlen(token); + *saveptr = NULL; + } + else { + *str = '\0'; + //printf("\n---RR----str:%s\n", str); + *saveptr = str + 1; + //printf("\n---RR----*saveptr:%s\n", *saveptr); + } + } + + return token; +} + +//StrSplitlƷ|ܤơAФpߨϥΡAnO@C +int StrSplit(char *InStr, char outArr[][STRSPLIT_SIZE], const char *del) { + + + //if (strstr(InStr, "person") != NULL) + { + //check_if_person = 1; + //printf("\n--------InStr:%s\n", InStr); + } + + int num = 0; + + if (InStr != NULL) { + //pthread_mutex_lock(&mutex_strsplit); + + //if (!check_if_person) + { + + char *pLeft = NULL; + //char pLeft[MAX_MSG_LEN * 10] = { 0 }; + + + char *s = strtok_modified(InStr, del, &pLeft); + if (s != NULL) { + + char token_temp[STRSPLIT_SIZE] = { 0 }; + for (int i = 0; i < (int)strlen(s); i++) { + token_temp[i] = s[i]; + } + token_temp[strlen(s)] = '\0'; + + //if (check_if_person) + //printf("\n-------s1(%d):%s\n",strlen(token_temp), token_temp); + memcpy(outArr[num], token_temp, strlen(token_temp)); + //memcpy(*(outArr+num), token_temp,strlen(token_temp)); + num++; + //*outArr++ = s; + } + else { + num = 0; + } + //printf("\n------S-m:%s\n",s); + //printf("\n------pLeft:%s\n", pLeft); + + while (s != NULL && pLeft != NULL) { + s = strtok_modified(NULL, del, &pLeft); + if (s != NULL) { + + char token_temp[STRSPLIT_SIZE] = { 0 }; + for (int i = 0; i < (int)strlen(s); i++) { + token_temp[i] = s[i]; + } + token_temp[strlen(s)] = '\0'; + + //if (check_if_person) + //printf("\n-------s2(%d):%s\n",strlen(token_temp), token_temp); + memcpy(outArr[num], token_temp, strlen(token_temp)); + //memcpy(*(outArr + num), token_temp, strlen(token_temp)); + num++; + //*outArr++ = s; + } + else { + break; + } + } + } + + //if (check_if_person) + { + + //if (num == 1) { + //printf("\n-------num 1:%s\n", outArr[0]); + //} + //else if (num == 2) { + //printf("\n-------num 1:%s\n", outArr[0]); + //printf("\n-------num 2:%s\n", outArr[1]); + //} + + //printf("\nKKK end:%d\n", num); + //check_if_person = 0; + + } + + //pthread_mutex_unlock(&mutex_strsplit); + } + + + return num; +} + +void UpperToLower(char *str) +{ + for (size_t i = 0; i <= strlen(str); i++) + { + if (str[i] >= 65 && str[i] <= 92) + { + str[i] = str[i] + 32; + } + } + +} + +void LowerToUpper(char *str) +{ + for (size_t i = 0; i <= strlen(str); i++) + { + if (str[i] >= 97 && str[i] <= 124) + { + str[i] = str[i] - 32; + } + } + +} + +// Simple C++ program to count occurrences of substr in txt. +int StrFrequency(char* input_str, char* sub_str) +{ + string pat = string(sub_str); + string txt = string(input_str); + int M = pat.length(); + int N = txt.length(); + int res = 0; + + /* A loop to slide pat[] one by one */ + for (int i = 0; i <= N - M; i++) + { + /* For current index i, check for + pattern match */ + int j; + for (j = 0; j < M; j++) + if (txt[i + j] != pat[j]) + break; + + // if pat[0...M-1] = txt[i, i+1, ...i+M-1] + if (j == M) + { + res++; + j = 0; + } + } + return res; +} + +int tcsstrFrequency(TCHAR* input_str, TCHAR* sub_str) +{ + TCHAR* pat; + int res = 0; + + pat = _tcsstr(input_str, sub_str); + /* A loop to slide pat[] one by one */ + while (pat) + { + res++; + input_str = pat + _tcslen(sub_str); + pat = _tcsstr(input_str, sub_str); + } + return res; +} + +int UTF8Strlen(char* str, size_t len) +{ + int c, i, ix, q; + for (q = 0, i = 0, ix = len; i < ix; i++, q++) + { + c = (unsigned char)str[i]; + if (c >= 0 && c <= 127) i += 0; + else if ((c & 0xE0) == 0xC0) i += 1; + else if ((c & 0xF0) == 0xE0) i += 2; + else if ((c & 0xF8) == 0xF0) i += 3; + //else if (($c & 0xFC) == 0xF8) i+=4; // 111110bb //byte 5, unnecessary in 4 byte UTF-8 + //else if (($c & 0xFE) == 0xFC) i+=5; // 1111110b //byte 6, unnecessary in 4 byte UTF-8 + else return 0;//invalid utf8 + } + return q; +} + +const char *GetFileExtion(const char *filename) { + const char *dot = strrchr(filename, '.'); + if (!dot || dot == filename) return ""; + return dot + 1; +} + +void GetFileParts(char *path, char *path_, char *base_, char *ext_) +{ + char *base; + char *ext; + char nameKeep[MAX_PATH]; + char pathKeep[MAX_PATH]; + char pathKeep2[MAX_PATH]; //preserve original input string + char File_Ext[40]; + char baseK[40]; + int lenFullPath, lenExt_, lenBase_; + char *sDelim = { 0 }; + int iDelim = 0; + int rel = 0, i; + + if (path) + { //determine type of path string (C:\\, \\, /, ./, .\\) + if ((strlen(path) > 1) && + + ( + ((path[1] == ':') && + (path[2] == '\\')) || + + (path[0] == '\\') || + + (path[0] == '/') || + + ((path[0] == '.') && + (path[1] == '/')) || + + ((path[0] == '.') && + (path[1] == '\\')) + ) + ) + { + sDelim = (char*)calloc(5, sizeof(char)); + /* // */if (path[0] == '\\') iDelim = '\\', strcpy(sDelim, "\\"); + /* c:\\ */if (path[1] == ':') iDelim = '\\', strcpy(sDelim, "\\"); // also satisfies path[2] == '\\' + /* / */if (path[0] == '/') iDelim = '/', strcpy(sDelim, "/"); + /* ./ */if ((path[0] == '.') && (path[1] == '/')) iDelim = '/', strcpy(sDelim, "/"); + /* .\\ */if ((path[0] == '.') && (path[1] == '\\')) iDelim = '\\', strcpy(sDelim, "\\"); + /* \\\\ */if ((path[0] == '\\') && (path[1] == '\\')) iDelim = '\\', strcpy(sDelim, "\\"); + if (path[0] == '.') + { + rel = 1; + path[0] = '*'; + } + + if (!strstr(path, ".")) // if no filename, set path to have trailing delim, + { //set others to "" and return + lenFullPath = strlen(path); + if (path[lenFullPath - 1] != iDelim) + { + strcat(path, sDelim); + path_[0] = 0; + base_[0] = 0; + ext_[0] = 0; + } + } + else + { + nameKeep[0] = 0; //works with C:\\dir1\file.txt + pathKeep[0] = 0; + pathKeep2[0] = 0; //preserves *path + File_Ext[0] = 0; + baseK[0] = 0; + + //Get lenth of full path + lenFullPath = strlen(path); + + strcpy(nameKeep, path); + strcpy(pathKeep, path); + strcpy(pathKeep2, path); + strcpy(path_, path); //capture path + + //Get length of extension: + for (i = lenFullPath - 1; i >= 0; i--) + { + if (pathKeep[i] == '.') break; + } + lenExt_ = (lenFullPath - i) - 1; + + char *pLeft = NULL; + base = strtok_modified(path, sDelim,&pLeft); + while (base) + { + strcpy(File_Ext, base); + base = strtok_modified(NULL, sDelim,&pLeft); + } + + + strcpy(baseK, File_Ext); + lenBase_ = strlen(baseK) - lenExt_; + baseK[lenBase_ - 1] = 0; + strcpy(base_, baseK); + + path_[lenFullPath - lenExt_ - lenBase_ - 1] = 0; + + char *pLeft2 = NULL; + ext = strtok_modified(File_Ext, ".",&pLeft2); + ext = strtok_modified(NULL, ".",&pLeft2); + if (ext) strcpy(ext_, ext); + else strcpy(ext_, ""); + } + memset(path, 0, lenFullPath); + strcpy(path, pathKeep2); + if (rel)path_[0] = '.';//replace first "." for relative path + if (sDelim) { + free(sDelim); + sDelim = NULL; + } + } + } +} + +unsigned long long get_millisec_time() +{ + struct timeb now; + ftime(&now); + return (unsigned long long)(1000 * now.time + now.millitm); +} + +void GetScreenResolution(int* width, int* height) { +#ifdef _WIN32 + *width = (int)GetSystemMetrics(SM_CXSCREEN); + *height = (int)GetSystemMetrics(SM_CYSCREEN); +#else + /*Display* disp = XOpenDisplay(NULL); + Screen* scrn = DefaultScreenOfDisplay(disp); + *width = scrn->width; + *height = scrn->height;*/ +#endif +} + +int IsANPRCategory_notcode(size_t featureType) +{ + return ((featureType & FEATURE_LPR_TWN) > 0 + || (featureType & FEATURE_LPR_EUR) > 0 + || (featureType & FEATURE_LPR_SEA) > 0 + //|| (featureType & FEATURE_LPR_CNA) > 0 + || (featureType & FEATURE_LPR_MEA) > 0 + || (featureType & FEATURE_LPR_USA) > 0 + || (featureType & FEATURE_LPR_AUS) > 0 + || (featureType & FEATURE_LPR_GBR) > 0 + || (featureType & FEATURE_LPR_IDN) > 0 + || (featureType & FEATURE_LPR_JPN) > 0 + || (featureType & FEATURE_LPR_THA) > 0 + || (featureType & FEATURE_LPR_LAO) > 0 + || (featureType & FEATURE_LPR_BGD) > 0 + || (featureType & FEATURE_LPR_PHL) > 0 + || (featureType & FEATURE_LPR_VNM) > 0 + || (featureType & FEATURE_LPR_CNT) > 0 + ) > 0 ? 1 : 0; +} + +int IsANPRCategory(size_t featureType) +{ + return ((featureType & FEATURE_LPR_TWN) > 0 + || (featureType & FEATURE_LPR_EUR) > 0 + || (featureType & FEATURE_LPR_SEA) > 0 + //|| (featureType & FEATURE_LPR_CNA) > 0 + || (featureType & FEATURE_LPR_MEA) > 0 + || (featureType & FEATURE_LPR_USA) > 0 + || (featureType & FEATURE_LPR_AUS) > 0 + || (featureType & FEATURE_LPR_GBR) > 0 + || (featureType & FEATURE_LPR_IDN) > 0 + || (featureType & FEATURE_LPR_JPN) > 0 + || (featureType & FEATURE_LPR_THA) > 0 + || (featureType & FEATURE_LPR_LAO) > 0 + || (featureType & FEATURE_LPR_BGD) > 0 + || (featureType & FEATURE_LPR_PHL) > 0 + || (featureType & FEATURE_LPR_VNM) > 0 + || (featureType & FEATURE_LPR_CNT) > 0 + || unlockingKeyInnoFR_success == 1 + || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION && strcmp(WeightFileModeName, "mod003") == 0) + ) > 0 ? 1 : 0; +} + +int IsANPRCategory_L_Plate(char * L_Plate) +{ + return (strcmp(L_Plate,"L._Plate_TWN") == 0 + || strcmp(L_Plate, "L._Plate_USA") == 0 + || strcmp(L_Plate, "L._Plate_EUR") == 0 + || strcmp(L_Plate, "L._Plate_GBR") == 0 + || strcmp(L_Plate, "L._Plate_VNM") == 0 + || strcmp(L_Plate, "L._Plate_JPN") == 0 + || strcmp(L_Plate, "L._Plate_IDN") == 0 + || strcmp(L_Plate, "L._Plate_IDN2") == 0 + || strcmp(L_Plate, "L._Plate_THA") == 0 + || strcmp(L_Plate, "L._Plate_BGD") == 0 + || strcmp(L_Plate, "L._Plate_MEA") == 0 + || strcmp(L_Plate, "L._Plate_AUS") == 0 + || strcmp(L_Plate, "L._Plate_MAC/MYS") == 0 + || strcmp(L_Plate, "L._Plate_PHL") == 0 + || strcmp(L_Plate, "L._Plate_CNT_1LINE") == 0 + || strcmp(L_Plate, "L._Plate_CNT_2LINES") == 0 + || strcmp(L_Plate, "L._Plate_CNT_3LINES") == 0 + || strcmp(L_Plate, "L._Plate_CNT_VERTICAL") == 0 + || strcmp(L_Plate, "L._Plate_CNT_USDOT") == 0 + || strcmp(L_Plate, "ambulance") == 0 + || strcmp(L_Plate, "blank") == 0 + || strcmp(L_Plate, "stop_sign") == 0 + || strcmp(L_Plate, "barcode") == 0 + || strcmp(L_Plate, "qrcode") == 0 + || strcmp(L_Plate, "face") == 0 + ) > 0 ? 1 : 0; +} + +/* +int IsTrafficCategory(size_t featureType) +{ + return ((featureType & FEATURE_AIFLOW) > 0 + || (featureType & FEATURE_AIAREA) > 0 + || (featureType & FEATURE_AIVIO) > 0 + || (featureType & FEATURE_AISPC) > 0 + || (featureType & FEATURE_LPR_LOGO) > 0 + || (featureType & FEATURE_AIFISHANPR) > 0 + || (featureType & FEATURE_AICAP) > 0 + || g_IsCustomWeight == 1 + //|| (featureType & FEATURE_AIDIS) > 0 + ) > 0 ? 1 : 0; +}*/ + +int IsHumanCategory(size_t featureType) +{ + return ((featureType & FEATURE_AIMASK) > 0 + || (featureType & FEATURE_AIHELM) > 0 + ) > 0 ? 1 : 0; +} + +int IsHumanPose(size_t featureType) +{ + return ((featureType & FEATURE_HUM_POS) > 0) + > 0 ? 1 : 0; +} + +int IsVehicleCategory(detection_pos* pNext) +{ + if (strcmp(pNext->name, "car") == 0 + || strcmp(pNext->name, "bus") == 0 + || strcmp(pNext->name, "truck") == 0 + || strcmp(pNext->name, "tuktuk") == 0 + || strcmp(pNext->name, "trailer") == 0 + || strcmp(pNext->name, "pickup") == 0 + || strcmp(pNext->name, "SUV") == 0 + || strcmp(pNext->name, "van") == 0 + || strcmp(pNext->name, "dual_headlight") == 0 + || strcmp(pNext->name, "single_headlight") == 0 + ) + return 1; + else + return 0; +} + +int IsMotorbikeCategory(detection_pos* pNext) +{ + if (strcmp(pNext->name, "motorbike") == 0 + || strcmp(pNext->name, "exhaust_ok") == 0 + || strcmp(pNext->name, "exhaust_ng") == 0 + ) + return 1; + else + return 0; +} + +int IsGarbageCategory(detection_pos* pNext) +{ + if (strcmp(pNext->name, "bag") == 0 + || strcmp(pNext->name, "bottle") == 0 + || strcmp(pNext->name, "cup") == 0 + || strcmp(pNext->name, "cigarette") == 0 + || strcmp(pNext->name, "paper_sheet") == 0 + || strcmp(pNext->name, "box") == 0 + ) + return 1; + else + return 0; + +} +int IsProductionCategory(detection_pos* pNext) +{ + if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIPRODUCTION)) + { + if (strcmp(pNext->name, "qrcode") == 0 || strcmp(pNext->name, "barcode") == 0) + return 1; + else + return 0; + } + else + return 0; +} +int IsFireSmokeCategory(size_t featureType) +{ + return ((featureType & FEATURE_DET_AIFIRE) > 0 + //|| (featureType & FEATURE_xxxx) > 0 + ) > 0 ? 1 : 0; +} + +void StripDetectedObjects(detection_pos* posInfo, int *element_size, int img_width, int img_height, int obj_min_proportion, int obj_max_proportion, int min_characters, int max_characters, int confidence, int confidence2, int confidence3, int confidence4) +{ + + int selected_detections_num = *element_size; + //int plate_number_len = 0; + detection_pos* pNext = NULL; + + for (int i = 0; i < selected_detections_num; i++) + { + + pNext = posInfo + i; + + if (pNext->engine_type == FEATURE_OTHER_ITEMS) + continue; + +#if 0 + if (IsANPRCategory(pNext->engine_type)) + { + if (pNext->obj_type == _PLATE) + { + //printf("\n-----------pNext->properties.plate: %s\n", pNext->properties.plate); + plate_number_len = UTF8Strlen(pNext->properties.plate, strlen(pNext->properties.plate)); + //printf("plate len = %d \n", plate_number_len); + } + + if (pNext->obj_type == _NUMBER) + { + plate_number_len = UTF8Strlen((posInfo + pNext->parent_idx)->properties.plate, strlen((posInfo + pNext->parent_idx)->properties.plate)); + } + } +#endif + + //printf("\nStripDetectedObjects:3\n"); + //printf("\nFEATURE_HUM_DET---17\n"); +#if 0 + if ( + + strlen(pNext->name) == 0 || + strncmp(pNext->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext->name, "_s", strlen("_s")) == 0 + //|| ( ((posInfo + i)->width * (posInfo + i)->height) / (img->width *img->height) ) > (obj_max_proportion/100.0) + || ((pNext->width / img_width) > (obj_max_proportion / 100.0) && !IsANPRCategory(pNext->engine_type) && !(pNext->engine_type & FEATURE_LPR_LOGO)) + || ((pNext->height / img_height) > (obj_max_proportion / 100.0) && !IsANPRCategory(pNext->engine_type) && !(pNext->engine_type & FEATURE_LPR_LOGO)) + || ((pNext->width / img_width) < (obj_min_proportion / 100.0) && !IsANPRCategory(pNext->engine_type) && !(pNext->engine_type & FEATURE_LPR_LOGO)) + || ((pNext->height / img_height) < (obj_min_proportion / 100.0) && !IsANPRCategory(pNext->engine_type) && !(pNext->engine_type & FEATURE_LPR_LOGO)) + || (IsANPRCategory(pNext->engine_type) && ((pNext->confidence < confidence) || (pNext->obj_type == _MISTAKE) || (plate_number_len < min_characters) || (plate_number_len > max_characters))) + || (((pNext->engine_type & FEATURE_TRAF_DET) + || (pNext->engine_type & FEATURE_AIFIRE) + || (pNext->engine_type & FEATURE_HUM_DET) + ) && (pNext->confidence < confidence2)) + /*|| ((pNext->engine_type & FEATURE_LPR_LOGO) && (pNext->confidence < confidence3))*/ + /*|| ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->confidence < confidence4))*/ + //|| exclusive_object + ) + { + //printf("\nStripDetectedObjects:4\n"); + for (int j = i + 1; j < selected_detections_num; j++) + { + memcpy(posInfo + j - 1, posInfo + j, sizeof(detection_pos)); + if (j == selected_detections_num - 1) + { + memset(posInfo + j, 0x00, sizeof(detection_pos)); + } + + //adjust parent_idx after deleting the detection object + + } + i--; + selected_detections_num--; + } +#endif + + if ( + + strlen(pNext->name) == 0 || + strncmp(pNext->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext->name, "_s", strlen("_s")) == 0 || + pNext->obj_type == _MISTAKE || + (IsANPRCategory(pNext->engine_type) && (pNext->confidence < confidence)) || + (((pNext->engine_type & FEATURE_TRAF_DET) + || (pNext->engine_type & FEATURE_AIFIRE) + || (pNext->engine_type & FEATURE_HUM_DET) + ) && (pNext->confidence < confidence2)) || + (((pNext->width * pNext->height) / ((float)img_width *(float)img_height)) > ((float)obj_max_proportion / 100.0) + && !IsANPRCategory(pNext->engine_type) && !(pNext->engine_type & FEATURE_LPR_LOGO)) || + (((pNext->width * pNext->height) / ((float)img_width *(float)img_height)) < ((float)obj_min_proportion / 100.0) + && !IsANPRCategory(pNext->engine_type) && !(pNext->engine_type & FEATURE_LPR_LOGO)) + ) + { +#if 1 + //printf("\nStripDetectedObjects:4\n"); + if (i < selected_detections_num - 1) { + for (int j = i + 1; j < selected_detections_num; j++) + { + + //memcpy(posInfo + j - 1, posInfo + j, sizeof(detection_pos));//o|O鬪| + memcpy(posInfo + j - 1, posInfo + j, sizeof(detection_pos)); + + if (j == selected_detections_num - 1) + { + memset(posInfo + j, 0x00, sizeof(detection_pos)); + } + + //adjust parent_idx after deleting the detection object + + } + } + else { + memset(posInfo + i, 0x00, sizeof(detection_pos)); + } + i--; + selected_detections_num--; +#endif + } + + } +#if 0 //check the strip result + for (int i = 0; i < selected_detections_num; i++) + { + pNext = posInfo + i; + if (IsANPRCategory(pNext->engine_type)) + { + if (pNext->obj_type == _PLATE) + { + plate_number_len = UTF8Strlen(pNext->properties.plate, strlen(pNext->properties.plate)); + //printf("[%02d]plate len = %d \n", i, plate_number_len); + printf("[%02d]plate = %s \n", i, pNext->properties.plate); + } + } + } +#endif + + *element_size = selected_detections_num; +} + + +void KillProcessByName(const char *filename) +{ +#ifdef _WIN32 + +#endif +} + +void BinaryDFS(int d, int power, int *eachBinArray, int **totalBinArray, int* rows) +{ + if (d == power) { + for (int i = 0; i < d; i++) + { + //printf("%d ", eachBinArray[i]); + totalBinArray[*rows][i] = eachBinArray[i]; + } + //puts(""); + *rows = *rows + 1; + return; + } + eachBinArray[d] = 0; + BinaryDFS(d + 1, power, eachBinArray, totalBinArray, rows); + eachBinArray[d] = 1; + BinaryDFS(d + 1, power, eachBinArray, totalBinArray, rows); +} + +int RegexMatch(char* str, char* pattern) +{ + int rtnCode = 0; + regex RegexPattern(pattern); + + if (regex_match(str, RegexPattern)) + rtnCode = 1; + + return rtnCode; +} + +void MapInsert(char* key, char* value) +{ + mapVariables.insert(pair<string, string>(key, value)); +} + +int MapFind(char* key, char* value) +{ + int result = 0; + std::map<string, string>::iterator iter; + iter = mapVariables.find(key); + if (iter != mapVariables.end()) + { + strcpy(value, mapVariables[key].c_str()); + result = 1; + } + else + result = 0; + + return result; +} + +int MapDelete(char* key) +{ + return mapVariables.erase(key); +} + +void MapClear() +{ + mapVariables.erase(mapVariables.begin(), mapVariables.end()); +} + +/* +pthread_mutex_t mutex_queue_lock; +void QueueLockInit() +{ + pthread_mutex_init(&mutex_queue_lock, NULL); +}*/ + +void QueuePush(QueueInfo q_info, int queue_type) +{ + switch (queue_type) + { + case _POST_NOTIFICATION: + g_PostNotificationQueue.push_back(q_info); + break; + case _GETALARMMOTION: + g_GetAlarmMotionQueue.push_back(q_info); + break; + default: + break; + } +} + +QueueInfo QueueFront(int queue_type) +{ + switch (queue_type) + { + case _POST_NOTIFICATION: + return g_PostNotificationQueue.front(); + break; + case _GETALARMMOTION: + return g_GetAlarmMotionQueue.front(); + break; + default: + return g_PostNotificationQueue.front();; + break; + } +} + +void QueuePop(int queue_type) +{ + + //if (queue_type == _POST_NOTIFICATION || queue_type == _GETALARMMOTION) + //{ + //QueueInfo q_info = QueueFront(queue_type); + + /*//SΨ + if (q_info.image_buff != NULL) + { + free(q_info.image_buff); + q_info.image_buff = NULL; + }*/ + //if (q_info.pNext != NULL) + //{ + //free(q_info.pNext); + //q_info.pNext = NULL; + //} + //} + + switch (queue_type) + { + case _POST_NOTIFICATION: + g_PostNotificationQueue.pop_front(); + if(QueueIsEmpty(_POST_NOTIFICATION)) + g_PostNotificationQueue.shrink_to_fit(); + break; + case _GETALARMMOTION: + g_GetAlarmMotionQueue.pop_front(); + if (QueueIsEmpty(_GETALARMMOTION)) + g_GetAlarmMotionQueue.shrink_to_fit(); + break; + default: + break; + } +} + +int QueueSize(int queue_type) +{ + switch (queue_type) + { + case _POST_NOTIFICATION: + return g_PostNotificationQueue.size(); + break; + case _GETALARMMOTION: + return g_GetAlarmMotionQueue.size(); + break; + default: + break; + } + return 0; +} + +int QueueIsEmpty(int queue_type) +{ + return QueueSize(queue_type) <= 0 ? 1 : 0; +} + +void QueueClear(int queue_type) +{ + if (queue_type == _POST_NOTIFICATION || queue_type == _GETALARMMOTION) + { + while (!QueueIsEmpty(queue_type)) + { + QueuePop(queue_type); + } + } +} + +void DumpHex(const void* data, size_t size) +{ + char ascii[17]; + size_t i, j; + ascii[16] = '\0'; + + for (i = 0; i < size; ++i) + { + printf("%02X ", ((unsigned char*)data)[i]); + if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') + { + ascii[i % 16] = ((unsigned char*)data)[i]; + } + else + { + ascii[i % 16] = '.'; + } + + if ((i + 1) % 8 == 0 || i + 1 == size) + { + printf(" "); + if ((i + 1) % 16 == 0) + { + printf("| %s \n", ascii); + } + else if (i + 1 == size) + { + ascii[(i + 1) % 16] = '\0'; + if ((i + 1) % 16 <= 8) + { + printf(" "); + } + + for (j = (i + 1) % 16; j < 16; ++j) + { + printf(" "); + } + printf("| %s \n", ascii); + } + } + } +} + +unsigned int HexStringToInt(char* HexString) +{ + unsigned int x; + stringstream sst; + sst << std::hex << HexString; + sst >> x; + return x; +} + +// Given three colinear points p, q, r, the function checks if +// point q lies on line segment 'pr' +int onSegment(CPoint p, CPoint q, CPoint r) +{ + if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) && + q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y)) + return true; + return false; +} + +// To find orientation of ordered triplet (p, q, r). +// The function returns following values +// 0 --> p, q and r are colinear +// 1 --> Clockwise +// 2 --> Counterclockwise +int orientation(CPoint p, CPoint q, CPoint r) +{ + int val = (q.y - p.y) * (r.x - q.x) - + (q.x - p.x) * (r.y - q.y); + + if (val == 0) return 0; // colinear + return (val > 0) ? 1 : 2; // clock or counterclock wise +} + +// The function that returns true if line segment 'p1q1' +// and 'p2q2' intersect. +int doIntersect(CPoint p1, CPoint q1, CPoint p2, CPoint q2) +{ + // Find the four orientations needed for general and + // special cases + int o1 = orientation(p1, q1, p2); + int o2 = orientation(p1, q1, q2); + int o3 = orientation(p2, q2, p1); + int o4 = orientation(p2, q2, q1); + + // General case + if (o1 != o2 && o3 != o4) + return true; + + // Special Cases + // p1, q1 and p2 are colinear and p2 lies on segment p1q1 + if (o1 == 0 && onSegment(p1, p2, q1)) return true; + + // p1, q1 and p2 are colinear and q2 lies on segment p1q1 + if (o2 == 0 && onSegment(p1, q2, q1)) return true; + + // p2, q2 and p1 are colinear and p1 lies on segment p2q2 + if (o3 == 0 && onSegment(p2, p1, q2)) return true; + + // p2, q2 and q1 are colinear and q1 lies on segment p2q2 + if (o4 == 0 && onSegment(p2, q1, q2)) return true; + + return false; // Doesn't fall in any of the above cases +} + +// Returns true if the point p lies inside the polygon[] with n vertices +int isInside(CPoint polygon[], int n, CPoint p) +{ + //for (int x = 0; x < n; x++) + //{ + // printf("zone, p[%d] = [%d], [%d] \n", x, polygon[x].x, polygon[x].y); + //} + //printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); + //printf("\nisInside\n"); + //printf("\nn: %d\n",n); + //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); + // There must be at least 3 vertices in polygon[] + if (n < 3) return 0; + + // Create a point for line segment from p to infinite + CPoint extreme = { INF, p.y }; + + int check_extreme_loc_OK = 0; + + int original_y = p.y; + int times = 0; + while (check_extreme_loc_OK < n && times <= 30) { + int index_polygon = 0; + check_extreme_loc_OK = 0; + do + { + int next_polygon = (index_polygon + 1) % n; + + if (polygon[index_polygon].y != extreme.y) { + check_extreme_loc_OK++; + } + index_polygon = next_polygon; + } while (index_polygon != 0); + + if (check_extreme_loc_OK < n) { + if (original_y + (times % 2 == 0 ? 1 : -1) * (times / 2 + 1) >= 1 && original_y + (times % 2 == 0 ? 1 : -1) * (times / 2 + 1) <= 499) { + extreme.y = original_y + (times % 2 == 0 ? 1 : -1) * (times / 2 + 1); + } + times++; + } + } + + // Count intersections of the above line with sides of polygon + int count = 0, i = 0; + do + { + int next = (i + 1) % n; + + //printf("CHK its A ([%d], [%d]) -- ([%d], [%d]) \n", polygon[i].x, polygon[i].y, polygon[next].x, polygon[next].y); + //printf("CHK its B ([%d], [%d]) -- ([%d], [%d]) \n", p.x, p.y, extreme.x, extreme.y); + + // Check if the line segment from 'p' to 'extreme' intersects + // with the line segment from 'polygon[i]' to 'polygon[next]' + if (doIntersect(polygon[i], polygon[next], p, extreme)) + { + //printf("[%d] is ITS \n", i); + // If the point 'p' is colinear with line segment 'i-next', + // then check if it lies on segment. If it lies, return true, + // otherwise false + if (orientation(polygon[i], p, polygon[next]) == 0) + { + return onSegment(polygon[i], p, polygon[next]); + } + + count++; + //printf("[%d] is ITS count = %d\n", i, count); + } + i = next; + } while (i != 0); + + if (count % 2 == 1) + return 1; + return 0; + + // Return true if count is odd, false otherwise + //return count & 1; // Same as (count%2 == 1) +} + +#ifdef GY_OS_AMBA +int GetAIImageDimension(char* image_buff, size_t image_buff_size, int* AIImage_width, int* AIImage_height) +{ + size_t i = 0; + + if (image_buff[i] == '\xFF' && image_buff[i + 1] == '\xD8' && image_buff[i + 2] == '\xFF' && image_buff[i + 3] == '\xE0') + { + i += 4; + /* need to check for null terminated JFIF */ + if (image_buff[i + 2] == 'J' && image_buff[i + 3] == 'F' && image_buff[i + 4] == 'I' && image_buff[i + 5] == 'F' && image_buff[i + 6] == '\x00') { + while (i < image_buff_size) { + i++; + if (image_buff[i] == '\xFF') { + if (image_buff[i + 1] == '\xC0') { + *AIImage_height = image_buff[i + 5] * 256 + image_buff[i + 6]; + *AIImage_width = image_buff[i + 7] * 256 + image_buff[i + 8]; + break; + } + } + } + } + } + else if (image_buff[i] == '\xFF' && image_buff[i + 1] == '\xD8' && image_buff[i + 2] == '\xFF' && image_buff[i + 3] == '\xE1') + { + easyexif::EXIFInfo result; + int code = result.parseFrom((unsigned char*)image_buff, image_buff_size); + //delete[] image_buff; + if (code) { + printf("Error parsing EXIF: code %d\n", code); + return 1; + } + + *AIImage_width = result.ImageWidth; + *AIImage_height = result.ImageHeight; + } + + return 0; +} +#endif + +int lastIndexof(const char* strIn, const char* strtoFind) //20201008 sophia add +{ + //printf("\n[lastIndexof] in:%s strtoFind:%s\n ", strIn, strtoFind); + int index = -1; + /*int i = 0; + while (strIn[i] != '\0') + { + printf("\n[lastIndexof] strIn[%d]:%c\n",i,strIn[i]); + if (strIn[i] == strtoFind[0]) + { + index = i; + printf("\n[lastIndexof] inside\n"); + } + i++; + }*/ + + int i = strlen(strIn) - 1; + while (i >= 0) + { + //printf("\n[lastIndexof] strIn[%d]:%c\n", i, strIn[i]); + if (strIn[i] == strtoFind[0]) + { + //printf("\n[lastIndexof] inside\n"); + index = i; + break; + } + + i = i - 1; + } + + //printf("\n[lastIndexof] find:%d\n", index); + return index; +} + +int getFilePath(char* strIn, char*strOut, int nOutSize) //20201008 sophia add +{ + //printf("\n[getFilePath] in:%s len:%d\n", strIn, strlen(strIn)); + + char find[2] = { '/',0 }; + + int lastidx = lastIndexof(strIn, find); + + if (lastidx == -1) return 0; + + memset(strOut, 0, nOutSize); + strncpy(strOut, strIn, lastidx + 1); + + //printf("\n[getFilePath] strOut:%s\n", strOut); + + return 1; +} + +int getFileName(char* strIn, char*strOut, int nOutSize) //20201008 sophia add +{ + //printf("\n[getFileName] in:%s len:%d\n", strIn, strlen(strIn)); + + char find[2] = { '/',0 }; + + int lastidx = lastIndexof(strIn, find); + + if (lastidx == -1) return 0; + + memset(strOut, 0, nOutSize); + strncpy(strOut, strIn + lastidx + 1, strlen(strIn) - lastidx - 1); + + //printf("\n[getFileName] strOut:%s\n", strOut); + + return 1; +} + +/*void split(char **arr, char *str, const char *del) { + char *pLeft = NULL; + char *s = strtok_r(str, del,&pLeft); + + while (s != NULL) { + * arr++ = s; + s = strtok_r(NULL, del, &pLeft); + } +}*/ + +int write_config() +{ + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + char exePath[1024] = {}; + //printf("exePath:%s\n", exePath); + getFilePath(buf, exePath, 1024); + //printf("exePath:%s\n", exePath); + + char configPATH[1024] = { 0 }; + strcpy(configPATH, exePath); + strcat(configPATH, "config.json"); + + char config_bakPATH[1024] = { 0 }; + strcpy(config_bakPATH, exePath); + strcat(config_bakPATH, "config_bak.json"); + + char eventsPATH[1024] = { 0 }; + strcpy(eventsPATH, exePath); + strcat(eventsPATH, "events.json"); + + char events_bakPATH[1024] = { 0 }; + strcpy(events_bakPATH, exePath); + strcat(events_bakPATH, "events_bak.json"); + + char *filename; + filename = configPATH; + + int ret = 0; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + g_write_config_file_dirty_flag = 0; + ret = -1; + return ret; + } + + //write config + if (g_config_root != NULL) + { + char* JsonString = cJSON_Print(g_config_root); + + //printf("\n--------[write config]: %s\n", JsonString); + + FILE *fp; + + if ((fp = fopen(filename, "w")) != NULL) + { + fprintf(fp, JsonString); + fclose(fp); + CopyFileTo(configPATH, config_bakPATH); + CopyFileTo(eventsPATH, events_bakPATH); + ret = 0; + } + else + { + printf("Fail to open Config.json \n"); + ret = -1; + } + + if (JsonString) { + free(JsonString); + JsonString = NULL; + } + if (g_config_root != NULL) { + cJSON_Delete(g_config_root); + g_config_root = NULL; + } + } + else + { + ret = -1; + } + + return ret; +} + +#define SHELLSCRIPT_DELETE_FIRST_LINE_LOGS "sh /emmc/plugin/Aida_data/delete_first_line_logs.sh" +int protected_logs = 0; +void write_to_logs_html(char * logs_message,char * logs_thread,char * logs_level,char *enable_system_logs) { + if (strcmp(enable_system_logs, "Yes") == 0 && protected_logs == 0) { + protected_logs = 1; + system(SHELLSCRIPT_DELETE_FIRST_LINE_LOGS); + + char msg_buffer[1024] = { 0 }; + strncpy(msg_buffer, logs_message, 1000); + + time_t now; + // Update current time using time(&now); + time(&now); + char date[128] = { 0 }; + strftime(date, sizeof(date), "%Y/%m/%d %H:%M:%S", localtime(&now)); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char logPATH[1024] = { 0 }; + strcpy(logPATH, exePath); + strcat(logPATH, "logs.js"); + + FILE *f = fopen(logPATH, "a+"); + if (f == NULL) + { + printf("Error opening log.txt!\n"); + } + else { + str_replace_all(msg_buffer, "\r\n", " "); + str_replace_all(msg_buffer, "\n", " "); + fprintf(f, "[%s][%s][%s][gynet logger][%s]\n", date, logs_thread, logs_level + , msg_buffer); + fclose(f); + } + protected_logs = 0; + } +} + +void write_to_log_for_start(char * msg_error, char * msg_func, char *msg_label) { + + time_t now; + // Update current time using time(&now); + time(&now); + char date[128] = { 0 }; + strftime(date, sizeof(date), "%a %b %d %T %Y", localtime(&now)); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char logPATH[1024] = { 0 }; + strcpy(logPATH, exePath); + strcat(logPATH, "log_for_start.txt"); + + FILE *f = fopen(logPATH, "w+"); + if (f == NULL) + { + printf("Error opening log.txt!\n"); + } + else { + fprintf(f, "%s: [%s][%s]%s\n", date, msg_func, msg_label, msg_error); + fclose(f); + } +} + +void write_to_log_if_error(char * msg_error, char * msg_func,char *msg_label) { + + time_t now; + // Update current time using time(&now); + time(&now); + char date[128] = { 0 }; + strftime(date, sizeof(date), "%a %b %d %T %Y", localtime(&now)); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char logPATH[1024] = { 0 }; + strcpy(logPATH, exePath); + strcat(logPATH, "log.txt"); + + FILE *f = fopen(logPATH, "w+"); + if (f == NULL) + { + printf("Error opening log.txt!\n"); + } + else { + fprintf(f, "%s: [%s][%s]%s\n", date, msg_func, msg_label, msg_error); + fclose(f); + } +} + +void write_to_log_if_error_nvclient(char * msg_error) { + + time_t now; + // Update current time using time(&now); + time(&now); + char date[128] = { 0 }; + strftime(date, sizeof(date), "%a %b %d %T %Y", localtime(&now)); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char logPATH[1024] = { 0 }; + strcpy(logPATH, exePath); + strcat(logPATH, "log_nvclient.txt"); + + FILE *f = fopen(logPATH, "w+"); + if (f == NULL) + { + printf("Error opening log_nvclient.txt!\n"); + } + else { + fprintf(f, "%s: %s\n", date, msg_error); + fclose(f); + } +} +#if 1 +void write_to_log_if_error_post_pns(char * msg_error) { + + time_t now; + // Update current time using time(&now); + time(&now); + char date[128]; + strftime(date, sizeof(date), "%a %b %d %T %Y", localtime(&now)); + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char logPATH[1024]; + strcpy(logPATH, exePath); + strcat(logPATH, "log_post_pns.txt"); + + FILE *f = fopen(logPATH, "w+"); + if (f == NULL) + { + printf("Error opening log_post_pns.txt!\n"); + } + else { + fprintf(f, "%s: %s\n", date, msg_error); + fclose(f); + } +} +#endif + +void delete_file(char *file_name) { + if (FileExist(file_name)) { + int del = unlink(file_name); + if (!del) { + //printf("db is Deleted successfully."); + } + else { + printf("%s cannot be Deleted.\n", file_name); + } + } +} + +float polygon_area(CPoint area_point[], int actual_size) +{ + //printf("In polygon.area\n"); + + float area = 0.0; + + for (int i = 0; i < actual_size; ++i) + { + int j = (i + 1) % actual_size; + area += 0.5 * (area_point[i].x * area_point[j].y - area_point[j].x * area_point[i].y); + } + + //printf("The area of the polygon is %f \n", abs(area)); + + return abs(area); +} + +void get_classname(int my_class_id, char* my_class_name) { + + memset(my_class_name, 0x00, strlen(my_class_name)); + + char buf[1024] = { 0 }; + readlink("/proc/self/exe", buf, sizeof(buf)); + //printf("Program binary path is: %s\n", buf); + + char exePath[1024] = { 0 }; + getFilePath(buf, exePath, 1024); + + char jsonClassIDPATH[1024] = { 0 }; + + strcpy(jsonClassIDPATH, exePath); + strcat(jsonClassIDPATH, "jsonClassID.json"); + + char* filename; + filename = jsonClassIDPATH; + + if (!FileExist(filename)) + { + printf("%s doesn't exist.\n", filename); + } + else { + char* fileBuf = ReadAllBytes(filename); + if (fileBuf) { + cJSON* root, *objectClassID, *a_object, *a_class_id, *a_ENG_name; + root = cJSON_Parse(fileBuf); + if (fileBuf) { + free(fileBuf); + fileBuf = NULL; + } + if (root) { + objectClassID = cJSON_GetObjectItem(root, "objectClassID"); + + cJSON_ArrayForEach(a_object, objectClassID) + { + a_class_id = cJSON_GetObjectItem(a_object, "class_id"); + a_ENG_name = cJSON_GetObjectItem(a_object, "ENG"); + + if (a_class_id && atoi(a_class_id->valuestring) == my_class_id) { + strcpy(my_class_name, a_ENG_name->valuestring); + UpperToLower(my_class_name); + for (int i = 0; i < (int)strlen(my_class_name); i++) { + if (my_class_name[i] == ' ') { + my_class_name[i] = '_'; + } + } + break; + } + } + + if (root) { + cJSON_Delete(root); + root = NULL; + } + } + } + } +} +#if 0 +CPoint SubPoint(CPoint vTarget1, CPoint vTarget2) +{ + CPoint vPoint; + vPoint.x = vTarget1.x - vTarget2.x; + vPoint.y = vTarget1.y - vTarget2.y; + return vPoint; +} + +float CrossProduct(CPoint vTarget1, CPoint vTarget2) +{ + return vTarget1.x * vTarget2.y - vTarget2.x * vTarget1.y; +} + +int IsPointInConvexPolygon(CPoint aPoints[], CPoint vTarget) +{ + + if (sizeof(aPoints) == 0) + return 0; + + float nCurCrossProduct = 0, nLastValue = 0; + for (int i = 0; i < sizeof(aPoints); i++) + { + CPoint vU = SubPoint(vTarget, aPoints[i]); + int nNextIndex = (i + 1) % sizeof(aPoints); + CPoint vV = SubPoint(aPoints[nNextIndex], aPoints[i]); + + nCurCrossProduct = CrossProduct(vU, vV); + if (i > 0 && nCurCrossProduct * nLastValue <= 0) + { + return 0; + } + nLastValue = nCurCrossProduct; + } + return 1; +} +#endif + +int insert_string(char* s, char* t, int i) { + char string[100]; + int len = strlen(s); + if (len <= 0 || i > len) { + printf("Error!\n"); + return 0; + } + else { + if (len == 0) { + strcpy(s, t); + } + else { + strncpy(string, s, i); + string[i] = '\0'; + strcat(string, t); + strcat(string, s + i); + strcpy(s, string); + } + return (int)strlen(s); + } +} + +int strstr_cnt(const char *string, const char *substring) { + int i, j, k, count = 0; + for (i = 0; string[i]; i++) { + for (j = i, k = 0; (string[j] == substring[k] && (j < (int)strlen(string))); j++, k++) { + if (!substring[k + 1]) { + count++; + } + } + } + return count; +} + +void usSleep(unsigned int nusecs) { + struct timeval tval; + tval.tv_sec = nusecs / 1000000; + tval.tv_usec = nusecs % 1000000; + select(0, NULL, NULL, NULL, &tval); + +} + +float X_Tranform_To_Onvif_Space(float ori_x_value, int half_ori_yuv_width) { + float new_x_value = (ori_x_value / (float)half_ori_yuv_width) - 1.0; + return new_x_value; +} + +float Y_Tranform_To_Onvif_Space(float ori_y_value, int half_ori_yuv_height) { + float new_y_value = 1.0 - (ori_y_value / (float)half_ori_yuv_height); + return new_y_value; +} + +#ifdef GY_OS_NOVA +void write_driver_setting_file(char* buffer_json_string) { + + char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf)); + + char exePath[1024] = {}; + getFilePath(buf, exePath, 1024); + + char settingPATH[1024]; + strcpy(settingPATH, exePath); + strcat(settingPATH, "nova_driver_valid_weight.txt"); + + FILE *f = fopen(settingPATH, "w+"); + if (f == NULL) + { + printf("Error opening or create settingPATH.txt!\n"); + } + else { + fprintf(f, "%s", buffer_json_string); //̫\WβŸ, קKΦr, X{ΨLŸb̫@Ӧrꤤ + //fprintf(f, "%s:%s\n", "NetFile", sNetFile); + //fprintf(f, "%s:%s\n", "LabelFile", sLabelFile); + fclose(f); + } +} +#endif +#ifdef GY_OS_AMBA +void verify_directory_exists(const char* path) { + char* directory_path = strdup(path); + char* last_slash = strrchr(directory_path, '/'); + + if (last_slash != NULL) { + *last_slash = '\0'; + struct stat st = {0}; + + if (stat(directory_path, &st) == -1) { + if (mkdir(directory_path, 0700) == -1) { + perror("mkdir error"); + } + } + } + free(directory_path); +} +#endif + +#if 1 +void writeImageFromBuffer(const char* filename, const char* buffer, unsigned long length) +{ +#ifdef GY_OS_AMBA + verify_directory_exists(filename); +#endif + FILE *image; /* Pointer to file */ + + image = fopen(filename, "wb"); + + fwrite(buffer, 1, length, image); + + fclose(image); +} +#endif + +#endif \ No newline at end of file diff --git a/src/utility.h b/src/utility.h new file mode 100644 index 0000000..a2aa037 --- /dev/null +++ b/src/utility.h @@ -0,0 +1,788 @@ +#if 1 +#pragma once +#ifndef UTILITY_H +#define UTILITY_H +#include "define_inc.h" +#include "auto_tchar.h" +#include <stdio.h> +#include "setting.h" +#include <time.h> +#include "darknet.h" +#include "list.h" +#include <sys/socket.h> +#include "string.h" + +#include <sys/prctl.h> +#include <errno.h> +#include <unistd.h> +#include "cJSON.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_PLATE_NUM_PER_SEC 30 +#define NIC_INFO_NUM 3 +#define MAX_MAC_SIZE 32 +#define INF 10000 +#define COLOR_CATEGORY_NUM 10 + +#define CANVAS_WIDTH 889 +#define CANVAS_HEIGHT 500 +#define SCALE_BOUNDING_BOX_WIDTH 1920 +#define SCALE_BOUNDING_BOX_HEIGHT 1080 + +#define VIEW_WEB_WIDTH 384 //1920 +#define VIEW_WEB_HEIGHT 216 //1080 + +#define VIEW_WEB_WIDTH_HD 384 //1920/10*2 +#define VIEW_WEB_HEIGHT_HD 216 //1080/10*2 + +#define VIEW_WEB_WIDTH_SMALL 352 //1920/10*2 +#define VIEW_WEB_HEIGHT_SMALL 240 //1080/10*2 + +#define VIEW_WEB_WIDTH_HD_1280 1280 //1920/10*2 +#define VIEW_WEB_HEIGHT_HD_720 720 //1080/10*2 + +#define READ_IPCAM_SETTING 60*60*1000 + +#define STRSPLIT_SIZE 100 + +//fInSourceOri_w, fInSourceOri_h + + + /*inline int GetLastError() + { + return errno; + };*/ + + inline void X2Sleep(int nMSecIN) + { + usleep(nMSecIN * 1000); + }; + + #ifndef FALSE + #define FALSE 0 + #endif + #ifndef TRUE + #define TRUE 1 + #endif + + #define SOCKET_ERROR (-1) + //#define WSAGetLastError GetLastError + #define Sleep X2Sleep + + typedef unsigned char uchar; + typedef int SOCKET; + typedef unsigned int DWORD; + + typedef struct + { + int iObjectID; + float left_x; + float top_y; + float right_x; + float bottom_y; + float center_x; + float center_y; + char TypeName[30]; //Name + float Likelihood; //confidence + + char sPlateNumber[64]; //Number + char sPlateType[20]; + char sCountryCode[64]; + char sIssuingEntity[64]; + + unsigned int behavior_id; + } onvif_data; + + typedef struct + { + int x; + int y; + } CPoint; + + typedef struct + { + float x; + float y; + } f_CPoint; + + typedef struct + { + char onvif_counter_name[36 + 1]; + unsigned int onvif_detect_event_id; + + char onvif_ReportTimeInterval[30]; + char onvif_ResetTime[50]; + char onvif_Direction[10]; + char onvif_PassAllPolylines[10]; + f_CPoint onvif_Points[6]; + + int counter_count; + int dwell_time; + + int forward_line; + + //char metadata1[2048]; + //char confidence[10]; //P Plate + //char confidence2[10]; //q Traffic + //int no_parking_time; + //int no_parking_time_in_minute; + + } onvif_counter_info; + + typedef struct { + int color_id; + char color[20]; + int h_min; + int h_max; + int s_min; + int s_max; + int v_min; + int v_max; + } ColorRange; + + typedef struct { + char plate[100]; + char country[20]; + char area[100]; + char logo[128]; + char color[20]; + char pose[20]; + int area_id; + //unsigned int counter_count[MAX_EVENT_COUNTERS]; + char plate_list[20]; + int plate_length; + //int colorCount[10]; + } detection_properties; + + typedef struct { + char name[5]; + + int number_row; + + float box_x; + float box_y; + float box_w; + float box_h; + + int iIsDigit; + int iIsAlpha; + } detection_sub_properties; + +//#ifdef GY_OS_AMBA + /*typedef struct { + char face_name[10]; + char user_name[50]; + char face_uuid[60]; + float identification_score; + int face_trackingID; + char face_bmp[60]; + } detection_FDFR;*/ +//#endif + /*typedef struct { + int social_obj_tracking_id; + float social_distance; + } distance_node;*/ + + /*typedef struct { + float fIOU; //pred or prev to new pos + short sdwCenterDistense; //pred vs new pos + short sdwCenterDistense_avg; + short sdwHSVColorDiff; //prev HSV or pred HSV + short sdwVector_x; //new vec + short sdwVector_y; // + short sdwVector_old_x; //pred vec + short sdwVector_old_y; // + short sdwVector_angel; //pred pos vec and new pos vec + float fWHRatio_pred; //w/h + float fWHRatio_new; //w/h + } ObjTrackingIDCheckItem;*/ + + /*typedef struct { + short IOU_vote; + short CenterDist_vote; + short CenterDist_avg_vote; + short HSVDiff_vote; + short Vector_vote; + short fWHRatio_vote; + } ObjTrackingIDVote;*/ + + typedef struct { + char name[30]; + //char replaced_name[30]; + + char code_content[512]; + float confidence; + float confidence2; +#ifdef GY_OS_NOVA + float class_score; + float object_score; +#endif + float progress_bar; + unsigned int engine_type; + unsigned int engine_type2; + float left_x; + float top_y; + float center_x; + float center_y; + float center_direction; + float center_stability; + float width; + float height; + float plate_char_top_y; + int parent_idx; + int car_logo_idx; + int number_row; + int obj_type; + int visual_left_x; + int class_id; + int obj_tracking_id; + char color[20]; + int color_id; + int sec_color_id; + unsigned int trigger_type; + float arc; + //int detection_zone_idx; + int trigger_idx[MAX_DETECTION_ZONE]; + int zone_violation_idx[MAX_DETECTION_ZONE]; + int zone_check_giveway[MAX_DETECTION_ZONE]; + + int check_if_within_zone[MAX_DETECTION_ZONE]; + + int check_person_inter; + //int speed_detection[MAX_DETECTION_ZONE]; // 2022-11-30 Ken + float box_x; + float box_y; + float box_w; + float box_h; + float dash_left_x; + time_t det_time; + int det_milli_sec; + double obj_dwell_time; + + double obj_first_dwell_time; + double obj_last_dwell_time; + + char linked_plate[60]; + int linked_plate_length; + char car_type_name[20]; + char logo[128]; + detection_properties properties; + + int plate_number_count; + detection_sub_properties mea_sub_properties[30]; +#ifdef GY_OS_AMBA + //detection_FDFR FDFR; +#endif + + //list *social_distence_repet_list; + //list *social_distence_new_list; + + int obj_tracking_id_idx; + //int vote_value; + short disappear_count; + + //short iou_prev_self; + //short near_iou_count[MAX_DETECTION_ZONE]; + short IsInsideZone[MAX_DETECTION_ZONE]; + short IsInsideZone_four_points[MAX_DETECTION_ZONE]; + + int test_id; + + unsigned long int image_id; + + int check_if_having_been_counted[MAX_DETECTION_ZONE]; + + int check_if_ok_import_lpr; + + //OBJECT TRACKING + //SOCIAL DIATANCE --MODIFY 20200528 +//#ifdef GY_OS_AMBA + //short distance_violation; + //distance_node social_distance_dup_list[MAX_DETECT_OBJECTS]; + //distance_node social_distance_new_list[MAX_DETECT_OBJECTS]; +//#endif + //SOCIAL DIATANCE + + //speed + float obj_speed[MAX_DETECTION_ZONE]; + float adjust_obj_speed; + //time_t last_speed_time; + //float last_speed_x; + //float last_speed_y; + //speed + + //long s_last_t_Counter[MAX_DETECTION_ZONE]; + + //char sPlateDirection[10]; + + char bring_with_object[MAX_DETECTION_ZONE][MAX_NUM_BRING_WITH_OBJECT][30]; + int num_bring_with_object[MAX_DETECTION_ZONE]; +#ifdef GY_OS_AMBA + float min_distance; + float max_distance; + float min_height; + float max_height; + + float bbox_distance; //object + float bbox_height; //object + +#endif + + int replaced_id; + int replaced_id_idx; + + int check_if_replaced_in_zone; + + //int iIsInvisible; + //int tInvisibleStartTime; + //int tInvisibleUpdateTime; + + } detection_pos; + + typedef struct { + unsigned int obj_tracking_id; + char name[30]; + //char replaced_name[30]; + int detection_count; + //int fake_detection_count; + //float avg_det_interval; + //float det_interval; + time_t first_det_time; + time_t first_det_time_to_enter_zone[MAX_DETECTION_ZONE]; + + int check_if_within_zone[MAX_DETECTION_ZONE]; + + detection_pos predict_detection_avg; + detection_pos predict_detection; + detection_pos prev_detections[TRACKING_BUFFER_SIZE]; + detection_pos predict_detections[TRACKING_BUFFER_SIZE]; + int IsInsideZone[MAX_DETECTION_ZONE][TRACKING_BUFFER_SIZE]; + int IsInsideZone_four_points[MAX_DETECTION_ZONE][TRACKING_BUFFER_SIZE]; + float prev_center_direction[TRACKING_BUFFER_SIZE]; + float prev_center_stability[TRACKING_BUFFER_SIZE]; + float learning_rate_x; + float learning_rate_y; + float learning_rate_error_x; + float learning_rate_error_y; + float mean_diff_x; + float mean_diff_y; + float error_diff_x; + float error_diff_y; + int point_touch[MAX_DETECTION_ZONE][TRACKING_BUFFER_SIZE][MAX_SENSOR_TYPE0]; + int point_touch_four_points[MAX_DETECTION_ZONE][TRACKING_BUFFER_SIZE][MAX_SENSOR_TYPE0]; + int enter_zone_line[MAX_DETECTION_ZONE]; + detection_pos enter_detection_zone[MAX_DETECTION_ZONE][2]; //outside the zone -> inside the zone + int leave_zone_line[MAX_DETECTION_ZONE]; + detection_pos leave_detection_zone[MAX_DETECTION_ZONE][2]; //inside the zone -> outside the zone + + //int trigger_survive[MAX_DETECTION_ZONE]; + int trigger_zone_id; + //int survive_tracking_channel_idx; + //int survive_detection_zone_idx; + //int survive_trigger_idx; + unsigned int trigger_type; + char linked_plate[60]; + int linked_plate_length; + char car_type_name[20]; + char logo[128]; + + //int vote_value; + //int frame_count; + int bAssign_flag; + int Assign_obj_idx; + //int iou_count_table[3]; + //int predit_iou_count_table[3]; + //int union_iou_count_table[3]; + //int union_predit_iou_count_table[3]; + int disappear_count; + + double obj_first_dwell_time; + double obj_last_dwell_time; + + int check_if_having_been_counted[MAX_DETECTION_ZONE]; + + int check_if_ok_import_lpr; + + unsigned long int image_id; + int confidence; +#ifdef GY_OS_NOVA + int class_score; + int object_score; +#endif + //long s_last_t_Counter[MAX_DETECTION_ZONE]; + + float obj_speed_avg[MAX_DETECTION_ZONE]; + float adjust_obj_speed_avg; + + char bring_with_object[MAX_DETECTION_ZONE][MAX_NUM_BRING_WITH_OBJECT][30]; + int num_bring_with_object[MAX_DETECTION_ZONE]; + + } ObjectTracking; + + typedef struct { + time_t rawtime; + + char q_name[30];//debug use + char q_plate[60];//debug use + + char post_event_name[256]; + char post_protocol[11]; + char post_method[11]; + //char post_name[MAX_MSG_LEN]; + char host_name[256];//MAX_MSG_LEN + char host_port[10]; + char post_url[8192];//BUFSIZE_V2 + char post_username[64]; + char post_password[64]; + char post_timeout[10]; + char content[BUFSIZE_V3];//BUFSIZE_V3 //8192*59 //MAX_IMG_SIZE + char content_no_base64_image[BUFSIZE_V2]; + + size_t content_size; + //unsigned char content_bin[MAX_HTTP_BUFFER]; + //char content_to_ipcam[BUFSIZE_V3]; + char cloud_aiengine[BUFSIZE_V2]; + char udp_aiengine[BUFSIZE_V2]; + + char cloud_v2_aiengine[BUFSIZE_V2];// different to cloud_aiengine + //char record_cloud_v2_aiengine[BUFSIZE_V2];// different to cloud_aiengine + + //char rtsp_meta_aiengine[BUFSIZE_V2];// for ipcam onvif + //char onvif_event_aiengine[BUFSIZE_V2];// for ipcam onvif + onvif_data onvif_object[100]; + onvif_counter_info onvif_counter[MAX_EVENT_COUNTERS]; + int onvif_object_num; + //char onvifUtcTime[256]; + + char image_buff[MAX_IMG_SIZE]; + int image_buff_size; + //detection_pos* pNext; + int behavior_ID; + char behavior_name[256]; + char behavior_desc[256]; + char post_customized_header[BUFSIZE_V2]; + + int enable_attached_image; + int enable_filename_fixed; + char post_jpeg_file_name[60]; +#ifdef GY_OS_AMBA + char snmp_event_name[256]; + char snmp_version[10]; + char snmp_group_name[256]; + char snmp_host_ip[256]; + char snmp_host_port[10]; + char snmp_oid[256]; + char snmp_value[BUFSIZE]; + char snmp_type[20]; +#endif + } QueueInfo; + + typedef struct { + int colorCategoryidx; + int colorCount; + } ColorArray; + + typedef struct { + char weight_name[100]; + char anchor_name[100]; + char label_name[100]; + short is_encryption; + } ThirdPartyWeight; + + //typedef struct { + //int H_avg; + //int S_avg; + //int V_avg; + //} HSVFeature; + + typedef struct amba_content { + size_t featureType; + size_t featureType2; + size_t i_layerCount; + size_t i_amba_LayerFeatureType[MAX_LAYER_NUM]; //feature list + size_t i_amba_LayerFeatureType2[MAX_LAYER_NUM]; //feature list + char sz_amba_NetworkNames[MAX_MSG_LEN]; //`net list + char sz_amba_anchor_fileNames[MAX_MSG_LEN]; //anchor file list + char sz_amba_label_fileNames[MAX_MSG_LEN]; //label file list + char sz_amba_ver_fileNames[MAX_MSG_LEN]; //ver file list + + //float confidence_limit; + float confidence_plate; //20210316 jim add + float confidence_traffic; //20210316 jim add + + //LicenseType *licenseType; //20201016 sophia mark + //AuthFailStatusCode *afsCode; //20201016 sophia mark + //AdvanceLicenseType *advLicenseType; //20201016 sophia mark + LicenseType licenseType; + AdvanceLicenseType advLicenseType; + AuthFailStatusCode afsCode; + + int tiny_enable[MAX_LAYER_NUM]; //each net has own tiny_enable, depends on weight is tiny or none tiny. sophia add 20201127 + + int sql_obj_tracking_id[MAX_PLATE_NUM_PER_SEC]; + int sql_obj_dwell_time[MAX_PLATE_NUM_PER_SEC]; + + } amba_content; +//#ifdef GY_OS_AMBA + //extern ObjTrackingIDCheckItem stTrackIDCheckItem[MAX_TRACKING_NUM][MAX_TRACKING_NUM]; + //extern ObjTrackingIDVote stTrackingObjVote[MAX_TRACKING_NUM][MAX_TRACKING_NUM]; +//#endif + extern ObjectTracking g_TrackingRecords[MAX_AI_ENGINE_VIEW][MAX_TRACKING_NUM]; + extern unsigned int g_TrackingIDAndChannel[MAX_AI_ENGINE_VIEW]; + extern int iFeature_lpr_layer_index; + + //extern pthread_mutex_t mutex_strsplit; + //extern int g_tracking_idx; + + extern int g_ori_yuv_width; + extern int g_ori_yuv_height; + extern int g_ori_half_yuv_width; + extern int g_ori_half_yuv_height; + + void QueuePush(QueueInfo q_info, int queue_type); + QueueInfo QueueFront(int queue_type); + void QueuePop(int queue_type); + int QueueSize(int queue_type); + int QueueIsEmpty(int queue_type); + void QueueClear(int queue_type); + + int FileExist(char *filename); + void CopyFileTo(char *src_file, char *dst_file); + size_t ReadFileSize(const char *fileName); + char* ReadAllBytes(const char *fileName); // You must free the result + + float detection_overlap_ratio(detection_pos* det1, detection_pos* det2); + float detection_overlap_ratio_union(detection_pos* det1, detection_pos* det2); + time_t StringToUnixTime(const char *timeString); + char* UnixTimeToString(time_t *timeStamp, int format); // You must free the result +#ifdef GY_OS_WIN + char** GetMACAddress(); // You must free the result +#elif defined GY_OS_AMBA || defined GY_OS_NOVA + void GetMACAddress(char *out_macaddr_buf); //20201111 sophia add + void GetMACAddress_WithoutDash(char* out_macaddr_buf); // 2021.06.09 Cayman added. +#endif + char* StrReplace(char *origion, const char *replace, const char *with); // You must free the result if result is non-NULL. + void str_replace_all(char *target, const char *needle, const char *replacement); + size_t TrimSpace(char *out, size_t len, const char *str, int trim_type); //trim_type:0 = both; 1 = leading, 2 = trailing + int StrSplit(char *InStr, char outArr[][STRSPLIT_SIZE], const char *del); + void UpperToLower(char *str); + void LowerToUpper(char *str); + int StrFrequency(char* substr, char* txt); + int tcsstrFrequency(TCHAR* input_str, TCHAR* sub_str); + int UTF8Strlen(char* str, size_t len); + const char* GetFileExtion(const char *filename); // not need free + void GetFileParts(char *path, char *path_, char *base_, char *ext_); + unsigned long long get_millisec_time(); + void GetScreenResolution(int* width, int* height); + //void Combination(int t[], int count, int total); + int IsANPRCategory(size_t featureType); + int IsANPRCategory_notcode(size_t featureType); + int IsANPRCategory_L_Plate(char * L_Plate); + //int IsTrafficCategory(size_t featureType); + int IsHumanCategory(size_t featureType); + int IsHumanPose(size_t featureType); + int IsVehicleCategory(detection_pos* pNext); + int IsMotorbikeCategory(detection_pos* pNext); + int IsGarbageCategory(detection_pos* pNext); + int IsProductionCategory(detection_pos* pNext); + int IsFireSmokeCategory(size_t featureType); + int IsExistingWeight(size_t featureType, size_t featureType2); + void RefreshCheckExistingWeight(); + + void StripDetectedObjects(detection_pos* posInfo, int *element_size, int img_width, int img_height, int obj_min_proportion, int obj_max_proportion, int min_characters, int max_characters, int confidence, int confidence2, int confidence3, int confidence4); + + void BinaryDFS(int d, int power, int *eachBinArray, int **totalBinArray, int *rows); + int RegexMatch(char* str, char* pattern); + void MapInsert(char* key, char* value); + int MapFind(char* key, char* value); + int MapDelete(char* key); + void MapClear(); + void KillProcessByName(const char *filename); + const char* StringToUTF8(char* cstr); + void DumpHex(const void* data, size_t size); + int CheckSSE(); + unsigned int HexStringToInt(char* HexString); + int onSegment(CPoint p, CPoint q, CPoint r); + int orientation(CPoint p, CPoint q, CPoint r); + int doIntersect(CPoint p1, CPoint q1, CPoint p2, CPoint q2); + int isInside(CPoint polygon[], int n, CPoint p); + + int write_config(); + +#ifdef GY_OS_AMBA + int GetAIImageDimension(char* image_buff, size_t image_buff_size, int* AIImage_width, int* AIImage_height); +#endif + extern cJSON *g_config_root; + + extern short td_weight_num; + extern int check_if_fe_fail; + + extern int check_if_correct_post; + extern int check_if_run_post; + + extern int g_camera_white_LED; + + extern int g_dual_sensor; + + extern int g_check_ping_OK; +#ifdef GY_OS_NOVA + extern int g_check_run_nova_detection; +#endif +#ifdef _MFC_VER + char* CStringToChar(CString cStr); //You must free the result + int GetFileVersion(const wchar_t *filename, char *ver); +#endif + + void QueueLockInit(); + + int lastIndexof(const char* strIn, const char* strtoFind); //fail:-1 //20201008 sophia add + int getFilePath(char* strIn, char*strOut, int nOutSize); //fail:0,ok:1 //20201008 sophia add + int getFileName(char* strIn, char*strOut, int nOutSize); //fail:0,ok:1 //20201008 sophia add + //void split(char **arr, char *str, const char *del); + void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_temp, int tracking_channel_idx, time_t curr_det_time, int i_InSourceOri_w, int i_InSourceOri_h); +#ifdef GY_OS_AMBA + //void GetObjectTrackingIDRadar(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, time_t curr_det_time, float g_radar_img_width, float g_radar_img_height); +#endif + void *read_ipcam_account_setting_thread(void* ptr); +#ifdef GY_OS_AMBA + void *run_osd_server_thread(void* ptr); +#endif + + void read_ipcam_account_setting(); + void get_current_events_json_data(); + void accountData_written_to_events_json(); + void MissingObjectDetection_VanishInZone(int tracking_channel_idx); //1:vanish 0:existing + void CheckEventCounterCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx,int enable_counter_post, char* image_buff, int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64); + void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int force_to_push, char* aiengine_data, int counter_idx, char* image_buff, int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64); + void HeartbeatPost(); +#ifdef GY_OS_AMBA + void check_start_PTZ_autotracking_Post(); + void check_end_PTZ_autotracking_Post(); +#endif + void SendMailEventCondition(char *my_subject, char * my_content, char* image_buff, int image_buff_size); + size_t ReplaceKeyWords(detection_pos* pNext, int space_zone, int space_id,char* InputString, char *OutputString, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64, int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox); + size_t ReplaceKeyWords_space(detection_pos* pNext, char *SequenceString, int space_zone, int space_id, char* InputString, char *OutputString, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64, int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox); + + void reset_id_obj(int tracking_channel_idx, int id_idx); + void set_DISAPPEAR_FRAME_MAX(int disappear_frame_max_temp); + void check_license(int license, int adv_license, int bMacMatch, time_t start_time, time_t end_time, char* filename); + void check_feature(); + void *run_event_counter_thread(void *ptr); + void write_to_enable_tracking(char *enable_tracking); + void *run_post_notification_thread(void *ptr); + void UpdateBehaviorData(QueueInfo* q_info, int tracking_channel_idx, int detection_zone_idx, int trigger_idx,int enable_lang); + void ResetCheckIfDelivering(); + long Get_eventCounterList_post_interval(int index_counter); + long Get_mail_post_interval(); + void write_to_logs_html(char * logs_message, char * logs_thread, char * logs_level, char *enable_system_logs); + void write_to_log_if_error(char * msg_error, char * msg_func, char *msg_label); + void write_to_log_for_start(char * msg_error, char * msg_func, char *msg_label); + void write_to_log_if_error_nvclient(char * msg_error); + void write_to_log_if_error_post_pns(char * msg_error); + + float polygon_area(CPoint area_point[], int actual_size); + + int get_check_if_correct_mail(); + void get_classname(int my_class_id, char* my_class_name); + void stop_btHttpServer(); +//#if defined GY_OS_AMBA + void get_image_dn(); + int get_check_if_existing_any_switch_happened(); +//#endif + + float X_Tranform_To_Onvif_Space(float ori_x_value, int half_ori_yuv_width); + float Y_Tranform_To_Onvif_Space(float ori_y_value, int half_ori_yuv_height); + + int external_memory_fragmentation_management(); + + long open_max(void); + FILE *vpopen(const char* cmdstring, const char *type); + int vpclose(FILE *fp); + + //extern struct timeval currtime_CheckPostEventCondition_cloud; + //extern long last_ms_CheckPostEventCondition_cloud; + //extern long current_ms_CheckPostEventCondition_cloud; +#if 0 + CPoint SubPoint(CPoint vTarget1, CPoint vTarget2); + float CrossProduct(CPoint vTarget1, CPoint vTarget2); + int IsPointInConvexPolygon(CPoint aPoints[], CPoint vTarget); +#endif +#ifdef GY_OS_NOVA + void write_driver_setting_file(char* buffer_json_string); +#endif + void stop_server(); + long getCurrentTime(); + void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, CPoint* zone_polygon, int side_number, int zone_index, int iSource_ori_w, int iSource_ori_h); + int insert_string(char* s, char* t, int i); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + void ReplacePlateWithDB(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx); + void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx); +#endif + void ObjectFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx); +#if defined GY_OS_AMBA || defined GY_OS_NOVA + void AddTWPlateDASH(detection_pos* PosInfo, int total_element_size, int featureType); + void MEAPlateRule(detection_pos* PosInfo, int total_element_size); +#endif + int Modify_Plate_and_Recount_Length(char *input_plate, char *output_plate); + + int strstr_cnt(const char *string, const char *substring); + + extern int g_max_sensor_size; + extern int g_sensors_type; + extern int g_check_if_OK_to_start_osd_server; + + extern int unlockingKeyInnoFR_success; +#ifdef GY_OS_AMBA + extern int g_check_current_resolution; +#endif + extern int g_enable_person_for_metadata[MAX_DETECTION_ZONE]; + + int get_bHttpServerThreadStart(); + + void delete_heatmap_image(); +#ifdef GY_OS_NOVA + void *RUN_NOVA_DETECTION(void *ptr); +#endif + void run_server(int argc, char **argv); +#ifdef GY_OS_AMBA + void cavalry_gen_sdk_3_0(char * bin_name); +#endif + void setPthreadName(char *p_name); + + + char *strtok_modified(char *str, const char *delim, char **saveptr); + + void delete_file(char *file_name); + + extern char WeightFileModeName[35]; + + void usSleep(unsigned int nusecs); + + void move_file(); + void writeImageFromBuffer(const char* filename, const char* buffer, unsigned long length); + + void getCameraPlugInInfo(); + void initial_weight_settings(); + void file_management(); + + void initial_g_PostRecorderList(); + void set_record_process_note(char *process_note); + + void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size); +#ifdef GY_OS_V_SERIES + +#else + void reset_counter(int index_counter, time_t now_time); + void set_counter_zone(); + void run_counter_mail(char * mail_content, int mail_content_size); +#endif + +#ifdef __cplusplus +} +#endif + +#endif +#endif \ No newline at end of file diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..97a1eac --- /dev/null +++ b/src/utils.c @@ -0,0 +1,687 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <assert.h> +#include <unistd.h> +#include <float.h> +#include <limits.h> +#include <time.h> +#include <sys/time.h> + +#include "utils.h" + +double what_time_is_it_now() +{ + struct timeval time; + if (gettimeofday(&time,NULL)){ + return 0; + } + return (double)time.tv_sec + (double)time.tv_usec * .000001; +} + +int *read_intlist(char *gpu_list, int *ngpus, int d) +{ + int *gpus = 0; + if(gpu_list){ + int len = strlen(gpu_list); + *ngpus = 1; + int i; + for(i = 0; i < len; ++i){ + if (gpu_list[i] == ',') ++*ngpus; + } + gpus = calloc(*ngpus, sizeof(int)); + for(i = 0; i < *ngpus; ++i){ + gpus[i] = atoi(gpu_list); + gpu_list = strchr(gpu_list, ',')+1; + } + } else { + gpus = calloc(1, sizeof(float)); + *gpus = d; + *ngpus = 1; + } + return gpus; +} + +int *read_map(char *filename) +{ + int n = 0; + int *map = 0; + char *str; + FILE *file = fopen(filename, "r"); + if(!file) file_error(filename); + while((str=fgetl(file))){ + ++n; + map = realloc(map, n*sizeof(int)); + map[n-1] = atoi(str); + } + return map; +} + +void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections) +{ + size_t i; + for(i = 0; i < sections; ++i){ + size_t start = n*i/sections; + size_t end = n*(i+1)/sections; + size_t num = end-start; + shuffle(arr+(start*size), num, size); + } +} + +void shuffle(void *arr, size_t n, size_t size) +{ + size_t i; + void *swp = calloc(1, size); + for(i = 0; i < n-1; ++i){ + size_t j = i + rand()/(RAND_MAX / (n-i)+1); + memcpy(swp, arr+(j*size), size); + memcpy(arr+(j*size), arr+(i*size), size); + memcpy(arr+(i*size), swp, size); + } +} + +int *random_index_order(int min, int max) +{ + int *inds = calloc(max-min, sizeof(int)); + int i; + for(i = min; i < max; ++i){ + inds[i] = i; + } + for(i = min; i < max-1; ++i){ + int swap = inds[i]; + int index = i + rand()%(max-i); + inds[i] = inds[index]; + inds[index] = swap; + } + return inds; +} + +void del_arg(int argc, char **argv, int index) +{ + int i; + for(i = index; i < argc-1; ++i) argv[i] = argv[i+1]; + argv[i] = 0; +} + +int find_arg(int argc, char* argv[], char *arg) +{ + int i; + for(i = 0; i < argc; ++i) { + if(!argv[i]) continue; + if(0==strcmp(argv[i], arg)) { + del_arg(argc, argv, i); + return 1; + } + } + return 0; +} + +int find_int_arg(int argc, char **argv, char *arg, int def) +{ + int i; + for(i = 0; i < argc-1; ++i){ + if(!argv[i]) continue; + if(0==strcmp(argv[i], arg)){ + def = atoi(argv[i+1]); + del_arg(argc, argv, i); + del_arg(argc, argv, i); + break; + } + } + return def; +} + +float find_float_arg(int argc, char **argv, char *arg, float def) +{ + int i; + for(i = 0; i < argc-1; ++i){ + if(!argv[i]) continue; + if(0==strcmp(argv[i], arg)){ + def = atof(argv[i+1]); + del_arg(argc, argv, i); + del_arg(argc, argv, i); + break; + } + } + return def; +} + +char *find_char_arg(int argc, char **argv, char *arg, char *def) +{ + int i; + for(i = 0; i < argc-1; ++i){ + if(!argv[i]) continue; + if(0==strcmp(argv[i], arg)){ + def = argv[i+1]; + del_arg(argc, argv, i); + del_arg(argc, argv, i); + break; + } + } + return def; +} + +int alphanum_to_int(char c) +{ + return (c < 58) ? c - 48 : c-87; +} +char int_to_alphanum(int i) +{ + if (i == 36) return '.'; + return (i < 10) ? i + 48 : i + 87; +} + +void pm(int M, int N, float *A) +{ + int i,j; + for(i =0 ; i < M; ++i){ + printf("%d ", i+1); + for(j = 0; j < N; ++j){ + printf("%2.4f, ", A[i*N+j]); + } + printf("\n"); + } + printf("\n"); +} + +void find_replace(char *str, char *orig, char *rep, char *output) +{ + char buffer[4096] = {0}; + char *p; + + sprintf(buffer, "%s", str); + if(!(p = strstr(buffer, orig))){ // Is 'orig' even in 'str'? + sprintf(output, "%s", str); + return; + } + + *p = '\0'; + + sprintf(output, "%s%s%s", buffer, rep, p+strlen(orig)); +} + +float sec(clock_t clocks) +{ + return (float)clocks/CLOCKS_PER_SEC; +} + +void top_k(float *a, int n, int k, int *index) +{ + int i,j; + for(j = 0; j < k; ++j) index[j] = -1; + for(i = 0; i < n; ++i){ + int curr = i; + for(j = 0; j < k; ++j){ + if((index[j] < 0) || a[curr] > a[index[j]]){ + int swap = curr; + curr = index[j]; + index[j] = swap; + } + } + } +} + +void error(const char *s) +{ + printf("\n%s\n",s); + assert(0); + printf("\nerror: %s\n",s); + exit(-1); +} + +unsigned char *read_file(char *filename) +{ + FILE *fp = fopen(filename, "rb"); + size_t size; + + fseek(fp, 0, SEEK_END); + size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + unsigned char *text = calloc(size+1, sizeof(char)); + fread(text, 1, size, fp); + fclose(fp); + return text; +} + +void malloc_error() +{ + fprintf(stderr, "Malloc error\n"); + printf("Malloc error\n"); + exit(-1); +} + +void file_error(char *s) +{ + fprintf(stderr, "Couldn't open file: %s\n", s); + printf("Couldn't open file: %s\n", s); + exit(0); +} + +/*list *split_str(char *s, char delim) +{ + size_t i; + size_t len = strlen(s); + list *l = make_list(); + list_insert(l, s); + for(i = 0; i < len; ++i){ + if(s[i] == delim){ + s[i] = '\0'; + list_insert(l, &(s[i+1])); + } + } + return l; +}*/ + +void strip(char *s) +{ + size_t i; + size_t len = strlen(s); + size_t offset = 0; + for(i = 0; i < len; ++i){ + char c = s[i]; + if(c==' '||c=='\t'||c=='\n') ++offset; + else s[i-offset] = c; + } + s[len-offset] = '\0'; +} + +void strip_char(char *s, char bad) +{ + size_t i; + size_t len = strlen(s); + size_t offset = 0; + for(i = 0; i < len; ++i){ + char c = s[i]; + if(c==bad) ++offset; + else s[i-offset] = c; + } + s[len-offset] = '\0'; +} + +void free_ptrs(void **ptrs, int n) +{ + int i; + for (i = 0; i < n; ++i) { + if (ptrs[i]) { + free(ptrs[i]); + ptrs[i] = NULL; + } + }; + if (ptrs) { + free(ptrs); + ptrs = NULL; + } +} + +char *fgetl(FILE *fp) +{ + if(feof(fp)) return 0; + size_t size = 512; + char *line = malloc(size*sizeof(char)); + if(!fgets(line, size, fp)){ + if (line) { + free(line); + line = NULL; + } + return 0; + } + + size_t curr = strlen(line); + + while((line[curr-1] != '\n') && !feof(fp)){ + if(curr == size-1){ + size *= 2; + line = realloc(line, size*sizeof(char)); + if(!line) { + //printf("%ld\n", size); + malloc_error(); + } + } + size_t readsize = size-curr; + if(readsize > INT_MAX) readsize = INT_MAX-1; + fgets(&line[curr], readsize, fp); + curr = strlen(line); + } + if(line[curr-1] == '\n') line[curr-1] = '\0'; + + return line; +} + +int read_int(int fd) +{ + int n = 0; + int next = read(fd, &n, sizeof(int)); + if(next <= 0) return -1; + return n; +} + +void write_int(int fd, int n) +{ + int next = write(fd, &n, sizeof(int)); + if(next <= 0) error("read failed"); +} + +int read_all_fail(int fd, char *buffer, size_t bytes) +{ + size_t n = 0; + while(n < bytes){ + int next = read(fd, buffer + n, bytes-n); + if(next <= 0) return 1; + n += next; + } + return 0; +} + +int write_all_fail(int fd, char *buffer, size_t bytes) +{ + size_t n = 0; + while(n < bytes){ + size_t next = write(fd, buffer + n, bytes-n); + if(next <= 0) return 1; + n += next; + } + return 0; +} + +void read_all(int fd, char *buffer, size_t bytes) +{ + size_t n = 0; + while(n < bytes){ + int next = read(fd, buffer + n, bytes-n); + if(next <= 0) error("read failed"); + n += next; + } +} + +void write_all(int fd, char *buffer, size_t bytes) +{ + size_t n = 0; + while(n < bytes){ + size_t next = write(fd, buffer + n, bytes-n); + if(next <= 0) error("write failed"); + n += next; + } +} + +int count_fields(char *line) +{ + int count = 0; + int done = 0; + char *c; + for(c = line; !done; ++c){ + done = (*c == '\0'); + if(*c == ',' || done) ++count; + } + return count; +} + +float *parse_fields(char *line, int n) +{ + float *field = calloc(n, sizeof(float)); + char *c, *p, *end; + int count = 0; + int done = 0; + for(c = line, p = line; !done; ++c){ + done = (*c == '\0'); + if(*c == ',' || done){ + *c = '\0'; + field[count] = strtod(p, &end); + if(p == c) field[count] = nan(""); + if(end != c && (end != c-1 || *end != '\r')) field[count] = nan(""); //DOS file formats! + p = c+1; + ++count; + } + } + return field; +} + +float sum_array(float *a, int n) +{ + int i; + float sum = 0; + for(i = 0; i < n; ++i) sum += a[i]; + return sum; +} + +float mean_array(float *a, int n) +{ + return sum_array(a,n)/n; +} + +void mean_arrays(float **a, int n, int els, float *avg) +{ + int i; + int j; + memset(avg, 0, els*sizeof(float)); + for(j = 0; j < n; ++j){ + for(i = 0; i < els; ++i){ + avg[i] += a[j][i]; + } + } + for(i = 0; i < els; ++i){ + avg[i] /= n; + } +} + +void print_statistics(float *a, int n) +{ + float m = mean_array(a, n); + float v = variance_array(a, n); + printf("MSE: %.6f, Mean: %.6f, Variance: %.6f\n", mse_array(a, n), m, v); +} + +float variance_array(float *a, int n) +{ + int i; + float sum = 0; + float mean = mean_array(a, n); + for(i = 0; i < n; ++i) sum += (a[i] - mean)*(a[i]-mean); + float variance = sum/n; + return variance; +} + +int constrain_int(int a, int min, int max) +{ + if (a < min) return min; + if (a > max) return max; + return a; +} + +float constrain(float min, float max, float a) +{ + if (a < min) return min; + if (a > max) return max; + return a; +} + +float dist_array(float *a, float *b, int n, int sub) +{ + int i; + float sum = 0; + for(i = 0; i < n; i += sub) sum += pow(a[i]-b[i], 2); + return sqrt(sum); +} + +float mse_array(float *a, int n) +{ + int i; + float sum = 0; + for(i = 0; i < n; ++i) sum += a[i]*a[i]; + return sqrt(sum/n); +} + +void normalize_array(float *a, int n) +{ + int i; + float mu = mean_array(a,n); + float sigma = sqrt(variance_array(a,n)); + for(i = 0; i < n; ++i){ + a[i] = (a[i] - mu)/sigma; + } + mu = mean_array(a,n); + sigma = sqrt(variance_array(a,n)); +} + +void translate_array(float *a, int n, float s) +{ + int i; + for(i = 0; i < n; ++i){ + a[i] += s; + } +} + +float mag_array(float *a, int n) +{ + int i; + float sum = 0; + for(i = 0; i < n; ++i){ + sum += a[i]*a[i]; + } + return sqrt(sum); +} + +void scale_array(float *a, int n, float s) +{ + int i; + for(i = 0; i < n; ++i){ + a[i] *= s; + } +} + +int sample_array(float *a, int n) +{ + float sum = sum_array(a, n); + scale_array(a, n, 1./sum); + float r = rand_uniform(0, 1); + int i; + for(i = 0; i < n; ++i){ + r = r - a[i]; + if (r <= 0) return i; + } + return n-1; +} + +int max_int_index(int *a, int n) +{ + if(n <= 0) return -1; + int i, max_i = 0; + int max = a[0]; + for(i = 1; i < n; ++i){ + if(a[i] > max){ + max = a[i]; + max_i = i; + } + } + return max_i; +} + +int max_index(float *a, int n) +{ + if(n <= 0) return -1; + int i, max_i = 0; + float max = a[0]; + for(i = 1; i < n; ++i){ + if(a[i] > max){ + max = a[i]; + max_i = i; + } + } + return max_i; +} + +int int_index(int *a, int val, int n) +{ + int i; + for(i = 0; i < n; ++i){ + if(a[i] == val) return i; + } + return -1; +} + +int rand_int(int min, int max) +{ + if (max < min){ + int s = min; + min = max; + max = s; + } + int r = (rand()%(max - min + 1)) + min; + return r; +} + +// From http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform +float rand_normal() +{ + static int haveSpare = 0; + static double rand1, rand2; + + if(haveSpare) + { + haveSpare = 0; + return sqrt(rand1) * sin(rand2); + } + + haveSpare = 1; + + rand1 = rand() / ((double) RAND_MAX); + if(rand1 < 1e-100) rand1 = 1e-100; + rand1 = -2 * log(rand1); + rand2 = (rand() / ((double) RAND_MAX)) * TWO_PI; + + return sqrt(rand1) * cos(rand2); +} + +/* + float rand_normal() + { + int n = 12; + int i; + float sum= 0; + for(i = 0; i < n; ++i) sum += (float)rand()/RAND_MAX; + return sum-n/2.; + } + */ + +/*size_t rand_size_t() +{ + return ((size_t)(rand()&0xff) << 56) | + ((size_t)(rand()&0xff) << 48) | + ((size_t)(rand()&0xff) << 40) | + ((size_t)(rand()&0xff) << 32) | + ((size_t)(rand()&0xff) << 24) | + ((size_t)(rand()&0xff) << 16) | + ((size_t)(rand()&0xff) << 8) | + ((size_t)(rand()&0xff) << 0); +}*/ + +float rand_uniform(float min, float max) +{ + if(max < min){ + float swap = min; + min = max; + max = swap; + } + return ((float)rand()/RAND_MAX * (max - min)) + min; +} + +float rand_scale(float s) +{ + float scale = rand_uniform(1, s); + if(rand()%2) return scale; + return 1./scale; +} + +float **one_hot_encode(float *a, int n, int k) +{ + int i; + float **t = calloc(n, sizeof(float*)); + for(i = 0; i < n; ++i){ + t[i] = calloc(k, sizeof(float)); + int index = (int)a[i]; + t[i][index] = 1; + } + return t; +} + diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..596f2d2 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,118 @@ +#pragma once +#ifndef UTILS_H +#define UTILS_H +#include "define_inc.h" +#include <stdio.h> +#include <time.h> +#include "darknet.h" +#include "list.h" + +#ifndef clip3 +#define clip3(a, b, c) fmax(fmin(b, c), a) +#endif + +/* set debug level */ +#define AMBA_DATA_PROCESS_DEBUG_ENABLE 0 // Disable it for real applicaton, enable it when debug +#define AMBA_DATA_PROCESS_DEBUG_LEVEL (L_INFO) + +typedef enum amba_ssd_debug_level_s +{ + AMBA_DATA_PROCESS_DEBUG_LEVEL_ERROR = 0, + AMBA_DATA_PROCESS_DEBUG_LEVEL_WARNING = 1, + AMBA_DATA_PROCESS_DEBUG_LEVEL_INFO = 2, + AMBA_DATA_PROCESS_DEBUG_LEVEL_DEBUG = 3, +} amba_ssd_debug_level_t; + +#define L_ERROR AMBA_DATA_PROCESS_DEBUG_LEVEL_ERROR +#define L_WARNING AMBA_DATA_PROCESS_DEBUG_LEVEL_WARNING +#define L_INFO AMBA_DATA_PROCESS_DEBUG_LEVEL_INFO +#define L_DEBUG AMBA_DATA_PROCESS_DEBUG_LEVEL_DEBUG + +#if (AMBA_DATA_PROCESS_DEBUG_ENABLE == 1) +#define DPRINT(level, ...) \ +do {\ + if ((level) <= AMBA_DATA_PROCESS_DEBUG_LEVEL) {\ + printf(__VA_ARGS__);\ + }\ +} while(0) +#else +#define DPRINT(level, ...) +#endif + +#define TIME(a) \ + do { \ + double start = what_time_is_it_now(); \ + a; \ + printf("%s took: %f seconds\n", #a, what_time_is_it_now() - start); \ + } while (0) + +#define SECRET_NUM -1234 +#define TWO_PI 6.2831853071795864769252866f + +double what_time_is_it_now(); +void shuffle(void *arr, size_t n, size_t size); +void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections); +void free_ptrs(void **ptrs, int n); +int alphanum_to_int(char c); +char int_to_alphanum(int i); +int read_int(int fd); +void write_int(int fd, int n); +void read_all(int fd, char *buffer, size_t bytes); +void write_all(int fd, char *buffer, size_t bytes); +int read_all_fail(int fd, char *buffer, size_t bytes); +int write_all_fail(int fd, char *buffer, size_t bytes); +void find_replace(char *str, char *orig, char *rep, char *output); +void malloc_error(); +void file_error(char *s); +void strip(char *s); +void strip_char(char *s, char bad); +//list *split_str(char *s, char delim); +char *fgetl(FILE *fp); + + +int count_fields(char *line); +float *parse_fields(char *line, int n); +void translate_array(float *a, int n, float s); +float constrain(float min, float max, float a); +int constrain_int(int a, int min, int max); +float rand_scale(float s); +int rand_int(int min, int max); +void mean_arrays(float **a, int n, int els, float *avg); +float dist_array(float *a, float *b, int n, int sub); +float **one_hot_encode(float *a, int n, int k); +float sec(clock_t clocks); +void print_statistics(float *a, int n); +int int_index(int *a, int val, int n); + + +int find_int_arg(int argc, char **argv, char *arg, int def); +float find_float_arg(int argc, char **argv, char *arg, float def); +int find_arg(int argc, char* argv[], char *arg); +char *find_char_arg(int argc, char **argv, char *arg, char *def); + +void find_replace(char *str, char *orig, char *rep, char *output); +void free_ptrs(void **ptrs, int n); +char *fgetl(FILE *fp); +void strip(char *s); +float sec(clock_t clocks); + +void top_k(float *a, int n, int k, int *index); +int *read_map(char *filename); +void error(const char *s); +int max_index(float *a, int n); +int sample_array(float *a, int n); + +float mse_array(float *a, int n); +float variance_array(float *a, int n); +float mag_array(float *a, int n); +void scale_array(float *a, int n, float s); +float mean_array(float *a, int n); +float sum_array(float *a, int n); +void normalize_array(float *a, int n); + +//size_t rand_size_t(); +float rand_normal(); +float rand_uniform(float min, float max); + +#endif + diff --git a/src/websocket.c b/src/websocket.c new file mode 100644 index 0000000..59ffc9b --- /dev/null +++ b/src/websocket.c @@ -0,0 +1,869 @@ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <math.h> +#include <limits.h> +#include "utility.h" + + +#include "websocket.h" + +//#include <openssl/pem.h> +//SHA_DIGEST_LENGTH + +//Client +//GET /demo HTTP/1.1 +//Host: example.com +//Connection: Upgrade +//Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 +//Sec-WebSocket-Protocol: sample +//Upgrade: WebSocket +//Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5 +//Origin: http://example.com +// +//^n:ds[4U + +REQ_INFO g_pCli; + +int strcnt(char *sOriString, char *sFindString) +{ + int iFindSubStrNum = 0; + int iStrLen1 = 0; + int iStrLen2 = 0; + //int iSearchIdx = 0; + int iCheckString = 1; + + if (sOriString && sFindString) + { + iStrLen1 = strlen(sOriString); + iStrLen2 = strlen(sFindString); + } + else + { + iCheckString = 0; + } + + int i, j, k; + + if (iCheckString == 1 + && iStrLen1 > 0 + && iStrLen2 > 0) + { + for (i = 0; sOriString[i] != '\0'; i++) + { + for (j = i, k = 0; sOriString[j] == sFindString[k]; j++, k++) + { + if (sFindString[k + 1] == '\0') + iFindSubStrNum++; + } + } + } + + return iFindSubStrNum; +} + +//The handshake from the server looks as follows: +//HTTP/1.1 101 WebSocket Protocol Handshake +//Upgrade: WebSocket +//Connection: Upgrade +//Sec-WebSocket-Origin: http://example.com +//Sec-WebSocket-Location: ws://example.com/demo +//Sec-WebSocket-Protocol: sample +// +//8jKS??????y:G*Co,Wxa- +//reference https://tools.ietf.org/pdf/draft-ietf-hybi-thewebsocketprotocol-00.pdf +//int send_websocket_hybi_00_boundary_header(REQ_INFO *pCli) +int send_websocket_hybi_00_boundary_header() +{ +#if 1 + //REQ_INFO *pCli; + //pCli = &g_pCli; + + char tmpString[2048] = { 0 }; + //char md5Str[17] = { 0 }; + char combineStr[17] = { 0 }; + char key1Str[512] = { 0 }; + char key2Str[512] = { 0 }; + char bigEndKey1[4] = { 0 }; + char bigEndKey2[4] = { 0 }; + + int k1len = strlen(g_pCli.sSec_websocket_key1); + int k2len = strlen(g_pCli.sSec_websocket_key2); + + int i = 0, cnt = 0; + + // remove space, take out digit + for (i = 0; i < k1len; i++) + { + if (isdigit(g_pCli.sSec_websocket_key1[i])) + key1Str[cnt++] = g_pCli.sSec_websocket_key1[i]; + } + + cnt = 0; + for (i = 0; i < k2len; i++) + { + if (isdigit(g_pCli.sSec_websocket_key2[i])) + key2Str[cnt++] = g_pCli.sSec_websocket_key2[i]; + } + + long long iK1 = atoll(key1Str); + long long iK2 = atoll(key2Str); + + // number / spaces + int k1Spaces = strcnt(g_pCli.sSec_websocket_key1, " "); + int k2Spaces = strcnt(g_pCli.sSec_websocket_key2, " "); + + unsigned int k1FinalNum = (k1Spaces > 0) ? ((unsigned int)(iK1 / k1Spaces)) : 0; + unsigned int k2FinalNum = (k2Spaces > 0) ? ((unsigned int)(iK2 / k2Spaces)) : 0; + + + bigEndKey1[0] = (k1FinalNum >> 24) & 0xFF; + bigEndKey1[1] = (k1FinalNum >> 16) & 0xFF; + bigEndKey1[2] = (k1FinalNum >> 8) & 0xFF; + bigEndKey1[3] = k1FinalNum & 0xFF; + + bigEndKey2[0] = (k2FinalNum >> 24) & 0xFF; + bigEndKey2[1] = (k2FinalNum >> 16) & 0xFF; + bigEndKey2[2] = (k2FinalNum >> 8) & 0xFF; + bigEndKey2[3] = k2FinalNum & 0xFF; + + + memcpy(&combineStr[0], bigEndKey1, 4); + memcpy(&combineStr[4], bigEndKey2, 4); + memcpy(&combineStr[8], g_pCli.sSec_websocket_key3, 8); + + unsigned char md5String[17] = { 0 }; + DoMD5((unsigned char *)combineStr, (unsigned char *)md5String); //5F ver + + int send_len/*, len = 0*/; + if (strlen(g_pCli.sNVR_Auth) >= 1) + { + /*len = */sprintf(tmpString, "%s %d %s\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Origin: %s\r\n" + "Sec-WebSocket-Location: ws://%s/getalarmmotion?nvr_auth=%s\r\n" + //"Sec-WebSocket-Protocol: %s\r\n" + "\r\n" + "%s", // key3 + "HTTP/1.1", //HTTP/1.1 //PROTOCOL + 101, + "WebSocket Protocol Handshake", + g_pCli.sOrigin, + g_pCli.sHost, + g_pCli.sNVR_Auth, + //pCli->sPath,//Note this path already special handle before use it. + //pCli->header.sec_websocket_protocol, + md5String + ); + } + else { + /*len = */sprintf(tmpString, "%s %d %s\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Origin: %s\r\n" + "Sec-WebSocket-Location: ws://%s/%s\r\n" + //"Sec-WebSocket-Protocol: %s\r\n" + "\r\n" + "%s", // key3 + "HTTP/1.1", //HTTP/1.1 //PROTOCOL + 101, + "WebSocket Protocol Handshake", + g_pCli.sOrigin, + g_pCli.sHost, + "getalarmmotion", + //pCli->sPath,//Note this path already special handle before use it. + //pCli->header.sec_websocket_protocol, + md5String + ); + } + //printf("[%d]vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv send string: \n %s\n", g_pCli.socket, tmpString); + + +#if 1 + send_len = block_to_send(g_pCli.socket, (unsigned char *)tmpString, strlen(tmpString), 1000000, 4096, NULL); + if (send_len <= 0) + printf("[%d] block to send >>>>>>>>>> %s fail\r\n", g_pCli.socket, __func__); + //else + //printf("[%d] block to send >>>>>>>>>> send len: %d \n", g_pCli.socket, send_len); +#endif + + +#endif + +#if 0 + REQ_INFO *pCli; + pCli = &g_pCli; + + //char *tmpString = KMALLOC((2 * KILO)); + //char *tmpString = KMALLOC((2048)); + //char *md5String = KMALLOC(17); + //char *combineStr = KMALLOC(17); + //char *key1Str = KMALLOC(512); + //char *key2Str = KMALLOC(512); + //char *bigEndKey1 = KMALLOC(4); + //char *bigEndKey2 = KMALLOC(4); + + char tmpString[2048] = { 0 }; + char md5Str[17] = { 0 }; + char combineStr[17] = { 0 }; + char key1Str[512] = { 0 }; + char key2Str[512] = { 0 }; + char bigEndKey1[4] = { 0 }; + char bigEndKey2[4] = { 0 }; + + int k1len = strlen(pCli->sSec_websocket_key1); + int k2len = strlen(pCli->sSec_websocket_key2); + + //printf("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP \n"); + //printf( "---%s---\r\n", pCli->sSec_websocket_key1 ); + //printf( "---%s---\r\n", pCli->sSec_websocket_key2 ); + //printf( "---%s---\r\n", pCli->sSec_websocket_key3); + + int i = 0, cnt = 0; + + // remove space, take out digit + for (i = 0; i < k1len; i++) + { + if (isdigit(pCli->sSec_websocket_key1[i])) + key1Str[cnt++] = pCli->sSec_websocket_key1[i]; + } + + cnt = 0; + for (i = 0; i < k2len; i++) + { + if (isdigit(pCli->sSec_websocket_key2[i])) + key2Str[cnt++] = pCli->sSec_websocket_key2[i]; + } + // KDEBUG( "key1str:%s\r\n", key1Str ); + // KDEBUG( "key2str:%s\r\n", key2Str ); + long long iK1 = atoll(key1Str); + long long iK2 = atoll(key2Str); + // KDEBUG( "iK1 %lld\r\n", iK1 ); + // KDEBUG( "iK2 %lld\r\n", iK2 ); + + // number / spaces + int k1Spaces = strcnt(pCli->sSec_websocket_key1, " "); + int k2Spaces = strcnt(pCli->sSec_websocket_key2, " "); + // KDEBUG( "k1Spaces %d\r\n", k1Spaces ); + // KDEBUG( "k1Spaces %d\r\n", k2Spaces ); + + unsigned int k1FinalNum = (k1Spaces > 0) ? ((unsigned int)(iK1 / k1Spaces)) : 0; + unsigned int k2FinalNum = (k2Spaces > 0) ? ((unsigned int)(iK2 / k2Spaces)) : 0; + + // KDEBUG( "k1FinalNum %ul\r\n", k1FinalNum ); + // KDEBUG( "k2FinalNum %ul\r\n", k2FinalNum ); + + bigEndKey1[0] = (k1FinalNum >> 24) & 0xFF; + bigEndKey1[1] = (k1FinalNum >> 16) & 0xFF; + bigEndKey1[2] = (k1FinalNum >> 8) & 0xFF; + bigEndKey1[3] = k1FinalNum & 0xFF; + + bigEndKey2[0] = (k2FinalNum >> 24) & 0xFF; + bigEndKey2[1] = (k2FinalNum >> 16) & 0xFF; + bigEndKey2[2] = (k2FinalNum >> 8) & 0xFF; + bigEndKey2[3] = k2FinalNum & 0xFF; + + // DUMP_BUFF( ( BYTE* )bigEndKey1, 4 ); + // DUMP_BUFF( ( BYTE* )bigEndKey2, 4 ); + + memcpy(&combineStr[0], bigEndKey1, 4); + memcpy(&combineStr[4], bigEndKey2, 4); + memcpy(&combineStr[8], pCli->sSec_websocket_key3, 8); + //memcpy(&combineStr[8], pCli->sSec_websocket_key3_str, 8);//sSec_websocket_key3_str + + unsigned char md5String[17] = { 0 }; + DoMD5((unsigned char *)combineStr, (unsigned char *)md5String); //5F ver + //unsigned char* key_by_md5 = md5String((unsigned char *)combineStr); //7F ver + //unsigned char* key_by_md5 = md5String((unsigned char *)"helloworld"); //7F ver + //memcpy(md5Str, key_by_md5, 16); + //md5Str + + //if (key_by_md5) { + // free(key_by_md5); + // key_by_md5 = NULL; + //} + + int send_len, len = 0; + len = sprintf(tmpString, "%s %d %s\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Origin: %s\r\n" + "Sec-WebSocket-Location: ws://%s/%s\r\n" + //"Sec-WebSocket-Protocol: %s\r\n" + "\r\n" + "%s", // key3 + "HTTP/1.1", //HTTP/1.1 //PROTOCOL + 101, + "WebSocket Protocol Handshake", + pCli->sOrigin, + pCli->sHost, + "getalarmmotion", + //pCli->sPath,//Note this path already special handle before use it. + //pCli->header.sec_websocket_protocol, + md5String + ); + +#if 0 // debug + char *debugString = KMALLOC((2 * KILO)); + memcpy(debugString, tmpString, len - 16); + KDEBUG("\r\n%s\r\n", debugString); + DUMP_BUFF((BYTE*)md5Str, 16); + _SAFE_FREE(debugString); +#endif + + printf("[%d]vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv send string: \n %s\n", pCli->socket, tmpString); +#if 0 + send_len = send(pCli->socket, tmpString, strlen(tmpString)); + + //retry + int retry_count = 10; + if (send_len <= 0) + { + while (retry_count >= 0) + { + send_len = send(pCli->socket, tmpString, strlen(tmpString)); + if (send_len > 0) + break; + + retry_count--; + + usSleep(1000); + } + } +#endif + +#if 1 + send_len = block_to_send(pCli->socket, (unsigned char *)tmpString, strlen(tmpString), 1000000, 4096, NULL); + if (send_len <= 0) + printf("ggggggg %s fail\r\n", __func__); + else + printf("[%d]ggggggg send len: %d \n", pCli->socket, send_len); +#endif + + + +#if 0 + + _SAFE_FREE(md5Str); + _SAFE_FREE(tmpString); + _SAFE_FREE(combineStr); + _SAFE_FREE(key1Str); + _SAFE_FREE(key2Str); + _SAFE_FREE(bigEndKey1); + _SAFE_FREE(bigEndKey2); +#endif + +#endif + return send_len; +} + + +/** + * @brief _readline + * read a line string from all buffer + * @param allbuf + * @param level + * @param linebuf + * @return + */ +int _readline(char* allbuf, int level, char* linebuf) +{ + int len = strlen(allbuf); + for (; level < len; ++level) + { + if (allbuf[level] == '\r' && allbuf[level + 1] == '\n') + return level + 2; + else + *(linebuf++) = allbuf[level]; + } + return -1; +} + +int is_websocket_hybi_00_request(char *key1, char *key2) +{ + if (strlen(key1) > 0 + && strlen(key2) > 0) + return 1; + else + return 0; +} + +/* +size_t http_recv(struct REQ_INFO *pCli, int sockfd, void *buf, size_t len, int flags) +{ + return recv(sockfd, buf, len, flags); +}*/ + +int iIfInShakeHand; + +int sharkhand_s(int client_socket, char *buffer, int *iIsWebsocket_hybi_00) +{ + + char *is_nvr_auth = NULL; + char *is_HTTP = NULL; + is_nvr_auth = strstr(buffer, "nvr_auth="); + if (is_nvr_auth != NULL) { + is_HTTP = strstr(is_nvr_auth," HTTP"); + if (is_HTTP != NULL) { + if (is_HTTP - is_nvr_auth > 9) { + char auth_basic[256] = { 0 }; + int length_auth = is_HTTP - is_nvr_auth - 9; + memcpy(auth_basic, is_nvr_auth + 9, length_auth); + //printf("\n-------------------auth_basic:%s\n", auth_basic); + memcpy(g_pCli.sNVR_Auth, auth_basic, length_auth); + } + } + } + + char GUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + + //a line data + char linebuf[256] = { 0 }; + + //next line's point num + int level = 0; + + //Sec-WebSocket-Accept + char sec_accept[32] = { 0 }; + + char test_ch[512] = { 0 }; + + //sha1 data + //unsigned char sha1_data[SHA_DIGEST_LENGTH + 1] = { 0 }; + char sha1_data[SHA1_DATA_SIZE + 1] = { 0 }; + + //reponse head buffer + char head[BUFFER_SIZE] = { 0 }; + + char sha1Data[8192 * 13] = { 0 }; + + int check_if_correct_head = 0; + //int count_incorrect = 0; + + char *field; + char sWebsocketKey1[128] = { 0 }; + char sWebsocketKey2[128] = { 0 }; + + do { + memset(linebuf, 0, 256); + level = _readline(buffer, level, linebuf); + //printf("line:%s\n", linebuf); + + if( strncasecmp(linebuf, "Sec-WebSocket-Key1:", 19 ) == 0 ) + { + field = (linebuf +20); + field += strspn( field, " \t"); + memcpy(sWebsocketKey1, (linebuf + 20), strlen(linebuf + 20)); + } + else if (strncasecmp(linebuf, "Sec-WebSocket-Key2:", 19) == 0) + { + field = (linebuf + 20); + field += strspn(field, " \t"); + memcpy(sWebsocketKey2, (linebuf + 20), strlen(linebuf + 20)); + } + else if (strncasecmp(linebuf, "Origin:", 7) == 0) + { + field = (linebuf + 8); + field += strspn(field, " \t"); + memcpy(g_pCli.sOrigin, (linebuf + 8), strlen(linebuf + 8)); + } + else if (strncasecmp(linebuf, "Host:", 5) == 0) + { + field = (linebuf + 6); + field += strspn(field, " \t"); + memcpy(g_pCli.sHost, (linebuf + 6), strlen(linebuf + 6)); + } + //if (strstr(linebuf, "Sec-WebSocket-Key") != NULL) + else if (strncasecmp(linebuf, "Sec-WebSocket-Key:", 18) == 0) + { + strcat(linebuf, GUID); + + memcpy(test_ch, (linebuf + 19), strlen(linebuf + 19)); + + char* p; + p = strstr(test_ch, "C5AB0DC85B11"); + + if (p) { + strcpy(p, "C5AB0DC85B11"); + } + else + { + check_if_correct_head = 0; + break; + } + + //printf("key3:%s\nlen=%d\n", test_ch, strlen(test_ch)); + + sha1_hash(test_ch, sha1_data); + //printf("sha1:%s\n", sha1_data); + + int n = strlen(sha1_data); + + //sha1Data = (char *)malloc(n / 2 + 1); + memset(sha1Data, 0, 8192*13); + + for (int i = 0; i < n; i += 2) + { + sha1Data[i / 2] = htoi_w(sha1_data, i, 2); + //printf("0x%x - ", sha1Data[i / 2]); + } + + //printf("\nbuild sha1Data :%p\n", sha1Data); + + size_t base64_encode_length = 0; + char launchTime[512] = { 0 }; + + base64_encode_a((unsigned char *)sha1Data, strlen(sha1Data), &base64_encode_length, launchTime); + + //printf("\n[sharkhand_s]base64_encode_length:%d\n", base64_encode_length); + //printf("\n[sharkhand_s]launchTime:%s\n", launchTime); + + *(launchTime + base64_encode_length) = '\0'; + memcpy(sec_accept, launchTime, base64_encode_length+1); + + //printf("\n[sharkhand_s]base64:%s\n", sec_accept); + + + + /* write the response */ + sprintf(head, "HTTP/1.1 101 Switching Protocols\r\n" \ + "Upgrade: websocket\r\n" \ + "Connection: Upgrade\r\n" \ + "Sec-WebSocket-Accept: %s\r\n" \ + "\r\n", sec_accept); + + //printf("response\n"); + //printf("%s", head); + + if (send(client_socket, head, strlen(head), 0) < 0) + { + //printf("shakehand send err!\n"); + check_if_correct_head = 0; + } + else { + check_if_correct_head = 1; + } + + //printf("response finish\n"); + + //printf("\nfree launchTime :%p\n", launchTime); + + + //printf("\nfree sha1Data :%p\n", sha1Data); + /* + if (sha1Data != NULL) { + free(sha1Data); + sha1Data = NULL; + }*/ + + /* + if (check_if_correct_head == 1 && count_incorrect<=1) + break; + else { + count_incorrect++; + usSleep(1000); + }*/ + + break; + } + } while ((buffer[level] != '\r' || buffer[level + 1] != '\n') && level != -1); + + if (is_websocket_hybi_00_request(sWebsocketKey1, sWebsocketKey2)) + { + memset(g_pCli.sSec_websocket_key1, 0, sizeof(g_pCli.sSec_websocket_key1)); + memset(g_pCli.sSec_websocket_key2, 0, sizeof(g_pCli.sSec_websocket_key2)); + + g_pCli.iIf_websocket_hybi_00 = 1; + g_pCli.socket = client_socket; + memcpy(g_pCli.sSec_websocket_key1, sWebsocketKey1, strlen(sWebsocketKey1)); + memcpy(g_pCli.sSec_websocket_key2, sWebsocketKey2, strlen(sWebsocketKey2)); + + if (1) + { + int sec_websocket_key3_len = 0; + + char sendBuffer[32] = { 0 }; + + usSleep(3000); + + sec_websocket_key3_len = recv(client_socket, sendBuffer, 24, 0); + + //g_pCli.sSec_websocket_key3 = malloc(32); + memset(g_pCli.sSec_websocket_key3, 0x00, 32);//malloc(32) + + //printf("[%d] >>>>>>>>>>>>>>>>> Key 3 readbuf:[%d] \n", client_socket, sec_websocket_key3_len); + //printf("[%d] >>>>>>>>>>>>>>>>> Key 3:\n %s \n", client_socket, sendBuffer); +#if 1 + if (sec_websocket_key3_len >= 8) + { + //g_pCli.sSec_websocket_key3 = g_pCli.readBuf + g_pCli.header_len; + memset(g_pCli.sSec_websocket_key3, 0x00, 32);//malloc(32) + memcpy(g_pCli.sSec_websocket_key3, sendBuffer, sec_websocket_key3_len); + + int ret_len = send_websocket_hybi_00_boundary_header(); + + /*printf("Sec-WebSocket-Key3:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", + *g_pCli.sSec_websocket_key3, + *(g_pCli.sSec_websocket_key3 + 1), + *(g_pCli.sSec_websocket_key3 + 2), + *(g_pCli.sSec_websocket_key3 + 3), + *(g_pCli.sSec_websocket_key3 + 4), + *(g_pCli.sSec_websocket_key3 + 5), + *(g_pCli.sSec_websocket_key3 + 6), + *(g_pCli.sSec_websocket_key3 + 7));*/ + + if (ret_len < 0) + { + check_if_correct_head = 0; + } + else + { + check_if_correct_head = 1; + + *iIsWebsocket_hybi_00 = 1; + + g_pCli.iIsConnect = 1; + } +#if 0 + g_pCli.send_websocket_boundry = send_websocket_hybi_00_boundary_header; + g_pCli.recv_websocket_frame = recv_websocket_hybi_00_frame; + g_pCli.get_websocket_frame_header = get_ws_hybi_00_header; + g_pCli.send_websocket_frame_header = send_ws_header; + g_pCli.get_websocket_frame_footer = get_ws_hybi_00_footer; + g_pCli.send_websocket_frame_footer = send_ws_header; +#endif + + //check_if_correct_head = 0; + //closesocket(client_socket); + + } + +#endif + } + + } + else + { + g_pCli.iIf_websocket_hybi_00 = 0; + *iIsWebsocket_hybi_00 = 0; + printf("Not websocket hybi 00 request XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \n"); + } + /* + if (g_pCli.sSec_websocket_key3 != NULL) + { + free(g_pCli.sSec_websocket_key3); + g_pCli.sSec_websocket_key3 = NULL; + }*/ + + //printf("\n\n Parse buffer finish \n"); + if (check_if_correct_head == 1) + return 0; + else + return -1; +} + +void packData(char * message,char * data, unsigned long * len) +{ + //char * data = NULL; + + int n; + n = strlen(message); + + //printf("\n-------------n:%d\n", n); + + if (g_pCli.iIf_websocket_hybi_00 == 1) + { + char tempHead[1] = { 0 }; + tempHead[0] = 0x00; + + char tempfooter[2] = { 0 }; + tempfooter[0] = 0xFF; + + //data = (char *)malloc(n + 2); + + //memset(data, 0, (n + 2)); + + memcpy(data, tempHead, sizeof(tempHead)); + memcpy(data + sizeof(tempHead), message, n); + memcpy(data + sizeof(tempHead) + n, tempfooter, sizeof(tempfooter)); + + *len = n + 2; + } + else + { + if (n < 126) + { + //data = (char *)malloc(n + 2); + //printf("\nbuild data: %p\n",data); + //memset(data, 0, n + 2); + data[0] = 0x81; + data[1] = n; + memcpy(data + 2, message, n); + *len = n + 2; + } + else if (n < 0xFFFF) + { + //data = (char *)malloc(n + 4); + //printf("\nbuild data: %p\n", data); + //memset(data, 0, n + 4); + data[0] = 0x81; + data[1] = 126; + data[2] = (n >> 8) & 0xFF; + data[3] = (n & 0xFF); + + memcpy(data + 4, message, n); + *len = n + 4; + } + /*else if(n < 0xFFFFFFFF )//&& n < BUFSIZE_V3 + { + data = (char *)malloc(n + 10); + //printf("\nbuild data: %p\n", data); + memset(data, 0, n + 10); + data[0] = 0x81; + data[1] = 127; + data[2] = (n >> 56) & 0xFF; + data[3] = (n >> 48) & 0xFF; + data[4] = (n >> 40) & 0xFF; + data[5] = (n >> 32) & 0xFF; + data[6] = (n >> 24) & 0xFF; + data[7] = (n >> 16) & 0xFF; + data[8] = (n >> 8) & 0xFF; + data[9] = (n & 0xFF); + + memcpy(data + 10, message, n); + *len = n + 10; + }*/ + else + { + *len = 0; + } + } + + //return data; +} + +int websocket_response(int connfd, char * message) +{ + char data[8192 * 59] = { 0 }; + unsigned long n = 0; + if (!connfd) + { + return -1; + } + + if (!message) + { + return -1; + } + + //printf("[%d]>>>>>>>>>>>> send data:\n %s\n", connfd, message); + //char *test_msg = "ABC123"; + + +#if 1 + packData(message, data, &n); + + if (/*!data || */n <= 0) + { + /*if (data != NULL) { + //printf("\nfree data: %p\n", data); + free(data); + data = NULL; + }*/ + printf("data is empty!\n"); + return -1; + } +#endif + +#if 0 + //char testsstr[] = ""; + + testh[0] = 0x00; + testf[0] = 0xFF; + + n = strlen(message); + + //data = (char *)malloc(n + 2); + memset(data, 0, sizeof(data)); + + memcpy(data, testh, sizeof(testh)); + //printf("[%d]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> send data 0 : %s\n\n", connfd, message); + //printf("[%d]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> send data size: %d\n", connfd, testlen); + memcpy(data + sizeof(testh), message, n); + //printf("[%d]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> send data 1 : %X\n", connfd, data); + memcpy(data + sizeof(testh) + n, testf, sizeof(testf)); + + n = n+2; +#endif + + //printf("[%d]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> send data size: %d\n", connfd, n); + +#if 1 + //int iSendResult = 0; + + //iSendResult = send(connfd, data, n, 0); + //printf("[%d] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ws send len: %d \n\n", connfd, n); + //usSleep(200000); + int ret_s = 0; + ret_s = send(connfd, data, n, 0); + + + //printf("[%d] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ret_s: %d \n", connfd, ret_s); + + if (ret_s == -1) + //if (send(connfd, sendttst, testlen, 0) == -1) + { + /*if (data != NULL) { + //printf("\nfree data: %p\n", data); + free(data); + data = NULL; + //free(sendttst); + }*/ + + //int last_err = WSAGetLastError(); + + //printf("[%d]websocket send A err !: %d\n", connfd, last_err); + printf("[%d]websocket send A err !\n", connfd); + + g_pCli.iIsConnect = 0; + return -1; + } + + //printf("[%d] >>>>>>>>>>>>>>>>>>> ws send len: %d \n\n", connfd, n); +#endif +#if 0 + //send_len = block_to_send(pCli->socket, (unsigned char *)tmpString, strlen(tmpString), 1000000, 4096, NULL); + //int send_len = block_to_send(connfd, (unsigned char *)data, n, 1000000, 4096, NULL); + int send_len = block_to_send(connfd, (unsigned char *)message, strlen(message), 300000, 0, NULL); + if (send_len < 0) + { + printf("ggggggg %s fail\r\n", __func__); + + if (data != NULL) { + //printf("\nfree data: %p\n", data); + free(data); + data = NULL; + //free(sendttst); + } + + return -1; + } + else + { + printf("ggggggg send len: %d \n", send_len); + } +#endif + /*if (data != NULL) { + //printf("\nfree data: %p\n", data); + free(data); + data = NULL; + //free(sendttst); + }*/ + + //printf("[%d] >>>>>>>>>>>>>>>>>>>>>>>>>>> finish send \n", connfd); + + //write(connfd, data, n); + return 1; +} \ No newline at end of file diff --git a/src/websocket.h b/src/websocket.h new file mode 100644 index 0000000..9c77d17 --- /dev/null +++ b/src/websocket.h @@ -0,0 +1,53 @@ +#pragma once +#ifndef WEBSOCKET_H +#define WEBSOCKET_H +#include "define_inc.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <ctype.h> +#include "base64.h" +#include "sha1.h" +#include "md5.h" +#include "md5_f.h" +#include "block_to_send.h" + +//#define LINE_MAX 256 +#define REQUEST_LEN_MAX 1024 +#define DEFEULT_SERVER_PORT 8000 +#define WEB_SOCKET_KEY_LEN_MAX 256 +#define RESPONSE_HEADER_LEN_MAX 1024 +#define BUFFER_SIZE 1024 + + + +#define WEBSOCKET_SEND_DELAY_A 0 +#define WEBSOCKET_SEND_DELAY_B 6 + + +typedef struct { + char sSec_websocket_key1[128]; + char sSec_websocket_key2[128]; + //char sSec_websocket_key3[128]; + //char *sSec_websocket_key3; + char sSec_websocket_key3[32]; + //char sSec_websocket_key3_str[128]; + + //char *sSec_websocket_key3; + char sOrigin[128]; + char sHost[128]; + char sPath[128]; + char sNVR_Auth[256]; + int socket; + int header_len; + char readBuf[8196]; + + int iIf_websocket_hybi_00; + + int iIsConnect; +} REQ_INFO; + + + +#endif \ No newline at end of file diff --git a/src/websocket_client.c b/src/websocket_client.c new file mode 100644 index 0000000..b939bd2 --- /dev/null +++ b/src/websocket_client.c @@ -0,0 +1,1003 @@ + +#include "websocket_client.h" + +#include "face_parser.h" + +/* +//== Radar 參數 ================================================== +static std::deque<FaceFrameData> g_FaceFrameQueue; +FaceFrameData gstNewFaceFrame; +int g_iGetDataSize = 0; + +void FaceQueuePush(FaceFrameData q_info) +{ + g_FaceFrameQueue.push_back(q_info); +} + +FaceFrameData FaceQueueFront() +{ + return g_FaceFrameQueue.front(); +} + +void FaceQueuePop() +{ + + //FaceFrameData q_info = FaceQueueFront(); + + g_FaceFrameQueue.pop_front(); + g_FaceFrameQueue.shrink_to_fit(); +} +*/ + +//================================================== 加密方法BASE64 ================================================== + + + +/******************************************************************************* + * 名稱: client_base64_encode + * 功能: ascii編碼爲base64格式 + * 形參: bindata : ascii字符串輸入 + * base64 : base64字符串輸出 + * binlength : bindata的長度 + * 返回: base64字符串長度 + * 說明: 無 + ******************************************************************************/ +int client_base64_encode( const unsigned char *bindata, char *base64, int binlength) +{ + int i, j; + unsigned char current; + for ( i = 0, j = 0 ; i < binlength ; i += 3 ) + { + current = (bindata[i] >> 2) ; + current &= (unsigned char)0x3F; + base64[j++] = base64char[(int)current]; + current = ( (unsigned char)(bindata[i] << 4 ) ) & ( (unsigned char)0x30 ) ; + if ( i + 1 >= binlength ) + { + base64[j++] = base64char[(int)current]; + base64[j++] = '='; + base64[j++] = '='; + break; + } + current |= ( (unsigned char)(bindata[i+1] >> 4) ) & ( (unsigned char) 0x0F ); + base64[j++] = base64char[(int)current]; + current = ( (unsigned char)(bindata[i+1] << 2) ) & ( (unsigned char)0x3C ) ; + if ( i + 2 >= binlength ) + { + base64[j++] = base64char[(int)current]; + base64[j++] = '='; + break; + } + current |= ( (unsigned char)(bindata[i+2] >> 6) ) & ( (unsigned char) 0x03 ); + base64[j++] = base64char[(int)current]; + current = ( (unsigned char)bindata[i+2] ) & ( (unsigned char)0x3F ) ; + base64[j++] = base64char[(int)current]; + } + base64[j] = '\0'; + return j; +} +/******************************************************************************* + * 名稱: client_base64_decode + * 功能: base64格式解碼爲ascii + * 形參: base64 : base64字符串輸入 + * bindata : ascii字符串輸出 + * 返回: 解碼出來的ascii字符串長度 + * 說明: 無 + ******************************************************************************/ +int client_base64_decode( const char *base64, unsigned char *bindata) +{ + int i, j; + unsigned char k; + unsigned char temp[4]; + for ( i = 0, j = 0; base64[i] != '\0' ; i += 4 ) + { + memset( temp, 0xFF, sizeof(temp) ); + for ( k = 0 ; k < 64 ; k ++ ) + { + if ( base64char[k] == base64[i] ) + temp[0]= k; + } + for ( k = 0 ; k < 64 ; k ++ ) + { + if ( base64char[k] == base64[i+1] ) + temp[1]= k; + } + for ( k = 0 ; k < 64 ; k ++ ) + { + if ( base64char[k] == base64[i+2] ) + temp[2]= k; + } + for ( k = 0 ; k < 64 ; k ++ ) + { + if ( base64char[k] == base64[i+3] ) + temp[3]= k; + } + bindata[j++] = ((unsigned char)(((unsigned char)(temp[0] << 2))&0xFC)) | \ + ((unsigned char)((unsigned char)(temp[1]>>4)&0x03)); + if ( base64[i+2] == '=' ) + break; + bindata[j++] = ((unsigned char)(((unsigned char)(temp[1] << 4))&0xF0)) | \ + ((unsigned char)((unsigned char)(temp[2]>>2)&0x0F)); + if ( base64[i+3] == '=' ) + break; + bindata[j++] = ((unsigned char)(((unsigned char)(temp[2] << 6))&0xF0)) | \ + ((unsigned char)(temp[3]&0x3F)); + } + return j; +} + + +//============================================================================================================== +//================================================== websocket ================================================== +//============================================================================================================== + + +/* +// websocket根據data[0]判別數據包類型 +typedef enum{ + WCT_MINDATA = -20, // 0x0:標識一箇中間數據包 + WCT_TXTDATA = -19, // 0x1:標識一個text類型數據包 + WCT_BINDATA = -18, // 0x2:標識一個binary類型數據包 + WCT_DISCONN = -17, // 0x8:標識一個斷開連接類型數據包 + WCT_PING = -16, // 0x8:標識一個斷開連接類型數據包 + WCT_PONG = -15, // 0xA:表示一個pong類型數據包 + WCT_ERR = -1, + WCT_NULL = 0 +}Websocket_CommunicationType;*/ + +/******************************************************************************* + * 名稱: webSocket_getRandomString + * 功能: 生成隨機字符串 + * 形參: *buf:隨機字符串存儲到 + * len : 生成隨機字符串長度 + * 返回: 無 + * 說明: 無 + ******************************************************************************/ +void webSocket_getRandomString(unsigned char *buf, unsigned int len) +{ + unsigned int i; + unsigned char temp; + srand((int)time(0)); + for(i = 0; i < len; i++) + { + temp = (unsigned char)(rand()%256); + if(temp == 0) // 隨機數不要0, 0 會干擾對字符串長度的判斷 + temp = 128; + buf[i] = temp; + } +} +/******************************************************************************* + * 名稱: webSocket_buildShakeKey + * 功能: client端使用隨機數構建握手用的key + * 形參: *key:隨機生成的握手key + * 返回: key的長度 + * 說明: 無 + ******************************************************************************/ +int webSocket_buildShakeKey(unsigned char *key) +{ + unsigned char tempKey[WEBSOCKET_SHAKE_KEY_LEN] = {0}; + webSocket_getRandomString(tempKey, WEBSOCKET_SHAKE_KEY_LEN); + return client_base64_encode((const unsigned char *)tempKey, (char *)key, WEBSOCKET_SHAKE_KEY_LEN); +} +/******************************************************************************* + * 名稱: webSocket_buildRespondShakeKey + * 功能: server端在接收client端的key後,構建迴應用的key + * 形參: *acceptKey:來自客戶端的key字符串 + * acceptKeyLen : 長度 + * *respondKey : 在 acceptKey 之後加上 GUID, 再sha1哈希, 再轉成base64得到 respondKey + * 返回: respondKey的長度(肯定比acceptKey要長) + * 說明: 無 + ******************************************************************************/ +int webSocket_buildRespondShakeKey(unsigned char *acceptKey, unsigned int acceptKeyLen, unsigned char *respondKey) +{ + char *clientKey; + char sha1DataTemp[128] = { 0 }; + char sha1Data[128] = { 0 }; + + int i, n; + const char GUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + unsigned int GUIDLEN; + + if(acceptKey == NULL) + return 0; + GUIDLEN = sizeof(GUID); + clientKey = (char *)calloc(1, sizeof(char)*(acceptKeyLen + GUIDLEN + 10)); + memset(clientKey, 0, (acceptKeyLen + GUIDLEN + 10)); + // + memcpy(clientKey, acceptKey, acceptKeyLen); + memcpy(&clientKey[acceptKeyLen], GUID, GUIDLEN); + clientKey[acceptKeyLen + GUIDLEN] = '\0'; + // + sha1_hash(clientKey, sha1DataTemp); + n = strlen(sha1DataTemp); + //sha1Data = (char *)calloc(1, n / 2 + 1); + //memset(sha1Data, 0, n / 2 + 1); + // + for(i = 0; i < n; i += 2) + sha1Data[ i / 2 ] = htoi_w(sha1DataTemp, i, 2); + n = client_base64_encode((const unsigned char *)sha1Data, (char *)respondKey, (n / 2)); + // + + free(clientKey); + return n; +} +/******************************************************************************* + * 名稱: webSocket_matchShakeKey + * 功能: client端收到來自服務器迴應的key後進行匹配,以驗證握手成功 + * 形參: *myKey:client端請求握手時發給服務器的key + * myKeyLen : 長度 + * *acceptKey : 服務器迴應的key + * acceptKeyLen : 長度 + * 返回: 0 成功 -1 失敗 + * 說明: 無 + ******************************************************************************/ +int webSocket_matchShakeKey(unsigned char *myKey, unsigned int myKeyLen, unsigned char *acceptKey, unsigned int acceptKeyLen) +{ + int retLen; + unsigned char tempKey[256] = {0}; + // + retLen = webSocket_buildRespondShakeKey(myKey, myKeyLen, tempKey); + //printf("webSocket_matchShakeKey :\r\n%d : %s\r\n%d : %s\r\n", acceptKeyLen, acceptKey, retLen, tempKey); + // + if(retLen != acceptKeyLen) + { + printf("webSocket_matchShakeKey : len err\r\n%s\r\n%s\r\n%s\r\n", myKey, tempKey, acceptKey); + return -1; + } + else if(strcmp((const char *)tempKey, (const char *)acceptKey) != 0) + { + printf("webSocket_matchShakeKey : str err\r\n%s\r\n%s\r\n", tempKey, acceptKey); + return -1; + } + return 0; +} +/******************************************************************************* + * 名稱: webSocket_buildHttpHead + * 功能: 構建client端連接服務器時的http協議頭, 注意websocket是GET形式的 + * 形參: *ip:要連接的服務器ip字符串 + * port : 服務器端口 + * *interfacePath : 要連接的端口地址 + * *shakeKey : 握手key, 可以由任意的16位字符串打包成base64後得到 + * *package : 存儲最後打包好的內容 + * 返回: 無 + * 說明: 無 + ******************************************************************************/ +void webSocket_buildHttpHead(char *ip, int port, char *interfacePath, unsigned char *shakeKey, char *package) +{ + const char httpDemo[] = "GET %s HTTP/1.1\r\n" + "Connection: Upgrade\r\n" + "Host: %s:%d\r\n" + "Sec-WebSocket-Key: %s\r\n" + "Sec-WebSocket-Version: 13\r\n" + "Upgrade: websocket\r\n\r\n"; + sprintf(package, httpDemo, interfacePath, ip, port, shakeKey); + //printf("\n-------shakeKey:%s\n", shakeKey); +} +/******************************************************************************* + * 名稱: webSocket_buildHttpRespond + * 功能: 構建server端回覆client連接請求的http協議 + * 形參: *acceptKey:來自client的握手key + * acceptKeyLen : 長度 + * *package : 存儲 + * 返回: 無 + * 說明: 無 + ******************************************************************************/ +void webSocket_buildHttpRespond(unsigned char *acceptKey, unsigned int acceptKeyLen, char *package) +{ + const char httpDemo[] = "HTTP/1.1 101 Switching Protocols\r\n" + "Upgrade: websocket\r\n" + "Server: Microsoft-HTTPAPI/2.0\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Accept: %s\r\n" + "%s\r\n\r\n"; // 時間打包待續 // 格式如 "Date: Tue, 20 Jun 2017 08:50:41 CST\r\n" + time_t now; + struct tm *tm_now; + char timeStr[256] = {0}; + unsigned char respondShakeKey[256] = {0}; + // 構建迴應的握手key + webSocket_buildRespondShakeKey(acceptKey, acceptKeyLen, respondShakeKey); + // 構建迴應時間字符串 + time(&now); + tm_now = localtime(&now); + strftime(timeStr, sizeof(timeStr), "Date: %a, %d %b %Y %T %Z", tm_now); + // 組成回覆信息 + sprintf(package, httpDemo, respondShakeKey, timeStr); +} +/******************************************************************************* + * 名稱: webSocket_enPackage + * 功能: websocket數據收發階段的數據打包, 通常client發server的數據都要isMask(掩碼)處理, 反之server到client卻不用 + * 形參: *data:準備發出的數據 + * dataLen : 長度 + * *package : 打包後存儲地址 + * packageMaxLen : 存儲地址可用長度 + * isMask : 是否使用掩碼 1要 0 不要 + * type : 數據類型, 由打包後第一個字節決定, 這裏默認是數據傳輸, 即0x81 + * 返回: 打包後的長度(會比原數據長2~16個字節不等) <=0 打包失敗 + * 說明: 無 + ******************************************************************************/ +int webSocket_enPackage(unsigned char *data, unsigned int dataLen, unsigned char *package, unsigned int packageMaxLen, bool isMask, Websocket_CommunicationType type) +{ + unsigned char maskKey[4] = {0}; // 掩碼 + unsigned char temp1, temp2; + int count; + unsigned int i, len = 0; + + if(packageMaxLen < 2) + return -1; + + if(type == WCT_MINDATA) + *package++ = 0x00; + else if(type == WCT_TXTDATA) + *package++ = 0x81; + else if(type == WCT_BINDATA) + *package++ = 0x82; + else if(type == WCT_DISCONN) + *package++ = 0x88; + else if(type == WCT_PING) + *package++ = 0x89; + else if(type == WCT_PONG) + *package++ = 0x8A; + else + return -1; + // + if(isMask) + *package = 0x80; + len += 1; + // + if(dataLen < 126) + { + *package++ |= (dataLen&0x7F); + len += 1; + } + else if(dataLen < 65536) + { + if(packageMaxLen < 4) + return -1; + *package++ |= 0x7E; + *package++ = (char)((dataLen >> 8) & 0xFF); + *package++ = (unsigned char)((dataLen >> 0) & 0xFF); + len += 3; + } + else if(dataLen < 0xFFFFFFFF) + { + if(packageMaxLen < 10) + return -1; + *package++ |= 0x7F; + *package++ = 0; //(char)((dataLen >> 56) & 0xFF); // 數據長度變量是 unsigned int dataLen, 暫時沒有那麼多數據 + *package++ = 0; //(char)((dataLen >> 48) & 0xFF); + *package++ = 0; //(char)((dataLen >> 40) & 0xFF); + *package++ = 0; //(char)((dataLen >> 32) & 0xFF); + *package++ = (char)((dataLen >> 24) & 0xFF); // 到這裏就夠傳4GB數據了 + *package++ = (char)((dataLen >> 16) & 0xFF); + *package++ = (char)((dataLen >> 8) & 0xFF); + *package++ = (char)((dataLen >> 0) & 0xFF); + len += 9; + } + // + if(isMask) // 數據使用掩碼時, 使用異或解碼, maskKey[4]依次和數據異或運算, 邏輯如下 + { + if(packageMaxLen < len + dataLen + 4) + return -1; + webSocket_getRandomString(maskKey, sizeof(maskKey)); // 隨機生成掩碼 + *package++ = maskKey[0]; + *package++ = maskKey[1]; + *package++ = maskKey[2]; + *package++ = maskKey[3]; + len += 4; + for(i = 0, count = 0; i < dataLen; i++) + { + temp1 = maskKey[count]; + temp2 = data[i]; + *package++ = (char)(((~temp1)&temp2) | (temp1&(~temp2))); // 異或運算後得到數據 + count += 1; + if(count >= sizeof(maskKey)) // maskKey[4]循環使用 + count = 0; + } + len += i; + *package = '\0'; + } + else // 數據沒使用掩碼, 直接複製數據段 + { + if(packageMaxLen < len + dataLen) + return -1; + memcpy(package, data, dataLen); + package[dataLen] = '\0'; + len += dataLen; + } + // + return len; +} +/******************************************************************************* + * 名稱: webSocket_dePackage + * 功能: websocket數據收發階段的數據解包, 通常client發server的數據都要isMask(掩碼)處理, 反之server到client卻不用 + * 形參: *data:解包的數據 + * dataLen : 長度 + * *package : 解包後存儲地址 + * packageMaxLen : 存儲地址可用長度 + * *packageLen : 解包所得長度 + * 返回: 解包識別的數據類型 如 : txt數據, bin數據, ping, pong等 + * 說明: 無 + ******************************************************************************/ +int webSocket_dePackage(unsigned char *data, unsigned int dataLen, unsigned char *package, unsigned int packageMaxLen, unsigned int *packageLen) +{ + unsigned char maskKey[4] = {0}; // 掩碼 + unsigned char temp1, temp2; + char Mask = 0, type; + int count, ret; + unsigned int i, len = 0, dataStart = 2; + if(dataLen < 2) + return -1; + + type = data[0]&0x0F; + + if((data[0]&0x80) == 0x80) + { + if(type == 0x01) + ret = WCT_TXTDATA; + else if(type == 0x02) + ret = WCT_BINDATA; + else if(type == 0x08) + ret = WCT_DISCONN; + else if(type == 0x09) + ret = WCT_PING; + else if(type == 0x0A) + ret = WCT_PONG; + else + return WCT_ERR; + } + else if(type == 0x00) + ret = WCT_MINDATA; + else + return WCT_ERR; + // + if((data[1] & 0x80) == 0x80) + { + Mask = 1; + count = 4; + } + else + { + Mask = 0; + count = 0; + } + // + len = data[1] & 0x7F; + // + if(len == 126) + { + if(dataLen < 4) + return WCT_ERR; + len = data[2]; + len = (len << 8) + data[3]; + if(dataLen < len + 4 + count) + return WCT_ERR; + if(Mask) + { + maskKey[0] = data[4]; + maskKey[1] = data[5]; + maskKey[2] = data[6]; + maskKey[3] = data[7]; + dataStart = 8; + } + else + dataStart = 4; + } + else if(len == 127) + { + if(dataLen < 10) + return WCT_ERR; + if(data[2] != 0 || data[3] != 0 || data[4] != 0 || data[5] != 0) // 使用8個字節存儲長度時, 前4位必須爲0, 裝不下那麼多數據... + return WCT_ERR; + len = data[6]; + len = (len << 8) + data[7]; + len = (len << 8) + data[8]; + len = (len << 8) + data[9]; + if(dataLen < len + 10 + count) + return WCT_ERR; + if(Mask) + { + maskKey[0] = data[10]; + maskKey[1] = data[11]; + maskKey[2] = data[12]; + maskKey[3] = data[13]; + dataStart = 14; + } + else + dataStart = 10; + } + else + { + if(dataLen < len + 2 + count) + return WCT_ERR; + if(Mask) + { + maskKey[0] = data[2]; + maskKey[1] = data[3]; + maskKey[2] = data[4]; + maskKey[3] = data[5]; + dataStart = 6; + } + else + dataStart = 2; + } + // + if(dataLen < len + dataStart) + return WCT_ERR; + // + if(packageMaxLen < len + 1) + return WCT_ERR; + // + if(Mask) // 解包數據使用掩碼時, 使用異或解碼, maskKey[4]依次和數據異或運算, 邏輯如下 + { + //printf("depackage : len/%d\r\n", len); + for(i = 0, count = 0; i < len; i++) + { + temp1 = maskKey[count]; + temp2 = data[i + dataStart]; + *package++ = (char)(((~temp1)&temp2) | (temp1&(~temp2))); // 異或運算後得到數據 + count += 1; + if(count >= sizeof(maskKey)) // maskKey[4]循環使用 + count = 0; + //printf("%.2X|%.2X|%.2X, ", temp1, temp2, *(package-1)); + } + *package = '\0'; + } + else // 解包數據沒使用掩碼, 直接複製數據段 + { + memcpy(package, &data[dataStart], len); + package[len] = '\0'; + } + *packageLen = len; + // + return ret; +} +/******************************************************************************* + * 名稱: webSocket_clientLinkToServer + * 功能: 向websocket服務器發送http(攜帶握手key), 以和服務器構建連接, 非阻塞模式 + * 形參: *ip:服務器ip + * port : 服務器端口 + * *interface_path : 接口地址 + * 返回: >0 返回連接句柄 <= 0 連接失敗或超時, 所花費的時間 ms + * 說明: 無 + ******************************************************************************/ +// Joy 2023.10.06 fix bug version +int g_try_websocket_face = 0; +void webSocket_clientLinkToServer(char *ip, int port, char *interface_path) +{ + clock_t current_time; + double current_time_ms; + current_time = clock(); + current_time_ms = (double)(current_time) / CLOCKS_PER_SEC; + + int ret, fd; + + unsigned char loginBuf[512] = {0}, recBuf[BUFSIZE * 59] = {0},/* recvbuffer[BUFSIZE * 60] = { 0 },*/ shakeKey[128] = {0}, /*shakeKey_temp[128] = { 0 },*/ *p; + unsigned char recBuf_copy[BUFSIZE * 60] = {0}; + + // STEP1 : 設置連接資訊 (zhd 服務器端網絡地址結構體) + struct sockaddr_in report_addr; + bzero(&report_addr, sizeof(report_addr)); + report_addr.sin_family = AF_INET; // 設置爲IP通信 + report_addr.sin_addr.s_addr = inet_addr(ip); // 服務器IP地址 + report_addr.sin_port = htons(port); // 服務器端口號 + + fd = socket(AF_INET, SOCK_STREAM, 0); + + // STEP2 : 建立 Socket + if(fd >= 0) + { + ///要關閉reuse + int reuse = 0; + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); + + struct timeval timeout; + timeout.tv_sec = 10; + timeout.tv_usec = 0; + + setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); + setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); + + int tcpnodelay = 1; + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); + + int qlen = 5; + setsockopt(fd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); + + // 非阻塞 + ret = fcntl(fd , F_GETFL , 0); + fcntl(fd , F_SETFL , ret | O_NONBLOCK); + + // STEP3 : 建立連接 + int ret_connect = -1; + //printf("\n-------KKKKKKKKK: 1\n"); + for (int try_times = 0; try_times < REPORT_LOGIN_CONNECT_TIMEOUT; try_times++) { + ret_connect = connect(fd, (struct sockaddr *)&report_addr, sizeof(struct sockaddr)); + if (ret_connect != -1) { + + break; + } + else { + g_try_websocket_face++; + if (g_try_websocket_face >= 5) { + g_try_websocket_face = 5; + } + printf("unconnect to websocket...\r\n"); + } + delayms(1000); + } + + //printf("\n-------KKKKKKKKK: 2\n"); + if (ret_connect != -1) { + //printf("\n-------KKKKKKKKK: 3\n"); + // 發送 http 協議頭 + memset(shakeKey, 0, sizeof(shakeKey)); + webSocket_buildShakeKey(shakeKey); // 創建握手key + + //printf("\n-------shakeKey:%s\n", shakeKey); + + //webSocket_buildRespondShakeKey(shakeKey, strlen(shakeKey), shakeKey_temp); + //printf("\n-------shakeKey_temp:%s\n", shakeKey_temp); + + memset(loginBuf, 0, sizeof(loginBuf)); // 創建協議包 + webSocket_buildHttpHead(ip, port, interface_path, shakeKey, (char *)loginBuf); + // STEP4 : 發出協議包 + send(fd, loginBuf, strlen((const char*)loginBuf), MSG_NOSIGNAL); + + // BUG4: 修正 while(1) 改為 while(條件式檢查) + int try_times = 0; + + int nbytes = 0; + int header_len = 0; + //int nTotalBytes = 0; + int nbytes_sec = 0; + //printf("\nTTTTTTTTTTTTTTTT\n"); + while (bHttpServerThreadStart && unlockingKeyInnoFR_success && try_times < REPORT_LOGIN_RESPOND_TIMEOUT) + { + nbytes = recv(fd, recBuf, sizeof(recBuf), 0);//MSG_NOSIGNAL + //printf("\n---------try_times:%d,nbytes:%d \n", try_times, nbytes); + //if (nbytes >= 250) { + //printf("\n------------recBuf:%s\n", recBuf); + //} + + // recBuf first 4 byte is 827e20b1 not the data + if (nbytes > 0) { + + header_len = nbytes; + + //printf("\nTTTTTTTTTTTTTTTT 7\n"); + nbytes = header_len; + + //printf("\n----------nbytes:%d\n", nbytes); + + //printf("\nTTTTTTTTTTTTTTTT 7----1\n"); + // 返回的是 http 迴應信息 + if (strncmp((const char *)recBuf, (const char *)"HTTP", strlen((const char *)"HTTP")) == 0) + { + // 檢查握手信號 + if ((p = (unsigned char *)strstr((const char *)recBuf, (const char *)"sec-websocket-accept: ")) != NULL) + { + p += strlen((const char *)"sec-websocket-accept: "); + + char *p_1 = strstr(recBuf, "sec-websocket-accept: "); + int strlen_p = 0; + char temp_p[128] = { 0 }; + if (p_1) { + char *p_2 = strstr(p_1, "\r\ndate"); + if (p_2) { + strlen_p = p_2 - p_1 - 22; + if (strlen_p >= 1) { + memcpy(temp_p, p_1 + 22, strlen_p); + temp_p[strlen_p] = '\0'; + } + } + } + + // 握手成功, 發送登錄數據包 + //printf("\n------------shakeKey #2:%s\n", shakeKey); + //printf("\n------------temp_p:%s\n", temp_p); + + //printf("\n-------KKKKKKKKK: 4\n"); + if (strlen_p >= 1 && webSocket_matchShakeKey(shakeKey, strlen((const char *)shakeKey), temp_p, strlen_p) == 0)//strlen((const char *)p) + { + try_times = 0; + char *ptr_1 = strstr(recBuf, "{\"timestamp\":"); + if(ptr_1) + { + g_try_websocket_face = 0; + char *ptr_2 = strstr(ptr_1, "\"client_id\":\"38-lilin\"}"); + if (ptr_2) { + int strlen_ptr = ptr_2 - ptr_1 + 23; + if (strlen_ptr >= 1) { + face_data_get(ptr_1, strlen_ptr); + } + } + } + //printf("\nTTTTTTTTTTTTTTTT 7----2\n"); + usSleep(100000); + } + else // 握手信號不對, 重發協議包 + { + + delayms(1000); //1ms + try_times++; + //printf("\nTTTTTTTTTTTTTTTT 7----3\n"); + send(fd, loginBuf, strlen((const char*)loginBuf), MSG_NOSIGNAL); // 重發協議包 + + } + } + else + { + delayms(1000); //1ms + try_times++; + //printf("\nTTTTTTTTTTTTTTTT 7----4\n"); + send(fd, loginBuf, strlen((const char*)loginBuf), MSG_NOSIGNAL); // 重發協議包 + } + } + else if (strstr(recBuf, "{\"timestamp\":")) + { + //printf("\n-------KKKKKKKKK: 5\n"); + try_times = 0; + char *ptr_1 = strstr(recBuf, "{\"timestamp\":"); + if (ptr_1) + { + g_try_websocket_face = 0; + char *ptr_2 = strstr(ptr_1, "\"client_id\":\"38-lilin\"}"); + if (ptr_2) { + int strlen_ptr = ptr_2 - ptr_1 + 23; + if (strlen_ptr >= 1) { + face_data_get(ptr_1, strlen_ptr); + } + } + } + //printf("\nTTTTTTTTTTTTTTTT 7----5\n"); + usSleep(100000); + } + else { + ///畫面沒有人臉 + try_times = 0; + g_try_websocket_face = 0; + face_data_get("{\"timestamp\":{}}", 16); + usSleep(100000); + } + } + else { + //沒有收到封包 + //printf("\nTTTTTTTTTTTTTTTT 7----6\n"); + //delayms(250); //250ms,秒數如果太小會造成記憶體溢位,有試過200ms以下不能運作 + try_times++; + usSleep(100000); + } + + memset(recBuf, 0, sizeof(recBuf)); + //memset(recvbuffer, 0, sizeof(recvbuffer)); + nbytes = 0; + header_len = 0; + //nTotalBytes = 0; + nbytes_sec = 0; + } + } + else + { + printf("webSocket_login : %s:%d cannot connect !\n", ip, port); + sprintf(loginBuf, "webSocket_login : %s:%d cannot connect !", ip, port); + } + } + else if (fd < 0)// socket 建立失敗 + { + printf("webSocket_login : cannot create socket\r\n"); + // BUG5: 修正 Single Entry, Single Exit + } + + if (fd) + close(fd); +} + +/******************************************************************************* + * 名稱: webSocket_serverLinkToClient + * 功能: 服務器回覆客戶端的連接請求, 以建立websocket連接 + * 形參: fd:連接句柄 + * *recvBuf : 接收到來自客戶端的數據(內含http連接請求) + * bufLen : + * 返回: =0 建立websocket連接成功 <0 建立websocket連接失敗 + * 說明: 無 + ******************************************************************************/ +int webSocket_serverLinkToClient(int fd, char *recvBuf, unsigned int bufLen) +{ + char *p; + int ret; + char recvShakeKey[512], respondPackage[1024]; + + if((p = strstr(recvBuf, "Sec-WebSocket-Key: ")) == NULL) + return -1; + p += strlen("Sec-WebSocket-Key: "); + // + memset(recvShakeKey, 0, sizeof(recvShakeKey)); + sscanf(p, "%s", recvShakeKey); // 取得握手key + ret = strlen(recvShakeKey); + if(ret < 1) + return -1; + // + memset(respondPackage, 0, sizeof(respondPackage)); + webSocket_buildHttpRespond(recvShakeKey, ret, respondPackage); + // + return send(fd, respondPackage, strlen(respondPackage), MSG_NOSIGNAL); +} +/******************************************************************************* + * 名稱: webSocket_send + * 功能: websocket數據基本打包和發送 + * 形參: fd:連接句柄 + * *data : 數據 + * dataLen : 長度 + * mod : 數據是否使用掩碼, 客戶端到服務器必須使用掩碼模式 + * type : 數據要要以什麼識別頭類型發送(txt, bin, ping, pong ...) + * 返回: 調用send的返回 + * 說明: 無 + ******************************************************************************/ +int webSocket_send(int fd, unsigned char *data, unsigned int dataLen, bool mod, Websocket_CommunicationType type) +{ + unsigned char *webSocketPackage; + unsigned int retLen, ret; + //unsigned int i; + + //printf("webSocket_send : %d\r\n", dataLen); + //---------- websocket數據打包 ---------- + webSocketPackage = (unsigned char *)calloc(1, sizeof(char)*(dataLen + 128)); memset(webSocketPackage, 0, (dataLen + 128)); + retLen = webSocket_enPackage(data, dataLen, webSocketPackage, (dataLen + 128), mod, type); + /* + printf("webSocket_send : %d\r\n" , retLen); + for(i = 0; i < retLen; i ++) printf("%.2X ", webSocketPackage[i]); + printf("\r\n");*/ + ret = send(fd, webSocketPackage, retLen, MSG_NOSIGNAL); + free(webSocketPackage); + return ret; +} +/******************************************************************************* + * 名稱: webSocket_recv + * 功能: websocket數據接收和基本解包 + * 形參: fd:連接句柄 + * *data : 數據接收地址 + * dataMaxLen : 接收區可用最大長度 + * 返回: <= 0 沒有收到有效數據 > 0 成功接收並解包數據 + * 說明: 無 + ******************************************************************************/ +int webSocket_recv(int fd, unsigned char *data, unsigned int dataMaxLen) +{ + unsigned char *webSocketPackage, *recvBuf; + int ret, ret2 = 0; + unsigned int retLen = 0; + //int i; + + recvBuf = (unsigned char *)calloc(1, sizeof(char)*dataMaxLen); memset(recvBuf, 0, dataMaxLen); + ret = recv(fd, recvBuf, dataMaxLen, MSG_NOSIGNAL); + if(ret > 0) + { + //------------------------------------------------------------------- 和客戶端的連接操作 + if(strncmp(recvBuf, "GET", 3) == 0) + { + ret2 = webSocket_serverLinkToClient(fd, recvBuf, ret); + free(recvBuf); + if(ret2 < 0) + { + memset(data, 0, dataMaxLen); + strcpy(data, "connect false !\r\n"); + return strlen("connect false !\r\n"); + } + memset(data, 0, dataMaxLen); + strcpy(data, "connect ...\r\n"); + return strlen("connect ...\r\n"); + } + + //------------------------------------------------------------------- 正常數據交換 + + //printf("webSocket_recv : %d\r\n", ret); + //---------- websocket數據打包 ---------- + webSocketPackage = (unsigned char *)calloc(1, sizeof(char)*(ret + 128)); memset(webSocketPackage, 0, (ret + 128)); + ret2 = webSocket_dePackage(recvBuf, ret, webSocketPackage, (ret + 128), &retLen); + if(ret2 == WCT_PING && retLen > 0) // 解析爲ping包, 自動回pong + { + webSocket_send(fd, webSocketPackage, retLen, true, WCT_PONG); + // 顯示數據 + printf("webSocket_recv : PING %d\r\n%s\r\n" , retLen, webSocketPackage); + free(recvBuf); + free(webSocketPackage); + return WCT_NULL; + } + else if(retLen > 0 && (ret2 == WCT_TXTDATA || ret2 == WCT_BINDATA || ret2 == WCT_MINDATA)) // 解析爲數據包 + { + memcpy(data, webSocketPackage, retLen); // 把解析得到的數據複製出去 + /* + // 顯示數據 + if(webSocketPackage[0] >= ' ' && webSocketPackage[0] <= '~') + { + printf("\r\nwebSocket_recv : New Package StrFile ret2:%d/retLen:%d\r\n%s\r\n" , ret2, retLen, webSocketPackage); + } + else + { + printf("\r\nwebSocket_recv : New Package BinFile ret2:%d/retLen:%d\r\n" , ret2, retLen); + for(i = 0; i < retLen; i++) printf("%.2X ", webSocketPackage[i]); printf("\r\n"); + }*/ + free(recvBuf); + free(webSocketPackage); + return retLen; + }/* + else + { + // 顯示數據 + if(recvBuf[0] >= ' ' && recvBuf[0] <= '~') + printf("\r\nwebSocket_recv : ret:%d/ret2:%d/retLen:%d\r\n%s\r\n" , ret, ret2, retLen, recvBuf); + else + { + printf("\r\nwebSocket_recv : ret:%d/ret2:%d/retLen:%d\r\n%s\r\n" , ret, ret2, retLen, recvBuf); + for(i = 0; i < ret; i++) printf("%.2X ", recvBuf[i]); printf("\r\n"); + } + }*/ + free(recvBuf); + free(webSocketPackage); + return -ret; + } + else + { + free(recvBuf); + return ret; + } +} + +void delayms(unsigned int ms) +{ + struct timeval tim; + tim.tv_sec = ms/1000; + tim.tv_usec = (ms%1000)*1000; + select(0, NULL, NULL, NULL, &tim); +} + +/** + * @brief Get the face websocket json + * + */ +void get_face_websocket(){ + char ip[] = "127.0.0.1";//"192.168.244.128"; // 服務器IP + int port = 4242; // 服務器端口 + //int fd; + + // BUG4: 修正 while(1) 改為 while(條件式檢查) + while(bHttpServerThreadStart && unlockingKeyInnoFR_success){ + webSocket_clientLinkToServer(ip, port, "/api/v1/frame_data"); + delayms(10); + } +} + + + +/** + * @brief thread get face websocket + * + * @param ptr + * @return void* + */ +void *thread_get_face_websocket(void *ptr) +{ + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run thread face websocket\n"); + pthread_detach(pthread_self()); + get_face_websocket(); + pthread_exit(NULL); +} + + +void *thread_parse_face(void *ptr) +{ + pthread_detach(pthread_self()); + + // while (get_bHttpServerThreadStart()) + // while (1) + //{ + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run thread face parser\n"); + face_data_parser(); + + // usSleep(80000); + //} + + pthread_exit(NULL); +} + + diff --git a/src/websocket_client.h b/src/websocket_client.h new file mode 100644 index 0000000..53e7c41 --- /dev/null +++ b/src/websocket_client.h @@ -0,0 +1,88 @@ +#pragma once +#ifndef _WEBSOCKET_CLIENT_H_ +#define _WEBSOCKET_CLIENT_H_ +#include "define_inc.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> // 使用 malloc, calloc等動態分配內存方法 +#include <stdbool.h> +#include <time.h> // 獲取系統時間 +#include "cJSON.h" // 使用cJSON解析json數據 + +#include <errno.h> +#include <netinet/in.h> +#include <fcntl.h> // socket設置非阻塞模式 +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/epoll.h> // epoll管理服務器的連接和接收觸發 +#include <netinet/tcp.h> +#include <netdb.h> + +#include <pthread.h> // 使用多線程 +#include "sha1.h" +#include "setting.h" +#include "utility.h" +#include "nweb.h" + +//base64編/解碼用的基礎字符集 +//const char base64char[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char base64char[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/' }; + +// 連接服務器 +#define REPORT_LOGIN_CONNECT_TIMEOUT 3 +#define REPORT_LOGIN_RESPOND_TIMEOUT 5 +// 指令發收 +#define REPORT_ANALYSIS_ERR_RESEND_DELAY 500 // 接收到回覆內容但解析不通過, 延時 一段時間後重發指令 單位ms +// 生成握手key的長度 +#define WEBSOCKET_SHAKE_KEY_LEN 16 + +extern int bHttpServerThreadStart; + +// websocket根據data[0]判別數據包類型 比如0x81 = 0x80 | 0x1 爲一個txt類型數據包 +typedef enum{ + WCT_MINDATA = -20, // 0x0:標識一箇中間數據包 + WCT_TXTDATA = -19, // 0x1:標識一個txt類型數據包 + WCT_BINDATA = -18, // 0x2:標識一個bin類型數據包 + WCT_DISCONN = -17, // 0x8:標識一個斷開連接類型數據包 + WCT_PING = -16, // 0x8:標識一個斷開連接類型數據包 + WCT_PONG = -15, // 0xA:表示一個pong類型數據包 + WCT_ERR = -1, + WCT_NULL = 0 +}Websocket_CommunicationType; + +extern SocketInfo socketRecords[MAX_CLIENT_SOCKET]; + +// client向server發送http連接請求, 並處理返回 +void webSocket_clientLinkToServer(char *ip, int port, char *interface_path); + +// server回覆client的http請求 +int webSocket_serverLinkToClient(int fd, char *recvBuf, unsigned int bufLen); + +int webSocket_send(int fd, unsigned char *data, unsigned int dataLen, bool mod, Websocket_CommunicationType type); +int webSocket_recv(int fd, unsigned char *data, unsigned int dataMaxLen); + +void delayms(unsigned int ms); +void *thread_get_face_websocket(void *ptr); +void *thread_parse_face(void *ptr); + +/* +#define MAX_FACE_DATA_SIZE 8192 * 10 +#define FACE_QUEUE_SIZE 10 +typedef struct +{ + char frame_buffer[MAX_FACE_DATA_SIZE]; + int iDataSize; + +} FaceFrameData; +*/ + + +#endif diff --git a/src/yolo_layer.c b/src/yolo_layer.c new file mode 100644 index 0000000..33a746f --- /dev/null +++ b/src/yolo_layer.c @@ -0,0 +1,426 @@ +#include "yolo_layer.h" +#include "activations.h" +#include "blas.h" +#include "box.h" +#include "cuda.h" +#include "utils.h" + +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes) +{ + int i; + layer l = {0}; + l.type = YOLO; + + l.n = n; + l.total = total; + l.batch = batch; + l.h = h; + l.w = w; + l.c = n*(classes + 4 + 1); + l.out_w = l.w; + l.out_h = l.h; + l.out_c = l.c; + l.classes = classes; + l.cost = calloc(1, sizeof(float)); + l.biases = calloc(total*2, sizeof(float)); + if(mask) l.mask = mask; + else{ + l.mask = calloc(n, sizeof(int)); + for(i = 0; i < n; ++i){ + l.mask[i] = i; + } + } + l.bias_updates = calloc(n*2, sizeof(float)); + l.outputs = h*w*n*(classes + 4 + 1); + l.inputs = l.outputs; + l.truths = 90*(4 + 1); + l.delta = calloc(batch*l.outputs, sizeof(float)); + l.output = calloc(batch*l.outputs, sizeof(float)); + for(i = 0; i < total*2; ++i){ + l.biases[i] = .5; + } + + l.forward = forward_yolo_layer; + l.backward = backward_yolo_layer; +#ifdef GPU + l.forward_gpu = forward_yolo_layer_gpu; + l.backward_gpu = backward_yolo_layer_gpu; + l.output_gpu = cuda_make_array(l.output, batch*l.outputs); + l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs); +#endif + + fprintf(stderr, "yolo\n"); + srand(0); + + return l; +} + +void resize_yolo_layer(layer *l, int w, int h) +{ + l->w = w; + l->h = h; + + l->outputs = h*w*l->n*(l->classes + 4 + 1); + l->inputs = l->outputs; + + l->output = realloc(l->output, l->batch*l->outputs*sizeof(float)); + l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float)); + +#ifdef GPU + cuda_free(l->delta_gpu); + cuda_free(l->output_gpu); + + l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs); + l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs); +#endif +} + +box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, int stride) +{ + box b; + b.x = (i + x[index + 0*stride]) / lw; + b.y = (j + x[index + 1*stride]) / lh; + b.w = exp(x[index + 2*stride]) * biases[2*n] / w; + b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; + return b; +} + +float delta_yolo_box(box truth, float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, float *delta, float scale, int stride) +{ + box pred = get_yolo_box(x, biases, n, index, i, j, lw, lh, w, h, stride); + float iou = box_iou(pred, truth); + + float tx = (truth.x*lw - i); + float ty = (truth.y*lh - j); + float tw = log(truth.w*w / biases[2*n]); + float th = log(truth.h*h / biases[2*n + 1]); + + delta[index + 0*stride] = scale * (tx - x[index + 0*stride]); + delta[index + 1*stride] = scale * (ty - x[index + 1*stride]); + delta[index + 2*stride] = scale * (tw - x[index + 2*stride]); + delta[index + 3*stride] = scale * (th - x[index + 3*stride]); + return iou; +} + + +void delta_yolo_class(float *output, float *delta, int index, int class, int classes, int stride, float *avg_cat) +{ + int n; + if (delta[index]){ + delta[index + stride*class] = 1 - output[index + stride*class]; + if(avg_cat) *avg_cat += output[index + stride*class]; + return; + } + for(n = 0; n < classes; ++n){ + delta[index + stride*n] = ((n == class)?1 : 0) - output[index + stride*n]; + if(n == class && avg_cat) *avg_cat += output[index + stride*n]; + } +} + +static int entry_index(layer l, int batch, int location, int entry) +{ + int n = location / (l.w*l.h); + int loc = location % (l.w*l.h); + return batch*l.outputs + n*l.w*l.h*(4+l.classes+1) + entry*l.w*l.h + loc; +} + +void forward_yolo_layer(const layer l, network net) +{ + int i,j,b,t,n; + memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float)); + +#ifndef GPU + for (b = 0; b < l.batch; ++b){ + for(n = 0; n < l.n; ++n){ + int index = entry_index(l, b, n*l.w*l.h, 0); + activate_array(l.output + index, 2*l.w*l.h, LOGISTIC); + index = entry_index(l, b, n*l.w*l.h, 4); + activate_array(l.output + index, (1+l.classes)*l.w*l.h, LOGISTIC); + } + } +#endif + + memset(l.delta, 0, l.outputs * l.batch * sizeof(float)); + if(!net.train) return; + float avg_iou = 0; + float recall = 0; + float recall75 = 0; + float avg_cat = 0; + float avg_obj = 0; + float avg_anyobj = 0; + int count = 0; + int class_count = 0; + *(l.cost) = 0; + for (b = 0; b < l.batch; ++b) { + for (j = 0; j < l.h; ++j) { + for (i = 0; i < l.w; ++i) { + for (n = 0; n < l.n; ++n) { + int box_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, 0); + box pred = get_yolo_box(l.output, l.biases, l.mask[n], box_index, i, j, l.w, l.h, net.w, net.h, l.w*l.h); + float best_iou = 0; + int best_t = 0; + for(t = 0; t < l.max_boxes; ++t){ + box truth = float_to_box(net.truth + t*(4 + 1) + b*l.truths, 1); + if(!truth.x) break; + float iou = box_iou(pred, truth); + if (iou > best_iou) { + best_iou = iou; + best_t = t; + } + } + int obj_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, 4); + avg_anyobj += l.output[obj_index]; + l.delta[obj_index] = 0 - l.output[obj_index]; + if (best_iou > l.ignore_thresh) { + l.delta[obj_index] = 0; + } + if (best_iou > l.truth_thresh) { + l.delta[obj_index] = 1 - l.output[obj_index]; + + int class = net.truth[best_t*(4 + 1) + b*l.truths + 4]; + if (l.map) class = l.map[class]; + int class_index = entry_index(l, b, n*l.w*l.h + j*l.w + i, 4 + 1); + delta_yolo_class(l.output, l.delta, class_index, class, l.classes, l.w*l.h, 0); + box truth = float_to_box(net.truth + best_t*(4 + 1) + b*l.truths, 1); + delta_yolo_box(truth, l.output, l.biases, l.mask[n], box_index, i, j, l.w, l.h, net.w, net.h, l.delta, (2-truth.w*truth.h), l.w*l.h); + } + } + } + } + for(t = 0; t < l.max_boxes; ++t){ + box truth = float_to_box(net.truth + t*(4 + 1) + b*l.truths, 1); + + if(!truth.x) break; + float best_iou = 0; + int best_n = 0; + i = (truth.x * l.w); + j = (truth.y * l.h); + box truth_shift = truth; + truth_shift.x = truth_shift.y = 0; + for(n = 0; n < l.total; ++n){ + box pred = {0}; + pred.w = l.biases[2*n]/net.w; + pred.h = l.biases[2*n+1]/net.h; + float iou = box_iou(pred, truth_shift); + if (iou > best_iou){ + best_iou = iou; + best_n = n; + } + } + + int mask_n = int_index(l.mask, best_n, l.n); + if(mask_n >= 0){ + int box_index = entry_index(l, b, mask_n*l.w*l.h + j*l.w + i, 0); + float iou = delta_yolo_box(truth, l.output, l.biases, best_n, box_index, i, j, l.w, l.h, net.w, net.h, l.delta, (2-truth.w*truth.h), l.w*l.h); + + int obj_index = entry_index(l, b, mask_n*l.w*l.h + j*l.w + i, 4); + avg_obj += l.output[obj_index]; + l.delta[obj_index] = 1 - l.output[obj_index]; + + int class = net.truth[t*(4 + 1) + b*l.truths + 4]; + if (l.map) class = l.map[class]; + int class_index = entry_index(l, b, mask_n*l.w*l.h + j*l.w + i, 4 + 1); + delta_yolo_class(l.output, l.delta, class_index, class, l.classes, l.w*l.h, &avg_cat); + + ++count; + ++class_count; + if(iou > .5) recall += 1; + if(iou > .75) recall75 += 1; + avg_iou += iou; + } + } + } + *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2); + printf("Region %d Avg IOU: %f, Class: %f, Obj: %f, No Obj: %f, .5R: %f, .75R: %f, count: %d\n", net.index, avg_iou/count, avg_cat/class_count, avg_obj/count, avg_anyobj/(l.w*l.h*l.n*l.batch), recall/count, recall75/count, count); +} + +void backward_yolo_layer(const layer l, network net) +{ + axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, net.delta, 1); +} + +void correct_yolo_boxes(detection *dets, int n, int w, int h, int netw, int neth, int relative) +{ + int i; + int new_w=0; + int new_h=0; + if (((float)netw/w) < ((float)neth/h)) { + new_w = netw; + new_h = (h * netw)/w; + } else { + new_h = neth; + new_w = (w * neth)/h; + } + for (i = 0; i < n; ++i){ + box b = dets[i].bbox; + b.x = (b.x - (netw - new_w)/2./netw) / ((float)new_w/netw); + b.y = (b.y - (neth - new_h)/2./neth) / ((float)new_h/neth); + b.w *= (float)netw/new_w; + b.h *= (float)neth/new_h; + if(!relative){ + b.x *= w; + b.w *= w; + b.y *= h; + b.h *= h; + } + dets[i].bbox = b; + } +} + +int yolo_num_detections(layer l, float thresh) +{ + int i, n; + int count = 0; + for (i = 0; i < l.w*l.h; ++i){ + for(n = 0; n < l.n; ++n){ + int obj_index = entry_index(l, 0, n*l.w*l.h + i, 4); + if(l.output[obj_index] > thresh){ + ++count; + } + } + } + return count; +} + +void avg_flipped_yolo(layer l) +{ + int i,j,n,z; + float *flip = l.output + l.outputs; + for (j = 0; j < l.h; ++j) { + for (i = 0; i < l.w/2; ++i) { + for (n = 0; n < l.n; ++n) { + for(z = 0; z < l.classes + 4 + 1; ++z){ + int i1 = z*l.w*l.h*l.n + n*l.w*l.h + j*l.w + i; + int i2 = z*l.w*l.h*l.n + n*l.w*l.h + j*l.w + (l.w - i - 1); + float swap = flip[i1]; + flip[i1] = flip[i2]; + flip[i2] = swap; + if(z == 0){ + flip[i1] = -flip[i1]; + flip[i2] = -flip[i2]; + } + } + } + } + } + for(i = 0; i < l.outputs; ++i){ + l.output[i] = (l.output[i] + flip[i])/2.; + } +} + +int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets) +{ + int i,j,n; + float *predictions = l.output; + if (l.batch == 2) avg_flipped_yolo(l); + int count = 0; + for (i = 0; i < l.w*l.h; ++i){ + int row = i / l.w; + int col = i % l.w; + for(n = 0; n < l.n; ++n){ + int obj_index = entry_index(l, 0, n*l.w*l.h + i, 4); + float objectness = predictions[obj_index]; + if(objectness <= thresh) continue; + int box_index = entry_index(l, 0, n*l.w*l.h + i, 0); + dets[count].bbox = get_yolo_box(predictions, l.biases, l.mask[n], box_index, col, row, l.w, l.h, netw, neth, l.w*l.h); + dets[count].objectness = objectness; + dets[count].classes = l.classes; + for(j = 0; j < l.classes; ++j){ + int class_index = entry_index(l, 0, n*l.w*l.h + i, 4 + 1 + j); + float prob = objectness*predictions[class_index]; + dets[count].prob[j] = (prob > thresh) ? prob : 0; + } + ++count; + } + } + correct_yolo_boxes(dets, count, w, h, netw, neth, relative); + return count; +} + +#ifdef GPU + +void forward_yolo_layer_gpu(const layer l, network net) +{ + copy_gpu(l.batch*l.inputs, net.input_gpu, 1, l.output_gpu, 1); + int b, n; + for (b = 0; b < l.batch; ++b){ + for(n = 0; n < l.n; ++n){ + int index = entry_index(l, b, n*l.w*l.h, 0); + activate_array_gpu(l.output_gpu + index, 2*l.w*l.h, LOGISTIC); + index = entry_index(l, b, n*l.w*l.h, 4); + activate_array_gpu(l.output_gpu + index, (1+l.classes)*l.w*l.h, LOGISTIC); + } + } + if(!net.train || l.onlyforward){ + cuda_pull_array(l.output_gpu, l.output, l.batch*l.outputs); + return; + } + + cuda_pull_array(l.output_gpu, net.input, l.batch*l.inputs); + forward_yolo_layer(l, net); + cuda_push_array(l.delta_gpu, l.delta, l.batch*l.outputs); +} + +void backward_yolo_layer_gpu(const layer l, network net) +{ + axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1); +} +#endif + +#ifdef ALLEN_MODIFIED +layer make_yolo_layer_mem(int batch, int w, int h, int n, int total, int *mask, int classes, int max_boxes) +{ + int i; + layer l = { 0 }; + l.type = YOLO; + + l.n = n; + l.total = total; + l.batch = batch; + l.h = h; + l.w = w; + l.c = n * (classes + 4 + 1); + l.out_w = l.w; + l.out_h = l.h; + l.out_c = l.c; + l.classes = classes; + l.cost = calloc(1, sizeof(float)); + l.biases = calloc(total * 2, sizeof(float)); + if (mask) l.mask = mask; + else { + l.mask = calloc(n, sizeof(int)); + for (i = 0; i < n; ++i) { + l.mask[i] = i; + } + } + l.bias_updates = calloc(n * 2, sizeof(float)); + l.outputs = h * w*n*(classes + 4 + 1); + l.inputs = l.outputs; + l.max_boxes = max_boxes; + l.truths = l.max_boxes*(4 + 1); // 90*(4 + 1); + l.delta = calloc(batch*l.outputs, sizeof(float)); + l.output = calloc(batch*l.outputs, sizeof(float)); + for (i = 0; i < total * 2; ++i) { + l.biases[i] = .5; + } + + l.forward = forward_yolo_layer; + l.backward = backward_yolo_layer; +#ifdef GPU + l.forward_gpu = forward_yolo_layer_gpu; + l.backward_gpu = backward_yolo_layer_gpu; + l.output_gpu = cuda_make_array(l.output, batch*l.outputs); + l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs); +#endif + + //fprintf(stderr, "yolo\n"); + srand(0); + + return l; +} +#endif \ No newline at end of file diff --git a/src/yolo_layer.h b/src/yolo_layer.h new file mode 100644 index 0000000..2d301e9 --- /dev/null +++ b/src/yolo_layer.h @@ -0,0 +1,25 @@ +#pragma once +#ifndef YOLO_LAYER_H +#define YOLO_LAYER_H +#include "define_inc.h" +#include "darknet.h" +#include "layer.h" +#include "network.h" +#include "option_list.h" + +layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes); +void forward_yolo_layer(const layer l, network net); +void backward_yolo_layer(const layer l, network net); +void resize_yolo_layer(layer *l, int w, int h); +int yolo_num_detections(layer l, float thresh); + +#ifdef GPU +void forward_yolo_layer_gpu(const layer l, network net); +void backward_yolo_layer_gpu(layer l, network net); +#endif + +#ifdef ALLEN_MODIFIED +layer make_yolo_layer_mem(int batch, int w, int h, int n, int total, int *mask, int classes, int max_boxes); +#endif + +#endif diff --git a/src/yuv_rgb.c b/src/yuv_rgb.c new file mode 100644 index 0000000..a089654 --- /dev/null +++ b/src/yuv_rgb.c @@ -0,0 +1,1312 @@ +// Copyright 2016 Adrien Descamps +// Distributed under BSD 3-Clause License + +#include "yuv_rgb.h" + +//#include <emmintrin.h> + +#ifdef _MSC_VER +// MSVC does not have __SSE2__ macro + #if (defined(_M_AMD64) || defined(_M_X64) || (_M_IX86_FP == 2)) + #define _YUVRGB_SSE2_ + #endif +#else +// For everything else than MSVC + #ifdef __SSE2__ + #define _YUVRGB_SSE2_ + #endif // __SSE2__ +#endif // _MSC_VER + +uint8_t clamp(int16_t value) +{ + return value<0 ? 0 : (value>255 ? 255 : value); +} + +// Definitions +// +// E'R, E'G, E'B, E'Y, E'Cb and E'Cr refer to the analog signals +// E'R, E'G, E'B and E'Y range is [0:1], while E'Cb and E'Cr range is [-0.5:0.5] +// R, G, B, Y, Cb and Cr refer to the digitalized values +// The digitalized values can use their full range ([0:255] for 8bit values), +// or a subrange (typically [16:235] for Y and [16:240] for CbCr). +// We assume here that RGB range is always [0:255], since it is the case for +// most digitalized images. +// For 8bit values : +// * Y = round((YMax-YMin)*E'Y + YMin) +// * Cb = round((CbRange)*E'Cb + 128) +// * Cr = round((CrRange)*E'Cr + 128) +// Where *Min and *Max are the range of each channel +// +// In the analog domain , the RGB to YCbCr transformation is defined as: +// * E'Y = Rf*E'R + Gf*E'G + Bf*E'B +// Where Rf, Gf and Bf are constants defined in each standard, with +// Rf + Gf + Bf = 1 (necessary to ensure that E'Y range is [0:1]) +// * E'Cb = (E'B - E'Y) / CbNorm +// * E'Cr = (E'R - E'Y) / CrNorm +// Where CbNorm and CrNorm are constants, dependent of Rf, Gf, Bf, computed +// to normalize to a [-0.5:0.5] range : CbNorm=2*(1-Bf) and CrNorm=2*(1-Rf) +// +// Algorithms +// +// Most operations will be made in a fixed point format for speed, using +// N bits of precision. In next section the [x] convention is used for +// a fixed point rounded value, that is (int being the c type conversion) +// * [x] = int(x*(2^N)+0.5) +// N can be different for each factor, we simply use the highest value +// that will not overflow in 16 bits intermediate variables. +//. +// For RGB to YCbCr conversion, we start by generating a pseudo Y value +// (noted Y') in fixed point format, using the full range for now. +// * Y' = ([Rf]*R + [Gf]*G + [Bf]*B)>>N +// We can then compute Cb and Cr by +// * Cb = ((B - Y')*[CbRange/(255*CbNorm)])>>N + 128 +// * Cr = ((R - Y')*[CrRange/(255*CrNorm)])>>N + 128 +// And finally, we normalize Y to its digital range +// * Y = (Y'*[(YMax-YMin)/255])>>N + YMin +// +// For YCbCr to RGB conversion, we first compute the full range Y' value : +// * Y' = ((Y-YMin)*[255/(YMax-YMin)])>>N +// We can then compute B and R values by : +// * B = ((Cb-128)*[(255*CbNorm)/CbRange])>>N + Y' +// * R = ((Cr-128)*[(255*CrNorm)/CrRange])>>N + Y' +// And finally, for G we know that: +// * G = (Y' - (Rf*R + Bf*B)) / Gf +// From above: +// * G = (Y' - Rf * ((Cr-128)*(255*CrNorm)/CrRange + Y') - Bf * ((Cb-128)*(255*CbNorm)/CbRange + Y')) / Gf +// Since 1-Rf-Bf=Gf, we can take Y' out of the division by Gf, and we get: +// * G = Y' - (Cr-128)*Rf/Gf*(255*CrNorm)/CrRange - (Cb-128)*Bf/Gf*(255*CbNorm)/CbRange +// That we can compute, with fixed point arithmetic, by +// * G = Y' - ((Cr-128)*[Rf/Gf*(255*CrNorm)/CrRange] + (Cb-128)*[Bf/Gf*(255*CbNorm)/CbRange])>>N +// +// Note : in ITU-T T.871(JPEG), Y=Y', so that part could be optimized out + + +#define FIXED_POINT_VALUE(value, precision) ((int)(((value)*(1<<precision))+0.5)) + +// see above for description +typedef struct +{ + uint8_t r_factor; // [Rf] + uint8_t g_factor; // [Rg] + uint8_t b_factor; // [Rb] + uint8_t cb_factor; // [CbRange/(255*CbNorm)] + uint8_t cr_factor; // [CrRange/(255*CrNorm)] + uint8_t y_factor; // [(YMax-YMin)/255] + uint8_t y_offset; // YMin +} RGB2YUVParam; + +typedef struct +{ + uint8_t cb_factor; // [(255*CbNorm)/CbRange] + uint8_t cr_factor; // [(255*CrNorm)/CrRange] + uint8_t g_cb_factor; // [Bf/Gf*(255*CbNorm)/CbRange] + uint8_t g_cr_factor; // [Rf/Gf*(255*CrNorm)/CrRange] + uint8_t y_factor; // [(YMax-YMin)/255] + uint8_t y_offset; // YMin +} YUV2RGBParam; + +#define RGB2YUV_PARAM(Rf, Bf, YMin, YMax, CbCrRange) \ +{.r_factor=FIXED_POINT_VALUE(Rf, 8), \ +.g_factor=256-FIXED_POINT_VALUE(Rf, 8)-FIXED_POINT_VALUE(Bf, 8), \ +.b_factor=FIXED_POINT_VALUE(Bf, 8), \ +.cb_factor=FIXED_POINT_VALUE((CbCrRange/255.0)/(2.0*(1-Bf)), 8), \ +.cr_factor=FIXED_POINT_VALUE((CbCrRange/255.0)/(2.0*(1-Rf)), 8), \ +.y_factor=FIXED_POINT_VALUE((YMax-YMin)/255.0, 7), \ +.y_offset=YMin} + +#define YUV2RGB_PARAM(Rf, Bf, YMin, YMax, CbCrRange) \ +{.cb_factor=FIXED_POINT_VALUE(255.0*(2.0*(1-Bf))/CbCrRange, 6), \ +.cr_factor=FIXED_POINT_VALUE(255.0*(2.0*(1-Rf))/CbCrRange, 6), \ +.g_cb_factor=FIXED_POINT_VALUE(Bf/(1.0-Bf-Rf)*255.0*(2.0*(1-Bf))/CbCrRange, 7), \ +.g_cr_factor=FIXED_POINT_VALUE(Rf/(1.0-Bf-Rf)*255.0*(2.0*(1-Rf))/CbCrRange, 7), \ +.y_factor=FIXED_POINT_VALUE(255.0/(YMax-YMin), 7), \ +.y_offset=YMin} + +static const RGB2YUVParam RGB2YUV[3] = { + // ITU-T T.871 (JPEG) + RGB2YUV_PARAM(0.299, 0.114, 0.0, 255.0, 255.0), + // ITU-R BT.601-7 + RGB2YUV_PARAM(0.299, 0.114, 16.0, 235.0, 224.0), + // ITU-R BT.709-6 + RGB2YUV_PARAM(0.2126, 0.0722, 16.0, 235.0, 224.0) +}; + +static const YUV2RGBParam YUV2RGB[3] = { + // ITU-T T.871 (JPEG) + YUV2RGB_PARAM(0.299, 0.114, 0.0, 255.0, 255.0), + // ITU-R BT.601-7 + YUV2RGB_PARAM(0.299, 0.114, 16.0, 235.0, 224.0), + // ITU-R BT.709-6 + YUV2RGB_PARAM(0.2126, 0.0722, 16.0, 235.0, 224.0) +}; + + +void rgb24_yuv420_std( + uint32_t width, uint32_t height, + const uint8_t *RGB, uint32_t RGB_stride, + uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + YCbCrType yuv_type) +{ + const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + for(x=0; x<(width-1); x+=2) + { + // compute yuv for the four pixels, u and v values are summed + uint8_t y_tmp; + int16_t u_tmp, v_tmp; + + y_tmp = (param->r_factor*rgb_ptr1[0] + param->g_factor*rgb_ptr1[1] + param->b_factor*rgb_ptr1[2])>>8; + u_tmp = rgb_ptr1[2]-y_tmp; + v_tmp = rgb_ptr1[0]-y_tmp; + y_ptr1[0]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + y_tmp = (param->r_factor*rgb_ptr1[3] + param->g_factor*rgb_ptr1[4] + param->b_factor*rgb_ptr1[5])>>8; + u_tmp += rgb_ptr1[5]-y_tmp; + v_tmp += rgb_ptr1[3]-y_tmp; + y_ptr1[1]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + y_tmp = (param->r_factor*rgb_ptr2[0] + param->g_factor*rgb_ptr2[1] + param->b_factor*rgb_ptr2[2])>>8; + u_tmp += rgb_ptr2[2]-y_tmp; + v_tmp += rgb_ptr2[0]-y_tmp; + y_ptr2[0]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + y_tmp = (param->r_factor*rgb_ptr2[3] + param->g_factor*rgb_ptr2[4] + param->b_factor*rgb_ptr2[5])>>8; + u_tmp += rgb_ptr2[5]-y_tmp; + v_tmp += rgb_ptr2[3]-y_tmp; + y_ptr2[1]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + u_ptr[0] = (((u_tmp>>2)*param->cb_factor)>>8) + 128; + v_ptr[0] = (((v_tmp>>2)*param->cr_factor)>>8) + 128; + + rgb_ptr1 += 6; + rgb_ptr2 += 6; + y_ptr1 += 2; + y_ptr2 += 2; + u_ptr += 1; + v_ptr += 1; + } + } +} + +void rgb32_yuv420_std( + uint32_t width, uint32_t height, + const uint8_t *RGBA, uint32_t RGBA_stride, + uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + YCbCrType yuv_type) +{ + const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *rgb_ptr1=RGBA+y*RGBA_stride, + *rgb_ptr2=RGBA+(y+1)*RGBA_stride; + + uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + for(x=0; x<(width-1); x+=2) + { + // compute yuv for the four pixels, u and v values are summed + uint8_t y_tmp; + int16_t u_tmp, v_tmp; + + y_tmp = (param->r_factor*rgb_ptr1[0] + param->g_factor*rgb_ptr1[1] + param->b_factor*rgb_ptr1[2])>>8; + u_tmp = rgb_ptr1[2]-y_tmp; + v_tmp = rgb_ptr1[0]-y_tmp; + y_ptr1[0]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + y_tmp = (param->r_factor*rgb_ptr1[4] + param->g_factor*rgb_ptr1[5] + param->b_factor*rgb_ptr1[6])>>8; + u_tmp += rgb_ptr1[6]-y_tmp; + v_tmp += rgb_ptr1[4]-y_tmp; + y_ptr1[1]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + y_tmp = (param->r_factor*rgb_ptr2[0] + param->g_factor*rgb_ptr2[1] + param->b_factor*rgb_ptr2[2])>>8; + u_tmp += rgb_ptr2[2]-y_tmp; + v_tmp += rgb_ptr2[0]-y_tmp; + y_ptr2[0]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + y_tmp = (param->r_factor*rgb_ptr2[4] + param->g_factor*rgb_ptr2[5] + param->b_factor*rgb_ptr2[6])>>8; + u_tmp += rgb_ptr2[6]-y_tmp; + v_tmp += rgb_ptr2[4]-y_tmp; + y_ptr2[1]=((y_tmp*param->y_factor)>>7) + param->y_offset; + + u_ptr[0] = (((u_tmp>>2)*param->cb_factor)>>8) + 128; + v_ptr[0] = (((v_tmp>>2)*param->cb_factor)>>8) + 128; + + rgb_ptr1 += 8; + rgb_ptr2 += 8; + y_ptr1 += 2; + y_ptr2 += 2; + u_ptr += 1; + v_ptr += 1; + } + } +} + + +void yuv420_rgb24_std( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *U, const uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-1); x+=2) + { + int8_t u_tmp, v_tmp; + u_tmp = u_ptr[0]-128; + v_tmp = v_ptr[0]-128; + + //compute Cb Cr color offsets, common to four pixels + int16_t b_cb_offset, r_cr_offset, g_cbcr_offset; + b_cb_offset = (param->cb_factor*u_tmp)>>6; + r_cr_offset = (param->cr_factor*v_tmp)>>6; + g_cbcr_offset = (param->g_cb_factor*u_tmp + param->g_cr_factor*v_tmp)>>7; + + int16_t y_tmp; + y_tmp = (param->y_factor*(y_ptr1[0]-param->y_offset))>>7; + rgb_ptr1[0] = clamp(y_tmp + r_cr_offset); + rgb_ptr1[1] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr1[2] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr1[1]-param->y_offset))>>7; + rgb_ptr1[3] = clamp(y_tmp + r_cr_offset); + rgb_ptr1[4] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr1[5] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr2[0]-param->y_offset))>>7; + rgb_ptr2[0] = clamp(y_tmp + r_cr_offset); + rgb_ptr2[1] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr2[2] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr2[1]-param->y_offset))>>7; + rgb_ptr2[3] = clamp(y_tmp + r_cr_offset); + rgb_ptr2[4] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr2[5] = clamp(y_tmp + b_cb_offset); + + rgb_ptr1 += 6; + rgb_ptr2 += 6; + y_ptr1 += 2; + y_ptr2 += 2; + u_ptr += 1; + v_ptr += 1; + } + } +} + +void nv12_rgb24_std( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *UV, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *uv_ptr=UV+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-1); x+=2) + { + int8_t u_tmp, v_tmp; + u_tmp = uv_ptr[0]-128; + v_tmp = uv_ptr[1]-128; + + //compute Cb Cr color offsets, common to four pixels + int16_t b_cb_offset, r_cr_offset, g_cbcr_offset; + b_cb_offset = (param->cb_factor*u_tmp)>>6; + r_cr_offset = (param->cr_factor*v_tmp)>>6; + g_cbcr_offset = (param->g_cb_factor*u_tmp + param->g_cr_factor*v_tmp)>>7; + + int16_t y_tmp; + y_tmp = (param->y_factor*(y_ptr1[0]-param->y_offset))>>7; + rgb_ptr1[0] = clamp(y_tmp + r_cr_offset); + rgb_ptr1[1] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr1[2] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr1[1]-param->y_offset))>>7; + rgb_ptr1[3] = clamp(y_tmp + r_cr_offset); + rgb_ptr1[4] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr1[5] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr2[0]-param->y_offset))>>7; + rgb_ptr2[0] = clamp(y_tmp + r_cr_offset); + rgb_ptr2[1] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr2[2] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr2[1]-param->y_offset))>>7; + rgb_ptr2[3] = clamp(y_tmp + r_cr_offset); + rgb_ptr2[4] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr2[5] = clamp(y_tmp + b_cb_offset); + + rgb_ptr1 += 6; + rgb_ptr2 += 6; + y_ptr1 += 2; + y_ptr2 += 2; + uv_ptr += 2; + } + } +} + +void nv21_rgb24_std( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *UV, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *uv_ptr=UV+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-1); x+=2) + { + int8_t u_tmp, v_tmp; + u_tmp = uv_ptr[1]-128; + v_tmp = uv_ptr[0]-128; + + //compute Cb Cr color offsets, common to four pixels + int16_t b_cb_offset, r_cr_offset, g_cbcr_offset; + b_cb_offset = (param->cb_factor*u_tmp)>>6; + r_cr_offset = (param->cr_factor*v_tmp)>>6; + g_cbcr_offset = (param->g_cb_factor*u_tmp + param->g_cr_factor*v_tmp)>>7; + + int16_t y_tmp; + y_tmp = (param->y_factor*(y_ptr1[0]-param->y_offset))>>7; + rgb_ptr1[0] = clamp(y_tmp + r_cr_offset); + rgb_ptr1[1] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr1[2] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr1[1]-param->y_offset))>>7; + rgb_ptr1[3] = clamp(y_tmp + r_cr_offset); + rgb_ptr1[4] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr1[5] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr2[0]-param->y_offset))>>7; + rgb_ptr2[0] = clamp(y_tmp + r_cr_offset); + rgb_ptr2[1] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr2[2] = clamp(y_tmp + b_cb_offset); + + y_tmp = (param->y_factor*(y_ptr2[1]-param->y_offset))>>7; + rgb_ptr2[3] = clamp(y_tmp + r_cr_offset); + rgb_ptr2[4] = clamp(y_tmp - g_cbcr_offset); + rgb_ptr2[5] = clamp(y_tmp + b_cb_offset); + + rgb_ptr1 += 6; + rgb_ptr2 += 6; + y_ptr1 += 2; + y_ptr2 += 2; + uv_ptr += 2; + } + } +} + + +#ifdef _YUVRGB_SSE2_ + +//see rgb.txt +#define UNPACK_RGB24_32_STEP(RS1, RS2, RS3, RS4, RS5, RS6, RD1, RD2, RD3, RD4, RD5, RD6) \ +RD1 = _mm_unpacklo_epi8(RS1, RS4); \ +RD2 = _mm_unpackhi_epi8(RS1, RS4); \ +RD3 = _mm_unpacklo_epi8(RS2, RS5); \ +RD4 = _mm_unpackhi_epi8(RS2, RS5); \ +RD5 = _mm_unpacklo_epi8(RS3, RS6); \ +RD6 = _mm_unpackhi_epi8(RS3, RS6); + +#define RGB2YUV_16(R, G, B, Y, U, V) \ +Y = _mm_add_epi16(_mm_mullo_epi16(R, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(G, _mm_set1_epi16(param->g_factor))); \ +Y = _mm_add_epi16(Y, _mm_mullo_epi16(B, _mm_set1_epi16(param->b_factor))); \ +Y = _mm_srli_epi16(Y, 8); \ +U = _mm_mullo_epi16(_mm_sub_epi16(B, Y), _mm_set1_epi16(param->cb_factor)); \ +U = _mm_add_epi16(_mm_srai_epi16(U, 8), _mm_set1_epi16(128)); \ +V = _mm_mullo_epi16(_mm_sub_epi16(R, Y), _mm_set1_epi16(param->cr_factor)); \ +V = _mm_add_epi16(_mm_srai_epi16(V, 8), _mm_set1_epi16(128)); \ +Y = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(Y, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); + +#define RGB2YUV_32 \ + __m128i r_16, g_16, b_16; \ + __m128i y1_16, y2_16, cb1_16, cb2_16, cr1_16, cr2_16, Y, cb, cr; \ + __m128i tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; \ + __m128i rgb1 = LOAD_SI128((const __m128i*)(rgb_ptr1)), \ + rgb2 = LOAD_SI128((const __m128i*)(rgb_ptr1+16)), \ + rgb3 = LOAD_SI128((const __m128i*)(rgb_ptr1+32)), \ + rgb4 = LOAD_SI128((const __m128i*)(rgb_ptr2)), \ + rgb5 = LOAD_SI128((const __m128i*)(rgb_ptr2+16)), \ + rgb6 = LOAD_SI128((const __m128i*)(rgb_ptr2+32)); \ + /* unpack rgb24 data to r, g and b data in separate channels*/ \ + /* see rgb.txt to get an idea of the algorithm, note that we only go to the next to last step*/ \ + /* here, because averaging in horizontal direction is easier like this*/ \ + /* The last step is applied further on the Y channel only*/ \ + UNPACK_RGB24_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6) \ + UNPACK_RGB24_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6) \ + UNPACK_RGB24_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6) \ + UNPACK_RGB24_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6) \ + /* first compute Y', (B-Y') and (R-Y'), in 16bits values, for the first line */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are saved*/ \ + r_16 = _mm_unpacklo_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb1_16 = _mm_sub_epi16(b_16, y1_16); \ + cr1_16 = _mm_sub_epi16(r_16, y1_16); \ + r_16 = _mm_unpacklo_epi8(rgb4, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb5, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb6, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb1_16 = _mm_add_epi16(cb1_16, _mm_sub_epi16(b_16, y2_16)); \ + cr1_16 = _mm_add_epi16(cr1_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr1), Y); \ + /* same for the second line, compute Y', (B-Y') and (R-Y'), in 16bits values */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are added to the previous values*/ \ + r_16 = _mm_unpackhi_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb1_16 = _mm_add_epi16(cb1_16, _mm_sub_epi16(b_16, y1_16)); \ + cr1_16 = _mm_add_epi16(cr1_16, _mm_sub_epi16(r_16, y1_16)); \ + r_16 = _mm_unpackhi_epi8(rgb4, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb5, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb6, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb1_16 = _mm_add_epi16(cb1_16, _mm_sub_epi16(b_16, y2_16)); \ + cr1_16 = _mm_add_epi16(cr1_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr2), Y); \ + /* Rescale Cb and Cr to their final range */ \ + cb1_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cb1_16, 2), _mm_set1_epi16(param->cb_factor)), 8), _mm_set1_epi16(128)); \ + cr1_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cr1_16, 2), _mm_set1_epi16(param->cr_factor)), 8), _mm_set1_epi16(128)); \ + \ + /* do the same again with next data */ \ + rgb1 = LOAD_SI128((const __m128i*)(rgb_ptr1+48)), \ + rgb2 = LOAD_SI128((const __m128i*)(rgb_ptr1+64)), \ + rgb3 = LOAD_SI128((const __m128i*)(rgb_ptr1+80)), \ + rgb4 = LOAD_SI128((const __m128i*)(rgb_ptr2+48)), \ + rgb5 = LOAD_SI128((const __m128i*)(rgb_ptr2+64)), \ + rgb6 = LOAD_SI128((const __m128i*)(rgb_ptr2+80)); \ + /* unpack rgb24 data to r, g and b data in separate channels*/ \ + /* see rgb.txt to get an idea of the algorithm, note that we only go to the next to last step*/ \ + /* here, because averaging in horizontal direction is easier like this*/ \ + /* The last step is applied further on the Y channel only*/ \ + UNPACK_RGB24_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6) \ + UNPACK_RGB24_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6) \ + UNPACK_RGB24_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6) \ + UNPACK_RGB24_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6) \ + /* first compute Y', (B-Y') and (R-Y'), in 16bits values, for the first line */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are saved*/ \ + r_16 = _mm_unpacklo_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb2_16 = _mm_sub_epi16(b_16, y1_16); \ + cr2_16 = _mm_sub_epi16(r_16, y1_16); \ + r_16 = _mm_unpacklo_epi8(rgb4, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb5, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb6, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb2_16 = _mm_add_epi16(cb2_16, _mm_sub_epi16(b_16, y2_16)); \ + cr2_16 = _mm_add_epi16(cr2_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr1+16), Y); \ + /* same for the second line, compute Y', (B-Y') and (R-Y'), in 16bits values */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are added to the previous values*/ \ + r_16 = _mm_unpackhi_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb2_16 = _mm_add_epi16(cb2_16, _mm_sub_epi16(b_16, y1_16)); \ + cr2_16 = _mm_add_epi16(cr2_16, _mm_sub_epi16(r_16, y1_16)); \ + r_16 = _mm_unpackhi_epi8(rgb4, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb5, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb6, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb2_16 = _mm_add_epi16(cb2_16, _mm_sub_epi16(b_16, y2_16)); \ + cr2_16 = _mm_add_epi16(cr2_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr2+16), Y); \ + /* Rescale Cb and Cr to their final range */ \ + cb2_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cb2_16, 2), _mm_set1_epi16(param->cb_factor)), 8), _mm_set1_epi16(128)); \ + cr2_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cr2_16, 2), _mm_set1_epi16(param->cr_factor)), 8), _mm_set1_epi16(128)); \ + /* Pack and save Cb Cr */ \ + cb = _mm_packus_epi16(cb1_16, cb2_16); \ + cr = _mm_packus_epi16(cr1_16, cr2_16); \ + SAVE_SI128((__m128i*)(u_ptr), cb); \ + SAVE_SI128((__m128i*)(v_ptr), cr); + + +void rgb24_yuv420_sse(uint32_t width, uint32_t height, + const uint8_t *RGB, uint32_t RGB_stride, + uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_load_si128 + #define SAVE_SI128 _mm_stream_si128 + const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + for(x=0; x<(width-31); x+=32) + { + RGB2YUV_32 + + rgb_ptr1+=96; + rgb_ptr2+=96; + y_ptr1+=32; + y_ptr2+=32; + u_ptr+=16; + v_ptr+=16; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void rgb24_yuv420_sseu(uint32_t width, uint32_t height, + const uint8_t *RGB, uint32_t RGB_stride, + uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_loadu_si128 + #define SAVE_SI128 _mm_storeu_si128 + const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + for(x=0; x<(width-31); x+=32) + { + RGB2YUV_32 + + rgb_ptr1+=96; + rgb_ptr2+=96; + y_ptr1+=32; + y_ptr2+=32; + u_ptr+=16; + v_ptr+=16; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + + +// see rgba.txt +#define UNPACK_RGB32_32_STEP(RS1, RS2, RS3, RS4, RS5, RS6, RS7, RS8, RD1, RD2, RD3, RD4, RD5, RD6, RD7, RD8) \ +RD1 = _mm_unpacklo_epi8(RS1, RS5); \ +RD2 = _mm_unpackhi_epi8(RS1, RS5); \ +RD3 = _mm_unpacklo_epi8(RS2, RS6); \ +RD4 = _mm_unpackhi_epi8(RS2, RS6); \ +RD5 = _mm_unpacklo_epi8(RS3, RS7); \ +RD6 = _mm_unpackhi_epi8(RS3, RS7); \ +RD7 = _mm_unpacklo_epi8(RS4, RS8); \ +RD8 = _mm_unpackhi_epi8(RS4, RS8); + + +#define RGBA2YUV_32 \ + __m128i r_16, g_16, b_16; \ + __m128i y1_16, y2_16, cb1_16, cb2_16, cr1_16, cr2_16, Y, cb, cr; \ + __m128i tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; \ + __m128i rgb1 = LOAD_SI128((const __m128i*)(rgb_ptr1)), \ + rgb2 = LOAD_SI128((const __m128i*)(rgb_ptr1+16)), \ + rgb3 = LOAD_SI128((const __m128i*)(rgb_ptr1+32)), \ + rgb4 = LOAD_SI128((const __m128i*)(rgb_ptr1+48)), \ + rgb5 = LOAD_SI128((const __m128i*)(rgb_ptr2)), \ + rgb6 = LOAD_SI128((const __m128i*)(rgb_ptr2+16)), \ + rgb7 = LOAD_SI128((const __m128i*)(rgb_ptr2+32)), \ + rgb8 = LOAD_SI128((const __m128i*)(rgb_ptr2+48)); \ + /* unpack rgb24 data to r, g and b data in separate channels*/ \ + /* see rgb.txt to get an idea of the algorithm, note that we only go to the next to last step*/ \ + /* here, because averaging in horizontal direction is easier like this*/ \ + /* The last step is applied further on the Y channel only*/ \ + UNPACK_RGB32_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8) \ + UNPACK_RGB32_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8) \ + UNPACK_RGB32_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8) \ + UNPACK_RGB32_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8) \ + /* first compute Y', (B-Y') and (R-Y'), in 16bits values, for the first line */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are saved*/ \ + r_16 = _mm_unpacklo_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb1_16 = _mm_sub_epi16(b_16, y1_16); \ + cr1_16 = _mm_sub_epi16(r_16, y1_16); \ + r_16 = _mm_unpacklo_epi8(rgb5, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb6, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb7, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb1_16 = _mm_add_epi16(cb1_16, _mm_sub_epi16(b_16, y2_16)); \ + cr1_16 = _mm_add_epi16(cr1_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr1), Y); \ + /* same for the second line, compute Y', (B-Y') and (R-Y'), in 16bits values */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are added to the previous values*/ \ + r_16 = _mm_unpackhi_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb1_16 = _mm_add_epi16(cb1_16, _mm_sub_epi16(b_16, y1_16)); \ + cr1_16 = _mm_add_epi16(cr1_16, _mm_sub_epi16(r_16, y1_16)); \ + r_16 = _mm_unpackhi_epi8(rgb5, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb6, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb7, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb1_16 = _mm_add_epi16(cb1_16, _mm_sub_epi16(b_16, y2_16)); \ + cr1_16 = _mm_add_epi16(cr1_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr2), Y); \ + /* Rescale Cb and Cr to their final range */ \ + cb1_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cb1_16, 2), _mm_set1_epi16(param->cb_factor)), 8), _mm_set1_epi16(128)); \ + cr1_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cr1_16, 2), _mm_set1_epi16(param->cr_factor)), 8), _mm_set1_epi16(128)); \ + \ + /* do the same again with next data */ \ + rgb1 = LOAD_SI128((const __m128i*)(rgb_ptr1+64)), \ + rgb2 = LOAD_SI128((const __m128i*)(rgb_ptr1+80)), \ + rgb3 = LOAD_SI128((const __m128i*)(rgb_ptr1+96)), \ + rgb4 = LOAD_SI128((const __m128i*)(rgb_ptr1+112)), \ + rgb5 = LOAD_SI128((const __m128i*)(rgb_ptr2+64)), \ + rgb6 = LOAD_SI128((const __m128i*)(rgb_ptr2+80)), \ + rgb7 = LOAD_SI128((const __m128i*)(rgb_ptr2+96)), \ + rgb8 = LOAD_SI128((const __m128i*)(rgb_ptr2+112)); \ + /* unpack rgb24 data to r, g and b data in separate channels*/ \ + /* see rgb.txt to get an idea of the algorithm, note that we only go to the next to last step*/ \ + /* here, because averaging in horizontal direction is easier like this*/ \ + /* The last step is applied further on the Y channel only*/ \ + UNPACK_RGB32_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8) \ + UNPACK_RGB32_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8) \ + UNPACK_RGB32_32_STEP(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8) \ + UNPACK_RGB32_32_STEP(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, rgb7, rgb8) \ + /* first compute Y', (B-Y') and (R-Y'), in 16bits values, for the first line */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are saved*/ \ + r_16 = _mm_unpacklo_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb2_16 = _mm_sub_epi16(b_16, y1_16); \ + cr2_16 = _mm_sub_epi16(r_16, y1_16); \ + r_16 = _mm_unpacklo_epi8(rgb5, _mm_setzero_si128()); \ + g_16 = _mm_unpacklo_epi8(rgb6, _mm_setzero_si128()); \ + b_16 = _mm_unpacklo_epi8(rgb7, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb2_16 = _mm_add_epi16(cb2_16, _mm_sub_epi16(b_16, y2_16)); \ + cr2_16 = _mm_add_epi16(cr2_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr1+16), Y); \ + /* same for the second line, compute Y', (B-Y') and (R-Y'), in 16bits values */ \ + /* Y is saved for each pixel, while only sums of (B-Y') and (R-Y') for pairs of adjacents pixels are added to the previous values*/ \ + r_16 = _mm_unpackhi_epi8(rgb1, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb2, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb3, _mm_setzero_si128()); \ + y1_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y1_16 = _mm_add_epi16(y1_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y1_16 = _mm_srli_epi16(y1_16, 8); \ + cb2_16 = _mm_add_epi16(cb2_16, _mm_sub_epi16(b_16, y1_16)); \ + cr2_16 = _mm_add_epi16(cr2_16, _mm_sub_epi16(r_16, y1_16)); \ + r_16 = _mm_unpackhi_epi8(rgb5, _mm_setzero_si128()); \ + g_16 = _mm_unpackhi_epi8(rgb6, _mm_setzero_si128()); \ + b_16 = _mm_unpackhi_epi8(rgb7, _mm_setzero_si128()); \ + y2_16 = _mm_add_epi16(_mm_mullo_epi16(r_16, _mm_set1_epi16(param->r_factor)), \ + _mm_mullo_epi16(g_16, _mm_set1_epi16(param->g_factor))); \ + y2_16 = _mm_add_epi16(y2_16, _mm_mullo_epi16(b_16, _mm_set1_epi16(param->b_factor))); \ + y2_16 = _mm_srli_epi16(y2_16, 8); \ + cb2_16 = _mm_add_epi16(cb2_16, _mm_sub_epi16(b_16, y2_16)); \ + cr2_16 = _mm_add_epi16(cr2_16, _mm_sub_epi16(r_16, y2_16)); \ + /* Rescale Y' to Y, pack it to 8bit values and save it */ \ + y1_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y1_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + y2_16 = _mm_add_epi16(_mm_srli_epi16(_mm_mullo_epi16(y2_16, _mm_set1_epi16(param->y_factor)), 7), _mm_set1_epi16(param->y_offset)); \ + Y = _mm_packus_epi16(y1_16, y2_16); \ + Y = _mm_unpackhi_epi8(_mm_slli_si128(Y, 8), Y); \ + SAVE_SI128((__m128i*)(y_ptr2+16), Y); \ + /* Rescale Cb and Cr to their final range */ \ + cb2_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cb2_16, 2), _mm_set1_epi16(param->cb_factor)), 8), _mm_set1_epi16(128)); \ + cr2_16 = _mm_add_epi16(_mm_srai_epi16(_mm_mullo_epi16(_mm_srai_epi16(cr2_16, 2), _mm_set1_epi16(param->cr_factor)), 8), _mm_set1_epi16(128)); \ + /* Pack and save Cb Cr */ \ + cb = _mm_packus_epi16(cb1_16, cb2_16); \ + cr = _mm_packus_epi16(cr1_16, cr2_16); \ + SAVE_SI128((__m128i*)(u_ptr), cb); \ + SAVE_SI128((__m128i*)(v_ptr), cr); + +void rgb32_yuv420_sse(uint32_t width, uint32_t height, + const uint8_t *RGBA, uint32_t RGBA_stride, + uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_load_si128 + #define SAVE_SI128 _mm_stream_si128 + const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *rgb_ptr1=RGBA+y*RGBA_stride, + *rgb_ptr2=RGBA+(y+1)*RGBA_stride; + + uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + for(x=0; x<(width-31); x+=32) + { + RGBA2YUV_32 + + rgb_ptr1+=128; + rgb_ptr2+=128; + y_ptr1+=32; + y_ptr2+=32; + u_ptr+=16; + v_ptr+=16; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void rgb32_yuv420_sseu(uint32_t width, uint32_t height, + const uint8_t *RGBA, uint32_t RGBA_stride, + uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_loadu_si128 + #define SAVE_SI128 _mm_storeu_si128 + const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *rgb_ptr1=RGBA+y*RGBA_stride, + *rgb_ptr2=RGBA+(y+1)*RGBA_stride; + + uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + for(x=0; x<(width-31); x+=32) + { + RGBA2YUV_32 + + rgb_ptr1+=128; + rgb_ptr2+=128; + y_ptr1+=32; + y_ptr2+=32; + u_ptr+=16; + v_ptr+=16; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +#endif + +#ifdef _YUVRGB_SSE2_ + +#define UV2RGB_16(U,V,R1,G1,B1,R2,G2,B2) \ + r_tmp = _mm_srai_epi16(_mm_mullo_epi16(V, _mm_set1_epi16(param->cr_factor)), 6); \ + g_tmp = _mm_srai_epi16(_mm_add_epi16( \ + _mm_mullo_epi16(U, _mm_set1_epi16(param->g_cb_factor)), \ + _mm_mullo_epi16(V, _mm_set1_epi16(param->g_cr_factor))), 7); \ + b_tmp = _mm_srai_epi16(_mm_mullo_epi16(U, _mm_set1_epi16(param->cb_factor)), 6); \ + R1 = _mm_unpacklo_epi16(r_tmp, r_tmp); \ + G1 = _mm_unpacklo_epi16(g_tmp, g_tmp); \ + B1 = _mm_unpacklo_epi16(b_tmp, b_tmp); \ + R2 = _mm_unpackhi_epi16(r_tmp, r_tmp); \ + G2 = _mm_unpackhi_epi16(g_tmp, g_tmp); \ + B2 = _mm_unpackhi_epi16(b_tmp, b_tmp); \ + +#define ADD_Y2RGB_16(Y1,Y2,R1,G1,B1,R2,G2,B2) \ + Y1 = _mm_srli_epi16(_mm_mullo_epi16(Y1, _mm_set1_epi16(param->y_factor)), 7); \ + Y2 = _mm_srli_epi16(_mm_mullo_epi16(Y2, _mm_set1_epi16(param->y_factor)), 7); \ + \ + R1 = _mm_add_epi16(Y1, R1); \ + G1 = _mm_sub_epi16(Y1, G1); \ + B1 = _mm_add_epi16(Y1, B1); \ + R2 = _mm_add_epi16(Y2, R2); \ + G2 = _mm_sub_epi16(Y2, G2); \ + B2 = _mm_add_epi16(Y2, B2); \ + +#define PACK_RGB24_32_STEP(RS1, RS2, RS3, RS4, RS5, RS6, RD1, RD2, RD3, RD4, RD5, RD6) \ +RD1 = _mm_packus_epi16(_mm_and_si128(RS1,_mm_set1_epi16(0xFF)), _mm_and_si128(RS2,_mm_set1_epi16(0xFF))); \ +RD2 = _mm_packus_epi16(_mm_and_si128(RS3,_mm_set1_epi16(0xFF)), _mm_and_si128(RS4,_mm_set1_epi16(0xFF))); \ +RD3 = _mm_packus_epi16(_mm_and_si128(RS5,_mm_set1_epi16(0xFF)), _mm_and_si128(RS6,_mm_set1_epi16(0xFF))); \ +RD4 = _mm_packus_epi16(_mm_srli_epi16(RS1,8), _mm_srli_epi16(RS2,8)); \ +RD5 = _mm_packus_epi16(_mm_srli_epi16(RS3,8), _mm_srli_epi16(RS4,8)); \ +RD6 = _mm_packus_epi16(_mm_srli_epi16(RS5,8), _mm_srli_epi16(RS6,8)); \ + +#define PACK_RGB24_32(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \ +PACK_RGB24_32_STEP(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \ +PACK_RGB24_32_STEP(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \ +PACK_RGB24_32_STEP(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \ +PACK_RGB24_32_STEP(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \ +PACK_RGB24_32_STEP(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \ + +#define LOAD_UV_PLANAR \ + __m128i u = LOAD_SI128((const __m128i*)(u_ptr)); \ + __m128i v = LOAD_SI128((const __m128i*)(v_ptr)); \ + +#define LOAD_UV_NV12 \ + __m128i uv1 = LOAD_SI128((const __m128i*)(uv_ptr)); \ + __m128i uv2 = LOAD_SI128((const __m128i*)(uv_ptr+16)); \ + __m128i u = _mm_packus_epi16(_mm_and_si128(uv1, _mm_set1_epi16(255)), _mm_and_si128(uv2, _mm_set1_epi16(255))); \ + uv1 = _mm_srli_epi16(uv1, 8); \ + uv2 = _mm_srli_epi16(uv2, 8); \ + __m128i v = _mm_packus_epi16(_mm_and_si128(uv1, _mm_set1_epi16(255)), _mm_and_si128(uv2, _mm_set1_epi16(255))); \ + +#define LOAD_UV_NV21 \ + __m128i uv1 = LOAD_SI128((const __m128i*)(uv_ptr)); \ + __m128i uv2 = LOAD_SI128((const __m128i*)(uv_ptr+16)); \ + __m128i v = _mm_packus_epi16(_mm_and_si128(uv1, _mm_set1_epi16(255)), _mm_and_si128(uv2, _mm_set1_epi16(255))); \ + uv1 = _mm_srli_epi16(uv1, 8); \ + uv2 = _mm_srli_epi16(uv2, 8); \ + __m128i u = _mm_packus_epi16(_mm_and_si128(uv1, _mm_set1_epi16(255)), _mm_and_si128(uv2, _mm_set1_epi16(255))); \ + +#define YUV2RGB_32 \ + __m128i r_tmp, g_tmp, b_tmp; \ + __m128i r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2; \ + __m128i r_uv_16_1, g_uv_16_1, b_uv_16_1, r_uv_16_2, g_uv_16_2, b_uv_16_2; \ + __m128i y_16_1, y_16_2; \ + \ + u = _mm_add_epi8(u, _mm_set1_epi8(-128)); \ + v = _mm_add_epi8(v, _mm_set1_epi8(-128)); \ + \ + /* process first 16 pixels of first line */\ + __m128i u_16 = _mm_srai_epi16(_mm_unpacklo_epi8(u, u), 8); \ + __m128i v_16 = _mm_srai_epi16(_mm_unpacklo_epi8(v, v), 8); \ + \ + UV2RGB_16(u_16, v_16, r_uv_16_1, g_uv_16_1, b_uv_16_1, r_uv_16_2, g_uv_16_2, b_uv_16_2) \ + r_16_1=r_uv_16_1; g_16_1=g_uv_16_1; b_16_1=b_uv_16_1; \ + r_16_2=r_uv_16_2; g_16_2=g_uv_16_2; b_16_2=b_uv_16_2; \ + \ + __m128i y = LOAD_SI128((const __m128i*)(y_ptr1)); \ + y = _mm_subs_epu8(y, _mm_set1_epi8(param->y_offset)); \ + y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \ + y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \ + \ + ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \ + \ + __m128i r_8_11 = _mm_packus_epi16(r_16_1, r_16_2); \ + __m128i g_8_11 = _mm_packus_epi16(g_16_1, g_16_2); \ + __m128i b_8_11 = _mm_packus_epi16(b_16_1, b_16_2); \ + \ + /* process first 16 pixels of second line */\ + r_16_1=r_uv_16_1; g_16_1=g_uv_16_1; b_16_1=b_uv_16_1; \ + r_16_2=r_uv_16_2; g_16_2=g_uv_16_2; b_16_2=b_uv_16_2; \ + \ + y = LOAD_SI128((const __m128i*)(y_ptr2)); \ + y = _mm_subs_epu8(y, _mm_set1_epi8(param->y_offset)); \ + y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \ + y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \ + \ + ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \ + \ + __m128i r_8_21 = _mm_packus_epi16(r_16_1, r_16_2); \ + __m128i g_8_21 = _mm_packus_epi16(g_16_1, g_16_2); \ + __m128i b_8_21 = _mm_packus_epi16(b_16_1, b_16_2); \ + \ + /* process last 16 pixels of first line */\ + u_16 = _mm_srai_epi16(_mm_unpackhi_epi8(u, u), 8); \ + v_16 = _mm_srai_epi16(_mm_unpackhi_epi8(v, v), 8); \ + \ + UV2RGB_16(u_16, v_16, r_uv_16_1, g_uv_16_1, b_uv_16_1, r_uv_16_2, g_uv_16_2, b_uv_16_2) \ + r_16_1=r_uv_16_1; g_16_1=g_uv_16_1; b_16_1=b_uv_16_1; \ + r_16_2=r_uv_16_2; g_16_2=g_uv_16_2; b_16_2=b_uv_16_2; \ + \ + y = LOAD_SI128((const __m128i*)(y_ptr1+16)); \ + y = _mm_subs_epu8(y, _mm_set1_epi8(param->y_offset)); \ + y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \ + y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \ + \ + ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \ + \ + __m128i r_8_12 = _mm_packus_epi16(r_16_1, r_16_2); \ + __m128i g_8_12 = _mm_packus_epi16(g_16_1, g_16_2); \ + __m128i b_8_12 = _mm_packus_epi16(b_16_1, b_16_2); \ + \ + /* process last 16 pixels of second line */\ + r_16_1=r_uv_16_1; g_16_1=g_uv_16_1; b_16_1=b_uv_16_1; \ + r_16_2=r_uv_16_2; g_16_2=g_uv_16_2; b_16_2=b_uv_16_2; \ + \ + y = LOAD_SI128((const __m128i*)(y_ptr2+16)); \ + y = _mm_subs_epu8(y, _mm_set1_epi8(param->y_offset)); \ + y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \ + y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \ + \ + ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \ + \ + __m128i r_8_22 = _mm_packus_epi16(r_16_1, r_16_2); \ + __m128i g_8_22 = _mm_packus_epi16(g_16_1, g_16_2); \ + __m128i b_8_22 = _mm_packus_epi16(b_16_1, b_16_2); \ + \ + __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6; \ + \ + PACK_RGB24_32(r_8_11, r_8_12, g_8_11, g_8_12, b_8_11, b_8_12, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6) \ + SAVE_SI128((__m128i*)(rgb_ptr1), rgb_1); \ + SAVE_SI128((__m128i*)(rgb_ptr1+16), rgb_2); \ + SAVE_SI128((__m128i*)(rgb_ptr1+32), rgb_3); \ + SAVE_SI128((__m128i*)(rgb_ptr1+48), rgb_4); \ + SAVE_SI128((__m128i*)(rgb_ptr1+64), rgb_5); \ + SAVE_SI128((__m128i*)(rgb_ptr1+80), rgb_6); \ + \ + PACK_RGB24_32(r_8_21, r_8_22, g_8_21, g_8_22, b_8_21, b_8_22, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6) \ + SAVE_SI128((__m128i*)(rgb_ptr2), rgb_1); \ + SAVE_SI128((__m128i*)(rgb_ptr2+16), rgb_2); \ + SAVE_SI128((__m128i*)(rgb_ptr2+32), rgb_3); \ + SAVE_SI128((__m128i*)(rgb_ptr2+48), rgb_4); \ + SAVE_SI128((__m128i*)(rgb_ptr2+64), rgb_5); \ + SAVE_SI128((__m128i*)(rgb_ptr2+80), rgb_6); \ + +#define YUV2RGB_32_PLANAR \ + LOAD_UV_PLANAR \ + YUV2RGB_32 + +#define YUV2RGB_32_NV12 \ + LOAD_UV_NV12 \ + YUV2RGB_32 + +#define YUV2RGB_32_NV21 \ + LOAD_UV_NV21 \ + YUV2RGB_32 + + +void yuv420_rgb24_sse( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *U, const uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_load_si128 + #define SAVE_SI128 _mm_stream_si128 + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-31); x+=32) + { + YUV2RGB_32_PLANAR + + y_ptr1+=32; + y_ptr2+=32; + u_ptr+=16; + v_ptr+=16; + rgb_ptr1+=96; + rgb_ptr2+=96; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void yuv420_rgb24_sseu( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *U, const uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_loadu_si128 + #define SAVE_SI128 _mm_storeu_si128 + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *u_ptr=U+(y/2)*UV_stride, + *v_ptr=V+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-31); x+=32) + { + YUV2RGB_32_PLANAR + + y_ptr1+=32; + y_ptr2+=32; + u_ptr+=16; + v_ptr+=16; + rgb_ptr1+=96; + rgb_ptr2+=96; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void nv12_rgb24_sse( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *UV, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_load_si128 + #define SAVE_SI128 _mm_stream_si128 + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *uv_ptr=UV+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-31); x+=32) + { + YUV2RGB_32_NV12 + + y_ptr1+=32; + y_ptr2+=32; + uv_ptr+=32; + rgb_ptr1+=96; + rgb_ptr2+=96; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void nv12_rgb24_sseu( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *UV, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_loadu_si128 + #define SAVE_SI128 _mm_storeu_si128 + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *uv_ptr=UV+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-31); x+=32) + { + YUV2RGB_32_NV12 + + y_ptr1+=32; + y_ptr2+=32; + uv_ptr+=32; + rgb_ptr1+=96; + rgb_ptr2+=96; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void nv21_rgb24_sse( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *UV, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_load_si128 + #define SAVE_SI128 _mm_stream_si128 + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *uv_ptr=UV+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-31); x+=32) + { + YUV2RGB_32_NV21 + + y_ptr1+=32; + y_ptr2+=32; + uv_ptr+=32; + rgb_ptr1+=96; + rgb_ptr2+=96; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + +void nv21_rgb24_sseu( + uint32_t width, uint32_t height, + const uint8_t *Y, const uint8_t *UV, uint32_t Y_stride, uint32_t UV_stride, + uint8_t *RGB, uint32_t RGB_stride, + YCbCrType yuv_type) +{ + #define LOAD_SI128 _mm_loadu_si128 + #define SAVE_SI128 _mm_storeu_si128 + const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]); + + uint32_t x, y; + for(y=0; y<(height-1); y+=2) + { + const uint8_t *y_ptr1=Y+y*Y_stride, + *y_ptr2=Y+(y+1)*Y_stride, + *uv_ptr=UV+(y/2)*UV_stride; + + uint8_t *rgb_ptr1=RGB+y*RGB_stride, + *rgb_ptr2=RGB+(y+1)*RGB_stride; + + for(x=0; x<(width-31); x+=32) + { + YUV2RGB_32_NV21 + + y_ptr1+=32; + y_ptr2+=32; + uv_ptr+=32; + rgb_ptr1+=96; + rgb_ptr2+=96; + } + } + #undef LOAD_SI128 + #undef SAVE_SI128 +} + + + +#endif //_YUVRGB_SSE2_ diff --git a/src/yuv_rgb.h b/src/yuv_rgb.h new file mode 100644 index 0000000..e59d73e --- /dev/null +++ b/src/yuv_rgb.h @@ -0,0 +1,165 @@ + +#pragma once +#ifndef YUV_RGB_H +#define YUV_RGB_H +// Copyright 2016 Adrien Descamps +// Distributed under BSD 3-Clause License + +// Provide optimized functions to convert images from 8bits yuv420 to rgb24 format + +// There are a few slightly different variations of the YCbCr color space with different parameters that +// change the conversion matrix. +// The three most common YCbCr color space, defined by BT.601, BT.709 and JPEG standard are implemented here. +// See the respective standards for details +// The matrix values used are derived from http://www.equasys.de/colorconversion.html + +// YUV420 is stored as three separate channels, with U and V (Cb and Cr) subsampled by a 2 factor +// For conversion from yuv to rgb, no interpolation is done, and the same UV value are used for 4 rgb pixels. This +// is suboptimal for image quality, but by far the fastest method. + +// For all methods, width and height should be even, if not, the last row/column of the result image won't be affected. +// For sse methods, if the width if not divisable by 32, the last (width%32) pixels of each line won't be affected. +#include "define_inc.h" +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +typedef enum +{ + YCBCR_JPEG, + YCBCR_601, + YCBCR_709 +} YCbCrType; + +#ifdef __cplusplus +extern "C" { +#endif + +// yuv to rgb, standard c implementation +void yuv420_rgb24_std( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv to rgb, yuv in nv12 semi planar format +void nv12_rgb24_std( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv to rgb, yuv in nv12 semi planar format +void nv21_rgb24_std( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv to rgb, sse implementation +// pointers must be 16 byte aligned, and strides must be divisable by 16 +void yuv420_rgb24_sse( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv to rgb, sse implementation +// pointers do not need to be 16 byte aligned +void yuv420_rgb24_sseu( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv nv12 to rgb, sse implementation +// pointers must be 16 byte aligned, and strides must be divisable by 16 +void nv12_rgb24_sse( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv nv12 to rgb, sse implementation +// pointers do not need to be 16 byte aligned +void nv12_rgb24_sseu( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv nv21 to rgb, sse implementation +// pointers must be 16 byte aligned, and strides must be divisable by 16 +void nv21_rgb24_sse( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + +// yuv nv21 to rgb, sse implementation +// pointers do not need to be 16 byte aligned +void nv21_rgb24_sseu( + uint32_t width, uint32_t height, + const uint8_t *y, const uint8_t *uv, uint32_t y_stride, uint32_t uv_stride, + uint8_t *rgb, uint32_t rgb_stride, + YCbCrType yuv_type); + + + + +// rgb to yuv, standard c implementation +void rgb24_yuv420_std( + uint32_t width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + +// rgb to yuv, sse implementation +// pointers must be 16 byte aligned, and strides must be divisible by 16 +void rgb24_yuv420_sse( + uint32_t width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + +// rgb to yuv, sse implementation +// pointers do not need to be 16 byte aligned +void rgb24_yuv420_sseu( + uint32_t width, uint32_t height, + const uint8_t *rgb, uint32_t rgb_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + +// rgba to yuv, standard c implementation +// alpha channel is ignored +void rgb32_yuv420_std( + uint32_t width, uint32_t height, + const uint8_t *rgba, uint32_t rgba_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + +// rgba to yuv, sse implementation +// pointers must be 16 byte aligned, and strides must be divisible by 16 +// alpha channel is ignored +void rgb32_yuv420_sse( + uint32_t width, uint32_t height, + const uint8_t *rgba, uint32_t rgba_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + +// rgba to yuv, sse implementation +// pointers do not need to be 16 byte aligned +// alpha channel is ignored +void rgb32_yuv420_sseu( + uint32_t width, uint32_t height, + const uint8_t *rgba, uint32_t rgba_stride, + uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride, + YCbCrType yuv_type); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/zlog.h b/src/zlog.h new file mode 100644 index 0000000..4571f6c --- /dev/null +++ b/src/zlog.h @@ -0,0 +1,279 @@ +/* + * This file is part of the zlog Library. + * + * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com> + * + * Licensed under the LGPL v2.1, see the file COPYING in base directory. + */ +#pragma once +#ifndef __zlog_h +#define __zlog_h + +#ifdef __cplusplus +extern "C" { +#endif +#include "define_inc.h" +#include <stdarg.h> /* for va_list */ +#include <stdio.h> /* for size_t */ + +# if defined __GNUC__ +# define ZLOG_CHECK_PRINTF(m,n) __attribute__((format(printf,m,n))) +# else +# define ZLOG_CHECK_PRINTF(m,n) +# endif + +typedef struct zlog_category_s zlog_category_t; + +int zlog_init(const char *config); +int zlog_reload(const char *config); +void zlog_fini(void); + +void zlog_profile(void); + +zlog_category_t *zlog_get_category(const char *cname); +int zlog_level_enabled(zlog_category_t *category, const int level); + +int zlog_put_mdc(const char *key, const char *value); +char *zlog_get_mdc(const char *key); +void zlog_remove_mdc(const char *key); +void zlog_clean_mdc(void); + +int zlog_level_switch(zlog_category_t * category, int level); +int zlog_level_enabled(zlog_category_t * category, int level); + +void zlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, ...) ZLOG_CHECK_PRINTF(8,9); +void vzlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, va_list args); +void hzlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const void *buf, size_t buflen); + +int dzlog_init(const char *confpath, const char *cname); +int dzlog_set_category(const char *cname); + +void dzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, ...) ZLOG_CHECK_PRINTF(7,8); +void vdzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, va_list args); +void hdzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const void *buf, size_t buflen); + +typedef struct zlog_msg_s { + char *buf; + size_t len; + char *path; +} zlog_msg_t; + +typedef int (*zlog_record_fn)(zlog_msg_t *msg); +int zlog_set_record(const char *rname, zlog_record_fn record); + +const char *zlog_version(void); + +/******* useful macros, can be redefined at user's h file **********/ + +typedef enum { + ZLOG_LEVEL_DEBUG = 20, + ZLOG_LEVEL_INFO = 40, + ZLOG_LEVEL_NOTICE = 60, + ZLOG_LEVEL_WARN = 80, + ZLOG_LEVEL_ERROR = 100, + ZLOG_LEVEL_FATAL = 120 +} zlog_level; + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L +# if defined __GNUC__ && __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "<unknown>" +# endif +#endif + +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +/* zlog macros */ +#define zlog_fatal(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, __VA_ARGS__) +#define zlog_error(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, __VA_ARGS__) +#define zlog_warn(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, __VA_ARGS__) +#define zlog_notice(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, __VA_ARGS__) +#define zlog_info(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, __VA_ARGS__) +#define zlog_debug(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, __VA_ARGS__) +/* dzlog macros */ +#define dzlog_fatal(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, __VA_ARGS__) +#define dzlog_error(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, __VA_ARGS__) +#define dzlog_warn(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, __VA_ARGS__) +#define dzlog_notice(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, __VA_ARGS__) +#define dzlog_info(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, __VA_ARGS__) +#define dzlog_debug(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, __VA_ARGS__) +#elif defined __GNUC__ +/* zlog macros */ +#define zlog_fatal(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, ##args) +#define zlog_error(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, ##args) +#define zlog_warn(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, ##args) +#define zlog_notice(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, ##args) +#define zlog_info(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, ##args) +#define zlog_debug(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, ##args) +/* dzlog macros */ +#define dzlog_fatal(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, ##args) +#define dzlog_error(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, ##args) +#define dzlog_warn(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, ##args) +#define dzlog_notice(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, ##args) +#define dzlog_info(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, ##args) +#define dzlog_debug(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, ##args) +#endif + +/* vzlog macros */ +#define vzlog_fatal(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, args) +#define vzlog_error(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, args) +#define vzlog_warn(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, args) +#define vzlog_notice(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, args) +#define vzlog_info(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, args) +#define vzlog_debug(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, args) + +/* hzlog macros */ +#define hzlog_fatal(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, buf, buf_len) +#define hzlog_error(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, buf, buf_len) +#define hzlog_warn(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, buf, buf_len) +#define hzlog_notice(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, buf, buf_len) +#define hzlog_info(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, buf, buf_len) +#define hzlog_debug(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, buf, buf_len) + + +/* vdzlog macros */ +#define vdzlog_fatal(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, args) +#define vdzlog_error(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, args) +#define vdzlog_warn(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, args) +#define vdzlog_notice(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, args) +#define vdzlog_info(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, args) +#define vdzlog_debug(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, args) + +/* hdzlog macros */ +#define hdzlog_fatal(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, buf, buf_len) +#define hdzlog_error(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, buf, buf_len) +#define hdzlog_warn(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, buf, buf_len) +#define hdzlog_notice(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, buf, buf_len) +#define hdzlog_info(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, buf, buf_len) +#define hdzlog_debug(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, buf, buf_len) + +/* enabled macros */ +#define zlog_fatal_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_FATAL) +#define zlog_error_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_ERROR) +#define zlog_warn_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_WARN) +#define zlog_notice_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_NOTICE) +#define zlog_info_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_INFO) +#define zlog_debug_enabled(zc) zlog_level_enabled(zc, ZLOG_LEVEL_DEBUG) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src_bak/zlog.h b/src_bak/zlog.h new file mode 100644 index 0000000..665edfa --- /dev/null +++ b/src_bak/zlog.h @@ -0,0 +1,277 @@ +/* + * This file is part of the zlog Library. + * + * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com> + * + * The zlog Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The zlog Library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the zlog Library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __zlog_h +#define __zlog_h + +#ifdef __cplusplus +extern "C" { +#endif + +extern char *zlog_git_sha1; + +#include <stdarg.h> /* for va_list */ +#include <stdio.h> /* for size_t */ + +typedef struct zlog_category_s zlog_category_t; + +int zlog_init(const char *confpath); +int zlog_reload(const char *confpath); +void zlog_fini(void); + +void zlog_profile(void); + +zlog_category_t *zlog_get_category(const char *cname); + +int zlog_put_mdc(const char *key, const char *value); +char *zlog_get_mdc(const char *key); +void zlog_remove_mdc(const char *key); +void zlog_clean_mdc(void); + +void zlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, ...); +void vzlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, va_list args); +void hzlog(zlog_category_t * category, + const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const void *buf, size_t buflen); + +int dzlog_init(const char *confpath, const char *cname); +int dzlog_set_category(const char *cname); + +void dzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, ...); +void vdzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const char *format, va_list args); +void hdzlog(const char *file, size_t filelen, + const char *func, size_t funclen, + long line, int level, + const void *buf, size_t buflen); + +typedef struct zlog_msg_s { + char *buf; + size_t len; + char *path; +} zlog_msg_t; + +typedef int (*zlog_record_fn)(zlog_msg_t *msg); +int zlog_set_record(const char *rname, zlog_record_fn record); + +/******* useful macros, can be redefined at user's h file **********/ + +typedef enum { + ZLOG_LEVEL_DEBUG = 20, + ZLOG_LEVEL_INFO = 40, + ZLOG_LEVEL_NOTICE = 60, + ZLOG_LEVEL_WARN = 80, + ZLOG_LEVEL_ERROR = 100, + ZLOG_LEVEL_FATAL = 120 +} zlog_level; + +#ifndef _MSC_VER +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L +# if defined __GNUC__ && __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "<unknown>" +# endif +#endif +//By LL +#else +#define __func__ __FUNCTION__ +#endif + +#if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || (defined _MSC_VER) +/* zlog macros */ +#define zlog_fatal(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, __VA_ARGS__) +#define zlog_error(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, __VA_ARGS__) +#define zlog_warn(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, __VA_ARGS__) +#define zlog_notice(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, __VA_ARGS__) +#define zlog_info(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, __VA_ARGS__) +#define zlog_debug(cat, ...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, __VA_ARGS__) +/* dzlog macros */ +#define dzlog_fatal(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, __VA_ARGS__) +#define dzlog_error(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, __VA_ARGS__) +#define dzlog_warn(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, __VA_ARGS__) +#define dzlog_notice(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, __VA_ARGS__) +#define dzlog_info(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, __VA_ARGS__) +#define dzlog_debug(...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, __VA_ARGS__) +#elif defined __GNUC__ +/* zlog macros */ +#define zlog_fatal(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, ##args) +#define zlog_error(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, ##args) +#define zlog_warn(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, ##args) +#define zlog_notice(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, ##args) +#define zlog_info(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, ##args) +#define zlog_debug(cat, format, args...) \ + zlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, ##args) +/* dzlog macros */ +#define dzlog_fatal(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, ##args) +#define dzlog_error(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, ##args) +#define dzlog_warn(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, ##args) +#define dzlog_notice(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, ##args) +#define dzlog_info(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, ##args) +#define dzlog_debug(format, args...) \ + dzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, ##args) +#endif + +/* vzlog macros */ +#define vzlog_fatal(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, args) +#define vzlog_error(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, args) +#define vzlog_warn(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, args) +#define vzlog_notice(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, args) +#define vzlog_info(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, args) +#define vzlog_debug(cat, format, args) \ + vzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, args) + +/* hzlog macros */ +#define hzlog_fatal(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, buf, buf_len) +#define hzlog_error(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, buf, buf_len) +#define hzlog_warn(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, buf, buf_len) +#define hzlog_notice(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, buf, buf_len) +#define hzlog_info(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, buf, buf_len) +#define hzlog_debug(cat, buf, buf_len) \ + hzlog(cat, __FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, buf, buf_len) + + +/* vdzlog macros */ +#define vdzlog_fatal(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, format, args) +#define vdzlog_error(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, format, args) +#define vdzlog_warn(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, format, args) +#define vdzlog_notice(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, format, args) +#define vdzlog_info(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, format, args) +#define vdzlog_debug(format, args) \ + vdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, format, args) + +/* hdzlog macros */ +#define hdzlog_fatal(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_FATAL, buf, buf_len) +#define hdzlog_error(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_ERROR, buf, buf_len) +#define hdzlog_warn(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_WARN, buf, buf_len) +#define hdzlog_notice(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_NOTICE, buf, buf_len) +#define hdzlog_info(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_INFO, buf, buf_len) +#define hdzlog_debug(buf, buf_len) \ + hdzlog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \ + ZLOG_LEVEL_DEBUG, buf, buf_len) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/srcb/config.json b/srcb/config.json new file mode 100644 index 0000000..d75e5aa --- /dev/null +++ b/srcb/config.json @@ -0,0 +1,2117 @@ +{ + "ai_server": { + "ip": "127.0.0.1", + "http_port": "8592", + "video_port": "8591" + }, + "view_setting": { + "camera01": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_Human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "0", + "confidence3": "80", + "confidence4": "80", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "car,bus,truck", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 141, + "y1": 257, + "x2": 635, + "y2": 255, + "x3": 729, + "y3": 411, + "x4": 10, + "y4": 409 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera02": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera03": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera04": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera05": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera06": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera07": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera08": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera09": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera10": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera11": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera12": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera13": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera14": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera15": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera16": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + } + }, + "system_setting": { + "AI dataset": "", + "dataset category": "Traffic", + "snapshot folder": "D:\\", + "language": "English", + "enable log": "No", + "auto reconnect": "No", + "enable watchdog": "No", + "enable watchdog UI": "No", + "cpu usage limit": "80", + "display OSD": "Yes", + "display dash": "No", + "display properties": "Yes", + "display tracking ID": "Yes", + "overlap thresh": 70, + "confidence thresh": 0, + "cnn type": "CUDA", + "cnn device1": "GPU", + "cnn device2": "GPU", + "cnn device3": "GPU", + "cnn device4": "GPU", + "cnn device5": "GPU", + "cnn device6": "GPU", + "cnn device7": "GPU", + "cnn device8": "GPU" + }, + "about_box": { + "dataset version": "", + "software version": "1.0.5.79", + "system id": "04-D9-F5-BA-4A-CC", + "NIC name": "AӺ", + "unlocking key": "vO41GPyfGu/VhX5VYvmmYk1w+jmPit/Z3AI2GyNf2dE/jcR9lMwkYDUtfR0uemV9Ko/RkhW6IJ9xr+YtjQyu3MbyAFtD5J94iVTHdrCPS78=" + } +} diff --git a/srcb/config_bak.json b/srcb/config_bak.json new file mode 100644 index 0000000..d75e5aa --- /dev/null +++ b/srcb/config_bak.json @@ -0,0 +1,2117 @@ +{ + "ai_server": { + "ip": "127.0.0.1", + "http_port": "8592", + "video_port": "8591" + }, + "view_setting": { + "camera01": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_Human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "0", + "confidence3": "80", + "confidence4": "80", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "car,bus,truck", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 141, + "y1": 257, + "x2": 635, + "y2": 255, + "x3": 729, + "y3": 411, + "x4": 10, + "y4": 409 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [{ + "checked": 0, + "detect_event_id": "0x00000001", + "detect_event_name": "Prohibit zone detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000002", + "detect_event_name": "Parking spot detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000004", + "detect_event_name": "Parking violation detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000008", + "detect_event_name": "Traffic flow", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000010", + "detect_event_name": "Turn left", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000020", + "detect_event_name": "Turn right", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000040", + "detect_event_name": "Wrong way", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000080", + "detect_event_name": "Turn left violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000100", + "detect_event_name": "Turn right violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000200", + "detect_event_name": "U-turn violation", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000400", + "detect_event_name": "Run the red light (straight)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00000800", + "detect_event_name": "Run the red light (left)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00001000", + "detect_event_name": "Run the red light (right)", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x10000000", + "detect_event_name": "Queuing detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }, { + "checked": 0, + "detect_event_id": "0x00010000", + "detect_event_name": "No mask detection", + "post_event_name": "", + "counter_name": "", + "counter_increment": "" + }], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "", + "no_parking_time": "", + "queuing_count": "", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera02": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera03": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera04": { + "ip": "192.168.4.79", + "http_port": "80", + "video_port": "554", + "username": "admin", + "password": "pass", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera05": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera06": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera07": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "0", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "889x500", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera08": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera09": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera10": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera11": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera12": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera13": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera14": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera15": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + }, + "camera16": { + "ip": "", + "http_port": "", + "video_port": "", + "username": "", + "password": "", + "channel_id": "", + "camera_name": "", + "enable_anpr": "Yes", + "enable_traffic": "Yes", + "enable_logo": "Yes", + "enable_human": "No", + "levenshtein_distance": "", + "min_characters": "4", + "max_characters": "10", + "confidence": "80", + "confidence2": "70", + "confidence3": "80", + "confidence4": "70", + "tab_view_size": "", + "detection_zone": [{ + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }, { + "enable_traffic_light": "", + "detection_time": "", + "metadata1": "", + "metadata2": "", + "link_to_counter": "", + "enable_direction1": "", + "enable_direction2": "", + "direction1": "", + "direction2": "", + "enable_tripwire": "No", + "no_parking_time": "60", + "queuing_count": "5", + "trigger_events": [], + "x1": 0, + "y1": 0, + "x2": 0, + "y2": 0, + "x3": 0, + "y3": 0, + "x4": 0, + "y4": 0 + }] + } + }, + "system_setting": { + "AI dataset": "", + "dataset category": "Traffic", + "snapshot folder": "D:\\", + "language": "English", + "enable log": "No", + "auto reconnect": "No", + "enable watchdog": "No", + "enable watchdog UI": "No", + "cpu usage limit": "80", + "display OSD": "Yes", + "display dash": "No", + "display properties": "Yes", + "display tracking ID": "Yes", + "overlap thresh": 70, + "confidence thresh": 0, + "cnn type": "CUDA", + "cnn device1": "GPU", + "cnn device2": "GPU", + "cnn device3": "GPU", + "cnn device4": "GPU", + "cnn device5": "GPU", + "cnn device6": "GPU", + "cnn device7": "GPU", + "cnn device8": "GPU" + }, + "about_box": { + "dataset version": "", + "software version": "1.0.5.79", + "system id": "04-D9-F5-BA-4A-CC", + "NIC name": "AӺ", + "unlocking key": "vO41GPyfGu/VhX5VYvmmYk1w+jmPit/Z3AI2GyNf2dE/jcR9lMwkYDUtfR0uemV9Ko/RkhW6IJ9xr+YtjQyu3MbyAFtD5J94iVTHdrCPS78=" + } +} diff --git a/stCHnmMT b/stCHnmMT new file mode 100644 index 0000000..72c83b8 Binary files /dev/null and b/stCHnmMT differ diff --git a/stDp9FeM b/stDp9FeM new file mode 100644 index 0000000..1f67531 Binary files /dev/null and b/stDp9FeM differ diff --git a/stHgxrPU b/stHgxrPU new file mode 100644 index 0000000..c7e6dda Binary files /dev/null and b/stHgxrPU differ diff --git a/stR7hk4K b/stR7hk4K new file mode 100644 index 0000000..c7e6dda Binary files /dev/null and b/stR7hk4K differ diff --git a/stvcdyPQ b/stvcdyPQ new file mode 100644 index 0000000..72c83b8 Binary files /dev/null and b/stvcdyPQ differ diff --git a/stwwQXG3 b/stwwQXG3 new file mode 100644 index 0000000..5f31b14 Binary files /dev/null and b/stwwQXG3 differ